Hey guys!
I've been building a GPU compute platform on pure stable-rust to let you write compute kernels directly in standard rust, Built entirely on Vulkan 1.3 (Compute) for the host api runtime & MLIR/LLVM for the backend JIT compiler.
It can make you write iters-enums-generics-etc.. in your function, and run it across GPU silicon, because the syntax is literally rust, It can execute on native CPU.
Here is a simple example:
```rust
use enki::*;
use glam::Vec2;
const COUNT: usize = 5;
// Declare the compute kernel with #[nam]
[nam]
fn scale_vectors(_space: &Space, input: &Vec2, output: &mut Vec2, factor: f32) {
*output = *input * factor;
}
fn main() {
// Initialize the headless GPU runtime
let enki = Enki::init();
// Allocate physical data directly in GPU VRAM
let in_gpu = gpu_vec![
Vec2::new(1.0, 2.0),
Vec2::new(3.0, 4.0),
Vec2::new(5.0, 6.0),
Vec2::new(7.0, 8.0),
Vec2::new(9.0, 10.0),
];
let mut out_gpu = gpu_vec![Vec2::ZERO; COUNT];
let factor = 2.5f32;
// Record and dispatch directly to GPU silicon
enki.flow(|_| {
scale_vectors.run(
&Space::gpu_x(COUNT),
&in_gpu,
&mut out_gpu,
GpuParam::new(factor),
);
});
// Dual Execution: Run the exact same function on CPU native rust
let in_cpu = vec![
Vec2::new(1.0, 2.0),
Vec2::new(3.0, 4.0),
Vec2::new(5.0, 6.0),
Vec2::new(7.0, 8.0),
Vec2::new(9.0, 10.0),
];
let mut out_cpu = vec![Vec2::ZERO; COUNT];
for i in 0..COUNT {
scale_vectors(&Space::cpu_x(i, COUNT), &in_cpu[i], &mut out_cpu[i], factor);
}
// Verify bit-for-bit equivalence
assert_eq!(&out_cpu[..], &out_gpu.to_vec()[..]);
println!("\nGPU Results: {:?}", out_gpu);
println!("\nCPU Results: {:?}", out_cpu);
println!("\nCPU and GPU outputs match.");
}
```
Result:
``text
enki_matmul on master [✘!+] is 📦 v0.1.0 via 🦀 v1.98.1
❯ cargo run
Compiling enki_matmul v0.1.0 (/home/mohiman/Projects/enki_demo_pack/enki_matmul)
Finisheddevprofile [optimized + debuginfo] target(s) in 1.86s
Runningtarget/debug/enki_matmul`
GPU Results: [Vec2(2.5, 5.0), Vec2(7.5, 10.0), Vec2(12.5, 15.0), Vec2(17.5, 20.0), Vec2(22.5, 25.0)]
CPU Results: [Vec2(2.5, 5.0), Vec2(7.5, 10.0), Vec2(12.5, 15.0), Vec2(17.5, 20.0), Vec2(22.5, 25.0)]
CPU and GPU outputs match.
enki_matmul on master [✘!+] is 📦 v0.1.0 via 🦀 v1.98.1 took 2s
❯
```
I've verified it on Linux (Docker Container Testing) & Windows (Wine) & colab T4, and my intel UHD laptop, every thing was great, i'd really love your help testing across more diverse hardware (AMD, Nvidia, Intel)
You can test SDF showcase in 3 commands:
bash
git clone https://github.com/enkiruntime/enki_sdf.git
cd enki_sdf
cargo run --release
(pressing space will toggle execution from GPU (Enki) to CPU (rust-rayon))
Enki is currently in Public Alpha (v0.2.x) release, I would really appreciate any feedback, architectural thoughts, or bug reports.