blob: 8a9ada81c1822ce456adfadf5b691e4b8ce7d9ba [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 Tello7fad9b12018-03-14 17:55:27 +000027#include <vector>
28
Moritz Pflanzerd929b9c2017-06-28 10:15:48 +010029namespace arm_compute
30{
Pablo Tello7fad9b12018-03-14 17:55:27 +000031/** CPU models - we only need to detect CPUs we have
32 * microarchitecture-specific code for.
33 *
34 * Architecture features are detected via HWCAPs.
35 */
36enum class CPUModel
Moritz Pflanzerd929b9c2017-06-28 10:15:48 +010037{
Pablo Tello7fad9b12018-03-14 17:55:27 +000038 GENERIC,
39 A53,
40 A55r0,
41 A55r1,
Moritz Pflanzerd929b9c2017-06-28 10:15:48 +010042};
Moritz Pflanzerc186b572017-09-07 09:48:04 +010043
Pablo Tello7fad9b12018-03-14 17:55:27 +000044class CPUInfo final
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010045{
Pablo Tello7fad9b12018-03-14 17:55:27 +000046public:
47 /** Constructor */
48 CPUInfo();
49
50 /** Disable copy constructor and assignment operator to avoid copying the vector of CPUs each time
51 * CPUInfo is initialized once in the IScheduler and ThreadInfo will get a pointer to it.
52 */
53 CPUInfo &operator=(const CPUInfo &cpuinfo) = delete;
54 CPUInfo(const CPUInfo &cpuinfo) = delete;
55 CPUInfo &operator=(const CPUInfo &&cpuinfo) = delete;
56 CPUInfo(const CPUInfo &&cpuinfo) = delete;
57
58 /** Checks if the cpu model supports fp16.
59 *
60 * @return true of the cpu supports fp16, false otherwise
61 */
62 bool has_fp16() const;
63 /** Checks if the cpu model supports dot product.
64 *
65 * @return true of the cpu supports dot product, false otherwise
66 */
67 bool has_dotprod() const;
68 /** Gets the cpu model for a given cpuid.
69 *
70 * @param[in] cpuid the id of the cpu core to be retrieved,
71 *
72 * @return the @ref CPUModel of the cpuid queiried.
73 */
74 CPUModel get_cpu_model(unsigned int cpuid) const;
75 /** Gets the current thread's cpu model
76 *
77 * @return Current thread's @ref CPUModel
78 */
79 CPUModel get_cpu_model() const;
80 /** Gets the L1 cache size
81 *
82 * @return the size of the L1 cache
83 */
84 unsigned int get_L1_cache_size() const;
85 /** Gets the L2 cache size
86 *
87 * @return the size of the L1 cache
88 */
89 unsigned int get_L2_cache_size() const;
90 /** Set the L1 cache size
91 *
92 * @param[in] size the new size to be set.
93 */
94 void set_L1_cache_size(unsigned int size);
95 /** Set the L2 cache size
96 *
97 * @param[in] size the new size to be set.
98 */
99 void set_L2_cache_size(unsigned int size);
100 /** Set fp16 support
101 *
102 * @param[in] fp16 whether the cpu supports fp16.
103 */
104 void set_fp16(const bool fp16);
105 /** Set dot product support
106 *
107 * @param[in] dotprod whether the cpu supports dot product.
108 */
109 void set_dotprod(const bool dotprod);
110 /** Set the cpumodel for a given cpu core
111 *
112 * @param[in] cpuid the id of the core to be set.
113 * @param[in] model the @ref CPUModel to be set.
114 */
115 void set_cpu_model(unsigned int cpuid, CPUModel model);
116 /** Set max number of cpus
117 *
118 * @param[in] cpu_count the number of CPUs in the system.
119 */
120 void set_cpu_num(unsigned int cpu_count);
121
122private:
123 std::vector<CPUModel> _percpu = {};
124 bool _fp16 = false;
125 bool _dotprod = false;
126 unsigned int _L1_cache_size = 32768;
127 unsigned int _L2_cache_size = 262144;
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100128};
129
Alex Gildayc357c472018-03-21 13:54:09 +0000130/** Information about executing thread and CPU. */
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100131struct ThreadInfo
132{
Pablo Tello7fad9b12018-03-14 17:55:27 +0000133 int thread_id{ 0 };
134 int num_threads{ 1 };
135 const CPUInfo *cpu_info{ nullptr };
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100136};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100137} // namespace arm_compute
Moritz Pflanzerd929b9c2017-06-28 10:15:48 +0100138#endif /* __ARM_COMPUTE_CPP_TYPES_H__ */