This patch fixes a bug in which testcases using thread_limit larger than the number of physical threads would crash with a memory fault. This was exacerbated in testcases with a lot of register pressure because the autoscaling reduces the number of physical threads to compensate for the increased resource usage.

Committed to devel/omp/gcc-11.

@ Thomas, this should probably be folded into another patch when upstreaming OG11 to mainline.

Andrew
libgomp amdgcn: Fix issues with dynamic OpenMP thread scaling

libgomp/ChangeLog:

        * config/gcn/bar.h (gomp_barrier_init): Limit thread count to the
        actual physical number.
        * config/gcn/team.c (gomp_team_start): Don't attempt to set up
        threads that do not exist.

diff --git a/libgomp/config/gcn/bar.h b/libgomp/config/gcn/bar.h
index bbd3141837f..63e803bd72b 100644
--- a/libgomp/config/gcn/bar.h
+++ b/libgomp/config/gcn/bar.h
@@ -55,6 +55,9 @@ typedef unsigned int gomp_barrier_state_t;
 
 static inline void gomp_barrier_init (gomp_barrier_t *bar, unsigned count)
 {
+  unsigned actual_thread_count = __builtin_gcn_dim_size (1);
+  if (count > actual_thread_count)
+    count = actual_thread_count;
   bar->total = count;
   bar->awaited = count;
   bar->awaited_final = count;
diff --git a/libgomp/config/gcn/team.c b/libgomp/config/gcn/team.c
index 627210ea407..6aa74744315 100644
--- a/libgomp/config/gcn/team.c
+++ b/libgomp/config/gcn/team.c
@@ -187,6 +187,10 @@ gomp_team_start (void (*fn) (void *), void *data, unsigned 
nthreads,
   if (nthreads == 1)
     return;
 
+  unsigned actual_thread_count = __builtin_gcn_dim_size (1);
+  if (nthreads > actual_thread_count)
+    nthreads = actual_thread_count;
+
   /* Release existing idle threads.  */
   for (unsigned i = 1; i < nthreads; ++i)
     {

Reply via email to