Skip to content

Commit 6894f7e

Browse files
grissom.wangclaude
andcommitted
feat(cuda-samples): bump submodule to v13.4, re-anchor moved samples
Upstream tagged v13.4 and removed the basic library samples (simpleCUBLAS, batchCUBLAS, simpleCUFFT, conjugateGradient, histEqualizationNPP) and split simpleCudaGraphs into _capture/_explicit variants. Re-anchored references to the surviving v13.4 samples: conjugateGradientCudaGraphs (cuBLAS+cuSPARSE under graph capture), conjugateGradientMultiBlockCG, oceanFFT, and the new CCCL 3.3 CUB samples (cubDeviceFind/SegmentedScan/Transform). Source stats updated (319 C++ files, ~121K lines, 35 Python samples); all 51 curated paths re-verified. Co-Authored-By: Claude Code <noreply@anthropic.com>
1 parent a11809e commit 6894f7e

5 files changed

Lines changed: 76 additions & 80 deletions

File tree

‎CLAUDE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ cuda-optimizer (orchestrator)
188188
└── cuda-code-generator → generate/rewrite .cu files with optimizations
189189
```
190190

191-
`cuda-knowledge` (~1170 markdown files) provides API reference based on CUDA Toolkit 13.4 (PTX ISA 9.4, cuBLAS 13.4, Runtime/Driver/Math API 13.4); `cuda-samples` (SKILL.md ~13 KB, 10 reference files 48 KB; ~50 curated entries) provides concrete working code patterns from official NVIDIA samples with GitHub permalinks and key snippets. Both follow progressive disclosure: lightweight SKILL.md stays in context, detailed references load on demand. All three action skills ground their work in both to reduce hallucination. The optimizer drives this loop: **benchmark → evaluate exit conditions → NCU profile → implement optimizations → repeat** until performance converges (<2% improvement over 2 consecutive rounds).
191+
`cuda-knowledge` (~1170 markdown files) provides API reference based on CUDA Toolkit 13.4 (PTX ISA 9.4, cuBLAS 13.4, Runtime/Driver/Math API 13.4); `cuda-samples` (SKILL.md ~16 KB, 10 reference files 68 KB; 52 curated entries) provides concrete working code patterns from official NVIDIA samples with GitHub permalinks and key snippets. Both follow progressive disclosure: lightweight SKILL.md stays in context, detailed references load on demand. All three action skills ground their work in both to reduce hallucination. The optimizer drives this loop: **benchmark → evaluate exit conditions → NCU profile → implement optimizations → repeat** until performance converges (<2% improvement over 2 consecutive rounds).
192192

193193
### Kernel Interface Convention
194194

‎cuda-samples‎

Submodule cuda-samples updated 871 files

‎skills/cuda-samples/SKILL.md‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Curated index of ~65 official [NVIDIA CUDA Samples](https://github.com/NVIDIA/cu
99

1010
**Usage**: Search this file by pattern name (e.g., "reduction", "GEMM", "graph capture") or API name (e.g., "cublasSgemm", "cudaMallocAsync"). When a match is found, follow the GitHub permalink for the full implementation.
1111

12-
**Source**: NVIDIA/cuda-samples (CUDA Toolkit 13.3), 375 C++ files (189 `.cu` + 186 `.cpp`), ~139K lines; 35 Python samples.
12+
**Source**: NVIDIA/cuda-samples (CUDA Toolkit 13.4, tag v13.4), 319 C++ files (175 `.cu` + 144 `.cpp`), ~121K lines; 35 Python samples.
1313

1414
---
1515

@@ -44,11 +44,11 @@ Curated index of ~65 official [NVIDIA CUDA Samples](https://github.com/NVIDIA/cu
4444
| Graph with updates | Graphs | `jacobiCudaGraphs` | — |
4545
| Graph memory nodes | Graphs | `graphMemoryNodes` | — |
4646
| Conditional graph nodes | Graphs | `graphConditionalNodes` | — |
47-
| cuBLAS GEMM | Libraries | `simpleCUBLAS` | — |
48-
| Batched cuBLAS GEMM | Libraries | `batchCUBLAS` | — |
47+
| CUB device-wide find (CCCL 3.3) | Libraries | `cubDeviceFind` | — |
48+
| CUB segmented scan | Libraries | `cubDeviceSegmentedScan` | — |
4949
| cuBLAS with CUDA Graphs | Libraries | `conjugateGradientCudaGraphs` | — |
50-
| Conjugate Gradient (cuBLAS+cuSPARSE) | Libraries | `conjugateGradient` | — |
51-
| cuFFT convolution | Libraries | `simpleCUFFT` | `fftSignalAnalysis` |
50+
| Conjugate Gradient (pure CUDA) | Libraries | `conjugateGradientMultiBlockCG` | — |
51+
| cuFFT 2D ocean simulation | Libraries | `oceanFFT` | `fftSignalAnalysis` |
5252
| Matrix transpose | Performance | `transpose` | — |
5353
| Block size tuning | Performance | — | `launchConfigTuning` |
5454
| Warp-aggregated atomics | Performance | `warpAggregatedAtomicsCG` | — |
@@ -59,7 +59,7 @@ Curated index of ~65 official [NVIDIA CUDA Samples](https://github.com/NVIDIA/cu
5959
| JIT LTO linking | Advanced | — | `jitLtoLinking` |
6060
| NVTX profiling markers | Profiling | — | `kernelNsysProfile` |
6161
| Green context (SM partitioning) | Advanced | — | `greenContext` |
62-
| Image processing (NPP) | Libraries | `histEqualizationNPP` | — |
62+
| CUB device-wide transform | Libraries | `cubDeviceTransform` | — |
6363
| CUB device find (libcu++) | Libraries | `cubDeviceFind` | — |
6464
| CUB device segmented scan (libcu++) | Libraries | `cubDeviceSegmentedScan` | — |
6565
| CUB device transform (libcu++) | Libraries | `cubDeviceTransform` | — |
@@ -84,7 +84,7 @@ The table above is a fast lookup index. Detailed code snippets and patterns for
8484
| Reduction, Scan & Sort | [samples-reduction-scan-sort.md](references/samples-reduction-scan-sort.md) | reduction (C++/Python), reductionMultiBlockCG, shfl_scan, radixSortThrust, parallelReduction |
8585
| Tensor Core GEMM | [samples-tensor-core-gemm.md](references/samples-tensor-core-gemm.md) | cudaTensorCoreGemm, bf16TensorCoreGemm, tf32TensorCoreGemm, dmmaTensorCoreGemm, globalToShmemAsyncCopy, tmaTensorMap |
8686
| CUDA Graphs | [samples-cuda-graphs.md](references/samples-cuda-graphs.md) | simpleCudaGraphs, cudaGraphs (Python), jacobiCudaGraphs, graphMemoryNodes |
87-
| CUDA Libraries | [samples-cuda-libraries.md](references/samples-cuda-libraries.md) | simpleCUBLAS, batchCUBLAS, conjugateGradient, simpleCUFFT, histEqualizationNPP |
87+
| CUDA Libraries | [samples-cuda-libraries.md](references/samples-cuda-libraries.md) | conjugateGradientCudaGraphs, oceanFFT, cubDeviceFind, cubDeviceSegmentedScan, cubDeviceTransform |
8888
| Performance Optimization | [samples-performance.md](references/samples-performance.md) | transpose, launchConfigTuning, warpAggregatedAtomicsCG, kernelNsysProfile |
8989
| Framework Interop | [samples-framework-interop.md](references/samples-framework-interop.md) | customPyTorchKernel, customTensorFlowKernel |
9090
| Multi-GPU & Distributed | [samples-multi-gpu.md](references/samples-multi-gpu.md) | simpleP2P (Python), ipcMemoryPool, multiGPUGradientAverage |
@@ -112,7 +112,7 @@ Map optimization strategies to relevant samples:
112112

113113
| Feature | Min SM | Samples |
114114
| -------------------------------- | ------ | ----------------------------------------------------------------------- |
115-
| Basic CUDA | All | `vectorAdd`, `asyncAPI`, `simpleStreams`, `simpleCUBLAS`, `simpleCUFFT` |
115+
| Basic CUDA | All | `vectorAdd`, `asyncAPI`, `simpleStreams`, `matrixMul` |
116116
| Warp shuffle (`__shfl_*`) | 3.0 | `shfl_scan`, `reduction` (variants 5-6) |
117117
| Cooperative groups (block-level) | 5.2 | `reduction` (CG variants), `warpAggregatedAtomicsCG` |
118118
| Cooperative launch (grid sync) | 6.0 | `reductionMultiBlockCG` |
@@ -142,7 +142,7 @@ grep -r "PyTorch\|TensorFlow\|framework" skills/cuda-samples/references/
142142
grep -r "SM 8.0\|SM 9.0\|Hopper\|Ampere" skills/cuda-samples/references/
143143

144144
# Find samples by name in the quick reference table
145-
grep -i "vectorAdd\|simpleCUBLAS\|transpose" skills/cuda-samples/SKILL.md
145+
grep -i "vectorAdd\|oceanFFT\|transpose" skills/cuda-samples/SKILL.md
146146

147147
# Clone full repo for compilation and detailed study
148148
git clone --depth 1 https://github.com/NVIDIA/cuda-samples.git

‎skills/cuda-samples/references/samples-cuda-graphs.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
## 5.1 simpleCudaGraphs
44

5-
- **Path**: `cpp/3_CUDA_Features/simpleCudaGraphs/simpleCudaGraphs.cu`
6-
- **URL**: <https://github.com/NVIDIA/cuda-samples/blob/master/cpp/3_CUDA_Features/simpleCudaGraphs/simpleCudaGraphs.cu>
7-
- **Pattern**: Both Graph API (manual node construction) and Stream Capture API for CUDA Graphs. Graph is instantiated once, launched repeatedly — eliminates per-launch CPU overhead.
5+
- **Path**: `cpp/3_CUDA_Features/simpleCudaGraphs/simpleCudaGraphs_capture.cu`
6+
- **URL**: <https://github.com/NVIDIA/cuda-samples/blob/master/cpp/3_CUDA_Features/simpleCudaGraphs/simpleCudaGraphs_capture.cu>
7+
- **Pattern**: Stream Capture API for CUDA Graphs (v13.4 splits the sample into `_capture.cu` and `_explicit.cu` variants; the explicit Graph API variant is `simpleCudaGraphs_explicit.cu`). Graph is instantiated once, launched repeatedly — eliminates per-launch CPU overhead.
88
- **Arch**: All (CUDA 10.0+)
9-
- **Lines**: ~407
9+
- **Lines**: ~156 (capture) / ~236 (explicit)
1010

1111
```cuda
1212
// Stream Capture approach
Lines changed: 61 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,90 @@
11
# CUDA Libraries Samples
22

