diff mbox

OpenMP target update tests

Message ID 87k3954p0g.fsf@schwinge.name
State New
Headers show

Commit Message

Thomas Schwinge May 28, 2014, 8:38 p.m. UTC
Hi!

Does that look appropriate (for trunk)?

 gcc/c/c-parser.c                                  |  2 +-
 gcc/c/c-typeck.c                                  |  2 ++
 gcc/cp/parser.c                                   |  2 +-
 gcc/cp/semantics.c                                |  2 ++
 gcc/testsuite/c-c++-common/gomp/target-update-1.c | 41 +++++++++++++++++++++++
 5 files changed, 47 insertions(+), 2 deletions(-)



Grüße,
 Thomas

Comments

Jakub Jelinek May 28, 2014, 10:14 p.m. UTC | #1
On Wed, May 28, 2014 at 10:38:55PM +0200, Thomas Schwinge wrote:
> --- gcc/c/c-parser.c
> +++ gcc/c/c-parser.c
> @@ -13530,7 +13530,7 @@ c_parser_omp_target_update (location_t loc, c_parser *parser,
>        && find_omp_clause (clauses, OMP_CLAUSE_FROM) == NULL_TREE)
>      {
>        error_at (loc,
> -		"%<#pragma omp target update must contain at least one "
> +		"%<#pragma omp target update%> must contain at least one "
>  		"%<from%> or %<to%> clauses");
>        return false;
>      }

This is fine, ditto the cp/parser.c change.

> --- gcc/c/c-typeck.c
> +++ gcc/c/c-typeck.c
> @@ -12152,6 +12152,8 @@ c_finish_omp_clauses (tree clauses)
>  		      remove = true;
>  		    }
>  		}
> +	      /* Currently, we're not doing any further checking for array
> +		 sections.  */
>  	      break;
>  	    }
>  	  if (t == error_mark_node)

I don't know what more checking would be desirable, in fact, reading the
latest standard I actually see no restriction that the same list item can't
appear in multiple map (or multiple from or multiple to) clauses on the same
construct, there is only a restriction that the same list item should not
appear in both to and from clauses on the same construct.
Will need to go through my omp-lang related mails to see if this has been
discussed post 4.0.
But, as soon as array sections are involved, it is hard (especially if
variable bounds are involved) to actually analyze this restriction.

> +#pragma omp target update from(a, a, b) /* { dg-error "'a' appears more than once in motion clauses" } */
> +#pragma omp target update to(a, a) to(b) /* { dg-error "'a' appears more than once in motion clauses" } */
> +#pragma omp target update from(a) from(a, b) /* { dg-error "'a' appears more than once in motion clauses" } */

See above, I believe this is not invalid.

> +#pragma omp target update from(a) to(a) from(b) /* { dg-error "'a' appears more than once in motion clauses" } */

> +#pragma omp target update to(a) to(a) from(b) /* { dg-error "'a' appears more than once in motion clauses" } */

The above one too.

> +#pragma omp target update from(a, b, b) /* { dg-error "'b' appears more than once in motion clauses" } */
> +#pragma omp target update to(a) to(b, b) /* { dg-error "'b' appears more than once in motion clauses" } */
> +#pragma omp target update from(a, b) from(b) /* { dg-error "'b' appears more than once in motion clauses" } */
> +#pragma omp target update from(a) to(b) from(b) /* { dg-error "'b' appears more than once in motion clauses" } */
> +#pragma omp target update from(a) to(b) to(b) /* { dg-error "'b' appears more than once in motion clauses" } */
> +
> +#pragma omp target update to(a) from(a[1:1]) /* { dg-error "'a' appears more than once in motion clauses" "not implemented" { xfail *-*-* } } */

Here I guess it really depends if a and a[1:1] is the same list item, I'd
say they are not.  I think it should be fine and useful to use at least
the cases where there is the same underlying variable, but non-overlapping
sections like:
#pragma omp target update to(a[10:4]) from(a[0:5])

	Jakub
Jakub Jelinek May 28, 2014, 10:31 p.m. UTC | #2
On Thu, May 29, 2014 at 12:14:45AM +0200, Jakub Jelinek wrote:
> > +#pragma omp target update from(a, b, b) /* { dg-error "'b' appears more than once in motion clauses" } */
> > +#pragma omp target update to(a) to(b, b) /* { dg-error "'b' appears more than once in motion clauses" } */
> > +#pragma omp target update from(a, b) from(b) /* { dg-error "'b' appears more than once in motion clauses" } */
> > +#pragma omp target update from(a) to(b) from(b) /* { dg-error "'b' appears more than once in motion clauses" } */
> > +#pragma omp target update from(a) to(b) to(b) /* { dg-error "'b' appears more than once in motion clauses" } */
> > +
> > +#pragma omp target update to(a) from(a[1:1]) /* { dg-error "'a' appears more than once in motion clauses" "not implemented" { xfail *-*-* } } */
> 
> Here I guess it really depends if a and a[1:1] is the same list item, I'd
> say they are not.  I think it should be fine and useful to use at least
> the cases where there is the same underlying variable, but non-overlapping
> sections like:
> #pragma omp target update to(a[10:4]) from(a[0:5])

Also, if you have say:
int *a;
void
foo ()
{
  #pragma omp target update to (a) from (a[0:10])
}
then there is actually no overlap, this would write the host
pointer value to the device's a pointer copy, and copy 40 bytes
from the device back to where a points.

	Jakub
