| 198 | } |
| 199 | |
| 200 | Status HloSchedule::Update() { |
| 201 | // The schedule must contain a sequence for every non-fusion computation in |
| 202 | // the module, but can have sequences for computations which no longer exist |
| 203 | // (these are removed). |
| 204 | std::vector<HloComputation*> nonfusion_computations = |
| 205 | module_->MakeNonfusionComputations(); |
| 206 | for (const HloComputation* computation : nonfusion_computations) { |
| 207 | TF_RET_CHECK(sequences_.contains(computation->unique_id())) |
| 208 | << "Computation " << computation->name() << " not in HloSchedule."; |
| 209 | } |
| 210 | if (sequences_.size() > nonfusion_computations.size()) { |
| 211 | // Schedule contains some computations which have been removed from the |
| 212 | // HloModule. Remove them from the schedule as well. |
| 213 | absl::flat_hash_set<int64> nonfusion_computations_ids; |
| 214 | for (const HloComputation* computation : nonfusion_computations) { |
| 215 | nonfusion_computations_ids.insert(computation->unique_id()); |
| 216 | } |
| 217 | for (auto it = sequences_.begin(); it != sequences_.end();) { |
| 218 | if (!nonfusion_computations_ids.contains(it->first)) { |
| 219 | sequences_.erase(it++); |
| 220 | } else { |
| 221 | ++it; |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | CHECK_EQ(sequences_.size(), nonfusion_computations.size()); |
| 226 | |
| 227 | for (const HloComputation* computation : nonfusion_computations) { |
| 228 | TF_RETURN_IF_ERROR(UpdateComputationSchedule(computation)); |
| 229 | } |
| 230 | |
| 231 | TF_RETURN_IF_ERROR(Verify()); |
| 232 | return Status::OK(); |
| 233 | } |
| 234 | |
| 235 | Status HloSchedule::Verify() const { |
| 236 | VLOG(2) << "VerifySchedule()"; |