Skip to content

Commit b40cb95

Browse files
committed
[SYCL] Pass kernel bundle to SYCL 2020 interop kernel
Interop kernels created using make_kernel does not have a reference to a kernel bundle, so calling get_kernel_bundle on these kernels will return an invalid kernel bundle. These changes pass the associated kernel bundle to the created interop kernel. This only applies to kernels created with make_kernel. Signed-off-by: Steffen Larsen <[email protected]>
1 parent 1d8ceba commit b40cb95

File tree

5 files changed

+22
-16
lines changed

5 files changed

+22
-16
lines changed

sycl/source/backend.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ kernel make_kernel(const context &TargetContext,
208208
backend Backend) {
209209
const auto &Plugin = getPlugin(Backend);
210210
const auto &ContextImpl = getSyclObjImpl(TargetContext);
211+
const auto KernelBundleImpl = getSyclObjImpl(KernelBundle);
211212

212213
// For Level-Zero expect exactly one device image in the bundle. This is
213214
// natural for interop kernel to get created out of a single native
@@ -218,7 +219,6 @@ kernel make_kernel(const context &TargetContext,
218219
//
219220
pi::PiProgram PiProgram = nullptr;
220221
if (Backend == backend::level_zero) {
221-
auto KernelBundleImpl = getSyclObjImpl(KernelBundle);
222222
if (KernelBundleImpl->size() != 1)
223223
throw sycl::runtime_error{
224224
"make_kernel: kernel_bundle must have single program image",
@@ -241,7 +241,7 @@ kernel make_kernel(const context &TargetContext,
241241

242242
// Construct the SYCL queue from PI queue.
243243
return detail::createSyclObjFromImpl<kernel>(
244-
std::make_shared<kernel_impl>(PiKernel, ContextImpl));
244+
std::make_shared<kernel_impl>(PiKernel, ContextImpl, KernelBundleImpl));
245245
}
246246

247247
kernel make_kernel(pi_native_handle NativeHandle, const context &TargetContext,

sycl/source/detail/kernel_impl.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ __SYCL_INLINE_NAMESPACE(cl) {
1717
namespace sycl {
1818
namespace detail {
1919

20-
kernel_impl::kernel_impl(RT::PiKernel Kernel, ContextImplPtr Context)
20+
kernel_impl::kernel_impl(RT::PiKernel Kernel, ContextImplPtr Context,
21+
KernelBundleImplPtr KernelBundleImpl)
2122
: kernel_impl(Kernel, Context,
2223
std::make_shared<program_impl>(Context, Kernel),
23-
/*IsCreatedFromSource*/ true) {
24+
/*IsCreatedFromSource*/ true,
25+
KernelBundleImpl) {
2426
// This constructor is only called in the interoperability kernel constructor.
2527
// Let the runtime caller handle native kernel retaining in other cases if
2628
// it's needed.
@@ -35,11 +37,12 @@ kernel_impl::kernel_impl(RT::PiKernel Kernel, ContextImplPtr Context)
3537
}
3638

3739
kernel_impl::kernel_impl(RT::PiKernel Kernel, ContextImplPtr ContextImpl,
38-
ProgramImplPtr ProgramImpl,
39-
bool IsCreatedFromSource)
40+
ProgramImplPtr ProgramImpl, bool IsCreatedFromSource,
41+
KernelBundleImplPtr KernelBundleImpl)
4042
: MKernel(Kernel), MContext(ContextImpl),
4143
MProgramImpl(std::move(ProgramImpl)),
42-
MCreatedFromSource(IsCreatedFromSource) {
44+
MCreatedFromSource(IsCreatedFromSource),
45+
MKernelBundleImpl(std::move(KernelBundleImpl)) {
4346

4447
RT::PiContext Context = nullptr;
4548
// Using the plugin from the passed ContextImpl
@@ -68,8 +71,7 @@ kernel_impl::kernel_impl(RT::PiKernel Kernel, ContextImplPtr ContextImpl,
6871
MIsInterop = MKernelBundleImpl->isInterop();
6972
}
7073

71-
kernel_impl::kernel_impl(ContextImplPtr Context,
72-
ProgramImplPtr ProgramImpl)
74+
kernel_impl::kernel_impl(ContextImplPtr Context, ProgramImplPtr ProgramImpl)
7375
: MContext(Context), MProgramImpl(std::move(ProgramImpl)) {}
7476

7577
kernel_impl::~kernel_impl() {

sycl/source/detail/kernel_impl.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ class kernel_impl {
4141
///
4242
/// \param Kernel is a valid PiKernel instance
4343
/// \param Context is a valid SYCL context
44-
kernel_impl(RT::PiKernel Kernel, ContextImplPtr Context);
44+
/// \param KernelBundleImpl is a valid instance of kernel_bundle_impl
45+
kernel_impl(RT::PiKernel Kernel, ContextImplPtr Context,
46+
KernelBundleImplPtr KernelBundleImpl);
4547

4648
/// Constructs a SYCL kernel instance from a SYCL program and a PiKernel
4749
///
@@ -55,15 +57,17 @@ class kernel_impl {
5557
/// \param ProgramImpl is a valid instance of program_impl
5658
/// \param IsCreatedFromSource is a flag that indicates whether program
5759
/// is created from source code
60+
/// \param KernelBundleImpl is a valid instance of kernel_bundle_impl
5861
kernel_impl(RT::PiKernel Kernel, ContextImplPtr ContextImpl,
59-
ProgramImplPtr ProgramImpl, bool IsCreatedFromSource);
62+
ProgramImplPtr ProgramImpl, bool IsCreatedFromSource,
63+
KernelBundleImplPtr KernelBundleImpl);
6064

6165
/// Constructs a SYCL kernel_impl instance from a SYCL device_image,
6266
/// kernel_bundle and / PiKernel.
6367
///
6468
/// \param Kernel is a valid PiKernel instance
6569
/// \param ContextImpl is a valid SYCL context
66-
/// \param ProgramImpl is a valid instance of kernel_bundle_impl
70+
/// \param KernelBundleImpl is a valid instance of kernel_bundle_impl
6771
kernel_impl(RT::PiKernel Kernel, ContextImplPtr ContextImpl,
6872
DeviceImageImplPtr DeviceImageImpl,
6973
KernelBundleImplPtr KernelBundleImpl);

sycl/source/detail/program_impl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,9 @@ kernel program_impl::get_kernel(std::string KernelName,
343343
return createSyclObjFromImpl<kernel>(
344344
std::make_shared<kernel_impl>(MContext, PtrToSelf));
345345
}
346-
return createSyclObjFromImpl<kernel>(std::make_shared<kernel_impl>(
347-
get_pi_kernel(KernelName), MContext, PtrToSelf,
348-
/*IsCreatedFromSource*/ IsCreatedFromSource));
346+
return createSyclObjFromImpl<kernel>(
347+
std::make_shared<kernel_impl>(get_pi_kernel(KernelName), MContext,
348+
PtrToSelf, IsCreatedFromSource, nullptr));
349349
}
350350

351351
std::vector<std::vector<char>> program_impl::get_binaries() const {

sycl/source/kernel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace sycl {
2020
kernel::kernel(cl_kernel ClKernel, const context &SyclContext)
2121
: impl(std::make_shared<detail::kernel_impl>(
2222
detail::pi::cast<detail::RT::PiKernel>(ClKernel),
23-
detail::getSyclObjImpl(SyclContext))) {}
23+
detail::getSyclObjImpl(SyclContext), nullptr)) {}
2424

2525
cl_kernel kernel::get() const { return impl->get(); }
2626

0 commit comments

Comments
 (0)