7

OS : Ubuntu 14.04LTS
Language : Python Anaconda 2.7 (keras, theano)
GPU : GTX980Ti CUDA : CUDA 7.5

I wanna run keras python code on IPython Notebook by using my GPU(GTX980Ti)
But I can't find it.

I want to test below code. When I run it on to Ubuntu terminal, I command as below (It uses GPU well. It doesn't have any problem)

First I set the path like below

export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH 

Second I run the code as below

THEANO_FLAGS='floatX=float32,device=gpu0,nvcc.fastmath=True'  python myscript.py


And it runs well.

But when i run the code on pycharm(python IDE) or When I run it on Ipython Notebook, It doesn't use gpu. It only uses CPU

myscript.py code is as below.

from 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 xrange(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')

To solve it, I force the code use gpu as below (Insert two lines more on myscript.py)

import theano.sandbox.cuda
theano.sandbox.cuda.use("gpu0")

Then It generate the error like below

ERROR (theano.sandbox.cuda): nvcc compiler not found on $PATH. Check your nvcc installation and try again.

how to do it??? I spent two days..
And I surely did the way of using '.theanorc' file at home directory.

talonmies
  • 70,661
  • 34
  • 192
  • 269
user3704652
  • 303
  • 4
  • 6
  • 16
  • 1
    Have you double-checked that `nvcc` resides in `/usr/local/cuda/bin`? A different location may have been chosen during installation. When you print `PATH` from within Python, does it contain the path to `nvcc`? It may be picking up a different instance of the environment variable `PATH` than the one you added the `nvcc` location to. – njuffa Dec 17 '15 at 09:32
  • @talomies Thanky you for answering! – user3704652 Dec 17 '15 at 10:14
  • @talomies But I double check that there is nvcc in /usr/local/cuda/bin.... And /usr/local/cuda-7.5/bin also has nvcc.. Is there a problem with it?! – user3704652 Dec 17 '15 at 10:14
  • 1
    Have you put the two `export` commands into your `~/.bashrc` file? In particular `export PATH=/usr/local/cuda/bin:$PATH`. – Daniel Renshaw Dec 17 '15 at 11:55
  • @DanielRenshaw Hi! Thank you for answering! Yes I put two lines as below export PATH=/usr/local/cuda-7.5/bin:$PATH and other one is export LD_LIBRARY_PATH=/usr/local/cuda-7.5/lib64:$LD_LIBRARY_PATH – user3704652 Dec 17 '15 at 12:38
  • 1
    And restarted after doing so? – Daniel Renshaw Dec 17 '15 at 12:41
  • @Daniel Renshaw Sure. But It doesn't work... – user3704652 Dec 17 '15 at 13:46
  • If you `print os.environ["PATH"]` inside Python, does it include `/usr/local/cuda/bin`? – Daniel Renshaw Dec 20 '15 at 11:30
  • @Daniel Renshaw There is no cuda path! below one was printed /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games – user3704652 Dec 20 '15 at 12:32
  • @Daniel Renshaw Then How can I fix it?! I really appreciate with you that you consider the problem still now! :) – user3704652 Dec 20 '15 at 12:33
  • @Daniel Renshaw I fix it. And I add the path. And there is no error even more. But It still doesn't utilize the GPU.. T.T – user3704652 Dec 20 '15 at 14:15
  • Does it still report "nvcc compiler not found on $PATH"? – Daniel Renshaw Dec 20 '15 at 15:06
  • @Daniel Renshaw No. It doesn't any more. But it still don't use gpu on python IDE(pycharm) or IPython Notebook. (But It still work well when I run on command line) When I open the IDE, "g_dbus_connection_register_object: assertion 'G_IS_DBUS_CONNECTION (connection)' failed" Error occured. Does it has a relationship with GPU? – user3704652 Dec 20 '15 at 15:09
  • How do you know it's not using the GPU? What error message is it now reporting? The DBUS thing is probably unrelated to Theano. Please update question instead of adding more comments. – Daniel Renshaw Dec 20 '15 at 16:20
  • Did you initiate the ipython session with `THEANO_FLAGS=floatX=float32,device=gpu ipython`? Likewise, you can add THEANO_FLAGS as an enviroment variable to the interpreter in pycharm with the value set to the necessary string and the pycharm interpreter will set them before executing. – o1lo01ol1o Dec 23 '15 at 00:00
  • I don't know, maybe creating a kernel of ipython and setting there the THEANO_FLAGS variables in that json could help you to start your notebook with GPU as default – ssierral Feb 22 '16 at 21:59

1 Answers1

3

I'm using theano on an ipython notebook making use of my system's GPU. This configuration seems to work fine on my system.(Macbook Pro with GTX 750M)

My ~/.theanorc file :

[global]
cnmem = True
floatX = float32
device = gpu0

Various environment variables (I use a virtual environment(macvnev):

echo $LD_LIBRARY_PATH
/opt/local/lib:

echo $PATH
/Developer/NVIDIA/CUDA-7.5/bin:/opt/local/bin:/opt/local/sbin:/Developer/NVIDIA/CUDA-7.0/bin:/Users/Ramana/projects/macvnev/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

echo $DYLD_LIBRARY_PATH
/Developer/NVIDIA/CUDA-7.5/lib:/Developer/NVIDIA/CUDA-7.0/lib:

How I run ipython notebook (For me, the device is gpu0) :

$THEANO_FLAGS=mode=FAST_RUN,device=gpu0,floatX=float32 ipython notebook

Output of $nvcc -V :

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2015 NVIDIA Corporation
Built on Thu_Sep_24_00:26:39_CDT_2015
Cuda compilation tools, release 7.5, V7.5.19

From your post, probably you've set the $PATH variable wrong.

Sentient07
  • 1,270
  • 1
  • 16
  • 24