June 18, 2016

Install CUDA on Ubuntu 16.04

For the record, my graphic card is a GTX 870M.

  1. Install Nvidia recommended drivers. You can find it out by using the command ubuntu-drivers devices. It will tell you the recommended driver you should install via apt-get (I installed nvidia-361).

2.Restart

3.Download CUDA Toolkit from here or Direct link to version 5.7.18 I used

  1. Run the file

./cuda_7.5.18_linux.run

Make sure to say yes to everything EXCEPT the prompt that reads:

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 352.39? ((y)es/(n)o/(q)uit): n

  1. Run the tests. Go to the folder you installed the Nvidia tests (default is /~/NVIDIA_CUDA-7.5_Samples). Then change one line (

And do make

You can test by doing nvcc -V

  1. Install Theano

`pip install theano´

  1. Add CUDA PATHS to .bashrc:
# CUDA
export PATH="/usr/local/cuda-7.5/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda-7.5/lib64:$LD_LIBRARY_PATH" 
export GLPATH=/usr/lib
  1. Run a theano test. As per theano’s Docs, you can use a test file like this:
# theano_test.py
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')```


THEANO_FLAGS=“mode=FAST_RUN,device=gpu,floatX=float32,nvcc.flags=-D_FORCE_INLINES” python theano_test.py ```

Profit.

Powered by Hugo & Kiss.