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/ur.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 get_platform_info_string_impl(ur_platform_handle_t Plt,
23  const PluginPtr &Plugin,
24  ur_platform_info_t UrCode) {
25  size_t ResultSize = 0;
26  // TODO catch an exception and put it to list of asynchronous exceptions
27  Plugin->call<UrApiKind::urPlatformGetInfo>(Plt, UrCode, 0, nullptr,
28  &ResultSize);
29  if (ResultSize == 0) {
30  return "";
31  }
32  std::unique_ptr<char[]> Result(new char[ResultSize]);
33  // TODO catch an exception and put it to list of asynchronous exceptions
34  Plugin->call<UrApiKind::urPlatformGetInfo>(Plt, UrCode, ResultSize,
35  Result.get(), nullptr);
36  return Result.get();
37 }
38 // The platform information methods
39 template <typename Param>
40 typename std::enable_if<
41  std::is_same<typename Param::return_type, std::string>::value,
42  std::string>::type
43 get_platform_info(ur_platform_handle_t Plt, const PluginPtr &Plugin) {
45  "Invalid platform information descriptor");
46  return get_platform_info_string_impl(Plt, Plugin,
48 }
49 
50 template <typename Param>
51 typename std::enable_if<std::is_same<Param, info::platform::extensions>::value,
52  std::vector<std::string>>::type
53 get_platform_info(ur_platform_handle_t Plt, const PluginPtr &Plugin) {
55  "Invalid platform information descriptor");
56  std::string Result = get_platform_info_string_impl(
58  return split_string(Result, ' ');
59 }
60 
61 } // namespace detail
62 } // namespace _V1
63 } // namespace sycl
std::enable_if< std::is_same< typename Param::return_type, std::string >::value, std::string >::type get_platform_info(ur_platform_handle_t Plt, const PluginPtr &Plugin)
std::string get_platform_info_string_impl(ur_platform_handle_t Plt, const PluginPtr &Plugin, ur_platform_info_t UrCode)
std::vector< std::string > split_string(std::string_view str, char delimeter)
std::shared_ptr< plugin > PluginPtr
Definition: ur.hpp:107
Definition: access.hpp:18
C++ utilities for Unified Runtime integration.