]> git.djapps.eu Git - pkg/ggml/sources/ggml/commit
Optimize MOE GEMV kernel for BS > 1. (llama/20905)
authorGaurav Garg <redacted>
Sun, 29 Mar 2026 16:35:18 +0000 (22:05 +0530)
committerGeorgi Gerganov <redacted>
Wed, 1 Apr 2026 13:00:26 +0000 (16:00 +0300)
commite79ce97d14d94dda20832b41588fe57c9330d48d
treed17eee7217d06b49fc9e11b7ab95a2dab278d572
parent06754dd1de5a94ee9161fa88b1e7117d832d07d3
Optimize MOE GEMV kernel for BS > 1. (llama/20905)

* Optimize MOE GEMV kernel for BS > 1.

The previous MOE kernel for BS > 1 had too many thread blocks (nrows_x, nchannels_dst, ncols_dst), with very little work per block. block of (32, 4) was doing inner dot product for a single row.

New mul_mat_vec_q_moe kernel is dedicated for MoE multi-token kernel with grid (ceil(nrows_x/rpb), nchannels_dst), block (warp_size, ncols_dst). Each warp handles two rows independently with warp-level reduction only (no shared memory sync).

This change doesn't increase any compilation time as a single template instance is needed per type. This also simplifies the original GEMV kernel and gets rid of `is_multi_token_id` specialization.

* Remove em-dashes

* Cherry-pick changes from @am17an PR https://github.com/ggml-org/llama.cpp/pull/20885 to enable small_k optimization only for cases where it benefits

Increase max batch size for MMVQ kernels for MUL_MAT_ID to 8

* Make the max batch size for MOE GEMV kernel configurable based on GPU arch and datatype

---------

Co-authored-by: Aman Gupta <redacted>
src/ggml-cuda/ggml-cuda.cu
src/ggml-cuda/mmvq.cu
src/ggml-cuda/mmvq.cuh