!17794 [LITE][IOS] fix ios compile

From: @YeFeng_24
Reviewed-by: @hangangqiang,@zhanghaibo5
Signed-off-by: @hangangqiang
This commit is contained in:
mindspore-ci-bot 2021-06-07 09:31:31 +08:00 committed by Gitee
commit 01dd276bf7
8 changed files with 69 additions and 52 deletions

View File

@ -572,7 +572,7 @@ build_lite()
if [ "$(uname)" == "Darwin" ]; then if [ "$(uname)" == "Darwin" ]; then
cmake -DCMAKE_TOOLCHAIN_FILE=${BASEPATH}/cmake/lite_ios.cmake -DARCHS="arm64" -DENABLE_BITCODE=0 \ 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" \ -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 .. -DENABLE_ASAN=${ENABLE_ASAN} -DCMAKE_INSTALL_PREFIX=${BUILD_PATH}/output/tmp -G Xcode ..
else else
checkndk checkndk
@ -586,9 +586,9 @@ build_lite()
fi fi
elif [[ "${local_lite_platform}" == "arm32" ]]; then elif [[ "${local_lite_platform}" == "arm32" ]]; then
if [ "$(uname)" == "Darwin" ]; then if [ "$(uname)" == "Darwin" ]; then
cmake -DCMAKE_TOOLCHAIN_FILE=${BASEPATH}/cmake/lite_ios.cmake -DARCHS="armv7;armv7s" -DENABLE_BITCODE=0 \ 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" \ -DCMAKE_BUILD_TYPE="Release" -DBUILD_MINDDATA="" -DPLATFORM_ARM32="on" -DENABLE_NEON="on" \
-DMSLITE_ENABLE_TRAIN="off" -DENABLE_MINDRT="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 .. -DENABLE_ASAN=${ENABLE_ASAN} -DCMAKE_INSTALL_PREFIX=${BUILD_PATH}/output/tmp -G Xcode ..
else else
checkndk checkndk
@ -606,7 +606,7 @@ build_lite()
-DENABLE_ASAN=${ENABLE_ASAN} -DCMAKE_INSTALL_PREFIX=${BASEPATH}/output/tmp -DENABLE_VERBOSE=${ENABLE_VERBOSE} "${BASEPATH}/mindspore/lite" -DENABLE_ASAN=${ENABLE_ASAN} -DCMAKE_INSTALL_PREFIX=${BASEPATH}/output/tmp -DENABLE_VERBOSE=${ENABLE_VERBOSE} "${BASEPATH}/mindspore/lite"
fi fi
if [ "$(uname)" == "Darwin" ]; then 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 else
make -j$THREAD_NUM && make install && make package make -j$THREAD_NUM && make install && make package
if [[ "${local_lite_platform}" == "x86_64" ]]; then if [[ "${local_lite_platform}" == "x86_64" ]]; then
@ -625,12 +625,12 @@ build_lite()
else else
if [ "$(uname)" == "Darwin" ]; then if [ "$(uname)" == "Darwin" ]; then
mkdir -p ${BASEPATH}/output 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 cd ${BASEPATH}/output
tar -zcvf mindspore_lite.framework-${VERSION_STR}-${local_lite_platform}.tar.gz 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 > \ sha256sum mindspore-lite.framework-${VERSION_STR}-${local_lite_platform}.tar.gz > \
mindspore_lite.framework-${VERSION_STR}-${local_lite_platform}.tar.gz.sha256 mindspore-lite.framework-${VERSION_STR}-${local_lite_platform}.tar.gz.sha256
rm -r mindspore_lite.framework rm -r mindspore-lite.framework
else else
mv ${BASEPATH}/output/tmp/*.tar.gz* ${BASEPATH}/output/ mv ${BASEPATH}/output/tmp/*.tar.gz* ${BASEPATH}/output/
fi fi

View File

@ -114,14 +114,26 @@ void ActorMgr::Finalize() {
} }
ActorBase *ActorMgr::GetActor(const AID &id) { ActorBase *ActorMgr::GetActor(const AID &id) {
#ifndef MS_COMPILE_IOS
actorsMutex.lock_shared(); actorsMutex.lock_shared();
#else
actorsMutex.lock();
#endif
const auto &actorIt = actors.find(id.Name()); const auto &actorIt = actors.find(id.Name());
if (actorIt != actors.end()) { if (actorIt != actors.end()) {
auto &result = actorIt->second; auto &result = actorIt->second;
#ifndef MS_COMPILE_IOS
actorsMutex.unlock_shared(); actorsMutex.unlock_shared();
#else
actorsMutex.unlock();
#endif
return result.get(); return result.get();
} else { } else {
#ifndef MS_COMPILE_IOS
actorsMutex.unlock_shared(); actorsMutex.unlock_shared();
#else
actorsMutex.unlock();
#endif
MS_LOG(DEBUG) << "can't find ACTOR with name=" << id.Name().c_str(); MS_LOG(DEBUG) << "can't find ACTOR with name=" << id.Name().c_str();
return nullptr; return nullptr;
} }

View File

@ -22,8 +22,9 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <string> #include <string>
#ifndef MS_COMPILE_IOS
#include <shared_mutex> #include <shared_mutex>
#endif
#include "actor/actor.h" #include "actor/actor.h"
#include "thread/inter_threadpool.h" #include "thread/inter_threadpool.h"
@ -83,8 +84,11 @@ class ActorMgr {
} }
// Map of all local spawned and running processes. // Map of all local spawned and running processes.
std::map<std::string, ActorReference> actors; std::map<std::string, ActorReference> actors;
#ifndef MS_COMPILE_IOS
std::shared_mutex actorsMutex; std::shared_mutex actorsMutex;
#else
std::mutex actorsMutex;
#endif
std::map<std::string, std::string> procotols; std::map<std::string, std::string> procotols;
std::set<std::string> urls; std::set<std::string> urls;
std::string delegate; std::string delegate;

View File

@ -148,7 +148,29 @@ add_dependencies(lite_src_mid fbs_src)
add_library(mindspore-lite SHARED $<TARGET_OBJECTS:lite_src_mid>) add_library(mindspore-lite SHARED $<TARGET_OBJECTS:lite_src_mid>)
set_target_properties(mindspore-lite PROPERTIES CLEAN_DIRECT_OUTPUT 1) set_target_properties(mindspore-lite PROPERTIES CLEAN_DIRECT_OUTPUT 1)
add_library(mindspore-lite_static STATIC $<TARGET_OBJECTS:lite_src_mid>) 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 $<TARGET_OBJECTS:lite_src_mid>)
endif()
set_target_properties(mindspore-lite_static PROPERTIES OUTPUT_NAME "mindspore-lite") set_target_properties(mindspore-lite_static PROPERTIES OUTPUT_NAME "mindspore-lite")
set_target_properties(mindspore-lite_static PROPERTIES CLEAN_DIRECT_OUTPUT 1) set_target_properties(mindspore-lite_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
@ -223,44 +245,9 @@ if(PLATFORM_ARM)
endif() endif()
if(DEFINED ARCHS) if(DEFINED ARCHS)
set(MINDSPORE_LITE_PUB_HDRS set_target_properties(mindspore-lite_static PROPERTIES FRAMEWORK TRUE)
${CMAKE_CURRENT_SOURCE_DIR}/../include/context.h set_target_properties(mindspore-lite_static PROPERTIES
${CMAKE_CURRENT_SOURCE_DIR}/../include/errorcode.h OUTPUT_NAME "mindspore-lite"
${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"
FRAMEWORK_VERSION C FRAMEWORK_VERSION C
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer" XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer"
XCODE_ATTRIBUTE_INSTALL_PAYH "@rpath" XCODE_ATTRIBUTE_INSTALL_PAYH "@rpath"
@ -271,7 +258,7 @@ if(DEFINED ARCHS)
FOREACH(HDR ${MINDSPORE_LITE_PUB_HDRS_IR_HDRS}) FOREACH(HDR ${MINDSPORE_LITE_PUB_HDRS_IR_HDRS})
SET_SOURCE_FILES_PROPERTIES(${HDR} PROPERTIES MACOSX_PACKAGE_LOCATION Headers/include/ir/dtype/) SET_SOURCE_FILES_PROPERTIES(${HDR} PROPERTIES MACOSX_PACKAGE_LOCATION Headers/include/ir/dtype/)
ENDFOREACH() ENDFOREACH()
target_link_libraries(mindspore_lite) target_link_libraries(mindspore-lite_static)
endif() endif()
if(NOT WIN32) if(NOT WIN32)

View File

@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#ifdef ENABLE_ARM #ifdef ENABLE_ARM
#ifndef MS_COMPILE_IOS
#include "src/cpu_info.h" #include "src/cpu_info.h"
#include <sys/auxv.h> #include <sys/auxv.h>
#include <asm/hwcap.h> #include <asm/hwcap.h>
@ -144,3 +145,4 @@ bool CpuInfo::ArmIsSupportFp16() {
} }
} // namespace mindspore::lite } // namespace mindspore::lite
#endif #endif
#endif

View File

@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#ifdef ENABLE_ARM #ifdef ENABLE_ARM
#ifndef MS_COMPILE_IOS
#include <string> #include <string>
#ifndef MINDSPORE_LITE_SRC_CPU_INFO_H #ifndef MINDSPORE_LITE_SRC_CPU_INFO_H
#define MINDSPORE_LITE_SRC_CPU_INFO_H #define MINDSPORE_LITE_SRC_CPU_INFO_H
@ -48,3 +49,4 @@ class CpuInfo {
} // namespace mindspore::lite } // namespace mindspore::lite
#endif // MINDSPORE_LITE_SRC_CPU_INFO_H #endif // MINDSPORE_LITE_SRC_CPU_INFO_H
#endif #endif
#endif

View File

@ -35,9 +35,11 @@ InnerContext::InnerContext(const Context *context) {
this->device_list_.push_back(device_ctx); this->device_list_.push_back(device_ctx);
} }
#ifdef ENABLE_ARM #ifdef ENABLE_ARM
#ifndef MS_COMPILE_IOS
cpu_info_ = new CpuInfo; cpu_info_ = new CpuInfo;
fp16_flag_ = cpu_info_->ArmIsSupportFp16(); fp16_flag_ = cpu_info_->ArmIsSupportFp16();
#endif #endif
#endif
} }
#if SUPPORT_NPU #if SUPPORT_NPU
@ -61,9 +63,11 @@ InnerContext::InnerContext(const Context *context, NPUManager *npu_manager) {
} }
this->npu_manager_ = npu_manager; this->npu_manager_ = npu_manager;
#ifdef ENABLE_ARM #ifdef ENABLE_ARM
#ifndef MS_COMPILE_IOS
cpu_info_ = new CpuInfo; cpu_info_ = new CpuInfo;
fp16_flag_ = cpu_info_->ArmIsSupportFp16(); fp16_flag_ = cpu_info_->ArmIsSupportFp16();
#endif #endif
#endif
} }
#endif #endif
@ -121,8 +125,10 @@ InnerContext::~InnerContext() {
this->thread_pool_ = nullptr; this->thread_pool_ = nullptr;
} }
#ifdef ENABLE_ARM #ifdef ENABLE_ARM
#ifndef MS_COMPILE_IOS
delete cpu_info_; delete cpu_info_;
#endif #endif
#endif
} }
int InnerContext::IsValid() const { int InnerContext::IsValid() const {

View File

@ -82,12 +82,16 @@ struct InnerContext : public Context {
bool fp16_flag_ = false; bool fp16_flag_ = false;
#ifdef ENABLE_ARM #ifdef ENABLE_ARM
#ifndef MS_COMPILE_IOS
CpuInfo *cpu_info_ = nullptr; CpuInfo *cpu_info_ = nullptr;
#endif #endif
#endif
#if SUPPORT_NPU #if SUPPORT_NPU
#ifndef MS_COMPILE_IOS
NPUManager *npu_manager_ = nullptr; NPUManager *npu_manager_ = nullptr;
#endif #endif
#endif
}; };
} // namespace mindspore::lite } // namespace mindspore::lite