|
11 | 11 | #include <vector>
|
12 | 12 |
|
13 | 13 | #ifdef GGML_USE_CPU_HBM
|
14 |
| -#include "ggml-cpu-hbm.h" |
| 14 | +# include "ggml-cpu-hbm.h" |
15 | 15 | #endif
|
16 | 16 |
|
17 | 17 | #ifdef GGML_USE_CPU_KLEIDIAI
|
18 |
| -#include "kleidiai/kleidiai.h" |
19 |
| -#endif |
20 |
| - |
21 |
| -#if defined(__APPLE__) |
22 |
| -#include <sys/types.h> |
23 |
| -#include <sys/sysctl.h> |
| 18 | +# include "kleidiai/kleidiai.h" |
24 | 19 | #endif
|
25 | 20 |
|
26 | 21 | #if defined(_WIN32)
|
27 |
| -#define WIN32_LEAN_AND_MEAN |
28 |
| -#ifndef NOMINMAX |
29 |
| - #define NOMINMAX |
| 22 | +# define WIN32_LEAN_AND_MEAN |
| 23 | +# ifndef NOMINMAX |
| 24 | +# define NOMINMAX |
| 25 | +# endif |
| 26 | +# include <windows.h> |
| 27 | +#else |
| 28 | +# include <unistd.h> |
30 | 29 | #endif
|
31 |
| -#include <windows.h> |
| 30 | + |
| 31 | +#if defined(__APPLE__) |
| 32 | +# include <sys/sysctl.h> |
| 33 | +# include <sys/types.h> |
32 | 34 | #endif
|
33 | 35 |
|
34 | 36 | // ggml-backend interface
|
@@ -70,8 +72,10 @@ static ggml_backend_buffer_type_t * ggml_backend_cpu_device_get_extra_buffers_ty
|
70 | 72 | }
|
71 | 73 |
|
72 | 74 | static bool ggml_backend_cpu_is_extra_buffer_type(ggml_backend_buffer_type_t buft) {
|
73 |
| - for (auto extra : ggml_backend_cpu_get_extra_buffers_type()) { |
74 |
| - if (extra && extra == buft) return true; |
| 75 | + for (auto * extra : ggml_backend_cpu_get_extra_buffers_type()) { |
| 76 | + if (extra && extra == buft) { |
| 77 | + return true; |
| 78 | + } |
75 | 79 | }
|
76 | 80 | return false;
|
77 | 81 | }
|
@@ -330,9 +334,18 @@ static const char * ggml_backend_cpu_device_get_description(ggml_backend_dev_t d
|
330 | 334 | }
|
331 | 335 |
|
332 | 336 | static void ggml_backend_cpu_device_get_memory(ggml_backend_dev_t dev, size_t * free, size_t * total) {
|
333 |
| - // TODO |
334 |
| - *free = 0; |
335 |
| - *total = 0; |
| 337 | +#ifdef _WIN32 |
| 338 | + MEMORYSTATUSEX status; |
| 339 | + status.dwLength = sizeof(status); |
| 340 | + GlobalMemoryStatusEx(&status); |
| 341 | + *total = status.ullTotalPhys; |
| 342 | + *free = status.ullAvailPhys; |
| 343 | +#else |
| 344 | + long pages = sysconf(_SC_PHYS_PAGES); |
| 345 | + long page_size = sysconf(_SC_PAGE_SIZE); |
| 346 | + *total = pages * page_size; |
| 347 | + *free = *total; |
| 348 | +#endif |
336 | 349 |
|
337 | 350 | GGML_UNUSED(dev);
|
338 | 351 | }
|
|
0 commit comments