Skip to content

GPU: a warp's builtins (shuffles, ballot, all/any, lane, warp size) - #1101

Closed
ASDAlexander77 wants to merge 2 commits into
mainfrom
gpu-warp
Closed

ASDAlexander77 wants to merge 2 commits into
mainfrom
gpu-warp

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

A warp's builtins

Threads that run together in a warp can now read each other's values directly:

  • gpuWarpSize(), gpuLaneIndex()
  • gpuShuffle(v, lane), gpuShuffleDown(v, d), gpuShuffleUp(v, d), gpuShuffleXor(v, m): v a number of 4 or 8 bytes
  • gpuBallot(p) (an int mask), gpuAll(p), gpuAny(p)

How they work on each GPU

NVIDIA AMD Intel
shuffle shfl.sync.idx over activemask ds_bpermute OpSubgroupShuffleINTEL (SPV_INTEL_subgroups)
ballot vote.sync.ballot amdgcn.ballot (wave32; refused on wave64, e.g. gfx906) sub-group reduce-add of 1 << lane
all / any vote.sync.all/any ballot compared OpGroupAll/Any

Rules

  • A kernel that uses a warp's builtins runs like a gpuBarrier kernel: every thread runs and array writes past n are guarded. Its votes leave out threads past n, and in a shuffle such a thread gives its own value.
  • Its block must be a whole number of warps (a multiple of 32 threads). gpuReduce refuses such a kernel, and calling it on the CPU is an error.
  • The SPIR-V backend reads its extensions only from its -spirv-ext command-line option, so tslang sets that option itself, once per process.

Tested

  • gpu_warp.ts checks every builtin with n = 1000, arrays longer than n, and a shuffle inside an if.
  • gpu_scan.ts computes a prefix sum of 100,000 values from gpuShuffleUp, shared memory and a second launch.
  • All 23 GPU programs pass under the JIT and as executables on an RTX 5080, on Windows and on Linux (WSL).
  • The full Windows ctest passes: 10,481 tests run, none failing. 7 of the GPU tests are new: a compile of every builtin for NVIDIA, AMD and Intel (with spirv-val), plus 5 error tests.
  • AMD and Intel are compile-checked only; this machine has no AMD GPU and its Intel iGPU is turned off.

gpuReduce is unchanged. It already runs close to the cost of a launch, and moving it to shuffles would change the order in which float sums are added.

🤖 Generated with Claude Code

ASDAlexander77 and others added 2 commits December 2, 2026 12:23
… gpuBallot, gpuAll, gpuAny

Stubs lowered per GPU: NVIDIA shfl.sync/vote.sync over activemask, AMD ds_bpermute and ballot (wave32 from
gfx10; gpuBallot refused on wave64), Intel OpSubgroupShuffleINTEL (SPV_INTEL_subgroups, given to the SPIR-V
backend through its -spirv-ext option) and sub-group reduce/all/any. A kernel that uses them runs as a barrier
kernel (every thread; writes past n dropped); its votes leave out the threads past n. Its block must be whole
warps (a multiple of 32), gpuReduce refuses it, and a CPU call is an error. gpu_warp.ts and gpu_scan.ts (a prefix
sum of shuffles and shared memory) pass on the RTX 5080, JIT and exe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…x (WSL) too

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77

Copy link
Copy Markdown
Owner Author

Closing: everything in this PR is already on main. #1103 was stacked on it, and its squash merge (e60ca38) included all of the warp builtin commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant