Skip to content

Commit d234df6

Browse files
authored
Solver: Cache Concretization Results (#48198)
Concretizer caching for reusing solver results
1 parent 4a5922a commit d234df6

File tree

12 files changed

+708
-154
lines changed

12 files changed

+708
-154
lines changed

lib/spack/docs/config_yaml.rst

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ are stored in ``$spack/var/spack/cache``. These are stored indefinitely
125125
by default. Can be purged with :ref:`spack clean --downloads
126126
<cmd-spack-clean>`.
127127

128+
.. _Misc Cache:
129+
128130
--------------------
129131
``misc_cache``
130132
--------------------
@@ -334,3 +336,52 @@ create a new alias called ``inst`` that will always call ``install -v``:
334336
335337
aliases:
336338
inst: install -v
339+
340+
-------------------------------
341+
``concretization_cache:enable``
342+
-------------------------------
343+
344+
When set to ``true``, Spack will utilize a cache of solver outputs from
345+
successful concretization runs. When enabled, Spack will check the concretization
346+
cache prior to running the solver. If a previous request to solve a given
347+
problem is present in the cache, Spack will load the concrete specs and other
348+
solver data from the cache rather than running the solver. Specs not previously
349+
concretized will be added to the cache on a successful solve. The cache additionally
350+
holds solver statistics, so commands like ``spack solve`` will still return information
351+
about the run that produced a given solver result.
352+
353+
This cache is a subcache of the :ref:`Misc Cache` and as such will be cleaned when the Misc
354+
Cache is cleaned.
355+
356+
When ``false`` or ommitted, all concretization requests will be performed from scatch
357+
358+
----------------------------
359+
``concretization_cache:url``
360+
----------------------------
361+
362+
Path to the location where Spack will root the concretization cache. Currently this only supports
363+
paths on the local filesystem.
364+
365+
Default location is under the :ref:`Misc Cache` at: ``$misc_cache/concretization``
366+
367+
------------------------------------
368+
``concretization_cache:entry_limit``
369+
------------------------------------
370+
371+
Sets a limit on the number of concretization results that Spack will cache. The limit is evaluated
372+
after each concretization run; if Spack has stored more results than the limit allows, the
373+
oldest concretization results are pruned until 10% of the limit has been removed.
374+
375+
Setting this value to 0 disables the automatic pruning. It is expected users will be
376+
responsible for maintaining this cache.
377+
378+
-----------------------------------
379+
``concretization_cache:size_limit``
380+
-----------------------------------
381+
382+
Sets a limit on the size of the concretization cache in bytes. The limit is evaluated
383+
after each concretization run; if Spack has stored more results than the limit allows, the
384+
oldest concretization results are pruned until 10% of the limit has been removed.
385+
386+
Setting this value to 0 disables the automatic pruning. It is expected users will be
387+
responsible for maintaining this cache.

lib/spack/llnl/util/filesystem.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import fnmatch
88
import glob
99
import hashlib
10+
import io
1011
import itertools
1112
import numbers
1213
import os
@@ -20,6 +21,7 @@
2021
from contextlib import contextmanager
2122
from itertools import accumulate
2223
from typing import (
24+
IO,
2325
Callable,
2426
Deque,
2527
Dict,
@@ -2881,6 +2883,20 @@ def keep_modification_time(*filenames):
28812883
os.utime(f, (os.path.getatime(f), mtime))
28822884

28832885

2886+
@contextmanager
2887+
def temporary_file_position(stream):
2888+
orig_pos = stream.tell()
2889+
yield
2890+
stream.seek(orig_pos)
2891+
2892+
2893+
@contextmanager
2894+
def current_file_position(stream: IO[str], loc: int, relative_to=io.SEEK_CUR):
2895+
with temporary_file_position(stream):
2896+
stream.seek(loc, relative_to)
2897+
yield
2898+
2899+
28842900
@contextmanager
28852901
def temporary_dir(
28862902
suffix: Optional[str] = None, prefix: Optional[str] = None, dir: Optional[str] = None

lib/spack/spack/paths.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ def _get_user_cache_path():
108108
#: transient caches for Spack data (virtual cache, patch sha256 lookup, etc.)
109109
default_misc_cache_path = os.path.join(user_cache_path, "cache")
110110

111+
#: concretization cache for Spack concretizations
112+
default_conc_cache_path = os.path.join(default_misc_cache_path, "concretization")
111113

112114
# Below paths pull configuration from the host environment.
113115
#

lib/spack/spack/schema/config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@
5858
{"type": "string"}, # deprecated
5959
]
6060
},
61+
"concretization_cache": {
62+
"type": "object",
63+
"properties": {
64+
"enable": {"type": "boolean"},
65+
"url": {"type": "string"},
66+
"entry_limit": {"type": "integer", "minimum": 0},
67+
"size_limit": {"type": "integer", "minimum": 0},
68+
},
69+
},
6170
"install_hash_length": {"type": "integer", "minimum": 1},
6271
"install_path_scheme": {"type": "string"}, # deprecated
6372
"build_stage": {

0 commit comments

Comments
 (0)