Skip to content

Commit 0190890

Browse files
committed
ASP-based solver: allow configuring target selection
This commit adds a new "concretizer:targets" configuration section, and two options under it. - "concretizer:targets:granularity" allows switching from considering only generic targets to consider all possible microarchitectures. - "concretizer:targets:host_compatible" instead controls whether we can concretize for microarchitectures that are incompatible with the current host.
1 parent 88b1bf7 commit 0190890

File tree

3 files changed

+48
-12
lines changed

3 files changed

+48
-12
lines changed

etc/spack/defaults/concretizer.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,16 @@ concretizer:
1515
# as possible, rather than building. If `false`, we'll always give you a fresh
1616
# concretization.
1717
reuse: false
18+
# Options that tune which targets are considered for concretization. The
19+
# concretization process is very sensitive to the number targets, and the time
20+
# needed to reach a solution increases noticeably with the number of targets
21+
# considered.
22+
targets:
23+
# Determine whether we want to target specific or generic microarchitectures.
24+
# An example of the first kind might be for instance "skylake" or "bulldozer",
25+
# while generic microarchitectures are for instance "aarch64" or "x86_64_v4".
26+
granularity: microarchitectures
27+
# If "false" allow targets that are incompatible with the current host (for
28+
# instance concretize with target "icelake" while running on "haswell").
29+
# If "true" only allow targets that are compatible with the host.
30+
host_compatible: false

lib/spack/spack/schema/concretizer.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
'additionalProperties': False,
1616
'properties': {
1717
'reuse': {'type': 'boolean'},
18+
'targets': {
19+
'type': 'object',
20+
'properties': {
21+
'host_compatible': {'type': 'boolean'},
22+
'granularity': {
23+
'type': 'string',
24+
'enum': ['generic', 'microarchitectures']
25+
}
26+
}
27+
},
1828
}
1929
}
2030
}

lib/spack/spack/solver/asp.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,13 +1404,26 @@ def target_defaults(self, specs):
14041404

14051405
self.gen.h2('Target compatibility')
14061406

1407-
compatible_targets = [uarch] + uarch.ancestors
1408-
additional_targets_in_family = sorted([
1409-
t for t in archspec.cpu.TARGETS.values()
1410-
if (t.family.name == uarch.family.name and
1411-
t not in compatible_targets)
1412-
], key=lambda x: len(x.ancestors), reverse=True)
1413-
compatible_targets += additional_targets_in_family
1407+
# Construct the list of targets which are compatible with the host
1408+
candidate_targets = [uarch] + uarch.ancestors
1409+
1410+
# Get configuration options
1411+
granularity = spack.config.get('concretizer:targets:granularity')
1412+
host_compatible = spack.config.get('concretizer:targets:host_compatible')
1413+
1414+
# Add targets which are not compatible with the current host
1415+
if not host_compatible:
1416+
additional_targets_in_family = sorted([
1417+
t for t in archspec.cpu.TARGETS.values()
1418+
if (t.family.name == uarch.family.name and
1419+
t not in candidate_targets)
1420+
], key=lambda x: len(x.ancestors), reverse=True)
1421+
candidate_targets += additional_targets_in_family
1422+
1423+
# Check if we want only generic architecture
1424+
if granularity == 'generic':
1425+
candidate_targets = [t for t in candidate_targets if t.vendor == 'generic']
1426+
14141427
compilers = self.possible_compilers
14151428

14161429
# this loop can be used to limit the number of targets
@@ -1420,7 +1433,7 @@ def target_defaults(self, specs):
14201433
best_targets = set([uarch.family.name])
14211434
for compiler in sorted(compilers):
14221435
supported = self._supported_targets(
1423-
compiler.name, compiler.version, compatible_targets
1436+
compiler.name, compiler.version, candidate_targets
14241437
)
14251438

14261439
# If we can't find supported targets it may be due to custom
@@ -1433,7 +1446,7 @@ def target_defaults(self, specs):
14331446
supported = self._supported_targets(
14341447
compiler.name,
14351448
compiler_obj.real_version,
1436-
compatible_targets
1449+
candidate_targets
14371450
)
14381451

14391452
if not supported:
@@ -1459,11 +1472,11 @@ def target_defaults(self, specs):
14591472
self.target_ranges(spec, None)
14601473
continue
14611474

1462-
if target not in compatible_targets:
1463-
compatible_targets.append(target)
1475+
if target not in candidate_targets:
1476+
candidate_targets.append(target)
14641477

14651478
i = 0
1466-
for target in compatible_targets:
1479+
for target in candidate_targets:
14671480
self.gen.fact(fn.target(target.name))
14681481
self.gen.fact(fn.target_family(target.name, target.family.name))
14691482
for parent in sorted(target.parents):

0 commit comments

Comments
 (0)