| 2896 | } // namespace |
| 2897 | |
| 2898 | PyObject* TFE_Py_FastPathExecute_C(PyObject*, PyObject* args) { |
| 2899 | Py_ssize_t args_size = PyTuple_GET_SIZE(args); |
| 2900 | if (args_size < kFastPathExecuteInputStartIndex) { |
| 2901 | PyErr_SetString( |
| 2902 | PyExc_ValueError, |
| 2903 | Printf("There must be at least %d items in the input tuple.", |
| 2904 | kFastPathExecuteInputStartIndex) |
| 2905 | .c_str()); |
| 2906 | return nullptr; |
| 2907 | } |
| 2908 | |
| 2909 | FastPathOpExecInfo op_exec_info; |
| 2910 | |
| 2911 | op_exec_info.ctx = reinterpret_cast<TFE_Context*>( |
| 2912 | PyCapsule_GetPointer(PyTuple_GET_ITEM(args, 0), nullptr)); |
| 2913 | op_exec_info.args = args; |
| 2914 | |
| 2915 | if (op_exec_info.ctx == nullptr) { |
| 2916 | // The context hasn't been initialized. It will be in the slow path. |
| 2917 | RaiseFallbackException( |
| 2918 | "This function does not handle the case of the path where " |
| 2919 | "all inputs are not already EagerTensors."); |
| 2920 | return nullptr; |
| 2921 | } |
| 2922 | |
| 2923 | op_exec_info.device_name = GetDeviceName(PyTuple_GET_ITEM(args, 1)); |
| 2924 | op_exec_info.op_name = PyTuple_GET_ITEM(args, 2); |
| 2925 | op_exec_info.op_def = GetOpDef(op_exec_info.op_name); |
| 2926 | if (op_exec_info.op_def == nullptr) return nullptr; |
| 2927 | op_exec_info.name = PyTuple_GET_ITEM(args, 3); |
| 2928 | op_exec_info.callbacks = PyTuple_GET_ITEM(args, 4); |
| 2929 | |
| 2930 | const tensorflow::OpDef* op_def = op_exec_info.op_def; |
| 2931 | |
| 2932 | // TODO(nareshmodi): Add a benchmark for the fast-path with gradient callbacks |
| 2933 | // (similar to benchmark_tf_gradient_function_*). Also consider using an |
| 2934 | // InlinedVector for flattened_attrs and flattened_inputs if the benchmarks |
| 2935 | // point out problems with heap allocs. |
| 2936 | op_exec_info.run_gradient_callback = !*ThreadTapeIsStopped() && HasTape(); |
| 2937 | op_exec_info.run_post_exec_callbacks = |
| 2938 | op_exec_info.callbacks != Py_None && |
| 2939 | PyList_Size(op_exec_info.callbacks) > 0; |
| 2940 | op_exec_info.run_callbacks = op_exec_info.run_gradient_callback || |
| 2941 | op_exec_info.run_post_exec_callbacks; |
| 2942 | |
| 2943 | if (args_size < kFastPathExecuteInputStartIndex + op_def->input_arg_size()) { |
| 2944 | PyErr_SetString( |
| 2945 | PyExc_ValueError, |
| 2946 | Printf("Tuple size smaller than intended. Expected to be at least %d, " |
| 2947 | "was %ld", |
| 2948 | kFastPathExecuteInputStartIndex + op_def->input_arg_size(), |
| 2949 | args_size) |
| 2950 | .c_str()); |
| 2951 | return nullptr; |
| 2952 | } |
| 2953 | |
| 2954 | if (!CheckInputsOk(args, kFastPathExecuteInputStartIndex, *op_def)) { |
| 2955 | RaiseFallbackException( |
nothing calls this directly
no test coverage detected