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 impl->getBackend(); }
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
sycl::_V1::backend
backend
Definition: backend_types.hpp:21
sycl::_V1::platform::get_platforms
static std::vector< platform > get_platforms()
Returns all available SYCL platforms in the system.
Definition: platform.cpp:53
sycl::_V1::detail::GlobalHandler::getPlatformToDefaultContextCacheMutex
std::mutex & getPlatformToDefaultContextCacheMutex()
Definition: global_handler.cpp:184
sycl::_V1::opencl::has_extension
bool has_extension(const sycl::platform &SyclPlatform, const std::string &Extension)
Definition: opencl.cpp:54
sycl::_V1::platform::platform
platform()
Constructs a SYCL platform using the default device.
Definition: platform.cpp:21
config.hpp
sycl::_V1::detail::platform_impl::get_platforms
static std::vector< platform > get_platforms()
Returns all available SYCL platforms in the system.
Definition: platform_impl.cpp:106
device_selector.hpp
device.hpp
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:11
sycl::_V1::detail::GlobalHandler::instance
static GlobalHandler & instance()
Definition: global_handler.cpp:125
sycl::_V1::detail::tie
auto tie(Ts &...Args)
Definition: tuple.hpp:40
sycl::_V1::detail::SYCLConfig
Definition: config.hpp:110
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
sycl::_V1::platform::ext_oneapi_get_default_context
context ext_oneapi_get_default_context() const
Return this platform's default context.
Definition: platform.cpp:76
sycl::_V1::platform::get_backend
backend get_backend() const noexcept
Returns the backend associated with this platform.
Definition: platform.cpp:57
sycl::_V1::default_selector_v
class __SYCL2020_DEPRECATED("Host device is no longer supported.") host_selector int default_selector_v(const device &dev)
Selects SYCL host device.
Definition: device_selector.cpp:179
std::get
constexpr tuple_element< I, tuple< Types... > >::type & get(sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
platform_impl.hpp
device_selector
sycl::_V1::detail::GlobalHandler::getPlatformToDefaultContextCache
std::unordered_map< PlatformImplPtr, ContextImplPtr > & getPlatformToDefaultContextCache()
Definition: global_handler.cpp:180
global_handler.hpp
sycl::_V1::info::device_type
device_type
Definition: info_desc.hpp:44
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:146
sycl::_V1::platform::has
bool has(aspect Aspect) const __SYCL_WARN_IMAGE_ASPECT(Aspect)
Indicates if all of the SYCL devices on this platform have the given feature.
Definition: platform.cpp:67
sycl::_V1::platform::get_devices
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
platform.hpp
sycl::_V1::detail::is_platform_info_desc
Definition: info_desc_helpers.hpp:19
backend_impl.hpp
info_desc.hpp
sycl::_V1::detail::platform_impl::getOrMakePlatformImpl
static std::shared_ptr< platform_impl > getOrMakePlatformImpl(RT::PiPlatform PiPlatform, const PluginPtr &Plugin)
Queries the cache to see if the specified PiPlatform has been seen before.
Definition: platform_impl.cpp:39
sycl::_V1::platform
Encapsulates a SYCL platform on which kernels may be executed.
Definition: platform.hpp:45
sycl::_V1::platform::get_info
detail::is_platform_info_desc< Param >::return_type get_info() const
Queries this SYCL platform for info.
Definition: platform.cpp:61
sycl::_V1::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:302
sycl::_V1::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:41