diff options
author | Joseph Huber <jhuber6@vols.utk.edu> | 2021-02-01 10:31:09 -0500 |
---|---|---|
committer | Tom Stellard <tstellar@redhat.com> | 2021-02-03 14:25:51 -0800 |
commit | 922e4149d16754b54ce225faa3e769d32937d7ad (patch) | |
tree | 28a6ed2fc1382bb615b64110f3f836529b58d049 | |
parent | 255f7398845a7cfb47aef53e40b68057ec56839e (diff) | |
download | llvm-922e4149d16754b54ce225faa3e769d32937d7ad.tar.gz |
[OpenMP] Fix seg fault in libomptarget when using Info with multiple threads
Summary:
One option for the LIBOMPTARGET_INFO environment variable is to print the current status of the device's data mappings. These are a shared resource among threads so this needs to be protected when using multiple streams.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D95786
(cherry picked from commit fda48539988d2a1bdb6395799151e9090312a20b)
-rw-r--r-- | openmp/libomptarget/src/interface.cpp | 4 | ||||
-rw-r--r-- | openmp/libomptarget/src/private.h | 4 |
2 files changed, 5 insertions, 3 deletions
diff --git a/openmp/libomptarget/src/interface.cpp b/openmp/libomptarget/src/interface.cpp index cf6d36960c75..01f3715d6bcc 100644 --- a/openmp/libomptarget/src/interface.cpp +++ b/openmp/libomptarget/src/interface.cpp @@ -58,7 +58,7 @@ static void HandleTargetOutcome(bool success, ident_t *loc = nullptr) { case tgt_mandatory: if (!success) { if (getInfoLevel() & OMP_INFOTYPE_DUMP_TABLE) - for (const auto &Device : PM->Devices) + for (auto &Device : PM->Devices) dumpTargetPointerMappings(loc, Device); else FAILURE_MESSAGE("Run with LIBOMPTARGET_DEBUG=%d to dump host-target " @@ -76,7 +76,7 @@ static void HandleTargetOutcome(bool success, ident_t *loc = nullptr) { 1, "failure of target construct while offloading is mandatory"); } else { if (getInfoLevel() & OMP_INFOTYPE_DUMP_TABLE) - for (const auto &Device : PM->Devices) + for (auto &Device : PM->Devices) dumpTargetPointerMappings(loc, Device); } break; diff --git a/openmp/libomptarget/src/private.h b/openmp/libomptarget/src/private.h index fb6f681d3020..3b0e57dfe15e 100644 --- a/openmp/libomptarget/src/private.h +++ b/openmp/libomptarget/src/private.h @@ -99,7 +99,7 @@ int __kmpc_get_target_offload(void) __attribute__((weak)); //////////////////////////////////////////////////////////////////////////////// /// dump a table of all the host-target pointer pairs on failure static inline void dumpTargetPointerMappings(const ident_t *Loc, - const DeviceTy &Device) { + DeviceTy &Device) { if (Device.HostDataToTargetMap.empty()) return; @@ -109,6 +109,7 @@ static inline void dumpTargetPointerMappings(const ident_t *Loc, Kernel.getFilename(), Kernel.getLine(), Kernel.getColumn()); INFO(OMP_INFOTYPE_ALL, Device.DeviceID, "%-18s %-18s %s %s %s\n", "Host Ptr", "Target Ptr", "Size (B)", "RefCount", "Declaration"); + Device.DataMapMtx.lock(); for (const auto &HostTargetMap : Device.HostDataToTargetMap) { SourceInfo Info(HostTargetMap.HstPtrName); INFO(OMP_INFOTYPE_ALL, Device.DeviceID, @@ -118,6 +119,7 @@ static inline void dumpTargetPointerMappings(const ident_t *Loc, HostTargetMap.getRefCount(), Info.getName(), Info.getFilename(), Info.getLine(), Info.getColumn()); } + Device.DataMapMtx.unlock(); } //////////////////////////////////////////////////////////////////////////////// |