Skip to content

[mlir][arith] Add division integration tests #98181

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 11 commits into
base: main
Choose a base branch
from

Conversation

pingshiyu
Copy link
Contributor

Division 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

Author: Jacob Yu (pingshiyu)

Changes

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


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

1 Files Affected:

  • (added) mlir/test/Integration/Dialect/Arith/CPU/divide.mlir (+109)
diff --git a/mlir/test/Integration/Dialect/Arith/CPU/divide.mlir b/mlir/test/Integration/Dialect/Arith/CPU/divide.mlir
new file mode 100644
index 0000000000000..a08f7975f5968
--- /dev/null
+++ b/mlir/test/Integration/Dialect/Arith/CPU/divide.mlir
@@ -0,0 +1,109 @@
+// Tests division operations and their variants (e.g. ceil/floordiv, rem etc)
+
+// RUN: mlir-opt %s --arith-expand --test-lower-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 @divsi_i8(%v1 : i8, %v2 : i8) {
+    vector.print str "@divsi_i8\n"
+    %0 = arith.divsi %v1, %v2 : i8
+    vector.print %0 : i8
+    return
+}
+
+func.func @divsi_i1(%v1 : i1, %v2 : i1) {
+    vector.print str "@divsi_i1\n"
+    %0 = arith.divsi %v1, %v2 : i1
+    vector.print %0 : i1
+    return
+
+}
+
+func.func @remsi_i8(%v1 : i8, %v2 : i8) {
+    vector.print str "@remsi_i8\n"
+    %0 = arith.remsi %v1, %v2 : i8
+    vector.print %0 : i8
+    return
+}
+
+func.func @ceildivsi_i8(%v1 : i8, %v2 : i8) {
+    vector.print str "@ceildivsi_i8\n"
+    %0 = arith.ceildivsi %v1, %v2 : i8
+    vector.print %0 : i8
+    return
+}
+
+func.func @divsi() {
+    // ------------------------------------------------
+    // Test i8
+    // ------------------------------------------------
+    %c68 = arith.constant 68 : i8
+    %cn97 = arith.constant -97 : i8
+
+    // divsi should round towards zero (rather than -infinity)
+    // divsi -97 68 = -1
+    // CHECK-LABEL: @divsi_i8
+    // CHECK-NEXT:  -1
+    func.call @divsi_i8(%cn97, %c68) : (i8, i8) -> ()
+
+    // ------------------------------------------------
+    // Test i1
+    // ------------------------------------------------
+    %false = arith.constant false
+    %true = arith.constant true
+
+    // CHECK-LABEL: @divsi_i1
+    // CHECK-NEXT:  1
+    func.call @divsi_i1(%true, %true) : (i1, i1) -> ()
+
+    // ------------------------------------------------
+    // TODO: i16, i32 etc
+    // ------------------------------------------------   
+    return 
+}
+
+func.func @remsi() {
+    // ------------------------------------------------
+    // Test i8
+    // ------------------------------------------------
+    %cn1 = arith.constant -1 : i8
+    %i8_min_p1 = arith.constant -127 : i8
+    
+    // remsi minIntPlus1 -1 = remsi -2^(w-1) -1 = 0
+    // CHECK-LABEL: @remsi_i8
+    // CHECK-NEXT:  0
+    func.call @remsi_i8(%i8_min_p1, %cn1) : (i8, i8) -> ()
+
+    // ------------------------------------------------
+    // TODO: i1, i16 etc
+    // ------------------------------------------------ 
+    return
+}
+
+func.func @ceildivsi() {
+    // ------------------------------------------------
+    // Test i8
+    // ------------------------------------------------
+    %c7 = arith.constant 7 : i8
+    %i8_min = arith.constant -128 : i8
+
+    // ceildivsi should keep signs
+    // forall w, y. (w > 0, y > 0) => -2^w `ceildiv` y : i_w < 0
+    // CHECK-LABEL: @ceildivsi_i8
+    // CHECK-NEXT:  -18
+    func.call @ceildivsi_i8(%i8_min, %c7) : (i8, i8) -> ()
+
+    // ------------------------------------------------
+    // TODO: i1, i16 etc
+    // ------------------------------------------------ 
+
+    return
+}
+
+func.func @entry() {
+    func.call @divsi() : () -> ()
+    func.call @remsi() : () -> ()
+    func.call @ceildivsi() : () -> ()
+    return
+}

@llvmbot
Copy link
Member

llvmbot commented Jul 9, 2024

@llvm/pr-subscribers-mlir-arith

Author: Jacob Yu (pingshiyu)

Changes

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


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

1 Files Affected:

  • (added) mlir/test/Integration/Dialect/Arith/CPU/divide.mlir (+109)
