tvm
Public Member Functions | Public Attributes | Static Public Attributes | Friends | List of all members
tvm::IRModuleNode Class Reference

IRModule that holds functions and type definitions. More...

#include <module.h>

Inheritance diagram for tvm::IRModuleNode:
Collaboration diagram for tvm::IRModuleNode:

Public Member Functions

template<typename TObjectRef >
Optional< TObjectRef > GetAttr (const std::string &attr_key, Optional< TObjectRef > default_value=Optional< TObjectRef >(nullptr)) const
 Get a module attribute. More...
 
template<typename TObjectRef >
Optional< TObjectRef > GetAttr (const std::string &attr_key, TObjectRef default_value) const
 
DictAttrs GetAttrs () const
 Get the metadata attributes. More...
 
bool HasNonzeroAttr (const std::string &attr_key) const
 Check whether the module has an non-zero integer attr. More...
 
 IRModuleNode ()
 
void VisitAttrs (AttrVisitor *v)
 
bool SEqualReduce (const IRModuleNode *other, SEqualReducer equal) const
 
void SHashReduce (SHashReducer hash_reduce) const
 
void Add (const GlobalVar &var, const BaseFunc &func, bool update=false)
 Add a function to the global environment. More...
 
void AddUnchecked (const GlobalVar &var, const BaseFunc &func)
 Add a function to the global environment. More...
 
void AddTypeDef (const GlobalTypeVar &var, const TypeData &type, bool update=false)
 Add a type-level definition to the global environment. More...
 
void AddTypeDefUnchecked (const GlobalTypeVar &var, const TypeData &type, bool update=false)
 Add a type-level definition to the global environment. More...
 
void Update (const GlobalVar &var, const BaseFunc &func)
 Update a function in the global environment. More...
 
void UpdateTypeDef (const GlobalTypeVar &var, const TypeData &type)
 Update a type definition in the global environment. More...
 
void UpdateGlobalInfo (const String &name, const Array< GlobalInfo > &info)
 Update an array of global infos in the global environment. More...
 
void Remove (const GlobalVar &var)
 Remove a function from the global environment. More...
 
bool ContainGlobalVar (const String &name) const
 Check if the global_var_map_ contains a global variable. More...
 
bool ContainGlobalTypeVar (const String &name) const
 Check if the global_type_var_map_ contains a global type variable. More...
 
GlobalVar GetGlobalVar (const String &str) const
 Lookup a global function by its variable. More...
 
Array< GlobalVarGetGlobalVars () const
 Collect all global vars defined in this module, ordered by the global variable name. More...
 
GlobalTypeVar GetGlobalTypeVar (const String &str) const
 Look up a global function by its name. More...
 
Array< GlobalTypeVarGetGlobalTypeVars () const
 Collect all global type vars defined in this module. More...
 
Constructor GetConstructor (const String &adt, const String &cons) const
 Find constructor of ADT using name. More...
 
BaseFunc Lookup (const GlobalVar &var) const
 Look up a global function by its variable. More...
 
BaseFunc Lookup (const String &name) const
 Look up a global function by its string name. More...
 
TypeData LookupTypeDef (const GlobalTypeVar &var) const
 Look up a global type definition by its variable. More...
 
TypeData LookupTypeDef (const String &var) const
 Look up a global type definition by its name. More...
 
Constructor LookupTag (const int32_t tag)
 Look up a constructor by its tag. More...
 
void Update (const IRModule &other)
 Update the functions inside this environment by functions in another environment. More...
 
IRModule ShallowCopy ()
 Create a shallow copy of this IRModule. More...
 
void Import (const String &path)
 Import Relay code from the file at path. More...
 
void ImportFromStd (const String &path)
 Import Relay code from the file at path, relative to the standard library. More...
 
std::unordered_set< StringImports () const
 The set of imported files. More...
 
 TVM_OBJECT_ENABLE_SCRIPT_PRINTER ()
 
 TVM_DECLARE_FINAL_OBJECT_INFO (IRModuleNode, 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)
 
Objectoperator= (const Object &other)
 
Objectoperator= (Object &&other)
 

Public Attributes

Map< GlobalVar, BaseFuncfunctions
 A map from ids to all global functions. More...
 
Map< GlobalTypeVar, TypeDatatype_definitions
 A map from global type vars to ADT type data. More...
 
SourceMap source_map
 The source map for the module. More...
 
DictAttrs attrs
 
Map< String, Array< GlobalInfo > > global_infos
 Globally static object that are referred by the IR itself. More...
 
Map< String, GlobalVarglobal_var_map_
 A map from string names to global variables that ensures global uniqueness. More...
 
Map< String, GlobalTypeVarglobal_type_var_map_
 A map from string names to global type variables (ADT names) that ensures global uniqueness. More...
 
std::unordered_map< int32_t, Constructorconstructor_tag_map_
 A map from constructor tags to constructor objects for convenient access. More...
 
std::unordered_set< Stringimport_set_
 The files previously imported, required to ensure importing is idempotent for each module. More...
 

Static Public Attributes

static constexpr const char * _type_key = "IRModule"
 
static constexpr const bool _type_has_method_sequal_reduce = true
 
static constexpr const bool _type_has_method_shash_reduce = true
 
- 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
 

Friends

class IRModule
 The IRModule declaration statement. More...
 

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...
 

Detailed Description

IRModule that holds functions and type definitions.

IRModule is the basic unit for all IR transformations across the stack.

Many operations require access to the global IRModule. We pass the IRModule by value in a functional style as an explicit argument, but we mutate the Module while optimizing programs.

See also
IRModule

Constructor & Destructor Documentation

◆ IRModuleNode()

tvm::IRModuleNode::IRModuleNode ( )
inline

Member Function Documentation

◆ Add()

void tvm::IRModuleNode::Add ( const GlobalVar var,
const BaseFunc func,
bool  update = false 
)

Add a function to the global environment.

Parameters
varThe var of the global function.
funcThe function.
updateControls whether you can replace a definition in the environment.

◆ AddTypeDef()

void tvm::IRModuleNode::AddTypeDef ( const GlobalTypeVar var,
const TypeData type,
bool  update = false 
)

Add a type-level definition to the global environment.

Parameters
varThe var of the global type definition.
typeThe ADT.
updateControls whether you can replace a definition in the environment.

◆ AddTypeDefUnchecked()

void tvm::IRModuleNode::AddTypeDefUnchecked ( const GlobalTypeVar var,
const TypeData type,
bool  update = false 
)

Add a type-level definition to the global environment.

Parameters
varThe var of the global type definition.
typeThe ADT.
updateControls whether you can replace a definition in the environment.

It does not do type checking as AddTypeDef does.

◆ AddUnchecked()

void tvm::IRModuleNode::AddUnchecked ( const GlobalVar var,
const BaseFunc func 
)

Add a function to the global environment.

Parameters
varThe name of the global function.
funcThe function.

It does not do type inference as Add does.

◆ ContainGlobalTypeVar()

bool tvm::IRModuleNode::ContainGlobalTypeVar ( const String name) const

Check if the global_type_var_map_ contains a global type variable.

Parameters
nameThe variable name.
Returns
true if contains, otherise false.

◆ ContainGlobalVar()

bool tvm::IRModuleNode::ContainGlobalVar ( const String name) const

Check if the global_var_map_ contains a global variable.

Parameters
nameThe variable name.
Returns
true if contains, otherise false.

◆ GetAttr() [1/2]

template<typename TObjectRef >
Optional<TObjectRef> tvm::IRModuleNode::GetAttr ( const std::string &  attr_key,
Optional< TObjectRef >  default_value = Optional<TObjectRef>(nullptr) 
) const
inline

Get a module attribute.

Parameters
attr_keyThe attribute key.
default_valueThe default value if the key does not exist, defaults to nullptr.
Returns
The result
Template Parameters
TOBjectRefthe expected object type.
Exceptions
Errorif the key exists but the value does not match TObjectRef
void GetAttrExample(const IRModule& mod) {
auto value = f->GetAttr<Integer>("AttrKey", 0);
}
friend class IRModule
The IRModule declaration statement.
Definition: module.h:359
tvm::PrimExpr mod(const tvm::PrimExpr &a, const tvm::PrimExpr &b)
Definition: broadcast.h:290

