提交 50f66cc6 authored 作者: Reyhane Askari's avatar Reyhane Askari

added check for gpuarray

上级 6a087050
......@@ -13,6 +13,7 @@ from itertools import chain
import time
import warnings
import numpy as np
import pygpu
import theano
from theano import config, gof
......@@ -1693,7 +1694,9 @@ class FunctionMaker(object):
if self.sync:
for i, inp in enumerate(input_storage):
if i in self.fgraph.update_mapping.values():
inp.data.sync()
if (hasattr(theano, "gpuarray") and
isinstance(inp.data, pygpu.gpuarray.GpuArray)):
inp.data.sync()
fn.profile = self.profile
return fn
......
......@@ -909,28 +909,29 @@ def test_empty_givens_updates():
def test_sync():
x = T.fmatrix('x')
w = theano.shared(np.random.rand(300, 500).astype('float32'), 'w')
b = theano.shared(np.zeros((500)).astype('float32'), 'b')
y = T.dot(x, w) + b.dimshuffle('x', 0)
updates = [(w, w + T.sum(T.dot(x, w) +
T.dot(5 * x, 2 * w)))]
f = theano.function([x], y, updates=updates, sync=True)
g = theano.function([x], y, updates=updates, sync=False)
x_ = np.random.rand(100, 300).astype('float32')
f(x_)
g(x_)
t_0 = time.time()
for i in range(1000):
if theano.config.device == 'cuda':
x = T.fmatrix('x')
w = theano.shared(np.random.rand(300, 500).astype('float32'), 'w')
b = theano.shared(np.zeros((500)).astype('float32'), 'b')
y = T.dot(x, w) + b.dimshuffle('x', 0)
updates = [(w, w + T.sum(T.dot(x, w) +
T.dot(5 * x, 2 * w)))]
f = theano.function([x], y, updates=updates, sync=True)
g = theano.function([x], y, updates=updates, sync=False)
x_ = np.random.rand(100, 300).astype('float32')
f(x_)
t_1 = time.time()
for i in range(1000):
g(x_)
t_2 = time.time()
assert (t_1 - t_0) > (t_2 - t_1)
t_0 = time.time()
for i in range(1000):
f(x_)
t_1 = time.time()
for i in range(1000):
g(x_)
t_2 = time.time()
assert (t_1 - t_0) > (t_2 - t_1)
if __name__ == '__main__':
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论