blob: 3ab1316369ea4862408c6390919e9f750de1f6f0 [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,
Anthony Barbier5a3ee4f2018-07-24 11:24:17 +010039 GENERIC_FP16,
40 GENERIC_FP16_DOT,
Pablo Tello7fad9b12018-03-14 17:55:27 +000041 A53,
42 A55r0,
Anthony Barbier5a3ee4f2018-07-24 11:24:17 +010043 A55r1
Moritz Pflanzerd929b9c2017-06-28 10:15:48 +010044};
Moritz Pflanzerc186b572017-09-07 09:48:04 +010045
Pablo Tello7fad9b12018-03-14 17:55:27 +000046class CPUInfo final
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010047{
Pablo Tello7fad9b12018-03-14 17:55:27 +000048public:
49 /** Constructor */
50 CPUInfo();
51
52 /** Disable copy constructor and assignment operator to avoid copying the vector of CPUs each time
53 * CPUInfo is initialized once in the IScheduler and ThreadInfo will get a pointer to it.
54 */
55 CPUInfo &operator=(const CPUInfo &cpuinfo) = delete;
56 CPUInfo(const CPUInfo &cpuinfo) = delete;
57 CPUInfo &operator=(const CPUInfo &&cpuinfo) = delete;
58 CPUInfo(const CPUInfo &&cpuinfo) = delete;
59
60 /** Checks if the cpu model supports fp16.
61 *
62 * @return true of the cpu supports fp16, false otherwise
63 */
64 bool has_fp16() const;
65 /** Checks if the cpu model supports dot product.
66 *
67 * @return true of the cpu supports dot product, false otherwise
68 */
69 bool has_dotprod() const;
70 /** Gets the cpu model for a given cpuid.
71 *
72 * @param[in] cpuid the id of the cpu core to be retrieved,
73 *
74 * @return the @ref CPUModel of the cpuid queiried.
75 */
76 CPUModel get_cpu_model(unsigned int cpuid) const;
77 /** Gets the current thread's cpu model
78 *
79 * @return Current thread's @ref CPUModel
80 */
81 CPUModel get_cpu_model() const;
82 /** Gets the L1 cache size
83 *
84 * @return the size of the L1 cache
85 */
86 unsigned int get_L1_cache_size() const;
87 /** Gets the L2 cache size
88 *
89 * @return the size of the L1 cache
90 */
91 unsigned int get_L2_cache_size() const;
92 /** Set the L1 cache size
93 *
94 * @param[in] size the new size to be set.
95 */
96 void set_L1_cache_size(unsigned int size);
97 /** Set the L2 cache size
98 *
99 * @param[in] size the new size to be set.
100 */
101 void set_L2_cache_size(unsigned int size);
102 /** Set fp16 support
103 *
104 * @param[in] fp16 whether the cpu supports fp16.
105 */
106 void set_fp16(const bool fp16);
107 /** Set dot product support
108 *
109 * @param[in] dotprod whether the cpu supports dot product.
110 */
111 void set_dotprod(const bool dotprod);
112 /** Set the cpumodel for a given cpu core
113 *
114 * @param[in] cpuid the id of the core to be set.
115 * @param[in] model the @ref CPUModel to be set.
116 */
117 void set_cpu_model(unsigned int cpuid, CPUModel model);
118 /** Set max number of cpus
119 *
120 * @param[in] cpu_count the number of CPUs in the system.
121 */
122 void set_cpu_num(unsigned int cpu_count);
123
Anthony Barbier8914e322018-08-10 15:28:25 +0100124 /** Return the maximum number of CPUs present
125 *
126 * @return Number of CPUs
127 */
128 unsigned int get_cpu_num() const;
129
Pablo Tello7fad9b12018-03-14 17:55:27 +0000130private:
131 std::vector<CPUModel> _percpu = {};
132 bool _fp16 = false;
133 bool _dotprod = false;
134 unsigned int _L1_cache_size = 32768;
135 unsigned int _L2_cache_size = 262144;
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +0100136};
137
Alex Gildayc357c472018-03-21 13:54:09 +0000138/** Information about executing thread and CPU. */
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100139struct ThreadInfo
140{
Pablo Tello7fad9b12018-03-14 17:55:27 +0000141 int thread_id{ 0 };
142 int num_threads{ 1 };
143 const CPUInfo *cpu_info{ nullptr };
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100144};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100145} // namespace arm_compute
Moritz Pflanzerd929b9c2017-06-28 10:15:48 +0100146#endif /* __ARM_COMPUTE_CPP_TYPES_H__ */