Skip to content

Commit 8cac8c8

Browse files
committed
Merge remote-tracking branch 'refs/remotes/BVLC/master'
2 parents 552a84a + 92dc4e6 commit 8cac8c8

File tree

81 files changed

+2220
-454
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+2220
-454
lines changed

.travis.yml

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
# one using CMake, and one using make.
33
env:
44
matrix:
5-
- WITH_CUDA=false WITH_CMAKE=false
6-
- WITH_CUDA=false WITH_CMAKE=true
7-
- WITH_CUDA=true WITH_CMAKE=false
8-
- WITH_CUDA=true WITH_CMAKE=true
9-
- WITH_CUDA=false WITH_CMAKE=true PYTHON_VERSION=3
5+
- WITH_CUDA=false WITH_CMAKE=false WITH_IO=true
6+
- WITH_CUDA=false WITH_CMAKE=true WITH_IO=true PYTHON_VERSION=3
7+
- WITH_CUDA=true WITH_CMAKE=false WITH_IO=true
8+
- WITH_CUDA=true WITH_CMAKE=true WITH_IO=true
9+
- WITH_CUDA=false WITH_CMAKE=false WITH_IO=false
10+
- WITH_CUDA=false WITH_CMAKE=true WITH_IO=false PYTHON_VERSION=3
1011

1112
language: cpp
1213

CMakeLists.txt

+6-3
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ include(cmake/ConfigGen.cmake)
1616

1717
# ---[ Options
1818
caffe_option(CPU_ONLY "Build Caffe without CUDA support" OFF) # TODO: rename to USE_CUDA
19-
caffe_option(USE_CUDNN "Build Caffe with cuDNN libary support" ON IF NOT CPU_ONLY)
19+
caffe_option(USE_CUDNN "Build Caffe with cuDNN library support" ON IF NOT CPU_ONLY)
2020
caffe_option(BUILD_SHARED_LIBS "Build shared libraries" ON)
2121
caffe_option(BUILD_python "Build Python wrapper" ON)
22-
set(python_version "2" CACHE STRING "Specify which python version to use")
22+
set(python_version "2" CACHE STRING "Specify which Python version to use")
2323
caffe_option(BUILD_matlab "Build Matlab wrapper" OFF IF UNIX OR APPLE)
2424
caffe_option(BUILD_docs "Build documentation" ON IF UNIX OR APPLE)
25-
caffe_option(BUILD_python_layer "Build the Caffe python layer" ON)
25+
caffe_option(BUILD_python_layer "Build the Caffe Python layer" ON)
26+
caffe_option(USE_LMDB "Build with lmdb" ON)
27+
caffe_option(USE_LEVELDB "Build with levelDB" ON)
28+
caffe_option(USE_OPENCV "Build with OpenCV support" ON)
2629

2730
# ---[ Dependencies
2831
include(cmake/Dependencies.cmake)

Makefile

+32-6
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,23 @@ ifneq ($(CPU_ONLY), 1)
169169
LIBRARY_DIRS += $(CUDA_LIB_DIR)
170170
LIBRARIES := cudart cublas curand
171171
endif
172-
LIBRARIES += glog gflags protobuf leveldb snappy \
173-
lmdb boost_system hdf5_hl hdf5 m \
174-
opencv_core opencv_highgui opencv_imgproc
172+
173+
LIBRARIES += glog gflags protobuf boost_system m hdf5_hl hdf5
174+
175+
# handle IO dependencies
176+
USE_LEVELDB ?= 1
177+
USE_LMDB ?= 1
178+
USE_OPENCV ?= 1
179+
180+
ifeq ($(USE_LEVELDB), 1)
181+
LIBRARIES += leveldb snappy
182+
endif
183+
ifeq ($(USE_LMDB), 1)
184+
LIBRARIES += lmdb
185+
endif
186+
ifeq ($(USE_OPENCV), 1)
187+
LIBRARIES += opencv_core opencv_highgui opencv_imgproc
188+
endif
175189
PYTHON_LIBRARIES := boost_python python2.7
176190
WARNINGS := -Wall -Wno-sign-compare
177191

@@ -290,6 +304,17 @@ ifeq ($(USE_CUDNN), 1)
290304
COMMON_FLAGS += -DUSE_CUDNN
291305
endif
292306

