liangfu commented on a change in pull request #6948:
URL: https://github.com/apache/tvm/pull/6948#discussion_r533859211
##########
File path: src/runtime/crt/common/crt_runtime_api.c
##########
@@ -315,21 +315,30 @@ int TVMFuncFree(TVMFunctionHandle func) {
return 0;
}
-tvm_crt_error_t TVMInitializeRuntime(uint8_t* memory_pool, size_t
memory_pool_size_bytes,
- size_t page_size_bytes_log2) {
+tvm_crt_error_t TVMInitializeRuntime() {
int idx;
tvm_crt_error_t error;
+ void* func_registry_memory;
- error =
- TVMInitializeGlobalMemoryManager(memory_pool, memory_pool_size_bytes,
page_size_bytes_log2);
+ system_lib_handle = kTVMModuleHandleUninitialized;
+
+ DLContext ctx = {kDLCPU, 0};
+ error = TVMPlatformMemoryAllocate(TVM_CRT_GLOBAL_FUNC_REGISTRY_SIZE_BYTES,
ctx,
+ &func_registry_memory);
if (error != kTvmErrorNoError) {
return error;
}
system_lib_handle = kTVMModuleHandleUninitialized;
- TVMMutableFuncRegistry_Create(&global_func_registry,
-
vmalloc(TVM_CRT_GLOBAL_FUNC_REGISTRY_SIZE_BYTES),
+ void* registry_backing_memory;
+ error = TVMPlatformMemoryAllocate(TVM_CRT_GLOBAL_FUNC_REGISTRY_SIZE_BYTES,
ctx,
+ ®istry_backing_memory);
+ if (error != kTvmErrorNoError) {
+ return error;
Review comment:
When we reach here, we might need to release func_registry_memory before
reporting an error?
I would suggest 1) initialize func_registry_memory to nullptr on creation of
the pointer, 2) have a single return statement at the end, 3) we could check
all failed malloc and release all allocated memory before reporting an error.
Facing a mixture of successful and failed mallocs inside a function before
returning an error status, I think we might have create a memory leak.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]