Skip to content

Commit 2c1b089

Browse files
committed
arch: Additional tweaks
1 parent d99468f commit 2c1b089

2 files changed

Lines changed: 44 additions & 6 deletions

File tree

devito/arch/archinfo.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
from devito.tools import all_equal, as_tuple, memoized_func
2020
from devito.warnings import warn
2121

22-
from .commands import lscpu, lshw, lspci, nvidia_smi, proc_cpuinfo, rocm_smi, sycl_ls
22+
from .commands import (
23+
lscpu, lshw, lspci_gpu, nvidia_smi, proc_cpuinfo, rocm_smi, sycl_ls
24+
)
2325

2426

2527
__all__ = [ # noqa: RUF022
@@ -193,7 +195,7 @@ def get_cpu_info():
193195
try:
194196
cpu_info = cpuinfo.get_cpu_info()
195197
except Exception as e:
196-
warn(f'Calling `cpuinfo.get_cpu_info()` faised an exception\n {e !s}')
198+
warn(f'Calling `cpuinfo.get_cpu_info()` raised an exception\n {e !s}')
197199
cpu_info = {}
198200

199201
cpu_info['logical'] = psutil.cpu_count(logical=True)
@@ -620,11 +622,11 @@ def get_gpu_info():
620622
- architecture: str, fallback 'unspecified'
621623
"""
622624

623-
for call in [nvidia_smi, rocm_smi, sycl_ls, lshw, lspci]:
625+
for call in [nvidia_smi, rocm_smi, sycl_ls, lshw, lspci_gpu]:
624626
try:
625627
gpu_info = homogenise_gpus(call())
626628
break
627-
except (OSError):
629+
except (OSError, FileNotFoundError, CalledProcessError):
628630
gpu_info = {}
629631

630632
# Attach callbacks to retrieve instantaneous memory info

devito/arch/commands.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
'lscpu',
1313
'lshw',
1414
'lspci',
15+
'lspci_gpu',
1516
'nvidia_smi',
1617
'nvidia_smi_memory',
1718
'proc_cpuinfo',
@@ -171,7 +172,7 @@ def nvidia_smi_memory():
171172
# the output format (though we still have tests in place that
172173
# will catch this)
173174
vals = []
174-
for value in line.split(', ')
175+
for value in line.split(', '):
175176
_, v, unit = re.split(r'([0-9]+)\s', line)
176177
assert unit == 'MiB'
177178
vals.append(int(v)*10**6)
@@ -331,7 +332,7 @@ def lshw():
331332
return filter_real_gpus(gpu_infos)
332333

333334

334-
def lspci():
335+
def old_lspci():
335336
ret = run(['lspci'], capture_output=True, text=True)
336337
lines = ret.stdout.splitlines()
337338

@@ -363,3 +364,38 @@ def lspci():
363364
gpu_infos.append(gpu_info)
364365

365366
return filter_real_gpus(gpu_infos)
367+
368+
369+
def lspci():
370+
ret = run(['lspci', '-mm', '-v'], capture_output=True, text=True)
371+
blocks = ret.stdout.strip().split('\n\n')
372+
373+
pci_info = {}
374+
for device in blocks:
375+
line = device.splitlines()
376+
slot = line[0].split(':', 1)[1].strip()
377+
info = {
378+
(part:=l.split(':', 1))[0]: part[1].strip()
379+
for l in line[1:]
380+
}
381+
pci_info[slot] = info
382+
return pci_info
383+
384+
385+
def lspci_gpu():
386+
devices = lspci()
387+
388+
gpu_info = []
389+
for dev in devices.values():
390+
# Graphics cards are listed as VGA, 3D controllers or Displays in lspci
391+
if any(sub in dev['Class'] for sub in ('VGA', '3D', 'Display')):
392+
info = {}
393+
info['class'] = dev['Class']
394+
info['vendor'] = dev['Vendor']
395+
info['device'] = dev['Device']
396+
info['product'] = dev['Device']
397+
info['architecture'] = 'unspecified'
398+
info['physicalid'] = 'unknown'
399+
gpu_info.append(info)
400+
401+
return filter_real_gpus(gpu_info)

0 commit comments

Comments
 (0)