This extension adds 4 new commands to gdb that improve the experience of debugging the Apache TVM code. The commands are explained below with examples.
-
Run the below command
bash < <(curl -s https://raw.githubusercontent.com/anirudhsundar/tvm-gdb-commands/master/install.sh)
-
Alternatively, download the
commands.py
to some location and source thecommands.py
file, either directly in your gdb session or add the below line to your.gdbinit
:source /path/to/commands.py
-
tvm_dump
/tvd
Calls
p tvm::Dump(<value>)
for a given valuetvd
is an alias totvm_dump
Eg:
(gdb) tvd index (((j.outer*64) + (i*n)) + j.inner)
-
tvm_type
/tvt
Prints the original object type of a given value. When a function gets a
PrimExpr
as argument, this commands prints which sub-class ofPrimExpr
the given value is. This is in same spirit to whatis command in gdbtvt
is an alias totvm_type
For example,
AddNode
could be the underlying original type of the object, declared using it's parentPrimExprNode
Usage:
(gdb) whatis index type = tvm::PrimExpr (gdb) tvt index tvm::tir::AddNode
-
tvm_attr
/tvat
This commmand extends the use of
tvm_type
and tries to access the underlying attributes/members of the original object.tvat
is an alias totvm_attr
For example, AddNode has the members
a
andb
, so this allows us to access those members.This prints out 3 lines, where the first line shows the access string used to access the member, second line shows the type of the object, and the last line prints a dump of the object
(gdb) tvat index.a access string '((tvm::tir::AddNode*)index).a' Type of object: 'tvm::tir::AddNode' ((j.outer*64) + (i*n))
This command can also take attributes recursively For example:
(gdb) tvat index.a.a.b access string '((tvm::tir::MulNode*)((tvm::tir::AddNode*)((tvm::tir::AddNode*)index).a).a).b' Type of object: 'tvm::IntImmNode' 64
-
tvm_fields
/tvf
This command prints the list of fields available in the given object/object.attributes. This can be called with either a single object, or the object.attr.attr syntax
tvf
is an alias totvm_fields
Note: The fields can also be directly found by completion when using the
tvm_attr
command, but there are some gotchas in that method, especially when trying completion more than once, so this command was written to help with that.For example:
(gdb) tvf index.a.a tvm::PrimExprNode a b _type_final _type_child_slots
-
There are 4 aliases (as shown below) defined in the code and if you wish to remove them in favor of others one might like, please comment out the last 4 lines in
commands.py
alias tvd = tvm_dump alias tvt = tvm_type alias tvat = tvm_attr alias tvf = tvm_fields
The .vscode/launch.json
configuration enables hybrid debugging of TVM's Python frontend (Python debugger) and C++ backend (GDB) in VSCode.
Before using this configuration to debug TVM, we should install the following extensions for VSCode:
- Python Debugger: Search
ms-python.debugpy
in VSCode extension marketplace. - C/C++: Search
ms-vscode.cpptools
in VSCode extension marketplace. - Python C++ Debugger: Search
benjamin-simmonds.pythoncpp-debug
in VSCode extension marketplace.
After installing the extensions, we should copy the .vscode/launch.json
file to the root directory of your own TVM project. And the next steps will explain some details that you should modify in the launch.json
file.
The current configuration supports two debugging modes:
- Hybrid Python Frontend + C++ Backend Debugging for TVM
- Pure C++ Backend Debugging for TVM
As the fowllowing image shows, we can choose the debugging mode in graphical interface. Ther are four choices:
Full Auto Debug (Python+C++)
is the entry for Hybrid Python Frontend + C++ Backend Debugging.Python: TVM Frontend
is responsible for the debugging of the Python Frontend.C++: TVM Backend
is responsible for the debugging of the C++ Backend.
Pure C++ Debug (C++)
is the entry for Pure C++ Backend Debugging.
This is a hybrid debugging approach, and requires users to first launch the Python script, after which the C++ process will be automatically attached.
Important
Customize the "program"
entry in .vscode/launch.json
to point to your Python virtual environment executable. Example path:
"program": "/home/user/miniconda3/envs/tvm-build-venv/bin/python3"
Commands that interact with the Debug Console should be preceded by -exec
, example:
-exec p pc
or-exec call tvm::Dump(mod)
Example:
This is a pure C++ debugging approach, where users can debug C++ components without Python scripts.
Important
Customize the "program"
entry in .vscode/launch.json
to your C++ executable path.
Example path:
"program": "${workspaceFolder}/get_started/tutorials/a.out"
Example:
You can also check .vscode/launch.json
for debugging mode details - we've added extensive comments there.
Always welcome.
Thanks to Lunderberg for valuable feedback and whose tvm-gdb-extension was the inspiration to create this one