28 #include <tvm/ffi/function.h>
29 #include <tvm/ffi/reflection/registry.h>
35 #include <tvm/runtime/logging.h>
96 refl::ObjectDef<OpNode>()
98 .def_ro(
"op_type", &
OpNode::op_type, refl::AttachFieldFlag::SEqHashIgnore())
111 uint32_t AttrRegistryIndex()
const {
return index_; }
113 std::string AttrRegistryName()
const {
return name; }
118 template <
typename,
typename>
140 template <
typename ValueType>
147 TVM_DLL
static bool HasAttrMap(
const ffi::String& attr_name);
154 TVM_DLL
static const Op&
Get(
const ffi::String& op_name);
174 const Op&
op()
const {
return op_; }
190 const std::string& description);
196 template <
typename AttrsType>
229 template <
typename ValueType>
231 const ValueType& value,
int plevel = 10);
241 if (get()->name.length() == 0) {
254 template <
typename,
typename>
265 TVM_DLL
void UpdateAttr(
const ffi::String& key, ffi::Any value,
int plevel);
272 template <
typename ValueType>
282 inline ValueType
get(
const RelaxExpr& expr, ValueType def_value)
const;
287 using TParent::operator[];
296 #define TVM_OP_REGISTER_VAR_DEF static DMLC_ATTRIBUTE_UNUSED ::tvm::OpRegEntry& __make_##Op
313 #define TVM_REGISTER_OP(OpName) \
314 TVM_STR_CONCAT(TVM_OP_REGISTER_VAR_DEF, __COUNTER__) = \
315 ::tvm::OpRegEntry::RegisterOrGet(OpName).set_name()
319 template <
typename ValueType>
324 inline OpNode* OpRegEntry::get() {
return const_cast<OpNode*
>(op_.operator->()); }
332 const std::string& description) {
333 auto n = ffi::make_object<AttrFieldInfoNode>();
336 n->description = description;
346 template <
typename AttrsType>
364 template <
typename ValueType>
366 const std::string& attr_name,
const ValueType& value,
int plevel) {
367 ICHECK_GT(plevel, 0) <<
"plevel in set_attr must be greater than 0";
368 UpdateAttr(attr_name, Any(value), plevel);
374 template <
typename ValueType>
376 ICHECK(expr.defined());
378 return this->map_.get(ffi::GetRef<Op>(op), def_value);
Attribute map used in registry.
Helpers for attribute objects.
AttrFieldInfo.
Definition: attrs.h:91
Generic attribute map.
Definition: attr_registry_map.h:38
ffi::Map<Key, ValueType> used to store meta-data.
Definition: attr_registry_map.h:105
ValueType get(const Op &key, ValueType def_value) const
get the corresponding value element at key with default value.
Definition: attr_registry_map.h:136
int count(const Op &key) const
Check if the map has op as key.
Definition: attr_registry_map.h:117
Definition: instruction.h:30
Managed reference to FuncTypeNode.
Definition: type.h:274
ffi::Map<Op,ValueType> used to store meta-information about Op.
Definition: op.h:273
ValueType get(const RelaxExpr &expr, ValueType def_value) const
get the corresponding value element at op with default value.
Definition: op.h:375
Primitive Op(builtin intrinsics)
Definition: op.h:59
ffi::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:76
static void RegisterReflection()
Definition: op.h:94
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.Op", OpNode, RelaxExprNode)
ffi::String description
detailed description of the operator This can be used to generate docstring automatically for the ope...
Definition: op.h:69
uint32_t attrs_type_index
attribute type index, this field varies in each run and is not exposed to frontend.
Definition: op.h:81
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: op.h:106
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:92
ffi::String name
name of the operator
Definition: op.h:62
int32_t num_inputs
number of input arguments to the operator, -1 means it is variable length
Definition: op.h:86
ffi::Array< AttrFieldInfo > arguments
Definition: op.h:71
FuncType op_type
the type of the operator
Definition: op.h:64
Helper structure to register operators.
Definition: op.h:171
OpRegEntry & describe(const std::string &descr)
setter function during registration Set the description of operator
Definition: op.h:326
static OpRegEntry & RegisterOrGet(const ffi::String &name)
Register or get a new entry.
OpRegEntry & set_name()
Definition: op.h:240
void reset_attr(const std::string &attr_name)
Resets an attr of the registry.
OpRegEntry & set_attrs_type_key(const ffi::String &key)
Set the attrs type key and index to be AttrsType.
Definition: op.h:353
OpRegEntry & add_argument(const std::string &name, const std::string &type, const std::string &description)
Add argument information to the function.
Definition: op.h:331
OpRegEntry & set_attrs_type()
Set the attrs type key and index to be AttrsType.
Definition: op.h:347
OpRegEntry & set_support_level(int32_t level)
Set the support level of op.
Definition: op.h:359
const Op & op() const
Definition: op.h:174
OpRegEntry & set_attr(const std::string &attr_name, const ValueType &value, int plevel=10)
Register additional attributes to operator.
Definition: op.h:365
OpRegEntry & set_num_inputs(int32_t n)
Set the num_inputs.
Definition: op.h:341
Managed reference class to OpNode.
Definition: op.h:131
static const Op & Get(const ffi::String &op_name)
Get an Op for a given operator name. Will raise an error if the op has not been registered.
static OpAttrMap< ValueType > GetAttrMap(const ffi::String &attr_name)
Get additional registered attribute about operators. If nothing has been registered,...
Definition: op.h:320
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Op, RelaxExpr, OpNode)
static bool HasAttrMap(const ffi::String &attr_name)
Checks if an attr map is present in the registry.
Base node of all non-primitive expressions.
Definition: expr.h:416
Managed reference to RelaxExprNode.
Definition: expr.h:439
Serializable global function used in IR.
IR/AST nodes for the unified type system in TVM.
Definition: repr_printer.h:91
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:37