Sarek_ir_typesSarek_ir_types - Pure type definitions for GPU kernel IR
This module contains only type definitions with no external dependencies. Used by spoc_framework for typed generate_source signature.
type elttype = | TInt32| TInt64| TFloat32| TFloat64| TBool| TUnit| TRecord of string * (string * elttype) listRecord type: name and field list
*)| TVariant of string * (string * elttype list) listVariant type: name and constructor list with arg types
*)| TArray of elttype * memspaceArray type with element type and memory space
*)| TVec of elttypeVector (GPU array parameter)
*)Element types
Variables with type info
type expr = | EConst of const| EVar of var| EBinop of binop * expr * expr| EUnop of unop * expr| EArrayRead of string * exprarridx
| EArrayReadExpr of expr * exprbase_expridx for complex bases
| ERecordField of expr * stringr.field
*)| EIntrinsic of string list * string * expr listmodule path, name, args
*)| ECast of elttype * expr| ETuple of expr list| EApp of expr * expr list| ERecord of string * (string * expr) listRecord construction: type name, field values
*)| EVariant of string * string * expr listVariant construction: type name, constructor, args
*)| EArrayLen of stringArray length intrinsic
*)| EArrayCreate of elttype * expr * memspaceelem type, size, memspace
*)| EIf of expr * expr * exprcondition, then, else - value-returning if
*)| EMatch of expr * (pattern * expr) listscrutinee, cases - value-returning match
*)Expressions (pure, no side effects)
type stmt = | SAssign of lvalue * expr| SSeq of stmt list| SIf of expr * stmt * stmt option| SWhile of expr * stmt| SFor of var * expr * expr * for_dir * stmt| SMatch of expr * (pattern * stmt) list| SReturn of expr| SBarrierBlock-level barrier (__syncthreads)
*)| SWarpBarrierWarp-level sync (__syncwarp)
*)| SExpr of exprSide-effecting expression
*)| SEmpty| SLet of var * expr * stmtLet binding: let v = e in body
*)| SLetMut of var * expr * stmtMutable let: let v = ref e in body
*)| SPragma of string list * stmtPragma hints wrapping a statement
*)| SMemFenceMemory fence (threadfence)
*)| SBlock of stmtScoped block - creates a C scope for variable isolation
*)| SNative of {gpu : framework:string -> string;Generate GPU code for framework
*)ocaml : ocaml_closure;Typed OCaml fallback
*)}Inline native GPU code with OCaml fallback
*)Statements (imperative, side effects)
Declarations
Helper function (device function called from kernel)
and native_arg = | NA_Int32 of int32| NA_Int64 of int64| NA_Float32 of float| NA_Float64 of float| NA_Vec of {length : int;elem_size : int;type_name : string;get_f32 : int -> float;set_f32 : int -> float -> unit;get_f64 : int -> float;set_f64 : int -> float -> unit;get_i32 : int -> int32;set_i32 : int -> int32 -> unit;get_i64 : int -> int64;set_i64 : int -> int64 -> unit;get_any : int -> Stdlib.Obj.t;set_any : int -> Stdlib.Obj.t -> unit;get_vec : unit -> Stdlib.Obj.t;}Native argument type for kernel execution. Typed arguments without Obj.t - used by PPX-generated native functions.
and ocaml_closure = {run : block:(int * int * int) ->
grid:(int * int * int) ->
native_arg array ->
unit;}These functions encapsulate the Obj operations so that PPX-generated code doesn't need to use Obj directly. The type parameter is inferred from context.
val vec_get_custom : 'a. native_arg -> int -> 'aGet element from NA_Vec as custom type. Type is inferred from usage.
val vec_set_custom : 'a. native_arg -> int -> 'a -> unitSet element in NA_Vec from custom type. Type is inferred from usage.
val vec_length : native_arg -> intGet length from NA_Vec
val vec_as_vector : 'a. native_arg -> 'aGet underlying vector. Used when passing vectors to functions/intrinsics that need the actual Vector.t type. Returns type-erased value that the caller casts to the appropriate Vector.t type.
type native_fn_t = | NativeFn of parallel:bool ->
block:(int * int * int) ->
grid:(int * int * int) ->
native_arg array ->
unitNative function type for V2 execution. Uses typed native_arg.
type kernel = {kern_name : string;kern_params : decl list;kern_locals : decl list;kern_body : stmt;kern_types : (string * (string * elttype) list) list;Record type definitions: (type_name, (field_name, field_type); ...)
kern_variants : (string * (string * elttype list) list) list;Variant type definitions: (type_name, (constructor_name, payload_types); ...)
kern_funcs : helper_func list;Helper functions defined in kernel scope
*)kern_native_fn : native_fn_t option;Optional pre-compiled native function for CPU execution
*)}Kernel representation