File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 7
7
import platform
8
8
import sys
9
9
import archspec .cpu
10
+ from archspec .cpu .detect import compatible_microarchitectures , raw_info_dictionary
10
11
11
12
VENDOR_MAP = {
12
13
'GenuineIntel' : 'intel' ,
@@ -33,7 +34,23 @@ def det_host_triple():
33
34
Determine host triple: (<cpu_family>, <cpu_vendor>, <cpu_name>).
34
35
<cpu_vendor> may be None if there's no match in VENDOR_MAP.
35
36
"""
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
+
37
54
host_vendor = VENDOR_MAP .get (host_cpu .vendor )
38
55
host_cpu_family = host_cpu .family .name
39
56
host_cpu_name = host_cpu .name
You can’t perform that action at this time.
0 commit comments