Add energy counter resolution to rsmi_dev_energy_count_get

Signed-off-by: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>
Change-Id: I03b70968257db7a45e21d7ba62542cdedd18eb85


[ROCm/rocm_smi_lib commit: 844acbc0d8]
This commit is contained in:
Harish Kasiviswanathan
2021-04-21 16:22:50 -04:00
parent 6b4889a3a4
commit 108cf12a97
3 changed files with 17 additions and 7 deletions
@@ -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
+7 -2
View File
@@ -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
@@ -105,7 +105,8 @@ void TestMetricsCounterRead::Run(void) {
uint64_t power;
uint64_t timestamp;
err = rsmi_dev_energy_count_get(i, &power, &timestamp);
float counter_resolution;
err = rsmi_dev_energy_count_get(i, &power, &counter_resolution, &timestamp);
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