mirror of
https://github.com/ggml-org/whisper.cpp.git
synced 2026-10-21 09:41:29 +02:00
ggml : add alloc_buffer_n to buffer type interface (llama/23671)
* ggml : add `alloc_buffer_n` to buffer type interface Add alloc_buffer_n method to ggml_backend_buffer_type_i interface, with a public API ggml_backend_buft_alloc_buffer_n. - Default implementation in ggml-backend.cpp handles multi-buffer splitting and tensor allocation via ggml_tallocr - Meta buffer type provides custom implementation that creates per-device sub-contexts and delegates to simple buffer types - ggml_backend_alloc_ctx_tensors_from_buft now collects tensors into a list and delegates to the new API - Remove temporary ggml_backend_meta_alloc_ctx_tensors_from_buft - Add NULL alloc_buffer_n to all existing buffer type interfaces (cpu, metal, openvino, hexagon, webgpu, zdnn, virtgpu, repack) Assisted-by: llama.cpp:local pi * cont : fix `cur_buf_size` init after flushing a buffer * ggml : add TODO tag for shared buffer split logic Assisted-by: pi:llama.cpp/DeepSeek-V4-Flash-Vision-Exp * tests : add alloc_buffer_n coverage Assisted-by: pi:llama.cpp/DeepSeek-V4-Flash-Vision-Exp * cont : fix compile warnings * tests : add descriptions for alloc_buffer_n tests Assisted-by: pi:llama.cpp/Qwen3.8-27B * ggml : address review comments on alloc_buffer_n - restore GGML_LOG_ERROR on buffer alloc / tensor init failure in the default impl (name the failing tensor) - check the malloc result and drop the _impl indirection in ggml_backend_alloc_ctx_tensors_from_buft - remove comments that restate the code - fix the TAG_ALLOC_SHARED_BUFFER_SPLIT typo Assisted-by: pi:llama.cpp/Qwen3.8-27B * ggml : add get_alloc_size_n to buffer type interface - Add ggml_backend_buft_get_alloc_size_n public API - Add optional get_alloc_size_n callback to ggml_backend_buffer_type_i - Share tensor->buffer planning between alloc_buffer_n default and get_alloc_size_n default - Replace unchecked realloc with std::vector in alloc_buffer_n default - Make ggml_backend_alloc_ctx_tensors_from_buft_size use the new API - Add test-alloc coverage for get_alloc_size_n Assisted-by: pi:llama.cpp/DeepSeek-V4-Flash-Vision-Exp * cont : report malloc failure
This commit is contained in:
@@ -75,9 +75,10 @@ GGML_API size_t ggml_gallocr_get_buffer_size(ggml_gallocr_t galloc, int buffer_i
|
|||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
// Create a buffer and allocate all the tensors in a ggml_context
|
// Create a buffer and allocate all the tensors in a ggml_context
|
||||||
// ggml_backend_alloc_ctx_tensors_from_buft_size returns the size of the buffer that would be allocated by ggml_backend_alloc_ctx_tensors_from_buft
|
|
||||||
// ggml_backend_alloc_ctx_tensors_from_buft returns NULL on failure or if all tensors in ctx are already allocated or zero-sized
|
// returns the size of the buffer that would be allocated by ggml_backend_alloc_ctx_tensors_from_buft. returns 0 on failure
|
||||||
GGML_API size_t ggml_backend_alloc_ctx_tensors_from_buft_size(struct ggml_context * ctx, ggml_backend_buffer_type_t buft);
|
GGML_API size_t ggml_backend_alloc_ctx_tensors_from_buft_size(struct ggml_context * ctx, ggml_backend_buffer_type_t buft);
|
||||||
|
// returns NULL on failure or if all tensors in ctx are already allocated or zero-sized
|
||||||
GGML_API struct ggml_backend_buffer * ggml_backend_alloc_ctx_tensors_from_buft(struct ggml_context * ctx, ggml_backend_buffer_type_t buft);
|
GGML_API struct ggml_backend_buffer * ggml_backend_alloc_ctx_tensors_from_buft(struct ggml_context * ctx, ggml_backend_buffer_type_t buft);
|
||||||
GGML_API struct ggml_backend_buffer * ggml_backend_alloc_ctx_tensors(struct ggml_context * ctx, ggml_backend_t backend);
|
GGML_API struct ggml_backend_buffer * ggml_backend_alloc_ctx_tensors(struct ggml_context * ctx, ggml_backend_t backend);
|
||||||
|
|
||||||
|
|||||||
@@ -34,13 +34,15 @@ extern "C" {
|
|||||||
// Backend buffer type
|
// Backend buffer type
|
||||||
//
|
//
|
||||||
|
|
||||||
GGML_API const char * ggml_backend_buft_name (ggml_backend_buffer_type_t buft);
|
GGML_API const char * ggml_backend_buft_name (ggml_backend_buffer_type_t buft);
|
||||||
GGML_API ggml_backend_buffer_t ggml_backend_buft_alloc_buffer (ggml_backend_buffer_type_t buft, size_t size);
|
GGML_API ggml_backend_buffer_t ggml_backend_buft_alloc_buffer (ggml_backend_buffer_type_t buft, size_t size);
|
||||||
GGML_API size_t ggml_backend_buft_get_alignment (ggml_backend_buffer_type_t buft);
|
GGML_API ggml_backend_buffer_t ggml_backend_buft_alloc_buffer_n (ggml_backend_buffer_type_t buft, struct ggml_tensor ** tensors, int n_tensors);
|
||||||
GGML_API size_t ggml_backend_buft_get_max_size (ggml_backend_buffer_type_t buft);
|
GGML_API size_t ggml_backend_buft_get_alignment (ggml_backend_buffer_type_t buft);
|
||||||
GGML_API size_t ggml_backend_buft_get_alloc_size(ggml_backend_buffer_type_t buft, const struct ggml_tensor * tensor);
|
GGML_API size_t ggml_backend_buft_get_max_size (ggml_backend_buffer_type_t buft);
|
||||||
GGML_API bool ggml_backend_buft_is_host (ggml_backend_buffer_type_t buft);
|
GGML_API size_t ggml_backend_buft_get_alloc_size (ggml_backend_buffer_type_t buft, const struct ggml_tensor * tensor);
|
||||||
GGML_API ggml_backend_dev_t ggml_backend_buft_get_device (ggml_backend_buffer_type_t buft);
|
GGML_API size_t ggml_backend_buft_get_alloc_size_n(ggml_backend_buffer_type_t buft, struct ggml_tensor ** tensors, int n_tensors);
|
||||||
|
GGML_API bool ggml_backend_buft_is_host (ggml_backend_buffer_type_t buft);
|
||||||
|
GGML_API ggml_backend_dev_t ggml_backend_buft_get_device (ggml_backend_buffer_type_t buft);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Backend buffer
|
// Backend buffer
|
||||||
|
|||||||
+35
-111
@@ -1117,131 +1117,55 @@ size_t ggml_gallocr_get_buffer_size(ggml_gallocr_t galloc, int buffer_id) {
|
|||||||
|
|
||||||
// utils
|
// utils
|
||||||
|
|
||||||
static void free_buffers(ggml_backend_buffer_t ** buffers, const size_t * n_buffers) {
|
static struct ggml_tensor ** ggml_backend_alloc_ctx_tensors_from_buft_collect(
|
||||||
for (size_t i = 0; i < *n_buffers; i++) {
|
struct ggml_context * ctx, int * n_tensors) {
|
||||||
ggml_backend_buffer_free((*buffers)[i]);
|
int n = 0;
|
||||||
|
for (struct ggml_tensor * t = ggml_get_first_tensor(ctx); t != NULL; t = ggml_get_next_tensor(ctx, t)) {
|
||||||
|
n++;
|
||||||
}
|
}
|
||||||
free(*buffers);
|
*n_tensors = n;
|
||||||
|
if (n == 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ggml_tensor ** tensors = (struct ggml_tensor **) malloc(n * sizeof(struct ggml_tensor *));
|
||||||
|
if (tensors == NULL) {
|
||||||
|
GGML_LOG_ERROR("%s: failed to allocate %zu bytes\n", __func__, n * sizeof(struct ggml_tensor *));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
int i = 0;
|
||||||
|
for (struct ggml_tensor * t = ggml_get_first_tensor(ctx); t != NULL; t = ggml_get_next_tensor(ctx, t)) {
|
||||||
|
tensors[i++] = t;
|
||||||
|
}
|
||||||
|
return tensors;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool alloc_tensor_range(struct ggml_context * ctx,
|
ggml_backend_buffer_t ggml_backend_alloc_ctx_tensors_from_buft(struct ggml_context * ctx, ggml_backend_buffer_type_t buft) {
|
||||||
struct ggml_tensor * first, struct ggml_tensor * last,
|
|
||||||
ggml_backend_buffer_type_t buft, size_t size,
|
|
||||||
ggml_backend_buffer_t ** buffers, size_t * n_buffers) {
|
|
||||||
|
|
||||||
ggml_backend_buffer_t buffer = ggml_backend_buft_alloc_buffer(buft, size);
|
|
||||||
if (buffer == NULL) {
|
|
||||||
GGML_LOG_ERROR("%s: failed to allocate %s buffer of size %zu\n", __func__, ggml_backend_buft_name(buft), size);
|
|
||||||
free_buffers(buffers, n_buffers);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
*buffers = realloc(*buffers, sizeof(ggml_backend_buffer_t) * (*n_buffers + 1));
|
|
||||||
(*buffers)[(*n_buffers)++] = buffer;
|
|
||||||
|
|
||||||
struct ggml_tallocr tallocr = ggml_tallocr_new(buffer);
|
|
||||||
|
|
||||||
for (struct ggml_tensor * t = first; t != last; t = ggml_get_next_tensor(ctx, t)) {
|
|
||||||
enum ggml_status status = GGML_STATUS_SUCCESS;
|
|
||||||
if (t->data == NULL) {
|
|
||||||
if (t->view_src == NULL) {
|
|
||||||
status = ggml_tallocr_alloc(&tallocr, t);
|
|
||||||
} else if (t->buffer == NULL) {
|
|
||||||
status = ggml_backend_view_init(t);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (t->view_src != NULL && t->buffer == NULL) {
|
|
||||||
// view of a pre-allocated tensor
|
|
||||||
status = ggml_backend_view_init(t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (status != GGML_STATUS_SUCCESS) {
|
|
||||||
GGML_LOG_ERROR("%s: failed to initialize tensor %s\n", __func__, t->name);
|
|
||||||
free_buffers(buffers, n_buffers);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static ggml_backend_buffer_t ggml_backend_alloc_ctx_tensors_from_buft_impl(
|
|
||||||
struct ggml_context * ctx, ggml_backend_buffer_type_t buft, size_t * nbytes_total, bool no_alloc) {
|
|
||||||
GGML_ASSERT(ggml_get_no_alloc(ctx) == true);
|
GGML_ASSERT(ggml_get_no_alloc(ctx) == true);
|
||||||
|
|
||||||
size_t alignment = ggml_backend_buft_get_alignment(buft);
|
int n_tensors = 0;
|
||||||
size_t max_size = ggml_backend_buft_get_max_size(buft);
|
struct ggml_tensor ** tensors = ggml_backend_alloc_ctx_tensors_from_buft_collect(ctx, &n_tensors);
|
||||||
|
if (tensors == NULL) {
|
||||||
ggml_backend_buffer_t * buffers = NULL;
|
|
||||||
size_t n_buffers = 0;
|
|
||||||
*nbytes_total = 0;
|
|
||||||
|
|
||||||
size_t cur_buf_size = 0;
|
|
||||||
struct ggml_tensor * first = ggml_get_first_tensor(ctx);
|
|
||||||
for (struct ggml_tensor * t = first; t != NULL; t = ggml_get_next_tensor(ctx, t)) {
|
|
||||||
size_t this_size = 0;
|
|
||||||
if (t->data == NULL && t->view_src == NULL) {
|
|
||||||
this_size = GGML_PAD(ggml_backend_buft_get_alloc_size(buft, t), alignment);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cur_buf_size > 0 && (cur_buf_size + this_size) > max_size) {
|
|
||||||
// allocate tensors in the current buffer
|
|
||||||
if (!no_alloc && !alloc_tensor_range(ctx, first, t, buft, cur_buf_size, &buffers, &n_buffers)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
first = t;
|
|
||||||
*nbytes_total += cur_buf_size;
|
|
||||||
cur_buf_size = this_size;
|
|
||||||
} else {
|
|
||||||
cur_buf_size += this_size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// allocate remaining tensors
|
|
||||||
if (cur_buf_size > 0) {
|
|
||||||
*nbytes_total += cur_buf_size;
|
|
||||||
if (!no_alloc && !alloc_tensor_range(ctx, first, NULL, buft, cur_buf_size, &buffers, &n_buffers)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (no_alloc) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n_buffers == 0) {
|
ggml_backend_buffer_t buffer = ggml_backend_buft_alloc_buffer_n(buft, tensors, n_tensors);
|
||||||
#ifndef NDEBUG
|
free(tensors);
|
||||||
GGML_LOG_DEBUG("%s: all tensors in the context are already allocated\n", __func__);
|
|
||||||
#endif
|
|
||||||
GGML_ASSERT(!buffers);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ggml_backend_buffer_t buffer;
|
|
||||||
if (n_buffers == 1) {
|
|
||||||
buffer = buffers[0];
|
|
||||||
} else {
|
|
||||||
buffer = ggml_backend_multi_buffer_alloc_buffer(buffers, n_buffers);
|
|
||||||
}
|
|
||||||
if (buffers) {
|
|
||||||
free(buffers); // can be NULL if context is empty or no_alloc
|
|
||||||
}
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ggml_backend_alloc_ctx_tensors_from_buft_size(struct ggml_context * ctx, ggml_backend_buffer_type_t buft) {
|
size_t ggml_backend_alloc_ctx_tensors_from_buft_size(struct ggml_context * ctx, ggml_backend_buffer_type_t buft) {
|
||||||
size_t nbytes_total = 0;
|
GGML_ASSERT(ggml_get_no_alloc(ctx) == true);
|
||||||
ggml_backend_buffer_t buf = ggml_backend_alloc_ctx_tensors_from_buft_impl(ctx, buft, &nbytes_total, /*no_alloc=*/ true);
|
|
||||||
GGML_ASSERT(!buf);
|
|
||||||
return nbytes_total;
|
|
||||||
}
|
|
||||||
|
|
||||||
ggml_backend_buffer_t ggml_backend_alloc_ctx_tensors_from_buft(struct ggml_context * ctx, ggml_backend_buffer_type_t buft) {
|
int n_tensors = 0;
|
||||||
size_t nbytes_total = 0;
|
struct ggml_tensor ** tensors = ggml_backend_alloc_ctx_tensors_from_buft_collect(ctx, &n_tensors);
|
||||||
if (ggml_backend_buft_is_meta(buft)) {
|
if (tensors == NULL) {
|
||||||
return ggml_backend_meta_alloc_ctx_tensors_from_buft(ctx, buft);
|
return 0;
|
||||||
}
|
}
|
||||||
return ggml_backend_alloc_ctx_tensors_from_buft_impl(ctx, buft, &nbytes_total, /*no_alloc =*/ false);
|
|
||||||
|
size_t nbytes_total = ggml_backend_buft_get_alloc_size_n(buft, tensors, n_tensors);
|
||||||
|
free(tensors);
|
||||||
|
return nbytes_total;
|
||||||
}
|
}
|
||||||
|
|
||||||
ggml_backend_buffer_t ggml_backend_alloc_ctx_tensors(struct ggml_context * ctx, ggml_backend_t backend) {
|
ggml_backend_buffer_t ggml_backend_alloc_ctx_tensors(struct ggml_context * ctx, ggml_backend_t backend) {
|
||||||
|
|||||||
@@ -8,24 +8,28 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define GGML_BACKEND_API_VERSION 2
|
#define GGML_BACKEND_API_VERSION 3
|
||||||
|
|
||||||
//
|
//
|
||||||
// Backend buffer type
|
// Backend buffer type
|
||||||
//
|
//
|
||||||
|
|
||||||
struct ggml_backend_buffer_type_i {
|
struct ggml_backend_buffer_type_i {
|
||||||
const char * (*get_name) (ggml_backend_buffer_type_t buft);
|
const char * (*get_name) (ggml_backend_buffer_type_t buft);
|
||||||
// allocate a buffer of this type
|
// allocate a buffer of this type
|
||||||
ggml_backend_buffer_t (*alloc_buffer) (ggml_backend_buffer_type_t buft, size_t size);
|
ggml_backend_buffer_t (*alloc_buffer) (ggml_backend_buffer_type_t buft, size_t size);
|
||||||
|
// (optional) allocate tensors from a list into a buffer of this type (defaults to alloc_buffer + linear allocator)
|
||||||
|
ggml_backend_buffer_t (*alloc_buffer_n) (ggml_backend_buffer_type_t buft, struct ggml_tensor ** tensors, int n_tensors);
|
||||||
// tensor alignment
|
// tensor alignment
|
||||||
size_t (*get_alignment) (ggml_backend_buffer_type_t buft);
|
size_t (*get_alignment) (ggml_backend_buffer_type_t buft);
|
||||||
// (optional) max buffer size that can be allocated (defaults to SIZE_MAX)
|
// (optional) max buffer size that can be allocated (defaults to SIZE_MAX)
|
||||||
size_t (*get_max_size) (ggml_backend_buffer_type_t buft);
|
size_t (*get_max_size) (ggml_backend_buffer_type_t buft);
|
||||||
// (optional) data size needed to allocate the tensor, including padding (defaults to ggml_nbytes)
|
// (optional) data size needed to allocate the tensor, including padding (defaults to ggml_nbytes)
|
||||||
size_t (*get_alloc_size)(ggml_backend_buffer_type_t buft, const struct ggml_tensor * tensor);
|
size_t (*get_alloc_size) (ggml_backend_buffer_type_t buft, const struct ggml_tensor * tensor);
|
||||||
|
// (optional) total data size needed to allocate the given tensors, including padding and splitting (defaults to per-tensor get_alloc_size)
|
||||||
|
size_t (*get_alloc_size_n)(ggml_backend_buffer_type_t buft, struct ggml_tensor ** tensors, int n_tensors);
|
||||||
// (optional) check if tensor data is in host memory and uses standard ggml tensor layout (defaults to false)
|
// (optional) check if tensor data is in host memory and uses standard ggml tensor layout (defaults to false)
|
||||||
bool (*is_host) (ggml_backend_buffer_type_t buft);
|
bool (*is_host) (ggml_backend_buffer_type_t buft);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ggml_backend_buffer_type {
|
struct ggml_backend_buffer_type {
|
||||||
@@ -101,9 +105,6 @@ extern "C" {
|
|||||||
GGML_API size_t ggml_backend_meta_n_backends (ggml_backend_t meta_backend);
|
GGML_API size_t ggml_backend_meta_n_backends (ggml_backend_t meta_backend);
|
||||||
GGML_API ggml_backend_t ggml_backend_meta_simple_backend(ggml_backend_t meta_backend, size_t index);
|
GGML_API ggml_backend_t ggml_backend_meta_simple_backend(ggml_backend_t meta_backend, size_t index);
|
||||||
|
|
||||||
// temporary workaround to statically allocate tensors from a context in a deduplicated way:
|
|
||||||
GGML_API struct ggml_backend_buffer * ggml_backend_meta_alloc_ctx_tensors_from_buft(struct ggml_context * ctx, ggml_backend_buffer_type_t buft);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Backend (stream)
|
// Backend (stream)
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -290,6 +290,8 @@ static ggml_backend_buffer_type_t ggml_backend_meta_buft_simple_buft(ggml_backen
|
|||||||
|
|
||||||
static ggml_backend_buffer_t ggml_backend_meta_buffer_type_alloc_buffer(ggml_backend_buffer_type_t buft, size_t size);
|
static ggml_backend_buffer_t ggml_backend_meta_buffer_type_alloc_buffer(ggml_backend_buffer_type_t buft, size_t size);
|
||||||
|
|
||||||
|
static ggml_backend_buffer_t ggml_backend_meta_buffer_type_alloc_buffer_n(ggml_backend_buffer_type_t buft, ggml_tensor ** tensors, int n_tensors);
|
||||||
|
|
||||||
static size_t ggml_backend_meta_buffer_type_get_alignment(ggml_backend_buffer_type_t buft) {
|
static size_t ggml_backend_meta_buffer_type_get_alignment(ggml_backend_buffer_type_t buft) {
|
||||||
const size_t n_simple_bufts = ggml_backend_meta_buft_n_bufts(buft);
|
const size_t n_simple_bufts = ggml_backend_meta_buft_n_bufts(buft);
|
||||||
size_t max_alignment = 1;
|
size_t max_alignment = 1;
|
||||||
@@ -331,12 +333,14 @@ static bool ggml_backend_meta_buffer_type_is_host(ggml_backend_buffer_type_t buf
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const struct ggml_backend_buffer_type_i ggml_backend_meta_buffer_type_iface = {
|
static const struct ggml_backend_buffer_type_i ggml_backend_meta_buffer_type_iface = {
|
||||||
/* .get_name = */ ggml_backend_meta_buffer_type_get_name,
|
/* .get_name = */ ggml_backend_meta_buffer_type_get_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_meta_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_meta_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_meta_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ ggml_backend_meta_buffer_type_alloc_buffer_n,
|
||||||
/* .get_max_size = */ ggml_backend_meta_buffer_type_get_max_size,
|
/* .get_alignment = */ ggml_backend_meta_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_meta_buffer_type_get_alloc_size,
|
/* .get_max_size = */ ggml_backend_meta_buffer_type_get_max_size,
|
||||||
/* .is_host = */ ggml_backend_meta_buffer_type_is_host,
|
/* .get_alloc_size = */ ggml_backend_meta_buffer_type_get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ ggml_backend_meta_buffer_type_is_host,
|
||||||
};
|
};
|
||||||
|
|
||||||
bool ggml_backend_buft_is_meta(ggml_backend_buffer_type_t buft) {
|
bool ggml_backend_buft_is_meta(ggml_backend_buffer_type_t buft) {
|
||||||
@@ -1715,17 +1719,17 @@ static ggml_backend_buffer_t ggml_backend_meta_buffer_type_alloc_buffer(ggml_bac
|
|||||||
return ggml_backend_buffer_init(buft, ggml_backend_meta_buffer_iface, buf_ctx, max_size);
|
return ggml_backend_buffer_init(buft, ggml_backend_meta_buffer_iface, buf_ctx, max_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ggml_backend_buffer * ggml_backend_meta_alloc_ctx_tensors_from_buft(struct ggml_context * ctx, ggml_backend_buffer_type_t buft) {
|
static ggml_backend_buffer_t ggml_backend_meta_buffer_type_alloc_buffer_n(ggml_backend_buffer_type_t buft, ggml_tensor ** tensors, int n_tensors) {
|
||||||
const size_t n_simple_bufts = ggml_backend_meta_buft_n_bufts(buft);
|
const size_t n_simple_bufts = ggml_backend_meta_buft_n_bufts(buft);
|
||||||
|
|
||||||
constexpr size_t compute_headroom = 16; // Maximum number of views per statically allocated tensor that can be created between evals.
|
constexpr size_t compute_headroom = 16; // Maximum number of views per statically allocated tensor that can be created between evals.
|
||||||
const ggml_init_params params_static = {
|
const ggml_init_params params_static = {
|
||||||
/*.mem_size =*/ ggml_get_mem_size(ctx),
|
/*.mem_size =*/ n_tensors * ggml_tensor_overhead(),
|
||||||
/*.mem_buffer =*/ nullptr,
|
/*.mem_buffer =*/ nullptr,
|
||||||
/*.no_alloc =*/ true,
|
/*.no_alloc =*/ true,
|
||||||
};
|
};
|
||||||
const ggml_init_params params_compute = {
|
const ggml_init_params params_compute = {
|
||||||
/*.mem_size =*/ compute_headroom*ggml_get_mem_size(ctx),
|
/*.mem_size =*/ compute_headroom * n_tensors * ggml_tensor_overhead(),
|
||||||
/*.mem_buffer =*/ nullptr,
|
/*.mem_buffer =*/ nullptr,
|
||||||
/*.no_alloc =*/ true,
|
/*.no_alloc =*/ true,
|
||||||
};
|
};
|
||||||
@@ -1737,7 +1741,8 @@ struct ggml_backend_buffer * ggml_backend_meta_alloc_ctx_tensors_from_buft(struc
|
|||||||
ggml_backend_meta_buffer_context * meta_buf_ctx = new ggml_backend_meta_buffer_context(stc_static, stc_compute_0, stc_compute_1, bufs);
|
ggml_backend_meta_buffer_context * meta_buf_ctx = new ggml_backend_meta_buffer_context(stc_static, stc_compute_0, stc_compute_1, bufs);
|
||||||
|
|
||||||
ggml_backend_buffer_t meta_buf = ggml_backend_buffer_init(buft, ggml_backend_meta_buffer_iface, meta_buf_ctx, 0);
|
ggml_backend_buffer_t meta_buf = ggml_backend_buffer_init(buft, ggml_backend_meta_buffer_iface, meta_buf_ctx, 0);
|
||||||
for (ggml_tensor * t = ggml_get_first_tensor(ctx); t != nullptr; t = ggml_get_next_tensor(ctx, t)) {
|
for (int i = 0; i < n_tensors; i++) {
|
||||||
|
ggml_tensor * t = tensors[i];
|
||||||
t->buffer = meta_buf;
|
t->buffer = meta_buf;
|
||||||
ggml_backend_meta_buffer_init_tensor_impl(meta_buf_ctx->stc_static, t);
|
ggml_backend_meta_buffer_init_tensor_impl(meta_buf_ctx->stc_static, t);
|
||||||
t->data = (void *) 0x2000000000000000; // FIXME
|
t->data = (void *) 0x2000000000000000; // FIXME
|
||||||
|
|||||||
+156
-12
@@ -45,6 +45,138 @@ ggml_backend_buffer_t ggml_backend_buft_alloc_buffer(ggml_backend_buffer_type_t
|
|||||||
return buft->iface.alloc_buffer(buft, size);
|
return buft->iface.alloc_buffer(buft, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// shared planning logic for allocating a list of tensors into one or more buffers of the given type
|
||||||
|
struct ggml_backend_buft_alloc_buffer_n_plan_item {
|
||||||
|
size_t size; // total bytes for this buffer
|
||||||
|
int first; // first tensor index (inclusive)
|
||||||
|
int last; // last tensor index (exclusive)
|
||||||
|
};
|
||||||
|
|
||||||
|
using ggml_backend_buft_alloc_buffer_n_plan_t = std::vector<ggml_backend_buft_alloc_buffer_n_plan_item>;
|
||||||
|
|
||||||
|
static ggml_backend_buft_alloc_buffer_n_plan_t ggml_backend_buft_alloc_buffer_n_plan(
|
||||||
|
ggml_backend_buffer_type_t buft, struct ggml_tensor ** tensors, int n_tensors) {
|
||||||
|
ggml_backend_buft_alloc_buffer_n_plan_t plan;
|
||||||
|
|
||||||
|
const size_t alignment = ggml_backend_buft_get_alignment(buft);
|
||||||
|
const size_t max_size = ggml_backend_buft_get_max_size(buft);
|
||||||
|
|
||||||
|
size_t cur_buf_size = 0;
|
||||||
|
int first = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < n_tensors; i++) {
|
||||||
|
size_t this_size = 0;
|
||||||
|
struct ggml_tensor * t = tensors[i];
|
||||||
|
if (t->data == NULL && t->view_src == NULL) {
|
||||||
|
this_size = GGML_PAD(ggml_backend_buft_get_alloc_size(buft, t), alignment);
|
||||||
|
}
|
||||||
|
|
||||||
|
// flush the current buffer if adding this tensor would exceed max_size
|
||||||
|
if (cur_buf_size > 0 && (cur_buf_size + this_size) > max_size) {
|
||||||
|
plan.push_back({ cur_buf_size, first, i });
|
||||||
|
cur_buf_size = this_size;
|
||||||
|
first = i;
|
||||||
|
} else {
|
||||||
|
cur_buf_size += this_size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cur_buf_size > 0) {
|
||||||
|
plan.push_back({ cur_buf_size, first, n_tensors });
|
||||||
|
}
|
||||||
|
|
||||||
|
return plan;
|
||||||
|
}
|
||||||
|
|
||||||
|
// default implementation of alloc_buffer_n
|
||||||
|
// allocates tensors from a list into one or more buffers of the given type
|
||||||
|
static ggml_backend_buffer_t ggml_backend_buft_alloc_buffer_n_default(ggml_backend_buffer_type_t buft, struct ggml_tensor ** tensors, int n_tensors) {
|
||||||
|
const ggml_backend_buft_alloc_buffer_n_plan_t plan = ggml_backend_buft_alloc_buffer_n_plan(buft, tensors, n_tensors);
|
||||||
|
|
||||||
|
std::vector<ggml_backend_buffer_t> buffers;
|
||||||
|
buffers.reserve(plan.size());
|
||||||
|
|
||||||
|
for (const ggml_backend_buft_alloc_buffer_n_plan_item & item : plan) {
|
||||||
|
ggml_backend_buffer_t buffer = ggml_backend_buft_alloc_buffer(buft, item.size);
|
||||||
|
if (buffer == NULL) {
|
||||||
|
GGML_LOG_ERROR("%s: failed to allocate %s buffer of size %zu\n", __func__, ggml_backend_buft_name(buft), item.size);
|
||||||
|
for (ggml_backend_buffer_t b : buffers) {
|
||||||
|
ggml_backend_buffer_free(b);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ggml_tallocr tallocr = ggml_tallocr_new(buffer);
|
||||||
|
|
||||||
|
// allocate tensors in the current buffer
|
||||||
|
struct ggml_tensor * t_failed = NULL;
|
||||||
|
for (int j = item.first; j < item.last; j++) {
|
||||||
|
struct ggml_tensor * t = tensors[j];
|
||||||
|
if (t->data == NULL) {
|
||||||
|
if (t->view_src == NULL) {
|
||||||
|
if (ggml_tallocr_alloc(&tallocr, t) != GGML_STATUS_SUCCESS) {
|
||||||
|
t_failed = t;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (t->buffer == NULL) {
|
||||||
|
if (ggml_backend_view_init(t) != GGML_STATUS_SUCCESS) {
|
||||||
|
t_failed = t;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (t->view_src != NULL && t->buffer == NULL) {
|
||||||
|
// view of a pre-allocated tensor
|
||||||
|
if (ggml_backend_view_init(t) != GGML_STATUS_SUCCESS) {
|
||||||
|
t_failed = t;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (t_failed != NULL) {
|
||||||
|
GGML_LOG_ERROR("%s: failed to initialize tensor %s\n", __func__, t_failed->name);
|
||||||
|
for (ggml_backend_buffer_t b : buffers) {
|
||||||
|
ggml_backend_buffer_free(b);
|
||||||
|
}
|
||||||
|
ggml_backend_buffer_free(buffer);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffers.push_back(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buffers.empty()) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buffers.size() == 1) {
|
||||||
|
return buffers[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ggml_backend_multi_buffer_alloc_buffer(buffers.data(), buffers.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// default implementation of get_alloc_size_n
|
||||||
|
// returns the total size that alloc_buffer_n_default would allocate for the given tensors
|
||||||
|
static size_t ggml_backend_buft_get_alloc_size_n_default(ggml_backend_buffer_type_t buft, struct ggml_tensor ** tensors, int n_tensors) {
|
||||||
|
const ggml_backend_buft_alloc_buffer_n_plan_t plan = ggml_backend_buft_alloc_buffer_n_plan(buft, tensors, n_tensors);
|
||||||
|
|
||||||
|
size_t total = 0;
|
||||||
|
for (const ggml_backend_buft_alloc_buffer_n_plan_item & item : plan) {
|
||||||
|
total += item.size;
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
ggml_backend_buffer_t ggml_backend_buft_alloc_buffer_n(ggml_backend_buffer_type_t buft, struct ggml_tensor ** tensors, int n_tensors) {
|
||||||
|
GGML_ASSERT(buft);
|
||||||
|
if (buft->iface.alloc_buffer_n) {
|
||||||
|
return buft->iface.alloc_buffer_n(buft, tensors, n_tensors);
|
||||||
|
}
|
||||||
|
return ggml_backend_buft_alloc_buffer_n_default(buft, tensors, n_tensors);
|
||||||
|
}
|
||||||
|
|
||||||
size_t ggml_backend_buft_get_alignment(ggml_backend_buffer_type_t buft) {
|
size_t ggml_backend_buft_get_alignment(ggml_backend_buffer_type_t buft) {
|
||||||
GGML_ASSERT(buft);
|
GGML_ASSERT(buft);
|
||||||
return buft->iface.get_alignment(buft);
|
return buft->iface.get_alignment(buft);
|
||||||
@@ -78,6 +210,14 @@ size_t ggml_backend_buft_get_alloc_size(ggml_backend_buffer_type_t buft, const s
|
|||||||
return ggml_nbytes(tensor);
|
return ggml_nbytes(tensor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t ggml_backend_buft_get_alloc_size_n(ggml_backend_buffer_type_t buft, struct ggml_tensor ** tensors, int n_tensors) {
|
||||||
|
GGML_ASSERT(buft);
|
||||||
|
if (buft->iface.get_alloc_size_n) {
|
||||||
|
return buft->iface.get_alloc_size_n(buft, tensors, n_tensors);
|
||||||
|
}
|
||||||
|
return ggml_backend_buft_get_alloc_size_n_default(buft, tensors, n_tensors);
|
||||||
|
}
|
||||||
|
|
||||||
bool ggml_backend_buft_is_host(ggml_backend_buffer_type_t buft) {
|
bool ggml_backend_buft_is_host(ggml_backend_buffer_type_t buft) {
|
||||||
GGML_ASSERT(buft);
|
GGML_ASSERT(buft);
|
||||||
if (buft->iface.is_host) {
|
if (buft->iface.is_host) {
|
||||||
@@ -2486,12 +2626,14 @@ static bool ggml_backend_cpu_buffer_type_is_host(ggml_backend_buffer_type_t buft
|
|||||||
ggml_backend_buffer_type_t ggml_backend_cpu_buffer_type(void) {
|
ggml_backend_buffer_type_t ggml_backend_cpu_buffer_type(void) {
|
||||||
static struct ggml_backend_buffer_type ggml_backend_cpu_buffer_type = {
|
static struct ggml_backend_buffer_type ggml_backend_cpu_buffer_type = {
|
||||||
/* .iface = */ {
|
/* .iface = */ {
|
||||||
/* .get_name = */ ggml_backend_cpu_buffer_type_get_name,
|
/* .get_name = */ ggml_backend_cpu_buffer_type_get_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_cpu_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_cpu_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_cpu_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ NULL, // defaults to SIZE_MAX
|
/* .get_alignment = */ ggml_backend_cpu_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ NULL, // defaults to ggml_nbytes
|
/* .get_max_size = */ NULL, // defaults to SIZE_MAX
|
||||||
/* .is_host = */ ggml_backend_cpu_buffer_type_is_host,
|
/* .get_alloc_size = */ NULL, // defaults to ggml_nbytes
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ ggml_backend_cpu_buffer_type_is_host,
|
||||||
},
|
},
|
||||||
/* .device = */ NULL, // FIXME ggml_backend_reg_dev_get(ggml_backend_cpu_reg(), 0),
|
/* .device = */ NULL, // FIXME ggml_backend_reg_dev_get(ggml_backend_cpu_reg(), 0),
|
||||||
/* .context = */ NULL,
|
/* .context = */ NULL,
|
||||||
@@ -2509,12 +2651,14 @@ static const char * ggml_backend_cpu_buffer_from_ptr_type_get_name(ggml_backend_
|
|||||||
static ggml_backend_buffer_type_t ggml_backend_cpu_buffer_from_ptr_type(void) {
|
static ggml_backend_buffer_type_t ggml_backend_cpu_buffer_from_ptr_type(void) {
|
||||||
static struct ggml_backend_buffer_type ggml_backend_cpu_buffer_type = {
|
static struct ggml_backend_buffer_type ggml_backend_cpu_buffer_type = {
|
||||||
/* .iface = */ {
|
/* .iface = */ {
|
||||||
/* .get_name = */ ggml_backend_cpu_buffer_from_ptr_type_get_name,
|
/* .get_name = */ ggml_backend_cpu_buffer_from_ptr_type_get_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_cpu_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_cpu_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_cpu_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ NULL, // defaults to SIZE_MAX
|
/* .get_alignment = */ ggml_backend_cpu_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ NULL, // defaults to ggml_nbytes
|
/* .get_max_size = */ NULL, // defaults to SIZE_MAX
|
||||||
/* .is_host = */ ggml_backend_cpu_buffer_type_is_host,
|
/* .get_alloc_size = */ NULL, // defaults to ggml_nbytes
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ ggml_backend_cpu_buffer_type_is_host,
|
||||||
},
|
},
|
||||||
/* .device = */ NULL, // FIXME ggml_backend_reg_dev_get(ggml_backend_cpu_reg(), 0),
|
/* .device = */ NULL, // FIXME ggml_backend_reg_dev_get(ggml_backend_cpu_reg(), 0),
|
||||||
/* .context = */ NULL,
|
/* .context = */ NULL,
|
||||||
|
|||||||
@@ -1595,12 +1595,14 @@ static bool ggml_backend_cann_buffer_type_is_host(ggml_backend_buffer_type_t buf
|
|||||||
* memory for CANN buffer types in the GGML backend.
|
* memory for CANN buffer types in the GGML backend.
|
||||||
*/
|
*/
|
||||||
static const ggml_backend_buffer_type_i ggml_backend_cann_buffer_type_interface = {
|
static const ggml_backend_buffer_type_i ggml_backend_cann_buffer_type_interface = {
|
||||||
/* .get_name = */ ggml_backend_cann_buffer_type_name,
|
/* .get_name = */ ggml_backend_cann_buffer_type_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_cann_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_cann_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_cann_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ NULL, // defaults to SIZE_MAX
|
/* .get_alignment = */ ggml_backend_cann_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_cann_buffer_type_get_alloc_size,
|
/* .get_max_size = */ NULL, // defaults to SIZE_MAX
|
||||||
/* .is_host = */ ggml_backend_cann_buffer_type_is_host,
|
/* .get_alloc_size = */ ggml_backend_cann_buffer_type_get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ ggml_backend_cann_buffer_type_is_host,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1742,12 +1744,14 @@ static ggml_backend_buffer_t ggml_backend_cann_host_buffer_type_alloc_buffer(ggm
|
|||||||
ggml_backend_buffer_type_t ggml_backend_cann_host_buffer_type() {
|
ggml_backend_buffer_type_t ggml_backend_cann_host_buffer_type() {
|
||||||
static struct ggml_backend_buffer_type ggml_backend_cann_buffer_type_host = {
|
static struct ggml_backend_buffer_type ggml_backend_cann_buffer_type_host = {
|
||||||
/* .iface = */ {
|
/* .iface = */ {
|
||||||
/* .get_name = */ ggml_backend_cann_host_buffer_type_name,
|
/* .get_name = */ ggml_backend_cann_host_buffer_type_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_cann_host_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_cann_host_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_cpu_buffer_type()->iface.get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ NULL, // defaults to SIZE_MAX
|
/* .get_alignment = */ ggml_backend_cpu_buffer_type()->iface.get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_cpu_buffer_type()->iface.get_alloc_size,
|
/* .get_max_size = */ NULL, // defaults to SIZE_MAX
|
||||||
/* .is_host = */ ggml_backend_cpu_buffer_type()->iface.is_host,
|
/* .get_alloc_size = */ ggml_backend_cpu_buffer_type()->iface.get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ ggml_backend_cpu_buffer_type()->iface.is_host,
|
||||||
},
|
},
|
||||||
/* .device = */
|
/* .device = */
|
||||||
ggml_backend_reg_dev_get(ggml_backend_cann_reg(), 0),
|
ggml_backend_reg_dev_get(ggml_backend_cann_reg(), 0),
|
||||||
|
|||||||
@@ -228,12 +228,14 @@ static bool ggml_amx_init() {
|
|||||||
ggml_backend_buffer_type_t ggml_backend_amx_buffer_type() {
|
ggml_backend_buffer_type_t ggml_backend_amx_buffer_type() {
|
||||||
static struct ggml_backend_buffer_type ggml_backend_buffer_type_amx = {
|
static struct ggml_backend_buffer_type ggml_backend_buffer_type_amx = {
|
||||||
/* .iface = */ {
|
/* .iface = */ {
|
||||||
/* .get_name = */ ggml_backend_amx_buffer_type_get_name,
|
/* .get_name = */ ggml_backend_amx_buffer_type_get_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_amx_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_amx_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_amx_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ nullptr,
|
||||||
/* .get_max_size = */ nullptr, // defaults to SIZE_MAX
|
/* .get_alignment = */ ggml_backend_amx_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_amx_buffer_type_get_alloc_size,
|
/* .get_max_size = */ nullptr, // defaults to SIZE_MAX
|
||||||
/* .is_host = */ nullptr,
|
/* .get_alloc_size = */ ggml_backend_amx_buffer_type_get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ nullptr,
|
||||||
},
|
},
|
||||||
/* .device = */ ggml_backend_reg_dev_get(ggml_backend_cpu_reg(), 0),
|
/* .device = */ ggml_backend_reg_dev_get(ggml_backend_cpu_reg(), 0),
|
||||||
/* .context = */ new ggml::cpu::amx::extra_buffer_type(),
|
/* .context = */ new ggml::cpu::amx::extra_buffer_type(),
|
||||||
|
|||||||
@@ -40,12 +40,14 @@ static ggml_backend_buffer_t ggml_backend_cpu_hbm_buffer_type_alloc_buffer(ggml_
|
|||||||
ggml_backend_buffer_type_t ggml_backend_cpu_hbm_buffer_type(void) {
|
ggml_backend_buffer_type_t ggml_backend_cpu_hbm_buffer_type(void) {
|
||||||
static struct ggml_backend_buffer_type ggml_backend_cpu_buffer_type_hbm = {
|
static struct ggml_backend_buffer_type ggml_backend_cpu_buffer_type_hbm = {
|
||||||
/* .iface = */ {
|
/* .iface = */ {
|
||||||
/* .get_name = */ ggml_backend_cpu_hbm_buffer_type_get_name,
|
/* .get_name = */ ggml_backend_cpu_hbm_buffer_type_get_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_cpu_hbm_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_cpu_hbm_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_cpu_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ nullptr,
|
||||||
/* .get_max_size = */ nullptr, // defaults to SIZE_MAX
|
/* .get_alignment = */ ggml_backend_cpu_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ nullptr, // defaults to ggml_nbytes
|
/* .get_max_size = */ nullptr, // defaults to SIZE_MAX
|
||||||
/* .is_host = */ ggml_backend_cpu_buffer_type_is_host,
|
/* .get_alloc_size = */ nullptr, // defaults to ggml_nbytes
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ ggml_backend_cpu_buffer_type_is_host,
|
||||||
},
|
},
|
||||||
/* .context = */ nullptr,
|
/* .context = */ nullptr,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1902,12 +1902,14 @@ ggml_backend_buffer_type_t ggml_backend_cpu_kleidiai_buffer_type(void) {
|
|||||||
static ggml::cpu::kleidiai::extra_buffer_type ctx;
|
static ggml::cpu::kleidiai::extra_buffer_type ctx;
|
||||||
static struct ggml_backend_buffer_type ggml_backend_cpu_buffer_type_kleidiai = {
|
static struct ggml_backend_buffer_type ggml_backend_cpu_buffer_type_kleidiai = {
|
||||||
/* .iface = */ {
|
/* .iface = */ {
|
||||||
/* .get_name = */ ggml_backend_cpu_kleidiai_buffer_type_get_name,
|
/* .get_name = */ ggml_backend_cpu_kleidiai_buffer_type_get_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_cpu_kleidiai_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_cpu_kleidiai_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_cpu_kleidiai_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ nullptr,
|
||||||
/* .get_max_size = */ nullptr, // defaults to SIZE_MAX
|
/* .get_alignment = */ ggml_backend_cpu_kleidiai_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_cpu_kleidiai_buffer_type_get_alloc_size,
|
/* .get_max_size = */ nullptr, // defaults to SIZE_MAX
|
||||||
/* .is_host = */ nullptr,
|
/* .get_alloc_size = */ ggml_backend_cpu_kleidiai_buffer_type_get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ nullptr,
|
||||||
},
|
},
|
||||||
/* .device = */ ggml_backend_reg_dev_get(ggml_backend_cpu_reg(), 0),
|
/* .device = */ ggml_backend_reg_dev_get(ggml_backend_cpu_reg(), 0),
|
||||||
/* .context = */ &ctx,
|
/* .context = */ &ctx,
|
||||||
|
|||||||
@@ -5238,12 +5238,14 @@ class extra_buffer_type : ggml::cpu::extra_buffer_type {
|
|||||||
ggml_backend_buffer_type_t ggml_backend_cpu_repack_buffer_type(void) {
|
ggml_backend_buffer_type_t ggml_backend_cpu_repack_buffer_type(void) {
|
||||||
static struct ggml_backend_buffer_type ggml_backend_cpu_buffer_type_repack = {
|
static struct ggml_backend_buffer_type ggml_backend_cpu_buffer_type_repack = {
|
||||||
/* .iface = */ {
|
/* .iface = */ {
|
||||||
/* .get_name = */ ggml_backend_cpu_repack_buffer_type_get_name,
|
/* .get_name = */ ggml_backend_cpu_repack_buffer_type_get_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_cpu_repack_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_cpu_repack_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_cpu_repack_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ nullptr,
|
||||||
/* .get_max_size = */ nullptr, // defaults to SIZE_MAX
|
/* .get_alignment = */ ggml_backend_cpu_repack_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ nullptr, // defaults to ggml_nbytes
|
/* .get_max_size = */ nullptr, // defaults to SIZE_MAX
|
||||||
/* .is_host = */ nullptr,
|
/* .get_alloc_size = */ nullptr, // defaults to ggml_nbytes
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ nullptr,
|
||||||
},
|
},
|
||||||
/* .device = */ ggml_backend_reg_dev_get(ggml_backend_cpu_reg(), 0),
|
/* .device = */ ggml_backend_reg_dev_get(ggml_backend_cpu_reg(), 0),
|
||||||
/* .context = */ new ggml::cpu::repack::extra_buffer_type(),
|
/* .context = */ new ggml::cpu::repack::extra_buffer_type(),
|
||||||
|
|||||||
@@ -1650,12 +1650,14 @@ ggml_backend_buffer_type_t ggml_backend_cpu_riscv64_spacemit_buffer_type(void) {
|
|||||||
static ggml_backend_buffer_type ggml_backend_cpu_buffer_type_riscv64_spacemit = {
|
static ggml_backend_buffer_type ggml_backend_cpu_buffer_type_riscv64_spacemit = {
|
||||||
/* .iface = */
|
/* .iface = */
|
||||||
{
|
{
|
||||||
/* .get_name = */ ggml_backend_cpu_riscv64_spacemit_buffer_type_get_name,
|
/* .get_name = */ ggml_backend_cpu_riscv64_spacemit_buffer_type_get_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_cpu_riscv64_spacemit_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_cpu_riscv64_spacemit_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_cpu_riscv64_spacemit_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ nullptr,
|
/* .get_alignment = */ ggml_backend_cpu_riscv64_spacemit_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_cpu_riscv64_spacemit_nbytes,
|
/* .get_max_size = */ nullptr,
|
||||||
/* .is_host = */ nullptr,
|
/* .get_alloc_size = */ ggml_backend_cpu_riscv64_spacemit_nbytes,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ nullptr,
|
||||||
},
|
},
|
||||||
/* .device = */
|
/* .device = */
|
||||||
ggml_backend_reg_dev_get(ggml_backend_cpu_reg(), 0),
|
ggml_backend_reg_dev_get(ggml_backend_cpu_reg(), 0),
|
||||||
|
|||||||
@@ -920,12 +920,14 @@ static size_t ggml_backend_cuda_buffer_type_get_alloc_size(ggml_backend_buffer_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const ggml_backend_buffer_type_i ggml_backend_cuda_buffer_type_interface = {
|
static const ggml_backend_buffer_type_i ggml_backend_cuda_buffer_type_interface = {
|
||||||
/* .get_name = */ ggml_backend_cuda_buffer_type_get_name,
|
/* .get_name = */ ggml_backend_cuda_buffer_type_get_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_cuda_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_cuda_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_cuda_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ NULL, // defaults to SIZE_MAX
|
/* .get_alignment = */ ggml_backend_cuda_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_cuda_buffer_type_get_alloc_size,
|
/* .get_max_size = */ NULL, // defaults to SIZE_MAX
|
||||||
/* .is_host = */ NULL,
|
/* .get_alloc_size = */ ggml_backend_cuda_buffer_type_get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
ggml_backend_buffer_type_t ggml_backend_cuda_buffer_type(int device) {
|
ggml_backend_buffer_type_t ggml_backend_cuda_buffer_type(int device) {
|
||||||
@@ -1304,12 +1306,14 @@ static ggml_backend_buffer_t ggml_backend_cuda_host_buffer_type_alloc_buffer(ggm
|
|||||||
ggml_backend_buffer_type_t ggml_backend_cuda_host_buffer_type() {
|
ggml_backend_buffer_type_t ggml_backend_cuda_host_buffer_type() {
|
||||||
static struct ggml_backend_buffer_type ggml_backend_cuda_buffer_type_host = {
|
static struct ggml_backend_buffer_type ggml_backend_cuda_buffer_type_host = {
|
||||||
/* .iface = */ {
|
/* .iface = */ {
|
||||||
/* .get_name = */ ggml_backend_cuda_host_buffer_type_name,
|
/* .get_name = */ ggml_backend_cuda_host_buffer_type_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_cuda_host_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_cuda_host_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_cpu_buffer_type()->iface.get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ NULL, // defaults to SIZE_MAX
|
/* .get_alignment = */ ggml_backend_cpu_buffer_type()->iface.get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_cpu_buffer_type()->iface.get_alloc_size,
|
/* .get_max_size = */ NULL, // defaults to SIZE_MAX
|
||||||
/* .is_host = */ ggml_backend_cpu_buffer_type()->iface.is_host,
|
/* .get_alloc_size = */ ggml_backend_cpu_buffer_type()->iface.get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ ggml_backend_cpu_buffer_type()->iface.is_host,
|
||||||
},
|
},
|
||||||
/* .device = */ ggml_backend_reg_dev_get(ggml_backend_cuda_reg(), 0),
|
/* .device = */ ggml_backend_reg_dev_get(ggml_backend_cuda_reg(), 0),
|
||||||
/* .context = */ nullptr,
|
/* .context = */ nullptr,
|
||||||
|
|||||||
@@ -439,12 +439,14 @@ static bool ggml_backend_et_buffer_type_is_host(ggml_backend_buffer_type_t buft)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const struct ggml_backend_buffer_type_i ggml_backend_et_buffer_type_i = {
|
static const struct ggml_backend_buffer_type_i ggml_backend_et_buffer_type_i = {
|
||||||
/* .get_name = */ ggml_backend_et_buffer_type_get_name,
|
/* .get_name = */ ggml_backend_et_buffer_type_get_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_et_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_et_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_et_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ ggml_backend_et_buffer_type_get_max_size,
|
/* .get_alignment = */ ggml_backend_et_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_et_buffer_type_get_alloc_size,
|
/* .get_max_size = */ ggml_backend_et_buffer_type_get_max_size,
|
||||||
/* .is_host = */ ggml_backend_et_buffer_type_is_host,
|
/* .get_alloc_size = */ ggml_backend_et_buffer_type_get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ ggml_backend_et_buffer_type_is_host,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char * ggml_backend_et_get_name(ggml_backend_t backend) {
|
static const char * ggml_backend_et_get_name(ggml_backend_t backend) {
|
||||||
|
|||||||
@@ -2795,21 +2795,25 @@ static bool ggml_backend_hexagon_host_buffer_type_is_host(ggml_backend_buffer_ty
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ggml_backend_buffer_type_i ggml_backend_hexagon_buffer_type_interface = {
|
static ggml_backend_buffer_type_i ggml_backend_hexagon_buffer_type_interface = {
|
||||||
/* .get_name = */ ggml_backend_hexagon_buffer_type_name,
|
/* .get_name = */ ggml_backend_hexagon_buffer_type_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_hexagon_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_hexagon_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_hexagon_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ ggml_backend_hexagon_buffer_type_get_max_size,
|
/* .get_alignment = */ ggml_backend_hexagon_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_hexagon_buffer_type_get_alloc_size,
|
/* .get_max_size = */ ggml_backend_hexagon_buffer_type_get_max_size,
|
||||||
/* .is_host = */ ggml_backend_hexagon_buffer_type_is_host,
|
/* .get_alloc_size = */ ggml_backend_hexagon_buffer_type_get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ ggml_backend_hexagon_buffer_type_is_host,
|
||||||
};
|
};
|
||||||
|
|
||||||
static ggml_backend_buffer_type_i ggml_backend_hexagon_host_buffer_type_interface = {
|
static ggml_backend_buffer_type_i ggml_backend_hexagon_host_buffer_type_interface = {
|
||||||
/* .get_name = */ ggml_backend_hexagon_buffer_type_name,
|
/* .get_name = */ ggml_backend_hexagon_buffer_type_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_hexagon_host_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_hexagon_host_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_hexagon_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ ggml_backend_hexagon_buffer_type_get_max_size,
|
/* .get_alignment = */ ggml_backend_hexagon_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_hexagon_buffer_type_get_alloc_size,
|
/* .get_max_size = */ ggml_backend_hexagon_buffer_type_get_max_size,
|
||||||
/* .is_host = */ ggml_backend_hexagon_host_buffer_type_is_host,
|
/* .get_alloc_size = */ ggml_backend_hexagon_buffer_type_get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ ggml_backend_hexagon_host_buffer_type_is_host,
|
||||||
};
|
};
|
||||||
|
|
||||||
ggml_backend_hexagon_device_context::ggml_backend_hexagon_device_context(int dev_id, const ggml_hexagon_device_config & config, ggml_backend_dev_t dev)
|
ggml_backend_hexagon_device_context::ggml_backend_hexagon_device_context(int dev_id, const ggml_hexagon_device_config & config, ggml_backend_dev_t dev)
|
||||||
|
|||||||
@@ -310,12 +310,14 @@ static ggml_backend_buffer_type_t ggml_backend_metal_buffer_type_shared(int devi
|
|||||||
|
|
||||||
ggml_backend_buffer_type buft = {
|
ggml_backend_buffer_type buft = {
|
||||||
/* .iface = */ {
|
/* .iface = */ {
|
||||||
/* .get_name = */ ggml_backend_metal_buffer_type_shared_get_name,
|
/* .get_name = */ ggml_backend_metal_buffer_type_shared_get_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_metal_buffer_type_shared_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_metal_buffer_type_shared_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_metal_buffer_type_shared_get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ ggml_backend_metal_buffer_type_shared_get_max_size,
|
/* .get_alignment = */ ggml_backend_metal_buffer_type_shared_get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_metal_buffer_type_shared_get_alloc_size,
|
/* .get_max_size = */ ggml_backend_metal_buffer_type_shared_get_max_size,
|
||||||
/* .is_host = */ ggml_backend_metal_buffer_type_shared_is_host,
|
/* .get_alloc_size = */ ggml_backend_metal_buffer_type_shared_get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ ggml_backend_metal_buffer_type_shared_is_host,
|
||||||
},
|
},
|
||||||
/* .device = */ ggml_backend_reg_dev_get(ggml_backend_metal_reg(), i),
|
/* .device = */ ggml_backend_reg_dev_get(ggml_backend_metal_reg(), i),
|
||||||
/* .context = */ raw_ctx,
|
/* .context = */ raw_ctx,
|
||||||
@@ -385,12 +387,14 @@ static ggml_backend_buffer_type_t ggml_backend_metal_buffer_type_private(int dev
|
|||||||
|
|
||||||
ggml_backend_buffer_type buft = {
|
ggml_backend_buffer_type buft = {
|
||||||
/* .iface = */ {
|
/* .iface = */ {
|
||||||
/* .get_name = */ ggml_backend_metal_buffer_type_private_get_name,
|
/* .get_name = */ ggml_backend_metal_buffer_type_private_get_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_metal_buffer_type_private_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_metal_buffer_type_private_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_metal_buffer_type_private_get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ ggml_backend_metal_buffer_type_private_get_max_size,
|
/* .get_alignment = */ ggml_backend_metal_buffer_type_private_get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_metal_buffer_type_private_get_alloc_size,
|
/* .get_max_size = */ ggml_backend_metal_buffer_type_private_get_max_size,
|
||||||
/* .is_host = */ ggml_backend_metal_buffer_type_private_is_host,
|
/* .get_alloc_size = */ ggml_backend_metal_buffer_type_private_get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ ggml_backend_metal_buffer_type_private_is_host,
|
||||||
},
|
},
|
||||||
/* .device = */ ggml_backend_reg_dev_get(ggml_backend_metal_reg(), i),
|
/* .device = */ ggml_backend_reg_dev_get(ggml_backend_metal_reg(), i),
|
||||||
/* .context = */ raw_ctx,
|
/* .context = */ raw_ctx,
|
||||||
@@ -463,12 +467,14 @@ static ggml_backend_buffer_type_t ggml_backend_metal_buffer_type_mapped(int devi
|
|||||||
// https://github.com/ggml-org/llama.cpp/pull/15832#discussion_r2333177099
|
// https://github.com/ggml-org/llama.cpp/pull/15832#discussion_r2333177099
|
||||||
ggml_backend_buffer_type buft = {
|
ggml_backend_buffer_type buft = {
|
||||||
/* .iface = */ {
|
/* .iface = */ {
|
||||||
/* .get_name = */ ggml_backend_metal_buffer_type_mapped_get_name,
|
/* .get_name = */ ggml_backend_metal_buffer_type_mapped_get_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_metal_buffer_type_mapped_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_metal_buffer_type_mapped_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_metal_buffer_type_mapped_get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ ggml_backend_metal_buffer_type_mapped_get_max_size,
|
/* .get_alignment = */ ggml_backend_metal_buffer_type_mapped_get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_metal_buffer_type_mapped_get_alloc_size,
|
/* .get_max_size = */ ggml_backend_metal_buffer_type_mapped_get_max_size,
|
||||||
/* .is_host = */ ggml_backend_metal_buffer_type_mapped_is_host,
|
/* .get_alloc_size = */ ggml_backend_metal_buffer_type_mapped_get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ ggml_backend_metal_buffer_type_mapped_is_host,
|
||||||
},
|
},
|
||||||
/* .device = */ ggml_backend_reg_dev_get(ggml_backend_metal_reg(), i),
|
/* .device = */ ggml_backend_reg_dev_get(ggml_backend_metal_reg(), i),
|
||||||
/* .context = */ raw_ctx,
|
/* .context = */ raw_ctx,
|
||||||
|
|||||||
@@ -12886,12 +12886,14 @@ static size_t ggml_backend_opencl_buffer_type_get_alloc_size(ggml_backend_buffer
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ggml_backend_buffer_type_i ggml_backend_opencl_buffer_type_interface = {
|
static ggml_backend_buffer_type_i ggml_backend_opencl_buffer_type_interface = {
|
||||||
/* .get_name = */ ggml_backend_opencl_buffer_type_get_name,
|
/* .get_name = */ ggml_backend_opencl_buffer_type_get_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_opencl_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_opencl_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_opencl_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ ggml_backend_opencl_buffer_type_get_max_size,
|
/* .get_alignment = */ ggml_backend_opencl_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_opencl_buffer_type_get_alloc_size,
|
/* .get_max_size = */ ggml_backend_opencl_buffer_type_get_max_size,
|
||||||
/* .is_host = */ NULL,
|
/* .get_alloc_size = */ ggml_backend_opencl_buffer_type_get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -631,12 +631,14 @@ static size_t ggml_backend_openvino_buffer_type_get_alloc_size(ggml_backend_buff
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const ggml_backend_buffer_type_i ggml_backend_openvino_buffer_type_interface = {
|
static const ggml_backend_buffer_type_i ggml_backend_openvino_buffer_type_interface = {
|
||||||
/* .get_name = */ ggml_backend_openvino_buffer_type_get_name,
|
/* .get_name = */ ggml_backend_openvino_buffer_type_get_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_openvino_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_openvino_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_openvino_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ ggml_backend_openvino_buffer_type_get_max_size,
|
/* .get_alignment = */ ggml_backend_openvino_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_openvino_buffer_type_get_alloc_size,
|
/* .get_max_size = */ ggml_backend_openvino_buffer_type_get_max_size,
|
||||||
/* .is_host = */ nullptr,
|
/* .get_alloc_size = */ ggml_backend_openvino_buffer_type_get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ nullptr,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get buffer type for a specific device
|
// Get buffer type for a specific device
|
||||||
@@ -684,12 +686,14 @@ static bool ggml_backend_openvino_host_buffer_type_is_host(ggml_backend_buffer_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const ggml_backend_buffer_type_i ggml_backend_openvino_host_buffer_type_interface = {
|
static const ggml_backend_buffer_type_i ggml_backend_openvino_host_buffer_type_interface = {
|
||||||
/* .get_name = */ ggml_backend_openvino_host_buffer_type_get_name,
|
/* .get_name = */ ggml_backend_openvino_host_buffer_type_get_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_openvino_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_openvino_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_openvino_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ ggml_backend_openvino_buffer_type_get_max_size,
|
/* .get_alignment = */ ggml_backend_openvino_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_openvino_buffer_type_get_alloc_size,
|
/* .get_max_size = */ ggml_backend_openvino_buffer_type_get_max_size,
|
||||||
/* .is_host = */ ggml_backend_openvino_host_buffer_type_is_host,
|
/* .get_alloc_size = */ ggml_backend_openvino_buffer_type_get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ ggml_backend_openvino_host_buffer_type_is_host,
|
||||||
};
|
};
|
||||||
|
|
||||||
GGML_BACKEND_API ggml_backend_buffer_type_t ggml_backend_openvino_host_buffer_type(int device) {
|
GGML_BACKEND_API ggml_backend_buffer_type_t ggml_backend_openvino_host_buffer_type(int device) {
|
||||||
|
|||||||
@@ -929,12 +929,14 @@ static size_t ggml_backend_rpc_buffer_type_get_alloc_size(ggml_backend_buffer_ty
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ggml_backend_buffer_type_i ggml_backend_rpc_buffer_type_interface = {
|
static ggml_backend_buffer_type_i ggml_backend_rpc_buffer_type_interface = {
|
||||||
/* .get_name = */ ggml_backend_rpc_buffer_type_name,
|
/* .get_name = */ ggml_backend_rpc_buffer_type_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_rpc_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_rpc_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_rpc_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ ggml_backend_rpc_get_max_size,
|
/* .get_alignment = */ ggml_backend_rpc_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_rpc_buffer_type_get_alloc_size,
|
/* .get_max_size = */ ggml_backend_rpc_get_max_size,
|
||||||
/* .is_host = */ NULL,
|
/* .get_alloc_size = */ ggml_backend_rpc_buffer_type_get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char * ggml_backend_rpc_name(ggml_backend_t backend) {
|
static const char * ggml_backend_rpc_name(ggml_backend_t backend) {
|
||||||
|
|||||||
@@ -1065,12 +1065,14 @@ static size_t ggml_backend_sycl_buffer_type_get_alloc_size(ggml_backend_buffer_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const ggml_backend_buffer_type_i ggml_backend_sycl_buffer_type_interface = {
|
static const ggml_backend_buffer_type_i ggml_backend_sycl_buffer_type_interface = {
|
||||||
/* .get_name = */ ggml_backend_sycl_buffer_type_get_name,
|
/* .get_name = */ ggml_backend_sycl_buffer_type_get_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_sycl_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_sycl_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_sycl_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ ggml_backend_sycl_buffer_type_get_max_size,
|
/* .get_alignment = */ ggml_backend_sycl_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_sycl_buffer_type_get_alloc_size,
|
/* .get_max_size = */ ggml_backend_sycl_buffer_type_get_max_size,
|
||||||
/* .is_host = */ NULL,
|
/* .get_alloc_size = */ ggml_backend_sycl_buffer_type_get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
ggml_backend_buffer_type_t ggml_backend_sycl_buffer_type(int device) {
|
ggml_backend_buffer_type_t ggml_backend_sycl_buffer_type(int device) {
|
||||||
@@ -1501,12 +1503,14 @@ static bool ggml_backend_sycl_split_buffer_type_is_host(ggml_backend_buffer_type
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ggml_backend_buffer_type_i ggml_backend_sycl_split_buffer_type_interface = {
|
static ggml_backend_buffer_type_i ggml_backend_sycl_split_buffer_type_interface = {
|
||||||
/* .get_name = */ ggml_backend_sycl_split_buffer_type_get_name,
|
/* .get_name = */ ggml_backend_sycl_split_buffer_type_get_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_sycl_split_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_sycl_split_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_sycl_split_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ NULL, // defaults to SIZE_MAX
|
/* .get_alignment = */ ggml_backend_sycl_split_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_sycl_split_buffer_type_get_alloc_size,
|
/* .get_max_size = */ NULL, // defaults to SIZE_MAX
|
||||||
/* .is_host = */ ggml_backend_sycl_split_buffer_type_is_host,
|
/* .get_alloc_size = */ ggml_backend_sycl_split_buffer_type_get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ ggml_backend_sycl_split_buffer_type_is_host,
|
||||||
};
|
};
|
||||||
|
|
||||||
ggml_backend_buffer_type_t ggml_backend_sycl_split_buffer_type(int main_device, const float * tensor_split) {
|
ggml_backend_buffer_type_t ggml_backend_sycl_split_buffer_type(int main_device, const float * tensor_split) {
|
||||||
@@ -1645,12 +1649,14 @@ static ggml_backend_buffer_type_t ggml_backend_sycl_host_buffer_type_for_device(
|
|||||||
for (size_t i = 0; i < bufts.size(); i++) {
|
for (size_t i = 0; i < bufts.size(); i++) {
|
||||||
bufts[i] = {
|
bufts[i] = {
|
||||||
/* .iface = */ {
|
/* .iface = */ {
|
||||||
/* .get_name = */ ggml_backend_sycl_host_buffer_type_name,
|
/* .get_name = */ ggml_backend_sycl_host_buffer_type_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_sycl_host_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_sycl_host_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_cpu_buffer_type()->iface.get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ ggml_backend_sycl_host_buffer_type_get_max_size,
|
/* .get_alignment = */ ggml_backend_cpu_buffer_type()->iface.get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_cpu_buffer_type()->iface.get_alloc_size,
|
/* .get_max_size = */ ggml_backend_sycl_host_buffer_type_get_max_size,
|
||||||
/* .is_host = */ ggml_backend_cpu_buffer_type()->iface.is_host,
|
/* .get_alloc_size = */ ggml_backend_cpu_buffer_type()->iface.get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ ggml_backend_cpu_buffer_type()->iface.is_host,
|
||||||
},
|
},
|
||||||
/* .device = */ ggml_backend_reg_dev_get(ggml_backend_sycl_reg(), i),
|
/* .device = */ ggml_backend_reg_dev_get(ggml_backend_sycl_reg(), i),
|
||||||
/* .context = */ nullptr,
|
/* .context = */ nullptr,
|
||||||
|
|||||||
@@ -63,19 +63,23 @@ static size_t ggml_backend_remoting_buffer_type_get_alloc_size(ggml_backend_buff
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ggml_backend_buffer_type_i ggml_backend_remoting_buffer_type_interface = {
|
const ggml_backend_buffer_type_i ggml_backend_remoting_buffer_type_interface = {
|
||||||
/* .get_name = */ ggml_backend_remoting_buffer_type_get_name,
|
/* .get_name = */ ggml_backend_remoting_buffer_type_get_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_remoting_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_remoting_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_remoting_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ ggml_backend_remoting_buffer_type_get_max_size,
|
/* .get_alignment = */ ggml_backend_remoting_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_remoting_buffer_type_get_alloc_size,
|
/* .get_max_size = */ ggml_backend_remoting_buffer_type_get_max_size,
|
||||||
/* .is_host = */ NULL,
|
/* .get_alloc_size = */ ggml_backend_remoting_buffer_type_get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
const ggml_backend_buffer_type_i ggml_backend_remoting_buffer_from_ptr_type_interface = {
|
const ggml_backend_buffer_type_i ggml_backend_remoting_buffer_from_ptr_type_interface = {
|
||||||
/* .get_name = */ ggml_backend_remoting_buffer_type_get_name,
|
/* .get_name = */ ggml_backend_remoting_buffer_type_get_name,
|
||||||
/* .alloc_buffer = */ NULL,
|
/* .alloc_buffer = */ NULL,
|
||||||
/* .get_alignment = */ ggml_backend_remoting_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ ggml_backend_remoting_buffer_type_get_max_size,
|
/* .get_alignment = */ ggml_backend_remoting_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_remoting_buffer_type_get_alloc_size,
|
/* .get_max_size = */ ggml_backend_remoting_buffer_type_get_max_size,
|
||||||
/* .is_host = */ NULL,
|
/* .get_alloc_size = */ ggml_backend_remoting_buffer_type_get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ NULL,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
#include "ggml-vulkan-common.h"
|
#include "ggml-vulkan-common.h"
|
||||||
|
|
||||||
ggml_backend_buffer_type_i ggml_backend_vk_buffer_type_interface = {
|
ggml_backend_buffer_type_i ggml_backend_vk_buffer_type_interface = {
|
||||||
/* .get_name = */ ggml_backend_vk_buffer_type_name,
|
/* .get_name = */ ggml_backend_vk_buffer_type_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_vk_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_vk_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_vk_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ ggml_backend_vk_buffer_type_get_max_size,
|
/* .get_alignment = */ ggml_backend_vk_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_vk_buffer_type_get_alloc_size,
|
/* .get_max_size = */ ggml_backend_vk_buffer_type_get_max_size,
|
||||||
/* .is_host = */ NULL,
|
/* .get_alloc_size = */ ggml_backend_vk_buffer_type_get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::vector<uint32_t> ggml_vk_find_memory_properties(const vk::PhysicalDeviceMemoryProperties* mem_props, vk::MemoryRequirements* mem_req, vk::MemoryPropertyFlags flags) {
|
static std::vector<uint32_t> ggml_vk_find_memory_properties(const vk::PhysicalDeviceMemoryProperties* mem_props, vk::MemoryRequirements* mem_req, vk::MemoryPropertyFlags flags) {
|
||||||
|
|||||||
@@ -13114,12 +13114,14 @@ static size_t ggml_backend_vk_host_buffer_type_get_max_size(ggml_backend_buffer_
|
|||||||
ggml_backend_buffer_type_t ggml_backend_vk_host_buffer_type() {
|
ggml_backend_buffer_type_t ggml_backend_vk_host_buffer_type() {
|
||||||
static struct ggml_backend_buffer_type ggml_backend_vk_buffer_type_host = {
|
static struct ggml_backend_buffer_type ggml_backend_vk_buffer_type_host = {
|
||||||
/* .iface = */ {
|
/* .iface = */ {
|
||||||
/* .get_name = */ ggml_backend_vk_host_buffer_type_name,
|
/* .get_name = */ ggml_backend_vk_host_buffer_type_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_vk_host_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_vk_host_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_vk_host_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ nullptr,
|
||||||
/* .get_max_size = */ ggml_backend_vk_host_buffer_type_get_max_size,
|
/* .get_alignment = */ ggml_backend_vk_host_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_cpu_buffer_type()->iface.get_alloc_size,
|
/* .get_max_size = */ ggml_backend_vk_host_buffer_type_get_max_size,
|
||||||
/* .is_host = */ ggml_backend_cpu_buffer_type()->iface.is_host,
|
/* .get_alloc_size = */ ggml_backend_cpu_buffer_type()->iface.get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ ggml_backend_cpu_buffer_type()->iface.is_host,
|
||||||
},
|
},
|
||||||
/* .device = */ ggml_backend_reg_dev_get(ggml_backend_vk_reg(), 0),
|
/* .device = */ ggml_backend_reg_dev_get(ggml_backend_vk_reg(), 0),
|
||||||
/* .context = */ nullptr,
|
/* .context = */ nullptr,
|
||||||
|
|||||||
@@ -4325,12 +4325,14 @@ static ggml_backend_buffer_type_t ggml_backend_webgpu_device_get_buffer_type(ggm
|
|||||||
|
|
||||||
static struct ggml_backend_buffer_type ggml_backend_webgpu_buffer_type = {
|
static struct ggml_backend_buffer_type ggml_backend_webgpu_buffer_type = {
|
||||||
/* .iface = */ {
|
/* .iface = */ {
|
||||||
/* .get_name = */ ggml_backend_webgpu_buffer_type_get_name,
|
/* .get_name = */ ggml_backend_webgpu_buffer_type_get_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_webgpu_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_webgpu_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_webgpu_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ ggml_backend_webgpu_buffer_type_get_max_size,
|
/* .get_alignment = */ ggml_backend_webgpu_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ ggml_backend_webgpu_buffer_type_get_alloc_size,
|
/* .get_max_size = */ ggml_backend_webgpu_buffer_type_get_max_size,
|
||||||
/* .is_host = */ NULL, // defaults to false
|
/* .get_alloc_size = */ ggml_backend_webgpu_buffer_type_get_alloc_size,
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ NULL, // defaults to false
|
||||||
},
|
},
|
||||||
/* .device = */
|
/* .device = */
|
||||||
dev,
|
dev,
|
||||||
|
|||||||
@@ -414,12 +414,14 @@ static bool ggml_backend_zdnn_buffer_type_is_host(ggml_backend_buffer_type_t buf
|
|||||||
ggml_backend_buffer_type_t ggml_backend_zdnn_buffer_type(void) {
|
ggml_backend_buffer_type_t ggml_backend_zdnn_buffer_type(void) {
|
||||||
static ggml_backend_buffer_type ggml_backend_buffer_type_zdnn = {
|
static ggml_backend_buffer_type ggml_backend_buffer_type_zdnn = {
|
||||||
/* .iface = */ {
|
/* .iface = */ {
|
||||||
/* .get_name = */ ggml_backend_zdnn_buffer_type_get_name,
|
/* .get_name = */ ggml_backend_zdnn_buffer_type_get_name,
|
||||||
/* .alloc_buffer = */ ggml_backend_zdnn_buffer_type_alloc_buffer,
|
/* .alloc_buffer = */ ggml_backend_zdnn_buffer_type_alloc_buffer,
|
||||||
/* .get_alignment = */ ggml_backend_zdnn_buffer_type_get_alignment,
|
/* .alloc_buffer_n = */ NULL,
|
||||||
/* .get_max_size = */ NULL,
|
/* .get_alignment = */ ggml_backend_zdnn_buffer_type_get_alignment,
|
||||||
/* .get_alloc_size = */ NULL, // defaults to ggml_nbytes
|
/* .get_max_size = */ NULL,
|
||||||
/* .is_host = */ ggml_backend_zdnn_buffer_type_is_host,
|
/* .get_alloc_size = */ NULL, // defaults to ggml_nbytes
|
||||||
|
/* .get_alloc_size_n = */ NULL,
|
||||||
|
/* .is_host = */ ggml_backend_zdnn_buffer_type_is_host,
|
||||||
},
|
},
|
||||||
/* .device = */ &g_ggml_backend_zdnn_device,
|
/* .device = */ &g_ggml_backend_zdnn_device,
|
||||||
/* .context = */ NULL,
|
/* .context = */ NULL,
|
||||||
|
|||||||
Reference in New Issue
Block a user