LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 49207 - Misuse of libomptarget plugin interface
Summary: Misuse of libomptarget plugin interface
Status: RESOLVED FIXED
Alias: None
Product: OpenMP
Classification: Unclassified
Component: Runtime Library (show other bugs)
Version: unspecified
Hardware: PC All
: P release blocker
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks: release-12.0.0
  Show dependency tree
 
Reported: 2021-02-16 08:54 PST by Shilei Tian
Modified: 2021-02-19 22:28 PST (History)
3 users (show)

See Also:
Fixed By Commit(s): 2518cc65d2a7564bb49d7b806f23dd47212dcefd 76d5d54f62599d249e0bf2d1b0998451a584c3f3


Attachments
fix for release branch (4.55 KB, patch)
2021-02-16 11:29 PST, Johannes Doerfert
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Shilei Tian 2021-02-16 08:54:58 PST
This bug was reported by Guilherme Valarini via Openmp-dev (openmp-dev@lists.llvm.org). The link is https://lists.llvm.org/pipermail/openmp-dev/2021-February/003867.html

The following is the bug description.

In both cases, the address to a local variable is passed as the host data to be copied to the target device, but since this function can be asynchronously executed, such variables can get out of scope when the actual submission is done.


```
// File: openmp/libomptarget/src/omptarget.cpp:419
if (arg_types[i] & OMP_TGT_MAPTYPE_PTR_AND_OBJ && !IsHostPtr) {
  DP("Update pointer (" DPxMOD ") -> [" DPxMOD "]\n",
      DPxPTR(PointerTgtPtrBegin), DPxPTR(TgtPtrBegin));
  uint64_t Delta = (uint64_t)HstPtrBegin - (uint64_t)HstPtrBase;
  void *TgtPtrBase = (void *)((uint64_t)TgtPtrBegin - Delta);
  int rt = Device.submitData(PointerTgtPtrBegin, &TgtPtrBase,
                              sizeof(void *), async_info_ptr);
  if (rt != OFFLOAD_SUCCESS) {
    REPORT("Copying data to device failed.\n");
    return OFFLOAD_FAIL;
  }
  // create shadow pointers for this entry
  Device.ShadowMtx.lock();
  Device.ShadowPtrMap[Pointer_HstPtrBegin] = {
      HstPtrBase, PointerTgtPtrBegin, TgtPtrBase};
  Device.ShadowMtx.unlock();
}
```

```
// File: openmp/libomptarget/src/omptarget.cpp:1141
DP("Parent lambda base " DPxMOD "\n", DPxPTR(TgtPtrBase));
uint64_t Delta = (uint64_t)HstPtrBegin - (uint64_t)HstPtrBase;
void *TgtPtrBegin = (void *)((uintptr_t)TgtPtrBase + Delta);
void *PointerTgtPtrBegin = Device.getTgtPtrBegin(
    HstPtrVal, ArgSizes[I], IsLast, false, IsHostPtr);
if (!PointerTgtPtrBegin) {
  DP("No lambda captured variable mapped (" DPxMOD ") - ignored\n",
      DPxPTR(HstPtrVal));
  continue;
}
if (PM->RTLs.RequiresFlags & OMP_REQ_UNIFIED_SHARED_MEMORY &&
    TgtPtrBegin == HstPtrBegin) {
  DP("Unified memory is active, no need to map lambda captured"
      "variable (" DPxMOD ")\n",
      DPxPTR(HstPtrVal));
  continue;
}
DP("Update lambda reference (" DPxMOD ") -> [" DPxMOD "]\n",
    DPxPTR(PointerTgtPtrBegin), DPxPTR(TgtPtrBegin));
Ret = Device.submitData(TgtPtrBegin, &PointerTgtPtrBegin,
                        sizeof(void *), AsyncInfo);
if (Ret != OFFLOAD_SUCCESS) {
  REPORT("Copying data to device failed.\n");
  return OFFLOAD_FAIL;
}
```
Comment 1 Shilei Tian 2021-02-16 08:55:52 PST
Johannes proposed a fix in https://reviews.llvm.org/D96667.
Comment 2 Johannes Doerfert 2021-02-16 11:29:48 PST
Created attachment 24542 [details]
fix for release branch
Comment 3 Johannes Doerfert 2021-02-16 11:30:35 PST
I'll push the fix into main today, the release branch version is attached as patch file.
Comment 4 Johannes Doerfert 2021-02-17 08:51:52 PST
@tstellar Can you apply the patch file to fix this in 12?
Comment 5 Tom Stellard 2021-02-19 22:28:37 PST
Merged: 76d5d54f62599d249e0bf2d1b0998451a584c3f3