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

Instead install from Ubuntu PPA repository.

sudo apt-add-repository ppa:graphics-drivers/ppa
sudo apt-get update
sudo apt-get install nvidia-375 
After this restart the machine

Step 2 (Download and Install NVIDIA CUDA SDK)

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). But don'd do that.  After sucessfull 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 CTEST_FULL_OUTPUTOpenCV version: 3.2.0OpenCV VCS version: 975b64d-dirtyBuild type: releaseParallel framework: pthreadsCPU features: mmx sse sse2 sse3Available options besides google test option: Usage: opencv_test_cudaarithm [params] --cuda_device (value:-1) CUDA device on which tests will be executed (-1 means all devices) -h, --help (value:false) Print help infoRun tests on all supported CUDA devices [----------][ GPU INFO ] Run on OS Linux x64.[----------]*** CUDA Device Query (Runtime API) version (CUDART static linking) *** Device count: 1Device 0: "GeForce GT 720M" CUDA Driver Version / Runtime Version 8.0 / 8.0 CUDA Capability Major/Minor version number: 2.1 Total amount of global memory: 1985 MBytes (2081685504 bytes) ( 2) Multiprocessors x (48) CUDA Cores/MP: 96 CUDA Cores GPU Clock Speed: 1.55 GHz Max Texture Dimension Size (x,y,z) 1D=(65536), 2D=(65536,65535), 3D=(2048,2048,2048) Max Layered Texture Size (dim) x layers 1D=(16384) x 2048, 2D=(16384,16384) x 2048 Total amount of constant memory: 65536 bytes Total amount of shared memory per block: 49152 bytes Total number of registers available per block: 32768 Warp size: 32 Maximum number of threads per block: 1024 Maximum sizes of each dimension of a block: 1024 x 1024 x 64 Maximum sizes of each dimension of a grid: 65535 x 65535 x 65535 Maximum memory pitch: 2147483647 bytes Texture alignment: 512 bytes Concurrent copy and execution: Yes with 0 copy engine(s) Run time limit on kernels: Yes Integrated GPU sharing Host Memory: No Support host page-locked memory mapping: Yes Concurrent kernel execution: Yes Alignment requirement for Surfaces: Yes Device has ECC support enabled: No Device is using TCC driver mode: No Device supports Unified Addressing (UVA): Yes Device PCI Bus ID / PCI location ID: 1 / 0 Compute Mode: Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 8.0, CUDA Runtime Version = 8.0, NumDevs = 1[==========] Running 0 tests from 0 test cases.[==========] 0 tests from 0 test cases ran. (0 ms total)[ PASSED ] 0 tests.

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...