提交 a156506d authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Merge pull request #69 from nouiz/blas_opt_fix

Blas opt fix
......@@ -144,6 +144,7 @@ if __name__ == "__main__":
C1060/3.2 0.46s
GTX550Ti/4.0 0.57s
GT220/3.2RC 3.80s
GT210/4.0 6.35s
8500GT/3.0 10.68s
"""
......
......@@ -1114,14 +1114,27 @@ def _gemm_from_factored_list(lst):
"""
# Make every pair in list have matching dtypes
# sM can be a tuple of 2 elements or a theano variable.
# We should not use __len__ as theano variables don't support
# it. I don't want to change this to isinstance(sM, tuple)
# as I'm not able to make a test that triggers this case.
def is_pair(sM):
try:
s, M = sM
return True
except Exception:
return False
lst = [(T.cast(sM[0],sM[1].type.dtype), sM[1])
for sM in lst if is_pair(sM)]
lst2 = []
# Remove the tuple that can't be casted correctly.
# This can happen when we try to cast a complex to a real
for sM in lst:
if is_pair(sM):
sm0, sm1 = sM
sm0 = T.as_tensor_variable(sm0)
if theano.scalar.upcast(sm0.dtype, sm1.dtype) == sm1.dtype:
lst2.append((T.cast(sm0, sm1.dtype), sM[1]))
lst = lst2
# Try every pair in the sM_list, trying to turn it into a gemm operation
for i in xrange(len(lst) - 1):
......
......@@ -578,7 +578,24 @@ def test_upcasting_scalar_nogemm():
f = theano.function([w, v, t, alpha], rval)
t = f.maker.env.toposort()
assert numpy.sum([isinstance(n.op, Gemm) for n in t]) == 0
theano.printing.debugprint(f, print_type=True)
#theano.printing.debugprint(f, print_type=True)
v = T.fmatrix('v')
w = T.fmatrix('w')
t = T.fmatrix('t')
alpha = T.cscalar('a')
on_opt_error = config.on_opt_error
try:
config.on_opt_error = 'raise'
rval = T.dot(w, v) * alpha + t
f = theano.function([w, v, t, alpha], rval)
finally:
config.on_opt_error = on_opt_error
t = f.maker.env.toposort()
assert numpy.sum([isinstance(n.op, Gemm) for n in t]) == 0
#theano.printing.debugprint(f, print_type=True)
def test_gemm_nested():
X,Y,Z,a,b = T.dmatrix('X'), T.dmatrix('Y'), T.dmatrix('Z'), T.dscalar('a'), T.dscalar('b')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论