transpile_stencil_kernel

Function transpile_stencil_kernel 

Source
pub fn transpile_stencil_kernel(
    func: &ItemFn,
    config: &StencilConfig,
) -> Result<String>
Expand description

Transpile a Rust stencil kernel function to WGSL code.

This is the main entry point for stencil code generation. It takes a parsed Rust function and stencil configuration, validates the DSL constraints, and generates equivalent WGSL code.

§Arguments

  • func - The parsed Rust function (from syn)
  • config - Stencil kernel configuration

§Returns

The generated WGSL source code as a string.

§Example

use ringkernel_wgpu_codegen::{transpile_stencil_kernel, StencilConfig};
use syn::parse_quote;

let func: syn::ItemFn = parse_quote! {
    fn heat(temp: &[f32], temp_new: &mut [f32], alpha: f32, pos: GridPos) {
        let t = temp[pos.idx()];
        let neighbors = pos.north(temp) + pos.south(temp) + pos.east(temp) + pos.west(temp);
        temp_new[pos.idx()] = t + alpha * (neighbors - 4.0 * t);
    }
};

let config = StencilConfig::new("heat").with_tile_size(16, 16).with_halo(1);
let wgsl = transpile_stencil_kernel(&func, &config)?;