From b6ce6d30f4da291a55c5217217de8011d9fa1e2d Mon Sep 17 00:00:00 2001 From: Chris Freehill Date: Mon, 7 Jan 2019 08:44:23 -0600 Subject: [PATCH] Add support for reading frequency-volt curve data --- src/rocm_smi.cc | 20 ++++++++-- src/rocm_smi_device.cc | 3 ++ tests/rocm_smi_test/functional/rsmi_sanity.cc | 37 ++++++++++--------- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/src/rocm_smi.cc b/src/rocm_smi.cc index bbe6f42fce..ebcce80db9 100755 --- a/src/rocm_smi.cc +++ b/src/rocm_smi.cc @@ -147,7 +147,7 @@ static uint64_t freq_string_to_int(const std::vector &freq_lines, std::istringstream fs(freq_lines[i]); uint32_t ind; - uint64_t freq; + long double freq; std::string junk; std::string units_str; std::string star_str; @@ -183,8 +183,8 @@ static void freq_volt_string_to_point(std::string in_line, assert(pt != nullptr); uint32_t ind; - float freq; - float volts; + long double freq; + long double volts; std::string junk; std::string freq_units_str; std::string volts_units_str; @@ -633,6 +633,8 @@ static const uint32_t kOD_OD_RANGE_label_array_index = kOD_VDDC_CURVE_label_array_index + 4; static const uint32_t kOD_VDDC_CURVE_start_index = kOD_OD_RANGE_label_array_index + 3; +static const uint32_t kOD_VDDC_CURVE_num_lines = + kOD_VDDC_CURVE_start_index + 4; static rsmi_status_t get_od_clk_volt_info(uint32_t dv_ind, rsmi_od_volt_freq_data *p) { @@ -647,6 +649,12 @@ static rsmi_status_t get_od_clk_volt_info(uint32_t dv_ind, return ret; } + // This is a work-around to handle systems where kDevPowerODVoltage is not + // fully supported yet. + if (val_vec.size() < 2) { + return RSMI_STATUS_NOT_YET_IMPLEMENTED; + } + assert(val_vec[kOD_SCLK_label_array_index] == "OD_SCLK:"); p->curr_sclk_range.lower_bound = freq_string_to_int(val_vec, nullptr, @@ -723,6 +731,12 @@ static rsmi_status_t get_od_clk_volt_curve_regions(uint32_t dv_ind, return ret; } + // This is a work-around to handle systems where kDevPowerODVoltage is not + // fully supported yet. + if (val_vec.size() < 2) { + return RSMI_STATUS_NOT_YET_IMPLEMENTED; + } + uint32_t val_vec_size = val_vec.size(); assert((val_vec_size - kOD_VDDC_CURVE_start_index) > 0); assert((val_vec_size - kOD_VDDC_CURVE_start_index)%2 == 0); diff --git a/src/rocm_smi_device.cc b/src/rocm_smi_device.cc index c4823fe0aa..1f10f85a5a 100755 --- a/src/rocm_smi_device.cc +++ b/src/rocm_smi_device.cc @@ -250,6 +250,9 @@ int Device::readDevInfoMultiLineStr(DevInfoTypes type, retVec->push_back(line); } + if (retVec->size() == 0) { + return EPERM; + } // Remove any *trailing* empty (whitespace) lines while (retVec->back().find_first_not_of(" \t\n\v\f\r") == std::string::npos) { retVec->pop_back(); diff --git a/tests/rocm_smi_test/functional/rsmi_sanity.cc b/tests/rocm_smi_test/functional/rsmi_sanity.cc index c9dba5ed78..6d339d23b4 100755 --- a/tests/rocm_smi_test/functional/rsmi_sanity.cc +++ b/tests/rocm_smi_test/functional/rsmi_sanity.cc @@ -63,7 +63,8 @@ static uint32_t gVerbosity = 3; std::cout << "RSMI call returned " << (RET); \ rsmi_status_string((RET), &err_str); \ std::cout << " (" << err_str << ")" << std::endl; \ - std::cout << " at " << __FILE__ << ":" << __LINE__ << std::endl; \ + std::cout << " at " << __FILE__ << ":" << std::dec << __LINE__ << \ + std::endl; \ } \ } @@ -92,7 +93,8 @@ static uint32_t gVerbosity = 3; std::cout << "ASSERT failure: Expected " << #A << " == " << #B << \ ", but got " << #A << " = " << (A) << ", and " << #B << " = " << \ (B) << std::endl; \ - std::cout << " at " << __FILE__ << ":" << __LINE__ << std::endl; \ + std::cout << " at " << __FILE__ << ":" << std::dec << \ + __LINE__ << std::endl; \ return RSMI_STATUS_UNKNOWN_ERROR; \ } \ } @@ -648,26 +650,27 @@ void TestSanity::Run(void) { } err = rsmi_dev_od_volt_info_get(i, &odv); - CHK_ERR_ASRT(err) + DISPLAY_RSMI_ERR(err) - std::cout << "\t**Frequency-voltage curve data:" << std::endl; - print_rsmi_od_volt_freq_data(&odv); + if (err == RSMI_STATUS_SUCCESS) { + std::cout << "\t**Frequency-voltage curve data:" << std::endl; + print_rsmi_od_volt_freq_data(&odv); - rsmi_freq_volt_region *regions; - uint32_t num_regions; - regions = new rsmi_freq_volt_region[odv.num_regions]; - ASSERT_TRUE(regions != nullptr); + rsmi_freq_volt_region *regions; + uint32_t num_regions; + regions = new rsmi_freq_volt_region[odv.num_regions]; + ASSERT_TRUE(regions != nullptr); - num_regions = odv.num_regions; - err = rsmi_dev_od_volt_curve_regions_get(i, &num_regions, regions); - CHK_ERR_ASRT(err) - ASSERT_TRUE(num_regions == odv.num_regions); + num_regions = odv.num_regions; + err = rsmi_dev_od_volt_curve_regions_get(i, &num_regions, regions); + CHK_ERR_ASRT(err) + ASSERT_TRUE(num_regions == odv.num_regions); - std::cout << "\t**Frequency-voltage curve regions:" << std::endl; - print_rsmi_od_volt_freq_regions(num_regions, regions); - - delete []regions; + std::cout << "\t**Frequency-voltage curve regions:" << std::endl; + print_rsmi_od_volt_freq_regions(num_regions, regions); + delete []regions; + } err = rsmi_dev_perf_level_get(i, &pfl); CHK_ERR_ASRT(err)