DPC++ Runtime
Runtime libraries for oneAPI DPC++
level_zero.cpp
Go to the documentation of this file.
1 //==--------- level_zero.cpp - SYCL Level-Zero backend ---------------------==//
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 
10 #include <detail/plugin.hpp>
11 #include <detail/program_impl.hpp>
12 #include <detail/queue_impl.hpp>
13 #include <sycl/backend.hpp>
14 #include <sycl/sycl.hpp>
15 
16 namespace sycl {
18 namespace ext::oneapi::level_zero {
19 using namespace detail;
20 
21 //----------------------------------------------------------------------------
22 // Implementation of level_zero::make<platform>
23 __SYCL_EXPORT platform make_platform(pi_native_handle NativeHandle) {
24  return detail::make_platform(NativeHandle, backend::ext_oneapi_level_zero);
25 }
26 
27 //----------------------------------------------------------------------------
28 // Implementation of level_zero::make<device>
29 __SYCL_EXPORT device make_device(const platform &Platform,
30  pi_native_handle NativeHandle) {
31  const auto &Plugin = pi::getPlugin<backend::ext_oneapi_level_zero>();
32  const auto &PlatformImpl = getSyclObjImpl(Platform);
33  // Create PI device first.
36  NativeHandle, PlatformImpl->getHandleRef(), &PiDevice);
37 
38  return detail::createSyclObjFromImpl<device>(
39  PlatformImpl->getOrMakeDeviceImpl(PiDevice, PlatformImpl));
40 }
41 
42 //----------------------------------------------------------------------------
43 // Implementation of level_zero::make<context>
44 __SYCL_EXPORT context make_context(const std::vector<device> &DeviceList,
45  pi_native_handle NativeHandle,
46  bool KeepOwnership) {
47  const auto &Plugin = pi::getPlugin<backend::ext_oneapi_level_zero>();
48  // Create PI context first.
50  std::vector<pi_device> DeviceHandles;
51  for (auto Dev : DeviceList) {
52  DeviceHandles.push_back(detail::getSyclObjImpl(Dev)->getHandleRef());
53  }
55  NativeHandle, DeviceHandles.size(), DeviceHandles.data(), !KeepOwnership,
56  &PiContext);
57  // Construct the SYCL context from PI context.
58  return detail::createSyclObjFromImpl<context>(std::make_shared<context_impl>(
60 }
61 
62 //----------------------------------------------------------------------------
63 // Implementation of level_zero::make<queue>
64 __SYCL_EXPORT queue make_queue(const context &Context,
65  pi_native_handle NativeHandle,
66  bool KeepOwnership) {
67  const auto &ContextImpl = getSyclObjImpl(Context);
68  return detail::make_queue(NativeHandle, Context, nullptr, KeepOwnership,
69  ContextImpl->get_async_handler(),
70  backend::ext_oneapi_level_zero);
71 }
72 
73 __SYCL_EXPORT queue make_queue(const context &Context, const device &Device,
74  pi_native_handle NativeHandle,
75  bool KeepOwnership) {
76  const auto &ContextImpl = getSyclObjImpl(Context);
77  return detail::make_queue(NativeHandle, Context, &Device, KeepOwnership,
78  ContextImpl->get_async_handler(),
79  backend::ext_oneapi_level_zero);
80 }
81 
82 //----------------------------------------------------------------------------
83 // Implementation of level_zero::make<event>
84 __SYCL_EXPORT event make_event(const context &Context,
85  pi_native_handle NativeHandle,
86  bool KeepOwnership) {
87  return detail::make_event(NativeHandle, Context, KeepOwnership,
88  backend::ext_oneapi_level_zero);
89 }
90 
91 } // namespace ext::oneapi::level_zero
92 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
93 } // namespace sycl
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:11
sycl::_V1::detail::pi::PiDevice
::pi_device PiDevice
Definition: pi.hpp:124
piextDeviceCreateWithNativeHandle
pi_result piextDeviceCreateWithNativeHandle(pi_native_handle nativeHandle, pi_platform platform, pi_device *device)
Creates PI device object from a native handle.
Definition: pi_esimd_emulator.cpp:831
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
plugin.hpp
queue_impl.hpp
sycl::_V1::opencl::make_context
context make_context(pi_native_handle NativeHandle)
Definition: opencl.cpp:38
piextContextCreateWithNativeHandle
pi_result piextContextCreateWithNativeHandle(pi_native_handle nativeHandle, pi_uint32 numDevices, const pi_device *devices, bool pluginOwnsNativeHandle, pi_context *context)
Creates PI context object from a native handle.
Definition: pi_esimd_emulator.cpp:881
sycl::_V1::opencl::make_queue
queue make_queue(const context &Context, pi_native_handle InteropHandle)
Definition: opencl.cpp:45
program_impl.hpp
platform_impl.hpp
sycl::_V1::queue
Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
Definition: queue.hpp:89
sycl::_V1::detail::pi::PiContext
::pi_context PiContext
Definition: pi.hpp:128
sycl::_V1::device
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:49
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:133
sycl::_V1::detail::defaultAsyncHandler
void defaultAsyncHandler(exception_list Exceptions)
Definition: exception_list.hpp:59
backend.hpp
sycl::_V1::opencl::make_device
device make_device(pi_native_handle NativeHandle)
Definition: opencl.cpp:32
sycl::_V1::opencl::make_platform
platform make_platform(pi_native_handle NativeHandle)
Definition: opencl.cpp:26
sycl.hpp
sycl::_V1::platform
Encapsulates a SYCL platform on which kernels may be executed.
Definition: platform.hpp:45
sycl::_V1::detail::make_event
event make_event(pi_native_handle NativeHandle, const context &TargetContext, backend Backend)
Definition: backend.cpp:112
_pi_context
PI context mapping to a CUDA context object.
Definition: pi_cuda.hpp:170
sycl::_V1::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:300
sycl::_V1::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:41