mbs-octoml commented on a change in pull request #9313:
URL: https://github.com/apache/tvm/pull/9313#discussion_r741539128
##########
File path: src/target/target.cc
##########
@@ -531,6 +531,88 @@ Optional<Target> TargetNode::GetHost() const {
return GetRef<Optional<Target>>(this->host.as<TargetNode>());
}
+bool TargetNode::SEqualReduce(const TargetNode* other, SEqualReducer equal)
const {
+ // Object identity for kinds.
+ if (kind != other->kind) {
+ VLOG(1) << "targets disagree on kinds";
+ return false;
+ }
+ // Structural equality for (optional) host.
+ if (host.defined() != other->host.defined()) {
+ VLOG(1) << "targets disagree on having hosts: " << host.defined() << " vs "
+ << other->host.defined();
+ return false;
+ }
+ if (host.defined() &&
+
!host.value().as<TargetNode>()->SEqualReduce(other->host.value().as<TargetNode>(),
equal)) {
+ VLOG(1) << "targets disagree on hosts";
+ return false;
+ }
+ if (tag != other->tag) {
+ VLOG(1) << "targets disagree on tags: '" << tag << "' vs '" << other->tag
<< "'";
+ return false;
+ }
+ // Array (not set) equality for keys.
+ if (keys.size() != other->keys.size()) {
+ VLOG(1) << "targets disagree on number of keys";
+ return false;
+ }
+ for (size_t i = 0; i < keys.size(); ++i) {
+ if (keys[i] != other->keys[i]) {
+ VLOG(1) << "targets disagree on key " << i << ": '" << keys[i] << "' vs
'" << other->keys[i]
+ << "'";
+ return false;
+ }
+ }
+ // Map equality for attributes.
+ if (attrs.size() != other->attrs.size()) {
+ VLOG(1) << "targets disagree on number of attributes";
+ return false;
+ }
+ if (!std::all_of(attrs.begin(), attrs.end(), [other](const std::pair<String,
ObjectRef>& pair) {
+ if (other->attrs.count(pair.first) == 0) {
+ VLOG(1) << "targets disagree on attribute for '" << pair.first <<
"': missing in other";
+ return false;
+ }
+ // Object/string identity for attribute values
+ if (!ObjectEqual()(pair.second, other->attrs[pair.first])) {
+ VLOG(1) << "targets disagree on attribute for '" << pair.first <<
"': " << pair.second
+ << " vs " << other->attrs[pair.first];
+ return false;
+ }
+ return true;
+ })) {
+ return false;
+ }
+ return true;
+}
+
+void TargetNode::SHashReduce(SHashReducer hash_reduce) const {
+ // Object identity for kinds.
+ hash_reduce(kind.get());
+ if (host.defined()) {
Review comment:
Ah, I only just groked Optional is just an ObjectRef without an
accompanying OptionalNode, so no need to worry Optional<T> won't use T's
eq/hash.
--
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]