Module Sarek_opencl.Sarek_ir_opencl

Constants

val small_buffer_size : int

Buffer size for small temporary string buffers

val large_buffer_size : int

Buffer size for large code generation buffers

val format_float : float -> string

Format float with full precision (17 digits for double precision)

val current_device : Spoc_core.Device.t option Stdlib.ref

Current device for SNative code generation (set during generate_for_device)

val current_variants : (string * (string * Sarek_ir_types.elttype list) list) list Stdlib.ref

Current kernel's variant definitions (set during generate)

Type Mapping

val mangle_name : string -> string

Mangle OCaml type name to valid C identifier (e.g., "Module.point" -> "Module_point")

val opencl_type_of_elttype : Sarek_ir_types.elttype -> string

Map Sarek IR element type to OpenCL C type string

val opencl_memspace : Sarek_ir_types.memspace -> string

Map memory space to OpenCL qualifier

val opencl_param_type : Sarek_ir_types.elttype -> string

Map Sarek IR element type to OpenCL C type for kernel parameters

Thread Intrinsics

val opencl_thread_intrinsic : string -> string

Expression Generation

val gen_expr : Stdlib.Buffer.t -> Sarek_ir_types.expr -> unit
val gen_binop : Sarek_ir_types.binop -> string
val gen_unop : Sarek_ir_types.unop -> string
val gen_intrinsic : Stdlib.Buffer.t -> string list -> string -> Sarek_ir_types.expr list -> unit

L-value Generation

val gen_lvalue : Stdlib.Buffer.t -> Sarek_ir_types.lvalue -> unit

Statement Generation

val gen_stmt : Stdlib.Buffer.t -> string -> Sarek_ir_types.stmt -> unit
val gen_match_case : Stdlib.Buffer.t -> string -> string -> Sarek_ir_types.pattern -> Sarek_ir_types.stmt -> unit

Generate a pattern match case (extracted helper)

val gen_array_decl : Stdlib.Buffer.t -> string -> Sarek_ir_types.var -> Sarek_ir_types.elttype -> Sarek_ir_types.expr -> Sarek_ir_types.memspace -> Sarek_ir_types.stmt -> unit

Generate array declaration with optional __local qualifier (extracted helper)

Declaration Generation

val is_vec_type : Sarek_ir_types.elttype -> bool

Check if a type is a vector (requires length parameter)

val gen_param : Stdlib.Buffer.t -> Sarek_ir_types.decl -> unit
val gen_local : Stdlib.Buffer.t -> string -> Sarek_ir_types.decl -> unit

Helper Function Generation

val gen_helper_func : Stdlib.Buffer.t -> Sarek_ir_types.helper_func -> unit

Generate a helper function (OpenCL device function)

Kernel Generation

val generate : Sarek_ir_types.kernel -> string

Generate complete OpenCL source for a kernel

val generate_for_device : device:Spoc_core.Device.t -> Sarek_ir_types.kernel -> string

Generate complete OpenCL source with device context for SNative

val gen_variant_def : Stdlib.Buffer.t -> (string * (string * Sarek_ir_types.elttype list) list) -> unit

Generate variant type definition for OpenCL

val generate_with_types : types:(string * (string * Sarek_ir_types.elttype) list) list -> Sarek_ir_types.kernel -> string

Generate OpenCL source with custom type definitions

val generate_with_fp64 : Sarek_ir_types.kernel -> string

Generate OpenCL source with double precision extension if needed