Elegant and Efficient ways needed in debugging TVM C++ files

I have installed the ffi_navigator, lldb and etc modules, its ok to debugging from python to C++. but it’s still not convenient to show the C++ object’s vars and methods, only got the dummy data_, too many class are inherited from Object/ObjectPtr/ObjectRef. :innocent:

In my case now, the C++ program occur error with ICHECK_EQ(undefined.size(), 0) in MakePackedAPI(),If there are any methods to show the func_ptr->body and func_ptr->params, I may find the base reason of error quickly, but now, I could only get abstract “data_”.

Is there any Useful method, which could visualize the IRModule structure in C++ side while debugging?

    Traceback (most recent call last):
      File "/home/repo/test_tvm_nms.py", line 239, in <module>
        test_relax_nms()
      File "/home/repo/test_tvm_nms.py", line 236, in test_relax_nms
        exe = relax.build(relax_model, target=target)
      File "/home/repo/tvm/python/tvm/relax/vm_build.py", line 338, in build
        return _vmlink(builder, target, tir_mod, ext_libs, params, system_lib=system_lib)
      File "/home/repo/tvm/python/tvm/relax/vm_build.py", line 242, in _vmlink
        lib = tvm.build(
      File "/home/repo/tvm/python/tvm/driver/build_module.py", line 281, in build
        rt_mod_host = _driver_ffi.tir_to_runtime(annotated_mods, target_host)
      File "/home/repo/tvm/python/tvm/_ffi/_ctypes/packed_func.py", line 238, in __call__
        raise get_last_ffi_error()
    tvm.error.InternalError: Traceback (most recent call last):
      8: 0x000055aeba62d666
            at ../sysdeps/x86_64/elf/start.S:103
      7: __libc_start_main
      6: operator()
            at /home/repo/tvm/src/driver/driver_api.cc:511
      5: tvm::TIRToRuntime(tvm::runtime::Map<tvm::Target, tvm::IRModule, void, void> const&, tvm::Target const&)
            at /home/repo/tvm/src/driver/driver_api.cc:471
      4: tvm::SplitMixedModule(tvm::IRModule, tvm::Target const&, tvm::Target const&)
            at /home/repo/tvm/src/driver/driver_api.cc:415
      3: tvm::ApplyPasses(tvm::IRModule, tvm::transform::Sequential)
            at /home/repo/tvm/src/driver/driver_api.cc:286
      2: tvm::runtime::TVMRetValue tvm::runtime::PackedFunc::operator()<tvm::IRModule, tvm::transform::PassContext>(tvm::IRModule&&, tvm::transform::PassContext&&) const
      1: operator()
            at /home/repo/tvm/src/tir/transforms/make_packed_api.cc:406
      0: tvm::tir::MakePackedAPI(tvm::tir::PrimFunc)
            at /home/repo/tvm/src/tir/transforms/make_packed_api.cc:369
      File "/home/repo/tvm/src/tir/transforms/make_packed_api.cc", line 369
    InternalError: Check failed: undefined.size() == 0 (3 vs. 0) : In PrimFunc all_class_non_max_suppression variables [elem_offset, elem_offset, elem_offset] are used, but are not passed in as API arguments
1 Like

The simplest way to print the TVM objects in a debugger is to call tvm::Dump function. For example in your case, you could use a command in gdb like print tvm::Dump(func_ptr->body), to print the body. This would print it in the same TVMScript format that you get when you debug in python.

For a more comfortable debugging, there’s also a gdb plugin I created and find very useful is https://github.com/anirudhsundar/tvm-gdb-commands.

3 Likes

Thanks! this really helped me, perfect!

1 Like