Skip to content

Commit

Permalink
Set CMAKE_CUDA_ARCHITECTURES early.
Browse files Browse the repository at this point in the history
  • Loading branch information
ye-luo committed Sep 30, 2021
1 parent ebf7849 commit b39aea6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CMake/ClangCompilers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ if(QMC_OMP)
CACHE STRING "Offload target architecture")
set(OPENMP_OFFLOAD_COMPILE_OPTIONS "-fopenmp-targets=${OFFLOAD_TARGET}")

if(NOT DEFINED OFFLOAD_ARCH AND OFFLOAD_TARGET MATCHES "nvptx64" AND DEFINED CMAKE_CUDA_ARCHITECTURES)
set(OFFLOAD_ARCH sm_${CMAKE_CUDA_ARCHITECTURES})
endif()

if(DEFINED OFFLOAD_ARCH)
set(OPENMP_OFFLOAD_COMPILE_OPTIONS
"${OPENMP_OFFLOAD_COMPILE_OPTIONS} -Xopenmp-target=${OFFLOAD_TARGET} -march=${OFFLOAD_ARCH}")
Expand Down
8 changes: 6 additions & 2 deletions CMake/NVHPCCompilers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ if(QMC_OMP)
if(ENABLE_OFFLOAD AND NOT CMAKE_SYSTEM_NAME STREQUAL "CrayLinuxEnvironment")
message(WARNING "QMCPACK OpenMP offload is not ready for NVIDIA HPC compiler.")
if(NOT DEFINED OFFLOAD_ARCH)
message(FATAL_ERROR "NVIDIA HPC compiler requires -gpu=ccXX option set based on the target GPU architecture! "
"Please add -DOFFLOAD_ARCH=ccXX to cmake. For example, cc70 is for Volta.")
if(DEFINED CMAKE_CUDA_ARCHITECTURES)
set(OFFLOAD_ARCH cc${CMAKE_CUDA_ARCHITECTURES})
else()
message(FATAL_ERROR "NVIDIA HPC compiler requires -gpu=ccXX option set based on the target GPU architecture! "
"Please add -DOFFLOAD_ARCH=ccXX to cmake. For example, cc70 is for Volta.")
endif()
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mp=gpu")
set(OPENMP_OFFLOAD_COMPILE_OPTIONS "-gpu=${OFFLOAD_ARCH}")
Expand Down
18 changes: 11 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ if(ENABLE_CUDA AND QMC_CUDA)
message(FATAL_ERROR "ENABLE_CUDA=ON and QMC_CUDA=ON can not be set together!")
endif(ENABLE_CUDA AND QMC_CUDA)

# set CMAKE_CUDA_ARCHITECTURES early such that offload compilers may take advantage of it
if(ENABLE_CUDA OR QMC_CUDA AND NOT QMC_CUDA2HIP)
if(DEFINED CUDA_ARCH)
unset(CUDA_ARCH CACHE)
message(FATAL_ERROR "CUDA_ARCH option has been removed. Use -DCMAKE_CUDA_ARCHITECTURES=80 if -DCUDA_ARCH=sm_80 was used.")
endif()
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
set(CMAKE_CUDA_ARCHITECTURES 70)
endif()
endif()

#--------------------------------------------------------------------
# Set compiler-time parameters
# WALKER_MAX_PROPERTIES max number of observables + 12 or so standard
Expand Down Expand Up @@ -665,19 +676,12 @@ if(QMC_CUDA OR ENABLE_CUDA)
if (CMAKE_VERSION VERSION_LESS 3.18.0)
message(FATAL_ERROR "QMC_CUDA or ENABLE_CUDA require CMake 3.18.0 or later")
endif()
if(DEFINED CUDA_ARCH)
unset(CUDA_ARCH CACHE)
message(FATAL_ERROR "CUDA_ARCH option has been removed. Use -DCMAKE_CUDA_ARCHITECTURES=80 if -DCUDA_ARCH=sm_80 was used.")
endif()
# a few production machines use CUDA 10 which only supports C++14.
if(NOT DEFINED CMAKE_CUDA_STANDARD)
set(CMAKE_CUDA_STANDARD 14)
endif()
set(CMAKE_CUDA_STANDARD_REQUIRED TRUE)
set(CMAKE_CUDA_EXTENSIONS OFF)
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
set(CMAKE_CUDA_ARCHITECTURES 70)
endif()
enable_language(CUDA)
find_package(CUDAToolkit REQUIRED)
# Automatically set the default NVCC flags
Expand Down

0 comments on commit b39aea6

Please sign in to comment.