Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Commit

Permalink
Merge Intel Caffe release_1.0.7.
Browse files Browse the repository at this point in the history
  • Loading branch information
daisyden committed Dec 13, 2017
2 parents c7ed327 + 7ef8316 commit f6a2a6b
Show file tree
Hide file tree
Showing 71 changed files with 7,945 additions and 16,295 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ caffe_option(PERFORMANCE_MONITORING "Build Caffe with PERFORMANCE_MONITORING " O

# ---[ Dependencies
include(cmake/MKLDNN.cmake)
include(cmake/DLCP.cmake)
include(cmake/Dependencies.cmake)

# ---[ Flags
Expand Down
35 changes: 25 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ endif

RETURN_STRING=$(shell ./external/mlsl/prepare_mlsl.sh)
MLSL_ROOT=$(firstword $(RETURN_STRING))
MLSL_LDFLAGS=$(lastword $(RETURN_STRING))
MLSL_LDFLAGS=$(lastword $(RETURN_STRING))
COMMON_FLAGS += -DUSE_MLSL=1
LIBRARIES += mlsl
INCLUDE_DIRS += $(MLSL_ROOT)/intel64/include
LIBRARY_DIRS += $(MLSL_ROOT)/intel64/lib
IGNORE := $(shell bash -c "source $(MLSL_ROOT)/intel64/bin/mlslvars.sh; env | sed 's/=/:=/' | sed 's/^/export /' > make_mlsl_env")
include make_mlsl_env

ifeq ($(CAFFE_PER_LAYER_TIMINGS), 1)
COMMON_FLAGS += -DCAFFE_PER_LAYER_TIMINGS
Expand Down Expand Up @@ -249,7 +251,13 @@ ifneq ($(CPU_ONLY), 1)
LIBRARIES := cudart cublas curand
endif

LIBRARIES += glog gflags protobuf m hdf5_hl hdf5
LIBRARIES += glog gflags protobuf m
ifeq ($(shell find /usr/lib* /usr/local/lib* -name "libhdf5_serial.so" 2> /dev/null | grep serial >/dev/null && echo serial) , serial)
LIBRARIES += hdf5_serial_hl hdf5_serial
else
LIBRARIES += hdf5_hl hdf5
endif

BOOST_LIBRARIES += boost_system boost_filesystem boost_regex

# handle IO dependencies
Expand Down Expand Up @@ -479,6 +487,11 @@ ifeq ($(WITH_PYTHON_LAYER), 1)
LIBRARIES += $(PYTHON_LIBRARIES)
endif

# Remove batch norm feature support
ifeq ($(DISABLE_BN_FOLDING), 1)
COMMON_FLAGS += -DDISABLE_BN_FOLDING
endif

# Performance monitoring
ifeq ($(PERFORMANCE_MONITORING), 1)
CXXFLAGS += -DPERFORMANCE_MONITORING
Expand All @@ -489,6 +502,8 @@ ifeq ($(USE_MKLDNN_AS_DEFAULT_ENGINE), 1)
CXXFLAGS += -DUSE_MKLDNN_AS_DEFAULT_ENGINE
endif

include Makefile.dlcp

# BOOST configuration
# detect support for custom boost version
BOOST_LDFLAGS += $(foreach boost_lib,$(BOOST_LIBRARIES),-l$(boost_lib))
Expand Down Expand Up @@ -602,7 +617,7 @@ endif
##############################
.PHONY: all lib test clean docs linecount lint lintclean tools examples $(DIST_ALIASES) \
py mat py$(PROJECT) mat$(PROJECT) proto runtest \
superclean supercleanlist supercleanfiles warn everything mkldnn mkldnn_clean
superclean supercleanlist supercleanfiles warn everything mkldnn mkldnn_clean dlcp dlcp_clean

.DEFAULT_GOAL := all

Expand Down Expand Up @@ -757,14 +772,14 @@ $(ALL_BUILD_DIRS): | $(BUILD_DIR_LINK)

$(DYNAMIC_NAME): $(OBJS) | $(LIB_BUILD_DIR)
@ echo LD -o $@
$(Q)$(CXX) -shared -o $@ $(OBJS) $(VERSIONFLAGS) $(BOOST_LDFLAGS) $(LINKFLAGS) $(MKL_LDFLAGS) $(MKLDNN_LDFLAGS) $(CXX_HARDENING_FLAGS) $(LINKER_SHARED_HARDENING_FLAGS) $(LDFLAGS)
$(Q)$(CXX) -shared -o $@ $(OBJS) $(VERSIONFLAGS) $(BOOST_LDFLAGS) $(LINKFLAGS) $(MKL_LDFLAGS) $(MKLDNN_LDFLAGS) $(DLCP_LDFLAGS) $(CXX_HARDENING_FLAGS) $(LINKER_SHARED_HARDENING_FLAGS) $(LDFLAGS)
@ cd $(BUILD_DIR)/lib; rm -f $(DYNAMIC_NAME_SHORT); ln -s $(DYNAMIC_VERSIONED_NAME_SHORT) $(DYNAMIC_NAME_SHORT)

$(STATIC_NAME): $(OBJS) | $(LIB_BUILD_DIR)
@ echo AR -o $@
$(Q)ar rcs $@ $(OBJS)

$(BUILD_DIR)/%.o: %.cpp | mkldnn $(ALL_BUILD_DIRS)
$(BUILD_DIR)/%.o: %.cpp | mkldnn dlcp $(ALL_BUILD_DIRS)
@ echo CXX $<
$(Q)$(CXX) $< $(CXX_HARDENING_FLAGS) $(CXXFLAGS) -c -o $@ 2> $@.$(WARNS_EXT) \
|| (cat $@.$(WARNS_EXT); exit 1)
Expand All @@ -789,7 +804,7 @@ $(TEST_ALL_BIN): $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJS) \
| $(DYNAMIC_NAME) $(TEST_BIN_DIR)
@ echo CXX/LD -o $@ $<
$(Q)$(CXX) -std=c++11 $(TEST_MAIN_SRC) $(TEST_OBJS) $(GTEST_OBJS) \
-o $@ $(BOOST_LDFLAGS) $(LINKFLAGS) $(MKL_LDFLAGS) $(MKLDNN_LDFLAGS) $(CXX_HARDENING_FLAGS) $(LINKER_EXEC_HARDENING_FLAGS) $(LDFLAGS) -l$(LIBRARY_NAME) -Wl,-rpath,$(ORIGIN)/../lib
-o $@ $(BOOST_LDFLAGS) $(LINKFLAGS) $(MKL_LDFLAGS) $(MKLDNN_LDFLAGS) $(DLCP_LDFLAGS) $(CXX_HARDENING_FLAGS) $(LINKER_EXEC_HARDENING_FLAGS) $(LDFLAGS) -l$(LIBRARY_NAME) -Wl,-rpath,$(ORIGIN)/../lib

$(TEST_CU_BINS): $(TEST_BIN_DIR)/%.testbin: $(TEST_CU_BUILD_DIR)/%.o \
$(GTEST_OBJS) | $(DYNAMIC_NAME) $(TEST_BIN_DIR)
Expand All @@ -801,7 +816,7 @@ $(TEST_CXX_BINS): $(TEST_BIN_DIR)/%.testbin: $(TEST_CXX_BUILD_DIR)/%.o \
$(GTEST_OBJS) | $(DYNAMIC_NAME) $(TEST_BIN_DIR)
@ echo LD $<
$(Q)$(CXX) -std=c++11 $(TEST_MAIN_SRC) $< $(GTEST_OBJS) \
-o $@ $(BOOST_LDFLAGS) $(LINKFLAGS) $(MKL_LDFLAGS) $(MKLDNN_LDFLAGS) $(CXX_HARDENING_FLAGS) $(LINKER_EXEC_HARDENING_FLAGS) $(LDFLAGS) -l$(LIBRARY_NAME) -Wl,-rpath,$(ORIGIN)/../lib
-o $@ $(BOOST_LDFLAGS) $(LINKFLAGS) $(MKL_LDFLAGS) $(MKLDNN_LDFLAGS) $(DLCP_LDFLAGS) $(CXX_HARDENING_FLAGS) $(LINKER_EXEC_HARDENING_FLAGS) $(LDFLAGS) -l$(LIBRARY_NAME) -Wl,-rpath,$(ORIGIN)/../lib

# Target for extension-less symlinks to tool binaries with extension '*.bin'.
$(TOOL_BUILD_DIR)/%: $(TOOL_BUILD_DIR)/%.bin | $(TOOL_BUILD_DIR)
Expand All @@ -810,12 +825,12 @@ $(TOOL_BUILD_DIR)/%: $(TOOL_BUILD_DIR)/%.bin | $(TOOL_BUILD_DIR)

