DPC++ Runtime
Runtime libraries for oneAPI Data Parallel C++
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 <CL/sycl/aspects.hpp>
12 #include <CL/sycl/context.hpp>
15 #include <CL/sycl/stl.hpp>
16 
17 // 4.6.2 Platform class
18 #include <utility>
20 namespace sycl {
21 // TODO: make code thread-safe
22 
23 // Forward declaration
24 class device_selector;
25 class device;
26 namespace detail {
27 class platform_impl;
28 }
29 
33 class __SYCL_EXPORT platform {
34 public:
36  platform();
37 
44 #ifdef __SYCL_INTERNAL_API
45  explicit platform(cl_platform_id PlatformId);
46 #endif
47 
55  explicit platform(const device_selector &DeviceSelector);
56 
57  platform(const platform &rhs) = default;
58 
59  platform(platform &&rhs) = default;
60 
61  platform &operator=(const platform &rhs) = default;
62 
63  platform &operator=(platform &&rhs) = default;
64 
65  bool operator==(const platform &rhs) const { return impl == rhs.impl; }
66 
67  bool operator!=(const platform &rhs) const { return !(*this == rhs); }
68 
72 #ifdef __SYCL_INTERNAL_API
73  cl_platform_id get() const;
74 #endif
75 
81  "use platform::has() function with aspects APIs instead")
82  bool has_extension(const std::string &ExtensionName) const;
83 
87  bool is_host() const;
88 
97  std::vector<device>
98  get_devices(info::device_type DeviceType = info::device_type::all) const;
99 
103  template <info::platform param>
104  typename info::param_traits<info::platform, param>::return_type
105  get_info() const;
106 
112  static std::vector<platform> get_platforms();
113 
117  backend get_backend() const noexcept;
118 
122  template <backend BackendName>
123  __SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function")
124  auto get_native() const -> typename interop<BackendName, platform>::type {
125  return reinterpret_cast<typename interop<BackendName, platform>::type>(
126  getNative());
127  }
128 
137  bool has(aspect Aspect) const;
138 
142  context ext_oneapi_get_default_context() const;
143 
144 private:
145  pi_native_handle getNative() const;
146 
147  std::shared_ptr<detail::platform_impl> impl;
148  platform(std::shared_ptr<detail::platform_impl> impl) : impl(impl) {}
149 
150  template <class T>
151  friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
152  template <class Obj>
153  friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
154 
155 }; // class platform
156 } // namespace sycl
157 } // __SYCL_INLINE_NAMESPACE(cl)
158 
159 namespace std {
160 template <> struct hash<cl::sycl::platform> {
161  size_t operator()(const cl::sycl::platform &p) const {
162  return hash<std::shared_ptr<cl::sycl::detail::platform_impl>>()(
164  }
165 };
166 } // namespace std
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
type
cl::sycl::info::device
device
Definition: info_desc.hpp:49
__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:69
stl.hpp
cl::sycl::detail::createSyclObjFromImpl
T createSyclObjFromImpl(decltype(T::impl) ImplObj)
Definition: common.hpp:199
cl::sycl::platform::operator==
bool operator==(const platform &rhs) const
Definition: platform.hpp:65
__SYCL_DEPRECATED
#define __SYCL_DEPRECATED(message)
Definition: defines_elementary.hpp:47
context.hpp
cl::sycl::info::device_type
device_type
Definition: info_desc.hpp:170
export.hpp
cl::sycl::device
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:34
cl::sycl::platform::operator!=
bool operator!=(const platform &rhs) const
Definition: platform.hpp:67
cl::sycl::detail::usm::free
void free(void *Ptr, const context &Ctxt)
Definition: usm_impl.cpp:132
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::interop
Definition: backend_types.hpp:35
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::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:182
cl::sycl::platform
Encapsulates a SYCL platform on which kernels may be executed.
Definition: platform.hpp:33
std
Definition: accessor.hpp:2358
std::hash< cl::sycl::platform >::operator()
size_t operator()(const cl::sycl::platform &p) const
Definition: platform.hpp:161
cl::sycl::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:35
cl::sycl::all
detail::enable_if_t< detail::is_sigeninteger< T >::value, int > all(T x) __NOEXC
Definition: builtins.hpp:1282
common.hpp
cl::sycl::info::platform
platform
Definition: info_desc.hpp:29
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12