Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/runtime_src/core/tools/common/XBHelpMenusCore.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2020-2022 Xilinx, Inc
// Copyright (C) 2022-2025 Advanced Micro Devices, Inc. All rights reserved.
// Copyright (C) 2022-2026 Advanced Micro Devices, Inc. All rights reserved.
// ------ I N C L U D E F I L E S -------------------------------------------
// Local - Include Files
#include "XBHelpMenusCore.h"
Expand Down Expand Up @@ -373,8 +373,15 @@ XBUtilities::report_commands_help( const std::string &_executable,

report_option_help("OPTIONS", _optionDescription);

if (XBU::getAdvance())
report_option_help(std::string("OPTIONS ") + sHidden, _optionHidden);
if (XBU::getAdvance()) {
po::options_description hiddenForDisplay;
for (const auto& opt : _optionHidden.options()) {
if (opt && !boost::iequals(opt->long_name(), "subCmd"))
hiddenForDisplay.add(opt);
}
if (!hiddenForDisplay.options().empty())
report_option_help(std::string("OPTIONS ") + sHidden, hiddenForDisplay);
}
}

static std::string
Expand All @@ -400,7 +407,11 @@ create_option_format_name(const boost::program_options::option_description * _op
optionDisplayName += removeLongOptDashes ? _option->long_name() : longName;
}

if (_reportParameter && !_option->format_parameter().empty())
// Omit Boost's format_parameter() for subCmd; semantics stay in the description.
const std::string& longKey = _option->long_name();
if (_reportParameter && boost::iequals(longKey, "device"))
optionDisplayName += " <BDF>";
else if (_reportParameter && !boost::iequals(longKey, "subCmd") && !_option->format_parameter().empty())
optionDisplayName += " " + _option->format_parameter();

return optionDisplayName;
Expand Down
41 changes: 21 additions & 20 deletions src/runtime_src/core/tools/common/XBMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void main_(int argc, char** argv,
const std::string device_default = xrt_core::get_total_devices(isUserDomain).first == 1 ? "default" : "";
po::options_description hiddenOptions("Hidden Options");
hiddenOptions.add_options()
("device,d", boost::program_options::value<decltype(sDevice)>(&sDevice)->default_value(device_default)->implicit_value("default"), "If specified with no BDF value and there is only 1 device, that device will be automatically selected.\n")
("device,d", boost::program_options::value<decltype(sDevice)>(&sDevice)->default_value(device_default)->implicit_value("default"), "Specify a BDF. If the option is omitted and there is only 1 device, that device is used\n")
("trace", boost::program_options::bool_switch(&bTrace), "Enables code flow tracing")
("subCmd", po::value<decltype(sCmd)>(&sCmd), "Command to execute")
;
Expand Down Expand Up @@ -120,28 +120,29 @@ void main_(int argc, char** argv,
XBU::setAdvance( bAdvance );
XBU::setForce( bForce );

// Was default device requested?
if (boost::iequals(sDevice, "default")) {
sDevice.clear();
boost::property_tree::ptree available_devices = XBU::get_available_devices(isUserDomain);

// DRC: Are there any devices
if (available_devices.empty())
throw std::runtime_error("No devices found.");

// DRC: Are there multiple devices, if so then no default device can be found.
if (available_devices.size() > 1) {
std::cerr << "\nERROR: Multiple devices found. Please specify a single device using the --device option\n\n";
// Was device specified? If not, try to use default device.
{
const auto& device_var = vm["device"];
if (device_var.defaulted()) {
boost::property_tree::ptree available_devices = XBU::get_available_devices(isUserDomain);
if (available_devices.empty())
throw std::runtime_error("No devices found.");
if (available_devices.size() > 1) {
std::cerr << "\nERROR: Multiple devices found. Please specify a single device using the --device option\n\n";
std::cerr << XBUtilities::str_available_devs(isUserDomain) << std::endl;
std::cout << std::endl;
throw xrt_core::error(std::errc::operation_canceled);
}
for (const auto& kd : available_devices) {
sDevice = kd.second.get<std::string>("bdf");
break;
}
}
else if (sDevice.empty() || boost::algorithm::iequals(sDevice, "default")) {
std::cerr << "\nERROR: Option --device (-d) requires a BDF.\n";
std::cerr << XBUtilities::str_available_devs(isUserDomain) << std::endl;

std::cout << std::endl;
throw xrt_core::error(std::errc::operation_canceled);
}

// We have only 1 item in the array, get it
for (const auto &kd : available_devices)
sDevice = kd.second.get<std::string>("bdf"); // Exit after the first item

}

// If there is a device value, parse for valid subcommands for this device.
Expand Down
Loading