Computation intensive applications which have high degree of data-level parallelism can very well harness the hardware capabilities provided a GPU. Enter the term GPGPU.

You might want to try out the Parallel Computing platform CUDA to gauge what kind of speed-up you can achieve in you current code by running it on a GPU. I wanted to use CUDA for one of my class projects but I do not have a compatible graphics card. Mine is an Intel Mobile 4 Series Chipset Integrated Graphics Controller, you can check yours using the command:

lspci | grep VGA

I spent a lot of time trying to install a GPU emulator but either I got stuck in some library dependency, or some of the downloaded packages were dependent on older gcc versions. The documentation online for installing emulators in systems which do not have a graphics card was insufficient. Finally, using few magical keywords in my Google search I located this blog entry which provided detailed installation procedure for the gpuocelot.

Here, I provide my version of the installation procedure to get a simple “Hello World” program up and running using GPGPU emulator.

  1. Download the “CUDA Toolkit for Ubuntu Linux 10.10” from here (v 4.0). Now start terminal (using ctrl + alt + t) and navigate to your Downloads directory. Change permissions for the installation file (mine was for 32bit) and install it. Hit enter if it asks for a change of destination directory.
    chmod +x ./cudatoolkit_4.0.17_linux_32_ubuntu10.10.run
    sudo ./cudatoolkit_4.0.17_linux_32_ubuntu10.10.run
    
  2. Next install gcc and g++ v4.4 and update alternatives and priorities for gcc versions
    sudo apt-get install gcc-4.4
    sudo apt-get install g++-4.4
    sudo update-alternatives \
    --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 40 \
    --slave /usr/bin/g++ g++ /usr/bin/g++-4.6
    sudo update-alternatives \
    --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 60 \
    --slave /usr/bin/g++ g++ /usr/bin/g++-4.4
    sudo update-alternatives --config gcc
    

    Now select the version 4.4 (usually item 0). Check the current version using

    gcc --version
    
  3. Now you need to update the paths in your bashrc file
    vi ~/.bashrc
    

    In vi editor enter “G” to go to the end of file, then “i” to add data. Copy paste the lines below

    export PATH=$PATH:/usr/local/cuda/bin
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib:/usr/local/lib
    export CPLUS_INCLUDE_PATH=/usr/local/cuda/include
    

    Now enter “:wq” to save and exit. Update the sources using

    source ~/.bashrc
    

    The CUDA setup is completed now and you can check using the command

    nvcc --version
    
  4. Next download the following files:
    libboost-filesystem1.42.0_1.42.0-4ubuntu2_i386.deb from here
    libboost-system1.42.0_1.42.0-4ubuntu2_i386.deb from here and
    libboost-thread1.42.0_1.42.0-4ubuntu2_i386.deb from here.
    I selected libboost-* in i386 (Release) and then downloaded the *.deb file below the Downloadable files section. Install by double clicking (it should open in the ubuntu software center, select install there).

  5. Finally, download gpuocelot from here. I chose ocelot_2.1.1272_i386.deb. Install by double clicking.

Hello World

  1. Navigate to your home directory and create a folder hellocuda. Download the configuration file from here and the Hello World program from here. Place both these files in the hellocuda directory. You may go through this page to understand the configuration file.

  2. Now compile the code

    nvcc -c hello.cu -arch=sm_20
    g++ -o hello.out hello.o `OcelotConfig -l`
    

    Next run it using

    ./hello.out
    

    This code computes the dot product of two vectors a and b using the GPU (in our case on the CPU using emulation) and stores the result in c. The final output shows the result of the computation performed using GPU and CPU respectively.