Skip to content

Commit f5ca054

Browse files
manyosoggerganov
andauthored
Early return for zero size calls to get_tensor. (#5482)
* 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]>
1 parent 6c00a06 commit f5ca054

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

ggml-backend.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ GGML_CALL void ggml_backend_tensor_set(struct ggml_tensor * tensor, const void *
219219
GGML_ASSERT(buf != NULL && "tensor buffer not set");
220220
GGML_ASSERT(offset + size <= ggml_nbytes(tensor) && "tensor write out of bounds");
221221

222+
if (!size) {
223+
return;
224+
}
225+
222226
tensor->buffer->iface.set_tensor(buf, tensor, data, offset, size);
223227
}
224228

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

236+
if (!size) {
237+
return;
238+
}
239+
232240
tensor->buffer->iface.get_tensor(buf, tensor, data, offset, size);
233241
}
234242

0 commit comments

Comments
 (0)