@@ -12,6 +12,7 @@ option(USE_CAFFE "set use caffe model as input or not" OFF)
1212option (USE_ONNX "set use onnx model as input or not" OFF )
1313option (USE_TFLITE "set use tflite model as input or not" OFF )
1414option (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
1718option (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)
2627option (USE_OPENMP "set use openmp to run test(tinybert) or not" OFF )
2728
2829option (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 )
2935option (USE_FLOW "set whether to use flow or not" OFF )
3036
3137option (USE_JNI "set whether to use Java API or not" OFF )
3238
3339option (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+
3547function (set_policy)
3648 if (POLICY CMP0074)
3749 cmake_policy (SET CMP0074 NEW)
3850 endif ()
3951endfunction (set_policy)
4052
4153macro (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)
168198macro (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)
219257endif ()
220258
221259macro (include_uni)
222260 include_directories (${BOLT_ROOT} /common/uni/include )
261+ if (USE_SECURE_C)
262+ include_directories (${SecureC_ROOT} /include )
263+ endif ()
223264endmacro ()
224265
225266macro (link_uni name )
226267 target_link_libraries (${name} ${uni_library} )
268+ if (USE_SECURE_C)
269+ target_link_libraries (${name} ${SecureC_LIBRARY} )
270+ endif ()
227271endmacro ()
228272
229273macro (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} )
0 commit comments