Expand description
Runtime traits and types for kernel management.
This module defines the core runtime abstraction that backends implement to provide kernel lifecycle management, message passing, and monitoring.
§Overview
The runtime module provides the central abstractions for managing GPU kernels:
RingKernelRuntime- The main trait implemented by backends (CPU, CUDA, Metal, WebGPU)KernelHandle- A handle for interacting with launched kernelsLaunchOptions- Configuration options for kernel launchesKernelState- Lifecycle states (Created → Launched → Active → Terminated)
§Kernel Lifecycle
┌─────────┐ ┌──────────┐ ┌────────┐ ┌────────────┐
│ Created │ ──► │ Launched │ ──► │ Active │ ──► │ Terminated │
└─────────┘ └──────────┘ └────────┘ └────────────┘
│ ▲ │
│ │ ▼
│ ┌─────────────┐
└──────► │ Deactivated │
└─────────────┘§Example
ⓘ
use ringkernel_core::runtime::{RingKernelRuntime, LaunchOptions, KernelState};
use ringkernel_cpu::CpuRuntime;
#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
// Create a runtime
let runtime = CpuRuntime::new().await?;
// Launch a kernel with custom options
let options = LaunchOptions::single_block(256)
.with_queue_capacity(2048)
.with_k2k(true); // Enable kernel-to-kernel messaging
let kernel = runtime.launch("my_processor", options).await?;
// Kernel auto-activates by default
assert!(kernel.is_active());
// Send messages to the kernel
kernel.send(MyMessage { value: 42 }).await?;
// Receive responses
let response = kernel.receive_timeout(Duration::from_secs(1)).await?;
// Terminate when done
kernel.terminate().await?;
Ok(())
}§Backend Selection
Use Backend::Auto to automatically select the best available backend,
or specify a specific backend for testing/deployment:
ⓘ
use ringkernel_core::runtime::{RuntimeBuilder, Backend};
// Auto-select: CUDA → Metal → WebGPU → CPU
let builder = RuntimeBuilder::new().backend(Backend::Auto);
// Force CPU for testing
let builder = RuntimeBuilder::new().backend(Backend::Cpu);
// Use CUDA with specific device
let builder = RuntimeBuilder::new()
.backend(Backend::Cuda)
.device(1) // Second GPU
.profiling(true);Structs§
- Kernel
Handle - Handle to a launched kernel.
- Kernel
Id - Unique kernel identifier.
- Kernel
Status - Kernel status including state and metrics.
- Launch
Options - Options for launching a kernel.
- Runtime
Builder - Builder for creating a runtime instance.
- Runtime
Metrics - Runtime-level metrics.
Enums§
- Backend
- GPU backend type.
- Kernel
State - Kernel lifecycle state.
Traits§
- Kernel
Handle Inner - Inner trait for kernel handle implementation.
- Ring
Kernel Runtime - Backend-agnostic runtime trait for kernel management.
Type Aliases§
- BoxFuture
- Type-erased future for async operations.