forked from Media-Smart/cheetahinfer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.config
217 lines (186 loc) · 8.08 KB
/
Makefile.config
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
.SUFFIXES:
CUDA_TRIPLE?=x86_64-linux
CUBLAS_TRIPLE?=x86_64-linux-gnu
DLSW_TRIPLE?=x86_64-linux-gnu
TARGET?=$(shell uname -m)
ifeq ($(CUDA_INSTALL_DIR),)
$(warning CUDA_INSTALL_DIR variable is not specified, using /usr/local/cuda by default, use CUDA_INSTALL_DIR=<cuda_directory> to change.)
endif
ifeq ($(CUDNN_INSTALL_DIR),)
$(warning CUDNN_INSTALL_DIR variable is not specified, using $$CUDA_INSTALL_DIR by default, use CUDNN_INSTALL_DIR=<cudnn_directory> to change.)
endif
CUDA_INSTALL_DIR?=/usr/local/cuda-10.1
CUDNN_INSTALL_DIR?=$(CUDA_INSTALL_DIR)
TENSORRT_INSTALL_DIR?=/home/yichaoxiong/opt
OPENCV_INSTALL_DIR?=/home/yichaoxiong/opt
CUDA_LIBDIR=lib
CUDNN_LIBDIR=lib64
CUDA_ARCH := -gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=sm_50 \
-gencode arch=compute_52,code=sm_52 \
-gencode arch=compute_60,code=sm_60 \
-gencode arch=compute_61,code=sm_61 \
-gencode arch=compute_61,code=compute_61
ifeq ($(TARGET), aarch64)
ifeq ($(shell uname -m), aarch64)
CUDA_LIBDIR=lib64
CC = g++
else
CC = aarch64-linux-gnu-g++
endif
CUCC =$(CUDA_INSTALL_DIR)/bin/nvcc -m64 -ccbin $(CC)
else ifeq ($(TARGET), x86_64)
CUDA_LIBDIR=lib64
CC = g++
CUCC =$(CUDA_INSTALL_DIR)/bin/nvcc -m64
else ifeq ($(TARGET), ppc64le)
CUDA_LIBDIR=lib64
CC = g++
CUCC = $(CUDA_INSTALL_DIR)/bin/nvcc -m64
else ifeq ($(TARGET), qnx)
CC = ${QNX_HOST}/usr/bin/aarch64-unknown-nto-qnx7.0.0-g++
CUCC = $(CUDA_INSTALL_DIR)/bin/nvcc -m64 -ccbin $(CC)
else ifeq ($(TARGET), android64)
ifeq ($(ANDROID_CC),)
$(error ANDROID_CC must be set to the clang compiler to build for android 64bit, for example /path/to/my-toolchain/bin/aarch64-linux-android-clang++)
endif
CUDA_LIBDIR=lib
ANDROID_FLAGS=-DANDROID -D_GLIBCXX_USE_C99=1 -Wno-sign-compare -D__aarch64__ -Wno-strict-aliasing -Werror -pie -fPIE -Wno-unused-command-line-argument
COMMON_FLAGS+=$(ANDROID_FLAGS)
COMMON_LD_FLAGS+=$(ANDROID_FLAGS)
CC=$(ANDROID_CC)
CUCC = $(CUDA_INSTALL_DIR)/bin/nvcc -m64 -ccbin $(CC) --compiler-options="-DANDROID -D_GLIBCXX_USE_C99=1 -Wno-sign-compare"
ANDROID=1
else ########
$(error Auto-detection of platform failed. Please specify one of the following arguments to make: TARGET=[aarch64|x86_64|qnx|android64])
endif
ifdef VERBOSE
AT=
else
AT=@
endif
AR = ar cr
ECHO = @echo
SHELL=/bin/sh
ROOT_PATH=build
OUT_PATH=$(ROOT_PATH)
OUTDIR=$(OUT_PATH)
define concat
$1$2$3$4$5$6$7$8
endef
#$(call make-depend,source-file,object-file,depend-file)
define make-depend
$(AT)$(CC) $(COMMON_FLAGS) -MM -MF $3 -MP -MT $2 $1
endef
#$(call make-cuda-depend,source-file,object-file,depend-file,flags)
define make-cuda-depend
$(AT)$(CUCC) $(CUDA_ARCH) $(CUFLAGS) -M -MT $2 $1 > $3
endef
#########################
INCPATHS=
LIBPATHS=
# add cross compile directories
ifneq ($(shell uname -m), $(TARGET))
INCPATHS += -I/usr/include/$(DLSW_TRIPLE) -I/usr/include/$(CUBLAS_TRIPLE)
LIBPATHS += -L/usr/lib/$(DLSW_TRIPLE)/stubs -L/usr/lib/$(DLSW_TRIPLE) -L/usr/lib/$(CUBLAS_TRIPLE)/stubs -L/usr/lib/$(CUBLAS_TRIPLE) -L$(CUDA_INSTALL_DIR)/targets/$(CUDA_TRIPLE)/$(CUDA_LIBDIR)/stubs -L$(CUDA_INSTALL_DIR)/targets/$(CUDA_TRIPLE)/$(CUDA_LIBDIR)
endif
INCPATHS += -I$(TENSORRT_INSTALL_DIR)/include/tensorrt
INCPATHS += -I$(OPENCV_INSTALL_DIR)/include/opencv
INCPATHS += $(addprefix -I, $(CUSTOM_INCPATHS)) -I$(CUDA_INSTALL_DIR)/include -I$(CUDNN_INSTALL_DIR)/include
LIBPATHS += -L$(CUDA_INSTALL_DIR)/$(CUDA_LIBDIR) -L$(CUDNN_INSTALL_DIR)/$(CUDNN_LIBDIR)
LIBPATHS += -L$(TENSORRT_INSTALL_DIR)/lib/tensorrt
LIBPATHS += -L$(OPENCV_INSTALL_DIR)/lib/opencv
.SUFFIXES:
vpath %.h $(CUSTOM_INCPATHS) #$(EXTRA_DIRECTORIES)
vpath %.cpp $(CUSTOM_SRCPATHS) #$(EXTRA_DIRECTORIES)
vpath %.cu $(CUSTOM_SRCPATHS) #$(EXTRA_DIRECTORIES)
COMMON_FLAGS += -Ofast -Wall -Wno-deprecated-declarations -std=c++11 $(INCPATHS)
ifneq ($(ANDROID),1)
COMMON_FLAGS += -D_REENTRANT
endif
ifeq ($(TARGET), qnx)
COMMON_FLAGS += -D_POSIX_C_SOURCE=200112L -D_QNX_SOURCE -D_FILE_OFFSET_BITS=64 -fpermissive
endif
COMMON_LD_FLAGS += $(LIBPATHS) -L$(OUTDIR)
OBJDIR =$(call concat,$(OUTDIR),/chobj)
DOBJDIR =$(call concat,$(OUTDIR),/dchobj)
COMMON_LIBS = -lcudnn -lcublas -lcudart
COMMON_LIBS += -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs
ifneq ($(TARGET), qnx)
ifneq ($(ANDROID),1)
COMMON_LIBS += -lrt -ldl -lpthread
endif
endif
ifeq ($(ANDROID),1)
COMMON_LIBS += -lculibos -llog
endif
LIBS =-lnvinfer -lnvparsers -lnvinfer_plugin -lnvonnxparser $(COMMON_LIBS)
DLIBS =-lnvinfer -lnvparsers -lnvinfer_plugin -lnvonnxparser $(COMMON_LIBS)
OBJS =$(patsubst %.cpp, $(OBJDIR)/%.o, $(wildcard *.cpp $(addsuffix /*.cpp, $(CUSTOM_SRCPATHS))))
DOBJS =$(patsubst %.cpp, $(DOBJDIR)/%.o, $(wildcard *.cpp $(addsuffix /*.cpp, $(CUSTOM_SRCPATHS))))
CUOBJS =$(patsubst %.cu, $(OBJDIR)/%.o, $(wildcard *.cu $(addsuffix /*.cu, $(CUSTOM_SRCPATHS))))
CUDOBJS =$(patsubst %.cu, $(DOBJDIR)/%.o, $(wildcard *.cu $(addsuffix /*.cu, $(CUSTOM_SRCPATHS))))
CFLAGS=$(COMMON_FLAGS)
CUFLAGS=$(INCPATHS) -std=c++11 --expt-extended-lambda
CFLAGSD=$(COMMON_FLAGS) -g
CUFLAGSD=$(INCPATHS) -std=c++11 --expt-extended-lambda
LFLAGS=$(COMMON_LD_FLAGS)
LFLAGSD=$(COMMON_LD_FLAGS)
all: debug release
release : $(OUTDIR)/$(OUTNAME_RELEASE)
debug : $(OUTDIR)/$(OUTNAME_DEBUG)
test: test_debug test_release
test_debug:
$(AT)cd $(OUTDIR) && ./$(OUTNAME_DEBUG)
test_release:
$(AT)cd $(OUTDIR) && ./$(OUTNAME_RELEASE)
$(OUTDIR)/$(OUTNAME_RELEASE) : $(OBJS) $(CUOBJS)
$(ECHO) Linking: $@
$(AT)$(CC) -o $@ $^ $(LFLAGS) -Wl,--start-group $(LIBS) -Wl,--end-group
# Copy every EXTRA_FILE of this sample to bin dir
$(foreach EXTRA_FILE,$(EXTRA_FILES), cp -f $(EXTRA_FILE) $(OUTDIR)/$(EXTRA_FILE); )
$(OUTDIR)/$(OUTNAME_DEBUG) : $(DOBJS) $(CUDOBJS)
$(ECHO) Linking: $@
$(AT)$(CC) -o $@ $^ $(LFLAGSD) -Wl,--start-group $(DLIBS) -Wl,--end-group
$(OBJDIR)/%.o: %.cpp
$(AT)if [ ! -d $(OBJDIR) ]; then mkdir -p $(OBJDIR); fi
$(foreach XDIR,$(CUSTOM_SRCPATHS), if [ ! -d $(OBJDIR)/$(XDIR) ]; then mkdir -p $(OBJDIR)/$(XDIR); fi;) :
$(call make-depend,$<,$@,$(subst .o,.d,$@))
$(ECHO) [OBJDIR] Compiling: $<
$(AT)$(CC) $(CFLAGS) -c -o $@ $<
$(DOBJDIR)/%.o: %.cpp
$(AT)if [ ! -d $(DOBJDIR) ]; then mkdir -p $(DOBJDIR); fi
$(foreach XDIR,$(CUSTOM_SRCPATHS), if [ ! -d $(OBJDIR)/$(XDIR) ]; then mkdir -p $(DOBJDIR)/$(XDIR); fi;) :
$(call make-depend,$<,$@,$(subst .o,.d,$@))
$(ECHO) [DOBJDIR] Compiling: $<
$(AT)$(CC) $(CFLAGSD) -c -o $@ $<
######################################################################### CU
$(OBJDIR)/%.o: %.cu
$(AT)if [ ! -d $(OBJDIR) ]; then mkdir -p $(OBJDIR); fi
$(foreach XDIR,$(CUSTOM_SRCPATHS), if [ ! -d $(OBJDIR)/$(XDIR) ]; then mkdir -p $(OBJDIR)/$(XDIR); fi;) :
$(call make-cuda-depend,$<,$@,$(subst .o,.d,$@))
$(ECHO) Compiling CUDA release: $<
$(AT)$(CUCC) $(CUDA_ARCH) $(CUFLAGS) -c -o $@ $<
$(DOBJDIR)/%.o: %.cu
$(AT)if [ ! -d $(DOBJDIR) ]; then mkdir -p $(DOBJDIR); fi
$(foreach XDIR,$(CUSTOM_SRCPATHS), if [ ! -d $(DOBJDIR)/$(XDIR) ]; then mkdir -p $(DOBJDIR)/$(XDIR); fi;) :
$(call make-cuda-depend,$<,$@,$(subst .o,.d,$@))
$(ECHO) Compiling CUDA debug: $<
$(AT)$(CUCC) $(CUDA_ARCH) $(CUFLAGSD) -c -o $@ $<
clean:
$(ECHO) Cleaning...
$(AT)rm -rf $(OUTDIR)/*
ifneq "$(MAKECMDGOALS)" "clean"
-include $(OBJDIR)/*.d $(DOBJDIR)/*.d
ifeq ($(DO_CUDNN_CHECK), 1)
# To display newlines in the message.
define _cudnn_missing_newline_5020fd0
endef
SHELL=/bin/bash
CUDNN_CHECK = $(shell echo -e '\#include <cudnn.h>\nint main(){ cudnnCreate(nullptr); return 0; }' | $(CC) -xc++ -o /dev/null $(CFLAGS) $(LFLAGS) - $(COMMON_LIBS) 2> /dev/null && echo 'passed_cudnn_exists_check')
ifneq ($(CUDNN_CHECK), passed_cudnn_exists_check)
$(error $(_cudnn_missing_newline_5020fd0)$(_cudnn_missing_newline_5020fd0)This sample requires CUDNN, but it could not be found.$(_cudnn_missing_newline_5020fd0)Please install CUDNN from https://developer.nvidia.com/cudnn or specify CUDNN_INSTALL_DIR when compiling.$(_cudnn_missing_newline_5020fd0)For example, `make CUDNN_INSTALL_DIR=/path/to/CUDNN/` where /path/to/CUDNN/ contains include/ and lib/ subdirectories.$(_cudnn_missing_newline_5020fd0)$(_cudnn_missing_newline_5020fd0))
endif # ifneq ($(CUDNN_CHECK), passed_cudnn_exists_check)
endif # ifeq ($(DO_CUDNN_CHECK), 1)
endif # ifneq "$(MAKECMDGOALS)" "clean"