Skip to content
Latchkey

nvcc Command: Compile CUDA in CI

nvcc compiles CUDA C/C++ into host code plus GPU device binaries.

nvcc is NVIDIA's CUDA compiler driver. It splits source into host and device code, compiling device kernels for one or more GPU architectures and handing host code to the system C++ compiler. CI for GPU code pins target architectures with -arch/-gencode.

Common flags

  • -o NAME - name the output executable/object
  • -arch=sm_80 - target a specific GPU compute capability
  • -gencode arch=compute_80,code=sm_80 - emit PTX + SASS for an arch (repeatable)
  • -c - compile to an object file without linking
  • -I DIR / -L DIR / -lNAME - header / lib path / link library
  • -O3 - optimize host and device code
  • -Xcompiler "-Wall" - pass flags through to the host compiler

Example in CI

Compile a CUDA program for two GPU architectures in a GPU CI job:

shell
nvcc -O3 -gencode arch=compute_80,code=sm_80 -gencode arch=compute_90,code=sm_90 kernel.cu -o app

Common errors in CI

  • nvcc fatal: Unsupported gpu architecture 'compute_XX' - toolkit too old for that arch
  • no kernel image is available for execution on the device - runtime arch mismatch with -arch
  • cuda_runtime.h: No such file or directory - CUDA toolkit not installed / wrong -I
  • unsupported GNU version! gcc versions later than N are not supported - host compiler too new

Key takeaways

  • Pin GPU targets with -arch/-gencode to match the runtime hardware.
  • "no kernel image available" means the built arch does not match the GPU.
  • nvcc needs a compatible host compiler; very new gcc/clang can be rejected.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →