Prefer Your Language

Search This Blog

Installation Process; How to install CUDA in Ubuntu 10.04 and 12.04



Installing CUDA 5 on Ubuntu 12.04



This post is aimed at CUDA 4.2 on Ubuntu 12.04. Although 12.10 is out, it’s not as stable as I would like it to be – I’d recommend sticking with Ubuntu 12.04 for development unless you have specific reasons to upgrade. With CUDA 5, Nvidia has greatly simplified the installation process for Linux, packaging the CUDA toolkit, the SDK and the development drivers all in a neat little package.
A few points before we begin though -
  1. As always, a working CUDA installation requires a CUDA capable card.
  2. Installing CUDA 5 will give you the option of opting for the development drivers or sticking with the regular ones. Personally, I chose the regular ones and they’ve worked out just fine (version 310.19 as of this writing).
STEP I – Driver installation (if you choose the regular drivers)
This section remains almost unchanged. Make sure the requisite tools are installed using the following command -
sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev
Next, blacklist the required modules (so that they don’t interfere with the driver installation) -
sudo nano /etc/modprobe.d/blacklist.conf
Add the following lines to the end of the file, one per line, and save it when done -
blacklist amd76x_edac
blacklist vga16fb
blacklist nouveau
blacklist rivafb
blacklist nvidiafb
blacklist rivatv
In order to get rid of any nVidia residuals, run the following command in a terminal -
sudo apt-get remove --purge nvidia*
This may take a while, so be patient. Once it’s done, reboot your machine. At the login screen, don’t login just yet. Press Ctrl+Alt+F1 to switch to a text-based login, and switch to the directory which contains the downloaded driver. Run the following commands -

sudo service lightdm stop
chmod +x NVIDIA*.run
where NVIDIA*.run is the full name of your driver. Next, start the installation with -

sudo ./NVIDIA*.run
Follow the onscreen instructions. If the installer throws up an error about nouveau still running, allow it to create a blacklist for nouveau, quit the installation and reboot. In that case, run the following commands again -

sudo service lightdm stop
sudo ./NVIDIA*.run
The installation should now proceed smoothly. When it asks you if you want the 32-bit libraries and if you want it to edit xorg.conf to use these drivers by default, allow both.
Reboot once the installation completes.
STEP II – CUDA toolkit installation
Download the CUDA toolkit (I used the Ubuntu 11.10 64-bit version). Navigate to the directory that contains the downloaded CUDA toolkit package, and run the following command -
chmod +x cuda*.run
sudo ./cuda*.run
where cuda*.run is the full name of the downloaded CUDA toolkit. Accept the license that appears. Next, choose to install the driver if you’ve not done so already (this is the development version). The CUDA 5.0 toolkit installation is compulsory, while that of the included samples isn’t. Allow the installer to proceed with default locations unless you have specific reasons for not doing so. This makes for easier troubleshooting in the future.
This process might take a while depending upon your system config. Once it’s done, double check the summary screen to make sure everything is in place. If the installation of the samples fails (which it does more often than not), it’s probably due to one or more missing libraries. In that case, install the required libraries and rerun the installer, choosing to install the samples alone.
To make sure the necessary environment variables (PATH and LD_LIBRARY_PATH) are modified every time you access a terminal, add the requisite lines (from the summary screen) to the end of ~/.bashrc as follows -
32 bit systems -
export PATH=$PATH:/usr/local/cuda-5.0/bin
export LD_LIBRARY_PATH=/usr/local/cuda-5.0/lib
64 bit systems -
export PATH=$PATH:/usr/local/cuda-5.0/bin
export LD_LIBRARY_PATH=/usr/local/cuda-5.0/lib64:/lib
The paths used above will vary based on the install directory you choose for the toolkit. This wraps up the arguably simpler setup (compared to CUDA 4.x for Linux users), although the samples’ installation still suffers from dependency hell.
STEP III – CUDA samples installation and troubleshooting
While the installation of the samples should be straightforward (simply run the all in one toolkit installer), it’s often not all that easy. If you’re getting an error similar to “Samples installation failed due to missing libraries – libglut.so not found”, it’s typically because the installer looks for libglut.so and not variants (like libglut.so.3). To fix this, we’ll have to create softlinks so the installer can track down these files.
Determine if variants of libglut.so are present as follows -
sudo find /usr -name libglut\*
On my 64-bit installation of Ubuntu 12.04, this output the following text -
/usr/lib/x86_64-linux-gnu/libglut.so.3
/usr/lib/x86_64-linux-gnu/libglut.so.3.9.0
/usr/lib/x86_64-linux-gnu/libglut.a
/usr/lib/x86_64-linux-gnu/libglut.so
Now that a variant of libglut.so (that is, libglut.so.3) has been found, we can create a softlink to it -
sudo ln -s /usr/lib/x86_64-linux-gnu/libglut.so.3 /usr/lib/libglut.so
Next, rerun the all in one installer choosing to install only the samples this time around. That should fix the “Missing libraries” error that cropped up previously.
Further reading resources can be found here if you’re looking for books on CUDA and GPGPU programming in general.
Credit for STEP III goes to these release notes (refer section III b – Known issues on CUDA Samples for Linux).



Installing CUDA 5 on Ubuntu 10.04

The following tutorial describes how to install Nvidia CUDA under Ubuntu 10.04. The described steps assume a freshly installed and security updated Ubuntu 10.04 - 64 bit. The setup has not been tested under the 32 bit version, but it should work. Please let us know if you experience any problems with Ubuntu 10.04 - 32 bit.

