Module Spoc_core.Kernel_arg

type t =
  1. | Vec : ('a, 'b) Vector.t -> t
    (*

    V2 Vector - carries full vector for Direct backends

    *)
  2. | Int : int -> t
    (*

    Integer scalar (converted to int32)

    *)
  3. | Int32 : int32 -> t
    (*

    32-bit integer scalar

    *)
  4. | Int64 : int64 -> t
    (*

    64-bit integer scalar

    *)
  5. | Float32 : float -> t
    (*

    32-bit float scalar

    *)
  6. | Float64 : float -> t
    (*

    64-bit float scalar

    *)

Kernel argument GADT - each variant carries its typed value

type any_vec =
  1. | AnyVec : ('a, 'b) Vector.t * ('a, 'b) Vector.kind -> any_vec

Existential wrapper for vectors with element type info

val as_vector : t -> any_vec option

Extract vector if argument is a Vec, with type info

val vector_length : t -> int option

Get vector length if argument is a Vec

val as_int32 : t -> int32 option

Get scalar as int32 if possible

val as_int64 : t -> int64 option

Get scalar as int64 if possible

val as_float : t -> float option

Get scalar as float if possible

type 'acc folder = {
  1. on_vec : 'a 'b. ('a, 'b) Vector.t -> 'acc -> 'acc;
  2. on_int : int -> 'acc -> 'acc;
  3. on_int32 : int32 -> 'acc -> 'acc;
  4. on_int64 : int64 -> 'acc -> 'acc;
  5. on_float32 : float -> 'acc -> 'acc;
  6. on_float64 : float -> 'acc -> 'acc;
}

Fold over kernel arguments with typed handlers. This is the main way backends consume args in a type-safe manner.

For JIT backends, the vector handler receives the vector and should bind (buffer_ptr, length) to the kernel args.

For Direct backends, the vector handler can access the vector directly.

val fold : 'acc folder -> t list -> 'acc -> 'acc
type iterator = {
  1. iter_vec : 'a 'b. ('a, 'b) Vector.t -> unit;
  2. iter_int : int -> unit;
  3. iter_int32 : int32 -> unit;
  4. iter_int64 : int64 -> unit;
  5. iter_float32 : float -> unit;
  6. iter_float64 : float -> unit;
}

Iterate over args with side effects

val iter : iterator -> t list -> unit
type 'a mapper = {
  1. map_vec : 'b 'c. ('b, 'c) Vector.t -> 'a;
  2. map_int : int -> 'a;
  3. map_int32 : int32 -> 'a;
  4. map_int64 : int64 -> 'a;
  5. map_float32 : float -> 'a;
  6. map_float64 : float -> 'a;
}

Map args to a list of values using typed handlers

val map : 'a mapper -> t list -> 'a list