Yellow Dog Linux for CUDA Support

TOPIC: Creating a simple CUDA application and Makefile on YDL


Introduction
CUDA is a powerful programming framework which takes advantage of the power and multitasking abilities of Nvidia GPUs which support CUDA. This howto document provides specific examples of how to make your own program which uses CUDA on Yellow Dog Linux.

Hello World!:
A sample program outlined below is available for download here(tar.gz).

Makefile:
The sample program package contains a very simple makefile.

			
In the Compilers section, the paths to the system's compilers are listed.
			# Compilers
			NVCC   = /usr/bin/nvcc
			CXX    = /usr/bin/g++
			LINK   = $(CXX) -fPIC
			
In the # Flags section, the various flags are listed. In the sample program, only NVCCFLAGS are used, the others remain for reference.
			# Flags
			COMMONFLAGS = -O2
			NVCCFLAGS   = --compiler-options -fno-strict-aliasing
			CXXFLAGS    = -fno-strict-aliasing
			CFLAGS      = -g -fno-strict-aliasing
			
			
In the the # Paths section, the paths to the CUDA includes and libraries files are listed. Libraries are used later by g++ while NVCC uses the includes.
It may be necessary to add additional library declarations to the LIBS. Libraries used must be listed here along with the path to find them.
In this example, lcufft and lcutil are the library declarations, and the path to them is /usr/lib64/cuda23.
			# Paths
			INCLUDES    = -I. -I/usr/include/cuda23
			LIBS        = -L/usr/lib64/cuda23 -lcufft -lcutil
			
			
In the # Program-specfic section, the target program's name along with its source and object files are listed.
These are used in the Build Rules section to layer dependency, with TARGET at the top depending on OBJ which in turn depends on SRC.
			# Program-specific
			TARGET= HelloWorld
			SRC = HelloWorld.cu HelloWorld_kernel.cu
			OBJ = HelloWorld.cu.o
			
			
In the # Build Rules section, the makefile's rules are defined.
Cuda uses nvcc to compile .cu source files into object files.
g++ is used to link the object files with the needed libraries in the final binary.
			# Build Rules
			.SUFFIXES: .cu
			
			$(TARGET): $(OBJ) 
				$(LINK) -o $(TARGET) $(OBJ) $(LIBS)
			
			$(OBJ): $(SRC)
				$(NVCC) $(NVCCFLAGS) $(INCLUDES) -o $(OBJ) -c $< 
			
			clean:
				rm -f $(OBJ) $(TARGET)
		

About the program:


This HOWTO was prepared by Owen Stampflee and Matt Watson, Fixstars Solutions, Inc.



 
          Copyright ® 1999-2010. Fixstars Corporation. All rights reserved.
YDL.net Fixstars Corporation