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 =
77  detail::EnableIfSYCL2020DeviceSelectorInvocable<DeviceSelector>>
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 
111  __SYCL2020_DEPRECATED(
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 
152  bool has(aspect Aspect) const;
153 
157  context ext_oneapi_get_default_context() const;
158 
159 private:
160  pi_native_handle getNative() const;
161 
162  std::shared_ptr<detail::platform_impl> impl;
163  platform(std::shared_ptr<detail::platform_impl> impl) : impl(impl) {}
164 
165  platform(const device &Device);
166 
167  template <class T>
168  friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
169  template <class Obj>
170  friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
171 
172  template <backend BackendName, class SyclObjectT>
173  friend auto get_native(const SyclObjectT &Obj)
175 }; // class platform
176 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
177 } // namespace sycl
178 
179 namespace std {
180 template <> struct hash<sycl::platform> {
181  size_t operator()(const sycl::platform &p) const {
182  return hash<std::shared_ptr<sycl::detail::platform_impl>>()(
184  }
185 };
186 } // namespace std
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:41
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:49
Encapsulates a SYCL platform on which kernels may be executed.
Definition: platform.hpp:45
platform & operator=(platform &&rhs)=default
platform & operator=(const platform &rhs)=default
bool operator!=(const platform &rhs) const
Definition: platform.hpp:91
platform(const platform &rhs)=default
platform(platform &&rhs)=default
bool operator==(const platform &rhs) const
Definition: platform.hpp:89
__SYCL2020_DEPRECATED("SYCL 1.2.1 device selectors are deprecated. Please " "use SYCL 2020 device selectors instead.") explicit platform(const device_selector &DeviceSelector)
Constructs a SYCL platform instance from an OpenCL cl_platform_id.
#define __SYCL_INLINE_VER_NAMESPACE(X)
#define __SYCL2020_DEPRECATED(message)
constexpr tuple_element< I, tuple< Types... > >::type & get(sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:300
T createSyclObjFromImpl(decltype(T::impl) ImplObj)
Definition: common.hpp:318
device select_device(const DSelectorInvocableType &DeviceSelectorInvocable)
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
bool has_extension(const sycl::platform &SyclPlatform, const std::string &Extension)
Definition: opencl.cpp:54
auto get_native(const SyclObjectT &Obj) -> backend_return_t< BackendName, SyclObjectT >
Definition: backend.hpp:123
typename backend_traits< Backend >::template return_type< SyclType > backend_return_t
Definition: backend.hpp:72
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
uintptr_t pi_native_handle
Definition: pi.h:128
@ Device
size_t operator()(const sycl::platform &p) const
Definition: platform.hpp:181