Skip to content

Commit 613b865

Browse files
[SYCL] Propagate data from handler to DeviceKernelInfo when using old binaries (#19993)
`DeviceKernelInfoPtr` wasn't/isn't used a single source of information neither before not after this PR, so things weren't "broken". However, we want to change that soon and for that we need all the necessary information from `handler`/`handler_impl` to be available in `DeviceKernelInfoPtr`. That change brings us closer to that state.
1 parent ce54584 commit 613b865

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

sycl/source/detail/device_kernel_info.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ void DeviceKernelInfo::init(KernelNameStrRefT KernelName) {
3232
}
3333

3434
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
35-
void DeviceKernelInfo::initIfNeeded(KernelNameStrRefT KernelName) {
36-
if (!MInitialized.load())
37-
init(KernelName);
35+
void DeviceKernelInfo::initIfEmpty(const CompileTimeKernelInfoTy &Info) {
36+
if (MInitialized.load())
37+
return;
38+
39+
CompileTimeKernelInfoTy::operator=(Info);
40+
Name = Info.Name.data();
41+
init(Name.data());
3842
}
3943
#endif
4044

sycl/source/detail/device_kernel_info.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ class DeviceKernelInfo : public CompileTimeKernelInfoTy {
102102

103103
void init(KernelNameStrRefT KernelName);
104104
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
105-
void initIfNeeded(KernelNameStrRefT KernelName);
105+
// Initialize default-created entry that has no data recorded:
106+
void initIfEmpty(const CompileTimeKernelInfoTy &Info);
106107
#endif
107108
void setCompileTimeInfoIfNeeded(const CompileTimeKernelInfoTy &Info);
108109

sycl/source/handler.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,14 @@ event handler::finalize() {
544544
if (type == detail::CGType::Kernel) {
545545
if (impl->MDeviceKernelInfoPtr) {
546546
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
547-
impl->MDeviceKernelInfoPtr->initIfNeeded(toKernelNameStrT(MKernelName));
547+
detail::CompileTimeKernelInfoTy HandlerInfo;
548+
HandlerInfo.Name = MKernelName;
549+
HandlerInfo.NumParams = impl->MKernelNumArgs;
550+
HandlerInfo.ParamDescGetter = impl->MKernelParamDescGetter;
551+
HandlerInfo.IsESIMD = impl->MKernelIsESIMD;
552+
HandlerInfo.HasSpecialCaptures = impl->MKernelHasSpecialCaptures;
553+
554+
impl->MDeviceKernelInfoPtr->initIfEmpty(HandlerInfo);
548555
#endif
549556
} else {
550557
// Fetch the device kernel info pointer if it hasn't been set (e.g.
@@ -553,6 +560,20 @@ event handler::finalize() {
553560
&detail::ProgramManager::getInstance().getOrCreateDeviceKernelInfo(
554561
toKernelNameStrT(MKernelName));
555562
}
563+
564+
detail::DeviceKernelInfo &Info = *impl->MDeviceKernelInfoPtr;
565+
(void)Info;
566+
567+
// Make sure that information set by old binaries gets properly copied to
568+
// the `DeviceKernelInfo` so that the rest of the code base could use it as
569+
// the single source of all the data:
570+
assert(MKernelName == static_cast<std::string_view>(Info.Name));
571+
assert(static_cast<unsigned>(impl->MKernelNumArgs) == Info.NumParams);
572+
assert(impl->MKernelParamDescGetter == Info.ParamDescGetter ||
573+
impl->MKernelParamDescGetter == nullptr);
574+
assert(impl->MKernelIsESIMD == Info.IsESIMD);
575+
assert(impl->MKernelHasSpecialCaptures == Info.HasSpecialCaptures);
576+
556577
// If there were uses of set_specialization_constant build the kernel_bundle
557578
detail::kernel_bundle_impl *KernelBundleImpPtr =
558579
getOrInsertHandlerKernelBundlePtr(/*Insert=*/false);

0 commit comments

Comments
 (0)