$(TOOL_BINS): %.bin : %.o | $(DYNAMIC_NAME)
@ echo CXX/LD -o $@
$(Q)$(CXX) $< -o $@ $(BOOST_LDFLAGS) $(LINKFLAGS) $(MKL_LDFLAGS) $(MKLDNN_LDFLAGS) $(CXX_HARDENING_FLAGS) $(LINKER_EXEC_HARDENING_FLAGS) -l$(LIBRARY_NAME) $(LDFLAGS) \
$(Q)$(CXX) $< -o $@ $(BOOST_LDFLAGS) $(LINKFLAGS) $(MKL_LDFLAGS) $(MKLDNN_LDFLAGS) $(DLCP_LDFLAGS) $(CXX_HARDENING_FLAGS) $(LINKER_EXEC_HARDENING_FLAGS) -l$(LIBRARY_NAME) $(LDFLAGS) \
-Wl,-rpath,$(ORIGIN)/../lib

$(EXAMPLE_BINS): %.bin : %.o | $(DYNAMIC_NAME)
@ echo CXX/LD -o $@
$(Q)$(CXX) $< -o $@ $(BOOST_LDFLAGS) $(LINKFLAGS) $(MKL_LDFLAGS) $(MKLDNN_LDFLAGS) $(CXX_HARDENING_FLAGS) $(LINKER_EXEC_HARDENING_FLAGS) -l$(LIBRARY_NAME) $(LDFLAGS) \
$(Q)$(CXX) $< -o $@ $(BOOST_LDFLAGS) $(LINKFLAGS) $(MKL_LDFLAGS) $(MKLDNN_LDFLAGS) $(DLCP_LDFLAGS) $(CXX_HARDENING_FLAGS) $(LINKER_EXEC_HARDENING_FLAGS) -l$(LIBRARY_NAME) $(LDFLAGS) \
-Wl,-rpath,$(ORIGIN)/../../lib

proto: $(PROTO_GEN_CC) $(PROTO_GEN_HEADER)
Expand All @@ -833,7 +848,7 @@ $(PY_PROTO_BUILD_DIR)/%_pb2.py : $(PROTO_SRC_DIR)/%.proto \
$(PY_PROTO_INIT): | $(PY_PROTO_BUILD_DIR)
touch $(PY_PROTO_INIT)

clean: mkldnn_clean
clean: mkldnn_clean dlcp_clean
@echo "Will download the new version of MKL2017 and MLSL when clean and prepare the environment."
@- $(RM) -rf $(ALL_BUILD_DIRS)
@- $(RM) -rf $(OTHER_BUILD_DIR)
Expand Down
6 changes: 5 additions & 1 deletion Makefile.config.example
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ USE_MKLDNN_AS_DEFAULT_ENGINE := 1
# already.
# BOOST_ROOT :=

# Use remove batch norm optimization to boost inferrence
DISABLE_BN_FOLDING := 0
# Intel(r) Machine Learning Scaling Library (uncomment to build
# with MLSL for multi-node training)
# USE_MLSL :=1
Expand Down Expand Up @@ -115,6 +117,8 @@ BLAS := mkl
# MATLAB_DIR := /usr/local
# MATLAB_DIR := /Applications/MATLAB_R2012b.app

SERIAL_HDF5_INCLUDE := /usr/include/hdf5/serial/

# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
PYTHON_INCLUDE := /usr/include/python2.7 \
Expand Down Expand Up @@ -143,7 +147,7 @@ PYTHON_LIB := /usr/lib
# WITH_PYTHON_LAYER := 1

# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
INCLUDE_DIRS := $(PYTHON_INCLUDE) ${SERIAL_HDF5_INCLUDE} /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib

# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
Expand Down
58 changes: 58 additions & 0 deletions Makefile.dlcp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
CAFFE_ROOTDIR := $(shell pwd)
DLCP_IDEEPDIR := $(CAFFE_ROOTDIR)/external/ideep
DLCP_ROOTDIR := $(DLCP_IDEEPDIR)/ideep/dlcp
DLCP_INCLDIR := $(DLCP_ROOTDIR)/include
DLCP_LIBDIR := $(DLCP_ROOTDIR)/lib
IDEEP_GITHUB := https://github.com/intel/ideep.git
DLCP_CXX := $(CXX)

