]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
nvptx/mkoffload.cc: Warn instead of error when reverse offload is not possible
authorTobias Burnus <tobias@codesourcery.com>
Mon, 12 Sep 2022 13:25:13 +0000 (15:25 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Mon, 12 Sep 2022 13:25:13 +0000 (15:25 +0200)
Reverse offload requests at least -misa=sm_35; with this patch, a warning
instead of an error is shown, still permitting reverse offload for all
other configured device types. This is achieved by not calling
GOMP_offload_register_ver (and stopping generating pointless 'static const char'
variables, once known.)

The tool_name as progname changes adds "nvptx " and "gcn " to the
"mkoffload: warning/error:" diagnostic.

gcc/ChangeLog:

* config/nvptx/mkoffload.cc (process): Replace a fatal_error by
a warning + not enabling offloading if -misa=sm_30 prevents
reverse offload.
(main): Use tool_name as progname for diagnostic.
* config/gcn/mkoffload.cc (main): Likewise.

libgomp/ChangeLog:

* libgomp.texi (Offload-Target Specifics: nvptx): Document
that reverse offload requires >= -march=sm_35.
* testsuite/libgomp.c-c++-common/requires-4.c: Build for nvptx
with -misa=sm_35.
* testsuite/libgomp.c-c++-common/requires-5.c: Likewise.
* testsuite/libgomp.c-c++-common/requires-6.c: Likewise.
* testsuite/libgomp.c-c++-common/reverse-offload-1.c: Likewise.
* testsuite/libgomp.fortran/reverse-offload-1.f90: Likewise.
* testsuite/libgomp.c/reverse-offload-sm30.c: New test.

gcc/config/gcn/mkoffload.cc
gcc/config/nvptx/mkoffload.cc
libgomp/libgomp.texi
libgomp/testsuite/libgomp.c-c++-common/requires-4.c
libgomp/testsuite/libgomp.c-c++-common/requires-5.c
libgomp/testsuite/libgomp.c-c++-common/requires-6.c
libgomp/testsuite/libgomp.c-c++-common/reverse-offload-1.c
libgomp/testsuite/libgomp.c/reverse-offload-sm30.c [new file with mode: 0644]
libgomp/testsuite/libgomp.fortran/reverse-offload-1.f90

index 24d327355e3cb825eb1781d46d8410c35701c9de..64037806acfc1f85568a540d57a6dcebbdf0a92a 100644 (file)
@@ -805,7 +805,7 @@ main (int argc, char **argv)
   FILE *cfile = stdout;
   const char *outname = 0;
 
-  progname = "mkoffload";
+  progname = tool_name;
   diagnostic_initialize (global_dc, 0);
 
   obstack_init (&files_to_cleanup);
index 834b2059aac2102d49a425c89fa95ab378835a9b..854cd72f3c74778694dc5977b9322f7e6129d8f7 100644 (file)
@@ -324,9 +324,19 @@ process (FILE *in, FILE *out, uint32_t omp_requires)
        {
          if (sm_ver && sm_ver[0] == '3' && sm_ver[1] == '0'
              && sm_ver[2] == '\n')
-           fatal_error (input_location,
-                        "%<omp requires reverse_offload%> requires at least "
-                        "%<sm_35%> for %<-misa=%>");
+           {
+             warning_at (input_location, 0,
+                         "%<omp requires reverse_offload%> requires at "
+                         "least %<sm_35%> for "
+                         "%<-foffload-options=nvptx-none=-march=%> - disabling"
+                         " offload-code generation for this device type");
+             /* As now an empty file is compiled and there is no call to
+                GOMP_offload_register_ver, this device type is effectively
+                disabled.  */
+             fflush (out);
+             ftruncate (fileno (out), 0);
+             return;
+           }
          sm_ver2 = sm_ver;
          version2 = version;
        }
@@ -526,7 +536,7 @@ main (int argc, char **argv)
   FILE *out = stdout;
   const char *outname = 0;
 
-  progname = "mkoffload";
+  progname = tool_name;
   diagnostic_initialize (global_dc, 0);
 
   if (atexit (mkoffload_cleanup) != 0)
index 4eaad4348bbd82e86d404215336f32d132297cdf..1f402d6df7921df34203687be1f15e9a6069cfb3 100644 (file)
@@ -4386,6 +4386,9 @@ The implementation remark:
 @item I/O within OpenMP target regions and OpenACC parallel/kernels is supported
       using the C library @code{printf} functions and the Fortran
       @code{print}/@code{write} statements.
+@item Compilation OpenMP code that contains @code{requires reverse_offload}
+      requires at least @code{-march=sm_35}, compiling for @code{-march=sm_30}
+      is not supported.
 @end itemize
 
 
index 6ed5a5f647a8b5656f7b3cb944843097d6f38626..5883eff0d9398fb80369a7b4b5f78485ee167957 100644 (file)
@@ -1,4 +1,5 @@
 /* { dg-additional-options "-flto" } */
+/* { dg-additional-options "-foffload-options=nvptx-none=-misa=sm_35" { target { offload_target_nvptx } } } */
 /* { dg-additional-sources requires-4-aux.c } */
 
 /* Check no diagnostic by device-compiler's or host compiler's lto1.
index 7fe0c735d277e8acd7de610358b8970546901e10..d43d78db6fab61cdc34804a3adf38245576f5bf5 100644 (file)
@@ -1,3 +1,4 @@
+/* { dg-additional-options "-foffload-options=nvptx-none=-misa=sm_35" { target { offload_target_nvptx } } } */
 /* { dg-additional-sources requires-5-aux.c } */
 
 /* Depending on offload device capabilities, it may print something like the
index b00c7459bbc3094ccfa704cf0fc4a19695f4f4b5..a25b4d2dedd456898e7e477aa0e3d31a00875f89 100644 (file)
@@ -1,3 +1,5 @@
+/* { dg-additional-options "-foffload-options=nvptx-none=-misa=sm_35" { target { offload_target_nvptx } } } */
+
 #pragma omp requires unified_shared_memory, unified_address, reverse_offload
 
 /* The requires line is not active as there is none of:
index 976e129f56033d557df00c5de126e5cbdb02c551..52d828caf1cf0f4c250586116c3bbf19f59b1869 100644 (file)
@@ -1,4 +1,5 @@
 /* { dg-do run }  */
+/* { dg-additional-options "-foffload-options=nvptx-none=-misa=sm_35" { target { offload_target_nvptx } } } */
 /* { dg-additional-sources reverse-offload-1-aux.c } */
 
 /* Check that reverse offload works in particular:
diff --git a/libgomp/testsuite/libgomp.c/reverse-offload-sm30.c b/libgomp/testsuite/libgomp.c/reverse-offload-sm30.c
new file mode 100644 (file)
index 0000000..fbfeae1
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do link { target { offload_target_nvptx } } } */
+/* { dg-additional-options "-foffload-options=nvptx-none=-march=sm_30 -foffload=-mptx=_" } */
+
+#pragma omp requires reverse_offload
+
+int
+main ()
+{
+  #pragma omp target
+    {
+    }
+  return 0;
+}
+
+/* { dg-warning "'omp requires reverse_offload' requires at least 'sm_35' for '-foffload-options=nvptx-none=-march=' - disabling offload-code generation for this device type" "" { target *-*-* } 0 } */
index 7cfb8b6552ef7cd94c29a69cfb3665d11ae016c2..de68011f8f7f52e3966032383be1b43da30fdddc 100644 (file)
@@ -1,4 +1,5 @@
 ! { dg-do run }
+! { dg-additional-options "-foffload-options=nvptx-none=-misa=sm_35" { target { offload_target_nvptx } } }
 ! { dg-additional-sources reverse-offload-1-aux.f90 }
 
 ! Check that reverse offload works in particular: