[all-commits] [llvm/llvm-project] 9584c6: [OpenMP][Offloading] Fixed data race in libomptarg...

Shilei Tian via All-commits all-commits at lists.llvm.org
Wed Jan 5 17:20:19 PST 2022

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9584c6fa2fe216522b86ee5422147b511c73cb4a
  Author: Shilei Tian <i at tianshilei.me>
  Date:   2022-01-05 (Wed, 05 Jan 2022)

  Changed paths:
    M openmp/libomptarget/include/device.h
    M openmp/libomptarget/src/device.cpp
    M openmp/libomptarget/src/omptarget.cpp

  Log Message:
  [OpenMP][Offloading] Fixed data race in libomptarget caused by async data movement

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`
by calling `createEvent`. The event will be attached to the corresponding mapping table

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 host side.

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.
- `waitEvent` can directly busy loop if `Event` is still 0.

My local test shows that `bug49334.cpp` can pass.

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

Reviewed By: grokos, JonChesterfield, ye-luo

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

More information about the All-commits mailing list