Skip to content

Conversation

@hikey-dj
Copy link

@hikey-dj hikey-dj commented Feb 2, 2026

Summary:

Adds a reusable GPU batch concatenation mechanism to coalesce small cuDF batches between GPU operators, improving kernel efficiency. Currently the operator is triggered after functions which may make the batches smaller and before filter projection.

Motivation:

After exchanges and some operators, GPU batches can become very small.
This change inserts a plan-level batch coalescing step in the cuDF adapter
without altering operator semantics.

Addresses #16105

@meta-cla
Copy link

meta-cla bot commented Feb 2, 2026

Hi @hikey-dj!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@netlify
Copy link

netlify bot commented Feb 2, 2026

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit c6dbbb5
🔍 Latest deploy log https://app.netlify.com/projects/meta-velox/deploys/6980c470e71e44000861f7a6

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 2, 2026
@meta-cla
Copy link

meta-cla bot commented Feb 2, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Copy link
Collaborator

@devavret devavret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a stab at this.

using TopNRowNumberNodePtr = std::shared_ptr<const TopNRowNumberNode>;

// A basic plan node for the GPU batch concatenation operation.
class CudfBatchConcatNode : public core::PlanNode {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We prefer keeping core velox untouched and utilize its extensibility to achieve cudf support.
Since we're relying on driver adapter, we don't need a separate plan node anyway.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you can, move this to a source inside experimental/cudf

@@ -0,0 +1,95 @@
#include "velox/experimental/cudf/CudfConfig.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file needs a license

Comment on lines +41 to +43
RowVectorPtr CudfBatchConcat::getOutput() {
// Drain the queue if there is any output to be flushed
if (!outputQueue_.empty()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend annotating this with an nvtx range.

Suggested change
RowVectorPtr CudfBatchConcat::getOutput() {
// Drain the queue if there is any output to be flushed
if (!outputQueue_.empty()) {
RowVectorPtr CudfBatchConcat::getOutput() {
VELOX_NVTX_OPERATOR_FUNC_RANGE();
// Drain the queue if there is any output to be flushed
if (!outputQueue_.empty()) {

Comment on lines +61 to +62
for (size_t i = 0; i < tables.size(); ++i) {
bool isLast = (i == tables.size() - 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be an interator based loop. currently i is used only for last, which can also be done with an iterator.

Comment on lines +65 to +72
// Do not push the last batch into the queue if it is smaller than
// targetRows_ But push it if it is the final batch
if (isLast && !noMoreInput_ && rowCount < targetRows_) {
currentNumRows_ = rowCount;
buffer_.push_back(
std::make_shared<CudfVector>(
pool(), outputType_, rowCount, std::move(tables[i]), stream));
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can go outside the loop. The instead of the loop this becomes two statements

  1. Move begin to end - 1 into outputQueue_ with some stl algo
  2. Check once at the end where the last one should go

Comment on lines +223 to +248
auto breaksBatchContinuity = [](const exec::Operator* op) {
return isAnyOf<
exec::LocalPartition,
exec::HashProbe,
exec::HashBuild,
exec::HashAggregation,
exec::StreamingAggregation,
exec::Limit,
exec::OrderBy,
exec::TopN,
CudfOperator>(op);
};

// Operators which are stateless and thus concat can safely be inserted before
auto isStatelessOperator = [](const exec::Operator* op) {
return isAnyOf<exec::FilterProject>(op);
};

// Determines if concat is needed before an operator
auto needsConcat = [breaksBatchContinuity, isStatelessOperator](
const exec::Operator* currentOp,
const exec::Operator* nextOp) {
// Add concat if current breaks batch and next is stateless
return currentOp != nullptr && nextOp != nullptr &&
breaksBatchContinuity(currentOp) && isStatelessOperator(nextOp);
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems too limiting. IIUC, with this, concat can only appear before FilterProject. A HashProbe should also be fairly easily able to take a concatenated batch. Similarly for HashAggregation. The operators that don't make sense having a concat before are the ones that do the concat themselves because they collect all input before emitting output. Like OrderBy and HashBuild

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants