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(),))
我运行此代码与Python 3.5测试theano代码,如何使用GPU?
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的变量。 该文件说一个文件调用.theanorc,在我的主目录中,该文件不存在。我如何设置“设备”的价值? – babeyh
如果'THEANO_FLAGS'不存在,请创建它! –
'import theano' 'device ='gpu0'' 检查设备值 'print(theano.config.device)' 它又是'cpu'。 – babeyh