How to debug tir::Stmt?

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