compile 3403

This commit is contained in:
zhaodezan 2021-12-09 17:32:25 +08:00
parent a11a4f011c
commit 3334bfe479
9 changed files with 146 additions and 59 deletions

View File

@ -227,7 +227,9 @@ if(PLATFORM_ARM64)
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h" PATTERN "ops*" EXCLUDE)
install(DIRECTORY ${TOP_DIR}/include/c_api/ DESTINATION ${RUNTIME_INC_DIR}/c_api
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h")
__install_micro_wrapper()
if(NOT MSLITE_ENABLE_DPICO_ACL_ADAPTER)
__install_micro_wrapper()
endif()
if(MSLITE_ENABLE_TOOLS)
install(TARGETS ${BENCHMARK_NAME} RUNTIME DESTINATION ${BENCHMARK_ROOT_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME})
if(SUPPORT_TRAIN)

View File

@ -31,7 +31,7 @@ typedef struct ArgElement {
int32_t i_data_;
float f_data_;
#ifdef ENABLE_ARM
#ifndef SUPPORT_NNIE
#if (!SUPPORT_NNIE) || (defined SUPPORT_34XX)
float16_t f16_data_;
#endif
#endif

View File

@ -39,6 +39,11 @@ if(NOT PLATFORM_ARM32 AND NOT TARGET_HIMIX AND NOT MACHINE_LINUX_ARM64)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8.2-a+dotprod+fp16")
endif()
if(TARGET_MIX210)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8.2-a+fp16")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8.2-a+fp16")
endif()
if(MSLITE_ENABLE_FP16)
add_library(nnacl_fp16_mid OBJECT ${FP16_FILES})
add_dependencies(nnacl_fp16_mid fbs_src)

View File

@ -10,7 +10,7 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/compile_link_option.cmake)
set(MSLITE_GPU_BACKEND "" CACHE STRING "enable gpu backend, \
opencl only support arm64 and x86_64 , tensorrt only support x86_64, opencl/cuda/tensorrt/off")
set(MSLITE_REGISTRY_DEVICE "off" CACHE STRING "Compile Mindspore Lite that supports specific devices, \
currently supported devices: Hi3516D/Hi3519A/Hi3559A")
currently supported devices: Hi3516D/Hi3519A/Hi3559A/sd3403")
option(MSLITE_ENABLE_NPU "enable npu, only arm64 or arm32 support" off)
option(MSLITE_ENABLE_TRAIN "enable train" on)
option(MSLITE_ENABLE_SSE "enable SSE instruction set, only x86_64 support" off)
@ -53,6 +53,13 @@ if(DEFINED ENV{MSLITE_GPU_BACKEND})
endif()
if(DEFINED ENV{MSLITE_REGISTRY_DEVICE})
set(MSLITE_REGISTRY_DEVICE $ENV{MSLITE_REGISTRY_DEVICE})
if(MSLITE_REGISTRY_DEVICE STREQUAL sd3403)
if(NOT PLATFORM_ARM64)
set(MSLITE_ENABLE_DPICO_ATC_ADAPTER on)
else()
set(MSLITE_ENABLE_DPICO_ACL_ADAPTER on)
endif()
endif()
endif()
if(DEFINED ENV{MSLITE_ENABLE_NPU})
set(MSLITE_ENABLE_NPU $ENV{MSLITE_ENABLE_NPU})
@ -149,12 +156,16 @@ elseif(TOOLCHAIN_NAME STREQUAL "himix100")
set(TARGET_HIMIX on)
set(TARGET_HIMIX100 on)
add_compile_definitions(SUPPORT_NNIE)
elseif(TOOLCHAIN_NAME STREQUAL "mix210")
set(TARGET_MIX210 on)
add_compile_definitions(SUPPORT_34XX)
elseif(TOOLCHAIN_NAME STREQUAL "ohos-lite")
set(TARGET_OHOS_LITE on)
SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3.0 AND NOT TARGET_HIMIX)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3.0
AND NOT TARGET_HIMIX AND NOT TARGET_MIX210)
message(FATAL_ERROR "GCC version ${CMAKE_CXX_COMPILER_VERSION} must not be less than 7.3.0")
endif()
@ -346,7 +357,7 @@ if(NOT MSVC)
endif()
if(PLATFORM_ARM64)
if(TARGET_HIMIX100 OR MACHINE_LINUX_ARM64)
if(TARGET_HIMIX100 OR TARGET_MIX210 OR MACHINE_LINUX_ARM64)
set(RUNTIME_COMPONENT_NAME "linux-aarch64")
else()
set(RUNTIME_COMPONENT_NAME "android-aarch64")
@ -368,6 +379,10 @@ else()
set(RUNTIME_COMPONENT_NAME "linux-x64")
endif()
if(MSLITE_ENABLE_DPICO_ACL_ADAPTER)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/benchmark/dpico)
endif()
string(REPLACE "/mindspore/lite" "" TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(CORE_DIR ${TOP_DIR}/mindspore/core)
set(CCSRC_DIR ${TOP_DIR}/mindspore/ccsrc)
@ -552,11 +567,12 @@ if(BUILD_MINDDATA STREQUAL "lite_cv")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/minddata)
endif()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/ops)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/micro/coder)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src)
add_subdirectory(${CCSRC_DIR}/backend/kernel_compiler/cpu/nnacl build)
if(NOT MSLITE_ENABLE_DPICO_ACL_ADAPTER)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/ops)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/micro/coder)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src)
add_subdirectory(${CCSRC_DIR}/backend/kernel_compiler/cpu/nnacl build)
endif()
if(MSLITE_ENABLE_TOOLS)

