Skip to content

Commit

Permalink
fix: allocating CPU buffer with size 0 (#9917)
Browse files Browse the repository at this point in the history
  • Loading branch information
giladgd authored Oct 16, 2024
1 parent 73afe68 commit 2194200
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ggml/src/ggml-backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,14 +768,19 @@ static const char * ggml_backend_cpu_buffer_type_get_name(ggml_backend_buffer_ty
}

static ggml_backend_buffer_t ggml_backend_cpu_buffer_type_alloc_buffer(ggml_backend_buffer_type_t buft, size_t size) {
void * data = ggml_aligned_malloc(size);
auto alloc_size = size;
if (alloc_size == 0) {
alloc_size = 1;
}

void * data = ggml_aligned_malloc(alloc_size);

if (data == NULL) {
GGML_LOG_ERROR("%s: failed to allocate buffer of size %zu\n", __func__, size);
GGML_LOG_ERROR("%s: failed to allocate buffer of size %zu\n", __func__, alloc_size);
return NULL;
}

return ggml_backend_buffer_init(buft, ggml_backend_cpu_buffer_i, data, size);
return ggml_backend_buffer_init(buft, ggml_backend_cpu_buffer_i, data, alloc_size);
}

static size_t ggml_backend_cpu_buffer_type_get_alignment(ggml_backend_buffer_type_t buft) {
Expand Down

0 comments on commit 2194200

Please sign in to comment.