-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
Makefile
256 lines (217 loc) · 7.85 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
# file: Makefile
# author: Andrea Vedaldi
# brief: matconvnet makefile for mex files
# Copyright (C) 2014-15 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
DEBUG ?=
ARCH ?= maci64
# Configure MATLAB
MATLABROOT ?= /Applications/MATLAB_R2014b.app
# Configure CUDA and CuDNN. CUDAMETHOD can be either 'nvcc' or 'mex'.
CUDAROOT ?= /Developer/NVIDIA/CUDA-5.5
CUDNNROOT ?= $(CURDIR)/local/
CUDAMETHOD ?= $(if $(ENABLE_CUDNN),nvcc,mex)
# Configure the image library (needed only if ENABLE_IMREADJPEG is true).
# IMAGELIB can be either 'libjpeg' (default on Linux) or 'quartz' (default on a Mac)
IMAGELIB ?= $(IMAGELIB_DEFAULT)
IMAGELIB_CFLAGS ?= $(IMAGELIB_CFLAGS_DEFAULT)
IMAGELIB_LDFLAGS ?= $(IMAGELIB_LDFLAGS_DEFAULT)
# 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_R2015b.app
#CUDAROOT ?= /Developer/NVIDIA/CUDA-6.5
# Maintenance
NAME = matconvnet
VER = 1.0-beta13
DIST = $(NAME)-$(VER)
RSYNC = rsync
HOST = vlfeat-admin:sites/sandbox-matconvnet
GIT = git
# --------------------------------------------------------------------
# Configuration
# --------------------------------------------------------------------
# General options
MEX = $(MATLABROOT)/bin/mex
MEXEXT = $(MATLABROOT)/bin/mexext
MEXARCH = $(subst mex,,$(shell $(MEXEXT)))
MEXOPTS ?= matlab/src/config/mex_CUDA_$(ARCH).xml
MEXFLAGS = -cxx -largeArrayDims -lmwblas \
$(if $(ENABLE_GPU),-DENABLE_GPU,) \
$(if $(ENABLE_CUDNN),-DENABLE_CUDNN -I$(CUDNNROOT),)
MEXFLAGS_GPU = $(MEXFLAGS) -f "$(MEXOPTS)"
SHELL = /bin/bash # sh not good enough
NVCC = $(CUDAROOT)/bin/nvcc
# this is used *onyl* for the 'nvcc' method
NVCCFLAGS = \
-gencode=arch=compute_30,code=\"sm_30,compute_30\" \
-DENABLE_GPU \
$(if $(ENABLE_CUDNN),-DENABLE_CUDNN -I$(CUDNNROOT),) \
-I"$(MATLABROOT)/extern/include" \
-I"$(MATLABROOT)/toolbox/distcomp/gpu/extern/include" \
-Xcompiler -fPIC
MEXFLAGS_NVCC = $(MEXFLAGS) -lmwgpu
ifneq ($(DEBUG),)
MEXFLAGS += -g
NVCCFLAGS += -g -O0
else
MEXFLAGS += -DNDEBUG -O
NVCCFLAGS += -DNDEBUG -O3
# we still want debug symbols
MEXFLAGS += CXXOPTIMFLAGS='$$CXXOPTIMFLAGS -g'
MEXFLAGS += LDOPTIMFLAGS='$$LDOPTIMFLAGS -g'
NVCCFLAGS += -g
endif
ifdef VERB
MEXFLAGS += -v
NVCCFLAGS += -v
endif
# Mac OS X Intel
ifeq "$(ARCH)" "$(filter $(ARCH),maci64)"
MEXFLAGS_GPU += -L$(CUDAROOT)/lib
MEXFLAGS_NVCC += -L$(CUDAROOT)/lib LDFLAGS='$$LDFLAGS -stdlib=libstdc++'
IMAGELIB_DEFAULT = quartz
endif
# Linux
ifeq "$(ARCH)" "$(filter $(ARCH),glnxa64)"
MEXFLAGS_GPU += -L$(CUDAROOT)/lib64
MEXFLAGS_NVCC += -L$(CUDAROOT)/lib64
IMAGELIB_DEFAULT = libjpeg
MEXFLAGS += CXXOPTIMFLAGS='$$CXXOPTIMFLAGS -mssse3 -ftree-vect-loop-version -ffast-math -funroll-all-loops'
NVCCFLAGS += -Xcompiler -mssse3,-ftree-vect-loop-version,-ffast-math,-funroll-all-loops
endif
# Image library
ifeq ($(IMAGELIB),libjpeg)
IMAGELIB_CFLAGS_DEFAULT :=
IMAGELIB_LDFLAGS_DEFAULT := -ljpeg
endif
ifeq ($(IMAGELIB),quartz)
IMAGELIB_CFLAGS_DEFAULT :=
IMAGELIB_LDFLAGS_DEFAULT := LDFLAGS='$$LDFLAGS -framework Cocoa -framework ImageIO'
endif
ifdef ENABLE_IMREADJPEG
MEXFLAGS += $(IMAGELIB_CFLAGS) $(IMAGELIB_LDFLAGS)
endif
MEXFLAGS_GPU += -lcublas -lcudart $(if $(ENABLE_CUDNN),-L$(CUDNNROOT) -lcudnn,)
MEXFLAGS_NVCC += -lcublas -lcudart $(if $(ENABLE_CUDNN),-L$(CUDNNROOT) -lcudnn,)
# --------------------------------------------------------------------
# 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)
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)
ifdef ENABLE_IMREADJPEG
mex_src+=matlab/src/vl_imreadjpeg.cpp
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/tinythread.cpp
ifdef ENABLE_IMREADJPEG
cpp_src+=matlab/src/bits/impl/imread_$(IMAGELIB).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/datacu.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
endif
endif
mex_tgt:=$(subst matlab/src/,matlab/mex/,$(mex_src))
mex_tgt:=$(patsubst %.cpp,%.mex$(MEXARCH),$(mex_tgt))
mex_tgt:=$(patsubst %.cu,%.mex$(MEXARCH),$(mex_tgt))
cpp_tgt:=$(patsubst %.cpp,%.o,$(cpp_src))
cpp_tgt:=$(patsubst %.cu,%.o,$(cpp_tgt))
cpp_tgt:=$(subst matlab/src/bits/,matlab/mex/.build/,$(cpp_tgt))
.PHONY: all, distclean, clean, info, pack, post, post-doc, doc
all: $(cpp_tgt) $(mex_tgt)
# Create build directory
%/.stamp:
mkdir -p $(*)/ ; touch $(*)/.stamp
$(mex_tgt): matlab/mex/.build/impl/.stamp
$(cpp_tgt): matlab/mex/.build/impl/.stamp
$(cu_tgt): matlab/mex/.build/impl/.stamp
# Standard code
.PRECIOUS: matlab/mex/.build/%.o
.PRECIOUS: %/.stamp
ifeq ($(CUDAMETHOD),mex)
include Makefile.mex
else
include Makefile.nvcc
endif
# --------------------------------------------------------------------
# Documentation
# --------------------------------------------------------------------
include doc/Makefile
# --------------------------------------------------------------------
# Maintenance
# --------------------------------------------------------------------
info: doc-info
@echo "mex_src=$(mex_src)"
@echo "mex_tgt=$(mex_tgt)"
@echo "cpp_src=$(cpp_src)"
@echo "cpp_tgt=$(cpp_tgt)"
@echo "cu_src=$(cu_src)"
@echo "cu_tgt=$(cu_tgt)"
@echo 'MEXFLAGS=$(MEXFLAGS)'
@echo 'MEXFLAGS_GPU=$(MEXFLAGS_GPU)'
@echo 'MEXFLAGS_NVCC=$(MEXFLAGS_NVCC)'
@echo 'NVCCFLAGS=$(NVCCFLAGS)'
clean: doc-clean
find . -name '*~' -delete
rm -f $(cpp_tgt) $(cu_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
post: pack
$(RSYNC) -aP $(DIST).tar.gz $(HOST)/download/
post-models:
$(RSYNC) -aP data/models/*.mat $(HOST)/models/
post-doc: doc
$(RSYNC) -aP README.md doc/matconvnet-manual.pdf $(HOST)/
$(RSYNC) -aP README.md doc/site/site/ $(HOST)/