Rust on GPUs matches CUDA and HIP performance — and keeps memory safety

Rust on GPUs matches CUDA and HIP performance — and keeps memory safety

A new research paper demonstrates that the Rust programming language can be used to write GPU kernels with competitive performance against native, hand-optimized C++ code for both NVIDIA CUDA and AMD HIP, while retaining Rust's memory safety guarantees.

The paper, authored by Manuel S. Drehwald, Marcelo Domínguez, Kevin Sala, Alán Aspuru-Guzik, and Johannes Doerfert, leverages LLVM's Offload infrastructure and the Rust compiler to offload computations to GPU accelerators. The approach allows most GPU kernels to avoid using raw pointers, which is a common source of bugs in C++-based GPU programming. The researchers claim that their front-end is safe and takes advantage of Rust's ownership model and borrow checker to prevent memory errors at compile time.

Benchmark results presented in the paper show that the Rust-based LLVM offload implementation is generally competitive with native AMD HIP and NVIDIA CUDA solutions. Rust won some tests and lost others, but overall the performance gap was narrow. The authors are aware of additional optimization opportunities, particularly around code generation and intermediate representation (IR) differences, which they believe could close the remaining gaps.

The work builds entirely on LLVM back-ends and the Rust compiler, meaning no proprietary toolchains are required. This could make Rust a viable alternative for GPU programming in scientific computing, machine learning, and other fields where both performance and safety are critical.

The full paper is available on arxiv.org. Upstream tracking for Rust offload support in LLVM is maintained via a ticket in the Rust-Lang repository.

Tags: NvidiaAMD
Slate (Sl8) — the new social network. Post, grow your audience and earn — plus staking rewards that actually pay.
Invite codehXA6hX
Join Slate