blob: 135ff969316ecff8dedf5154571a5e45b6c05a67 [file] [log] [blame]
Georgios Pinitas08302c12021-06-09 10:08:27 +01001/*
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
27#include "src/common/cpuinfo/CpuIsaInfo.h"
28#include "src/common/cpuinfo/CpuModel.h"
29
30#include <string>
31#include <vector>
32
33namespace arm_compute
34{
35namespace 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 */
44class CpuInfo
45{
46public:
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
61public:
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 }
Michalis Spyrou20fca522021-06-07 14:23:57 +010082 bool has_svebf16() const
83 {
84 return _isa.svebf16;
85 }
Georgios Pinitas08302c12021-06-09 10:08:27 +010086 bool has_dotprod() const
87 {
88 return _isa.dot;
89 }
Michalis Spyrou20fca522021-06-07 14:23:57 +010090 bool has_i8mm() const
Georgios Pinitas08302c12021-06-09 10:08:27 +010091 {
Michalis Spyrou20fca522021-06-07 14:23:57 +010092 return _isa.i8mm;
Georgios Pinitas08302c12021-06-09 10:08:27 +010093 }
Michalis Spyrou20fca522021-06-07 14:23:57 +010094 bool has_svei8mm() const
Georgios Pinitas08302c12021-06-09 10:08:27 +010095 {
Michalis Spyrou20fca522021-06-07 14:23:57 +010096 return _isa.svei8mm;
97 }
98 bool has_svef32mm() const
99 {
100 return _isa.svef32mm;
Georgios Pinitas08302c12021-06-09 10:08:27 +0100101 }
102
Georgios Pinitas731fe662021-06-24 20:32:11 +0100103 const CpuIsaInfo &isa() const
104 {
105 return _isa;
106 }
107 const std::vector<CpuModel> &cpus() const
108 {
109 return _cpus;
110 }
111
Georgios Pinitas08302c12021-06-09 10:08:27 +0100112 CpuModel cpu_model(uint32_t cpuid) const;
113 CpuModel cpu_model() const;
114 uint32_t num_cpus() const;
115
116private:
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 */
127uint32_t num_threads_hint();
128} // namespace cpuinfo
129} // namespace arm_compute
130#endif /* SRC_COMMON_CPUINFO_H */