[Openmp-commits] [openmp] d83ca62 - [OpenMP] Fix data-race in new device RTL
Joseph Huber via Openmp-commits
openmp-commits at lists.llvm.org
Thu Sep 23 14:28:19 PDT 2021
Author: Joseph Huber
Date: 2021-09-23T17:28:07-04:00
New Revision: d83ca624a1d52b600ddbd8bfcbb3d5d7c6003af7
URL: https://github.com/llvm/llvm-project/commit/d83ca624a1d52b600ddbd8bfcbb3d5d7c6003af7
DIFF: https://github.com/llvm/llvm-project/commit/d83ca624a1d52b600ddbd8bfcbb3d5d7c6003af7.diff
LOG: [OpenMP] Fix data-race in new device RTL
This patch fixes a data-race observed when using the new device runtime
library. The Internal control variable for the parallel level is read in
the `__kmpc_parallel_51` function while it could potentially be written
by other threads. This causes data corruption and will cause
nondetermistic behaviour in the runtime. This patch fixes this by adding
an explicit synchronization before the region starts.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D110366
Added:
Modified:
openmp/libomptarget/DeviceRTL/src/Parallelism.cpp
Removed:
################################################################################
diff --git a/openmp/libomptarget/DeviceRTL/src/Parallelism.cpp b/openmp/libomptarget/DeviceRTL/src/Parallelism.cpp
index 367c2966f10e9..afb0704f2642e 100644
--- a/openmp/libomptarget/DeviceRTL/src/Parallelism.cpp
+++ b/openmp/libomptarget/DeviceRTL/src/Parallelism.cpp
@@ -93,6 +93,7 @@ void __kmpc_parallel_51(IdentTy *ident, int32_t, int32_t if_expr,
uint32_t NumThreads = determineNumberOfThreads(num_threads);
if (mapping::isSPMDMode()) {
+ synchronize::threads();
{
state::ValueRAII ParallelTeamSizeRAII(state::ParallelTeamSize, NumThreads,
1u, TId == 0);
More information about the Openmp-commits
mailing list