Expand description
Procedural macros for RingKernel.
This crate provides the following macros:
#[derive(RingMessage)]- Implement the RingMessage trait for message types#[ring_kernel]- Define a ring kernel handler#[stencil_kernel]- Define a GPU stencil kernel (withcuda-codegenfeature)
§Example
ⓘ
use ringkernel_derive::{RingMessage, ring_kernel};
#[derive(RingMessage)]
struct AddRequest {
#[message(id)]
id: MessageId,
a: f32,
b: f32,
}
#[derive(RingMessage)]
struct AddResponse {
#[message(id)]
id: MessageId,
result: f32,
}
#[ring_kernel(id = "adder")]
async fn process(ctx: &mut RingContext, req: AddRequest) -> AddResponse {
AddResponse {
id: MessageId::generate(),
result: req.a + req.b,
}
}§Stencil Kernels (with cuda-codegen feature)
ⓘ
use ringkernel_derive::stencil_kernel;
use ringkernel_cuda_codegen::GridPos;
#[stencil_kernel(id = "fdtd", grid = "2d", tile_size = 16, halo = 1)]
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;
}Structs§
- Ring
Kernel 🔒Args - Attributes for the ring_kernel macro.
- Ring
Message 🔒Args - Attributes for the RingMessage derive macro.
- Ring
Message 🔒Field - Field attributes for RingMessage.
- Stencil
Kernel 🔒Args - Attributes for the stencil_kernel macro.
Functions§
Attribute Macros§
- ring_
kernel - Attribute macro for defining ring kernel handlers.
- stencil_
kernel - Attribute macro for defining stencil kernels that transpile to CUDA.
Derive Macros§
- GpuType
- Derive macro for GPU-compatible types.
- Ring
Message - Derive macro for implementing the RingMessage trait.