Skip to content

Commit b17bd73

Browse files
authored
[mlir][tosa] Add more negative tests for rank0 tensors, negate, and sub (#135061)
Signed-off-by: Jerry Ge <[email protected]>
1 parent 2bbe8e8 commit b17bd73

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

Diff for: mlir/test/Dialect/Tosa/invalid.mlir

+73
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,79 @@ func.func @test_non_tosa_ops() {
11441144

11451145
// -----
11461146

1147+
func.func @test_pad_rank0_pad_const(%arg0: tensor<13x21x3xf8E4M3FN>) -> tensor<13x21x3xf8E5M2> {
1148+
%padding = tosa.const_shape {values = dense<0> : tensor<6xindex>} : () -> !tosa.shape<6>
1149+
%cst = "tosa.const"() { values = dense<-0.0> : tensor<f8E4M3FN> } : () -> tensor<f8E4M3FN>
1150+
// expected-error@+1 {{'tosa.pad' op operand #2 must be tosa-conformant scalar tensor of number values, but got 'tensor<f8E4M3FN>'}}
1151+
%0 = tosa.pad %arg0, %padding, %cst : (tensor<13x21x3xf8E4M3FN>, !tosa.shape<6>, tensor<f8E4M3FN>) -> tensor<13x21x3xf8E5M2>
1152+
return %0 : tensor<13x21x3xf8E5M2>
1153+
}
1154+
1155+
// -----
1156+
1157+
func.func @test_conv2d_rank0_zp(%arg0: tensor<1x29x29x4xi8>, %arg1: tensor<16x3x3x4xi8>, %arg2: tensor<16xi8>) -> tensor<1x27x27x16xi32> {
1158+
%input_zp = "tosa.const"() <{values = dense<0> : tensor<i8>}> : () -> tensor<i8>
1159+
%weight_zp = "tosa.const"() <{values = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>
1160+
// expected-error@+1 {{'tosa.conv2d' op operand #3 must be tosa-conformant scalar tensor of unsigned integer or signless integer or floating-point values, but got 'tensor<i8>'}}
1161+
%0 = tosa.conv2d %arg0, %arg1, %arg2, %input_zp, %weight_zp {acc_type = i32, dilation = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>}
1162+
: (tensor<1x29x29x4xi8>, tensor<16x3x3x4xi8>, tensor<16xi8>, tensor<i8>, tensor<1xi8>) -> tensor<1x27x27x16xi32>
1163+
return %0 : tensor<1x27x27x16xi32>
1164+
}
1165+
1166+
// -----
1167+
1168+
// CHECK-LABEL: test_negate_same_element_type
1169+
func.func @test_negate_same_element_type(%arg0: tensor<8x8xf32>, %arg1: tensor<1xf32>, %arg2: tensor<1xf32>) -> tensor<8x8xf32> {
1170+
// expected-error@+1 {{'tosa.negate' op expect input and output to have same element type, got 'f32' and 'i32'}}
1171+
%0 = tosa.negate %arg0, %arg1, %arg2 : (tensor<8x8xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<8x8xi32>
1172+
return %0 : tensor<8x8xi32>
1173+
}
1174+
1175+
// -----
1176+
1177+
// CHECK-LABEL: test_negate_same_shape
1178+
func.func @test_negate_same_shape(%arg0: tensor<8x8xf32>, %arg1: tensor<1xf32>, %arg2: tensor<1xf32>) -> tensor<8x8xf32> {
1179+
// expected-error@+1 {{'tosa.negate' op requires the same shape for input1 and output}}
1180+
%0 = tosa.negate %arg0, %arg1, %arg2 : (tensor<8x8xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<8x6xf32>
1181+
return %0 : tensor<8x6xf32>
1182+
}
1183+
1184+
// -----
1185+
1186+
// CHECK-LABEL: test_negate_input_zp_same_element_type
1187+
func.func @test_negate_input_zp_same_element_type(%arg0: tensor<8x8xf32>, %arg1: tensor<1xi32>, %arg2: tensor<1xf32>) -> tensor<8x8xf32> {
1188+
// expected-error@+1 {{'tosa.negate' op expect both input1 and its zero point are the same element type, got 'f32' and 'i32'}}
1189+
%0 = tosa.negate %arg0, %arg1, %arg2 : (tensor<8x8xf32>, tensor<1xi32>, tensor<1xf32>) -> tensor<8x8xf32>
1190+
return %0 : tensor<8x8xf32>
1191+
}
1192+
1193+
// -----
1194+
1195+
// CHECK-LABEL: test_negate_output_zp_same_element_type
1196+
func.func @test_negate_output_zp_same_element_type(%arg0: tensor<8x8xf32>, %arg1: tensor<1xf32>, %arg2: tensor<1xi32>) -> tensor<8x8xf32> {
1197+
// expected-error@+1 {{'tosa.negate' op expect both output and its zero point are the same element type, got 'f32' and 'i32'}}
1198+
%0 = tosa.negate %arg0, %arg1, %arg2 : (tensor<8x8xf32>, tensor<1xf32>, tensor<1xi32>) -> tensor<8x8xf32>
1199+
return %0 : tensor<8x8xf32>
1200+
}
1201+
1202+
// -----
1203+
1204+
func.func @test_sub_with_unequal_operand_ranks(%arg0: tensor<1x21x3xf32>, %arg1: tensor<1x13x21x3xf32>) -> tensor<1x13x21x3xf32> {
1205+
// expected-error@+1 {{'tosa.sub' op operands don't have matching ranks}}
1206+
%0 = tosa.sub %arg0, %arg1 : (tensor<1x21x3xf32>, tensor<1x13x21x3xf32>) -> tensor<1x13x21x3xf32>
1207+
return %0 : tensor<1x13x21x3xf32>
1208+
}
1209+
1210+
// -----
1211+
1212+
func.func @test_sub_with_unequal_result_ranks(%arg0: tensor<1x21x3xf32>, %arg1: tensor<13x21x3xf32>) -> tensor<1x13x21x3xf32> {
1213+
// expected-error@+1 {{'tosa.sub' op result type has different rank than operands}}
1214+
%0 = tosa.sub %arg0, %arg1 : (tensor<1x21x3xf32>, tensor<13x21x3xf32>) -> tensor<1x13x21x3xf32>
1215+
return %0 : tensor<1x13x21x3xf32>
1216+
}
1217+
1218+
// -----
1219+
11471220
// expected-error@+1 {{invalid rank (must be >= 0): -1}}
11481221
func.func @test_shape_type(%arg0: !tosa.shape<-1>) -> !tosa.shape<-1> {
11491222
return %arg0 : !tosa.shape<-1>

0 commit comments

Comments
 (0)