<div dir="ltr">Hi everyone,<div><br></div><div>I am part of a team that is currently developing a new device target for libomptarget. We came across some strange behavior from the target agnostic layer and through some digging we have found two possible misuses of the plugin interface for the async functions (quoted below). 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.</div><div><br></div><div>Is there anyone that could check if this is an actual issue with the target agnostic layer? I could have sent a bug report but since I actually do not know if this is actually a problem, I thought it would be better to report it here first .</div><div><br></div><div>File: openmp/libomptarget/src/omptarget.cpp:419<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">if (arg_types[i] & OMP_TGT_MAPTYPE_PTR_AND_OBJ && !IsHostPtr) {<br>  DP("Update pointer (" DPxMOD ") -> [" DPxMOD "]\n",<br>      DPxPTR(PointerTgtPtrBegin), DPxPTR(TgtPtrBegin));<br>  uint64_t Delta = (uint64_t)HstPtrBegin - (uint64_t)HstPtrBase;<br>  void *TgtPtrBase = (void *)((uint64_t)TgtPtrBegin - Delta);<br>  int rt = Device.submitData(PointerTgtPtrBegin, &TgtPtrBase,<br>                              sizeof(void *), async_info_ptr);<br>  if (rt != OFFLOAD_SUCCESS) {<br>    REPORT("Copying data to device failed.\n");<br>    return OFFLOAD_FAIL;<br>  }<br>  // create shadow pointers for this entry<br>  Device.ShadowMtx.lock();<br>  Device.ShadowPtrMap[Pointer_HstPtrBegin] = {<br>      HstPtrBase, PointerTgtPtrBegin, TgtPtrBase};<br>  Device.ShadowMtx.unlock();<br>}<br></blockquote><div> </div><div>File: openmp/libomptarget/src/omptarget.cpp:1141<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">DP("Parent lambda base " DPxMOD "\n", DPxPTR(TgtPtrBase));<br>uint64_t Delta = (uint64_t)HstPtrBegin - (uint64_t)HstPtrBase;<br>void *TgtPtrBegin = (void *)((uintptr_t)TgtPtrBase + Delta);<br>void *PointerTgtPtrBegin = Device.getTgtPtrBegin(<br>    HstPtrVal, ArgSizes[I], IsLast, false, IsHostPtr);<br>if (!PointerTgtPtrBegin) {<br>  DP("No lambda captured variable mapped (" DPxMOD ") - ignored\n",<br>      DPxPTR(HstPtrVal));<br>  continue;<br>}<br>if (PM->RTLs.RequiresFlags & OMP_REQ_UNIFIED_SHARED_MEMORY &&<br>    TgtPtrBegin == HstPtrBegin) {<br>  DP("Unified memory is active, no need to map lambda captured"<br>      "variable (" DPxMOD ")\n",<br>      DPxPTR(HstPtrVal));<br>  continue;<br>}<br>DP("Update lambda reference (" DPxMOD ") -> [" DPxMOD "]\n",<br>    DPxPTR(PointerTgtPtrBegin), DPxPTR(TgtPtrBegin));<br>Ret = Device.submitData(TgtPtrBegin, &PointerTgtPtrBegin,<br>                        sizeof(void *), AsyncInfo);<br>if (Ret != OFFLOAD_SUCCESS) {<br>  REPORT("Copying data to device failed.\n");<br>  return OFFLOAD_FAIL;<br>}</blockquote><div><br></div><div>Note: We already came up with a way of fixing the first case by first storing TgtPtrBase in the shadow map and passing a pointer to the correct map member (which will live long enough for the async function to complete) instead of the local variable. But the second case is a little bit trickier to fix without any additional data added to the target agnostic structures. </div><div><br></div><div>Thanks in advance!</div></div>