std1.0.0-beta-7 SafeC docs

std :: ml::gpu_mps

Struct std::MpsBuf

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

struct MpsBuf {
    ?&MtlObject handle;
    unsigned long bytes;
    int dtype;
}

Fields

§unsigned long bytessource
§int dtypesource

Methods

§int valid() constsource · definition

handle != null

§void free()source · definition

back to the buffer pool; handle := null

§int read([]unsigned char dst) constsource · definition

Copies the first dst.len (<= this.bytes) bytes into 'dst'. Valid once every batch writing the buffer has ended (shared memory: no transfer). 1 = done.

§int write([]const unsigned char src)source · definition

Copies src.len bytes (<= this.bytes) from 'src' into the buffer: valid while no batch that reads or writes it is in flight. 1 = done.

§?&float contents() constsource · definition

The buffer's memory as the CPU sees it (shared storage: the same bytes the GPU reads and writes), null for an invalid buffer or without Metal. Read or write it only while no batch using the buffer is in flight.

§static struct MpsBuf alloc(unsigned long n, int dtype)source · definition

n uninitialized elements

§static struct MpsBuf upload([]const float host)source · definition
§static struct MpsBuf upload_f16([]const float host)source · definition

n fp32 values rounded on the CPU (float16.h's f32_to_fp16_bulk / f32_to_bf16_bulk) and stored as fp16 / bf16.

§static struct MpsBuf upload_bf16([]const float host)source · definition
§static struct MpsBuf upload_bits([]const unsigned short bits, int dtype)source · definition

n raw fp16 or bf16 values (dtype MPS_FP16 / MPS_BF16), copied as is.

§static struct MpsBuf linear_attn_state(unsigned long numHeads, unsigned long headDim)source · definition

A zeroed recurrent linear-attention state (mps_linear_attn_bf16_chained): mps_linear_attn_state_bytes(numHeads, headDim) bytes of fp32.

§static struct MpsBuf batch_last_output()source · definition

The output of the op most recently encoded into the open batch (its bytes and dtype), invalid if no batch is active or nothing has been encoded yet. Call right after a batched op returns to chain its still-pending result into a following op without waiting for mps_batch_end(). The batch owns it: don't free() it; it returns to the pool when the batch ends.