Skip to content

Commit ccbe355

Browse files
[SYCL] Implement DeviceKernelInfo for interop kernels (#20020)
For kernels represented by user-provided functors/lambdas the `DeviceKernelInfo` is stored in the `ProgramManager::m_DeviceKernelInfoMap`. This PR introduces support for the `DeviceKernelInfo` for interop kernels. --------- Co-authored-by: Andrei Elovikov <[email protected]>
1 parent 5b58b63 commit ccbe355

File tree

5 files changed

+34
-10
lines changed

5 files changed

+34
-10
lines changed

sycl/include/sycl/handler.hpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -501,14 +501,7 @@ class __SYCL_EXPORT handler {
501501
setType(detail::CGType::Kernel);
502502
}
503503

504-
void setDeviceKernelInfo(kernel &&Kernel) {
505-
MKernel = detail::getSyclObjImpl(std::move(Kernel));
506-
MKernelName = getKernelName();
507-
setType(detail::CGType::Kernel);
508-
509-
// If any extra actions are added here make sure that logic around
510-
// `lambdaAndKernelHaveEqualName` calls can handle that.
511-
}
504+
void setDeviceKernelInfo(kernel &&Kernel);
512505

513506
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
514507
// TODO: Those functions are not used anymore, remove it in the next

sycl/source/detail/kernel_impl.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ namespace sycl {
1616
inline namespace _V1 {
1717
namespace detail {
1818

19+
static CompileTimeKernelInfoTy
20+
createCompileTimeKernelInfo(std::string_view KernelName = {}) {
21+
return CompileTimeKernelInfoTy{KernelName};
22+
}
23+
1924
kernel_impl::kernel_impl(Managed<ur_kernel_handle_t> &&Kernel,
2025
context_impl &Context,
2126
kernel_bundle_impl *KernelBundleImpl,
@@ -26,7 +31,8 @@ kernel_impl::kernel_impl(Managed<ur_kernel_handle_t> &&Kernel,
2631
MCreatedFromSource(true),
2732
MKernelBundleImpl(KernelBundleImpl ? KernelBundleImpl->shared_from_this()
2833
: nullptr),
29-
MIsInterop(true), MKernelArgMaskPtr{ArgMask} {
34+
MIsInterop(true), MKernelArgMaskPtr{ArgMask},
35+
MInteropDeviceKernelInfo(createCompileTimeKernelInfo(getName())) {
3036
ur_context_handle_t UrContext = nullptr;
3137
// Using the adapter from the passed ContextImpl
3238
getAdapter().call<UrApiKind::urKernelGetInfo>(
@@ -52,7 +58,10 @@ kernel_impl::kernel_impl(Managed<ur_kernel_handle_t> &&Kernel,
5258
MDeviceImageImpl(std::move(DeviceImageImpl)),
5359
MKernelBundleImpl(KernelBundleImpl.shared_from_this()),
5460
MIsInterop(MDeviceImageImpl->getOriginMask() & ImageOriginInterop),
55-
MKernelArgMaskPtr{ArgMask}, MCacheMutex{CacheMutex} {
61+
MKernelArgMaskPtr{ArgMask}, MCacheMutex{CacheMutex},
62+
MInteropDeviceKernelInfo(MIsInterop
63+
? createCompileTimeKernelInfo(getName())
64+
: createCompileTimeKernelInfo()) {
5665
// Enable USM indirect access for interop and non-sycl-jit source kernels.
5766
// sycl-jit kernels will enable this if needed through the regular kernel
5867
// path.

sycl/source/detail/kernel_impl.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,13 @@ class kernel_impl {
238238
std::mutex *getCacheMutex() const { return MCacheMutex; }
239239
std::string_view getName() const;
240240

241+
DeviceKernelInfo &getDeviceKernelInfo() {
242+
return MIsInterop
243+
? MInteropDeviceKernelInfo
244+
: ProgramManager::getInstance().getOrCreateDeviceKernelInfo(
245+
KernelNameStrT(getName()));
246+
}
247+
241248
private:
242249
Managed<ur_kernel_handle_t> MKernel;
243250
const std::shared_ptr<context_impl> MContext;
@@ -251,6 +258,10 @@ class kernel_impl {
251258
std::mutex *MCacheMutex = nullptr;
252259
mutable std::string MName;
253260

261+
// It is used for the interop kernels only.
262+
// For regular kernel we get DeviceKernelInfo from the ProgramManager.
263+
DeviceKernelInfo MInteropDeviceKernelInfo;
264+
254265
bool isBuiltInKernel(device_impl &Device) const;
255266
void checkIfValidForNumArgsInfoQuery() const;
256267

sycl/source/handler.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,6 +2535,16 @@ bool handler::HasAssociatedAccessor(detail::AccessorImplHost *Req,
25352535
void handler::setType(sycl::detail::CGType Type) { impl->MCGType = Type; }
25362536
sycl::detail::CGType handler::getType() const { return impl->MCGType; }
25372537

2538+
void handler::setDeviceKernelInfo(kernel &&Kernel) {
2539+
MKernel = detail::getSyclObjImpl(std::move(Kernel));
2540+
MKernelName = getKernelName();
2541+
setDeviceKernelInfoPtr(&MKernel->getDeviceKernelInfo());
2542+
setType(detail::CGType::Kernel);
2543+
2544+
// If any extra actions are added here make sure that logic around
2545+
// `lambdaAndKernelHaveEqualName` calls can handle that.
2546+
}
2547+
25382548
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
25392549
void handler::setNDRangeDescriptorPadded(sycl::range<3> N,
25402550
bool SetNumWorkGroups, int Dims) {

sycl/test/abi/sycl_symbols_linux.dump

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3592,6 +3592,7 @@ _ZN4sycl3_V17handler21setKernelWorkGroupMemEm
35923592
_ZN4sycl3_V17handler21setUserFacingNodeTypeENS0_3ext6oneapi12experimental9node_typeE
35933593
_ZN4sycl3_V17handler22ext_oneapi_fill2d_implEPvmPKvmmm
35943594
_ZN4sycl3_V17handler22memcpyFromDeviceGlobalEPvPKvbmm
3595+
_ZN4sycl3_V17handler19setDeviceKernelInfoEONS0_6kernelE
35953596
_ZN4sycl3_V17handler22setDeviceKernelInfoPtrEPNS0_6detail16DeviceKernelInfoE
35963597
_ZN4sycl3_V17handler22setHandlerKernelBundleENS0_6kernelE
35973598
_ZN4sycl3_V17handler22setHandlerKernelBundleERKSt10shared_ptrINS0_6detail18kernel_bundle_implEE

0 commit comments

Comments
 (0)