I'm using CMake as a build system for my code, which involves CUDA. I was thinking of automating the task of deciding which compute_XX
and arch_XX
I need to to pass to my nvcc in order to compile for the GPU(s) on my current machine.
Is there a way to do this:
- With the NVIDIA GPU deployment kit?
- Without the NVIDIA GPU deployment kit?
Does CMake's
FindCUDA
help you in determining the values for these switches?
My strategy has been to compile and run a bash script that probes the card and returns the gencode for cmake. Inspiration came from University of Chicago's SLURM. To handle errors or multiple gpus or other circumstances, modify as necessary.
In your project folder create a file cudaComputeVersion.bash and ensure it is executable from the shell. Into this file put:
And in your CMakeLists.txt put:
cheers
A slight improvement over @orthopteroid's answer, which pretty much ensures a unique temporary file is generated, and only requires one instead of two temporary files.
The following goes into
scripts/get_cuda_sm.sh
:and the following goes into
CMakeLists.txt
or a CMake module: