Module Opencl_api.Memory

type 'a buffer = {
  1. handle : Opencl_types.cl_mem;
  2. size : int;
  3. elem_size : int;
  4. context : Context.t;
  5. zero_copy : bool;
}
val alloc : Context.t -> int -> ('a, 'b) Stdlib.Bigarray.kind -> 'c buffer
val alloc_with_host_ptr : Context.t -> int -> ('a, 'b) Stdlib.Bigarray.kind -> unit Ctypes_static.ptr -> 'c buffer

Allocate buffer with zero-copy using host pointer. For CPU OpenCL devices, this avoids memory copies entirely.

val alloc_custom : Context.t -> size:int -> elem_size:int -> 'a buffer

Allocate buffer for custom types with explicit element size in bytes

val is_zero_copy : 'a buffer -> bool

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

val free : 'a buffer -> unit
val host_to_device : CommandQueue.t -> src:('a, 'b, 'c) Stdlib.Bigarray.Array1.t -> dst:'d buffer -> unit
val device_to_host : CommandQueue.t -> src:'a buffer -> dst:('b, 'c, 'd) Stdlib.Bigarray.Array1.t -> unit
val host_ptr_to_device : CommandQueue.t -> src_ptr:unit Ctypes_static.ptr -> byte_size:int -> dst:'a buffer -> unit

Transfer from raw pointer to device buffer (for custom types)

val device_to_host_ptr : CommandQueue.t -> src:'a buffer -> dst_ptr:unit Ctypes_static.ptr -> byte_size:int -> unit

Transfer from device buffer to raw pointer (for custom types)