From ffbeb84dfa23ee1da4ad36260628113186d3e0d2 Mon Sep 17 00:00:00 2001 From: Ralf Seidler Date: Mon, 7 Feb 2022 11:12:46 +0000 Subject: [PATCH] Fixing compilation errors with clang 13 and OpenMP and MPI, fixing issue #102 --- .../0_Introduction/UnifiedMemoryStreams/Makefile | 13 ++++++++++++- Samples/0_Introduction/cudaOpenMP/Makefile | 14 +++++++++++++- Samples/0_Introduction/simpleMPI/Makefile | 4 ++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Samples/0_Introduction/UnifiedMemoryStreams/Makefile b/Samples/0_Introduction/UnifiedMemoryStreams/Makefile index ba7b78b45..b8bcad3db 100644 --- a/Samples/0_Introduction/UnifiedMemoryStreams/Makefile +++ b/Samples/0_Introduction/UnifiedMemoryStreams/Makefile @@ -288,13 +288,24 @@ LIBRARIES := # Attempt to compile a minimal OpenMP application. If a.out exists, OpenMP is properly set up. ifneq (,$(filter $(TARGET_OS),linux android)) +# Special treatment for Clang to not use standard OMP Library and fix OMP 5 bug in Clang 13 +ifneq (,$(findstring "clang",$(HOST_COMPILER))) ifneq (,$(filter $(TARGET_OS), android)) LIBRARIES += -lomp else LIBRARIES += -lgomp endif - ALL_CCFLAGS += -Xcompiler -fopenmp +else + ALL_CCFLAGS += -Xcompiler -fopenmp + ALL_LDFLAGS += -Xcompiler -fopenmp + COMPILER_VERSION= $(shell $(HOST_COMPILER) --version) +ifneq (,$(findstring 13.,$(COMPILER_VERSION))) + ALL_CCFLAGS += -Xcompiler -fopenmp -Xcompiler -fopenmp-version=45 + ALL_LDFLAGS += -Xcompiler -fopenmp -Xcompiler -fopenmp-version=45 +endif +endif + $(shell echo "#include " > test.c ; echo "int main() { omp_get_num_threads(); return 0; }" >> test.c ; $(HOST_COMPILER) -fopenmp test.c) OPENMP ?= $(shell find a.out 2>/dev/null) diff --git a/Samples/0_Introduction/cudaOpenMP/Makefile b/Samples/0_Introduction/cudaOpenMP/Makefile index 476ddbc9d..43403fe41 100644 --- a/Samples/0_Introduction/cudaOpenMP/Makefile +++ b/Samples/0_Introduction/cudaOpenMP/Makefile @@ -294,13 +294,25 @@ LIBRARIES := # Attempt to compile a minimal OpenMP application. If a.out exists, OpenMP is properly set up. ifneq (,$(filter $(TARGET_OS),linux android)) + +# Special treatment for Clang to not use standard OMP Library and fix OMP 5 bug in Clang 13 +ifneq (,$(findstring "clang",$(HOST_COMPILER))) ifneq (,$(filter $(TARGET_OS), android)) LIBRARIES += -lomp else LIBRARIES += -lgomp endif - ALL_CCFLAGS += -Xcompiler -fopenmp +else + ALL_CCFLAGS += -Xcompiler -fopenmp + ALL_LDFLAGS += -Xcompiler -fopenmp + COMPILER_VERSION= $(shell $(HOST_COMPILER) --version) +ifneq (,$(findstring 13.,$(COMPILER_VERSION))) + ALL_CCFLAGS += -Xcompiler -fopenmp -Xcompiler -fopenmp-version=45 + ALL_LDFLAGS += -Xcompiler -fopenmp -Xcompiler -fopenmp-version=45 +endif +endif + $(shell echo "#include " > test.c ; echo "int main() { omp_get_num_threads(); return 0; }" >> test.c ; $(HOST_COMPILER) -fopenmp test.c) OPENMP ?= $(shell find a.out 2>/dev/null) diff --git a/Samples/0_Introduction/simpleMPI/Makefile b/Samples/0_Introduction/simpleMPI/Makefile index 49fc56c36..006cc8e10 100644 --- a/Samples/0_Introduction/simpleMPI/Makefile +++ b/Samples/0_Introduction/simpleMPI/Makefile @@ -164,6 +164,10 @@ NVCCFLAGS := -m${TARGET_SIZE} CCFLAGS := LDFLAGS := +# Special treatment for Clang +ifneq (,$(findstring clang,$(HOST_COMPILER))) + CCFLAGS+= -fPIE +endif # build flags ifeq ($(TARGET_OS),darwin) LDFLAGS += -rpath $(CUDA_PATH)/lib