If `handle` is already symbolic, return it. Otherwise map it to a new symbolic tensor (a PlaceHolder op) and return that.
| 849 | // If `handle` is already symbolic, return it. Otherwise map it to a new |
| 850 | // symbolic tensor (a PlaceHolder op) and return that. |
| 851 | static TF_Output getOrCreateSymbolicTensor(TFE_TraceContext* trace_ctx, |
| 852 | tensorflow::TensorHandle* handle, |
| 853 | TF_Status* status) { |
| 854 | VLOG(1) << "Getting symbolic tensor for input tensor handle " << handle |
| 855 | << ": " << handle->DebugString(); |
| 856 | |
| 857 | auto* sym_tensor = handle->getSymbolicTensor(); |
| 858 | if (sym_tensor != nullptr) { |
| 859 | auto ret = TF_Output{sym_tensor->oper, sym_tensor->index}; |
| 860 | VLOG(1) << "This handle is a symbolic tensor " << sym_tensor << ": " |
| 861 | << getTF_OutputDebugString(ret); |
| 862 | return ret; |
| 863 | } |
| 864 | |
| 865 | auto find_it = trace_ctx->input_tensor_map.find(handle); |
| 866 | if (find_it != trace_ctx->input_tensor_map.end()) { |
| 867 | VLOG(1) << "There exists a map entry from this concrete tensor to: " |
| 868 | << getTF_OutputDebugString(find_it->second); |
| 869 | return find_it->second; |
| 870 | } |
| 871 | |
| 872 | auto node_name = tensorflow::strings::StrCat("additional_input_", |
| 873 | trace_ctx->node_counter++); |
| 874 | VLOG(1) << "Adding a place holder node named " << node_name; |
| 875 | auto* desc = |
| 876 | TF_NewOperation(trace_ctx->graph, "Placeholder", node_name.c_str()); |
| 877 | TF_SetAttrType(desc, "dtype", |
| 878 | static_cast<TF_DataType>(handle->dtype) /*TF_FLOAT*/); |
| 879 | auto* result = TF_FinishOperation(desc, status); |
| 880 | if (!status->status.ok()) { |
| 881 | return TF_Output{nullptr, -1}; |
| 882 | } |
| 883 | |
| 884 | auto ret = TF_Output{result, 0}; |
| 885 | VLOG(1) << "Creating a new map entry to map to: " |
| 886 | << getTF_OutputDebugString(ret); |
| 887 | trace_ctx->input_tensor_map[handle] = ret; |
| 888 | // `handle` could be destroyed before it's read from `input_tensor_map` (say |
| 889 | // during a subsequent TFE_FinalizeInputTensorsFromTraceContext() call), so we |
| 890 | // increment its ref count to extend its life span to that of `trace_ctx`. |
| 891 | handle->Ref(); |
| 892 | VLOG(1) << "Ref count for handle " << handle |
| 893 | << " is 1?: " << handle->RefCountIsOne(); |
| 894 | return ret; |
| 895 | } |
| 896 | |
| 897 | TF_Operation* TFE_AddEagerOpToGraph(TFE_Op* op, TFE_TraceContext* trace_ctx, |
| 898 | TFE_TensorHandle** retvals, |
no test coverage detected