MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / ggml_new_graph_custom

Function ggml_new_graph_custom

ggml.c:16345–16379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16343}
16344
16345struct ggml_cgraph * ggml_new_graph_custom(struct ggml_context * ctx, size_t size, bool grads) {
16346 const size_t obj_size = ggml_graph_nbytes(size, grads);
16347 struct ggml_object * obj = ggml_new_object(ctx, GGML_OBJECT_GRAPH, obj_size);
16348 struct ggml_cgraph * cgraph = (struct ggml_cgraph *) ((char *) ctx->mem_buffer + obj->offs);
16349
16350 struct ggml_tensor ** data_start = (struct ggml_tensor **) (cgraph + 1);
16351
16352 size_t hash_size = ggml_hash_size(size * 2);
16353 struct ggml_tensor ** nodes_ptr = data_start;
16354 struct ggml_tensor ** leafs_ptr = nodes_ptr + size;
16355 struct ggml_tensor ** hash_keys_ptr = leafs_ptr + size;
16356 struct ggml_tensor ** grads_ptr = grads ? hash_keys_ptr + hash_size : NULL;
16357
16358 // check that we allocated the correct amount of memory
16359 assert(obj_size == (size_t) (
16360 (grads ? (char *)(grads_ptr + size) : (char *)(hash_keys_ptr + hash_size)) - (char *)cgraph));
16361
16362 memset(hash_keys_ptr, 0, hash_size * sizeof(struct ggml_tensor *));
16363
16364 *cgraph = (struct ggml_cgraph) {
16365 /*.size =*/ size,
16366 /*.n_nodes =*/ 0,
16367 /*.n_leafs =*/ 0,
16368 /*.nodes =*/ nodes_ptr,
16369 /*.grads =*/ grads_ptr,
16370 /*.leafs =*/ leafs_ptr,
16371 /*.hash_table =*/ { hash_size, hash_keys_ptr },
16372 /*.order =*/ GGML_CGRAPH_EVAL_ORDER_LEFT_TO_RIGHT,
16373 /*.perf_runs =*/ 0,
16374 /*.perf_cycles =*/ 0,
16375 /*.perf_time_us =*/ 0,
16376 };
16377
16378 return cgraph;
16379}
16380
16381struct ggml_cgraph * ggml_new_graph(struct ggml_context * ctx) {
16382 return ggml_new_graph_custom(ctx, GGML_DEFAULT_GRAPH_SIZE, false);

Callers 15

ggml_new_graphFunction · 0.70
ggml_graph_dupFunction · 0.70
ggml_graph_importFunction · 0.70
ggml_opt_resumeFunction · 0.70
sum_gpu_indexFunction · 0.70
build_llama_variantsMethod · 0.70
build_optMethod · 0.70
build_baichuanMethod · 0.70
build_falconMethod · 0.70
build_starcoderMethod · 0.70
build_persimmonMethod · 0.70
build_refactMethod · 0.70

Calls 3

ggml_graph_nbytesFunction · 0.70
ggml_new_objectFunction · 0.70
ggml_hash_sizeFunction · 0.70

Tested by 2

check_gradientFunction · 0.40
mainFunction · 0.40