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(urPlatformGetInfo, Plt, UrCode, 0, nullptr, &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(urPlatformGetInfo, Plt, UrCode, ResultSize, Result.get(),
34  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
42 get_platform_info(ur_platform_handle_t Plt, const PluginPtr &Plugin) {
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
52 get_platform_info(ur_platform_handle_t Plt, const PluginPtr &Plugin) {
54  "Invalid platform information descriptor");
55  std::string Result = get_platform_info_string_impl(
57  return split_string(Result, ' ');
58 }
59 
60 } // namespace detail
61 } // namespace _V1
62 } // 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:60
Definition: access.hpp:18
C++ utilities for Unified Runtime integration.