forked from vlfeat/matconvnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
195 lines (158 loc) · 5.4 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
# file: Makefile
# author: Andrea Vedaldi
# brief: matconvnet makefile for mex files
# Copyright (C) 2007-14 Andrea Vedaldi and Brian Fulkerson.
# 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).
# For Linux: intermediate files must be compiled with -fPIC to go in a MEX file
ENABLE_GPU ?=
ENABLE_IMREADJPEG ?=
DEBUG ?=
ARCH ?= maci64
CUDAROOT ?= /Developer/NVIDIA/CUDA-5.5
MATLABROOT ?= /Applications/MATLAB_R2014a.app
NAME = matconvnet
VER = 1.0-beta7
DIST = $(NAME)-$(VER)
MARKDOWN = markdown2
HOST = vlfeat-admin:sites/sandbox-matconvnet
GIT = git
PDFLATEX = pdflatex
BIBTEX = bibtex
RSYNC = rsync
# --------------------------------------------------------------------
# Configuration
# --------------------------------------------------------------------
# General options
MEX = $(MATLABROOT)/bin/mex
MEXEXT = $(MATLABROOT)/bin/mexext
MEXARCH = $(subst mex,,$(shell $(MEXEXT)))
MEXOPTS = -largeArrayDims -lmwblas
MEXOPTS_GPU = \
-DENABLE_GPU -f matlab/src/config/mex_CUDA_$(ARCH).xml \
-largeArrayDims -lmwblas
ifeq ($(OS), Windows_NT)
SHELL=C:/Windows/System32/cmd.exe
else
SHELL = /bin/bash # sh not good enough
endif
# at least compute 2.0 required
NVCC = $(CUDAROOT)/bin/nvcc
NVCCOPTS = \
-gencode=arch=compute_20,code=sm_21 \
-gencode=arch=compute_30,code=sm_30
ifneq ($(DEBUG),)
MEXOPTS += -g
MEXOPTS_GPU += -g
NVCCOPTS += -g
endif
# Mac OS X Intel
ifeq "$(ARCH)" "$(filter $(ARCH),maci64)"
MEXOPTS_GPU += -L$(CUDAROOT)/lib -lcublas -lcudart
endif
# Linux
ifeq "$(ARCH)" "$(filter $(ARCH),glnxa64)"
NVCCOPTS += --compiler-options=-fPIC
MEXOPTS_GPU += -L$(CUDAROOT)/lib64 -lcublas -lcudart
endif
# --------------------------------------------------------------------
# Do the job
# --------------------------------------------------------------------
nvcc_filter=
# "2> >( sed 's/^\(.*\)(\([0-9][0-9]*\)): \([ew].*\)/\1:\2: \3/g' >&2 )"
cpp_src:=matlab/src/bits/im2col.cpp
cpp_src+=matlab/src/bits/pooling.cpp
cpp_src+=matlab/src/bits/normalize.cpp
cpp_src+=matlab/src/bits/subsample.cpp
ifneq ($(ENABLE_IMREADJPEG),)
mex_src:=matlab/src/vl_imreadjpeg.c
endif
ifeq ($(ENABLE_GPU),)
mex_src+=matlab/src/vl_nnconv.cpp
mex_src+=matlab/src/vl_nnpool.cpp
mex_src+=matlab/src/vl_nnnormalize.cpp
else
mex_src+=matlab/src/vl_nnconv.cu
mex_src+=matlab/src/vl_nnpool.cu
mex_src+=matlab/src/vl_nnnormalize.cu
cpp_src+=matlab/src/bits/im2col_gpu.cu
cpp_src+=matlab/src/bits/pooling_gpu.cu
cpp_src+=matlab/src/bits/normalize_gpu.cu
cpp_src+=matlab/src/bits/subsample_gpu.cu
endif
mex_tgt:=$(subst matlab/src/,matlab/mex/,$(mex_src))
mex_tgt:=$(patsubst %.c,%.mex$(MEXARCH),$(mex_tgt))
mex_tgt:=$(patsubst %.cpp,%.mex$(MEXARCH),$(mex_tgt))
mex_tgt:=$(patsubst %.cu,%.mex$(MEXARCH),$(mex_tgt))
cpp_tgt:=$(patsubst %.cpp,%.obj,$(cpp_src))
cpp_tgt:=$(patsubst %.cu,%.o,$(cpp_tgt))
.PHONY: all, distclean, clean, info, pack, post, post-doc, doc
all: $(mex_tgt)
matlab/mex/.stamp:
mkdir matlab/mex ; touch matlab/mex/.stamp
# Standard code
matlab/src/bits/%.obj : matlab/src/bits/%.cpp
$(MEX) -c $(MEXOPTS) "$(<)"
mv "$(notdir $(@))" "$(@)"
matlab/src/bits/%.o : matlab/src/bits/%.cu
$(NVCC) -c $(NVCCOPTS) "$(<)" -o "$(@)" $(nvcc_filter)
# MEX files
matlab/mex/vl_imreadjpeg.mex$(MEXARCH): MEXOPTS+=-I/opt/local/include -L/opt/local/lib -ljpeg
matlab/mex/%.mex$(MEXARCH) : matlab/src/%.c matlab/mex/.stamp $(cpp_tgt)
$(MEX) $(MEXOPTS) "$(<)" -output "$(@)" $(cu_tgt) $(nvcc_filter)
matlab/mex/%.mex$(MEXARCH) : matlab/src/%.cpp matlab/mex/.stamp $(cpp_tgt)
$(MEX) $(MEXOPTS) "$(<)" -output "$(@)" $(cu_tgt) $(nvcc_filter)
matlab/mex/%.mex$(MEXARCH) : matlab/src/%.cu matlab/mex/.stamp $(cpp_tgt)
ifeq ($(ENABLE_GPU),)
echo #include "../src/$(notdir $(<))" > "matlab/mex/$(*).cpp"
$(MEX) $(MEXOPTS) \
"matlab/mex/$(*).cpp" $(cpp_tgt) \
-output "$(@)"
else
echo $(@)
MW_NVCC_PATH='$(NVCC)' $(MEX) \
-output "$(@)" \
"$(<)" $(cpp_tgt) \
$(MEXOPTS_GPU) \
$(nvcc_filter)
endif
doc: doc/index.html doc/matconvnet-manual.pdf
doc/matconvnet-manual.pdf : doc/matconvnet-manual.tex
mkdir -p doc/.build
ln -sf ../references.bib doc/.build/references.bib
$(PDFLATEX) -file-line-error -output-directory=doc/.build/ "$(<)"
cd doc/.build ; $(BIBTEX) matconvnet-manual
$(PDFLATEX) -file-line-error -output-directory=doc/.build/ "$(<)"
$(PDFLATEX) -file-line-error -output-directory=doc/.build/ "$(<)"
cp -f doc/.build/matconvnet-manual.pdf doc/
doc/index.html : doc/.build/index.html.raw doc/template.html
sed -e '/%MARKDOWN%/{r doc/.build/index.html.raw' -e 'd;}' doc/template.html > $(@)
doc/.build/index.html.raw : doc/index.md
mkdir -p doc/.build
$(MARKDOWN) -x tables $(<) > $(@)
# Other targets
info:
@echo "mex_src=$(mex_src)"
@echo "mex_tgt=$(mex_tgt)"
@echo "cpp_src=$(cpp_src)"
@echo "cpp_tgt=$(cpp_tgt)"
clean:
find . -name '*~' -delete
$(RMALL) $(cpp_tgt)
$(RMDIR) doc/.build
distclean: clean
$(RMDIR) matlab/mex/
$(RMALL) doc/index.html doc/matconvnet-manual.pdf
$(RMALL) $(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/{index.html,matconvnet-manual.pdf} $(HOST)/