| 48 | } |
| 49 | |
| 50 | ThunkSchedule::ThunkSchedule( |
| 51 | std::unique_ptr<ThunkSequence> thunks, |
| 52 | std::unique_ptr<StreamAssignment> stream_assignment, |
| 53 | const std::vector<HloInstruction*>& hlo_total_order) |
| 54 | : thunks_(std::move(thunks)), |
| 55 | stream_assignment_(std::move(stream_assignment)) { |
| 56 | absl::flat_hash_map<const HloInstruction*, Thunk*> hlo_to_thunk; |
| 57 | for (const auto& thunk : *thunks_) { |
| 58 | InsertOrDie(&hlo_to_thunk, thunk->hlo_instruction(), thunk.get()); |
| 59 | } |
| 60 | |
| 61 | for (HloInstruction* hlo : hlo_total_order) { |
| 62 | if (Thunk** thunk = tensorflow::gtl::FindOrNull(hlo_to_thunk, hlo)) { |
| 63 | thunk_total_order_.push_back(*thunk); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | for (const Thunk* thunk : thunk_total_order_) { |
| 68 | const auto* dst = thunk->hlo_instruction(); |
| 69 | CHECK(stream_assignment_->HasStreamAssigned(*dst)); |
| 70 | for (const auto* src : dst->operands()) { |
| 71 | AddDependenciesOnTransitiveOperands(*thunk, *src, hlo_to_thunk); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | RemoveRedundantDependencyEdges(); |
| 76 | |
| 77 | // Compute `depended_by_`, the inverse of `depends_on_`. |
| 78 | for (const auto& dependency : depends_on_) { |
| 79 | for (const auto* depended : dependency.second) { |
| 80 | depended_by_.insert(depended); |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | void ThunkSchedule::RemoveRedundantDependencyEdges() { |
| 86 | std::unordered_map<const Thunk*, int> thunk_to_total_order; |
nothing calls this directly
no test coverage detected