Module Sarek_interp.Sarek_ir_interp

type value = Sarek_ir_interp_value.value =
  1. | VInt32 of int32
  2. | VInt64 of int64
  3. | VFloat32 of float
  4. | VFloat64 of float
  5. | VBool of bool
  6. | VUnit
  7. | VArray of value array
  8. | VRecord of string * value array
  9. | VVariant of string * int * value list

Re-export value type and constructors for external callers

val to_int : Sarek_ir_interp_value.value -> int
val to_int32 : Sarek_ir_interp_value.value -> int32
val to_int64 : Sarek_ir_interp_value.value -> int64
val to_float32 : Sarek_ir_interp_value.value -> float
val to_float64 : Sarek_ir_interp_value.value -> float
val to_bool : Sarek_ir_interp_value.value -> bool
type thread_state = Sarek_ir_interp_value.thread_state = {
  1. thread_idx : int * int * int;
  2. block_idx : int * int * int;
  3. block_dim : int * int * int;
  4. grid_dim : int * int * int;
}

Re-export thread_state type for external callers

type env = Sarek_ir_interp_value.env = {
  1. vars : (int, value) Stdlib.Hashtbl.t;
  2. vars_by_name : (string, value) Stdlib.Hashtbl.t;
  3. arrays : (string, value array) Stdlib.Hashtbl.t;
  4. shared : (string, value array) Stdlib.Hashtbl.t;
  5. funcs : (string, Sarek_ir_types.helper_func) Stdlib.Hashtbl.t;
  6. coopmats : (string, value array) Stdlib.Hashtbl.t;
}

Re-export env type for external callers

val create_env : unit -> Sarek_ir_interp_value.env

Domain Pool for Parallel Execution

module DomainPool : sig ... end
val resolve_domain_count : default:int -> unit -> int

Resolve how many domains the interpreter's DomainPool should use.

Reads SAREK_DOMAIN_COUNT first (any positive integer) so tests can force a domain count higher than the host's physical core count - this is the only reliable way to reproduce oversubscription races such as the DomainPool record-aliasing bug on a small developer machine. Falls back to Domain.recommended_domain_count (), and finally to a fixed default if that raises.

val global_pool : DomainPool.t option Stdlib.ref

Global pool - lazily initialized

val global_pool_mutex : Stdlib.Mutex.t
val get_pool : unit -> DomainPool.t
val run_grid_parallel : Sarek_ir_interp_value.env -> Sarek_ir_types.stmt -> (int * int * int) -> (int * int * int) -> unit

Run all blocks in a grid (parallel - distributes blocks across domain pool)

val parallel_mode : bool Stdlib.ref

Parallel execution mode flag

val run_grid : Sarek_ir_interp_value.env -> Sarek_ir_types.stmt -> (int * int * int) -> (int * int * int) -> unit

Run all blocks in a grid (uses parallel or sequential based on flag)

Public API

type arg =
  1. | ArgArray of value array
  2. | ArgScalar of value

Argument for kernel execution

val run_kernel : Sarek_ir_types.kernel -> block:(int * int * int) -> grid:(int * int * int) -> (string * arg) list -> unit

Run a kernel on CPU

V2 Vector Support

These functions work with typed Kernel_arg.t values. This is the preferred interface for Native/Interpreter backends.

val vector_to_array : 'a 'b. ('a, 'b) Spoc_core.Vector.t -> value array

Convert V2 Vector to interpreter value array. Uses the vector's element type to create properly typed values.

val array_to_vector : 'a 'b. value array -> ('a, 'b) Spoc_core.Vector.t -> unit

Write interpreter value array back to V2 Vector

type writeback =
  1. | Writeback : (('a, 'b) Spoc_core.Vector.t * value array) -> writeback

Existential wrapper to track V2 Vector + its interpreter array for writeback

type exec_writeback =
  1. | Exec_writeback : (module Spoc_framework.Typed_value.EXEC_VECTOR) * value array -> exec_writeback
val value_of_bytes : bytes -> Sarek_tuple_vec.field_layout -> value
val bytes_of_shape : Sarek_tuple_vec.shape -> value array -> bytes
val value_of_typed_value : Spoc_framework.Typed_value.typed_value -> value
val typed_value_of_value : (module Spoc_framework.Typed_value.EXEC_VECTOR with type elt = 'a) -> value -> Spoc_framework.Typed_value.typed_value option
val exec_vector_to_array : (module Spoc_framework.Typed_value.EXEC_VECTOR) -> value array
val array_to_exec_vector : (module Spoc_framework.Typed_value.EXEC_VECTOR) -> value array -> unit
val args_from_exec_args : Sarek_ir_types.kernel -> Spoc_framework.Framework_sig.exec_arg list -> (string * arg) list * exec_writeback list
val run_kernel_with_exec_args : Sarek_ir_types.kernel -> block:(int * int * int) -> grid:(int * int * int) -> Spoc_framework.Framework_sig.exec_arg list -> unit
val args_from_kernel_args : Sarek_ir_types.kernel -> Spoc_core.Kernel_arg.t list -> (string * arg) list * writeback list

Convert Kernel_arg.t list to interpreter args, tracking vectors for writeback

val run_kernel_with_args : Sarek_ir_types.kernel -> block:(int * int * int) -> grid:(int * int * int) -> Spoc_core.Kernel_arg.t list -> unit

Run kernel with V2 Vector arguments (Kernel_arg.t list). This is the preferred entry point for Native/Interpreter backends. Handles conversion to/from interpreter format with proper writeback.