Repository navigation
[ET-VK][gemm] Nest linear and matmul sources by scheme - #23723
Closed
pytorchbot wants to merge 1 commit into
Closed
pytorchbot wants to merge 1 commit into
pytorchbot wants to merge 1 commit into
Conversation
Pull Request resolved: #23493 ## Ulterior Motive Organize Vulkan operators by implementation family so operators with multiple routes can use clear, scalable directory layouts. ## Rationale **What**: Move the linear and matrix multiplication C++ implementations, GLSL templates, YAML variant definitions, and GEMM tile headers under `gemm/` in both `impl/` and `glsl/`, split into `linear/` (an activation times a usually prepacked weight) and `matmul/` (multiplication between live activations). Quantized linear sources are grouped by how they are quantized, and the multi-scheme `QuantizedLinear.cpp` and the shared `GemmCoopmat.cpp` are split accordingly. **Why**: Linear and matmul sources were interleaved by name in the flat directories, quantized linear variants for different schemes shared one file, and the shared GEMM tile headers were scattered across the shader root, which obscured which sources implement which operator, route, and scheme. ## Details - Layout (`impl/` and `glsl/` mirror each other) - `gemm/`: `GemmCommon.{h,cpp}` (fp weight prepack, resize helpers, and the cooperative-matrix tile constants and `is_coopmat_eligible()` shared by linear and matmul) and `coopmat_mm`, the cooperative-matrix shader shared by both. - `gemm/tile_utils/`: all GEMM tile headers (tile structs, tile load/store/compute, block packing, accumulators, and scale/sum/bias loaders), also used by convolution, SDPA, and quantize shaders. - `gemm/linear/`: `Linear.{h,cpp}` (`aten.linear`), `LinearCoopmat.{h,cpp}`, and `backward/LinearDw.cpp` (`et_vk.linear_dW`). - `gemm/linear/q8ta/`: `Q8taLinear` and `Q8taLinearGemv`; activations and weights are quantized ahead of time with static parameters (primarily statically quantized convolutional models). - `gemm/linear/qw/`: weight-only quantization, with activations kept in floating point or quantized dynamically (primarily LLMs and transformers). `QuantizedLinear.{h,cpp}` hold the shared weight prepacking, workgroup sizing, the weight-only node, and `quantized_linear_impl`; schemes live in `q4gsw/` (with `backward/` for `et_vk.linear_q4gsw_backward` and `et_vk.q4gsw_requant`), `dq8ca_q4gsw/`, `q8csw/`, and `legacy/` (`QuantizedLinearQCSNW` and the `q8ta_q8csw` implementation that runs through `quantized_linear_impl`). - `gemm/matmul/`: `MatMul.{h,cpp}` (`aten.mm`, `aten.bmm`, `aten.addmm`; renamed from `Matmul.cpp` to match its header) and `MatmulCoopmat.{h,cpp}`. - Weight packing shaders sit in `pack_weights/` subdirectories of the folder that dispatches them (`linear/`, `linear/qw/`, `linear/qw/q4gsw/`, and the shader root for `pack_int4_linear_weight_transposed_interleaved`). - Splits - `QuantizedLinear.cpp`: `q8csw/Q8cswLinear.cpp` (`et_vk.linear_q8csw`, `aten._weight_int8pack_mm`), `legacy/Q8taQ8cswLinear.{h,cpp}` (`add_linear_qa_qw_node`, `et_vk.linear_q8ta_q8csw`), and `dq8ca_q4gsw/Dq8caQ4gswLinear.{h,cpp}` (`add_linear_dqa_qw_node`, `et_vk.linear_dq8ca_q4gsw`). `can_use_q4gsw_coopmat` and the coopmat tile constants are now declared in `QuantizedLinear.h` because the shared and `dq8ca_q4gsw` files both use them. - `GemmCoopmat.cpp`: `linear/LinearCoopmat.cpp` and `matmul/MatmulCoopmat.cpp`. - Functions move unchanged. - Includes - Shaders inside `gemm/` include tile headers as `tile_utils/<header>`; shaders outside `gemm/` include them as `gemm/tile_utils/<header>`. - C++ include paths and `op_registry.py` section labels are updated. - Moved files are recorded as renames, and split files as copies of their source. - Code that moves within or between files is re-linted, so its CLANGTIDY findings are fixed: `(void)` for unused parameters, `utils::safe_downcast` for narrowing in `quantized_linear_gwg` and the coopmat size reads, bounds-checked `.at()` in place of `.back()` in `LinearCoopmat.cpp`, and removal of unused includes (`Softmax.h` in `SDPA.cpp`, `Linear.h` in `Conv1dPW.cpp`, and two utility headers in the coopmat files). Generated shader names and runtime dispatch behavior are unchanged. ghstack-source-id: 446951723 @exported-using-ghexport Differential Revision: [D123523650](https://our.internmc.facebook.com/intern/diff/D123523650/)
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/23723
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This branch was successfully 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.
This PR was created by the merge bot to help merge the original PR into the main branch.
ghstack PR number: #23493 by @SS-JIA
^ Please use this as the source of truth for the PR details, comments, and reviews
ghstack PR base: https://github.com/pytorch/executorch/tree/gh/SS-JIA/660/base
ghstack PR head: https://github.com/pytorch/executorch/tree/gh/SS-JIA/660/head
Merge bot PR base: https://github.com/pytorch/executorch/tree/gh/SS-JIA/659/orig
Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/SS-JIA/660/orig
Differential Revision: D123523650
@diff-train-skip-merge