Skip to content
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

[mlir][ArmSME] Add enable_arm_streaming_ignore attribute #66911

Merged
merged 3 commits into from
Sep 22, 2023

Conversation

MacDue
Copy link
Member

@MacDue MacDue commented Sep 20, 2023

This attribute makes the enable_arm_streaming pass ignore a function (i.e. not add the enable streaming/za attributes). The main use case for this is to prevent helper functions within tests being made streaming functions.

This attribute makes the `enable_arm_streaming` pass ignore a function
(i.e. not add the enable streaming/za attributes). The main use case for
this is to prevent helper functions within tests being made streaming
functions.
@llvmbot
Copy link
Member

llvmbot commented Sep 20, 2023

@llvm/pr-subscribers-mlir-sme

@llvm/pr-subscribers-mlir

Changes

This attribute makes the enable_arm_streaming pass ignore a function (i.e. not add the enable streaming/za attributes). The main use case for this is to prevent helper functions within tests being made streaming functions.


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

2 Files Affected:

  • (modified) mlir/lib/Dialect/ArmSME/Transforms/EnableArmStreaming.cpp (+5-1)
  • (modified) mlir/test/Dialect/ArmSME/enable-arm-streaming.mlir (+8)
diff --git a/mlir/lib/Dialect/ArmSME/Transforms/EnableArmStreaming.cpp b/mlir/lib/Dialect/ArmSME/Transforms/EnableArmStreaming.cpp
index 97c38b546349510..1d3a090e861013b 100644
--- a/mlir/lib/Dialect/ArmSME/Transforms/EnableArmStreaming.cpp
+++ b/mlir/lib/Dialect/ArmSME/Transforms/EnableArmStreaming.cpp
@@ -52,6 +52,8 @@ using namespace mlir::arm_sme;
 static constexpr char kArmStreamingAttr[] = "arm_streaming";
 static constexpr char kArmLocallyStreamingAttr[] = "arm_locally_streaming";
 static constexpr char kArmZAAttr[] = "arm_za";
