Skip to content

fix(warp_reduce): add explicit add_op overload to resolve CUB template ambiguity on CUDA 13.2+#3050

Open
zbrad wants to merge 3 commits into
NVIDIA:mainfrom
zbrad:fix/warp-reduce-cub-ambiguity
Open

fix(warp_reduce): add explicit add_op overload to resolve CUB template ambiguity on CUDA 13.2+#3050
zbrad wants to merge 3 commits into
NVIDIA:mainfrom
zbrad:fix/warp-reduce-cub-ambiguity

Conversation

@zbrad

@zbrad zbrad commented Jun 8, 2026

Copy link
Copy Markdown

Summary

On CUDA 13.2 (SM 121, DGX Spark), IVF-PQ builds fail with an ambiguous template instantiation error. When CUB scan kernels call warpReduce(val, raft::add_op{}), both raft::warpReduce<T, ReduceLambda> and cub::detail::scan::warpReduce<Tp, ScanOpT&> match, producing a compile error.

Fix: Add an explicit non-template overload in cpp/include/raft/util/reduction.cuh:

template <typename T>
DI T warpReduce(T val, raft::add_op reduce_op)

The explicit overload is preferred by the compiler over the generic ReduceLambda overload, resolving the ambiguity without changing any existing behavior.

  • cpp/include/raft/util/reduction.cuh — explicit raft::add_op overload for warpReduce
  • cpp/tests/util/reduction.cu — regression test (WARP_REDUCE_WITH_ADD_OP) to prevent future regressions

Repro / context

Observed on DGX Spark (SM 121) with CUDA 13.2. The upstream CI does not test CUDA 13.2 / SM 121; the new test compiles and passes on all CUDA versions but will catch regressions if CUDA 13.2 support is added to CI.

Error seen without fix:

error: more than one instance of overloaded function "warpReduce" matches the argument list

Test plan

  • WARP_REDUCE_WITH_ADD_OP regression test added in cpp/tests/util/reduction.cu
  • Verified fix compiles and tests pass on CUDA 13.2 (SM 121, DGX Spark)
  • No changes to existing warpReduce behavior — explicit overload only activates for raft::add_op

🤖 Generated with Claude Code

…e ambiguity on CUDA 13.2

On CUDA 13.2 (SM 121, DGX Spark), IVF-PQ builds fail because both
raft::warpReduce<T, ReduceLambda> and cub::detail::scan::warpReduce<Tp, ScanOpT&>
match when called with raft::add_op{}, causing an ambiguous template instantiation.

Add an explicit non-template overload DI T warpReduce(T val, raft::add_op reduce_op)
in reduction.cuh. The explicit overload is preferred by the compiler, resolving ambiguity.

Also added a regression test WARP_REDUCE_WITH_ADD_OP to prevent future regressions.
@copy-pr-bot

copy-pr-bot Bot commented Jun 8, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@achirkin achirkin 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.

Thank you for reporting the issue! Could you please provide the reference/example where the bug is triggered? Normally, I'd assume the fix should be on the user side - just call the function with explicit namespace.

