/docs/MyDocs

To get this branch, use:
bzr branch http://darksoft.org/webbzr/docs/MyDocs

« back to all changes in this revision

Viewing changes to Development/libraries/cuda/examples/common.mk

  • Committer: Suren A. Chilingaryan
  • Date: 2009-04-09 03:21:08 UTC
  • Revision ID: csa@dside.dyndns.org-20090409032108-w4edamdh4adrgdu3
import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
################################################################################
 
2
#
 
3
# Copyright 1993-2006 NVIDIA Corporation.  All rights reserved.
 
4
#
 
5
# NOTICE TO USER:   
 
6
#
 
7
# This source code is subject to NVIDIA ownership rights under U.S. and 
 
8
# international Copyright laws.  
 
9
#
 
10
# NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE 
 
11
# CODE FOR ANY PURPOSE.  IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR 
 
12
# IMPLIED WARRANTY OF ANY KIND.  NVIDIA DISCLAIMS ALL WARRANTIES WITH 
 
13
# REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF 
 
14
# MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.   
 
15
# IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, 
 
16
# OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 
 
17
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
 
18
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE 
 
19
# OR PERFORMANCE OF THIS SOURCE CODE.  
 
20
#
 
21
# U.S. Government End Users.  This source code is a "commercial item" as 
 
22
# that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting  of 
 
23
# "commercial computer software" and "commercial computer software 
 
24
# documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) 
 
25
# and is provided to the U.S. Government only as a commercial end item.  
 
26
# Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through 
 
27
# 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the 
 
28
# source code with only those rights set forth herein.
 
29
#
 
30
################################################################################
 
31
#
 
32
# Common build script
 
33
#
 
34
################################################################################
 
35
 
 
36
.SUFFIXES : .cu .cu_dbg_o .c_dbg_o .cpp_dbg_o .cu_rel_o .c_rel_o .cpp_rel_o .cubin
 
37
 
 
38
# Add new SM Versions here as devices with new Compute Capability are released
 
39
SM_VERSIONS := sm_10 sm_11 sm_12 sm_13
 
40
 
 
41
CUDA_INSTALL_PATH ?= /opt/cuda
 
42
 
 
43
ifdef cuda-install
 
44
        CUDA_INSTALL_PATH := $(cuda-install)
 
45
endif
 
46
 
 
47
# detect OS
 
48
OSUPPER = $(shell uname -s 2>/dev/null | tr [:lower:] [:upper:])
 
49
OSLOWER = $(shell uname -s 2>/dev/null | tr [:upper:] [:lower:])
 
50
# 'linux' is output for Linux system, 'darwin' for OS X
 
51
DARWIN = $(strip $(findstring DARWIN, $(OSUPPER)))
 
52
 
 
53
# Basic directory setup for SDK
 
54
# (override directories only if they are not already defined)
 
55
SRCDIR     ?= 
 
56
ROOTDIR    ?= ..
 
57
ROOTBINDIR ?= ./
 
58
BINDIR     ?= ./
 
59
ROOTOBJDIR ?= obj
 
60
LIBDIR     := /opt/cuda/sdk/lib
 
61
COMMONDIR  := /opt/cuda/sdk/common
 
62
 
 
63
# Compilers
 
64
NVCC       := $(CUDA_INSTALL_PATH)/bin/nvcc 
 
65
CXX        := g++-4.2.4
 
66
CC         := gcc-4.2.4
 
67
LINK       := g++-4.2.4 -fPIC
 
68
 
 
69
# Includes
 
70
INCLUDES  += -I. -I$(CUDA_INSTALL_PATH)/include -I$(COMMONDIR)/inc
 
71
 
 
72
# architecture flag for cubin build
 
73
CUBIN_ARCH_FLAG := -m32
 
74
 
 
75
# Warning flags
 
76
CXXWARN_FLAGS := \
 
77
        -W -Wall \
 
78
        -Wimplicit \
 
79
        -Wswitch \
 
80
        -Wformat \
 
81
        -Wchar-subscripts \
 
82
        -Wparentheses \
 
83
        -Wmultichar \
 
84
        -Wtrigraphs \
 
85
        -Wpointer-arith \
 
86
        -Wcast-align \
 
