Compute Library
 22.08
CpuInfo.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #ifndef SRC_COMMON_CPUINFO_H
25 #define SRC_COMMON_CPUINFO_H
26 
29 
30 #include <string>
31 #include <vector>
32 
33 namespace arm_compute
34 {
35 namespace cpuinfo
36 {
37 /** Aggregate class that contains CPU related information
38  *
39  * Contains information about the numbers of the CPUs, the model of each CPU,
40  * ISA related information and more
41  *
42  * @note We can safely assume that the ISA is common between different clusters of cores
43  */
44 class CpuInfo
45 {
46 public:
47  /** Default constructor */
48  CpuInfo() = default;
49  /** Construct a new Cpu Info object
50  *
51  * @param[in] isa ISA capabilities information
52  * @param[in] cpus CPU models information
53  */
54  CpuInfo(CpuIsaInfo isa, std::vector<CpuModel> cpus);
55  /** CpuInfo builder function from system related information
56  *
57  * @return CpuInfo A populated CpuInfo structure
58  */
59  static CpuInfo build();
60 
61 public:
62  bool has_neon() const
63  {
64  return _isa.neon;
65  }
66  bool has_sve() const
67  {
68  return _isa.sve;
69  }
70  bool has_sve2() const
71  {
72  return _isa.sve2;
73  }
74  bool has_fp16() const
75  {
76  return _isa.fp16;
77  }
78  bool has_bf16() const
79  {
80  return _isa.bf16;
81  }
82  bool has_svebf16() const
83  {
84  return _isa.svebf16;
85  }
86  bool has_dotprod() const
87  {
88  return _isa.dot;
89  }
90  bool has_i8mm() const
91  {
92  return _isa.i8mm;
93  }
94  bool has_svei8mm() const
95  {
96  return _isa.svei8mm;
97  }
98  bool has_svef32mm() const
99  {
100  return _isa.svef32mm;
101  }
102 
103  const CpuIsaInfo &isa() const
104  {
105  return _isa;
106  }
107  const std::vector<CpuModel> &cpus() const
108  {
109  return _cpus;
110  }
111 
112  CpuModel cpu_model(uint32_t cpuid) const;
113  CpuModel cpu_model() const;
114  uint32_t num_cpus() const;
115 
116 private:
117  CpuIsaInfo _isa{};
118  std::vector<CpuModel> _cpus{};
119 };
120 
121 /** Some systems have both big and small cores, this fuction computes the minimum number of cores
122  * that are exactly the same on the system. To maximize performance the library attempts to process
123  * workloads concurrently using as many threads as big cores are available on the system.
124  *
125  * @return The minumum number of common cores.
126  */
127 uint32_t num_threads_hint();
128 } // namespace cpuinfo
129 } // namespace arm_compute
130 #endif /* SRC_COMMON_CPUINFO_H */
bool has_svei8mm() const
Definition: CpuInfo.h:94
static CpuInfo build()
CpuInfo builder function from system related information.
Definition: CpuInfo.cpp:303
const std::vector< CpuModel > & cpus() const
Definition: CpuInfo.h:107
CPUModel
CPU models types.
Definition: CPPTypes.h:58
uint32_t num_threads_hint()
Some systems have both big and small cores, this fuction computes the minimum number of cores that ar...
Definition: CpuInfo.cpp:391
Copyright (c) 2017-2022 Arm Limited.
bool has_dotprod() const
Definition: CpuInfo.h:86
CPU ISA (Instruction Set Architecture) information.
Definition: CpuIsaInfo.h:37
Aggregate class that contains CPU related information.
Definition: CpuInfo.h:44
const CpuIsaInfo & isa() const
Definition: CpuInfo.h:103
uint32_t num_cpus() const
Definition: CpuInfo.cpp:386
CpuModel cpu_model() const
Definition: CpuInfo.cpp:377
bool has_svebf16() const
Definition: CpuInfo.h:82
CpuInfo()=default
Default constructor.
bool has_svef32mm() const
Definition: CpuInfo.h:98