#使用CPU還是GPU依賴於你的.theanorc文件中定義的環境變量。
#當前,應該使用GPU定義的float32,但大多數人喜歡使用CPU定義的float64
#theano提供了配置變量floatX 來設置到底使用GPU還是CPU
#爲了看得清楚,我的電腦上的.theanorc文件內容列出來,內容如下:
'''
# 文件C:\Documents and Settings\sf\.theanorc.txt的內容如下,則設置成GPU
#設置完成後,需要註銷當前windows用戶重新登錄才能生效.
#sf是電腦上的用戶名。
[global]
openmp=False
floatX = float32
device = gpu0
[blas]
ldflags=
[gcc]
cxxflags = -IC:\MinGW\include
'''
源程序如下:
import theano
print theano.config.device
print theano.config.floatX
'''顯示內容爲
gpu0
float32
'''
'''
# 文件C:\Documents and Settings\sf\.theanorc.txt的內容修改如下,也即採用默認值:
[global]
openmp=False
[blas]
ldflags=
[gcc]
cxxflags = -IC:\MinGW\include
'''
'''
源程序如下:
print theano.config.device
print theano.config.floatX
'''
'''顯示內容爲
cpu
float64
'''
# 也可以在運行過程中 獲取和設置floatX的值
old_floatX = theano.config.floatX
theano.config.floatX = 'float64'
print theano.config.device
print theano.config.floatX