87
        -Wreturn-type \
 
88
        -Wno-unused-function \
 
89
        $(SPACE)
 
90
 
 
91
CWARN_FLAGS := $(CXXWARN_FLAGS) \
 
92
        -Wstrict-prototypes \
 
93
        -Wmissing-prototypes \
 
94
        -Wmissing-declarations \
 
95
        -Wnested-externs \
 
96
        -Wmain \
 
97
 
 
98
# Compiler-specific flags
 
99
NVCCFLAGS := 
 
100
CXXFLAGS  := $(CXXWARN_FLAGS)
 
101
CFLAGS    := $(CWARN_FLAGS)
 
102
 
 
103
# Common flags
 
104
COMMONFLAGS += $(INCLUDES) -DUNIX
 
105
 
 
106
# Debug/release configuration
 
107
ifeq ($(dbg),1)
 
108
        COMMONFLAGS += -g
 
109
        NVCCFLAGS   += -D_DEBUG
 
110
        BINSUBDIR   := debug
 
111
        LIBSUFFIX   := D
 
112
else 
 
113
        COMMONFLAGS += -O3 
 
114
        BINSUBDIR   := release
 
115
        LIBSUFFIX   :=
 
116
        NVCCFLAGS   += --compiler-options -fno-strict-aliasing
 
117
        CXXFLAGS    += -fno-strict-aliasing
 
118
        CFLAGS      += -fno-strict-aliasing
 
119
endif
 
120
 
 
121
# append optional arch/SM version flags (such as -arch sm_11)
 
122
#NVCCFLAGS += $(SMVERSIONFLAGS)
 
123
 
 
124
# architecture flag for cubin build
 
125
CUBIN_ARCH_FLAG := -m32
 
126
 
 
127
# detect if 32 bit or 64 bit system
 
128
HP_64 = $(shell uname -m | grep 64)
 
129
 
 
130
# OpenGL is used or not (if it is used, then it is necessary to include GLEW)
 
131
ifeq ($(USEGLLIB),1)
 
132
 
 
133
        ifneq ($(DARWIN),)
 
134
                OPENGLLIB := -L/System/Library/Frameworks/OpenGL.framework/Libraries -lGL -lGLU $(COMMONDIR)/lib/$(OSLOWER)/libGLEW.a
 
135
        else
 
136
                OPENGLLIB := -lGL -lGLU
 
137
 
 
138
                ifeq "$(strip $(HP_64))" ""
 
139
                        OPENGLLIB += -lGLEW
 
140
                else
 
141
                        OPENGLLIB += -lGLEW_x86_64
 
142
                endif
 
143
        endif
 
144
 
 
145
        CUBIN_ARCH_FLAG := -m64
 
146
endif
 
147
 
 
148
ifeq ($(USEGLUT),1)
 
149
        ifneq ($(DARWIN),)
 
150
                OPENGLLIB += -framework GLUT
 
151
        else
 
152
                OPENGLLIB += -lglut
 
153
        endif
 
154
endif
 
155
 
 
156
ifeq ($(USEPARAMGL),1)
 
157
        PARAMGLLIB := -lparamgl$(LIBSUFFIX)
 
158
endif
 
159
 
 
160
ifeq ($(USERENDERCHECKGL),1)
 
161
        RENDERCHECKGLLIB := -lrendercheckgl$(LIBSUFFIX)
 
162
endif
 
163
 
 
164
ifeq ($(USECUDPP), 1)
 
165
        ifeq "$(strip $(HP_64))" ""
 
166
                CUDPPLIB := -lcudpp
 
167
        else
 
168
                CUDPPLIB := -lcudpp64
 
169
        endif
 
170
 
 
171
        CUDPPLIB := $(CUDPPLIB)$(LIBSUFFIX)
 
172
 
 
173
        ifeq ($(emu), 1)
 
174
                CUDPPLIB := $(CUDPPLIB)_emu
 
175
        endif
 
176
endif
 
177
 
 
178
# Libs
 
179
LIB       := -L$(CUDA_INSTALL_PATH)/lib -L$(LIBDIR) -L$(COMMONDIR)/lib/$(OSLOWER)
 
180
ifeq ($(USEDRVAPI),1)
 
181
   LIB += -lcuda ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB} 
 
