About Me

My photo
A Computer Enthusiast who's learning as much as I can, while attempting to share and re-distribute the knowledge! Enjoy! :D

Sunday, October 30, 2011

CUDA on Linux and OS X Lion - Updated

I wrote a quickstart sometime last year for CUDA on Linux and OS X. Here's an updated version covering CUDA 4.0 for Linux and OS X Lion. I will be installing the Toolkit and Example in my home directory. However, feel free to deviate and install in the normal system directories. Additionally, I'm using 64-bit version rather than 32-bit.

Please refer to NVIDIA's CUDA website to confirm your video card is CUDA ready. You can also check it here.

1.  Unless you have the proprietary NVIDIA Drivers already installed, download the appropriate Developer Drivers from here. Click on "Get Latest CUDA Toolkit".

2. Install the drivers as root. If you've installed Proprietary NVIDIA drivers before, the process is the same (for Linux).

Linux:
//**********
  • Ctrl-Alt-F2
  • Log in as root (as yourself on Ubuntu)
  • Stop your window manager: telinit 3 usually does it. For Ubuntu, try sudo service gdm stop (this assumes your running GNOME).
  • Become root (if not already) or utilize sudo for Ubuntu
  • Navigate to the directory where you've downloaded the NVIDIA graphic drivers
  • Run sh dev_driver_name.run. Try sudo sh dev_driver_name.run
//**********
 OS X:
//**********
  • Run devdriver.dmg
//**********

3. Download and install CUDA Toolkit.

Linux:
//**********

shell$ cd Downloads
shell$ sh cudatoolkit.run

For "enter install path", I used my home directory: /home/myname. You may utilize default path if needed.

//**********

OS X:
//**********
  • Run cudatoolkit.pkg
//**********

4. Update your PATH and LD_LIBRARY_PATH:

Linux:
//**********

PATH - /Path/To/Your/CUDA/Install/bin (my version --> /home/myname/cuda/bin)
LD - /Path/To/Your/CUDA/Install/lib (my version --> /home/myname/cuda/lib64:/home/myname/cuda/lib)

//**********

OS X:
//**********

PATH - /usr/local/cuda/bin
DYLD - /usr/local/cuda/lib

//**********

5. Download and install GPU Computing SDK

Linux:
//**********

shell$ cd Downloads
shell$ sh gpucomputingsdk.run

For "enter install path", I accepted the default. This is dependent upon where your CUDA Toolkit is installed. Additionally, you will be asked to confirm your CUDA installation directory.

//**********

OS X:
//**********
  • Run  gpucomputingsdk.pkg
//**********

6. Make the example programs.

Linux:
//**********

shell$ cd NVIDIA_GPU_Computing_SDK
shell$ cd C
shell$ make

//**********

OS X:
//**********

shell$ cd /Developer/GPU\ Computing/C
shell$ make

//**********

You have a fully functional CUDA environment. Run a few of the example programs to test your environment. Good luck!

Thursday, October 27, 2011

OpenMPI Quickstart - Updated

I wrote a quickstart sometime last year for OpenMPI on Linux. Here's an update for OpenMPI for Linux and OS X Lion.

1. Download the latest openmpi source files:
 2. Find out how many processors are available to utilize (optional).

Linux:
//**********

shell$ grep 'processor.*:' /proc/cpuinfo | wc -l

//**********

OS X:
//**********

shell$ system_profiler | egrep "Processors|Cores"
      Number of Processors: 1
      Total Number of Cores: 2

//**********

3. Move the downloaded file to your home directory, and untar the file.

Linux and OS X:
//**********

shell$ cp openmpi-1.4.4.tar.bz2 ~
shell$ cd
shell$ tar -xvjf  openmpi-1.4.4.tar.bz2

//**********

4. cd into the newly created openmpi directory and view the INSTALL file. Here you will find more information on how to install OpenMPI.

Linux and OS X:
//**********

shell$ cd openmpi-1.4.4
shell$ less INSTALL

//**********

5. Run configure and append the prefix option with your preference for the binary installation location.

Linux and OS X:
//**********

shell$ ./configure --prefix=$HOME/openmpi

//**********

6. Run 'make all install'

Linux and OS X:
//**********

shell$ make all install

//**********

7. cd into your home directory and edit your .bash_profile or .bashrc (.cshrc for c shell) to include the bin install location within your PATH. Don't forget to source it.

Linux and OS X:
//**********
shell$ cd
shell$ vi .bashrc

export PATH=$PATH:$HOME/openmpi/bin

shell$ source .bashrc
shell$ which mpic++
/home/username/openmpi/mpic++

//**********

