Skip to content

feat(compiler): keep stored shapes and lower integer conv and matmul - #1337

Draft
amd-mounikk wants to merge 15 commits into
mainfrom
gpuep/shape-merge-plus-quant-integer
Draft

amd-mounikk wants to merge 15 commits into
mainfrom
gpuep/shape-merge-plus-quant-integer

Conversation

@amd-mounikk

Copy link
Copy Markdown
Contributor

Summary

Related issue or design

Combines #1336 and #1248. #1336 follows up the Gemma-4 shape regression reported on #1306.

Why

The two changes do not touch the same lines. This branch is the single base that has the stored-shape compiler fix and the integer conv/matmul lowering together.

What

Test plan

  • pre-commit run --files on all 51 files changed versus main (passed: whitespace, end-of-file, large files, BOM, line endings, merge conflict, lintrunner, licenseheaders)
  • hip-mlir-opt --hip-infer-loop-body-shapes test/lit/Dialect/hip-infer-loop-body-shapes.mlir | FileCheck (passed)
  • hip-mlir-opt test/lit/Conversion/onnx-to-hip/test_split.mlir --hip-add-context-arg --convert-onnx-to-hip | FileCheck (passed)
  • Integer conv/matmul lit and numeric tests from feat(onnx-to-hip): lower quantized integer conv and matmul #1248 on this combined tree
  • Gemma-4 and the Topaz UNet on a full session

Notes for reviewers

The #1248 commits are unchanged. The shape commit is the #1336 patch cherry-picked onto that tip.

Drafted with Cursor assistance. I reviewed the stack, the pre-commit result, and the two FileCheck runs.

Checklist

  • The change is focused, or links a design/series explaining its scope.
  • Relevant tests were added or updated and the results are documented.
  • User-facing or design documentation was updated when needed.
  • Substantial AI assistance is disclosed, and I reviewed and understand the result.

Pragya0302 and others added 14 commits October 21, 2026 10:51
Decompose DynamicQuantizeLinear, ConvInteger, and MatMulInteger into existing HIP ops so a quantized graph can bufferize on both the HIP and rocMLIR paths.

Co-Authored-By: Cursor Grok 4.7 <cursoragent@cursor.com>
Made-with: Cursor
DynamicQuantizeLinear used an out-of-range axis on a vector, ReduceMin and ReduceMax rejected f32, and MatMulInteger checked batch broadcast without expanding it. An f32 dot product also drops bits once the reduction passes 258, so longer ConvInteger and MatMulInteger reductions now accumulate in int32.

Co-Authored-By: Cursor Grok 4.7 <cursoragent@cursor.com>
Made-with: Cursor
An i32 matmul passes B's batch stride so a shared matrix is not read past its end, and an integer convolution is not rewritten into hip.gemm. Wide i32 anchors stay on the HIP kernels. The f32 reduction clears the HIP last-error state before launch.

Co-Authored-By: Cursor Grok 4.7 <cursoragent@cursor.com>
Made-with: Cursor
Copying a rank-2 B into every batch allocates a separate matrix for a weight hip.matmul already reuses. Wide batched i32 matmul and an all-zero quantize now have exact numeric tests.

Co-Authored-By: Cursor Grok 4.7 <cursoragent@cursor.com>
Made-with: Cursor
The wide batched i32 matmul and the all-zero quantize now assert the execution provider output. A 259-channel i32 convolution stays hip.conv through the fusion pass.

Co-Authored-By: Cursor Grok 4.7 <cursoragent@cursor.com>
Made-with: Cursor
Co-authored-by: nvunnam57128 <261134987+nvunnam57128@users.noreply.github.com>
The i32 conv kernel was only checked on a 1x1 window. A reduction of 261 with stride, padding, two groups, and several output positions now checks the execution provider result.

