From 6e03ae805cfa2bf68e7fcaac2f61f33724a015f6 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Mon, 25 Sep 2017 11:17:17 -0500 Subject: [PATCH 1/3] Use WriteOncePersistentDict instead of PersistentDict. --- loopy/codegen/__init__.py | 12 ++++++++---- loopy/execution.py | 9 ++++++--- loopy/preprocess.py | 10 +++++++--- loopy/schedule/__init__.py | 10 +++++++--- loopy/transform/buffer.py | 10 +++++++--- setup.py | 2 +- 6 files changed, 36 insertions(+), 17 deletions(-) diff --git a/loopy/codegen/__init__.py b/loopy/codegen/__init__.py index 07bcdc7c6..42f383f3f 100644 --- a/loopy/codegen/__init__.py +++ b/loopy/codegen/__init__.py @@ -28,7 +28,7 @@ from loopy.diagnostic import LoopyError, warn from pytools import ImmutableRecord import islpy as isl -from pytools.persistent_dict import PersistentDict +from pytools.persistent_dict import WriteOncePersistentDict, ReadOnlyEntryError from loopy.tools import LoopyKeyBuilder from loopy.version import DATA_MODEL_VERSION @@ -357,8 +357,9 @@ class CodeGenerationState(object): # }}} -code_gen_cache = PersistentDict("loopy-code-gen-cache-v3-"+DATA_MODEL_VERSION, - key_builder=LoopyKeyBuilder()) +code_gen_cache = WriteOncePersistentDict( + "loopy-code-gen-cache-v3-"+DATA_MODEL_VERSION, + key_builder=LoopyKeyBuilder()) class PreambleInfo(ImmutableRecord): @@ -515,7 +516,10 @@ def generate_code_v2(kernel): logger.info("%s: generate code: done" % kernel.name) if CACHING_ENABLED: - code_gen_cache[input_kernel] = codegen_result + try: + code_gen_cache[input_kernel] = codegen_result + except ReadOnlyEntryError: + pass return codegen_result diff --git a/loopy/execution.py b/loopy/execution.py index 07e28f06d..f510a4389 100644 --- a/loopy/execution.py +++ b/loopy/execution.py @@ -31,7 +31,7 @@ from loopy.diagnostic import LoopyError import logging logger = logging.getLogger(__name__) -from pytools.persistent_dict import PersistentDict +from pytools.persistent_dict import WriteOncePersistentDict, ReadOnlyEntryError from loopy.tools import LoopyKeyBuilder from loopy.version import DATA_MODEL_VERSION @@ -120,7 +120,7 @@ class SeparateArrayPackingController(object): # {{{ KernelExecutorBase -typed_and_scheduled_cache = PersistentDict( +typed_and_scheduled_cache = WriteOncePersistentDict( "loopy-typed-and-scheduled-cache-v1-"+DATA_MODEL_VERSION, key_builder=LoopyKeyBuilder()) @@ -204,7 +204,10 @@ class KernelExecutorBase(object): kernel = self.get_typed_and_scheduled_kernel_uncached(arg_to_dtype_set) if CACHING_ENABLED: - typed_and_scheduled_cache[cache_key] = kernel + try: + typed_and_scheduled_cache[cache_key] = kernel + except ReadOnlyEntryError: + pass return kernel diff --git a/loopy/preprocess.py b/loopy/preprocess.py index 541b44f58..40a782a44 100644 --- a/loopy/preprocess.py +++ b/loopy/preprocess.py @@ -30,7 +30,7 @@ from loopy.diagnostic import ( import islpy as isl -from pytools.persistent_dict import PersistentDict +from pytools.persistent_dict import WriteOncePersistentDict, ReadOnlyEntryError from loopy.tools import LoopyKeyBuilder from loopy.version import DATA_MODEL_VERSION @@ -2020,7 +2020,8 @@ def limit_boostability(kernel): # }}} -preprocess_cache = PersistentDict("loopy-preprocess-cache-v2-"+DATA_MODEL_VERSION, +preprocess_cache = WriteOncePersistentDict( + "loopy-preprocess-cache-v2-"+DATA_MODEL_VERSION, key_builder=LoopyKeyBuilder()) @@ -2126,7 +2127,10 @@ def preprocess_kernel(kernel, device=None): # }}} if CACHING_ENABLED: - preprocess_cache[input_kernel] = kernel + try: + preprocess_cache[input_kernel] = kernel + except ReadOnlyEntryError: + pass return kernel diff --git a/loopy/schedule/__init__.py b/loopy/schedule/__init__.py index d28e7b1b3..221fcf3e0 100644 --- a/loopy/schedule/__init__.py +++ b/loopy/schedule/__init__.py @@ -29,7 +29,7 @@ import sys import islpy as isl from loopy.diagnostic import warn_with_kernel, LoopyError # noqa -from pytools.persistent_dict import PersistentDict +from pytools.persistent_dict import WriteOncePersistentDict, ReadOnlyEntryError from loopy.tools import LoopyKeyBuilder from loopy.version import DATA_MODEL_VERSION @@ -1940,7 +1940,8 @@ def generate_loop_schedules_inner(kernel, debug_args={}): # }}} -schedule_cache = PersistentDict("loopy-schedule-cache-v4-"+DATA_MODEL_VERSION, +schedule_cache = WriteOncePersistentDict( + "loopy-schedule-cache-v4-"+DATA_MODEL_VERSION, key_builder=LoopyKeyBuilder()) @@ -1971,7 +1972,10 @@ def get_one_scheduled_kernel(kernel): kernel.name, time()-start_time)) if CACHING_ENABLED and not from_cache: - schedule_cache[sched_cache_key] = result + try: + schedule_cache[sched_cache_key] = result + except ReadOnlyEntryError: + pass return result diff --git a/loopy/transform/buffer.py b/loopy/transform/buffer.py index 92cff7a50..a50844038 100644 --- a/loopy/transform/buffer.py +++ b/loopy/transform/buffer.py @@ -29,7 +29,7 @@ from loopy.symbolic import (get_dependencies, RuleAwareIdentityMapper, SubstitutionRuleMappingContext, SubstitutionMapper) from pymbolic.mapper.substitutor import make_subst_func -from pytools.persistent_dict import PersistentDict +from pytools.persistent_dict import WriteOncePersistentDict, ReadOnlyEntryError from loopy.tools import LoopyKeyBuilder, PymbolicExpressionHashWrapper from loopy.version import DATA_MODEL_VERSION from loopy.diagnostic import LoopyError @@ -124,7 +124,8 @@ class ArrayAccessReplacer(RuleAwareIdentityMapper): # }}} -buffer_array_cache = PersistentDict("loopy-buffer-array-cache-"+DATA_MODEL_VERSION, +buffer_array_cache = WriteOncePersistentDict( + "loopy-buffer-array-cache-"+DATA_MODEL_VERSION, key_builder=LoopyKeyBuilder()) @@ -531,7 +532,10 @@ def buffer_array(kernel, var_name, buffer_inames, init_expression=None, if CACHING_ENABLED: from loopy.preprocess import prepare_for_caching - buffer_array_cache[cache_key] = prepare_for_caching(kernel) + try: + buffer_array_cache[cache_key] = prepare_for_caching(kernel) + except ReadOnlyEntryError: + pass return kernel diff --git a/setup.py b/setup.py index 67d943af3..e1726772d 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,7 @@ setup(name="loo.py", ], install_requires=[ - "pytools>=2017.3", + "pytools>=2017.5", "pymbolic>=2016.2", "genpy>=2016.1.2", "cgen>=2016.1", -- GitLab From b3d0d7c65e05ad374f35b7a9c78fdd8e29541313 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Mon, 25 Sep 2017 22:02:39 -0500 Subject: [PATCH 2/3] Use store_if_not_present(). --- loopy/codegen/__init__.py | 7 ++----- loopy/execution.py | 7 ++----- loopy/preprocess.py | 7 ++----- loopy/schedule/__init__.py | 7 ++----- loopy/transform/buffer.py | 7 ++----- setup.py | 2 +- 6 files changed, 11 insertions(+), 26 deletions(-) diff --git a/loopy/codegen/__init__.py b/loopy/codegen/__init__.py index 42f383f3f..79adb922d 100644 --- a/loopy/codegen/__init__.py +++ b/loopy/codegen/__init__.py @@ -28,7 +28,7 @@ from loopy.diagnostic import LoopyError, warn from pytools import ImmutableRecord import islpy as isl -from pytools.persistent_dict import WriteOncePersistentDict, ReadOnlyEntryError +from pytools.persistent_dict import WriteOncePersistentDict from loopy.tools import LoopyKeyBuilder from loopy.version import DATA_MODEL_VERSION @@ -516,10 +516,7 @@ def generate_code_v2(kernel): logger.info("%s: generate code: done" % kernel.name) if CACHING_ENABLED: - try: - code_gen_cache[input_kernel] = codegen_result - except ReadOnlyEntryError: - pass + code_gen_cache.store_if_not_present(input_kernel, codegen_result) return codegen_result diff --git a/loopy/execution.py b/loopy/execution.py index f510a4389..a1228f8f3 100644 --- a/loopy/execution.py +++ b/loopy/execution.py @@ -31,7 +31,7 @@ from loopy.diagnostic import LoopyError import logging logger = logging.getLogger(__name__) -from pytools.persistent_dict import WriteOncePersistentDict, ReadOnlyEntryError +from pytools.persistent_dict import WriteOncePersistentDict from loopy.tools import LoopyKeyBuilder from loopy.version import DATA_MODEL_VERSION @@ -204,10 +204,7 @@ class KernelExecutorBase(object): kernel = self.get_typed_and_scheduled_kernel_uncached(arg_to_dtype_set) if CACHING_ENABLED: - try: - typed_and_scheduled_cache[cache_key] = kernel - except ReadOnlyEntryError: - pass + typed_and_scheduled_cache.store_if_not_present(cache_key, kernel) return kernel diff --git a/loopy/preprocess.py b/loopy/preprocess.py index 40a782a44..29d8888ae 100644 --- a/loopy/preprocess.py +++ b/loopy/preprocess.py @@ -30,7 +30,7 @@ from loopy.diagnostic import ( import islpy as isl -from pytools.persistent_dict import WriteOncePersistentDict, ReadOnlyEntryError +from pytools.persistent_dict import WriteOncePersistentDict from loopy.tools import LoopyKeyBuilder from loopy.version import DATA_MODEL_VERSION @@ -2127,10 +2127,7 @@ def preprocess_kernel(kernel, device=None): # }}} if CACHING_ENABLED: - try: - preprocess_cache[input_kernel] = kernel - except ReadOnlyEntryError: - pass + preprocess_cache.store_if_not_present(input_kernel, kernel) return kernel diff --git a/loopy/schedule/__init__.py b/loopy/schedule/__init__.py index 221fcf3e0..3d47a5ec5 100644 --- a/loopy/schedule/__init__.py +++ b/loopy/schedule/__init__.py @@ -29,7 +29,7 @@ import sys import islpy as isl from loopy.diagnostic import warn_with_kernel, LoopyError # noqa -from pytools.persistent_dict import WriteOncePersistentDict, ReadOnlyEntryError +from pytools.persistent_dict import WriteOncePersistentDict from loopy.tools import LoopyKeyBuilder from loopy.version import DATA_MODEL_VERSION @@ -1972,10 +1972,7 @@ def get_one_scheduled_kernel(kernel): kernel.name, time()-start_time)) if CACHING_ENABLED and not from_cache: - try: - schedule_cache[sched_cache_key] = result - except ReadOnlyEntryError: - pass + schedule_cache.store_if_not_present(sched_cache_key, result) return result diff --git a/loopy/transform/buffer.py b/loopy/transform/buffer.py index a50844038..52ae505d8 100644 --- a/loopy/transform/buffer.py +++ b/loopy/transform/buffer.py @@ -29,7 +29,7 @@ from loopy.symbolic import (get_dependencies, RuleAwareIdentityMapper, SubstitutionRuleMappingContext, SubstitutionMapper) from pymbolic.mapper.substitutor import make_subst_func -from pytools.persistent_dict import WriteOncePersistentDict, ReadOnlyEntryError +from pytools.persistent_dict import WriteOncePersistentDict from loopy.tools import LoopyKeyBuilder, PymbolicExpressionHashWrapper from loopy.version import DATA_MODEL_VERSION from loopy.diagnostic import LoopyError @@ -532,10 +532,7 @@ def buffer_array(kernel, var_name, buffer_inames, init_expression=None, if CACHING_ENABLED: from loopy.preprocess import prepare_for_caching - try: - buffer_array_cache[cache_key] = prepare_for_caching(kernel) - except ReadOnlyEntryError: - pass + buffer_array_cache.store_if_not_present(cache_key, prepare_for_caching(kernel)) return kernel diff --git a/setup.py b/setup.py index e1726772d..94843bf69 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,7 @@ setup(name="loo.py", ], install_requires=[ - "pytools>=2017.5", + "pytools>=2017.6", "pymbolic>=2016.2", "genpy>=2016.1.2", "cgen>=2016.1", -- GitLab From 88a0422ecfe862f7c69867d1d31a1c5e765d4872 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Mon, 25 Sep 2017 23:59:09 -0500 Subject: [PATCH 3/3] flake8 fix. --- loopy/transform/buffer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/loopy/transform/buffer.py b/loopy/transform/buffer.py index 52ae505d8..1b059b6a7 100644 --- a/loopy/transform/buffer.py +++ b/loopy/transform/buffer.py @@ -532,7 +532,8 @@ def buffer_array(kernel, var_name, buffer_inames, init_expression=None, if CACHING_ENABLED: from loopy.preprocess import prepare_for_caching - buffer_array_cache.store_if_not_present(cache_key, prepare_for_caching(kernel)) + buffer_array_cache.store_if_not_present( + cache_key, prepare_for_caching(kernel)) return kernel -- GitLab