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 <CL/sycl/aspects.hpp>
12 #include <CL/sycl/context.hpp>
16 #include <CL/sycl/stl.hpp>
17 
18 // 4.6.2 Platform class
19 #include <utility>
21 namespace sycl {
22 // TODO: make code thread-safe
23 
24 // Forward declaration
25 class device_selector;
26 class device;
27 namespace detail {
28 class platform_impl;
29 }
30 
34 class __SYCL_EXPORT platform {
35 public:
37  platform();
38 
45 #ifdef __SYCL_INTERNAL_API
46  explicit platform(cl_platform_id PlatformId);
47 #endif
48 
56  explicit platform(const device_selector &DeviceSelector);
57 
58  platform(const platform &rhs) = default;
59 
60  platform(platform &&rhs) = default;
61 
62  platform &operator=(const platform &rhs) = default;
63 
64  platform &operator=(platform &&rhs) = default;
65 
66  bool operator==(const platform &rhs) const { return impl == rhs.impl; }
67 
68  bool operator!=(const platform &rhs) const { return !(*this == rhs); }
69 
73 #ifdef __SYCL_INTERNAL_API
74  cl_platform_id get() const;
75 #endif
76 
82  "use platform::has() function with aspects APIs instead")
83  bool has_extension(const std::string &ExtensionName) const;
84 
88  bool is_host() const;
89 
98  std::vector<device>
99  get_devices(info::device_type DeviceType = info::device_type::all) const;
100 
104  template <info::platform param>
105  typename info::param_traits<info::platform, param>::return_type
106  get_info() const;
107 
113  static std::vector<platform> get_platforms();
114 
118  backend get_backend() const noexcept;
119 
123  template <backend Backend>
124  __SYCL_DEPRECATED("Use SYCL 2020 sycl::get_native free function")
126  return reinterpret_cast<backend_return_t<Backend, platform>>(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
cl::sycl::backend_return_t
typename backend_traits< Backend >::template return_type< SyclType > backend_return_t
Definition: backend.hpp:68
cl::sycl::info::device
device
Definition: info_desc.hpp:53
__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:119
stl.hpp
cl::sycl::detail::createSyclObjFromImpl
T createSyclObjFromImpl(decltype(T::impl) ImplObj)
Definition: common.hpp:221
cl::sycl::platform::operator==
bool operator==(const platform &rhs) const
Definition: platform.hpp:66
__SYCL_DEPRECATED
#define __SYCL_DEPRECATED(message)
Definition: defines_elementary.hpp:47
context.hpp
sycl
Definition: invoke_simd.hpp:68
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::platform::operator!=
bool operator!=(const platform &rhs) const
Definition: platform.hpp:68
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:76
std::get
constexpr tuple_element< I, tuple< Types... > >::type & get(cl::sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
cl::sycl::detail::usm::free
void free(void *Ptr, const context &Ctxt, const code_location &CL)
Definition: usm_impl.cpp:181
cl::sycl::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:204
cl::sycl::platform
Encapsulates a SYCL platform on which kernels may be executed.
Definition: platform.hpp:34
std
Definition: accessor.hpp:2616
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
common.hpp
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12