-
Notifications
You must be signed in to change notification settings - Fork 13
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
base: main
Are you sure you want to change the base?
Conversation
4d6355f
to
7a0e745
Compare
There was a problem hiding this 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
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1480 (comment)
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); |
There was a problem hiding this comment.
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);
Add support for ReshapeOp.
closes #1474