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. policy : Sarek_policy.Budget.t;
  7. coopmats : (int * string, value array) Stdlib.Hashtbl.t;
}

Re-export env type for external callers

val create_env : ?policy:Sarek_policy.Budget.t -> unit -> Sarek_ir_interp_value.env

Parallel Execution

Blocks run on Cpu_domain_pool, shared with the Native barrier path, created on the first parallel launch and retired when idle.

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 same_vector : 'a 'b 'c 'd. ('a, 'b) Spoc_core.Vector.t -> ('c, 'd) Spoc_core.Vector.t -> bool

Whether two vectors are the same vector.

Physical identity, taken on the vector's own device_buffers table: it is allocated once per vector and never replaced, it has one type whatever the vectors' element types (so two vectors of different types can be compared without Obj), and a comparison of the records themselves would need both to have the same type. The vector id is deliberately NOT used: ids come from a non-atomic counter and can collide across domains (R-1).

val bind_vector : writeback list Stdlib.ref -> ('a, 'b) Spoc_core.Vector.t -> to_array:(('a, 'b) Spoc_core.Vector.t -> value array) -> value array

The value array bound to vec: the one already bound among writebacks if vec is a vector passed before, otherwise a fresh one from to_array, which is recorded in writebacks.

Two kernel parameters bound to the same vector must share ONE value array: a private copy each would make a write through one invisible to a read through the other, and the writebacks would then overwrite each other in an order that depends on the entry point. Binding by identity gives the semantics of the device, where both parameters are the same buffer.

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 same_exec_vector : (module Spoc_framework.Typed_value.EXEC_VECTOR) -> (module Spoc_framework.Typed_value.EXEC_VECTOR) -> bool

Whether two EXEC_VECTOR wrappers stand for the same vector.

Their underlying values can only be compared once their types are known to be equal, which the type ids witness. Execute.exec_arg_of_vector gives every wrapper of a Vector.t the SAME stable underlying_type_id (per element kind) and underlying = v, so two arguments that are one vector compare physically equal. A wrapper that mints a fresh id per instance (the interpreter plugin's own buffer wrapper) never matches: it wraps a device buffer, not a host vector, and no launch built from host vectors reaches it.

val bind_exec_vector : exec_writeback list Stdlib.ref -> (module Spoc_framework.Typed_value.EXEC_VECTOR) -> value array

bind_vector for an EXEC_VECTOR argument.

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.