From 8eec0a7d369ff85735f0bea12676560ab0f7d375 Mon Sep 17 00:00:00 2001 From: "Bill(Shuzhou) Liu" Date: Mon, 12 Apr 2021 14:57:25 -0400 Subject: [PATCH] Add energy accumulator counter The energy accumulator counter tracks all energy consumed. Change-Id: I5b25f817b7802d81c477361447f0ecd7ec02fc61 --- include/rocm_smi/rocm_smi.h | 32 ++++++++++++++++++++++++++++++++ src/rocm_smi.cc | 24 ++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/include/rocm_smi/rocm_smi.h b/include/rocm_smi/rocm_smi.h index ddefebb941..939be4b623 100755 --- a/include/rocm_smi/rocm_smi.h +++ b/include/rocm_smi/rocm_smi.h @@ -1588,6 +1588,38 @@ rsmi_status_t rsmi_dev_pci_bandwidth_set(uint32_t dv_ind, uint64_t bw_bitmask); rsmi_status_t rsmi_dev_power_ave_get(uint32_t dv_ind, uint32_t sensor_ind, uint64_t *power); +/** + * @brief Get the energy accumulator counter of the device with provided + * device index. + * + * @details Given a device index @p dv_ind, a pointer to a uint64_t + * @p power, and a pointer to a uint64_t @p timestamp, this function will write + * amount of energy consumed to the uint64_t pointed to by @p power, + * and the timestamp to the uint64_t pointed to by @p timestamp. + * The rsmi_dev_power_ave_get() is an average of a short time. This function + * accumulates all energy consumed. + * + * @param[in] dv_ind a device index + * + * @param[inout] power a pointer to uint64_t to which the energy + * counter will be written + * If this parameter is nullptr, this function will return + * ::RSMI_STATUS_INVALID_ARGS if the function is supported with the provided, + * and ::RSMI_STATUS_NOT_SUPPORTED if it is not supported with the + * provided arguments. + * + * @param[inout] timestamp a pointer to uint64_t to which the timestamp + * will be written. + * + * @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_energy_count_get(uint32_t dv_ind, + uint64_t *power, uint64_t *timestamp); + /** * @brief Get the cap on power which, when reached, causes the system to take * action to reduce power. diff --git a/src/rocm_smi.cc b/src/rocm_smi.cc index 936e664bb3..1f26c0ba40 100755 --- a/src/rocm_smi.cc +++ b/src/rocm_smi.cc @@ -2513,6 +2513,30 @@ rsmi_dev_power_ave_get(uint32_t dv_ind, uint32_t sensor_ind, uint64_t *power) { CATCH } +rsmi_status_t +rsmi_dev_energy_count_get(uint32_t dv_ind, + uint64_t *power, uint64_t *timestamp) { + TRY + + rsmi_status_t ret; + rsmi_gpu_metrics_t gpu_metrics; + ret = rsmi_dev_gpu_metrics_info_get(dv_ind, &gpu_metrics); + if (ret != RSMI_STATUS_SUCCESS) { + return ret; + } + + if (power == nullptr || + timestamp == nullptr) { + return RSMI_STATUS_INVALID_ARGS; + } + + *power = gpu_metrics.energy_accumulator; + *timestamp = gpu_metrics.system_clock_counter; + + return ret; + CATCH +} + rsmi_status_t rsmi_dev_power_cap_get(uint32_t dv_ind, uint32_t sensor_ind, uint64_t *cap) { TRY