On 21/01/2021 7:33 pm, Kwok Cheung Yeung wrote:
With Nvidia and GCN offloading though, task-detach-6 hangs... I _think_ the reason why it 'worked' before was because the taskwait allowed tasks with detach clauses to always complete immediately after execution. Since that backdoor has been closed, task-detach-6 hangs with or without the taskwait.

It turns out that the hang is because the team barrier threads fail to wake up when gomp_team_barrier_wake is called from omp_fulfill_event, because it was done while task_lock was held. When the lock is freed first, the wake works as expected and the test completes.

Is this patch okay for trunk (to be squashed into the previous patch)?

Thanks

Kwok
From 2ee183c22772bc7d80d24ae75d5bd57f419712fd Mon Sep 17 00:00:00 2001
From: Kwok Cheung Yeung <k...@codesourcery.com>
Date: Thu, 21 Jan 2021 14:01:16 -0800
Subject: [PATCH] openmp: Fix hangs when task constructs with detach clauses
 are offloaded

2021-01-21  Kwok Cheung Yeung  <k...@codesourcery.com>

        libgomp/
        task.c (GOMP_task): Add thread to debug message.
        (gomp_barrier_handle_tasks): Do not take address of child_task in
        debug message.
        (omp_fulfill_event): Release team->task_lock before waking team
        barrier threads.
---
 libgomp/task.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/libgomp/task.c b/libgomp/task.c
index dbd6284..60b598e 100644
--- a/libgomp/task.c
+++ b/libgomp/task.c
@@ -492,7 +492,7 @@ GOMP_task (void (*fn) (void *), void *data, void (*cpyfn) 
(void *, void *),
          if (data)
            *(void **) data = task;
 
-         gomp_debug (0, "New event: %p\n", task);
+         gomp_debug (0, "Thread %d: new event: %p\n", thr->ts.team_id, task);
        }
       thr->task = task;
       if (cpyfn)
@@ -1372,7 +1372,7 @@ gomp_barrier_handle_tasks (gomp_barrier_state_t state)
                                 child_task, MEMMODEL_RELAXED);
          --team->task_detach_count;
          gomp_debug (0, "thread %d: found task with fulfilled event %p\n",
-                     thr->ts.team_id, &child_task);
+                     thr->ts.team_id, child_task);
 
          if (to_free)
            {
@@ -2470,8 +2470,12 @@ omp_fulfill_event (omp_event_handle_t event)
       gomp_sem_post (&task->taskgroup->taskgroup_sem);
     }
   if (team && team->nthreads > team->task_running_count)
-    gomp_team_barrier_wake (&team->barrier, 1);
-  gomp_mutex_unlock (&team->task_lock);
+    {
+      gomp_mutex_unlock (&team->task_lock);
+      gomp_team_barrier_wake (&team->barrier, 1);
+    }
+  else
+    gomp_mutex_unlock (&team->task_lock);
 }
 
 ialias (omp_fulfill_event)
-- 
2.8.1

Reply via email to