-
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
Open
sergey-semenov
wants to merge
14
commits into
intel:sycl
Choose a base branch
from
sergey-semenov:kernelnamecleanup
base: sycl
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+181
−92
Open
Changes from 13 commits
Commits
Show all changes
14 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 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 removeFromMultimap(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(); | ||
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. Can it be |
||
// 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__")) { | ||
removeFromMultimap(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()); | ||
// Remove everything associated with this KernelName if this is the last | ||
// image referencing it, otherwise remove just the ID -> Img mapping. | ||
auto RefCountIt = m_KernelNameRefCount.find(Name); | ||
assert(RefCountIt != m_KernelNameRefCount.end()); | ||
int &RefCount = RefCountIt->second; | ||
assert(RefCount > 0); | ||
--RefCount; | ||
|
||
if (auto It = m_KernelName2KernelIDs.find(EntriesIt->GetName()); | ||
if (auto It = m_KernelName2KernelIDs.find(Name); | ||
It != m_KernelName2KernelIDs.end()) { | ||
m_KernelIDs2BinImage.erase(It->second); | ||
m_KernelName2KernelIDs.erase(It); | ||
if (RefCount == 0) { | ||
m_KernelIDs2BinImage.erase(It->second); | ||
m_KernelName2KernelIDs.erase(It); | ||
} else { | ||
removeFromMultimap(m_KernelIDs2BinImage, It->second, Img); | ||
} | ||
} | ||
|
||
if (RefCount == 0) { | ||
m_KernelUsesAssert.erase(Name); | ||
m_KernelImplicitLocalArgPos.erase(Name); | ||
m_KernelNameRefCount.erase(RefCountIt); | ||
sergey-semenov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
// 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); | ||
removeFromMultimap(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); | ||
for (const auto &SetName : detail::split_string(StrValue, ',')) { | ||
auto It = m_VFSet2BinImage.find(SetName); | ||
assert(It != m_VFSet2BinImage.end()); | ||
sergey-semenov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
auto &ImgSet = It->second; | ||
auto ImgIt = ImgSet.find(Img); | ||
assert(ImgIt != ImgSet.end()); | ||
ImgSet.erase(ImgIt); | ||
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
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.