From e76156d2fd872d2263c71a0eadd4f138773e06d6 Mon Sep 17 00:00:00 2001 From: Gustavo Romero Date: Thu, 28 Oct 2021 14:19:23 +0000 Subject: [PATCH] areusch review: New workaround for multiple runs on micro targets Instead of not calling FreeHandle() when a session terminates on the host side, avoid calling TVMFreeMod() for system_lib_handle on the target side. --- src/runtime/crt/common/crt_runtime_api.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/runtime/crt/common/crt_runtime_api.c b/src/runtime/crt/common/crt_runtime_api.c index ea986a3bf0965..450ffee8daf1a 100644 --- a/src/runtime/crt/common/crt_runtime_api.c +++ b/src/runtime/crt/common/crt_runtime_api.c @@ -183,7 +183,17 @@ int TVMModCreateFromCModule(const TVMModule* mod, TVMModuleHandle* out_handle) { return -1; } +static const TVMModuleHandle kTVMModuleHandleUninitialized = (TVMModuleHandle)(~0UL); + +static TVMModuleHandle system_lib_handle; + int TVMModFree(TVMModuleHandle mod) { + /* Never free system_lib_handler */ + if (mod == system_lib_handle && + system_lib_handle != kTVMModuleHandleUninitialized) { + return 0; + } + tvm_module_index_t module_index; if (DecodeModuleHandle(mod, &module_index) != 0) { return -1; @@ -193,10 +203,6 @@ int TVMModFree(TVMModuleHandle mod) { return 0; } -static const TVMModuleHandle kTVMModuleHandleUninitialized = (TVMModuleHandle)(~0UL); - -static TVMModuleHandle system_lib_handle; - int SystemLibraryCreate(TVMValue* args, int* type_codes, int num_args, TVMValue* ret_val, int* ret_type_codes) { const TVMModule* system_lib;