Prefer Your Language

Search This Blog

Showing posts with label Installation. Show all posts

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 

Installation Process ; How to install CUDA in Windows





How to Install and Configure CUDA on Windows


NVIDIA CUDA Zone
CUDA is NVIDIA’s relatively mature API for data parallel GPU computing. I already explainedthe benefits of CUDA and even showed a simple code example. Now, you surely want to try it out yourself. This guide will explain how to correctly install and configure CUDA on Windows.

0. Make sure your computer can run CUDA

DirectX Properties
Find out which graphics card your computer has by going to the Run Dialog with Win+R and typing dxdiag. This will open the DirectX properties. Select the Display tab and it will tell you which card you have.
Next, go to NVIDIA’s list of CUDA-enabled products and search for you graphics card on the list. If you find it, you can run CUDA. All GeForce cards in the 8000 series or above in desktops and laptops as well as ION chipsets being used in new netbooks can run CUDA. Tesla and Quadro cards can also run CUDA. Check the list for your particular model just to make sure.
If your computer cannot run CUDA, you can still program and compile your projects in emulation mode, but it will be really slow.

1. Install Visual Studio 2008

Visual C++Visual C++ is arguably the best and the standard C++ IDE for Windows. You will need it to program and compile CUDA projects in Windows.
If you have 32-bit Windows, you can use Visual C++ 2008 Express Edition, which is free and works great for most projects.
If you have 64-bit Windows, you must use Visual Studio 2008 Professional, as the Express Edition does not compile to 64-bit binaries. If you’re a student, you can probably get it for free at Dreamspark. I’m not sure if Visual Studio 2008 Standard Edition works on 64-bit Windows. Please leave a comment if you can confirm this.

2. Install latest NVIDIA Driver

NVIDIA Driver Download
The driver is what lets you access all of your NVIDIA’s card latest features, including support for CUDA.
Go to NVIDIA’s Driver Download page, select your operating system and graphics card, and download the latest driver.
After installing the driver, you’ll have to restart your computer.

3. Install CUDA Toolkit and SDK

NVIDIA CUDA Download
The CUDA Toolkit will let you compile CUDA programs. The CUDA SDK contains sample projects that you can use when starting your own.
Go to NVIDIA’s CUDA Download page and select your OS. Next, download the correct version of the CUDA Toolkit and SDK for your system. Do not download the drivers on this page, you already downloaded the latest ones in the last step.
If you have a laptop, as of this writing the latest compatible version of CUDA is 2.2. Do not download 2.3, it will not work.
If you have a desktop, as of this writing the latest compatible version of CUDA is 2.3.

4. Try out the examples

CUDA SDK
Run the examples in the CUDA SDK to make sure everything works. In CUDA 2.2, search for NVIDIA CUDA SDK Browser in the Start Menu. In CUDA 2.3, search for NVIDIA GPU Computing SDK Browser. If they work, you have successfully installed the correct CUDA driver.

5. Test your setup by compiling an example

Compiling CUDA with Visual C++
Open the CUDA SDK folder by going to the SDK browser and choosing Files in any of the examples. Go to  the src (CUDA 2.3) or projects (CUDA 2.2) folder and then to one example. Open its Visual Studio 9.0 project in Visual C++. Compile it from scratch by choosing Build > Rebuild Solution.
Run it by choosing Debug > Start Without Debugging. If you are able to compile it without error, and it runs successfully, congratulations! You have correctly installed everything you need to develop with CUDA on Windows.

Visual Studio Settings 

Copy all files in -

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\extras\visual_studio_integration\rules

to directory -

C:\Program Files\Microsoft Visual Studio 9.0\VC\VCProjectDefaults

Now start Visual Studio 2008 and go to -

Tools -> Option -> Project and Solution -> VC++ Directory 

1. To the Executable files drop down add - 

    C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.0\C\common\bin
    C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\bin


2. To the Include files drop down add -

    C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.0\C\common\inc
    C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include


3. To the Library files drop down add -

    C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include
    C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.0\C\common\lib\x64


Now your visual studio environment is ready to build cuda projects.

For syntax highlighting 

Follow the steps here.
  • Copy usertype.dat from Program Files\NVIDIA Corporation\NVIDIA CUDA SDK\doc\syntax_highlighting\visual_studio_8 to Program Files\Microsoft Visual Studio 8\Common7\IDE.
  • Start Visual Studio and go to Tools -> Options -> Text Editor -> File Extension
  • In the extension box type "cu" and select "Microsoft Visual C++" in the drop down.
  • Restart.

Don't worry if your first step does't work, if you installed Visual studio before CUDA toolkit then only second step is needed.

What if it doesn't work?

If you followed this guide and CUDA still does not work, go back and make sure you installed the correct version of Visual Studio, drivers, toolkit and SDK. If it still does not work, leave a comment bellow and we’ll probably be able to help you. If you had problems installing CUDA but managed to solve them using a different method, also leave a comment sharing your solution.


Feel free to comment... 


Links
CUDA
NVIDIA’s list of CUDA-enabled products 
NVIDIA’s CUDA Download page
Visual C++ 2008 Express Edition,
NVIDIA’s Driver Download page,
Visual Studio 2008 Professional,

 References
Nvidia installation Guide 
How to install

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