-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
244 lines (194 loc) · 7.3 KB
/
Makefile
File metadata and controls
244 lines (194 loc) · 7.3 KB
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
GTEST_INCLUDE_DIR = googletest/downloaded_deps/googletest/googletest/include
CEREAL_INCLUDE_DIR = cereal/downloaded_deps/cereal/include
CXX = clang++
CPPFLAGS += -isystem $(GTEST_INCLUDE_DIR) -I . -isystem $(CEREAL_INCLUDE_DIR)
CXXFLAGS += -g -Wall -Wextra -pthread --std=c++11
CXXLINKFLAGS += -L$(CUDA_LIB) -lpthread -lcudart -lcurand
NVCC = /usr/local/cuda/bin/nvcc
NVCCFLAGS += --include-path=. --system-include=$(CEREAL_INCLUDE_DIR) --system-include=$(GTEST_INCLUDE_DIR) -Wno-deprecated-gpu-targets --compiler-bindir=$(CXX) --std=c++11
CUDA_LIB=/usr/local/cuda/lib64
SOURCES := $(wildcard **/*.cc) $(wildcard **/*.cu)
TEST_SOURCES := $(filter %_test.cc,$(SOURCES))
TEST_DS := $(addprefix bin/,$(subst .cc,.d,$(TEST_SOURCES)))
TEST_OBJS := $(addprefix bin/,$(subst .cc,.o,$(TEST_SOURCES)))
# PHONY targets
#######
.PHONY: clean clean_all test matrix_test matrix_perf_test fully_connected_layer_test error_layer_test convolutional_layer_test batch_normalization_layer_test input_image_normalization_layer_test bias_layer_test pooling_layer_test inverted_dropout_layer_test
test: matrix_test matrix_perf_test fully_connected_layer_test error_layer_test convolutional_layer_test batch_normalization_layer_test input_image_normalization_layer_test bias_layer_test pooling_layer_test inverted_dropout_layer_test
clean:
rm -Rf bin
clean_all: clean
$(MAKE) -C googletest clean
$(MAKE) -C cereal clean
rm -Rf apps/cifar10/downloaded_deps
matrix_test: bin/linalg/matrix_test
$<
matrix_perf_test: bin/linalg/matrix_perf_test
$<
fully_connected_layer_test: bin/cnn/fully_connected_layer_test
$<
error_layer_test: bin/cnn/error_layer_test
$<
convolutional_layer_test: bin/cnn/convolutional_layer_test
$<
batch_normalization_layer_test: bin/cnn/batch_normalization_layer_test
$<
input_image_normalization_layer_test: bin/cnn/input_image_normalization_layer_test
$<
bias_layer_test: bin/cnn/bias_layer_test
$<
pooling_layer_test: bin/cnn/pooling_layer_test
$<
inverted_dropout_layer_test: bin/cnn/inverted_dropout_layer_test
$<
layer_stack_test: bin/cnn/layer_stack_test
$<
cifar10_train: bin/apps/cifar10/cifar10_train
$<
# Build GoogleTest
#######
bin/googletest/gtest_main.a:
mkdir -p bin/googletest
$(MAKE) -C googletest ../$@
# Download & Unpack CIFAR-10 dataset
#######
apps/cifar10/downloaded_deps/cifar-10-binary.tar.gz:
mkdir -p apps/cifar10/downloaded_deps && \
cd apps/cifar10/downloaded_deps && \
curl -o cifar-10-binary.tar.gz https://www.cs.toronto.edu/~kriz/cifar-10-binary.tar.gz
apps/cifar10/downloaded_deps/cifar-10-batches-bin: apps/cifar10/downloaded_deps/cifar-10-binary.tar.gz
cd apps/cifar10/downloaded_deps && \
tar xf cifar-10-binary.tar.gz
touch $@
# Generate .d files (header dependency lists), and then include them in this Makefile
# to make header dependencies automatically discovered:
#######
bin/%.d: %.cc
@set -e; rm -f $@; \
mkdir -p $(dir bin/$*); \
$(CXX) -MM $(CPPFLAGS) $(CXXFLAGS) $< > $@.$$$$; \
sed 's,\($(notdir $(basename $*))\)\.o[ :]*,$(dir bin/$*)\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
bin/%.cu.d: %.cu
@set -e; rm -f $@; \
mkdir -p $(dir bin/$*); \
$(NVCC) -M $(NVCCFLAGS) $< > $@.$$$$; \
sed 's,\($(notdir $(basename $*))\)\.o[ :]*,$(dir bin/$*)\1.cu.o $@ : ,g' < $@.$$$$ | \
grep -v '^[[:space:]]*/' > $@; \
echo >> $@; \
rm -f $@.$$$$
include $(addprefix bin/,$(subst .cc,.d,$(subst .cu,.cu.d,$(SOURCES))))
# Invoke NVCC and C++ compilers to get .o files:
#######
bin/%.cu.o: %.cu
@set -e; mkdir -p $(dir bin/$*)
$(NVCC) $(filter %.cu %.cc,$^) $(NVCCFLAGS) --lib --output-file=$@
bin/%.o: %.cc
@set -e; mkdir -p $(dir bin/$*)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(filter %.cu %.cc %.o,$^) -o $@
# Put all object files into archives (this simplifies the linking rules)
#######
bin/test.a: bin/linalg/matrix_test_util.o \
bin/cnn/layer_test_base.o
ar rc $@ $?
# bin/linalg/martrix.cu.o should be here but it's a special kind of file
# because of CUDA and it doesn't work here.
bin/core.a: \
bin/cnn/batch_normalization_layer.o \
bin/cnn/bias_layer.o \
bin/cnn/convolutional_layer.o \
bin/cnn/error_layer.o \
bin/cnn/fully_connected_layer.o \
bin/cnn/input_image_normalization_layer.o \
bin/cnn/inverted_dropout_layer.o \
bin/cnn/l2_error_layer.o \
bin/cnn/layer.o \
bin/cnn/layer_stack.o \
bin/cnn/matrix_param.o \
bin/cnn/nonlinearity_layer.o \
bin/cnn/pooling_layer.o \
bin/cnn/reshape_layer.o \
bin/cnn/softmax_error_layer.o \
bin/infra/data_set.o \
bin/infra/logger.o \
bin/infra/trainer.o
ar rc $@ $^
# Fully linked end-product binary files:
#######
bin/linalg/matrix_test: bin/linalg/matrix_test.o \
bin/linalg/matrix.cu.o \
bin/googletest/gtest_main.a \
bin/test.a
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(CXXLINKFLAGS) $^ -o $@
bin/linalg/matrix_perf_test: bin/linalg/matrix_perf_test.o \
bin/linalg/matrix.cu.o \
bin/googletest/gtest_main.a \
bin/test.a
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(CXXLINKFLAGS) $^ -o $@
bin/cnn/fully_connected_layer_test: bin/cnn/fully_connected_layer_test.o \
bin/core.a \
bin/test.a \
bin/linalg/matrix.cu.o \
bin/googletest/gtest_main.a
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(CXXLINKFLAGS) $^ -o $@
bin/cnn/error_layer_test: bin/cnn/error_layer_test.o \
bin/core.a \
bin/test.a \
bin/linalg/matrix.cu.o \
bin/googletest/gtest_main.a
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(CXXLINKFLAGS) $^ -o $@
bin/cnn/convolutional_layer_test: bin/cnn/convolutional_layer_test.o \
bin/core.a \
bin/test.a \
bin/linalg/matrix.cu.o \
bin/googletest/gtest_main.a
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(CXXLINKFLAGS) $^ -o $@
bin/cnn/batch_normalization_layer_test: bin/cnn/batch_normalization_layer_test.o \
bin/core.a \
bin/test.a \
bin/linalg/matrix.cu.o \
bin/googletest/gtest_main.a
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(CXXLINKFLAGS) $^ -o $@
bin/cnn/input_image_normalization_layer_test: bin/cnn/input_image_normalization_layer_test.o \
bin/core.a \
bin/test.a \
bin/linalg/matrix.cu.o \
bin/googletest/gtest_main.a
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(CXXLINKFLAGS) $^ -o $@
bin/cnn/bias_layer_test: bin/cnn/bias_layer_test.o \
bin/core.a \
bin/test.a \
bin/linalg/matrix.cu.o \
bin/googletest/gtest_main.a
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(CXXLINKFLAGS) $^ -o $@
bin/cnn/pooling_layer_test: bin/cnn/pooling_layer_test.o \
bin/core.a \
bin/test.a \
bin/linalg/matrix.cu.o \
bin/googletest/gtest_main.a
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(CXXLINKFLAGS) $^ -o $@
bin/cnn/inverted_dropout_layer_test: bin/cnn/inverted_dropout_layer_test.o \
bin/core.a \
bin/test.a \
bin/linalg/matrix.cu.o \
bin/googletest/gtest_main.a
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(CXXLINKFLAGS) $^ -o $@
bin/cnn/layer_stack_test: bin/cnn/layer_stack_test.o \
bin/core.a \
bin/test.a \
bin/linalg/matrix.cu.o \
bin/googletest/gtest_main.a
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(CXXLINKFLAGS) $^ -o $@
bin/apps/cifar10/cifar10_train: apps/cifar10/downloaded_deps/cifar-10-batches-bin
bin/apps/cifar10/cifar10_train: bin/apps/cifar10/cifar10_train.o \
bin/apps/cifar10/cifar_data_set.o \
bin/core.a \
bin/test.a \
bin/linalg/matrix.cu.o
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(CXXLINKFLAGS) $(filter %.o %.a,$^) -o $@
bin/apps/cifar10/use_model: bin/apps/cifar10/use_model.o \
bin/apps/cifar10/cifar_data_set.o \
bin/core.a \
bin/test.a \
bin/linalg/matrix.cu.o
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(CXXLINKFLAGS) $(filter %.o %.a,$^) -o $@