From ddce24d8473580dd56b0b85c2c0797494403240b Mon Sep 17 00:00:00 2001 From: yefeng Date: Tue, 29 Jun 2021 21:22:24 +0800 Subject: [PATCH] ios fp16 --- mindspore/lite/src/cpu_info.cc | 42 +++++++++++++++++++++++++++++----- mindspore/lite/src/cpu_info.h | 20 ++++++++-------- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/mindspore/lite/src/cpu_info.cc b/mindspore/lite/src/cpu_info.cc index 3df9513ef35..f20f5c1eeb4 100644 --- a/mindspore/lite/src/cpu_info.cc +++ b/mindspore/lite/src/cpu_info.cc @@ -14,16 +14,39 @@ * limitations under the License. */ #ifdef ENABLE_ARM -#ifndef MS_COMPILE_IOS #include "src/cpu_info.h" -#include -#include -#include #include +#include #include "src/common/log_adapter.h" #include "nnacl/nnacl_utils.h" - +#ifndef MS_COMPILE_IOS +#include +#include +#else +#include +#include +#include +#include +#include +#include "TargetConditionals.h" +#ifndef CPUFAMILY_ARM_HURRICANE +#define CPUFAMILY_ARM_HURRICANE 0x67ceee93 +#endif +#ifndef CPUFAMILY_ARM_MONSOON_MISTRAL +#define CPUFAMILY_ARM_MONSOON_MISTRAL 0xe81e7ef6 +#endif +#ifndef CPUFAMILY_ARM_VORTEX_TEMPEST +#define CPUFAMILY_ARM_VORTEX_TEMPEST 0x07d34b9f +#endif +#ifndef CPUFAMILY_ARM_LIGHTNING_THUNDER +#define CPUFAMILY_ARM_LIGHTNING_THUNDER 0x462504d2 +#endif +#ifndef CPUFAMILY_ARM_FIRESTORM_ICESTORM +#define CPUFAMILY_ARM_FIRESTORM_ICESTORM 0x1b588bb3 +#endif +#endif namespace mindspore::lite { +#ifndef MS_COMPILE_IOS uint32_t CpuInfo::MidrSetPart(uint32_t part) { return ((part << ARM_CPU_PART_OFFSET) & ARM_CPU_PART_MASK) | (midr_ & ~ARM_CPU_PART_MASK); } @@ -101,9 +124,17 @@ void CpuInfo::GetArmProcCpuInfo(AndroidCpuInfo *android_cpu_info) { } infile.close(); } +#endif bool CpuInfo::ArmIsSupportFp16() { #ifdef MS_COMPILE_IOS + unsigned int value = 0; + size_t len = sizeof(value); + sysctlbyname("hw.cpufamily", &value, &len, NULL, 0); + if (value == CPUFAMILY_ARM_MONSOON_MISTRAL || value == CPUFAMILY_ARM_VORTEX_TEMPEST || + value == CPUFAMILY_ARM_LIGHTNING_THUNDER || value == CPUFAMILY_ARM_FIRESTORM_ICESTORM) { + return true; + } return false; #else #ifdef ENABLE_ARM32 @@ -149,4 +180,3 @@ 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 d8a4a07cc21..aef8f675c13 100644 --- a/mindspore/lite/src/cpu_info.h +++ b/mindspore/lite/src/cpu_info.h @@ -14,11 +14,11 @@ * 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 namespace mindspore::lite { +#ifndef MS_COMPILE_IOS #define ARM_CPU_IMPLEMENTER_MASK UINT32_C(0xFF000000) #define ARM_CPU_PART_MASK UINT32_C(0x0000FFF0) #define ARM_CPU_IMPLEMENTER_OFFSET 24 @@ -28,25 +28,27 @@ typedef struct AndroidCpuInfo { uint32_t cpu_part = 0; std::string hardware = ""; } AndroidCpuInfo; +#endif class CpuInfo { public: CpuInfo() = default; virtual ~CpuInfo() = default; - void GetArmProcCpuInfo(AndroidCpuInfo *android_cpu_info); - uint32_t ParseArmCpuImplementer(const std::string &suffix); - uint32_t ParseArmCpuPart(const std::string &suffix); - uint32_t MidrSetPart(uint32_t part); - uint32_t MidrSetImplementer(uint32_t implementer); bool ArmIsSupportFp16(); - uint32_t StringToDigit(const std::string &str); private: - bool fp16_flag_ = false; +#ifndef MS_COMPILE_IOS + uint32_t StringToDigit(const std::string &str); + uint32_t ParseArmCpuPart(const std::string &suffix); + uint32_t MidrSetImplementer(uint32_t implementer); + uint32_t MidrSetPart(uint32_t part); + uint32_t ParseArmCpuImplementer(const std::string &suffix); + void GetArmProcCpuInfo(AndroidCpuInfo *android_cpu_info); uint32_t midr_ = 0; AndroidCpuInfo android_cpu_info_; +#endif + bool fp16_flag_ = false; }; } // namespace mindspore::lite #endif // MINDSPORE_LITE_SRC_CPU_INFO_H #endif -#endif