Skip to content

Commit

Permalink
fix bug:load model from memory (#1168)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiguadong authored Sep 29, 2021
1 parent 7638a74 commit 1b61b30
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions source/api/c_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 1b61b30

Please sign in to comment.