Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 30 additions & 26 deletions cpp/velox/shuffle/VeloxHashShuffleWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,14 @@ arrow::Status VeloxHashShuffleWriter::write(std::shared_ptr<ColumnarBatch> cb, i
VELOX_CHECK(numColumns >= 2);
auto pidBatch = veloxColumnBatch->select(veloxPool_.get(), {0});
auto pidArr = getFirstColumn(*(pidBatch->getRowVector()));
START_TIMING(cpuWallTimingList_[CpuWallTimingCompute]);
std::fill(std::begin(partition2RowCount_), std::end(partition2RowCount_), 0);
RETURN_NOT_OK(partitioner_->compute(pidArr, pidBatch->numRows(), row2Partition_));
for (auto& pid : row2Partition_) {
partition2RowCount_[pid]++;
{
SCOPED_TIMER(cpuWallTimingList_[CpuWallTimingCompute]);
std::fill(std::begin(partition2RowCount_), std::end(partition2RowCount_), 0);
RETURN_NOT_OK(partitioner_->compute(pidArr, pidBatch->numRows(), row2Partition_));
for (auto& pid : row2Partition_) {
partition2RowCount_[pid]++;
}
}
END_TIMING();
std::vector<int32_t> range;
range.reserve(numColumns);
for (int32_t i = 1; i < numColumns; i++) {
Expand All @@ -289,9 +290,10 @@ arrow::Status VeloxHashShuffleWriter::write(std::shared_ptr<ColumnarBatch> cb, i
auto veloxColumnBatch = VeloxColumnarBatch::from(veloxPool_.get(), cb);
VELOX_CHECK_NOT_NULL(veloxColumnBatch);
facebook::velox::RowVectorPtr rv;
START_TIMING(cpuWallTimingList_[CpuWallTimingFlattenRV]);
rv = veloxColumnBatch->getFlattenedRowVector();
END_TIMING();
{
SCOPED_TIMER(cpuWallTimingList_[CpuWallTimingFlattenRV]);
rv = veloxColumnBatch->getFlattenedRowVector();
}
if (isExtremelyLargeBatch(rv)) {
auto numRows = rv->size();
int32_t offset = 0;
Expand All @@ -313,23 +315,25 @@ arrow::Status VeloxHashShuffleWriter::partitioningAndDoSplit(facebook::velox::Ro
std::fill(std::begin(partition2RowCount_), std::end(partition2RowCount_), 0);
if (partitioner_->hasPid()) {
auto pidArr = getFirstColumn(*rv);
START_TIMING(cpuWallTimingList_[CpuWallTimingCompute]);
RETURN_NOT_OK(partitioner_->compute(pidArr, rv->size(), row2Partition_));
for (auto& pid : row2Partition_) {
partition2RowCount_[pid]++;
{
SCOPED_TIMER(cpuWallTimingList_[CpuWallTimingCompute]);
RETURN_NOT_OK(partitioner_->compute(pidArr, rv->size(), row2Partition_));
for (auto& pid : row2Partition_) {
partition2RowCount_[pid]++;
}
}
END_TIMING();
auto strippedRv = getStrippedRowVector(*rv);
RETURN_NOT_OK(initFromRowVector(*strippedRv));
RETURN_NOT_OK(doSplit(*strippedRv, memLimit));
} else {
RETURN_NOT_OK(initFromRowVector(*rv));
START_TIMING(cpuWallTimingList_[CpuWallTimingCompute]);
RETURN_NOT_OK(partitioner_->compute(nullptr, rv->size(), row2Partition_));
for (auto& pid : row2Partition_) {
partition2RowCount_[pid]++;
{
SCOPED_TIMER(cpuWallTimingList_[CpuWallTimingCompute]);
RETURN_NOT_OK(partitioner_->compute(nullptr, rv->size(), row2Partition_));
for (auto& pid : row2Partition_) {
partition2RowCount_[pid]++;
}
}
END_TIMING();
RETURN_NOT_OK(doSplit(*rv, memLimit));
}
return arrow::Status::OK();
Expand Down Expand Up @@ -416,13 +420,13 @@ arrow::Status VeloxHashShuffleWriter::doSplit(const facebook::velox::RowVector&
RETURN_NOT_OK(buildPartition2Row(rowNum));
RETURN_NOT_OK(updateInputHasNull(rv));

START_TIMING(cpuWallTimingList_[CpuWallTimingIteratePartitions]);

setSplitState(SplitState::kPreAlloc);
// Calculate buffer size based on available offheap memory, history average bytes per row and options_.bufferSize.
auto preAllocBufferSize = calculatePartitionBufferSize(rv, memLimit);
RETURN_NOT_OK(preAllocPartitionBuffers(preAllocBufferSize));
END_TIMING();
{
SCOPED_TIMER(cpuWallTimingList_[CpuWallTimingIteratePartitions]);
setSplitState(SplitState::kPreAlloc);
// Calculate buffer size based on available offheap memory, history average bytes per row and options_.bufferSize.
auto preAllocBufferSize = calculatePartitionBufferSize(rv, memLimit);
RETURN_NOT_OK(preAllocPartitionBuffers(preAllocBufferSize));
}

printPartitionBuffer();

Expand Down
35 changes: 19 additions & 16 deletions cpp/velox/shuffle/VeloxRssSortShuffleWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "shuffle/ShuffleSchema.h"
#include "utils/Common.h"
#include "utils/Macros.h"
#include "utils/VeloxArrowUtils.h"

#include "velox/common/base/Nulls.h"
#include "velox/type/Type.h"
Expand Down Expand Up @@ -79,10 +78,11 @@ arrow::Status VeloxRssSortShuffleWriter::write(std::shared_ptr<ColumnarBatch> cb
VELOX_CHECK(numColumns >= 2);
auto pidBatch = veloxColumnBatch->select(veloxPool_.get(), {0});
auto pidArr = getFirstColumn(*(pidBatch->getRowVector()));
START_TIMING(cpuWallTimingList_[CpuWallTimingCompute]);
setSortState(RssSortState::kSort);
RETURN_NOT_OK(partitioner_->compute(pidArr, pidBatch->numRows(), batches_.size(), rowVectorIndexMap_));
END_TIMING();
{
SCOPED_TIMER(cpuWallTimingList_[CpuWallTimingCompute]);
setSortState(RssSortState::kSort);
RETURN_NOT_OK(partitioner_->compute(pidArr, pidBatch->numRows(), batches_.size(), rowVectorIndexMap_));
}
std::vector<int32_t> range;
range.reserve(numColumns);
for (int32_t i = 1; i < numColumns; i++) {
Expand All @@ -96,24 +96,27 @@ arrow::Status VeloxRssSortShuffleWriter::write(std::shared_ptr<ColumnarBatch> cb
auto veloxColumnBatch = VeloxColumnarBatch::from(veloxPool_.get(), cb);
VELOX_CHECK_NOT_NULL(veloxColumnBatch);
facebook::velox::RowVectorPtr rv;
START_TIMING(cpuWallTimingList_[CpuWallTimingFlattenRV]);
rv = veloxColumnBatch->getFlattenedRowVector();
END_TIMING();
{
SCOPED_TIMER(cpuWallTimingList_[CpuWallTimingFlattenRV]);
rv = veloxColumnBatch->getFlattenedRowVector();
}
if (partitioner_->hasPid()) {
auto pidArr = getFirstColumn(*rv);
START_TIMING(cpuWallTimingList_[CpuWallTimingCompute]);
setSortState(RssSortState::kSort);
RETURN_NOT_OK(partitioner_->compute(pidArr, rv->size(), batches_.size(), rowVectorIndexMap_));
END_TIMING();
{
SCOPED_TIMER(cpuWallTimingList_[CpuWallTimingCompute]);
setSortState(RssSortState::kSort);
RETURN_NOT_OK(partitioner_->compute(pidArr, rv->size(), batches_.size(), rowVectorIndexMap_));
}
auto strippedRv = getStrippedRowVector(*rv);
RETURN_NOT_OK(initFromRowVector(*strippedRv));
RETURN_NOT_OK(doSort(strippedRv, sortBufferMaxSize_));
} else {
RETURN_NOT_OK(initFromRowVector(*rv));
START_TIMING(cpuWallTimingList_[CpuWallTimingCompute]);
setSortState(RssSortState::kSort);
RETURN_NOT_OK(partitioner_->compute(nullptr, rv->size(), batches_.size(), rowVectorIndexMap_));
END_TIMING();
{
SCOPED_TIMER(cpuWallTimingList_[CpuWallTimingCompute]);
setSortState(RssSortState::kSort);
RETURN_NOT_OK(partitioner_->compute(nullptr, rv->size(), batches_.size(), rowVectorIndexMap_));
}
RETURN_NOT_OK(doSort(rv, sortBufferMaxSize_));
}
}
Expand Down
18 changes: 6 additions & 12 deletions cpp/velox/utils/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,11 @@ static inline void fastCopy(void* dst, const void* src, size_t n) {
facebook::velox::simd::memcpy(dst, src, n);
}

#define START_TIMING(timing) \
{ \
auto ptiming = &timing; \
facebook::velox::DeltaCpuWallTimer timer{ \
[ptiming](const facebook::velox::CpuWallTiming& delta) { ptiming->add(delta); }};

#define END_TIMING() }

#define SCOPED_TIMER(timing) \
auto ptiming = &timing; \
facebook::velox::DeltaCpuWallTimer timer{ \
[ptiming](const facebook::velox::CpuWallTiming& delta) { ptiming->add(delta); }};
#define SCOPED_TIMER(timing) \
do { \
auto ptiming = &timing; \
facebook::velox::DeltaCpuWallTimer timer{ \
[ptiming](const facebook::velox::CpuWallTiming& delta) { ptiming->add(delta); }}; \
} while (0)

} // namespace gluten