Verifies various invariants about the structure of the HLO: (1) each instruction has a non-null parent() set to the HloComputation which contains it. (2) each computation has a non-null parent() set to the HloModule which contains it. (3) the operands of each instruction are in the same computation as the instruction.
| 1231 | // (3) the operands of each instruction are in the same computation as the |
| 1232 | // instruction. |
| 1233 | Status VerifyHloStructure(HloModule* module) { |
| 1234 | for (const HloComputation* computation : module->computations()) { |
| 1235 | if (computation->parent() == nullptr) { |
| 1236 | return InternalError("Computation %s has a null parent pointer", |
| 1237 | computation->name()); |
| 1238 | } |
| 1239 | if (computation->parent() != module) { |
| 1240 | return InternalError( |
| 1241 | "Computation %s parent() does not point to parent module", |
| 1242 | computation->name()); |
| 1243 | } |
| 1244 | |
| 1245 | for (const HloInstruction* instruction : computation->instructions()) { |
| 1246 | if (instruction->parent() == nullptr) { |
| 1247 | return InternalError("Instruction %s has a null parent pointer", |
| 1248 | instruction->name()); |
| 1249 | } |
| 1250 | if (instruction->parent() != computation) { |
| 1251 | return InternalError( |
| 1252 | "Instruction %s parent() does not point to parent computation", |
| 1253 | instruction->name()); |
| 1254 | } |
| 1255 | } |
| 1256 | } |
| 1257 | |
| 1258 | // Check that operands are in the same computation separately from verifying |
| 1259 | // parent() correctness so conditions like a null HloInstruction::parent() |
| 1260 | // are identified and reported explicitly above rather than reporting a |
| 1261 | // mismatched operand. |
| 1262 | for (const HloComputation* computation : module->computations()) { |
| 1263 | for (const HloInstruction* instruction : computation->instructions()) { |
| 1264 | for (int i = 0; i < instruction->operand_count(); ++i) { |
| 1265 | const HloInstruction* operand = instruction->operand(i); |
| 1266 | if (operand->parent() != instruction->parent()) { |
| 1267 | return InternalError( |
| 1268 | "Operand %d (%s) of instruction %s is in a different " |
| 1269 | "computation: %s vs %s", |
| 1270 | i, operand->name(), instruction->name(), |
| 1271 | operand->parent()->name(), instruction->parent()->name()); |
| 1272 | } |
| 1273 | } |
| 1274 | } |
| 1275 | } |
| 1276 | return Status::OK(); |
| 1277 | } |
| 1278 | |
| 1279 | namespace { |
| 1280 |
no test coverage detected