Skip to content

webgpu: fix OOB subgroup-matrix loads for trailing partial tiles - #32364

Merged
Hariharan Seshadri (hariharans29) merged 2 commits into
microsoft:mainfrom
jchen10:sgmm_robust
Sep 8, 2026
Merged

Hariharan Seshadri (hariharans29) merged 2 commits into
microsoft:mainfrom
jchen10:sgmm_robust

Conversation

@jchen10

Copy link
Copy Markdown
Contributor

The 8x16x16 gemm/matmul kernels let a trailing partial M/N tile's subgroupMatrixLoad read past A/B. Tint's robustness transform resets such an out-of-bounds load to offset 0 with the minimum stride instead of zero-filling, so it silently returns a different valid tile and corrupts otherwise in-range data.

Shift the trailing tile back so it always ends exactly at M/N, and skip the rows/columns the shift re-covers at write-out. The host now falls back to the generic path when the tile doesn't fit M/N at all, since the shift only works when it does.

Copilot AI balanced review requested due to automatic review settings September 2, 2026 00:47
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

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 affected Gemm and MatMul paths lack enabled numerical regression coverage.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Prevents WebGPU subgroup-matrix Gemm/MatMul kernels from loading beyond trailing partial tiles.

Changes:

  • Shifts partial M/N tiles in bounds and skips overlapping writes.
  • Falls back when matrices are smaller than selected tiles.
  • Regenerates WGSL template goldens.
File summaries
File Description
tools/python/wgsl_template/test/in_tree_golden/static-cpp/string_table.h Updates generated shader strings.
tools/python/wgsl_template/test/in_tree_golden/static-cpp/index_impl.h Refreshes generated hashes.
tools/python/wgsl_template/test/in_tree_golden/static-cpp/generated/tensor/pad.h Reindexes generated strings.
tools/python/wgsl_template/test/in_tree_golden/static-cpp/generated/tensor/oihw_to_ohwi.h Reindexes generated strings.
tools/python/wgsl_template/test/in_tree_golden/static-cpp/generated/nn/im2col_matmul.h Reindexes generated strings.
tools/python/wgsl_template/test/in_tree_golden/static-cpp/generated/math/subgroup_matrix_matmul_pad_b.h Reindexes generated strings.
tools/python/wgsl_template/test/in_tree_golden/static-cpp/generated/math/subgroup_matrix_matmul_8x16x16.h Captures generated MatMul changes.
tools/python/wgsl_template/test/in_tree_golden/static-cpp-literal/index_impl.h Refreshes literal-generator hashes.
onnxruntime/core/providers/webgpu/math/subgroup_matrix_matmul.cc Adds small-matrix fallback.
onnxruntime/core/providers/webgpu/math/subgroup_matrix_matmul_8x16x16.wgsl.template Makes trailing MatMul tiles safe.
onnxruntime/core/providers/webgpu/math/subgroup_matrix_gemm.cc Adds small-matrix fallback.
onnxruntime/core/providers/webgpu/math/subgroup_matrix_gemm_8x16x16.wgsl.template Makes trailing Gemm tiles safe.
Review details
  • Files reviewed: 7/15 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@jchen10

Copy link
Copy Markdown
Contributor Author

Comment thread onnxruntime/core/providers/webgpu/math/subgroup_matrix_matmul.cc Outdated
Comment thread onnxruntime/core/providers/webgpu/math/subgroup_matrix_matmul.cc Outdated
…tiles

The 8x16x16 gemm/matmul kernels let a trailing partial M/N tile's
subgroupMatrixLoad read past A/B. Tint's robustness transform resets
such an out-of-bounds load to offset 0 with the minimum stride
instead of zero-filling, so it silently returns a different valid
tile and corrupts otherwise in-range data.

Shift the trailing tile back so it always ends exactly at M/N, and
skip the rows/columns the shift re-covers at write-out. The host now
falls back to the generic path when the tile doesn't fit M/N at all,
since the shift only works when it does.

Regenerated the wgsl_template golden snapshots (in_tree_golden) to
match the updated templates.
Compute N_b before dispatching the pad program so the tile-fit
check can bail out early without wasting a pad dispatch.
@hariharans29
Hariharan Seshadri (hariharans29) merged commit 2a2833a into microsoft:main Sep 8, 2026
97 of 100 checks passed
This was referenced Sep 14, 2026
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.

4 participants