2013-11-22 01:31:18 +04:00
|
|
|
# The makefile for caffe. Extremely hacky.
|
2013-09-22 21:18:13 +04:00
|
|
|
PROJECT := caffe
|
2013-11-16 04:58:53 +04:00
|
|
|
TEST_GPUID := 0
|
2013-10-11 02:20:20 +04:00
|
|
|
|
2013-11-26 21:47:26 +04:00
|
|
|
include Makefile.config
|
2013-11-22 01:31:18 +04:00
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
# After this line, things should happen automatically.
|
|
|
|
##############################################################################
|
|
|
|
|
2013-10-11 02:20:20 +04:00
|
|
|
# The target static library and shared library name
|
2013-09-13 04:10:48 +04:00
|
|
|
NAME := lib$(PROJECT).so
|
2013-10-11 02:20:20 +04:00
|
|
|
STATIC_NAME := lib$(PROJECT).a
|
2013-11-22 01:31:18 +04:00
|
|
|
|
|
|
|
##############################
|
|
|
|
# Get all source files
|
|
|
|
##############################
|
|
|
|
# CXX_SRCS are the source files excluding the test ones.
|
2013-10-16 01:35:14 +04:00
|
|
|
CXX_SRCS := $(shell find src/caffe ! -name "test_*.cpp" -name "*.cpp")
|
2013-11-29 01:55:17 +04:00
|
|
|
# HXX_SRCS are the header files
|
|
|
|
HXX_SRCS := $(shell find include/caffe ! -name "*.hpp")
|
2013-11-22 01:31:18 +04:00
|
|
|
# CU_SRCS are the cuda source files
|
2013-10-16 01:35:14 +04:00
|
|
|
CU_SRCS := $(shell find src/caffe -name "*.cu")
|
2013-11-22 01:31:18 +04:00
|
|
|
# TEST_SRCS are the test source files
|
2013-10-16 01:35:14 +04:00
|
|
|
TEST_SRCS := $(shell find src/caffe -name "test_*.cpp")
|
|
|
|
GTEST_SRC := src/gtest/gtest-all.cpp
|
2013-11-29 01:55:17 +04:00
|
|
|
# TEST_HDRS are the test header files
|
|
|
|
TEST_HDRS := $(shell find src/caffe -name "test_*.hpp")
|
|
|
|
# EXAMPLE_SRCS are the source files for the example binaries
|
2013-10-16 01:35:14 +04:00
|
|
|
EXAMPLE_SRCS := $(shell find examples -name "*.cpp")
|
2013-11-22 01:31:18 +04:00
|
|
|
# PROTO_SRCS are the protocol buffer definitions
|
2013-10-16 01:35:14 +04:00
|
|
|
PROTO_SRCS := $(wildcard src/caffe/proto/*.proto)
|
2013-11-22 01:31:18 +04:00
|
|
|
# PYCAFFE_SRC is the python wrapper for caffe
|
|
|
|
PYCAFFE_SRC := python/caffe/pycaffe.cpp
|
|
|
|
PYCAFFE_SO := python/caffe/pycaffe.so
|
2013-11-23 02:16:58 +04:00
|
|
|
# MATCAFFE_SRC is the matlab wrapper for caffe
|
|
|
|
MATCAFFE_SRC := matlab/caffe/matcaffe.cpp
|
|
|
|
MATCAFFE_SO := matlab/caffe/caffe
|
2013-11-22 01:31:18 +04:00
|
|
|
|
|
|
|
##############################
|
|
|
|
# Derive generated files
|
|
|
|
##############################
|
2013-10-11 02:20:20 +04:00
|
|
|
# The generated files for protocol buffers
|
2013-09-13 04:10:48 +04:00
|
|
|
PROTO_GEN_HEADER := ${PROTO_SRCS:.proto=.pb.h}
|
|
|
|
PROTO_GEN_CC := ${PROTO_SRCS:.proto=.pb.cc}
|
2013-09-17 22:47:03 +04:00
|
|
|
PROTO_GEN_PY := ${PROTO_SRCS:.proto=_pb2.py}
|
2013-11-22 01:31:18 +04:00
|
|
|
# The objects corresponding to the source files
|
2013-11-22 05:00:57 +04:00
|
|
|
# These objects will be linked into the final shared library, so we
|
2013-11-22 01:31:18 +04:00
|
|
|
# exclude the test and example objects.
|
2013-09-13 04:10:48 +04:00
|
|
|
CXX_OBJS := ${CXX_SRCS:.cpp=.o}
|
2013-09-20 03:26:01 +04:00
|
|
|
CU_OBJS := ${CU_SRCS:.cu=.cuo}
|
2013-10-11 02:20:20 +04:00
|
|
|
PROTO_OBJS := ${PROTO_GEN_CC:.cc=.o}
|
2013-09-16 22:25:43 +04:00
|
|
|
OBJS := $(PROTO_OBJS) $(CXX_OBJS) $(CU_OBJS)
|
2013-10-11 02:20:20 +04:00
|
|
|
# program and test objects
|
2013-10-16 01:35:14 +04:00
|
|
|
EXAMPLE_OBJS := ${EXAMPLE_SRCS:.cpp=.o}
|
2013-09-13 04:10:48 +04:00
|
|
|
TEST_OBJS := ${TEST_SRCS:.cpp=.o}
|
2013-09-20 02:19:50 +04:00
|
|
|
GTEST_OBJ := ${GTEST_SRC:.cpp=.o}
|
2013-10-11 02:20:20 +04:00
|
|
|
# program and test bins
|
2013-10-16 01:35:14 +04:00
|
|
|
EXAMPLE_BINS :=${EXAMPLE_OBJS:.o=.bin}
|
2013-10-11 02:20:20 +04:00
|
|
|
TEST_BINS := ${TEST_OBJS:.o=.testbin}
|
2013-09-13 04:10:48 +04:00
|
|
|
|
2013-11-22 01:31:18 +04:00
|
|
|
##############################
|
|
|
|
# Derive include and lib directories
|
|
|
|
##############################
|
2013-09-16 22:33:38 +04:00
|
|
|
CUDA_INCLUDE_DIR := $(CUDA_DIR)/include
|
2013-11-25 10:13:34 +04:00
|
|
|
CUDA_LIB_DIR := $(CUDA_DIR)/lib64 $(CUDA_DIR)/lib
|
2013-09-16 22:33:38 +04:00
|
|
|
MKL_INCLUDE_DIR := $(MKL_DIR)/include
|
2013-09-16 22:47:20 +04:00
|
|
|
MKL_LIB_DIR := $(MKL_DIR)/lib $(MKL_DIR)/lib/intel64
|
2013-09-13 04:10:48 +04:00
|
|
|
|
2013-11-22 01:31:18 +04:00
|
|
|
INCLUDE_DIRS += ./src ./include $(CUDA_INCLUDE_DIR) $(MKL_INCLUDE_DIR)
|
|
|
|
LIBRARY_DIRS += $(CUDA_LIB_DIR) $(MKL_LIB_DIR)
|
|
|
|
LIBRARIES := cudart cublas curand protobuf opencv_core opencv_highgui \
|
2013-11-09 01:50:12 +04:00
|
|
|
glog mkl_rt mkl_intel_thread leveldb snappy pthread boost_system \
|
2013-11-12 05:08:27 +04:00
|
|
|
opencv_imgproc
|
2013-11-22 01:31:18 +04:00
|
|
|
PYTHON_LIBRARIES := boost_python python2.7
|
2013-09-13 04:10:48 +04:00
|
|
|
WARNINGS := -Wall
|
|
|
|
|
2013-11-26 21:47:26 +04:00
|
|
|
COMMON_FLAGS := -DNDEBUG -O2 $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
|
|
|
|
CXXFLAGS += -pthread -fPIC $(COMMON_FLAGS)
|
|
|
|
NVCCFLAGS := -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
|
2013-10-11 02:20:20 +04:00
|
|
|
LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) \
|
2013-11-26 21:49:29 +04:00
|
|
|
$(foreach library,$(LIBRARIES),-l$(library))
|
2013-11-22 01:31:18 +04:00
|
|
|
PYTHON_LDFLAGS := $(LDFLAGS) $(foreach library,$(PYTHON_LIBRARIES),-l$(library))
|
2013-09-13 04:10:48 +04:00
|
|
|
|
|
|
|
|
2013-11-22 01:31:18 +04:00
|
|
|
##############################
|
|
|
|
# Define build targets
|
|
|
|
##############################
|
|
|
|
.PHONY: all test clean linecount examples pycaffe distribute
|
2013-09-13 04:10:48 +04:00
|
|
|
|
2013-11-23 21:37:27 +04:00
|
|
|
all: $(NAME) $(STATIC_NAME) examples
|
2013-11-13 01:49:37 +04:00
|
|
|
|
2013-09-19 10:43:20 +04:00
|
|
|
linecount: clean
|
2013-10-16 01:35:14 +04:00
|
|
|
cloc --read-lang-def=caffe.cloc src/caffe/
|
2013-09-17 22:47:03 +04:00
|
|
|
|
2013-10-11 02:20:20 +04:00
|
|
|
test: $(TEST_BINS)
|
2013-09-20 02:19:50 +04:00
|
|
|
|
2013-10-16 01:35:14 +04:00
|
|
|
examples: $(EXAMPLE_BINS)
|
2013-10-02 01:00:18 +04:00
|
|
|
|
2013-11-22 01:31:18 +04:00
|
|
|
pycaffe: $(STATIC_NAME) $(PYCAFFE_SRC) $(PROTO_GEN_PY)
|
|
|
|
$(CXX) -shared -o $(PYCAFFE_SO) $(PYCAFFE_SRC) \
|
|
|
|
$(STATIC_NAME) $(CXXFLAGS) $(PYTHON_LDFLAGS)
|
|
|
|
|
2013-11-23 02:16:58 +04:00
|
|
|
matcaffe: $(STATIC_NAME) $(MATCAFFE_SRC)
|
2013-11-23 21:37:27 +04:00
|
|
|
$(MATLAB_DIR)/bin/mex $(MATCAFFE_SRC) $(STATIC_NAME) \
|
2013-11-23 02:16:58 +04:00
|
|
|
CXXFLAGS="\$$CXXFLAGS $(CXXFLAGS) $(WARNINGS)" \
|
|
|
|
CXXLIBS="\$$CXXLIBS $(LDFLAGS)" \
|
|
|
|
-o $(MATCAFFE_SO)
|
|
|
|
|
2013-10-11 02:20:20 +04:00
|
|
|
$(NAME): $(PROTO_OBJS) $(OBJS)
|
2013-11-22 01:31:18 +04:00
|
|
|
$(CXX) -shared -o $(NAME) $(OBJS) $(LDFLAGS) $(WARNINGS)
|
2013-09-20 02:46:45 +04:00
|
|
|
|
2013-10-11 02:20:20 +04:00
|
|
|
$(STATIC_NAME): $(PROTO_OBJS) $(OBJS)
|
|
|
|
ar rcs $(STATIC_NAME) $(PROTO_OBJS) $(OBJS)
|
|
|
|
|
|
|
|
runtest: test
|
|
|
|
for testbin in $(TEST_BINS); do $$testbin $(TEST_GPUID); done
|
2013-09-13 04:10:48 +04:00
|
|
|
|
2013-11-29 01:55:17 +04:00
|
|
|
$(TEST_BINS): %.testbin : %.o $(GTEST_OBJ) $(STATIC_NAME) $(TEST_HDRS)
|
2013-10-11 02:20:20 +04:00
|
|
|
$(CXX) $< $(GTEST_OBJ) $(STATIC_NAME) -o $@ $(LDFLAGS) $(WARNINGS)
|
2013-10-02 01:00:18 +04:00
|
|
|
|
2013-10-16 01:35:14 +04:00
|
|
|
$(EXAMPLE_BINS): %.bin : %.o $(STATIC_NAME)
|
2013-10-11 02:20:20 +04:00
|
|
|
$(CXX) $< $(STATIC_NAME) -o $@ $(LDFLAGS) $(WARNINGS)
|
2013-09-13 04:10:48 +04:00
|
|
|
|
2013-11-29 01:55:17 +04:00
|
|
|
$(OBJS): $(PROTO_GEN_CC) $(HXX_SRCS)
|
2013-10-11 03:54:39 +04:00
|
|
|
|
2013-10-16 01:35:14 +04:00
|
|
|
$(EXAMPLE_OBJS): $(PROTO_GEN_CC)
|
2013-10-11 03:54:39 +04:00
|
|
|
|
2013-09-20 03:26:01 +04:00
|
|
|
$(CU_OBJS): %.cuo: %.cu
|
2013-11-22 01:31:18 +04:00
|
|
|
$(CUDA_DIR)/bin/nvcc $(NVCCFLAGS) $(CUDA_ARCH) -c $< -o $@
|
2013-09-16 22:25:43 +04:00
|
|
|
|
2013-11-20 03:05:39 +04:00
|
|
|
$(PROTO_GEN_PY): $(PROTO_SRCS)
|
|
|
|
protoc --proto_path=src --python_out=python $(PROTO_SRCS)
|
|
|
|
|
2013-09-13 04:10:48 +04:00
|
|
|
$(PROTO_GEN_CC): $(PROTO_SRCS)
|
2013-11-20 01:39:20 +04:00
|
|
|
protoc --proto_path=src --cpp_out=src $(PROTO_SRCS)
|
2013-10-16 01:35:14 +04:00
|
|
|
mkdir -p include/caffe/proto
|
|
|
|
cp $(PROTO_GEN_HEADER) include/caffe/proto/
|
2013-09-13 04:10:48 +04:00
|
|
|
|
|
|
|
clean:
|
2013-10-16 01:35:14 +04:00
|
|
|
@- $(RM) $(NAME) $(STATIC_NAME) $(TEST_BINS) $(EXAMPLE_BINS)
|
|
|
|
@- $(RM) $(OBJS) $(TEST_OBJS) $(EXAMPLE_OBJS)
|
2013-09-17 22:47:03 +04:00
|
|
|
@- $(RM) $(PROTO_GEN_HEADER) $(PROTO_GEN_CC) $(PROTO_GEN_PY)
|
2013-11-13 02:31:09 +04:00
|
|
|
@- $(RM) include/caffe/proto/caffe.pb.h
|
|
|
|
@- $(RM) python/caffe/proto/caffe_pb2.py
|
2013-10-16 01:35:14 +04:00
|
|
|
@- $(RM) -rf build
|
2013-09-13 04:10:48 +04:00
|
|
|
|
2013-10-16 01:35:14 +04:00
|
|
|
distribute: all
|
|
|
|
mkdir build
|
2013-11-22 01:31:18 +04:00
|
|
|
# add include
|
2013-10-16 01:35:14 +04:00
|
|
|
cp -r include build/
|
2013-11-22 01:31:18 +04:00
|
|
|
# add example binaries
|
2013-10-16 01:35:14 +04:00
|
|
|
mkdir build/bin
|
|
|
|
cp $(EXAMPLE_BINS) build/bin
|
2013-11-22 01:31:18 +04:00
|
|
|
# add libraries
|
2013-10-16 01:35:14 +04:00
|
|
|
mkdir build/lib
|
|
|
|
cp $(NAME) build/lib
|
|
|
|
cp $(STATIC_NAME) build/lib
|
2013-11-22 01:31:18 +04:00
|
|
|
# add python - it's not the standard way, indeed...
|
|
|
|
cp -r python build/python
|