24 #ifndef TVM_RELAY_RUNTIME_H_ 25 #define TVM_RELAY_RUNTIME_H_ 27 #include <dmlc/registry.h> 36 #include <unordered_map> 42 template <
typename,
typename>
48 static constexpr
const char* kTvmRuntimeCpp =
"cpp";
51 static constexpr
const char* kTvmRuntimeCrt =
"crt";
87 template <
typename TObjectRef>
89 const std::string& attr_key,
91 return attrs.
GetAttr(attr_key, default_value);
94 template <
typename TObjectRef>
100 v->Visit(
"name", &name);
101 v->Visit(
"attrs", &attrs);
159 auto n = make_object<RuntimeNode>();
160 n->name = std::move(name);
161 n->attrs = std::move(attrs);
162 data_ = std::move(n);
177 template <
typename ValueType>
186 template <
typename ValueType>
198 struct ValueTypeInfo {
199 std::string type_key;
202 std::unordered_map<std::string, ValueTypeInfo> key2vtype_;
204 std::unordered_map<String, ObjectRef> key2default_;
213 uint32_t AttrRegistryIndex()
const {
return index_; }
215 String AttrRegistryName()
const {
return name; }
223 template <
typename,
typename>
228 template <
typename ValueType>
230 ICHECK(!key2vtype_.count(key)) <<
"AttributeError: add_attr_option failed because '" << key
231 <<
"' has been set once";
233 using ValueNodeType =
typename ValueType::ContainerType;
235 uint32_t value_type_index = ValueNodeType::_GetOrAllocRuntimeTypeIndex();
238 info.type_index = value_type_index;
240 key2vtype_[key] = info;
244 template <
typename ValueType>
247 add_attr_option<ValueType>(key);
248 key2default_[key] = default_value;
253 #define TVM_RUNTIME_REGISTER_VAR_DEF \ 254 static DMLC_ATTRIBUTE_UNUSED ::tvm::relay::RuntimeRegEntry& __make_##Runtime 270 #define TVM_REGISTER_RUNTIME(RuntimeName) \ 271 TVM_STR_CONCAT(TVM_RUNTIME_REGISTER_VAR_DEF, __COUNTER__) = \ 272 ::tvm::relay::RuntimeRegEntry::RegisterOrGet(RuntimeName) 276 #endif // TVM_RELAY_RUNTIME_H_ static constexpr const char * _type_key
Definition: runtime.h:113
bool DefEqual(const ObjectRef &lhs, const ObjectRef &rhs)
Reduce condition to comparison of two definitions, where free vars can be mapped. ...
void VisitAttrs(AttrVisitor *v)
Definition: runtime.h:99
A Reducer class to reduce the structural equality result of two objects.
Definition: structural_equal.h:124
DictAttrs attrs
Definition: runtime.h:66
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
A Reducer class to reduce the structural hash value.
Definition: structural_hash.h:110
Type relation and function for type inference(checking).
RuntimeRegEntry & add_attr_option(const String &key)
Register a valid configuration option and its ValueType for validation.
Definition: runtime.h:229
PrimExpr equal(PrimExpr a, PrimExpr b, Span span=Span())
equal
Managed reference to DictAttrsNode.
Definition: attrs.h:227
base class of all object containers.
Definition: object.h:167
Definition: executor.h:43
Helpers for attribute objects.
bool SEqualReduce(const RuntimeNode *other, SEqualReducer equal) const
Definition: runtime.h:104
Generic attribute map.
Definition: attr_registry_map.h:38
Visitor class to get the attributes of an AST/IR node. The content is going to be called for each fie...
Definition: reflection.h:52
String name
name of the Runtime
Definition: runtime.h:64
IR/AST nodes for the unified type system in TVM.
Helper structure to register Runtimes.
Definition: runtime.h:170
Optional< TObjectRef > GetAttr(const std::string &attr_key, Optional< TObjectRef > default_value=Optional< TObjectRef >(nullptr)) const
Get a function attribute.
Definition: attrs.h:259
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Optional< TObjectRef > GetAttr(const std::string &attr_key, TObjectRef default_value) const
Definition: runtime.h:95
Reference to string objects.
Definition: string.h:98
Runtime information.
Definition: runtime.h:61
Managed reference class to RuntimeNode.
Definition: runtime.h:123
static constexpr const bool _type_has_method_sequal_reduce
Definition: runtime.h:114
Base class of all object reference.
Definition: object.h:511
Attribute map used in registry.
uint32_t type_index() const
Definition: object.h:175
TVM_DECLARE_FINAL_OBJECT_INFO(RuntimeNode, Object)
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics, which means map is mutable but copy will happen when array is referenced in more than two places.
Definition: map.h:1271
static std::string TypeIndex2Key(uint32_t tindex)
Get the type key of the corresponding index from runtime.
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Optional< TObjectRef > GetAttr(const std::string &attr_key, Optional< TObjectRef > default_value=Optional< TObjectRef >(nullptr)) const
Get an attribute.
Definition: runtime.h:88
static constexpr const bool _type_has_method_shash_reduce
Definition: runtime.h:115
#define TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:728
void SHashReduce(SHashReducer hash_reduce) const
Definition: runtime.h:108
This file defines the TVM global function registry.