@@ -50,31 +50,44 @@ if(CORENRN_ENABLE_GPU)
5050 endif ()
5151 set (CORENRN_CUDA_VERSION_SHORT "${CUDAToolkit_VERSION_MAJOR} .${CUDAToolkit_VERSION_MINOR} " )
5252 endif ()
53- # -cuda links CUDA libraries and also seems to be important to make the NVHPC do the device code
54- # linking. Without this, we had problems with linking between the explicit CUDA (.cu) device code
55- # and offloaded OpenACC/OpenMP code. Using -cuda when compiling seems to improve error messages in
56- # some cases, and to be recommended by NVIDIA. We pass -gpu=cudaX.Y to ensure that OpenACC/OpenMP
57- # code is compiled with the same CUDA version as the explicit CUDA code.
58- set (NVHPC_ACC_COMP_FLAGS "-cuda -gpu=cuda${CORENRN_CUDA_VERSION_SHORT} ,lineinfo" )
59- # Make sure that OpenACC code is generated for the same compute capabilities as the explicit CUDA
60- # code. Otherwise there may be confusing linker errors. We cannot rely on nvcc and nvc++ using the
61- # same default compute capabilities as each other, particularly on GPU-less build machines.
62- foreach (compute_capability ${CMAKE_CUDA_ARCHITECTURES} )
63- string (APPEND NVHPC_ACC_COMP_FLAGS ",cc${compute_capability} " )
64- endforeach ()
65- if (CORENRN_ACCELERATOR_OFFLOAD STREQUAL "OpenMP" )
66- # Enable OpenMP target offload to GPU and if both OpenACC and OpenMP directives are available
67- # for a region then prefer OpenMP.
68- add_compile_definitions (CORENEURON_PREFER_OPENMP_OFFLOAD)
69- string (APPEND NVHPC_ACC_COMP_FLAGS " -mp=gpu" )
70- elseif (CORENRN_ACCELERATOR_OFFLOAD STREQUAL "OpenACC" )
71- # Only enable OpenACC offload for GPU
72- string (APPEND NVHPC_ACC_COMP_FLAGS " -acc" )
53+ if (CORENRN_HAVE_NVHPC_COMPILER)
54+ # -cuda links CUDA libraries and also seems to be important to make the NVHPC do the device code
55+ # linking. Without this, we had problems with linking between the explicit CUDA (.cu) device code
56+ # and offloaded OpenACC/OpenMP code. Using -cuda when compiling seems to improve error messages in
57+ # some cases, and to be recommended by NVIDIA. We pass -gpu=cudaX.Y to ensure that OpenACC/OpenMP
58+ # code is compiled with the same CUDA version as the explicit CUDA code.
59+ set (NVHPC_ACC_COMP_FLAGS "-cuda -gpu=cuda${CORENRN_CUDA_VERSION_SHORT} ,lineinfo" )
60+ # Make sure that OpenACC code is generated for the same compute capabilities as the explicit CUDA
61+ # code. Otherwise there may be confusing linker errors. We cannot rely on nvcc and nvc++ using the
62+ # same default compute capabilities as each other, particularly on GPU-less build machines.
63+ foreach (compute_capability ${CMAKE_CUDA_ARCHITECTURES} )
64+ string (APPEND NVHPC_ACC_COMP_FLAGS ",cc${compute_capability} " )
65+ endforeach ()
66+ if (CORENRN_ACCELERATOR_OFFLOAD STREQUAL "OpenMP" )
67+ # Enable OpenMP target offload to GPU and if both OpenACC and OpenMP directives are available
68+ # for a region then prefer OpenMP.
69+ add_compile_definitions (CORENEURON_PREFER_OPENMP_OFFLOAD)
70+ string (APPEND NVHPC_ACC_COMP_FLAGS " -mp=gpu" )
71+ elseif (CORENRN_ACCELERATOR_OFFLOAD STREQUAL "OpenACC" )
72+ # Only enable OpenACC offload for GPU
73+ string (APPEND NVHPC_ACC_COMP_FLAGS " -acc" )
74+ else ()
75+ message (FATAL_ERROR "${CORENRN_ACCELERATOR_OFFLOAD} not supported with NVHPC compilers" )
76+ endif ()
77+ elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "XLClang" )
78+ set (NVHPC_ACC_COMP_FLAGS "-qsmp=omp -qoffload -qreport" )
79+ set (NVHPC_ACC_LINK_FLAGS "-qcuda -lcaliper" )
80+
81+ if (CORENRN_ENABLE_OPENMP AND CORENRN_ENABLE_OPENMP_OFFLOAD)
82+ # Enable OpenMP target offload to GPU and if both OpenACC and OpenMP directives are available
83+ # for a region then prefer OpenMP.
84+ add_compile_definitions (CORENRN_PREFER_OPENMP_OFFLOAD)
85+ endif ()
86+ elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" )
87+ set (NVHPC_ACC_COMP_FLAGS "-fopenmp -fopenmp-targets=nvptx64-nvidia-cuda -Wno-unknown-cuda-version -I${CUDAToolkit_INCLUDE_DIRS} " )
7388 else ()
74- message (FATAL_ERROR "${CORENRN_ACCELERATOR_OFFLOAD} not supported with NVHPC compilers " )
89+ message (FATAL_ERROR "${CMAKE_CXX_COMPILER_ID} is not supported in GPU builds. " )
7590 endif ()
76- set (NVHPC_ACC_COMP_FLAGS "-fopenmp -fopenmp-targets=nvptx64-nvidia-cuda -Wno-unknown-cuda-version -I${CUDAToolkit_INCLUDE_DIRS} " )
77- set (NVHPC_ACC_LINK_FLAGS)
7891 # avoid PGI adding standard compliant "-A" flags
7992 # set(CMAKE_CXX14_STANDARD_COMPILE_OPTION --c++14)
8093 string (APPEND CMAKE_EXE_LINKER_FLAGS " ${NVHPC_ACC_COMP_FLAGS} " )
0 commit comments