How to debug tir::Stmt?

  • I’m new to debug the tvm code with gdb, but has no idea to print its value? such as for a stmt node:

    a) I tried the *p ::tvm::ir::AsText(stmt.get()) and p tvm::AsText(stmt).str(),and both failed with the following info.

    b)I have built the tvm with O0 -g option

(gdb) p ::tvm::ir::AsText(*stmt.get())
No symbol "tvm" in current context.
(gdb) p *stmt.get()
$14 = {<ascend_tvm::runtime::Object> = {static _type_key = <optimized out>, static _type_final = false, static _type_child_slots = 0, static _type_child_slots_can_overflow = true, static _type_has_method_visit_attrs = true, 
    static _type_has_method_sequal_reduce = false, static _type_has_method_shash_reduce = false, static _type_index = 9, type_index_ = 227, ref_counter_ = {<std::__atomic_base<int>> = {static _S_alignment = 4, _M_i = 2}, <No data fields>}, deleter_ = 0x7fffd48e885b
     <ascend_tvm::runtime::SimpleObjAllocator::Handler<ascend_tvm::tir::StoreNode>::Deleter_(ascend_tvm::runtime::Object*)>}, span = {<ascend_tvm::runtime::ObjectRef> = {static _type_is_nullable = true, data_ = {data_ = 0x0}}, <No data fields>}, 
  static _type_key = <optimized out>, static _type_has_method_sequal_reduce = true, static _type_has_method_shash_reduce = true, static _type_child_slots = 15}
(gdb) p tvm::AsText(stmt).str()
No symbol "tvm" in current context.

It seems that there is no function tvm::ir::AsText() as you mentioned. Instead, we can directly use std::cout to print the content of a tvm::tir::Stmt variable.

  Stmt st1 = tvm::tir::LetStmt(tvm::tir::Var("x"), 1, tvm::tir::Evaluate(tvm::tir::Var("y")));
  std::cout <<  (st1) << '\n';
  /// Output:
  ///   with T.LetStmt(1) as x:
  ///     T.evaluate(y)

Alternatively, we can use tvm::Dump when dubugging with GDB:

Breakpoint 2, stmt_test::Test () at /home/......./stmt-test.cc:543
543       Stmt st1 = tvm::tir::LetStmt(tvm::tir::Var("x"), 1, tvm::tir::Evaluate(tvm::tir::Var("y")));
(gdb) n
544       std::cout <<  (st1) << '\n';
(gdb) call tvm::Dump(st1)
with T.LetStmt(1) as x:
    y = T.int32()
    T.evaluate(y)

Hope the link below is helpful: anirudhsundar/tvm-gdb-commands: Small set of gdb commands for useful tasks in tvm

2 Likes

@benkangpeng Thanks very much, I can dump in debug now :+1:

(gdb) call ascend_tvm::Dump(stmt)
(mul_0[i0.c, i1.c] + -1h)