forked from mindspore-Ecosystem/mindspore
compile MSLite for ohos
Signed-off-by: TonyWang222 <wangtongyu6@huawei.com>
This commit is contained in:
parent
aacb575440
commit
ad1d583d22
|
@ -64,6 +64,9 @@ if(APPLE OR PLATFORM_ARM32 OR PLATFORM_ARM64 OR PLATFORM_MCU)
|
|||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer -fstrict-aliasing \
|
||||
-ffunction-sections -fdata-sections -ffast-math")
|
||||
endif()
|
||||
if(TARGET_OHOS)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-inline-asm")
|
||||
endif()
|
||||
elseif(NOT MSVC)
|
||||
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer -fstrict-aliasing -ffunction-sections \
|
||||
|
@ -80,7 +83,7 @@ if(NOT MSVC)
|
|||
endif()
|
||||
if(WIN32)
|
||||
if("${X86_64_SIMD}" STREQUAL "avx512")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx512f -fno-asynchronous-unwind-tables")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx512f -fno-asynchronous-unwind-tables -Wno-inline-asm")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
|
|
@ -15,11 +15,11 @@
|
|||
*/
|
||||
|
||||
#include "nnacl/nnacl_utils.h"
|
||||
#ifdef __ANDROID__
|
||||
#if defined(__ANDROID__) || defined(MS_COMPILE_OHOS)
|
||||
#include <sys/auxv.h>
|
||||
#endif
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#if defined(__ANDROID__) || defined(MS_COMPILE_OHOS)
|
||||
uint32_t getHwCap(int hwcap_type) {
|
||||
uint32_t ret = getauxval(hwcap_type);
|
||||
return ret;
|
||||
|
|
|
@ -279,6 +279,11 @@ elseif(TOOLCHAIN_NAME STREQUAL "mix210")
|
|||
elseif(TOOLCHAIN_NAME STREQUAL "ohos-lite")
|
||||
set(TARGET_OHOS_LITE on)
|
||||
SET_PROPERTY(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
|
||||
elseif(TOOLCHAIN_NAME STREQUAL "ohos")
|
||||
set(TARGET_OHOS on)
|
||||
add_compile_definitions(MS_COMPILE_OHOS)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-command-line-argument -Wno-c++17-extensions")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-command-line-argument -Wno-c++17-extensions")
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3.0
|
||||
|
@ -602,6 +607,8 @@ endif()
|
|||
if(PLATFORM_ARM64)
|
||||
if(TARGET_HIMIX100 OR TARGET_MIX210 OR MACHINE_LINUX_ARM64)
|
||||
set(RUNTIME_COMPONENT_NAME "linux-aarch64")
|
||||
elseif(TARGET_OHOS)
|
||||
set(RUNTIME_COMPONENT_NAME "ohos-aarch64")
|
||||
else()
|
||||
set(RUNTIME_COMPONENT_NAME "android-aarch64")
|
||||
endif()
|
||||
|
@ -611,6 +618,8 @@ elseif(PLATFORM_ARM32)
|
|||
set(RUNTIME_COMPONENT_NAME "linux-aarch32")
|
||||
elseif(TARGET_OHOS_LITE)
|
||||
set(RUNTIME_COMPONENT_NAME "ohos-aarch32")
|
||||
elseif(TARGET_OHOS)
|
||||
set(RUNTIME_COMPONENT_NAME "ohos-aarch32")
|
||||
endif()
|
||||
elseif(WIN32)
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
|
|
|
@ -329,6 +329,12 @@ build_lite() {
|
|||
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DTOOLCHAIN_NAME=himix200"
|
||||
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DMSLITE_MINDDATA_IMPLEMENT=off"
|
||||
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DMSLITE_ENABLE_FP16=off -DMSLITE_ENABLE_TRAIN=off -DMSLITE_GPU_BACKEND=off"
|
||||
elif [[ "${TOOLCHAIN_NAME}" == "ohos" ]]; then
|
||||
pkg_name=mindspore-lite-${VERSION_STR}-ohos-arm32
|
||||
CMAKE_TOOLCHAIN_FILE=${OHOS_NDK}/build/cmake/ohos.toolchain.cmake
|
||||
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DCMAKE_OHOS_NDK=${OHOS_NDK} -DOHOS_ARCH=armeabi-v7a -DOHOS_STL=c++_static -DTOOLCHAIN_NAME=${TOOLCHAIN_NAME}"
|
||||
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DMSLITE_MINDDATA_IMPLEMENT=off"
|
||||
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DMSLITE_ENABLE_FP16=off -DMSLITE_ENABLE_TRAIN=off -DMSLITE_GPU_BACKEND=off"
|
||||
else
|
||||
# CPU : Android-aarch32
|
||||
checkndk
|
||||
|
@ -358,6 +364,12 @@ build_lite() {
|
|||
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DTOOLCHAIN_NAME=mix210"
|
||||
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DMSLITE_MINDDATA_IMPLEMENT=off"
|
||||
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DMSLITE_ENABLE_FP16=on -DMSLITE_ENABLE_TRAIN=off -DMSLITE_GPU_BACKEND=off"
|
||||
elif [[ "${TOOLCHAIN_NAME}" == "ohos" ]]; then
|
||||
pkg_name=mindspore-lite-${VERSION_STR}-ohos-aarch64
|
||||
CMAKE_TOOLCHAIN_FILE=${OHOS_NDK}/build/cmake/ohos.toolchain.cmake
|
||||
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DCMAKE_OHOS_NDK=${OHOS_NDK} -DOHOS_ARCH=arm64-v8a -DOHOS_STL=c++_static -DTOOLCHAIN_NAME=${TOOLCHAIN_NAME}"
|
||||
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DMSLITE_MINDDATA_IMPLEMENT=off"
|
||||
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DMSLITE_ENABLE_FP16=on -DMSLITE_ENABLE_TRAIN=off -DMSLITE_GPU_BACKEND=off"
|
||||
else
|
||||
if [[ "${machine}" == "aarch64" ]]; then
|
||||
# CPU : Linux-aarch64
|
||||
|
@ -409,7 +421,7 @@ build_lite() {
|
|||
if [[ "X$MSLITE_COMPILE_TWICE" != "X" ]]; then
|
||||
LITE_CMAKE_ARGS="${LITE_CMAKE_ARGS} -DMSLITE_COMPILE_TWICE=${MSLITE_COMPILE_TWICE}"
|
||||
fi
|
||||
if [[ "${local_lite_platform}" == "arm64" || "${local_lite_platform}" == "arm32" ]]; then
|
||||
if [[ ("${local_lite_platform}" == "arm64" || "${local_lite_platform}" == "arm32") && "${TOOLCHAIN_NAME}" != "ohos" ]]; then
|
||||
echo "default link libc++_static.a, export MSLITE_ANDROID_STL=c++_shared to link libc++_shared.so"
|
||||
fi
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ if(USE_GLOG)
|
|||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../../third_party/securec/include)
|
||||
include_directories(${CMAKE_BINARY_DIR}/jni_include)
|
||||
add_definitions(-DUSE_GLOG)
|
||||
|
||||
set_property(SOURCE ${JNI_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE)
|
||||
set(JNI_SRC
|
||||
${JNI_SRC}
|
||||
${TOP_DIR}/mindspore/core/utils/log_adapter.cc
|
||||
|
@ -166,6 +166,7 @@ if(SUPPORT_TRAIN)
|
|||
${JNI_TRAIN_SRC}
|
||||
${TOP_DIR}/mindspore/core/utils/log_adapter.cc
|
||||
)
|
||||
set_property(SOURCE ${JNI_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_LITE)
|
||||
else()
|
||||
set(JNI_TRAIN_SRC
|
||||
${JNI_TRAIN_SRC}
|
||||
|
|
|
@ -534,10 +534,16 @@ if(SUPPORT_NNAPI)
|
|||
endif()
|
||||
|
||||
if(PLATFORM_ARM32 OR PLATFORM_ARM64 AND NOT TARGET_HIMIX
|
||||
AND NOT TARGET_MIX210 AND NOT TARGET_OHOS_LITE AND NOT MACHINE_LINUX_ARM64)
|
||||
AND NOT TARGET_MIX210 AND NOT TARGET_OHOS_LITE AND NOT MACHINE_LINUX_ARM64 AND NOT TARGET_OHOS)
|
||||
target_link_libraries(mindspore-lite log)
|
||||
target_link_libraries(mindspore-lite_static log)
|
||||
endif()
|
||||
|
||||
if(TARGET_OHOS)
|
||||
target_link_libraries(mindspore-lite hilog_ndk.z.so)
|
||||
target_link_libraries(mindspore-lite_static hilog_ndk.z.so)
|
||||
endif()
|
||||
|
||||
if(MSLITE_MINDDATA_IMPLEMENT STREQUAL "lite")
|
||||
target_link_libraries(mindspore-lite minddata_eager_mid minddata-lite)
|
||||
target_link_libraries(mindspore-lite_static minddata_eager_mid)
|
||||
|
|
|
@ -17,13 +17,13 @@
|
|||
#include <cstring>
|
||||
#include <cstdio>
|
||||
|
||||
#if defined(ENABLE_ARM) && (defined(__ANDROID__) || defined(ANDROID))
|
||||
#if defined(__ANDROID__)
|
||||
#include <android/log.h>
|
||||
#endif
|
||||
|
||||
// namespace to support utils module definition namespace mindspore constexpr const char *ANDROID_LOG_TAG = "MS_LITE";
|
||||
namespace mindspore {
|
||||
#if defined(ENABLE_ARM) && (defined(__ANDROID__) || defined(ANDROID))
|
||||
#if defined(__ANDROID__)
|
||||
constexpr const char *ANDROID_LOG_TAG = "MS_LITE";
|
||||
#endif
|
||||
|
||||
|
@ -55,7 +55,7 @@ bool IsPrint(int level) {
|
|||
return level >= ms_level;
|
||||
}
|
||||
|
||||
#if defined(ENABLE_ARM) && (defined(__ANDROID__) || defined(ANDROID))
|
||||
#if defined(__ANDROID__)
|
||||
static int GetAndroidLogLevel(LiteLogLevel level) {
|
||||
switch (level) {
|
||||
case LiteLogLevel::DEBUG:
|
||||
|
@ -71,6 +71,22 @@ static int GetAndroidLogLevel(LiteLogLevel level) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef MS_COMPILE_OHOS
|
||||
void PrintHiLog(LiteLogLevel level, const char *file, int line, const char *func, const char *msg) {
|
||||
if (level == LiteLogLevel::DEBUG) {
|
||||
OH_LOG_Print(LOG_APP, LOG_DEBUG, LOG_DOMAIN, LOG_TAG, FORMAT, file, line, func, msg);
|
||||
} else if (level == LiteLogLevel::INFO) {
|
||||
OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, LOG_TAG, FORMAT, file, line, func, msg);
|
||||
} else if (level == LiteLogLevel::WARNING) {
|
||||
OH_LOG_Print(LOG_APP, LOG_WARN, LOG_DOMAIN, LOG_TAG, FORMAT, file, line, func, msg);
|
||||
} else if (level == LiteLogLevel::ERROR) {
|
||||
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_DOMAIN, LOG_TAG, FORMAT, file, line, func, msg);
|
||||
} else {
|
||||
OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_DOMAIN, LOG_TAG, FORMAT, file, line, func, msg);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
const char *EnumStrForMsLogLevel(LiteLogLevel level) {
|
||||
if (level == LiteLogLevel::DEBUG) {
|
||||
return "DEBUG";
|
||||
|
@ -87,9 +103,11 @@ const char *EnumStrForMsLogLevel(LiteLogLevel level) {
|
|||
|
||||
void LiteLogWriter::OutputLog(const std::ostringstream &msg) const {
|
||||
if (IsPrint(static_cast<int>(log_level_))) {
|
||||
#if defined(ENABLE_ARM) && (defined(__ANDROID__) || defined(ANDROID))
|
||||
#if defined(__ANDROID__)
|
||||
__android_log_print(GetAndroidLogLevel(log_level_), ANDROID_LOG_TAG, "[%s:%d] %s] %s", location_.file_,
|
||||
location_.line_, location_.func_, msg.str().c_str());
|
||||
#elif defined(MS_COMPILE_OHOS)
|
||||
PrintHiLog(log_level_, location_.file_, location_.line_, location_.func_, msg.str().c_str());
|
||||
#else
|
||||
printf("%s [%s:%d] %s] %s\n", EnumStrForMsLogLevel(log_level_), location_.file_, location_.line_, location_.func_,
|
||||
msg.str().c_str());
|
||||
|
|
|
@ -23,6 +23,12 @@
|
|||
#include <unordered_map>
|
||||
#include "utils/overload.h"
|
||||
|
||||
#ifdef MS_COMPILE_OHOS
|
||||
#define LOG_DOMAIN 0x2102
|
||||
#define LOG_TAG "MS_Lite"
|
||||
#define FORMAT "[%{public}s:%{public}d] %{public}s# %{public}s"
|
||||
#include "hilog/log.h"
|
||||
#endif
|
||||
// NOTICE: when relative path of 'log.h' changed, macro 'LITE_LOG_HEAR_FILE_REL_PATH' must be changed
|
||||
#ifndef LITE_LOG_HEAR_FILE_REL_PATH
|
||||
#define LITE_LOG_HEAR_FILE_REL_PATH "mindspore/lite/src/common/log.h"
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#if defined(__ANDROID__) || defined(MS_COMPILE_OHOS)
|
||||
#include <sys/auxv.h>
|
||||
#include <asm/hwcap.h>
|
||||
#endif
|
||||
|
@ -141,7 +141,7 @@ std::vector<std::string> Tokenize(const std::string &src, const std::string &del
|
|||
return tokens;
|
||||
}
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#if defined(__ANDROID__) || defined(MS_COMPILE_OHOS)
|
||||
uint32_t getHwCap(int hwcap_type) {
|
||||
uint32_t ret = getauxval(hwcap_type);
|
||||
return ret;
|
||||
|
@ -151,7 +151,7 @@ uint32_t getHwCap(int hwcap_type) {
|
|||
bool IsSupportSDot() {
|
||||
bool status = false;
|
||||
#ifdef ENABLE_ARM64
|
||||
#if defined(__ANDROID__)
|
||||
#if defined(__ANDROID__) || defined(MS_COMPILE_OHOS)
|
||||
int hwcap_type = 16;
|
||||
uint32_t hwcap = getHwCap(hwcap_type);
|
||||
if (hwcap & HWCAP_ASIMDDP) {
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
#endif
|
||||
#endif
|
||||
namespace mindspore::lite {
|
||||
#ifdef __ANDROID__
|
||||
#if defined(__ANDROID__) || defined(MS_COMPILE_OHOS)
|
||||
uint32_t CpuInfo::MidrSetPart(uint32_t part) {
|
||||
return ((part << ARM_CPU_PART_OFFSET) & ARM_CPU_PART_MASK) | (midr_ & ~ARM_CPU_PART_MASK);
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ bool CpuInfo::ArmIsSupportFp16() {
|
|||
}
|
||||
return false;
|
||||
#else
|
||||
#ifdef __ANDROID__
|
||||
#if defined(__ANDROID__) || defined(MS_COMPILE_OHOS)
|
||||
#ifdef ENABLE_ARM32
|
||||
GetArmProcCpuInfo(&android_cpu_info_);
|
||||
midr_ = MidrSetPart(android_cpu_info_.cpu_part);
|
||||
|
|
|
@ -2,7 +2,11 @@ cmake_minimum_required(VERSION 3.12)
|
|||
project(Lite_benchmark)
|
||||
|
||||
if(NOT MSLITE_ENABLE_CLOUD_FUSION_INFERENCE)
|
||||
if(TARGET_OHOS)
|
||||
set(BENCHMARK_LINK_LIB libmindspore-lite.so)
|
||||
else()
|
||||
set(BENCHMARK_LINK_LIB mindspore-lite)
|
||||
endif()
|
||||
else()
|
||||
add_definitions(-DUSE_GLOG)
|
||||
set(BENCHMARK_LINK_LIB mindspore-extendrt)
|
||||
|
@ -82,6 +86,11 @@ add_executable(benchmark
|
|||
${C_SRC}
|
||||
${COMMON_SRC})
|
||||
|
||||
if(TARGET_OHOS)
|
||||
target_link_directories(benchmark PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../../src)
|
||||
add_dependencies(benchmark mindspore-lite)
|
||||
endif()
|
||||
|
||||
add_dependencies(benchmark fbs_src)
|
||||
|
||||
target_link_libraries(benchmark ${BENCHMARK_LINK_LIB})
|
||||
|
|
|
@ -11,6 +11,9 @@ if(NOT MSVC)
|
|||
#add flags
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/usr/local/include -Werror")
|
||||
endif()
|
||||
if(TARGET_OHOS)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-command-line-argument")
|
||||
endif()
|
||||
|
||||
include_directories(./include)
|
||||
add_subdirectory(src)
|
||||
|
|
Loading…
Reference in New Issue