[Mlir-commits] [mlir] [mlir][tosa] Add error if checks Variable Operators (PR #137291)
Luke Hutton
llvmlistbot at llvm.org
Mon Apr 28 06:38:18 PDT 2025
================
@@ -403,3 +403,93 @@ func.func @test_gather_invalid_out_C(%arg0: tensor<13x21x3xf32>, %arg1: tensor<1
%0 = tosa.gather %arg0, %arg1 : (tensor<13x21x3xf32>, tensor<13x26xi32>) -> tensor<13x26x8xf32>
return %0 : tensor<13x26x8xf32>
}
+
+// -----
+
+func.func @test_variable_shape_mismatch() -> () {
+ // expected-error at +1 {{inferred shape of elements literal ([2]) does not match type ([3])}}
+ tosa.variable @stored_var = dense<[3.14, 2.14]> : tensor<3xf32>
+ // expected-error at +1 {{custom op 'tosa.variable' expected attribute}}
+ return
+}
+
+// -----
+
+func.func @test_variable_type_mismatch() -> () {
+ // expected-error at +1 {{expected integer elements, but parsed floating-point}}
+ tosa.variable @stored_var = dense<-1.2> : tensor<2x4x8xi32>
+ // expected-error at +1 {{custom op 'tosa.variable' expected attribute}}
+ return
+}
+
+// -----
+
+func.func @test_variable_read_no_declaration() -> () {
+ // expected-error at +1 {{'tosa.variable_read' op 'stored_var' has not been declared by 'tosa.variable'}}
+ %0 = tosa.variable_read @stored_var : tensor<f32>
+ return
+}
+
+// -----
+
+func.func @test_variable_read_multiple_declaration() -> () {
+ tosa.variable @stored_var = dense<-1> : tensor<2x4x8xi32>
+ tosa.variable @stored_var = dense<-1> : tensor<2x4x8xi32>
+ // expected-error at +1 {{'tosa.variable_read' op illegal to have multiple declaration of 'stored_var'}}
+ %0 = tosa.variable_read @stored_var : tensor<2x4x8xi32>
+ return
+}
+
+// -----
+
+func.func @test_variable_read_type_mismatch() -> () {
+ tosa.variable @stored_var = dense<-1.2> : tensor<2x4x8xf32>
+ // expected-error at +1 {{'tosa.variable_read' op require same element type for 'output1' ('i32') and the input tensor ('f32')}}
+ %0 = tosa.variable_read @stored_var : tensor<2x4x8xi32>
+ return
+}
+
+// -----
+
+func.func @test_variable_read_shape_mismatch() -> () {
+ tosa.variable @stored_var = dense<-1.2> : tensor<8x4x2xf32>
+ // expected-error at +1 {{'tosa.variable_read' op require same shapes for 'output1' ('tensor<2x4x8xf32>') and the input tensor ('tensor<8x4x2xf32>')}}
+ %0 = tosa.variable_read @stored_var : tensor<2x4x8xf32>
+ return
+}
+
+// -----
+
+func.func @test_variable_write_no_declaration(%arg0: tensor<f32>) -> () {
+ // expected-error at +1 {{'tosa.variable_write' op 'stored_var' has not been declared by 'tosa.variable'}}
+ tosa.variable_write @stored_var, %arg0 : tensor<f32>
+ return
+}
+
+// -----
+
+func.func @test_variable_write_multiple_declaration(%arg0: tensor<2x4x8xi32>) -> () {
+ tosa.variable @stored_var = dense<-1> : tensor<2x4x8xi32>
+ tosa.variable @stored_var = dense<-1> : tensor<2x4x8xi32>
+ // expected-error at +1 {{'tosa.variable_write' op illegal to have multiple declaration of 'stored_var'}}
----------------
lhutton1 wrote:
could this check be enforced on the creation of the variable op itself?
https://github.com/llvm/llvm-project/pull/137291
More information about the Mlir-commits
mailing list