From f33d54da0dc88b3dfaffc3e4c46ccb1e7bff90e7 Mon Sep 17 00:00:00 2001 From: Cory Mikida Date: Wed, 23 May 2018 16:54:58 -0500 Subject: [PATCH 1/7] First pass at deallocation of intermediate states (to reduce memory pressure) --- dagrt/codegen/data.py | 65 ++++++++++++++++++++++++++++++++++++++++ dagrt/codegen/fortran.py | 39 +++++++++++++++++++++++- 2 files changed, 103 insertions(+), 1 deletion(-) diff --git a/dagrt/codegen/data.py b/dagrt/codegen/data.py index 11b6a9a..8058457 100644 --- a/dagrt/codegen/data.py +++ b/dagrt/codegen/data.py @@ -551,6 +551,71 @@ class SymbolKindFinder(object): # }}} +class VariableDepTable(object): + """ + .. attribute:: global_table + + a mapping from variables to statement IDs, + to find the last dependent statement in the topological order + for a given phase, for a given variable + + .. attribute:: a nested mapping ``[function][symbol_name]`` + to statement IDs + """ + + def __init__(self): + self.global_table = {} + self.per_function_table = {} + + def set(self, func_name, name, inst_id): + tbl = self.per_function_table.setdefault(func_name, {}) + tbl[name] = inst_id + + def get(self, func_name, name): + tbl = self.per_function_table.setdefault(func_name, {}) + + return tbl[name] + + def __str__(self): + def format_table(tbl, indent=" "): + return "\n".join( + "%s%s: %s" % (indent, name, kind) + for name, kind in tbl.items()) + + return "\n".join( + ["global:\n%s" % format_table(self.global_table)] + [ + "func '%s':\n%s" % (func_name, format_table(tbl)) + for func_name, tbl in self.per_function_table.items()]) + + +# {{{ variable dependency finder + +class VariableDepFinder(object): + def __init__(self, function_registry): + self.function_registry = function_registry + + def __call__(self, names, functions): + """Return a :class:`VariableDepTable`. + """ + result = VariableDepTable() + + from dagrt.codegen.dag_ast import get_statements_in_ast + + for name, func in zip(names, functions): + + for statement in get_statements_in_ast(func): + # Associate latest statement in this phase at which + # a given variable is used + read_and_written = statement.get_read_variables().union( + statement.get_written_variables()) + for variable in read_and_written: + result.set(name, variable, statement.id) + + return result + +# }}} + + # {{{ collect user types def collect_user_types(skt): diff --git a/dagrt/codegen/fortran.py b/dagrt/codegen/fortran.py index 8f55710..ada2267 100644 --- a/dagrt/codegen/fortran.py +++ b/dagrt/codegen/fortran.py @@ -1058,12 +1058,16 @@ class CodeGenerator(StructuredCodeGenerator): # }}} - from dagrt.codegen.data import SymbolKindFinder + from dagrt.codegen.data import SymbolKindFinder, VariableDepFinder self.sym_kind_table = SymbolKindFinder(self.function_registry)( [fd.name for fd in fdescrs], [fd.ast for fd in fdescrs]) + self.var_dep_table = VariableDepFinder(self.function_registry)( + [fd.name for fd in fdescrs], + [fd.ast for fd in fdescrs]) + from dagrt.codegen.analysis import collect_ode_component_names_from_dag component_ids = collect_ode_component_names_from_dag(dag) @@ -2115,6 +2119,20 @@ class CodeGenerator(StructuredCodeGenerator): for ident, start, stop in inst.loops[::-1]: self.emitter.__exit__(None, None, None) + # Deallocate if done with intermed. quantities + from dagrt.utils import is_state_variable + + read_and_written = inst.get_read_variables().union( + inst.get_written_variables()) + + for variable in read_and_written: + var_kind = self.sym_kind_table.get( + self.current_function, variable) + test_id = self.var_dep_table.get( + self.current_function, variable) + if inst.id == test_id and not is_state_variable(variable): + self.emit_variable_deinit(variable, var_kind) + assert start_em is self.emitter # }}} @@ -2192,6 +2210,25 @@ class CodeGenerator(StructuredCodeGenerator): + assignee_fortran_names ))) + # Deallocate if done with intermed. quantities + from dagrt.utils import is_state_variable + + read_and_written = inst.get_read_variables().union( + inst.get_written_variables()) + + for variable in read_and_written: + # FIXME: This can fail for args of state update notification, + # hence the try/catch. + try: + var_kind = self.sym_kind_table.get( + self.current_function, variable) + test_id = self.var_dep_table.get( + self.current_function, variable) + if inst.id == test_id and not is_state_variable(variable): + self.emit_variable_deinit(variable, var_kind) + except KeyError: + pass + # }}} def emit_return(self): -- GitLab From 3f8855d62a849a85c1d996292dc8db10a81f5097 Mon Sep 17 00:00:00 2001 From: Cory Mikida Date: Thu, 31 May 2018 15:22:22 -0500 Subject: [PATCH 2/7] Changes to implementation of intermediate deallocation - uses function instead of class, changes some naming, fixes try-except block --- dagrt/codegen/analysis.py | 27 ++++++++++++++++ dagrt/codegen/data.py | 65 --------------------------------------- dagrt/codegen/fortran.py | 24 +++++++-------- 3 files changed, 39 insertions(+), 77 deletions(-) diff --git a/dagrt/codegen/analysis.py b/dagrt/codegen/analysis.py index 2d4e40c..a3e3d9c 100644 --- a/dagrt/codegen/analysis.py +++ b/dagrt/codegen/analysis.py @@ -247,4 +247,31 @@ def collect_ode_component_names_from_dag(dag): # }}} + +# {{{ variable dependency finder + +def var_to_statement_table(names, functions): + + """Return a table describing variable dependencies + in terms of statement ids. + """ + + tbl = {} + + from dagrt.codegen.dag_ast import get_statements_in_ast + + for name, func in zip(names, functions): + + for statement in get_statements_in_ast(func): + # Associate latest statement in this phase at which + # a given variable is used + read_and_written = statement.get_read_variables().union( + statement.get_written_variables()) + for variable in read_and_written: + tbl[variable, name] = statement.id + + return tbl + +# }}} + # vim: foldmethod=marker diff --git a/dagrt/codegen/data.py b/dagrt/codegen/data.py index 8058457..11b6a9a 100644 --- a/dagrt/codegen/data.py +++ b/dagrt/codegen/data.py @@ -551,71 +551,6 @@ class SymbolKindFinder(object): # }}} -class VariableDepTable(object): - """ - .. attribute:: global_table - - a mapping from variables to statement IDs, - to find the last dependent statement in the topological order - for a given phase, for a given variable - - .. attribute:: a nested mapping ``[function][symbol_name]`` - to statement IDs - """ - - def __init__(self): - self.global_table = {} - self.per_function_table = {} - - def set(self, func_name, name, inst_id): - tbl = self.per_function_table.setdefault(func_name, {}) - tbl[name] = inst_id - - def get(self, func_name, name): - tbl = self.per_function_table.setdefault(func_name, {}) - - return tbl[name] - - def __str__(self): - def format_table(tbl, indent=" "): - return "\n".join( - "%s%s: %s" % (indent, name, kind) - for name, kind in tbl.items()) - - return "\n".join( - ["global:\n%s" % format_table(self.global_table)] + [ - "func '%s':\n%s" % (func_name, format_table(tbl)) - for func_name, tbl in self.per_function_table.items()]) - - -# {{{ variable dependency finder - -class VariableDepFinder(object): - def __init__(self, function_registry): - self.function_registry = function_registry - - def __call__(self, names, functions): - """Return a :class:`VariableDepTable`. - """ - result = VariableDepTable() - - from dagrt.codegen.dag_ast import get_statements_in_ast - - for name, func in zip(names, functions): - - for statement in get_statements_in_ast(func): - # Associate latest statement in this phase at which - # a given variable is used - read_and_written = statement.get_read_variables().union( - statement.get_written_variables()) - for variable in read_and_written: - result.set(name, variable, statement.id) - - return result - -# }}} - - # {{{ collect user types def collect_user_types(skt): diff --git a/dagrt/codegen/fortran.py b/dagrt/codegen/fortran.py index ada2267..5af9147 100644 --- a/dagrt/codegen/fortran.py +++ b/dagrt/codegen/fortran.py @@ -1058,18 +1058,19 @@ class CodeGenerator(StructuredCodeGenerator): # }}} - from dagrt.codegen.data import SymbolKindFinder, VariableDepFinder + from dagrt.codegen.data import SymbolKindFinder self.sym_kind_table = SymbolKindFinder(self.function_registry)( [fd.name for fd in fdescrs], [fd.ast for fd in fdescrs]) - self.var_dep_table = VariableDepFinder(self.function_registry)( - [fd.name for fd in fdescrs], - [fd.ast for fd in fdescrs]) + from dagrt.codegen.analysis import ( + collect_ode_component_names_from_dag, var_to_statement_table) - from dagrt.codegen.analysis import collect_ode_component_names_from_dag component_ids = collect_ode_component_names_from_dag(dag) + self.var_dep_table = var_to_statement_table( + [fd.name for fd in fdescrs], + [fd.ast for fd in fdescrs]) if not component_ids <= set(self.user_type_map): raise RuntimeError("User type missing from user type map: %r" @@ -2128,8 +2129,7 @@ class CodeGenerator(StructuredCodeGenerator): for variable in read_and_written: var_kind = self.sym_kind_table.get( self.current_function, variable) - test_id = self.var_dep_table.get( - self.current_function, variable) + test_id = self.var_dep_table[variable, self.current_function] if inst.id == test_id and not is_state_variable(variable): self.emit_variable_deinit(variable, var_kind) @@ -2222,12 +2222,12 @@ class CodeGenerator(StructuredCodeGenerator): try: var_kind = self.sym_kind_table.get( self.current_function, variable) - test_id = self.var_dep_table.get( - self.current_function, variable) - if inst.id == test_id and not is_state_variable(variable): - self.emit_variable_deinit(variable, var_kind) except KeyError: - pass + continue + + test_id = self.var_dep_table[variable, self.current_function] + if inst.id == test_id and not is_state_variable(variable): + self.emit_variable_deinit(variable, var_kind) # }}} -- GitLab From f01a8c7c57a98331b05c7b52f68038f0917ffd78 Mon Sep 17 00:00:00 2001 From: Cory Mikida Date: Fri, 8 Jun 2018 16:23:51 -0500 Subject: [PATCH 3/7] Replace duplicate code with function calls, clarify naming/description --- dagrt/codegen/analysis.py | 11 +++++--- dagrt/codegen/fortran.py | 57 +++++++++++++++++---------------------- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/dagrt/codegen/analysis.py b/dagrt/codegen/analysis.py index a3e3d9c..5df169c 100644 --- a/dagrt/codegen/analysis.py +++ b/dagrt/codegen/analysis.py @@ -248,12 +248,15 @@ def collect_ode_component_names_from_dag(dag): # }}} -# {{{ variable dependency finder +# {{{ variable to last dependent statement table -def var_to_statement_table(names, functions): +def var_to_last_dependent_statement_table(names, functions): - """Return a table describing variable dependencies - in terms of statement ids. + """Return a table pairing each variable with the + latest statement in the topological order at which + that variable is used. This is used for intermediate + deallocation of variables that no longer need to be + read or written. """ tbl = {} diff --git a/dagrt/codegen/fortran.py b/dagrt/codegen/fortran.py index 5af9147..ed94b33 100644 --- a/dagrt/codegen/fortran.py +++ b/dagrt/codegen/fortran.py @@ -1065,10 +1065,11 @@ class CodeGenerator(StructuredCodeGenerator): [fd.ast for fd in fdescrs]) from dagrt.codegen.analysis import ( - collect_ode_component_names_from_dag, var_to_statement_table) + collect_ode_component_names_from_dag, + var_to_last_dependent_statement_table) component_ids = collect_ode_component_names_from_dag(dag) - self.var_dep_table = var_to_statement_table( + self.var_dep_table = var_to_last_dependent_statement_table( [fd.name for fd in fdescrs], [fd.ast for fd in fdescrs]) @@ -2120,18 +2121,7 @@ class CodeGenerator(StructuredCodeGenerator): for ident, start, stop in inst.loops[::-1]: self.emitter.__exit__(None, None, None) - # Deallocate if done with intermed. quantities - from dagrt.utils import is_state_variable - - read_and_written = inst.get_read_variables().union( - inst.get_written_variables()) - - for variable in read_and_written: - var_kind = self.sym_kind_table.get( - self.current_function, variable) - test_id = self.var_dep_table[variable, self.current_function] - if inst.id == test_id and not is_state_variable(variable): - self.emit_variable_deinit(variable, var_kind) + self.intermediate_deallocation(inst) assert start_em is self.emitter @@ -2210,24 +2200,7 @@ class CodeGenerator(StructuredCodeGenerator): + assignee_fortran_names ))) - # Deallocate if done with intermed. quantities - from dagrt.utils import is_state_variable - - read_and_written = inst.get_read_variables().union( - inst.get_written_variables()) - - for variable in read_and_written: - # FIXME: This can fail for args of state update notification, - # hence the try/catch. - try: - var_kind = self.sym_kind_table.get( - self.current_function, variable) - except KeyError: - continue - - test_id = self.var_dep_table[variable, self.current_function] - if inst.id == test_id and not is_state_variable(variable): - self.emit_variable_deinit(variable, var_kind) + self.intermediate_deallocation(inst) # }}} @@ -2268,6 +2241,26 @@ class CodeGenerator(StructuredCodeGenerator): (var(self.component_name_to_component_sym( inst.component_id)),))) + def intermediate_deallocation(self, inst): + # Deallocate if done with intermed. quantities + from dagrt.utils import is_state_variable + + read_and_written = inst.get_read_variables().union( + inst.get_written_variables()) + + for variable in read_and_written: + # FIXME: This can fail for args of state update notification, + # hence the try/catch. + try: + var_kind = self.sym_kind_table.get( + self.current_function, variable) + except KeyError: + continue + + test_id = self.var_dep_table[variable, self.current_function] + if inst.id == test_id and not is_state_variable(variable): + self.emit_variable_deinit(variable, var_kind) + def emit_inst_Raise(self, inst): # FIXME: Reenable emitting full error message # TBD: Quoting of quotes, extra-long lines -- GitLab From c29d7f2b5193872fe9c429b21d5c56d3634b6f53 Mon Sep 17 00:00:00 2001 From: Cory Mikida Date: Tue, 12 Jun 2018 16:12:31 -0500 Subject: [PATCH 4/7] Another round of name fixing/reducing redundant computations --- dagrt/codegen/analysis.py | 68 ++++++++++++++++++++++++++------------- dagrt/codegen/fortran.py | 29 +++++++++++------ 2 files changed, 65 insertions(+), 32 deletions(-) diff --git a/dagrt/codegen/analysis.py b/dagrt/codegen/analysis.py index 5df169c..ba36640 100644 --- a/dagrt/codegen/analysis.py +++ b/dagrt/codegen/analysis.py @@ -248,32 +248,56 @@ def collect_ode_component_names_from_dag(dag): # }}} -# {{{ variable to last dependent statement table - -def var_to_last_dependent_statement_table(names, functions): - - """Return a table pairing each variable with the - latest statement in the topological order at which - that variable is used. This is used for intermediate - deallocation of variables that no longer need to be - read or written. - """ - - tbl = {} +# {{{ variable to last dependent statement mapping + +#def var_to_last_dependent_statement_mapping(names, functions): +# +# """Return a mapping of each variable to the +# latest statement in the topological order at which +# that variable is used. This is used for intermediate +# deallocation of variables that no longer need to be +# read or written. +# """ +# +# tbl = {} +# +# from dagrt.codegen.dag_ast import get_statements_in_ast +# +# for name, func in zip(names, functions): +# +# for statement in get_statements_in_ast(func): +# # Associate latest statement in this phase at which +# # a given variable is used +# read_and_written = statement.get_read_variables().union( +# statement.get_written_variables()) +# for variable in read_and_written: +# tbl[variable, name] = statement.id +# +# return tbl + + +def var_to_last_dependent_statement_mapping(names, statement_lists): + + """Return a mapping of each variable to the + latest statement in the topological order at which + that variable is used. This is used for intermediate + deallocation of variables that no longer need to be + read or written. + """ - from dagrt.codegen.dag_ast import get_statements_in_ast + tbl = {} - for name, func in zip(names, functions): + for name, stmts in zip(names, statement_lists): - for statement in get_statements_in_ast(func): - # Associate latest statement in this phase at which - # a given variable is used - read_and_written = statement.get_read_variables().union( - statement.get_written_variables()) - for variable in read_and_written: - tbl[variable, name] = statement.id + for statement in stmts: + # Associate latest statement in this phase at which + # a given variable is used + read_and_written = statement.get_read_variables().union( + statement.get_written_variables()) + for variable in read_and_written: + tbl[variable, name] = statement.id - return tbl + return tbl # }}} diff --git a/dagrt/codegen/fortran.py b/dagrt/codegen/fortran.py index ed94b33..e577548 100644 --- a/dagrt/codegen/fortran.py +++ b/dagrt/codegen/fortran.py @@ -1046,7 +1046,8 @@ class CodeGenerator(StructuredCodeGenerator): # {{{ produce function name / function AST pairs - from dagrt.codegen.dag_ast import create_ast_from_phase + from dagrt.codegen.dag_ast import ( + create_ast_from_phase, get_statements_in_ast) from collections import namedtuple NameASTPair = namedtuple("NameASTPair", "name, ast") # noqa @@ -1066,12 +1067,16 @@ class CodeGenerator(StructuredCodeGenerator): from dagrt.codegen.analysis import ( collect_ode_component_names_from_dag, - var_to_last_dependent_statement_table) + var_to_last_dependent_statement_mapping) component_ids = collect_ode_component_names_from_dag(dag) - self.var_dep_table = var_to_last_dependent_statement_table( + + self.last_used_stmt_table = var_to_last_dependent_statement_mapping( [fd.name for fd in fdescrs], - [fd.ast for fd in fdescrs]) + [get_statements_in_ast(fd.ast) for fd in fdescrs]) + #self.last_used_stmt_table = var_to_last_dependent_statement_mapping( + # [fd.name for fd in fdescrs], + # [fd.ast for fd in fdescrs]) if not component_ids <= set(self.user_type_map): raise RuntimeError("User type missing from user type map: %r" @@ -1150,7 +1155,10 @@ class CodeGenerator(StructuredCodeGenerator): self.current_function, {}) for identifier, sym_kind in sorted(six.iteritems(sym_table)): - self.emit_variable_deinit(identifier, sym_kind) + try: + self.last_used_stmt_table[identifier, self.current_function] + except KeyError: + self.emit_variable_deinit(identifier, sym_kind) # }}} @@ -2121,7 +2129,7 @@ class CodeGenerator(StructuredCodeGenerator): for ident, start, stop in inst.loops[::-1]: self.emitter.__exit__(None, None, None) - self.intermediate_deallocation(inst) + self.emit_deinit_if_no_longer_used(inst) assert start_em is self.emitter @@ -2200,7 +2208,7 @@ class CodeGenerator(StructuredCodeGenerator): + assignee_fortran_names ))) - self.intermediate_deallocation(inst) + self.emit_deinit_if_no_longer_used(inst) # }}} @@ -2241,7 +2249,7 @@ class CodeGenerator(StructuredCodeGenerator): (var(self.component_name_to_component_sym( inst.component_id)),))) - def intermediate_deallocation(self, inst): + def emit_deinit_if_no_longer_used(self, inst): # Deallocate if done with intermed. quantities from dagrt.utils import is_state_variable @@ -2257,8 +2265,9 @@ class CodeGenerator(StructuredCodeGenerator): except KeyError: continue - test_id = self.var_dep_table[variable, self.current_function] - if inst.id == test_id and not is_state_variable(variable): + last_used_stmt_id = self.last_used_stmt_table[ + variable, self.current_function] + if inst.id == last_used_stmt_id and not is_state_variable(variable): self.emit_variable_deinit(variable, var_kind) def emit_inst_Raise(self, inst): -- GitLab From 279149e02a3d3fcd95f70f85fb03008777e90338 Mon Sep 17 00:00:00 2001 From: Cory Mikida Date: Thu, 14 Jun 2018 13:12:40 -0500 Subject: [PATCH 5/7] Remove a bunch of commented code (whoops), fix some small errors, improve documentation --- dagrt/codegen/analysis.py | 39 ++++++++------------------------------- dagrt/codegen/fortran.py | 14 +++++--------- 2 files changed, 13 insertions(+), 40 deletions(-) diff --git a/dagrt/codegen/analysis.py b/dagrt/codegen/analysis.py index ba36640..9f26237 100644 --- a/dagrt/codegen/analysis.py +++ b/dagrt/codegen/analysis.py @@ -250,39 +250,16 @@ def collect_ode_component_names_from_dag(dag): # {{{ variable to last dependent statement mapping -#def var_to_last_dependent_statement_mapping(names, functions): -# -# """Return a mapping of each variable to the -# latest statement in the topological order at which -# that variable is used. This is used for intermediate -# deallocation of variables that no longer need to be -# read or written. -# """ -# -# tbl = {} -# -# from dagrt.codegen.dag_ast import get_statements_in_ast -# -# for name, func in zip(names, functions): -# -# for statement in get_statements_in_ast(func): -# # Associate latest statement in this phase at which -# # a given variable is used -# read_and_written = statement.get_read_variables().union( -# statement.get_written_variables()) -# for variable in read_and_written: -# tbl[variable, name] = statement.id -# -# return tbl - - def var_to_last_dependent_statement_mapping(names, statement_lists): - """Return a mapping of each variable to the - latest statement in the topological order at which - that variable is used. This is used for intermediate - deallocation of variables that no longer need to be - read or written. + """For each function in names, return a mapping of each variable to the + latest statement in statement_lists at which that variable is used. + This is used for intermediate deallocation of variables that no longer + need to be read or written. + + :arg names: a list of function names in the ast. + :arg statement_lists: a set of topological orderings of the statements + in each function. """ tbl = {} diff --git a/dagrt/codegen/fortran.py b/dagrt/codegen/fortran.py index e577548..b15c3ec 100644 --- a/dagrt/codegen/fortran.py +++ b/dagrt/codegen/fortran.py @@ -1074,9 +1074,6 @@ class CodeGenerator(StructuredCodeGenerator): self.last_used_stmt_table = var_to_last_dependent_statement_mapping( [fd.name for fd in fdescrs], [get_statements_in_ast(fd.ast) for fd in fdescrs]) - #self.last_used_stmt_table = var_to_last_dependent_statement_mapping( - # [fd.name for fd in fdescrs], - # [fd.ast for fd in fdescrs]) if not component_ids <= set(self.user_type_map): raise RuntimeError("User type missing from user type map: %r" @@ -1155,9 +1152,7 @@ class CodeGenerator(StructuredCodeGenerator): self.current_function, {}) for identifier, sym_kind in sorted(six.iteritems(sym_table)): - try: - self.last_used_stmt_table[identifier, self.current_function] - except KeyError: + if (identifier, self.current_function) not in self.last_used_stmt_table: self.emit_variable_deinit(identifier, sym_kind) # }}} @@ -2250,11 +2245,12 @@ class CodeGenerator(StructuredCodeGenerator): inst.component_id)),))) def emit_deinit_if_no_longer_used(self, inst): - # Deallocate if done with intermed. quantities + """Check if a given inst is the last use of + a variable. If so, deallocate that variable. + """ from dagrt.utils import is_state_variable - read_and_written = inst.get_read_variables().union( - inst.get_written_variables()) + read_and_written = inst.get_read_variables() | inst.get_written_variables() for variable in read_and_written: # FIXME: This can fail for args of state update notification, -- GitLab From c580962075d7137e3beda551e860822a17cd86d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kl=C3=B6ckner?= Date: Thu, 14 Jun 2018 15:31:03 -0400 Subject: [PATCH 6/7] Minor naming/formatting tweaks to deinit-after-last-use changes --- dagrt/codegen/analysis.py | 3 +-- dagrt/codegen/fortran.py | 11 ++++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dagrt/codegen/analysis.py b/dagrt/codegen/analysis.py index 9f26237..8d61bc1 100644 --- a/dagrt/codegen/analysis.py +++ b/dagrt/codegen/analysis.py @@ -251,7 +251,6 @@ def collect_ode_component_names_from_dag(dag): # {{{ variable to last dependent statement mapping def var_to_last_dependent_statement_mapping(names, statement_lists): - """For each function in names, return a mapping of each variable to the latest statement in statement_lists at which that variable is used. This is used for intermediate deallocation of variables that no longer @@ -259,7 +258,7 @@ def var_to_last_dependent_statement_mapping(names, statement_lists): :arg names: a list of function names in the ast. :arg statement_lists: a set of topological orderings of the statements - in each function. + in each function. """ tbl = {} diff --git a/dagrt/codegen/fortran.py b/dagrt/codegen/fortran.py index b15c3ec..dea1906 100644 --- a/dagrt/codegen/fortran.py +++ b/dagrt/codegen/fortran.py @@ -2124,7 +2124,7 @@ class CodeGenerator(StructuredCodeGenerator): for ident, start, stop in inst.loops[::-1]: self.emitter.__exit__(None, None, None) - self.emit_deinit_if_no_longer_used(inst) + self.emit_deinit_for_last_usage_of_vars(inst) assert start_em is self.emitter @@ -2203,7 +2203,7 @@ class CodeGenerator(StructuredCodeGenerator): + assignee_fortran_names ))) - self.emit_deinit_if_no_longer_used(inst) + self.emit_deinit_for_last_usage_of_vars(inst) # }}} @@ -2244,9 +2244,10 @@ class CodeGenerator(StructuredCodeGenerator): (var(self.component_name_to_component_sym( inst.component_id)),))) - def emit_deinit_if_no_longer_used(self, inst): - """Check if a given inst is the last use of - a variable. If so, deallocate that variable. + def emit_deinit_for_last_usage_of_vars(self, inst): + """Check if, for any of the variables in instruction *inst*, + *inst* contains the last use of that variable in the + :attr:`current_function`. If so, emit code to deallocate that variable. """ from dagrt.utils import is_state_variable -- GitLab From b850ec424028056250f0b2c8ca9d4a356a28e413 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kl=C3=B6ckner?= Date: Thu, 14 Jun 2018 15:36:06 -0400 Subject: [PATCH 7/7] Remove trailing whitespace --- dagrt/codegen/fortran.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dagrt/codegen/fortran.py b/dagrt/codegen/fortran.py index dea1906..535779c 100644 --- a/dagrt/codegen/fortran.py +++ b/dagrt/codegen/fortran.py @@ -2246,7 +2246,7 @@ class CodeGenerator(StructuredCodeGenerator): def emit_deinit_for_last_usage_of_vars(self, inst): """Check if, for any of the variables in instruction *inst*, - *inst* contains the last use of that variable in the + *inst* contains the last use of that variable in the :attr:`current_function`. If so, emit code to deallocate that variable. """ from dagrt.utils import is_state_variable -- GitLab