How to convert f64tensor type with tosa tensor?

Hi, I’m new to MLIR and followed the toy language tutorial, in which a constant op with affine lowering is defined. I tried to add a subop for subtraction using the tosa dialect by creating a rewrite pattern:

struct SubOpLowering : public mlir::OpRewritePattern<SubOp> {
  using OpRewritePattern<SubOp>::OpRewritePattern;

  mlir::LogicalResult matchAndRewrite(SubOp op,
                                      mlir::PatternRewriter &rewritter) const final {
    auto output_type = op.getResult().getType().dyn_cast<RankedTensorType>();
    if (!output_type) {
      return failure();
    }

    rewritter.replaceOpWithNewOp<mlir::tosa::SubOp>(op, output_type, op.getOperand(0), op.getOperand(1));
    return mlir::success();
  }
};

but got an error:

error: 'tosa.sub' op operand #0 must be 0D/1D/2D/3D/4D tensor of number values, but got 'tensor<2x3xf64>'

On the first look, it seems to be tosa dialect doesn’t recognize the tensor created by the constant op defined in the toy tutorial? Could you please provide some guidance and examples on how to mix these tensor types? I read Dialect Conversion - MLIR but it doesn’t provide much details.

I’m using llvm 12.x branch compiled from source.

Hello and sorry for the delay in seeing this!

The problem here is that TOSA is a specification defined dialect, and currently only supports fp16, fp32 and bf16 among supported floating point datatypes, but not fp64 . The toy dialect appears to work univerally with double (f64) tensors only.

Thanks for the reply sjarus! This is really helpful.