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

Function TF_Run_Helper

tensorflow/c/c_api.cc:409–464  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

407}
408
409static void TF_Run_Helper(
410 Session* session, const char* handle, const TF_Buffer* run_options,
411 // Input tensors
412 const std::vector<std::pair<string, Tensor>>& input_pairs,
413 // Output tensors
414 const std::vector<string>& output_tensor_names, TF_Tensor** c_outputs,
415 // Target nodes
416 const std::vector<string>& target_oper_names, TF_Buffer* run_metadata,
417 TF_Status* status) {
418 const int noutputs = output_tensor_names.size();
419 std::vector<Tensor> outputs(noutputs);
420 Status result;
421
422 if (handle == nullptr) {
423 RunOptions run_options_proto;
424 if (run_options != nullptr && !run_options_proto.ParseFromArray(
425 run_options->data, run_options->length)) {
426 status->status = InvalidArgument("Unparseable RunOptions proto");
427 return;
428 }
429 if (run_metadata != nullptr && run_metadata->data != nullptr) {
430 status->status =
431 InvalidArgument("Passing non-empty run_metadata is invalid.");
432 return;
433 }
434
435 RunMetadata run_metadata_proto;
436 result = session->Run(run_options_proto, input_pairs, output_tensor_names,
437 target_oper_names, &outputs, &run_metadata_proto);
438
439 // Serialize back to upstream client, who now owns the new buffer
440 if (run_metadata != nullptr) {
441 status->status = MessageToBuffer(run_metadata_proto, run_metadata);
442 if (TF_GetCode(status) != TF_OK) return;
443 }
444 } else {
445 // NOTE(zongheng): PRun does not support RunOptions yet.
446 result = session->PRun(handle, input_pairs, output_tensor_names, &outputs);
447 }
448 if (!result.ok()) {
449 status->status = result;
450 return;
451 }
452
453 // Store results in c_outputs[]
454 for (int i = 0; i < noutputs; ++i) {
455 const Tensor& src = outputs[i];
456 if (!src.IsInitialized() || src.NumElements() == 0) {
457 c_outputs[i] =
458 EmptyTensor(static_cast<TF_DataType>(src.dtype()), src.shape());
459 continue;
460 }
461 c_outputs[i] = TF_TensorFromTensor(src, status);
462 if (TF_GetCode(status) != TF_OK) return;
463 }
464}
465
466extern "C" {

Callers 4

TF_RunFunction · 0.85
TF_PRunFunction · 0.85
TF_SessionRunFunction · 0.85
TF_SessionPRunFunction · 0.85

Calls 13

InvalidArgumentFunction · 0.85
MessageToBufferFunction · 0.85
TF_GetCodeFunction · 0.85
TF_TensorFromTensorFunction · 0.85
EmptyTensorFunction · 0.70
sizeMethod · 0.45
RunMethod · 0.45
PRunMethod · 0.45
okMethod · 0.45
IsInitializedMethod · 0.45
NumElementsMethod · 0.45
dtypeMethod · 0.45

Tested by

no test coverage detected