From dc905e20ff1459ec371733dabc2e178f90500440 Mon Sep 17 00:00:00 2001 From: Chen Gong Date: Sun, 25 Aug 2024 10:01:54 +0800 Subject: [PATCH] Implement the discovery -v command line interface Call the previously implemented get_rdcd_version and rdc_get_smiversion Change-Id: If76037d462fa9328c3af8c85423ee4547882e36e Signed-off-by: Chen Gong [ROCm/rdc commit: 0cfca6d93d4d6dc086ed56d5c6605fef3df13f18] --- .../rdc/rdci/include/RdciDiscoverySubSystem.h | 2 + .../rdc/rdci/src/RdciDiscoverySubSystem.cc | 50 ++++++++++++++++--- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/projects/rdc/rdci/include/RdciDiscoverySubSystem.h b/projects/rdc/rdci/include/RdciDiscoverySubSystem.h index f0dd2be95b..212e056591 100644 --- a/projects/rdc/rdci/include/RdciDiscoverySubSystem.h +++ b/projects/rdc/rdci/include/RdciDiscoverySubSystem.h @@ -38,6 +38,8 @@ class RdciDiscoverySubSystem : public RdciSubSystem { void show_help() const; bool is_list_; void show_attributes(); + bool show_version_; + void show_version(); }; } // namespace rdc diff --git a/projects/rdc/rdci/src/RdciDiscoverySubSystem.cc b/projects/rdc/rdci/src/RdciDiscoverySubSystem.cc index 8d5233a759..48a06b7b8a 100644 --- a/projects/rdc/rdci/src/RdciDiscoverySubSystem.cc +++ b/projects/rdc/rdci/src/RdciDiscoverySubSystem.cc @@ -25,6 +25,7 @@ THE SOFTWARE. #include #include "rdc/rdc.h" +#include "rdc/rdc_private.h" #include "rdc_lib/RdcException.h" #include "rdc_lib/rdc_common.h" @@ -33,7 +34,8 @@ namespace rdc { RdciDiscoverySubSystem::RdciDiscoverySubSystem() : show_help_(false), - is_list_(false) {} + is_list_(false), + show_version_(false) {} void RdciDiscoverySubSystem::parse_cmd_opts(int argc, char** argv) { const int HOST_OPTIONS = 1000; @@ -41,12 +43,12 @@ void RdciDiscoverySubSystem::parse_cmd_opts(int argc, char** argv) { const struct option long_options[] = { {"host", required_argument, nullptr, HOST_OPTIONS}, {"help", optional_argument, nullptr, 'h'}, {"unauth", optional_argument, nullptr, 'u'}, {"list", optional_argument, nullptr, 'l'}, - {"json", optional_argument, nullptr, JSON_OPTIONS}, {nullptr, 0, nullptr, 0}}; + {"json", optional_argument, nullptr, JSON_OPTIONS}, {"version", optional_argument, nullptr, 'v'}, {nullptr, 0, nullptr, 0}}; int option_index = 0; int opt = 0; - while ((opt = getopt_long(argc, argv, "hlu", long_options, &option_index)) != -1) { + while ((opt = getopt_long(argc, argv, "hluv", long_options, &option_index)) != -1) { switch (opt) { case HOST_OPTIONS: ip_port_ = optarg; @@ -63,13 +65,16 @@ void RdciDiscoverySubSystem::parse_cmd_opts(int argc, char** argv) { case 'l': is_list_ = true; break; + case 'v': + show_version_ = true; + break; default: show_help(); throw RdcException(RDC_ST_BAD_PARAMETER, "Unknown command line options"); } } - if (!is_list_) { + if ((!is_list_ && !show_version_) || (is_list_ && show_version_)) { show_help(); throw RdcException(RDC_ST_BAD_PARAMETER, "Need to specify operations"); } @@ -78,16 +83,18 @@ void RdciDiscoverySubSystem::parse_cmd_opts(int argc, char** argv) { void RdciDiscoverySubSystem::show_help() const { if (is_json_output()) return; std::cout << " discovery -- Used to discover and identify GPUs " - << "and their attributes.\n\n"; + << "and their attributes, as well as server version information.\n\n"; std::cout << "Usage\n"; std::cout << " rdci discovery [--host :port] [--json]" - << " [-u] -l\n"; + << " [-u] -l -v\n"; std::cout << "\nFlags:\n"; show_common_usage(); std::cout << " --json " << "Output using json.\n"; std::cout << " -l --list list GPU discovered" << " on the system\n"; + std::cout << " -v --version Display version information of the" + << " the server and libraries used by the server\n"; } void RdciDiscoverySubSystem::show_attributes() { @@ -138,6 +145,33 @@ void RdciDiscoverySubSystem::show_attributes() { } } +void RdciDiscoverySubSystem::show_version() { + rdc_component_version_t smiv; + rdc_status_t result = rdc_device_get_component_version(rdc_handle_, RDC_AMDMSI_COMPONENT, &smiv); + if (result != RDC_ST_OK) { + return; + } + + mixed_component_version_t rdcdv; + uint32_t ret = get_mixed_component_version(rdc_handle_, RDCD_COMPONENT, &rdcdv); + if (ret) { + std::cout << "get rdcd version fail"<< std::endl; + return; + } + + if (is_json_output()) { + std::cout << "\"version\" : "; + std::cout << '{'; + std::cout << "\"rdcd\": " << "\"" << rdcdv.version << "\", "; + std::cout << "\"amdsmi_lib\": " << "\"" << smiv.version << "\""; + std::cout << '}'; + } else { + std::cout << "RDCD : " << rdcdv.version << " | " << "AMDSMI Library : " << smiv.version << std::endl; + } + + return; +} + void RdciDiscoverySubSystem::process() { if (show_help_) { return show_help(); @@ -146,6 +180,10 @@ void RdciDiscoverySubSystem::process() { if (is_list_) { return show_attributes(); } + + if (show_version_) { + return show_version(); + } } } // namespace rdc