3-
## 6.1 simpleCUBLAS
3+
> v13.4 note: upstream removed `simpleCUBLAS`, `batchCUBLAS`, `simpleCUFFT`,
4+
> `conjugateGradient`, and `histEqualizationNPP`. For pure cuBLAS API patterns
5+
> (`cublasSgemm`, `cublasSgemmBatched`, `cublasLtMatmul`) consult the local
6+
> `cuda-knowledge` cublas docs (`cublas-docs/2-using-the-cublas-api/`).
47
5-
- **Path**: `cpp/4_CUDA_Libraries/simpleCUBLAS/simpleCUBLAS.cpp`
6-
- **URL**: <https://github.com/NVIDIA/cuda-samples/blob/master/cpp/4_CUDA_Libraries/simpleCUBLAS/simpleCUBLAS.cpp>
7-
- **Pattern**: Complete cuBLAS workflow: `cublasCreate` → `cublasSetVector` → `cublasSgemm` → `cublasGetVector` → `cublasDestroy`
8+
## 6.1 conjugateGradientCudaGraphs
9+
10+
- **Path**: `cpp/4_CUDA_Libraries/conjugateGradientCudaGraphs/conjugateGradientCudaGraphs.cu`
11+
- **URL**: <https://github.com/NVIDIA/cuda-samples/blob/master/cpp/4_CUDA_Libraries/conjugateGradientCudaGraphs/conjugateGradientCudaGraphs.cu>
12+
- **Pattern**: Complete Conjugate Gradient solver combining cuBLAS (dot, axpy) + cuSPARSE (`cusparseSpMV`), with the whole CG iteration captured into a CUDA Graph via Stream Capture and replayed — the reference pattern for graph-accelerated numerical solvers
813
- **Arch**: All
9-
- **Lines**: ~253
14+
- **Lines**: ~460
1015

