From f79ee0689ff665246bc5e554d4f381336c13d329 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 5 Jun 2016 01:36:16 -0500 Subject: [PATCH] Remove link_inames --- loopy/__init__.py | 4 +- loopy/transform/iname.py | 110 --------------------------------------- test/test_loopy.py | 13 +++-- 3 files changed, 10 insertions(+), 117 deletions(-) diff --git a/loopy/__init__.py b/loopy/__init__.py index 19d9ddbc7..4322bf928 100644 --- a/loopy/__init__.py +++ b/loopy/__init__.py @@ -62,7 +62,7 @@ from loopy.library.reduction import register_reduction_parser from loopy.transform.iname import ( set_loop_priority, split_iname, chunk_iname, join_inames, tag_inames, duplicate_inames, - rename_iname, link_inames, remove_unused_inames, + rename_iname, remove_unused_inames, split_reduction_inward, split_reduction_outward, affine_map_inames, find_unused_axis_tag, make_reduction_inames_unique) @@ -159,7 +159,7 @@ __all__ = [ "set_loop_priority", "split_iname", "chunk_iname", "join_inames", "tag_inames", "duplicate_inames", - "rename_iname", "link_inames", "remove_unused_inames", + "rename_iname", "remove_unused_inames", "split_reduction_inward", "split_reduction_outward", "affine_map_inames", "find_unused_axis_tag", "make_reduction_inames_unique", diff --git a/loopy/transform/iname.py b/loopy/transform/iname.py index e72897a04..12749a303 100644 --- a/loopy/transform/iname.py +++ b/loopy/transform/iname.py @@ -48,8 +48,6 @@ __doc__ = """ .. autofunction:: duplicate_inames -.. undocumented .. autofunction:: link_inames - .. autofunction:: rename_iname .. autofunction:: remove_unused_inames @@ -890,114 +888,6 @@ def rename_iname(knl, old_iname, new_iname, existing_ok=False, within=None): # }}} -# {{{ link inames - -def link_inames(knl, inames, new_iname, within=None, tag=None): - # {{{ normalize arguments - - if isinstance(inames, str): - inames = inames.split(",") - - var_name_gen = knl.get_var_name_generator() - new_iname = var_name_gen(new_iname) - - # }}} - - # {{{ ensure that each iname is used at most once in each instruction - - inames_set = set(inames) - - if 0: - # FIXME! - for insn in knl.instructions: - insn_inames = knl.insn_inames(insn.id) | insn.reduction_inames() - - if len(insn_inames & inames_set) > 1: - raise LoopyError("To-be-linked inames '%s' are used in " - "instruction '%s'. No more than one such iname can " - "be used in one instruction." - % (", ".join(insn_inames & inames_set), insn.id)) - - # }}} - - from loopy.kernel.tools import DomainChanger - domch = DomainChanger(knl, tuple(inames)) - - # {{{ ensure that projections are identical - - unrelated_dom_inames = list( - set(domch.domain.get_var_names(dim_type.set)) - - inames_set) - - domain = domch.domain - - # move all inames to be linked to end to prevent shuffly confusion - for iname in inames: - dt, index = domain.get_var_dict()[iname] - assert dt == dim_type.set - - # move to tail of param dim_type - domain = domain.move_dims( - dim_type.param, domain.dim(dim_type.param), - dt, index, 1) - # move to tail of set dim_type - domain = domain.move_dims( - dim_type.set, domain.dim(dim_type.set), - dim_type.param, domain.dim(dim_type.param)-1, 1) - - projections = [ - domch.domain.project_out_except( - unrelated_dom_inames + [iname], [dim_type.set]) - for iname in inames] - - all_equal = True - first_proj = projections[0] - for proj in projections[1:]: - all_equal = all_equal and (proj <= first_proj and first_proj <= proj) - - if not all_equal: - raise LoopyError("Inames cannot be linked because their domain " - "constraints are not the same.") - - del domain # messed up for testing, do not use - - # }}} - - # change the domain - from loopy.isl_helpers import duplicate_axes - knl = knl.copy( - domains=domch.get_domains_with( - duplicate_axes(domch.domain, [inames[0]], [new_iname]))) - - # {{{ change the code - - from pymbolic import var - subst_dict = dict((iname, var(new_iname)) for iname in inames) - - from loopy.match import parse_stack_match - within = parse_stack_match(within) - - from pymbolic.mapper.substitutor import make_subst_func - rule_mapping_context = SubstitutionRuleMappingContext( - knl.substitutions, var_name_gen) - ijoin = RuleAwareSubstitutionMapper(rule_mapping_context, - make_subst_func(subst_dict), within) - - knl = rule_mapping_context.finish_kernel( - ijoin.map_kernel(knl)) - - # }}} - - knl = remove_unused_inames(knl, inames) - - if tag is not None: - knl = tag_inames(knl, {new_iname: tag}) - - return knl - -# }}} - - # {{{ remove unused inames def remove_unused_inames(knl, inames=None): diff --git a/test/test_loopy.py b/test/test_loopy.py index 063c9bee6..cda192c64 100644 --- a/test/test_loopy.py +++ b/test/test_loopy.py @@ -854,17 +854,20 @@ def test_make_copy_kernel(ctx_factory): def test_auto_test_can_detect_problems(ctx_factory): ctx = ctx_factory() - knl = lp.make_kernel( + ref_knl = lp.make_kernel( "{[i,j]: 0<=i,j