-
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
base: sycl
Are you sure you want to change the base?
Conversation
Prior to this patch, kernel name based info (e.g. kernel id or assert usage) was deleted whenever an image referencing it was removed. This is technically incorrect since multiple images can contain the same kernel name.
This reverts commit dcb4788.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I would change the name to removeFromMultimapByVal.
m_VFSet2BinImage.erase(SetName); | ||
for (const auto &SetName : detail::split_string(StrValue, ',')) { | ||
auto It = m_VFSet2BinImage.find(SetName); | ||
assert(It != m_VFSet2BinImage.end()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to create a tiny separate method for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about outlining, but some inline comment would help...
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be std::string_view
instead?
// 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ugly enough to justify an extended comment. I'm not familiar with the code but it's very unexpected to have several branches for if (RefCount == 0)
, it looks like some ownership is spread between several places which is never good. Can you explain what is going on here?
Prior to this patch, symbol based info (e.g. kernel id, kernel assert usage or images containing an exported symbol) was deleted whenever an image referencing it was removed. This is incorrect since multiple images can contain the same symbol.
While unlikely to cause any problems now (since those images usually all get removed with one call to
removeImages
after another), this will cause issues once kernel name based kernel caches start getting cleaned up in the same manner.