]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - jacinto-ai/caffe-jacinto.git/blob - Makefile
solver restructuring: now all prototxt are specified in the solver protocol buffer
[jacinto-ai/caffe-jacinto.git] / Makefile
1 # The makefile for caffe. Extremely hack.
2 PROJECT := caffe
3 TEST_GPUID := 1
5 # The target static library and shared library name
6 NAME := lib$(PROJECT).so
7 STATIC_NAME := lib$(PROJECT).a
8 # All source files
9 CXX_SRCS := $(shell find src/caffe ! -name "test_*.cpp" -name "*.cpp")
10 CU_SRCS := $(shell find src/caffe -name "*.cu")
11 TEST_SRCS := $(shell find src/caffe -name "test_*.cpp")
12 GTEST_SRC := src/gtest/gtest-all.cpp
13 EXAMPLE_SRCS := $(shell find examples -name "*.cpp")
14 PROTO_SRCS := $(wildcard src/caffe/proto/*.proto)
15 # The generated files for protocol buffers
16 PROTO_GEN_HEADER := ${PROTO_SRCS:.proto=.pb.h}
17 PROTO_GEN_CC := ${PROTO_SRCS:.proto=.pb.cc}
18 PROTO_GEN_PY := ${PROTO_SRCS:.proto=_pb2.py}
19 # The objects that are needed to generate the library
20 CXX_OBJS := ${CXX_SRCS:.cpp=.o}
21 CU_OBJS := ${CU_SRCS:.cu=.cuo}
22 PROTO_OBJS := ${PROTO_GEN_CC:.cc=.o}
23 OBJS := $(PROTO_OBJS) $(CXX_OBJS) $(CU_OBJS)
24 # program and test objects
25 EXAMPLE_OBJS := ${EXAMPLE_SRCS:.cpp=.o}
26 TEST_OBJS := ${TEST_SRCS:.cpp=.o}
27 GTEST_OBJ := ${GTEST_SRC:.cpp=.o}
28 # program and test bins
29 EXAMPLE_BINS :=${EXAMPLE_OBJS:.o=.bin}
30 TEST_BINS := ${TEST_OBJS:.o=.testbin}
32 # define third-party library paths
33 CUDA_DIR := /usr/local/cuda
34 CUDA_ARCH := -arch=sm_30
35 MKL_DIR := /opt/intel/mkl
37 CUDA_INCLUDE_DIR := $(CUDA_DIR)/include
38 CUDA_LIB_DIR := $(CUDA_DIR)/lib64
39 MKL_INCLUDE_DIR := $(MKL_DIR)/include
40 MKL_LIB_DIR := $(MKL_DIR)/lib $(MKL_DIR)/lib/intel64
42 # define inclue and libaries
43 # We put src here just for gtest
44 INCLUDE_DIRS := ./src ./include /usr/local/include $(CUDA_INCLUDE_DIR) $(MKL_INCLUDE_DIR)
45 LIBRARY_DIRS := /usr/lib /usr/local/lib $(CUDA_LIB_DIR) $(MKL_LIB_DIR)
46 LIBRARIES := cuda cudart cublas curand protobuf opencv_core opencv_highgui \
47         glog mkl_rt mkl_intel_thread leveldb snappy pthread
48 WARNINGS := -Wall
50 COMMON_FLAGS := -DNDEBUG $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
51 CXXFLAGS += -pthread -fPIC -O2 $(COMMON_FLAGS)
52 NVCCFLAGS := -Xcompiler -fPIC -O2 $(COMMON_FLAGS)
53 LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) \
54                 $(foreach library,$(LIBRARIES),-l$(library))
56 NVCC = nvcc $(NVCCFLAGS) $(CPPFLAGS) $(CUDA_ARCH)
58 .PHONY: all test clean distclean linecount examples distribute
60 all: $(NAME) $(STATIC_NAME) test examples
62 linecount: clean
63         cloc --read-lang-def=caffe.cloc src/caffe/
65 test: $(TEST_BINS)
67 examples: $(EXAMPLE_BINS)
69 $(NAME): $(PROTO_OBJS) $(OBJS)
70         $(CXX) -shared $(OBJS) -o $(NAME) $(LDFLAGS) $(WARNINGS)
72 $(STATIC_NAME): $(PROTO_OBJS) $(OBJS)
73         ar rcs $(STATIC_NAME) $(PROTO_OBJS) $(OBJS)
75 runtest: test
76         for testbin in $(TEST_BINS); do $$testbin $(TEST_GPUID); done
78 $(TEST_BINS): %.testbin : %.o $(GTEST_OBJ) $(STATIC_NAME)
79         $(CXX) $< $(GTEST_OBJ) $(STATIC_NAME) -o $@ $(LDFLAGS) $(WARNINGS)
81 $(EXAMPLE_BINS): %.bin : %.o $(STATIC_NAME)
82         $(CXX) $< $(STATIC_NAME) -o $@ $(LDFLAGS) $(WARNINGS)
84 $(OBJS): $(PROTO_GEN_CC)
86 $(EXAMPLE_OBJS): $(PROTO_GEN_CC)
88 $(CU_OBJS): %.cuo: %.cu
89         $(NVCC) -c $< -o $@
91 $(PROTO_GEN_CC): $(PROTO_SRCS)
92         protoc --proto_path=src --cpp_out=src --python_out=src $(PROTO_SRCS)
93         mkdir -p include/caffe/proto
94         cp $(PROTO_GEN_HEADER) include/caffe/proto/
96 clean:
97         @- $(RM) $(NAME) $(STATIC_NAME) $(TEST_BINS) $(EXAMPLE_BINS)
98         @- $(RM) $(OBJS) $(TEST_OBJS) $(EXAMPLE_OBJS)
99         @- $(RM) $(PROTO_GEN_HEADER) $(PROTO_GEN_CC) $(PROTO_GEN_PY)
100         @- $(RM) -rf build
102 distclean: clean
104 distribute: all
105         mkdir build
106         cp -r include build/
107         mkdir build/bin
108         cp $(EXAMPLE_BINS) build/bin
109         mkdir build/lib
110         cp $(NAME) build/lib
111         cp $(STATIC_NAME) build/lib