From: @YeFeng_24
Reviewed-by: 
Signed-off-by: @hangangqiang
pull/13234/MERGE
mindspore-ci-bot 4 years ago committed by Gitee
commit fa0969e036

@ -205,7 +205,9 @@ function(mindspore_add_pkg pkg_name)
set(options)
set(oneValueArgs URL MD5 GIT_REPOSITORY GIT_TAG VER EXE DIR HEAD_ONLY CMAKE_PATH RELEASE LIB_PATH CUSTOM_CMAKE)
set(multiValueArgs CMAKE_OPTION LIBS PRE_CONFIGURE_COMMAND CONFIGURE_COMMAND BUILD_OPTION INSTALL_INCS INSTALL_LIBS PATCHES SUBMODULES SOURCEMODULES ONLY_MAKE ONLY_MAKE_INCS ONLY_MAKE_LIBS)
set(multiValueArgs
CMAKE_OPTION LIBS PRE_CONFIGURE_COMMAND CONFIGURE_COMMAND BUILD_OPTION INSTALL_INCS
INSTALL_LIBS PATCHES SUBMODULES SOURCEMODULES ONLY_MAKE ONLY_MAKE_INCS ONLY_MAKE_LIBS)
cmake_parse_arguments(PKG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT PKG_LIB_PATH)
@ -356,9 +358,13 @@ function(mindspore_add_pkg pkg_name)
-DCMAKE_INSTALL_PREFIX=${${pkg_name}_BASE_DIR} ${${pkg_name}_SOURCE_DIR}/${PKG_CMAKE_PATH}
WORKING_DIRECTORY ${${pkg_name}_SOURCE_DIR}/_build)
__exec_cmd(COMMAND ${CMAKE_COMMAND} --build . --target install -- -j${THNUM}
WORKING_DIRECTORY ${${pkg_name}_SOURCE_DIR}/_build)
if(APPLE)
__exec_cmd(COMMAND ${CMAKE_COMMAND} --build . --target install --
WORKING_DIRECTORY ${${pkg_name}_SOURCE_DIR}/_build)
else()
__exec_cmd(COMMAND ${CMAKE_COMMAND} --build . --target install -- -j${THNUM}
WORKING_DIRECTORY ${${pkg_name}_SOURCE_DIR}/_build)
endif()
else()
if(${pkg_name}_CFLAGS)
set(${pkg_name}_MAKE_CFLAGS "CFLAGS=${${pkg_name}_CFLAGS}")
@ -387,8 +393,13 @@ function(mindspore_add_pkg pkg_name)
${${pkg_name}_MAKE_CFLAGS} ${${pkg_name}_MAKE_CXXFLAGS} ${${pkg_name}_MAKE_LDFLAGS})
endif()
# build
__exec_cmd(COMMAND ${CMAKE_MAKE_PROGRAM} ${${pkg_name}_BUILD_OPTION} -j${THNUM}
WORKING_DIRECTORY ${${pkg_name}_SOURCE_DIR})
if(APPLE)
__exec_cmd(COMMAND ${CMAKE_MAKE_PROGRAM} ${${pkg_name}_BUILD_OPTION}
WORKING_DIRECTORY ${${pkg_name}_SOURCE_DIR})
else()
__exec_cmd(COMMAND ${CMAKE_MAKE_PROGRAM} ${${pkg_name}_BUILD_OPTION} -j${THNUM}
WORKING_DIRECTORY ${${pkg_name}_SOURCE_DIR})
endif()
if(PKG_INSTALL_INCS OR PKG_INSTALL_LIBS)
file(GLOB ${pkg_name}_INSTALL_INCS ${${pkg_name}_SOURCE_DIR}/${PKG_INSTALL_INCS})

