ggml-cuda: make mul_mat_q tile selection tunable per-type and per-arch - #21849
ggml-cuda: make mul_mat_q tile selection tunable per-type and per-arch#21849aviallon wants to merge 3 commits into
Conversation
Add mmq_config struct with per-(type, mmq_x, arch) min_blocks and enabled fields, following the fattn_mma_config pattern. Replace the __launch_bounds__ #ifdef maze with a single constexpr config lookup. This will allow easier per-arch tuning later-on. Separate config functions per arch family: - cdna4: defaults (min_blocks=2), placeholder for future tuning - cdna3: defaults (min_blocks=2), placeholder for future tuning - cdna2: gfx90a (min_blocks=2), placeholder for tuning - cdna1: gfx908 (min_blocks=2), placeholder for tuning - nvidia_volta_up: Volta and newer (min_blocks=1) - rdna1: gfx1010/gfx1012 (min_blocks=1, preserves old no-arg behavior since we changed the default) - default: everything else (min_blocks=2) Add if constexpr device-side early-exit for disabled tiles (via the enabled field) and host-side filter in the tile selection loop. Behavior should be exactly the same as before, unless I made a mistake.
Use the mmq_config enabled/min_blocks fields to tune IQ3_XXS MMQ tile selection on CDNA2 (gfx90a). Tested on MI210. IQ3_XXS overrides: - mmq_x=112 disabled (260 VGPRs, 1 wave/SIMD at 10% occupancy; falling through to mmq_x=128 gives the same tile count with 2 waves) - mmq_x=128 relaxed to min_blocks=1 (eliminates 412B scratch spill)
Assisted-By: github-copilot/claude-sonnet-4.6
|
Pinging @IMbackK and @JohannesGaessler for review. Please don't yell at me too loud, I'm scared 🫠 |
|
If something like this is done at all it should be a table that can be easily looked up and modified like for |
|
Ok. So constexpr functions are not ok here? In |
|
To clarify what I mean: for the mma FA kernel all relevant kernel parameters are packaged inside of a single table and explicitly listed for all GPUs and kernel configurations. If something like this is added it should be done in that format and that format should then encompass all relevant paramters. I don't want to make the way MMQ configuration is done more convoluted for a few % on some niche GPUs. |
IMbackK
left a comment
There was a problem hiding this comment.
In general A centralized place for mmq tuneing parameters would be great.
| return mmq_config{2, true}; | ||
| } | ||
|
|
||
| // CDNA2 (gfx90a, MI210): wavefront64, 512 VGPRs/SIMD. |
There was a problem hiding this comment.
Kind of misleading, cdan2+ dosent have 512 VGPRS despite what amd has in the datasheet.
All GCN/CDNA gpus have only 256 vector registers.
starting cdan2 there are two banks per smid, if the second bank is not used for AGPRs it can be used to increase the occupancy of the kernel, but no kernel can ever have more than 256 VGPRs allocated.
There was a problem hiding this comment.
Ah, indeed. You are better informed than me. Finding good doc on the matter was so hard.
There was a problem hiding this comment.
What should I write on those headers instead?
| } | ||
|
|
||
| // CDNA1 (gfx908, MI100): wavefront64, (256 VGPRs + 256 AccGPRs)/SIMD. | ||
| // Default min_blocks=2 targets <=256 VGPRs/wave (2 waves/SIMD). |
There was a problem hiding this comment.
Misleading, there are only 256 VGPRs a kernel with 256 registers allocated has occupancy 1 unless the kernel happens to be allocating exactly half as AGPRS
Centralized with both |
|
Historically I wrote MMQ first and after that FA. For MMQ I implemented functions per kernel parameter, for FA I eventually ended up changing the configuration to the current table-like setup. That table-like setup should also be used for MMQ and only after that would I consider approving a PR that extends the configuration for MMQ. |
|
To make it clear: the configuration for FA and MMQ should still be separate, but the pattern by which it is done should be the same. |
|
What kind of tunables would you want to see? Is the current list of tunables enough, or do you expect something much more comprehensive? |
|
If you want to work on this, please first make a PR that does nothing but change how the kernels are orchestrated using the existing tuning parameters and doesn't yet add any new ones. Currently there are a bunch of functions like |
|
@aviallon hello, we can put our efforts together. I propose to start with a minimal struct mmq_config { Then making some get_config as in your pr. We can parametrize these three things without changing any wrt upstream. I can update the vec dot q8 to use it then. If this struct gets approved will be much easier to implement our speedups, to expand to other params if necessary. Read again last response from maintaibers. We may need to start even simpler without new params. |
Consolidates per-arch MMQ tuning into a single table, per @JohannesGaessler request in ggml-org#21849 to mirror the FA orchestration pattern. No behavior change, verified on gfx1151 with test-backend-ops and llama-bench parity. Follows up PR ggml-org#21849, to allow tuning MMQ params per arch and perf PR with the gfx1151 tuning from ggml-org#21344 will sit on top of this orchestration, hopefully Co-authored-by: Antoine Viallon <antoine@lesviallon.fr> Co-authored-by: Sunil Pedapudi <424940+pedapudi@users.noreply.github.com>
Consolidates per-arch MMQ tuning into a single table, per @JohannesGaessler request in ggml-org#21849 to mirror the FA orchestration pattern. No behavior change, verified on gfx1151 with test-backend-ops and llama-bench parity. Follows up PR ggml-org#21849, to allow tuning MMQ params per arch and perf PR with the gfx1151 tuning from ggml-org#21344 will sit on top of this orchestration, hopefully Co-authored-by: Antoine Viallon <antoine@lesviallon.fr> Co-authored-by: Sunil Pedapudi <424940+pedapudi@users.noreply.github.com>
Overview
Modifies mmq.cuh tile selection logic to somewhat imitate what
fattn-mma-f16.cuhdoes.This allows tuning tile selection logic per-architecture, which is then used in this PR to avoid some tile configurations on CDNA2 (gfx90a) that make poor use of the hardware.
This is my first time touching actual computation code in llama.cpp, so it may not be of the highest quality, and I apologize for that.
I really tried to carefully benchmark my changes though.
This work was sponsored by JustAI
Additional information
Benchmarks:
Before (baseline)
After (tuned: IQ3_XXS tile=128 disabled)
Summary
Requirements