You now have a fully functionally parallel processing environment! Good luck!

Sunday, December 26, 2010

Eclipse + ShellEd plugin = Shell Scripting within Eclipse

Quick How-To for Eclipse + ShellEd plugin:

Tutorial on installing Eclipse Plugin ShellEd using the following:
  • MAC OS X (Version: 10.6.5)
  • Eclipse (Version: Helios Service Release 1)
1. Install Linux Tools Plugin
  • Within Eclipse: click Help --> Install New Software
  • Click "Available Software Sites" (link slightly below Add button)
  • Enable (check box): http://download.eclipse.org/technology/linuxtools/update
  • Click OK
  • Under "Work with:" --> Select the recently enabled linuxtools
  • Under "Linux Tools" (1st group) --> Enable: Man Page Viewer (Incubation)
  • Click Next --> Next --> Accept license agreement --> Finish
  • Restart Eclipse
2. Download and Install the latest ShellEd Plugin Build
  • Download the latest ShellEd Eclipse Plugin (.zip file) from: http://sourceforge.net/projects/shelled/files/shelled/
  • Within Eclipse: Click on Help --> Install New Software
  • Click Add --> Archive ...
  • Navigate to the downloaded location of the .zip file --> Click Open
  • Input a name for future reference --> Add Repository (Click Ok)
  • Check Box --> Next --> Next --> Accept license agreement --> Finish
  • Confirm Security Warning (Installing Unsigned Content) by Clicking OK
  • Restart Eclipse
3. Test the installation by creating a new Shell Project, setting up the Shell Interpreter, entering some code, and run the script within Eclipse.

