Skip to content

Commit 506122d

Browse files
kylo5abyslaren
andauthored
llama-bench : add support for getting cpu info on Windows (#8824)
* Add support for getting cpu info on Windows for llama_bench * refactor --------- Co-authored-by: slaren <[email protected]>
1 parent 725e3d9 commit 506122d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

examples/llama-bench/llama-bench.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
#include "ggml-cann.h"
2828
#endif
2929

30+
#ifdef _WIN32
31+
#define WIN32_LEAN_AND_MEAN
32+
#ifndef NOMINMAX
33+
# define NOMINMAX
34+
#endif
35+
#include <windows.h>
36+
#endif
37+
3038
// utils
3139
static uint64_t get_time_ns() {
3240
using clock = std::chrono::high_resolution_clock;
@@ -96,6 +104,27 @@ static std::string get_cpu_info() {
96104
}
97105
fclose(f);
98106
}
107+
#elif defined(_WIN32)
108+
HKEY hKey;
109+
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
110+
TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"),
111+
0,
112+
KEY_READ,
113+
&hKey) != ERROR_SUCCESS) {
114+
// fail to open registry key
115+
return "";
116+
}
117+
char cpu_brand[256];
118+
DWORD cpu_brand_size = sizeof(cpu_brand);
119+
if (RegQueryValueExA(hKey,
120+
TEXT("ProcessorNameString"),
121+
NULL,
122+
NULL,
123+
(LPBYTE)cpu_brand,
124+
&cpu_brand_size) == ERROR_SUCCESS) {
125+
id.assign(cpu_brand, cpu_brand_size);
126+
}
127+
RegCloseKey(hKey);
99128
#endif
100129
// TODO: other platforms
101130
return id;

0 commit comments

Comments
 (0)