Core TIRx IR

Contents

Core TIRx IR#

This page lists the core IR nodes and scalar operations in the top-level namespace. Layouts, execution scopes, visitors, compilation helpers, and tile-dispatch extensions are documented on their focused pages and excluded here so the same objects are not expanded twice.

For C++ construction, include tvm/tirx/expr.h for TensorVar, tensor loads, and tensor-region constructors. Include tvm/tirx/type.h for TensorType and TensorMapType. Tensor regions use the shared TensorRegion expression from tvm/ir/expr.h and TensorRegionType from tvm/ir/type.h.

Tensor-level IR nodes, layouts, operators, analysis, and compilation.

class tvm_tirx.tirx.TensorType(shape, dtype, scope=MemoryScope('global'), align=0, layout=None, *, data=None, loc: Location = UnknownLoc(), data_alignment=None)#

The shape, element type, and storage contract of a TIRx tensor expression.

Tensor variables expose the type’s properties and operations, such as tensor.shape and tensor.view(...). Strides and element offsets are described by layout.

Parameters:
  • shape (sequence[Expr] or Expr) – Logical dimension extents; a single extent denotes a one-dimensional tensor.

  • dtype (PrimType or str) – Primitive element type.

  • scope (MemoryScope or str, optional) – Storage scope, defaulting to global memory.

  • align (int, optional) – Data-pointer alignment in bytes; zero selects the runtime default.

  • layout (Layout or str, optional) – Explicit storage mapping. "default" creates a contiguous row-major layout; None leaves the layout unspecified.

  • data (Expr, optional) – Keyword-only pointer expression whose PtrType supplies the storage scope. The pointer itself is not stored in TensorType.

  • loc (Location, optional) – The source location of the type.

  • data_alignment (int, optional) – Keyword-only spelling of align; both must agree when explicitly set.

has_default_layout(analyzer=None) → bool#

Whether the layout matches implicit row-major storage with zero origin.

Equivalent split tiles are accepted when their extent covers this shape. An optional analyzer supplies existing bindings and constraints; otherwise symbolic analysis is initialized only when structural equality is insufficient.

effective_layout()#

Return the explicit layout or infer a compact global layout.

Inference uses the full tensor shape before a region is sliced and leaves this type unchanged. Other storage scopes and noncompact global tensors require an explicit layout.

is_scalar(expr, alloc_or_decl=True)#

Check if the tensor is a scalar.

Parameters:

alloc_or_decl (bool, optional) – Whether to consider alloc_scalar and decl_scalar as scalar. True for alloc_scalar, False for decl_scalar.

Returns:

bool

Return type:

True if the tensor is a scalar, False otherwise.

ptr_to(expr, indices)#

Get the pointer to the tensor at the given indices (logical indices).

Note that the tensorload inside requires LowerTIPp pass to apply the layout to get the physical indices.

view(expr, *args, **kwargs) → Var#

Creates a new view of the tensor. (used by parser)

Supported signatures are view(*shape, layout=None), where shape can contain -1 to indicate that the dimension size is auto-inferred, and view(dtype: Union[str, tvm_ffi.dtype]).

Returns:

view – The corresponding view tensor.

Return type:

tvm_tirx.tirx.Var

permute(expr, *dims) → Var#

Permute the dimensions of the tensor.

Parameters:

dims (tuple of int) – The permutation of dimensions.

Returns:

permuted – The tensor with permuted dimensions.

Return type:

tvm_tirx.tirx.Var

rearrange(expr, pattern: str = <object object>, /, **sizes) → Var#

einops-style relayout in one line: buf.rearrange("b (2 r) -> 2 b r").

A pure reshape+permute+reshape over the SAME physical bytes, spelled as an einops pattern. Lowers to view (split lhs groups) → permute (reorder to rhs atom order) → view (merge rhs groups), so it inherits whatever the underlying axis machinery does: a plain (unswizzled) tensor collapses to a flat layout, a swizzled tensor keeps its swizzle, and a tmem tensor retains its backing address. It therefore does NOT flatten a swizzle atom — the same pattern on a swizzled SMEM tensor vs an unswizzled TMEM tensor legitimately yields different physical layouts (that is the point: rearrange acts on the operand, not a string).

pattern is "lhs -> rhs"; each side is space-separated axis names, with (a b) grouping a product axis. Every lhs group’s product must equal that input dim; at most one axis per group may be unknown (inferred from the dim), the rest supplied via **sizes. Cannot express a replica (R[...]), a stride-fiction/padded view, or a reshape crossing a swizzle-atom boundary — keep those as explicit view(layout=...).

tvm_tirx.tirx.tensor_data_ptr(tensor, *, ty=None, loc: Location = UnknownLoc())#

Project a tensor variable’s physical pointer.

The result type is inferred from its element type and storage scope. ty may supply an explicit result type; loc records the source location.

tvm_tirx.tirx.is_tensor_var(value) → bool#

Return whether value is an ordinary tvm_tirx.tirx.Var carrying TensorType.

Unlike isinstance(value, tvm_tirx.tirx.Var), this predicate distinguishes tensor variables from scalar or pointer variables.

class tvm_tirx.tirx.TensorMapType(loc: Location = UnknownLoc())#

The type of a tensor-map descriptor used by backend memory operations.

A pointer to this type represents descriptor storage, rather than a tensor’s element data. The descriptor’s shape and layout are defined by the operations that create it, not by fields on this type.

Parameters:

loc (tvm_tirx.ir.Location, optional) – The source location of the type.

tvm_tirx.tirx.convert(expr) → Expr#

Convert a scalar or sequence to primitive expressions.

class tvm_tirx.tirx.Cast(ty: str | PrimType, value, loc: Location = UnknownLoc())#

Convert a primitive value to another dtype while preserving its lane count.

Parameters:
  • ty (str | PrimType) – The target primitive type.

  • value (Expr) – The value to cast.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.Add(a: Expr, b: Expr, loc: Location = UnknownLoc())#

Add two primitive values, elementwise for vectors.

Parameters:
  • a (Expr) – The left hand operand.

  • b (Expr) – The right hand operand.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.Sub(a: Expr, b: Expr, loc: Location = UnknownLoc())#

Subtract b from a, elementwise for vectors.

