16 #include <sycl/feature_test.hpp>
17 #if SYCL_BACKEND_OPENCL
20 #if SYCL_EXT_ONEAPI_BACKEND_CUDA
21 #ifdef SYCL_EXT_ONEAPI_BACKEND_CUDA_EXPERIMENTAL
27 #if SYCL_EXT_ONEAPI_BACKEND_HIP
30 #if SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
44 #include <type_traits>
66 template <backend Backend,
typename SyclType>
70 template <backend Backend,
typename SyclType>
75 template <backend Backend,
typename DataT,
int Dimensions,
typename AllocatorT>
83 ReturnValue = detail::pi::cast<ReturnType>(Handle[0]);
89 template <
typename DataT,
int Dimensions,
typename AllocatorT>
96 for (
auto &Obj : Handle) {
97 ReturnValue.push_back(
104 #if SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
112 if (BackendName == backend::ext_oneapi_level_zero)
113 throw sycl::runtime_error(
114 errc::feature_not_supported,
115 "Buffer interop is not supported by level zero yet",
116 PI_ERROR_INVALID_OPERATION);
117 return Obj.template getNative<BackendName>();
122 template <backend BackendName,
class SyclObjectT>
126 if (Obj.get_backend() != BackendName) {
127 throw sycl::runtime_error(errc::backend_mismatch,
"Backends mismatch",
128 PI_ERROR_INVALID_OPERATION);
134 template <backend BackendName, bundle_state State>
138 if (Obj.get_backend() != BackendName) {
139 throw sycl::runtime_error(errc::backend_mismatch,
"Backends mismatch",
140 PI_ERROR_INVALID_OPERATION);
142 return Obj.template getNative<BackendName>();
149 return detail::get_native_buffer<BackendName>(Obj);
152 #if SYCL_BACKEND_OPENCL
154 inline backend_return_t<backend::opencl, event>
155 get_native<backend::opencl, event>(
const event &Obj) {
157 if (Obj.get_backend() != backend::opencl) {
158 throw sycl::runtime_error(errc::backend_mismatch,
"Backends mismatch",
159 PI_ERROR_INVALID_OPERATION);
161 backend_return_t<backend::opencl, event> ReturnValue;
162 for (
auto const &element : Obj.getNativeVector()) {
163 ReturnValue.push_back(
165 typename detail::interop<backend::opencl, event>::value_type
>(
172 #if SYCL_EXT_ONEAPI_BACKEND_CUDA
174 inline backend_return_t<backend::ext_oneapi_cuda, device>
175 get_native<backend::ext_oneapi_cuda, device>(
const device &Obj) {
177 if (Obj.get_backend() != backend::ext_oneapi_cuda) {
178 throw sycl::runtime_error(errc::backend_mismatch,
"Backends mismatch",
179 PI_ERROR_INVALID_OPERATION);
183 return static_cast<backend_return_t<backend::ext_oneapi_cuda, device>
>(
194 typename detail::interop<
200 class kernel_bundle_impl;
210 const context &TargetContext,
211 const device *TargetDevice,
bool KeepOwnership,
214 const context &TargetContext,
backend Backend);
216 const context &TargetContext,
bool KeepOwnership,
220 const context &TargetContext,
backend Backend);
222 const context &TargetContext,
223 const kernel_bundle<bundle_state::executable> &KernelBundle,
226 __SYCL_EXPORT std::shared_ptr<detail::kernel_bundle_impl>
229 __SYCL_EXPORT std::shared_ptr<detail::kernel_bundle_impl>
234 template <backend Backend>
235 typename std::enable_if<
236 detail::InteropFeatureSupportMap<Backend>::MakePlatform ==
true,
242 detail::pi::cast<pi_native_handle>(BackendObject), Backend);
245 template <backend Backend>
246 typename std::enable_if<
247 detail::InteropFeatureSupportMap<Backend>::MakeDevice ==
true, device>::type
254 template <backend Backend>
255 typename std::enable_if<
256 detail::InteropFeatureSupportMap<Backend>::MakeContext ==
true,
266 template <backend Backend>
267 typename std::enable_if<
268 detail::InteropFeatureSupportMap<Backend>::MakeQueue ==
true, queue>::type
273 TargetContext,
nullptr,
false, Handler, Backend);
276 template <backend Backend>
277 typename std::enable_if<
278 detail::InteropFeatureSupportMap<Backend>::MakeEvent ==
true,
event>::type
281 const context &TargetContext) {
283 TargetContext, Backend);
286 template <backend Backend>
288 typename
std::enable_if<
289 detail::InteropFeatureSupportMap<Backend>::MakeEvent == true, event>::type
293 const
context &TargetContext,
bool KeepOwnership) {
295 TargetContext, KeepOwnership, Backend);
299 typename AllocatorT = buffer_allocator<std::remove_const_t<T>>>
300 typename std::enable_if<detail::InteropFeatureSupportMap<Backend>::MakeBuffer ==
302 Backend != backend::ext_oneapi_level_zero,
303 buffer<T, Dimensions, AllocatorT>>::type
306 const context &TargetContext,
event AvailableEvent = {}) {
307 return detail::make_buffer_helper<T, Dimensions, AllocatorT>(
308 detail::pi::cast<pi_native_handle>(BackendObject), TargetContext,
312 template <backend Backend>
316 const context &TargetContext) {
318 TargetContext, Backend);
321 template <backend Backend, bundle_state State>
322 typename std::enable_if<
323 detail::InteropFeatureSupportMap<Backend>::MakeKernelBundle ==
true,
324 kernel_bundle<State>>::type
327 const context &TargetContext) {
328 std::shared_ptr<detail::kernel_bundle_impl> KBImpl =
330 detail::pi::cast<pi_native_handle>(BackendObject), TargetContext,
331 false, State, Backend);
332 return detail::createSyclObjFromImpl<kernel_bundle<State>>(KBImpl);