Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Warp-level programming and SIMD optimization. Use warp shuffle instructions, voting functions, cooperative groups, warp-synchronous algorithms, and minimize warp divergence for optimal GPU performance.
.claude/skills/a5c-ai-warp-primitives/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 67% | 0% |
| case-04 | ✗→✓ | ▲ Improved | 140% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 248% | 0% |
| case-06 | ✗→✓ | ▲ Improved | 161% | 0% |
| case-07 | ✗→✓ | ▲ Improved | 173% | 0% |
You are warp-primitives - a specialized skill for warp-level programming and SIMD optimization on GPUs. This skill provides expert capabilities for low-level GPU performance optimization.
This skill enables AI-powered warp-level programming including:
Data exchange within a warp:
cuda// __shfl_sync: Broadcast from any lane __device__ float warpBroadcast(float val, int srcLane) { return __shfl_sync(0xffffffff, val, srcLane); } // __shfl_up_sync: Shift up (for inclusive scan) __device__ float shflUp(float val, int delta) { return __shfl_up_sync(0xffffffff, val, delta); } // __shfl_down_sync: Shift down (for reduction) __device__ float shflDown(float val, int delta) { return __shfl_down_sync(0xffffffff, val, delta); } // __shfl_xor_sync: Butterfly pattern (for reduction) __device__ float shflXor(float val, int laneMask) { return __shfl_xor_sync(0xffffffff, val, laneMask); } // Warp-level reduction using shuffle __device__ float warpReduceSum(float val) { for (int offset = warpSize / 2; offset > 0; offset >>= 1) { val += __shfl_down_sync(0xffffffff, val, offset); } return val; } // Warp-level reduction using XOR (butterfly) __device__ float warpReduceSumXor(float val) { for (int mask = warpSize / 2; mask > 0; mask >>= 1) { val += __shfl_xor_sync(0xffffffff, val, mask); } return val; // All lanes have result } // Warp-level inclusive scan __device__ float warpInclusiveScan(float val) { for (int offset = 1; offset < warpSize; offset <<= 1) { float n = __shfl_up_sync(0xffffffff, val, offset); if (threadIdx.x % warpSize >= offset) { val += n; } } return val; }
Collective warp operations:
cuda// __ballot_sync: Create bitmask of predicate __device__ unsigned int warpBallot(bool predicate) { return __ballot_sync(0xffffffff, predicate); } // __any_sync: Any thread has true predicate __device__ bool warpAny(bool predicate) { return __any_sync(0xffffffff, predicate); } // __all_sync: All threads have true predicate __device__ bool warpAll(bool predicate) { return __all_sync(0xffffffff, predicate); } // Count set bits in warp __device__ int warpPopcount(bool predicate) { return __popc(__ballot_sync(0xffffffff, predicate)); } // Find position within active threads __device__ int warpExclusiveCount(bool predicate) { unsigned int mask = __ballot_sync(0xffffffff, predicate); unsigned int laneMask = (1u << (threadIdx.x % warpSize)) - 1; return __popc(mask & laneMask); } // Example: Stream compaction within warp __device__ int warpCompact(int* output, int value, bool keep) { unsigned int mask = __ballot_sync(0xffffffff, keep); int total = __popc(mask); if (keep) { int pos = __popc(mask & ((1u << (threadIdx.x % warpSize)) - 1)); output[pos] = value; } return total; }
Flexible synchronization:
cuda#include <cooperative_groups.h> namespace cg = cooperative_groups; // Warp-level cooperative group __device__ void warpOperation(float* data) { cg::thread_block_tile<32> warp = cg::tiled_partition<32>(cg::this_thread_block()); int lane = warp.thread_rank(); float val = data[lane]; // Warp-level reduction for (int offset = warp.size() / 2; offset > 0; offset >>= 1) { val += warp.shfl_down(val, offset); } if (lane == 0) data[0] = val; } // Flexible tile sizes template<int TILE_SIZE> __device__ void tiledOperation(float* data) { cg::thread_block_tile<TILE_SIZE> tile = cg::tiled_partition<TILE_SIZE>(cg::this_thread_block()); float val = data[tile.thread_rank()]; // Tile-level reduction for (int offset = tile.size() / 2; offset > 0; offset >>= 1) { val += tile.shfl_down(val, offset); } if (tile.thread_rank() == 0) { data[tile.meta_group_rank()] = val; } } // Grid-level synchronization (requires cooperative launch) __global__ void gridSyncKernel(float* data, int n) { cg::grid_group grid = cg::this_grid(); // Phase 1 int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < n) data[idx] *= 2.0f; grid.sync(); // Synchronize entire grid // Phase 2 - all blocks see phase 1 results if (idx < n) data[idx] += 1.0f; }
Minimize divergence impact:
cuda// Bad: Divergent branches __global__ void divergentKernel(float* data, int n) { int idx = threadIdx.x + blockIdx.x * blockDim.x; if (idx < n) { if (data[idx] > 0) { // Divergent! data[idx] = expf(data[idx]); // Some threads execute } else { data[idx] = 0.0f; // Other threads execute } } } // Better: Predicated execution __global__ void predicatedKernel(float* data, int n) { int idx = threadIdx.x + blockIdx.x * blockDim.x; if (idx < n) { bool positive = data[idx] > 0; // Both paths computed, result selected float result = positive ? expf(data[idx]) : 0.0f; data[idx] = result; } } // Best: Reorganize data to reduce divergence // Process positive and negative values separately __global__ void reorganizedKernel(float* positive, float* negative, int nPos, int nNeg) { int idx = threadIdx.x + blockIdx.x * blockDim.x; // All threads in warp take same path if (idx < nPos) { positive[idx] = expf(positive[idx]); } } // Warp-level early exit __global__ void warpEarlyExit(float* data, int* flags, int n) { int idx = threadIdx.x + blockIdx.x * blockDim.x; // Check if entire warp can skip bool needsWork = (idx < n) && flags[idx]; if (!__any_sync(0xffffffff, needsWork)) { return; // Entire warp exits } // Only warps with work continue if (needsWork) { data[idx] = expensiveComputation(data[idx]); } }
Implicit warp synchronization:
cuda// Pre-Volta: Implicit warp sync (deprecated pattern) // Post-Volta: Use explicit __syncwarp() __device__ float warpSafeReduce(float val) { // Always use explicit sync mask val += __shfl_down_sync(0xffffffff, val, 16); val += __shfl_down_sync(0xffffffff, val, 8); val += __shfl_down_sync(0xffffffff, val, 4); val += __shfl_down_sync(0xffffffff, val, 2); val += __shfl_down_sync(0xffffffff, val, 1); return val; } // Active mask handling __device__ float activeWarpReduce(float val) { unsigned int active = __activemask(); for (int offset = warpSize / 2; offset > 0; offset >>= 1) { val += __shfl_down_sync(active, val, offset); } return val; } // Match sync for convergent warps __device__ void convergentOperation() { // Ensure threads converge before warp operation unsigned int mask = __match_any_sync(__activemask(), threadIdx.x / 8); // mask contains threads with same value }
Matrix fragments with warp cooperation:
cuda// Warp-level matrix multiply (simplified WMMA concept) __device__ void warpMatMul4x4(float* A, float* B, float* C) { int lane = threadIdx.x % 32; // Each lane owns one element of result int row = lane / 4; int col = lane % 4; float sum = 0.0f; for (int k = 0; k < 4; k++) { // Broadcast A[row][k] and B[k][col] float a = __shfl_sync(0xffffffff, A[row * 4 + k], row * 4 + k); float b = __shfl_sync(0xffffffff, B[k * 4 + col], k * 4 + col); sum += a * b; } C[lane] = sum; }
Identify and fix stall causes:
cuda// Common stall causes and solutions // 1. Memory dependency stalls __global__ void memoryStall(float* data) { int idx = threadIdx.x; float val = data[idx]; // Long latency load // Stall here waiting for data data[idx] = val * 2.0f; } // Solution: Increase occupancy or hide latency __global__ void hiddenLatency(float* data, int n) { int idx = threadIdx.x + blockIdx.x * blockDim.x; // Load multiple values float v1 = data[idx]; float v2 = data[idx + n]; // Compute on v1 while v2 loads v1 = v1 * 2.0f + 1.0f; // Now v2 should be ready v2 = v2 * 2.0f + 1.0f; data[idx] = v1; data[idx + n] = v2; } // 2. Synchronization stalls __global__ void syncStall(float* shared_data) { __shared__ float smem[256]; smem[threadIdx.x] = shared_data[threadIdx.x]; __syncthreads(); // All threads wait here } // Solution: Minimize sync points, use warp-level sync
This skill integrates with the following processes:
warp-efficiency-optimization.js - Warp efficiency workflowreduction-scan-implementation.js - Reduction/scan patternsparallel-algorithm-design.js - Algorithm optimizationjson{ "operation": "generate-warp-reduction", "configuration": { "data_type": "float", "reduction_op": "sum", "use_xor_pattern": true }, "generated_code": "warp_reduction.cu", "analysis": { "shuffle_instructions": 5, "sync_masks": "0xffffffff", "cooperative_groups_used": false }, "performance": { "instructions_per_element": 6, "warp_efficiency": 1.0, "divergence": "none" } }
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→pass | 13,254 | 17,391 | +31% | 1 | 1 | 0% | 2,938 | 4,919 | +67% | 0 | 0 | — |
case-02 | pass→pass | 31,719 | 17,766 | -44% | 1 | 1 | 0% | 5,344 | 6,143 | +15% | 0 | 0 | — |
case-03 | pass→pass | 20,146 | 19,644 | -2% | 1 | 1 | 0% | 3,928 | 6,416 | +63% | 0 | 0 | — |
case-04 | fail→pass | 12,744 | 7,850 | -38% | 1 | 1 | 0% | 1,984 | 4,756 | +140% | 0 | 0 | — |
case-05 | fail→pass | 7,024 | 8,183 | +17% | 1 | 1 | 0% | 1,340 | 4,660 | +248% | 0 | 0 | — |
case-06 | fail→pass | 9,884 | 8,909 | -10% | 1 | 1 | 0% | 1,878 | 4,908 | +161% | 0 | 0 | — |
case-07 | fail→pass | 8,756 | 10,002 | +14% | 1 | 1 | 0% | 1,717 | 4,690 | +173% | 0 | 0 | — |
case-08 | fail→pass | 13,241 | 12,516 | -5% | 1 | 1 | 0% | 2,620 | 5,483 | +109% | 0 | 0 | — |
case-09 | fail→pass | 12,580 | 11,947 | -5% | 1 | 1 | 0% | 2,527 | 5,055 | +100% | 0 | 0 | — |
case-10 | fail→pass | 20,898 | 13,700 | -34% | 1 | 1 | 0% | 4,865 | 5,498 | +13% | 0 | 0 | — |
case-11 | fail→pass | 14,797 | 14,380 | -3% | 1 | 1 | 0% | 3,060 | 6,296 | +106% | 0 | 0 | — |
case-12 | fail→fail | 15,370 | 10,760 | -30% | 1 | 1 | 0% | 2,711 | 5,051 | +86% | 0 | 0 | — |
case-13 | fail→fail | 10,559 | 21,786 | +106% | 1 | 1 | 0% | 2,073 | 6,501 | +214% | 0 | 0 | — |
case-14 | fail→pass | 12,219 | 9,793 | -20% | 1 | 1 | 0% | 2,465 | 5,238 | +112% | 0 | 0 | — |
case-15 | fail→fail | 8,652 | 12,616 | +46% | 1 | 1 | 0% | 1,435 | 5,464 | +281% | 0 | 0 | — |
case-16 | fail→pass | 11,994 | 9,645 | -20% | 1 | 1 | 0% | 2,385 | 5,002 | +110% | 0 | 0 | — |
case-17 | fail→pass | 11,541 | 20,092 | +74% | 1 | 1 | 0% | 2,647 | 6,839 | +158% | 0 | 0 | — |
case-18 | fail→pass | 16,180 | 13,112 | -19% | 1 | 1 | 0% | 2,857 | 5,716 | +100% | 0 | 0 | — |
case-19 | fail→pass | 4,524 | 6,197 | +37% | 1 | 1 | 0% | 972 | 4,414 | +354% | 0 | 0 | — |
case-20 | pass→pass | 17,044 | 13,782 | -19% | 1 | 1 | 0% | 3,482 | 5,981 | +72% | 0 | 0 | — |
case-21 | pass→pass | 22,694 | 16,709 | -26% | 1 | 1 | 0% | 4,625 | 6,591 | +43% | 0 | 0 | — |
case-22 | pass→pass | 6,324 | 6,362 | +1% | 1 | 1 | 0% | 1,211 | 4,416 | +265% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +64 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.