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: usizeBacking 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: u64Start byte address (contents_ptr() + byte_offset for
MlxBuffer). Used for overlap arithmetic.
p1: u64End 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: MemRangeRoleWhether this range is read or written by the recording dispatch.
Implementations§
Source§impl BufferRange
impl BufferRange
Sourcepub fn from_buffer(buf: &MlxBuffer, role: MemRangeRole) -> Self
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.
Sourcepub fn conflicts_with(&self, other: &BufferRange) -> bool
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
impl Clone for BufferRange
Source§fn clone(&self) -> BufferRange
fn clone(&self) -> BufferRange
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more