Module Sarek_ppx_lib.Sarek_ir_ppx

type memspace =
  1. | Global
  2. | Shared
  3. | Local

Memory spaces

type elttype =
  1. | TInt32
  2. | TInt64
  3. | TFloat32
  4. | TFloat64
  5. | TBool
  6. | TUnit
  7. | TRecord of string * (string * elttype) list
  8. | TVariant of string * (string * elttype list) list
  9. | TArray of elttype * memspace
  10. | TVec of elttype

Element types

type var = {
  1. var_name : string;
  2. var_id : int;
  3. var_type : elttype;
  4. var_mutable : bool;
}

Variables with type info

type const =
  1. | CInt32 of int32
  2. | CInt64 of int64
  3. | CFloat32 of float
  4. | CFloat64 of float
  5. | CBool of bool
  6. | CUnit

Constants

type binop =
  1. | Add
  2. | Sub
  3. | Mul
  4. | Div
  5. | Mod
  6. | Eq
  7. | Ne
  8. | Lt
  9. | Le
  10. | Gt
  11. | Ge
  12. | And
  13. | Or
  14. | Shl
  15. | Shr
  16. | BitAnd
  17. | BitOr
  18. | BitXor

Binary operators

type unop =
  1. | Neg
  2. | Not
  3. | BitNot

Unary operators

type for_dir =
  1. | Upto
  2. | Downto

Loop direction

type pattern =
  1. | PConstr of string * string list
  2. | PWild

Match pattern

type expr =
  1. | EConst of const
  2. | EVar of var
  3. | EBinop of binop * expr * expr
  4. | EUnop of unop * expr
  5. | EArrayRead of string * expr
  6. | EArrayReadExpr of expr * expr
  7. | ERecordField of expr * string
  8. | EIntrinsic of string list * string * expr list
  9. | ECast of elttype * expr
  10. | ETuple of expr list
  11. | EApp of expr * expr list
  12. | ERecord of string * (string * expr) list
  13. | EVariant of string * string * expr list
  14. | EArrayLen of string
  15. | EArrayCreate of elttype * expr * memspace
    (*

    elem type, size, memspace

    *)
  16. | EIf of expr * expr * expr
  17. | EMatch of expr * (pattern * expr) list

Expressions (pure, no side effects)

type lvalue =
  1. | LVar of var
  2. | LArrayElem of string * expr
  3. | LArrayElemExpr of expr * expr
  4. | LRecordField of lvalue * string

L-values (assignable locations)

type stmt =
  1. | SAssign of lvalue * expr
  2. | SSeq of stmt list
  3. | SIf of expr * stmt * stmt option
  4. | SWhile of expr * stmt
  5. | SFor of var * expr * expr * for_dir * stmt
  6. | SMatch of expr * (pattern * stmt) list
  7. | SReturn of expr
  8. | SBarrier
  9. | SWarpBarrier
  10. | SExpr of expr
  11. | SEmpty
  12. | SLet of var * expr * stmt
  13. | SLetMut of var * expr * stmt
  14. | SPragma of string list * stmt
  15. | SMemFence
  16. | SBlock of stmt
    (*

    Scoped block for C variable isolation

    *)
  17. | SNative of {
    1. gpu : Ppxlib.expression;
      (*

      fun dev -> "cuda/opencl code"

      *)
    2. ocaml : Ppxlib.expression;
      (*

      OCaml fallback for interpreter/native

      *)
    }
    (*

    Inline native GPU code with OCaml fallback

    *)

Statements (imperative, side effects)

type array_info = {
  1. arr_elttype : elttype;
  2. arr_memspace : memspace;
}

Array info for parameters

type decl =
  1. | DParam of var * array_info option
  2. | DLocal of var * expr option
  3. | DShared of string * elttype * expr option

Declarations

type helper_func = {
  1. hf_name : string;
  2. hf_params : var list;
  3. hf_ret_type : elttype;
  4. hf_body : stmt;
}

Helper function (device function called from kernel)

type kernel = {
  1. kern_name : string;
  2. kern_params : decl list;
  3. kern_locals : decl list;
  4. kern_body : stmt;
  5. kern_types : (string * (string * elttype) list) list;
    (*

    Record type definitions: (type_name, (field_name, field_type); ...)

    *)
  6. kern_variants : (string * (string * elttype list) list) list;
    (*

    Variant type definitions: (type_name, (constructor_name, payload_types); ...)

    *)
  7. kern_funcs : helper_func list;
    (*

    Helper functions defined in kernel scope

    *)
  8. kern_native_fn : unit option;
    (*

    Placeholder for native function - actual function added during quoting

    *)
}

Kernel representation