Creating A New Shell Project
  • Create a new project: New Project Wizard --> Select Shell Script Project Wizard --> Click Next
  • Input the Project Name --> Click Finish (default setting are fine for now
Setting Up The Shell Interpreter
  • Navigate to Eclipse Preferences (Eclipse Menu --> Preferences)
  • Navigate to ShellEd Options --> Select Interpreters
  • Click Search --> Select the interpreter you would like to use --> Click OK
Entering Code
  • Insert a new file into the project --> Right click on Shell Project Name --> Select New --> Select File
  • Input file name --> Click Finish
  • Enter a few commands (Bash Interpreter for this example) and Save
Run The Script Within Eclipse
  • Click Run Menu --> Run As --> Run shell script
--
Resources

1. SourceForge: Information on setting up Interpreter within Eclipse
  • http://sourceforge.net/projects/shelled/forums/forum/399718/topic/3863713
2. Linux Tools Project Plugin Install Help
  • http://wiki.eclipse.org/Linux_Tools_Project/PluginInstallHelp
3. SourceForge ShellEd Source and Zip Files
  • http://sourceforge.net/projects/shelled/files/shelled/
4. Eclipse Marketplace ShellEd
  • http://marketplace.eclipse.org/content/shelled

Monday, July 12, 2010

Boost Libraries and Eclipse

Installing Boost Libraries

1. Download the most recent version of Boost Libraries - http://sourceforge.net/projects/boost/files/boost/

2. Within the directory where you want to put the Boost Installation, execute the following:
  • tar --bzip2 -xf /path/to/boost_1_45_0.tar.bz2
Lagatuz-MacBookPro:Downloads marklagatuz$ pwd
/Users/marklagatuz/Downloads
Lagatuz-MacBookPro:Downloads marklagatuz$ tar --bzip2 -xf boost_1_45_0.tar.bz2

You now have a working Boost Library consisting of Header files. If you would like to make sure of the compiled libraries ... continue on!

3. Set up the Boost Compiled Library
  • Run the bootstrap strict with the --help option to receive options
./bootstrap.sh --help
  • Create the directory where you would like the Boost Library Binaries to reside
Lagatuz-MacBookPro:Downloads marklagatuz$ pwd
/Users/marklagatuz/Downloads
Lagatuz-MacBookPro:Downloads marklagatuz$ mkdir boost_1_45_0_Compiled
  • Change directory into the boost installation directory (header files only)
Lagatuz-MacBookPro:Downloads marklagatuz$ cd boost_1_45_0
Lagatuz-MacBookPro:boost_1_45_0 marklagatuz$ pwd
/Users/marklagatuz/Downloads/boost_1_45_0
  • Run the bootstrap script. I've added the following options:
  • --prefix: is for my own installation directory choosing.
  • --with-libraries. is for choosing which library binaries I want installed

Lagatuz-MacBookPro:boost_1_45_0 marklagatuz$ ./bootstrap.sh --prefix=/Users/marklagatuz/Downloads/boost_1_45_0_Compiled --with-libraries=all
  • Finally, install the binaries (a /lib will be created inside the prefix directory)
Lagatuz-MacBookPro:boost_1_45_0 marklagatuz$ ./bjam install

Congratulations ... you have the Boost Libraries installed!

Integrating Boost with Eclipse

After a successful installation of Boost Libraries on your system, here are some steps to integrate the Library with Eclipse. I've installed on OS X, so a Linux flavor should be similar.

If you want to utilize the Library which are only inline and templates (non-compiled):

1. Within Eclipse: Go to Properties menu
  • Project --> Properties
2. Add the headers into your Include path during compilation
  • C/C++ Build --> Settings --> GCC C++ Compiler --> Directories
  • Add the location of your installed Boost Library Include Path (/Users/marklagatuz/Downloads/boost_1_43_0 for me)
3. Finally save the configuration

If you want to utilize the Library which are compiled:

1. Within Eclipse: Go to Properties menu
  • Project --> Properties
2. Add the headers into your Include path during compilation
  • C/C++ Build --> Settings --> GCC C++ Compiler --> Directories
  • Add the location of compiled Boost Library Include Path (/Users/marklagatuz/Downloads/boost_compiled/include for me)
3. Add the compiled Library to the Library search path during linking
  • C/C++ Build --> Settings --> GCC C++ Linker --> Libraries --> Library search path (-L)
  • Add the location of the compiled Boost Library (/Users/marklagatuz/Downloads/boost_compiled/lib for me)
4. Add the specific Library name to the Libraries
  • C/C++ Build --> Settings --> GCC C++ Linker --> Libraries --> Libraries (-l)
  • Add compiled Library name you would like to utilize
5. Finally save the configuration

You are ready to utilize the Boost Library during your development!

--
Resources

1. Boost Getting Started Guide
  • http://www.boost.org/doc/libs/1_45_0/more/getting_started/index.html

Monday, June 21, 2010

CUDA: Know your limits on global memory

I was coding away on an assignment when I ran into a conundrum: I was getting weird results when attempting to copy data onto the device. There would be instances when arrays copied onto the device would be accessible, yet inaccessible during another run.

The fact I'm coding CUDA kernels on OS X gives way to a dilemma: cuda-gdb is not available (yet) on OS X. I have to rely on old school debugging techniques ... a code walk through and print statements! After numerous tests and frustrations ... I figured out I was running into a problem with global memory:

marklagatuz$ /Developer/GPU\ Computing/C/bin/darwin/release/deviceQuery

Device 0: "GeForce 9400M"
Total amount of global memory: 265945088 bytes

The above reads approximately 265MB of global memory. I had 4 arrays consisting of 67MB each being copied onto the device. I was clearly running into memory issues. This would explain why each time a different array would cause problems.

Lesson learned: Check your device(s) limitations before coding away! Then again ... you should be doing that anyways!

Tuesday, June 15, 2010

Learned Something New (or actually a review of something old)!

Since I'm forcing myself to think in terms of OO (Object Orientation), I forgot that computers are still 1 and 0's! As I'm reading code to understand design patterns, algorithms, and methods others folks are using, I came across something I've never used before (at least in my own code): shift operators.

  • <<
  • >>
I've always thought of the chevrons as output redirection in scripting or in C++. I've forgotten they actually shift the bits either to the left or right:

(1 << 24) == 0001 1111 1111 1111 1111 1111 1111

CUDA + THRUST + Eclipse

Quickstart

Assumptions: A working CUDA environment (I'm using OS X for this example).
  • nvcc --version --> should display CUDA Version, built date, and version of tools installed.
  • ./deviceQuery from /Developer/GPU Computing/C/bin/darwin/release (for OS X) should produce output for your device
1. Download the current library from the Thrust Project (currently 1.3.0) - http://code.google.com/p/thrust/downloads/list

2. Select a location and unzip the thrust library. You can unzip the library into the default cuda include location (/usr/local/cuda/include). I prefer to unzip the library in my home directory, (specifically the Downloads directory) but it's up to the user!
  • unzip thrust-v1.3.0.zip
This will create a directory called thrust

3. Add the libraries within your project in Eclipse
  • Project Name --> Properties
  • C/C++ Build --> Settings
  • CUDA NVCC Compiler --> Includes
  • Add (On the same line as Include Paths - green + button)
I originally added /Users/marklagatuz/Downloads/thrust, but was receiving the following
errors: error: thrust/host_vector.h: No such file or directory

The code compiled after removing /thrust from the -I on the command line (absolute path up to the thrust library).

--

References:

1. Thrust QuickStartGuide
  • http://code.google.com/p/thrust/wiki/QuickStartGuide