Repository navigation
metal : per-device tuned mul_mm tiles for every src0 type - #29743
Draft
forforever73 wants to merge 5 commits into
Draft
forforever73 wants to merge 5 commits into
forforever73 wants to merge 5 commits into
Conversation
Member
|
I am thinking that probably for the BS range of [2..16] we should have a separate set of kernels as proposed in #29869, that will replace the mat_vec_ext kernels. |
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.
Overview
Draft. Opening this early to get feedback on the structure; the tables are still provisional (see TODO).
kernel_mul_mmalways runs a 64x32 tile, which leaves most of the GPU idle on small batches. #25377 hand-picks 64x8 for q4_0; this PR makes the tile a measured, per-device choice for every src0 type.kernel_mul_mmwith a tunable tile:NR1is a template argument (8/16/32),NR0a function constant. 64x32 stays the default, existing host names are unchanged, and 52 instantiations are added (26 src0 types x nr1 {8,16}).ggml-metal-tuning mul-mm:mm_tile_tuned_tablepicks(nr0, nr1)from the src0 type, output features andne11. This is the pp16-pp64 gain.mm_tile_ne11_mm_min_tablelowers the mul_mv_ext -> mul_mm switch point insidene112-8, so those batches run a small mm tile instead of mul_mv_ext. This, together with the tile, is the pp5-pp8 gain.ne11 >= 256, batched mul_mat (ne12*ne13 > 1), mul_mm_id, the tensor-API path, and any device without rows.test-backend-ops -o MUL_MATgains a tile slice that checks every legal tile for every src0 type against the CPU.Results (M4 Max)
llama-bench -p 5,6,7,8,16,32,64,128,256,512 -n 0 -r 10 -fa on, PR / master (8df332de1) t/s:50 points: min 0.991, max 2.93, geomean 1.246.
The lowest point, 1B F16 pp256, measures 0.995 on an interleaved re-run. At
ne11 >= 256the table is not consulted, so both builds run the same 64x32 tile there.Tests:
MUL_MAT 1269/1269(tile slice 495 run / 0 failed / 36 unsupported),MUL_MAT_ID 867/867.Binary and compile cost:
default.metallibmul_mm.metalhost namesmul_mm.metaloffline compileSweep cost: 26 types, 9199 cells, about 23 h on M4 Max, split into one shard per type (
--dtype).TODO
ne00 % 128condition would then need to apply only to mv_ext types.Requirements