| 725 | } |
| 726 | |
| 727 | void GenEagerPythonOp::AddEagerFastPathExecute() { |
| 728 | string fastpath_execute_params = strings::StrCat( |
| 729 | "_ctx._context_handle, _ctx._thread_local_data.device_name, \"", |
| 730 | op_def_.name(), "\", ", "name, _ctx.post_execution_callbacks"); |
| 731 | string fallback_params; |
| 732 | |
| 733 | for (int i = 0; i < api_def_.in_arg_size(); i++) { |
| 734 | const string param_name = param_names_[i].GetRenameTo(); |
| 735 | strings::StrAppend(&fastpath_execute_params, ", ", param_name); |
| 736 | if (!fallback_params.empty()) strings::StrAppend(&fallback_params, ", "); |
| 737 | strings::StrAppend(&fallback_params, param_name); |
| 738 | } |
| 739 | |
| 740 | for (const auto& attr : api_def_.attr()) { |
| 741 | if (inferred_attrs_.find(attr.name()) == inferred_attrs_.end()) { |
| 742 | strings::StrAppend(&fastpath_execute_params, ", \"", attr.name(), "\", ", |
| 743 | attr.rename_to()); |
| 744 | |
| 745 | if (!fallback_params.empty()) strings::StrAppend(&fallback_params, ", "); |
| 746 | strings::StrAppend(&fallback_params, attr.rename_to(), "=", |
| 747 | attr.rename_to()); |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | if (!fallback_params.empty()) strings::StrAppend(&fallback_params, ", "); |
| 752 | strings::StrAppend(&fallback_params, "name=name"); |
| 753 | |
| 754 | strings::StrAppend(&result_, " try:\n"); |
| 755 | strings::StrAppend( |
| 756 | &result_, " ", |
| 757 | "_result = _pywrap_tensorflow.TFE_Py_FastPathExecute(\n", |
| 758 | WordWrap(strings::StrCat(" "), |
| 759 | strings::StrCat(fastpath_execute_params, ")"), kRightMargin), |
| 760 | "\n"); |
| 761 | |
| 762 | if (op_def_.output_arg_size() > 1) { |
| 763 | const string output_tuple_name = |
| 764 | strings::StrCat("_", op_def_.name(), "Output"); |
| 765 | strings::StrAppend(&result_, " ", "_result = ", output_tuple_name, |
| 766 | "._make(_result)\n"); |
| 767 | } |
| 768 | strings::StrAppend(&result_, " ", "return _result\n"); |
| 769 | |
| 770 | // Handle fallback. |
| 771 | if (!fallback_params.empty()) strings::StrAppend(&fallback_params, ", "); |
| 772 | strings::StrAppend(&fallback_params, "ctx=_ctx"); |
| 773 | strings::StrAppend(&result_, " ", "except _core._FallbackException:\n"); |
| 774 | strings::StrAppend(&result_, " try:\n"); |
| 775 | strings::StrAppend( |
| 776 | &result_, " ", "return ", function_name_, kEagerFallbackSuffix, |
| 777 | "(\n", |
| 778 | WordWrap(strings::StrCat(" "), |
| 779 | strings::StrCat(fallback_params, ")"), kRightMargin), |
| 780 | "\n"); |
| 781 | strings::StrAppend(&result_, " except _core._SymbolicException:\n"); |
| 782 | strings::StrAppend(&result_, |
| 783 | " pass # Add nodes to the TensorFlow graph.\n"); |
| 784 | AddDispatch(" "); |