Skip to main content

BufferRange

Struct BufferRange 

Source
pub struct BufferRange {
    pub buf_id: usize,
    pub p0: u64,
    pub p1: u64,
    pub role: MemRangeRole,
}
Expand description

A buffer region recorded for dataflow tracking.

Mirrors struct ggml_mem_range in ggml-metal-common.cpp:10-17.

Fields§

§buf_id: usize

Backing metal::Buffer pointer cast to usize. Stable across the encoder lifetime as long as the MlxBuffer’s ARC clone outlives the CB (see CommandEncoder::new_with_residency caller contract).

§p0: u64

Start byte address (contents_ptr() + byte_offset for MlxBuffer). Used for overlap arithmetic.

§p1: u64

End byte address (start + element-extent). llama.cpp uses tensor->data + ggml_backend_buft_get_alloc_size(tensor) — for mlx-native we use the buffer’s byte_len() minus byte_offset(), which equals the slice extent.

§role: MemRangeRole

Whether this range is read or written by the recording dispatch.

Implementations§

Source§

impl BufferRange

Source

pub fn from_buffer(buf: &MlxBuffer, role: MemRangeRole) -> Self

Build a BufferRange from an MlxBuffer and a role.

Uses metal_buffer().as_ptr() as usize as the buffer-id (so two slice_views of the same parent share a buf_id, which is the intended behavior — a slice write must barrier against a sibling-slice read of the same parent).

The (p0, p1) range covers the addressable extent the kernel can reach: [contents_ptr + byte_offset, contents_ptr + byte_offset + (byte_len - byte_offset)). For non-slice buffers byte_offset == 0 and the range covers the full allocation. For slices the range covers only the slice region — matching llama.cpp’s tensor->data .. tensor->data + alloc_size.

Source

pub fn conflicts_with(&self, other: &BufferRange) -> bool

Whether self and other overlap by the same arithmetic llama.cpp uses at ggml-metal-common.cpp:138.

Returns false for cross-buffer pairs (different buf_id) and for src-vs-src pairs (read-read is always concurrent-safe).

Trait Implementations§

Source§

impl Clone for BufferRange

Source§

fn clone(&self) -> BufferRange

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

impl Debug for BufferRange

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Copy for BufferRange

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.