tracel-ai/cubecl

Multi-platform high-performance compute language extension for Rust.

What it solves

CubeCL solves the problem of hardware fragmentation in high-performance computing. Instead of writing separate kernels for CUDA, Metal, Vulkan, or CPU, developers can write a single, high-performance kernel in Rust that runs efficiently across all these platforms.

How it works

CubeCL uses a Rust procedural macro (#[cube]) to allow you to write compute kernels directly in Rust. This code is compiled just-in-time into an intermediate representation, which is then translated into the native language of your target hardware (such as PTX for NVIDIA, MSL for Metal, or WGSL for WebGPU). The framework maps hardware parallelism into four levels—Unit, Plane, Cube, and Hypercube—allowing kernels to adapt to the specific architecture of the device they are running on.

Who it’s for

This tool is for developers who need to write high-performance compute kernels for scientific computing or deep learning and want to maintain a single, type-checked, and testable codebase that works across multiple GPU and CPU backends.

Highlights

  • Write once, run anywhere: Compile the same Rust code for CUDA, HIP, Metal, Vulkan, WebGPU, and CPU.
  • Native Rust integration: Kernels are type-checked and borrow-checked by the standard Rust compiler, and can be tested locally on a CPU.
  • Automatic vectorization: Specify a vectorization factor at launch to leverage native SIMD instructions without manual implementation.
  • Comptime specialization: Use compile-time logic to generate optimized kernel variants for specific hardware or input shapes.
  • Built-in autotuning: Automatically benchmark and select the best kernel configuration for the specific hardware at runtime, with support for caching results.

Related

  • Project
  • Project
  • Dispatch
  • Project
  • Project