diff --git a/cmake/package_lite.cmake b/cmake/package_lite.cmake index 1c82f9764f9..e084bb33d95 100644 --- a/cmake/package_lite.cmake +++ b/cmake/package_lite.cmake @@ -144,8 +144,8 @@ else () endif () if (ENABLE_TOOLS) install(TARGETS benchmark RUNTIME DESTINATION ${RUNTIME_PKG_NAME}/benchmark COMPONENT ${RUNTIME_COMPONENT_NAME}) - install(TARGETS lib_cropper RUNTIME DESTINATION ${RUNTIME_PKG_NAME}/lib_cropper COMPONENT ${RUNTIME_COMPONENT_NAME}) - install(FILES ${TOP_DIR}/mindspore/lite/build/tools/lib_cropper/cropper_mapping_cpu.cfg DESTINATION ${RUNTIME_PKG_NAME}/lib_cropper COMPONENT ${RUNTIME_COMPONENT_NAME}) + install(TARGETS cropper RUNTIME DESTINATION ${RUNTIME_PKG_NAME}/cropper COMPONENT ${RUNTIME_COMPONENT_NAME}) + install(FILES ${TOP_DIR}/mindspore/lite/build/tools/cropper/cropper_mapping_cpu.cfg DESTINATION ${RUNTIME_PKG_NAME}/cropper COMPONENT ${RUNTIME_COMPONENT_NAME}) endif () endif () diff --git a/mindspore/lite/CMakeLists.txt b/mindspore/lite/CMakeLists.txt index ed949173f40..f5c74d70e6f 100644 --- a/mindspore/lite/CMakeLists.txt +++ b/mindspore/lite/CMakeLists.txt @@ -237,7 +237,7 @@ if (NOT WIN32) if (ENABLE_TOOLS) if (NOT PLATFORM_ARM32 AND NOT PLATFORM_ARM64) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/schema_gen) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/lib_cropper) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/cropper) endif () endif () if (BUILD_TESTCASES) diff --git a/mindspore/lite/src/runtime/agent/npu/npu_manager.cc b/mindspore/lite/src/runtime/agent/npu/npu_manager.cc index c4c8263ca8a..56e7f08a34c 100644 --- a/mindspore/lite/src/runtime/agent/npu/npu_manager.cc +++ b/mindspore/lite/src/runtime/agent/npu/npu_manager.cc @@ -126,7 +126,7 @@ bool NPUManager::IsKirinChip() { } int NPUManager::AddModel(domi::ModelBufferData *model_buffer_data, const std::string &model_name, int frequency) { - auto model = new SubGraphModel(index_, model_name, model_buffer_data, frequency); + auto model = new SubGraphModel(index_, model_name, model_buffer_data); auto desc = std::make_shared(model_name, frequency, 0, 0, 0); model->desc_ = desc; models_.insert({model_name, model}); diff --git a/mindspore/lite/src/runtime/agent/npu/npu_manager.h b/mindspore/lite/src/runtime/agent/npu/npu_manager.h index 3c0675b45c9..bb5548b0121 100644 --- a/mindspore/lite/src/runtime/agent/npu/npu_manager.h +++ b/mindspore/lite/src/runtime/agent/npu/npu_manager.h @@ -33,7 +33,7 @@ static std::set npu_trans_nodes = { schema::PrimitiveType_Resize, schema::PrimitiveType_Pooling}; struct SubGraphModel { public: - SubGraphModel(int index, std::string model_name, domi::ModelBufferData *model_buffer_data, int frequency) + SubGraphModel(int index, std::string model_name, domi::ModelBufferData *model_buffer_data) : index_(index), model_name_(std::move(model_name)), model_buffer_data_(model_buffer_data) { std::cout << model_name; } diff --git a/mindspore/lite/tools/lib_cropper/CMakeLists.txt b/mindspore/lite/tools/cropper/CMakeLists.txt similarity index 68% rename from mindspore/lite/tools/lib_cropper/CMakeLists.txt rename to mindspore/lite/tools/cropper/CMakeLists.txt index cd34b0c82c9..0c3db33a1c2 100644 --- a/mindspore/lite/tools/lib_cropper/CMakeLists.txt +++ b/mindspore/lite/tools/cropper/CMakeLists.txt @@ -5,16 +5,16 @@ set(COMMON_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../src/common/utils.cc ) -add_executable(lib_cropper +add_executable(cropper ${CMAKE_CURRENT_SOURCE_DIR}/main.cc - ${CMAKE_CURRENT_SOURCE_DIR}/lib_cropper.cc + ${CMAKE_CURRENT_SOURCE_DIR}/cropper.cc ${CMAKE_CURRENT_SOURCE_DIR}/cropper_flags.cc ${CMAKE_CURRENT_SOURCE_DIR}/cropper_utils.cc ${COMMON_SRC}) -add_dependencies(lib_cropper fbs_src) +add_dependencies(cropper fbs_src) -target_link_libraries(lib_cropper mindspore-lite_static) +target_link_libraries(cropper mindspore-lite_static) -add_custom_command(TARGET lib_cropper POST_BUILD COMMAND +add_custom_command(TARGET cropper POST_BUILD COMMAND bash build_cropper_config.sh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/mindspore/lite/tools/lib_cropper/build_cropper_config.sh b/mindspore/lite/tools/cropper/build_cropper_config.sh similarity index 62% rename from mindspore/lite/tools/lib_cropper/build_cropper_config.sh rename to mindspore/lite/tools/cropper/build_cropper_config.sh index 4c7f18994be..e00123a85bf 100644 --- a/mindspore/lite/tools/lib_cropper/build_cropper_config.sh +++ b/mindspore/lite/tools/cropper/build_cropper_config.sh @@ -3,7 +3,7 @@ CURRENT_PATH=$(pwd) MINDSPORE_HOME="${CURRENT_PATH}/../../../.." echo "MINDSPORE_HOME path is ${MINDSPORE_HOME}" -CROPPER_OUTPUT_DIR=${MINDSPORE_HOME}/mindspore/lite/build/tools/lib_cropper +CROPPER_OUTPUT_DIR=${MINDSPORE_HOME}/mindspore/lite/build/tools/cropper mkdir -p ${CROPPER_OUTPUT_DIR} MAPPING_OUTPUT_FILE_NAME_TMP=${CROPPER_OUTPUT_DIR}/cropper_mapping_cpu_tmp.cfg MAPPING_OUTPUT_FILE_NAME=${CROPPER_OUTPUT_DIR}/cropper_mapping_cpu.cfg @@ -14,7 +14,8 @@ ops_list=() DEFINE_STR="-DENABLE_ANDROID -DENABLE_ARM -DENABLE_ARM64 -DENABLE_NEON -DNO_DLIB -DUSE_ANDROID_LOG -DANDROID" # get the flatbuffers path if [ ${MSLIBS_CACHE_PATH} ]; then - FLATBUFFERS_LIST=($(ls -d ${MSLIBS_CACHE_PATH}/flatbuffers_*/include)) + FLATBUFFERS_LIST=() + while IFS='' read -r line; do FLATBUFFERS_LIST+=("$line"); done < <(ls -d ${MSLIBS_CACHE_PATH}/flatbuffers_*/include) FLATBUFFERS=${FLATBUFFERS_LIST[0]} echo "FLATBUFFERS path is ${FLATBUFFERS}" else @@ -41,7 +42,9 @@ REMOVE_LISTS_STR="" getDeep() { map_files=$(gcc -MM ${2} ${DEFINE_STR} ${HEADER_LOCATION}) # first is *.o second is *.cc - array_deep=($(echo ${map_files} | awk -F '\' '{for(i=3;i<=NF;i++){print $i}}' | grep -E 'src/runtime|nnacl' | egrep -v ${REMOVE_LISTS_STR})) + array_deep=() + while IFS='' read -r line; do array_deep+=("$line"); done < <(echo ${map_files} | awk -F '\' '{for(i=3;i<=NF;i++){print $i}}' | grep -E 'src/runtime|nnacl' | egrep -v ${REMOVE_LISTS_STR}) + # shellcheck disable=SC2068 for array_deep_file in ${array_deep[@]}; do # only add existing files if [[ -e ${array_deep_file%h*}cc ]]; then @@ -56,10 +59,12 @@ getDeep() { } getOpsFile() { echo "start get operator mapping file $3" + # shellcheck disable=SC2068 for type in ${ops_list[@]}; do # get mapping ret=$(egrep -r -l "$1${type}," $2) - array=(${ret}) + array=("${ret}") + # shellcheck disable=SC2068 for file in ${array[@]}; do # delete \n out_file=$(echo ${file} | awk -F '/' '{print $NF}') @@ -67,7 +72,9 @@ getOpsFile() { echo "${type},${3},${out_file}.o" >>${MAPPING_OUTPUT_FILE_NAME_TMP} map_files=$(gcc -MM ${file} ${DEFINE_STR} ${HEADER_LOCATION}) # first is *.o second is *.cc - array_file=($(echo ${map_files} | awk -F '\' '{for(i=3;i<=NF;i++){print $i}}' | grep -E 'src/runtime|nnacl' | egrep -v ${REMOVE_LISTS_STR})) + array_file=() + while IFS='' read -r line; do array_file+=("$line"); done < <(echo ${map_files} | awk -F '\' '{for(i=3;i<=NF;i++){print $i}}' | grep -E 'src/runtime|nnacl' | egrep -v ${REMOVE_LISTS_STR}) + # shellcheck disable=SC2068 for array_file in ${array_file[@]}; do # only add existing files if [[ -e ${array_file%h*}cc ]]; then @@ -86,45 +93,55 @@ getOpsFile() { } getCommonFile() { echo "start get common files" - include_h=($(ls ${MINDSPORE_HOME}/mindspore/lite/include/*.h)) - src_files_h=($(ls ${MINDSPORE_HOME}/mindspore/lite/src/*.h)) - common_files_h=($(ls ${MINDSPORE_HOME}/mindspore/lite/src/common/*.h)) - runtime_files_h=($(ls ${MINDSPORE_HOME}/mindspore/lite/src/runtime/*.h)) - others_files=( - ${MINDSPORE_HOME}/mindspore/lite/src/populate/populate_register.h - ${MINDSPORE_HOME}/mindspore/lite/src/ops/primitive_c.h - ${MINDSPORE_HOME}/mindspore/lite/nnacl/nnacl_utils.h - ${MINDSPORE_HOME}/mindspore/lite/nnacl/pack.h - ${MINDSPORE_HOME}/mindspore/lite/src/runtime/kernel/arm/fp16/common_fp16.h + include_h=() + while IFS='' read -r line; do include_h+=("$line"); done < <(ls ${MINDSPORE_HOME}/mindspore/lite/include/*.h) + src_files_h=() + while IFS='' read -r line; do src_files_h+=("$line"); done < <(ls ${MINDSPORE_HOME}/mindspore/lite/src/*.h) + common_files_h=() + while IFS='' read -r line; do common_files_h+=("$line"); done < <(ls ${MINDSPORE_HOME}/mindspore/lite/src/common/*.h) + runtime_files_h=() + while IFS='' read -r line; do runtime_files_h+=("$line"); done < <(ls ${MINDSPORE_HOME}/mindspore/lite/src/runtime/*.h) + others_files_h=( + "${MINDSPORE_HOME}"/mindspore/lite/src/populate/populate_register.h + "${MINDSPORE_HOME}"/mindspore/lite/src/ops/primitive_c.h + "${MINDSPORE_HOME}"/mindspore/lite/nnacl/nnacl_utils.h + "${MINDSPORE_HOME}"/mindspore/lite/nnacl/pack.h + "${MINDSPORE_HOME}"/mindspore/lite/src/runtime/kernel/arm/fp16/common_fp16.h ) - all_files_h=(${include_h[@]} ${src_files_h[@]} ${common_files_h[@]} ${runtime_files_h[@]} ${others_files[@]}) + all_files_h=("${include_h[@]}" "${src_files_h[@]}" "${common_files_h[@]}" "${runtime_files_h[@]}" "${others_files_h[@]}") # concat regx REMOVE_LISTS_STR="${all_files_h[0]}" + # shellcheck disable=SC2068 for val in ${all_files_h[@]:1}; do REMOVE_LISTS_STR="$REMOVE_LISTS_STR|$val" done - src_files=($(ls ${MINDSPORE_HOME}/mindspore/lite/src/*.cc)) - common_files=($(ls ${MINDSPORE_HOME}/mindspore/lite/src/common/*.cc)) - runtime_files_cc=($(ls ${MINDSPORE_HOME}/mindspore/lite/src/runtime/*.cc)) - runtime_files_c=($(ls ${MINDSPORE_HOME}/mindspore/lite/src/runtime/*.c)) - + src_files=() + while IFS='' read -r line; do src_files+=("$line"); done < <(ls ${MINDSPORE_HOME}/mindspore/lite/src/*.cc) + common_files=() + while IFS='' read -r line; do common_files+=("$line"); done < <(ls ${MINDSPORE_HOME}/mindspore/lite/src/common/*.cc) + runtime_files_cc=() + while IFS='' read -r line; do runtime_files_cc+=("$line"); done < <(ls ${MINDSPORE_HOME}/mindspore/lite/src/runtime/*.cc) + runtime_files_c=() + while IFS='' read -r line; do runtime_files_c+=("$line"); done < <(ls ${MINDSPORE_HOME}/mindspore/lite/src/runtime/*.c) # sava all assembly files - assembly_files=("$(ls ${MINDSPORE_HOME}/mindspore/lite/nnacl/assembly/*/*.S)") - others_files=( - ${MINDSPORE_HOME}/mindspore/lite/src/ops/primitive_c.cc - ${MINDSPORE_HOME}/mindspore/lite/nnacl/nnacl_utils.c - ${MINDSPORE_HOME}/mindspore/lite/nnacl/pack.c - ${MINDSPORE_HOME}/mindspore/lite/src/runtime/kernel/arm/fp16/common_fp16.cc - ${MINDSPORE_HOME}/mindspore/lite/src/ops/populate/arithmetic_populate.cc - ${MINDSPORE_HOME}/mindspore/lite/src/ops/populate/arithmetic_self_populate.cc + assembly_files=() + while IFS='' read -r line; do assembly_files+=("$line"); done < <(ls ${MINDSPORE_HOME}/mindspore/lite/nnacl/assembly/*/*.S) + others_files_c=( + "${MINDSPORE_HOME}"/mindspore/lite/src/ops/primitive_c.cc + "${MINDSPORE_HOME}"/mindspore/lite/nnacl/nnacl_utils.c + "${MINDSPORE_HOME}"/mindspore/lite/nnacl/pack.c + "${MINDSPORE_HOME}"/mindspore/lite/src/runtime/kernel/arm/fp16/common_fp16.cc + "${MINDSPORE_HOME}"/mindspore/lite/src/ops/populate/arithmetic_populate.cc + "${MINDSPORE_HOME}"/mindspore/lite/src/ops/populate/arithmetic_self_populate.cc ) - all_files=(${src_files[@]} ${common_files[@]} ${runtime_files_cc[@]} ${runtime_files_c[@]} ${others_files[@]} ${assembly_files[@]}) - + all_files=("${src_files[@]}" "${common_files[@]}" "${runtime_files_cc[@]}" "${runtime_files_c[@]}" "${others_files_c[@]}" "${assembly_files[@]}") + # shellcheck disable=SC2068 for file in ${all_files[@]}; do map_files=$(gcc -MM ${file} ${DEFINE_STR} ${HEADER_LOCATION}) # first is *.o second is *.cc + # shellcheck disable=SC2207 array_runtime=($(echo ${map_files} | awk -F '\' '{for(i=3;i<=NF;i++){print $i}}' | grep -v "flatbuffers" | egrep -v ${REMOVE_LISTS_STR})) # only add existing files for array_runtime_file in "${array_runtime[@]}"; do @@ -136,6 +153,7 @@ getCommonFile() { fi done done + # shellcheck disable=SC2068 for file in ${all_files[@]}; do file=$(echo ${file} | awk -F '/' '{print $NF}') echo "CommonFile,common,${file}.o" >>${MAPPING_OUTPUT_FILE_NAME_TMP} & @@ -146,11 +164,12 @@ getCommonFile() { # automatically generate operator list generateOpsList() { echo "start generate operator list" - ops=($(egrep "PrimitiveType_.* = " "${MINDSPORE_HOME}/mindspore/lite/build/schema/model_generated.h" | awk -F '_' '{print $2}' | awk -F ' ' '{print $1}')) - + ops=() + while IFS='' read -r line; do ops+=("$line"); done < <(egrep "PrimitiveType_.* = " "${MINDSPORE_HOME}/mindspore/lite/build/schema/model_generated.h" | awk -F '_' '{print $2}' | awk -F ' ' '{print $1}') ops_num=$((${#ops[@]} - 3)) echo "ops nums:${ops_num}" - ops_list=${ops[@]:1:$ops_num} + ops_list=() + mapfile -t ops_list <<< "${ops[*]:1:$ops_num}" } echo "Start getting all file associations." generateOpsList diff --git a/mindspore/lite/tools/lib_cropper/lib_cropper.cc b/mindspore/lite/tools/cropper/cropper.cc similarity index 99% rename from mindspore/lite/tools/lib_cropper/lib_cropper.cc rename to mindspore/lite/tools/cropper/cropper.cc index aa108ac3a93..93e83b609c6 100644 --- a/mindspore/lite/tools/lib_cropper/lib_cropper.cc +++ b/mindspore/lite/tools/cropper/cropper.cc @@ -16,8 +16,8 @@ #include #include -#include "tools/lib_cropper/lib_cropper.h" -#include "tools/lib_cropper/cropper_utils.h" +#include "tools/cropper/cropper.h" +#include "tools/cropper/cropper_utils.h" #define BUF_SIZE 1024 namespace mindspore { diff --git a/mindspore/lite/tools/lib_cropper/lib_cropper.h b/mindspore/lite/tools/cropper/cropper.h similarity index 91% rename from mindspore/lite/tools/lib_cropper/lib_cropper.h rename to mindspore/lite/tools/cropper/cropper.h index 9d680b56435..af1f78ed765 100644 --- a/mindspore/lite/tools/lib_cropper/lib_cropper.h +++ b/mindspore/lite/tools/cropper/cropper.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef MINDSPORE_LITE_TOOLS_LIB_CROPPER_LIB_CROPPER_H_ -#define MINDSPORE_LITE_TOOLS_LIB_CROPPER_LIB_CROPPER_H_ +#ifndef MINDSPORE_LITE_TOOLS_CROPPER_CROPPER_H_ +#define MINDSPORE_LITE_TOOLS_CROPPER_CROPPER_H_ #include #include @@ -26,7 +26,7 @@ #include "src/common/utils.h" #include "schema/model_generated.h" #include "include/lite_session.h" -#include "tools/lib_cropper/cropper_flags.h" +#include "tools/cropper/cropper_flags.h" namespace mindspore::lite::cropper { diff --git a/mindspore/lite/tools/lib_cropper/cropper_flags.cc b/mindspore/lite/tools/cropper/cropper_flags.cc similarity index 97% rename from mindspore/lite/tools/lib_cropper/cropper_flags.cc rename to mindspore/lite/tools/cropper/cropper_flags.cc index 8d8ec9ade97..2ed9afe509b 100644 --- a/mindspore/lite/tools/lib_cropper/cropper_flags.cc +++ b/mindspore/lite/tools/cropper/cropper_flags.cc @@ -14,9 +14,9 @@ * limitations under the License. */ -#include "tools/lib_cropper/cropper_flags.h" +#include "tools/cropper/cropper_flags.h" #include -#include "tools/lib_cropper/cropper_utils.h" +#include "tools/cropper/cropper_utils.h" #include "src/common/file_utils.h" namespace mindspore { diff --git a/mindspore/lite/tools/lib_cropper/cropper_flags.h b/mindspore/lite/tools/cropper/cropper_flags.h similarity index 87% rename from mindspore/lite/tools/lib_cropper/cropper_flags.h rename to mindspore/lite/tools/cropper/cropper_flags.h index 273bd5c99df..afdb1af8e07 100644 --- a/mindspore/lite/tools/lib_cropper/cropper_flags.h +++ b/mindspore/lite/tools/cropper/cropper_flags.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef MINDSPORE_LITE_TOOLS_LIB_CROPPER_LIB_CROPPER_FLAGS_H -#define MINDSPORE_LITE_TOOLS_LIB_CROPPER_LIB_CROPPER_FLAGS_H +#ifndef MINDSPORE_LITE_TOOLS_CROPPER_CROPPER_FLAGS_H +#define MINDSPORE_LITE_TOOLS_CROPPER_CROPPER_FLAGS_H #include #include "tools/common/flag_parser.h" @@ -42,4 +42,4 @@ class CropperFlags : public virtual mindspore::lite::FlagParser { } // namespace lite } // namespace mindspore -#endif +#endif // MINDSPORE_LITE_TOOLS_CROPPER_CROPPER_FLAGS_H diff --git a/mindspore/lite/tools/lib_cropper/cropper_utils.cc b/mindspore/lite/tools/cropper/cropper_utils.cc similarity index 97% rename from mindspore/lite/tools/lib_cropper/cropper_utils.cc rename to mindspore/lite/tools/cropper/cropper_utils.cc index b150dd2e5ac..dc98eafb08d 100644 --- a/mindspore/lite/tools/lib_cropper/cropper_utils.cc +++ b/mindspore/lite/tools/cropper/cropper_utils.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "tools/lib_cropper/cropper_utils.h" +#include "tools/cropper/cropper_utils.h" #include #include #include "src/common/log_adapter.h" diff --git a/mindspore/lite/tools/lib_cropper/cropper_utils.h b/mindspore/lite/tools/cropper/cropper_utils.h similarity index 88% rename from mindspore/lite/tools/lib_cropper/cropper_utils.h rename to mindspore/lite/tools/cropper/cropper_utils.h index 8161a70c3ce..c1a65bce1aa 100644 --- a/mindspore/lite/tools/lib_cropper/cropper_utils.h +++ b/mindspore/lite/tools/cropper/cropper_utils.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef MINDSPORE_LITE_TOOLS_LIB_CROPPER_LIB_CROPPER_UTILS_H -#define MINDSPORE_LITE_TOOLS_LIB_CROPPER_LIB_CROPPER_UTILS_H +#ifndef MINDSPORE_LITE_TOOLS_CROPPER_CROPPER_UTILS_H +#define MINDSPORE_LITE_TOOLS_CROPPER_CROPPER_UTILS_H #include namespace mindspore { namespace lite { diff --git a/mindspore/lite/tools/lib_cropper/main.cc b/mindspore/lite/tools/cropper/main.cc similarity index 94% rename from mindspore/lite/tools/lib_cropper/main.cc rename to mindspore/lite/tools/cropper/main.cc index f0427c8a0d4..a0efca729df 100644 --- a/mindspore/lite/tools/lib_cropper/main.cc +++ b/mindspore/lite/tools/cropper/main.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "tools/lib_cropper/lib_cropper.h" +#include "tools/cropper/cropper.h" #include "include/version.h" int main(int argc, const char **argv) {