Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Transform] Refactor LegalizeOps #128

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/tvm/relax/op_attr_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ using FInferStructInfo =
*/
using FCallPacked = String;

/*!
* \brief Legalizes an expression with another expression. This function will be
* invoked in Legalize pass. It is a target-dependent pass.
* \param bb The blockbuilder context.
* \param call The original call.
*/
using FLegalize = runtime::TypedPackedFunc<Expr(const BlockBuilder& bb, const Call& call)>;

/*!
* \brief Gradient for a specific op.
*
Expand Down
23 changes: 23 additions & 0 deletions include/tvm/relax/transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,29 @@ TVM_DLL Pass SplitCallTIRByPattern(Array<TIRPattern> patterns, FCodegen fcodegen
*/
TVM_DLL Pass SimplifyNormInference();

/*!
* \brief Legalize high-level operator calls in Relax functions to call_tir
* with corresponding low-level TIR PrimFuncs.
*
* For each high-level operator, we register the way of legalizing it as a
* function, which takes a context BlockBuilder and the Call being legalized
* as input, and returns the legalized call. Here the input BlockBuilder is
* mainly used for adding the PrimFunc created by call_te into the context
* IRModule.
*
* The legalization function for each operator is registered as an attribute (with
* attribute key `FLegalize`) of the operator.
*
* For customizability, the user can pass their own legalization by an optional customized map,
* with the key to be the operator name and value to be the legalization function.
* The default legalization function will be overridden by the customized one.
*
* \param cmap The customized operator legalization function map. The customized function
* will override the default one.
* \return The Pass.
*/
TVM_DLL Pass LegalizeOps(Optional<Map<String, PackedFunc>> cmap);

} // namespace transform
} // namespace relax
} // namespace tvm
Expand Down
1 change: 0 additions & 1 deletion python/tvm/relax/transform/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@

from .transform import *
from .fma_rewrite import *
from .legalize_ops import LegalizeOps
Loading