1 /* Copyright 2016 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_RPC_GRPC_TENSOR_CODING_H_ 17 #define TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_RPC_GRPC_TENSOR_CODING_H_ 18 19 #include "grpcpp/impl/codegen/byte_buffer.h" 20 21 namespace tensorflow { 22 class Tensor; 23 class RecvTensorResponse; 24 25 // TODO(jeff,sanjay): this should not be grpc specific. Instead of 26 // grpc::ByteBuffer*, it should accept an object of an interface type 27 // to which owned byte-arrays can be added. 28 namespace grpc { 29 30 // Encode a RecvTensorResponse protocol buffer into a byte buffer in a 31 // format that is parseable as a RecvTensorResponse protocol buffer 32 // holding "proto". 33 // 34 // Discards original contents of *result. 35 void EncodeRecvTensorResponseToByteBuffer(const RecvTensorResponse& proto, 36 ::grpc::ByteBuffer* result); 37 38 // Encode a Tensor into a byte buffer in a format that is parseable 39 // as a RecvTensorResponse protocol buffer holding "val". 40 // 41 // "is_dead" is the value to encode for "RecvTensorResponse::is_dead" 42 // (tensor is the output of a dead node and content is invalid because 43 // control flow operations elsewhere caused the path on which this 44 // Tensor exists to not be taken). 45 // 46 // "val" holds the tensor value to be encoded. 47 // 48 // Discards original contents of *result. 49 void EncodeTensorToByteBuffer(bool is_dead, const Tensor& val, 50 ::grpc::ByteBuffer* result); 51 52 } // namespace grpc 53 } // namespace tensorflow 54 55 #endif // TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_RPC_GRPC_TENSOR_CODING_H_ 56