提交 ccf4f75f authored 作者: Frederic's avatar Frederic

Added config flag profile_optimizer that allow to profile the optimizer.

上级 4922359b
...@@ -1049,13 +1049,15 @@ class FunctionMaker(object): ...@@ -1049,13 +1049,15 @@ class FunctionMaker(object):
theano.config.compute_test_value = "off" theano.config.compute_test_value = "off"
gof.Op.add_stack_trace_on_call = False gof.Op.add_stack_trace_on_call = False
start_optimizer = time.time() start_optimizer = time.time()
optimizer(env) optimizer_profile = optimizer(env)
end_optimizer = time.time() end_optimizer = time.time()
opt_time = end_optimizer - start_optimizer opt_time = end_optimizer - start_optimizer
mode.optimizer_time += opt_time mode.optimizer_time += opt_time
if profile: if profile:
profile.optimizer_time += opt_time profile.optimizer_time += opt_time
if theano.config.profile_optimizer:
profile.optimizer_profile = (optimizer, optimizer_profile)
_logger.debug('Optimizing took %f seconds', opt_time) _logger.debug('Optimizing took %f seconds', opt_time)
#Add deep copy to respect the memory interface #Add deep copy to respect the memory interface
......
...@@ -64,6 +64,15 @@ def _atexit_print_fn(): ...@@ -64,6 +64,15 @@ def _atexit_print_fn():
for key, val in getattr(ps, attr).iteritems(): for key, val in getattr(ps, attr).iteritems():
assert key not in cum_attr assert key not in cum_attr
cum_attr[key] = val cum_attr[key] = val
if cum.optimizer_profile and ps.optimizer_profile:
merge = cum.optimizer_profile[0].merge_profile(
cum.optimizer_profile[1],
ps.optimizer_profile[1])
cum.optimizer_profile = (cum.optimizer_profile[0], merge)
else:
cum.optimizer_profile = None
cum.summary(file=_atexit_print_file) cum.summary(file=_atexit_print_file)
...@@ -133,6 +142,9 @@ class ProfileStats(object): ...@@ -133,6 +142,9 @@ class ProfileStats(object):
line_width = 140 line_width = 140
optimizer_profile = None
# None or tuple (the optimizer, the profile it returned)
# param is called flag_time_thunks because most other attributes with time # param is called flag_time_thunks because most other attributes with time
# in the name are times *of* something, rather than configuration flags. # in the name are times *of* something, rather than configuration flags.
def __init__(self, atexit_print=True, flag_time_thunks=None, **kwargs): def __init__(self, atexit_print=True, flag_time_thunks=None, **kwargs):
...@@ -419,6 +431,10 @@ class ProfileStats(object): ...@@ -419,6 +431,10 @@ class ProfileStats(object):
elif self.fct_callcount > 0: elif self.fct_callcount > 0:
print >> file, (" No node time accumulated " print >> file, (" No node time accumulated "
"(hint: try config profiling.time_thunks=1)") "(hint: try config profiling.time_thunks=1)")
if self.optimizer_profile:
print "Optimizer Profile"
print "-----------------"
self.optimizer_profile[0].print_profile(file, self.optimizer_profile[1])
if 0: # old code still to be ported from ProfileMode if 0: # old code still to be ported from ProfileMode
......
差异被折叠。
...@@ -17,6 +17,9 @@ logger = logging.getLogger(__name__) ...@@ -17,6 +17,9 @@ logger = logging.getLogger(__name__)
AddConfigVar('profile', AddConfigVar('profile',
"If VM should collect profile information", "If VM should collect profile information",
BoolParam(False)) BoolParam(False))
AddConfigVar('profile_optimizer',
"If VM should collect optimizer profile information",
BoolParam(False))
raise_with_op = link.raise_with_op raise_with_op = link.raise_with_op
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论