forked from vlfeat/matconvnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
365 lines (313 loc) · 11.9 KB
/
Makefile
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# file: Makefile
# author: Andrea Vedaldi
# brief: matconvnet makefile for mex files
# Copyright (C) 2014-16 Andrea Vedaldi
# All rights reserved.
#
# This file is part of the VLFeat library and is made available under
# the terms of the BSD license (see the COPYING file).
# ENABLE_GPU -- Set to YES to enable GPU support (requires CUDA and the MATLAB Parallel Toolbox)
# ENABLE_CUDNN -- Set to YES to enable CUDNN support. This will also likely require
# ENABLE_IMREADJPEG -- Set to YES to compile the function VL_IMREADJPEG()
ENABLE_GPU ?=
ENABLE_CUDNN ?=
ENABLE_IMREADJPEG ?= yes
ENABLE_DOUBLE ?= yes
DEBUG ?=
ARCH ?= maci64
# Configure MATLAB
MATLABROOT ?= /Applications/MATLAB_R2017a.app
# Configure CUDA and CuDNN. CUDAMETHOD can be either 'nvcc' or 'mex'.
CUDAROOT ?= /Developer/NVIDIA/CUDA-8.0
CUDNNROOT ?= $(CURDIR)/local/
CUDAMETHOD ?= $(if $(ENABLE_CUDNN),nvcc,mex)
# Remark: each MATLAB version requires a particular CUDA Toolkit version.
# Note that multiple CUDA Toolkits can be installed.
#MATLABROOT ?= /Applications/MATLAB_R2014b.app
#CUDAROOT ?= /Developer/NVIDIA/CUDA-6.0
#MATLABROOT ?= /Applications/MATLAB_R2015a.app
#CUDAROOT ?= /Developer/NVIDIA/CUDA-7.0
#MATLABROOT ?= /Applications/MATLAB_R2015b.app
#CUDAROOT ?= /Developer/NVIDIA/CUDA-7.5
# Maintenance
NAME = matconvnet
VER = 1.0-beta24
DIST = $(NAME)-$(VER)
LATEST = $(NAME)-latest
RSYNC = rsync
HOST = vlfeat-admin:sites/sandbox-matconvnet
GIT = git
SHELL = /bin/bash # sh not good enough
# --------------------------------------------------------------------
# Configuration
# --------------------------------------------------------------------
# General options
MEX = $(MATLABROOT)/bin/mex
MEXEXT = $(MATLABROOT)/bin/mexext
MEXARCH = $(subst mex,,$(shell $(MEXEXT)))
MEXOPTS ?= matlab/src/config/mex_CUDA_$(ARCH).xml
NVCC = $(CUDAROOT)/bin/nvcc
comma:=,
space:=
space+=
join-with = $(subst $(space),$1,$(strip $2))
nvcc-quote = $(if $(strip $1),-Xcompiler $(call join-with,$(comma),$(1)),)
# Flags:
# 1. `CXXFLAGS`: passed to `mex` and `nvcc` compiler wrappers
# 2. `CXXFLAGS_PASS`: passed directly to the underlying C++ compiler
# 3. `LDFLAGS`: passed directly to the underlying C++ compiler for linking
# 4. `CXXOPTIMFLAGS`: passed directyl to the underlying C++ compiler
# 5. `LDOPTIMFLAGS`: passed directly to the underlying C++ compiler
# 6. `NVCCFLAGS_PASS`: passed directly to `nvcc` when invoked directly or through `mex`
CXXFLAGS = \
$(if $(ENABLE_GPU),-DENABLE_GPU,) \
$(if $(ENABLE_CUDNN),-DENABLE_CUDNN -I$(CUDNNROOT)/include,) \
$(if $(ENABLE_DOUBLE),-DENABLE_DOUBLE,) \
$(if $(VERB),-v,)
CXXFLAGS_PASS =
CXXOPTIMFLAGS =
LDFLAGS =
LDOPTIMFLAGS =
LINKLIBS = -lmwblas
NVCCFLAGS_PASS = -D_FORCE_INLINES -gencode=arch=compute_30,code=\"sm_30,compute_30\"
NVCCVER = $(shell $(NVCC) --version | \
sed -n 's/.*V\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\1 \2 \3/p' | \
xargs printf '%02d%02d%02d')
NVCCVER_LT_70 = $(shell test $(NVCCVER) -lt 070000 && echo true)
# Mac OS X
ifeq "$(ARCH)" "$(filter $(ARCH),maci64)"
IMAGELIB ?= $(if $(ENABLE_IMREADJPEG),quartz,none)
CXXFLAGS_PASS += -mmacosx-version-min=10.9
CXXOPTIMFLAGS += -mssse3 -ffast-math
LDFLAGS += \
-mmacosx-version-min=10.9 \
$(if $(ENABLE_GPU),-Wl$(comma)-rpath -Wl$(comma)"$(CUDAROOT)/lib") \
$(if $(ENABLE_CUDNN),-Wl$(comma)-rpath -Wl$(comma)"$(CUDNNROOT)/lib") \
$(if $(NVCCVER_LT_70),-stdlib=libstdc++)
LINKLIBS += \
$(if $(ENABLE_GPU),-L"$(CUDAROOT)/lib" -lmwgpu -lcudart -lcublas) \
$(if $(ENABLE_CUDNN),-L"$(CUDNNROOT)/lib" -lcudnn)
endif
# Linux
ifeq "$(ARCH)" "$(filter $(ARCH),glnxa64)"
IMAGELIB ?= $(if $(ENABLE_IMREADJPEG),libjpeg,none)
CXXOPTIMFLAGS += -mssse3 -ftree-vect-loop-version -ffast-math -funroll-all-loops
LDFLAGS += \
$(if $(ENABLE_GPU),-Wl$(comma)-rpath -Wl$(comma)"$(CUDAROOT)/lib64") \
$(if $(ENABLE_CUDNN),-Wl$(comma)-rpath -Wl$(comma)"$(CUDNNROOT)/lib64")
LINKLIBS += \
-lrt \
$(if $(ENABLE_GPU),-L"$(CUDAROOT)/lib64" -lmwgpu -lcudart -lcublas) \
$(if $(ENABLE_CUDNN),-L"$(CUDNNROOT)/lib64" -lcudnn)
endif
# Image library
ifeq ($(IMAGELIB),libjpeg)
LINKLIBS += -ljpeg
endif
ifeq ($(IMAGELIB),quartz)
LINKLIBS += -framework Cocoa -framework ImageIO
endif
MEXFLAGS = $(CXXFLAGS) -largeArrayDims
ifneq ($(DEBUG),)
MEXFLAGS += -g
NVCCFLAGS_PASS += -g -O0
else
MEXFLAGS += -DNDEBUG -O
NVCCFLAGS_PASS += -DNDEBUG -O3
# include debug symbol also in non-debug version
CXXOPTIMFLAGS += -g
LDOPTIMFLAGS += -g
NVCCFLAGS_PASS += -g
endif
# --------------------------------------------------------------------
# Build MEX files
# --------------------------------------------------------------------
nvcc_filter=2> >( sed 's/^\(.*\)(\([0-9][0-9]*\)): \([ew].*\)/\1:\2: \3/g' >&2 )
cpp_src :=
mex_src :=
# Files that are compiled as CPP or GPU (CUDA) depending on whether GPU support
# is enabled.
ext := $(if $(ENABLE_GPU),cu,cpp)
cpp_src+=matlab/src/bits/data.$(ext)
cpp_src+=matlab/src/bits/datamex.$(ext)
cpp_src+=matlab/src/bits/nnconv.$(ext)
cpp_src+=matlab/src/bits/nnbias.$(ext)
cpp_src+=matlab/src/bits/nnfullyconnected.$(ext)
cpp_src+=matlab/src/bits/nnsubsample.$(ext)
cpp_src+=matlab/src/bits/nnpooling.$(ext)
cpp_src+=matlab/src/bits/nnnormalize.$(ext)
cpp_src+=matlab/src/bits/nnbnorm.$(ext)
cpp_src+=matlab/src/bits/nnbilinearsampler.$(ext)
cpp_src+=matlab/src/bits/nnroipooling.$(ext)
mex_src+=matlab/src/vl_nnconv.$(ext)
mex_src+=matlab/src/vl_nnconvt.$(ext)
mex_src+=matlab/src/vl_nnpool.$(ext)
mex_src+=matlab/src/vl_nnnormalize.$(ext)
mex_src+=matlab/src/vl_nnbnorm.$(ext)
mex_src+=matlab/src/vl_nnbilinearsampler.$(ext)
mex_src+=matlab/src/vl_nnroipool.$(ext)
mex_src+=matlab/src/vl_taccummex.$(ext)
mex_src+=matlab/src/vl_tmove.$(ext)
ifdef ENABLE_IMREADJPEG
mex_src+=matlab/src/vl_imreadjpeg.$(ext)
mex_src+=matlab/src/vl_imreadjpeg_old.$(ext)
endif
# CPU-specific files
cpp_src+=matlab/src/bits/impl/im2row_cpu.cpp
cpp_src+=matlab/src/bits/impl/subsample_cpu.cpp
cpp_src+=matlab/src/bits/impl/copy_cpu.cpp
cpp_src+=matlab/src/bits/impl/pooling_cpu.cpp
cpp_src+=matlab/src/bits/impl/normalize_cpu.cpp
cpp_src+=matlab/src/bits/impl/bnorm_cpu.cpp
cpp_src+=matlab/src/bits/impl/bilinearsampler_cpu.cpp
cpp_src+=matlab/src/bits/impl/roipooling_cpu.cpp
cpp_src+=matlab/src/bits/impl/tinythread.cpp
ifdef ENABLE_IMREADJPEG
cpp_src+=matlab/src/bits/impl/imread_$(IMAGELIB).cpp
cpp_src+=matlab/src/bits/imread.cpp
endif
# GPU-specific files
ifdef ENABLE_GPU
cpp_src+=matlab/src/bits/impl/im2row_gpu.cu
cpp_src+=matlab/src/bits/impl/subsample_gpu.cu
cpp_src+=matlab/src/bits/impl/copy_gpu.cu
cpp_src+=matlab/src/bits/impl/pooling_gpu.cu
cpp_src+=matlab/src/bits/impl/normalize_gpu.cu
cpp_src+=matlab/src/bits/impl/bnorm_gpu.cu
cpp_src+=matlab/src/bits/impl/bilinearsampler_gpu.cu
cpp_src+=matlab/src/bits/impl/roipooling_gpu.cu
cpp_src+=matlab/src/bits/datacu.cu
mex_src+=matlab/src/vl_cudatool.cu
ifdef ENABLE_CUDNN
cpp_src+=matlab/src/bits/impl/nnconv_cudnn.cu
cpp_src+=matlab/src/bits/impl/nnpooling_cudnn.cu
cpp_src+=matlab/src/bits/impl/nnbias_cudnn.cu
cpp_src+=matlab/src/bits/impl/nnbilinearsampler_cudnn.cu
cpp_src+=matlab/src/bits/impl/nnbnorm_cudnn.cu
endif
endif
mex_tgt:=$(patsubst %.cpp,%.mex$(MEXARCH),$(mex_src))
mex_tgt:=$(patsubst %.cu,%.mex$(MEXARCH),$(mex_tgt))
mex_tgt:=$(subst matlab/src/,matlab/mex/,$(mex_tgt))
mex_obj:=$(patsubst %.cpp,%.o,$(mex_src))
mex_obj:=$(patsubst %.cu,%.o,$(mex_obj))
mex_obj:=$(subst matlab/src/,matlab/mex/.build/,$(mex_obj))
cpp_tgt:=$(patsubst %.cpp,%.o,$(cpp_src))
cpp_tgt:=$(patsubst %.cu,%.o,$(cpp_tgt))
cpp_tgt:=$(subst matlab/src/,matlab/mex/.build/,$(cpp_tgt))
.PHONY: all, distclean, clean, info, pack, post, post-doc, doc
all: $(cpp_tgt) $(mex_obj) $(mex_tgt)
# Create build directory
%/.stamp:
mkdir -p $(*)/ ; touch $(*)/.stamp
$(mex_tgt): matlab/mex/.build/bits/impl/.stamp
$(cpp_tgt): matlab/mex/.build/bits/impl/.stamp
# Standard code
.PRECIOUS: matlab/mex/.build/%.o
.PRECIOUS: %/.stamp
matlab/mex/.build/bits/impl/imread.o : matlab/src/bits/impl/imread_helpers.hpp
matlab/mex/.build/bits/impl/imread_quartz.o : matlab/src/bits/impl/imread_helpers.hpp
matlab/mex/.build/bits/impl/imread_gdiplus.o : matlab/src/bits/impl/imread_helpers.hpp
matlab/mex/.build/bits/impl/imread_libjpeg.o : matlab/src/bits/impl/imread_helpers.hpp
# --------------------------------------------------------------------
# Compilation rules
# --------------------------------------------------------------------
MEXFLAGS_CC_CPU := \
$(MEXFLAGS) \
CXXFLAGS='$$CXXFLAGS $(CXXFLAGS_PASS)' \
CXXOPTIMFLAGS='$$CXXOPTIMFLAGS $(CXXOPTIMFLAGS)'
MEXFLAGS_CC_GPU := \
-f "$(MEXOPTS)" \
$(MEXFLAGS) \
CXXFLAGS='$$CXXFLAGS $(NVCCFLAGS_PASS) $(call nvcc-quote,$(CXXFLAGS_PASS))' \
CXXOPTIMFLAGS='$$CXXOPTIMFLAGS $(call nvcc-quote,$(CXXOPTIMFLAGS))'
MEXFLAGS_LD := $(MEXFLAGS) \
LDFLAGS='$$LDFLAGS $(LDFLAGS)' \
LDOPTIMFLAGS='$$LDOPTIMFLAGS $(LDOPTIMFLAGS)' \
LINKLIBS='$(LINKLIBS) $$LINKLIBS' \
NVCCFLAGS = $(CXXFLAGS) $(NVCCFLAGS_PASS) \
-I"$(MATLABROOT)/extern/include" \
-I"$(MATLABROOT)/toolbox/distcomp/gpu/extern/include" \
$(call nvcc-quote,-fPIC $(CXXFLAGS_PASS) $(CXXOPTIMFLAGS))
ifneq ($(ENABLE_GPU),)
ifeq ($(CUDAMETHOD),mex)
matlab/mex/.build/%.o : matlab/src/%.cu matlab/mex/.build/.stamp
MW_NVCC_PATH='$(NVCC)' \
$(MEX) -c $(MEXFLAGS_CC_GPU) "$(<)" $(nvcc_filter)
mv -f "$(notdir $(@))" "$(@)"
else
matlab/mex/.build/%.o : matlab/src/%.cu matlab/mex/.build/.stamp
$(NVCC) $(NVCCFLAGS) "$(<)" -c -o "$(@)" $(nvcc_filter)
endif
endif
matlab/mex/.build/%.o : matlab/src/%.cpp matlab/src/%.cu matlab/mex/.build/.stamp
$(MEX) -c $(MEXFLAGS_CC_CPU) "$(<)"
mv -f "$(notdir $(@))" "$(@)"
matlab/mex/.build/%.o : matlab/src/%.cpp matlab/mex/.build/.stamp
$(MEX) -c $(MEXFLAGS_CC_CPU) "$(<)"
mv -f "$(notdir $(@))" "$(@)"
matlab/mex/%.mex$(MEXARCH) : matlab/mex/.build/%.o $(cpp_tgt)
$(MEX) $(MEXFLAGS_LD) "$(<)" -output "$(@)" $(cpp_tgt)
# --------------------------------------------------------------------
# Documentation
# --------------------------------------------------------------------
include doc/Makefile
# --------------------------------------------------------------------
# Maintenance
# --------------------------------------------------------------------
info: doc-info
@echo "mex_src=$(mex_src)"
@echo "mex_obj=$(mex_obj)"
@echo "mex_tgt=$(mex_tgt)"
@echo "cpp_src=$(cpp_src)"
@echo "cpp_tgt=$(cpp_tgt)"
@echo '------------------------------'
@echo 'CUDAMETHOD=$(CUDAMETHOD)'
@echo 'CXXFLAGS=$(CXXFLAGS)'
@echo 'CXXOPTIMFLAGS=$(CXXOPTIMFLAGS)'
@echo 'LDFLAGS=$(LDFLAGS)'
@echo 'LDOPTIMFLAGS=$(LDOPTIMFLAGS)'
@echo 'LINKLIBS=$(LINKLIBS)'
@echo '------------------------------'
@echo 'MEXARCH=$(MEXARCH)'
@echo 'MEXFLAGS=$(MEXFLAGS)'
@echo 'MEXFLAGS_CC_CPU=$(MEXFLAGS_CC_CPU)'
@echo 'MEXFLAGS_CC_GPU=$(MEXFLAGS_CC_GPU)'
@echo 'MEXFLAGS_LD=$(MEXFLAGS_LD)'
@echo '------------------------------'
@echo 'NVCC=$(NVCC)'
@echo 'NVCCVER=$(NVCCVER)'
@echo 'NVCCVER_LT_70=$(NVCCVER_LT_70)'
@echo 'NVCCFLAGS_PASS=$(NVCCFLAGS_PASS)'
@echo 'NVCCFLAGS=$(NVCCFLAGS)'
clean: doc-clean
find . -name '*~' -delete
rm -f $(cpp_tgt)
rm -rf matlab/mex/.build
distclean: clean doc-distclean
rm -rf matlab/mex
rm -f doc/index.html doc/matconvnet-manual.pdf
rm -f $(NAME)-*.tar.gz
pack:
COPYFILE_DISABLE=1 \
COPY_EXTENDED_ATTRIBUTES_DISABLE=1 \
$(GIT) archive --prefix=$(NAME)-$(VER)/ v$(VER) | gzip > $(DIST).tar.gz
ln -sf $(DIST).tar.gz $(LATEST).tar.gz
post: pack
$(RSYNC) -aP $(DIST).tar.gz $(LATEST).tar.gz $(HOST)/download/
post-models:
$(RSYNC) -aP data/models/*.mat $(HOST)/models/
post-doc: doc
$(RSYNC) -aP doc/matconvnet-manual.pdf $(HOST)/
$(RSYNC) \
--recursive \
--perms \
--verbose \
--delete \
--exclude=download \
--exclude=models \
--exclude=matconvnet-manual.pdf \
--exclude=.htaccess doc/site/site/ $(HOST)/
.PHONY: model-md5
model-md5:
cd data/models ; md5sum *.mat | xargs printf '| %-33s| %-40s|\n'