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>
17 #include <sycl/info/info_desc.hpp>
18 #include <sycl/platform.hpp>
19 #include <sycl/stl.hpp>
20 
21 #include <memory>
22 #include <utility>
23 
24 namespace sycl {
26 // Forward declarations
27 class device_selector;
28 template <backend BackendName, class SyclObjectT>
29 auto get_native(const SyclObjectT &Obj)
30  -> backend_return_t<BackendName, SyclObjectT>;
31 namespace detail {
32 class device_impl;
34 } // namespace detail
35 
36 namespace ext {
37 namespace oneapi {
38 // Forward declaration
39 class filter_selector;
40 } // namespace oneapi
41 } // namespace ext
42 
47 class __SYCL_EXPORT device {
48 public:
50  device();
51 
56 #ifdef __SYCL_INTERNAL_API
57  explicit device(cl_device_id DeviceId);
58 #endif
59 
64  __SYCL2020_DEPRECATED("Use Callable device selectors instead of deprecated "
65  "device_selector subclasses.")
66  explicit device(const device_selector &DeviceSelector);
67 
68 #if __cplusplus >= 201703L
69  template <typename DeviceSelector,
74  typename = detail::EnableIfDeviceSelectorInvocable<DeviceSelector>>
75  explicit device(const DeviceSelector &deviceSelector)
76  : device(detail::select_device(deviceSelector)) {}
77 #endif
78 
79  bool operator==(const device &rhs) const { return impl == rhs.impl; }
80 
81  bool operator!=(const device &rhs) const { return !(*this == rhs); }
82 
83  device(const device &rhs) = default;
84 
85  device(device &&rhs) = default;
86 
87  device &operator=(const device &rhs) = default;
88 
89  device &operator=(device &&rhs) = default;
90 
95 #ifdef __SYCL_INTERNAL_API
96  cl_device_id get() const;
97 #endif
98 
103  "is_host() is deprecated as the host device is no longer supported.")
104  bool is_host() const;
105 
109  bool is_cpu() const;
110 
114  bool is_gpu() const;
115 
119  bool is_accelerator() const;
120 
131  platform get_platform() const;
132 
144  template <info::partition_property prop>
145  std::vector<device> create_sub_devices(size_t ComputeUnits) const;
146 
157  template <info::partition_property prop>
158  std::vector<device>
159  create_sub_devices(const std::vector<size_t> &Counts) const;
160 
174  template <info::partition_property prop>
175  std::vector<device>
176  create_sub_devices(info::partition_affinity_domain AffinityDomain) const;
177 
186  template <typename Param>
187  typename detail::is_device_info_desc<Param>::return_type get_info() const;
188 
193  __SYCL2020_DEPRECATED("use device::has() function with aspects APIs instead")
194  bool has_extension(const std::string &extension_name) const;
195 
204  static std::vector<device>
205  get_devices(info::device_type deviceType = info::device_type::all);
206 
210  backend get_backend() const noexcept;
211 
218  bool has(aspect Aspect) const;
219 
220 private:
221  std::shared_ptr<detail::device_impl> impl;
222  device(std::shared_ptr<detail::device_impl> impl) : impl(impl) {}
223 
224  pi_native_handle getNative() const;
225 
226  template <class Obj>
227  friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
228 
229  template <class T>
230  friend
231  typename detail::add_pointer_t<typename decltype(T::impl)::element_type>
232  detail::getRawSyclObjImpl(const T &SyclObject);
233 
234  template <class T>
235  friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
236 
237  friend auto detail::getDeviceComparisonLambda();
238 
239  template <backend BackendName, class SyclObjectT>
240  friend auto get_native(const SyclObjectT &Obj)
241  -> backend_return_t<BackendName, SyclObjectT>;
242 };
243 
244 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
245 } // namespace sycl
246 
247 namespace std {
248 template <> struct hash<sycl::device> {
249  size_t operator()(const sycl::device &Device) const {
250  return hash<std::shared_ptr<sycl::detail::device_impl>>()(
252  }
253 };
254 } // namespace std
sycl::_V1::info::partition_affinity_domain
partition_affinity_domain
Definition: info_desc.hpp:61
aspects.hpp
sycl::_V1::backend
backend
Definition: backend_types.hpp:21
sycl::_V1::info::partition_property
partition_property
Definition: info_desc.hpp:54
stl.hpp
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:13
sycl::_V1::device::operator!=
bool operator!=(const device &rhs) const
Definition: device.hpp:81
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:13
sycl::_V1::detail::getRawSyclObjImpl
detail::add_pointer_t< typename decltype(T::impl)::element_type > getRawSyclObjImpl(const T &SyclObject)
Definition: common.hpp:250
backend_traits.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
device_selector
std::hash< sycl::device >::operator()
size_t operator()(const sycl::device &Device) const
Definition: device.hpp:249
sycl::_V1::device::operator==
bool operator==(const device &rhs) const
Definition: device.hpp:79
sycl::_V1::detail::select_device
device select_device(const DSelectorInvocableType &DeviceSelectorInvocable)
Definition: device_selector.cpp:115
Device
@ Device
Definition: usm_allocator.hpp:14
sycl::_V1::instead
std::uint8_t instead
Definition: aliases.hpp:69
common.hpp
sycl::_V1::device
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:47
sycl::_V1::detail::createSyclObjFromImpl
T createSyclObjFromImpl(decltype(T::impl) ImplObj)
Definition: common.hpp:258
sycl::_V1::info::device_type
device_type
Definition: info_desc.hpp:43
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:103
platform.hpp
std
Definition: accessor.hpp:3071
info_desc_helpers.hpp
sycl::_V1::ext::oneapi::experimental::matrix::use
use
Definition: matrix-jit-use.hpp:44
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
sycl::_V1::get_native
auto get_native(const SyclObjectT &Obj) -> backend_return_t< BackendName, SyclObjectT >
Definition: backend.hpp:123
__SYCL2020_DEPRECATED
#define __SYCL2020_DEPRECATED(message)
Definition: defines_elementary.hpp:54
sycl::_V1::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:240