1116
```cuda
12-
cublasHandle_t handle; cublasCreate(&handle);
13-
cublasSetVector(n2, sizeof(float), h_A, 1, d_A, 1); // upload data
14-
float alpha = 1.0f, beta = 0.0f;
15-
cublasSgemm(handle, CUBLAS_OP_N, CUBLAS_OP_N, N, N, N,
16-
&alpha, d_A, N, d_B, N, &beta, d_C, N);
17-
cublasGetVector(n2, sizeof(float), d_C, 1, h_C, 1); // download result
18-
cublasDestroy(handle);
17+
// Capture one full CG iteration (cusparseSpMV + cublasDdot/axpy) into a graph
18+
cudaStreamBeginCapture(stream1, cudaStreamCaptureModeGlobal);
19+
cusparseSpMV(cusparseHandle, CUSPARSE_OPERATION_NON_TRANSPOSE,
20+
&alpha, matA, vecP, &beta, vecAp, ...); // Ap = A * p
21+
cublasDdot(cublasHandle, N, d_p, 1, d_Ap, 1, &dot); // pAp
22+
cudaStreamEndCapture(stream1, &graph);
23+
cudaGraphInstantiate(&graphExec, graph, NULL, NULL, 0);
24+
// Replay iterations with zero per-launch CPU overhead
25+
cudaGraphLaunch(graphExec, streamForGraph);
1926
```
2027

