Skip to content

Commit b2fb6f3

Browse files
authored
xrt-smi code cleanup (Xilinx#9765)
* xrt-smi code cleanup Signed-off-by: Akshay Tondak <aktondak@amd.com> * Namespace change and xdp update Signed-off-by: Akshay Tondak <aktondak@amd.com> * Adding alveo object to yocto builds Signed-off-by: Akshay Tondak <aktondak@amd.com> --------- Signed-off-by: Akshay Tondak <aktondak@amd.com>
1 parent 25abe9e commit b2fb6f3

28 files changed

Lines changed: 296 additions & 175 deletions

src/runtime_src/core/common/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ endif()
88
add_subdirectory(api)
99
add_subdirectory(xdp)
1010
add_subdirectory(runner)
11+
add_subdirectory(smi)
1112

1213
if(CMAKE_VERSION VERSION_LESS "3.18.0")
1314
message(WARNING "CMake version is less than 3.18.0, build of submodule aiebu disabled")
@@ -51,7 +52,6 @@ add_library(core_common_library_objects OBJECT
5152
sysinfo.cpp
5253
xclbin_parser.cpp
5354
xclbin_swemu.cpp
54-
smi.cpp
5555
)
5656

5757
target_include_directories(core_common_library_objects
@@ -84,13 +84,15 @@ add_library(xrt_coreutil SHARED
8484
$<TARGET_OBJECTS:core_common_runner_objects>
8585
$<TARGET_OBJECTS:core_common_api_library_objects>
8686
$<TARGET_OBJECTS:core_common_xdp_profile_objects>
87+
$<TARGET_OBJECTS:core_common_smi_objects>
8788
)
8889

8990
add_library(xrt_coreutil_static STATIC
9091
$<TARGET_OBJECTS:core_common_library_objects>
9192
$<TARGET_OBJECTS:core_common_runner_objects>
9293
$<TARGET_OBJECTS:core_common_api_library_objects>
9394
$<TARGET_OBJECTS:core_common_xdp_profile_objects>
95+
$<TARGET_OBJECTS:core_common_smi_objects>
9496
)
9597

9698
set_target_properties(xrt_coreutil PROPERTIES
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved.
3+
#
4+
# OBJECT libraries linked into xrt_coreutil, xrt_core (Alveo/edge), and xrt_driver_xdna / other shims.
5+
6+
add_library(core_common_smi_objects OBJECT smi.cpp)
7+
target_include_directories(core_common_smi_objects
8+
PRIVATE
9+
${XRT_SOURCE_DIR}/runtime_src
10+
)
11+
12+
add_library(core_smi_alveo_objects OBJECT smi_alveo.cpp)
13+
add_library(core_smi_ryzen_objects OBJECT smi_ryzen.cpp)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#define XRT_CORE_COMMON_SOURCE
55

66
// Local - Include Files
7-
#include "smi.h"
7+
#include "core/common/smi/smi.h"
88

99
// 3rd Party Library - Include Files
1010
#include <boost/property_tree/json_parser.hpp>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
#pragma once
55
// Local include files
6-
#include "config.h"
7-
#include "query_requests.h"
6+
#include "core/common/config.h"
7+
#include "core/common/query_requests.h"
88

99
// 3rd Party Library - Include Files
1010
#include <boost/property_tree/ptree.hpp>
@@ -182,7 +182,7 @@ class config_generator {
182182
// This subcommand is used for device and host configuration.
183183
// Derived classes must implement this method to define hardware-specific configuration logic.
184184
virtual subcommand
185-
create_configure_subcommand() = 0;
185+
create_configure_subcommand() = 0;
186186
};
187187

188188
// class smi_hardware_config

src/runtime_src/core/pcie/linux/smi_pcie.cpp renamed to src/runtime_src/core/common/smi/smi_alveo.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved.
3-
#include "smi_pcie.h"
43

5-
namespace shim_pcie::smi {
4+
#include "core/common/smi/smi_alveo.h"
65

7-
xrt_core::smi::subcommand
6+
#include "core/common/smi/smi.h"
7+
8+
#include <map>
9+
#include <memory>
10+
#include <string>
11+
#include <vector>
12+
13+
namespace xrt_core::smi::alveo {
14+
15+
static xrt_core::smi::subcommand
816
create_validate_subcommand()
917
{
1018
std::vector<xrt_core::smi::basic_option> validate_test_desc = {
@@ -29,7 +37,7 @@ create_validate_subcommand()
2937
{"verify", "Run 'Hello World' kernel test", "common"}
3038
};
3139

32-
std::map<std::string, std::shared_ptr<xrt_core::smi::option>> validate_suboptions;
40+
std::map<std::string, std::shared_ptr<xrt_core::smi::option>> validate_suboptions;
3341
validate_suboptions.emplace("device", std::make_shared<xrt_core::smi::option>("device", "d", "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", "common", "", "string"));
3442
validate_suboptions.emplace("format", std::make_shared<xrt_core::smi::option>("format", "f", "Report output format. Valid values are:\n"
3543
"\tJSON - Latest JSON schema\n"
@@ -40,12 +48,12 @@ create_validate_subcommand()
4048
"common", "", "array", validate_test_desc));
4149
validate_suboptions.emplace("path", std::make_shared<xrt_core::smi::option>("path", "p", "Path to the directory containing validate xclbins", "hidden", "", "string"));
4250
validate_suboptions.emplace("param", std::make_shared<xrt_core::smi::option>("param", "", "Extended parameter for a given test. Format: <test-name>:<key>:<value>", "hidden", "", "string"));
43-
validate_suboptions.emplace("pmode", std::make_shared<xrt_core::smi::option>("pmode", "", "Specify which power mode to run the benchmarks in. Note: Some tests might be unavailable for some modes", "hidden", "", "string"));
51+
validate_suboptions.emplace("pmode", std::make_shared<xrt_core::smi::option>("pmode", "", "Specify which power mode to run the benchmarks in. Note: Some tests might be unavailable for some modes", "hidden", "", "string"));
4452

4553
return {"validate", "Validates the given device by executing the platform's validate executable", "common", std::move(validate_suboptions)};
4654
}
4755

48-
xrt_core::smi::subcommand
56+
static xrt_core::smi::subcommand
4957
create_examine_subcommand()
5058
{
5159
std::vector<xrt_core::smi::basic_option> examine_report_desc = {
@@ -67,7 +75,7 @@ create_examine_subcommand()
6775
{"thermal", "Thermal sensors present on the device", "common"}
6876
};
6977

70-
std::map<std::string, std::shared_ptr<xrt_core::smi::option>> examine_suboptions;
78+
std::map<std::string, std::shared_ptr<xrt_core::smi::option>> examine_suboptions;
7179
examine_suboptions.emplace("device", std::make_shared<xrt_core::smi::option>("device", "d", "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", "common", "", "string"));
7280
examine_suboptions.emplace("format", std::make_shared<xrt_core::smi::option>("format", "f", "Report output format. Valid values are:\n"
7381
"\tJSON - Latest JSON schema\n"
@@ -78,9 +86,9 @@ create_examine_subcommand()
7886
examine_suboptions.emplace("element", std::make_shared<xrt_core::smi::option>("element", "e", "Filters individual elements(s) from the report. Format: '/<key>/<key>/...'", "hidden", "", "array"));
7987

8088
return {"examine", "This command will 'examine' the state of the system/device and will generate a report of interest in a text or JSON format.", "common", std::move(examine_suboptions)};
81-
} // namespace shim_pcie::smi
89+
}
8290

83-
xrt_core::smi::subcommand
91+
static xrt_core::smi::subcommand
8492
create_configure_subcommand()
8593
{
8694
std::map<std::string, std::shared_ptr<xrt_core::smi::option>> configure_suboptions;
@@ -89,22 +97,17 @@ create_configure_subcommand()
8997
configure_suboptions.emplace("p2p", std::make_shared<xrt_core::smi::option>("p2p", "", "Controls P2P functionality\n", "common", "", "string", true));
9098
configure_suboptions.emplace("host-mem", std::make_shared<xrt_core::smi::option>("host-mem", "", "Controls host-mem functionality\n", "common", "", "string", true));
9199

92-
93100
return {"configure", "Device and host configuration", "common", std::move(configure_suboptions)};
94101
}
95102

96103
std::string
97104
get_smi_config()
98105
{
99-
// Get the singleton instance
100106
auto smi_instance = xrt_core::smi::instance();
101-
102-
// Add subcommands
103107
smi_instance->add_subcommand("validate", create_validate_subcommand());
104108
smi_instance->add_subcommand("examine", create_examine_subcommand());
105109
smi_instance->add_subcommand("configure", create_configure_subcommand());
106-
107110
return smi_instance->build_json();
108111
}
109112

110-
} // namespace shim_pcie::smi
113+
} // namespace xrt_core::smi::alveo
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved.
3+
#pragma once
4+
5+
#include <string>
6+
7+
namespace xrt_core::smi::alveo {
8+
9+
// xrt-smi JSON for Alveo-class shims (PCIe Linux and edge user device_linux).
10+
std::string
11+
get_smi_config();
12+
13+
} // namespace xrt_core::smi::alveo
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved.
3+
4+
#include "core/common/smi/smi_ryzen.h"
5+
6+
#include "core/common/query_requests.h"
7+
8+
using namespace xrt_core::smi;
9+
10+
namespace xrt_core::smi::ryzen {
11+
12+
config_gen_ryzen::
13+
config_gen_ryzen()
14+
{
15+
validate_test_desc = {
16+
{"aie-reconfig-overhead", "Run end-to-end array reconfiguration overhead through shim DMA", "hidden"},
17+
{"all", "All applicable validate tests will be executed (default)", "common"},
18+
{"cmd-chain-latency", "Run end-to-end latency test using command chaining", "hidden"},
19+
{"cmd-chain-throughput", "Run end-to-end throughput test using command chaining", "hidden"},
20+
{"df-bw", "Run bandwidth test on data fabric", "hidden"},
21+
{"gemm", "Measure the TOPS value of GEMM INT8operations", "common"},
22+
{"latency", "Run end-to-end latency test", "common"},
23+
{"quick", "Run a subset of four tests: \n1. latency \n2. throughput \n3. cmd-chain-latency \n4. cmd-chain-throughput", "hidden"},
24+
{"tct-all-col", "Measure average TCT processing time for all columns", "hidden"},
25+
{"tct-one-col", "Measure average TCT processing time for one column", "hidden"},
26+
{"throughput", "Run end-to-end throughput test", "common"},
27+
{"temporal-sharing-overhead", "Run end-to-end temporal sharing overhead test", "hidden"},
28+
{"preemption-overhead", "Measure preemption overhead at noop and memtile levels", "hidden"}
29+
};
30+
}
31+
32+
config_gen_phoenix::
33+
config_gen_phoenix()
34+
{
35+
validate_test_desc = {
36+
{"all", "All applicable validate tests will be executed (default)", "common"},
37+
{"df-bw", "Run bandwidth test on data fabric", "hidden"},
38+
{"latency", "Run end-to-end latency test", "common"},
39+
{"tct-all-col", "Measure average TCT processing time for all columns", "hidden"},
40+
{"tct-one-col", "Measure average TCT processing time for one column", "hidden"},
41+
{"throughput", "Run end-to-end throughput test", "common"},
42+
};
43+
}
44+
45+
subcommand
46+
config_gen_ryzen::create_validate_subcommand()
47+
{
48+
std::map<std::string, std::shared_ptr<option>> validate_suboptions;
49+
validate_suboptions.emplace("device", std::make_shared<option>("device", "d", "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", "common", "", "string"));
50+
validate_suboptions.emplace("format", std::make_shared<option>("format", "f", "Report output format. Valid values are:\n"
51+
"\tJSON - Latest JSON schema\n"
52+
"\tJSON-2020.2 - JSON 2020.2 schema", "common", "JSON", "string"));
53+
validate_suboptions.emplace("output", std::make_shared<option>("output", "o", "Direct the output to the given file", "common", "", "string"));
54+
validate_suboptions.emplace("help", std::make_shared<option>("help", "h", "Help to use this sub-command", "common", "", "none"));
55+
validate_suboptions.emplace("run", std::make_shared<listable_description_option>("run", "r", "Run a subset of the test suite. Valid options are:\n",
56+
"common", "", "array", get_validate_test_desc()));
57+
validate_suboptions.emplace("param", std::make_shared<option>("param", "", "Extended parameter for a given test. Format: <test-name>:<key>:<value>", "param", "", "string"));
58+
validate_suboptions.emplace("pmode", std::make_shared<option>("pmode", "", "Specify which power mode to run the benchmarks in. Note: Some tests might be unavailable for some modes", "hidden", "", "string"));
59+
validate_suboptions.emplace("loop", std::make_shared<option>("loop", "", "Number of iterations to run the test", "hidden", "", "string"));
60+
61+
return {"validate", "Validates the given device by executing the platform's validate executable", "common", std::move(validate_suboptions)};
62+
}
63+
64+
subcommand
65+
config_gen_ryzen::create_examine_subcommand()
66+
{
67+
std::vector<basic_option> examine_report_desc = {
68+
{"aie-partitions", "AIE partition information", "common"},
69+
{"all", "All known reports are produced", "common"},
70+
{"host", "Host information (default)", "common"},
71+
{"platform", "Platforms flashed on the device", "common"},
72+
{"telemetry", "Telemetry data for the device", "hidden"},
73+
{"preemption", "Preemption telemetry data for the device", "hidden"},
74+
{"clocks", "Clock frequency information", "hidden"}
75+
};
76+
77+
std::map<std::string, std::shared_ptr<option>> examine_suboptions;
78+
examine_suboptions.emplace("device", std::make_shared<option>("device", "d", "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", "common", "", "string"));
79+
examine_suboptions.emplace("format", std::make_shared<option>("format", "f", "Report output format. Valid values are:\n"
80+
"\tJSON - Latest JSON schema\n"
81+
"\tJSON-2020.2 - JSON 2020.2 schema", "common", "JSON", "string"));
82+
examine_suboptions.emplace("output", std::make_shared<option>("output", "o", "Direct the output to the given file", "common", "", "string"));
83+
examine_suboptions.emplace("help", std::make_shared<option>("help", "h", "Help to use this sub-command", "common", "", "none"));
84+
examine_suboptions.emplace("watch", std::make_shared<option>("watch", "", "Refresh interval in seconds between examine updates. Exit with Ctrl+C.", "hidden", "0", "string"));
85+
examine_suboptions.emplace("report", std::make_shared<listable_description_option>("report", "r", "The type of report to be produced. Reports currently available are:\n", "common", "", "array", examine_report_desc));
86+
examine_suboptions.emplace("firmware-log", std::make_shared<option>("firmware-log", "", "Show status|watch firmware log data", "hidden", "", "string", true));
87+
examine_suboptions.emplace("event-trace", std::make_shared<option>("event-trace", "", "Show status|watch event trace data", "hidden", "", "string", true));
88+
examine_suboptions.emplace("context-health", std::make_shared<option>("context-health", "", "Show status|watch context health data", "hidden", "", "string", true));
89+
90+
return {"examine", "This command will 'examine' the state of the system/device and will generate a report of interest in a text or JSON format.", "common", std::move(examine_suboptions)};
91+
}
92+
93+
subcommand
94+
config_gen_ryzen::create_configure_subcommand()
95+
{
96+
std::map<std::string, std::shared_ptr<option>> configure_suboptions;
97+
configure_suboptions.emplace("device", std::make_shared<option>("device", "d", "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", "common", "", "string"));
98+
configure_suboptions.emplace("help", std::make_shared<option>("help", "h", "Help to use this sub-command", "common", "", "none"));
99+
configure_suboptions.emplace("pmode", std::make_shared<option>("pmode", "", "Modes: default, powersaver, balanced, performance, turbo", "common", "", "string", true));
100+
configure_suboptions.emplace("force-preemption", std::make_shared<option>("force-preemption", "", "Force enable|disable and see status of preemption", "hidden", "", "string", true));
101+
configure_suboptions.emplace("event-trace", std::make_shared<option>("event-trace", "", "Enable|disable event tracing", "hidden", "", "string", true));
102+
configure_suboptions.emplace("firmware-log", std::make_shared<option>("firmware-log", "", "Enable|disable firmware logging", "hidden", "", "string", true));
103+
104+
return {"configure", "Device and host configuration", "common", std::move(configure_suboptions)};
105+
}
106+
107+
void
108+
populate_smi_instance(xrt_core::smi::smi* smi_instance, const xrt_core::device* device)
109+
{
110+
smi_hardware_config smi_hrdw;
111+
const auto pcie_id = xrt_core::device_query<xrt_core::query::pcie_id>(device);
112+
auto hardware_type = smi_hrdw.get_hardware_type(pcie_id);
113+
114+
std::shared_ptr<config_generator> generator;
115+
116+
switch (hardware_type) {
117+
case smi_hardware_config::hardware_type::phx:
118+
{
119+
generator = std::make_shared<config_gen_phoenix>();
120+
break;
121+
}
122+
case smi_hardware_config::hardware_type::stxA0:
123+
case smi_hardware_config::hardware_type::stxB0:
124+
case smi_hardware_config::hardware_type::stxH:
125+
case smi_hardware_config::hardware_type::krk1:
126+
{
127+
generator = std::make_shared<config_gen_strix>();
128+
break;
129+
}
130+
case smi_hardware_config::hardware_type::npu3_f1:
131+
case smi_hardware_config::hardware_type::npu3_f2:
132+
case smi_hardware_config::hardware_type::npu3_f3:
133+
{
134+
generator = std::make_shared<config_gen_npu3>();
135+
break;
136+
}
137+
default:
138+
generator = std::make_shared<config_gen_strix>();
139+
break;
140+
}
141+
142+
if (generator) {
143+
smi_instance->add_subcommand("validate", generator->create_validate_subcommand());
144+
smi_instance->add_subcommand("examine", generator->create_examine_subcommand());
145+
smi_instance->add_subcommand("configure", generator->create_configure_subcommand());
146+
}
147+
}
148+
149+
std::string
150+
get_smi_config(const xrt_core::device* device)
151+
{
152+
auto smi_instance = xrt_core::smi::instance();
153+
154+
populate_smi_instance(smi_instance, device);
155+
156+
return smi_instance->build_json();
157+
}
158+
159+
} // namespace xrt_core::smi::ryzen

0 commit comments

Comments
 (0)