(This blog post is an experimental entry).

Wave intrinsics are a powerful set of HLSL functions that enable direct communication between threads within a wave - the fundamental execution unit in modern GPU architectures. Unlike traditional GPU programming where threads operate in isolation, wave intrinsics let you leverage the fact that groups of threads (typically 32-64) execute in lockstep, opening up new possibilities for optimization and algorithm design.


What is a Wave?

A wave (also called a warp in NVIDIA terminology or wavefront in AMD terminology) is a collection of threads that execute simultaneously on a GPU’s SIMD (Single Instruction, Multiple Data) units. Wave intrinsics expose this hardware-level parallelism directly to shader code, allowing threads to share data and coordinate without expensive memory operations.

Basic Wave Operations

// Get the size of the current wave (typically 32 or 64)
uint waveSize = WaveGetLaneCount();

// Get this thread's index within the wave
uint laneIndex = WaveGetLaneIndex();

// Check if all threads in the wave meet a condition
bool allThreadsReady = WaveActiveAllTrue(isReady);

// Sum values across all lanes in the wave
float waveSum = WaveActiveSum(localValue);

A Practical Example: Fast Reduction

// Traditional approach: write to shared memory, synchronize, read back
// Wave intrinsic approach: direct thread communication, no memory needed

float ComputeBlockAverage(float threadValue)
{
    // Sum across all threads in the wave
    float waveSum = WaveActiveSum(threadValue);
    
    // Get the count of active lanes
    uint activeCount = WaveActiveCountBits(true);
    
    // First lane returns the average
    return waveSum / (float)activeCount;
}

Wave intrinsics shine in scenarios like parallel reductions, prefix sums, ballot operations, and any algorithm where neighboring threads need to share data quickly. They’re particularly valuable in compute shaders for optimizing algorithms that would otherwise require shared memory and barriers.


<
Blog Archive
Archive of all previous blog posts
>
Next Post
Optimizing 3DGS to train in seconds