[Openmp-commits] [PATCH] D104418: [PoC][WIP][OpenMP][Offloading] Fixed data race in libomptarget caused by async data movement

Shilei Tian via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Wed Jun 16 13:24:45 PDT 2021


tianshilei1992 created this revision.
tianshilei1992 added reviewers: jdoerfert, grokos, JonChesterfield, ABataev.
Herald added subscribers: guansong, yaxunl.
tianshilei1992 requested review of this revision.
Herald added subscribers: openmp-commits, sstefan1.
Herald added a project: OpenMP.

The async data movement can cause data race if the target supports it.
Details can be found in [1]. This patch tries to fix this problem by attaching
an event to the entry of data mapping table. Here are the details.

For each issued data movement, a new event is generated and returned to `libomptarget`
in the async info. The event will be attached to the corresponding mapping table
entry.

For each data mapping lookup, if there is no need for a data movement, the
attached event has to be inserted into the queue to gaurantee that all following
operations in the queue can only be executed if the event is fulfilled.

This design is to avoid synchronization on the host side.

In order to support the whole logic, here is a list of changes we need:

- New data member `Event` in `__tgt_async_info`. It can be used bi-directionally.
- Two plugin interfaces are needed to destroy event (still WIP)  and set dependency.
- New volatile mutable data member `Event` in `HostDataToTargetTy`.

Note that we are using CUDA terminolofy here. Similar mechanism is assumped to
be supported by another targets. Even if the target doesn't support it, it can
be easily implemented in the following fall back way:

- `Event` can be any kind of flag that has at least two status, 0 and 1.
- `setDependency` can directly busy loop if `Event` is still 0.

Reference:
[1] https://bugs.llvm.org/show_bug.cgi?id=49940


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104418

Files:
  openmp/libomptarget/include/omptarget.h
  openmp/libomptarget/include/omptargetplugin.h
  openmp/libomptarget/plugins/cuda/src/rtl.cpp
  openmp/libomptarget/plugins/exports
  openmp/libomptarget/src/device.cpp
  openmp/libomptarget/src/device.h
  openmp/libomptarget/src/omptarget.cpp
  openmp/libomptarget/src/rtl.cpp
  openmp/libomptarget/src/rtl.h
  openmp/libomptarget/test/offloading/bug49334.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104418.352537.patch
Type: text/x-patch
Size: 9608 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210616/3fa01725/attachment.bin>


More information about the Openmp-commits mailing list