123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- ################################################################################
- #
- # Copyright 1993-2006 NVIDIA Corporation. All rights reserved.
- #
- # NOTICE TO USER:
- #
- # This source code is subject to NVIDIA ownership rights under U.S. and
- # international Copyright laws.
- #
- # NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE
- # CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR
- # IMPLIED WARRANTY OF ANY KIND. NVIDIA DISCLAIMS ALL WARRANTIES WITH
- # REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF
- # MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
- # IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
- # OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
- # OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
- # OR PERFORMANCE OF THIS SOURCE CODE.
- #
- # U.S. Government End Users. This source code is a "commercial item" as
- # that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting of
- # "commercial computer software" and "commercial computer software
- # documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995)
- # and is provided to the U.S. Government only as a commercial end item.
- # Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through
- # 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the
- # source code with only those rights set forth herein.
- #
- ################################################################################
- #
- # Common build script
- #
- ################################################################################
- .SUFFIXES : .cu .cu_dbg_o .c_dbg_o .cpp_dbg_o .cu_rel_o .c_rel_o .cpp_rel_o .cubin
- # Add new SM Versions here as devices with new Compute Capability are released
- SM_VERSIONS := sm_10 sm_11 sm_12 sm_13
- CUDA_INSTALL_PATH ?= /usr/local/cuda
- ifdef cuda-install
- CUDA_INSTALL_PATH := $(cuda-install)
- endif
- # detect OS
- OSUPPER = $(shell uname -s 2>/dev/null | tr [:lower:] [:upper:])
- OSLOWER = $(shell uname -s 2>/dev/null | tr [:upper:] [:lower:])
- # 'linux' is output for Linux system, 'darwin' for OS X
- DARWIN = $(strip $(findstring DARWIN, $(OSUPPER)))
- # Basic directory setup for SDK
- # (override directories only if they are not already defined)
- SRCDIR ?=
- ROOTDIR ?= ..
- ROOTBINDIR ?= $(ROOTDIR)/../bin
- BINDIR ?= $(ROOTBINDIR)/$(OSLOWER)
- ROOTOBJDIR ?= obj
- LIBDIR := $(ROOTDIR)/../lib
- COMMONDIR := $(ROOTDIR)/../common
- # Compilers
- NVCC := $(CUDA_INSTALL_PATH)/bin/nvcc
- CXX := g++
- CC := gcc
- LINK := g++ -fPIC
- # Includes
- INCLUDES += -I. -I$(CUDA_INSTALL_PATH)/include -I$(COMMONDIR)/inc
- # architecture flag for cubin build
- CUBIN_ARCH_FLAG := -m32
- # Warning flags
- CXXWARN_FLAGS := \
- -W -Wall \
- -Wimplicit \
- -Wswitch \
- -Wformat \
- -Wchar-subscripts \
- -Wparentheses \
- -Wmultichar \
- -Wtrigraphs \
- -Wpointer-arith \
- -Wcast-align \
- -Wreturn-type \
- -Wno-unused-function \
- $(SPACE)
- CWARN_FLAGS := $(CXXWARN_FLAGS) \
- -Wstrict-prototypes \
- -Wmissing-prototypes \
- -Wmissing-declarations \
- -Wnested-externs \
- -Wmain \
- # Compiler-specific flags
- NVCCFLAGS :=
- CXXFLAGS := $(CXXWARN_FLAGS)
- CFLAGS := $(CWARN_FLAGS)
- # Common flags
- COMMONFLAGS += $(INCLUDES) -DUNIX
- # Debug/release configuration
- ifeq ($(dbg),1)
- COMMONFLAGS += -g
- NVCCFLAGS += -D_DEBUG
- BINSUBDIR := debug
- LIBSUFFIX := D
- else
- COMMONFLAGS += -O3
- BINSUBDIR := release
- LIBSUFFIX :=
- NVCCFLAGS += --compiler-options -fno-strict-aliasing
- CXXFLAGS += -fno-strict-aliasing
- CFLAGS += -fno-strict-aliasing
- endif
- # append optional arch/SM version flags (such as -arch sm_11)
- #NVCCFLAGS += $(SMVERSIONFLAGS)
- # architecture flag for cubin build
- CUBIN_ARCH_FLAG := -m32
- # detect if 32 bit or 64 bit system
- HP_64 = $(shell uname -m | grep 64)
- # OpenGL is used or not (if it is used, then it is necessary to include GLEW)
- ifeq ($(USEGLLIB),1)
- ifneq ($(DARWIN),)
- OPENGLLIB := -L/System/Library/Frameworks/OpenGL.framework/Libraries -lGL -lGLU $(COMMONDIR)/lib/$(OSLOWER)/libGLEW.a
- else
- OPENGLLIB := -lGL -lGLU
- ifeq "$(strip $(HP_64))" ""
- OPENGLLIB += -lGLEW
- else
- OPENGLLIB += -lGLEW_x86_64
- endif
- endif
- CUBIN_ARCH_FLAG := -m64
- endif
- ifeq ($(USEGLUT),1)
- ifneq ($(DARWIN),)
- OPENGLLIB += -framework GLUT
- else
- OPENGLLIB += -lglut
- endif
- endif
- ifeq ($(USEPARAMGL),1)
- PARAMGLLIB := -lparamgl$(LIBSUFFIX)
- endif
- ifeq ($(USERENDERCHECKGL),1)
- RENDERCHECKGLLIB := -lrendercheckgl$(LIBSUFFIX)
- endif
- ifeq ($(USECUDPP), 1)
- ifeq "$(strip $(HP_64))" ""
- CUDPPLIB := -lcudpp
- else
- CUDPPLIB := -lcudpp64
- endif
- CUDPPLIB := $(CUDPPLIB)$(LIBSUFFIX)
- ifeq ($(emu), 1)
- CUDPPLIB := $(CUDPPLIB)_emu
- endif
- endif
- # Libs
- LIB := -L$(CUDA_INSTALL_PATH)/lib -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER)
- ifeq ($(USEDRVAPI),1)
- LIB += -lcuda ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}
- else
- LIB += -lcudart ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}
- endif
- ifeq ($(USECUFFT),1)
- ifeq ($(emu),1)
- LIB += -lcufftemu
- else
- LIB += -lcufft
- endif
- endif
- ifeq ($(USECUBLAS),1)
- ifeq ($(emu),1)
- LIB += -lcublasemu
- else
- LIB += -lcublas
- endif
- endif
- # Lib/exe configuration
- ifneq ($(STATIC_LIB),)
- TARGETDIR := $(LIBDIR)
- TARGET := $(subst .a,$(LIBSUFFIX).a,$(LIBDIR)/$(STATIC_LIB))
- LINKLINE = ar qv $(TARGET) $(OBJS)
- else
- # LIB += -lcutil$(LIBSUFFIX)
- # Device emulation configuration
- ifeq ($(emu), 1)
- NVCCFLAGS += -deviceemu
- CUDACCFLAGS +=
- BINSUBDIR := emu$(BINSUBDIR)
- # consistency, makes developing easier
- CXXFLAGS += -D__DEVICE_EMULATION__
- CFLAGS += -D__DEVICE_EMULATION__
- endif
- TARGETDIR := $(BINDIR)/$(BINSUBDIR)
- TARGET := $(TARGETDIR)/$(EXECUTABLE)
- LINKLINE = $(LINK) -o $(TARGET) $(OBJS) $(LIB)
- endif
- # check if verbose
- ifeq ($(verbose), 1)
- VERBOSE :=
- else
- VERBOSE := @
- endif
- ################################################################################
- # Check for input flags and set compiler flags appropriately
- ################################################################################
- ifeq ($(fastmath), 1)
- NVCCFLAGS += -use_fast_math
- endif
- ifeq ($(keep), 1)
- NVCCFLAGS += -keep
- NVCC_KEEP_CLEAN := *.i* *.cubin *.cu.c *.cudafe* *.fatbin.c *.ptx
- endif
- ifdef maxregisters
- NVCCFLAGS += -maxrregcount $(maxregisters)
- endif
- # Add cudacc flags
- NVCCFLAGS += $(CUDACCFLAGS)
- # workaround for mac os x cuda 1.1 compiler issues
- ifneq ($(DARWIN),)
- NVCCFLAGS += --host-compilation=C
- endif
- # Add common flags
- NVCCFLAGS += $(COMMONFLAGS)
- CXXFLAGS += $(COMMONFLAGS)
- CFLAGS += $(COMMONFLAGS)
- ifeq ($(nvcc_warn_verbose),1)
- NVCCFLAGS += $(addprefix --compiler-options ,$(CXXWARN_FLAGS))
- NVCCFLAGS += --compiler-options -fno-strict-aliasing
- endif
- ################################################################################
- # Set up object files
- ################################################################################
- OBJDIR := $(ROOTOBJDIR)/$(BINSUBDIR)
- OBJS += $(patsubst %.cpp,$(OBJDIR)/%.cpp_o,$(notdir $(CCFILES)))
- OBJS += $(patsubst %.c,$(OBJDIR)/%.c_o,$(notdir $(CFILES)))
- OBJS += $(patsubst %.cu,$(OBJDIR)/%.cu_o,$(notdir $(CUFILES)))
- ################################################################################
- # Set up cubin files
- ################################################################################
- CUBINDIR := $(SRCDIR)data
- CUBINS += $(patsubst %.cu,$(CUBINDIR)/%.cubin,$(notdir $(CUBINFILES)))
- ################################################################################
- # Rules
- ################################################################################
- $(OBJDIR)/%.c_o : $(SRCDIR)%.c $(C_DEPS)
- $(VERBOSE)$(CC) $(CFLAGS) -o $@ -c $<
- $(OBJDIR)/%.cpp_o : $(SRCDIR)%.cpp $(C_DEPS)
- $(VERBOSE)$(CXX) $(CXXFLAGS) -o $@ -c $<
- $(OBJDIR)/%.cu_o : $(SRCDIR)%.cu $(CU_DEPS)
- $(VERBOSE)$(NVCC) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $@ -c $<
- $(CUBINDIR)/%.cubin : $(SRCDIR)%.cu cubindirectory
- $(VERBOSE)$(NVCC) $(CUBIN_ARCH_FLAG) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $@ -cubin $<
- #
- # The following definition is a template that gets instantiated for each SM
- # version (sm_10, sm_13, etc.) stored in SMVERSIONS. It does 2 things:
- # 1. It adds to OBJS a .cu_sm_XX_o for each .cu file it finds in CUFILES_sm_XX.
- # 2. It generates a rule for building .cu_sm_XX_o files from the corresponding
- # .cu file.
- #
- # The intended use for this is to allow Makefiles that use common.mk to compile
- # files to different Compute Capability targets (aka SM arch version). To do
- # so, in the Makefile, list files for each SM arch separately, like so:
- #
- # CUFILES_sm_10 := mycudakernel_sm10.cu app.cu
- # CUFILES_sm_12 := anothercudakernel_sm12.cu
- #
- define SMVERSION_template
- OBJS += $(patsubst %.cu,$(OBJDIR)/%.cu_$(1)_o,$(notdir $(CUFILES_$(1))))
- $(OBJDIR)/%.cu_$(1)_o : $(SRCDIR)%.cu $(CU_DEPS)
- $(VERBOSE)$(NVCC) -o $$@ -c $$< $(NVCCFLAGS) -arch $(1)
- endef
- # This line invokes the above template for each arch version stored in
- # SM_VERSIONS. The call funtion invokes the template, and the eval
- # function interprets it as make commands.
- $(foreach smver,$(SM_VERSIONS),$(eval $(call SMVERSION_template,$(smver))))
- $(TARGET): makedirectories $(OBJS) $(CUBINS) Makefile
- $(VERBOSE)$(LINKLINE)
- cubindirectory:
- $(VERBOSE)mkdir -p $(CUBINDIR)
- makedirectories:
- $(VERBOSE)mkdir -p $(LIBDIR)
- $(VERBOSE)mkdir -p $(OBJDIR)
- $(VERBOSE)mkdir -p $(TARGETDIR)
- tidy :
- $(VERBOSE)find . | egrep "#" | xargs rm -f
- $(VERBOSE)find . | egrep "\~" | xargs rm -f
- clean : tidy
- $(VERBOSE)rm -f $(OBJS)
- $(VERBOSE)rm -f $(CUBINS)
- $(VERBOSE)rm -f $(TARGET)
- $(VERBOSE)rm -f $(NVCC_KEEP_CLEAN)
- clobber : clean
- $(VERBOSE)rm -rf $(ROOTOBJDIR)
|