blob: 9ffb4840a3ceead4f0971f5b92dc82b2c4ea9869 [file] [log] [blame]
Moritz Pflanzerd929b9c2017-06-28 10:15:48 +01001/*
Alex Gildayc357c472018-03-21 13:54:09 +00002 * Copyright (c) 2017-2018 ARM Limited.
Moritz Pflanzerd929b9c2017-06-28 10:15:48 +01003 *
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 __ARM_COMPUTE_CPP_TYPES_H__
25#define __ARM_COMPUTE_CPP_TYPES_H__
26
Pablo Tello4e0ac6f2018-10-01 14:31:11 +010027#include "arm_compute/core/Error.h"
28
29#include <string>
Pablo Tello7fad9b12018-03-14 17:55:27 +000030#include <vector>
31
Moritz Pflanzerd929b9c2017-06-28 10:15:48 +010032namespace arm_compute
33{
Pablo Tello7fad9b12018-03-14 17:55:27 +000034/** CPU models - we only need to detect CPUs we have
35 * microarchitecture-specific code for.
36 *
37 * Architecture features are detected via HWCAPs.
38 */
39enum class CPUModel
Moritz Pflanzerd929b9c2017-06-28 10:15:48 +010040{
Pablo Tello7fad9b12018-03-14 17:55:27 +000041 GENERIC,
Anthony Barbier5a3ee4f2018-07-24 11:24:17 +010042 GENERIC_FP16,
43 GENERIC_FP16_DOT,
Pablo Tello7fad9b12018-03-14 17:55:27 +000044 A53,
45 A55r0,
Anthony Barbier5a3ee4f2018-07-24 11:24:17 +010046 A55r1
Moritz Pflanzerd929b9c2017-06-28 10:15:48 +010047};
Moritz Pflanzerc186b572017-09-07 09:48:04 +010048
Pablo Tello4e0ac6f2018-10-01 14:31:11 +010049/** Convert a cpumodel value to a string
50 *
51 * @param val CPUModel value to be converted
52 *
53 * @return String representing the corresponding CPUModel.
54 */
55inline std::string cpu_model_to_string(CPUModel val)
56{
57 switch(val)
58 {
59 case CPUModel::GENERIC:
60 {
61 return std::string("GENERIC");
62 }
63 case CPUModel::GENERIC_FP16:
64 {
65 return std::string("GENERIC_FP16");
66 }
67 case CPUModel::GENERIC_FP16_DOT:
68 {
69 return std::string("GENERIC_FP16_DOT");
70 }
71 case CPUModel::A53:
72 {
73 return std::string("A53");
74 }
75 case CPUModel::A55r0:
76 {
77 return std::string("A55r0");
78 }
79 case CPUModel::A55r1:
80 {
81 return std::string("A55r1");
82 }
83 default:
84 {
85 ARM_COMPUTE_ERROR("Invalid CPUModel.");
86 return std::string("GENERIC");
87 }
88 }
89}
90
Pablo Tello7fad9b12018-03-14 17:55:27 +000091class CPUInfo final
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010092{
Pablo Tello7fad9b12018-03-14 17:55:27 +000093public:
94 /** Constructor */
95 CPUInfo();
96
97 /** Disable copy constructor and assignment operator to avoid copying the vector of CPUs each time
98 * CPUInfo is initialized once in the IScheduler and ThreadInfo will get a pointer to it.
99 */
100 CPUInfo &operator=(const CPUInfo &cpuinfo) = delete;
101 CPUInfo(const CPUInfo &cpuinfo) = delete;
102 CPUInfo &operator=(const CPUInfo &&cpuinfo) = delete;
103 CPUInfo(const CPUInfo &&cpuinfo) = delete;
104
105 /** Checks if the cpu model supports fp16.
106 *
107 * @return true of the cpu supports fp16, false otherwise
108 */
109 bool has_fp16() const;
110 /** Checks if the cpu model supports dot product.
111 *
112 * @return true of the cpu supports dot product, false otherwise
113 */
114 bool has_dotprod() const;
115 /** Gets the cpu model for a given cpuid.
116 *
117 * @param[in] cpuid the id of the cpu core to be retrieved,
118 *
119 * @return the @ref CPUModel of the cpuid queiried.
120 */
121 CPUModel get_cpu_model(unsigned int cpuid) const;
122 /** Gets the current thread's cpu model
123 *
124 * @return Current thread's @ref CPUModel
125 */
126 CPUModel get_cpu_model() const;
127 /** Gets the L1 cache size
128 *
129 * @return the size of the L1 cache
130 */
131 unsigned int get_L1_cache_size() const;
132 /** Gets the L2 cache size
133 *
134 * @return the size of the L1 cache
135 */
136 unsigned int get_L2_cache_size() const;
137 /** Set the L1 cache size
138 *
139 * @param[in] size the new size to be set.
140 */
141 void set_L1_cache_size(unsigned int size);
142 /** Set the L2 cache size
143 *
144 * @param[in] size the new size to be set.
145 */
146 void set_L2_cache_size(unsigned int size);
147 /** Set fp16 support
148 *
149 * @param[in] fp16 whether the cpu supports fp16.
150 */
151 void set_fp16(const bool fp16);
152 /** Set dot product support
153 *
154 * @param[in] dotprod whether the cpu supports dot product.
155 */
156 void set_dotprod(const bool dotprod);
157 /** Set the cpumodel for a given cpu core
158 *
159 * @param[in] cpuid the id of the core to be set.
160 * @param[in] model the @ref CPUModel to be set.
161 */
162 void set_cpu_model(unsigned int cpuid, CPUModel model);
163 /** Set max number of cpus
164 *
165 * @param[in] cpu_count the number of CPUs in the system.
166 */
167 void set_cpu_num(unsigned int cpu_count);
168
Anthony Barbier8914e322018-08-10 15:28:25 +0100169 /** Return the maximum number of CPUs present
170 *
171 * @return Number of CPUs
172 */
173 unsigned int get_cpu_num() const;
174
Pablo Tello7fad9b12018-03-14 17:55:27 +0000175private:
176 std::vector<CPUModel> _percpu = {};
177 bool _fp16 = false;
178 bool _dotprod = false;
179 unsigned int _L1_cache_size = 32768;
180 unsigned int _L2_cache_size = 262144;
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100181};
182
Alex Gildayc357c472018-03-21 13:54:09 +0000183/** Information about executing thread and CPU. */
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100184struct ThreadInfo
185{
Pablo Tello7fad9b12018-03-14 17:55:27 +0000186 int thread_id{ 0 };
187 int num_threads{ 1 };
188 const CPUInfo *cpu_info{ nullptr };
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100189};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100190} // namespace arm_compute
Moritz Pflanzerd929b9c2017-06-28 10:15:48 +0100191#endif /* __ARM_COMPUTE_CPP_TYPES_H__ */