Compute Library
 23.08
CpuInfo.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021-2022 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_sme() const
75  {
76  return _isa.sme;
77  }
78  bool has_sme2() const
79  {
80  return _isa.sme2;
81  }
82  bool has_fp16() const
83  {
84  return _isa.fp16;
85  }
86  bool has_bf16() const
87  {
88  return _isa.bf16;
89  }
90  bool has_svebf16() const
91  {
92  return _isa.svebf16;
93  }
94  bool has_dotprod() const
95  {
96  return _isa.dot;
97  }
98  bool has_i8mm() const
99  {
100  return _isa.i8mm;
101  }
102  bool has_svei8mm() const
103  {
104  return _isa.svei8mm;
105  }
106  bool has_svef32mm() const
107  {
108  return _isa.svef32mm;
109  }
110 
111  const CpuIsaInfo &isa() const
112  {
113  return _isa;
114  }
115  const std::vector<CpuModel> &cpus() const
116  {
117  return _cpus;
118  }
119 
120  CpuModel cpu_model(uint32_t cpuid) const;
121  CpuModel cpu_model() const;
122  uint32_t num_cpus() const;
123 
124 private:
125  CpuIsaInfo _isa{};
126  std::vector<CpuModel> _cpus{};
127 };
128 
129 /** Some systems have both big and small cores, this fuction computes the minimum number of cores
130  * that are exactly the same on the system. To maximize performance the library attempts to process
131  * workloads concurrently using as many threads as big cores are available on the system.
132  *
133  * @return The minumum number of common cores.
134  */
135 uint32_t num_threads_hint();
136 } // namespace cpuinfo
137 } // namespace arm_compute
138 #endif /* SRC_COMMON_CPUINFO_H */
CpuModel.h
arm_compute::cpuinfo::CpuIsaInfo
CPU ISA (Instruction Set Architecture) information.
Definition: CpuIsaInfo.h:37
arm_compute::cpuinfo::CpuIsaInfo::neon
bool neon
Definition: CpuIsaInfo.h:40
arm_compute::CPUModel
CPUModel
CPU models types.
Definition: CPPTypes.h:59
arm_compute::cpuinfo::CpuInfo::has_bf16
bool has_bf16() const
Definition: CpuInfo.h:86
arm_compute::cpuinfo::CpuInfo::has_fp16
bool has_fp16() const
Definition: CpuInfo.h:82
arm_compute::cpuinfo::CpuInfo::has_sme
bool has_sme() const
Definition: CpuInfo.h:74
arm_compute::cpuinfo::CpuIsaInfo::sme2
bool sme2
Definition: CpuIsaInfo.h:44
arm_compute::cpuinfo::CpuIsaInfo::dot
bool dot
Definition: CpuIsaInfo.h:52
arm_compute::cpuinfo::CpuIsaInfo::fp16
bool fp16
Definition: CpuIsaInfo.h:47
arm_compute::cpuinfo::CpuIsaInfo::svef32mm
bool svef32mm
Definition: CpuIsaInfo.h:55
arm_compute::cpuinfo::CpuInfo::has_neon
bool has_neon() const
Definition: CpuInfo.h:62
arm_compute::cpuinfo::CpuInfo::has_sve
bool has_sve() const
Definition: CpuInfo.h:66
arm_compute::cpuinfo::CpuInfo::cpu_model
CpuModel cpu_model() const
Definition: CpuInfo.cpp:378
arm_compute::cpuinfo::CpuInfo::cpus
const std::vector< CpuModel > & cpus() const
Definition: CpuInfo.h:115
arm_compute::cpuinfo::CpuIsaInfo::i8mm
bool i8mm
Definition: CpuIsaInfo.h:53
arm_compute::cpuinfo::CpuIsaInfo::svei8mm
bool svei8mm
Definition: CpuIsaInfo.h:54
CpuIsaInfo.h
arm_compute::cpuinfo::CpuIsaInfo::sve2
bool sve2
Definition: CpuIsaInfo.h:42
arm_compute::cpuinfo::CpuInfo::CpuInfo
CpuInfo()=default
Default constructor.
arm_compute::cpuinfo::CpuInfo::has_sve2
bool has_sve2() const
Definition: CpuInfo.h:70
arm_compute::cpuinfo::CpuInfo::build
static CpuInfo build()
CpuInfo builder function from system related information.
Definition: CpuInfo.cpp:303
arm_compute::cpuinfo::CpuInfo::has_dotprod
bool has_dotprod() const
Definition: CpuInfo.h:94
arm_compute::cpuinfo::CpuInfo
Aggregate class that contains CPU related information.
Definition: CpuInfo.h:44
arm_compute::cpuinfo::CpuInfo::has_sme2
bool has_sme2() const
Definition: CpuInfo.h:78
arm_compute::cpuinfo::CpuInfo::has_svei8mm
bool has_svei8mm() const
Definition: CpuInfo.h:102
arm_compute::cpuinfo::CpuInfo::has_svef32mm
bool has_svef32mm() const
Definition: CpuInfo.h:106
arm_compute::cpuinfo::CpuIsaInfo::svebf16
bool svebf16
Definition: CpuIsaInfo.h:49
arm_compute::cpuinfo::CpuIsaInfo::sve
bool sve
Definition: CpuIsaInfo.h:41
arm_compute::cpuinfo::CpuInfo::has_svebf16
bool has_svebf16() const
Definition: CpuInfo.h:90
arm_compute::cpuinfo::CpuInfo::has_i8mm
bool has_i8mm() const
Definition: CpuInfo.h:98
arm_compute::cpuinfo::CpuInfo::isa
const CpuIsaInfo & isa() const
Definition: CpuInfo.h:111
arm_compute::cpuinfo::CpuIsaInfo::sme
bool sme
Definition: CpuIsaInfo.h:43
arm_compute::cpuinfo::CpuIsaInfo::bf16
bool bf16
Definition: CpuIsaInfo.h:48
arm_compute
Copyright (c) 2017-2023 Arm Limited.
Definition: introduction.dox:24
arm_compute::cpuinfo::CpuInfo::num_cpus
uint32_t num_cpus() const
Definition: CpuInfo.cpp:387
arm_compute::cpuinfo::num_threads_hint
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:392