Skip to content

[CUB] Fully support warp redux - #9441

Merged
fbusato merged 11 commits into
NVIDIA:mainfrom
fbusato:redux-fp-max-min
Jun 17, 2026
Merged

fbusato merged 11 commits into
NVIDIA:mainfrom
fbusato:redux-fp-max-min

Conversation

@fbusato

@fbusato fbusato commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Description

I recently saw at least two PRs related to the warp reduction with specific dispatch for redux. Considering that the current dispatch logic is quite messy and there are additional optimizations, I create this PR:

  • Moved warp redux code to a dedicated header.
  • Added sm100a/f redux.sync.min/max.f32 for float
  • __half and __nv_bfloat16 min/max are also handled by promoted them to float.
  • The new warp_redux function returns cuda::std::optional to greatly simplify the calling dispatch.
  • Provided specific traits to understand when redux is valid.

Todo:

  • sass comparison/benchmarks

@fbusato fbusato self-assigned this Jun 12, 2026
@fbusato
fbusato requested a review from a team as a code owner June 12, 2026 23:45
@fbusato fbusato added the cub For all items related to CUB label Jun 12, 2026
@fbusato fbusato added this to CCCL Jun 12, 2026
@fbusato
fbusato requested a review from elstehle June 12, 2026 23:45
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jun 12, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Jun 12, 2026
@coderabbitai

coderabbitai Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

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

Introduces warp-level REDUX reduction dispatch for SM80 and SM100f architectures via new warp_redux.cuh with trait-gated backends and optional return type. Updates look_ahead, batched_wspro, and shfl to use the new dispatcher. Removes deprecated is_redux_enabled_cuda_operator trait. Adds floating-point redux tests.

Changes

Warp REDUX dispatch and consumers

Layer / File(s) Summary
warp_redux.cuh: SM80/SM100f dispatch and implementations
cub/cub/warp/specializations/warp_redux.cuh
New file defines compile-time support traits (is_warp_redux_op_supported_sm80, is_warp_redux_op_supported_sm100f, is_warp_redux_op_supported), implements warp_redux_sm80 using CUDA __reduce_*_sync intrinsics with integral type promotion and operator validation, implements warp_redux_sm100f using inline PTX float min/max helpers guarded by __cccl_ptx_isa >= 860, and exports warp_redux dispatcher returning optional<T> with NV_IF_TARGET backend selection.
look_ahead.cuh: integrate warp_redux_sm80
cub/cub/detail/warpspeed/look_ahead.cuh
Adds warp_redux.cuh and is_same.h includes. Updates warpIncrementalLookahead SM80 path to dispatch via is_warp_redux_op_supported_sm80 and call warp_redux_sm80 when supported, falling back to existing warp_reduce_t path for unsupported cases.
warp_reduce_batched_wspro.cuh: integrate generic warp_redux
cub/cub/warp/specializations/warp_reduce_batched_wspro.cuh
Adds warp_redux.cuh include. ReduceRedux signature changes from void to [[nodiscard]] bool. Reduce dispatches via is_warp_redux_op_supported with early return on ReduceRedux bool result. Replaces reduce_op_sync with warp_redux call; checks optional result before dereferencing and writing intermediate_outputs, returns false on failure or true on success.
warp_reduce_shfl.cuh: replace reduce_op_sync with warp_redux
cub/cub/warp/specializations/warp_reduce_shfl.cuh
Adds warp_redux.cuh include, removes internal reduce_op_sync helper. Updates ALL_LANES_VALID fast-path to dispatch via is_warp_redux_op_supported and call warp_redux, returning optional result when available.
thread_operators.cuh: remove is_redux_enabled_cuda_operator
cub/cub/thread/thread_operators.cuh
Removes is_redux_enabled_cuda_operator trait and TODO comment; functionality replaced by architecture-specific is_warp_redux_op_supported predicates.
catch2_test_warp_reduce.cu: floating-point redux tests
cub/test/warp/catch2_test_warp_reduce.cu
Adds floating_point_redux_type_list containing float and conditionally __half and __nv_bfloat16. New test case WarpReduce::Max/Min, floating-point redux types runs over new type list, uses verify_results_exact for float and verify_results for other types.

