File tree Expand file tree Collapse file tree 3 files changed +32
-0
lines changed
Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -262,6 +262,31 @@ void context_impl::addDeviceGlobalInitializer(
262262 }
263263}
264264
265+ void context_impl::removeDeviceGlobalInitializer (
266+ ur_program_handle_t Program, const RTDeviceBinaryImage *BinImage) {
267+ std::lock_guard<std::mutex> Lock (MDeviceGlobalInitializersMutex);
268+
269+ for (auto It = MDeviceGlobalInitializers.begin ();
270+ It != MDeviceGlobalInitializers.end ();) {
271+ const bool ProgramMatches = It->first .first == Program;
272+ const bool ImageMatches = !BinImage || It->second .MBinImage == BinImage;
273+
274+ if (!ProgramMatches || !ImageMatches) {
275+ ++It;
276+ continue ;
277+ }
278+
279+ {
280+ std::lock_guard<std::mutex> InitLock (It->second .MDeviceGlobalInitMutex );
281+ if (!It->second .MDeviceGlobalsFullyInitialized )
282+ --MDeviceGlobalNotInitializedCnt;
283+ It->second .ClearEvents (getAdapter ());
284+ }
285+
286+ It = MDeviceGlobalInitializers.erase (It);
287+ }
288+ }
289+
265290std::vector<ur_event_handle_t > context_impl::initializeDeviceGlobals (
266291 ur_program_handle_t NativePrg, queue_impl &QueueImpl,
267292 detail::kernel_bundle_impl *KernelBundleImplPtr) {
Original file line number Diff line number Diff line change @@ -194,6 +194,12 @@ class context_impl : public std::enable_shared_from_this<context_impl> {
194194 devices_range Devs,
195195 const RTDeviceBinaryImage *BinImage);
196196
197+ // / Removes device global initializers for a program. If BinImage is not
198+ // / null, only initializers associated with that image are removed.
199+ void
200+ removeDeviceGlobalInitializer (ur_program_handle_t Program,
201+ const RTDeviceBinaryImage *BinImage = nullptr );
202+
197203 // / Initializes device globals for a program on the associated queue.
198204 std::vector<ur_event_handle_t >
199205 initializeDeviceGlobals (ur_program_handle_t NativePrg, queue_impl &QueueImpl,
Original file line number Diff line number Diff line change @@ -1846,6 +1846,7 @@ void ProgramManager::removeImages(sycl_device_binaries DeviceBinary) {
18461846 auto CurIt = It++;
18471847 if (CurIt->second .second == Img) {
18481848 if (auto ContextImpl = CurIt->second .first .lock ()) {
1849+ ContextImpl->removeDeviceGlobalInitializer (CurIt->first , Img);
18491850 ContextImpl->getKernelProgramCache ().removeAllRelatedEntries (
18501851 Img->getImageID ());
18511852 }
You can’t perform that action at this time.
0 commit comments