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 #ifdef SYCL2020_CONFORMANT_APIS
90 template <
typename DataT,
int Dimensions,
typename AllocatorT>
95 static ReturnType GetNativeObjs(
const std::vector<pi_native_handle> &Handle) {
96 ReturnType ReturnValue{};
97 for (
auto &Obj : Handle) {
98 ReturnValue.push_back(
113 if (BackendName == backend::ext_oneapi_level_zero)
114 throw sycl::runtime_error(
115 errc::feature_not_supported,
116 "Buffer interop is not supported by level zero yet",
117 PI_ERROR_INVALID_OPERATION);
118 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);
130 return Obj.template get_native<BackendName>();
135 std::enable_if_t<BackendName == backend::opencl> * =
nullptr>
136 #ifndef SYCL2020_CONFORMANT_APIS
138 "get_native<backend::opencl, buffer>, which return type "
139 "cl_mem is deprecated. According to SYCL 2020 spec, please define "
140 "SYCL2020_CONFORMANT_APIS and use vector<cl_mem> instead.")
144 return detail::get_native_buffer<BackendName>(Obj);
149 std::enable_if_t<BackendName != backend::opencl> * =
nullptr>
152 return detail::get_native_buffer<BackendName>(Obj);
157 #ifdef SYCL2020_CONFORMANT_APIS
159 inline backend_return_t<backend::opencl, event>
160 get_native<backend::opencl, event>(
const event &Obj) {
162 if (Obj.get_backend() != backend::opencl) {
163 throw sycl::runtime_error(errc::backend_mismatch,
"Backends mismatch",
164 PI_ERROR_INVALID_OPERATION);
166 backend_return_t<backend::opencl, event> ReturnValue;
167 for (
auto const &element : Obj.getNativeVector()) {
168 ReturnValue.push_back(
170 typename detail::interop<backend::opencl, event>::value_type
>(
179 "get_native<backend::opencl, event>, which return type is "
180 "cl_event is deprecated. According to SYCL 2020 spec, please define "
181 "SYCL2020_CONFORMANT_APIS and use vector<cl_event> instead.")
185 if (Obj.get_backend() != backend::opencl) {
186 throw sycl::runtime_error(errc::backend_mismatch,
"Backends mismatch",
187 PI_ERROR_INVALID_OPERATION);
189 return reinterpret_cast<
199 IsPlaceholder> &Obj) ->
200 typename detail::interop<
201 BackendName, accessor<DataT,
Dimensions, AccessMode, AccessTarget,
202 IsPlaceholder>>::type =
delete;
206 class kernel_bundle_impl;
217 const device &TargetDevice,
bool KeepOwnership,
221 const context &TargetContext,
bool KeepOwnership,
229 const context &TargetContext,
bool KeepOwnership,
236 const kernel_bundle<bundle_state::executable> &KernelBundle,
239 __SYCL_EXPORT std::shared_ptr<detail::kernel_bundle_impl>
242 __SYCL_EXPORT std::shared_ptr<detail::kernel_bundle_impl>
247 template <backend Backend>
248 typename std::enable_if<
249 detail::InteropFeatureSupportMap<Backend>::MakePlatform ==
true,
255 detail::pi::cast<pi_native_handle>(BackendObject), Backend);
258 template <backend Backend>
259 typename std::enable_if<
260 detail::InteropFeatureSupportMap<Backend>::MakeDevice ==
true,
device>::type
267 template <backend Backend>
268 typename std::enable_if<
269 detail::InteropFeatureSupportMap<Backend>::MakeContext ==
true,
279 template <backend Backend>
281 typename
std::enable_if<
282 detail::InteropFeatureSupportMap<Backend>::MakeQueue == true,
queue>::type
286 const
context &TargetContext,
bool KeepOwnership,
289 TargetContext, KeepOwnership, Handler, Backend);
292 template <backend Backend>
293 typename std::enable_if<
294 detail::InteropFeatureSupportMap<Backend>::MakeQueue ==
true,
queue>::type
299 TargetContext,
false, Handler, Backend);
302 template <backend Backend>
303 typename std::enable_if<
304 detail::InteropFeatureSupportMap<Backend>::MakeEvent ==
true,
event>::type
307 const context &TargetContext) {
309 TargetContext, Backend);
312 template <backend Backend>
314 typename
std::enable_if<
315 detail::InteropFeatureSupportMap<Backend>::MakeEvent == true,
event>::type
319 const
context &TargetContext,
bool KeepOwnership) {
321 TargetContext, KeepOwnership, Backend);
325 typename AllocatorT = detail::default_buffer_allocator<T>>
326 typename std::enable_if<detail::InteropFeatureSupportMap<Backend>::MakeBuffer ==
328 Backend != backend::ext_oneapi_level_zero,
329 buffer<T, Dimensions, AllocatorT>>::type
332 const context &TargetContext,
event AvailableEvent = {}) {
333 return detail::make_buffer_helper<T, Dimensions, AllocatorT>(
334 detail::pi::cast<pi_native_handle>(BackendObject), TargetContext,
338 template <backend Backend>
342 const context &TargetContext) {
344 TargetContext, Backend);
347 template <backend Backend, bundle_state State>
348 typename std::enable_if<
349 detail::InteropFeatureSupportMap<Backend>::MakeKernelBundle ==
true,
350 kernel_bundle<State>>::type
353 const context &TargetContext) {
354 std::shared_ptr<detail::kernel_bundle_impl> KBImpl =
356 detail::pi::cast<pi_native_handle>(BackendObject), TargetContext,
357 false, State, Backend);
358 return detail::createSyclObjFromImpl<kernel_bundle<State>>(KBImpl);