提交 600c40e7 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Restore basic profiling for Mode, since it is in its interface.

Always update the following properties of current mode, even if current function does not have profiling statistics: call_time, fn_time, optimizer_time, linker_time. Re-add these attributes in ProfileMode (they exist in Mode). This basic timing functionality is used in particular for timing the deep learning tutorials.
上级 9c5109ba
...@@ -594,8 +594,7 @@ class Function(object): ...@@ -594,8 +594,7 @@ class Function(object):
self.inv_finder[c])) self.inv_finder[c]))
# Do the actual work # Do the actual work
if profile: t0_fn = time.time()
t0_fn = time.time()
try: try:
self.fn() self.fn()
except: except:
...@@ -607,8 +606,11 @@ class Function(object): ...@@ -607,8 +606,11 @@ class Function(object):
else: else:
# old-style linkers raise their own exceptions # old-style linkers raise their own exceptions
raise raise
dt_fn = time.time() - t0_fn
self.maker.mode.fn_time += dt_fn
if profile: if profile:
profile.vm_call_time += time.time() - t0_fn profile.vm_call_time += dt_fn
# Retrieve the values that were computed # Retrieve the values that were computed
outputs = [x.data for x in self.output_storage] outputs = [x.data for x in self.output_storage]
...@@ -647,8 +649,9 @@ class Function(object): ...@@ -647,8 +649,9 @@ class Function(object):
# grep for 'PROFILE_CODE' # grep for 'PROFILE_CODE'
# #
dt_call = time.time() - t0
self.maker.mode.call_time += dt_call
if profile: if profile:
dt_call=time.time()-t0
profile.fct_callcount += 1 profile.fct_callcount += 1
profile.fct_call_time += dt_call profile.fct_call_time += dt_call
if hasattr(self.fn, 'update_profile'): if hasattr(self.fn, 'update_profile'):
...@@ -976,9 +979,12 @@ class FunctionMaker(object): ...@@ -976,9 +979,12 @@ class FunctionMaker(object):
end_optimizer = time.time() end_optimizer = time.time()
finally: finally:
theano.config.compute_test_value = compute_test_value_orig theano.config.compute_test_value = compute_test_value_orig
opt_time = end_optimizer - start_optimizer
mode.optimizer_time += opt_time
if profile: if profile:
profile.optimizer_time += end_optimizer - start_optimizer profile.optimizer_time += opt_time
_logger.debug('Optimizing took %f seconds' % (end_optimizer - start_optimizer)) _logger.debug('Optimizing took %f seconds', opt_time)
#Add deep copy to respect the memory interface #Add deep copy to respect the memory interface
insert_deepcopy(env, inputs, outputs+additional_outputs) insert_deepcopy(env, inputs, outputs+additional_outputs)
...@@ -1059,11 +1065,16 @@ class FunctionMaker(object): ...@@ -1059,11 +1065,16 @@ class FunctionMaker(object):
start_linker = time.time() start_linker = time.time()
_fn, _i, _o = self.linker.make_thunk(input_storage = input_storage_lists) _fn, _i, _o = self.linker.make_thunk(input_storage = input_storage_lists)
end_linker = time.time() end_linker = time.time()
_logger.debug('Linker took %f seconds' % (end_linker - start_linker))
linker_time = end_linker - start_linker
_logger.debug('Linker took %f seconds', linker_time)
self.mode.linker_time += linker_time
if self.profile: if self.profile:
self.profile.linker_time += end_linker - start_linker self.profile.linker_time += linker_time
_fn.time_thunks = self.profile.flag_time_thunks _fn.time_thunks = self.profile.flag_time_thunks
fn = self.function_builder(_fn, _i, _o, self.indices, self.outputs, defaults, self.unpack_single, self.return_none, self)
fn = self.function_builder(_fn, _i, _o, self.indices, self.outputs,
defaults, self.unpack_single, self.return_none, self)
fn.profile = self.profile fn.profile = self.profile
return fn return fn
......
...@@ -196,6 +196,11 @@ class ProfileMode(Mode): ...@@ -196,6 +196,11 @@ class ProfileMode(Mode):
optimizer = predefined_optimizers[optimizer] optimizer = predefined_optimizers[optimizer]
self._optimizer = optimizer self._optimizer = optimizer
self.call_time = 0
self.fn_time = 0
self.optimizer_time = 0
self.linker_time = 0
def print_summary(self,**kwargs): def print_summary(self,**kwargs):
""" Print 3 summary that show where the time is spend. The first show an Apply-wise summary, the second show an Op-wise summary, the third show an type-Op-wise summary. """ Print 3 summary that show where the time is spend. The first show an Apply-wise summary, the second show an Op-wise summary, the third show an type-Op-wise summary.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论