@@ -60,6 +60,7 @@ struct GenericPluginTy;
6060struct GenericKernelTy ;
6161struct GenericDeviceTy ;
6262struct RecordReplayTy ;
63+ template <typename ResourceRef> class GenericDeviceResourceManagerTy ;
6364
6465namespace Plugin {
6566// / Create a success error. This is the same as calling Error::success(), but
@@ -127,6 +128,20 @@ struct AsyncInfoWrapperTy {
127128 AsyncInfoPtr->Queue = Queue;
128129 }
129130
131+ // / Get the queue, using the provided resource manager to initialise it if it
132+ // / doesn't exist.
133+ template <typename Ty, typename RMTy>
134+ Expected<Ty>
135+ getOrInitQueue (GenericDeviceResourceManagerTy<RMTy> &ResourceManager) {
136+ std::lock_guard<std::mutex> Lock (AsyncInfoPtr->Mutex );
137+ if (!AsyncInfoPtr->Queue ) {
138+ if (auto Err = ResourceManager.getResource (
139+ *reinterpret_cast <Ty *>(&AsyncInfoPtr->Queue )))
140+ return Err;
141+ }
142+ return getQueueAs<Ty>();
143+ }
144+
130145 // / Synchronize with the __tgt_async_info's pending operations if it's the
131146 // / internal async info. The error associated to the asynchronous operations
132147 // / issued in this queue must be provided in \p Err. This function will update
@@ -138,7 +153,7 @@ struct AsyncInfoWrapperTy {
138153 // / Register \p Ptr as an associated allocation that is freed after
139154 // / finalization.
140155 void freeAllocationAfterSynchronization (void *Ptr) {
141- std::lock_guard<std::mutex> AllocationGuard{AsyncInfoPtr->AllocationsMutex };
156+ std::lock_guard<std::mutex> AllocationGuard{AsyncInfoPtr->Mutex };
142157 AsyncInfoPtr->AssociatedAllocations .push_back (Ptr);
143158 }
144159
0 commit comments