Skip to content

[FEA] ANSI SQL Operator JIT Support (3) : Refactor operator library - #22836

Merged
rapids-bot[bot] merged 18 commits into
NVIDIA:mainfrom
lamarrr:ansi-jit-2--1--operators-refactoring
Jun 23, 2026
Merged

[FEA] ANSI SQL Operator JIT Support (3) : Refactor operator library#22836
rapids-bot[bot] merged 18 commits into
NVIDIA:mainfrom
lamarrr:ansi-jit-2--1--operators-refactoring

Conversation

@lamarrr

@lamarrr lamarrr commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Description

Follows up #22514.
Implements refactoring and bug fixes for the operator library:

  • renames the bit_* operators to bitwise_* for consistency with AST operator names
  • renames cast_to_b8 to cast_to_bool8 and other cast_to_* functions for consistency with existing AST operator names
  • renames ansi_* arithmetic to use _overflow and ansi_precision_check to precision_check for consistency with CUDF's operators
  • updates binary operators to use double template types (to make it usable with AST's double dispatch mechanism)
  • removes invalid .overflow checks in the ANSI operators
  • fixes error returns in ANSI operators (return std::unexpected)
  • removes cuda::std::convertible_to concept checks, which are not available in CUDA 12.2
  • properly constrains if_else operator to avoid ambiguous argument deduction
  • moves the error code enum to a public header
  • adds to_string function for the error code enum --- to be used in exceptions
  • refactors the transform kernel
  • removes nullify_if as it is not necessary for a first PoC for ANSI support
  • Fixes call to detail::decimal_cast in cast_to_decimal_* functions.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@copy-pr-bot

copy-pr-bot Bot commented Jun 10, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@github-actions github-actions Bot added libcudf Affects libcudf (C++/CUDA) code. CMake CMake build issue labels Jun 10, 2026
@lamarrr
lamarrr force-pushed the ansi-jit-2--1--operators-refactoring branch from 919caa4 to c738c00 Compare June 10, 2026 14:17
@lamarrr lamarrr added feature request New feature or request non-breaking Non-breaking change labels Jun 10, 2026
@lamarrr
lamarrr marked this pull request as ready for review June 10, 2026 14:26
@lamarrr
lamarrr requested a review from a team as a code owner June 10, 2026 14:26
@lamarrr lamarrr changed the title [FEA] Refactor operator library [FEA] ANSI SQL Operator JIT Support (3) : Refactor operator library Jun 10, 2026
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Refactors operator helpers (bitwise, casts, ANSI arithmetic, logic, null handling), migrates internal error enum to cudf::errc, updates AST invoker mappings to renamed helpers, and inlines transform kernel operation dispatch.

Changes

Operator Library and Transform Kernel Refactoring

Layer / File(s) Summary
Error handling infrastructure migration
cpp/include/cudf/errc.hpp, cpp/include/cudf/detail/operators/ansi_arithmetic.cuh, cpp/include/cudf/detail/operators/operators.cuh
Introduces public cudf::errc enum with SUCCESS, OVERFLOW, DIVISION_BY_ZERO codes and to_string() helper; removes internal cudf/detail/operators/error.hpp; updates operator headers to include the public error type.
Bitwise operator renaming
cpp/include/cudf/detail/operators/bitwise.cuh, cpp/include/cudf/ast/detail/operator_functor.cuh
Renames bit_and, bit_invert, bit_or, bit_xor, bit_shift_left, bit_shift_right to bitwise_and, bitwise_invert, bitwise_or, bitwise_xor, bitwise_shift_left, bitwise_shift_right and updates AST invoker mappings to call the new names.
Cast operator renaming and constraint updates
cpp/include/cudf/detail/operators/casts.cuh, cpp/include/cudf/ast/detail/operator_functor.cuh
Renames cast helpers to explicit type names (cast_to_bool8, cast_to_int8-64, cast_to_uint8-64, cast_to_float32-64, cast_to_decimal32-128); replaces convertible_to constraints with static_cast validity requires; generalizes rescale template parameter; updates decimal cast implementations and AST cast mappings.
ANSI arithmetic operator template refactoring
cpp/include/cudf/detail/operators/ansi_arithmetic.cuh
Converts ansi_add, ansi_sub, ansi_mul, ansi_div, ansi_mod from single-type to constrained two-parameter templates (A, B with requires(cuda::std::same_as<A, B>)); updates overflow-detection calls to new helper style; changes decimal modulus error propagation to return unexpected{error()} on missing value; generalizes ansi_precision_check to accept any integral precision type.
Utility operator generalization
cpp/include/cudf/detail/operators/logic.cuh, cpp/include/cudf/detail/operators/null_handling.cuh
Updates if_else to accept any cuda::std::integral predicate type instead of bool; refactors coalesce to use two-parameter template form with type-equality constraints; removes nullify_if helper.
AST operator functor dispatch updates
cpp/include/cudf/ast/detail/operator_functor.cuh
Updates AST operator invoker mappings to dispatch bitwise operations to renamed bitwise_* helpers and cast operations to renamed cast_to_int64/uint64/float64 helpers.
Transform kernel operation dispatch inlining
cpp/src/transform/jit/kernel.cu
Removes execute_transform_op device helper and inlines operation dispatch logic; builds a lambda that conditionally applies GENERIC_TRANSFORM_OP with or without user data using cuda::std::apply; renames loop variable from element_idx to row.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

  • rapidsai/cudf#22514: Updates the same ANSI operator-library building blocks and helper APIs adjusted in this PR.

Suggested labels

3 - Ready for Review

Suggested reviewers

  • bdice
  • devavret
  • mhaseeb123
  • wence-
  • vyasr
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main objective of the PR, which is refactoring the operator library to support ANSI SQL operator JIT. It captures the core change without excessive detail.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description clearly relates to the changeset and covers all major modifications including operator renames, template updates, error handling fixes, and kernel refactoring.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cpp/src/transform/jit/kernel.cu`:
- Around line 49-50: The loop body in the operation lambda calls __ballot_sync
with a hard-coded full mask while threads that meet row >= row_size may have
exited the loop, causing undefined behavior; replace the hard-coded mask usage
in the null-aware path (where __ballot_sync is invoked) with an active-thread
mask (e.g., use __activemask() or compute a mask from the per-lane predicate) so
only participating lanes are included, and ensure any subsequent warp-wide sync
uses the same mask; update references around the operation lambda and the
null-aware ballot call to use that computed mask instead of 0xFFFF'FFFFU.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 266f14c1-7ea0-4d98-8c68-ab2ca7f21bf0

📥 Commits

Reviewing files that changed from the base of the PR and between 023a6f5 and c738c00.

📒 Files selected for processing (10)
  • cpp/include/cudf/ast/detail/operator_functor.cuh
  • cpp/include/cudf/detail/operators/ansi_arithmetic.cuh
  • cpp/include/cudf/detail/operators/bitwise.cuh
  • cpp/include/cudf/detail/operators/casts.cuh
  • cpp/include/cudf/detail/operators/error.hpp
  • cpp/include/cudf/detail/operators/logic.cuh
  • cpp/include/cudf/detail/operators/null_handling.cuh
  • cpp/include/cudf/detail/operators/operators.cuh
  • cpp/include/cudf/errc.hpp
  • cpp/src/transform/jit/kernel.cu
💤 Files with no reviewable changes (1)
  • cpp/include/cudf/detail/operators/error.hpp

Comment thread cpp/src/transform/jit/kernel.cu
@bdice

bdice commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

removes cuda::std::convertible_to concept checks, they are not available in CUDA 12.2

We require a minimum of CUDA 12.9 for builds, is 12.9 supported? If so, this shouldn't be an issue.

@lamarrr

lamarrr commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

We require a minimum of CUDA 12.9 for builds, is 12.9 supported? If so, this shouldn't be an issue.

For JIT code, the C++ version & standard library headers are tied to the runtime CUDA version, not the build version

@bdice

bdice commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

For JIT code, the C++ version & standard library headers are tied to the runtime CUDA version, not the build version

Ouch. Was this something that passed CI previously? Do we have adequate CI test coverage of this area?

@lamarrr

lamarrr commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

Ouch. Was this something that passed CI previously? Do we have adequate CI test coverage of this area?

The existing operators are used and tested by AST; the new operators are used and tested in #22602.
Some C++ 20 features, like nested concepts on variadic arguments (requires (requires(T...){})) , silently fail on CUDA 12.2

Comment thread cpp/include/cudf/errc.hpp Outdated
Comment thread cpp/include/cudf/errc.hpp
Comment thread cpp/include/cudf/detail/operators/casts.cuh
Comment thread cpp/include/cudf/detail/operators/casts.cuh
Comment thread cpp/include/cudf/detail/operators/casts.cuh Outdated
Comment thread cpp/include/cudf/detail/operators/null_handling.cuh Outdated
Comment thread cpp/include/cudf/detail/operators/logic.cuh Outdated
Comment thread cpp/include/cudf/detail/operators/null_handling.cuh

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cpp/include/cudf/detail/operators/casts.cuh`:
- Around line 234-237: The rescale template currently accepts any signed_integer
Scale but unconditionally narrows new_scale to int32_t when constructing
numeric::scale_type, risking silent truncation; change the template to accept an
int32_t scale (e.g., template <typename R, signed_integer int32_t Scale> or
simply require Scale be int32_t) or, if you must support wider types, add an
explicit range check in rescale (check new_scale fits within int32_t bounds and
handle out-of-range cases by asserting/throwing/logging) before the static_cast
to int32_t when constructing numeric::scale_type for
numeric::decimal<R>::rescaled.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: df584d1a-c591-4628-9e87-fff92a4ff64d

📥 Commits

Reviewing files that changed from the base of the PR and between ebc30dc and 214205e.

📒 Files selected for processing (1)
  • cpp/include/cudf/detail/operators/casts.cuh

Comment thread cpp/include/cudf/detail/operators/casts.cuh

@igorpeshansky igorpeshansky left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One remaining question/optional comment, otherwise LGTM :shipit:.

Comment thread cpp/include/cudf/detail/operators/casts.cuh Outdated
@lamarrr
lamarrr requested a review from bdice June 11, 2026 06:29
Comment thread cpp/include/cudf/detail/operators/ansi_arithmetic.cuh
Comment thread cpp/include/cudf/detail/operators/checked_arithmetic.cuh
Comment thread cpp/include/cudf/detail/operators/ansi_arithmetic.cuh
Comment thread cpp/include/cudf/errc.hpp
Comment thread cpp/src/transform/jit/kernel.cu

@PointKernel PointKernel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good. Docs are outdated but not blocking

Comment thread cpp/include/cudf/detail/operators/ansi_arithmetic.cuh Outdated
lamarrr added 2 commits June 17, 2026 09:41
Fixed ballot sync in transform kernel
@lamarrr

lamarrr commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

I believe all concerns have been addressed @PointKernel @igorpeshansky @mhaseeb123

@igorpeshansky igorpeshansky left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM :shipit:

@lamarrr

lamarrr commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@rapids-bot
rapids-bot Bot merged commit 8a3a49f into NVIDIA:main Jun 23, 2026
135 checks passed
mhaseeb123 pushed a commit to mhaseeb123/cudf that referenced this pull request Jun 24, 2026
…VIDIA#22836)

Follows up NVIDIA#22514.
Implements refactoring and bug fixes for the operator library:
- renames the `bit_*` operators to `bitwise_*` for consistency with AST operator names
- renames `cast_to_b8` to `cast_to_bool8` and other `cast_to_*` functions for consistency with existing AST operator names
- renames `ansi_*` arithmetic to use  `_overflow` and `ansi_precision_check` to `precision_check` for consistency with CUDF's operators
- updates binary operators to use double template types (to make it usable with AST's double dispatch mechanism)
- removes invalid `.overflow` checks in the ANSI operators
- fixes error returns in ANSI operators (return `std::unexpected`)
- removes `cuda::std::convertible_to` concept checks, which are not available in CUDA 12.2
- properly constrains `if_else` operator to avoid ambiguous argument deduction
- moves the error code enum to a public header
- adds `to_string` function for the error code enum --- to be used in exceptions
- refactors the transform kernel
- removes `nullify_if` as it is not necessary for a first PoC for ANSI support
- Fixes call to `detail::decimal_cast` in  `cast_to_decimal_*` functions.

Authors:
  - Basit Ayantunde (https://github.com/lamarrr)

Approvers:
  - Igor Peshansky (https://github.com/igorpeshansky)
  - Yunsong Wang (https://github.com/PointKernel)

URL: NVIDIA#22836
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CMake CMake build issue feature request New feature or request libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants