Module Spoc_core.Memory

Buffer Module Type

module type BUFFER = sig ... end

A buffer packages backend-specific buffer with its operations. All transfers use raw pointers with byte sizes to avoid type parameter escaping issues in first-class modules.

type _ buffer =
  1. | Buffer : (module BUFFER) -> 'a buffer

Buffer with phantom type parameter for element type safety. The 'a parameter is not used at runtime but ensures type-safe transfers.

Allocation

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

Allocate a buffer on a device for standard Bigarray types

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

Allocate a buffer for custom types with explicit element size in bytes

Buffer Operations

val free : 'a. 'a buffer -> unit

Free a buffer

val host_to_device : 'a 'b. src:('a, 'b, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Array1.t -> dst:'a buffer -> unit

Copy data from host bigarray to device. Converts bigarray to pointer internally. Type parameter ensures bigarray element type matches buffer type.

val device_to_host : 'a 'b. src:'a buffer -> dst:('a, 'b, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Array1.t -> unit

Copy data from device to host bigarray. Converts bigarray to pointer internally. Type parameter ensures bigarray element type matches buffer type.

val host_ptr_to_device : 'a. src_ptr:unit Ctypes.ptr -> dst:'a buffer -> unit

Copy data from raw pointer to device buffer (for custom types)

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

Copy data from device buffer to raw pointer (for custom types)

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

Copy data between device buffers (same device). Type parameter ensures both buffers have same element type.

Accessors

val size : 'a. 'a buffer -> int

Get buffer size in elements

val elem_size : 'a. 'a buffer -> int

Get buffer element size in bytes

val device : 'a. 'a buffer -> Device.t

Get buffer device

val device_ptr : 'a. 'a buffer -> nativeint

Get raw device pointer

val bind_to_kargs : 'a. 'a buffer -> Spoc_framework.Framework_sig.kargs -> int -> unit

Bind buffer to kernel args