| 157 | } // namespace |
| 158 | |
| 159 | StatusOr<bool> DotDecomposer::Run(HloModule* module) { |
| 160 | XLA_VLOG_LINES(2, "DotDecomposer ENTRY\n" + module->ToString()); |
| 161 | // Gather all Non-canonical Dot operations. |
| 162 | std::vector<HloInstruction*> non_canonical_dots; |
| 163 | for (auto* computation : module->MakeNonfusionComputations()) { |
| 164 | for (auto* instruction : computation->instructions()) { |
| 165 | if (instruction->opcode() != HloOpcode::kDot) { |
| 166 | continue; |
| 167 | } |
| 168 | const DotDimensionNumbers& dnums = instruction->dot_dimension_numbers(); |
| 169 | // A dot it not canonical if there are more than one contracting |
| 170 | // dimension. |
| 171 | if (dnums.lhs_contracting_dimensions_size() != 1) { |
| 172 | non_canonical_dots.push_back(instruction); |
| 173 | continue; |
| 174 | } |
| 175 | // A dot is not canonical if it has more than one non-contracting |
| 176 | // dimension. |
| 177 | if (dnums.lhs_batch_dimensions_size() + 2 != |
| 178 | instruction->operand(0)->shape().rank() || |
| 179 | dnums.rhs_batch_dimensions_size() + 2 != |
| 180 | instruction->operand(1)->shape().rank()) { |
| 181 | non_canonical_dots.push_back(instruction); |
| 182 | continue; |
| 183 | } |
| 184 | if (dnums.lhs_batch_dimensions().empty() && |
| 185 | dnums.lhs_contracting_dimensions().empty()) { |
| 186 | non_canonical_dots.push_back(instruction); |
| 187 | continue; |
| 188 | } |
| 189 | if (dnums.lhs_batch_dimensions().empty()) { |
| 190 | continue; |
| 191 | } |
| 192 | std::vector<int64> canonical_batch_dims( |
| 193 | dnums.lhs_batch_dimensions_size()); |
| 194 | absl::c_iota(canonical_batch_dims, 0); |
| 195 | if (!absl::c_equal(dnums.lhs_batch_dimensions(), canonical_batch_dims) || |
| 196 | !absl::c_equal(dnums.rhs_batch_dimensions(), canonical_batch_dims)) { |
| 197 | non_canonical_dots.push_back(instruction); |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | bool changed = false; |
| 202 | for (auto* dot : non_canonical_dots) { |
| 203 | TF_RETURN_IF_ERROR(CanonicalizeDot(dot)); |
| 204 | changed = true; |
| 205 | } |
| 206 | XLA_VLOG_LINES(2, "DotDecompose EXIT\n" + module->ToString()); |
| 207 | return changed; |
| 208 | } |
| 209 | |
| 210 | } // namespace xla |
nothing calls this directly
no test coverage detected