tvm.ir#
Common data structures across all IR variants.
Functions:
|
construct a constant |
|
Make a new IR node by its type key and fields |
|
Assert lhs and rhs are structurally equal to each other. |
|
Load tvm object from json_str. |
|
Save tvm object as json string. |
|
Return whether an expression has a primitive result type. |
|
Return whether a value is an ordinary variable with a primitive type. |
|
Derive a Call's result type from its current inputs without changing the Call. |
|
Register an operator property of an operator by name. |
|
Make sequence of statements |
|
Make list of stmt from blocks. |
Classes:
|
Attribute node, which is mainly use for defining attributes of operators. |
|
Dictionary attributes. |
|
Environment function. |
Base class of all IR Nodes. |
|
Marker for display methods installed by the TVMScript owner. |
|
|
An identifier for a source location. |
|
Non-null source-location metadata attached to IR nodes. |
|
A source range with unchanged frontend coordinate units and endpoints. |
The canonical immutable location used when source information is unavailable. |
|
|
A callee's location together with the location of its caller. |
|
The top type, which admits any value. |
|
Function type. |
Type information that has not been supplied or computed. |
|
Type marker for opaque values that must be removed from finished IR. |
|
|
PointerType used in the low-level TIR. |
|
Primitive data type in the low level IR |
Semantic string type, independent of the function's calling convention. |
|
The type of a multi-dimensional |
|
|
The type of tuple values. |
|
The base class of all types. |
|
Core function call node. |
|
Base class of literal constants. |
|
A literal payload with an explicit expression type. |
|
A data type literal whose expression type is AnyType. |
|
A string literal with StringType. |
Python operator surface for anything that denotes an expression. |
|
|
Common type-directed operator behavior for core expressions. |
|
A global variable in the IR. |
|
A typed staging expression representing a lambda computation. |
|
A traversable expression eliminated before executable IR. |
|
Base class for opaque values that must be removed from finished IR. |
|
Represent a range in TVM. |
|
An indexed load from an expression source. |
|
A region of an arbitrary tensor expression. |
|
Tuple expression that groups several fields together. |
|
Get the index-th item from a tuple. |
|
A canonical local variable in the IR. |
|
Base class of all functions. |
|
Possible kinds of calling conventions. |
Base node for all global info that can appear in the IR |
|
|
IRModule that holds functions and type definitions. |
|
Primitive operator in the IR. |
|
Base class of all the statements. |
|
Sequence of statements. |
|
Bind node. |
|
Evaluate node. |
|
Return node. |
|
If node. |
|
The kind of the for loop. |
|
For node. |
|
While node. |
|
Break node. |
|
Continue node. |
|
AssertStmt node. |
|
An operation with enclosing-scope operands and one lexical body. |
|
Store a primitive value into a tensor destination. |
|
Array container that represents a sequence of values in the FFI. |
|
Map container. |
- class tvm.ir.Attrs#
Attribute node, which is mainly use for defining attributes of operators.
Used by function registered in python side, such as compute, schedule and alter_layout. Attrs is passed as the first argument to these functions.
Methods:
get_int_tuple(key)Get a python int tuple of a key
get_int(key)Get a python int value of a key
get_str(key)Get a python int value of a key
- get_int_tuple(key)#
Get a python int tuple of a key
- class tvm.ir.DictAttrs(__dict__)#
Dictionary attributes.
Methods:
keys()Get list of names in the attribute.
get(key[, default])Get an element with a default value.
items()Get items from the map.
- get(key, default=None)#
Get an element with a default value.
- items()#
Get items from the map.
- tvm.ir.make_node(type_key, **kwargs)#
Make a new IR node by its type key and fields
- Parameters:
- Returns:
node – The corresponding IR Node
- Return type:
Note
If the created node is instance of AttrsNode, then the creator function will also run bound checks and default value setup as supported by Attrs.
Example
The following code constructs a IntImm object
x = tvm.ir.make_node("ir.IntImm", dtype="int32", value=10, loc=tvm.ir.UnknownLoc()) assert isinstance(x, tvm.tirx.IntImm) assert x.value == 10
- class tvm.ir.EnvFunc(name, func)#
Environment function.
This is a global function object that can be serialized by its name.
Methods:
get(name)Get a static env function
- class tvm.ir.Node#
Base class of all IR Nodes.
- class tvm.ir.Scriptable#
Marker for display methods installed by the TVMScript owner.
Methods:
script(*[, name, show_meta, ir_prefix, ...])Print TVM IR into TVMScript text format
show([style, black_format, name, show_meta, ...])A sugar for print highlighted TVM script.
- script(*, name: str | None = None, show_meta: bool = False, ir_prefix: str = 'I', module_alias: str = 'cls', int_dtype: str = 'int32', float_dtype: str = 'void', verbose_expr: bool = False, indent_spaces: int = 4, print_line_numbers: bool = False, num_context_lines: int = -1, show_all_ty: bool = True, extra_config: dict | None = None, path_to_underline: list[AccessPath] | None = None, path_to_annotate: dict[AccessPath, str] | None = None, obj_to_underline: list[Object] | None = None, obj_to_annotate: dict[Object, str] | None = None) str#
Print TVM IR into TVMScript text format
- Parameters:
name (Optional[str] = None) – The name of the object
show_meta (bool = False) – Whether to print the meta data of the object
ir_prefix (str = "I") – The prefix of AST nodes from tvm.ir
module_alias (str = "cls") – Retained for compatibility. Cross-function calls use the module name directly.
int_dtype (str = "int32") – The default data type of integer
float_dtype (str = "void") – The default data type of float
verbose_expr (bool = False) – Whether to print the detailed definition of each variable in the expression
indent_spaces (int = 4) – The number of spaces for indentation
print_line_numbers (bool = False) – Whether to print line numbers
num_context_lines (int = -1) – The number of lines of context to print before and after the line to underline.
show_all_ty (bool = True) – If True (default), annotate all variable bindings with the struct info of that variable. If False, only add annotations where required for unambiguous round-trip of Relax -> TVMScript -> Relax.
extra_config (Optional[dict] = None) – Dialect-specific configuration passed through to PrinterConfig.extra_config. Keys are conventionally namespaced as “<dialect>.<knob>”, e.g.
{"tirx.prefix": "T"}.path_to_underline (Optional[List[AccessPath]] = None) – Object path to be underlined
path_to_annotate (Optional[Dict[AccessPath, str]] = None) – Object path to be annotated
obj_to_underline (Optional[List[Object]] = None) – Object to be underlined
obj_to_annotate (Optional[Dict[Object, str]] = None) – Object to be annotated
- Returns:
script – The TVM Script of the given TVM IR
- Return type:
- show(style: str | None = None, black_format: bool | None = None, *, name: str | None = None, show_meta: bool = False, ir_prefix: str = 'I', module_alias: str = 'cls', int_dtype: str = 'int32', float_dtype: str = 'void', verbose_expr: bool = False, indent_spaces: int = 4, print_line_numbers: bool = False, num_context_lines: int = -1, show_all_ty: bool = True, extra_config: dict | None = None, path_to_underline: list[AccessPath] | None = None, path_to_annotate: dict[AccessPath, str] | None = None, obj_to_underline: list[Object] | None = None, obj_to_annotate: dict[Object, str] | None = None) None#
A sugar for print highlighted TVM script.
- Parameters:
style (str, optional) – Pygmentize printing style, auto-detected if None. See tvm.script.printer.highlight.cprint for more details.
black_format (Optional[bool]) –
If true, use the formatter Black to format the TVMScript. If false, do not apply the auto-formatter.
If None (default), determine the behavior based on the environment variable “TVM_BLACK_FORMAT”. If this environment variable is unset, set to the empty string, or set to the integer zero, black auto-formatting will be disabled. If the environment variable is set to a non-zero integer, black auto-formatting will be enabled.
Note that the “TVM_BLACK_FORMAT” environment variable only applies to the .show() method, and not the underlying .script() method. The .show() method is intended for human-readable output based on individual user preferences, while the .script() method is intended to provided a consistent output regardless of environment.
name (Optional[str] = None) – The name of the object
show_meta (bool = False) – Whether to print the meta data of the object
ir_prefix (str = "I") – The prefix of AST nodes from tvm.ir
module_alias (str = "cls") – Retained for compatibility. Cross-function calls use the module name directly.
int_dtype (str = "int32") – The default data type of integer
float_dtype (str = "void") – The default data type of float
verbose_expr (bool = False) – Whether to print the detailed definition of each variable in the expression
indent_spaces (int = 4) – The number of spaces for indentation
print_line_numbers (bool = False) – Whether to print line numbers
num_context_lines (int = -1) – The number of lines of context to print before and after the line to underline.
show_all_ty (bool = True) – If True (default), annotate all variable bindings with the struct info of that variable. If False, only add annotations where required for unambiguous round-trip of Relax -> TVMScript -> Relax.
extra_config (Optional[dict] = None) – Dialect-specific configuration passed through to PrinterConfig.extra_config.
path_to_underline (Optional[List[AccessPath]] = None) – Object path to be underlined
path_to_annotate (Optional[Dict[AccessPath, str]] = None) – Object path to be annotated
obj_to_underline (Optional[List[Object]] = None) – Object to be underlined
obj_to_annotate (Optional[Dict[Object, str]] = None) – Object to be annotated
- tvm.ir.assert_structural_equal(lhs, rhs, map_free_vars=False)#
Assert lhs and rhs are structurally equal to each other.
- Parameters:
lhs (Object) – The left operand.
rhs (Object) – The left operand.
map_free_vars (bool) – Whether or not shall we map free vars that does not bound to any definitions as equal to each other.
:raises ValueError : if assertion does not hold.:
See also
tvm_ffi.structural_equal
- tvm.ir.load_json(json_str) Object#
Load tvm object from json_str.
- Parameters:
json_str (str) – The json string
- Returns:
node – The loaded tvm node.
- Return type:
Object
- tvm.ir.save_json(node) str#
Save tvm object as json string.
- Parameters:
node (Object) – A TVM object to be saved.
- Returns:
json_str – Saved json string.
- Return type:
- class tvm.ir.SourceName(name)#
An identifier for a source location.
- Parameters:
name (str) – The name of the source.
- class tvm.ir.Location#
Non-null source-location metadata attached to IR nodes.
IR constructors default to the shared
UNKNOWN_LOC.
- class tvm.ir.SourceLoc(source_name, start_line, start_column, end_line, end_column)#
A source range with unchanged frontend coordinate units and endpoints.
- Parameters:
source_name (SourceName) – The name of the source.
start_line (int) – The starting line number.
start_column (int) – The starting column offset.
end_line (int) – The ending line number.
end_column (int) – The ending column offset.
- class tvm.ir.UnknownLoc#
The canonical immutable location used when source information is unavailable.
- class tvm.ir.CallSiteLoc(callee: Location, caller: Location)#
A callee’s location together with the location of its caller.
- class tvm.ir.FuncType(arg_types, ret_type)#
Function type.
A function type consists of a list of type parameters to enable the definition of generic functions, a set of type constraints which we omit for the time being, a sequence of argument types, and a return type.
- Parameters:
arg_types (List[tvm.ir.Type]) – The argument types
ret_type (tvm.ir.Type) – The return type.
- class tvm.ir.MissingType#
Type information that has not been supplied or computed.
Unlike AnyType or Void, this is not a concrete type and must be resolved before a boundary that requires fully typed IR.
- class tvm.ir.OpaqueType#
Type marker for opaque values that must be removed from finished IR.
- class tvm.ir.PointerType(element_type, storage_scope='')#
PointerType used in the low-level TIR.
- Parameters:
element_type (tvm.ir.Type) – The type of pointer’s element.
storage_scope (str) – The storage scope into which the pointer addresses.
- class tvm.ir.PrimType(dtype)#
Primitive data type in the low level IR
- Parameters:
dtype (str) – The runtime data type relates to the primtype.
Methods:
matches_code(*codes)Return whether this type has any of the given DLPack dtype codes.
matches_element_type(code, bits)Return whether this type has the given scalar element code and bits.
Return whether this type has exactly one fixed lane.
- class tvm.ir.StringType#
Semantic string type, independent of the function’s calling convention.
- class tvm.ir.TensorRegionType#
The type of a multi-dimensional
tvm.ir.TensorRegion.
- class tvm.ir.TupleType(fields, loc: Location = UnknownLoc())#
The type of tuple values.
- Parameters:
fields (List[Type]) – The fields in the tuple
- class tvm.ir.Type(loc=<MISSING>)#
The base class of all types.
__expr_methods__names methods exposed on expressions of this type. Each method receives the type instance and then the expression operand:expr.method(...)is equivalent toexpr.ty.method(expr, ...).__expr_properties__maps read-only expression property names to getters taking(type_instance, expression). Ordinary expression attributes take precedence, then declared properties, then methods. Subclasses inherit these declarations or replace them explicitly.Methods:
missing()Construct a MissingType for missing type information.
Missing()Construct a MissingType for missing type information.
same_as(other)Compares two TVM types by referential equality.
is_base_of(derived)Check if this Relax type is a base of another Relax type.
- static missing()#
Construct a MissingType for missing type information.
- static Missing()#
Construct a MissingType for missing type information.
- same_as(other)#
Compares two TVM types by referential equality.
- class tvm.ir.Call(op: Expr | str, args: list[Expr] | tuple[Expr, ...], attrs: Attrs | dict | None = None, ty_args: list[tvm.ir.Type] | tuple[tvm.ir.Type, ...] | None = None, loc: Location = UnknownLoc(), ty: Type | str | None = None)#
Core function call node.
Omitted or
Nonetyuses available result inference, or a missing type when no deduction is available. Explicit types, includingType.missing(), are preserved exactly. Inference errors propagate. Construction permits provisional IR;validate()checks the operator contract explicitly after inputs are ready.Methods:
validate()Check the registered operator contract without changing this Call.
- class tvm.ir.Constant(loc=<MISSING>, ty=<MISSING>)#
Base class of literal constants.
- class tvm.ir.GenericConst(value, ty: Type, loc: Location = UnknownLoc())#
A literal payload with an explicit expression type.
- class tvm.ir.DataTypeImm(value: str | dtype, loc: Location = UnknownLoc())#
A data type literal whose expression type is AnyType.
- class tvm.ir.ExprOperand#
Python operator surface for anything that denotes an expression.
Methods:
expr_ty()Return this expression's primitive result type.
- expr_ty()#
Return this expression’s primitive result type.
- class tvm.ir.ExprWithOp(loc=<MISSING>, ty=<MISSING>)#
Common type-directed operator behavior for core expressions.
- class tvm.ir.GlobalVar(name_hint: str)#
A global variable in the IR.
GlobalVar is used to refer to the global functions stored in the IRModule.
- Parameters:
name_hint (str) – The name of the variable.
- class tvm.ir.LambdaExpr(parameter_types, function: Callable, *, ret_type=None)#
A typed staging expression representing a lambda computation.
LambdaExpr records computations such as reduction combiners and predication rules. Its body may describe computations on runtime values.
Parameters are bound within the expression body, which may produce a scalar or tuple result. The lambda has a FuncType describing its parameter and return types.
As a StagingExpr, LambdaExpr is eliminated during compilation and does not remain in executable IR.
- Parameters:
parameter_types (list[Type]) – Explicit parameter types, in callable argument order. Primitive dtype strings and script scalar constructors are also accepted.
function (Callable) – A callable evaluated once with one fresh typed Var per supplied type. Tuple/list results become shared IR Tuple expressions.
ret_type (Type, optional) – An exact return-type check. No implicit conversion or cast is inserted.
Methods:
apply(arguments)Substitute arguments simultaneously for the lambda's bound variables.
- class tvm.ir.StagingExpr(loc=<MISSING>, ty=<MISSING>)#
A traversable expression eliminated before executable IR.
- class tvm.ir.OpaqueExpr(loc=<MISSING>, ty=<MISSING>)#
Base class for opaque values that must be removed from finished IR.
- class tvm.ir.Range(begin: Expr, end: Expr | None = None, loc: Location = UnknownLoc())#
Represent a range in TVM.
You do not need to create a Range explicitly. Python lists and tuples will be converted automatically to a Range in API functions.
- Parameters:
Note
The constructor creates the range [begin, end) if the end argument is not None. Otherwise, it creates [0, begin).
Methods:
from_min_extent(min_value, extent[, loc])Construct a Range by min and extent.
- class tvm.ir.TensorLoad(*args, **kwargs)#
An indexed load from an expression source.
TensorLoad objects are constructed by a dialect-specific helper that validates the source and derives the result type.
- class tvm.ir.TensorRegion(source: Expr, region: list[Range], ty: Type, loc: Location = UnknownLoc())#
A region of an arbitrary tensor expression.
- Parameters:
source (Expr) – The source expression.
ty (tvm.ir.Type) – The result type, including any dialect-specific subscript semantics.
loc (Location, optional) – The location of the expression in the source code.
- class tvm.ir.Tuple(fields: list[Expr] | tuple[Expr, ...], loc: Location = UnknownLoc())#
Tuple expression that groups several fields together.
- class tvm.ir.TupleGetItem(tuple_value: Expr, index: int, loc: Location = UnknownLoc())#
Get the index-th item from a tuple.
- class tvm.ir.Var(name: str | None = None, ty: Type | str | None = None, loc: Location = UnknownLoc(), *, name_hint: str | None = None)#
A canonical local variable in the IR.
- tvm.ir.is_prim_var(value: object) bool#
Return whether a value is an ordinary variable with a primitive type.
- tvm.ir.reinfer_type(call: Call) Type#
Derive a Call’s result type from its current inputs without changing the Call.
The operator must register a fixed return type or a context-free inference rule. This does not invoke the operator’s validator.
- class tvm.ir.BaseFunc(attrs, loc=<MISSING>, ty=<MISSING>)#
Base class of all functions.
Attributes:
Return the attrs member of the function.
Methods:
with_attr(attr_key_or_dict[, attr_value])Create a new copy of the function and update the attribute.
with_attrs(attr_map)Copy the IRModule and add the given attribute map to it.
without_attr(attr_key)Create a new copy of the function with an attribute without provided key.
- property attrs#
Return the attrs member of the function.
- with_attr(attr_key_or_dict, attr_value=None) BaseFunc#
Create a new copy of the function and update the attribute.
- class tvm.ir.CallingConv(value)#
Possible kinds of calling conventions.
- class tvm.ir.GlobalInfo#
Base node for all global info that can appear in the IR
Methods:
same_as(other)Overload with structural equality.
- same_as(other)#
Overload with structural equality.
- class tvm.ir.IRModule(functions=None, attrs=None, global_infos=None)#
IRModule that holds functions and type definitions.
IRModule is the basic unit for all IR transformations across the stack.
- Parameters:
functions (Optional[dict].) – Map of global var to BaseFunc
Methods:
Get items in self.functions.items() in alphabetical order.
update(other)Insert functions in another Module to current one.
update_func(var, func)Update the function corresponding to a global variable in the module.
update_global_info(name, global_info)Update global info in the module
get_global_var(name)Get a global variable in the function by name.
Collect all global vars defined in this module.
from_expr(expr[, functions])Construct a module from a standalone expression.
get_attr(attr_key)Get the IRModule attribute.
with_attr(attr_key, attr_value)Copy the IRModule and add an attribute to it.
without_attr(attr_key)Copy the IRModule and remove an attribute key and its associated value.
with_attrs(attr_map)Copy the IRModule and add the given attribute map to it.
- functions_items()#
Get items in self.functions.items() in alphabetical order.
- update(other)#
Insert functions in another Module to current one.
- Parameters:
other (IRModule) – The module to merge into the current Module.
- update_func(var, func)#
Update the function corresponding to a global variable in the module.
- Parameters:
var (GlobalVar) – The global variable.
func (tvm.ir.BaseFunc) – The function to be inserted.
- update_global_info(name, global_info)#
Update global info in the module
- Parameters:
name (str) – The name for the global info.
global_info (List[GlobalInfo]) – The global info to be updated.
- get_global_var(name)#
Get a global variable in the function by name.
- get_global_vars()#
Collect all global vars defined in this module.
- static from_expr(expr, functions=None)#
Construct a module from a standalone expression.
- get_attr(attr_key)#
Get the IRModule attribute.
- Parameters:
attr_key (str) – The attribute key.
- Returns:
attr_value – Attribute value
- Return type:
Any
- with_attr(attr_key, attr_value)#
Copy the IRModule and add an attribute to it.
- class tvm.ir.Op#
Primitive operator in the IR.
Methods:
get(op_name)Get a registered operator by name.
List registered operator names in unspecified order.
set_attr(attr_name, value[, override])Set an operator attribute.
set_signature([args, ty_args, var_args, ...])Replace this Op's argument signature and validate Call arity.
add_arg(name, doc)Append an argument's name and documentation.
add_ty_arg(name, doc)Append a type-argument name and documentation without imposing a count rule.
get_attr(attr_name)Return this Op's attribute or None; an unregistered column raises InternalError.
has_attr(attr_name)Return whether the attribute column exists in the registry.
reset_attr(attr_name)Remove this Op's current value; missing values are ignored and cached views observe removal.
set_attrs_type_key(key)Resolve and set the attribute object type key and runtime index together; an unknown key raises before updating.
- static get(op_name)#
Get a registered operator by name.
- static list_op_names()#
List registered operator names in unspecified order.
- set_attr(attr_name, value, override=False)#
Set an operator attribute.
- set_signature(args=(), *, ty_args=(), var_args=None, var_ty_args=None) 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.
- Return type:
None
- add_ty_arg(name: str, doc: str) None#
Append a type-argument name and documentation without imposing a count rule.
- get_attr(attr_name: str) object#
Return this Op’s attribute or None; an unregistered column raises InternalError.
- tvm.ir.register_op_attr(op_name, attr_key, value=None, override=False)#
Register an operator property of an operator by name.
- Parameters:
- Returns:
result – The registered value when supplied, or a decorator that registers and returns its argument. The named Op is created if it does not exist.
- Return type:
object or function
- class tvm.ir.Stmt(loc)#
Base class of all the statements.
- class tvm.ir.SeqStmt(seq: Stmt | Sequence[Stmt], loc: Location | None = None)#
Sequence of statements.
- class tvm.ir.Bind(var: Var, value: Expr, loc: Location = UnknownLoc())#
Bind node.
Bind a variable to a value in the enclosing scope. Bind has no body field. The bound variable is visible in all subsequent statements within the same enclosing scope (SeqStmt, ForNode.body, etc.).
- class tvm.ir.If(condition: Expr, then_case: Stmt | Sequence[Stmt], else_case: Stmt | Sequence[Stmt] | None, loc: Location = UnknownLoc())#
If node.
- class tvm.ir.ForKind(value)#
The kind of the for loop.
Note
ForKind can change the control flow semantics of the loop and need to be considered in all TIR passes.
- class tvm.ir.For(loop_var: Var, min: Expr, extent: Expr, kind: ForKind, body: Stmt | Sequence[Stmt], annotations: Mapping[str, Object] | None = None, step: Expr | None = None, loc: Location = UnknownLoc())#
For node.
- Parameters:
loop_var (Var) – The loop variable.
min (Expr) – The beginning value.
extent (Expr) – The length of the loop.
kind (ForKind) – The type of the for.
annotations (Optional[Mapping[str, Object]]) – Additional loop annotations interpreted by the consuming dialect.
step (Expr) – The loop step. Defaults to None, which represents one.
loc (Location, optional) – The location of the stmt in the source code.
- class tvm.ir.While(condition: Expr, body: Stmt | Sequence[Stmt], loc: Location = UnknownLoc())#
While node.
- class tvm.ir.AssertStmt(kind: StringImm, condition: Expr, message_parts: list | None = None, loc: Location = UnknownLoc())#
AssertStmt node.
- Parameters:
kind (StringImm) – The error kind, e.g. “RuntimeError”, “TypeError”, “ValueError”.
condition (Expr) – The assert condition.
message_parts (list[StringImm]) – Error message fragments, concatenated at runtime when assertion fails.
loc (Location, optional) – The location of the stmt in the source code.
- class tvm.ir.RegionStmt(op: Op | str, args: Sequence[Expr], body_params: Sequence[Var], attrs: DictAttrs | Mapping[str, Any] | None, body: Stmt | Sequence[Stmt], result_vars: Sequence[Var] | None = None, loc: Location = UnknownLoc())#
An operation with enclosing-scope operands and one lexical body.
body_paramsdefine variables visible only withinbody. Their count and types must match the operation’s requiredFRegionGetBodyParamshook. Zero-parameter regions register an empty-return hook; operations without a hook do not support region construction. Explicit parameter identities and their references inbodyare preserved.result_varsdefine variables after the region in the enclosing sequence. Attributes are evaluated outside the body-parameter scope. Direct construction and JSON serialization support result variables; structured script syntax currently supports only result-free regions.
- class tvm.ir.TensorStore(dest: Expr, indices: list[Expr], value: Expr, loc: Location = UnknownLoc())#
Store a primitive value into a tensor destination.
- class tvm.ir.Array(input_list: Iterable[T])#
Array container that represents a sequence of values in the FFI.
tvm_ffi.convert()will map python list/tuple to this class.- Parameters:
input_list – The list of values to be stored in the array.
Examples
import tvm_ffi a = tvm_ffi.Array([1, 2, 3]) assert tuple(a) == (1, 2, 3)
Notes
For structural equality and hashing, use
structural_equalandstructural_hashAPIs.See also
tvm_ffi.convert()
- class tvm.ir.Map(input_dict: Mapping[K, V])#
Map container.
tvm_ffi.convert()will map python dict to this class.- Parameters:
input_dict – The dictionary of values to be stored in the map.
Examples
import tvm_ffi amap = tvm_ffi.Map({"a": 1, "b": 2}) assert len(amap) == 2 assert amap["a"] == 1 assert amap["b"] == 2
Notes
For structural equality and hashing, use
structural_equalandstructural_hashAPIs.See also
tvm_ffi.convert()Methods:
keys()Return a dynamic view of the map's keys.
values()Return a dynamic view of the map's values.
items()Get the items from the map.
get()Get an element with a default value.
- keys() KeysView[K]#
Return a dynamic view of the map’s keys.
- values() ValuesView[V]#
Return a dynamic view of the map’s values.
- items() ItemsView[K, V]#
Get the items from the map.