From 83cd2fe4f19e3e1cbca2d2d53eb29fdce8b77e77 Mon Sep 17 00:00:00 2001 From: Ori Messinger Date: Thu, 1 Apr 2021 08:04:53 -0400 Subject: [PATCH] ROCm SMI LIB: Add Default GPU Power Cap Implement default GPU power cap functionality in the LIB. Signed-off-by: Ori Messinger Change-Id: Ia6b3420beb0e4df5559c3e6d11d0667972590b53 --- include/rocm_smi/rocm_smi.h | 24 ++++++++++++++++++++++++ include/rocm_smi/rocm_smi_monitor.h | 1 + src/rocm_smi.cc | 16 ++++++++++++++++ src/rocm_smi_monitor.cc | 6 ++++++ 4 files changed, 47 insertions(+) diff --git a/include/rocm_smi/rocm_smi.h b/include/rocm_smi/rocm_smi.h index 4bf4230a27..c45aebef07 100755 --- a/include/rocm_smi/rocm_smi.h +++ b/include/rocm_smi/rocm_smi.h @@ -1653,6 +1653,30 @@ rsmi_dev_energy_count_get(uint32_t dv_ind, uint64_t *power, rsmi_status_t rsmi_dev_power_cap_get(uint32_t dv_ind, uint32_t sensor_ind, uint64_t *cap); +/** + * @brief Get the default power cap for the device specified by @p dv_ind. + * + * @details The maximum power cap be temporarily changed by the user. However, + * this function always returns the default reset power cap. The power level + * returned through @p power will be in microWatts. + * + * @param[in] dv_ind a device index + * + * @param[inout] default_cap a pointer to a uint64_t that indicates the default + * power cap, in microwatts + * If this parameter is nullptr, this function will return + * ::RSMI_STATUS_INVALID_ARGS if the function is supported with the provided, + * arguments and ::RSMI_STATUS_NOT_SUPPORTED if it is not supported with the + * provided arguments. + * + * @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_power_cap_default_get(uint32_t dv_ind, uint64_t *default_cap); + /** * @brief Get the range of valid values for the power cap * diff --git a/include/rocm_smi/rocm_smi_monitor.h b/include/rocm_smi/rocm_smi_monitor.h index a6da48bf84..c6bba27a60 100755 --- a/include/rocm_smi/rocm_smi_monitor.h +++ b/include/rocm_smi/rocm_smi_monitor.h @@ -63,6 +63,7 @@ enum MonitorTypes { kMonFanRPMs, kMonFanCntrlEnable, kMonPowerCap, + kMonPowerCapDefault, kMonPowerCapMax, kMonPowerCapMin, kMonPowerAve, diff --git a/src/rocm_smi.cc b/src/rocm_smi.cc index dd9ff94502..564b7ec22a 100755 --- a/src/rocm_smi.cc +++ b/src/rocm_smi.cc @@ -2632,6 +2632,22 @@ rsmi_dev_energy_count_get(uint32_t dv_ind, uint64_t *power, CATCH } +rsmi_status_t +rsmi_dev_power_cap_default_get(uint32_t dv_ind, uint64_t *default_cap) { + TRY + + uint32_t sensor_ind = 1; // power sysfs files have 1-based indices + CHK_SUPPORT_SUBVAR_ONLY(default_cap, sensor_ind) + + rsmi_status_t ret; + + DEVICE_MUTEX + ret = get_dev_mon_value(amd::smi::kMonPowerCapDefault, dv_ind, sensor_ind, default_cap); + + return ret; + CATCH +} + rsmi_status_t rsmi_dev_power_cap_get(uint32_t dv_ind, uint32_t sensor_ind, uint64_t *cap) { TRY diff --git a/src/rocm_smi_monitor.cc b/src/rocm_smi_monitor.cc index 97ceeaacc1..6b55a5b041 100755 --- a/src/rocm_smi_monitor.cc +++ b/src/rocm_smi_monitor.cc @@ -73,6 +73,7 @@ static const char *kMonMaxFanSpeedFName = "pwm#_max"; static const char *kMonFanRPMsName = "fan#_input"; static const char *kMonFanControlEnableName = "pwm#_enable"; static const char *kMonNameFName = "name"; +static const char *kMonPowerCapDefaultName = "power#_cap_default"; static const char *kMonPowerCapName = "power#_cap"; static const char *kMonPowerCapMaxName = "power#_cap_max"; static const char *kMonPowerCapMinName = "power#_cap_min"; @@ -128,6 +129,7 @@ static const std::map kMonitorNameMap = { {kMonMaxFanSpeed, kMonMaxFanSpeedFName}, {kMonFanRPMs, kMonFanRPMsName}, {kMonPowerCap, kMonPowerCapName}, + {kMonPowerCapDefault, kMonPowerCapDefaultName}, {kMonPowerCapMax, kMonPowerCapMaxName}, {kMonPowerCapMin, kMonPowerCapMinName}, {kMonPowerAve, kMonPowerAveName}, @@ -198,6 +200,10 @@ static const std::map kMonFuncDependsMap = { .variants = {kMonInvalid}, } }, + {"rsmi_dev_power_cap_default_get", { .mandatory_depends = {kMonPowerCapDefaultName}, + .variants = {kMonInvalid}, + } + }, {"rsmi_dev_power_cap_range_get", { .mandatory_depends = {kMonPowerCapMaxName, kMonPowerCapMinName},