Skip to content

Commit 79cf877

Browse files
abhinavgabaadurang
andauthored
[Offload] Introduce dataFence plugin interface. (#153793)
The purpose of this fence is to ensure that any `dataSubmit`s inserted into a queue before a `dataFence` finish before finish before any `dataSubmit`s inserted after it begin. This is a no-op for most queues, since they are in-order, and by design any operations inserted into them occur in order. But the interface is supposed to be functional for out-of-order queues. The addition of the interface means that any operations that rely on such ordering (like ATTACH map-type support in #149036) can invoke it, without worrying about whether the underlying queue is in-order or out-of-order. Once a plugin supports out-of-order queues, the plugin can implement this function, without requiring any change at the libomptarget level. --------- Co-authored-by: Alex Duran <[email protected]>
1 parent 82caa25 commit 79cf877

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

offload/plugins-nextgen/amdgpu/src/rtl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2576,6 +2576,13 @@ struct AMDGPUDeviceTy : public GenericDeviceTy, AMDGenericDeviceTy {
25762576
getAgent(), (uint64_t)Size);
25772577
}
25782578

2579+
/// Insert a data fence between previous data operations and the following
2580+
/// operations. This is a no-op for AMDGPU devices as operations inserted into
2581+
/// a queue are in-order.
2582+
Error dataFence(__tgt_async_info *Async) override {
2583+
return Plugin::success();
2584+
}
2585+
25792586
/// Initialize the async info for interoperability purposes.
25802587
Error initAsyncInfoImpl(AsyncInfoWrapperTy &AsyncInfoWrapper) override {
25812588
// TODO: Implement this function.

offload/plugins-nextgen/common/include/PluginInterface.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,10 @@ struct GenericDeviceTy : public DeviceAllocatorTy {
944944
virtual Error dataRetrieveImpl(void *HstPtr, const void *TgtPtr, int64_t Size,
945945
AsyncInfoWrapperTy &AsyncInfoWrapper) = 0;
946946

947+
/// Instert a data fence between previous data operations and the following
948+
/// operations if necessary for the device
949+
virtual Error dataFence(__tgt_async_info *AsyncInfo) = 0;
950+
947951
/// Exchange data between devices (device to device transfer). Calling this
948952
/// function is only valid if GenericPlugin::isDataExchangable() passing the
949953
/// two devices returns true.
@@ -1454,6 +1458,10 @@ struct GenericPluginTy {
14541458
int DstDeviceId, void *DstPtr, int64_t Size,
14551459
__tgt_async_info *AsyncInfo);
14561460

1461+
/// Places a fence between previous data movements and following data
1462+
/// movements if necessary on the device
1463+
int32_t data_fence(int32_t DeviceId, __tgt_async_info *AsyncInfo);
1464+
14571465
/// Begin executing a kernel on the given device.
14581466
int32_t launch_kernel(int32_t DeviceId, void *TgtEntryPtr, void **TgtArgs,
14591467
ptrdiff_t *TgtOffsets, KernelArgsTy *KernelArgs,

offload/plugins-nextgen/common/src/PluginInterface.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2333,3 +2333,15 @@ int32_t GenericPluginTy::async_barrier(omp_interop_val_t *Interop) {
23332333
}
23342334
return OFFLOAD_SUCCESS;
23352335
}
2336+
2337+
int32_t GenericPluginTy::data_fence(int32_t DeviceId,
2338+
__tgt_async_info *AsyncInfo) {
2339+
auto Err = getDevice(DeviceId).dataFence(AsyncInfo);
2340+
if (Err) {
2341+
REPORT("failure to place data fence on device %d: %s\n", DeviceId,
2342+
toString(std::move(Err)).data());
2343+
return OFFLOAD_FAIL;
2344+
}
2345+
2346+
return OFFLOAD_SUCCESS;
2347+
}

offload/plugins-nextgen/cuda/src/rtl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,13 @@ struct CUDADeviceTy : public GenericDeviceTy {
856856
return Plugin::success();
857857
}
858858

859+
/// Insert a data fence between previous data operations and the following
860+
/// operations. This is a no-op for CUDA devices as operations inserted into
861+
/// a queue are in-order.
862+
Error dataFence(__tgt_async_info *Async) override {
863+
return Plugin::success();
864+
}
865+
859866
/// Initialize the device info for interoperability purposes.
860867
Error initDeviceInfoImpl(__tgt_device_info *DeviceInfo) override {
861868
assert(Context && "Context is null");

offload/plugins-nextgen/host/src/rtl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,13 @@ struct GenELF64DeviceTy : public GenericDeviceTy {
295295
"dataExchangeImpl not supported");
296296
}
297297

298+
/// Insert a data fence between previous data operations and the following
299+
/// operations. This is a no-op for Host devices as operations inserted into
300+
/// a queue are in-order.
301+
Error dataFence(__tgt_async_info *Async) override {
302+
return Plugin::success();
303+
}
304+
298305
/// All functions are already synchronous. No need to do anything on this
299306
/// synchronization function.
300307
Error synchronizeImpl(__tgt_async_info &AsyncInfo,

0 commit comments

Comments
 (0)