| 1042 | |
| 1043 | template <class PropagatorStateType> |
| 1044 | Status ExecutorState<PropagatorStateType>::PrepareInputs( |
| 1045 | const NodeItem& item, Entry* first_input, TensorValueVec* inputs, |
| 1046 | AllocatorAttributeVec* input_alloc_attrs, bool* is_input_dead, |
| 1047 | std::vector<bool>* is_input_dead_details) { |
| 1048 | inputs->resize(item.num_inputs); |
| 1049 | input_alloc_attrs->resize(item.num_inputs); |
| 1050 | |
| 1051 | *is_input_dead = false; |
| 1052 | is_input_dead_details->resize(item.num_inputs, false); |
| 1053 | |
| 1054 | for (int i = 0; i < item.num_inputs; ++i) { |
| 1055 | (*is_input_dead_details)[i] = false; |
| 1056 | const bool expect_ref = TF_PREDICT_FALSE(item.is_any_input_ref_typed) && |
| 1057 | IsRefType(item.input_type(i)); |
| 1058 | Entry* entry = first_input + i; |
| 1059 | (*input_alloc_attrs)[i] = entry->alloc_attr; |
| 1060 | |
| 1061 | // i-th input. |
| 1062 | TensorValue* inp = &(*inputs)[i]; |
| 1063 | |
| 1064 | switch (entry->state) { |
| 1065 | case Entry::State::NO_VALUE: { |
| 1066 | // Only merge and transfer nodes can have no-value inputs. |
| 1067 | inp->mutex_if_ref = nullptr; |
| 1068 | if (item.is_merge) { |
| 1069 | inp->tensor = nullptr; |
| 1070 | } else { |
| 1071 | DCHECK(item.is_transfer_node) |
| 1072 | << item.kernel->name() << " - input " << i; |
| 1073 | entry->state = Entry::State::HAS_CONST_TENSOR; |
| 1074 | entry->const_tensor = kEmptyTensor; |
| 1075 | // NOTE(mrry): This `const_cast` is necessary because `TensorValue` |
| 1076 | // stores a non-const `Tensor*`, and relies on the `OpKernelContext` |
| 1077 | // accessors making dynamic checks that prevent using an immutable |
| 1078 | // tensor as a mutable tensor. |
| 1079 | inp->tensor = const_cast<Tensor*>(kEmptyTensor); |
| 1080 | *is_input_dead = true; |
| 1081 | (*is_input_dead_details)[i] = true; |
| 1082 | } |
| 1083 | break; |
| 1084 | } |
| 1085 | |
| 1086 | case Entry::State::HAS_VALUE: { |
| 1087 | if (TF_PREDICT_FALSE(expect_ref)) { |
| 1088 | return AttachDef( |
| 1089 | errors::InvalidArgument(i, "-th input expects a ref type"), |
| 1090 | item.kernel->def()); |
| 1091 | } |
| 1092 | inp->mutex_if_ref = nullptr; |
| 1093 | inp->tensor = entry->val.get(); |
| 1094 | break; |
| 1095 | } |
| 1096 | |
| 1097 | case Entry::State::HAS_CONST_TENSOR: { |
| 1098 | if (TF_PREDICT_FALSE(expect_ref)) { |
| 1099 | return AttachDef( |
| 1100 | errors::InvalidArgument(i, "-th input expects a ref type"), |
| 1101 | item.kernel->def()); |
nothing calls this directly
no test coverage detected