Added ggml_vk_mem_used()

This commit is contained in:
niansa 2023-06-23 17:57:09 +02:00
parent 1a68195408
commit e6da9bd96b
2 changed files with 19 additions and 2 deletions

View file

@ -10,6 +10,7 @@
#include <exception> #include <exception>
#include <thread> #include <thread>
#include <mutex> #include <mutex>
#include <atomic>
#include <cstring> #include <cstring>
#include <immintrin.h> #include <immintrin.h>
#include <kompute/Kompute.hpp> #include <kompute/Kompute.hpp>
@ -53,11 +54,25 @@ ggml_kompute_context *ggml_vk_init() {
return new ggml_kompute_context; 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; 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( bool ggml_vk_add_buffer(
struct ggml_kompute_context * ctx, struct ggml_kompute_context * ctx,
const char * name, const char * name,

View file

@ -11,7 +11,9 @@ struct ggml_kompute_context;
struct ggml_kompute_context * ggml_vk_init(void); 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 // 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 // - make sure to map all buffers used in the graph before calling ggml_vk_graph_compute