Skip to content

Optimize Krea Vulkan - MUL_MAT - #27493

Open
pwilkin wants to merge 2 commits into
ggml-org:masterfrom
pwilkin:optimize-krea-vulkan-matmul
Open

Optimize Krea Vulkan - MUL_MAT#27493
pwilkin wants to merge 2 commits into
ggml-org:masterfrom
pwilkin:optimize-krea-vulkan-matmul

Conversation

@pwilkin

@pwilkin pwilkin commented Aug 21, 2026

Copy link
Copy Markdown
Member

Overview

The MUL_MAT part of the Krea Vulkan optimization

Requirements

@pwilkin
pwilkin requested review from a team, JohannesGaessler and ggerganov as code owners August 21, 2026 11:35
@github-actions github-actions Bot added testing Everything test related Vulkan Issues specific to the Vulkan backend ggml changes relating to the ggml tensor library for machine learning CUDA Related to the CUDA backend labels Aug 21, 2026
Comment on lines +176 to +196
uint elem_row[CM_ELEMS];
uint elem_col[CM_ELEMS];
if (WARP == 32) {
[[unroll]] for (uint e = 0; e < CM_ELEMS; ++e) {
elem_row[e] = gl_SubgroupInvocationID / CM_N + 2 * e;
elem_col[e] = gl_SubgroupInvocationID % CM_N;
}
} else {
for (uint i = gl_LocalInvocationID.x; i < CM_M * CM_N; i += BLOCK_SIZE) {
cm_layout_probe[i] = int32_t(i);
}
barrier();

coopmat<int32_t, gl_ScopeSubgroup, CM_M, CM_N, gl_MatrixUseAccumulator> probe;
coopMatLoad(probe, cm_layout_probe, 0, CM_N, gl_CooperativeMatrixLayoutRowMajor);

[[unroll]] for (uint e = 0; e < CM_ELEMS; ++e) {
elem_row[e] = uint(probe[e]) / CM_N;
elem_col[e] = uint(probe[e]) % CM_N;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a huge hack and explains why you got it to work at all over my (naively spec-adhering) attempts.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Can you elaborate?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Usually you have to write a coopmat to shared memory to be able to work with its values directly, that is why my previous attempts to write an int8-based coopmat1 shader failed, it was too inefficient. I hadn't thought of probing the order the driver stores the values. It's hacky, but not a bad idea.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you know when we can expect driver support?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For NVIDIA it's already in the https://developer.nvidia.com/vulkan-driver, can't say for the mainline driver (could be a few months)

@pwilkin
pwilkin force-pushed the optimize-krea-vulkan-matmul branch from 86110ec to fcf82c2 Compare August 21, 2026 12:31
@jeffbolznv

Copy link
Copy Markdown
Contributor

This PR needs a description and some perf data.

@pwilkin

pwilkin commented Aug 21, 2026

Copy link
Copy Markdown
Member Author

Here are the numbers:

Krea GEMM family (M, N, K) Calls per denoise step Clean master PR #27493 Time reduction Speedup
Expansion 16384 × 3079 × 6144 56 32.359 ± 0.080 ms 22.126 ± 0.291 ms 31.62% 1.46×
Contraction 6144 × 3079 × 16384 28 36.995 ± 0.119 ms 22.371 ± 0.087 ms 39.53% 1.65×
Square projection 6144 × 3079 × 6144 84 12.210 ± 0.015 ms 8.474 ± 0.019 ms 30.59% 1.44×
QKV projection 1536 × 3079 × 6144 56 3.512 ± 0.064 ms 2.553 ± 0.033 ms 27.29% 1.38×

Useful-operation throughput:

Family Clean master PR #27493
Expansion 19.16 TOPS 28.02 TOPS
Contraction 16.75 TOPS 27.71 TOPS
Square projection 19.04 TOPS 27.43 TOPS
QKV projection 16.55 TOPS 22.76 TOPS

This is all for AMD gfx1151 (Strix Halo)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CUDA Related to the CUDA backend ggml changes relating to the ggml tensor library for machine learning testing Everything test related Vulkan Issues specific to the Vulkan backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants