Skip to content

Commit 06ae1ab

Browse files
committed
Shell usage fix
1 parent 8453243 commit 06ae1ab

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

sklbench/utils/common.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,12 @@ def custom_format(
5858
return output
5959

6060

61-
def read_output_from_command(command: str, shell=False) -> Tuple[int, str, str]:
61+
def read_output_from_command(command: str) -> Tuple[int, str, str]:
6262
"""Executes command and returns code, stdout and stderr"""
6363
res = sp.run(
64-
command if shell else command.split(" "),
64+
command.split(" "),
6565
stdout=sp.PIPE,
6666
stderr=sp.PIPE,
67-
shell=shell,
6867
encoding="utf-8",
6968
)
7069
return res.returncode, res.stdout[:-1], res.stderr[:-1]
@@ -197,7 +196,7 @@ def convert_to_numeric_if_possible(value: str) -> Union[Numeric, str]:
197196
return value
198197

199198

200-
def convert_to_numpy(a, dp_compat=False):
199+
def convert_to_numpy(a, dp_compat=False) -> np.ndarray:
201200
if dp_compat and ("dpctl" in str(type(a)) or "dpnp" in str(type(a))):
202201
return a
203202
if isinstance(a, np.ndarray):

sklbench/utils/env.py

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,21 @@
2323
from .logger import logger
2424

2525

26-
def get_numa_cpus_conf() -> Dict:
26+
def get_numa_cpus_conf() -> Dict[int, str]:
2727
try:
28-
_, numa_cpus_map, _ = read_output_from_command(
29-
"lscpu | grep NUMA | grep CPU | awk '{ print $4 }'", shell=True
30-
)
31-
return {i: cpus for i, cpus in enumerate(numa_cpus_map.split("\n"))}
28+
_, lscpu_text, _ = read_output_from_command("lscpu")
29+
return {
30+
i: numa_cpus
31+
for i, numa_cpus in enumerate(
32+
map(
33+
lambda x: x.split(" ")[-1],
34+
filter(
35+
lambda line: "NUMA" in line and "CPU(s)" in line,
36+
lscpu_text.split("\n"),
37+
),
38+
)
39+
)
40+
}
3241
except FileNotFoundError:
3342
logger.warning("Unable to get numa cpus configuration via lscpu")
3443
return dict()
@@ -54,26 +63,25 @@ def get_software_info() -> Dict:
5463

5564

5665
def get_oneapi_devices() -> pd.DataFrame:
57-
# # Removed until dpctl bug is fixed
58-
# # (lost devices in subprocesses)
59-
# try:
60-
# import dpctl
61-
# devices = dpctl.get_devices()
62-
# devices = {
63-
# device.filter_string: {
64-
# "name": device.name,
65-
# "vendor": device.vendor,
66-
# "type": str(device.device_type).split(".")[1],
67-
# "driver version": device.driver_version,
68-
# "memory size[GB]": device.global_mem_size / 2**30,
69-
# }
70-
# for device in devices
71-
# }
72-
# return pd.DataFrame(devices).T
73-
# except (ImportError, ModuleNotFoundError):
74-
# logger.warning("dpctl can not be imported")
75-
# # 'type' is left for device type selection only
76-
return pd.DataFrame({"type": list()})
66+
try:
67+
import dpctl
68+
69+
devices = dpctl.get_devices()
70+
devices = {
71+
device.filter_string: {
72+
"name": device.name,
73+
"vendor": device.vendor,
74+
"type": str(device.device_type).split(".")[1],
75+
"driver version": device.driver_version,
76+
"memory size[GB]": device.global_mem_size / 2**30,
77+
}
78+
for device in devices
79+
}
80+
return pd.DataFrame(devices).T
81+
except (ImportError, ModuleNotFoundError):
82+
logger.warning("dpctl can not be imported")
83+
# 'type' is left for device type selection only
84+
return pd.DataFrame({"type": list()})
7785

7886

7987
def get_higher_isa(cpu_flags: str) -> str:

0 commit comments

Comments
 (0)