diff options
Diffstat (limited to 'offload/plugins-nextgen/common/include/PluginInterface.h')
-rw-r--r-- | offload/plugins-nextgen/common/include/PluginInterface.h | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/offload/plugins-nextgen/common/include/PluginInterface.h b/offload/plugins-nextgen/common/include/PluginInterface.h index 1d64193..c9ab34b 100644 --- a/offload/plugins-nextgen/common/include/PluginInterface.h +++ b/offload/plugins-nextgen/common/include/PluginInterface.h @@ -60,6 +60,7 @@ struct GenericPluginTy; struct GenericKernelTy; struct GenericDeviceTy; struct RecordReplayTy; +template <typename ResourceRef> class GenericDeviceResourceManagerTy; namespace Plugin { /// Create a success error. This is the same as calling Error::success(), but @@ -127,6 +128,20 @@ struct AsyncInfoWrapperTy { AsyncInfoPtr->Queue = Queue; } + /// Get the queue, using the provided resource manager to initialise it if it + /// doesn't exist. + template <typename Ty, typename RMTy> + Expected<Ty> + getOrInitQueue(GenericDeviceResourceManagerTy<RMTy> &ResourceManager) { + std::lock_guard<std::mutex> Lock(AsyncInfoPtr->Mutex); + if (!AsyncInfoPtr->Queue) { + if (auto Err = ResourceManager.getResource( + *reinterpret_cast<Ty *>(&AsyncInfoPtr->Queue))) + return Err; + } + return getQueueAs<Ty>(); + } + /// Synchronize with the __tgt_async_info's pending operations if it's the /// internal async info. The error associated to the asynchronous operations /// issued in this queue must be provided in \p Err. This function will update @@ -138,6 +153,7 @@ struct AsyncInfoWrapperTy { /// Register \p Ptr as an associated allocation that is freed after /// finalization. void freeAllocationAfterSynchronization(void *Ptr) { + std::lock_guard<std::mutex> AllocationGuard(AsyncInfoPtr->Mutex); AsyncInfoPtr->AssociatedAllocations.push_back(Ptr); } @@ -827,9 +843,12 @@ struct GenericDeviceTy : public DeviceAllocatorTy { Error setupRPCServer(GenericPluginTy &Plugin, DeviceImageTy &Image); /// Synchronize the current thread with the pending operations on the - /// __tgt_async_info structure. - Error synchronize(__tgt_async_info *AsyncInfo); - virtual Error synchronizeImpl(__tgt_async_info &AsyncInfo) = 0; + /// __tgt_async_info structure. If ReleaseQueue is false, then the + // underlying queue will not be released. In this case, additional + // work may be submitted to the queue whilst a synchronize is running. + Error synchronize(__tgt_async_info *AsyncInfo, bool ReleaseQueue = true); + virtual Error synchronizeImpl(__tgt_async_info &AsyncInfo, + bool ReleaseQueue) = 0; /// Invokes any global constructors on the device if present and is required /// by the target. |