From e6da9bd96b3444941421e71a0962976d9931a773 Mon Sep 17 00:00:00 2001 From: niansa Date: Fri, 23 Jun 2023 17:57:09 +0200 Subject: [PATCH] Added ggml_vk_mem_used() --- ggml-vulkan.cpp | 17 ++++++++++++++++- ggml-vulkan.h | 4 +++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/ggml-vulkan.cpp b/ggml-vulkan.cpp index f8b24f706..12ed52fed 100644 --- a/ggml-vulkan.cpp +++ b/ggml-vulkan.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -53,11 +54,25 @@ ggml_kompute_context *ggml_vk_init() { return new ggml_kompute_context; } -void ggml_metal_free(struct ggml_kompute_context * ctx) { +void ggml_vk_free(struct ggml_kompute_context * ctx) { delete ctx; } +size_t ggml_vk_mem_used(struct ggml_kompute_context * ctx) { + size_t fres = 0; + ctx->tensors_mutex.lock(); + for (const auto& tensor : ctx->tensors) { + fres += tensor.second->size(); + } + ctx->tensors_mutex.unlock(); + for (const auto& buffer : ctx->buffers) { + fres += buffer.second->size(); + } + return fres; +} + + bool ggml_vk_add_buffer( struct ggml_kompute_context * ctx, const char * name, diff --git a/ggml-vulkan.h b/ggml-vulkan.h index 19aaec949..5ec392782 100644 --- a/ggml-vulkan.h +++ b/ggml-vulkan.h @@ -11,7 +11,9 @@ struct ggml_kompute_context; struct ggml_kompute_context * ggml_vk_init(void); -void ggml_metal_free(struct ggml_kompute_context * ctx); +void ggml_vk_free(struct ggml_kompute_context * ctx); + +size_t ggml_vk_mem_used(struct ggml_kompute_context * ctx); // creates a mapping between a host memory buffer and a device memory buffer // - make sure to map all buffers used in the graph before calling ggml_vk_graph_compute