lhutton1 commented on PR #16425:
URL: https://github.com/apache/tvm/pull/16425#issuecomment-2019958120

   Here is a reproducer:
   mem_leak.cpp
   ```c++
   #include "tvm/runtime/registry.h"
   #include "tvm/target/target.h"
   
   int main() {
     auto pf = tvm::runtime::Registry::Get("target.llvm_get_cpu_archlist");
     (*pf)(tvm::Target("llvm"));
   }
   ```
   Compile:
   ```bash
   g++ -std=c++17 -O2 -fPIC -I{TVM_DIR}/include 
-I{TVM_DIR}/3rdparty/dmlc-core/include -I{TVM_DIR}/tvm/3rdparty/dlpack/include 
-DDMLC_USE_LOGGING_LIBRARY=\<tvm/runtime/logging.h\> -o mem_leak_exec 
mem_leak.cpp -L{TVM_BUILD_DIR} -ldl -ltvm -pthread
   ```
   Run with valgrind:
   ```bash
   LD_PRELOAD="{TVM_BUILD_DIR}/libtvm.so" valgrind --leak-check=full -v 
--track-origins=yes ./mem_leak_exec
   ```
   
   Output:
   ```
   ...
   ==475237== 12,369 (1,560 direct, 10,809 indirect) bytes in 1 blocks are 
definitely lost in loss record 42,596 of 42,630
   ==475237==    at 0x4849013: operator new(unsigned long) (in 
/usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
   ==475237==    by 0x12244479: ??? (in 
/usr/lib/x86_64-linux-gnu/libLLVM-17.so.1)
   ==475237==    by 0xBC0131B: 
llvm::Target::createTargetMachine(llvm::StringRef, llvm::StringRef, 
llvm::StringRef, llvm::TargetOptions const&, std::optional<llvm::Reloc::Model>, 
std::optional<llvm::CodeModel::Model>, llvm::CodeGenOpt::Level, bool) const 
(TargetRegistry.h:488)
   ==475237==    by 0xBBFBC05: 
tvm::codegen::CreateLLVMTargetMachine(llvm::Target const*, 
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > 
const&, std::__cxx11::basic_string<char, std::char_traits<char>, 
std::allocator<char> > const&, std::__cxx11::basic_string<char, 
std::char_traits<char>, std::allocator<char> > const&, llvm::TargetOptions 
const&, llvm::Reloc::Model const&, llvm::CodeModel::Model const&, 
llvm::CodeGenOpt::Level const&) (llvm_instance.cc:393)
   ==475237==    by 0xBBFBD8A: 
tvm::codegen::GetLLVMSubtargetInfo(std::__cxx11::basic_string<char, 
std::char_traits<char>, std::allocator<char> > const&, 
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > 
const&, std::__cxx11::basic_string<char, std::char_traits<char>, 
std::allocator<char> > const&) (llvm_instance.cc:408)
   ==475237==    by 0xBBFEAE1: 
tvm::codegen::LLVMTargetInfo::GetAllLLVMTargetArches() const 
(llvm_instance.cc:835)
   ==475237==    by 0xBBFA2BB: 
tvm::codegen::LLVMTargetInfo::LLVMTargetInfo(tvm::codegen::LLVMInstance&, 
tvm::Target const&) (llvm_instance.cc:218)
   ==475237==    by 0xBC0EE16: tvm::codegen::__mk_TVM8::{lambda(tvm::Target 
const&)#1}::operator()(tvm::Target const) const (llvm_module.cc:695)
   ==475237==    by 0xBC188B0: 
tvm::runtime::TypedPackedFunc<tvm::runtime::Array<tvm::runtime::String, void> 
(tvm::Target 
const&)>::AssignTypedLambda<tvm::codegen::__mk_TVM8::{lambda(tvm::Target 
const&)#1}>(tvm::codegen::__mk_TVM8::{lambda(tvm::Target const&)#1}, 
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> 
>)::{lambda(tvm::runtime::TVMArgs const&, 
tvm::runtime::TVMRetValue*)#1}::operator()(tvm::runtime::TVMArgs const, 
tvm::runtime::TVMRetValue) const (packed_func.h:1826)
   ==475237==    by 0xBC233EE: 
tvm::runtime::PackedFuncObj::Extractor<tvm::runtime::PackedFuncSubObj<tvm::runtime::TypedPackedFunc<tvm::runtime::Array<tvm::runtime::String,
 void> (tvm::Target 
const&)>::AssignTypedLambda<tvm::codegen::__mk_TVM8::{lambda(tvm::Target 
const&)#1}>(tvm::codegen::__mk_TVM8::{lambda(tvm::Target const&)#1}, 
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> 
>)::{lambda(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)#1}> 
>::Call(tvm::runtime::PackedFuncObj const*, std::__cxx11::basic_string<char, 
std::char_traits<char>, std::allocator<char> >, tvm::runtime::TVMRetValue) 
(packed_func.h:1252)
   ==475237==    by 0x1092F8: main (in 
/workspaces/tvm-ethosn/src/tvm/test_mem_leak/cpp_deploy)
   ...
   ```
   
   


-- 
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.

To unsubscribe, e-mail: commits-unsubscr...@tvm.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to