diff mbox

[gomp4,PR,testsuite/70579,PR,testsuite/70580] Fix test cases failing because of the compiler's "avoid offloading" decision (was: Also test -O0 for OpenACC C, C++ offloading test cases)

Message ID 871t6g7b5d.fsf@hertz.schwinge.homeip.net
State New
Headers show

Commit Message

Thomas Schwinge April 8, 2016, 8:33 a.m. UTC
Hi!

On Thu, 7 Apr 2016 18:29:45 +0200, I wrote:
> On Fri, 1 Apr 2016 10:55:49 +0200, I wrote:
> > On Thu, 24 Mar 2016 22:31:29 +0100, I wrote:
> > > On Wed, 23 Mar 2016 19:57:50 +0100, Bernd Schmidt <bschmidt@redhat.com> wrote:
> > > > Ok with [...].
> > > 
> > > Thanks for the review; committed in r234471:
> > 
> > >     Also test -O0 for OpenACC C, C++ offloading test cases
> > 
> > Merged into gomp-4_0-branch in r234664:
> 
> > --- libgomp/testsuite/libgomp.oacc-c-c++-common/host_data-1.c
> > +++ libgomp/testsuite/libgomp.oacc-c-c++-common/host_data-1.c
> > @@ -1,5 +1,6 @@
> >  /* { dg-do run { target openacc_nvidia_accel_selected } } */
> >  /* { dg-additional-options "-lcuda -lcublas -lcudart" } */
> > +/* { dg-xfail-run-if "TODO" { *-*-* } { "-O0" } { "" } } */
> >  
> >  #include <stdlib.h>
> >  #include <openacc.h>
> 
> Filed <https://gcc.gnu.org/PR70579>.
> 
> > --- libgomp/testsuite/libgomp.oacc-c-c++-common/if-1.c
> > +++ libgomp/testsuite/libgomp.oacc-c-c++-common/if-1.c
> > @@ -1,3 +1,5 @@
> > +/* { dg-xfail-run-if "TODO" { *-*-* } { "-O0" } { "" } } */
> > +
> >  #include <openacc.h>
> >  #include <stdlib.h>
> >  #include <stdbool.h>
> 
> Filed <https://gcc.gnu.org/PR70580>.
> 
> The both PASS on trunk.
> 
> Currently unclear if it's the same underlying problem or not.

Committed to gomp-4_0-branch in r234823:

commit 8a56a354bea62a280ec46db00a8956184403ff6e
Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Fri Apr 8 08:31:40 2016 +0000

    [PR testsuite/70579, PR testsuite/70580] Fix test cases failing because of the compiler's "avoid offloading" decision
    
    	libgomp/
    	PR testsuite/70579
    	PR testsuite/70580
    	* testsuite/libgomp.oacc-c-c++-common/host_data-1.c: Initialize
    	the runtime for acc_device_nvidia.
    	* testsuite/libgomp.oacc-c-c++-common/if-1.c: Cope with
    	"avoid offloading" situation.
    	* libgomp.texi (Enabling OpenACC): Elaborate on interactions of
    	"avoid offloading".
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@234823 138bc75d-0d04-0410-961f-82ee72b054a4
---
 libgomp/ChangeLog.gomp                             |  11 +
 libgomp/libgomp.texi                               |   9 +
 .../libgomp.oacc-c-c++-common/host_data-1.c        |   4 +-
 libgomp/testsuite/libgomp.oacc-c-c++-common/if-1.c | 316 +++++++++++----------
 4 files changed, 184 insertions(+), 156 deletions(-)



Grüße
 Thomas
diff mbox

Patch

