-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmi.cpp
More file actions
170 lines (144 loc) · 5.54 KB
/
smi.cpp
File metadata and controls
170 lines (144 loc) · 5.54 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved.
#define XRT_CORE_COMMON_SOURCE
// Local - Include Files
#include "smi.h"
// 3rd Party Library - Include Files
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <string>
#include <vector>
namespace xrt_core::smi {
using boost::property_tree::ptree;
ptree
option::
to_ptree() const
{
boost::property_tree::ptree pt;
pt.put("name", name);
pt.put("description", description);
pt.put("type", type);
pt.put("alias", alias);
pt.put("default_value", default_value);
pt.put("value_type", value_type);
if (!description_array.empty()) {
boost::property_tree::ptree description_array_ptree;
for (const auto& desc : description_array) {
boost::property_tree::ptree desc_node;
desc_node.put("name", desc.name);
desc_node.put("description", desc.description);
desc_node.put("type", desc.type);
description_array_ptree.push_back(std::make_pair("", desc_node));
}
pt.add_child("description_array", description_array_ptree);
}
return pt;
}
smi_base::
smi_base() :
examine_report_desc {
{"host", "Host information", "common"}
},
configure_options {
{"device", "d", "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", "common", "", "string"},
{"help", "h", "Help to use this sub-command", "common", "", "none"}
}
{}
std::vector<basic_option>
smi_base::
construct_option_description(const tuple_vector& vec) const
{
std::vector<basic_option> option_descriptions;
for (const auto& [name, description, type] : vec) {
option_descriptions.push_back({name, description, type});
}
return option_descriptions;
}
ptree
smi_base::
construct_validate_subcommand() const
{
ptree subcommand;
subcommand.put("name", "validate");
subcommand.put("description", "Validates the given device by executing the platform's validate executable.");
subcommand.put("type", "common");
std::vector<option> options = {
{"device", "d", "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", "common", "", "string"},
{"format", "f", "Report output format. Valid values are:\n"
"\tJSON - Latest JSON schema\n"
"\tJSON-2020.2 - JSON 2020.2 schema", "common", "JSON", "string"},
{"output", "o", "Direct the output to the given file", "common", "", "string"},
{"help", "h", "Help to use this sub-command", "common", "", "none"},
{"run", "r", "Run a subset of the test suite. Valid options are:\n", "common", "", "array", construct_option_description(validate_test_desc)},
{"path", "p", "Path to the directory containing validate xclbins", "hidden", "", "string"},
{"param", "", "Extended parameter for a given test. Format: <test-name>:<key>:<value>", "hidden", "", "string"},
{"pmode", "", "Specify which power mode to run the benchmarks in. Note: Some tests might be unavailable for some modes", "hidden", "", "string"}
};
ptree options_ptree;
for (const auto& option : options) {
options_ptree.push_back(std::make_pair("", option.to_ptree()));
}
subcommand.add_child("options", options_ptree);
return subcommand;
}
ptree
smi_base::
construct_examine_subcommand() const
{
ptree subcommand;
subcommand.put("name", "examine");
subcommand.put("type", "common");
subcommand.put("description", "This command will 'examine' the state of the system/device and will generate a report of interest in a text or JSON format.");
std::vector<option> options = {
{"device", "d", "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", "common", "", "string"},
{"format", "f", "Report output format. Valid values are:\n"
"\tJSON - Latest JSON schema\n"
"\tJSON-2020.2 - JSON 2020.2 schema", "common", "", "string"},
{"output", "o", "Direct the output to the given file", "common", "", "string"},
{"help", "h", "Help to use this sub-command", "common", "", "none"},
{"report", "r", "The type of report to be produced. Reports currently available are:\n", "common", "", "array", construct_option_description(examine_report_desc)},
{"element", "e", "Filters individual elements(s) from the report. Format: '/<key>/<key>/...'", "hidden", "", "array"}
};
ptree options_ptree;
for (const auto& option : options) {
options_ptree.push_back(std::make_pair("", option.to_ptree()));
}
subcommand.add_child("options", options_ptree);
return subcommand;
}
ptree
smi_base::
construct_configure_subcommand() const
{
ptree subcommand;
subcommand.put("name", "configure");
subcommand.put("type", "common");
subcommand.put("description", "Device and host configuration");
ptree options_ptree;
for (const auto& option : configure_options) {
options_ptree.push_back(std::make_pair("", option.to_ptree()));
}
subcommand.add_child("options", options_ptree);
return subcommand;
}
std::string
smi_base::
get_smi_config() const
{
ptree config;
ptree subcommands;
subcommands.push_back(std::make_pair("", construct_validate_subcommand()));
subcommands.push_back(std::make_pair("", construct_examine_subcommand()));
subcommands.push_back(std::make_pair("", construct_configure_subcommand()));
config.add_child("subcommands", subcommands);
std::ostringstream oss;
boost::property_tree::write_json(oss, config, true); // Pretty print with true
return oss.str();
}
std::string
get_smi_config()
{
xrt_core::smi::smi_base instance;
return instance.get_smi_config();
}
} // namespace xrt_core::smi