Co-Authored-By: Cursor Grok 4.7 <cursoragent@cursor.com>
Made-with: Cursor
keepdims=0 drops the reduced axis, so trailing shape alignment treats a repeated extent as the inner suffix and reduces the wrong dimension.

Co-Authored-By: Cursor Grok 4.7 <cursoragent@cursor.com>
Made-with: Cursor
Widen 1-D NCL ConvInteger to the shared NC1L hip.conv path and collapse the result so int8 encoder convolutions bufferize.

Co-Authored-By: Cursor Grok 4.7 <cursoragent@cursor.com>
Made-with: Cursor
A data-dependent leading batch left ConvInteger and MatMulInteger unconverted. The runtime already reads that extent from the memref descriptor, so those ops can bufferize.

Co-Authored-By: Cursor Grok 4.7 <cursoragent@cursor.com>
Made-with: Cursor
A static rank-2 weight can be shared when the batch or M axis is dynamic. An uninferred K on A still accumulates in i32, and a per-row zero point still needs a static M.

Co-Authored-By: Cursor Grok 4.7 <cursoragent@cursor.com>
Made-with: Cursor
…t-integer

Keep the int32 matmul declaration alongside the channels-last causal convolution and GatedDeltaNet declarations.

Co-Authored-By: Cursor Grok 4.7 <cursoragent@cursor.com>
Made-with: Cursor
…t-integer

Keep the int32 matmul declaration alongside the DynamicSparseAttention and SparseAttentionIndexer declarations.

Co-Authored-By: Cursor Grok 4.7 <cursoragent@cursor.com>
Made-with: Cursor
A rule that only knows the rank was replacing a stored dimension with ?.
Merge each rule with the stored type, read constant bound inputs, and
rank AveragePool and attribute-form Upsample.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI balanced review requested due to automatic review settings October 26, 2026 14:42
@github-actions

Copy link
Copy Markdown

Thanks for opening a PR!

This project follows LLVM's incremental-development and AI-tool-use
guidance. See CONTRIBUTING.md
for the project workflow.

Before requesting review, please check that:

  1. The change is focused. Substantial work links the relevant issue
    or design discussion.
  2. The PR documents relevant test results and updates affected
    documentation.
  3. If AI tools provided substantial assistance, the description
    explains what was assisted and how it was validated, and commit
    trailers identify the tool. The contributor has reviewed and
    understands the result.

Reviewers are assigned through
CODEOWNERS where ownership
is configured.

@github-actions github-actions Bot added the large-pr Soft size threshold (>500 LOC or >10 files). Reviewer signal, not a block. label Oct 26, 2026

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.

🟡 Changes recommended

The new shape-inference paths can produce incorrect extents and perform an undefined integer conversion for common Slice bounds.

3 open issues
What changed in this PR

Combines the stored-shape preservation fix from #1336 with the integer convolution and matmul support from #1248, extending hip-ep’s quantized graph compilation.

Changes:

  • Preserve known result dimensions, infer additional ONNX shapes, and refine constant Split sizes.
  • Lower DynamicQuantizeLinear, ConvInteger, and MatMulInteger with supporting runtime kernels and compiler routing.
  • Add conversion, pipeline, and numeric tests, and document supported operations.
