NVlabs/cutile-rs

cuTile Rust provides a safe, tile-based kernel programming DSL for the Rust programming language. It features a safe host-side API for passing tensors to asynchronously executed kernel functions.

cuTile Rust (cutile‑rs)

What it is – A Rust library that lets you write GPU kernels safely and without data races. It does this by extending Rust’s ownership model to the GPU: mutable outputs are split into disjoint tiles while read‑only inputs can be shared. The source code is compiled just‑in‑time to NVIDIA’s CUDA Tile IR, then executed either synchronously, with Rust async/await, or as a CUDA graph.

Why it matters – GPU programming is notoriously error‑prone (race conditions, unsafe pointer arithmetic). cuTile Rust gives Rust developers a high‑level, memory‑safe way to target modern NVIDIA GPUs (Ampere, Ada, Hopper, Blackwell, etc.) while still exposing low‑level performance knobs such as FP4 packing and block‑scaled MMA. The project is used by several Rust‑based ML frameworks (e.g., Hugging Face’s Candle and mistral.rs) to implement fast quantized linear layers and mixture‑of‑experts kernels.

Current status – Early‑stage research code, actively developed. The repository is archived; development has moved to the NVIDIA/cuda‑rust monorepo (see the notice at the top of the README). Expect API breakage and missing features, but the core crates (cutile, cutile‑macro, cutile‑compiler, etc.) are functional and can be tried today.

How to get started

  1. Install Rust (stable 1.89+). No nightly needed.
  2. Install CUDA 13.3 (or a compatible 13.x version) and set CUDA_TOOLKIT_PATH (or CUDA_HOME).
  3. Clone the repo (or add the crates from crates.io) and run an example:
    cargo run -p cutile-examples --example hello_world
    
    You should see a message from a tile running on the GPU.
  4. For a more realistic workload, try the saxpy or async_gemm examples.

Typical workflow

use cutile::prelude::*;

#[cutile::module]
mod kernel {
    use cutile::core::*;

    #[cutile::entry()]
    fn add<const B: i32>(
        z: &mut Tensor<f32, { [B] }>,
        x: &Tensor<f32, { [-1] }>,
        y: &Tensor<f32, { [-1] }>,
    ) {
        let tx = x.load_like(z);
        let ty = y.load_like(z);
        z.store(tx + ty);
    }
}

fn main() -> Result<(), cutile::Error> {
    let x = cutile::api::ones::<f32>(&[1024]);
    let y = cutile::api::ones::<f32>(&[1024]);
    let z = cutile::api::zeros::<f32>(&[1024]).partition([128]);

    let (z, _x, _y) = kernel::add(z, x, y).sync()?;
    let result = z.unpartition().to_host_vec().sync()?;
    assert_eq!(result, vec![2.0_f32; 1024]);
    Ok(())
}
  • The #[cutile::module] macro turns add into a GPU kernel and creates a host‑side launcher.
  • partition([128]) splits the mutable output into 128‑element tiles, which determines the launch grid (here 8 tiles).
  • .sync() JIT‑compiles the kernel, launches it, and returns the runtime arguments in the same order they were declared.

Supported hardware / features

Compute capability Minimum Tile IR
sm_80‑sm_89 (Ampere/Ada) 13.2
sm_90 (Hopper) 13.3
Blackwell sm_100‑sm_121 13.2
sm_107 13.4

Advanced raw features (e.g., FP4 packing, block‑scaled MMA) require specific Tile IR versions and GPU generations – the README lists the exact matrix.

Building & testing

  • Unit tests – cargo test --package cutile-ir (IR builder), cutile-compiler, cutile.
  • Examples – run any example with cargo run -p cutile-examples --example <name>.
  • Benchmarks – cargo bench or the provided scripts/run_all.sh script.
  • Nix support – a flake is included; nix develop gives you a ready‑to‑go dev shell with CUDA and Rust pre‑configured.

Related ecosystem

  • Candle, mistral.rs, Grout – Rust ML projects that already use cuTile Rust kernels for quantized linear layers and MoE.
  • cuTile Python – a Python front‑end to the same Tile IR, showing cross‑language relevance.
  • TileGym – a collection of Tile IR kernel examples, some implemented in cuTile Rust.

Paper & citation – The project is backed by the paper “Fearless Concurrency on the GPU” (arXiv 2606.15991). It reports that safe Rust kernels achieve performance within 0.1 % of unchecked Rust and within a few percent of cuBLAS for large GEMM workloads.

License – Apache 2.0 (all crates).


Bottom line – cuTile Rust is a cutting‑edge, safety‑first approach to GPU kernel development in Rust. If you are comfortable with Rust and need to write custom high‑performance kernels (e.g., for ML inference, quantization, or research kernels), this library gives you a memory‑safe API while still exposing the low‑level performance knobs required for state‑of‑the‑art NVIDIA hardware.

Related

  • Dispatch
  • Dispatch
  • Project
  • Project
  • Project