Skip to content

Commit b85804f

Browse files
adurangabhinavgaba
authored andcommitted
[Offload] Introduce dataFence plugin interface.
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 llvm#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 plugins can implement this function, without requiring any change at the libomptarget level.
1 parent db5f7dc commit b85804f

File tree

5 files changed

+32
-0
lines changed

5 files changed

+32
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,6 +2537,10 @@ struct AMDGPUDeviceTy : public GenericDeviceTy, AMDGenericDeviceTy {
25372537
getAgent(), (uint64_t)Size);
25382538
}
25392539

2540+
Error dataFence(__tgt_async_info *Async) override {
2541+
return Plugin::success();
2542+
}
2543+
25402544
/// Initialize the async info for interoperability purposes.
25412545
Error initAsyncInfoImpl(AsyncInfoWrapperTy &AsyncInfoWrapper) override {
25422546
// 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.
@@ -1448,6 +1452,10 @@ struct GenericPluginTy {
14481452
int DstDeviceId, void *DstPtr, int64_t Size,
14491453
__tgt_async_info *AsyncInfo);
14501454

1455+
/// Places a fence between previous data movements and following data
1456+
/// movements if necessary on the device
1457+
int32_t data_fence(int32_t DeviceId, __tgt_async_info *AsyncInfo);
1458+
14511459
/// Begin executing a kernel on the given device.
14521460
int32_t launch_kernel(int32_t DeviceId, void *TgtEntryPtr, void **TgtArgs,
14531461
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
@@ -2324,3 +2324,15 @@ int32_t GenericPluginTy::async_barrier(omp_interop_val_t *Interop) {
23242324
}
23252325
return OFFLOAD_SUCCESS;
23262326
}
2327+
2328+
int32_t GenericPluginTy::data_fence(int32_t DeviceId,
2329+
__tgt_async_info *AsyncInfo) {
2330+
auto Err = getDevice(DeviceId).dataFence(AsyncInfo);
2331+
if (Err) {
2332+
REPORT("Failure to place data fence on device %d: %s\n", DeviceId,
2333+
toString(std::move(Err)).data());
2334+
return OFFLOAD_FAIL;
2335+
}
2336+
2337+
return OFFLOAD_SUCCESS;
2338+
}

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

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

859+
Error dataFence(__tgt_async_info *Async) override {
860+
return Plugin::success();
861+
}
862+
859863
/// Initialize the device info for interoperability purposes.
860864
Error initDeviceInfoImpl(__tgt_device_info *DeviceInfo) override {
861865
assert(Context && "Context is null");

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

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

298+
Error dataFence(__tgt_async_info *Async) override {
299+
return Plugin::success();
300+
}
301+
298302
/// All functions are already synchronous. No need to do anything on this
299303
/// synchronization function.
300304
Error synchronizeImpl(__tgt_async_info &AsyncInfo,

0 commit comments

Comments
 (0)