Skip to content

Commit 2ffaa6a

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

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

eessi_software_subdir.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
import os
66
import argparse
7-
import archspec.cpu
7+
from archspec.cpu.detect import compatible_microarchitectures, raw_info_dictionary
88

99
software_subdir = os.getenv('EESSI_SOFTWARE_SUBDIR_OVERRIDE')
1010
if software_subdir is None:
@@ -14,7 +14,26 @@
1414
default=False, help='Use generic for CPU name.')
1515
args = parser.parse_args()
1616

17-
host_cpu = archspec.cpu.host()
17+
# we can't directly use archspec.cpu.host(), because we may get back a virtual microarchitecture like x86_64_v3...
18+
def sorting_fn(item):
19+
"""Helper function to sort compatible microarchitectures."""
20+
return len(item.ancestors), len(item.features)
21+
22+
raw_cpu_info = raw_info_dictionary()
23+
compat_targets = compatible_microarchitectures(raw_cpu_info)
24+
25+
# filter out generic targets
26+
non_generic_compat_targets = [t for t in compat_targets if t.vendor != "generic"]
27+
28+
# Filter the candidates to be descendant of the best generic candidate
29+
best_generic = max([t for t in compat_targets if t.vendor == "generic"], key=sorting_fn)
30+
best_compat_targets = [t for t in non_generic_compat_targets if t > best_generic]
31+
32+
if best_compat_targets:
33+
host_cpu = max(best_compat_targets, key=sorting_fn)
34+
else:
35+
host_cpu = max(non_generic_compat_targets, key=sorting_fn)
36+
1837
vendors = {
1938
'GenuineIntel': 'intel',
2039
'AuthenticAMD': 'amd',

init/eessi_software_subdir_for_host.py

+21-1
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,26 @@ 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+
if best_compat_targets:
53+
host_cpu = max(best_compat_targets, key=sorting_fn)
54+
else:
55+
host_cpu = max(non_generic_compat_targets, key=sorting_fn)
56+
3757
host_vendor = VENDOR_MAP.get(host_cpu.vendor)
3858
host_cpu_family = host_cpu.family.name
3959
host_cpu_name = host_cpu.name

0 commit comments

Comments
 (0)