mindtorch_v2/mps: real Metal GPU compute backend for 30+ ops#2755
Merged
Conversation
Replace NumPy CPU fallbacks with actual Metal GPU compute kernels for element-wise, reduction, matmul, activation, and in-place ops. - Add metal_shaders.py: 105 MSL kernels (f32/f16 variants) - Add metal_compute.py: GPU dispatch engine with lazy compilation and pipeline caching (PyObjC + ctypes dual-path) - Extend runtime.py: compile_library, make_compute_pipeline, get_compute_encoder with ctypes fallbacks - Update mps_kernels.py: MPSMatrixMultiplication GPU matmul (4.3x faster than Accelerate BLAS at 1024x1024) - Update ops.py: GPU dispatch for 9 binary, 16 unary, 4 reduction, 4 NN fused, and 8 in-place ops with automatic f64/non-contiguous CPU fallback Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
lvyufeng
force-pushed
the
metal-gpu-backend
branch
from
March 8, 2026 07:06
251f208 to
903f61f
Compare
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.
Summary
MTLComputeCommandEncoderMetalKernelDispatcherengine: lazy shader compilation, pipeline state caching, and thread dispatch helpers (PyObjC + ctypes dual-path, no new dependencies)MPSMatrixMultiplicationkernel — 4.3x faster than Accelerate BLAS at 1024×1024New files
metal_shaders.pymetal_compute.pyModified files
runtime.pycompile_library,make_compute_pipeline,get_compute_encoder(PyObjC + ctypes)mps_kernels.pyMPSMatrixMultiplication(PyObjC + ctypes fallback)ops.pyTest plan
torch.allclosevalidation against CPU reference for every op🤖 Generated with Claude Code