forked from dmlc/cxxnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
162 lines (128 loc) · 4.16 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
ifndef config
ifdef CXXNET_CONFIG
config = $(CXXNET_CONFIG)
else ifneq ("$(wildcard ./config.mk)","")
config = config.mk
else
config = make/config.mk
endif
endif
ifndef DMLC_CORE
DMLC_CORE = dmlc-core
endif
ifneq ($(USE_OPENMP_ITER),1)
export NO_OPENMP = 1
endif
# use customized config file
include $(config)
include mshadow/make/mshadow.mk
include $(DMLC_CORE)/make/dmlc.mk
unexport NO_OPENMP
# all tge possible warning tread
WARNFLAGS= -Wall
CFLAGS = -DMSHADOW_FORCE_STREAM $(WARNFLAGS)
CFLAGS += -g -O3 -I./mshadow/ -I./dmlc-core/include -fPIC $(MSHADOW_CFLAGS)
LDFLAGS = -pthread $(MSHADOW_LDFLAGS) $(DMLC_LDFLAGS)
NVCCFLAGS = --use_fast_math -g -O3 -ccbin $(CXX) $(MSHADOW_NVCCFLAGS)
ROOTDIR = $(CURDIR)
# setup opencv
ifeq ($(USE_OPENCV),1)
CFLAGS+= -DCXXNET_USE_OPENCV=1
LDFLAGS+= `pkg-config --libs opencv`
else
CFLAGS+= -DCXXNET_USE_OPENCV=0
endif
ifeq ($(USE_OPENCV_DECODER),1)
CFLAGS+= -DCXXNET_USE_OPENCV_DECODER=1
else
CFLAGS+= -DCXXNET_USE_OPENCV_DECODER=0
endif
ifeq ($(USE_OPENMP_ITER), 1)
CFLAGS += -fopenmp
endif
# customize cudnn path
ifneq ($(USE_CUDNN_PATH), NONE)
CFLAGS += -I$(USE_CUDNN_PATH)
LDFLAGS += -L$(USE_CUDNN_PATH)
endif
ifeq ($(USE_CUDNN), 1)
CFLAGS += -DCXXNET_USE_CUDNN=1
LDFLAGS += -lcudnn
endif
ifeq ($(USE_CAFFE_CONVERTER), 1)
CFLAGS += -I$(CAFFE_ROOT)/include/ -I$(CAFFE_ROOT)/build/src/
LDFLAGS += -L$(CAFFE_ROOT)/build/lib/ -lcaffe -pthread -lglog
CFLAGS += -I./src/
ifeq ($(USE_BLAS), mkl)
CFLAGS += -DUSE_MKL=1
endif
endif
ifneq ($(ADD_CFLAGS), NONE)
CFLAGS += $(ADD_CFLAGS)
endif
ifneq ($(ADD_LDFLAGS), NONE)
LDFLAGS += $(ADD_LDFLAGS)
endif
# specify tensor path
BIN = bin/cxxnet
ifeq ($(USE_OPENCV),1)
BIN += bin/im2rec bin/bin2rec
endif
ifeq ($(USE_CAFFE_CONVERTER), 1)
BIN += bin/caffe_converter bin/caffe_mean_converter
endif
SLIB = wrapper/libcxxnetwrapper.so
OBJ = layer_cpu.o updater_cpu.o nnet_cpu.o main.o nnet_ps_server.o
OBJCXX11 = data.o
CUOBJ = layer_gpu.o updater_gpu.o nnet_gpu.o
CUBIN =
LIB_DEP = $(DMLC_CORE)/libdmlc.a
ifeq ($(USE_RABIT_PS), 1)
LIB_DEP += $(RABIT_PATH)/lib/librabit_base.a
endif
ifeq ($(USE_CUDA), 0)
CUDEP =
else
CUDEP = $(CUOBJ)
endif
.PHONY: clean all
ifeq ($(USE_DIST_PS), 1)
BIN=bin/cxxnet.ps
endif
all: $(BIN) $(SLIB)
$(DMLC_CORE)/libdmlc.a:
+ cd $(DMLC_CORE); make libdmlc.a config=$(ROOTDIR)/$(config); cd $(ROOTDIR)
$(RABIT_PATH)/lib/librabit_base.a:
+ cd $(RABIT_PATH); make; cd $(ROOTDIR)
layer_cpu.o layer_gpu.o: src/layer/layer_impl.cpp src/layer/layer_impl.cu\
src/layer/*.h src/layer/*.hpp src/utils/*.h src/plugin/*.hpp
updater_cpu.o updater_gpu.o: src/updater/updater_impl.cpp src/updater/updater_impl.cu\
src/layer/layer.h src/updater/*.hpp src/updater/*.h src/utils/*.h
nnet_cpu.o nnet_gpu.o: src/nnet/nnet_impl.cpp src/nnet/nnet_impl.cu src/layer/layer.h\
src/updater/updater.h src/utils/*.h src/nnet/*.hpp src/nnet/*.h
nnet_ps_server.o: src/nnet/nnet_ps_server.cpp src/utils/*.h src/nnet/*.hpp \
src/nnet/*.h mshadow/mshadow-ps/*.h
data.o: src/io/data.cpp src/io/*.hpp
main.o: src/cxxnet_main.cpp
wrapper/libcxxnetwrapper.so: wrapper/cxxnet_wrapper.cpp $(OBJ) $(OBJCXX11) $(LIB_DEP) $(CUDEP)
bin/cxxnet: src/local_main.cpp $(OBJ) $(OBJCXX11) $(LIB_DEP) $(CUDEP)
bin/cxxnet.ps: $(OBJ) $(OBJCXX11) $(CUDEP) $(LIB_DEP) $(PS_LIB)
bin/im2rec: tools/im2rec.cc $(DMLC_CORE)/libdmlc.a
bin/bin2rec: tools/bin2rec.cc $(DMLC_CORE)/libdmlc.a
bin/caffe_converter: tools/caffe_converter/convert.cpp $(OBJ) $(OBJCXX11) $(LIB_DEP) $(CUDEP)
bin/caffe_mean_converter: tools/caffe_converter/convert_mean.cpp $(OBJ) $(OBJCXX11) $(LIB_DEP) $(CUDEP)
$(BIN) :
$(CXX) $(CFLAGS) -o $@ $(filter %.cpp %.o %.c %.a %.cc, $^) $(LDFLAGS)
$(OBJ) :
$(CXX) -c $(CFLAGS) -o $@ $(firstword $(filter %.cpp %.c %.cc, $^) )
$(OBJCXX11) :
$(CXX) -std=c++0x -c $(CFLAGS) -o $@ $(firstword $(filter %.cpp %.c %.cc, $^) )
$(SLIB) :
$(CXX) $(CFLAGS) -shared -o $@ $(filter %.cpp %.o %.c %.a %.cc, $^) $(LDFLAGS)
$(CUOBJ) :
$(NVCC) -c -o $@ $(NVCCFLAGS) -Xcompiler "$(CFLAGS)" $(filter %.cu, $^)
$(CUBIN) :
$(NVCC) -o $@ $(NVCCFLAGS) -Xcompiler "$(CFLAGS)" -Xlinker "$(LDFLAGS)" $(filter %.cu %.cpp %.o, $^)
clean:
$(RM) $(OBJ) $(OBJCXX11) $(BIN) $(CUBIN) $(CUOBJ) $(SLIB) *~ */*~ */*/*~
cd $(DMLC_CORE); make clean; cd -