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 de6761ca62..c916bccfd9 100755 --- a/projects/rocm-smi-lib/include/rocm_smi/rocm_smi.h +++ b/projects/rocm-smi-lib/include/rocm_smi/rocm_smi.h @@ -3169,6 +3169,29 @@ rsmi_status_t rsmi_dev_firmware_version_get(uint32_t dv_ind, rsmi_fw_block_t block, uint64_t *fw_version); +/** + * @brief Get the graphics version for a GPU device + * + * @details Given a device ID @p dv_ind and a uint64_t pointer + * @p gfx_version, this function will write the graphics version. + * + * @param[in] dv_ind a device index + * + * @param[inout] gfx_version The device graphics version number indicated by + * KFD. If this parameter is nullptr, this function will return + * ::RSMI_STATUS_INVALID_ARGS. If device does not support this value, + * will return ::RSMI_STATUS_NOT_SUPPORTED and a maximum UINT64 value as + * @p gfx_version. + * + * @retval ::RSMI_STATUS_SUCCESS call was successful + * @retval ::RSMI_STATUS_NOT_SUPPORTED installed software or hardware does not + * support this function with the given arguments + * @retval ::RSMI_STATUS_INVALID_ARGS the provided arguments are not valid + * + */ +rsmi_status_t rsmi_dev_target_graphics_version_get(uint32_t dv_ind, + uint64_t *gfx_version); + /** @} */ // end of VersQuer /*****************************************************************************/ diff --git a/projects/rocm-smi-lib/include/rocm_smi/rocm_smi_utils.h b/projects/rocm-smi-lib/include/rocm_smi/rocm_smi_utils.h index d0ea9337cd..18b1c1fcb5 100755 --- a/projects/rocm-smi-lib/include/rocm_smi/rocm_smi_utils.h +++ b/projects/rocm-smi-lib/include/rocm_smi/rocm_smi_utils.h @@ -123,6 +123,8 @@ std::string print_rsmi_od_volt_freq_regions(uint32_t num_regions, bool is_sudo_user(); rsmi_status_t rsmi_get_gfx_target_version(uint32_t dv_ind, std::string *gfx_version); +std::string removeString(const std::string origStr, + const std::string &removeMe); template std::string print_int_as_hex(T i, bool showHexNotation = true) { std::stringstream ss; diff --git a/projects/rocm-smi-lib/rocm_smi/example/rocm_smi_example.cc b/projects/rocm-smi-lib/rocm_smi/example/rocm_smi_example.cc index e8781b4fb8..76b1341c7b 100755 --- a/projects/rocm-smi-lib/rocm_smi/example/rocm_smi_example.cc +++ b/projects/rocm-smi-lib/rocm_smi/example/rocm_smi_example.cc @@ -53,6 +53,7 @@ #include #include #include +#include #include "rocm_smi/rocm_smi.h" #include "rocm_smi/rocm_smi_utils.h" @@ -780,6 +781,7 @@ int main() { uint32_t num_monitor_devs = 0; rsmi_gpu_metrics_t gpu_metrics; std::string val_str; + RSMI_POWER_TYPE power_type = RSMI_INVALID_POWER; rsmi_num_monitor_devices(&num_monitor_devs); @@ -791,8 +793,9 @@ int main() { ret = rsmi_dev_revision_get(i, &val_ui16); CHK_RSMI_RET_I(ret) std::cout << "\t**Dev.Rev.ID: 0x" << std::hex << val_ui16 << "\n"; - ret = amd::smi::rsmi_get_gfx_target_version(i , &val_str); - std::cout << "\t**Target Graphics Version: " << val_str << "\n"; + ret = rsmi_dev_target_graphics_version_get(i, &val_ui64); + std::cout << "\t**Target Graphics Version: " << std::dec + << static_cast(val_ui64) << "\n"; char current_compute_partition[256]; current_compute_partition[0] = '\0'; diff --git a/projects/rocm-smi-lib/src/rocm_smi.cc b/projects/rocm-smi-lib/src/rocm_smi.cc index 7122e26d50..29a535c509 100755 --- a/projects/rocm-smi-lib/src/rocm_smi.cc +++ b/projects/rocm-smi-lib/src/rocm_smi.cc @@ -5087,6 +5087,36 @@ rsmi_status_t rsmi_dev_memory_partition_reset(uint32_t dv_ind) { CATCH } +rsmi_status_t rsmi_dev_target_graphics_version_get(uint32_t dv_ind, + uint64_t *gfx_version) { + TRY + std::ostringstream ss; + ss << __PRETTY_FUNCTION__ << "| ======= start ======="; + rsmi_status_t ret = RSMI_STATUS_NOT_SUPPORTED; + std::string version = ""; + const uint64_t undefined_gfx_version = std::numeric_limits::max(); + LOG_TRACE(ss); + if (gfx_version == nullptr) { + ret = RSMI_STATUS_INVALID_ARGS; + } else { + *gfx_version = undefined_gfx_version; + ret = amd::smi::rsmi_get_gfx_target_version(dv_ind , &version); + } + if (ret == RSMI_STATUS_SUCCESS) { + version = amd::smi::removeString(version, "gfx"); + *gfx_version = std::stoull(version); + } + ss << __PRETTY_FUNCTION__ + << " | ======= end ======= " + << " | Returning: " << getRSMIStatusString(ret) + << " | Device #: " << dv_ind + << " | Type: N/A" + << " | Data: " << ((gfx_version == nullptr) ? "nullptr": std::to_string(*gfx_version)); + LOG_TRACE(ss); + return ret; + CATCH +} + enum iterator_handle_type { FUNC_ITER = 0, VARIANT_ITER, diff --git a/projects/rocm-smi-lib/src/rocm_smi_utils.cc b/projects/rocm-smi-lib/src/rocm_smi_utils.cc index a47c07e550..81546952fb 100755 --- a/projects/rocm-smi-lib/src/rocm_smi_utils.cc +++ b/projects/rocm-smi-lib/src/rocm_smi_utils.cc @@ -1144,16 +1144,31 @@ bool is_sudo_user() { return isRunningWithSudo; } -rsmi_status_t rsmi_get_gfx_target_version(uint32_t dv_ind, - std::string *gfx_version) { +// string output of gfx_ +rsmi_status_t rsmi_get_gfx_target_version(uint32_t dv_ind, std::string *gfx_version) { std::ostringstream ss; uint64_t kfd_gfx_version = 0; GET_DEV_AND_KFDNODE_FROM_INDX int ret = kfd_node->get_gfx_target_version(&kfd_gfx_version); + uint64_t orig_target_version = 0; + uint64_t major = 0; + uint64_t minor = 0; + uint64_t rev = 0; if (ret == 0) { - ss << "gfx" << kfd_gfx_version; - *gfx_version = ss.str(); + orig_target_version = std::stoull(std::to_string(kfd_gfx_version)); + // separate out parts -> put back into normal graphics version format + major = static_cast((orig_target_version / 10000) * 100); + minor = static_cast((orig_target_version % 10000 / 100) * 10); + if (minor == 0) major *= 10; // 0 as a minor is correct, but bump up by 10 + rev = static_cast(orig_target_version % 100); + *gfx_version = "gfx" + std::to_string(major + minor + rev); + ss << __PRETTY_FUNCTION__ + << " | " << std::dec << "kfd_target_version = " << orig_target_version + << "; major = " << major << "; minor = " << minor << "; rev = " + << rev << "\nReporting rsmi_get_gfx_target_version = " << *gfx_version + << "\n"; + LOG_INFO(ss); return RSMI_STATUS_SUCCESS; } else { *gfx_version = "Unknown"; diff --git a/projects/rocm-smi-lib/tests/rocm_smi_test/functional/sys_info_read.cc b/projects/rocm-smi-lib/tests/rocm_smi_test/functional/sys_info_read.cc index 1a2d9ff4df..d7d681f5c9 100755 --- a/projects/rocm-smi-lib/tests/rocm_smi_test/functional/sys_info_read.cc +++ b/projects/rocm-smi-lib/tests/rocm_smi_test/functional/sys_info_read.cc @@ -48,6 +48,7 @@ #include #include +#include #include "gtest/gtest.h" #include "rocm_smi/rocm_smi.h" @@ -202,5 +203,15 @@ void TestSysInfoRead::Run(void) { err = rsmi_dev_firmware_version_get(i, block, nullptr); ASSERT_EQ(err, RSMI_STATUS_INVALID_ARGS); } + + err = rsmi_dev_target_graphics_version_get(i, &val_ui64); + IF_VERB(STANDARD) { + std::cout << "\t**Graphics Target version: " << std::dec + << val_ui64 << "\n"; + } + EXPECT_EQ(err, RSMI_STATUS_SUCCESS); + EXPECT_NE(val_ui64, std::numeric_limits::max()); + err = rsmi_dev_target_graphics_version_get(i, nullptr); + EXPECT_EQ(err, RSMI_STATUS_INVALID_ARGS); } } diff --git a/projects/rocm-smi-lib/tests/rocm_smi_test/main.cc b/projects/rocm-smi-lib/tests/rocm_smi_test/main.cc index 638b4224c8..9e691d3063 100755 --- a/projects/rocm-smi-lib/tests/rocm_smi_test/main.cc +++ b/projects/rocm-smi-lib/tests/rocm_smi_test/main.cc @@ -139,6 +139,10 @@ TEST(rsmitstReadOnly, TestVersionRead) { TestVersionRead tst; RunGenericTest(&tst); } +TEST(rsmitstReadOnly, TestSysInfoRead) { + TestSysInfoRead tst; + RunGenericTest(&tst); +} TEST(rsmitstReadOnly, FanRead) { TestFanRead tst; RunGenericTest(&tst); @@ -195,10 +199,6 @@ TEST(rsmitstReadWrite, TestPciReadWrite) { TestPciReadWrite tst; RunGenericTest(&tst); } -TEST(rsmitstReadOnly, TestSysInfoRead) { - TestSysInfoRead tst; - RunGenericTest(&tst); -} TEST(rsmitstReadOnly, TestGPUBusyRead) { TestGPUBusyRead tst; RunGenericTest(&tst);