Theano 0.9 pygpu 0.6.9 anaconda2版本匹配问题,目前最新的theano是1.0rc版,刚开始安装了最新的版本(condainstall theano=0.9),匹配的pygpu是0.7.x版本,pygpu又跟cudnn版本不匹配,重复安装折腾了好久。
官网:http://deeplearning.net/software/theano/
找不到cudnn –lcudnn
在[dnn]中配置library_path之后就好了。
如果主机上安装了多个版本的编译器,要在配置文件中手动的指定用的是哪个编译器。不然会有Warning,看着很不舒服。
安装了cuda之后,就不要再制定device=gpu了,应该将device=cuda,或者device=cuda0
配置文件整理如下:
[global]
openmp=False
device=cuda
floatX=float32
allow_input_downcast=True
optimizer_including=cudnn
optimizer=None
cxx=C:\yf_program\Anaconda2\Library\mingw-w64\bin\g++.exe
[blas]
ldflags= -LC:\yf_program\Anaconda2\Library\bin
[gcc]
cxxflags=-IC:\yf_program\Anaconda2\MinGW
cxxflags=-IC:\yf_program\CUDA\cuda_development\include
[nvcc]
flags = -LC:\yf_program\Anaconda2\libs
compiler_bindir = C:\yf_program\VS2013\VC\bin\amd64
fastmath = True
flags=-arch=sm_30
[lib]
cnmem=0.8
[dnn]
enabled=True
include_path=C:\yf_program\CUDA\cuda_development\include
library_path=C:\yf_program\CUDA\cuda_development\lib\x64
[cuda]
root = C:\yf_program\CUDA\cuda_development\
测试代码的问题,网上比较旧的版本,我跑起来也能看到gpu已经在工作了,但是吐出来的结果仍然是”used the cpu”,好多人说要命令行的方式添加环境变量,配置文件中的不好用。
这个问题我也没有再详细追,直接使用了官网上比较新的代码,结果测试正常。
官网地址:http://deeplearning.net/software/theano/tutorial/using_gpu.html
from theano import function, config, shared, tensor
import numpy
import time
vlen = 10 * 30 * 768 # 10 x #cores x # threads per core
iters = 1000
rng = numpy.random.RandomState(22)
x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
f = function([], tensor.exp(x))
print(f.maker.fgraph.toposort())
t0 = time.time()
for i in range(iters):
r = f()
t1 = time.time()
print("Looping %d times took %f seconds" % (iters, t1 - t0))
print("Result is %s" % (r,))
if numpy.any([isinstance(x.op, tensor.Elemwise) and
('Gpu' not in type(x.op).__name__)
for x in f.maker.fgraph.toposort()]):
print('Used the cpu')
else:
print('Used the gpu')