tvm_tirx.tirx.script.alloc_tensor#
- tvm_tirx.tirx.script.alloc_tensor(placement=None, *, ty_args, attrs=None, annotations=None, loc=UNKNOWN_LOC, ty=None)#
Allocate the tensor described by one explicit
Tensortype argument.Optional placement is an ordinary tuple operand. Allocation annotations belong to
attrs;annotationsaccepts a Python dictionary whose scalar values are normalized to typed IR constants. Under an active builder, emit one binding and return its tensor variable in anAlreadyEmittedreceipt. Parsed assignments consume this receipt automatically; programmatic code usesT.bind_(receipt)orreceipt.valueto obtain the variable without emitting another binding. Outside a builder return the allocation Call. Constructir.Call("tirx.alloc_tensor", ...)directly when a pure expression is needed inside a builder.Tensor allocation conveniences such as
T.alloc_localandT.alloc_shareduse the same receipt convention. Scalar allocation and declaration helpers instead returnAlreadyEmitted[TensorLoad]in an active builder, consumed through the same binding protocol.Examples
Parsed TVMScript uses an ordinary assignment. The allocation creates one binding, and subsequent tensor accesses use its variable.
from tvm_tirx import ir from tvm_tirx.script import tirx as T from tvm_tirx.script.ir_builder import IRBuilder @T.function(private=True) def example(): tensor = T.alloc_tensor(ty_args=[T.Tensor((4,), "int32", scope="local")]) tensor[0] = 1 tensor_type = T.Tensor((4,), "int32", scope="local") with IRBuilder() as builder: raw = ir.Call("tirx.alloc_tensor", [], ty_args=[tensor_type]) receipt = T.alloc_tensor(ty_args=[tensor_type]) tensor = T.bind_(receipt, name="tensor") assert tensor.same_as(receipt.value) binding = builder.get() assert isinstance(binding, ir.Bind) assert binding.var.same_as(tensor) assert not binding.value.same_as(raw)
- Parameters:
- Return type: