1*bb86c7edSAndroid Build Coastguard Worker /* Copyright 2020 Google LLC. All Rights Reserved. 2*bb86c7edSAndroid Build Coastguard Worker 3*bb86c7edSAndroid Build Coastguard Worker Licensed under the Apache License, Version 2.0 (the "License"); 4*bb86c7edSAndroid Build Coastguard Worker you may not use this file except in compliance with the License. 5*bb86c7edSAndroid Build Coastguard Worker You may obtain a copy of the License at 6*bb86c7edSAndroid Build Coastguard Worker 7*bb86c7edSAndroid Build Coastguard Worker http://www.apache.org/licenses/LICENSE-2.0 8*bb86c7edSAndroid Build Coastguard Worker 9*bb86c7edSAndroid Build Coastguard Worker Unless required by applicable law or agreed to in writing, software 10*bb86c7edSAndroid Build Coastguard Worker distributed under the License is distributed on an "AS IS" BASIS, 11*bb86c7edSAndroid Build Coastguard Worker WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*bb86c7edSAndroid Build Coastguard Worker See the License for the specific language governing permissions and 13*bb86c7edSAndroid Build Coastguard Worker limitations under the License. 14*bb86c7edSAndroid Build Coastguard Worker ==============================================================================*/ 15*bb86c7edSAndroid Build Coastguard Worker 16*bb86c7edSAndroid Build Coastguard Worker #ifndef RUY_RUY_CPUINFO_H_ 17*bb86c7edSAndroid Build Coastguard Worker #define RUY_RUY_CPUINFO_H_ 18*bb86c7edSAndroid Build Coastguard Worker 19*bb86c7edSAndroid Build Coastguard Worker #include "ruy/cpu_cache_params.h" 20*bb86c7edSAndroid Build Coastguard Worker 21*bb86c7edSAndroid Build Coastguard Worker namespace ruy { 22*bb86c7edSAndroid Build Coastguard Worker 23*bb86c7edSAndroid Build Coastguard Worker // Wraps the functionality that ruy needs from the cpuinfo library. 24*bb86c7edSAndroid Build Coastguard Worker class CpuInfo final { 25*bb86c7edSAndroid Build Coastguard Worker public: CpuInfo()26*bb86c7edSAndroid Build Coastguard Worker CpuInfo() {} 27*bb86c7edSAndroid Build Coastguard Worker ~CpuInfo(); 28*bb86c7edSAndroid Build Coastguard Worker 29*bb86c7edSAndroid Build Coastguard Worker // ARM features 30*bb86c7edSAndroid Build Coastguard Worker bool NeonDotprod(); 31*bb86c7edSAndroid Build Coastguard Worker 32*bb86c7edSAndroid Build Coastguard Worker // X86 features 33*bb86c7edSAndroid Build Coastguard Worker bool Sse42(); 34*bb86c7edSAndroid Build Coastguard Worker bool Avx(); 35*bb86c7edSAndroid Build Coastguard Worker bool Avx2Fma(); 36*bb86c7edSAndroid Build Coastguard Worker bool Avx512(); 37*bb86c7edSAndroid Build Coastguard Worker bool AvxVnni(); 38*bb86c7edSAndroid Build Coastguard Worker 39*bb86c7edSAndroid Build Coastguard Worker // Common features 40*bb86c7edSAndroid Build Coastguard Worker const CpuCacheParams& CacheParams(); 41*bb86c7edSAndroid Build Coastguard Worker bool CurrentCpuIsA55ish(); 42*bb86c7edSAndroid Build Coastguard Worker bool CurrentCpuIsX1(); 43*bb86c7edSAndroid Build Coastguard Worker 44*bb86c7edSAndroid Build Coastguard Worker private: 45*bb86c7edSAndroid Build Coastguard Worker enum class InitStatus { 46*bb86c7edSAndroid Build Coastguard Worker kNotYetAttempted, 47*bb86c7edSAndroid Build Coastguard Worker kInitialized, 48*bb86c7edSAndroid Build Coastguard Worker kFailed, 49*bb86c7edSAndroid Build Coastguard Worker }; 50*bb86c7edSAndroid Build Coastguard Worker 51*bb86c7edSAndroid Build Coastguard Worker InitStatus init_status_ = InitStatus::kNotYetAttempted; 52*bb86c7edSAndroid Build Coastguard Worker CpuCacheParams cache_params_; 53*bb86c7edSAndroid Build Coastguard Worker 54*bb86c7edSAndroid Build Coastguard Worker bool EnsureInitialized(); 55*bb86c7edSAndroid Build Coastguard Worker InitStatus Initialize(); 56*bb86c7edSAndroid Build Coastguard Worker 57*bb86c7edSAndroid Build Coastguard Worker CpuInfo(const CpuInfo&) = delete; 58*bb86c7edSAndroid Build Coastguard Worker }; 59*bb86c7edSAndroid Build Coastguard Worker 60*bb86c7edSAndroid Build Coastguard Worker } // namespace ruy 61*bb86c7edSAndroid Build Coastguard Worker 62*bb86c7edSAndroid Build Coastguard Worker #endif // RUY_RUY_CPUINFO_H_ 63