2013-10-11 02:20:20 +04:00
|
|
|
# The makefile for caffe. Extremely hack.
|
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
|
|
|
|
|
|
|
# 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
|
|
|
|
# All source files
|
2013-10-16 01:35:14 +04:00
|
|
|
CXX_SRCS := $(shell find src/caffe ! -name "test_*.cpp" -name "*.cpp")
|
|
|
|
CU_SRCS := $(shell find src/caffe -name "*.cu")
|
|
|
|
TEST_SRCS := $(shell find src/caffe -name "test_*.cpp")
|
|
|
|
GTEST_SRC := src/gtest/gtest-all.cpp
|
|
|
|
EXAMPLE_SRCS := $(shell find examples -name "*.cpp")
|
|
|
|
PROTO_SRCS := $(wildcard src/caffe/proto/*.proto)
|
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-10-11 02:20:20 +04:00
|
|
|
# The objects that are needed to generate the library
|
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-10-11 02:20:20 +04:00
|
|
|
# define third-party library paths
|
2013-09-16 22:33:38 +04:00
|
|
|
CUDA_DIR := /usr/local/cuda
|
2013-10-14 21:47:59 +04:00
|
|
|
CUDA_ARCH := -arch=sm_30
|
2013-09-16 22:33:38 +04:00
|
|
|
MKL_DIR := /opt/intel/mkl
|
2013-09-13 04:10:48 +04:00
|
|
|
|
2013-09-16 22:33:38 +04:00
|
|
|
CUDA_INCLUDE_DIR := $(CUDA_DIR)/include
|
|
|
|
CUDA_LIB_DIR := $(CUDA_DIR)/lib64
|
|
|
|
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-10-11 02:20:20 +04:00
|
|
|
# define inclue and libaries
|
2013-10-16 01:35:14 +04:00
|
|
|
# We put src here just for gtest
|
2013-11-09 01:50:12 +04:00
|
|
|
INCLUDE_DIRS := ./src ./include /usr/local/include $(CUDA_INCLUDE_DIR) \
|
2013-11-12 05:07:32 +04:00
|
|
|
$(MKL_INCLUDE_DIR)
|
2013-10-16 01:35:14 +04:00
|
|
|
LIBRARY_DIRS := /usr/lib /usr/local/lib $(CUDA_LIB_DIR) $(MKL_LIB_DIR)
|
2013-10-26 20:42:42 +04:00
|
|
|
LIBRARIES := cuda 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-09-13 04:10:48 +04:00
|
|
|
WARNINGS := -Wall
|
|
|
|
|
2013-11-01 03:52:22 +04:00
|
|
|
COMMON_FLAGS := -DNDEBUG $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
|
2013-10-11 02:20:20 +04:00
|
|
|
CXXFLAGS += -pthread -fPIC -O2 $(COMMON_FLAGS)
|
|
|
|
NVCCFLAGS := -Xcompiler -fPIC -O2 $(COMMON_FLAGS)
|
|
|
|
LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) \
|
|
|
|
$(foreach library,$(LIBRARIES),-l$(library))
|
2013-09-13 04:10:48 +04:00
|
|
|
|
2013-11-20 01:39:20 +04:00
|
|
|
NVCC = $(CUDA_DIR)/bin/nvcc $(NVCCFLAGS) $(CPPFLAGS) $(CUDA_ARCH)
|
2013-09-13 04:10:48 +04:00
|
|
|
|
2013-11-13 01:49:37 +04:00
|
|
|
.PHONY: all test clean distclean linecount examples pycaffe distribute
|
2013-09-13 04:10:48 +04:00
|
|
|
|
2013-11-13 01:49:37 +04:00
|
|
|
all: $(NAME) $(STATIC_NAME) test examples pycaffe
|
|
|
|
|
2013-11-13 02:14:02 +04:00
|
|
|
pycaffe: $(STATIC_NAME) python/caffe/pycaffe.cpp $(PROTO_GEN_PY)
|
|
|
|
protoc --proto_path=src --python_out=python $(PROTO_SRCS)
|
2013-11-13 23:29:26 +04:00
|
|
|
$(CXX) -o python/caffe/pycaffe.so -I/usr/include/python2.7 \
|
|
|
|
-I/usr/local/lib/python2.7/dist-packages/numpy/core/include/ -shared \
|
2013-11-13 02:05:28 +04:00
|
|
|
python/caffe/pycaffe.cpp $(STATIC_NAME) $(CXXFLAGS) $(LDFLAGS) \
|
2013-11-13 01:49:37 +04:00
|
|
|
$(WARNING) -lboost_python -lpython2.7
|
2013-09-13 04:10:48 +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-10-11 02:20:20 +04:00
|
|
|
$(NAME): $(PROTO_OBJS) $(OBJS)
|
|
|
|
$(CXX) -shared $(OBJS) -o $(NAME) $(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-10-11 02:20:20 +04:00
|
|
|
$(TEST_BINS): %.testbin : %.o $(GTEST_OBJ) $(STATIC_NAME)
|
|
|
|
$(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-10-11 03:54:39 +04:00
|
|
|
$(OBJS): $(PROTO_GEN_CC)
|
|
|
|
|
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-09-17 00:38:35 +04:00
|
|
|
$(NVCC) -c $< -o $@
|
2013-09-16 22:25:43 +04:00
|
|
|
|
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-09-13 08:10:35 +04:00
|
|
|
distclean: clean
|
2013-10-16 01:35:14 +04:00
|
|
|
|
|
|
|
distribute: all
|
|
|
|
mkdir build
|
|
|
|
cp -r include build/
|
|
|
|
mkdir build/bin
|
|
|
|
cp $(EXAMPLE_BINS) build/bin
|
|
|
|
mkdir build/lib
|
|
|
|
cp $(NAME) build/lib
|
|
|
|
cp $(STATIC_NAME) build/lib
|