{
assert(gridDim.x == 1);
int th_val = input[threadIdx.x];
th_val = raft::warpReduce(th_val, raft::add_op{});

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.

Does this really cause an ambiguity without the extra overload in util/reduction.cuh? It's called here with raft namespace, so I doubt CUB overload is ever picked up here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It showed up for me when trying to do a full source rebuild of cuvs on the dgx spark. When finally debugging my build failure, it traced down to raft, but only showed up when building for arm64.

@zbrad zbrad Jun 8, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Oh, I have the cuvs regression test for it that I'm submitting to cuvs, it's at cpp/tests/regression/warp_reduce_add_op.cu

@divyegala

Copy link
Copy Markdown
Contributor

@zbrad can you provide steps to reproduce this bug? I have a DGX Spark, and I have been building CUDA 13.2 without any failures.

@zbrad

zbrad commented Jun 8, 2026

Copy link
Copy Markdown
Author

some other folks had asked for more background, so I went back and re-created the original failure from compiling cuvs. I've attached the doc and the repro.
warp reduce ambiguity doc
repro

@achirkin

achirkin commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Thanks for the reproducer documentation! I feel uneasy about both suggested workarounds:

  • raft extra overload: it doesn't protect us from someone else failing exactly the same way on another device operation.
  • cuvs swap to thrust::plus: because we have a best practice guideline to use the raft operations where possible.

Maybe we could make the raft's warpReduce template itself a bit more restrictive so it wouldn't get in the way of thrust+cub primitives?..

Copilot AI review requested due to automatic review settings July 25, 2026 20:09
@zbrad
zbrad requested a review from a team as a code owner July 25, 2026 20:09

Copilot AI 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.

Pull request overview

This PR addresses a CUDA 13.2+ (SM 121) compilation failure caused by ambiguous warpReduce overload resolution when CUB scan code interacts with raft::warpReduce(val, raft::add_op{}). It does so by adding a more-specific overload for raft::add_op, and adds a regression test to ensure this call remains unambiguous going forward.

Changes:

  • Add an explicit warpReduce(T, raft::add_op) overload to disambiguate overload resolution on CUDA 13.2+.
  • Add a regression kernel + gtest case to compile and validate warpReduce(val, raft::add_op{}) usage.
  • Update .gitignore to ignore build logs and aarch64 build artifacts.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

File Description
cpp/include/raft/util/reduction.cuh Adds an explicit raft::add_op overload for warpReduce to avoid CUDA 13.2+ ambiguity with CUB.
cpp/tests/util/reduction.cu Adds a regression test that exercises warpReduce(val, raft::add_op{}) in device code.
.gitignore Ignores build log files and aarch64 build output artifacts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Improved warp-level reduction compatibility with newer CUDA toolchains when using addition operations.
    • Prevented potential ambiguity with CUDA’s built-in reduction utilities.
  • Tests

    • Added coverage verifying correct warp-level sum results across supported data types and configurations.
  • Chores

    • Updated ignore rules for build logs and generated build artifacts.

Walkthrough

Adds an explicit raft::add_op overload for warpReduce, introduces CUDA regression coverage for that overload, and updates .gitignore for build logs and packaged artifacts.

Changes

Warp reduction overload

Layer / File(s) Summary
Add-operation warpReduce overload
cpp/include/raft/util/reduction.cuh
Adds a raft::add_op overload that forwards to logicalWarpReduce to avoid CUDA 13.2+ CUB overload ambiguity.
Add-operation regression tests
cpp/tests/util/reduction.cu
Adds a CUDA kernel, launch helper, fixture method, and parameterized test covering warpReduce with raft::add_op{}.

Build artifact ignore rules

Layer / File(s) Summary
Ignore generated build artifacts
.gitignore
Adds ignore patterns for build logs, aarch64 build output, and .tar.bz2 packages.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: copilot

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding an explicit raft::add_op overload to fix CUDA 13.2 template ambiguity.
Description check ✅ Passed The description accurately explains the same overload fix and the added regression test, matching the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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 @.gitignore:
- Line 2: Update the build log ignore pattern in .gitignore from build_*.log so
it matches the CI-generated telemetry-artifacts/build.log, using either
build*.log or the more explicit telemetry-artifacts/*.log pattern.
🪄 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: Pro Plus

Run ID: 2f2a9068-a215-4b39-a05f-66e896c967d6

📥 Commits

Reviewing files that changed from the base of the PR and between aa9a6d5 and 9fdbdf9.

📒 Files selected for processing (3)
  • .gitignore
  • cpp/include/raft/util/reduction.cuh
  • cpp/tests/util/reduction.cu

Comment thread .gitignore
@@ -1,3 +1,10 @@
## build logs
build_*.log

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Match the build log generated by CI.

.github/workflows/pr.yaml:401-402 writes telemetry-artifacts/build.log, but build_*.log only matches filenames beginning with build_. Use build*.log or the more explicit telemetry-artifacts/*.log.

Proposed fix
-build_*.log
+build*.log
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
build_*.log
build*.log
🤖 Prompt for 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.

In @.gitignore at line 2, Update the build log ignore pattern in .gitignore from
build_*.log so it matches the CI-generated telemetry-artifacts/build.log, using
either build*.log or the more explicit telemetry-artifacts/*.log pattern.

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

5 participants