Skip to content

Commit

Permalink
Modern CMake: naming convention for CUDA variables
Browse files Browse the repository at this point in the history
The C++ standard used for CUDA code is set in `CMAKE_CUDA_STANDARD`.
Variable `CMAKE_CUDA_VERSION` was renamed to `MINIMAL_CUDA_VERSION`
for clarity.
  • Loading branch information
jngrad committed Mar 13, 2020
1 parent 8955e09 commit b9dc5d9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,12 @@ set(CMAKE_CXX_EXTENSIONS OFF)

# CUDA compiler
if(WITH_CUDA)
set(CMAKE_CUDA_STANDARD 9.0)
set(CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD})
set(MINIMAL_CUDA_VERSION 9.0)
set(WITH_CUDA_COMPILER "nvcc" CACHE STRING "Select the CUDA compiler, can be 'nvcc' (default), 'hip', or 'clang'")
if (WITH_CUDA_COMPILER STREQUAL "nvcc")
find_package(CUDA ${CMAKE_CUDA_STANDARD} REQUIRED)
find_package(CUDACompilerNVCC ${CMAKE_CUDA_STANDARD} REQUIRED)
find_package(CUDA ${MINIMAL_CUDA_VERSION} REQUIRED)
find_package(CUDACompilerNVCC ${MINIMAL_CUDA_VERSION} REQUIRED)
elseif (WITH_CUDA_COMPILER STREQUAL "hip")
set(ROCM_HOME "/opt/rocm" CACHE FILEPATH "Path to AMD ROCm")
list(APPEND CMAKE_MODULE_PATH "${ROCM_HOME}/hip/cmake")
Expand All @@ -301,7 +302,7 @@ if(WITH_CUDA)
find_package(HIP 1.5.18494 MODULE REQUIRED)
find_package(CUDACompilerHIP 6.0 REQUIRED)
elseif (WITH_CUDA_COMPILER STREQUAL "clang")
set(CMAKE_CUDA_STANDARD 8.0)
set(MINIMAL_CUDA_VERSION 8.0)
find_package(CUDACompilerClang 6.0 REQUIRED)
else()
message(FATAL_ERROR "Cannot process option -DWITH_CUDA_COMPILER='${WITH_CUDA_COMPILER}'")
Expand Down
4 changes: 2 additions & 2 deletions cmake/FindCUDACompilerClang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ message(STATUS "Found CUDA-capable host compiler: ${CMAKE_CUDA_COMPILER}")
message(STATUS "Found CUDA version: ${CUDA_VERSION}")
message(STATUS "Found CUDA installation: ${CUDA_DIR}")

if(CUDA_VERSION VERSION_LESS ${CMAKE_CUDA_STANDARD})
message(FATAL_ERROR "${CMAKE_CUDA_COMPILER} was built for CUDA ${CUDA_VERSION}: version does not match requirements (CUDA ${CMAKE_CUDA_STANDARD}).")
if(CUDA_VERSION VERSION_LESS ${MINIMAL_CUDA_VERSION})
message(FATAL_ERROR "${CMAKE_CUDA_COMPILER} was built for CUDA ${CUDA_VERSION}: version does not match requirements (CUDA ${MINIMAL_CUDA_VERSION}).")
endif()

find_library(CUDART_LIBRARY NAMES cudart PATHS ${CUDA_DIR}/lib64 ${CUDA_DIR}/lib /usr/local/nvidia/lib NO_DEFAULT_PATH)
Expand Down
2 changes: 1 addition & 1 deletion cmake/FindCUDACompilerHIP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ string(REGEX
CMAKE_CUDA_COMPILER_VERSION
"${HIPCC_VERSION_STRING}")

list(APPEND HIP_HCC_FLAGS "-I${HIP_ROOT_DIR}/include -I${ROCM_HOME}/include -Wno-c99-designator -Wno-macro-redefined -Wno-duplicate-decl-specifier -std=c++${CMAKE_CXX_STANDARD}")
list(APPEND HIP_HCC_FLAGS "-I${HIP_ROOT_DIR}/include -I${ROCM_HOME}/include -Wno-c99-designator -Wno-macro-redefined -Wno-duplicate-decl-specifier -std=c++${CMAKE_CUDA_STANDARD}")
list(APPEND HIP_HCC_FLAGS "-pedantic -Wall -Wextra -Wno-sign-compare -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter -Wno-missing-braces -Wno-gnu-anonymous-struct -Wno-nested-anon-types -Wno-gnu-zero-variadic-macro-arguments")
if(WARNINGS_ARE_ERRORS)
list(APPEND HIP_HCC_FLAGS "-Werror")
Expand Down
2 changes: 1 addition & 1 deletion cmake/FindCUDACompilerNVCC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ set(CUDA_NVCC_FLAGS_RELEASE "${CUDA_NVCC_FLAGS_RELEASE} -O3 -DNDEBUG")
set(CUDA_NVCC_FLAGS_MINSIZEREL "${CUDA_NVCC_FLAGS_MINSIZEREL} -Os -DNDEBUG")
set(CUDA_NVCC_FLAGS_RELWITHDEBINFO "${CUDA_NVCC_FLAGS_RELWITHDEBINFO} -g -O2")

set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_52,code=sm_52 -gencode=arch=compute_52,code=compute_52 -std=c++${CMAKE_CXX_STANDARD}")
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_52,code=sm_52 -gencode=arch=compute_52,code=compute_52 -std=c++${CMAKE_CUDA_STANDARD}")
if(WARNINGS_ARE_ERRORS)
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Xcompiler -Werror")
endif()
Expand Down

0 comments on commit b9dc5d9

Please sign in to comment.