◆ GetAttr() [2/2]

template<typename TObjectRef >
Optional<TObjectRef> tvm::IRModuleNode::GetAttr ( const std::string &  attr_key,
TObjectRef  default_value 
) const
inline

◆ GetAttrs()

DictAttrs tvm::IRModuleNode::GetAttrs ( ) const
inline

Get the metadata attributes.

Returns
The additional meta-data attributes

◆ GetConstructor()

Constructor tvm::IRModuleNode::GetConstructor ( const String adt,
const String cons 
) const

Find constructor of ADT using name.

Parameters
adtname of the ADT the constructor belongs to
consname of the constructor
Returns
Constructor of ADT, error if not found

◆ GetGlobalTypeVar()

GlobalTypeVar tvm::IRModuleNode::GetGlobalTypeVar ( const String str) const

Look up a global function by its name.

Parameters
strThe unique string specifying the global variable.
Returns
The global variable.

◆ GetGlobalTypeVars()

Array<GlobalTypeVar> tvm::IRModuleNode::GetGlobalTypeVars ( ) const

Collect all global type vars defined in this module.

Returns
An array of global type vars

◆ GetGlobalVar()

GlobalVar tvm::IRModuleNode::GetGlobalVar ( const String str) const

Lookup a global function by its variable.

Parameters
strThe unique string specifying the global variable.
Returns
The global variable.

◆ GetGlobalVars()

Array<GlobalVar> tvm::IRModuleNode::GetGlobalVars ( ) const

Collect all global vars defined in this module, ordered by the global variable name.

Returns
An array of global vars

◆ HasNonzeroAttr()

bool tvm::IRModuleNode::HasNonzeroAttr ( const std::string &  attr_key) const
inline

Check whether the module has an non-zero integer attr.

This function can be used to check whether an optional attribute mark(e.g. inline) exists.

Parameters
attr_keyThe key to the attribute.
Returns
The check result.
void HasNonzeroAttrExample(const IRModule& mod) {
if (mod->HasNonzeroAttr(attr::kInline)) {
// inline the function.
}
}
constexpr const char * kInline
Mark the function to be inlined.
Definition: function.h:193

◆ Import()

void tvm::IRModuleNode::Import ( const String path)

Import Relay code from the file at path.

Parameters
pathThe path of the Relay code to import.
Note
The path resolution behavior is standard, if abosolute will be the absolute file, if relative it will be resovled against the current working directory.

◆ ImportFromStd()

void tvm::IRModuleNode::ImportFromStd ( const String path)

Import Relay code from the file at path, relative to the standard library.

Parameters
pathThe path of the Relay code to import.

◆ Imports()

std::unordered_set<String> tvm::IRModuleNode::Imports ( ) const

The set of imported files.

◆ Lookup() [1/2]

BaseFunc tvm::IRModuleNode::Lookup ( const GlobalVar var) const

Look up a global function by its variable.

Parameters
varThe global var to lookup.
Returns
The function named by the variable argument.

◆ Lookup() [2/2]

BaseFunc tvm::IRModuleNode::Lookup ( const String name) const

Look up a global function by its string name.

Parameters
nameThe name of the function.
Returns
The function named by the argument.

◆ LookupTag()

Constructor tvm::IRModuleNode::LookupTag ( const int32_t  tag)

Look up a constructor by its tag.

Parameters
tagThe tag for the constructor.
Returns
The constructor object.

◆ LookupTypeDef() [1/2]

TypeData tvm::IRModuleNode::LookupTypeDef ( const GlobalTypeVar var) const

Look up a global type definition by its variable.

Parameters
varThe var of the global type definition.
Returns
The type definition.

◆ LookupTypeDef() [2/2]

TypeData tvm::IRModuleNode::LookupTypeDef ( const String var) const

Look up a global type definition by its name.

