Skip to content

Commit 88a9b90

Browse files
committed
module for checking the gpu in the system
1 parent 95832fb commit 88a9b90

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

src/utils/core/gpu_install.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from subprocess import (
2+
Popen,
3+
CalledProcessError,
4+
PIPE,
5+
check_output
6+
)
7+
8+
from src.utils.log.logger import Logger
9+
10+
11+
def fetch_gpu(log: Logger) -> str | None:
12+
"""Fetch the GPU of the system.
13+
14+
Args:
15+
log -- instance of Logger
16+
17+
Returns:
18+
The name of GPU or None.
19+
"""
20+
21+
try:
22+
lspci_out = Popen(("lspci"), stdout=PIPE)
23+
gpu_name: str = check_output(
24+
["grep", "-i", "VGA"], stdin=lspci_out.stdout
25+
)
26+
lspci_out.wait()
27+
28+
if lspci_out.returncode != 0:
29+
raise SystemExit(["lspci"], lspci_out.returncode)
30+
except CalledProcessError as Err:
31+
log.logger("e", f"{Err}. Command lspci failed to execute.")
32+
return None
33+
else:
34+
return gpu_name

0 commit comments

Comments
 (0)