Module Spoc_framework.Framework_sig

Common Types

type dims = {
  1. x : int;
  2. y : int;
  3. z : int;
}

3D dimensions for grid and block

val dims_1d : int -> dims
val dims_2d : int -> int -> dims
val dims_3d : int -> int -> int -> dims
type capabilities = {
  1. max_threads_per_block : int;
  2. max_block_dims : int * int * int;
  3. max_grid_dims : int * int * int;
  4. shared_mem_per_block : int;
  5. total_global_mem : int64;
  6. compute_capability : int * int;
    (*

    (major, minor) for CUDA, (0,0) for OpenCL

    *)
  7. supports_fp64 : bool;
  8. supports_atomics : bool;
  9. warp_size : int;
  10. max_registers_per_block : int;
  11. clock_rate_khz : int;
  12. multiprocessor_count : int;
  13. is_cpu : bool;
    (*

    True for CPU devices - enables zero-copy optimization

    *)
}

Device capabilities - queried from hardware

type device = {
  1. id : int;
    (*

    Global device ID (0, 1, 2...)

    *)
  2. backend_id : int;
    (*

    ID within the backend (0, 1...)

    *)
  3. name : string;
    (*

    Human-readable device name

    *)
  4. framework : string;
    (*

    Backend name: "CUDA", "OpenCL", "Vulkan", "Native"

    *)
  5. capabilities : capabilities;
}

Device representation - SDK layer type shared across all backends

Plugin Module Signature

module type S = sig ... end

Minimal framework signature for plugin registration. Used by Framework_registry for basic plugin management.

type execution_model =
  1. | JIT
  2. | Direct
  3. | Custom

Execution model for backends.

  • JIT: Generate source code at runtime, compile with GPU compiler (CUDA, OpenCL)
  • Direct: Execute pre-compiled OCaml functions directly (Native CPU)
  • Custom: Full control over compilation pipeline (LLVM, SPIR-V, future)
type source_lang =
  1. | CUDA_Source
    (*

    CUDA C/C++ source (.cu)

    *)
  2. | OpenCL_Source
    (*

    OpenCL C source (.cl)

    *)
  3. | PTX
    (*

    NVIDIA PTX assembly

    *)
  4. | SPIR_V
    (*

    SPIR-V binary

    *)
  5. | GLSL_Source
    (*

    Vulkan GLSL compute shader

    *)

Source language for external kernels

type kargs = ..

Extensible type for backend-specific kernel arguments. Each backend extends this type with its own variant. This allows type-safe passing of kernel args across the framework boundary without Obj.t.

type kargs +=
  1. | No_kargs

Placeholder kargs for testing - not associated with any backend

type run_source_arg =
  1. | RSA_Buffer of {
    1. binder : kargs -> int -> unit;
      (*

      Binds buffer to kernel arg

      *)
    2. length : int;
      (*

      Vector length for generated kernels

      *)
    }
  2. | RSA_Int32 of int32
  3. | RSA_Int64 of int64
  4. | RSA_Float32 of float
  5. | RSA_Float64 of float

Argument type for run_source. Buffer binder receives typed kargs.

type convergence =
  1. | Uniform
  2. | Divergent
  3. | Sync

Convergence behavior of an intrinsic.

  • Uniform: All threads in warp/wavefront compute same value
  • Divergent: Threads may compute different values
  • Sync: Intrinsic contains synchronization (barrier)
module type INTRINSIC_REGISTRY = sig ... end

Intrinsic registry interface for backend-specific intrinsics. Note: The actual intrinsic_impl type is defined in each backend's intrinsic registry module to avoid circular dependencies with Sarek_ir.

type exec_arg = Typed_value.exec_arg =
  1. | EA_Int32 of int32
  2. | EA_Int64 of int64
  3. | EA_Float32 of float
  4. | EA_Float64 of float
  5. | EA_Scalar : (module Typed_value.SCALAR_TYPE with type t = 'a) * 'a -> exec_arg
  6. | EA_Composite : (module Typed_value.COMPOSITE_TYPE with type t = 'a) * 'a -> exec_arg
  7. | EA_Vec of (module Typed_value.EXEC_VECTOR)

Re-export typed value types for convenience

module type BACKEND = sig ... end

Extended backend signature for Phase 4 unified execution. Adds execution model discrimination and IR-based code generation.