|
26 | 26 | - [Use CCache](#use-ccache)
|
27 | 27 | - [Use a faster linker](#use-a-faster-linker)
|
28 | 28 | - [C++ frontend development tips](#c-frontend-development-tips)
|
| 29 | + - [GDB integration](#gdb-integration) |
29 | 30 | - [CUDA development tips](#cuda-development-tips)
|
30 | 31 | - [Windows development tips](#windows-development-tips)
|
31 | 32 | - [Known MSVC (and MSVC with NVCC) bugs](#known-msvc-and-msvc-with-nvcc-bugs)
|
@@ -735,6 +736,68 @@ framework, which you can read up about to learn how to configure the test runner
|
735 | 736 | submitting a new feature, we care very much that you write appropriate tests.
|
736 | 737 | Please follow the lead of the other tests to see how to write a new test case.
|
737 | 738 |
|
| 739 | +### GDB integration |
| 740 | + |
| 741 | +If you are debugging pytorch inside GDB, you might be interested in |
| 742 | +[pytorch-gdb](tools/gdb/pytorch-gdb.py). This script introduces some |
| 743 | +pytorch-specific commands which you can use from the GDB prompt. In |
| 744 | +particular, `torch-tensor-repr` prints a human-readable repr of an at::Tensor |
| 745 | +object. Example of usage: |
| 746 | + |
| 747 | +``` |
| 748 | +$ gdb python |
| 749 | +GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2 |
| 750 | +[...] |
| 751 | +(gdb) # insert a breakpoint when we call .neg() |
| 752 | +(gdb) break at::native:neg |
| 753 | +No source file named at::native. |
| 754 | +Make breakpoint pending on future shared library load? (y or [n]) y |
| 755 | +Breakpoint 1 (at::native:neg) pending. |
| 756 | +
|
| 757 | +(gdb) run |
| 758 | +[...] |
| 759 | +>>> import torch |
| 760 | +>>> t = torch.tensor([1, 2, 3, 4], dtype=torch.float64) |
| 761 | +>>> t |
| 762 | +tensor([1., 2., 3., 4.], dtype=torch.float64) |
| 763 | +>>> t.neg() |
| 764 | +
|
| 765 | +Breakpoint 1, at::native::neg (self=...) at [...]/pytorch/aten/src/ATen/native/UnaryOps.cpp:520 |
| 766 | +520 Tensor neg(const Tensor& self) { return unary_op_impl(self, at::neg_out); } |
| 767 | +(gdb) # the default repr of 'self' is not very useful |
| 768 | +(gdb) p self |
| 769 | +$1 = (const at::Tensor &) @0x7ffff72ed780: {impl_ = {target_ = 0x5555559df6e0}} |
| 770 | +(gdb) torch-tensor-repr self |
| 771 | +Python-level repr of self: |
| 772 | +tensor([1., 2., 3., 4.], dtype=torch.float64) |
| 773 | +``` |
| 774 | + |
| 775 | +GDB tries to automatically load `pytorch-gdb` thanks to the |
| 776 | +[.gdbinit](.gdbinit) at the root of the pytorch repo. Howevever, auto-loadings is disabled by default, because of security reasons: |
| 777 | + |
| 778 | +``` |
| 779 | +$ gdb |
| 780 | +warning: File "/path/to/pytorch/.gdbinit" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load". |
| 781 | +To enable execution of this file add |
| 782 | + add-auto-load-safe-path /path/to/pytorch/.gdbinit |
| 783 | +line to your configuration file "/home/YOUR-USERNAME/.gdbinit". |
| 784 | +To completely disable this security protection add |
| 785 | + set auto-load safe-path / |
| 786 | +line to your configuration file "/home/YOUR-USERNAME/.gdbinit". |
| 787 | +For more information about this security protection see the |
| 788 | +"Auto-loading safe path" section in the GDB manual. E.g., run from the shell: |
| 789 | + info "(gdb)Auto-loading safe path" |
| 790 | +(gdb) |
| 791 | +``` |
| 792 | + |
| 793 | +As gdb itself suggests, the best way to enable auto-loading of `pytorch-gdb` |
| 794 | +is to add the following line to your `~/.gdbinit` (i.e., the `.gdbinit` file |
| 795 | +which is in your home directory, **not** `/path/to/pytorch/.gdbinit`): |
| 796 | +``` |
| 797 | +add-auto-load-safe-path /path/to/pytorch/.gdbinit |
| 798 | +``` |
| 799 | + |
| 800 | + |
738 | 801 | ## CUDA development tips
|
739 | 802 |
|
740 | 803 | If you are working on the CUDA code, here are some useful CUDA debugging tips:
|
|
0 commit comments