RingContext

Struct RingContext 

Source
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: ThreadId

Thread identity within block.

§block_id: BlockId

Block identity within grid.

§block_dim: Dim3

Block dimensions.

§grid_dim: Dim3

Grid dimensions.

Implementations§

Source§

impl<'a> RingContext<'a>

Source

pub fn new( thread_id: ThreadId, block_id: BlockId, block_dim: Dim3, grid_dim: Dim3, clock: &'a HlcClock, kernel_id: u64, backend: ContextBackend, ) -> Self

Create a new context with basic configuration.

For domain-aware contexts, use new_with_options instead.

Source

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>>, ) -> Self

Create a new context with full configuration (FR-2).

§Arguments
  • thread_id - Thread identity within block
  • block_id - Block identity within grid
  • block_dim - Block dimensions
  • grid_dim - Grid dimensions
  • clock - HLC clock instance
  • kernel_id - Unique kernel identifier
  • backend - Backend implementation
  • domain - Optional domain for this kernel
  • metrics_capacity - Metrics buffer capacity
  • alert_sender - Optional channel for emitting alerts
Source

pub fn thread_id(&self) -> ThreadId

Get thread ID within block.

Source

pub fn block_id(&self) -> BlockId

Get block ID within grid.

Source

pub fn global_thread_id(&self) -> GlobalThreadId

Get global thread ID across all blocks.

Source

pub fn warp_id(&self) -> WarpId

Get warp ID within block.

Source

pub fn lane_id(&self) -> u32

Get lane ID within warp (0-31).

Source

pub fn block_dim(&self) -> Dim3

Get block dimensions.

Source

pub fn grid_dim(&self) -> Dim3

Get grid dimensions.

Source

pub fn kernel_id(&self) -> u64

Get kernel ID.

Source

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.

Source

pub fn sync_grid(&self)

Synchronize all threads in the grid (cooperative groups).

Requires cooperative kernel launch support.

Source

pub fn sync_warp(&self)

Synchronize threads within a warp.

Source

pub fn thread_fence(&self, scope: FenceScope)

Memory fence at the specified scope.

Source

pub fn fence_thread(&self)

Thread-scope fence (compiler barrier).

Source

pub fn fence_block(&self)

Block-scope fence.

Source

pub fn fence_device(&self)

Device-scope fence.

Source

pub fn fence_system(&self)

System-scope fence (CPU+GPU visible).

Source

pub fn now(&self) -> HlcTimestamp

Get current HLC timestamp.

Source

pub fn tick(&self) -> HlcTimestamp

Generate a new HLC timestamp (advances clock).

Source

pub fn update_clock(&self, received: &HlcTimestamp) -> Result<HlcTimestamp>

Update clock with received timestamp.

Source

pub fn atomic_add(&self, ptr: &AtomicU64, val: u64, order: MemoryOrder) -> u64

Atomic add and return old value.

Source

pub fn atomic_cas( &self, ptr: &AtomicU64, expected: u64, desired: u64, success: MemoryOrder, failure: MemoryOrder, ) -> Result<u64, u64>

Atomic compare-and-swap.

Source

pub fn atomic_exchange( &self, ptr: &AtomicU64, val: u64, order: MemoryOrder, ) -> u64

Atomic exchange.

Source

pub fn warp_shuffle<T: Copy>(&self, value: T, src_lane: u32) -> T

Warp shuffle - get value from another lane.

Returns the value from the specified source lane.

Source

pub fn warp_shuffle_down<T: Copy>(&self, value: T, delta: u32) -> T

Warp shuffle down - get value from lane + delta.

Source

pub fn warp_shuffle_up<T: Copy>(&self, value: T, delta: u32) -> T

Warp shuffle up - get value from lane - delta.

Source

pub fn warp_shuffle_xor<T: Copy>(&self, value: T, mask: u32) -> T

Warp shuffle XOR - get value from lane XOR mask.

Source

pub fn warp_ballot(&self, predicate: bool) -> u32

Warp ballot - get bitmask of lanes where predicate is true.

Source

pub fn warp_all(&self, predicate: bool) -> bool

Warp all - check if predicate is true for all lanes.

Source

pub fn warp_any(&self, predicate: bool) -> bool

Warp any - check if predicate is true for any lane.

Source

pub fn k2k_send( &self, _target_kernel: u64, _envelope: &MessageEnvelope, ) -> Result<()>

Send message to another kernel (K2K).

This is a placeholder; actual implementation requires runtime support.

Source

pub fn k2k_try_recv(&self) -> Result<MessageEnvelope>

Try to receive message from K2K queue.

Source

pub fn domain(&self) -> Option<&Domain>

Get the domain this kernel operates in.

Returns None if no domain was configured.

Source

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.

Source

pub fn clear_domain(&mut self)

Clear the domain setting.

Source

pub fn record_latency(&mut self, operation: &str, latency_us: u64)

Record a latency metric in microseconds.

§Arguments
  • operation - Name of the operation (e.g., “process_order”)
  • latency_us - Latency in microseconds
§Example
let start = std::time::Instant::now();
// ... process message ...
ctx.record_latency("process", start.elapsed().as_micros() as u64);
Source

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
Source

pub fn record_counter(&mut self, operation: &str, increment: u64)

Record a counter increment.

Counters are monotonically increasing values (e.g., total orders received).

Source

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).

Source

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.

Source

pub fn metrics_count(&self) -> usize

Get the number of buffered metrics entries.

Source

pub fn metrics_buffer_full(&self) -> bool

Check if the metrics buffer is full.

Source

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 via KernelAlert::new() helpers)
§Example
ctx.emit_alert(KernelAlert::high_latency("Slow processing", 500));
ctx.emit_alert(KernelAlert::error("Processing failed"));
Source

pub fn has_alert_channel(&self) -> bool

Check if alert sending is configured.

Source

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 operation
  • latency_us - Actual latency in microseconds
  • threshold_us - Threshold above which to emit alert

Trait Implementations§

Source§

impl<'a> Debug for RingContext<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

Source§

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The type for metadata in pointers and references to Self.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more