diff options
author | Jakub Jelinek <jakub@redhat.com> | 2022-05-17 15:40:27 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2022-05-17 15:40:27 +0200 |
commit | 2c16eb3157f86ae561468c540caf8eb326106b5f (patch) | |
tree | d14eeb859d38591bdd83f3754a627ba21c4d5fae /libgomp | |
parent | 1815462a6e53465c404f8a5f6116891492d4b50b (diff) | |
download | gcc-2c16eb3157f86ae561468c540caf8eb326106b5f.zip gcc-2c16eb3157f86ae561468c540caf8eb326106b5f.tar.gz gcc-2c16eb3157f86ae561468c540caf8eb326106b5f.tar.bz2 |
openmp: Add support for inoutset depend-kind
This patch adds support for inoutset depend-kind in depend
clauses. It is very similar to the in depend-kind in that
a task with a dependency with that depend-kind is dependent
on all previously created sibling tasks with matching address
unless they have the same depend-kind.
In the in depend-kind case everything is dependent except
for in -> in dependency, for inoutset everything is
dependent except for inoutset -> inoutset dependency.
mutexinoutset is also similar (everything is dependent except
for mutexinoutset -> mutexinoutset dependency), but there is
also the additional restriction that only one task with
mutexinoutset for each address can be scheduled at once (i.e.
mutual exclusitivty). For now we support mutexinoutset
the same as inout/out, but the inoutset support is full.
In order not to bump the ABI for dependencies each time
(we've bumped it already once, the old ABI supports only
inout/out and in depend-kind, the new ABI supports
inout/out, mutexinoutset, in and depobj), this patch arranges
for inoutset to be at least for the time being always handled
as if it was specified through depobj even when it is not.
So it uses the new ABI for that and inoutset are represented
like depobj - pointer to a pair of pointers where the first one
will be the actual address of the object mentioned in depend
clause and second pointer will be (void *) GOMP_DEPEND_INOUTSET.
2022-05-17 Jakub Jelinek <jakub@redhat.com>
gcc/
* tree-core.h (enum omp_clause_depend_kind): Add
OMP_CLAUSE_DEPEND_INOUTSET.
* tree-pretty-print.cc (dump_omp_clause): Handle
OMP_CLAUSE_DEPEND_INOUTSET.
* gimplify.cc (gimplify_omp_depend): Likewise.
* omp-low.cc (lower_depend_clauses): Likewise.
gcc/c-family/
* c-omp.cc (c_finish_omp_depobj): Handle
OMP_CLAUSE_DEPEND_INOUTSET.
gcc/c/
* c-parser.cc (c_parser_omp_clause_depend): Parse
inoutset depend-kind.
(c_parser_omp_depobj): Likewise.
gcc/cp/
* parser.cc (cp_parser_omp_clause_depend): Parse
inoutset depend-kind.
(cp_parser_omp_depobj): Likewise.
* cxx-pretty-print.cc (cxx_pretty_printer::statement): Handle
OMP_CLAUSE_DEPEND_INOUTSET.
gcc/testsuite/
* c-c++-common/gomp/all-memory-1.c (boo): Add test with
inoutset depend-kind.
* c-c++-common/gomp/all-memory-2.c (boo): Likewise.
* c-c++-common/gomp/depobj-1.c (f1): Likewise.
(f2): Adjusted expected diagnostics.
* g++.dg/gomp/depobj-1.C (f4): Adjust expected diagnostics.
include/
* gomp-constants.h (GOMP_DEPEND_INOUTSET): Define.
libgomp/
* libgomp.h (struct gomp_task_depend_entry): Change is_in type
from bool to unsigned char.
* task.c (gomp_task_handle_depend): Handle GOMP_DEPEND_INOUTSET.
Ignore dependencies where
task->depend[i].is_in && task->depend[i].is_in == ent->is_in
rather than just task->depend[i].is_in && ent->is_in. Remember
whether GOMP_DEPEND_IN loop is needed and guard the loop with that
conditional.
(gomp_task_maybe_wait_for_dependencies): Handle GOMP_DEPEND_INOUTSET.
Ignore dependencies where elem.is_in && elem.is_in == ent->is_in
rather than just elem.is_in && ent->is_in.
* testsuite/libgomp.c-c++-common/depend-1.c (test): Add task with
inoutset depend-kind.
* testsuite/libgomp.c-c++-common/depend-2.c (test): Likewise.
* testsuite/libgomp.c-c++-common/depend-3.c (test): Likewise.
* testsuite/libgomp.c-c++-common/depend-inoutset-1.c: New test.
Diffstat (limited to 'libgomp')
-rw-r--r-- | libgomp/libgomp.h | 4 | ||||
-rw-r--r-- | libgomp/task.c | 33 | ||||
-rw-r--r-- | libgomp/testsuite/libgomp.c-c++-common/depend-1.c | 7 | ||||
-rw-r--r-- | libgomp/testsuite/libgomp.c-c++-common/depend-2.c | 7 | ||||
-rw-r--r-- | libgomp/testsuite/libgomp.c-c++-common/depend-3.c | 7 | ||||
-rw-r--r-- | libgomp/testsuite/libgomp.c-c++-common/depend-inoutset-1.c | 164 |
6 files changed, 206 insertions, 16 deletions
diff --git a/libgomp/libgomp.h b/libgomp/libgomp.h index 295d10f..74487e5 100644 --- a/libgomp/libgomp.h +++ b/libgomp/libgomp.h @@ -536,8 +536,8 @@ struct gomp_task_depend_entry struct gomp_task_depend_entry *prev; /* Task that provides the dependency in ADDR. */ struct gomp_task *task; - /* Depend entry is of type "IN". */ - bool is_in; + /* Depend entry is of type "IN" (1) or "INOUTSET" (2). */ + unsigned char is_in; bool redundant; bool redundant_out; }; diff --git a/libgomp/task.c b/libgomp/task.c index db4a6f7..e9a28bf 100644 --- a/libgomp/task.c +++ b/libgomp/task.c @@ -197,6 +197,7 @@ gomp_task_handle_depend (struct gomp_task *task, struct gomp_task *parent, /* ndepend - nout - nmutexinoutset - nin is # of depobjs */ size_t normal = nout + nmutexinoutset + nin; size_t n = 0; + bool has_in = false; for (i = normal; i < ndepend; i++) { void **d = (void **) (uintptr_t) depend[5 + i]; @@ -209,6 +210,8 @@ gomp_task_handle_depend (struct gomp_task *task, struct gomp_task *parent, case GOMP_DEPEND_MUTEXINOUTSET: break; case GOMP_DEPEND_IN: + case GOMP_DEPEND_INOUTSET: + has_in = true; continue; default: gomp_fatal ("unknown omp_depend_t dependence type %d", @@ -222,14 +225,17 @@ gomp_task_handle_depend (struct gomp_task *task, struct gomp_task *parent, task->depend[n].addr = depend[5 + i]; task->depend[n++].is_in = i >= nout + nmutexinoutset; } - for (i = normal; i < ndepend; i++) - { - void **d = (void **) (uintptr_t) depend[5 + i]; - if ((uintptr_t) d[1] != GOMP_DEPEND_IN) - continue; - task->depend[n].addr = d[0]; - task->depend[n++].is_in = 1; - } + if (has_in) + for (i = normal; i < ndepend; i++) + { + void **d = (void **) (uintptr_t) depend[5 + i]; + if ((uintptr_t) d[1] != GOMP_DEPEND_IN + && (uintptr_t) d[1] != GOMP_DEPEND_INOUTSET) + continue; + task->depend[n].addr = d[0]; + task->depend[n++].is_in + = 1 + ((uintptr_t) d[1] == GOMP_DEPEND_INOUTSET); + } } task->num_dependees = 0; if (__builtin_expect (parent->depend_all_memory && ndepend, false)) @@ -381,8 +387,10 @@ gomp_task_handle_depend (struct gomp_task *task, struct gomp_task *parent, last = ent; - /* depend(in:...) doesn't depend on earlier depend(in:...). */ - if (task->depend[i].is_in && ent->is_in) + /* depend(in:...) doesn't depend on earlier depend(in:...). + Similarly depend(inoutset:...) doesn't depend on earlier + depend(inoutset:...). */ + if (task->depend[i].is_in && task->depend[i].is_in == ent->is_in) continue; if (!ent->is_in) @@ -1890,6 +1898,9 @@ gomp_task_maybe_wait_for_dependencies (void **depend) case GOMP_DEPEND_MUTEXINOUTSET: elem.is_in = 0; break; + case GOMP_DEPEND_INOUTSET: + elem.is_in = 2; + break; default: gomp_fatal ("unknown omp_depend_t dependence type %d", (int) (uintptr_t) d[1]); @@ -1928,7 +1939,7 @@ gomp_task_maybe_wait_for_dependencies (void **depend) } ent = htab_find (task->depend_hash, &elem); for (; ent; ent = ent->next) - if (elem.is_in && ent->is_in) + if (elem.is_in && elem.is_in == ent->is_in) continue; else { diff --git a/libgomp/testsuite/libgomp.c-c++-common/depend-1.c b/libgomp/testsuite/libgomp.c-c++-common/depend-1.c index 3376b99..47d7570 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/depend-1.c +++ b/libgomp/testsuite/libgomp.c-c++-common/depend-1.c @@ -48,6 +48,11 @@ test (int ifval) usleep (5000); b[4] = 48; } + #pragma omp task shared(b) depend(inoutset: b[5]) + { + usleep (5000); + b[5] = 49; + } /* None of the above tasks depend on each other. The following task depends on all but the a[4] = 46; one. */ #pragma omp task shared(a, b) depend(out: omp_all_memory) private(i) if(ifval) @@ -55,7 +60,7 @@ test (int ifval) if (a[0] != 42 || a[1] != 43 || a[2] != 44 || a[3] != 45 || a[5] != 5 || a[6] != 6 || a[7] != 7 || b[0] != 47 || b[1] != 2 || b[2] != 4 || b[3] != 6 - || b[4] != 48 || b[5] != 10 || b[6] != 12 || b[7] != 14) + || b[4] != 48 || b[5] != 49 || b[6] != 12 || b[7] != 14) abort (); for (i = 0; i < 8; ++i) if (i != 4) diff --git a/libgomp/testsuite/libgomp.c-c++-common/depend-2.c b/libgomp/testsuite/libgomp.c-c++-common/depend-2.c index d7b5335..2fe867e 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/depend-2.c +++ b/libgomp/testsuite/libgomp.c-c++-common/depend-2.c @@ -52,6 +52,11 @@ test (int ifval) usleep (5000); b[4] = 48; } + #pragma omp task shared(b) depend(inoutset: b[5]) + { + usleep (5000); + b[5] = 49; + } /* None of the above tasks depend on each other. The following task depends on all but the a[4] = 46; one. */ #pragma omp task shared(a, b) depend(depobj: d1) private(i) if(ifval) @@ -59,7 +64,7 @@ test (int ifval) if (a[0] != 42 || a[1] != 43 || a[2] != 44 || a[3] != 45 || a[5] != 5 || a[6] != 6 || a[7] != 7 || b[0] != 47 || b[1] != 2 || b[2] != 4 || b[3] != 6 - || b[4] != 48 || b[5] != 10 || b[6] != 12 || b[7] != 14) + || b[4] != 48 || b[5] != 49 || b[6] != 12 || b[7] != 14) abort (); for (i = 0; i < 8; ++i) if (i != 4) diff --git a/libgomp/testsuite/libgomp.c-c++-common/depend-3.c b/libgomp/testsuite/libgomp.c-c++-common/depend-3.c index 052e77c..7cfda67 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/depend-3.c +++ b/libgomp/testsuite/libgomp.c-c++-common/depend-3.c @@ -48,6 +48,11 @@ main () usleep (5000); b[4] = 48; } + #pragma omp task shared(b) depend(inoutset: b[5]) + { + usleep (5000); + b[5] = 49; + } /* None of the above tasks depend on each other. The following task depends on all but the a[4] = 46; one. */ #pragma omp task shared(a, b) depend(iterator (j=0:7), inout: omp_all_memory) private(i) @@ -55,7 +60,7 @@ main () if (a[0] != 42 || a[1] != 43 || a[2] != 44 || a[3] != 45 || a[5] != 5 || a[6] != 6 || a[7] != 7 || b[0] != 47 || b[1] != 2 || b[2] != 4 || b[3] != 6 - || b[4] != 48 || b[5] != 10 || b[6] != 12 || b[7] != 14) + || b[4] != 48 || b[5] != 49 || b[6] != 12 || b[7] != 14) abort (); for (i = 0; i < 8; ++i) if (i != 4) diff --git a/libgomp/testsuite/libgomp.c-c++-common/depend-inoutset-1.c b/libgomp/testsuite/libgomp.c-c++-common/depend-inoutset-1.c new file mode 100644 index 0000000..77956f2 --- /dev/null +++ b/libgomp/testsuite/libgomp.c-c++-common/depend-inoutset-1.c @@ -0,0 +1,164 @@ +#include <omp.h> +#include <stdlib.h> +#include <unistd.h> + +int +main () +{ + int a[8] = {}; + omp_depend_t d1, d2; + #pragma omp depobj (d1) depend(inoutset: a) + #pragma omp depobj (d2) depend(inout: a) + #pragma omp depobj (d2) update(inoutset) + #pragma omp parallel + { + #pragma omp barrier + #pragma omp master + { + #pragma omp task shared(a) depend(out: a) + { + usleep (5000); + a[0] = 1; a[1] = 2; a[2] = 3; a[3] = 4; + } + /* The above task needs to finish first. */ + #pragma omp task shared(a) depend(in: a) + { + if (a[0] != 1 || a[1] != 2 || a[2] != 3 || a[3] != 4) + abort (); + usleep (5000); + a[4] = 42; + } + #pragma omp task shared(a) depend(in: a) + { + if (a[0] != 1 || a[1] != 2 || a[2] != 3 || a[3] != 4) + abort (); + usleep (5000); + a[5] = 43; + } + #pragma omp task shared(a) depend(in: a) + { + if (a[0] != 1 || a[1] != 2 || a[2] != 3 || a[3] != 4) + abort (); + usleep (5000); + a[6] = 44; + } + #pragma omp task shared(a) depend(in: a) + { + if (a[0] != 1 || a[1] != 2 || a[2] != 3 || a[3] != 4) + abort (); + usleep (5000); + a[7] = 45; + } + /* The above 4 tasks can be scheduled in any order but need to wait + for the depend(out: a) task. */ + #pragma omp task shared(a) depend(inoutset: a) + { + if (a[4] != 42 || a[5] != 43 || a[6] != 44 || a[7] != 45) + abort (); + usleep (5000); + a[0] = 42; + } + #pragma omp task shared(a) depend(iterator(i=1:3:2), inoutset: a) + { + if (a[4] != 42 || a[5] != 43 || a[6] != 44 || a[7] != 45) + abort (); + usleep (5000); + a[1] = 43; + } + #pragma omp task shared(a) depend(depobj: d1) + { + if (a[4] != 42 || a[5] != 43 || a[6] != 44 || a[7] != 45) + abort (); + usleep (5000); + a[2] = 44; + } + #pragma omp task shared(a) depend(depobj: d2) + { + if (a[4] != 42 || a[5] != 43 || a[6] != 44 || a[7] != 45) + abort (); + usleep (5000); + a[3] = 45; + } + /* The above 4 tasks can be scheduled in any order but need to wait + for all the above depend(in: a) tasks. */ + #pragma omp task shared(a) depend(in: a) + { + if (a[0] != 42 || a[1] != 43 || a[2] != 44 || a[3] != 45) + abort (); + usleep (5000); + a[4] = 46; + } + #pragma omp task shared(a) depend(in: a) + { + if (a[0] != 42 || a[1] != 43 || a[2] != 44 || a[3] != 45) + abort (); + usleep (5000); + a[5] = 47; + } + #pragma omp task shared(a) depend(in: a) + { + if (a[0] != 42 || a[1] != 43 || a[2] != 44 || a[3] != 45) + abort (); + usleep (5000); + a[6] = 48; + } + #pragma omp task shared(a) depend(in: a) + { + if (a[0] != 42 || a[1] != 43 || a[2] != 44 || a[3] != 45) + abort (); + usleep (5000); + a[7] = 49; + } + /* The above 4 tasks can be scheduled in any order but need to wait + for all the above depend(inoutset: a), + depend(iterator(i=1:3:2), inoutset: a), depend(depobj: d1) and + depend(depobj: d2) tasks. */ + #pragma omp task shared(a) depend(inoutset: a) + { + if (a[4] != 46|| a[5] != 47 || a[6] != 48 || a[7] != 49) + abort (); + usleep (5000); + a[0] = 50; + } + /* The above task needs to wait for all the above 4 depend(in: a) + tasks. */ + #pragma omp task shared(a) depend(out: a) + { + if (a[0] != 50 || a[4] != 46|| a[5] != 47 || a[6] != 48 || a[7] != 49) + abort (); + usleep (5000); + a[0] = 51; + } + /* The above task needs to wait for the above depend(inoutset: a) task. */ + #pragma omp task shared(a) depend(inoutset: a) + { + if (a[0] != 51 || a[4] != 46|| a[5] != 47 || a[6] != 48 || a[7] != 49) + abort (); + usleep (5000); + a[0] = 52; + } + /* The above task needs to wait for the above depend(out: a) task. */ + #pragma omp task shared(a) depend(mutexinoutset: a) + { + if (a[0] != 52 || a[4] != 46|| a[5] != 47 || a[6] != 48 || a[7] != 49) + abort (); + usleep (5000); + a[0] = 53; + } + /* The above task needs to wait for the above depend(inoutset: a) task. */ + #pragma omp task shared(a) depend(inoutset: a) + { + if (a[0] != 53 || a[4] != 46|| a[5] != 47 || a[6] != 48 || a[7] != 49) + abort (); + usleep (5000); + a[0] = 54; + } + /* The above task needs to wait for the above + depend(mutexinoutset: a) task. */ + } + } + if (a[0] != 54 || a[1] != 43 || a[2] != 44 || a[3] != 45 + || a[4] != 46|| a[5] != 47 || a[6] != 48 || a[7] != 49) + abort (); + return 0; +} |