[gcc/devel/omp/gcc-14] libgomp amdgcn: Fix issues with dynamic OpenMP thread scaling

Paul-Antoine Arras parras@gcc.gnu.org
Fri Jun 28 09:49:38 GMT 2024


https://gcc.gnu.org/g:2ca4602a941c1dfba2de376e3e523c7dd0491055

commit 2ca4602a941c1dfba2de376e3e523c7dd0491055
Author: Andrew Stubbs <ams@codesourcery.com>
Date:   Tue Aug 3 13:45:35 2021 +0100

    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:
---
 libgomp/ChangeLog.omp     | 7 +++++++
 libgomp/config/gcn/bar.h  | 3 +++
 libgomp/config/gcn/team.c | 4 ++++
 3 files changed, 14 insertions(+)

diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp
index 2ca82622336..5bf3a8a6890 100644
--- a/libgomp/ChangeLog.omp
+++ b/libgomp/ChangeLog.omp
@@ -1,3 +1,10 @@
+2021-08-03  Andrew Stubbs  <ams@codesourcery.com>
+
+	* 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.
+
 2021-02-23  Andrew Stubbs  <ams@codesourcery.com>
 
 	* plugin/plugin-nvptx.c (GOMP_OFFLOAD_alloc): Remove early call to
diff --git a/libgomp/config/gcn/bar.h b/libgomp/config/gcn/bar.h
index a130c749d00..645791575e9 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 bd3df448b52..47bf2df55ac 100644
--- a/libgomp/config/gcn/team.c
+++ b/libgomp/config/gcn/team.c
@@ -206,6 +206,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)
     {


More information about the Gcc-cvs mailing list