Skip to content

Commit dad20ea

Browse files
author
Hariprasad Ravishankar
committed
Notify failure during torch-to-tosa when empty.memory_format has tensor with some dimensions being 0 dim
1 parent 4e7f204 commit dad20ea

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/Conversion/TorchToTosa/TorchToTosa.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6435,6 +6435,11 @@ class ConvertAtenConstPatternOp : public OpConversionPattern<AtenOpT> {
64356435
for (auto s : shape)
64366436
size *= s;
64376437

6438+
if (size == 0) {
6439+
return rewriter.notifyMatchFailure(
6440+
op, "Shape must not have a dimension of size zero");
6441+
}
6442+
64386443
SmallVector<int32_t> values(size, fillVal);
64396444
auto constOp =
64406445
tosa::getConstTensor<int32_t>(rewriter, op, values, shape).value();

test/Conversion/TorchToTosa/torch-backend-to-tosa-backend-pipeline.mlir

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,17 @@ func.func @torch.prim.TupleConstruct() {
138138
torch.prim.Print(%0) : !torch.tuple<int>
139139
return
140140
}
141+
142+
// -----
143+
func.func @torch.aten.empty.memory_format() -> !torch.vtensor<[1,0,256],f32>{
144+
%c1 = torch.constant.int 1
145+
%c0 = torch.constant.int 0
146+
%c256 = torch.constant.int 256
147+
%2452 = torch.prim.ListConstruct %c1, %c0, %c256 : (!torch.int, !torch.int, !torch.int) -> !torch.list<int>
148+
%none = torch.constant.none
149+
%cpu = torch.constant.device "cpu"
150+
%false = torch.constant.bool false
151+
// expected-error @below {{failed to legalize operation 'torch.aten.empty.memory_format' that was explicitly marked illegal}}
152+
%out = torch.aten.empty.memory_format %2452, %none, %none, %cpu, %false, %none : !torch.list<int>, !torch.none, !torch.none, !torch.Device, !torch.bool, !torch.none -> !torch.vtensor<[1,0,256],f32>
153+
return %out : !torch.vtensor<[1,0,256],f32>
154+
}

0 commit comments

Comments
 (0)