-
Notifications
You must be signed in to change notification settings - Fork 801
[SYCL] Get rid of device kernel info duplication #20319
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
Changes from all commits
3f0ce59
1343d13
65e213b
3157885
68df2eb
f1b796c
41a8a01
0e1e67e
40d1ee6
3d952d5
a1c62d5
a7a31e8
b9f0548
168d0a4
1a663ba
ac56e0a
8e4fe98
59f8a66
83260d5
00ee337
dbb4cc9
0dfc937
b6784db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -235,10 +235,11 @@ class kernel_impl { | |
| std::mutex *getCacheMutex() const { return MCacheMutex; } | ||
| std::string_view getName() const; | ||
|
|
||
| bool checkOwnsDeviceKernelInfo(); | ||
| DeviceKernelInfo &getDeviceKernelInfo() { | ||
| return MIsInterop | ||
| ? MInteropDeviceKernelInfo | ||
| : ProgramManager::getInstance().getOrCreateDeviceKernelInfo( | ||
| return MOwnsDeviceKernelInfo | ||
| ? MDeviceKernelInfo | ||
| : ProgramManager::getInstance().getDeviceKernelInfo( | ||
|
Comment on lines
+240
to
+242
Contributor
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 we just have a reference/pointer as the member (potentially pointing to the owning smart pointer member) instead of doing those lookups?
Contributor
Author
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. Yes, we should. I was planning that as a follow-up change since the lookup is already there right now. |
||
| std::string_view(getName())); | ||
| } | ||
|
|
||
|
|
@@ -255,9 +256,11 @@ class kernel_impl { | |
| std::mutex *MCacheMutex = nullptr; | ||
| mutable std::string MName; | ||
|
|
||
| // It is used for the interop kernels only. | ||
| // Used for images that aren't obtained with standard SYCL offline | ||
| // compilation. | ||
| // For regular kernel we get DeviceKernelInfo from the ProgramManager. | ||
| DeviceKernelInfo MInteropDeviceKernelInfo; | ||
| bool MOwnsDeviceKernelInfo = false; | ||
| DeviceKernelInfo MDeviceKernelInfo; | ||
|
|
||
| bool isBuiltInKernel(device_impl &Device) const; | ||
| void checkIfValidForNumArgsInfoQuery() const; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1510,27 +1510,34 @@ void ProgramManager::cacheKernelImplicitLocalArg( | |
| Img.getImplicitLocalArg(); | ||
| if (ImplicitLocalArgRange.isAvailable()) | ||
| for (auto Prop : ImplicitLocalArgRange) { | ||
| m_KernelImplicitLocalArgPos[Prop->Name] = | ||
| DeviceBinaryProperty(Prop).asUint32(); | ||
| auto It = m_DeviceKernelInfoMap.find(Prop->Name); | ||
| assert(It != m_DeviceKernelInfoMap.end()); | ||
| It->second.setImplicitLocalArgPos(DeviceBinaryProperty(Prop).asUint32()); | ||
| } | ||
| } | ||
|
|
||
| DeviceKernelInfo &ProgramManager::getOrCreateDeviceKernelInfo( | ||
| const CompileTimeKernelInfoTy &Info) { | ||
| DeviceKernelInfo & | ||
| ProgramManager::getDeviceKernelInfo(const CompileTimeKernelInfoTy &Info) { | ||
| std::lock_guard<std::mutex> Guard(m_DeviceKernelInfoMapMutex); | ||
| auto [Iter, Inserted] = m_DeviceKernelInfoMap.try_emplace(Info.Name, Info); | ||
| if (!Inserted) | ||
| Iter->second.setCompileTimeInfoIfNeeded(Info); | ||
| return Iter->second; | ||
| auto It = m_DeviceKernelInfoMap.find(Info.Name); | ||
| assert(It != m_DeviceKernelInfoMap.end()); | ||
| It->second.setCompileTimeInfoIfNeeded(Info); | ||
| return It->second; | ||
| } | ||
|
|
||
| DeviceKernelInfo & | ||
| ProgramManager::getOrCreateDeviceKernelInfo(std::string_view KernelName) { | ||
| ProgramManager::getDeviceKernelInfo(std::string_view KernelName) { | ||
| std::lock_guard<std::mutex> Guard(m_DeviceKernelInfoMapMutex); | ||
| CompileTimeKernelInfoTy DefaultCompileTimeInfo{KernelName}; | ||
| auto Result = | ||
| m_DeviceKernelInfoMap.try_emplace(KernelName, DefaultCompileTimeInfo); | ||
| return Result.first->second; | ||
| auto It = m_DeviceKernelInfoMap.find(KernelName); | ||
| assert(It != m_DeviceKernelInfoMap.end()); | ||
| return It->second; | ||
| } | ||
|
|
||
| DeviceKernelInfo * | ||
| ProgramManager::tryGetDeviceKernelInfo(std::string_view KernelName) { | ||
| std::lock_guard<std::mutex> Guard(m_DeviceKernelInfoMapMutex); | ||
| auto It = m_DeviceKernelInfoMap.find(KernelName); | ||
| return It != m_DeviceKernelInfoMap.end() ? &It->second : nullptr; | ||
| } | ||
|
|
||
| static bool isBfloat16DeviceLibImage(sycl_device_binary RawImg, | ||
|
|
@@ -1733,6 +1740,10 @@ void ProgramManager::addImage(sycl_device_binary RawImg, | |
| m_KernelIDs2BinImage.insert(std::make_pair(It->second, Img.get())); | ||
| KernelIDs->push_back(It->second); | ||
|
|
||
| CompileTimeKernelInfoTy DefaultCompileTimeInfo{std::string_view(name)}; | ||
| m_DeviceKernelInfoMap.try_emplace(std::string_view(name), | ||
| DefaultCompileTimeInfo); | ||
|
Comment on lines
+1743
to
+1745
Contributor
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. IIUC,
Contributor
Author
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.
Now, there is a more general issue here if we, say, add images A and B coming from different libraries and containing the same kernel name, and then drop just the image we took the |
||
|
|
||
| // Keep track of image to kernel name reference count for cleanup. | ||
| m_KernelNameRefCount[name]++; | ||
| } | ||
|
|
@@ -1924,7 +1935,6 @@ void ProgramManager::removeImages(sycl_device_binaries DeviceBinary) { | |
| if (--RefCount == 0) { | ||
| // TODO aggregate all these maps into a single one since their entries | ||
| // share lifetime. | ||
| m_KernelImplicitLocalArgPos.erase(Name); | ||
| m_DeviceKernelInfoMap.erase(Name); | ||
| m_KernelNameRefCount.erase(RefCountIt); | ||
| if (Name2IDIt != m_KernelName2KernelIDs.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.
Sorry, could you please elaborate on how can we have a mixed origin image?
Uh oh!
There was an error while loading. Please reload this page.
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.
For example, if 2 images with different origins are explicitly linked, or an image has a dependency on a devicelib image.