Module Spoc_core.Runtime

type dims = Spoc_framework.Framework_sig.dims = {
  1. x : int;
  2. y : int;
  3. z : int;
}

Re-export framework dims helpers to avoid duplicate types

val dims2d : int -> int -> Spoc_framework.Framework_sig.dims
val dims3d : int -> int -> int -> Spoc_framework.Framework_sig.dims
val to_framework_dims : dims -> dims
val init_device : ?framework:string -> unit -> Device.t

Initialize the runtime and get the best available device

val all_devices : ?framework:string -> unit -> Device.t array

Get all available devices

val kernel_cache : (string * string * int, Kernel.t) Stdlib.Hashtbl.t

Kernel source cache: (device_framework, kernel_name, source_hash) -> compiled

val compile_kernel : Device.t -> name:string -> source:string -> Kernel.t

Compile a kernel from source, with caching

val clear_cache : unit -> unit

Clear the kernel cache

type arg =
  1. | ArgBuffer : _ Memory.buffer -> arg
  2. | ArgInt32 : int32 -> arg
  3. | ArgInt64 : int64 -> arg
  4. | ArgFloat32 : float -> arg
  5. | ArgFloat64 : float -> arg

Argument builder - collects kernel arguments

val set_args : Device.t -> arg list -> Kernel.args

Create arguments from a list

val run_kernel : Kernel.t -> args:Kernel.args -> grid:dims -> block:dims -> ?shared_mem:int -> unit -> unit

Run a kernel with the given arguments

val run : Device.t -> name:string -> source:string -> args:arg list -> grid:dims -> block:dims -> ?shared_mem:int -> unit -> unit

High-level run function: compile (if needed) and execute

val alloc_float32 : Device.t -> int -> float Memory.buffer

Memory allocation shortcuts

val alloc_float64 : Device.t -> int -> float Memory.buffer
val alloc_int32 : Device.t -> int -> int32 Memory.buffer
val alloc_int64 : Device.t -> int -> int64 Memory.buffer
val alloc_custom : Device.t -> size:int -> elem_size:int -> 'a Memory.buffer

Allocate a buffer for custom types with explicit element size

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

Host-to-device transfer

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

Device-to-host transfer

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

Host-to-device transfer for custom types (raw pointer)

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

Device-to-host transfer for custom types (raw pointer)

val free : 'a Memory.buffer -> unit

Free a buffer