-
Notifications
You must be signed in to change notification settings - Fork 798
[SYCL] Delete symbol based info with the last image referencing it #19659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+181
−91
Merged
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
9b74c13
[SYCL] Delete kernel name based info with the last image referencing it
sergey-semenov 91cbc30
Merge branch 'sycl' into kernelnamecleanup
sergey-semenov 0c50f13
Improve m_KernelIDs2BinImage cleanup
sergey-semenov 338b1a4
Fix cleanup of exported symbol images map
sergey-semenov 2c2a073
Check presence in ID->Img map instead of asserting it
sergey-semenov 151b5ca
Fix the if vs assert part
sergey-semenov 623d661
Merge branch 'sycl' into kernelnamecleanup
sergey-semenov dcb4788
Debug kernel_lin.cpp test
sergey-semenov 23166af
Revert "Debug kernel_lin.cpp test"
sergey-semenov 372a271
Refcount cleanup
sergey-semenov bd43afc
Extend cleanup unit tests
sergey-semenov b1f9365
Add a unit test
sergey-semenov 286b1a7
Merge branch 'sycl' into kernelnamecleanup
sergey-semenov 92bd78b
Apply comments
sergey-semenov 2370609
const char * -> string_view
sergey-semenov d505ad3
Merge branch 'sycl' into kernelnamecleanup
sergey-semenov 3f80ebf
Merge branch 'sycl' into kernelnamecleanup
sergey-semenov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2042,6 +2042,9 @@ void ProgramManager::addImage(sycl_device_binary RawImg, | |
} | ||
m_KernelIDs2BinImage.insert(std::make_pair(It->second, Img.get())); | ||
KernelIDs->push_back(It->second); | ||
|
||
// Keep track of image to kernel name reference count for cleanup. | ||
m_KernelNameRefCount[name]++; | ||
} | ||
|
||
cacheKernelUsesAssertInfo(*Img); | ||
|
@@ -2115,6 +2118,18 @@ void ProgramManager::addImages(sycl_device_binaries DeviceBinary) { | |
addImage(&(DeviceBinary->DeviceBinaries[I])); | ||
} | ||
|
||
template <typename MultimapT, typename KeyT, typename ValT> | ||
void removeFromMultimapByVal(MultimapT &Map, const KeyT &Key, const ValT &Val, | ||
bool AssertContains = true) { | ||
auto [RangeBegin, RangeEnd] = Map.equal_range(Key); | ||
auto It = std::find_if(RangeBegin, RangeEnd, | ||
[&](const auto &Pair) { return Pair.second == Val; }); | ||
if (!AssertContains && It == RangeEnd) | ||
return; | ||
assert(It != RangeEnd); | ||
Map.erase(It); | ||
} | ||
|
||
void ProgramManager::removeImages(sycl_device_binaries DeviceBinary) { | ||
if (DeviceBinary->NumDeviceBinaries == 0) | ||
return; | ||
|
@@ -2140,44 +2155,67 @@ void ProgramManager::removeImages(sycl_device_binaries DeviceBinary) { | |
// Unmap the unique kernel IDs for the offload entries | ||
for (sycl_offload_entry EntriesIt = EntriesB; EntriesIt != EntriesE; | ||
EntriesIt = EntriesIt->Increment()) { | ||
|
||
const char *Name = EntriesIt->GetName(); | ||
// Drop entry for service kernel | ||
if (std::strstr(EntriesIt->GetName(), "__sycl_service_kernel__")) { | ||
m_ServiceKernels.erase(EntriesIt->GetName()); | ||
if (std::strstr(Name, "__sycl_service_kernel__")) { | ||
removeFromMultimapByVal(m_ServiceKernels, Name, Img); | ||
continue; | ||
} | ||
|
||
// Exported device functions won't have a kernel ID | ||
if (m_ExportedSymbolImages.find(EntriesIt->GetName()) != | ||
m_ExportedSymbolImages.end()) { | ||
if (m_ExportedSymbolImages.find(Name) != m_ExportedSymbolImages.end()) { | ||
continue; | ||
} | ||
|
||
// remove everything associated with this KernelName | ||
m_KernelUsesAssert.erase(EntriesIt->GetName()); | ||
m_KernelImplicitLocalArgPos.erase(EntriesIt->GetName()); | ||
|
||
if (auto It = m_KernelName2KernelIDs.find(EntriesIt->GetName()); | ||
It != m_KernelName2KernelIDs.end()) { | ||
m_KernelIDs2BinImage.erase(It->second); | ||
m_KernelName2KernelIDs.erase(It); | ||
auto Name2IDIt = m_KernelName2KernelIDs.find(Name); | ||
if (Name2IDIt != m_KernelName2KernelIDs.end()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When isn't that true? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing comes to mind, pretty sure this should be an assert. I'll make a follow up change for this. |
||
removeFromMultimapByVal(m_KernelIDs2BinImage, Name2IDIt->second, Img); | ||
|
||
auto RefCountIt = m_KernelNameRefCount.find(Name); | ||
assert(RefCountIt != m_KernelNameRefCount.end()); | ||
int &RefCount = RefCountIt->second; | ||
assert(RefCount > 0); | ||
|
||
// Remove everything associated with this KernelName if this is the last | ||
// image referencing it. | ||
if (--RefCount == 0) { | ||
// TODO aggregate all these maps into a single one since their entries | ||
// share lifetime. | ||
m_KernelUsesAssert.erase(Name); | ||
m_KernelImplicitLocalArgPos.erase(Name); | ||
m_KernelNameRefCount.erase(RefCountIt); | ||
if (Name2IDIt != m_KernelName2KernelIDs.end()) | ||
m_KernelName2KernelIDs.erase(Name2IDIt); | ||
} | ||
} | ||
|
||
// Drop reverse mapping | ||
m_BinImg2KernelIDs.erase(Img); | ||
|
||
// Unregister exported symbols (needs to happen after the ID unmap loop) | ||
// Unregister exported symbol -> Img pair (needs to happen after the ID | ||
// unmap loop) | ||
for (const sycl_device_binary_property &ESProp : | ||
Img->getExportedSymbols()) { | ||
m_ExportedSymbolImages.erase(ESProp->Name); | ||
removeFromMultimapByVal(m_ExportedSymbolImages, ESProp->Name, Img, | ||
/*AssertContains*/ false); | ||
} | ||
|
||
for (const sycl_device_binary_property &VFProp : | ||
Img->getVirtualFunctions()) { | ||
std::string StrValue = DeviceBinaryProperty(VFProp).asCString(); | ||
for (const auto &SetName : detail::split_string(StrValue, ',')) | ||
m_VFSet2BinImage.erase(SetName); | ||
// Unregister the image from all referenced virtual function sets. | ||
for (const auto &VFSetName : detail::split_string(StrValue, ',')) { | ||
auto It = m_VFSet2BinImage.find(VFSetName); | ||
assert(It != m_VFSet2BinImage.end()); | ||
sergey-semenov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
std::set<const RTDeviceBinaryImage *> &ImgSet = It->second; | ||
auto ImgIt = ImgSet.find(Img); | ||
assert(ImgIt != ImgSet.end()); | ||
ImgSet.erase(ImgIt); | ||
// If no images referencing this virtual function set remain, drop | ||
// it from the map. | ||
if (ImgSet.empty()) | ||
m_VFSet2BinImage.erase(It); | ||
} | ||
} | ||
|
||
m_DeviceGlobals.eraseEntries(Img); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.