rpc : get available mem for the CPU backend

This can be overridden with the -m command line option

ref: #7293
This commit is contained in:
Radoslav Gerganov 2024-05-15 16:04:40 +03:00
parent 3b3963c55c
commit 9afdffe70e

View File

@ -7,6 +7,11 @@
#endif #endif
#include "ggml-rpc.h" #include "ggml-rpc.h"
#ifdef _WIN32
# include <windows.h>
#else
# include <unistd.h>
#endif
#include <string> #include <string>
#include <stdio.h> #include <stdio.h>
@ -84,9 +89,18 @@ static void get_backend_memory(size_t * free_mem, size_t * total_mem) {
#ifdef GGML_USE_CUDA #ifdef GGML_USE_CUDA
ggml_backend_cuda_get_device_memory(0, free_mem, total_mem); ggml_backend_cuda_get_device_memory(0, free_mem, total_mem);
#else #else
// TODO: implement for other backends #ifdef _WIN32
*free_mem = 1; MEMORYSTATUSEX status;
*total_mem = 1; status.dwLength = sizeof(status);
GlobalMemoryStatusEx(&status);
*total_mem = status.ullTotalPhys;
*free_mem = status.ullAvailPhys;
#else
long pages = sysconf(_SC_PHYS_PAGES);
long page_size = sysconf(_SC_PAGE_SIZE);
*total_mem = pages * page_size;
*free_mem = *total_mem;
#endif
#endif #endif
} }