ringkernel-wgpu-codegen
Rust-to-WGSL transpiler for RingKernel GPU kernels.
Overview
This crate provides transpilation from a restricted Rust DSL to WGSL (WebGPU Shading Language). It shares the same DSL as ringkernel-cuda-codegen, allowing the same kernel code to target both CUDA and WebGPU.
Installation
[]
= "0.1"
= { = "2.0", = ["full"] }
Global Kernels
use transpile_global_kernel;
use parse_quote;
let func: ItemFn = parse_quote! ;
let wgsl_code = transpile_global_kernel?;
Stencil Kernels
use ;
let func: ItemFn = parse_quote! ;
let config = new
.with_tile_size
.with_halo;
let wgsl_code = transpile_stencil_kernel?;
Ring Kernels
Ring kernels in WGPU are emulated using host-driven dispatch loops:
use ;
let handler: ItemFn = parse_quote! ;
let config = new
.with_workgroup_size
.with_hlc;
let wgsl_code = transpile_ring_kernel?;
WGSL Limitations
The transpiler handles these WebGPU limitations:
| CUDA Feature | WGSL Workaround |
|---|---|
| 64-bit atomics | Lo/hi u32 pairs with manual carry |
f64 |
Downcast to f32 (with warning) |
| Persistent kernels | Host-driven dispatch loop |
| Warp operations | Subgroup operations (where available) |
| K2K messaging | Not supported |
Type Mapping
| Rust Type | WGSL Type |
|---|---|
f32 |
f32 |
i32 |
i32 |
u32 |
u32 |
bool |
bool |
&[T] |
array<T> (storage, read) |
&mut [T] |
array<T> (storage, read_write) |
Testing
The crate includes 50 tests covering types, intrinsics, and transpilation.
License
Apache-2.0