182
else
 
183
   LIB += -lcudart ${OPENGLLIB} $(PARAMGLLIB) $(RENDERCHECKGLLIB) $(CUDPPLIB) ${LIB}
 
184
endif
 
185
 
 
186
ifeq ($(USECUFFT),1)
 
187
  ifeq ($(emu),1)
 
188
    LIB += -lcufftemu
 
189
  else
 
190
    LIB += -lcufft
 
191
  endif
 
192
endif
 
193
 
 
194
ifeq ($(USECUBLAS),1)
 
195
  ifeq ($(emu),1)
 
196
    LIB += -lcublasemu
 
197
  else
 
198
    LIB += -lcublas
 
199
  endif
 
200
endif
 
201
 
 
202
# Lib/exe configuration
 
203
ifneq ($(STATIC_LIB),)
 
204
        TARGETDIR := $(LIBDIR)
 
205
        TARGET   := $(subst .a,$(LIBSUFFIX).a,$(LIBDIR)/$(STATIC_LIB))
 
206
        LINKLINE  = ar qv $(TARGET) $(OBJS) 
 
207
else
 
208
        LIB += -lcutil$(LIBSUFFIX)
 
209
        # Device emulation configuration
 
210
        ifeq ($(emu), 1)
 
211
                NVCCFLAGS   += -deviceemu
 
212
                CUDACCFLAGS += 
 
213
                BINSUBDIR   := emu$(BINSUBDIR)
 
214
                # consistency, makes developing easier
 
215
                CXXFLAGS                += -D__DEVICE_EMULATION__
 
216
                CFLAGS                  += -D__DEVICE_EMULATION__
 
217
        endif
 
218
        TARGETDIR := $(BINDIR)/$(BINSUBDIR)
 
219
        TARGET    := $(TARGETDIR)/$(EXECUTABLE)
 
220
        LINKLINE  = $(LINK) -o $(TARGET) $(OBJS) $(LIB)
 
221
endif
 
222
 
 
223
# check if verbose 
 
224
ifeq ($(verbose), 1)
 
225
        VERBOSE :=
 
226
else
 
227
        VERBOSE := @
 
228
endif
 
229
 
 
230
################################################################################
 
231
# Check for input flags and set compiler flags appropriately
 
232
################################################################################
 
233
ifeq ($(fastmath), 1)
 
234
        NVCCFLAGS += -use_fast_math
 
235
endif
 
236
 
 
237
ifeq ($(keep), 1)
 
238
        NVCCFLAGS += -keep
 
239
        NVCC_KEEP_CLEAN := *.i* *.cubin *.cu.c *.cudafe* *.fatbin.c *.ptx
 
240
endif
 
241
 
 
242
ifdef maxregisters
 
243
        NVCCFLAGS += -maxrregcount $(maxregisters)
 
244
endif
 
245
 
 
246
# Add cudacc flags
 
247
NVCCFLAGS += $(CUDACCFLAGS)
 
248
 
 
249
# workaround for mac os x cuda 1.1 compiler issues
 
250
ifneq ($(DARWIN),)
 
251
        NVCCFLAGS += --host-compilation=C
 
252
endif
 
253
 
 
254
# Add common flags
 
255
NVCCFLAGS += $(COMMONFLAGS)
 
256
CXXFLAGS  += $(COMMONFLAGS)
 
257
CFLAGS    += $(COMMONFLAGS)
 
258
 
 
259
ifeq ($(nvcc_warn_verbose),1)
 
260
        NVCCFLAGS += $(addprefix --compiler-options ,$(CXXWARN_FLAGS)) 
 
261
        NVCCFLAGS += --compiler-options -fno-strict-aliasing
 
262
endif
 
263
 
 
264
################################################################################
 
265
# Set up object files
 
266
################################################################################
 
267
OBJDIR := $(ROOTOBJDIR)/$(BINSUBDIR)
 
268
OBJS +=  $(patsubst %.cpp,$(OBJDIR)/%.cpp_o,$(notdir $(CCFILES)))
 
269
OBJS +=  $(patsubst %.c,$(OBJDIR)/%.c_o,$(notdir $(CFILES)))
 
270
OBJS +=  $(patsubst %.cu,$(OBJDIR)/%.cu_o,$(notdir $(CUFILES)))
 