File Description
test/​numeric/​tests/​test_reduce.py Adds f32 ReduceMax coverage.
test/​numeric/​tests/​test_reduce_min.py Adds f32 ReduceMin coverage.
test/​numeric/​tests/​test_quantized_conv.py Tests dynamic quantization and integer convolution.
test/​numeric/​tests/​test_matmul_integer.py Tests integer matmul and batch handling.
test/​lit/​Transforms/​HipFusionTransform/​patch_embed_conv.mlir Checks integer convolution avoids GEMM fusion.
test/​lit/​e2e/​test_quantized_conv_model.mlir Checks quantized convolution pipeline lowering.
test/​lit/​e2e/​test_matmul_integer_wide.mlir Checks wide reductions use integer matmul.
test/​lit/​e2e/​test_matmul_integer_model.mlir Checks quantization-to-matmul pipeline lowering.
test/​lit/​e2e/​test_matmul_integer_dynamic.mlir Covers dynamic matmul batches.
test/​lit/​e2e/​test_matmul_integer_dynamic_sequence.mlir Covers dynamic matmul sequence lengths.
test/​lit/​e2e/​test_matmul_integer_dynamic_k.mlir Covers uninferred contraction dimensions.
test/​lit/​e2e/​test_integer_stays_on_hip.mlir Checks integer operations remain on HIP.
test/​lit/​e2e/​test_conv_integer_wide.mlir Checks wide integer convolution routing.
test/​lit/​e2e/​test_conv_integer_dynamic.mlir Covers dynamic convolution batches.
test/​lit/​e2e/​test_conv_integer_1d.mlir Covers rank-3 convolution lowering.
test/​lit/​Dialect/​hip-infer-loop-body-shapes.mlir Tests shape preservation and added inference rules.
test/​lit/​Conversion/​onnx-to-hip/​test_split.mlir Checks constant Split result extents.
test/​lit/​Conversion/​onnx-to-hip/​test_matmul_integer.mlir Tests integer matmul conversion variants.
test/​lit/​Conversion/​onnx-to-hip/​test_dynamic_quantize_linear.mlir Tests dynamic quantization decomposition.
test/​lit/​Conversion/​onnx-to-hip/​test_conv_integer.mlir Tests integer convolution conversion variants.
test/​lit/​Conversion/​hip-to-tosa/​test_matmul.mlir Checks integer matmul zero-point operands.
test/​lit/​Conversion/​hip-to-tosa/​test_conv.mlir Checks integer convolution TOSA operands.
test/​lit/​Conversion/​hip-to-llvm/​test_reduce_min.mlir Tests reduction strides with repeated dimensions.
test/​lit/​Conversion/​hip-to-llvm/​test_matmul.mlir Checks shared-weight integer matmul stride.
lib/​Runtime/​real/​reduce_min.cpp Enables f32 ReduceMin dispatch.
lib/​Runtime/​real/​reduce_max.cpp Enables f32 ReduceMax dispatch.
lib/​Runtime/​real/​matmul.cpp Adds the integer matmul runtime wrapper.
lib/​Runtime/​real/​conv.cpp Enables i32 convolution dispatch.
lib/​Runtime/​mock/​mock_gpu.cpp Adds the mock integer matmul wrapper.
lib/​Runtime/​Kernels/​include/​hip_custom_kernels.h Declares integer matmul and documents dtype support.
lib/​Runtime/​Kernels/​hip/​reduce_sum_kernel.hip Adds f32 generic reduction dispatch.
lib/​Runtime/​Kernels/​hip/​matmul_i32_kernel.hip Implements integer matmul accumulation.
lib/​Runtime/​Kernels/​hip/​conv_kernel.hip Implements integer convolution accumulation.
lib/​Runtime/​Kernels/​hip/​cast_kernel.hip Adds signed int8 casts and clears launch errors.
lib/​Runtime/​Kernels/​CMakeLists.txt Builds the integer matmul kernel.
lib/​Runtime/​hipdnn_ep_runtime.h Declares the integer matmul runtime ABI.
lib/​Dialect/​Transforms/​InferLoopBodyShapesPass.cpp Preserves stored sizes and extends shape inference.
lib/​Dialect/​Transforms/​fusion_pattern/​patch_embed_conv_to_gemm.cpp Excludes integer convolution from GEMM fusion.
lib/​Dialect/​Transforms/​FuseROCMlir.cpp Keeps i32 anchors on HIP kernels.
lib/​Conversion/​OnnxToHip/​ReshapeConversion.cpp Refines constant Split slice extents.
lib/​Conversion/​OnnxToHip/​OnnxToHipUtils.h Declares the new conversion registrations.
lib/​Conversion/​OnnxToHip/​OnnxToHip.cpp Registers the new ONNX conversions.
lib/​Conversion/​OnnxToHip/​MatMulIntegerConversion.cpp Decomposes integer matmul with accumulator selection.
lib/​Conversion/​OnnxToHip/​DynamicQuantizeLinearConversion.cpp Decomposes dynamic quantization into HIP operations.
lib/​Conversion/​OnnxToHip/​ConvIntegerConversion.cpp Decomposes integer convolution with accumulator selection.
lib/​Conversion/​OnnxToHip/​CMakeLists.txt Builds the new conversion sources.
lib/​Conversion/​HipToTosa/​HipToTosa.cpp Adds explicit integer zero-point operands.
lib/​Conversion/​HipToLLVM/​ReduceLowering.cpp Derives reduction strides from constant axes.
lib/​Conversion/​HipToLLVM/​MatmulLowering.cpp Routes i32 matmul to its runtime wrapper.
lib/​Conversion/​HipToLLVM/​HipToLLVMUtils.h Defines the integer matmul wrapper symbol.
docs/​supported-operations.md Documents quantized integer operation support.

