DPC++ Runtime
Runtime libraries for oneAPI DPC++
platform_info.hpp
Go to the documentation of this file.
1 //==------ platform_info.hpp - SYCL platform info methods ------------------==//
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 #include <detail/plugin.hpp>
11 #include <sycl/detail/common.hpp>
14 #include <sycl/detail/pi.hpp>
15 #include <sycl/info/info_desc.hpp>
16 
17 namespace sycl {
19 namespace detail {
20 
22  const plugin &Plugin,
23  pi_platform_info PiCode) {
24  size_t ResultSize;
25  // TODO catch an exception and put it to list of asynchronous exceptions
26  Plugin.call<PiApiKind::piPlatformGetInfo>(Plt, PiCode, 0, nullptr,
27  &ResultSize);
28  if (ResultSize == 0) {
29  return "";
30  }
31  std::unique_ptr<char[]> Result(new char[ResultSize]);
32  // TODO catch an exception and put it to list of asynchronous exceptions
33  Plugin.call<PiApiKind::piPlatformGetInfo>(Plt, PiCode, ResultSize,
34  Result.get(), nullptr);
35  return Result.get();
36 }
37 // The platform information methods
38 template <typename Param>
39 typename std::enable_if<
40  std::is_same<typename Param::return_type, std::string>::value,
41  std::string>::type
44  "Invalid platform information descriptor");
45  return get_platform_info_string_impl(Plt, Plugin,
47 }
48 
49 template <typename Param>
50 typename std::enable_if<std::is_same<Param, info::platform::extensions>::value,
51  std::vector<std::string>>::type
54  "Invalid platform information descriptor");
55  std::string Result = get_platform_info_string_impl(
57  return split_string(Result, ' ');
58 }
59 
60 // Host platform information methods
61 template <typename Param>
62 inline typename Param::return_type get_platform_info_host() = delete;
63 
64 template <>
65 inline std::string get_platform_info_host<info::platform::profile>() {
66  return "FULL PROFILE";
67 }
68 
69 template <>
70 inline std::string get_platform_info_host<info::platform::version>() {
71  return "1.2";
72 }
73 
74 template <> inline std::string get_platform_info_host<info::platform::name>() {
75  return "SYCL host platform";
76 }
77 
78 template <>
79 inline std::string get_platform_info_host<info::platform::vendor>() {
80  return "";
81 }
82 
83 template <>
84 inline std::vector<std::string>
85 get_platform_info_host<info::platform::extensions>() {
86  // TODO update when appropriate
87  return {};
88 }
89 
90 } // namespace detail
91 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
92 } // namespace sycl
The plugin class provides a unified interface to the underlying low-level runtimes for the device-agn...
Definition: plugin.hpp:90
void call(ArgsT... Args) const
Calls the API, traces the call, checks the result.
Definition: plugin.hpp:217
#define __SYCL_INLINE_VER_NAMESPACE(X)
::pi_platform PiPlatform
Definition: pi.hpp:109
Param::return_type get_platform_info_host()=delete
std::string get_platform_info_string_impl(RT::PiPlatform Plt, const plugin &Plugin, pi_platform_info PiCode)
std::vector< std::string > split_string(const std::string &str, char delimeter)
Definition: common.cpp:33
std::enable_if< std::is_same< Param, info::platform::extensions >::value, std::vector< std::string > >::type get_platform_info(RT::PiPlatform Plt, const plugin &Plugin)
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
_pi_platform_info
Definition: pi.h:133
pi_result piPlatformGetInfo(pi_platform platform, pi_platform_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret)
C++ wrapper of extern "C" PI interfaces.