BASIS icon indicating copy to clipboard operation
BASIS copied to clipboard

CUDA with BASIS

Open issamsaid opened this issue 7 years ago • 1 comments

CMake is now supporting CUDA as a native language. However it is not possible to use basis_add_libraray(TARGET files LANGUAGE CUDA) . The error message is :

 CMake Error at CMake-Basis/3.3.1/share/modules/TargetTools.cmake:519 (target_link_libraries):
   Target "cuda" of type UTILITY may not be linked into another target.
   One may link only to STATIC or SHARED libraries, or to executables with the
   ENABLE_EXPORTS property set.

Are they any plans to support CUDA?

issamsaid avatar Aug 29 '18 08:08 issamsaid

Thanks for reporting this issue. I'll collect some notes here as to which functions may need to be extended in order to support CUDA with CMake 3.8+ (i.e., without need for FindCUDA).

  • basis_get_source_language: Recognize .cu filename extension https://github.com/cmake-basis/BASIS/blob/b21423c169a0d15feff046421bfd76092b559af5/src/cmake/modules/CommonTools.cmake#L2760

  • basis_add_library_target: Sets LANGUAGE target property to CXX (CMake does not define this target property, it may only be used by BASIS; see file property) https://github.com/cmake-basis/BASIS/blob/b21423c169a0d15feff046421bfd76092b559af5/src/cmake/modules/TargetTools.cmake#L2118

  • Enable CUDA language support of CMake 3.8+ in BasisProject.cmake file using basis_project (no fix needed, user must specify CUDA language when used): https://github.com/cmake-basis/BASIS/blob/b21423c169a0d15feff046421bfd76092b559af5/src/cmake/modules/ProjectTools.cmake#L585

  • Pass basis_project(LANGUAGES CUDA) on to CMake's project command (also allow NONE?) (this is the most important change): https://github.com/cmake-basis/BASIS/blob/b21423c169a0d15feff046421bfd76092b559af5/src/cmake/modules/ProjectTools.cmake#L1869

  • Set property CUDA_SEPARABLE_COMPILATION appropriately. (though default value can be set by user by setting CMAKE_CUDA_SEPARABLE_COMPILATION).

  • On macOS, set property BUILD_RPATH to include CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES.

Note that the LANGUAGE option of basis_add_library is mainly used to determine which specialized function to use for defining the build target. When the option argument is CXX and it's not a MEX-file target, CMake's add_library function is used. Otherwise BASIS uses some custom basis_* functions which define custom build commands and targets.

Hence, I would try

basis_add_library(TARGET files LANGUAGE CXX)

until LANGUAGE argument CUDA is supported by basis_add_library and basis_add_executable.

See also: https://devblogs.nvidia.com/building-cuda-applications-cmake/

schuhschuh avatar Aug 29 '18 23:08 schuhschuh