Skip to content

Add block batch reduce algorithm - #5177

Open
pfultz2 wants to merge 8 commits into
developfrom
block-batch-reduce
Open

Add block batch reduce algorithm#5177
pfultz2 wants to merge 8 commits into
developfrom
block-batch-reduce

Conversation

@pfultz2

@pfultz2 pfultz2 commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Technical Details

Changelog Category

Add a CHANGELOG.md entry for any option other than Not Applicable

    • Added: New functionality.
    • Changed: Changes to existing functionality.
    • Removed: Functionality or support that has been removed. (Compared to a previous release)
    • Optimized: Component performance that has been optimized or improved.
    • Resolved Issues: Known issues from a previous version that have been resolved.
    • Not Applicable: This PR is not to be included in the changelog.

Follow the LLVM AI Tool Use Policy for contributions using AI.

@gh-app-migraphx-bot-pr-write

Copy link
Copy Markdown
Test Batch New Rate (9f9e56) Old Rate (3a503c)* Diff Status
torchvision-resnet50 64 3,320.07 3,264.92 1.69%
torchvision-resnet50_fp16 64 7,873.94 7,548.67 4.31%
torchvision-densenet121 32 2,489.57 2,483.99 0.22%
torchvision-densenet121_fp16 32 5,017.88 5,004.24 0.27%
torchvision-inceptionv3 32 2,070.23 2,058.51 0.57%
torchvision-inceptionv3_fp16 32 4,447.23 4,416.99 0.68%
cadene-inceptionv4 16 817.04 820.61 -0.44%
cadene-resnext64x4 16 782.76 782.78 -0.00%
slim-mobilenet 64 8,374.57 8,386.36 -0.14%
slim-nasnetalarge 64 228.35 228.86 -0.22%
slim-resnet50v2 64 3,235.67 3,180.91 1.72%
bert-mrpc-onnx 8 1,171.69 1,168.84 0.24%
bert-mrpc-tf 1 510.14 498.63 2.31%
pytorch-examples-wlang-gru 1 367.65 473.35 -22.33% 🔴
pytorch-examples-wlang-lstm 1 541.35 384.83 40.67% 🔆
torchvision-resnet50_1 1 1,058.55 1,046.63 1.14%
cadene-dpn92_1 1 452.09 437.32 3.38%
cadene-resnext101_1 1 365.95 365.89 0.02%
onnx-taau-downsample 1 842.22 844.09 -0.22%
dlrm-criteoterabyte 1 32.25 32.42 -0.53%
dlrm-criteoterabyte_fp16 1 51.63 51.80 -0.33%
agentmodel 1 14,910.13 9,209.12 61.91% 🔆
unet_fp16 2 58.35 58.80 -0.76%
resnet50v1_fp16 1 1,461.17 1,366.11 6.96% 🔆
resnet50v1_int8 1 1,801.75 1,883.96 -4.36%
bert_base_cased_fp16 64 1,097.94 1,098.16 -0.02%
bert_large_uncased_fp16 32 345.76 345.59 0.05%
bert_large_fp16 1 207.11 206.59 0.25%
distilgpt2_fp16 16 2,093.52 2,092.89 0.03%
yolov5s 1 561.85 558.33 0.63%
tinyllama 1 45.77 45.83 -0.13%
vicuna-fastchat 1 44.27 44.20 0.15%
whisper-tiny-encoder 1 412.44 411.87 0.14%
whisper-tiny-decoder 1 411.68 408.48 0.78%
llama2_7b 1 20.86 20.84 0.10%
qwen1.5-7b 1 23.66 23.58 0.35%
phi3-3.8b 1 28.36 26.72 6.16% 🔆
llama3-8b 1 22.68 21.80 4.01%
whisper-large-encoder 1 10.16 10.18 -0.14%
whisper-large-decoder 1 107.98 105.30 2.55%
mistral-7b 1 23.80 23.78 0.09%
FLUX.1-schnell 1 786.44 755.22 4.13%

Regressions detected 🔴

* No develop baseline was found for this PR's branch point; compared against the latest available develop run instead.

@gh-app-migraphx-bot-pr-write

Copy link
Copy Markdown
Test Status Result
bert-mrpc-onnx PASSED: MIGraphX meets tolerance
bert-mrpc-tf ERROR - check error output
traceback
Traceback (most recent call last):
File "/src/AMDMIGraphX/tools/accuracy/accuracy_checker.py", line 377, in
main()
File "/src/AMDMIGraphX/tools/accuracy/accuracy_checker.py", line 313, in main
import tensorflow as tf
File "/usr/local/lib/python3.12/dist-packages/tensorflow/init.py", line 40, in
from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow # pylint: disable=unused-import
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 37, in
self_check.preload_check()
File "/usr/local/lib/python3.12/dist-packages/tensorflow/python/platform/self_check.py", line 63, in preload_check
from tensorflow.python.platform import _pywrap_cpu_feature_guard
ImportError: libnuma.so.1: cannot open shared object file: No such file or directory
pytorch-examples-wlang-gru 🔴 FAILED: MIGraphX is not within tolerance - check verbose output
pytorch-examples-wlang-lstm 🔴 FAILED: MIGraphX is not within tolerance - check verbose output
dlrm-criteoterabyte PASSED: MIGraphX meets tolerance
agentmodel PASSED: MIGraphX meets tolerance
unet PASSED: MIGraphX meets tolerance
resnet50v1 PASSED: MIGraphX meets tolerance
bert_base_cased_fp16 PASSED: MIGraphX meets tolerance
bert_large_uncased_fp16 🔴 FAILED: MIGraphX is not within tolerance - check verbose output
bert_large PASSED: MIGraphX meets tolerance
yolov5s PASSED: MIGraphX meets tolerance
tinyllama PASSED: MIGraphX meets tolerance
vicuna-fastchat PASSED: MIGraphX meets tolerance
whisper-tiny-encoder PASSED: MIGraphX meets tolerance
whisper-tiny-decoder PASSED: MIGraphX meets tolerance
distilgpt2_fp16 🔴 FAILED: MIGraphX is not within tolerance - check verbose output
llama2_7b PASSED: MIGraphX meets tolerance
qwen1.5-7b PASSED: MIGraphX meets tolerance
phi3-3.8b PASSED: MIGraphX meets tolerance
llama3-8b PASSED: MIGraphX meets tolerance
whisper-large-encoder PASSED: MIGraphX meets tolerance
whisper-large-decoder PASSED: MIGraphX meets tolerance
mistral-7b PASSED: MIGraphX meets tolerance
FLUX.1-schnell PASSED: MIGraphX meets tolerance

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

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.

Comment on lines +323 to +327
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();
}))
Comment on lines +593 to +597
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;
}
Comment on lines +275 to +279
/// 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)
@pfultz2
pfultz2 marked this pull request as ready for review August 31, 2026 18:20
@pfultz2
pfultz2 requested a review from causten as a code owner August 31, 2026 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants