Rust Running on Every GPU
9 months ago
- #Cross-platform
- #Rust
- #GPU
- A demo showcases a single Rust codebase running on all major GPU platforms including CUDA, SPIR-V, Metal, DirectX 12, WebGPU, and CPU fallback.
- Traditional GPU programming uses specialized languages like WGSL, GLSL, MSL, HLSL, Slang, or Triton, increasing complexity.
- Rust projects like Rust GPU, Rust CUDA, and Naga enable compiling standard Rust code directly to GPU targets.
- The demo implements a bitonic sort with shared compute logic across all targets, written entirely in Rust.
- Backend selection is done via Rust feature flags and compilation targets, allowing dynamic GPU technology selection.
- Kernels are compiled to the appropriate device format and embedded into the binary at build time.
- Rust's no_std support is crucial for GPU programming, as the standard library isn't available on GPUs.
- Conditional compilation, newtypes, enums, traits, and generics are leveraged for type-safe and efficient GPU code.
- The project uses Rust's module system, workspaces, and standard tools like rustfmt and clippy for organization and quality.
- GPU kernel code can be tested on the CPU using standard Rust testing tools, improving development and debugging.
- Despite progress, the developer experience has rough edges, including compiler backend integration and debugging challenges.
- The Rust community is encouraged to contribute to improving the GPU programming experience in Rust.