Skip to content

anirudhsundar/tvm-gdb-commands

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TVM specific GDB commands and GDB debugging configuration in VSCode​

1. TVM specific GDB commands

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.

1.1 Installation

  • 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 the commands.py file, either directly in your gdb session or add the below line to your .gdbinit:

    source /path/to/commands.py

1.2 Commands Explained

  • tvm_dump / tvd

    Calls p tvm::Dump(<value>) for a given value

    tvd is an alias to tvm_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 of PrimExpr the given value is. This is in same spirit to whatis command in gdb

    tvt is an alias to tvm_type

    For example, AddNode could be the underlying original type of the object, declared using it's parent PrimExprNode

    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 to tvm_attr

    For example, AddNode has the members a and b, 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 to tvm_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

1.3 Other Tips

  • 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

2. GDB debugging configuration in VSCode​

The .vscode/launch.json configuration enables hybrid debugging of TVM's Python frontend (Python debugger) and C++ backend (GDB) in VSCode.

2.1 Required VSCode Extensions

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.

2.2 Debugging Modes​ and Usage

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.

Image

2.2.1 Hybrid Python + C++ Debugging for TVM

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:

Hybrid Debugging Example

2.2.2 Pure C++ Debugging

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:

Image

You can also check .vscode/launch.json for debugging mode details - we've added extensive comments there.

Contributions

Always welcome.

Acknowledgements

Thanks to Lunderberg for valuable feedback and whose tvm-gdb-extension was the inspiration to create this one

About

Small set of gdb commands for useful tasks in tvm

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •