From b1d4db0339c545fc21441582a3a3425322bad506 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Fri, 23 Feb 2018 23:25:52 -0600 Subject: [PATCH 1/3] Fix vim section bracketing --- loopy/kernel/tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loopy/kernel/tools.py b/loopy/kernel/tools.py index 15db06ad7..f2104ca76 100644 --- a/loopy/kernel/tools.py +++ b/loopy/kernel/tools.py @@ -1391,7 +1391,7 @@ def draw_dependencies_as_unicode_arrows( if value is None: del columns_in_use[col] - # }} + # }}} processed_ids.add(insn.id) -- GitLab From f318819dcf6903e619d297ca3940f43a6dfd08a6 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Fri, 23 Feb 2018 23:28:17 -0600 Subject: [PATCH 2/3] Ensure the scheduler generator chain is GC'd before resetting the recursion limit --- loopy/schedule/__init__.py | 39 ++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/loopy/schedule/__init__.py b/loopy/schedule/__init__.py index b196b343e..f40a943b0 100644 --- a/loopy/schedule/__init__.py +++ b/loopy/schedule/__init__.py @@ -29,6 +29,8 @@ import sys import islpy as isl from loopy.diagnostic import warn_with_kernel, LoopyError # noqa +from pytools import MinRecursionLimit + from pytools.persistent_dict import WriteOncePersistentDict from loopy.tools import LoopyKeyBuilder from loopy.version import DATA_MODEL_VERSION @@ -1810,12 +1812,27 @@ def insert_barriers(kernel, schedule, synchronization_kind, verify_only, level=0 # }}} +class MinRecursionLimitForScheduling(MinRecursionLimit): + def __init__(self, kernel): + MinRecursionLimit.__init__(self, + len(kernel.instructions) * 2 + len(kernel.all_inames()) * 4) + + # {{{ main scheduling entrypoint def generate_loop_schedules(kernel, debug_args={}): - from pytools import MinRecursionLimit - with MinRecursionLimit(max(len(kernel.instructions) * 2, - len(kernel.all_inames()) * 4)): + """ + .. warning:: + + This function needs to be called inside (another layer) of a + :class:`MinRecursionLimitForScheduling` context manager, and the + context manager needs to end *after* the last reference to the + generators has gone out of scope. Otherwise, the high-recursion-limit + generator chain may not be successfully garbage-collected and cause an + internal error in the Python runtime. + """ + + with MinRecursionLimitForScheduling(kernel): for sched in generate_loop_schedules_inner(kernel, debug_args=debug_args): yield sched @@ -2003,6 +2020,19 @@ schedule_cache = WriteOncePersistentDict( key_builder=LoopyKeyBuilder()) +def _get_one_scheduled_kernel_inner(kernel): + # This helper function exists to ensure that the generator chain is fully + # out of scope after the function returns. This allows it to be + # garbage-collected in the exit handler of the + # MinRecursionLimitForScheduling context manager in the surrounding + # function, because it possilby cannot be safely collected with a lower + # recursion limit without crashing the Python runtime. + # + # See https://gitlab.tiker.net/inducer/sumpy/issues/31 for context. + + return next(iter(generate_loop_schedules(kernel))) + + def get_one_scheduled_kernel(kernel): from loopy import CACHING_ENABLED @@ -2024,7 +2054,8 @@ def get_one_scheduled_kernel(kernel): logger.info("%s: schedule start" % kernel.name) - result = next(iter(generate_loop_schedules(kernel))) + with MinRecursionLimitForScheduling(kernel): + result = _get_one_scheduled_kernel_inner(kernel) logger.info("%s: scheduling done after %.2f s" % ( kernel.name, time()-start_time)) -- GitLab From 60ed8850abd9b73240990e7f78779814e426fd1c Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Fri, 23 Feb 2018 23:33:42 -0600 Subject: [PATCH 3/3] Bump pytools requirement --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b8f36d125..bd94ea7e7 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,7 @@ setup(name="loo.py", ], install_requires=[ - "pytools>=2017.6", + "pytools>=2018.1", "pymbolic>=2016.2", "genpy>=2016.1.2", "cgen>=2016.1", -- GitLab