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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to