提交 27ee5379 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Allow nodes to have a 'debug' behaviour for DebugMode.

上级 e088e2a8
...@@ -1883,8 +1883,10 @@ class _Linker(gof.link.LocalLinker): ...@@ -1883,8 +1883,10 @@ class _Linker(gof.link.LocalLinker):
if new_node is not None: if new_node is not None:
node = new_node node = new_node
debug = hasattr(node.op, 'debug_perform')
try: try:
if not self.maker.mode.check_c_code: if not self.maker.mode.check_c_code or debug:
raise utils.MethodNotDefined() raise utils.MethodNotDefined()
# Ops that do not inherit from gof.op.Op don't have certain # Ops that do not inherit from gof.op.Op don't have certain
# methods defined that the CLinker expects (Scan is an # methods defined that the CLinker expects (Scan is an
...@@ -1902,18 +1904,18 @@ class _Linker(gof.link.LocalLinker): ...@@ -1902,18 +1904,18 @@ class _Linker(gof.link.LocalLinker):
# Pure ops don't really have a perform ( or their perform just # Pure ops don't really have a perform ( or their perform just
# raises an not implemented exception), so in those cases we # raises an not implemented exception), so in those cases we
# consider that we don't have a python implementation # consider that we don't have a python implementation
if (self.maker.mode.check_py_code or thunks_c[-1] is None) and \ if (((self.maker.mode.check_py_code or thunks_c[-1] is None) and
node.op.perform.__code__ != gof.op.PureOp.perform.__code__: node.op.perform.__code__ != gof.op.PureOp.perform.__code__) or
debug):
thunk = node.op.make_py_thunk(node, storage_map, compute_map, thunk = node.op.make_py_thunk(node, storage_map, compute_map,
no_recycling) no_recycling, debug=debug)
thunks_py.append(thunk) thunks_py.append(thunk)
else: else:
thunks_py.append(None) thunks_py.append(None)
if not self.maker.mode.check_c_code and thunks_py[-1] is None: if not self.maker.mode.check_c_code and thunks_py[-1] is None:
_logger.warn( _logger.warn("Op %s doesn't have a perform, "
"Op %s don't have a perform, forcing check of the c code" % "forcing check of the C code" % node.op)
node.op)
thunk = node.op.make_c_thunk(node, storage_map, compute_map, thunk = node.op.make_c_thunk(node, storage_map, compute_map,
no_recycling) no_recycling)
thunks_c[-1] = thunk thunks_c[-1] = thunk
......
...@@ -1186,11 +1186,13 @@ class CLinker(link.Linker): ...@@ -1186,11 +1186,13 @@ class CLinker(link.Linker):
List of lists of length 1. In order to use List of lists of length 1. In order to use
the thunk returned by __compile__, the inputs must be put in the thunk returned by __compile__, the inputs must be put in
that storage. If None, storage will be allocated. that storage. If None, storage will be allocated.
@param output_storage: list of lists of length 1. The thunk returned output_storage: list of lists of length 1.
by __compile__ will put the variables of the computation in these The thunk returned by __compile__ will put the variables
lists. If None, storage will be allocated. of the computation in these lists. If None, storage will
@param storage_map: dict that map variables to storages. This is used be allocated.
when you need to customize the storage of this thunk. storage_map: dict that map variables to storages.
This is used when you need to customize the storage of
this thunk.
Returns: thunk, input_storage, output_storage Returns: thunk, input_storage, output_storage
......
...@@ -890,7 +890,8 @@ class Op(utils.object2, PureOp, CLinkerOp): ...@@ -890,7 +890,8 @@ class Op(utils.object2, PureOp, CLinkerOp):
rval.lazy = False rval.lazy = False
return rval return rval
def make_py_thunk(self, node, storage_map, compute_map, no_recycling): def make_py_thunk(self, node, storage_map, compute_map, no_recycling,
debug=False):
""" """
Like make_thunk() but only makes python thunks. Like make_thunk() but only makes python thunks.
...@@ -898,6 +899,9 @@ class Op(utils.object2, PureOp, CLinkerOp): ...@@ -898,6 +899,9 @@ class Op(utils.object2, PureOp, CLinkerOp):
node_input_storage = [storage_map[r] for r in node.inputs] node_input_storage = [storage_map[r] for r in node.inputs]
node_output_storage = [storage_map[r] for r in node.outputs] node_output_storage = [storage_map[r] for r in node.outputs]
if debug:
p = node.op.debug_perform
else:
p = node.op.perform p = node.op.perform
params = node.run_params() params = node.run_params()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论