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