提交 202718ba authored 作者: Frederic Bastien's avatar Frederic Bastien

added the theano.gof.destroyhandler.fast_inplace_check() fct that allow to…

added the theano.gof.destroyhandler.fast_inplace_check() fct that allow to pre-check is an op can be done inplace or not. It don't check all condition.
上级 b65faccd
...@@ -198,3 +198,20 @@ input(s)'s memory). From there, go to the previous section. ...@@ -198,3 +198,20 @@ input(s)'s memory). From there, go to the previous section.
by using :ref:`DebugMode`. *Be sure to use DebugMode when developing by using :ref:`DebugMode`. *Be sure to use DebugMode when developing
a new Op that uses ``view_map`` and/or ``destroy_map``.* a new Op that uses ``view_map`` and/or ``destroy_map``.*
Inplace optimization and DebugMode
==================================
It is recommended that during the graph construction, all op are not inplace.
Then an optimization replace them with an inplace one. Currently DebugMode check
all optimization that was tryed even if they got rejected. One reason an inplace
optimization can get rejected is that their is another op that already do an
inplace on the same input. A second reason to reject an inplace optimization is
if it introduce cycle into the graph.
To allow using DebugMode more often, we can pre-check that our optimization will
get rejected in many case.(not the cycle reason). For this you can use the
theano.gof.destroyhandler.fast_inplace_check() function that will tell you witch
op can be used.
.. _optdb:
...@@ -158,6 +158,23 @@ def get_impact(root, view_o): ...@@ -158,6 +158,23 @@ def get_impact(root, view_o):
add_impact(root, view_o, impact) add_impact(root, view_o, impact)
return impact return impact
def fast_inplace_check(inputs):
""" Return the variables in inputs that are posible candidate for as inputs of inplace operation
:type inputs: list
:param inputs: inputs Variable that you want to use as inplace destination
"""
env = inputs[0].env
protected_inputs = [f.protected for f in env._features if isinstance(f,theano.compile.function_module.Supervisor)]
protected_inputs = sum(protected_inputs,[])#flatten the list
protected_inputs.extend(env.outputs)
inputs = [i for i in inputs if
not isinstance(i,gof.Constant)
and not env.destroyers(i)
and i not in protected_inputs]
return inputs
class DestroyHandlerHelper2(toolbox.Bookkeeper): class DestroyHandlerHelper2(toolbox.Bookkeeper):
""" """
The DestroyHandlerHelper2 class detects when a graph is impossible to evaluate because of The DestroyHandlerHelper2 class detects when a graph is impossible to evaluate because of
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论