[Openmp-commits] [openmp] b86ff5f - [OpenMP] Sync writes to child thread's data before reduction

Bryan Chan via Openmp-commits openmp-commits at lists.llvm.org
Tue Apr 14 11:32:41 PDT 2020


Author: Bryan Chan
Date: 2020-04-14T14:31:06-04:00
New Revision: b86ff5f6efbed626fee135ae11311569d84b1e15

URL: https://github.com/llvm/llvm-project/commit/b86ff5f6efbed626fee135ae11311569d84b1e15
DIFF: https://github.com/llvm/llvm-project/commit/b86ff5f6efbed626fee135ae11311569d84b1e15.diff

LOG: [OpenMP] Sync writes to child thread's data before reduction

On systems with weak memory consistency, this patch fixes an intermittent crash
in the reduction function called by __kmp_hyper_barrier_gather, which suffers
from a race on a child thread's data.

Reviewed-By: AndreyChurbanov

Differential Revision: https://reviews.llvm.org/D77603

Added: 
    

Modified: 
    openmp/runtime/src/kmp_barrier.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/runtime/src/kmp_barrier.cpp b/openmp/runtime/src/kmp_barrier.cpp
index a6d87b5d7a2e..4aa7a084f53a 100644
--- a/openmp/runtime/src/kmp_barrier.cpp
+++ b/openmp/runtime/src/kmp_barrier.cpp
@@ -549,6 +549,7 @@ __kmp_hyper_barrier_gather(enum barrier_type bt, kmp_info_t *this_thr, int gtid,
     if (((tid >> level) & (branch_factor - 1)) != 0) {
       kmp_int32 parent_tid = tid & ~((1 << (level + branch_bits)) - 1);
 
+      KMP_MB(); // Synchronize parent and child threads.
       KA_TRACE(20,
                ("__kmp_hyper_barrier_gather: T#%d(%d:%d) releasing T#%d(%d:%d) "
                 "arrived(%p): %llu => %llu\n",
@@ -590,6 +591,7 @@ __kmp_hyper_barrier_gather(enum barrier_type bt, kmp_info_t *this_thr, int gtid,
       kmp_flag_64 c_flag(&child_bar->b_arrived, new_state);
       c_flag.wait(this_thr, FALSE USE_ITT_BUILD_ARG(itt_sync_obj));
       ANNOTATE_BARRIER_END(child_thr);
+      KMP_MB(); // Synchronize parent and child threads.
 #if USE_ITT_BUILD && USE_ITT_NOTIFY
       // Barrier imbalance - write min of the thread time and a child time to
       // the thread.


        


More information about the Openmp-commits mailing list