Skip to content
fn

settle_buffer_readers

void settle_buffer_readers(const SharedStorage & sh, int with)

Run every pending GPU array whose graph reads sh's bytes, then wait for the device, so a host write into sh that follows changes none of them.

Parameters

shconst SharedStorage&
The buffer about to be written.
withstd::vector<mlx::core::array>= None
Arrays to run in the same pass — the value about to be written, which would otherwise cost a second trip to the device.

Notes

A pending array reads the buffer when its graph reaches an array that has run and holds the buffer's bytes: the pinned alias (sh.gpu_alias), a DLPack import of the same Metal buffer, or whatever MLX derived from either without a copy (reshape, slice, contiguous, copy, single-input cat/stack, unit-axis sum). Only arrays wrap_mlx_array noted as pending are roots of the search. Other pending work stays lazy while the walking it costs stays within a budget shared by successive settles; past it every pending array runs, which costs no more than searching it again on every later write would. Every op result wrap_mlx_array created that MLX evaluated by aliasing the buffer's bytes (copy_shared_buffer) is then rebound onto a fresh snapshot of the pre-write bytes before the write lands.