: HstPtrBegin(HstPtr), DataSize(Size), ForceDelete(ForceDelete),
HasCloseModifier(HasCloseModifier) {}
};
+
+/// Synchronize device
+static int syncDevice(DeviceTy &Device, __tgt_async_info *AsyncInfo) {
+ assert(AsyncInfo && AsyncInfo->Queue && "Invalid AsyncInfo");
+ if (Device.synchronize(AsyncInfo) != OFFLOAD_SUCCESS) {
+ REPORT("Failed to synchronize device.\n");
+ return OFFLOAD_FAIL;
+ }
+
+ return OFFLOAD_SUCCESS;
+}
} // namespace
/// Internal function to undo the mapping and retrieve the data from the device.
// AsyncInfo->Queue will not be nullptr, so again, we don't need to
// synchronize.
if (AsyncInfo && AsyncInfo->Queue) {
- Ret = Device.synchronize(AsyncInfo);
- if (Ret != OFFLOAD_SUCCESS) {
- REPORT("Failed to synchronize device.\n");
+ Ret = syncDevice(Device, AsyncInfo);
+ if (Ret != OFFLOAD_SUCCESS)
return OFFLOAD_FAIL;
- }
}
// Deallocate target pointer
REPORT("Failed to process data after launching the kernel.\n");
return OFFLOAD_FAIL;
}
+ } else if (AsyncInfo.Queue) {
+ // If ArgNum is zero, but AsyncInfo.Queue is valid, then the kernel doesn't
+ // hava any argument, and the device supports async operations, so we need a
+ // sync at this point.
+ return syncDevice(Device, &AsyncInfo);
}
return OFFLOAD_SUCCESS;