From 654d8114ed5f7526e2c1755e54cbff224341170c Mon Sep 17 00:00:00 2001 From: Jeff Donahue Date: Sat, 29 Mar 2014 17:46:39 -0700 Subject: [PATCH 01/18] put TEST_GPUID in Makefile.config --- Makefile | 1 - Makefile.config.example | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index acef07d6837..a432c871b89 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,5 @@ # The makefile for caffe. Extremely hacky. PROJECT := caffe -TEST_GPUID := 0 include Makefile.config diff --git a/Makefile.config.example b/Makefile.config.example index e747d2a76ad..09aea6f94eb 100644 --- a/Makefile.config.example +++ b/Makefile.config.example @@ -48,3 +48,6 @@ DISTRIBUTE_DIR := distribute # uncomment for debugging #DEBUG := 1 + +# The ID of the GPU that 'make runtest' will use to run unit tests. +TEST_GPUID := 0 From 3abb10e9107226e2e9353913abef691b37e84377 Mon Sep 17 00:00:00 2001 From: Jeff Donahue Date: Sat, 29 Mar 2014 17:47:58 -0700 Subject: [PATCH 02/18] create superclean Makefile target to delete all files with generated extensions --- Makefile | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a432c871b89..ac91df729d5 100644 --- a/Makefile +++ b/Makefile @@ -124,7 +124,8 @@ PYTHON_LDFLAGS := $(LDFLAGS) $(foreach library,$(PYTHON_LIBRARIES),-l$(library)) # Define build targets ############################## .PHONY: all init test clean linecount lint tools examples py mat distribute \ - py$(PROJECT) mat$(PROJECT) proto runtest + py$(PROJECT) mat$(PROJECT) proto runtest \ + superclean supercleanlist supercleanfiles all: init $(NAME) $(STATIC_NAME) tools examples @echo $(CXX_OBJS) @@ -260,6 +261,40 @@ clean: @- $(RM) -rf $(BUILD_DIR) @- $(RM) -rf $(DISTRIBUTE_DIR) +# make superclean recursively* deletes all files ending with an extension +# suggesting that Caffe built them. This may be useful if you've built older +# versions of Caffe that do not place all generated files in a location known +# to make clean. +# +# make supercleanlist will list the files to be deleted by make superclean. +# +# * Recursive with the exception that symbolic links are never followed, per the +# default behavior of 'find'. +SUPERCLEAN_EXTS := .so .a .o .bin .testbin .pb.cc .pb.h _pb2.py .cuo + +supercleanfiles: + $(eval SUPERCLEAN_FILES := \ + $(strip $(foreach ext,$(SUPERCLEAN_EXTS), \ + $(shell find . -name '*$(ext)')))) + +supercleanlist: supercleanfiles + @ \ + if [ -z "$(SUPERCLEAN_FILES)" ]; then \ + echo "No generated files found."; \ + else \ + echo $(SUPERCLEAN_FILES); \ + fi + +superclean: clean supercleanfiles + @ \ + if [ -z "$(SUPERCLEAN_FILES)" ]; then \ + echo "No generated files found."; \ + else \ + echo "Deleting the following generated files:"; \ + echo $(SUPERCLEAN_FILES); \ + $(RM) $(SUPERCLEAN_FILES); \ + fi + distribute: all mkdir $(DISTRIBUTE_DIR) # add include From a750a31c5eef6d6e31b9607156036e735478a7e0 Mon Sep 17 00:00:00 2001 From: Jeff Donahue Date: Sat, 29 Mar 2014 18:29:15 -0700 Subject: [PATCH 03/18] create softlink to test directory at build/test --- Makefile | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index ac91df729d5..e9f48d826c1 100644 --- a/Makefile +++ b/Makefile @@ -75,7 +75,11 @@ GTEST_OBJ := $(addprefix $(BUILD_DIR)/, ${GTEST_SRC:.cpp=.o}) TOOL_BINS := ${TOOL_OBJS:.o=.bin} EXAMPLE_BINS := ${EXAMPLE_OBJS:.o=.bin} TEST_BINS := ${TEST_OBJS:.o=.testbin} -TEST_ALL_BIN := $(BUILD_DIR)/src/$(PROJECT)/test/test_all.testbin +TEST_BUILD_SUB_DIR := src/$(PROJECT)/test +TEST_DIR = $(BUILD_DIR)/$(TEST_BUILD_SUB_DIR) +TEST_ALL_BIN := $(TEST_DIR)/test_all.testbin +# A shortcut to the directory of test binaries for convenience. +TEST_DIR_LINK := $(BUILD_DIR)/test ############################## # Derive include and lib directories @@ -123,9 +127,10 @@ PYTHON_LDFLAGS := $(LDFLAGS) $(foreach library,$(PYTHON_LIBRARIES),-l$(library)) ############################## # Define build targets ############################## -.PHONY: all init test clean linecount lint tools examples py mat distribute \ - py$(PROJECT) mat$(PROJECT) proto runtest \ - superclean supercleanlist supercleanfiles +.PHONY: all init test clean linecount lint tools examples distribute \ + py mat py$(PROJECT) mat$(PROJECT) proto runtest \ + superclean supercleanlist supercleanfiles \ + testshortcut all: init $(NAME) $(STATIC_NAME) tools examples @echo $(CXX_OBJS) @@ -184,11 +189,21 @@ $(STATIC_NAME): init $(PROTO_OBJS) $(OBJS) runtest: $(TEST_ALL_BIN) $(TEST_ALL_BIN) $(TEST_GPUID) -$(TEST_BINS): %.testbin : %.o $(GTEST_OBJ) $(STATIC_NAME) $(TEST_HDRS) - $(CXX) $(TEST_MAIN_SRC) $< $(GTEST_OBJ) $(STATIC_NAME) -o $@ $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) +$(TEST_BINS): %.testbin : %.o $(GTEST_OBJ) $(STATIC_NAME) $(TEST_HDRS) testshortcut + $(CXX) $(TEST_MAIN_SRC) $< $(GTEST_OBJ) $(STATIC_NAME) \ + -o $@ $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) -$(TEST_ALL_BIN): $(GTEST_OBJ) $(STATIC_NAME) $(TEST_OBJS) - $(CXX) $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) $(STATIC_NAME) -o $(TEST_ALL_BIN) $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) +$(TEST_ALL_BIN): $(GTEST_OBJ) $(STATIC_NAME) $(TEST_OBJS) testshortcut + $(CXX) $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) $(STATIC_NAME) \ + -o $(TEST_ALL_BIN) $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) + +testshortcut: $(TEST_DIR_LINK) + +$(TEST_DIR_LINK): $(TEST_DIR) + @ln -s $(TEST_BUILD_SUB_DIR) $(TEST_DIR_LINK) + +$(TEST_DIR): + @mkdir -p $(TEST_DIR) $(TOOL_BINS): %.bin : %.o $(STATIC_NAME) $(CXX) $< $(STATIC_NAME) -o $@ $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) From e29838ddf14fcbc01e4d4925750eef7d75c09575 Mon Sep 17 00:00:00 2001 From: Jeff Donahue Date: Sat, 29 Mar 2014 19:36:05 -0700 Subject: [PATCH 04/18] put proto-generated .cc and .h files in build directory --- Makefile | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index e9f48d826c1..23d7b6fe324 100644 --- a/Makefile +++ b/Makefile @@ -31,8 +31,15 @@ TEST_HDRS := $(shell find src/$(PROJECT) -name "test_*.hpp") TOOL_SRCS := $(shell find tools -name "*.cpp") # EXAMPLE_SRCS are the source files for the example binaries EXAMPLE_SRCS := $(shell find examples -name "*.cpp") +# BUILD_INCLUDE_DIR contains any generated header files we want to include. +BUILD_INCLUDE_DIR := $(BUILD_DIR)/include # PROTO_SRCS are the protocol buffer definitions -PROTO_SRCS := $(wildcard src/$(PROJECT)/proto/*.proto) +PROTO_SRC_DIR := src/$(PROJECT)/proto +PROTO_SRCS := $(wildcard $(PROTO_SRC_DIR)/*.proto) +# PROTO_BUILD_DIR will contain the .cc and obj files generated from +# PROTO_SRCS; PROTO_BUILD_INCLUDE_DIR will contain the .h header files +PROTO_BUILD_DIR := $(BUILD_DIR)/$(PROTO_SRC_DIR) +PROTO_BUILD_INCLUDE_DIR := $(BUILD_INCLUDE_DIR)/$(PROJECT)/proto # NONGEN_CXX_SRCS includes all source/header files except those generated # automatically (e.g., by proto). NONGEN_CXX_SRCS := $(shell find \ @@ -56,15 +63,15 @@ MAT$(PROJECT)_SO := matlab/$(PROJECT)/$(PROJECT) # Derive generated files ############################## # The generated files for protocol buffers -PROTO_GEN_HEADER := ${PROTO_SRCS:.proto=.pb.h} -PROTO_GEN_CC := ${PROTO_SRCS:.proto=.pb.cc} +PROTO_GEN_HEADER := $(addprefix $(BUILD_DIR)/, ${PROTO_SRCS:.proto=.pb.h}) +PROTO_GEN_CC := $(addprefix $(BUILD_DIR)/, ${PROTO_SRCS:.proto=.pb.cc}) PROTO_GEN_PY := ${PROTO_SRCS:.proto=_pb2.py} # The objects corresponding to the source files # These objects will be linked into the final shared library, so we # exclude the tool, example, and test objects. CXX_OBJS := $(addprefix $(BUILD_DIR)/, ${CXX_SRCS:.cpp=.o}) CU_OBJS := $(addprefix $(BUILD_DIR)/, ${CU_SRCS:.cu=.cuo}) -PROTO_OBJS := $(addprefix $(BUILD_DIR)/, ${PROTO_GEN_CC:.cc=.o}) +PROTO_OBJS := ${PROTO_GEN_CC:.cc=.o} OBJS := $(PROTO_OBJS) $(CXX_OBJS) $(CU_OBJS) # tool, example, and test objects TOOL_OBJS := $(addprefix $(BUILD_DIR)/, ${TOOL_SRCS:.cpp=.o}) @@ -90,6 +97,7 @@ MKL_INCLUDE_DIR := $(MKL_DIR)/include MKL_LIB_DIR := $(MKL_DIR)/lib $(MKL_DIR)/lib/intel64 INCLUDE_DIRS += ./src ./include $(CUDA_INCLUDE_DIR) +INCLUDE_DIRS += $(BUILD_INCLUDE_DIR) LIBRARY_DIRS += $(CUDA_LIB_DIR) LIBRARIES := cudart cublas curand \ pthread \ @@ -200,10 +208,10 @@ $(TEST_ALL_BIN): $(GTEST_OBJ) $(STATIC_NAME) $(TEST_OBJS) testshortcut testshortcut: $(TEST_DIR_LINK) $(TEST_DIR_LINK): $(TEST_DIR) - @ln -s $(TEST_BUILD_SUB_DIR) $(TEST_DIR_LINK) + ln -s $(TEST_BUILD_SUB_DIR) $(TEST_DIR_LINK) $(TEST_DIR): - @mkdir -p $(TEST_DIR) + mkdir -p $(TEST_DIR) $(TOOL_BINS): %.bin : %.o $(STATIC_NAME) $(CXX) $< $(STATIC_NAME) -o $@ $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) @@ -259,14 +267,19 @@ $(PROTO_GEN_PY): $(PROTO_SRCS) protoc --proto_path=src --python_out=python $(PROTO_SRCS) @echo -proto: $(PROTO_GEN_CC) +proto: init $(PROTO_GEN_CC) -$(PROTO_GEN_CC): $(PROTO_SRCS) - protoc --proto_path=src --cpp_out=src $(PROTO_SRCS) - mkdir -p include/$(PROJECT)/proto - cp $(PROTO_GEN_HEADER) include/$(PROJECT)/proto/ +$(PROTO_GEN_CC): $(PROTO_SRCS) $(PROTO_BUILD_DIR) $(PROTO_BUILD_INCLUDE_DIR) + protoc --proto_path=src --cpp_out=build/src $(PROTO_SRCS) + cp $(PROTO_GEN_HEADER) $(PROTO_BUILD_INCLUDE_DIR) @echo +$(PROTO_BUILD_DIR): + mkdir -p $(PROTO_BUILD_DIR) + +$(PROTO_BUILD_INCLUDE_DIR): + mkdir -p $(PROTO_BUILD_INCLUDE_DIR) + clean: @- $(RM) $(NAME) $(STATIC_NAME) @- $(RM) $(PROTO_GEN_HEADER) $(PROTO_GEN_CC) $(PROTO_GEN_PY) From 5d9040a3d8cc039eebed29b43a2d90c6e6f54844 Mon Sep 17 00:00:00 2001 From: Jeff Donahue Date: Sat, 29 Mar 2014 20:12:24 -0700 Subject: [PATCH 05/18] cleanup superclean output --- Makefile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 23d7b6fe324..b413df67a80 100644 --- a/Makefile +++ b/Makefile @@ -301,16 +301,15 @@ clean: SUPERCLEAN_EXTS := .so .a .o .bin .testbin .pb.cc .pb.h _pb2.py .cuo supercleanfiles: - $(eval SUPERCLEAN_FILES := \ - $(strip $(foreach ext,$(SUPERCLEAN_EXTS), \ - $(shell find . -name '*$(ext)')))) + $(eval SUPERCLEAN_FILES := $(strip \ + $(foreach ext,$(SUPERCLEAN_EXTS), $(shell find . -name '*$(ext)')))) supercleanlist: supercleanfiles @ \ if [ -z "$(SUPERCLEAN_FILES)" ]; then \ echo "No generated files found."; \ else \ - echo $(SUPERCLEAN_FILES); \ + echo $(SUPERCLEAN_FILES) | tr ' ' '\n'; \ fi superclean: clean supercleanfiles @@ -319,7 +318,7 @@ superclean: clean supercleanfiles echo "No generated files found."; \ else \ echo "Deleting the following generated files:"; \ - echo $(SUPERCLEAN_FILES); \ + echo $(SUPERCLEAN_FILES) | tr ' ' '\n'; \ $(RM) $(SUPERCLEAN_FILES); \ fi From 060c5f1ad6852b132cc42c3837dd845fe43ef233 Mon Sep 17 00:00:00 2001 From: Jeff Donahue Date: Sat, 29 Mar 2014 22:26:46 -0700 Subject: [PATCH 06/18] messed around with Makefile - currently in very messy state --- Makefile | 50 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index b413df67a80..ad74fb870a2 100644 --- a/Makefile +++ b/Makefile @@ -63,7 +63,9 @@ MAT$(PROJECT)_SO := matlab/$(PROJECT)/$(PROJECT) # Derive generated files ############################## # The generated files for protocol buffers -PROTO_GEN_HEADER := $(addprefix $(BUILD_DIR)/, ${PROTO_SRCS:.proto=.pb.h}) +PROTO_GEN_HEADER := $(addprefix $(PROTO_BUILD_INCLUDE_DIR)/, \ + $(notdir ${PROTO_SRCS:.proto=.pb.h})) +HXX_SRCS += $(PROTO_GEN_HEADER) PROTO_GEN_CC := $(addprefix $(BUILD_DIR)/, ${PROTO_SRCS:.proto=.pb.cc}) PROTO_GEN_PY := ${PROTO_SRCS:.proto=_pb2.py} # The objects corresponding to the source files @@ -166,7 +168,7 @@ $(LINT_REPORT): $(NONGEN_CXX_SRCS) test: init $(TEST_BINS) $(TEST_ALL_BIN) -tools: init $(TOOL_BINS) +tools: init proto $(TOOL_BINS) examples: init $(EXAMPLE_BINS) @@ -197,7 +199,9 @@ $(STATIC_NAME): init $(PROTO_OBJS) $(OBJS) runtest: $(TEST_ALL_BIN) $(TEST_ALL_BIN) $(TEST_GPUID) -$(TEST_BINS): %.testbin : %.o $(GTEST_OBJ) $(STATIC_NAME) $(TEST_HDRS) testshortcut +$(BUILD_DIR)/src/$(PROJECT)/test/%.testbin: \ + $(BUILD_DIR)/src/$(PROJECT)/test/%.o \ + $(GTEST_OBJ) $(STATIC_NAME) testshortcut $(CXX) $(TEST_MAIN_SRC) $< $(GTEST_OBJ) $(STATIC_NAME) \ -o $@ $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) @@ -205,9 +209,9 @@ $(TEST_ALL_BIN): $(GTEST_OBJ) $(STATIC_NAME) $(TEST_OBJS) testshortcut $(CXX) $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) $(STATIC_NAME) \ -o $(TEST_ALL_BIN) $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) -testshortcut: $(TEST_DIR_LINK) +testshortcut: | $(TEST_DIR_LINK) -$(TEST_DIR_LINK): $(TEST_DIR) +$(TEST_DIR_LINK): | $(TEST_DIR) ln -s $(TEST_BUILD_SUB_DIR) $(TEST_DIR_LINK) $(TEST_DIR): @@ -221,23 +225,29 @@ $(EXAMPLE_BINS): %.bin : %.o $(STATIC_NAME) $(CXX) $< $(STATIC_NAME) -o $@ $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) @echo -$(OBJS): $(PROTO_GEN_CC) $(HXX_SRCS) - $(BUILD_DIR)/src/$(PROJECT)/%.o: src/$(PROJECT)/%.cpp $(CXX) $< $(CXXFLAGS) -c -o $@ @echo -$(BUILD_DIR)/src/$(PROJECT)/layers/%.o: src/$(PROJECT)/layers/%.cpp +$(OBJS): $(PROTO_GEN_HEADER) $(HXX_SRCS) + @echo matched the first objs!! + + +LAYERS_DIR := $(BUILD_DIR)/src/$(PROJECT)/layers +$(LAYERS_DIR): + @ mkdir -p $(LAYERS_DIR) + +$(BUILD_DIR)/src/$(PROJECT)/layers/%.o: \ + src/$(PROJECT)/layers/%.cpp $(HXX_SRCS) | $(LAYERS_DIR) $(CXX) $< $(CXXFLAGS) -c -o $@ @echo -$(BUILD_DIR)/src/$(PROJECT)/proto/%.o: src/$(PROJECT)/proto/%.cc +$(BUILD_DIR)/src/$(PROJECT)/proto/%.o: src/$(PROJECT)/proto/%.cc src/$(PROJECT)/proto/%.h $(CXX) $< $(CXXFLAGS) -c -o $@ @echo -$(BUILD_DIR)/src/$(PROJECT)/test/%.o: src/test/%.cpp +$(BUILD_DIR)/src/$(PROJECT)/test/%.o: $(PROTO_GEN_HEADER) src/$(PROJECT)/test/%.cpp $(CXX) $< $(CXXFLAGS) -c -o $@ - @echo $(BUILD_DIR)/src/$(PROJECT)/util/%.o: src/$(PROJECT)/util/%.cpp $(CXX) $< $(CXXFLAGS) -c -o $@ @@ -255,11 +265,11 @@ $(BUILD_DIR)/src/$(PROJECT)/util/%.cuo: src/$(PROJECT)/util/%.cu $(CUDA_DIR)/bin/nvcc $(NVCCFLAGS) $(CUDA_ARCH) -c $< -o $@ @echo -$(BUILD_DIR)/tools/%.o: tools/%.cpp +$(BUILD_DIR)/tools/%.o: tools/%.cpp $(PROTO_GEN_HEADER) $(CXX) $< $(CXXFLAGS) -c -o $@ $(LDFLAGS) @echo -$(BUILD_DIR)/examples/%.o: examples/%.cpp +$(BUILD_DIR)/examples/%.o: examples/%.cpp $(PROTO_GEN_HEADER) $(CXX) $< $(CXXFLAGS) -c -o $@ $(LDFLAGS) @echo @@ -267,12 +277,16 @@ $(PROTO_GEN_PY): $(PROTO_SRCS) protoc --proto_path=src --python_out=python $(PROTO_SRCS) @echo -proto: init $(PROTO_GEN_CC) +proto: init $(PROTO_GEN_CC) $(PROTO_GEN_HEADER) + @echo PROTO_GEN_CC: $(PROTO_GEN_CC) + @echo PROTO_GEN_HEADER: $(PROTO_GEN_HEADER) + @echo PROTO_OBJS: $(PROTO_OBJS) -$(PROTO_GEN_CC): $(PROTO_SRCS) $(PROTO_BUILD_DIR) $(PROTO_BUILD_INCLUDE_DIR) - protoc --proto_path=src --cpp_out=build/src $(PROTO_SRCS) - cp $(PROTO_GEN_HEADER) $(PROTO_BUILD_INCLUDE_DIR) - @echo +$(PROTO_BUILD_DIR)/%.pb.cc $(PROTO_BUILD_DIR)/%.pb.h \ + $(PROTO_BUILD_INCLUDE_DIR)/%.pb.h: \ + $(PROTO_SRC_DIR)/%.proto | $(PROTO_BUILD_DIR) $(PROTO_BUILD_INCLUDE_DIR) + protoc --proto_path=src --cpp_out=build/src $< + cp $(PROTO_BUILD_DIR)/$(*F).pb.h $(PROTO_BUILD_INCLUDE_DIR)/$(*F).pb.h $(PROTO_BUILD_DIR): mkdir -p $(PROTO_BUILD_DIR) From fd09cb3641fbc132ba590e0ec8e2d58c921596a7 Mon Sep 17 00:00:00 2001 From: Jeff Donahue Date: Sun, 30 Mar 2014 04:14:48 -0700 Subject: [PATCH 07/18] lots of corrections to dependencies etc., things seem to mostly build coherently now --- Makefile | 230 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 120 insertions(+), 110 deletions(-) diff --git a/Makefile b/Makefile index ad74fb870a2..26c9517e821 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# The makefile for caffe. Extremely hacky. +# The makefile for caffe. Pretty hacky. PROJECT := caffe include Makefile.config @@ -33,7 +33,7 @@ TOOL_SRCS := $(shell find tools -name "*.cpp") EXAMPLE_SRCS := $(shell find examples -name "*.cpp") # BUILD_INCLUDE_DIR contains any generated header files we want to include. BUILD_INCLUDE_DIR := $(BUILD_DIR)/include -# PROTO_SRCS are the protocol buffer definitions +# PROTO_SRCS are the protocol buffer defions PROTO_SRC_DIR := src/$(PROJECT)/proto PROTO_SRCS := $(wildcard $(PROTO_SRC_DIR)/*.proto) # PROTO_BUILD_DIR will contain the .cc and obj files generated from @@ -63,32 +63,45 @@ MAT$(PROJECT)_SO := matlab/$(PROJECT)/$(PROJECT) # Derive generated files ############################## # The generated files for protocol buffers +PROTO_GEN_HEADER_SRCS := $(addprefix $(PROTO_BUILD_DIR)/, \ + $(notdir ${PROTO_SRCS:.proto=.pb.h})) PROTO_GEN_HEADER := $(addprefix $(PROTO_BUILD_INCLUDE_DIR)/, \ $(notdir ${PROTO_SRCS:.proto=.pb.h})) HXX_SRCS += $(PROTO_GEN_HEADER) PROTO_GEN_CC := $(addprefix $(BUILD_DIR)/, ${PROTO_SRCS:.proto=.pb.cc}) -PROTO_GEN_PY := ${PROTO_SRCS:.proto=_pb2.py} +PROTO_GEN_PY := $(foreach file,${PROTO_SRCS:.proto=_pb2.py},python/$(PROJECT)/proto/$(notdir $(file))) # The objects corresponding to the source files # These objects will be linked into the final shared library, so we # exclude the tool, example, and test objects. CXX_OBJS := $(addprefix $(BUILD_DIR)/, ${CXX_SRCS:.cpp=.o}) CU_OBJS := $(addprefix $(BUILD_DIR)/, ${CU_SRCS:.cu=.cuo}) PROTO_OBJS := ${PROTO_GEN_CC:.cc=.o} +OBJ_BUILD_DIR := $(BUILD_DIR)/src/$(PROJECT) +LAYER_BUILD_DIR := $(OBJ_BUILD_DIR)/layers +UTIL_BUILD_DIR := $(OBJ_BUILD_DIR)/util OBJS := $(PROTO_OBJS) $(CXX_OBJS) $(CU_OBJS) # tool, example, and test objects TOOL_OBJS := $(addprefix $(BUILD_DIR)/, ${TOOL_SRCS:.cpp=.o}) -EXAMPLE_OBJS := $(addprefix $(BUILD_DIR)/, ${EXAMPLE_SRCS:.cpp=.o}) +TOOL_BUILD_DIR := $(BUILD_DIR)/tools +TOOL_BUILD_DIRS := $(sort $(foreach obj,$(TOOL_OBJS),$(dir $(obj)))) +TEST_BUILD_DIR := $(BUILD_DIR)/src/$(PROJECT)/test TEST_OBJS := $(addprefix $(BUILD_DIR)/, ${TEST_SRCS:.cpp=.o}) GTEST_OBJ := $(addprefix $(BUILD_DIR)/, ${GTEST_SRC:.cpp=.o}) +GTEST_BUILD_DIR := $(dir $(GTEST_OBJ)) +EXAMPLE_OBJS := $(addprefix $(BUILD_DIR)/, ${EXAMPLE_SRCS:.cpp=.o}) +EXAMPLE_BUILD_DIR := $(BUILD_DIR)/examples +EXAMPLE_BUILD_DIRS := $(EXAMPLE_BUILD_DIR) +EXAMPLE_BUILD_DIRS += $(foreach obj,$(EXAMPLE_OBJS),$(dir $(obj))) # tool, example, and test bins TOOL_BINS := ${TOOL_OBJS:.o=.bin} EXAMPLE_BINS := ${EXAMPLE_OBJS:.o=.bin} TEST_BINS := ${TEST_OBJS:.o=.testbin} -TEST_BUILD_SUB_DIR := src/$(PROJECT)/test -TEST_DIR = $(BUILD_DIR)/$(TEST_BUILD_SUB_DIR) -TEST_ALL_BIN := $(TEST_DIR)/test_all.testbin +TEST_ALL_BIN := $(TEST_BUILD_DIR)/test_all.testbin +TEST_ALL_BINS := $(TEST_ALL_BIN) $(TEST_BINS) # A shortcut to the directory of test binaries for convenience. -TEST_DIR_LINK := $(BUILD_DIR)/test +TEST_LINK_DIR := $(BUILD_DIR)/test +TEST_ALL_BIN_LINKS := $(foreach \ + bin,$(TEST_ALL_BINS),$(TEST_LINK_DIR)/$(notdir $(bin))) ############################## # Derive include and lib directories @@ -110,7 +123,27 @@ LIBRARIES := cudart cublas curand \ PYTHON_LIBRARIES := boost_python python2.7 WARNINGS := -Wall -ifdef DEBUG +############################## +# Set build directories +############################## + +DISTRIBUTE_SUBDIRS := $(DISTRIBUTE_DIR)/bin $(DISTRIBUTE_DIR)/lib +DIST_ALIASES := dist +ifneq ($(strip $(DISTRIBUTE_DIR)),distribute) + DIST_ALIASES += distribute +endif + +ALL_BUILD_DIRS := $(BUILD_DIR) $(OBJ_BUILD_DIR) \ + $(LAYER_BUILD_DIR) $(UTIL_BUILD_DIR) $(TOOL_BUILD_DIRS) \ + $(TEST_BUILD_DIR) $(TEST_LINK_DIR) $(GTEST_BUILD_DIR) \ + $(EXAMPLE_BUILD_DIRS) \ + $(PROTO_BUILD_DIR) $(PROTO_BUILD_INCLUDE_DIR) \ + $(DISTRIBUTE_SUBDIRS) + +ALL_BUILD_DIRS := $(sort $(ALL_BUILD_DIRS)) + +DEBUG ?= 0 +ifeq ($(DEBUG), 1) COMMON_FLAGS := -DDEBUG -g -O0 else COMMON_FLAGS := -DNDEBUG -O2 @@ -134,31 +167,34 @@ LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) \ $(foreach library,$(LIBRARIES),-l$(library)) PYTHON_LDFLAGS := $(LDFLAGS) $(foreach library,$(PYTHON_LIBRARIES),-l$(library)) +# 'superclean' target recursively* deletes all files ending with an extension +# suggesting that Caffe built them. This may be useful if you've built older +# versions of Caffe that do not place all generated files in a location known +# to make clean. +# +# 'supercleanlist' will list the files to be deleted by make superclean. +# +# * Recursive with the exception that symbolic links are never followed, per the +# default behavior of 'find'. +SUPERCLEAN_EXTS := .so .a .o .bin .testbin .pb.cc .pb.h _pb2.py .cuo + ############################## # Define build targets ############################## -.PHONY: all init test clean linecount lint tools examples distribute \ +.PHONY: all test clean linecount lint tools examples dist \ py mat py$(PROJECT) mat$(PROJECT) proto runtest \ - superclean supercleanlist supercleanfiles \ - testshortcut + superclean supercleanlist supercleanfiles -all: init $(NAME) $(STATIC_NAME) tools examples - @echo $(CXX_OBJS) +.SECONDARY: $(PROTO_GEN_HEADER_SRCS) $(TEST_BINS) -init: - @ mkdir -p $(foreach obj,$(OBJS),$(dir $(obj))) - @ mkdir -p $(foreach obj,$(TOOL_OBJS),$(dir $(obj))) - @ mkdir -p $(foreach obj,$(EXAMPLE_OBJS),$(dir $(obj))) - @ mkdir -p $(foreach obj,$(TEST_OBJS),$(dir $(obj))) - @ mkdir -p $(foreach obj,$(GTEST_OBJ),$(dir $(obj))) +all: $(NAME) $(STATIC_NAME) tools examples linecount: clean cloc --read-lang-def=$(PROJECT).cloc src/$(PROJECT)/ lint: $(LINT_REPORT) -$(LINT_REPORT): $(NONGEN_CXX_SRCS) - @ mkdir -p $(BUILD_DIR) +$(LINT_REPORT): $(NONGEN_CXX_SRCS) | $(BUILD_DIR) @ (python ./scripts/cpp_lint.py $(NONGEN_CXX_SRCS) > $(LINT_REPORT) 2>&1 \ && (rm -f $(FAILED_LINT_REPORT); echo "No lint errors!")) || ( \ mv $(LINT_REPORT) $(FAILED_LINT_REPORT); \ @@ -166,133 +202,119 @@ $(LINT_REPORT): $(NONGEN_CXX_SRCS) echo "Found 1 or more lint errors; see log at $(FAILED_LINT_REPORT)"; \ exit 1) -test: init $(TEST_BINS) $(TEST_ALL_BIN) +test: $(TEST_ALL_BIN_LINKS) -tools: init proto $(TOOL_BINS) +tools: $(TOOL_BINS) -examples: init $(EXAMPLE_BINS) +examples: $(EXAMPLE_BINS) py$(PROJECT): py -py: init $(STATIC_NAME) $(PY$(PROJECT)_SRC) $(PROTO_GEN_PY) - $(CXX) -shared -o $(PY$(PROJECT)_SO) $(PY$(PROJECT)_SRC) \ +py: $(PY$(PROJECT)_SO) $(PROTO_GEN_PY) + +$(PY$(PROJECT)_SO): $(STATIC_NAME) $(PY$(PROJECT)_SRC) + $(CXX) -shared -o $@ $(PY$(PROJECT)_SRC) \ $(STATIC_NAME) $(CXXFLAGS) $(PYTHON_LDFLAGS) - @echo mat$(PROJECT): mat -mat: init $(STATIC_NAME) $(MAT$(PROJECT)_SRC) +mat: $(STATIC_NAME) $(MAT$(PROJECT)_SRC) $(MATLAB_DIR)/bin/mex $(MAT$(PROJECT)_SRC) $(STATIC_NAME) \ CXXFLAGS="\$$CXXFLAGS $(CXXFLAGS) $(WARNINGS)" \ CXXLIBS="\$$CXXLIBS $(LDFLAGS)" \ -o $(MAT$(PROJECT)_SO) - @echo + @ echo + +runtest: $(TEST_ALL_BIN) + $(TEST_ALL_BIN) $(TEST_GPUID) + +$(ALL_BUILD_DIRS): + @ mkdir -p $@ -$(NAME): init $(PROTO_OBJS) $(OBJS) +$(NAME): $(PROTO_OBJS) $(OBJS) $(CXX) -shared -o $(NAME) $(OBJS) $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) - @echo -$(STATIC_NAME): init $(PROTO_OBJS) $(OBJS) +$(STATIC_NAME): $(PROTO_OBJS) $(OBJS) ar rcs $(STATIC_NAME) $(PROTO_OBJS) $(OBJS) - @echo -runtest: $(TEST_ALL_BIN) - $(TEST_ALL_BIN) $(TEST_GPUID) - -$(BUILD_DIR)/src/$(PROJECT)/test/%.testbin: \ - $(BUILD_DIR)/src/$(PROJECT)/test/%.o \ - $(GTEST_OBJ) $(STATIC_NAME) testshortcut +$(TEST_BUILD_DIR)/%.testbin: $(TEST_BUILD_DIR)/%.o $(GTEST_OBJ) $(STATIC_NAME) \ + | $(TEST_BUILD_DIR) $(CXX) $(TEST_MAIN_SRC) $< $(GTEST_OBJ) $(STATIC_NAME) \ -o $@ $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) -$(TEST_ALL_BIN): $(GTEST_OBJ) $(STATIC_NAME) $(TEST_OBJS) testshortcut +$(TEST_ALL_BIN): $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) $(STATIC_NAME) $(CXX) $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) $(STATIC_NAME) \ -o $(TEST_ALL_BIN) $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) -testshortcut: | $(TEST_DIR_LINK) - -$(TEST_DIR_LINK): | $(TEST_DIR) - ln -s $(TEST_BUILD_SUB_DIR) $(TEST_DIR_LINK) - -$(TEST_DIR): - mkdir -p $(TEST_DIR) +$(TEST_LINK_DIR)/%.testbin: $(TEST_BUILD_DIR)/%.testbin | $(TEST_LINK_DIR) + @ $(RM) $@ + @ ln -s ../../$(TEST_BUILD_DIR)/$(@F) $@ $(TOOL_BINS): %.bin : %.o $(STATIC_NAME) $(CXX) $< $(STATIC_NAME) -o $@ $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) - @echo + @ echo $(EXAMPLE_BINS): %.bin : %.o $(STATIC_NAME) $(CXX) $< $(STATIC_NAME) -o $@ $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) - @echo - -$(BUILD_DIR)/src/$(PROJECT)/%.o: src/$(PROJECT)/%.cpp - $(CXX) $< $(CXXFLAGS) -c -o $@ - @echo - -$(OBJS): $(PROTO_GEN_HEADER) $(HXX_SRCS) - @echo matched the first objs!! - + @ echo -LAYERS_DIR := $(BUILD_DIR)/src/$(PROJECT)/layers -$(LAYERS_DIR): - @ mkdir -p $(LAYERS_DIR) - -$(BUILD_DIR)/src/$(PROJECT)/layers/%.o: \ - src/$(PROJECT)/layers/%.cpp $(HXX_SRCS) | $(LAYERS_DIR) +$(LAYER_BUILD_DIR)/%.o: \ + src/$(PROJECT)/layers/%.cpp $(HXX_SRCS) | $(LAYER_BUILD_DIR) $(CXX) $< $(CXXFLAGS) -c -o $@ - @echo -$(BUILD_DIR)/src/$(PROJECT)/proto/%.o: src/$(PROJECT)/proto/%.cc src/$(PROJECT)/proto/%.h +$(PROTO_BUILD_DIR)/%.pb.o: $(PROTO_BUILD_DIR)/%.pb.cc \ + $(PROTO_GEN_HEADER) | $(PROTO_BUILD_DIR) $(CXX) $< $(CXXFLAGS) -c -o $@ - @echo + @ echo -$(BUILD_DIR)/src/$(PROJECT)/test/%.o: $(PROTO_GEN_HEADER) src/$(PROJECT)/test/%.cpp +$(TEST_BUILD_DIR)/%.o: src/$(PROJECT)/test/%.cpp $(HXX_SRCS) | $(TEST_BUILD_DIR) $(CXX) $< $(CXXFLAGS) -c -o $@ -$(BUILD_DIR)/src/$(PROJECT)/util/%.o: src/$(PROJECT)/util/%.cpp +$(UTIL_BUILD_DIR)/%.o: src/$(PROJECT)/util/%.cpp $(HXX_SRCS) | $(UTIL_BUILD_DIR) $(CXX) $< $(CXXFLAGS) -c -o $@ - @echo + @ echo -$(BUILD_DIR)/src/gtest/%.o: src/gtest/%.cpp +$(GTEST_OBJ): $(GTEST_SRC) | $(GTEST_BUILD_DIR) $(CXX) $< $(CXXFLAGS) -c -o $@ - @echo + @ echo -$(BUILD_DIR)/src/$(PROJECT)/layers/%.cuo: src/$(PROJECT)/layers/%.cu +$(LAYER_BUILD_DIR)/%.cuo: \ + src/$(PROJECT)/layers/%.cu $(HXX_SRCS) | $(LAYER_BUILD_DIR) $(CUDA_DIR)/bin/nvcc $(NVCCFLAGS) $(CUDA_ARCH) -c $< -o $@ - @echo + @ echo -$(BUILD_DIR)/src/$(PROJECT)/util/%.cuo: src/$(PROJECT)/util/%.cu +$(UTIL_BUILD_DIR)/%.cuo: src/$(PROJECT)/util/%.cu | $(UTIL_BUILD_DIR) $(CUDA_DIR)/bin/nvcc $(NVCCFLAGS) $(CUDA_ARCH) -c $< -o $@ - @echo + @ echo -$(BUILD_DIR)/tools/%.o: tools/%.cpp $(PROTO_GEN_HEADER) +$(TOOL_BUILD_DIR)/%.o: tools/%.cpp $(PROTO_GEN_HEADER) | $(TOOL_BUILD_DIR) $(CXX) $< $(CXXFLAGS) -c -o $@ $(LDFLAGS) - @echo + @ echo -$(BUILD_DIR)/examples/%.o: examples/%.cpp $(PROTO_GEN_HEADER) +$(EXAMPLE_BUILD_DIR)/%.o: examples/%.cpp $(PROTO_GEN_HEADER) \ + | $(EXAMPLE_BUILD_DIRS) $(CXX) $< $(CXXFLAGS) -c -o $@ $(LDFLAGS) - @echo + @ echo + +$(BUILD_DIR)/src/$(PROJECT)/%.o: src/$(PROJECT)/%.cpp $(HXX_SRCS) + $(CXX) $< $(CXXFLAGS) -c -o $@ + @ echo $(PROTO_GEN_PY): $(PROTO_SRCS) protoc --proto_path=src --python_out=python $(PROTO_SRCS) - @echo + @ echo -proto: init $(PROTO_GEN_CC) $(PROTO_GEN_HEADER) - @echo PROTO_GEN_CC: $(PROTO_GEN_CC) - @echo PROTO_GEN_HEADER: $(PROTO_GEN_HEADER) - @echo PROTO_OBJS: $(PROTO_OBJS) +proto: $(PROTO_GEN_CC) $(PROTO_GEN_HEADER) -$(PROTO_BUILD_DIR)/%.pb.cc $(PROTO_BUILD_DIR)/%.pb.h \ - $(PROTO_BUILD_INCLUDE_DIR)/%.pb.h: \ - $(PROTO_SRC_DIR)/%.proto | $(PROTO_BUILD_DIR) $(PROTO_BUILD_INCLUDE_DIR) +$(PROTO_BUILD_DIR)/%.pb.cc $(PROTO_BUILD_DIR)/%.pb.h : \ + $(PROTO_SRC_DIR)/%.proto | $(PROTO_BUILD_DIR) protoc --proto_path=src --cpp_out=build/src $< - cp $(PROTO_BUILD_DIR)/$(*F).pb.h $(PROTO_BUILD_INCLUDE_DIR)/$(*F).pb.h -$(PROTO_BUILD_DIR): - mkdir -p $(PROTO_BUILD_DIR) - -$(PROTO_BUILD_INCLUDE_DIR): - mkdir -p $(PROTO_BUILD_INCLUDE_DIR) +$(PROTO_BUILD_INCLUDE_DIR)/%.pb.h: $(PROTO_BUILD_DIR)/%.pb.h \ + | $(PROTO_BUILD_INCLUDE_DIR) + @ $(RM) $(PROTO_BUILD_INCLUDE_DIR)/$(*F).pb.h + @ ln -s ../../../../$(PROTO_BUILD_DIR)/$(*F).pb.h \ + $(PROTO_BUILD_INCLUDE_DIR)/$(*F).pb.h clean: @- $(RM) $(NAME) $(STATIC_NAME) @@ -303,20 +325,9 @@ clean: @- $(RM) -rf $(BUILD_DIR) @- $(RM) -rf $(DISTRIBUTE_DIR) -# make superclean recursively* deletes all files ending with an extension -# suggesting that Caffe built them. This may be useful if you've built older -# versions of Caffe that do not place all generated files in a location known -# to make clean. -# -# make supercleanlist will list the files to be deleted by make superclean. -# -# * Recursive with the exception that symbolic links are never followed, per the -# default behavior of 'find'. -SUPERCLEAN_EXTS := .so .a .o .bin .testbin .pb.cc .pb.h _pb2.py .cuo - supercleanfiles: $(eval SUPERCLEAN_FILES := $(strip \ - $(foreach ext,$(SUPERCLEAN_EXTS), $(shell find . -name '*$(ext)')))) + $(foreach ext,$(SUPERCLEAN_EXTS), $(shell find . -name '*$(ext)')))) supercleanlist: supercleanfiles @ \ @@ -336,16 +347,15 @@ superclean: clean supercleanfiles $(RM) $(SUPERCLEAN_FILES); \ fi -distribute: all - mkdir $(DISTRIBUTE_DIR) +$(DIST_ALIASES): $(DISTRIBUTE_DIR) + +$(DISTRIBUTE_DIR): all py $(HXX_SRCS) | $(DISTRIBUTE_SUBDIRS) # add include cp -r include $(DISTRIBUTE_DIR)/ # add tool and example binaries - mkdir $(DISTRIBUTE_DIR)/bin cp $(TOOL_BINS) $(DISTRIBUTE_DIR)/bin cp $(EXAMPLE_BINS) $(DISTRIBUTE_DIR)/bin # add libraries - mkdir $(DISTRIBUTE_DIR)/lib cp $(NAME) $(DISTRIBUTE_DIR)/lib cp $(STATIC_NAME) $(DISTRIBUTE_DIR)/lib # add python - it's not the standard way, indeed... From 195ba81b8836846da69b9ec192dec457ba82f959 Mon Sep 17 00:00:00 2001 From: Jeff Donahue Date: Sun, 30 Mar 2014 04:36:22 -0700 Subject: [PATCH 08/18] everything prints a blank line after compiling --- Makefile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Makefile b/Makefile index 26c9517e821..9ba87f31d76 100644 --- a/Makefile +++ b/Makefile @@ -215,6 +215,7 @@ py: $(PY$(PROJECT)_SO) $(PROTO_GEN_PY) $(PY$(PROJECT)_SO): $(STATIC_NAME) $(PY$(PROJECT)_SRC) $(CXX) -shared -o $@ $(PY$(PROJECT)_SRC) \ $(STATIC_NAME) $(CXXFLAGS) $(PYTHON_LDFLAGS) + @ echo mat$(PROJECT): mat @@ -233,18 +234,22 @@ $(ALL_BUILD_DIRS): $(NAME): $(PROTO_OBJS) $(OBJS) $(CXX) -shared -o $(NAME) $(OBJS) $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) + @ echo $(STATIC_NAME): $(PROTO_OBJS) $(OBJS) ar rcs $(STATIC_NAME) $(PROTO_OBJS) $(OBJS) + @ echo $(TEST_BUILD_DIR)/%.testbin: $(TEST_BUILD_DIR)/%.o $(GTEST_OBJ) $(STATIC_NAME) \ | $(TEST_BUILD_DIR) $(CXX) $(TEST_MAIN_SRC) $< $(GTEST_OBJ) $(STATIC_NAME) \ -o $@ $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) + @ echo $(TEST_ALL_BIN): $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) $(STATIC_NAME) $(CXX) $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) $(STATIC_NAME) \ -o $(TEST_ALL_BIN) $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) + @ echo $(TEST_LINK_DIR)/%.testbin: $(TEST_BUILD_DIR)/%.testbin | $(TEST_LINK_DIR) @ $(RM) $@ @@ -261,6 +266,7 @@ $(EXAMPLE_BINS): %.bin : %.o $(STATIC_NAME) $(LAYER_BUILD_DIR)/%.o: \ src/$(PROJECT)/layers/%.cpp $(HXX_SRCS) | $(LAYER_BUILD_DIR) $(CXX) $< $(CXXFLAGS) -c -o $@ + @ echo $(PROTO_BUILD_DIR)/%.pb.o: $(PROTO_BUILD_DIR)/%.pb.cc \ $(PROTO_GEN_HEADER) | $(PROTO_BUILD_DIR) @@ -269,6 +275,7 @@ $(PROTO_BUILD_DIR)/%.pb.o: $(PROTO_BUILD_DIR)/%.pb.cc \ $(TEST_BUILD_DIR)/%.o: src/$(PROJECT)/test/%.cpp $(HXX_SRCS) | $(TEST_BUILD_DIR) $(CXX) $< $(CXXFLAGS) -c -o $@ + @ echo $(UTIL_BUILD_DIR)/%.o: src/$(PROJECT)/util/%.cpp $(HXX_SRCS) | $(UTIL_BUILD_DIR) $(CXX) $< $(CXXFLAGS) -c -o $@ @@ -309,6 +316,7 @@ proto: $(PROTO_GEN_CC) $(PROTO_GEN_HEADER) $(PROTO_BUILD_DIR)/%.pb.cc $(PROTO_BUILD_DIR)/%.pb.h : \ $(PROTO_SRC_DIR)/%.proto | $(PROTO_BUILD_DIR) protoc --proto_path=src --cpp_out=build/src $< + @ echo $(PROTO_BUILD_INCLUDE_DIR)/%.pb.h: $(PROTO_BUILD_DIR)/%.pb.h \ | $(PROTO_BUILD_INCLUDE_DIR) From 9f14265cfd05762a404bd033a73df4f125bd0194 Mon Sep 17 00:00:00 2001 From: Jeff Donahue Date: Sun, 30 Mar 2014 04:42:43 -0700 Subject: [PATCH 09/18] libcaffe.* in build/lib/ --- Makefile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 9ba87f31d76..6e3610a0a48 100644 --- a/Makefile +++ b/Makefile @@ -8,8 +8,9 @@ include Makefile.config ############################################################################## # The target static library and shared library name -NAME := lib$(PROJECT).so -STATIC_NAME := lib$(PROJECT).a +LIB_BUILD_DIR := $(BUILD_DIR)/lib +NAME := $(LIB_BUILD_DIR)/lib$(PROJECT).so +STATIC_NAME := $(LIB_BUILD_DIR)/lib$(PROJECT).a ############################## # Get all source files @@ -133,7 +134,7 @@ ifneq ($(strip $(DISTRIBUTE_DIR)),distribute) DIST_ALIASES += distribute endif -ALL_BUILD_DIRS := $(BUILD_DIR) $(OBJ_BUILD_DIR) \ +ALL_BUILD_DIRS := $(BUILD_DIR) $(LIB_BUILD_DIR) $(OBJ_BUILD_DIR) \ $(LAYER_BUILD_DIR) $(UTIL_BUILD_DIR) $(TOOL_BUILD_DIRS) \ $(TEST_BUILD_DIR) $(TEST_LINK_DIR) $(GTEST_BUILD_DIR) \ $(EXAMPLE_BUILD_DIRS) \ @@ -232,11 +233,11 @@ runtest: $(TEST_ALL_BIN) $(ALL_BUILD_DIRS): @ mkdir -p $@ -$(NAME): $(PROTO_OBJS) $(OBJS) +$(NAME): $(PROTO_OBJS) $(OBJS) | $(LIB_BUILD_DIR) $(CXX) -shared -o $(NAME) $(OBJS) $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) @ echo -$(STATIC_NAME): $(PROTO_OBJS) $(OBJS) +$(STATIC_NAME): $(PROTO_OBJS) $(OBJS) | $(LIB_BUILD_DIR) ar rcs $(STATIC_NAME) $(PROTO_OBJS) $(OBJS) @ echo From a034d629588f4717476f3427c793dc7f32200669 Mon Sep 17 00:00:00 2001 From: Jeff Donahue Date: Sun, 30 Mar 2014 04:44:17 -0700 Subject: [PATCH 10/18] minor cleanup --- Makefile | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 6e3610a0a48..783cc6042b2 100644 --- a/Makefile +++ b/Makefile @@ -84,7 +84,6 @@ OBJS := $(PROTO_OBJS) $(CXX_OBJS) $(CU_OBJS) # tool, example, and test objects TOOL_OBJS := $(addprefix $(BUILD_DIR)/, ${TOOL_SRCS:.cpp=.o}) TOOL_BUILD_DIR := $(BUILD_DIR)/tools -TOOL_BUILD_DIRS := $(sort $(foreach obj,$(TOOL_OBJS),$(dir $(obj)))) TEST_BUILD_DIR := $(BUILD_DIR)/src/$(PROJECT)/test TEST_OBJS := $(addprefix $(BUILD_DIR)/, ${TEST_SRCS:.cpp=.o}) GTEST_OBJ := $(addprefix $(BUILD_DIR)/, ${GTEST_SRC:.cpp=.o}) @@ -134,14 +133,13 @@ ifneq ($(strip $(DISTRIBUTE_DIR)),distribute) DIST_ALIASES += distribute endif -ALL_BUILD_DIRS := $(BUILD_DIR) $(LIB_BUILD_DIR) $(OBJ_BUILD_DIR) \ - $(LAYER_BUILD_DIR) $(UTIL_BUILD_DIR) $(TOOL_BUILD_DIRS) \ +ALL_BUILD_DIRS := $(sort \ + $(BUILD_DIR) $(LIB_BUILD_DIR) $(OBJ_BUILD_DIR) \ + $(LAYER_BUILD_DIR) $(UTIL_BUILD_DIR) $(TOOL_BUILD_DIR) \ $(TEST_BUILD_DIR) $(TEST_LINK_DIR) $(GTEST_BUILD_DIR) \ $(EXAMPLE_BUILD_DIRS) \ $(PROTO_BUILD_DIR) $(PROTO_BUILD_INCLUDE_DIR) \ - $(DISTRIBUTE_SUBDIRS) - -ALL_BUILD_DIRS := $(sort $(ALL_BUILD_DIRS)) + $(DISTRIBUTE_SUBDIRS)) DEBUG ?= 0 ifeq ($(DEBUG), 1) @@ -197,7 +195,7 @@ lint: $(LINT_REPORT) $(LINT_REPORT): $(NONGEN_CXX_SRCS) | $(BUILD_DIR) @ (python ./scripts/cpp_lint.py $(NONGEN_CXX_SRCS) > $(LINT_REPORT) 2>&1 \ - && (rm -f $(FAILED_LINT_REPORT); echo "No lint errors!")) || ( \ + && ($(RM) $(FAILED_LINT_REPORT); echo "No lint errors!")) || ( \ mv $(LINT_REPORT) $(FAILED_LINT_REPORT); \ grep -v "^Done processing " $(FAILED_LINT_REPORT); \ echo "Found 1 or more lint errors; see log at $(FAILED_LINT_REPORT)"; \ @@ -264,13 +262,13 @@ $(EXAMPLE_BINS): %.bin : %.o $(STATIC_NAME) $(CXX) $< $(STATIC_NAME) -o $@ $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) @ echo -$(LAYER_BUILD_DIR)/%.o: \ - src/$(PROJECT)/layers/%.cpp $(HXX_SRCS) | $(LAYER_BUILD_DIR) +$(LAYER_BUILD_DIR)/%.o: src/$(PROJECT)/layers/%.cpp $(HXX_SRCS) \ + | $(LAYER_BUILD_DIR) $(CXX) $< $(CXXFLAGS) -c -o $@ @ echo -$(PROTO_BUILD_DIR)/%.pb.o: $(PROTO_BUILD_DIR)/%.pb.cc \ - $(PROTO_GEN_HEADER) | $(PROTO_BUILD_DIR) +$(PROTO_BUILD_DIR)/%.pb.o: $(PROTO_BUILD_DIR)/%.pb.cc $(PROTO_GEN_HEADER) \ + | $(PROTO_BUILD_DIR) $(CXX) $< $(CXXFLAGS) -c -o $@ @ echo From 209b4c82eeb6f936936e0843184d2b39ec0623d0 Mon Sep 17 00:00:00 2001 From: Jeff Donahue Date: Sun, 30 Mar 2014 05:22:52 -0700 Subject: [PATCH 11/18] add test header dependency and fix mat targets --- Makefile | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 783cc6042b2..040a34ff1da 100644 --- a/Makefile +++ b/Makefile @@ -218,11 +218,12 @@ $(PY$(PROJECT)_SO): $(STATIC_NAME) $(PY$(PROJECT)_SRC) mat$(PROJECT): mat -mat: $(STATIC_NAME) $(MAT$(PROJECT)_SRC) +mat: $(MAT$(PROJECT)_SO) + +$(MAT$(PROJECT)_SO): $(MAT$(PROJECT)_SRC) $(STATIC_NAME) $(MATLAB_DIR)/bin/mex $(MAT$(PROJECT)_SRC) $(STATIC_NAME) \ - CXXFLAGS="\$$CXXFLAGS $(CXXFLAGS) $(WARNINGS)" \ - CXXLIBS="\$$CXXLIBS $(LDFLAGS)" \ - -o $(MAT$(PROJECT)_SO) + CXXFLAGS="\$$CXXFLAGS $(CXXFLAGS) $(WARNINGS)" \ + CXXLIBS="\$$CXXLIBS $(LDFLAGS)" -o $@ @ echo runtest: $(TEST_ALL_BIN) @@ -232,7 +233,7 @@ $(ALL_BUILD_DIRS): @ mkdir -p $@ $(NAME): $(PROTO_OBJS) $(OBJS) | $(LIB_BUILD_DIR) - $(CXX) -shared -o $(NAME) $(OBJS) $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) + $(CXX) -shared -o $@ $(OBJS) $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) @ echo $(STATIC_NAME): $(PROTO_OBJS) $(OBJS) | $(LIB_BUILD_DIR) @@ -247,7 +248,7 @@ $(TEST_BUILD_DIR)/%.testbin: $(TEST_BUILD_DIR)/%.o $(GTEST_OBJ) $(STATIC_NAME) \ $(TEST_ALL_BIN): $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) $(STATIC_NAME) $(CXX) $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) $(STATIC_NAME) \ - -o $(TEST_ALL_BIN) $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) + -o $@ $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) @ echo $(TEST_LINK_DIR)/%.testbin: $(TEST_BUILD_DIR)/%.testbin | $(TEST_LINK_DIR) @@ -272,7 +273,8 @@ $(PROTO_BUILD_DIR)/%.pb.o: $(PROTO_BUILD_DIR)/%.pb.cc $(PROTO_GEN_HEADER) \ $(CXX) $< $(CXXFLAGS) -c -o $@ @ echo -$(TEST_BUILD_DIR)/%.o: src/$(PROJECT)/test/%.cpp $(HXX_SRCS) | $(TEST_BUILD_DIR) +$(TEST_BUILD_DIR)/%.o: src/$(PROJECT)/test/%.cpp $(HXX_SRCS) $(TEST_HDRS) \ + | $(TEST_BUILD_DIR) $(CXX) $< $(CXXFLAGS) -c -o $@ @ echo @@ -306,10 +308,6 @@ $(BUILD_DIR)/src/$(PROJECT)/%.o: src/$(PROJECT)/%.cpp $(HXX_SRCS) $(CXX) $< $(CXXFLAGS) -c -o $@ @ echo -$(PROTO_GEN_PY): $(PROTO_SRCS) - protoc --proto_path=src --python_out=python $(PROTO_SRCS) - @ echo - proto: $(PROTO_GEN_CC) $(PROTO_GEN_HEADER) $(PROTO_BUILD_DIR)/%.pb.cc $(PROTO_BUILD_DIR)/%.pb.h : \ @@ -323,6 +321,10 @@ $(PROTO_BUILD_INCLUDE_DIR)/%.pb.h: $(PROTO_BUILD_DIR)/%.pb.h \ @ ln -s ../../../../$(PROTO_BUILD_DIR)/$(*F).pb.h \ $(PROTO_BUILD_INCLUDE_DIR)/$(*F).pb.h +$(PROTO_GEN_PY): $(PROTO_SRCS) + protoc --proto_path=src --python_out=python $(PROTO_SRCS) + @ echo + clean: @- $(RM) $(NAME) $(STATIC_NAME) @- $(RM) $(PROTO_GEN_HEADER) $(PROTO_GEN_CC) $(PROTO_GEN_PY) From db26e5a8f3f294782d5b5adefc441452f57b8cdd Mon Sep 17 00:00:00 2001 From: Jeff Donahue Date: Sun, 30 Mar 2014 06:21:38 -0700 Subject: [PATCH 12/18] compile test bins directly into build/test --- Makefile | 47 +++++++++++++++++++---------------------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index 040a34ff1da..7c35c60199e 100644 --- a/Makefile +++ b/Makefile @@ -65,12 +65,13 @@ MAT$(PROJECT)_SO := matlab/$(PROJECT)/$(PROJECT) ############################## # The generated files for protocol buffers PROTO_GEN_HEADER_SRCS := $(addprefix $(PROTO_BUILD_DIR)/, \ - $(notdir ${PROTO_SRCS:.proto=.pb.h})) + $(notdir ${PROTO_SRCS:.proto=.pb.h})) PROTO_GEN_HEADER := $(addprefix $(PROTO_BUILD_INCLUDE_DIR)/, \ - $(notdir ${PROTO_SRCS:.proto=.pb.h})) + $(notdir ${PROTO_SRCS:.proto=.pb.h})) HXX_SRCS += $(PROTO_GEN_HEADER) PROTO_GEN_CC := $(addprefix $(BUILD_DIR)/, ${PROTO_SRCS:.proto=.pb.cc}) -PROTO_GEN_PY := $(foreach file,${PROTO_SRCS:.proto=_pb2.py},python/$(PROJECT)/proto/$(notdir $(file))) +PROTO_GEN_PY := $(foreach file,${PROTO_SRCS:.proto=_pb2.py}, \ + python/$(PROJECT)/proto/$(notdir $(file))) # The objects corresponding to the source files # These objects will be linked into the final shared library, so we # exclude the tool, example, and test objects. @@ -95,13 +96,11 @@ EXAMPLE_BUILD_DIRS += $(foreach obj,$(EXAMPLE_OBJS),$(dir $(obj))) # tool, example, and test bins TOOL_BINS := ${TOOL_OBJS:.o=.bin} EXAMPLE_BINS := ${EXAMPLE_OBJS:.o=.bin} -TEST_BINS := ${TEST_OBJS:.o=.testbin} -TEST_ALL_BIN := $(TEST_BUILD_DIR)/test_all.testbin -TEST_ALL_BINS := $(TEST_ALL_BIN) $(TEST_BINS) # A shortcut to the directory of test binaries for convenience. -TEST_LINK_DIR := $(BUILD_DIR)/test -TEST_ALL_BIN_LINKS := $(foreach \ - bin,$(TEST_ALL_BINS),$(TEST_LINK_DIR)/$(notdir $(bin))) +TEST_BIN_DIR := $(BUILD_DIR)/test +TEST_BINS := $(addprefix $(TEST_BIN_DIR)/, \ + $(foreach obj,$(TEST_OBJS),$(notdir $(obj)))) +TEST_ALL_BIN := $(TEST_BIN_DIR)/test_all.testbin ############################## # Derive include and lib directories @@ -136,7 +135,7 @@ endif ALL_BUILD_DIRS := $(sort \ $(BUILD_DIR) $(LIB_BUILD_DIR) $(OBJ_BUILD_DIR) \ $(LAYER_BUILD_DIR) $(UTIL_BUILD_DIR) $(TOOL_BUILD_DIR) \ - $(TEST_BUILD_DIR) $(TEST_LINK_DIR) $(GTEST_BUILD_DIR) \ + $(TEST_BUILD_DIR) $(TEST_BIN_DIR) $(GTEST_BUILD_DIR) \ $(EXAMPLE_BUILD_DIRS) \ $(PROTO_BUILD_DIR) $(PROTO_BUILD_INCLUDE_DIR) \ $(DISTRIBUTE_SUBDIRS)) @@ -184,8 +183,6 @@ SUPERCLEAN_EXTS := .so .a .o .bin .testbin .pb.cc .pb.h _pb2.py .cuo py mat py$(PROJECT) mat$(PROJECT) proto runtest \ superclean supercleanlist supercleanfiles -.SECONDARY: $(PROTO_GEN_HEADER_SRCS) $(TEST_BINS) - all: $(NAME) $(STATIC_NAME) tools examples linecount: clean @@ -201,7 +198,7 @@ $(LINT_REPORT): $(NONGEN_CXX_SRCS) | $(BUILD_DIR) echo "Found 1 or more lint errors; see log at $(FAILED_LINT_REPORT)"; \ exit 1) -test: $(TEST_ALL_BIN_LINKS) +test: $(TEST_ALL_BIN) $(TEST_BINS) tools: $(TOOL_BINS) @@ -237,13 +234,12 @@ $(NAME): $(PROTO_OBJS) $(OBJS) | $(LIB_BUILD_DIR) @ echo $(STATIC_NAME): $(PROTO_OBJS) $(OBJS) | $(LIB_BUILD_DIR) - ar rcs $(STATIC_NAME) $(PROTO_OBJS) $(OBJS) + ar rcs $@ $(PROTO_OBJS) $(OBJS) @ echo -$(TEST_BUILD_DIR)/%.testbin: $(TEST_BUILD_DIR)/%.o $(GTEST_OBJ) $(STATIC_NAME) \ +$(TEST_BUILD_DIR)/%.o: src/$(PROJECT)/test/%.cpp $(HXX_SRCS) $(TEST_HDRS) \ | $(TEST_BUILD_DIR) - $(CXX) $(TEST_MAIN_SRC) $< $(GTEST_OBJ) $(STATIC_NAME) \ - -o $@ $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) + $(CXX) $< $(CXXFLAGS) -c -o $@ @ echo $(TEST_ALL_BIN): $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) $(STATIC_NAME) @@ -251,9 +247,11 @@ $(TEST_ALL_BIN): $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) $(STATIC_NAME) -o $@ $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) @ echo -$(TEST_LINK_DIR)/%.testbin: $(TEST_BUILD_DIR)/%.testbin | $(TEST_LINK_DIR) - @ $(RM) $@ - @ ln -s ../../$(TEST_BUILD_DIR)/$(@F) $@ +$(TEST_BIN_DIR)/%.testbin: $(TEST_BUILD_DIR)/%.o $(GTEST_OBJ) $(STATIC_NAME) \ + | $(TEST_BIN_DIR) + $(CXX) $(TEST_MAIN_SRC) $< $(GTEST_OBJ) $(STATIC_NAME) \ + -o $@ $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) + @ echo $(TOOL_BINS): %.bin : %.o $(STATIC_NAME) $(CXX) $< $(STATIC_NAME) -o $@ $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) @@ -273,11 +271,6 @@ $(PROTO_BUILD_DIR)/%.pb.o: $(PROTO_BUILD_DIR)/%.pb.cc $(PROTO_GEN_HEADER) \ $(CXX) $< $(CXXFLAGS) -c -o $@ @ echo -$(TEST_BUILD_DIR)/%.o: src/$(PROJECT)/test/%.cpp $(HXX_SRCS) $(TEST_HDRS) \ - | $(TEST_BUILD_DIR) - $(CXX) $< $(CXXFLAGS) -c -o $@ - @ echo - $(UTIL_BUILD_DIR)/%.o: src/$(PROJECT)/util/%.cpp $(HXX_SRCS) | $(UTIL_BUILD_DIR) $(CXX) $< $(CXXFLAGS) -c -o $@ @ echo @@ -317,9 +310,7 @@ $(PROTO_BUILD_DIR)/%.pb.cc $(PROTO_BUILD_DIR)/%.pb.h : \ $(PROTO_BUILD_INCLUDE_DIR)/%.pb.h: $(PROTO_BUILD_DIR)/%.pb.h \ | $(PROTO_BUILD_INCLUDE_DIR) - @ $(RM) $(PROTO_BUILD_INCLUDE_DIR)/$(*F).pb.h - @ ln -s ../../../../$(PROTO_BUILD_DIR)/$(*F).pb.h \ - $(PROTO_BUILD_INCLUDE_DIR)/$(*F).pb.h + @ cp $(PROTO_BUILD_DIR)/$(*F).pb.h $(PROTO_BUILD_INCLUDE_DIR)/$(*F).pb.h $(PROTO_GEN_PY): $(PROTO_SRCS) protoc --proto_path=src --python_out=python $(PROTO_SRCS) From 39ca2def3528610e38233bb2b97c810e126a32e9 Mon Sep 17 00:00:00 2001 From: Jeff Donahue Date: Sun, 30 Mar 2014 06:58:17 -0700 Subject: [PATCH 13/18] cleanup python build and clean --- Makefile | 27 +++++++++++++++------------ python/caffe/proto/__init__.py | 0 2 files changed, 15 insertions(+), 12 deletions(-) delete mode 100644 python/caffe/proto/__init__.py diff --git a/Makefile b/Makefile index 7c35c60199e..8cbb278ce5d 100644 --- a/Makefile +++ b/Makefile @@ -70,8 +70,10 @@ PROTO_GEN_HEADER := $(addprefix $(PROTO_BUILD_INCLUDE_DIR)/, \ $(notdir ${PROTO_SRCS:.proto=.pb.h})) HXX_SRCS += $(PROTO_GEN_HEADER) PROTO_GEN_CC := $(addprefix $(BUILD_DIR)/, ${PROTO_SRCS:.proto=.pb.cc}) +PY_PROTO_BUILD_DIR := python/$(PROJECT)/proto +PY_PROTO_INIT := python/$(PROJECT)/proto/__init__.py PROTO_GEN_PY := $(foreach file,${PROTO_SRCS:.proto=_pb2.py}, \ - python/$(PROJECT)/proto/$(notdir $(file))) + $(PY_PROTO_BUILD_DIR)/$(notdir $(file))) # The objects corresponding to the source files # These objects will be linked into the final shared library, so we # exclude the tool, example, and test objects. @@ -137,7 +139,7 @@ ALL_BUILD_DIRS := $(sort \ $(LAYER_BUILD_DIR) $(UTIL_BUILD_DIR) $(TOOL_BUILD_DIR) \ $(TEST_BUILD_DIR) $(TEST_BIN_DIR) $(GTEST_BUILD_DIR) \ $(EXAMPLE_BUILD_DIRS) \ - $(PROTO_BUILD_DIR) $(PROTO_BUILD_INCLUDE_DIR) \ + $(PROTO_BUILD_DIR) $(PROTO_BUILD_INCLUDE_DIR) $(PY_PROTO_BUILD_DIR) \ $(DISTRIBUTE_SUBDIRS)) DEBUG ?= 0 @@ -279,8 +281,8 @@ $(GTEST_OBJ): $(GTEST_SRC) | $(GTEST_BUILD_DIR) $(CXX) $< $(CXXFLAGS) -c -o $@ @ echo -$(LAYER_BUILD_DIR)/%.cuo: \ - src/$(PROJECT)/layers/%.cu $(HXX_SRCS) | $(LAYER_BUILD_DIR) +$(LAYER_BUILD_DIR)/%.cuo: src/$(PROJECT)/layers/%.cu $(HXX_SRCS) \ + | $(LAYER_BUILD_DIR) $(CUDA_DIR)/bin/nvcc $(NVCCFLAGS) $(CUDA_ARCH) -c $< -o $@ @ echo @@ -312,18 +314,19 @@ $(PROTO_BUILD_INCLUDE_DIR)/%.pb.h: $(PROTO_BUILD_DIR)/%.pb.h \ | $(PROTO_BUILD_INCLUDE_DIR) @ cp $(PROTO_BUILD_DIR)/$(*F).pb.h $(PROTO_BUILD_INCLUDE_DIR)/$(*F).pb.h -$(PROTO_GEN_PY): $(PROTO_SRCS) - protoc --proto_path=src --python_out=python $(PROTO_SRCS) +$(PY_PROTO_BUILD_DIR)/%_pb2.py : $(PROTO_SRC_DIR)/%.proto \ + $(PY_PROTO_INIT) | $(PY_PROTO_BUILD_DIR) + protoc --proto_path=src --python_out=python $< @ echo +$(PY_PROTO_INIT): | $(PY_PROTO_BUILD_DIR) + touch $(PY_PROTO_INIT) + clean: - @- $(RM) $(NAME) $(STATIC_NAME) - @- $(RM) $(PROTO_GEN_HEADER) $(PROTO_GEN_CC) $(PROTO_GEN_PY) - @- $(RM) include/$(PROJECT)/proto/$(PROJECT).pb.h - @- $(RM) python/$(PROJECT)/proto/$(PROJECT)_pb2.py - @- $(RM) python/$(PROJECT)/*.so - @- $(RM) -rf $(BUILD_DIR) + @- $(RM) -rf $(ALL_BUILD_DIRS) @- $(RM) -rf $(DISTRIBUTE_DIR) + @- $(RM) $(PY$(PROJECT)_SO) + @- $(RM) $(MAT$(PROJECT)_SO) supercleanfiles: $(eval SUPERCLEAN_FILES := $(strip \ diff --git a/python/caffe/proto/__init__.py b/python/caffe/proto/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 From 48994cf0ddcaac0ca875c166dd3a1d0a3d1f4c8b Mon Sep 17 00:00:00 2001 From: Jeff Donahue Date: Sun, 30 Mar 2014 07:21:00 -0700 Subject: [PATCH 14/18] fix test bugs and minor cleanup --- Makefile | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 8cbb278ce5d..7172b3c7574 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ TOOL_SRCS := $(shell find tools -name "*.cpp") EXAMPLE_SRCS := $(shell find examples -name "*.cpp") # BUILD_INCLUDE_DIR contains any generated header files we want to include. BUILD_INCLUDE_DIR := $(BUILD_DIR)/include -# PROTO_SRCS are the protocol buffer defions +# PROTO_SRCS are the protocol buffer definitions PROTO_SRC_DIR := src/$(PROJECT)/proto PROTO_SRCS := $(wildcard $(PROTO_SRC_DIR)/*.proto) # PROTO_BUILD_DIR will contain the .cc and obj files generated from @@ -98,10 +98,10 @@ EXAMPLE_BUILD_DIRS += $(foreach obj,$(EXAMPLE_OBJS),$(dir $(obj))) # tool, example, and test bins TOOL_BINS := ${TOOL_OBJS:.o=.bin} EXAMPLE_BINS := ${EXAMPLE_OBJS:.o=.bin} -# A shortcut to the directory of test binaries for convenience. +# Put the test binaries in build/test for convenience. TEST_BIN_DIR := $(BUILD_DIR)/test -TEST_BINS := $(addprefix $(TEST_BIN_DIR)/, \ - $(foreach obj,$(TEST_OBJS),$(notdir $(obj)))) +TEST_BINS := $(addsuffix .testbin,$(addprefix $(TEST_BIN_DIR)/, \ + $(foreach obj,$(TEST_OBJS),$(basename $(notdir $(obj)))))) TEST_ALL_BIN := $(TEST_BIN_DIR)/test_all.testbin ############################## @@ -168,9 +168,9 @@ LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) \ PYTHON_LDFLAGS := $(LDFLAGS) $(foreach library,$(PYTHON_LIBRARIES),-l$(library)) # 'superclean' target recursively* deletes all files ending with an extension -# suggesting that Caffe built them. This may be useful if you've built older +# in $(SUPERCLEAN_EXTS) below. This may be useful if you've built older # versions of Caffe that do not place all generated files in a location known -# to make clean. +# to the 'clean' target. # # 'supercleanlist' will list the files to be deleted by make superclean. # @@ -181,7 +181,7 @@ SUPERCLEAN_EXTS := .so .a .o .bin .testbin .pb.cc .pb.h _pb2.py .cuo ############################## # Define build targets ############################## -.PHONY: all test clean linecount lint tools examples dist \ +.PHONY: all test clean linecount lint tools examples $(DIST_ALIASES) \ py mat py$(PROJECT) mat$(PROJECT) proto runtest \ superclean supercleanlist supercleanfiles @@ -244,7 +244,8 @@ $(TEST_BUILD_DIR)/%.o: src/$(PROJECT)/test/%.cpp $(HXX_SRCS) $(TEST_HDRS) \ $(CXX) $< $(CXXFLAGS) -c -o $@ @ echo -$(TEST_ALL_BIN): $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) $(STATIC_NAME) +$(TEST_ALL_BIN): $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) $(STATIC_NAME) \ + | $(TEST_BIN_DIR) $(CXX) $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJ) $(STATIC_NAME) \ -o $@ $(CXXFLAGS) $(LDFLAGS) $(WARNINGS) @ echo From abf44a6174df4cfd69849c91cc237bb33a4e6e3e Mon Sep 17 00:00:00 2001 From: Jeff Donahue Date: Mon, 31 Mar 2014 14:16:11 -0700 Subject: [PATCH 15/18] matcaffe fixes --- Makefile | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 7172b3c7574..a84d3b0d008 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,8 @@ # The makefile for caffe. Pretty hacky. PROJECT := caffe -include Makefile.config - -############################################################################## -# After this line, things should happen automatically. -############################################################################## +CONFIG_FILE := Makefile.config +include $(CONFIG_FILE) # The target static library and shared library name LIB_BUILD_DIR := $(BUILD_DIR)/lib @@ -58,7 +55,10 @@ PY$(PROJECT)_SRC := python/$(PROJECT)/_$(PROJECT).cpp PY$(PROJECT)_SO := python/$(PROJECT)/_$(PROJECT).so # MAT$(PROJECT)_SRC is the matlab wrapper for $(PROJECT) MAT$(PROJECT)_SRC := matlab/$(PROJECT)/mat$(PROJECT).cpp -MAT$(PROJECT)_SO := matlab/$(PROJECT)/$(PROJECT) +ifneq ($(MATLAB_DIR),) + MAT_SO_EXT := $(shell $(MATLAB_DIR)/bin/mexext) +endif +MAT$(PROJECT)_SO := matlab/$(PROJECT)/$(PROJECT).$(MAT_SO_EXT) ############################## # Derive generated files @@ -220,6 +220,11 @@ mat$(PROJECT): mat mat: $(MAT$(PROJECT)_SO) $(MAT$(PROJECT)_SO): $(MAT$(PROJECT)_SRC) $(STATIC_NAME) + @ if [ -z "$(MATLAB_DIR)" ]; then \ + echo "MATLAB_DIR must be specified in $(CONFIG_FILE)" \ + "to build mat$(PROJECT)."; \ + exit 1; \ + fi $(MATLAB_DIR)/bin/mex $(MAT$(PROJECT)_SRC) $(STATIC_NAME) \ CXXFLAGS="\$$CXXFLAGS $(CXXFLAGS) $(WARNINGS)" \ CXXLIBS="\$$CXXLIBS $(LDFLAGS)" -o $@ From 74a3788298226e9e6552651efc3dc8a97ff29307 Mon Sep 17 00:00:00 2001 From: Jeff Donahue Date: Mon, 31 Mar 2014 14:25:42 -0700 Subject: [PATCH 16/18] remove silly thing where I copied proto headers to a separate build/include dir --- Makefile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Makefile b/Makefile index a84d3b0d008..b9688d7f66f 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ TOOL_SRCS := $(shell find tools -name "*.cpp") # EXAMPLE_SRCS are the source files for the example binaries EXAMPLE_SRCS := $(shell find examples -name "*.cpp") # BUILD_INCLUDE_DIR contains any generated header files we want to include. -BUILD_INCLUDE_DIR := $(BUILD_DIR)/include +BUILD_INCLUDE_DIR := $(BUILD_DIR)/src # PROTO_SRCS are the protocol buffer definitions PROTO_SRC_DIR := src/$(PROJECT)/proto PROTO_SRCS := $(wildcard $(PROTO_SRC_DIR)/*.proto) @@ -316,10 +316,6 @@ $(PROTO_BUILD_DIR)/%.pb.cc $(PROTO_BUILD_DIR)/%.pb.h : \ protoc --proto_path=src --cpp_out=build/src $< @ echo -$(PROTO_BUILD_INCLUDE_DIR)/%.pb.h: $(PROTO_BUILD_DIR)/%.pb.h \ - | $(PROTO_BUILD_INCLUDE_DIR) - @ cp $(PROTO_BUILD_DIR)/$(*F).pb.h $(PROTO_BUILD_INCLUDE_DIR)/$(*F).pb.h - $(PY_PROTO_BUILD_DIR)/%_pb2.py : $(PROTO_SRC_DIR)/%.proto \ $(PY_PROTO_INIT) | $(PY_PROTO_BUILD_DIR) protoc --proto_path=src --python_out=python $< From 6b3d257eea7680c96332e6359c12eba93a784c75 Mon Sep 17 00:00:00 2001 From: Jeff Donahue Date: Wed, 2 Apr 2014 11:29:01 -0700 Subject: [PATCH 17/18] include build/ before other dirs so old proto built files in src/ and include/ don't interfere --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b9688d7f66f..094719685ec 100644 --- a/Makefile +++ b/Makefile @@ -112,8 +112,8 @@ CUDA_LIB_DIR := $(CUDA_DIR)/lib64 $(CUDA_DIR)/lib MKL_INCLUDE_DIR := $(MKL_DIR)/include MKL_LIB_DIR := $(MKL_DIR)/lib $(MKL_DIR)/lib/intel64 -INCLUDE_DIRS += ./src ./include $(CUDA_INCLUDE_DIR) INCLUDE_DIRS += $(BUILD_INCLUDE_DIR) +INCLUDE_DIRS += ./src ./include $(CUDA_INCLUDE_DIR) LIBRARY_DIRS += $(CUDA_LIB_DIR) LIBRARIES := cudart cublas curand \ pthread \ From 76caca3a5a5027e1cbe43123a6db9e9d89ac347d Mon Sep 17 00:00:00 2001 From: Jeff Donahue Date: Fri, 4 Apr 2014 13:44:34 -0700 Subject: [PATCH 18/18] gitignore python/caffe/proto/; superclean ignore data dir --- .gitignore | 1 + Makefile | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3997e463cdb..5aeb3dc24e2 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ build/* distribute/* *.testbin *.bin +python/caffe/proto/ # Editor temporaries *.swp diff --git a/Makefile b/Makefile index 094719685ec..83117e3ae41 100644 --- a/Makefile +++ b/Makefile @@ -332,7 +332,8 @@ clean: supercleanfiles: $(eval SUPERCLEAN_FILES := $(strip \ - $(foreach ext,$(SUPERCLEAN_EXTS), $(shell find . -name '*$(ext)')))) + $(foreach ext,$(SUPERCLEAN_EXTS), $(shell find . -name '*$(ext)' \ + -not -path './data/*')))) supercleanlist: supercleanfiles @ \