Skip to content

Commit 87c28dd

Browse files
rgerganovslaren
authored andcommitted
llama : offload to RPC in addition to other backends (llama/7640)
* llama : offload to RPC in addition to other backends * - fix copy_tensor being called on the src buffer instead of the dst buffer - always initialize views in the view_src buffer - add RPC backend to Makefile build - add endpoint to all RPC object names * add rpc-server to Makefile * Update llama.cpp Co-authored-by: slaren <[email protected]> --------- Co-authored-by: slaren <[email protected]>
1 parent 437b0cf commit 87c28dd

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

ggml-alloc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ static void ggml_gallocr_init_tensor(ggml_gallocr_t galloc, struct ggml_tensor *
750750
// this tensor was allocated without ggml-backend
751751
return;
752752
}
753-
ggml_backend_view_init(galloc->buffers[buffer_id], tensor);
753+
ggml_backend_view_init(tensor);
754754
}
755755
} else {
756756
if (tensor->data == NULL) {
@@ -899,12 +899,12 @@ static bool alloc_tensor_range(struct ggml_context * ctx,
899899
if (t->view_src == NULL) {
900900
ggml_tallocr_alloc(&tallocr, t);
901901
} else if (t->buffer == NULL) {
902-
ggml_backend_view_init(buffer, t);
902+
ggml_backend_view_init(t);
903903
}
904904
} else {
905905
if (t->view_src != NULL && t->buffer == NULL) {
906906
// view of a pre-allocated tensor
907-
ggml_backend_view_init(buffer, t);
907+
ggml_backend_view_init(t);
908908
}
909909
}
910910
}

ggml-backend.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void ggml_backend_buffer_reset(ggml_backend_buffer_t buffer) {
151151
bool ggml_backend_buffer_copy_tensor(const struct ggml_tensor * src, struct ggml_tensor * dst) {
152152
ggml_backend_buffer_t dst_buf = dst->view_src ? dst->view_src->buffer : dst->buffer;
153153
if (dst_buf->iface.cpy_tensor) {
154-
return src->buffer->iface.cpy_tensor(dst_buf, src, dst);
154+
return dst_buf->iface.cpy_tensor(dst_buf, src, dst);
155155
}
156156
return false;
157157
}
@@ -1887,15 +1887,15 @@ ggml_backend_t ggml_backend_sched_get_tensor_backend(ggml_backend_sched_t sched,
18871887

18881888
// utils
18891889

1890-
void ggml_backend_view_init(ggml_backend_buffer_t buffer, struct ggml_tensor * tensor) {
1890+
void ggml_backend_view_init(struct ggml_tensor * tensor) {
18911891
GGML_ASSERT(tensor->buffer == NULL);
18921892
GGML_ASSERT(tensor->view_src != NULL);
18931893
GGML_ASSERT(tensor->view_src->buffer != NULL);
18941894
GGML_ASSERT(tensor->view_src->data != NULL);
18951895

1896-
tensor->buffer = buffer;
1896+
tensor->buffer = tensor->view_src->buffer;
18971897
tensor->data = (char *)tensor->view_src->data + tensor->view_offs;
1898-
ggml_backend_buffer_init_tensor(buffer, tensor);
1898+
ggml_backend_buffer_init_tensor(tensor->buffer, tensor);
18991899
}
19001900

19011901
void ggml_backend_tensor_alloc(ggml_backend_buffer_t buffer, struct ggml_tensor * tensor, void * addr) {
@@ -1954,7 +1954,7 @@ static void graph_copy_init_tensor(struct ggml_hash_set hash_set, struct ggml_te
19541954
struct ggml_tensor * dst = node_copies[id];
19551955
if (dst->view_src != NULL) {
19561956
graph_copy_init_tensor(hash_set, node_copies, node_init, src->view_src);
1957-
ggml_backend_view_init(dst->view_src->buffer, dst);
1957+
ggml_backend_view_init(dst);
19581958
}
19591959
else {
19601960
ggml_backend_tensor_copy(src, dst);

ggml-backend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ extern "C" {
225225

226226
// Tensor initialization
227227
GGML_API void ggml_backend_tensor_alloc(ggml_backend_buffer_t buffer, struct ggml_tensor * tensor, void * addr);
228-
GGML_API void ggml_backend_view_init(ggml_backend_buffer_t buffer, struct ggml_tensor * tensor);
228+
GGML_API void ggml_backend_view_init(struct ggml_tensor * tensor);
229229

230230

231231
#ifdef __cplusplus

ggml-rpc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ GGML_CALL static ggml_backend_buffer_t ggml_backend_rpc_buffer_type_alloc_buffer
491491
if (remote_ptr != 0) {
492492
ggml_backend_buffer_t buffer = ggml_backend_buffer_init(buft,
493493
ggml_backend_rpc_buffer_interface,
494-
new ggml_backend_rpc_buffer_context{sock, {}, remote_ptr, "RPC"},
494+
new ggml_backend_rpc_buffer_context{sock, {}, remote_ptr, "RPC[" + std::string(buft_ctx->endpoint) + "]"},
495495
remote_size);
496496
return buffer;
497497
} else {
@@ -692,7 +692,7 @@ GGML_API GGML_CALL ggml_backend_buffer_type_t ggml_backend_rpc_buffer_type(const
692692
GGML_CALL ggml_backend_t ggml_backend_rpc_init(const char * endpoint) {
693693
ggml_backend_rpc_context * ctx = new ggml_backend_rpc_context {
694694
/* .endpoint = */ endpoint,
695-
/* .name = */ "RPC",
695+
/* .name = */ "RPC[" + std::string(endpoint) + "]",
696696
};
697697

698698
ggml_backend_t backend = new ggml_backend {

0 commit comments

Comments
 (0)