Opencl - half floating point support and introduce layer fusion for inference #5745

Open
wants to merge 33 commits into
from
Commits
Jump to file or symbol
Failed to load files and symbols.
+16,321 −2,962
Split
View
@@ -185,6 +185,10 @@ if (USE_ISAAC)
endif()
list(APPEND Caffe_LINKER_LIBS PUBLIC ${ISAAC_LIBRARY})
list(APPEND Caffe_DEFINITIONS PUBLIC -DUSE_CLBLAS)
+ if (USE_GREENTEA AND NOT USE_CUDA)
+ message(STATUS "Enable half floating point supprot.")
+ list(APPEND Caffe_DEFINITIONS PUBLIC -DHAS_HALF_SUPPORT)
+ endif()
endif()
# ---[ CLBlast
@@ -14,7 +14,7 @@
# ---[ Options
-caffe_option(MKL_USE_SINGLE_DYNAMIC_LIBRARY "Use single dynamic library interface" ON)
+caffe_option(MKL_USE_SINGLE_DYNAMIC_LIBRARY "Use single dynamic library interface" OFF)
caffe_option(MKL_USE_STATIC_LIBS "Use static libraries" OFF IF NOT MKL_USE_SINGLE_DYNAMIC_LIBRARY)
caffe_option(MKL_MULTI_THREADED "Use multi-threading" ON IF NOT MKL_USE_SINGLE_DYNAMIC_LIBRARY)
@@ -10,8 +10,9 @@
/* This is an absolute path so that we can run test from any build
* directory */
#define ABS_TEST_DATA_DIR "${PROJECT_SOURCE_DIR}/src/caffe/test/test_data/"
+#define EXAMPLES_SOURCE_DIR "${PROJECT_SOURCE_DIR}/examples/"
/* Test device */
#define CUDA_TEST_DEVICE ${CUDA_TEST_DEVICE}
-#endif // CAFFE_CONFIG_HPP_
+#endif // CAFFE_CONFIG_HPP_
View
@@ -8,6 +8,7 @@ set(LINT_COMMAND ${python_executable} ${CMAKE_SOURCE_DIR}/scripts/cpp_lint.py)
set(SRC_FILE_EXTENSIONS h hpp hu c cpp cu cc)
set(EXCLUDE_FILE_EXTENSTIONS pb.h pb.cc)
set(LINT_DIRS include src/caffe examples tools python matlab)
+set(EXCLUDE_DIRS include/3rdparty)
cmake_policy(SET CMP0009 NEW) # suppress cmake warning
@@ -25,6 +26,11 @@ foreach(ext ${EXCLUDE_FILE_EXTENSTIONS})
set(EXCLUDED_FILES ${EXCLUDED_FILES} ${FOUND_FILES})
endforeach()
+foreach(dir ${EXCLUDE_DIRS})
+ file(GLOB_RECURSE FOUND_FILES ${CMAKE_SOURCE_DIR}/${dir}/*.*)
+ set(EXCLUDED_FILES ${EXCLUDED_SOURCES} ${FOUND_FILES})
+endforeach()
+
# exclude generated pb files
if(EXCLUDED_FILES)
list(REMOVE_ITEM LINT_SOURCES ${EXCLUDED_FILES})
@@ -0,0 +1,20 @@
+#!/bin/sh
+export CAFFE_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"/../..
+export PYTHONPATH=$CAFFE_ROOT/"python"
+# generate new fused model
+python $CAFFE_ROOT/tools/inference-optimize/model_fuse.py \
+ --indefinition $CAFFE_ROOT/models/bvlc_googlenet/deploy.prototxt \
+ --inmodel $CAFFE_ROOT/models/bvlc_googlenet/bvlc_googlenet.caffemodel \
+ --outdefinition $CAFFE_ROOT/models/bvlc_googlenet/fused_deploy.prototxt \
+ --outmodel $CAFFE_ROOT/models/bvlc_googlenet/fused_bvlc_googlenet.caffemodel \
+ --half_precision_mode=HALF_NONE \
+
+#Use cpp_classfication to test
+$CAFFE_ROOT/build/examples/cpp_classification/classification.bin \
+ $CAFFE_ROOT/models/bvlc_googlenet/fused_deploy.prototxt \
+ $CAFFE_ROOT/models/bvlc_googlenet/fused_bvlc_googlenet.caffemodel \
+ $CAFFE_ROOT/data/ilsvrc12/imagenet_mean.binaryproto \
+ $CAFFE_ROOT/data/ilsvrc12/synset_words.txt \
+ $CAFFE_ROOT/examples/images/cat.jpg
+
+
@@ -0,0 +1,18 @@
+# Using model fuse to run inference-ontpimzed caffe
+
+The example use fused-model prototxt and weightfile to using layer-fused classification.
+
+Take googlenet as an example:
+
+1. Download GoogleNet model form "Model Zoo" using following script:
+```
+ $CAFFE_ROOT/scripts/download_model_binary.py models/bvlc_googlenet
+```
+2. ImageNet label file required by:
+```
+ $CAFFE_ROOT/data/ilsvrc12/get_ilsvrc_aux.sh
+```
+3. Use model_fuse.py to generate fused model and cpp_classifcation to test the clasify funtionality with script:
+```
+ ./googlenet_inference_test.sh
+```
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (c) 2012-2017 Christian Rau
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
Oops, something went wrong.