]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
llama-bench : add support for getting cpu info on Windows (#8824)
authorZhenwei Jin <redacted>
Wed, 7 Aug 2024 01:01:06 +0000 (09:01 +0800)
committerGitHub <redacted>
Wed, 7 Aug 2024 01:01:06 +0000 (03:01 +0200)
* Add support for getting cpu info on Windows for llama_bench

* refactor

---------

Co-authored-by: slaren <redacted>
examples/llama-bench/llama-bench.cpp

index 521fa8880b7c7e9b9cd6290105a3b9f6c38823b2..42918bfc79f2240ba97a744367ee56101d14a7f5 100644 (file)
 #include "ggml-cann.h"
 #endif
 
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#ifndef NOMINMAX
+#   define NOMINMAX
+#endif
+#include <windows.h>
+#endif
+
 // utils
 static uint64_t get_time_ns() {
     using clock = std::chrono::high_resolution_clock;
@@ -96,6 +104,27 @@ static std::string get_cpu_info() {
         }
         fclose(f);
     }
+#elif defined(_WIN32)
+    HKEY hKey;
+    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+                     TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"),
+                     0,
+                     KEY_READ,
+                     &hKey) != ERROR_SUCCESS) {
+        // fail to open registry key
+        return "";
+    }
+    char cpu_brand[256];
+    DWORD cpu_brand_size = sizeof(cpu_brand);
+    if (RegQueryValueExA(hKey,
+                        TEXT("ProcessorNameString"),
+                        NULL,
+                        NULL,
+                        (LPBYTE)cpu_brand,
+                        &cpu_brand_size) == ERROR_SUCCESS) {
+        id.assign(cpu_brand, cpu_brand_size);
+    }
+    RegCloseKey(hKey);
 #endif
     // TODO: other platforms
     return id;