Add native Apple Silicon Metal support - #413
Open
TaewoooPark wants to merge 6 commits into
Open
Conversation
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.
1. Scope
This change extends mumax³ from NVIDIA CUDA hosts to native Apple Silicon Macs running macOS 14 or later. Linux and Windows continue to select the existing CUDA implementation. Intel Macs are not included.
2. Technical implementation
The build selects the backend through
darwin/arm64build tags. Metal Shading Language kernels and Go launch wrappers implement the existing CUDA kernel contracts. An Objective C++ runtime bridge maps allocation, copies, ordered command submission, synchronization, and kernel launches to Metal and Apple unified memory. MPSGraph provides real to complex and complex to real FFT operations with the packed layout used by cuFFT. Ten round Philox4x32 with Box Muller generation provides thermal noise on Metal. Runtime shader compilation allows the build to work with Apple Command Line Tools without CUDA or the full Xcode application.3. Physics engine
No physical equation, material term, energy expression, solver, integrator, or upstream regression input is changed. The
.mx3language, high level Go model, physical parameters, and output formats remain common to both backends. The existing CUDA source remains selected on non Apple hosts.The Metal backend preserves the single precision numerical model and the FFT data layout used by the demagnetizing field convolution. Parallel reduction order can change the final floating point bits. Metal thermal simulations use Philox while CUDA uses the cuRAND XORWOW sequence, so equal seeds are reproducible within Metal but select different sample sequences across backends. Thermal correctness is therefore tested statistically rather than by matching individual random samples.
4. Validation
All 15 runnable simulations from the official mumax³ examples page completed on Apple M4 Metal with 15 passes, zero failures, 96 OVF files, 1,118 table lines, and no empty artifact or NaN or Inf table value. The exact inputs, execution logs, outputs, provenance, and GPL attribution are recorded in the official examples result.
The nonthermal physics cohort passed 15 of 15 unchanged upstream tests and 103 of 103 original assertions, giving 100.000 percent conformance within the upstream tolerances. Ten average magnetization vectors produced 99.9923 percent mean normalized L2 agreement, 99.9984 percent median agreement, and 99.9415 percent minimum agreement with the embedded upstream references. All 19 zero tolerance assertions matched exactly. The method and individual values are recorded in the physics validation result.
This PR branch also passed the Metal generator and shader checks, all Go tests with the cache disabled, the macOS installer build and Metal initialization test, validation of all 176 upstream
.mx3files, and a fresh execution of the same 15 nonthermal physics tests with 15 passes.5. Installation
The README adds one Apple Silicon section containing both the automated fresh Mac installer and the separate manual dependency, clone, build, path, and verification procedure.
6. Author
My name is Taewoo Park and I am an undergraduate physics student at the Korea Advanced Institute of Science and Technology (KAIST) and a research intern at the KAIST Ultrafast Spin Dynamics Laboratory (USDL), led by Prof. Kab-Jin Kim.
Contact: ptw151125@kaist.ac.kr