@@ -338,16 +338,23 @@ void context_impl::removeAssociatedDeviceGlobal(const void *DeviceGlobalPtr) {
338
338
void context_impl::addDeviceGlobalInitializer (
339
339
ur_program_handle_t Program, const std::vector<device> &Devs,
340
340
const RTDeviceBinaryImage *BinImage) {
341
+ if (BinImage->getDeviceGlobals ().empty ())
342
+ return ;
341
343
std::lock_guard<std::mutex> Lock (MDeviceGlobalInitializersMutex);
342
344
for (const device &Dev : Devs) {
343
345
auto Key = std::make_pair (Program, getSyclObjImpl (Dev)->getHandleRef ());
344
- MDeviceGlobalInitializers.emplace (Key, BinImage);
346
+ auto [Iter, Inserted] = MDeviceGlobalInitializers.emplace (Key, BinImage);
347
+ if (Inserted && !Iter->second .MDeviceGlobalsFullyInitialized )
348
+ ++MDeviceGlobalNotInitializedCnt;
345
349
}
346
350
}
347
351
348
352
std::vector<ur_event_handle_t > context_impl::initializeDeviceGlobals (
349
353
ur_program_handle_t NativePrg,
350
354
const std::shared_ptr<queue_impl> &QueueImpl) {
355
+ if (!MDeviceGlobalNotInitializedCnt.load (std::memory_order_acquire))
356
+ return {};
357
+
351
358
const AdapterPtr &Adapter = getAdapter ();
352
359
const DeviceImplPtr &DeviceImpl = QueueImpl->getDeviceImplPtr ();
353
360
std::lock_guard<std::mutex> NativeProgramLock (MDeviceGlobalInitializersMutex);
@@ -369,16 +376,17 @@ std::vector<ur_event_handle_t> context_impl::initializeDeviceGlobals(
369
376
[&Adapter](const ur_event_handle_t &Event) {
370
377
return get_event_info<info::event::command_execution_status>(
371
378
Event, Adapter) == info::event_command_status::complete;
372
- return false ;
373
379
});
374
380
// Release the removed events.
375
381
for (auto EventIt = NewEnd; EventIt != InitEventsRef.end (); ++EventIt)
376
382
Adapter->call <UrApiKind::urEventRelease>(*EventIt);
377
383
// Remove them from the collection.
378
384
InitEventsRef.erase (NewEnd, InitEventsRef.end ());
379
385
// If there are no more events, we can mark it as fully initialized.
380
- if (InitEventsRef.empty ())
386
+ if (InitEventsRef.empty ()) {
381
387
InitRef.MDeviceGlobalsFullyInitialized = true ;
388
+ --MDeviceGlobalNotInitializedCnt;
389
+ }
382
390
return InitEventsRef;
383
391
} else if (InitRef.MDeviceGlobalsFullyInitialized ) {
384
392
// MDeviceGlobalsFullyInitialized could have been set while we were
@@ -387,7 +395,7 @@ std::vector<ur_event_handle_t> context_impl::initializeDeviceGlobals(
387
395
}
388
396
389
397
// There were no events and it was not set as fully initialized, so this is
390
- // responsible for intializing the device globals.
398
+ // responsible for initializing the device globals.
391
399
auto DeviceGlobals = InitRef.MBinImage ->getDeviceGlobals ();
392
400
std::vector<std::string> DeviceGlobalIds;
393
401
DeviceGlobalIds.reserve (DeviceGlobals.size ());
@@ -402,6 +410,7 @@ std::vector<ur_event_handle_t> context_impl::initializeDeviceGlobals(
402
410
// globals are trivially fully initialized and we can end early.
403
411
if (DeviceGlobalEntries.empty ()) {
404
412
InitRef.MDeviceGlobalsFullyInitialized = true ;
413
+ --MDeviceGlobalNotInitializedCnt;
405
414
return {};
406
415
}
407
416
0 commit comments