DPC++ Runtime
Runtime libraries for oneAPI Data Parallel C++
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 <CL/sycl/aspects.hpp>
16 #include <CL/sycl/platform.hpp>
17 #include <CL/sycl/stl.hpp>
18 
19 #include <memory>
20 #include <utility>
21 
23 namespace sycl {
24 // Forward declarations
25 class device_selector;
26 namespace detail {
27 class device_impl;
29 }
30 
35 class __SYCL_EXPORT device {
36 public:
38  device();
39 
44 #ifdef __SYCL_INTERNAL_API
45  explicit device(cl_device_id DeviceId);
46 #endif
47 
52  explicit device(const device_selector &DeviceSelector);
53 
54  bool operator==(const device &rhs) const { return impl == rhs.impl; }
55 
56  bool operator!=(const device &rhs) const { return !(*this == rhs); }
57 
58  device(const device &rhs) = default;
59 
60  device(device &&rhs) = default;
61 
62  device &operator=(const device &rhs) = default;
63 
64  device &operator=(device &&rhs) = default;
65 
70 #ifdef __SYCL_INTERNAL_API
71  cl_device_id get() const;
72 #endif
73 
77  bool is_host() const;
78 
82  bool is_cpu() const;
83 
87  bool is_gpu() const;
88 
92  bool is_accelerator() const;
93 
104  platform get_platform() const;
105 
117  template <info::partition_property prop>
118  std::vector<device> create_sub_devices(size_t ComputeUnits) const;
119 
130  template <info::partition_property prop>
131  std::vector<device>
132  create_sub_devices(const std::vector<size_t> &Counts) const;
133 
147  template <info::partition_property prop>
148  std::vector<device>
149  create_sub_devices(info::partition_affinity_domain AffinityDomain) const;
150 
159  template <info::device param>
161  get_info() const;
162 
167  __SYCL2020_DEPRECATED("use device::has() function with aspects APIs instead")
168  bool has_extension(const std::string &extension_name) const;
169 
178  static std::vector<device>
179  get_devices(info::device_type deviceType = info::device_type::all);
180 
184  backend get_backend() const noexcept;
185 
189  template <backend Backend>
190  __SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function")
191  backend_return_t<Backend, device> get_native() const {
192  // In CUDA CUdevice isn't an opaque pointer, unlike a lot of the others,
193  // but instead a 32-bit int (on all relevant systems). Different
194  // backends use the same function for this purpose so static_cast is
195  // needed in some cases but not others, so a C-style cast was chosen.
196  return (backend_return_t<Backend, device>)getNative();
197  }
198 
205  bool has(aspect Aspect) const;
206 
207 private:
208  std::shared_ptr<detail::device_impl> impl;
209  device(std::shared_ptr<detail::device_impl> impl) : impl(impl) {}
210 
211  pi_native_handle getNative() const;
212 
213  template <class Obj>
214  friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
215 
216  template <class T>
217  friend
218  typename detail::add_pointer_t<typename decltype(T::impl)::element_type>
219  detail::getRawSyclObjImpl(const T &SyclObject);
220 
221  template <class T>
222  friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
223 
224  friend auto detail::getDeviceComparisonLambda();
225 };
226 
227 } // namespace sycl
228 } // __SYCL_INLINE_NAMESPACE(cl)
229 
230 namespace std {
231 template <> struct hash<cl::sycl::device> {
232  size_t operator()(const cl::sycl::device &Device) const {
233  return hash<std::shared_ptr<cl::sycl::detail::device_impl>>()(
235  }
236 };
237 } // namespace std
cl::sycl::detail::getRawSyclObjImpl
detail::add_pointer_t< typename decltype(T::impl)::element_type > getRawSyclObjImpl(const T &SyclObject)
Definition: common.hpp:207
aspects.hpp
cl::sycl::backend
backend
Definition: backend_types.hpp:21
cl::sycl::device_selector
The device_selector class provides ability to choose the best SYCL device based on heuristics specifi...
Definition: device_selector.hpp:28
cl::sycl::device::operator==
bool operator==(const device &rhs) const
Definition: device.hpp:54
cl::sycl::backend_return_t
typename backend_traits< Backend >::template return_type< SyclType > backend_return_t
Definition: backend.hpp:65
cl::sycl::info::device
device
Definition: info_desc.hpp:50
cl::sycl::info::param_traits
Definition: info_desc.hpp:300
__SYCL2020_DEPRECATED
#define __SYCL2020_DEPRECATED(message)
Definition: defines_elementary.hpp:56
cl::sycl::get_native
auto get_native(const SyclObjectT &Obj) -> backend_return_t< BackendName, SyclObjectT >
Definition: backend.hpp:68
cl::sycl::device::operator!=
bool operator!=(const device &rhs) const
Definition: device.hpp:56
stl.hpp
cl::sycl::detail::createSyclObjFromImpl
T createSyclObjFromImpl(decltype(T::impl) ImplObj)
Definition: common.hpp:215
__SYCL_DEPRECATED
#define __SYCL_DEPRECATED(message)
Definition: defines_elementary.hpp:47
cl::sycl::info::device_type
device_type
Definition: info_desc.hpp:173
backend_traits.hpp
export.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::usm::free
void free(void *Ptr, const context &Ctxt)
Definition: usm_impl.cpp:132
std::hash< cl::sycl::device >::operator()
size_t operator()(const cl::sycl::device &Device) const
Definition: device.hpp:232
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::aspect
aspect
Definition: aspects.hpp:15
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:72
std::get
constexpr tuple_element< I, tuple< Types... > >::type & get(cl::sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
cl::sycl::detail::add_pointer_t
typename std::add_pointer< T >::type add_pointer_t
Definition: stl_type_traits.hpp:37
cl::sycl::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:198
platform.hpp
cl::sycl::platform
Encapsulates a SYCL platform on which kernels may be executed.
Definition: platform.hpp:34
std
Definition: accessor.hpp:2397
cl::sycl::all
detail::enable_if_t< detail::is_sigeninteger< T >::value, int > all(T x) __NOEXC
Definition: builtins.hpp:1282
info_desc.hpp
common.hpp
cl::sycl::detail::getDeviceComparisonLambda
auto getDeviceComparisonLambda()
Definition: kernel_bundle.hpp:380
cl::sycl::info::partition_affinity_domain
partition_affinity_domain
Definition: info_desc.hpp:191
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12