Module Spoc_core_base.Make

Parameters

module Ops : CUSTOM_OPS

Signature

Element types

type ('a, 'b) scalar_kind =
  1. | Float32 : (float, Stdlib.Bigarray.float32_elt) scalar_kind
  2. | Float64 : (float, Stdlib.Bigarray.float64_elt) scalar_kind
  3. | Int32 : (int32, Stdlib.Bigarray.int32_elt) scalar_kind
  4. | Int64 : (int64, Stdlib.Bigarray.int64_elt) scalar_kind
  5. | Char : (char, Stdlib.Bigarray.int8_unsigned_elt) scalar_kind
  6. | Complex32 : (Stdlib.Complex.t, Stdlib.Bigarray.complex32_elt) scalar_kind
type location =
  1. | CPU
  2. | GPU of Ops.device_t
  3. | Both of Ops.device_t
  4. | Stale_CPU of Ops.device_t
  5. | Stale_GPU of Ops.device_t
type 'a custom_type = {
  1. elem_size : int;
  2. type_id : 'a Sarek_ir_types.Type_id.t;
  3. vector_type_id : ('a, unit) t Sarek_ir_types.Type_id.t;
  4. get : Ops.handle -> int -> 'a;
  5. set : Ops.handle -> int -> 'a -> unit;
  6. name : string;
}
and (_, _) kind =
  1. | Scalar : ('a, 'b) scalar_kind -> ('a, 'b) kind
  2. | Custom : 'a custom_type -> ('a, unit) kind
and (_, _) host_storage =
  1. | Bigarray_storage : ('a, 'b, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Array1.t -> ('a, 'b) host_storage
  2. | Custom_storage : {
    1. ptr : Ops.handle;
    2. custom : 'a custom_type;
    3. length : int;
    } -> ('a, unit) host_storage
and ('a, 'b) t = {
  1. host : ('a, 'b) host_storage;
  2. device_buffers : (int, Ops.device_buf) Stdlib.Hashtbl.t;
  3. length : int;
  4. kind : ('a, 'b) kind;
  5. mutable location : location;
  6. mutable auto_sync : bool;
  7. id : int;
}

Kind helpers — pure

val to_bigarray_kind : ('a, 'b) scalar_kind -> ('a, 'b) Stdlib.Bigarray.kind
val bigarray_elem_size : ('a, 'b) Stdlib.Bigarray.kind -> int
val scalar_elem_size : ('a, 'b) scalar_kind -> int
val elem_size : ('a, 'b) kind -> int
val scalar_kind_name : ('a, 'b) scalar_kind -> string
val kind_name : ('a, 'b) kind -> string

Type-id helpers

val float32_type_id : float Sarek_ir_types.Type_id.t
val float64_type_id : float Sarek_ir_types.Type_id.t
val int32_type_id : int32 Sarek_ir_types.Type_id.t
val int64_type_id : int64 Sarek_ir_types.Type_id.t
val char_type_id : char Sarek_ir_types.Type_id.t
val complex32_type_id : Stdlib.Complex.t Sarek_ir_types.Type_id.t
val scalar_type_id : ('a, 'b) scalar_kind -> 'a Sarek_ir_types.Type_id.t
val type_id : ('a, 'b) kind -> 'a Sarek_ir_types.Type_id.t
val float32_vector_type_id : (float, Stdlib.Bigarray.float32_elt) t Sarek_ir_types.Type_id.t
val float64_vector_type_id : (float, Stdlib.Bigarray.float64_elt) t Sarek_ir_types.Type_id.t
val int32_vector_type_id : (int32, Stdlib.Bigarray.int32_elt) t Sarek_ir_types.Type_id.t
val int64_vector_type_id : (int64, Stdlib.Bigarray.int64_elt) t Sarek_ir_types.Type_id.t
val char_vector_type_id : (char, Stdlib.Bigarray.int8_unsigned_elt) t Sarek_ir_types.Type_id.t
val complex32_vector_type_id : (Stdlib.Complex.t, Stdlib.Bigarray.complex32_elt) t Sarek_ir_types.Type_id.t
val vector_type_id : ('a, 'b) kind -> ('a, 'b) t Sarek_ir_types.Type_id.t

Creation

val create_scalar : ('a, 'b) scalar_kind -> ?dev:Ops.device_t -> int -> ('a, 'b) t
val create : ('a, 'b) kind -> ?dev:Ops.device_t -> int -> ('a, 'b) t
val create_custom : 'a custom_type -> ?dev:Ops.device_t -> int -> ('a, unit) t
val of_bigarray : ('a, 'b) scalar_kind -> ('a, 'b, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Array1.t -> ('a, 'b) t
val of_raw_handle : 'a custom_type -> nativeint -> int -> ('a, unit) t

Accessors

val to_bigarray : ('a, 'b) t -> ('a, 'b, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Array1.t
val has_buffer : ('a, 'b) t -> Ops.device_t -> bool
val get_buffer : ('a, 'b) t -> Ops.device_t -> Ops.device_buf option

Subvector metadata

type sub_meta = {
  1. parent_id : int;
  2. start : int;
  3. ok_range : int;
  4. ko_range : int;
  5. depth : int;
}
val is_sub : ('a, 'b) t -> bool
val get_sub_meta : ('a, 'b) t -> sub_meta option
val depth : ('a, 'b) t -> int
val parent_id : ('a, 'b) t -> int option
val sub_start : ('a, 'b) t -> int option
val sub_ok_range : ('a, 'b) t -> int option
val sub_ko_range : ('a, 'b) t -> int option

Copy & slicing

val copy_host_only : ('a, 'b) t -> ('a, 'b) t
val sub_vector_host : ('a, 'b) t -> start:int -> len:int -> ('a, 'b) t
val sub_vector : ('a, 'b) t -> start:int -> len:int -> ok_range:int -> ko_range:int -> ('a, 'b) t
val partition_host : ('a, 'b) t -> Ops.device_t array -> ('a, 'b) t array

List / array creation

val of_list : ('a, 'b) kind -> 'a list -> ('a, 'b) t
val of_array : ('a, 'b) kind -> 'a array -> ('a, 'b) t

Auto-sync callback

type sync_callback = {
  1. sync : 'a 'b. ('a, 'b) t -> bool;
}
val register_sync_callback : sync_callback -> unit
val ensure_cpu_sync : ('a, 'b) t -> unit

Handle access for the transfer layer

val host_handle : ('a, 'b) t -> Ops.handle
val host_raw : ('a, 'b) t -> nativeint

Convenience scalar-kind values

val float32 : (float, Stdlib.Bigarray.float32_elt) kind
val float64 : (float, Stdlib.Bigarray.float64_elt) kind
val int32 : (int32, Stdlib.Bigarray.int32_elt) kind
val int64 : (int64, Stdlib.Bigarray.int64_elt) kind
val char : (char, Stdlib.Bigarray.int8_unsigned_elt) kind
val complex32 : (Stdlib.Complex.t, Stdlib.Bigarray.complex32_elt) kind