Tuesday, March 28, 2017

Install/Upgrade NVIDI Driver in Ubuntu for CUDA SDK


Most linux distribution comes with the Nouveau https://nouveau.freedesktop.org/wiki/ display driver configured. If you need to use NVIDIA CUDA libray in you application, example OpenCV with GPU support, then you need to install NVIDIA proprietary driver.

There is a NVIDIA-Linux-x86_64-375.39.run file  from NVIDIA; I have never got the driver updated properly with this. Even if the driver is updated, the GUI never comes up; I guess this is something to do with configuring the Xorg with this.

The thing which works consistenly in Ubuntu is given below.
In ArchLLinux /Manjaro I tried https://wiki.archlinux.org/index.php/bumblebee but could not get the display configured properly

Step 1 (Ubuntu 16.04)

Go to Additional Drivers and Select the Using NVIDIA Driver. with this you will have the nvidia-smi utility also and check the driver version



Tue Mar 28 12:06:06 2017       +------------------------------------------------------+                       | NVIDIA-SMI 340.102    Driver Version: 340.102        |                       |-------------------------------+----------------------+----------------------+| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC || Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. ||===============================+======================+======================||   0  GeForce GT 720M     Off  | 0000:01:00.0     N/A |                  N/A || N/A   50C    P0    N/A /  N/A |    570MiB /  2047MiB |     N/A      Default |+-------------------------------+----------------------+----------------------+                                                                               +-----------------------------------------------------------------------------+| Compute processes:                                               GPU Memory ||  GPU       PID  Process name                                     Usage      ||=============================================================================||    0            Not Supported                                               |+-----------------------------------------------------------------------------+

This Driver version 340 is not suitable to run CUDA applications.

For example assuming you have installed NVDIA CUDA SDK , and not updated the driver when prompted , your CUDA programs are going to faile with the error

h:~/Coding/opencv/build2/bin$ ./opencv_test_cudaarithm terminate called after throwing an instance of 'cv::Exception'  what():  /media/alex/LENOVO/Coding/opencv/sources/modules/core/src/cuda_info.cpp:85: error: (-217) CUDA driver version is insufficient for CUDA runtime version in function getDevice

Okay now we need to update driver; Please don't use any of the NVIDIA .run files to update the driver, as after that it will leave your display in an un-configured state usually


Example : Don't run $ sudo ./cuda_8.0.61_375.26_linux.run  -driver -silent or NVIDIA-Linux-x86_64-xx.xx.run, if you want a desktop or GUI.


Instead install from Ubuntu PPA repository.
sudo apt-add-repository ppa:graphics-drivers/ppasudo apt-get updatesudo apt-get install nvidia-375 

After this restart the machine and you may need to install and run nvidia-modprobe

Note : - If you are running on a server or if you don't need to configure the XServer with the driver you can use the NVIDIA run script.  Applicable for non Ubuntu systems.

Step 2 (Download and Install NVIDIA CUDA SDK)

Note: - I would suggest that you would use a docker container  instead of this: https://hub.docker.com/r/alexcpn/nvidia-opencv/tags/ the docker file is present in readme; or in github  - https://github.com/alexcpn/cuda_opencv.
You can build for your architecture or drop me a comment

From https://developer.nvidia.com/cuda-downloads for your machine (example  cuda_8.0.61_375.26_linux.run file)

It will ask you if you need to install the updated CUDA driver. Do not do that. If you are doing this from the GUI and select to install the driver it will fail as you need to stop the GUI. For that Cntl + Alt + F1 or F2) and sudo systemctl lightdm stop . (killing xserver will start it up again).After successful run you will get something like

***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 361.00 is required for CUDA 8.0 functionality to work.
To install the driver using this installer, run the following command, replacing with the name of this run file:

Good ,this is what we need. We don't want to install the driver

Now let us run nvidi-smi and check if your driver is updated

alex@alex-Lenovo-G400s-Touch:~$ nvidia-smiTue Mar 28 12:44:30 2017       +-----------------------------------------------------------------------------+| NVIDIA-SMI 375.39                 Driver Version: 375.39                    ||-------------------------------+----------------------+----------------------+| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC || Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. ||===============================+======================+======================||   0  GeForce GT 720M     Off  | 0000:01:00.0     N/A |                  N/A || N/A   47C    P8    N/A /  N/A |     93MiB /  1985MiB |     N/A      Default |+-------------------------------+----------------------+----------------------+                                                                               +-----------------------------------------------------------------------------+| Processes:                                                       GPU Memory ||  GPU       PID  Type  Process name                               Usage      ||=============================================================================||    0                  Not Supported                                         |+-----------------------------------------------------------------------------+

it is updated, and hopefully you are in the GUI environment.  Don't mind if Additional Drivers in Ubuntu is showing that this driver is not used.

Assuming you have compiled OpenCV with CUDA , let us run some test program and see if things are working;

/opencv_test_cudaarithm 

Here is the CMakeCache.txt file which you can reuse; Please change the architecture of the NVIDIA card from Fermi. CMakeCache.txt



No comments:

Install/Upgrade NVIDI Driver in Ubuntu for CUDA SDK

Most linux distribution comes with the Nouveau https://nouveau.freedesktop.org/wiki/ display driver configured. If you need to use NVIDIA...