diff --git libgomp/ChangeLog.gomp libgomp/ChangeLog.gomp
index f54de33..1c99026 100644
--- libgomp/ChangeLog.gomp
+++ libgomp/ChangeLog.gomp
@@ -1,3 +1,14 @@ 
+2016-04-08  Thomas Schwinge  <thomas@codesourcery.com>
+
+	PR testsuite/70579
+	PR testsuite/70580
+	* testsuite/libgomp.oacc-c-c++-common/host_data-1.c: Initialize
+	the runtime for acc_device_nvidia.
+	* testsuite/libgomp.oacc-c-c++-common/if-1.c: Cope with
+	"avoid offloading" situation.
+	* libgomp.texi (Enabling OpenACC): Elaborate on interactions of
+	"avoid offloading".
+
 2016-04-04  Thomas Schwinge  <thomas@codesourcery.com>
 
 	* testsuite/libgomp.oacc-c-c++-common/asyncwait-1.c: Don't XFAIL.
diff --git libgomp/libgomp.texi libgomp/libgomp.texi
index 350fb82..7cb677c 100644
--- libgomp/libgomp.texi
+++ libgomp/libgomp.texi
@@ -1824,6 +1824,15 @@  the option @option{-foffload-force} to force offloading in such cases.
 Alternatively, offloading is also enabled if a specific device type is
 requested, in a call to @code{acc_init} or by setting the
 @env{ACC_DEVICE_TYPE} environment variable, for example.
+If you expect code to be offloaded no matter the overhead, for
+example, when preparing data on a non-shared memory offloading device
+for later use in an OpenACC @code{host_data} construct, be sure to
+force offloading, to get the device memory initialized.
+For example, if calling into the cuBLAS library (@ref{OpenACC Library
+Interoperability}) from an OpenACC @code{host_data} construct, this
+program is portable only to @code{acc_device_nvidia} devices, so it's
+good practice then to initialize the runtime with an explicit
+@code{acc_init (acc_device_nvidia)} call.
 
 A complete description of all OpenACC directives accepted may be found in 
 the @uref{http://www.openacc.org/, OpenACC} Application Programming
diff --git libgomp/testsuite/libgomp.oacc-c-c++-common/host_data-1.c libgomp/testsuite/libgomp.oacc-c-c++-common/host_data-1.c
index b97d877..d19aa20 100644
--- libgomp/testsuite/libgomp.oacc-c-c++-common/host_data-1.c
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/host_data-1.c
@@ -1,6 +1,5 @@ 
 /* { dg-do run { target openacc_nvidia_accel_selected } } */
 /* { dg-additional-options "-lcuda -lcublas -lcudart" } */
-/* { dg-xfail-run-if "TODO" { *-*-* } { "-O0" } { "" } } */
 
 #include <stdlib.h>
 #include <openacc.h>
@@ -30,6 +29,9 @@  saxpy_target (int n, float a, float *x, float *y)
 int
 main(int argc, char **argv)
 {
+  /* We're using cuBLAS, so excpect to be using a Nvidia GPU.  */
+  acc_init (acc_device_nvidia);
+
 #define N 8
   int i;
   float x_ref[N], y_ref[N];
diff --git libgomp/testsuite/libgomp.oacc-c-c++-common/if-1.c libgomp/testsuite/libgomp.oacc-c-c++-common/if-1.c
index ade064d..cc250f8 100644
--- libgomp/testsuite/libgomp.oacc-c-c++-common/if-1.c
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/if-1.c
@@ -1,5 +1,3 @@ 
-/* { dg-xfail-run-if "TODO" { *-*-* } { "-O0" } { "" } } */
-
 #include <openacc.h>
 #include <stdlib.h>
 #include <stdbool.h>
@@ -23,6 +21,11 @@  main(int argc, char **argv)
     for (i = 0; i < N; i++)
         a[i] = 4.0;
 
+    /* Are we actually offloading?  */
+    bool offloading;
+#pragma acc parallel copyout(offloading)
+    offloading = acc_on_device (acc_device_not_host);
+
 #pragma acc parallel copyin(a[0:N]) copyout(b[0:N]) if(1)
     {
         int ii;
@@ -36,11 +39,10 @@  main(int argc, char **argv)
         }
     }
 
-#if ACC_MEM_SHARED
-    exp = 5.0;
-#else
-    exp = 4.0;
-#endif
+    if (offloading)
+      exp = 4.0;
+    else
+      exp = 5.0;
 
     for (i = 0; i < N; i++)
     {
@@ -86,11 +88,10 @@  main(int argc, char **argv)
         }
     }
 
