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

Function ggml_init

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

Source from the content-addressed store, hash-verified

1520////////////////////////////////////////////////////////////////////////////////
1521
1522struct ggml_context * ggml_init(struct ggml_init_params params) {
1523 static bool is_first_call = true;
1524
1525 ggml_critical_section_start();
1526
1527 if (is_first_call) {
1528 // initialize time system (required on Windows)
1529 ggml_time_init();
1530
1531 is_first_call = false;
1532 }
1533
1534 ggml_critical_section_end();
1535
1536 struct ggml_context * ctx = GGML_MALLOC(sizeof(struct ggml_context));
1537
1538 // allow to call ggml_init with 0 size
1539 if (params.mem_size == 0) {
1540 params.mem_size = GGML_MEM_ALIGN;
1541 }
1542
1543 const size_t mem_size = params.mem_buffer ? params.mem_size : GGML_PAD(params.mem_size, GGML_MEM_ALIGN);
1544
1545 *ctx = (struct ggml_context) {
1546 /*.mem_size =*/ mem_size,
1547 /*.mem_buffer =*/ params.mem_buffer ? params.mem_buffer : ggml_aligned_malloc(mem_size),
1548 /*.mem_buffer_owned =*/ params.mem_buffer ? false : true,
1549 /*.no_alloc =*/ params.no_alloc,
1550 /*.n_objects =*/ 0,
1551 /*.objects_begin =*/ NULL,
1552 /*.objects_end =*/ NULL,
1553 };
1554
1555 GGML_ASSERT(ctx->mem_buffer != NULL);
1556
1557 GGML_ASSERT_ALIGNED(ctx->mem_buffer);
1558
1559 GGML_PRINT_DEBUG("%s: context initialized\n", __func__);
1560
1561 return ctx;
1562}
1563
1564void ggml_reset(struct ggml_context * ctx) {
1565 if (ctx == NULL) {

Callers 15

save_tensor_for_layerMethod · 0.85
train_contextMethod · 0.85
pca_modelMethod · 0.85
build_graph_piterFunction · 0.85
lora_merge_ctxMethod · 0.85
merge_tensorMethod · 0.85
clip_graphMethod · 0.85
load_tensorsMethod · 0.85
save_imatrixMethod · 0.85
weight_buft_supportedFunction · 0.85
load_tensorsMethod · 0.85

Calls 4

ggml_time_initFunction · 0.85
ggml_aligned_mallocFunction · 0.85

Tested by 14

mainFunction · 0.68
test_barrierFunction · 0.68
test_activeFunction · 0.68
test_multi_graphFunction · 0.68
helper_get_ctx_dataFunction · 0.68
test_regressionFunction · 0.68
mainFunction · 0.68
make_contextFunction · 0.68
evalMethod · 0.68
eval_perfMethod · 0.68
eval_supportMethod · 0.68
eval_gradMethod · 0.68