base class of all object containers.
More...
#include <object.h>
Inherited by tvm::AffineTypeNode, tvm::arith::ConstIntBoundNode, tvm::arith::IntConstraintsNode, tvm::arith::IntConstraintsTransformNode, tvm::arith::IntGroupBoundsNode, tvm::arith::IntSetNode, tvm::arith::IterMapResultNode, tvm::arith::IterMarkNode, tvm::arith::ModularSetNode, tvm::AttrFieldInfoNode, tvm::auto_scheduler::AccessAnalyzerNode, tvm::auto_scheduler::AttachMapNode, tvm::auto_scheduler::BuildResultNode, tvm::auto_scheduler::ComputeDAGNode, tvm::auto_scheduler::CostModelNode, tvm::auto_scheduler::HardwareParamsNode, tvm::auto_scheduler::IteratorNode, tvm::auto_scheduler::MeasureCallbackNode, tvm::auto_scheduler::MeasureInputNode, tvm::auto_scheduler::MeasureResultNode, tvm::auto_scheduler::ProgramBuilderNode, tvm::auto_scheduler::ProgramMeasurerNode, tvm::auto_scheduler::ProgramRunnerNode, tvm::auto_scheduler::RecordReaderNode, tvm::auto_scheduler::SearchCallbackNode, tvm::auto_scheduler::SearchPolicyNode, tvm::auto_scheduler::SearchTaskNode, tvm::auto_scheduler::StageNode, tvm::auto_scheduler::StateNode, tvm::auto_scheduler::StepNode, tvm::auto_scheduler::TuningOptionsNode, tvm::BaseAttrsNode, tvm::BaseExprNode, tvm::CompilationConfigNode, tvm::ConstantInfoNode, tvm::ConstantMemoryPoolsNode, tvm::DiagnosticContextNode, tvm::DiagnosticNode, tvm::DiagnosticRendererNode, tvm::EnvFuncNode, tvm::GenericFuncNode, tvm::GlobalVarSupplyNode, tvm::instrument::PassInstrumentNode, tvm::IRModuleNode, tvm::MemoryInfoNode, tvm::meta_schedule::ArgInfoNode, tvm::meta_schedule::BuilderInputNode, tvm::meta_schedule::BuilderNode, tvm::meta_schedule::BuilderResultNode, tvm::meta_schedule::CostModelNode, tvm::meta_schedule::DatabaseNode, tvm::meta_schedule::ExtractedTaskNode, tvm::meta_schedule::FeatureExtractorNode, tvm::meta_schedule::MeasureCallbackNode, tvm::meta_schedule::MeasureCandidateNode, tvm::meta_schedule::MutatorNode, tvm::meta_schedule::PostprocNode, tvm::meta_schedule::ProfilerNode, tvm::meta_schedule::RunnerFutureNode, tvm::meta_schedule::RunnerInputNode, tvm::meta_schedule::RunnerNode, tvm::meta_schedule::RunnerResultNode, tvm::meta_schedule::ScheduleRuleNode, tvm::meta_schedule::SearchStrategyNode, tvm::meta_schedule::SpaceGeneratorNode, tvm::meta_schedule::TaskRecordNode, tvm::meta_schedule::TaskSchedulerNode, tvm::meta_schedule::TuneContextNode, tvm::meta_schedule::TuningRecordNode, tvm::meta_schedule::WorkloadNode, tvm::NameSupplyNode, tvm::ObjectPathNode, tvm::ObjectPathPairNode, tvm::PoolInfoNode, tvm::PoolInfoPropertiesNode, tvm::PrinterConfigNode, tvm::RangeNode, tvm::relay::ClauseNode, tvm::relay::ConstructorValueObj, tvm::relay::DFPatternCallbackNode, tvm::relay::DFPatternNode, tvm::relay::ExecutorNode, tvm::relay::IdNode, tvm::relay::OpImplementationNode, tvm::relay::OpSpecializationNode, tvm::relay::OpStrategyNode, tvm::relay::RecClosureObj, tvm::relay::RefValueObj, tvm::relay::RelayNode, tvm::relay::RuntimeNode, tvm::runtime::ADTObj, tvm::runtime::ArrayNode, tvm::runtime::ClosureObj, tvm::runtime::MapNode, tvm::runtime::metadata::MetadataBaseNode, tvm::runtime::ModuleNode, tvm::runtime::NDArray::Container, tvm::runtime::PackedFuncObj, tvm::runtime::profiling::CountNode, tvm::runtime::profiling::DeviceWrapperNode, tvm::runtime::profiling::DurationNode, tvm::runtime::profiling::MetricCollectorNode, tvm::runtime::profiling::PercentNode, tvm::runtime::profiling::RatioNode, tvm::runtime::profiling::ReportNode, tvm::runtime::ShapeTupleObj, tvm::runtime::StringObj, tvm::runtime::TimerNode, tvm::runtime::vm::StorageObj, tvm::script::ir_builder::IRBuilderFrameNode, tvm::script::ir_builder::IRBuilderNode, tvm::script::printer::DocNode, tvm::script::printer::FrameNode, tvm::script::printer::IRDocsifierNode, tvm::SourceMapNode, tvm::SourceNameNode, tvm::SourceNode, tvm::SpanNode, tvm::TargetKindNode, tvm::TargetNode, tvm::TargetTagNode, tvm::te::IterVarAttrNode, tvm::te::IterVarRelationNode, tvm::te::OperationNode, tvm::te::ScheduleNode, tvm::te::SpecializedConditionNode, tvm::te::StageNode, tvm::te::TensorIntrinCallNode, tvm::te::TensorIntrinNode, tvm::tir::BijectiveLayoutNode, tvm::tir::BlockRVNode, tvm::tir::BlockScopeNode, tvm::tir::BufferNode, tvm::tir::BufferRegionNode, tvm::tir::CommReducerNode, tvm::tir::DataProducerNode, tvm::tir::DependencyNode, tvm::tir::IndexMapNode, tvm::tir::InstructionKindNode, tvm::tir::InstructionNode, tvm::tir::IterVarNode, tvm::tir::LayoutNode, tvm::tir::LoopRVNode, tvm::tir::MatchBufferRegionNode, tvm::tir::ScheduleNode, tvm::tir::ScheduleStateNode, tvm::tir::StmtNode, tvm::tir::StmtSRefNode, tvm::tir::TensorIntrinNode, tvm::tir::TraceNode, tvm::tir::usmp::AllocatedPoolInfoNode, tvm::tir::usmp::BufferInfoAnalysisNode, tvm::tir::usmp::BufferInfoNode, tvm::tir::usmp::PoolAllocationNode, tvm::transform::PassContextNode, tvm::transform::PassInfoNode, tvm::transform::PassNode, tvm::TypeNode, tvm::TypeReporterNode, and tvm::WorkspaceMemoryPoolsNode.
|
void | IncRef () |
| developer function, increases reference counter. More...
|
|
void | DecRef () |
| developer function, decrease reference counter. More...
|
|
|
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...
|
|
base class of all object containers.
Sub-class of objects should declare the following static constexpr fields:
- _type_index: Static type index of the object, if assigned to TypeIndex::kDynamic the type index will be assigned during runtime. Runtime type index can be accessed by ObjectType::TypeIndex();
- _type_key: The unique string identifier of the type.
- _type_final: Whether the type is terminal type(there is no subclass of the type in the object system). This field is automatically set by macro TVM_DECLARE_FINAL_OBJECT_INFO It is still OK to sub-class a terminal object type T and construct it using make_object. But IsInstance check will only show that the object type is T(instead of the sub-class).
The following two fields are necessary for base classes that can be sub-classed.
- _type_child_slots: Number of reserved type index slots for child classes. Used for runtime optimization for type checking in IsInstance. If an object's type_index is within range of [type_index, type_index + _type_child_slots] Then the object can be quickly decided as sub-class of the current object class. If not, a fallback mechanism is used to check the global type table. Recommendation: set to estimate number of children needed.
- _type_child_slots_can_overflow: Whether we can add additional child classes even if the number of child classes exceeds the _type_child_slots. A fallback mechanism to check global type table will be used. Recommendation: set to false for optimal runtime speed if we know exact number of children.
Two macros are used to declare helper functions in the object:
- Use TVM_DECLARE_BASE_OBJECT_INFO for object classes that can be sub-classed.
- Use TVM_DECLARE_FINAL_OBJECT_INFO for object classes that cannot be sub-classed.
New objects can be created using make_object function. Which will automatically populate the type_index and deleter of the object.
- See also
- make_object
-
ObjectPtr
-
ObjectRef
class BaseObj :
public Object {
public:
int field0;
static constexpr
const char*
_type_key =
"test.BaseObj";
};
class LeafObj : public BaseObj {
public:
int child_field0;
static constexpr
const char*
_type_key =
"test.LeafObj";
};
void TestObjects() {
ObjectRef leaf_ref(make_object<LeafObj>());
const LeafObj* leaf_ptr = leaf_ref.as<LeafObj>();
ICHECK(leaf_ptr != nullptr);
ICHECK(leaf_ref.as<BaseObj>() != nullptr);
}
◆ FDeleter
typedef void(* tvm::runtime::Object::FDeleter) (Object *self) |
◆ RefCounterType
◆ Object() [1/3]
tvm::runtime::Object::Object |
( |
| ) |
|
|
inline |
◆ Object() [2/3]
tvm::runtime::Object::Object |
( |
const Object & |
other | ) |
|
|
inline |
◆ Object() [3/3]
tvm::runtime::Object::Object |
( |
Object && |
other | ) |
|
|
inline |
◆ _GetOrAllocRuntimeTypeIndex()
static uint32_t tvm::runtime::Object::_GetOrAllocRuntimeTypeIndex |
( |
| ) |
|
|
inlinestatic |
◆ DecRef()
void tvm::runtime::Object::DecRef |
( |
| ) |
|
|
inlineprotected |
developer function, decrease reference counter.
- Note
- The deleter will be called when ref_counter_ becomes zero.
◆ GetOrAllocRuntimeTypeIndex()
static uint32_t tvm::runtime::Object::GetOrAllocRuntimeTypeIndex |
( |
const std::string & |
key, |
|
|
uint32_t |
static_tindex, |
|
|
uint32_t |
parent_tindex, |
|
|
uint32_t |
type_child_slots, |
|
|
bool |
type_child_slots_can_overflow |
|
) |
| |
|
staticprotected |
Get the type index using type key.
When the function is first time called for a type, it will register the type to the type table in the runtime. If the static_tindex is TypeIndex::kDynamic, the function will allocate a runtime type index. Otherwise, we will populate the type table and return the static index.
- Parameters
-
key | the type key. |
static_tindex | The current _type_index field. can be TypeIndex::kDynamic. |
parent_tindex | The index of the parent. |
type_child_slots | Number of slots reserved for its children. |
type_child_slots_can_overflow | Whether to allow child to overflow the slots. |
- Returns
- The allocated type index.
◆ GetTypeKey()
std::string tvm::runtime::Object::GetTypeKey |
( |
| ) |
const |
|
inline |
- Returns
- the type key of the object.
- Note
- this operation is expensive, can be used for error reporting.
◆ GetTypeKeyHash()
size_t tvm::runtime::Object::GetTypeKeyHash |
( |
| ) |
const |
|
inline |
- Returns
- A hash value of the return of GetTypeKey.
◆ IncRef()
void tvm::runtime::Object::IncRef |
( |
| ) |
|
|
inlineprotected |
developer function, increases reference counter.
◆ IsInstance()
template<typename TargetType >
bool tvm::runtime::Object::IsInstance |
( |
| ) |
const |
|
inline |
Check if the object is an instance of TargetType.
- Template Parameters
-
TargetType | The target type to be checked. |
- Returns
- Whether the target type is true.
◆ operator=() [1/2]
Object& tvm::runtime::Object::operator= |
( |
const Object & |
other | ) |
|
|
inline |
◆ operator=() [2/2]
◆ RuntimeTypeIndex()
static uint32_t tvm::runtime::Object::RuntimeTypeIndex |
( |
| ) |
|
|
inlinestatic |
◆ type_index()
uint32_t tvm::runtime::Object::type_index |
( |
| ) |
const |
|
inline |
- Returns
- The internal runtime type index of the object.
◆ TypeIndex2Key()
static std::string tvm::runtime::Object::TypeIndex2Key |
( |
uint32_t |
tindex | ) |
|
|
static |
Get the type key of the corresponding index from runtime.
- Parameters
-
- Returns
- the result.
◆ TypeIndex2KeyHash()
static size_t tvm::runtime::Object::TypeIndex2KeyHash |
( |
uint32_t |
tindex | ) |
|
|
static |
Get the type key hash of the corresponding index from runtime.
- Parameters
-
- Returns
- the related key-hash.
◆ TypeKey2Index()
static uint32_t tvm::runtime::Object::TypeKey2Index |
( |
const std::string & |
key | ) |
|
|
static |
Get the type index of the corresponding key from runtime.
- Parameters
-
- Returns
- the result.
◆ unique()
bool tvm::runtime::Object::unique |
( |
| ) |
const |
|
inline |
- Returns
- Whether the cell has only one reference
- Note
- We use stl style naming to be consistent with known API in shared_ptr.
◆ ObjAllocatorBase
◆ ObjectInternal
friend class ObjectInternal |
|
friend |
◆ ObjectPtr
◆ TVMRetValue
◆ _type_child_slots
constexpr uint32_t tvm::runtime::Object::_type_child_slots = 0 |
|
static |
◆ _type_child_slots_can_overflow
constexpr bool tvm::runtime::Object::_type_child_slots_can_overflow = true |
|
static |
◆ _type_final
constexpr bool tvm::runtime::Object::_type_final = false |
|
static |
◆ _type_has_method_sequal_reduce
constexpr bool tvm::runtime::Object::_type_has_method_sequal_reduce = false |
|
static |
◆ _type_has_method_shash_reduce
constexpr bool tvm::runtime::Object::_type_has_method_shash_reduce = false |
|
static |
◆ _type_has_method_visit_attrs
constexpr bool tvm::runtime::Object::_type_has_method_visit_attrs = true |
|
static |
◆ _type_index
◆ _type_key
constexpr const char* tvm::runtime::Object::_type_key = "runtime.Object" |
|
static |
◆ deleter_
FDeleter tvm::runtime::Object::deleter_ = nullptr |
|
protected |
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.
◆ ref_counter_
The internal reference counter.
◆ type_index_
uint32_t tvm::runtime::Object::type_index_ {0} |
|
protected |
Type index(tag) that indicates the type of the object.
The documentation for this class was generated from the following file: