1233 lines · plain
1//--------------------------------------------------------------------------------------------------2// Test expected errors generated by verifier checks.3//--------------------------------------------------------------------------------------------------4 5// RUN: mlir-opt %s -split-input-file -verify-diagnostics6 7// -----8 9func.func @test_transpose_io_rank_mismatch(%arg0: tensor<13x21x3xf32>, %arg1: tensor<3xi32>) -> tensor<3x13x21x1xf32> {10 // expected-error@+1 {{'tosa.transpose' op expected input tensor rank to equal result tensor rank}}11 %0 = tosa.transpose %arg0 {perms = array<i32: 2, 1, 0>}: (tensor<13x21x3xf32>) -> tensor<3x13x21x1xf32>12 return %0 : tensor<3x13x21x1xf32>13}14 15// -----16 17func.func @test_transpose_rank0_perms() {18 %14 = tensor.empty() : tensor<5x27xi64>19 // expected-error@+1 {{'tosa.transpose' op expected perms attribute to have size 2 (input rank) but got size 0}}20 %72 = tosa.transpose %14 {perms = array<i32> }: (tensor<5x27xi64>) -> tensor<?x?xi64>21 return22}23 24// -----25 26func.func @test_transpose_invalid_perms_size(%arg0: tensor<13x21x3xf32>) -> tensor<3x13x21xf32> {27 // expected-error@+1 {{'tosa.transpose' op expected perms attribute to have size 3 (input rank) but got size 7}}28 %0 = tosa.transpose %arg0 {perms = array<i32: 6, 5, 4, 3, 2, 1, 0> }: (tensor<13x21x3xf32>) -> tensor<3x13x21xf32>29 return %0 : tensor<3x13x21xf32>30}31 32// -----33 34func.func @test_transpose_invalid_permutation_tensor(%arg0: tensor<13x21x3xf32>) -> tensor<?x?x?xf32> {35 // expected-error@+1 {{'tosa.transpose' op expected valid permutation indices}}36 %0 = tosa.transpose %arg0 {perms = array<i32: 2, 0, 0> }: (tensor<13x21x3xf32>) -> tensor<?x?x?xf32>37 return %0 : tensor<?x?x?xf32>38}39 40// -----41 42func.func @test_transpose_invalid_permutation_negative(%arg0: tensor<3x2xi32>) -> tensor<*xi32> {43 // expected-error@+1 {{'tosa.transpose' op expected valid permutation indices}}44 %1 = tosa.transpose %arg0 {perms = array<i32: -1, 0> }: (tensor<3x2xi32>) -> tensor<*xi32>45 return %1 : tensor<*xi32>46}47 48// -----49 50func.func @test_transpose_invalid_permutation_tensor_above_range(%arg0: tensor<3x2xi32>) -> tensor<*xi32> {51 // expected-error@+1 {{'tosa.transpose' op expected valid permutation indices}}52 %1 = tosa.transpose %arg0 {perms = array<i32: 2, 0> }: (tensor<3x2xi32>) -> tensor<*xi32>53 return %1 : tensor<*xi32>54}55 56// -----57 58func.func @test_transpose_invalid_num_elements(%arg0: tensor<3x2xi32>) -> tensor<3x4xi32> {59 // expected-error@+1 {{'tosa.transpose' op expected input1 and output to have same numbers of elements, got 6 and 12}}60 %1 = tosa.transpose %arg0 {perms = array<i32: 1, 0> }: (tensor<3x2xi32>) -> tensor<3x4xi32>61 return %1 : tensor<3x4xi32>62}63 64// -----65 66func.func @test_transpose_invalid_permutation_types(%arg0: tensor<3x2xi32>) -> tensor<3x2xi32> {67 // expected-error@+1 {{'tosa.transpose' op expected output tensor dim 0 to match input dim 1 with value of 2}}68 %1 = tosa.transpose %arg0 {perms = array<i32: 1, 0> }: (tensor<3x2xi32>) -> tensor<3x2xi32>69 return %1 : tensor<3x2xi32>70}71 72// -----73 74func.func @test_transpose_invalid_permutation_types_dynamic_dim_ok(%arg0: tensor<2x?xi32>) -> tensor<3x4xi32> {75 // expected-error@+1 {{'tosa.transpose' op expected output tensor dim 1 to match input dim 0 with value of 2}}76 %1 = tosa.transpose %arg0 {perms = array<i32: 1, 0> }: (tensor<2x?xi32>) -> tensor<3x4xi32>77 return %1 : tensor<3x4xi32>78}79 80// -----81 82func.func @test_transpose_element_type_mismatch(%arg0: tensor<2x3xi32>) -> tensor<3x2xf32> {83 // expected-error@+1 {{'tosa.transpose' op failed to verify that all of {input1, output} have same element type}}84 %1 = tosa.transpose %arg0 {perms = array<i32: 1, 0>} : (tensor<2x3xi32>) -> tensor<3x2xf32>85 return %1 : tensor<3x2xf32>86}87 88// -----89 90// CHECK-LABEL: @test_invalid_constant_permutation91func.func @test_invalid_constant_permutation() {92 %0 = tensor.empty() : tensor<3x4x5xi32>93 // expected-error@+1 {{'tosa.transpose' op expected valid permutation indices}}94 %2 = tosa.transpose %0 {perms = array<i32: 3, 0, 1>}: (tensor<3x4x5xi32>) -> tensor<3x4x5xi32>95 return96}97 98// -----99 100// CHECK-LABEL: test_rank_size_constant_permutation101func.func @test_rank_size_constant_permutation() {102 %0 = arith.constant 6 : index103 %2 = tensor.empty(%0) : tensor<?x27xi64>104 // expected-error@+1 {{'tosa.transpose' op expected valid permutation indices}}105 %3 = tosa.transpose %2 {perms = array<i32: 0, 2>}: (tensor<?x27xi64>) -> tensor<?x27xi64>106 return107}108 109// -----110 111// CHECK-LABEL: test_large_constant_permutation112func.func @test_large_constant_permutation() {113 %0 = arith.constant 6 : index114 %2 = tensor.empty(%0) : tensor<?x27xi64>115 // expected-error@+1 {{'tosa.transpose' op expected valid permutation indices}}116 %3 = tosa.transpose %2 {perms = array<i32: 1185677355, 332462212>}: (tensor<?x27xi64>) -> tensor<?x27xi64>117 return118}119 120// -----121 122func.func @test_scalar_output_transpose(%arg0: tensor<*xf32>) -> tensor<f32> {123 // expected-error@+1 {{'tosa.transpose' op result #0 must be tosa-conformant tensor of at least rank 1, but got 'tensor<f32>'}}124 %1 = tosa.transpose %arg0 {perms = array<i32: 2, 0, 1>} : (tensor<*xf32>) -> tensor<f32>125 return %1 : tensor<f32>126}127 128// -----129 130func.func @test_slice_invalid_output_rank() {131 %0 = tensor.empty() : tensor<4x31x31xf32>132 %start = tosa.const_shape {values = dense<[1, 1]> : tensor<2xindex>} : () -> !tosa.shape<2>133 %size = tosa.const_shape {values = dense<[1, 1, 1]> : tensor<3xindex>} : () -> !tosa.shape<3>134 // expected-error@+1 {{'tosa.slice' op expect input1 and output to have the same ranks, got 3 and 4}}135 %3 = tosa.slice %0, %start, %size : (tensor<4x31x31xf32>, !tosa.shape<2>, !tosa.shape<3>) -> tensor<?x?x?x?xf32>136 return137}138 139// -----140 141func.func @test_slice_invalid_start() {142 %0 = tensor.empty() : tensor<4x31x31xf32>143 %start = tosa.const_shape {values = dense<[1, 1]> : tensor<2xindex>} : () -> !tosa.shape<2>144 %size = tosa.const_shape {values = dense<[1, 1, 1]> : tensor<3xindex>} : () -> !tosa.shape<3>145 // expected-error@+1 {{'tosa.slice' op length of start is not equal to rank of input shape}}146 %3 = tosa.slice %0, %start, %size : (tensor<4x31x31xf32>, !tosa.shape<2>, !tosa.shape<3>) -> tensor<*xf32>147 return148}149 150// -----151 152func.func @test_slice_invalid_size() {153 %0 = tensor.empty() : tensor<4x31x31xf32>154 %start = tosa.const_shape {values = dense<[1, 1, 1]> : tensor<3xindex>} : () -> !tosa.shape<3>155 %size = tosa.const_shape {values = dense<[1]> : tensor<1xindex>} : () -> !tosa.shape<1>156 // expected-error@+1 {{'tosa.slice' op length of size is not equal to rank of input shape}}157 %3 = tosa.slice %0, %start, %size : (tensor<4x31x31xf32>, !tosa.shape<3>, !tosa.shape<1>) -> tensor<*xf32>158 return159}160 161// -----162 163func.func @test_scalar_slice(%arg0: tensor<f32>) -> tensor<f32> {164 %0 = tosa.const_shape {values = dense<[]> : tensor<0xindex>} : () -> !tosa.shape<0>165 %1 = tosa.const_shape {values = dense<[]> : tensor<0xindex>} : () -> !tosa.shape<0>166 // expected-error@+1 {{'tosa.slice' op operand #0 must be tosa-conformant tensor of at least rank 1, but got 'tensor<f32>'}}167 %2 = tosa.slice %arg0, %0, %1 : (tensor<f32>, !tosa.shape<0>, !tosa.shape<0>) -> tensor<f32>168 return %2 : tensor<f32>169}170 171// -----172 173func.func @test_depthwise_conv2d_invalid_padding(%arg0: tensor<1x4x4x4xf32>, %arg1: tensor<1x1x8x4xf32>, %arg2: tensor<8xf32>, %arg3: tensor<1xf32>, %arg4: tensor<1xf32>) -> tensor<1x4x4x8xf32> {174 // expected-error@+1 {{'tosa.depthwise_conv2d' op expect all padding values to be >= 0, got 0, 0, -1, 0}}175 %0 = tosa.depthwise_conv2d %arg0, %arg1, %arg2, %arg3, %arg4 {acc_type = f32, dilation = array<i64: 1, 1>, pad = array<i64: 0, 0, -1, 0>, stride = array<i64: 1, 1>, local_bound = true}176 : (tensor<1x4x4x4xf32>, tensor<1x1x8x4xf32>, tensor<8xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1x4x4x8xf32>177 return %0 : tensor<1x4x4x8xf32>178}179 180// -----181 182func.func @test_depthwise_conv2d_invalid_stride(%arg0: tensor<1x4x4x4xf32>, %arg1: tensor<1x1x8x4xf32>, %arg2: tensor<8xf32>, %arg3: tensor<1xf32>, %arg4: tensor<1xf32>) -> tensor<1x4x4x8xf32> {183 // expected-error@+1 {{'tosa.depthwise_conv2d' op expect all stride values to be >= 1, got 0, 1}}184 %0 = tosa.depthwise_conv2d %arg0, %arg1, %arg2, %arg3, %arg4 {acc_type = f32, dilation = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 0, 1>, local_bound = true}185 : (tensor<1x4x4x4xf32>, tensor<1x1x8x4xf32>, tensor<8xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1x4x4x8xf32>186 return %0 : tensor<1x4x4x8xf32>187}188 189// -----190 191func.func @test_depthwise_conv2d_invalid_dilation(%arg0: tensor<1x4x4x4xf32>, %arg1: tensor<1x1x8x4xf32>, %arg2: tensor<8xf32>, %arg3: tensor<1xf32>, %arg4: tensor<1xf32>) -> tensor<1x4x4x8xf32> {192 // expected-error@+1 {{'tosa.depthwise_conv2d' op expect all dilation values to be >= 1, got 1, 0}}193 %0 = tosa.depthwise_conv2d %arg0, %arg1, %arg2, %arg3, %arg4 {acc_type = f32, dilation = array<i64: 1, 0>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>, local_bound = true}194 : (tensor<1x4x4x4xf32>, tensor<1x1x8x4xf32>, tensor<8xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1x4x4x8xf32>195 return %0 : tensor<1x4x4x8xf32>196}197 198// -----199 200func.func @test_depthwise_conv2d_wholly_divisible_height(%arg0: tensor<1x4x4x4xf32>, %arg1: tensor<1x1x8x4xf32>, %arg2: tensor<8xf32>, %arg3: tensor<1xf32>, %arg4: tensor<1xf32>) -> tensor<1x4x4x8xf32> {201 // expected-error@+1 {{'tosa.depthwise_conv2d' op expected input_height - 1 + pad_top + pad_bottom - (kernel_height - 1) * dilation_y to be wholly divisible by stride_y, got (4 - 1 + 0 + 0 - (1 - 1) * 1) / 2}}202 %0 = tosa.depthwise_conv2d %arg0, %arg1, %arg2, %arg3, %arg4 {acc_type = f32, dilation = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 2, 1>, local_bound = true}203 : (tensor<1x4x4x4xf32>, tensor<1x1x8x4xf32>, tensor<8xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1x4x4x8xf32>204 return %0 : tensor<1x4x4x8xf32>205}206 207// -----208 209func.func @test_depthwise_conv2d_wholly_divisible_width(%arg0: tensor<1x4x4x4xf32>, %arg1: tensor<1x1x8x4xf32>, %arg2: tensor<8xf32>, %arg3: tensor<1xf32>, %arg4: tensor<1xf32>) -> tensor<1x4x4x8xf32> {210 // expected-error@+1 {{'tosa.depthwise_conv2d' op expected input_width - 1 + pad_left + pad_right - (kernel_width - 1) * dilation_x to be wholly divisible by stride_x, got (4 - 1 + 0 + 0 - (1 - 1) * 1) / 2}}211 %0 = tosa.depthwise_conv2d %arg0, %arg1, %arg2, %arg3, %arg4 {acc_type = f32, dilation = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 2>, local_bound = true}212 : (tensor<1x4x4x4xf32>, tensor<1x1x8x4xf32>, tensor<8xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1x4x4x8xf32>213 return %0 : tensor<1x4x4x8xf32>214}215 216// -----217 218func.func @test_depthwise_conv2d_unexpected_output_height(%arg0: tensor<1x4x4x4xf32>, %arg1: tensor<1x1x8x4xf32>, %arg2: tensor<8xf32>, %arg3: tensor<1xf32>, %arg4: tensor<1xf32>) -> tensor<1x6x4x8xf32> {219 // expected-error@+1 {{'tosa.depthwise_conv2d' op calculated output height did not match expected: calculated=4, expected=6}}220 %0 = tosa.depthwise_conv2d %arg0, %arg1, %arg2, %arg3, %arg4 {acc_type = f32, dilation = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>, local_bound = true}221 : (tensor<1x4x4x4xf32>, tensor<1x1x8x4xf32>, tensor<8xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1x6x4x8xf32>222 return %0 : tensor<1x6x4x8xf32>223}224 225// -----226 227func.func @test_depthwise_conv2d_unexpected_output_width(%arg0: tensor<1x4x4x4xf32>, %arg1: tensor<1x1x8x4xf32>, %arg2: tensor<8xf32>, %arg3: tensor<1xf32>, %arg4: tensor<1xf32>) -> tensor<1x4x6x8xf32> {228 // expected-error@+1 {{'tosa.depthwise_conv2d' op calculated output width did not match expected: calculated=4, expected=6}}229 %0 = tosa.depthwise_conv2d %arg0, %arg1, %arg2, %arg3, %arg4 {acc_type = f32, dilation = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>, local_bound = true}230 : (tensor<1x4x4x4xf32>, tensor<1x1x8x4xf32>, tensor<8xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1x4x6x8xf32>231 return %0 : tensor<1x4x6x8xf32>232}233 234// -----235 236func.func @test_depthwise_conv2d_invalid_bias_size(%arg0: tensor<1x4x4x4xf32>, %arg1: tensor<1x1x8x4xf32>, %arg2: tensor<7xf32>, %arg3: tensor<1xf32>, %arg4: tensor<1xf32>) -> tensor<1x4x4x8xf32> {237 // expected-error@+1 {{'tosa.depthwise_conv2d' op bias channels expected to be equal to output channels (8) or 1, got 7}}238 %0 = tosa.depthwise_conv2d %arg0, %arg1, %arg2, %arg3, %arg4 {acc_type = f32, dilation = array<i64: 1, 1>, pad = array<i64: 0, 0, 0, 0>, stride = array<i64: 1, 1>, local_bound = true}239 : (tensor<1x4x4x4xf32>, tensor<1x1x8x4xf32>, tensor<7xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1x4x4x8xf32>240 return %0 : tensor<1x4x4x8xf32>241}242 243// -----244 245func.func @test_conv3d_invalid_padding(%arg0: tensor<1x4x8x21x17xf32>, %arg1: tensor<34x1x1x1x17xf32>, %arg2: tensor<21xf32>, %arg3: tensor<1xf32>, %arg4: tensor<1xf32>) -> tensor<1x4x8x21x34xf32> {246 // expected-error@+1 {{'tosa.conv3d' op expect all padding values to be >= 0, got 0, -1, 0, -1, 0, 0}}247 %0 = tosa.conv3d %arg0, %arg1, %arg2, %arg3, %arg4 {acc_type = f32, dilation = array<i64: 1, 2, 1>, pad = array<i64: 0, -1, 0, -1, 0, 0>, stride = array<i64: 1, 1, 1>}248 : (tensor<1x4x8x21x17xf32>, tensor<34x1x1x1x17xf32>, tensor<21xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1x4x8x21x34xf32>249 return %0 : tensor<1x4x8x21x34xf32>250}251// -----252 253func.func @test_conv3d_invalid_stride(%arg0: tensor<1x4x8x21x17xf32>, %arg1: tensor<34x1x1x1x17xf32>, %arg2: tensor<21xf32>, %arg3: tensor<1xf32>, %arg4: tensor<1xf32>) -> tensor<1x4x8x21x34xf32> {254 // expected-error@+1 {{'tosa.conv3d' op expect all stride values to be >= 1, got 0, 1, 1}}255 %0 = tosa.conv3d %arg0, %arg1, %arg2, %arg3, %arg4 {acc_type = f32, dilation = array<i64: 1, 1, 1>, pad = array<i64: 0, 0, 0, 0, 0, 0>, stride = array<i64: 0, 1, 1>}256 : (tensor<1x4x8x21x17xf32>, tensor<34x1x1x1x17xf32>, tensor<21xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1x4x8x21x34xf32>257 return %0 : tensor<1x4x8x21x34xf32>258}259 260// -----261 262func.func @test_conv3d_invalid_dilation(%arg0: tensor<1x4x8x21x17xf32>, %arg1: tensor<34x1x1x1x17xf32>, %arg2: tensor<21xf32>, %arg3: tensor<1xf32>, %arg4: tensor<1xf32>) -> tensor<1x4x8x21x34xf32> {263 // expected-error@+1 {{'tosa.conv3d' op expect all dilation values to be >= 1, got 1, 0, 1}}264 %0 = tosa.conv3d %arg0, %arg1, %arg2, %arg3, %arg4 {acc_type = f32, dilation = array<i64: 1, 0, 1>, pad = array<i64: 0, 0, 0, 0, 0, 0>, stride = array<i64: 1, 1, 1>}265 : (tensor<1x4x8x21x17xf32>, tensor<34x1x1x1x17xf32>, tensor<21xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1x4x8x21x34xf32>266 return %0 : tensor<1x4x8x21x34xf32>267}268 269// -----270 271func.func @test_conv3d_wholly_divisible_input_depth(%arg0: tensor<1x4x16x21x17xf32>, %arg1: tensor<34x1x1x1x17xf32>, %arg2: tensor<21xf32>, %arg3: tensor<1xf32>, %arg4: tensor<1xf32>) -> tensor<1x4x8x21x34xf32> {272 // expected-error@+1 {{'tosa.conv3d' op expected input_depth - 1 + pad_front + pad_back - (kernel_depth - 1) * dilation_d to be wholly divisible by stride_d, got (4 - 1 + 0 + 0 - (1 - 1) * 1) / 2}}273 %0 = tosa.conv3d %arg0, %arg1, %arg2, %arg3, %arg4 {acc_type = f32, dilation = array<i64: 1, 1, 1>, pad = array<i64: 0, 0, 0, 0, 0, 0>, stride = array<i64: 2, 1, 1>}274 : (tensor<1x4x16x21x17xf32>, tensor<34x1x1x1x17xf32>, tensor<21xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1x4x8x21x34xf32>275 return %0 : tensor<1x4x8x21x34xf32>276}277 278// -----279 280func.func @test_conv3d_wholly_divisible_input_height(%arg0: tensor<1x4x10x21x17xf32>, %arg1: tensor<34x1x1x1x17xf32>, %arg2: tensor<21xf32>, %arg3: tensor<1xf32>, %arg4: tensor<1xf32>) -> tensor<1x4x8x21x34xf32> {281 // expected-error@+1 {{'tosa.conv3d' op expected input_height - 1 + pad_top + pad_bottom - (kernel_height - 1) * dilation_y to be wholly divisible by stride_y, got (10 - 1 + 0 + 0 - (1 - 1) * 1) / 4}}282 %0 = tosa.conv3d %arg0, %arg1, %arg2, %arg3, %arg4 {acc_type = f32, dilation = array<i64: 1, 1, 1>, pad = array<i64: 0, 0, 0, 0, 0, 0>, stride = array<i64: 1, 4, 1>}283 : (tensor<1x4x10x21x17xf32>, tensor<34x1x1x1x17xf32>, tensor<21xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1x4x8x21x34xf32>284 return %0 : tensor<1x4x8x21x34xf32>285}286 287// -----288 289func.func @test_conv3d_wholly_divisible_input_width(%arg0: tensor<1x4x8x21x19xf32>, %arg1: tensor<34x1x1x1x17xf32>, %arg2: tensor<21xf32>, %arg3: tensor<1xf32>, %arg4: tensor<1xf32>) -> tensor<1x4x8x21x34xf32> {290 // expected-error@+1 {{'tosa.conv3d' op expected input_width - 1 + pad_left + pad_right - (kernel_width - 1) * dilation_x to be wholly divisible by stride_x, got (21 - 1 + 0 + 0 - (1 - 1) * 1) / 8}}291 %0 = tosa.conv3d %arg0, %arg1, %arg2, %arg3, %arg4 {acc_type = f32, dilation = array<i64: 1, 1, 1>, pad = array<i64: 0, 0, 0, 0, 0, 0>, stride = array<i64: 1, 1, 8>}292 : (tensor<1x4x8x21x19xf32>, tensor<34x1x1x1x17xf32>, tensor<21xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1x4x8x21x34xf32>293 return %0 : tensor<1x4x8x21x34xf32>294}295 296// -----297 298func.func @test_conv3d_wholly_divisible_output_depth(%arg0: tensor<1x4x10x21x17xf32>, %arg1: tensor<34x1x1x1x17xf32>, %arg2: tensor<21xf32>, %arg3: tensor<1xf32>, %arg4: tensor<1xf32>) -> tensor<1x3x10x21x34xf32> {299 // expected-error@+1 {{'tosa.conv3d' op calculated output depth did not match expected: calculated=4, expected=3}}300 %0 = tosa.conv3d %arg0, %arg1, %arg2, %arg3, %arg4 {acc_type = f32, dilation = array<i64: 1, 1, 1>, pad = array<i64: 0, 0, 0, 0, 0, 0>, stride = array<i64: 1, 1, 1>}301 : (tensor<1x4x10x21x17xf32>, tensor<34x1x1x1x17xf32>, tensor<21xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1x3x10x21x34xf32>302 return %0 : tensor<1x3x10x21x34xf32>303}304 305// -----306 307func.func @test_conv3d_wholly_divisible_output_height(%arg0: tensor<1x4x16x21x17xf32>, %arg1: tensor<34x1x1x1x17xf32>, %arg2: tensor<21xf32>, %arg3: tensor<1xf32>, %arg4: tensor<1xf32>) -> tensor<1x4x8x21x34xf32> {308 // expected-error@+1 {{'tosa.conv3d' op calculated output height did not match expected: calculated=16, expected=8}}309 %0 = tosa.conv3d %arg0, %arg1, %arg2, %arg3, %arg4 {acc_type = f32, dilation = array<i64: 1, 1, 1>, pad = array<i64: 0, 0, 0, 0, 0, 0>, stride = array<i64: 1, 1, 1>}310 : (tensor<1x4x16x21x17xf32>, tensor<34x1x1x1x17xf32>, tensor<21xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1x4x8x21x34xf32>311 return %0 : tensor<1x4x8x21x34xf32>312}313 314// -----315 316func.func @test_conv3d_wholly_divisible_output_width(%arg0: tensor<1x4x8x21x19xf32>, %arg1: tensor<34x1x1x1x17xf32>, %arg2: tensor<21xf32>, %arg3: tensor<1xf32>, %arg4: tensor<1xf32>) -> tensor<1x4x8x19x34xf32> {317 // expected-error@+1 {{'tosa.conv3d' op calculated output width did not match expected: calculated=21, expected=19}}318 %0 = tosa.conv3d %arg0, %arg1, %arg2, %arg3, %arg4 {acc_type = f32, dilation = array<i64: 1, 1, 1>, pad = array<i64: 0, 0, 0, 0, 0, 0>, stride = array<i64: 1, 1, 1>}319 : (tensor<1x4x8x21x19xf32>, tensor<34x1x1x1x17xf32>, tensor<21xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1x4x8x19x34xf32>320 return %0 : tensor<1x4x8x19x34xf32>321}322 323// -----324 325func.func @test_concat_element_type_mismatch(%arg0 : tensor<1x2xf32>, %arg1 : tensor<2x2xf32>) -> tensor<?x?xi8> {326 // expected-error@+1 {{'tosa.concat' op expect input and output to have same element type, got 'f32' and 'i8'}}327 %0 = tosa.concat %arg0, %arg1 {axis = 0 : i32} : (tensor<1x2xf32>, tensor<2x2xf32>) -> tensor<?x?xi8>328 return %0 : tensor<?x?xi8>329}330 331// -----332 333func.func @test_concat_zero_inputs() {334 // expected-error@+1 {{'tosa.concat' op expect at least one input}}335 %0 = tosa.concat {axis = 0 : i32} : () -> tensor<*xf32>336}337 338// -----339 340func.func @test_concat_axis_negative(%arg0: tensor<1x2xf32>, %arg1: tensor<2x2xf32>) -> tensor<2x2xf32> {341 // expected-error@+1 {{'tosa.concat' op expect axis to be within range 0 < axis < rank(input1[firstRankedTensorIdx]), got -1}}342 %0 = tosa.concat %arg0, %arg1 {axis = -1 : i32} : (tensor<1x2xf32>, tensor<2x2xf32>) -> tensor<2x2xf32>343 return %0 : tensor<2x2xf32>344}345 346// -----347 348func.func @test_concat_axis_out_of_range(%arg0: tensor<1x2xf32>, %arg1: tensor<2x2xf32>) -> tensor<2x2xf32> {349 // expected-error@+1 {{'tosa.concat' op expect axis to be within range 0 < axis < rank(input1[firstRankedTensorIdx]), got 3}}350 %0 = tosa.concat %arg0, %arg1 {axis = 3 : i32} : (tensor<1x2xf32>, tensor<2x2xf32>) -> tensor<2x2xf32>351 return %0 : tensor<2x2xf32>352}353 354// -----355 356func.func @test_concat_axis_sum_error(%arg0: tensor<1x2xf32>, %arg1: tensor<2x?xf32>) -> tensor<2x?xf32> {357 // expected-error@+1 {{'tosa.concat' op requires sum of axis dimensions of input1 equal to output axis dimension, got 3 and 2}}358 %0 = tosa.concat %arg0, %arg1 {axis = 0 : i32} : (tensor<1x2xf32>, tensor<2x?xf32>) -> tensor<2x?xf32>359 return %0 : tensor<2x?xf32>360}361 362// -----363 364func.func @test_error_scalar_input_with_per_channel(%arg0: tensor<i8>) -> tensor<i16> {365 %multiplier = "tosa.const"() {values = dense<4> : tensor<1xi32> } : () -> tensor<1xi32>366 %shift = "tosa.const"() {values = dense<2> : tensor<1xi8> } : () -> tensor<1xi8>367 %input_zp = "tosa.const"() {values = dense<0> : tensor<1xi8>} : () -> tensor<1xi8>368 %output_zp = "tosa.const"() {values = dense<0> : tensor<1xi16>} : () -> tensor<1xi16>369 // expected-error@+1 {{'tosa.rescale' op requires input to be at least rank 1 when per_channel is true, but got rank 0}}370 %0 = tosa.rescale %arg0, %multiplier, %shift, %input_zp, %output_zp {scale32 = true, rounding_mode = SINGLE_ROUND, per_channel = true, input_unsigned = false, output_unsigned = false} : (tensor<i8>, tensor<1xi32>, tensor<1xi8>, tensor<1xi8>, tensor<1xi16>) -> tensor<i16>371 return %0 : tensor<i16>372}373 374// -----375 376// CHECK-LABEL: @test_gather_invalid_indices_N377func.func @test_gather_invalid_indices_N(%arg0: tensor<13x21x3xf32>, %arg1: tensor<12x26xi32>) -> tensor<13x26x3xf32> {378 // expected-error@+1 {{'tosa.gather' op requires indices dimension 0 to have size 13, got 12}}379 %0 = tosa.gather %arg0, %arg1 : (tensor<13x21x3xf32>, tensor<12x26xi32>) -> tensor<13x26x3xf32>380 return %0 : tensor<13x26x3xf32>381}382 383// -----384// CHECK-LABEL: test_gather_invalid_out_N385func.func @test_gather_invalid_out_N(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x26xi32>) -> tensor<12x26x3xf32> {386 // expected-error@+1 {{'tosa.gather' op requires output dimension 0 to have size 13, got 12}}387 %0 = tosa.gather %arg0, %arg1 : (tensor<13x21x3xf32>, tensor<13x26xi32>) -> tensor<12x26x3xf32>388 return %0 : tensor<12x26x3xf32>389}390 391// -----392// CHECK-LABEL: test_gather_invalid_out_W393func.func @test_gather_invalid_out_W(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x26xi32>) -> tensor<13x28x3xf32> {394 // expected-error@+1 {{'tosa.gather' op requires output dimension 1 to have size 26, got 28}}395 %0 = tosa.gather %arg0, %arg1 : (tensor<13x21x3xf32>, tensor<13x26xi32>) -> tensor<13x28x3xf32>396 return %0 : tensor<13x28x3xf32>397}398 399// -----400// CHECK-LABEL: test_gather_invalid_out_C401func.func @test_gather_invalid_out_C(%arg0: tensor<13x21x3xf32>, %arg1: tensor<13x26xi32>) -> tensor<13x26x8xf32> {402 // expected-error@+1 {{'tosa.gather' op requires output dimension 2 to have size 3, got 8}}403 %0 = tosa.gather %arg0, %arg1 : (tensor<13x21x3xf32>, tensor<13x26xi32>) -> tensor<13x26x8xf32>404 return %0 : tensor<13x26x8xf32>405}406 407// -----408func.func @test_pad_padding_shape_mismatch(%arg0: tensor<13x21x3xf32>) -> tensor<13x21x3xf32> {409 %0 = tosa.const_shape {values = dense<1> : tensor<4xindex>} : () -> !tosa.shape<4>410 %pad_const = "tosa.const"() {values = dense<3.14> : tensor<1xf32>} : () -> tensor<1xf32>411 // expected-error@+1 {{'tosa.pad' op padding tensor must have 3 * 2 = 6 elements, but got 4}}412 %1 = tosa.pad %arg0, %0, %pad_const : (tensor<13x21x3xf32>, !tosa.shape<4>, tensor<1xf32>) -> tensor<13x21x3xf32>413 return %1 : tensor<13x21x3xf32>414}415 416// -----417func.func @test_pad_invalid_padding_rank(%arg0: tensor<13x21xf32>) {418 %0 = tosa.const_shape {values = dense<1> : tensor<6xindex>} : () -> !tosa.shape<6>419 %pad_const = "tosa.const"() {values = dense<3.14> : tensor<1xf32>} : () -> tensor<1xf32>420 // expected-error@+1 {{'tosa.pad' op padding tensor must have 2 * 2 = 4 elements, but got 6}}421 %1 = tosa.pad %arg0, %0, %pad_const : (tensor<13x21xf32>, !tosa.shape<6>, tensor<1xf32>) -> tensor<13x21xf32>422 return423}424 425// -----426func.func @test_pad_output_mismatch(%arg0: tensor<13x21x3xi8>, %arg1: tensor<1xi8>) -> tensor<13x21x3xi8> {427 %0 = tosa.const_shape {values = dense<[0, 0, 0, 1, 0, 1]> : tensor<6xindex>} : () -> !tosa.shape<6>428 // expected-error@+1 {{mismatch in output shape at dimension 1: expected 21 + 0 + 1 = 22, but got 21}}429 %1 = tosa.pad %arg0, %0, %arg1 : (tensor<13x21x3xi8>, !tosa.shape<6>, tensor<1xi8>) -> tensor<13x21x3xi8>430 return %1 : tensor<13x21x3xi8>431}432 433// -----434func.func @test_pad_invalid_padding_value(%arg0: tensor<10xi8>, %arg1: tensor<1xi8>) -> tensor<10xi8> {435 %0 = tosa.const_shape {values = dense<[-2, 2]> : tensor<2xindex>} : () -> !tosa.shape<2>436 // expected-error@+1 {{invalid padding values at dimension 0: values must be non-negative or -1 for dynamic padding, got [-2, 2]}}437 %1 = tosa.pad %arg0, %0, %arg1 : (tensor<10xi8>, !tosa.shape<2>, tensor<1xi8>) -> tensor<10xi8>438 return %1 : tensor<10xi8>439}440 441// -----442func.func @test_cond_if_wrong_terminator_op(%arg0: tensor<i1>) -> tensor<i32> {443 %0 = "tosa.cond_if"(%arg0) ({444 %1 = "tosa.const"() <{values = dense<1> : tensor<i32>}> : () -> tensor<i32>445 "tosa.yield"(%1) : (tensor<i32>) -> ()446 }, {447 // expected-error@+2 {{'func.return' op expects parent op 'func.func'}}448 %2 = "tosa.const"() <{values = dense<2> : tensor<i32>}> : () -> tensor<i32>449 "func.return"(%2) : (tensor<i32>) -> ()450 }) : (tensor<i1>) -> tensor<i32>451 return %0 : tensor<i32>452}453 454// -----455func.func @test_cond_if_missing_then_terminator(%arg0: tensor<i1>) -> tensor<i32> {456 %0 = "tosa.cond_if"(%arg0) ({457 // expected-error@+1 {{block with no terminator}}458 %1 = "tosa.const"() <{values = dense<1> : tensor<i32>}> : () -> tensor<i32>459 }, {460 %2 = "tosa.const"() <{values = dense<2> : tensor<i32>}> : () -> tensor<i32>461 "tosa.yield"(%2) : (tensor<i32>) -> ()462 }) : (tensor<i1>) -> tensor<i32>463 return %0 : tensor<i32>464}465 466// -----467func.func @test_cond_if_missing_else_terminator(%arg0: tensor<i1>) -> tensor<i32> {468 %0 = "tosa.cond_if"(%arg0) ({469 %1 = "tosa.const"() <{values = dense<1> : tensor<i32>}> : () -> tensor<i32>470 "tosa.yield"(%1) : (tensor<i32>) -> ()471 }, {472 // expected-error@+1 {{block with no terminator}}473 %2 = "tosa.const"() <{values = dense<2> : tensor<i32>}> : () -> tensor<i32>474 }) : (tensor<i1>) -> tensor<i32>475 return %0 : tensor<i32>476}477 478// -----479 480func.func @test_cond_if_input_list_mismatch_then_block(%arg0: tensor<f32>, %arg1: tensor<f32>, %arg2: tensor<i1>) -> tensor<f32> {481 // expected-error@+1 {{'tosa.cond_if' op require same number of values in 'then_graph' arguments (1) and 'input_list' (2)}}482 %0 = "tosa.cond_if"(%arg2, %arg0, %arg1) ({483 ^bb0(%arg3: tensor<f32>):484 tosa.yield %arg3 : tensor<f32>485 }, {486 ^bb0(%arg4: tensor<f32>):487 tosa.yield %arg4 : tensor<f32>488 }) : (tensor<i1>, tensor<f32>, tensor<f32>) -> tensor<f32>489 return %0 : tensor<f32>490 491}492 493// -----494 495func.func @test_cond_if_input_list_mismatch_then_block_2(%arg0: tensor<f32>, %arg1: tensor<f32>, %arg2: tensor<i1>) -> tensor<f32> {496 // expected-error@+1 {{'tosa.cond_if' op require same number of values in 'then_graph' arguments (2) and 'input_list' (1)}}497 %0 = "tosa.cond_if"(%arg2, %arg0) ({498 ^bb0(%arg3: tensor<f32>, %arg4: tensor<f32>):499 tosa.yield %arg3 : tensor<f32>500 }, {501 ^bb0(%arg4: tensor<f32>):502 tosa.yield %arg4 : tensor<f32>503 }) : (tensor<i1>, tensor<f32>) -> tensor<f32>504 return %0 : tensor<f32>505 506}507 508// -----509 510func.func @test_cond_if_input_list_mismatch_else_block(%arg0: tensor<f32>, %arg1: tensor<f32>, %arg2: tensor<i1>) -> tensor<f32> {511 // expected-error@+1 {{'tosa.cond_if' op require same number of values in 'else_graph' arguments (1) and 'input_list' (2)}}512 %0 = "tosa.cond_if"(%arg2, %arg0, %arg1) ({513 ^bb0(%arg3: tensor<f32>, %arg4: tensor<f32>):514 tosa.yield %arg3 : tensor<f32>515 }, {516 ^bb0(%arg4: tensor<f32>):517 tosa.yield %arg4 : tensor<f32>518 }) : (tensor<i1>, tensor<f32>, tensor<f32>) -> tensor<f32>519 return %0 : tensor<f32>520 521}522 523// -----524 525func.func @test_cond_if_input_list_mismatch_else_block_2(%arg0: tensor<f32>, %arg1: tensor<f32>, %arg2: tensor<i1>) -> tensor<f32> {526 // expected-error@+1 {{'tosa.cond_if' op require same number of values in 'else_graph' arguments (2) and 'input_list' (1)}}527 %0 = "tosa.cond_if"(%arg2, %arg0) ({528 ^bb0(%arg3: tensor<f32>):529 tosa.yield %arg3 : tensor<f32>530 }, {531 ^bb0(%arg4: tensor<f32>, %arg3: tensor<f32>):532 tosa.yield %arg4 : tensor<f32>533 }) : (tensor<i1>, tensor<f32>) -> tensor<f32>534 return %0 : tensor<f32>535 536}537 538// -----539 540func.func @test_cond_if_input_list_mismatch_else_block_simple(%arg0: tensor<f32>, %arg1: tensor<f32>, %arg2: tensor<i1>) -> tensor<f32> {541 // expected-error@+1 {{'tosa.cond_if' op require same number of values in 'else_graph' arguments (1) and 'input_list' (2)}}542 %0 = tosa.cond_if %arg2 (%arg3 = %arg0, %arg4 = %arg1) : tensor<i1> (tensor<f32>, tensor<f32>) -> tensor<f32> {543 ^bb0(%arg3: tensor<f32>, %arg4: tensor<f32>):544 %1 = tosa.add %arg3, %arg4 : (tensor<f32>, tensor<f32>) -> tensor<f32>545 tosa.yield %1 : tensor<f32>546 } else {547 ^bb0(%arg3: tensor<f32>):548 tosa.yield %arg3 : tensor<f32>549 }550 return %0 : tensor<f32>551}552 553// -----554 555func.func @test_cond_if_input_list_mismatch_else_block_simple_2(%arg0: tensor<f32>, %arg1: tensor<f32>, %arg2: tensor<i1>) -> tensor<f32> {556 // expected-error@+1 {{'tosa.cond_if' op require same number of values in 'else_graph' arguments (2) and 'input_list' (1)}}557 %0 = tosa.cond_if %arg2 (%arg3 = %arg0) : tensor<i1> (tensor<f32>) -> tensor<f32> {558 ^bb0(%arg3: tensor<f32>):559 tosa.yield %arg3 : tensor<f32>560 } else {561 ^bb0(%arg3: tensor<f32>, %arg4: tensor<f32>):562 %1 = tosa.sub %arg3, %arg4 : (tensor<f32>, tensor<f32>) -> tensor<f32>563 tosa.yield %1 : tensor<f32>564 }565 return %0 : tensor<f32>566}567 568// -----569 570func.func @test_cond_if_output_list_mismatch_then_block(%arg0: tensor<f32>, %arg1: tensor<f32>, %arg2: tensor<i1>) -> tensor<f32> {571 // expected-error@+1 {{'tosa.cond_if' op require same number of values in 'then_graph' results (2) and 'output_list' (1)}}572 %0 = tosa.cond_if %arg2 : tensor<i1> -> tensor<f32> {573 %1 = tosa.add %arg0, %arg1 : (tensor<f32>, tensor<f32>) -> tensor<f32>574 %2 = tosa.add %1, %arg1 : (tensor<f32>, tensor<f32>) -> tensor<f32>575 tosa.yield %1, %2 : tensor<f32>, tensor<f32>576 } else {577 %1 = tosa.sub %arg0, %arg1 : (tensor<f32>, tensor<f32>) -> tensor<f32>578 tosa.yield %1 : tensor<f32>579 }580 return %0 : tensor<f32>581}582 583// -----584 585func.func @test_cond_if_output_list_mismatch_then_block_2(%arg0: tensor<f32>, %arg1: tensor<f32>, %arg2: tensor<i1>) -> tensor<f32> {586 // expected-error@+1 {{'tosa.cond_if' op require same number of values in 'then_graph' results (1) and 'output_list' (2)}}587 %0, %2 = tosa.cond_if %arg2 : tensor<i1> -> (tensor<f32>, tensor<f32>) {588 %1 = tosa.add %arg0, %arg1 : (tensor<f32>, tensor<f32>) -> tensor<f32>589 tosa.yield %1 : tensor<f32>590 } else {591 %1 = tosa.sub %arg0, %arg1 : (tensor<f32>, tensor<f32>) -> tensor<f32>592 tosa.yield %1 : tensor<f32>593 }594 return %0 : tensor<f32>595}596 597// -----598 599func.func @test_cond_if_output_list_mismatch_else_block(%arg0: tensor<f32>, %arg1: tensor<f32>, %arg2: tensor<i1>) -> tensor<f32> {600 // expected-error@+1 {{'tosa.cond_if' op require same number of values in 'else_graph' results (2) and 'output_list' (1)}}601 %0 = tosa.cond_if %arg2 : tensor<i1> -> tensor<f32> {602 %1 = tosa.add %arg0, %arg1 : (tensor<f32>, tensor<f32>) -> tensor<f32>603 tosa.yield %1 : tensor<f32>604 } else {605 %1 = tosa.sub %arg0, %arg1 : (tensor<f32>, tensor<f32>) -> tensor<f32>606 %2 = tosa.add %1, %arg1 : (tensor<f32>, tensor<f32>) -> tensor<f32>607 tosa.yield %1, %2 : tensor<f32>, tensor<f32>608 }609 return %0 : tensor<f32>610}611 612// -----613 614func.func @test_cond_if_output_list_mismatch_else_block_2(%arg0: tensor<f32>, %arg1: tensor<f32>, %arg2: tensor<i1>) -> tensor<f32> {615 // expected-error@+1 {{'tosa.cond_if' op require same number of values in 'else_graph' results (1) and 'output_list' (2)}}616 %0, %2 = tosa.cond_if %arg2 : tensor<i1> -> (tensor<f32>, tensor<f32>) {617 %1 = tosa.add %arg0, %arg1 : (tensor<f32>, tensor<f32>) -> tensor<f32>618 %2 = tosa.sub %arg0, %arg1 : (tensor<f32>, tensor<f32>) -> tensor<f32>619 tosa.yield %1, %2 : tensor<f32>, tensor<f32>620 } else {621 %1 = tosa.sub %arg0, %arg1 : (tensor<f32>, tensor<f32>) -> tensor<f32>622 tosa.yield %1 : tensor<f32>623 }624 return %0 : tensor<f32>625}626 627// -----628 629func.func @test_cond_if_cond_input_not_size_one(%arg0: tensor<f32>, %arg1: tensor<f32>, %arg2: tensor<2xi1>) -> tensor<f32> {630 // expected-error@+1 {{'tosa.cond_if' op 'condition' must be a size 1 tensor, got 'tensor<2xi1>'}}631 %0 = "tosa.cond_if"(%arg2, %arg0, %arg1) ({632 ^bb0(%arg3: tensor<f32>, %arg4: tensor<f32>):633 tosa.yield %arg3 : tensor<f32>634 }, {635 ^bb0(%arg3: tensor<f32>, %arg4: tensor<f32>):636 tosa.yield %arg4 : tensor<f32>637 }) : (tensor<2xi1>, tensor<f32>, tensor<f32>) -> tensor<f32>638 return %0 : tensor<f32>639 640}641 642// -----643 644// CHECK-LABEL: cond_if_cond_type645func.func @test_cond_if_cond_type(%arg0: tensor<f32>, %arg1: tensor<f32>, %arg2: tensor<i1>) -> tensor<f32> {646 // expected-error@+2 {{expected ':'}}647 // expected-error@+1 {{custom op 'tosa.cond_if' expected type for condition operand}}648 %0 = tosa.cond_if %arg2 -> (tensor<f32>) {649 tosa.yield %arg0 : tensor<f32>650 } else {651 tosa.yield %arg1 : tensor<f32>652 }653 return %0 : tensor<f32>654}655 656// -----657 658func.func @test_cond_if_input_list_type_mismatch_simple(%arg0: tensor<f32>, %arg1: tensor<f32>, %arg2: tensor<i1>) -> tensor<f32> {659 // expected-error@+1 {{custom op 'tosa.cond_if' expected as many input types as operands (expected 2 got 0)}}660 %0 = tosa.cond_if %arg2 (%arg3 = %arg0, %arg4 = %arg1) : tensor<i1> () -> tensor<f32> {661 ^bb0(%arg3: tensor<f32>, %arg4: tensor<f32>):662 %1 = tosa.add %arg3, %arg4 : (tensor<f32>, tensor<f32>) -> tensor<f32>663 tosa.yield %1 : tensor<f32>664 } else {665 ^bb0(%arg3: tensor<f32>, %arg4: tensor<f32>):666 %1 = tosa.sub %arg3, %arg4 : (tensor<f32>, tensor<f32>) -> tensor<f32>667 tosa.yield %1 : tensor<f32>668 }669 return %0 : tensor<f32>670}671 672// -----673 674func.func @test_cond_if_incorrect_type_simple(%arg0: tensor<f32>, %arg1: tensor<f32>, %arg2: tensor<i1>) -> tensor<f32> {675 // expected-error@+2 {{expected non-function type}}676 // expected-error@+1 {{custom op 'tosa.cond_if' expected list of types for block arguments followed by arrow type and list of return types}}677 %0 = tosa.cond_if %arg2 (%arg3 = %arg0, %arg4 = %arg1) : tensor<i1> (%arg3) -> tensor<f32> {678 ^bb0(%arg3: tensor<f32>, %arg4: tensor<f32>):679 %1 = tosa.add %arg3, %arg4 : (tensor<f32>, tensor<f32>) -> tensor<f32>680 tosa.yield %1 : tensor<f32>681 } else {682 ^bb0(%arg3: tensor<f32>, %arg4: tensor<f32>):683 %1 = tosa.sub %arg3, %arg4 : (tensor<f32>, tensor<f32>) -> tensor<f32>684 tosa.yield %1 : tensor<f32>685 }686 return %0 : tensor<f32>687}688 689// -----690func.func @test_while_loop_wrong_terminator(%arg0: tensor<i32>, %arg1: tensor<i32>) -> tensor<i32> {691 %0 = tosa.while_loop (%arg2 = %arg0) : (tensor<i32>) -> tensor<i32> {692 // expected-error@+2 {{'func.return' op expects parent op 'func.func'}}693 %1 = tosa.greater_equal %arg1, %arg2 : (tensor<i32>, tensor<i32>) -> tensor<i1>694 "func.return"(%arg2) : (tensor<i32>) -> ()695 } do {696 ^bb0(%arg2: tensor<i32>):697 %1 = "tosa.const"() <{values = dense<1> : tensor<i32>}> : () -> tensor<i32>698 %2 = tosa.add %arg2, %1 : (tensor<i32>, tensor<i32>) -> tensor<i32>699 tosa.yield %2 : tensor<i32>700 }701 return %0 : tensor<i32>702}703 704// -----705func.func @test_while_loop_missing_cond_terminator(%arg0: tensor<i32>, %arg1: tensor<i32>) -> tensor<i32> {706 %0 = tosa.while_loop (%arg2 = %arg0) : (tensor<i32>) -> tensor<i32> {707 // expected-error@+1 {{block with no terminator}}708 %1 = tosa.greater_equal %arg1, %arg2 : (tensor<i32>, tensor<i32>) -> tensor<i1>709 } do {710 ^bb0(%arg2: tensor<i32>):711 %1 = "tosa.const"() <{values = dense<1> : tensor<i32>}> : () -> tensor<i32>712 %2 = tosa.add %arg2, %1 : (tensor<i32>, tensor<i32>) -> tensor<i32>713 tosa.yield %2 : tensor<i32>714 }715 return %0 : tensor<i32>716}717 718// -----719func.func @test_while_loop_missing_body_terminator(%arg0: tensor<i32>, %arg1: tensor<i32>) -> tensor<i32> {720 %0 = tosa.while_loop (%arg2 = %arg0) : (tensor<i32>) -> tensor<i32> {721 %1 = tosa.greater_equal %arg1, %arg2 : (tensor<i32>, tensor<i32>) -> tensor<i1>722 tosa.yield %1 : tensor<i1>723 } do {724 ^bb0(%arg2: tensor<i32>):725 // expected-error@+1 {{block with no terminator}}726 %1 = "tosa.const"() <{values = dense<1> : tensor<i32>}> : () -> tensor<i32>727 }728 return %0 : tensor<i32>729}730 731// -----732 733func.func @test_while_loop_input_list_mismatch_body_block_in(%arg0: tensor<10xi32>, %arg1: tensor<i32>) {734 %0 = "tosa.const"() {values = dense<0> : tensor<i32>} : () -> tensor<i32>735 // expected-error@+1 {{'tosa.while_loop' op require same number of values in 'body_graph' arguments (3) and 'input_list' (2)}}736 %1:2 = tosa.while_loop (%arg2 = %0, %arg3 = %arg0) : (tensor<i32>, tensor<10xi32>) -> (tensor<i32>, tensor<10xi32>) {737 %2 = tosa.greater_equal %arg2, %arg1 : (tensor<i32>, tensor<i32>) -> tensor<i1>738 tosa.yield %2 : tensor<i1>739 } do {740 ^bb0(%arg2: tensor<i32>, %arg3: tensor<i32>, %arg4: tensor<10xi32>):741 %2 = "tosa.const"() {values = dense<1> : tensor<i32>} : () -> tensor<i32>742 %3 = tosa.add %arg2, %2 : (tensor<i32>, tensor<i32>) -> tensor<i32>743 tosa.yield %3, %arg4 : tensor<i32>, tensor<10xi32>744 }745 return746}747 748// -----749 750func.func @test_while_loop_input_list_mismatch_body_block_in_2(%arg0: tensor<10xi32>, %arg1: tensor<i32>) {751 %0 = "tosa.const"() {values = dense<0> : tensor<i32>} : () -> tensor<i32>752 // expected-error@+1 {{'tosa.while_loop' op require same number of values in 'body_graph' arguments (2) and 'input_list' (3)}}753 %1:3 = tosa.while_loop (%arg2 = %0, %arg3 = %arg0, %arg4 = %arg0)754 : (tensor<i32>, tensor<10xi32>, tensor<10xi32>) -> (tensor<i32>, tensor<10xi32>, tensor<10xi32>) {755 %2 = tosa.greater_equal %arg2, %arg1 : (tensor<i32>, tensor<i32>) -> tensor<i1>756 tosa.yield %2 : tensor<i1>757 } do {758 ^bb0(%arg2: tensor<i32>, %arg3: tensor<i32>):759 %2 = "tosa.const"() {values = dense<1> : tensor<i32>} : () -> tensor<i32>760 %3 = tosa.add %arg2, %2 : (tensor<i32>, tensor<i32>) -> tensor<i32>761 tosa.yield %3, %arg3 : tensor<i32>, tensor<i32>762 }763 return764}765 766// -----767 768func.func @test_while_loop_input_list_mismatch_output_list(%arg0: tensor<10xi32>, %arg1: tensor<i32>) {769 %0 = "tosa.const"() {values = dense<0> : tensor<i32>} : () -> tensor<i32>770 // expected-error@+1 {{'tosa.while_loop' op require same number of values in 'input_list' (3) and 'output_list' (2)}}771 %1:2 = tosa.while_loop (%arg2 = %0, %arg3 = %arg0, %arg4 = %arg0)772 : (tensor<i32>, tensor<10xi32>, tensor<10xi32>) -> (tensor<i32>, tensor<10xi32>) {773 %2 = tosa.greater_equal %arg2, %arg1 : (tensor<i32>, tensor<i32>) -> tensor<i1>774 tosa.yield %2 : tensor<i1>775 } do {776 ^bb0(%arg2: tensor<i32>, %arg3: tensor<i32>):777 %2 = "tosa.const"() {values = dense<1> : tensor<i32>} : () -> tensor<i32>778 %3 = tosa.add %arg2, %2 : (tensor<i32>, tensor<i32>) -> tensor<i32>779 tosa.yield %3, %arg3 : tensor<i32>, tensor<i32>780 }781 return782}783 784// -----785 786func.func @test_while_loop_input_list_mismatch_output_list_2(%arg0: tensor<10xi32>, %arg1: tensor<i32>) {787 %0 = "tosa.const"() {values = dense<0> : tensor<i32>} : () -> tensor<i32>788 // expected-error@+1 {{'tosa.while_loop' op require same number of values in 'input_list' (2) and 'output_list' (3)}}789 %1:3 = tosa.while_loop (%arg2 = %0, %arg3 = %arg0)790 : (tensor<i32>, tensor<10xi32>) -> (tensor<i32>, tensor<10xi32>, tensor<10xi32>) {791 %2 = tosa.greater_equal %arg2, %arg1 : (tensor<i32>, tensor<i32>) -> tensor<i1>792 tosa.yield %2 : tensor<i1>793 } do {794 ^bb0(%arg2: tensor<i32>, %arg3: tensor<i32>):795 %2 = "tosa.const"() {values = dense<1> : tensor<i32>} : () -> tensor<i32>796 %3 = tosa.add %arg2, %2 : (tensor<i32>, tensor<i32>) -> tensor<i32>797 tosa.yield %3, %arg3 : tensor<i32>, tensor<i32>798 }799 return800}801 802// -----803 804func.func @test_while_loop_input_list_mismatch_cond_block(%arg0: tensor<2xf32>, %arg1: tensor<i32>) {805 %0 = "tosa.const"() {values = dense<0> : tensor<i32>} : () -> tensor<i32>806 // expected-error@+1 {{'tosa.while_loop' op require same number of values in 'cond_graph' arguments (3) and 'input_list' (2)}}807 %1:2 = "tosa.while_loop"(%0, %arg0) ({808 ^bb0(%arg3: tensor<i32>, %arg4: tensor<2xf32>, %arg5: tensor<2xf32>):809 %2 = "tosa.greater_equal"(%arg3, %arg1) : (tensor<i32>, tensor<i32>) -> tensor<i1>810 "tosa.yield"(%2) : (tensor<i1>) -> ()811 }, {812 ^bb0(%arg3: tensor<i32>, %arg4: tensor<2xf32>):813 %2 = "tosa.const"() {values = dense<1> : tensor<i32>} : () -> tensor<i32>814 %3 = "tosa.const"() {values = dense<2> : tensor<1xi8>} : () -> tensor<1xi8>815 %4 = "tosa.mul"(%arg3, %2, %3) : (tensor<i32>, tensor<i32>, tensor<1xi8>) -> tensor<i32>816 "tosa.yield"(%4, %arg4) : (tensor<i32>, tensor<2xf32>) -> ()817 }) : (tensor<i32>, tensor<2xf32>) -> (tensor<i32>, tensor<2xf32>)818 return819}820 821// -----822 823func.func @test_while_loop_input_list_mismatch_cond_block_2(%arg0: tensor<2xf32>, %arg1: tensor<i32>) {824 %0 = "tosa.const"() {values = dense<0> : tensor<i32>} : () -> tensor<i32>825 // expected-error@+1 {{'tosa.while_loop' op require same number of values in 'cond_graph' arguments (1) and 'input_list' (3)}}826 %1:3 = "tosa.while_loop"(%0, %arg0, %arg1) ({827 ^bb0(%arg3: tensor<i32>):828 %2 = "tosa.greater_equal"(%arg3, %arg1) : (tensor<i32>, tensor<i32>) -> tensor<i1>829 "tosa.yield"(%2) : (tensor<i1>) -> ()830 }, {831 ^bb0(%arg3: tensor<i32>, %arg4: tensor<2xf32>):832 %2 = "tosa.const"() {values = dense<1> : tensor<i32>} : () -> tensor<i32>833 %3 = "tosa.const"() {values = dense<2> : tensor<1xi8>} : () -> tensor<1xi8>834 %4 = "tosa.mul"(%arg3, %2, %3) : (tensor<i32>, tensor<i32>, tensor<1xi8>) -> tensor<i32>835 "tosa.yield"(%4, %arg4) : (tensor<i32>, tensor<2xf32>) -> ()836 }) : (tensor<i32>, tensor<2xf32>, tensor<i32>) -> (tensor<i32>, tensor<2xf32>, tensor<i32>)837 return838}839 840// -----841 842func.func @test_while_loop_input_list_mismatch_body_block_out(%arg0: tensor<10xi32>, %arg1: tensor<i32>) {843 %0 = "tosa.const"() {values = dense<0> : tensor<i32>} : () -> tensor<i32>844 // expected-error@+1 {{'tosa.while_loop' op require same number of values in 'body_graph' results (3) and 'input_list' (2)}}845 %1:2 = tosa.while_loop (%arg2 = %0, %arg3 = %arg0) : (tensor<i32>, tensor<10xi32>) -> (tensor<i32>, tensor<10xi32>) {846 %2 = tosa.greater_equal %arg2, %arg1 : (tensor<i32>, tensor<i32>) -> tensor<i1>847 tosa.yield %2 : tensor<i1>848 } do {849 ^bb0(%arg2: tensor<i32>, %arg4: tensor<10xi32>):850 %2 = "tosa.const"() {values = dense<1> : tensor<i32>} : () -> tensor<i32>851 %3 = tosa.add %arg2, %2 : (tensor<i32>, tensor<i32>) -> tensor<i32>852 tosa.yield %2, %3, %arg4 : tensor<i32>, tensor<i32>, tensor<10xi32>853 }854 return855}856 857// -----858 859func.func @test_while_loop_input_list_mismatch_body_block_out_2(%arg0: tensor<10xi32>, %arg1: tensor<i32>) {860 %0 = "tosa.const"() {values = dense<0> : tensor<i32>} : () -> tensor<i32>861 // expected-error@+1 {{'tosa.while_loop' op require same number of values in 'body_graph' results (1) and 'input_list' (2)}}862 %1:2 = tosa.while_loop (%arg2 = %0, %arg3 = %arg0) : (tensor<i32>, tensor<10xi32>) -> (tensor<i32>, tensor<10xi32>) {863 %2 = tosa.greater_equal %arg2, %arg1 : (tensor<i32>, tensor<i32>) -> tensor<i1>864 tosa.yield %2 : tensor<i1>865 } do {866 ^bb0(%arg2: tensor<i32>, %arg4: tensor<10xi32>):867 %2 = "tosa.const"() {values = dense<1> : tensor<i32>} : () -> tensor<i32>868 %3 = tosa.add %arg2, %2 : (tensor<i32>, tensor<i32>) -> tensor<i32>869 tosa.yield %3 : tensor<i32>870 }871 return872}873 874// -----875 876func.func @test_while_loop_type_mismatch(%arg0: tensor<10xi32>, %arg1: tensor<i32>) {877 %0 = "tosa.const"() {values = dense<0> : tensor<i32>} : () -> tensor<i32>878 // expected-error@+1 {{'tosa.while_loop' op require same element type for 'body_graph' arguments ('f32') and 'input_list' ('i32')}}879 %1:3 = tosa.while_loop (%arg2 = %0, %arg3 = %0, %arg4 = %arg0) : (tensor<i32>, tensor<i32>, tensor<10xi32>) -> (tensor<i32>, tensor<i32>, tensor<10xi32>) {880 %2 = tosa.greater_equal %arg3, %arg1 : (tensor<i32>, tensor<i32>) -> tensor<i1>881 %3 = tosa.logical_not %2 : (tensor<i1>) -> tensor<i1>882 tosa.yield %3 : tensor<i1>883 } do {884 ^bb0(%arg2: tensor<i32>, %arg3: tensor<f32>, %arg4: tensor<10xi32>):885 %2 = "tosa.const"() {values = dense<1> : tensor<i32>} : () -> tensor<i32>886 %6 = tosa.add %arg2, %2 : (tensor<i32>, tensor<i32>) -> tensor<i32>887 tosa.yield %6, %2, %arg4 : tensor<i32>, tensor<i32>, tensor<10xi32>888 }889 return890}891 892// -----893 894func.func @test_while_loop_type_mismatch_2(%arg0: tensor<10xi32>, %arg1: tensor<i32>) {895 %0 = "tosa.const"() {values = dense<0> : tensor<i32>} : () -> tensor<i32>896 // expected-error@+1 {{'tosa.while_loop' op require same shapes for 'body_graph' arguments ('tensor<10xi32>') and 'input_list' ('tensor<i32>')}}897 %1:3 = tosa.while_loop (%arg2 = %0, %arg3 = %0, %arg4 = %arg0) : (tensor<i32>, tensor<i32>, tensor<10xi32>) -> (tensor<i32>, tensor<i32>, tensor<10xi32>) {898 %2 = tosa.greater_equal %arg3, %arg1 : (tensor<i32>, tensor<i32>) -> tensor<i1>899 %3 = tosa.logical_not %2 : (tensor<i1>) -> tensor<i1>900 tosa.yield %3 : tensor<i1>901 } do {902 ^bb0(%arg2: tensor<10xi32>, %arg3: tensor<i32>, %arg4: tensor<10xi32>):903 %2 = "tosa.const"() {values = dense<1> : tensor<i32>} : () -> tensor<i32>904 %6 = tosa.add %arg2, %2 : (tensor<10xi32>, tensor<i32>) -> tensor<i32>905 tosa.yield %6, %2, %arg4 : tensor<i32>, tensor<i32>, tensor<10xi32>906 }907 return908}909 910// -----911 912func.func @test_while_loop_cond_output_not_size_one(%arg0: tensor<10xi32>, %arg1: tensor<2xi32>) {913 %0 = "tosa.const"() {values = dense<[4, 1]> : tensor<2xi32>} : () -> tensor<2xi32>914 // expected-error@+1 {{'tosa.while_loop' op 'cond_graph' result must be a size 1 tensor, got 'tensor<2xi1>'}}915 %1:3 = tosa.while_loop (%arg2 = %arg0, %arg3 = %0, %arg4 = %arg0) : (tensor<10xi32>, tensor<2xi32>, tensor<10xi32>) -> (tensor<10xi32>, tensor<2xi32>, tensor<10xi32>) {916 %2 = tosa.greater_equal %arg3, %arg1 : (tensor<2xi32>, tensor<2xi32>) -> tensor<2xi1>917 tosa.yield %2 : tensor<2xi1>918 } do {919 ^bb0(%arg2: tensor<10xi32>, %arg3: tensor<2xi32>, %arg4: tensor<10xi32>):920 %2 = "tosa.const"() {values = dense<1> : tensor<i32>} : () -> tensor<i32>921 %3 = "tosa.const"() {values = dense<[3, 5]> : tensor<2xi32>} : () -> tensor<2xi32>922 %4 = tosa.add %arg2, %2 : (tensor<10xi32>, tensor<i32>) -> tensor<10xi32>923 tosa.yield %4, %3, %arg4 : tensor<10xi32>, tensor<2xi32>, tensor<10xi32>924 }925 return926}927 928// -----929 930func.func @test_while_loop_cond_output_not_bool(%arg0: tensor<10xi32>, %arg1: tensor<i32>) {931 %0 = "tosa.const"() {values = dense<9> : tensor<i32>} : () -> tensor<i32>932 // expected-error@+1 {{'tosa.while_loop' op 'cond_graph' result must be a boolean tensor, got 'tensor<i32>'}}933 %1:3 = tosa.while_loop (%arg2 = %arg0, %arg3 = %0, %arg4 = %arg0) : (tensor<10xi32>, tensor<i32>, tensor<10xi32>) -> (tensor<10xi32>, tensor<i32>, tensor<10xi32>) {934 %2 = tosa.add %arg3, %arg1 : (tensor<i32>, tensor<i32>) -> tensor<i32>935 tosa.yield %2 : tensor<i32>936 } do {937 ^bb0(%arg2: tensor<10xi32>, %arg3: tensor<i32>, %arg4: tensor<10xi32>):938 %2 = "tosa.const"() {values = dense<1> : tensor<i32>} : () -> tensor<i32>939 %4 = tosa.add %arg2, %2 : (tensor<10xi32>, tensor<i32>) -> tensor<10xi32>940 tosa.yield %4, %2, %arg4 : tensor<10xi32>, tensor<i32>, tensor<10xi32>941 }942 return943}944 945// -----946 947module {948 // expected-note@below {{see existing symbol definition here}}949 tosa.variable @stored_var = dense<-1> : tensor<2x4x8xi32>950 // expected-error@+1 {{redefinition of symbol named 'stored_var'}}951 tosa.variable @stored_var = dense<-3> : tensor<2x4x8xi32>952}953 954// -----955 956module {957 // expected-error@+1 {{inferred shape of elements literal ([2]) does not match type ([3])}}958 tosa.variable @stored_var = dense<[3.14, 2.14]> : tensor<3xf32>959 // expected-error@+1 {{custom op 'tosa.variable' expected attribute}}960}961 962// -----963 964module {965 // expected-error@+1 {{expected integer elements, but parsed floating-point}}966 tosa.variable @stored_var = dense<-1.2> : tensor<2x4x8xi32>967 // expected-error@+1 {{custom op 'tosa.variable' expected attribute}}968}969 970// -----971 972func.func @test_variable_read_no_declaration() -> () {973 // expected-error@+1 {{'tosa.variable_read' op 'stored_var' has not been declared by 'tosa.variable'}}974 %0 = tosa.variable_read @stored_var : tensor<f32>975 return976}977 978// -----979 980module {981 tosa.variable @stored_var = dense<-1.2> : tensor<2x4x8xf32>982 983 func.func @test_variable_read_type_mismatch() -> () {984 // expected-error@+1 {{'tosa.variable_read' op require same element type for 'output1' ('i32') and the input tensor ('f32')}}985 %0 = tosa.variable_read @stored_var : tensor<2x4x8xi32>986 return987 }988}989 990// -----991 992module {993 tosa.variable @stored_var = dense<-1.2> : tensor<8x4x2xf32>994 995 func.func @test_variable_read_shape_mismatch() -> () {996 // expected-error@+1 {{'tosa.variable_read' op require same shapes for 'output1' ('tensor<2x4x8xf32>') and the input tensor ('tensor<8x4x2xf32>')}}997 %0 = tosa.variable_read @stored_var : tensor<2x4x8xf32>998 return999 }1000}1001 1002// -----1003 1004func.func @test_variable_write_no_declaration(%arg0: tensor<f32>) -> () {1005 // expected-error@+1 {{'tosa.variable_write' op 'stored_var' has not been declared by 'tosa.variable'}}1006 tosa.variable_write @stored_var, %arg0 : tensor<f32>1007 return1008}1009 1010// -----1011 1012module {1013 tosa.variable @stored_var = dense<-1.2> : tensor<2x4x8xf32>1014 1015 func.func @test_variable_write_type_mismatch(%arg0: tensor<2x4x8xi32>) -> () {1016 // expected-error@+1 {{'tosa.variable_write' op require same element type for 'input1' ('i32') and the input tensor ('f32')}}1017 tosa.variable_write @stored_var, %arg0 : tensor<2x4x8xi32>1018 return1019 }1020}1021 1022// -----1023 1024module {1025 tosa.variable @stored_var = dense<-1.2> : tensor<8x4x2xf32>1026 1027 func.func @test_variable_write_shape_mismatch(%arg0: tensor<2x4x8xf32>) -> () {1028 // expected-error@+1 {{'tosa.variable_write' op require same shapes for 'input1' ('tensor<2x4x8xf32>') and the input tensor ('tensor<8x4x2xf32>')}}1029 tosa.variable_write @stored_var, %arg0 : tensor<2x4x8xf32>1030 return1031 }1032}1033 1034// -----1035 1036func.func @scatter_invalid_indices_N(%arg0 : tensor<2x4x5xi32>, %arg1 : tensor<3x2xi32>, %arg2 : tensor<2x2x5xi32>) {1037 // expected-error@+1 {{'tosa.scatter' op requires indices dimension 0 to have size 2, got 3}}1038 %1 = tosa.scatter %arg0, %arg1, %arg2 : (tensor<2x4x5xi32>, tensor<3x2xi32>, tensor<2x2x5xi32>) -> tensor<2x4x5xi32>1039 return1040}1041 1042// -----1043 1044func.func @scatter_invalid_input_N(%arg0 : tensor<?x4x5xi32>, %arg1 : tensor<2x2xi32>, %arg2 : tensor<3x2x5xi32>) {1045 // expected-error@+1 {{'tosa.scatter' op requires input dimension 0 to have size 2, got 3}}1046 %2 = tosa.scatter %arg0, %arg1, %arg2 : (tensor<?x4x5xi32>, tensor<2x2xi32>, tensor<3x2x5xi32>) -> tensor<2x4x5xi32>1047 return1048}1049 1050// -----1051 1052func.func @scatter_invalid_out_N(%arg0 : tensor<?x4x5xi32>, %arg1 : tensor<?x2xi32>, %arg2 : tensor<2x2x5xi32>) {1053 // expected-error@+1 {{'tosa.scatter' op requires values_out dimension 0 to have size 2, got 3}}1054 %2 = tosa.scatter %arg0, %arg1, %arg2 : (tensor<?x4x5xi32>, tensor<?x2xi32>, tensor<2x2x5xi32>) -> tensor<3x4x5xi32>1055 return1056}1057 1058// -----1059 1060func.func @scatter_invalid_out_K(%arg0 : tensor<?x4x5xi32>, %arg1 : tensor<?x2xi32>, %arg2 : tensor<2x2x5xi32>) {1061 // expected-error@+1 {{'tosa.scatter' op requires values_out dimension 1 to have size 4, got 3}}1062 %2 = tosa.scatter %arg0, %arg1, %arg2 : (tensor<?x4x5xi32>, tensor<?x2xi32>, tensor<2x2x5xi32>) -> tensor<2x3x5xi32>1063 return1064}1065 1066// -----1067 1068func.func @scatter_invalid_input_W(%arg0 : tensor<?x4x5xi32>, %arg1 : tensor<?x2xi32>, %arg2 : tensor<2x3x5xi32>) {1069 // expected-error@+1 {{'tosa.scatter' op requires input dimension 1 to have size 2, got 3}}1070 %2 = tosa.scatter %arg0, %arg1, %arg2 : (tensor<?x4x5xi32>, tensor<?x2xi32>, tensor<2x3x5xi32>) -> tensor<2x4x5xi32>1071 return1072}1073 1074// -----1075 1076func.func @scatter_invalid_input_C(%arg0 : tensor<?x4x5xi32>, %arg1 : tensor<?x2xi32>, %arg2 : tensor<2x2x6xi32>) {1077 // expected-error@+1 {{'tosa.scatter' op requires input dimension 2 to have size 5, got 6}}1078 %2 = tosa.scatter %arg0, %arg1, %arg2 : (tensor<?x4x5xi32>, tensor<?x2xi32>, tensor<2x2x6xi32>) -> tensor<2x4x5xi32>1079 return1080}1081 1082// -----1083 1084func.func @scatter_invalid_out_C(%arg0 : tensor<?x4x5xi32>, %arg1 : tensor<?x2xi32>, %arg2 : tensor<2x2x5xi32>) {1085 // expected-error@+1 {{'tosa.scatter' op requires values_out dimension 2 to have size 5, got 6}}1086 %2 = tosa.scatter %arg0, %arg1, %arg2 : (tensor<?x4x5xi32>, tensor<?x2xi32>, tensor<2x2x5xi32>) -> tensor<2x4x6xi32>1087 return1088}1089 1090// -----1091 1092func.func @scatter_invalid_K_W(%arg0 : tensor<2x4x5xi32>, %arg1 : tensor<2x6xi32>, %arg2 : tensor<2x6x5xi32>) {1093 // expected-error@+1 {{'tosa.scatter' op requires dimensions K >= W, got K=4 and W=6}}1094 %2 = tosa.scatter %arg0, %arg1, %arg2 : (tensor<2x4x5xi32>, tensor<2x6xi32>, tensor<2x6x5xi32>) -> tensor<2x4x5xi32>1095 return1096}1097 1098// -----1099 1100func.func @test_matmul_t_block_scaled_data_mismatch(%arg0: tensor<4x8x32xf8E4M3FN>, %arg1: tensor<4x8x1xf8E8M0FNU>, %arg2: tensor<4x16x32xf8E5M2>, %arg3: tensor<4x16x1xf8E8M0FNU>) -> tensor<4x8x16xf32> {1101 // expected-error@+1 {{'tosa.matmul_t_block_scaled' op expect A_data and B_data to have same element type, got 'f8E4M3FN' and 'f8E5M2'}}1102 %0 = tosa.matmul_t_block_scaled %arg0, %arg1, %arg2, %arg3 {block_size = #tosa.block_size<BLOCK_SIZE_32> : i32} : (tensor<4x8x32xf8E4M3FN>, tensor<4x8x1xf8E8M0FNU>, tensor<4x16x32xf8E5M2>, tensor<4x16x1xf8E8M0FNU>) -> tensor<4x8x16xf32>1103 return %0 : tensor<4x8x16xf32>1104}1105 1106// -----1107 1108func.func @test_matmul_t_block_scaled_output_batch_mismatch(%arg0: tensor<*xf8E4M3FN>, %arg1: tensor<?x8x1xf8E8M0FNU>, %arg2: tensor<*xf8E4M3FN>, %arg3: tensor<4x?x?xf8E8M0FNU>) -> tensor<5x?x?xf32> {1109 // expected-error@+1 {{'tosa.matmul_t_block_scaled' op expected output shape 5, ?, ? to be compatible with expected output shape 4, 8, ?}}1110 %0 = tosa.matmul_t_block_scaled %arg0, %arg1, %arg2, %arg3 {block_size = #tosa.block_size<BLOCK_SIZE_32> : i32} : (tensor<*xf8E4M3FN>, tensor<?x8x1xf8E8M0FNU>, tensor<*xf8E4M3FN>, tensor<4x?x?xf8E8M0FNU>) -> tensor<5x?x?xf32>1111 return %0 : tensor<5x?x?xf32>1112}1113 1114// -----1115 1116func.func @test_matmul_t_block_scaled_output_height_mismatch(%arg0: tensor<*xf8E4M3FN>, %arg1: tensor<?x9x1xf8E8M0FNU>, %arg2: tensor<*xf8E4M3FN>, %arg3: tensor<4x?x?xf8E8M0FNU>) -> tensor<4x8x?xf32> {1117 // expected-error@+1 {{'tosa.matmul_t_block_scaled' op expected output shape 4, 8, ? to be compatible with expected output shape 4, 9, ?}}1118 %0 = tosa.matmul_t_block_scaled %arg0, %arg1, %arg2, %arg3 {block_size = #tosa.block_size<BLOCK_SIZE_32> : i32} : (tensor<*xf8E4M3FN>, tensor<?x9x1xf8E8M0FNU>, tensor<*xf8E4M3FN>, tensor<4x?x?xf8E8M0FNU>) -> tensor<4x8x?xf32>1119 return %0 : tensor<4x8x?xf32>1120}1121 1122// -----1123 1124func.func @test_matmul_t_block_scaled_output_width_mismatch(%arg0: tensor<*xf8E4M3FN>, %arg1: tensor<?x?x1xf8E8M0FNU>, %arg2: tensor<?x1x?xf8E4M3FN>, %arg3: tensor<*xf8E8M0FNU>) -> tensor<?x?x10xf32> {1125 // expected-error@+1 {{'tosa.matmul_t_block_scaled' op expected output shape ?, ?, 10 to be compatible with expected output shape ?, ?, 1}}1126 %0 = tosa.matmul_t_block_scaled %arg0, %arg1, %arg2, %arg3 {block_size = #tosa.block_size<BLOCK_SIZE_32> : i32} : (tensor<*xf8E4M3FN>, tensor<?x?x1xf8E8M0FNU>, tensor<?x1x?xf8E4M3FN>, tensor<*xf8E8M0FNU>) -> tensor<?x?x10xf32>1127 return %0 : tensor<?x?x10xf32>1128}1129 1130// -----1131 1132func.func @test_matmul_t_block_scaled_channel_not_multiple_of_block_size(%arg0: tensor<4x8x55xf8E4M3FN>, %arg1: tensor<4x8x1xf8E8M0FNU>, %arg2: tensor<4x16x32xf8E4M3FN>, %arg3: tensor<4x16x1xf8E8M0FNU>) -> tensor<4x8x16xf32> {1133 // expected-error@+1 {{'tosa.matmul_t_block_scaled' op expected channels of b_data to match size 55, got 32}}1134 %0 = tosa.matmul_t_block_scaled %arg0, %arg1, %arg2, %arg3 {block_size = #tosa.block_size<BLOCK_SIZE_32> : i32} : (tensor<4x8x55xf8E4M3FN>, tensor<4x8x1xf8E8M0FNU>, tensor<4x16x32xf8E4M3FN>, tensor<4x16x1xf8E8M0FNU>) -> tensor<4x8x16xf32>1135 return %0 : tensor<4x8x16xf32>1136}1137 1138// -----1139 1140func.func @test_matmul_t_block_scaled_batch_mismatch(%arg0: tensor<4x8x32xf8E4M3FN>, %arg1: tensor<4x8x1xf8E8M0FNU>, %arg2: tensor<2x16x32xf8E4M3FN>, %arg3: tensor<2x16x1xf8E8M0FNU>) -> tensor<4x8x16xf32> {1141 // expected-error@+1 {{'tosa.matmul_t_block_scaled' op expect B matrix batch size to be broadcast compatible with A, got D=2 vs N=4}}1142 %0 = tosa.matmul_t_block_scaled %arg0, %arg1, %arg2, %arg3 {block_size = #tosa.block_size<BLOCK_SIZE_32> : i32} : (tensor<4x8x32xf8E4M3FN>, tensor<4x8x1xf8E8M0FNU>, tensor<2x16x32xf8E4M3FN>, tensor<2x16x1xf8E8M0FNU>) -> tensor<4x8x16xf32>1143 return %0 : tensor<4x8x16xf32>1144}1145 1146// -----1147 1148func.func @cast_from_block_scaled_incompatible_input_output_shape(%arg0: tensor<4x32xf4E2M1FN>, %arg1: tensor<4x1xf8E8M0FNU>) -> tensor<5x32xf32> {1149 // expected-error@+1 {{'tosa.cast_from_block_scaled' op require compatible shapes for input_data ('tensor<4x32xf4E2M1FN>') and output_data ('tensor<5x32xf32>')}}1150 %0 = tosa.cast_from_block_scaled %arg0, %arg1 {block_size = #tosa.block_size<BLOCK_SIZE_32> : i32} : (tensor<4x32xf4E2M1FN>, tensor<4x1xf8E8M0FNU>) -> tensor<5x32xf32>1151 return %0 : tensor<5x32xf32>1152}1153 1154// -----1155 1156func.func @cast_from_block_scaled_not_scalar(%arg0: tensor<f4E2M1FN>, %arg1: tensor<f8E8M0FNU>) -> tensor<f32> {1157 // expected-error@+1 {{'tosa.cast_from_block_scaled' op operand #0 must be tosa-conformant tensor of at least rank 1, but got 'tensor<f4E2M1FN>'}}1158 %0 = tosa.cast_from_block_scaled %arg0, %arg1 {block_size = #tosa.block_size<BLOCK_SIZE_32> : i32} : (tensor<f4E2M1FN>, tensor<f8E8M0FNU>) -> tensor<f32>1159 return %0 : tensor<f32>1160}1161 1162// -----1163 1164func.func @cast_from_block_scaled_not_divisible_by_block_size(%arg0: tensor<4x33xf4E2M1FN>, %arg1: tensor<4x1xf8E8M0FNU>) -> tensor<4x33xf32> {1165 // expected-error@+1 {{'tosa.cast_from_block_scaled' op expect last dimension of input_data (33) to be divisible by block_size (32)}}1166 %0 = tosa.cast_from_block_scaled %arg0, %arg1 {block_size = #tosa.block_size<BLOCK_SIZE_32> : i32} : (tensor<4x33xf4E2M1FN>, tensor<4x1xf8E8M0FNU>) -> tensor<4x33xf32>1167 return %0 : tensor<4x33xf32>1168}1169 1170// -----1171 1172func.func @cast_from_block_scaled_data_scale_mismatch(%arg0: tensor<4x32xf4E2M1FN>, %arg1: tensor<5x1xf8E8M0FNU>) -> tensor<4x32xf32> {1173 // expected-error@+1 {{'tosa.cast_from_block_scaled' op require compatible shapes for input_data ('tensor<4x32xf4E2M1FN>') and input_scale ('tensor<5x1xf8E8M0FNU>') except for the last dimension}}1174 %0 = tosa.cast_from_block_scaled %arg0, %arg1 {block_size = #tosa.block_size<BLOCK_SIZE_32> : i32} : (tensor<4x32xf4E2M1FN>, tensor<5x1xf8E8M0FNU>) -> tensor<4x32xf32>1175 return %0 : tensor<4x32xf32>1176}1177 1178// -----1179 1180func.func @cast_from_block_scaled_data_scale_channel_mismatch(%arg0: tensor<4x32xf4E2M1FN>, %arg1: tensor<4x2xf8E8M0FNU>) -> tensor<4x32xf32> {1181 // expected-error@+1 {{'tosa.cast_from_block_scaled' op expect last dimension of input_scale (2) to be equal to last dimension of input_data / block_size (1)}}1182 %0 = tosa.cast_from_block_scaled %arg0, %arg1 {block_size = #tosa.block_size<BLOCK_SIZE_32>} : (tensor<4x32xf4E2M1FN>, tensor<4x2xf8E8M0FNU>) -> tensor<4x32xf32>1183 return %0 : tensor<4x32xf32>1184}1185 1186// -----1187 1188func.func @test_cast_to_block_scaled_incompatible_input_output_shape(%arg0: tensor<4x32xf32>) -> (tensor<5x32xf4E2M1FN>, tensor<4x1xf8E8M0FNU>) {1189 // expected-error@+1 {{'tosa.cast_to_block_scaled' op require compatible shapes for input_data ('tensor<4x32xf32>') and output_data ('tensor<5x32xf4E2M1FN>')}}1190 %0:2 = tosa.cast_to_block_scaled %arg0 {block_size = #tosa.block_size<BLOCK_SIZE_32>} : (tensor<4x32xf32>) -> (tensor<5x32xf4E2M1FN>, tensor<4x1xf8E8M0FNU>)1191 return %0#0, %0#1 : tensor<5x32xf4E2M1FN>, tensor<4x1xf8E8M0FNU>1192}1193 1194// -----1195 1196func.func @test_cast_to_block_scaled_not_scalar(%arg0: tensor<f32>) -> (tensor<f4E2M1FN>, tensor<f8E8M0FNU>) {1197 // expected-error@+1 {{'tosa.cast_to_block_scaled' op operand #0 must be tosa-conformant tensor of at least rank 1, but got 'tensor<f32>'}}1198 %0:2 = tosa.cast_to_block_scaled %arg0 {block_size = #tosa.block_size<BLOCK_SIZE_32>} : (tensor<f32>) -> (tensor<f4E2M1FN>, tensor<f8E8M0FNU>)1199 return %0#0, %0#1 : tensor<f4E2M1FN>, tensor<f8E8M0FNU>1200}1201 1202// -----1203 1204func.func @test_cast_to_block_scaled_not_divisible_by_block_size(%arg0: tensor<4x33xf32>) -> (tensor<4x33xf4E2M1FN>, tensor<4x1xf8E8M0FNU>) {1205 // expected-error@+1 {{'tosa.cast_to_block_scaled' op expect last dimension of input_data (33) to be divisible by block_size (32)}}1206 %0:2 = tosa.cast_to_block_scaled %arg0 {block_size = #tosa.block_size<BLOCK_SIZE_32>} : (tensor<4x33xf32>) -> (tensor<4x33xf4E2M1FN>, tensor<4x1xf8E8M0FNU>)1207 return %0#0, %0#1 : tensor<4x33xf4E2M1FN>, tensor<4x1xf8E8M0FNU>1208}1209 1210// -----1211 1212func.func @test_cast_to_block_scaled_data_scale_mismatch(%arg0: tensor<4x32xf32>) -> (tensor<4x32xf4E2M1FN>, tensor<5x1xf8E8M0FNU>) {1213 // expected-error@+1 {{'tosa.cast_to_block_scaled' op require compatible shapes for output_data ('tensor<4x32xf4E2M1FN>') and output_scale ('tensor<5x1xf8E8M0FNU>') except for the last dimension}}1214 %0:2 = tosa.cast_to_block_scaled %arg0 {block_size = #tosa.block_size<BLOCK_SIZE_32>} : (tensor<4x32xf32>) -> (tensor<4x32xf4E2M1FN>, tensor<5x1xf8E8M0FNU>)1215 return %0#0, %0#1 : tensor<4x32xf4E2M1FN>, tensor<5x1xf8E8M0FNU>1216}1217 1218// -----1219 1220func.func @test_cast_to_block_scaled_data_scale_channel_mismatch(%arg0: tensor<4x32xf32>) -> (tensor<4x32xf4E2M1FN>, tensor<4x2xf8E8M0FNU>) {1221 // expected-error@+1 {{'tosa.cast_to_block_scaled' op expect last dimension of output_scale (2) to be equal to last dimension of output_data / block_size (1)}}1222 %0:2 = tosa.cast_to_block_scaled %arg0 {block_size = #tosa.block_size<BLOCK_SIZE_32>} : (tensor<4x32xf32>) -> (tensor<4x32xf4E2M1FN>, tensor<4x2xf8E8M0FNU>)1223 return %0#0, %0#1 : tensor<4x32xf4E2M1FN>, tensor<4x2xf8E8M0FNU>1224}1225 1226// -----1227 1228func.func @test_clamp_quantized(%arg0:tensor<?x112x112x32x!quant.uniform<u8:f32, 0.023529412224888802:-128>>) -> (tensor<?x112x112x32x!quant.uniform<u8:f32, 0.023529412224888802:-128>>) {1229 // expected-error@+1 {{'tosa.clamp' op min/max attributes types are incompatible with input/output element types.}}1230 %0 = tosa.clamp %arg0 {max_val = 127 : i8, min_val = -128 : i8} : (tensor<?x112x112x32x!quant.uniform<u8:f32, 0.023529412224888802:-128>>) -> tensor<?x112x112x32x!quant.uniform<u8:f32, 0.023529412224888802:-128>>1231 return %0 : tensor<?x112x112x32x!quant.uniform<u8:f32, 0.023529412224888802:-128>>1232}1233