DPC++ Runtime
Runtime libraries for oneAPI Data Parallel C++
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 
9 #include <CL/sycl/device.hpp>
12 #include <CL/sycl/platform.hpp>
13 #include <detail/backend_impl.hpp>
14 #include <detail/config.hpp>
15 #include <detail/force_device.hpp>
17 #include <detail/platform_impl.hpp>
18 
20 namespace sycl {
21 
22 platform::platform() : impl(detail::platform_impl::getHostPlatformImpl()) {}
23 
24 platform::platform(cl_platform_id PlatformId) {
26  detail::pi::cast<detail::RT::PiPlatform>(PlatformId),
27  detail::RT::getPlugin<backend::opencl>());
28 }
29 
30 platform::platform(const device_selector &dev_selector) {
31  *this = dev_selector.select_device().get_platform();
32 }
33 
34 cl_platform_id platform::get() const { return impl->get(); }
35 
36 bool platform::has_extension(const std::string &ExtensionName) const {
37  return impl->has_extension(ExtensionName);
38 }
39 
40 bool platform::is_host() const { return impl->is_host(); }
41 
42 std::vector<device> platform::get_devices(info::device_type DeviceType) const {
43  return impl->get_devices(DeviceType);
44 }
45 
46 std::vector<platform> platform::get_platforms() {
48 }
49 
50 backend platform::get_backend() const noexcept { return getImplBackend(impl); }
51 
52 template <info::platform param>
55  return impl->get_info<param>();
56 }
57 
58 pi_native_handle platform::getNative() const { return impl->getNative(); }
59 
60 bool platform::has(aspect Aspect) const { return impl->has(Aspect); }
61 
62 #define __SYCL_PARAM_TRAITS_SPEC(param_type, param, ret_type) \
63  template __SYCL_EXPORT ret_type \
64  platform::get_info<info::param_type::param>() const;
65 
66 #include <CL/sycl/info/platform_traits.def>
67 
68 #undef __SYCL_PARAM_TRAITS_SPEC
69 
72  throw std::runtime_error("SYCL default contexts are not enabled");
73 
74  // Keeping the default context for platforms in the global cache to avoid
75  // shared_ptr based circular dependency between platform and context classes
76  std::unordered_map<detail::PlatformImplPtr, detail::ContextImplPtr>
77  &PlatformToDefaultContextCache =
79 
80  std::lock_guard Lock{detail::GlobalHandler::instance()
82 
83  auto It = PlatformToDefaultContextCache.find(impl);
84  if (PlatformToDefaultContextCache.end() == It)
85  std::tie(It, std::ignore) = PlatformToDefaultContextCache.insert(
87 
88  return detail::createSyclObjFromImpl<context>(It->second);
89 }
90 
91 } // namespace sycl
92 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::backend
backend
Definition: backend_types.hpp:21
cl::sycl::platform::ext_oneapi_get_default_context
context ext_oneapi_get_default_context() const
Return this platform's default context.
Definition: platform.cpp:70
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::detail::GlobalHandler::instance
static GlobalHandler & instance()
Definition: global_handler.cpp:33
cl::sycl::device_selector::select_device
virtual device select_device() const
Definition: device_selector.cpp:65
cl::sycl::info::param_traits
Definition: info_desc.hpp:297
config.hpp
device_selector.hpp
device.hpp
cl::sycl::detail::SYCLConfig
Definition: config.hpp:104
cl::sycl::device::get_platform
platform get_platform() const
Get associated SYCL platform.
Definition: device.cpp:110
cl::sycl::platform::get_info
info::param_traits< info::platform, param >::return_type get_info() const
Queries this SYCL platform for info.
Definition: platform.cpp:54
cl::sycl::info::device_type
device_type
Definition: info_desc.hpp:170
cl::sycl::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:42
cl::sycl::detail::platform_impl::getOrMakePlatformImpl
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.
Definition: platform_impl.cpp:36
cl::sycl::detail::getImplBackend
backend getImplBackend(const T &Impl)
Definition: backend_impl.hpp:16
cl::sycl::detail::platform_impl::get_platforms
static std::vector< platform > get_platforms()
Returns all available SYCL platforms in the system.
Definition: platform_impl.cpp:96
platform_impl.hpp
cl::sycl::platform::platform
platform()
Constructs a SYCL platform as a host platform.
Definition: platform.cpp:22
force_device.hpp
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::platform::get_platforms
static std::vector< platform > get_platforms()
Returns all available SYCL platforms in the system.
Definition: platform.cpp:46
global_handler.hpp
cl::sycl::detail::tie
auto tie(Ts &... Args)
Definition: tuple.hpp:40
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::GlobalHandler::getPlatformToDefaultContextCache
std::unordered_map< PlatformImplPtr, ContextImplPtr > & getPlatformToDefaultContextCache()
Definition: global_handler.cpp:55
cl::sycl::detail::getSyclObjImpl
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: common.hpp:182
platform.hpp
cl::sycl::detail::platform_impl
Definition: platform_impl.hpp:31
cl::sycl::detail::GlobalHandler::getPlatformToDefaultContextCacheMutex
std::mutex & getPlatformToDefaultContextCacheMutex()
Definition: global_handler.cpp:59
cl::sycl::platform::get_backend
backend get_backend() const noexcept
Returns the backend associated with this platform.
Definition: platform.cpp:50
cl::sycl::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:35
backend_impl.hpp
info_desc.hpp
cl::sycl::platform::has
bool has(aspect Aspect) const
Indicates if all of the SYCL devices on this platform have the given feature.
Definition: platform.cpp:60
cl::sycl::info::platform
platform
Definition: info_desc.hpp:29
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12