Metal shared-memory storage accessible from both CPU and GPU.
The underlying allocation is a Metal buffer created with
MTLResourceStorageModeShared, which the Metal driver maps into the
process address space. This gives Lucid a zero-copy host↔device bridge on
Apple Silicon unified-memory hardware: the same bytes are addressable from
CPU code through cpu_ptr and submitted to the GPU through
mtl_handle.
See Also
cpu_view — produces a CpuStorage aliasing this buffer.
Attributes
cpu_ptrvoid*mtl_handlevoid*id<MTLBuffer> handle, stored as void* to avoid pulling the Metal headers into this translation unit.nbytesstd::size_tdtypeDtypeDtype::F32.versionstd::shared_ptr<VersionCounter>ownerstd::shared_ptr<void>cpu_view deleter captures a copy so the Metal buffer cannot be freed while a CPU view is alive.Methods
3Atomically increments the shared version counter.
CpuStorage cpu_view()Returns a CpuStorage that aliases cpu_ptr without copying bytes.
The returned storage installs a custom deleter that holds a copy of
owner, guaranteeing the Metal buffer outlives every
CpuStorage view spawned this way. The VersionCounter
is also shared with this SharedStorage, so mutations through
the CPU view are visible to the GPU side.
Returns
CpuStorageCPU view aliasing the shared buffer. Lifetime-tied to owner.
Reads the current version counter value.
Returns
std::uint64_tMonotonically non-decreasing snapshot of mutation count.