21-
## 6.2 batchCUBLAS
28+
## 6.2 conjugateGradientMultiBlockCG
2229

23-
- **Path**: `cpp/4_CUDA_Libraries/batchCUBLAS/batchCUBLAS.cpp`
24-
- **URL**: <https://github.com/NVIDIA/cuda-samples/blob/master/cpp/4_CUDA_Libraries/batchCUBLAS/batchCUBLAS.cpp>
25-
- **Pattern**: `cublasSgemmBatched` and `cublasSgemmStridedBatched` — batched small-GEMM patterns essential for multi-head attention and ensemble models
30+
- **Path**: `cpp/4_CUDA_Libraries/conjugateGradientMultiBlockCG/conjugateGradientMultiBlockCG.cu`
31+
- **URL**: <https://github.com/NVIDIA/cuda-samples/blob/master/cpp/4_CUDA_Libraries/conjugateGradientMultiBlockCG/conjugateGradientMultiBlockCG.cu>
32+
- **Pattern**: Pure-CUDA Conjugate Gradient with a multi-block (grid-level) dot-product reduction using cooperative groups grid sync — no library calls, shows how to hand-roll the BLAS primitives a CG solver needs
2633
- **Arch**: All
27-
- **Lines**: ~350
34+
- **Lines**: ~529
2835

2936
```cuda
30-
// Pointer array variant
31-
float *d_Aarray[batchCount], *d_Barray[batchCount], *d_Carray[batchCount];
32-
cublasSgemmBatched(handle, CUBLAS_OP_N, CUBLAS_OP_N, M, N, K,
33-
&alpha, d_Aarray, M, d_Barray, K, &beta, d_Carray, M, batchCount);
34-
// Strided variant (single contiguous buffer)
35-
cublasSgemmStridedBatched(handle, CUBLAS_OP_N, CUBLAS_OP_N, M, N, K,
36-
&alpha, d_A, M, strideA, d_B, K, strideB, &beta, d_C, M, strideC, batchCount);
37+
// Grid-wide dot product via cooperative groups (multi-block reduction)
38+
grid_group grid = cg::this_grid();
39+
__shared__ float partial[...];
40+
// per-block partial reduction, then grid.sync() + final combine kernel
3741
```
3842

