提交 30d8150c authored 作者: Olivier Delalleau's avatar Olivier Delalleau

PEP8

上级 3db224ef
...@@ -1236,20 +1236,21 @@ class OpWiseCLinker(link.LocalLinker): ...@@ -1236,20 +1236,21 @@ class OpWiseCLinker(link.LocalLinker):
self.no_recycling = no_recycling self.no_recycling = no_recycling
return self return self
def make_all(self, profiler = None, input_storage = None, output_storage = None): def make_all(self, profiler=None, input_storage=None, output_storage=None):
# The lock will be acquired when we compile the first # The lock will be acquired when we compile the first
# C code. We will keep the lock untill all the function # C code. We will keep the lock untill all the function
# compilation will be finished. This allow to don't # compilation will be finished. This allow to don't
# require the lock when all c code are already compiled! # require the lock when all c code are already compiled!
orig_n_lock = getattr(get_lock,"n_lock",0) orig_n_lock = getattr(get_lock, "n_lock", 0)
try: try:
env = self.env env = self.env
order = env.toposort() order = env.toposort()
no_recycling = self.no_recycling no_recycling = self.no_recycling
input_storage, output_storage, storage_map = link.map_storage(env, order, input_storage, output_storage) input_storage, output_storage, storage_map = link.map_storage(
env, order, input_storage, output_storage)
if self.allow_gc: if self.allow_gc:
computed, last_user = link.gc_helper(order) computed, last_user = link.gc_helper(order)
post_thunk_old_storage = [] post_thunk_old_storage = []
...@@ -1267,7 +1268,7 @@ class OpWiseCLinker(link.LocalLinker): ...@@ -1267,7 +1268,7 @@ class OpWiseCLinker(link.LocalLinker):
# There are ops that don't have _op_use_c_code property # There are ops that don't have _op_use_c_code property
# for example ifelse (or any ops that come with their own # for example ifelse (or any ops that come with their own
# make_thunk # make_thunk
old_value = getattr(node.op,'_op_use_c_code', False) old_value = getattr(node.op, '_op_use_c_code', False)
try: try:
node.op._op_use_c_code = True node.op._op_use_c_code = True
thunks += [node.op.make_thunk(node, thunks += [node.op.make_thunk(node,
...@@ -1282,31 +1283,37 @@ class OpWiseCLinker(link.LocalLinker): ...@@ -1282,31 +1283,37 @@ class OpWiseCLinker(link.LocalLinker):
if self.allow_gc: if self.allow_gc:
post_thunk_old_storage.append([storage_map[input] post_thunk_old_storage.append([storage_map[input]
for input in node.inputs for input in node.inputs
if (input in computed) and (input not in env.outputs) and node == last_user[input]]) if ((input in computed) and
(input not in env.outputs) and
node == last_user[input])])
if no_recycling is True: if no_recycling is True:
no_recycling = storage_map.values() no_recycling = storage_map.values()
no_recycling = utils.difference(no_recycling, input_storage) no_recycling = utils.difference(no_recycling, input_storage)
else: else:
no_recycling = [storage_map[r] for r in no_recycling if r not in env.inputs] no_recycling = [storage_map[r]
for r in no_recycling if r not in env.inputs]
f = link.streamline(env, thunks, order, f = link.streamline(env, thunks, order,
post_thunk_old_storage, post_thunk_old_storage,
no_recycling = no_recycling, no_recycling=no_recycling,
nice_errors = self.nice_errors) nice_errors=self.nice_errors)
f.allow_gc = self.allow_gc f.allow_gc = self.allow_gc
finally: finally:
# Release lock on compilation directory. # Release lock on compilation directory.
if getattr(get_lock,"n_lock",0) > orig_n_lock: if getattr(get_lock, "n_lock", 0) > orig_n_lock:
release_lock() release_lock()
assert get_lock.n_lock == orig_n_lock assert get_lock.n_lock == orig_n_lock
return f, [link.Container(input, storage) for input, storage in izip(env.inputs, input_storage)], \ return (f,
[link.Container(output, storage, True) for output, storage in izip(env.outputs, output_storage)], \ [link.Container(input, storage)
thunks, order for input, storage in izip(env.inputs, input_storage)],
[link.Container(output, storage, True)
for output, storage in izip(env.outputs, output_storage)],
thunks,
order)
def _default_checker(x, y): def _default_checker(x, y):
...@@ -1315,7 +1322,9 @@ def _default_checker(x, y): ...@@ -1315,7 +1322,9 @@ def _default_checker(x, y):
variables contain the same data using ==. variables contain the same data using ==.
""" """
if x[0] != y[0]: if x[0] != y[0]:
raise Exception("Output mismatch.", {'performlinker': x[0], 'clinker': y[0]}) raise Exception("Output mismatch.",
{'performlinker': x[0], 'clinker': y[0]})
class DualLinker(link.Linker): class DualLinker(link.Linker):
"""WRITEME """WRITEME
...@@ -1329,7 +1338,7 @@ class DualLinker(link.Linker): ...@@ -1329,7 +1338,7 @@ class DualLinker(link.Linker):
function. function.
""" """
def __init__(self, checker = _default_checker): def __init__(self, checker=_default_checker):
""" """
Initialize a DualLinker. Initialize a DualLinker.
...@@ -1355,10 +1364,11 @@ class DualLinker(link.Linker): ...@@ -1355,10 +1364,11 @@ class DualLinker(link.Linker):
self.env = None self.env = None
self.checker = checker self.checker = checker
def accept(self, env, no_recycling = []): def accept(self, env, no_recycling=[]):
if self.env is not None and self.env is not env: if self.env is not None and self.env is not env:
return type(self)(self.checker).accept(env, no_recycling) return type(self)(self.checker).accept(env, no_recycling)
#raise Exception("Cannot accept from a Linker that is already tied to another Env.") # raise Exception("Cannot accept from a Linker that is already "
# "tied to another Env.")
self.env = env self.env = env
self.no_recycling = no_recycling self.no_recycling = no_recycling
return self return self
...@@ -1368,16 +1378,20 @@ class DualLinker(link.Linker): ...@@ -1368,16 +1378,20 @@ class DualLinker(link.Linker):
env = self.env env = self.env
no_recycling = self.no_recycling no_recycling = self.no_recycling
_f, i1, o1, thunks1, order1 = link.PerformLinker().accept(env, no_recycling = no_recycling).make_all(**kwargs) _f, i1, o1, thunks1, order1 = link.PerformLinker().accept(env,
no_recycling=no_recycling).make_all(**kwargs)
kwargs.pop('input_storage', None) kwargs.pop('input_storage', None)
_f, i2, o2, thunks2, order2 = OpWiseCLinker().accept(env, no_recycling = no_recycling).make_all(**kwargs) _f, i2, o2, thunks2, order2 = OpWiseCLinker().accept(env,
no_recycling=no_recycling).make_all(**kwargs)
def f(): def f():
for input1, input2 in izip(i1, i2): for input1, input2 in izip(i1, i2):
# set the inputs to be the same in both branches # Set the inputs to be the same in both branches.
# the copy is necessary in order for inplace ops not to interfere # The copy is necessary in order for inplace ops not to
# interfere.
input2.storage[0] = copy(input1.storage[0]) input2.storage[0] = copy(input1.storage[0])
for thunk1, thunk2, node1, node2 in izip(thunks1, thunks2, order1, order2): for thunk1, thunk2, node1, node2 in izip(thunks1, thunks2,
order1, order2):
for output, storage in izip(node1.outputs, thunk1.outputs): for output, storage in izip(node1.outputs, thunk1.outputs):
if output in no_recycling: if output in no_recycling:
storage[0] = None storage[0] = None
...@@ -1387,7 +1401,8 @@ class DualLinker(link.Linker): ...@@ -1387,7 +1401,8 @@ class DualLinker(link.Linker):
try: try:
thunk1() thunk1()
thunk2() thunk2()
for output1, output2 in izip(thunk1.outputs, thunk2.outputs): for output1, output2 in izip(thunk1.outputs,
thunk2.outputs):
self.checker(output1, output2) self.checker(output1, output2)
except Exception: except Exception:
link.raise_with_op(node1) link.raise_with_op(node1)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论