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 {
17 inline namespace _V1 {
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) {
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>(
59  std::make_shared<context_impl>(PiContext, detail::defaultAsyncHandler,
60  Plugin, DeviceList, !KeepOwnership));
61 }
62 
63 //----------------------------------------------------------------------------
64 // Implementation of level_zero::make<queue>
65 __SYCL_EXPORT queue make_queue(const context &Context, const device &Device,
66  pi_native_handle NativeHandle, bool IsImmCmdList,
67  bool KeepOwnership,
68  const property_list &Properties) {
69  const auto &ContextImpl = getSyclObjImpl(Context);
70  return detail::make_queue(
71  NativeHandle, IsImmCmdList, Context, &Device, KeepOwnership, Properties,
72  ContextImpl->get_async_handler(), backend::ext_oneapi_level_zero);
73 }
74 
75 //----------------------------------------------------------------------------
76 // Implementation of level_zero::make<event>
77 __SYCL_EXPORT event make_event(const context &Context,
78  pi_native_handle NativeHandle,
79  bool KeepOwnership) {
80  return detail::make_event(NativeHandle, Context, KeepOwnership,
82 }
83 
84 } // namespace ext::oneapi::level_zero
85 } // namespace _V1
86 } // namespace sycl
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:50
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:64
Encapsulates a SYCL platform on which kernels may be executed.
Definition: platform.hpp:99
Objects of the property_list class are containers for the SYCL properties.
Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
Definition: queue.hpp:111
::pi_device PiDevice
Definition: pi.hpp:131
::pi_context PiContext
Definition: pi.hpp:135
void defaultAsyncHandler(exception_list Exceptions)
queue make_queue(pi_native_handle NativeHandle, int32_t nativeHandleDesc, const context &TargetContext, const device *TargetDevice, bool KeepOwnership, const property_list &PropList, const async_handler &Handler, backend Backend)
Definition: backend.cpp:107
platform make_platform(pi_native_handle NativeHandle, backend Backend)
Definition: backend.cpp:70
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: impl_utils.hpp:30
event make_event(pi_native_handle NativeHandle, const context &TargetContext, backend Backend)
Definition: backend.cpp:141
platform make_platform(pi_native_handle NativeHandle)
Definition: level_zero.cpp:23
context make_context(const std::vector< device > &DeviceList, pi_native_handle NativeHandle, bool keep_ownership=false)
Definition: level_zero.cpp:44
event make_event(const context &Context, pi_native_handle InteropHandle, bool keep_ownership=false)
Definition: level_zero.cpp:77
device make_device(const platform &Platform, pi_native_handle NativeHandle)
Definition: level_zero.cpp:29
queue make_queue(const context &Context, const device &Device, pi_native_handle InteropHandle, bool IsImmCmdList, bool keep_ownership, const property_list &Properties)
Definition: level_zero.cpp:65
Definition: access.hpp:18
uintptr_t pi_native_handle
Definition: pi.h:217
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_cuda.cpp:143
pi_result piextDeviceCreateWithNativeHandle(pi_native_handle nativeHandle, pi_platform platform, pi_device *device)
Creates PI device object from a native handle.
Definition: pi_cuda.cpp:106