Skip to main content

Module dsl

Module dsl 

Source
Expand description

DSL marker functions for WGSL code generation.

These functions are compile-time markers that the transpiler recognizes and converts to WGSL intrinsics. They do nothing at Rust compile time.

Common functions (thread indices, basic math, synchronization) are shared with the CUDA backend via ringkernel_codegen::dsl_common.

§Thread/Workgroup Indices

FunctionWGSL Equivalent
thread_idx_x()local_invocation_id.x
thread_idx_y()local_invocation_id.y
thread_idx_z()local_invocation_id.z
block_idx_x()workgroup_id.x
block_idx_y()workgroup_id.y
block_idx_z()workgroup_id.z
block_dim_x()WORKGROUP_SIZE_X (constant)
global_thread_id()global_invocation_id.x

Functions§

abs
Absolute value. Maps to abs(x) in WGSL.
atomic_add
Atomic add. Maps to atomicAdd(&var, value) in WGSL.
atomic_cas
Atomic compare-and-swap. Maps to atomicCompareExchangeWeak(&var, compare, value) in WGSL. Returns the old value.
atomic_exchange
Atomic exchange. Maps to atomicExchange(&var, value) in WGSL.
atomic_load
Atomic load. Maps to atomicLoad(&var) in WGSL.
atomic_max
Atomic maximum. Maps to atomicMax(&var, value) in WGSL.
atomic_min
Atomic minimum. Maps to atomicMin(&var, value) in WGSL.
atomic_store
Atomic store. Maps to atomicStore(&var, value) in WGSL.
atomic_sub
Atomic subtract. Maps to atomicSub(&var, value) in WGSL.
block_dim_x
Get the block/workgroup dimension (x dimension).
block_dim_y
Get the block/workgroup dimension (y dimension).
block_dim_z
Get the block/workgroup dimension (z dimension).
block_idx_x
Get the block/workgroup index (x dimension).
block_idx_y
Get the block/workgroup index (y dimension).
block_idx_z
Get the block/workgroup index (z dimension).
ceil
Ceiling.
clamp
Clamp. Maps to clamp(x, lo, hi) in WGSL.
cos
Cosine.
exp
Exponential (base e).
floor
Floor.
fma
Fused multiply-add: a * b + c.
global_thread_id
Get the global thread ID (x-component). Maps to global_invocation_id.x in WGSL.
global_thread_id_y
Get the global thread ID in the y-dimension. Maps to global_invocation_id.y in WGSL.
global_thread_id_z
Get the global thread ID in the z-dimension. Maps to global_invocation_id.z in WGSL.
grid_dim_x
Get the grid/dispatch dimension (x dimension).
grid_dim_y
Get the grid/dispatch dimension (y dimension).
grid_dim_z
Get the grid/dispatch dimension (z dimension).
lane_id
Get the lane ID within the subgroup. Maps to subgroup_invocation_id builtin in WGSL.
log
Natural logarithm (base e).
max
Maximum. Maps to max(a, b) in WGSL.
min
Minimum. Maps to min(a, b) in WGSL.
mix
Linear interpolation. Maps to mix(a, b, t) in WGSL.
powf
Power: x^y.
round
Round to nearest.
rsqrt
Reciprocal square root.
sin
Sine.
sqrt
Square root.
sync_threads
Synchronize all threads in a block/workgroup.
tan
Tangent.
thread_fence
Thread/storage memory fence.
thread_fence_block
Block-level/workgroup memory fence.
thread_idx_x
Get the thread index within a block/workgroup (x dimension).
thread_idx_y
Get the thread index within a block/workgroup (y dimension).
thread_idx_z
Get the thread index within a block/workgroup (z dimension).
warp_all
Check if all lanes in subgroup satisfy predicate. Maps to subgroupAll(predicate) in WGSL.
warp_any
Check if any lane in subgroup satisfies predicate. Maps to subgroupAny(predicate) in WGSL.
warp_ballot
Ballot within subgroup. Maps to subgroupBallot(predicate) in WGSL. Returns a vec4 where each bit represents a lane’s predicate.
warp_shuffle
Shuffle within subgroup. Maps to subgroupShuffle(value, lane) in WGSL. Requires: enable chromium_experimental_subgroups;
warp_shuffle_down
Shuffle down within subgroup. Maps to subgroupShuffleDown(value, delta) in WGSL.
warp_shuffle_up
Shuffle up within subgroup. Maps to subgroupShuffleUp(value, delta) in WGSL.
warp_shuffle_xor
Shuffle XOR within subgroup. Maps to subgroupShuffleXor(value, mask) in WGSL.
warp_size
Get the subgroup size. Maps to subgroup_size builtin in WGSL.