15
15
# ===============================================================================
16
16
17
17
import json
18
- import logging
19
18
import os
20
19
import pathlib
21
20
import platform
@@ -68,6 +67,14 @@ def read_output_from_command(command: str,
68
67
return res .stdout [:- 1 ], res .stderr [:- 1 ]
69
68
70
69
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
+
71
78
def get_hw_parameters () -> Union [bool , Dict [Any , Any ]]:
72
79
if 'Linux' not in platform .platform ():
73
80
return {}
@@ -88,21 +95,36 @@ def get_hw_parameters() -> Union[bool, Dict[Any, Any]]:
88
95
mem_info = ' ' .join (mem_info .split ())
89
96
hw_params ['RAM size[GB]' ] = int (mem_info .split (' ' )[1 ]) / 2 ** 30
90
97
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
92
115
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
106
128
107
129
108
130
def get_sw_parameters () -> Dict [str , Dict [str , Any ]]:
0 commit comments