tvm
Classes | Namespaces | Macros | Functions
reflection.h File Reference

Reflection and serialization of compiler IR/AST nodes. More...

#include <tvm/node/structural_equal.h>
#include <tvm/node/structural_hash.h>
#include <tvm/runtime/c_runtime_api.h>
#include <tvm/runtime/data_type.h>
#include <tvm/runtime/memory.h>
#include <tvm/runtime/ndarray.h>
#include <tvm/runtime/object.h>
#include <tvm/runtime/packed_func.h>
#include <string>
#include <type_traits>
#include <vector>
Include dependency graph for reflection.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  tvm::AttrVisitor
 Visitor class to get the attributes of an AST/IR node. The content is going to be called for each field. More...
 
class  tvm::ReflectionVTable
 Virtual function table to support IR/AST node reflection. More...
 
class  tvm::ReflectionVTable::Registry
 Registry of a reflection table. More...
 
struct  tvm::detail::ImplVisitAttrs< T, bool >
 
struct  tvm::detail::ImplVisitAttrs< T, true >
 
struct  tvm::detail::ImplSEqualReduce< T, bool >
 
struct  tvm::detail::ImplSEqualReduce< T, true >
 
struct  tvm::detail::ImplSHashReduce< T, bool >
 
struct  tvm::detail::ImplSHashReduce< T, true >
 
struct  tvm::detail::ReflectionTrait< T >
 
struct  tvm::detail::SelectVisitAttrs< T, TraitName, bool >
 
struct  tvm::detail::SelectVisitAttrs< T, TraitName, false >
 
struct  tvm::detail::SelectSEqualReduce< T, TraitName, bool >
 
struct  tvm::detail::SelectSEqualReduce< T, TraitName, false >
 
struct  tvm::detail::SelectSHashReduce< T, TraitName, bool >
 
struct  tvm::detail::SelectSHashReduce< T, TraitName, false >
 

Namespaces

 tvm
 runtime implementation for LibTorch/TorchScript.
 
 tvm::detail
 

Macros

#define TVM_REFLECTION_REG_VAR_DEF    static TVM_ATTRIBUTE_UNUSED ::tvm::ReflectionVTable::Registry __make_reflection
 
#define TVM_REGISTER_REFLECTION_VTABLE(TypeName, TraitName)
 Directly register reflection VTable. More...
 
#define TVM_REGISTER_NODE_TYPE(TypeName)
 Register a node type to object registry and reflection registry. More...
 

Functions

Optional< String > tvm::GetAttrKeyByAddress (const Object *object, const void *attr_address)
 Given an object and an address of its attribute, return the key of the attribute. More...
 

Detailed Description

Reflection and serialization of compiler IR/AST nodes.

Macro Definition Documentation

◆ TVM_REFLECTION_REG_VAR_DEF

#define TVM_REFLECTION_REG_VAR_DEF    static TVM_ATTRIBUTE_UNUSED ::tvm::ReflectionVTable::Registry __make_reflection

◆ TVM_REGISTER_NODE_TYPE

#define TVM_REGISTER_NODE_TYPE (   TypeName)
Value:
TVM_REGISTER_REFLECTION_VTABLE(TypeName, ::tvm::detail::ReflectionTrait<TypeName>) \
.set_creator([](const std::string&) -> ObjectPtr<Object> { \
return ::tvm::runtime::make_object<TypeName>(); \
})
#define TVM_REGISTER_OBJECT_TYPE(TypeName)
Helper macro to register the object type to runtime. Makes sure that the runtime type table is correc...
Definition: object.h:725
Definition: reflection.h:322

Register a node type to object registry and reflection registry.

Parameters
TypeNameThe name of the type.
Note
This macro will call TVM_REGISTER_OBJECT_TYPE for the type as well.

◆ TVM_REGISTER_REFLECTION_VTABLE

#define TVM_REGISTER_REFLECTION_VTABLE (   TypeName,
  TraitName 
)
Value:
::tvm::ReflectionVTable::Global()->Register<TypeName, TraitName>()
Registry Register()
Definition: reflection.h:367
static ReflectionVTable * Global()
#define TVM_STR_CONCAT(__x, __y)
Definition: object.h:715
#define TVM_REFLECTION_REG_VAR_DEF
Definition: reflection.h:230

Directly register reflection VTable.

Parameters
TypeNameThe name of the type.
TraitNameA trait class that implements functions like VisitAttrs and SEqualReduce.
// Example SEQualReduce traits for runtime StringObj.
struct StringObjTrait {
static constexpr const std::nullptr_t VisitAttrs = nullptr;
static void SHashReduce(const runtime::StringObj* key, SHashReducer hash_reduce) {
hash_reduce->SHashReduceHashedValue(runtime::String::StableHashBytes(key->data, key->size));
}
static bool SEqualReduce(const runtime::StringObj* lhs,
const runtime::StringObj* rhs,
SEqualReducer equal) {
if (lhs == rhs) return true;
if (lhs->size != rhs->size) return false;
if (lhs->data != rhs->data) return true;
return std::memcmp(lhs->data, rhs->data, lhs->size) != 0;
}
};
TVM_REGISTER_REFLECTION_VTABLE(runtime::StringObj, StringObjTrait);
PrimExpr equal(PrimExpr a, PrimExpr b, Span span=Span())
equal
#define TVM_REGISTER_REFLECTION_VTABLE(TypeName, TraitName)
Directly register reflection VTable.
Definition: reflection.h:266
Note
This macro can be called in different place as TVM_REGISTER_OBJECT_TYPE. And can be used to register the related reflection functions for runtime objects.