Spoc_core.Vectorinclude module type of struct include Vector_types endtype (_, _) scalar_kind = (_, _) Vector_types.scalar_kind = | Float32 : (float, Stdlib.Bigarray.float32_elt) scalar_kind| Float64 : (float, Stdlib.Bigarray.float64_elt) scalar_kind| Int32 : (int32, Stdlib.Bigarray.int32_elt) scalar_kind| Int64 : (int64, Stdlib.Bigarray.int64_elt) scalar_kind| Char : (char, Stdlib.Bigarray.int8_unsigned_elt) scalar_kind| Complex32 : (Stdlib.Complex.t, Stdlib.Bigarray.complex32_elt) scalar_kindStandard numeric kinds backed by Bigarray
type 'a custom_type = 'a Vector_types.custom_type = {elem_size : int;Size of each element in bytes
*)get : unit Ctypes.ptr -> int -> 'a;Read element at index
*)set : unit Ctypes.ptr -> int -> 'a -> unit;Write element at index
*)name : string;Type name for debugging
*)}Custom type descriptor for ctypes-based structures
module Custom_helpers = Vector_types.Custom_helpersHelper functions for custom type implementations. These wrap Ctypes operations to provide simpler APIs for PPX-generated code.
type (_, _) kind = (_, _) Vector_types.kind = | Scalar : ('a, 'b) scalar_kind -> ('a, 'b) kind| Custom : 'a custom_type -> ('a, unit) kindUnified kind type supporting both scalar and custom types
val to_bigarray_kind :
'a 'b. ('a, 'b) scalar_kind ->
('a, 'b) Stdlib.Bigarray.kindConvert scalar kind to Bigarray.kind
val scalar_elem_size : 'a 'b. ('a, 'b) scalar_kind -> intElement size in bytes
val elem_size : 'a 'b. ('a, 'b) kind -> intval scalar_kind_name : 'a 'b. ('a, 'b) scalar_kind -> stringKind name for debugging
val kind_name : 'a 'b. ('a, 'b) kind -> stringtype (_, _) host_storage = (_, _) Vector_types.host_storage = | Bigarray_storage : ('a, 'b, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Array1.t ->
('a, 'b)
host_storage| Custom_storage : {ptr : unit Ctypes.ptr;custom : 'a custom_type;length : int;} -> ('a, unit) host_storageCPU-side storage - either Bigarray or raw ctypes pointer
type location = Vector_types.location = Where the authoritative copy of data resides
module type DEVICE_BUFFER = Vector_types.DEVICE_BUFFERDevice buffer reuses Memory.BUFFER module type. We use the raw module type here (not the phantom-typed Memory.buffer) because the hashtable stores buffers for a single vector type, and the type safety comes from the Vector's ('a, 'b) t type parameter.
type device_buffer = (module DEVICE_BUFFER)type device_buffers = (int, device_buffer) Stdlib.Hashtbl.tDevice buffer storage - maps device ID to buffer
type ('a, 'b) t = ('a, 'b) Vector_types.t = {host : ('a, 'b) host_storage;device_buffers : device_buffers;length : int;kind : ('a, 'b) kind;mutable location : location;mutable auto_sync : bool;Enable automatic CPU sync on get
*)id : int;Unique vector ID for debugging
*)}High-level vector with location tracking
val create_scalar :
('a, 'b) Vector_types.scalar_kind ->
?dev:Device.t ->
int ->
('a, 'b) Vector_types.tval create :
('a, 'b) Vector_types.kind ->
?dev:Device.t ->
int ->
('a, 'b) Vector_types.tval create_custom :
'a Vector_types.custom_type ->
?dev:Device.t ->
int ->
('a, unit) Vector_types.tval of_bigarray :
('a, 'b) Vector_types.scalar_kind ->
('a, 'b, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Array1.t ->
('a, 'b) Vector_types.tval of_ctypes_ptr :
'a Vector_types.custom_type ->
unit Ctypes.ptr ->
int ->
('a, unit) Vector_types.tval length : ('a, 'b) t -> intval id : ('a, 'b) t -> intval to_bigarray :
'a 'b. ('a, 'b) t ->
('a, 'b, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Array1.tGet underlying Bigarray (only for scalar vectors)
val to_ctypes_ptr : ('a, 'b) Vector_types.t -> unit Ctypes.ptrval host_ptr : ('a, 'b) Vector_types.t -> nativeintval register_sync_callback : Vector_transfer.sync_callback -> unitval ensure_cpu_sync : ('a, 'b) Vector_types.t -> unitval get : 'a 'b. ('a, 'b) t -> int -> 'aGet element (works for both storage types). Auto-syncs from GPU if location is Stale_CPU and auto_sync is enabled.
val set : 'a 'b. ('a, 'b) t -> int -> 'a -> unitSet element (works for both storage types)
val (.%[]) : ('a, 'b) t -> int -> 'aIndexing operators
val (.%[]<-) : ('a, 'b) t -> int -> 'a -> unitval unsafe_get : 'a 'b. ('a, 'b) t -> int -> 'aval unsafe_set : 'a 'b. ('a, 'b) t -> int -> 'a -> unitval kernel_set : 'a 'b. ('a, 'b) t -> int -> 'a -> unitKernel-safe set: no bounds check, no location update. Use this in parallel kernel execution where:
val set_auto_sync : ('a, 'b) t -> bool -> unitval auto_sync : ('a, 'b) t -> boolval is_on_cpu : ('a, 'b) t -> boolval is_on_gpu : ('a, 'b) t -> boolval is_synced : ('a, 'b) t -> boolval needs_gpu_update : ('a, 'b) t -> boolval needs_cpu_update : ('a, 'b) t -> boolval has_buffer : ('a, 'b) Vector_types.t -> Device.t -> boolCheck if vector has buffer on specific device
val get_buffer :
('a, 'b) Vector_types.t ->
Device.t ->
Vector_types.device_buffer optionGet device buffer if allocated
val location_to_string : location -> stringval to_string : ('a, 'b) t -> stringval float32 : (float, Stdlib.Bigarray.float32_elt) kindval float64 : (float, Stdlib.Bigarray.float64_elt) kindval int32 : (int32, Stdlib.Bigarray.int32_elt) kindval int64 : (int64, Stdlib.Bigarray.int64_elt) kindval char : (char, Stdlib.Bigarray.int8_unsigned_elt) kindval complex32 : (Stdlib.Complex.t, Stdlib.Bigarray.complex32_elt) kindval create_float32 :
?dev:Device.t ->
int ->
(float, Stdlib.Bigarray.float32_elt) Vector_types.tval create_float64 :
?dev:Device.t ->
int ->
(float, Stdlib.Bigarray.float64_elt) Vector_types.tval create_int32 :
?dev:Device.t ->
int ->
(int32, Stdlib.Bigarray.int32_elt) Vector_types.tval create_int64 :
?dev:Device.t ->
int ->
(int64, Stdlib.Bigarray.int64_elt) Vector_types.tval fill : 'a 'b. ('a, 'b) t -> 'a -> unitFill vector with a value
type sub_meta = Vector_storage.sub_metaval is_sub : ('a, 'b) Vector_types.t -> boolval get_sub_meta : ('a, 'b) Vector_types.t -> Vector_storage.sub_meta optionval sub_vector :
('a, 'b) t ->
start:int ->
len:int ->
?ok_range:int ->
?ko_range:int ->
unit ->
('a, 'b) tCreate a subvector that shares CPU memory with parent.
Partition a vector across multiple devices. Creates subvectors, one per device, that together cover the full vector.
val gather : ('a, 'b) t array -> unitGather subvectors back to parent (sync all to CPU). Assumes subvectors were created by partition and don't overlap.
val depth : ('a, 'b) t -> intGet subvector depth (0 = root, 1 = child, 2 = grandchild, ...)
val parent_id : ('a, 'b) t -> int optionGet parent vector ID if this is a subvector
val sub_start : ('a, 'b) t -> int optionGet start offset relative to immediate parent
val sub_ok_range : ('a, 'b) t -> int optionGet ok_range (safe read range)
val sub_ko_range : ('a, 'b) t -> int optionGet ko_range (unsafe write range)
val iter : 'a 'b. ('a -> unit) -> ('a, 'b) t -> unitIterate over all elements (CPU-side, auto-syncs if needed)
val iteri : 'a 'b. (int -> 'a -> unit) -> ('a, 'b) t -> unitIterate with index
Map function over vector, creating new vector with given kind
Map with index
val map_inplace : 'a 'b. ('a -> 'a) -> ('a, 'b) t -> unitIn-place map (same type)
val fold_left : 'a 'b 'acc. ('acc -> 'a -> 'acc) -> 'acc -> ('a, 'b) t -> 'accFold left
val fold_right : 'a 'b 'acc. ('a -> 'acc -> 'acc) -> ('a, 'b) t -> 'acc -> 'accFold right
val for_all : 'a 'b. ('a -> bool) -> ('a, 'b) t -> boolCheck if all elements satisfy predicate
val exists : 'a 'b. ('a -> bool) -> ('a, 'b) t -> boolCheck if any element satisfies predicate
val find : 'a 'b. ('a -> bool) -> ('a, 'b) t -> 'a optionFind first element satisfying predicate
val find_index : 'a 'b. ('a -> bool) -> ('a, 'b) t -> int optionFind index of first element satisfying predicate
val sum : zero:'a -> add:('a -> 'a -> 'a) -> ('a, 'b) t -> 'aSum elements (requires + operation via fold)
val min_elt : compare:('a -> 'a -> int) -> ('a, 'b) t -> 'a optionFind minimum element
val max_elt : compare:('a -> 'a -> int) -> ('a, 'b) t -> 'a optionFind maximum element
val to_list : 'a 'b. ('a, 'b) t -> 'a listConvert to OCaml list
val of_list : ('a, 'b) Vector_types.kind -> 'a list -> ('a, 'b) Vector_types.tCreate from OCaml list
val to_array : 'a 'b. ('a, 'b) t -> 'a arrayConvert to OCaml array
val of_array :
('a, 'b) Vector_types.kind ->
'a array ->
('a, 'b) Vector_types.tCreate from OCaml array