Are you a Rust developer who wants to learn CUDA programming?
Try a GPU programming challenge in Rust. Write a kernel, run it on a real GPU, and use profiling to see what your code is doing.
I added Rust support to GPUFlight Performance Lab so you can do exactly that. Start with a provided problem, make a change, and compare the results.
Learn GPU programming in Rust by solving hands-on challenges in GPU occupancy, memory coalescing, shared-memory bank conflicts, tiled matrix multiplication, atomic contention, warp-level reductions, stencil optimization, online softmax, and so on.
Rust selected in GPUFlight Performance Lab. This vector-add kernel uses 256 threads per block.
Comparing it with CUDA C++ has been a useful way to see how each compiler handles the same work.
One thing I keep coming back to is the compiler output. The source code tells me what I asked for. Looking at the compiled instructions helps me understand what happened to it.
With NVIDIA introducing CUDA Rust, there is more to explore here. GPUFlight’s Rust labs use cuda-oxide, which compiles Rust kernels to PTX.
PTX is an intermediate instruction language for NVIDIA GPUs. It sits between your source code and the machine instructions the GPU executes. You can follow the loads, arithmetic, checks, and branches.
That makes it useful for learning.
I started with vector addition. Each GPU thread reads two values, adds them, and writes the result.
Simple enough that I could follow both versions without getting lost in the algorithm.
The CUDA C++ version uses raw pointers. It checks whether the thread’s index is below the element count, then performs the addition.
The Rust version uses slices for the inputs. A slice carries its length along with its address. In this example, the compiled code checks whether each input access stays within that length.
Both versions do the same basic work. But the interfaces give the compiler different information.
When I first saw the longer Rust listing, I wondered how much extra work it was doing.
Reading the PTX helped. I could find the same two loads, addition, and store in both versions. In Rust, I could also follow the input checks to the paths that trap on an invalid access.
Rust PTX: input-length checks at lines 69–70 and 76–77, then loads, addition, and a store at lines 85–91.
The measured kernel times were close: about 0.85 milliseconds for C++ and 0.86 milliseconds for Rust on the L4.
Same NVIDIA L4. Baseline is C++; candidate is Rust. This is one captured pair, not a language benchmark.
That small difference needs repeated measurements before drawing conclusions. These implementations also use different toolchains and PTX versions. The listing length alone cannot tell us which will run faster.
What interested me was seeing some of the design choices become visible.
In this C++ interface, the programmer is responsible for providing valid buffers. The Rust slice interface carries information used to check accesses. Those checks can also be removed when validity can be established. The cuda-oxide documentation explores this in more detail.
This is the kind of exploration I want Performance Lab to make easier.
You start with a problem, some code, and a measurable target. Choose Rust in a supported lab, edit the kernel, and run it on a managed GPU.
Then inspect the result. Change one thing and run it again. Select two completed runs and click Compare to examine their saved source, profiling results, and compiled code.
Select the C++ run, select the Rust run, and open Compare. Recorded in the actual GPUFlight app.
You can compare two Rust implementations or look at Rust alongside CUDA C++.
Rust support is still in beta, and language availability depends on the lab.
I developed the lab solutions with AI assistance. If you spot anything incorrect or see a more efficient approach, please let me know!
If you’re curious about Rust on the GPU, start with a small kernel. Follow what the compiler did with it. Then check the measurements.
You can try it in GPUFlight Performance Lab.




Top comments (0)