diff options
author | Yangqing Jia <jiayq84@gmail.com> | 2013-10-10 15:20:20 -0700 |
---|---|---|
committer | Yangqing Jia <jiayq84@gmail.com> | 2013-10-10 15:20:20 -0700 |
commit | 5badef47fbde0f0ef90817e83900270ecfad6d95 (patch) | |
tree | b8d946cf72bce526476a05d9e1f77207a40f8911 /src | |
parent | 7d3fcf92abaabd3e2acea9b1d294cc01dbb855e6 (diff) | |
download | caffeonacl-5badef47fbde0f0ef90817e83900270ecfad6d95.tar.gz caffeonacl-5badef47fbde0f0ef90817e83900270ecfad6d95.tar.bz2 caffeonacl-5badef47fbde0f0ef90817e83900270ecfad6d95.zip |
makefile cleaning: now it supports -j while the old version has bugs in dependencies
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 63 | ||||
-rw-r--r-- | src/programs/train_net.cpp | 10 |
2 files changed, 41 insertions, 32 deletions
diff --git a/src/Makefile b/src/Makefile index 27fd7603..6f06866f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,32 +1,35 @@ -# -# The following defines a variable named "NAME" with a value of "myprogram". By convention, -# a lowercase prefix (in this case "program") and an uppercased suffix (in this case "NAME"), separated -# by an underscore is used to name attributes for a common element. Think of this like -# using program.NAME, program.C_SRCS, etc. There are no structs in Make, so we use this convention -# to keep track of attributes that all belong to the same target or program. -# +# The makefile for caffe. Extremely hack. PROJECT := caffe +TEST_GPUID := 1 + +# The target static library and shared library name NAME := lib$(PROJECT).so -TEST_NAME := test_$(PROJECT) +STATIC_NAME := lib$(PROJECT).a +# All source files CXX_SRCS := $(shell find caffe ! -name "test_*.cpp" -name "*.cpp") CU_SRCS := $(shell find caffe -name "*.cu") TEST_SRCS := $(shell find caffe -name "test_*.cpp") GTEST_SRC := gtest/gtest-all.cpp PROGRAM_SRCS := $(shell find programs -name "*.cpp") PROTO_SRCS := $(wildcard caffe/proto/*.proto) +# The generated files for protocol buffers PROTO_GEN_HEADER := ${PROTO_SRCS:.proto=.pb.h} PROTO_GEN_CC := ${PROTO_SRCS:.proto=.pb.cc} PROTO_GEN_PY := ${PROTO_SRCS:.proto=_pb2.py} +# The objects that are needed to generate the library CXX_OBJS := ${CXX_SRCS:.cpp=.o} CU_OBJS := ${CU_SRCS:.cu=.cuo} -PROGRAM_OBJS := ${PROGRAM_SRCS:.cpp=.o} -PROTO_OBJS := ${PROTO_SRCS:.proto=.pb.o} +PROTO_OBJS := ${PROTO_GEN_CC:.cc=.o} OBJS := $(PROTO_OBJS) $(CXX_OBJS) $(CU_OBJS) +# program and test objects +PROGRAM_OBJS := ${PROGRAM_SRCS:.cpp=.o} TEST_OBJS := ${TEST_SRCS:.cpp=.o} GTEST_OBJ := ${GTEST_SRC:.cpp=.o} -TEST_BINS := ${TEST_OBJS:.o=.testbin} +# program and test bins PROGRAM_BINS :=${PROGRAM_OBJS:.o=.bin} +TEST_BINS := ${TEST_OBJS:.o=.testbin} +# define third-party library paths CUDA_DIR := /usr/local/cuda CUDA_ARCH := -arch=sm_20 MKL_DIR := /opt/intel/mkl @@ -36,42 +39,46 @@ CUDA_LIB_DIR := $(CUDA_DIR)/lib64 MKL_INCLUDE_DIR := $(MKL_DIR)/include MKL_LIB_DIR := $(MKL_DIR)/lib $(MKL_DIR)/lib/intel64 +# define inclue and libaries INCLUDE_DIRS := . /usr/local/include $(CUDA_INCLUDE_DIR) $(MKL_INCLUDE_DIR) LIBRARY_DIRS := . /usr/lib /usr/local/lib $(CUDA_LIB_DIR) $(MKL_LIB_DIR) LIBRARIES := cuda cudart cublas protobuf glog mkl_rt mkl_intel_thread curand \ leveldb snappy opencv_core opencv_highgui pthread tcmalloc WARNINGS := -Wall -CXXFLAGS += -pthread -fPIC -O2 $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir)) -NVCCFLAGS := -Xcompiler -fPIC -O2 $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir)) -LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) -LDFLAGS += $(foreach library,$(LIBRARIES),-l$(library)) +COMMON_FLAGS := $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir)) +CXXFLAGS += -pthread -fPIC -O2 $(COMMON_FLAGS) +NVCCFLAGS := -Xcompiler -fPIC -O2 $(COMMON_FLAGS) +LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) \ + $(foreach library,$(LIBRARIES),-l$(library)) -LINK = $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(WARNINGS) NVCC = nvcc $(NVCCFLAGS) $(CPPFLAGS) $(CUDA_ARCH) .PHONY: all test clean distclean linecount program -all: $(NAME) +all: $(NAME) $(STATIC_NAME) test program linecount: clean cloc --read-lang-def=caffe.cloc caffe/ -test: $(OBJS) $(GTEST_OBJ) $(TEST_BINS) +test: $(TEST_BINS) -program: $(OBJS) $(PROGRAM_BINS) +program: $(PROGRAM_BINS) -runtest: test - for testbin in $(TEST_BINS); do $$testbin 1; done +$(NAME): $(PROTO_OBJS) $(OBJS) + $(CXX) -shared $(OBJS) -o $(NAME) $(LDFLAGS) $(WARNINGS) -$(TEST_BINS): %.testbin : %.o - $(CXX) -pthread $< $(OBJS) $(GTEST_OBJ) -o $@ $(LDFLAGS) $(WARNINGS) +$(STATIC_NAME): $(PROTO_OBJS) $(OBJS) + ar rcs $(STATIC_NAME) $(PROTO_OBJS) $(OBJS) + +runtest: test + for testbin in $(TEST_BINS); do $$testbin $(TEST_GPUID); done -$(PROGRAM_BINS): %.bin : %.o - $(CXX) -pthread $< $(OBJS) -o $@ $(LDFLAGS) $(WARNINGS) +$(TEST_BINS): %.testbin : %.o $(GTEST_OBJ) $(STATIC_NAME) + $(CXX) $< $(GTEST_OBJ) $(STATIC_NAME) -o $@ $(LDFLAGS) $(WARNINGS) -$(NAME): $(PROTO_GEN_CC) $(OBJS) - $(LINK) -shared $(OBJS) -o $(NAME) +$(PROGRAM_BINS): %.bin : %.o $(STATIC_NAME) + $(CXX) $< $(STATIC_NAME) -o $@ $(LDFLAGS) $(WARNINGS) $(CU_OBJS): %.cuo: %.cu $(NVCC) -c $< -o $@ @@ -80,7 +87,7 @@ $(PROTO_GEN_CC): $(PROTO_SRCS) protoc $(PROTO_SRCS) --cpp_out=. --python_out=. clean: - @- $(RM) $(NAME) $(TEST_BINS) $(PROGRAM_BINS) + @- $(RM) $(NAME) $(STATIC_NAME) $(TEST_BINS) $(PROGRAM_BINS) @- $(RM) $(OBJS) $(TEST_OBJS) $(PROGRAM_OBJS) @- $(RM) $(PROTO_GEN_HEADER) $(PROTO_GEN_CC) $(PROTO_GEN_PY) diff --git a/src/programs/train_net.cpp b/src/programs/train_net.cpp index 41110430..15f43151 100644 --- a/src/programs/train_net.cpp +++ b/src/programs/train_net.cpp @@ -1,8 +1,11 @@ // Copyright 2013 Yangqing Jia +// +// This is a simple script that allows one to quickly train a network whose +// parameters are specified by text format protocol buffers. +// Usage: +// train_net net_proto_file solver_proto_file #include <cuda_runtime.h> -#include <fcntl.h> -#include <google/protobuf/text_format.h> #include <cstring> @@ -22,8 +25,7 @@ int main(int argc, char** argv) { Caffe::set_phase(Caffe::TRAIN); NetParameter net_param; - ReadProtoFromTextFile(argv[1], - &net_param); + ReadProtoFromTextFile(argv[1], &net_param); vector<Blob<float>*> bottom_vec; Net<float> caffe_net(net_param, bottom_vec); |