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

Support for zero-sized dimensions in aten.empty.memory_format #134

Open
wants to merge 6 commits into
base: feature/backport_ea1_ops
Choose a base branch
from
Open
8 changes: 8 additions & 0 deletions lib/Conversion/TorchToTosa/TorchToTosa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5392,6 +5392,14 @@ LogicalResult ConvertAtenOp<AtenEmptyMemoryFormatOp>::matchAndRewrite(
auto resultType =
typeConverter->convertType(op.getType()).template cast<RankedTensorType>();

// TOSA does not allow empty dimensions, so we can't lower this while
// preserving the shape.
if (llvm::any_of(resultType.getShape(),
[](int dimSize) { return dimSize == 0; })) {
return rewriter.notifyMatchFailure(
op, "Cannot lower tensors with 0-sized dimensions to TOSA.");
}

DenseElementsAttr emptyVal;
if (op.getDtype().getType().template isa<Torch::NoneType>()) {
emptyVal = DenseFPElementsAttr::get(resultType, {0.0F});
Expand Down