Skip to content

Commit 4dd1c10

Browse files
bkanangomarifamd
authored andcommitted
Move build_xcp_dict def to helpers.
Signed-off-by: Bindhiya Kanangot Balakrishnan <[email protected]>
1 parent ee1445e commit 4dd1c10

File tree

2 files changed

+43
-43
lines changed

2 files changed

+43
-43
lines changed

amdsmi_cli/amdsmi_commands.py

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,31 +1427,6 @@ def bad_pages(self, args, multiple_devices=False, gpu=None, retired=None, pendin
14271427
self.logger.print_output()
14281428

14291429

1430-
def build_xcp_dict(self, key, violation_status, num_partition):
1431-
if not isinstance(violation_status[key], list):
1432-
if "active_" in key:
1433-
if violation_status[key] != "N/A":
1434-
if violation_status[key] is True:
1435-
violation_status[key] = "ACTIVE"
1436-
elif violation_status[key] is False:
1437-
violation_status[key] = "NOT ACTIVE"
1438-
ret = violation_status[key]
1439-
elif isinstance(violation_status[key], list):
1440-
for row in violation_status[key]:
1441-
for element in row:
1442-
if element != "N/A":
1443-
if "active_" in key:
1444-
if element is True:
1445-
row[row.index(element)] = "ACTIVE"
1446-
elif element is False:
1447-
row[row.index(element)] = "NOT ACTIVE"
1448-
elif ("per_" or "acc_") in key:
1449-
row[row.index(element)] = element
1450-
else:
1451-
continue
1452-
ret = {f"xcp_{i}": violation_status[key][i] for i in range(num_partition)}
1453-
return ret
1454-
14551430
def metric_gpu(self, args, multiple_devices=False, watching_output=False, gpu=None,
14561431
usage=None, watch=None, watch_time=None, iterations=None, power=None,
14571432
clock=None, temperature=None, ecc=None, ecc_blocks=None, pcie=None,
@@ -2662,30 +2637,30 @@ def metric_gpu(self, args, multiple_devices=False, watching_output=False, gpu=No
26622637
throttle_status['vr_thermal_accumulated'] = violation_status['acc_vr_thrm']
26632638
throttle_status['hbm_thermal_accumulated'] = violation_status['acc_hbm_thrm']
26642639
throttle_status['gfx_clk_below_host_limit_accumulated'] = violation_status['acc_gfx_clk_below_host_limit'] #deprecated
2665-
throttle_status['gfx_clk_below_host_limit_power_accumulated'] = self.build_xcp_dict('acc_gfx_clk_below_host_limit_pwr', violation_status, num_partition)
2666-
throttle_status['gfx_clk_below_host_limit_thermal_accumulated'] = self.build_xcp_dict('acc_gfx_clk_below_host_limit_thm', violation_status, num_partition)
2667-
throttle_status['total_gfx_clk_below_host_limit_accumulated'] = self.build_xcp_dict('acc_gfx_clk_below_host_limit_total', violation_status, num_partition)
2668-
throttle_status['low_utilization_accumulated'] = self.build_xcp_dict('acc_low_utilization', violation_status, num_partition)
2669-
throttle_status['prochot_violation_status'] = self.build_xcp_dict('active_prochot_thrm', violation_status, num_partition)
2670-
throttle_status['ppt_violation_status'] = self.build_xcp_dict('active_ppt_pwr', violation_status, num_partition)
2671-
throttle_status['socket_thermal_violation_status'] = self.build_xcp_dict('active_socket_thrm', violation_status, num_partition)
2672-
throttle_status['vr_thermal_violation_status'] = self.build_xcp_dict('active_vr_thrm', violation_status, num_partition)
2673-
throttle_status['hbm_thermal_violation_status'] = self.build_xcp_dict('active_hbm_thrm', violation_status, num_partition)
2674-
throttle_status['gfx_clk_below_host_limit_violation_status'] = self.build_xcp_dict('active_gfx_clk_below_host_limit', violation_status, num_partition) # deprecated
2675-
throttle_status['gfx_clk_below_host_limit_power_violation_status'] = self.build_xcp_dict('active_gfx_clk_below_host_limit_pwr', violation_status, num_partition)
2676-
throttle_status['gfx_clk_below_host_limit_thermal_violation_status'] = self.build_xcp_dict('active_gfx_clk_below_host_limit_thm', violation_status, num_partition)
2677-
throttle_status['total_gfx_clk_below_host_limit_violation_status'] = self.build_xcp_dict('active_gfx_clk_below_host_limit_total', violation_status, num_partition)
2678-
throttle_status['low_utilization_violation_status'] = self.build_xcp_dict('active_low_utilization', violation_status, num_partition)
2640+
throttle_status['gfx_clk_below_host_limit_power_accumulated'] = self.helpers.build_xcp_dict('acc_gfx_clk_below_host_limit_pwr', violation_status, num_partition)
2641+
throttle_status['gfx_clk_below_host_limit_thermal_accumulated'] = self.helpers.build_xcp_dict('acc_gfx_clk_below_host_limit_thm', violation_status, num_partition)
2642+
throttle_status['total_gfx_clk_below_host_limit_accumulated'] = self.helpers.build_xcp_dict('acc_gfx_clk_below_host_limit_total', violation_status, num_partition)
2643+
throttle_status['low_utilization_accumulated'] = self.helpers.build_xcp_dict('acc_low_utilization', violation_status, num_partition)
2644+
throttle_status['prochot_violation_status'] = self.helpers.build_xcp_dict('active_prochot_thrm', violation_status, num_partition)
2645+
throttle_status['ppt_violation_status'] = self.helpers.build_xcp_dict('active_ppt_pwr', violation_status, num_partition)
2646+
throttle_status['socket_thermal_violation_status'] = self.helpers.build_xcp_dict('active_socket_thrm', violation_status, num_partition)
2647+
throttle_status['vr_thermal_violation_status'] = self.helpers.build_xcp_dict('active_vr_thrm', violation_status, num_partition)
2648+
throttle_status['hbm_thermal_violation_status'] = self.helpers.build_xcp_dict('active_hbm_thrm', violation_status, num_partition)
2649+
throttle_status['gfx_clk_below_host_limit_violation_status'] = self.helpers.build_xcp_dict('active_gfx_clk_below_host_limit', violation_status, num_partition) # deprecated
2650+
throttle_status['gfx_clk_below_host_limit_power_violation_status'] = self.helpers.build_xcp_dict('active_gfx_clk_below_host_limit_pwr', violation_status, num_partition)
2651+
throttle_status['gfx_clk_below_host_limit_thermal_violation_status'] = self.helpers.build_xcp_dict('active_gfx_clk_below_host_limit_thm', violation_status, num_partition)
2652+
throttle_status['total_gfx_clk_below_host_limit_violation_status'] = self.helpers.build_xcp_dict('active_gfx_clk_below_host_limit_total', violation_status, num_partition)
2653+
throttle_status['low_utilization_violation_status'] = self.helpers.build_xcp_dict('active_low_utilization', violation_status, num_partition)
26792654
throttle_status['prochot_violation_activity'] = violation_status['per_prochot_thrm']
26802655
throttle_status['ppt_violation_activity'] = violation_status['per_ppt_pwr']
26812656
throttle_status['socket_thermal_violation_activity'] = violation_status['per_socket_thrm']
26822657
throttle_status['vr_thermal_violation_activity'] = violation_status['per_vr_thrm']
26832658
throttle_status['hbm_thermal_violation_activity'] = violation_status['per_hbm_thrm']
26842659
throttle_status['gfx_clk_below_host_limit_violation_activity'] = violation_status['per_gfx_clk_below_host_limit'] # deprecated
2685-
throttle_status['gfx_clk_below_host_limit_power_violation_activity'] = self.build_xcp_dict('per_gfx_clk_below_host_limit_pwr', violation_status, num_partition)
2686-
throttle_status['gfx_clk_below_host_limit_thermal_violation_activity'] = self.build_xcp_dict('per_gfx_clk_below_host_limit_thm', violation_status, num_partition)
2687-
throttle_status['total_gfx_clk_below_host_limit_violation_activity'] = self.build_xcp_dict('per_gfx_clk_below_host_limit_total', violation_status, num_partition)
2688-
throttle_status['low_utilization_violation_activity'] = self.build_xcp_dict('per_low_utilization', violation_status, num_partition)
2660+
throttle_status['gfx_clk_below_host_limit_power_violation_activity'] = self.helpers.build_xcp_dict('per_gfx_clk_below_host_limit_pwr', violation_status, num_partition)
2661+
throttle_status['gfx_clk_below_host_limit_thermal_violation_activity'] = self.helpers.build_xcp_dict('per_gfx_clk_below_host_limit_thm', violation_status, num_partition)
2662+
throttle_status['total_gfx_clk_below_host_limit_violation_activity'] = self.helpers.build_xcp_dict('per_gfx_clk_below_host_limit_total', violation_status, num_partition)
2663+
throttle_status['low_utilization_violation_activity'] = self.helpers.build_xcp_dict('per_low_utilization', violation_status, num_partition)
26892664

26902665
except amdsmi_exception.AmdSmiLibraryException as e:
26912666
values_dict['throttle'] = throttle_status

amdsmi_cli/amdsmi_helpers.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,31 @@ def get_bitmask_ranges(self, bitmask_dict):
16991699

17001700
return ranges
17011701

1702+
def build_xcp_dict(self, key, violation_status, num_partition):
1703+
if not isinstance(violation_status[key], list):
1704+
if "active_" in key:
1705+
if violation_status[key] != "N/A":
1706+
if violation_status[key] is True:
1707+
violation_status[key] = "ACTIVE"
1708+
elif violation_status[key] is False:
1709+
violation_status[key] = "NOT ACTIVE"
1710+
ret = violation_status[key]
1711+
elif isinstance(violation_status[key], list):
1712+
for row in violation_status[key]:
1713+
for element in row:
1714+
if element != "N/A":
1715+
if "active_" in key:
1716+
if element is True:
1717+
row[row.index(element)] = "ACTIVE"
1718+
elif element is False:
1719+
row[row.index(element)] = "NOT ACTIVE"
1720+
elif ("per_" in key) or ("acc_" in key):
1721+
row[row.index(element)] = element
1722+
else:
1723+
continue
1724+
ret = {f"xcp_{i}": violation_status[key][i] for i in range(num_partition)}
1725+
return ret
1726+
17021727
@staticmethod
17031728
def average_flattened_ints(data, context="data"):
17041729
"""Calculate the average of flattened integers from a list or tuple

0 commit comments

Comments
 (0)