|
| 1 | +#################################################### |
| 2 | +## Only modify if you know what you're doing. ## |
| 3 | +#################################################### |
| 4 | + |
| 5 | + |
| 6 | +# Helps Eclipse/CDT find our include directories |
| 7 | +set(CMAKE_VERBOSE_MAKEFILE on) |
| 8 | + |
| 9 | +# Detect the bitness of our machine (eg 32- or 64-bit) |
| 10 | +# C-equiv: sizeof(void*) |
| 11 | +# Alt: 8*sizeof(void*) |
| 12 | +math(EXPR CMAKE_ARCH_BITNESS 8*${CMAKE_SIZEOF_VOID_P}) |
| 13 | + |
| 14 | +# For non-multi-configuration generators (eg, make, Eclipse) |
| 15 | +# The Visual Studio generator creates a single project with all these |
| 16 | +set(CMAKE_BUILD_TYPE "Release" CACHE STRING "For single-configuration generators (e.g. make) set the type of build: Release, Debug, RelWithDebugInfo, MinSizeRel") |
| 17 | +SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release" "Debug" "RelWithDebugInfo" "MinSizeRel") |
| 18 | + |
| 19 | + |
| 20 | +#################################################### |
| 21 | +## ---------------------------------------------- ## |
| 22 | +## - - ## |
| 23 | +## - Enable MPI Support - ## |
| 24 | +## - - ## |
| 25 | +## ---------------------------------------------- ## |
| 26 | +#################################################### |
| 27 | + |
| 28 | +# Begin configuring MPI options |
| 29 | +macro(enable_mpi_support) |
| 30 | + |
| 31 | + find_package("MPI" REQUIRED) |
| 32 | + |
| 33 | + # Add the MPI-specific compiler and linker flags |
| 34 | + # Also, search for #includes in MPI's paths |
| 35 | + |
| 36 | + list(APPEND CMAKE_C_COMPILE_FLAGS ${MPI_C_COMPILE_FLAGS}) |
| 37 | + list(APPEND CMAKE_C_LINK_FLAGS ${MPI_C_LINK_FLAGS}) |
| 38 | + include_directories(${MPI_C_INCLUDE_PATH}) |
| 39 | + |
| 40 | + list(APPEND CMAKE_CXX_COMPILE_FLAGS ${MPI_CXX_COMPILE_FLAGS}) |
| 41 | + list(APPEND CMAKE_CXX_LINK_FLAGS ${MPI_CXX_LINK_FLAGS}) |
| 42 | + include_directories(${MPI_CXX_INCLUDE_PATH}) |
| 43 | + |
| 44 | +endmacro(enable_mpi_support) |
| 45 | +# Done configuring MPI Options |
| 46 | + |
| 47 | + |
| 48 | +#################################################### |
| 49 | +## ---------------------------------------------- ## |
| 50 | +## - - ## |
| 51 | +## - Enable OpenMP Support - ## |
| 52 | +## - - ## |
| 53 | +## ---------------------------------------------- ## |
| 54 | +#################################################### |
| 55 | + |
| 56 | +# Begin configuring OpenMP options |
| 57 | +macro(enable_openmp_support) |
| 58 | + |
| 59 | + find_package("OpenMP" REQUIRED) |
| 60 | + |
| 61 | + # Add the OpenMP-specific compiler and linker flags |
| 62 | + list(APPEND CMAKE_CXX_FLAGS ${OpenMP_CXX_FLAGS}) |
| 63 | + list(APPEND CMAKE_C_FLAGS ${OpenMP_C_FLAGS}) |
| 64 | + |
| 65 | +endmacro(enable_openmp_support) |
| 66 | +# Done configuring OpenMP Options |
| 67 | + |
| 68 | + |
| 69 | +#################################################### |
| 70 | +## ---------------------------------------------- ## |
| 71 | +## - - ## |
| 72 | +## - Enable CUDA Support - ## |
| 73 | +## - - ## |
| 74 | +## ---------------------------------------------- ## |
| 75 | +#################################################### |
| 76 | + |
| 77 | +# Begin configuring CUDA options |
| 78 | +# This is ugly... |
| 79 | +macro(enable_cuda_support) |
| 80 | + |
| 81 | + # Hide a number of options from the default CMake screen |
| 82 | + mark_as_advanced(CLEAR CUDA_BUILD_CUBIN) |
| 83 | + mark_as_advanced(CLEAR CUDA_SDK_ROOT_DIR) |
| 84 | + mark_as_advanced(CLEAR CUDA_TOOLKIT_ROOT_DIR) |
| 85 | + mark_as_advanced(CLEAR CUDA_VERBOSE_BUILD) |
| 86 | + mark_as_advanced(CLEAR CUDA_FAST_MATH) |
| 87 | + mark_as_advanced(CLEAR CUDA_USE_CUSTOM_COMPILER) |
| 88 | + mark_as_advanced(CLEAR CUDA_VERBOSE_PTX) |
| 89 | + mark_as_advanced(CLEAR CUDA_DEVICE_VERSION) |
| 90 | + |
| 91 | + # select Compute Capability |
| 92 | + # This needs to be manually updated when devices with new CCs come out |
| 93 | + set(CUDA_DEVICE_VERSION "20" CACHE STRING "CUDA Device Version") |
| 94 | + set_property(CACHE CUDA_DEVICE_VERSION PROPERTY STRINGS "10" "11" "12" "13" "20" "21" "30" "35") |
| 95 | + |
| 96 | + # Enable fast-math for CUDA (_not_ GCC) |
| 97 | + set(CUDA_FAST_MATH TRUE CACHE BOOL "Use Fast Math Operations") |
| 98 | + |
| 99 | + # Tell nvcc to use a separate compiler for non-CUDA code. |
| 100 | + # This is useful if you need to use an older of GCC than comes by default |
| 101 | + set(CUDA_USE_CUSTOM_COMPILER FALSE CACHE BOOL "Use Custom Compiler") |
| 102 | + set(CUDA_CUSTOM_COMPILER "" CACHE STRING "Custom C++ Compiler for CUDA If Needed") |
| 103 | + |
| 104 | + # Shows register usage, etc |
| 105 | + set(CUDA_VERBOSE_PTX TRUE CACHE BOOL "Show Verbose Kernel Info During Compilation") |
| 106 | + |
| 107 | + |
| 108 | + # Let's get going... |
| 109 | + find_package("CUDA" REQUIRED) |
| 110 | + |
| 111 | + # Frequently used in the examples |
| 112 | + cuda_include_directories(${CUDA_SDK_ROOT_DIR}/common/inc) |
| 113 | + cuda_include_directories(${CUDA_SDK_ROOT_DIR}/../shared/inc) |
| 114 | + |
| 115 | + set(CUDA_SDK_LIB_DIR ${CUDA_SDK_ROOT_DIR}/common/lib |
| 116 | + ${CUDA_SDK_ROOT_DIR}/lib ${CUDA_SDK_ROOT_DIR}/../shared/lib) |
| 117 | + |
| 118 | + # these are no longer needed |
| 119 | + # # Find path to shrutil libs, from CUDA SDK |
| 120 | + # find_library(LIBSHRUTIL |
| 121 | + # NAMES shrUtils${CMAKE_ARCH_BITNESS} shrutil_${CMAKE_SYSTEM_PROCESSOR} |
| 122 | + # PATHS ${CUDA_SDK_LIB_DIR}) |
| 123 | + # find_library(LIBSHRUTIL_DBG |
| 124 | + # NAMES shrUtils${CMAKE_ARCH_BITNESS}D shrutil_${CMAKE_SYSTEM_PROCESSOR}D |
| 125 | + # PATHS ${CUDA_SDK_LIB_DIR}) |
| 126 | + # |
| 127 | + # # Find path to cutil libs, from CUDA SDK |
| 128 | + # find_library(LIBCUTIL |
| 129 | + # NAMES cutil${CMAKE_ARCH_BITNESS} cutil_${CMAKE_SYSTEM_PROCESSOR} |
| 130 | + # PATHS ${CUDA_SDK_LIB_DIR}) |
| 131 | + # find_library(LIBCUTIL_DBG |
| 132 | + # NAMES cutil${arch}D cutil_${CMAKE_SYSTEM_PROCESSOR}D |
| 133 | + # PATHS ${CUDA_SDK_LIB_DIR}) |
| 134 | + |
| 135 | + # Set custom compiler flags |
| 136 | + set(CUDA_NVCC_FLAGS "" CACHE STRING "" FORCE) |
| 137 | + |
| 138 | + if(CUDA_USE_CUSTOM_COMPILER) |
| 139 | + mark_as_advanced(CLEAR CUDA_CUSTOM_COMPILER) |
| 140 | + list(APPEND CUDA_NVCC_FLAGS "-ccbin=${CUDA_CUSTOM_COMPILER}") |
| 141 | + else() |
| 142 | + mark_as_advanced(FORCE CUDA_CUSTOM_COMPILER) |
| 143 | + endif() |
| 144 | + |
| 145 | + # Macro for setting the Compute Capability |
| 146 | + macro(set_compute_capability cc) |
| 147 | + list(APPEND CUDA_NVCC_FLAGS "-gencode=arch=compute_${cc},code=sm_${cc}") |
| 148 | + list(APPEND CUDA_NVCC_FLAGS "-gencode=arch=compute_${cc},code=compute_${cc}") |
| 149 | + endmacro(set_compute_capability) |
| 150 | + |
| 151 | + # Tell nvcc to compile for the selected Compute Capability |
| 152 | + # This can also be called from the main CMakeLists.txt to enable |
| 153 | + # support for additional CCs |
| 154 | + set_compute_capability(${CUDA_DEVICE_VERSION}) |
| 155 | + |
| 156 | + # Enable fast-math if selected |
| 157 | + if(CUDA_FAST_MATH) |
| 158 | + list(APPEND CUDA_NVCC_FLAGS "-use_fast_math") |
| 159 | + endif() |
| 160 | + |
| 161 | + # Enable verbose compile if selected |
| 162 | + if(CUDA_VERBOSE_PTX) |
| 163 | + list(APPEND CUDA_NVCC_FLAGS "--ptxas-options=-v") |
| 164 | + endif() |
| 165 | +endmacro(enable_cuda_support) |
| 166 | +# Done configuring CUDA options |
0 commit comments