@ -135,6 +135,10 @@ if(SUPPORT_TRAIN OR WIN32)
set(ENABLE_MINDRT "off")
endif()
if(DEFINED ARCHS)
add_definitions(-DMS_COMPILE_IOS)
endif()
file(GLOB FBS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/schema/*.fbs)
ms_build_flatbuffers_lite(FBS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/schema/ fbs_src ${CMAKE_BINARY_DIR}/schema "")
ms_build_flatbuffers_lite(FBS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/schema/ fbs_inner_src ${CMAKE_BINARY_DIR}/schema/inner
@ -221,7 +225,7 @@ endif()
if(PLATFORM_ARM32 OR PLATFORM_ARM64)
if(NOT DEFINED ENV{ANDROID_NDK})
if(NOT APPLE AND NOT DEFINED ENV{ANDROID_NDK})
message(FATAL_ERROR "env ANDROID_NDK should be set for ARM compile")
endif()
add_compile_definitions(ENABLE_ARM)
@ -267,7 +271,7 @@ endif()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/nnacl)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/micro/coder)
if(ENABLE_TOOLS)
if(NOT APPLE AND ENABLE_TOOLS)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/benchmark)
if(SUPPORT_TRAIN)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/benchmark_train)
@ -285,5 +289,6 @@ if(NOT WIN32)
endif()
endif()
include(${TOP_DIR}/cmake/package_lite.cmake)
if(NOT APPLE)
include(${TOP_DIR}/cmake/package_lite.cmake)
endif()

@ -4,7 +4,13 @@ set(NNACL_DIR ${CMAKE_CURRENT_SOURCE_DIR})
include_directories(NNACL_DIR)
if(PLATFORM_ARM32 OR PLATFORM_ARM64)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND DEFINED ARCHS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstrict-aliasing \
-ffunction-sections -fdata-sections -ffast-math -Wno-shorten-64-to-32")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstrict-aliasing \
-ffunction-sections -fdata-sections -ffast-math -Wno-shorten-64-to-32")
endif()
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND NOT DEFINED ARCHS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer -fstrict-aliasing \
-ffunction-sections -fdata-sections -ffast-math")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fomit-frame-pointer -fstrict-aliasing \
@ -51,6 +57,10 @@ if("${X86_64_SIMD}" STREQUAL "avx")
set_property(SOURCE ${ASSEMBLY_SRC} PROPERTY LANGUAGE C)
endif()
if(APPLE)
set_source_files_properties(${ASSEMBLY_SRC} PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp")
endif()
########################### build nnacl static library ########################
string(REPLACE "-fvisibility=hidden" "-fvisibility=default" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
add_library(nnacl STATIC ${KERNEL_SRC} ${TRAIN_SRC} ${ASSEMBLY_SRC})

@ -18,15 +18,16 @@
.macro asm_function fname
#ifdef __APPLE__
.globl _\fname _\fname :
.globl _\fname;
_\fname :
#else
.global \fname
.global \fname;
#ifdef __ELE__
.hidden \fname.type \fname,
% function
.hidden \fname;
.type \fname, % function;
#endif
\fname :
#endif
.endm
.endm
#endif // MINDSPORE_LITE_NNACL_ASSEMBLY_GLOBAL_H

@ -14,6 +14,7 @@
* limitations under the License.
*/
#include "nnacl/fp16/activation_fp16.h"
#include <float.h>
#include "nnacl/fp32/exp_fp32.h"
#include "nnacl/errorcode.h"

@ -16,6 +16,7 @@
#include "nnacl/fp16/lstm_fp16.h"
#include <string.h>
#include <float.h>
#include "nnacl/fp16/activation_fp16.h"
#include "nnacl/fp16/arithmetic_fp16.h"
#include "nnacl/fp16/matmul_fp16.h"

@ -12,6 +12,10 @@ set_property(SOURCE ${SDOT_SRC} PROPERTY LANGUAGE C)
set_property(SOURCE ${FP16_C_SRC} PROPERTY LANGUAGE C)
set_property(SOURCE ${FP16_NEON_SRC} PROPERTY LANGUAGE C)
if(APPLE)
set_source_files_properties(${SDOT_SRC} PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp")
set_source_files_properties(${FP16_NEON_SRC} PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp")
endif()
########################### share library build ########################
list(APPEND SDOT_FILES ${SDOT_SRC})
list(APPEND FP16_FILES ${FP16_C_SRC})

@ -8,12 +8,18 @@ include_directories(${LITE_DIR}/nnacl/optimize)
if(PLATFORM_ARM32 OR PLATFORM_ARM64)
#for performance
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND NOT APPLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer -fstrict-aliasing -ffunction-sections \
-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")
endif()
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND APPLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstrict-aliasing -ffunction-sections \
-fdata-sections -ffast-math -fno-rtti -fno-exceptions -Wno-shorten-64-to-32")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstrict-aliasing -ffunction-sections \
-fdata-sections -ffast-math -fno-rtti -fno-exceptions -Wno-shorten-64-to-32")
endif()
endif()
set(API_SRC
@ -182,18 +188,18 @@ if(SUPPORT_TRAIN)
endif()
if(PLATFORM_ARM)
if(NOT APPLE AND PLATFORM_ARM)
set(NDK_STRIP
"${ANDROID_NDK}/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/aarch64-linux-android/bin/strip")
endif()
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND PLATFORM_ARM)
if(NOT APPLE AND "${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND PLATFORM_ARM)
add_custom_command(TARGET mindspore-lite POST_BUILD COMMAND ${NDK_STRIP}
${CMAKE_BINARY_DIR}/src/libmindspore-lite.so)
endif()
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
if(PLATFORM_ARM)
if(NOT APPLE AND PLATFORM_ARM)
add_custom_command(TARGET mindspore-lite POST_BUILD COMMAND ${NDK_STRIP}
${CMAKE_BINARY_DIR}/src/libmindspore-lite.so)
elseif(NOT WIN32)
@ -210,3 +216,54 @@ if(PLATFORM_ARM64)
target_link_libraries(mindspore-lite_static cpu_fp16_kernel_mid nnacl_fp16_mid)
endif()
endif()
if(DEFINED ARCHS)
set(MINDSPORE_LITE_PUB_HDRS
${CMAKE_CURRENT_SOURCE_DIR}/../include/context.h
${CMAKE_CURRENT_SOURCE_DIR}/../include/errorcode.h
${CMAKE_CURRENT_SOURCE_DIR}/../include/lite_session.h
${CMAKE_CURRENT_SOURCE_DIR}/../include/lite_types.h
${CMAKE_CURRENT_SOURCE_DIR}/../include/lite_utils.h
${CMAKE_CURRENT_SOURCE_DIR}/../include/model.h
${CMAKE_CURRENT_SOURCE_DIR}/../include/ms_tensor.h
${CMAKE_CURRENT_SOURCE_DIR}/../include/version.h
)
set(MINDSPORE_LITE_PUB_HDRS_IR_HDRS
${CMAKE_CURRENT_SOURCE_DIR}/../../core/ir/dtype/type_id.h
)
add_library(mindspore_lite STATIC
${LITE_SRC}
${MINDSPORE_LITE_PUB_HDRS}
${MINDSPORE_LITE_PUB_HDRS_IR_HDRS}
)
add_dependencies(mindspore_lite fbs_src)
set_target_properties(mindspore_lite PROPERTIES OUTPUT_NAME "mindspore_lite")
set_target_properties(mindspore_lite PROPERTIES CLEAN_DIRECT_OUTPUT 1)
target_link_libraries(mindspore_lite cpu_kernel_mid nnacl_mid cpu_ops_mid)
target_link_libraries(mindspore_lite log)
if(ENABLE_MINDRT)
target_link_libraries(mindspore_lite mindrt_mid)
endif()
if(PLATFORM_ARM64)
target_link_libraries(mindspore_lite cpu_opt_kernel_mid nnacl_optimize_mid)
if(ENABLE_FP16)
target_link_libraries(mindspore_lite cpu_fp16_kernel_mid nnacl_fp16_mid)
endif()
endif()
set_target_properties(mindspore_lite PROPERTIES FRAMEWORK TRUE)
set_target_properties(mindspore_lite PROPERTIES
OUTPUT_NAME "mindspore_lite"
FRAMEWORK_VERSION C
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer"
XCODE_ATTRIBUTE_INSTALL_PAYH "@rpath"
)
FOREACH(HDR ${MINDSPORE_LITE_PUB_HDRS})
SET_SOURCE_FILES_PROPERTIES(${HDR} PROPERTIES MACOSX_PACKAGE_LOCATION Headers/)
ENDFOREACH()
FOREACH(HDR ${MINDSPORE_LITE_PUB_HDRS_IR_HDRS})
SET_SOURCE_FILES_PROPERTIES(${HDR} PROPERTIES MACOSX_PACKAGE_LOCATION Headers/ir/dtype/)
ENDFOREACH()
target_link_libraries(mindspore_lite)
endif()

@ -19,12 +19,16 @@
#include <cstdio>
#ifdef ENABLE_ARM
#if defined(__ANDROID__) || defined(ANDROID)
#include <android/log.h>
#endif
#endif
// namespace to support utils module definition namespace mindspore constexpr const char *ANDROID_LOG_TAG = "MS_LITE";
namespace mindspore {
#if defined(__ANDROID__) || defined(ANDROID)
constexpr const char *ANDROID_LOG_TAG = "MS_LITE";
#endif
int StrToInt(const char *env) {
if (env == nullptr) return 2;
@ -45,6 +49,7 @@ bool IsPrint(int level) {
}
#ifdef ENABLE_ARM
#if defined(__ANDROID__) || defined(ANDROID)
// convert MsLogLevel to corresponding android level
static int GetAndroidLogLevel(MsLogLevel level) {
switch (level) {
@ -60,6 +65,7 @@ static int GetAndroidLogLevel(MsLogLevel level) {
}
}
#endif
#endif
const char *EnumStrForMsLogLevel(MsLogLevel level) {
if (level == DEBUG) {
@ -78,8 +84,10 @@ const char *EnumStrForMsLogLevel(MsLogLevel level) {
void LogWriter::OutputLog(const std::ostringstream &msg) const {
if (IsPrint(log_level_)) {
#ifdef ENABLE_ARM
#if defined(__ANDROID__) || 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());
#endif
#else
printf("%s [%s:%d] %s] %s\n", EnumStrForMsLogLevel(log_level_), location_.file_, location_.line_, location_.func_,
msg.str().c_str());

@ -138,6 +138,7 @@ uint32_t getHwCap(int hwcap_type) {
bool IsSupportSDot() {
bool status = false;
#ifdef ENABLE_ARM64
#if defined(__ANDROID__)
int hwcap_type = 16;
uint32_t hwcap = getHwCap(hwcap_type);
if (hwcap & HWCAP_ASIMDDP) {
@ -147,6 +148,7 @@ bool IsSupportSDot() {
MS_LOG(DEBUG) << "Hw cap NOT support SIMD Dot Product, hwcap: 0x" << hwcap;
status = false;
}
#endif
#endif
return status;
}
@ -154,6 +156,7 @@ bool IsSupportSDot() {
bool IsSupportFloat16() {
bool status = false;
#ifdef ENABLE_ARM64
#if defined(__ANDROID__)
int hwcap_type = 16;
uint32_t hwcap = getHwCap(hwcap_type);
if (hwcap & HWCAP_FPHP) {
@ -163,6 +166,7 @@ bool IsSupportFloat16() {
MS_LOG(DEBUG) << "Hw cap NOT support FP16, hwcap: 0x" << hwcap;
status = false;
}
#endif
#endif
return status;
}

@ -20,7 +20,9 @@
#include "src/common/prim_util.h"
#include "nnacl/pooling_parameter.h"
#ifdef ENABLE_ARM64
#if defined(__ANDROID__)
#include <asm/hwcap.h>
#endif
#include "common/utils.h"
#include "src/common/log_adapter.h"
#include "src/common/utils.h"

@ -23,8 +23,10 @@
#include <limits>
#ifdef ENABLE_ARM
#include <arm_neon.h>
#if defined(__ANDROID__) || defined(ANDROID)
#include <android/log.h>
#endif
#endif
#include "src/lite_kernel.h"
#include "include/context.h"
#include "src/runtime/kernel/arm/base/layout_transform.h"

@ -40,7 +40,7 @@ int RandomStandardNormalCPUKernel::Run() {
} else {
random_seed = static_cast<size_t>(clock());
}
std::default_random_engine engine{random_seed};
std::default_random_engine engine{static_cast<unsigned int>(random_seed)};
std::normal_distribution<double> nums(0, 1.0);
auto all_data_nums = out_tensors_[0]->ElementsNum();
auto out_data = out_tensors_[0]->data_c();

@ -16,6 +16,7 @@
#include "src/runtime/kernel/arm/fp16/lstm_fp16.h"
#include <vector>
#include <cfloat>
#include "schema/model_generated.h"
#include "src/kernel_registry.h"
#include "include/errorcode.h"

@ -18,6 +18,7 @@
#include <arm_neon.h>
#include <vector>
#include <cfloat>
#include "src/lite_kernel.h"
#include "src/runtime/kernel/arm/base/pooling_base.h"

@ -27,6 +27,11 @@
#include <unistd.h>
#include <sched.h>
#endif
#ifdef MS_COMPILE_IOS
#include <sys/types.h>
#include <sys/sysctl.h>
#include <mach/machine.h>
#endif // MS_COMPILE_IOS
#ifdef THREAD_POOL_DEBUG
#include <stdio.h>

Loading…
Cancel
Save