Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit fbf9551

Browse files
Pramod Kumbharpramodk
authored andcommitted
Various changes (including temporary) to make XL OpenMP offload build working
* todo: temporary changes to OpenAccHelper.cmake, needs refinement * todo: see caliper linkling issue * todo: _OPENACC needs to be renamed CORENRN_ENABLE_GPU so that OpenMP based builds can use GPU offload. * todo: hardcoded CXX flags for quick build
1 parent 72cb02a commit fbf9551

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

CMake/OpenAccHelper.cmake

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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}")

coreneuron/utils/offload.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <cstddef>
1010

1111
#define nrn_pragma_stringify(x) #x
12-
#if defined(CORENEURON_ENABLE_GPU) && defined(CORENEURON_PREFER_OPENMP_OFFLOAD) && defined(_OPENMP)
12+
#if defined(CORENEURON_ENABLE_GPU) && defined(CORENRN_PREFER_OPENMP_OFFLOAD) && defined(_OPENMP)
1313
#define nrn_pragma_acc(x)
1414
#define nrn_pragma_omp(x) _Pragma(nrn_pragma_stringify(omp x))
1515
#include <omp.h>

extra/nrnivmodl_core_makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ ifeq ($(wildcard $(CORENRN_PERLEXE)),)
7171
CORENRN_PERLEXE=perl
7272
endif
7373

74-
CXXFLAGS = @CORENRN_CXX_FLAGS@
74+
CXXFLAGS = @CORENRN_CXX_FLAGS@ -lcaliper -qcuda
7575
CXX_COMPILE_CMD = $(CXX) $(CXXFLAGS) @CMAKE_CXX_COMPILE_OPTIONS_PIC@ @CORENRN_COMMON_COMPILE_DEFS@ $(INCLUDES)
7676
CXX_LINK_EXE_CMD = $(CXX) $(CXXFLAGS) @CMAKE_EXE_LINKER_FLAGS@
7777
CXX_SHARED_LIB_CMD = $(CXX) $(CXXFLAGS) @CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS@ @CMAKE_SHARED_LIBRARY_CXX_FLAGS@ @CMAKE_SHARED_LINKER_FLAGS@

0 commit comments

Comments
 (0)