1*c217d954SCole Faust /* 2*c217d954SCole Faust * Copyright (c) 2021-2022 Arm Limited. 3*c217d954SCole Faust * 4*c217d954SCole Faust * SPDX-License-Identifier: MIT 5*c217d954SCole Faust * 6*c217d954SCole Faust * Permission is hereby granted, free of charge, to any person obtaining a copy 7*c217d954SCole Faust * of this software and associated documentation files (the "Software"), to 8*c217d954SCole Faust * deal in the Software without restriction, including without limitation the 9*c217d954SCole Faust * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10*c217d954SCole Faust * sell copies of the Software, and to permit persons to whom the Software is 11*c217d954SCole Faust * furnished to do so, subject to the following conditions: 12*c217d954SCole Faust * 13*c217d954SCole Faust * The above copyright notice and this permission notice shall be included in all 14*c217d954SCole Faust * copies or substantial portions of the Software. 15*c217d954SCole Faust * 16*c217d954SCole Faust * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17*c217d954SCole Faust * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18*c217d954SCole Faust * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19*c217d954SCole Faust * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20*c217d954SCole Faust * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21*c217d954SCole Faust * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22*c217d954SCole Faust * SOFTWARE. 23*c217d954SCole Faust */ 24*c217d954SCole Faust #ifndef SRC_COMMON_CPUINFO_H 25*c217d954SCole Faust #define SRC_COMMON_CPUINFO_H 26*c217d954SCole Faust 27*c217d954SCole Faust #include "src/common/cpuinfo/CpuIsaInfo.h" 28*c217d954SCole Faust #include "src/common/cpuinfo/CpuModel.h" 29*c217d954SCole Faust 30*c217d954SCole Faust #include <string> 31*c217d954SCole Faust #include <vector> 32*c217d954SCole Faust 33*c217d954SCole Faust namespace arm_compute 34*c217d954SCole Faust { 35*c217d954SCole Faust namespace cpuinfo 36*c217d954SCole Faust { 37*c217d954SCole Faust /** Aggregate class that contains CPU related information 38*c217d954SCole Faust * 39*c217d954SCole Faust * Contains information about the numbers of the CPUs, the model of each CPU, 40*c217d954SCole Faust * ISA related information and more 41*c217d954SCole Faust * 42*c217d954SCole Faust * @note We can safely assume that the ISA is common between different clusters of cores 43*c217d954SCole Faust */ 44*c217d954SCole Faust class CpuInfo 45*c217d954SCole Faust { 46*c217d954SCole Faust public: 47*c217d954SCole Faust /** Default constructor */ 48*c217d954SCole Faust CpuInfo() = default; 49*c217d954SCole Faust /** Construct a new Cpu Info object 50*c217d954SCole Faust * 51*c217d954SCole Faust * @param[in] isa ISA capabilities information 52*c217d954SCole Faust * @param[in] cpus CPU models information 53*c217d954SCole Faust */ 54*c217d954SCole Faust CpuInfo(CpuIsaInfo isa, std::vector<CpuModel> cpus); 55*c217d954SCole Faust /** CpuInfo builder function from system related information 56*c217d954SCole Faust * 57*c217d954SCole Faust * @return CpuInfo A populated CpuInfo structure 58*c217d954SCole Faust */ 59*c217d954SCole Faust static CpuInfo build(); 60*c217d954SCole Faust 61*c217d954SCole Faust public: has_neon()62*c217d954SCole Faust bool has_neon() const 63*c217d954SCole Faust { 64*c217d954SCole Faust return _isa.neon; 65*c217d954SCole Faust } has_sve()66*c217d954SCole Faust bool has_sve() const 67*c217d954SCole Faust { 68*c217d954SCole Faust return _isa.sve; 69*c217d954SCole Faust } has_sve2()70*c217d954SCole Faust bool has_sve2() const 71*c217d954SCole Faust { 72*c217d954SCole Faust return _isa.sve2; 73*c217d954SCole Faust } has_sme()74*c217d954SCole Faust bool has_sme() const 75*c217d954SCole Faust { 76*c217d954SCole Faust return _isa.sme; 77*c217d954SCole Faust } has_sme2()78*c217d954SCole Faust bool has_sme2() const 79*c217d954SCole Faust { 80*c217d954SCole Faust return _isa.sme2; 81*c217d954SCole Faust } has_fp16()82*c217d954SCole Faust bool has_fp16() const 83*c217d954SCole Faust { 84*c217d954SCole Faust return _isa.fp16; 85*c217d954SCole Faust } has_bf16()86*c217d954SCole Faust bool has_bf16() const 87*c217d954SCole Faust { 88*c217d954SCole Faust return _isa.bf16; 89*c217d954SCole Faust } has_svebf16()90*c217d954SCole Faust bool has_svebf16() const 91*c217d954SCole Faust { 92*c217d954SCole Faust return _isa.svebf16; 93*c217d954SCole Faust } has_dotprod()94*c217d954SCole Faust bool has_dotprod() const 95*c217d954SCole Faust { 96*c217d954SCole Faust return _isa.dot; 97*c217d954SCole Faust } has_i8mm()98*c217d954SCole Faust bool has_i8mm() const 99*c217d954SCole Faust { 100*c217d954SCole Faust return _isa.i8mm; 101*c217d954SCole Faust } has_svei8mm()102*c217d954SCole Faust bool has_svei8mm() const 103*c217d954SCole Faust { 104*c217d954SCole Faust return _isa.svei8mm; 105*c217d954SCole Faust } has_svef32mm()106*c217d954SCole Faust bool has_svef32mm() const 107*c217d954SCole Faust { 108*c217d954SCole Faust return _isa.svef32mm; 109*c217d954SCole Faust } 110*c217d954SCole Faust isa()111*c217d954SCole Faust const CpuIsaInfo &isa() const 112*c217d954SCole Faust { 113*c217d954SCole Faust return _isa; 114*c217d954SCole Faust } cpus()115*c217d954SCole Faust const std::vector<CpuModel> &cpus() const 116*c217d954SCole Faust { 117*c217d954SCole Faust return _cpus; 118*c217d954SCole Faust } 119*c217d954SCole Faust 120*c217d954SCole Faust CpuModel cpu_model(uint32_t cpuid) const; 121*c217d954SCole Faust CpuModel cpu_model() const; 122*c217d954SCole Faust uint32_t num_cpus() const; 123*c217d954SCole Faust 124*c217d954SCole Faust private: 125*c217d954SCole Faust CpuIsaInfo _isa{}; 126*c217d954SCole Faust std::vector<CpuModel> _cpus{}; 127*c217d954SCole Faust }; 128*c217d954SCole Faust 129*c217d954SCole Faust /** Some systems have both big and small cores, this fuction computes the minimum number of cores 130*c217d954SCole Faust * that are exactly the same on the system. To maximize performance the library attempts to process 131*c217d954SCole Faust * workloads concurrently using as many threads as big cores are available on the system. 132*c217d954SCole Faust * 133*c217d954SCole Faust * @return The minumum number of common cores. 134*c217d954SCole Faust */ 135*c217d954SCole Faust uint32_t num_threads_hint(); 136*c217d954SCole Faust } // namespace cpuinfo 137*c217d954SCole Faust } // namespace arm_compute 138*c217d954SCole Faust #endif /* SRC_COMMON_CPUINFO_H */ 139