diff options
author | Jakub Jelinek <jakub@redhat.com> | 2022-10-12 17:54:08 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2022-11-04 09:29:34 +0100 |
commit | a2423e832d936ab50a2bf1a6b2f0dfb811d0be50 (patch) | |
tree | bdb08b96051af5b219d3f8a9d3356d713fbb2514 /libgomp/target.c | |
parent | 8693cafd8975364ef9b409c18ddfc233e66345d8 (diff) | |
download | gcc-a2423e832d936ab50a2bf1a6b2f0dfb811d0be50.zip gcc-a2423e832d936ab50a2bf1a6b2f0dfb811d0be50.tar.gz gcc-a2423e832d936ab50a2bf1a6b2f0dfb811d0be50.tar.bz2 |
libgomp: Fix up creation of artificial teams
When not in explicit parallel/target/teams construct, we in some cases create
an artificial parallel with a single thread (either to handle target nowait
or for task reduction purposes). In those cases, it handled again artificially
created implicit task (created by gomp_new_icv for cases where we needed to write
to some ICVs), but as the testcases show, didn't take into account possibility
of this being done from explicit task(s). The code would destroy/free the previous
task and replace it with the new implicit task. If task is an explicit task
(when teams is NULL, all explicit tasks behave like if (0)), it is a pointer to
a local stack variable, so freeing it doesn't work, and additionally we shouldn't
lose the explicit tasks - the new implicit task should instead replace the
ancestor task which is the first implicit one.
2022-10-12 Jakub Jelinek <jakub@redhat.com>
* task.c (gomp_create_artificial_team): Fix up handling of invocations
from within explicit task.
* target.c (GOMP_target_ext): Likewise.
* testsuite/libgomp.c/task-7.c: New test.
* testsuite/libgomp.c/task-8.c: New test.
* testsuite/libgomp.c-c++-common/task-reduction-17.c: New test.
* testsuite/libgomp.c-c++-common/task-reduction-18.c: New test.
(cherry picked from commit a58a965eb73253759f6a3e1c7380392557da89c8)
Diffstat (limited to 'libgomp/target.c')
-rw-r--r-- | libgomp/target.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/libgomp/target.c b/libgomp/target.c index 4a4e1f8..98a7917 100644 --- a/libgomp/target.c +++ b/libgomp/target.c @@ -2192,6 +2192,7 @@ GOMP_target_ext (int device, void (*fn) (void *), size_t mapnum, { struct gomp_team *team = gomp_new_team (1); struct gomp_task *task = thr->task; + struct gomp_task **implicit_task = &task; struct gomp_task_icv *icv = task ? &task->icv : &gomp_global_icv; team->prev_ts = thr->ts; thr->ts.team = team; @@ -2204,15 +2205,23 @@ GOMP_target_ext (int device, void (*fn) (void *), size_t mapnum, thr->ts.static_trip = 0; thr->task = &team->implicit_task[0]; gomp_init_task (thr->task, NULL, icv); - if (task) + while (*implicit_task + && (*implicit_task)->kind != GOMP_TASK_IMPLICIT) + implicit_task = &(*implicit_task)->parent; + if (*implicit_task) { - thr->task = task; + thr->task = *implicit_task; gomp_end_task (); - free (task); + free (*implicit_task); thr->task = &team->implicit_task[0]; } else pthread_setspecific (gomp_thread_destructor, thr); + if (implicit_task != &task) + { + *implicit_task = thr->task; + thr->task = task; + } } if (thr->ts.team && !thr->task->final_task) |