ringkernel-derive
Procedural macros for RingKernel.
Overview
This crate provides derive macros and attribute macros for defining RingKernel messages, handlers, and GPU kernels.
Macros
#[derive(RingMessage)]
Implements the RingMessage trait for message types:
use RingMessage;
Struct attributes:
#[message(type_id = N)]- Explicit message type ID (optional, auto-generated from name hash if omitted)
Field attributes:
#[message(id)]- Mark as message ID field#[message(correlation)]- Mark as correlation ID field#[message(priority)]- Mark as priority field
#[ring_kernel]
Defines a ring kernel handler with metadata:
use ring_kernel;
async
Attributes:
id(required) - Unique kernel identifiermode-"persistent"(default) or"event_driven"grid_size- Number of blocks (default: 1)block_size- Threads per block (default: 256)publishes_to- Comma-separated list of target kernel IDs
#[derive(GpuType)]
Marks a type as GPU-compatible for direct transfer:
use GpuType;
Generates compile-time assertions for Copy and implements bytemuck::Pod and bytemuck::Zeroable.
#[stencil_kernel]
Defines a stencil kernel that transpiles to CUDA (requires cuda-codegen feature):
use stencil_kernel;
// Access generated CUDA source:
assert!;
Attributes:
id(required) - Kernel identifiergrid-"1d","2d"(default), or"3d"tile_size- Square tile size (default: 16)tile_width/tile_height- Non-square tile dimensionshalo- Stencil radius (default: 1)
Generated Code
The macros generate:
- Trait implementations (
RingMessage) - Handler wrapper functions
- Kernel registration via
inventory - CUDA source constants (for
stencil_kernel)
Testing
The crate includes 14 tests covering all macro functionality.
License
Apache-2.0