From 4745abd53a25cd49bc68845763f666e02a212dc9 Mon Sep 17 00:00:00 2001 From: Akshay Tondak Date: Wed, 11 Dec 2024 11:43:51 -0800 Subject: [PATCH 01/19] Json config work chk1 Signed-off-by: Akshay Tondak --- .../common/tests/TestValidateUtilities.cpp | 29 +++++++++++++++++++ .../common/tests/TestValidateUtilities.h | 1 + .../core/tools/xbutil2/CMakeLists.txt | 2 ++ .../core/tools/xbutil2/SubCmdValidate.cpp | 21 +++++++++++++- .../core/tools/xbutil2/SubCmdValidate.h | 4 ++- src/runtime_src/core/tools/xbutil2/xbutil.cpp | 5 +++- 6 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp b/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp index 70b49461e9b..602cbd5da40 100644 --- a/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp +++ b/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include "core/common/query_requests.h" #include "core/common/module_loader.h" #include "tools/common/XBUtilities.h" @@ -449,4 +450,32 @@ dpu_or_elf(const std::shared_ptr& dev, const xrt::xclbin& xclb return elf_path; } } +void loadConfigFile(const std::string &configPath, boost::property_tree::ptree &configTree) +{ + try + { + // Open the JSON file + std::ifstream jsonFile(configPath); + if (!jsonFile.is_open()) + { + throw std::runtime_error("Failed to open " + configPath); + } + + // Read the JSON file into the property tree + boost::property_tree::read_json(jsonFile, configTree); + + // Close the JSON file + jsonFile.close(); + } + catch (const boost::property_tree::json_parser_error &e) + { + std::cerr << "Error parsing JSON file: " << e.what() << std::endl; + throw; + } + catch (const std::exception &e) + { + std::cerr << "Error: " << e.what() << std::endl; + throw; + } +} }// end of namespace XBValidateUtils diff --git a/src/runtime_src/core/tools/common/tests/TestValidateUtilities.h b/src/runtime_src/core/tools/common/tests/TestValidateUtilities.h index c2667b7f046..253d5b9c760 100644 --- a/src/runtime_src/core/tools/common/tests/TestValidateUtilities.h +++ b/src/runtime_src/core/tools/common/tests/TestValidateUtilities.h @@ -90,5 +90,6 @@ bool search_and_program_xclbin(const std::shared_ptr& dev, boo int validate_binary_file(const std::string& binaryfile); std::string dpu_or_elf(const std::shared_ptr& dev, const xrt::xclbin& xclbin, boost::property_tree::ptree& ptTest); +void loadConfigFile(const std::string& configFile, boost::property_tree::ptree& pt); } //End of namespace XBValidateUtils #endif diff --git a/src/runtime_src/core/tools/xbutil2/CMakeLists.txt b/src/runtime_src/core/tools/xbutil2/CMakeLists.txt index 96ba609af4c..03769c9e25a 100644 --- a/src/runtime_src/core/tools/xbutil2/CMakeLists.txt +++ b/src/runtime_src/core/tools/xbutil2/CMakeLists.txt @@ -3,6 +3,7 @@ # Copyright (C) 2022-2023 Advanced Micro Devices, Inc. All rights reserved. # # Collect files outside of this directory + file(GLOB XBUTIL_V2_BASE_FILES "xbutil.cpp" "../common/XBMain.cpp" @@ -40,6 +41,7 @@ file(GLOB XBUTIL_V2_SUBCMD_FILES "SubCmdValidate.cpp" "SubCmdAdvanced.cpp" "SubCmdConfigure.cpp" + "SubCmdJsonObjects.cpp" "OO_Clock.cpp" "OO_MemRead.cpp" "OO_MemWrite.cpp" diff --git a/src/runtime_src/core/tools/xbutil2/SubCmdValidate.cpp b/src/runtime_src/core/tools/xbutil2/SubCmdValidate.cpp index a8341aa3a5d..5ea0b9a810f 100644 --- a/src/runtime_src/core/tools/xbutil2/SubCmdValidate.cpp +++ b/src/runtime_src/core/tools/xbutil2/SubCmdValidate.cpp @@ -440,7 +440,7 @@ static std::map>> json static const std::pair all_test = {"all", "All applicable validate tests will be executed (default)"}; static const std::pair quick_test = {"quick", "Run a subset of four tests: \n1. latency\n2. throughput\n3. cmd-chain-latency\n4. cmd-chain-throughput"}; -SubCmdValidate::SubCmdValidate(bool _isHidden, bool _isDepricated, bool _isPreliminary, const boost::property_tree::ptree& configurations) +SubCmdValidate::SubCmdValidate(bool _isHidden, bool _isDepricated, bool _isPreliminary, const boost::property_tree::ptree& configurations, const boost::property_tree::ptree& configTree) : SubCmd("validate", "Validates the basic device acceleration functionality") , m_device("") @@ -451,6 +451,7 @@ SubCmdValidate::SubCmdValidate(bool _isHidden, bool _isDepricated, bool _isPreli , m_xclbin_location("") , m_pmode("") , m_help(false) + , m_jsonConfig (JsonConfig(configTree.get_child("subcommands"), "validate")) { const std::string longDescription = "Validates the given device by executing the platform's validate executable."; setLongDescription(longDescription); @@ -471,6 +472,16 @@ SubCmdValidate::SubCmdValidate(bool _isHidden, bool _isDepricated, bool _isPreli common_tests.emplace_back(quick_test); static const auto formatRunValues = XBU::create_suboption_list_map("", jsonOptions, common_tests); + try{ + m_jsonConfig.addProgramOptions(m_commonOptions, "common", "validate"); + m_jsonConfig.addProgramOptions(m_hiddenOptions, "hidden", "validate"); + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } + + + /* common_options.add_options() ("device,d", boost::program_options::value(&m_device), "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest") ("format,f", boost::program_options::value(&m_format)->implicit_value(""), (std::string("Report output format. Valid values are:\n") + formatOptionValues).c_str() ) @@ -488,6 +499,14 @@ SubCmdValidate::SubCmdValidate(bool _isHidden, bool _isDepricated, bool _isPreli m_commonOptions.add_options() ("run,r", boost::program_options::value(&m_tests_to_run)->multitoken()->zero_tokens(), (std::string("Run a subset of the test suite. Valid options are:\n") + formatRunValues).c_str() ) ; + */ + try{ + m_jsonConfig.addProgramOptions(m_commonOptions, "common", "validate"); + m_jsonConfig.addProgramOptions(m_hiddenOptions, "hidden", "validate"); + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } } void diff --git a/src/runtime_src/core/tools/xbutil2/SubCmdValidate.h b/src/runtime_src/core/tools/xbutil2/SubCmdValidate.h index 6efe9681a29..95a86886d18 100644 --- a/src/runtime_src/core/tools/xbutil2/SubCmdValidate.h +++ b/src/runtime_src/core/tools/xbutil2/SubCmdValidate.h @@ -8,13 +8,14 @@ #include #include "tools/common/SubCmd.h" #include "tools/common/XBHelpMenus.h" +#include "SubCmdJsonObjects.h" class SubCmdValidate : public SubCmd { public: virtual void execute(const SubCmdOptions &_options) const; public: - SubCmdValidate(bool _isHidden, bool _isDepricated, bool _isPreliminary, const boost::property_tree::ptree& configurations); + SubCmdValidate(bool _isHidden, bool _isDepricated, bool _isPreliminary, const boost::property_tree::ptree& configurations, const boost::property_tree::ptree& config_tree); private: std::string m_device; @@ -25,6 +26,7 @@ class SubCmdValidate : public SubCmd { std::string m_xclbin_location; std::string m_pmode; bool m_help; + JsonConfig m_jsonConfig; void print_help_internal() const; void handle_errors_and_validate_tests(boost::program_options::variables_map&, diff --git a/src/runtime_src/core/tools/xbutil2/xbutil.cpp b/src/runtime_src/core/tools/xbutil2/xbutil.cpp index 0502eed078e..85e2525109c 100644 --- a/src/runtime_src/core/tools/xbutil2/xbutil.cpp +++ b/src/runtime_src/core/tools/xbutil2/xbutil.cpp @@ -9,6 +9,7 @@ #include "SubCmdProgram.h" #include "SubCmdReset.h" #include "SubCmdValidate.h" +#include "tools/common/tests/TestValidateUtilities.h" // Supporting tools #include "common/error.h" @@ -83,6 +84,8 @@ int main( int argc, char** argv ) std::istringstream command_config_stream(command_config); boost::property_tree::read_json(command_config_stream, configTree); + boost::property_tree::ptree configTreeMain; + XBValidateUtils::loadConfigFile("config.h", configTreeMain); { // Syntax: SubCmdClass( IsHidden, IsDepricated, IsPreliminary) subCommands.emplace_back(std::make_shared< SubCmdExamine >(false, false, false, configTree)); @@ -94,7 +97,7 @@ int main( int argc, char** argv ) populateSubCommandsFromJSON(subCommands, executable); #ifdef ENABLE_NATIVE_SUBCMDS_AND_REPORTS - subCommands.emplace_back(std::make_shared< SubCmdValidate >(false, false, false, configTree)); + subCommands.emplace_back(std::make_shared< SubCmdValidate >(false, false, false, configTree, configTreeMain)); #endif subCommands.emplace_back(std::make_shared< SubCmdAdvanced >(true, false, true, configTree)); From 0ee2d03aa52c3eaf055c8595bf5f938894e2b9a6 Mon Sep 17 00:00:00 2001 From: Akshay Tondak Date: Thu, 12 Dec 2024 15:31:32 -0800 Subject: [PATCH 02/19] Config based xrt-smi chk2 Signed-off-by: Akshay Tondak --- .../core/tools/xbutil2/CMakeLists.txt | 7 + .../core/tools/xbutil2/SubCmdJsonObjects.cpp | 153 ++++++++++++++ .../core/tools/xbutil2/SubCmdJsonObjects.h | 150 ++++++++++++++ .../core/tools/xbutil2/SubCmdValidate.cpp | 167 ++++++++------- .../core/tools/xbutil2/SubCmdValidate.h | 27 ++- src/runtime_src/core/tools/xbutil2/xbutil.cpp | 5 +- .../core/tools/xbutil2/xrt_smi_config.json | 194 ++++++++++++++++++ 7 files changed, 604 insertions(+), 99 deletions(-) create mode 100644 src/runtime_src/core/tools/xbutil2/SubCmdJsonObjects.cpp create mode 100644 src/runtime_src/core/tools/xbutil2/SubCmdJsonObjects.h create mode 100644 src/runtime_src/core/tools/xbutil2/xrt_smi_config.json diff --git a/src/runtime_src/core/tools/xbutil2/CMakeLists.txt b/src/runtime_src/core/tools/xbutil2/CMakeLists.txt index 03769c9e25a..03adcc01e37 100644 --- a/src/runtime_src/core/tools/xbutil2/CMakeLists.txt +++ b/src/runtime_src/core/tools/xbutil2/CMakeLists.txt @@ -54,6 +54,8 @@ file(GLOB XBUTIL_V2_SUBCMD_FILES "OO_Reports.cpp" ) +file(GLOB XRT_SMI_CONFIG_FILE "xrt_smi_config.json") + # Merge the files into one collection set(XBUTIL_V2_SRCS ${XBUTIL_V2_BASE_FILES} ${XBUTIL_V2_SUBCMD_FILES}) @@ -120,4 +122,9 @@ endif() # Install our built executable install (TARGETS ${XBUTIL2_NAME} RUNTIME DESTINATION ${XRT_INSTALL_UNWRAPPED_DIR}) install (PROGRAMS ${XRT_HELPER_SCRIPTS} DESTINATION ${XRT_INSTALL_BIN_DIR}) + +# TODO: xrt-smi rearchitecture. This is temporary and will be removed once +# driver stores have this config file and shim layer has device query implemented. +install (FILES ${XRT_SMI_CONFIG_FILE} DESTINATION ${XRT_INSTALL_UNWRAPPED_DIR}) +install (FILES ${XRT_SMI_CONFIG_FILE} DESTINATION ${XRT_INSTALL_BIN_DIR}) # ----------------------------------------------------------------------------- diff --git a/src/runtime_src/core/tools/xbutil2/SubCmdJsonObjects.cpp b/src/runtime_src/core/tools/xbutil2/SubCmdJsonObjects.cpp new file mode 100644 index 00000000000..e3275c0ad71 --- /dev/null +++ b/src/runtime_src/core/tools/xbutil2/SubCmdJsonObjects.cpp @@ -0,0 +1,153 @@ +#include + +#include "SubCmdJsonObjects.h" + +void +OptionBasic::printOption() const +{ + std::cout << "Name: " << m_name << std::endl; + std::cout << "Description: " << m_description << std::endl; + std::cout << "Tag: " << m_tag << std::endl; +} + +/** + * Adds the sub-command option to the options description. + * This method checks the option type and adds the option to the provided options description + * based on its value type (BOOL, STRING, ARRAY). + * If the option type does not match the provided optionsType, the option is not added. + * If the value type is invalid, an exception is thrown. + */ +void +SubCommandOption::addProgramOption(po::options_description& options, const std::string& optionsType) +{ + if (m_optionType != optionsType) return; + + auto valueType = m_valueTypeMap.find(m_valueType); + if (valueType == m_valueTypeMap.end()) { + throw std::runtime_error("Invalid value type for option " + m_name); + } + switch (valueType->second){ + case ValueType::BOOL: + { + auto defaultVal = m_defaultValue == "true" ? true : false; + options.add_options()((m_name + "," + m_alias).c_str() + , po::value()->default_value(defaultVal) + , m_description.c_str()); + break; + } + case ValueType::STRING: + { + options.add_options()((m_name + "," + m_alias).c_str() + , po::value()->implicit_value(m_defaultValue) + , m_description.c_str()); + break; + } + case ValueType::ARRAY: + { + options.add_options()((m_name + "," + m_alias).c_str() + , po::value>()->multitoken()->zero_tokens() + , m_description.c_str()); + break; + } + case ValueType::NONE: + { + options.add_options()((m_name + "," + m_alias).c_str() + , po::bool_switch() + , m_description.c_str()); + break; + } + default: + throw std::runtime_error("Invalid value type for option " + m_name); + } +} + +std::unordered_map +SubCommandOption::createBasicOptions(const pt::ptree& pt) +{ + std::unordered_map optionMap; + for (const auto& [key, value] : pt) { + optionMap.emplace(value.get(std::string(const_name_literal)), OptionBasic(value)); + } + return optionMap; +} + +void +SubCommandOption::printOption() const +{ + std::cout << "Name: " << m_name << std::endl; + std::cout << "Description: " << m_description << std::endl; + std::cout << "Tag: " << m_tag << std::endl; + std::cout << "Alias: " << m_alias << std::endl; + std::cout << "Default Value: " << m_defaultValue << std::endl; + std::cout << "Option Type: " << m_optionType << std::endl; + std::cout << "Value Type: " << m_valueType << std::endl; + for (const auto& [key, value] : m_subOptionMap) { + value.printOption(); + } +} + +std::unordered_map +SubCommand::createSubCommandOptions(const pt::ptree& pt) +{ + std::unordered_map optionMap; + for (const auto& [key, value] : pt) { + optionMap.emplace(value.get(std::string(const_name_literal)), SubCommandOption(value)); + } + return optionMap; +} + +void +SubCommand::addProgramOptions(po::options_description& options, const std::string& optionsType) +{ + for (auto& [optionName, optionObj] : m_optionMap) { + optionObj.addProgramOption(options, optionsType); + } +} + +/** + * Creates sub-commands from the property tree. + * This method parses the property tree to create a map of sub-command names to SubCommand objects. + * Only sub-commands matching the provided subCommand name are included. + */ +std::unordered_map +JsonConfig::createSubCommands(const pt::ptree& pt, const std::string& subCommand) +{ + std::unordered_map subCommandMap; + for (const auto& [key, value] : pt) { + if (value.get(std::string(const_name_literal)) != subCommand) { + continue; + } + subCommandMap.emplace(value.get(std::string(const_name_literal)), SubCommand(value)); + } + return subCommandMap; +} + +/** + * Adds program options to the options description for a specific sub-command. + * This method finds the specified sub-command and adds its options to the provided options description. + * If the sub-command is not found, an exception is thrown. + */ +void +JsonConfig::addProgramOptions(po::options_description& options + , const std::string& optionsType + , const std::string& subCommand) +{ + auto subCommandIter = m_subCommandMap.find(subCommand); + if (subCommandIter == m_subCommandMap.end()) { + throw std::runtime_error("Subcommand not found"); + } + subCommandIter->second.addProgramOptions(options, optionsType); +} + +void +JsonConfig::printConfigurations() const +{ + for (const auto& [key, value] : m_subCommandMap) { + std::cout << "Subcommand: " << key << std::endl; + std::cout << "Description: " << value.getDescription() << std::endl; + std::cout << "Tag: " << value.getTag() << std::endl; + for (const auto& [key2, value2] : value.getOptionMap()) { + value2.printOption(); + } + } +} \ No newline at end of file diff --git a/src/runtime_src/core/tools/xbutil2/SubCmdJsonObjects.h b/src/runtime_src/core/tools/xbutil2/SubCmdJsonObjects.h new file mode 100644 index 00000000000..5dbd12c2485 --- /dev/null +++ b/src/runtime_src/core/tools/xbutil2/SubCmdJsonObjects.h @@ -0,0 +1,150 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright (C) 2022-2024 Advanced Micro Devices, Inc. All rights reserved. + +#pragma once + +#include +#include +#include + +#include "boost/property_tree/ptree.hpp" +#include "boost/program_options.hpp" + +static constexpr std::string_view const_name_literal = "name"; +static constexpr std::string_view const_description_literal = "description"; +static constexpr std::string_view const_tag_literal = "tag"; +static constexpr std::string_view const_alias_literal = "alias"; +static constexpr std::string_view const_default_value_literal = "default_value"; +static constexpr std::string_view const_option_type_literal = "option_type"; +static constexpr std::string_view const_value_type_literal = "value_type"; +static constexpr std::string_view const_options_literal = "options"; + +namespace po = boost::program_options; +namespace pt = boost::property_tree; + +using variantType = std::variant>; + +enum class ValueType { + BOOL, + STRING, + ARRAY, + NONE +}; + +class OptionBasic { + +public: + std::string m_name; + std::string m_description; + std::string m_tag; + OptionBasic(const pt::ptree& configurations) + : m_name(configurations.get(std::string(const_name_literal))), + m_description(configurations.get(std::string(const_description_literal))), + m_tag(configurations.get(std::string(const_tag_literal))) + {} + + std::string getName() const { return m_name; } + std::string getDescription() const { return m_description; } + std::string getTag() const { return m_tag; } + void printOption() const; +}; + + +class SubCommandOption : public OptionBasic { + std::string m_alias; + std::string m_defaultValue; + std::string m_optionType; + std::string m_valueType; + pt::ptree m_ptEmpty; + + /* + * Map of option name vs SubCommandOption objects. Example: + * --run can have multiple option Values like latency, throughput etc. + * latency : OptionBasic object + * throughput : OptionBasic object + * ................. + * df-bw : OptionBasic object + */ + std::unordered_map m_subOptionMap; + std::unordered_map + createBasicOptions(const pt::ptree& pt); + +protected: + const std::unordered_map m_valueTypeMap = { + {"bool", ValueType::BOOL}, + {"string", ValueType::STRING}, + {"array", ValueType::ARRAY}, + {"none", ValueType::NONE} + }; + +public: + + SubCommandOption(const pt::ptree& configurations): + OptionBasic(configurations), + m_alias(configurations.get(std::string(const_alias_literal), "")), + m_defaultValue(configurations.get(std::string(const_default_value_literal), "")), + m_optionType(configurations.get(std::string(const_option_type_literal), "")), + m_valueType(configurations.get(std::string(const_value_type_literal), "")), + m_ptEmpty(pt::ptree()), + m_subOptionMap(createBasicOptions(configurations.get_child(std::string(const_options_literal), m_ptEmpty))) + {} + + std::string getValueType() const { return m_valueType; } + std::string getAlias() const { return m_alias; } + std::string getDefaultValue() const { return m_defaultValue; } + std::string getOptionType() const { return m_optionType; } + std::unordered_map getSubOptionMap() const { return m_subOptionMap; } + + void addProgramOption(po::options_description& options, const std::string& optionsType); + void printOption() const; +}; + +class SubCommand : public OptionBasic { + /* + * Map of option name vs SubCommandOption objects. Example: + * --device : SubCommandOption object + * --format : SubCommandOption object + * ................. + * --run : SubCommandOption object + */ + std::unordered_map m_optionMap; + + std::unordered_map + createSubCommandOptions(const pt::ptree& pt); + +public: + SubCommand(const pt::ptree& configurations) : + OptionBasic(configurations), + m_optionMap(createSubCommandOptions(configurations.get_child(std::string(const_options_literal)))) + {} + std::unordered_map getOptionMap() const { return m_optionMap; } + + void addProgramOptions(po::options_description& options, const std::string& optionsType); +}; + +/** + * @brief JsonConfig class to handle the json configurations. + * Each SubCommand class will keep an object of this class type. + * Ideally SubCommand object creation should also be done at run-time + * and there should only be one object of this class type in existence. + * But that's a task for future enhancements. + */ + +class JsonConfig { + /* Map of subcommand name vs Subcommand objects + * validate : SubCommand object + * configure : SubCommand object + * examine : SubCommand object + */ + std::unordered_map m_subCommandMap; + std::unordered_map + createSubCommands(const pt::ptree& pt, const std::string& subCommand); + std::string JsonConfig::handleOptionValue(const variantType& value) const; +public: + JsonConfig(const pt::ptree& configurations, const std::string& subCommand) + : m_subCommandMap(createSubCommands(configurations, subCommand)) + {} + + void addProgramOptions(po::options_description& options, const std::string& optionsType, const std::string& subCommand); + void printConfigurations() const; +}; diff --git a/src/runtime_src/core/tools/xbutil2/SubCmdValidate.cpp b/src/runtime_src/core/tools/xbutil2/SubCmdValidate.cpp index 5ea0b9a810f..8949e0717a9 100644 --- a/src/runtime_src/core/tools/xbutil2/SubCmdValidate.cpp +++ b/src/runtime_src/core/tools/xbutil2/SubCmdValidate.cpp @@ -409,7 +409,7 @@ extendedKeysOptions() // ----- C L A S S M E T H O D S ------------------------------------------- XBU::VectorPairStrings -SubCmdValidate::getTestNameDescriptions(const bool addAdditionOptions) const +SubCmdValidate::getTestNameDescriptions(const SubCmdValidateOptions& options, const bool addAdditionOptions) const { XBU::VectorPairStrings reportDescriptionCollection; @@ -421,7 +421,7 @@ SubCmdValidate::getTestNameDescriptions(const bool addAdditionOptions) const const auto& configs = JSONConfigurable::parse_configuration_tree(m_commandConfig); const auto& testOptionsMap = JSONConfigurable::extract_subcmd_config(testSuite, configs, getConfigName(), std::string("test")); - const std::string& deviceClass = XBU::get_device_class(m_device, true); + const std::string& deviceClass = XBU::get_device_class(options.m_device, true); const auto it = testOptionsMap.find(deviceClass); const std::vector>& testOptions = (it == testOptionsMap.end()) ? testSuite : it->second; @@ -435,7 +435,6 @@ SubCmdValidate::getTestNameDescriptions(const bool addAdditionOptions) const } // -- Build up the format options -static boost::program_options::options_description common_options; static std::map>> jsonOptions; static const std::pair all_test = {"all", "All applicable validate tests will be executed (default)"}; static const std::pair quick_test = {"quick", "Run a subset of four tests: \n1. latency\n2. throughput\n3. cmd-chain-latency\n4. cmd-chain-throughput"}; @@ -443,14 +442,6 @@ static const std::pair quick_test = {"quick", "Run a s SubCmdValidate::SubCmdValidate(bool _isHidden, bool _isDepricated, bool _isPreliminary, const boost::property_tree::ptree& configurations, const boost::property_tree::ptree& configTree) : SubCmd("validate", "Validates the basic device acceleration functionality") - , m_device("") - , m_tests_to_run({"all"}) - , m_format("JSON") - , m_output("") - , m_param("") - , m_xclbin_location("") - , m_pmode("") - , m_help(false) , m_jsonConfig (JsonConfig(configTree.get_child("subcommands"), "validate")) { const std::string longDescription = "Validates the given device by executing the platform's validate executable."; @@ -466,43 +457,14 @@ SubCmdValidate::SubCmdValidate(bool _isHidden, bool _isDepricated, bool _isPreli jsonOptions = JSONConfigurable::extract_subcmd_config(testSuite, configs, getConfigName(), std::string("test")); // -- Build up the format options - static const auto formatOptionValues = XBU::create_suboption_list_string(Report::getSchemaDescriptionVector()); XBUtilities::VectorPairStrings common_tests; common_tests.emplace_back(all_test); common_tests.emplace_back(quick_test); static const auto formatRunValues = XBU::create_suboption_list_map("", jsonOptions, common_tests); try{ - m_jsonConfig.addProgramOptions(m_commonOptions, "common", "validate"); - m_jsonConfig.addProgramOptions(m_hiddenOptions, "hidden", "validate"); - } - catch (const std::exception& e) { - std::cerr << "Error: " << e.what() << std::endl; - } - - - /* - common_options.add_options() - ("device,d", boost::program_options::value(&m_device), "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest") - ("format,f", boost::program_options::value(&m_format)->implicit_value(""), (std::string("Report output format. Valid values are:\n") + formatOptionValues).c_str() ) - ("output,o", boost::program_options::value(&m_output)->implicit_value(""), "Direct the output to the given file") - ("help", boost::program_options::bool_switch(&m_help), "Help to use this sub-command") - ; - - m_hiddenOptions.add_options() - ("path,p", boost::program_options::value(&m_xclbin_location)->implicit_value(""), "Path to the directory containing validate xclbins") - ("param", boost::program_options::value(&m_param)->implicit_value(""), (std::string("Extended parameter for a given test. Format: ::\n") + extendedKeysOptions()).c_str()) - ("pmode", boost::program_options::value(&m_pmode)->implicit_value(""), "Specify which power mode to run the benchmarks in. Note: Some tests might be unavailable for some modes") - ; - - m_commonOptions.add(common_options); - m_commonOptions.add_options() - ("run,r", boost::program_options::value(&m_tests_to_run)->multitoken()->zero_tokens(), (std::string("Run a subset of the test suite. Valid options are:\n") + formatRunValues).c_str() ) - ; - */ - try{ - m_jsonConfig.addProgramOptions(m_commonOptions, "common", "validate"); - m_jsonConfig.addProgramOptions(m_hiddenOptions, "hidden", "validate"); + m_jsonConfig.addProgramOptions(m_commonOptions, "common", getName()); + m_jsonConfig.addProgramOptions(m_hiddenOptions, "hidden", getName()); } catch (const std::exception& e) { std::cerr << "Error: " << e.what() << std::endl; @@ -510,64 +472,80 @@ SubCmdValidate::SubCmdValidate(bool _isHidden, bool _isDepricated, bool _isPreli } void -SubCmdValidate::print_help_internal() const +SubCmdValidate::print_help_internal(const SubCmdValidateOptions& options) const { - if (m_device.empty()) { + if (options.m_device.empty()) { printHelp(false); return; } - const std::string deviceClass = XBU::get_device_class(m_device, true); + const std::string deviceClass = XBU::get_device_class(options.m_device, true); auto it = jsonOptions.find(deviceClass); XBUtilities::VectorPairStrings help_tests = { all_test }; if (it != jsonOptions.end() && it->second.size() > 3) help_tests.emplace_back(quick_test); + const auto formatOptionValues = XBU::create_suboption_list_string(Report::getSchemaDescriptionVector()); static const std::string testOptionValues = XBU::create_suboption_list_map(deviceClass, jsonOptions, help_tests); std::vector tempVec; + boost::program_options::options_description common_options; + + /* TODO: xrt-smi rearchitecture + * These add_options calls should be obsoleted and help printing should be done through m_jsonConfig. + * This is not done in patch since this help printing is tightly coupled with JSONConfigurable to get + * the test names and report names. This should be refactored in a separate patch and JSONConfigurable + * should be obsoleted. + */ common_options.add_options() - ("run,r", boost::program_options::value(&tempVec)->multitoken(), (std::string("Run a subset of the test suite. Valid options are:\n") + testOptionValues).c_str() ) - ; + ("device,d", boost::program_options::value(), "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest") + ("format,f", boost::program_options::value()->implicit_value(""), (std::string("Report output format. Valid values are:\n") + formatOptionValues).c_str() ) + ("output,o", boost::program_options::value()->implicit_value(""), "Direct the output to the given file") + ("help", boost::program_options::bool_switch(), "Help to use this sub-command") + ("run,r", boost::program_options::value()->multitoken(), (std::string("Run a subset of the test suite. Valid options are:\n") + testOptionValues).c_str() ) + ; printHelp(common_options, m_hiddenOptions, deviceClass, false); } void -SubCmdValidate::handle_errors_and_validate_tests(po::variables_map& vm, + +SubCmdValidate::handle_errors_and_validate_tests(const boost::program_options::variables_map& vm, + const SubCmdValidateOptions& options, std::vector& validatedTests, std::vector& param) const { - const auto testNameDescription = getTestNameDescriptions(true /* Add "all" and "quick" options*/); - if (vm.count("output") && m_output.empty()) - throw xrt_core::error("Output file not specified"); + const auto testNameDescription = getTestNameDescriptions(options, true /* Add "all" and "quick" options*/); + + if (vm.count("output") && options.m_output.empty()) + throw xrt_core::error("Output file not specified "); - if (vm.count("path") && m_xclbin_location.empty()) + if (vm.count("path") && options.m_xclbin_path.empty()) throw xrt_core::error("xclbin path not specified"); - if (vm.count("param") && m_param.empty()) + if (vm.count("param") && options.m_param.empty()) throw xrt_core::error("Parameter not specified"); - if (vm.count("pmode") && m_pmode.empty()) + if (vm.count("pmode") && options.m_pmode.empty()) throw xrt_core::error("Power mode not specified"); - if (vm.count("format") && m_format.empty()) + if (vm.count("format") && options.m_format.empty()) throw xrt_core::error("Output format not specified"); - if (!m_output.empty() && !XBU::getForce() && std::filesystem::exists(m_output)) - throw xrt_core::error((boost::format("Output file already exists: '%s'") % m_output).str()); + if (!options.m_output.empty() && !XBU::getForce() && std::filesystem::exists(options.m_output)) + throw xrt_core::error((boost::format("Output file already exists: '%s'") % options.m_output).str()); - if (m_tests_to_run.empty()) + if (options.m_tests_to_run.empty()) throw xrt_core::error("No test given to validate against."); // Validate the user test requests - for (auto &userTestName : m_tests_to_run) { + for (auto &userTestName : options.m_tests_to_run) { const auto validateTestName = boost::algorithm::to_lower_copy(userTestName); - if ((validateTestName == "all") && (m_tests_to_run.size() > 1)) + if ((validateTestName == "all") && (options.m_tests_to_run.size() > 1)) throw xrt_core::error("The 'all' value for the tests to run cannot be used with any other named tests."); - if ((validateTestName == "quick") && (m_tests_to_run.size() > 1)) + if ((validateTestName == "quick") && (options.m_tests_to_run.size() > 1)) throw xrt_core::error("The 'quick' value for the tests to run cannot be used with any other name tests."); // Verify the current user test request exists in the test suite @@ -575,13 +553,13 @@ SubCmdValidate::handle_errors_and_validate_tests(po::variables_map& vm, validatedTests.push_back(validateTestName); } //check if param option is provided - if (!m_param.empty()) { + if (!options.m_param.empty()) { XBU::verbose("Sub command: --param"); - boost::split(param, m_param, boost::is_any_of(":")); // eg: dma:block-size:1024 + boost::split(param, options.m_param, boost::is_any_of(":")); // eg: dma:block-size:1024 //check parameter format if (param.size() != 3) - throw xrt_core::error((boost::format("Invalid parameter format (expected 3 positional arguments): '%s'") % m_param).str()); + throw xrt_core::error((boost::format("Invalid parameter format (expected 3 positional arguments): '%s'") % options.m_param).str()); //check test case name doesTestExist(param[0], testNameDescription); @@ -599,8 +577,10 @@ SubCmdValidate::execute(const SubCmdOptions& _options) const { // Parse sub-command ... po::variables_map vm; + SubCmdValidateOptions options; try{ const auto unrecognized_options = process_arguments(vm, _options, false); + fill_option_values(vm, options); if (!unrecognized_options.empty()) { @@ -614,13 +594,14 @@ SubCmdValidate::execute(const SubCmdOptions& _options) const catch (const boost::program_options::error& e) { std::cerr << boost::format("ERROR: %s\n") % e.what(); - print_help_internal(); + print_help_internal(options); throw xrt_core::error(std::errc::operation_canceled); } + // Check to see if help was requested or no command was found - if (m_help) { - print_help_internal(); + if (options.m_help) { + print_help_internal(options); return; } @@ -628,15 +609,15 @@ SubCmdValidate::execute(const SubCmdOptions& _options) const Report::SchemaVersion schemaVersion = Report::SchemaVersion::unknown; // Output schema version std::vector param; std::vector validatedTests; - std::string validateXclbinPath = m_xclbin_location; + std::string validateXclbinPath = options.m_xclbin_path; try { // Output Format - schemaVersion = Report::getSchemaDescription(m_format).schemaVersion; + schemaVersion = Report::getSchemaDescription(options.m_format).schemaVersion; if (schemaVersion == Report::SchemaVersion::unknown) - throw xrt_core::error((boost::format("Unknown output format: '%s'") % m_format).str()); + throw xrt_core::error((boost::format("Unknown output format: '%s'") % options.m_format).str()); // All Error Handling for xrt-smi validate should go here - handle_errors_and_validate_tests(vm, validatedTests, param); + handle_errors_and_validate_tests(vm, options, validatedTests, param); // check if xclbin folder path is provided if (!validateXclbinPath.empty()) { @@ -651,7 +632,7 @@ SubCmdValidate::execute(const SubCmdOptions& _options) const } catch (const xrt_core::error& e) { // Catch only the exceptions that we have generated earlier std::cerr << boost::format("ERROR: %s\n") % e.what(); - print_help_internal(); + print_help_internal(options); throw xrt_core::error(std::errc::operation_canceled); } @@ -659,7 +640,7 @@ SubCmdValidate::execute(const SubCmdOptions& _options) const // Find device of interest std::shared_ptr device; try { - device = XBU::get_device(boost::algorithm::to_lower_copy(m_device), true /*inUserDomain*/); + device = XBU::get_device(boost::algorithm::to_lower_copy(options.m_device), true /*inUserDomain*/); } catch (const std::runtime_error& e) { // Catch only the exceptions that we have generated earlier std::cerr << boost::format("ERROR: %s\n") % e.what(); @@ -668,10 +649,10 @@ SubCmdValidate::execute(const SubCmdOptions& _options) const const auto& configs = JSONConfigurable::parse_configuration_tree(m_commandConfig); auto testOptionsMap = JSONConfigurable::extract_subcmd_config(testSuite, configs, getConfigName(), std::string("test")); - const std::string& deviceClass = XBU::get_device_class(m_device, true); + const std::string& deviceClass = XBU::get_device_class(options.m_device, true); auto it = testOptionsMap.find(deviceClass); if (it == testOptionsMap.end()) - XBU::throw_cancel(boost::format("Invalid device class %s. Device: %s") % deviceClass % m_device); + XBU::throw_cancel(boost::format("Invalid device class %s. Device: %s") % deviceClass % options.m_device); std::vector>& testOptions = it->second; // Collect all of the tests of interests @@ -722,25 +703,25 @@ SubCmdValidate::execute(const SubCmdOptions& _options) const const auto curr_mode = xrt_core::device_query_default(device, 0); //--pmode try { - if (!m_pmode.empty()) { + if (!options.m_pmode.empty()) { XBU::verbose("Sub command: --param"); - if (boost::iequals(m_pmode, "DEFAULT")) { + if (boost::iequals(options.m_pmode, "DEFAULT")) { xrt_core::device_update(device.get(), xrt_core::query::performance_mode::power_type::basic); // default } - else if (boost::iequals(m_pmode, "PERFORMANCE")) { + else if (boost::iequals(options.m_pmode, "PERFORMANCE")) { xrt_core::device_update(device.get(), xrt_core::query::performance_mode::power_type::performance); } - else if (boost::iequals(m_pmode, "TURBO")) { + else if (boost::iequals(options.m_pmode, "TURBO")) { xrt_core::device_update(device.get(), xrt_core::query::performance_mode::power_type::turbo); } - else if (boost::iequals(m_pmode, "POWERSAVER") || boost::iequals(m_pmode, "BALANCED")) { - throw xrt_core::error(boost::str(boost::format("No tests are supported in %s mode\n") % m_pmode)); + else if (boost::iequals(options.m_pmode, "POWERSAVER") || boost::iequals(options.m_pmode, "BALANCED")) { + throw xrt_core::error(boost::str(boost::format("No tests are supported in %s mode\n") % options.m_pmode)); } else { - throw xrt_core::error(boost::str(boost::format("Invalid pmode value: '%s'\n") % m_pmode)); + throw xrt_core::error(boost::str(boost::format("Invalid pmode value: '%s'\n") % options.m_pmode)); } - XBU::verbose(boost::str(boost::format("Setting power mode to `%s` \n") % m_pmode)); + XBU::verbose(boost::str(boost::format("Setting power mode to `%s` \n") % options.m_pmode)); } else { xrt_core::device_update(device.get(), xrt_core::query::performance_mode::power_type::performance); @@ -768,17 +749,29 @@ SubCmdValidate::execute(const SubCmdOptions& _options) const } // -- Write output file ---------------------------------------------- - if (!m_output.empty()) { + if (!options.m_output.empty()) { std::ofstream fOutput; - fOutput.open(m_output, std::ios::out | std::ios::binary); + fOutput.open(options.m_output, std::ios::out | std::ios::binary); if (!fOutput.is_open()) - throw xrt_core::error((boost::format("Unable to open the file '%s' for writing.") % m_output).str()); + throw xrt_core::error((boost::format("Unable to open the file '%s' for writing.") % options.m_output).str()); fOutput << oSchemaOutput.str(); - std::cout << boost::format("Successfully wrote the %s file: %s") % m_format % m_output << std::endl; + std::cout << boost::format("Successfully wrote the %s file: %s") % options.m_format % options.m_output << std::endl; } if (has_failures == true) throw xrt_core::error(std::errc::operation_canceled); } + +void SubCmdValidate::fill_option_values(const po::variables_map& vm, SubCmdValidateOptions& options) const +{ + options.m_device = vm.count("device") ? vm["device"].as() : ""; + options.m_format = vm.count("format") ? vm["format"].as() : "JSON"; + options.m_output = vm.count("output") ? vm["output"].as() : ""; + options.m_param = vm.count("param") ? vm["param"].as() : ""; + options.m_xclbin_path = vm.count("path") ? vm["path"].as() : ""; + options.m_pmode = vm.count("pmode") ? vm["pmode"].as() : ""; + options.m_tests_to_run = vm.count("run") ? vm["run"].as>() : std::vector({"all"}); + options.m_help = vm.count("help") ? vm["help"].as() : false; +} \ No newline at end of file diff --git a/src/runtime_src/core/tools/xbutil2/SubCmdValidate.h b/src/runtime_src/core/tools/xbutil2/SubCmdValidate.h index 95a86886d18..740c81ae9ad 100644 --- a/src/runtime_src/core/tools/xbutil2/SubCmdValidate.h +++ b/src/runtime_src/core/tools/xbutil2/SubCmdValidate.h @@ -10,6 +10,17 @@ #include "tools/common/XBHelpMenus.h" #include "SubCmdJsonObjects.h" +struct SubCmdValidateOptions { + std::string m_device; + std::string m_format; + std::string m_output; + std::string m_param; + std::string m_xclbin_path; + std::string m_pmode; + std::vector m_tests_to_run; + bool m_help; +}; + class SubCmdValidate : public SubCmd { public: virtual void execute(const SubCmdOptions &_options) const; @@ -18,21 +29,15 @@ class SubCmdValidate : public SubCmd { SubCmdValidate(bool _isHidden, bool _isDepricated, bool _isPreliminary, const boost::property_tree::ptree& configurations, const boost::property_tree::ptree& config_tree); private: - std::string m_device; - std::vector m_tests_to_run; - std::string m_format; - std::string m_output; - std::string m_param; - std::string m_xclbin_location; - std::string m_pmode; - bool m_help; JsonConfig m_jsonConfig; - void print_help_internal() const; - void handle_errors_and_validate_tests(boost::program_options::variables_map&, + void fill_option_values(const po::variables_map& vm, SubCmdValidateOptions& options) const; + void print_help_internal(const SubCmdValidateOptions& ) const; + void handle_errors_and_validate_tests(const boost::program_options::variables_map&, + const SubCmdValidateOptions&, std::vector&, std::vector&) const; - XBUtilities::VectorPairStrings getTestNameDescriptions(const bool addAdditionOptions) const; + XBUtilities::VectorPairStrings getTestNameDescriptions(const SubCmdValidateOptions&, const bool addAdditionOptions) const; }; #endif diff --git a/src/runtime_src/core/tools/xbutil2/xbutil.cpp b/src/runtime_src/core/tools/xbutil2/xbutil.cpp index 85e2525109c..379c77f3ace 100644 --- a/src/runtime_src/core/tools/xbutil2/xbutil.cpp +++ b/src/runtime_src/core/tools/xbutil2/xbutil.cpp @@ -84,8 +84,11 @@ int main( int argc, char** argv ) std::istringstream command_config_stream(command_config); boost::property_tree::read_json(command_config_stream, configTree); + /*TODO: xrt-smi rearchitecture + * This should be a device query to get the path of the xrt_smi_config.json file + */ boost::property_tree::ptree configTreeMain; - XBValidateUtils::loadConfigFile("config.h", configTreeMain); + XBValidateUtils::loadConfigFile("xrt_smi_config.json", configTreeMain); { // Syntax: SubCmdClass( IsHidden, IsDepricated, IsPreliminary) subCommands.emplace_back(std::make_shared< SubCmdExamine >(false, false, false, configTree)); diff --git a/src/runtime_src/core/tools/xbutil2/xrt_smi_config.json b/src/runtime_src/core/tools/xbutil2/xrt_smi_config.json new file mode 100644 index 00000000000..b87f365a4a5 --- /dev/null +++ b/src/runtime_src/core/tools/xbutil2/xrt_smi_config.json @@ -0,0 +1,194 @@ +{ + "subcommands": + [{ + "name" : "validate", + "description" : "Validates the given device by executing the platform's validate executable.", + "tag" : "basic", + "options" : + [ + { + "name": "device", + "alias": "d", + "description": "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", + "tag": "basic", + "default_value": "", + "option_type": "common", + "value_type" : "string" + }, + { + "name": "format", + "alias": "f", + "description": "Report output format", + "tag": "basic", + "default_value": "JSON", + "option_type": "common", + "value_type" : "string" + }, + { + "name": "output", + "alias": "o", + "description" : "Direct the output to the given file", + "tag": "basic", + "default_value": "", + "option_type": "common", + "value_type" : "string" + }, + { + "name": "help", + "alias": "h", + "description" : "Help to use this sub-command", + "tag": "basic", + "default_value": "", + "option_type": "common", + "value_type" : "none" + }, + { + "name" : "run", + "alias" : "r", + "description" : "Run a subset of the test suite", + "tag" : "basic", + "option_type": "common", + "value_type" : "array", + "options" : [ + { + "name" : "latency", + "tag" : "basic", + "description" : "Run end-to-end latency test" + }, + { + "name" : "throughput", + "tag" : "basic", + "description" : "Run end-to-end throughput test" + }, + { + "name" : "cmd-chain-latency", + "tag" : "basic", + "description" : "Run command chain latency test" + }, + { + "name" : "cmd-chain-throughput", + "tag" : "basic", + "description" : "Run end-to-end throughput test using command chaining" + }, + { + "name" : "df-bw", + "tag" : "basic", + "description" : "Run dataflow bandwidth test" + }, + { + "name" : "tct-one-col", + "tag" : "basic", + "description" : "Run TCT test with one column" + }, + { + "name" : "tct-all-col", + "tag" : "basic", + "description" : "Run TCT test with all columns" + }, + { + "name" : "gemm", + "tag" : "basic", + "description" : "Run GEMM test" + }, + { + "name" : "aie-reconfig-overhead", + "tag" : "advanced", + "description" : "Run AIE reconfiguration overhead test" + }, + { + "name" : "spatial-sharing-overhead", + "tag" : "advanced", + "description" : "Run spatial sharing overhead test" + }, + { + "name" : "temporal-sharing-overhead", + "tag" : "advanced", + "description" : "Run temporal sharing overhead test" + } + ] + }, + { + "name" : "path", + "alias" : "p", + "description" : "Path to the directory containing validate xclbins", + "tag" : "basic", + "default_value": "", + "option_type": "hidden", + "value_type" : "string" + }, + { + "name" : "param", + "description" : "Extended parameter for a given test. Format: ::", + "tag" : "basic", + "option_type": "hidden", + "default_value": "", + "value_type" : "string" + }, + { + "name" : "pmode", + "description" : "Specify which power mode to run the benchmarks in. Note: Some tests might be unavailable for some modes", + "tag" : "basic", + "option_type": "hidden", + "default_value": "", + "value_type" : "string" + } + ] + }, + { + "name" : "examine", + "tag" : "basic", + "description": "This command will 'examine' the state of the system/device and will generate a report of interest in a text or JSON format.", + "options": + [ + { + "name": "device", + "description": "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", + "tag": "devl", + "value_type": "string" + }, + { + "name": "format", + "description": "Report output format", + "tag": "devl", + "value_type": "string" + }, + { + "name": "report", + "description": "The type of report to be produced. Reports currently available are:", + "tag": "basic", + "options": [ + { + "name": "aie-partitions", + "tag": "basic", + "description": "AIE partition information" + }, + { + "name": "telemetry", + "tag": "devl", + "description": "Telemetry data for the device" + } + ] + } + ] + }, + { + "name" : "configure", + "tag" : "devl", + "description" : "Device and host configuration.", + "options" : + [ + { + "name": "device", + "description": "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", + "tag": "devl", + "value_type" : "string" + }, + { + "name": "pmode", + "description": "Modes: default, powersaver, balanced, performance, turbo", + "tag": "basic", + "value_type": "string" + } + ] + }] +} \ No newline at end of file From 1b762b314bd826aa9351827d4e4ae91d8bea3975 Mon Sep 17 00:00:00 2001 From: Akshay Tondak Date: Fri, 13 Dec 2024 12:12:37 -0800 Subject: [PATCH 03/19] Review comment updates and XRT standalone build failure fix Signed-off-by: Akshay Tondak --- .../core/tools/xbutil2/SubCmdJsonObjects.cpp | 17 +++++++++----- .../core/tools/xbutil2/SubCmdJsonObjects.h | 22 ++++++++----------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/runtime_src/core/tools/xbutil2/SubCmdJsonObjects.cpp b/src/runtime_src/core/tools/xbutil2/SubCmdJsonObjects.cpp index e3275c0ad71..668f24a4a0e 100644 --- a/src/runtime_src/core/tools/xbutil2/SubCmdJsonObjects.cpp +++ b/src/runtime_src/core/tools/xbutil2/SubCmdJsonObjects.cpp @@ -1,5 +1,12 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved. + #include +#include +#include +#include "boost/property_tree/ptree.hpp" +#include "boost/program_options.hpp" #include "SubCmdJsonObjects.h" void @@ -27,7 +34,7 @@ SubCommandOption::addProgramOption(po::options_description& options, const std:: throw std::runtime_error("Invalid value type for option " + m_name); } switch (valueType->second){ - case ValueType::BOOL: + case ValueType::boolean: { auto defaultVal = m_defaultValue == "true" ? true : false; options.add_options()((m_name + "," + m_alias).c_str() @@ -35,21 +42,21 @@ SubCommandOption::addProgramOption(po::options_description& options, const std:: , m_description.c_str()); break; } - case ValueType::STRING: + case ValueType::string: { options.add_options()((m_name + "," + m_alias).c_str() , po::value()->implicit_value(m_defaultValue) , m_description.c_str()); break; } - case ValueType::ARRAY: + case ValueType::array: { options.add_options()((m_name + "," + m_alias).c_str() , po::value>()->multitoken()->zero_tokens() , m_description.c_str()); break; } - case ValueType::NONE: + case ValueType::none: { options.add_options()((m_name + "," + m_alias).c_str() , po::bool_switch() @@ -150,4 +157,4 @@ JsonConfig::printConfigurations() const value2.printOption(); } } -} \ No newline at end of file +} diff --git a/src/runtime_src/core/tools/xbutil2/SubCmdJsonObjects.h b/src/runtime_src/core/tools/xbutil2/SubCmdJsonObjects.h index 5dbd12c2485..964c17dbb82 100644 --- a/src/runtime_src/core/tools/xbutil2/SubCmdJsonObjects.h +++ b/src/runtime_src/core/tools/xbutil2/SubCmdJsonObjects.h @@ -1,10 +1,9 @@ // SPDX-License-Identifier: Apache-2.0 -// Copyright (C) 2022-2024 Advanced Micro Devices, Inc. All rights reserved. +// Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved. #pragma once #include -#include #include #include "boost/property_tree/ptree.hpp" @@ -22,13 +21,11 @@ static constexpr std::string_view const_options_literal = "options"; namespace po = boost::program_options; namespace pt = boost::property_tree; -using variantType = std::variant>; - enum class ValueType { - BOOL, - STRING, - ARRAY, - NONE + boolean, + string, + array, + none }; class OptionBasic { @@ -71,10 +68,10 @@ class SubCommandOption : public OptionBasic { protected: const std::unordered_map m_valueTypeMap = { - {"bool", ValueType::BOOL}, - {"string", ValueType::STRING}, - {"array", ValueType::ARRAY}, - {"none", ValueType::NONE} + {"bool", ValueType::boolean}, + {"string", ValueType::string}, + {"array", ValueType::array}, + {"none", ValueType::none} }; public: @@ -139,7 +136,6 @@ class JsonConfig { std::unordered_map m_subCommandMap; std::unordered_map createSubCommands(const pt::ptree& pt, const std::string& subCommand); - std::string JsonConfig::handleOptionValue(const variantType& value) const; public: JsonConfig(const pt::ptree& configurations, const std::string& subCommand) : m_subCommandMap(createSubCommands(configurations, subCommand)) From 09dd662866a2474c080334879bf49b9ae6d10a5d Mon Sep 17 00:00:00 2001 From: Akshay Tondak Date: Fri, 13 Dec 2024 15:00:44 -0800 Subject: [PATCH 04/19] Removed extended keys options API Signed-off-by: Akshay Tondak --- .../core/tools/xbutil2/SubCmdValidate.cpp | 28 ------------------- .../core/tools/xbutil2/xrt_smi_config.json | 2 +- 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/src/runtime_src/core/tools/xbutil2/SubCmdValidate.cpp b/src/runtime_src/core/tools/xbutil2/SubCmdValidate.cpp index 8949e0717a9..d215194b859 100644 --- a/src/runtime_src/core/tools/xbutil2/SubCmdValidate.cpp +++ b/src/runtime_src/core/tools/xbutil2/SubCmdValidate.cpp @@ -375,34 +375,6 @@ static std::vector extendedKeysCollection = { {"dma", "block-size", "Memory transfer size (bytes)"} }; -std::string -extendedKeysOptions() -{ - static unsigned int m_maxColumnWidth = 100; - std::stringstream fmt_output; - // Formatting color parameters - const std::string fgc_header = XBU::is_escape_codes_disabled() ? "" : EscapeCodes::fgcolor(EscapeCodes::FGC_HEADER).string(); - const std::string fgc_optionName = XBU::is_escape_codes_disabled() ? "" : EscapeCodes::fgcolor(EscapeCodes::FGC_OPTION).string(); - const std::string fgc_optionBody = XBU::is_escape_codes_disabled() ? "" : EscapeCodes::fgcolor(EscapeCodes::FGC_OPTION_BODY).string(); - const std::string fgc_reset = XBU::is_escape_codes_disabled() ? "" : EscapeCodes::fgcolor::reset(); - - // Report option group name (if defined) - boost::format fmtHeader(fgc_header + "\n%s:\n" + fgc_reset); - fmt_output << fmtHeader % "EXTENDED KEYS"; - - // Report the options - boost::format fmtOption(fgc_optionName + " %-18s " + fgc_optionBody + "- %s\n" + fgc_reset); - unsigned int optionDescTab = 23; - - for (auto& param : extendedKeysCollection) { - const auto key_desc = (boost::format("%s: - %s") % param.param_name % param.description).str(); - const auto& formattedString = XBU::wrap_paragraphs(key_desc, optionDescTab, m_maxColumnWidth - optionDescTab, false); - fmt_output << fmtOption % param.test_name % formattedString; - } - - return fmt_output.str(); -} - } //end anonymous namespace diff --git a/src/runtime_src/core/tools/xbutil2/xrt_smi_config.json b/src/runtime_src/core/tools/xbutil2/xrt_smi_config.json index b87f365a4a5..c9e472d4822 100644 --- a/src/runtime_src/core/tools/xbutil2/xrt_smi_config.json +++ b/src/runtime_src/core/tools/xbutil2/xrt_smi_config.json @@ -191,4 +191,4 @@ } ] }] -} \ No newline at end of file +} From 6b7ab55c532431fb05bf7669571db1cde64266c6 Mon Sep 17 00:00:00 2001 From: Akshay Tondak Date: Mon, 16 Dec 2024 12:10:50 -0800 Subject: [PATCH 05/19] Build fail try 1 Signed-off-by: Akshay Tondak --- src/runtime_src/core/tools/xbutil2/xbutil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime_src/core/tools/xbutil2/xbutil.cpp b/src/runtime_src/core/tools/xbutil2/xbutil.cpp index 379c77f3ace..8a9b77ac215 100644 --- a/src/runtime_src/core/tools/xbutil2/xbutil.cpp +++ b/src/runtime_src/core/tools/xbutil2/xbutil.cpp @@ -88,7 +88,7 @@ int main( int argc, char** argv ) * This should be a device query to get the path of the xrt_smi_config.json file */ boost::property_tree::ptree configTreeMain; - XBValidateUtils::loadConfigFile("xrt_smi_config.json", configTreeMain); + XBValidateUtils::loadConfigFile("./xrt_smi_config.json", configTreeMain); { // Syntax: SubCmdClass( IsHidden, IsDepricated, IsPreliminary) subCommands.emplace_back(std::make_shared< SubCmdExamine >(false, false, false, configTree)); From d4e0c9ad18a1beba93dfbcd000141632a2538509 Mon Sep 17 00:00:00 2001 From: Akshay Tondak Date: Mon, 16 Dec 2024 14:42:33 -0800 Subject: [PATCH 06/19] Build failure fix Signed-off-by: Akshay Tondak --- src/runtime_src/core/tools/xbutil2/xbutil.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/runtime_src/core/tools/xbutil2/xbutil.cpp b/src/runtime_src/core/tools/xbutil2/xbutil.cpp index 8a9b77ac215..1279d2ed399 100644 --- a/src/runtime_src/core/tools/xbutil2/xbutil.cpp +++ b/src/runtime_src/core/tools/xbutil2/xbutil.cpp @@ -18,6 +18,7 @@ #include "tools/common/XBMain.h" #include "tools/common/XBUtilities.h" #include "tools/common/JSONConfigurable.h" +#include "core/common/module_loader.h" // System include files #include @@ -88,7 +89,8 @@ int main( int argc, char** argv ) * This should be a device query to get the path of the xrt_smi_config.json file */ boost::property_tree::ptree configTreeMain; - XBValidateUtils::loadConfigFile("./xrt_smi_config.json", configTreeMain); + std::filesystem::path configPath = xrt_core::environment::xilinx_xrt()/"bin/xrt_smi_config.json"; + XBValidateUtils::loadConfigFile(configPath.string(), configTreeMain); { // Syntax: SubCmdClass( IsHidden, IsDepricated, IsPreliminary) subCommands.emplace_back(std::make_shared< SubCmdExamine >(false, false, false, configTree)); From 7f99c919885bfef7f182319361c609dd4b75f759 Mon Sep 17 00:00:00 2001 From: Akshay Tondak Date: Tue, 31 Dec 2024 15:44:19 -0800 Subject: [PATCH 07/19] Change to device query Signed-off-by: Akshay Tondak --- src/runtime_src/core/tools/common/SubCmd.cpp | 12 ++++++++ src/runtime_src/core/tools/common/SubCmd.h | 3 ++ .../{xbutil2 => common}/SubCmdJsonObjects.cpp | 0 .../{xbutil2 => common}/SubCmdJsonObjects.h | 1 + src/runtime_src/core/tools/common/XBMain.cpp | 11 +++++++ .../core/tools/common/XBUtilities.cpp | 30 +++++++++++++++++++ .../core/tools/common/XBUtilities.h | 1 + .../common/tests/TestValidateUtilities.cpp | 30 +------------------ .../common/tests/TestValidateUtilities.h | 1 - .../core/tools/xbflash2/CMakeLists.txt | 1 + .../core/tools/xbmgmt2/CMakeLists.txt | 1 + .../core/tools/xbutil2/CMakeLists.txt | 2 +- .../core/tools/xbutil2/SubCmdValidate.cpp | 11 +------ .../core/tools/xbutil2/SubCmdValidate.h | 4 +-- src/runtime_src/core/tools/xbutil2/xbutil.cpp | 8 +---- 15 files changed, 65 insertions(+), 51 deletions(-) rename src/runtime_src/core/tools/{xbutil2 => common}/SubCmdJsonObjects.cpp (100%) rename src/runtime_src/core/tools/{xbutil2 => common}/SubCmdJsonObjects.h (99%) diff --git a/src/runtime_src/core/tools/common/SubCmd.cpp b/src/runtime_src/core/tools/common/SubCmd.cpp index f6f67b8dbfa..eb9b0a9dd61 100644 --- a/src/runtime_src/core/tools/common/SubCmd.cpp +++ b/src/runtime_src/core/tools/common/SubCmd.cpp @@ -167,3 +167,15 @@ SubCmd::checkForSubOption(const boost::program_options::variables_map& vm, const return option; } +void +SubCmd::setOptionConfig(const boost::property_tree::ptree &config) +{ + m_jsonConfig = JsonConfig(config.get_child("subcommands"), getName()); + try{ + m_jsonConfig.addProgramOptions(m_commonOptions, "common", getName()); + m_jsonConfig.addProgramOptions(m_hiddenOptions, "hidden", getName()); + } + catch (const std::exception& e) { + std::cerr << "Error: " << e.what() << std::endl; + } +} diff --git a/src/runtime_src/core/tools/common/SubCmd.h b/src/runtime_src/core/tools/common/SubCmd.h index 2cace31780f..5c8bbfbebdb 100644 --- a/src/runtime_src/core/tools/common/SubCmd.h +++ b/src/runtime_src/core/tools/common/SubCmd.h @@ -12,6 +12,7 @@ #include #include "JSONConfigurable.h" +#include "SubCmdJsonObjects.h" #include "OptionOptions.h" class SubCmd : public JSONConfigurable { @@ -38,6 +39,7 @@ class SubCmd : public JSONConfigurable { const std::string & getExecutableName() const {return m_executableName; }; void setGlobalOptions(const boost::program_options::options_description &globalOptions) { m_globalOptions.add(globalOptions); }; + void setOptionConfig(const boost::property_tree::ptree &config); protected: const boost::program_options::options_description & getGlobalOptions() const { return m_globalOptions; }; @@ -85,6 +87,7 @@ class SubCmd : public JSONConfigurable { boost::program_options::options_description m_hiddenOptions; boost::program_options::positional_options_description m_positionals; boost::property_tree::ptree m_commandConfig; + JsonConfig m_jsonConfig; template std::vector> diff --git a/src/runtime_src/core/tools/xbutil2/SubCmdJsonObjects.cpp b/src/runtime_src/core/tools/common/SubCmdJsonObjects.cpp similarity index 100% rename from src/runtime_src/core/tools/xbutil2/SubCmdJsonObjects.cpp rename to src/runtime_src/core/tools/common/SubCmdJsonObjects.cpp diff --git a/src/runtime_src/core/tools/xbutil2/SubCmdJsonObjects.h b/src/runtime_src/core/tools/common/SubCmdJsonObjects.h similarity index 99% rename from src/runtime_src/core/tools/xbutil2/SubCmdJsonObjects.h rename to src/runtime_src/core/tools/common/SubCmdJsonObjects.h index 964c17dbb82..84087325758 100644 --- a/src/runtime_src/core/tools/xbutil2/SubCmdJsonObjects.h +++ b/src/runtime_src/core/tools/common/SubCmdJsonObjects.h @@ -140,6 +140,7 @@ class JsonConfig { JsonConfig(const pt::ptree& configurations, const std::string& subCommand) : m_subCommandMap(createSubCommands(configurations, subCommand)) {} + JsonConfig() = default; void addProgramOptions(po::options_description& options, const std::string& optionsType, const std::string& subCommand); void printConfigurations() const; diff --git a/src/runtime_src/core/tools/common/XBMain.cpp b/src/runtime_src/core/tools/common/XBMain.cpp index ffe21ebe493..c44107e0ce9 100644 --- a/src/runtime_src/core/tools/common/XBMain.cpp +++ b/src/runtime_src/core/tools/common/XBMain.cpp @@ -124,6 +124,16 @@ void main_(int argc, char** argv, sDevice = kd.second.get("bdf"); // Exit after the first item } + std::shared_ptr device; + try { + device = XBU::get_device(boost::algorithm::to_lower_copy(sDevice), true /*inUserDomain*/); + } catch (const std::runtime_error& e) { + // Catch only the exceptions that we have generated earlier + std::cerr << boost::format("ERROR: %s\n") % e.what(); + } + boost::property_tree::ptree configTreeMain; + const auto config_file_name = xrt_core::device_query(device, xrt_core::query::xrt_smi_config::type::options_config); + XBU::loadConfigFile(config_file_name, configTreeMain); // If there is a device value, parse for valid subcommands for this device. SubCmdsCollection devSubCmds; @@ -172,6 +182,7 @@ void main_(int argc, char** argv, } subCommand->setGlobalOptions(globalSubCmdOptions); + subCommand->setOptionConfig(configTreeMain); // -- Execute the sub-command subCommand->execute(subcmd_options); diff --git a/src/runtime_src/core/tools/common/XBUtilities.cpp b/src/runtime_src/core/tools/common/XBUtilities.cpp index d9ce655f122..bd83b31c33e 100755 --- a/src/runtime_src/core/tools/common/XBUtilities.cpp +++ b/src/runtime_src/core/tools/common/XBUtilities.cpp @@ -774,3 +774,33 @@ fill_xrt_versions(const boost::property_tree::ptree& pt_xrt, //no device available } } + +void +XBUtilities::loadConfigFile(const std::string &configPath, boost::property_tree::ptree &configTree) +{ + try + { + // Open the JSON file + std::ifstream jsonFile(configPath); + if (!jsonFile.is_open()) + { + throw std::runtime_error("Failed to open " + configPath); + } + + // Read the JSON file into the property tree + boost::property_tree::read_json(jsonFile, configTree); + + // Close the JSON file + jsonFile.close(); + } + catch (const boost::property_tree::json_parser_error &e) + { + std::cerr << "Error parsing JSON file: " << e.what() << std::endl; + throw; + } + catch (const std::exception &e) + { + std::cerr << "Error: " << e.what() << std::endl; + throw; + } +}// end of namespace XBValidateUtils diff --git a/src/runtime_src/core/tools/common/XBUtilities.h b/src/runtime_src/core/tools/common/XBUtilities.h index ce409835ffc..b97c992eeda 100644 --- a/src/runtime_src/core/tools/common/XBUtilities.h +++ b/src/runtime_src/core/tools/common/XBUtilities.h @@ -153,6 +153,7 @@ namespace XBUtilities { m_device->close_context(m_uuid, std::numeric_limits::max()); } }; + void loadConfigFile(const std::string& configFile, boost::property_tree::ptree& pt); }; diff --git a/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp b/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp index 602cbd5da40..f78b03f87e7 100644 --- a/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp +++ b/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp @@ -450,32 +450,4 @@ dpu_or_elf(const std::shared_ptr& dev, const xrt::xclbin& xclb return elf_path; } } -void loadConfigFile(const std::string &configPath, boost::property_tree::ptree &configTree) -{ - try - { - // Open the JSON file - std::ifstream jsonFile(configPath); - if (!jsonFile.is_open()) - { - throw std::runtime_error("Failed to open " + configPath); - } - - // Read the JSON file into the property tree - boost::property_tree::read_json(jsonFile, configTree); - - // Close the JSON file - jsonFile.close(); - } - catch (const boost::property_tree::json_parser_error &e) - { - std::cerr << "Error parsing JSON file: " << e.what() << std::endl; - throw; - } - catch (const std::exception &e) - { - std::cerr << "Error: " << e.what() << std::endl; - throw; - } -} -}// end of namespace XBValidateUtils +} //End of namespace XBValidateUtils \ No newline at end of file diff --git a/src/runtime_src/core/tools/common/tests/TestValidateUtilities.h b/src/runtime_src/core/tools/common/tests/TestValidateUtilities.h index 253d5b9c760..c2667b7f046 100644 --- a/src/runtime_src/core/tools/common/tests/TestValidateUtilities.h +++ b/src/runtime_src/core/tools/common/tests/TestValidateUtilities.h @@ -90,6 +90,5 @@ bool search_and_program_xclbin(const std::shared_ptr& dev, boo int validate_binary_file(const std::string& binaryfile); std::string dpu_or_elf(const std::shared_ptr& dev, const xrt::xclbin& xclbin, boost::property_tree::ptree& ptTest); -void loadConfigFile(const std::string& configFile, boost::property_tree::ptree& pt); } //End of namespace XBValidateUtils #endif diff --git a/src/runtime_src/core/tools/xbflash2/CMakeLists.txt b/src/runtime_src/core/tools/xbflash2/CMakeLists.txt index dce47786d9d..6250f8862ab 100755 --- a/src/runtime_src/core/tools/xbflash2/CMakeLists.txt +++ b/src/runtime_src/core/tools/xbflash2/CMakeLists.txt @@ -18,6 +18,7 @@ file(GLOB XBFLASH_BASE_FILES "../common/OptionOptions.cpp" "../common/XBHelpMenusCore.cpp" "../common/JSONConfigurable.cpp" + "../common/SubCmdJsonObjects.cpp" "../../pcie/tools/xbflash.qspi/firmware_image.cpp" "../../pcie/tools/xbflash.qspi/pcidev.cpp" "../../pcie/tools/xbflash.qspi/xqspips.cpp" diff --git a/src/runtime_src/core/tools/xbmgmt2/CMakeLists.txt b/src/runtime_src/core/tools/xbmgmt2/CMakeLists.txt index 4f6985d9a17..3f6c688ce27 100644 --- a/src/runtime_src/core/tools/xbmgmt2/CMakeLists.txt +++ b/src/runtime_src/core/tools/xbmgmt2/CMakeLists.txt @@ -10,6 +10,7 @@ file(GLOB XBMGMT_V2_BASE_FILES "../common/XBUtilities.cpp" "../common/JSONConfigurable.cpp" "../common/SubCmd.cpp" + "../common/SubCmdJsonObjects.cpp" "../common/SubCmdConfigureInternal.cpp" "../common/SubCmdExamineInternal.cpp" "../common/XBHelpMenusCore.cpp" diff --git a/src/runtime_src/core/tools/xbutil2/CMakeLists.txt b/src/runtime_src/core/tools/xbutil2/CMakeLists.txt index 03adcc01e37..9a3ce4ebac6 100644 --- a/src/runtime_src/core/tools/xbutil2/CMakeLists.txt +++ b/src/runtime_src/core/tools/xbutil2/CMakeLists.txt @@ -11,6 +11,7 @@ file(GLOB XBUTIL_V2_BASE_FILES "../common/XBUtilities.cpp" "../common/JSONConfigurable.cpp" "../common/SubCmd.cpp" + "../common/SubCmdJsonObjects.cpp" "../common/SubCmdConfigureInternal.cpp" "../common/SubCmdExamineInternal.cpp" "../common/OptionOptions.cpp" @@ -41,7 +42,6 @@ file(GLOB XBUTIL_V2_SUBCMD_FILES "SubCmdValidate.cpp" "SubCmdAdvanced.cpp" "SubCmdConfigure.cpp" - "SubCmdJsonObjects.cpp" "OO_Clock.cpp" "OO_MemRead.cpp" "OO_MemWrite.cpp" diff --git a/src/runtime_src/core/tools/xbutil2/SubCmdValidate.cpp b/src/runtime_src/core/tools/xbutil2/SubCmdValidate.cpp index d215194b859..d7b569f26eb 100644 --- a/src/runtime_src/core/tools/xbutil2/SubCmdValidate.cpp +++ b/src/runtime_src/core/tools/xbutil2/SubCmdValidate.cpp @@ -411,10 +411,9 @@ static std::map>> json static const std::pair all_test = {"all", "All applicable validate tests will be executed (default)"}; static const std::pair quick_test = {"quick", "Run a subset of four tests: \n1. latency\n2. throughput\n3. cmd-chain-latency\n4. cmd-chain-throughput"}; -SubCmdValidate::SubCmdValidate(bool _isHidden, bool _isDepricated, bool _isPreliminary, const boost::property_tree::ptree& configurations, const boost::property_tree::ptree& configTree) +SubCmdValidate::SubCmdValidate(bool _isHidden, bool _isDepricated, bool _isPreliminary, const boost::property_tree::ptree& configurations) : SubCmd("validate", "Validates the basic device acceleration functionality") - , m_jsonConfig (JsonConfig(configTree.get_child("subcommands"), "validate")) { const std::string longDescription = "Validates the given device by executing the platform's validate executable."; setLongDescription(longDescription); @@ -433,14 +432,6 @@ SubCmdValidate::SubCmdValidate(bool _isHidden, bool _isDepricated, bool _isPreli common_tests.emplace_back(all_test); common_tests.emplace_back(quick_test); static const auto formatRunValues = XBU::create_suboption_list_map("", jsonOptions, common_tests); - - try{ - m_jsonConfig.addProgramOptions(m_commonOptions, "common", getName()); - m_jsonConfig.addProgramOptions(m_hiddenOptions, "hidden", getName()); - } - catch (const std::exception& e) { - std::cerr << "Error: " << e.what() << std::endl; - } } void diff --git a/src/runtime_src/core/tools/xbutil2/SubCmdValidate.h b/src/runtime_src/core/tools/xbutil2/SubCmdValidate.h index 740c81ae9ad..ed07a712186 100644 --- a/src/runtime_src/core/tools/xbutil2/SubCmdValidate.h +++ b/src/runtime_src/core/tools/xbutil2/SubCmdValidate.h @@ -8,7 +8,6 @@ #include #include "tools/common/SubCmd.h" #include "tools/common/XBHelpMenus.h" -#include "SubCmdJsonObjects.h" struct SubCmdValidateOptions { std::string m_device; @@ -26,10 +25,9 @@ class SubCmdValidate : public SubCmd { virtual void execute(const SubCmdOptions &_options) const; public: - SubCmdValidate(bool _isHidden, bool _isDepricated, bool _isPreliminary, const boost::property_tree::ptree& configurations, const boost::property_tree::ptree& config_tree); + SubCmdValidate(bool _isHidden, bool _isDepricated, bool _isPreliminary, const boost::property_tree::ptree& configurations); private: - JsonConfig m_jsonConfig; void fill_option_values(const po::variables_map& vm, SubCmdValidateOptions& options) const; void print_help_internal(const SubCmdValidateOptions& ) const; diff --git a/src/runtime_src/core/tools/xbutil2/xbutil.cpp b/src/runtime_src/core/tools/xbutil2/xbutil.cpp index 1279d2ed399..e46875e919a 100644 --- a/src/runtime_src/core/tools/xbutil2/xbutil.cpp +++ b/src/runtime_src/core/tools/xbutil2/xbutil.cpp @@ -85,12 +85,6 @@ int main( int argc, char** argv ) std::istringstream command_config_stream(command_config); boost::property_tree::read_json(command_config_stream, configTree); - /*TODO: xrt-smi rearchitecture - * This should be a device query to get the path of the xrt_smi_config.json file - */ - boost::property_tree::ptree configTreeMain; - std::filesystem::path configPath = xrt_core::environment::xilinx_xrt()/"bin/xrt_smi_config.json"; - XBValidateUtils::loadConfigFile(configPath.string(), configTreeMain); { // Syntax: SubCmdClass( IsHidden, IsDepricated, IsPreliminary) subCommands.emplace_back(std::make_shared< SubCmdExamine >(false, false, false, configTree)); @@ -102,7 +96,7 @@ int main( int argc, char** argv ) populateSubCommandsFromJSON(subCommands, executable); #ifdef ENABLE_NATIVE_SUBCMDS_AND_REPORTS - subCommands.emplace_back(std::make_shared< SubCmdValidate >(false, false, false, configTree, configTreeMain)); + subCommands.emplace_back(std::make_shared< SubCmdValidate >(false, false, false, configTree)); #endif subCommands.emplace_back(std::make_shared< SubCmdAdvanced >(true, false, true, configTree)); From 9a58c17156a02a7f9ef063052b5f652df67ff6d0 Mon Sep 17 00:00:00 2001 From: Akshay Tondak Date: Tue, 31 Dec 2024 16:15:23 -0800 Subject: [PATCH 08/19] Build correction Signed-off-by: Akshay Tondak --- src/runtime_src/core/tools/common/XBMain.cpp | 2 +- .../core/tools/common/tests/TestValidateUtilities.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime_src/core/tools/common/XBMain.cpp b/src/runtime_src/core/tools/common/XBMain.cpp index c44107e0ce9..81ce68f054d 100644 --- a/src/runtime_src/core/tools/common/XBMain.cpp +++ b/src/runtime_src/core/tools/common/XBMain.cpp @@ -132,7 +132,7 @@ void main_(int argc, char** argv, std::cerr << boost::format("ERROR: %s\n") % e.what(); } boost::property_tree::ptree configTreeMain; - const auto config_file_name = xrt_core::device_query(device, xrt_core::query::xrt_smi_config::type::options_config); + const std::string config_file_name = xrt_core::device_query(device, xrt_core::query::xrt_smi_config::type::options_config); XBU::loadConfigFile(config_file_name, configTreeMain); // If there is a device value, parse for valid subcommands for this device. diff --git a/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp b/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp index f78b03f87e7..d6a861560ac 100644 --- a/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp +++ b/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp @@ -450,4 +450,4 @@ dpu_or_elf(const std::shared_ptr& dev, const xrt::xclbin& xclb return elf_path; } } -} //End of namespace XBValidateUtils \ No newline at end of file +} //end of namespace XBValidateUtils From c8a5ab182613e9e9f2a9e66f916c6260d14017fe Mon Sep 17 00:00:00 2001 From: Akshay Tondak Date: Wed, 8 Jan 2025 10:15:05 -0800 Subject: [PATCH 09/19] Changing device query to string type Signed-off-by: Akshay Tondak --- src/runtime_src/core/tools/common/XBMain.cpp | 25 +++++++++---------- .../common/tests/TestValidateUtilities.cpp | 3 +-- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/runtime_src/core/tools/common/XBMain.cpp b/src/runtime_src/core/tools/common/XBMain.cpp index 81ce68f054d..53c5271db10 100644 --- a/src/runtime_src/core/tools/common/XBMain.cpp +++ b/src/runtime_src/core/tools/common/XBMain.cpp @@ -16,6 +16,7 @@ namespace XBU = XBUtilities; // 3rd Party Library - Include Files #include #include +#include namespace po = boost::program_options; @@ -124,16 +125,6 @@ void main_(int argc, char** argv, sDevice = kd.second.get("bdf"); // Exit after the first item } - std::shared_ptr device; - try { - device = XBU::get_device(boost::algorithm::to_lower_copy(sDevice), true /*inUserDomain*/); - } catch (const std::runtime_error& e) { - // Catch only the exceptions that we have generated earlier - std::cerr << boost::format("ERROR: %s\n") % e.what(); - } - boost::property_tree::ptree configTreeMain; - const std::string config_file_name = xrt_core::device_query(device, xrt_core::query::xrt_smi_config::type::options_config); - XBU::loadConfigFile(config_file_name, configTreeMain); // If there is a device value, parse for valid subcommands for this device. SubCmdsCollection devSubCmds; @@ -182,11 +173,19 @@ void main_(int argc, char** argv, } subCommand->setGlobalOptions(globalSubCmdOptions); + std::shared_ptr device; + try { + device = XBU::get_device(boost::algorithm::to_lower_copy(sDevice), true /*inUserDomain*/); + } catch (const std::runtime_error& e) { + // Catch only the exceptions that we have generated earlier + std::cerr << boost::format("ERROR: %s\n") % e.what(); + } + boost::property_tree::ptree configTreeMain; + const std::string config = xrt_core::device_query(device, xrt_core::query::xrt_smi_config::type::options_config); + std::istringstream command_config_stream(config); + boost::property_tree::read_json(command_config_stream, configTreeMain); subCommand->setOptionConfig(configTreeMain); // -- Execute the sub-command subCommand->execute(subcmd_options); } - - - diff --git a/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp b/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp index d6a861560ac..e916b3faa13 100644 --- a/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp +++ b/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include "core/common/query_requests.h" #include "core/common/module_loader.h" #include "tools/common/XBUtilities.h" @@ -450,4 +449,4 @@ dpu_or_elf(const std::shared_ptr& dev, const xrt::xclbin& xclb return elf_path; } } -} //end of namespace XBValidateUtils +}//end of namespace XBValidateUtils From ced84d517242928a078168994e6b1eaa7f354322 Mon Sep 17 00:00:00 2001 From: Akshay Tondak Date: Wed, 8 Jan 2025 15:55:36 -0800 Subject: [PATCH 10/19] Build failure fix Signed-off-by: Akshay Tondak --- src/runtime_src/core/tools/common/XBMain.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/runtime_src/core/tools/common/XBMain.cpp b/src/runtime_src/core/tools/common/XBMain.cpp index 53c5271db10..c5206449a58 100644 --- a/src/runtime_src/core/tools/common/XBMain.cpp +++ b/src/runtime_src/core/tools/common/XBMain.cpp @@ -180,11 +180,13 @@ void main_(int argc, char** argv, // Catch only the exceptions that we have generated earlier std::cerr << boost::format("ERROR: %s\n") % e.what(); } - boost::property_tree::ptree configTreeMain; - const std::string config = xrt_core::device_query(device, xrt_core::query::xrt_smi_config::type::options_config); - std::istringstream command_config_stream(config); - boost::property_tree::read_json(command_config_stream, configTreeMain); - subCommand->setOptionConfig(configTreeMain); + if (device){ + boost::property_tree::ptree configTreeMain; + const std::string config = xrt_core::device_query(device, xrt_core::query::xrt_smi_config::type::options_config); + std::istringstream command_config_stream(config); + boost::property_tree::read_json(command_config_stream, configTreeMain); + subCommand->setOptionConfig(configTreeMain); + } // -- Execute the sub-command subCommand->execute(subcmd_options); From 38527ec7f32481205aef362c85094aea18579162 Mon Sep 17 00:00:00 2001 From: Akshay Tondak Date: Wed, 8 Jan 2025 16:00:40 -0800 Subject: [PATCH 11/19] Remove TODO tasks since we moved to query requests Signed-off-by: Akshay Tondak --- .../common/tests/TestValidateUtilities.cpp | 2 +- .../core/tools/xbutil2/CMakeLists.txt | 6 - .../core/tools/xbutil2/xrt_smi_config.json | 194 ------------------ 3 files changed, 1 insertion(+), 201 deletions(-) delete mode 100644 src/runtime_src/core/tools/xbutil2/xrt_smi_config.json diff --git a/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp b/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp index e916b3faa13..70b49461e9b 100644 --- a/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp +++ b/src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp @@ -449,4 +449,4 @@ dpu_or_elf(const std::shared_ptr& dev, const xrt::xclbin& xclb return elf_path; } } -}//end of namespace XBValidateUtils +}// end of namespace XBValidateUtils diff --git a/src/runtime_src/core/tools/xbutil2/CMakeLists.txt b/src/runtime_src/core/tools/xbutil2/CMakeLists.txt index 9a3ce4ebac6..6b7313ced5a 100644 --- a/src/runtime_src/core/tools/xbutil2/CMakeLists.txt +++ b/src/runtime_src/core/tools/xbutil2/CMakeLists.txt @@ -54,8 +54,6 @@ file(GLOB XBUTIL_V2_SUBCMD_FILES "OO_Reports.cpp" ) -file(GLOB XRT_SMI_CONFIG_FILE "xrt_smi_config.json") - # Merge the files into one collection set(XBUTIL_V2_SRCS ${XBUTIL_V2_BASE_FILES} ${XBUTIL_V2_SUBCMD_FILES}) @@ -123,8 +121,4 @@ endif() install (TARGETS ${XBUTIL2_NAME} RUNTIME DESTINATION ${XRT_INSTALL_UNWRAPPED_DIR}) install (PROGRAMS ${XRT_HELPER_SCRIPTS} DESTINATION ${XRT_INSTALL_BIN_DIR}) -# TODO: xrt-smi rearchitecture. This is temporary and will be removed once -# driver stores have this config file and shim layer has device query implemented. -install (FILES ${XRT_SMI_CONFIG_FILE} DESTINATION ${XRT_INSTALL_UNWRAPPED_DIR}) -install (FILES ${XRT_SMI_CONFIG_FILE} DESTINATION ${XRT_INSTALL_BIN_DIR}) # ----------------------------------------------------------------------------- diff --git a/src/runtime_src/core/tools/xbutil2/xrt_smi_config.json b/src/runtime_src/core/tools/xbutil2/xrt_smi_config.json deleted file mode 100644 index c9e472d4822..00000000000 --- a/src/runtime_src/core/tools/xbutil2/xrt_smi_config.json +++ /dev/null @@ -1,194 +0,0 @@ -{ - "subcommands": - [{ - "name" : "validate", - "description" : "Validates the given device by executing the platform's validate executable.", - "tag" : "basic", - "options" : - [ - { - "name": "device", - "alias": "d", - "description": "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", - "tag": "basic", - "default_value": "", - "option_type": "common", - "value_type" : "string" - }, - { - "name": "format", - "alias": "f", - "description": "Report output format", - "tag": "basic", - "default_value": "JSON", - "option_type": "common", - "value_type" : "string" - }, - { - "name": "output", - "alias": "o", - "description" : "Direct the output to the given file", - "tag": "basic", - "default_value": "", - "option_type": "common", - "value_type" : "string" - }, - { - "name": "help", - "alias": "h", - "description" : "Help to use this sub-command", - "tag": "basic", - "default_value": "", - "option_type": "common", - "value_type" : "none" - }, - { - "name" : "run", - "alias" : "r", - "description" : "Run a subset of the test suite", - "tag" : "basic", - "option_type": "common", - "value_type" : "array", - "options" : [ - { - "name" : "latency", - "tag" : "basic", - "description" : "Run end-to-end latency test" - }, - { - "name" : "throughput", - "tag" : "basic", - "description" : "Run end-to-end throughput test" - }, - { - "name" : "cmd-chain-latency", - "tag" : "basic", - "description" : "Run command chain latency test" - }, - { - "name" : "cmd-chain-throughput", - "tag" : "basic", - "description" : "Run end-to-end throughput test using command chaining" - }, - { - "name" : "df-bw", - "tag" : "basic", - "description" : "Run dataflow bandwidth test" - }, - { - "name" : "tct-one-col", - "tag" : "basic", - "description" : "Run TCT test with one column" - }, - { - "name" : "tct-all-col", - "tag" : "basic", - "description" : "Run TCT test with all columns" - }, - { - "name" : "gemm", - "tag" : "basic", - "description" : "Run GEMM test" - }, - { - "name" : "aie-reconfig-overhead", - "tag" : "advanced", - "description" : "Run AIE reconfiguration overhead test" - }, - { - "name" : "spatial-sharing-overhead", - "tag" : "advanced", - "description" : "Run spatial sharing overhead test" - }, - { - "name" : "temporal-sharing-overhead", - "tag" : "advanced", - "description" : "Run temporal sharing overhead test" - } - ] - }, - { - "name" : "path", - "alias" : "p", - "description" : "Path to the directory containing validate xclbins", - "tag" : "basic", - "default_value": "", - "option_type": "hidden", - "value_type" : "string" - }, - { - "name" : "param", - "description" : "Extended parameter for a given test. Format: ::", - "tag" : "basic", - "option_type": "hidden", - "default_value": "", - "value_type" : "string" - }, - { - "name" : "pmode", - "description" : "Specify which power mode to run the benchmarks in. Note: Some tests might be unavailable for some modes", - "tag" : "basic", - "option_type": "hidden", - "default_value": "", - "value_type" : "string" - } - ] - }, - { - "name" : "examine", - "tag" : "basic", - "description": "This command will 'examine' the state of the system/device and will generate a report of interest in a text or JSON format.", - "options": - [ - { - "name": "device", - "description": "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", - "tag": "devl", - "value_type": "string" - }, - { - "name": "format", - "description": "Report output format", - "tag": "devl", - "value_type": "string" - }, - { - "name": "report", - "description": "The type of report to be produced. Reports currently available are:", - "tag": "basic", - "options": [ - { - "name": "aie-partitions", - "tag": "basic", - "description": "AIE partition information" - }, - { - "name": "telemetry", - "tag": "devl", - "description": "Telemetry data for the device" - } - ] - } - ] - }, - { - "name" : "configure", - "tag" : "devl", - "description" : "Device and host configuration.", - "options" : - [ - { - "name": "device", - "description": "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", - "tag": "devl", - "value_type" : "string" - }, - { - "name": "pmode", - "description": "Modes: default, powersaver, balanced, performance, turbo", - "tag": "basic", - "value_type": "string" - } - ] - }] -} From 85bc6958f1f31029152a4ef85bea9284be492259 Mon Sep 17 00:00:00 2001 From: Akshay Tondak Date: Thu, 9 Jan 2025 11:09:59 -0800 Subject: [PATCH 12/19] Possible pipeline test failure fix Signed-off-by: Akshay Tondak --- src/runtime_src/core/tools/common/XBMain.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/runtime_src/core/tools/common/XBMain.cpp b/src/runtime_src/core/tools/common/XBMain.cpp index c5206449a58..5763731fd4d 100644 --- a/src/runtime_src/core/tools/common/XBMain.cpp +++ b/src/runtime_src/core/tools/common/XBMain.cpp @@ -173,11 +173,15 @@ void main_(int argc, char** argv, } subCommand->setGlobalOptions(globalSubCmdOptions); + + /* xrt-smi. Tool should query device upfront and get the configurations + * from shim. This moves the resposibility for option setting to each shim + * instead of xrt-smi. + */ std::shared_ptr device; try { - device = XBU::get_device(boost::algorithm::to_lower_copy(sDevice), true /*inUserDomain*/); + device = XBU::get_device(boost::algorithm::to_lower_copy(sDevice), isUserDomain); } catch (const std::runtime_error& e) { - // Catch only the exceptions that we have generated earlier std::cerr << boost::format("ERROR: %s\n") % e.what(); } if (device){ From 2b3b9ba65c39a250170661057d841f887e4c2c66 Mon Sep 17 00:00:00 2001 From: Akshay Tondak Date: Thu, 9 Jan 2025 15:23:19 -0800 Subject: [PATCH 13/19] Disabling device query for non xrt-smi cases Signed-off-by: Akshay Tondak --- src/runtime_src/core/tools/common/XBMain.cpp | 26 +++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/runtime_src/core/tools/common/XBMain.cpp b/src/runtime_src/core/tools/common/XBMain.cpp index 5763731fd4d..a4e1f8128a4 100644 --- a/src/runtime_src/core/tools/common/XBMain.cpp +++ b/src/runtime_src/core/tools/common/XBMain.cpp @@ -178,18 +178,20 @@ void main_(int argc, char** argv, * from shim. This moves the resposibility for option setting to each shim * instead of xrt-smi. */ - std::shared_ptr device; - try { - device = XBU::get_device(boost::algorithm::to_lower_copy(sDevice), isUserDomain); - } catch (const std::runtime_error& e) { - std::cerr << boost::format("ERROR: %s\n") % e.what(); - } - if (device){ - boost::property_tree::ptree configTreeMain; - const std::string config = xrt_core::device_query(device, xrt_core::query::xrt_smi_config::type::options_config); - std::istringstream command_config_stream(config); - boost::property_tree::read_json(command_config_stream, configTreeMain); - subCommand->setOptionConfig(configTreeMain); + if (isUserDomain) { + std::shared_ptr device; + try { + device = XBU::get_device(boost::algorithm::to_lower_copy(sDevice), isUserDomain); + } catch (const std::runtime_error& e) { + std::cerr << boost::format("ERROR: %s\n") % e.what(); + } + if (device){ + boost::property_tree::ptree configTreeMain; + const std::string config = xrt_core::device_query(device, xrt_core::query::xrt_smi_config::type::options_config); + std::istringstream command_config_stream(config); + boost::property_tree::read_json(command_config_stream, configTreeMain); + subCommand->setOptionConfig(configTreeMain); + } } // -- Execute the sub-command From ff7b918b602799bb7e6e5a31ccae6cd8f3fd3482 Mon Sep 17 00:00:00 2001 From: Akshay Tondak Date: Mon, 13 Jan 2025 13:04:27 -0800 Subject: [PATCH 14/19] Adding device query to alveo device Signed-off-by: Akshay Tondak --- .../core/edge/user/device_linux.cpp | 25 ++ src/runtime_src/core/edge/user/smi.cpp | 211 +++++++++++++++++ src/runtime_src/core/edge/user/smi.h | 11 + src/runtime_src/core/tools/common/XBMain.cpp | 21 +- .../core/tools/common/XBUtilities.cpp | 223 ++++++++++++++++-- .../core/tools/common/XBUtilities.h | 2 +- 6 files changed, 458 insertions(+), 35 deletions(-) create mode 100644 src/runtime_src/core/edge/user/smi.cpp create mode 100644 src/runtime_src/core/edge/user/smi.h diff --git a/src/runtime_src/core/edge/user/device_linux.cpp b/src/runtime_src/core/edge/user/device_linux.cpp index 938b6ef73d1..27ebfdf4efc 100644 --- a/src/runtime_src/core/edge/user/device_linux.cpp +++ b/src/runtime_src/core/edge/user/device_linux.cpp @@ -5,6 +5,7 @@ #include "xrt.h" #include "zynq_dev.h" #include "aie_sys_parser.h" +#include "smi.h" #include "core/common/debug_ip.h" #include "core/common/query_requests.h" @@ -665,6 +666,29 @@ struct aim_counter } }; +struct xrt_smi_config +{ + using result_type = std::any; + + static result_type + get(const xrt_core::device* device, key_type key, const std::any& reqType) + { + if (key != xrt_key_type::xrt_smi_config) + throw xrt_core::query::no_such_key(key, "Not implemented"); + std::string xrt_smi_config; + const auto xrt_smi_config_type = std::any_cast(reqType); + switch (xrt_smi_config_type) { + case xrt_core::query::xrt_smi_config::type::options_config: + xrt_smi_config = xrt_core::shim::smi::get_smi_config(); + break; + default: + throw xrt_core::query::no_such_key(key, "Not implemented"); + } + + return xrt_smi_config; + } +}; + struct am_counter { using result_type = query::am_counter::result_type; @@ -1055,6 +1079,7 @@ initialize_query_table() emplace_func0_request(); emplace_func0_request(); + emplace_func4_request(); emplace_func4_request(); emplace_func4_request(); emplace_func4_request(); diff --git a/src/runtime_src/core/edge/user/smi.cpp b/src/runtime_src/core/edge/user/smi.cpp new file mode 100644 index 00000000000..6ba55e682e8 --- /dev/null +++ b/src/runtime_src/core/edge/user/smi.cpp @@ -0,0 +1,211 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. +#include "smi.h" + +namespace xrt_core::shim::smi { + +static constexpr std::string_view xrt_smi_config = + R"( + { + "subcommands": + [{ + "name" : "validate", + "description" : "Validates the given device by executing the platform's validate executable.", + "tag" : "basic", + "options" : + [ + { + "name": "device", + "alias": "d", + "description": "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", + "tag": "basic", + "default_value": "", + "option_type": "common", + "value_type" : "string" + }, + { + "name": "format", + "alias": "f", + "description": "Report output format", + "tag": "basic", + "default_value": "JSON", + "option_type": "common", + "value_type" : "string" + }, + { + "name": "output", + "alias": "o", + "description" : "Direct the output to the given file", + "tag": "basic", + "default_value": "", + "option_type": "common", + "value_type" : "string" + }, + { + "name": "help", + "alias": "h", + "description" : "Help to use this sub-command", + "tag": "basic", + "default_value": "", + "option_type": "common", + "value_type" : "none" + }, + { + "name" : "run", + "alias" : "r", + "description" : "Run a subset of the test suite", + "tag" : "basic", + "option_type": "common", + "value_type" : "array", + "options" : [ + { + "name" : "latency", + "tag" : "basic", + "description" : "Run end-to-end latency test" + }, + { + "name" : "throughput", + "tag" : "basic", + "description" : "Run end-to-end throughput test" + }, + { + "name" : "cmd-chain-latency", + "tag" : "basic", + "description" : "Run command chain latency test" + }, + { + "name" : "cmd-chain-throughput", + "tag" : "basic", + "description" : "Run end-to-end throughput test using command chaining" + }, + { + "name" : "df-bw", + "tag" : "basic", + "description" : "Run dataflow bandwidth test" + }, + { + "name" : "tct-one-col", + "tag" : "basic", + "description" : "Run TCT test with one column" + }, + { + "name" : "tct-all-col", + "tag" : "basic", + "description" : "Run TCT test with all columns" + }, + { + "name" : "gemm", + "tag" : "basic", + "description" : "Run GEMM test" + }, + { + "name" : "aie-reconfig-overhead", + "tag" : "advanced", + "description" : "Run AIE reconfiguration overhead test" + }, + { + "name" : "spatial-sharing-overhead", + "tag" : "advanced", + "description" : "Run spatial sharing overhead test" + }, + { + "name" : "temporal-sharing-overhead", + "tag" : "advanced", + "description" : "Run temporal sharing overhead test" + } + ] + }, + { + "name" : "path", + "alias" : "p", + "description" : "Path to the directory containing validate xclbins", + "tag" : "basic", + "default_value": "", + "option_type": "hidden", + "value_type" : "string" + }, + { + "name" : "param", + "description" : "Extended parameter for a given test. Format: ::", + "tag" : "basic", + "option_type": "hidden", + "default_value": "", + "value_type" : "string" + }, + { + "name" : "pmode", + "description" : "Specify which power mode to run the benchmarks in. Note: Some tests might be unavailable for some modes", + "tag" : "basic", + "option_type": "hidden", + "default_value": "", + "value_type" : "string" + } + ] + }, + { + "name" : "examine", + "tag" : "basic", + "description": "This command will 'examine' the state of the system/device and will generate a report of interest in a text or JSON format.", + "options": + [ + { + "name": "device", + "description": "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", + "tag": "devl", + "value_type": "string" + }, + { + "name": "format", + "description": "Report output format", + "tag": "devl", + "value_type": "string" + }, + { + "name": "report", + "description": "The type of report to be produced. Reports currently available are:", + "tag": "basic", + "options": [ + { + "name": "aie-partitions", + "tag": "basic", + "description": "AIE partition information" + }, + { + "name": "telemetry", + "tag": "devl", + "description": "Telemetry data for the device" + } + ] + } + ] + }, + { + "name" : "configure", + "tag" : "devl", + "description" : "Device and host configuration.", + "options" : + [ + { + "name": "device", + "description": "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", + "tag": "devl", + "value_type" : "string" + }, + { + "name": "pmode", + "description": "Modes: default, powersaver, balanced, performance, turbo", + "tag": "basic", + "value_type": "string" + } + ] + }] +} +)"; + + +std::string +get_smi_config() +{ + return std::string(xrt_smi_config); +} +} // namespace xrt_core::shim::smi \ No newline at end of file diff --git a/src/runtime_src/core/edge/user/smi.h b/src/runtime_src/core/edge/user/smi.h new file mode 100644 index 00000000000..d3edb00bfd1 --- /dev/null +++ b/src/runtime_src/core/edge/user/smi.h @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. + +#include + +namespace xrt_core::shim::smi { + +std::string +get_smi_config(); + +} // namespace xrt_core::shim::smi \ No newline at end of file diff --git a/src/runtime_src/core/tools/common/XBMain.cpp b/src/runtime_src/core/tools/common/XBMain.cpp index a4e1f8128a4..0b2b560d803 100644 --- a/src/runtime_src/core/tools/common/XBMain.cpp +++ b/src/runtime_src/core/tools/common/XBMain.cpp @@ -177,21 +177,24 @@ void main_(int argc, char** argv, /* xrt-smi. Tool should query device upfront and get the configurations * from shim. This moves the resposibility for option setting to each shim * instead of xrt-smi. + * If the device is not found, then load the default xrt-smi config. */ if (isUserDomain) { std::shared_ptr device; + boost::property_tree::ptree configTreeMain; + std::string config; try { device = XBU::get_device(boost::algorithm::to_lower_copy(sDevice), isUserDomain); - } catch (const std::runtime_error& e) { - std::cerr << boost::format("ERROR: %s\n") % e.what(); - } - if (device){ - boost::property_tree::ptree configTreeMain; - const std::string config = xrt_core::device_query(device, xrt_core::query::xrt_smi_config::type::options_config); - std::istringstream command_config_stream(config); - boost::property_tree::read_json(command_config_stream, configTreeMain); - subCommand->setOptionConfig(configTreeMain); + } catch (...) { + device = nullptr; } + if (device) + config = xrt_core::device_query(device, xrt_core::query::xrt_smi_config::type::options_config); + else + config = XBU::loadDefaultSmiConfig(); + std::istringstream command_config_stream(config); + boost::property_tree::read_json(command_config_stream, configTreeMain); + subCommand->setOptionConfig(configTreeMain); } // -- Execute the sub-command diff --git a/src/runtime_src/core/tools/common/XBUtilities.cpp b/src/runtime_src/core/tools/common/XBUtilities.cpp index bd83b31c33e..001bfb5e370 100755 --- a/src/runtime_src/core/tools/common/XBUtilities.cpp +++ b/src/runtime_src/core/tools/common/XBUtilities.cpp @@ -775,32 +775,205 @@ fill_xrt_versions(const boost::property_tree::ptree& pt_xrt, } } -void -XBUtilities::loadConfigFile(const std::string &configPath, boost::property_tree::ptree &configTree) +std::string +XBUtilities::loadDefaultSmiConfig() { - try - { - // Open the JSON file - std::ifstream jsonFile(configPath); - if (!jsonFile.is_open()) - { - throw std::runtime_error("Failed to open " + configPath); - } - - // Read the JSON file into the property tree - boost::property_tree::read_json(jsonFile, configTree); - - // Close the JSON file - jsonFile.close(); - } - catch (const boost::property_tree::json_parser_error &e) + return std::string( + R"( + { + "subcommands": + [{ + "name" : "validate", + "description" : "Validates the given device by executing the platform's validate executable.", + "tag" : "basic", + "options" : + [ + { + "name": "device", + "alias": "d", + "description": "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", + "tag": "basic", + "default_value": "", + "option_type": "common", + "value_type" : "string" + }, + { + "name": "format", + "alias": "f", + "description": "Report output format", + "tag": "basic", + "default_value": "JSON", + "option_type": "common", + "value_type" : "string" + }, + { + "name": "output", + "alias": "o", + "description" : "Direct the output to the given file", + "tag": "basic", + "default_value": "", + "option_type": "common", + "value_type" : "string" + }, + { + "name": "help", + "alias": "h", + "description" : "Help to use this sub-command", + "tag": "basic", + "default_value": "", + "option_type": "common", + "value_type" : "none" + }, + { + "name" : "run", + "alias" : "r", + "description" : "Run a subset of the test suite", + "tag" : "basic", + "option_type": "common", + "value_type" : "array", + "options" : [ + { + "name" : "latency", + "tag" : "basic", + "description" : "Run end-to-end latency test" + }, + { + "name" : "throughput", + "tag" : "basic", + "description" : "Run end-to-end throughput test" + }, + { + "name" : "cmd-chain-latency", + "tag" : "basic", + "description" : "Run command chain latency test" + }, + { + "name" : "cmd-chain-throughput", + "tag" : "basic", + "description" : "Run end-to-end throughput test using command chaining" + }, + { + "name" : "df-bw", + "tag" : "basic", + "description" : "Run dataflow bandwidth test" + }, + { + "name" : "tct-one-col", + "tag" : "basic", + "description" : "Run TCT test with one column" + }, + { + "name" : "tct-all-col", + "tag" : "basic", + "description" : "Run TCT test with all columns" + }, + { + "name" : "gemm", + "tag" : "basic", + "description" : "Run GEMM test" + }, + { + "name" : "aie-reconfig-overhead", + "tag" : "advanced", + "description" : "Run AIE reconfiguration overhead test" + }, + { + "name" : "spatial-sharing-overhead", + "tag" : "advanced", + "description" : "Run spatial sharing overhead test" + }, + { + "name" : "temporal-sharing-overhead", + "tag" : "advanced", + "description" : "Run temporal sharing overhead test" + } + ] + }, + { + "name" : "path", + "alias" : "p", + "description" : "Path to the directory containing validate xclbins", + "tag" : "basic", + "default_value": "", + "option_type": "hidden", + "value_type" : "string" + }, + { + "name" : "param", + "description" : "Extended parameter for a given test. Format: ::", + "tag" : "basic", + "option_type": "hidden", + "default_value": "", + "value_type" : "string" + }, + { + "name" : "pmode", + "description" : "Specify which power mode to run the benchmarks in. Note: Some tests might be unavailable for some modes", + "tag" : "basic", + "option_type": "hidden", + "default_value": "", + "value_type" : "string" + } + ] + }, { - std::cerr << "Error parsing JSON file: " << e.what() << std::endl; - throw; - } - catch (const std::exception &e) + "name" : "examine", + "tag" : "basic", + "description": "This command will 'examine' the state of the system/device and will generate a report of interest in a text or JSON format.", + "options": + [ + { + "name": "device", + "description": "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", + "tag": "devl", + "value_type": "string" + }, + { + "name": "format", + "description": "Report output format", + "tag": "devl", + "value_type": "string" + }, + { + "name": "report", + "description": "The type of report to be produced. Reports currently available are:", + "tag": "basic", + "options": [ + { + "name": "aie-partitions", + "tag": "basic", + "description": "AIE partition information" + }, + { + "name": "telemetry", + "tag": "devl", + "description": "Telemetry data for the device" + } + ] + } + ] + }, { - std::cerr << "Error: " << e.what() << std::endl; - throw; - } + "name" : "configure", + "tag" : "devl", + "description" : "Device and host configuration.", + "options" : + [ + { + "name": "device", + "description": "The Bus:Device.Function (e.g., 0000:d8:00.0) device of interest", + "tag": "devl", + "value_type" : "string" + }, + { + "name": "pmode", + "description": "Modes: default, powersaver, balanced, performance, turbo", + "tag": "basic", + "value_type": "string" + } + ] + }] +} +)" + ); }// end of namespace XBValidateUtils diff --git a/src/runtime_src/core/tools/common/XBUtilities.h b/src/runtime_src/core/tools/common/XBUtilities.h index b97c992eeda..aaa32a92786 100644 --- a/src/runtime_src/core/tools/common/XBUtilities.h +++ b/src/runtime_src/core/tools/common/XBUtilities.h @@ -153,7 +153,7 @@ namespace XBUtilities { m_device->close_context(m_uuid, std::numeric_limits::max()); } }; - void loadConfigFile(const std::string& configFile, boost::property_tree::ptree& pt); + std::string loadDefaultSmiConfig(); }; From 91d22f364c5da1a2e166a712bbd0f13898198018 Mon Sep 17 00:00:00 2001 From: Akshay Tondak Date: Mon, 13 Jan 2025 14:08:19 -0800 Subject: [PATCH 15/19] Moving query to pcie queries Signed-off-by: Akshay Tondak --- .../core/edge/user/device_linux.cpp | 25 ------------------ .../core/pcie/linux/device_linux.cpp | 26 +++++++++++++++++++ .../core/{edge/user => pcie/linux}/smi.cpp | 0 .../core/{edge/user => pcie/linux}/smi.h | 0 4 files changed, 26 insertions(+), 25 deletions(-) rename src/runtime_src/core/{edge/user => pcie/linux}/smi.cpp (100%) rename src/runtime_src/core/{edge/user => pcie/linux}/smi.h (100%) diff --git a/src/runtime_src/core/edge/user/device_linux.cpp b/src/runtime_src/core/edge/user/device_linux.cpp index 27ebfdf4efc..938b6ef73d1 100644 --- a/src/runtime_src/core/edge/user/device_linux.cpp +++ b/src/runtime_src/core/edge/user/device_linux.cpp @@ -5,7 +5,6 @@ #include "xrt.h" #include "zynq_dev.h" #include "aie_sys_parser.h" -#include "smi.h" #include "core/common/debug_ip.h" #include "core/common/query_requests.h" @@ -666,29 +665,6 @@ struct aim_counter } }; -struct xrt_smi_config -{ - using result_type = std::any; - - static result_type - get(const xrt_core::device* device, key_type key, const std::any& reqType) - { - if (key != xrt_key_type::xrt_smi_config) - throw xrt_core::query::no_such_key(key, "Not implemented"); - std::string xrt_smi_config; - const auto xrt_smi_config_type = std::any_cast(reqType); - switch (xrt_smi_config_type) { - case xrt_core::query::xrt_smi_config::type::options_config: - xrt_smi_config = xrt_core::shim::smi::get_smi_config(); - break; - default: - throw xrt_core::query::no_such_key(key, "Not implemented"); - } - - return xrt_smi_config; - } -}; - struct am_counter { using result_type = query::am_counter::result_type; @@ -1079,7 +1055,6 @@ initialize_query_table() emplace_func0_request(); emplace_func0_request(); - emplace_func4_request(); emplace_func4_request(); emplace_func4_request(); emplace_func4_request(); diff --git a/src/runtime_src/core/pcie/linux/device_linux.cpp b/src/runtime_src/core/pcie/linux/device_linux.cpp index cf58c969fe8..d07d80d0fc3 100644 --- a/src/runtime_src/core/pcie/linux/device_linux.cpp +++ b/src/runtime_src/core/pcie/linux/device_linux.cpp @@ -17,6 +17,7 @@ #include "core/include/xdp/spc.h" #include "core/pcie/driver/linux/include/mgmt-ioctl.h" +#include "smi.h" #include "pcidev.h" #include "xrt.h" @@ -906,6 +907,30 @@ struct am_counter }; +struct xrt_smi_config +{ + using result_type = std::any; + + static result_type + get(const xrt_core::device* device, key_type key, const std::any& reqType) + { + if (key != xrt_key_type::xrt_smi_config) + throw xrt_core::query::no_such_key(key, "Not implemented"); + std::string xrt_smi_config; + const auto xrt_smi_config_type = std::any_cast(reqType); + switch (xrt_smi_config_type) { + case xrt_core::query::xrt_smi_config::type::options_config: + xrt_smi_config = xrt_core::shim::smi::get_smi_config(); + break; + default: + throw xrt_core::query::no_such_key(key, "Not implemented"); + } + + return xrt_smi_config; + } +}; + + /* ASM counter values * In PCIe Linux, access the sysfs file for ASM to retrieve the ASM counter values @@ -1457,6 +1482,7 @@ initialize_query_table() emplace_func4_request(); emplace_func4_request(); emplace_func4_request(); + emplace_func4_request(); emplace_func4_request(); emplace_func4_request(); emplace_func4_request(); diff --git a/src/runtime_src/core/edge/user/smi.cpp b/src/runtime_src/core/pcie/linux/smi.cpp similarity index 100% rename from src/runtime_src/core/edge/user/smi.cpp rename to src/runtime_src/core/pcie/linux/smi.cpp diff --git a/src/runtime_src/core/edge/user/smi.h b/src/runtime_src/core/pcie/linux/smi.h similarity index 100% rename from src/runtime_src/core/edge/user/smi.h rename to src/runtime_src/core/pcie/linux/smi.h From 1507ee72b052aa4ad3c333b988b731caa656c22f Mon Sep 17 00:00:00 2001 From: Akshay Tondak Date: Mon, 13 Jan 2025 14:20:45 -0800 Subject: [PATCH 16/19] Build failure fix Signed-off-by: Akshay Tondak --- src/runtime_src/core/pcie/linux/device_linux.cpp | 2 +- src/runtime_src/core/pcie/linux/smi.cpp | 4 ++-- src/runtime_src/core/pcie/linux/smi.h | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/runtime_src/core/pcie/linux/device_linux.cpp b/src/runtime_src/core/pcie/linux/device_linux.cpp index d07d80d0fc3..2f56f9d7907 100644 --- a/src/runtime_src/core/pcie/linux/device_linux.cpp +++ b/src/runtime_src/core/pcie/linux/device_linux.cpp @@ -920,7 +920,7 @@ struct xrt_smi_config const auto xrt_smi_config_type = std::any_cast(reqType); switch (xrt_smi_config_type) { case xrt_core::query::xrt_smi_config::type::options_config: - xrt_smi_config = xrt_core::shim::smi::get_smi_config(); + xrt_smi_config = xrt_core::smi::get_smi_config(); break; default: throw xrt_core::query::no_such_key(key, "Not implemented"); diff --git a/src/runtime_src/core/pcie/linux/smi.cpp b/src/runtime_src/core/pcie/linux/smi.cpp index 6ba55e682e8..47f58f76913 100644 --- a/src/runtime_src/core/pcie/linux/smi.cpp +++ b/src/runtime_src/core/pcie/linux/smi.cpp @@ -2,7 +2,7 @@ // Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. #include "smi.h" -namespace xrt_core::shim::smi { +namespace xrt_core::smi { static constexpr std::string_view xrt_smi_config = R"( @@ -208,4 +208,4 @@ get_smi_config() { return std::string(xrt_smi_config); } -} // namespace xrt_core::shim::smi \ No newline at end of file +} // namespace xrt_core::smi \ No newline at end of file diff --git a/src/runtime_src/core/pcie/linux/smi.h b/src/runtime_src/core/pcie/linux/smi.h index d3edb00bfd1..ca41882ddb7 100644 --- a/src/runtime_src/core/pcie/linux/smi.h +++ b/src/runtime_src/core/pcie/linux/smi.h @@ -3,9 +3,9 @@ #include -namespace xrt_core::shim::smi { +namespace xrt_core::smi { std::string get_smi_config(); -} // namespace xrt_core::shim::smi \ No newline at end of file +} // namespace xrt_core::smi \ No newline at end of file From d0c8a2c5f95d265b511d789a8c9b3a538b8b0e92 Mon Sep 17 00:00:00 2001 From: Akshay Tondak Date: Mon, 13 Jan 2025 14:49:32 -0800 Subject: [PATCH 17/19] Build fix try 2 Signed-off-by: Akshay Tondak --- src/runtime_src/core/pcie/linux/device_linux.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime_src/core/pcie/linux/device_linux.cpp b/src/runtime_src/core/pcie/linux/device_linux.cpp index 2f56f9d7907..d6da96ff862 100644 --- a/src/runtime_src/core/pcie/linux/device_linux.cpp +++ b/src/runtime_src/core/pcie/linux/device_linux.cpp @@ -914,7 +914,7 @@ struct xrt_smi_config static result_type get(const xrt_core::device* device, key_type key, const std::any& reqType) { - if (key != xrt_key_type::xrt_smi_config) + if (key != key_type::xrt_smi_config) throw xrt_core::query::no_such_key(key, "Not implemented"); std::string xrt_smi_config; const auto xrt_smi_config_type = std::any_cast(reqType); From 94bc8ef6c19ec658056cde4725bc4b64ee1c5a96 Mon Sep 17 00:00:00 2001 From: Akshay Tondak Date: Mon, 13 Jan 2025 15:29:20 -0800 Subject: [PATCH 18/19] Build fix Signed-off-by: Akshay Tondak --- src/runtime_src/core/pcie/linux/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/runtime_src/core/pcie/linux/CMakeLists.txt b/src/runtime_src/core/pcie/linux/CMakeLists.txt index 443cdb212d0..c1c24bd4c1d 100644 --- a/src/runtime_src/core/pcie/linux/CMakeLists.txt +++ b/src/runtime_src/core/pcie/linux/CMakeLists.txt @@ -10,6 +10,7 @@ add_library(core_pcielinux_objects OBJECT pcidrv.cpp shim.cpp system_linux.cpp + smi.cpp ) target_compile_definitions(core_pcielinux_objects From fc7285d13f2aed4f28c13b24a832434f64a6d967 Mon Sep 17 00:00:00 2001 From: Akshay Tondak Date: Tue, 14 Jan 2025 14:10:14 -0800 Subject: [PATCH 19/19] Review comments handled Signed-off-by: Akshay Tondak --- src/runtime_src/core/pcie/linux/smi.cpp | 2 +- src/runtime_src/core/pcie/linux/smi.h | 2 +- src/runtime_src/core/tools/common/SubCmd.cpp | 2 +- src/runtime_src/core/tools/common/SubCmd.h | 2 +- .../core/tools/common/SubCmdJsonObjects.cpp | 47 +++++++++++++++++-- .../core/tools/common/SubCmdJsonObjects.h | 45 ++++-------------- .../core/tools/xbutil2/SubCmdValidate.h | 2 +- 7 files changed, 57 insertions(+), 45 deletions(-) diff --git a/src/runtime_src/core/pcie/linux/smi.cpp b/src/runtime_src/core/pcie/linux/smi.cpp index 47f58f76913..3ffa55af0d3 100644 --- a/src/runtime_src/core/pcie/linux/smi.cpp +++ b/src/runtime_src/core/pcie/linux/smi.cpp @@ -208,4 +208,4 @@ get_smi_config() { return std::string(xrt_smi_config); } -} // namespace xrt_core::smi \ No newline at end of file +} // namespace xrt_core::smi diff --git a/src/runtime_src/core/pcie/linux/smi.h b/src/runtime_src/core/pcie/linux/smi.h index ca41882ddb7..d986f07b555 100644 --- a/src/runtime_src/core/pcie/linux/smi.h +++ b/src/runtime_src/core/pcie/linux/smi.h @@ -8,4 +8,4 @@ namespace xrt_core::smi { std::string get_smi_config(); -} // namespace xrt_core::smi \ No newline at end of file +} // namespace xrt_core::smi diff --git a/src/runtime_src/core/tools/common/SubCmd.cpp b/src/runtime_src/core/tools/common/SubCmd.cpp index eb9b0a9dd61..757a8b50fa4 100644 --- a/src/runtime_src/core/tools/common/SubCmd.cpp +++ b/src/runtime_src/core/tools/common/SubCmd.cpp @@ -170,7 +170,7 @@ SubCmd::checkForSubOption(const boost::program_options::variables_map& vm, const void SubCmd::setOptionConfig(const boost::property_tree::ptree &config) { - m_jsonConfig = JsonConfig(config.get_child("subcommands"), getName()); + m_jsonConfig = SubCmdJsonObjects::JsonConfig(config.get_child("subcommands"), getName()); try{ m_jsonConfig.addProgramOptions(m_commonOptions, "common", getName()); m_jsonConfig.addProgramOptions(m_hiddenOptions, "hidden", getName()); diff --git a/src/runtime_src/core/tools/common/SubCmd.h b/src/runtime_src/core/tools/common/SubCmd.h index 5c8bbfbebdb..7cef998fd7e 100644 --- a/src/runtime_src/core/tools/common/SubCmd.h +++ b/src/runtime_src/core/tools/common/SubCmd.h @@ -87,7 +87,7 @@ class SubCmd : public JSONConfigurable { boost::program_options::options_description m_hiddenOptions; boost::program_options::positional_options_description m_positionals; boost::property_tree::ptree m_commandConfig; - JsonConfig m_jsonConfig; + SubCmdJsonObjects::JsonConfig m_jsonConfig; template std::vector> diff --git a/src/runtime_src/core/tools/common/SubCmdJsonObjects.cpp b/src/runtime_src/core/tools/common/SubCmdJsonObjects.cpp index 668f24a4a0e..748e8a7ece8 100644 --- a/src/runtime_src/core/tools/common/SubCmdJsonObjects.cpp +++ b/src/runtime_src/core/tools/common/SubCmdJsonObjects.cpp @@ -5,10 +5,34 @@ #include #include -#include "boost/property_tree/ptree.hpp" -#include "boost/program_options.hpp" +#include +#include #include "SubCmdJsonObjects.h" +namespace SubCmdJsonObjects { + +static constexpr std::string_view const_name_literal = "name"; +static constexpr std::string_view const_description_literal = "description"; +static constexpr std::string_view const_tag_literal = "tag"; +static constexpr std::string_view const_alias_literal = "alias"; +static constexpr std::string_view const_default_value_literal = "default_value"; +static constexpr std::string_view const_option_type_literal = "option_type"; +static constexpr std::string_view const_value_type_literal = "value_type"; +static constexpr std::string_view const_options_literal = "options"; + +static std::unordered_map valueTypeMap = { + {"bool", ValueType::boolean}, + {"string", ValueType::string}, + {"array", ValueType::array}, + {"none", ValueType::none} +}; + +OptionBasic::OptionBasic(const pt::ptree& configurations) + : m_name(configurations.get(std::string(const_name_literal))), + m_description(configurations.get(std::string(const_description_literal))), + m_tag(configurations.get(std::string(const_tag_literal))) + {} + void OptionBasic::printOption() const { @@ -17,6 +41,15 @@ OptionBasic::printOption() const std::cout << "Tag: " << m_tag << std::endl; } +SubCommandOption::SubCommandOption(const pt::ptree& configurations): + OptionBasic(configurations), + m_alias(configurations.get(std::string(const_alias_literal), "")), + m_defaultValue(configurations.get(std::string(const_default_value_literal), "")), + m_optionType(configurations.get(std::string(const_option_type_literal), "")), + m_valueType(configurations.get(std::string(const_value_type_literal), "")), + m_ptEmpty(pt::ptree()), + m_subOptionMap(createBasicOptions(configurations.get_child(std::string(const_options_literal), m_ptEmpty))){} + /** * Adds the sub-command option to the options description. * This method checks the option type and adds the option to the provided options description @@ -29,8 +62,8 @@ SubCommandOption::addProgramOption(po::options_description& options, const std:: { if (m_optionType != optionsType) return; - auto valueType = m_valueTypeMap.find(m_valueType); - if (valueType == m_valueTypeMap.end()) { + auto valueType = valueTypeMap.find(m_valueType); + if (valueType == valueTypeMap.end()) { throw std::runtime_error("Invalid value type for option " + m_name); } switch (valueType->second){ @@ -93,6 +126,11 @@ SubCommandOption::printOption() const } } +SubCommand::SubCommand(const pt::ptree& configurations) : + OptionBasic(configurations), + m_optionMap(createSubCommandOptions(configurations.get_child(std::string(const_options_literal)))) + {} + std::unordered_map SubCommand::createSubCommandOptions(const pt::ptree& pt) { @@ -158,3 +196,4 @@ JsonConfig::printConfigurations() const } } } +} // namespace SubCmdJsonObjects diff --git a/src/runtime_src/core/tools/common/SubCmdJsonObjects.h b/src/runtime_src/core/tools/common/SubCmdJsonObjects.h index 84087325758..05d6d47323b 100644 --- a/src/runtime_src/core/tools/common/SubCmdJsonObjects.h +++ b/src/runtime_src/core/tools/common/SubCmdJsonObjects.h @@ -9,14 +9,7 @@ #include "boost/property_tree/ptree.hpp" #include "boost/program_options.hpp" -static constexpr std::string_view const_name_literal = "name"; -static constexpr std::string_view const_description_literal = "description"; -static constexpr std::string_view const_tag_literal = "tag"; -static constexpr std::string_view const_alias_literal = "alias"; -static constexpr std::string_view const_default_value_literal = "default_value"; -static constexpr std::string_view const_option_type_literal = "option_type"; -static constexpr std::string_view const_value_type_literal = "value_type"; -static constexpr std::string_view const_options_literal = "options"; +namespace SubCmdJsonObjects { namespace po = boost::program_options; namespace pt = boost::property_tree; @@ -34,11 +27,10 @@ class OptionBasic { std::string m_name; std::string m_description; std::string m_tag; - OptionBasic(const pt::ptree& configurations) - : m_name(configurations.get(std::string(const_name_literal))), - m_description(configurations.get(std::string(const_description_literal))), - m_tag(configurations.get(std::string(const_tag_literal))) - {} + + public: + + OptionBasic(const pt::ptree& configurations); std::string getName() const { return m_name; } std::string getDescription() const { return m_description; } @@ -56,7 +48,7 @@ class SubCommandOption : public OptionBasic { /* * Map of option name vs SubCommandOption objects. Example: - * --run can have multiple option Values like latency, throughput etc. + * --run can have multiple option values like latency, throughput etc. * latency : OptionBasic object * throughput : OptionBasic object * ................. @@ -66,25 +58,8 @@ class SubCommandOption : public OptionBasic { std::unordered_map createBasicOptions(const pt::ptree& pt); -protected: - const std::unordered_map m_valueTypeMap = { - {"bool", ValueType::boolean}, - {"string", ValueType::string}, - {"array", ValueType::array}, - {"none", ValueType::none} - }; - public: - - SubCommandOption(const pt::ptree& configurations): - OptionBasic(configurations), - m_alias(configurations.get(std::string(const_alias_literal), "")), - m_defaultValue(configurations.get(std::string(const_default_value_literal), "")), - m_optionType(configurations.get(std::string(const_option_type_literal), "")), - m_valueType(configurations.get(std::string(const_value_type_literal), "")), - m_ptEmpty(pt::ptree()), - m_subOptionMap(createBasicOptions(configurations.get_child(std::string(const_options_literal), m_ptEmpty))) - {} + SubCommandOption(const pt::ptree& configurations); std::string getValueType() const { return m_valueType; } std::string getAlias() const { return m_alias; } @@ -110,10 +85,7 @@ class SubCommand : public OptionBasic { createSubCommandOptions(const pt::ptree& pt); public: - SubCommand(const pt::ptree& configurations) : - OptionBasic(configurations), - m_optionMap(createSubCommandOptions(configurations.get_child(std::string(const_options_literal)))) - {} + SubCommand(const pt::ptree& configurations); std::unordered_map getOptionMap() const { return m_optionMap; } void addProgramOptions(po::options_description& options, const std::string& optionsType); @@ -145,3 +117,4 @@ class JsonConfig { void addProgramOptions(po::options_description& options, const std::string& optionsType, const std::string& subCommand); void printConfigurations() const; }; +} // namespace SubCmdJsonObjects diff --git a/src/runtime_src/core/tools/xbutil2/SubCmdValidate.h b/src/runtime_src/core/tools/xbutil2/SubCmdValidate.h index ed07a712186..0a7f4e3c864 100644 --- a/src/runtime_src/core/tools/xbutil2/SubCmdValidate.h +++ b/src/runtime_src/core/tools/xbutil2/SubCmdValidate.h @@ -29,7 +29,7 @@ class SubCmdValidate : public SubCmd { private: - void fill_option_values(const po::variables_map& vm, SubCmdValidateOptions& options) const; + void fill_option_values(const boost::program_options::variables_map& vm, SubCmdValidateOptions& options) const; void print_help_internal(const SubCmdValidateOptions& ) const; void handle_errors_and_validate_tests(const boost::program_options::variables_map&, const SubCmdValidateOptions&,