-#if ACC_MEM_SHARED
-    exp = 9.0;
-#else
-    exp = 8.0;
-#endif
+    if (offloading)
+      exp = 8.0;
+    else
+      exp = 9.0;
 
     for (i = 0; i < N; i++)
     {
@@ -136,11 +137,10 @@  main(int argc, char **argv)
         }
     }
 
-#if ACC_MEM_SHARED
-    exp = 17.0;
-#else
-    exp = 16.0;
-#endif
+    if (offloading)
+      exp = 16.0;
+    else
+      exp = 17.0;
 
     for (i = 0; i < N; i++)
     {
@@ -188,11 +188,10 @@  main(int argc, char **argv)
         }
     }
 
-#if ACC_MEM_SHARED
-    exp = 23.0;
-#else
-    exp = 22.0;
-#endif
+    if (offloading)
+      exp = 22.0;
+    else
+      exp = 23.0;
 
     for (i = 0; i < N; i++)
     {
@@ -242,11 +241,10 @@  main(int argc, char **argv)
         }
     }
 
-#if ACC_MEM_SHARED
-    exp = 50.0;
-#else
-    exp = 49.0;
-#endif
+    if (offloading)
+      exp = 49.0;
+    else
+      exp = 50.0;
 
     for (i = 0; i < N; i++)
     {
@@ -294,11 +292,10 @@  main(int argc, char **argv)
         }
     }
 
-#if ACC_MEM_SHARED
-    exp = 92.0;
-#else
-    exp = 91.0;
-#endif
+    if (offloading)
+      exp = 91.0;
+    else
+      exp = 92.0;
 
     for (i = 0; i < N; i++)
     {
@@ -322,11 +319,10 @@  main(int argc, char **argv)
         }
     }
 
-#if ACC_MEM_SHARED
-    exp = 44.0;
-#else
-    exp = 43.0;
-#endif
+    if (offloading)
+      exp = 43.0;
+    else
+      exp = 44.0;
 
     for (i = 0; i < N; i++)
     {
@@ -362,15 +358,18 @@  main(int argc, char **argv)
         b[i] = 9.0;
     }
 
-#if ACC_MEM_SHARED
-    exp = 0.0;
-    exp2 = 0.0;
-#else
-    acc_map_data (a, d_a, N * sizeof (float));
-    acc_map_data (b, d_b, N * sizeof (float));
-    exp = 3.0;
-    exp2 = 9.0;
-#endif
+    if (offloading)
+      {
+	acc_map_data (a, d_a, N * sizeof (float));
+	acc_map_data (b, d_b, N * sizeof (float));
+	exp = 3.0;
+	exp2 = 9.0;
+      }
+    else
+      {
+	exp = 0.0;
+	exp2 = 0.0;
+      }
 
 #pragma acc update device(a[0:N], b[0:N]) if(1)
 
@@ -441,10 +440,11 @@  main(int argc, char **argv)
             abort();
     }
 
-#if !ACC_MEM_SHARED
-    acc_unmap_data (a);
-    acc_unmap_data (b);
-#endif
+    if (offloading)
+      {
+	acc_unmap_data (a);
+	acc_unmap_data (b);
+      }
 
     acc_free (d_a);
     acc_free (d_b);
@@ -481,17 +481,15 @@  main(int argc, char **argv)
     }
 
 #pragma acc data copyin(a[0:N]) copyout(b[0:N]) if(0)
-{
-#if !ACC_MEM_SHARED
-    if (acc_is_present (a, N * sizeof (float)))
-        abort ();
-#endif
-
-#if !ACC_MEM_SHARED
-    if (acc_is_present (b, N * sizeof (float)))
-        abort ();
-#endif
-}
+    {
+      if (offloading)
+	{
+	  if (acc_is_present (a, N * sizeof (float)))
+	    abort ();
+	  if (acc_is_present (b, N * sizeof (float)))
+	    abort ();
+	}
+    }
 
     for (i = 0; i < N; i++)
     {
@@ -500,18 +498,20 @@  main(int argc, char **argv)
     }
 
 #pragma acc data copyin(a[0:N]) if(1)
