DPC++ Runtime
Runtime libraries for oneAPI DPC++
platform_impl.hpp
Go to the documentation of this file.
1 //==-------------- platform_impl.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 
12 #include <CL/sycl/detail/pi.hpp>
14 #include <CL/sycl/stl.hpp>
15 #include <detail/platform_info.hpp>
16 #include <detail/plugin.hpp>
17 
19 namespace sycl {
20 
21 // Forward declaration
22 class device_selector;
23 class device;
24 enum class aspect;
25 
26 namespace detail {
27 class device_impl;
28 
29 // TODO: implement extension management for host device
30 // TODO: implement parameters treatment for host device
32 public:
34  platform_impl() : MHostPlatform(true) {}
35 
41  explicit platform_impl(RT::PiPlatform APlatform, const plugin &APlugin)
42  : MPlatform(APlatform), MPlugin(std::make_shared<plugin>(APlugin)) {}
43 
44  explicit platform_impl(RT::PiPlatform APlatform,
45  std::shared_ptr<plugin> APlugin)
46  : MPlatform(APlatform), MPlugin(APlugin) {}
47 
48  ~platform_impl() = default;
49 
54  bool has_extension(const std::string &ExtensionName) const;
55 
65  std::vector<device>
66  get_devices(info::device_type DeviceType = info::device_type::all) const;
67 
71  template <info::platform param>
73  get_info() const;
74 
76  bool is_host() const { return MHostPlatform; };
77 
79  cl_platform_id get() const {
80  if (is_host()) {
81  throw invalid_object_error(
82  "This instance of platform doesn't support OpenCL interoperability.",
84  }
85  return pi::cast<cl_platform_id>(MPlatform);
86  }
87 
95  const RT::PiPlatform &getHandleRef() const {
96  if (is_host())
97  throw invalid_object_error("This instance of platform is a host instance",
99 
100  return MPlatform;
101  }
102 
110  static std::vector<platform> get_platforms();
111 
112  // \return the Plugin associated with this platform.
113  const plugin &getPlugin() const {
114  assert(!MHostPlatform && "Plugin is not available for Host.");
115  return *MPlugin;
116  }
117 
121  void setPlugin(std::shared_ptr<plugin> PluginPtr) {
122  assert(!MHostPlatform && "Plugin is not available for Host");
123  MPlugin = std::move(PluginPtr);
124  }
125 
129  pi_native_handle getNative() const;
130 
139  bool has(aspect Aspect) const;
140 
150  std::shared_ptr<device_impl>
151  getOrMakeDeviceImpl(RT::PiDevice PiDevice,
152  const std::shared_ptr<platform_impl> &PlatformImpl);
153 
156 
160  static std::shared_ptr<platform_impl> getHostPlatformImpl();
161 
169  static std::shared_ptr<platform_impl>
170  getOrMakePlatformImpl(RT::PiPlatform PiPlatform, const plugin &Plugin);
171 
181  static std::shared_ptr<platform_impl>
182  getPlatformFromPiDevice(RT::PiDevice PiDevice, const plugin &Plugin);
183 
184 private:
185  bool MHostPlatform = false;
186  RT::PiPlatform MPlatform = 0;
187  std::shared_ptr<plugin> MPlugin;
188  std::vector<std::weak_ptr<device_impl>> MDeviceCache;
189  std::mutex MDeviceMapMutex;
190 };
191 
192 } // namespace detail
193 } // namespace sycl
194 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::info::device
device
Definition: info_desc.hpp:53
cl::sycl::info::param_traits
Definition: info_desc.hpp:310
stl.hpp
cl::sycl::detail::pi::PiDevice
::pi_device PiDevice
Definition: pi.hpp:102
cl::sycl::info::device_type
device_type
Definition: info_desc.hpp:180
sycl
Definition: invoke_simd.hpp:68
plugin.hpp
_pi_platform
A PI platform stores all known PI devices, in the CUDA plugin this is just a vector of available devi...
Definition: pi_cuda.hpp:63
cl::sycl::detail::platform_impl::get
cl_platform_id get() const
Definition: platform_impl.hpp:79
cl::sycl::detail::platform_impl::is_host
bool is_host() const
Definition: platform_impl.hpp:76
pi.hpp
cl::sycl::detail::platform_impl::platform_impl
platform_impl(RT::PiPlatform APlatform, std::shared_ptr< plugin > APlugin)
Definition: platform_impl.hpp:44
cl::sycl::detail::platform_impl::setPlugin
void setPlugin(std::shared_ptr< plugin > PluginPtr)
Sets the platform implementation to use another plugin.
Definition: platform_impl.hpp:121
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::detail::platform_impl::platform_impl
platform_impl()
Constructs platform_impl for a SYCL host platform.
Definition: platform_impl.hpp:34
cl::sycl::aspect
aspect
Definition: aspects.hpp:15
cl::sycl::detail::platform_impl::platform_impl
platform_impl(RT::PiPlatform APlatform, const plugin &APlugin)
Constructs platform_impl from a plug-in interoperability platform handle.
Definition: platform_impl.hpp:41
platform_info.hpp
cl::sycl::detail::plugin
The plugin class provides a unified interface to the underlying low-level runtimes for the device-agn...
Definition: plugin.hpp:90
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:76
std
Definition: accessor.hpp:2616
cl::sycl::detail::platform_impl
Definition: platform_impl.hpp:31
PI_INVALID_PLATFORM
@ PI_INVALID_PLATFORM
Definition: pi.h:93
cl::sycl::all
detail::enable_if_t< detail::is_sigeninteger< T >::value, int > all(T x) __NOEXC
Definition: builtins.hpp:1297
info_desc.hpp
common.hpp
cl::sycl::detail::platform_impl::getHandleRef
const RT::PiPlatform & getHandleRef() const
Returns raw underlying plug-in platform handle.
Definition: platform_impl.hpp:95
cl::sycl::detail::pi::PiPlatform
::pi_platform PiPlatform
Definition: pi.hpp:101
cl::sycl::detail::platform_impl::getPlugin
const plugin & getPlugin() const
Definition: platform_impl.hpp:113
_pi_device
PI device mapping to a CUdevice.
Definition: pi_cuda.hpp:73
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12