I’m working on a project which uses CUDA for some functions. But I also want the program to be run on a computer without cuda installed using equivalent (but of course slower) versions of the functions.
To compile my project, I’m currently using cmake together with ccmake to produce the Makefiles. I’ve been trying to write some CMakelists file for ages but I’ve not been able to achieve what I am looking for.
I’d like nvcc to compile the .cu files, gcc to compile the standard c++ files and the usual linker to link everything if needed. At the same time, I’d like to be able to switch off the cuda-compilation so that gcc only compiles the whole project.
Do you have any advice on how I could manage that ?
I’ve tried with the findCUDA script, but as far as I understood, I cannot use it on a computer without CUDA and hence switch off the GPU part.
Create an option (i.e. ENABLE_CUDA) and only find_package(FindCUDA.cmake) if ENABLE_CUDA is true. You will probably need to pass the ENABLE_CUDA as a -D define and use ifdef to conditionally include cuda related stuff in your .cc files.
This is what I do. FinCUDA.cmake is pretty advanced and extremely well tested, I wouldn’t try to roll your own :)
I already have an ENABLE_CUDA pre-processor option in my files. I don’t know how to launch FindCUDA if the option is switched on in the ccmake interface.
FindCUDA.cmake + CMake takes care of all the linking for you. All .cc / .cpp files are compiled by gcc/visual studio and only the .cu files are compiled by nvcc.