From 81209bd8b616cff3784572899a8a90c09c0cb254 Mon Sep 17 00:00:00 2001 From: Miklos Homolya Date: Tue, 13 Dec 2016 10:23:49 +0000 Subject: [PATCH 1/2] minor simplication to impero_utils.py Remove TODO.md --- TODO.md | 12 ------------ gem/impero_utils.py | 47 +++++++++++++++++++++++---------------------- 2 files changed, 24 insertions(+), 35 deletions(-) delete mode 100644 TODO.md diff --git a/TODO.md b/TODO.md deleted file mode 100644 index ceaf853e..00000000 --- a/TODO.md +++ /dev/null @@ -1,12 +0,0 @@ -- [X] `driver.py` cleanup - - [X] clean up around the `fem.process` call -- UFL to GEM: - - [X] Re-think translation context - - [ ] ~~symbolic tabulation for cellwise constantness?~~ (See [#15](https://github.com/firedrakeproject/tsfc/issues/15)) - - [ ] ~~simplification in the `FormSplitter`?~~ - - [X] on branch for new H(div) trace element -- [X] `geometric.py`: move functionality to FIAT -- [ ] split `compile_gem`: Impero AST, ImperoC -- [X] `gem.py`: common base class for indices, make `Zero` a "`Literal`" -- [ ] Better `README`, AUTHORS, more pedantic licensing info -- [X] refactor CellVolue / FacetArea diff --git a/gem/impero_utils.py b/gem/impero_utils.py index 72be93d9..4f58bac1 100644 --- a/gem/impero_utils.py +++ b/gem/impero_utils.py @@ -92,10 +92,10 @@ def compile_gem(return_variables, expressions, prefix_ordering, remove_zeros=Fal tree = make_loop_tree(ops, get_indices) # Collect temporaries - temporaries = collect_temporaries(ops) + temporaries = collect_temporaries(tree) # Determine declarations - declare, indices = place_declarations(ops, tree, temporaries, get_indices) + declare, indices = place_declarations(tree, temporaries, get_indices) # Prepare ImperoC (Impero AST + other data for code generation) return ImperoC(tree, temporaries, declare, indices) @@ -147,18 +147,18 @@ def inline_temporaries(expressions, ops): return [op for op in ops if not (isinstance(op, imp.Evaluate) and op.expression in candidates)] -def collect_temporaries(ops): +def collect_temporaries(tree): """Collects GEM expressions to assign to temporaries from a list of Impero terminals.""" result = [] - for op in ops: + for node in traversal((tree,)): # IndexSum temporaries should be added either at Initialise or # at Accumulate. The difference is only in ordering # (numbering). We chose Accumulate here. - if isinstance(op, imp.Accumulate): - result.append(op.indexsum) - elif isinstance(op, imp.Evaluate): - result.append(op.expression) + if isinstance(node, imp.Accumulate): + result.append(node.indexsum) + elif isinstance(node, imp.Evaluate): + result.append(node.expression) return result @@ -185,10 +185,9 @@ def make_loop_tree(ops, get_indices, level=0): return imp.Block(statements) -def place_declarations(ops, tree, temporaries, get_indices): +def place_declarations(tree, temporaries, get_indices): """Determines where and how to declare temporaries for an Impero AST. - :arg ops: terminals of ``tree`` :arg tree: Impero AST to determine the declarations for :arg temporaries: list of GEM expressions which are assigned to temporaries @@ -200,8 +199,9 @@ def place_declarations(ops, tree, temporaries, get_indices): # Collect the total number of temporary references total_refcount = collections.Counter() - for op in ops: - total_refcount.update(temp_refcount(temporaries_set, op)) + for node in traversal((tree,)): + if isinstance(node, imp.Terminal): + total_refcount.update(temp_refcount(temporaries_set, node)) assert temporaries_set == set(total_refcount) # Result @@ -264,17 +264,18 @@ def recurse_block(expr, loop_indices): # Set in ``declare`` for Impero terminals whether they should # declare the temporary that they are writing to. - for op in ops: - declare[op] = False - if isinstance(op, imp.Evaluate): - e = op.expression - elif isinstance(op, imp.Initialise): - e = op.indexsum - else: - continue - - if len(indices[e]) == 0: - declare[op] = True + for node in traversal((tree,)): + if isinstance(node, imp.Terminal): + declare[node] = False + if isinstance(node, imp.Evaluate): + e = node.expression + elif isinstance(node, imp.Initialise): + e = node.indexsum + else: + continue + + if len(indices[e]) == 0: + declare[node] = True return declare, indices From 166b608fd3a80378c7583e68cacbc4de22dc4263 Mon Sep 17 00:00:00 2001 From: Miklos Homolya Date: Tue, 13 Dec 2016 11:30:35 +0000 Subject: [PATCH 2/2] fix node ordering and temporary numbering --- gem/node.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gem/node.py b/gem/node.py index a5ed3a69..5adce50f 100644 --- a/gem/node.py +++ b/gem/node.py @@ -113,7 +113,7 @@ def traversal(expression_dags): while lifo: node = lifo.pop() yield node - for child in node.children: + for child in reversed(node.children): if child not in seen: seen.add(child) lifo.append(child)