Parameters:
  • a (Expr) – The left hand operand.

  • b (Expr) – The right hand operand.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.Mul(a: Expr, b: Expr, loc: Location = UnknownLoc())#

Multiply two primitive values, elementwise for vectors.

Parameters:
  • a (Expr) – The left hand operand.

  • b (Expr) – The right hand operand.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.Div(a: Expr, b: Expr, loc: Location = UnknownLoc())#

Divide a by b; integer division truncates toward zero.

Parameters:
  • a (Expr) – The left hand operand.

  • b (Expr) – The right hand operand.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.Mod(a: Expr, b: Expr, loc: Location = UnknownLoc())#

Compute the remainder of integer division truncated toward zero.

Parameters:
  • a (Expr) – The left hand operand.

  • b (Expr) – The right hand operand.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.FloorDiv(a: Expr, b: Expr, loc: Location = UnknownLoc())#

Divide a by b, rounding the quotient down toward negative infinity.

Parameters:
  • a (Expr) – The left hand operand.

  • b (Expr) – The right hand operand.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.FloorMod(a: Expr, b: Expr, loc: Location = UnknownLoc())#

Compute a - FloorDiv(a, b) * b, the remainder of floor division.

Parameters:
  • a (Expr) – The left hand operand.

  • b (Expr) – The right hand operand.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.LShift(a: Expr, b: Expr, loc: Location = UnknownLoc())#

Shift the bits of a left by b positions.

Parameters:
  • a (Expr) – The left hand operand.

  • b (Expr) – The right hand operand.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.RShift(a: Expr, b: Expr, loc: Location = UnknownLoc())#

Shift the bits of a right by b positions.

Parameters:
  • a (Expr) – The left hand operand.

  • b (Expr) – The right hand operand.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.BitwiseAnd(a: Expr, b: Expr, loc: Location = UnknownLoc())#

Compute the bitwise intersection of a and b.

Parameters:
  • a (Expr) – The left hand operand.

  • b (Expr) – The right hand operand.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.BitwiseOr(a: Expr, b: Expr, loc: Location = UnknownLoc())#

Compute the bitwise union of a and b.

Parameters:
  • a (Expr) – The left hand operand.

  • b (Expr) – The right hand operand.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.BitwiseXor(a: Expr, b: Expr, loc: Location = UnknownLoc())#

Compute the bitwise exclusive-or of a and b.

Parameters:
  • a (Expr) – The left hand operand.

  • b (Expr) – The right hand operand.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.BitwiseNot(a: Expr, loc: Location = UnknownLoc())#

Invert every bit of the input value.

Parameters:
  • a (Expr) – The input value.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.Min(a: Expr, b: Expr, loc: Location = UnknownLoc())#

Choose the smaller of two primitive values, elementwise for vectors.

Parameters:
  • a (Expr) – The left hand operand.

  • b (Expr) – The right hand operand.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.Max(a: Expr, b: Expr, loc: Location = UnknownLoc())#

Choose the larger of two primitive values, elementwise for vectors.

Parameters:
  • a (Expr) – The left hand operand.

  • b (Expr) – The right hand operand.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.EQ(a: Expr, b: Expr, loc: Location = UnknownLoc())#

Compare whether a equals b, elementwise for vectors.

Parameters:
  • a (Expr) – The left hand operand.

  • b (Expr) – The right hand operand.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.NE(a: Expr, b: Expr, loc: Location = UnknownLoc())#

Compare whether a differs from b, elementwise for vectors.

Parameters:
  • a (Expr) – The left hand operand.

  • b (Expr) – The right hand operand.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.LT(a: Expr, b: Expr, loc: Location = UnknownLoc())#

Compare whether a is less than b, elementwise for vectors.

Parameters:
  • a (Expr) – The left hand operand.

  • b (Expr) – The right hand operand.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.LE(a: Expr, b: Expr, loc: Location = UnknownLoc())#

Compare whether a is at most b, elementwise for vectors.

Parameters:
  • a (Expr) – The left hand operand.

  • b (Expr) – The right hand operand.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.GT(a: Expr, b: Expr, loc: Location = UnknownLoc())#

Compare whether a is greater than b, elementwise for vectors.

Parameters:
  • a (Expr) – The left hand operand.

  • b (Expr) – The right hand operand.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.GE(a: Expr, b: Expr, loc: Location = UnknownLoc())#

Compare whether a is at least b, elementwise for vectors.

Parameters:
  • a (Expr) – The left hand operand.

  • b (Expr) – The right hand operand.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.And(a: Expr, b: Expr, loc: Location = UnknownLoc())#

Compute the conjunction of two boolean values.

Parameters:
  • a (Expr) – The left hand operand.

  • b (Expr) – The right hand operand.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.Or(a: Expr, b: Expr, loc: Location = UnknownLoc())#

Compute the disjunction of two boolean values.

Parameters:
  • a (Expr) – The left hand operand.

  • b (Expr) – The right hand operand.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.Not(a: Expr, loc: Location = UnknownLoc())#

Negate a boolean value, elementwise for vectors.

Parameters:
  • a (Expr) – The input value

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.Select(condition: Expr, true_value: Expr, false_value: Expr, loc: Location = UnknownLoc())#

Select between two values according to a boolean condition.

Note

Select may compute both true_value and false_value. Use tvm_tirx.ir.prim.if_then_else() instead if you want to get a conditional expression that only evaluates the correct branch.

Parameters:
  • condition (Expr) – The condition expression.

  • true_value (Expr) – The value to take when condition is true.

  • false_value (Expr) – The value to take when condition is false.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.Let(var: Var, value: Expr, body: Expr, loc: Location = UnknownLoc())#

Bind var to value within an expression body and return the body result.

Parameters:
  • var (tvm_tirx.tirx.Var) – The variable in the binding.

  • value (Expr) – The value in to be bound.

  • body (Expr) – The body expression.

  • loc (Location, optional) – The location of this expression in the source code.

class tvm_tirx.tirx.Function(params, body: Stmt | Sequence[Stmt] | None, ret_type=None, attrs=None, loc: Location = UnknownLoc())#

A TIRx function definition or declaration.

The function’s ty is a FuncType derived from parameter types and ret_type. A present body is normalized to a SeqStmt.

