DPC++ Runtime
Runtime libraries for oneAPI DPC++
device.hpp
Go to the documentation of this file.
1 //==------------------- device.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 <sycl/aspects.hpp>
13 #include <sycl/detail/cl.h>
14 #include <sycl/detail/common.hpp>
15 #include <sycl/detail/export.hpp>
19 #include <sycl/info/info_desc.hpp>
20 #include <sycl/platform.hpp>
21 #include <sycl/stl.hpp>
22 
23 #include <memory>
24 #include <utility>
25 
26 namespace sycl {
28 // Forward declarations
29 class device_selector;
30 template <backend BackendName, class SyclObjectT>
31 auto get_native(const SyclObjectT &Obj)
32  -> backend_return_t<BackendName, SyclObjectT>;
33 namespace detail {
34 class device_impl;
36 } // namespace detail
37 
38 enum class aspect;
39 
40 namespace ext::oneapi {
41 // Forward declaration
42 class filter_selector;
43 } // namespace ext::oneapi
44 
49 class __SYCL_EXPORT device : public detail::OwnerLessBase<device> {
50 public:
52  device();
53 
58 #ifdef __SYCL_INTERNAL_API
59  explicit device(cl_device_id DeviceId);
60 #endif
61 
66  __SYCL2020_DEPRECATED("SYCL 1.2.1 device selectors are deprecated. Please "
67  "use SYCL 2020 device selectors instead.")
68  explicit device(const device_selector &DeviceSelector);
69 
74  template <typename DeviceSelector,
75  typename =
77  explicit device(const DeviceSelector &deviceSelector)
78  : device(detail::select_device(deviceSelector)) {}
79 
80  bool operator==(const device &rhs) const { return impl == rhs.impl; }
81 
82  bool operator!=(const device &rhs) const { return !(*this == rhs); }
83 
84  device(const device &rhs) = default;
85 
86  device(device &&rhs) = default;
87 
88  device &operator=(const device &rhs) = default;
89 
90  device &operator=(device &&rhs) = default;
91 
96 #ifdef __SYCL_INTERNAL_API
97  cl_device_id get() const;
98 #endif
99 
104  "is_host() is deprecated as the host device is no longer supported.")
105  bool is_host() const;
106 
110  bool is_cpu() const;
111 
115  bool is_gpu() const;
116 
120  bool is_accelerator() const;
121 
132  platform get_platform() const;
133 
145  template <info::partition_property prop>
146  std::vector<device> create_sub_devices(size_t ComputeUnits) const;
147 
158  template <info::partition_property prop>
159  std::vector<device>
160  create_sub_devices(const std::vector<size_t> &Counts) const;
161 
175  template <info::partition_property prop>
176  std::vector<device>
177  create_sub_devices(info::partition_affinity_domain AffinityDomain) const;
178 
189  template <info::partition_property prop>
190  std::vector<device> create_sub_devices() const;
191 
200  template <typename Param>
201  typename detail::is_device_info_desc<Param>::return_type get_info() const;
202 
207  __SYCL2020_DEPRECATED("use device::has() function with aspects APIs instead")
208  bool has_extension(const std::string &extension_name) const;
209 
218  static std::vector<device>
219  get_devices(info::device_type deviceType = info::device_type::all);
220 
224  backend get_backend() const noexcept;
225 
232  bool has(aspect Aspect) const;
233 
234 private:
235  std::shared_ptr<detail::device_impl> impl;
236  device(std::shared_ptr<detail::device_impl> impl) : impl(impl) {}
237 
238  pi_native_handle getNative() const;
239 
240  template <class Obj>
241  friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
242 
243  template <class T>
244  friend
245  typename detail::add_pointer_t<typename decltype(T::impl)::element_type>
246  detail::getRawSyclObjImpl(const T &SyclObject);
247 
248  template <class T>
249  friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
250 
251  template <backend BackendName, class SyclObjectT>
252  friend auto get_native(const SyclObjectT &Obj)
253  -> backend_return_t<BackendName, SyclObjectT>;
254 };
255 
256 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
257 } // namespace sycl
258 
259 namespace std {
260 template <> struct hash<sycl::device> {
261  size_t operator()(const sycl::device &Device) const {
262  return hash<std::shared_ptr<sycl::detail::device_impl>>()(
264  }
265 };
266 } // namespace std
sycl::_V1::info::partition_affinity_domain
partition_affinity_domain
Definition: info_desc.hpp:63
sycl::_V1::__SYCL2020_DEPRECATED
signed char __SYCL2020_DEPRECATED
Definition: aliases.hpp:96
aspects.hpp
sycl::_V1::instead
std::uint8_t instead
Definition: aliases.hpp:95
sycl::_V1::backend
backend
Definition: backend_types.hpp:21
sycl::_V1::opencl::has_extension
bool has_extension(const sycl::platform &SyclPlatform, const std::string &Extension)
Definition: opencl.cpp:54
sycl::_V1::info::partition_property
partition_property
Definition: info_desc.hpp:55
stl.hpp
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:11
sycl::_V1::device::operator!=
bool operator!=(const device &rhs) const
Definition: device.hpp:82
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
sycl::_V1::detail::getRawSyclObjImpl
detail::add_pointer_t< typename decltype(T::impl)::element_type > getRawSyclObjImpl(const T &SyclObject)
Definition: common.hpp:310
backend_traits.hpp
owner_less_base.hpp
sycl::_V1::detail::getDeviceComparisonLambda
auto getDeviceComparisonLambda()
export.hpp
std::get
constexpr tuple_element< I, tuple< Types... > >::type & get(sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
cl.h
sycl::_V1::device::device
device(const DeviceSelector &deviceSelector)
Constructs a SYCL device instance using the device identified by the device selector provided.
Definition: device.hpp:77
sycl::_V1::ext::oneapi::experimental::operator=
annotated_arg & operator=(annotated_arg &)=default
device_selector
std::hash< sycl::device >::operator()
size_t operator()(const sycl::device &Device) const
Definition: device.hpp:261
sycl::_V1::detail::OwnerLessBase
Definition: owner_less_base.hpp:21
sycl::_V1::device::operator==
bool operator==(const device &rhs) const
Definition: device.hpp:80
sycl::_V1::detail::select_device
device select_device(const DSelectorInvocableType &DeviceSelectorInvocable)
Definition: device_selector.cpp:136
common.hpp
sycl::_V1::device
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:49
sycl::_V1::detail::createSyclObjFromImpl
T createSyclObjFromImpl(decltype(T::impl) ImplObj)
Definition: common.hpp:318
sycl::_V1::info::device_type
device_type
Definition: info_desc.hpp:44
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:133
platform.hpp
std
Definition: accessor.hpp:3230
info_desc_helpers.hpp
sycl::_V1::ext::oneapi::experimental::matrix::use
use
Definition: matrix-unified-utils.hpp:17
info_desc.hpp
sycl::_V1::platform
Encapsulates a SYCL platform on which kernels may be executed.
Definition: platform.hpp:45
sycl::_V1::detail::add_pointer_t
typename std::add_pointer< T >::type add_pointer_t
Definition: stl_type_traits.hpp:37
weak_object_base.hpp
sycl::_V1::get_native
auto get_native(const SyclObjectT &Obj) -> backend_return_t< BackendName, SyclObjectT >
Definition: backend.hpp:123
sycl::_V1::detail::EnableIfSYCL2020DeviceSelectorInvocable
std::enable_if_t< std::is_invocable_r_v< int, DeviceSelector &, const device & > &&!std::is_base_of_v< ext::oneapi::filter_selector, DeviceSelector > &&!std::is_base_of_v< device_selector, DeviceSelector > > EnableIfSYCL2020DeviceSelectorInvocable
Definition: device_selector.hpp:139
sycl::_V1::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:300