Fundamentals 7 min read

Running CUDA Code on Apple GPU with Minimal Kernel Changes

A CUDA/HIP‑based 3‑D fluid simulation was ported to an Apple M3 Pro device via a Clang‑HIP → SPIR‑V → Vulkan → MoltenVK conversion pipeline, achieving roughly ten‑fold speedup without any Metal‑specific API changes and preserving numerical accuracy.

Machine Heart
Machine Heart
Machine Heart
Running CUDA Code on Apple GPU with Minimal Kernel Changes

A CUDA/HIP program originally written for NVIDIA GPUs was executed on an Apple device equipped with an M3 Pro chip with almost no modifications to the kernel code. The work, shared by X‑user @Abhinav, targets a real‑world 3‑D fluid‑simulation workload rather than a simple arithmetic demo.

The GPU computing ecosystem has been fragmented for over a decade: NVIDIA uses CUDA, AMD uses HIP, and Apple provides Metal. Because these APIs are incompatible, porting a CUDA program to Metal typically requires extensive rewrites. Instead of developing a native Metal version, the developers built a conversion path: the program is first processed by Clang/HIP, then translated to SPIR‑V, passed through Vulkan and MoltenVK, and finally executed on Apple’s Metal GPU. No Metal‑specific particle APIs were added, keeping the application layer’s original CUDA/HIP‑style kernel calls intact and achieving true hardware transparency.

GPT‑5.6 Sol played a crucial role in the process. It helped construct the device‑side memory layout and, within about six hours, identified compatibility issues between MoltenVK and SPIR‑V, proposing work‑arounds that enabled the pipeline to function.

The benchmark used a complex 3‑D Smoothed Particle Hydrodynamics (SPH) dam‑break simulation, which involves scanning, sorting, reordering, cell and neighbor‑list construction, ghost‑particle exchange, reductions, and atomic operations. On the Apple device’s Metal GPU the simulation completed in roughly six seconds, whereas a sequential CPU run took about sixty seconds—an approximate ten‑fold speedup with GPU utilization near 100 %.

Importantly, the speedup did not sacrifice accuracy. The authors verified that the physical results (key parameters and simulation trajectories) from the Metal version matched those of the original CUDA/HIP version, confirming that the Apple GPU performed the scientific computation correctly.

The developers note that particle storage scales linearly with particle count N, while neighbor‑search work scales as O(N·k) (k being the fixed neighbor count). The reported ten‑fold gain reflects a single‑node comparison; they suggest that future extensions could leverage Apple’s Thunderbolt‑based RDMA to enable multi‑node dynamic load balancing.

Despite the achievement, the authors acknowledge limitations: Apple’s Metal GPUs currently lack strong double‑precision support, which is essential for many high‑precision scientific domains such as weather forecasting and aerospace simulation, where NVIDIA’s professional GPUs remain dominant.

Some community members questioned the practical value, arguing that macOS is not a typical platform for large‑scale scientific simulations. The developer responded that the main benefit is convenience: small‑scale debugging runs on a laptop are far faster than CPU‑only runs, and the same binary can later be deployed unchanged on GPU clusters, simplifying workflow.

This experiment demonstrates that CUDA/HIP‑style algorithms can run transparently on diverse hardware back‑ends like Apple Silicon, hinting at a future where developers are less constrained by a single GPU ecosystem. It also showcases an emerging role for AI systems such as GPT‑5.6 Sol, moving from code‑generation assistance to low‑level system design, optimization, and cross‑platform debugging.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

performanceCross‑platformCUDAGPUMetal3D fluid simulationOpenFPM
Machine Heart
Written by

Machine Heart

Professional AI media and industry service platform

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.