Review effort: Balanced

Comment on lines +456 to +462
for (int64_t axis : *axisValues) {
if (axis < 0)
axis += rank;
if (axis < 0 || axis >= rank)
return {};
axes.push_back(axis);
}
Comment on lines +763 to +764
int64_t out = quot + 1;
shape[2 + s] = out > 0 ? out : 0;
Comment on lines +1287 to +1290
for (double element : tensor->data) {
if (!std::isfinite(element) || element != std::trunc(element))
return std::nullopt;
values.push_back(static_cast<int64_t>(element));
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Kernel Unit Test Results

Op Leaf Arch Cases Failed Suite (ms) Verdict
matmul_nbits Xfp16_Wu2_Yfp16 gfx1151 12 0 6570.5 PASS
matmul_nbits Xfp16_Wu3_Yfp16 gfx1151 12 0 6751.2 PASS
matmul_nbits Xfp16_Wu4_Yfp16 gfx1151 12 0 4498.5 PASS
matmul_nbits Xfp16_Wi8_Yfp16 gfx1151 12 0 5900.8 PASS
matmul_nbits Xfp32_Wu2_Yfp32 gfx1151 12 0 6649.2 PASS
matmul_nbits Xfp32_Wu3_Yfp32 gfx1151 12 0 7084.1 PASS
matmul_nbits Xfp32_Wu4_Yfp32 gfx1151 12 0 4944.9 PASS
matmul_nbits Xfp32_Wi8_Yfp32 gfx1151 12 0 5827.2 PASS
gqa/decode Xfp16_Wfp16_Yfp16 gfx1151 17 0 3356.5 PASS
gqa/decode Xfp16_Wi8_Yfp16 gfx1151 13 0 2491.6 PASS
gqa/prefill Xfp16_Wfp16_Yfp16 gfx1151 26 0 5179.9 PASS
gqa/prefill Xfp16_Wi8_Yfp16 gfx1151 9 0 4680.3 PASS
qmoe_ragged_mm Xfp16_Wu4_Yfp16 gfx1151 40 0 1662.6 PASS
gather_block_quantized Xi64_Wu4_Yfp16 gfx1151 32 0 953.6 PASS
gather_block_quantized Xi64_Wu8_Yfp16 gfx1151 32 0 282 PASS
gather_block_quantized Xi64_Wfp8_Yfp16 gfx1151 24 0 378.4 PASS

Leaves: 16 (0 failed) | Cases: 289 (0 failed)

Mode: lookup | Coverage: 1 | Run: 7972 - Commit: e7ec78e

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

L2 Accuracy Results (EP vs CPU)

Model Combined L2 Total Elems Skipped NaN/Inf
conv_test_hybrid 1.12256E-07 64 0
GroupQueryAttention_seq256 59.2561 2621440 0
MatMulNBits_o_seq128 259.905 368640 0
QMoE_seq128 24.2583 368640 0

Threshold: 0.01 | Run: 7972 - Commit: e7ec78e

@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Binary sizes

Baseline: run 40457802257 - ae1dc4f (dll-sizes)

File This (MB) Main (MB) Delta (MB)
hipgpu.dll 118.36 59.31 +59.05 FAIL
custom_kernels_gfx1170.dll 5.56 5.55 +0.01
custom_kernels_gfx11-generic.dll 5.81 5.79 +0.02

MorphiZen EP Performance Results

Model QPS Session (s) 1st Infer (ms) CPU% Mem (MB)
full_model_seq128 8.79 7.54 293 3 1162
GroupQueryAttention_seq128 11390.00 2.57527 1 5 232
matmul_down_seq128 508.07 3.25 119 3 276

EPContext Export Performance

Model QPS Session (s) 1st Infer (ms) CPU% Mem (MB)
full_model_seq128 8.83 48.33 246 3 15508

EPContext Import Performance

Model QPS Session (s) 1st Infer (ms) CPU% Mem (MB)
full_model_seq128 8.82 10.13 252 3 15640

OGA Benchmark Results

Model Warmup Reps Prompt Len Gen Tokens TTFT (ms) TPS Peak Mem (GB) GPU Mem (GB)
gpt-oss-20b-webgpu-int4-rtn-block-32 1 5 128 128 93.5 74.9 1.25 12.24
Llama-3.1-8B-awq-g128-int4-asym-fp16-onnx-dml 1 5 128 128 119.0 47.7 1.15 5.23

OGA Wheel Smoke (Python benchmark_e2e.py)

Model TTFT (ms) TPS
Llama-3.1-8B-awq-g128-int4-asym-fp16-onnx-dml 118 47.9

VLM Benchmark Results

Model TTFT (ms) TPS Output
gemma-4-E4B-it-fp16-int4-kquant-prune-logits 4034.8 7.3 This is a high-quality, outdoor photograph featuring a beautiful, fluffy white dog, likely a West Highland White Terrier or a si
Qwen3.8-27B-fp16-ve-fp16-int4-k_quant-gs128-text-dml-onnx 14501.2 14.0 The user wants a detailed description of the image. Let me carefully observe all elements before writing. Subject: A white do

TTFT / TPS vs main

Baseline: run 40457802257 - ae1dc4f | Gate: TTFT +20% / TPS -20%

Suite Model TTFT (ms) Main Delta TPS Main Delta
oga gpt-oss-20b-webgpu-int4-rtn-block-32 93.5 91.5 +2.2% 74.9 74.2 +1.0%
oga Llama-3.1-8B-awq-g128-int4-asym-fp16-onnx-dml 119.0 116.9 +1.9% 47.7 47.6 +0.3%
vlm gemma-4-E4B-it-fp16-int4-kquant-prune-logits 4034.8 4141.2 -2.6% 7.3 7.2 +0.4%
vlm Qwen3.8-27B-fp16-ve-fp16-int4-k_quant-gs128-text-dml-onnx 14501.2 14900.2 -2.7% 14.0 14.0 0.0%

Run: 7972 - Commit: e7ec78e

CI LLVM prefixes include AMDGPU and use a new cache key so rocMLIR can link. The mock job keeps the flag off because it has no ROCm SDK.

Co-authored-by: Cursor <cursoragent@cursor.com>
@pragyam32
pragyam32 force-pushed the gpuep/shape-merge-plus-quant-integer branch from 6e190c7 to e7ec78e Compare October 27, 2026 09:50
@amd-mounikk
amd-mounikk marked this pull request as draft October 27, 2026 12:41

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

large-pr Soft size threshold (>500 LOC or >10 files). Reviewer signal, not a block.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants