public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r8-10728] [nvptx libgomp plugin] Build only in supported configurations
@ 2021-01-14 18:09 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2021-01-14 18:09 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:f9267925c648f2ccd9e4680b699e581003125bcf

commit r8-10728-gf9267925c648f2ccd9e4680b699e581003125bcf
Author: Thomas Schwinge <thomas@codesourcery.com>
Date:   Mon Nov 30 15:15:20 2020 +0100

    [nvptx libgomp plugin] Build only in supported configurations
    
    As recently again discussed in <https://gcc.gnu.org/PR97436> "[nvptx] -m32
    support", nvptx offloading other than for 64-bit host has never been
    implemented, tested, supported.  So we simply should buildn't the nvptx libgomp
    plugin in this case.
    
    This avoids build problems if, for example, in a (standard) bi-arch
    x86_64-pc-linux-gnu '-m64'/'-m32' build, libcuda is available only in a 64-bit
    variant but not in a 32-bit one, which, for example, is the case if you build
    GCC against the CUDA toolkit's 'stubs/libcuda.so' (see
    <https://stackoverflow.com/a/52784819>).
    
    This amends PR65099 commit a92defdab79a1268f4b9dcf42b937e4002a4cf15 (r225560)
    "[nvptx offloading] Only 64-bit configurations are currently supported" to
    match the way we're doing this for the HSA/GCN plugins.
    
            libgomp/
            PR libgomp/65099
            * plugin/configfrag.ac (PLUGIN_NVPTX): Restrict to supported
            configurations.
            * configure: Regenerate.
            * plugin/plugin-nvptx.c (nvptx_get_num_devices): Remove 64-bit
            check.
    
    (cherry picked from commit 6106dfb9f73a33c87108ad5b2dcd4842bdd7828e)

Diff:
---
 libgomp/configure             | 75 +++++++++++++++++++++++----------------
 libgomp/plugin/configfrag.ac  | 81 ++++++++++++++++++++++++++-----------------
 libgomp/plugin/plugin-nvptx.c |  9 -----
 3 files changed, 95 insertions(+), 70 deletions(-)

diff --git a/libgomp/configure b/libgomp/configure
index ced7606b355..2529a8e0603 100755
--- a/libgomp/configure
+++ b/libgomp/configure
@@ -15398,19 +15398,28 @@ if test x"$enable_offload_targets" != x; then
 	tgt_name=intelmic
 	;;
       nvptx*)
-        tgt_name=nvptx
-	PLUGIN_NVPTX=$tgt
-	PLUGIN_NVPTX_CPPFLAGS=$CUDA_DRIVER_CPPFLAGS
-	PLUGIN_NVPTX_LDFLAGS=$CUDA_DRIVER_LDFLAGS
-	PLUGIN_NVPTX_LIBS='-lcuda'
-
-	PLUGIN_NVPTX_save_CPPFLAGS=$CPPFLAGS
-	CPPFLAGS="$PLUGIN_NVPTX_CPPFLAGS $CPPFLAGS"
-	PLUGIN_NVPTX_save_LDFLAGS=$LDFLAGS
-	LDFLAGS="$PLUGIN_NVPTX_LDFLAGS $LDFLAGS"
-	PLUGIN_NVPTX_save_LIBS=$LIBS
-	LIBS="$PLUGIN_NVPTX_LIBS $LIBS"
-	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+	case "${target}" in
+	  aarch64*-*-* | powerpc64le-*-* | x86_64-*-*)
+	    case " ${CC} ${CFLAGS} " in
+	      *" -m32 "* | *" -mx32 "*)
+		# PR libgomp/65099: Currently, we only support offloading in
+		# 64-bit configurations.
+		PLUGIN_NVPTX=0
+		;;
+	      *)
+		tgt_name=nvptx
+		PLUGIN_NVPTX=$tgt
+		PLUGIN_NVPTX_CPPFLAGS=$CUDA_DRIVER_CPPFLAGS
+		PLUGIN_NVPTX_LDFLAGS=$CUDA_DRIVER_LDFLAGS
+		PLUGIN_NVPTX_LIBS='-lcuda'
+
+		PLUGIN_NVPTX_save_CPPFLAGS=$CPPFLAGS
+		CPPFLAGS="$PLUGIN_NVPTX_CPPFLAGS $CPPFLAGS"
+		PLUGIN_NVPTX_save_LDFLAGS=$LDFLAGS
+		LDFLAGS="$PLUGIN_NVPTX_LDFLAGS $LDFLAGS"
+		PLUGIN_NVPTX_save_LIBS=$LIBS
+		LIBS="$PLUGIN_NVPTX_LIBS $LIBS"
+		cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include "cuda.h"
 int
