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 
9 #include <CL/sycl.hpp>
10 #include <CL/sycl/backend.hpp>
11 #include <detail/platform_impl.hpp>
12 #include <detail/plugin.hpp>
13 #include <detail/program_impl.hpp>
14 #include <detail/queue_impl.hpp>
15 
17 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>(
61  std::make_shared<context_impl>(PiContext, async_handler{}, Plugin));
62 }
63 
64 // TODO: remove this version (without ownership) when allowed to break ABI.
65 __SYCL_EXPORT context make_context(const std::vector<device> &DeviceList,
66  pi_native_handle NativeHandle) {
67  return make_context(DeviceList, NativeHandle, false);
68 }
69 
70 //----------------------------------------------------------------------------
71 // Implementation of level_zero::make<program>
72 __SYCL_EXPORT program make_program(const context &Context,
73  pi_native_handle NativeHandle) {
74  // Construct the SYCL program from native program.
75  // TODO: move here the code that creates PI program, and remove the
76  // native interop constructor.
77  return detail::createSyclObjFromImpl<program>(
78  std::make_shared<program_impl>(getSyclObjImpl(Context), NativeHandle));
79 }
80 
81 //----------------------------------------------------------------------------
82 // Implementation of level_zero::make<queue>
83 __SYCL_EXPORT queue make_queue(const context &Context,
84  pi_native_handle NativeHandle,
85  bool KeepOwnership) {
86  const auto &ContextImpl = getSyclObjImpl(Context);
87  return detail::make_queue(NativeHandle, Context, KeepOwnership,
88  ContextImpl->get_async_handler(),
89  backend::ext_oneapi_level_zero);
90 }
91 
92 __SYCL_EXPORT queue make_queue(const context &Context, const device &Device,
93  pi_native_handle NativeHandle,
94  bool KeepOwnership) {
95  const auto &ContextImpl = getSyclObjImpl(Context);
96  return detail::make_queue(NativeHandle, Context, Device, KeepOwnership,
97  ContextImpl->get_async_handler(),
98  backend::ext_oneapi_level_zero);
99 }
100 
101 // TODO: remove this version (without ownership) when allowed to break ABI.
102 __SYCL_EXPORT queue make_queue(const context &Context,
103  pi_native_handle NativeHandle) {
104  return make_queue(Context, NativeHandle, false);
105 }
106 
107 //----------------------------------------------------------------------------
108 // Implementation of level_zero::make<event>
109 __SYCL_EXPORT event make_event(const context &Context,
110  pi_native_handle NativeHandle,
111  bool KeepOwnership) {
112  return detail::make_event(NativeHandle, Context, KeepOwnership,
113  backend::ext_oneapi_level_zero);
114 }
115 
116 } // namespace level_zero
117 } // namespace oneapi
118 } // namespace ext
119 } // namespace sycl
120 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::opencl::make_platform
platform make_platform(pi_native_handle NativeHandle)
Definition: opencl.cpp:23
cl::sycl::ext::oneapi::level_zero::make_program
program make_program(const context &Context, pi_native_handle NativeHandle)
Definition: level_zero.cpp:72
cl::sycl::opencl::make_device
device make_device(pi_native_handle NativeHandle)
Definition: opencl.cpp:29
cl::sycl::detail::pi::PiDevice
::pi_device PiDevice
Definition: pi.hpp:102
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:822
sycl
Definition: invoke_simd.hpp:68
plugin.hpp
queue_impl.hpp
cl::sycl::detail::pi::PiContext
::pi_context PiContext
Definition: pi.hpp:106
cl::sycl::queue
Encapsulates a single SYCL queue which schedules kernels on a SYCL device.
Definition: queue.hpp:103
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:872
program_impl.hpp
sycl.hpp
platform_impl.hpp
cl::sycl::device
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:35
cl::sycl::detail::make_event
event make_event(pi_native_handle NativeHandle, const context &TargetContext, backend Backend)
Definition: backend.cpp:118
cl::sycl::ext::oneapi::level_zero::make_queue
queue make_queue(const context &Context, pi_native_handle NativeHandle)
Definition: level_zero.cpp:102
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::ext::oneapi::level_zero::make_context
context make_context(const std::vector< device > &DeviceList, pi_native_handle NativeHandle)
Definition: level_zero.cpp:65
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:76
cl::sycl::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:198
cl::sycl::platform
Encapsulates a SYCL platform on which kernels may be executed.
Definition: platform.hpp:34
backend.hpp
cl::sycl::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:35
cl::sycl::async_handler
std::function< void(cl::sycl::exception_list)> async_handler
Definition: exception_list.hpp:53
_pi_context
PI context mapping to a CUDA context object.
Definition: pi_cuda.hpp:150
_pi_device
PI device mapping to a CUdevice.
Definition: pi_cuda.hpp:73
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12