pub struct RingContext<'a> {
pub thread_id: ThreadId,
pub block_id: BlockId,
pub block_dim: Dim3,
pub grid_dim: Dim3,
clock: &'a HlcClock,
kernel_id: u64,
backend: ContextBackend,
}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.
clock: &'a HlcClockHLC clock instance.
kernel_id: u64Kernel ID.
backend: ContextBackendBackend implementation.
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,
) -> Self
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.
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>
pub fn update_clock(&self, received: &HlcTimestamp) -> Result<HlcTimestamp>
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: Copy>(&self, value: T, src_lane: u32) -> T
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.
Sourcepub fn warp_shuffle_down<T: Copy>(&self, value: T, delta: u32) -> T
pub fn warp_shuffle_down<T: Copy>(&self, value: T, delta: u32) -> T
Warp shuffle down - get value from lane + delta.
Sourcepub fn warp_shuffle_up<T: Copy>(&self, value: T, delta: u32) -> T
pub fn warp_shuffle_up<T: Copy>(&self, value: T, delta: u32) -> T
Warp shuffle up - get value from lane - delta.
Sourcepub fn warp_shuffle_xor<T: Copy>(&self, value: T, mask: u32) -> T
pub fn warp_shuffle_xor<T: Copy>(&self, value: T, mask: u32) -> T
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<()>
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.
Sourcepub fn k2k_try_recv(&self) -> Result<MessageEnvelope>
pub fn k2k_try_recv(&self) -> Result<MessageEnvelope>
Try to receive message from K2K queue.