39-
## 6.3 conjugateGradient
43+
## 6.3 oceanFFT
4044

41-
- **Path**: `cpp/4_CUDA_Libraries/conjugateGradient/main.cpp`
42-
- **URL**: <https://github.com/NVIDIA/cuda-samples/blob/master/cpp/4_CUDA_Libraries/conjugateGradient/main.cpp>
43-
- **Pattern**: Complete Conjugate Gradient solver combining CUBLAS (BLAS ops: dot, axpy, gemv) and CUSPARSE (sparse matrix-vector multiply) — the reference pattern for numerical solvers
45+
- **Path**: `cpp/4_CUDA_Libraries/oceanFFT/oceanFFT.cpp`
46+
- **URL**: <https://github.com/NVIDIA/cuda-samples/blob/master/cpp/4_CUDA_Libraries/oceanFFT/oceanFFT.cpp>
47+
- **Pattern**: Frequency-domain ocean simulation via cuFFT 2D: `cufftPlan2d` → forward `cufftExecC2C` → spectrum multiply (dispersion kernel in `oceanFFT_kernel.cu`) → inverse transform, with OpenGL interop for display
4448
- **Arch**: All
45-
- **Lines**: ~400
49+
- **Lines**: ~903
4650

4751
```cuda
48-
// CG iteration combining cuBLAS + cuSPARSE
49-
cublasDdot(handle, N, d_r, 1, d_r, 1, &r1); // residual norm
50-
cusparseSpMV(handle_sp, CUSPARSE_OPERATION_NON_TRANSPOSE,
51-
&alpha, matA, vecX, &beta, vecY, CUDA_R_64F, ...); // Ap = A * p
52-
cublasDaxpy(handle, N, &alpha, d_p, 1, d_x, 1); // x = x + alpha * p
53-
cublasDaxpy(handle, N, &neg_beta, d_p, 1, d_r, 1); // r = r - alpha * Ap
52+
cufftHandle fftPlan;
53+
cufftPlan2d(&fftPlan, meshSize, meshSize, CUFFT_C2R);
54+
cufftExecC2C(fftPlan, h_fftData, h_fftData, CUFFT_FORWARD); // height spectrum
55+
generateSpectrumKernel<<<...>>>(...); // dispersion multiply
56+
cufftExecC2C(fftPlan, d_fftData, d_fftData, CUFFT_INVERSE); // back to spatial
57+
cufftDestroy(fftPlan);
5458
```
5559

56-
## 6.4 simpleCUFFT
60+
## 6.4 cubDeviceFind
5761

58-
- **Path**: `cpp/4_CUDA_Libraries/simpleCUFFT/simpleCUFFT.cu`
59-
- **URL**: <https://github.com/NVIDIA/cuda-samples/blob/master/cpp/4_CUDA_Libraries/simpleCUFFT/simpleCUFFT.cu>
60-
- **Pattern**: Frequency-domain convolution via cuFFT: forward FFT → complex multiply → inverse FFT. Both simple and advanced plan APIs.
62+
- **Path**: `cpp/4_CUDA_Libraries/cubDeviceFind/cubDeviceFind.cu`
63+
- **URL**: <https://github.com/NVIDIA/cuda-samples/blob/master/cpp/4_CUDA_Libraries/cubDeviceFind/cubDeviceFind.cu>
64+
- **Pattern**: CUB device-wide search primitives introduced in CCCL 3.3 — `cub::DeviceFind::FindIf` (predicate search) and `LowerBound`/`UpperBound` (parallel binary search) — using the standard two-pass temp-storage idiom
6165
- **Arch**: All
62-
- **Lines**: ~170
66+
- **Lines**: ~248
6367

