From da2abd9adc9e380e75eb509cee92f60d1bf19352 Mon Sep 17 00:00:00 2001 From: Chris Freehill Date: Sun, 10 Mar 2019 17:56:06 -0500 Subject: [PATCH] Add table for GPU name look to give better name than just "amdgpu" [ROCm/rocm_smi_lib commit: d39752cee7cb875f340b04dfafc1071498264c14] --- projects/rocm-smi-lib/CMakeLists.txt | 2 ++ .../rocm-smi-lib/include/rocm_smi/rocm_smi.h | 11 +++++++--- projects/rocm-smi-lib/src/rocm_smi.cc | 22 ++++++++++++++++--- .../tests/rocm_smi_test/test_base.cc | 6 ++--- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/projects/rocm-smi-lib/CMakeLists.txt b/projects/rocm-smi-lib/CMakeLists.txt index 01b00d62bc..d4cb1d2159 100755 --- a/projects/rocm-smi-lib/CMakeLists.txt +++ b/projects/rocm-smi-lib/CMakeLists.txt @@ -113,6 +113,7 @@ set(SMI_SRC_LIST ${SMI_SRC_LIST} "${SRC_DIR}/rocm_smi_monitor.cc") set(SMI_SRC_LIST ${SMI_SRC_LIST} "${SRC_DIR}/rocm_smi.cc") set(SMI_SRC_LIST ${SMI_SRC_LIST} "${SRC_DIR}/rocm_smi_power_mon.cc") set(SMI_SRC_LIST ${SMI_SRC_LIST} "${SRC_DIR}/rocm_smi_utils.cc") +set(SMI_SRC_LIST ${SMI_SRC_LIST} "${SRC_DIR}/rocm_smi_dev_names.cc") set(SMI_INC_LIST "${INC_DIR}/rocm_smi_device.h") set(SMI_INC_LIST ${SMI_INC_LIST} "${INC_DIR}/rocm_smi_main.h") @@ -121,6 +122,7 @@ set(SMI_INC_LIST ${SMI_INC_LIST} "${INC_DIR}/rocm_smi_power_mon.h") set(SMI_INC_LIST ${SMI_INC_LIST} "${INC_DIR}/rocm_smi_utils.h") set(SMI_INC_LIST ${SMI_INC_LIST} "${INC_DIR}/rocm_smi_common.h") set(SMI_INC_LIST ${SMI_INC_LIST} "${INC_DIR}/rocm_smi_exception.h") +set(SMI_INC_LIST ${SMI_INC_LIST} "${INC_DIR}/rocm_smi_dev_names.h") set(SMI_EXAMPLE_EXE "rocm_smi_ex") diff --git a/projects/rocm-smi-lib/include/rocm_smi/rocm_smi.h b/projects/rocm-smi-lib/include/rocm_smi/rocm_smi.h index 7e8cf64e0d..789e50ae2a 100755 --- a/projects/rocm-smi-lib/include/rocm_smi/rocm_smi.h +++ b/projects/rocm-smi-lib/include/rocm_smi/rocm_smi.h @@ -1,6 +1,4 @@ /* - * ============================================================================= - * ROC Runtime Conformance Release License * ============================================================================= * The University of Illinois/NCSA * Open Source License (NCSA) @@ -108,6 +106,10 @@ typedef enum { //!< yet been implemented in the //!< current system for the current //!< devices + RSMI_STATUS_NOT_FOUND, //!< An item was searched for but not + //!< found + RSMI_STATUS_INSUFFICIENT_SIZE, //!< Not enough resources were + //!< for the operation RSMI_STATUS_UNKNOWN_ERROR = 0xFFFFFFFF, //!< An unknown error occurred } rsmi_status_t; @@ -515,6 +517,9 @@ rsmi_status_t rsmi_dev_id_get(uint32_t dv_ind, uint64_t *id); * @param[in] len the length of the caller provided buffer @p name. * * @retval ::RSMI_STATUS_SUCCESS is returned upon successful call. + * @retval ::RSMI_STATUS_INSUFFICIENT_SIZE is returned if @p len bytes is not + * large enough to hold the entire name. In this case, only @len bytes will + * be written. * */ rsmi_status_t rsmi_dev_name_get(uint32_t dv_ind, char *name, size_t len); @@ -808,7 +813,7 @@ rsmi_dev_memory_usage_get(uint32_t dv_ind, rsmi_memory_type_t mem_type, /** @} */ // end of MemQuer -/** @defgroup PhysQuer Physcial State Queries +/** @defgroup PhysQuer Physical State Queries * These functions provide information about the physical characteristics of * the device. * @{ diff --git a/projects/rocm-smi-lib/src/rocm_smi.cc b/projects/rocm-smi-lib/src/rocm_smi.cc index 85819ad65c..944fd30f98 100755 --- a/projects/rocm-smi-lib/src/rocm_smi.cc +++ b/projects/rocm-smi-lib/src/rocm_smi.cc @@ -57,6 +57,8 @@ #include "rocm_smi/rocm_smi_device.h" #include "rocm_smi/rocm_smi_utils.h" #include "rocm_smi/rocm_smi_exception.h" +#include "rocm_smi/rocm_smi_dev_names.h" + #include "rocm_smi/rocm_smi64Config.h" static const uint32_t kMaxOverdriveLevel = 20; @@ -403,8 +405,6 @@ static rsmi_status_t get_dev_value_vec(amd::smi::DevInfoTypes type, return errno_to_rsmi_status(ret); } -// A call to rsmi_init is not technically necessary at this time, but may be -// in the future. rsmi_status_t rsmi_init(uint64_t init_flags) { TRY @@ -959,15 +959,31 @@ rsmi_dev_name_get(uint32_t dv_ind, char *name, size_t len) { std::string val_str; rsmi_status_t ret; + uint64_t id; + + ret = rsmi_dev_id_get(dv_ind, &id); - ret = get_dev_mon_value_str(amd::smi::kMonName, dv_ind, -1, &val_str); if (ret != RSMI_STATUS_SUCCESS) { return ret; } + val_str = get_dev_id_name_map(id); + + if (val_str.size() == 0) { + ret = get_dev_mon_value_str(amd::smi::kMonName, dv_ind, -1, &val_str); + if (ret != RSMI_STATUS_SUCCESS) { + return ret; + } + } + size_t ln = val_str.copy(name, len); name[std::min(len - 1, ln)] = '\0'; + + if (len < val_str.size()) { + return RSMI_STATUS_INSUFFICIENT_SIZE; + } + return RSMI_STATUS_SUCCESS; CATCH } diff --git a/projects/rocm-smi-lib/tests/rocm_smi_test/test_base.cc b/projects/rocm-smi-lib/tests/rocm_smi_test/test_base.cc index 98aa7f7f13..0351a9e4ec 100755 --- a/projects/rocm-smi-lib/tests/rocm_smi_test/test_base.cc +++ b/projects/rocm-smi-lib/tests/rocm_smi_test/test_base.cc @@ -112,11 +112,11 @@ void TestBase::PrintDeviceHeader(uint32_t dv_ind) { } std::cout << std::setbase(10); - char name[20]; - err = rsmi_dev_name_get(dv_ind, name, 20); + char name[128]; + err = rsmi_dev_name_get(dv_ind, name, 128); CHK_ERR_ASRT(err) IF_VERB(STANDARD) { - std::cout << "\t**Monitor name: " << name << std::endl; + std::cout << "\t**Device name: " << name << std::endl; } } void TestBase::Run(void) {