Coverage for /opt/cloud/slavespace/usr1/096471637100f3de0fcfc01072822a80/ut/src/asys/common/ascend950/ascend950_handler.py: 39%

67 statements  

« prev     ^ index     » next       coverage.py v7.14.1, created at 2026-08-21 15:37 +0800

1#!/usr/bin/env python3 

2# -*- coding: utf-8 -*- 

3# ---------------------------------------------------------------------------- 

4# Copyright (c) 2025 Huawei Technologies Co., Ltd. 

5# 

6# Licensed under the Apache License, Version 2.0 (the "License"); 

7# you may not use this file except in compliance with the License. 

8# You may obtain a copy of the License at 

9# 

10# http://www.apache.org/licenses/LICENSE-2.0 

11# 

12# Unless required by applicable law or agreed to in writing, software 

13# distributed under the License is distributed on an "AS IS" BASIS, 

14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

15# See the License for the specific language governing permissions and 

16# limitations under the License. 

17# ---------------------------------------------------------------------------- 

18 

19import ctypes 

20from common import log_debug 

21from common.device import DeviceInfo 

22from common.device import DsmiNormalMemoryInfoStru, DsmiTagSensorInfo 

23from common.device import DSMI_MAIN_CMD_MEMORY, DSMI_SUB_CMD_HBM_MEMORY, MEMEORY_CONVERT_RATIO, SOC_TEMP_ID 

24from common.const import HBM_BANDWIDTH_USE, NOT_SUPPORT 

25import common.interface as interface 

26 

27 

28class Ascend950Handler(DeviceInfo): 

29 """Ascend950 device info""" 

30 SHIFT_BIT = 16 

31 MASK_BIT = 0xFFFF 

32 OFFSET = 0x0001 

33 UNSUPPORTED_KEY_WORDS = [NOT_SUPPORT, f"{NOT_SUPPORT}, {NOT_SUPPORT}"] 

34 

35 def __init__(self): 

36 super().__init__() 

37 

38 @classmethod 

39 def get_encode_component_one_id(cls, device_id): 

40 """Get the encoded component1 id, only supported when device_id < 65536.""" 

41 high_value = device_id >> cls.SHIFT_BIT 

42 if high_value: 

43 log_debug("Only supports encode component when device_id in [0, 65536)") 

44 return 0 

45 return (cls.OFFSET << cls.SHIFT_BIT) | (device_id & cls.MASK_BIT) 

46 

47 @classmethod 

48 def need_lp_param(cls): 

49 return True 

50 

51 def get_device_aic_info(self, device_id): 

52 """get aicore info, adapter to two component feature of ascend 950""" 

53 aic_c, aic_v0, aic_f0 = super().get_device_aic_info(device_id) 

54 component_one_id = self.get_encode_component_one_id(device_id) 

55 aic_v1, aic_f1 = [NOT_SUPPORT, NOT_SUPPORT] 

56 if component_one_id: 

57 _, aic_v1, aic_f1 = super().get_device_aic_info(component_one_id) 

58 return [aic_c, f"{aic_v0}, {aic_v1}", f"{aic_f0}, {aic_f1}"] 

59 

60 def get_device_bus_info(self, device_id): 

61 """get bus info, adapter to two component feature of ascend 950""" 

62 bus_v0, ring_f0, cpu_f0, mate_f0, l2_buf_f0 = super().get_device_bus_info(device_id) 

63 component_one_id = self.get_encode_component_one_id(device_id) 

64 bus_v1, ring_f1, mate_f1, l2_buf_f1 = [NOT_SUPPORT, NOT_SUPPORT, NOT_SUPPORT, NOT_SUPPORT] 

65 if component_one_id: 

66 bus_v1, ring_f1, _, mate_f1, l2_buf_f1 = super().get_device_bus_info(component_one_id) 

67 return [f"{bus_v0}, {bus_v1}", f"{ring_f0}, {ring_f1}", cpu_f0, 

68 f"{mate_f0}, {mate_f1}", f"{l2_buf_f0}, {l2_buf_f1}"] 

69 

70 def get_device_hbm_info(self, device_id): 

71 """get hbm info, adapter to Ascend950""" 

72 p_memory_info = ctypes.pointer(DsmiNormalMemoryInfoStru()) 

73 try: 

74 ret = self.dsmi_handle.dsmi_get_device_info( 

75 device_id, DSMI_MAIN_CMD_MEMORY, DSMI_SUB_CMD_HBM_MEMORY, 

76 p_memory_info, ctypes.pointer(ctypes.c_uint(ctypes.sizeof(DsmiNormalMemoryInfoStru()))) 

77 ) 

78 except AttributeError: 

79 return [NOT_SUPPORT, NOT_SUPPORT, NOT_SUPPORT, NOT_SUPPORT] 

80 if not self.check_status(ret, "Get memory info failed!"): 

81 return [NOT_SUPPORT, NOT_SUPPORT, NOT_SUPPORT, NOT_SUPPORT] 

82 

83 memory_size = p_memory_info.contents.total_size // MEMEORY_CONVERT_RATIO 

84 usage = p_memory_info.contents.used_size 

85 bandwidth = self.get_device_utilization_rate(device_id, HBM_BANDWIDTH_USE) 

86 return [memory_size, round(usage / MEMEORY_CONVERT_RATIO, 2), NOT_SUPPORT, bandwidth] 

87 

88 def get_device_voltage(self, device_id): 

89 """get aicore max voltage with 950""" 

90 voltage_value = super().get_device_voltage(device_id) 

91 return f"{voltage_value}(Max)" if voltage_value != NOT_SUPPORT else NOT_SUPPORT 

92 

93 def get_device_aicore_frequency(self, device_id): 

94 """get aicore avg frequency with 950""" 

95 aicore_frequecy = super().get_device_aicore_frequency(device_id) 

96 return f"{aicore_frequecy}(Avg)" if aicore_frequecy != NOT_SUPPORT else NOT_SUPPORT 

97 

98 def get_device_temperature(self, device_id): 

99 p_temperature = ctypes.pointer(DsmiTagSensorInfo()) 

100 try: 

101 ret = self.dsmi_handle.dsmi_get_soc_sensor_info(ctypes.c_int32(device_id), SOC_TEMP_ID, p_temperature) 

102 except AttributeError: 

103 return NOT_SUPPORT 

104 if not self.check_status(ret, "Get temperature info failed"): 

105 return NOT_SUPPORT 

106 return p_temperature.contents.iint 

107 

108 def run_diagnose(self, device_obj, diagnose_devices, run_mode): 

109 return interface.run_diagnose(device_obj, diagnose_devices, run_mode)