Skip to content

Commit

Permalink
do
Browse files Browse the repository at this point in the history
  • Loading branch information
MarisaKirisame committed May 20, 2019
1 parent f3ac8bb commit ae86024
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions include/tvm/relay/pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,13 +472,29 @@ TVM_DLL tvm::Array<TypeVar> AllTypeVars(const Type& t, const Module& mod);
*/
TVM_DLL Expr DeadCodeElimination(const Expr& e);

inline pass::Pass DeadCodeEliminationPass() {
runtime::TypedPackedFunc<Function(Function, Module, pass::PassContext)> pass_func =
[=](Function f, Module m, pass::PassContext pc) {
return Downcast<Function>(DeadCodeElimination(f));
};
return pass::CreateFunctionPass(pass_func, 1, "dead_code_elimination", {});
}

/*!
* \brief Fold constant expressions.
* \param expr the expression to be optimized.
* \return The optimized expression.
*/
TVM_DLL Expr FoldConstant(const Expr& expr);

inline pass::Pass FoldConstantPass() {
runtime::TypedPackedFunc<Function(Function, Module, pass::PassContext)> pass_func =
[=](Function f, Module m, pass::PassContext pc) {
return Downcast<Function>(FoldConstant(f));
};
return pass::CreateFunctionPass(pass_func, 1, "fold_constant", {});
}

/*!
* \brief Fuse operations into expr into seperate functions.
* \param expr The expression.
Expand Down Expand Up @@ -561,6 +577,14 @@ inline pass::Pass ForwardRewritePass(const FForwardRewrite& rewrite_func,
*/
TVM_DLL Expr RewriteAnnotatedOps(const Expr& expr, int fallback_device);

inline pass::Pass RewriteAnnotatedOpsPass(int fallback_device) {
runtime::TypedPackedFunc<Function(Function, Module, pass::PassContext)> pass_func =
[=](Function f, Module m, pass::PassContext pc) {
return Downcast<Function>(RewriteAnnotatedOps(f, fallback_device));
};
return pass::CreateFunctionPass(pass_func, 1, "rewrite_annotated_ops", {});
}

/*!
* \brief Collect the device mapping information of each expression.
* \param expr The expression.
Expand Down Expand Up @@ -611,6 +635,14 @@ struct StructuralHash {
*/
TVM_DLL Expr ToANormalForm(const Expr& e, const Module& mod);

inline pass::Pass ToANormalFormPass() {
runtime::TypedPackedFunc<Function(Function, Module, pass::PassContext)> pass_func =
[=](Function f, Module m, pass::PassContext pc) {
return Downcast<Function>(ToANormalForm(f, m));
};
return pass::CreateFunctionPass(pass_func, 1, "to_a_normal_form", {});
}

/*! \brief Remove let binding and directly share via pointer instead.
*
* It will remove all let binding,
Expand All @@ -622,12 +654,29 @@ TVM_DLL Expr ToANormalForm(const Expr& e, const Module& mod);
*/
TVM_DLL Expr ToGraphNormalForm(const Expr& e);

inline pass::Pass ToGraphNormalFormPass() {
runtime::TypedPackedFunc<Function(Function, Module, pass::PassContext)> pass_func =
[=](Function f, Module m, pass::PassContext pc) {
return Downcast<Function>(ToGraphNormalForm(f));
};
return pass::CreateFunctionPass(pass_func, 1, "to_graph_normal_form", {});
}

/*! \brief Aggressive constant propagation/constant folding/inlining.
* It will do as much computation in compile time as possible.
* It has two benefit: remove runtime overhead, and allow more optimization (typically fusion).
* As a side effect, code size will explode.
*/
Expr PartialEval(const Expr& e);

inline pass::Pass PartialEvalPass() {
runtime::TypedPackedFunc<Function(Function, Module, pass::PassContext)> pass_func =
[=](Function f, Module m, pass::PassContext pc) {
return Downcast<Function>(PartialEval(f));
};
return pass::CreateFunctionPass(pass_func, 1, "partial_eval", {});
}

} // namespace relay
} // namespace tvm

Expand Down

0 comments on commit ae86024

Please sign in to comment.