6468
```cuda
65-
cufftHandle plan; cufftPlan1d(&plan, N, CUFFT_C2C, 1);
66-
cufftExecC2C(plan, d_signal, d_signal, CUFFT_FORWARD); // FFT
67-
complex_pointwise_multiply<<<grid, block>>>(d_signal, d_filter, N);
68-
cufftExecC2C(plan, d_signal, d_signal, CUFFT_INVERSE); // IFFT
69+
// Two-pass CUB idiom: query temp storage, allocate, then run
70+
std::size_t temp_bytes = 0;
71+
cub::DeviceFind::FindIf(nullptr, temp_bytes, d_in.begin(), d_out.begin(), predicate, num_items);
72+
thrust::device_vector<std::uint8_t> temp(temp_bytes);
73+
cub::DeviceFind::FindIf(thrust::raw_pointer_cast(temp.data()),
74+
temp_bytes, d_in.begin(), d_out.begin(), predicate, num_items);
6975
```
7076

71-
## 6.5 histEqualizationNPP
77+
## 6.5 cubDeviceSegmentedScan
7278

73-
- **Path**: `cpp/4_CUDA_Libraries/histEqualizationNPP/histEqualizationNPP.cpp`
74-
- **URL**: <https://github.com/NVIDIA/cuda-samples/blob/master/cpp/4_CUDA_Libraries/histEqualizationNPP/histEqualizationNPP.cpp>
75-
- **Pattern**: GPU-accelerated image histogram equalization using NPP (NVIDIA Performance Primitives) — demonstrates the complete NPP workflow: compute histogram → build cumulative LUT → apply LUT transform
79+
- **Path**: `cpp/4_CUDA_Libraries/cubDeviceSegmentedScan/cubDeviceSegmentedScan.cu`
80+
- **URL**: <https://github.com/NVIDIA/cuda-samples/blob/master/cpp/4_CUDA_Libraries/cubDeviceSegmentedScan/cubDeviceSegmentedScan.cu>
81+
- **Pattern**: `cub::DeviceSegmentedScan::ExclusiveSum` — per-segment prefix sums over offset-delimited ranges, the primitive behind grouped/windowed reductions (segmented softmax, per-row scan)
7682
- **Arch**: All
77-
- **Lines**: ~300
78-
79-
```cpp
80-
// NPP histogram equalization workflow
81-
nppiHistogramEvenGetBufferSize_8u_C1R_Ctx(oSizeROI, levelCount, &nDeviceBufferSize, nppStreamCtx);
82-
cudaMalloc(&pDeviceBuffer, nDeviceBufferSize);
83-
nppiEvenLevelsHost_32s(levelsHost, levelCount, 0, binCount);
84-
// Compute histogram on GPU
85-
nppiHistogramEven_8u_C1R_Ctx(oDeviceSrc.data(), oDeviceSrc.pitch(), oSizeROI,
86-
histDevice, levelCount, 0, binCount,
87-
pDeviceBuffer, nppStreamCtx);
88-
cudaMemcpy(histHost, histDevice, binCount * sizeof(Npp32s), cudaMemcpyDeviceToHost);
89-
// Build cumulative LUT on host, upload to device, apply
90-
cudaMemcpy(lutDevice, lutHost, sizeof(Npp32s) * levelCount, cudaMemcpyHostToDevice);
91-
nppiLUT_Linear_8u_C1R_Ctx(oDeviceSrc.data(), oDeviceSrc.pitch(),
92-
oDeviceDst.data(), oDeviceDst.pitch(),
93-
oSizeROI, lutDevice, lvlsDevice, nppStreamCtx);
83+
- **Lines**: ~188
84+
85+
```cuda
86+
std::size_t temp_bytes = 0;
87+
cub::DeviceSegmentedScan::ExclusiveSum(nullptr, temp_bytes, d_in, d_out,
88+
num_segments, d_offsets, d_offsets + 1, num_items);
89+
// ... allocate temp, rerun with real pointers
9490
```

0 commit comments

Comments
 (0)