View File

@ -148,6 +148,8 @@ build_lite() {
MSLITE_REGISTRY_DEVICE=Hi3516D
elif [[ "${MSLITE_REGISTRY_DEVICE}" == "Hi3559A" && "${local_lite_platform}" == "arm64" ]]; then
TOOLCHAIN_NAME="himix100"
elif [[ "${MSLITE_REGISTRY_DEVICE}" == "sd3403" && "${local_lite_platform}" == "arm64" ]]; then
TOOLCHAIN_NAME="mix210"
elif [[ "${MSLITE_REGISTRY_DEVICE}" == "Hi3519A" && "${local_lite_platform}" == "arm32" ]]; then
TOOLCHAIN_NAME="himix200"
elif [[ ("${MSLITE_ENABLE_NNIE}" == "on" || "${MSLITE_REGISTRY_DEVICE}" == "Hi3516D") && "${local_lite_platform}" == "x86_64" ]]; then
@ -189,6 +191,12 @@ build_lite() {
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DBUILD_MINDDATA=off"
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DMSLITE_ENABLE_FP16=off -DMSLITE_ENABLE_TRAIN=off -DMSLITE_GPU_BACKEND=off"
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DMSLITE_ENABLE_TOOLS=off"
elif [[ "${TOOLCHAIN_NAME}" == "mix210" ]]; then
CMAKE_TOOLCHAIN_FILE=${BASEPATH}/mindspore/lite/cmake/mix210.toolchain.cmake
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DTOOLCHAIN_NAME=mix210"
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DBUILD_MINDDATA=off"
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DMSLITE_ENABLE_FP16=off -DMSLITE_ENABLE_TRAIN=off -DMSLITE_GPU_BACKEND=off"
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DMSLITE_ENABLE_TOOLS=off"
else
if [[ "${machine}" == "aarch64" ]]; then
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DMACHINE_LINUX_ARM64=on"
@ -220,15 +228,20 @@ build_lite() {
if [[ "X$CMAKE_TOOLCHAIN_FILE" != "X" ]]; then
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}"
fi
if [[ "X$MSLITE_REGISTRY_DEVICE" != "X" ]]; then
if [[ "X$MSLITE_REGISTRY_DEVICE" != "X" ]] && [[ "${MSLITE_REGISTRY_DEVICE}" != "sd3403" ]]; then
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DMSLITE_REGISTRY_DEVICE=${MSLITE_REGISTRY_DEVICE}"
fi
if [[ "${local_lite_platform}" == "arm64" || "${local_lite_platform}" == "arm32" ]]; then
echo "default link libc++_static.a, export MSLITE_ANDROID_STL=c++_shared to link libc++_shared.so"
fi
echo "cmake ${LITE_CMAKE_ARGS} ${BASEPATH}/mindspore/lite"
cmake ${LITE_CMAKE_ARGS} "${BASEPATH}/mindspore/lite"
if [[ "${MSLITE_REGISTRY_DEVICE}" == "sd3403" ]] && [[ "${local_lite_platform}" == "arm64" ]]; then
export MSLITE_REGISTRY_DEVICE=""
cmake ${LITE_CMAKE_ARGS} "${BASEPATH}/mindspore/lite"
export MSLITE_REGISTRY_DEVICE=sd3403
else
cmake ${LITE_CMAKE_ARGS} "${BASEPATH}/mindspore/lite"
fi
if [[ "$(uname)" == "Darwin" && "${local_lite_platform}" != "x86_64" ]]; then
xcodebuild ONLY_ACTIVE_ARCH=NO -configuration Release -scheme mindspore-lite_static -target mindspore-lite_static -sdk iphoneos -quiet
@ -275,7 +288,7 @@ build_lite() {
fi
[ -n "${BASEPATH}" ] && rm -rf ${BASEPATH}/output/tmp/
if [[ "X$MSLITE_REGISTRY_DEVICE" != "X" ]]; then
if [[ "X$MSLITE_REGISTRY_DEVICE" != "X" ]] && [[ "${MSLITE_REGISTRY_DEVICE}" != "sd3403" ]]; then
local compile_nnie_script=${BASEPATH}/mindspore/lite/tools/providers/NNIE/Hi3516D/compile_nnie.sh
cd ${BASEPATH}/../
if [[ "${local_lite_platform}" == "x86_64" ]]; then
@ -287,6 +300,25 @@ build_lite() {
echo "compile ${local_lite_platform} for nnie failed."
exit 1
fi
elif [[ "${MSLITE_REGISTRY_DEVICE}" == "sd3403" ]] && [[ "${local_lite_platform}" == "arm64" ]]; then
LITE_CMAKE_ARGS=$(echo ${LITE_CMAKE_ARGS} | sed -e "s/MSLITE_ENABLE_TOOLS=off/MSLITE_ENABLE_TOOLS=on/g")
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DMSLITE_REGISTRY_DEVICE=${MSLITE_REGISTRY_DEVICE}"
cmake ${LITE_CMAKE_ARGS} "${BASEPATH}/mindspore/lite"
cd ${BASEPATH}
compile_dpico_script=${BASEPATH}/mindspore/lite/tools/providers/dpico/sd3403/compile_3403.sh
bash ${compile_dpico_script} -t prepare_third_party
if [[ $? -ne 0 ]]; then
echo "prepare for dpico failed."
exit 1
fi
cd ${BASEPATH}/mindspore/lite/build
make -j$THREAD_NUM
cd ${BASEPATH}
sh ${compile_dpico_script}
if [[ $? -ne 0 ]]; then
echo "second compile arm64 for dpico failed."
exit 1
fi
fi
echo "---------------- mindspore lite: build success ----------------"
fi

View File

@ -22,7 +22,7 @@
bool GetSupportOptFlag() {
bool status = false;
#if defined(ENABLE_ARM64) && !defined(SUPPORT_NNIE) && !defined(MS_COMPILE_IOS)
#if defined(ENABLE_ARM64) && !defined(SUPPORT_NNIE) && !defined(MS_COMPILE_IOS) && !defined(SUPPORT_34XX)
int hwcap_type = 16;
// getHwCap
const uint32_t hwcap = getauxval(hwcap_type);

View File

@ -38,7 +38,7 @@ if(APPLE OR PLATFORM_ARM32 OR PLATFORM_ARM64)
-fdata-sections -ffast-math -fno-rtti -fno-exceptions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fomit-frame-pointer -fstrict-aliasing -ffunction-sections \
-fdata-sections -ffast-math -fno-rtti -fno-exceptions")
if(TARGET_HIMIX200)
if(TARGET_HIMIX200 OR TARGET_MIX210)
string(REPLACE "-fno-rtti " "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
endif()
endif()
@ -363,7 +363,8 @@ if(SUPPORT_NPU)
target_link_libraries(mindspore-lite npu_kernel_mid)
target_link_libraries(mindspore-lite_static npu_kernel_mid)
endif()
if(PLATFORM_ARM32 OR PLATFORM_ARM64 AND NOT TARGET_HIMIX AND NOT TARGET_OHOS_LITE AND NOT MACHINE_LINUX_ARM64)
if(PLATFORM_ARM32 OR PLATFORM_ARM64 AND NOT TARGET_HIMIX
AND NOT TARGET_MIX210 AND NOT TARGET_OHOS_LITE AND NOT MACHINE_LINUX_ARM64)
target_link_libraries(mindspore-lite log)
target_link_libraries(mindspore-lite_static log)
endif()

View File

@ -1,6 +1,5 @@
# add shared link library
include_directories(${CCSRC_DIR}/backend/kernel_compiler/cpu)
set(COMMON_SRC
${CMAKE_CURRENT_SOURCE_DIR}/../common/flag_parser.cc
${CMAKE_CURRENT_SOURCE_DIR}/../common/string_util.cc
@ -8,35 +7,67 @@ set(COMMON_SRC
${CMAKE_CURRENT_SOURCE_DIR}/../../src/common/utils.cc
${CMAKE_CURRENT_SOURCE_DIR}/../../../ccsrc/backend/kernel_compiler/cpu/nnacl/nnacl_common.c
)
if(MSLITE_ENABLE_SHARING_MEM_WITH_OPENGL)
set(COMMON_SRC ${COMMON_SRC} ../common/opengl_util.cc)
endif()
add_executable(benchmark
${CMAKE_CURRENT_SOURCE_DIR}/main.cc
${CMAKE_CURRENT_SOURCE_DIR}/run_benchmark.cc
${CMAKE_CURRENT_SOURCE_DIR}/benchmark_base.cc
${CMAKE_CURRENT_SOURCE_DIR}/benchmark.cc
${CMAKE_CURRENT_SOURCE_DIR}/benchmark_unified_api.cc
${CMAKE_CURRENT_SOURCE_DIR}/benchmark_c_api.cc
${COMMON_SRC})
add_dependencies(benchmark fbs_src)
if(MSLITE_ENABLE_SHARING_MEM_WITH_OPENGL)
list(APPEND opengl_lib EGL GLESv3)
target_link_libraries(benchmark ${opengl_lib})
endif()
if((PLATFORM_ARM32 OR PLATFORM_ARM64) AND NOT TARGET_HIMIX AND NOT TARGET_OHOS_LITE AND NOT MACHINE_LINUX_ARM64)
if(SUPPORT_NPU AND ANDROID_STL STREQUAL "c++_static")
target_link_libraries(benchmark mindspore-lite mindspore::json c++_shared)
else()
target_link_libraries(benchmark mindspore-lite mindspore::json)
if(NOT MSLITE_ENABLE_DPICO_ACL_ADAPTER)
if(MSLITE_ENABLE_SHARING_MEM_WITH_OPENGL)
set(COMMON_SRC ${COMMON_SRC} ../common/opengl_util.cc)
endif()
add_executable(benchmark
${CMAKE_CURRENT_SOURCE_DIR}/main.cc
${CMAKE_CURRENT_SOURCE_DIR}/run_benchmark.cc
${CMAKE_CURRENT_SOURCE_DIR}/benchmark_base.cc
${CMAKE_CURRENT_SOURCE_DIR}/benchmark.cc
${CMAKE_CURRENT_SOURCE_DIR}/benchmark_unified_api.cc
${CMAKE_CURRENT_SOURCE_DIR}/benchmark_c_api.cc
${COMMON_SRC})
add_dependencies(benchmark fbs_src)
if(MSLITE_ENABLE_SHARING_MEM_WITH_OPENGL)
list(APPEND opengl_lib EGL GLESv3)
target_link_libraries(benchmark ${opengl_lib})
endif()
if((PLATFORM_ARM32 OR PLATFORM_ARM64) AND NOT TARGET_HIMIX
AND NOT TARGET_OHOS_LITE AND NOT MACHINE_LINUX_ARM64 AND NOT TARGET_MIX210)
if(SUPPORT_NPU AND ANDROID_STL STREQUAL "c++_static")
target_link_libraries(benchmark mindspore-lite mindspore::json c++_shared)
else()
target_link_libraries(benchmark mindspore-lite mindspore::json)
endif()
elseif(MSVC)
target_link_libraries(benchmark mindspore-lite mindspore::json)
else()
target_link_libraries(benchmark mindspore-lite mindspore::json pthread)
endif()
elseif(MSVC)
target_link_libraries(benchmark mindspore-lite mindspore::json)
else()
target_link_libraries(benchmark mindspore-lite mindspore::json pthread)
endif()
__download_pkg(34xx_sdk
http://mindspore-repo.csi.rnd.huawei.com/mindspore/enterprise/dpico/34xx_sdk.tar.gz
f64a9129615b3b41b63debe17c6785af)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../lite)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../core)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/dpico/third_party/runtime)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/dpico/third_party/runtime/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/dpico/third_party/runtime/include/third_party)
include_directories(${34xx_sdk_SOURCE_DIR}/include)
include_directories(${34xx_sdk_SOURCE_DIR})
link_directories(${34xx_sdk_SOURCE_DIR}/lib)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/dpico/third_party/runtime/lib)
set(CMAKE_SKIP_BUILD_RPATH on)
add_executable(benchmark
${CMAKE_CURRENT_SOURCE_DIR}/main.cc
${CMAKE_CURRENT_SOURCE_DIR}/run_benchmark.cc
${CMAKE_CURRENT_SOURCE_DIR}/benchmark_base.cc
${CMAKE_CURRENT_SOURCE_DIR}/benchmark.cc
${CMAKE_CURRENT_SOURCE_DIR}/benchmark_unified_api.cc
${CMAKE_CURRENT_SOURCE_DIR}/benchmark_c_api.cc
${COMMON_SRC})
add_dependencies(benchmark fbs_src)
target_link_libraries(benchmark mindspore-lite mindspore::json pthread
dpico_acl_adapter dl svp_acl securec protobuf-c stdc++)
endif()

View File

@ -33,18 +33,18 @@ namespace lite {
namespace {
constexpr size_t kBitNumOfOneByte = 8;
constexpr size_t TOP_LEFT_X = 0;
constexpr size_t TOP_LEFT_Y = 1;
constexpr size_t BOTTOM_RIGHT_X = 2;
constexpr size_t BOTTOM_RIGHT_Y = 3;
constexpr size_t SCORE = 4;
constexpr size_t CLASS_ID = 5;
constexpr size_t BBOX_SIZE = 6;
constexpr int TOP_LEFT_X = 0;
constexpr int TOP_LEFT_Y = 1;
constexpr int BOTTOM_RIGHT_X = 2;
constexpr int BOTTOM_RIGHT_Y = 3;
constexpr int SCORE = 4;
constexpr int CLASS_ID = 5;
constexpr int BBOX_SIZE = 6;
constexpr size_t NMS_THR = 0;
constexpr size_t SCORE_THR = 1;
constexpr size_t MIN_HEIGHT = 2;
constexpr size_t MIN_WIDTH = 3;
constexpr int NMS_THR = 0;
constexpr int SCORE_THR = 1;
constexpr int MIN_HEIGHT = 2;
constexpr int MIN_WIDTH = 3;
int DetermineInputIndexInOm(const svp_acl_mdl_desc *model_desc, const std::string &tensor_name, size_t *input_index) {
MS_CHECK_FALSE_MSG(model_desc == nullptr || input_index == nullptr, SVP_ACL_ERROR_INVALID_PARAM,