From c10458b0ed9b06de7e11c0eb2febfa0608eabe2e Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 7 Sep 2017 16:28:06 -0500 Subject: [PATCH 1/4] Kernel constructor: Add an option to control whether instruction IDs get uniquified or not. Related: #67 --- loopy/kernel/__init__.py | 55 ++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/loopy/kernel/__init__.py b/loopy/kernel/__init__.py index 622f5e49b..8d59b528a 100644 --- a/loopy/kernel/__init__.py +++ b/loopy/kernel/__init__.py @@ -212,10 +212,16 @@ class LoopKernel(ImmutableRecordWithoutPickling): state=kernel_state.INITIAL, target=None, - # When kernels get intersected in slab decomposition, - # their grid sizes shouldn't change. This provides - # a way to forward sub-kernel grid size requests. - overridden_get_grid_sizes_for_insn_ids=None): + overridden_get_grid_sizes_for_insn_ids=None, + uniquify_instruction_ids=True): + """ + :arg overridden_get_grid_sizes_for_insn_ids: A callable. When kernels get + intersected in slab decomposition, their grid sizes shouldn't + change. This provides a way to forward sub-kernel grid size requests. + + :arg uniquify_instruction_ids: Ensure all instruction ids are unique. + If *False*, does not look at `instructions`. + """ if cache_manager is None: from loopy.kernel.tools import SetOperationCacheManager @@ -223,31 +229,32 @@ class LoopKernel(ImmutableRecordWithoutPickling): # {{{ make instruction ids unique - from loopy.kernel.creation import UniqueName + if uniquify_instruction_ids: + from loopy.kernel.creation import UniqueName - insn_ids = set() - for insn in instructions: - if insn.id is not None and not isinstance(insn.id, UniqueName): - if insn.id in insn_ids: - raise RuntimeError("duplicate instruction id: %s" % insn.id) - insn_ids.add(insn.id) + insn_ids = set() + for insn in instructions: + if insn.id is not None and not isinstance(insn.id, UniqueName): + if insn.id in insn_ids: + raise RuntimeError("duplicate instruction id: %s" % insn.id) + insn_ids.add(insn.id) - insn_id_gen = UniqueNameGenerator(insn_ids) + insn_id_gen = UniqueNameGenerator(insn_ids) - new_instructions = [] + new_instructions = [] - for insn in instructions: - if insn.id is None: - new_instructions.append( - insn.copy(id=insn_id_gen("insn"))) - elif isinstance(insn.id, UniqueName): - new_instructions.append( - insn.copy(id=insn_id_gen(insn.id.name))) - else: - new_instructions.append(insn) + for insn in instructions: + if insn.id is None: + new_instructions.append( + insn.copy(id=insn_id_gen("insn"))) + elif isinstance(insn.id, UniqueName): + new_instructions.append( + insn.copy(id=insn_id_gen(insn.id.name))) + else: + new_instructions.append(insn) - instructions = new_instructions - del new_instructions + instructions = new_instructions + del new_instructions # }}} -- GitLab From db0f288666cc1e420dfe7177e8624a1e4d874d65 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 7 Sep 2017 16:36:48 -0500 Subject: [PATCH 2/4] Make the description a bit more precise. --- loopy/kernel/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/loopy/kernel/__init__.py b/loopy/kernel/__init__.py index 8d59b528a..e042e9ec4 100644 --- a/loopy/kernel/__init__.py +++ b/loopy/kernel/__init__.py @@ -219,8 +219,9 @@ class LoopKernel(ImmutableRecordWithoutPickling): intersected in slab decomposition, their grid sizes shouldn't change. This provides a way to forward sub-kernel grid size requests. - :arg uniquify_instruction_ids: Ensure all instruction ids are unique. - If *False*, does not look at `instructions`. + :arg uniquify_instruction_ids: Ensure all instruction ids are unique and + convert any IDs that are :class:`loopy.UniqueName` or *None* into + appropriate strings. If *False*, does not look at `instructions`. """ if cache_manager is None: -- GitLab From fc0bface9a942e191079b7c7d7ec3e21510d42cc Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 7 Sep 2017 16:37:47 -0500 Subject: [PATCH 3/4] Fix typo. --- loopy/kernel/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loopy/kernel/__init__.py b/loopy/kernel/__init__.py index e042e9ec4..8bb584297 100644 --- a/loopy/kernel/__init__.py +++ b/loopy/kernel/__init__.py @@ -219,7 +219,7 @@ class LoopKernel(ImmutableRecordWithoutPickling): intersected in slab decomposition, their grid sizes shouldn't change. This provides a way to forward sub-kernel grid size requests. - :arg uniquify_instruction_ids: Ensure all instruction ids are unique and + :arg uniquify_instruction_ids: Ensure all instruction IDs are unique and convert any IDs that are :class:`loopy.UniqueName` or *None* into appropriate strings. If *False*, does not look at `instructions`. """ -- GitLab From 4a9ee21b65462fe54c76c0c1f971e243d1f6f025 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 7 Sep 2017 16:40:54 -0500 Subject: [PATCH 4/4] Fix the namespace of the UniqueName class in the description. --- loopy/kernel/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/loopy/kernel/__init__.py b/loopy/kernel/__init__.py index 8bb584297..ad8643668 100644 --- a/loopy/kernel/__init__.py +++ b/loopy/kernel/__init__.py @@ -220,8 +220,9 @@ class LoopKernel(ImmutableRecordWithoutPickling): change. This provides a way to forward sub-kernel grid size requests. :arg uniquify_instruction_ids: Ensure all instruction IDs are unique and - convert any IDs that are :class:`loopy.UniqueName` or *None* into - appropriate strings. If *False*, does not look at `instructions`. + convert any IDs that are :class:`loopy.kernel.creation.UniqueName` or + *None* into appropriate strings. If *False*, does not look at + `instructions`. """ if cache_manager is None: -- GitLab