Encapsulates the tensor value inside a vector of Event protos. Large tensors are broken up to multiple protos to fit the chunk_size_limit. In each Event proto the field summary.tensor carries the content of the tensor. If chunk_size_limit <= 0, the tensor will not be broken into chunks, i.e., a length-1 vector will be returned, regardless of the size of the tensor.
| 186 | // If chunk_size_limit <= 0, the tensor will not be broken into chunks, i.e., a |
| 187 | // length-1 vector will be returned, regardless of the size of the tensor. |
| 188 | Status WrapTensorAsEvents(const DebugNodeKey& debug_node_key, |
| 189 | const Tensor& tensor, const uint64 wall_time_us, |
| 190 | const size_t chunk_size_limit, |
| 191 | std::vector<Event>* events) { |
| 192 | TensorProto tensor_proto; |
| 193 | if (tensor.dtype() == DT_STRING) { |
| 194 | // Treat DT_STRING specially, so that tensor_util.MakeNdarray in Python can |
| 195 | // convert the TensorProto to string-type numpy array. MakeNdarray does not |
| 196 | // work with strings encoded by AsProtoTensorContent() in tensor_content. |
| 197 | tensor.AsProtoField(&tensor_proto); |
| 198 | |
| 199 | TF_RETURN_IF_ERROR(WrapStringTensorAsEvents( |
| 200 | debug_node_key, wall_time_us, chunk_size_limit, &tensor_proto, events)); |
| 201 | } else { |
| 202 | tensor.AsProtoTensorContent(&tensor_proto); |
| 203 | |
| 204 | const size_t total_length = tensor_proto.tensor_content().size(); |
| 205 | const size_t chunk_size_ub = |
| 206 | chunk_size_limit > 0 ? chunk_size_limit : total_length; |
| 207 | const size_t num_chunks = |
| 208 | (total_length == 0) |
| 209 | ? 1 |
| 210 | : (total_length + chunk_size_ub - 1) / chunk_size_ub; |
| 211 | for (size_t i = 0; i < num_chunks; ++i) { |
| 212 | const size_t pos = i * chunk_size_ub; |
| 213 | const size_t len = |
| 214 | (i == num_chunks - 1) ? (total_length - pos) : chunk_size_ub; |
| 215 | Event event = PrepareChunkEventProto(debug_node_key, wall_time_us, |
| 216 | num_chunks, i, tensor_proto.dtype(), |
| 217 | tensor_proto.tensor_shape()); |
| 218 | event.mutable_summary() |
| 219 | ->mutable_value(0) |
| 220 | ->mutable_tensor() |
| 221 | ->set_tensor_content(tensor_proto.tensor_content().substr(pos, len)); |
| 222 | events->push_back(std::move(event)); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | return Status::OK(); |
| 227 | } |
| 228 | |
| 229 | // Appends an underscore and a timestamp to a file path. If the path already |
| 230 | // exists on the file system, append a hyphen and a 1-up index. Consecutive |
no test coverage detected