I’ve been using CMake (Kitware’s cross platform build system) with Cuda for quite some time now. CMake eliminates the need to modify visual studio build configuration manually to invoke nvcc.
I’ve finally posted a build script called FindCuda.cmake. This script locates Cuda/Cut and defines several macros for adding cuda executables or libraries. This version performs fully dependency checking by parsing the output of “nvcc -M” in a separate cmake script. I use WinXP with the script but it should work in linux too.
Thanks for the note. This problem was fixed in r187 using a regex.
Since the original posting the script has been updated. I’ve added the ability to automatically parse -cubin generated files and output stats each kernel. This prints out the number of registers etc. on the build console. Details and changelog are on the web page above.
Hi, I’ve updated (to r537) the FindCuda.cmake script and tested it with the current version on WinXP, Linux and Mac OSX. Thanks to everyone who has provided feedback; I think the update should address most issues. See the notes in the script for usage.
I have made the needed modifications, but it was so long ago I don’t remember what I did :( What I have now works in linux and windows, but I remember it being tricky to get it working in both simultaneously.
I’ve attached the FindCUDA.cmake that I’ve been using. Bu it is based on an older version of the file so it doesn’t have some of the features of the latest one (like Mac support). Maybe you can merge my changes into the new version. Otherwise, I will get around to making the merge myself in a few days: I’m looking forward to adding Mac support to my application.
your file did solve the inital problem but threw up several other issues on my system. So I just took the actual version of FindCUDA.cmake and removed additional prefixes from the filenames (see attached file).
Now every *.cu file has to be passed with its absolute path in CmakeLists.txt, which seems to be a sufficient workaround for my problem.
As I said, my version was based on a very old version of FindCUDA.cmake which is probably why you had trouble getting it to work on your system.
What I don’t like about the quick and dirty method you did is that you have
SET(generated_target “${file}_target”)
which populates the source directory with generated files: a no-no in CMake out-of-source builds because it makes a mess.
I’ve merged my changes into the latest r537 FindCUDA.cmake from Abe’s repository. The file is attached here. I’ve tested it and it works in linux. I assume it will work in Windows still, since it is the same modification I made before.
Note: I also had to change the generated file from ${stripped_file}_${cuda_target}generated.cc to ${stripped_file}${cuda_target}_generated.c (note the extension change). With the generated file as .cc I got lots of undefined references for all of my functions in .cu files. I noticed the old version of FindCUDA.cmake I used generated a .c file so I made the change to the new one to get it to work.
By the way, I forgot to add: Thank you very much Abe, for providing FindCUDA.cmake. I’ve been using it for a year now in a very large project and it has never let me down (except for this minor little file path issue, I guess).
Thanks for sharing the cmake script! I just checked from the trunk, but currently I’m unable to compile the sample project. I would welcome any hints from anyone…
I am currently running on ubuntu 7.10 and the generate file that gives the linking error is:
For me it seems that something goes wrong with libcudart.so. This lib should contain the functions which are not found by the linker but I do not know why.
Even if link by myself it does not work. Could that be an issue on x86 system which mine is?
I am having problems to compile the example project from FindCuda.cmake.
I am using VS2005 on XP64. Can anybody help me?
The error:
1>C:\CUDA\bin/…/include\crt/host_runtime.h(57) : error C2632: ‘char’ followed by ‘bool’ is illegal
1>C:\CUDA\bin/…/include\crt/host_runtime.h(57) : warning C4091: 'typedef ’ : ignored on left of ‘char’ when no variable is declared
I’m seeing the same problem (also using VS2005, XP64, compiling as 32bit)
Looking at host_runtime.h, the error is caused by __cplusplus not being defined. My understanding is that the compiler should automatically set this definition… but for some reason its undefined.
I tried copying the preprocessor block into another src file in my project, and it evaluated correctly. It seems like this is caused by something in the nvcc generated source.
Looking at this a little more, I think I am slightly off target.
CMake uses NVCC to generate cc source from the cu files. These files are C code. The Visual Studio compiler is treating them as C++ though. If I force the compiler to treat them as C, then they compile correctly. However, now the linker reports “unresolved external symbol” for the functions in the cu files :blink: