Skip to content

Build1 publisher3 min readPublished

Nvidia's two-track Rust support puts the safety payoff in the host code

A practical dev.to guide sets out the low-level and high-level tracks for writing CUDA kernels in Rust, then demonstrates them with a nightly-only kernel whose body dereferences three raw pointers inside an unsafe function.

The Engineer · Build desk

Illustration accompanying Nvidia's two-track Rust support puts the safety payoff in the host code

What happened

  • A dev.to practical guide describes Nvidia's native GPU programming support for Rust as a "two tracks" approach to writing CUDA kernels, one low-level and one higher-level.
  • The guide says that for the past decade Rust GPU work ran through community projects: rust-cuda via ptx-builder and the nvptx64-nvidia-cuda target, wgpu for compute shaders, and cudarc for FFI bindings.
  • Its getting-started path installs a nightly toolchain and the rust-src component, adds the nvptx64-nvidia-cuda target, and checks that nvcc is present, with nightly required for GPU codegen features.

Compiled by The EngineerSomething wrong?How this is made

Why it matters

  • decision A team weighing a Rust rewrite against binding to existing C++ is choosing a build that pins an unstable compiler. The pin is what CI has to carry, and it outlasts the kernel that motivated it.
  • exposure Device-side bugs stay exactly where they were. Nothing in the sample kernel body is checked by the borrow checker, so kernel review effort does not drop when the language changes.
  • contradiction The guide treats the nvptx64 target as the superseded community route and then installs it. On this evidence, a first-party toolchain replacing community crates is not yet demonstrated.
  • constraint Device codegen sits behind a feature gate, so a toolchain bump can break a build for reasons that have nothing to do with the kernel or the CUDA driver.

A Rust CUDA build has exactly one handoff, and it is PTX text. The device module compiles for the nvptx64-nvidia-cuda target, build.rs writes kernel.ptx into OUT_DIR, and the host binary reads that file back with include_str! before passing it to Module::from_ptx and launching on a non-blocking stream [7][13]. The driver loads PTX, and by then the source language is gone. "Rust doesn't make your kernels magically faster. The GPU doesn't care what language emitted the PTX," the guide says [11].

The sample kernel shows what that leaves. The file is declared #![no_std] with #![feature(abi_ptx)], and the entry point is a pub unsafe extern "ptx-kernel" fn taking three raw pointers and an i32 [8]. The body derives its index from _thread_idx_x, _block_idx_x and _block_dim_x, checks idx < n by hand, then writes *c.add(i) = *a.add(i) + *b.add(i) [9]. That single statement dereferences three raw pointers inside an unsafe function [10]. The bounds check is written out, the same way it is in the C++ version printed beside it [19]. On where the win sits, the guide is straight: host-side code managing allocation, launches and transfers, where it puts use-after-free on device pointers and forgotten cudaFree calls [12].

The walkthrough itself runs on the community path. rust-cuda, reached through ptx-builder and the nvptx64-nvidia-cuda target, appears on the guide's list of unofficial tooling that first-party backing supersedes, alongside wgpu and cudarc [4]. The setup steps then add nvptx64-nvidia-cuda, and the host program is written against cust [7][13][20]. Nowhere does it cite Nvidia's announcement or name a crate, a release or a version [16].

For the official-support framing to change a build-versus-bind decision, the toolchain would have to show crates published by Nvidia, device codegen on stable instead of an unstable feature gate, and cuda-gdb and nsight resolving Rust frames. That last item is precisely what the guide says community crates lacked, along with guaranteed compatibility across CUDA toolkit releases [5]. Today the adoption cost is a pinned nightly in CI and nvcc on the build host [7][14].

In my view the two-track split is honest about who it serves. Track two is an iterator-style API compared to rayon, for people who do not want to size grids and blocks for every operation [3]. Track one gives direct control over thread blocks, shared memory, warps and memory coalescing, and the guide says it is aimed at engineers porting existing CUDA code [2][15]. For a team running an inference server, the part that changes is the host: swapping FFI glue for a first-party host API removes the bug class the guide names, and the kernel still needs the same review it needed in C++. The guide says Nvidia is targeting both the performance-obsessed kernel author and the application developer who wants GPU acceleration without becoming a CUDA architecture expert [17].

What to watch

  • Nvidia publishing crates and docs under its own name, with a version number, would settle whether the two tracks exist as shipped code.
  • A stable-channel path for nvptx64 device codegen would take the nightly pin out of CI.
  • cuda-gdb or nsight sessions that resolve Rust symbols in device frames, which is the tooling gap the guide attributes to community crates.
Loading claim ledger
Loading source directory links
Loading share composer
Loading topic controls
Loading related stories