[Frontend] Add Arithmetic Operations on Tensor
Closed this issue · 3 comments
Adding arithmetic operations to Tensor seems like weird choice. But we need to support arithmetic and comparison operations on hcl.scalar
. For example:
def core(instr, uop_mem, inp_mem, wgt_mem, acc_mem, out_mem, dram):
'''VTA core'''
opcode = hcl.scalar(instr[0:3], name='opcode')
with hcl.if_(opcode == load.VTA_OPCODE_LOAD):
load.load(instr, uop_mem, inp_mem, wgt_mem, acc_mem, dram)
with hcl.elif_(opcode == store.VTA_OPCODE_STORE):
store.store(instr, out_mem, dram)
with hcl.elif_(opcode == alu.VTA_OPCODE_ALU):
alu.alu(instr, uop_mem, acc_mem, out_mem)
with hcl.elif_(opcode == gemm.VTA_OPCODE_GEMM):
gemm.gemm(instr, uop_mem, inp_mem, wgt_mem, acc_mem, out_mem)
with hcl.elif_(opcode == finish.VTA_OPCODE_FINISH):
...
hcl.scalar
is a hcl.mlir.tensor.Tensor
object, but it should act like a scalar value.
My thoughts are that we could add operations like __add__
, __eq__
to hcl.mlir.tensor.Tensor
class. @chhzh123 What do you think?
I do not get the point here. hcl.Tensor
is just a wrapper of hcl_mlir.TensorOp
. All the operations are overloaded in hcl_mlir.TensorOp
. I think users should use .v
to access the actual value in hcl.scalar
.
I remember there was a confusion about whether to use scalar.v
or just scalar
with the old HCL. I think we can enforce using .v
in the new version, so we won't need to add operations in the Tensor wrapper
Right. Users should explicitly distinguish scalar and tensor by using .v
.