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

Function AddInputToOp

tensorflow/python/eager/pywrap_tfe_src.cc:2730–2778  ·  view source on GitHub ↗

Adds input and type attr to the op, and to the list of flattened inputs/attrs.

Source from the content-addressed store, hash-verified

2728// Adds input and type attr to the op, and to the list of flattened
2729// inputs/attrs.
2730bool AddInputToOp(FastPathOpExecInfo* op_exec_info, PyObject* input,
2731 const bool add_type_attr,
2732 const tensorflow::OpDef::ArgDef& input_arg,
2733 std::vector<tensorflow::Safe_PyObjectPtr>* flattened_attrs,
2734 std::vector<tensorflow::Safe_PyObjectPtr>* flattened_inputs,
2735 TFE_Op* op, TF_Status* status) {
2736 // py_eager_tensor's ownership is transferred to flattened_inputs if it is
2737 // required, else the object is destroyed and DECREF'd when the object goes
2738 // out of scope in this function.
2739 tensorflow::Safe_PyObjectPtr py_eager_tensor = nullptr;
2740
2741 if (!ConvertToTensor(
2742 *op_exec_info, input, &py_eager_tensor,
2743 [&]() {
2744 if (input_arg.type() != tensorflow::DataType::DT_INVALID) {
2745 return input_arg.type();
2746 }
2747 return MaybeGetDTypeForAttr(input_arg.type_attr(), op_exec_info);
2748 },
2749 [&](const tensorflow::DataType dtype) {
2750 op_exec_info->cached_dtypes[input_arg.type_attr()] = dtype;
2751 },
2752 status)) {
2753 return false;
2754 }
2755
2756 TFE_TensorHandle* input_handle = EagerTensor_Handle(py_eager_tensor.get());
2757
2758 if (add_type_attr && !input_arg.type_attr().empty()) {
2759 auto dtype = TFE_TensorHandleDataType(input_handle);
2760 TFE_OpSetAttrType(op, input_arg.type_attr().data(), dtype);
2761 if (flattened_attrs != nullptr) {
2762 flattened_attrs->emplace_back(
2763 GetPythonObjectFromString(input_arg.type_attr().data()));
2764 flattened_attrs->emplace_back(PyLong_FromLong(dtype));
2765 }
2766 }
2767
2768 if (flattened_inputs != nullptr) {
2769 flattened_inputs->emplace_back(std::move(py_eager_tensor));
2770 }
2771
2772 TFE_OpAddInput(op, input_handle, status);
2773 if (MaybeRaiseExceptionFromTFStatus(status, nullptr)) {
2774 return false;
2775 }
2776
2777 return true;
2778}
2779
2780const tensorflow::OpDef* GetOpDef(PyObject* py_op_name) {
2781 const char* op_name = TFE_GetPythonString(py_op_name);

Callers 1

TFE_Py_FastPathExecute_CFunction · 0.85

Calls 12

MaybeGetDTypeForAttrFunction · 0.85
TFE_TensorHandleDataTypeFunction · 0.85
TFE_OpSetAttrTypeFunction · 0.85
TFE_OpAddInputFunction · 0.85
ConvertToTensorFunction · 0.70
typeMethod · 0.65
getMethod · 0.45
emptyMethod · 0.45
dataMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected