Skip to content

Commit

Permalink
Change to device query
Browse files Browse the repository at this point in the history
Signed-off-by: Akshay Tondak <[email protected]>
  • Loading branch information
Akshay Tondak authored and Akshay Tondak committed Dec 31, 2024
1 parent 6098c9c commit 7f99c91
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 51 deletions.
12 changes: 12 additions & 0 deletions src/runtime_src/core/tools/common/SubCmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
3 changes: 3 additions & 0 deletions src/runtime_src/core/tools/common/SubCmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <boost/program_options.hpp>

#include "JSONConfigurable.h"
#include "SubCmdJsonObjects.h"
#include "OptionOptions.h"

class SubCmd : public JSONConfigurable {
Expand All @@ -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; };
Expand Down Expand Up @@ -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<class T>
std::vector<std::shared_ptr<T>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions src/runtime_src/core/tools/common/XBMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ void main_(int argc, char** argv,
sDevice = kd.second.get<std::string>("bdf"); // Exit after the first item

}
std::shared_ptr<xrt_core::device> 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<xrt_core::query::xrt_smi_config>(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;
Expand Down Expand Up @@ -172,6 +182,7 @@ void main_(int argc, char** argv,
}

subCommand->setGlobalOptions(globalSubCmdOptions);
subCommand->setOptionConfig(configTreeMain);

// -- Execute the sub-command
subCommand->execute(subcmd_options);
Expand Down
30 changes: 30 additions & 0 deletions src/runtime_src/core/tools/common/XBUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/runtime_src/core/tools/common/XBUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ namespace XBUtilities {
m_device->close_context(m_uuid, std::numeric_limits<unsigned int>::max());
}
};
void loadConfigFile(const std::string& configFile, boost::property_tree::ptree& pt);

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,32 +450,4 @@ dpu_or_elf(const std::shared_ptr<xrt_core::device>& 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
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,5 @@ bool search_and_program_xclbin(const std::shared_ptr<xrt_core::device>& dev, boo
int validate_binary_file(const std::string& binaryfile);
std::string dpu_or_elf(const std::shared_ptr<xrt_core::device>& 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
1 change: 1 addition & 0 deletions src/runtime_src/core/tools/xbflash2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/runtime_src/core/tools/xbmgmt2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/tools/xbutil2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
11 changes: 1 addition & 10 deletions src/runtime_src/core/tools/xbutil2/SubCmdValidate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,9 @@ static std::map<std::string,std::vector<std::shared_ptr<JSONConfigurable>>> json
static const std::pair<std::string, std::string> all_test = {"all", "All applicable validate tests will be executed (default)"};
static const std::pair<std::string, std::string> 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);
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/runtime_src/core/tools/xbutil2/SubCmdValidate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <boost/program_options.hpp>
#include "tools/common/SubCmd.h"
#include "tools/common/XBHelpMenus.h"
#include "SubCmdJsonObjects.h"

struct SubCmdValidateOptions {
std::string m_device;
Expand All @@ -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;
Expand Down
8 changes: 1 addition & 7 deletions src/runtime_src/core/tools/xbutil2/xbutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand Down

0 comments on commit 7f99c91

Please sign in to comment.