Crate ringkernel_derive

Crate ringkernel_derive 

Source
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 (with cuda-codegen feature)

§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§

RingKernelArgs 🔒
Attributes for the ring_kernel macro.
RingMessageArgs 🔒
Attributes for the RingMessage derive macro.
RingMessageField 🔒
Field attributes for RingMessage.
StencilKernelArgs 🔒
Attributes for the stencil_kernel macro.

Functions§

stencil_kernel_impl 🔒

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.
RingMessage
Derive macro for implementing the RingMessage trait.