Skip to content

ggml-zendnn : group matmul direct API for mul_mat_id - #25918

Merged
ggerganov merged 2 commits into
ggml-org:masterfrom
z-sachin:ggml-zendnn/refactor-mul-mat-id
Jul 31, 2026
Merged

ggml-zendnn : group matmul direct API for mul_mat_id#25918
ggerganov merged 2 commits into
ggml-org:masterfrom
z-sachin:ggml-zendnn/refactor-mul-mat-id

Conversation

@z-sachin

Copy link
Copy Markdown
Contributor

Overview

This PR updates the vendored ZenDNN dependency to the latest WW28 release and switches the ZenDNN mul_mat_id implementation to use grouped GEMM, allowing all active experts to be processed in a single backend call.

Changes

  • Add ggml_zendnn_group_matmul() and ggml_zendnn_group_gemm() wrappers that batch all active experts' GEMMs into a single ZenDNN grouped GEMM call instead of issuing one call per expert.

  • Rework ggml_zendnn_compute_forward_mul_mat_id() to support grouped execution:

    • Resize the gather/scatter buffer based on total_rows instead of max_rows, since data for all active experts must coexist for a single grouped GEMM.
    • Precompute each expert's offset into the shared buffer.
    • Fold the src1vec_dot_type conversion into the gather step, eliminating the separate conversion pass.
  • Restructure the execution flow from for each expert: gather → GEMM → scatter to gather all experts → one grouped GEMM → scatter all experts.

  • Remove the outdated comment in device_supports_op() that described grouped GEMM as future work. The existing 32-expert limit remains unchanged.

Requirements

@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning AMD ZenDNN Issues related to the AMD ZenDNN backend labels Jul 20, 2026
@taronaeo

Copy link
Copy Markdown
Member

cc: @z-vishal

@z-manoj

z-manoj commented Jul 21, 2026

Copy link
Copy Markdown

CC @avinashcpandey @Jiten1parmar

z-sachin added a commit to z-sachin/llama.cpp that referenced this pull request Jul 24, 2026
…nly)

Rebased on top of ggml-org#25918's grouped-GEMM mul_mat_id rework. Q4_0 support
is restricted to plain MUL_MAT: ggml-cpu's CPU_REPACK mechanism claims
Q4_0 weights into the 8-row-interleaved block_q4_0x8 layout, and ZenDNN
detects that layout (is_superblock) to compute over it directly instead
of forcing plain blocks. mul_mat_id (MoE) has no Q4_0 path yet, so
Q4_0 experts continue to fall back to CPU there.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
z-sachin added a commit to z-sachin/llama.cpp that referenced this pull request Jul 24, 2026
With grouped-GEMM (ggml-org#25918) the per-call overhead dropped, but ZenDNN's
mul_mat_id still loses to CPU below a real per-batch token count of
~384 on gpt-oss-20B (32 experts, top-4) - measured empirically. Fall
back to CPU under that threshold instead of always taking the ZenDNN
path once the expert-count gate passes.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

@Jiten1parmar Jiten1parmar left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@taronaeo taronaeo added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Jul 30, 2026
@ggerganov
ggerganov merged commit 1e22599 into ggml-org:master Jul 31, 2026
19 of 25 checks passed
kashif pushed a commit to kashif/llama.cpp that referenced this pull request Aug 2, 2026
* ggml-zendnn : group matmul API for mul_mat_id

* ggml-zendnn : scale MUL_MAT_ID fallback threshold by expert count
huaxel pushed a commit to huaxel/CachyLLama that referenced this pull request Aug 2, 2026
* ggml-zendnn : group matmul API for mul_mat_id

* ggml-zendnn : scale MUL_MAT_ID fallback threshold by expert count
smalinin pushed a commit to smalinin/llama.cpp that referenced this pull request Aug 4, 2026
* ggml-zendnn : group matmul API for mul_mat_id

* ggml-zendnn : scale MUL_MAT_ID fallback threshold by expert count
satindergrewal pushed a commit to satindergrewal/llama.cpp that referenced this pull request Aug 11, 2026
* ggml-zendnn : group matmul API for mul_mat_id

* ggml-zendnn : scale MUL_MAT_ID fallback threshold by expert count
satindergrewal pushed a commit to satindergrewal/llama.cpp that referenced this pull request Aug 12, 2026
* ggml-zendnn : group matmul API for mul_mat_id

* ggml-zendnn : scale MUL_MAT_ID fallback threshold by expert count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AMD ZenDNN Issues related to the AMD ZenDNN backend ggml changes relating to the ggml tensor library for machine learning merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants