chelsea0x3b/cudarc

Safe rust wrapper around CUDA toolkit

What it solves

It provides a minimal and safe Rust API for interacting with the NVIDIA CUDA toolkit, allowing developers to leverage GPU acceleration without dealing directly with the raw, unsafe C-style FFI (Foreign Function Interface) calls typically required for CUDA development.

How it works

The project creates a layered wrapper system around the CUDA toolkit libraries (such as the Driver API, NVRTC, cuBLAS, and cuDNN). It organizes these wrappers into three levels of abstraction:

  1. sys: Raw FFI APIs generated via bindgen.
  2. result: A thin wrapper that converts raw return codes into Rust Result types.
  3. safe: High-level, safe abstractions that prioritize ergonomics and memory safety.

It supports multiple linking methods (dynamic loading, dynamic linking, and static linking) and allows users to specify the CUDA version they are targeting at build time.

Who it’s for

Rust developers who want to write high-performance GPU kernels and utilize NVIDIA's specialized libraries for linear algebra, random number generation, and deep learning primitives within a safe Rust environment.

Highlights

  • Broad Library Support: Wrappers for a wide array of CUDA tools including cuBLAS, cuDNN, NCCL, cuRAND, and cuSPARSE.
  • Runtime Compilation: Integration with NVRTC for compiling CUDA kernels at runtime.
  • Flexible Linking: Supports dynamic loading (no libraries required at build time), dynamic linking, and static linking.
  • Ergonomic Kernel Launching: Uses a builder pattern to specify kernel arguments and launch configurations.

Related

  • Project
  • Dispatch
  • Project
  • Dispatch
  • Project