Below, I'll guide you step-by-step on how to interpret and address the issues you're seeing in NVIDIA Compute Utility (NCU) when profiling your CUDA kernels. These metrics indicate potential bottlenecks or underutilization in your kernel's execution. NCU (formerly nsight-compute) provides detailed insights into GPU resource usage, and low values in these areas often point to memory-bound, compute-bound, or occupancy-related problems.
I'll start with a quick overview of what each metric means, then provide actionable steps to diagnose and optimize. These issues are often interconnected (e.g., low occupancy can cause low throughputs across the board), so I recommend profiling iteratively: make one change, re-profile with NCU, and measure improvements. Use commands like ncu --metrics <metric_list> your_program to focus on specific metrics (e.g., sm__throughput.avg.pct_of_peak_sustained_active for SM throughput).
Key Concepts and General Advice
- Throughput Metrics: These measure utilization as a percentage of peak theoretical performance. "Low" typically means <30-50% utilization, but it depends on your hardware (e.g., Ampere/Ada GPUs have higher peaks). Low throughputs suggest the kernel is bottlenecked or idle.
- Occupancy: Theoretical occupancy is the max possible active warps per SM based on kernel limits (registers, shared memory, block size). Achieved occupancy is the runtime average. If achieved < theoretical (e.g., 20% vs. 100%), threads aren't keeping the GPU busy, often hiding latencies poorly.
- Common Root Causes: Poor memory access patterns, excessive synchronization, insufficient parallelism, register pressure, or kernel launch config issues.
- Tools: Use NCU's roofline chart to see if you're memory-bound or compute-bound. Also, check CUDA Occupancy Calculator (in Excel or online) to simulate occupancy. Enable compiler optimizations with
-O3 and profile with -lineinfo for source correlation.
- Benchmark: Always compare before/after metrics. Test on your specific GPU architecture (e.g., Volta, Ampere).
Now, let's break it down by metric.
1. Low Achieved Occupancy (Achieved < Theoretical)
What it means: Your kernel isn't launching enough threads or warps to fully utilize the SMs (Streaming Multiprocessors). This leads to idle hardware, poor latency hiding (e.g., for memory accesses), and often cascades into low throughputs elsewhere. Common if block size is too small or resource limits (registers/shared memory) cap warps per SM.
Steps to Fix:
2. Low Memory Throughput
What it means: Global memory bandwidth isn't being utilized efficiently. This often indicates a memory-bound kernel with scattered accesses, poor coalescing, or insufficient data reuse.
Steps to Fix:
3. Low DRAM Throughput
What it means: Device memory (DRAM) bandwidth is underutilized, often because the kernel is compute-bound, has poor access patterns, or isn't issuing enough memory requests. Low DRAM can mask other issues if caches (L1/L2) are handling most loads.
Steps to Fix:
-
Improve Data Locality and Reuse:
- Maximize cache hits to reduce DRAM traffic: Restructure loops for temporal/spatial locality.
- Use const/restrict qualifiers or texture memory for read-only data.
-
Balance Load:
- If compute throughput is high, the kernel might be compute-bound—shift work to memory ops if possible.
- Increase data volume processed per kernel (e.g., tile larger datasets) to saturate DRAM.
-
Hardware-Specific Tweaks:
- On newer GPUs (e.g., Ampere+), use asynchronous global-to-shared copies (
cuda::memcpy_async).
- Check for over-subscription: Ensure your data fits in GPU memory; use unified memory sparingly.
-
Profile Tip: Monitor dram__bytes_read.sum vs. dram__bytes_write.sum to see if reads/writes are balanced.
4. Low L1 Throughput
What it means: The per-SM L1 cache isn't being used effectively, often due to poor locality, cache thrashing, or evictions. L1 is fastest but smallest, so low throughput means missed opportunities for quick data access.
Steps to Fix:
5. Low L2 Throughput
What it means: The unified L2 cache (shared across SMs) is underutilized, often because data doesn't fit in L1 or access patterns cause evictions. Low L2 can bottleneck if DRAM is slow to refill it.
Steps to Fix:
6. Low Compute (SM) Throughput
What it means: The SMs aren't busy with computations (e.g., ALU/FPU operations). This could be due to stalls from memory waits, synchronization, or insufficient instruction-level parallelism (ILP). If memory throughputs are also low, the kernel might be idle-heavy or too short-lived.
Steps to Fix:
-
Increase ILP and Reduce Stalls:
- Unroll loops to expose more independent instructions.
- Minimize divergences (e.g., if/else branches) using techniques like thread compaction.
-
Address Dependencies:
- Reduce
__syncthreads() or atomic ops; use warp-level primitives (e.g., __shfl_sync) instead.
- If occupancy is low, fix it to keep SMs fed with warps.
-
Balance Workload:
- If memory-bound, offload computations or fuse kernels.
- Ensure enough FLOPs per thread; trivial kernels won't saturate compute.
-
Profile Tip: Check sm__inst_executed.avg.pct_of_peak_sustained_active and stall reasons (e.g., "No Instructions" or "Memory Dependency").
Holistic Optimization Strategy
- Start with Occupancy: It's foundational—low occupancy amplifies other issues. Fix it first.
- Identify the Bottleneck: Use NCU's roofline model or "Speed of Light" view. If memory throughputs are low but compute is high, you're compute-bound (add more math ops). Vice versa? Memory-bound (optimize accesses).
- Common Patterns for All:
- Code Optimizations: Use shared memory for caching, coalesce accesses, minimize globals.
- Launch Config: Experiment with block/grid sizes using tools like
ncu --launch-count 1 for isolated profiling.
- Hardware Considerations: Results vary by GPU (e.g., A100 has higher bandwidth). Test on target hardware.
- Advanced: Use Tensor Cores or CUDA Graphs for throughput boosts if applicable.
- When to Stop: Aim for 70-90% utilization in key areas. Perfect isn't always possible—diminishing returns apply.
- Potential Pitfalls: Over-optimizing one area (e.g., occupancy) might hurt another (e.g., increase cache misses). Always re-profile.
- Resources: NVIDIA's CUDA Best Practices Guide, NCU documentation, and blogs on roofline analysis. If stuck, share your kernel code/snippet and NCU output for specific advice.
If you provide more details (e.g., your kernel type, GPU model, or exact NCU metrics/values), I can give more tailored recommendations!