Expand description
CUDA code generation from Rust DSL for RingKernel stencil kernels.
This crate provides transpilation from a restricted Rust DSL to CUDA C code, enabling developers to write GPU kernels in Rust without directly writing CUDA.
§Overview
The transpiler supports a subset of Rust focused on stencil/grid operations:
- Primitive types:
f32,f64,i32,u32,i64,u64,bool - Array slices:
&[T],&mut [T] - Arithmetic and comparison operators
- Let bindings and if/else expressions
- Stencil intrinsics via
GridPoscontext
§Example
ⓘ
use ringkernel_cuda_codegen::{transpile_stencil_kernel, StencilConfig};
let rust_code = r#"
fn fdtd(p: &[f32], p_prev: &mut [f32], c2: f32, pos: GridPos) {
let curr = p[pos.idx()];
let lap = pos.north(p) + pos.south(p) + pos.east(p) + pos.west(p) - 4.0 * curr;
p_prev[pos.idx()] = 2.0 * curr - p_prev[pos.idx()] + c2 * lap;
}
"#;
let config = StencilConfig {
id: "fdtd".to_string(),
grid: Grid::Grid2D,
tile_size: (16, 16),
halo: 1,
};
let cuda_code = transpile_stencil_kernel(rust_code, &config)?;Re-exports§
pub use handler::generate_cuda_struct;pub use handler::generate_message_deser;pub use handler::generate_response_ser;pub use handler::ContextMethod;pub use handler::HandlerCodegenConfig;pub use handler::HandlerParam;pub use handler::HandlerParamKind;pub use handler::HandlerReturnType;pub use handler::HandlerSignature;pub use handler::MessageTypeInfo;pub use handler::MessageTypeRegistry;pub use loops::LoopPattern;pub use loops::RangeInfo;pub use persistent_fdtd::generate_persistent_fdtd_kernel;pub use persistent_fdtd::PersistentFdtdConfig;pub use reduction_intrinsics::generate_inline_block_reduce;pub use reduction_intrinsics::generate_inline_grid_reduce;pub use reduction_intrinsics::generate_inline_reduce_and_broadcast;pub use reduction_intrinsics::generate_reduction_helpers;pub use reduction_intrinsics::transpile_reduction_call;pub use reduction_intrinsics::ReductionCodegenConfig;pub use reduction_intrinsics::ReductionIntrinsic;pub use reduction_intrinsics::ReductionOp as CodegenReductionOp;pub use ring_kernel::generate_control_block_struct;pub use ring_kernel::generate_hlc_struct;pub use ring_kernel::generate_k2k_structs;pub use ring_kernel::KernelReductionConfig;pub use ring_kernel::RingKernelConfig;
Modules§
- dsl
- Rust DSL functions for writing CUDA kernels.
- handler
- Handler function integration for ring kernel transpilation.
- loops
- Loop transpilation helpers for CUDA code generation.
- persistent_
fdtd - Persistent FDTD kernel code generation.
- reduction_
intrinsics - Reduction Intrinsics for CUDA Code Generation
- ring_
kernel - Ring kernel configuration and code generation for persistent actor kernels.
- shared
- Shared memory support for CUDA code generation.
Structs§
- Cuda
Transpiler - CUDA code transpiler.
- GridPos
- Context for grid position within a stencil kernel.
- Intrinsic
Registry - Registry for mapping Rust function names to GPU intrinsics.
- Shared
VarInfo - Information about a shared memory variable.
- Stencil
Config - Configuration for a stencil kernel.
- Stencil
Launch Config - Launch configuration for stencil kernels.
- Type
Mapper - Type mapper for Rust to CUDA conversions.
Enums§
- Cuda
Type - CUDA type representation.
- GpuIntrinsic
- GPU intrinsic operations.
- Grid
- Grid dimensionality for stencil kernels.
- Ring
Kernel Intrinsic - Ring kernel intrinsics for persistent actor kernels.
- Ring
Kernel Param Kind - Known ring kernel parameter types.
- Stencil
Intrinsic - Stencil-specific intrinsics for neighbor access.
- Transpile
Error - Errors that can occur during transpilation.
- Validation
Error - Validation errors for DSL constraint violations.
- Validation
Mode - Validation mode for different kernel types.
Functions§
- get_
slice_ element_ type - Extract the inner element type from a slice reference.
- is_
control_ block_ type - Check if a type is the ControlBlock type.
- is_
mutable_ reference - Check if a type is a mutable reference.
- is_
ring_ context_ type - Check if a type is the RingContext type.
- is_
simple_ assignment - Check if a statement might need special handling.
- ring_
kernel_ type_ mapper - Create a TypeMapper with ring kernel types pre-registered.
- transpile_
device_ function - Transpile a Rust function to a CUDA
__device__function. - transpile_
function - Transpile a function to CUDA without stencil configuration.
- transpile_
global_ kernel - Transpile a Rust function to a CUDA
__global__kernel. - transpile_
ring_ kernel - Transpile a Rust handler function to a persistent ring kernel.
- transpile_
stencil_ kernel - Transpile a Rust stencil kernel function to CUDA C code.
- validate_
function - Validate that a function conforms to the stencil kernel DSL.
- validate_
function_ with_ mode - Validate a function with a specific validation mode.
- validate_
stencil_ signature - Validate function signature for stencil kernels.
Type Aliases§
- Result
- Result type for transpilation operations.