You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/08/16 09:35:03 UTC

[GitHub] [tvm] Mousius opened a new pull request, #12454: [Target] Add Target Parser for Arm(R) Cortex(R) A-Profile CPUs

Mousius opened a new pull request, #12454:
URL: https://github.com/apache/tvm/pull/12454

   This implements an initial Target Parser which aims to consolidate architecture feature detection from a few different places:
   * https://github.com/apache/tvm/blob/d2db9cb0d839e32778f461b77e59f6418282a511/python/tvm/topi/arm_cpu/arm_utils.py#L24-L70
   * https://github.com/apache/tvm/blob/02fbaf0ed9120a8f95155e63de42459f230584aa/python/tvm/relay/qnn/op/legalizations.py#L350-L359
   * https://github.com/apache/tvm/blob/b542724873140bb051492530d97a78b9b7b7983d/python/tvm/relay/op/strategy/arm_cpu.py#L232
   
   A further patch will remove all of the above and replace usages with the `.features` map.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] Mousius merged pull request #12454: [Target] Add Target Parser for Arm(R) Cortex(R) A-Profile CPUs

Posted by GitBox <gi...@apache.org>.
Mousius merged PR #12454:
URL: https://github.com/apache/tvm/pull/12454


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] github-actions[bot] commented on pull request #12454: [Target] Add Target Parser for Arm(R) Cortex(R) A-Profile CPUs

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #12454:
URL: https://github.com/apache/tvm/pull/12454#issuecomment-1234034899

   It has been a while since this PR was updated, @u99127 please leave a review or address the outstanding comments. @Mousius if this PR is still a work in progress, please [convert it to a draft](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-stage-of-a-pull-request#converting-a-pull-request-to-a-draft) until it is ready for review.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] Mousius commented on pull request #12454: [Target] Add Target Parser for Arm(R) Cortex(R) A-Profile CPUs

Posted by GitBox <gi...@apache.org>.
Mousius commented on PR #12454:
URL: https://github.com/apache/tvm/pull/12454#issuecomment-1216398017

   cc @u99127 for review 😸 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] tvm-bot commented on pull request #12454: [Target] Add Target Parser for Arm(R) Cortex(R) A-Profile CPUs

