Repository navigation
[WebGPU] Add Apple INT4 register and FP32 subgroup matrix tiles - #34208
Draft
Nikhil Jain (nikhilJain17) wants to merge 4 commits into
Draft
Nikhil Jain (nikhilJain17) wants to merge 4 commits into
Nikhil Jain (nikhilJain17) wants to merge 4 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Author
|
@microsoft-github-policy-service agree |
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.
Motivation
We want to reduce the TTFT of running Qwen3.8-27B on Apple devices via WebGPU.
Kernel-level profiling shows that the wide tiling matmul kernel has the best opportunity for a speedup on prefill:
Solution
We introduce two new kernels:
The existing MatMulNBitsWideTile kernel uses 32×128 output tiles and 128-thread workgroups, with each thread computing a 32×1 output column. Threads cooperatively load a 32×32 activation tile into shared memory and individually load their weight columns. They read activation chunks from shared memory and use
subgroupShuffleto distribute them across the subgroup, accumulating partial dot products along K.We switch to 64×64 output tiles and 64-thread workgroups. Each 32-thread subgroup handles a 64×32 tile, with each thread computing 2×32 outputs. Activations are stored in each thread's local memory, and weights are loaded and broadcasted using
subgroupShuffle.So essentially we change the tile dimensions, and also replace the shared activation buffer (and associated workgroup barriers) with duplicate activation loads.
We have a second kernel which uses the experimental
subgroupMatrixMulitplyAccumulateoperation. Each 128-thread workgroup is comprised of four subgroups of 32 threads. The output tile size is 64x64. Threads cooperatively load activations and weights into shared memory, and then each subgroup does an individual 8x8 matrix multiply and accumulates the results. This kernel was faster in testing, but requires an experimental instruction which may not be supported by all browsers.Testing
Tested on Mac M4 Pro running Qwen3.8-27B.