Set description of inputs/outputs/data/fptrs for node `node_index`. This variant assumes an external buffer has been allocated of size bytes. The lifetime of buffer must be ensured to be greater or equal to Interpreter.
| 984 | // bytes. The lifetime of buffer must be ensured to be greater or equal |
| 985 | // to Interpreter. |
| 986 | TfLiteStatus Subgraph::SetTensorParametersReadWrite( |
| 987 | int tensor_index, TfLiteType type, const char* name, const size_t rank, |
| 988 | const int* dims, TfLiteQuantization quantization, bool is_variable) { |
| 989 | // Ensure quantization cleanup on failure. |
| 990 | ScopedTfLiteQuantization scoped_quantization(&quantization); |
| 991 | if (state_ == kStateInvokableAndImmutable) { |
| 992 | ReportError( |
| 993 | "SetTensorParametersReadWrite is disallowed when graph is immutable."); |
| 994 | return kTfLiteError; |
| 995 | } |
| 996 | TF_LITE_ENSURE(&context_, |
| 997 | tensor_index < context_.tensors_size && tensor_index >= 0); |
| 998 | size_t required_bytes = 0; |
| 999 | if (type != kTfLiteString) { |
| 1000 | // These types will be allocated in our arena so we need to record how |
| 1001 | // many bytes we will need based on the dimensions. String tensors are |
| 1002 | // allocated dynamically and we can't know ahead of time how much space |
| 1003 | // they will require. |
| 1004 | TF_LITE_ENSURE_OK(&context_, |
| 1005 | BytesRequired(type, dims, rank, &required_bytes)); |
| 1006 | } |
| 1007 | |
| 1008 | TfLiteAllocationType allocation_type = kTfLiteArenaRw; |
| 1009 | if (type == kTfLiteString) { |
| 1010 | if (is_variable) { |
| 1011 | // We don't have a real use case for string variable tensor. |
| 1012 | ReportError("String variable tensor isn't supported."); |
| 1013 | return kTfLiteError; |
| 1014 | } |
| 1015 | allocation_type = kTfLiteDynamic; |
| 1016 | } else if (is_variable) { |
| 1017 | allocation_type = kTfLiteArenaRwPersistent; |
| 1018 | } |
| 1019 | |
| 1020 | TfLiteTensor& tensor = context_.tensors[tensor_index]; |
| 1021 | TfLiteTensorReset(type, name, ConvertArrayToTfLiteIntArray(rank, dims), |
| 1022 | GetLegacyQuantization(quantization), |
| 1023 | /*buffer=*/nullptr, required_bytes, allocation_type, |
| 1024 | nullptr, is_variable, &tensor); |
| 1025 | // TODO(suharshs): Update TfLiteTensorReset to include the new quantization |
| 1026 | // if there are other required callers. |
| 1027 | tensor.quantization = *scoped_quantization.release(); |
| 1028 | return kTfLiteOk; |
| 1029 | } |
| 1030 | |
| 1031 | TfLiteStatus Subgraph::SetExecutionPlan(const std::vector<int>& new_plan) { |
| 1032 | for (int node_index : new_plan) { |