Skip to main content

DispatchRecord

Struct DispatchRecord 

Source
pub struct DispatchRecord {
    pub pipeline: ComputePipelineState,
    pub threadgroups: MTLSize,
    pub threads_per_tg: MTLSize,
    pub threadgroup_mem: Vec<(u64, u64)>,
    pub params_bytes: Vec<u8>,
    pub params_slot: u64,
    pub buffer_slots: Vec<u64>,
    pub op_kind: CapturedOpKind,
    pub kernel_name: String,
}
Expand description

Pre-baked dispatch record for hot decode paths.

ADR-029 iter-175 Step 1d — first piece of the multi-week “Option A” refactor that the gemma4 decode gap analysis localized to per-dispatch CPU orchestration (forward_mlx::forward_decode → encode_one_layer → dispatch_qmatmul → quantized_matmul_ggml → dispatch_mv → encoder.encode_threadgroups_with_args).

At gemma4 decode m=1, every dispatch within the inner loop has load-time-immutable shape: the kernel pipeline, threadgroup geometry, params struct bytes, and binding-slot layout are fully determined by the weight + ggml_type and never change across the thousands of decode tokens that follow. DispatchRecord captures that state once at model-load (or on first-call lazy-init) so the hot path skips:

  • KernelRegistry::get_pipeline* HashMap lookups
  • match expressions over ggml_type for kernel-name + geometry
  • MTLSize::new construction (already-known values)
  • param-struct field stores + bytemuck::bytes_of conversion

Only the runtime-varying buffers (input, output) need to be passed to CommandEncoder::dispatch_record. Weight buffers are baked inline via the bake_buffers slot list.

§Bake-time invariants

  • buffer_slots.len() == bake_buffers.len() + runtime_buffer_count for the call site contract; the call site documents runtime_buffer_count and the order of runtime buffers.
  • params_bytes.len() is whatever the kernel’s KernelArg::Bytes expects (typically 8-byte aligned per Metal struct layout).
  • threadgroup_mem is (slot, byte_length) pairs; empty when the kernel doesn’t request [[threadgroup]] memory.

§Coherence

dispatch_record produces a byte-identical Metal command stream to the equivalent encode_threadgroups_with_args* call. Capture mode is supported (replays into CapturedNode::Dispatch exactly like the unbaked path). See dispatch_record for the lockstep.

Fields§

§pipeline: ComputePipelineState

Pipeline reference, looked up once at bake time.

§threadgroups: MTLSize

Threadgroup count.

§threads_per_tg: MTLSize

Threads per threadgroup.

§threadgroup_mem: Vec<(u64, u64)>

Threadgroup shared-memory bindings: (slot_index, byte_length). Empty when the kernel doesn’t allocate [[threadgroup]] memory.

§params_bytes: Vec<u8>

Pre-encoded params struct bytes (bound as KernelArg::Bytes). Empty when the kernel has no inline-bytes parameter.

§params_slot: u64

Slot index for params_bytes. Ignored when params_bytes is empty.

§buffer_slots: Vec<u64>

Slot indices for runtime buffer arguments, in caller order. dispatch_record zips runtime_buffers against this list.

§op_kind: CapturedOpKind

CapturedOpKind used when the encoder is in capture mode.

§kernel_name: String

Diagnostic label (kernel name) for debug/timing.

Trait Implementations§

Source§

impl Clone for DispatchRecord

Source§

fn clone(&self) -> DispatchRecord

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.