Module Backend.Memory

GPU memory allocation and transfer

type 'a buffer
val alloc : Device.t -> int -> ('a, 'b) Stdlib.Bigarray.kind -> 'a buffer
val alloc_custom : Device.t -> size:int -> elem_size:int -> 'a buffer

Allocate buffer for custom types with explicit element size in bytes

val alloc_zero_copy : Device.t -> ('a, 'b, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Array1.t -> ('a, 'b) Stdlib.Bigarray.kind -> 'a buffer option

Allocate zero-copy buffer using host bigarray memory directly. For CPU OpenCL devices, this avoids memory copies entirely. Returns None if zero-copy not supported by this backend.

val free : 'a buffer -> unit

Synchronous Transfers

val host_to_device : src:('a, 'b, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Array1.t -> dst:'a buffer -> unit
val device_to_host : src:'a buffer -> dst:('a, 'b, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Array1.t -> unit
val host_ptr_to_device : src_ptr:unit Ctypes.ptr -> byte_size:int -> dst:'a buffer -> unit

Transfer from raw pointer to device (for custom types). src_ptr should be obtained via Ctypes from a customarray.

val device_to_host_ptr : src:'a buffer -> dst_ptr:unit Ctypes.ptr -> byte_size:int -> unit

Transfer from device to raw pointer (for custom types)

val device_to_device : src:'a buffer -> dst:'a buffer -> unit

Buffer Info

val size : 'a buffer -> int
val device_ptr : 'a buffer -> nativeint
val is_zero_copy : 'a buffer -> bool

Check if buffer uses zero-copy (no transfers needed)