271
 
 
272
################################################################################
 
273
# Set up cubin files
 
274
################################################################################
 
275
CUBINDIR := $(SRCDIR)data
 
276
CUBINS +=  $(patsubst %.cu,$(CUBINDIR)/%.cubin,$(notdir $(CUBINFILES)))
 
277
 
 
278
################################################################################
 
279
# Rules
 
280
################################################################################
 
281
$(OBJDIR)/%.c_o : $(SRCDIR)%.c $(C_DEPS)
 
282
        $(VERBOSE)$(CC) $(CFLAGS) -o $@ -c $<
 
283
 
 
284
$(OBJDIR)/%.cpp_o : $(SRCDIR)%.cpp $(C_DEPS)
 
285
        $(VERBOSE)$(CXX) $(CXXFLAGS) -o $@ -c $<
 
286
 
 
287
$(OBJDIR)/%.cu_o : $(SRCDIR)%.cu $(CU_DEPS)
 
288
        $(VERBOSE)$(NVCC) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $@ -c $<
 
289
 
 
290
$(CUBINDIR)/%.cubin : $(SRCDIR)%.cu cubindirectory
 
291
        $(VERBOSE)$(NVCC) $(CUBIN_ARCH_FLAG) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $@ -cubin $<
 
292
 
 
293
#
 
294
# The following definition is a template that gets instantiated for each SM
 
295
# version (sm_10, sm_13, etc.) stored in SMVERSIONS.  It does 2 things:
 
296
# 1. It adds to OBJS a .cu_sm_XX_o for each .cu file it finds in CUFILES_sm_XX.
 
297
# 2. It generates a rule for building .cu_sm_XX_o files from the corresponding 
 
298
#    .cu file.
 
299
#
 
300
# The intended use for this is to allow Makefiles that use common.mk to compile
 
301
# files to different Compute Capability targets (aka SM arch version).  To do
 
302
# so, in the Makefile, list files for each SM arch separately, like so:
 
303
#
 
304
# CUFILES_sm_10 := mycudakernel_sm10.cu app.cu
 
305
# CUFILES_sm_12 := anothercudakernel_sm12.cu
 
306
#
 
307
define SMVERSION_template
 
308
OBJS += $(patsubst %.cu,$(OBJDIR)/%.cu_$(1)_o,$(notdir $(CUFILES_$(1))))
 
309
$(OBJDIR)/%.cu_$(1)_o : $(SRCDIR)%.cu $(CU_DEPS)
 
310
        $(VERBOSE)$(NVCC) -o $$@ -c $$< $(NVCCFLAGS) -arch $(1)
 
311
endef
 
312
 
 
313
# This line invokes the above template for each arch version stored in
 
314
# SM_VERSIONS.  The call funtion invokes the template, and the eval
 
315
# function interprets it as make commands.
 
316
$(foreach smver,$(SM_VERSIONS),$(eval $(call SMVERSION_template,$(smver))))
 
317
 
 
318
$(TARGET): makedirectories $(OBJS) $(CUBINS) Makefile
 
319
        $(VERBOSE)$(LINKLINE)
 
320
 
 
321
cubindirectory:
 
322
        $(VERBOSE)mkdir -p $(CUBINDIR)
 
323
 
 
324
makedirectories:
 
325
        $(VERBOSE)mkdir -p $(LIBDIR)
 
326
        $(VERBOSE)mkdir -p $(OBJDIR)
 
327
        $(VERBOSE)mkdir -p $(TARGETDIR)
 
328
 
 
329
 
 
330
tidy :
 
331
        $(VERBOSE)find . | egrep "#" | xargs rm -f
 
332
        $(VERBOSE)find . | egrep "\~" | xargs rm -f
 
333
 
 
334
clean : tidy
 
335
        $(VERBOSE)rm -f $(OBJS)
 
336
        $(VERBOSE)rm -f $(CUBINS)
 
337
        $(VERBOSE)rm -f $(TARGET)
 
338
        $(VERBOSE)rm -f $(NVCC_KEEP_CLEAN)
 
339
 
 
340
clobber : clean
 
341
        $(VERBOSE)rm -rf $(ROOTOBJDIR)