DPC++ Runtime
Runtime libraries for oneAPI DPC++
device_impl.hpp
Go to the documentation of this file.
1 //==----------------- device_impl.hpp - SYCL device ------------------------==//
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 #pragma once
10 
11 #include <CL/sycl/aspects.hpp>
12 #include <CL/sycl/detail/pi.hpp>
14 #include <CL/sycl/stl.hpp>
15 #include <detail/device_info.hpp>
16 #include <detail/platform_impl.hpp>
17 
18 #include <memory>
19 #include <mutex>
20 
22 namespace sycl {
23 
24 // Forward declaration
25 class platform;
26 
27 namespace detail {
28 
29 // Forward declaration
30 class platform_impl;
31 using PlatformImplPtr = std::shared_ptr<platform_impl>;
32 
33 // TODO: Make code thread-safe
34 class device_impl {
35 public:
37  device_impl();
38 
40  explicit device_impl(pi_native_handle, const plugin &Plugin);
41 
44  explicit device_impl(RT::PiDevice Device, PlatformImplPtr Platform);
45 
48  explicit device_impl(RT::PiDevice Device, const plugin &Plugin);
49 
50  ~device_impl();
51 
56  cl_device_id get() const;
57 
64  if (MIsHostDevice)
65  throw invalid_object_error("This instance of device is a host instance",
67 
68  return MDevice;
69  }
70 
76  const RT::PiDevice &getHandleRef() const {
77  if (MIsHostDevice)
78  throw invalid_object_error("This instance of device is a host instance",
80 
81  return MDevice;
82  }
83 
87  bool is_host() const { return MIsHostDevice; }
88 
92  bool is_cpu() const { return (!is_host() && (MType == PI_DEVICE_TYPE_CPU)); }
93 
97  bool is_gpu() const { return (!is_host() && (MType == PI_DEVICE_TYPE_GPU)); }
98 
102  bool is_accelerator() const {
103  return (!is_host() && (MType == PI_DEVICE_TYPE_ACC));
104  }
105 
109  RT::PiDeviceType get_device_type() const { return MType; }
110 
121  platform get_platform() const;
122 
124  const plugin &getPlugin() const { return MPlatform->getPlugin(); }
125 
130  bool has_extension(const std::string &ExtensionName) const;
131 
132  std::vector<device>
133  create_sub_devices(const cl_device_partition_property *Properties,
134  size_t SubDevicesCount) const;
135 
146  std::vector<device> create_sub_devices(size_t ComputeUnits) const;
147 
157  std::vector<device>
158  create_sub_devices(const std::vector<size_t> &Counts) const;
159 
171  std::vector<device>
172  create_sub_devices(info::partition_affinity_domain AffinityDomain) const;
173 
179  bool is_partition_supported(info::partition_property Prop) const;
180 
189  template <info::device param>
191  get_info() const {
192  if (is_host()) {
193  return get_device_info_host<param>();
194  }
195  return get_device_info<
197  param>::get(this->getHandleRef(), this->getPlugin());
198  }
199 
206  bool
207  is_affinity_supported(info::partition_affinity_domain AffinityDomain) const;
208 
212  pi_native_handle getNative() const;
213 
218  //
220  bool has(aspect Aspect) const;
221 
225  static std::shared_ptr<device_impl> getHostDeviceImpl();
226 
227  bool isAssertFailSupported() const;
228 
229  bool isRootDevice() const { return MRootDevice == nullptr; }
230 
231  std::string getDeviceName() const;
232 
233 private:
234  explicit device_impl(pi_native_handle InteropDevice, RT::PiDevice Device,
235  PlatformImplPtr Platform, const plugin &Plugin);
236  RT::PiDevice MDevice = 0;
237  RT::PiDeviceType MType;
238  RT::PiDevice MRootDevice = nullptr;
239  bool MIsHostDevice;
240  PlatformImplPtr MPlatform;
241  bool MIsAssertFailSupported = false;
242  mutable std::string MDeviceName;
243  mutable std::once_flag MDeviceNameFlag;
244 }; // class device_impl
245 
246 } // namespace detail
247 } // namespace sycl
248 } // __SYCL_INLINE_NAMESPACE(cl)
aspects.hpp
device_info.hpp
cl::sycl::detail::pi::getPlugin
const plugin & getPlugin()
Definition: pi.cpp:511
cl::sycl::detail::device_impl::is_gpu
bool is_gpu() const
Check if device is a GPU device.
Definition: device_impl.hpp:97
cl::sycl::detail::device_impl::getPlugin
const plugin & getPlugin() const
Definition: device_impl.hpp:124
cl::sycl::info::param_traits
Definition: info_desc.hpp:310
cl::sycl::detail::device_impl
Definition: device_impl.hpp:34
stl.hpp
cl::sycl::detail::device_impl::isRootDevice
bool isRootDevice() const
Definition: device_impl.hpp:229
_pi_device_type
_pi_device_type
Definition: pi.h:174
cl::sycl::detail::get_device_info
Definition: device_info.hpp:101
sycl
Definition: invoke_simd.hpp:68
pi.hpp
cl::sycl::detail::device_impl::is_host
bool is_host() const
Check if SYCL device is a host device.
Definition: device_impl.hpp:87
PI_DEVICE_TYPE_GPU
@ PI_DEVICE_TYPE_GPU
A PI device that is a GPU.
Definition: pi.h:182
platform_impl.hpp
kernel_bundle.hpp
PI_DEVICE_TYPE_ACC
@ PI_DEVICE_TYPE_ACC
A PI device that is a dedicated accelerator.
Definition: pi.h:183
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::detail::device_impl::getHandleRef
const RT::PiDevice & getHandleRef() const
Get constant reference to PI device.
Definition: device_impl.hpp:76
cl::sycl::aspect
aspect
Definition: aspects.hpp:15
cl::sycl::detail::plugin
The plugin class provides a unified interface to the underlying low-level runtimes for the device-agn...
Definition: plugin.hpp:90
cl::sycl::detail::device_impl::is_accelerator
bool is_accelerator() const
Check if device is an accelerator device.
Definition: device_impl.hpp:102
cl::sycl::detail::device_impl::get_info
info::param_traits< info::device, param >::return_type get_info() const
Queries this SYCL device for information requested by the template parameter param.
Definition: device_impl.hpp:191
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:76
PI_DEVICE_TYPE_CPU
@ PI_DEVICE_TYPE_CPU
A PI device that is the host processor.
Definition: pi.h:180
cl::sycl::info::partition_property
partition_property
Definition: info_desc.hpp:191
std::get
constexpr tuple_element< I, tuple< Types... > >::type & get(cl::sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
cl::sycl::detail::device_impl::getHandleRef
RT::PiDevice & getHandleRef()
Get reference to PI device.
Definition: device_impl.hpp:63
cl::sycl::detail::PlatformImplPtr
std::shared_ptr< detail::platform_impl > PlatformImplPtr
Definition: context_impl.hpp:30
cl::sycl::platform
Encapsulates a SYCL platform on which kernels may be executed.
Definition: platform.hpp:34
cl::sycl::detail::device_impl::is_cpu
bool is_cpu() const
Check if device is a CPU device.
Definition: device_impl.hpp:92
cl::sycl::info::platform
platform
Definition: info_desc.hpp:31
cl::sycl::detail::device_impl::get_device_type
RT::PiDeviceType get_device_type() const
Return device type.
Definition: device_impl.hpp:109
PI_INVALID_DEVICE
@ PI_INVALID_DEVICE
Definition: pi.h:94
_pi_device
PI device mapping to a CUdevice.
Definition: pi_cuda.hpp:73
cl::sycl::info::partition_affinity_domain
partition_affinity_domain
Definition: info_desc.hpp:198
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12