DPC++ Runtime
Runtime libraries for oneAPI DPC++
platform.hpp
Go to the documentation of this file.
1 //==---------------- platform.hpp - SYCL platform --------------------------==//
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>
12 #include <sycl/context.hpp>
14 #include <sycl/detail/common.hpp>
15 #include <sycl/detail/export.hpp>
18 #include <sycl/device_selector.hpp>
20 #include <sycl/stl.hpp>
21 
22 // 4.6.2 Platform class
23 #include <utility>
24 namespace sycl {
26 // TODO: make code thread-safe
27 
28 // Forward declaration
29 class device_selector;
30 class device;
31 template <backend BackendName, class SyclObjectT>
32 auto get_native(const SyclObjectT &Obj)
33  -> backend_return_t<BackendName, SyclObjectT>;
34 namespace detail {
35 class platform_impl;
36 }
37 namespace ext::oneapi {
38 // Forward declaration
39 class filter_selector;
40 } // namespace ext::oneapi
41 
45 class __SYCL_EXPORT platform : public detail::OwnerLessBase<platform> {
46 public:
48  platform();
49 
56 #ifdef __SYCL_INTERNAL_API
57  explicit platform(cl_platform_id PlatformId);
58 #endif
59 
67  __SYCL2020_DEPRECATED("SYCL 1.2.1 device selectors are deprecated. Please "
68  "use SYCL 2020 device selectors instead.")
69  explicit platform(const device_selector &DeviceSelector);
70 
75  template <typename DeviceSelector,
76  typename =
78  explicit platform(const DeviceSelector &deviceSelector)
79  : platform(detail::select_device(deviceSelector)) {}
80 
81  platform(const platform &rhs) = default;
82 
83  platform(platform &&rhs) = default;
84 
85  platform &operator=(const platform &rhs) = default;
86 
87  platform &operator=(platform &&rhs) = default;
88 
89  bool operator==(const platform &rhs) const { return impl == rhs.impl; }
90 
91  bool operator!=(const platform &rhs) const { return !(*this == rhs); }
92 
96 #ifdef __SYCL_INTERNAL_API
97  cl_platform_id get() const;
98 #endif
99 
105  "use platform::has() function with aspects APIs instead")
106  bool has_extension(const std::string &ExtensionName) const;
107 
112  "is_host() is deprecated as the host device is no longer supported.")
113  bool is_host() const;
114 
123  std::vector<device>
124  get_devices(info::device_type DeviceType = info::device_type::all) const;
125 
129  template <typename Param>
130  typename detail::is_platform_info_desc<Param>::return_type get_info() const;
131 
137  static std::vector<platform> get_platforms();
138 
142  backend get_backend() const noexcept;
143 
144 // Clang may warn about the use of diagnose_if in __SYCL_WARN_IMAGE_ASPECT, so
145 // we disable that warning as we make appropriate checks to ensure its
146 // existence.
147 // TODO: Remove this diagnostics when __SYCL_WARN_IMAGE_ASPECT is removed.
148 #if defined(__clang__)
149 #pragma clang diagnostic push
150 #pragma clang diagnostic ignored "-Wgcc-compat"
151 #endif // defined(__clang__)
152 
161  bool has(aspect Aspect) const __SYCL_WARN_IMAGE_ASPECT(Aspect);
162 
163 // TODO: Remove this diagnostics when __SYCL_WARN_IMAGE_ASPECT is removed.
164 #if defined(__clang__)
165 #pragma clang diagnostic pop
166 #endif // defined(__clang__)
167 
171  context ext_oneapi_get_default_context() const;
172 
173 private:
174  pi_native_handle getNative() const;
175 
176  std::shared_ptr<detail::platform_impl> impl;
177  platform(std::shared_ptr<detail::platform_impl> impl) : impl(impl) {}
178 
179  platform(const device &Device);
180 
181  template <class T>
182  friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
183  template <class Obj>
184  friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
185 
186  template <backend BackendName, class SyclObjectT>
187  friend auto get_native(const SyclObjectT &Obj)
188  -> backend_return_t<BackendName, SyclObjectT>;
189 }; // class platform
190 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
191 } // namespace sycl
192 
193 namespace std {
194 template <> struct hash<sycl::platform> {
195  size_t operator()(const sycl::platform &p) const {
196  return hash<std::shared_ptr<sycl::detail::platform_impl>>()(
198  }
199 };
200 } // namespace std
sycl::_V1::__SYCL2020_DEPRECATED
signed char __SYCL2020_DEPRECATED
Definition: aliases.hpp:96
aspects.hpp
sycl::_V1::platform::operator==
bool operator==(const platform &rhs) const
Definition: platform.hpp:89
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
stl.hpp
device_selector.hpp
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:11
context.hpp
sycl::_V1::platform::platform
platform(const DeviceSelector &deviceSelector)
Constructs a SYCL platform instance using the platform of the device identified by the device selecto...
Definition: platform.hpp:78
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
backend_traits.hpp
owner_less_base.hpp
export.hpp
std::get
constexpr tuple_element< I, tuple< Types... > >::type & get(sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
__SYCL_WARN_IMAGE_ASPECT
#define __SYCL_WARN_IMAGE_ASPECT(aspect)
Definition: defines_elementary.hpp:71
sycl::_V1::ext::oneapi::experimental::operator=
annotated_arg & operator=(annotated_arg &)=default
device_selector
std::hash< sycl::platform >::operator()
size_t operator()(const sycl::platform &p) const
Definition: platform.hpp:195
sycl::_V1::detail::OwnerLessBase
Definition: owner_less_base.hpp:21
sycl::_V1::detail::select_device
device select_device(const DSelectorInvocableType &DeviceSelectorInvocable)
Definition: device_selector.cpp:137
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:320
sycl::_V1::platform::operator!=
bool operator!=(const platform &rhs) const
Definition: platform.hpp:91
sycl::_V1::access::target::device
@ device
sycl::_V1::info::device_type
device_type
Definition: info_desc.hpp:44
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:146
std
Definition: accessor.hpp:3910
info_desc_helpers.hpp
sycl::_V1::platform
Encapsulates a SYCL platform on which kernels may be executed.
Definition: platform.hpp:45
weak_object_base.hpp
sycl::_V1::get_native
auto get_native(const SyclObjectT &Obj) -> backend_return_t< BackendName, SyclObjectT >
Definition: backend.hpp:127
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:302
sycl::_V1::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:41