forked from EESSI/software-layer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
eessi_software_subdir.py
executable file
·53 lines (41 loc) · 1.9 KB
/
eessi_software_subdir.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
#
# Determine EESSI software subdirectory to use for current build host, using archspec
#
import os
import argparse
from archspec.cpu.detect import compatible_microarchitectures, raw_info_dictionary
software_subdir = os.getenv('EESSI_SOFTWARE_SUBDIR_OVERRIDE')
if software_subdir is None:
parser = argparse.ArgumentParser(description='Determine EESSI software subdirectory to use for current build host.')
parser.add_argument('--generic', dest='generic', action='store_true',
default=False, help='Use generic for CPU name.')
args = parser.parse_args()
# we can't directly use archspec.cpu.host(), because we may get back a virtual microarchitecture like x86_64_v3...
def sorting_fn(item):
"""Helper function to sort compatible microarchitectures."""
return len(item.ancestors), len(item.features)
raw_cpu_info = raw_info_dictionary()
compat_targets = compatible_microarchitectures(raw_cpu_info)
# filter out generic targets
non_generic_compat_targets = [t for t in compat_targets if t.vendor != "generic"]
# Filter the candidates to be descendant of the best generic candidate
best_generic = max([t for t in compat_targets if t.vendor == "generic"], key=sorting_fn)
best_compat_targets = [t for t in non_generic_compat_targets if t > best_generic]
if best_compat_targets:
host_cpu = max(best_compat_targets, key=sorting_fn)
else:
host_cpu = max(non_generic_compat_targets, key=sorting_fn)
vendors = {
'GenuineIntel': 'intel',
'AuthenticAMD': 'amd',
}
vendor = vendors.get(host_cpu.vendor)
if args.generic:
parts = (host_cpu.family.name, 'generic')
elif vendor:
parts = (host_cpu.family.name, vendor, host_cpu.name)
else:
parts = (host_cpu.family.name, host_cpu.name)
software_subdir = os.path.join(*parts)
print(software_subdir)