Repository navigation
metal : relax conditions on fast matrix multiplication kernel - #3168
Merged
Merged
Conversation
ikawrakow
approved these changes
Sep 14, 2023
| if (ne11 * ne12 < 4) { | ||
| [encoder setComputePipelineState:ctx->pipeline_mul_mat_f16_f32_1row]; | ||
| } else if (ne00 >= 128 && ne01 >= 8 && ne00%4 == 0) { | ||
| //} else if (ne00 >= 128 && ne01 >= 8 && ne00%4 == 0) { |
Contributor
There was a problem hiding this comment.
So, if you are sure that it is no longer needed, then remove it altogether. If you are not sure, then this change does not make sense.
Member
Author
There was a problem hiding this comment.
Will do some more tests - for now keeping the original implementation.
With this PR, nrows is always 1 because ne11 is 1, so I think it would either need to be updated or probably it is not needed anymore.
Member
|
M2 (10c GPU)
|
jhen0409
approved these changes
Sep 15, 2023
pkrmf
pushed a commit
to morlockstudios-com/llama.cpp
that referenced
this pull request
Sep 26, 2023
…rg#3168) * metal : relax conditions on fast matrix multiplication kernel * metal : revert the concurrnecy change because it was wrong * llama : remove experimental stuff
Seunghhon
pushed a commit
to Seunghhon/llama.cpp
that referenced
this pull request
Apr 26, 2026
…rg#3168) * metal : relax conditions on fast matrix multiplication kernel * metal : revert the concurrnecy change because it was wrong * llama : remove experimental stuff
phuongncn
pushed a commit
to phuongncn/llama.cpp-gx10-dgx-sparks-deepseekv4
that referenced
this pull request
Apr 28, 2026
…rg#3168) * metal : relax conditions on fast matrix multiplication kernel * metal : revert the concurrnecy change because it was wrong * llama : remove experimental stuff
ljubomirj
pushed a commit
to ljubomirj/llama.cpp
that referenced
this pull request
May 6, 2026
…rg#3168) * metal : relax conditions on fast matrix multiplication kernel * metal : revert the concurrnecy change because it was wrong * llama : remove experimental stuff
AlexiAlp
pushed a commit
to minghaop/llama.cpp
that referenced
this pull request
Jun 2, 2026
…rg#3168) * metal : relax conditions on fast matrix multiplication kernel * metal : revert the concurrnecy change because it was wrong * llama : remove experimental stuff
AlexiAlp
pushed a commit
to minghaop/llama.cpp
that referenced
this pull request
Jun 2, 2026
…rg#3168) * metal : relax conditions on fast matrix multiplication kernel * metal : revert the concurrnecy change because it was wrong * llama : remove experimental stuff
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.
close #2850
In #3123, @ikawrakow made an important observation that the
KQtensor does not benefit from the fast matrix multiplication kernel because theKandQtensors are not contiguous, so we fallback to the slower variant of the kernel.However, the fast kernel does not really need
src0andsrc1to be contiguous. It only requires them to not be transposed - i.e. only the elements in the rows need to be contiguous. Relaxing this restriction leads to improvement in PP speed.With this change, LLaMA is ~10% faster on M2 Ultra and Falcon is as fast as LLaMA.
While implementing this, I noticed that the metal concurrency optimization while improving PP speed, it actually degrades the TG speed on M2 Ultra. So I've added a flag to use it only if we are computingn_batch > 1. This leads to the TG speedup in the results below.Ignore this comment - preparing the allocator with concurrency enabled and then not using it produces incorrect results. Updated the tables below.
This PR also fixes a bug in
ggml_nbytes()which does not affectllama.cpp.Please give this branch a thorough testing and let me know if you observe similar speed-up on other Metal chips.
I did some checks on the perplexity for a few quants and everything looks normal, but lets double-check.
build: 71ca2fa (1221)