Suggested reviewers

  • davebayer
  • pauleonix
  • miscco
  • bernhardmgruber

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

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 6

🧹 Nitpick comments (4)
cub/cub/warp/specializations/warp_redux.cuh (4)

1-2: 📐 Maintainability & Code Quality | 💤 Low value

suggestion: SPDX license identifier should be BSD-3-Clause for full compliance.


65-73: 📐 Maintainability & Code Quality | 💤 Low value

suggestion: Per coding guidelines, unmodified parameters and local variables should be const. mask parameter and value local are not modified.

 template <typename T, typename ReductionOp>
 [[nodiscard]] _CCCL_DEVICE_API _CCCL_FORCEINLINE T
-warp_redux_sm80(const T input, const ::cuda::std::uint32_t mask, ReductionOp)
+warp_redux_sm80(const T input, const ::cuda::std::uint32_t mask, ReductionOp) noexcept
 {
   static_assert(is_warp_redux_op_supported_sm80<ReductionOp, T>, "Reduction operator not supported");
   _CCCL_ASSERT(mask != 0, "Mask must not be 0");
 
-  using promotion_t = ::cuda::std::conditional_t<::cuda::std::is_signed_v<T>, int, unsigned>;
-  const auto value  = static_cast<promotion_t>(input);
+  using promotion_t  = ::cuda::std::conditional_t<::cuda::std::is_signed_v<T>, int, unsigned>;
+  const promotion_t value = static_cast<promotion_t>(input);

Source: Coding guidelines


110-121: 🚀 Performance & Scalability | 💤 Low value

suggestion: The macro-generated PTX functions use asm volatile but the reduction is a pure read operation with no memory side effects. Consider asm without volatile to allow compiler optimization, or add a brief comment explaining why volatile is necessary (e.g., if required for synchronization semantics).


131-149: 📐 Maintainability & Code Quality | 💤 Low value

suggestion: Per guidelines, value and result locals should be const where possible. value is not modified after initialization.

 template <typename T, typename ReductionOp>
 [[nodiscard]] _CCCL_DEVICE_API
-_CCCL_FORCEINLINE T warp_redux_sm100af(const T input, const ::cuda::std::uint32_t mask, ReductionOp)
+_CCCL_FORCEINLINE T warp_redux_sm100af(const T input, const ::cuda::std::uint32_t mask, ReductionOp) noexcept
 {
   static_assert(is_warp_redux_op_supported_sm100af<ReductionOp, T>, "Reduction operator not supported");
   _CCCL_ASSERT(mask != 0, "Mask must not be 0");
 
   const float value = ::cuda::std::__fp_cast<float>(input);
-  float result;
+  const float result = [&]() {
   if constexpr (is_cuda_minimum_v<ReductionOp, T>)
   {
-    result = cub::detail::redux_sm100af_min_ptx(value, mask);
+    return ::cub::detail::redux_sm100af_min_ptx(value, mask);
   }
   else
   {
-    result = cub::detail::redux_sm100af_max_ptx(value, mask);
+    return ::cub::detail::redux_sm100af_max_ptx(value, mask);
   }
+  }();
   return ::cuda::std::__fp_cast<T>(result);
 }

Alternatively, keep the current structure but add const where applicable and fully qualify cub::detail:: as ::cub::detail::.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 66046a44-cb32-43c6-8ce3-c6b5f927aa61

📥 Commits

Reviewing files that changed from the base of the PR and between 8c0e6cb and 2261919.

📒 Files selected for processing (6)
  • cub/cub/detail/warpspeed/look_ahead.cuh
  • cub/cub/thread/thread_operators.cuh
  • cub/cub/warp/specializations/warp_reduce_batched_wspro.cuh
  • cub/cub/warp/specializations/warp_reduce_shfl.cuh
  • cub/cub/warp/specializations/warp_redux.cuh
  • cub/test/warp/catch2_test_warp_reduce.cu
💤 Files with no reviewable changes (1)
  • cub/cub/thread/thread_operators.cuh

Comment on lines +464 to 470
if constexpr (ALL_LANES_VALID && is_warp_redux_op_supported<ReductionOp, T>)
{
NV_IF_TARGET(NV_PROVIDES_SM_80, (return reduce_op_sync(input, member_mask, reduction_op);))
if (const auto output = cub::detail::warp_redux(input, member_mask, reduction_op))
{
return *output;
}
}

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.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

suggestion: Per coding guidelines, trait and function call should be fully qualified with :: prefix.

-    if constexpr (ALL_LANES_VALID && is_warp_redux_op_supported<ReductionOp, T>)
+    if constexpr (ALL_LANES_VALID && ::cub::detail::is_warp_redux_op_supported<ReductionOp, T>)
     {
-      if (const auto output = cub::detail::warp_redux(input, member_mask, reduction_op))
+      if (const auto output = ::cub::detail::warp_redux(input, member_mask, reduction_op))
       {
         return *output;
       }
     }

Source: Coding guidelines

Comment on lines +163 to +170
NV_IF_TARGET(NV_PROVIDES_SM_80, (return cub::detail::warp_redux_sm80(input, mask, reduction_op);))
}
#if __cccl_ptx_isa >= 860
else if constexpr (is_warp_redux_op_supported_sm100af<ReductionOp, T>)
{
NV_IF_TARGET(NV_HAS_FEATURE_SM_100a, (return cub::detail::warp_redux_sm100af(input, mask, reduction_op);))
# if __cccl_ptx_isa >= 880
NV_IF_TARGET(NV_HAS_FEATURE_SM_100f, (return cub::detail::warp_redux_sm100af(input, mask, reduction_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.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

suggestion: Multiple call sites across warp_redux.cuh, look_ahead.cuh, warp_reduce_batched_wspro.cuh, and warp_reduce_shfl.cuh reference cub::detail:: functions/traits without the leading :: global namespace qualifier. Per coding guidelines, all free function calls and trait references must be fully qualified starting from global namespace (e.g., ::cub::detail::warp_redux(...)). This ensures ADL doesn't cause unexpected behavior and maintains consistency across the codebase.

Source: Coding guidelines

else
{
_CCCL_UNREACHABLE();
return T{};

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.

Should this be an optional as well? Its packed into one after return anyway

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it could be a good extension. For now, I would keep it as is because it used only one time

@github-actions

This comment has been minimized.

Co-authored-by: David Bayer <48736217+davebayer@users.noreply.github.com>

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: baabf63b-60f6-4346-ae5f-cf824bf3bffa

📥 Commits

Reviewing files that changed from the base of the PR and between 2261919 and d2c45d2.

📒 Files selected for processing (1)
  • cub/cub/warp/specializations/warp_redux.cuh

@github-actions

This comment has been minimized.

Co-authored-by: David Bayer <48736217+davebayer@users.noreply.github.com>
@davebayer

Copy link
Copy Markdown
Contributor

pre-commit.ci autofix

@copy-pr-bot

copy-pr-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

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.

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cub/cub/warp/specializations/warp_redux.cuh (1)

165-175: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

critical: #endif at line 174 has no matching #if. The inner #if __cccl_ptx_isa >= 880 at line 168 is closed by #endif at line 172. Line 174 is orphaned and will fail to compile.

Add the missing guard:

+#if __cccl_ptx_isa >= 860
   else if constexpr (is_warp_redux_op_supported_sm100f<ReductionOp, T>)
   {
     // Before PTX ISA 8.8, float reductions are only supported on sm100a.
 #  if __cccl_ptx_isa >= 880
     NV_IF_TARGET(NV_HAS_FEATURE_SM_100f, (return cub::detail::warp_redux_sm100f(input, mask, reduction_op);))
 #  else // ^^^ __cccl_ptx_isa >= 880 ^^^ / vvv __cccl_ptx_isa < 880 vvv
     NV_IF_TARGET(NV_HAS_FEATURE_SM_100a, (return cub::detail::warp_redux_sm100f(input, mask, reduction_op);))
 #  endif // ^^^ __cccl_ptx_isa < 880 ^^^
   }
 `#endif` // __cccl_ptx_isa >= 860

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: f1e5288b-be3b-4c37-8cdc-7d615b947197

📥 Commits

Reviewing files that changed from the base of the PR and between d2c45d2 and 2431a6d.

📒 Files selected for processing (1)
  • cub/cub/warp/specializations/warp_redux.cuh

@davebayer

Copy link
Copy Markdown
Contributor

/ok to test d008108

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
cub/cub/warp/specializations/warp_redux.cuh (3)

50-52: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

critical: Undefined symbol is_warp_redux_op_supported_sm100f — the trait is defined as is_warp_redux_op_supported_sm100af on line 46. This will fail to compile.

 template <typename Op, typename T>
 inline constexpr bool is_warp_redux_op_supported =
-  is_warp_redux_op_supported_sm80<Op, T> || is_warp_redux_op_supported_sm100f<Op, T>;
+  is_warp_redux_op_supported_sm80<Op, T> || is_warp_redux_op_supported_sm100af<Op, T>;

123-141: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

critical: Line 127 uses undefined is_warp_redux_op_supported_sm100f. Should be is_warp_redux_op_supported_sm100af to match the trait definition on line 46.

-  static_assert(is_warp_redux_op_supported_sm100f<ReductionOp, T>, "Reduction operator not supported");
+  static_assert(is_warp_redux_op_supported_sm100af<ReductionOp, T>, "Reduction operator not supported");

148-167: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

critical: Lines 161 and 163 call warp_redux_sm100f which is undefined — the function is defined as warp_redux_sm100af on line 125. Also, per past review feedback, use ::cub::detail:: prefix.

   else if constexpr (is_warp_redux_op_supported_sm100af<ReductionOp, T>)
   {
     // Before PTX ISA 8.8, float reductions are only supported on sm100a.
 `#if` __cccl_ptx_isa >= 880
-    NV_IF_TARGET(NV_HAS_FEATURE_SM_100f, (return cub::detail::warp_redux_sm100f(input, mask, reduction_op);))
+    NV_IF_TARGET(NV_HAS_FEATURE_SM_100f, (return ::cub::detail::warp_redux_sm100af(input, mask, reduction_op);))
 `#else` // ^^^ __cccl_ptx_isa >= 880 ^^^ / vvv __cccl_ptx_isa < 880 vvv
-    NV_IF_TARGET(NV_HAS_FEATURE_SM_100a, (return cub::detail::warp_redux_sm100f(input, mask, reduction_op);))
+    NV_IF_TARGET(NV_HAS_FEATURE_SM_100a, (return ::cub::detail::warp_redux_sm100af(input, mask, reduction_op);))
 `#endif` // ^^^ __cccl_ptx_isa < 880 ^^^
   }

Similarly, line 155 should use ::cub::detail::warp_redux_sm80.

🧹 Nitpick comments (1)
cub/cub/warp/specializations/warp_redux.cuh (1)

117-117: 💤 Low value

suggestion: Typo — "corresposing" should be "corresponding".


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: f8eb5788-efc4-4720-af83-27e811e14f14

📥 Commits

Reviewing files that changed from the base of the PR and between d008108 and 7b73f9a.

📒 Files selected for processing (1)
  • cub/cub/warp/specializations/warp_redux.cuh

@fbusato

fbusato commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

SASS comparison: no diff for sum benchmarks (as expected). SM100af min/max float replaces 5 SHFL.DOWN with CREDUX.MIN.F32

@fbusato

fbusato commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 2428754

@fbusato
fbusato enabled auto-merge (squash) June 15, 2026 19:17
@github-actions

This comment has been minimized.

@fbusato

fbusato commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 2428754

@github-actions

This comment has been minimized.

@fbusato

fbusato commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 8904168

@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 2h 41m: Pass: 100%/287 | Total: 11d 19h | Max: 2h 41m | Hits: 15%/1148788

See results here.

@fbusato
fbusato requested a review from davebayer June 16, 2026 19:56
@fbusato
fbusato merged commit ff3421b into NVIDIA:main Jun 17, 2026
307 checks passed
@fbusato fbusato mentioned this pull request Oct 13, 2026
19 of 27 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cub For all items related to CUB

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants