Skip to content

Distribute and run LLMs with a single file.

Improve CPU brand detection

Justine Tunneye973fa23aeca
diff --git a/llama.cpp/llama-bench/llama-bench.cpp b/llama.cpp/llama-bench/llama-bench.cpp
index c436a431..83fd3479 100644
--- a/llama.cpp/llama-bench/llama-bench.cpp
+++ b/llama.cpp/llama-bench/llama-bench.cpp
@@ -97,16 +97,40 @@ static std::string replaceAll(std::string str, const std::string& from, const st
return str;
}
+
+#ifdef __x86_64__
+static void cpuid(unsigned leaf, unsigned subleaf, unsigned *info) {
+ asm("movq\t%%rbx,%%rsi\n\t"
+ "cpuid\n\t"
+ "xchgq\t%%rbx,%%rsi"
+ : "=a"(info[0]), "=S"(info[1]), "=c"(info[2]), "=d"(info[3])
+ : "0"(leaf), "2"(subleaf));
+}
+#endif // __x86_64__
+
static std::string get_cpu_info() { // [jart]
std::string id;
+#ifdef __x86_64__
+ union { // [jart]
+ char str[64];
+ unsigned reg[16];
+ } u = {0};
+ cpuid(0x80000002, 0, u.reg + 0*4);
+ cpuid(0x80000003, 0, u.reg + 1*4);
+ cpuid(0x80000004, 0, u.reg + 2*4);
+ int len = strlen(u.str);
+ while (len > 0 && u.str[len - 1] == ' ')
+ u.str[--len] = 0;
+ id = u.str;
+#else
if (IsLinux()) {
FILE * f = fopen("/proc/cpuinfo", "r");
if (f) {
char buf[1024];
while (fgets(buf, sizeof(buf), f)) {
- if (strncmp(buf, "model name", 10) == 0 ||
- startswith(buf, "Model :")) {
+ if (!strncmp(buf, "model name", 10) ||
+ startswith(buf, "Model\t\t:")) { // e.g. raspi
char * p = strchr(buf, ':');
if (p) {
p++;
@@ -117,9 +141,6 @@ static std::string get_cpu_info() { // [jart]
p[strlen(p) - 1] = '\0';
}
id = p;
- id = replaceAll(id, " 96-Cores", "");
- id = replaceAll(id, "(TM)", "");
- id = replaceAll(id, "(R)", "");
break;
}
}
@@ -127,7 +148,6 @@ static std::string get_cpu_info() { // [jart]
fclose(f);
}
}
-
if (IsXnu()) {
char cpu_name[128] = {0};
size_t size = sizeof(cpu_name);
@@ -135,6 +155,10 @@ static std::string get_cpu_info() { // [jart]
id = cpu_name;
}
}
+#endif
+ id = replaceAll(id, " 96-Cores", "");
+ id = replaceAll(id, "(TM)", "");
+ id = replaceAll(id, "(R)", "");
std::string march;
#ifdef __x86_64__