]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
rpc : get available mem for the CPU backend
authorRadoslav Gerganov <redacted>
Wed, 15 May 2024 13:04:40 +0000 (16:04 +0300)
committerRadoslav Gerganov <redacted>
Thu, 16 May 2024 09:04:08 +0000 (12:04 +0300)
This can be overridden with the -m command line option

ref: #7293

examples/rpc/rpc-server.cpp

index 021185b83cbbf794253ebb193d4cb55a1a35b869..41f377376eb23dd0d9af4c1f9182893292a778e1 100644 (file)
@@ -7,6 +7,11 @@
 #endif
 
 #include "ggml-rpc.h"
+#ifdef _WIN32
+#  include <windows.h>
+#else
+#  include <unistd.h>
+#endif
 #include <string>
 #include <stdio.h>
 
@@ -84,9 +89,18 @@ static void get_backend_memory(size_t * free_mem, size_t * total_mem) {
 #ifdef GGML_USE_CUDA
     ggml_backend_cuda_get_device_memory(0, free_mem, total_mem);
 #else
-    // TODO: implement for other backends
-    *free_mem = 1;
-    *total_mem = 1;
+    #ifdef _WIN32
+        MEMORYSTATUSEX status;
+        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
 }