Skip to main content

Crate hydroplane_macros

Crate hydroplane_macros 

Source
Expand description

The #[kernel] attribute — write a hydroplane kernel as a plain generic function.

From a function whose first parameter is the SIMD context, #[kernel] generates the kernel struct and Kernel impl (MatrixKernel with #[kernel(matrix)], adding the .tiles() surface), a callable wrapper that runs dispatch for you, and a <name>_on(ctx, …) companion that runs the body on a caller-supplied context — call it from another kernel to skip dispatch.

ⓘ
#[hydroplane::kernel]
fn any_overlap<'a, T: Scalar>(ctx: Gang, soa: &'a Soa<T>, q: [T; 4]) -> bool { /* body */ }
let hit = any_overlap(&soa, q);   // call site — no struct, no impl, no `dispatch`

The context is written bare (ctx: Gang) or concrete (ctx: Gang<f32>); every later parameter becomes a struct field carried across the dispatch boundary, so borrows need explicit lifetimes. The dispatch element is the generic bound by Scalar/FloatScalar/IntScalar (or the one named T), inferred for concrete kernels; attribute overrides: scalar = U, extra element names (OR’d into the dispatch type-combo), and unroll = N, which caps the ILP unroll factor for this kernel. tiny and noalias are still accepted but no longer change the generated code: the body always runs in an inlined _on.

Inside the body, a * b + c and c + a * b on varyings compile to a fused multiply-add, as .fma would; on anything else they stay the two operators.

Attribute Macros§

kernel
Generate a Kernel (or, with #[kernel(matrix)], a MatrixKernel) and a dispatching wrapper from one annotated function. See the crate docs for the full shape.