-{
-#if !ACC_MEM_SHARED
-    if (!acc_is_present (a, N * sizeof (float)))
-        abort ();
-#endif
+    {
+      if (offloading)
+	{
+	  if (!acc_is_present (a, N * sizeof (float)))
+	    abort ();
+	}
 
 #pragma acc data copyout(b[0:N]) if(0)
-    {
-#if !ACC_MEM_SHARED
-        if (acc_is_present (b, N * sizeof (float)))
-            abort ();
-#endif
+      {
+	if (offloading)
+	  {
+	    if (acc_is_present (b, N * sizeof (float)))
+	      abort ();
+	  }
 
 #pragma acc data copyout(b[0:N]) if(1)
         {
@@ -526,10 +526,11 @@  main(int argc, char **argv)
             }
         }
 
-#if !ACC_MEM_SHARED
-        if (acc_is_present (b, N * sizeof (float)))
-            abort ();
-#endif
+	if (offloading)
+	  {
+	    if (acc_is_present (b, N * sizeof (float)))
+	      abort ();
+	  }
     }
 }
 
@@ -541,72 +542,81 @@  main(int argc, char **argv)
 
 #pragma acc enter data copyin (b[0:N]) if (0)
 
-#if !ACC_MEM_SHARED
-    if (acc_is_present (b, N * sizeof (float)))
-	abort ();
-#endif
+    if (offloading)
+      {
+	if (acc_is_present (b, N * sizeof (float)))
+	  abort ();
+      }
 
 #pragma acc exit data delete (b[0:N]) if (0)
 
 #pragma acc enter data copyin (b[0:N]) if (1)
 
-#if !ACC_MEM_SHARED
-    if (!acc_is_present (b, N * sizeof (float)))
-	abort ();
-#endif
+    if (offloading)
+      {
+	if (!acc_is_present (b, N * sizeof (float)))
+	  abort ();
+      }
 
 #pragma acc exit data delete (b[0:N]) if (1)
 
-#if !ACC_MEM_SHARED
-    if (acc_is_present (b, N * sizeof (float)))
-	abort ();
-#endif
+    if (offloading)
+      {
+	if (acc_is_present (b, N * sizeof (float)))
+	  abort ();
+      }
 
 #pragma acc enter data copyin (b[0:N]) if (zero)
 
-#if !ACC_MEM_SHARED
-    if (acc_is_present (b, N * sizeof (float)))
-	abort ();
-#endif
+    if (offloading)
+      {
+	if (acc_is_present (b, N * sizeof (float)))
+	  abort ();
+      }
 
 #pragma acc exit data delete (b[0:N]) if (zero)
 
 #pragma acc enter data copyin (b[0:N]) if (one)
 
-#if !ACC_MEM_SHARED
-    if (!acc_is_present (b, N * sizeof (float)))
-	abort ();
-#endif
+    if (offloading)
+      {
+	if (!acc_is_present (b, N * sizeof (float)))
+	  abort ();
+      }
 
 #pragma acc exit data delete (b[0:N]) if (one)
 
-#if !ACC_MEM_SHARED
-    if (acc_is_present (b, N * sizeof (float)))
-	abort ();
-#endif
+    if (offloading)
+      {
+	if (acc_is_present (b, N * sizeof (float)))
+	  abort ();
+      }
 
 #pragma acc enter data copyin (b[0:N]) if (one == 0)
 
-#if !ACC_MEM_SHARED
-    if (acc_is_present (b, N * sizeof (float)))
-	abort ();
-#endif
+    if (offloading)
+      {
+	if (acc_is_present (b, N * sizeof (float)))
+	  abort ();
+      }
 
 #pragma acc exit data delete (b[0:N]) if (one == 0)
 
 #pragma acc enter data copyin (b[0:N]) if (one == 1)
 
-#if !ACC_MEM_SHARED
-    if (!acc_is_present (b, N * sizeof (float)))
-	abort ();
-#endif
+    if (offloading)
+      {
+	if (!acc_is_present (b, N * sizeof (float)))
+	  abort ();
+      }
 
 #pragma acc exit data delete (b[0:N]) if (one == 1)
 
-#if !ACC_MEM_SHARED
-    if (acc_is_present (b, N * sizeof (float)))
-	abort ();
-#endif
+    if (offloading)
+      {
+	if (acc_is_present (b, N * sizeof (float)))
+	  abort ();
+      }
 
     for (i = 0; i < N; i++)
         a[i] = 4.0;
@@ -624,11 +634,10 @@  main(int argc, char **argv)
         }
     }
 
