首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >火炬漏了吗?

火炬漏了吗?
EN

Stack Overflow用户
提问于 2021-08-03 09:22:38
回答 2查看 589关注 0票数 0

在我的项目中,我使用的是pytorch c++库(lib手电)。在使用“英勇”时,似乎有些内存没有得到适当的释放。

Main.cpp:

代码语言:javascript
复制
int main() {
    // Do somenting with libtorch here...
    std::cout << "end of main" << std::endl;
    return EXIT_SUCCESS;
}

值研命令: valgrind --leak-check=full ./myapp

值研磨输出:

代码语言:javascript
复制
==385785== Memcheck, a memory error detector
==385785== Copyright (C) 2002-2017, and GNU GPL d, by Julian Seward et al.
==385785== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==385785== Command: ./btai
==385785== 
==385785== Warning: set address range perms: large range [0x48f5000, 0x17ecd000) (defined)
end of main
==385785== Conditional jump or move depends on uninitialised value(s)
==385785==    at 0x8181EE8: torch::jit::deregisterOperator(c10::FunctionSchema const&) (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x8361AB5: torch::jit::(anonymous namespace)::RegistrationListener::onOperatorDeregistered(c10::OperatorHandle const&) (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x583ACAC: c10::Dispatcher::deregisterDef_(c10::OperatorHandle const&, c10::OperatorName const&) (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x58733D4: c10::RegisterOperators::~RegisterOperators() (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x1827F15D: __cxa_finalize (cxa_finalize.c:83)
==385785==    by 0x574C6E2: ??? (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x4011F5A: _dl_fini (dl-fini.c:138)
==385785==    by 0x1827EA26: __run_exit_handlers (exit.c:108)
==385785==    by 0x1827EBDF: exit (exit.c:139)
==385785==    by 0x1825C0B9: (below main) (libc-start.c:342)
==385785== 
==385785== Conditional jump or move depends on uninitialised value(s)
==385785==    at 0x81820FD: torch::jit::deregisterOperator(c10::FunctionSchema const&) (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x8361AB5: torch::jit::(anonymous namespace)::RegistrationListener::onOperatorDeregistered(c10::OperatorHandle const&) (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x583ACAC: c10::Dispatcher::deregisterDef_(c10::OperatorHandle const&, c10::OperatorName const&) (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x58733D4: c10::RegisterOperators::~RegisterOperators() (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x1827F15D: __cxa_finalize (cxa_finalize.c:83)
==385785==    by 0x574C6E2: ??? (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x4011F5A: _dl_fini (dl-fini.c:138)
==385785==    by 0x1827EA26: __run_exit_handlers (exit.c:108)
==385785==    by 0x1827EBDF: exit (exit.c:139)
==385785==    by 0x1825C0B9: (below main) (libc-start.c:342)
==385785== 
==385785== 
==385785== HEAP SUMMARY:
==385785==     in use at exit: 724,686 bytes in 11,651 blocks
==385785==   total heap usage: 481,322 allocs, 469,671 frees, 59,519,540 bytes allocated
==385785== 
==385785== 256 bytes in 1 blocks are possibly lost in loss record 11,294 of 11,400
==385785==    at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==385785==    by 0xB7CB7A3: mm_account_ptr_by_tid..0 (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0xB7CAE79: mkl_serv_malloc (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x9AB5B86: mkl_serv_domain_get_max_threads (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x5791278: at::init_num_threads() (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x8E1C68B: at::native::(anonymous namespace)::min_all_kernel_impl(at::Tensor&, at::Tensor const&) (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x5B19042: at::native::min(at::Tensor const&) (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x633CD3B: c10::impl::wrap_kernel_functor_unboxed_<c10::impl::detail::WrapFunctionIntoFunctor_<c10::CompileTimeFunctionPointer<at::Tensor (at::Tensor const&), &at::(anonymous namespace)::(anonymous namespace)::wrapper__min>, at::Tensor, c10::guts::typelist::typelist<at::Tensor const&> >, at::Tensor (at::Tensor const&)>::call(c10::OperatorKernel*, c10::DispatchKeySet, at::Tensor const&) (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x6154390: at::Tensor c10::Dispatcher::redispatch<at::Tensor, at::Tensor const&>(c10::TypedOperatorHandle<at::Tensor (at::Tensor const&)> const&, c10::DispatchKeySet, at::Tensor const&) const [clone .isra.165] (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x615DA3E: at::redispatch::min(c10::DispatchKeySet, at::Tensor const&) (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x7AC1310: torch::autograd::VariableType::(anonymous namespace)::min(c10::DispatchKeySet, at::Tensor const&) (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x7AC17EE: c10::impl::wrap_kernel_functor_unboxed_<c10::impl::detail::WrapFunctionIntoFunctor_<c10::CompileTimeFunctionPointer<at::Tensor (c10::DispatchKeySet, at::Tensor const&), &torch::autograd::VariableType::(anonymous namespace)::min>, at::Tensor, c10::guts::typelist::typelist<c10::DispatchKeySet, at::Tensor const&> >, at::Tensor (c10::DispatchKeySet, at::Tensor const&)>::call(c10::OperatorKernel*, c10::DispatchKeySet, at::Tensor const&) (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785== 
==385785== 69,664 bytes in 1 blocks are possibly lost in loss record 11,400 of 11,400
==385785==    at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==385785==    by 0xB7CBA27: mm_account_ptr_by_tid..0 (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0xB7CAE79: mkl_serv_malloc (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x9AB5B86: mkl_serv_domain_get_max_threads (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x5791278: at::init_num_threads() (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x8E1C68B: at::native::(anonymous namespace)::min_all_kernel_impl(at::Tensor&, at::Tensor const&) (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x5B19042: at::native::min(at::Tensor const&) (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x633CD3B: c10::impl::wrap_kernel_functor_unboxed_<c10::impl::detail::WrapFunctionIntoFunctor_<c10::CompileTimeFunctionPointer<at::Tensor (at::Tensor const&), &at::(anonymous namespace)::(anonymous namespace)::wrapper__min>, at::Tensor, c10::guts::typelist::typelist<at::Tensor const&> >, at::Tensor (at::Tensor const&)>::call(c10::OperatorKernel*, c10::DispatchKeySet, at::Tensor const&) (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x6154390: at::Tensor c10::Dispatcher::redispatch<at::Tensor, at::Tensor const&>(c10::TypedOperatorHandle<at::Tensor (at::Tensor const&)> const&, c10::DispatchKeySet, at::Tensor const&) const [clone .isra.165] (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x615DA3E: at::redispatch::min(c10::DispatchKeySet, at::Tensor const&) (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x7AC1310: torch::autograd::VariableType::(anonymous namespace)::min(c10::DispatchKeySet, at::Tensor const&) (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785==    by 0x7AC17EE: c10::impl::wrap_kernel_functor_unboxed_<c10::impl::detail::WrapFunctionIntoFunctor_<c10::CompileTimeFunctionPointer<at::Tensor (c10::DispatchKeySet, at::Tensor const&), &torch::autograd::VariableType::(anonymous namespace)::min>, at::Tensor, c10::guts::typelist::typelist<c10::DispatchKeySet, at::Tensor const&> >, at::Tensor (c10::DispatchKeySet, at::Tensor const&)>::call(c10::OperatorKernel*, c10::DispatchKeySet, at::Tensor const&) (in /home/tmac3/Desktop/Branching_Time_Active_Inference/libs/torch/lib/libtorch_cpu.so)
==385785== 
==385785== LEAK SUMMARY:
==385785==    definitely lost: 0 bytes in 0 blocks
==385785==    indirectly lost: 0 bytes in 0 blocks
==385785==      possibly lost: 69,920 bytes in 2 blocks
==385785==    still reachable: 654,766 bytes in 11,649 blocks
==385785==                       of which reachable via heuristic:
==385785==                         stdstring          : 359,526 bytes in 4,879 blocks
==385785==         suppressed: 0 bytes in 0 blocks
==385785== Reachable blocks (those to which a pointer was found) are not shown.
==385785== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==385785== 
==385785== Use --track-origins=yes to see where uninitialised values come from
==385785== For lists of detected and suppressed errors, rerun with: -s
==385785== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)

正如您所看到的,在主函数之后会出现大量错误和内存泄漏。它们似乎来自于电子邮件,这些错误从何而来,以及如何消除它们?

EN

回答 2

Stack Overflow用户

发布于 2021-08-28 10:27:31

据我们所知,libTorch torch::jit::Module在移动上泄漏内存:在加载TorchCcript文件后不能释放torch::jit::Module的内存。

票数 1
EN

Stack Overflow用户

发布于 2021-08-09 02:12:16

我们在at::init_num_threads()完全相同的位置遇到了相同的泄漏问题。似乎泄漏可能发生在某些lib手电代码上,但最终会转到at::init_num_threads()。我们希望你在这个问题上有了一些进展。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68633454

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档