altanh commented on a change in pull request #7952:
URL: https://github.com/apache/tvm/pull/7952#discussion_r638212865
##########
File path: include/tvm/ir/transform.h
##########
@@ -189,12 +183,36 @@ class PassContext : public ObjectRef {
TVM_DLL static PassContext Current();
/*!
- * \brief Apply the tracing functions of the context to the module, with the
info.
- * \param module The IRModule to trace.
+ * \brief Call instrument implementations' callbacks when entering
PassContex.
+ * In order, if one raises exceptions, remaings will not be called.
+ */
+ TVM_DLL void InstrumentEnterPassContext();
+
+ /*!
+ * \brief Call instrument implementations' callback when exiting PassContext.
Review comment:
```suggestion
* \brief Call instrument implementations' callbacks when exiting
PassContext.
```
##########
File path: include/tvm/ir/transform.h
##########
@@ -189,12 +183,36 @@ class PassContext : public ObjectRef {
TVM_DLL static PassContext Current();
/*!
- * \brief Apply the tracing functions of the context to the module, with the
info.
- * \param module The IRModule to trace.
+ * \brief Call instrument implementations' callbacks when entering
PassContex.
+ * In order, if one raises exceptions, remaings will not be called.
+ */
+ TVM_DLL void InstrumentEnterPassContext();
+
+ /*!
+ * \brief Call instrument implementations' callback when exiting PassContext.
+ * In order, if one raises exceptions, remaings will not be called.
Review comment:
see above
##########
File path: include/tvm/ir/transform.h
##########
@@ -189,12 +183,36 @@ class PassContext : public ObjectRef {
TVM_DLL static PassContext Current();
/*!
- * \brief Apply the tracing functions of the context to the module, with the
info.
- * \param module The IRModule to trace.
+ * \brief Call instrument implementations' callbacks when entering
PassContex.
Review comment:
```suggestion
* \brief Call instrument implementations' callbacks when entering
PassContext.
```
##########
File path: include/tvm/ir/transform.h
##########
@@ -189,12 +183,36 @@ class PassContext : public ObjectRef {
TVM_DLL static PassContext Current();
/*!
- * \brief Apply the tracing functions of the context to the module, with the
info.
- * \param module The IRModule to trace.
+ * \brief Call instrument implementations' callbacks when entering
PassContex.
+ * In order, if one raises exceptions, remaings will not be called.
Review comment:
```suggestion
* The callbacks are called In order, and if one raises an
exception, the rest will not be called.
```
##########
File path: python/tvm/ir/transform.py
##########
@@ -92,6 +104,9 @@ def __enter__(self):
def __exit__(self, ptype, value, trace):
_ffi_transform_api.ExitPassContext(self)
+ def override_instruments(self, instruments):
Review comment:
could you add a docstring here to describe this method
##########
File path: include/tvm/ir/transform.h
##########
@@ -189,12 +183,36 @@ class PassContext : public ObjectRef {
TVM_DLL static PassContext Current();
/*!
- * \brief Apply the tracing functions of the context to the module, with the
info.
- * \param module The IRModule to trace.
+ * \brief Call instrument implementations' callbacks when entering
PassContex.
+ * In order, if one raises exceptions, remaings will not be called.
+ */
+ TVM_DLL void InstrumentEnterPassContext();
+
+ /*!
+ * \brief Call instrument implementations' callback when exiting PassContext.
+ * In order, if one raises exceptions, remaings will not be called.
+ */
+ TVM_DLL void InstrumentExitPassContext();
+
+ /*!
+ * \brief Call intrument implementations' callbacks before a pass run.
Review comment:
```suggestion
* \brief Call instrument implementations' callbacks before a pass run.
```
##########
File path: include/tvm/ir/transform.h
##########
@@ -189,12 +183,36 @@ class PassContext : public ObjectRef {
TVM_DLL static PassContext Current();
/*!
- * \brief Apply the tracing functions of the context to the module, with the
info.
- * \param module The IRModule to trace.
+ * \brief Call instrument implementations' callbacks when entering
PassContex.
+ * In order, if one raises exceptions, remaings will not be called.
+ */
+ TVM_DLL void InstrumentEnterPassContext();
+
+ /*!
+ * \brief Call instrument implementations' callback when exiting PassContext.
+ * In order, if one raises exceptions, remaings will not be called.
+ */
+ TVM_DLL void InstrumentExitPassContext();
+
+ /*!
+ * \brief Call intrument implementations' callbacks before a pass run.
+ * In order, if one raises exceptions, remaings will not be called.
Review comment:
see previous suggestion
##########
File path: include/tvm/ir/transform.h
##########
@@ -189,12 +183,36 @@ class PassContext : public ObjectRef {
TVM_DLL static PassContext Current();
/*!
- * \brief Apply the tracing functions of the context to the module, with the
info.
- * \param module The IRModule to trace.
+ * \brief Call instrument implementations' callbacks when entering
PassContex.
+ * In order, if one raises exceptions, remaings will not be called.
+ */
+ TVM_DLL void InstrumentEnterPassContext();
+
+ /*!
+ * \brief Call instrument implementations' callback when exiting PassContext.
+ * In order, if one raises exceptions, remaings will not be called.
+ */
+ TVM_DLL void InstrumentExitPassContext();
+
+ /*!
+ * \brief Call intrument implementations' callbacks before a pass run.
+ * In order, if one raises exceptions, remaings will not be called.
+ *
+ * \param mod The module that an optimization pass runs on.
* \param info The pass information.
- * \param is_before Indicated whether the tracing is before or after a pass.
+ *
+ * \return false: the pass is skipped; true: the pass runs.
*/
- TVM_DLL void Trace(const IRModule& module, const PassInfo& info, bool
is_before) const;
+ TVM_DLL bool InstrumentBeforePass(const IRModule& mod, const PassInfo& info)
const;
+
+ /*!
+ * \brief Call instrument implementations callbacks after a pass run.
+ * In order, if one raises exceptions, remaings will not be called.
Review comment:
see previous
##########
File path: tests/python/relay/test_pass_manager.py
##########
@@ -559,15 +569,20 @@ def test_print_debug_callback():
]
)
- assert __TRACE_COUNTER__ == 0
mod = tvm.IRModule({"main": func})
- with tvm.transform.PassContext(opt_level=3, trace=_tracer):
+ pass_counter = PassCounter()
+ with tvm.transform.PassContext(opt_level=3, instruments=[pass_counter]):
+ # Should be reseted when entering pass context
+ assert pass_counter.get_counts() == 0
mod = seq(mod)
- # TODO(@jroesch): when we remove new fn pass behavior we need to remove
- # change this back to 3
- assert __TRACE_COUNTER__ == 5
+ # TODO(@jroesch): when we remove new fn pass behavior we need to remove
+ # change this back to match correct behavior
+ assert pass_counter.get_counts() == 6
Review comment:
how come this number changed?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]