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 {
19 namespace oneapi {
20 namespace level_zero {
21 using namespace detail;
22 
23 //----------------------------------------------------------------------------
24 // Implementation of level_zero::make<platform>
25 __SYCL_EXPORT platform make_platform(pi_native_handle NativeHandle) {
26  return detail::make_platform(NativeHandle, backend::ext_oneapi_level_zero);
27 }
28 
29 //----------------------------------------------------------------------------
30 // Implementation of level_zero::make<device>
31 __SYCL_EXPORT device make_device(const platform &Platform,
32  pi_native_handle NativeHandle) {
33  const auto &Plugin = pi::getPlugin<backend::ext_oneapi_level_zero>();
34  const auto &PlatformImpl = getSyclObjImpl(Platform);
35  // Create PI device first.
38  NativeHandle, PlatformImpl->getHandleRef(), &PiDevice);
39 
40  return detail::createSyclObjFromImpl<device>(
41  PlatformImpl->getOrMakeDeviceImpl(PiDevice, PlatformImpl));
42 }
43 
44 //----------------------------------------------------------------------------
45 // Implementation of level_zero::make<context>
46 __SYCL_EXPORT context make_context(const std::vector<device> &DeviceList,
47  pi_native_handle NativeHandle,
48  bool KeepOwnership) {
49  const auto &Plugin = pi::getPlugin<backend::ext_oneapi_level_zero>();
50  // Create PI context first.
52  std::vector<pi_device> DeviceHandles;
53  for (auto Dev : DeviceList) {
54  DeviceHandles.push_back(detail::getSyclObjImpl(Dev)->getHandleRef());
55  }
57  NativeHandle, DeviceHandles.size(), DeviceHandles.data(), !KeepOwnership,
58  &PiContext);
59  // Construct the SYCL context from PI context.
60  return detail::createSyclObjFromImpl<context>(std::make_shared<context_impl>(
62 }
63 
64 //----------------------------------------------------------------------------
65 // Implementation of level_zero::make<queue>
66 __SYCL_EXPORT queue make_queue(const context &Context,
67  pi_native_handle NativeHandle,
68  bool KeepOwnership) {
69  const auto &ContextImpl = getSyclObjImpl(Context);
70  return detail::make_queue(NativeHandle, Context, nullptr, KeepOwnership,
71  ContextImpl->get_async_handler(),
72  backend::ext_oneapi_level_zero);
73 }
74 
75 __SYCL_EXPORT queue make_queue(const context &Context, const device &Device,
76  pi_native_handle NativeHandle,
77  bool KeepOwnership) {
78  const auto &ContextImpl = getSyclObjImpl(Context);
79  return detail::make_queue(NativeHandle, Context, &Device, KeepOwnership,
80  ContextImpl->get_async_handler(),
81  backend::ext_oneapi_level_zero);
82 }
83 
84 //----------------------------------------------------------------------------
85 // Implementation of level_zero::make<event>
86 __SYCL_EXPORT event make_event(const context &Context,
87  pi_native_handle NativeHandle,
88  bool KeepOwnership) {
89  return detail::make_event(NativeHandle, Context, KeepOwnership,
90  backend::ext_oneapi_level_zero);
91 }
92 
93 } // namespace level_zero
94 } // namespace oneapi
95 } // namespace ext
96 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
97 } // namespace sycl
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:39
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:47
Encapsulates a SYCL platform on which kernels may be executed.
Definition: platform.hpp:45
Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
Definition: queue.hpp:86
#define __SYCL_INLINE_VER_NAMESPACE(X)
::pi_device PiDevice
Definition: pi.hpp:110
::pi_context PiContext
Definition: pi.hpp:114
void defaultAsyncHandler(exception_list Exceptions)
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:240
event make_event(pi_native_handle NativeHandle, const context &TargetContext, backend Backend)
Definition: backend.cpp:112
device make_device(pi_native_handle NativeHandle)
Definition: opencl.cpp:32
platform make_platform(pi_native_handle NativeHandle)
Definition: opencl.cpp:26
context make_context(pi_native_handle NativeHandle)
Definition: opencl.cpp:38
queue make_queue(const context &Context, pi_native_handle InteropHandle)
Definition: opencl.cpp:45
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
uintptr_t pi_native_handle
Definition: pi.h:107
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.
pi_result piextDeviceCreateWithNativeHandle(pi_native_handle nativeHandle, pi_platform platform, pi_device *device)
Creates PI device object from a native handle.
@ Device
PI context mapping to a CUDA context object.
Definition: pi_cuda.hpp:160