提交 2cc09a3f authored 作者: Razvan Pascanu's avatar Razvan Pascanu

Changed DebugMode to allow ops that have their own make_thunk

(note : the implementation of make_thunk is seen by DebugMode as a python implementation, and it sees no C implementation for that Op. Are there checks for the C implementation that are not done for the python implementaion ? )
上级 74777739
...@@ -1183,36 +1183,46 @@ class _Linker(gof.link.LocalLinker): ...@@ -1183,36 +1183,46 @@ class _Linker(gof.link.LocalLinker):
thunks_py = [] #python thunks thunks_py = [] #python thunks
thunks_c = [] #c thunks thunks_c = [] #c thunks
compute_map = {}
for k in storage_map:
compute_map[k] = [k.owner is None]
for node in order: for node in order:
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]
try:
if not self.maker.mode.check_c_code:
raise utils.MethodNotDefined()
e = Env(*graph.clone(node.inputs, node.outputs))
e.toposort = lambda: e.nodes #WARNING: STOCHASTIC ORDER
# Specifically... e.nodes is a set, but of only 1 element
cl = CLinker().accept(e, [r for r, r2 in zip(e.outputs, node.outputs) if r2 in no_recycling])
thunk, node_input_filters, node_output_filters = cl.make_thunk(
input_storage = node_input_storage,
output_storage = node_output_storage)
thunk.inputs = node_input_storage
thunk.outputs = node_output_storage
thunks_c.append(thunk)
except (NotImplementedError, utils.MethodNotDefined): if hasattr(node.op, '_op_use_c_code'):
thunks_c.append(None) old_value = node.op._op_use_c_code
else:
old_value = False
try:
# ! Problem ! We do not know if make_thunk succedded into
# generating a cthunk, or if it reverted back to a python
# thunk, or if it is none of the above ...
node.op._op_use_c_code = True
tmp_thunk = node.op.make_thunk(node,
storage_map,
compute_map,
no_recycling)
if hasattr(tmp_thunk, 'cthunk'):
# Arbritrary check to see if it has a C implementation
thunks_c.append(tmp_thunk)
else:
thunks_c.append(None)
finally:
node.op._op_use_c_code = old_value
if self.maker.mode.check_py_code or thunks_c[-1] is None: if self.maker.mode.check_py_code or thunks_c[-1] is None:
p = node.op.perform try:
thunk = (lambda p = p, i = node_input_storage, o = node_output_storage, n = node.op._op_use_c_code = False
node: p(n, [x[0] for x in i], o)) thunks_py += [node.op.make_thunk(node,
thunk.inputs = node_input_storage storage_map,
thunk.outputs = node_output_storage compute_map,
thunk.perform = p no_recycling)]
thunks_py.append(thunk) finally:
node.op._op_use_c_code = old_value
else: else:
thunks_py.append(None) thunks_py.append(None)
...@@ -1233,6 +1243,11 @@ class _Linker(gof.link.LocalLinker): ...@@ -1233,6 +1243,11 @@ class _Linker(gof.link.LocalLinker):
# This is the function that runs when you evaluate the graph # This is the function that runs when you evaluate the graph
##### #####
def f(): def f():
####
# Note: `f` ignores the compute_map and evaluates the nodes in
# topological order. In some sense, this is ok, and can be used
# for now.
#####
_logger.debug("starting a DebugMode call") _logger.debug("starting a DebugMode call")
for x in no_recycling: for x in no_recycling:
x[0] = None x[0] = None
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论