There are some problems installing and using CUDA 3.1 under Ubuntu 10.04, since that CUDA release only supports Ubuntu 9.10. Therefore, this tutorial describes installation of CUDA 3.2 RC2. The tutorial has not been updated for the final CUDA 3.2 release - please let me know if something does not work with the final CUDA 3.2 release. CUDA 3.2 can be found at http://developer.nvidia.com/object/c...downloads.html in stead of the link below. The driver version for the final CUDA 3.2 will be different than the one stated in this tutorial.

Steps are below 
  1. Download Nvidia driver and CUDA:
    1. Goto Nvidia's homepage http://developer.nvidia.com/object/cuda_3_2_toolkit_rc.html#Linux, the Linux section.
    2. Download and store the following files in a location on your computer that you can find again:
      1. "Developer Drivers for Linux (260.40)" (64 bit).
      2. "CUDA Toolkit for Ubuntu Linux 10.04" (64 bit).
      3. "GPU Computing SDK code samples".
        Optional - this will only be used for verification of the CUDA installation at the end.
  2. First get rid of any existing drivers that will interfere with the Nvidia development driver (as suggested, e.g., here http://ubuntuforums.org/showthread.php?p=9233555):
    1. Blacklist kernel modules:
      Code:
      gsudo gedit /etc/modprobe.d/blacklist.conf
      Add the following lines to the file: 
      Code:
      blacklist vga16fb
      blacklist nouveau
      blacklist rivafb
      blacklist nvidiafb
      blacklist rivatv
      Save and quit the editor.
    2. Get rid of any installed Nvidia drivers:
      Code:
      sudo apt-get --purge remove nvidia-*
  3. Reboot your PC.
  4. Go to a virtual terminal (we will need to shut down the X server):
    Code:
    CTRL+ALT+F5
    Some users have reported problems changing between virtual terminals in Ubuntu 10.04. If you have this problem, see the following solutionhttp://ubuntuforums.org/showthread.php?t=1473045.
  5. Login at the terminal and run:
    Code:
    sudo service gdm stop
  6. Install Nvidia development drivers:
    1. Go to the location where you stored the downloaded Nvidia files and run:
      Code:
      sudo devdriver_3.2_linux_64_260.24.run
      1. Accept the license agreement.
      2. Install NVIDIA's 32-bit compatibility OpenGL libraries?
        Answer 'Yes' - we don't know if this is actually necessary, but it does not seem to hurt...
      3. Would you like to run the nvidia-xconfig utility to automatically update your X configuration file so that the NVIDIA X driver will be used when you restart X?
        Answer 'Yes'.
  7. The driver should now be installed successfully. Now we install CUDA:
    1. Go to the location where you stored the downloaded Nvidia files and run:
      Code:
      sudo cudatoolkit_3.2.9_linux_64_ubuntu10.04.run
      1. Enter install path (default /usr/local/cuda, '/cuda' will be appended):
        Press enter to select default path or choose another location - this tutorial assumes you choose the default path.
  8. Set up environment variables:
    1. Set PATH:
      Code:
      gksudo gedit /etc/environment
      Append the path to the CUDA binaries. Change 
      Code:
      PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
      to
      Code:
      PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/cuda/bin"
      Save and quit the editor.
    2. Reload PATH:
      Code:
      source /etc/environment
    3. Set LD_LIBRARY_PATH:
      Code:
      gksudo gedit /etc/ld.so.conf.d/cuda.conf (creates a new file).
      Paste into the file: 
      Code:
      /usr/local/cuda/lib64
         /usr/local/cuda/lib
      Save and quit the editor.
    4. Reload LD_LIBRARY_PATH:
      Code:
      sudo ldconfig
  9. CUDA should now be installed and ready to run. If you wish, you can install the "GPU Computing SDK" and compile of the examples to verify that your installation works:
    1. Go to the location where you stored the downloaded Nvidia files and run:
      Code:
      gpucomputingsdk_3.2_linux.run
      1. Enter install path (default ~/NVIDIA_GPU_Computing_SDK):
        Press enter to select default path or choose another location - this tutorial assumes you choose the default path.
      2. Located CUDA at /usr/local/cuda
        If this is correct, choose the default below.
        If it is not correct, enter the correct path to CUDA

        Press enter to confirm.
    2. Install compiler:
      Code:
      sudo apt-get install g++
      1. Do you want to continue [Y/n]?
        Press enter to install dependencies.
    3. Repair broken link to libGL.so (http://ubuntuforums.org/showthread.php?t=409438):
      Code:
      sudo rm /usr/lib/libGL.so
      sudo ln -s /usr/lib/libGL.so.260.24 /usr/lib/libGL.so
    4. Create link to libXmu.so:
      Code:
      sudo ln -s /usr/lib/libXmu.so.6 /usr/lib/libXmu.so
    5. Install libraries necessary to compile CUDA code examples:
      Code:
      sudo apt-get install freeglut3-dev libxi-dev
      1. Do you want to continue [Y/n]?
        Press enter to install dependencies.
    6. Go to the GPU Computing SDK directory:
      Code:
      cd ~/NVIDIA_GPU_Computing_SDK/C
    7. Build code examples:
      Code:
      make
  10. The compiled examples can now be found under ~/NVIDIA_GPU_Computing_SDK/C/bin/linux/release/




Feel free to comment... 


 References
Nvidia installation Guide 
How to install

Guide
Ubuntu Form
CUDA 5
Youtube 

0 comments:

Help us to improve our quality and become contributor to our blog

Become a contributor to this blog. Click on contact us tab
Blogger Template by Clairvo