Created
August 1, 2021 23:45
-
-
Save AnirudhDagar/2b06a26f3ae1ac0db997ac8267c988d7 to your computer and use it in GitHub Desktop.
These are some gdb commands I use to debug pytorch and peek into the c++ source. Here I want to understand what all functions are called when you use `torch.cat`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
# your code... | |
a = torch.tensor([1,2]) | |
b = torch.tensor([3,4]) | |
c = torch.cat([a, b]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Clean build | |
python setup.py clean | |
# Build with debug flag | |
DEBUG=1 python setup.py develop | |
# Now inside your source dir | |
gdb python | |
# Now inside gdb to get output saved into gdb.txt use | |
set logging on | |
# in gdb prompt, setup a break point | |
b /home/anirudhdagar/pytorch/aten/src/ATen/native/TensorShape.cpp:457 | |
# this will ask if you want to set the break beacause source file not found | |
# the reason is the process is not already started. | |
# Now run your actual program which will call this C code below | |
run scripts/debug_cat.py | |
# this will take some time to break into child process | |
# now check the backtrace | |
bt 32 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment