Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

cuda

БесплатноБез исполняемых скриптовНе проверен

CUDA C/C++ skill for NVIDIA GPU kernel programming. Use when writing CUDA kernels, managing thread/block/grid hierarchy, optimizing memory access patterns…

mohitmishra786от mohitmishra786★ 307 звёзд на GitHub

Об этом скилле

CUDA

Purpose

Guide agents through NVIDIA CUDA C/C++ development: kernel launch configuration, the memory hierarchy from registers through global memory, asynchronous execution with streams, nvcc compilation flags, Thrust library usage, and diagnosing common performance pitfalls like warp divergence and uncoalesced memory access.

Triggers

  • Writing or optimizing a CUDA kernel for matrix multiply, reduction, or stencil operations
  • Choosing block/grid dimensions and estimating occupancy
  • Debugging slow kernels due to memory access patterns or low occupancy
  • Setting up multi-stream pipelines with async cudaMemcpyAsync
  • Compiling with nvcc and selecting architecture flags for CUDA 13 (-gencode, sm_100a)
  • Using Thrust for parallel primitives instead of hand-written kernels

Workflow

1. Minimal kernel and launch

CUDA organizes work as threads grouped into blocks, blocks grouped into a grid.

Thread hierarchy
├── grid (1D/2D/3D)
│   └── block (1D/2D/3D, max 1024 threads)
│       └── thread (threadIdx, blockIdx, blockDim, gridDim)
// vector_add.cu
#include <cuda_runtime.h>
#include <stdio.h>

__global__ void vector_add(const float *a, const float *b, float *c, int n) {
    int i = blockIdx.x * blockDim.x + threadIdx.x;
    if (i < n)
        c[i] = a[i] + b[i];
}

int main(void) {
    const int n = 1 << 20;
    size_t bytes = n * sizeof(float);
    float *h_a, *h_b, *h_c, *d_a, *d_b, *d_c;

    cudaMalloc(&d_a, bytes);
    cudaMalloc(&d_b, bytes);
    cudaMalloc(&d_c, bytes);
    // ... host init and cudaMemcpy H2D ...

    int threads = 256;
    int blocks = (n + threads - 1) / threads;
    vector_add<<<blocks, threads>>>(d_a, d_b, d_c, n);
    cudaDeviceSynchronize();

    cudaMemcpy(h_c, d_c, bytes, cudaMemcpyDeviceToHost);
    cudaFree(d_a); cudaFree(d_b); cudaFree(d_c);
    return 0;
}

2. Memory hierarchy

Memory Scope Latency Typical use
Registers Per-thread ~1 cycle Local scalars, loop indices
Shared (__shared__) Per-block ~5 cycles Tile data, halo exchange
Global All threads ~400+ cycles Large arrays, coalesced access
Constant (__constant__) Read-only, cached Fast broadcast Kernel parameters, lookup tables
Texture Cached 2D access Cached Image sampling, irregular reads

Shared memory example (matrix tile):

#define TILE 16

__global__ void matmul_tiled(const float *A, const float *B, float *C, int N) {
    __shared__ float As[TILE][TILE];
    __shared__ float Bs[TILE][TILE];

    int row = blockIdx.y * TILE + threadIdx.y;
    int col = blockIdx.x * TILE + threadIdx.x;
    float sum = 0.0f;

    for (int t = 0; t < (N + TILE - 1) / TILE; t++) {
        As[threadIdx.y][threadIdx.x] = (row < N && t * TILE + threadIdx.x < N)
            ? A[row * N + t * TILE + threadIdx.x] : 0.0f;
        Bs[threadIdx.y][threadIdx.x] = (col < N && t * TILE + threadIdx.y < N)
            ? B[(t * TILE + threadIdx.y) * N + col] : 0.0f;
        __syncthreads();

        for (int k = 0; k < TILE; k++)
            sum += As[threadIdx.y][k] * Bs[k][threadIdx.x];
        __syncthreads();
    }
    if (row < N && col < N)
        C[row * N + col] = sum;
}

3. Streams and async copies

cudaStream_t stream1, stream2;
cudaStreamCreate(&stream1);
cudaStreamCreate(&stream2);

cudaMemcpyAsync(d_a, h_a, bytes, cudaMemcpyHostToDevice, stream1);
cudaMemcpyAsync(d_b, h_b, bytes, cudaMemcpyHostToDevice, stream2);
vector_add<<<blocks, threads, 0, stream1>>>(d_a, d_b, d_c, n);
cudaMemcpyAsync(h_c, d_c, bytes, cudaMemcpyDeviceToHost, stream1);
cudaStreamSynchronize(stream1);

Pinned host memory (cudaMallocHost) enables true async DMA overlap with kernel execution.

4. nvcc compilation

CUDA 13 (current: 13.5) supports compute capability 7.5 and newer. Maxwell, Pascal and Volta (sm_50–sm_72) were removed: nvcc -arch=sm_70 fails with Unsupported gpu architecture 'sm_70'. Keep a CUDA 12.x toolkit for those GPUs. Drivers from the R580 branch run CUDA 13.x applications through minor version compatibility, with limits (for example PTX JIT of newer PTX can fail); CUDA 13.5 features and newly enabled platforms need an R620 or later driver. From 13.4 on, the Linux toolkit no longer bundles the driver.

Compute capability GPUs nvcc target
7.5 Turing (T4, RTX 20) sm_75
8.0 / 8.6 / 8.7 / 8.9 Ampere (A100, RTX 30, Orin), Ada (L4, RTX 40) sm_80, sm_86, sm_87, sm_89
9.0 Hopper (H100/H200) sm_90 (sm_90a for wgmma)
10.0 / 10.3 / 11.0 Blackwell datacenter (B200, B300), Thor sm_100, sm_103, sm_110
10.7 Rubin compute_107 (listed by nvcc 13.5)
12.0 / 12.1 Blackwell consumer (RTX 50, RTX PRO), DGX Spark sm_120, sm_121

nvcc --list-gpu-arch prints what the installed toolkit accepts. Suffixes: sm_100a uses architecture-specific instructions (run

Полный SKILL.md на GitHub

Установить cuda в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл cuda?

CUDA C/C++ skill for NVIDIA GPU kernel programming. Use when writing CUDA kernels, managing thread/block/grid hierarchy, optimizing memory access patterns, using streams and async copies, configuring nvcc flags, or integrating Thrust. Activates on queries about CUDA kernels, nvcc, shared memory, warp divergence, occupancy, or Thrust.

Как установить скилл cuda?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл cuda запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить cuda с