(lldb) bt * thread #1, queue = 'com.apple.main-thread', stop reason = step over * frame #0: 0x000000032727a57c libtorch_cpu.dylib`torch::autograd::VariableType::(anonymous namespace)::add_Tensor(ks=(repr_ = 137438986241), self=0x000000010019e7b8, other=0x000000016fdfe838, alpha=0x000000016fdfe940) at VariableType_2.cpp:6345:3 frame #1: 0x000000032727b738 libtorch_cpu.dylib`c10::impl::wrap_kernel_functor_unboxed_<c10::impl::detail::WrapFunctionIntoFunctor_<c10::CompileTimeFunctionPointer<at::Tensor (c10::DispatchKeySet, at::Tensor const&, at::Tensor const&, c10::Scalar const&), &torch::autograd::VariableType::(anonymous namespace)::add_Tensor(c10::DispatchKeySet, at::Tensor const&, at::Tensor const&, c10::Scalar const&)>, at::Tensor, c10::guts::typelist::typelist<c10::DispatchKeySet, at::Tensor const&, at::Tensor const&, c10::Scalar const&>>, at::Tensor (c10::DispatchKeySet, at::Tensor const&, at::Tensor const&, c10::Scalar const&)>::call(c10::OperatorKernel*, c10::DispatchKeySet, at::Tensor const&, at::Tensor const&, c10::Scalar const&) [inlined] c10::impl::detail::WrapFunctionIntoFunctor_<c10::CompileTimeFunctionPointer<at::Tensor (c10::DispatchKeySet, at::Tensor const&, at::Tensor const&, c10::Scalar const&), &torch::autograd::VariableType::(anonymous namespace)::add_Tensor(c10::DispatchKeySet, at::Tensor const&, at::Tensor const&, c10::Scalar const&)>, at::Tensor, c10::guts::typelist::typelist<c10::DispatchKeySet, at::Tensor const&, at::Tensor const&, c10::Scalar const&>>::operator()(this=0x00006000008dbe00, args=(repr_ = 137438986241), args=0x000000010019e7b8, args=0x000000016fdfe838, args=0x000000016fdfe940) at WrapFunctionIntoFunctor.h:13:16 frame #2: 0x000000032727b710 libtorch_cpu.dylib`c10::impl::wrap_kernel_functor_unboxed_<c10::impl::detail::WrapFunctionIntoFunctor_<c10::CompileTimeFunctionPointer<at::Tensor (c10::DispatchKeySet, at::Tensor const&, at::Tensor const&, c10::Scalar const&), &torch::autograd::VariableType::(anonymous namespace)::add_Tensor(c10::DispatchKeySet, at::Tensor const&, at::Tensor const&, c10::Scalar const&)>, at::Tensor, c10::guts::typelist::typelist<c10::DispatchKeySet, at::Tensor const&, at::Tensor const&, c10::Scalar const&>>, at::Tensor (c10::DispatchKeySet, at::Tensor const&, at::Tensor const&, c10::Scalar const&)>::call(functor=0x00006000008dbe00, dispatchKeySet=(repr_ = 137438986241), args=0x000000010019e7b8, args=0x000000016fdfe838, args=0x000000016fdfe940) at make_boxed_from_unboxed_functor.h:485:14 frame #3: 0x0000000323408ea8 libtorch_cpu.dylib`at::Tensor c10::callUnboxedKernelFunction<at::Tensor, at::Tensor const&, at::Tensor const&, c10::Scalar const&>(unboxed_kernel_func=0x000000032727b6a4, functor=0x00006000008dbe00, dispatchKeySet=(repr_ = 137438986241), args=0x000000010019e7b8, args=0x000000016fdfe838, args=0x000000016fdfe940) at KernelFunction_impl.h:53:12 frame #4: 0x0000000323814984 libtorch_cpu.dylib`at::_ops::add_Tensor::call(at::Tensor const&, at::Tensor const&, c10::Scalar const&) at KernelFunction_impl.h:104:16 frame #5: 0x0000000323814934 libtorch_cpu.dylib`at::_ops::add_Tensor::call(at::Tensor const&, at::Tensor const&, c10::Scalar const&) [inlined] at::Tensor c10::Dispatcher::call<at::Tensor, at::Tensor const&, at::Tensor const&, c10::Scalar const&>(this=0x000000032c0c6ab8, op=0x000000032c0db150, args=0x000000010019e7b8, args=0x000000016fdfe838, args=0x000000016fdfe940) const at Dispatcher.h:698:28 frame #6: 0x0000000323814650 libtorch_cpu.dylib`at::_ops::add_Tensor::call(at::Tensor const&, at::Tensor const&, c10::Scalar const&) [inlined] c10::TypedOperatorHandle<at::Tensor (at::Tensor const&, at::Tensor const&, c10::Scalar const&)>::call(this=0x000000032c0db150, args=0x000000010019e7b8, args=0x000000016fdfe838, args=0x000000016fdfe940) const at Dispatcher.h:531:41 frame #7: 0x0000000323814590 libtorch_cpu.dylib`at::_ops::add_Tensor::call(self=0x000000010019e7b8, other=0x000000016fdfe838, alpha=0x000000016fdfe940) at Operators_2.cpp:1077:15 frame #8: 0x0000000104e1c804 libtorch_python.dylib`at::Tensor::add(this=0x000000010019e7b8, other=0x000000016fdfe838, alpha=0x000000016fdfe940) const at TensorBody.h:1664:12 frame #9: 0x0000000104e1c79c libtorch_python.dylib`torch::autograd::THPVariable_add(_object*, _object*, _object*)::$_1::operator()(this=0x000000016fdfe84f, self=0x000000010019e7b8, other=0x000000016fdfe838, alpha=0x000000016fdfe940) const at python_variable_methods.cpp:2743:21 frame #10: 0x0000000104d4a248 l 在mac上手动编译pytorch源码,并且安装这个编译的模块,然后使用lldb查看完整的add 调用栈。 mac 上目前还无法使用gdb。
lldb python3.10
b at::Tensor::add
run # 执行完run就进入了python环境
import torch
a= torch.Tensor([1,2])
b= torch.Tensor([1,2])
a + b
build/aten/./src/ATen/Operators_2.cpp pytorch这个文件是自动生成的
参考:
https://zhuanlan.zhihu.com/p/567978232
 
                    
                 
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号