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

added check for gpuarray

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