TOPIC: Creating a simple CUDA application and Makefile on YDL
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.
A sample program outlined below is available for download here(tar.gz).
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) -fPICIn 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-aliasingIn 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 -lcutilIn 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.oIn 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.