Skip to content

[Offload] Introduce dataFence plugin interface. #153793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions offload/plugins-nextgen/amdgpu/src/rtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2537,6 +2537,13 @@ struct AMDGPUDeviceTy : public GenericDeviceTy, AMDGenericDeviceTy {
getAgent(), (uint64_t)Size);
}

/// Insert a data fence between previous data operations and the following
/// operations. This is a no-op for AMDGPU devices as operations inserted into
/// a queue are in-order.
Error dataFence(__tgt_async_info *Async) override {
return Plugin::success();
}

/// Initialize the async info for interoperability purposes.
Error initAsyncInfoImpl(AsyncInfoWrapperTy &AsyncInfoWrapper) override {
// TODO: Implement this function.
Expand Down
8 changes: 8 additions & 0 deletions offload/plugins-nextgen/common/include/PluginInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,10 @@ struct GenericDeviceTy : public DeviceAllocatorTy {
virtual Error dataRetrieveImpl(void *HstPtr, const void *TgtPtr, int64_t Size,
AsyncInfoWrapperTy &AsyncInfoWrapper) = 0;

/// Instert a data fence between previous data operations and the following
/// operations if necessary for the device
virtual Error dataFence(__tgt_async_info *AsyncInfo) = 0;

/// Exchange data between devices (device to device transfer). Calling this
/// function is only valid if GenericPlugin::isDataExchangable() passing the
/// two devices returns true.
Expand Down Expand Up @@ -1448,6 +1452,10 @@ struct GenericPluginTy {
int DstDeviceId, void *DstPtr, int64_t Size,
__tgt_async_info *AsyncInfo);

/// Places a fence between previous data movements and following data
/// movements if necessary on the device
int32_t data_fence(int32_t DeviceId, __tgt_async_info *AsyncInfo);

/// Begin executing a kernel on the given device.
int32_t launch_kernel(int32_t DeviceId, void *TgtEntryPtr, void **TgtArgs,
ptrdiff_t *TgtOffsets, KernelArgsTy *KernelArgs,
Expand Down
12 changes: 12 additions & 0 deletions offload/plugins-nextgen/common/src/PluginInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2324,3 +2324,15 @@ int32_t GenericPluginTy::async_barrier(omp_interop_val_t *Interop) {
}
return OFFLOAD_SUCCESS;
}

int32_t GenericPluginTy::data_fence(int32_t DeviceId,
__tgt_async_info *AsyncInfo) {
auto Err = getDevice(DeviceId).dataFence(AsyncInfo);
if (Err) {
REPORT("failure to place data fence on device %d: %s\n", DeviceId,
toString(std::move(Err)).data());
return OFFLOAD_FAIL;
}

return OFFLOAD_SUCCESS;
}
7 changes: 7 additions & 0 deletions offload/plugins-nextgen/cuda/src/rtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,13 @@ struct CUDADeviceTy : public GenericDeviceTy {
return Plugin::success();
}

/// Insert a data fence between previous data operations and the following
/// operations. This is a no-op for CUDA devices as operations inserted into
/// a queue are in-order.
Error dataFence(__tgt_async_info *Async) override {
return Plugin::success();
}

/// Initialize the device info for interoperability purposes.
Error initDeviceInfoImpl(__tgt_device_info *DeviceInfo) override {
assert(Context && "Context is null");
Expand Down
7 changes: 7 additions & 0 deletions offload/plugins-nextgen/host/src/rtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ struct GenELF64DeviceTy : public GenericDeviceTy {
"dataExchangeImpl not supported");
}

/// Insert a data fence between previous data operations and the following
/// operations. This is a no-op for Host devices as operations inserted into
/// a queue are in-order.
Error dataFence(__tgt_async_info *Async) override {
return Plugin::success();
}

/// All functions are already synchronous. No need to do anything on this
/// synchronization function.
Error synchronizeImpl(__tgt_async_info &AsyncInfo,
Expand Down
Loading