I am trying to make Theano use the gpu on my Linux machine. It works from the command line, but not from Pycharm. Both are using Python 3.5 from the same folder of my machine.
I am testing this script:
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')
If I run it from the command line, it works fine:
THEANO_FLAGS=device=cuda0 /home/jon/anaconda3/bin/python check_theano_cuda.py
Looping 1000 times took 0.840969 seconds
Result is [ 1.23178032 1.61879341 1.52278065 ..., 2.20771815 2.29967753
1.62323285]
Used the gpu
If I run it from PyCharm, I get this error:
ERROR (theano.gpuarray): Could not initialize pygpu, support disabled
Traceback (most recent call last):
File "/home/jon/anaconda3/lib/python3.5/site-packages/theano/gpuarray/__init__.py", line 164, in <module>
use(config.device)
File "/home/jon/anaconda3/lib/python3.5/site-packages/theano/gpuarray/__init__.py", line 151, in use
init_dev(device)
File "/home/jon/anaconda3/lib/python3.5/site-packages/theano/gpuarray/__init__.py", line 60, in init_dev
sched=config.gpuarray.sched)
File "pygpu/gpuarray.pyx", line 614, in pygpu.gpuarray.init (pygpu/gpuarray.c:9419)
File "pygpu/gpuarray.pyx", line 566, in pygpu.gpuarray.pygpu_init (pygpu/gpuarray.c:9110)
File "pygpu/gpuarray.pyx", line 1021, in pygpu.gpuarray.GpuContext.__cinit__ (pygpu/gpuarray.c:13472)
pygpu.gpuarray.GpuArrayException: Error loading library: 0
In PyCharm, I have modified the run configuration's environment variables to device=cuda0, which I was hoping would duplicate what is happening from the command line version. But that doesn't work.
I have tried making a file at ~/.theanorc file, but it does not work. It contained:
[global] device = cuda0 floatX = float32
What else could I try to make this work? My installation must be OK as it runs from the command line.