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: |
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 | bool CurrentCpuIsX1(); |
43 | |
44 | private: |
45 | enum class InitStatus { |
46 | kNotYetAttempted, |
47 | kInitialized, |
48 | kFailed, |
49 | }; |
50 | |
51 | InitStatus init_status_ = InitStatus::kNotYetAttempted; |
52 | CpuCacheParams cache_params_; |
53 | |
54 | bool EnsureInitialized(); |
55 | InitStatus Initialize(); |
56 | |
57 | CpuInfo(const CpuInfo&) = delete; |
58 | }; |
59 | |
60 | } // namespace ruy |
61 | |
62 | #endif // RUY_RUY_CPUINFO_H_ |
63 | |