@@ -15426,22 +15435,30 @@ if ac_fn_c_try_link "$LINENO"; then :
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
-	CPPFLAGS=$PLUGIN_NVPTX_save_CPPFLAGS
-	LDFLAGS=$PLUGIN_NVPTX_save_LDFLAGS
-	LIBS=$PLUGIN_NVPTX_save_LIBS
-	case $PLUGIN_NVPTX in
-	  nvptx*)
-	    if test "x$CUDA_DRIVER_INCLUDE" = x \
-	       && test "x$CUDA_DRIVER_LIB" = x; then
-	      PLUGIN_NVPTX=1
-	      PLUGIN_NVPTX_CPPFLAGS='-I$(srcdir)/plugin/cuda'
-	      PLUGIN_NVPTX_LIBS='-ldl'
-	      PLUGIN_NVPTX_DYNAMIC=1
-	    else
-	      PLUGIN_NVPTX=0
-	      as_fn_error "CUDA driver package required for nvptx support" "$LINENO" 5
-	    fi
-	  ;;
+		CPPFLAGS=$PLUGIN_NVPTX_save_CPPFLAGS
+		LDFLAGS=$PLUGIN_NVPTX_save_LDFLAGS
+		LIBS=$PLUGIN_NVPTX_save_LIBS
+		case $PLUGIN_NVPTX in
+		  nvptx*)
+		    if test "x$CUDA_DRIVER_INCLUDE" = x \
+		       && test "x$CUDA_DRIVER_LIB" = x; then
+		      PLUGIN_NVPTX=1
+		      PLUGIN_NVPTX_CPPFLAGS='-I$(srcdir)/plugin/cuda'
+		      PLUGIN_NVPTX_LIBS='-ldl'
+		      PLUGIN_NVPTX_DYNAMIC=1
+		    else
+		      PLUGIN_NVPTX=0
+		      as_fn_error "CUDA driver package required for nvptx support" "$LINENO" 5
+		    fi
+		    ;;
+		esac
+		;;
+	    esac
+	    ;;
+	  *-*-*)
+	    # Target architecture not supported.
+	    PLUGIN_NVPTX=0
+	    ;;
 	esac
 	;;
       hsa*)
diff --git a/libgomp/plugin/configfrag.ac b/libgomp/plugin/configfrag.ac
index 864817d44d1..d3470f82f8c 100644
--- a/libgomp/plugin/configfrag.ac
+++ b/libgomp/plugin/configfrag.ac
@@ -148,39 +148,56 @@ if test x"$enable_offload_targets" != x; then
 	tgt_name=intelmic
 	;;
       nvptx*)
-        tgt_name=nvptx
-	PLUGIN_NVPTX=$tgt
-	PLUGIN_NVPTX_CPPFLAGS=$CUDA_DRIVER_CPPFLAGS
-	PLUGIN_NVPTX_LDFLAGS=$CUDA_DRIVER_LDFLAGS
-	PLUGIN_NVPTX_LIBS='-lcuda'
+	case "${target}" in
+	  aarch64*-*-* | powerpc64le-*-* | x86_64-*-*)
+	    case " ${CC} ${CFLAGS} " in
+	      *" -m32 "* | *" -mx32 "*)
+		# PR libgomp/65099: Currently, we only support offloading in
+		# 64-bit configurations.
+		PLUGIN_NVPTX=0
+		;;
+	      *)
+		tgt_name=nvptx
+		PLUGIN_NVPTX=$tgt
+		PLUGIN_NVPTX_CPPFLAGS=$CUDA_DRIVER_CPPFLAGS
+		PLUGIN_NVPTX_LDFLAGS=$CUDA_DRIVER_LDFLAGS
+		PLUGIN_NVPTX_LIBS='-lcuda'
 
