add debug asserts in ggml_allocr_alloc to some common pitfalls when using this function directly

This commit is contained in:
xaedes 2023-08-14 20:50:09 +02:00
parent 6e280b24dc
commit faf3e21eaf
No known key found for this signature in database
GPG key ID: 30030EDD817EA2B1

View file

@ -104,6 +104,10 @@ static size_t ggml_allocator_get_alloc_size(struct ggml_allocr * alloc, struct g
} }
void ggml_allocr_alloc(struct ggml_allocr * alloc, struct ggml_tensor * tensor) { void ggml_allocr_alloc(struct ggml_allocr * alloc, struct ggml_tensor * tensor) {
#ifdef GGML_ALLOCATOR_DEBUG
GGML_ASSERT(ggml_is_view(tensor) == false); // views generally get data pointer from one of their sources
GGML_ASSERT(tensor->data == NULL); // avoid allocating tensor which already has memory allocated
#endif
size_t size = ggml_allocator_get_alloc_size(alloc, tensor); size_t size = ggml_allocator_get_alloc_size(alloc, tensor);
size = aligned_offset(NULL, size, alloc->alignment); size = aligned_offset(NULL, size, alloc->alignment);