* open acc default data attribute
@ 2015-11-11 17:20 Nathan Sidwell
2015-11-12 8:53 ` Jakub Jelinek
0 siblings, 1 reply; 5+ messages in thread
From: Nathan Sidwell @ 2015-11-11 17:20 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: GCC Patches, Cesar Philippidis
[-- Attachment #1: Type: text/plain, Size: 588 bytes --]
Jakub,
this patch implements default data attribute determination. The current
behaviour defaults to 'copy' and ignores 'default(none)'. The patch corrects that.
1) We emit a diagnostic when 'default(none)' is in effect. The fortran FE emits
some artificial decls that it doesn't otherwise annotate, which is why we check
DECL_ARTIFICIAL. IIUC Cesar had a patch to address that but it needed some
reworking?
2) 'copy' is the correct default for 'kernels' regions, but for a 'parallel'
region, scalars should be 'firstprivate', which is what this patch implements.
ok?
nathan
[-- Attachment #2: trunk-default-1111.patch --]
[-- Type: text/x-patch, Size: 5174 bytes --]
2015-11-11 Nathan Sidwell <nathan@codesourcery.com>
gcc/
* gimplify.c (oacc_default_clause): New.
(omp_notice_variable): Call it.
gcc/testsuite/
* c-c++-common/goacc/data-default-1.c: New.
libgomp/
* testsuite/libgomp.oacc-c-c++-common/default-1.c: New.
Index: gcc/gimplify.c
===================================================================
--- gcc/gimplify.c (revision 230169)
+++ gcc/gimplify.c (working copy)
@@ -5900,6 +5900,60 @@ omp_default_clause (struct gimplify_omp_
return flags;
}
+
+/* Determine outer default flags for DECL mentioned in an OACC region
+ but not declared in an enclosing clause. */
+
+static unsigned
+oacc_default_clause (struct gimplify_omp_ctx *ctx, tree decl, unsigned flags)
+{
+ const char *rkind;
+
+ switch (ctx->region_type)
+ {
+ default:
+ gcc_unreachable ();
+
+ case ORT_ACC_KERNELS:
+ /* Everything under kernels are default 'present_or_copy'. */
+ flags |= GOVD_MAP;
+ rkind = "kernels";
+ break;
+
+ case ORT_ACC_PARALLEL:
+ {
+ tree type = TREE_TYPE (decl);
+
+ if (TREE_CODE (type) == REFERENCE_TYPE
+ || POINTER_TYPE_P (type))
+ type = TREE_TYPE (type);
+
+ if (AGGREGATE_TYPE_P (type))
+ /* Aggregates default to 'present_or_copy'. */
+ flags |= GOVD_MAP;
+ else
+ /* Scalars default to 'firstprivate'. */
+ flags |= GOVD_FIRSTPRIVATE;
+ rkind = "parallel";
+ }
+ break;
+ }
+
+ if (DECL_ARTIFICIAL (decl))
+ ; /* We can get compiler-generated decls, and should not complain
+ about them. */
+ else if (ctx->default_kind == OMP_CLAUSE_DEFAULT_NONE)
+ {
+ error ("%qE not specified in enclosing OpenACC %s construct",
+ DECL_NAME (lang_hooks.decls.omp_report_decl (decl)), rkind);
+ error_at (ctx->location, "enclosing OpenACC %s construct", rkind);
+ }
+ else
+ gcc_checking_assert (ctx->default_kind == OMP_CLAUSE_DEFAULT_SHARED);
+
+ return flags;
+}
+
/* Record the fact that DECL was used within the OMP context CTX.
IN_CODE is true when real code uses DECL, and false when we should
merely emit default(none) errors. Return true if DECL is going to
@@ -6023,7 +6077,12 @@ omp_notice_variable (struct gimplify_omp
nflags |= GOVD_MAP | GOVD_EXPLICIT;
}
else if (nflags == flags)
- nflags |= GOVD_MAP;
+ {
+ if ((ctx->region_type & ORT_ACC) != 0)
+ nflags = oacc_default_clause (ctx, decl, flags);
+ else
+ nflags |= GOVD_MAP;
+ }
}
found_outer:
omp_add_variable (ctx, decl, nflags);
Index: gcc/testsuite/c-c++-common/goacc/data-default-1.c
===================================================================
--- gcc/testsuite/c-c++-common/goacc/data-default-1.c (revision 0)
+++ gcc/testsuite/c-c++-common/goacc/data-default-1.c (working copy)
@@ -0,0 +1,37 @@
+/* { dg-do compile } */
+
+
+int main ()
+{
+ int n = 2;
+ int ary[2];
+
+#pragma acc parallel default (none) /* { dg-message "parallel construct" 2 } */
+ {
+ ary[0] /* { dg-error "not specified in enclosing" } */
+ = n; /* { dg-error "not specified in enclosing" } */
+ }
+
+#pragma acc kernels default (none) /* { dg-message "kernels construct" 2 } */
+ {
+ ary[0] /* { dg-error "not specified in enclosing" } */
+ = n; /* { dg-error "not specified in enclosing" } */
+ }
+
+#pragma acc data copy (ary, n)
+ {
+#pragma acc parallel default (none)
+ {
+ ary[0]
+ = n;
+ }
+
+#pragma acc kernels default (none)
+ {
+ ary[0]
+ = n;
+ }
+ }
+
+ return 0;
+}
Index: libgomp/testsuite/libgomp.oacc-c-c++-common/default-1.c
===================================================================
--- libgomp/testsuite/libgomp.oacc-c-c++-common/default-1.c (revision 0)
+++ libgomp/testsuite/libgomp.oacc-c-c++-common/default-1.c (working copy)
@@ -0,0 +1,87 @@
+/* { dg-do run } */
+
+#include <openacc.h>
+
+int test_parallel ()
+{
+ int ok = 1;
+ int val = 2;
+ int ary[32];
+ int ondev = 0;
+
+ for (int i = 0; i < 32; i++)
+ ary[i] = ~0;
+
+ /* val defaults to firstprivate, ary defaults to copy. */
+#pragma acc parallel num_gangs (32) copy (ok) copy(ondev)
+ {
+ ondev = acc_on_device (acc_device_not_host);
+#pragma acc loop gang(static:1)
+ for (unsigned i = 0; i < 32; i++)
+ {
+ if (val != 2)
+ ok = 0;
+ val += i;
+ ary[i] = val;
+ }
+ }
+
+ if (ondev)
+ {
+ if (!ok)
+ return 1;
+ if (val != 2)
+ return 1;
+
+ for (int i = 0; i < 32; i++)
+ if (ary[i] != 2 + i)
+ return 1;
+ }
+
+ return 0;
+}
+
+int test_kernels ()
+{
+ int val = 2;
+ int ary[32];
+ int ondev = 0;
+
+ for (int i = 0; i < 32; i++)
+ ary[i] = ~0;
+
+ /* val defaults to copy, ary defaults to copy. */
+#pragma acc kernels copy(ondev)
+ {
+ ondev = acc_on_device (acc_device_not_host);
+#pragma acc loop
+ for (unsigned i = 0; i < 32; i++)
+ {
+ ary[i] = val;
+ val++;
+ }
+ }
+
+ if (ondev)
+ {
+ if (val != 2 + 32)
+ return 1;
+
+ for (int i = 0; i < 32; i++)
+ if (ary[i] != 2 + i)
+ return 1;
+ }
+
+ return 0;
+}
+
+int main ()
+{
+ if (test_parallel ())
+ return 1;
+
+ if (test_kernels ())
+ return 1;
+
+ return 0;
+}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: open acc default data attribute
2015-11-11 17:20 open acc default data attribute Nathan Sidwell
@ 2015-11-12 8:53 ` Jakub Jelinek
2015-11-12 13:48 ` Nathan Sidwell
0 siblings, 1 reply; 5+ messages in thread
From: Jakub Jelinek @ 2015-11-12 8:53 UTC (permalink / raw)
To: Nathan Sidwell; +Cc: GCC Patches, Cesar Philippidis
On Wed, Nov 11, 2015 at 12:19:55PM -0500, Nathan Sidwell wrote:
> this patch implements default data attribute determination. The current
> behaviour defaults to 'copy' and ignores 'default(none)'. The patch
> corrects that.
>
> 1) We emit a diagnostic when 'default(none)' is in effect. The fortran FE
> emits some artificial decls that it doesn't otherwise annotate, which is why
> we check DECL_ARTIFICIAL. IIUC Cesar had a patch to address that but it
> needed some reworking?
I don't think treating DECL_ARTIFICIAL specially is a bug of any kind,
there are tons of different artificals even for C/C++ VLAs etc., and user
has no way to put them into any clauses explicitly, so what we do with them
is GCC internal thing.
> 2015-11-11 Nathan Sidwell <nathan@codesourcery.com>
>
> gcc/
> * gimplify.c (oacc_default_clause): New.
> (omp_notice_variable): Call it.
>
> gcc/testsuite/
> * c-c++-common/goacc/data-default-1.c: New.
>
> libgomp/
> * testsuite/libgomp.oacc-c-c++-common/default-1.c: New.
+ error ("%qE not specified in enclosing OpenACC %s construct",
+ DECL_NAME (lang_hooks.decls.omp_report_decl (decl)), rkind);
+ error_at (ctx->location, "enclosing OpenACC %s construct", rkind);
I'd use %qs instead of %s.
Otherwise ok.
Jakub
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: open acc default data attribute
2015-11-12 8:53 ` Jakub Jelinek
@ 2015-11-12 13:48 ` Nathan Sidwell
0 siblings, 0 replies; 5+ messages in thread
From: Nathan Sidwell @ 2015-11-12 13:48 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: GCC Patches, Cesar Philippidis
On 11/12/15 03:53, Jakub Jelinek wrote:
> + error ("%qE not specified in enclosing OpenACC %s construct",
> + DECL_NAME (lang_hooks.decls.omp_report_decl (decl)), rkind);
> + error_at (ctx->location, "enclosing OpenACC %s construct", rkind);
>
> I'd use %qs instead of %s.
thanks,
nathan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: open acc default data attribute
2015-11-12 20:22 David Edelsohn
@ 2015-11-12 20:53 ` Nathan Sidwell
0 siblings, 0 replies; 5+ messages in thread
From: Nathan Sidwell @ 2015-11-12 20:53 UTC (permalink / raw)
To: David Edelsohn; +Cc: GCC Patches
On 11/12/15 15:22, David Edelsohn wrote:
> Nathan,
>
> The ChangeLog was placed in the wrong files.
>
> gcc/
> * gimplify.c (oacc_default_clause): New.
> (omp_notice_variable): Call it.
Fixed. I placed the entries in the other files, but failed to cleanup the above
one.
nathan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: open acc default data attribute
@ 2015-11-12 20:22 David Edelsohn
2015-11-12 20:53 ` Nathan Sidwell
0 siblings, 1 reply; 5+ messages in thread
From: David Edelsohn @ 2015-11-12 20:22 UTC (permalink / raw)
To: Nathan Sidwell; +Cc: GCC Patches
Nathan,
The ChangeLog was placed in the wrong files.
gcc/
* gimplify.c (oacc_default_clause): New.
(omp_notice_variable): Call it.
Should go in gcc/ChangeLog without "gcc/"
gcc/testsuite/
* c-c++-common/goacc/data-default-1.c: New.
should go in gcc/testsuite/ChangeLog
libgomp/
* testsuite/libgomp.oacc-c-c++-common/default-1.c: New.
should go in libgomp/ChangeLog
Thanks, David
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-11-12 20:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-11 17:20 open acc default data attribute Nathan Sidwell
2015-11-12 8:53 ` Jakub Jelinek
2015-11-12 13:48 ` Nathan Sidwell
2015-11-12 20:22 David Edelsohn
2015-11-12 20:53 ` Nathan Sidwell
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).