Posted by GitBox <gi...@apache.org>.
tvm-bot commented on PR #12454:
URL: https://github.com/apache/tvm/pull/12454#issuecomment-1284595630

   <!---bot-comment-->
   
   Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from [Reviewers](https://github.com/apache/incubator-tvm/blob/master/CONTRIBUTORS.md#reviewers) by @-ing them in a comment.
   
   <!--bot-comment-docs-start-->
    * Built docs for commit c566c978978b50325a6cc2d18959672e4fa17288 can be found [here](https://pr-docs.tlcpack.ai/PR-12454/11/docs/index.html).<!--bot-comment-docs-end-->
   
   <sub>Generated by [tvm-bot](https://github.com/apache/tvm/blob/main/ci/README.md#github-actions)</sub>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] github-actions[bot] commented on pull request #12454: [Target] Add Target Parser for Arm(R) Cortex(R) A-Profile CPUs

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #12454:
URL: https://github.com/apache/tvm/pull/12454#issuecomment-1240485424

   It has been a while since this PR was updated, @u99127 please leave a review or address the outstanding comments. @Mousius if this PR is still a work in progress, please [convert it to a draft](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-stage-of-a-pull-request#converting-a-pull-request-to-a-draft) until it is ready for review.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] u99127 commented on a diff in pull request #12454: [Target] Add Target Parser for Arm(R) Cortex(R) A-Profile CPUs

Posted by GitBox <gi...@apache.org>.
u99127 commented on code in PR #12454:
URL: https://github.com/apache/tvm/pull/12454#discussion_r994745639


##########
src/target/parsers/aprofile.cc:
##########
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * \file tvm/target/parsers/aprofile.cc
+ * \brief Target Parser for Arm(R) Cortex(R) A-Profile CPUs
+ */
+
+#include "aprofile.h"
+
+#include <regex>
+#include <string>
+
+#include "../../support/utils.h"
+
+namespace tvm {
+namespace target {
+namespace parsers {
+namespace aprofile {
+
+const std::regex version_regex("\\+v(\\d+\\.\\d+)a");
+
+static inline double GetArchVersion(Array<String> mattr) {
+  std::smatch version;
+
+  for (const String& attr : mattr) {
+    std::string attr_string = attr;
+    if (std::regex_match(attr_string, version, version_regex)) {
+      if (version.size() == 2) {
+        return atof(version[1].str().data());
+      }
+    }
+  }
+  return 0.0;
+}
+
+static inline double GetArchVersion(Optional<Array<String>> attr) {
+  if (!attr) {
+    return false;
+  }
+  return GetArchVersion(attr.value());
+}
+
+static inline bool HasFlag(String attr, std::string flag) {
+  std::string attr_str = attr;
+  return attr_str.find(flag) != std::string::npos;
+}
+
+static inline bool HasFlag(Optional<String> attr, std::string flag) {
+  if (!attr) {
+    return false;
+  }
+  return HasFlag(attr.value(), flag);
+}
+
+static inline bool HasFlag(Optional<Array<String>> attr, std::string flag) {
+  if (!attr) {
+    return false;
+  }
+  Array<String> attr_array = attr.value();
+
+  auto matching_attr = std::find_if(attr_array.begin(), attr_array.end(),
+                                    [flag](String attr_str) { return HasFlag(attr_str, flag); });
+  return matching_attr != attr_array.end();
+}
+
+static bool HasFlag(Optional<String> mcpu, Optional<Array<String>> mattr, std::string flag) {
+  return HasFlag(mcpu, flag) || HasFlag(mattr, flag);
+}
+
+bool IsAArch32(Optional<String> mtriple) {
+  if (mtriple) {
+    return support::StartsWith(mtriple.value(), "armv8a") ||
+           support::StartsWith(mtriple.value(), "armv7a");
+  }
+  return false;
+}
+
+bool IsAArch64(Optional<String> mtriple) {
+  if (mtriple) {
+    return support::StartsWith(mtriple.value(), "aarch64");
+  }
+  return false;
+}
+
+bool IsArch(TargetJSON attrs) {
+  Optional<String> mtriple = Downcast<Optional<String>>(attrs.Get("mtriple"));
+
+  return IsAArch32(mtriple) || IsAArch64(mtriple);
+}
+
+static TargetFeatures GetFeatures(TargetJSON target) {
+  Optional<String> mcpu = Downcast<Optional<String>>(target.Get("mcpu"));
+  Optional<String> mtriple = Downcast<Optional<String>>(target.Get("mtriple"));
+  Optional<Array<String>> mattr = Downcast<Optional<Array<String>>>(target.Get("mattr"));
+
+  double arch_version = GetArchVersion(mattr);
+
+  bool is_aarch64 = IsAArch64(mtriple);
+
+  bool simd_flag = HasFlag(mcpu, mattr, "+neon") || HasFlag(mcpu, mattr, "+simd");
+  bool simd_disable = HasFlag(mcpu, mattr, "nosimd");
+  bool has_asimd = (is_aarch64 || simd_flag) && !simd_disable;

Review Comment:
   I think this should be 
   
   has_asimd = is_aarch64 || simd_flag ;
   
   It can be assumed that we have simd for AArch64, the optionality is really in AArch32 land. I think we should remove the simd_disable option . 
   
   



##########
src/target/parsers/aprofile.cc:
##########
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * \file tvm/target/parsers/aprofile.cc
+ * \brief Target Parser for Arm(R) Cortex(R) A-Profile CPUs
+ */
+
+#include "aprofile.h"
+
+#include <regex>
+#include <string>
+
+#include "../../support/utils.h"
+
+namespace tvm {
+namespace target {
+namespace parsers {
+namespace aprofile {
+
+const std::regex version_regex("\\+v(\\d+\\.\\d+)a");
+
+static inline double GetArchVersion(Array<String> mattr) {
+  std::smatch version;
+
+  for (const String& attr : mattr) {
+    std::string attr_string = attr;
+    if (std::regex_match(attr_string, version, version_regex)) {
+      if (version.size() == 2) {
+        return atof(version[1].str().data());
+      }
+    }
+  }
+  return 0.0;
+}
+
+static inline double GetArchVersion(Optional<Array<String>> attr) {
+  if (!attr) {
+    return false;
+  }
+  return GetArchVersion(attr.value());
+}
+
+static inline bool HasFlag(String attr, std::string flag) {
+  std::string attr_str = attr;
+  return attr_str.find(flag) != std::string::npos;
+}
+
+static inline bool HasFlag(Optional<String> attr, std::string flag) {
+  if (!attr) {
+    return false;
+  }
+  return HasFlag(attr.value(), flag);
+}
+
+static inline bool HasFlag(Optional<Array<String>> attr, std::string flag) {
+  if (!attr) {
+    return false;
+  }
+  Array<String> attr_array = attr.value();
+
+  auto matching_attr = std::find_if(attr_array.begin(), attr_array.end(),
+                                    [flag](String attr_str) { return HasFlag(attr_str, flag); });
+  return matching_attr != attr_array.end();
+}
+
+static bool HasFlag(Optional<String> mcpu, Optional<Array<String>> mattr, std::string flag) {
+  return HasFlag(mcpu, flag) || HasFlag(mattr, flag);
+}
+
+bool IsAArch32(Optional<String> mtriple) {
+  if (mtriple) {
+    return support::StartsWith(mtriple.value(), "armv8a") ||
+           support::StartsWith(mtriple.value(), "armv7a");
+  }
+  return false;
+}
+
+bool IsAArch64(Optional<String> mtriple) {
+  if (mtriple) {
+    return support::StartsWith(mtriple.value(), "aarch64");
+  }
+  return false;
+}
+
+bool IsArch(TargetJSON attrs) {
+  Optional<String> mtriple = Downcast<Optional<String>>(attrs.Get("mtriple"));
+
+  return IsAArch32(mtriple) || IsAArch64(mtriple);
+}
+
+static TargetFeatures GetFeatures(TargetJSON target) {
+  Optional<String> mcpu = Downcast<Optional<String>>(target.Get("mcpu"));
+  Optional<String> mtriple = Downcast<Optional<String>>(target.Get("mtriple"));
+  Optional<Array<String>> mattr = Downcast<Optional<Array<String>>>(target.Get("mattr"));
+
+  double arch_version = GetArchVersion(mattr);
+
+  bool is_aarch64 = IsAArch64(mtriple);
+
+  bool simd_flag = HasFlag(mcpu, mattr, "+neon") || HasFlag(mcpu, mattr, "+simd");
+  bool simd_disable = HasFlag(mcpu, mattr, "nosimd");
+  bool has_asimd = (is_aarch64 || simd_flag) && !simd_disable;
+
+  bool i8mm_flag = HasFlag(mcpu, mattr, "+i8mm");
+  bool i8mm_default = arch_version >= 8.6;
+  bool i8mm_support = arch_version >= 8.2 && arch_version <= 8.5;
+  bool has_i8mm = i8mm_default || (i8mm_support && i8mm_flag);

Review Comment:
   Possibly add a noi8mm for v8.6 and above. 



##########
src/target/parsers/aprofile.cc:
##########
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * \file tvm/target/parsers/aprofile.cc
+ * \brief Target Parser for Arm(R) Cortex(R) A-Profile CPUs
+ */
+
+#include "aprofile.h"
+
+#include <regex>
+#include <string>
+
+#include "../../support/utils.h"
+
+namespace tvm {
+namespace target {
+namespace parsers {
+namespace aprofile {
+
+const std::regex version_regex("\\+v(\\d+\\.\\d+)a");
+
+static inline double GetArchVersion(Array<String> mattr) {
+  std::smatch version;
+
+  for (const String& attr : mattr) {
+    std::string attr_string = attr;
+    if (std::regex_match(attr_string, version, version_regex)) {
+      if (version.size() == 2) {
+        return atof(version[1].str().data());
+      }
+    }
+  }
+  return 0.0;
+}
+
+static inline double GetArchVersion(Optional<Array<String>> attr) {
+  if (!attr) {
+    return false;
+  }
+  return GetArchVersion(attr.value());
+}
+
+static inline bool HasFlag(String attr, std::string flag) {
+  std::string attr_str = attr;
+  return attr_str.find(flag) != std::string::npos;
+}
+
+static inline bool HasFlag(Optional<String> attr, std::string flag) {
+  if (!attr) {
+    return false;
+  }
+  return HasFlag(attr.value(), flag);
+}
+
+static inline bool HasFlag(Optional<Array<String>> attr, std::string flag) {
+  if (!attr) {
+    return false;
+  }
+  Array<String> attr_array = attr.value();
+
+  auto matching_attr = std::find_if(attr_array.begin(), attr_array.end(),
+                                    [flag](String attr_str) { return HasFlag(attr_str, flag); });
+  return matching_attr != attr_array.end();
+}
+
+static bool HasFlag(Optional<String> mcpu, Optional<Array<String>> mattr, std::string flag) {
+  return HasFlag(mcpu, flag) || HasFlag(mattr, flag);
+}
+
+bool IsAArch32(Optional<String> mtriple) {
+  if (mtriple) {
+    return support::StartsWith(mtriple.value(), "armv8a") ||
+           support::StartsWith(mtriple.value(), "armv7a");

Review Comment:
   Could this be simplified to be StartsWith(triple.value(), "arm");  ?  Defensively possibly ignore any that have cortex-m in mcpu ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] github-actions[bot] commented on pull request #12454: [Target] Add Target Parser for Arm(R) Cortex(R) A-Profile CPUs

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #12454:
URL: https://github.com/apache/tvm/pull/12454#issuecomment-1224302981

   It has been a while since this PR was updated, @u99127 please leave a review or address the outstanding comments. @Mousius if this PR is still a work in progress, please [convert it to a draft](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-stage-of-a-pull-request#converting-a-pull-request-to-a-draft) until it is ready for review.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] github-actions[bot] commented on pull request #12454: [Target] Add Target Parser for Arm(R) Cortex(R) A-Profile CPUs

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #12454:
URL: https://github.com/apache/tvm/pull/12454#issuecomment-1247876944

   It has been a while since this PR was updated, @u99127 please leave a review or address the outstanding comments. @Mousius if this PR is still a work in progress, please [convert it to a draft](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-stage-of-a-pull-request#converting-a-pull-request-to-a-draft) until it is ready for review.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org