@@ -85,12 +85,8 @@ is_valid_graph(TFLiteContext *tfl_ctx, graph g)
8585 NN_ERR_PRINTF (" Invalid graph: %d >= %d." , g, MAX_GRAPHS_PER_INST );
8686 return runtime_error;
8787 }
88- if (tfl_ctx->models [g].model_pointer == NULL ) {
89- NN_ERR_PRINTF (" Context (model) non-initialized." );
90- return runtime_error;
91- }
9288 if (tfl_ctx->models [g].model == NULL ) {
93- NN_ERR_PRINTF (" Context (tflite model) non-initialized." );
89+ NN_ERR_PRINTF (" Context (model) non-initialized." );
9490 return runtime_error;
9591 }
9692 return success;
@@ -472,32 +468,31 @@ deinit_backend(void *tflite_ctx)
472468 NN_DBG_PRINTF (" Freeing memory." );
473469 for (int i = 0 ; i < MAX_GRAPHS_PER_INST ; ++i) {
474470 tfl_ctx->models [i].model .reset ();
475- if (tfl_ctx->models [i].model_pointer ) {
476- if (tfl_ctx->delegate ) {
477- switch (tfl_ctx->models [i].target ) {
478- case gpu:
479- {
471+ if (tfl_ctx->delegate ) {
472+ switch (tfl_ctx->models [i].target ) {
473+ case gpu:
474+ {
480475#if WASM_ENABLE_WASI_NN_GPU != 0
481- TfLiteGpuDelegateV2Delete (tfl_ctx->delegate );
476+ TfLiteGpuDelegateV2Delete (tfl_ctx->delegate );
482477#else
483- NN_ERR_PRINTF (" GPU delegate delete but not enabled." );
478+ NN_ERR_PRINTF (" GPU delegate delete but not enabled." );
484479#endif
485- break ;
486- }
487- case tpu:
488- {
480+ break ;
481+ }
482+ case tpu:
483+ {
489484#if WASM_ENABLE_WASI_NN_EXTERNAL_DELEGATE != 0
490- TfLiteExternalDelegateDelete (tfl_ctx->delegate );
485+ TfLiteExternalDelegateDelete (tfl_ctx->delegate );
491486#else
492- NN_ERR_PRINTF (
493- " External delegate delete but not enabled." );
487+ NN_ERR_PRINTF (" External delegate delete but not enabled." );
494488#endif
495- break ;
496- }
497- default :
498- break ;
489+ break ;
499490 }
491+ default :
492+ break ;
500493 }
494+ }
495+ if (tfl_ctx->models [i].model_pointer ) {
501496 wasm_runtime_free (tfl_ctx->models [i].model_pointer );
502497 }
503498 tfl_ctx->models [i].model_pointer = NULL ;
0 commit comments