Skip to content

[mlir][arith] Add printing integration tests #98184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pingshiyu
Copy link
Contributor

Printing operations regression tests, from the original larger PR that has been broken down: #92272

@llvmbot
Copy link
Member

llvmbot commented Jul 9, 2024

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-arith

Author: Jacob Yu (pingshiyu)

Changes

Printing operations regression tests, from the original larger PR that has been broken down: #92272


Full diff: https://github.com/llvm/llvm-project/pull/98184.diff

1 Files Affected:

  • (added) mlir/test/Integration/Dialect/Arith/CPU/print.mlir (+47)
diff --git a/mlir/test/Integration/Dialect/Arith/CPU/print.mlir b/mlir/test/Integration/Dialect/Arith/CPU/print.mlir
new file mode 100644
index 0000000000000..d322c23952bab
--- /dev/null
+++ b/mlir/test/Integration/Dialect/Arith/CPU/print.mlir
@@ -0,0 +1,47 @@
+// RUN: mlir-opt %s --convert-scf-to-cf --convert-cf-to-llvm --convert-vector-to-llvm \
+// RUN:             --convert-func-to-llvm --convert-arith-to-llvm | \
+// RUN:   mlir-cpu-runner -e entry -entry-point-result=void \
+// RUN:                   --shared-libs=%mlir_c_runner_utils | \
+// RUN:   FileCheck %s --match-full-lines
+
+func.func @i1() {
+    // printing i1 values
+    // print(0 : i1) = '0'; print(1 : i1) = '1'; print(-1 : i1) = '1'
+    // CHECK:      0
+    // CHECK-NEXT: 1
+    // CHECK-NEXT: 1
+    %false = arith.constant false
+    %true = arith.constant 1 : i1
+    %true_as_n1 = arith.constant -1 : i1
+    vector.print %false : i1
+    vector.print %true : i1
+    vector.print %true_as_n1 : i1
+    return
+}
+
+func.func @index() {
+    // printing index values
+    // print(0 : index) = '0'; print(1 : index) = '1'; print(-1 : index) = '2^w - 1'
+    // index constants are printed as unsigned
+    // vector.print(arith.constant(x)) ~= toUnsignedRepr x
+    // CHECK-NEXT: 0
+    // CHECK-NEXT: 1
+    // CHECK-NEXT: 18446744073709551615
+    // CHECK-NEXT: 63
+    %c0 = arith.constant 0 : index
+    %c1 = arith.constant 1 : index
+    %cn1 = arith.constant -1 : index
+    %c63 = arith.constant 63 : index
+
+    vector.print %c0 : index
+    vector.print %c1 : index
+    vector.print %cn1 : index
+    vector.print %c63 : index
+    return
+}
+
+func.func @entry() {
+    func.call @i1() : () -> ()
+    func.call @index() : () -> ()
+    return
+}

@banach-space banach-space self-requested a review July 21, 2024 15:06
@pingshiyu pingshiyu changed the title [mlir][arith] Add printing regression tests [mlir][arith] Add printing integration tests Jul 23, 2024
Comment on lines +13 to +14
%false = arith.constant false
%true = arith.constant 1 : i1
Copy link
Member

Choose a reason for hiding this comment

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

Could we use either 0 / 1 or false / true for consistency here?

Comment on lines +22 to +41
func.func @index() {
// printing index values
// print(0 : index) = '0'; print(1 : index) = '1'; print(-1 : index) = '2^w - 1'
// index constants are printed as unsigned
// vector.print(arith.constant(x)) ~= toUnsignedRepr x
// CHECK-NEXT: 0
// CHECK-NEXT: 1
// CHECK-NEXT: 18446744073709551615
// CHECK-NEXT: 63
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
%cn1 = arith.constant -1 : index
%c63 = arith.constant 63 : index

vector.print %c0 : index
vector.print %c1 : index
vector.print %cn1 : index
vector.print %c63 : index
return
}
Copy link
Member

Choose a reason for hiding this comment

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

Could we specify the index type in the mlir-opt pipeline above? I'm worried this can be printed as u64 or u32 depending on the host

@joker-eph
Copy link
Collaborator

Thanks for adding tests, we surely have holes here and there and not enough people closing them... :)

Printing operations regression tests, from the original larger PR that has been broken down: #92272

Please provide a standalone description, we don't need to refer another PR here and instead I'd rather see here a clear "why" these tests are added.

Thanks!

%true_as_n1 = arith.constant -1 : i1
vector.print %false : i1
vector.print %true : i1
vector.print %true_as_n1 : i1
Copy link
Collaborator

Choose a reason for hiding this comment

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

From what I can tell, this is not testing anything about arith is it? Seems like this is all about testing "vector.print" in itself, or even just the testing runtime we have.
Can you try to make the file location more relevant?

Can we also consolidate all the testing for the runtime in a single execution? (each new lit test isn't free: it'll fork/exec a compiler process, and then execute the result here).

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also consolidate all the testing for the runtime in a single execution? (each new lit test isn't free: it'll fork/exec a compiler process, and then execute the result here).

I advocated for keeping them in separate files - to make sure the tests are minimal and to make it easier to identify what's being tested. That has made reviewing much easier, but I didn't really think about the runtime cost. Consolidation makes sense, but l'd wait until all PR's from #100121 are complete. Is that OK?

Copy link
Contributor

@banach-space banach-space left a comment

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants