From e3df15c5abf4c0acb4af2acf5761b955b5f111a4 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 27 Nov 2018 14:04:46 -0600 Subject: [PATCH 1/3] Make ConstantToNumpyConversionMapper CSE-caching-aware --- grudge/symbolic/mappers/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/grudge/symbolic/mappers/__init__.py b/grudge/symbolic/mappers/__init__.py index 2b0b2242..c2fba3d6 100644 --- a/grudge/symbolic/mappers/__init__.py +++ b/grudge/symbolic/mappers/__init__.py @@ -933,9 +933,13 @@ class QuadratureCheckerAndRemover(CSECachingMapperMixin, IdentityMapper): # {{{ simplification / optimization class ConstantToNumpyConversionMapper( + CSECachingMapperMixin, pymbolic.mapper.constant_converter.ConstantToNumpyConversionMapper, IdentityMapperMixin): - pass + map_common_subexpression_uncached = ( + pymbolic.mapper.constant_converter + .ConstantToNumpyConversionMapper + .map_common_subexpression) class CommutativeConstantFoldingMapper( -- GitLab From 3e88d2d6a5c741f642bd6088602d821147d0a2ce Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 27 Nov 2018 14:05:14 -0600 Subject: [PATCH 2/3] Make code printing topsort aware of subscripted variables --- grudge/symbolic/compiler.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/grudge/symbolic/compiler.py b/grudge/symbolic/compiler.py index 4a58961b..a4f203d6 100644 --- a/grudge/symbolic/compiler.py +++ b/grudge/symbolic/compiler.py @@ -405,7 +405,12 @@ class Code(object): for dep in insn.get_dependencies(): try: - writer = var_to_writer[dep.name] + if isinstance(dep, Subscript): + dep_name = dep.aggregate.name + else: + dep_name = dep.name + + writer = var_to_writer[dep_name] except KeyError: # input variables won't be found pass -- GitLab From 67c3b330b1e68ec8586cf2d4336c926991f2e13f Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Tue, 27 Nov 2018 14:05:32 -0600 Subject: [PATCH 3/3] Add caching to get_complete_origins_set in assignment aggreation --- grudge/symbolic/compiler.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/grudge/symbolic/compiler.py b/grudge/symbolic/compiler.py index a4f203d6..972e4056 100644 --- a/grudge/symbolic/compiler.py +++ b/grudge/symbolic/compiler.py @@ -609,6 +609,11 @@ def aggregate_assignments(inf_mapper, instructions, result, # {{{ aggregation helpers def get_complete_origins_set(insn, skip_levels=0): + try: + return insn_to_origins_cache[insn] + except KeyError: + pass + if skip_levels < 0: skip_levels = 0 @@ -622,6 +627,8 @@ def aggregate_assignments(inf_mapper, instructions, result, result |= get_complete_origins_set( dep_origin, skip_levels-1) + insn_to_origins_cache[insn] = result + return result var_assignees_cache = {} @@ -651,6 +658,8 @@ def aggregate_assignments(inf_mapper, instructions, result, # {{{ main aggregation pass + insn_to_origins_cache = {} + origins_map = dict( (assignee, insn) for insn in instructions -- GitLab