tvm
|
A builder to build Relax binding blocks. More...
#include <block_builder.h>
Public Member Functions | |
virtual NameSupply | name_supply ()=0 |
Get the name supply for generating unique names. More... | |
virtual IRModule | GetContextIRModule () const =0 |
Get the context IRModule in this builder. More... | |
virtual IRModule | Finalize ()=0 |
Finalize the building process and return the result IRModule. Possibly rename GlobalVars in the IRModule to ensure name uniqueness and the invariant: every public function has the same name as its "global_symbol" attribute. More... | |
virtual GlobalVar | AddFunction (const BaseFunc &func, String func_name_hint)=0 |
Add a Relax function or a TIR PrimFunc to internal context module. More... | |
virtual void | UpdateFunction (const GlobalVar &gv, BaseFunc function)=0 |
Update a Relax function or a TIR PrimFunc in the internal context module. More... | |
virtual void | ReportFatal (const Diagnostic &diagnostic)=0 |
Report an error during transformation construction. More... | |
virtual Optional< Expr > | LookupBinding (const Var &var)=0 |
Lookup the binding value that var binds to in the current emitted sequences. More... | |
virtual void | BeginScope (Optional< Array< Var >> params)=0 |
Begin a new scope, with optional parameters that are visible within the scope. More... | |
virtual void | BeginInnerScope ()=0 |
Begin a new scope, which inherits visible parameters from its parent scope. More... | |
virtual void | AddDefinitionToScope (Var var)=0 |
Append a definition to the current scope. More... | |
virtual void | EndScope ()=0 |
End the previously defined scope. More... | |
virtual void | BeginDataflowBlock ()=0 |
Begin to build a DataflowBlock. More... | |
virtual void | BeginBindingBlock ()=0 |
Begin to build a BindingBlock. More... | |
virtual BindingBlock | EndBlock ()=0 |
End building a BindingBlock. More... | |
virtual bool | CurrentBlockIsDataFlow ()=0 |
Check if the block being built is DataflowBlock or not. More... | |
virtual Var | Emit (Expr expr, String name_hint="")=0 |
Emits an Expr, and returns the variable it is bound to. More... | |
virtual Var | EmitMatchCast (Expr value, StructInfo struct_info, String name_hint="")=0 |
Emit a MatchCast. More... | |
virtual Var | EmitOutput (Expr output, String name_hint="")=0 |
Generate an output for the current dataflow block. More... | |
virtual void | EmitNormalized (Binding normalized_binding)=0 |
Emit a binding that is already normalized. More... | |
virtual Expr | Normalize (const Expr &expr)=0 |
Convert an expression to normal form, and try to eagerly infer types and shapes. More... | |
virtual Expr | NormalizeArgument (const Expr &expr)=0 |
Normalize argument to a call or another IRNode. More... | |
virtual arith::Analyzer * | GetAnalyzer ()=0 |
Get the analyzer of the BlockBuilder. More... | |
TVM_DECLARE_BASE_OBJECT_INFO (BlockBuilderNode, Object) | |
Public Member Functions inherited from tvm::runtime::Object | |
uint32_t | type_index () const |
std::string | GetTypeKey () const |
size_t | GetTypeKeyHash () const |
template<typename TargetType > | |
bool | IsInstance () const |
bool | unique () const |
Object () | |
Object (const Object &other) | |
Object (Object &&other) | |
Object & | operator= (const Object &other) |
Object & | operator= (Object &&other) |
Static Public Attributes | |
static constexpr const uint32_t | _type_index = TypeIndex::kDynamic |
static constexpr const char * | _type_key = "relax.BlockBuilder" |
Static Public Attributes inherited from tvm::runtime::Object | |
static constexpr const char * | _type_key = "runtime.Object" |
static constexpr bool | _type_final = false |
static constexpr uint32_t | _type_child_slots = 0 |
static constexpr bool | _type_child_slots_can_overflow = true |
static constexpr bool | _type_has_method_visit_attrs = true |
static constexpr bool | _type_has_method_sequal_reduce = false |
static constexpr bool | _type_has_method_shash_reduce = false |
static constexpr uint32_t | _type_index = TypeIndex::kDynamic |
Additional Inherited Members | |
Public Types inherited from tvm::runtime::Object | |
typedef void(* | FDeleter) (Object *self) |
Object deleter. More... | |
using | RefCounterType = std::atomic< int32_t > |
Static Public Member Functions inherited from tvm::runtime::Object | |
static std::string | TypeIndex2Key (uint32_t tindex) |
Get the type key of the corresponding index from runtime. More... | |
static size_t | TypeIndex2KeyHash (uint32_t tindex) |
Get the type key hash of the corresponding index from runtime. More... | |
static uint32_t | TypeKey2Index (const std::string &key) |
Get the type index of the corresponding key from runtime. More... | |
static uint32_t | _GetOrAllocRuntimeTypeIndex () |
static uint32_t | RuntimeTypeIndex () |
Protected Member Functions inherited from tvm::runtime::Object | |
void | IncRef () |
developer function, increases reference counter. More... | |
void | DecRef () |
developer function, decrease reference counter. More... | |
Static Protected Member Functions inherited from tvm::runtime::Object | |
static uint32_t | GetOrAllocRuntimeTypeIndex (const std::string &key, uint32_t static_tindex, uint32_t parent_tindex, uint32_t type_child_slots, bool type_child_slots_can_overflow) |
Get the type index using type key. More... | |
Protected Attributes inherited from tvm::runtime::Object | |
uint32_t | type_index_ {0} |
Type index(tag) that indicates the type of the object. More... | |
RefCounterType | ref_counter_ {0} |
The internal reference counter. More... | |
FDeleter | deleter_ = nullptr |
deleter of this object to enable customized allocation. If the deleter is nullptr, no deletion will be performed. The creator of the object must always set the deleter field properly. More... | |
A builder to build Relax binding blocks.
BlockBuilder provides the following three categories of main functionalities for IR building and transformations:
Importantly, these three categories of features can be dependent on each other. For example, when we emit into scope we will call normalize to ensure the code is in normal form. Similarly, when we normalize we could choose to emit into the current context.
We would encourage the developers to keep these three category in mind when using and developing BlockBuilder, we can group the code in a logically clean way.
BlockBuilderNode is implemented as a virtual interface to allow logically grouped implementation and internal data structures that are hidden from the users.
|
pure virtual |
Append a definition to the current scope.
var | A variable within the current scope. |
|
pure virtual |
Begin to build a BindingBlock.
|
pure virtual |
Begin to build a DataflowBlock.
|
pure virtual |
Begin a new scope, which inherits visible parameters from its parent scope.
Symbolic variables from the parent scope are available.
|
pure virtual |
Begin a new scope, with optional parameters that are visible within the scope.
Symbolic variables from the parent scope are not available.
params | Parameters that are visible within the scope. |
|
pure virtual |
Check if the block being built is DataflowBlock or not.
Emits an Expr, and returns the variable it is bound to.
expr | The Expr to be emitted. |
name_hint | Name hint for the bound variable. |
expr
is bound to.expr
, and performs shape and type deductions by calling Normalize.
|
pure virtual |
|
pure virtual |
Emit a binding that is already normalized.
normalized_binding | A binding whose value is already normalized. |
|
pure virtual |
Generate an output for the current dataflow block.
output | The output variable of the block. |
name_hint | Name hint for the bound variable. |
output
.
|
pure virtual |
End building a BindingBlock.
|
pure virtual |
End the previously defined scope.
|
pure virtual |
Finalize the building process and return the result IRModule. Possibly rename GlobalVars in the IRModule to ensure name uniqueness and the invariant: every public function has the same name as its "global_symbol" attribute.
|
pure virtual |
Get the analyzer of the BlockBuilder.
|
pure virtual |
Lookup the binding value that var binds to in the current emitted sequences.
var | The input var. |
var
.
|
pure virtual |
Get the name supply for generating unique names.
Convert an expression to normal form, and try to eagerly infer types and shapes.
expr | The input expression. |
Normalize argument to a call or another IRNode.
expr | The input expression. |
|
pure virtual |
Report an error during transformation construction.
diagnostic | The diagnostic information. |
tvm::relax::BlockBuilderNode::TVM_DECLARE_BASE_OBJECT_INFO | ( | BlockBuilderNode | , |
Object | |||
) |
|
pure virtual |
Update a Relax function or a TIR PrimFunc in the internal context module.
gv | The global var referring the function to be updated. |
function | The updated function. |
|
staticconstexpr |
|
staticconstexpr |