| 147 | } |
| 148 | |
| 149 | string ThunkSchedule::ToString() const { |
| 150 | if (thunk_total_order_.empty()) { |
| 151 | return "No thunks."; |
| 152 | } |
| 153 | |
| 154 | const Thunk* thunk_with_longest_kind = *absl::c_max_element( |
| 155 | thunk_total_order_, [](const Thunk* a, const Thunk* b) { |
| 156 | return ThunkKindToString(a->kind()).length() < |
| 157 | ThunkKindToString(b->kind()).length(); |
| 158 | }); |
| 159 | int64 max_thunk_kind_len = |
| 160 | ThunkKindToString(thunk_with_longest_kind->kind()).length(); |
| 161 | |
| 162 | string result = "Total order:\n"; |
| 163 | for (Thunk* thunk : thunk_total_order_) { |
| 164 | // Write out the thunk kind, padded out to max_thunk_kind_len. |
| 165 | absl::string_view kind_str = ThunkKindToString(thunk->kind()); |
| 166 | absl::StrAppend(&result, kind_str, |
| 167 | string(max_thunk_kind_len - kind_str.length(), ' '), "\t"); |
| 168 | if (thunk->hlo_instruction() != nullptr) { |
| 169 | absl::StrAppend(&result, thunk->hlo_instruction()->ToString()); |
| 170 | } else { |
| 171 | absl::StrAppend(&result, "(no HloInstruction)"); |
| 172 | } |
| 173 | absl::StrAppend(&result, "\n"); |
| 174 | } |
| 175 | absl::StrAppend(&result, "\nDependencies:\n"); |
| 176 | for (const auto& entry : depends_on_) { |
| 177 | const Thunk* dependent = entry.first; |
| 178 | for (const Thunk* dependency : entry.second) { |
| 179 | absl::StrAppend(&result, "\t", dependent->hlo_instruction()->name(), |
| 180 | " depends on ", dependency->hlo_instruction()->name(), |
| 181 | "\n"); |
| 182 | } |
| 183 | } |
| 184 | return result; |
| 185 | } |
| 186 | |
| 187 | } // namespace gpu |
| 188 | } // namespace xla |