Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
openmp/libomptarget/src/device.cpp
Show First 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | int DeviceTy::associatePtr(void *HstPtrBegin, void *TgtPtrBegin, int64_t Size) { | ||||
DP("Creating new map entry: HstBase=" DPxMOD ", HstBegin=" DPxMOD | DP("Creating new map entry: HstBase=" DPxMOD ", HstBegin=" DPxMOD | ||||
", HstEnd=" DPxMOD ", TgtBegin=" DPxMOD ", DynRefCount=%s, " | ", HstEnd=" DPxMOD ", TgtBegin=" DPxMOD ", DynRefCount=%s, " | ||||
"HoldRefCount=%s\n", | "HoldRefCount=%s\n", | ||||
DPxPTR(NewEntry.HstPtrBase), DPxPTR(NewEntry.HstPtrBegin), | DPxPTR(NewEntry.HstPtrBase), DPxPTR(NewEntry.HstPtrBegin), | ||||
DPxPTR(NewEntry.HstPtrEnd), DPxPTR(NewEntry.TgtPtrBegin), | DPxPTR(NewEntry.HstPtrEnd), DPxPTR(NewEntry.TgtPtrBegin), | ||||
NewEntry.dynRefCountToStr().c_str(), NewEntry.holdRefCountToStr().c_str()); | NewEntry.dynRefCountToStr().c_str(), NewEntry.holdRefCountToStr().c_str()); | ||||
(void)NewEntry; | (void)NewEntry; | ||||
return OFFLOAD_SUCCESS; | // Notify the plugin about the new mapping. | ||||
return notifyDataMapped(HstPtrBegin, Size); | |||||
} | } | ||||
int DeviceTy::disassociatePtr(void *HstPtrBegin) { | int DeviceTy::disassociatePtr(void *HstPtrBegin) { | ||||
HDTTMapAccessorTy HDTTMap = HostDataToTargetMap.getExclusiveAccessor(); | HDTTMapAccessorTy HDTTMap = HostDataToTargetMap.getExclusiveAccessor(); | ||||
auto It = HDTTMap->find(HstPtrBegin); | auto It = HDTTMap->find(HstPtrBegin); | ||||
if (It != HDTTMap->end()) { | if (It != HDTTMap->end()) { | ||||
HostDataToTargetTy &HDTT = *It->HDTT; | HostDataToTargetTy &HDTT = *It->HDTT; | ||||
// Mapping exists | // Mapping exists | ||||
if (HDTT.getHoldRefCount()) { | if (HDTT.getHoldRefCount()) { | ||||
// This is based on OpenACC 3.1, sec 3.2.33 "acc_unmap_data", L3656-3657: | // This is based on OpenACC 3.1, sec 3.2.33 "acc_unmap_data", L3656-3657: | ||||
// "It is an error to call acc_unmap_data if the structured reference | // "It is an error to call acc_unmap_data if the structured reference | ||||
// count for the pointer is not zero." | // count for the pointer is not zero." | ||||
REPORT("Trying to disassociate a pointer with a non-zero hold reference " | REPORT("Trying to disassociate a pointer with a non-zero hold reference " | ||||
"count\n"); | "count\n"); | ||||
} else if (HDTT.isDynRefCountInf()) { | } else if (HDTT.isDynRefCountInf()) { | ||||
DP("Association found, removing it\n"); | DP("Association found, removing it\n"); | ||||
void *Event = HDTT.getEvent(); | void *Event = HDTT.getEvent(); | ||||
delete &HDTT; | delete &HDTT; | ||||
if (Event) | if (Event) | ||||
destroyEvent(Event); | destroyEvent(Event); | ||||
HDTTMap->erase(It); | HDTTMap->erase(It); | ||||
return OFFLOAD_SUCCESS; | |||||
// Notify the plugin about the unmapped memory. | |||||
return notifyDataUnmapped(HstPtrBegin); | |||||
} else { | } else { | ||||
REPORT("Trying to disassociate a pointer which was not mapped via " | REPORT("Trying to disassociate a pointer which was not mapped via " | ||||
"omp_target_associate_ptr\n"); | "omp_target_associate_ptr\n"); | ||||
} | } | ||||
} else { | } else { | ||||
REPORT("Association not found\n"); | REPORT("Association not found\n"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 164 Lines • ▼ Show 20 Lines | if (LR.Flags.IsContained || | ||||
INFO(OMP_INFOTYPE_MAPPING_CHANGED, DeviceID, | INFO(OMP_INFOTYPE_MAPPING_CHANGED, DeviceID, | ||||
"Creating new map entry with HstPtrBase=" DPxMOD | "Creating new map entry with HstPtrBase=" DPxMOD | ||||
", HstPtrBegin=" DPxMOD ", TgtPtrBegin=" DPxMOD ", Size=%ld, " | ", HstPtrBegin=" DPxMOD ", TgtPtrBegin=" DPxMOD ", Size=%ld, " | ||||
"DynRefCount=%s, HoldRefCount=%s, Name=%s\n", | "DynRefCount=%s, HoldRefCount=%s, Name=%s\n", | ||||
DPxPTR(HstPtrBase), DPxPTR(HstPtrBegin), DPxPTR(Ptr), Size, | DPxPTR(HstPtrBase), DPxPTR(HstPtrBegin), DPxPTR(Ptr), Size, | ||||
Entry->dynRefCountToStr().c_str(), Entry->holdRefCountToStr().c_str(), | Entry->dynRefCountToStr().c_str(), Entry->holdRefCountToStr().c_str(), | ||||
(HstPtrName) ? getNameFromMapping(HstPtrName).c_str() : "unknown"); | (HstPtrName) ? getNameFromMapping(HstPtrName).c_str() : "unknown"); | ||||
TargetPointer = (void *)Ptr; | TargetPointer = (void *)Ptr; | ||||
// Notify the plugin about the new mapping. | |||||
if (notifyDataMapped(HstPtrBegin, Size)) | |||||
return {{false /* IsNewEntry */, false /* IsHostPointer */}, | |||||
nullptr /* Entry */, | |||||
nullptr /* TargetPointer */}; | |||||
} else { | } else { | ||||
// This entry is not present and we did not create a new entry for it. | // This entry is not present and we did not create a new entry for it. | ||||
IsPresent = false; | IsPresent = false; | ||||
} | } | ||||
// If the target pointer is valid, and we need to transfer data, issue the | // If the target pointer is valid, and we need to transfer data, issue the | ||||
// data transfer. | // data transfer. | ||||
if (TargetPointer && !IsHostPtr && HasFlagTo && (IsNew || HasFlagAlways)) { | if (TargetPointer && !IsHostPtr && HasFlagTo && (IsNew || HasFlagAlways)) { | ||||
▲ Show 20 Lines • Show All 164 Lines • ▼ Show 20 Lines | int DeviceTy::deallocTgtPtrAndEntry(HostDataToTargetTy *Entry, int64_t Size) { | ||||
void *Event = Entry->getEvent(); | void *Event = Entry->getEvent(); | ||||
if (Event && destroyEvent(Event) != OFFLOAD_SUCCESS) { | if (Event && destroyEvent(Event) != OFFLOAD_SUCCESS) { | ||||
REPORT("Failed to destroy event " DPxMOD "\n", DPxPTR(Event)); | REPORT("Failed to destroy event " DPxMOD "\n", DPxPTR(Event)); | ||||
return OFFLOAD_FAIL; | return OFFLOAD_FAIL; | ||||
} | } | ||||
int Ret = deleteData((void *)Entry->TgtPtrBegin); | int Ret = deleteData((void *)Entry->TgtPtrBegin); | ||||
// Notify the plugin about the unmapped memory. | |||||
Ret |= notifyDataUnmapped((void *)Entry->HstPtrBegin); | |||||
delete Entry; | delete Entry; | ||||
return Ret; | return Ret; | ||||
} | } | ||||
/// Init device, should not be called directly. | /// Init device, should not be called directly. | ||||
void DeviceTy::init() { | void DeviceTy::init() { | ||||
// Make call to init_requires if it exists for this plugin. | // Make call to init_requires if it exists for this plugin. | ||||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | if (!AsyncInfo || !RTL->data_exchange_async || !RTL->synchronize) { | ||||
assert(RTL->data_exchange && "RTL->data_exchange is nullptr"); | assert(RTL->data_exchange && "RTL->data_exchange is nullptr"); | ||||
return RTL->data_exchange(RTLDeviceID, SrcPtr, DstDev.RTLDeviceID, DstPtr, | return RTL->data_exchange(RTLDeviceID, SrcPtr, DstDev.RTLDeviceID, DstPtr, | ||||
Size); | Size); | ||||
} | } | ||||
return RTL->data_exchange_async(RTLDeviceID, SrcPtr, DstDev.RTLDeviceID, | return RTL->data_exchange_async(RTLDeviceID, SrcPtr, DstDev.RTLDeviceID, | ||||
DstPtr, Size, AsyncInfo); | DstPtr, Size, AsyncInfo); | ||||
} | } | ||||
int32_t DeviceTy::notifyDataMapped(void *HstPtr, int64_t Size) { | |||||
if (!RTL->data_notify_mapped) | |||||
return OFFLOAD_SUCCESS; | |||||
DP("Notifying about new mapping: HstPtr=" DPxMOD ", Size=%" PRId64 "\n", | |||||
ye-luo: "Size=%" missing "%" | |||||
DPxPTR(HstPtr), Size); | |||||
if (RTL->data_notify_mapped(RTLDeviceID, HstPtr, Size)) { | |||||
REPORT("Notifiying about data mapping failed.\n"); | |||||
return OFFLOAD_FAIL; | |||||
} | |||||
return OFFLOAD_SUCCESS; | |||||
} | |||||
int32_t DeviceTy::notifyDataUnmapped(void *HstPtr) { | |||||
if (!RTL->data_notify_unmapped) | |||||
return OFFLOAD_SUCCESS; | |||||
DP("Notifying about an unmapping: HstPtr=" DPxMOD "\n", DPxPTR(HstPtr)); | |||||
if (RTL->data_notify_unmapped(RTLDeviceID, HstPtr)) { | |||||
REPORT("Notifiying about data unmapping failed.\n"); | |||||
return OFFLOAD_FAIL; | |||||
} | |||||
return OFFLOAD_SUCCESS; | |||||
} | |||||
// Run region on device | // Run region on device | ||||
int32_t DeviceTy::launchKernel(void *TgtEntryPtr, void **TgtVarsPtr, | int32_t DeviceTy::launchKernel(void *TgtEntryPtr, void **TgtVarsPtr, | ||||
ptrdiff_t *TgtOffsets, | ptrdiff_t *TgtOffsets, | ||||
const KernelArgsTy &KernelArgs, | const KernelArgsTy &KernelArgs, | ||||
AsyncInfoTy &AsyncInfo) { | AsyncInfoTy &AsyncInfo) { | ||||
return RTL->launch_kernel(RTLDeviceID, TgtEntryPtr, TgtVarsPtr, TgtOffsets, | return RTL->launch_kernel(RTLDeviceID, TgtEntryPtr, TgtVarsPtr, TgtOffsets, | ||||
&KernelArgs, AsyncInfo); | &KernelArgs, AsyncInfo); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines |
"Size=%" missing "%"