@@ -2115,42 +2115,7 @@ void ProgramManager::addImage(sycl_device_binary RawImg,
2115
2115
KernelIDs->end ());
2116
2116
2117
2117
// ... and initialize associated device_global information
2118
- {
2119
- std::lock_guard<std::mutex> DeviceGlobalsGuard (m_DeviceGlobalsMutex);
2120
-
2121
- auto DeviceGlobals = Img->getDeviceGlobals ();
2122
- for (const sycl_device_binary_property &DeviceGlobal : DeviceGlobals) {
2123
- ByteArray DeviceGlobalInfo =
2124
- DeviceBinaryProperty (DeviceGlobal).asByteArray ();
2125
-
2126
- // The supplied device_global info property is expected to contain:
2127
- // * 8 bytes - Size of the property.
2128
- // * 4 bytes - Size of the underlying type in the device_global.
2129
- // * 4 bytes - 0 if device_global has device_image_scope and any value
2130
- // otherwise.
2131
- DeviceGlobalInfo.dropBytes (8 );
2132
- auto [TypeSize, DeviceImageScopeDecorated] =
2133
- DeviceGlobalInfo.consume <std::uint32_t , std::uint32_t >();
2134
- assert (DeviceGlobalInfo.empty () && " Extra data left!" );
2135
-
2136
- // Give the image pointer as an identifier for the image the
2137
- // device-global is associated with.
2138
-
2139
- auto ExistingDeviceGlobal = m_DeviceGlobals.find (DeviceGlobal->Name );
2140
- if (ExistingDeviceGlobal != m_DeviceGlobals.end ()) {
2141
- // If it has already been registered we update the information.
2142
- ExistingDeviceGlobal->second ->initialize (Img.get (), TypeSize,
2143
- DeviceImageScopeDecorated);
2144
- } else {
2145
- // If it has not already been registered we create a new entry.
2146
- // Note: Pointer to the device global is not available here, so it
2147
- // cannot be set until registration happens.
2148
- auto EntryUPtr = std::make_unique<DeviceGlobalMapEntry>(
2149
- DeviceGlobal->Name , Img.get (), TypeSize, DeviceImageScopeDecorated);
2150
- m_DeviceGlobals.emplace (DeviceGlobal->Name , std::move (EntryUPtr));
2151
- }
2152
- }
2153
- }
2118
+ m_DeviceGlobals.initializeEntries (Img.get ());
2154
2119
// ... and initialize associated host_pipe information
2155
2120
{
2156
2121
std::lock_guard<std::mutex> HostPipesGuard (m_HostPipesMutex);
@@ -2257,24 +2222,7 @@ void ProgramManager::removeImages(sycl_device_binaries DeviceBinary) {
2257
2222
m_VFSet2BinImage.erase (SetName);
2258
2223
}
2259
2224
2260
- {
2261
- std::lock_guard<std::mutex> DeviceGlobalsGuard (m_DeviceGlobalsMutex);
2262
- auto DeviceGlobals = Img->getDeviceGlobals ();
2263
- for (const sycl_device_binary_property &DeviceGlobal : DeviceGlobals) {
2264
- if (auto DevGlobalIt = m_DeviceGlobals.find (DeviceGlobal->Name );
2265
- DevGlobalIt != m_DeviceGlobals.end ()) {
2266
- auto findDevGlobalByValue = std::find_if (
2267
- m_Ptr2DeviceGlobal.begin (), m_Ptr2DeviceGlobal.end (),
2268
- [&DevGlobalIt](const std::pair<const void *,
2269
- DeviceGlobalMapEntry *> &Entry) {
2270
- return Entry.second == DevGlobalIt->second .get ();
2271
- });
2272
- if (findDevGlobalByValue != m_Ptr2DeviceGlobal.end ())
2273
- m_Ptr2DeviceGlobal.erase (findDevGlobalByValue);
2274
- m_DeviceGlobals.erase (DevGlobalIt);
2275
- }
2276
- }
2277
- }
2225
+ m_DeviceGlobals.eraseEntries (Img);
2278
2226
2279
2227
{
2280
2228
std::lock_guard<std::mutex> HostPipesGuard (m_HostPipesMutex);
@@ -2468,21 +2416,7 @@ kernel_id ProgramManager::getBuiltInKernelID(KernelNameStrRefT KernelName) {
2468
2416
2469
2417
void ProgramManager::addOrInitDeviceGlobalEntry (const void *DeviceGlobalPtr,
2470
2418
const char *UniqueId) {
2471
- std::lock_guard<std::mutex> DeviceGlobalsGuard (m_DeviceGlobalsMutex);
2472
-
2473
- auto ExistingDeviceGlobal = m_DeviceGlobals.find (UniqueId);
2474
- if (ExistingDeviceGlobal != m_DeviceGlobals.end ()) {
2475
- // Update the existing information and add the entry to the pointer map.
2476
- ExistingDeviceGlobal->second ->initialize (DeviceGlobalPtr);
2477
- m_Ptr2DeviceGlobal.insert (
2478
- {DeviceGlobalPtr, ExistingDeviceGlobal->second .get ()});
2479
- return ;
2480
- }
2481
-
2482
- auto EntryUPtr =
2483
- std::make_unique<DeviceGlobalMapEntry>(UniqueId, DeviceGlobalPtr);
2484
- auto NewEntry = m_DeviceGlobals.emplace (UniqueId, std::move (EntryUPtr));
2485
- m_Ptr2DeviceGlobal.insert ({DeviceGlobalPtr, NewEntry.first ->second .get ()});
2419
+ m_DeviceGlobals.addOrInitialize (DeviceGlobalPtr, UniqueId);
2486
2420
}
2487
2421
2488
2422
std::set<RTDeviceBinaryImage *>
@@ -2499,42 +2433,21 @@ ProgramManager::getRawDeviceImages(const std::vector<kernel_id> &KernelIDs) {
2499
2433
2500
2434
DeviceGlobalMapEntry *
2501
2435
ProgramManager::getDeviceGlobalEntry (const void *DeviceGlobalPtr) {
2502
- std::lock_guard<std::mutex> DeviceGlobalsGuard (m_DeviceGlobalsMutex);
2503
- auto Entry = m_Ptr2DeviceGlobal.find (DeviceGlobalPtr);
2504
- assert (Entry != m_Ptr2DeviceGlobal.end () && " Device global entry not found" );
2505
- return Entry->second ;
2436
+ return m_DeviceGlobals.getEntry (DeviceGlobalPtr);
2506
2437
}
2507
2438
2508
2439
DeviceGlobalMapEntry *
2509
2440
ProgramManager::tryGetDeviceGlobalEntry (const std::string &UniqueId,
2510
2441
bool ExcludeDeviceImageScopeDecorated) {
2511
- std::lock_guard<std::mutex> DeviceGlobalsGuard (m_DeviceGlobalsMutex);
2512
- auto DeviceGlobalEntry = m_DeviceGlobals.find (UniqueId);
2513
- assert (DeviceGlobalEntry != m_DeviceGlobals.end () &&
2514
- " Device global not found in map." );
2515
- if (DeviceGlobalEntry != m_DeviceGlobals.end () &&
2516
- (!ExcludeDeviceImageScopeDecorated ||
2517
- !DeviceGlobalEntry->second ->MIsDeviceImageScopeDecorated ))
2518
- return DeviceGlobalEntry->second .get ();
2519
- return nullptr ;
2442
+ return m_DeviceGlobals.tryGetEntry (UniqueId,
2443
+ ExcludeDeviceImageScopeDecorated);
2520
2444
}
2521
2445
2522
2446
std::vector<DeviceGlobalMapEntry *> ProgramManager::getDeviceGlobalEntries (
2523
2447
const std::vector<std::string> &UniqueIds,
2524
2448
bool ExcludeDeviceImageScopeDecorated) {
2525
- std::vector<DeviceGlobalMapEntry *> FoundEntries;
2526
- FoundEntries.reserve (UniqueIds.size ());
2527
-
2528
- std::lock_guard<std::mutex> DeviceGlobalsGuard (m_DeviceGlobalsMutex);
2529
- for (const std::string &UniqueId : UniqueIds) {
2530
- auto DeviceGlobalEntry = m_DeviceGlobals.find (UniqueId);
2531
- assert (DeviceGlobalEntry != m_DeviceGlobals.end () &&
2532
- " Device global not found in map." );
2533
- if (!ExcludeDeviceImageScopeDecorated ||
2534
- !DeviceGlobalEntry->second ->MIsDeviceImageScopeDecorated )
2535
- FoundEntries.push_back (DeviceGlobalEntry->second .get ());
2536
- }
2537
- return FoundEntries;
2449
+ return m_DeviceGlobals.getEntries (UniqueIds,
2450
+ ExcludeDeviceImageScopeDecorated);
2538
2451
}
2539
2452
2540
2453
void ProgramManager::addOrInitHostPipeEntry (const void *HostPipePtr,
0 commit comments