Articles

An Introduction to GPU computing (CUDA) on Porteus

This is meant as an introduction on how to do some serious number crunching on the GPU using Porteus and the CUDA programming framework. We will start from the very basics, ie how to set up everything and all the way to compiling some simple examples.This post will be updated as needed. However, please keep in mind that for any questions related to CUDA programming itself you should use the NVIDIA forum instead.

1) Requirements
2) Download the necessary files
3) Installation of the framework and the SDK
4) Build the shared libs
5) Do some tests
6) Have some fun!

All the tests during the writing of this post were performed on an HP dv8-1190eo laptop running Porteusx64, 8GB RAM with a Geforce 230M GT graphics card.

1) Requirements

i) A laptop/PC running Porteus
ii) Some familiarity with C/C++ and programming in general (can't help you in this!)
iii) A supported  NVIDIA graphics card. The i486 version of the driver can be found here, and the x64 version of the driver can be found here.

If you are not sure whether your card is supported, a quick way to check is to see if your laptop or PC has an NVIDIA sticker that says something like: "GEFORCE with CUDA" or  just go to
http://www.nvidia.com/object/cuda_gpus.html and check if your card is supported.  

2) Download the necessary files (take care to download the x64 versions where available)
You will need the following files freely available from NVIDIA's site:
http://developer.nvidia.com/object/gpucomputing.html
http://developer.nvidia.com/object/cuda_3_2_downloads.html

The NVIDIA driver found at the Porteus site includes the CUDA driver, so you only need to download the Toolkit and the SDK.

i) Grab the CUDA toolkit (it's the Fedora version, but it works OK):
http://www.nvidia.com/object/thankyou.html?url=/compute/cuda/3_2_prod/toolkit/cudatoolkit_3.2.16_linux_64_fedora13.run

ii) Grab the SDK:
http://developer.download.nvidia.com/compute/cuda/3_2_prod/sdk/gpucomputingsdk_3.2.16_linux.run
The SDK contains tons of examples and it is vital if you want to do any serious work.

iii) Grab any extra Guides or Libraries you want. The GPU-accelerated LAPACK libraries could be useful but it will cover that in a future post.

3) Installation of the framework and the SDK

In order to install the files open a console in the folder where you downloaded them and type:

  sh ./cudatoolkit_3.2.16_linux_64_fedora13.run

The command above will install the toolkit. When prompted choose the recommended path. You can of course choose a different one, but that complicates thing

 sh ./gpucomputingsdk_3.2.16_linux.run

The command above will install the SDK. Again when prompted choose the recommended path. You might get a couple of warnings during the installation (I did) but everything should be OK.

iii) Go to your .bash_profile file (it is hidden in your Home folder) and add the following lines:


PATH=$PATH:/usr/local/cuda/bin

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64

export PATH

export LD_LIBRARY_PATH


and yes there is some redundancy but not including some of the lines might give some errors during the tests. Anyway, remember to change lib64 to just lib if you have the x32 version.

iv) REBOOT!!!

4) Build the shared and common libs
i) After the reboot, go to:
/root/NVIDIA_GPU_Computing_SDK/shared/

Type make to build the shared libs. These are not necessary to use CUDA, but they are required for the examples. The result should be a lib: libshrutil_x86_64.a in the lib folder.

ii) Go to:
/root/NVIDIA_GPU_Computing_SDK/C/common/
Type

make

to build the common libs. Again, this is not necessary for CUDA, just the examples. The result should be a lib: libcutil_x86_64.a in the lib folder.

5) Do some tests
The folder /root/NVIDIA_GPU_Computing_SDK/C/src/ contains the examples.
So, go to the folder named bandwidthTest/ and in a console type

make

This will build the example and if no errors have occured a binary will have been created in /root/NVIDIA_GPU_Computing_SDK/C/bin/linux/release/ ,  so go to this folder and run the binary bandwidthTest. The result should be something like:

--------------------------------------------------------------
./bandwidthTest Starting...
 Running on...
 
 Device 0: GeForce GT 230M
 Quick Mode
 
 Host to Device Bandwidth, 1 Device(s), Paged memory
 Transfer Size (Bytes)    Bandwidth(MB/s)
 33554432            3354.7
 
 Device to Host Bandwidth, 1 Device(s), Paged memory
 Transfer Size (Bytes)    Bandwidth(MB/s)
 33554432            3855.3
 
 Device to Device Bandwidth, 1 Device(s)
 Transfer Size (Bytes)    Bandwidth(MB/s)
 33554432            20571.4
 
 [bandwidthTest] - Test results:
 PASSED
--------------------------------------------------------------

The critical part is where is says PASSED which obviously means that everything is working OK.

6) Have some fun!

Try compiling some of the other examples, but keep in mind that some of them have extra requirements, like the OpenGL lib etc.

Report any problems or questions in this thread:
http://forum.porteus.org/viewtopic.php?f=39&t=376