Skip to content

Commit 99d5b28

Browse files
rgerganovteleprint-me
authored andcommitted
rpc : get available mem for the CPU backend
This can be overridden with the -m command line option ref: ggml-org#7293
1 parent 3d210da commit 99d5b28

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

examples/rpc/rpc-server.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
#endif
88

99
#include "ggml-rpc.h"
10+
#ifdef _WIN32
11+
# include <windows.h>
12+
#else
13+
# include <unistd.h>
14+
#endif
1015
#include <string>
1116
#include <stdio.h>
1217

@@ -84,9 +89,18 @@ static void get_backend_memory(size_t * free_mem, size_t * total_mem) {
8489
#ifdef GGML_USE_CUDA
8590
ggml_backend_cuda_get_device_memory(0, free_mem, total_mem);
8691
#else
87-
// TODO: implement for other backends
88-
*free_mem = 1;
89-
*total_mem = 1;
92+
#ifdef _WIN32
93+
MEMORYSTATUSEX status;
94+
status.dwLength = sizeof(status);
95+
GlobalMemoryStatusEx(&status);
96+
*total_mem = status.ullTotalPhys;
97+
*free_mem = status.ullAvailPhys;
98+
#else
99+
long pages = sysconf(_SC_PHYS_PAGES);
100+
long page_size = sysconf(_SC_PAGE_SIZE);
101+
*total_mem = pages * page_size;
102+
*free_mem = *total_mem;
103+
#endif
90104
#endif
91105
}
92106

0 commit comments

Comments
 (0)