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