提交 7ea29681 authored 作者: Frederic's avatar Frederic

Add the theano flag profiling.{n_apply,n_ops,min_memory_size}

上级 7f25e754
...@@ -286,6 +286,25 @@ import theano and print the config variable, as in: ...@@ -286,6 +286,25 @@ import theano and print the config variable, as in:
Do the vm/cvm linkers profile the optimization phase when compiling a Theano function? Do the vm/cvm linkers profile the optimization phase when compiling a Theano function?
It only work when profile=True. It only work when profile=True.
.. attribute:: profiling.n_apply
Positive int value, default: 20.
The number of apply node to print in the profiler output
.. attribute:: profiling.n_ops
Positive int value, default: 20.
The number of ops to print in the profiler output
.. attribute:: profiling.min_memory_size
Positive int value, default: 1024.
For the memory profile, do not print apply nodes if the size
of their outputs (in bytes) is lower then this.
.. attribute:: config.lib.amdlibm .. attribute:: config.lib.amdlibm
Bool value: either True or False Bool value: either True or False
......
...@@ -23,7 +23,8 @@ import time ...@@ -23,7 +23,8 @@ import time
import numpy import numpy
import theano import theano
from theano.configparser import AddConfigVar, BoolParam from theano.configparser import AddConfigVar, BoolParam, IntParam
import_time = time.time() import_time = time.time()
config = theano.config config = theano.config
...@@ -33,7 +34,23 @@ _atexit_print_file = sys.stderr ...@@ -33,7 +34,23 @@ _atexit_print_file = sys.stderr
AddConfigVar('profiling.time_thunks', AddConfigVar('profiling.time_thunks',
"""Time individual thunks when profiling""", """Time individual thunks when profiling""",
BoolParam(True)) BoolParam(True))
AddConfigVar('profiling.n_apply',
"Number of apply instances to print by default",
IntParam(20, lambda i: i > 0),
in_c_key=False)
AddConfigVar('profiling.n_ops',
"Number of ops to print by default",
IntParam(20, lambda i: i > 0),
in_c_key=False)
AddConfigVar('profiling.min_memory_size',
"""For the memory profile, do not print apply nodes if the size
of their outputs (in bytes) is lower then this threshold""",
IntParam(1024, lambda i: i >= 0),
in_c_key=False)
def _atexit_print_fn(): def _atexit_print_fn():
...@@ -42,7 +59,9 @@ def _atexit_print_fn(): ...@@ -42,7 +59,9 @@ def _atexit_print_fn():
printed = 0 printed = 0
for ps in _atexit_print_list: for ps in _atexit_print_list:
if ps.fct_callcount or ps.compile_time > 0: if ps.fct_callcount or ps.compile_time > 0:
ps.summary(file=_atexit_print_file) ps.summary(file=_atexit_print_file,
n_ops_to_print=config.profiling.n_ops,
n_apply_to_print=config.profiling.n_apply)
printed += 1 printed += 1
else: else:
print 'Skipping empty Profile' print 'Skipping empty Profile'
...@@ -74,7 +93,9 @@ def _atexit_print_fn(): ...@@ -74,7 +93,9 @@ def _atexit_print_fn():
else: else:
cum.optimizer_profile = None cum.optimizer_profile = None
cum.summary(file=_atexit_print_file) cum.summary(file=_atexit_print_file,
n_ops_to_print=config.profiling.n_ops,
n_apply_to_print=config.profiling.n_apply)
atexit.register(_atexit_print_fn) atexit.register(_atexit_print_fn)
...@@ -729,7 +750,7 @@ class ProfileStats(object): ...@@ -729,7 +750,7 @@ class ProfileStats(object):
items = node_mem.items() items = node_mem.items()
items.sort(key=lambda a: a[1]) items.sort(key=lambda a: a[1])
items.reverse() items.reverse()
for node, node_outputs_size in items[:N]: for idx, (node, node_outputs_size) in enumerate(items[:N]):
code = ['c'] * len(node.outputs) code = ['c'] * len(node.outputs)
for out, inp in getattr(node.op, 'destroy_map', {}).iteritems(): for out, inp in getattr(node.op, 'destroy_map', {}).iteritems():
code[out] = "i" code[out] = "i"
...@@ -740,6 +761,9 @@ class ProfileStats(object): ...@@ -740,6 +761,9 @@ class ProfileStats(object):
if all([hasattr(out.type, 'get_size') if all([hasattr(out.type, 'get_size')
for out in node.outputs]): for out in node.outputs]):
size = "%9dB" % node_outputs_size size = "%9dB" % node_outputs_size
if node_outputs_size < config.profiling.min_memory_size:
N = idx
break
else: else:
size = "%10s" % "Unknown" size = "%10s" % "Unknown"
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论