CI/CD for a CUDA/C++ Project with GitHub Actions
Compile CUDA kernels on a CPU runner and gate device tests on GPUs.
A CUDA/C++ project compiles kernels with nvcc but only needs a GPU to run them. This recipe installs the toolkit, builds with CMake on a CPU runner, and runs device tests on a self-hosted GPU job.
What the pipeline does
- install the CUDA toolkit
- configure with CMake and CUDA architectures
- compile kernels with nvcc on a CPU runner
- run host-side tests
- run device tests on a self-hosted GPU runner
The workflow
Compilation does not need a GPU, so the build runs on a standard runner. Set CMAKE_CUDA_ARCHITECTURES to your target SM versions; device tests run on a labeled self-hosted GPU runner.
name: CI
on:
push:
branches: [main]
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Jimver/cuda-toolkit@v0.2.19
with:
cuda: '12.4.0'
- run: cmake -B build -DCMAKE_CUDA_ARCHITECTURES='80;86'
- run: cmake --build build -j
- run: ctest --test-dir build -L host
- uses: actions/upload-artifact@v4
with:
name: cuda-build
path: buildCaching and speed
Cache the CUDA toolkit install and use ccache (cache ~/.ccache) to skip recompiling unchanged translation units across multi-arch builds. nvcc multi-arch compiles are slow; cheaper managed runners such as Latchkey (around 69% cheaper than GitHub-hosted) keep these long builds affordable and auto-retry transient toolkit download failures.
Deploying
CPU runners verify the build and host-side tests; add a self-hosted GPU runner job for device tests. Package the compiled binaries or a CUDA-enabled container image and deploy to a GPU host or Kubernetes GPU node pool.
Key takeaways
- nvcc compiles on a CPU runner; only device tests need a GPU.
- Set CMAKE_CUDA_ARCHITECTURES to your target SM versions.
- Use ccache to speed multi-arch kernel compiles.