MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / VerifyHloStructure

Function VerifyHloStructure

tensorflow/compiler/xla/service/hlo_verifier.cc:1233–1277  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

1231// (3) the operands of each instruction are in the same computation as the
1232// instruction.
1233Status 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
1279namespace {
1280

Callers 1

RunMethod · 0.85

Calls 7

computationsMethod · 0.80
instructionsMethod · 0.80
operand_countMethod · 0.80
nameMethod · 0.65
InternalErrorFunction · 0.50
parentMethod · 0.45
operandMethod · 0.45

Tested by

no test coverage detected