fix(warp_reduce): add explicit add_op overload to resolve CUB template ambiguity on CUDA 13.2+#3050
fix(warp_reduce): add explicit add_op overload to resolve CUB template ambiguity on CUDA 13.2+#3050zbrad wants to merge 3 commits into
Conversation
…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.
| { | ||
| assert(gridDim.x == 1); | ||
| int th_val = input[threadIdx.x]; | ||
| th_val = raft::warpReduce(th_val, raft::add_op{}); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
|
@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. |
|
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. |
|
Thanks for the reproducer documentation! I feel uneasy about both suggested workarounds:
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?.. |
There was a problem hiding this comment.
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
.gitignoreto 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.
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds an explicit ChangesWarp reduction overload
Build artifact ignore rules
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
.gitignorecpp/include/raft/util/reduction.cuhcpp/tests/util/reduction.cu
| @@ -1,3 +1,10 @@ | |||
| ## build logs | |||
| build_*.log | |||
There was a problem hiding this comment.
🎯 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.
| 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.
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{}), bothraft::warpReduce<T, ReduceLambda>andcub::detail::scan::warpReduce<Tp, ScanOpT&>match, producing a compile error.Fix: Add an explicit non-template overload in
cpp/include/raft/util/reduction.cuh:The explicit overload is preferred by the compiler over the generic
ReduceLambdaoverload, resolving the ambiguity without changing any existing behavior.cpp/include/raft/util/reduction.cuh— explicitraft::add_opoverload forwarpReducecpp/tests/util/reduction.cu— regression test (WARP_REDUCE_WITH_ADD_OP) to prevent future regressionsRepro / 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:
Test plan
WARP_REDUCE_WITH_ADD_OPregression test added incpp/tests/util/reduction.cuwarpReducebehavior — explicit overload only activates forraft::add_op🤖 Generated with Claude Code