[gomp4] Un-parallelized OpenACC kernels constructs with nvptx offloading: "avoid offloading"

Thomas Schwinge thomas@codesourcery.com
Thu Jun 30 21:46:00 GMT 2016


Hi!

On Thu, 21 Jan 2016 22:54:26 +0100, I wrote:
> Committed to gomp-4_0-branch in r232709:
> 
> commit 41a76d233e714fd7b79dc1f40823f607c38306ba
> Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
> Date:   Thu Jan 21 21:52:50 2016 +0000
> 
>     Un-parallelized OpenACC kernels constructs with nvptx offloading: "avoid offloading"

In gomp-4_0-branch r237895, I committed the following patch to 'only
trigger the "avoid offloading" mechanism for -O2 and higher', resolving
the confusing case that for -O0 and -O1 we'D not emit the diagnostic but
still trigger the "avoid offloading" mechanism.

commit 68ce05b476b68b50c2ed341ae6a77279850edbb1
Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Thu Jun 30 20:46:07 2016 +0000

    Only trigger the "avoid offloading" mechanism for -O2 and higher
    
    	gcc/
    	* config/nvptx/nvptx.c (nvptx_goacc_validate_dims): Only trigger
    	the "avoid offloading" mechanism for -O2 and higher.
    	libgomp/
    	* testsuite/libgomp.oacc-c-c++-common/avoid-offloading-1.c:
    	Update.
    	* testsuite/libgomp.oacc-fortran/avoid-offloading-1.f: Update.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@237895 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog.gomp                                    |  5 +++++
 gcc/config/nvptx/nvptx.c                              | 19 ++++++++++---------
 libgomp/ChangeLog.gomp                                |  6 ++++++
 .../libgomp.oacc-c-c++-common/avoid-offloading-1.c    | 10 +++++++++-
 .../libgomp.oacc-fortran/avoid-offloading-1.f         | 12 +++++++++++-
 5 files changed, 41 insertions(+), 11 deletions(-)

diff --git gcc/ChangeLog.gomp gcc/ChangeLog.gomp
index 9bc1fbe..8c88119 100644
--- gcc/ChangeLog.gomp
+++ gcc/ChangeLog.gomp
@@ -1,3 +1,8 @@
+2016-06-30  Thomas Schwinge  <thomas@codesourcery.com>
+
+	* config/nvptx/nvptx.c (nvptx_goacc_validate_dims): Only trigger
+	the "avoid offloading" mechanism for -O2 and higher.
+
 2016-06-10  James Norris  <jnorris@codesourcery.com>
 
 	Backport from mainline r236098.
