Skip to content

Commit 31febac

Browse files
committed
Support OpenMP offload with the NVIDIA compiler
These changes enable the ElectromagneticPIC OpenMP offload application to succeed (Particles/ElectromagneticPIC/Exec/OpenMP). It requires NVIDIA HPC SDK 21.3 or higher. Earlier versions of NVIDIA HPC SDK fail for one of two reasons: no interoperability between CUDA and OpenMP offload, or failure to support Fortran automatic arrays in OpenMP offload regions. I tested on Cori-GPU with nvhpc/21.3 and cuda/11.1.1.
1 parent a61b404 commit 31febac

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

Tools/GNUMake/Make.defs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,15 @@ f77EXETempDir = $(TmpBuildDir)/f/$(optionsSuffix).EXE
849849
tmpEXETempDir = $(TmpBuildDir)/t/$(optionsSuffix).EXE
850850

851851
includes = -I$(srcTempDir) -I. $(addprefix -I, $(INCLUDE_LOCATIONS)) $(addprefix -isystem , $(SYSTEM_INCLUDE_LOCATIONS))
852-
fincludes = $(includes)
852+
ifeq ($(lowercase_comp),pgi)
853+
# pgfortran-Error-Unknown switch: -isystem
854+
fincludes = $(subst -isystem,-I,$(includes))
855+
else ifeq ($(lowercase_comp),nvhpc)
856+
# nvfortran-Error-Unknown switch: -isystem
857+
fincludes = $(subst -isystem,-I,$(includes))
858+
else
859+
fincludes = $(includes)
860+
endif
853861
fmoddir = $(objEXETempDir)
854862

855863
amrexlib = $(objEXETempDir)/libamrex.a

Tools/GNUMake/comps/nvhpc.mak

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ gcc_minor_version = $(shell g++ -dumpfullversion -dumpversion | head -1 | sed -e
1919

2020
COMP_VERSION = $(nvhpc_version)
2121

22+
# -MP not supported by nvhpc and -MMD's output is put in the wrong directory
23+
USE_LEGACY_DEPFLAGS = TRUE
24+
DEPFLAGS =
25+
2226
########################################################################
2327

2428
GENERIC_NVHPC_FLAGS =
@@ -27,6 +31,18 @@ ifeq ($(USE_OMP),TRUE)
2731
GENERIC_NVHPC_FLAGS += -mp -Minfo=mp
2832
endif
2933

34+
ifeq ($(USE_OMP_OFFLOAD),TRUE)
35+
# CUDA + NVIDIA OpenMP-offload requires CUDA 11.0 or later:
36+
# "nvfortran-Fatal-Use of -Mcuda and -mp=gpu requires CUDA 11.0 or later"
37+
# My Cori GPU interactive tests worked without needing to specify
38+
# a CUDA version: I used nvhpc/21.3 and cuda/11.1.1 modules.
39+
# (The USE_ACC code path below should be revisited)
40+
GENERIC_NVHPC_FLAGS += -mp=gpu -Minfo=mp
41+
ifneq ($(CUDA_ARCH),)
42+
GENERIC_NVHPC_FLAGS += -gpu=cc$(CUDA_ARCH)
43+
endif
44+
endif
45+
3046
ifeq ($(USE_ACC),TRUE)
3147
GENERIC_NVHPC_FLAGS += -acc=gpu -Minfo=accel -mcmodel=medium
3248
ifneq ($(CUDA_ARCH),)
@@ -208,7 +224,9 @@ F90FLAGS += $(GENERIC_NVHPC_FLAGS)
208224

209225
########################################################################
210226

211-
override XTRALIBS += -lstdc++ -latomic -lnvf
227+
# Add -lrt for the missing "aio_return" symbol
228+
# /usr/common/software/sles15_cgpu/nvhpc/21.3/Linux_x86_64/21.3/compilers/lib/libnvf.a:async.o: U aio_return
229+
override XTRALIBS += -lstdc++ -latomic -lnvf -lrt
212230

213231
LINK_WITH_FORTRAN_COMPILER ?= $(USE_F_INTERFACES)
214232

Tools/libamrex/mkconfig.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ def doit(defines, undefines, comp, allow_diff_comp):
4646
elif comp == "pgi":
4747
comp_macro = "__PGI"
4848
comp_id = "PGI"
49+
elif comp == "nvhpc":
50+
comp_macro = "__NVCOMPILER"
51+
comp_id = "NVHPC"
4952
elif comp == "llvm":
5053
comp_macro = "__llvm__"
5154
comp_id = "Clang/LLVM"
@@ -89,7 +92,7 @@ def doit(defines, undefines, comp, allow_diff_comp):
8992
default="")
9093
parser.add_argument("--comp",
9194
help="compiler",
92-
choices=["gnu","intel","cray","pgi","llvm","nag","nec","ibm","hip","dpcpp"])
95+
choices=["gnu","intel","cray","pgi","nvhpc","llvm","nag","nec","ibm","hip","dpcpp"])
9396
parser.add_argument("--allow-different-compiler",
9497
help="allow an application to use a different compiler than the one used to build libamrex",
9598
choices=["TRUE","FALSE"])

0 commit comments

Comments
 (0)