-	PLUGIN_NVPTX_save_CPPFLAGS=$CPPFLAGS
-	CPPFLAGS="$PLUGIN_NVPTX_CPPFLAGS $CPPFLAGS"
-	PLUGIN_NVPTX_save_LDFLAGS=$LDFLAGS
-	LDFLAGS="$PLUGIN_NVPTX_LDFLAGS $LDFLAGS"
-	PLUGIN_NVPTX_save_LIBS=$LIBS
-	LIBS="$PLUGIN_NVPTX_LIBS $LIBS"
-	AC_LINK_IFELSE(
-	  [AC_LANG_PROGRAM(
-	    [#include "cuda.h"],
-	      [CUresult r = cuCtxPushCurrent (NULL);])],
-	  [PLUGIN_NVPTX=1])
-	CPPFLAGS=$PLUGIN_NVPTX_save_CPPFLAGS
-	LDFLAGS=$PLUGIN_NVPTX_save_LDFLAGS
-	LIBS=$PLUGIN_NVPTX_save_LIBS
-	case $PLUGIN_NVPTX in
-	  nvptx*)
-	    if test "x$CUDA_DRIVER_INCLUDE" = x \
-	       && test "x$CUDA_DRIVER_LIB" = x; then
-	      PLUGIN_NVPTX=1
-	      PLUGIN_NVPTX_CPPFLAGS='-I$(srcdir)/plugin/cuda'
-	      PLUGIN_NVPTX_LIBS='-ldl'
-	      PLUGIN_NVPTX_DYNAMIC=1
-	    else
-	      PLUGIN_NVPTX=0
-	      AC_MSG_ERROR([CUDA driver package required for nvptx support])
-	    fi
-	  ;;
+		PLUGIN_NVPTX_save_CPPFLAGS=$CPPFLAGS
+		CPPFLAGS="$PLUGIN_NVPTX_CPPFLAGS $CPPFLAGS"
+		PLUGIN_NVPTX_save_LDFLAGS=$LDFLAGS
+		LDFLAGS="$PLUGIN_NVPTX_LDFLAGS $LDFLAGS"
+		PLUGIN_NVPTX_save_LIBS=$LIBS
+		LIBS="$PLUGIN_NVPTX_LIBS $LIBS"
+		AC_LINK_IFELSE(
+		  [AC_LANG_PROGRAM(
+		    [#include "cuda.h"],
+		      [CUresult r = cuCtxPushCurrent (NULL);])],
+		  [PLUGIN_NVPTX=1])
+		CPPFLAGS=$PLUGIN_NVPTX_save_CPPFLAGS
+		LDFLAGS=$PLUGIN_NVPTX_save_LDFLAGS
+		LIBS=$PLUGIN_NVPTX_save_LIBS
+		case $PLUGIN_NVPTX in
+		  nvptx*)
+		    if test "x$CUDA_DRIVER_INCLUDE" = x \
+		       && test "x$CUDA_DRIVER_LIB" = x; then
+		      PLUGIN_NVPTX=1
+		      PLUGIN_NVPTX_CPPFLAGS='-I$(srcdir)/plugin/cuda'
+		      PLUGIN_NVPTX_LIBS='-ldl'
+		      PLUGIN_NVPTX_DYNAMIC=1
+		    else
+		      PLUGIN_NVPTX=0
+		      AC_MSG_ERROR([CUDA driver package required for nvptx support])
+		    fi
+		    ;;
+		esac
+		;;
+	    esac
+	    ;;
+	  *-*-*)
+	    # Target architecture not supported.
+	    PLUGIN_NVPTX=0
+	    ;;
 	esac
 	;;
       hsa*)
diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c
index 9ae60953a9a..0a4f4f410bb 100644
--- a/libgomp/plugin/plugin-nvptx.c
+++ b/libgomp/plugin/plugin-nvptx.c
@@ -835,15 +835,6 @@ nvptx_get_num_devices (void)
 {
   int n;
 
-  /* PR libgomp/65099: Currently, we only support offloading in 64-bit
-     configurations.  */
-  if (sizeof (void *) != 8)
-    {
-      GOMP_PLUGIN_debug (0, "Disabling nvptx offloading;"
-			 " only 64-bit configurations are supported\n");
-      return 0;
-    }
-
   /* This function will be called before the plugin has been initialized in
      order to enumerate available devices, but CUDA API routines can't be used
      until cuInit has been called.  Just call it now (but don't yet do any


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-01-14 18:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-14 18:09 [gcc r8-10728] [nvptx libgomp plugin] Build only in supported configurations Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).