Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions mlir/lib/Dialect/Tosa/Transforms/TosaValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1257,17 +1257,17 @@ bool checkErrorIfCondIf(Operation *op) {
// tosa.yield %arg4
// }

return failed(checkIsolatedRegion(op, ifOp.getThenGraph(), "then")) ||
failed(checkIsolatedRegion(op, ifOp.getElseGraph(), "else"));
return succeeded(checkIsolatedRegion(op, ifOp.getThenGraph(), "then")) &&
succeeded(checkIsolatedRegion(op, ifOp.getElseGraph(), "else"));
}

bool checkErrorIfWhileLoop(Operation *op) {
auto whileOp = dyn_cast<tosa::WhileOp>(op);
if (!whileOp)
return true;

return failed(checkIsolatedRegion(op, whileOp.getCondGraph(), "cond")) ||
failed(checkIsolatedRegion(op, whileOp.getBodyGraph(), "body"));
return succeeded(checkIsolatedRegion(op, whileOp.getCondGraph(), "cond")) &&
succeeded(checkIsolatedRegion(op, whileOp.getBodyGraph(), "body"));
}

bool checkErrorIfScatter(Operation *op) {
Expand Down
33 changes: 0 additions & 33 deletions mlir/test/Dialect/Tosa/error_if_check.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -269,20 +269,6 @@ func.func @test_cond_if_simplified_form_not_isolated_from_above(%arg0: tensor<f3

// -----

// Check isolated cond_if's are valid
func.func @test_cond_if_isolated_from_above(%arg0: tensor<f32>, %arg1: tensor<f32>, %arg2: tensor<i1>) -> tensor<f32> {
%0 = "tosa.cond_if"(%arg2, %arg0, %arg1) ({
^bb0(%arg3: tensor<f32>, %arg4: tensor<f32>):
tosa.yield %arg3 : tensor<f32>
}, {
^bb0(%arg3: tensor<f32>, %arg4: tensor<f32>):
tosa.yield %arg4 : tensor<f32>
}) : (tensor<i1>, tensor<f32>, tensor<f32>) -> tensor<f32>
return %0 : tensor<f32>
}

// -----

func.func @test_while_loop_cond_not_isolated_from_above(%arg0: tensor<i32>, %arg1: tensor<i32>, %arg2: tensor<f32>) {
%0 = "tosa.const"() {values = dense<0> : tensor<i32>} : () -> tensor<i32>
// expected-error@+1 {{'tosa.while_loop' op is not conformant to the TOSA specification. It requires the 'cond' region is isolated from above.}}
Expand Down Expand Up @@ -318,22 +304,3 @@ func.func @test_while_loop_body_not_isolated_from_above(%arg0: tensor<i32>, %arg
}) : (tensor<i32>) -> (tensor<i32>)
return
}

// -----

// Check isolated while_loops are valid
func.func @test_while_loop_isolated_from_above(%arg0: tensor<f32>, %arg1: tensor<i32>) {
%0 = "tosa.const"() {values = dense<0> : tensor<i32>} : () -> tensor<i32>
%1:3 = "tosa.while_loop"(%0, %arg0, %arg1) ({
^bb0(%arg3: tensor<i32>, %arg4: tensor<f32>, %arg5: tensor<i32>):
%2 = "tosa.greater_equal"(%arg3, %arg5) : (tensor<i32>, tensor<i32>) -> tensor<i1>
%3 = "tosa.logical_not"(%2) : (tensor<i1>) -> tensor<i1>
"tosa.yield"(%3) : (tensor<i1>) -> ()
}, {
^bb0(%arg3: tensor<i32>, %arg4: tensor<f32>, %arg5: tensor<i32>):
%2 = "tosa.const"() {values = dense<1> : tensor<i32>} : () -> tensor<i32>
%3 = "tosa.add"(%arg3, %2) : (tensor<i32>, tensor<i32>) -> tensor<i32>
"tosa.yield"(%3, %arg4, %arg5) : (tensor<i32>, tensor<f32>, tensor<i32>) -> ()
}) : (tensor<i32>, tensor<f32>, tensor<i32>) -> (tensor<i32>, tensor<f32>, tensor<i32>)
return
}
34 changes: 34 additions & 0 deletions mlir/test/Dialect/Tosa/tosa-validation-valid-strict.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// RUN: mlir-opt %s -split-input-file -verify-diagnostics --tosa-validate="profile=pro_int,pro_fp extension=int16,int4,bf16,fp8e4m3,fp8e5m2,fft,variable,controlflow,doubleround,inexactround strict-op-spec-alignment" | FileCheck %s

// -----

// CHECK-LABEL: test_cond_if_isolated_from_above
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what is the value in those CHECK-LABEL since there are no CHECK between them. Since these tests try to check the absence of an error, the mlir-opt line should be enough and FileCheck is not needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise in error_if_check.mlir by the way which doesn't even run FileCheck. Can you do a separate patch to remove the CHECK directives in that file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, you're more familiar with FileCheck/LIT so appreciate any suggestion. Without this fix, these tests still passed without FileCheck. I suspect it's because they were returning a silent failure? So I used FileCheck here to help make sure that something was returned from mlir-opt and that the test would fail as expected without the fix.

I think you're correct that I didn't need to use CHECK-LABEL, I was just following the pattern used by most tests under TOSA.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For checking the absence of an error you could just remove the --split-input-files and then mlir-opt should return an error if any of the test fail to compile. On the other hand having CHECK-LABEL means you'll get a more precise error of which test fail so maybe worth keeping. The CHECK-LABEL without a FileCheck invocation though is waiting for trouble because someone might add some tests thinking that FileCheck is being run and wrongly conclude that their test work.

func.func @test_cond_if_isolated_from_above(%arg0: tensor<f32>, %arg1: tensor<f32>, %arg2: tensor<i1>) -> tensor<f32> {
%0 = "tosa.cond_if"(%arg2, %arg0, %arg1) ({
^bb0(%arg3: tensor<f32>, %arg4: tensor<f32>):
tosa.yield %arg3 : tensor<f32>
}, {
^bb0(%arg3: tensor<f32>, %arg4: tensor<f32>):
tosa.yield %arg4 : tensor<f32>
}) : (tensor<i1>, tensor<f32>, tensor<f32>) -> tensor<f32>
return %0 : tensor<f32>
}

// -----

// CHECK-LABEL: test_while_loop_isolated_from_above
func.func @test_while_loop_isolated_from_above(%arg0: tensor<f32>, %arg1: tensor<i32>) {
%0 = "tosa.const"() {values = dense<0> : tensor<i32>} : () -> tensor<i32>
%1:3 = "tosa.while_loop"(%0, %arg0, %arg1) ({
^bb0(%arg3: tensor<i32>, %arg4: tensor<f32>, %arg5: tensor<i32>):
%2 = "tosa.greater_equal"(%arg3, %arg5) : (tensor<i32>, tensor<i32>) -> tensor<i1>
%3 = "tosa.logical_not"(%2) : (tensor<i1>) -> tensor<i1>
"tosa.yield"(%3) : (tensor<i1>) -> ()
}, {
^bb0(%arg3: tensor<i32>, %arg4: tensor<f32>, %arg5: tensor<i32>):
%2 = "tosa.const"() {values = dense<1> : tensor<i32>} : () -> tensor<i32>
%3 = "tosa.add"(%arg3, %2) : (tensor<i32>, tensor<i32>) -> tensor<i32>
"tosa.yield"(%3, %arg4, %arg5) : (tensor<i32>, tensor<f32>, tensor<i32>) -> ()
}) : (tensor<i32>, tensor<f32>, tensor<i32>) -> (tensor<i32>, tensor<f32>, tensor<i32>)
return
}