DPC++ Runtime
Runtime libraries for oneAPI DPC++
kernel_impl.cpp
Go to the documentation of this file.
1 //==------- kernel_impl.cpp --- SYCL kernel implementation -----------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
11 #include <detail/kernel_impl.hpp>
12 #include <detail/program_impl.hpp>
13 
14 #include <memory>
15 
16 namespace sycl {
18 namespace detail {
19 
20 kernel_impl::kernel_impl(RT::PiKernel Kernel, ContextImplPtr Context,
21  KernelBundleImplPtr KernelBundleImpl)
22  : kernel_impl(Kernel, Context,
23  std::make_shared<program_impl>(Context, Kernel),
24  /*IsCreatedFromSource*/ true, KernelBundleImpl) {
25  // Enable USM indirect access for interoperability kernels.
26  // Some PI Plugins (like OpenCL) require this call to enable USM
27  // For others, PI will turn this into a NOP.
29  MKernel, PI_USM_INDIRECT_ACCESS, sizeof(pi_bool), &PI_TRUE);
30 
31  // This constructor is only called in the interoperability kernel constructor.
32  MIsInterop = true;
33 }
34 
36  ProgramImplPtr ProgramImpl, bool IsCreatedFromSource,
37  KernelBundleImplPtr KernelBundleImpl)
38  : MKernel(Kernel), MContext(ContextImpl),
39  MProgramImpl(std::move(ProgramImpl)),
40  MCreatedFromSource(IsCreatedFromSource),
41  MKernelBundleImpl(std::move(KernelBundleImpl)) {
42 
43  RT::PiContext Context = nullptr;
44  // Using the plugin from the passed ContextImpl
46  MKernel, PI_KERNEL_INFO_CONTEXT, sizeof(Context), &Context, nullptr);
47  if (ContextImpl->getHandleRef() != Context)
48  throw sycl::invalid_parameter_error(
49  "Input context must be the same as the context of cl_kernel",
50  PI_ERROR_INVALID_CONTEXT);
51 
52  MIsInterop = MProgramImpl->isInterop();
53 }
54 
56  DeviceImageImplPtr DeviceImageImpl,
57  KernelBundleImplPtr KernelBundleImpl)
58  : MKernel(Kernel), MContext(std::move(ContextImpl)), MProgramImpl(nullptr),
59  MCreatedFromSource(false), MDeviceImageImpl(std::move(DeviceImageImpl)),
60  MKernelBundleImpl(std::move(KernelBundleImpl)) {
61 
62  // kernel_impl shared ownership of kernel handle
63  if (!is_host()) {
65  }
66 
67  MIsInterop = MKernelBundleImpl->isInterop();
68 }
69 
71  : MContext(Context), MProgramImpl(std::move(ProgramImpl)) {}
72 
74  // TODO catch an exception and put it to list of asynchronous exceptions
75  if (!is_host()) {
77  }
78 }
79 
81  // TODO it is not clear how to understand whether the SYCL kernel is created
82  // from source code or not when the SYCL kernel is created using
83  // the interoperability constructor.
84  // Here a strange case which does not work now:
85  // context Context;
86  // program Program(Context);
87  // Program.build_with_kernel_type<class A>();
88  // kernel FirstKernel= Program.get_kernel<class A>();
89  // cl_kernel ClKernel = FirstKernel.get();
90  // kernel SecondKernel = kernel(ClKernel, Context);
91  // clReleaseKernel(ClKernel);
92  // FirstKernel.isCreatedFromSource() != FirstKernel.isCreatedFromSource();
93  return MCreatedFromSource;
94 }
95 
96 } // namespace detail
97 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
98 } // namespace sycl
kernel_impl(RT::PiKernel Kernel, ContextImplPtr Context, KernelBundleImplPtr KernelBundleImpl)
Constructs a SYCL kernel instance from a PiKernel.
Definition: kernel_impl.cpp:20
bool is_host() const
Check if the associated SYCL context is a SYCL host context.
const plugin & getPlugin() const
bool isCreatedFromSource() const
Check if kernel was created from a program that had been created from source.
Definition: kernel_impl.cpp:80
void call(ArgsT... Args) const
Calls the API, traces the call, checks the result.
Definition: plugin.hpp:217
#define __SYCL_INLINE_VER_NAMESPACE(X)
::pi_kernel PiKernel
Definition: pi.hpp:116
::pi_context PiContext
Definition: pi.hpp:114
std::shared_ptr< device_image_impl > DeviceImageImplPtr
std::shared_ptr< program_impl > ProgramImplPtr
Definition: kernel_impl.hpp:31
std::shared_ptr< sycl::detail::context_impl > ContextImplPtr
Definition: event_impl.hpp:30
std::shared_ptr< detail::kernel_bundle_impl > KernelBundleImplPtr
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
pi_result piKernelRelease(pi_kernel kernel)
pi_uint32 pi_bool
Definition: pi.h:109
const pi_bool PI_TRUE
Definition: pi.h:483
@ PI_USM_INDIRECT_ACCESS
indicates that the kernel might access data through USM ptrs
Definition: pi.h:1315
pi_result piKernelRetain(pi_kernel kernel)
pi_result piKernelSetExecInfo(pi_kernel kernel, pi_kernel_exec_info value_name, size_t param_value_size, const void *param_value)
API to set attributes controlling kernel execution.
@ PI_KERNEL_INFO_CONTEXT
Definition: pi.h:346
pi_result piKernelGetInfo(pi_kernel kernel, pi_kernel_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)