| 309 | } // namespace |
| 310 | |
| 311 | string HloSchedule::ToString() const { |
| 312 | std::vector<string> pieces; |
| 313 | |
| 314 | pieces.push_back("HloSchedule"); |
| 315 | for (const auto& id_sequence : sequences_) { |
| 316 | const HloComputation* computation = |
| 317 | IdToComputation(module_, id_sequence.first); |
| 318 | if (computation == nullptr) { |
| 319 | // The computation is not in the module and may have been deleted so it is |
| 320 | // not safe to dereference any HLO pointers. Just use the HLO unique ids |
| 321 | // stored in this object. |
| 322 | pieces.push_back( |
| 323 | absl::StrFormat("computation with id %d (no longer in HLO module):", |
| 324 | id_sequence.first)); |
| 325 | for (int id : id_sequence.second.ids()) { |
| 326 | pieces.push_back(absl::StrCat(" ", id)); |
| 327 | } |
| 328 | } else { |
| 329 | pieces.push_back(absl::StrFormat("computation %s:", computation->name())); |
| 330 | for (const HloInstruction* instruction : |
| 331 | id_sequence.second.instructions()) { |
| 332 | pieces.push_back(absl::StrCat(" ", instruction->name())); |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | return absl::StrJoin(pieces, "\n"); |
| 337 | } |
| 338 | |
| 339 | std::ostream& operator<<(std::ostream& out, const HloSchedule& schedule) { |
| 340 | out << schedule.ToString(); |
no test coverage detected