Repository navigation
[WebGPU] Use shared memory tiles in subgroup matrix MatMul on NVIDIA - #33639
Rithik Sharma (SharmaRithik) wants to merge 2 commits into
Conversation
The subgroup matrix tiling gains a subgroup grid and a staged K depth. On NVIDIA a 4x4 grid of subgroups stages 64 deep K slices of A and B in shared memory and computes a 64x64 or 128x128 output tile from there, chosen by the problem size, and the existing split K tiling is kept for small problems. Other vendors are unchanged. Prefill of Llama 3.2 1B, Qwen3 0.6B and Gemma 3 270M at 512 and 1024 tokens is 4 percent faster on average on an RTX 5080 and 11 percent on an RTX 4070.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Jiajia Qin (@qjia7) could you take a look when you have time? This is the tuning follow-up I mentioned in #32937. It is NVIDIA only and was tested on Linux with Vulkan on an RTX 5080 and an RTX 4070. The second commit only regenerates the WGSL template goldens. The workflows need approval to run, thanks. |
|
Rithik Sharma (@SharmaRithik), are you using the f16 model with f16 weights or quantized weights? For quantized weights, I think the model will be generated with MatMulNbits instead of MatMul. And the MatMulNbits path has many optimizations for the language model prefill and decode stage. I am just curious why you have so many matmul ops in your model. |
|
Thanks Jiajia Qin (@qjia7), I used both. The fp16 rows use the onnx-community fp16 exports, where every projection is an FP16 MatMul. The q4f16 rows use the q4f16 exports, where the projections are MatMulNBits and only lm_head is an FP16 MatMul, which is why those rows gain less. The models are:
|
Description
The subgroup matrix MatMul kernel loads A and B straight from global memory with one subgroup per K split, so this PR adds a path where a workgroup of subgroups copies a K slice of A and B into shared memory and loads its subgroup matrices from there. On NVIDIA a 4x4 grid of subgroups stages K slices 64 deep and computes a 128x128 output tile for large problems and a 64x64 tile otherwise, while small problems keep the existing split K tiling because it fills the GPU better there, and each tiling is checked against the device limits with the existing tiling as the fallback. The tile sizes and the K depth were measured in ORT on an RTX 5080 and an RTX 4070, and since the path is selected for NVIDIA only, other vendors are unchanged.
Motivation and Context
Prefill speedup over main for the onnx-community models on Linux with Vulkan, P50 of 100 runs with
onnxruntime_perf_test, averaged over five rounds:The q4f16 models gain because their
lm_headMatMul is FP16.