Skip to main content

Arena

Struct Arena 

Source
pub struct Arena {
    pub buffer: Buffer,
    pub f16_buffer: Option<Buffer>,
    pub offsets: HashMap<NodeId, usize>,
    pub lens: HashMap<NodeId, usize>,
    pub size: usize,
    pub scratch_off: usize,
    pub scratch_bytes: usize,
}
Expand description

One contiguous arena buffer + per-node byte offsets. Lives for the entire executable graph’s lifetime.

Fields§

§buffer: Buffer

Underlying GPU buffer. Bound as a single STORAGE_READ_WRITE resource for every kernel; offsets disambiguate per-node access.

§f16_buffer: Option<Buffer>

Optional shadow buffer holding f16 versions of every value written via write_f32. Sized at half the arena byte budget (each f32 element pairs with an f16 element at the same logical index — i.e. f16_off = f32_off / 2). Created only when the device exposes the SHADER_F16 feature; matmul kernels with f16-typed B input bind both buffer (for f32 activations) and f16_buffer (for f16 weights). Halves global memory traffic on the dominant matmul reads.

§offsets: HashMap<NodeId, usize>

Per-node byte offset into buffer.

§lens: HashMap<NodeId, usize>

Per-node byte length.

§size: usize

Total arena size in bytes.

§scratch_off: usize

Byte offset of the tail scratch zone (also size - scratch_bytes). Set when callers request scratch via from_plan_with_scratch. Reuseable across ops since scratch is temporary — only one op writes to it at a time within a schedule.

§scratch_bytes: usize

Size in bytes of the tail scratch zone (0 when not used).

Implementations§

Source§

impl Arena

Source

pub fn from_plan_with_scratch( device: &Device, plan: &MemoryPlan, scratch_bytes: usize, ) -> Self

Build an arena from a memory plan with an extra tail scratch zone of scratch_bytes reserved past the plan’s arena_size. Useful for ops that need throwaway temp storage that doesn’t fit in a workgroup-shared variable.

Source

pub fn from_plan(device: &Device, plan: &MemoryPlan) -> Self

Build an arena from a memory plan. Allocates one big buffer sized to fit every node’s offset+length.

Source

pub fn has(&self, id: NodeId) -> bool

Source

pub fn offset(&self, id: NodeId) -> usize

Source

pub fn len_of(&self, id: NodeId) -> usize

Source

pub fn param_fits_f16_mirror(&self, id: NodeId) -> bool

Whether this node’s f16 mirror fits in the capped f16 shadow buffer.

Source

pub fn set_actual_len(&mut self, id: NodeId, bytes: usize)

Override the actual data length (in bytes) for a node. The backend calls this after planning to record true elem*4 sizes instead of the alignment-padded slot sizes.

Source

pub fn write_f32(&self, queue: &Queue, id: NodeId, data: &[f32])

Write f32 data into the node’s slot. The queue performs an async transfer; subsequent kernel dispatches on the same queue see the new bytes. When the device supports SHADER_F16, also downcasts and writes the same data into the f16 shadow buffer at offset f32_offset / 2 — so matmul kernels with f16 weight bindings can read directly from there at half the bandwidth.

Source

pub fn write_f16_shadow(&self, queue: &Queue, id: NodeId, data: &[f32])

Downcast host f32 data into the f16 shadow buffer at id’s slot. Used when skipping redundant f32 write_buffer but CoopF16Vk still needs a fresh f16 mirror (e.g. input upload hash cache hits).

Source

pub fn read_f32(&self, device: &Device, queue: &Queue, id: NodeId) -> Vec<f32>

Read a node’s bytes back to host f32. Uses a fresh staging buffer; hot paths should call read_f32_pooled with a reused ReadbackStaging.

Source

pub fn read_bytes_range( &self, device: &Device, queue: &Queue, byte_off: usize, len: usize, ) -> Vec<u8>

Read a byte range from the arena (used for packed GGUF weights).

Source

pub fn write_bytes_range(&self, queue: &Queue, byte_off: usize, data: &[u8])

Write raw bytes into the arena at byte_off.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Arena

§

impl !UnwindSafe for Arena

§

impl Freeze for Arena

§

impl Send for Arena

§

impl Sync for Arena

§

impl Unpin for Arena

§

impl UnsafeUnpin for Arena

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> 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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,