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

Function ggml_new_object

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

Source from the content-addressed store, hash-verified

1617////////////////////////////////////////////////////////////////////////////////
1618
1619static struct ggml_object * ggml_new_object(struct ggml_context * ctx, enum ggml_object_type type, size_t size) {
1620 // always insert objects at the end of the context's memory pool
1621 struct ggml_object * obj_cur = ctx->objects_end;
1622
1623 const size_t cur_offs = obj_cur == NULL ? 0 : obj_cur->offs;
1624 const size_t cur_size = obj_cur == NULL ? 0 : obj_cur->size;
1625 const size_t cur_end = cur_offs + cur_size;
1626
1627 // align to GGML_MEM_ALIGN
1628 size_t size_needed = GGML_PAD(size, GGML_MEM_ALIGN);
1629
1630 char * const mem_buffer = ctx->mem_buffer;
1631 struct ggml_object * const obj_new = (struct ggml_object *)(mem_buffer + cur_end);
1632
1633 if (cur_end + size_needed + GGML_OBJECT_SIZE > ctx->mem_size) {
1634 GGML_LOG_WARN("%s: not enough space in the context's memory pool (needed %zu, available %zu)\n",
1635 __func__, cur_end + size_needed + GGML_OBJECT_SIZE, ctx->mem_size);
1636#ifndef NDEBUG
1637 GGML_ABORT("not enough space in the context's memory pool");
1638#endif
1639 return NULL;
1640 }
1641
1642 *obj_new = (struct ggml_object) {
1643 .offs = cur_end + GGML_OBJECT_SIZE,
1644 .size = size_needed,
1645 .next = NULL,
1646 .type = type,
1647 };
1648
1649 GGML_ASSERT_ALIGNED(mem_buffer + obj_new->offs);
1650
1651 if (obj_cur != NULL) {
1652 obj_cur->next = obj_new;
1653 } else {
1654 // this is the first object in this context
1655 ctx->objects_begin = obj_new;
1656 }
1657
1658 ctx->objects_end = obj_new;
1659
1660 //printf("%s: inserted new object at %zu, size = %zu\n", __func__, cur_end, obj_new->size);
1661
1662 return obj_new;
1663}
1664
1665static struct ggml_tensor * ggml_new_tensor_impl(
1666 struct ggml_context * ctx,

Callers 3

ggml_new_tensor_implFunction · 0.85
ggml_new_bufferFunction · 0.85
ggml_new_graph_customFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected