I’m relatively new to C++ and LibTorch, but I would like to know how to inspect a tensor content in the debugger, since my workflow involves a lot of usage of the debugger.
I think you can see the content using cout in either run or debug consoles. Since you asked about gdb, I mentioned that approach. If you want to use gdb, you need to add more dimensions, e.g. p *x[i][j][k][l].data<float>().
It’s defined in ATen/core/Formatting.h. As far as I can see it should be there for 1.0, 1.0.1, and master. You could try using it in your code to see what’s wrong.
Strange. It worked for me the other day. While the version without the ostream might not be available due to the inlining, I would have expected the one with to be exported at the least.
As of 1.5.0, Tensor.print() seems to work to print type and shape info.
gdb) call t.print()
[CPUByteType [1, 10, 1, 10]]
To print full contents, it seems the form std::cout << Tensor << std::endl must be present in debugged C++ file first. But you also have to call fflush(0) since gdb has trouble with std::endl in my test case.
A .gdbinit quick solution:
define ptensor
call std::cout << $arg0
call fflush(0)
end
I’d love to know how to view a tensor in CLION’s debugger. I have not been able to get any of these solutions to work. I would love to be able to see the contents of the tensor while inspecting or evaluating an expression like I am able to see a vector.
How were you able to get it working in LLDB?