Skip to content

Commit c3eb7a2

Browse files
committed
Merge branch 'v1.3.0_beta'
2 parents 2c022c5 + a9fb901 commit c3eb7a2

File tree

1,740 files changed

+202072
-24795
lines changed

Some content is hidden

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

1,740 files changed

+202072
-24795
lines changed

.Doxyfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -771,8 +771,11 @@ WARN_LOGFILE =
771771
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
772772
# Note: If this tag is empty the current directory is searched.
773773

774-
INPUT = ./inference/engine/api ./inference/flow/include/flow.h \
775-
./common/uni/include/task.h ./inference/flow/src/flow.proto
774+
INPUT = ./inference/engine/api/c \
775+
./inference/engine/api/java \
776+
./inference/flow/include/flow.h ./common/uni/include/task.h ./inference/flow/src/flow.proto \
777+
./training/api/training/api/API.h \
778+
./training/demos/common/training.h
776779

777780
# This tag can be used to specify the character encoding of the source files
778781
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ kit/Android/SimpleImageClassification/app/src/main/java
5353
kit/iOS/SimpleImgClassfication/libbolt
5454
kit/Android/Semantics/app/src/main/java
5555
kit/Android/Semantics/app/src/main/assets/
56+
kit/Android
57+
kit/iOS
5658

5759

5860
final_combinations.txt

CMakeLists.txt

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ if (NOT "$ENV{JNI_ROOT}" STREQUAL "")
2525
set(USE_JNI ON)
2626
endif(JNI_FOUND)
2727
endif ()
28+
if (USE_SECURE_C)
29+
find_package(SecureC)
30+
endif ()
2831
if (BUILD_TEST)
2932
find_package(jpeg)
3033
if (EXISTS ${OpenCV_CMAKE_PATH})
@@ -33,7 +36,7 @@ if (BUILD_TEST)
3336
endif (BUILD_TEST)
3437

3538
add_subdirectory(common)
36-
if (USE_CAFFE OR USE_ONNX OR USE_TFLITE OR USE_TENSORFLOW)
39+
if (USE_CAFFE OR USE_ONNX OR USE_TFLITE OR USE_TENSORFLOW OR USE_MINDSPORE)
3740
add_subdirectory(model_tools)
3841
endif()
3942
add_subdirectory(compute)
@@ -45,6 +48,13 @@ message(STATUS "CXXFLAGS: ${CMAKE_CXX_FLAGS}")
4548
add_custom_target(bolt_library ALL
4649
COMMAND bash ./scripts/build_light_bolt.sh ${CMAKE_SYSTEM_NAME} ${CMAKE_CXX_COMPILER} ${CMAKE_AR} ${CMAKE_STRIP} ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_OUTPUT_EXTENSION} ${CMAKE_SHARED_LIBRARY_PREFIX} ${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_PREFIX} ${CMAKE_STATIC_LIBRARY_SUFFIX} ${CMAKE_BINARY_DIR}
4750
WORKING_DIRECTORY ${BOLT_ROOT})
51+
if (USE_TRAINING)
52+
set(TRAINING_BUILD_C_API ON)
53+
set(TRAINING_BUILD_DEMO ON)
54+
add_subdirectory(training)
55+
add_dependencies(Raul blas_enhance uni)
56+
add_dependencies(Raul blas_enhance_static uni_static)
57+
endif (USE_TRAINING)
4858
add_dependencies(bolt_library engine model_spec tensor image blas_enhance uni)
4959
add_dependencies(bolt_library engine_static model_spec_static tensor_static image_static blas_enhance_static uni_static)
5060

