@@ -129,3 +129,99 @@ func.func @test_i8_table_size(%arg0: tensor<2x64xi8>, %arg1: tensor<513xi8>) ->
129129 %0 = tosa.table %arg0 , %arg1 : (tensor <2 x64 xi8 >, tensor <513 xi8 >) -> tensor <2 x64 xi8 >
130130 return %0 : tensor <2 x64 xi8 >
131131}
132+
133+ // -----
134+ // CHECK-LABEL: test_error_scale32_with_i48
135+ func.func @test_error_scale32_with_i48 (%arg0: tensor <1 xi48 >) -> tensor <1 xi8 > {
136+ %multiplier = " tosa.const" () {values = dense <19689 > : tensor <1 xi32 > } : () -> tensor <1 xi32 >
137+ %shift = " tosa.const" () {values = dense <30 > : tensor <1 xi8 > } : () -> tensor <1 xi8 >
138+ %input_zp = " tosa.const" () {values = dense <0 > : tensor <1 xi48 >} : () -> tensor <1 xi48 >
139+ %output_zp = " tosa.const" () {values = dense <0 > : tensor <1 xi8 >} : () -> tensor <1 xi8 >
140+ // expected-error@+1 {{'tosa.rescale' op scale32 is not allowed with 48-bit input}}
141+ %0 = tosa.rescale %arg0 , %multiplier , %shift , %input_zp , %output_zp {scale32 = true , rounding_mode = " SINGLE_ROUND" , per_channel = false , input_unsigned = false , output_unsigned = false } : (tensor <1 xi48 >, tensor <1 xi32 >, tensor <1 xi8 >, tensor <1 xi48 >, tensor <1 xi8 >) -> tensor <1 xi8 >
142+ return %0 : tensor <1 xi8 >
143+ }
144+
145+ // -----
146+ // CHECK-LABEL: test_error_input_output_unsigned
147+ func.func @test_error_input_output_unsigned (%arg0: tensor <1 xi8 >) -> tensor <1 xi16 > {
148+ %multiplier = " tosa.const" () {values = dense <19689 > : tensor <1 xi16 > } : () -> tensor <1 xi16 >
149+ %shift = " tosa.const" () {values = dense <30 > : tensor <1 xi8 > } : () -> tensor <1 xi8 >
150+ %input_zp = " tosa.const" () {values = dense <0 > : tensor <1 xi8 >} : () -> tensor <1 xi8 >
151+ %output_zp = " tosa.const" () {values = dense <0 > : tensor <1 xi16 >} : () -> tensor <1 xi16 >
152+ // expected-error@+1 {{'tosa.rescale' op input and output cannot be both unsigned}}
153+ %0 = tosa.rescale %arg0 , %multiplier , %shift , %input_zp , %output_zp {scale32 = false , rounding_mode = " SINGLE_ROUND" , per_channel = false , input_unsigned = true , output_unsigned = true } : (tensor <1 xi8 >, tensor <1 xi16 >, tensor <1 xi8 >, tensor <1 xi8 >, tensor <1 xi16 >) -> tensor <1 xi16 >
154+ return %0 : tensor <1 xi16 >
155+ }
156+
157+ // -----
158+ // CHECK-LABEL: test_error_i32_output_unsigned_input
159+ func.func @test_error_i32_output_unsigned_input (%arg0: tensor <1 xi8 >) -> tensor <1 xi32 > {
160+ %multiplier = " tosa.const" () {values = dense <19689 > : tensor <1 xi16 > } : () -> tensor <1 xi16 >
161+ %shift = " tosa.const" () {values = dense <30 > : tensor <1 xi8 > } : () -> tensor <1 xi8 >
162+ %input_zp = " tosa.const" () {values = dense <0 > : tensor <1 xi8 >} : () -> tensor <1 xi8 >
163+ %output_zp = " tosa.const" () {values = dense <0 > : tensor <1 xi32 >} : () -> tensor <1 xi32 >
164+ // expected-error@+1 {{'tosa.rescale' op i32 output type is not allowed with unsigned input}}
165+ %0 = tosa.rescale %arg0 , %multiplier , %shift , %input_zp , %output_zp {scale32 = false , rounding_mode = " SINGLE_ROUND" , per_channel = false , input_unsigned = true , output_unsigned = false } : (tensor <1 xi8 >, tensor <1 xi16 >, tensor <1 xi8 >, tensor <1 xi8 >, tensor <1 xi32 >) -> tensor <1 xi32 >
166+ return %0 : tensor <1 xi32 >
167+ }
168+
169+ // -----
170+ // CHECK-LABEL: test_error_i32_input_unsigned_output
171+ func.func @test_error_i32_input_unsigned_output (%arg0: tensor <1 xi32 >) -> tensor <1 xi8 > {
172+ %multiplier = " tosa.const" () {values = dense <19689 > : tensor <1 xi16 > } : () -> tensor <1 xi16 >
173+ %shift = " tosa.const" () {values = dense <30 > : tensor <1 xi8 > } : () -> tensor <1 xi8 >
174+ %input_zp = " tosa.const" () {values = dense <0 > : tensor <1 xi32 >} : () -> tensor <1 xi32 >
175+ %output_zp = " tosa.const" () {values = dense <0 > : tensor <1 xi8 >} : () -> tensor <1 xi8 >
176+ // expected-error@+1 {{'tosa.rescale' op i32 input type is not allowed with unsigned output}}
177+ %0 = tosa.rescale %arg0 , %multiplier , %shift , %input_zp , %output_zp {scale32 = false , rounding_mode = " SINGLE_ROUND" , per_channel = false , input_unsigned = false , output_unsigned = true } : (tensor <1 xi32 >, tensor <1 xi16 >, tensor <1 xi8 >, tensor <1 xi32 >, tensor <1 xi8 >) -> tensor <1 xi8 >
178+ return %0 : tensor <1 xi8 >
179+ }
180+
181+ // -----
182+ // CHECK-LABEL: test_error_i48_input_unsigned_output
183+ func.func @test_error_i48_input_unsigned_output (%arg0: tensor <1 xi48 >) -> tensor <1 xi8 > {
184+ %multiplier = " tosa.const" () {values = dense <19689 > : tensor <1 xi16 > } : () -> tensor <1 xi16 >
185+ %shift = " tosa.const" () {values = dense <30 > : tensor <1 xi8 > } : () -> tensor <1 xi8 >
186+ %input_zp = " tosa.const" () {values = dense <0 > : tensor <1 xi48 >} : () -> tensor <1 xi48 >
187+ %output_zp = " tosa.const" () {values = dense <0 > : tensor <1 xi8 >} : () -> tensor <1 xi8 >
188+ // expected-error@+1 {{'tosa.rescale' op i48 input type is not allowed with unsigned output}}
189+ %0 = tosa.rescale %arg0 , %multiplier , %shift , %input_zp , %output_zp {scale32 = false , rounding_mode = " SINGLE_ROUND" , per_channel = false , input_unsigned = false , output_unsigned = true } : (tensor <1 xi48 >, tensor <1 xi16 >, tensor <1 xi8 >, tensor <1 xi48 >, tensor <1 xi8 >) -> tensor <1 xi8 >
190+ return %0 : tensor <1 xi8 >
191+ }
192+
193+ // -----
194+ // CHECK-LABEL: test_error_i48_unsigned_input
195+ func.func @test_error_i48_input_unsigned_output (%arg0: tensor <1 xi48 >) -> tensor <1 xi8 > {
196+ %multiplier = " tosa.const" () {values = dense <19689 > : tensor <1 xi16 > } : () -> tensor <1 xi16 >
197+ %shift = " tosa.const" () {values = dense <30 > : tensor <1 xi8 > } : () -> tensor <1 xi8 >
198+ %input_zp = " tosa.const" () {values = dense <0 > : tensor <1 xi48 >} : () -> tensor <1 xi48 >
199+ %output_zp = " tosa.const" () {values = dense <0 > : tensor <1 xi8 >} : () -> tensor <1 xi8 >
200+ // expected-error@+1 {{'tosa.rescale' op i48 input type cannot be unsigned}}
201+ %0 = tosa.rescale %arg0 , %multiplier , %shift , %input_zp , %output_zp {scale32 = false , rounding_mode = " SINGLE_ROUND" , per_channel = false , input_unsigned = true , output_unsigned = false } : (tensor <1 xi48 >, tensor <1 xi16 >, tensor <1 xi8 >, tensor <1 xi48 >, tensor <1 xi8 >) -> tensor <1 xi8 >
202+ return %0 : tensor <1 xi8 >
203+ }
204+
205+ // -----
206+ // CHECK-LABEL: test_error_i32_unsigned_input
207+ func.func @test_error_i32_input_unsigned_output (%arg0: tensor <1 xi32 >) -> tensor <1 xi8 > {
208+ %multiplier = " tosa.const" () {values = dense <19689 > : tensor <1 xi16 > } : () -> tensor <1 xi16 >
209+ %shift = " tosa.const" () {values = dense <30 > : tensor <1 xi8 > } : () -> tensor <1 xi8 >
210+ %input_zp = " tosa.const" () {values = dense <0 > : tensor <1 xi32 >} : () -> tensor <1 xi32 >
211+ %output_zp = " tosa.const" () {values = dense <0 > : tensor <1 xi8 >} : () -> tensor <1 xi8 >
212+ // expected-error@+1 {{'tosa.rescale' op i32 input type cannot be unsigned}}
213+ %0 = tosa.rescale %arg0 , %multiplier , %shift , %input_zp , %output_zp {scale32 = false , rounding_mode = " SINGLE_ROUND" , per_channel = false , input_unsigned = true , output_unsigned = false } : (tensor <1 xi32 >, tensor <1 xi16 >, tensor <1 xi8 >, tensor <1 xi32 >, tensor <1 xi8 >) -> tensor <1 xi8 >
214+ return %0 : tensor <1 xi8 >
215+ }
216+
217+ // -----
218+ // CHECK-LABEL: test_error_i32_unsigned_output
219+ func.func @test_error_i32_unsigned_output (%arg0: tensor <1 xi8 >) -> tensor <1 xi32 > {
220+ %multiplier = " tosa.const" () {values = dense <19689 > : tensor <1 xi16 > } : () -> tensor <1 xi16 >
221+ %shift = " tosa.const" () {values = dense <30 > : tensor <1 xi8 > } : () -> tensor <1 xi8 >
222+ %input_zp = " tosa.const" () {values = dense <0 > : tensor <1 xi8 >} : () -> tensor <1 xi8 >
223+ %output_zp = " tosa.const" () {values = dense <0 > : tensor <1 xi32 >} : () -> tensor <1 xi32 >
224+ // expected-error@+1 {{'tosa.rescale' op i32 output type cannot be unsigned}}
225+ %0 = tosa.rescale %arg0 , %multiplier , %shift , %input_zp , %output_zp {scale32 = false , rounding_mode = " SINGLE_ROUND" , per_channel = false , input_unsigned = false , output_unsigned = true } : (tensor <1 xi8 >, tensor <1 xi16 >, tensor <1 xi8 >, tensor <1 xi8 >, tensor <1 xi32 >) -> tensor <1 xi32 >
226+ return %0 : tensor <1 xi32 >
227+ }
0 commit comments