ifeq ("$(wildcard $(DLCP_INCLDIR)/dl_compression.h)", "")
dlcp_download:
rm -rf $(DLCP_IDEEPDIR)
git clone $(IDEEP_GITHUB) -b dlcp $(DLCP_IDEEPDIR)

dlcp_build: dlcp_download
make -C $(DLCP_ROOTDIR) -j$(shell cat /proc/cpuinfo |grep 'processor'|wc -l)
else
dlcp_download:
dlcp_build:
make -C $(DLCP_ROOTDIR) -j$(shell cat /proc/cpuinfo |grep 'processor'|wc -l)
endif

dlcp_clean:
@rm -rf $(DLCP_IDEEPDIR)

dlcproot_set:
$(eval COMMON_FLAGS += -DENABLE_WEIGHT_GRAD_COMPRESSION) \
$(eval INCLUDE_DIRS += $(DLCP_INCLDIR)) \
$(eval DLCP_LDFLAGS += -ldlcomp -L$(DLCPROOT)/lib) \
$(eval DLCP_LDFLAGS += -Wl,-rpath,$(DLCPROOT)/lib)


dlcproot_notset: dlcp_build
$(eval COMMON_FLAGS += -DENABLE_WEIGHT_GRAD_COMPRESSION) \
$(eval INCLUDE_DIRS += $(DLCP_INCLDIR)) \
$(eval DLCP_LDFLAGS += -ldlcomp) \
$(eval DLCP_LDFLAGS += -L$(DLCP_LIBDIR) -Wl,-rpath,${DLCP_LIBDIR})

ifeq (,$(findstring icpc, $(DLCP_CXX)))
ifneq (,$(findstring icpc,$(shell command -v icpc)))
DLCP_CXX := icpc
endif
endif

ifeq ($(USE_MLSL), 1)
ifeq ($(origin DLCPROOT), environment)
dlcp: dlcproot_set
else
ifneq (,$(findstring icpc,$(DLCP_CXX)))
dlcp: dlcproot_notset
else
dlcp:
@echo "weight grad compression disabled because intel compiler not found"
endif
endif
else
dlcp:
@echo "disabling weight grad compression if USE_MLSL is not 1"
endif
29 changes: 29 additions & 0 deletions cmake/DLCP.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function(Download_DLCP)
find_program(HAS_ICPC NAMES icpc DOC "Intel Compiler")
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel")
set(DLCP_CXX "${CMAKE_CXX_COMPILER}" PARENT_SCOPE)
elseif(HAS_ICPC)
set(DLCP_CXX "icpc" PARENT_SCOPE)
else()
message(WARNING "weight grad compression is disabled because intel compiler is not found")
return()
endif()

set(EXTERNAL_DIR ${CMAKE_SOURCE_DIR}/external)
set(DLCP_IDEEPDIR ${EXTERNAL_DIR}/ideep)
set(DLCP_ROOTDIR ${DLCP_IDEEPDIR}/ideep/dlcp)
set(DLCP_INCLDIR "${DLCP_ROOTDIR}/include" PARENT_SCOPE)
set(DLCP_LIBDIR ${DLCP_ROOTDIR}/lib PARENT_SCOPE)

