Skip to content

Commit 4fa0b0a

Browse files
committed
remoting: cache the buffer_get_base result
1 parent 4f9a2d4 commit 4fa0b0a

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

ggml/src/ggml-remotingfrontend/ggml-backend-buffer-type.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ggml_backend_remoting_buffer_type_alloc_buffer(ggml_backend_buffer_type_t buft,
1515

1616
context->gpu = gpu;
1717
context->apir_context = apir_buffer_type_alloc_buffer(gpu, buft, size);
18+
context->base = NULL;
1819

1920
ggml_backend_buffer_t buffer = ggml_backend_buffer_init(buft, ggml_backend_remoting_buffer_interface, (void *) context, size);
2021

ggml/src/ggml-remotingfrontend/ggml-backend-buffer.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44
((struct ggml_backend_remoting_buffer_context *) (name)->context)->gpu
55

66
static void * ggml_backend_remoting_buffer_get_base(ggml_backend_buffer_t buffer) {
7-
//IMPLEMENTED;
7+
IMPLEMENTED_ONCE;
88

9-
struct virtgpu *gpu = BUFFER_TO_GPU(buffer);
9+
struct ggml_backend_remoting_buffer_context *context = (struct ggml_backend_remoting_buffer_context *) buffer->context;
10+
if (context->base) {
11+
return context->base;
12+
}
13+
14+
context->base = apir_buffer_get_base(BUFFER_TO_GPU(buffer),
15+
BUFFER_TO_APIR_CONTEXT(buffer));
1016

11-
return apir_buffer_get_base(gpu, BUFFER_TO_APIR_CONTEXT(buffer));
17+
return context->base;
1218
}
1319

1420
static void ggml_backend_remoting_buffer_memset_tensor(ggml_backend_buffer_t buffer, ggml_tensor * tensor, uint8_t value, size_t offset, size_t size) {

ggml/src/ggml-remotingfrontend/ggml-remoting.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ struct ggml_backend_remoting_buffer_context {
8888
apir_buffer_context_t apir_context;
8989

9090
struct virtgpu *gpu;
91+
92+
void *base;
9193
};
9294

9395
extern const ggml_backend_buffer_type_i ggml_backend_remoting_buffer_type_interface;

0 commit comments

Comments
 (0)