From 30f189e999d698cc70683310e45064f03dfee83b Mon Sep 17 00:00:00 2001 From: yefeng Date: Sat, 5 Jun 2021 10:17:17 +0800 Subject: [PATCH] fix ios --- build.sh | 20 +++--- mindspore/core/mindrt/src/actor/actormgr.cc | 12 ++++ mindspore/core/mindrt/src/actor/actormgr.h | 8 ++- mindspore/lite/src/CMakeLists.txt | 67 +++++++++------------ mindspore/lite/src/cpu_info.cc | 2 + mindspore/lite/src/cpu_info.h | 2 + mindspore/lite/src/inner_context.cc | 6 ++ mindspore/lite/src/inner_context.h | 4 ++ 8 files changed, 69 insertions(+), 52 deletions(-) diff --git a/build.sh b/build.sh index 6b6eddf05da..85545dceddb 100755 --- a/build.sh +++ b/build.sh @@ -572,7 +572,7 @@ build_lite() if [ "$(uname)" == "Darwin" ]; then cmake -DCMAKE_TOOLCHAIN_FILE=${BASEPATH}/cmake/lite_ios.cmake -DARCHS="arm64" -DENABLE_BITCODE=0 \ -DCMAKE_BUILD_TYPE="Release" -DBUILD_MINDDATA="" -DPLATFORM_ARM64="on" -DENABLE_NEON="on" -DENABLE_FP16="on" \ - -DMSLITE_ENABLE_TRAIN="off" -DENABLE_MINDRT="off" -DMSLITE_GPU_BACKEND="off" -DMSLITE_ENABLE_NPU="off" \ + -DMSLITE_ENABLE_TRAIN="off" -DENABLE_MINDRT="on" -DMSLITE_GPU_BACKEND="off" -DMSLITE_ENABLE_NPU="off" \ -DENABLE_ASAN=${ENABLE_ASAN} -DCMAKE_INSTALL_PREFIX=${BUILD_PATH}/output/tmp -G Xcode .. else checkndk @@ -586,9 +586,9 @@ build_lite() fi elif [[ "${local_lite_platform}" == "arm32" ]]; then if [ "$(uname)" == "Darwin" ]; then - cmake -DCMAKE_TOOLCHAIN_FILE=${BASEPATH}/cmake/lite_ios.cmake -DARCHS="armv7;armv7s" -DENABLE_BITCODE=0 \ - -DCMAKE_BUILD_TYPE="Release" -DBUILD_MINDDATA="" -DPLATFORM_ARM32="on" -DENABLE_NEON="on" \ - -DMSLITE_ENABLE_TRAIN="off" -DENABLE_MINDRT="off" \ + cmake -DCMAKE_TOOLCHAIN_FILE=${BASEPATH}/cmake/lite_ios.cmake -DARCHS="armv7;armv7s" -DENABLE_BITCODE=0 \ + -DCMAKE_BUILD_TYPE="Release" -DBUILD_MINDDATA="" -DPLATFORM_ARM32="on" -DENABLE_NEON="on" \ + -DMSLITE_ENABLE_TRAIN="off" -DENABLE_MINDRT="on" -DMSLITE_GPU_BACKEND="off" -DMSLITE_ENABLE_NPU="off" \ -DENABLE_ASAN=${ENABLE_ASAN} -DCMAKE_INSTALL_PREFIX=${BUILD_PATH}/output/tmp -G Xcode .. else checkndk @@ -606,7 +606,7 @@ build_lite() -DENABLE_ASAN=${ENABLE_ASAN} -DCMAKE_INSTALL_PREFIX=${BASEPATH}/output/tmp -DENABLE_VERBOSE=${ENABLE_VERBOSE} "${BASEPATH}/mindspore/lite" fi if [ "$(uname)" == "Darwin" ]; then - xcodebuild ONLY_ACTIVE_ARCH=NO -configuration Release -scheme mindspore_lite -target mindspore_lite -sdk iphoneos -quiet + xcodebuild ONLY_ACTIVE_ARCH=NO -configuration Release -scheme mindspore-lite_static -target mindspore-lite_static -sdk iphoneos -quiet else make -j$THREAD_NUM && make install && make package if [[ "${local_lite_platform}" == "x86_64" ]]; then @@ -625,12 +625,12 @@ build_lite() else if [ "$(uname)" == "Darwin" ]; then mkdir -p ${BASEPATH}/output - cp -r ${BASEPATH}/mindspore/lite/build/src/Release-iphoneos/mindspore_lite.framework ${BASEPATH}/output/mindspore_lite.framework + cp -r ${BASEPATH}/mindspore/lite/build/src/Release-iphoneos/mindspore-lite.framework ${BASEPATH}/output/mindspore-lite.framework cd ${BASEPATH}/output - tar -zcvf mindspore_lite.framework-${VERSION_STR}-${local_lite_platform}.tar.gz mindspore_lite.framework/ - sha256sum mindspore_lite.framework-${VERSION_STR}-${local_lite_platform}.tar.gz > \ - mindspore_lite.framework-${VERSION_STR}-${local_lite_platform}.tar.gz.sha256 - rm -r mindspore_lite.framework + tar -zcvf mindspore-lite.framework-${VERSION_STR}-${local_lite_platform}.tar.gz mindspore-lite.framework/ + sha256sum mindspore-lite.framework-${VERSION_STR}-${local_lite_platform}.tar.gz > \ + mindspore-lite.framework-${VERSION_STR}-${local_lite_platform}.tar.gz.sha256 + rm -r mindspore-lite.framework else mv ${BASEPATH}/output/tmp/*.tar.gz* ${BASEPATH}/output/ fi diff --git a/mindspore/core/mindrt/src/actor/actormgr.cc b/mindspore/core/mindrt/src/actor/actormgr.cc index dbe066d42d7..4d9c7283637 100644 --- a/mindspore/core/mindrt/src/actor/actormgr.cc +++ b/mindspore/core/mindrt/src/actor/actormgr.cc @@ -114,14 +114,26 @@ void ActorMgr::Finalize() { } ActorBase *ActorMgr::GetActor(const AID &id) { +#ifndef MS_COMPILE_IOS actorsMutex.lock_shared(); +#else + actorsMutex.lock(); +#endif const auto &actorIt = actors.find(id.Name()); if (actorIt != actors.end()) { auto &result = actorIt->second; +#ifndef MS_COMPILE_IOS actorsMutex.unlock_shared(); +#else + actorsMutex.unlock(); +#endif return result.get(); } else { +#ifndef MS_COMPILE_IOS actorsMutex.unlock_shared(); +#else + actorsMutex.unlock(); +#endif MS_LOG(DEBUG) << "can't find ACTOR with name=" << id.Name().c_str(); return nullptr; } diff --git a/mindspore/core/mindrt/src/actor/actormgr.h b/mindspore/core/mindrt/src/actor/actormgr.h index 1681d3700c5..d129ce254dd 100644 --- a/mindspore/core/mindrt/src/actor/actormgr.h +++ b/mindspore/core/mindrt/src/actor/actormgr.h @@ -22,8 +22,9 @@ #include #include #include +#ifndef MS_COMPILE_IOS #include - +#endif #include "actor/actor.h" #include "thread/inter_threadpool.h" @@ -83,8 +84,11 @@ class ActorMgr { } // Map of all local spawned and running processes. std::map actors; +#ifndef MS_COMPILE_IOS std::shared_mutex actorsMutex; - +#else + std::mutex actorsMutex; +#endif std::map procotols; std::set urls; std::string delegate; diff --git a/mindspore/lite/src/CMakeLists.txt b/mindspore/lite/src/CMakeLists.txt index d31be860170..2a82e90f2bd 100644 --- a/mindspore/lite/src/CMakeLists.txt +++ b/mindspore/lite/src/CMakeLists.txt @@ -157,7 +157,29 @@ add_dependencies(lite_src_mid fbs_src) add_library(mindspore-lite SHARED $) set_target_properties(mindspore-lite PROPERTIES CLEAN_DIRECT_OUTPUT 1) -add_library(mindspore-lite_static STATIC $) +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 STATIC + ${LITE_SRC} + ${MINDSPORE_LITE_PUB_HDRS} + ${MINDSPORE_LITE_PUB_HDRS_IR_HDRS} + ) + add_dependencies(mindspore-lite_static fbs_inner_src) +else() + add_library(mindspore-lite_static STATIC $) +endif() set_target_properties(mindspore-lite_static PROPERTIES OUTPUT_NAME "mindspore-lite") set_target_properties(mindspore-lite_static PROPERTIES CLEAN_DIRECT_OUTPUT 1) @@ -224,44 +246,9 @@ if(PLATFORM_ARM) 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 - ${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 lite_src_mid 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_ARM) - if(PLATFORM_ARM64) - target_link_libraries(mindspore_lite cpu_opt_kernel_mid nnacl_optimize_mid) - endif() - 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" + set_target_properties(mindspore-lite_static PROPERTIES FRAMEWORK TRUE) + set_target_properties(mindspore-lite_static PROPERTIES + OUTPUT_NAME "mindspore-lite" FRAMEWORK_VERSION C XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer" XCODE_ATTRIBUTE_INSTALL_PAYH "@rpath" @@ -272,7 +259,7 @@ if(DEFINED ARCHS) FOREACH(HDR ${MINDSPORE_LITE_PUB_HDRS_IR_HDRS}) SET_SOURCE_FILES_PROPERTIES(${HDR} PROPERTIES MACOSX_PACKAGE_LOCATION Headers/include/ir/dtype/) ENDFOREACH() - target_link_libraries(mindspore_lite) + target_link_libraries(mindspore-lite_static) endif() if(NOT WIN32) diff --git a/mindspore/lite/src/cpu_info.cc b/mindspore/lite/src/cpu_info.cc index 9786530be72..2917377bd91 100644 --- a/mindspore/lite/src/cpu_info.cc +++ b/mindspore/lite/src/cpu_info.cc @@ -14,6 +14,7 @@ * limitations under the License. */ #ifdef ENABLE_ARM +#ifndef MS_COMPILE_IOS #include "src/cpu_info.h" #include #include @@ -144,3 +145,4 @@ bool CpuInfo::ArmIsSupportFp16() { } } // namespace mindspore::lite #endif +#endif diff --git a/mindspore/lite/src/cpu_info.h b/mindspore/lite/src/cpu_info.h index cd3be525737..d8a4a07cc21 100644 --- a/mindspore/lite/src/cpu_info.h +++ b/mindspore/lite/src/cpu_info.h @@ -14,6 +14,7 @@ * limitations under the License. */ #ifdef ENABLE_ARM +#ifndef MS_COMPILE_IOS #include #ifndef MINDSPORE_LITE_SRC_CPU_INFO_H #define MINDSPORE_LITE_SRC_CPU_INFO_H @@ -48,3 +49,4 @@ class CpuInfo { } // namespace mindspore::lite #endif // MINDSPORE_LITE_SRC_CPU_INFO_H #endif +#endif diff --git a/mindspore/lite/src/inner_context.cc b/mindspore/lite/src/inner_context.cc index 1c46a51425f..23529f35a4f 100644 --- a/mindspore/lite/src/inner_context.cc +++ b/mindspore/lite/src/inner_context.cc @@ -34,9 +34,11 @@ InnerContext::InnerContext(const Context *context) { this->device_list_.push_back(device_ctx); } #ifdef ENABLE_ARM +#ifndef MS_COMPILE_IOS cpu_info_ = new CpuInfo; fp16_flag_ = cpu_info_->ArmIsSupportFp16(); #endif +#endif } #if SUPPORT_NPU @@ -60,9 +62,11 @@ InnerContext::InnerContext(const Context *context, NPUManager *npu_manager) { } this->npu_manager_ = npu_manager; #ifdef ENABLE_ARM +#ifndef MS_COMPILE_IOS cpu_info_ = new CpuInfo; fp16_flag_ = cpu_info_->ArmIsSupportFp16(); #endif +#endif } #endif @@ -120,8 +124,10 @@ InnerContext::~InnerContext() { this->thread_pool_ = nullptr; } #ifdef ENABLE_ARM +#ifndef MS_COMPILE_IOS delete cpu_info_; #endif +#endif } int InnerContext::IsValid() const { diff --git a/mindspore/lite/src/inner_context.h b/mindspore/lite/src/inner_context.h index 3231b4624e3..9aefa14b962 100644 --- a/mindspore/lite/src/inner_context.h +++ b/mindspore/lite/src/inner_context.h @@ -83,12 +83,16 @@ struct InnerContext : public Context { bool fp16_flag_ = false; #ifdef ENABLE_ARM +#ifndef MS_COMPILE_IOS CpuInfo *cpu_info_ = nullptr; #endif +#endif #if SUPPORT_NPU +#ifndef MS_COMPILE_IOS NPUManager *npu_manager_ = nullptr; #endif +#endif }; } // namespace mindspore::lite