Skip to content

Commit 7e023c8

Browse files
committed
Fix Windows subprocess issue
1 parent 73c6498 commit 7e023c8

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

sklbench/utils/env.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,15 @@ def get_numa_cpus_conf() -> Dict[int, str]:
4747

4848
def get_number_of_sockets():
4949
if sys.platform == "win32":
50-
command = "wmic cpu get DeviceID"
51-
result = subprocess.check_output(command, shell=False, text=True)
52-
n_sockets = len(list(filter(lambda x: x.startswith("CPU"), result.split("\n"))))
50+
try:
51+
command = ["wmic", "cpu", "get", "DeviceID"]
52+
result = subprocess.check_output(command, shell=False, text=True)
53+
n_sockets = len(
54+
list(filter(lambda x: x.startswith("CPU"), result.split("\n")))
55+
)
56+
except (FileNotFoundError, subprocess.CalledProcessError, ValueError, IndexError):
57+
logger.warning("Unable to get number of sockets via wmic")
58+
n_sockets = 1
5359
elif sys.platform == "linux":
5460
try:
5561
_, lscpu_text, _ = read_output_from_command("lscpu")

sklbench/utils/measurement.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ def get_n_from_cache_size():
124124
return ceil(sqrt(n_sockets * cache_size / 8))
125125

126126

127-
def flush_cache(n: int = get_n_from_cache_size()):
127+
def flush_cache(n: int | None = None):
128+
if n is None:
129+
n = get_n_from_cache_size()
128130
np.matmul(np.random.rand(n, n), np.random.rand(n, n))
129131

130132

0 commit comments

Comments
 (0)