Help please! How can I convert a list to a tvm.tensor?


Following is my code:

x =[2, 3, 6] # x is a list
output = tvm.compute((3,),lambda i: x[i]) #convert list x to a tvm.tensor

So I want to convert a list to a tvm.tensor, but it failed with the following error:
TypeError: list indices must be integers, not Var


You might be interested in tvm’s NDArray instead


Thanks. But I want to obtain a tvm.Tensor which contains the same value as the list x, while tvm’s NDArray returns a NDArray type.


I thought of a solution shown below:
output = tvm.compute((3,), lambda i: 0.5*(i-1)*(2-i)*x[0]+i*(2-i)*x[1]+i*(i-1)*0.5*x[2])
However, it can not be used while len(x) is large.


I don’t know any other way. But the following:

You can define your list x as tvm.placeholder and create a module. Then, pass in your list x as tvm.ndArray to your module to compute the results.

Another way is, you could try x = tvm.convert(x) to convert list to tvm class.


You can use tvm.expr.Select in compute and then unroll all axes during schedule. TVM will simplify select conditions.

See examples here


Thanks a lot!
Could you please explain more about the function tvm.all()?