IDE Debugging into TVM code base

Hi All,

I am wondering what are the best practices of debugging into TVM code base in Linux? I’d like to have an IDE that steps into TVM code? I could not setup such development environment so far.

Any suggestions or directions?

1 Like

https://github.com/tqchen/ffi-navigator might be helpful, thanks to @masahi and @comaniac

1 Like

tqchen, thank you very much, and I just saw your other post regarding ffi-navigator as well. I am hitting my head to wall for a while to get proper development environment, and I have tried both Windows and Linux. I will see the ffi-navigator.

Is it possible for TVM-core gurus like you to share your experience setting up development environment to actually build and debug TVM? If I could create a development environment, I’d be happy to share, so far my efforts are failing. I think it will be really useful to have a documentation of setting up development environment. When I say development environment, I’d like to get proper IDE to build TVM and ability to step into TVM runtime code.

If you point some resources, I am happy to lead and create this tutorial by myself. But I need some help at this moment.

the source navigator will certainly help to look around the source. Different people try different kinds of approaches for runtime debugging, I believe some folks use gdb. In my case I use emacs and gdb if necessary

Thank you, and source navigator already boosted my performance. Thank you for the link.

Please share in the future, if there are any helpful tricks regarding developing for TVM including debugging. I am mostly having hard time regarding debugging so far. I hope that source navigator will help to some level.

This is a tough problem I think. I also met a few people who are trying to understand tvm by running it under debugger. Personally I don’t think it is the right approach (due to cpp <-> py issues) but I don’t have a good recommendation either. I can only say “just dive into the code and get your hands dirty” :slight_smile:

For me, since I know a way around the codebase, a simple logging (aka printf debugging) is enough and it always gets me the right answer quickly.

2 Likes

Thank you for sharing your opinion which is very valuable to know.

As I also asked here (How to debug TVMRuntime), I just want to hit any break point of C++ code under the relay.build_module.build() python function.

This is what I have done so far:

  • Build TVM with LLVM in debug mode
  • installed topi and tvm under anaconda environment
  • Created a python project with PyCharm which has relay.build_module.build() python function.

Now my problem is the python source codes (entry) are located under anaconda environment which i created, and C++ source codes are not included in those directories. I could not figure out how the python code under anaconda finds the C++ code?

I am sure there is a better way of doing this, but I somehow lost, and please share any suggestions to enable me to hit C++ break point from relay.build_module.build() python function.

You should be able to use the development mode see method 1 https://docs.tvm.ai/install/from_source.html#tvm-package

This way the python and c++ should be under the same project folder(as in the original source repo). Personally I do not use IDE to set break pts. But I think there should be a way to tell the debugger to build the dll, set the break pts according to the IDE and run the dll.

Perhaps others will know

@comaniac @jroesch

2 Likes

@Leo-arm , @mbaret , maybe you can share your experiences with lldb / clion ?

Ramana

I was trying to use C/Python mixed debugging mode in VSCode by following this material but it never becomes one of my major practice in development. The approach I used is similar to @masahi, so the navigator extension plays a more important role to me.

1 Like

I use CLion (https://www.jetbrains.com/clion/, free for personal use but needs a license for commercial use, I believe) on a Mac (CLion is cross-platform). This works reasonably well with TVM because TVM uses cmake, which happens to be the way CLion organises projects. Debugging between Python and C++ is not possible (ffi_navigator looks interesting) but debugging either Python -or- C++ is convenient, i.e. breakpoints work, single stepping works on both sides. For Python debug you can just set breakpoints in the Python code and run the python script with a CLion Run/Debug configuration; for C++ I set the Python interpreter as a debug target, use a Python script as a parameter, and any breakpoints at the C++ side are set when the shared object is loaded (and remembered between runs). There are some pretty printers for the lldb debugger in apps/lldb that make it a little easier to see what the variables are you are looking at.

Hope this helps. It is never going to be easy, I am afraid. :wink:

3 Likes

Thank you Leo-arm for sharing your experience. These are all very informative and I hope that it will help others as well.

Could you please clarify following? Is this mean that I can not step into corresponding C++ functions under the python function (e.g., relay.build_module.build()) using CLION?

Thanks again for sharing your experiences.

Yes, that is correct. The only way I have found to do that is to grep through the source code for the names of the functions. There are naming patterns to follow but it is not straightforward. Next week if I have time I’ll have a look at the ffi_navigator that tqchen pointed out. Maybe there is a way to hook that into CLion, as that also supports the Language Server Protocol.