Module Spoc_core.Transfer

Auto-Transfer Mode

val auto_mode : bool Stdlib.ref
val enable_auto : unit -> unit
val disable_auto : unit -> unit
val is_auto : unit -> bool
val set_auto : bool -> unit

Device Buffer Allocation

val alloc_scalar_buffer : Device.t -> int -> ('a, 'b) Vector.scalar_kind -> Vector.device_buffer

Allocate a device buffer for a scalar vector, returning a DEVICE_BUFFER module. The buffer is packaged with its backend for type-safe operations.

For CPU devices (OpenCL CPU, Native), uses zero-copy allocation when possible to avoid memory transfers entirely.

val alloc_scalar_buffer_zero_copy : Device.t -> ('a, 'b, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Array1.t -> ('a, 'b) Vector.scalar_kind -> Vector.device_buffer option

Allocate a device buffer using zero-copy (host memory sharing) if supported. Returns None if the backend doesn't support zero-copy for this device.

val alloc_custom_buffer : Device.t -> int -> int -> Vector.device_buffer

Allocate a device buffer for a custom vector

Buffer Management for Vectors

val ensure_buffer : ('a, 'b) Vector.t -> Device.t -> Vector.device_buffer

Ensure vector has a device buffer, allocating if needed. For backends that support zero-copy (typically CPU backends), automatically uses zero-copy to avoid memory transfer overhead. The backend decides via alloc_zero_copy.

Transfer Operations

val to_device : ('a, 'b) Vector.t -> Device.t -> unit

Transfer vector data to a device

val to_cpu : ?force:bool -> ('a, 'b) Vector.t -> unit

Transfer vector data from device to CPU.

  • parameter force

    If true, always transfer even if location is Both (useful after kernel writes)

val sync : ('a, 'b) Vector.t -> unit

Ensure vector is fully synchronized

Buffer Cleanup

val free_buffer : ('a, 'b) Vector.t -> Device.t -> unit

Free device buffer for a vector

val free_all_buffers : ('a, 'b) Vector.t -> unit

Free all device buffers for a vector

Device Synchronization

val flush : Device.t -> unit

Synchronize all pending operations on a device

Stream Operations

module type STREAM = sig ... end

Stream handle - packages backend stream with its operations

type stream = (module STREAM)
val create_stream : Device.t -> stream

Create a new stream on a device

val default_stream : Device.t -> stream

Get default stream for a device

val synchronize_stream : stream -> unit
val destroy_stream : stream -> unit

Batch Operations

val to_device_all : ('a, 'b) Vector.t list -> Device.t -> unit
val to_cpu_all : ('a, 'b) Vector.t list -> unit
val sync_all : ('a, 'b) Vector.t list -> unit

Auto-sync Callback Registration