MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / ggml_new_graph_custom

Function ggml_new_graph_custom

subprojects/llama.cpp/ggml/src/ggml.c:6966–7008  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6964}
6965
6966struct ggml_cgraph * ggml_new_graph_custom(struct ggml_context * ctx, size_t size, bool grads) {
6967 const size_t obj_size = ggml_graph_nbytes(size, grads);
6968 struct ggml_object * obj = ggml_new_object(ctx, GGML_OBJECT_TYPE_GRAPH, obj_size);
6969 struct ggml_cgraph * cgraph = (struct ggml_cgraph *) ((char *) ctx->mem_buffer + obj->offs);
6970
6971 // the size of the hash table is doubled since it needs to hold both nodes and leafs
6972 size_t hash_size = ggml_hash_size(size * 2);
6973
6974 void * p = cgraph + 1;
6975
6976 struct ggml_tensor ** nodes_ptr = incr_ptr_aligned(&p, size * sizeof(struct ggml_tensor *), sizeof(struct ggml_tensor *));
6977 struct ggml_tensor ** leafs_ptr = incr_ptr_aligned(&p, size * sizeof(struct ggml_tensor *), sizeof(struct ggml_tensor *));
6978 int32_t * use_counts_ptr = incr_ptr_aligned(&p, hash_size * sizeof(int32_t), sizeof(int32_t));
6979 struct ggml_tensor ** hash_keys_ptr = incr_ptr_aligned(&p, hash_size * sizeof(struct ggml_tensor *), sizeof(struct ggml_tensor *));
6980 struct ggml_tensor ** grads_ptr = grads ? incr_ptr_aligned(&p, hash_size * sizeof(struct ggml_tensor *), sizeof(struct ggml_tensor *)) : NULL;
6981 struct ggml_tensor ** grad_accs_ptr = grads ? incr_ptr_aligned(&p, hash_size * sizeof(struct ggml_tensor *), sizeof(struct ggml_tensor *)) : NULL;
6982
6983 ggml_bitset_t * hash_used = incr_ptr_aligned(&p, ggml_bitset_size(hash_size) * sizeof(ggml_bitset_t), sizeof(ggml_bitset_t));
6984
6985 // check that we allocated the correct amount of memory
6986 assert(obj_size == (size_t)((char *)p - (char *)cgraph));
6987
6988 *cgraph = (struct ggml_cgraph) {
6989 /*.size =*/ size,
6990 /*.n_nodes =*/ 0,
6991 /*.n_leafs =*/ 0,
6992 /*.nodes =*/ nodes_ptr,
6993 /*.grads =*/ grads_ptr,
6994 /*.grad_accs =*/ grad_accs_ptr,
6995 /*.leafs =*/ leafs_ptr,
6996 /*.use_counts =*/ use_counts_ptr,
6997 /*.hash_table =*/ { hash_size, hash_used, hash_keys_ptr },
6998 /*.order =*/ GGML_CGRAPH_EVAL_ORDER_LEFT_TO_RIGHT,
6999 };
7000
7001 ggml_hash_set_reset(&cgraph->visited_hash_set);
7002 if (grads) {
7003 memset(cgraph->grads, 0, hash_size*sizeof(struct ggml_tensor *));
7004 memset(cgraph->grad_accs, 0, hash_size*sizeof(struct ggml_tensor *));
7005 }
7006
7007 return cgraph;
7008}
7009
7010struct ggml_cgraph * ggml_new_graph(struct ggml_context * ctx) {
7011 return ggml_new_graph_custom(ctx, GGML_DEFAULT_GRAPH_SIZE, false);

Callers 12

clip_graphMethod · 0.85
resetMethod · 0.85
eval_perfMethod · 0.85
eval_supportMethod · 0.85
eval_gradMethod · 0.85
ggml_new_graphFunction · 0.85
ggml_graph_dupFunction · 0.85
dup_graphFunction · 0.85
ggml_opt_initFunction · 0.85
ggml_backend_graph_copyFunction · 0.85
graph_computeMethod · 0.85
apir_deserialize_graphFunction · 0.85

Calls 6

ggml_graph_nbytesFunction · 0.85
ggml_new_objectFunction · 0.85
ggml_hash_sizeFunction · 0.85
ggml_bitset_sizeFunction · 0.85
ggml_hash_set_resetFunction · 0.85
incr_ptr_alignedFunction · 0.70

Tested by 3

eval_perfMethod · 0.68
eval_supportMethod · 0.68
eval_gradMethod · 0.68