@@ -70,11 +80,30 @@ endif ()
7080
enable_testing()
7181
find_program (BASH_PROGRAM bash)
7282
if (BASH_PROGRAM AND USE_GENERAL)
83+
file(GLOB CPUINFO_CMAKE_FILE $ENV{BOLT_ROOT}/common/cmakes/cpuinfo.cmake ${BOLT_ROOT}/common/cmakes/cpuinfo.cmake)
84+
include(${CPUINFO_CMAKE_FILE})
7385
set(parameters --host_dir=${CMAKE_INSTALL_PREFIX})
7486
if (ANDROID)
7587
set(parameters ${parameters} -d android --device_dir=/data/local/tmp/uldra)
7688
elseif("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "${CMAKE_SYSTEM_PROCESSOR}" AND "${CMAKE_HOST_SYSTEM}" MATCHES "${CMAKE_SYSTEM_NAME}*")
77-
set(parameters ${parameters} -d host)
89+
if ("${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "aarch64" OR "${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "armv7")
90+
set(parameters ${parameters} -d host)
91+
elseif (USE_X86)
92+
set(x86_test ${cpuinfo_avx2})
93+
if (USE_INT8)
94+
set(x86_test ${cpuinfo_avx512})
95+
endif ()
96+
if (USE_AVX512_VNNI)
97+
set(x86_test ${cpuinfo_avx512_vnni})
98+
endif()
99+
if (x86_test)
100+
set(parameters ${parameters} -d host)
101+
else ()
102+
set(parameters ${parameters} -d unknown)
103+
endif ()
104+
else ()
105+
set(parameters ${parameters} -d unknown)
106+
endif()
78107
else()
79108
set(parameters ${parameters} -d unknown)
80109
endif()

README.md

Lines changed: 70 additions & 33 deletions
Large diffs are not rendered by default.

SUMMARY.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Summary
2+
3+
* [Introduction](README.md)
4+
5+
6+
* [Architechture](docs/ARCHITECTURE.md)
7+
8+
9+
* [Operators](docs/OPERATORS.md)
10+
11+
12+
* [Install](docs/INSTALL.md)
13+
14+
15+
* [Basic Inference Usage](docs/USER_HANDBOOK.md#basic-usage)
16+
17+
18+
* [Basic On-device Training Usage](training/TUTORIAL.md)
19+
20+
21+
* [Advanced Features](docs/USER_HANDBOOK.md#advanced-features)
22+
23+
24+
* [Developer Customization](docs/DEVELOPER.md)
25+
26+
27+
* [How to Reduce GPU Initial Time](docs/REDUCE_GPU_PREPARE_TIME.md)
28+
29+
30+
* [Kit Example](docs/KIT.md)
31+
32+
33+
* [Changelog](docs/CHANGELOG.md)
34+
35+
36+
* [FAQ](docs/FAQ.md)
37+
38+
39+
* [Feedback](docs/FEEDBACK.md)
40+
41+
42+
* [Appendix](docs/IOS_USAGE.md)

book.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"plugins": [
3+
"github",
4+
"back-to-top-button",
5+
"page-toc-button",
6+
"insert-logo"
7+
],
8+
9+
"pluginsConfig": {
10+
"github": {
11+
"url": "https://github.com/huawei-noah/bolt"
12+
},
13+
"page-toc-button": {
14+
"maxTocDepth": 1,
15+
"minTocSize": 2
16+
},
17+
"insert-logo":{
18+
"url":"../docs/images/LOGO.PNG",
19+
"style":"background:none;max-height:100px"
20+
}
21+
}
22+
}

common/cmakes/FindSecureC.cmake

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
find_path(SecureC_INCLUDE_DIR NAMES securec.h HINTS $ENV{SecureC_ROOT}/include ${SecureC_ROOT}/include)
2+
3+
if (USE_DYNAMIC_LIBRARY)
4+
find_library(SecureC_LIBRARY NAMES securec HINTS $ENV{SecureC_ROOT}/lib ${SecureC_ROOT}/lib)
5+
set(SecureC_SHARED_LIBRARY ${SecureC_LIBRARY})
6+
else (USE_DYNAMIC_LIBRARY)
7+
find_library(SecureC_LIBRARY NAMES ${CMAKE_STATIC_LIBRARY_PREFIX}securec${CMAKE_STATIC_LIBRARY_SUFFIX} HINTS $ENV{SecureC_ROOT}/lib ${SecureC_ROOT}/lib)
8+
find_library(SecureC_SHARED_LIBRARY NAMES securec HINTS $ENV{SecureC_ROOT}/lib ${SecureC_ROOT}/lib)
9+
endif (USE_DYNAMIC_LIBRARY)
10+
11+
if (SecureC_INCLUDE_DIR AND SecureC_LIBRARY)
12+
set(SecureC_FOUND true)
13+
endif (SecureC_INCLUDE_DIR AND SecureC_LIBRARY)
14+
15+
if (SecureC_FOUND)
16+
include_directories(${SecureC_INCLUDE_DIR})
17+
message(STATUS "Found securec.h: ${SecureC_INCLUDE_DIR}")
18+
message(STATUS "Found securec: ${SecureC_LIBRARY}")
19+
else (SecureC_FOUND)
20+
message(FATAL_ERROR "
21+
FATAL: can not find securec library in <SecureC_ROOT>/[include|lib] directory,
22+
please set shell environment variable SecureC_ROOT.
23+
")
24+
endif (SecureC_FOUND)

common/cmakes/bolt.cmake

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ option(USE_CAFFE "set use caffe model as input or not" OFF)
1212
option(USE_ONNX "set use onnx model as input or not" OFF)
1313
option(USE_TFLITE "set use tflite model as input or not" OFF)
1414
option(USE_TENSORFLOW "set use tensorflow model as input or not" OFF)
15+
option(USE_MINDSPORE "set use mindspore model as input or not" OFF)
1516

1617
# blas_enhance tensor
1718
option(USE_GENERAL "set use CPU serial code or not" OFF)
@@ -26,28 +27,43 @@ option(USE_INT8_WINOGRAD "set use ARM NEON INT8 winograd" ON)
2627
option(USE_OPENMP "set use openmp to run test(tinybert) or not" OFF)
2728

2829
option(USE_LIBRARY_TUNING "set use algorithm tuning or not" OFF)
30+
option(USE_MEM_CHECK "set to use memory check or not" OFF)
31+
option(USE_MODEL_PRINT "set to use model print or not" ON)
32+
option(USE_SECURE_C "set to use Huawei Secure C or not" OFF)
33+
34+
option(USE_TRAINING "set whether to use training or not" OFF)
2935
option(USE_FLOW "set whether to use flow or not" OFF)
3036

3137
option(USE_JNI "set whether to use Java API or not" OFF)
3238

3339
option(BUILD_TEST "set to build unit test or not" OFF)
3440

41+
include(CheckCXXCompilerFlag)
42+
43+
if (USE_TRAINING)
44+
set(ANDROID_TOOLCHAIN_PREFIX "aarch64-linux-android-")
45+
endif(USE_TRAINING)
46+
3547
function (set_policy)
3648
if (POLICY CMP0074)
3749
cmake_policy(SET CMP0074 NEW)
3850
endif()
3951
endfunction(set_policy)
4052

4153
macro (set_c_cxx_flags)
42-
set(COMMON_FLAGS "-W -Wextra -O3 -fPIC")
43-
if (NOT WIN32)
44-
set(COMMON_FLAGS "${COMMON_FLAGS} -fstack-protector-all")
45-
endif()
54+
set(COMMON_FLAGS "-O3 -fPIC -fPIE")
55+
# warning flag can be remove in release version
56+
set(COMMON_FLAGS "${COMMON_FLAGS} -W -Wextra")
57+
set(COMMON_FLAGS "${COMMON_FLAGS} -fstack-protector-all -fstack-protector-strong")
4658
set(COMMON_FLAGS "${COMMON_FLAGS} -Wno-unused-command-line-argument -Wno-unused-parameter")
4759
set(COMMON_FLAGS "${COMMON_FLAGS} -Wno-unused-result -Wno-deprecated-declarations -Wno-unused-variable")
4860

4961
if (USE_OPENMP)
5062
set(COMMON_FLAGS "${COMMON_FLAGS} -D_USE_OPENMP -fopenmp")
63+
CHECK_CXX_COMPILER_FLAG("-static-openmp" COMPILER_SUPPORTS_STATIC_OPENMP)
64+
if (COMPILER_SUPPORTS_STATIC_OPENMP)
65+
set(COMMON_FLAGS "${COMMON_FLAGS} -static-openmp")
66+
endif ()
5167
endif(USE_OPENMP)
5268

5369
if (USE_THREAD_SAFE OR USE_CAFFE OR USE_ONNX OR USE_FLOW)
@@ -99,27 +115,29 @@ macro (set_c_cxx_flags)
99115
if (USE_INT8)
100116
set(COMMON_FLAGS "${COMMON_FLAGS} -mavx512f")
101117
endif (USE_INT8)
102-
if (USE_AVX512_VNNI)
118+
if (USE_AVX512_VNNI)
103119
set(COMMON_FLAGS "${COMMON_FLAGS} -D_USE_AVX512_VNNI")
104-
endif(USE_AVX512_VNNI)
120+
endif(USE_AVX512_VNNI)
105121
endif(USE_X86)
106122

107123
if (USE_FP32)
108124
set(COMMON_FLAGS "${COMMON_FLAGS} -D_USE_FP32")
109125
endif (USE_FP32)
110126

127+
if (USE_FP16)
128+
set(COMMON_FLAGS "${COMMON_FLAGS} -D_USE_FP16")
129+
if (USE_F16_MIX_PRECISION)
130+
set(COMMON_FLAGS "${COMMON_FLAGS} -D_USE_F16_MIX_PRECISION")
131+
endif (USE_F16_MIX_PRECISION)
132+
endif ()
133+
111134
if (USE_INT8)
112135
set(COMMON_FLAGS "${COMMON_FLAGS} -D_USE_INT8")
113136
endif (USE_INT8)
114137

115138
if (USE_NEON)
116139
set(COMMON_FLAGS "${COMMON_FLAGS} -D_USE_NEON")
117-
118140
if (USE_FP16)
119-
set(COMMON_FLAGS "${COMMON_FLAGS} -D_USE_FP16")
120-
if (USE_F16_MIX_PRECISION)
121-
set(COMMON_FLAGS "${COMMON_FLAGS} -D_USE_F16_MIX_PRECISION")
122-
endif (USE_F16_MIX_PRECISION)
123141
if (USE_INT8)
124142
if (USE_INT8_WINOGRAD)
125143
set(COMMON_FLAGS "${COMMON_FLAGS} -D_USE_INT8_WINOGRAD")
@@ -137,9 +155,6 @@ macro (set_c_cxx_flags)
137155
endif ()
138156
endif (USE_INT8)
139157
endif (USE_FP16)
140-
if (USE_INT8)
141-
set(COMMON_FLAGS "${COMMON_FLAGS} -D_USE_INT8")
142-
endif ()
143158
endif(USE_NEON)
144159

145160
if (USE_CAFFE)
@@ -154,6 +169,21 @@ macro (set_c_cxx_flags)
154169
if (USE_TENSORFLOW)
155170
set(COMMON_FLAGS "${COMMON_FLAGS} -D_USE_TENSORFLOW")
156171
endif()
172+
if (USE_MINDSPORE)
173+
set(COMMON_FLAGS "${COMMON_FLAGS} -D_USE_MINDSPORE")
174+
endif()
175+
176+
if (USE_MEM_CHECK)
177+
set(COMMON_FLAGS "${COMMON_FLAGS} -D_USE_MEM_CHECK")
178+
endif()
179+
180+
if (USE_MODEL_PRINT)
181+
set(COMMON_FLAGS "${COMMON_FLAGS} -D_USE_MODEL_PRINT")
182+
endif()
183+
184+
if (USE_SECURE_C)
185+
set(COMMON_FLAGS "${COMMON_FLAGS} -D_USE_SECURE_C")
186+
endif()
157187

158188
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAGS} -std=gnu99")
159189
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_FLAGS} -std=c++11")
@@ -168,8 +198,14 @@ endmacro(set_c_cxx_flags)
168198
macro (set_test_c_cxx_flags)
169199
if (NOT USE_DYNAMIC_LIBRARY)
170200
set(COMMON_FLAGS "${COMMON_FLAGS} -static-libstdc++")
171-
if (NOT "${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "${CMAKE_SYSTEM_PROCESSOR}" AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
172-
set(COMMON_FLAGS "${COMMON_FLAGS} -static")
201+
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
202+
set(COMMON_FLAGS "${COMMON_FLAGS} -static-libgcc")
203+
if (NOT "${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "${CMAKE_SYSTEM_PROCESSOR}")
204+
set(COMMON_FLAGS "${COMMON_FLAGS} -static")
205+
endif()
206+
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
207+
set(COMMON_FLAGS "${COMMON_FLAGS} -static")
208+
endif()
173209
endif()
174210
endif()
175211

@@ -198,6 +234,7 @@ if(USE_DYNAMIC_LIBRARY)
198234
set(model_tools_onnx_library model_tools_onnx)
199235
set(model_tools_tflite_library model_tools_tflite)
200236
set(model_tools_tensorflow_library model_tools_tensorflow)
237+
set(model_tools_mindspore_library model_tools_mindspore)
201238
set(model_tools_library model_tools)
202239
set(engine_library engine)
203240
set(flow_library flow)
@@ -213,17 +250,24 @@ else()
213250
set(model_tools_onnx_library model_tools_onnx_static)
214251
set(model_tools_tflite_library model_tools_tflite_static)
215252
set(model_tools_tensorflow_library model_tools_tensorflow_static)
253+
set(model_tools_mindspore_library model_tools_mindspore_static)
216254
set(model_tools_library model_tools_static)
217255
set(engine_library engine_static)
218256
set(flow_library flow_static)
219257
endif()
220258

221259
macro(include_uni)
222260
include_directories(${BOLT_ROOT}/common/uni/include)
261+
if (USE_SECURE_C)
262+
include_directories(${SecureC_ROOT}/include)
263+
endif ()
223264
endmacro()
224265

225266
macro(link_uni name)
226267
target_link_libraries(${name} ${uni_library})
268+
if (USE_SECURE_C)
269+
target_link_libraries(${name} ${SecureC_LIBRARY})
270+
endif ()
227271
endmacro()
228272

229273
macro(include_model_spec)
@@ -330,7 +374,10 @@ macro(link_model_tools name)
330374
target_link_libraries(${name} ${model_tools_tensorflow_library})
331375
target_link_libraries(${name} ${JSONCPP_LIBRARY})
332376
endif()
333-
if(USE_CAFFE OR USE_ONNX)
377+
if(USE_MINDSPORE)
378+
target_link_libraries(${name} ${model_tools_mindspore_library})
379+
endif()
380+
if(USE_CAFFE OR USE_ONNX OR USE_MINDSPORE)
334381
link_protobuf(${name})
335382
endif()
336383
link_model_spec(${name})

common/cmakes/cpuinfo.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
set(CPUINFO "null")
2+
file(GLOB CPUINFO_FILE /proc/cpuinfo)
3+
if (CPUINFO_FILE)
4+
exec_program(cat ARGS ${CPUINFO_FILE} OUTPUT_VARIABLE CPUINFO)
5+
else ()
6+
message(STATUS "can not find /proc/cpuinfo")
7+
endif ()
8+
9+
macro(check_cpuinfo feature)
10+
string(REGEX REPLACE "^.*(${feature}).*$" "\\1" _FEATURE_THERE ${CPUINFO})
11+
string(COMPARE EQUAL "${feature}" "${_FEATURE_THERE}" cpuinfo_${feature})
12+
endmacro()
13+
14+
check_cpuinfo(avx2)
15+
check_cpuinfo(avx512)
16+
check_cpuinfo(avx512_vnni)

0 commit comments

Comments
 (0)