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

Function ggml_graph_import

ggml.c:17729–17984  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17727}
17728
17729struct ggml_cgraph * ggml_graph_import(const char * fname, struct ggml_context ** ctx_data, struct ggml_context ** ctx_eval) {
17730 assert(*ctx_data == NULL);
17731 assert(*ctx_eval == NULL);
17732
17733 struct ggml_cgraph * result = NULL;
17734
17735 struct ggml_tensor * data = NULL;
17736
17737 // read file into data
17738 {
17739 FILE * fin = fopen(fname, "rb");
17740 if (!fin) {
17741 fprintf(stderr, "%s: failed to open %s\n", __func__, fname);
17742 return result;
17743 }
17744
17745 size_t fsize = 0;
17746
17747 fseek(fin, 0, SEEK_END);
17748 fsize = ftell(fin);
17749 fseek(fin, 0, SEEK_SET);
17750
17751 // create the data context
17752 {
17753 const size_t overhead = 1*ggml_tensor_overhead();
17754
17755 struct ggml_init_params params = {
17756 .mem_size = fsize + overhead,
17757 .mem_buffer = NULL,
17758 .no_alloc = false,
17759 };
17760
17761 *ctx_data = ggml_init(params);
17762
17763 if (!*ctx_data) {
17764 fprintf(stderr, "%s: failed to create ggml context\n", __func__);
17765 fclose(fin);
17766 return result;
17767 }
17768 }
17769
17770 data = ggml_new_tensor_1d(*ctx_data, GGML_TYPE_I8, fsize);
17771
17772 {
17773 const size_t ret = fread(data->data, sizeof(char), fsize, fin);
17774 if (ret != fsize) {
17775 fprintf(stderr, "%s: failed to read %s\n", __func__, fname);
17776 fclose(fin);
17777 return result;
17778 }
17779 }
17780
17781 fclose(fin);
17782 }
17783
17784 // populate result
17785 {
17786 char * ptr = (char *) data->data;

Callers 1

mainFunction · 0.85

Calls 12

fprintfFunction · 0.85
ggml_tensor_overheadFunction · 0.70
ggml_initFunction · 0.70
ggml_new_tensor_1dFunction · 0.70
ggml_new_graph_customFunction · 0.70
ggml_new_tensorFunction · 0.70
ggml_nbytesFunction · 0.70
ggml_set_no_allocFunction · 0.70
ggml_reshape_4dFunction · 0.70
ggml_view_4dFunction · 0.70
ggml_transposeFunction · 0.70

Tested by

no test coverage detected