1//-------------------------------------------------------------------------------------------------- 2// Test expected errors in terms of the shape and type of tensor, and the argument type of 3// operation. Excludes the profile compilance checking since it is performed earlier in the 4// validation flow. 5//-------------------------------------------------------------------------------------------------- 6 7// RUN: mlir-opt %s -split-input-file -verify-diagnostics --tosa-validate="profile=bi,mi,mt strict-op-spec-alignment" 8 9 10func.func @test_const() -> tensor<1xf32> { 11 // expected-error@+1{{'tosa.const' op expected same attr/result element types}} 12 %0 = "tosa.const"() {value = dense<1> : tensor<1xi32>} : () -> tensor<1xf32> 13 return %0 : tensor<1xf32> 14} 15 16// ----- 17 18func.func @test_const_non_tensor_attr() { 19 // expected-error@+1{{tosa.const' op expected tensors for attr/result type}} 20 %0 = "tosa.const"() {value = dense<1.0> : vector<f32>} : () -> tensor<f32> 21 return 22} 23 24// ----- 25 26func.func @test_conv2d(%arg0: tensor<1x29x29x4xf32>, %arg1: tensor<16x3x3x4xi8>, %arg2: tensor<16xi8>) -> tensor<1x27x27x16xi8> { 27 // expected-error@+1 {{expect both input and weight to be float or not together, got 'f32' and 'i8'}} 28 %0 = tosa.conv2d %arg0, %arg1, %arg2 {acc_type = i32, dilation = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>} 29 : (tensor<1x29x29x4xf32>, tensor<16x3x3x4xi8>, tensor<16xi8>) -> tensor<1x27x27x16xi8> 30 return %0 : tensor<1x27x27x16xi8> 31} 32 33// ----- 34 35func.func @test_conv2d(%arg0: tensor<*xi8>, %arg1: tensor<16x3x3x4xi8>, %arg2: tensor<16xi8>) -> tensor<1x27x27x16xi8> { 36 // expected-error@+1 {{expect a ranked tensor for input, got <block argument> of type 'tensor<*xi8>' at index: 0}} 37 %0 = tosa.conv2d %arg0, %arg1, %arg2 {acc_type = i32, dilation = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>} 38 : (tensor<*xi8>, tensor<16x3x3x4xi8>, tensor<16xi8>) -> tensor<1x27x27x16xi8> 39 return %0 : tensor<1x27x27x16xi8> 40} 41 42// ----- 43 44func.func @test_conv2d(%arg0: tensor<1x29x29x4xi8>, %arg1: tensor<*xi8>, %arg2: tensor<16xi8>) -> tensor<1x27x27x16xi8> { 45 // expected-error@+1 {{'tosa.conv2d' op operand #1 must be 4D tensor of 4-bit signless integer or 8-bit signless integer or Quint8 type or Qint4 type or Qint8 type or Qint16 type or Qint32 type or floating-point values, but got 'tensor<*xi8>'}} 46 %0 = tosa.conv2d %arg0, %arg1, %arg2 {acc_type = i32, dilation = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>} 47 : (tensor<1x29x29x4xi8>, tensor<*xi8>, tensor<16xi8>) -> tensor<1x27x27x16xi8> 48 return %0 : tensor<1x27x27x16xi8> 49} 50 51// ----- 52 53func.func @test_conv2d(%arg0: tensor<1x29x29x4xi8>, %arg1: tensor<16x3x3x4xi8>, %arg2: tensor<16xi8>) -> tensor<1x27x27x16xi8> { 54 // expected-error@+1 {{'tosa.conv2d' op quantizationattr is required for quantized type, and not allowed for float type}} 55 %0 = tosa.conv2d %arg0, %arg1, %arg2 {acc_type = f16, dilation = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>} 56 : (tensor<1x29x29x4xi8>, tensor<16x3x3x4xi8>, tensor<16xi8>) -> tensor<1x27x27x16xi8> 57 return %0 : tensor<1x27x27x16xi8> 58} 59 60// ----- 61 62func.func @test_conv2d_acc_type(%arg0: tensor<1x29x29x4xi8>, %arg1: tensor<16x3x3x4xi8>, %arg2: tensor<16xi8>) -> tensor<1x27x27x16xi8> { 63 // expected-error@+1 {{'tosa.conv2d' op accumulator type for i8 tensor is not i32}} 64 %0 = tosa.conv2d %arg0, %arg1, %arg2 {acc_type = f16, dilation = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>, quantization_info = #tosa.conv_quant<input_zp = 0, weight_zp = 0>} 65 : (tensor<1x29x29x4xi8>, tensor<16x3x3x4xi8>, tensor<16xi8>) -> tensor<1x27x27x16xi8> 66 return %0 : tensor<1x27x27x16xi8> 67} 68 69// ----- 70 71func.func @test_conv2d_acc_type(%arg0: tensor<1x29x29x4xi16>, %arg1: tensor<16x3x3x4xi8>, %arg2: tensor<16xi16>) -> tensor<1x27x27x16xi16> { 72 // expected-error@+1 {{'tosa.conv2d' op accumulator type for i16 tensor is not i48}} 73 %0 = tosa.conv2d %arg0, %arg1, %arg2 {acc_type = f16, dilation = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>, quantization_info = #tosa.conv_quant<input_zp = 0, weight_zp = 0>} 74 : (tensor<1x29x29x4xi16>, tensor<16x3x3x4xi8>, tensor<16xi16>) -> tensor<1x27x27x16xi16> 75 return %0 : tensor<1x27x27x16xi16> 76} 77 78// ----- 79 80func.func @test_conv2d_acc_type(%arg0: tensor<1x29x29x4xf8E5M2>, %arg1: tensor<16x3x3x4xf8E5M2>, %arg2: tensor<16xf16>) -> tensor<1x27x27x16xf16> { 81 // expected-error@+1 {{'tosa.conv2d' op accumulator type for f8 tensor is not f16}} 82 %0 = tosa.conv2d %arg0, %arg1, %arg2 {acc_type = i32, dilation = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>} 83 : (tensor<1x29x29x4xf8E5M2>, tensor<16x3x3x4xf8E5M2>, tensor<16xf16>) -> tensor<1x27x27x16xf16> 84 return %0 : tensor<1x27x27x16xf16> 85} 86 87// ----- 88 89func.func @test_conv2d_acc_type(%arg0: tensor<1x29x29x4xf8E4M3>, %arg1: tensor<16x3x3x4xf8E4M3>, %arg2: tensor<16xf16>) -> tensor<1x27x27x16xf16> { 90 // expected-error@+1 {{'tosa.conv2d' op accumulator type for f8 tensor is not f16}} 91 %0 = tosa.conv2d %arg0, %arg1, %arg2 {acc_type = i32, dilation = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>} 92 : (tensor<1x29x29x4xf8E4M3>, tensor<16x3x3x4xf8E4M3>, tensor<16xf16>) -> tensor<1x27x27x16xf16> 93 return %0 : tensor<1x27x27x16xf16> 94} 95 96// ----- 97 98func.func @test_conv2d_acc_type(%arg0: tensor<1x29x29x4xf16>, %arg1: tensor<16x3x3x4xf16>, %arg2: tensor<16xf16>) -> tensor<1x27x27x16xf16> { 99 // expected-error@+1 {{'tosa.conv2d' op accumulator type for f16 tensor is not f16/f32}} 100 %0 = tosa.conv2d %arg0, %arg1, %arg2 {acc_type = i32, dilation = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>} 101 : (tensor<1x29x29x4xf16>, tensor<16x3x3x4xf16>, tensor<16xf16>) -> tensor<1x27x27x16xf16> 102 return %0 : tensor<1x27x27x16xf16> 103} 104 105// ----- 106 107func.func @test_conv2d_acc_type(%arg0: tensor<1x29x29x4xbf16>, %arg1: tensor<16x3x3x4xbf16>, %arg2: tensor<16xbf16>) -> tensor<1x27x27x16xbf16> { 108 // expected-error@+1 {{'tosa.conv2d' op accumulator type for bf16 tensor is not f32}} 109 %0 = tosa.conv2d %arg0, %arg1, %arg2 {acc_type = i32, dilation = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>} 110 : (tensor<1x29x29x4xbf16>, tensor<16x3x3x4xbf16>, tensor<16xbf16>) -> tensor<1x27x27x16xbf16> 111 return %0 : tensor<1x27x27x16xbf16> 112} 113 114// ----- 115 116func.func @test_conv2d_acc_type(%arg0: tensor<1x29x29x4xf32>, %arg1: tensor<16x3x3x4xf32>, %arg2: tensor<16xf32>) -> tensor<1x27x27x16xf32> { 117 // expected-error@+1 {{'tosa.conv2d' op accumulator type for f32 tensor is not f32}} 118 %0 = tosa.conv2d %arg0, %arg1, %arg2 {acc_type = i32, dilation = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>} 119 : (tensor<1x29x29x4xf32>, tensor<16x3x3x4xf32>, tensor<16xf32>) -> tensor<1x27x27x16xf32> 120 return %0 : tensor<1x27x27x16xf32> 121} 122 123// ----- 124 125func.func @test_conv3d_acc_type(%arg0: tensor<1x4x8x21x17xi8>, %arg1: tensor<34x1x1x1x17xi8>, %arg2: tensor<34xi8>) -> tensor<1x4x8x21x34xi8> { 126 // expected-error@+1 {{'tosa.conv3d' op accumulator type for i8 tensor is not i32}} 127 %0 = tosa.conv3d %arg0, %arg1, %arg2 {acc_type = f16, dilation = array<i64: 1, 1, 1>, pad = array<i64: 0, 0, 0, 0, 0, 0>, stride = array<i64: 1, 1, 1>, quantization_info = #tosa.conv_quant<input_zp = 0, weight_zp = 0>} 128 : (tensor<1x4x8x21x17xi8>, tensor<34x1x1x1x17xi8>, tensor<34xi8>) -> tensor<1x4x8x21x34xi8> 129 return %0 : tensor<1x4x8x21x34xi8> 130} 131 132// ----- 133 134func.func @test_depthwise_conv2d_acc_type(%arg0: tensor<1x4x4x4xi8>, %arg1: tensor<1x1x4x2xi8>, %arg2: tensor<8xi8>) -> tensor<1x4x4x8xi8> { 135 // expected-error@+1 {{'tosa.depthwise_conv2d' op accumulator type for i8 tensor is not i32}} 136 %0 = tosa.depthwise_conv2d %arg0, %arg1, %arg2 {acc_type = f16, dilation = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>, quantization_info = #tosa.conv_quant<input_zp = 0, weight_zp = 0>} : (tensor<1x4x4x4xi8>, tensor<1x1x4x2xi8>, tensor<8xi8>) -> tensor<1x4x4x8xi8> 137 return %0 : tensor<1x4x4x8xi8> 138} 139 140// ----- 141 142func.func @test_transpose_conv2d(%arg0: tensor<1x32x32x8xi8>, %arg1: tensor<16x1x1x8xi8>, %arg2: tensor<16xi8>) -> tensor<1x32x32x16xi8> { 143 // expected-error@+1 {{'tosa.transpose_conv2d' op accumulator type for i8 tensor is not i32}} 144 %0 = tosa.transpose_conv2d %arg0, %arg1, %arg2 {acc_type = f16, out_pad = array<i64: 0, 0, 0, 0>, out_shape = array<i64: 1, 32, 32, 16>, stride = array<i64: 1, 1>, quantization_info = #tosa.conv_quant<input_zp = 0, weight_zp = 0>} : (tensor<1x32x32x8xi8>, tensor<16x1x1x8xi8>, tensor<16xi8>) -> tensor<1x32x32x16xi8> 145 return %0 : tensor<1x32x32x16xi8> 146} 147 148// ----- 149 150func.func @test_concat(%arg0 : tensor<2x1xf32>, %arg1 : tensor<2x2xf32>) -> tensor<?x?xf32> { 151 // expected-error@+2 {{failed to infer returned types}} 152 // expected-error@+1 {{Cannot concat tensors with different sizes on the non-axis dimension 1}} 153 %0 = tosa.concat %arg0, %arg1 {axis = 0 : i32} : (tensor<2x1xf32>, tensor<2x2xf32>) -> tensor<?x?xf32> 154 return %0 : tensor<?x?xf32> 155} 156 157// ----- 158 159func.func @test_concat_element_type_mismatch(%arg0 : tensor<1x2xf32>, %arg1 : tensor<2x2xf32>) -> tensor<?x?xi8> { 160 // expected-error@+2 {{failed to infer returned types}} 161 // expected-error@+1 {{'tosa.concat' op inferred type(s) 'tensor<3x2xf32>' are incompatible with return type(s) of operation 'tensor<?x?xi8>}} 162 %0 = tosa.concat %arg0, %arg1 {axis = 0 : i32} : (tensor<1x2xf32>, tensor<2x2xf32>) -> tensor<?x?xi8> 163 return %0 : tensor<?x?xi8> 164} 165 166// ----- 167 168func.func @test_pad_non_const(%arg0: tensor<13x21x3xf32>, %arg1: !tosa.shape<6>) -> tensor<13x21x3xf32> { 169 // expected-error@+1 {{'tosa.pad' op shape operand is not compile time resolvable}} 170 %0 = tosa.pad %arg0, %arg1 : (tensor<13x21x3xf32>, !tosa.shape<6>) -> tensor<13x21x3xf32> 171 return %0 : tensor<13x21x3xf32> 172} 173 174// ----- 175 176func.func @test_pad_non_const(%arg0: tensor<13x21x3xi8>, %arg1: tensor<i8>) -> tensor<13x21x3xi8> { 177 %0 = tosa.const_shape {value = dense<[0, 0, 0, 1, 0, 1]> : tensor<6xindex>} : () -> !tosa.shape<6> 178 // expected-error@+1 {{'tosa.pad' op pad_const of pad is not constant}} 179 %1 = tosa.pad %arg0, %0, %arg1 : (tensor<13x21x3xi8>, !tosa.shape<6>, tensor<i8>) -> tensor<13x21x3xi8> 180 return %1 : tensor<13x21x3xi8> 181} 182 183// ----- 184 185func.func @test_pad_io_rank_mismatch(%arg0: tensor<13x21xf32>) { 186 %padding = tosa.const_shape {value = dense<0> : tensor<4xindex>} : () -> !tosa.shape<4> 187 // expected-error@+1 {{'tosa.pad' op expect same input and output tensor rank.}} 188 %1 = tosa.pad %arg0, %padding : (tensor<13x21xf32>, !tosa.shape<4>) -> tensor<13x21x3xf32> 189 return 190} 191 192// ----- 193 194func.func @test_pad_invalid_padding_rank(%arg0: tensor<13x21xf32>) { 195 %0 = tosa.const_shape {value = dense<1> : tensor<6xindex>} : () -> !tosa.shape<6> 196 // expected-error@+1 {{'tosa.pad' op expected padding tensor dim 0 to have size 4 (2*rank(shape1)) but got size 6}} 197 %1 = tosa.pad %arg0, %0 : (tensor<13x21xf32>, !tosa.shape<6>) -> tensor<13x21xf32> 198 return 199} 200 201// ----- 202 203func.func @test_pad_invalid_padConst_rank(%arg0: tensor<13x21xf32>, %arg1: tensor<2x2xi32>) { 204 %0 = tosa.const_shape {value = dense<1> : tensor<4xindex>} : () -> !tosa.shape<4> 205 %1 = "tosa.const"() {value = dense<3.14> : tensor<2xf32>} : () -> tensor<2xf32> 206 // expected-error@+1 {{'tosa.pad' op operand #2 must be 0D tensor of number values, but got 'tensor<2xf32>'}} 207 %2 = tosa.pad %arg0, %0, %1 : (tensor<13x21xf32>, !tosa.shape<4>, tensor<2xf32>) -> tensor<13x21xf32> 208 return 209} 210 211// ----- 212 213func.func @test_pad_padding_shape_mismatch(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> { 214 %0 = tosa.const_shape {value = dense<1> : tensor<4xindex>} : () -> !tosa.shape<4> 215 // expected-error@+1 {{'tosa.pad' op expected padding tensor dim 0 to have size 6 (2*rank(shape1)) but got size 4}} 216 %1 = tosa.pad %arg0, %0 : (tensor<13x21x3xf32>, !tosa.shape<4>) -> tensor<13x21x3xf32> 217 return %1 : tensor<13x21x3xf32> 218} 219 220// ----- 221 222func.func @test_transpose_non_const(%arg0: tensor<13x21x3xf32>, %arg1: tensor<3xi32>) -> tensor<3x13x21xf32> { 223 // expected-error@+1 {{'tosa.transpose' op perms of transpose is not constant}} 224 %0 = tosa.transpose %arg0, %arg1 : (tensor<13x21x3xf32>, tensor<3xi32>) -> tensor<3x13x21xf32> 225 return %0 : tensor<3x13x21xf32> 226} 227 228// ----- 229 230func.func @test_transpose_io_rank_mismatch(%arg0: tensor<13x21x3xf32>, %arg1: tensor<3xi32>) -> tensor<3x13x21x1xf32> { 231 // expected-error@+1 {{'tosa.transpose' op expected input tensor rank to equal result tensor rank}} 232 %0 = tosa.transpose %arg0, %arg1 : (tensor<13x21x3xf32>, tensor<3xi32>) -> tensor<3x13x21x1xf32> 233 return %0 : tensor<3x13x21x1xf32> 234} 235 236// ----- 237 238func.func @test_transpose_invalid_perms_rank(%arg0: tensor<13x21x3xf32>, %arg1: tensor<3x2xi32>) -> tensor<3x13x21xf32> { 239 // expected-error@+1 {{'tosa.transpose' op expected permutation tensor to be rank 1 but got rank 2}} 240 %0 = tosa.transpose %arg0, %arg1 : (tensor<13x21x3xf32>, tensor<3x2xi32>) -> tensor<3x13x21xf32> 241 return %0 : tensor<3x13x21xf32> 242} 243 244// ----- 245 246func.func @test_transpose_rank0_perms() { 247 %14 = tensor.empty() : tensor<5x27xi64> 248 %cst = tensor.empty() : tensor<i32> 249 // expected-error@+1 {{'tosa.transpose' op expected permutation tensor to be rank 1 but got rank 0}} 250 %72 = tosa.transpose %14, %cst : (tensor<5x27xi64>, tensor<i32>) -> tensor<?x?xi64> 251 return 252} 253 254// ----- 255 256func.func @test_transpose_invalid_perms_size(%arg0: tensor<13x21x3xf32>, %arg1: tensor<7xi32>) -> tensor<3x13x21xf32> { 257 // expected-error@+1 {{'tosa.transpose' op expected permutation tensor dim 0 to have size 3 (input rank) but got size 7}} 258 %0 = tosa.transpose %arg0, %arg1 : (tensor<13x21x3xf32>, tensor<7xi32>) -> tensor<3x13x21xf32> 259 return %0 : tensor<3x13x21xf32> 260} 261 262// ----- 263 264func.func @test_transpose_invalid_permutation_tensor(%arg0: tensor<13x21x3xf32>) -> tensor<?x?x?xf32> { 265 %perms = arith.constant dense<[2, 0, 0]> : tensor<3xi32> 266 // expected-error@+1 {{'tosa.transpose' op expected valid permutation tensor}} 267 %0 = tosa.transpose %arg0, %perms : (tensor<13x21x3xf32>, tensor<3xi32>) -> tensor<?x?x?xf32> 268 return %0 : tensor<?x?x?xf32> 269} 270 271// ----- 272 273func.func @test_transpose_invalid_permutation_negative(%arg0: tensor<3x2xi32>) -> tensor<*xi32> { 274 %perms = "tosa.const"() {value = dense<[-1, 0]> : tensor<2xi32>} : () -> tensor<2xi32> 275 // expected-error@+1 {{'tosa.transpose' op expected valid permutation tensor}} 276 %1 = tosa.transpose %arg0, %perms : (tensor<3x2xi32>, tensor<2xi32>) -> tensor<*xi32> 277 return %1 : tensor<*xi32> 278} 279 280// ----- 281 282func.func @test_transpose_invalid_permutation_tensor_above_range(%arg0: tensor<3x2xi32>) -> tensor<*xi32> { 283 %perms = "tosa.const"() {value = dense<[2, 0]> : tensor<2xi32>} : () -> tensor<2xi32> 284 // expected-error@+1 {{'tosa.transpose' op expected valid permutation tensor}} 285 %1 = tosa.transpose %arg0, %perms : (tensor<3x2xi32>, tensor<2xi32>) -> tensor<*xi32> 286 return %1 : tensor<*xi32> 287} 288 289// ----- 290 291func.func @test_transpose_invalid_permutation_types(%arg0: tensor<3x2xi32>) -> tensor<3x4xi32> { 292 %perms = "tosa.const"() {value = dense<[1, 0]> : tensor<2xi32>} : () -> tensor<2xi32> 293 // expected-error@+1 {{'tosa.transpose' op expected output tensor dim 0 to match input dim 1 with value of 2}} 294 %1 = tosa.transpose %arg0, %perms : (tensor<3x2xi32>, tensor<2xi32>) -> tensor<3x4xi32> 295 return %1 : tensor<3x4xi32> 296} 297 298// ----- 299 300func.func @test_transpose_invalid_permutation_types_dynamic_dim_ok(%arg0: tensor<2x?xi32>) -> tensor<3x4xi32> { 301 %perms = "tosa.const"() {value = dense<[1, 0]> : tensor<2xi32>} : () -> tensor<2xi32> 302 // expected-error@+1 {{'tosa.transpose' op expected output tensor dim 1 to match input dim 0 with value of 2}} 303 %1 = tosa.transpose %arg0, %perms : (tensor<2x?xi32>, tensor<2xi32>) -> tensor<3x4xi32> 304 return %1 : tensor<3x4xi32> 305} 306 307// ----- 308 309func.func @test_transpose_element_type_mismatch(%arg0: tensor<2x3xi32>) -> tensor<3x2xf32> { 310 %perms = "tosa.const"() {value = dense<[1, 0]> : tensor<2xi32>} : () -> tensor<2xi32> 311 // expected-error@+1 {{'tosa.transpose' op failed to verify that all of {input1, output} have same element type}} 312 %1 = tosa.transpose %arg0, %perms : (tensor<2x3xi32>, tensor<2xi32>) -> tensor<3x2xf32> 313 return %1 : tensor<3x2xf32> 314} 315 316// ----- 317 318func.func @test_fully_connected_non_const(%arg0: tensor<13x21x3xf32>, %arg1: tensor<2x3xf32>) -> tensor<273x2xf32> { 319 %0 = "tosa.const"() {value = dense<0.000000e+00> : tensor<2xf32>} : () -> tensor<2xf32> 320 %1 = tosa.reshape %arg0 {new_shape = array<i64: 273, 3>} : (tensor<13x21x3xf32>) -> tensor<273x3xf32> 321 // expected-error@+1 {{'tosa.fully_connected' op weight of fully_connected is not constant}} 322 %2 = tosa.fully_connected %1, %arg1, %0 : (tensor<273x3xf32>, tensor<2x3xf32>, tensor<2xf32>) -> tensor<273x2xf32> 323 return %2 : tensor<273x2xf32> 324} 325 326// ----- 327 328func.func @test_fully_connected_non_const(%arg0: tensor<13x21x3xf32>, %arg1: tensor<2xf32>) -> tensor<273x2xf32> { 329 %0 = "tosa.const"() {value = dense<[[-0.613216758, -0.63714242, -0.73500061], [0.180762768, 0.773053169, -0.933686495]]> : tensor<2x3xf32>} : () -> tensor<2x3xf32> 330 %1 = tosa.reshape %arg0 {new_shape = array<i64: 273, 3>} : (tensor<13x21x3xf32>) -> tensor<273x3xf32> 331 // expected-error@+1 {{'tosa.fully_connected' op bias of fully_connected is not constant}} 332 %2 = tosa.fully_connected %1, %0, %arg1 : (tensor<273x3xf32>, tensor<2x3xf32>, tensor<2xf32>) -> tensor<273x2xf32> 333 return %2 : tensor<273x2xf32> 334} 335 336// ----- 337 338func.func @test_reduce_sum_type_mismatch(%arg0 : tensor<2x3x4x5xf32>) -> () { 339 // expected-error@+2 {{failed to infer returned types}} 340 // expected-error@+1 {{'tosa.reduce_sum' op inferred type(s) 'tensor<1x3x4x5xf32>' are incompatible with return type(s) of operation 'tensor<1x3x4x5xi32>'}} 341 %0 = tosa.reduce_sum %arg0 {axis = 0 : i32} : (tensor<2x3x4x5xf32>) -> tensor<1x3x4x5xi32> 342 return 343} 344 345// ----- 346 347func.func @test_reduce_max_type_mismatch(%arg0 : tensor<2x3x4x5xf32>) -> () { 348 // expected-error@+2 {{failed to infer returned types}} 349 // expected-error@+1 {{'tosa.reduce_max' op inferred type(s) 'tensor<2x3x4x1xf32>' are incompatible with return type(s) of operation 'tensor<2x3x4x1xi32>'}} 350 %0 = tosa.reduce_max %arg0 {axis = 3 : i32} : (tensor<2x3x4x5xf32>) -> tensor<2x3x4x1xi32> 351 return 352} 353 354// ----- 355 356func.func @test_reduce_min_type_mismatch(%arg0 : tensor<2x3x4x5xf32>) -> () { 357 // expected-error@+2 {{failed to infer returned types}} 358 // expected-error@+1 {{'tosa.reduce_min' op inferred type(s) 'tensor<2x1x4x5xf32>' are incompatible with return type(s) of operation 'tensor<2x1x4x5xi32>'}} 359 %0 = tosa.reduce_min %arg0 {axis = 1 : i32} : (tensor<2x3x4x5xf32>) -> tensor<2x1x4x5xi32> 360 return 361} 362 363// ----- 364 365func.func @test_reduce_prod_type_mismatch(%arg0 : tensor<2x3x4x5xf32>) -> () { 366 // expected-error@+1 {{'tosa.reduce_prod' op expect reduced dimension size to be 1, got 3}} 367 %0 = tosa.reduce_prod %arg0 {axis = 1 : i32} : (tensor<2x3x4x5xf32>) -> tensor<2x3x4x5xf32> 368 return 369} 370 371// ----- 372 373func.func @test_reduce_all_invalid_axis(%arg0 : tensor<2x3x4xf32>) -> () { 374 // expected-error@+1 {{'tosa.reduce_all' op expect input tensor rank (3) to be larger than reduce axis (3)}} 375 %0 = tosa.reduce_all %arg0 {axis = 3 : i32} : (tensor<2x3x4xf32>) -> tensor<2x3x1xf32> 376 return 377} 378 379// ----- 380 381func.func @test_reduce_any_invalid_axis(%arg0 : tensor<2x3x4xf32>) -> () { 382 // expected-error@+1 {{'tosa.reduce_any' op expect input tensor rank (3) to be larger than reduce axis (3)}} 383 %0 = tosa.reduce_any %arg0 {axis = 3 : i32} : (tensor<2x3x4xf32>) -> tensor<2x3x1xf32> 384 return 385} 386 387// ----- 388 389func.func @test_reduce_max_invalid_axis(%arg0 : tensor<2x3x4xf32>) -> () { 390 // expected-error@+1 {{'tosa.reduce_max' op expect input tensor rank (3) to be larger than reduce axis (3)}} 391 %0 = tosa.reduce_max %arg0 {axis = 3 : i32} : (tensor<2x3x4xf32>) -> tensor<2x3x1xf32> 392 return 393} 394 395// ----- 396 397func.func @test_reduce_min_invalid_axis(%arg0 : tensor<2x3x4xf32>) -> () { 398 // expected-error@+1 {{'tosa.reduce_min' op expect input tensor rank (3) to be larger than reduce axis (3)}} 399 %0 = tosa.reduce_min %arg0 {axis = 3 : i32} : (tensor<2x3x4xf32>) -> tensor<2x3x1xf32> 400 return 401} 402 403// ----- 404 405func.func @test_reduce_prod_invalid_axis(%arg0 : tensor<2x3x4xf32>) -> () { 406 // expected-error@+1 {{'tosa.reduce_prod' op expect input tensor rank (3) to be larger than reduce axis (3)}} 407 %0 = tosa.reduce_prod %arg0 {axis = 3 : i32} : (tensor<2x3x4xf32>) -> tensor<2x3x1xf32> 408 return 409} 410 411// ----- 412 413func.func @test_reduce_sum_invalid_axis(%arg0 : tensor<2x3x4xf32>) -> () { 414 // expected-error@+1 {{'tosa.reduce_sum' op expect input tensor rank (3) to be larger than reduce axis (3)}} 415 %0 = tosa.reduce_sum %arg0 {axis = 3 : i32} : (tensor<2x3x4xf32>) -> tensor<2x3x1xf32> 416 return 417} 418 419// ----- 420 421func.func @test_reduce_min_invalid_output_rank(%arg0 : tensor<i32>) -> () { 422 // expected-error@+1 {{'tosa.reduce_min' op expect output tensor rank to be equal to input tensor rank}} 423 %0 = tosa.reduce_min %arg0 {axis = 0 : i32} : (tensor<i32>) -> tensor<1x10xi32> 424 return 425} 426 427// ----- 428 429func.func @test_reshape_type_mismatch(%arg0 : tensor<13x21x3xf32>) -> () { 430 // expected-error@+2 {{failed to infer returned types}} 431 // expected-error@+1 {{'tosa.reshape' op inferred type(s) 'tensor<13x21x3x1xf32>' are incompatible with return type(s) of operation 'tensor<13x21x3x1xi32>'}} 432 %0 = tosa.reshape %arg0 {new_shape = array<i64: 13, 21, 3, 1>} : (tensor<13x21x3xf32>) -> tensor<13x21x3x1xi32> 433 return 434} 435 436// ----- 437 438func.func @test_reshape_static_zero_dim_input(%arg0 : tensor<13x0x3xf32>) -> () { 439 // expected-error@+1 {{'tosa.reshape' op operand #0 must be tosa-conformant tensor of number values, but got 'tensor<13x0x3xf32>'}} 440 %0 = "tosa.reshape"(%arg0) {new_shape = array<i64: 13, 21, 3>} : (tensor<13x0x3xf32>) -> tensor<13x0x3xf32> 441 return 442} 443 444// ----- 445 446func.func @test_reshape_zero_dim_input(%arg0 : tensor<?x0x3xf32>) -> () { 447 // expected-error@+1 {{'tosa.reshape' op operand #0 must be tosa-conformant tensor of number values, but got 'tensor<?x0x3xf32>'}} 448 %0 = "tosa.reshape"(%arg0) {new_shape = array<i64: 13, 21, 3>} : (tensor<?x0x3xf32>) -> tensor<13x0x3xf32> 449 return 450} 451 452// ----- 453 454func.func @test_reshape_rank_mismatch(%arg0 : tensor<?xf32>) -> () { 455 // expected-error@+1 {{'tosa.reshape' op new shape does not match result rank}} 456 %0 = "tosa.reshape"(%arg0) {new_shape = array<i64: 2, 4>} : (tensor<?xf32>) -> tensor<?xf32> 457 return 458} 459 460// ----- 461 462func.func @test_reshape_inconsistent_result_type(%arg0 : tensor<?xf32>) -> () { 463 // expected-error@+1 {{'tosa.reshape' op new shape is inconsistent with result shape}} 464 %0 = "tosa.reshape"(%arg0) {new_shape = array<i64: 2, 4, -1>} : (tensor<?xf32>) -> tensor<?x3x5xf32> 465 return 466} 467 468// ----- 469 470func.func @test_reshape_invalid_size(%arg0 : tensor<2x4xf32>) -> () { 471 // expected-error@+1 {{'tosa.reshape' op cannot reshape 8 elements into 15}} 472 %0 = "tosa.reshape"(%arg0) {new_shape = array<i64: 3, 5>} : (tensor<2x4xf32>) -> tensor<3x5xf32> 473 return 474} 475 476// ----- 477 478func.func @test_reshape_invalid_newshape(%arg0 : tensor<1xf32>) -> () { 479 // expected-error@+1 {{'tosa.reshape' op cannot reshape 1 elements into 4}} 480 %0 = "tosa.reshape"(%arg0) {new_shape = array<i64: -1, 4>} : (tensor<1xf32>) -> tensor<?x4xf32> 481 return 482} 483 484// ----- 485 486func.func @test_reshape_invalid_newshape(%arg0 : tensor<8xf32>) -> () { 487 // expected-error@+1 {{'tosa.reshape' op cannot reshape 8 elements into 4}} 488 %0 = "tosa.reshape"(%arg0) {new_shape = array<i64: 1, 4>} : (tensor<8xf32>) -> tensor<?x4xf32> 489 return 490} 491 492// ----- 493 494func.func @test_reshape_invalid_placeholders(%arg0 : tensor<?xf32>) -> () { 495 // expected-error@+1 {{'tosa.reshape' op expected at most one target dimension to be -1}} 496 %0 = "tosa.reshape"(%arg0) {new_shape = array<i64: 2, -1, -1>} : (tensor<?xf32>) -> tensor<2x?x?xf32> 497 return 498} 499 500// ----- 501 502func.func @test_reshape_invalid_tensor_dim(%arg0 : tensor<4x?xf32>) -> () { 503 // expected-error@+1 {{'tosa.reshape' op new shape has invalid tensor dimension size -2}} 504 %0 = "tosa.reshape" (%arg0) {new_shape = array<i64: -2, -1>} : (tensor<4x?xf32>) -> tensor<?x4xf32> 505 return 506} 507 508// ----- 509 510func.func @test_reverse_axis_out_of_range(%arg0 : tensor<13x21x3xf32>) -> () { 511 // expected-error@+1 {{'tosa.reverse' op expect input tensor rank (3) to be larger than reverse axis (5)}} 512 %0 = tosa.reverse %arg0 {axis = 5 : i32} : (tensor<13x21x3xf32>) -> tensor<?x?x?xi32> 513 return 514} 515 516// ----- 517 518func.func @test_const_attribute_type_mismatch() -> tensor<100x100xf32> { 519 // expected-error@+1 {{'tosa.const' op failed to verify that all of {value, output} have same shape}} 520 %0 = "tosa.const"() {value = dense<0.000000e+00> : tensor<1x1xf32>} : () -> tensor<100x100xf32> 521 return %0 : tensor<100x100xf32> 522} 523 524// ----- 525 526func.func @test_conv2d_static_zero_dim_input(%arg0: tensor<1x29x0x4xf32>, %arg1: tensor<16x3x3x4xf32>, %arg2: tensor<16xf32>) -> tensor<1x27x27x16xf32> { 527 // expected-error@+1 {{'tosa.conv2d' op operand #0 must be 4-d tosa-conformant tensor, but got 'tensor<1x29x0x4xf32>'}} 528 %0 = "tosa.conv2d"(%arg0, %arg1, %arg2) {acc_type = f32, dilation = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>} 529 : (tensor<1x29x0x4xf32>, tensor<16x3x3x4xf32>, tensor<16xf32>) -> tensor<1x27x27x16xf32> 530 return %0 : tensor<1x27x27x16xf32> 531} 532 533// ----- 534 535func.func @test_conv2d_zero_dim_input(%arg0: tensor<1x?x0x4xf32>, %arg1: tensor<16x3x3x4xf32>, %arg2: tensor<16xf32>) -> tensor<1x27x27x16xf32> { 536 // expected-error@+1 {{'tosa.conv2d' op operand #0 must be 4-d tosa-conformant tensor, but got 'tensor<1x?x0x4xf32>'}} 537 %0 = "tosa.conv2d"(%arg0, %arg1, %arg2) {acc_type = f32, dilation = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>} 538 : (tensor<1x?x0x4xf32>, tensor<16x3x3x4xf32>, tensor<16xf32>) -> tensor<1x27x27x16xf32> 539 return %0 : tensor<1x27x27x16xf32> 540} 541 542 543// ----- 544 545func.func @test_avg_pool2d_static_zero_dim_input(%arg0: tensor<1x0x7x9xf32>) -> tensor<1x7x7x9xf32> { 546 // expected-error@+1 {{'tosa.avg_pool2d' op operand #0 must be 4-d tosa-conformant tensor, but got 'tensor<1x0x7x9xf32>'}} 547 %0 = "tosa.avg_pool2d"(%arg0) {acc_type = f32, kernel = array<i64: 2, 2>, pad = array<i64: 0, 1, 0, 1>, stride = array<i64: 1, 1>} 548 : (tensor<1x0x7x9xf32>) -> tensor<1x7x7x9xf32> 549 return %0 : tensor<1x7x7x9xf32> 550} 551 552// ----- 553 554func.func @test_avg_pool2d_zero_dim_input(%arg0: tensor<1x0x?x9xf32>) -> tensor<1x7x7x9xf32> { 555 // expected-error@+1 {{'tosa.avg_pool2d' op operand #0 must be 4-d tosa-conformant tensor, but got 'tensor<1x0x?x9xf32>'}} 556 %0 = "tosa.avg_pool2d"(%arg0) {acc_type = f32, kernel = array<i64: 2, 2>, pad = array<i64: 0, 1, 0, 1>, stride = array<i64: 1, 1>} 557 : (tensor<1x0x?x9xf32>) -> tensor<1x7x7x9xf32> 558 return %0 : tensor<1x7x7x9xf32> 559} 560 561// ----- 562 563func.func @test_variable_duplicates(%arg0: tensor<2x4x8xi32>) -> () { 564 tosa.variable @stored_var = dense<-1> : tensor<2x4x8xi32> 565 // expected-error@+1 {{'tosa.variable' op name has already been declared}} 566 tosa.variable @stored_var : tensor<1x4x8xi32> 567 return 568} 569 570// ----- 571 572func.func @test_variable_read_type(%arg0: tensor<2x4x8xi32>) -> () { 573 tosa.variable @stored_var = dense<-1> : tensor<2x4x8xi32> 574 // expected-error@+1 {{'tosa.variable.read' op result type does not equal variable type}} 575 %0 = tosa.variable.read @stored_var : tensor<2x4x8xi16> 576 return 577} 578 579// ----- 580 581func.func @test_variable_read_shape(%arg0: tensor<2x4x8xi32>) -> () { 582 tosa.variable @stored_var = dense<-1> : tensor<2x4x8xi32> 583 // expected-error@+1 {{'tosa.variable.read' op result type does not equal variable type}} 584 %0 = tosa.variable.read @stored_var : tensor<1x4x8xi32> 585 return 586} 587 588// ----- 589 590func.func @test_variable_write_type(%arg0: tensor<2x4x8xi16>) -> () { 591 tosa.variable @stored_var = dense<-1> : tensor<2x4x8xi32> 592 // expected-error@+1 {{'tosa.variable.write' op operand type does not equal variable type}} 593 tosa.variable.write @stored_var, %arg0 : tensor<2x4x8xi16> 594 return 595} 596 597// ----- 598 599func.func @test_variable_write_shape(%arg0: tensor<1x4x8xi32>) -> () { 600 tosa.variable @stored_var = dense<-1> : tensor<2x4x8xi32> 601 // expected-error@+1 {{'tosa.variable.write' op operand type does not equal variable type}} 602 tosa.variable.write @stored_var, %arg0 : tensor<1x4x8xi32> 603 return 604} 605 606// ----- 607 608func.func @test_slice_invalid_start() { 609 %0 = tensor.empty() : tensor<4x31x31xf32> 610 %start = tosa.const_shape {value = dense<[1, 1]> : tensor<2xindex>} : () -> !tosa.shape<2> 611 %size = tosa.const_shape {value = dense<[1, 1, 1]> : tensor<3xindex>} : () -> !tosa.shape<3> 612 // expected-error@+1 {{'tosa.slice' op length of start attribute is not equal rank of input shape}} 613 %3 = tosa.slice %0, %start, %size : (tensor<4x31x31xf32>, !tosa.shape<2>, !tosa.shape<3>) -> tensor<*xf32> 614 return 615} 616 617// ----- 618 619func.func @test_slice_invalid_size() { 620 %0 = tensor.empty() : tensor<4x31x31xf32> 621 %start = tosa.const_shape {value = dense<[1, 1, 1]> : tensor<3xindex>} : () -> !tosa.shape<3> 622 %size = tosa.const_shape {value = dense<[1]> : tensor<1xindex>} : () -> !tosa.shape<1> 623 // expected-error@+1 {{'tosa.slice' op length of size attribute is not equal rank of input shape}} 624 %3 = tosa.slice %0, %start, %size : (tensor<4x31x31xf32>, !tosa.shape<3>, !tosa.shape<1>) -> tensor<*xf32> 625 return 626} 627 628// ----- 629 630func.func @test_tile_invalid_multiples() { 631 %0 = tensor.empty() : tensor<4x31x31xf32> 632 %cst = tosa.const_shape { value = dense<1> : tensor<1xindex> } : () -> !tosa.shape<1> 633 // expected-error@+1 {{'tosa.tile' op expect 'multiples' to have rank 3 but got 1.}} 634 %1 = tosa.tile %0, %cst: (tensor<4x31x31xf32>, !tosa.shape<1>) -> tensor<4x31x31xf32> 635 return 636} 637 638// ----- 639 640func.func @test_tile_invalid_multiples_value() { 641 %0 = tensor.empty() : tensor<4x31xf32> 642 %multiples = tosa.const_shape { value = dense<[2, -2]> : tensor<2xindex> } : () -> !tosa.shape<2> 643 // expected-error@+1 {{'tosa.tile' op expect element of 'multiples' to be positive integer or -1.}} 644 %1 = tosa.tile %0, %multiples : (tensor<4x31xf32>, !tosa.shape<2>) -> tensor<4x31xf32> 645 return 646} 647 648// ----- 649 650func.func @test_tile_io_rank_mismatch() { 651 %0 = tensor.empty() : tensor<4x31xf32> 652 %multiples = tosa.const_shape { value = dense<[2, 2]> : tensor<2xindex> } : () -> !tosa.shape<2> 653 // expected-error@+1 {{'tosa.tile' op expect same input and output tensor rank.}} 654 %1 = tosa.tile %0, %multiples : (tensor<4x31xf32>, !tosa.shape<2>) -> tensor<4x31x31xf32> 655 return 656} 657 658// ----- 659 660// CHECK-LABEL: @test_invalid_constant_permutation 661func.func @test_invalid_constant_permutation() { 662 // expected-error@+3 {{'tosa.transpose' op expected valid permutation tensor}} 663 %0 = tensor.empty() : tensor<3x4x5xi32> 664 %1 = arith.constant dense<[3, 0, 1]> : tensor<3xi32> 665 %2 = tosa.transpose %0, %1 : (tensor<3x4x5xi32>, tensor<3xi32>) -> tensor<3x4x5xi32> 666 return 667} 668 669// ----- 670 671// CHECK-LABEL: test_rank_size_constant_permutation 672func.func @test_rank_size_constant_permutation() { 673 // expected-error@+4 {{'tosa.transpose' op expected valid permutation tensor}} 674 %0 = arith.constant 6 : index 675 %1 = arith.constant dense<[0, 2]> : tensor<2xi32> 676 %2 = tensor.empty(%0) : tensor<?x27xi64> 677 %3 = tosa.transpose %2, %1 : (tensor<?x27xi64>, tensor<2xi32>) -> tensor<?x27xi64> 678 return 679} 680 681// ----- 682 683// CHECK-LABEL: test_large_constant_permutation 684func.func @test_large_constant_permutation() { 685 // expected-error@+4 {{'tosa.transpose' op expected valid permutation tensor}} 686 %0 = arith.constant 6 : index 687 %1 = arith.constant dense<[1185677355, 332462212]> : tensor<2xi32> 688 %2 = tensor.empty(%0) : tensor<?x27xi64> 689 %3 = tosa.transpose %2, %1 : (tensor<?x27xi64>, tensor<2xi32>) -> tensor<?x27xi64> 690 return 691} 692 693// ----- 694 695// CHECK-LABEL: test_table_rank0_table 696func.func @test_table_rank0_table(%arg0: tensor<64xi16>, %arg1: tensor<i16>) { 697 // expected-error@+1 {{'tosa.table' op operand #1 must be 1-d tosa-conformant tensor, but got 'tensor<i16>'}} 698 %0 = tosa.table %arg0, %arg1 : (tensor<64xi16>, tensor<i16>) -> tensor<64xi16> 699 return 700} 701 702// ----- 703 704// CHECK-LABEL: test_table_io_rank_mismatch 705func.func @test_table_io_rank_mismatch(%arg0: tensor<64xi16>, %arg1: tensor<6xi16>) { 706 // expected-error@+1 {{'tosa.table' op expected input tensor rank to equal result tensor rank}} 707 %0 = tosa.table %arg0, %arg1 : (tensor<64xi16>, tensor<6xi16>) -> tensor<64x?xi16> 708 return 709} 710 711// ----- 712 713// CHECK-LABEL: test_table_io_shape_mismatch 714func.func @test_table_io_shape_mismatch(%arg0: tensor<?x16xi16>, %arg1: tensor<6xi16>) { 715 // expected-error@+1 {{'tosa.table' op dim(result, 1) = 15 doesn't match dim(input, 1) = 16}} 716 %0 = tosa.table %arg0, %arg1 : (tensor<?x16xi16>, tensor<6xi16>) -> tensor<?x15xi16> 717 return 718} 719 720// ----- 721 722// CHECK-LABEL: test_transpose_conv2d_invalid_outshape 723func.func @test_transpose_conv2d_invalid_outshape(%arg0: tensor<1x32x32x8xf32>, %arg1: tensor<16x1x1x8xf32>, %arg2: tensor<16xf32>) -> tensor<1x32x32x16xf32> { 724 // expected-error@+1 {{'tosa.transpose_conv2d' op attribute 'out_shape' failed to satisfy constraint: i64 dense array attribute with exactly 4 elements}} 725 %0 = tosa.transpose_conv2d %arg0, %arg1, %arg2 {out_pad = array<i64: 0, 0, 0, 0>, out_shape = array<i64: 1, 32, 32>, stride = array<i64: 1, 1>} : (tensor<1x32x32x8xf32>, tensor<16x1x1x8xf32>, tensor<16xf32>) -> tensor<1x32x32x16xf32> 726 return %0 : tensor<1x32x32x16xf32> 727} 728 729// ----- 730 731// CHECK-LABEL: test_mul_type_mismatch 732func.func @test_mul_type_mismatch(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x1x3xf16>) -> tensor<13x21x3xf32> { 733 // expected-error@+1 {{'tosa.mul' op requires the same element type for all operands}} 734 %0 = tosa.mul %arg0, %arg1 : (tensor<13x21x3xf32>, tensor<13x1x3xf16>) -> tensor<13x21x3xf32> 735 return %0 : tensor<13x21x3xf32> 736} 737 738// ----- 739 740// CHECK-LABEL: test_mul_invalid_shift 741func.func @test_mul_invalid_shift(%arg0: tensor<13x21x3xi32>, %arg1: tensor<13x1x3xi32>) -> tensor<13x21x3xi32> { 742 %shift = "tosa.const"() {value = dense<0.0> : tensor<f32>} : () -> tensor<f32> 743 // expected-error@+1 {{'tosa.mul' op operand #2 must be 1D tensor of 8-bit signless integer values, but got 'tensor<f32>'}} 744 %0 = tosa.mul %arg0, %arg1, %shift : (tensor<13x21x3xi32>, tensor<13x1x3xi32>, tensor<f32>) -> tensor<13x21x3xi32> 745 return %0 : tensor<13x21x3xi32> 746} 747 748// ----- 749 750// CHECK-LABEL: test_mul_missing_shift 751func.func @test_mul_missing_shift(%arg0: tensor<13x21x3xi32>, %arg1: tensor<13x1x3xi32>) -> tensor<13x21x3xi32> { 752 // expected-error@+1 {{'tosa.mul' op expected 3 operands, but found 2}} 753 %0 = tosa.mul %arg0, %arg1 : (tensor<13x21x3xi32>, tensor<13x1x3xi32>) -> tensor<13x21x3xi32> 754 return %0 : tensor<13x21x3xi32> 755} 756 757// ----- 758 759// CHECK-LABEL: test_unsupported_int64_data_type 760func.func @test_unsupported_int64_data_type(%arg0: tensor<1x13x13x5xf32>) -> tensor<1x13x13xi64> { 761 // expected-error@+1 {{'tosa.argmax' op is not profile-aligned: element type 'i64' is not legal}} 762 %0 = tosa.argmax %arg0 {axis = 3 : i32} : (tensor<1x13x13x5xf32>) -> tensor<1x13x13xi64> 763 return %0 : tensor<1x13x13xi64> 764} 765 766// ----- 767 768// CHECK-LABEL: test_mismatch_in_out_data_type_clamp 769func.func @test_mismatch_in_out_data_type_clamp(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf16> { 770 // expected-error@+1 {{'tosa.clamp' op requires the same element type for all operands and results}} 771 %0 = tosa.clamp %arg0 {min_fp = 0.0 : f32, max_fp = 1.0: f32, min_int = 0 : i64, max_int = 1 : i64} : (tensor<13x21x3xf32>) -> tensor<13x21x3xf16> 772 return %0 : tensor<13x21x3xf16> 773} 774 775// ----- 776 777// CHECK-LABEL: test_mismatch_in_out_shape_clamp 778func.func @test_mismatch_in_out_shape_clamp(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x1xf32> { 779 // expected-error@+1 {{'tosa.clamp' op requires the same shape for all operands and results}} 780 %0 = tosa.clamp %arg0 {min_fp = 0.0 : f32, max_fp = 1.0: f32, min_int = 0 : i64, max_int = 1 : i64} : (tensor<13x21x3xf32>) -> tensor<13x21x1xf32> 781 return %0 : tensor<13x21x1xf32> 782} 783 784// ----- 785 786// CHECK-LABEL: test_mismatch_in_out_data_type_erf 787func.func @test_mismatch_in_out_data_type_erf(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf16> { 788 // expected-error@+1 {{'tosa.erf' op requires the same element type for all operands and results}} 789 %0 = tosa.erf %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf16> 790 return %0 : tensor<13x21x3xf16> 791} 792 793// ----- 794 795// CHECK-LABEL: test_mismatch_in_out_shape_erf 796func.func @test_mismatch_in_out_shape_erf(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x1xf32> { 797 // expected-error@+1 {{'tosa.erf' op requires the same shape for all operands and results}} 798 %0 = tosa.erf %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x1xf32> 799 return %0 : tensor<13x21x1xf32> 800} 801 802// ----- 803 804// CHECK-LABEL: test_mismatch_in_out_data_type_sigmoid 805func.func @test_mismatch_in_out_data_type_sigmoid(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf16> { 806 // expected-error@+1 {{'tosa.sigmoid' op requires the same element type for all operands and results}} 807 %0 = tosa.sigmoid %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf16> 808 return %0 : tensor<13x21x3xf16> 809} 810 811// ----- 812 813// CHECK-LABEL: test_mismatch_in_out_shape_sigmoid 814func.func @test_mismatch_in_out_shape_sigmoid(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x1xf32> { 815 // expected-error@+1 {{'tosa.sigmoid' op requires the same shape for all operands and results}} 816 %0 = tosa.sigmoid %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x1xf32> 817 return %0 : tensor<13x21x1xf32> 818} 819 820// ----- 821 822// CHECK-LABEL: test_mismatch_in_out_data_type_tanh 823func.func @test_mismatch_in_out_data_type_tanh(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf16> { 824 // expected-error@+1 {{'tosa.tanh' op requires the same element type for all operands and results}} 825 %0 = tosa.tanh %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf16> 826 return %0 : tensor<13x21x3xf16> 827} 828 829// ----- 830 831// CHECK-LABEL: test_mismatch_in_out_shape_tanh 832func.func @test_mismatch_in_out_shape_tanh(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x1xf32> { 833 // expected-error@+1 {{'tosa.tanh' op requires the same shape for all operands and results}} 834 %0 = tosa.tanh %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x1xf32> 835 return %0 : tensor<13x21x1xf32> 836} 837 838// ----- 839 840// CHECK-LABEL: test_mismatch_in_out_data_type_cos 841func.func @test_mismatch_in_out_data_type_cos(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf16> { 842 // expected-error@+1 {{'tosa.cos' op requires the same element type for all operands and results}} 843 %0 = tosa.cos %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf16> 844 return %0 : tensor<13x21x3xf16> 845} 846 847// ----- 848 849// CHECK-LABEL: test_mismatch_in_out_shape_cos 850func.func @test_mismatch_in_out_shape_cos(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x1xf32> { 851 // expected-error@+1 {{'tosa.cos' op requires the same shape for all operands and results}} 852 %0 = tosa.cos %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x1xf32> 853 return %0 : tensor<13x21x1xf32> 854} 855 856// ----- 857 858// CHECK-LABEL: test_mismatch_in_out_data_type_sin 859func.func @test_mismatch_in_out_data_type_sin(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf16> { 860 // expected-error@+1 {{'tosa.sin' op requires the same element type for all operands and results}} 861 %0 = tosa.sin %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf16> 862 return %0 : tensor<13x21x3xf16> 863} 864 865// ----- 866 867// CHECK-LABEL: test_mismatch_in_out_shape_sin 868func.func @test_mismatch_in_out_shape_sin(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x1xf32> { 869 // expected-error@+1 {{'tosa.sin' op requires the same shape for all operands and results}} 870 %0 = tosa.sin %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x1xf32> 871 return %0 : tensor<13x21x1xf32> 872} 873 874// ----- 875 876// CHECK-LABEL: test_mismatch_in_out_data_type_abs 877func.func @test_mismatch_in_out_data_type_abs(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf16> { 878 // expected-error@+1 {{'tosa.abs' op requires the same element type for all operands and results}} 879 %0 = tosa.abs %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf16> 880 return %0 : tensor<13x21x3xf16> 881} 882 883// ----- 884 885// CHECK-LABEL: test_mismatch_in_out_shape_abs 886func.func @test_mismatch_in_out_shape_abs(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x1xf32> { 887 // expected-error@+1 {{'tosa.abs' op requires the same shape for all operands and results}} 888 %0 = tosa.abs %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x1xf32> 889 return %0 : tensor<13x21x1xf32> 890} 891 892// ----- 893 894// CHECK-LABEL: test_mismatch_in_out_data_type_bitwise_not 895func.func @test_mismatch_in_out_data_type_bitwise_not(%arg0: tensor<13x21x1xi32>) -> tensor<13x21x1xi16> { 896 // expected-error@+1 {{'tosa.bitwise_not' op requires the same element type for all operands and results}} 897 %0 = tosa.bitwise_not %arg0 : (tensor<13x21x1xi32>) -> tensor<13x21x1xi16> 898 return %0 : tensor<13x21x1xi16> 899} 900 901// ----- 902 903// CHECK-LABEL: test_mismatch_in_out_shape_bitwise_not 904func.func @test_mismatch_in_out_shape_bitwise_not(%arg0: tensor<13x21x1xi32>) -> tensor<13x21x3xi32> { 905 // expected-error@+1 {{'tosa.bitwise_not' op requires the same shape for all operands and results}} 906 %0 = tosa.bitwise_not %arg0 : (tensor<13x21x1xi32>) -> tensor<13x21x3xi32> 907 return %0 : tensor<13x21x3xi32> 908} 909 910// ----- 911 912// CHECK-LABEL: test_mismatch_in_out_data_type_ceil 913func.func @test_mismatch_in_out_data_type_ceil(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf16> { 914 // expected-error@+1 {{'tosa.ceil' op requires the same element type for all operands and results}} 915 %0 = tosa.ceil %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf16> 916 return %0 : tensor<13x21x3xf16> 917} 918 919// ----- 920 921// CHECK-LABEL: test_mismatch_in_out_shape_ceil 922func.func @test_mismatch_in_out_shape_ceil(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x1xf32> { 923 // expected-error@+1 {{'tosa.ceil' op requires the same shape for all operands and results}} 924 %0 = tosa.ceil %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x1xf32> 925 return %0 : tensor<13x21x1xf32> 926} 927 928// ----- 929 930// CHECK-LABEL: test_mismatch_in_out_data_type_clz 931func.func @test_mismatch_in_out_data_type_clz(%arg0: tensor<13x21x3xi32>) -> tensor<13x21x3xi16> { 932 // expected-error@+1 {{'tosa.clz' op requires the same element type for all operands and results}} 933 %0 = tosa.clz %arg0 : (tensor<13x21x3xi32>) -> tensor<13x21x3xi16> 934 return %0 : tensor<13x21x3xi16> 935} 936 937// ----- 938 939// CHECK-LABEL: test_mismatch_in_out_shape_clz 940func.func @test_mismatch_in_out_shape_clz(%arg0: tensor<13x21x3xi32>) -> tensor<13x21x1xi32> { 941 // expected-error@+1 {{'tosa.clz' op requires the same shape for all operands and results}} 942 %0 = tosa.clz %arg0 : (tensor<13x21x3xi32>) -> tensor<13x21x1xi32> 943 return %0 : tensor<13x21x1xi32> 944} 945 946// ----- 947// CHECK-LABEL: test_mismatch_in_out_data_type_cos 948func.func @test_mismatch_in_out_data_type_cos(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf16> { 949 // expected-error@+1 {{'tosa.cos' op requires the same element type for all operands and results}} 950 %0 = tosa.cos %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf16> 951 return %0 : tensor<13x21x3xf16> 952} 953 954// ----- 955// CHECK-LABEL: test_mismatch_in_out_shape_cos 956func.func @test_mismatch_in_out_shape_cos(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x1xf32> { 957 // expected-error@+1 {{'tosa.cos' op requires the same shape for all operands and results}} 958 %0 = tosa.cos %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x1xf32> 959 return %0 : tensor<13x21x1xf32> 960} 961 962// ----- 963// CHECK-LABEL: test_mismatch_in_out_data_type_exp 964func.func @test_mismatch_in_out_data_type_exp(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf16> { 965 // expected-error@+1 {{'tosa.exp' op requires the same element type for all operands and results}} 966 %0 = tosa.exp %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf16> 967 return %0 : tensor<13x21x3xf16> 968} 969 970// ----- 971// CHECK-LABEL: test_mismatch_in_out_shape_exp 972func.func @test_mismatch_in_out_shape_exp(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x1xf32> { 973 // expected-error@+1 {{'tosa.exp' op requires the same shape for all operands and results}} 974 %0 = tosa.exp %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x1xf32> 975 return %0 : tensor<13x21x1xf32> 976} 977 978// ----- 979// CHECK-LABEL: test_mismatch_in_out_data_type_floor 980func.func @test_mismatch_in_out_data_type_floor(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf16> { 981 // expected-error@+1 {{'tosa.floor' op requires the same element type for all operands and results}} 982 %0 = tosa.floor %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf16> 983 return %0 : tensor<13x21x3xf16> 984} 985 986// ----- 987// CHECK-LABEL: test_mismatch_in_out_shape_floor 988func.func @test_mismatch_in_out_shape_floor(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x1xf32> { 989 // expected-error@+1 {{'tosa.floor' op requires the same shape for all operands and results}} 990 %0 = tosa.floor %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x1xf32> 991 return %0 : tensor<13x21x1xf32> 992} 993 994// ----- 995// CHECK-LABEL: test_mismatch_in_out_data_type_log 996func.func @test_mismatch_in_out_data_type_log(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf16> { 997 // expected-error@+1 {{'tosa.log' op requires the same element type for all operands and results}} 998 %0 = tosa.log %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x3xf16> 999 return %0 : tensor<13x21x3xf16> 1000} 1001 1002// ----- 1003// CHECK-LABEL: test_mismatch_in_out_shape_log 1004func.func @test_mismatch_in_out_shape_log(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x1xf32> { 1005 // expected-error@+1 {{'tosa.log' op requires the same shape for all operands and results}} 1006 %0 = tosa.log %arg0 : (tensor<13x21x3xf32>) -> tensor<13x21x1xf32> 1007 return %0 : tensor<13x21x1xf32> 1008} 1009 1010// ----- 1011// CHECK-LABEL: test_mismatch_in_out_shape_logical_not 1012func.func @test_mismatch_in_out_shape_logical_not(%arg0: tensor<1x21x3xi1>) -> tensor<13x21x3xi1> { 1013 // expected-error@+1 {{'tosa.logical_not' op requires the same shape for all operands and results}} 1014 %0 = tosa.logical_not %arg0 : (tensor<1x21x3xi1>) -> tensor<13x21x3xi1> 1015 return %0 : tensor<13x21x3xi1> 1016} 1017 1018// ----- 1019 1020// Check validate pass doesn't run on non TOSA ops 1021func.func @test_non_tosa_ops() { 1022 %0 = arith.constant 6 : index 1023 %2 = tensor.empty(%0) : tensor<?x27xi64> 1024 return 1025} 1026 1027// ----- 1028 1029// expected-error@+1 {{invalid rank (must be >= 0): -1}} 1030func.func @test_shape_type(%arg0: !tosa.shape<-1>) -> !tosa.shape<-1> { 1031 return %arg0 : !tosa.shape<-1> 1032} 1033 1034// ----- 1035func.func @test_const_shape() -> !tosa.shape<4> { 1036 // expected-error@+1 {{'tosa.const_shape' op attribute 'value' failed to satisfy constraint: index elements attribute}} 1037 %cst = tosa.const_shape {value = dense<[1, 2, 3, 4]> : tensor<4xi32>} : () -> !tosa.shape<4> 1038 return %cst : !tosa.shape<4> 1039} 1040 1041// ----- 1042 1043func.func @test_const_shape_value() -> !tosa.shape<5> { 1044 // expected-error@+1 {{'tosa.const_shape' op expect number of elements in attribute value (4) to be equal to the rank (5) for the result shape type}} 1045 %cst = tosa.const_shape {value = dense<[1, 2, 3, 4]> : tensor<4xindex>} : () -> !tosa.shape<5> 1046 return %cst : !tosa.shape<5> 1047} 1048 1049// ----- 1050 1051func.func @test_sub_with_unequal_operand_ranks(%arg0: tensor<1x21x3xf32>, %arg1: tensor<1x13x21x3xf32>) -> tensor<1x13x21x3xf32> { 1052 // expected-error@+1 {{'tosa.sub' op operands don't have matching ranks}} 1053 %0 = tosa.sub %arg0, %arg1 : (tensor<1x21x3xf32>, tensor<1x13x21x3xf32>) -> tensor<1x13x21x3xf32> 1054 return %0 : tensor<1x13x21x3xf32> 1055} 1056 1057// ----- 1058 1059func.func @test_sub_with_unequal_result_ranks(%arg0: tensor<1x21x3xf32>, %arg1: tensor<13x21x3xf32>) -> tensor<1x13x21x3xf32> { 1060 // expected-error@+1 {{'tosa.sub' op result type has different rank than operands}} 1061 %0 = tosa.sub %arg0, %arg1 : (tensor<1x21x3xf32>, tensor<13x21x3xf32>) -> tensor<1x13x21x3xf32> 1062 return %0 : tensor<1x13x21x3xf32> 1063} 1064