tvm_tirx.ir.Op#
- class tvm_tirx.ir.Op#
Bases:
ExprA registered primitive operator used as a
Callcallee.Retrieve the shared operator with
Op.get(name). Its registration supplies argument signatures, attributes, validation, and result-type inference; constructing a Call does not itself execute the operator.- static get(op_name)#
Get a registered operator by name.
- Parameters:
op_name (str) – The canonical operator name.
- Returns:
Op – A handle to the registered operator.
- static register(op_name, doc='')#
Register a new operator and return it.
The operator is added to the global registry for the rest of the process, so
Op.get(op_name)returns the same object afterwards. It starts with an empty signature and no attributes: set them withset_signature()andset_attr(), then callexpose()to make it available to API destinations.- Parameters:
op_name (str) – The canonical operator name. It must not already be registered.
doc (str, optional) – A short description of the operator.
- Returns:
Op – The newly registered operator.
- Raises:
AttributeError – If an operator with the same name is already registered.
- static list_op_names()#
List registered operator names in unspecified order.
- Returns:
list[str] – The registered operator names.
- static list_attr_names()#
List registered attribute column names in unspecified order.
- Returns:
list[str] – The attribute column names, such as
"TCallEffectKind".
- static get_attr_map(attr_name)#
Get the map from operators to their values of an attribute.
This is the Python counterpart of C++
Op::GetAttrMap. The map reads the registry’s storage directly, so later registrations, overrides and removals are visible through it, and it can be cached.- Parameters:
attr_name (str) – Attribute name, such as
"TCallEffectKind".- Returns:
OpAttrMap or None – The attribute map, or None when no operator has registered the attribute.
- set_attr(attr_name, value, override=False)#
Set an operator attribute.
- Parameters:
attr_name (str) – Attribute column name.
value (object) – Non-None attribute value.
override (bool, optional) – Replace an existing value if True. Duplicate registration otherwise raises ValueError. Cached views observe replacements; no history is kept.
- Returns:
None
- set_signature(args=(), *, ty_args=(), var_args=None, var_ty_args=None)#
Replace this Op’s argument signature and validate Call arity.
Each entry is a name string or a
(name, doc)tuple of strings. Fixed entries form required prefixes; a variadic entry allows zero or more additional arguments. Calls must have exactly the required count without a tail, or at least that count with one. This method does not check argument types or Call attrs. It replaces a generated typed validator with a count-only one, while an existing custom validator keeps precedence.- Parameters:
args (sequence[str or tuple[str, str]], optional) – Fixed value arguments, in order.
ty_args (sequence[str or tuple[str, str]], optional) – Fixed type arguments, in order.
var_args (str or tuple[str, str], optional) – Variadic value-argument tail.
var_ty_args (str or tuple[str, str], optional) – Variadic type-argument tail.
- Returns:
None
- Return type:
None
- expose()#
Expose the completed operator definition to registered API destinations.
Call after setting the signature and attributes. Destinations initialized later replay the request; explicit Python APIs take precedence. Registration and attribute updates alone do not expose an Op.
- Return type:
None
- add_arg(name: str, doc: str) None#
Append an argument’s name and documentation.
- Parameters:
self (Any)
args (Any)
- Return type:
Any
- add_ty_arg(name: str, doc: str) None#
Append a type-argument name and documentation without imposing a count rule.
- Parameters:
self (Any)
args (Any)
- Return type:
Any
- property args_info#
- property attrs_type_key#
- property doc#
- get_attr(attr_name: str) object#
Return this Op’s attribute or None; an unregistered column raises InternalError.
- Parameters:
self (Any)
args (Any)
- Return type:
Any
- has_attr(attr_name: str) bool#
Return whether the attribute column exists in the registry.
- Parameters:
self (Any)
args (Any)
- Return type:
Any
- property index#
- property name#
- reset_attr(attr_name: str) None#
Remove this Op’s current value; missing values are ignored and cached views observe removal.
- Parameters:
self (Any)
args (Any)
- Return type:
Any
- set_attrs_type_key(key: str) None#
Resolve and set the attribute object type key and runtime index together; an unknown key raises before updating.
- Parameters:
self (Any)
args (Any)
- Return type:
Any
- property ty_args_info#
- property var_args_info#
- property var_ty_args_info#