Hi, I am a mlir newbie, thanks.
I define a custom dialect and custom op like
def SumOp : Flow_Op<"sum"> {
let summary = "sum operation";
let description = [{ "flow.sum" }];
let arguments = (ins F64Tensor:$in);
let results = (outs F64:$out);
let hasCustomAssemblyFormat = 1;
let builders = [
OpBuilder<(ins "Value":$in)>
];
let assemblyFormat = "$in attr-dict `:` type($in) `to` type($out)";
}
and I want to lowing this op to affine dialect, but I do not how to write this lowering,
struct SumOpLowering : public ConversionPattern {
SumOpLowering(MLIRContext *context)
: ConversionPattern(flow::SumOp::getOperationName(), 1, context) {}
LogicalResult matchAndRewrite(Operation *op, ArrayRef<Value> operands,
ConversionPatternRewriter &rewriter) const final {
llvm::errs() << "sum op lowering\n";
auto loc = op->getLoc();
/// %0 = flow.constant dense<[1.0, 2.0, 3.0, 4.0]> : tensor<4xf64>
/// %2 = flow.sum %0: tensor<4xf64> to f64
auto input = operands[0];
input.dump();
auto inputType = input.getType().cast<mlir::ShapedType>();// memref<fxf64>
inputType.dump();
auto outputType = op->getResult(0).getType();// f64
outputType.dump();
auto shape = inputType.getShape();// [4]
assert(shape.size() == 1 && "expected 1D tensor");
auto rank = shape.size();
?
rewriter.eraseOp(op);
return success();
}
};
where can I reference related code , and how can I implenment mlir knowledge, thanks