From 680e5cd75f1e5efe8695faade3a553ce8f37ef50 Mon Sep 17 00:00:00 2001 From: sunsuodong Date: Mon, 10 May 2021 09:05:15 +0800 Subject: [PATCH] optimize_compilation_speed --- .../kernel_compiler/cpu/nnacl/CMakeLists.txt | 14 +- mindspore/lite/micro/cmake/file_list.cmake | 172 +----------------- .../lite/micro/cmake/package_wrapper.cmake | 2 - mindspore/lite/micro/coder/CMakeLists.txt | 2 +- .../lite/micro/coder/wrapper/CMakeLists.txt | 3 +- mindspore/lite/src/CMakeLists.txt | 20 +- mindspore/lite/tools/converter/CMakeLists.txt | 33 +--- 7 files changed, 27 insertions(+), 219 deletions(-) diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/CMakeLists.txt b/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/CMakeLists.txt index a9b70536809..0eefb7d7a7f 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/CMakeLists.txt +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/CMakeLists.txt @@ -61,14 +61,16 @@ endif() ########################### build nnacl static library ######################## string(REPLACE "-fvisibility=hidden" "-fvisibility=default" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") -if(ENABLE_CPU) - add_library(nnacl SHARED ${KERNEL_SRC} ${TRAIN_SRC} ${ASSEMBLY_SRC}) -else() - add_library(nnacl STATIC ${KERNEL_SRC} ${TRAIN_SRC} ${ASSEMBLY_SRC}) -endif() + add_library(nnacl_mid OBJECT ${KERNEL_SRC} ${TRAIN_SRC} ${ASSEMBLY_SRC}) + +if(ENABLE_CPU) + add_library(nnacl SHARED $) +else() + add_library(nnacl STATIC $) +endif() + if(NOT ENABLE_CPU) - add_dependencies(nnacl fbs_src) add_dependencies(nnacl_mid fbs_src) endif() diff --git a/mindspore/lite/micro/cmake/file_list.cmake b/mindspore/lite/micro/cmake/file_list.cmake index 06f21e712d5..b0a3bccd4cc 100644 --- a/mindspore/lite/micro/cmake/file_list.cmake +++ b/mindspore/lite/micro/cmake/file_list.cmake @@ -142,180 +142,10 @@ set(LITE_SRC ${LITE_DIR}/src/huffman_decode.cc ${LITE_DIR}/src/common/log_adapter.cc ${LITE_DIR}/src/common/utils.cc - ### populate operator parameter - ${LITE_DIR}/src/ops/ops_utils.cc - ${LITE_DIR}/src/ops/populate/default_populate.cc - ${LITE_DIR}/src/ops/populate/conv2d_populate.cc - ${LITE_DIR}/src/ops/populate/arithmetic_populate.cc - ${LITE_DIR}/src/ops/populate/add_populate.cc - ${LITE_DIR}/src/ops/populate/concat_populate.cc - ${LITE_DIR}/src/ops/populate/conv2d_populate.cc - ${LITE_DIR}/src/ops/populate/detection_post_process_populate.cc - ${LITE_DIR}/src/ops/populate/depthwise_conv2d_populate.cc - ${LITE_DIR}/src/ops/populate/deconv2d_populate.cc - ${LITE_DIR}/src/ops/populate/full_connection_populate.cc - ${LITE_DIR}/src/ops/populate/pooling_populate.cc - ${LITE_DIR}/src/ops/populate/quant_dtype_cast_populate.cc - ${LITE_DIR}/src/ops/populate/reduce_populate.cc - ${LITE_DIR}/src/ops/populate/resize_populate.cc - ${LITE_DIR}/src/ops/populate/reshape_populate.cc - ${LITE_DIR}/src/ops/populate/batch_norm_populate.cc - ${LITE_DIR}/src/ops/populate/slice_populate.cc - ${LITE_DIR}/src/ops/populate/while_populate.cc - ${LITE_DIR}/src/ops/populate/matmul_populate.cc - ${LITE_DIR}/src/ops/populate/bias_add_populate.cc - ${LITE_DIR}/src/ops/populate/activation_populate.cc - ${LITE_DIR}/src/ops/populate/softmax_populate.cc - ${LITE_DIR}/src/ops/populate/splice_populate.cc - ${LITE_DIR}/src/ops/populate/transpose_populate.cc - ${LITE_DIR}/src/ops/populate/sub_populate.cc - ${LITE_DIR}/src/ops/populate/power_populate.cc - ${LITE_DIR}/src/ops/populate/mul_populate.cc - ${LITE_DIR}/src/ops/populate/arithmetic_self_populate.cc - ${LITE_DIR}/src/ops/populate/div_populate.cc - ${LITE_DIR}/src/ops/populate/erf_populate.cc - ${LITE_DIR}/src/ops/populate/exp_populate.cc - ${LITE_DIR}/src/ops/populate/strided_slice_populate.cc - ${LITE_DIR}/src/ops/populate/scale_populate.cc - ${LITE_DIR}/src/ops/populate/lstm_populate.cc - ${LITE_DIR}/src/ops/populate/squeeze_populate.cc - ${LITE_DIR}/src/ops/populate/transpose_populate.cc ### tools ${LITE_DIR}/tools/common/flag_parser.cc ) -set(LITE_KERNEL_SRC - ### nnacl - ${NNACL_DIR}/common_func.c - ${NNACL_DIR}/base/minimal_filtering_generator.c - ${NNACL_DIR}/base/arithmetic_base.c - ${NNACL_DIR}/base/slice_base.c - ${NNACL_DIR}/fp32/winograd_utils.c - ${NNACL_DIR}/fp32/pack_fp32.c - ${NNACL_DIR}/fp32/arithmetic_fp32.c - ${NNACL_DIR}/fp32/deconv_fp32.c - ${NNACL_DIR}/fp32/matmul_fp32.c - ${NNACL_DIR}/fp32/common_func_fp32.c - ${NNACL_DIR}/fp32/resize_fp32.c - ${NNACL_DIR}/int8/quantize.c - ${NNACL_DIR}/int8/pack_int8.c - ${NNACL_DIR}/int8/matmul_int8.c - ${NNACL_DIR}/int8/fixed_point.c - ${NNACL_DIR}/int8/arithmetic_int8.c - ${NNACL_DIR}/int8/add_int8.c - ${NNACL_DIR}/int8/concat_int8.c - ${NNACL_DIR}/int8/conv_int8.c - ${NNACL_DIR}/int8/conv3x3_int8.c - ${NNACL_DIR}/int8/conv1x1_int8.c - ${NNACL_DIR}/base/conv1x1_base.c - ${NNACL_DIR}/int8/conv_depthwise_int8.c - ${NNACL_DIR}/int8/deconv_int8.c - ${NNACL_DIR}/int8/common_func_int8.c - ${NNACL_DIR}/int8/slice_int8.c - ${NNACL_DIR}/int8/batchnorm_int8.c - ${NNACL_DIR}/int8/sub_int8.c - ${NNACL_DIR}/int8/quant_dtype_cast_int8.c - ${NNACL_DIR}/int8/sigmoid_int8.c - ${NNACL_DIR}/int8/resize_int8.c - ### infer - ${NNACL_DIR}/infer/adam_infer.c - ${NNACL_DIR}/infer/add_sub_grad_infer.c - ${NNACL_DIR}/infer/addn_infer.c - ${NNACL_DIR}/infer/apply_momentum_infer.c - ${NNACL_DIR}/infer/argmin_max_infer.c - ${NNACL_DIR}/infer/arithmetic_compare_infer.c - ${NNACL_DIR}/infer/arithmetic_grad_infer.c - ${NNACL_DIR}/infer/arithmetic_infer.c - ${NNACL_DIR}/infer/assign_add_infer.c - ${NNACL_DIR}/infer/assign_infer.c - ${NNACL_DIR}/infer/batch_to_space_infer.c - ${NNACL_DIR}/infer/bias_grad_infer.c - ${NNACL_DIR}/infer/binary_cross_entropy_infer.c - ${NNACL_DIR}/infer/bn_grad_infer.c - ${NNACL_DIR}/infer/broadcast_to_infer.c - ${NNACL_DIR}/infer/cast_infer.c - ${NNACL_DIR}/infer/common_infer.c - ${NNACL_DIR}/infer/concat_infer.c - ${NNACL_DIR}/infer/constant_of_shape_infer.c - ${NNACL_DIR}/infer/conv2d_grad_filter_infer.c - ${NNACL_DIR}/infer/conv2d_grad_input_infer.c - ${NNACL_DIR}/infer/conv2d_infer.c - ${NNACL_DIR}/infer/deconv2d_infer.c - ${NNACL_DIR}/infer/dedepthwise_conv2d_infer.c - ${NNACL_DIR}/infer/depthwise_conv2d_infer.c - ${NNACL_DIR}/infer/detection_post_process_infer.c - ${NNACL_DIR}/infer/expand_dims_infer.c - ${NNACL_DIR}/infer/fill_infer.c - ${NNACL_DIR}/infer/full_connection_infer.c - ${NNACL_DIR}/infer/fused_batchnorm_infer.c - ${NNACL_DIR}/infer/gather_infer.c - ${NNACL_DIR}/infer/gather_nd_infer.c - ${NNACL_DIR}/infer/group_conv2d_grad_input_infer.c - ${NNACL_DIR}/infer/infer_register.c - ${NNACL_DIR}/infer/lsh_projection_infer.c - ${NNACL_DIR}/infer/lstm_infer.c - ${NNACL_DIR}/infer/matmul_infer.c - ${NNACL_DIR}/infer/max_min_grad_infer.c - ${NNACL_DIR}/infer/mean_infer.c - ${NNACL_DIR}/infer/pooling_grad_infer.c - ${NNACL_DIR}/infer/pooling_infer.c - ${NNACL_DIR}/infer/power_infer.c - ${NNACL_DIR}/infer/quant_dtype_cast_infer.c - ${NNACL_DIR}/infer/range_infer.c - ${NNACL_DIR}/infer/rank_infer.c - ${NNACL_DIR}/infer/reduce_infer.c - ${NNACL_DIR}/infer/reshape_infer.c - ${NNACL_DIR}/infer/resize_infer.c - ${NNACL_DIR}/infer/roi_pooling_infer.c - ${NNACL_DIR}/infer/select_infer.c - ${NNACL_DIR}/infer/sgd_infer.c - ${NNACL_DIR}/infer/shape_infer.c - ${NNACL_DIR}/infer/slice_infer.c - ${NNACL_DIR}/infer/softmax_cross_entropy_infer.c - ${NNACL_DIR}/infer/softmax_infer.c - ${NNACL_DIR}/infer/space_to_batch_infer.c - ${NNACL_DIR}/infer/space_to_batch_nd_infer.c - ${NNACL_DIR}/infer/space_to_depth_infer.c - ${NNACL_DIR}/infer/sparse_softmax_cross_entropy_with_logits_infer.c - ${NNACL_DIR}/infer/sparse_to_dense_infer.c - ${NNACL_DIR}/infer/split_infer.c - ${NNACL_DIR}/infer/squeeze_infer.c - ${NNACL_DIR}/infer/strided_slice_grad_infer.c - ${NNACL_DIR}/infer/strided_slice_infer.c - ${NNACL_DIR}/infer/tile_infer.c - ${NNACL_DIR}/infer/topk_infer.c - ${NNACL_DIR}/infer/transpose_infer.c - ${NNACL_DIR}/infer/unsorted_segment_sum_infer.c - ${NNACL_DIR}/infer/unsqueeze_infer.c - ${NNACL_DIR}/infer/where_infer.c - ${NNACL_DIR}/infer/while_infer.c - ${NNACL_DIR}/infer/splice_infer.c - ) - -#### sse -if("${X86_64_SIMD}" STREQUAL "sse") - set(SSE_SRC - ${NNACL_DIR}/intrinsics/sse/MatMul_Sse.c - ${NNACL_DIR}/intrinsics/sse/PostFuncBiasReluC8.c - ${NNACL_DIR}/intrinsics/sse/PostFuncBiasReluC4.c - ) - set_property(SOURCE ${SSE_SRC} PROPERTY LANGUAGE C) -endif() - -#### avx -if("${X86_64_SIMD}" STREQUAL "avx") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1 -mavx -mavx2") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1 -mavx -mavx2") - set(AVX_SRC - ${NNACL_DIR}/intrinsics/avx/common_utils.c - ${NNACL_DIR}/intrinsics/sse/MatMul_Sse.c - ${NNACL_DIR}/intrinsics/sse/PostFuncBiasReluC8.c - ${NNACL_DIR}/intrinsics/sse/PostFuncBiasReluC4.c - ${NNACL_DIR}/assembly/avx/MatmulAvx.S - ) - set_property(SOURCE ${AVX_SRC} PROPERTY LANGUAGE C) -endif() list(APPEND FILE_SET ${CODER_SRC} ${CODER_OPCODERS_SRC} ${CODER_GENERATOR_SRC} - ${CODER_ALLOCATOR_SRC} ${LITE_SRC} ${LITE_KERNEL_SRC} ${MINDSPORE_CORE} ${SSE_SRC} ${AVX_SRC}) - + ${CODER_ALLOCATOR_SRC} ${LITE_SRC} ${MINDSPORE_CORE}) diff --git a/mindspore/lite/micro/cmake/package_wrapper.cmake b/mindspore/lite/micro/cmake/package_wrapper.cmake index 2b00fa96623..09205b44666 100644 --- a/mindspore/lite/micro/cmake/package_wrapper.cmake +++ b/mindspore/lite/micro/cmake/package_wrapper.cmake @@ -21,5 +21,3 @@ set(WRAPPER_SRC ${WRAPPER_DIR}/int8/slice_int8_wrapper.c ${WRAPPER_DIR}/int8/batchnorm_int8_wrapper.c ) - -list(APPEND FILE_SET ${WRAPPER_SRC}) diff --git a/mindspore/lite/micro/coder/CMakeLists.txt b/mindspore/lite/micro/coder/CMakeLists.txt index 6f098ac4c99..886c0819251 100644 --- a/mindspore/lite/micro/coder/CMakeLists.txt +++ b/mindspore/lite/micro/coder/CMakeLists.txt @@ -31,7 +31,7 @@ if(ENABLE_CONVERTER) add_executable(codegen main.cc ${FILE_SET}) add_dependencies(codegen fbs_src) add_dependencies(codegen fbs_inner_src) - target_link_libraries(codegen PRIVATE ${SECUREC_LIBRARY} mindspore::glog) + target_link_libraries(codegen PRIVATE ${SECUREC_LIBRARY} mindspore::glog wrapper_mid nnacl_mid cpu_ops_mid) if(NOT WIN32 AND "${CMAKE_BUILD_TYPE}" STREQUAL "Release") add_custom_command(TARGET codegen POST_BUILD COMMAND strip ${CODEGEN_PATH}) endif() diff --git a/mindspore/lite/micro/coder/wrapper/CMakeLists.txt b/mindspore/lite/micro/coder/wrapper/CMakeLists.txt index 1961a8caa49..1643866d69d 100644 --- a/mindspore/lite/micro/coder/wrapper/CMakeLists.txt +++ b/mindspore/lite/micro/coder/wrapper/CMakeLists.txt @@ -23,4 +23,5 @@ endif() include(${MICRO_DIR}/cmake/package_wrapper.cmake) # generate static library -add_library(wrapper STATIC ${WRAPPER_SRC}) +add_library(wrapper_mid OBJECT ${WRAPPER_SRC}) +add_library(wrapper STATIC $) \ No newline at end of file diff --git a/mindspore/lite/src/CMakeLists.txt b/mindspore/lite/src/CMakeLists.txt index 77f7cbe6abb..58c0afbf881 100644 --- a/mindspore/lite/src/CMakeLists.txt +++ b/mindspore/lite/src/CMakeLists.txt @@ -151,12 +151,14 @@ endif() add_subdirectory(ops) add_subdirectory(runtime/kernel/arm) -add_library(mindspore-lite SHARED ${LITE_SRC}) -add_dependencies(mindspore-lite fbs_src) +add_library(lite_src_mid OBJECT ${LITE_SRC}) +add_dependencies(lite_src_mid fbs_src) +set_target_properties(lite_src_mid PROPERTIES POSITION_INDEPENDENT_CODE 1) + +add_library(mindspore-lite SHARED $) set_target_properties(mindspore-lite PROPERTIES CLEAN_DIRECT_OUTPUT 1) -add_library(mindspore-lite_static STATIC ${LITE_SRC}) -add_dependencies(mindspore-lite_static fbs_src) +add_library(mindspore-lite_static STATIC $) set_target_properties(mindspore-lite_static PROPERTIES OUTPUT_NAME "mindspore-lite") set_target_properties(mindspore-lite_static PROPERTIES CLEAN_DIRECT_OUTPUT 1) @@ -170,17 +172,18 @@ endif() if(SUPPORT_GPU STREQUAL opencl) add_subdirectory(runtime/kernel/opencl) target_link_libraries(mindspore-lite cpu_kernel_mid opencl_kernel_mid - -Wl,--whole-archive nnacl -Wl,--no-whole-archive cpu_ops_mid) + -Wl,--whole-archive nnacl_mid -Wl,--no-whole-archive cpu_ops_mid) target_link_libraries(mindspore-lite_static cpu_kernel_mid opencl_kernel_mid -Wl,--whole-archive nnacl_mid -Wl,--no-whole-archive cpu_ops_mid) elseif(SUPPORT_GPU STREQUAL cuda) add_subdirectory(runtime/kernel/cuda) target_link_libraries(mindspore-lite cpu_kernel_mid cuda_kernel_mid - -Wl,--whole-archive nnacl -Wl,--no-whole-archive cpu_ops_mid) + -Wl,--whole-archive nnacl_mid -Wl,--no-whole-archive cpu_ops_mid) target_link_libraries(mindspore-lite_static cpu_kernel_mid cuda_kernel_mid -Wl,--whole-archive nnacl_mid -Wl,--no-whole-archive cpu_ops_mid) else() - target_link_libraries(mindspore-lite cpu_kernel_mid -Wl,--whole-archive nnacl -Wl,--no-whole-archive cpu_ops_mid) + target_link_libraries(mindspore-lite cpu_kernel_mid -Wl,--whole-archive nnacl_mid -Wl,--no-whole-archive + cpu_ops_mid) target_link_libraries(mindspore-lite_static cpu_kernel_mid -Wl,--whole-archive nnacl_mid -Wl,--no-whole-archive cpu_ops_mid) endif() @@ -251,14 +254,13 @@ if(DEFINED ARCHS) ${CMAKE_CURRENT_SOURCE_DIR}/../../core/ir/dtype/type_id.h ) add_library(mindspore_lite STATIC - ${LITE_SRC} ${MINDSPORE_LITE_PUB_HDRS} ${MINDSPORE_LITE_PUB_HDRS_IR_HDRS} ) add_dependencies(mindspore_lite fbs_src) set_target_properties(mindspore_lite PROPERTIES OUTPUT_NAME "mindspore_lite") set_target_properties(mindspore_lite PROPERTIES CLEAN_DIRECT_OUTPUT 1) - target_link_libraries(mindspore_lite cpu_kernel_mid nnacl_mid cpu_ops_mid) + target_link_libraries(mindspore_lite lite_src_mid cpu_kernel_mid nnacl_mid cpu_ops_mid) target_link_libraries(mindspore_lite log) if(ENABLE_MINDRT) diff --git a/mindspore/lite/tools/converter/CMakeLists.txt b/mindspore/lite/tools/converter/CMakeLists.txt index 7d11dab9645..5352d9b8cc9 100644 --- a/mindspore/lite/tools/converter/CMakeLists.txt +++ b/mindspore/lite/tools/converter/CMakeLists.txt @@ -9,12 +9,9 @@ set(CCSRC_SRC include(${TOP_DIR}/cmake/external_libs/glog.cmake) include_directories(${TOP_DIR}/mindspore/ccsrc/backend/kernel_compiler/cpu) -file(GLOB OPS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../src/ops/*.cc - ${CMAKE_CURRENT_SOURCE_DIR}/../../src/ops/populate/*.cc - ${CMAKE_CURRENT_SOURCE_DIR}/ops/*.cc - ) file(GLOB_RECURSE CONVERTER_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/ops/*.cc ${CMAKE_CURRENT_SOURCE_DIR}/../flag/flag_parser.cc ${CMAKE_CURRENT_SOURCE_DIR}/converter.cc ${CMAKE_CURRENT_SOURCE_DIR}/converter_flags.cc @@ -164,27 +161,6 @@ if(ENABLE_MINDRT) ) endif() -set(ARM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../src/runtime/kernel/arm) -file(GLOB KERNEL_SRC - ${ARM_DIR}/base/*.cc - ${NNACL_DIR}/*.c - ${NNACL_DIR}/fp32/*.c - ${NNACL_DIR}/infer/*.c - ${NNACL_DIR}/int8/*.c - ${NNACL_DIR}/base/*.c - ${NNACL_DIR}/quantization/*.c - ${ARM_DIR}/fp32/*.cc - ${ARM_DIR}/int8/*.cc - ) - -if(PLATFORM_ARM64) - # assembly - file(GLOB ASSEMBLY_SRC ${NNACL_DIR}/assembly/arm64/*.s - ${NNACL_DIR}/assembly/arm64/*.S) - set_property(SOURCE ${ASSEMBLY_SRC} PROPERTY LANGUAGE C) - set(KERNEL_SRC ${KERNEL_SRC} ${ASSEMBLY_SRC}) -endif() - file(GLOB PROTO_FILE "" ${CMAKE_CURRENT_SOURCE_DIR}/parser/caffe/caffe.proto ${CMAKE_CURRENT_SOURCE_DIR}/parser/tf/proto/*.proto @@ -200,16 +176,12 @@ ms_build_flatbuffers_lite(TFLITE_FBS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/parser/tf set_property(SOURCE ${CONVERTER_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE) set_property(SOURCE ${CCSRC_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE) -set_property(SOURCE ${OPS_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE) -set_property(SOURCE ${KERNEL_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE) set_property(SOURCE ${LITE_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE) set_property(SOURCE ${MINDRT_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE) add_executable(converter_lite main.cc ${CCSRC_SRC} ${CONVERTER_SRC} - ${OPS_SRC} - ${KERNEL_SRC} ${LITE_SRC} ${MINDRT_SRC} ) @@ -217,6 +189,9 @@ add_dependencies(converter_lite fbs_src) add_dependencies(converter_lite fbs_inner_src) target_link_libraries(converter_lite PRIVATE + cpu_ops_mid + nnacl_mid + cpu_kernel_mid mslite_converter_plugin_reg tflite_parser_mid tf_parser_mid