Module Sarek_ppx_lib.Sarek_native_intrinsics

Type Mapping

val core_type_of_typ : loc:Ppxlib.location -> Sarek_types.typ -> Ppxlib.core_type

Generate a core type from a Sarek type (for type annotations).

For scalar types (int32, float, etc), we generate explicit types to help OCaml infer the correct numeric type.

For record types, we generate the type name to help OCaml resolve field accesses. The type name may be qualified (e.g., "Module.point").

For vectors and other complex types, we use wildcards.

Intrinsic Mapping

Map Sarek intrinsics to their OCaml equivalents. For cpu_kern, we call the OCaml implementations directly rather than generating GPU code.

type gen_mode =
  1. | FullMode
    (*

    Standard mode - uses thread_state for all indices

    *)
  2. | Simple1DMode
    (*

    Simple 1D - gid_x passed directly as int32

    *)
  3. | Simple2DMode
    (*

    Simple 2D - gid_x, gid_y passed directly

    *)
  4. | Simple3DMode
    (*

    Simple 3D - gid_x, gid_y, gid_z passed directly

    *)

Kernel generation mode for simple vs full execution - defined early for use below

val simple_gid_x : string

Variable names for simple mode global indices

val simple_gid_y : string
val simple_gid_z : string
val map_stdlib_path : string list -> string list

Map stdlib module paths to their runtime module paths. Sarek stdlib modules are available at both "Foo" and "Sarek_stdlib.Foo" paths at compile time. At runtime, the corresponding CPU implementations are in Sarek_cpu_runtime.

val gen_intrinsic_const : loc:Ppxlib__.Location.t -> gen_mode:gen_mode -> Sarek_env.intrinsic_ref -> Ppxlib_ast.Ast.expression

Generate intrinsic constant based on generation mode. For simple modes, direct global indices are used. For full mode, we access thread_state.

val gen_intrinsic_fun : loc:Ppxlib__.Location.t -> gen_mode:gen_mode -> Sarek_env.intrinsic_ref -> Ppxlib__.Import.expression list -> Ppxlib__.Import.expression

Generate intrinsic function call based on generation mode. For simple modes, we use thread_state for most operations. stdlib functions are called directly from their runtime implementations.