diff options
author | Georgios Pinitas <georgios.pinitas@arm.com> | 2021-06-24 20:32:11 +0100 |
---|---|---|
committer | Georgios Pinitas <georgios.pinitas@arm.com> | 2021-06-28 12:00:14 +0000 |
commit | 731fe667e3009bfbfee8b0eb74ecb68b291e4311 (patch) | |
tree | e3a8ea66b88cee4af19363212e5a92864032becd /src/common/cpuinfo | |
parent | b1496e6a1074c90fba64633ec92fa202f5f7d1d8 (diff) | |
download | ComputeLibrary-731fe667e3009bfbfee8b0eb74ecb68b291e4311.tar.gz |
Simplify CpuInfo logic
Refactors the CpuInfo extraction code and cleans the usage of it in the
CpuContext class
Signed-off-by: Georgios Pinitas <georgios.pinitas@arm.com>
Change-Id: Iea47dfdaad431fb49285da92778d6b42cf318f60
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/5848
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Giorgio Arena <giorgio.arena@arm.com>
Diffstat (limited to 'src/common/cpuinfo')
-rw-r--r-- | src/common/cpuinfo/CpuInfo.h | 9 | ||||
-rw-r--r-- | src/common/cpuinfo/CpuIsaInfo.cpp | 117 |
2 files changed, 40 insertions, 86 deletions
diff --git a/src/common/cpuinfo/CpuInfo.h b/src/common/cpuinfo/CpuInfo.h index c04c9f4ec8..135ff96931 100644 --- a/src/common/cpuinfo/CpuInfo.h +++ b/src/common/cpuinfo/CpuInfo.h @@ -100,6 +100,15 @@ public: return _isa.svef32mm; } + const CpuIsaInfo &isa() const + { + return _isa; + } + const std::vector<CpuModel> &cpus() const + { + return _cpus; + } + CpuModel cpu_model(uint32_t cpuid) const; CpuModel cpu_model() const; uint32_t num_cpus() const; diff --git a/src/common/cpuinfo/CpuIsaInfo.cpp b/src/common/cpuinfo/CpuIsaInfo.cpp index 14466ef4e7..845ad1c4e9 100644 --- a/src/common/cpuinfo/CpuIsaInfo.cpp +++ b/src/common/cpuinfo/CpuIsaInfo.cpp @@ -49,69 +49,36 @@ namespace cpuinfo { namespace { +inline bool is_feature_supported(uint64_t features, uint64_t feature_mask) +{ + return (features & feature_mask); +} + #if defined(__arm__) void decode_hwcaps(CpuIsaInfo &isa, const uint32_t hwcaps, const uint32_t hwcaps2) { ARM_COMPUTE_UNUSED(hwcaps2); - - if(hwcaps & ARM_COMPUTE_CPU_FEATURE_HWCAP_HALF) - { - isa.fp16 = true; - } - if(hwcaps & ARM_COMPUTE_CPU_FEATURE_HWCAP_NEON) - { - isa.neon = true; - } + isa.fp16 = is_feature_supported(hwcaps, ARM_COMPUTE_CPU_FEATURE_HWCAP_HALF); + isa.neon = is_feature_supported(hwcaps, ARM_COMPUTE_CPU_FEATURE_HWCAP_NEON); } #elif defined(__aarch64__) void decode_hwcaps(CpuIsaInfo &isa, const uint32_t hwcaps, const uint32_t hwcaps2) { // High-level SIMD support - if(hwcaps & ARM_COMPUTE_CPU_FEATURE_HWCAP_ASIMD) - { - isa.neon = true; - } - if(hwcaps & ARM_COMPUTE_CPU_FEATURE_HWCAP_SVE) - { - isa.sve = true; - } - if(hwcaps2 & ARM_COMPUTE_CPU_FEATURE_HWCAP2_SVE2) - { - isa.sve2 = true; - } + isa.neon = is_feature_supported(hwcaps, ARM_COMPUTE_CPU_FEATURE_HWCAP_ASIMD); + isa.sve = is_feature_supported(hwcaps, ARM_COMPUTE_CPU_FEATURE_HWCAP_SVE); + isa.sve2 = is_feature_supported(hwcaps2, ARM_COMPUTE_CPU_FEATURE_HWCAP2_SVE2); // Data-type support - const uint32_t fp16_support_mask = ARM_COMPUTE_CPU_FEATURE_HWCAP_FPHP | ARM_COMPUTE_CPU_FEATURE_HWCAP_ASIMDHP; - if(hwcaps & fp16_support_mask) - { - isa.fp16 = true; - } - if(hwcaps2 & ARM_COMPUTE_CPU_FEATURE_HWCAP2_BF16) - { - isa.bf16 = true; - } - if(hwcaps2 & ARM_COMPUTE_CPU_FEATURE_HWCAP2_SVEBF16) - { - isa.svebf16 = true; - } + isa.fp16 = is_feature_supported(hwcaps, ARM_COMPUTE_CPU_FEATURE_HWCAP_FPHP | ARM_COMPUTE_CPU_FEATURE_HWCAP_ASIMDHP); + isa.bf16 = is_feature_supported(hwcaps2, ARM_COMPUTE_CPU_FEATURE_HWCAP2_BF16); + isa.svebf16 = is_feature_supported(hwcaps2, ARM_COMPUTE_CPU_FEATURE_HWCAP2_SVEBF16); // Instruction extensions - if(hwcaps & ARM_COMPUTE_CPU_FEATURE_HWCAP_ASIMDDP) - { - isa.dot = true; - } - if(hwcaps2 & ARM_COMPUTE_CPU_FEATURE_HWCAP2_I8MM) - { - isa.i8mm = true; - } - if(hwcaps2 & ARM_COMPUTE_CPU_FEATURE_HWCAP2_SVEI8MM) - { - isa.svei8mm = true; - } - if(hwcaps2 & ARM_COMPUTE_CPU_FEATURE_HWCAP2_SVEF32MM) - { - isa.svef32mm = true; - } + isa.dot = is_feature_supported(hwcaps, ARM_COMPUTE_CPU_FEATURE_HWCAP_ASIMDDP); + isa.i8mm = is_feature_supported(hwcaps2, ARM_COMPUTE_CPU_FEATURE_HWCAP2_I8MM); + isa.svei8mm = is_feature_supported(hwcaps2, ARM_COMPUTE_CPU_FEATURE_HWCAP2_SVEI8MM); + isa.svef32mm = is_feature_supported(hwcaps2, ARM_COMPUTE_CPU_FEATURE_HWCAP2_SVEF32MM); } #else /* defined(__aarch64__) */ void decode_hwcaps(CpuIsaInfo &isa, const uint32_t hwcaps, const uint32_t hwcaps2) @@ -122,47 +89,25 @@ void decode_hwcaps(CpuIsaInfo &isa, const uint32_t hwcaps, const uint32_t hwcaps void decode_regs(CpuIsaInfo &isa, const uint64_t isar0, const uint64_t isar1, const uint64_t pfr0, const uint64_t svefr0) { - // High-level SIMD support - if((pfr0 >> 32) & 0xf) - { - isa.sve = true; - } - if(svefr0 & 0xf) + auto is_supported = [](uint64_t feature_reg, uint8_t feature_pos) -> bool { - isa.sve2 = true; - } + return ((feature_reg >> feature_pos) & 0xf); + }; + + // High-level SIMD support + isa.sve = is_supported(pfr0, 32); + isa.sve2 = is_supported(svefr0, 0); // Data-type support - if((pfr0 >> 16) & 0xf) - { - isa.fp16 = true; - } - if((isar1 >> 44) & 0xf) - { - isa.bf16 = true; - } - if((svefr0 >> 20) & 0xf) - { - isa.svebf16 = true; - } + isa.fp16 = is_supported(pfr0, 16); + isa.bf16 = is_supported(isar1, 44); + isa.svebf16 = is_supported(svefr0, 20); // Instruction extensions - if((isar0 >> 44) & 0xf) - { - isa.dot = true; - } - if((isar1 >> 48) & 0xf) - { - isa.i8mm = true; - } - if((svefr0 >> 44) & 0xf) - { - isa.svei8mm = true; - } - if((svefr0 >> 52) & 0xf) - { - isa.svef32mm = true; - } + isa.dot = is_supported(isar0, 44); + isa.i8mm = is_supported(isar1, 48); + isa.svei8mm = is_supported(svefr0, 44); + isa.svef32mm = is_supported(svefr0, 52); } /** Handle features from whitelisted models in case of problematic kernels |