Demo project showing a single Rust codebase running on CPU and directly on GPUs
Rust GPU Chimera Demo
A cross-platform demo of a single Rust codebase running on both the CPU and GPU via CUDA, Vulkan, Metal, and DirectX. There are no shader or kernel languages used, only Rust.
Supported Configurations
| Platform | Rust Features | Host | Backend | Driver | How it Works | Status | | ------------ | ------------- | ------ | ------- | ------------- | -------------------- | ------------------ | | Linux | - | CPU | - | - | Rust โ Native | โ
Working | | Linux | wgpu | [wgpu] | Vulkan | Native | Rust โ SPIR-V | โ
Working | | Linux | ash | [ash] | Vulkan | Native | Rust โ SPIR-V | โ
Working | | Linux | cuda | [cust] | CUDA | Native | Rust โ NVVM โ PTX | โ
Working | | macOS | - | CPU | - | - | Rust โ Native | โ
Working | | macOS | wgpu | [wgpu] | Metal | Metal | Rust โ SPIR-V โ MSL | โ
Working | | macOS | wgpu,vulkan | [wgpu] | Vulkan | [MoltenVK] | Rust โ SPIR-V | โ
Working | | macOS | wgpu,vulkan | [wgpu] | Vulkan | [SwiftShader] | Rust โ SPIR-V | โ
Working | | macOS | ash | [ash] | Vulkan | [MoltenVK] | Rust โ SPIR-V | โ
Working | | macOS | ash | [ash] | Vulkan | [SwiftShader] | Rust โ SPIR-V | โ
Working | | macOS | cuda | [cust] | CUDA | - | - | โ Unavailable[^1] | | Windows | - | CPU | - | - | Rust โ Native | โ
Working | | Windows | wgpu | [wgpu] | DX12 | Native | Rust โ SPIR-V โ HLSL | โ
Working | | Windows | wgpu,vulkan | [wgpu] | Vulkan | Native | Rust โ SPIR-V | โ
Working | | Windows | wgpu,vulkan | [wgpu] | Vulkan | [SwiftShader] | Rust โ SPIR-V | โ
Working | | Windows | ash | [ash] | Vulkan | Native | Rust โ SPIR-V | โ
Working | | Windows | ash | [ash] | Vulkan | [SwiftShader] | Rust โ SPIR-V | โ
Working | | Windows | cuda | [cust] | CUDA | Native | Rust โ NVVM โ PTX | โ
Working | | Android | - | CPU | - | - | Rust โ Native | โ
Working | | Android | wgpu | [wgpu] | Vulkan | Native | Rust โ SPIR-V | โ
Working | | Android | ash | [ash] | Vulkan | Native | Rust โ SPIR-V | โ
Working | | Android | cuda | [cust] | CUDA | - | - | โ Unavailable[^2] | | iOS | - | CPU | - | - | Rust โ Native | โ
Working | | iOS | wgpu | [wgpu] | Metal | Metal | Rust โ SPIR-V โ MSL | ๐ท Should work | | iOS | wgpu,vulkan | [wgpu] | Vulkan | [MoltenVK] | Rust โ SPIR-V | ๐ท Should work | | iOS | ash | [ash] | Vulkan | [MoltenVK] | Rust โ SPIR-V | ๐ท Should work | | iOS | cuda | [cust] | CUDA | - | - | โ Unavailable[^1] | | tvOS | - | CPU | - | - | Rust โ Native | โ
Working | | tvOS | wgpu | [wgpu] | Metal | Metal | Rust โ SPIR-V โ MSL | ๐ท Should work | | tvOS | wgpu,vulkan | [wgpu] | Vulkan | [MoltenVK] | Rust โ SPIR-V | ๐ท Should work | | tvOS | ash | [ash] | Vulkan | [MoltenVK] | Rust โ SPIR-V | ๐ท Should work | | tvOS | cuda | [cust] | CUDA | - | - | โ Unavailable[^1] | | visionOS | - | CPU | - | - | Rust โ Native | โ
Working | | visionOS | wgpu | [wgpu] | Metal | Metal | Rust โ SPIR-V โ MSL | ๐ท Should work | | visionOS | wgpu,vulkan | [wgpu] | Vulkan | [MoltenVK] | Rust โ SPIR-V | ๐ท Should work | | visionOS | ash | [ash] | Vulkan | [MoltenVK] | Rust โ SPIR-V | ๐ท Should work | | visionOS | cuda | [cust] | CUDA | - | - | โ Unavailable[^1] |
[^1]: CUDA is not supported on macOS/iOS/tvOS/visionOS. ZLUDA could potentially enable CUDA on these platforms in the future.
[^2]: CUDA is not supported on Android. ZLUDA could potentially enable CUDA on Android in the future.
Running the Demo
The demo runs a bitonic sort on various data types (u32, i32, f32) with different sizes and configurations.
Linux
# CPU execution
cargo run --release
Vulkan via wgpu
cargo run --release --features wgpu
Vulkan via ash
cargo run --release --features ash
CUDA (NVIDIA GPU required)
cargo run --release --features cuda
macOS
# CPU execution
cargo run --release
Metal via wgpu (SPIR-V โ MSL translation)
cargo run --release --features wgpu
Vulkan via wgpu (requires MoltenVK)
cargo run --release --features wgpu,vulkan
Vulkan via ash (requires MoltenVK)
cargo run --release --features ash
Windows
# CPU execution
cargo run --release
DirectX 12 via wgpu (SPIR-V โ HLSL translation)
cargo run --release --features wgpu
Vulkan via wgpu
cargo run --release --features wgpu,vulkan
Vulkan via ash
cargo run --release --features ash
CUDA (NVIDIA GPU required)
cargo run --release --features cuda
Instead of cargo run you can replace it with cargo test to run unit tests for the same configuration.
Project Structure
rust-gpu-chimera-demo/
โโโ kernel/ # Compute kernel logic and entrypoints
โ โโโ src/
โ โโโ lib.rs
โโโ shared/ # Code that runs on both the CPU and GPU
โ โโโ src/
โ โโโ lib.rs
โโโ src/
โ โโโ runners/ # Code that runs on the CPU/host and interfaces with the GPU
โ โ โโโ cpu.rs
โ โ โโโ cuda.rs
โ โ โโโ wgpu.rs
โ โ โโโ ash.rs
โ โโโ lib.rs
โ โโโ main.rs # Demo application binary
โโโ build.rs # Kernel compilation orchestration
[wgpu]: https://github.com/gfx-rs/wgpu [ash]: https://github.com/ash-rs/ash [cust]: https://github.com/Rust-GPU/Rust-CUDA/tree/main/crates/cust [MoltenVK]: https://github.com/KhronosGroup/MoltenVK [SwiftShader]: https://github.com/google/swiftshader