I’m using cuda 2.1 in linux.
I was able to install the sdk successfully (and yes, I’ve ran some applications).
Now I’m trying to build an application in a directory outside the sdk. I tried 3 different ways but they all failed. I’ve been trying this for some days now :(
For each approach I copied matrixMul to a directory outside the sdk dir.
(1)
Edited the matrixMul Makefile to point to the correct cuda sdk dir.
I followed these instructions: http://www.acooke.org/cute/ReusingCUD0.html
I get this error:
$ make
make: *** No rule to make target `obj/debug/matrixMul_gold.cpp.o', needed by ``pwd`//debug/matrixMul.exe'. Stop.
(Don’t pay attention to the .exe file extension for my target, my host system is linux).
Even though this seems to be a makefile/shell issue, the question remains on how to re-use the sdk makefiles.
(2)
I tried using an independent makefile.
I used the one in http://www.eecs.berkeley.edu/~mjmurphy/makefile
My adapted makefile:
# vim:comments=
#
# I don't like the Cuda SDK makefiles. Here's my own! This makefile should
# allow you to build Cuda programs independent of the NVidia Cuda SDK. Its
# simplicity makes it easy for you to put objects, binaries, etc where you want
# them. There is even some boiler-plate Makefile magic that you can copy
# into other Makefiles.
#
# Mark Murphy 2008
# Fill in the name of the output binary here
target := matrixMul.exe
# List of sources, with .c, .cu, and .cc extensions
sources := matrixMul.cu matrixMul_gold.cpp matrixMul_kernel.cu
# Other things that need to be built, e.g. .cubin files
extradeps :=
# Flags common to all compilers. You can set these on the comamnd line, e.g:
# $ make opt="" dbg="-g" warn="-Wno-deptrcated-declarations -Wall -Werror"
opt ?= -O3
dbg ?=
warn ?= -Wall -Werror
# This is where the cuda runtime libraries and includes reside on the
# berkeley millennium/rad clusters. It may be different on your machine.
cudaroot := /usr/local/cuda
cudasdkroot := /usr/local/cuda-sdk
#----- C compilation options ------
gcc := /usr/bin/gcc
cflags += $(opt) $(dbg) $(warn)
clib_paths :=
cinc_paths :=
clibraries :=
#----- C++ compilation options ------
gpp := /usr/bin/g++
ccflags += $(opt) $(dbg) $(warn)
cclib_paths :=
ccinc_paths :=
cclibraries :=
#----- CUDA compilation options -----
nvcc := $(cudaroot)/bin/nvcc
cuflags += $(opt) $(dbg)
culib_paths := -L$(cudaroot)/lib -L$(cudasdkroot)/lib
cuinc_paths := -I$(cudaroot)/include -I$(cudasdkroot)/common/inc
culibraries := -lcuda -lcudart -lcutil
lib_paths := $(culib_paths) $(cclib_paths) $(clib_paths)
libraries := $(culibraries) $(cclibraries) $(clibraries)
#----- Generate source file and object file lists
# This code separates the source files by filename extension into C, C++,
# and Cuda files.
csources := $(filter %.c ,$(sources))
ccsources := $(filter %.cc,$(sources))
cusources := $(filter %.cu,$(sources))
# This code generates a list of object files by replacing filename extensions
objects := $(patsubst %.c,%.o ,$(csources)) \
$(patsubst %.cu,%.o,$(cusources)) \
$(patsubst %.cc,%.o,$(ccsources))
#----- Build rules ------
$(target): $(extradeps)
$(target): $(objects)
$(gcc) -o $@ $(lib_paths) $(libraries) $(objects)
%.o: %.cu
$(nvcc) -c $^ $(cuflags) $(cuinc_paths) -o $@
%.cubin: %.cu
$(nvcc) -cubin $(cuflags) $(cuinc_paths) $^
%.o: %.cc
$(gpp) -c $^ $(ccflags) $(ccinc_paths) -o $@
%.o: %.c
$(gcc) -c $^ $(cflags) $(cinc_paths) -o $@
clean:
rm -f *.o $(target) makefile.*dep
#----- Dependency Generation -----
#
# If a particular set of sources is non-empty, then have rules for
# generating the necessary dep files.
#
ccdep := ccdep.mk
cdep := cdep.mk
cudep := cudep.mk
depfiles =
ifneq ($(ccsources),)
depfiles += $(ccdep)
$(ccdep): $(ccsources)
$(gpp) -MM $(ccsources) > $(ccdep)
else
$(ccdep):
endif
ifneq ($(cusources),)
depfiles += $(cudep)
$(cudep):
$(gpp) -MM -x c++ $(cusources) > $(cudep)
else
$(cudep):
endif
ifneq ($(csources),)
depfiles += $(cdep)
$(cdep): $(csources)
$(gcc) -MM -x c $(csources) > $(cdep)
else
$(cdep):
endif
.PHONY: dep
dep: $(depfiles)
ifneq ($(MAKECMDGOALS),dep)
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(ccsources),)
include $(ccdep)
endif
ifneq ($(cusources),)
include $(cudep)
endif
ifneq ($(csources),)
include $(cdep)
endif
endif
endif
My error message:
$ make
/usr/local/cuda/bin/nvcc -c matrixMul.cu -O3 -I/usr/local/cuda/include -I/usr/local/cuda-sdk/common/inc -o matrixMul.o
/usr/local/cuda/bin/nvcc -c matrixMul_kernel.cu matrixMul.h -O3 -I/usr/local/cuda/include -I/usr/local/cuda-sdk/common/inc -o matrixMul_kernel.o
nvcc fatal : A single input file is required for a non-link phase when an outputfile is specified
make: *** [matrixMul_kernel.o] Error 255
(3)
Building it directly from command line.
$ nvcc -o matrixMul.exe matrixMul.cu matrixMul_gold.cpp matrixMul_kernel.cu -I/usr/local/cuda-sdk/common/inc/ -L/usr/local/cuda-sdk/lib/ -lcuda -lcudart -lcutil
/tmp/tmpxft_00002d58_00000000-25_matrixMul_kernel.o: In function `__device_stub__Z9matrixMulPfS_S_ii':
tmpxft_00002d58_00000000-24_matrixMul_kernel.ii:(.text+0x126): multiple definition of `__device_stub__Z9matrixMulPfS_S_ii'
/tmp/tmpxft_00002d58_00000000-15_matrixMul.o:tmpxft_00002d58_00000000-14_matrixMul.ii:(.text+0x126): first defined here
collect2: ld returned 1 exit status
Can anyone help with the fix for each of these methods.
I only need to have a working makefile in order to start developing my own application, however I would like to be able to understand the cause of the problems for each case and its respective solutions.
Thank you very much for your time.