From 108cf12a97fd80d8687dbe941a630912cc01a7ec Mon Sep 17 00:00:00 2001 From: Harish Kasiviswanathan Date: Wed, 21 Apr 2021 16:22:50 -0400 Subject: [PATCH] Add energy counter resolution to rsmi_dev_energy_count_get Signed-off-by: Harish Kasiviswanathan Change-Id: I03b70968257db7a45e21d7ba62542cdedd18eb85 [ROCm/rocm_smi_lib commit: 844acbc0d8d887ca6e6e1462f83d3b9a09a787b1] --- projects/rocm-smi-lib/include/rocm_smi/rocm_smi.h | 6 ++++-- projects/rocm-smi-lib/src/rocm_smi.cc | 9 +++++++-- .../rocm_smi_test/functional/metrics_counter_read.cc | 9 ++++++--- 3 files changed, 17 insertions(+), 7 deletions(-) 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 84ae0f0ad6..4bf4230a27 100755 --- a/projects/rocm-smi-lib/include/rocm_smi/rocm_smi.h +++ b/projects/rocm-smi-lib/include/rocm_smi/rocm_smi.h @@ -1603,6 +1603,8 @@ rsmi_dev_power_ave_get(uint32_t dv_ind, uint32_t sensor_ind, uint64_t *power); * accumulates all energy consumed. * * @param[in] dv_ind a device index + * @param[inout] counter_resolution resolution of the counter @p power in + * micro Joules * * @param[inout] power a pointer to uint64_t to which the energy * counter will be written @@ -1620,8 +1622,8 @@ rsmi_dev_power_ave_get(uint32_t dv_ind, uint32_t sensor_ind, uint64_t *power); * @retval ::RSMI_STATUS_INVALID_ARGS the provided arguments are not valid */ rsmi_status_t -rsmi_dev_energy_count_get(uint32_t dv_ind, - uint64_t *power, uint64_t *timestamp); +rsmi_dev_energy_count_get(uint32_t dv_ind, uint64_t *power, + float *counter_resolution, uint64_t *timestamp); /** * @brief Get the cap on power which, when reached, causes the system to take diff --git a/projects/rocm-smi-lib/src/rocm_smi.cc b/projects/rocm-smi-lib/src/rocm_smi.cc index 272b56cb71..dd9ff94502 100755 --- a/projects/rocm-smi-lib/src/rocm_smi.cc +++ b/projects/rocm-smi-lib/src/rocm_smi.cc @@ -75,6 +75,7 @@ #include "rocm_smi/rocm_smi64Config.h" static const uint32_t kMaxOverdriveLevel = 20; +static const float kEnergyCounterResolution = 15.3f; #define TRY try { #define CATCH } catch (...) {return amd::smi::handleException();} @@ -2604,8 +2605,8 @@ rsmi_dev_power_ave_get(uint32_t dv_ind, uint32_t sensor_ind, uint64_t *power) { } rsmi_status_t -rsmi_dev_energy_count_get(uint32_t dv_ind, - uint64_t *power, uint64_t *timestamp) { +rsmi_dev_energy_count_get(uint32_t dv_ind, uint64_t *power, + float *counter_resolution, uint64_t *timestamp) { TRY rsmi_status_t ret; @@ -2622,6 +2623,10 @@ rsmi_dev_energy_count_get(uint32_t dv_ind, *power = gpu_metrics.energy_accumulator; *timestamp = gpu_metrics.system_clock_counter; + // hard-coded for now since all ASICs have same resolution. If it ASIC + // dependent then this information should come from Kernel + if (counter_resolution) + *counter_resolution = kEnergyCounterResolution; return ret; CATCH diff --git a/projects/rocm-smi-lib/tests/rocm_smi_test/functional/metrics_counter_read.cc b/projects/rocm-smi-lib/tests/rocm_smi_test/functional/metrics_counter_read.cc index e8af7c79e6..2b3b503030 100644 --- a/projects/rocm-smi-lib/tests/rocm_smi_test/functional/metrics_counter_read.cc +++ b/projects/rocm-smi-lib/tests/rocm_smi_test/functional/metrics_counter_read.cc @@ -105,7 +105,8 @@ void TestMetricsCounterRead::Run(void) { uint64_t power; uint64_t timestamp; - err = rsmi_dev_energy_count_get(i, &power, ×tamp); + float counter_resolution; + err = rsmi_dev_energy_count_get(i, &power, &counter_resolution, ×tamp); if (err != RSMI_STATUS_SUCCESS) { if (err == RSMI_STATUS_NOT_SUPPORTED) { IF_VERB(STANDARD) { @@ -117,15 +118,17 @@ void TestMetricsCounterRead::Run(void) { } else { CHK_ERR_ASRT(err); IF_VERB(STANDARD) { - std::cout << std::dec << "power=" + std::cout << std::dec << "power counter=" << power << '\n'; + std::cout << "power in uJ=" + << (double)(power * counter_resolution) << '\n'; std::cout << std::dec << "timestamp=" << timestamp << '\n'; } } // Verify api support checking functionality is working - err = rsmi_dev_energy_count_get(i, nullptr, nullptr); + err = rsmi_dev_energy_count_get(i, nullptr, nullptr, nullptr); ASSERT_EQ(err, RSMI_STATUS_INVALID_ARGS); // Coarse Grain counters