提交 f0ebe1f8 authored 作者: Frederic Bastien's avatar Frederic Bastien

Do not introduce GpuElemwise when the op do not have c code.

上级 a63fe4a1
...@@ -748,6 +748,8 @@ def local_gpua_elemwise(op, context_name, inputs, outputs): ...@@ -748,6 +748,8 @@ def local_gpua_elemwise(op, context_name, inputs, outputs):
scal_op) scal_op)
if not have_cuda: if not have_cuda:
return None return None
if not scal_op.supports_c_code(inputs, outputs):
return
res = GpuElemwise(scal_op, name=name, res = GpuElemwise(scal_op, name=name,
inplace_pattern=copy.copy(op.inplace_pattern), inplace_pattern=copy.copy(op.inplace_pattern),
nfunc_spec=op.nfunc_spec) nfunc_spec=op.nfunc_spec)
......
...@@ -1124,6 +1124,38 @@ class ScalarOp(Op): ...@@ -1124,6 +1124,38 @@ class ScalarOp(Op):
""" """
raise theano.gof.utils.MethodNotDefined() raise theano.gof.utils.MethodNotDefined()
def supports_c_code(self, inputs, outputs):
"""Returns True if the current op has functioning C code for
the given Elemwise inputs, outputs.
"""
try:
tmp_s_input = []
# To keep the same aliasing between inputs
mapping = dict()
for ii in inputs:
if ii in mapping:
tmp_s_input.append(mapping[ii])
else:
tmp = get_scalar_type(ii.dtype).make_variable()
tmp_s_input.append(tmp)
mapping[ii] = tmp_s_input[-1]
with theano.change_flags(compute_test_value='ignore'):
s_op = self(*tmp_s_input, return_list=True)
# if the scalar_op don't have a c implementation,
# we skip its fusion to allow the fusion of the
# other ops.
self.c_code(s_op[0].owner,
"test_presence_of_c_code",
["x" for x in inputs],
["z" for z in outputs],
{"fail": "%(fail)s"})
except (theano.gof.utils.MethodNotDefined, NotImplementedError):
return False
return True
class UnaryScalarOp(ScalarOp): class UnaryScalarOp(ScalarOp):
nin = 1 nin = 1
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论