Parameters:
  • params (list[tvm_tirx.ir.Var]) – Input parameters, in calling order.

  • body (Stmt or Sequence[Stmt] or None) – The function body, or None for a declaration without an implementation.

  • ret_type (tvm_tirx.ir.Type, optional) – The return type; defaults to MissingType until supplied or inferred.

  • attrs (tvm_tirx.ir.DictAttrs, optional) – Function attributes, empty by default.

  • loc (Location, optional) – The source location of the function.

with_body(new_body: Stmt | Sequence[Stmt] | None, loc: Location = UnknownLoc())#

Create a function with the same parameters, return type, and attributes but a new body.

Parameters:
  • new_body (Stmt | Sequence[Stmt] | None) – The new body, or None for a declaration.

  • loc (Location, optional) – The source location of the function.

Returns:

new_func – The created new function.

Return type:

Function

tvm_tirx.tirx.renew_def(func: Function) → Function#

Renew variable definitions and remap their uses in a function.

Definition regions follow the registered structural hooks. Free variables and function attributes are preserved, and the function signature is rebuilt.

Parameters:

func (Function) – The function to renew.

Returns:

The function with fresh variable definitions.

Return type:

Function

class tvm_tirx.tirx.IndexMap(initial_indices, final_indices, inverse_index_map)#

Map input index variables to expressions for output indices.

Use from_func() to derive a map from a Python callable, or supply the input variables and output expressions directly.

Parameters:
  • initial_indices (list[tvm_tirx.tirx.Var]) – Bound variables representing the input coordinates, in dimension order.

  • final_indices (list[Expr]) – Output coordinate expressions in terms of the input variables.

  • inverse_index_map (IndexMap or Callable or None) – A supplied inverse, or None to compute the inverse when requested. The caller is responsible for correctness of a supplied inverse.

static from_func(mapping_function: Callable, ndim: int | None = None, inverse_index_map: Callable | IndexMap | None = None, *, index_dtype: str = 'int64')#

Create an index map from a function

Parameters:
  • mapping_function (Callable) – The function to map from source indices to target indices. The function should accept tirx.Var parameters and return a either a tirx.Expr, or a list of tirx.Expr. Returning a tirx.Expr is equivalent to returning a list of length 1 containing that tirx.Expr.

  • ndim (Optional[int]) – The dimensionality of the tensor to which this transformation should be applied. If mapping_function uses variadic argument *args, ndim must be specified. If mapping_function does not use variadic arguments, ndim is optional.

  • inverse_index_map (Union[Callable, Optional[IndexMap]]) – The optional pre-defined inverse index map. When this is defined, IndexMap::Inverse will return the pre-defined inverse index map. Otherwise, the inverse index map will be computed on the fly. It is the user’s responsibility to ensure the correctness of the pre-defined inverse index map.

  • index_dtype (str) – The default index dtype to use for input iters in the mapping function.

Returns:

index_map – Returns an IndexMap representing the mapping_function.

Return type:

IndexMap

is_equivalent_to(other_map: IndexMap, analyzer=None) → bool#

Return if the index maps are equivalent.

Parameters:
  • other_map (IndexMap) – The IndexMap to which the comparison should be made.

  • analyzer (Optional[tvm_tirx.sym.Analyzer]) – The analyzer to use while comparing the mapped indices. When provided, its accumulated bindings and constraints are reused so that maps that are only equivalent under those bindings can be proven equal.

Returns:

is_equivalent – True if the two mappings represent the same transformation, otherwise False

Return type:

bool

map_indices(indices: list[Expr], analyzer=None) → list[Expr]#

Apply the index map to a set of indices

Parameters:
  • indices (List[Expr]) – The indices to be mapped

  • analyzer (Optional[tvm_tirx.sym.Analyzer]) – The analyzer to use while simplifying mapped indices.

Returns:

result – The mapped indices

Return type:

List[Expr]

map_shape(shape: list[Expr], analyzer=None) → list[Expr]#

Apply the index map to a tensor shape

Parameters:
  • shape (List[Expr]) – The tensor shape to be mapped

  • analyzer (Optional[tvm_tirx.sym.Analyzer]) – The analyzer to use while simplifying mapped shape expressions.

Returns:

result – The mapped shape

Return type:

List[Expr]

map_tensor(arr_src: Tensor) → Tensor#

Apply thie index map to transform the layout of the input Tensor

Parameters:

arr_src (runtime.Tensor) – The Tensor to be transformed

Returns:

arr_dst – The transformed Tensor

Return type:

runtime.Tensor

inverse(shape: list[Range | Expr], analyzer=None) → IndexMap#

Return the inverse of the map

Throws an error if the function is not bijective.

Parameters:
  • shape (List[Union[Range,Expr]]) – The region over which the inverse should be determined. Used for validating that the mapping is bijective over this range.

  • analyzer (Optional[tvm_tirx.sym.Analyzer]) – The analyzer to use while deriving and validating the inverse.

Returns:

inverse – The inverse

Return type:

IndexMap

non_surjective_inverse(shape: list[Range | Expr], analyzer=None) → tuple[IndexMap, Expr]#

Return the inverse of the map

Can be applied to transformations that introduce padding.

Parameters:
  • shape (List[Union[Range,Expr]]) – The region over which the inverse should be determined. Used for determining the predicate.

  • analyzer (Optional[tvm_tirx.sym.Analyzer]) – The analyzer to use while deriving the inverse and padding predicate.

Returns:

result – The inverse, and a predicate for which the inverse maps to a valid index in the input range.

Return type:

Tuple[IndexMap, Expr]

Examples

