| 234 | } |
| 235 | |
| 236 | uint64 NodeDefHash(const NodeDef& ndef, const EqualGraphDefOptions& options) { |
| 237 | uint64 h = Hash64(ndef.name()); |
| 238 | h = Hash64(ndef.op().data(), ndef.op().size(), h); |
| 239 | h = Hash64(ndef.device().data(), ndef.device().size(), h); |
| 240 | |
| 241 | // Normal inputs. Order important. |
| 242 | int first_control_input = ndef.input_size(); |
| 243 | for (int i = 0; i < ndef.input_size(); ++i) { |
| 244 | if (absl::StartsWith(ndef.input(i), "^")) { |
| 245 | first_control_input = i; |
| 246 | break; |
| 247 | } |
| 248 | h = Hash64(ndef.input(i).data(), ndef.input(i).size(), h); |
| 249 | } |
| 250 | |
| 251 | // Control inputs. Order irrelevant. |
| 252 | std::set<string> ndef_control; |
| 253 | for (int i = first_control_input; i < ndef.input_size(); ++i) { |
| 254 | ndef_control.insert(ndef.input(i)); |
| 255 | } |
| 256 | for (const string& s : ndef_control) { |
| 257 | h = Hash64(s.data(), s.size(), h); |
| 258 | } |
| 259 | |
| 260 | // Attributes |
| 261 | std::map<string, AttrValue> ndef_attr; |
| 262 | for (const auto& a : ndef.attr()) { |
| 263 | if (options.ignore_internal_attrs && !a.first.empty() && |
| 264 | a.first[0] == '_') { |
| 265 | continue; |
| 266 | } |
| 267 | ndef_attr[a.first] = a.second; |
| 268 | } |
| 269 | for (const auto& a : ndef_attr) { |
| 270 | h = Hash64(a.first.data(), a.first.size(), h); |
| 271 | h = Hash64Combine(AttrValueHash(a.second), h); |
| 272 | } |
| 273 | |
| 274 | return h; |
| 275 | } |
| 276 | |
| 277 | } // namespace tensorflow |
no test coverage detected