MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / ggml_gallocr_reserve_n_impl

Function ggml_gallocr_reserve_n_impl

external/ggml/src/ggml-alloc.c:824–948  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

822}
823
824static bool ggml_gallocr_reserve_n_impl(
825 ggml_gallocr_t galloc, struct ggml_cgraph * graph, const int * node_buffer_ids, const int * leaf_buffer_ids, bool no_alloc) {
826 size_t min_hash_size = graph->n_nodes + graph->n_leafs;
827 // add 25% margin to avoid hash collisions
828 min_hash_size += min_hash_size / 4;
829
830 // initialize hash table
831 if (galloc->hash_set.size < min_hash_size) {
832 ggml_hash_set_free(&galloc->hash_set);
833 galloc->hash_set = ggml_hash_set_new(min_hash_size);
834 GGML_ASSERT(galloc->hash_set.keys != NULL);
835
836 free(galloc->hash_values);
837 galloc->hash_values = malloc(sizeof(struct hash_node) * galloc->hash_set.size);
838 GGML_ASSERT(galloc->hash_values != NULL);
839 }
840
841 // reset allocators
842 for (int i = 0; i < galloc->n_buffers; i++) {
843 ggml_dyn_tallocr_reset(galloc->buf_tallocs[i]);
844 }
845
846 // allocate in hash table
847 ggml_gallocr_alloc_graph_impl(galloc, graph, node_buffer_ids, leaf_buffer_ids);
848
849 // set the node_allocs from the hash table
850 if (galloc->n_nodes < graph->n_nodes) {
851 free(galloc->node_allocs);
852 galloc->node_allocs = calloc(graph->n_nodes, sizeof(struct node_alloc));
853 GGML_ASSERT(galloc->node_allocs != NULL);
854 }
855 galloc->n_nodes = graph->n_nodes;
856 for (int i = 0; i < graph->n_nodes; i++) {
857 struct ggml_tensor * node = graph->nodes[i];
858 struct node_alloc * node_alloc = &galloc->node_allocs[i];
859 if (node->view_src || node->data) {
860 node_alloc->dst.buffer_id = -1;
861 node_alloc->dst.addr = GGML_BUFFER_ADDRESS_INVALID;
862 node_alloc->dst.size_max = 0;
863 } else {
864 struct hash_node * hn = ggml_gallocr_hash_get(galloc, node);
865 node_alloc->dst.buffer_id = hn->buffer_id;
866 node_alloc->dst.addr = hn->addr;
867 node_alloc->dst.size_max = ggml_backend_buft_get_alloc_size(galloc->bufts[hn->buffer_id], node);
868 }
869 for (int j = 0; j < GGML_MAX_SRC; j++) {
870 struct ggml_tensor * src = node->src[j];
871 if (!src || src->view_src || src->data) {
872 node_alloc->src[j].buffer_id = -1;
873 node_alloc->src[j].addr = GGML_BUFFER_ADDRESS_INVALID;
874 node_alloc->src[j].size_max = 0;
875 } else {
876 struct hash_node * hn = ggml_gallocr_hash_get(galloc, src);
877 node_alloc->src[j].buffer_id = hn->buffer_id;
878 node_alloc->src[j].addr = hn->addr;
879 node_alloc->src[j].size_max = ggml_backend_buft_get_alloc_size(galloc->bufts[hn->buffer_id], src);
880 }
881 }

Callers 2

ggml_gallocr_reserve_nFunction · 0.85

Calls 12

ggml_hash_set_freeFunction · 0.85
ggml_hash_set_newFunction · 0.85
ggml_dyn_tallocr_resetFunction · 0.85
ggml_gallocr_hash_getFunction · 0.85
ggml_vbuffer_chunk_sizeFunction · 0.85
ggml_vbuffer_sizeFunction · 0.85
ggml_backend_buft_nameFunction · 0.85
ggml_vbuffer_freeFunction · 0.85
ggml_vbuffer_allocFunction · 0.85

Tested by

no test coverage detected