tensorflow/core/debug/debug_io_utils.cc
// Breaks a string Tensor (represented as a TensorProto) as a vector of Event
// protos.
Breaks a string Tensor (represented as a TensorProto) as a vector of Event
protos.
Breaks a string Tensor ( represented as a TensorProto ) as a vector of Event protos .
Status WrapStringTensorAsEvents(const DebugNodeKey& debug_node_key,
                                const uint64 wall_time_us,
                                const size_t chunk_size_limit,
                                TensorProto* tensor_proto,
                                std::vector<Event>* events) {
  const protobuf::RepeatedPtrField<string>& strs = tensor_proto->string_val();
  const size_t num_strs = strs.size();
  const size_t chunk_size_ub = chunk_size_limit > 0
                                   ? chunk_size_limit
                                   : std::numeric_limits<size_t>::max();
  std::vector<size_t> cutoffs;
  size_t chunk_size = 0;
  for (size_t i = 0; i < num_strs; ++i) {
    if (StringValMaxBytesInProto(strs[i]) > chunk_size_ub) {
      return errors::FailedPrecondition(
          "string value at index ", i, " from debug node ",
          debug_node_key.debug_node_name,
          " does not fit gRPC message size limit (", chunk_size_ub, ")");
    }
    if (chunk_size + StringValMaxBytesInProto(strs[i]) > chunk_size_ub) {
      cutoffs.push_back(i);
      chunk_size = 0;
    }
    chunk_size += StringValMaxBytesInProto(strs[i]);
  }
  cutoffs.push_back(num_strs);
  const size_t num_chunks = cutoffs.size();
  for (size_t i = 0; i < num_chunks; ++i) {
    Event event = PrepareChunkEventProto(debug_node_key, wall_time_us,
                                         num_chunks, i, tensor_proto->dtype(),
                                         tensor_proto->tensor_shape());
    Summary::Value* value = event.mutable_summary()->mutable_value(0);
    if (cutoffs.size() == 1) {
      value->mutable_tensor()->mutable_string_val()->Swap(
          tensor_proto->mutable_string_val());
    } else {
      const size_t begin = (i == 0) ? 0 : cutoffs[i - 1];
      const size_t end = cutoffs[i];
      for (size_t j = begin; j < end; ++j) {
        value->mutable_tensor()->add_string_val(strs[j]);
      }
    }
    events->push_back(std::move(event));
  }
  return Status::OK();
}
Status WrapStringTensorAsEvents ( const DebugNodeKey & debug_node_key , const uint64 wall_time_us , const size_t chunk_size_limit , TensorProto * tensor_proto , std :: vector < Event > * events ) { const protobuf :: RepeatedPtrField < string > & strs = tensor_proto -> string_val ( ) ; const size_t num_strs = strs . size ( ) ; const size_t chunk_size_ub = chunk_size_limit > 0 ? chunk_size_limit : std :: numeric_limits < size_t > :: max ( ) ; std :: vector < size_t > cutoffs ; size_t chunk_size = 0 ; for ( size_t i = 0 ; i < num_strs ; ++ i ) { if ( StringValMaxBytesInProto ( strs [ i ] ) > chunk_size_ub ) { return errors :: FailedPrecondition ( " " , i , " " , debug_node_key . debug_node_name , " " , chunk_size_ub , " " ) ; } if ( chunk_size + StringValMaxBytesInProto ( strs [ i ] ) > chunk_size_ub ) { cutoffs . push_back ( i ) ; chunk_size = 0 ; } chunk_size += StringValMaxBytesInProto ( strs [ i ] ) ; } cutoffs . push_back ( num_strs ) ; const size_t num_chunks = cutoffs . size ( ) ; for ( size_t i = 0 ; i < num_chunks ; ++ i ) { Event event = PrepareChunkEventProto ( debug_node_key , wall_time_us , num_chunks , i , tensor_proto -> dtype ( ) , tensor_proto -> tensor_shape ( ) ) ; Summary :: Value * value = event . mutable_summary ( ) -> mutable_value ( 0 ) ; if ( cutoffs . size ( ) == 1 ) { value -> mutable_tensor ( ) -> mutable_string_val ( ) -> Swap ( tensor_proto -> mutable_string_val ( ) ) ; } else { const size_t begin = ( i == 0 ) ? 0 : cutoffs [ i - 1 ] ; const size_t end = cutoffs [ i ] ; for ( size_t j = begin ; j < end ; ++ j ) { value -> mutable_tensor ( ) -> add_string_val ( strs [ j ] ) ; } } events -> push_back ( std :: move ( event ) ) ; } return Status :: OK ( ) ; }
Breaks a string Tensor (represented as a TensorProto) as a vector of Event
protos.
Breaks a string Tensor ( represented as a TensorProto ) as a vector of Event protos .
// E.g., if cutoffs is {j, k, l}, the chunks will have index ranges: //   [0:a), [a:b), [c:<end>]. // Take into account the extra bytes in proto buffer.