change cropper name

This commit is contained in:
yeyunpeng 2020-12-22 20:41:38 +08:00
parent 5d4a308aca
commit 8e7052ce74
13 changed files with 77 additions and 58 deletions

View File

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

View File

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

View File

@ -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<hiai::AiModelDescription>(model_name, frequency, 0, 0, 0);
model->desc_ = desc;
models_.insert({model_name, model});

View File

@ -33,7 +33,7 @@ static std::set<mindspore::schema::PrimitiveType> 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;
}

View File

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

View File

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

View File

@ -16,8 +16,8 @@
#include <memory>
#include <string>
#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 {

View File

@ -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 <set>
#include <string>
@ -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 {

View File

@ -14,9 +14,9 @@
* limitations under the License.
*/
#include "tools/lib_cropper/cropper_flags.h"
#include "tools/cropper/cropper_flags.h"
#include <string>
#include "tools/lib_cropper/cropper_utils.h"
#include "tools/cropper/cropper_utils.h"
#include "src/common/file_utils.h"
namespace mindspore {

View File

@ -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 <string>
#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

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
#include "tools/lib_cropper/cropper_utils.h"
#include "tools/cropper/cropper_utils.h"
#include <fstream>
#include <iostream>
#include "src/common/log_adapter.h"

View File

@ -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 <string>
namespace mindspore {
namespace lite {

View File

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