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
| Function | WGSL 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.xin WGSL. - global_
thread_ id_ y - Get the global thread ID in the y-dimension.
Maps to
global_invocation_id.yin WGSL. - global_
thread_ id_ z - Get the global thread ID in the z-dimension.
Maps to
global_invocation_id.zin 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_idbuiltin 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 vec4where 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_sizebuiltin in WGSL.