1 /** 2 * Copyright 2021-2022 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MINDSPORE_LITE_SRC_RUNTIME_CPU_INFO_H_ 18 #define MINDSPORE_LITE_SRC_RUNTIME_CPU_INFO_H_ 19 20 #if defined(ENABLE_AVX512) || defined(ENABLE_AVX) 21 #include "nnacl/intrinsics/ms_simd_cpu_info.h" 22 #endif 23 PlatformInstructionSetSupportCheck()24inline bool PlatformInstructionSetSupportCheck() { 25 #if defined(ENABLE_AVX512) || defined(ENABLE_AVX) 26 auto ret = IntelX86InstructionSetSupportCheck(); 27 if (ret == X86CPUINFO_PLATFORM_ERR) { 28 MS_LOG(WARNING) << "This is not intel platform."; 29 return true; 30 } else if (ret == X86CPUINFO_AVX512_ERR) { 31 MS_LOG(ERROR) << "This is avx512 version, but the platform don't support avx512 instruction."; 32 return false; 33 } else if (ret == X86CPUINFO_AVX_ERR) { 34 MS_LOG(ERROR) << "This is avx version, but the platform don't support avx instruction."; 35 return false; 36 } else if (ret == X86CPUINFO_SSE_ERR) { 37 MS_LOG(ERROR) << "This is sse version, but the platform don't support sse instruction."; 38 return false; 39 } 40 #endif 41 42 return true; 43 } 44 45 #ifdef ENABLE_ARM 46 #include <string> 47 48 namespace mindspore::lite { 49 #ifndef MS_COMPILE_IOS 50 #define ARM_CPU_IMPLEMENTER_MASK UINT32_C(0xFF000000) 51 #define ARM_CPU_PART_MASK UINT32_C(0x0000FFF0) 52 #define ARM_CPU_IMPLEMENTER_OFFSET 24 53 #define ARM_CPU_PART_OFFSET 4 54 typedef struct AndroidCpuInfo { 55 uint32_t cpu_implementer = 0; 56 uint32_t cpu_part = 0; 57 std::string hardware = ""; 58 } AndroidCpuInfo; 59 #endif 60 61 class CpuInfo { 62 public: 63 CpuInfo() = default; 64 virtual ~CpuInfo() = default; 65 bool ArmIsSupportFp16(); 66 67 private: 68 #ifndef MS_COMPILE_IOS 69 uint32_t StringToDigit(const std::string &str); 70 uint32_t ParseArmCpuPart(const std::string &suffix); 71 uint32_t MidrSetImplementer(uint32_t implementer); 72 uint32_t MidrSetPart(uint32_t part); 73 uint32_t ParseArmCpuImplementer(const std::string &suffix); 74 void GetArmProcCpuInfo(AndroidCpuInfo *android_cpu_info); 75 uint32_t midr_ = 0; 76 AndroidCpuInfo android_cpu_info_; 77 #endif 78 bool fp16_flag_ = false; 79 }; 80 } // namespace mindspore::lite 81 #endif 82 #endif // MINDSPORE_LITE_SRC_RUNTIME_CPU_INFO_H_ 83