CUDA 9.0 Installation

物体検出

Installing CUDA is a very torturous thing to do, so here are the steps I took to install CUDA successful (at least enough for Darknet YOLO Object Detection).

Resources

Linux - Ubuntu 16.04 (min 30Gb space)

CUDA 9.0 (maybe 9.3 too?)

Why so difficult?

Installing CUDA is painful because following the instruction given in the website itself will procure an error about X server. Googling on how to disable X server is worthy of another page by itself, and even after following all the instructions online (at least to the best of my ability) I still couldn't disable X server for the installation of CUDA 9.0. Thus, after much research(googling) and tears. I have come out with a method of installing CUDA without needing to disable X server

BEFORE YOU CONTINUE

Checklist: (if you could not tick any close this page and abandond all hope)

Do you have a Nvidia Graphics card?

Is your card CUDA capable?

Check here

Do you wish to suffer from frustration and hair lost(from pulling it)?

If your answer to above is all yes, you may proceed...

WARNING: I do not take personal responsibility in your quest to install CUDA. If installation does not work, I will not be held responsible!

Flow of installation

Normally, if you just google CUDA 9.0 toolkit, you will come across a website by Nvidia providing CUDA 9.0 Toolkit download. After providing info of your operating system and versions, you can finally download the file and realised that you cannot install it. The file that is provided by Nvidia is a bundle of:

1. Nvidia card driver
2. CUDA toolkit itself
3. Sample CUDA files

The installation of the card driver is what cause the X server error, so if you can install the card driver separately..... yeah (PROBLEM = SOLVE). If you know what to do after this, then good for you, if not, follow along what I did

WHAT YOU WILL NEED

CUDA 9.0 toolkit from Nvidia (get the .run file) (just google it)

thats all you need to download separately, anything else could be done from the linux terminal itself

Installing: Nvidia Card Driver

Open up terminal and add the official Nvidia PPA to Ubuntu

sudo add-apt-repository ppa:graphics-drivers/ppa

Next, install nvidia driver

sudo apt update
sudo apt install nvidia-387
Note: For G8x, G9x and GT2xx GPUs use `nvidia-340` (340.104)
For NV4x and G7x GPUs use `nvidia-304` (304.137)

Reboot your system after driver installation

sudo reboot

Next, verify if driver is properly installed

nvidia-smi

If verification is correct, proceed

Installing: CUDA Toolkit 9.0 and Sample

Open Terminal in the same location where you install your CUDA .run file(the one that you install above)

NOTE:Right click on the folder and select "Open in Terminal" to open terminal directly in that path

install the .run file

sudo sh [name of cuda installation file].run

change the code above accordingly

An EULA will appear, scroll to the bottom of it to continue

NOTE: Pressing [d] will scroll faster

Accept the EULA

READ THE INSTRUCTION AND DO NOT INSTALL THE NVIDIA DRIVER (already installed above)

Say YES('y') to everything else

After installing, run the following

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

I don't know what the above does, but just do it...

Test CUDA Installation

Make the sample file

cd /usr/local/cuda-9.0/samples
sudo make
NOTE:If it looks stuck DON'T PANIC, mine took pretty long too...

Test it!

cd /usr/local/cuda/samples/bin/x86_64/linux/release
./deviceQuery

If everything goes well, then CONGRATULATION!!!! YOU DID IT!!!

Setting CUDA up

Next, will just be some path thingy to configure CUDA properly

export PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}}

And the next is Operating System sensitive, so for 64-bit run

export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64\
{LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

For 32-bit

export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib\
{LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

And you are done. xD

Troubleshooting

It will be sad if you are reading this, but if you are still determined to install CUDA, here are the website that I used when installing mine

https://gist.github.com/zhanwenchen/e520767a409325d9961072f666815bb8

https://websiteforstudents.com/install-proprietary-nvidia-gpu-drivers-on-ubuntu-16-04-17-10-18-04/

https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#pre-installation-actions

If all else fails, just GoOglE it ;)