307+
# configure IO libraries
308+
ifeq ($(USE_OPENCV), 1)
309+
COMMON_FLAGS += -DUSE_OPENCV
310+
endif
311+
ifeq ($(USE_LEVELDB), 1)
312+
COMMON_FLAGS += -DUSE_LEVELDB
313+
endif
314+
ifeq ($(USE_LMDB), 1)
315+
COMMON_FLAGS += -DUSE_LMDB
316+
endif
317+
293318
# CPU-only configuration
294319
ifeq ($(CPU_ONLY), 1)
295320
OBJS := $(PROTO_OBJS) $(CXX_OBJS)
@@ -329,8 +354,9 @@ else
329354
# OS X packages atlas as the vecLib framework
330355
LIBRARIES += cblas
331356
# 10.10 has accelerate while 10.9 has veclib
332-
XCODE_CLT_VER := $(shell pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep -o 'version: 6')
333-
ifneq (,$(findstring version: 6,$(XCODE_CLT_VER)))
357+
XCODE_CLT_VER := $(shell pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep 'version' | sed 's/[^0-9]*\([0-9]\).*/\1/')
358+
XCODE_CLT_GEQ_6 := $(shell [ $(XCODE_CLT_VER) -gt 5 ] && echo 1)
359+
ifeq ($(XCODE_CLT_GEQ_6), 1)
334360
BLAS_INCLUDE ?= /System/Library/Frameworks/Accelerate.framework/Versions/Current/Frameworks/vecLib.framework/Headers/
335361
LDFLAGS += -framework Accelerate
336362
else
@@ -472,7 +498,7 @@ runtest: $(TEST_ALL_BIN)
472498

473499
pytest: py
474500
cd python; python -m unittest discover -s caffe/test
475-
501+
476502
mattest: mat
477503
cd matlab; $(MATLAB_DIR)/bin/matlab -nodisplay -r 'caffe.run_tests(), exit()'
478504

Makefile.config.example

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
# CPU-only switch (uncomment to build without GPU support).
88
# CPU_ONLY := 1
99

10+
# uncomment to disable IO dependencies and corresponding data layers
11+
# USE_LEVELDB := 0
12+
# USE_LMDB := 0
13+
# USE_OPENCV := 0
14+
1015
# To customize your choice of compiler, uncomment and set the following.
1116
# N.B. the default for Linux is g++ and the default for OSX is clang++
1217
# CUSTOM_CXX := g++

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Caffe
22

