std1.0.0-beta-7 SafeC docs

std :: ml::gpu_mps

Struct std::MtlObject

#include <std/ml/gpu_mps.h> source

struct MtlObject { }

A Metal buffer the GPU ops below read and write directly -- the MPS twin of gpu_rocm.h's RocmBuf / RocmHalfBuf. 'handle' is the MTLBuffer (CPU/GPU shared memory, never dereferenced by callers) and null for an invalid (failed or freed) buffer; every op returns 0 for one. 'bytes' is the size it was created with -- what free() returns to the buffer pool and the most read() copies. 'dtype' is its element type: 0 = fp32, MPS_FP16 or MPS_BF16 (informational: ops don't check it, so a buffer can hold any 4- or 2-byte data, e.g. a uint32 length table uploaded through upload()).

Persistent buffers (alloc / upload* / linear_attn_state) are owned by the caller: upload once, then pass the same buffer to as many dispatches and batches as you like, instead of re-uploading a CPU array on every call. Construct only while no batch that might still be reading a freed buffer is in flight (constructors reuse pool slots); free() exactly once, after every batch reading it has ended. All constructors return an invalid buffer without a Metal device. An Objective-C / Metal object (id<MTLBuffer>, id<MTLDevice>, ...): opaque, never constructed, only passed back to the Metal APIs it comes from.