3 ##################################
5 # If CUDA is enabled, set it up
7 # the package is needed
8 find_package(CUDA REQUIRED REQUIRED)
10 if (${CUDA_VERSION} VERSION_LESS 4.0)
11 message(SEND_ERROR "CUDA 3.2 and older are not supported")
12 endif (${CUDA_VERSION} VERSION_LESS 4.0)
17 if (${THRUST_VERSION} VERSION_LESS 1.5.0)
18 message(SEND_ERROR "Thrust version ${THRUST_VERSION} found, >= 1.5.0 is required")
19 endif (${THRUST_VERSION} VERSION_LESS 1.5.0)
21 # first thrust, then CUDA (to allow for local thrust installation
22 # that overrides CUDA toolkit)
23 include_directories(${THRUST_INCLUDE_DIR})
25 include_directories(${CUDA_INCLUDE_DIRS})
27 get_directory_property(DIRS INCLUDE_DIRECTORIES SYSTEM)
28 # hide some variables users don't need to see
29 mark_as_advanced(CUDA_SDK_ROOT_DIR)
30 if (CUDA_TOOLKIT_ROOT_DIR)
31 mark_as_advanced(CUDA_TOOLKIT_ROOT_DIR)
32 endif (CUDA_TOOLKIT_ROOT_DIR)
33 mark_as_advanced(CUDA_VERBOSE_BUILD)
34 mark_as_advanced(CUDA_BUILD_EMULATION)
37 find_library(CUDA_nvToolsExt_LIBRARY
39 PATHS "${CUDA_TOOLKIT_ROOT_DIR}/lib64"
40 "${CUDA_TOOLKIT_ROOT_DIR}/lib"
46 mark_as_advanced(CUDA_nvToolsExt_LIBRARY)
50 # setup CUDA compile options
52 # setup nvcc to build for all CUDA architectures. Allow user to modify the list if desired
53 if (CUDA_VERSION VERSION_GREATER 4.99)
54 set(CUDA_ARCH_LIST 20 30 35 CACHE STRING "List of target sm_ architectures to compile CUDA code for. Separate with semicolons.")
55 elseif (CUDA_VERSION VERSION_GREATER 4.1)
56 set(CUDA_ARCH_LIST 20 30 CACHE STRING "List of target sm_ architectures to compile CUDA code for. Separate with semicolons.")
58 set(CUDA_ARCH_LIST 20 CACHE STRING "List of target sm_ architectures to compile CUDA code for. Separate with semicolons.")
61 foreach(_cuda_arch ${CUDA_ARCH_LIST})
62 list(APPEND CUDA_NVCC_FLAGS "-gencode=arch=compute_${_cuda_arch},code=sm_${_cuda_arch}")
63 endforeach (_cuda_arch)
65 # need to know the minumum supported CUDA_ARCH
66 set(_cuda_arch_list_sorted ${CUDA_ARCH_LIST})
67 list(SORT _cuda_arch_list_sorted)
68 list(GET _cuda_arch_list_sorted 0 _cuda_min_arch)
69 add_definitions(-DCUDA_ARCH=${_cuda_min_arch})
71 # only generage ptx code for the maximum supported CUDA_ARCH (saves on file size)
72 list(REVERSE _cuda_arch_list_sorted)
73 list(GET _cuda_arch_list_sorted 0 _cuda_max_arch)
74 list(APPEND CUDA_NVCC_FLAGS "-gencode=arch=compute_${_cuda_max_arch},code=compute_${_cuda_max_arch}")
77 # embed the CUDA libraries into the lib dir
78 if (ENABLE_EMBED_CUDA)
80 # determine the directory of the found cuda libs
81 get_filename_component(_cuda_libdir ${CUDA_CUDART_LIBRARY} PATH)
82 FILE(GLOB _cuda_libs ${_cuda_libdir}/libcudart.* ${_cuda_libdir}/libcufft.*)
83 install(PROGRAMS ${_cuda_libs} DESTINATION ${LIB_INSTALL_DIR})
85 endif (ENABLE_EMBED_CUDA)
87 # automatically handle setting ccbin to /usr when needed
88 if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_VERSION VERSION_GREATER 2.8.7)
89 # CMAKE_CXX_COMPILER_VERSION is only available on 2.8.8 and newer
91 # need to set ccbin to when gcc is unsupported
92 # this assumes that the user is on a system where CUDA is supported and /usr/bin/gcc will work - if they aren't, then it is their problem
94 if (CUDA_VERSION VERSION_EQUAL 4.1)
95 if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.5.99)
96 message(STATUS "CUDA 4.1 doesn't support gcc >= 4.6, falling back on /usr/bin/gcc")
97 list(APPEND CUDA_NVCC_FLAGS "-ccbin;/usr/bin/gcc")
101 if (CUDA_VERSION VERSION_EQUAL 4.2)
102 if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.6.99)
103 message(STATUS "CUDA 4.2 doesn't support gcc >= 4.7, falling back on /usr/bin/gcc")
104 list(APPEND CUDA_NVCC_FLAGS "-ccbin;/usr/bin/gcc")
108 if (CUDA_VERSION VERSION_EQUAL 5.0)
109 if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.6.99)
110 message(STATUS "CUDA 5.0 doesn't support gcc >= 4.7, falling back on /usr/bin/gcc")
111 list(APPEND CUDA_NVCC_FLAGS "-ccbin;/usr/bin/gcc")