cuda-programming
Use when the user asks about a CUDA kernel, nvcc, shared memory tiling, coalesced access, warp divergence, occupancy, CUDA streams or __syncthreads. Produces…
от j4flmao★ 47 звёзд на GitHub
Установить cuda-programming в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
CUDA Programming
Purpose
Write correct, fast CUDA C++ kernels for NVIDIA GPUs. Most kernels are limited by memory bandwidth or latency, not arithmetic, so the work is mostly about access patterns, data reuse in shared memory/registers, and enough parallelism to hide latency. Every optimization must be confirmed with Nsight Compute, not intuition.
Agent Protocol
Trigger
"cuda", "cuda kernel", "nvcc", "gpu programming", "thread block", "shared memory", "warp divergence", "coalesced", "occupancy", "cuda streams", "__syncthreads".
Input Context
- Target GPU / compute capability (e.g. sm_80 A100, sm_90 H100, sm_100 B200).
- CUDA toolkit version, host language, problem sizes and data types.
- Current kernel + profiler output if optimizing.
Output Artifact
Kernel code (.cu) with launch code, error checking, and a profiling plan. No file unless requested.
Response Format
Bound: {memory|compute|latency} (evidence: {ncu metric})
Launch: grid={...} block={...} smem={bytes}
Change: {what and why}
Expected effect: {metric to re-check}
Completion Criteria
- Every CUDA API call and kernel launch error-checked.
- Bounds checks for partial tiles / tails.
- Result validated against a CPU or library reference.
- Bottleneck classified with Nsight Compute before and after the change.
Execution Model
| Level | Facts |
|---|---|
| Thread | Has private registers; spills go to "local" memory (device DRAM, cached in L1/L2). |
| Warp | 32 threads. Scheduler issues one instruction per warp per cycle. Since Volta, threads have independent program counters but divergent paths still execute serially. |
| Block (CTA) | Up to 1024 threads. Shares shared memory; synchronizes with __syncthreads(). Runs on one SM. |
| Cluster (sm_90+) | Group of blocks on a GPC that can access each other's shared memory (distributed shared memory). |
| Grid | All blocks of a launch. No grid-wide barrier except cooperative launch. |
Memory Hierarchy
| Space | Scope | Notes |
|---|---|---|
| Registers | thread | Fastest. Per-thread limit 255. High usage lowers occupancy. |
| Shared memory | block | On-chip SRAM, 32 banks of 4 bytes. Default static limit 48 KB per block; larger requires cudaFuncSetAttribute(..., cudaFuncAttributeMaxDynamicSharedMemorySize, bytes) (up to ~227 KB on H100, ~163 KB on A100). |
| L1 / L2 | SM / device | Hardware caches; L1 shares capacity with shared memory. |
| Global (HBM/GDDR) | device | Hundreds of cycles latency. Bandwidth is the usual limit. |
| Constant | device, cached | Fast only when all threads of a warp read the same address. |
Rules
- Coalesce global access. Consecutive threads of a warp should touch consecutive addresses so a warp load maps to few 32-byte sectors. Structure-of-arrays beats array-of-structures.
- Reuse via shared memory. Load a tile once, use it many times (tiled GEMM/stencils). Pad tiles (
[TILE][TILE+1]) to avoid bank conflicts on column access. - Avoid divergence inside a warp. Branching on
threadIdx.x % 2serializes both paths; branching on warp-uniform values (threadIdx.x / 32) does not. - Occupancy is a means, not a goal. Enough warps to hide latency; higher occupancy past that point rarely helps. Use
cudaOccupancyMaxPotentialBlockSizeas a starting point. - Block size a multiple of 32, usually 128-256.
- Grid-stride loops make kernels correct for any
nand reusable across GPUs. - Minimize host-device transfers; use pinned memory (
cudaMallocHost) andcudaMemcpyAsyncon streams to overlap copy and compute. - Check errors after launches:
cudaGetLastError()for launch errors, a sync (in debug) for execution errors.
Example: Error Checking + Grid-Stride SAXPY
#include <cstdio>
#include <cstdlib>
#include <cuda_runtime.h>
#define CUDA_CHECK(call) \
do { \
cudaError_t err_ = (call); \
if (err_ != cudaSuccess) { \
std::fprintf(stderr, "CUDA error %s at %s:%d: %s\n", #call, __FILE__, \
__LINE__, cudaGetErrorString(err_)); \
std::exit(EXIT_FAILURE); \
} \
} while (0)
__global__ void saxpy(int n, float a, const float* __restrict__ x,
float* __restrict__ y) {
for (int i = blockIdx.x * blockDim.x + threadIdx.x; i < n;
i += blockDim.x * gridDim.x) {
y[i] = a * x[i] + y[i];
}
}
void run_saxpy(int n, float a, const float* d_x, float* d_y, cudaStream_t s) {
int device = 0, sms = 0;
CUDA_CHECK(cudaGetDevice(&device));
CUDA_CHECK(cudaDeviceGetAttribute(&sms, cudaDevAttrMultiProcessorCount, device));
const int block =
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл cuda-programming?
Use when the user asks about a CUDA kernel, nvcc, shared memory tiling, coalesced access, warp divergence, occupancy, CUDA streams or __syncthreads. Produces CUDA C++ kernels with launch config, error checking and an Nsight Compute profiling plan. Not for Triton kernels (use triton-kernels) or PTX/SASS reading (use ptx-assembly).
Как установить скилл cuda-programming?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл cuda-programming запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…