Follow the classic NVIDIA reduction progression. Start with a naive implementation and apply six successive optimizations — from divergent warps to warp shuffle intrinsics.
// PREREQUISITES
// PROJECT PHASES
Divergent reduction (baseline)
Tree reduction with warp divergence.
Bank-conflict-free reduction
Contiguous active threads.
Idle first-step elimination
Load two elements per thread.
Unrolled last warp
Avoid syncthreads when < 32 threads.
Full loop unroll
Template parameter for blockSize.
Warp shuffle reduction
__shfl_down_sync replaces shared memory.
// SANDBOX
GPU execution// EXPECTED OUTPUT
Reduce0 (divergent): 18.4 ms 22.9 GB/s Reduce5 (shuffle): 2.5 ms 168.4 GB/s
// YOUR PROGRESS
Log in to save progress
// DETAILS
// MORE IN ALGORITHMS
// LEARN THE THEORY
Algorithms concepts