From 125bc1f24818c9c038ccfb64aaf71e3c4908f322 Mon Sep 17 00:00:00 2001 From: Connor Ward Date: Tue, 7 Dec 2021 10:11:59 +0000 Subject: [PATCH 1/3] Make ArrayBase hashable Previously __hash__ was implicitly set to None because ArrayBase implemented __eq__. --- loopy/kernel/array.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/loopy/kernel/array.py b/loopy/kernel/array.py index 97bc02dfd..b6ed5518d 100644 --- a/loopy/kernel/array.py +++ b/loopy/kernel/array.py @@ -892,6 +892,11 @@ def __init__(self, name, dtype=None, shape=None, dim_tags=None, offset=0, tags=tags, **kwargs) + # Without this __hash__ is set to None because this class overrides __eq__. + # Source: https://docs.python.org/3/reference/datamodel.html#object.__hash__ + def __hash__(self): + return super().__hash__() + def __eq__(self, other): from loopy.symbolic import ( is_tuple_of_expressions_equal as istoee, From 6312092e3b9749db84f143f111ad5d7e5b58a838 Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni Date: Thu, 9 Dec 2021 17:24:37 +0530 Subject: [PATCH 2/3] add a rename_iname regression with reduction --- test/test_transform.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/test_transform.py b/test/test_transform.py index 27f55c760..3915ce161 100644 --- a/test/test_transform.py +++ b/test/test_transform.py @@ -1324,6 +1324,19 @@ def test_precompute_does_not_lead_to_dep_cycle(ctx_factory): lp.auto_test_vs_ref(knl, ctx, ref_knl) +def test_rename_inames_redn(): + t_unit = lp.make_kernel( + "{[i, j0, j1]: 0<=i, j0, j1<10}", + """ + y0[i] = sum(j0, sum([j1], 2*A[i, j0, j1])) + """) + + t_unit = lp.rename_iname(t_unit, "j1", "ifused") + + assert "j1" not in t_unit.default_entrypoint.all_inames() + assert "ifused" in t_unit.default_entrypoint.all_inames() + + if __name__ == "__main__": if len(sys.argv) > 1: exec(sys.argv[1]) From da5c36e1ccd24bfc83c136ffbb83f78e8f224434 Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni Date: Thu, 9 Dec 2021 17:10:18 +0530 Subject: [PATCH 3/3] duplicate inames within reduction contexts reduction inames are not included within expression deps. --- loopy/transform/iname.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/loopy/transform/iname.py b/loopy/transform/iname.py index e61b85be3..e55bad50c 100644 --- a/loopy/transform/iname.py +++ b/loopy/transform/iname.py @@ -935,7 +935,8 @@ def duplicate_inames(kernel, inames, within, new_inames=None, suffix=None, within=within) def _does_access_old_inames(kernel, insn, *args): - return bool(frozenset(inames) & insn.dependency_names()) + return bool(frozenset(inames) & (insn.dependency_names() + | insn.reduction_inames())) kernel = rule_mapping_context.finish_kernel( indup.map_kernel(kernel, within=_does_access_old_inames,