28 #include <dmlc/registry.h>
94 v->Visit(
"name", &
name);
105 return this == other;
119 if (is_primitive_ != -1)
return is_primitive_ != 0;
120 is_primitive_ = this->IsPrimitiveOp_() ? 1 : 0;
121 return is_primitive_ != 0;
129 uint32_t AttrRegistryIndex()
const {
return index_; }
131 std::string AttrRegistryName()
const {
return name; }
136 template <
typename,
typename>
145 mutable int is_primitive_{-1};
147 bool IsPrimitiveOp_()
const {
148 const auto& fn_ty = this->
op_type;
149 ICHECK(fn_ty.get() !=
nullptr) <<
"op_type of " << this->name <<
" is not registered";
150 if (fn_ty->type_constraints.size() != 1)
return false;
152 if (rel ==
nullptr)
return false;
154 for (
size_t i = 0; i < fn_ty->type_params.size(); ++i) {
155 if (!fn_ty->type_params[i].same_as(rel->args[i]))
return false;
174 template <
typename ValueType>
208 const Op&
op()
const {
return op_; }
224 const std::string& description);
233 const std::string& rel_name,
241 template <
typename AttrsType>
274 template <
typename ValueType>
276 const ValueType& value,
int plevel = 10);
286 if (get()->name.
length() == 0) {
299 template <
typename,
typename>
317 template <
typename ValueType>
327 inline ValueType
get(
const RelayExpr& expr, ValueType def_value)
const;
332 using TParent::operator[];
341 #define TVM_OP_REGISTER_VAR_DEF static DMLC_ATTRIBUTE_UNUSED ::tvm::OpRegEntry& __make_##Op
358 #define TVM_REGISTER_OP(OpName) \
359 TVM_STR_CONCAT(TVM_OP_REGISTER_VAR_DEF, __COUNTER__) = \
360 ::tvm::OpRegEntry::RegisterOrGet(OpName).set_name()
364 template <
typename ValueType>
369 inline OpNode* OpRegEntry::get() {
return const_cast<OpNode*
>(op_.operator->()); }
377 const std::string& description) {
378 auto n = make_object<AttrFieldInfoNode>();
381 n->description = description;
387 const std::string& rel_name,
390 auto func_name = std::string(
"tvm.relay.type_relation.") + rel_name;
395 env_type_rel_func = env_func;
399 env_type_rel_func = env_func;
406 std::string input_name_prefix =
"in";
408 auto name = input_name_prefix + std::to_string(i);
433 auto func_type =
FuncType(arg_types, out_param, type_params, {type_rel});
445 template <
typename AttrsType>
463 template <
typename ValueType>
465 const std::string& attr_name,
const ValueType& value,
int plevel) {
466 ICHECK_GT(plevel, 0) <<
"plevel in set_attr must be greater than 0";
469 UpdateAttr(attr_name, rv, plevel);
475 template <
typename ValueType>
479 return this->map_.get(GetRef<Op>(op), def_value);
Attribute map used in registry.
AttrFieldInfo.
Definition: attrs.h:128
Generic attribute map.
Definition: attr_registry_map.h:38
Map<Key, ValueType> used to store meta-data.
Definition: attr_registry_map.h:101
ValueType get(const Op &key, ValueType def_value) const
get the corresponding value element at key with default value.
Definition: attr_registry_map.h:126
int count(const Op &key) const
Check if the map has op as key.
Definition: attr_registry_map.h:113
Definition: executor.h:43
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
Managed reference to BaseAttrsNode.
Definition: attrs.h:190
static EnvFunc Get(const String &name)
Get a global function based on the name.
Managed reference to FuncTypeNode.
Definition: type.h:481
Map<Op,ValueType> used to store meta-information about Op.
Definition: op.h:318
ValueType get(const RelayExpr &expr, ValueType def_value) const
get the corresponding value element at op with default value.
Definition: op.h:476
Primitive Op(builtin intrinsics)
Definition: op.h:58
void SHashReduce(SHashReducer hash_reduce) const
Definition: op.h:108
static constexpr const char * _type_key
Definition: op.h:124
bool IsPrimitiveOp() const
Check that if current op is a "primtive operator". That is the arguments are all type variables,...
Definition: op.h:118
String name
name of the operator
Definition: op.h:61
uint32_t attrs_type_index
attribute type index, this field varies in each run and is not exposed to frontend.
Definition: op.h:80
String attrs_type_key
The type key of the attribute field This can be empty, in which case it defaults to anything.
Definition: op.h:75
int32_t support_level
support level of the operator, The lower the more priority it contains. This is in analogies to BLAS ...
Definition: op.h:91
void VisitAttrs(AttrVisitor *v)
Definition: op.h:93
int32_t num_inputs
number of input arguments to the operator, -1 means it is variable length
Definition: op.h:85
TVM_DECLARE_FINAL_OBJECT_INFO(OpNode, RelayExprNode)
FuncType op_type
the type of the operator
Definition: op.h:63
String description
detailed description of the operator This can be used to generate docstring automatically for the ope...
Definition: op.h:68
Array< AttrFieldInfo > arguments
Definition: op.h:70
bool SEqualReduce(const OpNode *other, SEqualReducer equal) const
Definition: op.h:103
Helper structure to register operators.
Definition: op.h:205
OpRegEntry & set_attrs_type_key(const String &key)
Set the attrs type key and index to be AttrsType.
Definition: op.h:452
OpRegEntry & describe(const std::string &descr)
setter function during registration Set the description of operator
Definition: op.h:371
static OpRegEntry & RegisterOrGet(const String &name)
Register or get a new entry.
OpRegEntry & add_type_rel(const std::string &rel_name, runtime::TypedPackedFunc< bool(const Array< Type > &, int, const Attrs &, const TypeReporter &)> type_rel_func)
Attach the type function corresponding to the return type.
Definition: op.h:386
OpRegEntry & set_name()
Definition: op.h:285
void reset_attr(const std::string &attr_name)
Resets an attr of the registry.
OpRegEntry & add_argument(const std::string &name, const std::string &type, const std::string &description)
Add argument information to the function.
Definition: op.h:376
OpRegEntry & set_attrs_type()
Set the attrs type key and index to be AttrsType.
Definition: op.h:446
OpRegEntry & set_support_level(int32_t level)
Set the support level of op.
Definition: op.h:458
const Op & op() const
Definition: op.h:208
OpRegEntry & set_attr(const std::string &attr_name, const ValueType &value, int plevel=10)
Register additional attributes to operator.
Definition: op.h:464
OpRegEntry & set_num_inputs(int32_t n)
Set the num_inputs.
Definition: op.h:440
Managed reference class to OpNode.
Definition: op.h:165
static OpAttrMap< ValueType > GetAttrMap(const String &attr_name)
Get additional registered attribute about operators. If nothing has been registered,...
Definition: op.h:365
static bool HasAttrMap(const String &attr_name)
Checks if an attr map is present in the registry.
static const Op & Get(const String &op_name)
Get an Op for a given operator name. Will raise an error if the op has not been registered.
Base node of all non-primitive expressions.
Definition: expr.h:362
Managed reference to RelayExprNode.
Definition: expr.h:442
TVM_DEFINE_OBJECT_REF_METHODS(RelayExpr, BaseExpr, RelayExprNode)
A Reducer class to reduce the structural equality result of two objects.
Definition: structural_equal.h:137
A Reducer class to reduce the structural hash value.
Definition: structural_hash.h:121
Managed reference to TypeConstraintNode.
Definition: type.h:423
Container class of TypeReporter.
Definition: type_relation.h:145
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
void push_back(const T &item)
push a new item to the back of the list
Definition: array.h:457
size_t size() const
Definition: array.h:420
bool defined() const
Definition: object.h:552
const ObjectType * as() const
Try to downcast the internal Object to a raw pointer of a corresponding type.
Definition: object.h:910
static uint32_t TypeKey2Index(const std::string &key)
Get the type index of the corresponding key from runtime.
static Registry & Register(const String &name, bool override=false)
Register a function with given name.
static const PackedFunc * Get(const String &name)
Get the global function by name.
Registry & set_body(PackedFunc f)
set the body of the function to be f
Reference to string objects.
Definition: string.h:98
size_t length() const
Return the length of the string.
Definition: string.h:201
Return Value container, Unlike TVMArgValue, which only holds reference and do not delete the underlyi...
Definition: packed_func.h:946
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:63
Helpers for attribute objects.
IR/AST nodes for the unified type system in TVM.
tvm::TypeVar TypeVar
Definition: type.h:49
tvm::TypeRelationNode TypeRelationNode
Definition: type.h:68
tvm::FuncType FuncType
Definition: type.h:57
tvm::TypeRelation TypeRelation
Definition: type.h:67
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
PrimExpr equal(PrimExpr a, PrimExpr b, Span span=Span())
equal
bool IsPrimitiveOp(const RelayExpr &expr)
Check that an expression is a "primitive operator".
Definition: op.h:498
@ kType
Definition: type.h:202
This file defines the TVM global function registry.
Type relation and function for type inference(checking).