nvcc -arch=sm_XX: Target the Right GPU
nvcc -arch=sm_XX tells the compiler which GPU compute capability to generate code for, and -gencode builds fat binaries covering several.
Compute capability (sm_XX) must match the target GPU. Build too new and old cards reject it; too old and you lose features. Fatbins cover a range.
What it does
nvcc -arch=sm_XX sets the real GPU architecture (SASS) target; -arch=compute_XX sets the virtual PTX target. -gencode arch=compute_XX,code=sm_YY embeds multiple targets in one fat binary so it runs on several GPU generations.
Common usage
# single target: Ampere A100 (sm_80)
nvcc kernel.cu -arch=sm_80 -o kernel
# fat binary for Ampere + Hopper, with PTX fallback
nvcc kernel.cu \
-gencode arch=compute_80,code=sm_80 \
-gencode arch=compute_90,code=sm_90 \
-gencode arch=compute_90,code=compute_90 -o kernelOptions
| Value | GPU generation |
|---|---|
| sm_70 | Volta (V100) |
| sm_75 | Turing (T4, RTX 20xx) |
| sm_80 / sm_86 | Ampere (A100 / A10, RTX 30xx) |
| sm_89 | Ada Lovelace (L4, RTX 40xx) |
| sm_90 | Hopper (H100) |
| -gencode ...,code=compute_XX | Embed PTX so future GPUs can JIT it |
In CI
Match -arch to the runner GPU (from nvidia-smi). Include a compute_XX PTX target so a newer GPU than you built for can JIT-compile the PTX instead of failing. Building only for a very new sm_XX breaks on older CI GPUs.
Common errors in CI
"nvcc fatal : Unsupported gpu architecture \"compute_90\"" means the toolkit is too old to know that sm; upgrade CUDA or lower the target. "no kernel image is available for execution on the device" at runtime means the binary lacks code for the actual GPU\u0027s compute capability; add its sm_XX or a compute_XX PTX fallback.