Question about return type of build methods in TOSA operations


I am a little confused about how to build an operation. Take abs in TOSA as an example,
It has following build method:

void AbsOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type output, ::mlir::Value input1) {

My question is, why we need the output parameter? For abs operation, it is expected the output has the same with input. I don’t understand this design. Thanks for answering my question ! >w<

All the best,

tosa.abs may have a return type that is different from input’s one: llvm-project/tosa-infer-shapes.mlir at main · llvm/llvm-project · GitHub

  %0 = "tosa.abs"(%arg0) : (tensor<4xf32>) -> tensor<*xf32>
1 Like


but may I ask, what are possible valid return types? I can’t find them on the doc. Or Is there any related doc?

For most of these I’d start with the spec (⚡ TOSA) as source of truth, thereafter you often would not need to look at code to see how the dialect differs (something we can improve, I don’t think the generated dialect doc captures many of these). This dialect is more permissive to allow easier targeting from frontends.

This particular op seems like it isn’t constrained to match the spec too much, so it’ll not fail to verify on many cases that it should today. So I’d recommend looking only at spec and the parts allowed which are outside the spec I’d consider more areas for improvement.

Now, you’d rarely use this build method directly. You’d more like use OpBuilder with create and if the op implements the return type interface it would not need return type parameter (ODS generated method).


thanks for your response! Really appreciate it >w<