Skip to content

Commit

Permalink
Early return for zero size calls to get_tensor. (llama/5482)
Browse files Browse the repository at this point in the history
* Early return for zero size calls to get_tensor.

Signed-off-by: Adam Treat <[email protected]>

* Update ggml-kompute.cpp

Co-authored-by: Georgi Gerganov <[email protected]>

* Update ggml-kompute.cpp

Co-authored-by: Georgi Gerganov <[email protected]>

* Add an early return to the get/set tensor when the size is null.

Signed-off-by: Adam Treat <[email protected]>

* Early return after the assertions.

Signed-off-by: Adam Treat <[email protected]>

* Since we do the early return in the generic backend now no reason to do so here as well.

Signed-off-by: Adam Treat <[email protected]>

---------

Signed-off-by: Adam Treat <[email protected]>
Co-authored-by: Georgi Gerganov <[email protected]>
  • Loading branch information
manyoso and ggerganov committed Feb 19, 2024
1 parent c58fecf commit f91c377
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/ggml-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ GGML_CALL void ggml_backend_tensor_set(struct ggml_tensor * tensor, const void *
GGML_ASSERT(buf != NULL && "tensor buffer not set");
GGML_ASSERT(offset + size <= ggml_nbytes(tensor) && "tensor write out of bounds");

if (!size) {
return;
}

tensor->buffer->iface.set_tensor(buf, tensor, data, offset, size);
}

Expand All @@ -229,6 +233,10 @@ GGML_CALL void ggml_backend_tensor_get(const struct ggml_tensor * tensor, void *
GGML_ASSERT(tensor->buffer != NULL && "tensor buffer not set");
GGML_ASSERT(offset + size <= ggml_nbytes(tensor) && "tensor read out of bounds");

if (!size) {
return;
}

tensor->buffer->iface.get_tensor(buf, tensor, data, offset, size);
}

Expand Down

0 comments on commit f91c377

Please sign in to comment.