Skip to content

Commit af41c47

Browse files
authored
Merge pull request #2006 from lexming/mesa
take into account user defined gallium_drivers and swr_arches in Mesa easyblock
2 parents 5701c03 + 5d1bbc6 commit af41c47

File tree

1 file changed

+55
-16
lines changed

1 file changed

+55
-16
lines changed

easybuild/easyblocks/m/mesa.py

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
2828
@author: Andrew Edmondson (University of Birmingham)
2929
@author: Kenneth Hoste (HPC-UGent)
30+
@author: Alex Domingo (Vrije Universiteit Brussel)
31+
@author: Alexander Grund (TU Dresden)
3032
"""
3133
import os
3234
from distutils.version import LooseVersion
@@ -40,42 +42,79 @@ class EB_Mesa(MesonNinja):
4042
"""Custom easyblock for building and installing Mesa."""
4143

4244
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."""
4446

4547
super(EB_Mesa, self).__init__(*args, **kwargs)
4648

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+
4768
self.swr_arches = []
4869

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
5276
feat_to_swrarch = {
5377
'avx': 'avx',
5478
'avx1.0': 'avx', # on macOS, AVX is indicated with 'avx1.0' rather than 'avx'
5579
'avx2': 'avx2',
5680
'avx512f': 'skx', # AVX-512 Foundation - introduced in Skylake
5781
'avx512er': 'knl', # AVX-512 Exponential and Reciprocal Instructions implemented in Knights Landing
5882
}
59-
# determine list of values to pass to swr-arches configuration option
83+
# Determine list of values to pass to swr-arches configuration option
6084
cpu_features = get_cpu_features()
6185
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
62109

63110
def configure_step(self):
64111
"""
65112
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, ...)
67114
"""
68115

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)
79118

80119
return super(EB_Mesa, self).configure_step()
81120

0 commit comments

Comments
 (0)