DPC++ Runtime
Runtime libraries for oneAPI DPC++
platform.cpp
Go to the documentation of this file.
1 //==----------- platform.cpp -----------------------------------------------==//
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 
10 #include <detail/config.hpp>
12 #include <detail/platform_impl.hpp>
13 #include <sycl/device.hpp>
14 #include <sycl/device_selector.hpp>
15 #include <sycl/info/info_desc.hpp>
16 #include <sycl/platform.hpp>
17 
18 namespace sycl {
20 
21 platform::platform() : platform(default_selector_v) {}
22 
23 platform::platform(cl_platform_id PlatformId) {
25  detail::pi::cast<detail::RT::PiPlatform>(PlatformId),
26  detail::RT::getPlugin<backend::opencl>());
27 }
28 
29 // protected constructor for internal use
30 platform::platform(const device &Device) { *this = Device.get_platform(); }
31 
32 platform::platform(const device_selector &dev_selector) {
33  *this = dev_selector.select_device().get_platform();
34 }
35 
36 cl_platform_id platform::get() const { return impl->get(); }
37 
38 bool platform::has_extension(const std::string &ExtensionName) const {
39  return impl->has_extension(ExtensionName);
40 }
41 
42 bool platform::is_host() const {
43  bool IsHost = impl->is_host();
44  assert(!IsHost &&
45  "platform::is_host should not be called in implementation.");
46  return IsHost;
47 }
48 
49 std::vector<device> platform::get_devices(info::device_type DeviceType) const {
50  return impl->get_devices(DeviceType);
51 }
52 
53 std::vector<platform> platform::get_platforms() {
55 }
56 
57 backend platform::get_backend() const noexcept { return getImplBackend(impl); }
58 
59 template <typename Param>
62  return impl->get_info<Param>();
63 }
64 
65 pi_native_handle platform::getNative() const { return impl->getNative(); }
66 
67 bool platform::has(aspect Aspect) const { return impl->has(Aspect); }
68 
69 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
70  template __SYCL_EXPORT ReturnT platform::get_info<info::platform::Desc>() \
71  const;
72 
73 #include <sycl/info/platform_traits.def>
74 #undef __SYCL_PARAM_TRAITS_SPEC
75 
78  throw std::runtime_error("SYCL default contexts are not enabled");
79 
80  // Keeping the default context for platforms in the global cache to avoid
81  // shared_ptr based circular dependency between platform and context classes
82  std::unordered_map<detail::PlatformImplPtr, detail::ContextImplPtr>
83  &PlatformToDefaultContextCache =
85 
86  std::lock_guard<std::mutex> Lock{
89 
90  auto It = PlatformToDefaultContextCache.find(impl);
91  if (PlatformToDefaultContextCache.end() == It)
92  std::tie(It, std::ignore) = PlatformToDefaultContextCache.insert(
94 
95  return detail::createSyclObjFromImpl<context>(It->second);
96 }
97 
98 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
99 } // namespace sycl
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:41
std::unordered_map< PlatformImplPtr, ContextImplPtr > & getPlatformToDefaultContextCache()
std::mutex & getPlatformToDefaultContextCacheMutex()
static GlobalHandler & instance()
static std::shared_ptr< platform_impl > getOrMakePlatformImpl(RT::PiPlatform PiPlatform, const plugin &Plugin)
Queries the cache to see if the specified PiPlatform has been seen before.
static std::vector< platform > get_platforms()
Returns all available SYCL platforms in the system.
Encapsulates a SYCL platform on which kernels may be executed.
Definition: platform.hpp:45
backend get_backend() const noexcept
Returns the backend associated with this platform.
Definition: platform.cpp:57
context ext_oneapi_get_default_context() const
Return this platform's default context.
Definition: platform.cpp:76
platform()
Constructs a SYCL platform using the default device.
Definition: platform.cpp:21
static std::vector< platform > get_platforms()
Returns all available SYCL platforms in the system.
Definition: platform.cpp:53
std::vector< device > get_devices(info::device_type DeviceType=info::device_type::all) const
Returns all SYCL devices associated with this platform.
Definition: platform.cpp:49
detail::is_platform_info_desc< Param >::return_type get_info() const
Queries this SYCL platform for info.
Definition: platform.cpp:61
bool has(aspect Aspect) const
Indicates if all of the SYCL devices on this platform have the given feature.
Definition: platform.cpp:67
#define __SYCL_INLINE_VER_NAMESPACE(X)
class __SYCL2020_DEPRECATED("Host device is no longer supported.") host_selector int default_selector_v(const device &dev)
Selects SYCL host device.
constexpr tuple_element< I, tuple< Types... > >::type & get(sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
backend getImplBackend(const T &Impl)
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:300
auto tie(Ts &...Args)
Definition: tuple.hpp:40
bool has_extension(const sycl::platform &SyclPlatform, const std::string &Extension)
Definition: opencl.cpp:54
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
uintptr_t pi_native_handle
Definition: pi.h:128
@ Device