Skip to content

Commit 94b2702

Browse files
committed
ggml-cpu: Rank neoverse-v2 over generic ARM
1 parent fd114fe commit 94b2702

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

ggml/src/ggml-cpu/arch/arm/cpu-feats.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
#if defined(__linux__)
66
#include <sys/auxv.h>
7+
8+
#include <fstream>
9+
#include <string>
710
#elif defined(__APPLE__)
811
#include <sys/sysctl.h>
912
#endif
@@ -17,6 +20,7 @@
1720
#endif
1821

1922
struct aarch64_features {
23+
int cpu_part = -1;
2024
// has_neon not needed, aarch64 has NEON guaranteed
2125
bool has_dotprod = false;
2226
bool has_fp16_va = false;
@@ -36,6 +40,17 @@ struct aarch64_features {
3640
has_sve2 = !!(hwcap2 & HWCAP2_SVE2);
3741
has_i8mm = !!(hwcap2 & HWCAP2_I8MM);
3842
has_sme = !!(hwcap2 & HWCAP2_SME);
43+
44+
std::ifstream cpuinfo("/proc/cpuinfo");
45+
std::string line;
46+
while (std::getline(cpuinfo, line)) {
47+
if (line.find("CPU part") == 0) {
48+
// Parse the hex number after the colon
49+
cpu_part = std::stoi(line.substr(line.find(':') + 1), nullptr, 16);
50+
break;
51+
}
52+
}
53+
cpuinfo.close();
3954
#elif defined(__APPLE__)
4055
int oldp = 0;
4156
size_t size = sizeof(oldp);
@@ -63,6 +78,11 @@ static int ggml_backend_cpu_aarch64_score() {
6378

6479
// Bits 2-8 are used to rank backends by architecture or core when they
6580
// otherwise have identical features.
81+
#if defined(GGML_ARM_MCPU) && GGML_ARM_MCPU == NEOVERSE_V2
82+
if (af.cpu_part == 0xd4f) {
83+
score += 1<<5;
84+
}
85+
#endif
6686

6787
// Bits 9+: Features always trump architecture or core.
6888
#ifdef GGML_USE_DOTPROD

0 commit comments

Comments
 (0)