Skip to content

Commit

Permalink
Handle multiple VENVs + instrumenting
Browse files Browse the repository at this point in the history
  • Loading branch information
JDBetteridge committed Aug 27, 2024
1 parent 3eef196 commit ec62654
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
15 changes: 7 additions & 8 deletions pyop2/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,12 @@ class DEFAULT_CACHE(dict):
pass


# Examples of how to instrument and use different default caches:
# ~ DEFAULT_CACHE = instrument(DEFAULT_CACHE)
# ~ DEFAULT_CACHE = instrument(cachetools.LRUCache)
# ~ DEFAULT_CACHE = partial(DEFAULT_CACHE, maxsize=100)
# Example of how to instrument and use different default caches:
EXOTIC_CACHE = partial(instrument(cachetools.LRUCache), maxsize=100)
# ~ DictLikeDiskAccess = instrument(DictLikeDiskAccess)
# Turn on cache measurements if printing cache info is enabled
if configuration["print_cache_info"] or _running_on_ci:
DEFAULT_CACHE = instrument(DEFAULT_CACHE)
DictLikeDiskAccess = instrument(DictLikeDiskAccess)


# JBTODO: This functionality should only be enabled with a PYOP2_SPMD_STRICT
Expand Down Expand Up @@ -509,7 +509,6 @@ def wrapper(*args, **kwargs):
return decorator


# JBTODO: This needs some more thought
def clear_memory_cache(comm):
with temp_internal_comm(comm) as icomm:
if icomm.Get_attr(comm_cache_keyval) is not None:
Expand Down Expand Up @@ -540,6 +539,6 @@ def decorator(func):
# * Refactor compilation.py to use @mem_and_disk_cached, where get_so is just uses DictLikeDiskAccess with an overloaded self.write() method ✓
# * Systematic investigation into cache sizes/types for Firedrake
# - Is a mem cache needed for DLLs? ~~No~~ Yes!!
# - Is LRUCache better than a simple dict? (memory profile test suite)
# - What is the optimal maxsize?
# - Is LRUCache better than a simple dict? (memory profile test suite) No
# - What is the optimal maxsize?
# * Add some docstrings and maybe some exposition!
11 changes: 6 additions & 5 deletions pyop2/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ def _check_hashes(x, y, datatype):

_check_op = mpi.MPI.Op.Create(_check_hashes, commute=True)
_compiler = None
# Directory must be unique per user for shared machines
MEM_TMP_DIR = Path(gettempdir()).joinpath(f"pyop2-tempcache-uid{os.getuid()}")
# Directory must be unique per VENV for multiple installs
# _and_ per user for shared machines
_EXE_HASH = md5(sys.executable.encode()).hexdigest()[-6:]
MEM_TMP_DIR = Path(gettempdir()).joinpath(f"pyop2-tempcache-uid{os.getuid()}").joinpath(_EXE_HASH)


def set_default_compiler(compiler):
Expand Down Expand Up @@ -678,9 +680,8 @@ def _add_profiling_events(dll, events):
ctypes.c_int.in_dll(dll, 'ID_'+e).value = PETSc.Log.Event(e).id


# JBTODO: Move to caching??
def clear_cache(prompt=False):
"""Clear the PyOP2 compiler cache.
def clear_compiler_disk_cache(prompt=False):
"""Clear the PyOP2 compiler disk cache.
:arg prompt: if ``True`` prompt before removing any files
"""
Expand Down
4 changes: 2 additions & 2 deletions scripts/pyop2-clean
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
from pyop2.compilation import clear_cache
from pyop2.compilation import clear_compiler_disk_cache


if __name__ == '__main__':
clear_cache(prompt=True)
clear_compiler_disk_cache(prompt=True)

0 comments on commit ec62654

Please sign in to comment.