[Metal][Performance] Add implicit matmul pathway for mx.conv3d - #3147
Merged
Conversation
Member
|
All right, added the small filter loader for filters <=16^3, added a pad and slice option for unaligned channels. A small channels loader would give us even better performance but I think it is already pretty good. I also edited the benchmark to measure sequential performance rather than parallel. The following are on an M3 Ultra. TL;DR we are now on average 2.5x faster with highs of 3.7x for larger inputs while before we were 15% slower (The diff is Before this PR With this PR |
angeloskath
approved these changes
Feb 24, 2026
cocl-pm
pushed a commit
to cocl-pm/mlx
that referenced
this pull request
Mar 22, 2026
Co-authored-by: Gleb Sterkin <g_sterkin@apple.com> Co-authored-by: Angelos Katharopoulos <a_katharopoulos@apple.com>
jzdziarski
pushed a commit
to jzdziarski/mlx
that referenced
this pull request
Jul 26, 2026
Co-authored-by: Gleb Sterkin <g_sterkin@apple.com> Co-authored-by: Angelos Katharopoulos <a_katharopoulos@apple.com>
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.
Proposed changes
The existing conv3d GPU implementation uses an explicit GEMM approach that materializes the full im2col matrix, leading to high memory usage and poor performance compared to PyTorch MPS (25-53% slower and unnecessarily memory-intensive).
This PR introduces an implicit GEMM convolution kernel for 3D (implicit_gemm_conv_3d) on the Metal backend, matching the existing 2D implicit GEMM pattern. The kernel avoids materializing the im2col matrix by computing input positions on-the-fly within the GEMM loop, significantly reducing memory overhead and improving throughput. It dispatches automatically when input channels are 16-aligned and there is no input dilation, falling back to the explicit GEMM kernel otherwise.
What changed
Benchmark script output
If C % 16 implicit GEMM is being used, explicit is used otherwise, note how implicit GEMM is 250% faster then PyTorch with a similar memory footprint and explicit GEMM is up to 50% slower and requires much more memory
Checklist
pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes