Error : Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above.
in case you passed the cudnn test [https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html#verify], yet still facing the same problem for Theano:
in ~/.theanorc, ensure you have:
[cuda]
root=/usr/local/cuda/bin
[dnn]
include_path=/usr/local/cuda/include
library_path=/usr/local/cuda/lib64
cd /usr/local/cuda/include
sudo cp /usr/include/cudnn.h .
cd /usr/local/cuda/lib64
sudo cp /usr/lib/x86_64-linux-gnu/libcudnn* .
python -c 'import theano'
Using cuDNN version 7103 on context None
Mapped name None to device cuda: GeForce GTX 1080 Ti (0000:02:00.0)
passed.
Error (theano.gpuarray): could not initialize pygpu, support disabled
1) Clean-up:
theano-cache purge
2) Install:
#conda install numpy scipy mkl-service libpython m2w64-toolchain nose
#pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git
#conda install pygpu
#REM Create a new conda env named "python2" with python 2.7
conda create -n python2 python=2
#REM activate python2
activate python2
#REM Then install basic required packages for Theano
conda install numpy scipy mkl-service libpython m2w64-toolchain
#REM Now install theano and pygpu
conda install theano pygpu
#conda install theano=0.9.0
#REM And check if all is OK.
import theano, pygpu, numpy
print(theano.__version__, pygpu.__version__, numpy.__version__)
#REM If all is OK, consider using this conda env ("python2") for your works.
#REM You can deactivate it at anytime:
deactivate
#REM If you want to delete the env, be sure it is deactivated and then run:
conda remove --all -n python2
3) Modify backend:
"image_data_format": "channels_first"
"backend": "theano"
#https://github.com/keras-team/keras/blob/master/keras/backend/common.py#L111
4) Configure to use GPU:
[global]
device=cuda
floatX = float32
optimizer_including=cudnn
openmp=False
allow_input_downcast=True
cxx=C:Anaconda2Librarymingw-w64bing++.exe
[dnn]
enabled=True
include_path=C:Program FilesNVIDIA GPU Computing ToolkitCUDAv8.0include
library_path=C:Program FilesNVIDIA GPU Computing ToolkitCUDAv8.0libx64
[cuda]
root = C:Program FilesNVIDIA GPU Computing ToolkitCUDAv8.0
5) Test http://deeplearning.net/software/theano/tutorial/using_gpu.html
from theano import function, config, shared, sandboximporttheano.tensorasfrom theano import function, config, shared, sandbox
import theano.tensor as T
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([], T.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, T.Elemwise) for x in f.maker.fgraph.toposort()]):
print('Used the cpu')
else:
print('Used the gpu')
Sources:
https://github.com/Theano/libgpuarray/issues/264
https://github.com/Theano/Theano/issues/5831
https://github.com/Theano/Theano/issues/5838
https://zhuanlan.zhihu.com/p/26473699