+static constexpr char kEnableArmStreamingIgnoreAttr[] =
+    "enable_arm_streaming_ignore";
 
 namespace {
 struct EnableArmStreamingPass
@@ -61,7 +63,9 @@ struct EnableArmStreamingPass
     this->enableZA = enableZA;
   }
   void runOnOperation() override {
-    std::string attr;
+    if (getOperation()->getAttr(kEnableArmStreamingIgnoreAttr))
+      return;
+    StringRef attr;
     switch (mode) {
     case ArmStreaming::Default:
       attr = kArmStreamingAttr;
diff --git a/mlir/test/Dialect/ArmSME/enable-arm-streaming.mlir b/mlir/test/Dialect/ArmSME/enable-arm-streaming.mlir
index f5cc83192f9f6e1..e7bbe8c0047687d 100644
--- a/mlir/test/Dialect/ArmSME/enable-arm-streaming.mlir
+++ b/mlir/test/Dialect/ArmSME/enable-arm-streaming.mlir
@@ -9,3 +9,11 @@
 // CHECK-ENABLE-ZA-LABEL: @arm_streaming
 // CHECK-ENABLE-ZA-SAME: attributes {arm_streaming, arm_za}
 func.func @arm_streaming() { return }
+
+// CHECK-LABEL: @not_arm_streaming
+// CHECK-SAME: attributes {enable_arm_streaming_ignore}
+// CHECK-LOCALLY-LABEL: @not_arm_streaming
+// CHECK-LOCALLY-SAME: attributes {enable_arm_streaming_ignore}
+// CHECK-ENABLE-ZA-LABEL: @not_arm_streaming
+// CHECK-ENABLE-ZA-SAME: attributes {enable_arm_streaming_ignore}
+func.func @not_arm_streaming() attributes {enable_arm_streaming_ignore} { return }

@MacDue
Copy link
Member Author

MacDue commented Sep 20, 2023

RE: #66691 (comment)

I think <pass_name> + _ignore makes the intent clearer, disable_arm_streaming implies that it was on before the pass, which is not the case.

@banach-space
Copy link
Contributor

The main use case for this is to prevent helper functions within tests being made streaming functions.

Any chance to add a test that would demonstrate this?

@MacDue
Copy link
Member Author

MacDue commented Sep 21, 2023

The main use case for this is to prevent helper functions within tests being made streaming functions.

Any chance to add a test that would demonstrate this?

I'm not sure what that'd be other than the test here (which shows the streaming attributes are not added no matter what enable_arm_streaming flags you set). In #66691 I use this attribute on helper functions within tests.

@c-rhodes
Copy link
Collaborator

The main use case for this is to prevent helper functions within tests being made streaming functions.

Any chance to add a test that would demonstrate this?

I'm not sure what that'd be other than the test here (which shows the streaming attributes are not added no matter what enable_arm_streaming flags you set). In #66691 I use this attribute on helper functions within tests.

I think the test you've added is sufficient.

Comment on lines +13 to +18
// CHECK-LABEL: @not_arm_streaming
// CHECK-SAME: attributes {enable_arm_streaming_ignore}
// CHECK-LOCALLY-LABEL: @not_arm_streaming
// CHECK-LOCALLY-SAME: attributes {enable_arm_streaming_ignore}
// CHECK-ENABLE-ZA-LABEL: @not_arm_streaming
// CHECK-ENABLE-ZA-SAME: attributes {enable_arm_streaming_ignore}
Copy link
Contributor

@banach-space banach-space Sep 21, 2023

Choose a reason for hiding this comment

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

I was after something like this - I think that CHECK-NOT is more descriptive in this context (i.e., we want to make sure that in presence of enable_arm_streaming_ignore we won't see these streaming SVE attributes)

Suggested change
// CHECK-LABEL: @not_arm_streaming
// CHECK-SAME: attributes {enable_arm_streaming_ignore}
// CHECK-LOCALLY-LABEL: @not_arm_streaming
// CHECK-LOCALLY-SAME: attributes {enable_arm_streaming_ignore}
// CHECK-ENABLE-ZA-LABEL: @not_arm_streaming
// CHECK-ENABLE-ZA-SAME: attributes {enable_arm_streaming_ignore}
// CHECK-LABEL: @not_arm_streaming
// CHECK-NOT: arm_streaming
// CHECK-LOCALLY-LABEL: @not_arm_streaming
// CHECK-LOCALLY-NOT: arm_locally_streaming
// CHECK-ENABLE-ZA-LABEL: @not_arm_streaming
// CHECK-ENABLE-ZA-NOT: arm_za

I could've explained better first time round, apologies :)

Copy link
Member Author

@MacDue MacDue Sep 21, 2023

Choose a reason for hiding this comment

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

I've added CHECK-NOTs between the matches now (still with the CHECK-SAMEs too). I'm a little wary of just using CHECK-NOT alone (since if it's checking the wrong line it can falsely pass too).

Copy link
Contributor

Choose a reason for hiding this comment

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

The way this is written now, I think that you could have the following output and the test would pass (which is not what we want):

func.func @not_arm_streaming() attributes {enable_arm_streaming_ignore, arm_locally_streaming} { return }

So you'd need this to be 100% sure:

// CHECK-LABEL: @not_arm_streaming
// CHECK-NOT: arm_streaming
// CHECK-LOCALLY-LABEL: @not_arm_streaming
// CHECK-NOT: arm_streaming

This should be sufficient though:

// CHECK-LABEL: @not_arm_streaming
// CHECK-NOT: arm_streaming

This way, you match the label (which is unique) and the make sure that there's no arm_streaming attribute starting from the label all the way to EOF.

Copy link
Member Author

Choose a reason for hiding this comment

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

You have to do:

// CHECK-LABEL: @not_arm_streaming
// CHECK-NOT: arm_streaming
// CHECK-LOCALLY-LABEL: @not_arm_streaming
// CHECK-NOT: arm_streaming

Because arm_streaming is a substring of enable_arm_streaming_ignore. There's probably some syntax for whole word matches, but I think that just using // CHECK-SAME: is a little simpler and easier to understand here.

Copy link
Contributor

Choose a reason for hiding this comment

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

There's probably some syntax for whole word matches

There's -match-full-lines

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.

LGTM, ta!

Comment on lines +13 to +18
// CHECK-LABEL: @not_arm_streaming
// CHECK-SAME: attributes {enable_arm_streaming_ignore}
// CHECK-LOCALLY-LABEL: @not_arm_streaming
// CHECK-LOCALLY-SAME: attributes {enable_arm_streaming_ignore}
// CHECK-ENABLE-ZA-LABEL: @not_arm_streaming
// CHECK-ENABLE-ZA-SAME: attributes {enable_arm_streaming_ignore}
Copy link
Contributor

Choose a reason for hiding this comment

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

There's probably some syntax for whole word matches

There's -match-full-lines

@MacDue MacDue merged commit 06f22c9 into llvm:main Sep 22, 2023
MacDue added a commit that referenced this pull request Sep 26, 2023
This adds a custom lowering for SME that loops over each row of the
tile, extracting it via an SME MOVA, then printing with a normal 1D
vector.print.

This makes writing SME integration tests easier and less verbose.

Depends on: #66910, #66911
legrosbuffle pushed a commit to legrosbuffle/llvm-project that referenced this pull request Sep 29, 2023
…6691)

This adds a custom lowering for SME that loops over each row of the
tile, extracting it via an SME MOVA, then printing with a normal 1D
vector.print.

This makes writing SME integration tests easier and less verbose.

Depends on: llvm#66910, llvm#66911
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