27
27
28
28
@author: Andrew Edmondson (University of Birmingham)
29
29
@author: Kenneth Hoste (HPC-UGent)
30
+ @author: Alex Domingo (Vrije Universiteit Brussel)
31
+ @author: Alexander Grund (TU Dresden)
30
32
"""
31
33
import os
32
34
from distutils .version import LooseVersion
@@ -40,42 +42,79 @@ class EB_Mesa(MesonNinja):
40
42
"""Custom easyblock for building and installing Mesa."""
41
43
42
44
def __init__ (self , * args , ** kwargs ):
43
- """Constructor for custom Mesa easyblock: figure out which vales to pass to swr-arches configuration option."""
45
+ """Constructor for custom Mesa easyblock: figure out which values to pass to swr-arches configuration option."""
44
46
45
47
super (EB_Mesa , self ).__init__ (* args , ** kwargs )
46
48
49
+ self .gallium_configopts = []
50
+
51
+ # Check user-defined Gallium drivers
52
+ gallium_drivers = self .get_configopt_value ('gallium-drivers' )
53
+
54
+ if not gallium_drivers :
55
+ # Add appropriate Gallium drivers for current architecture
56
+ arch = get_cpu_architecture ()
57
+ arch_gallium_drivers = {
58
+ 'x86_64' : ['swrast' , 'swr' ],
59
+ 'POWER' : ['swrast' ],
60
+ }
61
+ if arch in arch_gallium_drivers :
62
+ gallium_drivers = arch_gallium_drivers [arch ]
63
+ # Add configopt for additional Gallium drivers
64
+ self .gallium_configopts .append ('-Dgallium-drivers=' + ',' .join (gallium_drivers ))
65
+
66
+ self .log .debug ('Gallium driver(s) included in the installation: %s' % ', ' .join (gallium_drivers ))
67
+
47
68
self .swr_arches = []
48
69
49
- if 'swr-arches' not in self .cfg ['configopts' ]:
50
- # set cpu features of SWR for current architecture (only on x86_64)
51
- if get_cpu_architecture () == X86_64 :
70
+ if 'swr' in gallium_drivers :
71
+ # Check user-defined SWR arches
72
+ self .swr_arches = self .get_configopt_value ('swr-arches' )
73
+
74
+ if not self .swr_arches :
75
+ # Set cpu features of SWR for current micro-architecture
52
76
feat_to_swrarch = {
53
77
'avx' : 'avx' ,
54
78
'avx1.0' : 'avx' , # on macOS, AVX is indicated with 'avx1.0' rather than 'avx'
55
79
'avx2' : 'avx2' ,
56
80
'avx512f' : 'skx' , # AVX-512 Foundation - introduced in Skylake
57
81
'avx512er' : 'knl' , # AVX-512 Exponential and Reciprocal Instructions implemented in Knights Landing
58
82
}
59
- # determine list of values to pass to swr-arches configuration option
83
+ # Determine list of values to pass to swr-arches configuration option
60
84
cpu_features = get_cpu_features ()
61
85
self .swr_arches = sorted ([swrarch for feat , swrarch in feat_to_swrarch .items () if feat in cpu_features ])
86
+ # Add configopt for additional SWR arches
87
+ self .gallium_configopts .append ('-Dswr-arches=' + ',' .join (self .swr_arches ))
88
+
89
+ self .log .debug ('SWR Gallium driver will support: %s' % ', ' .join (self .swr_arches ))
90
+
91
+ def get_configopt_value (self , configopt_name ):
92
+ """
93
+ Return list of values for the given configuration option in configopts
94
+ """
95
+ configopt_args = [opt for opt in self .cfg ['configopts' ].split () if opt .startswith ('-D%s=' % configopt_name )]
96
+
97
+ if configopt_args :
98
+ if len (configopt_args ) > 1 :
99
+ self .log .warning ("Found multiple instances of %s in configopts, using last one: %s" ,
100
+ configopt_name , configopt_args [- 1 ])
101
+ # Get value of last option added
102
+ configopt_value = configopt_args [- 1 ].split ('=' )[- 1 ]
103
+ # Remove quotes and extract individual values
104
+ configopt_value = configopt_value .strip ('"\' ' ).split (',' )
105
+ else :
106
+ configopt_value = None
107
+
108
+ return configopt_value
62
109
63
110
def configure_step (self ):
64
111
"""
65
112
Customise the configure options based on the processor architecture of the host
66
- (x86_64 or not, CPU features, ...)
113
+ (Gallium drivers installed, SWR CPU features, ...)
67
114
"""
68
115
69
- arch = get_cpu_architecture ()
70
- if 'gallium-drivers' not in self .cfg ['configopts' ]:
71
- # Install appropriate Gallium drivers for current architecture
72
- if arch == X86_64 :
73
- self .cfg .update ('configopts' , "-Dgallium-drivers='swrast,swr'" )
74
- elif arch == POWER :
75
- self .cfg .update ('configopts' , "-Dgallium-drivers='swrast'" )
76
-
77
- if self .swr_arches :
78
- self .cfg .update ('configopts' , '-Dswr-arches=' + ',' .join (self .swr_arches ))
116
+ if self .gallium_configopts :
117
+ self .cfg .update ('configopts' , self .gallium_configopts )
79
118
80
119
return super (EB_Mesa , self ).configure_step ()
81
120
0 commit comments