Skip to content

Commit 5913b85

Browse files
authored
xdna shim side changes for NPU handling (#577)
Signed-off-by: Akshay Tondak <[email protected]>
1 parent 03b23af commit 5913b85

File tree

5 files changed

+109
-40
lines changed

5 files changed

+109
-40
lines changed

src/shim/device.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ struct xrt_smi_config
939939
const auto xrt_smi_config_type = std::any_cast<xrt_core::query::xrt_smi_config::type>(param);
940940
switch (xrt_smi_config_type) {
941941
case xrt_core::query::xrt_smi_config::type::options_config:
942-
return shim_xdna::smi::get_smi_config();
942+
return shim_xdna::smi::get_smi_config(device);
943943
default:
944944
throw xrt_core::query::no_such_key(key, "Not implemented");
945945
}

src/shim/smi_xdna.cpp

Lines changed: 73 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
// Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved.
33

44
#include "smi_xdna.h"
5+
using namespace xrt_core::smi;
56

67
namespace shim_xdna::smi {
78

89
// Function to create the "validate" subcommand
9-
xrt_core::smi::subcommand
10-
create_validate_subcommand()
10+
subcommand
11+
config_gen_xdna::create_validate_subcommand()
1112
{
12-
std::vector<xrt_core::smi::basic_option> validate_test_desc = {
13+
std::vector<basic_option> validate_test_desc = {
1314
{"aie-reconfig-overhead", "Run end-to-end array reconfiguration overhead through shim DMA", "hidden"},
1415
{"all", "All applicable validate tests will be executed (default)", "common"},
1516
{"cmd-chain-latency", "Run end-to-end latency test using command chaining", "hidden"},
@@ -25,28 +26,28 @@ create_validate_subcommand()
2526
{"preemption-overhead", "Measure preemption overhead at noop and memtile levels", "hidden"},
2627
};
2728

28-
std::map<std::string, std::shared_ptr<xrt_core::smi::option>> validate_suboptions;
29-
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"));
30-
validate_suboptions.emplace("format", std::make_shared<xrt_core::smi::option>("format", "f", "Report output format. Valid values are:\n"
29+
std::map<std::string, std::shared_ptr<option>> validate_suboptions;
30+
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"));
31+
validate_suboptions.emplace("format", std::make_shared<option>("format", "f", "Report output format. Valid values are:\n"
3132
"\tJSON - Latest JSON schema\n"
3233
"\tJSON-2020.2 - JSON 2020.2 schema", "common", "JSON", "string"));
33-
validate_suboptions.emplace("output", std::make_shared<xrt_core::smi::option>("output", "o", "Direct the output to the given file", "common", "", "string"));
34-
validate_suboptions.emplace("help", std::make_shared<xrt_core::smi::option>("help", "h", "Help to use this sub-command", "common", "", "none"));
35-
validate_suboptions.emplace("run", std::make_shared<xrt_core::smi::listable_description_option>("run", "r", "Run a subset of the test suite. Valid options are:\n",
34+
validate_suboptions.emplace("output", std::make_shared<option>("output", "o", "Direct the output to the given file", "common", "", "string"));
35+
validate_suboptions.emplace("help", std::make_shared<option>("help", "h", "Help to use this sub-command", "common", "", "none"));
36+
validate_suboptions.emplace("run", std::make_shared<listable_description_option>("run", "r", "Run a subset of the test suite. Valid options are:\n",
3637
"common", "", "array", validate_test_desc));
37-
validate_suboptions.emplace("path", std::make_shared<xrt_core::smi::option>("path", "p", "Path to the directory containing validate xclbins", "hidden", "", "string"));
38-
validate_suboptions.emplace("param", std::make_shared<xrt_core::smi::option>("param", "", "Extended parameter for a given test. Format: <test-name>:<key>:<value>", "param", "", "string"));
39-
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"));
40-
validate_suboptions.emplace("elf", std::make_shared<xrt_core::smi::option>("elf", "", "Run the test in ELF mode", "hidden", "", "none"));
38+
validate_suboptions.emplace("path", std::make_shared<option>("path", "p", "Path to the directory containing validate xclbins", "hidden", "", "string"));
39+
validate_suboptions.emplace("param", std::make_shared<option>("param", "", "Extended parameter for a given test. Format: <test-name>:<key>:<value>", "param", "", "string"));
40+
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"));
41+
validate_suboptions.emplace("elf", std::make_shared<option>("elf", "", "Run the test in ELF mode", "hidden", "", "none"));
4142

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

4546
// Function to create the "examine" subcommand
46-
xrt_core::smi::subcommand
47-
create_examine_subcommand()
47+
subcommand
48+
config_gen_xdna::create_examine_subcommand()
4849
{
49-
std::vector<xrt_core::smi::basic_option> examine_report_desc = {
50+
std::vector<basic_option> examine_report_desc = {
5051
{"aie-partitions", "AIE partition information", "common"},
5152
{"all", "All known reports are produced", "common"},
5253
{"host", "Host information", "common"},
@@ -56,45 +57,81 @@ create_examine_subcommand()
5657
{"clocks", "Clock frequency information", "hidden"}
5758
};
5859

59-
std::map<std::string, std::shared_ptr<xrt_core::smi::option>> examine_suboptions;
60-
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"));
61-
examine_suboptions.emplace("format", std::make_shared<xrt_core::smi::option>("format", "f", "Report output format. Valid values are:\n"
60+
std::map<std::string, std::shared_ptr<option>> examine_suboptions;
61+
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"));
62+
examine_suboptions.emplace("format", std::make_shared<option>("format", "f", "Report output format. Valid values are:\n"
6263
"\tJSON - Latest JSON schema\n"
6364
"\tJSON-2020.2 - JSON 2020.2 schema", "common", "JSON", "string"));
64-
examine_suboptions.emplace("output", std::make_shared<xrt_core::smi::option>("output", "o", "Direct the output to the given file", "common", "", "string"));
65-
examine_suboptions.emplace("help", std::make_shared<xrt_core::smi::option>("help", "h", "Help to use this sub-command", "common", "", "none"));
66-
examine_suboptions.emplace("report", std::make_shared<xrt_core::smi::listable_description_option>("report", "r", "The type of report to be produced. Reports currently available are:\n", "common", "", "array", examine_report_desc));
67-
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"));
65+
examine_suboptions.emplace("output", std::make_shared<option>("output", "o", "Direct the output to the given file", "common", "", "string"));
66+
examine_suboptions.emplace("help", std::make_shared<option>("help", "h", "Help to use this sub-command", "common", "", "none"));
67+
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));
68+
examine_suboptions.emplace("element", std::make_shared<option>("element", "e", "Filters individual elements(s) from the report. Format: '/<key>/<key>/...'", "hidden", "", "array"));
6869

6970
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)};
7071
}
7172

7273
// Function to create the "configure" subcommand
73-
xrt_core::smi::subcommand
74-
create_configure_subcommand()
74+
subcommand
75+
config_gen_xdna::create_configure_subcommand()
7576
{
76-
std::map<std::string, std::shared_ptr<xrt_core::smi::option>> configure_suboptions;
77-
configure_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"));
78-
configure_suboptions.emplace("help", std::make_shared<xrt_core::smi::option>("help", "h", "Help to use this sub-command", "common", "", "none"));
79-
configure_suboptions.emplace("pmode", std::make_shared<xrt_core::smi::option>("pmode", "", "Modes: default, powersaver, balanced, performance, turbo", "common", "", "string", true));
80-
configure_suboptions.emplace("force-preemption", std::make_shared<xrt_core::smi::option>("force-preemption", "", "Force enable|disable and see status of preemption", "hidden", "", "string", true));
77+
std::map<std::string, std::shared_ptr<option>> configure_suboptions;
78+
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"));
79+
configure_suboptions.emplace("help", std::make_shared<option>("help", "h", "Help to use this sub-command", "common", "", "none"));
80+
configure_suboptions.emplace("pmode", std::make_shared<option>("pmode", "", "Modes: default, powersaver, balanced, performance, turbo", "common", "", "string", true));
81+
configure_suboptions.emplace("force-preemption", std::make_shared<option>("force-preemption", "", "Force enable|disable and see status of preemption", "hidden", "", "string", true));
8182

8283
return {"configure", "Device and host configuration", "common", std::move(configure_suboptions)};
8384
}
8485

86+
void
87+
populate_smi_instance(xrt_core::smi::smi* smi_instance, const xrt_core::device* device)
88+
{
89+
smi_hardware_config smi_hrdw;
90+
const auto pcie_id = xrt_core::device_query<xrt_core::query::pcie_id>(device);
91+
auto hardware_type = smi_hrdw.get_hardware_type(pcie_id);
92+
93+
// Retrieve the appropriate config generator based on hardware type
94+
std::shared_ptr<config_generator> generator;
95+
96+
switch (hardware_type) {
97+
case smi_hardware_config::hardware_type::phx:
98+
case smi_hardware_config::hardware_type::stxA0:
99+
case smi_hardware_config::hardware_type::stxB0:
100+
case smi_hardware_config::hardware_type::stxH:
101+
case smi_hardware_config::hardware_type::krk1:
102+
{
103+
generator = std::make_shared<config_gen_strix>();
104+
break;
105+
}
106+
case smi_hardware_config::hardware_type::npu3_f1:
107+
case smi_hardware_config::hardware_type::npu3_f2:
108+
case smi_hardware_config::hardware_type::npu3_f3:
109+
{
110+
generator = std::make_shared<config_gen_npu3>();
111+
break;
112+
}
113+
default:
114+
// Failsafe case for unknown hardware types for now. This should be changed to an error.
115+
generator = std::make_shared<config_gen_strix>();
116+
break;
117+
}
118+
119+
if (generator) {
120+
smi_instance->add_subcommand("validate", generator->create_validate_subcommand());
121+
smi_instance->add_subcommand("examine", generator->create_examine_subcommand());
122+
smi_instance->add_subcommand("configure", generator->create_configure_subcommand());
123+
}
124+
}
85125
std::string
86-
get_smi_config()
126+
get_smi_config(const xrt_core::device* device)
87127
{
88128

89129
// Get the singleton instance
90130
auto smi_instance = xrt_core::smi::instance();
91131

92-
// Add subcommands
93-
smi_instance->add_subcommand("validate", create_validate_subcommand());
94-
smi_instance->add_subcommand("examine", create_examine_subcommand());
95-
smi_instance->add_subcommand("configure", create_configure_subcommand());
132+
populate_smi_instance(smi_instance, device);
96133

97-
return smi_instance->build_smi_config();
134+
return smi_instance->build_json();
98135
}
99136

100137
} // namespace shim_xdna::smi

src/shim/smi_xdna.h

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,41 @@
33

44
#include <string>
55
#include "core/common/smi.h"
6+
#include "core/common/device.h"
67

78
namespace shim_xdna::smi {
9+
// class : config_generator
10+
//
11+
// This class is responsible for generating configuration subcommands for the xrt-smi.
12+
// Any behavior specific to windows platform should be defined here.
13+
class config_gen_xdna : public xrt_core::smi::config_generator {
14+
public:
15+
xrt_core::smi::subcommand
16+
create_validate_subcommand() override;
17+
18+
xrt_core::smi::subcommand
19+
create_examine_subcommand() override;
20+
21+
xrt_core::smi::subcommand
22+
create_configure_subcommand() override;
23+
24+
};
25+
26+
// class : config_gen_strix
27+
// This class is a specific implementation of config_gen_mcdm for Strix hardware.
28+
// Any xrt-smi configuration specific to Strix hardware should be defined here.
29+
class config_gen_strix : public config_gen_xdna {
30+
31+
};
32+
33+
// class : config_gen_npu3
34+
// This class is a specific implementation of config_gen_mcdm for NPU3 hardware.
35+
// Any xrt-smi configuration specific to NPU3 hardware should be defined here.
36+
class config_gen_npu3 : public config_gen_xdna {
37+
38+
};
39+
840
std::string
9-
get_smi_config();
41+
get_smi_config(const xrt_core::device* device);
1042

1143
} // namespace shim_xdna::smi

tools/info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"copyright": "Copyright (C) 2023-2025 Advanced Micro Devices, Inc. All rights reserved.",
33
"xrt" : {
4-
"version": "202520.2.20.41",
4+
"version": "202520.2.20.49",
55
"os_rel": ["22.04", "24.04"]
66
},
77
"firmwares": [

xrt

Submodule xrt updated 41 files

0 commit comments

Comments
 (0)