!16138 [MSLITE][Develop] optimize_compilation_speed

From: @sunsuodong
Reviewed-by: @zhang_xue_tong,@jpc_chenjianping
Signed-off-by: @zhang_xue_tong
This commit is contained in:
mindspore-ci-bot 2021-05-13 21:06:29 +08:00 committed by Gitee
commit 83b58d22b3
7 changed files with 27 additions and 219 deletions

View File

@ -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 $<TARGET_OBJECTS:nnacl_mid>)
else()
add_library(nnacl STATIC $<TARGET_OBJECTS:nnacl_mid>)
endif()
if(NOT ENABLE_CPU)
add_dependencies(nnacl fbs_src)
add_dependencies(nnacl_mid fbs_src)
endif()

View File

@ -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})

View File

@ -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})

View File

@ -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()

View File

@ -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 $<TARGET_OBJECTS:wrapper_mid>)

View File

@ -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 $<TARGET_OBJECTS:lite_src_mid>)
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 $<TARGET_OBJECTS:lite_src_mid>)
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)

View File

@ -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
@ -167,27 +164,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
@ -203,16 +179,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}
)
@ -220,6 +192,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