cmake-basis/BASIS

CUDA with BASIS

issamsaid opened this issue · 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?

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

    ## @brief Detect programming language of given source code files.

  • 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)

    set_target_properties (${TARGET_UID} PROPERTIES BASIS_TYPE "${TYPE}_LIBRARY" LANGUAGE "CXX" OUTPUT_NAME "${OUTPUT_NAME}")

  • 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):

    # @tp @b LANGUAGES lang1 [lang2...] @endtp

  • Pass basis_project(LANGUAGES CUDA) on to CMake's project command (also allow NONE?)
    (this is the most important change):

    if (lang MATCHES "^(C|CXX)$")

  • 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/