tensorflow/core/tpu/kernels/tpu_execute_op.cc
// Creates a VariableUpdateMap from both the compilation and the fused variable
// reads/updates.
Creates a VariableUpdateMap from both the compilation and the fused variable
reads/updates.
Creates a VariableUpdateMap from both the compilation and the fused variable reads / updates .
xla::StatusOr<VariableUpdateMap> BuildVariableUpdateMap(
    absl::Span<const TPUExecutableInfoProto::UpdateIndexPair* const>
        compiled_variable_updates,
    absl::Span<int const> fused_device_var_reads_in_computation_inputs,
    const std::vector<int>& fused_device_var_updates_in_computation_outputs,
    int64_t computation_output_count) {
  VariableUpdateMap map;
  auto add_pair = [&](int input, int output, bool from_compilation) -> Status {
    TF_RET_CHECK(map.input_to_output.emplace(input, output).second)
        << "Duplicate variable input index: " << input;
    if (output >= 0) {
      TF_RET_CHECK(map.output_to_input
                       .emplace(output, std::make_pair(input, from_compilation))
                       .second)
          << "Duplicate variable output index: " << output;
    }
    return Status::OK();
  };
  int num_updated_variables = 0;
  for (int i = 0; i < compiled_variable_updates.size(); ++i) {
    const bool updated = compiled_variable_updates[i]->updated();
    if (updated) ++num_updated_variables;
  }
  TF_RET_CHECK(num_updated_variables <= computation_output_count)
      << num_updated_variables << " <= " << computation_output_count;
  int64_t compiled_variable_output_index =
      computation_output_count - num_updated_variables;
  for (auto update : compiled_variable_updates) {
    map.input_in_compiled_update_order.push_back(update->index());
    if (!update->updated()) {
      TF_RETURN_IF_ERROR(add_pair(update->index(), -1, true));
      continue;
    }
    TF_RETURN_IF_ERROR(
        add_pair(update->index(), compiled_variable_output_index, true));
    ++compiled_variable_output_index;
  }
  TF_RET_CHECK(fused_device_var_reads_in_computation_inputs.size() ==
               fused_device_var_updates_in_computation_outputs.size());
  for (int64_t i = 0; i < fused_device_var_reads_in_computation_inputs.size();
       ++i) {
    TF_RETURN_IF_ERROR(
        add_pair(fused_device_var_reads_in_computation_inputs[i],
                 fused_device_var_updates_in_computation_outputs[i], false));
  }
  return map;
}
xla :: StatusOr < VariableUpdateMap > BuildVariableUpdateMap ( absl :: Span < const TPUExecutableInfoProto :: UpdateIndexPair * const > compiled_variable_updates , absl :: Span < int const > fused_device_var_reads_in_computation_inputs , const std :: vector < int > & fused_device_var_updates_in_computation_outputs , int64_t computation_output_count ) { VariableUpdateMap map ; auto add_pair = [ & ] ( int input , int output , bool from_compilation ) -> Status { TF_RET_CHECK ( map . input_to_output . emplace ( input , output ) . second ) << " " << input ; if ( output >= 0 ) { TF_RET_CHECK ( map . output_to_input . emplace ( output , std :: make_pair ( input , from_compilation ) ) . second ) << " " << output ; } return Status :: OK ( ) ; } ; int num_updated_variables = 0 ; for ( int i = 0 ; i < compiled_variable_updates . size ( ) ; ++ i ) { const bool updated = compiled_variable_updates [ i ] -> updated ( ) ; if ( updated ) ++ num_updated_variables ; } TF_RET_CHECK ( num_updated_variables <= computation_output_count ) << num_updated_variables << " " << computation_output_count ; int64_t compiled_variable_output_index = computation_output_count - num_updated_variables ; for ( auto update : compiled_variable_updates ) { map . input_in_compiled_update_order . push_back ( update -> index ( ) ) ; if ( ! update -> updated ( ) ) { TF_RETURN_IF_ERROR ( add_pair ( update -> index ( ) , -1 , true ) ) ; continue ; } TF_RETURN_IF_ERROR ( add_pair ( update -> index ( ) , compiled_variable_output_index , true ) ) ; ++ compiled_variable_output_index ; } TF_RET_CHECK ( fused_device_var_reads_in_computation_inputs . size ( ) == fused_device_var_updates_in_computation_outputs . size ( ) ) ; for ( int64_t i = 0 ; i < fused_device_var_reads_in_computation_inputs . size ( ) ; ++ i ) { TF_RETURN_IF_ERROR ( add_pair ( fused_device_var_reads_in_computation_inputs [ i ] , fused_device_var_updates_in_computation_outputs [ i ] , false ) ) ; } return map ; }
Creates a VariableUpdateMap from both the compilation and the fused variable
reads/updates.
Creates a VariableUpdateMap from both the compilation and the fused variable reads / updates .
// First add the updates produced by the compilation. Not all variables are // updated, and if not, they do not have an output in the XLA computation. The // update output indices in the XLA computation start after the non-variable // outputs. // Now add the updates from the attributes.