Skip to content

Commit 16d5e5d

Browse files
committed
fix init script for archspec 0.1.3 (cfr. EESSI#142)
1 parent 49db988 commit 16d5e5d

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

init/eessi_software_subdir_for_host.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import platform
88
import sys
99
import archspec.cpu
10+
from archspec.cpu.detect import compatible_microarchitectures, raw_info_dictionary
1011

1112
VENDOR_MAP = {
1213
'GenuineIntel': 'intel',
@@ -33,7 +34,23 @@ def det_host_triple():
3334
Determine host triple: (<cpu_family>, <cpu_vendor>, <cpu_name>).
3435
<cpu_vendor> may be None if there's no match in VENDOR_MAP.
3536
"""
36-
host_cpu = archspec.cpu.host()
37+
# we can't directly use archspec.cpu.host(), because we may get back a virtual microarchitecture like x86_64_v3...
38+
def sorting_fn(item):
39+
"""Helper function to sort compatible microarchitectures."""
40+
return len(item.ancestors), len(item.features)
41+
42+
raw_cpu_info = raw_info_dictionary()
43+
compat_targets = compatible_microarchitectures(raw_cpu_info)
44+
45+
# filter out generic targets
46+
non_generic_compat_targets = [t for t in compat_targets if t.vendor != "generic"]
47+
48+
# Filter the candidates to be descendant of the best generic candidate
49+
best_generic = max([t for t in compat_targets if t.vendor == "generic"], key=sorting_fn)
50+
best_compat_targets = [t for t in non_generic_compat_targets if t > best_generic]
51+
52+
host_cpu = max(best_compat_targets, key=sorting_fn)
53+
3754
host_vendor = VENDOR_MAP.get(host_cpu.vendor)
3855
host_cpu_family = host_cpu.family.name
3956
host_cpu_name = host_cpu.name

0 commit comments

Comments
 (0)