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.
Namespace for Tensor-level IR
- class tvm.tirx.BufferAccessKind(value)#
Buffer access modes accepted by
buffer_access_ptr().
- class tvm.tirx.BufferType(dtype, storage_scope, shape, strides, elem_offset, data_alignment, offset_factor, layout, allocated_addr, span=<MISSING>)#
The structural type carried by an ordinary buffer variable.
- tvm.tirx.buffer_data(buffer)#
Project the physical pointer associated with a buffer variable.
- tvm.tirx.buffer_data_pointer_type(buffer)#
Return the pointer type produced by
buffer_data().
- tvm.tirx.is_buffer_var(value) bool#
Return whether
valueis an ordinary tirx.Var carrying BufferType.Use this predicate instead of
isinstance(value, Buffer).Bufferis a source-compatibility alias fortvm.ir.Varand therefore does not discriminate buffer variables from scalar or pointer variables.
- class tvm.tirx.FloatImm(dtype: str | PrimType, value: float, span: Span | None = None)#
Float constant.
- class tvm.tirx.Select(condition: Expr, true_value: Expr, false_value: Expr, span: Span | None = None)#
Select node.
Note
Select may compute both true_value and false_value. Use
tvm.tirx.if_then_elseinstead if you want to get a conditional expression that only evaluates the correct branch.
- tvm.tirx.BufferLoad(buffer: Var, indices: list[Expr], span: Span | None = None) TensorLoad#
Construct a validated buffer load.
- class tvm.tirx.Shuffle(vectors: list[Expr], indices: list[Expr], span: Span | None = None)#
Shuffle node.
- class tvm.tirx.CallEffectKind#
Possible kinds of tirx.Call effects.
- class tvm.tirx.IterVar(dom: Range, var: Var | str, iter_type: int, thread_tag: str = '', span: Span | None = None)#
Represent iteration variable.
IterVar represents axis iterations in the computation.
- Parameters:
See also
te.thread_axisCreate thread axis IterVar.
te.reduce_axisCreate reduce axis IterVar.
- class tvm.tirx.Stmt(span)#
Base class of all the statements.
- class tvm.tirx.Bind(var: Var, value: Expr, span: Span | None = None)#
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.tirx.AssertStmt(kind: StringImm, condition: Expr, message_parts: list | None = None, span: Span | None = None)#
AssertStmt node.
- Parameters:
- class tvm.tirx.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.tirx.For(loop_var: Var, min: Expr, extent: Expr, kind: ForKind, body: Stmt, thread_binding: IterVar | None = None, annotations: Mapping[str, Object] | None = None, step: Expr | None = None, span: Span | None = None)#
For node.
- Parameters:
loop_var (tirx.Var) – The loop variable.
min (Expr) – The beginning value.
extent (Expr) – The length of the loop.
kind (ForKind) – The type of the for.
body (Stmt) – The body statement.
thread_binding (Optional[tirx.IterVar]) – The thread this loop binds to. Only valid if kind is ThreadBinding
step (Expr) – The loop step. Default to none which represent one.
annotations (Optional[Mapping[str, Object]]) – Additional annotation hints.
span (Optional[Span]) – The location of the stmt in the source code.
- class tvm.tirx.BufferStore(buffer: Var, value: Expr, indices: list[Expr], span: Span | None = None)#
Buffer store node.
- class tvm.tirx.AllocBuffer(buffer: Var, *args, **kwargs)#
AllocBuffer node.
Allocates a buffer and declares it in scope.
- class tvm.tirx.AttrStmt(node: Any, attr_key: str, value: Expr, body: Stmt, span: Span | None = None)#
AttrStmt node.
- class tvm.tirx.IfThenElse(condition: Expr, then_case: Stmt, else_case: Stmt | None, span: Span | None = None)#
IfThenElse node.
- class tvm.tirx.BufferRegion(buffer: Var, region: list[Range])#
BufferRegion node.
- Parameters:
buffer (Buffer) – The buffer of the buffer region
region (List[Range]) – The region array of the buffer region
- class tvm.tirx.BufferRegionType#
The structural type of a
BufferRegionexpression.
- class tvm.tirx.MatchBufferRegion(buffer: Var, source: BufferRegion)#
MatchBufferRegion node.
- Parameters:
buffer (Buffer) – The target buffer
source (BufferRegion) – The region of source buffer
- class tvm.tirx.SBlock(iter_vars: list[IterVar], reads: list[BufferRegion], writes: list[BufferRegion], name_hint: str, body: Stmt, init: Stmt | None = None, alloc_buffers: list[Var] | None = None, match_buffers: list[MatchBufferRegion] | None = None, annotations: Mapping[str, Object] | None = None, span: Span | None = None)#
SBlock node.
- Parameters:
iter_vars (List[IterVar]) – The block Variable.
reads (List[BufferRegion]) – The read buffer regions of the block.
writes (List[BufferRegion]) – The write buffer regions of the block.
name_hint (str) – the name_hint of the block.
body (Stmt) – The body of the block.
init (Optional[Stmt]) – The init block of the reduction block
alloc_buffers (Optional[list[Buffer]]) – The buffer allocations
match_buffers (Optional[List[MatchBufferRegion]]) – The subregion buffer match
annotations (Optional[Mapping[str, Object]]) – Additional annotation hints.
span (Optional[Span]) – The location of this block in the source code.
- class tvm.tirx.SBlockRealize(iter_values: list[Expr], predicate: Expr | bool, block: SBlock, span: Span | None = None)#
SBlockRealize node.
- class tvm.tirx.ScopeIdDefStmt(def_: ScopeIdDef, span: Span | None = None)#
ScopeIdDefStmt node.
Leaf statement that introduces scope-identifier vars (
wg_id = Tx.warpgroup_id([N]),warp_id = Tx.warp_id_in_wg([4]),lane_id = Tx.lane_id([32]), …) at the kernel-body top level. The underlyingScopeIdDefcarries the def vars, their extents, and the parent/child scope binding.Note: the C++ field is named
def(a Python keyword). Access it viagetattr(stmt, "def")orstmt.__getattribute__("def")— the type-annotation alias here is purely for documentation.- Parameters:
def (ScopeIdDef) – The scope-id definition (def vars, extents, scope binding).
span (Optional[Span]) – The location of this statement in the source code.
- class tvm.tirx.LambdaExpr(f_pred: Callable[[...], Expr])#
A reified Python lambda: bound variables and a body over them.
Used by tile primitive ops that take a per-element expression over the destination axes (e.g.
tirx.tile.select).
- class tvm.tirx.TilePrimitiveCall(*args: list[Expr], op: Op | None = None, workspace: dict[str, Var] | None = None, config: dict[str, Any] | None = None, dispatch: str | None = None, scope: ExecScope | None = None)#
TilePrimitiveCall node.
- Parameters:
- replace(**changes: Any) TilePrimitiveCall#
Return a copy of this call with selected fields replaced.
Every field that is not overridden in
changesis preserved fromself(includingscope), so rebuilds never silently drop fields. The returned node is downcast to the registered subclass forop.- Parameters:
**changes (Any) – Field overrides; any of
op,args,workspace,config,dispatch,scope.- Returns:
new_call – A new call with the requested fields replaced.
- Return type:
- with_workspace(workspace: dict[str, Var]) TilePrimitiveCall#
Return a copy with
workspacereplaced, preserving all other fields.
- get_private_buffers(buffer_dict: dict[Any, tuple[Var, Stmt | None]], sctx: DispatchContext) dict[str, Any]#
Create private (intermediate) buffers needed in this operator.
- Parameters:
buffer_dict (Dict[Any, Tuple[Buffer, Optional[Stmt]]]) – A dictionary containing private buffers (and their init stmts) in other operators. Key can be anything to reference the buffer. This is used to reuse private buffers in other operators (like identity tensor etc.). If the buffer is not found in the buffer_dict, it will be created and added to the buffer_dict. If the buffer is found in the buffer_dict but smaller than required, it will be enlarged and updated.
sctx (DispatchContext) – The dispatch context. This is used to get the target and reuse op dispatch implementations.
Returns
-------
private_buffer_refs (Dict[str, Any]) – The references to private buffers created in this operator. Key will be the name to add into workspace. private buffer can be accessed by buffer_dict[private_buffer_refs[name]]
- class tvm.tirx.PrimFunc(params, body, ret_type=None, attrs=None, span=None)#
A function declaration expression.
- Parameters:
params (List[Union[tvm.tirx.Var, tvm.tirx.Buffer]]) – List of input parameters to the function.
body (tvm.tirx.Stmt) – The body of the function.
ret_type (tvm.ir.Type) – The return type annotation of the function.
attrs (Optional[tvm.Attrs]) – Attributes of the function, can be None
span (Optional[Span]) – The location of this itervar in the source code.
- with_body(new_body, span=None)#
Create a new PrimFunc with the same set signatures but a new body.
- specialize(param_map: Mapping[Var, Expr | Var])#
Specialize parameters of PrimFunc
- Parameters:
param_map (Mapping[tirx.Var, Union[Expr, Buffer]]) – The mapping from function params to the instance
Examples
We can define a Meta TIR function with symbolic shape:
@T.prim_func(s_tir=True) def mem_copy(a: T.handle, b: T.handle, m: T.int32, n: T.int32) -> None: A = T.match_buffer(a, (m, n), "float32") B = T.match_buffer(b, (m, n), "float32") for i, j in T.grid(m, n): with T.sblock(): vi, vj = T.axis.remap("SS", [i, j]) B[vi, vj] = A[vi, vj]
Then we can make it specialized with given shapes or buffers.
a, _, m, n = mem_copy.params func = mem_copy.specialize({a: tirx.decl_buffer((16, 16))}) # or func = mem_copy.specialize({n: 16, m: 16})
The specialized function:
@T.prim_func(s_tir=True) def mem_copy_16_16(a: T.handle, b: T.handle) -> None: A = T.match_buffer(a, (16, 16), "float32") B = T.match_buffer(b, (16, 16), "float32") for i, j in T.grid(16, 16): with T.sblock(): vi, vj = T.axis.remap("SS", [i, j]) B[vi, vj] = A[vi, vj]
- Returns:
func – The new function with parameter specialized
- Return type:
- class tvm.tirx.TensorIntrin(desc, impl)#
A tensor intrinsic.
- Parameters:
- static register(name: str, desc: PrimFunc, impl: PrimFunc, override: bool = False)#
Register a tensor intrinsic with its name.
- static get(name: str, allow_missing: bool = False) TensorIntrin | None#
Look up a tensor intrinsic by its name.
- Parameters:
- Returns:
result – The TensorIntrin with the specified name, or None if not found.
- Return type:
Optional[TensorIntrin]
- class tvm.tirx.IndexMap(initial_indices, final_indices, inverse_index_map)#
A mapping from multi-dimensional indices to another set of multi-dimensional indices
- Parameters:
initial_indices (List[tirx.Var]) – Variables representing the indices prior to remapping.
final_indices (List[Expr]) – Expressions defining the indices after remapping.
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.
- 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 buffer 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.arith.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.arith.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 buffer shape
- Parameters:
shape (List[Expr]) – The buffer shape to be mapped
analyzer (Optional[tvm.arith.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.arith.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.arith.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.call_packed_lowered(*args, span=None)#
Lowered version of call packed. The argument to packed function can be Expr or Buffer. The argument is the corresponding POD type when Expr is presented. When the argument is Buffer, 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.call_cpacked_lowered(*args, span=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.call_tir(global_var: GlobalVar, *args)#
Performs a call into another PrimFunc in the same IRModule
- Returns:
call – The call expression.
- Return type:
- tvm.tirx.call_packed(*args, span=None)#
Build expression by call an external packed function.
The argument to packed function can be Expr or Buffer. The argument is the corresponding POD type when Expr is presented.
When the argument is Buffer, 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.call_cpacked(*args, span=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.call_intrin(dtype: str | Type, func_name, *args, attrs=None, span=None)#
Build expression by calling an intrinsic function.
Intrinsics can be overloaded with multiple data types via the intrinsic translation rule.
- Parameters:
dtype (str or tvm.ir.Type) – The data type of the result.
func_name (str) – The intrinsic function name.
args (list) – Positional arguments.
attrs (Optional[tvm.ir.Attrs or Dict[str, Object]]) – Additional attributes for the call.
span (Optional[Span]) – The location of this operator in the source code.
- Returns:
call – The call expression.
- Return type:
- tvm.tirx.call_pure_extern(dtype, func_name, *args, span=None)#
Build expression by calling a pure extern function.
- tvm.tirx.call_extern(dtype, func_name, *args, span=None)#
Build expression by calling a extern function.
- tvm.tirx.call_llvm_intrin(dtype, name, *args, span=None)#
Build expression by calling a llvm intrinsic function
- tvm.tirx.call_llvm_pure_intrin(dtype, name, *args, span=None)#
Build expression by calling a pure llvm intrinsic function
- tvm.tirx.all(*args, span=None)#
- Create a new expression of the intersection of all conditions in the
arguments
- tvm.tirx.any(*args, span=None)#
Create a new experssion of the union of all conditions in the arguments
- tvm.tirx.min_value(dtype, span=None)#
minimum value of dtype
- tvm.tirx.trace(args, trace_action='tvm.default_trace_action')#
Trace tensor data at the runtime.
The trace function allows to trace specific tensor at the runtime. The tracing value should come as last argument. The trace action should be specified, by default tvm.default_trace_action is used.
- Parameters:
- Returns:
call – The call expression.
- Return type:
See also
tvm.tirx.call_packedCreates packed function.
- tvm.tirx.tvm_stack_alloca(dtype_str, num)#
Return new on stack dtype[num]
- tvm.tirx.tvm_stack_make_shape(*args)#
Allocate a shape tuple on stack, return the handle
- tvm.tirx.tvm_stack_make_array(data, shape, strides, ndim, arr_dtype, elem_offset)#
Allocate a Tensor(DLTensor) on stack, return the handle
- Parameters:
- Returns:
call – The call expression.
- Return type:
- tvm.tirx.tvm_tuple(*value)#
Create a tuple structure in value field of AttrStmt
- tvm.tirx.handle_add_byte_offset(handle, offset)#
Add offset to handle
- tvm.tirx.tvm_struct_get(arr, index, field, dtype)#
Get struct field value in array
- tvm.tirx.tvm_struct_set(arr, index, field, value)#
Set value in struct field in array
- tvm.tirx.address_of(obj: Var | TensorLoad, span: Span | None = None) Expr#
Returns the address of a buffer element or addressable variable.
- Parameters:
obj (Union[Buffer, TensorLoad, tirx.Var]) – The buffer, buffer load, or addressable variable.
span (Optional[Span]) – The location of this operator in the source code.
- Returns:
call – The call expression.
- Return type:
- tvm.tirx.lookup_param(param_name, span=None)#
Returns the param by name
- tvm.tirx.assume(cond=None)#
Provide a true statement that can be used for simplifications
- tvm.tirx.undef()#
Returns an initialized but arbitrary value
- Returns:
call – The call expression.
- Return type:
- tvm.tirx.continue_loop(span=None)#
Create a tir intrinsic call to represent continue expression
- tvm.tirx.break_loop(span=None)#
Create a tir intrinsic call to represent break expression
- tvm.tirx.tvm_thread_allreduce(*freduce_args)#
Perform allreduce inside threadblock.
- tvm.tirx.type_annotation(dtype)#
Create a type annotation expression
- tvm.tirx.tvm_access_ptr(ptype, data, offset, extent, rw_mask)#
Get head access address with memory access pattern info
- Parameters:
ptype (Expr, PrimType, or str) – The data type of pointer. If a
PrimTypeorstr, it is wrapped viatype_annotation()so that the lowering rule (which readsargs[0].dtype()for the cast type) sees the intended dtype instead ofvoidfrom a raw StringImm.data (DType*) – The data of pointer.
offset (int) – The offset of pointer.
extent (int) – The extent of pointer.
rw_mask (int) – The read write mask.
- Returns:
call – The call expression.
- Return type:
- tvm.tirx.ptr_byte_offset(data, byte_offset, dtype)#
Cast
data + byte_offsettodtype*.byte_offsetis always in bytes. Use this when the source CUDA shape needs an explicitly typed local pointer derived from a byte-addressed base.
- tvm.tirx.tvm_throw_last_error()#
Throw TVMGetLastError()
- Returns:
ret – The return expression
- Return type:
- tvm.tirx.tvm_load_matrix_sync(fragment, m, n, k, index, buffer_ptr, stride, layout)#
TVM intrinsic for tensor core load operators
- Parameters:
fragment (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.tvm_store_matrix_sync(fragment, m, n, k, index, buffer_ptr, stride, layout)#
TVM intrinsic for tensor core store operators
- Parameters:
fragment (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.tvm_mma_sync(fragment_d, index_d, fragment_a, index_a, fragment_b, index_b, fragment_c, index_c)#
TVM intrinsic for tensor core mma_sync operators
- Parameters:
fragment_d (tirx.Var) – The wmma fragment_d.
index_d (Expr) – The fragment_d index.
fragment_a (tirx.Var) – The wmma fragment_a.
index_a (Expr) – The fragment_a index.
fragment_b (tirx.Var) – The wmma fragment_b.
index_b (Expr) – The fragment_b index.
fragment_c (tirx.Var) – The wmma fragment_c.
index_c (Expr) – The fragment_c index.
- Returns:
call – The call expression.
- Return type:
- tvm.tirx.tvm_bmma_sync(fragment_d, index_d, fragment_a, index_a, fragment_b, index_b, fragment_c, index_c)#
TVM intrinsic for tensor core bmma_sync operators
- Parameters:
fragment_d (tirx.Var) – The bwmma fragment_d.
index_d (Expr) – The fragment_d index.
fragment_a (tirx.Var) – The bwmma fragment_a.
index_a (Expr) – The fragment_a index.
fragment_b (tirx.Var) – The bwmma fragment_b.
index_b (Expr) – The fragment_b index.
fragment_c (tirx.Var) – The bwmma fragment_c.
index_c (Expr) – The fragment_c index.
- Returns:
call – The call expression.
- Return type:
- tvm.tirx.tvm_fill_fragment(fragment, m, n, k, index, value)#
TVM intrinsic for tensor core fill_fragment operators
- Parameters:
- Returns:
call – The call expression.
- Return type:
- tvm.tirx.vectorlow(dtype, vec)#
Get the low level half of the vector
- tvm.tirx.vectorhigh(dtype, vec)#
Get the high level half of the vector
- tvm.tirx.vectorcombine(dtype, vec1, vec2)#
Concat two vectors
- tvm.tirx.reinterpret(dtype, value, span: Span | None = None) Expr#
Reinterpret a value as an exact primitive or pointer type.
- Parameters:
dtype (str or tvm.ir.Type) – The data type.
value (Expr) – The input value.
span (Optional[Span]) – The location of this operator in the source code.
- Returns:
value – The reinterpret cast value of dtype.
- Return type:
tvm.Expr
- tvm.tirx.exp(x)#
Take exponential of input x.
- tvm.tirx.exp2(x)#
Calculate 2**x
- tvm.tirx.exp10(x)#
Calculate 10**x
- tvm.tirx.log(x)#
Take log of input x.
- tvm.tirx.log2(x)#
Take log2 of input x.
- tvm.tirx.log10(x)#
Take log10 of input x.
- tvm.tirx.log1p(x)#
Take log(x + 1) with respect to input x.
- tvm.tirx.ldexp(x1, x2)#
Returns x1 * (2 ** x2).
- tvm.tirx.clz(x)#
Count leading zero bits of an integer x.
- tvm.tirx.sin(x)#
Take sin of input x.
- tvm.tirx.sinh(x)#
Take sinh of input x.
- tvm.tirx.asin(x)#
Take asin of input x.
- tvm.tirx.asinh(x)#
Take asinh of input x.
- tvm.tirx.cos(x)#
Take cos of input x.
- tvm.tirx.cosh(x)#
Take cosh of input x.
- tvm.tirx.acos(x)#
Take acos of input x.
- tvm.tirx.acosh(x)#
Take acos of input x.
- tvm.tirx.tan(x)#
Take tan of input x.
- tvm.tirx.tanh(x)#
Take hyperbolic tanh of input x.
- tvm.tirx.atan(x)#
Take atan of input x.
- tvm.tirx.atan2(x1, x2)#
Take arctan2(x1, x2).
- tvm.tirx.atanh(x)#
Take atanh of input x.
- tvm.tirx.bitwise_and(x, y, span=None)#
Take bitwise and of two values
- tvm.tirx.bitwise_not(x, span=None)#
Take bitwise not of input value
- tvm.tirx.bitwise_or(x, y, span=None)#
Take bitwise or of two values
- tvm.tirx.bitwise_xor(x, y, span=None)#
Take bitwise xor of two values
- tvm.tirx.erf(x)#
Take gauss error function of the input x.
- tvm.tirx.sigmoid(x)#
Quick function to get sigmoid
- tvm.tirx.sqrt(x)#
Take square root of input x.
- tvm.tirx.rsqrt(x)#
Take reciprocal of square root of input x.
- tvm.tirx.floor(x: ExprWithOp, span=None)#
Take floor of float input x.
- tvm.tirx.ceil(x, span=None)#
Take ceil of float input x.
- tvm.tirx.hypot(x1, x2)#
Equivalent to sqrt(x1**2 + x2**2), element-wise.
- tvm.tirx.trunc(x, span=None)#
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.abs(x, span=None)#
Get absolute value of the input element-wise.
- tvm.tirx.round(x, span=None)#
Round elements of the array to the nearest integer.
- tvm.tirx.nextafter(x1, x2)#
Return the next floating-point value after x1 towards x2.
- tvm.tirx.nearbyint(x, span=None)#
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.power(x, y, span=None)#
x power y
- tvm.tirx.pow(x, y, span=None)#
x power y
- tvm.tirx.popcount(x)#
Count the number of set bits in input x.
- tvm.tirx.fmod(x, y)#
Return the remainder of x divided by y with the same sign as x.
- tvm.tirx.if_then_else(cond, t, f, span=None)#
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.likely(cond, span=None)#
Mark condition as likely.
- tvm.tirx.isnan(x, span=None)#
Check if input value is Nan.
- tvm.tirx.isnullptr(x, span=None)#
Check if input value is nullptr.
- tvm.tirx.isfinite(x, span=None)#
Check if input value is finite.
- tvm.tirx.isinf(x, span=None)#
Check if input value is infinite.
- tvm.tirx.copysign(x1, x2)#
Change the sign of x1 to that of x2, element-wise.
- tvm.tirx.div(a, b, span=None)#
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, span).
- tvm.tirx.indexdiv(a, b, span=None)#
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.indexmod(a, b, span=None)#
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.truncdiv(a, b, span=None)#
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.truncmod(a, b, span=None)#
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.floordiv(a, b, span=None)#
Compute the floordiv of two expressions.
- tvm.tirx.floormod(a, b, span=None)#
Compute the floormod of two expressions.
- tvm.tirx.ceildiv(lhs, rhs, span=None)#
Generic ceildiv operator.
- tvm.tirx.logaddexp(a, b, span=None)#
Compute the logaddexp of two expressions.
- tvm.tirx.comm_reducer(fcombine, fidentity, name='reduce')#
Create a commutative reducer for reduction.
- Parameters:
fcombine (function(Expr -> Expr -> Expr)) – A binary function which takes two Expr as input to return a Expr.
fidentity (function(str -> Expr)) – A function which takes a type string as input to return a const Expr.
- Returns:
reducer – A function which creates a reduce expression over axis. There are two ways to use it:
accept (expr, axis, where) to produce an Reduce Expr on specified axis;
simply use it with multiple Exprs.
- Return type:
function
Example
n = te.var("n") m = te.var("m") mysum = te.comm_reducer(lambda x, y: x+y, lambda t: tvm.tirx.const(0, dtype=t), name="mysum") A = te.placeholder((n, m), name="A") k = te.reduce_axis((0, m), name="k") B = te.compute((n,), lambda i: mysum(A[i, k], axis=k), name="B")
- tvm.tirx.min(expr, axis, where=None, init=None, *args)#
Create a min expression over axis.
- Parameters:
- Returns:
value – The result value.
- Return type:
Example
m = te.var("m") n = te.var("n") A = te.placeholder((m, n), name="A") k = te.reduce_axis((0, n), name="k") # there are two way to use this min reducer: # mode 1, accept (expr, axis, where) to produce an Reduce Expr # tvm.min represents tvm.te.min or tvm.tirx.min. B = te.compute((m,), lambda i: tvm.min(A[i, k], axis=k), name="B") # mode 2, simply use it with multiple Exprs: min_res = tvm.min(m, n)
- tvm.tirx.max(expr, axis, where=None, init=None, *args)#
Create a max expression over axis.
- Parameters:
- Returns:
value – The result value.
- Return type:
Example
m = te.var("m") n = te.var("n") A = te.placeholder((m, n), name="A") k = te.reduce_axis((0, n), name="k") # there are two way to use this max reducer: # mode 1, accept (expr, axis, where) to produce an Reduce Expr # tvm.max represents tvm.te.max or tvm.tirx.max. B = te.compute((m,), lambda i: tvm.max(A[i, k], axis=k), name="B") # mode 2, simply use it with multiple Exprs: max_res = tvm.max(m, n)
- tvm.tirx.sum(expr, axis, where=None, init=None, *args)#
Create a sum expression over axis.
- Parameters:
- Returns:
value – The result value.
- Return type:
Example
m = te.var("m") n = te.var("n") A = te.placeholder((m, n), name="A") k = te.reduce_axis((0, n), name="k") # there are two way to use this sum reducer: # mode 1, accept (expr, axis, where) to produce an Reduce Expr # tvm.sum represents tvm.te.sum or tvm.tirx.sum. B = te.compute((m,), lambda i: tvm.sum(A[i, k], axis=k), name="B") # mode 2, simply use it with multiple Exprs: sum_res = tvm.sum(m, n)
- tvm.tirx.q_multiply_shift(x, y, q, s)#
Execute a multiplication between two Q-numbers x and y followed by a right shift s. The mathematical expression is:
out = round(x*y*2^-s)
More about Q-numbers here: https://en.wikipedia.org/wiki/Q_(number_format) The rounding rule is to the nearest value, rounding half up (i.e., round(x.1) = x and round (x.5) = x+1)
- tvm.tirx.q_multiply_shift_per_axis(x: Expr, y: Expr, ls: Expr, rs: Expr, q: IntImm, is_lshift_required: IntImm, is_rshift_required: IntImm)#
Execute a multiplication between two Q-numbers x and y
- Parameters:
x (Expr) – First Q-number.
y (Expr) – Second Q-number.
ls (Expr) – Integer left shift.
rs (Expr) – Integer right shift.
q (IntImm) – Number of fractional bits in x and y. Needs to be > 0.
is_lshift_required (IntImm) – Whether we need to do left shift or not.
is_rshift_required (IntImm) – Whether we need to do right shift or not.
- Returns:
z – The result.
- Return type:
- tvm.tirx.shift_left(x, y, span=None)#
Return the result of x left shifted by y bits.
- tvm.tirx.shift_right(x, y, span=None)#
Return the result of x right shifted by y bits.
- tvm.tirx.TVMBackendAllocWorkspace(device_type, device_id, nbytes, dtype_code_hint, dtype_bits_hint)#
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.TVMBackendFreeWorkspace(device_type, device_id, ptr)#
Backend function to free temporal workspace.
- tvm.tirx.start_profile_intrinsic(id)#
Start profile intrinsic. :param id: The intrinsic id. :type id: int
- Returns:
call – The call expression.
- Return type:
- tvm.tirx.end_profile_intrinsic(id)#
End profile intrinsic. :param id: The intrinsic id. :type id: int
- Returns:
call – The call expression.
- Return type:
- tvm.tirx.vscale()#
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 – tirx.Call to the vscale intrinsic :rtype: Expr
- tvm.tirx.get_active_lane_mask(dtype, base, limit)#
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.get_vscale_expr(dtype: str | dtype, min_size: int = 128) Expr#
Create a datatype dependent scalable expression.
- tvm.tirx.dp4a(vec1, vec2, acc=0)#
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: