Changeset View
Changeset View
Standalone View
Standalone View
openmp/libomptarget/src/api.cpp
Show First 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | if (device_num == omp_get_initial_device()) { | ||||
return; | return; | ||||
} | } | ||||
if (!device_is_ready(device_num)) { | if (!device_is_ready(device_num)) { | ||||
DP("omp_target_free returns, nothing to do\n"); | DP("omp_target_free returns, nothing to do\n"); | ||||
return; | return; | ||||
} | } | ||||
PM->Devices[device_num].deleteData(device_ptr); | PM->Devices[device_num]->deleteData(device_ptr); | ||||
DP("omp_target_free deallocated device ptr\n"); | DP("omp_target_free deallocated device ptr\n"); | ||||
} | } | ||||
EXTERN int omp_target_is_present(const void *ptr, int device_num) { | EXTERN int omp_target_is_present(const void *ptr, int device_num) { | ||||
TIMESCOPE(); | TIMESCOPE(); | ||||
DP("Call to omp_target_is_present for device %d and address " DPxMOD "\n", | DP("Call to omp_target_is_present for device %d and address " DPxMOD "\n", | ||||
device_num, DPxPTR(ptr)); | device_num, DPxPTR(ptr)); | ||||
Show All 11 Lines | EXTERN int omp_target_is_present(const void *ptr, int device_num) { | ||||
size_t DevicesSize = PM->Devices.size(); | size_t DevicesSize = PM->Devices.size(); | ||||
PM->RTLsMtx.unlock(); | PM->RTLsMtx.unlock(); | ||||
if (DevicesSize <= (size_t)device_num) { | if (DevicesSize <= (size_t)device_num) { | ||||
DP("Call to omp_target_is_present with invalid device ID, returning " | DP("Call to omp_target_is_present with invalid device ID, returning " | ||||
"false\n"); | "false\n"); | ||||
return false; | return false; | ||||
} | } | ||||
DeviceTy &Device = PM->Devices[device_num]; | DeviceTy &Device = *PM->Devices[device_num]; | ||||
bool IsLast; // not used | bool IsLast; // not used | ||||
bool IsHostPtr; | bool IsHostPtr; | ||||
void *TgtPtr = Device.getTgtPtrBegin(const_cast<void *>(ptr), 0, IsLast, | void *TgtPtr = Device.getTgtPtrBegin(const_cast<void *>(ptr), 0, IsLast, | ||||
/*UpdateRefCount=*/false, | /*UpdateRefCount=*/false, | ||||
/*UseHoldRefCount=*/false, IsHostPtr); | /*UseHoldRefCount=*/false, IsHostPtr); | ||||
int rc = (TgtPtr != NULL); | int rc = (TgtPtr != NULL); | ||||
// Under unified memory the host pointer can be returned by the | // Under unified memory the host pointer can be returned by the | ||||
// getTgtPtrBegin() function which means that there is no device | // getTgtPtrBegin() function which means that there is no device | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | EXTERN int omp_target_memcpy(void *dst, const void *src, size_t length, | ||||
if (src_device == omp_get_initial_device() && | if (src_device == omp_get_initial_device() && | ||||
dst_device == omp_get_initial_device()) { | dst_device == omp_get_initial_device()) { | ||||
DP("copy from host to host\n"); | DP("copy from host to host\n"); | ||||
const void *p = memcpy(dstAddr, srcAddr, length); | const void *p = memcpy(dstAddr, srcAddr, length); | ||||
if (p == NULL) | if (p == NULL) | ||||
rc = OFFLOAD_FAIL; | rc = OFFLOAD_FAIL; | ||||
} else if (src_device == omp_get_initial_device()) { | } else if (src_device == omp_get_initial_device()) { | ||||
DP("copy from host to device\n"); | DP("copy from host to device\n"); | ||||
DeviceTy &DstDev = PM->Devices[dst_device]; | DeviceTy &DstDev = *PM->Devices[dst_device]; | ||||
AsyncInfoTy AsyncInfo(DstDev); | AsyncInfoTy AsyncInfo(DstDev); | ||||
rc = DstDev.submitData(dstAddr, srcAddr, length, AsyncInfo); | rc = DstDev.submitData(dstAddr, srcAddr, length, AsyncInfo); | ||||
} else if (dst_device == omp_get_initial_device()) { | } else if (dst_device == omp_get_initial_device()) { | ||||
DP("copy from device to host\n"); | DP("copy from device to host\n"); | ||||
DeviceTy &SrcDev = PM->Devices[src_device]; | DeviceTy &SrcDev = *PM->Devices[src_device]; | ||||
AsyncInfoTy AsyncInfo(SrcDev); | AsyncInfoTy AsyncInfo(SrcDev); | ||||
rc = SrcDev.retrieveData(dstAddr, srcAddr, length, AsyncInfo); | rc = SrcDev.retrieveData(dstAddr, srcAddr, length, AsyncInfo); | ||||
} else { | } else { | ||||
DP("copy from device to device\n"); | DP("copy from device to device\n"); | ||||
DeviceTy &SrcDev = PM->Devices[src_device]; | DeviceTy &SrcDev = *PM->Devices[src_device]; | ||||
DeviceTy &DstDev = PM->Devices[dst_device]; | DeviceTy &DstDev = *PM->Devices[dst_device]; | ||||
// First try to use D2D memcpy which is more efficient. If fails, fall back | // First try to use D2D memcpy which is more efficient. If fails, fall back | ||||
// to unefficient way. | // to unefficient way. | ||||
if (SrcDev.isDataExchangable(DstDev)) { | if (SrcDev.isDataExchangable(DstDev)) { | ||||
AsyncInfoTy AsyncInfo(SrcDev); | AsyncInfoTy AsyncInfo(SrcDev); | ||||
rc = SrcDev.dataExchange(srcAddr, DstDev, dstAddr, length, AsyncInfo); | rc = SrcDev.dataExchange(srcAddr, DstDev, dstAddr, length, AsyncInfo); | ||||
if (rc == OFFLOAD_SUCCESS) | if (rc == OFFLOAD_SUCCESS) | ||||
return OFFLOAD_SUCCESS; | return OFFLOAD_SUCCESS; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | if (device_num == omp_get_initial_device()) { | ||||
return OFFLOAD_FAIL; | return OFFLOAD_FAIL; | ||||
} | } | ||||
if (!device_is_ready(device_num)) { | if (!device_is_ready(device_num)) { | ||||
REPORT("omp_target_associate_ptr returns OFFLOAD_FAIL\n"); | REPORT("omp_target_associate_ptr returns OFFLOAD_FAIL\n"); | ||||
return OFFLOAD_FAIL; | return OFFLOAD_FAIL; | ||||
} | } | ||||
DeviceTy &Device = PM->Devices[device_num]; | DeviceTy &Device = *PM->Devices[device_num]; | ||||
void *device_addr = (void *)((uint64_t)device_ptr + (uint64_t)device_offset); | void *device_addr = (void *)((uint64_t)device_ptr + (uint64_t)device_offset); | ||||
int rc = Device.associatePtr(const_cast<void *>(host_ptr), | int rc = Device.associatePtr(const_cast<void *>(host_ptr), | ||||
const_cast<void *>(device_addr), size); | const_cast<void *>(device_addr), size); | ||||
DP("omp_target_associate_ptr returns %d\n", rc); | DP("omp_target_associate_ptr returns %d\n", rc); | ||||
return rc; | return rc; | ||||
} | } | ||||
EXTERN int omp_target_disassociate_ptr(const void *host_ptr, int device_num) { | EXTERN int omp_target_disassociate_ptr(const void *host_ptr, int device_num) { | ||||
Show All 13 Lines | if (device_num == omp_get_initial_device()) { | ||||
return OFFLOAD_FAIL; | return OFFLOAD_FAIL; | ||||
} | } | ||||
if (!device_is_ready(device_num)) { | if (!device_is_ready(device_num)) { | ||||
REPORT("omp_target_disassociate_ptr returns OFFLOAD_FAIL\n"); | REPORT("omp_target_disassociate_ptr returns OFFLOAD_FAIL\n"); | ||||
return OFFLOAD_FAIL; | return OFFLOAD_FAIL; | ||||
} | } | ||||
DeviceTy &Device = PM->Devices[device_num]; | DeviceTy &Device = *PM->Devices[device_num]; | ||||
int rc = Device.disassociatePtr(const_cast<void *>(host_ptr)); | int rc = Device.disassociatePtr(const_cast<void *>(host_ptr)); | ||||
DP("omp_target_disassociate_ptr returns %d\n", rc); | DP("omp_target_disassociate_ptr returns %d\n", rc); | ||||
return rc; | return rc; | ||||
} | } |