Skip to content

Commit 2194200

Browse files
authored
fix: allocating CPU buffer with size 0 (#9917)
1 parent 73afe68 commit 2194200

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

ggml/src/ggml-backend.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,14 +768,19 @@ static const char * ggml_backend_cpu_buffer_type_get_name(ggml_backend_buffer_ty
768768
}
769769

770770
static ggml_backend_buffer_t ggml_backend_cpu_buffer_type_alloc_buffer(ggml_backend_buffer_type_t buft, size_t size) {
771-
void * data = ggml_aligned_malloc(size);
771+
auto alloc_size = size;
772+
if (alloc_size == 0) {
773+
alloc_size = 1;
774+
}
775+
776+
void * data = ggml_aligned_malloc(alloc_size);
772777

773778
if (data == NULL) {
774-
GGML_LOG_ERROR("%s: failed to allocate buffer of size %zu\n", __func__, size);
779+
GGML_LOG_ERROR("%s: failed to allocate buffer of size %zu\n", __func__, alloc_size);
775780
return NULL;
776781
}
777782

778-
return ggml_backend_buffer_init(buft, ggml_backend_cpu_buffer_i, data, size);
783+
return ggml_backend_buffer_init(buft, ggml_backend_cpu_buffer_i, data, alloc_size);
779784
}
780785

781786
static size_t ggml_backend_cpu_buffer_type_get_alignment(ggml_backend_buffer_type_t buft) {

0 commit comments

Comments
 (0)