Taewoo Park

Research

mumax3-for-mac

The CUDA-based micromagnetic simulator, rebuilt to run natively on Apple Silicon. The first public implementation of its kind in the field, and the first thing I had to build before anything above it was worth building.

A whole discipline's standard tool, locked to one vendor's hardware

mumax3 calculates nanoscale magnetisation dynamics and has been a working instrument in magnetism research for over a decade. It is also built around NVIDIA CUDA, which is unavailable on current Macs, so on Apple hardware it does not run at all — not slowly, not in a degraded mode, not at all. Even a light local test meant keeping a Linux box with an NVIDIA card, renting one, or going without.

My fork replaces that GPU execution layer with a native Metal implementation, so an Apple Silicon Mac runs ordinary .mx3 simulations locally with no NVIDIA GPU, no CUDA, no virtual machine and no remote Linux host. When an important tool in a discipline is restricted to one environment, the discipline quietly loses the people whose setup does not match, and I was one of them. This is the bottleneck I removed first.

Five CUDA dependencies, five Metal replacements, one contract preserved

CUDA compute kernels become Metal compute shaders behind an Objective-C++ runtime bridge, keeping the existing mumax3 kernel contracts and the FP32 model. cuFFT becomes an MPSGraph FFT that preserves the packed R2C and C2R layout the demagnetising-field convolution depends on. cudaMalloc and CUDA streams become Apple unified-memory buffers, command batching and one ordered Metal queue, so buffer semantics and execution ordering survive intact.

cuRAND thermal noise becomes Philox4x32-10 with Box–Muller normal generation, giving seeded reproducibility on Metal and validated noise statistics. CUDA-only platform bindings become darwin/arm64 build tags and compatibility shims, leaving the .mx3 language and the high-level Go API untouched.

Underneath, I use X-contiguous 32-wide SIMD tiles suited to Apple GPUs, and compile the shader library at runtime through the system Metal runtime — which is why the full Xcode application and an offline Metal compiler are not required, and Command Line Tools alone are enough.

The equations were not reimplemented, and that is the point

I did not rewrite the physical equations or the solvers independently. The native backend executes the existing mumax3 model through Metal, so the model anyone cites is still mumax3. I validated against unchanged upstream CUDA-era regression references: fifteen of fifteen non-thermal upstream physics tests passed, 103 of 103 assertions landed inside the original upstream tolerances, nineteen of nineteen zero-tolerance assertions matched exactly, and all fifteen official mumax3 example-page simulations completed.

Mean average-magnetisation vector agreement came out at 99.9923%, with a minimum across the suite of 99.9415%. The example inputs are byte-for-byte identical to the upstream template, and I committed their outputs, logs and provenance to the repository rather than summarising them.

A hundred per cent means tolerance conformance, not bit-for-bit identity

The 100.000% figure is conformance to the original tolerances, and I say so in the README rather than letting the number stand on its own. Parallel GPU reductions can differ in their last floating-point bits, and no port that changes the reduction order can honestly claim otherwise.

Thermal simulations are a further, separate caveat. Philox replaces cuRAND's XORWOW sequence, so the same seed is reproducible on Metal but does not generate the same sample-by-sample trajectory as CUDA. What I validated there is the statistical behaviour, and I put that distinction where a user meets it before relying on it, not in a footnote.

The installation has to survive an unfamiliar machine

A single curl-piped script on a fresh supported Mac checks the machine and shell architecture, opens Apple's Command Line Tools installer when it is needed, installs native Homebrew and a compatible Go toolchain if they are missing, clones and builds the Metal port, configures the binary path, and finishes by running mumax3 -test so the first thing you see is whether it actually works.

I made it safe to rerun after an interruption, because completed prerequisites are reused rather than redone. From an existing checkout the same script runs directly. The support envelope is plain: Apple Silicon, M1 or newer, on macOS 14 or newer. Intel Macs are not supported, and the original CUDA backend remains available for NVIDIA-equipped Linux and Windows systems.

The same simulation, with or without a browser watching it

The default mode runs the simulation with the live web interface served at 127.0.0.1:35367, writing output to example.out/. For a headless benchmark, a script or a batch job, the interface is disabled explicitly with an empty -http flag. Both modes execute the same simulation and produce the same output, which matters more than it sounds: a tool whose batch path and interactive path can disagree is a tool I would not trust a sweep to.

Against a comparable notebook CUDA part, 37.5% of the throughput

For price-class context rather than a claim of parity, I put the measured base M4 Metal result beside the RTX 4050 Laptop GPU in mumax3's own four-million-cell benchmark. Both appeared in consumer notebook families with overlapping launch-price ranges. The M4 reaches 37.5% of the CUDA throughput, and I am explicit in the README that this is not an exact configuration-normalised or price-normalised test.

The machine I measured on was a fanless, base ten-core-GPU M4 MacBook Air, so this is one conservative hardware datapoint rather than a ceiling for Apple Silicon. Absolute results, raw runs, the full CUDA comparison, the projections, the limitations and a protocol for submitting your own measurement all live in the benchmark documentation, alongside a registry that keeps estimated Apple entries visibly separate from measured ones.

The measured M4 entry sits inside the published CUDA ranking; estimated Apple parts are marked as estimates and must be replaced by submitted measurements
The measured M4 entry sits inside the published CUDA ranking; estimated Apple parts are marked as estimates and must be replaced by submitted measurements

A benchmark that shows where it sits rather than where it wins

The full chart is not a victory plot, and I did not draw it as one. It orders every entry by throughput, puts the single measured Apple result in among published CUDA numbers, and marks every projected Apple part as an estimate anchored to that one measurement — with a note on the figure itself saying the orange bars are not hardware measurements and not official mumax3 ranks.

That habit runs through everything on these pages. A benchmark that hides its edges is worth nothing to me, so I draw the edges onto the chart.

The full four-million-cell comparison against the published CUDA snapshot
The full four-million-cell comparison against the published CUDA snapshot

Running was the first problem; running fast enough to iterate was the next

At roughly a third of a mobile CUDA part, the port let me develop and check a script on my own machine, which was the whole point. What it did not buy me was iteration — three mesh refinements and a re-run sweep between one thought and the next. Closing that gap is mumax3-ultrafast; putting an agent on the result afterwards is spinloop.

The project is derived from mumax3, whose design and verification are described in Vansteenkiste and colleagues, AIP Advances 4, 107133 (2014), and is distributed under the GNU GPL v3 or later. My notices preserve the upstream CUDA linking permission and identify the July 2026 macOS modifications, with separate third-party notices for Random123, Go, SVGo and Freetype-Go.