Skip to content

Commit 03d2364

Browse files
committed
Cherry-picked USE_HDF5 from Android branch
1 parent c707aaa commit 03d2364

16 files changed

+79
-1
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ caffe_option(USE_LMDB "Build with lmdb" ON)
4242
caffe_option(ALLOW_LMDB_NOLOCK "Allow MDB_NOLOCK when reading LMDB files (only if necessary)" OFF)
4343
caffe_option(USE_OPENMP "Link with OpenMP (when your BLAS wants OpenMP and you get linker errors)" OFF)
4444

45+
# This code is taken from https://github.com/sh1r0/caffe-android-lib
46+
caffe_option(USE_HDF5 "Build with hdf5" ON)
47+
4548
# ---[ Dependencies
4649
include(cmake/Dependencies.cmake)
4750

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,13 @@ ifneq ($(CPU_ONLY), 1)
178178
LIBRARIES := cudart cublas curand
179179
endif
180180

181-
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
181+
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m
182182

183183
# handle IO dependencies
184184
USE_LEVELDB ?= 1
185185
USE_LMDB ?= 1
186+
# This code is taken from https://github.com/sh1r0/caffe-android-lib
187+
USE_HDF5 ?= 1
186188
USE_OPENCV ?= 1
187189

188190
ifeq ($(USE_LEVELDB), 1)
@@ -191,6 +193,10 @@ endif
191193
ifeq ($(USE_LMDB), 1)
192194
LIBRARIES += lmdb
193195
endif
196+
# This code is taken from https://github.com/sh1r0/caffe-android-lib
197+
ifeq ($(USE_HDF5), 1)
198+
LIBRARIES += hdf5_hl hdf5
199+
endif
194200
ifeq ($(USE_OPENCV), 1)
195201
LIBRARIES += opencv_core opencv_highgui opencv_imgproc
196202

@@ -347,6 +353,10 @@ ifeq ($(ALLOW_LMDB_NOLOCK), 1)
347353
COMMON_FLAGS += -DALLOW_LMDB_NOLOCK
348354
endif
349355
endif
356+
# This code is taken from https://github.com/sh1r0/caffe-android-lib
357+
ifeq ($(USE_HDF5), 1)
358+
COMMON_FLAGS += -DUSE_HDF5
359+
endif
350360

351361
# CPU-only configuration
352362
ifeq ($(CPU_ONLY), 1)

Makefile.config.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# USE_OPENCV := 0
1212
# USE_LEVELDB := 0
1313
# USE_LMDB := 0
14+
# This code is taken from https://github.com/sh1r0/caffe-android-lib
15+
# USE_HDF5 := 0
1416

1517
# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
1618
# You should not set this flag if you will be reading LMDBs with any

cmake/ConfigGen.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ function(caffe_generate_export_configs)
2424
set(HAVE_CUDA FALSE)
2525
endif()
2626

27+
set(HDF5_IMPORTED OFF)
28+
foreach(_lib ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES})
29+
if(TARGET ${_lib})
30+
set(HDF5_IMPORTED ON)
31+
endif()
32+
endforeach()
33+
34+
# This code is taken from https://github.com/sh1r0/caffe-android-lib
35+
if(USE_HDF5)
36+
list(APPEND Caffe_DEFINITIONS -DUSE_HDF5)
37+
endif()
38+
2739
if(NOT HAVE_CUDNN)
2840
set(HAVE_CUDNN FALSE)
2941
endif()

cmake/Dependencies.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ find_package(HDF5 COMPONENTS HL REQUIRED)
4747
list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${HDF5_INCLUDE_DIRS})
4848
list(APPEND Caffe_LINKER_LIBS PUBLIC ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES})
4949

50+
# This code is taken from https://github.com/sh1r0/caffe-android-lib
51+
if(USE_HDF5)
52+
find_package(HDF5 COMPONENTS HL REQUIRED)
53+
include_directories(SYSTEM ${HDF5_INCLUDE_DIRS} ${HDF5_HL_INCLUDE_DIR})
54+
list(APPEND Caffe_LINKER_LIBS ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES})
55+
add_definitions(-DUSE_HDF5)
56+
endif()
57+
5058
# ---[ LMDB
5159
if(USE_LMDB)
5260
find_package(LMDB REQUIRED)

cmake/Summary.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ function(caffe_print_configuration_summary)
119119
caffe_status(" USE_LMDB : ${USE_LMDB}")
120120
caffe_status(" USE_NCCL : ${USE_NCCL}")
121121
caffe_status(" ALLOW_LMDB_NOLOCK : ${ALLOW_LMDB_NOLOCK}")
122+
# This code is taken from https://github.com/sh1r0/caffe-android-lib
123+
caffe_status(" USE_HDF5 : ${USE_HDF5}")
122124
caffe_status("")
123125
caffe_status("Dependencies:")
124126
caffe_status(" BLAS : " APPLE THEN "Yes (vecLib)" ELSE "Yes (${BLAS})")

include/caffe/util/hdf5.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#ifdef USE_HDF5
12
#ifndef CAFFE_UTIL_HDF5_H_
23
#define CAFFE_UTIL_HDF5_H_
34

@@ -37,3 +38,4 @@ string hdf5_get_name_by_idx(hid_t loc_id, int idx);
3738
} // namespace caffe
3839

3940
#endif // CAFFE_UTIL_HDF5_H_
41+
#endif // USE_HDF5

src/caffe/layers/hdf5_data_layer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#ifdef USE_HDF5
12
/*
23
TODO:
34
- load file in a separate thread ("prefetch")
@@ -184,3 +185,4 @@ INSTANTIATE_CLASS(HDF5DataLayer);
184185
REGISTER_LAYER_CLASS(HDF5Data);
185186

186187
} // namespace caffe
188+
#endif // USE_HDF5

src/caffe/layers/hdf5_data_layer.cu

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#ifdef USE_HDF5
12
/*
23
TODO:
34
- only load parts of the file, in accordance with a prototxt param "max_mem"
@@ -34,3 +35,4 @@ void HDF5DataLayer<Dtype>::Forward_gpu(const vector<Blob<Dtype>*>& bottom,
3435
INSTANTIATE_LAYER_GPU_FUNCS(HDF5DataLayer);
3536

3637
} // namespace caffe
38+
#endif // USE_HDF5

src/caffe/layers/hdf5_output_layer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#ifdef USE_HDF5
12
#include <vector>
23

34
#include "hdf5.h"
@@ -72,3 +73,4 @@ INSTANTIATE_CLASS(HDF5OutputLayer);
7273
REGISTER_LAYER_CLASS(HDF5Output);
7374

7475
} // namespace caffe
76+
#endif // USE_HDF5

0 commit comments

Comments
 (0)