3+
[![Build Status](https://travis-ci.org/BVLC/caffe.svg?branch=master)](https://travis-ci.org/BVLC/caffe)
4+
[![License](https://img.shields.io/badge/license-BSD-blue.svg)](LICENSE)
5+
36
Caffe is a deep learning framework made with expression, speed, and modularity in mind.
47
It is developed by the Berkeley Vision and Learning Center ([BVLC](http://bvlc.eecs.berkeley.edu)) and community contributors.
58

cmake/ConfigGen.cmake

+12
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ function(caffe_generate_export_configs)
5656
list(APPEND Caffe_DEFINITIONS -DCPU_ONLY)
5757
endif()
5858

59+
if(USE_OPENCV)
60+
list(APPEND Caffe_DEFINITIONS -DUSE_OPENCV)
61+
endif()
62+
63+
if(USE_LMDB)
64+
list(APPEND Caffe_DEFINITIONS -DUSE_LMDB)
65+
endif()
66+
67+
if(USE_LEVELDB)
68+
list(APPEND Caffe_DEFINITIONS -DUSE_LEVELDB)
69+
endif()
70+
5971
if(NOT HAVE_CUDNN)
6072
set(HAVE_CUDNN FALSE)
6173
else()

cmake/Dependencies.cmake

+26-15
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,27 @@ include_directories(SYSTEM ${HDF5_INCLUDE_DIRS} ${HDF5_HL_INCLUDE_DIR})
2929
list(APPEND Caffe_LINKER_LIBS ${HDF5_LIBRARIES})
3030

3131
# ---[ LMDB
32-
find_package(LMDB REQUIRED)
33-
include_directories(SYSTEM ${LMDB_INCLUDE_DIR})
34-
list(APPEND Caffe_LINKER_LIBS ${LMDB_LIBRARIES})
32+
if(USE_LMDB)
33+
find_package(LMDB REQUIRED)
34+
include_directories(SYSTEM ${LMDB_INCLUDE_DIR})
35+
list(APPEND Caffe_LINKER_LIBS ${LMDB_LIBRARIES})
36+
add_definitions(-DUSE_LMDB)
37+
endif()
3538

3639
# ---[ LevelDB
37-
find_package(LevelDB REQUIRED)
38-
include_directories(SYSTEM ${LevelDB_INCLUDE})
39-
list(APPEND Caffe_LINKER_LIBS ${LevelDB_LIBRARIES})
40+
if(USE_LEVELDB)
41+
find_package(LevelDB REQUIRED)
42+
include_directories(SYSTEM ${LevelDB_INCLUDE})
43+
list(APPEND Caffe_LINKER_LIBS ${LevelDB_LIBRARIES})
44+
add_definitions(-DUSE_LEVELDB)
45+
endif()
4046

4147
# ---[ Snappy
42-
find_package(Snappy REQUIRED)
43-
include_directories(SYSTEM ${Snappy_INCLUDE_DIR})
44-
list(APPEND Caffe_LINKER_LIBS ${Snappy_LIBRARIES})
48+
if(USE_LEVELDB)
49+
find_package(Snappy REQUIRED)
50+
include_directories(SYSTEM ${Snappy_INCLUDE_DIR})
51+
list(APPEND Caffe_LINKER_LIBS ${Snappy_LIBRARIES})
52+
endif()
4553

4654
# ---[ CUDA
4755
include(cmake/Cuda.cmake)
@@ -57,13 +65,16 @@ if(NOT HAVE_CUDA)
5765
endif()
5866

5967
# ---[ OpenCV
60-
find_package(OpenCV QUIET COMPONENTS core highgui imgproc imgcodecs)
61-
if(NOT OpenCV_FOUND) # if not OpenCV 3.x, then imgcodecs are not found
62-
find_package(OpenCV REQUIRED COMPONENTS core highgui imgproc)
68+
if(USE_OPENCV)
69+
find_package(OpenCV QUIET COMPONENTS core highgui imgproc imgcodecs)
70+
if(NOT OpenCV_FOUND) # if not OpenCV 3.x, then imgcodecs are not found
71+
find_package(OpenCV REQUIRED COMPONENTS core highgui imgproc)
72+
endif()
73+
include_directories(SYSTEM ${OpenCV_INCLUDE_DIRS})
74+
list(APPEND Caffe_LINKER_LIBS ${OpenCV_LIBS})
75+
message(STATUS "OpenCV found (${OpenCV_CONFIG_PATH})")
76+
add_definitions(-DUSE_OPENCV)
6377
endif()
64-
include_directories(SYSTEM ${OpenCV_INCLUDE_DIRS})
65-
list(APPEND Caffe_LINKER_LIBS ${OpenCV_LIBS})
66-
message(STATUS "OpenCV found (${OpenCV_CONFIG_PATH})")
6778

6879
# ---[ BLAS
6980
if(NOT APPLE)

cmake/Summary.cmake

+13-5
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,26 @@ function(caffe_print_configuration_summary)
114114
caffe_status(" BUILD_matlab : ${BUILD_matlab}")
115115
caffe_status(" BUILD_docs : ${BUILD_docs}")
116116
caffe_status(" CPU_ONLY : ${CPU_ONLY}")
117+
caffe_status(" USE_LMDB : ${USE_LMDB}")
118+
caffe_status(" USE_LEVELDB : ${USE_LEVELDB}")
119+
caffe_status(" USE_OPENCV : ${USE_OPENCV}")
117120
caffe_status("")
118121
caffe_status("Dependencies:")
119122
caffe_status(" BLAS : " APPLE THEN "Yes (vecLib)" ELSE "Yes (${BLAS})")
120123
caffe_status(" Boost : Yes (ver. ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION})")
121124
caffe_status(" glog : Yes")
122125
caffe_status(" gflags : Yes")
123126
caffe_status(" protobuf : " PROTOBUF_FOUND THEN "Yes (ver. ${PROTOBUF_VERSION})" ELSE "No" )
124-
caffe_status(" lmdb : " LMDB_FOUND THEN "Yes (ver. ${LMDB_VERSION})" ELSE "No")
125-
caffe_status(" Snappy : " SNAPPY_FOUND THEN "Yes (ver. ${Snappy_VERSION})" ELSE "No" )
126-
caffe_status(" LevelDB : " LEVELDB_FOUND THEN "Yes (ver. ${LEVELDB_VERSION})" ELSE "No")
127-
caffe_status(" OpenCV : Yes (ver. ${OpenCV_VERSION})")
127+
if(USE_LMDB)
128+
caffe_status(" lmdb : " LMDB_FOUND THEN "Yes (ver. ${LMDB_VERSION})" ELSE "No")
129+
endif()
130+
if(USE_LEVELDB)
131+
caffe_status(" LevelDB : " LEVELDB_FOUND THEN "Yes (ver. ${LEVELDB_VERSION})" ELSE "No")
132+
caffe_status(" Snappy : " SNAPPY_FOUND THEN "Yes (ver. ${Snappy_VERSION})" ELSE "No" )
133+
endif()
134+
if(USE_OPENCV)
135+
caffe_status(" OpenCV : Yes (ver. ${OpenCV_VERSION})")
136+
endif()
128137
caffe_status(" CUDA : " HAVE_CUDA THEN "Yes (ver. ${CUDA_VERSION})" ELSE "No" )
129138
caffe_status("")
130139
if(HAVE_CUDA)
@@ -165,4 +174,3 @@ function(caffe_print_configuration_summary)
165174
caffe_status(" Install path : ${CMAKE_INSTALL_PREFIX}")
166175
caffe_status("")
167176
endfunction()
168-

cmake/Templates/CaffeConfig.cmake.in

+14-12
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,24 @@
1717
# Caffe_HAVE_CUDNN - signals about cuDNN support
1818

1919

20-
# OpenCV dependency
20+
# OpenCV dependency (optional)
2121

22-
if(NOT OpenCV_FOUND)
23-
set(Caffe_OpenCV_CONFIG_PATH "@OpenCV_CONFIG_PATH@")
24-
if(Caffe_OpenCV_CONFIG_PATH)
25-
get_filename_component(Caffe_OpenCV_CONFIG_PATH ${Caffe_OpenCV_CONFIG_PATH} ABSOLUTE)
22+
if(@USE_OPENCV@)
23+
if(NOT OpenCV_FOUND)
24+
set(Caffe_OpenCV_CONFIG_PATH "@OpenCV_CONFIG_PATH@")
25+
if(Caffe_OpenCV_CONFIG_PATH)
26+
get_filename_component(Caffe_OpenCV_CONFIG_PATH ${Caffe_OpenCV_CONFIG_PATH} ABSOLUTE)
2627

27-
if(EXISTS ${Caffe_OpenCV_CONFIG_PATH} AND NOT TARGET opencv_core)
28-
message(STATUS "Caffe: using OpenCV config from ${Caffe_OpenCV_CONFIG_PATH}")
29-
include(${Caffe_OpenCV_CONFIG_PATH}/OpenCVModules.cmake)
30-
endif()
28+
if(EXISTS ${Caffe_OpenCV_CONFIG_PATH} AND NOT TARGET opencv_core)
29+
message(STATUS "Caffe: using OpenCV config from ${Caffe_OpenCV_CONFIG_PATH}")
30+
include(${Caffe_OpenCV_CONFIG_PATH}/OpenCVModules.cmake)
31+
endif()
3132

32-
else()
33-
find_package(OpenCV REQUIRED)
33+
else()
34+
find_package(OpenCV REQUIRED)
35+
endif()
36+
unset(Caffe_OpenCV_CONFIG_PATH)
3437
endif()
35-
unset(Caffe_OpenCV_CONFIG_PATH)
3638
endif()
3739

3840
# Compute paths

cmake/Templates/caffe_config.h.in

+5
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@
3030

3131
/* Matlab */
3232
#cmakedefine HAVE_MATLAB
33+
34+
/* IO libraries */
35+
#cmakedefine USE_OPENCV
36+
#cmakedefine USE_LMDB
37+
#cmakedefine USE_LEVELDB

docs/installation.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@ When updating Caffe, it's best to `make clean` before re-compiling.
1717

1818
## Prerequisites
1919

20-
Caffe has several dependencies.
20+
Caffe has several dependencies:
2121

2222
* [CUDA](https://developer.nvidia.com/cuda-zone) is required for GPU mode.
2323
* library version 7.0 and the latest driver version are recommended, but 6.* is fine too
2424
* 5.5, and 5.0 are compatible but considered legacy
2525
* [BLAS](http://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms) via ATLAS, MKL, or OpenBLAS.
2626
* [Boost](http://www.boost.org/) >= 1.55
27+
* `protobuf`, `glog`, `gflags`, `hdf5`
28+
29+
Optional dependencies:
30+
2731
* [OpenCV](http://opencv.org/) >= 2.4 including 3.0
28-
* `protobuf`, `glog`, `gflags`
29-
* IO libraries `hdf5`, `leveldb`, `snappy`, `lmdb`
32+
* IO libraries: `lmdb`, `leveldb` (note: leveldb requires `snappy`)
3033

3134
Pycaffe and Matcaffe interfaces have their own natural needs.
3235

docs/multigpu.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: Multi-GPU Usage, Hardware Configuration Assumptions, and Performance
3+
---
4+
5+
# Multi-GPU Usage
6+
7+
Currently Multi-GPU is only supported via the C/C++ paths and only for training.
8+
9+
The GPUs to be used for training can be set with the "-gpu" flag on the command line to the 'caffe' tool. e.g. "build/tools/caffe train --solver=models/bvlc_alexnet/solver.prototxt --gpu=0,1" will train on GPUs 0 and 1.
10+
11+
**NOTE**: each GPU runs the batchsize specified in your train_val.prototxt. So if you go from 1 GPU to 2 GPU, your effective batchsize will double. e.g. if your train_val.prototxt specified a batchsize of 256, if you run 2 GPUs your effective batch size is now 512. So you need to adjust the batchsize when running multiple GPUs and/or adjust your solver params, specifically learning rate.
12+
13+
# Hardware Configuration Assumptions
14+
15+
The current implementation uses a tree reduction strategy. e.g. if there are 4 GPUs in the system, 0:1, 2:3 will exchange gradients, then 0:2 (top of the tree) will exchange gradients, 0 will calculate
16+
updated model, 0\-\>2, and then 0\-\>1, 2\-\>3.
17+
18+
For best performance, P2P DMA access between devices is needed. Without P2P access, for example crossing PCIe root complex, data is copied through host and effective exchange bandwidth is greatly reduced.
19+
20+
Current implementation has a "soft" assumption that the devices being used are homogeneous. In practice, any devices of the same general class should work together, but performance and total size is limited by the smallest device being used. e.g. if you combine a TitanX and a GTX980, peformance will be limited by the 980. Mixing vastly different levels of boards, e.g. Kepler and Fermi, is not supported.
21+
22+
"nvidia-smi topo -m" will show you the connectivity matrix. You can do P2P through PCIe bridges, but not across socket level links at this time, e.g. across CPU sockets on a multi-socket motherboard.
23+
24+
# Scaling Performance
25+
26+
Performance is **heavily** dependent on the PCIe topology of the system, the configuration of the neural network you are training, and the speed of each of the layers. Systems like the DIGITS DevBox have an optimized PCIe topology (X99-E WS chipset). In general, scaling on 2 GPUs tends to be ~1.8X on average for networks like AlexNet, CaffeNet, VGG, GoogleNet. 4 GPUs begins to have falloff in scaling. Generally with "weak scaling" where the batchsize increases with the number of GPUs you will see 3.5x scaling or so. With "strong scaling", the system can become communication bound, especially with layer performance optimizations like those in [cuDNNv3](http://nvidia.com/cudnn), and you will likely see closer to mid 2.x scaling in performance. Networks that have heavy computation compared to the number of parameters tend to have the best scaling performance.

examples/cpp_classification/classification.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
#include <caffe/caffe.hpp>
2+
#ifdef USE_OPENCV
23
#include <opencv2/core/core.hpp>
34
#include <opencv2/highgui/highgui.hpp>
45
#include <opencv2/imgproc/imgproc.hpp>
6+
#endif // USE_OPENCV
57
#include <algorithm>
68
#include <iosfwd>
79
#include <memory>
810
#include <string>
911
#include <utility>
1012
#include <vector>
1113

14+
#ifdef USE_OPENCV
1215
using namespace caffe; // NOLINT(build/namespaces)
1316
using std::string;
1417

@@ -255,3 +258,8 @@ int main(int argc, char** argv) {
255258
<< p.first << "\"" << std::endl;
256259
}
257260
}
261+
#else
262+
int main(int argc, char** argv) {
263+
LOG(FATAL) << "This example requires OpenCV; compile with USE_OPENCV.";
264+
}
265+
#endif // USE_OPENCV

examples/feature_extraction/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ If you meet with the error "Check failed: status.ok() Failed to open leveldb exa
6464

6565
rm -rf examples/_temp/features/
6666

67-
If you'd like to use the Python wrapper for extracting features, check out the [layer visualization notebook](http://nbviewer.ipython.org/github/BVLC/caffe/blob/master/examples/filter_visualization.ipynb).
67+
If you'd like to use the Python wrapper for extracting features, check out the [filter visualization notebook](http://nbviewer.ipython.org/github/BVLC/caffe/blob/master/examples/00-classification.ipynb).
6868

6969
Clean Up
7070
--------

0 commit comments

Comments
 (0)