Repository navigation
Conversation
The subgroup MatMul kernel runs with subgroup size 32 and 8 rows per invocation, which spills registers. Pointwise Conv, which reaches the kernel, became 8-15x slower than the packed MatMul. Add a second subgroup kernel, used only on architectures where it was measured to be faster. Other GPUs keep the default kernel, subgroup size selection and selection rules. The subgroup-16 kernel: - Uses a 16x8 workgroup (128 invocations) where each row is one subgroup of 16 lanes, a 64-column output tile and a 16-deep K tile. - Double-buffers the B tile in workgroup memory and prefetches the next tile into registers, so each K tile needs one barrier. - Loads A cooperatively as vec4 values along K when K % 4 == 0, with one vec4 subgroupBroadcast per row serving four K steps, addressed by subgroup_invocation_id. - Picks rows per invocation from the output size: the most rows (up to 8) that still launch 320 workgroups, at least 4 with f32 accumulators and 2 with f16, and at most 4 for f32 accumulators with scalar A loads. - Leaves shapes that use split-K to the packed path, for MatMul and Gemm. - Serves Gemm without transposes, including alpha and empty inputs. UseMatMulSubgroup16Kernel() selects the kernel; on those architectures subgroup size 16 is preferred. The planner, its plan validation, MatMul and Gemm all derive the kernel, tile sizes and rows per invocation from the same facts. On an Arc A770 versus the packed MatMul, over 420 shapes each (M 64-4096, N 512-5120, K 64-4096): MatMul fp32 1.54x / fp16 1.77x geomean where the subgroup kernel is selected, Gemm fp32 1.49x / fp16 1.74x, no shape below 0.95x. The pointwise Conv from microsoft#33856 (384x2560x1280 fp32) goes from 7043 us to 343 us (packed: 543 us). Fixes microsoft#33856. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The new architecture-specific routing, adaptive planning, and subgroup-16 kernel paths lack regression coverage for key fallback, boundary, unaligned, and batched cases.
No open issues 🎉
What changed in this PR
Adds an Intel Alchemist–specific subgroup-size-16 MatMul/Gemm kernel to address the WebGPU pointwise Conv slowdown reported in #33856, while retaining the default kernel on other architectures.
Changes:
- Introduces a 64-column kernel with double-buffered B tiles, cooperative A loads, and adaptive rows per invocation.
- Integrates architecture-aware selection into MatMul and Gemm, preserving the packed path for split-K shapes.
- Aligns execution-plan validation with the new kernel’s tile sizes and accumulation settings.
| File | Description |
|---|---|
onnxruntime/core/providers/webgpu/vendor/intel/math/matmul.h |
Adds the subgroup-16 program flag. |
onnxruntime/core/providers/webgpu/vendor/intel/math/matmul.cc |
Selects and dispatches the architecture-specific kernel. |
onnxruntime/core/providers/webgpu/vendor/intel/math/matmul_execution_planner.cc |
Preserves split-K selection for eligible shapes. |
onnxruntime/core/providers/webgpu/vendor/intel/math/gemm.h |
Adds subgroup-16 configuration to Gemm. |
onnxruntime/core/providers/webgpu/vendor/intel/math/gemm.cc |
Integrates subgroup-16 shader generation and dispatch. |
onnxruntime/core/providers/webgpu/vendor/intel/math/gemm_subgroup16.h |
Declares the new kernel interface and workgroup dimensions. |
onnxruntime/core/providers/webgpu/vendor/intel/math/gemm_subgroup16.cc |
Implements the shader, architecture gate, and row tuning. |
onnxruntime/core/providers/webgpu/vendor/intel/math/gemm_subgroup.h |
Updates the eligibility-check context signature. |
onnxruntime/core/providers/webgpu/vendor/intel/math/gemm_subgroup.cc |
Adds split-K-aware Gemm eligibility checks. |
onnxruntime/core/providers/webgpu/vendor/intel/math/gemm_subgroup_utils.h |
Declares architecture-aware selection and tuning helpers. |
onnxruntime/core/providers/webgpu/math/matmul.cc |
Passes accumulation precision into planning. |
onnxruntime/core/providers/webgpu/math/matmul_execution_planner.h |
Extends selection parameters and exposes the split-K predicate to derived planners. |
onnxruntime/core/providers/webgpu/math/matmul_execution_planner.cc |
Validates dispatch using the selected kernel’s tile geometry. |
Review effort: Balanced
Contributor
Author
|
Jie Chen (@jchen10) PTAL |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The subgroup MatMul kernel runs with subgroup size 32 and 8 rows per invocation, which spills registers. Pointwise Conv, which reaches the kernel, became 8-15x slower than the packed MatMul.
Add a second subgroup kernel, used only on architectures where it was measured to be faster. Other GPUs keep the default kernel, subgroup size selection and selection rules.
The subgroup-16 kernel:
UseMatMulSubgroup16Kernel() selects the kernel; on those architectures subgroup size 16 is preferred. The planner, its plan validation, MatMul and Gemm all derive the kernel, tile sizes and rows per invocation from the same facts.
On an Arc A770 versus the packed MatMul, over 420 shapes each (M 64-4096, N 512-5120, K 64-4096): MatMul fp32 1.54x / fp16 1.77x geomean where the subgroup kernel is selected, Gemm fp32 1.49x / fp16 1.74x, no shape below 0.95x. The pointwise Conv from #33856 (384x2560x1280 fp32) goes from 7043 us to 343 us (packed: 543 us).
Fixes #33856.
Description
Motivation and Context