pub struct RingContext<'a> {
pub thread_id: ThreadId,
pub block_id: BlockId,
pub block_dim: Dim3,
pub grid_dim: Dim3,
/* private fields */
}Expand description
GPU intrinsics facade for kernel handlers.
This struct provides access to GPU-specific operations like thread identification, synchronization, and atomic operations. The actual implementation varies by backend.
§Lifetime
The context is borrowed for the duration of the kernel handler execution.
Fields§
§thread_id: ThreadIdThread identity within block.
block_id: BlockIdBlock identity within grid.
block_dim: Dim3Block dimensions.
grid_dim: Dim3Grid dimensions.
Implementations§
Source§impl<'a> RingContext<'a>
impl<'a> RingContext<'a>
Sourcepub fn new(
thread_id: ThreadId,
block_id: BlockId,
block_dim: Dim3,
grid_dim: Dim3,
clock: &'a HlcClock,
kernel_id: u64,
backend: ContextBackend,
) -> RingContext<'a>
pub fn new( thread_id: ThreadId, block_id: BlockId, block_dim: Dim3, grid_dim: Dim3, clock: &'a HlcClock, kernel_id: u64, backend: ContextBackend, ) -> RingContext<'a>
Create a new context with basic configuration.
For domain-aware contexts, use new_with_options instead.
Sourcepub fn new_with_options(
thread_id: ThreadId,
block_id: BlockId,
block_dim: Dim3,
grid_dim: Dim3,
clock: &'a HlcClock,
kernel_id: u64,
backend: ContextBackend,
domain: Option<Domain>,
metrics_capacity: usize,
alert_sender: Option<UnboundedSender<KernelAlert>>,
) -> RingContext<'a>
pub fn new_with_options( thread_id: ThreadId, block_id: BlockId, block_dim: Dim3, grid_dim: Dim3, clock: &'a HlcClock, kernel_id: u64, backend: ContextBackend, domain: Option<Domain>, metrics_capacity: usize, alert_sender: Option<UnboundedSender<KernelAlert>>, ) -> RingContext<'a>
Create a new context with full configuration (FR-2).
§Arguments
thread_id- Thread identity within blockblock_id- Block identity within gridblock_dim- Block dimensionsgrid_dim- Grid dimensionsclock- HLC clock instancekernel_id- Unique kernel identifierbackend- Backend implementationdomain- Optional domain for this kernelmetrics_capacity- Metrics buffer capacityalert_sender- Optional channel for emitting alerts
Sourcepub fn global_thread_id(&self) -> GlobalThreadId
pub fn global_thread_id(&self) -> GlobalThreadId
Get global thread ID across all blocks.
Sourcepub fn sync_threads(&self)
pub fn sync_threads(&self)
Synchronize all threads in the block.
All threads in the block must reach this barrier before any thread can proceed past it.
Sourcepub fn sync_grid(&self)
pub fn sync_grid(&self)
Synchronize all threads in the grid (cooperative groups).
Requires cooperative kernel launch support.
Sourcepub fn thread_fence(&self, scope: FenceScope)
pub fn thread_fence(&self, scope: FenceScope)
Memory fence at the specified scope.
Sourcepub fn fence_thread(&self)
pub fn fence_thread(&self)
Thread-scope fence (compiler barrier).
Sourcepub fn fence_block(&self)
pub fn fence_block(&self)
Block-scope fence.
Sourcepub fn fence_device(&self)
pub fn fence_device(&self)
Device-scope fence.
Sourcepub fn fence_system(&self)
pub fn fence_system(&self)
System-scope fence (CPU+GPU visible).
Sourcepub fn now(&self) -> HlcTimestamp
pub fn now(&self) -> HlcTimestamp
Get current HLC timestamp.
Sourcepub fn tick(&self) -> HlcTimestamp
pub fn tick(&self) -> HlcTimestamp
Generate a new HLC timestamp (advances clock).
Sourcepub fn update_clock(
&self,
received: &HlcTimestamp,
) -> Result<HlcTimestamp, RingKernelError>
pub fn update_clock( &self, received: &HlcTimestamp, ) -> Result<HlcTimestamp, RingKernelError>
Update clock with received timestamp.
Sourcepub fn atomic_add(&self, ptr: &AtomicU64, val: u64, order: MemoryOrder) -> u64
pub fn atomic_add(&self, ptr: &AtomicU64, val: u64, order: MemoryOrder) -> u64
Atomic add and return old value.
Sourcepub fn atomic_cas(
&self,
ptr: &AtomicU64,
expected: u64,
desired: u64,
success: MemoryOrder,
failure: MemoryOrder,
) -> Result<u64, u64>
pub fn atomic_cas( &self, ptr: &AtomicU64, expected: u64, desired: u64, success: MemoryOrder, failure: MemoryOrder, ) -> Result<u64, u64>
Atomic compare-and-swap.
Sourcepub fn atomic_exchange(
&self,
ptr: &AtomicU64,
val: u64,
order: MemoryOrder,
) -> u64
pub fn atomic_exchange( &self, ptr: &AtomicU64, val: u64, order: MemoryOrder, ) -> u64
Atomic exchange.
Sourcepub fn warp_shuffle<T>(&self, value: T, src_lane: u32) -> Twhere
T: Copy,
pub fn warp_shuffle<T>(&self, value: T, src_lane: u32) -> Twhere
T: Copy,
Warp shuffle - get value from another lane.
Returns the value from the specified source lane.
Sourcepub fn warp_shuffle_down<T>(&self, value: T, delta: u32) -> Twhere
T: Copy,
pub fn warp_shuffle_down<T>(&self, value: T, delta: u32) -> Twhere
T: Copy,
Warp shuffle down - get value from lane + delta.
Sourcepub fn warp_shuffle_up<T>(&self, value: T, delta: u32) -> Twhere
T: Copy,
pub fn warp_shuffle_up<T>(&self, value: T, delta: u32) -> Twhere
T: Copy,
Warp shuffle up - get value from lane - delta.
Sourcepub fn warp_shuffle_xor<T>(&self, value: T, mask: u32) -> Twhere
T: Copy,
pub fn warp_shuffle_xor<T>(&self, value: T, mask: u32) -> Twhere
T: Copy,
Warp shuffle XOR - get value from lane XOR mask.
Sourcepub fn warp_ballot(&self, predicate: bool) -> u32
pub fn warp_ballot(&self, predicate: bool) -> u32
Warp ballot - get bitmask of lanes where predicate is true.
Sourcepub fn warp_all(&self, predicate: bool) -> bool
pub fn warp_all(&self, predicate: bool) -> bool
Warp all - check if predicate is true for all lanes.
Sourcepub fn warp_any(&self, predicate: bool) -> bool
pub fn warp_any(&self, predicate: bool) -> bool
Warp any - check if predicate is true for any lane.
Sourcepub fn k2k_send(
&self,
_target_kernel: u64,
_envelope: &MessageEnvelope,
) -> Result<(), RingKernelError>
pub fn k2k_send( &self, _target_kernel: u64, _envelope: &MessageEnvelope, ) -> Result<(), RingKernelError>
Send message to another kernel (K2K).
This is a placeholder; actual implementation requires runtime support.
Sourcepub fn k2k_try_recv(&self) -> Result<MessageEnvelope, RingKernelError>
pub fn k2k_try_recv(&self) -> Result<MessageEnvelope, RingKernelError>
Try to receive message from K2K queue.
Sourcepub fn domain(&self) -> Option<&Domain>
pub fn domain(&self) -> Option<&Domain>
Get the domain this kernel operates in.
Returns None if no domain was configured.
Sourcepub fn set_domain(&mut self, domain: Domain)
pub fn set_domain(&mut self, domain: Domain)
Set the domain for this kernel context.
This allows runtime domain assignment for kernels that process messages from multiple domains.
Sourcepub fn clear_domain(&mut self)
pub fn clear_domain(&mut self)
Clear the domain setting.
Sourcepub fn record_latency(&mut self, operation: &str, latency_us: u64)
pub fn record_latency(&mut self, operation: &str, latency_us: u64)
Sourcepub fn record_throughput(&mut self, operation: &str, count: u64)
pub fn record_throughput(&mut self, operation: &str, count: u64)
Record a throughput metric (count per time period).
§Arguments
operation- Name of the operation (e.g., “messages_processed”)count- Number of items processed
Sourcepub fn record_counter(&mut self, operation: &str, increment: u64)
pub fn record_counter(&mut self, operation: &str, increment: u64)
Record a counter increment.
Counters are monotonically increasing values (e.g., total orders received).
Sourcepub fn record_gauge(&mut self, operation: &str, value: u64)
pub fn record_gauge(&mut self, operation: &str, value: u64)
Record a gauge value (absolute measurement).
Gauges represent point-in-time values that can go up or down (e.g., queue depth, memory usage).
Sourcepub fn flush_metrics(&mut self) -> Vec<MetricsEntry>
pub fn flush_metrics(&mut self) -> Vec<MetricsEntry>
Flush and return all buffered metrics.
After calling this method, the metrics buffer will be empty. This is typically called by the runtime when transferring metrics to the host telemetry pipeline.
Sourcepub fn metrics_count(&self) -> usize
pub fn metrics_count(&self) -> usize
Get the number of buffered metrics entries.
Sourcepub fn metrics_buffer_full(&self) -> bool
pub fn metrics_buffer_full(&self) -> bool
Check if the metrics buffer is full.
Sourcepub fn emit_alert(&self, alert: impl Into<KernelAlert>)
pub fn emit_alert(&self, alert: impl Into<KernelAlert>)
Emit an alert from this kernel.
Alerts are sent to the configured alert channel (if any). The alert is enriched with kernel ID, domain, and timestamp.
§Arguments
alert- The alert to emit (can be created viaKernelAlert::new()helpers)
§Example
ctx.emit_alert(KernelAlert::high_latency("Slow processing", 500));
ctx.emit_alert(KernelAlert::error("Processing failed"));Sourcepub fn has_alert_channel(&self) -> bool
pub fn has_alert_channel(&self) -> bool
Check if alert sending is configured.
Sourcepub fn alert_if_slow(&self, operation: &str, latency_us: u64, threshold_us: u64)
pub fn alert_if_slow(&self, operation: &str, latency_us: u64, threshold_us: u64)
Emit a high-latency alert if latency exceeds threshold.
Convenience method that only emits an alert when latency exceeds the specified threshold.
§Arguments
operation- Name of the operationlatency_us- Actual latency in microsecondsthreshold_us- Threshold above which to emit alert
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for RingContext<'a>
impl<'a> RefUnwindSafe for RingContext<'a>
impl<'a> Send for RingContext<'a>
impl<'a> Sync for RingContext<'a>
impl<'a> Unpin for RingContext<'a>
impl<'a> UnwindSafe for RingContext<'a>
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more