[MSLITE] support compiling micro runtime for openharmony lite

This commit is contained in:
zhanyuan 2021-07-20 20:46:00 +08:00
parent ec7ce3494a
commit 5720ae8392
8 changed files with 67 additions and 11 deletions

View File

@ -8,7 +8,11 @@ if(NOT TARGET securec)
set(_ms_tmp_CMAKE_POSITION_INDEPENDENT_CODE ${CMAKE_POSITION_INDEPENDENT_CODE})
set(_ms_tmp_CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
if(TARGET_OHOS_LITE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SECURE_CXX_FLAGS}")
else()
set(CMAKE_C_FLAGS "${SECURE_CXX_FLAGS}")
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
add_compile_definitions(SECUREC_ONLY_DECLARE_MEMSET)
endif()

View File

@ -290,7 +290,7 @@ elseif(PLATFORM_ARM32)
install(DIRECTORY ${TOP_DIR}/include/api/ DESTINATION ${RUNTIME_INC_DIR}/api
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h" PATTERN "ops*" EXCLUDE)
__install_micro_wrapper()
if(MSLITE_ENABLE_TOOLS)
if(MSLITE_ENABLE_TOOLS AND NOT TARGET_OHOS_LITE)
install(TARGETS ${BENCHMARK_NAME} RUNTIME DESTINATION ${BENCHMARK_ROOT_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME})
if(SUPPORT_TRAIN)
install(TARGETS ${BENCHMARK_TRAIN_NAME} RUNTIME DESTINATION ${BENCHMARK_TRAIN_ROOT_DIR} COMPONENT

View File

@ -6,6 +6,9 @@ if(TOOLCHAIN_NAME STREQUAL "himix200")
set(TARGET_HIMIX200 on)
set(ENABLE_MINDRT off)
add_compile_definitions(SUPPORT_NNIE)
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_HIMIX200)
@ -177,6 +180,8 @@ elseif(PLATFORM_ARM32)
set(RUNTIME_COMPONENT_NAME "android-aarch32")
if(TARGET_HIMIX200)
set(RUNTIME_COMPONENT_NAME "linux-aarch32")
elseif(TARGET_OHOS_LITE)
set(RUNTIME_COMPONENT_NAME "ohos-aarch32")
endif()
elseif(WIN32)
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
@ -211,7 +216,7 @@ include(${TOP_DIR}/cmake/utils.cmake)
include(${TOP_DIR}/cmake/dependency_utils.cmake)
include(${TOP_DIR}/cmake/dependency_securec.cmake)
include(${TOP_DIR}/cmake/external_libs/flatbuffers.cmake)
if(NOT TARGET_HIMIX200)
if(NOT TARGET_HIMIX200 AND NOT TARGET_OHOS_LITE)
include(${TOP_DIR}/cmake/external_libs/openssl.cmake)
endif()
if(MSLITE_GPU_BACKEND STREQUAL opencl)
@ -309,7 +314,7 @@ if(WIN32)
add_compile_definitions(BUILDING_DLL)
endif()
if(ENABLE_MINDRT OR TARGET_HIMIX200)
if(ENABLE_MINDRT OR TARGET_HIMIX200 OR TARGET_OHOS_LITE)
include_directories(${CORE_DIR}/mindrt/include)
include_directories(${CORE_DIR}/mindrt/src)
endif()

View File

@ -0,0 +1,31 @@
if(NOT DEFINED ENV{OHOS_SYSROOT_PATH})
message(FATAL_ERROR "No defined environment variable: OHOS_SYSROOT_PATH")
endif()
set(OHOS_SYSROOT_PATH "$ENV{OHOS_SYSROOT_PATH}")
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_CXX_COMPILER_ID Clang)
set(CMAKE_TOOLCHAIN_PREFIX llvm-)
set(CMAKE_C_COMPILER clang)
set(CMAKE_C_FLAGS "--target=arm-liteos -D__clang__ -march=armv7-a -w")
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_FLAGS "--target=arm-liteos -D__clang__ -march=armv7-a -w")
set(MY_LINK_FLAGS "--target=arm-liteos --sysroot=${OHOS_SYSROOT_PATH}")
set(CMAKE_LINKER clang)
set(CMAKE_CXX_LINKER clang++)
set(CMAKE_C_LINKER clang)
set(CMAKE_C_LINK_EXECUTABLE
"${CMAKE_C_LINKER} ${MY_LINK_FLAGS} <FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
set(CMAKE_CXX_LINK_EXECUTABLE
"${CMAKE_CXX_LINKER} ${MY_LINK_FLAGS} <FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
set(CMAKE_SYSROOT ${OHOS_SYSROOT_PATH})
set(ENABLE_MINDRT "off")
find_path(GCC_PATH gcc)
find_path(GXX_PATH g++)
if(NOT ${GCC_PATH} STREQUAL "GCC_PATH-NOTFOUND" AND NOT ${GXX_PATH} STREQUAL "GXX_PATH-NOTFOUND")
set(FLATC_GCC_COMPILER ${GCC_PATH}/gcc)
set(FLATC_GXX_COMPILER ${GXX_PATH}/g++)
endif()
string(APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,--gc-sections")

View File

@ -139,8 +139,19 @@ int main(int argc, const char **argv) {
return lite::RET_ERROR;
}
context->thread_num_ = atoi(argv[5]);
if (context->thread_num_ < 1) {
printf("Thread number error! It should be greater than 0\n");
return lite::RET_ERROR;
}
context->device_list_.resize(1);
context->device_list_[0] = {lite::DT_CPU, {{false, static_cast<lite::CpuBindMode>(atoi(argv[6]))}}};
context->device_list_[0].device_type_ = lite::DT_CPU;
context->device_list_[0].device_info_.cpu_device_info_.enable_float16_ = false;
lite::CpuBindMode bind_mode = static_cast<lite::CpuBindMode>(atoi(argv[6]));
if (bind_mode < lite::NO_BIND || bind_mode > lite::MID_CPU) {
printf("Thread bind mode error! 0: No bind, 1: Bind hign cpu, 2: Bind mid cpu.\n");
return lite::RET_ERROR;
}
context->device_list_[0].device_info_.cpu_device_info_.cpu_bind_mode_ = bind_mode;
printf("context: ThreadNum: %d, BindMode: %d\n", context->thread_num_,
context->device_list_[0].device_info_.cpu_device_info_.cpu_bind_mode_);
}

View File

@ -149,7 +149,7 @@ if(ENABLE_MINDRT)
${CMAKE_CURRENT_SOURCE_DIR}/lite_mindrt.cc
${CMAKE_CURRENT_SOURCE_DIR}/mindrt_executor.cc
)
elseif(TARGET_HIMIX200)
elseif(TARGET_HIMIX200 OR TARGET_OHOS_LITE)
file(GLOB MINDRT_ACTOR ${CORE_DIR}/mindrt/src/actor/*.cc)
set(LITE_SRC
${LITE_SRC}
@ -232,7 +232,7 @@ 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_HIMIX200)
if(PLATFORM_ARM32 OR PLATFORM_ARM64 AND NOT TARGET_HIMIX200 AND NOT TARGET_OHOS_LITE)
target_link_libraries(mindspore-lite log)
target_link_libraries(mindspore-lite_static log)
endif()
@ -260,6 +260,8 @@ if(NOT APPLE AND PLATFORM_ARM)
"${ANDROID_NDK}/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/aarch64-linux-android/bin/strip")
if(TARGET_HIMIX200)
set(NDK_STRIP ${HIMIX_STRIP})
elseif(TARGET_OHOS_LITE)
set(NDK_STRIP "llvm-strip")
endif()
endif()

View File

@ -19,10 +19,11 @@
#include <fstream>
#include "src/common/log_adapter.h"
#include "nnacl/nnacl_utils.h"
#ifndef MS_COMPILE_IOS
#ifdef __ANDROID__
#include <sys/auxv.h>
#include <asm/hwcap.h>
#else
#endif
#ifdef MS_COMPILE_IOS
#include <mach/mach.h>
#include <mach/machine.h>
#include <mach/thread_act.h>
@ -46,7 +47,7 @@
#endif
#endif
namespace mindspore::lite {
#ifndef MS_COMPILE_IOS
#ifdef __ANDROID__
uint32_t CpuInfo::MidrSetPart(uint32_t part) {
return ((part << ARM_CPU_PART_OFFSET) & ARM_CPU_PART_MASK) | (midr_ & ~ARM_CPU_PART_MASK);
}
@ -137,6 +138,7 @@ bool CpuInfo::ArmIsSupportFp16() {
}
return false;
#else
#ifdef __ANDROID__
#ifdef ENABLE_ARM32
GetArmProcCpuInfo(&android_cpu_info_);
midr_ = MidrSetPart(android_cpu_info_.cpu_part);
@ -174,6 +176,7 @@ bool CpuInfo::ArmIsSupportFp16() {
} else {
MS_LOG(DEBUG) << "Hw cap NOT support FP16, hwcap: 0x" << hwcap;
}
#endif
#endif
return fp16_flag_;
#endif

View File

@ -15,7 +15,7 @@ add_executable(benchmark
add_dependencies(benchmark fbs_src)
if((PLATFORM_ARM32 OR PLATFORM_ARM64) AND NOT TARGET_HIMIX200)
if((PLATFORM_ARM32 OR PLATFORM_ARM64) AND NOT TARGET_HIMIX200 AND NOT TARGET_OHOS_LITE)
if(SUPPORT_NPU AND ANDROID_STL STREQUAL "c++_static")
target_link_libraries(benchmark mindspore-lite mindspore::json c++_shared)
else()