diff mbox

Patch

diff --git gcc/c/c-parser.c gcc/c/c-parser.c
index ae13b0a..d9c91f0 100644
--- gcc/c/c-parser.c
+++ gcc/c/c-parser.c
@@ -13530,7 +13530,7 @@  c_parser_omp_target_update (location_t loc, c_parser *parser,
       && find_omp_clause (clauses, OMP_CLAUSE_FROM) == NULL_TREE)
     {
       error_at (loc,
-		"%<#pragma omp target update must contain at least one "
+		"%<#pragma omp target update%> must contain at least one "
 		"%<from%> or %<to%> clauses");
       return false;
     }
diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c
index b6db627..ab78f6d 100644
--- gcc/c/c-typeck.c
+++ gcc/c/c-typeck.c
@@ -12152,6 +12152,8 @@  c_finish_omp_clauses (tree clauses)
 		      remove = true;
 		    }
 		}
+	      /* Currently, we're not doing any further checking for array
+		 sections.  */
 	      break;
 	    }
 	  if (t == error_mark_node)
diff --git gcc/cp/parser.c gcc/cp/parser.c
index e52edbb..6c88fe4 100644
--- gcc/cp/parser.c
+++ gcc/cp/parser.c
@@ -30288,7 +30288,7 @@  cp_parser_omp_target_update (cp_parser *parser, cp_token *pragma_tok,
       && find_omp_clause (clauses, OMP_CLAUSE_FROM) == NULL_TREE)
     {
       error_at (pragma_tok->location,
-		"%<#pragma omp target update must contain at least one "
+		"%<#pragma omp target update%> must contain at least one "
 		"%<from%> or %<to%> clauses");
       return false;
     }
diff --git gcc/cp/semantics.c gcc/cp/semantics.c
index 7f06f3f..5f29268 100644
--- gcc/cp/semantics.c
+++ gcc/cp/semantics.c
@@ -5648,6 +5648,8 @@  finish_omp_clauses (tree clauses)
 		      remove = true;
 		    }
 		}
+	      /* Currently, we're not doing any further checking for array
+		 sections.  */
 	      break;
 	    }
 	  if (t == error_mark_node)
diff --git gcc/testsuite/c-c++-common/gomp/target-update-1.c gcc/testsuite/c-c++-common/gomp/target-update-1.c
new file mode 100644
index 0000000..8476314
--- /dev/null
+++ gcc/testsuite/c-c++-common/gomp/target-update-1.c
@@ -0,0 +1,41 @@ 
+void
+f (int a[10], float b)
+{
+#pragma omp target update from(a)
+#pragma omp target update to(a)
+#pragma omp target update from(b)
+#pragma omp target update to(b)
+
+#pragma omp target update from(a, b)
+#pragma omp target update from(a) to(b)
+#pragma omp target update to(a, b)
+
+#pragma omp target update from(a, a, b) /* { dg-error "'a' appears more than once in motion clauses" } */
+#pragma omp target update to(a, a) to(b) /* { dg-error "'a' appears more than once in motion clauses" } */
+#pragma omp target update from(a) from(a, b) /* { dg-error "'a' appears more than once in motion clauses" } */
+#pragma omp target update from(a) to(a) from(b) /* { dg-error "'a' appears more than once in motion clauses" } */
+#pragma omp target update to(a) to(a) from(b) /* { dg-error "'a' appears more than once in motion clauses" } */
+
+#pragma omp target update from(a, b, b) /* { dg-error "'b' appears more than once in motion clauses" } */
+#pragma omp target update to(a) to(b, b) /* { dg-error "'b' appears more than once in motion clauses" } */
+#pragma omp target update from(a, b) from(b) /* { dg-error "'b' appears more than once in motion clauses" } */
+#pragma omp target update from(a) to(b) from(b) /* { dg-error "'b' appears more than once in motion clauses" } */
+#pragma omp target update from(a) to(b) to(b) /* { dg-error "'b' appears more than once in motion clauses" } */
+
+#pragma omp target update to(a) from(a[1:1]) /* { dg-error "'a' appears more than once in motion clauses" "not implemented" { xfail *-*-* } } */
+#pragma omp target update to(a[1:1]) from(a[1:1]) /* { dg-error "'a' appears more than once in motion clauses" "not implemented" { xfail *-*-* } } */
+#pragma omp target update to(a[1:1]) to(a[1:1]) /* { dg-error "'a' appears more than once in motion clauses" "not implemented" { xfail *-*-* } } */
+#pragma omp target update to(a[1:3]) from(a[2:1]) /* { dg-error "'a' appears more than once in motion clauses" "not implemented" { xfail *-*-* } } */
+
+#pragma omp target update from(a) if(0)
+
+#pragma omp target update from(a) if(0) if(0) /* { dg-error "too many 'if' clauses" } */
+
+#pragma omp target update from(a) device(0)
+
+#pragma omp target update from(a) device(0) device(0) /* { dg-error "too many 'device' clauses" } */
+
+#pragma omp target update if(0) /* { dg-error "'#pragma omp target update' must contain at least one 'from' or 'to' clauses" } */
+#pragma omp target update device(0) /* { dg-error "'#pragma omp target update' must contain at least one 'from' or 'to' clauses" } */
+#pragma omp target update if(0) device(0) /* { dg-error "'#pragma omp target update' must contain at least one 'from' or 'to' clauses" } */
+}