如果我使用Python 3.5运行以下代码:
我收到了输出
import numpy as np
import time
import theano
A = np.random.rand(1000,10000).astype(theano.config.floatX)
B = np.random.rand(10000,1000).astype(theano.config.floatX)
np_start = time.time()
AB = A.dot(B)
np_end = time.time()
X,Y = theano.tensor.matrices('XY')
mf = theano.function([X,Y],X.dot(Y))
t_start = time.time()
tAB = mf(A,B)
t_end = time.time()
print ("NP time: %f[s], theano time: %f[s] **(times should be close when run
on CPU!)**" %(np_end-np_start, t_end-t_start))
print ("Result difference: %f" % (np.abs(AB-tAB).max(), ))
我收到了输出
NP time: 0.161123[s], theano time: 0.167119[s] (times should be close when
run on CPU!)
Result difference: 0.000000
如果时间接近,这意味着我正在使用 CPU 运行代码。
如何在 GPU 上运行此代码?
注:
- 我有一台装有 Nvidia Quadro k4200 的工作站。
- 我已经安装了 Cuda 工具包。
- 我已经成功地在 VS2012 上运行了一个 cuda vectorAdd 示例项目。
THEANO_FLAGS
不存在,则创建它! - Daniel Renshawimport theano
device='gpu0'
检查设备值print(theano.config.device)
它又变成了 'cpu'。 - babeyhimport theano
时,会出现多个错误:( - babeyh