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
Showing posts with label mac. Show all posts
Showing posts with label mac. Show all posts

Tuesday, May 25, 2010

Example of Eclipse + CUDA Integration

I'm tired of using vi to edit my .cu source files, so I decided to attempt to integrate CUDA with the Eclipse IDE.

Right off the back, when you build your CUDA project within Eclipse, it will FAIL! Determined not to use vi, I trolled Google for help. Additionally, I attempted to mimic a build similar to a simple Hello World Project.

Assumptions: Drop this Makefile (located after the Example Project Creation) at the top of your Project Directory to have a successful build.

MAC OS X

1. Create a new C++ Project
  • ctrl + mouse click --> New --> C++ Project

2. Create an Empty Project
  • Select Empty Project
  • Create a project name
  • Click Next

3. Click Advanced Settings

4. Remove Automatic Makefile Generation
  • C/C++ Build --> Makefile Generation
  • Uncheck Generate Makefile automatically

5. Apply and OK

6. Finish

7. Create a source directory within your project
  • ctrl+mouse click on project --> New --> Source Folder
  • Name the folder
  • Finish

8. Create C++ source files within the source folder

9. Create a regular file for the associated Makefile
  • ctrl+mouse click on the project --> New -->File
  • Name the file Makefile

10. Copy the example Makefile from below into your Project
(using your own information)

##############################################
#
# Makefile for CUDA
#
# A hack created by Mark Lagatuz to compile .cu files within Eclipse
#
# This makefile assumes you separate the device and host code into
# separate files:
#
# HOST: _H appended to file name (code_H.cu)
# DEVICE: _D appended to file name (code_D.cu)
#
# Replace the following with your own information:
#
# CUDA_INSTALL_PATH: /path/to/your/cuda/installation
# PROGRAM: Name of Executable
#
##############################################

# CUDA Installation Path
CUDA_INSTALL_PATH = /usr/local/cuda

# Source Folder (Relative to where Makefile is located)
SRC_FOLDER = src

# Compiler
NVCC = $(CUDA_INSTALL_PATH)/bin/nvcc

# Includes
INCLUDE = $(CUDA_INSTALL_PATH)/include

# Program or Executable
PROGRAM = mandelbrotCUDA

# Device Code
DEVICE = _D

# Host Code
HOST = _H

all : $(PROGRAM)

# Create Executable by linking *.o (host and device object's)
$(PROGRAM) : $(PROGRAM)$(DEVICE).o $(PROGRAM)$(HOST).o
$(NVCC) -o $(PROGRAM) $^

# Compile device code to an object
$(PROGRAM)$(DEVICE).o : $(SRC_FOLDER)/$(PROGRAM)$(DEVICE).cu
$(NVCC) -I $(INCLUDE) -o $@ -c $< # Compile host code to an object $(PROGRAM)$(HOST).o : $(SRC_FOLDER)/$(PROGRAM)$(HOST).cu $(NVCC) -I $(INCLUDE) -o $@ -c $< # Remove *.o files and executables clean : rm *.o $(PROGRAM) -- Resources

1. MAC OS X
  • /Developer/GPU Computing/C/common/common.mk (I utilized this file to help build my Makefile

2. Life of a Programmer Greek
  • http://lifeofaprogrammergeek.blogspot.com/2008/07/using-eclipse-for-cuda-development.html

3. How to set up CUDA in Eclipse
  • http://imonad.com/blog/how-to-set-cuda-in-eclipse/

Monday, May 24, 2010

CUDA (Version 3.0) on OS X

Installing a working CUDA Environment

Assumptions: You have a working c/c++ environment (compilers and libraries --> XCode)

I was able to install the drivers, toolkit, and SDK on my MBP running OS X 10.6.3. Please refer to the NVIDIA's CUDA website to confirm your video card is CUDA ready or you can check it here --> http://www.nvidia.com/object/cuda_gpus.html

1. Set the following variables in your .bash_profile or .cshrc (I use csh at work, but bash at home
  • PATH: /cuda/bin (export PATH=$PATH:/usr/local/cuda/bin)
  • DYLD_LIBRARY_PATH: /cuda/lib (export DYLD_LIBRARY_PATH=/usr/local/cuda/lib)

2. Download the Development Drivers, Toolkit, and SDK from:
  • http://developer.nvidia.com/object/cuda_3_0_downloads.html

3. Install the drivers and verify the installation:
Lagatuz-MacBookPro:cuda marklagatuz$ ls
include lib
Lagatuz-MacBookPro:cuda marklagatuz$ pwd
/usr/local/cuda

4. Install the Toolkit and verify the installation:
Lagatuz-MacBookPro:cuda marklagatuz$ ls
bin cudaprof doc include lib man open64 src
Lagatuz-MacBookPro:cuda marklagatuz$ pwd
/usr/local/cuda

5. Install the SDK and verify the installation:
Lagatuz-MacBookPro:cuda marklagatuz$ cd /Developer/GPU\ Computing/
Lagatuz-MacBookPro:GPU Computing marklagatuz$ ls
C OpenCL bin doc lib shared
Lagatuz-MacBookPro:GPU Computing marklagatuz$ pwd
/Developer/GPU Computing

6. Complete installation of the SDK:
  • cd into C and run make:
Lagatuz-MacBookPro:GPU Computing marklagatuz$ ls
C OpenCL bin doc lib shared
Lagatuz-MacBookPro:GPU Computing marklagatuz$ cd C
Lagatuz-MacBookPro:C marklagatuz$make
Finished building all

7. At this point after the make you should have a fully functional CUDA environment. To test out your environment:
  • cd into /Developer/GPU Computing/C/bin/darwin/release
  • execute the file deviceQuery: ./deviceQuery
Lagatuz-MacBookPro:C marklagatuz$ ls
Makefile bin doc releaseNotesData tools
Samples.html common lib src
Lagatuz-MacBookPro:C marklagatuz$ cd bin/
Lagatuz-MacBookPro:bin marklagatuz$ ls
darwin
Lagatuz-MacBookPro:bin marklagatuz$ cd darwin/
Lagatuz-MacBookPro:darwin marklagatuz$ ls
release
Lagatuz-MacBookPro:darwin marklagatuz$ cd release/
Lagatuz-MacBookPro:release marklagatuz$ ./deviceQuery

The output should give you information on your CUDA Enabled Device!

--
Resources

1. NVIDIA CUDA 3.0 Downloads
  • http://developer.nvidia.com/object/cuda_3_0_downloads.html
2. Getting started Guide for MAC PDF File
  • http://developer.download.nvidia.com/compute/cuda/3_0/docs/GettingStartedMacOS.pdf
3. Trial & Error