[Documentation] [TitleIndex] [WordIndex

Installing CUDA 7.5 on Ubuntu 15.10 (nvidia 960M)

1. Install nvidia-drivers and reboot

sudo apt-get install nvidia-352-updates nvidia-modprobe
sudo reboot

2. Download the deb file from https://developer.nvidia.com/cuda-downloads

3. Install it using the following commands

sudo dpkg -i cuda-repo-ubuntu1504-7-5-local_7.5-18_amd64.deb 
sudo apt-get update
sudo apt-get install cuda

4. Add these lines to ~/.bashrc

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

5. Configure runtime library

sudo bash -c "echo /usr/local/cuda/lib64/ > /etc/ld.so.conf.d/cuda.conf"
sudo ldconfig

6. Since Ubuntu 15.10 comes with gcc/g++ of 5.2 version. We have to make cuda work with it, by default it won't. Some people suggest to install 4.9 and to link it with cuda-7.5. But this will cause linker issues in future reference1 reference2

7. Edit header file host_config.h

gedit /usr/local/cuda/include/host_config.h

as shown below, Comment line 115.

#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 9)


//#error -- unsupported GNU version! gcc 4.10 and up are not supported!                                       


#endif /* __GNUC__> 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 9) */

8. duplicate and compile cuda samples

rsync -av /usr/local/cuda/samples .

cd samples

make -j4

9. Run the sample example nbody simulation

cd 5_Simulations/nbody
./nbody -benchmark -numbodies=256000

Working with theano and cuda

1. Install Theano

sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ libopenblas-dev git
sudo pip install Theano

2. Add the following code to gpu_test.py

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 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')

3. See if gpu is used or not

python gpu_test.py

4. If not create a file ~/.theanorc with the following code

[blas]
ldflags =

[global] 
floatX = float32
device = gpu

# By default the compiled files were being written to my local network drive.
# Since I have limited space on this drive (on a school's network),
# we can change the path to compile the files on the local machine.
# You will have to create the directories and modify according to where you 
# want to install the files. 
# Uncomment if you want to change the default path to your own.
# base_compiledir = /local-scratch/jer/theano/

[nvcc]
fastmath = True

[gcc]
cxxflags = -ID:\MinGW\include

[cuda]
# Set to where the cuda drivers are installed.
# You might have to change this depending where your cuda driver/what version is installed.
root=/usr/local/cuda-7.5/

4. Now run

python gpu_test.py

You should see "gpu is used"

Installing Caffe

http://corpocrat.com/2014/11/03/how-to-setup-caffe-to-run-deep-neural-network/

Issue of hd5: https://github.com/BVLC/caffe/issues/2690

add

just modify the Makefile.config 
    +INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
    +LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial/

Installing Digits

http://www.andrewjanowczyk.com/how-to-install-nvidia-digits/

Issue of latlas https://github.com/BVLC/caffe/issues/559 Install libatlas-base-dev

sudo apt-get install libatlas-base-dev

Tensorflow with GPU

If you have to configure to different version of cuda then build from sources, else you could install directly

1. Clone latest tensorflow

git clone https://github.com/tensorflow/tensorflow.git

1a. Install coreutils using brew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install)"

PATH="$HOME/.linuxbrew/bin:$PATH"

brew install coreutils

2. Configure depending on your cuda and other needs after going into cloned directory https://www.tensorflow.org/install/install_sources#ConfigureInstallation

./configure

3. Build with bazel (gpu)

bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package

CPU only

bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package

If you haven't installed bazel

sudo apt-get install software-properties-common swig

sudo add-apt-repository ppa:webupd8team/java

sudo apt-get update

sudo apt-get install oracle-java8-installer

echo "deb http://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list

curl https://storage.googleapis.com/bazel-apt/doc/apt-key.pub.gpg | sudo apt-key add -

sudo apt-get update

sudo apt-get install bazel 

4. Install Tensorflow pip package

bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

sudo pip install /tmp/tensorflow_pkg/tensorflow-1.1.0rc1-cp27-cp27mu-linux_x86_64.whl

5. Upgrade Protobuf

sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/protobuf-3.0.0b2.post2-cp27-none-linux_x86_64.whl

2024-11-16 14:45