Skip to content

Commit 251a00c

Browse files
committed
Fix cpuinfo usage on Windows
1 parent acde702 commit 251a00c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

sklbench/utils/measurement.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,15 @@ def enrich_metrics(
113113

114114
def get_n_from_cache_size():
115115
"""Gets `n` size of square matrix that fits into L3 cache"""
116-
l3_size = get_cpu_info()["l3_cache_size"]
116+
cache_size = 0
117+
cpu_info = get_cpu_info()
118+
# cache reading abibility of cpuinfo is platform dependent
119+
if "l3_cache_size" in cpu_info:
120+
cache_size += cpu_info["l3_cache_size"]
121+
if "l2_cache_size" in cpu_info:
122+
cache_size += cpu_info["l2_cache_size"] * psutil.cpu_count(logical=False)
117123
n_sockets = get_number_of_sockets()
118-
return ceil(sqrt(n_sockets * l3_size / 8))
124+
return ceil(sqrt(n_sockets * cache_size / 8))
119125

120126

121127
def flush_cache(n: int = get_n_from_cache_size()):

0 commit comments

Comments
 (0)