Cuda support
jjcasmar opened this issue · 8 comments
Hi,
ive been using CMakeCommon for a while now, but ive not been able to compile any library which uses CUDA.
If I try to compile using cuda_add_library, CMakeCommon complains that the target is not exported, but if I try to compile using common_library, g++ is used and not nvcc.
I believe that I should modify CMAKE_C_COMPILER and CMAKE_CXX_COMPILER to use nvcc and a compatible gcc compiler. I thought that was that CommonCUDA did, but it seems there is a bug in the string(REGEX REPLACE) command.
What should I do?
Thanks!
BTW, this is the error im having
CMake Error at CMake/common/CommonCUDA.cmake:33 (string):
string sub-command REGEX, mode REPLACE needs at least 6 arguments total to
command.
Call Stack (most recent call first):
CMake/common/CommonFindPackage.cmake:276 (find_cuda_compatible_host_compiler)
CMakeLists.txt:103 (common_find_package_post)
CMake 3.9.4
You don't need to use CommonCUDA explicitly, the necessary code gets invoked from common_find_package_post(). If you've observed that error just by adding common_find_package(CUDA), then the problem must be in the parsing of the host_config.h CUDA header, which keeps changing all the time.
Related to the first problem, you should use cuda_add_library. Although I don't remember what's the actual explanation for it I added this to my CMakeLists.txt:
install(TARGETS your_target EXPORT ${PROJECT_NAME}Targets LIBRARY DESTINATION lib COMPONENT COMMON)
It may also solve your problem.
The problem with cudacommon happens when doing common_find_package(CUDA). Isn't there an easy way to simply do common_library and that compiles it with cuda if cuda is enabled? Or what should be the correct process to configure a project with cuda with cmakecommon?
Ideally, having a smart common_library that can handle CUDA libraries would be perfect. But nobody has the time time right now to implement and I'm afraid that is not that simple, as it requires embedding cuda_add_library and will require making a few assumptions about the user intentions.
I think the problem is the header parsing as I said, so it should be easily fixable. Which CUDA version are you using?
Cuda 9
I'll try to see the difference in the host_config.h header as soon as possible.
Sorry for the delay, but I had to look into more urgent things and eventually forgot about this issue. If you're problem with the header parsing solved?
Ive been able to workaround the problem adding common_find_package(CUDA) after common_find_package_post(). This bypass the checks done in _post() and everything seems to work fine.
Not a production solution for CMakeCommon, but it works.