Skip to content

Commit

Permalink
Support aborting on cache miss (#828)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasdiener authored Feb 12, 2025
1 parent 0682244 commit a46bd53
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,15 @@ jobs:
- uses: actions/checkout@v4
- name: "Main Script"
run: |
# This test makes sure that loopy can run with kernels loaded from disk cache.
curl -L -O https://tiker.net/ci-support-v0
. ./ci-support-v0
build_py_project_in_conda_env
( test_py_project )
# See https://github.com/inducer/loopy/pull/828 why this is disabled.
# export LOOPY_ABORT_ON_CACHE_MISS=1
( test_py_project )
examples:
Expand Down
7 changes: 7 additions & 0 deletions doc/ref_other.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ Controlling caching
is suppressed.


.. envvar:: LOOPY_ABORT_ON_CACHE_MISS

If set to a string that :func:`pytools.strtobool` evaluates as ``True``,
loopy will raise an exception if a cache miss occurs. This can be useful
for debugging cache-related issues. For example, it can be used to automatically test whether caching is successful for a particular code, by setting this variable to ``True`` and re-running the code.


.. autofunction:: set_caching_enabled

.. autoclass:: CacheMode
Expand Down
3 changes: 3 additions & 0 deletions loopy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,9 @@ def register_symbol_manglers(kernel, manglers):
not strtobool(os.environ.get("CG_NO_CACHE", "false")))


ABORT_ON_CACHE_MISS = strtobool(os.environ.get("LOOPY_ABORT_ON_CACHE_MISS", "false"))


def set_caching_enabled(flag):
"""Set whether :mod:`loopy` is allowed to use disk caching for its various
code generation stages.
Expand Down
5 changes: 4 additions & 1 deletion loopy/codegen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ def all_code(self):

def generate_code_v2(t_unit: TranslationUnit) -> CodeGenerationResult:
# {{{ cache retrieval
from loopy import CACHING_ENABLED

from loopy import ABORT_ON_CACHE_MISS, CACHING_ENABLED
from loopy.kernel import LoopKernel
from loopy.translation_unit import make_program

Expand All @@ -563,6 +564,8 @@ def generate_code_v2(t_unit: TranslationUnit) -> CodeGenerationResult:
except KeyError:
logger.debug(f"TranslationUnit with entrypoints {t_unit.entrypoints}:"
" code generation cache miss")
if ABORT_ON_CACHE_MISS:
raise

# }}}

Expand Down
7 changes: 5 additions & 2 deletions test/test_c_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ def __get_kernel(order="C"):

def test_c_target_strides_nonsquare():
from loopy.target.c import ExecutableCTarget
rng = np.random.default_rng(seed=42)

def __get_kernel(order="C"):
indices = ["i", "j", "k"]
sizes = tuple(np.random.randint(1, 11, size=len(indices)))
sizes = tuple(rng.integers(1, 11, size=len(indices)))
# create domain strings
domain_template = "{{ [{iname}]: 0 <= {iname} < {size} }}"
domains = []
Expand Down Expand Up @@ -141,9 +142,11 @@ def __get_kernel(order="C"):
def test_c_optimizations():
from loopy.target.c import ExecutableCTarget

rng = np.random.default_rng(seed=42)

def __get_kernel(order="C"):
indices = ["i", "j", "k"]
sizes = tuple(np.random.randint(1, 11, size=len(indices)))
sizes = tuple(rng.integers(1, 11, size=len(indices)))
# create domain strings
domain_template = "{{ [{iname}]: 0 <= {iname} < {size} }}"
domains = []
Expand Down

0 comments on commit a46bd53

Please sign in to comment.