| 967 | } |
| 968 | |
| 969 | static void ggml_gallocr_init_tensor(ggml_gallocr_t galloc, struct ggml_tensor * tensor, struct tensor_alloc * tensor_alloc) { |
| 970 | int buffer_id = tensor_alloc->buffer_id; |
| 971 | assert(tensor->data || tensor->view_src || ggml_backend_buft_get_alloc_size(galloc->bufts[buffer_id], tensor) <= tensor_alloc->size_max); |
| 972 | |
| 973 | if (tensor->view_src != NULL) { |
| 974 | if (tensor->buffer == NULL) { |
| 975 | assert(tensor_alloc->addr.offset == SIZE_MAX); |
| 976 | if (tensor->view_src->buffer == NULL) { |
| 977 | // this tensor was allocated without ggml-backend |
| 978 | return; |
| 979 | } |
| 980 | ggml_backend_view_init(tensor); |
| 981 | } |
| 982 | } else { |
| 983 | if (tensor->data == NULL) { |
| 984 | assert(tensor_alloc->addr.offset != SIZE_MAX); |
| 985 | assert(ggml_backend_buft_get_alloc_size(galloc->bufts[buffer_id], tensor) <= tensor_alloc->size_max); |
| 986 | ggml_vbuffer_tensor_alloc(galloc->buffers[buffer_id], tensor, tensor_alloc->addr); |
| 987 | } else { |
| 988 | if (tensor->buffer == NULL) { |
| 989 | // this tensor was allocated without ggml-backend |
| 990 | return; |
| 991 | } |
| 992 | } |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | static bool ggml_gallocr_node_needs_realloc(ggml_gallocr_t galloc, struct ggml_tensor * node, struct tensor_alloc * talloc) { |
| 997 | size_t node_size = 0; |
no test coverage detected