25 #include <sycl/feature_test.hpp>
36 #if SYCL_BACKEND_OPENCL
39 #if SYCL_EXT_ONEAPI_BACKEND_CUDA
40 #ifdef SYCL_EXT_ONEAPI_BACKEND_CUDA_EXPERIMENTAL
46 #if SYCL_EXT_ONEAPI_BACKEND_HIP
49 #if SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
57 #include <type_traits>
61 inline namespace _V1 {
81 template <backend Backend,
typename SyclType>
85 template <backend Backend,
typename SyclType>
90 template <backend Backend,
typename DataT,
int Dimensions,
typename AllocatorT>
99 ReturnValue = detail::ur::cast<ReturnType>(Handle[0]);
105 template <
typename DataT,
int Dimensions,
typename AllocatorT>
113 for (
auto &Obj : Handle) {
114 ReturnValue.push_back(
121 #if SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
131 "Buffer interop is not supported by level zero yet");
132 return Obj.template getNative<BackendName>();
137 template <backend BackendName,
class SyclObjectT>
140 if (Obj.get_backend() != BackendName) {
142 "Backends mismatch");
148 template <backend BackendName>
150 if (Obj.get_backend() != BackendName) {
152 "Backends mismatch");
154 int32_t IsImmCmdList;
155 ur_native_handle_t Handle = Obj.getNative(IsImmCmdList);
158 RetVal = IsImmCmdList
169 template <backend BackendName, bundle_state State>
172 if (Obj.get_backend() != BackendName) {
174 "Backends mismatch");
176 return Obj.template getNative<BackendName>();
183 return detail::get_native_buffer<BackendName>(Obj);
186 #if SYCL_BACKEND_OPENCL
188 inline backend_return_t<backend::opencl, event>
189 get_native<backend::opencl, event>(
const event &Obj) {
192 "Backends mismatch");
194 backend_return_t<backend::opencl, event> ReturnValue;
195 for (
auto const &element : Obj.getNativeVector()) {
196 ReturnValue.push_back(
205 #if SYCL_EXT_ONEAPI_BACKEND_CUDA
207 inline backend_return_t<backend::ext_oneapi_cuda, device>
208 get_native<backend::ext_oneapi_cuda, device>(
const device &Obj) {
211 "Backends mismatch");
215 return static_cast<backend_return_t<backend::ext_oneapi_cuda, device>
>(
219 #ifndef SYCL_EXT_ONEAPI_BACKEND_CUDA_EXPERIMENTAL
222 "Context interop is deprecated for CUDA. If a native context is required,"
223 " use cuDevicePrimaryCtxRetain with a native device")
225 backend::ext_oneapi_cuda, context>(const context &Obj) {
228 "Backends mismatch");
230 return reinterpret_cast<backend_return_t<backend::ext_oneapi_cuda, context>
>(
237 #if SYCL_EXT_ONEAPI_BACKEND_HIP
241 "Context interop is deprecated for HIP. If a native context is required,"
242 " use hipDevicePrimaryCtxRetain with a native device")
244 backend::ext_oneapi_hip, context>(const context &Obj) {
247 "Backends mismatch");
249 return reinterpret_cast<backend_return_t<backend::ext_oneapi_hip, context>
>(
260 typename detail::interop<
274 backend Backend,
bool KeepOwnership,
275 const std::vector<device> &DeviceList = {});
277 int32_t nativeHandleDesc,
279 const device *TargetDevice,
bool KeepOwnership,
282 __SYCL_EXPORT
event make_event(ur_native_handle_t NativeHandle,
284 __SYCL_EXPORT
event make_event(ur_native_handle_t NativeHandle,
285 const context &TargetContext,
bool KeepOwnership,
293 ur_native_handle_t NativeKernelHandle,
bool KeepOwnership,
backend Backend);
295 __SYCL_EXPORT std::shared_ptr<detail::kernel_bundle_impl>
299 __SYCL_EXPORT std::shared_ptr<detail::kernel_bundle_impl>
301 const context &TargetContext,
bool KeepOwnership,
305 template <backend Backend>
312 detail::ur::cast<ur_native_handle_t>(BackendObject), Backend);
315 template <backend Backend>
316 std::enable_if_t<detail::InteropFeatureSupportMap<Backend>::MakeDevice ==
true,
321 if (p.get_backend() != Backend)
324 for (
auto d : p.get_devices()) {
325 if (get_native<Backend>(d) == BackendObject)
331 detail::ur::cast<ur_native_handle_t>(BackendObject), Backend);
334 template <backend Backend>
335 std::enable_if_t<detail::InteropFeatureSupportMap<Backend>::MakeContext ==
true,
342 detail::ur::cast<ur_native_handle_t>(BackendObject), Handler, Backend,
346 template <backend Backend>
347 std::enable_if_t<detail::InteropFeatureSupportMap<Backend>::MakeQueue ==
true,
355 false, TargetContext,
nullptr, KeepOwnership, {},
359 template <backend Backend>
360 std::enable_if_t<detail::InteropFeatureSupportMap<Backend>::MakeEvent ==
true,
364 const context &TargetContext) {
366 TargetContext, Backend);
369 template <backend Backend>
371 std::enable_if_t<detail::InteropFeatureSupportMap<Backend>::MakeEvent == true,
373 template input_type<
event>
376 bool KeepOwnership) {
378 TargetContext, KeepOwnership, Backend);
382 typename AllocatorT = buffer_allocator<std::remove_const_t<T>>>
383 std::enable_if_t<detail::InteropFeatureSupportMap<Backend>::MakeBuffer ==
386 buffer<T, Dimensions, AllocatorT>>
389 const context &TargetContext,
event AvailableEvent = {}) {
390 return detail::make_buffer_helper<T, Dimensions, AllocatorT>(
391 detail::ur::cast<ur_native_handle_t>(BackendObject), TargetContext,
397 std::enable_if_t<detail::InteropFeatureSupportMap<Backend>::MakeImage ==
true &&
399 image<Dimensions, AllocatorT>>
402 const context &TargetContext,
event AvailableEvent = {}) {
403 return image<Dimensions, AllocatorT>(
404 detail::ur::cast<ur_native_handle_t>(BackendObject), TargetContext,
408 template <backend Backend>
412 const context &TargetContext) {
414 detail::ur::cast<ur_native_handle_t>(BackendObject), TargetContext,
418 template <backend Backend, bundle_state State>
419 std::enable_if_t<detail::InteropFeatureSupportMap<Backend>::MakeKernelBundle ==
421 kernel_bundle<State>>
424 const context &TargetContext) {
425 std::shared_ptr<detail::kernel_bundle_impl> KBImpl =
427 detail::ur::cast<ur_native_handle_t>(BackendObject), TargetContext,
428 false, State, Backend);
429 return detail::createSyclObjFromImpl<kernel_bundle<State>>(KBImpl);
The file contains implementations of accessor class.
struct _ze_command_queue_handle_t * ze_command_queue_handle_t
struct _ze_command_list_handle_t * ze_command_list_handle_t
typename detail::BackendReturn< Backend, T >::type return_type
typename detail::BackendInput< Backend, T >::type input_type
Defines a shared array that can be used by kernels in queues.
The context class represents a SYCL context on which kernel functions may be executed.
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
An event object can be used to synchronize memory transfers, enqueues of kernels and signaling barrie...
Defines a shared image data.
The kernel_bundle class represents collection of device images in a particular state.
Provides an abstraction of a SYCL kernel.
Objects of the property_list class are containers for the SYCL properties.
Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
#define __SYCL_DEPRECATED(message)
To cast(std::vector< cl_event > value)
queue make_queue(ur_native_handle_t NativeHandle, int32_t nativeHandleDesc, const context &TargetContext, const device *TargetDevice, bool KeepOwnership, const property_list &PropList, const async_handler &Handler, backend Backend)
context make_context(ur_native_handle_t NativeHandle, const async_handler &Handler, backend Backend, bool KeepOwnership, const std::vector< device > &DeviceList={})
auto get_native_buffer(const buffer< DataT, Dimensions, Allocator, void > &Obj) -> backend_return_t< BackendName, buffer< DataT, Dimensions, Allocator, void >>
std::shared_ptr< detail::kernel_bundle_impl > make_kernel_bundle(ur_native_handle_t NativeHandle, const context &TargetContext, bundle_state State, backend Backend)
device make_device(ur_native_handle_t NativeHandle, backend Backend)
backend convertUrBackend(ur_platform_backend_t UrBackend)
event make_event(ur_native_handle_t NativeHandle, const context &TargetContext, backend Backend)
kernel make_kernel(ur_native_handle_t NativeHandle, const context &TargetContext, backend Backend)
platform make_platform(ur_native_handle_t NativeHandle, backend Backend)
sycl::detail::kernel_bundle_impl kernel_bundle_impl
std::enable_if_t< detail::InteropFeatureSupportMap< Backend >::MakeQueue==true, queue > make_queue(const typename backend_traits< Backend >::template input_type< queue > &BackendObject, const context &TargetContext, const async_handler Handler={})
std::enable_if_t< detail::InteropFeatureSupportMap< Backend >::MakeDevice==true, device > make_device(const typename backend_traits< Backend >::template input_type< device > &BackendObject)
std::enable_if_t< detail::InteropFeatureSupportMap< Backend >::MakeKernelBundle==true, kernel_bundle< State > > make_kernel_bundle(const typename backend_traits< Backend >::template input_type< kernel_bundle< State >> &BackendObject, const context &TargetContext)
class __SYCL_EBO __SYCL_SPECIAL_CLASS Dimensions
std::enable_if_t< detail::InteropFeatureSupportMap< Backend >::MakeEvent==true, event > make_event(const typename backend_traits< Backend >::template input_type< event > &BackendObject, const context &TargetContext)
auto get_native(const SyclObjectT &Obj) -> backend_return_t< BackendName, SyclObjectT >
typename backend_traits< Backend >::template return_type< SyclType > backend_return_t
std::enable_if_t< detail::InteropFeatureSupportMap< Backend >::MakeImage==true &&Backend !=backend::ext_oneapi_level_zero, image< Dimensions, AllocatorT > > make_image(const typename backend_traits< Backend >::template input_type< image< Dimensions, AllocatorT >> &BackendObject, const context &TargetContext, event AvailableEvent={})
class __SYCL_EBO __SYCL_SPECIAL_CLASS IsPlaceholder
kernel make_kernel(const typename backend_traits< Backend >::template input_type< kernel > &BackendObject, const context &TargetContext)
std::enable_if_t< detail::InteropFeatureSupportMap< Backend >::MakePlatform==true, platform > make_platform(const typename backend_traits< Backend >::template input_type< platform > &BackendObject)
std::function< void(sycl::exception_list)> async_handler
class __SYCL_EBO __SYCL_SPECIAL_CLASS AccessMode
detail::aligned_allocator< byte > image_allocator
std::enable_if_t< detail::InteropFeatureSupportMap< Backend >::MakeContext==true, context > make_context(const typename backend_traits< Backend >::template input_type< context > &BackendObject, const async_handler &Handler={})
std::error_code make_error_code(sycl::errc E) noexcept
Constructs an error code using e and sycl_category()
std::enable_if_t< detail::InteropFeatureSupportMap< Backend >::MakeBuffer==true &&Backend !=backend::ext_oneapi_level_zero, buffer< T, Dimensions, AllocatorT > > make_buffer(const typename backend_traits< Backend >::template input_type< buffer< T, Dimensions, AllocatorT >> &BackendObject, const context &TargetContext, event AvailableEvent={})
typename backend_traits< Backend >::template input_type< SyclType > backend_input_t
static ReturnType GetNativeObjs(const std::vector< ur_native_handle_t > &Handle)
backend_return_t< backend::opencl, buffer< DataT, Dimensions, AllocatorT > > ReturnType
backend_return_t< Backend, buffer< DataT, Dimensions, AllocatorT > > ReturnType
static ReturnType GetNativeObjs(const std::vector< ur_native_handle_t > &Handle)
static constexpr bool MakePlatform
C++ utilities for Unified Runtime integration.