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>
13 #include <sycl/detail/pi.hpp>
14 #include <sycl/info/info_desc.hpp>
15 
16 #include "split_string.hpp"
17 
18 namespace sycl {
19 inline namespace _V1 {
20 namespace detail {
21 
22 inline std::string
24  const PluginPtr &Plugin,
25  pi_platform_info PiCode) {
26  size_t ResultSize;
27  // TODO catch an exception and put it to list of asynchronous exceptions
28  Plugin->call<PiApiKind::piPlatformGetInfo>(Plt, PiCode, 0, nullptr,
29  &ResultSize);
30  if (ResultSize == 0) {
31  return "";
32  }
33  std::unique_ptr<char[]> Result(new char[ResultSize]);
34  // TODO catch an exception and put it to list of asynchronous exceptions
35  Plugin->call<PiApiKind::piPlatformGetInfo>(Plt, PiCode, ResultSize,
36  Result.get(), nullptr);
37  return Result.get();
38 }
39 // The platform information methods
40 template <typename Param>
41 typename std::enable_if<
42  std::is_same<typename Param::return_type, std::string>::value,
43  std::string>::type
46  "Invalid platform information descriptor");
47  return get_platform_info_string_impl(Plt, Plugin,
49 }
50 
51 template <typename Param>
52 typename std::enable_if<std::is_same<Param, info::platform::extensions>::value,
53  std::vector<std::string>>::type
56  "Invalid platform information descriptor");
57  std::string Result = get_platform_info_string_impl(
59  return split_string(Result, ' ');
60 }
61 
62 // Host platform information methods
63 template <typename Param>
64 inline typename Param::return_type get_platform_info_host() = delete;
65 
66 template <>
67 inline std::string get_platform_info_host<info::platform::profile>() {
68  return "FULL PROFILE";
69 }
70 
71 template <>
72 inline std::string get_platform_info_host<info::platform::version>() {
73  return "1.2";
74 }
75 
76 template <> inline std::string get_platform_info_host<info::platform::name>() {
77  return "SYCL host platform";
78 }
79 
80 template <>
81 inline std::string get_platform_info_host<info::platform::vendor>() {
82  return "";
83 }
84 
85 template <>
86 inline std::vector<std::string>
87 get_platform_info_host<info::platform::extensions>() {
88  // TODO update when appropriate
89  return {};
90 }
91 
92 } // namespace detail
93 } // namespace _V1
94 } // namespace sycl
Param::return_type get_platform_info_host()=delete
std::enable_if< std::is_same< typename Param::return_type, std::string >::value, std::string >::type get_platform_info(sycl::detail::pi::PiPlatform Plt, const PluginPtr &Plugin)
std::string get_platform_info_string_impl(sycl::detail::pi::PiPlatform Plt, const PluginPtr &Plugin, pi_platform_info PiCode)
std::vector< std::string > split_string(std::string_view str, char delimeter)
std::shared_ptr< plugin > PluginPtr
Definition: pi.hpp:48
Definition: access.hpp:18
_pi_platform_info
Definition: pi.h:239
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)
Definition: pi_cuda.cpp:35
C++ wrapper of extern "C" PI interfaces.