提交 8e42f3f9 authored 作者: Roy Xue's avatar Roy Xue

1. extend node_cleard_order in another allow_gc loop in ../gof/vm.py

2. add count_running_memory method to take places of 2 loops in ../compile/profiling.py 3. add new_order's memory value in Store the max stats
上级 49966686
...@@ -628,6 +628,33 @@ class ProfileStats(object): ...@@ -628,6 +628,33 @@ class ProfileStats(object):
max_running_max_memory_size = 0 max_running_max_memory_size = 0
max_node_memory_saved_by_view = 0 max_node_memory_saved_by_view = 0
max_node_memory_saved_by_inplace = 0 max_node_memory_saved_by_inplace = 0
def count_running_memory(order, old_storage):
for node in order:
val = nodes_mem[node]
dmap = getattr(node.op, 'destroy_map', None)
vmap = getattr(node.op, 'view_map', None)
for idx, v in enumerate(val):
# TODO check the op returned a view
if dmap and idx in dmap:
node_memory_saved_by_inplace += v
# TODO check the op returned a view
elif vmap and idx in vmap:
node_memory_saved_by_view += v
elif not isinstance(v, str):
node_memory_size += v
running_memory_size += v
if running_memory_size > running_max_memory_size:
running_max_memory_size = running_memory_size
old_storage = post_thunk_old_storage[order.index(node)]
for old_s in old_storage:
old_v = var_mem[node.inputs[old_s]]
if not isinstance(old_v, str):
running_memory_size -= old_v
return node_memory_size, running_memory_size, running_max_memory_size, node_memory_saved_by_inplace, node_memory_saved_by_view
for fgraph, nodes_mem in fct_memory.iteritems(): for fgraph, nodes_mem in fct_memory.iteritems():
# Sum of the size of all variables in bytes # Sum of the size of all variables in bytes
sum_size = sum([sum([v for v in val if not isinstance(v, str)]) sum_size = sum([sum([v for v in val if not isinstance(v, str)])
...@@ -665,12 +692,6 @@ class ProfileStats(object): ...@@ -665,12 +692,6 @@ class ProfileStats(object):
# after the execution of the corresponding node. # after the execution of the corresponding node.
# It mean that after executing the node, # It mean that after executing the node,
# the corresponding variable can be gc. # the corresponding variable can be gc.
new_order = fgraph.profile.node_executed_order
# A list of new executed node order
new_storage = fgraph.profile.node_cleared_order
# A list of variables that get freed
post_thunk_old_storage = [] post_thunk_old_storage = []
computed, last_user = theano.gof.link.gc_helper(order) computed, last_user = theano.gof.link.gc_helper(order)
for node in order: for node in order:
...@@ -680,58 +701,24 @@ class ProfileStats(object): ...@@ -680,58 +701,24 @@ class ProfileStats(object):
if (input in computed) and if (input in computed) and
(input not in fgraph.outputs) and (input not in fgraph.outputs) and
node == last_user[input]]) node == last_user[input]])
for node in order: node_memory_size, running_memory_size, running_max_memory_size, node_memory_saved_by_view, node_memory_saved_by_inplace = count_running_memory(order, post_thunk_old_storage)
val = nodes_mem[node]
dmap = getattr(node.op, 'destroy_map', None)
vmap = getattr(node.op, 'view_map', None)
for idx, v in enumerate(val): new_order = fgraph.profile.node_executed_order
# TODO check the op returned a view # A list of new executed node order
if dmap and idx in dmap: new_storage = fgraph.profile.node_cleared_order
node_memory_saved_by_inplace += v # A list of variables that get freed
# TODO check the op returned a view
elif vmap and idx in vmap:
node_memory_saved_by_view += v
elif not isinstance(v, str):
node_memory_size += v
running_memory_size += v
if running_memory_size > running_max_memory_size:
running_max_memory_size = running_memory_size
old_storage = post_thunk_old_storage[order.index(node)]
for old_s in old_storage:
old_v = var_mem[node.inputs[old_s]]
if not isinstance(old_v, str):
running_memory_size -= old_v
for node in new_order:
val = nodes_mem[node]
dmap = getattr(node.op, 'destroy_map', None)
vmap = getattr(node.op, 'view_map', None)
for idx, v in enumerate(val): new_node_memory_size, new_running_memory_size, new_running_max_memory_size, new_node_memory_saved_by_view, new_node_memory_saved_by_inplace = count_running_memory(new_order, new_storage)
if dmap and idx in dmap:
new_node_memory_saved_by_inplace += v
elif vmap and idx in vmap:
new_node_memory_saved_by_view += v
elif not isinstance(v, str):
new_node_memory_size += v
new_running_memory_size += v
if new_running_memory_size > new_running_max_memory_size:
new_running_max_memory_size = new_running_memory_size
for new_s in new_storage:
new_v = var_mem[node.inputs[new_s]]
if not isinstance(new_v, str):
new_running_memory_size -= new_v
# Store the max of some stats by any function in this profile. # Store the max of some stats by any function in this profile.
max_sum_size = max(max_sum_size, sum_size) max_sum_size = max(max_sum_size, sum_size)
max_node_memory_size = max(max_node_memory_size, node_memory_size) max_node_memory_size = max(max_node_memory_size, node_memory_size, new_node_memory_size)
max_running_max_memory_size = max(max_running_max_memory_size, max_running_max_memory_size = max(max_running_max_memory_size,
running_max_memory_size) running_max_memory_size, new_running_max_memory_size)
max_node_memory_saved_by_view = max(max_node_memory_saved_by_view, max_node_memory_saved_by_view = max(max_node_memory_saved_by_view,
node_memory_saved_by_view) node_memory_saved_by_view, new_node_memory_saved_by_view)
max_node_memory_saved_by_inplace = max( max_node_memory_saved_by_inplace = max(
max_node_memory_saved_by_inplace, node_memory_saved_by_inplace) max_node_memory_saved_by_inplace, node_memory_saved_by_inplace, new_node_memory_saved_by_inplace)
del fgraph, nodes_mem, post_thunk_old_storage, node del fgraph, nodes_mem, post_thunk_old_storage, node
......
...@@ -521,6 +521,7 @@ class Stack(VM): ...@@ -521,6 +521,7 @@ class Stack(VM):
for v in storage_map: for v in storage_map:
if v.owner and not v in self.outputs: if v.owner and not v in self.outputs:
storage_map[v][0] = None storage_map[v][0] = None
self.node_cleared_order.append(storage_map[v])
try: try:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论