Skip to content

[SYCL] Pass kernel bundle to SYCL 2020 interop kernel #4877

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sycl/source/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ kernel make_kernel(const context &TargetContext,
backend Backend) {
const auto &Plugin = getPlugin(Backend);
const auto &ContextImpl = getSyclObjImpl(TargetContext);
const auto KernelBundleImpl = getSyclObjImpl(KernelBundle);

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

// Construct the SYCL queue from PI queue.
return detail::createSyclObjFromImpl<kernel>(
std::make_shared<kernel_impl>(PiKernel, ContextImpl));
std::make_shared<kernel_impl>(PiKernel, ContextImpl, KernelBundleImpl));
}

kernel make_kernel(pi_native_handle NativeHandle, const context &TargetContext,
Expand Down
15 changes: 8 additions & 7 deletions sycl/source/detail/kernel_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ __SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
namespace detail {

kernel_impl::kernel_impl(RT::PiKernel Kernel, ContextImplPtr Context)
kernel_impl::kernel_impl(RT::PiKernel Kernel, ContextImplPtr Context,
KernelBundleImplPtr KernelBundleImpl)
: kernel_impl(Kernel, Context,
std::make_shared<program_impl>(Context, Kernel),
/*IsCreatedFromSource*/ true) {
/*IsCreatedFromSource*/ true, KernelBundleImpl) {
// This constructor is only called in the interoperability kernel constructor.
// Let the runtime caller handle native kernel retaining in other cases if
// it's needed.
Expand All @@ -35,11 +36,12 @@ kernel_impl::kernel_impl(RT::PiKernel Kernel, ContextImplPtr Context)
}

kernel_impl::kernel_impl(RT::PiKernel Kernel, ContextImplPtr ContextImpl,
ProgramImplPtr ProgramImpl,
bool IsCreatedFromSource)
ProgramImplPtr ProgramImpl, bool IsCreatedFromSource,
KernelBundleImplPtr KernelBundleImpl)
: MKernel(Kernel), MContext(ContextImpl),
MProgramImpl(std::move(ProgramImpl)),
MCreatedFromSource(IsCreatedFromSource) {
MCreatedFromSource(IsCreatedFromSource),
MKernelBundleImpl(std::move(KernelBundleImpl)) {

RT::PiContext Context = nullptr;
// Using the plugin from the passed ContextImpl
Expand Down Expand Up @@ -68,8 +70,7 @@ kernel_impl::kernel_impl(RT::PiKernel Kernel, ContextImplPtr ContextImpl,
MIsInterop = MKernelBundleImpl->isInterop();
}

kernel_impl::kernel_impl(ContextImplPtr Context,
ProgramImplPtr ProgramImpl)
kernel_impl::kernel_impl(ContextImplPtr Context, ProgramImplPtr ProgramImpl)
: MContext(Context), MProgramImpl(std::move(ProgramImpl)) {}

kernel_impl::~kernel_impl() {
Expand Down
10 changes: 7 additions & 3 deletions sycl/source/detail/kernel_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ class kernel_impl {
///
/// \param Kernel is a valid PiKernel instance
/// \param Context is a valid SYCL context
kernel_impl(RT::PiKernel Kernel, ContextImplPtr Context);
/// \param KernelBundleImpl is a valid instance of kernel_bundle_impl
kernel_impl(RT::PiKernel Kernel, ContextImplPtr Context,
KernelBundleImplPtr KernelBundleImpl);

/// Constructs a SYCL kernel instance from a SYCL program and a PiKernel
///
Expand All @@ -55,15 +57,17 @@ class kernel_impl {
/// \param ProgramImpl is a valid instance of program_impl
/// \param IsCreatedFromSource is a flag that indicates whether program
/// is created from source code
/// \param KernelBundleImpl is a valid instance of kernel_bundle_impl
kernel_impl(RT::PiKernel Kernel, ContextImplPtr ContextImpl,
ProgramImplPtr ProgramImpl, bool IsCreatedFromSource);
ProgramImplPtr ProgramImpl, bool IsCreatedFromSource,
KernelBundleImplPtr KernelBundleImpl);

/// Constructs a SYCL kernel_impl instance from a SYCL device_image,
/// kernel_bundle and / PiKernel.
///
/// \param Kernel is a valid PiKernel instance
/// \param ContextImpl is a valid SYCL context
/// \param ProgramImpl is a valid instance of kernel_bundle_impl
/// \param KernelBundleImpl is a valid instance of kernel_bundle_impl
kernel_impl(RT::PiKernel Kernel, ContextImplPtr ContextImpl,
DeviceImageImplPtr DeviceImageImpl,
KernelBundleImplPtr KernelBundleImpl);
Expand Down
6 changes: 3 additions & 3 deletions sycl/source/detail/program_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ kernel program_impl::get_kernel(std::string KernelName,
return createSyclObjFromImpl<kernel>(
std::make_shared<kernel_impl>(MContext, PtrToSelf));
}
return createSyclObjFromImpl<kernel>(std::make_shared<kernel_impl>(
get_pi_kernel(KernelName), MContext, PtrToSelf,
/*IsCreatedFromSource*/ IsCreatedFromSource));
return createSyclObjFromImpl<kernel>(
std::make_shared<kernel_impl>(get_pi_kernel(KernelName), MContext,
PtrToSelf, IsCreatedFromSource, nullptr));
}

std::vector<std::vector<char>> program_impl::get_binaries() const {
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace sycl {
kernel::kernel(cl_kernel ClKernel, const context &SyclContext)
: impl(std::make_shared<detail::kernel_impl>(
detail::pi::cast<detail::RT::PiKernel>(ClKernel),
detail::getSyclObjImpl(SyclContext))) {}
detail::getSyclObjImpl(SyclContext), nullptr)) {}

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

Expand Down