Skip to content

[mlir][nfc] Add a negative test for --linalg-specialize-generic-ops #127600

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

Conversation

banach-space
Copy link
Contributor

@banach-space banach-space commented Feb 18, 2025

Following on from #126737, adds a negative test that:

I've also made minor editorial changes.

Following on from llvm#126737, adds a negative test that:
* prior to llvm#126737, would incorrectly generated empty output,
* with the fix in-tree, simply outputs the input IR (i.e. the
  specialization "fails").

I've also made minor editorial changes.
@llvmbot
Copy link
Member

llvmbot commented Feb 18, 2025

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-linalg

Author: Andrzej Warzyński (banach-space)

Changes

Following on from #126737, adds a negative test that:

  • prior to #126737, would incorrectly generated empty output,
  • with the fix in-tree, simply outputs the input IR (i.e. the
    specialization "fails").

I've also made minor editorial changes.


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

1 Files Affected:

  • (modified) mlir/test/Dialect/Linalg/specialize-generic-ops-fail.mlir (+21-6)
diff --git a/mlir/test/Dialect/Linalg/specialize-generic-ops-fail.mlir b/mlir/test/Dialect/Linalg/specialize-generic-ops-fail.mlir
index 542a7ed4a198b..357f2c11a7936 100644
--- a/mlir/test/Dialect/Linalg/specialize-generic-ops-fail.mlir
+++ b/mlir/test/Dialect/Linalg/specialize-generic-ops-fail.mlir
@@ -6,11 +6,26 @@
 // CHECK-LABEL: @transpose_and_broadcast
 // CHECK: linalg.generic
 func.func @transpose_and_broadcast(%arg0: tensor<7x8xf32>, %arg1: tensor<8x7x9xf32>) -> tensor<8x7x9xf32> {
-  %0 = linalg.generic
-        {indexing_maps = [#map, #map1], iterator_types = ["parallel", "parallel", "parallel"]}
-        ins(%arg0 : tensor<7x8xf32>) outs(%arg1 : tensor<8x7x9xf32>) {
-        ^bb0(%in: f32, %out: f32):
-           linalg.yield %in : f32
+  %res = linalg.generic {
+    indexing_maps = [#map, #map1], iterator_types = ["parallel", "parallel", "parallel"]
+  } ins(%arg0 : tensor<7x8xf32>) outs(%arg1 : tensor<8x7x9xf32>) {
+  ^bb0(%in: f32, %out: f32):
+    linalg.yield %in : f32
   } -> tensor<8x7x9xf32>
-  return %0 : tensor<8x7x9xf32>
+  return %res : tensor<8x7x9xf32>
+}
+
+// -----
+
+#map = affine_map<(d0) -> (d0)>
+// CHECK-LABEL: @neither_permutation_nor_broadcast
+// CHECK: linalg.generic
+func.func @neither_permutation_nor_broadcast(%init : tensor<8xi32>) -> tensor<8xi32> {
+  %res = linalg.generic {
+    indexing_maps = [#map], iterator_types = ["parallel"]
+  } outs(%init: tensor<8xi32>) {
+  ^bb0(%out: i32):
+    linalg.yield %out: i32
+  } -> tensor<8xi32>
+  return %res : tensor<8xi32>
 }

@banach-space
Copy link
Contributor Author

@javedabsar , why is @transpose_and_broadcast supposed to fail? That's not clear from the comments (nor the test function name).

The example that I added contains neither broadcasts nor transposes, so the reason for failure is (hopefully) clear.

Thanks!

Copy link
Contributor

@javedabsar1 javedabsar1 left a comment

Choose a reason for hiding this comment

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

awesome. thanks !

@banach-space banach-space merged commit 7e2707a into llvm:main Feb 18, 2025
11 checks passed
@banach-space banach-space deleted the andrzej/add_negative_test_for_linalg_specialize branch February 18, 2025 14:17
wldfngrs pushed a commit to wldfngrs/llvm-project that referenced this pull request Feb 19, 2025
…lvm#127600)

Following on from llvm#126737, adds a negative test that:
* prior to llvm#126737, would incorrectly generated empty output,
* with the fix in-tree, simply outputs the input IR (i.e. the
  specialization "fails").

I've also made minor editorial changes.
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.

3 participants