index_map = IndexMap.from_func(lambda i: [i//4, i%4])
inverse_map, predicate = index_map.non_surjective_inverse([14])
assert inverse_map.is_equivalent_to(IndexMap.from_func(lambda j,k: [4*j + k])
print(predicate) # Prints "(axis0==3) && (axis2 >= 2)"
tvm_tirx.tirx.call_packed_lowered(*args, loc: Location = UnknownLoc(), ty=None)#

Lowered version of call packed. The argument to a packed function can be an Expr or a tensor variable. The argument is the corresponding POD type when Expr is presented. When the argument is a tvm_tirx.tirx.Var carrying TensorType, the corresponding PackedFunc will receive an TVMArrayHandle whose content is valid during the callback period. If the PackedFunc is a python callback, then the corresponding argument is Tensor.

Parameters:
  • args (list of Expr or Var.) – Positional arguments.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

call – The call expression.

Return type:

Expr

See also

te.extern

Create tensor with extern function call.

tvm_tirx.tirx.call_cpacked_lowered(*args, loc: Location = UnknownLoc(), ty=None)#

Lowered version of call c-packed. Same as call_packed, except that the first argument is the function name (as in call_extern), and the last argument is the resource handle.

Parameters:
  • args (list of Expr or Var.) – Positional arguments.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

call – The call expression.

Return type:

Expr

See also

te.extern

Create tensor with extern function call.

tvm_tirx.tirx.register_intrin_lowering(op_name, target, *, f=None, override=False)#

Register Op lowering function

Parameters:
  • op_name (str) – The op name

  • target (str) – The target string for given intrinsic lowering function

  • f (function, optional) – The function to be registered.

  • override (bool, optional) – Replace an existing lowering if True; duplicate registration otherwise raises ValueError.

Returns:

result – The registered lowering, or a decorator if f is not supplied.

Return type:

function

tvm_tirx.tirx.call_packed(*args, loc: Location = UnknownLoc(), ty=None)#

Build expression by call an external packed function.

The argument to a packed function can be an Expr or a tensor variable. The argument is the corresponding POD type when Expr is presented.

When the argument is a tvm_tirx.tirx.Var carrying TensorType, the corresponding PackedFunc will receive an TVMArrayHandle whose content is valid during the callback period. If the PackedFunc is a python callback, then the corresponding argument is Tensor.

Parameters:
  • args (list of Expr or Var.) – Positional arguments.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

call – The call expression.

Return type:

Expr

See also

te.extern

Create tensor with extern function call.

tvm_tirx.tirx.call_cpacked(*args, loc: Location = UnknownLoc(), ty=None)#

Build expression by call an external packed function.

Same as call_packed, except that the first argument is the function name (as in call_extern), and the last argument is the resource handle.

Parameters:
  • args (list of Expr or Var.) – Positional arguments.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

call – The call expression.

Return type:

Expr

See also

te.extern

Create tensor with extern function call.

tvm_tirx.tirx.call_intrin(func_name, *args, ty: str | Type, attrs=None, loc: Location = UnknownLoc())#

Build expression by calling an intrinsic function.

Intrinsics can be overloaded with multiple data types via the intrinsic translation rule.

Parameters:
  • ty (str or tvm_tirx.ir.Type) – The data type of the result.

  • func_name (str) – The intrinsic function name.

  • args (list) – Positional arguments.

  • attrs (Optional[tvm_tirx.ir.Attrs or Dict[str, Object]]) – Additional attributes for the call.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

call – The call expression.

Return type:

Expr

tvm_tirx.tirx.call_pure_extern(func_name, *args, ty, loc: Location = UnknownLoc())#

Build expression by calling a pure extern function.

Parameters:
  • ty (str) – The data type of the result.

  • func_name (str) – The extern function name.

  • args (list) – Positional arguments.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

call – The call expression.

Return type:

Expr

tvm_tirx.tirx.call_extern(func_name, *args, ty, loc: Location = UnknownLoc())#

Build expression by calling a extern function.

Parameters:
  • ty (str) – The data type of the result.

  • func_name (str) – The extern function name.

  • args (list) – Positional arguments.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

call – The call expression.

Return type:

Expr

class tvm_tirx.tirx.CallFFIKernelAttr(launch_params=(), launch_fields=(), num_kernel_args=-1, kernel_attrs=None)#

Ordered launch tags for an explicit FFI kernel call.

tvm_tirx.tirx.call_ffi_kernel(*args, launch=None, launch_params=None, ty='int32', loc: Location = UnknownLoc())#

tvm_tirx.tirx.Call a kernel with its symbol, kernel operands, then launch values.

launch_params contains ordered tags for the launch-value suffix. Flag-only tags consume no argument, and dynamic shared-memory bytes are last when present. Host codegen may launch directly; other hosts use the existing packed-function calling convention.

tvm_tirx.tirx.call_llvm_intrin(name, *args, ty, loc: Location = UnknownLoc())#

Build expression by calling a llvm intrinsic function

Parameters:
  • ty (str) – The data type of the result.

  • name (str) – The name of the llvm intrinsic function.

  • args (list) – Positional arguments.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

call – The call expression.

Return type:

Expr

tvm_tirx.tirx.call_llvm_pure_intrin(name, *args, ty, loc: Location = UnknownLoc())#

Build expression by calling a pure llvm intrinsic function

Parameters:
  • ty (str) – The data type of the result.

  • name (str) – The name of the llvm intrinsic function.

  • args (list) – Positional arguments.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

call – The call expression.

Return type:

Expr

tvm_tirx.tirx.all(*args, loc: Location = UnknownLoc())#
Create a new expression of the intersection of all conditions in the

arguments

Parameters:
  • args (list) – List of symbolic boolean expressions

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

expr – Expression

Return type:

Expr

tvm_tirx.tirx.any(*args, loc: Location = UnknownLoc())#

Create a new experssion of the union of all conditions in the arguments

Parameters:
  • args (list) – List of symbolic boolean expressions

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

expr – Expression

Return type:

Expr

tvm_tirx.tirx.min_value(*, ty, loc: Location = UnknownLoc())#

minimum value of ty

Parameters:
  • ty (str) – The data type.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

value – The minimum value of ty.

Return type:

tvm_tirx.ir.Expr

tvm_tirx.tirx.max_value(*, ty: str, loc: Location = UnknownLoc()) → Any#

maximum value of ty

Parameters:
  • ty (str) – The data type.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

value – The maximum value of ty.

Return type:

tvm_tirx.ir.Expr

tvm_tirx.tirx.stack_alloca(dtype_str, num, *, ty=None, loc: Location = UnknownLoc())#

Return new on stack dtype[num]

Parameters:
  • dtype_str (str) – The data type of array.

  • num (int) – The size of array.

Returns:

call – The call expression.

Return type:

Expr

tvm_tirx.tirx.stack_make_shape(*args, ty=None, loc: Location = UnknownLoc())#

Allocate a shape tuple on stack, return the handle

Parameters:

args (int) – The tuple shape.

Returns:

call – The call expression.

Return type:

Expr

tvm_tirx.tirx.stack_make_dltensor(data, shape, strides, ndim, arr_dtype, elem_offset, *, ty=None, loc: Location = UnknownLoc())#

Allocate a Tensor(DLTensor) on stack, return the handle

Parameters:
  • data (Expr) – The data of array.

  • shape (Expr) – The shape of array.

  • strides (Expr) – The strides of array.

  • ndim (Expr) – The dimensions of array.

  • arr_dtype (Expr) – The data type of array.

  • elem_offse (Expr) – The element offset of array.

Returns:

call – The call expression.

Return type:

Expr

tvm_tirx.tirx.handle_add_byte_offset(handle, offset, *, ty=None, loc: Location = UnknownLoc())#

Add offset to handle

Parameters:
  • handle (Expr) – The handle.

  • offset (int) – The offset.

Returns:

call – The call expression.

Return type:

Expr

tvm_tirx.tirx.abi_field_get(arr, index, field, *, ty, loc: Location = UnknownLoc())#

Get struct field value in array

Parameters:
  • ty (str) – The date type of the result.

  • arr (StructType*) – The array of struct.

  • index (int) – The index of struct.

  • field (int) – The field of struct.

Returns:

call – The call expression.

Return type:

Expr

tvm_tirx.tirx.abi_field_set(arr, index, field, value, *, ty=None, loc: Location = UnknownLoc())#

Set value in struct field in array

Parameters:
  • arr (StructType*) – The array of struct.

  • index (int) – The index of struct.

  • field (int) – The field of struct.

  • value (Expr) – The value to be set in field.

Returns:

call – The call expression.

Return type:

Expr

tvm_tirx.tirx.address_of(obj: Var | TensorLoad, loc: Location = UnknownLoc(), *, ty=None) → Expr#

Returns the address of a tensor element or addressable variable.

Parameters:
  • obj (Union[tvm_tirx.tirx.Var, TensorLoad]) – The tensor, tensor load, or addressable variable.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

call – The call expression.

Return type:

Expr

tvm_tirx.tirx.assume(cond=None, *, ty=None, loc: Location = UnknownLoc())#

Provide a true statement that can be used for simplifications

Parameters:

cond (Expr) – The constraint condition.

Returns:

call – The call expression.

Return type:

Expr

tvm_tirx.tirx.assume_aligned(tensor, alignment_bytes, *, ty=None, loc: Location = UnknownLoc())#

Assume the tensor’s base address is aligned to alignment_bytes.

This compiler fact does not check or modify the address. The tensor must be a tensor variable and alignment a scalar integer constant, a power of two between 1 and 2**27 bytes (inclusive).

tvm_tirx.tirx.undef(*, ty=None, loc: Location = UnknownLoc())#

Returns an initialized but arbitrary value

Returns:

call – The call expression.

Return type:

Expr

tvm_tirx.tirx.gpu_thread_allreduce(combine, identity, values, predicate, destinations, thread_axes, *, ty=None, loc: Location = UnknownLoc())#

Perform an all-reduce inside a thread block.

Parameters:
  • combine (tvm_tirx.ir.LambdaExpr) – Typed combining lambda with parameters ordered as all left-hand values followed by all right-hand values. Its body returns a scalar for one result or a Tuple of results.

  • identity (Expr or Sequence[Expr]) – Identity value for each reduction result.

  • values (Expr or Sequence[Expr]) – Values contributed by the current thread.

  • predicate (PrimExpr) – Boolean participation predicate. Inactive threads contribute identities.

  • destinations (Expr or Sequence[Expr]) – Tensor loads at index zero of one-element result temporaries, optionally cast for boolean storage. Each temporary must be accessed only at index zero.

  • thread_axes (Expr or Sequence[Expr]) – Thread variables participating in the reduction.

Returns:

call – The void call expression with six explicit operands.

Return type:

Expr

tvm_tirx.tirx.ptr_byte_offset(data, byte_offset, *, ty, loc: Location = UnknownLoc())#

Return data + byte_offset with pointer type ty.

byte_offset is always in bytes. ty specifies both the result element type and storage scope.

tvm_tirx.tirx.throw_last_error(*, ty=None, loc: Location = UnknownLoc())#

Throw TVMGetLastError()

Returns:

ret – The return expression

Return type:

Expr

tvm_tirx.tirx.cpu_parallel_barrier(*, ty=None, loc: Location = UnknownLoc())#

Synchronize all workers in the current CPU parallel launch.

Every worker must reach this operation at the same program point. Place it inside a parallel_launch region, outside parallel loops, whose iteration counts can differ between workers. Writes before the barrier are visible to all workers after it.

To replace pragma_parallel_barrier_when_finish, place this operation after the former attribute body.

tvm_tirx.tirx.gpu_load_matrix_sync(fragment, m, n, k, index, buffer_ptr, stride, layout, *, ty=None, loc: Location = UnknownLoc())#

TVM intrinsic for tensor core load operators

Parameters:
  • fragment (tvm_tirx.tirx.Var) – The wmma fragment.

  • m (UIntImm) – The shape of wmma fragment.

  • n (UIntImm) – The shape of wmma fragment.

  • k (UIntImm) – The shape of wmma fragment.

  • index (Expr) – The fragment index.

  • buffer_ptr (Expr) – The fragment buffer pointer.

  • stride (Expr) – The fragment stride.

  • layout (Literal["row_major", "column_major"]) – The fragment layout.

Returns:

call – The call expression.

Return type:

Expr

tvm_tirx.tirx.gpu_store_matrix_sync(fragment, m, n, k, index, buffer_ptr, stride, layout, *, ty=None, loc: Location = UnknownLoc())#

TVM intrinsic for tensor core store operators

Parameters:
  • fragment (tvm_tirx.tirx.Var) – The wmma fragment.

  • m (UIntImm) – The shape of wmma fragment.

  • n (UIntImm) – The shape of wmma fragment.

  • k (UIntImm) – The shape of wmma fragment.

  • index (Expr) – The fragment index.

  • buffer_ptr (Expr) – The fragment buffer pointer.

  • stride (Expr) – The fragment stride.

  • layout (Literal["row_major", "column_major"]) – The fragment layout.

Returns:

call – The call expression.

Return type:

Expr

tvm_tirx.tirx.gpu_mma_sync(fragment_d, index_d, fragment_a, index_a, fragment_b, index_b, fragment_c, index_c, *, ty=None, loc: Location = UnknownLoc())#

TVM intrinsic for tensor core mma_sync operators

Parameters:
  • fragment_d (tvm_tirx.tirx.Var) – The wmma fragment_d.

  • index_d (Expr) – The fragment_d index.

  • fragment_a (tvm_tirx.tirx.Var) – The wmma fragment_a.

  • index_a (Expr) – The fragment_a index.

  • fragment_b (tvm_tirx.tirx.Var) – The wmma fragment_b.

  • index_b (Expr) – The fragment_b index.

  • fragment_c (tvm_tirx.tirx.Var) – The wmma fragment_c.

  • index_c (Expr) – The fragment_c index.

Returns:

call – The call expression.

Return type:

Expr

tvm_tirx.tirx.gpu_fill_fragment(fragment, m, n, k, index, value, *, ty=None, loc: Location = UnknownLoc())#

TVM intrinsic for tensor core fill_fragment operators

Parameters:
  • fragment (tvm_tirx.tirx.Var) – The wmma fragment

  • m (UIntImm) – The shape of wmma fragment.

  • n (UIntImm) – The shape of wmma fragment.

  • k (UIntImm) – The shape of wmma fragment.

  • index (Expr) – The fragment index.

  • value (Expr) – The value to be filled in fragment.

Returns:

call – The call expression.

Return type:

Expr

tvm_tirx.tirx.vector_low(vec, *, ty, loc: Location = UnknownLoc())#

Get the low level half of the vector

Parameters:
  • ty (str) – The data type of the result.

  • vec (list) – The input vector.

Returns:

call – The call expression.

Return type:

Expr

tvm_tirx.tirx.vector_high(vec, *, ty, loc: Location = UnknownLoc())#

Get the high level half of the vector

Parameters:
  • ty (str) – The data type of the result.

  • vec (list) – The input vector.

Returns:

call – The call expression.

Return type:

Expr

tvm_tirx.tirx.vector_combine(vec1, vec2, *, ty, loc: Location = UnknownLoc())#

Concat two vectors

Parameters:
  • vec1 (list) – The input vector.

  • vec2 (list) – The input vector.

Returns:

call – The call expression.

Return type:

Expr

tvm_tirx.tirx.infinity(*, ty: str, loc: Location = UnknownLoc()) → Any#

infinity value of ty

Parameters:
  • ty (str) – The data type.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

value – The infinity value of ty.

Return type:

tvm.Expr

tvm_tirx.tirx.reinterpret(value, *, ty, loc: Location = UnknownLoc()) → Expr#

Reinterpret a value as an exact primitive or pointer type.

Parameters:
  • ty (str or tvm_tirx.ir.Type) – The data type.

  • value (Expr) – The input value.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

value – The reinterpret cast value of ty.

Return type:

tvm.Expr

tvm_tirx.tirx.exp(x, *, ty=None, loc: Location = UnknownLoc())#

Take exponential of input x.

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.exp2(x, *, ty=None, loc: Location = UnknownLoc())#

Calculate 2**x

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.exp10(x, *, ty=None, loc: Location = UnknownLoc())#

Calculate 10**x

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.log(x, *, ty=None, loc: Location = UnknownLoc())#

Take log of input x.

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.log2(x, *, ty=None, loc: Location = UnknownLoc())#

Take log2 of input x.

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.log10(x, *, ty=None, loc: Location = UnknownLoc())#

Take log10 of input x.

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.log1p(x, *, ty=None, loc: Location = UnknownLoc())#

Take log(x + 1) with respect to input x.

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.ldexp(x1, x2, *, ty=None, loc: Location = UnknownLoc())#

Returns x1 * (2 ** x2).

Parameters:
  • x1 (Expr) – Input argument.

  • x2 (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.clz(x)#

Count leading zero bits of an integer x.

Parameters:

x (Expr) – Input 32 or 64 bit integer. The result is undefined if the input is 0.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.sin(x, *, ty=None, loc: Location = UnknownLoc())#

Take sin of input x.

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.sinh(x, *, ty=None, loc: Location = UnknownLoc())#

Take sinh of input x.

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.asin(x, *, ty=None, loc: Location = UnknownLoc())#

Take asin of input x.

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.asinh(x, *, ty=None, loc: Location = UnknownLoc())#

Take asinh of input x.

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.cos(x, *, ty=None, loc: Location = UnknownLoc())#

Take cos of input x.

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.cosh(x, *, ty=None, loc: Location = UnknownLoc())#

Take cosh of input x.

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.acos(x, *, ty=None, loc: Location = UnknownLoc())#

Take acos of input x.

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.acosh(x, *, ty=None, loc: Location = UnknownLoc())#

Take acos of input x.

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.tan(x, *, ty=None, loc: Location = UnknownLoc())#

Take tan of input x.

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.tanh(x, *, ty=None, loc: Location = UnknownLoc())#

Take hyperbolic tanh of input x.

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.atan(x, *, ty=None, loc: Location = UnknownLoc())#

Take atan of input x.

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.atan2(x1, x2, *, ty=None, loc: Location = UnknownLoc())#

Take arctan2(x1, x2).

Parameters:
  • x1 (Expr) – Input argument.

  • x2 (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.atanh(x, *, ty=None, loc: Location = UnknownLoc())#

Take atanh of input x.

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.bitwise_and(x, y, loc: Location = UnknownLoc())#

Take bitwise and of two values

Parameters:
  • x (Expr) – Left operand

  • y (Expr) – Right operand

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

res – The result.

Return type:

Expr

tvm_tirx.tirx.bitwise_not(x, loc: Location = UnknownLoc())#

Take bitwise not of input value

Parameters:
  • x (Expr) – Input operand

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

res – The result.

Return type:

Expr

tvm_tirx.tirx.bitwise_or(x, y, loc: Location = UnknownLoc())#

Take bitwise or of two values

Parameters:
  • x (Expr) – Left operand

  • y (Expr) – Right operand

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

res – The result.

Return type:

Expr

tvm_tirx.tirx.bitwise_xor(x, y, loc: Location = UnknownLoc())#

Take bitwise xor of two values

Parameters:
  • x (Expr) – Left operand

  • y (Expr) – Right operand

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

res – The result.

Return type:

Expr

tvm_tirx.tirx.erf(x, *, ty=None, loc: Location = UnknownLoc())#

Take gauss error function of the input x.

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.sigmoid(x, *, ty=None, loc: Location = UnknownLoc())#

Quick function to get sigmoid

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.sqrt(x, *, ty=None, loc: Location = UnknownLoc())#

Take square root of input x.

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.rsqrt(x, *, ty=None, loc: Location = UnknownLoc())#

Take reciprocal of square root of input x.

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.floor(x: ExprWithOp, loc: Location = UnknownLoc())#

Take floor of float input x.

Parameters:
  • x (Expr) – Input argument.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.ceil(x, loc: Location = UnknownLoc())#

Take ceil of float input x.

Parameters:
  • x (Expr) – Input argument.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.hypot(x1, x2, *, ty=None, loc: Location = UnknownLoc())#

Equivalent to sqrt(x1**2 + x2**2), element-wise.

Parameters:
  • x1 (Expr) – Input argument.

  • x2 (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.trunc(x, loc: Location = UnknownLoc())#

Get truncated value of the input.

The truncated value of the scalar x is the nearest integer i which is closer to zero than x is.

Parameters:
  • x (Expr) – Input argument.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.abs(x, loc: Location = UnknownLoc())#

Get absolute value of the input element-wise.

Parameters:
  • x (Expr) – Input argument.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.round(x, loc: Location = UnknownLoc())#

Round elements of the array to the nearest integer.

Parameters:
  • x (Expr) – Input argument.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.nextafter(x1, x2, *, ty=None, loc: Location = UnknownLoc())#

Return the next floating-point value after x1 towards x2.

Parameters:
  • x1 (Expr) – Input argument.

  • x2 (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.nearbyint(x, loc: Location = UnknownLoc())#

Round elements of the array to the nearest integer. This intrinsic uses llvm.nearbyint instead of llvm.round which is faster but will results different from te.round. Notably nearbyint rounds according to the rounding mode, whereas te.round (llvm.round) ignores that. For differences between the two see: https://en.cppreference.com/w/cpp/numeric/math/round https://en.cppreference.com/w/cpp/numeric/math/nearbyint

Parameters:
  • x (Expr) – Input argument.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.power(x, y, loc: Location = UnknownLoc())#

x power y

Parameters:
  • x (Expr) – Input argument.

  • y (Expr) – The exponent

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

z – The result.

Return type:

Expr

tvm_tirx.tirx.pow(x, y, loc: Location = UnknownLoc())#

x power y

Parameters:
  • x (Expr) – Input argument.

  • y (Expr) – The exponent

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

z – The result.

Return type:

Expr

tvm_tirx.tirx.popcount(x, *, ty=None, loc: Location = UnknownLoc())#

Count the number of set bits in input x.

Parameters:

x (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.fmod(x, y, *, ty=None, loc: Location = UnknownLoc())#

Return the remainder of x divided by y with the same sign as x.

Parameters:
  • x (Expr) – Input argument.

  • y (Expr) – Input argument.

Returns:

z – The result.

Return type:

Expr

tvm_tirx.tirx.if_then_else(cond, t, f, loc: Location = UnknownLoc())#

Conditional selection expression.

Parameters:
  • cond (Expr) – The condition

  • t (Expr) – The result expression if cond is true.

  • f (Expr) – The result expression if cond is false.

  • loc (Location, optional) – The location of this operator in the source.

Returns:

result – The result of conditional expression.

Return type:

Node

Note

Unlike Select, if_then_else will not execute the branch that does not satisfy the condition. You can use it to guard against out of bound access. Unlike Select, if_then_else cannot be vectorized if some lanes in the vector have different conditions.

tvm_tirx.tirx.likely(cond, loc: Location = UnknownLoc())#

Mark condition as likely.

Parameters:
  • cond (Expr) – Input argument.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

y – The marked expression.

Return type:

Expr

tvm_tirx.tirx.isnan(x, loc: Location = UnknownLoc(), *, ty=None)#

Check if input value is Nan.

Parameters:
  • x (Expr) – Input argument.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.isnullptr(x, loc: Location = UnknownLoc(), *, ty=None)#

Check if input value is nullptr.

Parameters:
  • x (Expr) – Input argument.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.isfinite(x, loc: Location = UnknownLoc())#

Check if input value is finite.

Parameters:
  • x (Expr) – Input argument.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.isinf(x, loc: Location = UnknownLoc())#

Check if input value is infinite.

Parameters:
  • x (Expr) – Input argument.

  • loc (Location, optional) – The location of this operator in the source code.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.copysign(x1, x2, *, ty=None, loc: Location = UnknownLoc())#

Change the sign of x1 to that of x2, element-wise.

Parameters:
  • x1 (Expr) – Input argument.

  • x2 (Expr) – Input argument.

Returns:

y – The result.

Return type:

Expr

tvm_tirx.tirx.div(a, b, loc: Location = UnknownLoc())#

Compute a / b as in C/C++ semantics.

Parameters:
  • a (Expr) – The left hand operand, known to be non-negative.

  • b (Expr) – The right hand operand, known to be non-negative.

  • loc (Location, optional) – The location of this operator in the source.

Returns:

res – The result expression.

Return type:

Expr

Note

When operands are integers, returns truncdiv(a, b, loc).

tvm_tirx.tirx.indexdiv(a, b, loc: Location = UnknownLoc())#

Compute floor(a / b) where a and b are non-negative.

Parameters:
  • a (Expr) – The left hand operand, known to be non-negative.

  • b (Expr) – The right hand operand, known to be non-negative.

  • loc (Location, optional) – The location of this operator in the source.

Returns:

res – The result expression.

Return type:

Expr

Note

Use this function to split non-negative indices. This function may take advantage of operands’ non-negativeness.

tvm_tirx.tirx.indexmod(a, b, loc: Location = UnknownLoc())#

Compute the remainder of indexdiv. a and b are non-negative.

Parameters:
  • a (Expr) – The left hand operand, known to be non-negative.

  • b (Expr) – The right hand operand, known to be non-negative.

  • loc (Location, optional) – The location of this operator in the source.

Returns:

res – The result expression.

Return type:

Expr

Note

Use this function to split non-negative indices. This function may take advantage of operands’ non-negativeness.

tvm_tirx.tirx.truncdiv(a, b, loc: Location = UnknownLoc())#

Compute the truncdiv of two expressions.

Parameters:
  • a (Expr) – The left hand operand

  • b (Expr) – The right hand operand

  • loc (Location, optional) – The location of this operator in the source.

Returns:

res – The result expression.

Return type:

Expr

Note

This is the default integer division behavior in C.

tvm_tirx.tirx.truncmod(a, b, loc: Location = UnknownLoc())#

Compute the truncmod of two expressions.

Parameters:
  • a (Expr) – The left hand operand

  • b (Expr) – The right hand operand

  • loc (Location, optional) – The location of this operator in the source.

Returns:

res – The result expression.

Return type:

Expr

Note

This is the default integer division behavior in C.

tvm_tirx.tirx.floordiv(a, b, loc: Location = UnknownLoc())#

Compute the floordiv of two expressions.

Parameters:
  • a (Expr) – The left hand operand

  • b (Expr) – The right hand operand

  • loc (Location, optional) – The location of this operator in the source.

Returns:

res – The result expression.

Return type:

Expr

tvm_tirx.tirx.floormod(a, b, loc: Location = UnknownLoc())#

Compute the floormod of two expressions.

Parameters:
  • a (Expr) – The left hand operand

  • b (Expr) – The right hand operand

  • loc (Location, optional) – The location of this operator in the source.

Returns:

res – The result expression.

Return type:

Expr

tvm_tirx.tirx.ceildiv(lhs, rhs, loc: Location = UnknownLoc())#

Generic ceildiv operator.

Parameters:
  • lhs (object) – The left operand.

  • rhs (object) – The right operand.

  • loc (Location, optional) – The location of this operator in the source.

Returns:

op – The result Expr of ceildiv operaton.

Return type:

tvm.Expr

tvm_tirx.tirx.logaddexp(a, b, loc: Location = UnknownLoc())#

Compute the logaddexp of two expressions.

Parameters:
  • a (Expr) – The left hand operand

  • b (Expr) – The right hand operand

  • loc (Location, optional) – The location of this operator in the source.

Returns:

res – The result expression.

Return type:

Expr

tvm_tirx.tirx.min(a, b, loc: Location = UnknownLoc())#

Elementwise minimum of two primitive expressions.

tvm_tirx.tirx.max(a, b, loc: Location = UnknownLoc())#

Elementwise maximum of two primitive expressions.

tvm_tirx.tirx.shift_left(x, y, loc: Location = UnknownLoc())#

Return the result of x left shifted by y bits.

Parameters:
  • x (Expr) – Input argument.

  • y (Expr) – Input argument.

Returns:

z – The result.

Return type:

Expr

tvm_tirx.tirx.shift_right(x, y, loc: Location = UnknownLoc())#

Return the result of x right shifted by y bits.

Parameters:
  • x (Expr) – Input argument.

  • y (Expr) – Input argument.

Returns:

z – The result.

Return type:

Expr

tvm_tirx.tirx.alloc_workspace(device_type, device_id, nbytes, dtype_code_hint, dtype_bits_hint, *, ty=None, loc: Location = UnknownLoc())#

Backend function to allocate temporal workspace

Parameters:
  • device_type (int) – The device type which the space will be allocated.

  • device_id (int) – The device id which the space will be allocated.

  • nbytes (int) – The size of the space requested.

  • dtype_code_hint (int) – The type code of the array elements. Only used in certain backends such as OpenGL.

  • dtype_bits_hint (int) – The type bits of the array elements. Only used in certain backends such as OpenGL.

Returns:

call – The call expression.

Return type:

Expr

tvm_tirx.tirx.free_workspace(device_type, device_id, ptr, *, ty=None, loc: Location = UnknownLoc())#

Backend function to free temporal workspace.

Parameters:
  • device_type (int) – The device type which the space will be allocated.

  • device_id (int) – The device id which the space will be allocated.

  • ptr (tvm_tirx.tirx.Var) – The result allocated space pointer.

Returns:

call – The call expression.

Return type:

Expr

tvm_tirx.tirx.vscale(*, ty=None, loc: Location = UnknownLoc())#

Get the target’s vscale value. It will be lowered to llvm.vscale intrinsic (https://llvm.org/docs/LangRef.html#llvm-vscale-intrinsic) :returns: call – tvm_tirx.tirx.Call to the vscale intrinsic :rtype: Expr

tvm_tirx.tirx.get_active_lane_mask(base, limit, *, ty, loc: Location = UnknownLoc())#

Calculate a predicate mask given an upper bound (limit) and a current value (base).

It will be lowered to the llvm.get.active.lane.mask intrinsic. (https://llvm.org/docs/LangRef.html#llvm-get-active-lane-mask-intrinsics)

Parameters:
  • ty (str) – The data type of the result.

  • base (Expr) – An expression reprsenting the base.

  • limit (Expr) – An expression representing the limit.

tvm_tirx.tirx.get_vscale_expr(dtype: str | dtype, min_size: int = 128) → Expr#

Create a datatype dependent scalable expression.

Parameters:
  • dtype (Union[str, tvm_ffi.dtype]) – Element data type.

  • min_size (int) – The minimum size of the scalable vector in bits.

tvm_tirx.tirx.gpu_dp4a(vec1, vec2, acc=0, **kwargs)#

Dot product of two int8x4 vectors and add an optional accumulator

Parameters:
  • vec1 (int8x4) – The input vector.

  • vec2 (int8x4) – The input vector.

  • acc (int32) – The accumulator.

Returns:

call – The call expression.

Return type:

Expr

tvm_tirx.tirx.ignore_loop_partition(predicate, *, ty=None, loc: Location = UnknownLoc()) → Expr#

Annotate a predicate not be considered as target condition of loop partition.

Parameters:

predicate (Expr) – The annotated predicate expression.

tvm_tirx.tirx.compile(mod: Function | IRModule, target: str | Target | None = None, pipeline: str | Pass | None = 'default') → Executable#

Compile a function or module to an executable for the target.

Parameters:
  • mod (Union[Function, IRModule]) – The input to be compiled.

  • target (Optional[Union[str, Target]]) – The target for compilation, including backend configuration defaults.

  • pipeline (Union[None, str, tvm_tirx.ir.transform.Pass]) – The pipeline to use for compilation.

Returns:

An executable combining both host and device code.

Return type:

tvm_tirx.codegen.Executable