-
Notifications
You must be signed in to change notification settings - Fork 31
/
Makefile~
151 lines (116 loc) · 5.94 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
PROJECT := caffe
NAME := lib$(PROJECT).so
LIB := lib$(PROJECT).a
TEST_NAME := test_$(PROJECT)
layer_folders := src/caffe/layers/activation src/caffe/layers/operator src/caffe/layers/loss src/caffe/layers/func src/caffe/layers/data
CXX_SRCS := $(shell find src/caffe $(layer_folders) src/caffe/util src/caffe/solvers -maxdepth 1 -name "*.cpp")
CU_SRCS := $(shell find $(layer_folders) src/caffe/util src/caffe -maxdepth 1 -name "*.cu")
TEST_SRCS := $(shell find src/caffe/test -maxdepth 1 -name "test_*.cpp")
GTEST_SRCS := src/gtest/gtest-all.cpp src/gtest/test_caffe_main.cpp
TOOL_SRCS := $(shell find tools -maxdepth 1 -name "*.cpp")
PROTO_SRCS := $(wildcard src/caffe/proto/*.proto)
PROTO_GEN_HEADER := ${PROTO_SRCS:.proto=.pb.h}
PROTO_GEN_CC := ${PROTO_SRCS:.proto=.pb.cc}
CXX_OBJS_ := ${CXX_SRCS:.cpp=.o}
CU_OBJS_ := ${CU_SRCS:.cu=.o}
PROTO_OBJS_ := ${PROTO_SRCS:.proto=.pb.o}
CXX_OBJS = $(foreach file,$(CXX_OBJS_),build/$(file))
CU_OBJS = $(foreach file,$(CU_OBJS_),build/cuda/$(file))
PROTO_OBJS = $(foreach file,$(PROTO_OBJS_),build/$(file))
OBJS := $(CXX_OBJS) $(CU_OBJS) $(PROTO_OBJS)
TOOL_OBJS_ := ${TOOL_SRCS:.cpp=.o}
TOOL_OBJS = $(foreach file,$(TOOL_OBJS_),build/$(file))
GTEST_OBJS_ := ${GTEST_SRCS:.cpp=.o}
GTEST_OBJS = $(foreach file,$(GTEST_OBJS_),build/$(file))
TEST_OBJS_ := ${TEST_SRCS:.cpp=.o}
TEST_OBJS = $(foreach file,$(TEST_OBJS_),build/$(file))
TEST_BINS := ${TEST_OBJS:.o=.testbin}
TOOL_BINS :=${TOOL_OBJS:.o=.bin}
CUDA_DIR := /usr/local/cuda
CUDA_ARCH :=-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=sm_50 \
-gencode arch=compute_50,code=compute_50
CUDA_INCLUDE_DIR := $(CUDA_DIR)/include
CUDA_LIB_DIR := $(CUDA_DIR)/lib64
INCLUDE_DIRS := /home/sensetime/caffe/thirdparty/cudnn/include . src /usr/local/include $(CUDA_INCLUDE_DIR) include /home/sensetime/caffe/thirdparty/nccl/include /home/sensetime/caffe/thirdparty/blas/include /home/sensetime/caffe/thirdparty/mpich/include
LIBRARY_DIRS := /home/sensetime/caffe/thirdparty/cudnn/lib64 . /usr/lib /usr/local/lib $(CUDA_LIB_DIR) /home/sensetime/caffe/thirdparty/nccl/lib /home/sensetime/caffe/thirdparty/blas/lib /home/sensetime/caffe/thirdparty/mpich/lib
LIBRARIES := glog gflags protobuf boost_system boost_filesystem boost_regex m opencv_core opencv_highgui opencv_imgproc boost_thread stdc++ cudnn openblas
LIBRARIES += cudart cublas curand nccl mpi
WARNINGS := -Wall
CXXFLAGS += -MMD -MP -fPIC -fopenmp
LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir))
LDFLAGS += $(foreach library,$(LIBRARIES),-l$(library))
LDFLAGS += -lgomp
LINK = $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(WARNINGS)
NVCC = nvcc $(CPPFLAGS) $(CUDA_ARCH)
COMMON_FLAGS := $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir)) -DUSE_CUDNN
NVCCFLAGS := -ccbin=$(CXX) -Xcompiler -fPIC -Xcompiler -fopenmp
DEBUG := 0
# Debugging
ifeq ($(DEBUG), 1)
COMMON_FLAGS += -DDEBUG -g -O0
NVCCFLAGS += -G
else
COMMON_FLAGS += -DNDEBUG -O3
endif
NVCCFLAGS += $(COMMON_FLAGS)
#---------------------------------------------------------------------------------------------------------
DEPS := ${CXX_OBJS:.o=.d} ${CU_OBJS:.o=.d} ${TEST_OBJS:.o=.d} ${GTEST_OBJS:.o=.d} ${TOOL_OBJS:.o=.d}
.PHONY: all test clean
all: $(NAME) $(TOOL_BINS) $(LIB)
-include $(DEPS)
test: $(TEST_BINS) $(GTEST_OBJS) $(GTEST_MAIN) $(OBJS)
#---------------------------------------------- matlab ------------------------------------------------
matcaffe: all
/usr/local/MATLAB/R2014b/bin/mex matlab/matcaffe.cpp \
CXX="g++" \
CXXFLAGS="\$$CXXFLAGS $(CXXFLAGS) $(COMMON_FLAGS) -Wno-uninitialized" \
CXXLIBS="\$$LIBRARIES -Wl,--whole-archive lib$(PROJECT).a -Wl,--no-whole-archive $(LDFLAGS)" \
-output matlab/caffe
#--------------------------------------------- python -------------------------------------------------
pycaffe: all
$(CXX) -I/home/sensetime/.local/lib/python2.7/site-packages/numpy/core/include/ $(CXXFLAGS) $(COMMON_FLAGS) -shared python/_pycaffe.cpp -lboost_python \
-I/usr/include/python2.7/ -Wl,--whole-archive lib$(PROJECT).a -Wl,--no-whole-archive \
$(LDFLAGS) -fPIC -o python/_pycaffe.so
#---------------------------------------------- link ---------------------------------------------------
$(TEST_BINS): %.testbin : %.o $(OBJS) $(GTEST_OBJS) $(GTEST_MAIN)
@ echo LD -o $<
@ $(CXX) $< $(GTEST_OBJS) $(GTEST_MAIN) $(OBJS) -o $@ $(LDFLAGS) $(COMMON_FLAGS) $(WARNINGS)
$(TOOL_BINS): %.bin : %.o $(OBJS)
@ echo LD -o $<
@ $(CXX) $< $(OBJS) -o $@ $(COMMON_FLAGS) $(LDFLAGS) $(WARNINGS)
$(NAME): $(OBJS)
@ echo LD -o $@
@$(LINK) -shared $(OBJS) -o $(NAME) $(COMMON_FLAGS)
$(LIB): $(OBJS)
@ echo AR -o $@
@ ar rcs $@ $(OBJS)
#---------------------------------------------- compile -------------------------------------------------
$(TEST_OBJS): build/%.o: %.cpp
@ echo CXX $<
@$(CXX) $(CXXFLAGS) $(COMMON_FLAGS) -c $< -o $@
$(GTEST_OBJS): build/%.o: %.cpp
@ echo CXX $<
@$(CXX) $(CXXFLAGS) $(COMMON_FLAGS) -c $< -o $@
$(TOOL_OBJS): build/%.o: %.cpp
@ echo CXX $<
@$(CXX) $(CXXFLAGS) $(COMMON_FLAGS) -c $< -o $@
$(CU_OBJS): build/cuda/%.o: %.cu $(PROTO_GEN_CC)
@ echo NVCC $<
@$(NVCC) $(NVCCFLAGS) -M $< -o ${@:.o=.d} -odir $(@D)
@$(NVCC) $(NVCCFLAGS) -c $< -o $@
$(CXX_OBJS): build/%.o: %.cpp $(PROTO_GEN_CC)
@ echo CXX $<
@$(CXX) $(CXXFLAGS) $(COMMON_FLAGS) -c $< -o $@
$(PROTO_OBJS): $(PROTO_GEN_CC)
@ echo CXX $<
@$(CXX) $(CXXFLAGS) $(COMMON_FLAGS) -c $< -o $@
$(PROTO_GEN_CC): $(PROTO_SRCS)
@ mkdir -p $(foreach file,$(layer_folders),build/$(file)) build/src/caffe/solvers build/src/caffe/proto build/src/caffe/test build/src/gtest build/src/caffe/util build/tools
@ mkdir -p $(foreach file,$(layer_folders),build/cuda/$(file)) build/cuda/src/caffe/proto build/cuda/src/caffe/test build/cuda/src/gtest build/cuda/src/caffe build/cuda/src/caffe/util build/cuda/tools
@ echo PROTOC -o $@
@ protoc $(PROTO_SRCS) --cpp_out=.
clean:
@- $(RM) -rf build
@- $(RM) $(PROTO_GEN_HEADER) $(PROTO_GEN_CC)
@- $(RM) libcaffe.a libcaffe.so