From 610fb875732f36d8212cdef05ed8623716922b86 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Tue, 23 Jun 2020 00:19:24 -0500 Subject: [PATCH] Call topo sort only once --- loopy/schedule/__init__.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/loopy/schedule/__init__.py b/loopy/schedule/__init__.py index e6ae063b1..c4380b0e0 100644 --- a/loopy/schedule/__init__.py +++ b/loopy/schedule/__init__.py @@ -770,6 +770,10 @@ class SchedulerState(ImmutableRecord): Used to produce warnings about deprecated 'boosting' behavior Should be removed along with boostability in 2017.x. + + .. attribute:: lazy_topological_sort_getter + + Used to get a topologically sort of the instructions lazily. """ @property @@ -779,8 +783,16 @@ class SchedulerState(ImmutableRecord): else: return None + +class LazyTopologicalSortGetter(object): + """Returns instruction ids of the kernel in a topologically sorted order + """ + + def __init__(self, kernel): + self.kernel = kernel + @memoize_method - def get_insn_ids_in_a_topologically_sorted_order(self): + def __call__(self): from pytools.graph import compute_topological_order rev_dep_map = {insn.id: set() for insn in self.kernel.instructions} @@ -812,7 +824,7 @@ def schedule_as_many_run_insns_as_possible(sched_state): # {{{ topological sort toposorted_insn_ids = tuple(insn_id for insn_id in - sched_state.get_insn_ids_in_a_topologically_sorted_order() if + sched_state.lazy_topological_sort_getter() if insn_id in sched_state.unscheduled_insn_ids and ( sched_state.kernel.id_to_insn[insn_id].within_inames >= frozenset(sched_state.active_inames))) @@ -2133,7 +2145,9 @@ def generate_loop_schedules_inner(kernel, debug_args={}): group_insn_counts=group_insn_counts(kernel), active_group_counts={}, - uses_of_boostability=[]) + uses_of_boostability=[], + lazy_topological_sort_getter=LazyTopologicalSortGetter(kernel), + ) schedule_gen_kwargs = {} if kernel.options.ignore_boostable_into: -- GitLab