Add block batch reduce algorithm - #5177
Conversation
Regressions detected 🔴 * No develop baseline was found for this PR's branch point; compared against the latest available develop run instead. |
|
… block-batch-reduce
There was a problem hiding this comment.
Pull request overview
Adds a batched GPU block-reduction algorithm for tiled fused reductions.
Changes:
- Adds batched accumulation, slicing, and result assignment.
- Adds JIT eligibility and tuning logic.
- Adds a cppcheck-safe math wrapper definition.
Review used a single pass without subagent fan-out. GPU verification on wave32 and wave64 remains necessary.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
reduce.hpp |
Implements the batched kernel algorithm. |
math.hpp |
Adds cppcheck macro handling. |
reduce.cpp |
Selects and tunes batched reductions. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if(any_of(ins->inputs(), [&](instruction_ref input) { | ||
| if(input->name() != "@param") | ||
| return false; | ||
| return input->get_shape().lens() == rlens or input->get_shape().broadcasted(); | ||
| })) |
| static std::size_t | ||
| batch_iterations(std::size_t n_per_block, std::size_t relements, std::size_t block_size) | ||
| { | ||
| return (n_per_block * relements) / block_size; | ||
| } |
| /// Like block_reduce but computes N independent reductions in one pass. The | ||
| /// iteration space covers N consecutive segments of relements elements and | ||
| /// each lane accumulates into the vector slot of the segment it is reading. | ||
| template <index_int N, class Op, class T, class Size, class F> | ||
| __device__ auto block_batch_reduce(index idx, Op op, T init, Size n, F f) |
|
Here is some perf numbers for batch 4 and 2 rows:
|
TedThemistokleous
left a comment
There was a problem hiding this comment.
Just one comment but wont block review for this - more style question
| auto noutputs = plan.finputs.size() - shapes.size() + 1; | ||
| auto tile = find_reduce_tile( | ||
| plan.virtual_inputs, noutputs, plan.reduce_output_shape, plan.reduction_shape.lens()); | ||
| assert(not ins->module_inputs().empty()); |
There was a problem hiding this comment.
Why not put this at the top of the function similar to compile()? No point in doing the work here if module inputs are empty
# Conflicts: # src/targets/gpu/jit/reduce.cpp
bdevorem
left a comment
There was a problem hiding this comment.
lgtm, but can you address the top two copilot comments? They look convincing
Motivation
Technical Details
Changelog Category
Add a
CHANGELOG.mdentry for any option other thanNot ApplicableFollow the LLVM AI Tool Use Policy for contributions using AI.