MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / MessageToBuffer

Function MessageToBuffer

tensorflow/c/c_api.cc:217–239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

215
216
217Status MessageToBuffer(const tensorflow::protobuf::MessageLite& in,
218 TF_Buffer* out) {
219 if (out->data != nullptr) {
220 return InvalidArgument("Passing non-empty TF_Buffer is invalid.");
221 }
222 const size_t proto_size = in.ByteSizeLong();
223 void* buf = port::Malloc(proto_size);
224 if (buf == nullptr) {
225 return tensorflow::errors::ResourceExhausted(
226 "Failed to allocate memory to serialize message of type '",
227 in.GetTypeName(), "' and size ", proto_size);
228 }
229 if (!in.SerializeWithCachedSizesToArray(static_cast<uint8*>(buf))) {
230 port::Free(buf);
231 return InvalidArgument("Unable to serialize ", in.GetTypeName(),
232 " protocol buffer, perhaps the serialized size (",
233 proto_size, " bytes) is too large?");
234 }
235 out->data = buf;
236 out->length = proto_size;
237 out->data_deallocator = [](void* data, size_t length) { port::Free(data); };
238 return Status::OK();
239}
240
241void RecordMutation(TF_Graph* graph, const TF_Operation& op,
242 const char* mutation_type) {

Callers 15

RunCallableHelperFunction · 0.85
TF_FunctionToFunctionDefFunction · 0.85
TF_Run_HelperFunction · 0.85
TF_GetAllOpListFunction · 0.85
TF_OperationToNodeDefFunction · 0.85
TF_GraphToGraphDefFunction · 0.85
TF_GraphGetOpDefFunction · 0.85
TF_GraphVersionsFunction · 0.85

Calls 5

InvalidArgumentFunction · 0.85
ResourceExhaustedFunction · 0.85
GetTypeNameMethod · 0.80
MallocFunction · 0.50
FreeFunction · 0.50

Tested by

no test coverage detected