From 69cbb523110f553ff5284f78d48ac3ffb72231d1 Mon Sep 17 00:00:00 2001 From: KeDengMS Date: Fri, 28 Jun 2019 14:13:09 -0700 Subject: [PATCH] Add debug print for Visual Studio immediate window. Now you can run tvm::ToString(node) to show the content --- include/tvm/expr.h | 6 ++++++ src/lang/expr.cc | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/include/tvm/expr.h b/include/tvm/expr.h index 35083cafae81..b9dd54881c77 100644 --- a/include/tvm/expr.h +++ b/include/tvm/expr.h @@ -278,6 +278,12 @@ TVM_DLL std::ostream& operator<<(std::ostream& os, const NodeRef& n); // NOLINT */ TVM_DLL void Dump(const NodeRef& node); +/*! + * \brief Dump the node to char[], used for debug purposes. + * \param node The input node + */ +TVM_DLL std::unique_ptr ToString(const NodeRef& node); + // definition of Node. /*! * \brief An iteration variable representing an iteration diff --git a/src/lang/expr.cc b/src/lang/expr.cc index 7ac0e372371c..aef8d5a00937 100644 --- a/src/lang/expr.cc +++ b/src/lang/expr.cc @@ -52,6 +52,14 @@ void Dump(const NodeRef& n) { std::cerr << n << "\n"; } +std::unique_ptr ToString(const NodeRef& n) { + std::ostringstream s; + s << n << "\n"; + std::unique_ptr cc(new char[s.str().length() + 1]); + strcpy(cc.get(), s.str().c_str()); + return cc; +} + Var var(const std::string& name_hint, Type t) { return Var(name_hint, t); }