Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TOSA to TTIR conversion for reshape #1475

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sgligorijevicTT
Copy link
Contributor

Add support for ReshapeOp.

closes #1474

Copy link
Contributor

@kmitrovicTT kmitrovicTT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall good, minor comments below

Comment on lines +91 to +110
matchAndRewrite(tosa::ReshapeOp srcOp, Adaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
auto outputType = mlir::cast<RankedTensorType>(srcOp.getResult().getType());
mlir::OpBuilder builder(getContext());
mlir::DenseI64ArrayAttr src_shape_attr = adaptor.getNewShapeAttr();
SmallVector<Attribute> dims;
for (int64_t dim : src_shape_attr.asArrayRef()) {
dims.push_back(builder.getI32IntegerAttr(dim));
}
auto dst_shape_attr = rewriter.getArrayAttr(dims);

auto outputTensor = rewriter.create<tensor::EmptyOp>(
srcOp.getLoc(), outputType.getShape(), outputType.getElementType());
rewriter.replaceOpWithNewOp<mlir::tt::ttir::ReshapeOp>(
srcOp, outputType, adaptor.getInput1(), outputTensor, dst_shape_attr,
rewriter.getArrayAttr(
SmallVector<Attribute>(adaptor.getOperands().size() + 1,
rewriter.getAttr<OperandConstraintAttr>(
OperandConstraint::AnyDeviceTile))));
return success();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +95 to +100
mlir::DenseI64ArrayAttr src_shape_attr = adaptor.getNewShapeAttr();
SmallVector<Attribute> dims;
for (int64_t dim : src_shape_attr.asArrayRef()) {
dims.push_back(builder.getI32IntegerAttr(dim));
}
auto dst_shape_attr = rewriter.getArrayAttr(dims);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simplify this a bit

    std::vector<int32_t> new_shape_i32;
    for (int64_t dim : outputType.getShape()) {
      new_shape_i32.push_back(static_cast<int32_t>(dim));
    }
    ArrayAttr new_shape_attr = rewriter.getI32ArrayAttr(new_shape_i32);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add TOSA to TTIR conversion for ReshapeOP
2 participants