1add_compile_definitions(USE_ANDROID_LOG) 2if(MSLITE_ENABLE_V0) 3 add_definitions(-DENABLE_V0) 4endif() 5include_directories(${CCSRC_DIR}/backend/kernel_compiler/cpu) 6 7if(NOT MSLITE_ENABLE_STRING_KERNEL) 8 add_compile_definitions(STRING_KERNEL_CLIP) 9endif() 10if(NOT MSLITE_ENABLE_CONTROLFLOW) 11 add_compile_definitions(CONTROLFLOW_TENSORLIST_CLIP) 12endif() 13if(NOT MSLITE_ENABLE_AUTO_PARALLEL) 14 add_compile_definitions(AUTO_PARALLEL_CLIP) 15endif() 16if(NOT MSLITE_ENABLE_WEIGHT_DECODE) 17 add_compile_definitions(WEIGHT_DECODE_CLIP) 18endif() 19if(NOT MSLITE_ENABLE_CUSTOM_KERNEL) 20 add_compile_definitions(CUSTOM_KERNEL_REGISTRY_CLIP) 21endif() 22if(NOT MSLITE_ENABLE_RUNTIME_PASS) 23 add_compile_definitions(RUNTIME_PASS_CLIP) 24endif() 25if(NOT MSLITE_ENABLE_DELEGATE) 26 add_compile_definitions(DELEGATE_CLIP) 27endif() 28 29if(APPLE OR PLATFORM_ARM32 OR PLATFORM_ARM64) 30 #for performance 31 if("${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND NOT APPLE) 32 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer -fstrict-aliasing -ffunction-sections \ 33 -fdata-sections -ffast-math -fno-rtti -fno-exceptions") 34 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fomit-frame-pointer -fstrict-aliasing -ffunction-sections \ 35 -fdata-sections -ffast-math -fno-rtti -fno-exceptions") 36 if(TARGET_HIMIX200) 37 string(REPLACE "-fno-rtti " "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) 38 endif() 39 endif() 40 if("${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND APPLE) 41 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstrict-aliasing -ffunction-sections \ 42 -fdata-sections -ffast-math -fno-rtti -fno-exceptions -Wno-shorten-64-to-32 \ 43 -fno-aligned-allocation -DTARGET_OS_OSX") 44 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstrict-aliasing -ffunction-sections \ 45 -fdata-sections -ffast-math -fno-rtti -fno-exceptions -Wno-shorten-64-to-32 \ 46 -fno-aligned-allocation -DTARGET_OS_OSX") 47 endif() 48elseif(NOT MSVC) 49 if("${CMAKE_BUILD_TYPE}" STREQUAL "Release") 50 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer -fstrict-aliasing -ffunction-sections \ 51 -fdata-sections -ffast-math -fno-rtti") 52 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fomit-frame-pointer -fstrict-aliasing -ffunction-sections \ 53 -fdata-sections -ffast-math -fno-rtti") 54 endif() 55endif() 56 57file(GLOB CXX_API_SRCS 58 ${CMAKE_CURRENT_SOURCE_DIR}/cxx_api/*.cc 59 ${CMAKE_CURRENT_SOURCE_DIR}/cxx_api/model/*.cc 60 ${CMAKE_CURRENT_SOURCE_DIR}/cxx_api/graph/*.cc 61 ${CMAKE_CURRENT_SOURCE_DIR}/cxx_api/tensor/*.cc 62 ) 63 64file(GLOB C_API_SRCS 65 ${CMAKE_CURRENT_SOURCE_DIR}/c_api/*.cc 66 ) 67 68set(API_SRC 69 ${CORE_DIR}/utils/status.cc 70 ${CXX_API_SRCS} 71 ${C_API_SRCS} 72 ) 73 74file(GLOB CXX_API_TRAIN_SRCS 75 ${CMAKE_CURRENT_SOURCE_DIR}/cxx_api/train/*.cc 76 ${CMAKE_CURRENT_SOURCE_DIR}/cxx_api/metrics/*.cc 77 ${CMAKE_CURRENT_SOURCE_DIR}/cxx_api/callback/*.cc 78 ) 79set(API_TRAIN_SRC 80 ${CXX_API_TRAIN_SRCS} 81 ) 82 83if(SUPPORT_NPU) 84 include_directories(${DDK_PATH}) 85 include_directories(${DDK_INCLUDE_PATH}) 86endif() 87 88set(LITE_SRC 89 ${API_SRC} 90 ${CMAKE_CURRENT_SOURCE_DIR}/common/context_util.cc 91 ${CMAKE_CURRENT_SOURCE_DIR}/common/file_utils.cc 92 ${CMAKE_CURRENT_SOURCE_DIR}/common/config_file.cc 93 ${CMAKE_CURRENT_SOURCE_DIR}/common/utils.cc 94 ${CMAKE_CURRENT_SOURCE_DIR}/common/graph_util.cc 95 ${CMAKE_CURRENT_SOURCE_DIR}/common/log.cc 96 ${CMAKE_CURRENT_SOURCE_DIR}/common/lite_utils.cc 97 ${CMAKE_CURRENT_SOURCE_DIR}/common/prim_util.cc 98 ${CMAKE_CURRENT_SOURCE_DIR}/common/tensor_util.cc 99 ${CMAKE_CURRENT_SOURCE_DIR}/runtime/inner_allocator.cc 100 ${CMAKE_CURRENT_SOURCE_DIR}/runtime/infer_manager.cc 101 ${CMAKE_CURRENT_SOURCE_DIR}/tensor.cc 102 ${CMAKE_CURRENT_SOURCE_DIR}/ms_tensor.cc 103 ${CMAKE_CURRENT_SOURCE_DIR}/executor.cc 104 ${CMAKE_CURRENT_SOURCE_DIR}/inner_context.cc 105 ${CMAKE_CURRENT_SOURCE_DIR}/lite_model.cc 106 ${CMAKE_CURRENT_SOURCE_DIR}/kernel_registry.cc 107 ${CMAKE_CURRENT_SOURCE_DIR}/inner_kernel.cc 108 ${CMAKE_CURRENT_SOURCE_DIR}/lite_kernel.cc 109 ${CMAKE_CURRENT_SOURCE_DIR}/lite_kernel_util.cc 110 ${CMAKE_CURRENT_SOURCE_DIR}/sub_graph_kernel.cc 111 ${CMAKE_CURRENT_SOURCE_DIR}/scheduler.cc 112 ${CMAKE_CURRENT_SOURCE_DIR}/lite_session.cc 113 ${CMAKE_CURRENT_SOURCE_DIR}/errorcode.cc 114 ${CMAKE_CURRENT_SOURCE_DIR}/cpu_info.cc 115 ) 116 117if(MSLITE_ENABLE_STRING_KERNEL) 118 set(LITE_SRC 119 ${LITE_SRC} 120 ${CMAKE_CURRENT_SOURCE_DIR}/common/string_util.cc 121 ) 122endif() 123if(MSLITE_ENABLE_RUNTIME_PASS) 124 set(LITE_SRC 125 ${LITE_SRC} 126 ${CMAKE_CURRENT_SOURCE_DIR}/runtime/runtime_pass.cc 127 ) 128endif() 129 130if(MSLITE_ENABLE_CONTROLFLOW) 131 set(LITE_SRC 132 ${LITE_SRC} 133 ${CMAKE_CURRENT_SOURCE_DIR}/tensorlist.cc 134 ) 135endif() 136 137if(MSLITE_ENABLE_WEIGHT_DECODE) 138 set(LITE_SRC 139 ${LITE_SRC} 140 ${CMAKE_CURRENT_SOURCE_DIR}/huffman_decode.cc 141 ${CMAKE_CURRENT_SOURCE_DIR}/weight_decoder.cc 142 ${CMAKE_CURRENT_SOURCE_DIR}/../tools/converter/quantizer/fse_decoder.cc 143 ${CMAKE_CURRENT_SOURCE_DIR}/../tools/converter/quantizer/fse_bit_stream.cc 144 ) 145endif() 146 147if(MSLITE_ENABLE_AUTO_PARALLEL) 148 set(LITE_SRC 149 ${LITE_SRC} 150 ${CMAKE_CURRENT_SOURCE_DIR}/sub_graph_split.cc 151 ) 152endif() 153 154if(MSLITE_ENABLE_CUSTOM_KERNEL) 155 file(GLOB KERNEL_REG_SRC ${CMAKE_CURRENT_SOURCE_DIR}/registry/*.cc) 156else() 157 set(KERNEL_REG_SRC 158 ${CMAKE_CURRENT_SOURCE_DIR}/registry/register_kernel_interface.cc 159 ${CMAKE_CURRENT_SOURCE_DIR}/registry/register_kernel.cc 160 ) 161endif() 162 163set(LITE_SRC 164 ${LITE_SRC} 165 ${KERNEL_REG_SRC} 166 ) 167 168if(MSLITE_GPU_BACKEND STREQUAL opencl) 169 file(GLOB_RECURSE OPENCL_RUNTIME_SRC 170 ${CMAKE_CURRENT_SOURCE_DIR}/runtime/gpu/opencl/*.cc 171 ) 172 set(LITE_SRC 173 ${LITE_SRC} 174 ${OPENCL_RUNTIME_SRC} 175 ) 176endif() 177 178if(MSLITE_GPU_BACKEND STREQUAL cuda) 179 file(GLOB CUDA_RUNTIME_SRC 180 ${CMAKE_CURRENT_SOURCE_DIR}/runtime/gpu/*.cc 181 ${CMAKE_CURRENT_SOURCE_DIR}/runtime/gpu/cuda/*.cc 182 ) 183 set(LITE_SRC 184 ${LITE_SRC} 185 ${CUDA_RUNTIME_SRC} 186 ) 187endif() 188set(TRAIN_SRC 189 ${API_TRAIN_SRC} 190 ${CMAKE_CURRENT_SOURCE_DIR}/common/quant_utils.cc 191 ${CMAKE_CURRENT_SOURCE_DIR}/train/train_populate_parameter.cc 192 ${CMAKE_CURRENT_SOURCE_DIR}/train/train_session.cc 193 ${CMAKE_CURRENT_SOURCE_DIR}/train/transfer_session.cc 194 ${CMAKE_CURRENT_SOURCE_DIR}/train/train_loop.cc 195 ${CMAKE_CURRENT_SOURCE_DIR}/train/train_utils.cc 196 ${CMAKE_CURRENT_SOURCE_DIR}/train/loss_monitor.cc 197 ${CMAKE_CURRENT_SOURCE_DIR}/train/lr_scheduler.cc 198 ${CMAKE_CURRENT_SOURCE_DIR}/train/accuracy_metrics.cc 199 ${CMAKE_CURRENT_SOURCE_DIR}/train/accuracy_monitor.cc 200 ${CMAKE_CURRENT_SOURCE_DIR}/train/classification_train_accuracy_monitor.cc 201 ${CMAKE_CURRENT_SOURCE_DIR}/train/train_export.cc 202 ${CMAKE_CURRENT_SOURCE_DIR}/train/opt_allocator.cc 203 ${CMAKE_CURRENT_SOURCE_DIR}/../tools/common/storage.cc 204 ) 205if(MSLITE_ENABLE_V0) 206 set(TRAIN_SRC 207 ${TRAIN_SRC} 208 ${CMAKE_CURRENT_SOURCE_DIR}/train/train_populate_parameter_v0.cc 209 ) 210endif() 211 212if(MSLITE_ENABLE_MINDRT) 213 add_subdirectory(${CORE_DIR}/mindrt mindspore_mindrt) 214 set(LITE_SRC ${LITE_SRC} 215 ${CMAKE_CURRENT_SOURCE_DIR}/lite_mindrt.cc 216 ${CMAKE_CURRENT_SOURCE_DIR}/mindrt_executor.cc 217 ) 218else() 219 set(LITE_SRC ${LITE_SRC} 220 ${CORE_DIR}/mindrt/src/thread/core_affinity.cc 221 ${CORE_DIR}/mindrt/src/thread/threadpool.cc 222 ) 223endif() 224 225add_subdirectory(ops) 226add_subdirectory(runtime/kernel/arm) 227 228add_library(lite_src_mid OBJECT ${LITE_SRC}) 229add_dependencies(lite_src_mid fbs_src) 230 231if(MSLITE_ENABLE_ACL) 232 add_subdirectory(runtime/kernel/ascend310) 233 link_directories(${ASCEND_RUNTIME_PATH} ${ASCEND_TOOLKIT_RUNTIME_PATH}) 234endif() 235 236add_library(mindspore-lite SHARED $<TARGET_OBJECTS:lite_src_mid>) 237set_target_properties(mindspore-lite PROPERTIES CLEAN_DIRECT_OUTPUT 1) 238 239if(APPLE) 240 set(MINDSPORE_LITE_PUB_HDRS 241 ${CMAKE_CURRENT_SOURCE_DIR}/../include/context.h 242 ${CMAKE_CURRENT_SOURCE_DIR}/../include/errorcode.h 243 ${CMAKE_CURRENT_SOURCE_DIR}/../include/lite_session.h 244 ${CMAKE_CURRENT_SOURCE_DIR}/../include/lite_types.h 245 ${CMAKE_CURRENT_SOURCE_DIR}/../include/lite_utils.h 246 ${CMAKE_CURRENT_SOURCE_DIR}/../include/model.h 247 ${CMAKE_CURRENT_SOURCE_DIR}/../include/ms_tensor.h 248 ${CMAKE_CURRENT_SOURCE_DIR}/../include/version.h 249 ) 250 set(MINDSPORE_LITE_PUB_HDRS_IR_HDRS 251 ${CMAKE_CURRENT_SOURCE_DIR}/../../core/ir/dtype/type_id.h 252 ) 253 add_library(mindspore-lite_static STATIC 254 ${LITE_SRC} 255 ${MINDSPORE_LITE_PUB_HDRS} 256 ${MINDSPORE_LITE_PUB_HDRS_IR_HDRS} 257 ) 258 add_dependencies(mindspore-lite_static fbs_inner_src) 259else() 260 add_library(mindspore-lite_static STATIC $<TARGET_OBJECTS:lite_src_mid>) 261endif() 262set_target_properties(mindspore-lite_static PROPERTIES OUTPUT_NAME "mindspore-lite") 263set_target_properties(mindspore-lite_static PROPERTIES CLEAN_DIRECT_OUTPUT 1) 264 265if(NOT MSVC) 266 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-private-field") 267endif() 268 269if(MSVC) 270 set_target_properties(mindspore-lite PROPERTIES PREFIX lib) 271 set_target_properties(mindspore-lite PROPERTIES IMPORT_PREFIX lib) 272 set_target_properties(mindspore-lite PROPERTIES IMPORT_SUFFIX .dll.lib) 273 set_target_properties(mindspore-lite_static PROPERTIES PREFIX lib) 274endif() 275 276if(MSLITE_ENABLE_MINDRT) 277 target_link_libraries(mindspore-lite mindrt_mid) 278 target_link_libraries(mindspore-lite_static mindrt_mid) 279endif() 280 281if(SUPPORT_TENSORRT) 282 add_compile_definitions(GPU_TENSORRT) 283 set(TENSORRT_PATH $ENV{TENSORRT_PATH}) 284 set(CUDA_PATH $ENV{CUDA_HOME}) 285 set(TENSORRT_LIB_PATH ${TENSORRT_PATH}/lib) 286 set(CUDA_LIB_PATH ${CUDA_PATH}/lib64) 287 include_directories(${TENSORRT_PATH}/include) 288 include_directories(${CUDA_PATH}/include) 289 add_subdirectory(delegate/tensorrt) 290 target_link_libraries(mindspore-lite tensorrt_kernel_mid) 291 target_link_libraries(mindspore-lite_static tensorrt_kernel_mid) 292endif() 293 294if(MSLITE_GPU_BACKEND STREQUAL opencl) 295 add_subdirectory(runtime/kernel/opencl) 296 target_link_libraries(mindspore-lite cpu_kernel_mid opencl_kernel_mid nnacl_mid cpu_ops_mid) 297 target_link_libraries(mindspore-lite_static cpu_kernel_mid opencl_kernel_mid nnacl_mid cpu_ops_mid) 298elseif(MSLITE_GPU_BACKEND STREQUAL cuda) 299 add_subdirectory(runtime/kernel/cuda) 300 target_link_libraries(mindspore-lite cpu_kernel_mid cuda_kernel_mid nnacl_mid cpu_ops_mid) 301 target_link_libraries(mindspore-lite_static cpu_kernel_mid cuda_kernel_mid nnacl_mid cpu_ops_mid) 302else() 303 target_link_libraries(mindspore-lite cpu_kernel_mid nnacl_mid cpu_ops_mid) 304 target_link_libraries(mindspore-lite_static cpu_kernel_mid nnacl_mid cpu_ops_mid) 305endif() 306if(SUPPORT_NPU) 307 add_subdirectory(delegate/npu) 308 target_link_libraries(mindspore-lite npu_kernel_mid) 309 target_link_libraries(mindspore-lite_static npu_kernel_mid) 310endif() 311if(SUPPORT_NNRT) 312 add_subdirectory(delegate/nnrt) 313 add_compile_definitions(SUPPORT_NNRT=ON) 314 target_link_libraries(mindspore-lite nnrt_mid) 315 target_link_libraries(mindspore-lite_static nnrt_mid) 316endif() 317 318if(PLATFORM_ARM32 OR PLATFORM_ARM64 AND NOT TARGET_HIMIX200 AND NOT TARGET_OHOS_LITE) 319 target_link_libraries(mindspore-lite log) 320 target_link_libraries(mindspore-lite_static log) 321endif() 322if(BUILD_MINDDATA STREQUAL "lite") 323 target_link_libraries(mindspore-lite minddata_eager_mid minddata-lite) 324 target_link_libraries(mindspore-lite_static minddata_eager_mid) 325endif() 326 327if(SUPPORT_TRAIN) 328 add_library(lite_train_src_mid OBJECT ${TRAIN_SRC}) 329 add_dependencies(lite_train_src_mid fbs_src fbs_inner_src) 330 331 add_library(mindspore-lite-train SHARED $<TARGET_OBJECTS:lite_train_src_mid>) 332 set_target_properties(mindspore-lite-train PROPERTIES OUTPUT_NAME "mindspore-lite-train") 333 set_target_properties(mindspore-lite-train PROPERTIES CLEAN_DIRECT_OUTPUT 1) 334 target_link_libraries(mindspore-lite-train minddata-lite mindspore-lite) 335 336 add_library(mindspore-lite-train_static STATIC $<TARGET_OBJECTS:lite_train_src_mid>) 337 set_target_properties(mindspore-lite-train_static PROPERTIES OUTPUT_NAME "mindspore-lite-train") 338 set_target_properties(mindspore-lite-train_static PROPERTIES CLEAN_DIRECT_OUTPUT 1) 339 target_link_libraries(mindspore-lite-train_static minddata-lite mindspore-lite) 340endif() 341 342########################## build optimize and float16 library ################################# 343if(PLATFORM_ARM) 344 if(PLATFORM_ARM64) 345 target_link_libraries(mindspore-lite cpu_opt_kernel_mid nnacl_optimize_mid) 346 target_link_libraries(mindspore-lite_static cpu_opt_kernel_mid nnacl_optimize_mid) 347 endif() 348 if(MSLITE_ENABLE_FP16) 349 target_link_libraries(mindspore-lite cpu_fp16_kernel_mid nnacl_fp16_mid) 350 target_link_libraries(mindspore-lite_static cpu_fp16_kernel_mid nnacl_fp16_mid) 351 endif() 352endif() 353 354if(DEFINED ARCHS) 355 set_target_properties(mindspore-lite_static PROPERTIES FRAMEWORK TRUE) 356 set_target_properties(mindspore-lite_static PROPERTIES 357 OUTPUT_NAME "mindspore-lite" 358 FRAMEWORK_VERSION C 359 XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer" 360 XCODE_ATTRIBUTE_INSTALL_PAYH "@rpath" 361 ) 362 FOREACH(HDR ${MINDSPORE_LITE_PUB_HDRS}) 363 SET_SOURCE_FILES_PROPERTIES(${HDR} PROPERTIES MACOSX_PACKAGE_LOCATION Headers/include/) 364 ENDFOREACH() 365 FOREACH(HDR ${MINDSPORE_LITE_PUB_HDRS_IR_HDRS}) 366 SET_SOURCE_FILES_PROPERTIES(${HDR} PROPERTIES MACOSX_PACKAGE_LOCATION Headers/include/ir/dtype/) 367 ENDFOREACH() 368 target_link_libraries(mindspore-lite_static) 369endif() 370 371if(NOT WIN32) 372 target_link_libraries(mindspore-lite dl) 373endif() 374 375if(ENABLE_MODEL_OBF) 376 target_link_libraries(mindspore-lite ${OBF_LIB_DIR}/libmsdeobfuscator-lite.so) 377 target_link_libraries(mindspore-lite_static ${OBF_LIB_DIR}/libmsdeobfuscator-lite.so) 378endif() 379 380if(MSLITE_ENABLE_ACL) 381 target_link_libraries(mindspore-lite ascend310_kernel_mid) 382 target_link_libraries(mindspore-lite_static ascend310_kernel_mid) 383endif() 384