Advertisement
Guest User

Untitled

a guest
Jan 17th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.69 KB | None | 0 0
  1. ################################################################################
  2. #
  3. # Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
  4. #
  5. # NVIDIA Corporation and its licensors retain all intellectual property and
  6. # proprietary rights in and to this software and related documentation.
  7. # Any use, reproduction, disclosure, or distribution of this software
  8. # and related documentation without an express license agreement from
  9. # NVIDIA Corporation is strictly prohibited.
  10. #
  11. # Please refer to the applicable NVIDIA end user license agreement (EULA)
  12. # associated with this source code for terms and conditions that govern
  13. # your use of this NVIDIA software.
  14. #
  15. ################################################################################
  16. #
  17. # Common build script for CUDA source projects for Linux and Mac platforms
  18. #
  19. ################################################################################
  20.  
  21. .SUFFIXES : .cu .cu_dbg.o .c_dbg.o .cpp_dbg.o .cu_rel.o .c_rel.o .cpp_rel.o .cubin .ptx
  22.  
  23. # Add new SM Versions here as devices with new Compute Capability are released
  24. SM_VERSIONS := 10 11 12 13 20
  25.  
  26. CUDA_INSTALL_PATH ?= /usr/local/cuda
  27.  
  28. ifdef cuda-install
  29. CUDA_INSTALL_PATH := $(cuda-install)
  30. endif
  31.  
  32. # detect OS
  33. OSUPPER = $(shell uname -s 2>/dev/null | tr [:lower:] [:upper:])
  34. OSLOWER = $(shell uname -s 2>/dev/null | tr [:upper:] [:lower:])
  35.  
  36. # 'linux' is output for Linux system, 'darwin' for OS X
  37. DARWIN = $(strip $(findstring DARWIN, $(OSUPPER)))
  38. ifneq ($(DARWIN),)
  39. SNOWLEOPARD = $(strip $(findstring 10.6, $(shell egrep "<string>10\.6" /System/Library/CoreServices/SystemVersion.plist)))
  40. endif
  41.  
  42. # detect 32-bit or 64-bit platform
  43. HP_64 = $(shell uname -m | grep 64)
  44. OSARCH= $(shell uname -m)
  45.  
  46. # Basic directory setup for SDK
  47. # (override directories only if they are not already defined)
  48.  
  49. SRCDIR ?=
  50. ROOTDIR ?= ..
  51. ROOTBINDIR ?= $(ROOTDIR)/bin
  52. BINDIR ?= $(ROOTBINDIR)/
  53. ROOTOBJDIR ?= obj
  54. CUDASDKDIR := $(HOME)/NVIDIA_GPU_Computing_SDK
  55.  
  56. LIBDIR := $(CUDASDKDIR)/C/lib
  57. COMMONDIR := $(CUDASDKDIR)/C/common
  58. SHAREDDIR := $(CUDASDKDIR)/shared
  59.  
  60. # Compilers
  61. NVCC := $(CUDA_INSTALL_PATH)/bin/nvcc
  62. # CXX := g++-4.3
  63. CXX := g++
  64. # CC := gcc-4.3
  65. CC := gcc
  66. # LINK := g++-4.3 -fPIC
  67. LINK := g++ -fPIC
  68.  
  69. # Includes
  70. INCLUDES += -I. -I$(CUDA_INSTALL_PATH)/include -I$(COMMONDIR)/inc -I$(SHAREDDIR)/inc -I/usr/include/opencv
  71.  
  72. #-I$(GpuInc) -I$(ToolsInc)
  73.  
  74. # Warning flags
  75. CXXWARN_FLAGS := \
  76. -W -Wall \
  77. -Wimplicit \
  78. -Wswitch \
  79. -Wformat \
  80. -Wchar-subscripts \
  81. -Wparentheses \
  82. -Wmultichar \
  83. -Wtrigraphs \
  84. -Wpointer-arith \
  85. -Wcast-align \
  86. -Wreturn-type \
  87. -Wno-unused-function \
  88. $(SPACE)
  89.  
  90. CWARN_FLAGS := $(CXXWARN_FLAGS) \
  91. -Wstrict-prototypes \
  92. -Wmissing-prototypes \
  93. -Wmissing-declarations \
  94. -Wnested-externs \
  95. -Wmain \
  96.  
  97. # architecture flag for nvcc and gcc compilers build
  98. CUBIN_ARCH_FLAG :=
  99. CXX_ARCH_FLAGS :=
  100. NVCCFLAGS :=
  101. # --compiler-bindir /tmp
  102. LIB_ARCH := $(OSARCH)
  103.  
  104. # Determining the necessary Cross-Compilation Flags
  105. # 32-bit OS, but we target 64-bit cross compilation
  106. ifeq ($(x86_64),1)
  107. NVCCFLAGS += -m64
  108. LIB_ARCH = x86_64
  109. CUDPPLIB_SUFFIX = x86_64
  110.  
  111. ifneq ($(DARWIN),)
  112. CXX_ARCH_FLAGS += -arch x86_64
  113. else
  114. CXX_ARCH_FLAGS += -m64
  115. endif
  116. else
  117. # 64-bit OS, and we target 32-bit cross compilation
  118. ifeq ($(i386),1)
  119. NVCCFLAGS += -m32
  120. LIB_ARCH = i386
  121. CUDPPLIB_SUFFIX = i386
  122.  
  123. ifneq ($(DARWIN),)
  124. CXX_ARCH_FLAGS += -arch i386
  125. else
  126. CXX_ARCH_FLAGS += -m32
  127. endif
  128. else
  129. ifneq ($(SNOWLEOPARD),)
  130. NVCCFLAGS += -m32
  131. CXX_ARCH_FLAGS += -m32 -arch i386
  132. LIB_ARCH = i386
  133. CUDPPLIB_SUFFIX = i386
  134. else
  135. ifeq "$(strip $(HP_64))" ""
  136. LIB_ARCH = i386
  137. CUDPPLIB_SUFFIX = i386
  138. else
  139. LIB_ARCH = x86_64
  140. CUDPPLIB_SUFFIX = x86_64
  141. endif
  142. endif
  143. endif
  144. endif
  145.  
  146. # Compiler-specific flags (by default, we always use sm_10 and sm_20), unless we use the SMVERSION template
  147. GENCODE_SM10 := -gencode=arch=compute_10,code=\"sm_10,compute_10\"
  148. GENCODE_SM20 := -gencode=arch=compute_20,code=\"sm_20,compute_20\"
  149.  
  150. CXXFLAGS += $(CXXWARN_FLAGS) $(CXX_ARCH_FLAGS)
  151. CFLAGS += $(CWARN_FLAGS) $(CXX_ARCH_FLAGS)
  152. LINKFLAGS +=
  153. LINK += $(LINKFLAGS) $(CXX_ARCH_FLAGS)
  154.  
  155. # This option for Mac allows CUDA applications to work without requiring to set DYLD_LIBRARY_PATH
  156. ifneq ($(DARWIN),)
  157. LINK += -Xlinker -rpath $(CUDA_INSTALL_PATH)/lib
  158. endif
  159.  
  160. # Common flags
  161. COMMONFLAGS += $(INCLUDES) -DUNIX
  162.  
  163. # Debug/release configuration
  164. ifeq ($(dbg),1)
  165. COMMONFLAGS += -g
  166. NVCCFLAGS += -D_DEBUG
  167. CXXFLAGS += -D_DEBUG
  168. CFLAGS += -D_DEBUG
  169. BINSUBDIR := debug
  170. LIBSUFFIX := D
  171. else
  172. COMMONFLAGS += -O2
  173. BINSUBDIR :=
  174. LIBSUFFIX :=
  175. NVCCFLAGS += --compiler-options -fno-strict-aliasing
  176. # --ptxas-options="-v"
  177. CXXFLAGS += -fno-strict-aliasing
  178. CFLAGS += -fno-strict-aliasing
  179. endif
  180.  
  181. # architecture flag for cubin build
  182. CUBIN_ARCH_FLAG :=
  183.  
  184. # OpenGL is used or not (if it is used, then it is necessary to include GLEW)
  185. ifeq ($(USEGLLIB),1)
  186. ifneq ($(DARWIN),)
  187. OPENGLLIB := -L/System/Library/Frameworks/OpenGL.framework/Libraries
  188. OPENGLLIB += -lGL -lGLU $(COMMONDIR)/lib/$(OSLOWER)/libGLEW.a
  189. else
  190. # this case for linux platforms
  191. OPENGLLIB := -lGL -lGLU -lX11 -lXi -lXmu
  192. # check if x86_64 flag has been set, otherwise, check HP_64 is i386/x86_64
  193. ifeq ($(x86_64),1)
  194. OPENGLLIB += -lGLEW_x86_64 -L/usr/X11R6/lib64
  195. else
  196. ifeq ($(i386),)
  197. ifeq "$(strip $(HP_64))" ""
  198. OPENGLLIB += -lGLEW -L/usr/X11R6/lib
  199. else
  200. OPENGLLIB += -lGLEW_x86_64 -L/usr/X11R6/lib64
  201. endif
  202. endif
  203. endif
  204. # check if i386 flag has been set, otehrwise check HP_64 is i386/x86_64
  205. ifeq ($(i386),1)
  206. OPENGLLIB += -lGLEW -L/usr/X11R6/lib
  207. else
  208. ifeq ($(x86_64),)
  209. ifeq "$(strip $(HP_64))" ""
  210. OPENGLLIB += -lGLEW -L/usr/X11R6/lib
  211. else
  212. OPENGLLIB += -lGLEW_x86_64 -L/usr/X11R6/lib64
  213. endif
  214. endif
  215. endif
  216. endif
  217. endif
  218.  
  219. ifeq ($(USEGLUT),1)
  220. ifneq ($(DARWIN),)
  221. OPENGLLIB += -framework GLUT
  222. else
  223. ifeq ($(x86_64),1)
  224. OPENGLLIB += -lglut -L/usr/lib64
  225. endif
  226. ifeq ($(i386),1)
  227. OPENGLLIB += -lglut -L/usr/lib
  228. endif
  229.  
  230. ifeq ($(x86_64),)
  231. ifeq ($(i386),)
  232. OPENGLLIB += -lglut
  233. endif
  234. endif
  235. endif
  236. endif
  237.  
  238. ifeq ($(USEPARAMGL),1)
  239. PARAMGLLIB := -lparamgl_$(LIB_ARCH)$(LIBSUFFIX)
  240. endif
  241.  
  242. ifeq ($(USERENDERCHECKGL),1)
  243. RENDERCHECKGLLIB := -lrendercheckgl_$(LIB_ARCH)$(LIBSUFFIX)
  244. endif
  245.  
  246. ifeq ($(USECUDPP), 1)
  247. CUDPPLIB := -lcudpp_$(CUDPPLIB_SUFFIX)$(LIBSUFFIX)
  248.  
  249. ifeq ($(emu), 1)
  250. CUDPPLIB := $(CUDPPLIB)_emu
  251. endif
  252. endif
  253.  
  254. ifeq ($(USENVCUVID), 1)
  255. ifneq ($(DARWIN),)
  256. NVCUVIDLIB := -L../../common/lib/darwin -lnvcuvid
  257. endif
  258. endif
  259.  
  260. # Libs
  261. ifneq ($(DARWIN),)
  262. LIB := -L$(CUDA_INSTALL_PATH)/lib -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER) -L$(SHAREDDIR)/lib $(NVCUVIDLIB)
  263. else
  264. ifeq "$(strip $(HP_64))" ""
  265. ifeq ($(x86_64),1)
  266. LIB := -L$(CUDA_INSTALL_PATH)/lib64 -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER) -L$(SHAREDDIR)/lib
  267. else
  268. LIB := -L$(CUDA_INSTALL_PATH)/lib -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER) -L$(SHAREDDIR)/lib
  269. endif
  270. else
  271. ifeq ($(i386),1)
  272. LIB := -L$(CUDA_INSTALL_PATH)/lib -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER) -L$(SHAREDDIR)/lib
  273. else
  274. LIB := -L$(CUDA_INSTALL_PATH)/lib64 -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER) -L$(SHAREDDIR)/lib
  275. endif
  276. endif
  277. endif
  278.  
  279. # If dynamically linking to CUDA and CUDART, we exclude the libraries from the LIB
  280. ifeq ($(USECUDADYNLIB),1)
  281. LIB += ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB} -ldl -rdynamic
  282. else
  283. # static linking, we will statically link against CUDA and CUDART
  284. ifeq ($(USEDRVAPI),1)
  285. LIB += -lcuda ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}
  286. else
  287. ifeq ($(emu),1)
  288. LIB += -lcudartemu
  289. else
  290. LIB += -lcudart
  291. endif
  292. LIB += ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}
  293. endif
  294. endif
  295.  
  296. ifeq ($(USECUFFT),1)
  297. ifeq ($(emu),1)
  298. LIB += -lcufftemu
  299. else
  300. LIB += -lcufft
  301. endif
  302. endif
  303.  
  304. ifeq ($(USECUBLAS),1)
  305. ifeq ($(emu),1)
  306. LIB += -lcublasemu
  307. else
  308. LIB += -lcublas
  309. endif
  310. endif
  311.  
  312. ifeq ($(USEOPENCV),1)
  313. LIB += -lhighgui
  314. endif
  315.  
  316. # Lib/exe configuration
  317. ifneq ($(STATIC_LIB),)
  318. TARGETDIR := $(LIBDIR)
  319. TARGET := $(subst .a,_$(LIB_ARCH)$(LIBSUFFIX).a,$(LIBDIR)/$(STATIC_LIB))
  320. LINKLINE = ar rucv $(TARGET) $(OBJS)
  321. else
  322. # LIB += $(DIRJSLIB)
  323. ifneq ($(OMIT_CUTIL_LIB),1)
  324. LIB += -lcutil_$(LIB_ARCH)$(LIBSUFFIX) -lshrutil_$(LIB_ARCH)$(LIBSUFFIX)
  325. endif
  326. # Device emulation configuration
  327. ifeq ($(emu), 1)
  328. NVCCFLAGS += -deviceemu
  329. CUDACCFLAGS +=
  330. BINSUBDIR := emu$(BINSUBDIR)
  331. # consistency, makes developing easier
  332. CXXFLAGS += -D__DEVICE_EMULATION__
  333. CFLAGS += -D__DEVICE_EMULATION__
  334. endif
  335. TARGETDIR := $(BINDIR)/$(BINSUBDIR)
  336. TARGET := $(TARGETDIR)/$(EXECUTABLE)
  337. LINKLINE = $(LINK) -o $(TARGET) $(OBJS) $(LIB)
  338. endif
  339.  
  340. # check if verbose
  341. ifeq ($(verbose), 1)
  342. VERBOSE :=
  343. else
  344. VERBOSE := @
  345. endif
  346.  
  347. ################################################################################
  348. # Check for input flags and set compiler flags appropriately
  349. ################################################################################
  350. ifeq ($(fastmath), 1)
  351. NVCCFLAGS += -use_fast_math
  352. endif
  353.  
  354. ifeq ($(keep), 1)
  355. NVCCFLAGS += -keep
  356. NVCC_KEEP_CLEAN := *.i* *.cubin *.cu.c *.cudafe* *.fatbin.c *.ptx
  357. endif
  358.  
  359. ifdef maxregisters
  360. NVCCFLAGS += -maxrregcount $(maxregisters)
  361. endif
  362.  
  363. # Add cudacc flags
  364. NVCCFLAGS += $(CUDACCFLAGS)
  365.  
  366. # Add common flags
  367. NVCCFLAGS += $(COMMONFLAGS)
  368. CXXFLAGS += $(COMMONFLAGS)
  369. CFLAGS += $(COMMONFLAGS)
  370.  
  371. ifeq ($(nvcc_warn_verbose),1)
  372. NVCCFLAGS += $(addprefix --compiler-options ,$(CXXWARN_FLAGS))
  373. NVCCFLAGS += --compiler-options -fno-strict-aliasing
  374. endif
  375.  
  376. ################################################################################
  377. # Set up object files
  378. ################################################################################
  379. OBJDIR := $(ROOTOBJDIR)/$(LIB_ARCH)/$(BINSUBDIR)
  380. OBJS += $(patsubst %.cpp,$(OBJDIR)/%.cpp.o,$(notdir $(CCFILES)))
  381. OBJS += $(patsubst %.c,$(OBJDIR)/%.c.o,$(notdir $(CFILES)))
  382. OBJS += $(patsubst %.cu,$(OBJDIR)/%.cu.o,$(notdir $(CUFILES)))
  383.  
  384. ################################################################################
  385. # Set up cubin output files
  386. ################################################################################
  387. CUBINDIR := $(SRCDIR)data
  388. CUBINS += $(patsubst %.cu,$(CUBINDIR)/%.cubin,$(notdir $(CUBINFILES)))
  389.  
  390. ################################################################################
  391. # Set up PTX output files
  392. ################################################################################
  393. PTXDIR := $(SRCDIR)data
  394. PTXBINS += $(patsubst %.cu,$(PTXDIR)/%.ptx,$(notdir $(PTXFILES)))
  395.  
  396. ################################################################################
  397. # Rules
  398. ################################################################################
  399. $(OBJDIR)/%.c.o : $(SRCDIR)%.c $(C_DEPS)
  400. $(VERBOSE)$(CC) $(CFLAGS) -o $@ -c $<
  401.  
  402. $(OBJDIR)/%.cpp.o : $(SRCDIR)%.cpp $(C_DEPS)
  403. $(VERBOSE)$(CXX) $(CXXFLAGS) -o $@ -c $<
  404.  
  405. # Default arch includes gencode for sm_10, sm_20, and other archs from GENCODE_ARCH declared in the makefile
  406. $(OBJDIR)/%.cu.o : $(SRCDIR)%.cu $(CU_DEPS)
  407. $(VERBOSE)$(NVCC) $(GENCODE_SM10) $(GENCODE_ARCH) $(GENCODE_SM20) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $@ -c $<
  408.  
  409. # Default arch includes gencode for sm_10, sm_20, and other archs from GENCODE_ARCH declared in the makefile
  410. $(CUBINDIR)/%.cubin : $(SRCDIR)%.cu cubindirectory
  411. $(VERBOSE)$(NVCC) $(GENCODE_SM10) $(GENCODE_ARCH) $(GENCODE_SM20) $(CUBIN_ARCH_FLAG) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $@ -cubin $<
  412.  
  413. $(PTXDIR)/%.ptx : $(SRCDIR)%.cu ptxdirectory
  414. $(VERBOSE)$(NVCC) $(CUBIN_ARCH_FLAG) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $@ -ptx $<
  415.  
  416. #
  417. # The following definition is a template that gets instantiated for each SM
  418. # version (sm_10, sm_13, etc.) stored in SMVERSIONS. It does 2 things:
  419. # 1. It adds to OBJS a .cu_sm_XX.o for each .cu file it finds in CUFILES_sm_XX.
  420. # 2. It generates a rule for building .cu_sm_XX.o files from the corresponding
  421. # .cu file.
  422. #
  423. # The intended use for this is to allow Makefiles that use common.mk to compile
  424. # files to different Compute Capability targets (aka SM arch version). To do
  425. # so, in the Makefile, list files for each SM arch separately, like so:
  426. # This will be used over the default rule abov
  427. #
  428. # CUFILES_sm_10 := mycudakernel_sm10.cu app.cu
  429. # CUFILES_sm_12 := anothercudakernel_sm12.cu
  430. #
  431. define SMVERSION_template
  432. #OBJS += $(patsubst %.cu,$(OBJDIR)/%.cu_$(1).o,$(notdir $(CUFILES_$(1))))
  433. OBJS += $(patsubst %.cu,$(OBJDIR)/%.cu_$(1).o,$(notdir $(CUFILES_sm_$(1))))
  434. $(OBJDIR)/%.cu_$(1).o : $(SRCDIR)%.cu $(CU_DEPS)
  435. # $(VERBOSE)$(NVCC) -o $$@ -c $$< $(NVCCFLAGS) $(1)
  436. $(VERBOSE)$(NVCC) -gencode=arch=compute_$(1),code=\"sm_$(1),compute_$(1)\" $(GENCODE_SM20) -o $$@ -c $$< $(NVCCFLAGS)
  437. endef
  438.  
  439. # This line invokes the above template for each arch version stored in
  440. # SM_VERSIONS. The call funtion invokes the template, and the eval
  441. # function interprets it as make commands.
  442. $(foreach smver,$(SM_VERSIONS),$(eval $(call SMVERSION_template,$(smver))))
  443.  
  444. $(TARGET): makedirectories $(OBJS) $(CUBINS) $(PTXBINS) Makefile
  445. $(VERBOSE)$(LINKLINE)
  446.  
  447. cubindirectory:
  448. $(VERBOSE)mkdir -p $(CUBINDIR)
  449.  
  450. ptxdirectory:
  451. $(VERBOSE)mkdir -p $(PTXDIR)
  452.  
  453. makedirectories:
  454. $(VERBOSE)mkdir -p $(LIBDIR)
  455. $(VERBOSE)mkdir -p $(OBJDIR)
  456. $(VERBOSE)mkdir -p $(TARGETDIR)
  457.  
  458.  
  459. tidy :
  460. $(VERBOSE)find . | egrep "#" | xargs rm -f
  461. $(VERBOSE)find . | egrep "\~" | xargs rm -f
  462.  
  463. clean : tidy
  464. $(VERBOSE)rm -f $(OBJS)
  465. $(VERBOSE)rm -f $(CUBINS)
  466. $(VERBOSE)rm -f $(PTXBINS)
  467. $(VERBOSE)rm -f $(TARGET)
  468. $(VERBOSE)rm -f $(NVCC_KEEP_CLEAN)
  469. $(VERBOSE)rm -f $(ROOTBINDIR)/$(OSLOWER)/$(BINSUBDIR)/*.ppm
  470. $(VERBOSE)rm -f $(ROOTBINDIR)/$(OSLOWER)/$(BINSUBDIR)/*.pgm
  471. $(VERBOSE)rm -f $(ROOTBINDIR)/$(OSLOWER)/$(BINSUBDIR)/*.bin
  472. $(VERBOSE)rm -f $(ROOTBINDIR)/$(OSLOWER)/$(BINSUBDIR)/*.bmp
  473.  
  474. clobber : clean
  475. $(VERBOSE)rm -rf $(ROOTOBJDIR)
  476.  
  477. all : $(TARGET)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement