-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathdpctl_sycl_platform_manager.cpp
More file actions
141 lines (125 loc) · 4.72 KB
/
Copy pathdpctl_sycl_platform_manager.cpp
File metadata and controls
141 lines (125 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//=== dpctl_sycl_platform_manager.cpp - Implements helpers for sycl::platform //
//
// Data Parallel Control (dpctl)
//
// Copyright 2021 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This file implements the functions declared in
/// dpctl_sycl_platform_manager.h.
///
//===----------------------------------------------------------------------===//
#include "dpctl_sycl_platform_manager.h"
#include "Config/dpctl_config.h"
#include "dpctl_error_handlers.h"
#include "dpctl_string_utils.hpp"
#include "dpctl_sycl_platform_interface.h"
#include "dpctl_sycl_type_casters.hpp"
#include "dpctl_utils_helper.h"
#include <iomanip>
#include <iostream>
#include <set>
#include <sstream>
#include <stddef.h>
#include <sycl/sycl.hpp>
using namespace sycl;
namespace
{
static_assert(__SYCL_COMPILER_VERSION >= __SYCL_COMPILER_VERSION_REQUIRED,
"The compiler does not meet minimum version requirement");
using namespace dpctl::syclinterface;
std::string platform_print_info_impl(const platform &p, size_t verbosity)
{
std::stringstream ss;
static constexpr const char *_endl = "\n";
if (verbosity > 2) {
error_handler("Illegal verbosity level. Accepted values are 0, 1, or 2."
"Defaulting to verbosity level 0.",
__FILE__, __func__, __LINE__);
verbosity = 0;
}
if (verbosity == 0)
ss << p.get_info<info::platform::name>() << " "
<< p.get_info<info::platform::version>() << _endl;
if (verbosity > 0) {
auto vendor = p.get_info<info::platform::vendor>();
if (vendor.empty())
vendor = "unknown";
ss << std::setw(4) << " " << std::left << std::setw(12) << "Name"
<< p.get_info<info::platform::name>() << _endl << std::setw(4) << " "
<< std::left << std::setw(12) << "Version"
<< p.get_info<info::platform::version>() << _endl << std::setw(4)
<< " " << std::left << std::setw(12) << "Vendor" << vendor << _endl
<< std::setw(4) << " " << std::left << std::setw(12) << "Backend";
ss << p.get_backend();
ss << _endl;
// Get number of devices on the platform
auto devices = p.get_devices();
ss << std::setw(4) << " " << std::left << std::setw(12) << "Num Devices"
<< devices.size() << _endl;
if (verbosity == 2)
// Print some of the device information
for (auto dn = 0ul; dn < devices.size(); ++dn) {
ss << std::setw(6) << " " << std::left << "# " << dn << _endl
<< std::setw(8) << " " << std::left << std::setw(20)
<< "Name" << devices[dn].get_info<info::device::name>()
<< _endl << std::setw(8) << " " << std::left << std::setw(20)
<< "Version"
<< devices[dn].get_info<info::device::driver_version>()
<< _endl << std::setw(8) << " " << std::left << std::setw(20)
<< "Filter string"
<< DPCTL_GetDeviceFilterString(devices[dn]) << _endl;
}
}
return ss.str();
}
} // namespace
#undef EL
#undef EL_SYCL_TYPE
#define EL Platform
#define EL_SYCL_TYPE sycl::platform
#include "dpctl_vector_templ.cpp"
#undef EL
#undef EL_SYCL_TYPE
void DPCTLPlatformMgr_PrintInfo(__dpctl_keep const DPCTLSyclPlatformRef PRef,
size_t verbosity)
{
auto p = unwrap<platform>(PRef);
if (p) {
std::cout << platform_print_info_impl(*p, verbosity);
}
else {
error_handler("Platform reference is NULL.", __FILE__, __func__,
__LINE__);
}
}
__dpctl_give const char *
DPCTLPlatformMgr_GetInfo(__dpctl_keep const DPCTLSyclPlatformRef PRef,
size_t verbosity)
{
const char *cstr_info = nullptr;
auto p = unwrap<platform>(PRef);
if (p) {
auto infostr = platform_print_info_impl(*p, verbosity);
cstr_info = dpctl::helper::cstring_from_string(infostr);
}
else {
error_handler("Platform reference is NULL.", __FILE__, __func__,
__LINE__);
}
return cstr_info;
}