Skip to content

Instantly share code, notes, and snippets.

@AnirudhDagar
Created August 1, 2021 23:45
Show Gist options
  • Save AnirudhDagar/2b06a26f3ae1ac0db997ac8267c988d7 to your computer and use it in GitHub Desktop.
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`
import torch
# your code...
a = torch.tensor([1,2])
b = torch.tensor([3,4])
c = torch.cat([a, b])
# 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