From 1b61b302334bf38a5e957b768b8953323c251533 Mon Sep 17 00:00:00 2001 From: xiguadong <55774832+xiguadong@users.noreply.github.com> Date: Wed, 29 Sep 2021 17:28:23 +0800 Subject: [PATCH] fix bug:load model from memory (#1168) --- source/api/c_api.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/source/api/c_api.c b/source/api/c_api.c index 11a1332b6..ec3edb829 100644 --- a/source/api/c_api.c +++ b/source/api/c_api.c @@ -393,42 +393,43 @@ graph_t create_graph(context_t context, const char* model_format, const char* fi { int ret = 0; struct serializer* loader = find_serializer_via_name(model_format); - if (loader == NULL) - { - TLOG_ERR("Tengine: No matched serializer(name: %s) found.\n", model_format); - return create_graph_error; - } - va_list ap; - va_start(ap, file_name); - - const char* p = strchr(model_format, ':'); - - // load from file or memory - if (NULL == p) - { - ret = loader->load_model(loader, ir_graph, file_name, ap); - } - else + if (loader == NULL) { - if (p[1] != 'm') + // load from memory + const char* p = strchr(model_format, ':'); + if ((NULL == p) || (p[1] != 'm')) { TLOG_ERR("Tengine: Invalid postfix(%s) for model format: should 'm' only.\n", p); return create_graph_error(ir_graph); } + loader = find_serializer_via_name("tengine"); + if (NULL == loader->load_mem) { TLOG_ERR("Tengine: Serializer(%s) does not support loading from memory.\n", loader->get_name(loader)); return create_graph_error(ir_graph); } + va_start(ap, file_name); + int size = va_arg(ap, int); ret = loader->load_mem(loader, ir_graph, (void*)file_name, size, ap); + + va_end(ap); } + else + { + // load from file + + va_start(ap, file_name); - va_end(ap); + ret = loader->load_model(loader, ir_graph, file_name, ap); + + va_end(ap); + } if (0 != ret) {