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 27 #include "src/common/cpuinfo/CpuIsaInfo.h" 28 #include "src/common/cpuinfo/CpuModel.h" 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: has_neon()62 bool has_neon() const 63 { 64 return _isa.neon; 65 } has_sve()66 bool has_sve() const 67 { 68 return _isa.sve; 69 } has_sve2()70 bool has_sve2() const 71 { 72 return _isa.sve2; 73 } has_sme()74 bool has_sme() const 75 { 76 return _isa.sme; 77 } has_sme2()78 bool has_sme2() const 79 { 80 return _isa.sme2; 81 } has_fp16()82 bool has_fp16() const 83 { 84 return _isa.fp16; 85 } has_bf16()86 bool has_bf16() const 87 { 88 return _isa.bf16; 89 } has_svebf16()90 bool has_svebf16() const 91 { 92 return _isa.svebf16; 93 } has_dotprod()94 bool has_dotprod() const 95 { 96 return _isa.dot; 97 } has_i8mm()98 bool has_i8mm() const 99 { 100 return _isa.i8mm; 101 } has_svei8mm()102 bool has_svei8mm() const 103 { 104 return _isa.svei8mm; 105 } has_svef32mm()106 bool has_svef32mm() const 107 { 108 return _isa.svef32mm; 109 } 110 isa()111 const CpuIsaInfo &isa() const 112 { 113 return _isa; 114 } cpus()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 */ 139