Sarek_codegen.Sarek_ir_warp_textSource-text lowering of the warp operations, shared by the source backends (CUDA C / HIP, OpenCL C, GLSL, MSL, WGSL).
The semantics are those of Sarek_warp: every lane of the warp participates, and the result for lane i is the table of docs/plans/warp-shuffle-intake-2026-10-17.md section 4.3. The vendors differ in what they leave undefined (an out-of-range delta, the high bits of a lane operand), so no backend passes the Sarek operand to a relative shuffle unguarded:
delta / mask to 0 (which every native relative shuffle maps to "own value") and use the native __shfl_down / __shfl_up / __shfl_xor / __shfl;_relative / _shuffle_up extension, no SHUFFLE_RELATIVE feature bit), and the out-of-range cases are defined by construction.A shuffle is emitted as a call of a small helper function, defined once per (operation, value type) the kernel uses, so an operand expression is evaluated exactly once. The value type is part of the IR name (Sarek_warp.ir_name), so no backend infers expression types.
val value_ctype : dialect -> Sarek_warp.value_type -> stringval helper_name : Sarek_warp.op -> Sarek_warp.value_type -> stringThe name of the helper a shuffle call is emitted as.
val shuffles_of_calls :
Sarek_warp.call list ->
(Sarek_warp.op * Sarek_warp.value_type) listval uses_shuffle : Sarek_warp.call list -> boolWritten once over a tiny syntax record, instantiated for C-like targets, GLSL and WGSL. x is the signed lane operand, lane and w the lane id and the warp width, both unsigned.
val c_syntax : syntaxval cuda_syntax : syntaxval glsl_syntax : syntaxval wgsl_syntax : syntaxval source_lane_expr :
syntax ->
Sarek_warp.op ->
x:string ->
lane:string ->
w:string ->
stringThe unsigned source lane for operation op, operand expression x.
The spelling of a warp operation at its call site.
val constant_expr : dialect -> Sarek_warp.call -> stringwarp_size and lane_id, as int32 expressions.
val emit_call :
dialect ->
bad_arity:(string -> int -> int -> unit) ->
Stdlib.Buffer.t ->
Sarek_warp.call ->
string list ->
unitEmit warp_size, lane_id or a shuffle call. args are the already rendered operand strings; bad_arity raises the backend's located arity error.
val cuda_helper : Sarek_warp.op -> Sarek_warp.value_type -> stringval index_shuffle : dialect -> Sarek_warp.value_type -> src:string -> stringval c_helper : dialect -> Sarek_warp.op -> Sarek_warp.value_type -> stringval glsl_helper : Sarek_warp.op -> Sarek_warp.value_type -> stringval wgsl_helper : Sarek_warp.op -> Sarek_warp.value_type -> stringval helper_source : dialect -> Sarek_warp.op -> Sarek_warp.value_type -> stringval helpers : dialect -> Sarek_warp.call list -> stringThe helper definitions for the shuffles in calls.
val opencl_pragmas : Sarek_warp.call list -> stringOpenCL C extension pragmas for calls: sub-group built-ins, and the shuffle extension when a shuffle is used. Empty when the kernel uses no warp operation.
val glsl_extensions : Sarek_warp.call list -> stringGLSL #extension lines for calls (placed in the header, before any declaration).
The WGSL directive and module-scope state: enable subgroups; must come first in the module; the lane and width are module-scope private variables that main assigns from its subgroup built-ins, so helper functions can read them.