Expand description
RingKernel Intermediate Representation (IR)
This crate provides a unified IR for GPU code generation across multiple backends (CUDA, WGSL, MSL). The IR is SSA-based and captures GPU-specific operations.
§Architecture
Rust DSL → IR → Backend-specific lowering → CUDA/WGSL/MSL§Example
ⓘ
use ringkernel_ir::{IrBuilder, IrType, Dimension};
let mut builder = IrBuilder::new("saxpy");
// Define parameters
let x = builder.parameter("x", IrType::Ptr(Box::new(IrType::F32)));
let y = builder.parameter("y", IrType::Ptr(Box::new(IrType::F32)));
let a = builder.parameter("a", IrType::F32);
let n = builder.parameter("n", IrType::I32);
// Get thread index
let idx = builder.thread_id(Dimension::X);
// Bounds check
let in_bounds = builder.lt(idx, n);
builder.if_then(in_bounds, |b| {
let x_val = b.load(x, idx);
let y_val = b.load(y, idx);
let result = b.add(b.mul(a, x_val), y_val);
b.store(y, idx, result);
});
let ir = builder.build();Re-exports§
pub use lower_cuda::lower_to_cuda;pub use lower_cuda::lower_to_cuda_with_config;pub use lower_cuda::CudaLowering;pub use lower_cuda::CudaLoweringConfig;pub use lower_cuda::LoweringError;pub use lower_msl::lower_to_msl;pub use lower_msl::lower_to_msl_with_config;pub use lower_msl::MslLowering;pub use lower_msl::MslLoweringConfig;pub use lower_msl::MslLoweringError;pub use lower_wgsl::lower_to_wgsl;pub use lower_wgsl::lower_to_wgsl_with_config;pub use lower_wgsl::WgslLowering;pub use lower_wgsl::WgslLoweringConfig;pub use lower_wgsl::WgslLoweringError;pub use optimize::optimize;pub use optimize::run_constant_folding;pub use optimize::run_dce;pub use optimize::AlgebraicSimplification;pub use optimize::ConstantFolding;pub use optimize::DeadBlockElimination;pub use optimize::DeadCodeElimination;pub use optimize::OptimizationPass;pub use optimize::OptimizationResult;pub use optimize::PassManager;
Modules§
- lower_
cuda - IR to CUDA lowering pass.
- lower_
msl - IR to MSL (Metal Shading Language) lowering pass.
- lower_
wgsl - IR to WGSL lowering pass.
- optimize
- Optimization passes for the IR.
Structs§
- Backend
Capabilities - Backend-specific capabilities.
- Block
- A basic block containing IR nodes.
- BlockId
- Unique identifier for IR blocks.
- Capabilities
- Set of capabilities required or available.
- Instruction
- An IR instruction that produces a value.
- IrBuilder
- Builder for constructing IR modules.
- IrBuilder
Scope - Scoped builder for structured control flow.
- IrModule
- A complete IR module representing a GPU kernel.
- IrPrinter
- IR pretty printer.
- Kernel
Config - Kernel configuration.
- Parameter
- A function parameter.
- Validation
Result - Result of validation.
- Validator
- IR validator.
- Value
- An IR value with type information.
- ValueId
- Unique identifier for IR values.
- Vector
Type - Vector types.
Enums§
- Atomic
Op - Atomic operations.
- Binary
Op - Binary operations.
- Capability
Flag - Capability flags for GPU features.
- Cast
Kind - Cast kinds.
- Compare
Op - Comparison operations.
- Constant
Value - Constant values.
- Dimension
- Dimension for GPU indexing.
- IrError
- IR errors.
- IrNode
- IR node representing an operation.
- IrType
- IR type.
- Kernel
Mode - Kernel execution mode.
- MathOp
- Math operations (intrinsics).
- Memory
Scope - Memory scope for fences.
- Scalar
Type - Scalar types supported in IR.
- Terminator
- Block terminator instructions.
- UnaryOp
- Unary operations.
- Validation
Level - Validation strictness level.
- Warp
Reduce Op - Warp reduce operations.
- Warp
Shuffle Op - Warp shuffle operations.
- Warp
Vote Op - Warp vote operations.
Type Aliases§
- IrResult
- IR result type.