cuTile Rust (cutile-rs) 是一个基于分块的系统,用于以地道的 Rust 编写内存安全、无数据竞争的 GPU 内核。它将 Rust 的所有权规则扩展到了 GPU 启动边界之外:在启动前,可变张量被分割成互不重叠的片段,不可变张量则被共享,生成的启动器在 GPU 工作执行期间保持所有权。同一模型支持同步启动、异步流水线和 CUDA 图回放。`#[cutile::module]` 宏将每个内核的捕获 Rust AST 嵌入到宿主二进制文件中;当需要某个内核时,cuTile Rust 通过 CUDA Tile IR 将该 AST 即时编译为 GPU cubin。当需要更低层级的控制时,仍可进行局部退出。
项目状态
我们很高兴发布这个研究项目,以展示如何在 Rust 生态系统中实现 GPU 编程。该软件处于早期阶段,正在积极开发中:在我们努力改进的过程中,您可能会遇到错误、不完整的功能以及 API 变更。话虽如此,我们希望您有兴趣在工作中尝试它,并通过提供您的使用反馈来帮助塑造其发展方向。
如果您有兴趣贡献,请查看 CONTRIBUTING.md。
快速开始
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 = load_tile_like(x, z); let ty = load_tile_like(y, z); z.store(tx + ty); } } fn main() -> Result<(), Error> { let x = api::ones::<f32>(&[1024]); let y = api::ones::<f32>(&[1024]); let z = api::zeros::<f32>(&[1024]).partition([128]); let (_z, _x, _y) = kernel::add(z, x, y).sync()?; Ok(()) }
`#[cutile::module]` 宏将 `add` 转换为一个 GPU 内核,并生成一个宿主端启动器。宿主代码构建惰性张量操作,将可变输出分割成 128 个元素的块,并调用 `.sync()` 来即时编译并执行内核。
内核签名将访问规则带入设备代码:`z` 是独占的可变输出,而 `x` 和 `y` 是共享的只读输入。函数体加载与输出分块匹配的输入块,将它们相加,并存储结果。启动网格 `(8, 1, 1)` 由分块推断得出:1024 ÷ 128 = 8 个块。
- 通过 `cargo run -p cutile-examples --example saxpy` 运行一个类似的示例。
- 更多内核和宿主端 API 的使用示例可以在这里找到。
论文
cuTile Rust 论文《Fearless Concurrency on the GPU》可在此处获取。在 NVIDIA B200 上,cuTile Rust 在逐元素运算中达到 7 TB/s,在 GEMM 中达到 2 PFlop/s,分别约为峰值内存带宽的 91% 和密集 f16 峰值的 92%。其 GEMM 结果与 cuBLAS 相当,而 B200 安全开销微基准测试表明,cuTile Rust 在增加安全性的同时没有带来可测量的运行时开销:在 M=N=K=8192 时,安全的 Rust 持久化 GEMM 达到 2.07 PFlop/s(B200 密集 f16 峰值的 92%),与对应的底层 Tile IR 变体相差在 0.3% 以内。
该论文还评估了 Grout,这是一个与 Hugging Face 合作、使用 cuTile Rust 构建的 Qwen3 推理引擎。在 batch-1 Qwen3 解码中,Grout 在 NVIDIA GeForce RTX 5090 上对 Qwen3-4B 达到 171 tokens/s,在 B200 上对 Qwen3-32B 达到 82 tokens/s,根据我们的 HBM 屋顶线分析,在内存受限的推理任务上展现出具有竞争力的 SOTA 性能。
论文评估的可复现性工件可在此处获取。论文相关的测量基于 cuTile Rust 0.2.0 版本运行,论文中使用的 Grout 版本可在此处获取。
引用
如果您在研究中使用 cuTile Rust,请引用该论文:
@misc{elibol2026fearlessconcurrencygpu, title = {Fearless Concurrency on the GPU}, author = {Elibol, Melih and Roesch, Jared and Gelado, Isaac and Buehler, Eric and Garland, Michael}, year = {2026}, eprint = {2606.15991}, archivePrefix = {arXiv}, primaryClass = {cs.PL}, url = {https://arxiv.org/abs/2606.15991} }
相关项目与参考
- Grout:由 Hugging Face 用 Rust 编写的 Qwen 3 推理引擎,基于 cuTile Rust 构建,可作为生产级内核调用点的参考。
- cuTile Python:使用 CUDA Tile 进行 Python 内核编程。
- TileGym:CUDA Tile 内核示例与调优模式。
- cuda-oxide:NVlabs 的实验性 Rust 到 CUDA 编译器,用于在 Rust 中编写 SIMT 风格的 GPU 内核。
- CUDA Tile IR 文档:CUDA Tile IR 参考文档。
- CUDA 文档:CUDA 工具包文档。
- Rust NVPTX 后端:rustc 为 NVIDIA GPU 生成 PTX 的目标支持。
cuTile Rust 面向基于 tile 的内核,这些内核通过 CUDA Tile IR 进行降级,其 API 围绕张量分区和面向张量核心的操作构建。
设置
要求
- NVIDIA GPU with compute capability
sm_80or higher (minimum supported architecture:sm_80).- sm_100+ 由 CUDA 13.1+ 支持。
- sm_8x 支持在 CUDA 13.2 中新增。
- CUDA 13.3 新增了 sm_90 支持,因此 CUDA 13.3 用户现在拥有 sm_80+ 的覆盖范围。
- 推荐使用 CUDA 13.3(支持 sm_80+ 以及 CUDA Tile IR 13.3 功能,如 FP4 打包和块缩放 MMA)。
- Rust 1.89+
- Linux(已在 Ubuntu 24.04 上测试通过)
安装
Rust
安装 Rust:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh rustup default stable
CUDA
按照官方说明为你的操作系统安装 CUDA 13.3:https://developer.nvidia.com/cuda-downloads
配置环境
将 CUDA_TOOLKIT_PATH 设置为你的 CUDA 13.3 安装目录。
示例 .cargo/config.toml:
[env] CUDA_TOOLKIT_PATH = { value = "/usr/local/cuda-13", relative = false }
验证安装
运行 hello world 示例:
cargo run -p cutile-examples --example hello_world
如果一切正常,你应该会看到:Hello, I am tile <0, 0, 0> in a kernel with <1, 1, 1> tiles.
通过 Nix
我们提供了一个 Nix flake 以便于设置和开发。如果尚未在你的 Nix 配置中启用 Flakes,请将其添加到 ~/.config/nix/nix.conf:
experimental-features = nix-command flakes
直接运行命令:
nix develop -c cargo run -p cutile-examples --example saxpy
或者打开一个交互式 shell:
nix develop # cutile-rs dev shell # ✓ CUDA /nix/store/...-cuda-toolkit-13.3 # ✓ Rust 1.90.0-nightly
该 flake 会自动定位 NixOS 和非 NixOS 系统上的主机 NVIDIA 驱动库。
测试
- cuTile IR:cargo test --package cutile-ir
- cuTile Rust 编译器:cargo test --package cutile-compiler
- cuTile Rust 库:cargo test --package cutile
- 示例:运行单个示例,例如 cargo run -p cutile-examples --example async_gemm
- 基准测试:cargo bench
- 全部运行:./scripts/run_all.sh(或输出到日志文件:./scripts/run_all.sh 2>&1 | tee test_run.log)
工作区 Crates
cutile User-facing crate for authoring and executing tile kernels
├── cutile-macro
├── cutile-compiler
├── cuda-async
└── cuda-core
cutile-kernels Reusable cuTile Rust kernels
└── cutile
cutile-macro cuTile Rust proc-macro
└── cutile-compiler
cutile-compiler Compiles cuTile Rust kernels to executables
├── cutile-ir
├── cuda-async
└── cuda-core
cutile-ir Pure Rust Tile IR builder and bytecode writer
cuda-async Async CUDA execution via async Rust
└── cuda-core
cuda-core Idiomatic safe CUDA API
└── cuda-bindings
cuda-bindings NVIDIA CUDA bindings
许可证
cuda-bindings crate 根据 NVIDIA 软件许可证(LICENSE-NVIDIA)授权。所有其他 crate 均根据 Apache 许可证 2.0 版(https://www.apache.org/licenses/LICENSE-2.0)授权。
关于
cuTile Rust 为 Rust 编程语言提供了一种安全的、基于 tile 的内核编程 DSL。它包含一个安全的主机端 API,用于将张量传递给异步执行的内核函数。
nvlabs.github.io/cutile-rs/
贡献者
编程语言
- Rust 92.9%
- Python 4.5%
- Shell 1.7%
- Cuda 0.3%
- CSS 0.3%
- Nix 0.1%
- 其他 0.2%