Commit d7a56e0b authored by one's avatar one
Browse files

SysInfo: Simplify smi commands

parent 511807b7
...@@ -286,23 +286,26 @@ def get_gpu_amd(self): ...@@ -286,23 +286,26 @@ def get_gpu_amd(self):
return gpu_dict return gpu_dict
def _merge_hygon_gpu_json_info(self, gpu_info, command): def _get_hygon_gpu_json_info(self, command):
"""Merge Hygon GPU info from json command output. """Get Hygon GPU info from json command output.
Args: Args:
gpu_info (dict): GPU info keyed by card id.
command (str): Command to get GPU info in json format. command (str): Command to get GPU info in json format.
Returns:
dict: Hygon GPU info keyed by card id.
""" """
gpu_info = {}
command_output = self._run_cmd(command) command_output = self._run_cmd(command)
command_info = json.loads(command_output) command_info = json.loads(command_output)
for card, card_info in command_info.items(): for card, card_info in command_info.items():
if not card.startswith('card'): if not card.startswith('card'):
continue continue
if card not in gpu_info: gpu_info[card] = {}
gpu_info[card] = {}
for key, value in card_info.items(): for key, value in card_info.items():
if key: if key:
gpu_info[card][key] = value gpu_info[card][key] = value
return gpu_info
def get_gpu_hygon(self): def get_gpu_hygon(self):
"""Get hygon gpu info.""" """Get hygon gpu info."""
...@@ -336,12 +339,11 @@ def get_gpu_hygon(self): ...@@ -336,12 +339,11 @@ def get_gpu_hygon(self):
'--showuse', '--showuse',
'--showbw', '--showbw',
] ]
for option in hygon_json_info_options: command = 'hy-smi --json {}'.format(' '.join(hygon_json_info_options))
command = 'hy-smi --json {}'.format(option) try:
try: gpu_dict['rocm_info'] = self._get_hygon_gpu_json_info(command)
self._merge_hygon_gpu_json_info(gpu_dict['rocm_info'], command) except Exception:
except Exception: logger.exception('Error: get hygon gpu info failed with command: %s', command)
logger.exception('Error: get hygon gpu info failed with command: %s', command)
try: try:
gpu_dict['topo'] = self._run_cmd('hy-smi --showtopo') gpu_dict['topo'] = self._run_cmd('hy-smi --showtopo')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment