Repository navigation
Implement parallel final reduction in BlockReduceWarp - #9101
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 Walkthrough
Comment |
|
@charan-003, thanks a lot for the contribution. Even before starting the review, I would like to see if there are actual performance benefits for this approach. |
sure, working on it |
0b48748 to
cb6dd6c
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
cub/cub/block/specializations/block_reduce_warp_reductions.cuh (2)
125-125: 💤 Low valuesuggestion: Use
static_cast<int>(warps)instead of C-style castint(warps)for consistency with thestatic_castused in the same expression.- const int num_warps = FullTile ? int(warps) : static_cast<int>(::cuda::ceil_div(num_valid, logical_warp_size)); + const int num_warps = FullTile ? static_cast<int>(warps) : static_cast<int>(::cuda::ceil_div(num_valid, logical_warp_size));
148-148: 💤 Low valuesuggestion: Per coding guidelines, variables not modified should be
const.dummy_storageis only passed to the constructor.- NullType dummy_storage; + const NullType dummy_storage{};
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: ffc63f63-2430-4ac6-8a11-ae99c579665d
📒 Files selected for processing (1)
cub/cub/block/specializations/block_reduce_warp_reductions.cuh
|
@charan-003 thanks for reporting them but I think a better approach would be:
|
Thanks a lot for the guidance! I didn't know the exact process... |
830c2b4 to
a949e20
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 53e3ccfa-d3a5-484a-85fd-7cf18e522152
📒 Files selected for processing (3)
ci/bench.yamlcub/benchmarks/bench/reduce/block_reduce_warp_reductions_base.cuhcub/benchmarks/bench/reduce/block_reduce_warp_reductions_sum.cu
✅ Files skipped from review due to trivial changes (1)
- cub/benchmarks/bench/reduce/block_reduce_warp_reductions_sum.cu
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 519c38f3-5544-4f5a-9750-fc04a66589e0
📒 Files selected for processing (3)
ci/bench.yamlcub/benchmarks/bench/reduce/block_reduce_warp_reductions_base.cuhcub/benchmarks/bench/reduce/block_reduce_warp_reductions_sum.cu
✅ Files skipped from review due to trivial changes (1)
- ci/bench.yaml
This comment was marked as resolved.
This comment was marked as resolved.
This comment has been minimized.
This comment has been minimized.
|
@fbusato the benchmarks shows a slowdown. can we use bit_ceil(warps) for the logical warp size. Does this approach look reasonable, or would you suggest a different direction? |
|
The code looks good and I really like the simplifications. Related to performance, some high-level thoughts:
|
This comment was marked as resolved.
This comment was marked as resolved.
|
@charan-003 sorry for the delay. Please ping me every time you need to trigger the CI |
This comment has been minimized.
This comment has been minimized.
| // Without it, a simple unrolled loop over <=31 values is just as fast. | ||
| constexpr bool use_warp_redux_path = | ||
| (WarpAggregateThreshold == -1) | ||
| && is_warp_redux_op_supported_sm80<ReductionOp, T> && ::cuda::has_identity_element_v<ReductionOp, T>; |
There was a problem hiding this comment.
| && is_warp_redux_op_supported_sm80<ReductionOp, T> && ::cuda::has_identity_element_v<ReductionOp, T>; | |
| && is_warp_redux_op_supported<ReductionOp, T> && ::cuda::has_identity_element_v<ReductionOp, T>; |
| FullTile ? warps : (::cuda::std::min) (::cuda::ceil_div(num_valid, logical_warp_size), +warps); | ||
|
|
||
| return warp_aggregate; | ||
| constexpr bool has_identity = ::cuda::has_identity_element_v<ReductionOp, T>; |
There was a problem hiding this comment.
I think cuda::identity_element is no more needed
This comment was marked as resolved.
This comment was marked as resolved.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@fbusato @pauleonix, those failures appear unrelated to this PR. |
This comment was marked as resolved.
This comment was marked as resolved.
|
@charan-003 No, it can be merged as is once CI is green. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
This can be merged with perf comparison results on affected SASS algorithms |
|
thanks @gevtushenko, the SASS differences point to actual performance regressions. @charan-003 there are two main issues for performance: (1) The following check // Nothing to reduce when the tile has no valid items.
if constexpr (!FullTile)
{
if (num_valid <= 0)
{
return warp_aggregate;
}
}is not needed in the sequential reduction path. (2) if (FullTile || (warp_idx * logical_warp_size < num_valid))
{
warp_aggregate = reduction_op(warp_aggregate, temp_storage.warp_aggregates[warp_idx]);
}this is bad for performance because most reduction operators take their argument by reference, and here the reference is a shared memory location, not a register. The original pattern is the right one const auto addend = temp_storage.warp_aggregates[warp_idx];
warp_aggregate = reduction_op(warp_aggregate, addend); |
This comment was marked as resolved.
This comment was marked as resolved.
🥳 CI Workflow Results🟩 Finished in 1d 20h: Pass: 100%/204 | Total: 14d 07h | Max: 4h 07m | Hits: 34%/781641See results here. |
|
@charan-003, thanks a lot for the contribution! the task was much more challenging than I originally thought! you didn't give up even if it took a long time. That's great! |
i learnt a lot from this too, and i really appreciate the guidance from you and @pauleonix throughout the process. it was definitely challenging, but that made it even more rewarding. Thanks for being so supportive and patient throughout the whole PR! |
Closes #5167
Replace sequential aggregation with cooperative warp reduction
Benchmark Comparison:
optimize_blockreducevsorigin/mainrtxa6000 — cub.bench.reduce.min.base
[0] NVIDIA RTX A6000
Summary: Total Matches: 56 — Pass: 28 / Failure: 28
rtxa6000 — cub.bench.reduce.sum.base
[0] NVIDIA RTX A6000
Summary: Total Matches: 64 — Pass: 43 / Failure: 21
h100 — cub.bench.reduce.sum.base
[0] NVIDIA H100
Summary: Total Matches: 64 — Pass: 44 / Failure: 20
Details
h100 — cub.bench.reduce.min.base
[0] NVIDIA H100 PCIe
Summary: Total Matches: 56 — Pass: 49 / Failure: 7
rtxpro6000 — cub.bench.reduce.sum.base
[0] NVIDIA RTX Pro 6000
Summary: Total Matches: 64 — Pass: 34 / Unknown: 8 / Failure: 22
rtxpro6000 — cub.bench.reduce.min.base
[0] NVIDIA RTX PRO 6000 Blackwell Server Edition
Summary: Total Matches: 56 — Pass: 39 / Unknown: 8 / Failure: 9