Skip to content

Commit 523df30

Browse files
author
Igor Rukhovich
committed
Cleanup after someone's commit
1 parent 41e003f commit 523df30

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

utils.py

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# ===============================================================================
1616

1717
import json
18-
import logging
1918
import os
2019
import pathlib
2120
import platform
@@ -68,6 +67,14 @@ def read_output_from_command(command: str,
6867
return res.stdout[:-1], res.stderr[:-1]
6968

7069

70+
def parse_lscpu_lscl_info(command_output: str) -> Dict[str, str]:
71+
res: Dict[str, str] = {}
72+
for elem in command_output.strip().split('\n'):
73+
splt = elem.split(':')
74+
res[splt[0]] = splt[1]
75+
return res
76+
77+
7178
def get_hw_parameters() -> Union[bool, Dict[Any, Any]]:
7279
if 'Linux' not in platform.platform():
7380
return {}
@@ -88,21 +95,36 @@ def get_hw_parameters() -> Union[bool, Dict[Any, Any]]:
8895
mem_info = ' '.join(mem_info.split())
8996
hw_params['RAM size[GB]'] = int(mem_info.split(' ')[1]) / 2 ** 30
9097

91-
# get GPU information
98+
# get Intel GPU information
99+
try:
100+
lsgpu_info, _ = read_output_from_command(
101+
'lscl --device-type=gpu --platform-vendor=Intel')
102+
device_num = 0
103+
start_idx = lsgpu_info.find('Device ')
104+
while start_idx >= 0:
105+
start_idx = lsgpu_info.find(':', start_idx) + 1
106+
end_idx = lsgpu_info.find('Device ', start_idx)
107+
hw_params[f'GPU Intel #{device_num + 1}'] = parse_lscpu_lscl_info(
108+
lsgpu_info[start_idx: end_idx])
109+
device_num += 1
110+
start_idx = end_idx
111+
except (FileNotFoundError, json.JSONDecodeError):
112+
pass
113+
114+
# get Nvidia GPU information
92115
try:
93-
nfo, _ = read_output_from_command('lscpu')
94-
cpu_info = nfo.split('\n')
95-
for el in cpu_info:
96-
if 'Thread(s) per core' in el:
97-
threads_per_core = int(el[-1])
98-
if threads_per_core > 1:
99-
return True
100-
else:
101-
return False
102-
return False
103-
except FileNotFoundError:
104-
logging.info('Impossible to check hyperthreading via lscpu')
105-
return False
116+
gpu_info, _ = read_output_from_command(
117+
'nvidia-smi --query-gpu=name,memory.total,driver_version,pstate '
118+
'--format=csv,noheader')
119+
gpu_info_arr = gpu_info.split(', ')
120+
hw_params['GPU Nvidia'] = {
121+
'Name': gpu_info_arr[0],
122+
'Memory size': gpu_info_arr[1],
123+
'Performance mode': gpu_info_arr[3]
124+
}
125+
except (FileNotFoundError, json.JSONDecodeError):
126+
pass
127+
return hw_params
106128

107129

108130
def get_sw_parameters() -> Dict[str, Dict[str, Any]]:

0 commit comments

Comments
 (0)