Ensure the data in `tensor.data` is readable. In case delegate is used, it might require to copy the data from delegate buffer to raw memory. WARNING: This is an experimental API and subject to change. TODO(b/119495520): make this private when refactoring complete.
| 255 | // WARNING: This is an experimental API and subject to change. |
| 256 | // TODO(b/119495520): make this private when refactoring complete. |
| 257 | TfLiteStatus EnsureTensorDataIsReadable(int tensor_index) { |
| 258 | TfLiteTensor* t = &tensors_[tensor_index]; |
| 259 | TF_LITE_ENSURE(&context_, t != nullptr); |
| 260 | if (t->data_is_stale) { |
| 261 | TF_LITE_ENSURE(&context_, t->delegate != nullptr); |
| 262 | TF_LITE_ENSURE(&context_, t->buffer_handle != kTfLiteNullBufferHandle); |
| 263 | TF_LITE_ENSURE(&context_, t->delegate->CopyFromBufferHandle != nullptr); |
| 264 | // TODO(b/120420546): we must add a test that exercise this code. |
| 265 | TF_LITE_ENSURE_STATUS(t->delegate->CopyFromBufferHandle( |
| 266 | &context_, t->delegate, t->buffer_handle, t)); |
| 267 | t->data_is_stale = false; |
| 268 | } |
| 269 | return kTfLiteOk; |
| 270 | } |
| 271 | |
| 272 | // The default capacity of `tensors_` vector. |
| 273 | static constexpr int kTensorsReservedCapacity = 128; |
no test coverage detected