C++ vs. Rust for CUDA: What the PTX Reveals
C++ or Rust for CUDA? Follow the same vector-addition kernel through GPUFlight Performance Lab, from saved source code to PTX and measured kernel time.
Try Performance Lab: gpuflight.com
Following NVIDIA's introduction of CUDA Rust, we compare CUDA C++ compiled with nvcc and Rust compiled with cuda-oxide. This guided app demo shows how to select two runs, open Compare, read their saved source, and follow the exact PTX lines for loads, addition, stores, bounds checks, and trap paths.
In this NVIDIA L4 pair, the C++ listing contains 22 PTX instructions and the Rust listing contains 57. Measured kernel times are 853.25 microseconds and 861.15 microseconds, respectively—a 0.9% difference. These are results from one pair of implementations, not a language benchmark. The toolchains and PTX versions differ, and listing counts are not execution times.
The interesting part is what the interfaces reveal: raw pointers leave buffer validity to the programmer, while Rust slices carry information used for checks. Checks can also be optimized away when validity can be established. Choose the guarantees and ecosystem you need, then measure your workload.
CHAPTERS
00:00 C++ vs. Rust for CUDA
00:18 The same vector addition
00:41 How C++ and Rust reach the GPU
01:20 Select runs and open Compare
01:43 Read the saved C++ source
02:09 Read the matching Rust source
02:38 Open the PTX listings
02:58 C++ loads, addition, and store
03:26 Find the same work in Rust
03:45 The shared index check
04:07 Rust input bounds checks
04:36 Follow the branches to traps
04:56 Output and launch checks
05:18 Instruction counts and compiler context
05:39 Compare kernel time
06:10 What the interfaces reveal
REFERENCES
NVIDIA's CUDA Rust introduction:
developer.nvidia.com
NVIDIA PTX documentation:
docs.nvidia.com
cuda-oxide bounds checks:
nvidia.github.io
CREDITS
Rust logo: Rust Project (rust-lang/rust-artwork), CC BY 4.0 (creativecommons.org), resized.
C++ logo: Standard C++ Foundation (isocpp/logos), resized.
NVIDIA eye symbol identifies the CUDA platform; NVIDIA is a trademark of NVIDIA Corporation.
Narration uses the Kokoro Heart synthetic voice.
#CUDA #Rust #GPUProgramming
51 views
Mentions
C++ vs. Rust for CUDA: What the PTX Reveals C++ or Rust for CUDA? Follow the same vector-addition kernel through GPUFlight Performance Lab, from saved source code to PTX and measured kernel time. Try Performance Lab: gpuflight.com Following NVIDIA's introduction of CUDA Rust, we compare CUDA C++ compiled with nvcc and Rust compiled with cuda-oxide. This guided app demo shows how to select two runs, open Compare, read their saved source, and follow the exact PTX lines for loads, addition, stores, bounds checks, and trap paths. In this NVIDIA L4 pair, the C++ listing contains 22 PTX instructions and the Rust listing contains 57. Measured kernel times are 853.25 microseconds and 861.15 microseconds, respectively—a 0.9% difference. These are results from one pair of implementations, not a language benchmark. The toolchains and PTX versions differ, and listing counts are not execution times. The interesting part is what the interfaces reveal: raw pointers leave buffer validity to the programmer, while Rust slices carry information used for checks. Checks can also be optimized away when validity can be established. Choose the guarantees and ecosystem you need, then measure your workload. CHAPTERS 00:00 C++ vs. Rust for CUDA 00:18 The same vector addition 00:41 How C++ and Rust reach the GPU 01:20 Select runs and open Compare 01:43 Read the saved C++ source 02:09 Read the matching Rust source 02:38 Open the PTX listings 02:58 C++ loads, addition, and store 03:26 Find the same work in Rust 03:45 The shared index check 04:07 Rust input bounds checks 04:36 Follow the branches to traps 04:56 Output and launch checks 05:18 Instruction counts and compiler context 05:39 Compare kernel time 06:10 What the interfaces reveal REFERENCES NVIDIA's CUDA Rust introduction: developer.nvidia.com NVIDIA PTX documentation: docs.nvidia.com cuda-oxide bounds checks: nvidia.github.io CREDITS Rust logo: Rust Project (rust-lang/rust-artwork), CC BY 4.0 (creativecommons.org), resized. C++ logo: Standard C++ Foundation (isocpp/logos), resized. NVIDIA eye symbol identifies the CUDA platform; NVIDIA is a trademark of NVIDIA Corporation. Narration uses the Kokoro Heart synthetic voice. #CUDA #Rust #GPUProgramming