Coverage for /opt/cloud/slavespace/usr1/096471637100f3de0fcfc01072822a80/ut/src/asys/common/ascend950/ascend950_handler.py: 86%
70 statements
« prev ^ index » next coverage.py v7.15.3, created at 2026-08-11 18:39 +0800
« prev ^ index » next coverage.py v7.15.3, created at 2026-08-11 18:39 +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# ----------------------------------------------------------------------------
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
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}"]
35 def __init__(self):
36 super().__init__()
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)
47 @classmethod
48 def need_lp_param(cls):
49 return True
51 @classmethod
52 def support_dvpp(cls):
53 return True
55 def get_device_aic_info(self, device_id):
56 """get aicore info, adapter to two component feature of ascend 950"""
57 aic_c, aic_v0, aic_f0 = super().get_device_aic_info(device_id)
58 component_one_id = self.get_encode_component_one_id(device_id)
59 aic_v1, aic_f1 = [NOT_SUPPORT, NOT_SUPPORT]
60 if component_one_id:
61 _, aic_v1, aic_f1 = super().get_device_aic_info(component_one_id)
62 return [aic_c, f"{aic_v0}, {aic_v1}", f"{aic_f0}, {aic_f1}"]
64 def get_device_bus_info(self, device_id):
65 """get bus info, adapter to two component feature of ascend 950"""
66 bus_v0, ring_f0, cpu_f0, mate_f0, l2_buf_f0 = super().get_device_bus_info(device_id)
67 component_one_id = self.get_encode_component_one_id(device_id)
68 bus_v1, ring_f1, mate_f1, l2_buf_f1 = [NOT_SUPPORT, NOT_SUPPORT, NOT_SUPPORT, NOT_SUPPORT]
69 if component_one_id:
70 bus_v1, ring_f1, _, mate_f1, l2_buf_f1 = super().get_device_bus_info(component_one_id)
71 return [f"{bus_v0}, {bus_v1}", f"{ring_f0}, {ring_f1}", cpu_f0,
72 f"{mate_f0}, {mate_f1}", f"{l2_buf_f0}, {l2_buf_f1}"]
74 def get_device_hbm_info(self, device_id):
75 """get hbm info, adapter to Ascend950"""
76 p_memory_info = ctypes.pointer(DsmiNormalMemoryInfoStru())
77 try:
78 ret = self.dsmi_handle.dsmi_get_device_info(
79 device_id, DSMI_MAIN_CMD_MEMORY, DSMI_SUB_CMD_HBM_MEMORY,
80 p_memory_info, ctypes.pointer(ctypes.c_uint(ctypes.sizeof(DsmiNormalMemoryInfoStru())))
81 )
82 except AttributeError:
83 return [NOT_SUPPORT, NOT_SUPPORT, NOT_SUPPORT, NOT_SUPPORT]
84 if not self.check_status(ret, "Get memory info failed!"):
85 return [NOT_SUPPORT, NOT_SUPPORT, NOT_SUPPORT, NOT_SUPPORT]
87 memory_size = p_memory_info.contents.total_size // MEMEORY_CONVERT_RATIO
88 usage = p_memory_info.contents.used_size
89 bandwidth = self.get_device_utilization_rate(device_id, HBM_BANDWIDTH_USE)
90 return [memory_size, round(usage / MEMEORY_CONVERT_RATIO, 2), NOT_SUPPORT, bandwidth]
92 def get_device_voltage(self, device_id):
93 """get aicore max voltage with 950"""
94 voltage_value = super().get_device_voltage(device_id)
95 return f"{voltage_value}(Max)" if voltage_value != NOT_SUPPORT else NOT_SUPPORT
97 def get_device_aicore_frequency(self, device_id):
98 """get aicore avg frequency with 950"""
99 aicore_frequecy = super().get_device_aicore_frequency(device_id)
100 return f"{aicore_frequecy}(Avg)" if aicore_frequecy != NOT_SUPPORT else NOT_SUPPORT
102 def get_device_temperature(self, device_id):
103 p_temperature = ctypes.pointer(DsmiTagSensorInfo())
104 try:
105 ret = self.dsmi_handle.dsmi_get_soc_sensor_info(ctypes.c_int32(device_id), SOC_TEMP_ID, p_temperature)
106 except AttributeError:
107 return NOT_SUPPORT
108 if not self.check_status(ret, "Get temperature info failed"):
109 return NOT_SUPPORT
110 return p_temperature.contents.iint
112 def run_diagnose(self, device_obj, diagnose_devices, run_mode):
113 return interface.run_diagnose(device_obj, diagnose_devices, run_mode)