Parameters
varThe name of the global type definition.
Returns
The type definition.

◆ Remove()

void tvm::IRModuleNode::Remove ( const GlobalVar var)

Remove a function from the global environment.

Parameters
varThe name of the global function to update.

◆ SEqualReduce()

bool tvm::IRModuleNode::SEqualReduce ( const IRModuleNode other,
SEqualReducer  equal 
) const

◆ ShallowCopy()

IRModule tvm::IRModuleNode::ShallowCopy ( )

Create a shallow copy of this IRModule.

Returns
The shallow copy of the IRModule.

◆ SHashReduce()

void tvm::IRModuleNode::SHashReduce ( SHashReducer  hash_reduce) const

◆ TVM_DECLARE_FINAL_OBJECT_INFO()

tvm::IRModuleNode::TVM_DECLARE_FINAL_OBJECT_INFO ( IRModuleNode  ,
Object   
)

◆ TVM_OBJECT_ENABLE_SCRIPT_PRINTER()

tvm::IRModuleNode::TVM_OBJECT_ENABLE_SCRIPT_PRINTER ( )

◆ Update() [1/2]

void tvm::IRModuleNode::Update ( const GlobalVar var,
const BaseFunc func 
)

Update a function in the global environment.

Parameters
varThe name of the global function to update.
funcThe new function.

◆ Update() [2/2]

void tvm::IRModuleNode::Update ( const IRModule other)

Update the functions inside this environment by functions in another environment.

Parameters
otherThe other environment.

◆ UpdateGlobalInfo()

void tvm::IRModuleNode::UpdateGlobalInfo ( const String name,
const Array< GlobalInfo > &  info 
)

Update an array of global infos in the global environment.

Parameters
nameThe name of the global info.
infoThe new array of global infos.

◆ UpdateTypeDef()

void tvm::IRModuleNode::UpdateTypeDef ( const GlobalTypeVar var,
const TypeData type 
)

Update a type definition in the global environment.

Parameters
varThe name of the global type definition to update.
typeThe new ADT.

◆ VisitAttrs()

void tvm::IRModuleNode::VisitAttrs ( AttrVisitor v)
inline

Friends And Related Function Documentation

◆ IRModule

friend class IRModule
friend

The IRModule declaration statement.

Returns
The IRModuleFrame.

Member Data Documentation

◆ _type_has_method_sequal_reduce

constexpr const bool tvm::IRModuleNode::_type_has_method_sequal_reduce = true
staticconstexpr

◆ _type_has_method_shash_reduce

constexpr const bool tvm::IRModuleNode::_type_has_method_shash_reduce = true
staticconstexpr

◆ _type_key

constexpr const char* tvm::IRModuleNode::_type_key = "IRModule"
staticconstexpr

◆ attrs

DictAttrs tvm::IRModuleNode::attrs

◆ constructor_tag_map_

std::unordered_map<int32_t, Constructor> tvm::IRModuleNode::constructor_tag_map_

A map from constructor tags to constructor objects for convenient access.

◆ functions

Map<GlobalVar, BaseFunc> tvm::IRModuleNode::functions

A map from ids to all global functions.

◆ global_infos

Map<String, Array<GlobalInfo> > tvm::IRModuleNode::global_infos

Globally static object that are referred by the IR itself.

◆ global_type_var_map_

Map<String, GlobalTypeVar> tvm::IRModuleNode::global_type_var_map_

A map from string names to global type variables (ADT names) that ensures global uniqueness.

◆ global_var_map_

Map<String, GlobalVar> tvm::IRModuleNode::global_var_map_

A map from string names to global variables that ensures global uniqueness.

◆ import_set_

std::unordered_set<String> tvm::IRModuleNode::import_set_

The files previously imported, required to ensure importing is idempotent for each module.

◆ source_map

SourceMap tvm::IRModuleNode::source_map

The source map for the module.

◆ type_definitions

Map<GlobalTypeVar, TypeData> tvm::IRModuleNode::type_definitions

A map from global type vars to ADT type data.


The documentation for this class was generated from the following file: