tensorflow/compiler/xla/service/hlo_proto_util.cc
// Returns the parameters of the given computation. Parameter numbers are
// checked for validity and contiguousness.
Returns the parameters of the given computation. Parameter numbers are
checked for validity and contiguousness.
Returns the parameters of the given computation . Parameter numbers are checked for validity and contiguousness .
StatusOr<std::vector<const HloInstructionProto*>> GetParameters(
    const HloComputationProto& computation) {
  std::vector<const HloInstructionProto*> parameters;
  for (const HloInstructionProto& instruction : computation.instructions()) {
    if (instruction.opcode() == HloOpcodeString(HloOpcode::kParameter)) {
      parameters.push_back(&instruction);
    }
  }
  tensorflow::gtl::FlatSet<int64> parameter_numbers;
  for (const HloInstructionProto* parameter : parameters) {
    if (parameter->parameter_number() < 0 ||
        parameter->parameter_number() >= parameters.size()) {
      return InvalidArgument(
          "Parameter instruction %s has invalid parameter number %lld.",
          parameter->name().c_str(), parameter->parameter_number());
    }
    if (parameter_numbers.count(parameter->parameter_number()) != 0) {
      return InvalidArgument(
          "Multiple parameter instructions have parameter number %lld.",
          parameter->parameter_number());
    }
    parameter_numbers.insert(parameter->parameter_number());
  }
  std::sort(parameters.begin(), parameters.end(),
            [](const HloInstructionProto* a, const HloInstructionProto* b) {
              return a->parameter_number() < b->parameter_number();
            });
  return parameters;
}
StatusOr < std :: vector < const HloInstructionProto * > > GetParameters ( const HloComputationProto & computation ) { std :: vector < const HloInstructionProto * > parameters ; for ( const HloInstructionProto & instruction : computation . instructions ( ) ) { if ( instruction . opcode ( ) == HloOpcodeString ( HloOpcode :: kParameter ) ) { parameters . push_back ( & instruction ) ; } } tensorflow :: gtl :: FlatSet < int64 > parameter_numbers ; for ( const HloInstructionProto * parameter : parameters ) { if ( parameter -> parameter_number ( ) < 0 || parameter -> parameter_number ( ) >= parameters . size ( ) ) { return InvalidArgument ( " " , parameter -> name ( ) . c_str ( ) , parameter -> parameter_number ( ) ) ; } if ( parameter_numbers . count ( parameter -> parameter_number ( ) ) != 0 ) { return InvalidArgument ( " " , parameter -> parameter_number ( ) ) ; } parameter_numbers . insert ( parameter -> parameter_number ( ) ) ; } std :: sort ( parameters . begin ( ) , parameters . end ( ) , [ ] ( const HloInstructionProto * a , const HloInstructionProto * b ) { return a -> parameter_number ( ) < b -> parameter_number ( ) ; } ) ; return parameters ; }
Returns the parameters of the given computation.
Returns the parameters of the given computation .
// Verify the uniqueness and validity of the parameter numbers.