tracel-ai/cubecl
Multi-platform high-performance compute language extension for Rust.
What it solves
CubeCL addresses the difficulty of writing high-performance compute kernels that run across diverse hardware. Traditionally, developers must write separate code for different GPUs (CUDA for NVIDIA, HIP for AMD, Metal for Apple) and CPUs, or use high-level abstractions that may sacrifice peak performance. CubeCL allows developers to write a single kernel in Rust that is translated to run optimally on multiple backends.
How it works
CubeCL acts as a Rust language extension and Just-in-Time (JIT) compiler. It uses a #[cube] macro to rewrite Rust functions into an intermediate representation (IR) called pliron, which is then compiled into platform-specific languages like PTX, MSL, SPIR-V, or WGSL.
It organizes hardware parallelism into four levels:
- Unit: Individual registers (threads/invocations).
- Plane: Lockstep instructions (warps/subgroups).
- Cube: Shared memory (blocks/workgroups).
- Hypercube: Global memory across multiple cubes.
Who it’s for
It is designed for developers building low-level compute kernels, scientific computing libraries, and deep learning frameworks (such as Burn) who need maximum hardware performance without maintaining multiple separate codebases for different GPU/CPU vendors.
Highlights
- Single Codebase: Write kernels in Rust and deploy to CUDA, HIP, Metal, Vulkan, WebGPU, and CPU.
- Automatic Vectorization: Uses a
Vector<F, N>type where the widthNis determined at launch, lowering to native SIMD instructions. - Comptime: Allows modifying the compiler IR during the first compilation to specialize kernels for specific hardware instructions, shapes, or loop unrolling.
- Autotuning: Benchmarks different kernel configurations at runtime to automatically select the most performant version for the current device.
- Rust Integration: Kernels are type-checked and borrow-checked by the Rust compiler, and can be tested on CPUs using
cargo test.
Related
- Project
- Dispatch
- Dispatch
- Project
- Project