Skip to content

Commit 1e1fa27

Browse files
slarenggerganov
authored andcommitted
rpc : use backend registry, support dl backends (llama/13304)
1 parent e1bdd14 commit 1e1fa27

File tree

2 files changed

+40
-16
lines changed

2 files changed

+40
-16
lines changed

ggml/src/ggml-cpu/ggml-cpu.cpp

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,26 @@
1111
#include <vector>
1212

1313
#ifdef GGML_USE_CPU_HBM
14-
#include "ggml-cpu-hbm.h"
14+
# include "ggml-cpu-hbm.h"
1515
#endif
1616

1717
#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"
2419
#endif
2520

2621
#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>
3029
#endif
31-
#include <windows.h>
30+
31+
#if defined(__APPLE__)
32+
# include <sys/sysctl.h>
33+
# include <sys/types.h>
3234
#endif
3335

3436
// ggml-backend interface
@@ -70,8 +72,10 @@ static ggml_backend_buffer_type_t * ggml_backend_cpu_device_get_extra_buffers_ty
7072
}
7173

7274
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+
}
7579
}
7680
return false;
7781
}
@@ -330,9 +334,18 @@ static const char * ggml_backend_cpu_device_get_description(ggml_backend_dev_t d
330334
}
331335

332336
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
336349

337350
GGML_UNUSED(dev);
338351
}

ggml/src/ggml-rpc/ggml-rpc.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,14 @@ static void rpc_serve_client(ggml_backend_t backend, const char * cache_dir,
15941594
void ggml_backend_rpc_start_server(ggml_backend_t backend, const char * endpoint,
15951595
const char * cache_dir,
15961596
size_t free_mem, size_t total_mem) {
1597+
printf("Starting RPC server v%d.%d.%d\n",
1598+
RPC_PROTO_MAJOR_VERSION,
1599+
RPC_PROTO_MINOR_VERSION,
1600+
RPC_PROTO_PATCH_VERSION);
1601+
printf(" endpoint : %s\n", endpoint);
1602+
printf(" local cache : %s\n", cache_dir ? cache_dir : "n/a");
1603+
printf(" backend memory : %zu MB\n", free_mem / (1024 * 1024));
1604+
15971605
std::string host;
15981606
int port;
15991607
if (!parse_endpoint(endpoint, host, port)) {
@@ -1753,6 +1761,9 @@ static void * ggml_backend_rpc_get_proc_address(ggml_backend_reg_t reg, const ch
17531761
if (std::strcmp(name, "ggml_backend_rpc_add_device") == 0) {
17541762
return (void *)ggml_backend_rpc_add_device;
17551763
}
1764+
if (std::strcmp(name, "ggml_backend_rpc_start_server") == 0) {
1765+
return (void *)ggml_backend_rpc_start_server;
1766+
}
17561767
return NULL;
17571768

17581769
GGML_UNUSED(reg);

0 commit comments

Comments
 (0)