Segmented mm nax kernel#3419
Conversation
nastya236
left a comment
There was a problem hiding this comment.
Looks great! I asked couple of questions as usual for my own understanding :)
| // Use NAX kernel if available | ||
| if (use_nax) { | ||
| int average_k = K / batch_size_out; | ||
| bm = 64; |
There was a problem hiding this comment.
Just out of curiosity, why 2 x 2 simdgroups and 64 x 64 tiles?
There was a problem hiding this comment.
Well this can be tuned for sure. I haven't actually ran extensive testing and it seemed like a good default 🤷♂️
| MTL::Size group_dims = MTL::Size(32, wn, wm); | ||
| MTL::Size grid_dims = | ||
| MTL::Size(params.tiles_n, params.tiles_m, batch_size_out); | ||
| MTL::Size grid_dims = (use_nax && bk == 64) |
There was a problem hiding this comment.
I am wondering should non nax kernel also swap dimensions when there are many small segments?
There was a problem hiding this comment.
Yeah it is possible. The idea was that we launch threadgroups in order x, y, z and since K is very small in these cases we want the different Ks to run one after the other since it is very likely that the 2nd matmul's K will be in the cache already.
…dLocalStream, linalg.det) Highlights: - ThreadLocalStream in C++ (ml-explore#3405) — joins StreamOrDevice variant - Segmented mm NAX kernel (ml-explore#3419) — new steel/gemm/kernels/steel_gemm_segmented{,_nax} - mlx.core.linalg additions: determinant, sign-log-determinant (ml-explore#3416) - NAX split-K tuning + addmm fix (ml-explore#3422) - gather_mm CUDA + qmm CUDA fixes (ml-explore#3414, ml-explore#3417, ml-explore#3445) - Scheduler::enqueue thread safety (ml-explore#3423) - Random kernel bytes_per_key truncation fix (ml-explore#3432) - Many smaller bug + CI fixes; nanobind 2.12.0 pin Conflict resolution (5 files; all auto-merged cleanly, no manual edits): - mlx/utils.h — `ThreadLocalStream` joins StreamOrDevice; our metal_retain_bound_buffers() helper preserved. - mlx/backend/metal/device.cpp — upstream's "no Metal device available" error message coexists with our signpost/MLX_METAL_PROFILE perf diagnostic + hazard-mode retain logic. - mlx/backend/metal/CMakeLists.txt — upstream's steel_gemm_segmented{,_nax} joins our kernel registrations. - mlx/backend/metal/kernels/CMakeLists.txt — same: upstream segmented + our fused_gate_activation kernel. - tests/scheduler_tests.cpp — upstream's "test thread local stream" joins our scheduler-test alignment for lazy command-encoder init. No disputed conflicts; the auto-merge produced a coherent result with both sides' work intact. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
As the title suggests it adds a NAX kernel for the
segmented_mm. It also fixes #3362.Micro benchmark numbers