transpile_global_kernel

Function transpile_global_kernel 

Source
pub fn transpile_global_kernel(func: &ItemFn) -> Result<String>
Expand description

Transpile a Rust function to a WGSL @compute kernel.

This generates an compute shader entry point without stencil-specific patterns. Use DSL functions like thread_idx_x(), block_idx_x() to access WGSL indices.

§Example

use ringkernel_wgpu_codegen::transpile_global_kernel;
use syn::parse_quote;

let func: syn::ItemFn = parse_quote! {
    fn saxpy(x: &[f32], y: &mut [f32], a: f32, n: i32) {
        let idx = block_idx_x() * block_dim_x() + thread_idx_x();
        if idx >= n { return; }
        y[idx as usize] = a * x[idx as usize] + y[idx as usize];
    }
};

let wgsl = transpile_global_kernel(&func)?;
// Generates: @compute @workgroup_size(256) fn saxpy(...) { ... }