# Download dl compression lib source code if it doesn't exist
if (NOT EXISTS ${DLCP_INCLDIR}/dl_compression.h)
execute_process(COMMAND rm -rf ${DLCP_IDEEPDIR})
execute_process(COMMAND git clone https://github.com/intel/ideep.git -b dlcp ${DLCP_IDEEPDIR})
endif()

add_custom_target(DLCP_Build ALL
COMMAND export DLCP_CXX=${DLCP_CXX}
COMMAND make -j
WORKING_DIRECTORY ${DLCP_ROOTDIR})

endfunction(Download_DLCP)
27 changes: 27 additions & 0 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,33 @@ if(USE_MLSL)
endif()
endif()

# ---| DLCP
if(USE_MLSL)
if(DEFINED ENV{DLCPROOT})
set(DLCPROOT_DIR $ENV{DLCPROOT})
if(NOT ${DLCPROOT_DIR} STREQUAL "")
set(DLCPROOT_INCLUDE_DIR "${DLCPROOT_DIR}/include/")
set(DLCPROOT_LIB_DIR "${DLCPROOT_DIR}/lib/")
if(EXISTS ${DLCPROOT_INCLUDE_DIR}/dl_compression.h AND EXISTS ${DLCPROOT_LIB_DIR}/libdlcomp.so)
message(STATUS "Found DLCP: ${DLCPROOT_DIR}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_WEIGHT_GRAD_COMPRESSION")
list(APPEND Caffe_LINKER_LIBS "${DLCPROOT_LIB_DIR}/libdlcomp.so")
include_directories(SYSTEM ${DLCP_INCLUDE_DIR})
else()
message(STATUS "DLCP not found. DLCP_INCLUDE_DIR = ${DLCPROOT_INCLUDE_DIR} DLCP_LIB_DIR = ${DLCPROOT_LIB_DIR}")
message(WARNING "weight grad compression is disabled.")
endif()
endif()
else()
Download_DLCP()
if(DLCP_CXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_WEIGHT_GRAD_COMPRESSION")
list(APPEND Caffe_LINKER_LIBS "${DLCP_LIBDIR}/libdlcomp.so")
include_directories(SYSTEM ${DLCP_INCLDIR})
endif()
endif()
endif()

# ---[ BLAS
set(MKL_EXTERNAL "0")
if(NOT APPLE)
Expand Down
4 changes: 4 additions & 0 deletions cmake/Misc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ if(DEFINED CMAKE_BUILD_TYPE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES})
endif()

if(DISABLE_BN_FOLDING)
message(STATUS "Bn folding is disabled!")
add_definitions("-DDISABLE_BN_FOLDING")
endif()
# --[ If user doesn't specify build type then assume release
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE Release)
Expand Down
3 changes: 3 additions & 0 deletions docker/standalone/cpu-ubuntu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
python-dev \
python-numpy \
python-pip \
python-setuptools \
python-scipy && \
rm -rf /var/lib/apt/lists/*

Expand All @@ -32,6 +33,8 @@ WORKDIR $CAFFE_ROOT
# FIXME: clone a specific git tag and use ARG instead of ENV once DockerHub supports this.
ENV CLONE_TAG=master

RUN pip install --upgrade pip

RUN git clone -b ${CLONE_TAG} --depth 1 https://github.com/intel/caffe.git . && \
for req in $(cat python/requirements.txt) pydot; do pip install $req; done && \
mkdir build && cd build && \
Expand Down
28 changes: 28 additions & 0 deletions examples/LRCN_activity_recognition/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,31 @@ Chicago

Please see http://www.eecs.berkeley.edu/~lisa_anne/LRCN_video for detailed instructions on how to reimplement experiments and download pre-trained models.

# Support Flow LRCN From Quadra_L
- [Quadra_L](http://www.swcontest.net/index.php?a=show&m=news&aid=177)
## Preparing
- install protocol buffer 3.4.0, referring this link http://blog.csdn.net/twilightdream/article/details/72953338
- sudo -H pip install --upgrade protobuf==3.1.0.post1
- sudo apt-get install libhdf5-dev
- sudo apt-get install python-h5py
## Building
- remember WITH_PYTHON_LAYER := 1 !
- make all
- make pycaffe

## Training
- download data and models from http://www.eecs.berkeley.edu/~lisa_anne/LRCN_video,
- create flow frame using python instead of matlab like below
https://github.com/pathak22/pyflow
git clone https://github.com/pathak22/pyflow.git
cd pyflow/
python setup.py build_ext -i
python demo.py # -viz option to visualize output
- change my path like '/home/link/frames' in sequence_input_layer.py to your path and modify other relative path.
- bash run_lstm_flow.sh, start training!






8 changes: 4 additions & 4 deletions examples/LRCN_activity_recognition/sequence_input_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import skimage.io
import copy

flow_frames = 'flow_images/'
RGB_frames = 'frames/'
flow_frames = '/home/link/flow_images/'
RGB_frames = '/home/link/frames/'
test_frames = 16
train_frames = 16
test_buffer = 3
Expand Down Expand Up @@ -174,11 +174,11 @@ def setup(self, bottom, top):
if self.flow:
image_mean = [128, 128, 128]
# TODO: No flow support in transformer currently
# self.transformer.set_is_flow('data_in', True)
self.transformer.set_is_flow('data_in', True)
else:
image_mean = [103.939, 116.779, 128.68]
# TODO: No flow support in transformer currently
# self.transformer.set_is_flow('data_in', False)
self.transformer.set_is_flow('data_in', False)
channel_mean = np.zeros((3,227,227))
for channel_index, mean_val in enumerate(image_mean):
channel_mean[channel_index, ...] = mean_val
Expand Down

0 comments on commit f6a2a6b

Please sign in to comment.