diff --git a/mlir/test/Integration/Dialect/Arith/CPU/divide.mlir b/mlir/test/Integration/Dialect/Arith/CPU/divide.mlir
new file mode 100644
index 0000000000000..a08f7975f5968
--- /dev/null
+++ b/mlir/test/Integration/Dialect/Arith/CPU/divide.mlir
@@ -0,0 +1,109 @@
+// Tests division operations and their variants (e.g. ceil/floordiv, rem etc)
+
+// RUN: mlir-opt %s --arith-expand --test-lower-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 @divsi_i8(%v1 : i8, %v2 : i8) {
+    vector.print str "@divsi_i8\n"
+    %0 = arith.divsi %v1, %v2 : i8
+    vector.print %0 : i8
+    return
+}
+
+func.func @divsi_i1(%v1 : i1, %v2 : i1) {
+    vector.print str "@divsi_i1\n"
+    %0 = arith.divsi %v1, %v2 : i1
+    vector.print %0 : i1
+    return
+
+}
+
+func.func @remsi_i8(%v1 : i8, %v2 : i8) {
+    vector.print str "@remsi_i8\n"
+    %0 = arith.remsi %v1, %v2 : i8
+    vector.print %0 : i8
+    return
+}
+
+func.func @ceildivsi_i8(%v1 : i8, %v2 : i8) {
+    vector.print str "@ceildivsi_i8\n"
+    %0 = arith.ceildivsi %v1, %v2 : i8
+    vector.print %0 : i8
+    return
+}
+
+func.func @divsi() {
+    // ------------------------------------------------
+    // Test i8
+    // ------------------------------------------------
+    %c68 = arith.constant 68 : i8
+    %cn97 = arith.constant -97 : i8
+
+    // divsi should round towards zero (rather than -infinity)
+    // divsi -97 68 = -1
+    // CHECK-LABEL: @divsi_i8
+    // CHECK-NEXT:  -1
+    func.call @divsi_i8(%cn97, %c68) : (i8, i8) -> ()
+
+    // ------------------------------------------------
+    // Test i1
+    // ------------------------------------------------
+    %false = arith.constant false
+    %true = arith.constant true
+
+    // CHECK-LABEL: @divsi_i1
+    // CHECK-NEXT:  1
+    func.call @divsi_i1(%true, %true) : (i1, i1) -> ()
+
+    // ------------------------------------------------
+    // TODO: i16, i32 etc
+    // ------------------------------------------------   
+    return 
+}
+
+func.func @remsi() {
+    // ------------------------------------------------
+    // Test i8
+    // ------------------------------------------------
+    %cn1 = arith.constant -1 : i8
+    %i8_min_p1 = arith.constant -127 : i8
+    
+    // remsi minIntPlus1 -1 = remsi -2^(w-1) -1 = 0
+    // CHECK-LABEL: @remsi_i8
+    // CHECK-NEXT:  0
+    func.call @remsi_i8(%i8_min_p1, %cn1) : (i8, i8) -> ()
+
+    // ------------------------------------------------
+    // TODO: i1, i16 etc
+    // ------------------------------------------------ 
+    return
+}
+
+func.func @ceildivsi() {
+    // ------------------------------------------------
+    // Test i8
+    // ------------------------------------------------
+    %c7 = arith.constant 7 : i8
+    %i8_min = arith.constant -128 : i8
+
+    // ceildivsi should keep signs
+    // forall w, y. (w > 0, y > 0) => -2^w `ceildiv` y : i_w < 0
+    // CHECK-LABEL: @ceildivsi_i8
+    // CHECK-NEXT:  -18
+    func.call @ceildivsi_i8(%i8_min, %c7) : (i8, i8) -> ()
+
+    // ------------------------------------------------
+    // TODO: i1, i16 etc
+    // ------------------------------------------------ 
+
+    return
+}
+
+func.func @entry() {
+    func.call @divsi() : () -> ()
+    func.call @remsi() : () -> ()
+    func.call @ceildivsi() : () -> ()
+    return
+}

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.

Would you be able to add some contrasting edge cases to the ones that you already have here?

@pingshiyu pingshiyu changed the title [mlir][arith] Add division regression tests [mlir][arith] Add division integration tests Jul 23, 2024
@pingshiyu
Copy link
Contributor Author

pingshiyu commented Jul 23, 2024

Thank you for the suggestion!

Would you be able to add some contrasting edge cases to the ones that you already have here?

I am not 100% I grokked what you meant here by "contrasting", but I've added some edge cases to the suite now :)

@pingshiyu
Copy link
Contributor Author

Thanks for the comments @banach-space!

I've just pushed a commit addressing those :)

pingshiyu and others added 3 commits July 29, 2024 13:26
Co-authored-by: Andrzej Warzyński <andrzej.warzynski@gmail.com>
Co-authored-by: Andrzej Warzyński <andrzej.warzynski@gmail.com>
pingshiyu and others added 3 commits August 28, 2024 12:44
Co-authored-by: Jakub Kuderski <kubakuderski@gmail.com>
Co-authored-by: Jakub Kuderski <kubakuderski@gmail.com>
@pingshiyu
Copy link
Contributor Author

pingshiyu commented Aug 29, 2024

@kuhar @banach-space all comments addressed :)

One of the tests will fail due to an existing bug: #106519

@banach-space
Copy link
Contributor

Given the discussion here:

and the resulting update to the MLIR guidelines on e2e tests:

I suggest that we park this for now.

@pingshiyu, thank you so much for your contribution and for bearing with us throughout this process. Apologies for not resolving the earlier discussion sooner—it would have saved you a lot of effort. I hope this doesn’t discourage you from contributing to MLIR in the future, and we truly appreciate your work!

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.

4 participants