-
Notifications
You must be signed in to change notification settings - Fork 957
Support for DECODE operator #3213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,12 +18,37 @@ limitations under the License. | |
| #include "tensorflow/lite/kernels/kernel_util.h" | ||
| #include "tensorflow/lite/micro/kernels/decode_state.h" | ||
| #include "tensorflow/lite/micro/kernels/kernel_util.h" | ||
| #include "tensorflow/lite/micro/micro_arena_constants.h" | ||
| #include "tensorflow/lite/micro/micro_context.h" | ||
| #include "tensorflow/lite/micro/micro_log.h" | ||
|
|
||
| namespace tflite { | ||
| namespace { | ||
|
|
||
| TfLiteStatus SetOutputTensorData(TfLiteContext* context, const TfLiteNode* node, | ||
| size_t tensor_output_index, | ||
| TfLiteTensor* output) { | ||
| if (output->data.data != nullptr) { | ||
| // If memory has already been assigned to the tensor, leave it be | ||
| return kTfLiteOk; | ||
| } | ||
|
|
||
| // If alternate decompression memory is available, set the tensor data | ||
| // pointer now to preclude allocation by the memory planner. | ||
| void* alternate_decompress_mem = | ||
| GetMicroContext(context)->AllocateDecompressionMemory( | ||
| output->bytes, MicroArenaBufferAlignment()); | ||
| if (alternate_decompress_mem != nullptr) { | ||
| TfLiteEvalTensor* output_eval = | ||
| tflite::micro::GetEvalOutput(context, node, tensor_output_index); | ||
| TF_LITE_ENSURE(context, output_eval != nullptr); | ||
| output_eval->data.data = alternate_decompress_mem; | ||
| output->data.data = alternate_decompress_mem; | ||
| } | ||
|
|
||
| return kTfLiteOk; | ||
| } | ||
|
|
||
| TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) { | ||
| const size_t num_inputs = NumInputs(node); | ||
| const size_t num_outputs = NumOutputs(node); | ||
|
|
@@ -43,6 +68,8 @@ TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) { | |
| TfLiteTensor* output = nullptr; | ||
| TfLiteStatus status = kTfLiteOk; | ||
|
|
||
| micro_context->ResetDecompressionMemoryAllocations(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this mean that there will be only one Decode node in the entire graph? It looks like that if there were two Decode nodes, the second one's Prepare call would wipe out the memory assignments planned by the first one.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. <discussion moved to alternate venue> |
||
|
|
||
| for (size_t i = 0; i < num_inputs; i += 2) { | ||
| input = micro_context->AllocateTempInputTensor(node, i); | ||
| if (input == nullptr) { | ||
|
|
@@ -95,6 +122,11 @@ TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) { | |
| break; | ||
| } | ||
|
|
||
| status = SetOutputTensorData(context, node, i / 2, output); | ||
| if (status != kTfLiteOk) { | ||
| break; | ||
| } | ||
|
|
||
| if (dsp != nullptr) { | ||
| status = dsp->Setup(*input, *ancillary, *output); | ||
| if (status != kTfLiteOk) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious how this would happen?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<discussion moved to alternate venue>