Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Specialized skill for GPU memory hierarchy analysis and optimization. Analyze memory access patterns, detect bank conflicts, optimize cache utilization, profile global memory bandwidth, and generate optimized memory access code patterns.
.claude/skills/a5c-ai-gpu-memory-analysis/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 18% | 0% |
| case-02 | ✗→✓ | ▲ Improved | 46% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 82% | 0% |
| case-08 | ✗→✓ | ▲ Improved | 29% | 0% |
| case-22 | ✗→✓ | ▲ Improved | 109% | 0% |
You are gpu-memory-analysis - a specialized skill for GPU memory hierarchy analysis and optimization. This skill provides expert capabilities for understanding and optimizing GPU memory access patterns.
This skill enables AI-powered GPU memory optimization including:
Analyze coalescing and striding:
cuda// Good: Coalesced access (threads access consecutive addresses) __global__ void coalescedAccess(float* data, int n) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < n) { float val = data[idx]; // Coalesced: thread i accesses data[i] data[idx] = val * 2.0f; } } // Bad: Strided access (cache unfriendly) __global__ void stridedAccess(float* data, int n, int stride) { int idx = blockIdx.x * blockDim.x + threadIdx.x; int actualIdx = idx * stride; // Non-coalesced! if (actualIdx < n) { float val = data[actualIdx]; data[actualIdx] = val * 2.0f; } } // Analysis command // ncu --section MemoryWorkloadAnalysis ./program
Detect and resolve shared memory conflicts:
cuda// Bad: Bank conflicts (all threads access same bank) __global__ void bankConflict(float* output) { __shared__ float smem[256]; int tid = threadIdx.x; // All threads in warp access same column = bank conflict smem[tid * 32] = tid; // 32-way bank conflict! __syncthreads(); output[tid] = smem[tid * 32]; } // Good: No bank conflicts __global__ void noBankConflict(float* output) { __shared__ float smem[256]; int tid = threadIdx.x; smem[tid] = tid; // Consecutive = no conflict __syncthreads(); output[tid] = smem[tid]; } // Padded to avoid conflicts in 2D access __global__ void paddedAccess(float* input, float* output, int width) { // Pad by 1 to avoid bank conflicts on column access __shared__ float smem[32][33]; // 33 instead of 32 int x = threadIdx.x; int y = threadIdx.y; smem[y][x] = input[y * width + x]; __syncthreads(); // Transposed access - no bank conflicts due to padding output[x * width + y] = smem[x][y]; }
Optimize L1/L2 cache usage:
cuda// Configure L1/shared memory preference cudaFuncSetCacheConfig(myKernel, cudaFuncCachePreferL1); // More L1 cudaFuncSetCacheConfig(myKernel, cudaFuncCachePreferShared); // More shared cudaFuncSetCacheConfig(myKernel, cudaFuncCachePreferEqual); // Equal split // Cache hints with __ldg (read-only data cache) __global__ void cacheOptimized(const float* __restrict__ input, float* output, int n) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < n) { // Use read-only cache for input float val = __ldg(&input[idx]); output[idx] = val * 2.0f; } } // Streaming stores (bypass cache for write-only data) __global__ void streamingStore(float* output, int n) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < n) { // Bypass cache, don't pollute for write-only __stcs(&output[idx], computeValue(idx)); } }
Efficient shared memory usage:
cuda// Tiled matrix multiply with optimized shared memory template<int TILE_SIZE> __global__ void tiledMatMul(const float* A, const float* B, float* C, int M, int N, int K) { __shared__ float As[TILE_SIZE][TILE_SIZE]; __shared__ float Bs[TILE_SIZE][TILE_SIZE]; int bx = blockIdx.x, by = blockIdx.y; int tx = threadIdx.x, ty = threadIdx.y; int row = by * TILE_SIZE + ty; int col = bx * TILE_SIZE + tx; float sum = 0.0f; for (int t = 0; t < (K + TILE_SIZE - 1) / TILE_SIZE; t++) { // Collaborative load to shared memory if (row < M && t * TILE_SIZE + tx < K) As[ty][tx] = A[row * K + t * TILE_SIZE + tx]; else As[ty][tx] = 0.0f; if (t * TILE_SIZE + ty < K && col < N) Bs[ty][tx] = B[(t * TILE_SIZE + ty) * N + col]; else Bs[ty][tx] = 0.0f; __syncthreads(); // Compute partial product for (int k = 0; k < TILE_SIZE; k++) { sum += As[ty][k] * Bs[k][tx]; } __syncthreads(); } if (row < M && col < N) { C[row * N + col] = sum; } }
Profile and optimize bandwidth:
bash# Profile memory throughput ncu --metrics \ l1tex__t_bytes_pipe_lsu_mem_global_op_ld.sum.per_second,\ l1tex__t_bytes_pipe_lsu_mem_global_op_st.sum.per_second,\ dram__bytes_read.sum.per_second,\ dram__bytes_write.sum.per_second \ ./program # Check memory efficiency ncu --metrics \ smsp__sass_average_data_bytes_per_sector_mem_global_op_ld.ratio,\ smsp__sass_average_data_bytes_per_sector_mem_global_op_st.ratio \ ./program
Specialized memory optimization:
cuda// Texture memory for spatially local access texture<float, 2, cudaReadModeElementType> texRef; __global__ void textureKernel(float* output, int width, int height) { int x = blockIdx.x * blockDim.x + threadIdx.x; int y = blockIdx.y * blockDim.y + threadIdx.y; if (x < width && y < height) { // Hardware interpolation and caching float val = tex2D(texRef, x + 0.5f, y + 0.5f); output[y * width + x] = val; } } // Constant memory for broadcast data __constant__ float coefficients[256]; __global__ void constantMemKernel(float* data, int n) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < n) { // All threads read same constant = broadcast data[idx] *= coefficients[idx % 256]; } }
Identify unnecessary transactions:
cuda// Analyze memory transactions per request // Ideal: 1 transaction per 32 threads (4 bytes * 32 = 128 bytes = 1 sector) // Bad: Unaligned access causes extra transactions __global__ void unalignedAccess(float* data, int offset) { int idx = blockIdx.x * blockDim.x + threadIdx.x; // Misaligned by offset bytes float val = data[idx + offset]; // May require 2 transactions } // Good: Aligned access __global__ void alignedAccess(float* __restrict__ data) { int idx = blockIdx.x * blockDim.x + threadIdx.x; float val = data[idx]; // 1 transaction per warp }
Generate optimized patterns:
cuda// Structure of Arrays (SoA) - better for GPU struct ParticlesSoA { float* x; float* y; float* z; float* vx; float* vy; float* vz; }; __global__ void updateParticlesSoA(ParticlesSoA p, int n, float dt) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < n) { // Coalesced access for each field p.x[idx] += p.vx[idx] * dt; p.y[idx] += p.vy[idx] * dt; p.z[idx] += p.vz[idx] * dt; } } // Array of Structures (AoS) - avoid on GPU struct ParticleAoS { float x, y, z; float vx, vy, vz; }; __global__ void updateParticlesAoS(ParticleAoS* particles, int n, float dt) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < n) { // Non-coalesced: threads access interleaved memory particles[idx].x += particles[idx].vx * dt; particles[idx].y += particles[idx].vy * dt; particles[idx].z += particles[idx].vz * dt; } }
This skill integrates with the following processes:
gpu-memory-optimization.js - Memory optimization workflowshared-memory-usage-patterns.js - Shared memory patternsgpu-cpu-data-transfer-optimization.js - Transfer optimizationgpu-memory-pool-allocator.js - Memory poolingjson{ "operation": "analyze-memory-access", "kernel": "matrixMultiply", "analysis": { "global_memory": { "load_efficiency": 0.95, "store_efficiency": 1.0, "transactions_per_request": 1.05, "throughput_gbps": 450 }, "shared_memory": { "bank_conflicts": 0, "utilization": 0.85 }, "cache": { "l1_hit_rate": 0.72, "l2_hit_rate": 0.45 } }, "issues": [ { "type": "strided_access", "location": "line 42", "severity": "medium", "recommendation": "Reorder data layout to SoA" } ], "recommendations": [ "Convert AoS to SoA for better coalescing", "Add padding to shared memory to avoid bank conflicts" ] }
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→pass | 24,909 | 16,273 | -35% | 1 | 1 | 0% | 4,011 | 4,748 | +18% | 0 | 0 | — |
case-02 | fail→pass | 20,957 | 13,934 | -34% | 1 | 1 | 0% | 3,296 | 4,824 | +46% | 0 | 0 | — |
case-03 | fail→pass | 20,274 | 17,335 | -14% | 1 | 1 | 0% | 3,137 | 5,696 | +82% | 0 | 0 | — |
case-04 | pass→pass | 29,632 | 30,524 | +3% | 1 | 1 | 0% | 3,138 | 7,888 | +151% | 0 | 0 | — |
case-05 | pass→pass | 17,060 | 12,252 | -28% | 1 | 1 | 0% | 2,540 | 5,111 | +101% | 0 | 0 | — |
case-06 | pass→fail | 23,572 | 19,003 | -19% | 1 | 1 | 0% | 3,765 | 5,867 | +56% | 0 | 0 | — |
case-07 | pass→pass | 13,879 | 9,602 | -31% | 1 | 1 | 0% | 2,416 | 4,436 | +84% | 0 | 0 | — |
case-08 | fail→pass | 20,891 | 8,035 | -62% | 1 | 1 | 0% | 3,189 | 4,112 | +29% | 0 | 0 | — |
case-09 | pass→pass | 12,609 | 12,934 | +3% | 1 | 1 | 0% | 2,502 | 4,992 | +100% | 0 | 0 | — |
case-10 | pass→pass | 11,451 | 11,265 | -2% | 1 | 1 | 0% | 2,041 | 4,785 | +134% | 0 | 0 | — |
case-11 | pass→pass | 10,147 | 7,128 | -30% | 1 | 1 | 0% | 1,715 | 4,201 | +145% | 0 | 0 | — |
case-12 | pass→pass | 8,279 | 8,856 | +7% | 1 | 1 | 0% | 1,382 | 4,255 | +208% | 0 | 0 | — |
case-13 | pass→pass | 3,157 | 6,261 | +98% | 1 | 1 | 0% | 498 | 4,122 | +728% | 0 | 0 | — |
case-14 | pass→pass | 18,987 | 18,731 | -1% | 1 | 1 | 0% | 3,036 | 6,758 | +123% | 0 | 0 | — |
case-15 | pass→pass | 6,452 | 13,477 | +109% | 1 | 1 | 0% | 1,128 | 4,850 | +330% | 0 | 0 | — |
case-16 | fail→fail | 13,031 | 19,377 | +49% | 1 | 1 | 0% | 2,350 | 5,957 | +153% | 0 | 0 | — |
case-17 | pass→pass | 18,929 | 19,757 | +4% | 1 | 1 | 0% | 3,289 | 7,293 | +122% | 0 | 0 | — |
case-18 | pass→pass | 17,148 | 12,347 | -28% | 1 | 1 | 0% | 2,596 | 4,881 | +88% | 0 | 0 | — |
case-19 | pass→pass | 4,076 | 4,424 | +9% | 1 | 1 | 0% | 518 | 3,531 | +582% | 0 | 0 | — |
case-20 | pass→pass | 7,020 | 8,639 | +23% | 1 | 1 | 0% | 1,108 | 4,652 | +320% | 0 | 0 | — |
case-21 | pass→pass | 6,589 | 9,129 | +39% | 1 | 1 | 0% | 874 | 3,742 | +328% | 0 | 0 | — |
case-22 | fail→pass | 16,681 | 11,263 | -32% | 1 | 1 | 0% | 2,410 | 5,042 | +109% | 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 +18 percentage points is the difference between those two pass rates over the 22 comparable cases. 1 case got worse with the skill loaded, and it is included in that figure.
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.