28 #include <tvm/ffi/error.h>
29 #include <tvm/ffi/function.h>
30 #include <tvm/ffi/reflection/registry.h>
64 namespace rfl = ffi::reflection;
65 rfl::ObjectDef<ArgumentInfoNode>()
128 namespace refl = tvm::ffi::reflection;
129 refl::ObjectDef<OpNode>()
143 uint32_t AttrRegistryIndex()
const {
return index_; }
145 std::string AttrRegistryName()
const {
return name; }
150 template <
typename,
typename>
165 explicit Op(ffi::ObjectPtr<OpNode> n) :
Expr(std::move(n)) {
166 TVM_FFI_CHECK(defined(), ValueError) <<
"Op expects a defined OpNode";
176 template <
typename ValueType>
183 TVM_DLL
static bool HasAttrMap(
const ffi::String& attr_name);
190 TVM_DLL
static const Op&
Get(
const ffi::String& op_name);
210 const Op&
op()
const {
return op_; }
226 const std::string& description);
232 template <
typename AttrsType>
265 template <
typename ValueType>
267 const ValueType& value,
int plevel = 10);
277 if (get()->name.length() == 0) {
290 template <
typename,
typename>
297 static Op MakeOp(uint32_t reg_index);
303 TVM_DLL
void UpdateAttr(
const ffi::String& key, ffi::Any value,
int plevel);
310 template <
typename ValueType>
320 inline ValueType
get(
const Expr& expr, ValueType def_value)
const;
325 using TParent::operator[];
334 #define TVM_OP_REGISTER_VAR_DEF [[maybe_unused]] static ::tvm::OpRegEntry& __make_##Op
351 #define TVM_REGISTER_OP(OpName) \
352 TVM_FFI_STR_CONCAT(TVM_OP_REGISTER_VAR_DEF, __COUNTER__) = \
353 ::tvm::OpRegEntry::RegisterOrGet(OpName).set_name()
357 template <
typename ValueType>
362 inline OpNode* OpRegEntry::get() {
return const_cast<OpNode*
>(op_.operator->()); }
370 const std::string& description) {
371 auto n = ffi::make_object<ArgumentInfoNode>();
374 n->description = description;
384 template <
typename AttrsType>
402 template <
typename ValueType>
404 const std::string& attr_name,
const ValueType& value,
int plevel) {
405 TVM_FFI_ICHECK_GT(plevel, 0) <<
"plevel in set_attr must be greater than 0";
406 UpdateAttr(attr_name, Any(value), plevel);
412 template <
typename ValueType>
414 TVM_FFI_ICHECK(expr.defined());
416 return this->map_.get(ffi::GetRef<Op>(op), def_value);
Attribute map used in registry.
Helpers for attribute objects.
Information about an input field of an Op (name, type, description).
Definition: op.h:54
ffi::String description
detailed description of the type
Definition: op.h:61
static void RegisterReflection()
Definition: op.h:63
ffi::String name
name of the field
Definition: op.h:57
ffi::String type_info
type docstring information in str.
Definition: op.h:59
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.ArgumentInfo", ArgumentInfoNode, ffi::Object)
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: op.h:71
Managed reference to ArgumentInfoNode.
Definition: op.h:77
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(ArgumentInfo, ffi::ObjectRef, ArgumentInfoNode)
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
Base type of all the expressions.
Definition: base_expr.h:276
Managed reference to ExprNode.
Definition: base_expr.h:311
ffi::Map<Op,ValueType> used to store meta-information about Op.
Definition: op.h:311
ValueType get(const Expr &expr, ValueType def_value) const
get the corresponding value element at op with default value.
Definition: op.h:413
Primitive Op(builtin intrinsics)
Definition: op.h:94
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:109
static void RegisterReflection()
Definition: op.h:127
ffi::String description
detailed description of the operator This can be used to generate docstring automatically for the ope...
Definition: op.h:102
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.Op", OpNode, ExprNode)
uint32_t attrs_type_index
attribute type index, this field varies in each run and is not exposed to frontend.
Definition: op.h:114
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: op.h:138
ffi::Array< ArgumentInfo > arguments
Definition: op.h:104
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:125
ffi::String name
name of the operator
Definition: op.h:97
int32_t num_inputs
number of input arguments to the operator, -1 means it is variable length
Definition: op.h:119
Helper structure to register operators.
Definition: op.h:207
OpRegEntry & describe(const std::string &descr)
setter function during registration Set the description of operator
Definition: op.h:364
static OpRegEntry & RegisterOrGet(const ffi::String &name)
Register or get a new entry.
OpRegEntry & set_name()
Definition: op.h:276
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:391
OpRegEntry & add_argument(const std::string &name, const std::string &type, const std::string &description)
Add argument information to the function.
Definition: op.h:369
OpRegEntry & set_attrs_type()
Set the attrs type key and index to be AttrsType.
Definition: op.h:385
OpRegEntry & set_support_level(int32_t level)
Set the support level of op.
Definition: op.h:397
const Op & op() const
Definition: op.h:210
OpRegEntry & set_attr(const std::string &attr_name, const ValueType &value, int plevel=10)
Register additional attributes to operator.
Definition: op.h:403
OpRegEntry & set_num_inputs(int32_t n)
Set the num_inputs.
Definition: op.h:379
Managed reference class to OpNode.
Definition: op.h:163
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Op, Expr, OpNode)
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:358
static bool HasAttrMap(const ffi::String &attr_name)
Checks if an attr map is present in the registry.
Op(ffi::ObjectPtr< OpNode > n)
Definition: op.h:165
Serializable global function used in IR.
IR/AST nodes for TVM types shared across IR variants.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition: analyzer.h:40