@@ -2115,42 +2115,7 @@ void ProgramManager::addImage(sycl_device_binary RawImg,
21152115 KernelIDs->end ());
21162116
21172117 // ... 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 ());
21542119 // ... and initialize associated host_pipe information
21552120 {
21562121 std::lock_guard<std::mutex> HostPipesGuard (m_HostPipesMutex);
@@ -2257,24 +2222,7 @@ void ProgramManager::removeImages(sycl_device_binaries DeviceBinary) {
22572222 m_VFSet2BinImage.erase (SetName);
22582223 }
22592224
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);
22782226
22792227 {
22802228 std::lock_guard<std::mutex> HostPipesGuard (m_HostPipesMutex);
@@ -2468,21 +2416,7 @@ kernel_id ProgramManager::getBuiltInKernelID(KernelNameStrRefT KernelName) {
24682416
24692417void ProgramManager::addOrInitDeviceGlobalEntry (const void *DeviceGlobalPtr,
24702418 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);
24862420}
24872421
24882422std::set<RTDeviceBinaryImage *>
@@ -2499,42 +2433,21 @@ ProgramManager::getRawDeviceImages(const std::vector<kernel_id> &KernelIDs) {
24992433
25002434DeviceGlobalMapEntry *
25012435ProgramManager::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);
25062437}
25072438
25082439DeviceGlobalMapEntry *
25092440ProgramManager::tryGetDeviceGlobalEntry (const std::string &UniqueId,
25102441 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);
25202444}
25212445
25222446std::vector<DeviceGlobalMapEntry *> ProgramManager::getDeviceGlobalEntries (
25232447 const std::vector<std::string> &UniqueIds,
25242448 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);
25382451}
25392452
25402453void ProgramManager::addOrInitHostPipeEntry (const void *HostPipePtr,
0 commit comments