From dabcb60bc943946f19a6af1fb13415f958053e43 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Thu, 6 Jul 2017 15:04:41 -0700 Subject: [PATCH] [XLA] Add reasonable error messages to Builder::Build for bad parameter numbers. PiperOrigin-RevId: 161136262 --- tensorflow/compiler/xla/service/hlo_computation.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tensorflow/compiler/xla/service/hlo_computation.cc b/tensorflow/compiler/xla/service/hlo_computation.cc index fef6cfc95a0..6a5533c4696 100644 --- a/tensorflow/compiler/xla/service/hlo_computation.cc +++ b/tensorflow/compiler/xla/service/hlo_computation.cc @@ -73,15 +73,19 @@ HloComputation::HloComputation( for (auto& instruction : *instructions) { if (instruction->opcode() == HloOpcode::kParameter) { int64 param_no = instruction->parameter_number(); - CHECK_GE(param_no, 0); - CHECK_LT(param_no, param_instructions_.size()); - CHECK_EQ(nullptr, param_instructions_[param_no]); + CHECK(param_no >= 0 && param_no < parameter_count) + << "\nERROR: invalid parameter number. Expected [0, " + << parameter_count << "), got " << param_no; + CHECK(param_instructions_[param_no] == nullptr) + << "\nERROR: parameter number " << param_no + << " already allocated in this computation"; param_instructions_[param_no] = instruction.get(); } root_found |= instruction.get() == root_instruction_; AddInstructionInternal(std::move(instruction)); } - CHECK(root_found); + CHECK(root_found) + << "\nERROR: root instruction is not present in computation."; } HloInstruction* HloComputation::AddInstruction(