MetalBuffer wrap_existing(void * cpu_ptr, int nbytes)Wrap an externally-owned, page-aligned CPU pointer in a Metal buffer.
Calls newBufferWithBytesNoCopy: on the shared MTLDevice, which
requires the source memory to be page-aligned and at least
page-size bytes. No copy is performed — GPU kernels read/write the
caller's buffer in place.
See Also
allocate_shared — fresh allocation, no aliasing.
Parameters
cpu_ ptrvoid*CPU pointer to wrap. Must be page-aligned (typically obtained from
posix_memalign or another Metal allocation).nbytesstd::size_tByte length of the region. Must be ≥ system page size.
Returns
MetalBufferDescriptor referring to cpu_ptr with mtl_handle set to the freshly created id<MTLBuffer>.
Raises
:runtime_errorIf Metal rejects the wrap (e.g. unaligned pointer, missing MTLDevice).