Write CUDA Reduction Kernel

Design CUDA reduction kernels with warp and block reductions.

54|7|Updated Apr 10, 2026
One-click install
npx skills add https://github.com/KrxGu/kernel-skills --skill write-cuda-reduction-kernel
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Write CUDA Reduction Kernel
Source: https://github.com/KrxGu/kernel-skills/tree/main/skills/cuda/write-cuda-reduction-kernel
Command: npx skills add https://github.com/KrxGu/kernel-skills --skill write-cuda-reduction-kernel

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill provides a thorough, reusable approach to implementing correct and efficient CUDA reduction kernels, handling warp-level primitives, block-level reductions, and multi-block strategies to scale to large inputs.

Core Features & Use Cases

  • Warp-level shuffle reductions with explicit masks and non-full-warp handling
  • Block-level reductions using shared memory with correct synchronization
  • Two-pass vs atomic strategies for large inputs and reproducible results
  • Batched and axis-based reductions with proper memory access patterns

Quick Start

Implement a CUDA reduction kernel that reduces a 1D array of floats to a single value using a 256-thread block and a two-pass strategy.

Frequently Asked Questions about Write CUDA Reduction Kernel

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement a CUDA reduction kernel for large arrays?

To implement a CUDA reduction kernel for large arrays, use a two-pass strategy or atomic operations to scale block-level reductions across multiple thread blocks, ensuring proper identity initialization and boundary guards for correctness.

What is the best way to handle warp-level reductions in CUDA?

The best way to handle warp-level reductions in CUDA is using the __shfl_down_sync primitive with an explicit mask, which safely manages non-full warps and ensures accurate final values without shared memory dependencies.

When should I use a two-pass strategy versus atomic operations for GPU reductions?

Use a two-pass strategy for GPU reductions when you need deterministic, reproducible results, and choose atomic operations when prioritizing performance over strict numerical determinism across large input sizes.

How does block-level reduction work with shared memory in CUDA?

Block-level reduction in CUDA works by loading data into shared memory, performing partial reductions across the 256-thread block, and using correct synchronization barriers before the final warp-level shuffle.

Can I perform batched and axis-based reductions using CUDA kernels?

Yes, you can perform batched and axis-based reductions using CUDA kernels by structuring proper memory access patterns, allowing efficient multi-dimensional array processing alongside standard 1D reductions.