diff --git gcc/config/nvptx/nvptx.c gcc/config/nvptx/nvptx.c
index 6d787b0..09a5a62 100644
--- gcc/config/nvptx/nvptx.c
+++ gcc/config/nvptx/nvptx.c
@@ -4152,8 +4152,13 @@ nvptx_goacc_validate_dims (tree decl, int dims[], int fn_level)
   /* Detect if a function is unsuitable for offloading.  */
   if (!flag_offload_force && decl)
     {
+      /* Trigger the "avoid offloading" mechanism if a OpenACC kernels
+	 construct could not be parallelized, but only do that for -O2 and
+	 higher, as otherwise we're not expecting any parallelization to
+	 happen.  */
       tree oacc_function_attr = get_oacc_fn_attrib (decl);
-      if (oacc_function_attr
+      if (optimize >= 2
+	  && oacc_function_attr
 	  && oacc_fn_attrib_kernels_p (oacc_function_attr))
 	{
 	  bool avoid_offloading_p = true;
@@ -4167,14 +4172,10 @@ nvptx_goacc_validate_dims (tree decl, int dims[], int fn_level)
 	    }
 	  if (avoid_offloading_p)
 	    {
-	      /* OpenACC kernels constructs will never be parallelized for
-		 optimization levels smaller than -O2; avoid the diagnostic in
-		 this case.  */
-	      if (optimize >= 2)
-		warning_at (DECL_SOURCE_LOCATION (decl), 0,
-			    "OpenACC kernels construct will be executed "
-			    "sequentially; will by default avoid offloading "
-			    "to prevent data copy penalty");
+	      warning_at (DECL_SOURCE_LOCATION (decl), 0,
+			  "OpenACC kernels construct will be executed"
+			  " sequentially; will by default avoid offloading to"
+			  " prevent data copy penalty");
 	      DECL_ATTRIBUTES (decl)
 		= tree_cons (get_identifier ("omp avoid offloading"),
 			     NULL_TREE, DECL_ATTRIBUTES (decl));
diff --git libgomp/ChangeLog.gomp libgomp/ChangeLog.gomp
index af4e0d5..07fe8b7 100644
--- libgomp/ChangeLog.gomp
+++ libgomp/ChangeLog.gomp
@@ -1,3 +1,9 @@
+2016-06-30  Thomas Schwinge  <thomas@codesourcery.com>
+
+	* testsuite/libgomp.oacc-c-c++-common/avoid-offloading-1.c:
+	Update.
+	* testsuite/libgomp.oacc-fortran/avoid-offloading-1.f: Update.
+
 2016-06-10  Thomas Schwinge  <thomas@codesourcery.com>
 
 	PR middle-end/71373
diff --git libgomp/testsuite/libgomp.oacc-c-c++-common/avoid-offloading-1.c libgomp/testsuite/libgomp.oacc-c-c++-common/avoid-offloading-1.c
index 8f50ba3..d5fff2d 100644
--- libgomp/testsuite/libgomp.oacc-c-c++-common/avoid-offloading-1.c
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/avoid-offloading-1.c
@@ -15,7 +15,15 @@ int main(void)
 
   if (x != 33)
     __builtin_abort();
-#if defined ACC_DEVICE_TYPE_host || defined ACC_DEVICE_TYPE_nvidia
+#if defined ACC_DEVICE_TYPE_nvidia
+# if !defined __OPTIMIZE__
+  if (y != 0)
+    __builtin_abort();
+# else
+  if (y != 1)
+    __builtin_abort();
+# endif
+#elif defined ACC_DEVICE_TYPE_host
   if (y != 1)
     __builtin_abort();
 #else
diff --git libgomp/testsuite/libgomp.oacc-fortran/avoid-offloading-1.f libgomp/testsuite/libgomp.oacc-fortran/avoid-offloading-1.f
index 452afe1..da89b93 100644
--- libgomp/testsuite/libgomp.oacc-fortran/avoid-offloading-1.f
+++ libgomp/testsuite/libgomp.oacc-fortran/avoid-offloading-1.f
@@ -4,6 +4,10 @@
 ! { dg-additional-options "-cpp" }
 ! The warning is only triggered for -O2 and higher.
 ! { dg-xfail-if "n/a" { openacc_nvidia_accel_selected } { "-O0" "-O1" } { "" } }
+! As __OPTIMIZE__ is defined for -O1 and higher, we don't have an (easy) way to
+! distinguish -O1 (where we will offload) from -O2 (where we won't offload), so
+! for -O1 testing, we expect to abort.
+! { dg-xfail-run-if "" { openacc_nvidia_accel_selected } { "-O1" } { "" } }
 
       IMPLICIT NONE
       INCLUDE "openacc_lib.h"
@@ -19,7 +23,13 @@
 !$ACC END DATA
 
       IF (X .NE. 33) CALL ABORT
-#if defined ACC_DEVICE_TYPE_host || defined ACC_DEVICE_TYPE_nvidia
+#if defined ACC_DEVICE_TYPE_nvidia
+# if !defined __OPTIMIZE__
+      IF (Y) CALL ABORT
+# else
+      IF (.NOT. Y) CALL ABORT
+# endif
+#elif defined ACC_DEVICE_TYPE_host
       IF (.NOT. Y) CALL ABORT
 #else
 # error Not ported to this ACC_DEVICE_TYPE


Grüße
 Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 472 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20160630/d7107145/attachment.sig>


More information about the Gcc-patches mailing list