class

ML::MetalBuffer

Inherits Reference / Object

Wraps a Metal buffer with automatic resource management Uses MTLResourceStorageModeShared for unified memory on M-series chips

Constructors

from_array(data : Array(Float32), mode : StorageMode = StorageMode::Shared) : MetalBuffer

Wrap existing Array without copy (zero-copy)

Source
from_slice(data : Slice(Float32), mode : StorageMode = StorageMode::Shared) : MetalBuffer

Wrap existing Slice

Source
new(size : Int64, storage_mode : StorageMode = StorageMode::Shared)
Source

Class methods

stats
Source

Instance methods

contents

Get raw pointer for Metal kernel bindings

Source
copy_from(src : MetalBuffer, byte_size : Int64) : Nil

Copy from another buffer

Source
element_count

Element count (assuming Float32)

Source
finalize

RAII cleanup

Source
handle

Get underlying handle for FFI

Source
read(count : Int32) : Array(Float32)

Read data from buffer

Source
read_bytes(ptr : Pointer(UInt8), byte_size : Int) : Nil

Read raw bytes from buffer (validates actual bytes read)

Source
read_to_slice(dest : Slice(Float32)) : Nil
Source
release

Manual release (for explicit control)

Source
set_purgeable(state : PurgeableState) : Nil
Source
size
storage_mode
sync

Synchronize (for Managed mode on macOS)

Source
valid?
write(data : Array(Float32)) : Nil

Write data to buffer

Source
write_bytes(ptr : Pointer(UInt8), byte_size : Int) : Nil

Write raw bytes to buffer

Source
write_slice(data : Slice(Float32)) : Nil
Source