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.shapeandtensor.view(...). Strides and element offsets are described bylayout.- Parameters:
shape (sequence[Expr] or Expr) – Logical dimension extents; a single extent denotes a one-dimensional tensor.
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-1to indicate that the dimension size is auto-inferred, andview(dtype: Union[str, tvm_ffi.dtype]).- Returns:
view – The corresponding view tensor.
- 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).patternis"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 explicitview(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.
tymay supply an explicit result type;locrecords the source location.
- tvm_tirx.tirx.is_tensor_var(value) bool#
Return whether
valueis 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.
- class tvm_tirx.tirx.Cast(ty: str | PrimType, value, loc: Location = UnknownLoc())#
Convert a primitive value to another dtype while preserving its lane count.
- class tvm_tirx.tirx.Add(a: Expr, b: Expr, loc: Location = UnknownLoc())#
Add two primitive values, elementwise for vectors.
- class tvm_tirx.tirx.Sub(a: Expr, b: Expr, loc: Location = UnknownLoc())#
Subtract
bfroma, elementwise for vectors.
- class tvm_tirx.tirx.Mul(a: Expr, b: Expr, loc: Location = UnknownLoc())#
Multiply two primitive values, elementwise for vectors.
- class tvm_tirx.tirx.Div(a: Expr, b: Expr, loc: Location = UnknownLoc())#
Divide
abyb; integer division truncates toward zero.
- class tvm_tirx.tirx.Mod(a: Expr, b: Expr, loc: Location = UnknownLoc())#
Compute the remainder of integer division truncated toward zero.
- class tvm_tirx.tirx.FloorDiv(a: Expr, b: Expr, loc: Location = UnknownLoc())#
Divide
abyb, rounding the quotient down toward negative infinity.
- class tvm_tirx.tirx.FloorMod(a: Expr, b: Expr, loc: Location = UnknownLoc())#
Compute
a - FloorDiv(a, b) * b, the remainder of floor division.
- class tvm_tirx.tirx.LShift(a: Expr, b: Expr, loc: Location = UnknownLoc())#
Shift the bits of
aleft bybpositions.
- class tvm_tirx.tirx.RShift(a: Expr, b: Expr, loc: Location = UnknownLoc())#
Shift the bits of
aright bybpositions.
- class tvm_tirx.tirx.BitwiseAnd(a: Expr, b: Expr, loc: Location = UnknownLoc())#
Compute the bitwise intersection of
aandb.
- class tvm_tirx.tirx.BitwiseOr(a: Expr, b: Expr, loc: Location = UnknownLoc())#
Compute the bitwise union of
aandb.
- class tvm_tirx.tirx.BitwiseXor(a: Expr, b: Expr, loc: Location = UnknownLoc())#
Compute the bitwise exclusive-or of
aandb.
- class tvm_tirx.tirx.BitwiseNot(a: Expr, loc: Location = UnknownLoc())#
Invert every bit of the input value.
- class tvm_tirx.tirx.Min(a: Expr, b: Expr, loc: Location = UnknownLoc())#
Choose the smaller of two primitive values, elementwise for vectors.
- class tvm_tirx.tirx.Max(a: Expr, b: Expr, loc: Location = UnknownLoc())#
Choose the larger of two primitive values, elementwise for vectors.
- class tvm_tirx.tirx.EQ(a: Expr, b: Expr, loc: Location = UnknownLoc())#
Compare whether
aequalsb, elementwise for vectors.
- class tvm_tirx.tirx.NE(a: Expr, b: Expr, loc: Location = UnknownLoc())#
Compare whether
adiffers fromb, elementwise for vectors.
- class tvm_tirx.tirx.LT(a: Expr, b: Expr, loc: Location = UnknownLoc())#
Compare whether
ais less thanb, elementwise for vectors.
- class tvm_tirx.tirx.LE(a: Expr, b: Expr, loc: Location = UnknownLoc())#
Compare whether
ais at mostb, elementwise for vectors.
- class tvm_tirx.tirx.GT(a: Expr, b: Expr, loc: Location = UnknownLoc())#
Compare whether
ais greater thanb, elementwise for vectors.
- class tvm_tirx.tirx.GE(a: Expr, b: Expr, loc: Location = UnknownLoc())#
Compare whether
ais at leastb, elementwise for vectors.
- class tvm_tirx.tirx.And(a: Expr, b: Expr, loc: Location = UnknownLoc())#
Compute the conjunction of two boolean values.
- class tvm_tirx.tirx.Or(a: Expr, b: Expr, loc: Location = UnknownLoc())#
Compute the disjunction of two boolean values.
- class tvm_tirx.tirx.Not(a: Expr, loc: Location = UnknownLoc())#
Negate a boolean value, elementwise for vectors.
- 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.
- class tvm_tirx.tirx.Let(var: Var, value: Expr, body: Expr, loc: Location = UnknownLoc())#
Bind
vartovaluewithin an expression body and return the body result.
- 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
tyis a FuncType derived from parameter types andret_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.
- 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.
- 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:
- 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:
- 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:
- 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:
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:
- Returns:
call – The call expression.
- Return type:
See also
te.externCreate 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:
- Returns:
call – The call expression.
- Return type:
See also
te.externCreate tensor with extern function call.
- tvm_tirx.tirx.register_intrin_lowering(op_name, target, *, f=None, override=False)#
Register Op lowering function
- Parameters:
- 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:
- Returns:
call – The call expression.
- Return type:
See also
te.externCreate 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:
- Returns:
call – The call expression.
- Return type:
See also
te.externCreate 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:
- tvm_tirx.tirx.call_pure_extern(func_name, *args, ty, loc: Location = UnknownLoc())#
Build expression by calling a pure extern function.
- tvm_tirx.tirx.call_extern(func_name, *args, ty, loc: Location = UnknownLoc())#
Build expression by calling a extern function.
- 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_paramscontains 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
- tvm_tirx.tirx.call_llvm_pure_intrin(name, *args, ty, loc: Location = UnknownLoc())#
Build expression by calling a pure llvm intrinsic function
- tvm_tirx.tirx.all(*args, loc: Location = UnknownLoc())#
- Create a new expression of the intersection of all conditions in the
arguments
- tvm_tirx.tirx.any(*args, loc: Location = UnknownLoc())#
Create a new experssion of the union of all conditions in the arguments
- tvm_tirx.tirx.stack_alloca(dtype_str, num, *, ty=None, loc: Location = UnknownLoc())#
Return new on stack dtype[num]
- tvm_tirx.tirx.stack_make_shape(*args, ty=None, loc: Location = UnknownLoc())#
Allocate a shape tuple on stack, return the handle
- 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:
- Returns:
call – The call expression.
- Return type:
- tvm_tirx.tirx.handle_add_byte_offset(handle, offset, *, ty=None, loc: Location = UnknownLoc())#
Add offset to handle
- tvm_tirx.tirx.abi_field_get(arr, index, field, *, ty, loc: Location = UnknownLoc())#
Get struct field value in array
- tvm_tirx.tirx.abi_field_set(arr, index, field, value, *, ty=None, loc: Location = UnknownLoc())#
Set value in struct field in array
- 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:
- tvm_tirx.tirx.assume(cond=None, *, ty=None, loc: Location = UnknownLoc())#
Provide a true statement that can be used for simplifications
- 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:
- 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:
- tvm_tirx.tirx.ptr_byte_offset(data, byte_offset, *, ty, loc: Location = UnknownLoc())#
Return
data + byte_offsetwith pointer typety.byte_offsetis always in bytes.tyspecifies 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:
- 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_launchregion, 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:
- 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:
- 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:
- 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:
- Returns:
call – The call expression.
- Return type:
- tvm_tirx.tirx.vector_low(vec, *, ty, loc: Location = UnknownLoc())#
Get the low level half of the vector
- tvm_tirx.tirx.vector_high(vec, *, ty, loc: Location = UnknownLoc())#
Get the high level half of the vector
- 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.log1p(x, *, ty=None, loc: Location = UnknownLoc())#
Take log(x + 1) with respect to input x.
- tvm_tirx.tirx.clz(x)#
Count leading zero bits of an integer x.
- tvm_tirx.tirx.erf(x, *, ty=None, loc: Location = UnknownLoc())#
Take gauss error function of the input x.
- tvm_tirx.tirx.rsqrt(x, *, ty=None, loc: Location = UnknownLoc())#
Take reciprocal of square root of input x.
- tvm_tirx.tirx.floor(x: ExprWithOp, loc: Location = UnknownLoc())#
Take floor of float input x.
- tvm_tirx.tirx.hypot(x1, x2, *, ty=None, loc: Location = UnknownLoc())#
Equivalent to sqrt(x1**2 + x2**2), element-wise.
- 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.
- tvm_tirx.tirx.round(x, loc: Location = UnknownLoc())#
Round elements of the array to the nearest integer.
- tvm_tirx.tirx.nextafter(x1, x2, *, ty=None, loc: Location = UnknownLoc())#
Return the next floating-point value after x1 towards x2.
- 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
- tvm_tirx.tirx.popcount(x, *, ty=None, loc: Location = UnknownLoc())#
Count the number of set bits in input x.
- 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.
- tvm_tirx.tirx.if_then_else(cond, t, f, loc: Location = UnknownLoc())#
Conditional selection expression.
- Parameters:
- Returns:
result – The result of conditional expression.
- Return type:
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.isnullptr(x, loc: Location = UnknownLoc(), *, ty=None)#
Check if input value is nullptr.
- tvm_tirx.tirx.copysign(x1, x2, *, ty=None, loc: Location = UnknownLoc())#
Change the sign of x1 to that of x2, element-wise.
- tvm_tirx.tirx.div(a, b, loc: Location = UnknownLoc())#
Compute a / b as in C/C++ semantics.
- Parameters:
- Returns:
res – The result expression.
- Return type:
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:
- Returns:
res – The result expression.
- Return type:
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:
- Returns:
res – The result expression.
- Return type:
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:
- Returns:
res – The result expression.
- Return type:
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:
- Returns:
res – The result expression.
- Return type:
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.
- tvm_tirx.tirx.floormod(a, b, loc: Location = UnknownLoc())#
Compute the floormod of two expressions.
- tvm_tirx.tirx.logaddexp(a, b, loc: Location = UnknownLoc())#
Compute the logaddexp of two expressions.
- 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.
- tvm_tirx.tirx.shift_right(x, y, loc: Location = UnknownLoc())#
Return the result of x right shifted by y bits.
- 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:
- tvm_tirx.tirx.free_workspace(device_type, device_id, ptr, *, ty=None, loc: Location = UnknownLoc())#
Backend function to free temporal workspace.
- 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)
- tvm_tirx.tirx.get_vscale_expr(dtype: str | dtype, min_size: int = 128) Expr#
Create a datatype dependent scalable expression.
- 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:
- 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:
- Returns:
An executable combining both host and device code.
- Return type:
tvm_tirx.codegen.Executable