-#if ACC_MEM_SHARED
-    exp = 5.0;
-#else
-    exp = 4.0;
-#endif
+    if (offloading)
+      exp = 4.0;
+    else
+      exp = 5.0;
 
     for (i = 0; i < N; i++)
     {
@@ -674,11 +683,10 @@  main(int argc, char **argv)
         }
     }
 
-#if ACC_MEM_SHARED
-    exp = 9.0;
-#else
-    exp = 8.0;
-#endif
+    if (offloading)
+      exp = 8.0;
+    else
+      exp = 9.0;
 
     for (i = 0; i < N; i++)
     {
@@ -724,11 +732,10 @@  main(int argc, char **argv)
         }
     }
 
-#if ACC_MEM_SHARED
-    exp = 17.0;
-#else
-    exp = 16.0;
-#endif
+    if (offloading)
+      exp = 16.0;
+    else
+      exp = 17.0;
 
     for (i = 0; i < N; i++)
     {
@@ -776,11 +783,10 @@  main(int argc, char **argv)
         }
     }
 
-#if ACC_MEM_SHARED
-    exp = 23.0;
-#else
-    exp = 22.0;
-#endif
+    if (offloading)
+      exp = 22.0;
+    else
+      exp = 23.0;
 
     for (i = 0; i < N; i++)
     {
@@ -830,11 +836,10 @@  main(int argc, char **argv)
         }
     }
 
-#if ACC_MEM_SHARED
-    exp = 50.0;
-#else
-    exp = 49.0;
-#endif
+    if (offloading)
+      exp = 49.0;
+    else
+      exp = 50.0;
 
     for (i = 0; i < N; i++)
     {
@@ -882,11 +887,10 @@  main(int argc, char **argv)
         }
     }
 
-#if ACC_MEM_SHARED
-    exp = 92.0;
-#else
-    exp = 91.0;
-#endif
+    if (offloading)
+      exp = 91.0;
+    else
+      exp = 92.0;
 
     for (i = 0; i < N; i++)
     {
@@ -910,11 +914,10 @@  main(int argc, char **argv)
         }
     }
 
-#if ACC_MEM_SHARED
-    exp = 44.0;
-#else
-    exp = 43.0;
-#endif
+    if (offloading)
+      exp = 43.0;
+    else
+      exp = 44.0;
 
     for (i = 0; i < N; i++)
     {
@@ -950,15 +953,18 @@  main(int argc, char **argv)
         b[i] = 9.0;
     }
 
-#if ACC_MEM_SHARED
-    exp = 0.0;
-    exp2 = 0.0;
-#else
-    acc_map_data (a, d_a, N * sizeof (float));
-    acc_map_data (b, d_b, N * sizeof (float));
-    exp = 3.0;
-    exp2 = 9.0;
-#endif
+    if (offloading)
+      {
+	acc_map_data (a, d_a, N * sizeof (float));
+	acc_map_data (b, d_b, N * sizeof (float));
+	exp = 3.0;
+	exp2 = 9.0;
+      }
+    else
+      {
+	exp = 0.0;
+	exp2 = 0.0;
+      }
 
     return 0;
 }