From d33d7f4b18711dd963668917a08aaf269b821b7d Mon Sep 17 00:00:00 2001 From: Anthony Danalis Date: Thu, 26 Sep 2024 19:41:45 +0000 Subject: [PATCH] CUDA Tests: Conditionally adding -fpic to nvcc. If the PAPI shared library is built (either because the user explicitly configured with --with-shared-lib=yes, or by default because the user did not specify anything) then nvcc will be instructed to create position-independent code through the flag "-fpic". If the user has disabled the shared library (by configuring with --with-shared-lib=no) then this flag is not passed to nvcc. --- src/components/Makefile_comp_tests.target.in | 1 + src/components/cuda/tests/Makefile | 3 +++ src/configure | 4 ++++ src/configure.in | 3 +++ 4 files changed, 11 insertions(+) diff --git a/src/components/Makefile_comp_tests.target.in b/src/components/Makefile_comp_tests.target.in index b1e2a9892..0c949e34d 100644 --- a/src/components/Makefile_comp_tests.target.in +++ b/src/components/Makefile_comp_tests.target.in @@ -21,6 +21,7 @@ OPTFLAGS= @OPTFLAGS@ TOPTFLAGS= @TOPTFLAGS@ OMPCFLGS = @OMPCFLGS@ UTILOBJS = $(TESTLIB) +BUILD_SHARED_LIB = @BUILD_SHARED_LIB@ BUILD_LIBSDE_SHARED = @BUILD_LIBSDE_SHARED@ BUILD_LIBSDE_STATIC = @BUILD_LIBSDE_STATIC@ NO_MPI_TESTS = @NO_MPI_TESTS@ diff --git a/src/components/cuda/tests/Makefile b/src/components/cuda/tests/Makefile index a2f337a98..d4129c85e 100644 --- a/src/components/cuda/tests/Makefile +++ b/src/components/cuda/tests/Makefile @@ -16,6 +16,9 @@ NVCC = $(PAPI_CUDA_ROOT)/bin/nvcc PAPI_FLAG = -DPAPI # Comment this line for tests to run without PAPI profiling NVCFLAGS = -g -ccbin='$(CC)' $(PAPI_FLAG) +ifeq ($(BUILD_SHARED_LIB),yes) + NVCFLAGS += -Xcompiler -fpic +endif CFLAGS += -g $(PAPI_FLAG) INCLUDE += -I$(PAPI_CUDA_ROOT)/include CUDALIBS = -L$(PAPI_CUDA_ROOT)/lib64 -lcudart -lcuda diff --git a/src/configure b/src/configure index 7b2f712ae..cc7e9ab8d 100755 --- a/src/configure +++ b/src/configure @@ -698,6 +698,7 @@ arch LIBSDEFLAGS BUILD_LIBSDE_STATIC BUILD_LIBSDE_SHARED +BUILD_SHARED_LIB LDL LRT EGREP @@ -5666,9 +5667,12 @@ if test "$shared_lib" = "no" -a "$static_lib" = "no"; then as_fn_error $? "Both shared and static libs are disabled" "$LINENO" 5 fi +BUILD_SHARED_LIB="no" if test "$shared_lib" = "yes"; then + BUILD_SHARED_LIB="yes" papiLIBS="shared" fi + if test "$static_lib" = "yes"; then papiLIBS="$papiLIBS static" fi diff --git a/src/configure.in b/src/configure.in index 7736565da..e6ec941b1 100644 --- a/src/configure.in +++ b/src/configure.in @@ -967,9 +967,12 @@ if test "$shared_lib" = "no" -a "$static_lib" = "no"; then AC_MSG_ERROR(Both shared and static libs are disabled) fi +BUILD_SHARED_LIB="no" if test "$shared_lib" = "yes"; then + BUILD_SHARED_LIB="yes" papiLIBS="shared" fi +AC_SUBST(BUILD_SHARED_LIB) if test "$static_lib" = "yes"; then papiLIBS="$papiLIBS static" fi