| 118 | } |
| 119 | |
| 120 | uint64 HashNodeDef(const NodeDef& node) { |
| 121 | uint64 hash = Hash64String(node.op()); |
| 122 | hash = Hash64Combine(hash, Hash64String(node.name())); |
| 123 | for (const string& input : node.input()) { |
| 124 | hash = Hash64Combine(hash, Hash64String(CanonicalInputName(input))); |
| 125 | } |
| 126 | hash = Hash64Combine(hash, Hash64String(node.device())); |
| 127 | std::vector<string> attr_names; |
| 128 | attr_names.reserve(node.attr().size()); |
| 129 | for (const auto& attr : node.attr()) { |
| 130 | attr_names.push_back(attr.first); |
| 131 | } |
| 132 | std::sort(attr_names.begin(), attr_names.end()); |
| 133 | string attr_serialized; |
| 134 | for (const string& attr_name : attr_names) { |
| 135 | auto attr = node.attr().at(attr_name); |
| 136 | attr.SerializeToString(&attr_serialized); |
| 137 | hash = Hash64Combine(hash, Hash64String(attr_serialized)); |
| 138 | } |
| 139 | return hash; |
| 140 | } |
| 141 | |
| 142 | void AddNodeInput(const string& input_name, NodeDef* node) { |
| 143 | *(node->mutable_input()->Add()) = input_name; |