diff --git a/components/tflite/.gitignore b/components/tflite/.gitignore new file mode 100644 index 00000000..c4531785 --- /dev/null +++ b/components/tflite/.gitignore @@ -0,0 +1,5 @@ +/bazel-* +*.swp +.vscode/ +*audio_frontend* +*google* diff --git a/components/tflite/CMakeLists.txt b/components/tflite/CMakeLists.txt new file mode 100644 index 00000000..e0294595 --- /dev/null +++ b/components/tflite/CMakeLists.txt @@ -0,0 +1,57 @@ +################# Add global include ################# +list(APPEND ADD_INCLUDE +"${CMAKE_CURRENT_SOURCE_DIR}" +"${CMAKE_CURRENT_SOURCE_DIR}/third_party/flatbuffers/include" +"${CMAKE_CURRENT_SOURCE_DIR}/third_party/gemmlowp" +"${CMAKE_CURRENT_SOURCE_DIR}/third_party/ruy" +) +####################################################### + +################# Add private include ################# +# list(APPEND ADD_PRIVATE_INCLUDE +# ) +####################################################### + + +############## Add current dir source files ########### +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/c sources) +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/core/api sources) +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/kernels sources) +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/kernels/internal sources) +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/micro sources) +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/micro/kernels sources) +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/micro/memory_planner sources) +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/lite/schema sources) + +list(APPEND ADD_SRCS ${sources}) +####################################################### + +########### Add required/dependent components ######### +# list(APPEND ADD_REQUIREMENTS xxx) +####################################################### + +############ Add static libs ########################## +#list(APPEND ADD_STATIC_LIB "libxxx.a") +####################################################### + +############ Add dynamic libs ######################### +# list(APPEND ADD_DYNAMIC_LIB "libxxx.so" +# ) +####################################################### + +############ Add global compile option ################ +#add components denpend on this component +list(APPEND ADD_DEFINITIONS -DTF_LITE_USE_GLOBAL_CMATH_FUNCTIONS) +list(APPEND ADD_DEFINITIONS -DTF_LITE_USE_GLOBAL_MIN) +list(APPEND ADD_DEFINITIONS -DTF_LITE_USE_GLOBAL_MAX) +list(APPEND ADD_DEFINITIONS -DTF_LITE_STATIC_MEMORY) +list(APPEND ADD_DEFINITIONS $<$:-fno-threadsafe-statics>) + +####################################################### + +############ Add private compile option ################ +#add compile option for this component that won't affect other modules +# list(APPEND ADD_PRIVATE_DEFINITIONS) +####################################################### + +generate_library() diff --git a/components/tflite/LICENSE b/components/tflite/LICENSE new file mode 100644 index 00000000..d6456956 --- /dev/null +++ b/components/tflite/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/components/tflite/README.md b/components/tflite/README.md new file mode 100644 index 00000000..b0d84b35 --- /dev/null +++ b/components/tflite/README.md @@ -0,0 +1,75 @@ + + * [TensorFlow Lite for Microcontrollers](#tensorflow-lite-for-microcontrollers) + * [Build Status](#build-status) + * [Official Builds](#official-builds) + * [Community Supported Builds](#community-supported-builds) + * [Contributing](#contributing) + * [Getting Help](#getting-help) + * [Additional Documentation](#additional-documentation) + * [RFCs](#rfcs) + + + + + +# TensorFlow Lite for Microcontrollers + +TensorFlow Lite for Microcontrollers is a port of TensorFlow Lite designed to +run machine learning models on DSPs, microcontrollers and other devices with +limited memory. + +Additional Links: + * [Tensorflow github repository](https://github.com/tensorflow/tensorflow/) + * [TFLM at tensorflow.org](https://www.tensorflow.org/lite/microcontrollers) + +# Build Status + + * [GitHub Status](https://www.githubstatus.com/) + +## Official Builds + +Build Type | Status | +----------- | --------------| +CI (Linux) | [![CI](https://github.com/tensorflow/tflite-micro/actions/workflows/ci.yml/badge.svg?event=schedule)](https://github.com/tensorflow/tflite-micro/actions/workflows/ci.yml?query=event%3Aschedule) | +Code Sync | [![Sync from Upstream TF](https://github.com/tensorflow/tflite-micro/actions/workflows/sync.yml/badge.svg)](https://github.com/tensorflow/tflite-micro/actions/workflows/sync.yml) | + +## Community Supported Builds +Build Type | Status | +----------- | --------------| +Arduino | [![Arduino](https://github.com/tensorflow/tflite-micro/actions/workflows/arduino.yml/badge.svg)](https://github.com/tensorflow/tflite-micro/actions/workflows/arduino.yml) [![Antmicro](https://github.com/antmicro/tensorflow-arduino-examples/actions/workflows/test_examples.yml/badge.svg)](https://github.com/antmicro/tensorflow-arduino-examples/actions/workflows/test_examples.yml) | +Cortex-M | [![Cortex-M](https://github.com/tensorflow/tflite-micro/actions/workflows/cortex_m.yml/badge.svg)](https://github.com/tensorflow/tflite-micro/actions/workflows/cortex_m.yml) | +Sparkfun Edge | [![Sparkfun Edge](https://github.com/tensorflow/tflite-micro/actions/workflows/sparkfun_edge.yml/badge.svg)](https://github.com/tensorflow/tflite-micro/actions/workflows/sparkfun_edge.yml) | +Xtensa | [![Xtensa](https://github.com/tensorflow/tflite-micro/actions/workflows/xtensa.yml/badge.svg?event=schedule)](https://github.com/tensorflow/tflite-micro/actions/workflows/xtensa.yml?query=event%3Aschedule) [![Xtensa](https://raw.githubusercontent.com/advaitjain/tflite-micro/local-continuous-builds/tensorflow/lite/micro/docs/local_continuous_builds/xtensa-build-status.svg)](https://github.com/advaitjain/tflite-micro/tree/local-continuous-builds/tensorflow/lite/micro/docs/local_continuous_builds/xtensa.md#summary) | + + +# Contributing +See our [contribution documentation](CONTRIBUTING.md). + +# Getting Help + +A [Github issue](https://github.com/tensorflow/tflite-micro/issues/new/choose) +should be the primary method of getting in touch with the TensorFlow Lite Micro +(TFLM) team. + +The following resources may also be useful: + +1. SIG Micro [email group](https://groups.google.com/a/tensorflow.org/g/micro) + and + [monthly meetings](http://doc/1YHq9rmhrOUdcZnrEnVCWvd87s2wQbq4z17HbeRl-DBc). + +1. SIG Micro [gitter chat room](https://gitter.im/tensorflow/sig-micro). + +# Additional Documentation + + * [Continuous Integration](docs/continuous_integration.md) + * [Benchmarks](tensorflow/lite/micro/benchmarks/README.md) + * [Profiling](tensorflow/lite/micro/docs/profiling.md) + * [Memory Management](tensorflow/lite/micro/docs/memory_management.md) + * [Optimized Kernel Implementations](tensorflow/lite/micro/docs/optimized_kernel_implementations.md) + * [New Platform Support](tensorflow/lite/micro/docs/new_platform_support.md) + * [Software Emulation with Renode](tensorflow/lite/micro/docs/renode.md) + +# RFCs + +1. [Pre-allocated tensors](tensorflow/lite/micro/docs/rfc/001_preallocated_tensors.md) +1. [TensorFlow Lite for Microcontrollers Port of 16x8 Quantized Operators](tensorflow/lite/micro/docs/rfc/002_16x8_quantization_port.md) diff --git a/components/tflite/tensorflow/lite/c/builtin_op_data.h b/components/tflite/tensorflow/lite/c/builtin_op_data.h new file mode 100644 index 00000000..c76644f6 --- /dev/null +++ b/components/tflite/tensorflow/lite/c/builtin_op_data.h @@ -0,0 +1,504 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_C_BUILTIN_OP_DATA_H_ +#define TENSORFLOW_LITE_C_BUILTIN_OP_DATA_H_ + +#include + +#include "tensorflow/lite/c/common.h" + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +// TfLiteReshapeParams can't have dynamic data so we fix the maximum possible +// number of dimensions. +#define TFLITE_RESHAPE_PARAMS_MAX_DIMENSION_COUNT 8 + +// TODO(aselle): Consider using "if this then that" for testing. + +// Useful placeholder to put in otherwise empty structs to avoid size warnings. +typedef struct { + char dummy; +} EmptyStructPlaceholder; + +// IMPORTANT: All new members of structs must be added at the end to ensure +// backwards compatibility. + +// Possible padding types (for convolutions) +typedef enum { + kTfLitePaddingUnknown = 0, + kTfLitePaddingSame, + kTfLitePaddingValid, +} TfLitePadding; + +typedef enum { + kTfLiteMirrorPaddingUnknown = 0, + kTfLiteMirrorPaddingReflect, + kTfLiteMirrorPaddingSymmetric, +} TfLiteMirrorPaddingMode; + +// TODO(b/130259536): We should move this out of builtin_op_data. +typedef struct { + int width; + int height; + int width_offset; + int height_offset; +} TfLitePaddingValues; + +typedef struct { + TfLiteMirrorPaddingMode mode; +} TfLiteMirrorPaddingParams; + +// Possible fused activation functions. +typedef enum { + kTfLiteActNone = 0, + kTfLiteActRelu, + kTfLiteActReluN1To1, // min(max(-1, x), 1) + kTfLiteActRelu6, // min(max(0, x), 6) + kTfLiteActTanh, + kTfLiteActSignBit, + kTfLiteActSigmoid, +} TfLiteFusedActivation; + +typedef struct { + // Parameters for CONV_2D version 1. + TfLitePadding padding; + int stride_width; + int stride_height; + TfLiteFusedActivation activation; + + // Parameters for CONV_2D version 2. + // Note: Version 2 supports dilation values not equal to 1. + int dilation_width_factor; + int dilation_height_factor; +} TfLiteConvParams; + +typedef struct { + TfLitePadding padding; + int stride_width; + int stride_height; + int stride_depth; + int dilation_width_factor; + int dilation_height_factor; + int dilation_depth_factor; + TfLiteFusedActivation activation; +} TfLiteConv3DParams; + +typedef TfLiteConv3DParams TfLiteConv3DTransposeParams; + +typedef struct { + TfLitePadding padding; + int stride_width; + int stride_height; + int filter_width; + int filter_height; + TfLiteFusedActivation activation; + struct { + TfLitePaddingValues padding; + } computed; +} TfLitePoolParams; + +typedef struct { + // Parameters for DepthwiseConv version 1 or above. + TfLitePadding padding; + int stride_width; + int stride_height; + // `depth_multiplier` is redundant. It's used by CPU kernels in + // TensorFlow 2.0 or below, but ignored in versions above. + // + // The information can be deduced from the shape of input and the shape of + // weights. Since the TFLiteConverter toolchain doesn't support partially + // specified shapes, relying on `depth_multiplier` stops us from supporting + // graphs with dynamic shape tensors. + // + // Note: Some of the delegates (e.g. NNAPI, GPU) are still relying on this + // field. + int depth_multiplier; + TfLiteFusedActivation activation; + // Parameters for DepthwiseConv version 2 or above. + int dilation_width_factor; + int dilation_height_factor; +} TfLiteDepthwiseConvParams; + +typedef struct { + int rank; + TfLiteFusedActivation activation; + + // Parameter for SVDF version 4. + bool asymmetric_quantize_inputs; +} TfLiteSVDFParams; + +typedef struct { + TfLiteFusedActivation activation; + + // Parameter for RNN version 3. + bool asymmetric_quantize_inputs; +} TfLiteRNNParams; + +typedef struct { + bool time_major; + TfLiteFusedActivation activation; + + // Parameter for Sequence RNN version 3. + bool asymmetric_quantize_inputs; +} TfLiteSequenceRNNParams; + +typedef struct { + bool time_major; + TfLiteFusedActivation activation; + bool merge_outputs; + + // Parameter for Bidirectional RNN verison 3. + bool asymmetric_quantize_inputs; +} TfLiteBidirectionalSequenceRNNParams; + +typedef enum { + kTfLiteFullyConnectedWeightsFormatDefault = 0, + kTfLiteFullyConnectedWeightsFormatShuffled4x16Int8 = 1, +} TfLiteFullyConnectedWeightsFormat; + +typedef struct { + // Parameters for FullyConnected version 1 or above. + TfLiteFusedActivation activation; + + // Parameters for FullyConnected version 2 or above. + TfLiteFullyConnectedWeightsFormat weights_format; + + // Parameters for FullyConnected version 5 or above. + // If set to true, then the number of dimensions in the input and the output + // tensors are the same. Furthermore, all but the last dimension of the input + // and output shapes will be equal. + bool keep_num_dims; + + // Parameters for FullyConnected version 7 or above. + // If set to true and the weights are quantized, then non constant inputs + // are quantized at evaluation time with asymmetric quantization. + bool asymmetric_quantize_inputs; +} TfLiteFullyConnectedParams; + +typedef enum { + kTfLiteLshProjectionUnknown = 0, + kTfLiteLshProjectionSparse = 1, + kTfLiteLshProjectionDense = 2, +} TfLiteLSHProjectionType; + +typedef struct { + TfLiteLSHProjectionType type; +} TfLiteLSHProjectionParams; + +typedef struct { + float beta; +} TfLiteSoftmaxParams; + +typedef struct { + int axis; + TfLiteFusedActivation activation; +} TfLiteConcatenationParams; + +typedef struct { + TfLiteFusedActivation activation; + // Parameter added for the version 4. + bool pot_scale_int16; +} TfLiteAddParams; + +typedef struct { + EmptyStructPlaceholder placeholder; +} TfLiteSpaceToBatchNDParams; + +typedef struct { + EmptyStructPlaceholder placeholder; +} TfLiteBatchToSpaceNDParams; + +typedef struct { + bool adj_x; + bool adj_y; + // Parameters for BatchMatMul version 4 or above. + // If set to true and the weights are quantized, then non constant inputs + // are quantized at evaluation time with asymmetric quantization. + bool asymmetric_quantize_inputs; +} TfLiteBatchMatMulParams; + +typedef struct { + TfLiteFusedActivation activation; +} TfLiteMulParams; + +typedef struct { + TfLiteFusedActivation activation; + // Parameter added for the version 5. + bool pot_scale_int16; +} TfLiteSubParams; + +typedef struct { + TfLiteFusedActivation activation; +} TfLiteDivParams; + +typedef struct { + TfLiteFusedActivation activation; +} TfLiteL2NormParams; + +typedef struct { + int radius; + float bias; + float alpha; + float beta; +} TfLiteLocalResponseNormParams; + +typedef enum { + kTfLiteLSTMFullKernel = 0, + kTfLiteLSTMBasicKernel +} TfLiteLSTMKernelType; + +typedef struct { + // Parameters for LSTM version 1. + TfLiteFusedActivation activation; + float cell_clip; + float proj_clip; + + // Parameters for LSTM version 2. + // kTfLiteLSTMBasicKernel is only supported in version 2 or above. + TfLiteLSTMKernelType kernel_type; + + // Parameters for LSTM version 4. + bool asymmetric_quantize_inputs; +} TfLiteLSTMParams; + +typedef struct { + // Parameters needed for the underlying LSTM. + TfLiteFusedActivation activation; + float cell_clip; + float proj_clip; + + // If set to true then the first dimension is time, otherwise batch. + bool time_major; + + // Parameter for unidirectional sequence RNN version 3. + bool asymmetric_quantize_inputs; +} TfLiteUnidirectionalSequenceLSTMParams; + +typedef struct { + // Parameters supported by version 1: + // Parameters inherited for the LSTM kernel. + TfLiteFusedActivation activation; + float cell_clip; + float proj_clip; + + // If true, store the outputs of both directions in the first output. + bool merge_outputs; + + // Parameters supported by version 2: + // If set to true then the first dimension is time, otherwise batch. + bool time_major; + + // Parameters supported by version 4: + // If set to true, then hybrid ops use asymmetric quantization for inputs. + bool asymmetric_quantize_inputs; +} TfLiteBidirectionalSequenceLSTMParams; + +typedef struct { + bool align_corners; + // half_pixel_centers assumes pixels are of half the actual dimensions, and + // yields more accurate resizes. Corresponds to the same argument for the + // original TensorFlow op in TF2.0. + bool half_pixel_centers; +} TfLiteResizeBilinearParams; + +typedef struct { + bool align_corners; + bool half_pixel_centers; +} TfLiteResizeNearestNeighborParams; + +typedef struct { + EmptyStructPlaceholder placeholder; +} TfLitePadParams; + +typedef struct { + EmptyStructPlaceholder placeholder; +} TfLitePadV2Params; + +typedef struct { + // These fields are only used in old models for backward compatibility. + // In the current implementation, we use the 2nd input of the op as the shape, + // and these fields are unused. + int shape[TFLITE_RESHAPE_PARAMS_MAX_DIMENSION_COUNT]; + int num_dimensions; +} TfLiteReshapeParams; + +typedef struct { + int ngram_size; + int max_skip_size; + bool include_all_ngrams; +} TfLiteSkipGramParams; + +typedef struct { + int block_size; +} TfLiteSpaceToDepthParams; + +typedef struct { + int block_size; +} TfLiteDepthToSpaceParams; + +typedef struct { + TfLiteType in_data_type; + TfLiteType out_data_type; +} TfLiteCastParams; + +typedef enum { + kTfLiteCombinerTypeSum = 0, + kTfLiteCombinerTypeMean = 1, + kTfLiteCombinerTypeSqrtn = 2, +} TfLiteCombinerType; + +typedef struct { + TfLiteCombinerType combiner; +} TfLiteEmbeddingLookupSparseParams; + +typedef struct { + int axis; + int batch_dims; +} TfLiteGatherParams; + +typedef struct { + EmptyStructPlaceholder placeholder; +} TfLiteTransposeParams; + +typedef struct { + bool keep_dims; +} TfLiteReducerParams; + +typedef struct { + int num_splits; +} TfLiteSplitParams; + +typedef struct { + int num_splits; +} TfLiteSplitVParams; + +typedef struct { + // TODO(ahentz): We can't have dynamic data in this struct, at least not yet. + // For now we will fix the maximum possible number of dimensions. + int squeeze_dims[8]; + int num_squeeze_dims; +} TfLiteSqueezeParams; + +typedef struct { + int begin_mask; + int end_mask; + int ellipsis_mask; + int new_axis_mask; + int shrink_axis_mask; +} TfLiteStridedSliceParams; + +typedef struct { + TfLiteType output_type; +} TfLiteArgMaxParams; + +typedef struct { + TfLiteType output_type; +} TfLiteArgMinParams; + +typedef struct { + TfLitePadding padding; + int stride_width; + int stride_height; +} TfLiteTransposeConvParams; + +typedef struct { + bool validate_indices; +} TfLiteSparseToDenseParams; + +typedef struct { + TfLiteType out_type; +} TfLiteShapeParams; + +typedef struct { + EmptyStructPlaceholder placeholder; +} TfLiteRankParams; + +typedef struct { + // Parameters supported by version 1: + float min; + float max; + int num_bits; + + // Parameters supported by version 2: + bool narrow_range; +} TfLiteFakeQuantParams; + +typedef struct { + int values_count; + int axis; +} TfLitePackParams; + +typedef struct { + int axis; +} TfLiteOneHotParams; + +typedef struct { + int num; + int axis; +} TfLiteUnpackParams; + +typedef struct { + float alpha; +} TfLiteLeakyReluParams; + +typedef struct { + TfLiteType index_out_type; +} TfLiteUniqueParams; + +typedef struct { + int seq_dim; + int batch_dim; +} TfLiteReverseSequenceParams; + +typedef struct { + EmptyStructPlaceholder placeholder; +} TfLiteMatrixDiagParams; + +typedef struct { + EmptyStructPlaceholder placeholder; +} TfLiteMatrixSetDiagParams; + +typedef struct { + int then_subgraph_index; + int else_subgraph_index; +} TfLiteIfParams; + +typedef struct { + int cond_subgraph_index; + int body_subgraph_index; +} TfLiteWhileParams; + +typedef struct { + bool exclusive; + bool reverse; +} TfLiteCumsumParams; + +typedef struct { + int init_subgraph_index; +} TfLiteCallOnceParams; + +typedef struct { + int table_id; + TfLiteType key_dtype; + TfLiteType value_dtype; +} TfLiteHashtableParams; + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus + +#endif // TENSORFLOW_LITE_C_BUILTIN_OP_DATA_H_ diff --git a/components/tflite/tensorflow/lite/c/c_api_types.h b/components/tflite/tensorflow/lite/c/c_api_types.h new file mode 100644 index 00000000..a8921177 --- /dev/null +++ b/components/tflite/tensorflow/lite/c/c_api_types.h @@ -0,0 +1,105 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// This file declares types used by the pure C inference API defined in c_api.h, +// some of which are also used in the C++ and C kernel and interpreter APIs. + +#ifndef TENSORFLOW_LITE_C_C_API_TYPES_H_ +#define TENSORFLOW_LITE_C_C_API_TYPES_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// Define TFL_CAPI_EXPORT macro to export a function properly with a shared +// library. +#ifdef SWIG +#define TFL_CAPI_EXPORT +#elif defined(TFL_STATIC_LIBRARY_BUILD) +#define TFL_CAPI_EXPORT +#else // not definded TFL_STATIC_LIBRARY_BUILD +#if defined(_WIN32) +#ifdef TFL_COMPILE_LIBRARY +#define TFL_CAPI_EXPORT __declspec(dllexport) +#else +#define TFL_CAPI_EXPORT __declspec(dllimport) +#endif // TFL_COMPILE_LIBRARY +#else +#define TFL_CAPI_EXPORT __attribute__((visibility("default"))) +#endif // _WIN32 +#endif // SWIG + +typedef enum TfLiteStatus { + kTfLiteOk = 0, + + // Generally referring to an error in the runtime (i.e. interpreter) + kTfLiteError = 1, + + // Generally referring to an error from a TfLiteDelegate itself. + kTfLiteDelegateError = 2, + + // Generally referring to an error in applying a delegate due to + // incompatibility between runtime and delegate, e.g., this error is returned + // when trying to apply a TfLite delegate onto a model graph that's already + // immutable. + kTfLiteApplicationError = 3, + + // Generally referring to serialized delegate data not being found. + // See tflite::delegates::Serialization. + kTfLiteDelegateDataNotFound = 4, + + // Generally referring to data-writing issues in delegate serialization. + // See tflite::delegates::Serialization. + kTfLiteDelegateDataWriteError = 5, +} TfLiteStatus; + +// Types supported by tensor +typedef enum { + kTfLiteNoType = 0, + kTfLiteFloat32 = 1, + kTfLiteInt32 = 2, + kTfLiteUInt8 = 3, + kTfLiteInt64 = 4, + kTfLiteString = 5, + kTfLiteBool = 6, + kTfLiteInt16 = 7, + kTfLiteComplex64 = 8, + kTfLiteInt8 = 9, + kTfLiteFloat16 = 10, + kTfLiteFloat64 = 11, + kTfLiteComplex128 = 12, + kTfLiteUInt64 = 13, + kTfLiteResource = 14, + kTfLiteVariant = 15, + kTfLiteUInt32 = 16, +} TfLiteType; + +// Legacy. Will be deprecated in favor of TfLiteAffineQuantization. +// If per-layer quantization is specified this field will still be populated in +// addition to TfLiteAffineQuantization. +// Parameters for asymmetric quantization. Quantized values can be converted +// back to float using: +// real_value = scale * (quantized_value - zero_point) +typedef struct TfLiteQuantizationParams { + float scale; + int32_t zero_point; +} TfLiteQuantizationParams; + +#ifdef __cplusplus +} // extern C +#endif +#endif // TENSORFLOW_LITE_C_C_API_TYPES_H_ diff --git a/components/tflite/tensorflow/lite/c/common.c b/components/tflite/tensorflow/lite/c/common.c new file mode 100644 index 00000000..811c0a23 --- /dev/null +++ b/components/tflite/tensorflow/lite/c/common.c @@ -0,0 +1,274 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/c/c_api_types.h" + +#ifndef TF_LITE_STATIC_MEMORY +#include +#include +#endif // TF_LITE_STATIC_MEMORY + +int TfLiteIntArrayGetSizeInBytes(int size) +{ + static TfLiteIntArray dummy; + return sizeof(dummy) + sizeof(dummy.data[0]) * size; +} + +int TfLiteIntArrayEqual(const TfLiteIntArray *a, const TfLiteIntArray *b) +{ + if (a == b) + return 1; + if (a == NULL || b == NULL) + return 0; + return TfLiteIntArrayEqualsArray(a, b->size, b->data); +} + +int TfLiteIntArrayEqualsArray(const TfLiteIntArray *a, int b_size, + const int b_data[]) +{ + if (a == NULL) + return (b_size == 0); + if (a->size != b_size) + return 0; + int i = 0; + for (; i < a->size; i++) + if (a->data[i] != b_data[i]) + return 0; + return 1; +} + +#ifndef TF_LITE_STATIC_MEMORY + +TfLiteIntArray *TfLiteIntArrayCreate(int size) +{ + int alloc_size = TfLiteIntArrayGetSizeInBytes(size); + if (alloc_size <= 0) + return NULL; + TfLiteIntArray *ret = (TfLiteIntArray *)malloc(alloc_size); + if (!ret) + return ret; + ret->size = size; + return ret; +} + +TfLiteIntArray *TfLiteIntArrayCopy(const TfLiteIntArray *src) +{ + if (!src) + return NULL; + TfLiteIntArray *ret = TfLiteIntArrayCreate(src->size); + if (ret) { + memcpy(ret->data, src->data, src->size * sizeof(int)); + } + return ret; +} + +void TfLiteIntArrayFree(TfLiteIntArray *a) +{ + free(a); +} + +#endif // TF_LITE_STATIC_MEMORY + +int TfLiteFloatArrayGetSizeInBytes(int size) +{ + static TfLiteFloatArray dummy; + return sizeof(dummy) + sizeof(dummy.data[0]) * size; +} + +#ifndef TF_LITE_STATIC_MEMORY + +TfLiteFloatArray *TfLiteFloatArrayCreate(int size) +{ + TfLiteFloatArray *ret = + (TfLiteFloatArray *)malloc(TfLiteFloatArrayGetSizeInBytes(size)); + ret->size = size; + return ret; +} + +void TfLiteFloatArrayFree(TfLiteFloatArray *a) +{ + free(a); +} + +void TfLiteTensorDataFree(TfLiteTensor *t) +{ + if (t->allocation_type == kTfLiteDynamic || + t->allocation_type == kTfLitePersistentRo) { + free(t->data.raw); + } + t->data.raw = NULL; +} + +void TfLiteQuantizationFree(TfLiteQuantization *quantization) +{ + if (quantization->type == kTfLiteAffineQuantization) { + TfLiteAffineQuantization *q_params = + (TfLiteAffineQuantization *)(quantization->params); + if (q_params->scale) { + TfLiteFloatArrayFree(q_params->scale); + q_params->scale = NULL; + } + if (q_params->zero_point) { + TfLiteIntArrayFree(q_params->zero_point); + q_params->zero_point = NULL; + } + free(q_params); + } + quantization->params = NULL; + quantization->type = kTfLiteNoQuantization; +} + +void TfLiteSparsityFree(TfLiteSparsity *sparsity) +{ + if (sparsity == NULL) { + return; + } + + if (sparsity->traversal_order) { + TfLiteIntArrayFree(sparsity->traversal_order); + sparsity->traversal_order = NULL; + } + + if (sparsity->block_map) { + TfLiteIntArrayFree(sparsity->block_map); + sparsity->block_map = NULL; + } + + if (sparsity->dim_metadata) { + int i = 0; + for (; i < sparsity->dim_metadata_size; i++) { + TfLiteDimensionMetadata metadata = sparsity->dim_metadata[i]; + if (metadata.format == kTfLiteDimSparseCSR) { + TfLiteIntArrayFree(metadata.array_segments); + metadata.array_segments = NULL; + TfLiteIntArrayFree(metadata.array_indices); + metadata.array_indices = NULL; + } + } + free(sparsity->dim_metadata); + sparsity->dim_metadata = NULL; + } + + free(sparsity); +} + +void TfLiteTensorFree(TfLiteTensor *t) +{ + TfLiteTensorDataFree(t); + if (t->dims) + TfLiteIntArrayFree(t->dims); + t->dims = NULL; + + if (t->dims_signature) { + TfLiteIntArrayFree((TfLiteIntArray *)t->dims_signature); + } + t->dims_signature = NULL; + + TfLiteQuantizationFree(&t->quantization); + TfLiteSparsityFree(t->sparsity); + t->sparsity = NULL; +} + +void TfLiteTensorReset(TfLiteType type, const char *name, TfLiteIntArray *dims, + TfLiteQuantizationParams quantization, char *buffer, + size_t size, TfLiteAllocationType allocation_type, + const void *allocation, bool is_variable, + TfLiteTensor *tensor) +{ + TfLiteTensorFree(tensor); + tensor->type = type; + tensor->name = name; + tensor->dims = dims; + tensor->params = quantization; + tensor->data.raw = buffer; + tensor->bytes = size; + tensor->allocation_type = allocation_type; + tensor->allocation = allocation; + tensor->is_variable = is_variable; + + tensor->quantization.type = kTfLiteNoQuantization; + tensor->quantization.params = NULL; +} + +void TfLiteTensorRealloc(size_t num_bytes, TfLiteTensor *tensor) +{ + if (tensor->allocation_type != kTfLiteDynamic && + tensor->allocation_type != kTfLitePersistentRo) { + return; + } + // TODO(b/145340303): Tensor data should be aligned. + if (!tensor->data.raw) { + tensor->data.raw = (char *)malloc(num_bytes); + } else if (num_bytes > tensor->bytes) { + tensor->data.raw = (char *)realloc(tensor->data.raw, num_bytes); + } + tensor->bytes = num_bytes; +} +#endif // TF_LITE_STATIC_MEMORY + +const char *TfLiteTypeGetName(TfLiteType type) +{ + switch (type) { + case kTfLiteNoType: + return "NOTYPE"; + case kTfLiteFloat32: + return "FLOAT32"; + case kTfLiteInt16: + return "INT16"; + case kTfLiteInt32: + return "INT32"; + case kTfLiteUInt32: + return "UINT32"; + case kTfLiteUInt8: + return "UINT8"; + case kTfLiteInt8: + return "INT8"; + case kTfLiteInt64: + return "INT64"; + case kTfLiteUInt64: + return "UINT64"; + case kTfLiteBool: + return "BOOL"; + case kTfLiteComplex64: + return "COMPLEX64"; + case kTfLiteComplex128: + return "COMPLEX128"; + case kTfLiteString: + return "STRING"; + case kTfLiteFloat16: + return "FLOAT16"; + case kTfLiteFloat64: + return "FLOAT64"; + case kTfLiteResource: + return "RESOURCE"; + case kTfLiteVariant: + return "VARIANT"; + } + return "Unknown type"; +} + +TfLiteDelegate TfLiteDelegateCreate(void) +{ + TfLiteDelegate d = { + .data_ = NULL, + .Prepare = NULL, + .CopyFromBufferHandle = NULL, + .CopyToBufferHandle = NULL, + .FreeBufferHandle = NULL, + .flags = kTfLiteDelegateFlagsNone, + }; + return d; +} diff --git a/components/tflite/tensorflow/lite/c/common.h b/components/tflite/tensorflow/lite/c/common.h new file mode 100644 index 00000000..51b9bbfa --- /dev/null +++ b/components/tflite/tensorflow/lite/c/common.h @@ -0,0 +1,952 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// This file defines common C types and APIs for implementing operations, +// delegates and other constructs in TensorFlow Lite. The actual operations and +// delegates can be defined using C++, but the interface between the interpreter +// and the operations are C. +// +// Summary of abstractions +// TF_LITE_ENSURE - Self-sufficient error checking +// TfLiteStatus - Status reporting +// TfLiteIntArray - stores tensor shapes (dims), +// TfLiteContext - allows an op to access the tensors +// TfLiteTensor - tensor (a multidimensional array) +// TfLiteNode - a single node or operation +// TfLiteRegistration - the implementation of a conceptual operation. +// TfLiteDelegate - allows delegation of nodes to alternative backends. +// +// Some abstractions in this file are created and managed by Interpreter. +// +// NOTE: The order of values in these structs are "semi-ABI stable". New values +// should be added only to the end of structs and never reordered. + +#ifndef TENSORFLOW_LITE_C_COMMON_H_ +#define TENSORFLOW_LITE_C_COMMON_H_ + +#include +#include +#include + +#include "tensorflow/lite/c/c_api_types.h" // IWYU pragma: export + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +// The list of external context types known to TF Lite. This list exists solely +// to avoid conflicts and to ensure ops can share the external contexts they +// need. Access to the external contexts is controlled by one of the +// corresponding support files. +typedef enum TfLiteExternalContextType { + kTfLiteEigenContext = 0, // include eigen_support.h to use. + kTfLiteGemmLowpContext = 1, // include gemm_support.h to use. + kTfLiteEdgeTpuContext = 2, // Placeholder for Edge TPU support. + kTfLiteCpuBackendContext = 3, // include cpu_backend_context.h to use. + kTfLiteMaxExternalContexts = 4 +} TfLiteExternalContextType; + +// Forward declare so dependent structs and methods can reference these types +// prior to the struct definitions. +struct TfLiteContext; +struct TfLiteDelegate; +struct TfLiteRegistration; + +// An external context is a collection of information unrelated to the TF Lite +// framework, but useful to a subset of the ops. TF Lite knows very little +// about the actual contexts, but it keeps a list of them, and is able to +// refresh them if configurations like the number of recommended threads +// change. +typedef struct TfLiteExternalContext { + TfLiteExternalContextType type; + TfLiteStatus (*Refresh)(struct TfLiteContext *context); +} TfLiteExternalContext; + +#define kTfLiteOptionalTensor (-1) + +// Fixed size list of integers. Used for dimensions and inputs/outputs tensor +// indices +typedef struct TfLiteIntArray { + int size; +// gcc 6.1+ have a bug where flexible members aren't properly handled +// https://github.com/google/re2/commit/b94b7cd42e9f02673cd748c1ac1d16db4052514c +#if (!defined(__clang__) && defined(__GNUC__) && __GNUC__ == 6 && \ + __GNUC_MINOR__ >= 1) || \ + defined(HEXAGON) || \ + (defined(__clang__) && __clang_major__ == 7 && __clang_minor__ == 1) + int data[0]; +#else + int data[]; +#endif +} TfLiteIntArray; + +// Given the size (number of elements) in a TfLiteIntArray, calculate its size +// in bytes. +int TfLiteIntArrayGetSizeInBytes(int size); + +#ifndef TF_LITE_STATIC_MEMORY +// Create a array of a given `size` (uninitialized entries). +// This returns a pointer, that you must free using TfLiteIntArrayFree(). +TfLiteIntArray *TfLiteIntArrayCreate(int size); +#endif + +// Check if two intarrays are equal. Returns 1 if they are equal, 0 otherwise. +int TfLiteIntArrayEqual(const TfLiteIntArray *a, const TfLiteIntArray *b); + +// Check if an intarray equals an array. Returns 1 if equals, 0 otherwise. +int TfLiteIntArrayEqualsArray(const TfLiteIntArray *a, int b_size, + const int b_data[]); + +#ifndef TF_LITE_STATIC_MEMORY +// Create a copy of an array passed as `src`. +// You are expected to free memory with TfLiteIntArrayFree +TfLiteIntArray *TfLiteIntArrayCopy(const TfLiteIntArray *src); + +// Free memory of array `a`. +void TfLiteIntArrayFree(TfLiteIntArray *a); +#endif // TF_LITE_STATIC_MEMORY + +// Fixed size list of floats. Used for per-channel quantization. +typedef struct TfLiteFloatArray { + int size; +// gcc 6.1+ have a bug where flexible members aren't properly handled +// https://github.com/google/re2/commit/b94b7cd42e9f02673cd748c1ac1d16db4052514c +// This also applies to the toolchain used for Qualcomm Hexagon DSPs. +#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ == 6 && \ + __GNUC_MINOR__ >= 1 + float data[0]; +#else + float data[]; +#endif +} TfLiteFloatArray; + +// Given the size (number of elements) in a TfLiteFloatArray, calculate its size +// in bytes. +int TfLiteFloatArrayGetSizeInBytes(int size); + +#ifndef TF_LITE_STATIC_MEMORY +// Create a array of a given `size` (uninitialized entries). +// This returns a pointer, that you must free using TfLiteFloatArrayFree(). +TfLiteFloatArray *TfLiteFloatArrayCreate(int size); + +// Free memory of array `a`. +void TfLiteFloatArrayFree(TfLiteFloatArray *a); +#endif // TF_LITE_STATIC_MEMORY + +// Since we must not depend on any libraries, define a minimal subset of +// error macros while avoiding names that have pre-conceived meanings like +// assert and check. + +// Try to make all reporting calls through TF_LITE_KERNEL_LOG rather than +// calling the context->ReportError function directly, so that message strings +// can be stripped out if the binary size needs to be severely optimized. +#ifndef TF_LITE_STRIP_ERROR_STRINGS +#define TF_LITE_KERNEL_LOG(context, ...) \ + do { \ + (context)->ReportError((context), __VA_ARGS__); \ + } while (false) + +#define TF_LITE_MAYBE_KERNEL_LOG(context, ...) \ + do { \ + if ((context) != nullptr) { \ + (context)->ReportError((context), __VA_ARGS__); \ + } \ + } while (false) +#else // TF_LITE_STRIP_ERROR_STRINGS +#define TF_LITE_KERNEL_LOG(context, ...) +#define TF_LITE_MAYBE_KERNEL_LOG(context, ...) +#endif // TF_LITE_STRIP_ERROR_STRINGS + +// Check whether value is true, and if not return kTfLiteError from +// the current function (and report the error string msg). +#define TF_LITE_ENSURE_MSG(context, value, msg) \ + do { \ + if (!(value)) { \ + TF_LITE_KERNEL_LOG((context), __FILE__ " " msg); \ + return kTfLiteError; \ + } \ + } while (0) + +// Check whether the value `a` is true, and if not return kTfLiteError from +// the current function, while also reporting the location of the error. +#define TF_LITE_ENSURE(context, a) \ + do { \ + if (!(a)) { \ + TF_LITE_KERNEL_LOG((context), "%s:%d %s was not true.", __FILE__, \ + __LINE__, #a); \ + return kTfLiteError; \ + } \ + } while (0) + +#define TF_LITE_ENSURE_STATUS(a) \ + do { \ + const TfLiteStatus s = (a); \ + if (s != kTfLiteOk) { \ + return s; \ + } \ + } while (0) + +// Check whether the value `a == b` is true, and if not return kTfLiteError from +// the current function, while also reporting the location of the error. +// `a` and `b` may be evaluated more than once, so no side effects or +// extremely expensive computations should be done. +// NOTE: Use TF_LITE_ENSURE_TYPES_EQ if comparing TfLiteTypes. +#define TF_LITE_ENSURE_EQ(context, a, b) \ + do { \ + if ((a) != (b)) { \ + TF_LITE_KERNEL_LOG((context), "%s:%d %s != %s (%d != %d)", __FILE__, \ + __LINE__, #a, #b, (a), (b)); \ + return kTfLiteError; \ + } \ + } while (0) + +#define TF_LITE_ENSURE_TYPES_EQ(context, a, b) \ + do { \ + if ((a) != (b)) { \ + TF_LITE_KERNEL_LOG((context), "%s:%d %s != %s (%s != %s)", __FILE__, \ + __LINE__, #a, #b, TfLiteTypeGetName(a), \ + TfLiteTypeGetName(b)); \ + return kTfLiteError; \ + } \ + } while (0) + +#define TF_LITE_ENSURE_NEAR(context, a, b, epsilon) \ + do { \ + auto delta = ((a) > (b)) ? ((a) - (b)) : ((b) - (a)); \ + if (delta > epsilon) { \ + TF_LITE_KERNEL_LOG((context), "%s:%d %s not near %s (%f != %f)", \ + __FILE__, __LINE__, #a, #b, static_cast(a), \ + static_cast(b)); \ + return kTfLiteError; \ + } \ + } while (0) + +#define TF_LITE_ENSURE_OK(context, status) \ + do { \ + const TfLiteStatus s = (status); \ + if ((s) != kTfLiteOk) { \ + return s; \ + } \ + } while (0) + +// Single-precision complex data type compatible with the C99 definition. +typedef struct TfLiteComplex64 { + float re, im; // real and imaginary parts, respectively. +} TfLiteComplex64; + +// Double-precision complex data type compatible with the C99 definition. +typedef struct TfLiteComplex128 { + double re, im; // real and imaginary parts, respectively. +} TfLiteComplex128; + +// Half precision data type compatible with the C99 definition. +typedef struct TfLiteFloat16 { + uint16_t data; +} TfLiteFloat16; + +// Return the name of a given type, for error reporting purposes. +const char *TfLiteTypeGetName(TfLiteType type); + +// SupportedQuantizationTypes. +typedef enum TfLiteQuantizationType { + // No quantization. + kTfLiteNoQuantization = 0, + // Affine quantization (with support for per-channel quantization). + // Corresponds to TfLiteAffineQuantization. + kTfLiteAffineQuantization = 1, +} TfLiteQuantizationType; + +// Structure specifying the quantization used by the tensor, if-any. +typedef struct TfLiteQuantization { + // The type of quantization held by params. + TfLiteQuantizationType type; + // Holds an optional reference to a quantization param structure. The actual + // type depends on the value of the `type` field (see the comment there for + // the values and corresponding types). + void *params; +} TfLiteQuantization; + +// Parameters for asymmetric quantization across a dimension (i.e per output +// channel quantization). +// quantized_dimension specifies which dimension the scales and zero_points +// correspond to. +// For a particular value in quantized_dimension, quantized values can be +// converted back to float using: +// real_value = scale * (quantized_value - zero_point) +typedef struct TfLiteAffineQuantization { + TfLiteFloatArray *scale; + TfLiteIntArray *zero_point; + int32_t quantized_dimension; +} TfLiteAffineQuantization; + +/* A union of pointers that points to memory for a given tensor. */ +typedef union TfLitePtrUnion { + /* Do not access these members directly, if possible, use + * GetTensorData(tensor) instead, otherwise only access .data, as other + * members are deprecated. */ + int32_t *i32; + uint32_t *u32; + int64_t *i64; + uint64_t *u64; + float *f; + TfLiteFloat16 *f16; + double *f64; + char *raw; + const char *raw_const; + uint8_t *uint8; + bool *b; + int16_t *i16; + TfLiteComplex64 *c64; + TfLiteComplex128 *c128; + int8_t *int8; + /* Only use this member. */ + void *data; +} TfLitePtrUnion; + +// Memory allocation strategies. +// * kTfLiteMmapRo: Read-only memory-mapped data, or data externally allocated. +// * kTfLiteArenaRw: Arena allocated with no guarantees about persistence, +// and available during eval. +// * kTfLiteArenaRwPersistent: Arena allocated but persistent across eval, and +// only available during eval. +// * kTfLiteDynamic: Allocated during eval, or for string tensors. +// * kTfLitePersistentRo: Allocated and populated during prepare. This is +// useful for tensors that can be computed during prepare and treated +// as constant inputs for downstream ops (also in prepare). +// * kTfLiteCustom: Custom memory allocation provided by the user. See +// TfLiteCustomAllocation below. +typedef enum TfLiteAllocationType { + kTfLiteMemNone = 0, + kTfLiteMmapRo, + kTfLiteArenaRw, + kTfLiteArenaRwPersistent, + kTfLiteDynamic, + kTfLitePersistentRo, + kTfLiteCustom, +} TfLiteAllocationType; + +// The delegates should use zero or positive integers to represent handles. +// -1 is reserved from unallocated status. +typedef int TfLiteBufferHandle; +enum { + kTfLiteNullBufferHandle = -1, +}; + +// Storage format of each dimension in a sparse tensor. +typedef enum TfLiteDimensionType { + kTfLiteDimDense = 0, + kTfLiteDimSparseCSR, +} TfLiteDimensionType; + +// Metadata to encode each dimension in a sparse tensor. +typedef struct TfLiteDimensionMetadata { + TfLiteDimensionType format; + int dense_size; + TfLiteIntArray *array_segments; + TfLiteIntArray *array_indices; +} TfLiteDimensionMetadata; + +// Parameters used to encode a sparse tensor. For detailed explanation of each +// field please refer to lite/schema/schema.fbs. +typedef struct TfLiteSparsity { + TfLiteIntArray *traversal_order; + TfLiteIntArray *block_map; + TfLiteDimensionMetadata *dim_metadata; + int dim_metadata_size; +} TfLiteSparsity; + +// Defines a custom memory allocation not owned by the runtime. +// `data` should be aligned to kDefaultTensorAlignment defined in +// lite/util.h. (Currently 64 bytes) +// NOTE: See Interpreter.SetCustomAllocationForTensor for details on usage. +typedef struct TfLiteCustomAllocation { + void *data; + size_t bytes; +} TfLiteCustomAllocation; + +// The flags used in `Interpreter::SetCustomAllocationForTensor`. +// Note that this is a bitmask, so the values should be 1, 2, 4, 8, ...etc. +typedef enum TfLiteCustomAllocationFlags { + kTfLiteCustomAllocationFlagsNone = 0, + // Skips checking whether allocation.data points to an aligned buffer as + // expected by the TFLite runtime. + // NOTE: Setting this flag can cause crashes when calling Invoke(). + // Use with caution. + kTfLiteCustomAllocationFlagsSkipAlignCheck = 1, +} TfLiteCustomAllocationFlags; + +// A tensor in the interpreter system which is a wrapper around a buffer of +// data including a dimensionality (or NULL if not currently defined). +#ifndef TF_LITE_STATIC_MEMORY +typedef struct TfLiteTensor { + // The data type specification for data stored in `data`. This affects + // what member of `data` union should be used. + TfLiteType type; + // A union of data pointers. The appropriate type should be used for a typed + // tensor based on `type`. + TfLitePtrUnion data; + // A pointer to a structure representing the dimensionality interpretation + // that the buffer should have. NOTE: the product of elements of `dims` + // and the element datatype size should be equal to `bytes` below. + TfLiteIntArray *dims; + // Quantization information. + TfLiteQuantizationParams params; + // How memory is mapped + // kTfLiteMmapRo: Memory mapped read only. + // i.e. weights + // kTfLiteArenaRw: Arena allocated read write memory + // (i.e. temporaries, outputs). + TfLiteAllocationType allocation_type; + // The number of bytes required to store the data of this Tensor. I.e. + // (bytes of each element) * dims[0] * ... * dims[n-1]. For example, if + // type is kTfLiteFloat32 and dims = {3, 2} then + // bytes = sizeof(float) * 3 * 2 = 4 * 3 * 2 = 24. + size_t bytes; + + // An opaque pointer to a tflite::MMapAllocation + const void *allocation; + + // Null-terminated name of this tensor. + const char *name; + + // The delegate which knows how to handle `buffer_handle`. + // WARNING: This is an experimental interface that is subject to change. + struct TfLiteDelegate *delegate; + + // An integer buffer handle that can be handled by `delegate`. + // The value is valid only when delegate is not null. + // WARNING: This is an experimental interface that is subject to change. + TfLiteBufferHandle buffer_handle; + + // If the delegate uses its own buffer (e.g. GPU memory), the delegate is + // responsible to set data_is_stale to true. + // `delegate->CopyFromBufferHandle` can be called to copy the data from + // delegate buffer. + // WARNING: This is an // experimental interface that is subject to change. + bool data_is_stale; + + // True if the tensor is a variable. + bool is_variable; + + // Quantization information. Replaces params field above. + TfLiteQuantization quantization; + + // Parameters used to encode a sparse tensor. + // This is optional. The field is NULL if a tensor is dense. + // WARNING: This is an experimental interface that is subject to change. + TfLiteSparsity *sparsity; + + // Optional. Encodes shapes with unknown dimensions with -1. This field is + // only populated when unknown dimensions exist in a read-write tensor (i.e. + // an input or output tensor). (e.g. `dims` contains [1, 1, 1, 3] and + // `dims_signature` contains [1, -1, -1, 3]). + const TfLiteIntArray *dims_signature; +} TfLiteTensor; + +// A structure representing an instance of a node. +// This structure only exhibits the inputs, outputs, user defined data and some +// node properties (like statefulness), not other features like the type. +typedef struct TfLiteNode { + // Inputs to this node expressed as indices into the simulator's tensors. + TfLiteIntArray *inputs; + + // Outputs to this node expressed as indices into the simulator's tensors. + TfLiteIntArray *outputs; + + // intermediate tensors to this node expressed as indices into the simulator's + // tensors. + TfLiteIntArray *intermediates; + + // Temporary tensors uses during the computations. This usually contains no + // tensors, but ops are allowed to change that if they need scratch space of + // any sort. + TfLiteIntArray *temporaries; + + // Opaque data provided by the node implementer through `Registration.init`. + void *user_data; + + // Opaque data provided to the node if the node is a builtin. This is usually + // a structure defined in builtin_op_data.h + void *builtin_data; + + // Custom initial data. This is the opaque data provided in the flatbuffer. + // WARNING: This is an experimental interface that is subject to change. + const void *custom_initial_data; + int custom_initial_data_size; + + // The pointer to the delegate. This is non-null only when the node is + // created by calling `interpreter.ModifyGraphWithDelegate`. + // WARNING: This is an experimental interface that is subject to change. + struct TfLiteDelegate *delegate; + + // Whether this op might have side effect (e.g. stateful op). + bool might_have_side_effect; +} TfLiteNode; +#else // defined(TF_LITE_STATIC_MEMORY)? +// NOTE: This flag is opt-in only at compile time. +// +// Specific reduced TfLiteTensor struct for TF Micro runtime. This struct +// contains only the minimum fields required to initialize and prepare a micro +// inference graph. The fields in this struct have been ordered from +// largest-to-smallest for optimal struct sizeof. +// +// This struct does not use: +// - allocation +// - buffer_handle +// - data_is_stale +// - delegate +// - dims_signature +// - name +// - sparsity +typedef struct TfLiteTensor { + // TODO(b/155784997): Consider consolidating these quantization fields: + // Quantization information. Replaces params field above. + TfLiteQuantization quantization; + + // Quantization information. + TfLiteQuantizationParams params; + + // A union of data pointers. The appropriate type should be used for a typed + // tensor based on `type`. + TfLitePtrUnion data; + + // A pointer to a structure representing the dimensionality interpretation + // that the buffer should have. NOTE: the product of elements of `dims` + // and the element datatype size should be equal to `bytes` below. + TfLiteIntArray *dims; + + // The number of bytes required to store the data of this Tensor. I.e. + // (bytes of each element) * dims[0] * ... * dims[n-1]. For example, if + // type is kTfLiteFloat32 and dims = {3, 2} then + // bytes = sizeof(float) * 3 * 2 = 4 * 3 * 2 = 24. + size_t bytes; + + // The data type specification for data stored in `data`. This affects + // what member of `data` union should be used. + TfLiteType type; + + // How memory is mapped + // kTfLiteMmapRo: Memory mapped read only. + // i.e. weights + // kTfLiteArenaRw: Arena allocated read write memory + // (i.e. temporaries, outputs). + TfLiteAllocationType allocation_type; + + // True if the tensor is a variable. + bool is_variable; +} TfLiteTensor; + +// Specific reduced TfLiteNode struct for TF Micro runtime. This struct contains +// only the minimum fields required to represent a node. +// +// This struct does not use: +// - delegate +// - intermediates +// - temporaries +typedef struct TfLiteNode { + // Inputs to this node expressed as indices into the simulator's tensors. + TfLiteIntArray *inputs; + + // Outputs to this node expressed as indices into the simulator's tensors. + TfLiteIntArray *outputs; + + // Opaque data provided by the node implementer through `Registration.init`. + void *user_data; + + // Opaque data provided to the node if the node is a builtin. This is usually + // a structure defined in builtin_op_data.h + void *builtin_data; + + // Custom initial data. This is the opaque data provided in the flatbuffer. + // WARNING: This is an experimental interface that is subject to change. + const void *custom_initial_data; + int custom_initial_data_size; +} TfLiteNode; +#endif // TF_LITE_STATIC_MEMORY + +// Light-weight tensor struct for TF Micro runtime. Provides the minimal amount +// of information required for a kernel to run during TfLiteRegistration::Eval. +// TODO(b/160955687): Move this field into TF_LITE_STATIC_MEMORY when TFLM +// builds with this flag by default internally. +typedef struct TfLiteEvalTensor { + // A union of data pointers. The appropriate type should be used for a typed + // tensor based on `type`. + TfLitePtrUnion data; + + // A pointer to a structure representing the dimensionality interpretation + // that the buffer should have. + TfLiteIntArray *dims; + + // The data type specification for data stored in `data`. This affects + // what member of `data` union should be used. + TfLiteType type; +} TfLiteEvalTensor; + +#ifndef TF_LITE_STATIC_MEMORY +// Free data memory of tensor `t`. +void TfLiteTensorDataFree(TfLiteTensor *t); + +// Free quantization data. +void TfLiteQuantizationFree(TfLiteQuantization *quantization); + +// Free sparsity parameters. +void TfLiteSparsityFree(TfLiteSparsity *sparsity); + +// Free memory of tensor `t`. +void TfLiteTensorFree(TfLiteTensor *t); + +// Set all of a tensor's fields (and free any previously allocated data). +void TfLiteTensorReset(TfLiteType type, const char *name, TfLiteIntArray *dims, + TfLiteQuantizationParams quantization, char *buffer, + size_t size, TfLiteAllocationType allocation_type, + const void *allocation, bool is_variable, + TfLiteTensor *tensor); + +// Resize the allocated data of a (dynamic) tensor. Tensors with allocation +// types other than kTfLiteDynamic will be ignored. +void TfLiteTensorRealloc(size_t num_bytes, TfLiteTensor *tensor); +#endif // TF_LITE_STATIC_MEMORY + +// WARNING: This is an experimental interface that is subject to change. +// +// Currently, TfLiteDelegateParams has to be allocated in a way that it's +// trivially destructable. It will be stored as `builtin_data` field in +// `TfLiteNode` of the delegate node. +// +// See also the `CreateDelegateParams` function in `interpreter.cc` details. +typedef struct TfLiteDelegateParams { + struct TfLiteDelegate *delegate; + TfLiteIntArray *nodes_to_replace; + TfLiteIntArray *input_tensors; + TfLiteIntArray *output_tensors; +} TfLiteDelegateParams; + +typedef struct TfLiteContext { + // Number of tensors in the context. + size_t tensors_size; + + // The execution plan contains a list of the node indices in execution + // order. execution_plan->size is the current number of nodes. And, + // execution_plan->data[0] is the first node that needs to be run. + // TfLiteDelegates can traverse the current execution plan by iterating + // through each member of this array and using GetNodeAndRegistration() to + // access details about a node. i.e. + // + // TfLiteIntArray* execution_plan; + // TF_LITE_ENSURE_STATUS(context->GetExecutionPlan(context, &execution_plan)); + // for (int exec_index = 0; exec_index < execution_plan->size; exec_index++) { + // int node_index = execution_plan->data[exec_index]; + // TfLiteNode* node; + // TfLiteRegistration* reg; + // context->GetNodeAndRegistration(context, node_index, &node, ®); + // } + // Note: the memory pointed by '`*execution_plan` is OWNED by TfLite runtime. + // Future calls to GetExecutionPlan invalidates earlier outputs. The following + // code snippet shows the issue of such an invocation pattern. After calling + // CheckNode, subsequent access to `plan_1st` is undefined. + // + // void CheckNode(const TfLiteNode* node) { + // ... + // TfLiteIntArray* plan_2nd; + // TF_LITE_ENSURE_STATUS(context->GetExecutionPlan(context, &plan_2nd)); + // ... + // } + // + // TfLiteIntArray* plan_1st; + // TF_LITE_ENSURE_STATUS(context->GetExecutionPlan(context, &plan_1st)); + // for (int exec_index = 0; exec_index < plan_1st->size; exec_index++) { + // int node_index = plan_1st->data[exec_index]; + // TfLiteNode* node; + // TfLiteRegistration* reg; + // context->GetNodeAndRegistration(context, node_index, &node, ®); + // CheckNode(node); + // } + // + // WARNING: This is an experimental interface that is subject to change. + TfLiteStatus (*GetExecutionPlan)(struct TfLiteContext *context, + TfLiteIntArray **execution_plan); + + // An array of tensors in the interpreter context (of length `tensors_size`) + TfLiteTensor *tensors; + + // opaque full context ptr (an opaque c++ data structure) + void *impl_; + + // Request memory pointer be resized. Updates dimensions on the tensor. + // NOTE: ResizeTensor takes ownership of newSize. + TfLiteStatus (*ResizeTensor)(struct TfLiteContext *, TfLiteTensor *tensor, + TfLiteIntArray *new_size); + // Request that an error be reported with format string msg. + void (*ReportError)(struct TfLiteContext *, const char *msg, ...); + + // Add `tensors_to_add` tensors, preserving pre-existing Tensor entries. If + // non-null, the value pointed to by `first_new_tensor_index` will be set to + // the index of the first new tensor. + TfLiteStatus (*AddTensors)(struct TfLiteContext *, int tensors_to_add, + int *first_new_tensor_index); + + // Get a Tensor node by node_index. + // WARNING: This is an experimental interface that is subject to change. + TfLiteStatus (*GetNodeAndRegistration)( + struct TfLiteContext *, int node_index, TfLiteNode **node, + struct TfLiteRegistration **registration); + + // Replace ops with one or more stub delegate operations. This function + // does not take ownership of `nodes_to_replace`. + TfLiteStatus (*ReplaceNodeSubsetsWithDelegateKernels)( + struct TfLiteContext *, struct TfLiteRegistration registration, + const TfLiteIntArray *nodes_to_replace, struct TfLiteDelegate *delegate); + + // Number of threads that are recommended to subsystems like gemmlowp and + // eigen. + int recommended_num_threads; + + // Access external contexts by type. + // WARNING: This is an experimental interface that is subject to change. + TfLiteExternalContext *(*GetExternalContext)(struct TfLiteContext *, + TfLiteExternalContextType); + // Set the value of a external context. Does not take ownership of the + // pointer. + // WARNING: This is an experimental interface that is subject to change. + void (*SetExternalContext)(struct TfLiteContext *, TfLiteExternalContextType, + TfLiteExternalContext *); + + // Flag for allowing float16 precision for FP32 calculation. + // default: false. + // WARNING: This is an experimental API and subject to change. + bool allow_fp32_relax_to_fp16; + + // Pointer to the op-level profiler, if set; nullptr otherwise. + void *profiler; + + // Allocate persistent buffer which has the same life time as the interpreter. + // Returns nullptr on failure. + // The memory is allocated from heap for TFL, and from tail in TFLM. + // This method is only available in Init or Prepare stage. + // WARNING: This is an experimental interface that is subject to change. + void *(*AllocatePersistentBuffer)(struct TfLiteContext *ctx, size_t bytes); + + // Allocate a buffer which will be deallocated right after invoke phase. + // The memory is allocated from heap in TFL, and from volatile arena in TFLM. + // This method is only available in invoke stage. + // NOTE: If possible use RequestScratchBufferInArena method to avoid memory + // allocation during inference time. + // WARNING: This is an experimental interface that is subject to change. + TfLiteStatus (*AllocateBufferForEval)(struct TfLiteContext *ctx, size_t bytes, + void **ptr); + + // Request a scratch buffer in the arena through static memory planning. + // This method is only available in Prepare stage and the buffer is allocated + // by the interpreter between Prepare and Eval stage. In Eval stage, + // GetScratchBuffer API can be used to fetch the address. + // WARNING: This is an experimental interface that is subject to change. + TfLiteStatus (*RequestScratchBufferInArena)(struct TfLiteContext *ctx, + size_t bytes, int *buffer_idx); + + // Get the scratch buffer pointer. + // This method is only available in Eval stage. + // WARNING: This is an experimental interface that is subject to change. + void *(*GetScratchBuffer)(struct TfLiteContext *ctx, int buffer_idx); + + // Resize the memory pointer of the `tensor`. This method behaves the same as + // `ResizeTensor`, except that it makes a copy of the shape array internally + // so the shape array could be deallocated right afterwards. + // WARNING: This is an experimental interface that is subject to change. + TfLiteStatus (*ResizeTensorExplicit)(struct TfLiteContext *ctx, + TfLiteTensor *tensor, int dims, + const int *shape); + + // This method provides a preview of post-delegation partitioning. Each + // TfLiteDelegateParams in the referenced array corresponds to one instance of + // the delegate kernel. + // Example usage: + // + // TfLiteIntArray* nodes_to_replace = ...; + // TfLiteDelegateParams* params_array; + // int num_partitions = 0; + // TF_LITE_ENSURE_STATUS(context->PreviewDelegatePartitioning( + // context, delegate, nodes_to_replace, ¶ms_array, &num_partitions)); + // for (int idx = 0; idx < num_partitions; idx++) { + // const auto& partition_params = params_array[idx]; + // ... + // } + // + // NOTE: The context owns the memory referenced by partition_params_array. It + // will be cleared with another call to PreviewDelegateParitioning, or after + // TfLiteDelegateParams::Prepare returns. + // + // WARNING: This is an experimental interface that is subject to change. + TfLiteStatus (*PreviewDelegatePartitioning)( + struct TfLiteContext *context, const TfLiteIntArray *nodes_to_replace, + TfLiteDelegateParams **partition_params_array, int *num_partitions); + + // Returns a TfLiteTensor struct for a given index. + // WARNING: This is an experimental interface that is subject to change. + // WARNING: This method may not be available on all platforms. + TfLiteTensor *(*GetTensor)(const struct TfLiteContext *context, + int tensor_idx); + + // Returns a TfLiteEvalTensor struct for a given index. + // WARNING: This is an experimental interface that is subject to change. + // WARNING: This method may not be available on all platforms. + TfLiteEvalTensor *(*GetEvalTensor)(const struct TfLiteContext *context, + int tensor_idx); +} TfLiteContext; + +typedef struct TfLiteRegistration { + // Initializes the op from serialized data. + // If a built-in op: + // `buffer` is the op's params data (TfLiteLSTMParams*). + // `length` is zero. + // If custom op: + // `buffer` is the op's `custom_options`. + // `length` is the size of the buffer. + // + // Returns a type-punned (i.e. void*) opaque data (e.g. a primitive pointer + // or an instance of a struct). + // + // The returned pointer will be stored with the node in the `user_data` field, + // accessible within prepare and invoke functions below. + // NOTE: if the data is already in the desired format, simply implement this + // function to return `nullptr` and implement the free function to be a no-op. + void *(*init)(TfLiteContext *context, const char *buffer, size_t length); + + // The pointer `buffer` is the data previously returned by an init invocation. + void (*free)(TfLiteContext *context, void *buffer); + + // prepare is called when the inputs this node depends on have been resized. + // context->ResizeTensor() can be called to request output tensors to be + // resized. + // + // Returns kTfLiteOk on success. + TfLiteStatus (*prepare)(TfLiteContext *context, TfLiteNode *node); + + // Execute the node (should read node->inputs and output to node->outputs). + // Returns kTfLiteOk on success. + TfLiteStatus (*invoke)(TfLiteContext *context, TfLiteNode *node); + + // profiling_string is called during summarization of profiling information + // in order to group executions together. Providing a value here will cause a + // given op to appear multiple times is the profiling report. This is + // particularly useful for custom ops that can perform significantly + // different calculations depending on their `user-data`. + const char *(*profiling_string)(const TfLiteContext *context, + const TfLiteNode *node); + + // Builtin codes. If this kernel refers to a builtin this is the code + // of the builtin. This is so we can do marshaling to other frameworks like + // NN API. + // Note: It is the responsibility of the registration binder to set this + // properly. + int32_t builtin_code; + + // Custom op name. If the op is a builtin, this will be null. + // Note: It is the responsibility of the registration binder to set this + // properly. + // WARNING: This is an experimental interface that is subject to change. + const char *custom_name; + + // The version of the op. + // Note: It is the responsibility of the registration binder to set this + // properly. + int version; +} TfLiteRegistration; + +// The flags used in `TfLiteDelegate`. Note that this is a bitmask, so the +// values should be 1, 2, 4, 8, ...etc. +typedef enum TfLiteDelegateFlags { + kTfLiteDelegateFlagsNone = 0, + // The flag is set if the delegate can handle dynamic sized tensors. + // For example, the output shape of a `Resize` op with non-constant shape + // can only be inferred when the op is invoked. + // In this case, the Delegate is responsible for calling + // `SetTensorToDynamic` to mark the tensor as a dynamic tensor, and calling + // `ResizeTensor` when invoking the op. + // + // If the delegate isn't capable to handle dynamic tensors, this flag need + // to be set to false. + kTfLiteDelegateFlagsAllowDynamicTensors = 1, + + // This flag can be used by delegates (that allow dynamic tensors) to ensure + // applicable tensor shapes are automatically propagated in the case of tensor + // resizing. + // This means that non-dynamic (allocation_type != kTfLiteDynamic) I/O tensors + // of a delegate kernel will have correct shapes before its Prepare() method + // is called. The runtime leverages TFLite builtin ops in the original + // execution plan to propagate shapes. + // + // A few points to note: + // 1. This requires kTfLiteDelegateFlagsAllowDynamicTensors. If that flag is + // false, this one is redundant since the delegate kernels are re-initialized + // every time tensors are resized. + // 2. Enabling this flag adds some overhead to AllocateTensors(), since extra + // work is required to prepare the original execution plan. + // 3. This flag requires that the original execution plan only have ops with + // valid registrations (and not 'dummy' custom ops like with Flex). + // WARNING: This feature is experimental and subject to change. + kTfLiteDelegateFlagsRequirePropagatedShapes = 2 +} TfLiteDelegateFlags; + +// WARNING: This is an experimental interface that is subject to change. +typedef struct TfLiteDelegate { + // Data that delegate needs to identify itself. This data is owned by the + // delegate. The delegate is owned in the user code, so the delegate is + // responsible for doing this when it is destroyed. + void *data_; + + // Invoked by ModifyGraphWithDelegate. This prepare is called, giving the + // delegate a view of the current graph through TfLiteContext*. It typically + // will look at the nodes and call ReplaceNodeSubsetsWithDelegateKernels() + // to ask the TensorFlow lite runtime to create macro-nodes to represent + // delegated subgraphs of the original graph. + TfLiteStatus (*Prepare)(TfLiteContext *context, + struct TfLiteDelegate *delegate); + + // Copy the data from delegate buffer handle into raw memory of the given + // 'tensor'. Note that the delegate is allowed to allocate the raw bytes as + // long as it follows the rules for kTfLiteDynamic tensors, in which case this + // cannot be null. + TfLiteStatus (*CopyFromBufferHandle)(TfLiteContext *context, + struct TfLiteDelegate *delegate, + TfLiteBufferHandle buffer_handle, + TfLiteTensor *tensor); + + // Copy the data from raw memory of the given 'tensor' to delegate buffer + // handle. This can be null if the delegate doesn't use its own buffer. + TfLiteStatus (*CopyToBufferHandle)(TfLiteContext *context, + struct TfLiteDelegate *delegate, + TfLiteBufferHandle buffer_handle, + TfLiteTensor *tensor); + + // Free the Delegate Buffer Handle. Note: This only frees the handle, but + // this doesn't release the underlying resource (e.g. textures). The + // resources are either owned by application layer or the delegate. + // This can be null if the delegate doesn't use its own buffer. + void (*FreeBufferHandle)(TfLiteContext *context, + struct TfLiteDelegate *delegate, + TfLiteBufferHandle *handle); + + // Bitmask flags. See the comments in `TfLiteDelegateFlags`. + int64_t flags; +} TfLiteDelegate; + +// Build a 'null' delegate, with all the fields properly set to their default +// values. +TfLiteDelegate TfLiteDelegateCreate(void); + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus +#endif // TENSORFLOW_LITE_C_COMMON_H_ diff --git a/components/tflite/tensorflow/lite/core/api/error_reporter.cc b/components/tflite/tensorflow/lite/core/api/error_reporter.cc new file mode 100644 index 00000000..f290d891 --- /dev/null +++ b/components/tflite/tensorflow/lite/core/api/error_reporter.cc @@ -0,0 +1,40 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/core/api/error_reporter.h" +#include + +namespace tflite { + +int ErrorReporter::Report(const char *format, ...) +{ + va_list args; + va_start(args, format); + int code = Report(format, args); + va_end(args); + return code; +} + +// TODO(aselle): Make the name of ReportError on context the same, so +// we can use the ensure functions w/o a context and w/ a reporter. +int ErrorReporter::ReportError(void *, const char *format, ...) +{ + va_list args; + va_start(args, format); + int code = Report(format, args); + va_end(args); + return code; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/core/api/error_reporter.h b/components/tflite/tensorflow/lite/core/api/error_reporter.h new file mode 100644 index 00000000..c5371e55 --- /dev/null +++ b/components/tflite/tensorflow/lite/core/api/error_reporter.h @@ -0,0 +1,60 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_CORE_API_ERROR_REPORTER_H_ +#define TENSORFLOW_LITE_CORE_API_ERROR_REPORTER_H_ + +#include + +namespace tflite { +/// A functor that reports error to supporting system. Invoked similar to +/// printf. +/// +/// Usage: +/// ErrorReporter foo; +/// foo.Report("test %d", 5); +/// or +/// va_list args; +/// foo.Report("test %d", args); // where args is va_list +/// +/// Subclass ErrorReporter to provide another reporting destination. +/// For example, if you have a GUI program, you might redirect to a buffer +/// that drives a GUI error log box. +class ErrorReporter { +public: + virtual ~ErrorReporter() + { + } + virtual int Report(const char *format, va_list args) = 0; + int Report(const char *format, ...); + int ReportError(void *, const char *format, ...); +}; + +} // namespace tflite + +// You should not make bare calls to the error reporter, instead use the +// TF_LITE_REPORT_ERROR macro, since this allows message strings to be +// stripped when the binary size has to be optimized. If you are looking to +// reduce binary size, define TF_LITE_STRIP_ERROR_STRINGS when compiling and +// every call will be stubbed out, taking no memory. +#ifndef TF_LITE_STRIP_ERROR_STRINGS +#define TF_LITE_REPORT_ERROR(reporter, ...) \ + do { \ + static_cast(reporter)->Report(__VA_ARGS__); \ + } while (false) +#else // TF_LITE_STRIP_ERROR_STRINGS +#define TF_LITE_REPORT_ERROR(reporter, ...) +#endif // TF_LITE_STRIP_ERROR_STRINGS + +#endif // TENSORFLOW_LITE_CORE_API_ERROR_REPORTER_H_ diff --git a/components/tflite/tensorflow/lite/core/api/flatbuffer_conversions.cc b/components/tflite/tensorflow/lite/core/api/flatbuffer_conversions.cc new file mode 100644 index 00000000..e8511162 --- /dev/null +++ b/components/tflite/tensorflow/lite/core/api/flatbuffer_conversions.cc @@ -0,0 +1,2278 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/core/api/flatbuffer_conversions.h" + +#include +#include +#include + +#include "flatbuffers/flatbuffers.h" // from @flatbuffers +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/core/api/error_reporter.h" +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/schema/schema_generated.h" + +namespace tflite { + +namespace { + +// Utility class for safely allocating POD data. This is useful for avoiding +// leaks in cases where op params are allocated but fail to propagate to the +// parsed op data (e.g., when model parameters are invalid). +class SafeBuiltinDataAllocator { +public: + class BuiltinDataDeleter { + public: + explicit BuiltinDataDeleter(BuiltinDataAllocator *allocator) + : allocator_(allocator) + { + } + + void operator()(void *data) + { + allocator_->Deallocate(data); + } + + private: + BuiltinDataAllocator *allocator_; + }; + + template + using BuiltinDataPtr = std::unique_ptr; + + explicit SafeBuiltinDataAllocator(BuiltinDataAllocator *allocator) + : allocator_(allocator) + { + } + + template + BuiltinDataPtr Allocate() + { + return BuiltinDataPtr(allocator_->AllocatePOD(), + BuiltinDataDeleter(allocator_)); + } + +private: + BuiltinDataAllocator *allocator_; +}; + +// All the Parse functions take some pointers as params and this function has +// the common DCHECKs to catch if any of those are nullptr. +void CheckParsePointerParams(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data) +{ + TFLITE_DCHECK(op != nullptr); + TFLITE_DCHECK(error_reporter != nullptr); + TFLITE_DCHECK(allocator != nullptr); + TFLITE_DCHECK(builtin_data != nullptr); +} + +// Copies the contents from the flatbuffer int vector `flatbuffer` into the +// int array `buffer`. `flat_vector` and `buffer` represent the same +// configuration operation for a given operation. +TfLiteStatus FlatBufferIntVectorToArray( + int max_size_of_buffer, const flatbuffers::Vector *flat_vector, + int *buffer, ErrorReporter *error_reporter, const char *op_name) +{ + if (!flat_vector) { + TF_LITE_REPORT_ERROR(error_reporter, + "Input array not provided for operation '%s'.\n", + op_name); + return kTfLiteError; + } else { + size_t num_dimensions = flat_vector->size(); + if (num_dimensions > max_size_of_buffer / sizeof(int)) { + TF_LITE_REPORT_ERROR( + error_reporter, + "Found too many dimensions in the input array of operation '%s'.\n", + op_name); + return kTfLiteError; + } else { + for (size_t i = 0; i < num_dimensions; ++i) { + buffer[i] = flat_vector->Get(i); + } + } + } + return kTfLiteOk; +} + +// Converts the flatbuffer activation to what is used at runtime. +TfLiteFusedActivation ConvertActivation(ActivationFunctionType activation) +{ + switch (activation) { + case ActivationFunctionType_NONE: + return kTfLiteActNone; + case ActivationFunctionType_RELU: + return kTfLiteActRelu; + case ActivationFunctionType_RELU_N1_TO_1: + return kTfLiteActReluN1To1; + case ActivationFunctionType_RELU6: + return kTfLiteActRelu6; + case ActivationFunctionType_TANH: + return kTfLiteActTanh; + case ActivationFunctionType_SIGN_BIT: + return kTfLiteActSignBit; + } + return kTfLiteActNone; +} + +// Converts the flatbuffer padding enum to what is used at runtime. +TfLitePadding ConvertPadding(Padding padding) +{ + switch (padding) { + case Padding_SAME: + return kTfLitePaddingSame; + case Padding_VALID: + return kTfLitePaddingValid; + } + return kTfLitePaddingUnknown; +} + +#ifndef TF_LITE_STATIC_MEMORY +TfLiteStatus ParseOpDataTfLite(const Operator *op, BuiltinOperator op_type, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data) +{ + auto parseLSHProjectionType = [](LSHProjectionType type) { + switch (type) { + case LSHProjectionType_SPARSE: + return kTfLiteLshProjectionSparse; + case LSHProjectionType_DENSE: + return kTfLiteLshProjectionDense; + default: + return kTfLiteLshProjectionUnknown; + } + }; + auto parseCombinerType = [](CombinerType type) { + switch (type) { + case CombinerType_MEAN: + return kTfLiteCombinerTypeMean; + case CombinerType_SQRTN: + return kTfLiteCombinerTypeSqrtn; + case CombinerType_SUM: + default: + return kTfLiteCombinerTypeSum; + } + }; + + SafeBuiltinDataAllocator safe_allocator(allocator); + *builtin_data = nullptr; + switch (op_type) { + case BuiltinOperator_ABS: { + return ParseAbs(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_ADD: { + return ParseAdd(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_ADD_N: { + return ParseAddN(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_ARG_MAX: { + return ParseArgMax(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_ARG_MIN: { + return ParseArgMin(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_AVERAGE_POOL_2D: { + return ParsePool(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_BATCH_MATMUL: { + return ParseBatchMatMul(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_BATCH_TO_SPACE_ND: { + return ParseBatchToSpaceNd(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_CEIL: { + return ParseCeil(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_CONCATENATION: { + return ParseConcatenation(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_CONV_2D: { + return ParseConv2D(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_CUMSUM: { + return ParseCumsum(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_DEPTH_TO_SPACE: { + return ParseDepthToSpace(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_DEPTHWISE_CONV_2D: { + return ParseDepthwiseConv2D(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_DEQUANTIZE: { + return ParseDequantize(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_DIV: { + return ParseDiv(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_ELU: { + return ParseElu(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_EXP: { + return ParseExp(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_EXPAND_DIMS: { + return ParseExpandDims(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_FILL: { + return ParseFill(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_FLOOR: { + return ParseFloor(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_FLOOR_DIV: { + return ParseFloorDiv(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_FLOOR_MOD: { + return ParseFloorMod(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_FULLY_CONNECTED: { + return ParseFullyConnected(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_GATHER_ND: { + return ParseGatherNd(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_GREATER: { + return ParseGreater(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_GREATER_EQUAL: { + return ParseGreaterEqual(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_HARD_SWISH: { + return ParseHardSwish(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_L2_NORMALIZATION: { + return ParseL2Normalization(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_L2_POOL_2D: { + return ParsePool(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_LEAKY_RELU: { + return ParseLeakyRelu(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_LESS: { + return ParseLess(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_LESS_EQUAL: { + return ParseLessEqual(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_LOG: { + return ParseLog(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_LOGICAL_AND: { + return ParseLogicalAnd(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_LOGICAL_NOT: { + return ParseLogicalNot(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_LOGICAL_OR: { + return ParseLogicalOr(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_LOGISTIC: { + return ParseLogistic(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_LOG_SOFTMAX: { + return ParseLogSoftmax(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_MAXIMUM: { + return ParseMaximum(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_MAX_POOL_2D: { + return ParsePool(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_MEAN: { + return ParseReducer(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_MINIMUM: { + return ParseMinimum(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_MUL: { + return ParseMul(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_NEG: { + return ParseNeg(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_NOT_EQUAL: { + return ParseNotEqual(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_PACK: { + return ParsePack(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_PAD: { + return ParsePad(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_PADV2: { + return ParsePadV2(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_POW: { + return ParsePow(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_PRELU: { + return ParsePrelu(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_QUANTIZE: { + return ParseQuantize(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_REDUCE_ANY: { + return ParseReducer(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_REDUCE_ALL: { + return ParseReducer(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_REDUCE_MAX: { + return ParseReducer(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_REDUCE_MIN: { + return ParseReducer(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_REDUCE_PROD: { + return ParseReducer(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_RELU: { + return ParseRelu(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_RELU6: { + return ParseRelu6(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_RESHAPE: { + return ParseReshape(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_RESIZE_BILINEAR: { + return ParseResizeBilinear(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_RESIZE_NEAREST_NEIGHBOR: { + return ParseResizeNearestNeighbor(op, error_reporter, allocator, + builtin_data); + } + + case BuiltinOperator_ROUND: { + return ParseRound(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_RSQRT: { + return ParseRsqrt(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_SHAPE: { + return ParseShape(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_SIN: { + return ParseSin(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_SOFTMAX: { + return ParseSoftmax(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_SPACE_TO_BATCH_ND: { + return ParseSpaceToBatchNd(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_SPACE_TO_DEPTH: { + return ParseSpaceToDepth(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_SPLIT: { + return ParseSplit(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_SPLIT_V: { + return ParseSplitV(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_SQRT: { + return ParseSqrt(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_SQUARE: { + return ParseSquare(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_SQUEEZE: { + return ParseSqueeze(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_STRIDED_SLICE: { + return ParseStridedSlice(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_SUB: { + return ParseSub(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_SUM: { + return ParseReducer(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_SVDF: { + return ParseSvdf(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_TANH: { + return ParseTanh(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_TRANSPOSE_CONV: { + return ParseTransposeConv(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_UNPACK: { + return ParseUnpack(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_ZEROS_LIKE: { + return ParseZerosLike(op, error_reporter, allocator, builtin_data); + } + + case BuiltinOperator_CAST: { + return ParseCast(op, error_reporter, allocator, builtin_data); + } + case BuiltinOperator_LSH_PROJECTION: { + auto params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *lshParams = + op->builtin_options_as_LSHProjectionOptions()) { + params->type = parseLSHProjectionType(lshParams->type()); + } + *builtin_data = params.release(); + return kTfLiteOk; + } + case BuiltinOperator_UNIDIRECTIONAL_SEQUENCE_RNN: { + auto params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *sequence_rnn_params = + op->builtin_options_as_SequenceRNNOptions()) { + params->activation = + ConvertActivation(sequence_rnn_params->fused_activation_function()); + params->time_major = sequence_rnn_params->time_major(); + params->asymmetric_quantize_inputs = + sequence_rnn_params->asymmetric_quantize_inputs(); + } + *builtin_data = params.release(); + return kTfLiteOk; + } + case BuiltinOperator_BIDIRECTIONAL_SEQUENCE_RNN: { + auto params = + safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *bidi_sequence_rnn_params = + op->builtin_options_as_BidirectionalSequenceRNNOptions()) { + params->activation = ConvertActivation( + bidi_sequence_rnn_params->fused_activation_function()); + params->time_major = bidi_sequence_rnn_params->time_major(); + params->merge_outputs = bidi_sequence_rnn_params->merge_outputs(); + params->asymmetric_quantize_inputs = + bidi_sequence_rnn_params->asymmetric_quantize_inputs(); + } + *builtin_data = params.release(); + return kTfLiteOk; + } + case BuiltinOperator_RNN: { + auto params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *rnn_params = op->builtin_options_as_RNNOptions()) { + params->activation = + ConvertActivation(rnn_params->fused_activation_function()); + params->asymmetric_quantize_inputs = + rnn_params->asymmetric_quantize_inputs(); + } + *builtin_data = params.release(); + return kTfLiteOk; + } + case BuiltinOperator_EMBEDDING_LOOKUP_SPARSE: { + auto params = + safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *embedding_params = + op->builtin_options_as_EmbeddingLookupSparseOptions()) { + params->combiner = parseCombinerType(embedding_params->combiner()); + } + *builtin_data = params.release(); + return kTfLiteOk; + } + + case BuiltinOperator_HASHTABLE_LOOKUP: + // no-op. + return kTfLiteOk; + + case BuiltinOperator_LOCAL_RESPONSE_NORMALIZATION: { + auto params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *schema_params = + op->builtin_options_as_LocalResponseNormalizationOptions()) { + params->radius = schema_params->radius(); + params->bias = schema_params->bias(); + params->alpha = schema_params->alpha(); + params->beta = schema_params->beta(); + } + *builtin_data = params.release(); + return kTfLiteOk; + } + case BuiltinOperator_LSTM: { + auto params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *lstm_params = op->builtin_options_as_LSTMOptions()) { + params->activation = + ConvertActivation(lstm_params->fused_activation_function()); + params->cell_clip = lstm_params->cell_clip(); + params->proj_clip = lstm_params->proj_clip(); + switch (lstm_params->kernel_type()) { + case LSTMKernelType_FULL: + params->kernel_type = kTfLiteLSTMFullKernel; + break; + case LSTMKernelType_BASIC: + params->kernel_type = kTfLiteLSTMBasicKernel; + break; + default: + TF_LITE_REPORT_ERROR(error_reporter, + "Unhandled LSTM kernel type: %d", + lstm_params->kernel_type()); + return kTfLiteError; + } + params->asymmetric_quantize_inputs = + lstm_params->asymmetric_quantize_inputs(); + } else { + TF_LITE_REPORT_ERROR(error_reporter, + "No valid LSTM builtin options exist"); + return kTfLiteError; + } + *builtin_data = params.release(); + return kTfLiteOk; + } + case BuiltinOperator_UNIDIRECTIONAL_SEQUENCE_LSTM: { + auto params = + safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *seq_lstm_params = + op->builtin_options_as_UnidirectionalSequenceLSTMOptions()) { + params->activation = + ConvertActivation(seq_lstm_params->fused_activation_function()); + params->cell_clip = seq_lstm_params->cell_clip(); + params->proj_clip = seq_lstm_params->proj_clip(); + params->time_major = seq_lstm_params->time_major(); + params->asymmetric_quantize_inputs = + seq_lstm_params->asymmetric_quantize_inputs(); + } + *builtin_data = params.release(); + return kTfLiteOk; + } + case BuiltinOperator_BIDIRECTIONAL_SEQUENCE_LSTM: { + auto params = + safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *bidi_lstm_params = + op->builtin_options_as_BidirectionalSequenceLSTMOptions()) { + params->activation = + ConvertActivation(bidi_lstm_params->fused_activation_function()); + params->cell_clip = bidi_lstm_params->cell_clip(); + params->proj_clip = bidi_lstm_params->proj_clip(); + params->merge_outputs = bidi_lstm_params->merge_outputs(); + params->time_major = bidi_lstm_params->time_major(); + params->asymmetric_quantize_inputs = + bidi_lstm_params->asymmetric_quantize_inputs(); + } + *builtin_data = params.release(); + return kTfLiteOk; + } + case BuiltinOperator_SKIP_GRAM: { + auto params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *skip_gram_params = + op->builtin_options_as_SkipGramOptions()) { + params->ngram_size = skip_gram_params->ngram_size(); + params->max_skip_size = skip_gram_params->max_skip_size(); + params->include_all_ngrams = skip_gram_params->include_all_ngrams(); + } + *builtin_data = params.release(); + return kTfLiteOk; + } + + case BuiltinOperator_GATHER: { + return ParseGather(op, error_reporter, allocator, builtin_data); + } + case BuiltinOperator_SPARSE_TO_DENSE: { + auto params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *sparse_to_dense_params = + op->builtin_options_as_SparseToDenseOptions()) { + params->validate_indices = sparse_to_dense_params->validate_indices(); + } + *builtin_data = params.release(); + return kTfLiteOk; + } + case BuiltinOperator_DELEGATE: { + TF_LITE_REPORT_ERROR(error_reporter, + "DELEGATE op shouldn't exist in model."); + return kTfLiteError; + } + case BuiltinOperator_FAKE_QUANT: { + auto params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *schema_params = + op->builtin_options_as_FakeQuantOptions()) { + params->min = schema_params->min(); + params->max = schema_params->max(); + params->num_bits = schema_params->num_bits(); + params->narrow_range = schema_params->narrow_range(); + } + *builtin_data = params.release(); + return kTfLiteOk; + } + case BuiltinOperator_ONE_HOT: { + auto params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *schema_params = op->builtin_options_as_OneHotOptions()) { + params->axis = schema_params->axis(); + } + *builtin_data = params.release(); + return kTfLiteOk; + } + case BuiltinOperator_MIRROR_PAD: { + auto params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + const auto *mirror_pad_params = op->builtin_options_as_MirrorPadOptions(); + if (mirror_pad_params != nullptr) { + params->mode = + mirror_pad_params->mode() == tflite::MirrorPadMode_REFLECT ? TfLiteMirrorPaddingMode::kTfLiteMirrorPaddingReflect : TfLiteMirrorPaddingMode::kTfLiteMirrorPaddingSymmetric; + } + *builtin_data = params.release(); + return kTfLiteOk; + } + case BuiltinOperator_UNIQUE: { + auto params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + const auto *unique_params = op->builtin_options_as_UniqueOptions(); + if (unique_params != nullptr) { + params->index_out_type = + unique_params->idx_out_type() == tflite::TensorType_INT64 ? TfLiteType::kTfLiteInt64 : TfLiteType::kTfLiteInt32; + } + *builtin_data = params.release(); + return kTfLiteOk; + } + case BuiltinOperator_REVERSE_SEQUENCE: { + auto params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *reverse_seq_params = + op->builtin_options_as_ReverseSequenceOptions()) { + params->seq_dim = reverse_seq_params->seq_dim(); + params->batch_dim = reverse_seq_params->batch_dim(); + } + *builtin_data = params.release(); + return kTfLiteOk; + } + case BuiltinOperator_IF: { + auto params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *if_params = op->builtin_options_as_IfOptions()) { + params->then_subgraph_index = if_params->then_subgraph_index(); + params->else_subgraph_index = if_params->else_subgraph_index(); + } + *builtin_data = params.release(); + return kTfLiteOk; + } + case BuiltinOperator_WHILE: { + auto params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *while_params = op->builtin_options_as_WhileOptions()) { + params->cond_subgraph_index = while_params->cond_subgraph_index(); + params->body_subgraph_index = while_params->body_subgraph_index(); + } + *builtin_data = params.release(); + return kTfLiteOk; + } + case BuiltinOperator_CALL_ONCE: { + auto params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *call_once_params = + op->builtin_options_as_CallOnceOptions()) { + params->init_subgraph_index = call_once_params->init_subgraph_index(); + } + *builtin_data = params.release(); + return kTfLiteOk; + } + case BuiltinOperator_CONV_3D: + case BuiltinOperator_CONV_3D_TRANSPOSE: { + auto params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *conv3d_params = op->builtin_options_as_Conv3DOptions()) { + params->padding = ConvertPadding(conv3d_params->padding()); + params->activation = + ConvertActivation(conv3d_params->fused_activation_function()); + params->stride_depth = conv3d_params->stride_d(); + params->stride_height = conv3d_params->stride_h(); + params->stride_width = conv3d_params->stride_w(); + params->dilation_depth_factor = conv3d_params->dilation_d_factor(); + params->dilation_height_factor = conv3d_params->dilation_h_factor(); + params->dilation_width_factor = conv3d_params->dilation_w_factor(); + } + *builtin_data = params.release(); + return kTfLiteOk; + } + case BuiltinOperator_HASHTABLE: { + auto params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *hashtable_params = + op->builtin_options_as_HashtableOptions()) { + params->table_id = hashtable_params->table_id(); + TF_LITE_ENSURE_STATUS(ConvertTensorType( + hashtable_params->key_dtype(), ¶ms->key_dtype, error_reporter)); + TF_LITE_ENSURE_STATUS(ConvertTensorType(hashtable_params->value_dtype(), + ¶ms->value_dtype, + error_reporter)); + } + *builtin_data = params.release(); + return kTfLiteOk; + } + // Below are the ops with no builtin_data structure. + // TODO(aselle): Implement call in BuiltinOptions, but nullptrs are + // ok for now, since there is no call implementation either. + case BuiltinOperator_CALL: + case BuiltinOperator_CONCAT_EMBEDDINGS: + case BuiltinOperator_COS: + case BuiltinOperator_CUSTOM: + case BuiltinOperator_EMBEDDING_LOOKUP: + case BuiltinOperator_EQUAL: + case BuiltinOperator_MATRIX_DIAG: + case BuiltinOperator_MATRIX_SET_DIAG: + case BuiltinOperator_RELU_N1_TO_1: + case BuiltinOperator_SELECT: + case BuiltinOperator_SELECT_V2: + case BuiltinOperator_SLICE: + case BuiltinOperator_TILE: + case BuiltinOperator_TOPK_V2: + case BuiltinOperator_TRANSPOSE: + case BuiltinOperator_RANGE: + case BuiltinOperator_SQUARED_DIFFERENCE: + case BuiltinOperator_REVERSE_V2: + case BuiltinOperator_WHERE: + case BuiltinOperator_RANK: + case BuiltinOperator_NON_MAX_SUPPRESSION_V4: + case BuiltinOperator_NON_MAX_SUPPRESSION_V5: + case BuiltinOperator_SCATTER_ND: + case BuiltinOperator_DENSIFY: + case BuiltinOperator_SEGMENT_SUM: + case BuiltinOperator_BROADCAST_TO: + case BuiltinOperator_RFFT2D: + case BuiltinOperator_IMAG: + case BuiltinOperator_REAL: + case BuiltinOperator_COMPLEX_ABS: + case BuiltinOperator_HASHTABLE_FIND: + case BuiltinOperator_HASHTABLE_IMPORT: + case BuiltinOperator_HASHTABLE_SIZE: + return kTfLiteOk; + case BuiltinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES: + return kTfLiteError; + } + return kTfLiteError; +} // NOLINT[readability/fn_size] +#endif // !defined(TF_LITE_STATIC_MEMORY) +} // namespace + +TfLiteStatus ConvertTensorType(TensorType tensor_type, TfLiteType *type, + ErrorReporter *error_reporter) +{ + switch (tensor_type) { + case TensorType_FLOAT16: + *type = kTfLiteFloat16; + return kTfLiteOk; + case TensorType_FLOAT32: + *type = kTfLiteFloat32; + return kTfLiteOk; + case TensorType_FLOAT64: + *type = kTfLiteFloat64; + return kTfLiteOk; + case TensorType_INT16: + *type = kTfLiteInt16; + return kTfLiteOk; + case TensorType_INT32: + *type = kTfLiteInt32; + return kTfLiteOk; + case TensorType_UINT32: + *type = kTfLiteUInt32; + return kTfLiteOk; + case TensorType_UINT8: + *type = kTfLiteUInt8; + return kTfLiteOk; + case TensorType_INT8: + *type = kTfLiteInt8; + return kTfLiteOk; + case TensorType_INT64: + *type = kTfLiteInt64; + return kTfLiteOk; + case TensorType_UINT64: + *type = kTfLiteUInt64; + return kTfLiteOk; + case TensorType_STRING: + *type = kTfLiteString; + return kTfLiteOk; + case TensorType_BOOL: + *type = kTfLiteBool; + return kTfLiteOk; + case TensorType_COMPLEX64: + *type = kTfLiteComplex64; + return kTfLiteOk; + case TensorType_COMPLEX128: + *type = kTfLiteComplex128; + return kTfLiteOk; + case TensorType_RESOURCE: + *type = kTfLiteResource; + return kTfLiteOk; + case TensorType_VARIANT: + *type = kTfLiteVariant; + return kTfLiteOk; + default: + *type = kTfLiteNoType; + TF_LITE_REPORT_ERROR(error_reporter, + "Unsupported data type %d in tensor\n", tensor_type); + return kTfLiteError; + } +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseAbs(const Operator *, ErrorReporter *, BuiltinDataAllocator *, + void **) +{ + return kTfLiteOk; +} + +TfLiteStatus ParseAdd(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const AddOptions *schema_params = op->builtin_options_as_AddOptions(); + + if (schema_params != nullptr) { + params->activation = + ConvertActivation(schema_params->fused_activation_function()); + params->pot_scale_int16 = schema_params->pot_scale_int16(); + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +TfLiteStatus ParseAddN(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data) +{ + return kTfLiteOk; +} + +TfLiteStatus ParseArgMax(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const ArgMaxOptions *schema_params = op->builtin_options_as_ArgMaxOptions(); + + if (schema_params != nullptr) { + TF_LITE_ENSURE_STATUS(ConvertTensorType( + schema_params->output_type(), ¶ms->output_type, error_reporter)); + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +TfLiteStatus ParseArgMin(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const ArgMinOptions *schema_params = op->builtin_options_as_ArgMinOptions(); + + if (schema_params != nullptr) { + TF_LITE_ENSURE_STATUS(ConvertTensorType( + schema_params->output_type(), ¶ms->output_type, error_reporter)); + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseBatchMatMul(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + auto params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *bmm_params = op->builtin_options_as_BatchMatMulOptions()) { + params->adj_x = bmm_params->adj_x(); + params->adj_y = bmm_params->adj_y(); + params->asymmetric_quantize_inputs = + bmm_params->asymmetric_quantize_inputs(); + } + *builtin_data = params.release(); + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseBatchToSpaceNd(const Operator *, ErrorReporter *, + BuiltinDataAllocator *, void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseCast(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + auto params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *schema_params = op->builtin_options_as_CastOptions()) { + TF_LITE_ENSURE_STATUS(ConvertTensorType( + schema_params->in_data_type(), ¶ms->in_data_type, error_reporter)); + TF_LITE_ENSURE_STATUS(ConvertTensorType(schema_params->out_data_type(), + ¶ms->out_data_type, + error_reporter)); + } + *builtin_data = params.release(); + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseCeil(const Operator *, ErrorReporter *, BuiltinDataAllocator *, + void **) +{ + return kTfLiteOk; +} + +TfLiteStatus ParseConcatenation(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const ConcatenationOptions *schema_params = + op->builtin_options_as_ConcatenationOptions(); + + if (schema_params != nullptr) { + params->activation = + ConvertActivation(schema_params->fused_activation_function()); + params->axis = schema_params->axis(); + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +TfLiteStatus ParseConv2D(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const Conv2DOptions *schema_params = op->builtin_options_as_Conv2DOptions(); + + if (schema_params != nullptr) { + params->padding = ConvertPadding(schema_params->padding()); + params->stride_width = schema_params->stride_w(); + params->stride_height = schema_params->stride_h(); + params->activation = + ConvertActivation(schema_params->fused_activation_function()); + + params->dilation_width_factor = schema_params->dilation_w_factor(); + params->dilation_height_factor = schema_params->dilation_h_factor(); + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseCumsum(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + auto params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *cumsum_params = op->builtin_options_as_CumsumOptions()) { + params->exclusive = cumsum_params->exclusive(); + params->reverse = cumsum_params->reverse(); + } + *builtin_data = params.release(); + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseCos(const Operator *, ErrorReporter *, BuiltinDataAllocator *, + void **) +{ + return kTfLiteOk; +} + +TfLiteStatus ParseDepthToSpace(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const auto *schema_params = op->builtin_options_as_DepthToSpaceOptions(); + if (schema_params != nullptr) { + params->block_size = schema_params->block_size(); + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +TfLiteStatus ParseDepthwiseConv2D(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const DepthwiseConv2DOptions *schema_params = + op->builtin_options_as_DepthwiseConv2DOptions(); + + if (schema_params != nullptr) { + params->padding = ConvertPadding(schema_params->padding()); + params->stride_width = schema_params->stride_w(); + params->stride_height = schema_params->stride_h(); + params->depth_multiplier = schema_params->depth_multiplier(); + params->activation = + ConvertActivation(schema_params->fused_activation_function()); + + params->dilation_width_factor = schema_params->dilation_w_factor(); + params->dilation_height_factor = schema_params->dilation_h_factor(); + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseDequantize(const Operator *, ErrorReporter *, + BuiltinDataAllocator *, void **) +{ + return kTfLiteOk; +} + +TfLiteStatus ParseDiv(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + auto params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *schema_params = op->builtin_options_as_DivOptions()) { + params->activation = + ConvertActivation(schema_params->fused_activation_function()); + } + *builtin_data = params.release(); + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseElu(const Operator *, ErrorReporter *, BuiltinDataAllocator *, + void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseEqual(const Operator *, ErrorReporter *, BuiltinDataAllocator *, + void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseExp(const Operator *, ErrorReporter *, BuiltinDataAllocator *, + void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseExpandDims(const Operator *, ErrorReporter *, + BuiltinDataAllocator *, void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseFill(const Operator *, ErrorReporter *, BuiltinDataAllocator *, + void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseFloor(const Operator *, ErrorReporter *, BuiltinDataAllocator *, + void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseFloorDiv(const Operator *, ErrorReporter *, + BuiltinDataAllocator *, void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseFloorMod(const Operator *, ErrorReporter *, + BuiltinDataAllocator *, void **) +{ + return kTfLiteOk; +} + +TfLiteStatus ParseFullyConnected(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const FullyConnectedOptions *schema_params = + op->builtin_options_as_FullyConnectedOptions(); + + if (schema_params != nullptr) { + params->activation = + ConvertActivation(schema_params->fused_activation_function()); + params->keep_num_dims = schema_params->keep_num_dims(); + params->asymmetric_quantize_inputs = + schema_params->asymmetric_quantize_inputs(); + + switch (schema_params->weights_format()) { + case FullyConnectedOptionsWeightsFormat_DEFAULT: + params->weights_format = kTfLiteFullyConnectedWeightsFormatDefault; + break; + case FullyConnectedOptionsWeightsFormat_SHUFFLED4x16INT8: + params->weights_format = + kTfLiteFullyConnectedWeightsFormatShuffled4x16Int8; + break; + default: + TF_LITE_REPORT_ERROR(error_reporter, + "Unhandled fully-connected weights format."); + return kTfLiteError; + } + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseGather(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + auto params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + params->axis = 0; + params->batch_dims = 0; + if (const auto *gather_params = op->builtin_options_as_GatherOptions()) { + params->axis = gather_params->axis(); + params->batch_dims = gather_params->batch_dims(); + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseGatherNd(const Operator *, ErrorReporter *, + BuiltinDataAllocator *, void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseGreater(const Operator *, ErrorReporter *, + BuiltinDataAllocator *, void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseGreaterEqual(const Operator *, ErrorReporter *, + BuiltinDataAllocator *, void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseHardSwish(const Operator *, ErrorReporter *, + BuiltinDataAllocator *, void **) +{ + return kTfLiteOk; +} + +TfLiteStatus ParseIf(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const IfOptions *schema_params = op->builtin_options_as_IfOptions(); + + if (schema_params != nullptr) { + params->then_subgraph_index = schema_params->then_subgraph_index(); + params->else_subgraph_index = schema_params->else_subgraph_index(); + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +TfLiteStatus ParseL2Normalization(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const L2NormOptions *schema_params = op->builtin_options_as_L2NormOptions(); + + if (schema_params != nullptr) { + params->activation = + ConvertActivation(schema_params->fused_activation_function()); + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +TfLiteStatus ParseLeakyRelu(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + auto params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + if (const auto *leaky_relu_params = + op->builtin_options_as_LeakyReluOptions()) { + params->alpha = leaky_relu_params->alpha(); + } + *builtin_data = params.release(); + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseLess(const Operator *, ErrorReporter *, BuiltinDataAllocator *, + void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseLessEqual(const Operator *, ErrorReporter *, + BuiltinDataAllocator *, void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseLog(const Operator *, ErrorReporter *, BuiltinDataAllocator *, + void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseLogicalAnd(const Operator *, ErrorReporter *, + BuiltinDataAllocator *, void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseLogicalNot(const Operator *, ErrorReporter *, + BuiltinDataAllocator *, void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseLogicalOr(const Operator *, ErrorReporter *, + BuiltinDataAllocator *, void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseLogistic(const Operator *, ErrorReporter *, + BuiltinDataAllocator *, void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseLogSoftmax(const Operator *, ErrorReporter *, + BuiltinDataAllocator *, void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseMaximum(const Operator *, ErrorReporter *, + BuiltinDataAllocator *, void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseMinimum(const Operator *, ErrorReporter *, + BuiltinDataAllocator *, void **) +{ + return kTfLiteOk; +} + +TfLiteStatus ParseMul(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const MulOptions *schema_params = op->builtin_options_as_MulOptions(); + + if (schema_params != nullptr) { + params->activation = + ConvertActivation(schema_params->fused_activation_function()); + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseNeg(const Operator *, ErrorReporter *, BuiltinDataAllocator *, + void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseNotEqual(const Operator *, ErrorReporter *, + BuiltinDataAllocator *, void **) +{ + return kTfLiteOk; +} + +TfLiteStatus ParsePack(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const PackOptions *schema_params = op->builtin_options_as_PackOptions(); + + if (schema_params != nullptr) { + params->values_count = schema_params->values_count(); + params->axis = schema_params->axis(); + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParsePad(const Operator *, ErrorReporter *, BuiltinDataAllocator *, + void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParsePadV2(const Operator *, ErrorReporter *, BuiltinDataAllocator *, + void **) +{ + return kTfLiteOk; +} + +TfLiteStatus ParsePool(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const Pool2DOptions *schema_params = op->builtin_options_as_Pool2DOptions(); + + if (schema_params != nullptr) { + params->padding = ConvertPadding(schema_params->padding()); + params->stride_width = schema_params->stride_w(); + params->stride_height = schema_params->stride_h(); + params->filter_width = schema_params->filter_width(); + params->filter_height = schema_params->filter_height(); + params->activation = + ConvertActivation(schema_params->fused_activation_function()); + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParsePow(const Operator *, ErrorReporter *, BuiltinDataAllocator *, + void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParsePrelu(const Operator *, ErrorReporter *, BuiltinDataAllocator *, + void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseQuantize(const Operator *, ErrorReporter *, + BuiltinDataAllocator *, void **) +{ + return kTfLiteOk; +} + +TfLiteStatus ParseReducer(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const ReducerOptions *schema_params = op->builtin_options_as_ReducerOptions(); + + if (schema_params != nullptr) { + params->keep_dims = schema_params->keep_dims(); + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseRelu(const Operator *, ErrorReporter *, BuiltinDataAllocator *, + void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseRelu6(const Operator *, ErrorReporter *, BuiltinDataAllocator *, + void **) +{ + return kTfLiteOk; +} + +TfLiteStatus ParseReshape(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const ReshapeOptions *schema_params = op->builtin_options_as_ReshapeOptions(); + + if (schema_params != nullptr) { + const flatbuffers::Vector *new_shape = schema_params->new_shape(); + if (new_shape != nullptr) { + TF_LITE_ENSURE_STATUS( + FlatBufferIntVectorToArray(sizeof(params->shape), new_shape, + params->shape, error_reporter, "reshape")); + params->num_dimensions = new_shape->size(); + } else { + // TODO(b/157480169) TODO(b/147203660): We should either return + // kTfLiteError or fill in some reasonable defaults in the params struct. + // We are not doing so until we better undertand the ramifications of + // changing the legacy behavior. + } + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +TfLiteStatus ParseResizeBilinear(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const ResizeBilinearOptions *schema_params = + op->builtin_options_as_ResizeBilinearOptions(); + + if (schema_params != nullptr) { + params->align_corners = schema_params->align_corners(); + params->half_pixel_centers = schema_params->half_pixel_centers(); + } else { + params->align_corners = false; + params->half_pixel_centers = false; + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +TfLiteStatus ParseResizeNearestNeighbor(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const ResizeNearestNeighborOptions *schema_params = + op->builtin_options_as_ResizeNearestNeighborOptions(); + + if (schema_params != nullptr) { + params->align_corners = schema_params->align_corners(); + params->half_pixel_centers = schema_params->half_pixel_centers(); + } else { + params->align_corners = false; + params->half_pixel_centers = false; + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseRound(const Operator *, ErrorReporter *, BuiltinDataAllocator *, + void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseRsqrt(const Operator *, ErrorReporter *, BuiltinDataAllocator *, + void **) +{ + return kTfLiteOk; +} + +TfLiteStatus ParseShape(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data) +{ + SafeBuiltinDataAllocator safe_allocator(allocator); + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const ShapeOptions *schema_params = op->builtin_options_as_ShapeOptions(); + + if (schema_params != nullptr) { + TF_LITE_ENSURE_STATUS(ConvertTensorType(schema_params->out_type(), + ¶ms->out_type, error_reporter)); + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseSin(const Operator *, ErrorReporter *, BuiltinDataAllocator *, + void **) +{ + return kTfLiteOk; +} + +TfLiteStatus ParseSoftmax(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const SoftmaxOptions *schema_params = op->builtin_options_as_SoftmaxOptions(); + + if (schema_params != nullptr) { + params->beta = schema_params->beta(); + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseSpaceToBatchNd(const Operator *, ErrorReporter *, + BuiltinDataAllocator *, void **) +{ + return kTfLiteOk; +} + +TfLiteStatus ParseSpaceToDepth(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const auto *schema_params = op->builtin_options_as_SpaceToDepthOptions(); + if (schema_params != nullptr) { + params->block_size = schema_params->block_size(); + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +TfLiteStatus ParseSplit(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const SplitOptions *schema_params = op->builtin_options_as_SplitOptions(); + + if (schema_params != nullptr) { + params->num_splits = schema_params->num_splits(); + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +TfLiteStatus ParseSplitV(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + SafeBuiltinDataAllocator safe_allocator(allocator); + + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const SplitVOptions *schema_params = op->builtin_options_as_SplitVOptions(); + + if (schema_params != nullptr) { + params->num_splits = schema_params->num_splits(); + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +TfLiteStatus ParseSqueeze(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + SafeBuiltinDataAllocator safe_allocator(allocator); + + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const SqueezeOptions *schema_params = op->builtin_options_as_SqueezeOptions(); + + if (schema_params != nullptr) { + const auto *squeeze_dims = schema_params->squeeze_dims(); + if (squeeze_dims != nullptr) { + TF_LITE_ENSURE_STATUS(FlatBufferIntVectorToArray( + sizeof(params->squeeze_dims), squeeze_dims, params->squeeze_dims, + error_reporter, "squeeze")); + params->num_squeeze_dims = squeeze_dims->size(); + } else { + params->num_squeeze_dims = 0; + } + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseSqrt(const Operator *, ErrorReporter *, BuiltinDataAllocator *, + void **) +{ + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseSquare(const Operator *, ErrorReporter *, BuiltinDataAllocator *, + void **) +{ + return kTfLiteOk; +} + +TfLiteStatus ParseStridedSlice(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const StridedSliceOptions *schema_params = + op->builtin_options_as_StridedSliceOptions(); + + if (schema_params != nullptr) { + params->begin_mask = schema_params->begin_mask(); + params->end_mask = schema_params->end_mask(); + params->ellipsis_mask = schema_params->ellipsis_mask(); + params->new_axis_mask = schema_params->new_axis_mask(); + params->shrink_axis_mask = schema_params->shrink_axis_mask(); + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +TfLiteStatus ParseSub(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const SubOptions *schema_params = op->builtin_options_as_SubOptions(); + + if (schema_params != nullptr) { + params->activation = + ConvertActivation(schema_params->fused_activation_function()); + params->pot_scale_int16 = schema_params->pot_scale_int16(); + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +TfLiteStatus ParseSvdf(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const SVDFOptions *schema_params = op->builtin_options_as_SVDFOptions(); + if (schema_params != nullptr) { + params->rank = schema_params->rank(); + params->activation = + ConvertActivation(schema_params->fused_activation_function()); + params->asymmetric_quantize_inputs = + schema_params->asymmetric_quantize_inputs(); + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseTanh(const Operator *, ErrorReporter *, BuiltinDataAllocator *, + void **) +{ + return kTfLiteOk; +} +// +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseTranspose(const Operator *, ErrorReporter *, + BuiltinDataAllocator *, void **) +{ + return kTfLiteOk; +} + +TfLiteStatus ParseTransposeConv(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + const TransposeConvOptions *transpose_conv_params = + op->builtin_options_as_TransposeConvOptions(); + if (transpose_conv_params != nullptr) { + params->padding = ConvertPadding(transpose_conv_params->padding()); + params->stride_width = transpose_conv_params->stride_w(); + params->stride_height = transpose_conv_params->stride_h(); + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + *builtin_data = params.release(); + return kTfLiteOk; +} + +TfLiteStatus ParseUnpack(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data) +{ + CheckParsePointerParams(op, error_reporter, allocator, builtin_data); + + SafeBuiltinDataAllocator safe_allocator(allocator); + std::unique_ptr + params = safe_allocator.Allocate(); + TF_LITE_ENSURE(error_reporter, params != nullptr); + + const UnpackOptions *schema_params = op->builtin_options_as_UnpackOptions(); + + if (schema_params != nullptr) { + params->num = schema_params->num(); + params->axis = schema_params->axis(); + } else { + // TODO(b/157480169): We should either return kTfLiteError or fill in some + // reasonable defaults in the params struct. We are not doing so until we + // better undertand the ramifications of changing the legacy behavior. + } + + *builtin_data = params.release(); + return kTfLiteOk; +} + +// We have this parse function instead of directly returning kTfLiteOk from the +// switch-case in ParseOpData because this function is used as part of the +// selective registration for the OpResolver implementation in micro. +TfLiteStatus ParseZerosLike(const Operator *, ErrorReporter *, + BuiltinDataAllocator *, void **) +{ + return kTfLiteOk; +} + +TfLiteStatus ParseOpData(const Operator *op, BuiltinOperator op_type, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data) +{ +// TODO(b/145762662): It would be preferable to have the build graph for TF Lite +// Micro not have the ParseOpData function at all. This would require splitting +// the current file into two separate files, one of which defines the +// ParseOpData function and the other that defines the operator specific parse +// functions (e.g. ParseAdd). +// +// Such a split was attempted but was not worth the effort at the time because +// of the following reasons: +// * We could either duplicate the functions and the SafeBuiltinDataAllocator +// class in the anonymous namespace of this file, or attempt to make a common +// library with these helper functions and class. +// * Making a common library with a separate build target was not feasible as +// it introduced circular dependencies due to the ErrorReporter and a common +// .cc and .h within the same api build target the also cause circular +// dependencies due to the BuiltinDataAllocator class. +// * If all the builtin operators were to have their own parse functions, or we +// were ok with some amount of code duplication, then this split of the .cc +// files would be a lot more feasible. +#ifdef TF_LITE_STATIC_MEMORY + TF_LITE_REPORT_ERROR( + error_reporter, + "ParseOpData is unsupported on TfLiteMicro, please use the operator " + "specific parse functions (e.g. ParseAdd etc.).\n"); + return kTfLiteError; +#else + return ParseOpDataTfLite(op, op_type, error_reporter, allocator, + builtin_data); +#endif +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/core/api/flatbuffer_conversions.h b/components/tflite/tensorflow/lite/core/api/flatbuffer_conversions.h new file mode 100644 index 00000000..8136080d --- /dev/null +++ b/components/tflite/tensorflow/lite/core/api/flatbuffer_conversions.h @@ -0,0 +1,360 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_CORE_API_FLATBUFFER_CONVERSIONS_H_ +#define TENSORFLOW_LITE_CORE_API_FLATBUFFER_CONVERSIONS_H_ + +// These functions transform codes and data structures that are defined in the +// flatbuffer serialization format into in-memory values that are used by the +// runtime API and interpreter. + +#include +#include +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/core/api/error_reporter.h" +#include "tensorflow/lite/schema/schema_generated.h" + +namespace tflite { +// Interface class for builtin data allocations. +class BuiltinDataAllocator { +public: + virtual void *Allocate(size_t size, size_t alignment_hint) = 0; + virtual void Deallocate(void *data) = 0; + + // Allocate a structure, but make sure it is a POD structure that doesn't + // require constructors to run. The reason we do this, is that Interpreter's C + // extension part will take ownership so destructors will not be run during + // deallocation. + template + T *AllocatePOD() + { + // TODO(b/154346074): Change this to is_trivially_destructible when all + // platform targets support that properly. + static_assert(std::is_pod::value, "Builtin data structure must be POD."); + void *allocated_memory = this->Allocate(sizeof(T), alignof(T)); + return new (allocated_memory) T(); + } + + virtual ~BuiltinDataAllocator() + { + } +}; + +// Parse the appropriate data out of the op. +// +// This handles builtin data explicitly as there are flatbuffer schemas. +// If it returns kTfLiteOk, it passes the data out with `builtin_data`. The +// calling function has to pass in an allocator object, and this allocator +// will be called to reserve space for the output data. If the calling +// function's allocator reserves memory on the heap, then it's the calling +// function's responsibility to free it. +// If it returns kTfLiteError, `builtin_data` will be `nullptr`. +TfLiteStatus ParseOpData(const Operator *op, BuiltinOperator op_type, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +// Converts the tensor data type used in the flat buffer to the representation +// used by the runtime. +TfLiteStatus ConvertTensorType(TensorType tensor_type, TfLiteType *type, + ErrorReporter *error_reporter); + +TfLiteStatus ParseAbs(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseAdd(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseAddN(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseArgMax(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseArgMin(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseBatchMatMul(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseBatchToSpaceNd(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseCeil(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseCast(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseConcatenation(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseConv2D(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseCos(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseCumsum(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseDepthToSpace(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseDepthwiseConv2D(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseDequantize(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseDiv(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseElu(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseEqual(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseExp(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseExpandDims(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseFill(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseFloor(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseFloorDiv(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseFloorMod(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseFullyConnected(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseGather(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseGatherNd(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseGreater(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseGreaterEqual(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseHardSwish(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseIf(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseL2Normalization(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseLeakyRelu(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseLess(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseLessEqual(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseLog(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseLogicalAnd(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseLogicalNot(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseLogicalOr(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseLogistic(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseLogSoftmax(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseMaximum(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseMinimum(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseMul(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseNeg(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseNotEqual(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParsePack(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParsePad(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParsePadV2(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParsePool(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParsePow(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParsePrelu(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseQuantize(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseReducer(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseRelu(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseRelu6(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseReshape(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseResizeBilinear(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseResizeNearestNeighbor(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseRound(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseRsqrt(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseShape(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseSin(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseSoftmax(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseSpaceToBatchNd(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseSpaceToDepth(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseSplit(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseSplitV(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseSqueeze(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseSqrt(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseSquare(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseStridedSlice(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseSub(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseSvdf(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseTanh(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseTranspose(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseTransposeConv(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +TfLiteStatus ParseUnpack(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, void **builtin_data); + +TfLiteStatus ParseZerosLike(const Operator *op, ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + +} // namespace tflite + +#endif // TENSORFLOW_LITE_CORE_API_FLATBUFFER_CONVERSIONS_H_ diff --git a/components/tflite/tensorflow/lite/core/api/op_resolver.cc b/components/tflite/tensorflow/lite/core/api/op_resolver.cc new file mode 100644 index 00000000..363848bd --- /dev/null +++ b/components/tflite/tensorflow/lite/core/api/op_resolver.cc @@ -0,0 +1,70 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/core/api/op_resolver.h" + +#include "flatbuffers/flatbuffers.h" // from @flatbuffers +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/core/api/error_reporter.h" +#include "tensorflow/lite/schema/schema_utils.h" + +namespace tflite { + +TfLiteStatus GetRegistrationFromOpCode( + const OperatorCode *opcode, const OpResolver &op_resolver, + ErrorReporter *error_reporter, const TfLiteRegistration **registration) +{ + TfLiteStatus status = kTfLiteOk; + *registration = nullptr; + auto builtin_code = GetBuiltinCode(opcode); + int version = opcode->version(); + + if (builtin_code > BuiltinOperator_MAX || + builtin_code < BuiltinOperator_MIN) { + TF_LITE_REPORT_ERROR( + error_reporter, + "Op builtin_code out of range: %d. Are you using old TFLite binary " + "with newer model?", + builtin_code); + status = kTfLiteError; + } else if (builtin_code != BuiltinOperator_CUSTOM) { + *registration = op_resolver.FindOp(builtin_code, version); + if (*registration == nullptr) { + TF_LITE_REPORT_ERROR( + error_reporter, + "Didn't find op for builtin opcode '%s' version '%d'. " + "An older version of this builtin might be supported. " + "Are you using an old TFLite binary with a newer model?\n", + EnumNameBuiltinOperator(builtin_code), version); + status = kTfLiteError; + } + } else if (!opcode->custom_code()) { + TF_LITE_REPORT_ERROR( + error_reporter, + "Operator with CUSTOM builtin_code has no custom_code.\n"); + status = kTfLiteError; + } else { + const char *name = opcode->custom_code()->c_str(); + *registration = op_resolver.FindOp(name, version); + if (*registration == nullptr) { + // Do not report error for unresolved custom op, we do the final check + // while preparing ops. + status = kTfLiteError; + } + } + return status; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/core/api/op_resolver.h b/components/tflite/tensorflow/lite/core/api/op_resolver.h new file mode 100644 index 00000000..85cfdccb --- /dev/null +++ b/components/tflite/tensorflow/lite/core/api/op_resolver.h @@ -0,0 +1,82 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_CORE_API_OP_RESOLVER_H_ +#define TENSORFLOW_LITE_CORE_API_OP_RESOLVER_H_ + +#include +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/core/api/error_reporter.h" +#include "tensorflow/lite/schema/schema_generated.h" + +namespace tflite { +/// Abstract interface that returns TfLiteRegistrations given op codes or custom +/// op names. This is the mechanism that ops being referenced in the flatbuffer +/// model are mapped to executable function pointers (TfLiteRegistrations). +class OpResolver { +public: + /// Finds the op registration for a builtin operator by enum code. + virtual const TfLiteRegistration *FindOp(tflite::BuiltinOperator op, + int version) const = 0; + /// Finds the op registration of a custom operator by op name. + virtual const TfLiteRegistration *FindOp(const char *op, + int version) const = 0; + + // Returns optional delegates for resolving and handling ops in the flatbuffer + // model. This may be used in addition to the standard TfLiteRegistration + // lookup for graph resolution. + using TfLiteDelegatePtrVector = + std::vector >; + virtual TfLiteDelegatePtrVector GetDelegates(int num_threads) const + { + return TfLiteDelegatePtrVector(); + } + + virtual ~OpResolver() + { + } + +private: + /// Returns true if this OpResolver may contain any "user defined" ops. + /// By "user defined" ops, we mean any op definitions other than those + /// contained in tflite::ops::builtin::BuiltinOpResolver. + /// + /// If this method returns true, it doesn't necessarily mean that the + /// OpResolver contains a user-defined op, just that the absence of + /// user-defined ops can't be guaranteed. + /// + /// Note that "user-defined" ops are not the same as "custom" ops; + /// BuiltinOpResolver may support certain "custom" ops, in addition to + /// "builtin" ops, and may not support all of the "builtin" op enum values. + virtual bool MayContainUserDefinedOps() const + { + return true; + } + + friend class OpResolverInternal; +}; + +// Handles the logic for converting between an OperatorCode structure extracted +// from a flatbuffer and information about a registered operator +// implementation. +TfLiteStatus GetRegistrationFromOpCode(const OperatorCode *opcode, + const OpResolver &op_resolver, + ErrorReporter *error_reporter, + const TfLiteRegistration **registration); + +} // namespace tflite + +#endif // TENSORFLOW_LITE_CORE_API_OP_RESOLVER_H_ diff --git a/components/tflite/tensorflow/lite/core/api/tensor_utils.cc b/components/tflite/tensorflow/lite/core/api/tensor_utils.cc new file mode 100644 index 00000000..30259ba4 --- /dev/null +++ b/components/tflite/tensorflow/lite/core/api/tensor_utils.cc @@ -0,0 +1,51 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/core/api/tensor_utils.h" + +#include + +#include "tensorflow/lite/c/common.h" + +namespace tflite { + +TfLiteStatus ResetVariableTensor(TfLiteTensor *tensor) +{ + if (!tensor->is_variable) { + return kTfLiteOk; + } + // TODO(b/115961645): Implement - If a variable tensor has a buffer, reset it + // to the value of the buffer. + int value = 0; + if (tensor->type == kTfLiteInt8) { + value = tensor->params.zero_point; + } + // TODO(b/139446230): Provide a platform header to better handle these + // specific scenarios. +#if __ANDROID__ || defined(__x86_64__) || defined(__i386__) || \ + defined(__i386) || defined(__x86__) || defined(__X86__) || \ + defined(_X86_) || defined(_M_IX86) || defined(_M_X64) + memset(tensor->data.raw, value, tensor->bytes); +#else + char *raw_ptr = tensor->data.raw; + for (size_t i = 0; i < tensor->bytes; ++i) { + *raw_ptr = value; + raw_ptr++; + } +#endif + return kTfLiteOk; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/core/api/tensor_utils.h b/components/tflite/tensorflow/lite/core/api/tensor_utils.h new file mode 100644 index 00000000..a57acce2 --- /dev/null +++ b/components/tflite/tensorflow/lite/core/api/tensor_utils.h @@ -0,0 +1,27 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_CORE_API_TENSOR_UTILS_H_ +#define TENSORFLOW_LITE_CORE_API_TENSOR_UTILS_H_ + +#include "tensorflow/lite/c/common.h" + +namespace tflite { +// Resets a variable tensor to the default value. +TfLiteStatus ResetVariableTensor(TfLiteTensor *tensor); + +} // namespace tflite + +#endif // TENSORFLOW_LITE_CORE_API_TENSOR_UTILS_H_ diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/README.md b/components/tflite/tensorflow/lite/experimental/microfrontend/README.md new file mode 100644 index 00000000..1362ddb2 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/README.md @@ -0,0 +1,6 @@ +This directory contains the subset of functionality that is needed to run the +micro_speech example with TFLM. + +The source of truth for the experimental microfrontend in TfLite is at: +https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/experimental/microfrontend + diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/README.md b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/README.md new file mode 100644 index 00000000..ba5e82c4 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/README.md @@ -0,0 +1,65 @@ +# Audio "frontend" library for feature generation + +A feature generation library (also called frontend) that receives raw audio +input, and produces filter banks (a vector of values). + +The raw audio input is expected to be 16-bit PCM features, with a configurable +sample rate. More specifically the audio signal goes through a pre-emphasis +filter (optionally); then gets sliced into (potentially overlapping) frames and +a window function is applied to each frame; afterwards, we do a Fourier +transform on each frame (or more specifically a Short-Time Fourier Transform) +and calculate the power spectrum; and subsequently compute the filter banks. + +By default the library is configured with a set of defaults to perform the +different processing tasks. This takes place with the frontend_util.c function: + +```c++ +void FrontendFillConfigWithDefaults(struct FrontendConfig* config) +``` + +A single invocation looks like: + +```c++ +struct FrontendConfig frontend_config; +FrontendFillConfigWithDefaults(&frontend_config); +int sample_rate = 16000; +FrontendPopulateState(&frontend_config, &frontend_state, sample_rate); +int16_t* audio_data = ; // PCM audio samples at 16KHz. +size_t audio_size = ; // Number of audio samples. +size_t num_samples_read; // How many samples were processed. +struct FrontendOutput output = + FrontendProcessSamples( + &frontend_state, audio_data, audio_size, &num_samples_read); +for (i = 0; i < output.size; ++i) { + printf("%d ", output.values[i]); // Print the feature vector. +} +``` + +Something to note in the above example is that the frontend consumes as many +samples needed from the audio data to produce a single feature vector (according +to the frontend configuration). If not enough samples were available to generate +a feature vector, the returned size will be 0 and the values pointer will be +`NULL`. + +An example of how to use the frontend is provided in frontend_main.cc and its +binary frontend_main. This example, expects a path to a file containing `int16` +PCM features at a sample rate of 16KHz, and upon execution will printing out +the coefficients according to the frontend default configuration. + +## Extra features +Extra features of this frontend library include a noise reduction module, as +well as a gain control module. + +**Noise cancellation**. Removes stationary noise from each channel of the signal +using a low pass filter. + +**Gain control**. A novel automatic gain control based dynamic compression to +replace the widely used static (such as log or root) compression. Disabled +by default. + +## Memory map +The binary frontend_memmap_main shows a sample usage of how to avoid all the +initialization code in your application, by first running +"frontend_generate_memmap" to create a header/source file that uses a baked in +frontend state. This command could be automated as part of your build process, +or you can just use the output directly. diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/bits.h b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/bits.h new file mode 100644 index 00000000..2b74286c --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/bits.h @@ -0,0 +1,115 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_BITS_H_ +#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_BITS_H_ + +#ifdef __cplusplus +#include + +extern "C" { +#endif + +static inline int CountLeadingZeros32Slow(uint64_t n) +{ + int zeroes = 28; + if (n >> 16) + zeroes -= 16, n >>= 16; + if (n >> 8) + zeroes -= 8, n >>= 8; + if (n >> 4) + zeroes -= 4, n >>= 4; + return "\4\3\2\2\1\1\1\1\0\0\0\0\0\0\0"[n] + zeroes; +} + +static inline int CountLeadingZeros32(uint32_t n) +{ +#if defined(_MSC_VER) + unsigned long result = 0; // NOLINT(runtime/int) + if (_BitScanReverse(&result, n)) { + return 31 - result; + } + return 32; +#elif defined(__GNUC__) + + // Handle 0 as a special case because __builtin_clz(0) is undefined. + if (n == 0) { + return 32; + } + return __builtin_clz(n); +#else + return CountLeadingZeros32Slow(n); +#endif +} + +static inline int MostSignificantBit32(uint32_t n) +{ + return 32 - CountLeadingZeros32(n); +} + +static inline int CountLeadingZeros64Slow(uint64_t n) +{ + int zeroes = 60; + if (n >> 32) + zeroes -= 32, n >>= 32; + if (n >> 16) + zeroes -= 16, n >>= 16; + if (n >> 8) + zeroes -= 8, n >>= 8; + if (n >> 4) + zeroes -= 4, n >>= 4; + return "\4\3\2\2\1\1\1\1\0\0\0\0\0\0\0"[n] + zeroes; +} + +static inline int CountLeadingZeros64(uint64_t n) +{ +#if defined(_MSC_VER) && defined(_M_X64) + // MSVC does not have __builtin_clzll. Use _BitScanReverse64. + unsigned long result = 0; // NOLINT(runtime/int) + if (_BitScanReverse64(&result, n)) { + return 63 - result; + } + return 64; +#elif defined(_MSC_VER) + // MSVC does not have __builtin_clzll. Compose two calls to _BitScanReverse + unsigned long result = 0; // NOLINT(runtime/int) + if ((n >> 32) && _BitScanReverse(&result, n >> 32)) { + return 31 - result; + } + if (_BitScanReverse(&result, n)) { + return 63 - result; + } + return 64; +#elif defined(__GNUC__) + + // Handle 0 as a special case because __builtin_clzll(0) is undefined. + if (n == 0) { + return 64; + } + return __builtin_clzll(n); +#else + return CountLeadingZeros64Slow(n); +#endif +} + +static inline int MostSignificantBit64(uint64_t n) +{ + return 64 - CountLeadingZeros64(n); +} + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_BITS_H_ diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/fft.cc b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/fft.cc new file mode 100644 index 00000000..4312abff --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/fft.cc @@ -0,0 +1,56 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/fft.h" + +#include + +#define FIXED_POINT 16 +#include "kiss_fft.h" +#include "tools/kiss_fftr.h" + +void FftCompute(struct FftState *state, const int16_t *input, + int input_scale_shift) +{ + const size_t input_size = state->input_size; + const size_t fft_size = state->fft_size; + + int16_t *fft_input = state->input; + // First, scale the input by the given shift. + size_t i; + for (i = 0; i < input_size; ++i) { + fft_input[i] = static_cast(static_cast(input[i]) + << input_scale_shift); + } + // Zero out whatever else remains in the top part of the input. + for (; i < fft_size; ++i) { + fft_input[i] = 0; + } + + // Apply the FFT. + kiss_fftr(reinterpret_cast(state->scratch), + state->input, + reinterpret_cast(state->output)); +} + +void FftInit(struct FftState *state) +{ + // All the initialization is done in FftPopulateState() +} + +void FftReset(struct FftState *state) +{ + memset(state->input, 0, state->fft_size * sizeof(*state->input)); + memset(state->output, 0, (state->fft_size / 2 + 1) * sizeof(*state->output)); +} diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/fft.h b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/fft.h new file mode 100644 index 00000000..2197eb60 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/fft.h @@ -0,0 +1,50 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FFT_H_ +#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FFT_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct complex_int16_t { + int16_t real; + int16_t imag; +}; + +struct FftState { + int16_t *input; + struct complex_int16_t *output; + size_t fft_size; + size_t input_size; + void *scratch; + size_t scratch_size; +}; + +void FftCompute(struct FftState *state, const int16_t *input, + int input_scale_shift); + +void FftInit(struct FftState *state); + +void FftReset(struct FftState *state); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FFT_H_ diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/fft_io.c b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/fft_io.c new file mode 100644 index 00000000..1f9a6945 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/fft_io.c @@ -0,0 +1,35 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/fft_io.h" + +void FftWriteMemmapPreamble(FILE *fp, const struct FftState *state) +{ + fprintf(fp, "static int16_t fft_input[%zu];\n", state->fft_size); + fprintf(fp, "static struct complex_int16_t fft_output[%zu];\n", + state->fft_size / 2 + 1); + fprintf(fp, "static char fft_scratch[%zu];\n", state->scratch_size); + fprintf(fp, "\n"); +} + +void FftWriteMemmap(FILE *fp, const struct FftState *state, + const char *variable) +{ + fprintf(fp, "%s->input = fft_input;\n", variable); + fprintf(fp, "%s->output = fft_output;\n", variable); + fprintf(fp, "%s->fft_size = %zu;\n", variable, state->fft_size); + fprintf(fp, "%s->input_size = %zu;\n", variable, state->input_size); + fprintf(fp, "%s->scratch = fft_scratch;\n", variable); + fprintf(fp, "%s->scratch_size = %zu;\n", variable, state->scratch_size); +} diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/fft_io.h b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/fft_io.h new file mode 100644 index 00000000..4bdd9372 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/fft_io.h @@ -0,0 +1,34 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FFT_IO_H_ +#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FFT_IO_H_ + +#include + +#include "tensorflow/lite/experimental/microfrontend/lib/fft.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void FftWriteMemmapPreamble(FILE *fp, const struct FftState *state); +void FftWriteMemmap(FILE *fp, const struct FftState *state, + const char *variable); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FFT_IO_H_ diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/fft_test.cc b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/fft_test.cc new file mode 100644 index 00000000..ee16ad98 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/fft_test.cc @@ -0,0 +1,55 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/fft.h" + +#include "tensorflow/lite/experimental/microfrontend/lib/fft_util.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace { + +const int16_t kFakeWindow[] = { + 0, 1151, 0, -5944, 0, 13311, 0, -21448, 0, 28327, 0, -32256, 0, 32255, + 0, -28328, 0, 21447, 0, -13312, 0, 5943, 0, -1152, 0 +}; +const int kScaleShift = 0; + +} // namespace + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(FftTest_CheckOutputValues) +{ + struct FftState state; + TF_LITE_MICRO_EXPECT( + FftPopulateState(&state, sizeof(kFakeWindow) / sizeof(kFakeWindow[0]))); + + FftInit(&state); + FftCompute(&state, kFakeWindow, kScaleShift); + + const struct complex_int16_t expected[] = { + { 0, 0 }, { -10, 9 }, { -20, 0 }, { -9, -10 }, { 0, 25 }, { -119, 119 }, { -887, 0 }, { 3000, 3000 }, { 0, -6401 }, { -3000, 3000 }, { 886, 0 }, { 118, 119 }, { 0, 25 }, { 9, -10 }, { 19, 0 }, { 9, 9 }, { 0, 0 } + }; + TF_LITE_MICRO_EXPECT_EQ(state.fft_size / 2 + 1, + sizeof(expected) / sizeof(expected[0])); + unsigned int i; + for (i = 0; i <= state.fft_size / 2; ++i) { + TF_LITE_MICRO_EXPECT_EQ(state.output[i].real, expected[i].real); + TF_LITE_MICRO_EXPECT_EQ(state.output[i].imag, expected[i].imag); + } + + FftFreeStateContents(&state); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/fft_util.cc b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/fft_util.cc new file mode 100644 index 00000000..73beb812 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/fft_util.cc @@ -0,0 +1,74 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/fft_util.h" + +#include + +#define FIXED_POINT 16 +#include "kiss_fft.h" +#include "tools/kiss_fftr.h" + +int FftPopulateState(struct FftState *state, size_t input_size) +{ + state->input_size = input_size; + state->fft_size = 1; + while (state->fft_size < state->input_size) { + state->fft_size <<= 1; + } + + state->input = reinterpret_cast( + malloc(state->fft_size * sizeof(*state->input))); + if (state->input == nullptr) { + fprintf(stderr, "Failed to alloc fft input buffer\n"); + return 0; + } + + state->output = reinterpret_cast( + malloc((state->fft_size / 2 + 1) * sizeof(*state->output) * 2)); + if (state->output == nullptr) { + fprintf(stderr, "Failed to alloc fft output buffer\n"); + return 0; + } + + // Ask kissfft how much memory it wants. + size_t scratch_size = 0; + kiss_fftr_cfg kfft_cfg = kiss_fftr_alloc( + state->fft_size, 0, nullptr, &scratch_size); + if (kfft_cfg != nullptr) { + fprintf(stderr, "Kiss memory sizing failed.\n"); + return 0; + } + state->scratch = malloc(scratch_size); + if (state->scratch == nullptr) { + fprintf(stderr, "Failed to alloc fft scratch buffer\n"); + return 0; + } + state->scratch_size = scratch_size; + // Let kissfft configure the scratch space we just allocated + kfft_cfg = kiss_fftr_alloc(state->fft_size, 0, + state->scratch, &scratch_size); + if (kfft_cfg != state->scratch) { + fprintf(stderr, "Kiss memory preallocation strategy failed.\n"); + return 0; + } + return 1; +} + +void FftFreeStateContents(struct FftState *state) +{ + free(state->input); + free(state->output); + free(state->scratch); +} diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/fft_util.h b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/fft_util.h new file mode 100644 index 00000000..8552abaa --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/fft_util.h @@ -0,0 +1,34 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FFT_UTIL_H_ +#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FFT_UTIL_H_ + +#include "tensorflow/lite/experimental/microfrontend/lib/fft.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// Prepares and FFT for the given input size. +int FftPopulateState(struct FftState *state, size_t input_size); + +// Frees any allocated buffers. +void FftFreeStateContents(struct FftState *state); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FFT_UTIL_H_ diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/filterbank.c b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/filterbank.c new file mode 100644 index 00000000..88c94822 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/filterbank.c @@ -0,0 +1,140 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/filterbank.h" + +#include + +#include "tensorflow/lite/experimental/microfrontend/lib/bits.h" + +void FilterbankConvertFftComplexToEnergy(struct FilterbankState *state, + struct complex_int16_t *fft_output, + int32_t *energy) +{ + const int end_index = state->end_index; + int i; + energy += state->start_index; + fft_output += state->start_index; + for (i = state->start_index; i < end_index; ++i) { + const int32_t real = fft_output->real; + const int32_t imag = fft_output->imag; + fft_output++; + const uint32_t mag_squared = (real * real) + (imag * imag); + *energy++ = mag_squared; + } +} + +void FilterbankAccumulateChannels(struct FilterbankState *state, + const int32_t *energy) +{ + uint64_t *work = state->work; + uint64_t weight_accumulator = 0; + uint64_t unweight_accumulator = 0; + + const int16_t *channel_frequency_starts = state->channel_frequency_starts; + const int16_t *channel_weight_starts = state->channel_weight_starts; + const int16_t *channel_widths = state->channel_widths; + + int num_channels_plus_1 = state->num_channels + 1; + int i; + for (i = 0; i < num_channels_plus_1; ++i) { + const int32_t *magnitudes = energy + *channel_frequency_starts++; + const int16_t *weights = state->weights + *channel_weight_starts; + const int16_t *unweights = state->unweights + *channel_weight_starts++; + const int width = *channel_widths++; + int j; + for (j = 0; j < width; ++j) { + weight_accumulator += *weights++ * ((uint64_t)*magnitudes); + unweight_accumulator += *unweights++ * ((uint64_t)*magnitudes); + ++magnitudes; + } + *work++ = weight_accumulator; + weight_accumulator = unweight_accumulator; + unweight_accumulator = 0; + } +} + +static uint16_t Sqrt32(uint32_t num) +{ + if (num == 0) { + return 0; + } + uint32_t res = 0; + int max_bit_number = 32 - MostSignificantBit32(num); + max_bit_number |= 1; + uint32_t bit = 1U << (31 - max_bit_number); + int iterations = (31 - max_bit_number) / 2 + 1; + while (iterations--) { + if (num >= res + bit) { + num -= res + bit; + res = (res >> 1U) + bit; + } else { + res >>= 1U; + } + bit >>= 2U; + } + // Do rounding - if we have the bits. + if (num > res && res != 0xFFFF) { + ++res; + } + return res; +} + +static uint32_t Sqrt64(uint64_t num) +{ + // Take a shortcut and just use 32 bit operations if the upper word is all + // clear. This will cause a slight off by one issue for numbers close to 2^32, + // but it probably isn't going to matter (and gives us a big performance win). + if ((num >> 32) == 0) { + return Sqrt32((uint32_t)num); + } + uint64_t res = 0; + int max_bit_number = 64 - MostSignificantBit64(num); + max_bit_number |= 1; + uint64_t bit = 1ULL << (63 - max_bit_number); + int iterations = (63 - max_bit_number) / 2 + 1; + while (iterations--) { + if (num >= res + bit) { + num -= res + bit; + res = (res >> 1U) + bit; + } else { + res >>= 1U; + } + bit >>= 2U; + } + // Do rounding - if we have the bits. + if (num > res && res != 0xFFFFFFFFLL) { + ++res; + } + return res; +} + +uint32_t *FilterbankSqrt(struct FilterbankState *state, int scale_down_shift) +{ + const int num_channels = state->num_channels; + const uint64_t *work = state->work + 1; + // Reuse the work buffer since we're fine clobbering it at this point to hold + // the output. + uint32_t *output = (uint32_t *)state->work; + int i; + for (i = 0; i < num_channels; ++i) { + *output++ = Sqrt64(*work++) >> scale_down_shift; + } + return (uint32_t *)state->work; +} + +void FilterbankReset(struct FilterbankState *state) +{ + memset(state->work, 0, (state->num_channels + 1) * sizeof(*state->work)); +} diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/filterbank.h b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/filterbank.h new file mode 100644 index 00000000..07200295 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/filterbank.h @@ -0,0 +1,63 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FILTERBANK_H_ +#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FILTERBANK_H_ + +#include +#include + +#include "tensorflow/lite/experimental/microfrontend/lib/fft.h" + +#define kFilterbankBits 12 + +#ifdef __cplusplus +extern "C" { +#endif + +struct FilterbankState { + int num_channels; + int start_index; + int end_index; + int16_t *channel_frequency_starts; + int16_t *channel_weight_starts; + int16_t *channel_widths; + int16_t *weights; + int16_t *unweights; + uint64_t *work; +}; + +// Converts the relevant complex values of an FFT output into energy (the +// square magnitude). +void FilterbankConvertFftComplexToEnergy(struct FilterbankState *state, + struct complex_int16_t *fft_output, + int32_t *energy); + +// Computes the mel-scale filterbank on the given energy array. Output is cached +// internally - to fetch it, you need to call FilterbankSqrt. +void FilterbankAccumulateChannels(struct FilterbankState *state, + const int32_t *energy); + +// Applies an integer square root to the 64 bit intermediate values of the +// filterbank, and returns a pointer to them. Memory will be invalidated the +// next time FilterbankAccumulateChannels is called. +uint32_t *FilterbankSqrt(struct FilterbankState *state, int scale_down_shift); + +void FilterbankReset(struct FilterbankState *state); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FILTERBANK_H_ diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/filterbank_io.c b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/filterbank_io.c new file mode 100644 index 00000000..4ee60fe1 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/filterbank_io.c @@ -0,0 +1,70 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/filterbank_io.h" + +static void PrintArray(FILE *fp, const char *name, const int16_t *values, + size_t size) +{ + fprintf(fp, "static int16_t filterbank_%s[] = {", name); + int i; + for (i = 0; i < size; ++i) { + fprintf(fp, "%d", values[i]); + if (i < size - 1) { + fprintf(fp, ", "); + } + } + fprintf(fp, "};\n"); +} + +void FilterbankWriteMemmapPreamble(FILE *fp, + const struct FilterbankState *state) +{ + const int num_channels_plus_1 = state->num_channels + 1; + + PrintArray(fp, "channel_frequency_starts", state->channel_frequency_starts, + num_channels_plus_1); + PrintArray(fp, "channel_weight_starts", state->channel_weight_starts, + num_channels_plus_1); + PrintArray(fp, "channel_widths", state->channel_widths, num_channels_plus_1); + int num_weights = 0; + int i; + for (i = 0; i < num_channels_plus_1; ++i) { + num_weights += state->channel_widths[i]; + } + PrintArray(fp, "weights", state->weights, num_weights); + PrintArray(fp, "unweights", state->unweights, num_weights); + + fprintf(fp, "static uint64_t filterbank_work[%d];\n", num_channels_plus_1); + fprintf(fp, "\n"); +} + +void FilterbankWriteMemmap(FILE *fp, const struct FilterbankState *state, + const char *variable) +{ + fprintf(fp, "%s->num_channels = %d;\n", variable, state->num_channels); + fprintf(fp, "%s->start_index = %d;\n", variable, state->start_index); + fprintf(fp, "%s->end_index = %d;\n", variable, state->end_index); + + fprintf( + fp, + "%s->channel_frequency_starts = filterbank_channel_frequency_starts;\n", + variable); + fprintf(fp, "%s->channel_weight_starts = filterbank_channel_weight_starts;\n", + variable); + fprintf(fp, "%s->channel_widths = filterbank_channel_widths;\n", variable); + fprintf(fp, "%s->weights = filterbank_weights;\n", variable); + fprintf(fp, "%s->unweights = filterbank_unweights;\n", variable); + fprintf(fp, "%s->work = filterbank_work;\n", variable); +} diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/filterbank_io.h b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/filterbank_io.h new file mode 100644 index 00000000..239c20be --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/filterbank_io.h @@ -0,0 +1,35 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FILTERBANK_IO_H_ +#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FILTERBANK_IO_H_ + +#include + +#include "tensorflow/lite/experimental/microfrontend/lib/filterbank.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void FilterbankWriteMemmapPreamble(FILE *fp, + const struct FilterbankState *state); +void FilterbankWriteMemmap(FILE *fp, const struct FilterbankState *state, + const char *variable); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FILTERBANK_IO_H_ diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/filterbank_test.cc b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/filterbank_test.cc new file mode 100644 index 00000000..82e6bb88 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/filterbank_test.cc @@ -0,0 +1,229 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/filterbank.h" + +#include + +#include "tensorflow/lite/experimental/microfrontend/lib/filterbank_util.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace { + +const int kSampleRate = 1000; +const int kSpectrumSize = 17; +const int kStartIndex = 1; +const int kEndIndex = 15; +const int32_t kEnergy[] = { -1, 181, 400, 181, 625, 28322, + 786769, 18000000, 40972801, 18000000, 784996, 28085, + 625, 181, 361, -1, -1 }; +const uint64_t kWork[] = { 1835887, 61162970173, 258694800000 }; +const int kScaleShift = 0; + +// Test filterbank generation using scaled-down defaults. +class FilterbankTestConfig { +public: + FilterbankTestConfig() + { + config_.num_channels = 2; + config_.lower_band_limit = 8.0; + config_.upper_band_limit = 450.0; + } + + struct FilterbankConfig config_; +}; + +} // namespace + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(FilterbankTest_CheckStartIndex) +{ + FilterbankTestConfig config; + struct FilterbankState state; + TF_LITE_MICRO_EXPECT(FilterbankPopulateState(&config.config_, &state, + kSampleRate, kSpectrumSize)); + + TF_LITE_MICRO_EXPECT_EQ(state.start_index, kStartIndex); + + FilterbankFreeStateContents(&state); +} + +TF_LITE_MICRO_TEST(FilterbankTest_CheckEndIndex) +{ + FilterbankTestConfig config; + struct FilterbankState state; + TF_LITE_MICRO_EXPECT(FilterbankPopulateState(&config.config_, &state, + kSampleRate, kSpectrumSize)); + + TF_LITE_MICRO_EXPECT_EQ(state.end_index, kEndIndex); + + FilterbankFreeStateContents(&state); +} + +TF_LITE_MICRO_TEST(FilterbankTest_CheckChannelFrequencyStarts) +{ + FilterbankTestConfig config; + struct FilterbankState state; + TF_LITE_MICRO_EXPECT(FilterbankPopulateState(&config.config_, &state, + kSampleRate, kSpectrumSize)); + + const int16_t expected[] = { 0, 4, 8 }; + TF_LITE_MICRO_EXPECT_EQ(state.num_channels + 1, + sizeof(expected) / sizeof(expected[0])); + int i; + for (i = 0; i <= state.num_channels; ++i) { + TF_LITE_MICRO_EXPECT_EQ(state.channel_frequency_starts[i], expected[i]); + } + + FilterbankFreeStateContents(&state); +} + +TF_LITE_MICRO_TEST(FilterbankTest_CheckChannelWeightStarts) +{ + FilterbankTestConfig config; + struct FilterbankState state; + TF_LITE_MICRO_EXPECT(FilterbankPopulateState(&config.config_, &state, + kSampleRate, kSpectrumSize)); + + const int16_t expected[] = { 0, 8, 16 }; + TF_LITE_MICRO_EXPECT_EQ(state.num_channels + 1, + sizeof(expected) / sizeof(expected[0])); + int i; + for (i = 0; i <= state.num_channels; ++i) { + TF_LITE_MICRO_EXPECT_EQ(state.channel_weight_starts[i], expected[i]); + } + + FilterbankFreeStateContents(&state); +} + +TF_LITE_MICRO_TEST(FilterbankTest_CheckChannelWidths) +{ + FilterbankTestConfig config; + struct FilterbankState state; + TF_LITE_MICRO_EXPECT(FilterbankPopulateState(&config.config_, &state, + kSampleRate, kSpectrumSize)); + + const int16_t expected[] = { 8, 8, 8 }; + TF_LITE_MICRO_EXPECT_EQ(state.num_channels + 1, + sizeof(expected) / sizeof(expected[0])); + int i; + for (i = 0; i <= state.num_channels; ++i) { + TF_LITE_MICRO_EXPECT_EQ(state.channel_widths[i], expected[i]); + } + + FilterbankFreeStateContents(&state); +} + +TF_LITE_MICRO_TEST(FilterbankTest_CheckWeights) +{ + FilterbankTestConfig config; + struct FilterbankState state; + TF_LITE_MICRO_EXPECT(FilterbankPopulateState(&config.config_, &state, + kSampleRate, kSpectrumSize)); + + const int16_t expected[] = { 0, 3277, 2217, 1200, 222, 0, 0, 0, + 0, 3376, 2468, 1591, 744, 0, 0, 0, + 0, 4020, 3226, 2456, 1708, 983, 277, 0 }; + TF_LITE_MICRO_EXPECT_EQ(state.channel_weight_starts[state.num_channels] + + state.channel_widths[state.num_channels], + sizeof(expected) / sizeof(expected[0])); + int i; + for (i = 0; i < sizeof(expected) / sizeof(expected[0]); ++i) { + TF_LITE_MICRO_EXPECT_EQ(state.weights[i], expected[i]); + } + + FilterbankFreeStateContents(&state); +} + +TF_LITE_MICRO_TEST(FilterbankTest_CheckUnweights) +{ + FilterbankTestConfig config; + struct FilterbankState state; + TF_LITE_MICRO_EXPECT(FilterbankPopulateState(&config.config_, &state, + kSampleRate, kSpectrumSize)); + + const int16_t expected[] = { 0, 819, 1879, 2896, 3874, 0, 0, 0, + 0, 720, 1628, 2505, 3352, 0, 0, 0, + 0, 76, 870, 1640, 2388, 3113, 3819, 0 }; + TF_LITE_MICRO_EXPECT_EQ(state.channel_weight_starts[state.num_channels] + + state.channel_widths[state.num_channels], + sizeof(expected) / sizeof(expected[0])); + int i; + for (i = 0; i < sizeof(expected) / sizeof(expected[0]); ++i) { + TF_LITE_MICRO_EXPECT_EQ(state.unweights[i], expected[i]); + } + + FilterbankFreeStateContents(&state); +} + +TF_LITE_MICRO_TEST(FilterbankTest_CheckConvertFftComplexToEnergy) +{ + struct FilterbankState state; + state.start_index = kStartIndex; + state.end_index = kEndIndex; + + struct complex_int16_t fake_fft[] = { + { 0, 0 }, { -10, 9 }, { -20, 0 }, { -9, -10 }, { 0, 25 }, { -119, 119 }, { -887, 0 }, { 3000, 3000 }, { 0, -6401 }, { -3000, 3000 }, { 886, 0 }, { 118, 119 }, { 0, 25 }, { 9, -10 }, { 19, 0 }, { 9, 9 }, { 0, 0 } + }; + int32_t *energy = reinterpret_cast(fake_fft); + FilterbankConvertFftComplexToEnergy(&state, fake_fft, energy); + + int i; + for (i = state.start_index; i < state.end_index; ++i) { + TF_LITE_MICRO_EXPECT_EQ(energy[i], kEnergy[i]); + } +} + +TF_LITE_MICRO_TEST(FilterbankTest_CheckAccumulateChannels) +{ + FilterbankTestConfig config; + struct FilterbankState state; + TF_LITE_MICRO_EXPECT(FilterbankPopulateState(&config.config_, &state, + kSampleRate, kSpectrumSize)); + + FilterbankAccumulateChannels(&state, kEnergy); + + TF_LITE_MICRO_EXPECT_EQ(state.num_channels + 1, + sizeof(kWork) / sizeof(kWork[0])); + int i; + for (i = 0; i <= state.num_channels; ++i) { + TF_LITE_MICRO_EXPECT_EQ(state.work[i], kWork[i]); + } + + FilterbankFreeStateContents(&state); +} + +TF_LITE_MICRO_TEST(FilterbankTest_CheckSqrt) +{ + FilterbankTestConfig config; + struct FilterbankState state; + TF_LITE_MICRO_EXPECT(FilterbankPopulateState(&config.config_, &state, + kSampleRate, kSpectrumSize)); + std::memcpy(state.work, kWork, sizeof(kWork)); + + uint32_t *scaled_filterbank = FilterbankSqrt(&state, kScaleShift); + + const uint32_t expected[] = { 247311, 508620 }; + TF_LITE_MICRO_EXPECT_EQ(state.num_channels, + sizeof(expected) / sizeof(expected[0])); + int i; + for (i = 0; i < state.num_channels; ++i) { + TF_LITE_MICRO_EXPECT_EQ(scaled_filterbank[i], expected[i]); + } + + FilterbankFreeStateContents(&state); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/filterbank_util.c b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/filterbank_util.c new file mode 100644 index 00000000..4afa4d33 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/filterbank_util.c @@ -0,0 +1,226 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/filterbank_util.h" + +#include +#include +#include + +#define kFilterbankIndexAlignment 4 +#define kFilterbankChannelBlockSize 4 + +void FilterbankFillConfigWithDefaults(struct FilterbankConfig *config) +{ + config->num_channels = 32; + config->lower_band_limit = 125.0f; + config->upper_band_limit = 7500.0f; + config->output_scale_shift = 7; +} + +static float FreqToMel(float freq) +{ + return 1127.0 * log1p(freq / 700.0); +} + +static void CalculateCenterFrequencies(const int num_channels, + const float lower_frequency_limit, + const float upper_frequency_limit, + float *center_frequencies) +{ + assert(lower_frequency_limit >= 0.0f); + assert(upper_frequency_limit > lower_frequency_limit); + + const float mel_low = FreqToMel(lower_frequency_limit); + const float mel_hi = FreqToMel(upper_frequency_limit); + const float mel_span = mel_hi - mel_low; + const float mel_spacing = mel_span / ((float)num_channels); + int i; + for (i = 0; i < num_channels; ++i) { + center_frequencies[i] = mel_low + (mel_spacing * (i + 1)); + } +} + +static void QuantizeFilterbankWeights(const float float_weight, int16_t *weight, + int16_t *unweight) +{ + *weight = floor(float_weight * (1 << kFilterbankBits) + 0.5); + *unweight = floor((1.0 - float_weight) * (1 << kFilterbankBits) + 0.5); +} + +int FilterbankPopulateState(const struct FilterbankConfig *config, + struct FilterbankState *state, int sample_rate, + int spectrum_size) +{ + state->num_channels = config->num_channels; + const int num_channels_plus_1 = config->num_channels + 1; + + // How should we align things to index counts given the byte alignment? + const int index_alignment = + (kFilterbankIndexAlignment < sizeof(int16_t) ? 1 : kFilterbankIndexAlignment / sizeof(int16_t)); + + state->channel_frequency_starts = + malloc(num_channels_plus_1 * sizeof(*state->channel_frequency_starts)); + state->channel_weight_starts = + malloc(num_channels_plus_1 * sizeof(*state->channel_weight_starts)); + state->channel_widths = + malloc(num_channels_plus_1 * sizeof(*state->channel_widths)); + state->work = malloc(num_channels_plus_1 * sizeof(*state->work)); + + float *center_mel_freqs = + malloc(num_channels_plus_1 * sizeof(*center_mel_freqs)); + int16_t *actual_channel_starts = + malloc(num_channels_plus_1 * sizeof(*actual_channel_starts)); + int16_t *actual_channel_widths = + malloc(num_channels_plus_1 * sizeof(*actual_channel_widths)); + + if (state->channel_frequency_starts == NULL || + state->channel_weight_starts == NULL || state->channel_widths == NULL || + center_mel_freqs == NULL || actual_channel_starts == NULL || + actual_channel_widths == NULL) { + free(center_mel_freqs); + free(actual_channel_starts); + free(actual_channel_widths); + fprintf(stderr, "Failed to allocate channel buffers\n"); + return 0; + } + + CalculateCenterFrequencies(num_channels_plus_1, config->lower_band_limit, + config->upper_band_limit, center_mel_freqs); + + // Always exclude DC. + const float hz_per_sbin = 0.5 * sample_rate / ((float)spectrum_size - 1); + state->start_index = 1.5 + config->lower_band_limit / hz_per_sbin; + state->end_index = 0; // Initialized to zero here, but actually set below. + + // For each channel, we need to figure out what frequencies belong to it, and + // how much padding we need to add so that we can efficiently multiply the + // weights and unweights for accumulation. To simplify the multiplication + // logic, all channels will have some multiplication to do (even if there are + // no frequencies that accumulate to that channel) - they will be directed to + // a set of zero weights. + int chan_freq_index_start = state->start_index; + int weight_index_start = 0; + int needs_zeros = 0; + + int chan; + for (chan = 0; chan < num_channels_plus_1; ++chan) { + // Keep jumping frequencies until we overshoot the bound on this channel. + int freq_index = chan_freq_index_start; + while (FreqToMel((freq_index)*hz_per_sbin) <= center_mel_freqs[chan]) { + ++freq_index; + } + + const int width = freq_index - chan_freq_index_start; + actual_channel_starts[chan] = chan_freq_index_start; + actual_channel_widths[chan] = width; + + if (width == 0) { + // This channel doesn't actually get anything from the frequencies, it's + // always zero. We need then to insert some 'zero' weights into the + // output, and just redirect this channel to do a single multiplication at + // this point. For simplicity, the zeros are placed at the beginning of + // the weights arrays, so we have to go and update all the other + // weight_starts to reflect this shift (but only once). + state->channel_frequency_starts[chan] = 0; + state->channel_weight_starts[chan] = 0; + state->channel_widths[chan] = kFilterbankChannelBlockSize; + if (!needs_zeros) { + needs_zeros = 1; + int j; + for (j = 0; j < chan; ++j) { + state->channel_weight_starts[j] += kFilterbankChannelBlockSize; + } + weight_index_start += kFilterbankChannelBlockSize; + } + } else { + // How far back do we need to go to ensure that we have the proper + // alignment? + const int aligned_start = + (chan_freq_index_start / index_alignment) * index_alignment; + const int aligned_width = (chan_freq_index_start - aligned_start + width); + const int padded_width = + (((aligned_width - 1) / kFilterbankChannelBlockSize) + 1) * + kFilterbankChannelBlockSize; + + state->channel_frequency_starts[chan] = aligned_start; + state->channel_weight_starts[chan] = weight_index_start; + state->channel_widths[chan] = padded_width; + weight_index_start += padded_width; + } + chan_freq_index_start = freq_index; + } + + // Allocate the two arrays to store the weights - weight_index_start contains + // the index of what would be the next set of weights that we would need to + // add, so that's how many weights we need to allocate. + state->weights = calloc(weight_index_start, sizeof(*state->weights)); + state->unweights = calloc(weight_index_start, sizeof(*state->unweights)); + + // If the alloc failed, we also need to nuke the arrays. + if (state->weights == NULL || state->unweights == NULL) { + free(center_mel_freqs); + free(actual_channel_starts); + free(actual_channel_widths); + fprintf(stderr, "Failed to allocate weights or unweights\n"); + return 0; + } + + // Next pass, compute all the weights. Since everything has been memset to + // zero, we only need to fill in the weights that correspond to some frequency + // for a channel. + const float mel_low = FreqToMel(config->lower_band_limit); + for (chan = 0; chan < num_channels_plus_1; ++chan) { + int frequency = actual_channel_starts[chan]; + const int num_frequencies = actual_channel_widths[chan]; + const int frequency_offset = + frequency - state->channel_frequency_starts[chan]; + const int weight_start = state->channel_weight_starts[chan]; + const float denom_val = (chan == 0) ? mel_low : center_mel_freqs[chan - 1]; + + int j; + for (j = 0; j < num_frequencies; ++j, ++frequency) { + const float weight = + (center_mel_freqs[chan] - FreqToMel(frequency * hz_per_sbin)) / + (center_mel_freqs[chan] - denom_val); + + // Make the float into an integer for the weights (and unweights). + const int weight_index = weight_start + frequency_offset + j; + QuantizeFilterbankWeights(weight, state->weights + weight_index, + state->unweights + weight_index); + } + if (frequency > state->end_index) { + state->end_index = frequency; + } + } + + free(center_mel_freqs); + free(actual_channel_starts); + free(actual_channel_widths); + if (state->end_index >= spectrum_size) { + fprintf(stderr, "Filterbank end_index is above spectrum size.\n"); + return 0; + } + return 1; +} + +void FilterbankFreeStateContents(struct FilterbankState *state) +{ + free(state->channel_frequency_starts); + free(state->channel_weight_starts); + free(state->channel_widths); + free(state->weights); + free(state->unweights); + free(state->work); +} diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/filterbank_util.h b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/filterbank_util.h new file mode 100644 index 00000000..cfc5ca98 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/filterbank_util.h @@ -0,0 +1,50 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FILTERBANK_UTIL_H_ +#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FILTERBANK_UTIL_H_ + +#include "tensorflow/lite/experimental/microfrontend/lib/filterbank.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct FilterbankConfig { + // number of frequency channel buckets for filterbank + int num_channels; + // maximum frequency to include + float upper_band_limit; + // minimum frequency to include + float lower_band_limit; + // unused + int output_scale_shift; +}; + +// Fills the frontendConfig with "sane" defaults. +void FilterbankFillConfigWithDefaults(struct FilterbankConfig *config); + +// Allocates any buffers. +int FilterbankPopulateState(const struct FilterbankConfig *config, + struct FilterbankState *state, int sample_rate, + int spectrum_size); + +// Frees any allocated buffers. +void FilterbankFreeStateContents(struct FilterbankState *state); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FILTERBANK_UTIL_H_ diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend.c b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend.c new file mode 100644 index 00000000..32ede40c --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend.c @@ -0,0 +1,74 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/frontend.h" + +#include "tensorflow/lite/experimental/microfrontend/lib/bits.h" + +struct FrontendOutput FrontendProcessSamples(struct FrontendState *state, + const int16_t *samples, + size_t num_samples, + size_t *num_samples_read) +{ + struct FrontendOutput output; + output.values = NULL; + output.size = 0; + + // Try to apply the window - if it fails, return and wait for more data. + if (!WindowProcessSamples(&state->window, samples, num_samples, + num_samples_read)) { + return output; + } + + // Apply the FFT to the window's output (and scale it so that the fixed point + // FFT can have as much resolution as possible). + int input_shift = + 15 - MostSignificantBit32(state->window.max_abs_output_value); + FftCompute(&state->fft, state->window.output, input_shift); + + // We can re-ruse the fft's output buffer to hold the energy. + int32_t *energy = (int32_t *)state->fft.output; + + FilterbankConvertFftComplexToEnergy(&state->filterbank, state->fft.output, + energy); + + FilterbankAccumulateChannels(&state->filterbank, energy); + uint32_t *scaled_filterbank = FilterbankSqrt(&state->filterbank, input_shift); + + // Apply noise reduction. + NoiseReductionApply(&state->noise_reduction, scaled_filterbank); + + if (state->pcan_gain_control.enable_pcan) { + PcanGainControlApply(&state->pcan_gain_control, scaled_filterbank); + } + + // Apply the log and scale. + int correction_bits = + MostSignificantBit32(state->fft.fft_size) - 1 - (kFilterbankBits / 2); + uint16_t *logged_filterbank = + LogScaleApply(&state->log_scale, scaled_filterbank, + state->filterbank.num_channels, correction_bits); + + output.size = state->filterbank.num_channels; + output.values = logged_filterbank; + return output; +} + +void FrontendReset(struct FrontendState *state) +{ + WindowReset(&state->window); + FftReset(&state->fft); + FilterbankReset(&state->filterbank); + NoiseReductionReset(&state->noise_reduction); +} diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend.h b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend.h new file mode 100644 index 00000000..e1e4ca35 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend.h @@ -0,0 +1,64 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FRONTEND_H_ +#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FRONTEND_H_ + +#include +#include + +#include "tensorflow/lite/experimental/microfrontend/lib/fft.h" +#include "tensorflow/lite/experimental/microfrontend/lib/filterbank.h" +#include "tensorflow/lite/experimental/microfrontend/lib/log_scale.h" +#include "tensorflow/lite/experimental/microfrontend/lib/noise_reduction.h" +#include "tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.h" +#include "tensorflow/lite/experimental/microfrontend/lib/window.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct FrontendState { + struct WindowState window; + struct FftState fft; + struct FilterbankState filterbank; + struct NoiseReductionState noise_reduction; + struct PcanGainControlState pcan_gain_control; + struct LogScaleState log_scale; +}; + +struct FrontendOutput { + const uint16_t *values; + size_t size; +}; + +// Main entry point to processing frontend samples. Updates num_samples_read to +// contain the number of samples that have been consumed from the input array. +// Returns a struct containing the generated output. If not enough samples were +// added to generate a feature vector, the returned size will be 0 and the +// values pointer will be NULL. Note that the output pointer will be invalidated +// as soon as FrontendProcessSamples is called again, so copy the contents +// elsewhere if you need to use them later. +struct FrontendOutput FrontendProcessSamples(struct FrontendState *state, + const int16_t *samples, + size_t num_samples, + size_t *num_samples_read); + +void FrontendReset(struct FrontendState *state); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FRONTEND_H_ diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_io.c b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_io.c new file mode 100644 index 00000000..da8cc0b5 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_io.c @@ -0,0 +1,70 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/frontend_io.h" + +#include + +#include "tensorflow/lite/experimental/microfrontend/lib/fft_io.h" +#include "tensorflow/lite/experimental/microfrontend/lib/filterbank_io.h" +#include "tensorflow/lite/experimental/microfrontend/lib/log_scale_io.h" +#include "tensorflow/lite/experimental/microfrontend/lib/noise_reduction_io.h" +#include "tensorflow/lite/experimental/microfrontend/lib/window_io.h" + +int WriteFrontendStateMemmap(const char *header, const char *source, + const struct FrontendState *state) +{ + // Write a header that just has our init function. + FILE *fp = fopen(header, "w"); + if (!fp) { + fprintf(stderr, "Failed to open header '%s' for write\n", header); + return 0; + } + fprintf(fp, "#ifndef FRONTEND_STATE_MEMMAP_H_\n"); + fprintf(fp, "#define FRONTEND_STATE_MEMMAP_H_\n"); + fprintf(fp, "\n"); + fprintf(fp, "#include \"frontend.h\"\n"); + fprintf(fp, "\n"); + fprintf(fp, "struct FrontendState* GetFrontendStateMemmap();\n"); + fprintf(fp, "\n"); + fprintf(fp, "#endif // FRONTEND_STATE_MEMMAP_H_\n"); + fclose(fp); + + // Write out the source file that actually has everything in it. + fp = fopen(source, "w"); + if (!fp) { + fprintf(stderr, "Failed to open source '%s' for write\n", source); + return 0; + } + fprintf(fp, "#include \"%s\"\n", header); + fprintf(fp, "\n"); + WindowWriteMemmapPreamble(fp, &state->window); + FftWriteMemmapPreamble(fp, &state->fft); + FilterbankWriteMemmapPreamble(fp, &state->filterbank); + NoiseReductionWriteMemmapPreamble(fp, &state->noise_reduction); + fprintf(fp, "static struct FrontendState state;\n"); + fprintf(fp, "struct FrontendState* GetFrontendStateMemmap() {\n"); + WindowWriteMemmap(fp, &state->window, " (&state.window)"); + FftWriteMemmap(fp, &state->fft, " (&state.fft)"); + FilterbankWriteMemmap(fp, &state->filterbank, " (&state.filterbank)"); + NoiseReductionWriteMemmap(fp, &state->noise_reduction, + " (&state.noise_reduction)"); + LogScaleWriteMemmap(fp, &state->log_scale, " (&state.log_scale)"); + fprintf(fp, " FftInit(&state.fft);\n"); + fprintf(fp, " FrontendReset(&state);\n"); + fprintf(fp, " return &state;\n"); + fprintf(fp, "}\n"); + fclose(fp); + return 1; +} diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_io.h b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_io.h new file mode 100644 index 00000000..b21b1df0 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_io.h @@ -0,0 +1,31 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FRONTEND_IO_H_ +#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FRONTEND_IO_H_ + +#include "tensorflow/lite/experimental/microfrontend/lib/frontend.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int WriteFrontendStateMemmap(const char *header, const char *source, + const struct FrontendState *state); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FRONTEND_IO_H_ diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_main.c b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_main.c new file mode 100644 index 00000000..2371fd34 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_main.c @@ -0,0 +1,72 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include + +#include "tensorflow/lite/experimental/microfrontend/lib/frontend.h" +#include "tensorflow/lite/experimental/microfrontend/lib/frontend_util.h" + +int main(int argc, char **argv) +{ + struct FrontendConfig frontend_config; + FrontendFillConfigWithDefaults(&frontend_config); + + char *filename = argv[1]; + int sample_rate = 16000; + + struct FrontendState frontend_state; + if (!FrontendPopulateState(&frontend_config, &frontend_state, sample_rate)) { + fprintf(stderr, "Failed to populate frontend state\n"); + FrontendFreeStateContents(&frontend_state); + return 1; + } + + FILE *fp = fopen(filename, "r"); + if (fp == NULL) { + fprintf(stderr, "Failed to open %s for read\n", filename); + return 1; + } + fseek(fp, 0L, SEEK_END); + size_t audio_file_size = ftell(fp) / sizeof(int16_t); + fseek(fp, 0L, SEEK_SET); + int16_t *audio_data = malloc(audio_file_size * sizeof(int16_t)); + int16_t *original_audio_data = audio_data; + if (audio_file_size != + fread(audio_data, sizeof(int16_t), audio_file_size, fp)) { + fprintf(stderr, "Failed to read in all audio data\n"); + fclose(fp); + return 1; + } + + while (audio_file_size > 0) { + size_t num_samples_read; + struct FrontendOutput output = FrontendProcessSamples( + &frontend_state, audio_data, audio_file_size, &num_samples_read); + audio_data += num_samples_read; + audio_file_size -= num_samples_read; + + if (output.values != NULL) { + int i; + for (i = 0; i < output.size; ++i) { + printf("%d ", output.values[i]); + } + printf("\n"); + } + } + + FrontendFreeStateContents(&frontend_state); + free(original_audio_data); + fclose(fp); + return 0; +} diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_memmap_generator.c b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_memmap_generator.c new file mode 100644 index 00000000..4dc83ed1 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_memmap_generator.c @@ -0,0 +1,49 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include + +#include "tensorflow/lite/experimental/microfrontend/lib/frontend.h" +#include "tensorflow/lite/experimental/microfrontend/lib/frontend_util.h" +#include "tensorflow/lite/experimental/microfrontend/lib/frontend_io.h" + +int main(int argc, char **argv) +{ + if (argc != 3) { + fprintf(stderr, + "%s requires exactly two parameters - the names of the header and " + "source files to save\n", + argv[0]); + return 1; + } + struct FrontendConfig frontend_config; + FrontendFillConfigWithDefaults(&frontend_config); + + int sample_rate = 16000; + struct FrontendState frontend_state; + if (!FrontendPopulateState(&frontend_config, &frontend_state, sample_rate)) { + fprintf(stderr, "Failed to populate frontend state\n"); + FrontendFreeStateContents(&frontend_state); + return 1; + } + + if (!WriteFrontendStateMemmap(argv[1], argv[2], &frontend_state)) { + fprintf(stderr, "Failed to write memmap\n"); + FrontendFreeStateContents(&frontend_state); + return 1; + } + + FrontendFreeStateContents(&frontend_state); + return 0; +} diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_memmap_main.c b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_memmap_main.c new file mode 100644 index 00000000..9c21f466 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_memmap_main.c @@ -0,0 +1,61 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include + +#include "memmap.h" +#include "tensorflow/lite/experimental/microfrontend/lib/frontend.h" + +int main(int argc, char **argv) +{ + struct FrontendState *frontend_state = GetFrontendStateMemmap(); + + char *filename = argv[1]; + FILE *fp = fopen(filename, "r"); + if (fp == NULL) { + fprintf(stderr, "Failed to open %s for read\n", filename); + return 1; + } + fseek(fp, 0L, SEEK_END); + size_t audio_file_size = ftell(fp) / sizeof(int16_t); + fseek(fp, 0L, SEEK_SET); + int16_t *audio_data = malloc(audio_file_size * sizeof(int16_t)); + int16_t *original_audio_data = audio_data; + if (audio_file_size != + fread(audio_data, sizeof(int16_t), audio_file_size, fp)) { + fprintf(stderr, "Failed to read in all audio data\n"); + fclose(fp); + return 1; + } + + while (audio_file_size > 0) { + size_t num_samples_read; + struct FrontendOutput output = FrontendProcessSamples( + frontend_state, audio_data, audio_file_size, &num_samples_read); + audio_data += num_samples_read; + audio_file_size -= num_samples_read; + + if (output.values != NULL) { + int i; + for (i = 0; i < output.size; ++i) { + printf("%d ", output.values[i]); + } + printf("\n"); + } + } + + free(original_audio_data); + fclose(fp); + return 0; +} diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_test.cc b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_test.cc new file mode 100644 index 00000000..258ad3d5 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_test.cc @@ -0,0 +1,136 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/frontend.h" + +#include "tensorflow/lite/experimental/microfrontend/lib/frontend_util.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace { + +const int kSampleRate = 1000; +const int kWindowSamples = 25; +const int kStepSamples = 10; +const int16_t kFakeAudioData[] = { + 0, 32767, 0, -32768, 0, 32767, 0, -32768, 0, 32767, 0, -32768, + 0, 32767, 0, -32768, 0, 32767, 0, -32768, 0, 32767, 0, -32768, + 0, 32767, 0, -32768, 0, 32767, 0, -32768, 0, 32767, 0, -32768 +}; + +// Test end-to-end frontend behaviors. +class FrontendTestConfig { +public: + FrontendTestConfig() + { + config_.window.size_ms = 25; + config_.window.step_size_ms = 10; + config_.noise_reduction.smoothing_bits = 10; + config_.filterbank.num_channels = 2; + config_.filterbank.lower_band_limit = 8.0; + config_.filterbank.upper_band_limit = 450.0; + config_.noise_reduction.smoothing_bits = 10; + config_.noise_reduction.even_smoothing = 0.025; + config_.noise_reduction.odd_smoothing = 0.06; + config_.noise_reduction.min_signal_remaining = 0.05; + config_.pcan_gain_control.enable_pcan = true; + config_.pcan_gain_control.strength = 0.95; + config_.pcan_gain_control.offset = 80.0; + config_.pcan_gain_control.gain_bits = 21; + config_.log_scale.enable_log = true; + config_.log_scale.scale_shift = 6; + } + + struct FrontendConfig config_; +}; + +} // namespace + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(FrontendTest_CheckOutputValues) +{ + FrontendTestConfig config; + struct FrontendState state; + TF_LITE_MICRO_EXPECT( + FrontendPopulateState(&config.config_, &state, kSampleRate)); + size_t num_samples_read; + + struct FrontendOutput output = FrontendProcessSamples( + &state, kFakeAudioData, + sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]), &num_samples_read); + + const uint16_t expected[] = { 479, 425 }; + TF_LITE_MICRO_EXPECT_EQ(output.size, sizeof(expected) / sizeof(expected[0])); + int i; + for (i = 0; i < output.size; ++i) { + TF_LITE_MICRO_EXPECT_EQ(output.values[i], expected[i]); + } + + FrontendFreeStateContents(&state); +} + +TF_LITE_MICRO_TEST(FrontendTest_CheckConsecutiveWindow) +{ + FrontendTestConfig config; + struct FrontendState state; + TF_LITE_MICRO_EXPECT( + FrontendPopulateState(&config.config_, &state, kSampleRate)); + size_t num_samples_read; + + FrontendProcessSamples(&state, kFakeAudioData, + sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]), + &num_samples_read); + struct FrontendOutput output = FrontendProcessSamples( + &state, kFakeAudioData + kWindowSamples, + sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]) - kWindowSamples, + &num_samples_read); + + const int16_t expected[] = { 436, 378 }; + TF_LITE_MICRO_EXPECT_EQ(output.size, sizeof(expected) / sizeof(expected[0])); + int i; + for (i = 0; i < output.size; ++i) { + TF_LITE_MICRO_EXPECT_EQ(output.values[i], expected[i]); + } + + FrontendFreeStateContents(&state); +} + +TF_LITE_MICRO_TEST(FrontendTest_CheckNotEnoughSamples) +{ + FrontendTestConfig config; + struct FrontendState state; + TF_LITE_MICRO_EXPECT( + FrontendPopulateState(&config.config_, &state, kSampleRate)); + size_t num_samples_read; + + FrontendProcessSamples(&state, kFakeAudioData, + sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]), + &num_samples_read); + FrontendProcessSamples( + &state, kFakeAudioData + kWindowSamples, + sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]) - kWindowSamples, + &num_samples_read); + struct FrontendOutput output = FrontendProcessSamples( + &state, kFakeAudioData + kWindowSamples + kStepSamples, + sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]) - kWindowSamples - + kStepSamples, + &num_samples_read); + + TF_LITE_MICRO_EXPECT_EQ(output.size, 0); + TF_LITE_MICRO_EXPECT(output.values == nullptr); + + FrontendFreeStateContents(&state); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_util.c b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_util.c new file mode 100644 index 00000000..7bdd7731 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_util.c @@ -0,0 +1,88 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/frontend_util.h" + +#include +#include + +#include "tensorflow/lite/experimental/microfrontend/lib/bits.h" + +void FrontendFillConfigWithDefaults(struct FrontendConfig *config) +{ + WindowFillConfigWithDefaults(&config->window); + FilterbankFillConfigWithDefaults(&config->filterbank); + NoiseReductionFillConfigWithDefaults(&config->noise_reduction); + PcanGainControlFillConfigWithDefaults(&config->pcan_gain_control); + LogScaleFillConfigWithDefaults(&config->log_scale); +} + +int FrontendPopulateState(const struct FrontendConfig *config, + struct FrontendState *state, int sample_rate) +{ + memset(state, 0, sizeof(*state)); + + if (!WindowPopulateState(&config->window, &state->window, sample_rate)) { + fprintf(stderr, "Failed to populate window state\n"); + return 0; + } + + if (!FftPopulateState(&state->fft, state->window.size)) { + fprintf(stderr, "Failed to populate fft state\n"); + return 0; + } + FftInit(&state->fft); + + if (!FilterbankPopulateState(&config->filterbank, &state->filterbank, + sample_rate, state->fft.fft_size / 2 + 1)) { + fprintf(stderr, "Failed to populate filterbank state\n"); + return 0; + } + + if (!NoiseReductionPopulateState(&config->noise_reduction, + &state->noise_reduction, + state->filterbank.num_channels)) { + fprintf(stderr, "Failed to populate noise reduction state\n"); + return 0; + } + + int input_correction_bits = + MostSignificantBit32(state->fft.fft_size) - 1 - (kFilterbankBits / 2); + if (!PcanGainControlPopulateState( + &config->pcan_gain_control, &state->pcan_gain_control, + state->noise_reduction.estimate, state->filterbank.num_channels, + state->noise_reduction.smoothing_bits, input_correction_bits)) { + fprintf(stderr, "Failed to populate pcan gain control state\n"); + return 0; + } + + if (!LogScalePopulateState(&config->log_scale, &state->log_scale)) { + fprintf(stderr, "Failed to populate log scale state\n"); + return 0; + } + + FrontendReset(state); + + // All good, return a true value. + return 1; +} + +void FrontendFreeStateContents(struct FrontendState *state) +{ + WindowFreeStateContents(&state->window); + FftFreeStateContents(&state->fft); + FilterbankFreeStateContents(&state->filterbank); + NoiseReductionFreeStateContents(&state->noise_reduction); + PcanGainControlFreeStateContents(&state->pcan_gain_control); +} diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_util.h b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_util.h new file mode 100644 index 00000000..6cfc1d33 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/frontend_util.h @@ -0,0 +1,52 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FRONTEND_UTIL_H_ +#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FRONTEND_UTIL_H_ + +#include "tensorflow/lite/experimental/microfrontend/lib/fft_util.h" +#include "tensorflow/lite/experimental/microfrontend/lib/filterbank_util.h" +#include "tensorflow/lite/experimental/microfrontend/lib/frontend.h" +#include "tensorflow/lite/experimental/microfrontend/lib/log_scale_util.h" +#include "tensorflow/lite/experimental/microfrontend/lib/noise_reduction_util.h" +#include "tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control_util.h" +#include "tensorflow/lite/experimental/microfrontend/lib/window_util.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct FrontendConfig { + struct WindowConfig window; + struct FilterbankConfig filterbank; + struct NoiseReductionConfig noise_reduction; + struct PcanGainControlConfig pcan_gain_control; + struct LogScaleConfig log_scale; +}; + +// Fills the frontendConfig with "sane" defaults. +void FrontendFillConfigWithDefaults(struct FrontendConfig *config); + +// Allocates any buffers. +int FrontendPopulateState(const struct FrontendConfig *config, + struct FrontendState *state, int sample_rate); + +// Frees any allocated buffers. +void FrontendFreeStateContents(struct FrontendState *state); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FRONTEND_UTIL_H_ diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_lut.c b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_lut.c new file mode 100644 index 00000000..e8d6ceda --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_lut.c @@ -0,0 +1,30 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/log_lut.h" +const uint16_t kLogLut[] +#ifndef _MSC_VER + __attribute__((aligned(4))) +#endif // _MSV_VER + = { 0, 224, 442, 654, 861, 1063, 1259, 1450, 1636, 1817, 1992, 2163, + 2329, 2490, 2646, 2797, 2944, 3087, 3224, 3358, 3487, 3611, 3732, 3848, + 3960, 4068, 4172, 4272, 4368, 4460, 4549, 4633, 4714, 4791, 4864, 4934, + 5001, 5063, 5123, 5178, 5231, 5280, 5326, 5368, 5408, 5444, 5477, 5507, + 5533, 5557, 5578, 5595, 5610, 5622, 5631, 5637, 5640, 5641, 5638, 5633, + 5626, 5615, 5602, 5586, 5568, 5547, 5524, 5498, 5470, 5439, 5406, 5370, + 5332, 5291, 5249, 5203, 5156, 5106, 5054, 5000, 4944, 4885, 4825, 4762, + 4697, 4630, 4561, 4490, 4416, 4341, 4264, 4184, 4103, 4020, 3935, 3848, + 3759, 3668, 3575, 3481, 3384, 3286, 3186, 3084, 2981, 2875, 2768, 2659, + 2549, 2437, 2323, 2207, 2090, 1971, 1851, 1729, 1605, 1480, 1353, 1224, + 1094, 963, 830, 695, 559, 421, 282, 142, 0, 0 }; diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_lut.h b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_lut.h new file mode 100644 index 00000000..6fd04f1c --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_lut.h @@ -0,0 +1,40 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_LOG_LUT_H_ +#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_LOG_LUT_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// Number of segments in the log lookup table. The table will be kLogSegments+1 +// in length (with some padding). +#define kLogSegments 128 +#define kLogSegmentsLog2 7 + +// Scale used by lookup table. +#define kLogScale 65536 +#define kLogScaleLog2 16 +#define kLogCoeff 45426 + +extern const uint16_t kLogLut[]; + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_LOG_LUT_H_ diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_scale.c b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_scale.c new file mode 100644 index 00000000..0cf70dd3 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_scale.c @@ -0,0 +1,86 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/log_scale.h" + +#include "tensorflow/lite/experimental/microfrontend/lib/bits.h" +#include "tensorflow/lite/experimental/microfrontend/lib/log_lut.h" + +#define kuint16max 0x0000FFFF + +// The following functions implement integer logarithms of various sizes. The +// approximation is calculated according to method described in +// www.inti.gob.ar/electronicaeinformatica/instrumentacion/utic/ +// publicaciones/SPL2007/Log10-spl07.pdf +// It first calculates log2 of the input and then converts it to natural +// logarithm. + +static uint32_t Log2FractionPart(const uint32_t x, const uint32_t log2x) +{ + // Part 1 + int32_t frac = x - (1LL << log2x); + if (log2x < kLogScaleLog2) { + frac <<= kLogScaleLog2 - log2x; + } else { + frac >>= log2x - kLogScaleLog2; + } + // Part 2 + const uint32_t base_seg = frac >> (kLogScaleLog2 - kLogSegmentsLog2); + const uint32_t seg_unit = + (((uint32_t)1) << kLogScaleLog2) >> kLogSegmentsLog2; + + const int32_t c0 = kLogLut[base_seg]; + const int32_t c1 = kLogLut[base_seg + 1]; + const int32_t seg_base = seg_unit * base_seg; + const int32_t rel_pos = ((c1 - c0) * (frac - seg_base)) >> kLogScaleLog2; + return frac + c0 + rel_pos; +} + +static uint32_t Log(const uint32_t x, const uint32_t scale_shift) +{ + const uint32_t integer = MostSignificantBit32(x) - 1; + const uint32_t fraction = Log2FractionPart(x, integer); + const uint32_t log2 = (integer << kLogScaleLog2) + fraction; + const uint32_t round = kLogScale / 2; + const uint32_t loge = (((uint64_t)kLogCoeff) * log2 + round) >> kLogScaleLog2; + // Finally scale to our output scale + const uint32_t loge_scaled = ((loge << scale_shift) + round) >> kLogScaleLog2; + return loge_scaled; +} + +uint16_t *LogScaleApply(struct LogScaleState *state, uint32_t *signal, + int signal_size, int correction_bits) +{ + const int scale_shift = state->scale_shift; + uint16_t *output = (uint16_t *)signal; + uint16_t *ret = output; + int i; + for (i = 0; i < signal_size; ++i) { + uint32_t value = *signal++; + if (state->enable_log) { + if (correction_bits < 0) { + value >>= -correction_bits; + } else { + value <<= correction_bits; + } + if (value > 1) { + value = Log(value, scale_shift); + } else { + value = 0; + } + } + *output++ = (value < kuint16max) ? value : kuint16max; + } + return ret; +} diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_scale.h b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_scale.h new file mode 100644 index 00000000..26630be8 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_scale.h @@ -0,0 +1,39 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_LOG_SCALE_H_ +#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_LOG_SCALE_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct LogScaleState { + int enable_log; + int scale_shift; +}; + +// Applies a fixed point logarithm to the signal and converts it to 16 bit. Note +// that the signal array will be modified. +uint16_t *LogScaleApply(struct LogScaleState *state, uint32_t *signal, + int signal_size, int correction_bits); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_LOG_SCALE_H_ diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_scale_io.c b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_scale_io.c new file mode 100644 index 00000000..7968d45f --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_scale_io.c @@ -0,0 +1,22 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/log_scale_io.h" + +void LogScaleWriteMemmap(FILE *fp, const struct LogScaleState *state, + const char *variable) +{ + fprintf(fp, "%s->enable_log = %d;\n", variable, state->enable_log); + fprintf(fp, "%s->scale_shift = %d;\n", variable, state->scale_shift); +} diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_scale_io.h b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_scale_io.h new file mode 100644 index 00000000..de6d5830 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_scale_io.h @@ -0,0 +1,33 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_LOG_SCALE_IO_H_ +#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_LOG_SCALE_IO_H_ + +#include + +#include "tensorflow/lite/experimental/microfrontend/lib/log_scale.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void LogScaleWriteMemmap(FILE *fp, const struct LogScaleState *state, + const char *variable); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_LOG_SCALE_IO_H_ diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_scale_test.cc b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_scale_test.cc new file mode 100644 index 00000000..71f1a20c --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_scale_test.cc @@ -0,0 +1,65 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/log_scale.h" + +#include "tensorflow/lite/experimental/microfrontend/lib/log_scale_util.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace { + +const int kScaleShift = 6; +const int kCorrectionBits = -1; + +} // namespace + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(LogScaleTest_CheckOutputValues) +{ + struct LogScaleState state; + state.enable_log = true; + state.scale_shift = kScaleShift; + + uint32_t fake_signal[] = { 3578, 1533 }; + uint16_t *output = LogScaleApply(&state, fake_signal, + sizeof(fake_signal) / sizeof(fake_signal[0]), + kCorrectionBits); + + const uint16_t expected[] = { 479, 425 }; + int i; + for (i = 0; i < sizeof(expected) / sizeof(expected[0]); ++i) { + TF_LITE_MICRO_EXPECT_EQ(output[i], expected[i]); + } +} + +TF_LITE_MICRO_TEST(LogScaleTest_CheckOutputValuesNoLog) +{ + struct LogScaleState state; + state.enable_log = false; + state.scale_shift = kScaleShift; + + uint32_t fake_signal[] = { 85964, 45998 }; + uint16_t *output = LogScaleApply(&state, fake_signal, + sizeof(fake_signal) / sizeof(fake_signal[0]), + kCorrectionBits); + + const uint16_t expected[] = { 65535, 45998 }; + int i; + for (i = 0; i < sizeof(expected) / sizeof(expected[0]); ++i) { + TF_LITE_MICRO_EXPECT_EQ(output[i], expected[i]); + } +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_scale_util.c b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_scale_util.c new file mode 100644 index 00000000..42ff89c8 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_scale_util.c @@ -0,0 +1,29 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/log_scale_util.h" + +void LogScaleFillConfigWithDefaults(struct LogScaleConfig *config) +{ + config->enable_log = 1; + config->scale_shift = 6; +} + +int LogScalePopulateState(const struct LogScaleConfig *config, + struct LogScaleState *state) +{ + state->enable_log = config->enable_log; + state->scale_shift = config->scale_shift; + return 1; +} diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_scale_util.h b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_scale_util.h new file mode 100644 index 00000000..3decebbb --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/log_scale_util.h @@ -0,0 +1,45 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_LOG_SCALE_UTIL_H_ +#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_LOG_SCALE_UTIL_H_ + +#include +#include + +#include "tensorflow/lite/experimental/microfrontend/lib/log_scale.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct LogScaleConfig { + // set to false (0) to disable this module + int enable_log; + // scale results by 2^(scale_shift) + int scale_shift; +}; + +// Populates the LogScaleConfig with "sane" default values. +void LogScaleFillConfigWithDefaults(struct LogScaleConfig *config); + +// Allocates any buffers. +int LogScalePopulateState(const struct LogScaleConfig *config, + struct LogScaleState *state); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_LOG_SCALE_UTIL_H_ diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/noise_reduction.c b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/noise_reduction.c new file mode 100644 index 00000000..bcb02e16 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/noise_reduction.c @@ -0,0 +1,53 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/noise_reduction.h" + +#include + +void NoiseReductionApply(struct NoiseReductionState *state, uint32_t *signal) +{ + int i; + for (i = 0; i < state->num_channels; ++i) { + const uint32_t smoothing = + ((i & 1) == 0) ? state->even_smoothing : state->odd_smoothing; + const uint32_t one_minus_smoothing = (1 << kNoiseReductionBits) - smoothing; + + // Update the estimate of the noise. + const uint32_t signal_scaled_up = signal[i] << state->smoothing_bits; + uint32_t estimate = + (((uint64_t)signal_scaled_up * smoothing) + + ((uint64_t)state->estimate[i] * one_minus_smoothing)) >> + kNoiseReductionBits; + state->estimate[i] = estimate; + + // Make sure that we can't get a negative value for the signal - estimate. + if (estimate > signal_scaled_up) { + estimate = signal_scaled_up; + } + + const uint32_t floor = + ((uint64_t)signal[i] * state->min_signal_remaining) >> + kNoiseReductionBits; + const uint32_t subtracted = + (signal_scaled_up - estimate) >> state->smoothing_bits; + const uint32_t output = subtracted > floor ? subtracted : floor; + signal[i] = output; + } +} + +void NoiseReductionReset(struct NoiseReductionState *state) +{ + memset(state->estimate, 0, sizeof(*state->estimate) * state->num_channels); +} diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/noise_reduction.h b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/noise_reduction.h new file mode 100644 index 00000000..462e7edb --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/noise_reduction.h @@ -0,0 +1,46 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_NOISE_REDUCTION_H_ +#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_NOISE_REDUCTION_H_ + +#define kNoiseReductionBits 14 + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct NoiseReductionState { + int smoothing_bits; + uint16_t even_smoothing; + uint16_t odd_smoothing; + uint16_t min_signal_remaining; + int num_channels; + uint32_t *estimate; +}; + +// Removes stationary noise from each channel of the signal using a low pass +// filter. +void NoiseReductionApply(struct NoiseReductionState *state, uint32_t *signal); + +void NoiseReductionReset(struct NoiseReductionState *state); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_NOISE_REDUCTION_H_ diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_io.c b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_io.c new file mode 100644 index 00000000..f963767e --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_io.c @@ -0,0 +1,36 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/noise_reduction_io.h" + +void NoiseReductionWriteMemmapPreamble( + FILE *fp, const struct NoiseReductionState *state) +{ + fprintf(fp, "static uint32_t noise_reduction_estimate[%zu];\n", + state->num_channels); + fprintf(fp, "\n"); +} + +void NoiseReductionWriteMemmap(FILE *fp, + const struct NoiseReductionState *state, + const char *variable) +{ + fprintf(fp, "%s->even_smoothing = %d;\n", variable, state->even_smoothing); + fprintf(fp, "%s->odd_smoothing = %d;\n", variable, state->odd_smoothing); + fprintf(fp, "%s->min_signal_remaining = %d;\n", variable, + state->min_signal_remaining); + fprintf(fp, "%s->num_channels = %d;\n", variable, state->num_channels); + + fprintf(fp, "%s->estimate = noise_reduction_estimate;\n", variable); +} diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_io.h b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_io.h new file mode 100644 index 00000000..1a065a90 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_io.h @@ -0,0 +1,36 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_NOISE_REDUCTION_IO_H_ +#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_NOISE_REDUCTION_IO_H_ + +#include + +#include "tensorflow/lite/experimental/microfrontend/lib/noise_reduction.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void NoiseReductionWriteMemmapPreamble(FILE *fp, + const struct NoiseReductionState *state); +void NoiseReductionWriteMemmap(FILE *fp, + const struct NoiseReductionState *state, + const char *variable); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_NOISE_REDUCTION_IO_H_ diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_test.cc b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_test.cc new file mode 100644 index 00000000..2840b091 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_test.cc @@ -0,0 +1,84 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/noise_reduction.h" + +#include "tensorflow/lite/experimental/microfrontend/lib/noise_reduction_util.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace { + +const int kNumChannels = 2; + +// Test noise reduction using default config values. +class NoiseReductionTestConfig { +public: + NoiseReductionTestConfig() + { + config_.smoothing_bits = 10; + config_.even_smoothing = 0.025; + config_.odd_smoothing = 0.06; + config_.min_signal_remaining = 0.05; + } + + struct NoiseReductionConfig config_; +}; + +} // namespace + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(NoiseReductionTest_TestNoiseReductionEstimate) +{ + NoiseReductionTestConfig config; + struct NoiseReductionState state; + TF_LITE_MICRO_EXPECT( + NoiseReductionPopulateState(&config.config_, &state, kNumChannels)); + + uint32_t signal[] = { 247311, 508620 }; + NoiseReductionApply(&state, signal); + + const uint32_t expected[] = { 6321887, 31248341 }; + TF_LITE_MICRO_EXPECT_EQ(state.num_channels, + sizeof(expected) / sizeof(expected[0])); + int i; + for (i = 0; i < state.num_channels; ++i) { + TF_LITE_MICRO_EXPECT_EQ(state.estimate[i], expected[i]); + } + + NoiseReductionFreeStateContents(&state); +} + +TF_LITE_MICRO_TEST(NoiseReductionTest_TestNoiseReduction) +{ + NoiseReductionTestConfig config; + struct NoiseReductionState state; + TF_LITE_MICRO_EXPECT( + NoiseReductionPopulateState(&config.config_, &state, kNumChannels)); + + uint32_t signal[] = { 247311, 508620 }; + NoiseReductionApply(&state, signal); + + const uint32_t expected[] = { 241137, 478104 }; + TF_LITE_MICRO_EXPECT_EQ(state.num_channels, + sizeof(expected) / sizeof(expected[0])); + int i; + for (i = 0; i < state.num_channels; ++i) { + TF_LITE_MICRO_EXPECT_EQ(signal[i], expected[i]); + } + + NoiseReductionFreeStateContents(&state); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_util.c b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_util.c new file mode 100644 index 00000000..d79c7856 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_util.c @@ -0,0 +1,48 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/noise_reduction_util.h" + +#include + +void NoiseReductionFillConfigWithDefaults(struct NoiseReductionConfig *config) +{ + config->smoothing_bits = 10; + config->even_smoothing = 0.025; + config->odd_smoothing = 0.06; + config->min_signal_remaining = 0.05; +} + +int NoiseReductionPopulateState(const struct NoiseReductionConfig *config, + struct NoiseReductionState *state, + int num_channels) +{ + state->smoothing_bits = config->smoothing_bits; + state->odd_smoothing = config->odd_smoothing * (1 << kNoiseReductionBits); + state->even_smoothing = config->even_smoothing * (1 << kNoiseReductionBits); + state->min_signal_remaining = + config->min_signal_remaining * (1 << kNoiseReductionBits); + state->num_channels = num_channels; + state->estimate = calloc(state->num_channels, sizeof(*state->estimate)); + if (state->estimate == NULL) { + fprintf(stderr, "Failed to alloc estimate buffer\n"); + return 0; + } + return 1; +} + +void NoiseReductionFreeStateContents(struct NoiseReductionState *state) +{ + free(state->estimate); +} diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_util.h b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_util.h new file mode 100644 index 00000000..f2e89944 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_util.h @@ -0,0 +1,50 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_NOISE_REDUCTION_UTIL_H_ +#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_NOISE_REDUCTION_UTIL_H_ + +#include "tensorflow/lite/experimental/microfrontend/lib/noise_reduction.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct NoiseReductionConfig { + // scale the signal up by 2^(smoothing_bits) before reduction + int smoothing_bits; + // smoothing coefficient for even-numbered channels + float even_smoothing; + // smoothing coefficient for odd-numbered channels + float odd_smoothing; + // fraction of signal to preserve (1.0 disables this module) + float min_signal_remaining; +}; + +// Populates the NoiseReductionConfig with "sane" default values. +void NoiseReductionFillConfigWithDefaults(struct NoiseReductionConfig *config); + +// Allocates any buffers. +int NoiseReductionPopulateState(const struct NoiseReductionConfig *config, + struct NoiseReductionState *state, + int num_channels); + +// Frees any allocated buffers. +void NoiseReductionFreeStateContents(struct NoiseReductionState *state); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_NOISE_REDUCTION_UTIL_H_ diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.c b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.c new file mode 100644 index 00000000..7c92fd31 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.c @@ -0,0 +1,59 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.h" + +#include "tensorflow/lite/experimental/microfrontend/lib/bits.h" + +int16_t WideDynamicFunction(const uint32_t x, const int16_t *lut) +{ + if (x <= 2) { + return lut[x]; + } + + const int16_t interval = MostSignificantBit32(x); + lut += 4 * interval - 6; + + const int16_t frac = + ((interval < 11) ? (x << (11 - interval)) : (x >> (interval - 11))) & + 0x3FF; + + int32_t result = ((int32_t)lut[2] * frac) >> 5; + result += (int32_t)((uint32_t)lut[1] << 5); + result *= frac; + result = (result + (1 << 14)) >> 15; + result += lut[0]; + return (int16_t)result; +} + +uint32_t PcanShrink(const uint32_t x) +{ + if (x < (2 << kPcanSnrBits)) { + return (x * x) >> (2 + 2 * kPcanSnrBits - kPcanOutputBits); + } else { + return (x >> (kPcanSnrBits - kPcanOutputBits)) - (1 << kPcanOutputBits); + } +} + +void PcanGainControlApply(struct PcanGainControlState *state, + uint32_t *signal) +{ + int i; + for (i = 0; i < state->num_channels; ++i) { + const uint32_t gain = + WideDynamicFunction(state->noise_estimate[i], state->gain_lut); + const uint32_t snr = ((uint64_t)signal[i] * gain) >> state->snr_shift; + signal[i] = PcanShrink(snr); + } +} diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.h b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.h new file mode 100644 index 00000000..47b61d91 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.h @@ -0,0 +1,47 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_PCAN_GAIN_CONTROL_H_ +#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_PCAN_GAIN_CONTROL_H_ + +#include +#include + +#define kPcanSnrBits 12 +#define kPcanOutputBits 6 + +#ifdef __cplusplus +extern "C" { +#endif + +// Details at https://research.google/pubs/pub45911.pdf +struct PcanGainControlState { + int enable_pcan; + uint32_t *noise_estimate; + int num_channels; + int16_t *gain_lut; + int32_t snr_shift; +}; + +int16_t WideDynamicFunction(const uint32_t x, const int16_t *lut); + +uint32_t PcanShrink(const uint32_t x); + +void PcanGainControlApply(struct PcanGainControlState *state, uint32_t *signal); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_PCAN_GAIN_CONTROL_H_ diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control_test.cc b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control_test.cc new file mode 100644 index 00000000..05a8dd40 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control_test.cc @@ -0,0 +1,67 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.h" + +#include "tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control_util.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace { + +const int kNumChannels = 2; +const int kSmoothingBits = 10; +const int kCorrectionBits = -1; + +// Test pcan auto gain control using default config values. +class PcanGainControlTestConfig { +public: + PcanGainControlTestConfig() + { + config_.enable_pcan = 1; + config_.strength = 0.95; + config_.offset = 80.0; + config_.gain_bits = 21; + } + + struct PcanGainControlConfig config_; +}; + +} // namespace + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(PcanGainControlTest_TestPcanGainControl) +{ + uint32_t estimate[] = { 6321887, 31248341 }; + PcanGainControlTestConfig config; + struct PcanGainControlState state; + TF_LITE_MICRO_EXPECT(PcanGainControlPopulateState( + &config.config_, &state, estimate, kNumChannels, kSmoothingBits, + kCorrectionBits)); + + uint32_t signal[] = { 241137, 478104 }; + PcanGainControlApply(&state, signal); + + const uint32_t expected[] = { 3578, 1533 }; + TF_LITE_MICRO_EXPECT_EQ(state.num_channels, + sizeof(expected) / sizeof(expected[0])); + int i; + for (i = 0; i < state.num_channels; ++i) { + TF_LITE_MICRO_EXPECT_EQ(signal[i], expected[i]); + } + + PcanGainControlFreeStateContents(&state); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control_util.c b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control_util.c new file mode 100644 index 00000000..1d9d0957 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control_util.c @@ -0,0 +1,96 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control_util.h" + +#include +#include + +#define kint16max 0x00007FFF + +void PcanGainControlFillConfigWithDefaults( + struct PcanGainControlConfig *config) +{ + config->enable_pcan = 0; + config->strength = 0.95; + config->offset = 80.0; + config->gain_bits = 21; +} + +int16_t PcanGainLookupFunction(const struct PcanGainControlConfig *config, + int32_t input_bits, uint32_t x) +{ + const float x_as_float = ((float)x) / ((uint32_t)1 << input_bits); + const float gain_as_float = + ((uint32_t)1 << config->gain_bits) * + powf(x_as_float + config->offset, -config->strength); + + if (gain_as_float > kint16max) { + return kint16max; + } + return (int16_t)(gain_as_float + 0.5f); +} + +int PcanGainControlPopulateState(const struct PcanGainControlConfig *config, + struct PcanGainControlState *state, + uint32_t *noise_estimate, + const int num_channels, + const uint16_t smoothing_bits, + const int32_t input_correction_bits) +{ + state->enable_pcan = config->enable_pcan; + if (!state->enable_pcan) { + return 1; + } + state->noise_estimate = noise_estimate; + state->num_channels = num_channels; + state->gain_lut = malloc(kWideDynamicFunctionLUTSize * sizeof(int16_t)); + if (state->gain_lut == NULL) { + fprintf(stderr, "Failed to allocate gain LUT\n"); + return 0; + } + state->snr_shift = config->gain_bits - input_correction_bits - kPcanSnrBits; + + const int32_t input_bits = smoothing_bits - input_correction_bits; + state->gain_lut[0] = PcanGainLookupFunction(config, input_bits, 0); + state->gain_lut[1] = PcanGainLookupFunction(config, input_bits, 1); + state->gain_lut -= 6; + int interval; + for (interval = 2; interval <= kWideDynamicFunctionBits; ++interval) { + const uint32_t x0 = (uint32_t)1 << (interval - 1); + const uint32_t x1 = x0 + (x0 >> 1); + const uint32_t x2 = + (interval == kWideDynamicFunctionBits) ? x0 + (x0 - 1) : 2 * x0; + + const int16_t y0 = PcanGainLookupFunction(config, input_bits, x0); + const int16_t y1 = PcanGainLookupFunction(config, input_bits, x1); + const int16_t y2 = PcanGainLookupFunction(config, input_bits, x2); + + const int32_t diff1 = (int32_t)y1 - y0; + const int32_t diff2 = (int32_t)y2 - y0; + const int32_t a1 = 4 * diff1 - diff2; + const int32_t a2 = diff2 - a1; + + state->gain_lut[4 * interval] = y0; + state->gain_lut[4 * interval + 1] = (int16_t)a1; + state->gain_lut[4 * interval + 2] = (int16_t)a2; + } + state->gain_lut += 6; + return 1; +} + +void PcanGainControlFreeStateContents(struct PcanGainControlState *state) +{ + free(state->gain_lut); +} diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control_util.h b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control_util.h new file mode 100644 index 00000000..364f232e --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control_util.h @@ -0,0 +1,57 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_PCAN_GAIN_CONTROL_UTIL_H_ +#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_PCAN_GAIN_CONTROL_UTIL_H_ + +#include "tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.h" + +#define kWideDynamicFunctionBits 32 +#define kWideDynamicFunctionLUTSize (4 * kWideDynamicFunctionBits - 3) + +#ifdef __cplusplus +extern "C" { +#endif + +struct PcanGainControlConfig { + // set to false (0) to disable this module + int enable_pcan; + // gain normalization exponent (0.0 disables, 1.0 full strength) + float strength; + // positive value added in the normalization denominator + float offset; + // number of fractional bits in the gain + int gain_bits; +}; + +void PcanGainControlFillConfigWithDefaults( + struct PcanGainControlConfig *config); + +int16_t PcanGainLookupFunction(const struct PcanGainControlConfig *config, + int32_t input_bits, uint32_t x); + +int PcanGainControlPopulateState(const struct PcanGainControlConfig *config, + struct PcanGainControlState *state, + uint32_t *noise_estimate, + const int num_channels, + const uint16_t smoothing_bits, + const int32_t input_correction_bits); + +void PcanGainControlFreeStateContents(struct PcanGainControlState *state); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_PCAN_GAIN_CONTROL_UTIL_H_ diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/window.c b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/window.c new file mode 100644 index 00000000..ec3a7526 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/window.c @@ -0,0 +1,72 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/window.h" + +#include + +int WindowProcessSamples(struct WindowState *state, const int16_t *samples, + size_t num_samples, size_t *num_samples_read) +{ + const int size = state->size; + + // Copy samples from the samples buffer over to our local input. + size_t max_samples_to_copy = state->size - state->input_used; + if (max_samples_to_copy > num_samples) { + max_samples_to_copy = num_samples; + } + memcpy(state->input + state->input_used, samples, + max_samples_to_copy * sizeof(*samples)); + *num_samples_read = max_samples_to_copy; + state->input_used += max_samples_to_copy; + + if (state->input_used < state->size) { + // We don't have enough samples to compute a window. + return 0; + } + + // Apply the window to the input. + const int16_t *coefficients = state->coefficients; + const int16_t *input = state->input; + int16_t *output = state->output; + int i; + int16_t max_abs_output_value = 0; + for (i = 0; i < size; ++i) { + int16_t new_value = + (((int32_t)*input++) * *coefficients++) >> kFrontendWindowBits; + *output++ = new_value; + if (new_value < 0) { + new_value = -new_value; + } + if (new_value > max_abs_output_value) { + max_abs_output_value = new_value; + } + } + // Shuffle the input down by the step size, and update how much we have used. + memmove(state->input, state->input + state->step, + sizeof(*state->input) * (state->size - state->step)); + state->input_used -= state->step; + state->max_abs_output_value = max_abs_output_value; + + // Indicate that the output buffer is valid for the next stage. + return 1; +} + +void WindowReset(struct WindowState *state) +{ + memset(state->input, 0, state->size * sizeof(*state->input)); + memset(state->output, 0, state->size * sizeof(*state->output)); + state->input_used = 0; + state->max_abs_output_value = 0; +} diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/window.h b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/window.h new file mode 100644 index 00000000..5f6d1bae --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/window.h @@ -0,0 +1,49 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_WINDOW_H_ +#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_WINDOW_H_ + +#include +#include + +#define kFrontendWindowBits 12 + +#ifdef __cplusplus +extern "C" { +#endif + +struct WindowState { + size_t size; + int16_t *coefficients; + size_t step; + + int16_t *input; + size_t input_used; + int16_t *output; + int16_t max_abs_output_value; +}; + +// Applies a window to the samples coming in, stepping forward at the given +// rate. +int WindowProcessSamples(struct WindowState *state, const int16_t *samples, + size_t num_samples, size_t *num_samples_read); + +void WindowReset(struct WindowState *state); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_WINDOW_H_ diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/window_io.c b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/window_io.c new file mode 100644 index 00000000..e9a51b08 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/window_io.c @@ -0,0 +1,45 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/window_io.h" + +void WindowWriteMemmapPreamble(FILE *fp, const struct WindowState *state) +{ + fprintf(fp, "static int16_t window_coefficients[] = {\n"); + int i; + for (i = 0; i < state->size; ++i) { + fprintf(fp, "%d", state->coefficients[i]); + if (i < state->size - 1) { + fprintf(fp, ", "); + } + } + fprintf(fp, "};\n"); + fprintf(fp, "static int16_t window_input[%zu];\n", state->size); + fprintf(fp, "static int16_t window_output[%zu];\n", state->size); + fprintf(fp, "\n"); +} + +void WindowWriteMemmap(FILE *fp, const struct WindowState *state, + const char *variable) +{ + fprintf(fp, "%s->size = %zu;\n", variable, state->size); + fprintf(fp, "%s->coefficients = window_coefficients;\n", variable); + fprintf(fp, "%s->step = %zu;\n", variable, state->step); + + fprintf(fp, "%s->input = window_input;\n", variable); + fprintf(fp, "%s->input_used = %zu;\n", variable, state->input_used); + fprintf(fp, "%s->output = window_output;\n", variable); + fprintf(fp, "%s->max_abs_output_value = %d;\n", variable, + state->max_abs_output_value); +} diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/window_io.h b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/window_io.h new file mode 100644 index 00000000..d8c44731 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/window_io.h @@ -0,0 +1,34 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_WINDOW_IO_H_ +#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_WINDOW_IO_H_ + +#include + +#include "tensorflow/lite/experimental/microfrontend/lib/window.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void WindowWriteMemmapPreamble(FILE *fp, const struct WindowState *state); +void WindowWriteMemmap(FILE *fp, const struct WindowState *state, + const char *variable); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_WINDOW_IO_H_ diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/window_test.cc b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/window_test.cc new file mode 100644 index 00000000..166fd21b --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/window_test.cc @@ -0,0 +1,187 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/window.h" + +#include "tensorflow/lite/experimental/microfrontend/lib/window_util.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace { + +const int kSampleRate = 1000; +const int kWindowSamples = 25; +const int kStepSamples = 10; +const int16_t kFakeAudioData[] = { + 0, 32767, 0, -32768, 0, 32767, 0, -32768, 0, 32767, 0, -32768, + 0, 32767, 0, -32768, 0, 32767, 0, -32768, 0, 32767, 0, -32768, + 0, 32767, 0, -32768, 0, 32767, 0, -32768, 0, 32767, 0, -32768 +}; + +// Test window function behaviors using default config values. +class WindowTestConfig { +public: + WindowTestConfig() + { + config_.size_ms = 25; + config_.step_size_ms = 10; + } + + struct WindowConfig config_; +}; + +} // namespace + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(WindowState_CheckCoefficients) +{ + WindowTestConfig config; + struct WindowState state; + TF_LITE_MICRO_EXPECT( + WindowPopulateState(&config.config_, &state, kSampleRate)); + + const int16_t expected[] = { 16, 144, 391, 743, 1176, 1664, 2177, + 2681, 3145, 3541, 3843, 4032, 4096, 4032, + 3843, 3541, 3145, 2681, 2177, 1664, 1176, + 743, 391, 144, 16 }; + TF_LITE_MICRO_EXPECT_EQ(state.size, sizeof(expected) / sizeof(expected[0])); + int i; + for (i = 0; i < state.size; ++i) { + TF_LITE_MICRO_EXPECT_EQ(state.coefficients[i], expected[i]); + } + + WindowFreeStateContents(&state); +} + +TF_LITE_MICRO_TEST(WindowState_CheckResidualInput) +{ + WindowTestConfig config; + struct WindowState state; + TF_LITE_MICRO_EXPECT( + WindowPopulateState(&config.config_, &state, kSampleRate)); + size_t num_samples_read; + + TF_LITE_MICRO_EXPECT(WindowProcessSamples( + &state, kFakeAudioData, + sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]), &num_samples_read)); + + int i; + for (i = kStepSamples; i < kWindowSamples; ++i) { + TF_LITE_MICRO_EXPECT_EQ(state.input[i - kStepSamples], kFakeAudioData[i]); + } + + WindowFreeStateContents(&state); +} + +TF_LITE_MICRO_TEST(WindowState_CheckOutputValues) +{ + WindowTestConfig config; + struct WindowState state; + TF_LITE_MICRO_EXPECT( + WindowPopulateState(&config.config_, &state, kSampleRate)); + size_t num_samples_read; + + TF_LITE_MICRO_EXPECT(WindowProcessSamples( + &state, kFakeAudioData, + sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]), &num_samples_read)); + + const int16_t expected[] = { + 0, 1151, 0, -5944, 0, 13311, 0, -21448, 0, 28327, 0, -32256, 0, 32255, + 0, -28328, 0, 21447, 0, -13312, 0, 5943, 0, -1152, 0 + }; + TF_LITE_MICRO_EXPECT_EQ(state.size, sizeof(expected) / sizeof(expected[0])); + int i; + for (i = 0; i < state.size; ++i) { + TF_LITE_MICRO_EXPECT_EQ(state.output[i], expected[i]); + } + + WindowFreeStateContents(&state); +} + +TF_LITE_MICRO_TEST(WindowState_CheckMaxAbsValue) +{ + WindowTestConfig config; + struct WindowState state; + TF_LITE_MICRO_EXPECT( + WindowPopulateState(&config.config_, &state, kSampleRate)); + size_t num_samples_read; + + TF_LITE_MICRO_EXPECT(WindowProcessSamples( + &state, kFakeAudioData, + sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]), &num_samples_read)); + + TF_LITE_MICRO_EXPECT_EQ(state.max_abs_output_value, 32256); + + WindowFreeStateContents(&state); +} + +TF_LITE_MICRO_TEST(WindowState_CheckConsecutiveWindow) +{ + WindowTestConfig config; + struct WindowState state; + TF_LITE_MICRO_EXPECT( + WindowPopulateState(&config.config_, &state, kSampleRate)); + size_t num_samples_read; + + TF_LITE_MICRO_EXPECT(WindowProcessSamples( + &state, kFakeAudioData, + sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]), &num_samples_read)); + TF_LITE_MICRO_EXPECT(WindowProcessSamples( + &state, kFakeAudioData + kWindowSamples, + sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]) - kWindowSamples, + &num_samples_read)); + + const int16_t expected[] = { + 0, -1152, 0, 5943, 0, -13312, 0, 21447, 0, -28328, 0, 32255, 0, -32256, + 0, 28327, 0, -21448, 0, 13311, 0, -5944, 0, 1151, 0 + }; + TF_LITE_MICRO_EXPECT_EQ(state.size, sizeof(expected) / sizeof(expected[0])); + int i; + for (i = 0; i < state.size; ++i) { + TF_LITE_MICRO_EXPECT_EQ(state.output[i], expected[i]); + } + + WindowFreeStateContents(&state); +} + +TF_LITE_MICRO_TEST(WindowState_CheckNotEnoughSamples) +{ + WindowTestConfig config; + struct WindowState state; + TF_LITE_MICRO_EXPECT( + WindowPopulateState(&config.config_, &state, kSampleRate)); + size_t num_samples_read; + + TF_LITE_MICRO_EXPECT(WindowProcessSamples( + &state, kFakeAudioData, + sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]), &num_samples_read)); + TF_LITE_MICRO_EXPECT(WindowProcessSamples( + &state, kFakeAudioData + kWindowSamples, + sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]) - kWindowSamples, + &num_samples_read)); + TF_LITE_MICRO_EXPECT_EQ( + false, WindowProcessSamples( + &state, kFakeAudioData + kWindowSamples + kStepSamples, + sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]) - + kWindowSamples - kStepSamples, + &num_samples_read)); + + TF_LITE_MICRO_EXPECT_EQ( + state.input_used, + sizeof(kFakeAudioData) / sizeof(kFakeAudioData[0]) - 2 * kStepSamples); + + WindowFreeStateContents(&state); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/window_util.c b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/window_util.c new file mode 100644 index 00000000..2195c0d4 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/window_util.c @@ -0,0 +1,76 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/experimental/microfrontend/lib/window_util.h" + +#include +#include +#include +#include + +// Some platforms don't have M_PI +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +void WindowFillConfigWithDefaults(struct WindowConfig *config) +{ + config->size_ms = 25; + config->step_size_ms = 10; +} + +int WindowPopulateState(const struct WindowConfig *config, + struct WindowState *state, int sample_rate) +{ + state->size = config->size_ms * sample_rate / 1000; + state->step = config->step_size_ms * sample_rate / 1000; + + state->coefficients = malloc(state->size * sizeof(*state->coefficients)); + if (state->coefficients == NULL) { + fprintf(stderr, "Failed to allocate window coefficients\n"); + return 0; + } + + // Populate the window values. + const float arg = M_PI * 2.0 / ((float)state->size); + int i; + for (i = 0; i < state->size; ++i) { + float float_value = 0.5 - (0.5 * cos(arg * (i + 0.5))); + // Scale it to fixed point and round it. + state->coefficients[i] = + floor(float_value * (1 << kFrontendWindowBits) + 0.5); + } + + state->input_used = 0; + state->input = malloc(state->size * sizeof(*state->input)); + if (state->input == NULL) { + fprintf(stderr, "Failed to allocate window input\n"); + return 0; + } + + state->output = malloc(state->size * sizeof(*state->output)); + if (state->output == NULL) { + fprintf(stderr, "Failed to allocate window output\n"); + return 0; + } + + return 1; +} + +void WindowFreeStateContents(struct WindowState *state) +{ + free(state->coefficients); + free(state->input); + free(state->output); +} diff --git a/components/tflite/tensorflow/lite/experimental/microfrontend/lib/window_util.h b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/window_util.h new file mode 100644 index 00000000..2517e378 --- /dev/null +++ b/components/tflite/tensorflow/lite/experimental/microfrontend/lib/window_util.h @@ -0,0 +1,45 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_WINDOW_UTIL_H_ +#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_WINDOW_UTIL_H_ + +#include "tensorflow/lite/experimental/microfrontend/lib/window.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct WindowConfig { + // length of window frame in milliseconds + size_t size_ms; + // length of step for next frame in milliseconds + size_t step_size_ms; +}; + +// Populates the WindowConfig with "sane" default values. +void WindowFillConfigWithDefaults(struct WindowConfig *config); + +// Allocates any buffers. +int WindowPopulateState(const struct WindowConfig *config, + struct WindowState *state, int sample_rate); + +// Frees any allocated buffers. +void WindowFreeStateContents(struct WindowState *state); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_WINDOW_UTIL_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/common.h b/components/tflite/tensorflow/lite/kernels/internal/common.h new file mode 100644 index 00000000..f1d0a0d0 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/common.h @@ -0,0 +1,1080 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_COMMON_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_COMMON_H_ + +#ifndef ALLOW_SLOW_GENERIC_DEPTHWISECONV_FALLBACK +#ifdef GEMMLOWP_ALLOW_SLOW_SCALAR_FALLBACK +#define ALLOW_SLOW_GENERIC_DEPTHWISECONV_FALLBACK +#endif +#endif + +#include + +#include "fixedpoint/fixedpoint.h" +#include "tensorflow/lite/kernels/internal/cppmath.h" +#include "tensorflow/lite/kernels/internal/optimized/neon_check.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +constexpr int kReverseShift = -1; + +inline void GetActivationMinMax(FusedActivationFunctionType ac, + float *output_activation_min, + float *output_activation_max) +{ + switch (ac) { + case FusedActivationFunctionType::kNone: + *output_activation_min = std::numeric_limits::lowest(); + *output_activation_max = std::numeric_limits::max(); + break; + case FusedActivationFunctionType::kRelu: + *output_activation_min = 0.f; + *output_activation_max = std::numeric_limits::max(); + break; + case FusedActivationFunctionType::kRelu1: + *output_activation_min = -1.f; + *output_activation_max = 1.f; + break; + case FusedActivationFunctionType::kRelu6: + *output_activation_min = 0.f; + *output_activation_max = 6.f; + break; + } +} + +template +inline T ActivationFunctionWithMinMax(T x, T output_activation_min, + T output_activation_max) +{ + using std::max; + using std::min; + return min(max(x, output_activation_min), output_activation_max); +} + +// Legacy function, left for compatibility only. +template +float ActivationFunction(float x) +{ + float output_activation_min, output_activation_max; + GetActivationMinMax(Ac, &output_activation_min, &output_activation_max); + return ActivationFunctionWithMinMax(x, output_activation_min, + output_activation_max); +} + +inline void BiasAndClamp(float clamp_min, float clamp_max, int bias_size, + const float *bias_data, int array_size, + float *array_data) +{ + // Note: see b/132215220: in May 2019 we thought it would be OK to replace + // this with the Eigen one-liner: + // return (array.colwise() + bias).cwiseMin(clamp_max).cwiseMin(clamp_max). + // This turned out to severely regress performance: +4ms (i.e. 8%) on + // MobileNet v2 / 1.0 / 224. So we keep custom NEON code for now. + TFLITE_DCHECK_EQ((array_size % bias_size), 0); +#ifdef USE_NEON + float *array_ptr = array_data; + float *array_end_ptr = array_ptr + array_size; + const auto clamp_min_vec = vdupq_n_f32(clamp_min); + const auto clamp_max_vec = vdupq_n_f32(clamp_max); + for (; array_ptr != array_end_ptr; array_ptr += bias_size) { + int i = 0; + for (; i <= bias_size - 16; i += 16) { + auto b0 = vld1q_f32(bias_data + i); + auto b1 = vld1q_f32(bias_data + i + 4); + auto b2 = vld1q_f32(bias_data + i + 8); + auto b3 = vld1q_f32(bias_data + i + 12); + auto a0 = vld1q_f32(array_ptr + i); + auto a1 = vld1q_f32(array_ptr + i + 4); + auto a2 = vld1q_f32(array_ptr + i + 8); + auto a3 = vld1q_f32(array_ptr + i + 12); + auto x0 = vaddq_f32(a0, b0); + auto x1 = vaddq_f32(a1, b1); + auto x2 = vaddq_f32(a2, b2); + auto x3 = vaddq_f32(a3, b3); + x0 = vmaxq_f32(clamp_min_vec, x0); + x1 = vmaxq_f32(clamp_min_vec, x1); + x2 = vmaxq_f32(clamp_min_vec, x2); + x3 = vmaxq_f32(clamp_min_vec, x3); + x0 = vminq_f32(clamp_max_vec, x0); + x1 = vminq_f32(clamp_max_vec, x1); + x2 = vminq_f32(clamp_max_vec, x2); + x3 = vminq_f32(clamp_max_vec, x3); + vst1q_f32(array_ptr + i, x0); + vst1q_f32(array_ptr + i + 4, x1); + vst1q_f32(array_ptr + i + 8, x2); + vst1q_f32(array_ptr + i + 12, x3); + } + for (; i <= bias_size - 4; i += 4) { + auto b = vld1q_f32(bias_data + i); + auto a = vld1q_f32(array_ptr + i); + auto x = vaddq_f32(a, b); + x = vmaxq_f32(clamp_min_vec, x); + x = vminq_f32(clamp_max_vec, x); + vst1q_f32(array_ptr + i, x); + } + for (; i < bias_size; i++) { + array_ptr[i] = ActivationFunctionWithMinMax(array_ptr[i] + bias_data[i], + clamp_min, clamp_max); + } + } +#else // not NEON + for (int array_offset = 0; array_offset < array_size; + array_offset += bias_size) { + for (int i = 0; i < bias_size; i++) { + array_data[array_offset + i] = ActivationFunctionWithMinMax( + array_data[array_offset + i] + bias_data[i], clamp_min, clamp_max); + } + } +#endif +} + +inline int32_t MultiplyByQuantizedMultiplierSmallerThanOneExp( + int32_t x, int32_t quantized_multiplier, int left_shift) +{ + using gemmlowp::RoundingDivideByPOT; + using gemmlowp::SaturatingRoundingDoublingHighMul; + return RoundingDivideByPOT( + SaturatingRoundingDoublingHighMul(x, quantized_multiplier), -left_shift); +} + +inline int32_t MultiplyByQuantizedMultiplierGreaterThanOne( + int32_t x, int32_t quantized_multiplier, int left_shift) +{ + using gemmlowp::SaturatingRoundingDoublingHighMul; + return SaturatingRoundingDoublingHighMul(x * (1 << left_shift), + quantized_multiplier); +} + +inline int32_t MultiplyByQuantizedMultiplier(int32_t x, + int32_t quantized_multiplier, + int shift) +{ + using gemmlowp::RoundingDivideByPOT; + using gemmlowp::SaturatingRoundingDoublingHighMul; + int left_shift = shift > 0 ? shift : 0; + int right_shift = shift > 0 ? 0 : -shift; + return RoundingDivideByPOT(SaturatingRoundingDoublingHighMul( + x * (1 << left_shift), quantized_multiplier), + right_shift); +} + +inline int32_t MultiplyByQuantizedMultiplier(int64_t x, + int32_t quantized_multiplier, + int shift) +{ + // Inputs: + // - quantized_multiplier has fixed point at bit 31 + // - shift is -31 to +7 (negative for right shift) + // + // Assumptions: The following input ranges are assumed + // - quantize_scale>=0 (the usual range is (1<<30) to (1>>31)-1) + // - scaling is chosen so final scaled result fits in int32_t + // - input x is in the range -(1<<47) <= x < (1<<47) + assert(quantized_multiplier >= 0); + assert(shift >= -31 && shift < 8); + assert(x >= -(static_cast(1) << 47) && + x < (static_cast(1) << 47)); + + int32_t reduced_multiplier = (quantized_multiplier < 0x7FFF0000) ? ((quantized_multiplier + (1 << 15)) >> 16) : 0x7FFF; + int total_shift = 15 - shift; + x = (x * (int64_t)reduced_multiplier) + ((int64_t)1 << (total_shift - 1)); + int32_t result = x >> total_shift; + return result; +} + +#ifdef USE_NEON +// Round uses ARM's rounding shift right. +inline int32x4x4_t MultiplyByQuantizedMultiplier4Rows( + int32x4x4_t input_val, int32_t quantized_multiplier, int shift) +{ + const int left_shift = std::max(shift, 0); + const int right_shift = std::min(shift, 0); + int32x4x4_t result; + + int32x4_t multiplier_dup = vdupq_n_s32(quantized_multiplier); + int32x4_t left_shift_dup = vdupq_n_s32(left_shift); + int32x4_t right_shift_dup = vdupq_n_s32(right_shift); + + result.val[0] = + vrshlq_s32(vqrdmulhq_s32(vshlq_s32(input_val.val[0], left_shift_dup), + multiplier_dup), + right_shift_dup); + + result.val[1] = + vrshlq_s32(vqrdmulhq_s32(vshlq_s32(input_val.val[1], left_shift_dup), + multiplier_dup), + right_shift_dup); + + result.val[2] = + vrshlq_s32(vqrdmulhq_s32(vshlq_s32(input_val.val[2], left_shift_dup), + multiplier_dup), + right_shift_dup); + + result.val[3] = + vrshlq_s32(vqrdmulhq_s32(vshlq_s32(input_val.val[3], left_shift_dup), + multiplier_dup), + right_shift_dup); + + return result; +} +#endif + +template +int CountLeadingZeros(T integer_input) +{ + static_assert(std::is_unsigned::value, + "Only unsigned integer types handled."); +#if defined(__GNUC__) + return integer_input ? __builtin_clz(integer_input) : std::numeric_limits::digits; +#else + if (integer_input == 0) { + return std::numeric_limits::digits; + } + + const T one_in_leading_positive = static_cast(1) + << (std::numeric_limits::digits - 1); + int leading_zeros = 0; + while (integer_input < one_in_leading_positive) { + integer_input <<= 1; + ++leading_zeros; + } + return leading_zeros; +#endif +} + +template +inline int CountLeadingSignBits(T integer_input) +{ + static_assert(std::is_signed::value, "Only signed integer types handled."); +#if defined(__GNUC__) && !defined(__clang__) + return integer_input ? __builtin_clrsb(integer_input) : std::numeric_limits::digits; +#else + using U = typename std::make_unsigned::type; + return integer_input >= 0 ? CountLeadingZeros(static_cast(integer_input)) - 1 : integer_input != std::numeric_limits::min() ? CountLeadingZeros(2 * static_cast(-integer_input) - 1) : + 0; +#endif +} + +// Use "count leading zeros" helper functions to do a fast Floor(log_2(x)). +template +inline Integer FloorLog2(Integer n) +{ + static_assert(std::is_integral::value, ""); + static_assert(std::is_signed::value, ""); + static_assert(sizeof(Integer) == 4 || sizeof(Integer) == 8, ""); + TFLITE_CHECK_GT(n, 0); + if (sizeof(Integer) == 4) { + return 30 - CountLeadingSignBits(n); + } else { + return 62 - CountLeadingSignBits(n); + } +} + +// generate INT16 LUT for function(), e.g., table exp(x) and 1/(1+x) used in +// softmax +// func - the function to build the LUT for (e.g exp(x)) +// min,max - table limits +// table - pointer to buffer +// num - number of elements in the LUT +inline void gen_lut(double (*func)(double), double min, double max, + int16_t *table, const int num) +{ + // size of table should equal to num + 1 + // last element only for slope calculation + double step = (max - min) / (num - 1); + double half_step = step / 2.0; + for (int i = 0; i < num - 1; i++) { + double sample_val = TfLiteRound(func(min + i * step) * 32768.0); + double midpoint_interp_val = + TfLiteRound((func(min + (i + 1) * step) * 32768.0 + + TfLiteRound(func(min + i * step) * 32768.0)) / + 2.0); + double midpoint_val = + TfLiteRound(func(min + i * step + half_step) * 32768.0); + double midpoint_err = midpoint_interp_val - midpoint_val; + double bias = TfLiteRound(midpoint_err / 2.0); + table[i] = std::min(std::max(sample_val - bias, -32768.0), + 32767.0); + } + table[num - 1] = std::min( + std::max(TfLiteRound(func(max) * 32768.0), -32768.0), 32767.0); +} + +// generate INT16 LUT for function(), e.g., table exp(x) and 1/(1+x) used in +// softmax +// func - the function to build the LUT for (e.g exp(x)) +// min,max - table limits +// table - pointer to buffer +// num - number of elements in the LUT +inline void gen_lut(float (*func)(float), float min, float max, int16_t *table, + const int num) +{ + // size of table should equal to num + 1 + // last element only for slope calculation + float step = (max - min) / (num - 1); + float half_step = step / 2.0f; + for (int i = 0; i < num - 1; i++) { + float sample_val = TfLiteRound(func(min + i * step) * 32768.0f); + float midpoint_interp_val = + TfLiteRound((func(min + (i + 1) * step) * 32768.0f + + TfLiteRound(func(min + i * step) * 32768.0f)) / + 2.0f); + float midpoint_val = + TfLiteRound(func(min + i * step + half_step) * 32768.0f); + float midpoint_err = midpoint_interp_val - midpoint_val; + float bias = TfLiteRound(midpoint_err / 2.0f); + table[i] = std::min(std::max(sample_val - bias, -32768.0f), + 32767.0f); + } + table[num - 1] = std::min( + std::max(TfLiteRound(func(max) * 32768.0f), -32768.0f), 32767.0f); +} + +// int16_t func table lookup, e.g., lookup exp() and 1/(1+x) used in softmax +inline int16_t generic_int16_table_lookup(int16_t value, const int16_t *lut) +{ + // 512 base value, lut[513] only for calculate slope + uint16_t index = static_cast(256 + (value >> 7)); + assert(index < 512 && "LUT index out of range."); + int16_t offset = value & 0x7f; + + // base and slope are Q0.15 + int16_t base = lut[index]; + int16_t slope = lut[index + 1] - lut[index]; + + // Q0.15 * Q0.7 = Q0.22 + // Round and convert from Q0.22 to Q0.15 + int32_t delta = (static_cast(slope) * offset + 64) >> 7; + + // Q0.15 + Q0.15 + return base + delta; +} + +// Table of sigmoid(i/24) at 0.16 format - 256 elements. + +// We use combined sigmoid and tanh look-up table, since +// tanh(x) = 2*sigmoid(2*x) -1. +// Both functions are symmetric, so the LUT table is only needed +// for the absolute value of the input. +static const uint16_t sigmoid_table_uint16[256] = { + 32768, 33451, 34133, 34813, 35493, 36169, 36843, 37513, 38180, 38841, 39498, + 40149, 40794, 41432, 42064, 42688, 43304, 43912, 44511, 45102, 45683, 46255, + 46817, 47369, 47911, 48443, 48964, 49475, 49975, 50464, 50942, 51409, 51865, + 52311, 52745, 53169, 53581, 53983, 54374, 54755, 55125, 55485, 55834, 56174, + 56503, 56823, 57133, 57433, 57724, 58007, 58280, 58544, 58800, 59048, 59288, + 59519, 59743, 59959, 60168, 60370, 60565, 60753, 60935, 61110, 61279, 61441, + 61599, 61750, 61896, 62036, 62172, 62302, 62428, 62549, 62666, 62778, 62886, + 62990, 63090, 63186, 63279, 63368, 63454, 63536, 63615, 63691, 63765, 63835, + 63903, 63968, 64030, 64090, 64148, 64204, 64257, 64308, 64357, 64405, 64450, + 64494, 64536, 64576, 64614, 64652, 64687, 64721, 64754, 64786, 64816, 64845, + 64873, 64900, 64926, 64950, 64974, 64997, 65019, 65039, 65060, 65079, 65097, + 65115, 65132, 65149, 65164, 65179, 65194, 65208, 65221, 65234, 65246, 65258, + 65269, 65280, 65291, 65301, 65310, 65319, 65328, 65337, 65345, 65352, 65360, + 65367, 65374, 65381, 65387, 65393, 65399, 65404, 65410, 65415, 65420, 65425, + 65429, 65433, 65438, 65442, 65445, 65449, 65453, 65456, 65459, 65462, 65465, + 65468, 65471, 65474, 65476, 65479, 65481, 65483, 65485, 65488, 65489, 65491, + 65493, 65495, 65497, 65498, 65500, 65501, 65503, 65504, 65505, 65507, 65508, + 65509, 65510, 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65517, 65518, + 65519, 65520, 65520, 65521, 65522, 65522, 65523, 65523, 65524, 65524, 65525, + 65525, 65526, 65526, 65526, 65527, 65527, 65528, 65528, 65528, 65529, 65529, + 65529, 65529, 65530, 65530, 65530, 65530, 65531, 65531, 65531, 65531, 65531, + 65532, 65532, 65532, 65532, 65532, 65532, 65533, 65533, 65533, 65533, 65533, + 65533, 65533, 65533, 65534, 65534, 65534, 65534, 65534, 65534, 65534, 65534, + 65534, 65534, 65535 +}; + +// TODO(b/77858996): Add these to gemmlowp. +template +IntegerType SaturatingAddNonGemmlowp(IntegerType a, IntegerType b) +{ + static_assert(std::is_same::value, "unimplemented"); + return a; +} + +template <> +inline std::int32_t SaturatingAddNonGemmlowp(std::int32_t a, std::int32_t b) +{ + std::int64_t a64 = a; + std::int64_t b64 = b; + std::int64_t sum = a64 + b64; + return static_cast(std::min( + static_cast(std::numeric_limits::max()), + std::max( + static_cast(std::numeric_limits::min()), + sum))); +} + +template +gemmlowp::FixedPoint SaturatingAddNonGemmlowp( + gemmlowp::FixedPoint a, + gemmlowp::FixedPoint b) +{ + return gemmlowp::FixedPoint::FromRaw( + SaturatingAddNonGemmlowp(a.raw(), b.raw())); +} + +template +IntegerType SaturatingSub(IntegerType a, IntegerType b) +{ + static_assert(std::is_same::value, "unimplemented"); + return a; +} + +template <> +inline std::int16_t SaturatingSub(std::int16_t a, std::int16_t b) +{ + std::int32_t a32 = a; + std::int32_t b32 = b; + std::int32_t diff = a32 - b32; + return static_cast( + std::min(static_cast(32767), + std::max(static_cast(-32768), diff))); +} + +template <> +inline std::int32_t SaturatingSub(std::int32_t a, std::int32_t b) +{ + std::int64_t a64 = a; + std::int64_t b64 = b; + std::int64_t diff = a64 - b64; + return static_cast(std::min( + static_cast(std::numeric_limits::max()), + std::max( + static_cast(std::numeric_limits::min()), + diff))); +} + +template +gemmlowp::FixedPoint SaturatingSub( + gemmlowp::FixedPoint a, + gemmlowp::FixedPoint b) +{ + return gemmlowp::FixedPoint::FromRaw( + SaturatingSub(a.raw(), b.raw())); +} +// End section to be moved to gemmlowp. + +template +IntegerType SaturatingRoundingMultiplyByPOTParam(IntegerType x, int exponent) +{ + if (exponent == 0) { + return x; + } + using ScalarIntegerType = + typename gemmlowp::FixedPointRawTypeTraits::ScalarRawType; + const IntegerType min = + gemmlowp::Dup(std::numeric_limits::min()); + const IntegerType max = + gemmlowp::Dup(std::numeric_limits::max()); + const int ScalarIntegerTypeBits = 8 * sizeof(ScalarIntegerType); + + const std::int32_t threshold = + ((1 << (ScalarIntegerTypeBits - 1 - exponent)) - 1); + const IntegerType positive_mask = + gemmlowp::MaskIfGreaterThan(x, gemmlowp::Dup(threshold)); + const IntegerType negative_mask = + gemmlowp::MaskIfLessThan(x, gemmlowp::Dup(-threshold)); + + IntegerType result = gemmlowp::ShiftLeft(x, exponent); + result = gemmlowp::SelectUsingMask(positive_mask, max, result); + result = gemmlowp::SelectUsingMask(negative_mask, min, result); + return result; +} + +// If we want to leave IntegerBits fixed, then multiplication +// by a power of two has to be saturating/rounding, not exact anymore. +template +gemmlowp::FixedPoint +SaturatingRoundingMultiplyByPOTParam( + gemmlowp::FixedPoint a, int exponent) +{ + return gemmlowp::FixedPoint::FromRaw( + SaturatingRoundingMultiplyByPOTParam(a.raw(), exponent)); +} + +// Convert int32_t multiplier to int16_t with rounding. +inline void DownScaleInt32ToInt16Multiplier(int32_t multiplier_int32_t, + int16_t *multiplier_int16_t) +{ + TFLITE_DCHECK_GE(multiplier_int32_t, 0); + static constexpr int32_t kRoundingOffset = 1 << 15; + if (multiplier_int32_t >= + std::numeric_limits::max() - kRoundingOffset) { + *multiplier_int16_t = std::numeric_limits::max(); + return; + } + const int32_t result = (multiplier_int32_t + kRoundingOffset) >> 16; + TFLITE_DCHECK_LE(result << 16, multiplier_int32_t + kRoundingOffset); + TFLITE_DCHECK_GT(result << 16, multiplier_int32_t - kRoundingOffset); + *multiplier_int16_t = result; + TFLITE_DCHECK_EQ(*multiplier_int16_t, result); +} + +// Minimum output bits to accommodate log of maximum input range. It actually +// does not matter if one considers, say, [-64,64] or [-64,64). +// +// For example, run this through Octave: +// [0:127; ... +// ceil(log(abs( log(2.^(0:127))+1 ))/log(2)); ... +// ceil(log(abs( log(2.^(0:127))+1 ))/log(2))] +constexpr int min_log_x_output_bits(int input_bits) +{ + return input_bits > 90 ? 7 : input_bits > 44 ? 6 : + input_bits > 21 ? 5 : + input_bits > 10 ? 4 : + input_bits > 4 ? 3 : + input_bits > 1 ? 2 : + 1; +} + +// Although currently the name of this function says that it cannot handle +// values less than 1, in practice it can handle as low as 1/x_max, where +// x_max is the largest representable input. In other words, the output range +// is symmetric. +template +inline gemmlowp::FixedPoint +log_x_for_x_greater_than_or_equal_to_1_impl( + gemmlowp::FixedPoint input_val) +{ + // assert(__builtin_clz(0u) >= std::numeric_limits::digits - 1); + // assert(__builtin_clz(0u) <= std::numeric_limits::digits); + using FixedPoint0 = gemmlowp::FixedPoint; + // The reason for accumulating the result with an extra bit of headroom is + // that z_pow_2_adj * log_2 might be saturated, and adding num_scaled * + // recip_denom will otherwise introduce an error. + static constexpr int kAccumIntegerBits = OutputIntegerBits + 1; + using FixedPointAccum = gemmlowp::FixedPoint; + + const FixedPoint0 log_2 = GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT( + FixedPoint0, 1488522236, std::log(2.0)); + const FixedPoint0 sqrt_sqrt_half = GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT( + FixedPoint0, 1805811301, std::sqrt(std::sqrt(0.5))); + const FixedPoint0 sqrt_half = GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT( + FixedPoint0, 1518500250, std::sqrt(0.5)); + const FixedPoint0 one_quarter = + GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(FixedPoint0, 536870912, 1.0 / 4.0); + + const FixedPoint0 alpha_n = GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT( + FixedPoint0, 117049297, 11.0 / 240.0 * std::sqrt(std::sqrt(2.0))); + const FixedPoint0 alpha_d = GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT( + FixedPoint0, 127690142, 1.0 / 20.0 * std::sqrt(std::sqrt(2.0))); + const FixedPoint0 alpha_i = GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT( + FixedPoint0, 1057819769, + 2.0 / std::sqrt(std::sqrt(2.0)) - std::sqrt(std::sqrt(2.0))); + const FixedPoint0 alpha_f = GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT( + FixedPoint0, 638450708, 1.0 / 4.0 * std::sqrt(std::sqrt(2.0))); + + const FixedPointAccum shifted_quarter = + gemmlowp::Rescale(one_quarter); + + // Reinterpret the input value as Q0.31, because we will figure out the + // required shift "ourselves" instead of using, say, Rescale. + FixedPoint0 z_a = FixedPoint0::FromRaw(input_val.raw()); + // z_a_pow_2 = input_integer_bits - z_a_headroom; + int z_a_headroom_plus_1 = CountLeadingZeros(static_cast(z_a.raw())); + FixedPoint0 r_a_tmp = + SaturatingRoundingMultiplyByPOTParam(z_a, (z_a_headroom_plus_1 - 1)); + const int32_t r_a_raw = + SaturatingRoundingMultiplyByPOTParam((r_a_tmp * sqrt_half).raw(), 1); + // z_pow_2_adj = max(z_pow_2_a - 0.75, z_pow_2_b - 0.25); + // z_pow_2_adj = max(InputIntegerBits - z_a_headroom_plus_1 + 0.25, + // InputIntegerBits - z_b_headroom - 0.25); + const FixedPointAccum z_a_pow_2_adj = SaturatingAddNonGemmlowp( + FixedPointAccum::FromRaw(SaturatingRoundingMultiplyByPOTParam( + static_cast(InputIntegerBits - z_a_headroom_plus_1), + 31 - kAccumIntegerBits)), + shifted_quarter); + + // z_b is treated like z_a, but premultiplying by sqrt(0.5). + FixedPoint0 z_b = z_a * sqrt_half; + int z_b_headroom = CountLeadingZeros(static_cast(z_b.raw())) - 1; + const int32_t r_b_raw = + SaturatingRoundingMultiplyByPOTParam(z_a.raw(), z_b_headroom); + const FixedPointAccum z_b_pow_2_adj = SaturatingSub( + FixedPointAccum::FromRaw(SaturatingRoundingMultiplyByPOTParam( + static_cast(InputIntegerBits - z_b_headroom), + 31 - kAccumIntegerBits)), + shifted_quarter); + + const FixedPoint0 r = FixedPoint0::FromRaw(std::min(r_a_raw, r_b_raw)); + const FixedPointAccum z_pow_2_adj = FixedPointAccum::FromRaw( + std::max(z_a_pow_2_adj.raw(), z_b_pow_2_adj.raw())); + + const FixedPoint0 p = gemmlowp::RoundingHalfSum(r, sqrt_sqrt_half); + FixedPoint0 q = r - sqrt_sqrt_half; + q = q + q; + + const FixedPoint0 common_sq = q * q; + const FixedPoint0 num = q * r + q * common_sq * alpha_n; + const FixedPoint0 denom_minus_one_0 = + p * (alpha_i + q + alpha_d * common_sq) + alpha_f * q; + const FixedPoint0 recip_denom = + one_over_one_plus_x_for_x_in_0_1(denom_minus_one_0); + + const FixedPointAccum num_scaled = gemmlowp::Rescale(num); + return gemmlowp::Rescale(z_pow_2_adj * log_2 + + num_scaled * recip_denom); +} + +template +inline gemmlowp::FixedPoint +log_x_for_x_greater_than_or_equal_to_1( + gemmlowp::FixedPoint input_val) +{ + static_assert( + OutputIntegerBits >= min_log_x_output_bits(InputIntegerBits), + "Output integer bits must be sufficient to accommodate logs of inputs."); + return log_x_for_x_greater_than_or_equal_to_1_impl( + input_val); +} + +inline int32_t GetReciprocal(int32_t x, int x_integer_digits, + int *num_bits_over_unit) +{ + int headroom_plus_one = CountLeadingZeros(static_cast(x)); + // This is the number of bits to the left of the binary point above 1.0. + // Consider x=1.25. In that case shifted_scale=0.8 and + // no later adjustment will be needed. + *num_bits_over_unit = x_integer_digits - headroom_plus_one; + const int32_t shifted_sum_minus_one = + static_cast((static_cast(x) << headroom_plus_one) - + (static_cast(1) << 31)); + + gemmlowp::FixedPoint shifted_scale = + gemmlowp::one_over_one_plus_x_for_x_in_0_1( + gemmlowp::FixedPoint::FromRaw(shifted_sum_minus_one)); + return shifted_scale.raw(); +} + +inline void GetInvSqrtQuantizedMultiplierExp(int32_t input, int reverse_shift, + int32_t *output_inv_sqrt, + int *output_shift) +{ + TFLITE_DCHECK_GE(input, 0); + if (input <= 1) { + // Handle the input value 1 separately to avoid overflow in that case + // in the general computation below (b/143972021). Also handle 0 as if it + // were a 1. 0 is an invalid input here (divide by zero) and 1 is a valid + // but rare/unrealistic input value. We can expect both to occur in some + // incompletely trained models, but probably not in fully trained models. + *output_inv_sqrt = std::numeric_limits::max(); + *output_shift = 0; + return; + } + TFLITE_DCHECK_GT(input, 1); + *output_shift = 11; + while (input >= (1 << 29)) { + input /= 4; + ++*output_shift; + } + const unsigned max_left_shift_bits = + CountLeadingZeros(static_cast(input)) - 1; + const unsigned max_left_shift_bit_pairs = max_left_shift_bits / 2; + const unsigned left_shift_bit_pairs = max_left_shift_bit_pairs - 1; + *output_shift -= left_shift_bit_pairs; + input <<= 2 * left_shift_bit_pairs; + TFLITE_DCHECK_GE(input, (1 << 27)); + TFLITE_DCHECK_LT(input, (1 << 29)); + using gemmlowp::FixedPoint; + using gemmlowp::Rescale; + using gemmlowp::SaturatingRoundingMultiplyByPOT; + // Using 3 integer bits gives us enough room for the internal arithmetic in + // this Newton-Raphson iteration. + using F3 = FixedPoint; + using F0 = FixedPoint; + const F3 fixedpoint_input = F3::FromRaw(input >> 1); + const F3 fixedpoint_half_input = + SaturatingRoundingMultiplyByPOT<-1>(fixedpoint_input); + const F3 fixedpoint_half_three = + GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(F3, (1 << 28) + (1 << 27), 1.5); + // Newton-Raphson iteration + // Naive unoptimized starting guess: x = 1 + F3 x = F3::One(); + // Naive unoptimized number of iterations: 5 + for (int i = 0; i < 5; i++) { + const F3 x3 = Rescale<3>(x * x * x); + x = Rescale<3>(fixedpoint_half_three * x - fixedpoint_half_input * x3); + } + const F0 fixedpoint_half_sqrt_2 = + GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(F0, 1518500250, std::sqrt(2.) / 2.); + x = x * fixedpoint_half_sqrt_2; + *output_inv_sqrt = x.raw(); + if (*output_shift < 0) { + *output_inv_sqrt <<= -*output_shift; + *output_shift = 0; + } + // Convert right shift (right is positive) to left shift. + *output_shift *= reverse_shift; +} + +// DO NOT USE THIS STRUCT FOR NEW FUNCTIONALITY BEYOND IMPLEMENTING +// BROADCASTING. +// +// NdArrayDesc describes the shape and memory layout of an N-dimensional +// rectangular array of numbers. +// +// NdArrayDesc is basically identical to Dims defined in types.h. +// However, as Dims is to be deprecated, this class exists as an adaptor +// to enable simple unoptimized implementations of element-wise broadcasting +// operations. +template +struct NdArrayDesc { + // The "extent" of each dimension. Indices along dimension d must be in the + // half-open interval [0, extents[d]). + int extents[N]; + + // The number of *elements* (not bytes) between consecutive indices of each + // dimension. + int strides[N]; +}; + +// DO NOT USE THIS FUNCTION FOR NEW FUNCTIONALITY BEYOND IMPLEMENTING +// BROADCASTING. +// +// Same as Offset(), except takes as NdArrayDesc instead of Dims. +inline int SubscriptToIndex(const NdArrayDesc<4> &desc, int i0, int i1, int i2, + int i3) +{ + TFLITE_DCHECK(i0 >= 0 && i0 < desc.extents[0]); + TFLITE_DCHECK(i1 >= 0 && i1 < desc.extents[1]); + TFLITE_DCHECK(i2 >= 0 && i2 < desc.extents[2]); + TFLITE_DCHECK(i3 >= 0 && i3 < desc.extents[3]); + return i0 * desc.strides[0] + i1 * desc.strides[1] + i2 * desc.strides[2] + + i3 * desc.strides[3]; +} + +inline int SubscriptToIndex(const NdArrayDesc<5> &desc, int indexes[5]) +{ + return indexes[0] * desc.strides[0] + indexes[1] * desc.strides[1] + + indexes[2] * desc.strides[2] + indexes[3] * desc.strides[3] + + indexes[4] * desc.strides[4]; +} + +inline int SubscriptToIndex(const NdArrayDesc<8> &desc, int indexes[8]) +{ + return indexes[0] * desc.strides[0] + indexes[1] * desc.strides[1] + + indexes[2] * desc.strides[2] + indexes[3] * desc.strides[3] + + indexes[4] * desc.strides[4] + indexes[5] * desc.strides[5] + + indexes[6] * desc.strides[6] + indexes[7] * desc.strides[7]; +} + +// Given the dimensions of the operands for an element-wise binary broadcast, +// adjusts them so that they can be directly iterated over with simple loops. +// Returns the adjusted dims as instances of NdArrayDesc in 'desc0_out' and +// 'desc1_out'. 'desc0_out' and 'desc1_out' cannot be nullptr. +// +// This function assumes that the two input shapes are compatible up to +// broadcasting and the shorter one has already been prepended with 1s to be the +// same length. E.g., if shape0 is (1, 16, 16, 64) and shape1 is (1, 64), +// shape1 must already have been prepended to be (1, 1, 1, 64). Recall that +// Dims refer to shapes in reverse order. In this case, input0_dims will be +// (64, 16, 16, 1) and input1_dims will be (64, 1, 1, 1). +// +// When two shapes are compatible up to broadcasting, for each dimension d, +// the input extents are either equal, or one of them is 1. +// +// This function performs the following for each dimension d: +// - If the extents are equal, then do nothing since the loop that walks over +// both of the input arrays is correct. +// - Otherwise, one (and only one) of the extents must be 1. Say extent0 is 1 +// and extent1 is e1. Then set extent0 to e1 and stride0 *to 0*. This allows +// array0 to be referenced *at any index* in dimension d and still access the +// same slice. +template +inline void NdArrayDescsForElementwiseBroadcast(const Dims &input0_dims, + const Dims &input1_dims, + NdArrayDesc *desc0_out, + NdArrayDesc *desc1_out) +{ + TFLITE_DCHECK(desc0_out != nullptr); + TFLITE_DCHECK(desc1_out != nullptr); + + // Copy dims to desc. + for (int i = 0; i < N; ++i) { + desc0_out->extents[i] = input0_dims.sizes[i]; + desc0_out->strides[i] = input0_dims.strides[i]; + desc1_out->extents[i] = input1_dims.sizes[i]; + desc1_out->strides[i] = input1_dims.strides[i]; + } + + // Walk over each dimension. If the extents are equal do nothing. + // Otherwise, set the desc with extent 1 to have extent equal to the other and + // stride 0. + for (int i = 0; i < N; ++i) { + const int extent0 = ArraySize(input0_dims, i); + const int extent1 = ArraySize(input1_dims, i); + if (extent0 != extent1) { + if (extent0 == 1) { + desc0_out->strides[i] = 0; + desc0_out->extents[i] = extent1; + } else { + TFLITE_DCHECK_EQ(extent1, 1); + desc1_out->strides[i] = 0; + desc1_out->extents[i] = extent0; + } + } + } +} + +// Copies dims to desc, calculating strides. +template +inline void CopyDimsToDesc(const RuntimeShape &input_shape, + NdArrayDesc *desc_out) +{ + int desc_stride = 1; + for (int i = N - 1; i >= 0; --i) { + desc_out->extents[i] = input_shape.Dims(i); + desc_out->strides[i] = desc_stride; + desc_stride *= input_shape.Dims(i); + } +} + +template +inline void NdArrayDescsForElementwiseBroadcast( + const RuntimeShape &input0_shape, const RuntimeShape &input1_shape, + NdArrayDesc *desc0_out, NdArrayDesc *desc1_out) +{ + TFLITE_DCHECK(desc0_out != nullptr); + TFLITE_DCHECK(desc1_out != nullptr); + + auto extended_input0_shape = RuntimeShape::ExtendedShape(N, input0_shape); + auto extended_input1_shape = RuntimeShape::ExtendedShape(N, input1_shape); + + // Copy dims to desc, calculating strides. + CopyDimsToDesc(extended_input0_shape, desc0_out); + CopyDimsToDesc(extended_input1_shape, desc1_out); + + // Walk over each dimension. If the extents are equal do nothing. + // Otherwise, set the desc with extent 1 to have extent equal to the other and + // stride 0. + for (int i = 0; i < N; ++i) { + const int extent0 = extended_input0_shape.Dims(i); + const int extent1 = extended_input1_shape.Dims(i); + if (extent0 != extent1) { + if (extent0 == 1) { + desc0_out->strides[i] = 0; + desc0_out->extents[i] = extent1; + } else { + TFLITE_DCHECK_EQ(extent1, 1); + desc1_out->strides[i] = 0; + desc1_out->extents[i] = extent0; + } + } + } +} + +template +inline void NdArrayDescsForElementwiseBroadcast( + const RuntimeShape &input0_shape, const RuntimeShape &input1_shape, + const RuntimeShape &input2_shape, NdArrayDesc *desc0_out, + NdArrayDesc *desc1_out, NdArrayDesc *desc2_out) +{ + TFLITE_DCHECK(desc0_out != nullptr); + TFLITE_DCHECK(desc1_out != nullptr); + TFLITE_DCHECK(desc2_out != nullptr); + + auto extended_input0_shape = RuntimeShape::ExtendedShape(N, input0_shape); + auto extended_input1_shape = RuntimeShape::ExtendedShape(N, input1_shape); + auto extended_input2_shape = RuntimeShape::ExtendedShape(N, input2_shape); + + // Copy dims to desc, calculating strides. + CopyDimsToDesc(extended_input0_shape, desc0_out); + CopyDimsToDesc(extended_input1_shape, desc1_out); + CopyDimsToDesc(extended_input2_shape, desc2_out); + + // Walk over each dimension. If the extents are equal do nothing. + // Otherwise, set the desc with extent 1 to have extent equal to the other and + // stride 0. + for (int i = 0; i < N; ++i) { + const int extent0 = extended_input0_shape.Dims(i); + const int extent1 = extended_input1_shape.Dims(i); + const int extent2 = extended_input2_shape.Dims(i); + + int extent = extent0; + if (extent1 != 1) + extent = extent1; + if (extent2 != 1) + extent = extent2; + + TFLITE_DCHECK(extent0 == 1 || extent0 == extent); + TFLITE_DCHECK(extent1 == 1 || extent1 == extent); + TFLITE_DCHECK(extent2 == 1 || extent2 == extent); + + if (!(extent0 == extent1 && extent1 == extent2)) { + if (extent0 == 1) { + desc0_out->strides[i] = 0; + desc0_out->extents[i] = extent; + } + if (extent1 == 1) { + desc1_out->strides[i] = 0; + desc1_out->extents[i] = extent; + } + if (extent2 == 1) { + desc2_out->strides[i] = 0; + desc2_out->extents[i] = extent; + } + } + } +} + +// Detailed implementation of NDOpsHelper, the indexes must be a zero array. +// This implementation is equivalent to N nested loops. Ex, if N=4, it can be +// re-writen as: +// for (int b = 0; b < output.extents[0]; ++b) { +// for (int y = 0; y < output.extents[1]; ++y) { +// for (int x = 0; x < output.extents[2]; ++x) { +// for (int c = 0; c < output.extents[3]; ++c) { +// calc({b,y,x,c}); +// } +// } +// } +// } +template +typename std::enable_if::type NDOpsHelperImpl( + const NdArrayDesc &output, const Calc &calc, int indexes[N]) +{ + for (indexes[DIM] = 0; indexes[DIM] < output.extents[DIM]; ++indexes[DIM]) { + NDOpsHelperImpl(output, calc, indexes); + } +} + +template +typename std::enable_if::type NDOpsHelperImpl( + const NdArrayDesc &output, const Calc &calc, int indexes[N]) +{ + for (indexes[DIM] = 0; indexes[DIM] < output.extents[DIM]; ++indexes[DIM]) { + calc(indexes); + } +} + +// Execute the calc function in the innermost iteration based on the shape of +// the output. The calc function should take a single argument of type int[N]. +template +inline void NDOpsHelper(const NdArrayDesc &output, const Calc &calc) +{ + int indexes[N] = { 0 }; + NDOpsHelperImpl(output, calc, indexes); +} +// Copied from gemmlowp::RoundDown when we dropped direct dependency on +// gemmlowp. +// +// Returns the runtime argument rounded down to the nearest multiple of +// the fixed Modulus. +template +Integer RoundDown(Integer i) +{ + return i - (i % Modulus); +} + +// Copied from gemmlowp::RoundUp when we dropped direct dependency on +// gemmlowp. +// +// Returns the runtime argument rounded up to the nearest multiple of +// the fixed Modulus. +template +Integer RoundUp(Integer i) +{ + return RoundDown(i + Modulus - 1); +} + +// Copied from gemmlowp::CeilQuotient when we dropped direct dependency on +// gemmlowp. +// +// Returns the quotient a / b rounded up ('ceil') to the nearest integer. +template +Integer CeilQuotient(Integer a, Integer b) +{ + return (a + b - 1) / b; +} + +// This function is a copy of gemmlowp::HowManyThreads, copied when we dropped +// the direct dependency of internal/optimized/ on gemmlowp. +// +// It computes a reasonable number of threads to use for a GEMM of shape +// (rows, cols, depth). +// +// TODO(b/131910176): get rid of this function by switching each call site +// to its own more sensible logic for its own workload. +template +inline int LegacyHowManyThreads(int max_num_threads, int rows, int cols, + int depth) +{ + // Early-exit in the default case where multi-threading is disabled. + if (max_num_threads == 1) { + return 1; + } + + // Ensure that each thread has KernelRows rows to process, if at all possible. + int thread_count = std::min(max_num_threads, rows / KernelRows); + + // Limit the number of threads according to the overall size of the problem. + if (thread_count > 1) { + // Empirically determined value. + static constexpr std::uint64_t min_cubic_size_per_thread = 64 * 1024; + + // We can only multiply two out of three sizes without risking overflow + const std::uint64_t cubic_size = + std::uint64_t(rows) * std::uint64_t(cols) * std::uint64_t(depth); + + thread_count = std::min( + thread_count, static_cast(cubic_size / min_cubic_size_per_thread)); + } + + if (thread_count < 1) { + thread_count = 1; + } + + assert(thread_count > 0 && thread_count <= max_num_threads); + return thread_count; +} + +template +void optimized_ops_preload_l1_stream(const T *ptr) +{ +#ifdef __GNUC__ + // builtin offered by GCC-compatible compilers including clang + __builtin_prefetch(ptr, /* 0 means read */ 0, /* 0 means no locality */ 0); +#else + (void)ptr; +#endif +} + +template +void optimized_ops_preload_l1_keep(const T *ptr) +{ +#ifdef __GNUC__ + // builtin offered by GCC-compatible compilers including clang + __builtin_prefetch(ptr, /* 0 means read */ 0, /* 3 means high locality */ 3); +#else + (void)ptr; +#endif +} + +template +void optimized_ops_prefetch_write_l1_keep(const T *ptr) +{ +#ifdef __GNUC__ + // builtin offered by GCC-compatible compilers including clang + __builtin_prefetch(ptr, /* 1 means write */ 1, /* 3 means high locality */ 3); +#else + (void)ptr; +#endif +} + +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_COMMON_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/compatibility.h b/components/tflite/tensorflow/lite/kernels/internal/compatibility.h new file mode 100644 index 00000000..e53eb2fa --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/compatibility.h @@ -0,0 +1,112 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_COMPATIBILITY_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_COMPATIBILITY_H_ + +#include + +#include "tensorflow/lite/kernels/op_macros.h" + +#ifndef TFLITE_DCHECK +#define TFLITE_DCHECK(condition) (condition) ? (void)0 : TFLITE_ASSERT_FALSE +#endif + +#ifndef TFLITE_DCHECK_EQ +#define TFLITE_DCHECK_EQ(x, y) ((x) == (y)) ? (void)0 : TFLITE_ASSERT_FALSE +#endif + +#ifndef TFLITE_DCHECK_NE +#define TFLITE_DCHECK_NE(x, y) ((x) != (y)) ? (void)0 : TFLITE_ASSERT_FALSE +#endif + +#ifndef TFLITE_DCHECK_GE +#define TFLITE_DCHECK_GE(x, y) ((x) >= (y)) ? (void)0 : TFLITE_ASSERT_FALSE +#endif + +#ifndef TFLITE_DCHECK_GT +#define TFLITE_DCHECK_GT(x, y) ((x) > (y)) ? (void)0 : TFLITE_ASSERT_FALSE +#endif + +#ifndef TFLITE_DCHECK_LE +#define TFLITE_DCHECK_LE(x, y) ((x) <= (y)) ? (void)0 : TFLITE_ASSERT_FALSE +#endif + +#ifndef TFLITE_DCHECK_LT +#define TFLITE_DCHECK_LT(x, y) ((x) < (y)) ? (void)0 : TFLITE_ASSERT_FALSE +#endif + +// TODO(ahentz): Clean up: We should stick to the DCHECK versions. +#ifndef TFLITE_CHECK +#define TFLITE_CHECK(condition) (condition) ? (void)0 : TFLITE_ABORT +#endif + +#ifndef TFLITE_CHECK_EQ +#define TFLITE_CHECK_EQ(x, y) ((x) == (y)) ? (void)0 : TFLITE_ABORT +#endif + +#ifndef TFLITE_CHECK_NE +#define TFLITE_CHECK_NE(x, y) ((x) != (y)) ? (void)0 : TFLITE_ABORT +#endif + +#ifndef TFLITE_CHECK_GE +#define TFLITE_CHECK_GE(x, y) ((x) >= (y)) ? (void)0 : TFLITE_ABORT +#endif + +#ifndef TFLITE_CHECK_GT +#define TFLITE_CHECK_GT(x, y) ((x) > (y)) ? (void)0 : TFLITE_ABORT +#endif + +#ifndef TFLITE_CHECK_LE +#define TFLITE_CHECK_LE(x, y) ((x) <= (y)) ? (void)0 : TFLITE_ABORT +#endif + +#ifndef TFLITE_CHECK_LT +#define TFLITE_CHECK_LT(x, y) ((x) < (y)) ? (void)0 : TFLITE_ABORT +#endif + +#ifndef TF_LITE_STATIC_MEMORY +// TODO(b/162019032): Consider removing these type-aliases. +using int8 = std::int8_t; +using uint8 = std::uint8_t; +using int16 = std::int16_t; +using uint16 = std::uint16_t; +using int32 = std::int32_t; +using uint32 = std::uint32_t; +#endif // !defined(TF_LITE_STATIC_MEMORY) + +// TFLITE_DEPRECATED() +// +// Duplicated from absl/base/macros.h to avoid pulling in that library. +// Marks a deprecated class, struct, enum, function, method and variable +// declarations. The macro argument is used as a custom diagnostic message (e.g. +// suggestion of a better alternative). +// +// Example: +// +// class TFLITE_DEPRECATED("Use Bar instead") Foo {...}; +// TFLITE_DEPRECATED("Use Baz instead") void Bar() {...} +// +// Every usage of a deprecated entity will trigger a warning when compiled with +// clang's `-Wdeprecated-declarations` option. This option is turned off by +// default, but the warnings will be reported by clang-tidy. +#if defined(__clang__) && __cplusplus >= 201103L +#define TFLITE_DEPRECATED(message) __attribute__((deprecated(message))) +#endif + +#ifndef TFLITE_DEPRECATED +#define TFLITE_DEPRECATED(message) +#endif + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_COMPATIBILITY_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/cppmath.h b/components/tflite/tensorflow/lite/kernels/internal/cppmath.h new file mode 100644 index 00000000..bac4e9b3 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/cppmath.h @@ -0,0 +1,41 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_CPPMATH_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_CPPMATH_H_ + +#include + +namespace tflite { +#if defined(TF_LITE_USE_GLOBAL_CMATH_FUNCTIONS) || \ + (defined(__ANDROID__) && !defined(__NDK_MAJOR__)) || defined(ARDUINO) || \ + defined(__ZEPHYR__) +#define TF_LITE_GLOBAL_STD_PREFIX +#else +#define TF_LITE_GLOBAL_STD_PREFIX std +#endif + +#define DECLARE_STD_GLOBAL_SWITCH1(tf_name, std_name) \ + template \ + inline T tf_name(const T x) \ + { \ + return TF_LITE_GLOBAL_STD_PREFIX::std_name(x); \ + } + +DECLARE_STD_GLOBAL_SWITCH1(TfLiteRound, round); +DECLARE_STD_GLOBAL_SWITCH1(TfLiteExpm1, expm1); + +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_CPPMATH_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/max.h b/components/tflite/tensorflow/lite/kernels/internal/max.h new file mode 100644 index 00000000..6b57d56e --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/max.h @@ -0,0 +1,36 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_MAX_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_MAX_H_ + +#include + +namespace tflite { +#if defined(TF_LITE_USE_GLOBAL_MAX) || defined(__ZEPHYR__) +inline float TfLiteMax(const float &x, const float &y) +{ + return std::max(x, y); +} +#else +template +inline T TfLiteMax(const T &x, const T &y) +{ + return std::fmax(x, y); +} +#endif + +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_MAX_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/min.h b/components/tflite/tensorflow/lite/kernels/internal/min.h new file mode 100644 index 00000000..563cc6d8 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/min.h @@ -0,0 +1,36 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_MIN_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_MIN_H_ + +#include + +namespace tflite { +#if defined(TF_LITE_USE_GLOBAL_MIN) || defined(__ZEPHYR__) +inline float TfLiteMin(const float &x, const float &y) +{ + return std::min(x, y); +} +#else +template +inline T TfLiteMin(const T &x, const T &y) +{ + return std::fmin(x, y); +} +#endif + +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_MIN_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/optimized/neon_check.h b/components/tflite/tensorflow/lite/kernels/internal/optimized/neon_check.h new file mode 100644 index 00000000..e2b07228 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/optimized/neon_check.h @@ -0,0 +1,20 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_OPTIMIZED_NEON_CHECK_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_OPTIMIZED_NEON_CHECK_H_ + +// TFLM does not need to utilize any Neon optimizations. + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_OPTIMIZED_NEON_CHECK_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/portable_tensor.h b/components/tflite/tensorflow/lite/kernels/internal/portable_tensor.h new file mode 100644 index 00000000..724ccad7 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/portable_tensor.h @@ -0,0 +1,143 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_PORTABLE_TENSOR_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_PORTABLE_TENSOR_H_ + +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +inline RuntimeShape GetTensorShape(std::vector data) +{ + return RuntimeShape(data.size(), data.data()); +} + +// A list of tensors in a format that can be used by kernels like split and +// concatenation. +template +class VectorOfTensors { +public: + // Build with the tensors in 'tensor_list'. + VectorOfTensors(const TfLiteContext &context, + const TfLiteIntArray &tensor_list) + { + int num_tensors = tensor_list.size; + + all_data_.reserve(num_tensors); + all_shape_.reserve(num_tensors); + all_shape_ptr_.reserve(num_tensors); + + for (int i = 0; i < num_tensors; ++i) { + TfLiteTensor *t = &context.tensors[tensor_list.data[i]]; + all_data_.push_back(GetTensorData(t)); + all_shape_.push_back(GetTensorShape(t)); + } + + // Taking the pointer from inside a std::vector is only OK if the vector is + // never modified, so we populate all_shape in the previous loop and then we + // are free to grab iterators here. + for (int i = 0; i < num_tensors; ++i) { + all_shape_ptr_.push_back(&all_shape_[i]); + } + } + // Return a pointer to the data pointers of all tensors in the list. For + // example: + // float* const* f = v.data(); + // f[0][1] is the second element of the first tensor. + T *const *data() const + { + return all_data_.data(); + } + + // Return a pointer the shape pointers of all tensors in the list. For + // example: + // const RuntimeShape* const* d = v.dims(); + // dims[1] are the dimensions of the second tensor in the list. + const RuntimeShape *const *shapes() const + { + return all_shape_ptr_.data(); + } + +private: + std::vector all_data_; + std::vector all_shape_; + std::vector all_shape_ptr_; +}; + +// A list of quantized tensors in a format that can be used by kernels like +// split and concatenation. +class VectorOfQuantizedTensors : public VectorOfTensors { +public: + // Build with the tensors in 'tensor_list'. + VectorOfQuantizedTensors(const TfLiteContext &context, + const TfLiteIntArray &tensor_list) + : VectorOfTensors(context, tensor_list) + { + for (int i = 0; i < tensor_list.size; ++i) { + TfLiteTensor *t = &context.tensors[tensor_list.data[i]]; + zero_point_.push_back(t->params.zero_point); + scale_.push_back(t->params.scale); + } + } + + const float *scale() const + { + return scale_.data(); + } + const int32_t *zero_point() const + { + return zero_point_.data(); + } + +private: + std::vector zero_point_; + std::vector scale_; +}; + +// Writes randomly accessed values from `input` sequentially into `output`. +template +class SequentialTensorWriter { +public: + SequentialTensorWriter(const TfLiteTensor *input, TfLiteTensor *output) + { + input_data_ = GetTensorData(input); + output_ptr_ = GetTensorData(output); + } + SequentialTensorWriter(const T *input_data, T *output_data) + : input_data_(input_data), output_ptr_(output_data) + { + } + + void Write(int position) + { + *output_ptr_++ = input_data_[position]; + } + void WriteN(int position, int len) + { + memcpy(output_ptr_, &input_data_[position], sizeof(T) * len); + output_ptr_ += len; + } + +private: + const T *input_data_; + T *output_ptr_; +}; + +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_PORTABLE_TENSOR_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/quantization_util.cc b/components/tflite/tensorflow/lite/kernels/internal/quantization_util.cc new file mode 100644 index 00000000..5eb08ceb --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/quantization_util.cc @@ -0,0 +1,409 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/quantization_util.h" + +#include +#include +#include + +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/kernels/internal/cppmath.h" + +namespace tflite { + +namespace { +// These constants are used to manipulate the binary representation of doubles. +// Double-precision binary64 floating point format is: +// Bit | 63 | 62-52 | 51-0 | +// | Sign | Exponent | Fraction | +// To avoid 64-bit integers as much as possible, I break this into high and +// low 32-bit chunks. High is: +// Bit | 31 | 30-20 | 19-0 | +// | Sign | Exponent | High Fraction | +// Low is: +// Bit | 31-0 | +// | Low Fraction | +// We then access the components through logical bit-wise operations to +// extract the parts needed, with the positions and masks derived from the +// layout shown above. +constexpr uint64_t kSignMask = 0x8000000000000000LL; +constexpr uint64_t kExponentMask = 0x7ff0000000000000LL; +constexpr int32_t kExponentShift = 52; +constexpr int32_t kExponentBias = 1023; +constexpr uint32_t kExponentIsBadNum = 0x7ff; +constexpr uint64_t kFractionMask = 0x000fffffffc00000LL; +constexpr uint32_t kFractionShift = 22; +constexpr uint32_t kFractionRoundingMask = 0x003fffff; +constexpr uint32_t kFractionRoundingThreshold = 0x00200000; +} // namespace + +void QuantizeMultiplier(double double_multiplier, int32_t *quantized_multiplier, + int *shift) +{ + if (double_multiplier == 0.) { + *quantized_multiplier = 0; + *shift = 0; + return; + } +#ifdef TFLITE_EMULATE_FLOAT + // If we're trying to avoid the use of floating-point instructions (for + // example on microcontrollers) then use an alternative implementation + // that only requires integer and bitwise operations. To enable this, you + // need to set the define during the build process for your platform. + int64_t q_fixed = IntegerFrExp(double_multiplier, shift); +#else // TFLITE_EMULATE_FLOAT + const double q = std::frexp(double_multiplier, shift); + auto q_fixed = static_cast(TfLiteRound(q * (1ll << 31))); +#endif // TFLITE_EMULATE_FLOAT + TFLITE_CHECK(q_fixed <= (1ll << 31)); + if (q_fixed == (1ll << 31)) { + q_fixed /= 2; + ++*shift; + } + TFLITE_CHECK_LE(q_fixed, std::numeric_limits::max()); + // A shift amount smaller than -31 would cause all bits to be shifted out + // and thus all results would be zero. We implement that instead with + // q_fixed==0, so as to avoid hitting issues with right-shift + // operations with shift amounts greater than 31. Note that this happens + // roughly when abs(double_multiplier) < 2^-31 and the present handling means + // that we're effectively flushing tiny double_multiplier's to zero. + // We could conceivably handle values in the range (roughly) [32, 63] + // as 'denormals' i.e. (shift==0, q_fixed < 2^30). In that point of view + // the present handling is just doing 'flush denormals to zero'. We could + // reconsider and actually generate nonzero denormals if a need arises. + if (*shift < -31) { + *shift = 0; + q_fixed = 0; + } + *quantized_multiplier = static_cast(q_fixed); +} + +void QuantizeMultiplierGreaterThanOne(double double_multiplier, + int32_t *quantized_multiplier, + int *left_shift) +{ + TFLITE_CHECK_GT(double_multiplier, 1.); + QuantizeMultiplier(double_multiplier, quantized_multiplier, left_shift); + TFLITE_CHECK_GE(*left_shift, 0); +} + +void QuantizeMultiplierSmallerThanOneExp(double double_multiplier, + int32_t *quantized_multiplier, + int *left_shift) +{ + TFLITE_CHECK_LT(double_multiplier, 1.); + TFLITE_CHECK_GT(double_multiplier, 0.); + int shift; + QuantizeMultiplier(double_multiplier, quantized_multiplier, &shift); + TFLITE_CHECK_LE(shift, 0); + *left_shift = shift; +} + +int64_t IntegerFrExp(double input, int *shift) +{ + // Make sure our assumptions about the double layout hold. + TFLITE_CHECK_EQ(8, sizeof(double)); + + // We want to access the bits of the input double value directly, which is + // tricky to do safely, so use a union to handle the casting. + union { + double double_value; + uint64_t double_as_uint; + } cast_union; + cast_union.double_value = input; + const uint64_t u = cast_union.double_as_uint; + + // If the bitfield is all zeros apart from the sign bit, this is a normalized + // zero value, so return standard values for this special case. + if ((u & ~kSignMask) == 0) { + *shift = 0; + return 0; + } + + // Deal with NaNs and Infs, which are always indicated with a fixed pattern in + // the exponent, and distinguished by whether the fractions are zero or + // non-zero. + const uint32_t exponent_part = ((u & kExponentMask) >> kExponentShift); + if (exponent_part == kExponentIsBadNum) { + *shift = std::numeric_limits::max(); + if (u & kFractionMask) { + // NaN, so just return zero (with the exponent set to INT_MAX). + return 0; + } else { + // Infinity, so return +/- INT_MAX. + if (u & kSignMask) { + return std::numeric_limits::min(); + } else { + return std::numeric_limits::max(); + } + } + } + + // The shift is fairly easy to extract from the high bits of the double value, + // just by masking it out and applying a bias. The std::frexp() implementation + // always returns values between 0.5 and 1.0 though, whereas the exponent + // assumes 1.0 to 2.0 is the standard range, so I add on one to match that + // interface. + *shift = (exponent_part - kExponentBias) + 1; + + // There's an implicit high bit in the double format definition, so make sure + // we include that at the top, and then reconstruct the rest of the fractional + // value from the remaining fragments. + int64_t fraction = 0x40000000 + ((u & kFractionMask) >> kFractionShift); + + // We're cutting off some bits at the bottom, so to exactly match the standard + // frexp implementation here we'll apply rounding by adding one to the least + // significant bit of the result if the discarded portion is over half of the + // maximum. + if ((u & kFractionRoundingMask) > kFractionRoundingThreshold) { + fraction += 1; + } + // Negate the fraction if the sign bit was set. + if (u & kSignMask) { + fraction *= -1; + } + + return fraction; +} + +double DoubleFromFractionAndShift(int64_t fraction, int shift) +{ + union { + double double_value; + uint64_t double_as_uint; + } result; + + // Detect NaNs and infinities. + if (shift == std::numeric_limits::max()) { + if (fraction == 0) { + return std::numeric_limits::quiet_NaN(); + } else if (fraction > 0) { + return std::numeric_limits::infinity(); + } else { + return -std::numeric_limits::infinity(); + } + } + + // Return a normalized zero for a zero fraction. + if (fraction == 0) { + result.double_as_uint = 0; + return result.double_value; + } + + bool is_negative = (fraction < 0); + int64_t encoded_fraction = is_negative ? -fraction : fraction; + int64_t encoded_shift = (shift - 1); + while (encoded_fraction < 0x40000000) { + encoded_fraction *= 2; + encoded_shift -= 1; + } + while (encoded_fraction > 0x80000000) { + encoded_fraction /= 2; + encoded_shift += 1; + } + encoded_fraction -= 0x40000000; + if (encoded_shift < -1022) { + encoded_shift = -1023; + } else if (encoded_shift > 1022) { + encoded_shift = 1023; + } + encoded_shift += kExponentBias; + uint64_t encoded_sign = is_negative ? kSignMask : 0; + result.double_as_uint = encoded_sign | (encoded_shift << kExponentShift) | + (encoded_fraction << kFractionShift); + return result.double_value; +} + +double IntegerDoubleMultiply(double a, double b) +{ + int a_shift; + const int64_t a_fraction = IntegerFrExp(a, &a_shift); + int b_shift; + const int64_t b_fraction = IntegerFrExp(b, &b_shift); + // Detect NaNs and infinities. + if (a_shift == std::numeric_limits::max() || + (b_shift == std::numeric_limits::max())) { + return std::numeric_limits::quiet_NaN(); + } + const int result_shift = a_shift + b_shift + 1; + const int64_t result_fraction = (a_fraction * b_fraction) >> 32; + return DoubleFromFractionAndShift(result_fraction, result_shift); +} + +int IntegerDoubleCompare(double a, double b) +{ + int a_shift; + const int64_t a_fraction = IntegerFrExp(a, &a_shift); + int b_shift; + const int64_t b_fraction = IntegerFrExp(b, &b_shift); + + // Detect NaNs and infinities. + if (a_shift == std::numeric_limits::max() || + (b_shift == std::numeric_limits::max())) { + return 1; + } + + if ((a_fraction == 0) && (b_fraction < 0)) { + return 1; + } else if ((a_fraction < 0) && (b_fraction == 0)) { + return -1; + } else if (a_shift < b_shift) { + return -1; + } else if (a_shift > b_shift) { + return 1; + } else if (a_fraction < b_fraction) { + return -1; + } else if (a_fraction > b_fraction) { + return 1; + } else { + return 0; + } +} + +void PreprocessSoftmaxScaling(double beta, double input_scale, + int input_integer_bits, + int32_t *quantized_multiplier, int *left_shift) +{ + // If the overall multiplier (input and beta) is large, then exp() of an + // input difference of 1 scaled by this will be large. In other words, we + // can cap the multiplier and know that, when it is used, the output will be + // (round to) zero wherever the input is not at the maximum value. + + // If the overall scale is less than one, and input_integer_bits=0, then the + // result is double equivalent of Q0.31 (actually with more precision). Thus + // this generates a Q(input_integer_bits).(31-input_integer_bits) + // representation. +#ifdef TFLITE_EMULATE_FLOAT + const double input_beta = IntegerDoubleMultiply(beta, input_scale); + int shift; + int64_t fraction = IntegerFrExp(input_beta, &shift); + shift += (31 - input_integer_bits); + double input_beta_real_multiplier = + DoubleFromFractionAndShift(fraction, shift); + if (IntegerDoubleCompare(input_beta_real_multiplier, (1ll << 31) - 1.0) > 0) { + input_beta_real_multiplier = (1ll << 31) - 1.0; + } +#else // TFLITE_EMULATE_FLOAT + const double input_beta_real_multiplier = std::min( + beta * input_scale * (1 << (31 - input_integer_bits)), (1ll << 31) - 1.0); +#endif // TFLITE_EMULATE_FLOAT + + QuantizeMultiplierGreaterThanOne(input_beta_real_multiplier, + quantized_multiplier, left_shift); +} + +void PreprocessLogSoftmaxScalingExp(double beta, double input_scale, + int input_integer_bits, + int32_t *quantized_multiplier, + int *left_shift, + int32_t *reverse_scaling_divisor, + int *reverse_scaling_left_shift) +{ + PreprocessSoftmaxScaling(beta, input_scale, input_integer_bits, + quantized_multiplier, left_shift); + + // Also calculate what amounts to the inverse scaling factor for the input. + const double real_reverse_scaling_divisor = + (1 << (31 - *left_shift)) / static_cast(*quantized_multiplier); + tflite::QuantizeMultiplierSmallerThanOneExp(real_reverse_scaling_divisor, + reverse_scaling_divisor, + reverse_scaling_left_shift); +} + +int CalculateInputRadius(int input_integer_bits, int input_left_shift, + int total_signed_bits) +{ +#ifdef TFLITE_EMULATE_FLOAT + int64_t result = (1 << input_integer_bits) - 1; + result <<= (total_signed_bits - input_integer_bits); + result >>= input_left_shift; + return result; +#else // TFLITE_EMULATE_FLOAT + const double max_input_rescaled = + 1.0 * ((1 << input_integer_bits) - 1) * + (1ll << (total_signed_bits - input_integer_bits)) / + (1ll << input_left_shift); + // Tighten bound using floor. Suppose that we could use the exact value. + // After scaling the difference, the result would be at the maximum. Thus we + // must ensure that our value has lower magnitude. + return static_cast(std::floor(max_input_rescaled)); +#endif // TFLITE_EMULATE_FLOAT +} + +void NudgeQuantizationRange(const float min, const float max, + const int quant_min, const int quant_max, + float *nudged_min, float *nudged_max, + float *nudged_scale) +{ + // This code originates from tensorflow/core/kernels/fake_quant_ops_functor.h. + const float quant_min_float = static_cast(quant_min); + const float quant_max_float = static_cast(quant_max); + *nudged_scale = (max - min) / (quant_max_float - quant_min_float); + const float zero_point_from_min = quant_min_float - min / *nudged_scale; + uint16_t nudged_zero_point; + if (zero_point_from_min < quant_min_float) { + nudged_zero_point = static_cast(quant_min); + } else if (zero_point_from_min > quant_max_float) { + nudged_zero_point = static_cast(quant_max); + } else { + nudged_zero_point = static_cast(TfLiteRound(zero_point_from_min)); + } + *nudged_min = (quant_min_float - nudged_zero_point) * (*nudged_scale); + *nudged_max = (quant_max_float - nudged_zero_point) * (*nudged_scale); +} + +void FakeQuantizeArray(const float nudged_scale, const float nudged_min, + const float nudged_max, const float *input_data, + float *output_data, const float size) +{ + // This code originates from tensorflow/core/kernels/fake_quant_ops_functor.h. + const float inv_nudged_scale = 1.0f / nudged_scale; + + for (int i = 0; i < size; i++) { + const float src_val = input_data[i]; + const float clamped = std::min(nudged_max, std::max(nudged_min, src_val)); + const float clamped_shifted = clamped - nudged_min; + const float dst_val = + TfLiteRound(clamped_shifted * inv_nudged_scale) * nudged_scale + + nudged_min; + output_data[i] = dst_val; + } +} + +bool CheckedLog2(const float x, int *log2_result) +{ + // Using TfLiteRound instead of std::round and std::log instead of + // std::log2 to work around these functions being missing in a toolchain + // used in some TensorFlow tests as of May 2018. + const float x_log2 = std::log(x) * (1.0f / std::log(2.0f)); + const float x_log2_rounded = TfLiteRound(x_log2); + const float x_log2_fracpart = x_log2 - x_log2_rounded; + + *log2_result = static_cast(x_log2_rounded); + return std::abs(x_log2_fracpart) < 1e-3f; +} + +void QuantizeMultiplierArray(const double *effective_scales, size_t size, + int32_t *effective_scale_significand, + int *effective_shift) +{ + for (size_t i = 0; i < size; ++i) { + QuantizeMultiplier(effective_scales[i], &effective_scale_significand[i], + &effective_shift[i]); + } +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/kernels/internal/quantization_util.h b/components/tflite/tensorflow/lite/kernels/internal/quantization_util.h new file mode 100644 index 00000000..27fc0e08 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/quantization_util.h @@ -0,0 +1,290 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_QUANTIZATION_UTIL_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_QUANTIZATION_UTIL_H_ + +#include +#include +#include + +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/kernels/internal/cppmath.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +// Given the min and max values of a float array, return +// reasonable quantization parameters to use for this array. +template +QuantizationParams ChooseQuantizationParams(double rmin, double rmax, + bool narrow_range) +{ + const T qmin = std::numeric_limits::min() + (narrow_range ? 1 : 0); + const T qmax = std::numeric_limits::max(); + const double qmin_double = qmin; + const double qmax_double = qmax; + // 0 should always be a representable value. Let's assume that the initial + // min,max range contains 0. + TFLITE_CHECK_LE(rmin, 0.); + TFLITE_CHECK_GE(rmax, 0.); + if (rmin == rmax) { + // Special case where the min,max range is a point. Should be {0}. + TFLITE_CHECK_EQ(rmin, 0.); + TFLITE_CHECK_EQ(rmax, 0.); + QuantizationParams quantization_params; + quantization_params.zero_point = 0; + quantization_params.scale = 0.; + return quantization_params; + } + + // General case. + // + // First determine the scale. + const double scale = (rmax - rmin) / (qmax_double - qmin_double); + + // Zero-point computation. + // First the initial floating-point computation. The zero-point can be + // determined from solving an affine equation for any known pair + // (real value, corresponding quantized value). + // We know two such pairs: (rmin, qmin) and (rmax, qmax). + // The arithmetic error on the zero point computed from either pair + // will be roughly machine_epsilon * (sum of absolute values of terms) + // so we want to use the variant that adds the smaller terms. + const double zero_point_from_min = qmin_double - rmin / scale; + const double zero_point_from_max = qmax_double - rmax / scale; + const double zero_point_from_min_error = + std::abs(qmin_double) + std::abs(rmin / scale); + const double zero_point_from_max_error = + std::abs(qmax_double) + std::abs(rmax / scale); + + const double zero_point_double = + zero_point_from_min_error < zero_point_from_max_error ? zero_point_from_min : zero_point_from_max; + + // Now we need to nudge the zero point to be an integer + // (our zero points are integer, and this is motivated by the requirement + // to be able to represent the real value "0" exactly as a quantized value, + // which is required in multiple places, for example in Im2col with SAME + // padding). + T nudged_zero_point = 0; + if (zero_point_double < qmin_double) { + nudged_zero_point = qmin; + } else if (zero_point_double > qmax_double) { + nudged_zero_point = qmax; + } else { + nudged_zero_point = static_cast(round(zero_point_double)); + } + // The zero point should always be in the range of quantized value, + // [qmin, qmax]. + TFLITE_CHECK_GE(nudged_zero_point, qmin); + TFLITE_CHECK_LE(nudged_zero_point, qmax); + + // Finally, store the result nudged quantization params. + QuantizationParams quantization_params; + quantization_params.zero_point = nudged_zero_point; + quantization_params.scale = scale; + return quantization_params; +} + +template +QuantizationParams ChooseQuantizationParams(double rmin, double rmax) +{ + return ChooseQuantizationParams(rmin, rmax, false); +} + +// Converts a floating-point number to an integer. For all inputs x where +// static_cast(x) is legal according to the C++ standard, the result +// is identical to that cast (i.e. the result is x with its fractional part +// truncated whenever that is representable as IntOut). +// +// static_cast would cause undefined behavior for the following cases, which +// have well-defined behavior for this function: +// +// 1. If x is NaN, the result is zero. +// +// 2. If the truncated form of x is above the representable range of IntOut, +// the result is std::numeric_limits::max(). +// +// 3. If the truncated form of x is below the representable range of IntOut, +// the result is std::numeric_limits::min(). +// +// Note that cases #2 and #3 cover infinities as well as finite numbers. +// +// The range of FloatIn must include the range of IntOut, otherwise +// the results are undefined. +// TODO(sfeuz): Replace by absl::SafeCast once available. +template +IntOut SafeCast(FloatIn x) +{ + static_assert(!std::numeric_limits::is_integer, + "FloatIn is integer"); + static_assert(std::numeric_limits::is_integer, + "IntOut is not integer"); + static_assert(std::numeric_limits::radix == 2, "IntOut is base 2"); + + // Special case NaN, for which the logic below doesn't work. + if (std::isnan(x)) { + return 0; + } + + // Negative values all clip to zero for unsigned results. + if (!std::numeric_limits::is_signed && x < 0) { + return 0; + } + + // Handle infinities. + if (std::isinf(x)) { + return x < 0 ? std::numeric_limits::min() : std::numeric_limits::max(); + } + + // Set exp such that x == f * 2^exp for some f with |f| in [0.5, 1.0), + // unless x is zero in which case exp == 0. Note that this implies that the + // magnitude of x is strictly less than 2^exp. + int exp = 0; + std::frexp(x, &exp); + + // Let N be the number of non-sign bits in the representation of IntOut. If + // the magnitude of x is strictly less than 2^N, the truncated version of x + // is representable as IntOut. The only representable integer for which this + // is not the case is kMin for signed types (i.e. -2^N), but that is covered + // by the fall-through below. + if (exp <= std::numeric_limits::digits) { + return x; + } + + // Handle numbers with magnitude >= 2^N. + return x < 0 ? std::numeric_limits::min() : std::numeric_limits::max(); +} + +// Decompose a double multiplier into a Q0.31 int32 representation of its +// significand, and shift representation of NEGATIVE its exponent --- +// this is intended as a RIGHT-shift. +// +// Restricted to the case where the multiplier < 1 (and non-negative). +void QuantizeMultiplierSmallerThanOneExp(double double_multiplier, + int32_t *quantized_multiplier, + int *left_shift); + +// Decompose a double multiplier into a Q0.31 int32 representation of its +// significand, and shift representation of its exponent. +// +// Restricted to the case where the multiplier > 1. +void QuantizeMultiplierGreaterThanOne(double double_multiplier, + int32_t *quantized_multiplier, + int *left_shift); + +// Decompose a double multiplier into a Q0.31 int32 representation of its +// significand, and shift representation of its exponent. +// +// Handles an arbitrary positive multiplier. The 'shift' output-value is +// basically the 'floating-point exponent' of the multiplier: +// Negative for a right-shift (when the multiplier is <1), positive for a +// left-shift (when the multiplier is >1) +void QuantizeMultiplier(double double_multiplier, int32_t *quantized_multiplier, + int *shift); + +// Splits a double input value into a returned fraction, and a shift value from +// the exponent, using only bitwise and integer operations to support +// microcontrollers and other environments without floating-point support. +// +// This is designed to be a replacement for how std::frexp() is used within the +// QuantizeMultiplier() function, and so has a different signature than the +// standard version, returning a 64-bit integer rather than a double. This +// result has a maximum value of 1<<31, with the fraction expressed as a +// proportion of that maximum. +// +// std::frexp() returns NaNs and infinities unmodified, but since we're +// returning integers that can't represent those values, instead we return +// a shift of std::numeric_limits::max() for all bad numbers, with an int64 +// result of 0 for NaNs, std:numeric_limits::max() for +INFINITY, and +// std::numeric_limits::min() for -INFINITY. Denormalized inputs will +// result in return values that end up truncating some bits at the end, +// reflecting the loss of precision inherent in denormalization. +int64_t IntegerFrExp(double input, int *shift); + +// Converts an integer fraction in the format produced by IntegerFrExp (where +// 0x40000000 is 1.0) and an exponent shift (between -1022 and +1022) into an +// IEEE binary64 double format result. The implementation uses only integer and +// bitwise operators, so no floating point hardware support or emulation is +// needed. This is here so quantized operations can run non-time-critical +// preparation calculations on microcontrollers and other platforms without +// float support. +double DoubleFromFractionAndShift(int64_t fraction, int shift); + +// Performs a multiplication of two numbers in double format, using only integer +// and bitwise instructions. This is aimed at supporting housekeeping functions +// for quantized operations on microcontrollers without floating-point hardware. +double IntegerDoubleMultiply(double a, double b); + +// Returns -1 if a is less than b, 0 if a and b are equal, and +1 if a is +// greater than b. It is implemented using only integer and logical instructions +// so that it can be easily run on microcontrollers for quantized operations. +int IntegerDoubleCompare(double a, double b); + +// This first creates a multiplier in a double equivalent of +// Q(input_integer_bits).(31-input_integer_bits) representation, with extra +// precision in the double's fractional bits. It then splits the result into +// significand and exponent. +void PreprocessSoftmaxScaling(double beta, double input_scale, + int input_integer_bits, + int32_t *quantized_multiplier, int *left_shift); +// Like PreprocessSoftmaxScaling, but inverse scaling factors also calculated. +void PreprocessLogSoftmaxScalingExp(double beta, double input_scale, + int input_integer_bits, + int32_t *quantized_multiplier, + int *left_shift, + int32_t *reverse_scaling_divisor, + int *reverse_scaling_left_shift); +// Calculate the largest input that will result in a within-bounds intermediate +// result within MultiplyByQuantizedMultiplierGreaterThanOne. In other words, +// it must not overflow before we reduce the value by multiplication by the +// input multiplier. The negative radius is used as the minimum difference in +// Softmax. +int CalculateInputRadius(int input_integer_bits, int input_left_shift, + int total_signed_bits = 31); + +// Nudges a min/max quantization range to ensure zero is zero. +// Gymnastics with nudged zero point is to ensure that real zero maps to +// an integer, which is required for e.g. zero-padding in convolutional layers. +// Outputs nudged_min, nudged_max, nudged_scale. +void NudgeQuantizationRange(const float min, const float max, + const int quant_min, const int quant_max, + float *nudged_min, float *nudged_max, + float *nudged_scale); + +// Fake quantizes (quantizes and dequantizes) input_data using the scale, +// nudged_min, and nudged_max from NudgeQuantizationRange. This matches the code +// in TensorFlow's FakeQuantizeWithMinMaxVarsFunctor. +void FakeQuantizeArray(const float nudged_scale, const float nudged_min, + const float nudged_max, const float *input_data, + float *output_data, const float size); + +// If x is approximately a power of two (with any positive or negative +// exponent), stores that exponent (i.e. log2(x)) in *log2_result, otherwise +// returns false. +bool CheckedLog2(const float x, int *log2_result); + +// Decomposes an array of double multipliers into a Q0.31 int32 representation +// of its significand, and shift representation of its exponent. +// +// Handles an arbitrary multiplier. The 'shift' output-value is +// basically the 'floating-point exponent' of the multiplier: +// Negative for a right-shift (when the multiplier is <1), positive for a +// left-shift (when the multiplier is >1) +void QuantizeMultiplierArray(const double *effective_scales, size_t size, + int32_t *effective_scale_significand, + int *effective_shift); + +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_QUANTIZATION_UTIL_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/add.h b/components/tflite/tensorflow/lite/kernels/internal/reference/add.h new file mode 100644 index 00000000..5adcfd1b --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/add.h @@ -0,0 +1,406 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ADD_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ADD_H_ + +#include + +#include "fixedpoint/fixedpoint.h" +#include "tensorflow/lite/kernels/internal/common.h" + +namespace tflite { +namespace reference_ops { +template +inline void Add(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, const T *input1_data, + const RuntimeShape &input2_shape, const T *input2_data, + const RuntimeShape &output_shape, T *output_data) +{ + T activation_min, activation_max; + GetActivationParams(params, &activation_min, &activation_max); + + const int flat_size = + MatchingElementsSize(input1_shape, input2_shape, output_shape); + for (int i = 0; i < flat_size; ++i) { + output_data[i] = ActivationFunctionWithMinMax( + input1_data[i] + input2_data[i], activation_min, activation_max); + } +} + +// Element-wise add that can often be used for inner loop of broadcast add as +// well as the non-broadcast add. + +// This function is used for 8-bit as well as for 16-bit, but the accumulator +// is 32-bit for both cases. The overflow does not happen due to the +// choice of the shift (20 or 15, accordingly - see add.cc for more comments). +template +inline void AddElementwise(int size, const ArithmeticParams ¶ms, + const T *input1_data, const T *input2_data, + T *output_data) +{ + TFLITE_DCHECK_GT(params.input1_offset, -std::numeric_limits::max()); + TFLITE_DCHECK_GT(params.input2_offset, -std::numeric_limits::max()); + TFLITE_DCHECK_LT(params.input1_offset, std::numeric_limits::max()); + TFLITE_DCHECK_LT(params.input2_offset, std::numeric_limits::max()); + + for (int i = 0; i < size; ++i) { + const int32_t input1_val = params.input1_offset + input1_data[i]; + const int32_t input2_val = params.input2_offset + input2_data[i]; + const int32_t shifted_input1_val = input1_val * (1 << params.left_shift); + const int32_t shifted_input2_val = input2_val * (1 << params.left_shift); + const int32_t scaled_input1_val = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + shifted_input1_val, params.input1_multiplier, params.input1_shift); + const int32_t scaled_input2_val = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + shifted_input2_val, params.input2_multiplier, params.input2_shift); + const int32_t raw_sum = scaled_input1_val + scaled_input2_val; + const int32_t raw_output = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + raw_sum, params.output_multiplier, params.output_shift) + + params.output_offset; + const int32_t clamped_output = + std::min(params.quantized_activation_max, + std::max(params.quantized_activation_min, raw_output)); + output_data[i] = static_cast(clamped_output); + } +} + +// Scalar-broadcast add that can be used for inner loop of more general +// broadcast add, so that, for example, scalar-broadcast with batch will still +// be fast. +inline void AddScalarBroadcast(int size, const ArithmeticParams ¶ms, + uint8_t input1_data, const uint8_t *input2_data, + uint8_t *output_data) +{ + TFLITE_DCHECK_GT(params.input1_offset, -256); + TFLITE_DCHECK_GT(params.input2_offset, -256); + TFLITE_DCHECK_LT(params.input1_offset, 256); + TFLITE_DCHECK_LT(params.input2_offset, 256); + + const int32_t input1_val = params.input1_offset + input1_data; + const int32_t shifted_input1_val = input1_val * (1 << params.left_shift); + const int32_t scaled_input1_val = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + shifted_input1_val, params.input1_multiplier, params.input1_shift); + for (int i = 0; i < size; ++i) { + const int32_t input2_val = params.input2_offset + input2_data[i]; + const int32_t shifted_input2_val = input2_val * (1 << params.left_shift); + const int32_t scaled_input2_val = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + shifted_input2_val, params.input2_multiplier, params.input2_shift); + const int32_t raw_sum = scaled_input1_val + scaled_input2_val; + const int32_t raw_output = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + raw_sum, params.output_multiplier, params.output_shift) + + params.output_offset; + const int32_t clamped_output = + std::min(params.quantized_activation_max, + std::max(params.quantized_activation_min, raw_output)); + output_data[i] = static_cast(clamped_output); + } +} + +inline void Add(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, const uint8_t *input1_data, + const RuntimeShape &input2_shape, const uint8_t *input2_data, + const RuntimeShape &output_shape, uint8_t *output_data) +{ + TFLITE_DCHECK_LE(params.quantized_activation_min, + params.quantized_activation_max); + const int flat_size = + MatchingElementsSize(input1_shape, input2_shape, output_shape); + + TFLITE_DCHECK_GT(params.input1_offset, -256); + TFLITE_DCHECK_GT(params.input2_offset, -256); + TFLITE_DCHECK_LT(params.input1_offset, 256); + TFLITE_DCHECK_LT(params.input2_offset, 256); + AddElementwise(flat_size, params, input1_data, input2_data, output_data); +} + +inline void AddGeneralParamScale(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, + const int16_t *input1_data, + const RuntimeShape &input2_shape, + const int16_t *input2_data, + const RuntimeShape &output_shape, + int16_t *output_data) +{ + TFLITE_DCHECK_LE(params.quantized_activation_min, + params.quantized_activation_max); + const int flat_size = + MatchingElementsSize(input1_shape, input2_shape, output_shape); + + int max_value = std::numeric_limits::max(); + + TFLITE_DCHECK_GT(params.input1_offset, -max_value); + TFLITE_DCHECK_GT(params.input2_offset, -max_value); + TFLITE_DCHECK_LT(params.input1_offset, max_value); + TFLITE_DCHECK_LT(params.input2_offset, max_value); + AddElementwise(flat_size, params, input1_data, input2_data, output_data); +} + +inline void Add(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, const int16_t *input1_data, + const RuntimeShape &input2_shape, const int16_t *input2_data, + const RuntimeShape &output_shape, int16_t *output_data, + bool pot_scale = true) +{ + if (!pot_scale) { + AddGeneralParamScale(params, input1_shape, input1_data, input2_shape, + input2_data, output_shape, output_data); + return; + } + + TFLITE_DCHECK_LE(params.quantized_activation_min, + params.quantized_activation_max); + + const int input1_shift = params.input1_shift; + const int flat_size = + MatchingElementsSize(input1_shape, input2_shape, output_shape); + const int16_t output_activation_min = params.quantized_activation_min; + const int16_t output_activation_max = params.quantized_activation_max; + + TFLITE_DCHECK(input1_shift == 0 || params.input2_shift == 0); + TFLITE_DCHECK_LE(input1_shift, 0); + TFLITE_DCHECK_LE(params.input2_shift, 0); + const int16_t *not_shift_input = + input1_shift == 0 ? input1_data : input2_data; + const int16_t *shift_input = input1_shift == 0 ? input2_data : input1_data; + const int input_right_shift = + input1_shift == 0 ? -params.input2_shift : -input1_shift; + + for (int i = 0; i < flat_size; i++) { + // F0 uses 0 integer bits, range [-1, 1]. + using F0 = gemmlowp::FixedPoint; + + F0 input_ready_scaled = F0::FromRaw(not_shift_input[i]); + F0 scaled_input = F0::FromRaw( + gemmlowp::RoundingDivideByPOT(shift_input[i], input_right_shift)); + F0 result = gemmlowp::SaturatingAdd(scaled_input, input_ready_scaled); + const int16_t raw_output = result.raw(); + const int16_t clamped_output = std::min( + output_activation_max, std::max(output_activation_min, raw_output)); + output_data[i] = clamped_output; + } +} + +template +inline typename std::enable_if::value, void>::type +BroadcastAdd4DSlow(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, const T *input1_data, + const RuntimeShape &input2_shape, const T *input2_data, + const RuntimeShape &output_shape, T *output_data) +{ + NdArrayDesc<4> desc1; + NdArrayDesc<4> desc2; + NdArrayDescsForElementwiseBroadcast(input1_shape, input2_shape, &desc1, + &desc2); + const RuntimeShape extended_output_shape = + RuntimeShape::ExtendedShape(4, output_shape); + + T activation_min, activation_max; + GetActivationParams(params, &activation_min, &activation_max); + + // In Tensorflow, the dimensions are canonically named (batch_number, row, + // col, channel), with extents (batches, height, width, depth), with the + // trailing dimension changing most rapidly (channels has the smallest stride, + // typically 1 element). + // + // In generated C code, we store arrays with the dimensions reversed. The + // first dimension has smallest stride. + // + // We name our variables by their Tensorflow convention, but generate C code + // nesting loops such that the innermost loop has the smallest stride for the + // best cache behavior. + for (int b = 0; b < extended_output_shape.Dims(0); ++b) { + for (int y = 0; y < extended_output_shape.Dims(1); ++y) { + for (int x = 0; x < extended_output_shape.Dims(2); ++x) { + for (int c = 0; c < extended_output_shape.Dims(3); ++c) { + output_data[Offset(extended_output_shape, b, y, x, c)] = + ActivationFunctionWithMinMax( + input1_data[SubscriptToIndex(desc1, b, y, x, c)] + + input2_data[SubscriptToIndex(desc2, b, y, x, c)], + activation_min, activation_max); + } + } + } + } +} + +// This function is used for 8-bit as well as for 16-bit, but the accumulator +// is 32-bit for both cases. The overflow does not happen due to the +// choice of the shift (20 or 15, accordingly - see add.cc for more comments). +template +inline typename std::enable_if::value, void>::type +BroadcastAdd4DSlow(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, const T *input1_data, + const RuntimeShape &input2_shape, const T *input2_data, + const RuntimeShape &output_shape, T *output_data) +{ + NdArrayDesc<4> desc1; + NdArrayDesc<4> desc2; + NdArrayDescsForElementwiseBroadcast(input1_shape, input2_shape, &desc1, + &desc2); + const RuntimeShape extended_output_shape = + RuntimeShape::ExtendedShape(4, output_shape); + + // In Tensorflow, the dimensions are canonically named (batch_number, row, + // col, channel), with extents (batches, height, width, depth), with the + // trailing dimension changing most rapidly (channels has the smallest stride, + // typically 1 element). + // + // In generated C code, we store arrays with the dimensions reversed. The + // first dimension has smallest stride. + // + // We name our variables by their Tensorflow convention, but generate C code + // nesting loops such that the innermost loop has the smallest stride for the + // best cache behavior. + for (int b = 0; b < extended_output_shape.Dims(0); ++b) { + for (int y = 0; y < extended_output_shape.Dims(1); ++y) { + for (int x = 0; x < extended_output_shape.Dims(2); ++x) { + for (int c = 0; c < extended_output_shape.Dims(3); ++c) { + const int32_t input1_val = + params.input1_offset + + input1_data[SubscriptToIndex(desc1, b, y, x, c)]; + const int32_t input2_val = + params.input2_offset + + input2_data[SubscriptToIndex(desc2, b, y, x, c)]; + const int32_t shifted_input1_val = + input1_val * (1 << params.left_shift); + const int32_t shifted_input2_val = + input2_val * (1 << params.left_shift); + const int32_t scaled_input1_val = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + shifted_input1_val, params.input1_multiplier, + params.input1_shift); + const int32_t scaled_input2_val = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + shifted_input2_val, params.input2_multiplier, + params.input2_shift); + const int32_t raw_sum = scaled_input1_val + scaled_input2_val; + const int32_t raw_output = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + raw_sum, params.output_multiplier, params.output_shift) + + params.output_offset; + const int32_t clamped_output = + std::min(params.quantized_activation_max, + std::max(params.quantized_activation_min, raw_output)); + output_data[Offset(extended_output_shape, b, y, x, c)] = + static_cast(clamped_output); + } + } + } + } +} + +inline void BroadcastAddFivefold(const ArithmeticParams &unswitched_params, + const RuntimeShape &unswitched_input1_shape, + const uint8_t *unswitched_input1_data, + const RuntimeShape &unswitched_input2_shape, + const uint8_t *unswitched_input2_data, + const RuntimeShape &output_shape, + uint8_t *output_data) +{ + ArithmeticParams switched_params = unswitched_params; + switched_params.input1_offset = unswitched_params.input2_offset; + switched_params.input1_multiplier = unswitched_params.input2_multiplier; + switched_params.input1_shift = unswitched_params.input2_shift; + switched_params.input2_offset = unswitched_params.input1_offset; + switched_params.input2_multiplier = unswitched_params.input1_multiplier; + switched_params.input2_shift = unswitched_params.input1_shift; + + const bool use_unswitched = + unswitched_params.broadcast_category == + tflite::BroadcastableOpCategory::kFirstInputBroadcastsFast; + + const ArithmeticParams ¶ms = + use_unswitched ? unswitched_params : switched_params; + const uint8_t *input1_data = + use_unswitched ? unswitched_input1_data : unswitched_input2_data; + const uint8_t *input2_data = + use_unswitched ? unswitched_input2_data : unswitched_input1_data; + + // Fivefold nested loops. The second input resets its position for each + // iteration of the second loop. The first input resets its position at the + // beginning of the fourth loop. The innermost loop is an elementwise add of + // sections of the arrays. + uint8_t *output_data_ptr = output_data; + const uint8_t *input1_data_ptr = input1_data; + const uint8_t *input2_data_reset = input2_data; + // In the fivefold pattern, y0, y2 and y4 are not broadcast, and so shared + // between input shapes. y3 for input 1 is always broadcast, and so the + // dimension there is 1, whereas optionally y1 might be broadcast for input 2. + // Put another way, + // input1.shape.FlatSize = y0 * y1 * y2 * y4, + // input2.shape.FlatSize = y0 * y2 * y3 * y4. + int y0 = params.broadcast_shape[0]; + int y1 = params.broadcast_shape[1]; + int y2 = params.broadcast_shape[2]; + int y3 = params.broadcast_shape[3]; + int y4 = params.broadcast_shape[4]; + if (y4 > 1) { + // General fivefold pattern, with y4 > 1 so there is a non-broadcast inner + // dimension. + for (int i0 = 0; i0 < y0; ++i0) { + const uint8_t *input2_data_ptr; + for (int i1 = 0; i1 < y1; ++i1) { + input2_data_ptr = input2_data_reset; + for (int i2 = 0; i2 < y2; ++i2) { + for (int i3 = 0; i3 < y3; ++i3) { + AddElementwise(y4, params, input1_data_ptr, input2_data_ptr, + output_data_ptr); + input2_data_ptr += y4; + output_data_ptr += y4; + } + // We have broadcast y4 of input1 data y3 times, and now move on. + input1_data_ptr += y4; + } + } + // We have broadcast y2*y3*y4 of input2 data y1 times, and now move on. + input2_data_reset = input2_data_ptr; + } + } else { + // Special case of y4 == 1, in which the innermost loop is a single element + // and can be combined with the next (y3) as an inner broadcast. + // + // Note that this handles the case of pure scalar broadcast when + // y0 == y1 == y2 == 1. With low overhead it handles cases such as scalar + // broadcast with batch (as y2 > 1). + // + // NOTE The process is the same as the above general case except simplified + // for y4 == 1 and the loop over y3 is contained within the + // AddScalarBroadcast function. + for (int i0 = 0; i0 < y0; ++i0) { + const uint8_t *input2_data_ptr; + for (int i1 = 0; i1 < y1; ++i1) { + input2_data_ptr = input2_data_reset; + for (int i2 = 0; i2 < y2; ++i2) { + AddScalarBroadcast(y3, params, *input1_data_ptr, input2_data_ptr, + output_data_ptr); + input2_data_ptr += y3; + output_data_ptr += y3; + input1_data_ptr += 1; + } + } + input2_data_reset = input2_data_ptr; + } + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ADD_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/add_n.h b/components/tflite/tensorflow/lite/kernels/internal/reference/add_n.h new file mode 100644 index 00000000..881d784f --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/add_n.h @@ -0,0 +1,87 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ADD_N_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ADD_N_H_ + +#include +#include + +#include "tensorflow/lite/kernels/internal/common.h" + +namespace tflite { +namespace reference_ops { +// T is expected to be either float or int. +template +inline void AddN(const RuntimeShape &input_shape, const size_t num_inputs, + const T *const *input_data, T *output_data) +{ + // All inputs and output should have the same shape, this is checked during + // Prepare stage. + const size_t size = input_shape.FlatSize(); + for (size_t i = 0; i < size; ++i) { + T x = 0; + for (size_t j = 0; j < num_inputs; ++j) { + x += input_data[j][i]; + } + output_data[i] = x; + } +} + +inline void AddN(const ArithmeticParams ¶ms, + const RuntimeShape &input_shape, const size_t num_inputs, + const int8_t *const *input_data, int8_t *output_data) +{ + TFLITE_DCHECK_LE(params.quantized_activation_min, + params.quantized_activation_max); + // Input offset is negative input zero point. Activation tensors are + // asymmetric quantized so they span the full int8 range. + // All inputs should have same zero-point and scale, this is checked during + // Prepare stage. + TFLITE_DCHECK_GE(-params.input1_offset, std::numeric_limits::min()); + TFLITE_DCHECK_LE(-params.input1_offset, std::numeric_limits::max()); + + // All inputs and output should have the same shape, this is checked during + // Prepare stage. + const size_t size = input_shape.FlatSize(); + for (size_t i = 0; i < size; ++i) { + // accumulate in scaled_x before clamping to avoid overflow + const int32_t x = params.input1_offset; // x = 0 + const int32_t shifted_x = x * (1 << params.left_shift); + int32_t scaled_x = MultiplyByQuantizedMultiplierSmallerThanOneExp( + shifted_x, params.input1_multiplier, params.input1_shift); + + for (size_t j = 0; j < num_inputs; ++j) { + const int32_t y = params.input1_offset + input_data[j][i]; + const int32_t shifted_y = y * (1 << params.left_shift); + int32_t scaled_y = MultiplyByQuantizedMultiplierSmallerThanOneExp( + shifted_y, params.input1_multiplier, params.input1_shift); + scaled_x += scaled_y; + } + + const int32_t raw_output = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + scaled_x, params.output_multiplier, params.output_shift) + + params.output_offset; + const int32_t clamped_output = + std::min(params.quantized_activation_max, + std::max(params.quantized_activation_min, raw_output)); + output_data[i] = static_cast(clamped_output); + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ADD_N_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/arg_min_max.h b/components/tflite/tensorflow/lite/kernels/internal/reference/arg_min_max.h new file mode 100644 index 00000000..070e719d --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/arg_min_max.h @@ -0,0 +1,89 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ARG_MIN_MAX_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ARG_MIN_MAX_H_ + +#include + +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +template +std::function GetComparefunction(bool is_arg_max) +{ + if (is_arg_max) { + return std::greater(); + } else { + return std::less(); + } +} + +template +void ArgMinMax(const RuntimeShape &input1_shape, const T1 *input1_data, + const T3 *input2_data, const RuntimeShape &output_shape, + T2 *output_data, const Cmp &cmp) +{ + TFLITE_DCHECK_GT(input1_shape.DimensionsCount(), 0); + TFLITE_DCHECK_EQ(input1_shape.DimensionsCount() - 1, + output_shape.DimensionsCount()); + int axis = input2_data[0]; + if (axis < 0) { + axis += input1_shape.DimensionsCount(); + } + const int axis_size = input1_shape.Dims(axis); + + int outer_size = 1; + for (int i = 0; i < axis; ++i) { + TFLITE_DCHECK_EQ(input1_shape.Dims(i), output_shape.Dims(i)); + outer_size *= input1_shape.Dims(i); + } + + int inner_size = 1; + const int dims_count = input1_shape.DimensionsCount(); + for (int i = axis + 1; i < dims_count; ++i) { + TFLITE_DCHECK_EQ(input1_shape.Dims(i), output_shape.Dims(i - 1)); + inner_size *= input1_shape.Dims(i); + } + for (int outer = 0; outer < outer_size; ++outer) { + for (int inner = 0; inner < inner_size; ++inner) { + auto min_max_value = input1_data[outer * axis_size * inner_size + inner]; + T2 min_max_index = 0; + for (int i = 1; i < axis_size; ++i) { + const auto &curr_value = + input1_data[(outer * axis_size + i) * inner_size + inner]; + if (cmp(curr_value, min_max_value)) { + min_max_value = curr_value; + min_max_index = static_cast(i); + } + } + output_data[outer * inner_size + inner] = min_max_index; + } + } +} + +template +void ArgMinMax(const RuntimeShape &input1_shape, const T1 *input1_data, + const T3 *input2_data, const RuntimeShape &output_shape, + T2 *output_data, const bool is_arg_max) +{ + ArgMinMax(input1_shape, input1_data, input2_data, output_shape, output_data, + GetComparefunction(is_arg_max)); +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ARG_MIN_MAX_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/batch_matmul.h b/components/tflite/tensorflow/lite/kernels/internal/reference/batch_matmul.h new file mode 100644 index 00000000..1014c1db --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/batch_matmul.h @@ -0,0 +1,281 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BATCH_MATMUL_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BATCH_MATMUL_H_ + +#include +#include + +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/kernels/internal/tensor_utils_common.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +namespace batch_matmul { +// Determine which dimension is the broadcast dimension. +inline int broadcast_dim(int lhs_dim, int rhs_dim) +{ + if (lhs_dim == rhs_dim) + return lhs_dim; + if (lhs_dim == 1) + return rhs_dim; + TFLITE_DCHECK_EQ(rhs_dim, 1); + return lhs_dim; +} + +// Compute the "extent" for iterating on this dimension. +// If we are broadcasting, then don't advance (i.e return 0). +inline int extent(const RuntimeShape &shape, int x) +{ + if (shape.Dims(x) == 1) { + return 0; + } + int prod = 1; + for (int i = x + 1; i < shape.DimensionsCount(); ++i) { + prod *= shape.Dims(i); + } + return prod; +} + +} // namespace batch_matmul + +template +inline void BatchMatMul(const RuntimeShape &lhs_shape, const Ta *lhs_data, + const RuntimeShape &rhs_shape, const Tb *rhs_data, + const RuntimeShape &output_shape, Tout *output_data) +{ + const RuntimeShape extended_lhs_shape = + RuntimeShape::ExtendedShape(5, lhs_shape); + const RuntimeShape extended_rhs_shape = + RuntimeShape::ExtendedShape(5, rhs_shape); + + const int batch_dim0 = batch_matmul::broadcast_dim( + extended_lhs_shape.Dims(0), extended_rhs_shape.Dims(0)); + const int batch_dim1 = batch_matmul::broadcast_dim( + extended_lhs_shape.Dims(1), extended_rhs_shape.Dims(1)); + const int batch_dim2 = batch_matmul::broadcast_dim( + extended_lhs_shape.Dims(2), extended_rhs_shape.Dims(2)); + + const int lhs_ext0 = batch_matmul::extent(extended_lhs_shape, 0); + const int lhs_ext1 = batch_matmul::extent(extended_lhs_shape, 1); + const int lhs_ext2 = batch_matmul::extent(extended_lhs_shape, 2); + const int rhs_ext0 = batch_matmul::extent(extended_rhs_shape, 0); + const int rhs_ext1 = batch_matmul::extent(extended_rhs_shape, 1); + const int rhs_ext2 = batch_matmul::extent(extended_rhs_shape, 2); + + // Set params for each matrix multiply. + const int lhs_rows = extended_lhs_shape.Dims(3); + const int rhs_cols = extended_rhs_shape.Dims(4); + const int accum_depth = extended_lhs_shape.Dims(4); + + for (int b0 = 0; b0 < batch_dim0; ++b0) { + const Ta *lhs_ptr0 = lhs_data + (b0 * lhs_ext0); + const Tb *rhs_ptr0 = rhs_data + (b0 * rhs_ext0); + for (int b1 = 0; b1 < batch_dim1; ++b1) { + const Ta *lhs_ptr1 = lhs_ptr0 + b1 * lhs_ext1; + const Tb *rhs_ptr1 = rhs_ptr0 + b1 * rhs_ext1; + for (int b2 = 0; b2 < batch_dim2; ++b2) { + const Ta *lhs_ptr2 = lhs_ptr1 + b2 * lhs_ext2; + const Tb *rhs_ptr2 = rhs_ptr1 + b2 * rhs_ext2; + Tout *out_ptr = output_data + ((b0 * batch_dim1 * batch_dim2) + + b1 * batch_dim2 + b2) * + lhs_rows * rhs_cols; + for (int j = 0; j < rhs_cols; ++j) { + for (int i = 0; i < lhs_rows; ++i) { + Tout total = 0; + for (int k = 0; k < accum_depth; ++k) { + total += static_cast(lhs_ptr2[accum_depth * i + k]) * + static_cast(rhs_ptr2[j * accum_depth + k]); + } + int idx = lhs_rows * j + i; + out_ptr[idx] = total; + } + } + } + } + } +} + +inline void BatchMatMul(const RuntimeShape &lhs_shape, const int8_t *lhs_data, + const RuntimeShape &rhs_shape, const int8_t *rhs_data, + const float *scaling_factors, + const int32_t *input_offset, int32_t *row_sums, + const RuntimeShape &output_shape, float *output_data, + bool *compute_row_sums) +{ + const RuntimeShape extended_lhs_shape = + RuntimeShape::ExtendedShape(5, lhs_shape); + const RuntimeShape extended_rhs_shape = + RuntimeShape::ExtendedShape(5, rhs_shape); + + const int batch_dim0 = batch_matmul::broadcast_dim( + extended_lhs_shape.Dims(0), extended_rhs_shape.Dims(0)); + const int batch_dim1 = batch_matmul::broadcast_dim( + extended_lhs_shape.Dims(1), extended_rhs_shape.Dims(1)); + const int batch_dim2 = batch_matmul::broadcast_dim( + extended_lhs_shape.Dims(2), extended_rhs_shape.Dims(2)); + + const int lhs_ext0 = batch_matmul::extent(extended_lhs_shape, 0); + const int lhs_ext1 = batch_matmul::extent(extended_lhs_shape, 1); + const int lhs_ext2 = batch_matmul::extent(extended_lhs_shape, 2); + const int rhs_ext0 = batch_matmul::extent(extended_rhs_shape, 0); + const int rhs_ext1 = batch_matmul::extent(extended_rhs_shape, 1); + const int rhs_ext2 = batch_matmul::extent(extended_rhs_shape, 2); + + // Set params for each matrix multiply. + const int lhs_rows = extended_lhs_shape.Dims(3); + const int rhs_cols = extended_rhs_shape.Dims(4); + const int accum_depth = extended_lhs_shape.Dims(4); + + const int ioff_ext0 = rhs_ext0 == 0 ? 0 : rhs_cols; + const int ioff_ext1 = rhs_ext1 == 0 ? 0 : rhs_cols; + const int ioff_ext2 = rhs_ext2 == 0 ? 0 : rhs_cols; + const int woff_ext0 = lhs_ext0 == 0 ? 0 : lhs_rows; + const int woff_ext1 = lhs_ext1 == 0 ? 0 : lhs_rows; + const int woff_ext2 = lhs_ext2 == 0 ? 0 : lhs_rows; + + if (!compute_row_sums || *compute_row_sums) { + int num_weights_matrices = 1; + for (int i = 1; i < extended_lhs_shape.DimensionsCount() - 2; ++i) { + num_weights_matrices *= extended_lhs_shape.Dims(i); + } + tensor_utils::ReductionSumVector( + lhs_data, row_sums, num_weights_matrices * lhs_rows, accum_depth); + if (compute_row_sums) { + *compute_row_sums = false; + } + } + + for (int b0 = 0; b0 < batch_dim0; ++b0) { + const int8_t *lhs_ptr0 = lhs_data + (b0 * lhs_ext0); + const int8_t *rhs_ptr0 = rhs_data + (b0 * rhs_ext0); + const int32_t *ioff_ptr0 = input_offset + (b0 * ioff_ext0); + const float *scale_ptr0 = scaling_factors + (b0 * ioff_ext0); + const int32_t *woff_ptr0 = row_sums + (b0 * woff_ext0); + for (int b1 = 0; b1 < batch_dim1; ++b1) { + const int8_t *lhs_ptr1 = lhs_ptr0 + b1 * lhs_ext1; + const int8_t *rhs_ptr1 = rhs_ptr0 + b1 * rhs_ext1; + const int32_t *ioff_ptr1 = ioff_ptr0 + (b1 * ioff_ext1); + const float *scale_ptr1 = scale_ptr0 + (b1 * ioff_ext1); + const int32_t *woff_ptr1 = woff_ptr0 + (b1 * woff_ext1); + for (int b2 = 0; b2 < batch_dim2; ++b2) { + const int8_t *lhs_ptr2 = lhs_ptr1 + b2 * lhs_ext2; + const int8_t *rhs_ptr2 = rhs_ptr1 + b2 * rhs_ext2; + const int32_t *ioff_ptr2 = ioff_ptr1 + (b2 * ioff_ext2); + const float *scale_ptr2 = scale_ptr1 + (b2 * ioff_ext2); + const int32_t *woff_ptr2 = woff_ptr1 + (b2 * woff_ext2); + float *out_ptr = output_data + ((b0 * batch_dim1 * batch_dim2) + + b1 * batch_dim2 + b2) * + lhs_rows * rhs_cols; + for (int j = 0; j < rhs_cols; ++j) { + const float batch_scaling_factor = scale_ptr2[j]; + const float batch_offset = static_cast(ioff_ptr2[j]); + for (int i = 0; i < lhs_rows; ++i) { + int32_t total = 0; + for (int k = 0; k < accum_depth; ++k) { + total += + lhs_ptr2[accum_depth * i + k] * rhs_ptr2[j * accum_depth + k]; + } + int32_t row_sum = woff_ptr2[i]; + total -= row_sum * batch_offset; + int idx = lhs_rows * j + i; + out_ptr[idx] += batch_scaling_factor * total; + } + } + } + } + } +} + +template +inline void BatchMatMul(const FullyConnectedParams ¶ms, + const RuntimeShape &lhs_shape, const T *lhs_data, + const RuntimeShape &rhs_shape, const T *rhs_data, + const RuntimeShape &output_shape, T *output_data) +{ + const RuntimeShape extended_lhs_shape = + RuntimeShape::ExtendedShape(5, lhs_shape); + const RuntimeShape extended_rhs_shape = + RuntimeShape::ExtendedShape(5, rhs_shape); + + const int batch_dim0 = batch_matmul::broadcast_dim( + extended_lhs_shape.Dims(0), extended_rhs_shape.Dims(0)); + const int batch_dim1 = batch_matmul::broadcast_dim( + extended_lhs_shape.Dims(1), extended_rhs_shape.Dims(1)); + const int batch_dim2 = batch_matmul::broadcast_dim( + extended_lhs_shape.Dims(2), extended_rhs_shape.Dims(2)); + + const int lhs_ext0 = batch_matmul::extent(extended_lhs_shape, 0); + const int lhs_ext1 = batch_matmul::extent(extended_lhs_shape, 1); + const int lhs_ext2 = batch_matmul::extent(extended_lhs_shape, 2); + const int rhs_ext0 = batch_matmul::extent(extended_rhs_shape, 0); + const int rhs_ext1 = batch_matmul::extent(extended_rhs_shape, 1); + const int rhs_ext2 = batch_matmul::extent(extended_rhs_shape, 2); + + // Set params for each matrix multiply. + const int lhs_rows = extended_lhs_shape.Dims(3); + const int rhs_cols = extended_rhs_shape.Dims(4); + const int accum_depth = extended_lhs_shape.Dims(4); + + const int32_t input_offset = params.input_offset; + const int32_t filter_offset = params.weights_offset; + const int32_t output_offset = params.output_offset; + const int32_t output_multiplier = params.output_multiplier; + const int output_shift = params.output_shift; + const int32_t output_activation_min = params.quantized_activation_min; + const int32_t output_activation_max = params.quantized_activation_max; + TFLITE_DCHECK_LE(output_activation_min, output_activation_max); + + for (int b0 = 0; b0 < batch_dim0; ++b0) { + const T *lhs_ptr0 = lhs_data + (b0 * lhs_ext0); + const T *rhs_ptr0 = rhs_data + (b0 * rhs_ext0); + for (int b1 = 0; b1 < batch_dim1; ++b1) { + const T *lhs_ptr1 = lhs_ptr0 + b1 * lhs_ext1; + const T *rhs_ptr1 = rhs_ptr0 + b1 * rhs_ext1; + for (int b2 = 0; b2 < batch_dim2; ++b2) { + const T *lhs_ptr2 = lhs_ptr1 + b2 * lhs_ext2; + const T *rhs_ptr2 = rhs_ptr1 + b2 * rhs_ext2; + T *out_ptr = output_data + + ((b0 * batch_dim1 * batch_dim2) + b1 * batch_dim2 + b2) * + lhs_rows * rhs_cols; + + for (int j = 0; j < rhs_cols; ++j) { + for (int i = 0; i < lhs_rows; ++i) { + AccumT total = 0; + for (int k = 0; k < accum_depth; ++k) { + AccumT lhs_val = lhs_ptr2[accum_depth * i + k]; + AccumT rhs_val = rhs_ptr2[accum_depth * j + k]; + total += (lhs_val + filter_offset) * (rhs_val + input_offset); + } + int32_t total_scaled = MultiplyByQuantizedMultiplier( + total, output_multiplier, output_shift); + total_scaled += output_offset; + total_scaled = std::max(total_scaled, output_activation_min); + total_scaled = std::min(total_scaled, output_activation_max); + const int idx = lhs_rows * j + i; + out_ptr[idx] = static_cast(total_scaled); + } + } + } + } + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BATCH_MATMUL_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/batch_to_space_nd.h b/components/tflite/tensorflow/lite/kernels/internal/reference/batch_to_space_nd.h new file mode 100644 index 00000000..f3a14e8b --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/batch_to_space_nd.h @@ -0,0 +1,102 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BATCH_TO_SPACE_ND_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BATCH_TO_SPACE_ND_H_ + +#include + +#include "ruy/profiler/instrumentation.h" // from @ruy +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +// TODO(b/135760455): Move this method anonymous namespace in a cc file. +inline RuntimeShape ExtendShapeBatchToSpace(const RuntimeShape &shape) +{ + if (shape.DimensionsCount() == 4) { + return shape; + } + RuntimeShape new_shape(4, 1); + new_shape.SetDim(0, shape.Dims(0)); + new_shape.SetDim(1, shape.Dims(1)); + new_shape.SetDim(3, shape.Dims(2)); + return new_shape; +} + +template +inline void BatchToSpaceND(const RuntimeShape &unextended_input1_shape, + const T *input1_data, + const RuntimeShape &unextended_input2_shape, + const int32_t *block_shape_data, + const RuntimeShape &unextended_input3_shape, + const int32_t *crops_data, + const RuntimeShape &unextended_output_shape, + T *output_data) +{ + ruy::profiler::ScopeLabel label("BatchToSpaceND"); + TFLITE_DCHECK_GE(unextended_input1_shape.DimensionsCount(), 3); + TFLITE_DCHECK_LE(unextended_input1_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(unextended_input1_shape.DimensionsCount(), + unextended_output_shape.DimensionsCount()); + + const RuntimeShape input1_shape = + ExtendShapeBatchToSpace(unextended_input1_shape); + const RuntimeShape output_shape = + ExtendShapeBatchToSpace(unextended_output_shape); + + const int output_width = output_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_batch_size = output_shape.Dims(0); + + const int depth = input1_shape.Dims(3); + const int input_width = input1_shape.Dims(2); + const int input_height = input1_shape.Dims(1); + const int input_batch_size = input1_shape.Dims(0); + + const int block_shape_height = block_shape_data[0]; + const int block_shape_width = + unextended_input1_shape.DimensionsCount() == 4 ? block_shape_data[1] : 1; + const int crops_top = crops_data[0]; + const int crops_left = + unextended_input1_shape.DimensionsCount() == 4 ? crops_data[2] : 0; + for (int in_batch = 0; in_batch < input_batch_size; ++in_batch) { + const int out_batch = in_batch % output_batch_size; + const int spatial_offset = in_batch / output_batch_size; + for (int in_h = 0; in_h < input_height; ++in_h) { + const int out_h = in_h * block_shape_height + + spatial_offset / block_shape_width - crops_top; + if (out_h < 0 || out_h >= output_height) { + continue; + } + for (int in_w = 0; in_w < input_width; ++in_w) { + const int out_w = in_w * block_shape_width + + spatial_offset % block_shape_width - crops_left; + + if (out_w < 0 || out_w >= output_width) { + continue; + } + T *out = output_data + Offset(output_shape, out_batch, out_h, out_w, 0); + const T *in = + input1_data + Offset(input1_shape, in_batch, in_h, in_w, 0); + memcpy(out, in, depth * sizeof(T)); + } + } + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BATCH_TO_SPACE_ND_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/binary_function.h b/components/tflite/tensorflow/lite/kernels/internal/reference/binary_function.h new file mode 100644 index 00000000..4141e59d --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/binary_function.h @@ -0,0 +1,80 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BINARY_FUNCTION_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BINARY_FUNCTION_H_ + +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +// Also appears to duplicate MinimumMaximum. +// +// R: Result type. T1: Input 1 type. T2: Input 2 type. +template +inline void BroadcastBinaryFunction4DSlow( + const RuntimeShape &unextended_input1_shape, const T1 *input1_data, + const RuntimeShape &unextended_input2_shape, const T2 *input2_data, + const RuntimeShape &unextended_output_shape, R *output_data, + R (*func)(T1, T2)) +{ + TFLITE_DCHECK_LE(unextended_input1_shape.DimensionsCount(), 4); + TFLITE_DCHECK_LE(unextended_input2_shape.DimensionsCount(), 4); + TFLITE_DCHECK_LE(unextended_output_shape.DimensionsCount(), 4); + const RuntimeShape output_shape = + RuntimeShape::ExtendedShape(4, unextended_output_shape); + + NdArrayDesc<4> desc1; + NdArrayDesc<4> desc2; + NdArrayDescsForElementwiseBroadcast(unextended_input1_shape, + unextended_input2_shape, &desc1, &desc2); + + for (int b = 0; b < output_shape.Dims(0); ++b) { + for (int y = 0; y < output_shape.Dims(1); ++y) { + for (int x = 0; x < output_shape.Dims(2); ++x) { + for (int c = 0; c < output_shape.Dims(3); ++c) { + auto out_idx = Offset(output_shape, b, y, x, c); + auto in1_idx = SubscriptToIndex(desc1, b, y, x, c); + auto in2_idx = SubscriptToIndex(desc2, b, y, x, c); + auto in1_val = input1_data[in1_idx]; + auto in2_val = input2_data[in2_idx]; + output_data[out_idx] = func(in1_val, in2_val); + } + } + } + } +} + +// R: Result type. T1: Input 1 type. T2: Input 2 type. +template +inline void BinaryFunction(const RuntimeShape &input1_shape, + const T1 *input1_data, + const RuntimeShape &input2_shape, + const T2 *input2_data, + const RuntimeShape &output_shape, R *output_data, + R (*func)(T1, T2)) +{ + const int flat_size = + MatchingFlatSize(input1_shape, input2_shape, output_shape); + for (int i = 0; i < flat_size; ++i) { + output_data[i] = func(input1_data[i], input2_data[i]); + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BINARY_FUNCTION_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/ceil.h b/components/tflite/tensorflow/lite/kernels/internal/reference/ceil.h new file mode 100644 index 00000000..e4e55094 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/ceil.h @@ -0,0 +1,36 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CEIL_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CEIL_H_ + +#include + +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +inline void Ceil(const RuntimeShape &input_shape, const float *input_data, + const RuntimeShape &output_shape, float *output_data) +{ + const int flat_size = MatchingFlatSize(input_shape, output_shape); + + for (int i = 0; i < flat_size; ++i) { + output_data[i] = std::ceil(input_data[i]); + } +} + +} // namespace reference_ops +} // namespace tflite +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CEIL_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/comparisons.h b/components/tflite/tensorflow/lite/kernels/internal/reference/comparisons.h new file mode 100644 index 00000000..5023b36c --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/comparisons.h @@ -0,0 +1,297 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_COMPARISONS_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_COMPARISONS_H_ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +template +inline bool EqualFn(T lhs, T rhs) +{ + return lhs == rhs; +} + +template +inline bool NotEqualFn(T lhs, T rhs) +{ + return lhs != rhs; +} + +template +inline bool GreaterFn(T lhs, T rhs) +{ + return lhs > rhs; +} +template +inline bool GreaterEqualFn(T lhs, T rhs) +{ + return lhs >= rhs; +} +template +inline bool LessFn(T lhs, T rhs) +{ + return lhs < rhs; +} +template +inline bool LessEqualFn(T lhs, T rhs) +{ + return lhs <= rhs; +} + +template +using ComparisonFn = bool (*)(T, T); + +template F> +inline void ComparisonImpl( + const ComparisonParams &op_params, const RuntimeShape &input1_shape, + const T *input1_data, const RuntimeShape &input2_shape, + const T *input2_data, const RuntimeShape &output_shape, bool *output_data) +{ + const int64_t flatsize = + MatchingFlatSize(input1_shape, input2_shape, output_shape); + for (int64_t i = 0; i < flatsize; ++i) { + output_data[i] = F(input1_data[i], input2_data[i]); + } +} + +template F> +inline void Comparison(const ComparisonParams &op_params, + const RuntimeShape &input1_shape, + const float *input1_data, + const RuntimeShape &input2_shape, + const float *input2_data, + const RuntimeShape &output_shape, bool *output_data) +{ + ComparisonImpl(op_params, input1_shape, input1_data, input2_shape, + input2_data, output_shape, output_data); +} + +template F> +inline void ComparisonWithScaling( + const ComparisonParams &op_params, const RuntimeShape &input1_shape, + const T *input1_data, const RuntimeShape &input2_shape, + const T *input2_data, const RuntimeShape &output_shape, bool *output_data) +{ + int left_shift = op_params.left_shift; + int32_t input1_offset = op_params.input1_offset; + int32_t input1_multiplier = op_params.input1_multiplier; + int input1_shift = op_params.input1_shift; + int32_t input2_offset = op_params.input2_offset; + int32_t input2_multiplier = op_params.input2_multiplier; + int input2_shift = op_params.input2_shift; + + const int64_t flatsize = + MatchingFlatSize(input1_shape, input2_shape, output_shape); + for (int64_t i = 0; i < flatsize; ++i) { + const int32_t input1_val = input1_offset + input1_data[i]; + const int32_t input2_val = input2_offset + input2_data[i]; + const int32_t shifted_input1_val = input1_val * (1 << left_shift); + const int32_t shifted_input2_val = input2_val * (1 << left_shift); + const int32_t scaled_input1_val = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + shifted_input1_val, input1_multiplier, input1_shift); + const int32_t scaled_input2_val = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + shifted_input2_val, input2_multiplier, input2_shift); + output_data[i] = F(scaled_input1_val, scaled_input2_val); + } +} + +struct BroadcastComparison4DSlowCommon { + const RuntimeShape output_shape; + NdArrayDesc<4> desc1; + NdArrayDesc<4> desc2; +}; + +inline BroadcastComparison4DSlowCommon BroadcastComparison4DSlowPreprocess( + const RuntimeShape &unextended_input1_shape, + const RuntimeShape &unextended_input2_shape, + const RuntimeShape &unextended_output_shape) +{ + TFLITE_DCHECK_LE(unextended_input1_shape.DimensionsCount(), 4); + TFLITE_DCHECK_LE(unextended_input2_shape.DimensionsCount(), 4); + TFLITE_DCHECK_LE(unextended_output_shape.DimensionsCount(), 4); + NdArrayDesc<4> desc1; + NdArrayDesc<4> desc2; + NdArrayDescsForElementwiseBroadcast(unextended_input1_shape, + unextended_input2_shape, &desc1, &desc2); + return { RuntimeShape::ExtendedShape(4, unextended_output_shape), desc1, + desc2 }; +} + +template F> +inline void BroadcastComparison4DSlowImpl( + const ComparisonParams &op_params, + const RuntimeShape &unextended_input1_shape, const T *input1_data, + const RuntimeShape &unextended_input2_shape, const T *input2_data, + const RuntimeShape &unextended_output_shape, bool *output_data) +{ + const BroadcastComparison4DSlowCommon dims = + BroadcastComparison4DSlowPreprocess(unextended_input1_shape, + unextended_input2_shape, + unextended_output_shape); + + for (int b = 0; b < dims.output_shape.Dims(0); ++b) { + for (int y = 0; y < dims.output_shape.Dims(1); ++y) { + for (int x = 0; x < dims.output_shape.Dims(2); ++x) { + for (int c = 0; c < dims.output_shape.Dims(3); ++c) { + output_data[Offset(dims.output_shape, b, y, x, c)] = + F(input1_data[SubscriptToIndex(dims.desc1, b, y, x, c)], + input2_data[SubscriptToIndex(dims.desc2, b, y, x, c)]); + } + } + } + } +} + +template F> +inline void BroadcastComparison4DSlow(const ComparisonParams &op_params, + const RuntimeShape &input1_shape, + const float *input1_data, + const RuntimeShape &input2_shape, + const float *input2_data, + const RuntimeShape &output_shape, + bool *output_data) +{ + BroadcastComparison4DSlowImpl(op_params, input1_shape, input1_data, + input2_shape, input2_data, + output_shape, output_data); +} + +template F> +inline void BroadcastComparison4DSlowWithScaling( + const ComparisonParams &op_params, + const RuntimeShape &unextended_input1_shape, const T *input1_data, + const RuntimeShape &unextended_input2_shape, const T *input2_data, + const RuntimeShape &unextended_output_shape, bool *output_data) +{ + const BroadcastComparison4DSlowCommon dims = + BroadcastComparison4DSlowPreprocess(unextended_input1_shape, + unextended_input2_shape, + unextended_output_shape); + + int left_shift = op_params.left_shift; + int32_t input1_offset = op_params.input1_offset; + int32_t input1_multiplier = op_params.input1_multiplier; + int input1_shift = op_params.input1_shift; + int32_t input2_offset = op_params.input2_offset; + int32_t input2_multiplier = op_params.input2_multiplier; + int input2_shift = op_params.input2_shift; + + for (int b = 0; b < dims.output_shape.Dims(0); ++b) { + for (int y = 0; y < dims.output_shape.Dims(1); ++y) { + for (int x = 0; x < dims.output_shape.Dims(2); ++x) { + for (int c = 0; c < dims.output_shape.Dims(3); ++c) { + const int32_t input1_val = + input1_offset + + input1_data[SubscriptToIndex(dims.desc1, b, y, x, c)]; + const int32_t input2_val = + input2_offset + + input2_data[SubscriptToIndex(dims.desc2, b, y, x, c)]; + const int32_t shifted_input1_val = input1_val * (1 << left_shift); + const int32_t shifted_input2_val = input2_val * (1 << left_shift); + const int32_t scaled_input1_val = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + shifted_input1_val, input1_multiplier, input1_shift); + const int32_t scaled_input2_val = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + shifted_input2_val, input2_multiplier, input2_shift); + output_data[Offset(dims.output_shape, b, y, x, c)] = + F(scaled_input1_val, scaled_input2_val); + } + } + } + } +} + +#define TFLITE_COMPARISON_OP(name) \ + inline void name(const ComparisonParams &op_params, \ + const RuntimeShape &input1_shape, const float *input1_data, \ + const RuntimeShape &input2_shape, const float *input2_data, \ + const RuntimeShape &output_shape, bool *output_data) \ + { \ + Comparison(op_params, input1_shape, input1_data, input2_shape, \ + input2_data, output_shape, output_data); \ + } \ + template \ + inline void name##NoScaling( \ + const ComparisonParams &op_params, const RuntimeShape &input1_shape, \ + const T *input1_data, const RuntimeShape &input2_shape, \ + const T *input2_data, const RuntimeShape &output_shape, \ + bool *output_data) \ + { \ + ComparisonImpl(op_params, input1_shape, input1_data, \ + input2_shape, input2_data, output_shape, \ + output_data); \ + } \ + template \ + inline void name##WithScaling( \ + const ComparisonParams &op_params, const RuntimeShape &input1_shape, \ + const T *input1_data, const RuntimeShape &input2_shape, \ + const T *input2_data, const RuntimeShape &output_shape, \ + bool *output_data) \ + { \ + ComparisonWithScaling(op_params, input1_shape, input1_data, \ + input2_shape, input2_data, \ + output_shape, output_data); \ + } \ + template \ + inline void Broadcast4DSlow##name##NoScaling( \ + const ComparisonParams &op_params, const RuntimeShape &input1_shape, \ + const T *input1_data, const RuntimeShape &input2_shape, \ + const T *input2_data, const RuntimeShape &output_shape, \ + bool *output_data) \ + { \ + BroadcastComparison4DSlowImpl( \ + op_params, input1_shape, input1_data, input2_shape, input2_data, \ + output_shape, output_data); \ + } \ + inline void Broadcast4DSlow##name( \ + const ComparisonParams &op_params, const RuntimeShape &input1_shape, \ + const float *input1_data, const RuntimeShape &input2_shape, \ + const float *input2_data, const RuntimeShape &output_shape, \ + bool *output_data) \ + { \ + BroadcastComparison4DSlow(op_params, input1_shape, input1_data, \ + input2_shape, input2_data, \ + output_shape, output_data); \ + } \ + template \ + inline void Broadcast4DSlow##name##WithScaling( \ + const ComparisonParams &op_params, const RuntimeShape &input1_shape, \ + const T *input1_data, const RuntimeShape &input2_shape, \ + const T *input2_data, const RuntimeShape &output_shape, \ + bool *output_data) \ + { \ + BroadcastComparison4DSlowWithScaling( \ + op_params, input1_shape, input1_data, input2_shape, input2_data, \ + output_shape, output_data); \ + } +TFLITE_COMPARISON_OP(Equal); +TFLITE_COMPARISON_OP(NotEqual); +TFLITE_COMPARISON_OP(Greater); +TFLITE_COMPARISON_OP(GreaterEqual); +TFLITE_COMPARISON_OP(Less); +TFLITE_COMPARISON_OP(LessEqual); +#undef TFLITE_COMPARISON_OP + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_COMPARISONS_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/concatenation.h b/components/tflite/tensorflow/lite/kernels/internal/reference/concatenation.h new file mode 100644 index 00000000..3b119137 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/concatenation.h @@ -0,0 +1,140 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CONCATENATION_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CONCATENATION_H_ + +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/kernels/internal/cppmath.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +template +inline void Concatenation(const ConcatenationParams ¶ms, + const RuntimeShape *const *input_shapes, + const Scalar *const *input_data, + const RuntimeShape &output_shape, + Scalar *output_data) +{ + int axis = params.axis; + int inputs_count = params.inputs_count; + const int concat_dimensions = output_shape.DimensionsCount(); + TFLITE_DCHECK_LT(axis, concat_dimensions); + + int64_t concat_size = 0; + for (int i = 0; i < inputs_count; i++) { + TFLITE_DCHECK_EQ(input_shapes[i]->DimensionsCount(), concat_dimensions); + for (int j = 0; j < concat_dimensions; j++) { + if (j != axis) { + MatchingDim(*input_shapes[i], j, output_shape, j); + } + } + concat_size += input_shapes[i]->Dims(axis); + } + TFLITE_DCHECK_EQ(concat_size, output_shape.Dims(axis)); + int64_t outer_size = 1; + for (int i = 0; i < axis; ++i) { + outer_size *= output_shape.Dims(i); + } + // For all input arrays, + // FlatSize() = outer_size * Dims(axis) * base_inner_size; + int64_t base_inner_size = 1; + for (int i = axis + 1; i < concat_dimensions; ++i) { + base_inner_size *= output_shape.Dims(i); + } + + Scalar *output_ptr = output_data; + for (int k = 0; k < outer_size; k++) { + for (int i = 0; i < inputs_count; ++i) { + const int copy_size = input_shapes[i]->Dims(axis) * base_inner_size; + const Scalar *input_ptr = input_data[i] + k * copy_size; + memcpy(output_ptr, input_ptr, copy_size * sizeof(Scalar)); + output_ptr += copy_size; + } + } +} + +// TODO(b/174275780): The quantized implementation of concatentation isn't fully +// quantized as it takes scale as a floating point value. This should be fixed +// when optimizng this routine further. +inline void ConcatenationWithScaling(const ConcatenationParams ¶ms, + const RuntimeShape *const *input_shapes, + const uint8_t *const *input_data, + const RuntimeShape &output_shape, + uint8_t *output_data) +{ + int axis = params.axis; + const int32_t *input_zeropoint = params.input_zeropoint; + const float *input_scale = params.input_scale; + int inputs_count = params.inputs_count; + const int32_t output_zeropoint = params.output_zeropoint; + const float output_scale = params.output_scale; + + const int concat_dimensions = output_shape.DimensionsCount(); + TFLITE_DCHECK_LT(axis, concat_dimensions); + + int64_t concat_size = 0; + for (int i = 0; i < inputs_count; i++) { + TFLITE_DCHECK_EQ(input_shapes[i]->DimensionsCount(), concat_dimensions); + for (int j = 0; j < concat_dimensions; j++) { + if (j != axis) { + MatchingDim(*input_shapes[i], j, output_shape, j); + } + } + concat_size += input_shapes[i]->Dims(axis); + } + TFLITE_DCHECK_EQ(concat_size, output_shape.Dims(axis)); + int64_t outer_size = 1; + for (int i = 0; i < axis; ++i) { + outer_size *= output_shape.Dims(i); + } + // For all input arrays, + // FlatSize() = outer_size * Dims(axis) * base_inner_size; + int64_t base_inner_size = 1; + for (int i = axis + 1; i < concat_dimensions; ++i) { + base_inner_size *= output_shape.Dims(i); + } + + const float inverse_output_scale = 1.f / output_scale; + uint8_t *output_ptr = output_data; + for (int k = 0; k < outer_size; k++) { + for (int i = 0; i < inputs_count; ++i) { + const int copy_size = input_shapes[i]->Dims(axis) * base_inner_size; + const uint8_t *input_ptr = input_data[i] + k * copy_size; + if (input_zeropoint[i] == output_zeropoint && + input_scale[i] == output_scale) { + memcpy(output_ptr, input_ptr, copy_size); + } else { + const float scale = input_scale[i] * inverse_output_scale; + const float bias = -input_zeropoint[i] * scale; + for (int j = 0; j < copy_size; ++j) { + const int32_t value = static_cast(tflite::TfLiteRound( + input_ptr[j] * scale + bias)) + + output_zeropoint; + output_ptr[j] = static_cast( + std::max(std::min(255, value), 0)); + } + } + output_ptr += copy_size; + } + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CONCATENATION_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/conv.h b/components/tflite/tensorflow/lite/kernels/internal/reference/conv.h new file mode 100644 index 00000000..0fe12ccf --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/conv.h @@ -0,0 +1,265 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CONV_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CONV_H_ + +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +inline void Conv(const ConvParams ¶ms, const RuntimeShape &input_shape, + const float *input_data, const RuntimeShape &filter_shape, + const float *filter_data, const RuntimeShape &bias_shape, + const float *bias_data, const RuntimeShape &output_shape, + float *output_data, const RuntimeShape &im2col_shape, + float *im2col_data) +{ + const int stride_width = params.stride_width; + const int stride_height = params.stride_height; + const int dilation_width_factor = params.dilation_width_factor; + const int dilation_height_factor = params.dilation_height_factor; + const int pad_width = params.padding_values.width; + const int pad_height = params.padding_values.height; + const float output_activation_min = params.float_activation_min; + const float output_activation_max = params.float_activation_max; + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + + (void)im2col_data; // only used in optimized code. + (void)im2col_shape; // only used in optimized code. + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int input_depth = MatchingDim(input_shape, 3, filter_shape, 3); + const int output_depth = MatchingDim(filter_shape, 0, output_shape, 3); + if (bias_data) { + TFLITE_DCHECK_EQ(bias_shape.FlatSize(), output_depth); + } + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int filter_height = filter_shape.Dims(1); + const int filter_width = filter_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + for (int batch = 0; batch < batches; ++batch) { + for (int out_y = 0; out_y < output_height; ++out_y) { + const int in_y_origin = (out_y * stride_height) - pad_height; + for (int out_x = 0; out_x < output_width; ++out_x) { + const int in_x_origin = (out_x * stride_width) - pad_width; + for (int out_channel = 0; out_channel < output_depth; ++out_channel) { + float total = 0.f; + for (int filter_y = 0; filter_y < filter_height; ++filter_y) { + const int in_y = in_y_origin + dilation_height_factor * filter_y; + for (int filter_x = 0; filter_x < filter_width; ++filter_x) { + const int in_x = in_x_origin + dilation_width_factor * filter_x; + + // Zero padding by omitting the areas outside the image. + const bool is_point_inside_image = + (in_x >= 0) && (in_x < input_width) && (in_y >= 0) && + (in_y < input_height); + + if (!is_point_inside_image) { + continue; + } + + for (int in_channel = 0; in_channel < input_depth; ++in_channel) { + float input_value = input_data[Offset(input_shape, batch, in_y, + in_x, in_channel)]; + float filter_value = filter_data[Offset( + filter_shape, out_channel, filter_y, filter_x, in_channel)]; + total += (input_value * filter_value); + } + } + } + float bias_value = 0.0f; + if (bias_data) { + bias_value = bias_data[out_channel]; + } + output_data[Offset(output_shape, batch, out_y, out_x, out_channel)] = + ActivationFunctionWithMinMax(total + bias_value, + output_activation_min, + output_activation_max); + } + } + } + } +} + +inline void Conv(const ConvParams ¶ms, const RuntimeShape &input_shape, + const uint8_t *input_data, const RuntimeShape &filter_shape, + const uint8_t *filter_data, const RuntimeShape &bias_shape, + const int32_t *bias_data, const RuntimeShape &output_shape, + uint8_t *output_data, const RuntimeShape &im2col_shape, + uint8_t *im2col_data, void *cpu_backend_context) +{ + (void)cpu_backend_context; // only used in optimized code. + (void)im2col_data; // only used in optimized code. + (void)im2col_shape; // only used in optimized code. + const int stride_width = params.stride_width; + const int stride_height = params.stride_height; + const int dilation_width_factor = params.dilation_width_factor; + const int dilation_height_factor = params.dilation_height_factor; + const int pad_width = params.padding_values.width; + const int pad_height = params.padding_values.height; + const int32_t input_offset = params.input_offset; + const int32_t filter_offset = params.weights_offset; + const int32_t output_offset = params.output_offset; + const int32_t output_multiplier = params.output_multiplier; + const int output_shift = params.output_shift; + const int32_t output_activation_min = params.quantized_activation_min; + const int32_t output_activation_max = params.quantized_activation_max; + TFLITE_DCHECK_LE(output_activation_min, output_activation_max); + + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int input_depth = MatchingDim(input_shape, 3, filter_shape, 3); + const int output_depth = MatchingDim(filter_shape, 0, output_shape, 3); + if (bias_data) { + TFLITE_DCHECK_EQ(bias_shape.FlatSize(), output_depth); + } + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int filter_height = filter_shape.Dims(1); + const int filter_width = filter_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + for (int batch = 0; batch < batches; ++batch) { + for (int out_y = 0; out_y < output_height; ++out_y) { + const int in_y_origin = (out_y * stride_height) - pad_height; + for (int out_x = 0; out_x < output_width; ++out_x) { + const int in_x_origin = (out_x * stride_width) - pad_width; + for (int out_channel = 0; out_channel < output_depth; ++out_channel) { + int32_t acc = 0; + for (int filter_y = 0; filter_y < filter_height; ++filter_y) { + const int in_y = in_y_origin + dilation_height_factor * filter_y; + for (int filter_x = 0; filter_x < filter_width; ++filter_x) { + const int in_x = in_x_origin + dilation_width_factor * filter_x; + + // Zero padding by omitting the areas outside the image. + const bool is_point_inside_image = + (in_x >= 0) && (in_x < input_width) && (in_y >= 0) && + (in_y < input_height); + + if (!is_point_inside_image) { + continue; + } + + for (int in_channel = 0; in_channel < input_depth; ++in_channel) { + int32_t input_val = input_data[Offset(input_shape, batch, in_y, + in_x, in_channel)]; + int32_t filter_val = filter_data[Offset( + filter_shape, out_channel, filter_y, filter_x, in_channel)]; + acc += + (filter_val + filter_offset) * (input_val + input_offset); + } + } + } + if (bias_data) { + acc += bias_data[out_channel]; + } + acc = MultiplyByQuantizedMultiplier(acc, output_multiplier, + output_shift); + acc += output_offset; + acc = std::max(acc, output_activation_min); + acc = std::min(acc, output_activation_max); + output_data[Offset(output_shape, batch, out_y, out_x, out_channel)] = + static_cast(acc); + } + } + } + } +} + +inline void HybridConvPerChannel( + const ConvParams ¶ms, float *scaling_factors_ptr, + const RuntimeShape &input_shape, const int8_t *input_data, + const RuntimeShape &filter_shape, const int8_t *filter_data, + const RuntimeShape &bias_shape, const float *bias_data, + const RuntimeShape &output_shape, float *output_data, + const RuntimeShape &im2col_shape, int8_t *im2col_data, + const float *per_channel_scale, int32_t *input_offset) +{ + (void)im2col_data; // only used in optimized code. + (void)im2col_shape; // only used in optimized code. + const int stride_width = params.stride_width; + const int stride_height = params.stride_height; + const int dilation_width_factor = params.dilation_width_factor; + const int dilation_height_factor = params.dilation_height_factor; + const int pad_width = params.padding_values.width; + const int pad_height = params.padding_values.height; + const float output_activation_min = params.float_activation_min; + const float output_activation_max = params.float_activation_max; + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int input_depth = MatchingDim(input_shape, 3, filter_shape, 3); + const int output_depth = MatchingDim(filter_shape, 0, output_shape, 3); + if (bias_data) { + TFLITE_DCHECK_EQ(bias_shape.FlatSize(), output_depth); + } + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int filter_height = filter_shape.Dims(1); + const int filter_width = filter_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + for (int batch = 0; batch < batches; ++batch) { + for (int out_y = 0; out_y < output_height; ++out_y) { + for (int out_x = 0; out_x < output_width; ++out_x) { + for (int out_channel = 0; out_channel < output_depth; ++out_channel) { + const int in_x_origin = (out_x * stride_width) - pad_width; + const int in_y_origin = (out_y * stride_height) - pad_height; + int32_t acc = 0; + for (int filter_y = 0; filter_y < filter_height; ++filter_y) { + for (int filter_x = 0; filter_x < filter_width; ++filter_x) { + for (int in_channel = 0; in_channel < input_depth; ++in_channel) { + const int in_x = in_x_origin + dilation_width_factor * filter_x; + const int in_y = + in_y_origin + dilation_height_factor * filter_y; + // If the location is outside the bounds of the input image, + // use zero as a default value. + if ((in_x >= 0) && (in_x < input_width) && (in_y >= 0) && + (in_y < input_height)) { + int32_t input_val = input_data[Offset( + input_shape, batch, in_y, in_x, in_channel)]; + int32_t filter_val = + filter_data[Offset(filter_shape, out_channel, filter_y, + filter_x, in_channel)]; + acc += filter_val * (input_val - input_offset[batch]); + } + } + } + } + float acc_float = + acc * per_channel_scale[out_channel] * scaling_factors_ptr[batch]; + if (bias_data) { + acc_float += bias_data[out_channel]; + } + output_data[Offset(output_shape, batch, out_y, out_x, out_channel)] = + ActivationFunctionWithMinMax(acc_float, output_activation_min, + output_activation_max); + } + } + } + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CONV_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/cumsum.h b/components/tflite/tensorflow/lite/kernels/internal/reference/cumsum.h new file mode 100644 index 00000000..4f29ce2c --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/cumsum.h @@ -0,0 +1,176 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CUMSUM_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CUMSUM_H_ + +#include +#include +#include + +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/compatibility.h" + +namespace tflite { +namespace reference_ops { +template +inline void CumSum(const T *input_data, const RuntimeShape &shape, int32_t axis, + bool exclusive, bool reverse, T *output_data) +{ + const int32_t rank = shape.DimensionsCount(); + TFLITE_DCHECK_GE(rank, 1); + TFLITE_DCHECK_GE(axis, 0); + TFLITE_DCHECK_LT(axis, rank); + + size_t inner = 1; + size_t outer = 1; + size_t depth = 1; + for (int32_t i = 0; i < rank; i++) { + if (i < axis) + inner *= shape.Dims(i); + else if (i > axis) + outer *= shape.Dims(i); + else + depth = shape.Dims(i); + } + + for (size_t outer_index = 0; outer_index < outer; outer_index++) { + size_t outer_index_adj; + if (reverse) + outer_index_adj = (outer - 1) - outer_index; + else + outer_index_adj = outer_index; + for (size_t inner_index = 0; inner_index < inner; inner_index++) { + T accumulator = 0; + size_t inner_index_adj; + if (reverse) + inner_index_adj = (inner - 1) - inner_index; + else + inner_index_adj = inner_index; + for (size_t depth_index = 0; depth_index < depth; depth_index++) { + size_t depth_index_adj; + if (reverse) + depth_index_adj = (depth - 1) - depth_index; + else + depth_index_adj = depth_index; + + size_t index = outer_index_adj; + index += inner_index_adj * depth * outer; + index += depth_index_adj * outer; + + if (exclusive) { + output_data[index] = accumulator; + accumulator += input_data[index]; + } else { + accumulator += input_data[index]; + output_data[index] = accumulator; + } + } + } + } +} + +// +// Quantized INT8 CUMSUM +// +inline void CumSum(const ArithmeticParams ¶ms, const int8_t *input_data, + const RuntimeShape &shape, int32_t axis, bool exclusive, + bool reverse, int8_t *output_data) +{ + TFLITE_DCHECK_LE(params.quantized_activation_min, + params.quantized_activation_max); + // Input offset is negative input zero point. Activation tensors are + // asymmetric quantized so they span the full int8 range. + // All inputs should have same zero-point and scale, this is checked during + // Prepare stage. + TFLITE_DCHECK_GE(-params.input1_offset, std::numeric_limits::min()); + TFLITE_DCHECK_LE(-params.input1_offset, std::numeric_limits::max()); + + const int32_t rank = shape.DimensionsCount(); + TFLITE_DCHECK_GE(rank, 1); + TFLITE_DCHECK_GE(axis, 0); + TFLITE_DCHECK_LT(axis, rank); + + size_t inner = 1; + size_t outer = 1; + size_t depth = 1; + for (int32_t i = 0; i < rank; i++) { + if (i < axis) + inner *= shape.Dims(i); + else if (i > axis) + outer *= shape.Dims(i); + else + depth = shape.Dims(i); + } + + for (size_t outer_index = 0; outer_index < outer; outer_index++) { + size_t outer_index_adj; + if (reverse) + outer_index_adj = (outer - 1) - outer_index; + else + outer_index_adj = outer_index; + for (size_t inner_index = 0; inner_index < inner; inner_index++) { + int32_t accumulator = params.input1_offset; // accumulator = 0 + accumulator *= (1 << params.left_shift); + accumulator = MultiplyByQuantizedMultiplierSmallerThanOneExp( + accumulator, params.input1_multiplier, params.input1_shift); + + size_t inner_index_adj; + if (reverse) + inner_index_adj = (inner - 1) - inner_index; + else + inner_index_adj = inner_index; + + for (size_t depth_index = 0; depth_index < depth; depth_index++) { + size_t depth_index_adj; + if (reverse) + depth_index_adj = (depth - 1) - depth_index; + else + depth_index_adj = depth_index; + + size_t index = outer_index_adj; + index += inner_index_adj * depth * outer; + index += depth_index_adj * outer; + + const int32_t y = params.input1_offset + input_data[index]; + const int32_t shifted_y = y * (1 << params.left_shift); + const int32_t scaled_y = MultiplyByQuantizedMultiplierSmallerThanOneExp( + shifted_y, params.input1_multiplier, params.input1_shift); + + int32_t scaled_output; + if (exclusive) { + scaled_output = accumulator; + accumulator += scaled_y; + } else { + accumulator += scaled_y; + scaled_output = accumulator; + } + + const int32_t raw_output = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + scaled_output, params.output_multiplier, params.output_shift) + + params.output_offset; + const int32_t clamped_output = + std::min(params.quantized_activation_max, + std::max(params.quantized_activation_min, raw_output)); + output_data[index] = static_cast(clamped_output); + } + } + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CUMSUM_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/depth_to_space.h b/components/tflite/tensorflow/lite/kernels/internal/reference/depth_to_space.h new file mode 100644 index 00000000..00cca867 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/depth_to_space.h @@ -0,0 +1,79 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_DEPTH_TO_SPACE_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_DEPTH_TO_SPACE_H_ + +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +template +inline void DepthToSpace(const tflite::DepthToSpaceParams &op_params, + const RuntimeShape &unextended_input_shape, + const T *input_data, + const RuntimeShape &unextended_output_shape, + T *output_data) +{ + TFLITE_DCHECK_LE(unextended_input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_LE(unextended_output_shape.DimensionsCount(), 4); + const RuntimeShape input_shape = + RuntimeShape::ExtendedShape(4, unextended_input_shape); + const RuntimeShape output_shape = + RuntimeShape::ExtendedShape(4, unextended_output_shape); + + const int input_depth = input_shape.Dims(3); + const int input_width = input_shape.Dims(2); + const int input_height = input_shape.Dims(1); + const int input_batch = input_shape.Dims(0); + + const int output_depth = output_shape.Dims(3); + const int output_width = output_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_batch = output_shape.Dims(0); + + const int32_t block_size = op_params.block_size; + + TFLITE_DCHECK_EQ(input_width * block_size, output_width); + TFLITE_DCHECK_EQ(input_height * block_size, output_height); + TFLITE_DCHECK_EQ(input_depth, output_depth * block_size * block_size); + TFLITE_DCHECK_EQ(input_batch, output_batch); + + for (int out_b = 0; out_b < output_batch; ++out_b) { + for (int out_h = 0; out_h < output_height; ++out_h) { + for (int out_w = 0; out_w < output_width; ++out_w) { + for (int out_d = 0; out_d < output_depth; ++out_d) { + const int in_d = + out_d + ((out_h % block_size) * block_size + out_w % block_size) * + output_depth; + + const int in_w = out_w / block_size; + const int in_h = out_h / block_size; + const int in_b = out_b; + + const int input_index = Offset(input_shape, in_b, in_h, in_w, in_d); + const int output_index = + Offset(output_shape, out_b, out_h, out_w, out_d); + + output_data[output_index] = input_data[input_index]; + } + } + } + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_DEPTH_TO_SPACE_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/depthwiseconv_float.h b/components/tflite/tensorflow/lite/kernels/internal/reference/depthwiseconv_float.h new file mode 100644 index 00000000..0b6c08ff --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/depthwiseconv_float.h @@ -0,0 +1,100 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_DEPTHWISECONV_FLOAT_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_DEPTHWISECONV_FLOAT_H_ + +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +inline void DepthwiseConv( + const DepthwiseParams ¶ms, const RuntimeShape &input_shape, + const float *input_data, const RuntimeShape &filter_shape, + const float *filter_data, const RuntimeShape &bias_shape, + const float *bias_data, const RuntimeShape &output_shape, + float *output_data) +{ + const int stride_width = params.stride_width; + const int stride_height = params.stride_height; + const int dilation_width_factor = params.dilation_width_factor; + const int dilation_height_factor = params.dilation_height_factor; + const int pad_width = params.padding_values.width; + const int pad_height = params.padding_values.height; + const int depth_multiplier = params.depth_multiplier; + const float output_activation_min = params.float_activation_min; + const float output_activation_max = params.float_activation_max; + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int output_depth = MatchingDim(filter_shape, 3, output_shape, 3); + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int input_depth = input_shape.Dims(3); + const int filter_height = filter_shape.Dims(1); + const int filter_width = filter_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + TFLITE_DCHECK_EQ(output_depth, input_depth * depth_multiplier); + TFLITE_DCHECK_EQ(bias_shape.FlatSize(), output_depth); + + for (int b = 0; b < batches; ++b) { + for (int out_y = 0; out_y < output_height; ++out_y) { + for (int out_x = 0; out_x < output_width; ++out_x) { + for (int ic = 0; ic < input_depth; ++ic) { + for (int m = 0; m < depth_multiplier; m++) { + const int oc = m + ic * depth_multiplier; + const int in_x_origin = (out_x * stride_width) - pad_width; + const int in_y_origin = (out_y * stride_height) - pad_height; + float total = 0.f; + for (int filter_y = 0; filter_y < filter_height; ++filter_y) { + for (int filter_x = 0; filter_x < filter_width; ++filter_x) { + const int in_x = in_x_origin + dilation_width_factor * filter_x; + const int in_y = + in_y_origin + dilation_height_factor * filter_y; + // If the location is outside the bounds of the input image, + // use zero as a default value. + if ((in_x >= 0) && (in_x < input_width) && (in_y >= 0) && + (in_y < input_height)) { + float input_value = + input_data[Offset(input_shape, b, in_y, in_x, ic)]; + float filter_value = filter_data[Offset( + filter_shape, 0, filter_y, filter_x, oc)]; + total += (input_value * filter_value); + } + } + } + float bias_value = 0.0f; + if (bias_data) { + bias_value = bias_data[oc]; + } + output_data[Offset(output_shape, b, out_y, out_x, oc)] = + ActivationFunctionWithMinMax(total + bias_value, + output_activation_min, + output_activation_max); + } + } + } + } + } +} + +} // end namespace reference_ops +} // end namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_DEPTHWISECONV_FLOAT_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/depthwiseconv_uint8.h b/components/tflite/tensorflow/lite/kernels/internal/reference/depthwiseconv_uint8.h new file mode 100644 index 00000000..7de2d377 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/depthwiseconv_uint8.h @@ -0,0 +1,301 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_DEPTHWISECONV_UINT8_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_DEPTHWISECONV_UINT8_H_ + +#include + +#include "fixedpoint/fixedpoint.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +// Used in tests and template parameters to control which version of depthwise +// convolution is called. Primarily for reference code, and specializations +// forced in tests. +enum class DepthwiseConvImplementation { + // Run all tests against kUseStandardEntry even if also testing another + // kernel, since we need to be sure that the main DepthwiseConv() function in + // optimized_ops.h dispatches to a correctly-executing kernel. + kNone = 0, // The "default" option: use the normal + // DepthwiseConv kernel (entry) function. + kUseGenericKernel, // Forced use of generic kernel. + kUseNeon3x3, // 3x3 kernel that uses NEON when available. + kUseNeon3x3DotProduct, // 3x3 kernel that uses dot-product enabled NEON + // when available. + kUseCModel3x3DotProduct, // 3x3 kernel, reference C model that is intended + // to match overall design NEON code. + kUseUnwound3x3DotProduct, // 3x3 kernel, reference C model with unwound loops + // and some arrays. + kUseIntrinsics3x3DotProduct, // 3x3 kernel using NEON intrinsics. +}; + +// Category of depthwise convolution output rounding. +enum class DepthwiseConvOutputRounding { + kNone = 0, // Invalid: specific method must be specified. + kAwayFromZero, // Original method: exact halves rounded away from zero. + kUpward, // Halves towards +infinity: adds 0.5 before truncate. + // This is where a future kNearestEven would be placed. +}; + +// Category of depthwise convolution depth multiplication. +enum class DepthwiseConvDepthMultiplication { + kNoMultiplication = 0, // Depth multiplier = 1. + kUnitInputDepth, // Input depth = 1, output depth = depth multiplier. +}; + +namespace reference_ops { +namespace depthwise_conv { +template +inline int32_t DepthwiseConvRound(int32_t x, int32_t quantized_multiplier, + int shift) +{ + TFLITE_DCHECK_NE(output_rounding, DepthwiseConvOutputRounding::kNone); + return MultiplyByQuantizedMultiplier(x, quantized_multiplier, shift); +} + +template <> +inline int32_t DepthwiseConvRound( + int32_t x, int32_t quantized_multiplier, int shift) +{ + return MultiplyByQuantizedMultiplier(x, quantized_multiplier, shift); +} + +template <> +inline int32_t DepthwiseConvRound( + int32_t x, int32_t quantized_multiplier, int shift) +{ + using gemmlowp::SaturatingRoundingDoublingHighMul; + const int left_shift = shift > 0 ? shift : 0; + const int right_shift = shift > 0 ? 0 : -shift; + const int rounding_offset = right_shift > 0 ? 1 << (right_shift - 1) : 0; + return (SaturatingRoundingDoublingHighMul(x * (1 << left_shift), + quantized_multiplier) + + rounding_offset) >> + right_shift; +} + +template +struct DepthwiseConvBasicKernel { + static inline void Run( + const DepthwiseParams ¶ms, const RuntimeShape &input_shape, + const uint8_t *input_data, const RuntimeShape &filter_shape, + const uint8_t *filter_data, const RuntimeShape &bias_shape, + const int32_t *bias_data, const RuntimeShape &output_shape, + uint8_t *output_data) + { + const int stride_width = params.stride_width; + const int stride_height = params.stride_height; + const int dilation_width_factor = params.dilation_width_factor; + const int dilation_height_factor = params.dilation_height_factor; + const int pad_width = params.padding_values.width; + const int pad_height = params.padding_values.height; + const int depth_multiplier = params.depth_multiplier; + const int32_t output_activation_min = params.quantized_activation_min; + const int32_t output_activation_max = params.quantized_activation_max; + const int32_t input_offset = params.input_offset; + const int32_t filter_offset = params.weights_offset; + const int32_t output_offset = params.output_offset; + const int32_t output_multiplier = params.output_multiplier; + const int output_shift = params.output_shift; + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + + TFLITE_DCHECK_LE(output_activation_min, output_activation_max); + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int output_depth = MatchingDim(filter_shape, 3, output_shape, 3); + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int input_depth = input_shape.Dims(3); + const int filter_height = filter_shape.Dims(1); + const int filter_width = filter_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + TFLITE_DCHECK_EQ(output_depth, input_depth * depth_multiplier); + TFLITE_DCHECK_EQ(bias_shape.FlatSize(), output_depth); + + for (int b = 0; b < batches; ++b) { + for (int out_y = 0; out_y < output_height; ++out_y) { + for (int out_x = 0; out_x < output_width; ++out_x) { + for (int ic = 0; ic < input_depth; ++ic) { + for (int m = 0; m < depth_multiplier; m++) { + const int oc = m + ic * depth_multiplier; + const int in_x_origin = (out_x * stride_width) - pad_width; + const int in_y_origin = (out_y * stride_height) - pad_height; + int32_t acc = 0; + for (int filter_y = 0; filter_y < filter_height; ++filter_y) { + for (int filter_x = 0; filter_x < filter_width; ++filter_x) { + const int in_x = + in_x_origin + dilation_width_factor * filter_x; + const int in_y = + in_y_origin + dilation_height_factor * filter_y; + // If the location is outside the bounds of the input image, + // use zero as a default value. + if ((in_x >= 0) && (in_x < input_width) && (in_y >= 0) && + (in_y < input_height)) { + int32_t input_val = + input_data[Offset(input_shape, b, in_y, in_x, ic)]; + int32_t filter_val = filter_data[Offset( + filter_shape, 0, filter_y, filter_x, oc)]; + acc += (filter_val + filter_offset) * + (input_val + input_offset); + } + } + } + if (bias_data) { + acc += bias_data[oc]; + } + acc = DepthwiseConvRound(acc, output_multiplier, + output_shift); + acc += output_offset; + acc = std::max(acc, output_activation_min); + acc = std::min(acc, output_activation_max); + output_data[Offset(output_shape, b, out_y, out_x, oc)] = + static_cast(acc); + } + } + } + } + } + } + + // TODO(b/148596273): Reconcile reference versions, perhaps with common + // MultiplyByQuantizedMultiplier or DepthwiseConvRound function. + static inline void RunPerChannel( + const DepthwiseParams ¶ms, const RuntimeShape &input_shape, + const int8_t *input_data, const RuntimeShape &filter_shape, + const int8_t *filter_data, const RuntimeShape &bias_shape, + const int32_t *bias_data, const RuntimeShape &output_shape, + int8_t *output_data) + { + // Get parameters. + // TODO(b/141565753): Re-introduce ScopedProfilingLabel on Micro. + const int stride_width = params.stride_width; + const int stride_height = params.stride_height; + const int dilation_width_factor = params.dilation_width_factor; + const int dilation_height_factor = params.dilation_height_factor; + const int pad_width = params.padding_values.width; + const int pad_height = params.padding_values.height; + const int depth_multiplier = params.depth_multiplier; + const int32_t input_offset = params.input_offset; + const int32_t output_offset = params.output_offset; + const int32_t output_activation_min = params.quantized_activation_min; + const int32_t output_activation_max = params.quantized_activation_max; + const int32_t *output_multiplier = params.output_multiplier_per_channel; + const int32_t *output_shift = params.output_shift_per_channel; + + // Check dimensions of the tensors. + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + + TFLITE_DCHECK_LE(output_activation_min, output_activation_max); + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int output_depth = MatchingDim(filter_shape, 3, output_shape, 3); + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int input_depth = input_shape.Dims(3); + const int filter_height = filter_shape.Dims(1); + const int filter_width = filter_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + TFLITE_DCHECK_EQ(output_depth, input_depth * depth_multiplier); + TFLITE_DCHECK_EQ(bias_shape.FlatSize(), output_depth); + + for (int batch = 0; batch < batches; ++batch) { + for (int out_y = 0; out_y < output_height; ++out_y) { + for (int out_x = 0; out_x < output_width; ++out_x) { + for (int in_channel = 0; in_channel < input_depth; ++in_channel) { + for (int m = 0; m < depth_multiplier; ++m) { + const int output_channel = m + in_channel * depth_multiplier; + const int in_x_origin = (out_x * stride_width) - pad_width; + const int in_y_origin = (out_y * stride_height) - pad_height; + int32_t acc = 0; + for (int filter_y = 0; filter_y < filter_height; ++filter_y) { + for (int filter_x = 0; filter_x < filter_width; ++filter_x) { + const int in_x = + in_x_origin + dilation_width_factor * filter_x; + const int in_y = + in_y_origin + dilation_height_factor * filter_y; + // Zero padding by omitting the areas outside the image. + const bool is_point_inside_image = + (in_x >= 0) && (in_x < input_width) && (in_y >= 0) && + (in_y < input_height); + if (is_point_inside_image) { + int32_t input_val = input_data[Offset( + input_shape, batch, in_y, in_x, in_channel)]; + int32_t filter_val = filter_data[Offset( + filter_shape, 0, filter_y, filter_x, output_channel)]; + // Accumulate with 32 bits accumulator. + // In the nudging process during model quantization, we + // force real value of 0.0 be represented by a quantized + // value. This guarantees that the input_offset is a int8_t, + // even though it is represented using int32_t. int32_t += + // int8_t + // * (int8_t - int8_t) so the highest value we can get from + // each accumulation is [-127, 127] * ([-128, 127] - + // [-128, 127]), which is [-32512, 32512]. log2(32512) + // = 14.98, which means we can accumulate at least 2^16 + // multiplications without overflow. The accumulator is + // applied to a filter so the accumulation logic will hold + // as long as the filter size (filter_y * filter_x * + // in_channel) does not exceed 2^16, which is the case in + // all the models we have seen so far. + acc += filter_val * (input_val + input_offset); + } + } + } + if (bias_data) { + acc += bias_data[output_channel]; + } + acc = DepthwiseConvRound( + acc, output_multiplier[output_channel], + output_shift[output_channel]); + acc += output_offset; + acc = std::max(acc, output_activation_min); + acc = std::min(acc, output_activation_max); + output_data[Offset(output_shape, batch, out_y, out_x, + output_channel)] = static_cast(acc); + } + } + } + } + } + } +}; + +} // namespace depthwise_conv + +inline void DepthwiseConv( + const DepthwiseParams ¶ms, const RuntimeShape &input_shape, + const uint8_t *input_data, const RuntimeShape &filter_shape, + const uint8_t *filter_data, const RuntimeShape &bias_shape, + const int32_t *bias_data, const RuntimeShape &output_shape, + uint8_t *output_data) +{ + return depthwise_conv::DepthwiseConvBasicKernel< + DepthwiseConvOutputRounding::kAwayFromZero>::Run(params, input_shape, + input_data, filter_shape, + filter_data, bias_shape, + bias_data, output_shape, + output_data); +} + +} // namespace reference_ops +} // end namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_DEPTHWISECONV_UINT8_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/dequantize.h b/components/tflite/tensorflow/lite/kernels/internal/reference/dequantize.h new file mode 100644 index 00000000..f09bb7c3 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/dequantize.h @@ -0,0 +1,78 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_DEQUANTIZE_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_DEQUANTIZE_H_ + +#include + +#include + +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +// Dequantizes into a float without rounding. +template +inline void Dequantize(const tflite::DequantizationParams &op_params, + const RuntimeShape &input_shape, + const InputT *input_data, + const RuntimeShape &output_shape, OutputT *output_data) +{ + int32_t zero_point = op_params.zero_point; + const double scale = op_params.scale; + const int flat_size = MatchingFlatSize(input_shape, output_shape); + + for (int i = 0; i < flat_size; i++) { + const int32_t val = input_data[i]; + const OutputT result = static_cast(scale * (val - zero_point)); + output_data[i] = result; + } +} + +// Dequantizes per-channel quantized tensor to float. +template +inline void PerChannelDequantize( + const tflite::PerChannelDequantizationParams &op_params, + const RuntimeShape &input_shape, const T *input_data, + const RuntimeShape &output_shape, float *output_data) +{ + // Ensure flat size is same. + MatchingFlatSize(input_shape, output_shape); + + const int32_t *zero_point = op_params.zero_point; + const float *scale = op_params.scale; + const int32_t quantized_dimension = op_params.quantized_dimension; + const int32_t num_dims = input_shape.DimensionsCount(); + const int32_t *dims_data = input_shape.DimsData(); + std::vector current_dim(num_dims, 0); + + do { + size_t offset = + ReducedOutputOffset(num_dims, reinterpret_cast(dims_data), + current_dim.data(), 0, nullptr); + const int channel = current_dim[quantized_dimension]; + const int32_t val = input_data[offset]; + const float result = + static_cast(scale[channel] * (val - zero_point[channel])); + output_data[offset] = result; + } while (NextIndex(num_dims, reinterpret_cast(dims_data), + current_dim.data())); +} + +} // namespace reference_ops + +} // namespace tflite +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_DEQUANTIZE_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/elu.h b/components/tflite/tensorflow/lite/kernels/internal/reference/elu.h new file mode 100644 index 00000000..839f5f4b --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/elu.h @@ -0,0 +1,36 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ELU_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ELU_H_ + +#include "tensorflow/lite/kernels/internal/cppmath.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +inline void Elu(const RuntimeShape &input_shape, const float *input_data, + const RuntimeShape &output_shape, float *output_data) +{ + const int flat_size = MatchingFlatSize(input_shape, output_shape); + for (int i = 0; i < flat_size; ++i) { + const float val = input_data[i]; + output_data[i] = val < 0.0f ? TfLiteExpm1(val) : val; + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ELU_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/exp.h b/components/tflite/tensorflow/lite/kernels/internal/reference/exp.h new file mode 100644 index 00000000..401191ca --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/exp.h @@ -0,0 +1,38 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_EXP_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_EXP_H_ + +#include + +#include "ruy/profiler/instrumentation.h" // from @ruy +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +template +inline void Exp(const T *input_data, const size_t num_elements, + T *output_data) +{ + ruy::profiler::ScopeLabel label("Exp"); + for (size_t idx = 0; idx < num_elements; ++idx) { + output_data[idx] = std::exp(input_data[idx]); + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_EXP_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/fill.h b/components/tflite/tensorflow/lite/kernels/internal/reference/fill.h new file mode 100644 index 00000000..13c5dc56 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/fill.h @@ -0,0 +1,38 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FILL_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FILL_H_ + +#include + +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +template +void Fill(const RuntimeShape &value_shape, const T *value_data, + const RuntimeShape &output_shape, T *output_data) +{ + TFLITE_DCHECK_EQ(value_shape.DimensionsCount(), 0); + const int flat_size = output_shape.FlatSize(); + for (int i = 0; i < flat_size; ++i) { + output_data[i] = *value_data; + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FILL_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/floor.h b/components/tflite/tensorflow/lite/kernels/internal/reference/floor.h new file mode 100644 index 00000000..a2c1b96b --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/floor.h @@ -0,0 +1,38 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FLOOR_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FLOOR_H_ + +#include + +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +inline void Floor(const RuntimeShape &input_shape, const float *input_data, + const RuntimeShape &output_shape, float *output_data) +{ + const int flat_size = MatchingFlatSize(input_shape, output_shape); + + for (int i = 0; i < flat_size; i++) { + int offset = i; + output_data[offset] = std::floor(input_data[offset]); + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FLOOR_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/floor_div.h b/components/tflite/tensorflow/lite/kernels/internal/reference/floor_div.h new file mode 100644 index 00000000..bfa18c3b --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/floor_div.h @@ -0,0 +1,35 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FLOOR_DIV_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FLOOR_DIV_H_ + +#include +#include + +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +template +T FloorDiv(T input1, T input2) +{ + return std::floor(std::divides()(static_cast(input1), + static_cast(input2))); +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FLOOR_DIV_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/floor_mod.h b/components/tflite/tensorflow/lite/kernels/internal/reference/floor_mod.h new file mode 100644 index 00000000..47c80829 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/floor_mod.h @@ -0,0 +1,42 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FLOOR_MOD_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FLOOR_MOD_H_ + +#include +#include + +namespace tflite { +namespace reference_ops { +template +T FloorMod(T input1, T input2) +{ + struct FloatMod { + float operator()(const float lhs, const float rhs) const + { + return std::fmod(lhs, rhs); + } + }; + using ModFunc = typename std::conditional::value, + std::modulus, FloatMod>::type; + ModFunc mod_func; + T trunc_mod = mod_func(input1, input2); + return (trunc_mod != 0) && ((input2 < 0) != (trunc_mod < 0)) ? (trunc_mod + input2) : trunc_mod; +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FLOOR_MOD_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/fully_connected.h b/components/tflite/tensorflow/lite/kernels/internal/reference/fully_connected.h new file mode 100644 index 00000000..d9d7c722 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/fully_connected.h @@ -0,0 +1,323 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FULLY_CONNECTED_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FULLY_CONNECTED_H_ + +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/cppmath.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +inline void FullyConnected( + const FullyConnectedParams ¶ms, const RuntimeShape &input_shape, + const float *input_data, const RuntimeShape &weights_shape, + const float *weights_data, const RuntimeShape &bias_shape, + const float *bias_data, const RuntimeShape &output_shape, + float *output_data) +{ + const float output_activation_min = params.float_activation_min; + const float output_activation_max = params.float_activation_max; + // TODO(b/62193649): This really should be: + // const int batches = ArraySize(output_dims, 1); + // but the current --variable_batch hack consists in overwriting the 3rd + // dimension with the runtime batch size, as we don't keep track for each + // array of which dimension is the batch dimension in it. + const int output_dims_count = output_shape.DimensionsCount(); + const int weights_dims_count = weights_shape.DimensionsCount(); + const int batches = FlatSizeSkipDim(output_shape, output_dims_count - 1); + const int output_depth = MatchingDim(weights_shape, weights_dims_count - 2, + output_shape, output_dims_count - 1); + const int accum_depth = weights_shape.Dims(weights_dims_count - 1); + for (int b = 0; b < batches; ++b) { + for (int out_c = 0; out_c < output_depth; ++out_c) { + float total = 0.f; + for (int d = 0; d < accum_depth; ++d) { + total += input_data[b * accum_depth + d] * + weights_data[out_c * accum_depth + d]; + } + float bias_value = 0.0f; + if (bias_data) { + bias_value = bias_data[out_c]; + } + output_data[out_c + output_depth * b] = ActivationFunctionWithMinMax( + total + bias_value, output_activation_min, output_activation_max); + } + } +} + +inline void FullyConnected( + const FullyConnectedParams ¶ms, const RuntimeShape &input_shape, + const uint8_t *input_data, const RuntimeShape &filter_shape, + const uint8_t *filter_data, const RuntimeShape &bias_shape, + const int32_t *bias_data, const RuntimeShape &output_shape, + uint8_t *output_data) +{ + const int32_t input_offset = params.input_offset; + const int32_t filter_offset = params.weights_offset; + const int32_t output_offset = params.output_offset; + const int32_t output_multiplier = params.output_multiplier; + const int output_shift = params.output_shift; + const int32_t output_activation_min = params.quantized_activation_min; + const int32_t output_activation_max = params.quantized_activation_max; + TFLITE_DCHECK_GE(filter_shape.DimensionsCount(), 2); + TFLITE_DCHECK_GE(output_shape.DimensionsCount(), 1); + + TFLITE_DCHECK_LE(output_activation_min, output_activation_max); + // TODO(b/62193649): This really should be: + // const int batches = ArraySize(output_dims, 1); + // but the current --variable_batch hack consists in overwriting the 3rd + // dimension with the runtime batch size, as we don't keep track for each + // array of which dimension is the batch dimension in it. + const int output_dim_count = output_shape.DimensionsCount(); + const int filter_dim_count = filter_shape.DimensionsCount(); + const int batches = FlatSizeSkipDim(output_shape, output_dim_count - 1); + const int output_depth = MatchingDim(filter_shape, filter_dim_count - 2, + output_shape, output_dim_count - 1); + const int accum_depth = filter_shape.Dims(filter_dim_count - 1); + for (int b = 0; b < batches; ++b) { + for (int out_c = 0; out_c < output_depth; ++out_c) { + int32_t acc = 0; + for (int d = 0; d < accum_depth; ++d) { + int32_t input_val = input_data[b * accum_depth + d]; + int32_t filter_val = filter_data[out_c * accum_depth + d]; + acc += (filter_val + filter_offset) * (input_val + input_offset); + } + if (bias_data) { + acc += bias_data[out_c]; + } + acc = MultiplyByQuantizedMultiplier(acc, output_multiplier, output_shift); + acc += output_offset; + acc = std::max(acc, output_activation_min); + acc = std::min(acc, output_activation_max); + output_data[out_c + output_depth * b] = static_cast(acc); + } + } +} + +inline void FullyConnected( + const FullyConnectedParams ¶ms, const RuntimeShape &input_shape, + const uint8_t *input_data, const RuntimeShape &filter_shape, + const uint8_t *filter_data, const RuntimeShape &bias_shape, + const int32_t *bias_data, const RuntimeShape &output_shape, + int16_t *output_data) +{ + const int32_t input_offset = params.input_offset; + const int32_t filter_offset = params.weights_offset; + const int32_t output_offset = params.output_offset; + const int32_t output_multiplier = params.output_multiplier; + const int output_shift = params.output_shift; + const int32_t output_activation_min = params.quantized_activation_min; + const int32_t output_activation_max = params.quantized_activation_max; + + TFLITE_DCHECK_LE(output_activation_min, output_activation_max); + TFLITE_DCHECK_EQ(output_offset, 0); + // TODO(b/62193649): This really should be: + // const int batches = ArraySize(output_dims, 1); + // but the current --variable_batch hack consists in overwriting the 3rd + // dimension with the runtime batch size, as we don't keep track for each + // array of which dimension is the batch dimension in it. + const int output_dim_count = output_shape.DimensionsCount(); + const int filter_dim_count = filter_shape.DimensionsCount(); + const int batches = FlatSizeSkipDim(output_shape, output_dim_count - 1); + const int output_depth = MatchingDim(filter_shape, filter_dim_count - 2, + output_shape, output_dim_count - 1); + const int accum_depth = filter_shape.Dims(filter_dim_count - 1); + for (int b = 0; b < batches; ++b) { + for (int out_c = 0; out_c < output_depth; ++out_c) { + // Internal accumulation. + // Initialize accumulator with the bias-value. + int32_t accum = bias_data[out_c]; + // Accumulation loop. + for (int d = 0; d < accum_depth; ++d) { + int16_t input_val = input_data[b * accum_depth + d] + input_offset; + int16_t filter_val = + filter_data[out_c * accum_depth + d] + filter_offset; + accum += filter_val * input_val; + } + // Down-scale the final int32_t accumulator to the scale used by our + // (16-bit, typically 3 integer bits) fixed-point format. The quantized + // multiplier and shift here have been pre-computed offline + // (e.g. by toco). + accum = + MultiplyByQuantizedMultiplier(accum, output_multiplier, output_shift); + // Saturate, cast to int16_t, and store to output array. + accum = std::max(accum, output_activation_min - output_offset); + accum = std::min(accum, output_activation_max - output_offset); + accum += output_offset; + output_data[out_c + output_depth * b] = accum; + } + } +} + +inline void ShuffledFullyConnected( + const FullyConnectedParams ¶ms, const RuntimeShape &input_shape, + const uint8_t *input_data, const RuntimeShape &weights_shape, + const uint8_t *shuffled_weights_data, const RuntimeShape &bias_shape, + const int32_t *bias_data, const RuntimeShape &output_shape, + int16_t *output_data, uint8_t *shuffled_input_workspace_data) +{ + const int32_t output_multiplier = params.output_multiplier; + const int output_shift = params.output_shift; + const int32_t output_activation_min = params.quantized_activation_min; + const int32_t output_activation_max = params.quantized_activation_max; + TFLITE_DCHECK_LE(output_activation_min, output_activation_max); + + TFLITE_DCHECK_GE(input_shape.DimensionsCount(), 1); + TFLITE_DCHECK_GE(weights_shape.DimensionsCount(), 2); + TFLITE_DCHECK_GE(output_shape.DimensionsCount(), 1); + // TODO(b/62193649): This really should be: + // const int batches = ArraySize(output_dims, 1); + // but the current --variable_batch hack consists in overwriting the 3rd + // dimension with the runtime batch size, as we don't keep track for each + // array of which dimension is the batch dimension in it. + const int output_dim_count = output_shape.DimensionsCount(); + const int weights_dim_count = weights_shape.DimensionsCount(); + const int batches = FlatSizeSkipDim(output_shape, output_dim_count - 1); + const int output_depth = MatchingDim(weights_shape, weights_dim_count - 2, + output_shape, output_dim_count - 1); + const int accum_depth = weights_shape.Dims(weights_dim_count - 1); + TFLITE_DCHECK((accum_depth % 16) == 0); + TFLITE_DCHECK((output_depth % 4) == 0); + + // Shuffling and xoring of input activations into the workspace buffer + uint8_t *shuffled_input_workspace_ptr = shuffled_input_workspace_data; + if (batches == 1) { + for (int i = 0; i < accum_depth; i++) { + shuffled_input_workspace_data[i] = input_data[i] ^ 0x80; + } + } else if (batches == 4) { + for (int c = 0; c < accum_depth; c += 16) { + for (int b = 0; b < 4; b++) { + const uint8_t *src_data_ptr = input_data + b * accum_depth + c; + for (int j = 0; j < 16; j++) { + uint8_t src_val = *src_data_ptr++; + // Flip the sign bit, so that the kernel will only need to + // reinterpret these uint8_t values as int8_t, getting for free the + // subtraction of the zero_point value 128. + uint8_t dst_val = src_val ^ 0x80; + *shuffled_input_workspace_ptr++ = dst_val; + } + } + } + } else { + TFLITE_DCHECK(false); + return; + } + + // Actual computation + if (batches == 1) { + int16_t *output_ptr = output_data; + // Shuffled weights have had their sign bit (0x80) pre-flipped (xor'd) + // so that just reinterpreting them as int8_t values is equivalent to + // subtracting 128 from them, thus implementing for free the subtraction of + // the zero_point value 128. + const int8_t *shuffled_weights_ptr = + reinterpret_cast(shuffled_weights_data); + // Likewise, we preshuffled and pre-xored the input data above. + const int8_t *shuffled_input_data = + reinterpret_cast(shuffled_input_workspace_data); + for (int c = 0; c < output_depth; c += 4) { + // Internal accumulation. + // Initialize accumulator with the bias-value. + int32_t accum[4] = { 0 }; + // Accumulation loop. + for (int d = 0; d < accum_depth; d += 16) { + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 16; j++) { + int8_t input_val = shuffled_input_data[d + j]; + int8_t weights_val = *shuffled_weights_ptr++; + accum[i] += weights_val * input_val; + } + } + } + for (int i = 0; i < 4; i++) { + // Add bias value + int32_t acc = accum[i] + bias_data[c + i]; + // Down-scale the final int32_t accumulator to the scale used by our + // (16-bit, typically 3 integer bits) fixed-point format. The quantized + // multiplier and shift here have been pre-computed offline + // (e.g. by toco). + acc = + MultiplyByQuantizedMultiplier(acc, output_multiplier, output_shift); + // Saturate, cast to int16_t, and store to output array. + acc = std::max(acc, output_activation_min); + acc = std::min(acc, output_activation_max); + output_ptr[c + i] = acc; + } + } + } else if (batches == 4) { + int16_t *output_ptr = output_data; + // Shuffled weights have had their sign bit (0x80) pre-flipped (xor'd) + // so that just reinterpreting them as int8_t values is equivalent to + // subtracting 128 from them, thus implementing for free the subtraction of + // the zero_point value 128. + const int8_t *shuffled_weights_ptr = + reinterpret_cast(shuffled_weights_data); + // Likewise, we preshuffled and pre-xored the input data above. + const int8_t *shuffled_input_data = + reinterpret_cast(shuffled_input_workspace_data); + for (int c = 0; c < output_depth; c += 4) { + const int8_t *shuffled_input_ptr = shuffled_input_data; + // Accumulation loop. + // Internal accumulation. + // Initialize accumulator with the bias-value. + int32_t accum[4][4]; + for (int i = 0; i < 4; i++) { + for (int b = 0; b < 4; b++) { + accum[i][b] = 0; + } + } + for (int d = 0; d < accum_depth; d += 16) { + for (int i = 0; i < 4; i++) { + for (int b = 0; b < 4; b++) { + for (int j = 0; j < 16; j++) { + int8_t input_val = shuffled_input_ptr[16 * b + j]; + int8_t weights_val = shuffled_weights_ptr[16 * i + j]; + accum[i][b] += weights_val * input_val; + } + } + } + shuffled_input_ptr += 64; + shuffled_weights_ptr += 64; + } + for (int i = 0; i < 4; i++) { + for (int b = 0; b < 4; b++) { + // Add bias value + int32_t acc = accum[i][b] + bias_data[c + i]; + // Down-scale the final int32_t accumulator to the scale used by our + // (16-bit, typically 3 integer bits) fixed-point format. The + // quantized multiplier and shift here have been pre-computed offline + // (e.g. by toco). + acc = MultiplyByQuantizedMultiplier(acc, output_multiplier, + output_shift); + // Saturate, cast to int16_t, and store to output array. + acc = std::max(acc, output_activation_min); + acc = std::min(acc, output_activation_max); + output_ptr[b * output_depth + c + i] = acc; + } + } + } + } else { + TFLITE_DCHECK(false); + return; + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FULLY_CONNECTED_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/hard_swish.h b/components/tflite/tensorflow/lite/kernels/internal/reference/hard_swish.h new file mode 100644 index 00000000..faa7d01f --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/hard_swish.h @@ -0,0 +1,169 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ACTIVATIONS_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ACTIVATIONS_H_ + +#include "ruy/profiler/instrumentation.h" // from @ruy +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +inline int16_t SaturatingLeftShift(int16_t value, int amount) +{ + int32_t result = static_cast(value) * (1 << amount); + result = std::min(result, std::numeric_limits::max()); + result = std::max(result, std::numeric_limits::min()); + return result; +} + +// Similar to ARM instruction SQDMULH. +// Similar to gemmlowp::SaturatingRoundingDoublingHighMul except +// rounding to zero instead of to nearest (SQRDMULH). +inline std::int16_t SaturatingDoublingHighMul(std::int16_t a, std::int16_t b) +{ + bool overflow = a == b && a == std::numeric_limits::min(); + std::int32_t a_32(a); + std::int32_t b_32(b); + std::int32_t ab_32 = a_32 * b_32; + std::int16_t ab_x2_high16 = static_cast((ab_32) / (1 << 15)); + return overflow ? std::numeric_limits::max() : ab_x2_high16; +} + +template +inline void HardSwish(const RuntimeShape &input_shape, const T *input_data, + const RuntimeShape &output_shape, T *output_data) +{ + ruy::profiler::ScopeLabel label("ReferenceHardSwish/Float"); + auto matching_size = MatchingFlatSize(input_shape, output_shape); + const T *in_end = input_data + matching_size; + for (; input_data < in_end; input_data++, output_data++) { + const float in = *input_data; + *output_data = + in * std::min(static_cast(6), std::max(static_cast(0), in + 3)) / + 6; + } +} + +template +inline void HardSwish(const HardSwishParams ¶ms, + const RuntimeShape &input_shape, const T *input_data, + const RuntimeShape &output_shape, T *output_data) +{ + ruy::profiler::ScopeLabel label("ReferenceHardSwish/Quantized"); + + const int flat_size = MatchingFlatSize(input_shape, output_shape); + + for (int i = 0; i < flat_size; i++) { + const int16_t input_value = input_data[i] - params.input_zero_point; + // Left-shift as much as we can without overflow/saturation to put + // significant bits in the high bits of our 16-bit fixedpoint values, so + // that fixed-point approximate computations below are as accurate as + // possible. + const int16_t input_value_on_hires_input_scale = input_value * (1 << 7); + // Compute the input value on essentially the output scale, just not + // right-shifted yet. This is the value that we'll use in the (x >= +3) + // case, and that in the general case we'll multiply against the "relu-ish" + // fixed-point multiplier in [0, 1]. + const int16_t input_value_on_preshift_output_scale = + gemmlowp::SaturatingRoundingDoublingHighMul( + input_value_on_hires_input_scale, + params.output_multiplier_fixedpoint_int16); + // Now compute the "relu-ish multiplier". In the (-3 <= x <= +3) case, that + // is just an affine rescaling of x from [-3, 3] to [0, 1]. In the general + // case, it is just that plus saturation at the boundaries of [-3, 3]. + // First, we rescale from [-3, 3] to [-1, 1], saturating. + // That is done by rescaling the input value with a fixed-point multiplier + // (reluish_multiplier_fixedpoint) and bit-shift such that we represent + // that input value on the scale where the real value 3.0f is represented + // by the quantized value 32768. (+32768 is actually not representable as + // int16_t, so this saturates at +32767, and that is seen empirically to be + // a negligible contribution to numerical error/bias). + // + // This code is careful to correctly implement any magnitude of multiplier, + // involving either a right shift or a left shift, with correct saturation + // behavior in the left-shift case. This forces this code to be more + // complicated, but is necessary for real applications: a partially + // trained quantized MobileNet v3-small model that motivated this code + // exhibits some large [min, max] range boundaries, of the order of + // magnitude of 10 or 100 depending on layers. + // + // The next few lines are basically just an ordinary + // MultiplyByQuantizedMultiplier, except that we are more careful here + // about the fine details of saturation when left-shifting, because here + // overflow in left-shift is a common case, not an anomaly as + // MultiplyByQuantizedMultiplier assumes. + int16_t reluish_value = input_value_on_hires_input_scale; + // Shift left, saturating, as much as we can while ensuring that this + // saturation will not contribute to the result. That is, left shift amount + // reduced by 1. + if (params.reluish_multiplier_exponent > 0) { + reluish_value = SaturatingLeftShift( + reluish_value, params.reluish_multiplier_exponent - 1); + } + // Apply the fixed-point multiplier, dividing the value by a divisor + // ranging in [1, 2]. + reluish_value = gemmlowp::SaturatingRoundingDoublingHighMul( + reluish_value, params.reluish_multiplier_fixedpoint_int16); + // Apply the last bit of left-shift. Thus, in the left-shifting case, if + // any saturation affects the result, it is happening here --- any + // saturation having occurred above is overwritten here, not affecting the + // result. + if (params.reluish_multiplier_exponent > 0) { + reluish_value = SaturatingLeftShift(reluish_value, 1); + } + // Shift right, in the right-shifting case. + if (params.reluish_multiplier_exponent < 0) { + reluish_value = gemmlowp::RoundingDivideByPOT( + reluish_value, -params.reluish_multiplier_exponent); + } + // At this point we have rescaled the value into a 16bit fixedpoint + // reluish_value in [-1, 1]. + // We now convert that to a 16bit fixedpoint value in [0, 1]. + reluish_value = (reluish_value + (1 << 15)) >> 1; + // Use of SaturatingDoublingHighMul here is important to cancel the biases + // from the above SaturatingRoundingDoublingHighMul. + // + // On a partially trained MobileNet-v3-small, + // + // | bias on | ImageNet + // | quantized | Top-1 + // Operation used here | values | accuracy (50k) + // --------------------------------------+------------+----------- + // SaturatingDoublingHighMul | -0.0024 | 58.920 + // SaturatingRoundingDoublingHighMul | -0.0067 | 58.064 + // + // In activations_test, this is covered by this testcase: + // QuantizedActivationsOpTest.HardSwishBias + // + const int16_t preshift_output_value = SaturatingDoublingHighMul( + reluish_value, input_value_on_preshift_output_scale); + // We were so far operating on the pre-shift output scale. Now we finally + // apply that output shift, arriving at the final output scale. + int16_t output_value = gemmlowp::RoundingDivideByPOT( + preshift_output_value, -params.output_multiplier_exponent); + output_value += params.output_zero_point; + output_value = + std::min(output_value, std::numeric_limits::max()); + output_value = + std::max(output_value, std::numeric_limits::min()); + output_data[i] = output_value; + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CONV_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/add.h b/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/add.h new file mode 100644 index 00000000..6405ebc2 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/add.h @@ -0,0 +1,150 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_ADD_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_ADD_H_ + +#include + +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_integer_ops { +inline void CheckArithmeticParams(const ArithmeticParams ¶ms) +{ + TFLITE_DCHECK_LE(params.quantized_activation_min, + params.quantized_activation_max); + // Input offset is negative input zero point. Activation tensors are + // asymmetric quantized so they span the full int8 range. + TFLITE_DCHECK_GE(-params.input1_offset, std::numeric_limits::min()); + TFLITE_DCHECK_GE(-params.input2_offset, std::numeric_limits::min()); + TFLITE_DCHECK_LE(-params.input1_offset, std::numeric_limits::max()); + TFLITE_DCHECK_LE(-params.input2_offset, std::numeric_limits::max()); +} + +inline void ElementWise( + int size, const ArithmeticParams ¶ms, const int8_t *input1_data, + const int8_t *input2_data, int8_t *output_data, + void (*check_arithmetic_params)(const ArithmeticParams &), + int8_t (*binary_func)(int8_t, int8_t, const ArithmeticParams &)) +{ + CheckArithmeticParams(params); + for (int i = 0; i < size; ++i) { + output_data[i] = binary_func(input1_data[i], input2_data[i], params); + } +} + +inline void BroadcastBinaryFunction4DSlow( + const ArithmeticParams ¶ms, const RuntimeShape &input1_shape, + const int8_t *input1_data, const RuntimeShape &input2_shape, + const int8_t *input2_data, const RuntimeShape &output_shape, + int8_t *output_data, + void (*check_arithmetic_params)(const ArithmeticParams &), + int8_t (*binary_func)(int8_t, int8_t, const ArithmeticParams &)) +{ + NdArrayDesc<4> desc1; + NdArrayDesc<4> desc2; + NdArrayDescsForElementwiseBroadcast(input1_shape, input2_shape, &desc1, + &desc2); + const RuntimeShape extended_output_shape = + RuntimeShape::ExtendedShape(4, output_shape); + + // In Tensorflow, the dimensions are canonically named (batch_number, row, + // col, channel), with extents (batches, height, width, depth), with the + // trailing dimension changing most rapidly (channels has the smallest stride, + // typically 1 element). + // + // In generated C code, we store arrays with the dimensions reversed. The + // first dimension has smallest stride. + // + // We name our variables by their Tensorflow convention, but generate C code + // nesting loops such that the innermost loop has the smallest stride for the + // best cache behavior. + for (int b = 0; b < extended_output_shape.Dims(0); ++b) { + for (int y = 0; y < extended_output_shape.Dims(1); ++y) { + for (int x = 0; x < extended_output_shape.Dims(2); ++x) { + for (int c = 0; c < extended_output_shape.Dims(3); ++c) { + output_data[Offset(extended_output_shape, b, y, x, c)] = binary_func( + input1_data[SubscriptToIndex(desc1, b, y, x, c)], + input2_data[SubscriptToIndex(desc2, b, y, x, c)], params); + } + } + } + } +} + +inline int8_t AddFunc(int8_t x, int8_t y, const ArithmeticParams ¶ms) +{ + const int32_t input1_val = params.input1_offset + x; + const int32_t input2_val = params.input2_offset + y; + const int32_t shifted_input1_val = input1_val * (1 << params.left_shift); + const int32_t shifted_input2_val = input2_val * (1 << params.left_shift); + const int32_t scaled_input1_val = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + shifted_input1_val, params.input1_multiplier, params.input1_shift); + const int32_t scaled_input2_val = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + shifted_input2_val, params.input2_multiplier, params.input2_shift); + const int32_t raw_sum = scaled_input1_val + scaled_input2_val; + const int32_t raw_output = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + raw_sum, params.output_multiplier, params.output_shift) + + params.output_offset; + const int32_t clamped_output = + std::min(params.quantized_activation_max, + std::max(params.quantized_activation_min, raw_output)); + return static_cast(clamped_output); +} + +// Element-wise add that can often be used for inner loop of broadcast add as +// well as the non-broadcast add. +inline void AddElementwise(int size, const ArithmeticParams ¶ms, + const int8_t *input1_data, const int8_t *input2_data, + int8_t *output_data) +{ + ElementWise(size, params, input1_data, input2_data, output_data, + CheckArithmeticParams, AddFunc); +} + +inline void Add(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, const int8_t *input1_data, + const RuntimeShape &input2_shape, const int8_t *input2_data, + const RuntimeShape &output_shape, int8_t *output_data) +{ + CheckArithmeticParams(params); + + const int flat_size = + MatchingElementsSize(input1_shape, input2_shape, output_shape); + + AddElementwise(flat_size, params, input1_data, input2_data, output_data); +} + +inline void BroadcastAdd4DSlow(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, + const int8_t *input1_data, + const RuntimeShape &input2_shape, + const int8_t *input2_data, + const RuntimeShape &output_shape, + int8_t *output_data) +{ + BroadcastBinaryFunction4DSlow(params, input1_shape, input1_data, input2_shape, + input2_data, output_shape, output_data, + CheckArithmeticParams, AddFunc); +} + +} // namespace reference_integer_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_ADD_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/conv.h b/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/conv.h new file mode 100644 index 00000000..65fec608 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/conv.h @@ -0,0 +1,222 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_CONV_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_CONV_H_ + +#include "tensorflow/lite/kernels/internal/common.h" + +namespace tflite { +namespace reference_integer_ops { +// Fixed-point per-channel-quantization convolution reference kernel. +inline void ConvPerChannel( + const ConvParams ¶ms, const int32_t *output_multiplier, + const int32_t *output_shift, const RuntimeShape &input_shape, + const int8_t *input_data, const RuntimeShape &filter_shape, + const int8_t *filter_data, const RuntimeShape &bias_shape, + const int32_t *bias_data, const RuntimeShape &output_shape, + int8_t *output_data) +{ + // Get parameters. + const int32_t input_offset = params.input_offset; // r = s(q - Z) + const int stride_width = params.stride_width; + const int stride_height = params.stride_height; + const int dilation_width_factor = params.dilation_width_factor; + const int dilation_height_factor = params.dilation_height_factor; + const int pad_width = params.padding_values.width; + const int pad_height = params.padding_values.height; + const int32_t output_offset = params.output_offset; + + // Set min and max value of the output. + const int32_t output_activation_min = params.quantized_activation_min; + const int32_t output_activation_max = params.quantized_activation_max; + + // Consistency check. + TFLITE_DCHECK_LE(output_activation_min, output_activation_max); + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int input_depth = MatchingDim(input_shape, 3, filter_shape, 3); + const int output_depth = MatchingDim(filter_shape, 0, output_shape, 3); + if (bias_data) { + TFLITE_DCHECK_EQ(bias_shape.FlatSize(), output_depth); + } + + // Check dimensions of the tensors. + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int filter_height = filter_shape.Dims(1); + const int filter_width = filter_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + for (int batch = 0; batch < batches; ++batch) { + for (int out_y = 0; out_y < output_height; ++out_y) { + const int in_y_origin = (out_y * stride_height) - pad_height; + for (int out_x = 0; out_x < output_width; ++out_x) { + const int in_x_origin = (out_x * stride_width) - pad_width; + for (int out_channel = 0; out_channel < output_depth; ++out_channel) { + int32_t acc = 0; + for (int filter_y = 0; filter_y < filter_height; ++filter_y) { + const int in_y = in_y_origin + dilation_height_factor * filter_y; + for (int filter_x = 0; filter_x < filter_width; ++filter_x) { + const int in_x = in_x_origin + dilation_width_factor * filter_x; + + // Zero padding by omitting the areas outside the image. + const bool is_point_inside_image = + (in_x >= 0) && (in_x < input_width) && (in_y >= 0) && + (in_y < input_height); + + if (!is_point_inside_image) { + continue; + } + + for (int in_channel = 0; in_channel < input_depth; ++in_channel) { + int32_t input_val = input_data[Offset(input_shape, batch, in_y, + in_x, in_channel)]; + int32_t filter_val = filter_data[Offset( + filter_shape, out_channel, filter_y, filter_x, in_channel)]; + // Accumulate with 32 bits accumulator. + // In the nudging process during model quantization, we force + // real value of 0.0 be represented by a quantized value. This + // guarantees that the input_offset is a int8_t, even though + // it is represented using int32_t. int32_t += int8_t * + // (int8_t - int8_t) so the highest value we can get from each + // accumulation is [-127, 127] * ([-128, 127] - + // [-128, 127]), which is [-32512, 32512]. log2(32512) + // = 14.98, which means we can accumulate at least 2^16 + // multiplications without overflow. The accumulator is + // applied to a filter so the accumulation logic will hold as + // long as the filter size (filter_y * filter_x * in_channel) + // does not exceed 2^16, which is the case in all the models + // we have seen so far. + // TODO(b/174275578): Add a check to make sure the + // accumulator depth is smaller than 2^16. + acc += filter_val * (input_val + input_offset); + } + } + } + + if (bias_data) { + acc += bias_data[out_channel]; + } + acc = MultiplyByQuantizedMultiplier( + acc, output_multiplier[out_channel], output_shift[out_channel]); + acc += output_offset; + acc = std::max(acc, output_activation_min); + acc = std::min(acc, output_activation_max); + output_data[Offset(output_shape, batch, out_y, out_x, out_channel)] = + static_cast(acc); + } + } + } + } +} + +// Fixed-point per-channel-quantization convolution reference kernel. +// 16-bit data and 8-bit filter +inline void ConvPerChannel( + const ConvParams ¶ms, const int32_t *output_multiplier, + const int32_t *output_shift, const RuntimeShape &input_shape, + const int16_t *input_data, const RuntimeShape &filter_shape, + const int8_t *filter_data, const RuntimeShape &bias_shape, + const std::int64_t *bias_data, const RuntimeShape &output_shape, + int16_t *output_data) +{ + // Get parameters. + const int stride_width = params.stride_width; + const int stride_height = params.stride_height; + const int dilation_width_factor = params.dilation_width_factor; + const int dilation_height_factor = params.dilation_height_factor; + const int pad_width = params.padding_values.width; + const int pad_height = params.padding_values.height; + + // Set min and max value of the output. + const int32_t output_activation_min = params.quantized_activation_min; + const int32_t output_activation_max = params.quantized_activation_max; + + // Consistency check. + TFLITE_DCHECK_LE(output_activation_min, output_activation_max); + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int input_depth = MatchingDim(input_shape, 3, filter_shape, 3); + const int output_depth = MatchingDim(filter_shape, 0, output_shape, 3); + if (bias_data) { + TFLITE_DCHECK_EQ(bias_shape.FlatSize(), output_depth); + } + + // Check dimensions of the tensors. + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int filter_height = filter_shape.Dims(1); + const int filter_width = filter_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + for (int batch = 0; batch < batches; ++batch) { + for (int out_y = 0; out_y < output_height; ++out_y) { + const int in_y_origin = (out_y * stride_height) - pad_height; + for (int out_x = 0; out_x < output_width; ++out_x) { + const int in_x_origin = (out_x * stride_width) - pad_width; + for (int out_channel = 0; out_channel < output_depth; ++out_channel) { + std::int64_t acc = 0; + for (int filter_y = 0; filter_y < filter_height; ++filter_y) { + const int in_y = in_y_origin + dilation_height_factor * filter_y; + for (int filter_x = 0; filter_x < filter_width; ++filter_x) { + const int in_x = in_x_origin + dilation_width_factor * filter_x; + + // Zero padding by omitting the areas outside the image. + const bool is_point_inside_image = + (in_x >= 0) && (in_x < input_width) && (in_y >= 0) && + (in_y < input_height); + + if (!is_point_inside_image) { + continue; + } + + for (int in_channel = 0; in_channel < input_depth; ++in_channel) { + int32_t input_val = input_data[Offset(input_shape, batch, in_y, + in_x, in_channel)]; + int32_t filter_val = filter_data[Offset( + filter_shape, out_channel, filter_y, filter_x, in_channel)]; + // Accumulate with 64 bits accumulator. + // int64_t += int8_t * int16_t so the highest value we can + // get from each accumulation is [-127, 127] * ([-32768, + // 32767] - + // [-32768, 32767]), which is [-8322945, 8322945]. + // log2(8322945) = 22.99. + acc += filter_val * input_val; + } + } + } + if (bias_data) { + acc += bias_data[out_channel]; + } + int32_t scaled_acc = MultiplyByQuantizedMultiplier( + acc, output_multiplier[out_channel], output_shift[out_channel]); + scaled_acc = std::max(scaled_acc, output_activation_min); + scaled_acc = std::min(scaled_acc, output_activation_max); + output_data[Offset(output_shape, batch, out_y, out_x, out_channel)] = + static_cast(scaled_acc); + } + } + } + } +} + +} // namespace reference_integer_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_CONV_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/depthwise_conv.h b/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/depthwise_conv.h new file mode 100644 index 00000000..d9e7caca --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/depthwise_conv.h @@ -0,0 +1,292 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_DEPTHWISE_CONV_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_DEPTHWISE_CONV_H_ + +#include "tensorflow/lite/kernels/internal/common.h" + +namespace tflite { +namespace reference_integer_ops { +inline void DepthwiseConvPerChannel( + const DepthwiseParams ¶ms, const int32_t *output_multiplier, + const int32_t *output_shift, const RuntimeShape &input_shape, + const int8_t *input_data, const RuntimeShape &filter_shape, + const int8_t *filter_data, const RuntimeShape &bias_shape, + const int32_t *bias_data, const RuntimeShape &output_shape, + int8_t *output_data) +{ + // Get parameters. + // TODO(b/141565753): Re-introduce ScopedProfilingLabel on Micro. + const int stride_width = params.stride_width; + const int stride_height = params.stride_height; + const int dilation_width_factor = params.dilation_width_factor; + const int dilation_height_factor = params.dilation_height_factor; + const int pad_width = params.padding_values.width; + const int pad_height = params.padding_values.height; + const int depth_multiplier = params.depth_multiplier; + const int32_t input_offset = params.input_offset; + const int32_t output_offset = params.output_offset; + const int32_t output_activation_min = params.quantized_activation_min; + const int32_t output_activation_max = params.quantized_activation_max; + + // Check dimensions of the tensors. + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + + TFLITE_DCHECK_LE(output_activation_min, output_activation_max); + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int output_depth = MatchingDim(filter_shape, 3, output_shape, 3); + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int input_depth = input_shape.Dims(3); + const int filter_height = filter_shape.Dims(1); + const int filter_width = filter_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + TFLITE_DCHECK_EQ(output_depth, input_depth * depth_multiplier); + TFLITE_DCHECK_EQ(bias_shape.FlatSize(), output_depth); + + for (int batch = 0; batch < batches; ++batch) { + for (int out_y = 0; out_y < output_height; ++out_y) { + for (int out_x = 0; out_x < output_width; ++out_x) { + for (int in_channel = 0; in_channel < input_depth; ++in_channel) { + for (int m = 0; m < depth_multiplier; ++m) { + const int output_channel = m + in_channel * depth_multiplier; + const int in_x_origin = (out_x * stride_width) - pad_width; + const int in_y_origin = (out_y * stride_height) - pad_height; + int32_t acc = 0; + for (int filter_y = 0; filter_y < filter_height; ++filter_y) { + for (int filter_x = 0; filter_x < filter_width; ++filter_x) { + const int in_x = in_x_origin + dilation_width_factor * filter_x; + const int in_y = + in_y_origin + dilation_height_factor * filter_y; + // Zero padding by omitting the areas outside the image. + const bool is_point_inside_image = + (in_x >= 0) && (in_x < input_width) && (in_y >= 0) && + (in_y < input_height); + if (is_point_inside_image) { + int32_t input_val = input_data[Offset( + input_shape, batch, in_y, in_x, in_channel)]; + int32_t filter_val = filter_data[Offset( + filter_shape, 0, filter_y, filter_x, output_channel)]; + // Accumulate with 32 bits accumulator. + // In the nudging process during model quantization, we force + // real value of 0.0 be represented by a quantized value. This + // guarantees that the input_offset is a int8_t, even though + // it is represented using int32_t. int32_t += int8_t * + // (int8_t - int8_t) so the highest value we can get from each + // accumulation is [-127, 127] * ([-128, 127] - + // [-128, 127]), which is [-32512, 32512]. log2(32512) + // = 14.98, which means we can accumulate at least 2^16 + // multiplications without overflow. The accumulator is + // applied to a filter so the accumulation logic will hold as + // long as the filter size (filter_y * filter_x * in_channel) + // does not exceed 2^16, which is the case in all the models + // we have seen so far. + // TODO(b/174275578): Add a check to make sure the + // accumulator depth is smaller than 2^16. + acc += filter_val * (input_val + input_offset); + } + } + } + if (bias_data) { + acc += bias_data[output_channel]; + } + acc = MultiplyByQuantizedMultiplier( + acc, output_multiplier[output_channel], + output_shift[output_channel]); + acc += output_offset; + acc = std::max(acc, output_activation_min); + acc = std::min(acc, output_activation_max); + output_data[Offset(output_shape, batch, out_y, out_x, + output_channel)] = static_cast(acc); + } + } + } + } + } +} + +inline void DepthwiseConvPerChannel( + const DepthwiseParams ¶ms, const int32_t *output_multiplier, + const int32_t *output_shift, const RuntimeShape &input_shape, + const int16_t *input_data, const RuntimeShape &filter_shape, + const int8_t *filter_data, const RuntimeShape &bias_shape, + const std::int64_t *bias_data, const RuntimeShape &output_shape, + int16_t *output_data) +{ + // Get parameters. + const int stride_width = params.stride_width; + const int stride_height = params.stride_height; + const int dilation_width_factor = params.dilation_width_factor; + const int dilation_height_factor = params.dilation_height_factor; + const int pad_width = params.padding_values.width; + const int pad_height = params.padding_values.height; + const int depth_multiplier = params.depth_multiplier; + const int32_t output_activation_min = params.quantized_activation_min; + const int32_t output_activation_max = params.quantized_activation_max; + + // Check dimensions of the tensors. + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + + TFLITE_DCHECK_LE(output_activation_min, output_activation_max); + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int output_depth = MatchingDim(filter_shape, 3, output_shape, 3); + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int input_depth = input_shape.Dims(3); + const int filter_height = filter_shape.Dims(1); + const int filter_width = filter_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + TFLITE_DCHECK_EQ(output_depth, input_depth * depth_multiplier); + TFLITE_DCHECK_EQ(bias_shape.FlatSize(), output_depth); + + for (int batch = 0; batch < batches; ++batch) { + for (int out_y = 0; out_y < output_height; ++out_y) { + for (int out_x = 0; out_x < output_width; ++out_x) { + for (int in_channel = 0; in_channel < input_depth; ++in_channel) { + for (int m = 0; m < depth_multiplier; ++m) { + const int output_channel = m + in_channel * depth_multiplier; + const int in_x_origin = (out_x * stride_width) - pad_width; + const int in_y_origin = (out_y * stride_height) - pad_height; + std::int64_t acc = 0; + for (int filter_y = 0; filter_y < filter_height; ++filter_y) { + for (int filter_x = 0; filter_x < filter_width; ++filter_x) { + const int in_x = in_x_origin + dilation_width_factor * filter_x; + const int in_y = + in_y_origin + dilation_height_factor * filter_y; + // Zero padding by omitting the areas outside the image. + const bool is_point_inside_image = + (in_x >= 0) && (in_x < input_width) && (in_y >= 0) && + (in_y < input_height); + if (is_point_inside_image) { + int32_t input_val = input_data[Offset( + input_shape, batch, in_y, in_x, in_channel)]; + int32_t filter_val = filter_data[Offset( + filter_shape, 0, filter_y, filter_x, output_channel)]; + // Accumulate with 64 bits accumulator. + // We assume maximum of 2^16 accumulations as with the 8-bit + // case so actually the value in the accumulator should not + // exceed 40 bits + acc += static_cast(filter_val) * + static_cast(input_val); + } + } + } + if (bias_data) { + acc += bias_data[output_channel]; + } + int32_t scaled_acc = MultiplyByQuantizedMultiplier( + acc, output_multiplier[output_channel], + output_shift[output_channel]); + scaled_acc = std::max(scaled_acc, output_activation_min); + scaled_acc = std::min(scaled_acc, output_activation_max); + output_data[Offset(output_shape, batch, out_y, out_x, + output_channel)] = + static_cast(scaled_acc); + } + } + } + } + } +} + +inline void DepthwiseConvHybridPerChannel( + const DepthwiseParams ¶ms, float *scaling_factors_ptr, + const RuntimeShape &input_shape, const int8_t *input_data, + const RuntimeShape &filter_shape, const int8_t *filter_data, + const RuntimeShape &bias_shape, const float *bias_data, + const RuntimeShape &output_shape, float *output_data, + const float *per_channel_scale, int32_t *input_offset) +{ + const int stride_width = params.stride_width; + const int stride_height = params.stride_height; + const int dilation_width_factor = params.dilation_width_factor; + const int dilation_height_factor = params.dilation_height_factor; + const int pad_width = params.padding_values.width; + const int pad_height = params.padding_values.height; + const int depth_multiplier = params.depth_multiplier; + const float output_activation_min = params.float_activation_min; + const float output_activation_max = params.float_activation_max; + // Check dimensions of the tensors. + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int output_depth = MatchingDim(filter_shape, 3, output_shape, 3); + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int input_depth = input_shape.Dims(3); + const int filter_height = filter_shape.Dims(1); + const int filter_width = filter_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + const int bias_depth = bias_shape.FlatSize(); + TFLITE_DCHECK_EQ(output_depth, input_depth * depth_multiplier); + TFLITE_DCHECK_EQ(bias_depth, output_depth); + + for (int batch = 0; batch < batches; ++batch) { + for (int out_y = 0; out_y < output_height; ++out_y) { + for (int out_x = 0; out_x < output_width; ++out_x) { + for (int in_channel = 0; in_channel < input_depth; ++in_channel) { + for (int m = 0; m < depth_multiplier; ++m) { + const int output_channel = m + in_channel * depth_multiplier; + const int in_x_origin = (out_x * stride_width) - pad_width; + const int in_y_origin = (out_y * stride_height) - pad_height; + int32_t acc = 0; + for (int filter_y = 0; filter_y < filter_height; ++filter_y) { + for (int filter_x = 0; filter_x < filter_width; ++filter_x) { + const int in_x = in_x_origin + dilation_width_factor * filter_x; + const int in_y = + in_y_origin + dilation_height_factor * filter_y; + // Zero padding by omitting the areas outside the image. + const bool is_point_inside_image = + (in_x >= 0) && (in_x < input_width) && (in_y >= 0) && + (in_y < input_height); + if (is_point_inside_image) { + int32_t input_val = input_data[Offset( + input_shape, batch, in_y, in_x, in_channel)]; + int32_t filter_val = filter_data[Offset( + filter_shape, 0, filter_y, filter_x, output_channel)]; + acc += filter_val * (input_val - input_offset[batch]); + } + } + } + float acc_float = static_cast(acc); + acc_float *= + per_channel_scale[output_channel] * scaling_factors_ptr[batch]; + if (bias_data && output_channel < bias_depth) { + acc_float += bias_data[output_channel]; + } + output_data[Offset(output_shape, batch, out_y, out_x, + output_channel)] = + ActivationFunctionWithMinMax(acc_float, output_activation_min, + output_activation_max); + } + } + } + } + } +} + +} // namespace reference_integer_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_DEPTHWISE_CONV_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/fully_connected.h b/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/fully_connected.h new file mode 100644 index 00000000..4bae7de4 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/fully_connected.h @@ -0,0 +1,109 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_FULLY_CONNECTED_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_FULLY_CONNECTED_H_ + +#include "tensorflow/lite/kernels/internal/common.h" + +namespace tflite { +namespace reference_integer_ops { +inline void FullyConnected( + const FullyConnectedParams ¶ms, const RuntimeShape &input_shape, + const int8_t *input_data, const RuntimeShape &filter_shape, + const int8_t *filter_data, const RuntimeShape &bias_shape, + const int32_t *bias_data, const RuntimeShape &output_shape, + int8_t *output_data) +{ + const int32_t input_offset = params.input_offset; + const int32_t filter_offset = params.weights_offset; + const int32_t output_offset = params.output_offset; + const int32_t output_multiplier = params.output_multiplier; + const int output_shift = params.output_shift; + const int32_t output_activation_min = params.quantized_activation_min; + const int32_t output_activation_max = params.quantized_activation_max; + TFLITE_DCHECK_GE(filter_shape.DimensionsCount(), 2); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 2); + + TFLITE_DCHECK_LE(output_activation_min, output_activation_max); + const int filter_dim_count = filter_shape.DimensionsCount(); + const int batches = output_shape.Dims(0); + const int output_depth = output_shape.Dims(1); + TFLITE_DCHECK_LE(output_depth, filter_shape.Dims(filter_dim_count - 2)); + const int accum_depth = filter_shape.Dims(filter_dim_count - 1); + for (int b = 0; b < batches; ++b) { + for (int out_c = 0; out_c < output_depth; ++out_c) { + int32_t acc = 0; + for (int d = 0; d < accum_depth; ++d) { + int32_t input_val = input_data[b * accum_depth + d]; + int32_t filter_val = filter_data[out_c * accum_depth + d]; + acc += (filter_val + filter_offset) * (input_val + input_offset); + } + if (bias_data) { + acc += bias_data[out_c]; + } + acc = MultiplyByQuantizedMultiplier(acc, output_multiplier, output_shift); + acc += output_offset; + acc = std::max(acc, output_activation_min); + acc = std::min(acc, output_activation_max); + output_data[out_c + output_depth * b] = static_cast(acc); + } + } +} + +inline void FullyConnected( + const FullyConnectedParams ¶ms, const RuntimeShape &input_shape, + const int16_t *input_data, const RuntimeShape &filter_shape, + const int8_t *filter_data, const RuntimeShape &bias_shape, + const int64_t *bias_data, const RuntimeShape &output_shape, + int16_t *output_data) +{ + const int32_t filter_offset = params.weights_offset; + const int32_t output_multiplier = params.output_multiplier; + const int output_shift = params.output_shift; + const int32_t output_activation_min = params.quantized_activation_min; + const int32_t output_activation_max = params.quantized_activation_max; + TFLITE_DCHECK_GE(filter_shape.DimensionsCount(), 2); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 2); + + TFLITE_DCHECK_LE(output_activation_min, output_activation_max); + const int filter_dim_count = filter_shape.DimensionsCount(); + const int batches = output_shape.Dims(0); + const int output_depth = output_shape.Dims(1); + TFLITE_DCHECK_LE(output_depth, filter_shape.Dims(filter_dim_count - 2)); + const int accum_depth = filter_shape.Dims(filter_dim_count - 1); + for (int b = 0; b < batches; ++b) { + for (int out_c = 0; out_c < output_depth; ++out_c) { + int64_t acc = 0; + for (int d = 0; d < accum_depth; ++d) { + int32_t input_val = input_data[b * accum_depth + d]; + int32_t filter_val = filter_data[out_c * accum_depth + d]; + acc += (filter_val + filter_offset) * input_val; + } + if (bias_data) { + acc += bias_data[out_c]; + } + int32_t acc_scaled = + MultiplyByQuantizedMultiplier(acc, output_multiplier, output_shift); + acc_scaled = std::max(acc_scaled, output_activation_min); + acc_scaled = std::min(acc_scaled, output_activation_max); + output_data[out_c + output_depth * b] = static_cast(acc_scaled); + } + } +} + +} // namespace reference_integer_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_FULLY_CONNECTED_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/l2normalization.h b/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/l2normalization.h new file mode 100644 index 00000000..892e9fd3 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/l2normalization.h @@ -0,0 +1,65 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_L2NORMALIZATION_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_L2NORMALIZATION_H_ + +#include "tensorflow/lite/kernels/internal/common.h" + +namespace tflite { +namespace reference_integer_ops { +inline void L2Normalization(int32_t input_zero_point, int32_t outer_size, + int32_t depth, const int8_t *input_data, + int8_t *output_data) +{ + static constexpr int8_t kMinInt8 = std::numeric_limits::min(); + static constexpr int8_t kMaxInt8 = std::numeric_limits::max(); + // The output scale must be in sync with Prepare(). + // Output is in 1/128 scale so the actual output range is nudged from [-1, 1] + // to [-1, 127/128]. + static constexpr int32_t kOutputScale = 7; + for (int outer_index = 0; outer_index < outer_size; ++outer_index) { + // int32_t = (int8_t - int8_t) ^ 2. + // ([-128, 127] - [-128, 127]) ^ 2 = [0, (2^8 - 1)^2] so the accumulator is + // safe from overflowing in at least 2^16 steps. + int32_t acc = 0; + for (int inner_index = 0; inner_index < depth; ++inner_index) { + int32_t input = + input_data[depth * outer_index + inner_index] - input_zero_point; + acc += input * input; + } + int32_t inv_l2norm_multiplier; + int inv_l2norm_shift; + GetInvSqrtQuantizedMultiplierExp(acc, kReverseShift, &inv_l2norm_multiplier, + &inv_l2norm_shift); + + for (int inner_index = 0; inner_index < depth; ++inner_index) { + int32_t input = + input_data[depth * outer_index + inner_index] - input_zero_point; + + // Rescale and downcast. Rescale is folded into the division. + int32_t output_in_q24 = MultiplyByQuantizedMultiplier( + input, inv_l2norm_multiplier, inv_l2norm_shift + kOutputScale); + output_in_q24 = + std::min(static_cast(kMaxInt8), + std::max(static_cast(kMinInt8), output_in_q24)); + output_data[depth * outer_index + inner_index] = + static_cast(output_in_q24); + } + } +} +} // namespace reference_integer_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_L2NORMALIZATION_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/logistic.h b/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/logistic.h new file mode 100644 index 00000000..c19d6a4e --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/logistic.h @@ -0,0 +1,119 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_LOGISTIC_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_LOGISTIC_H_ + +#include +#include "tensorflow/lite/kernels/internal/common.h" + +namespace tflite { +namespace reference_integer_ops { +inline void Logistic(int32_t input_zero_point, int32_t input_range_radius, + int32_t input_multiplier, int32_t input_left_shift, + int32_t input_size, const int8_t *input_data, + int8_t *output_data) +{ + // Integer bits must be in sync with Prepare() function. + static constexpr int32_t kInputIntegerBits = 4; + static constexpr int32_t kOutputIntegerBits = 8; + static constexpr int8_t kMinInt8 = std::numeric_limits::min(); + static constexpr int8_t kMaxInt8 = std::numeric_limits::max(); + static constexpr int32_t kOutputZeroPoint = -128; + + for (int i = 0; i < input_size; ++i) { + const int32_t input = + static_cast(input_data[i]) - input_zero_point; + if (input <= -input_range_radius) { + output_data[i] = kMinInt8; + } else if (input >= input_range_radius) { + output_data[i] = kMaxInt8; + } else { + const int32_t input_in_q4 = MultiplyByQuantizedMultiplier( + input, input_multiplier, input_left_shift); + using FixedPoint4 = gemmlowp::FixedPoint; + const int32_t output_in_q0 = + gemmlowp::logistic(FixedPoint4::FromRaw(input_in_q4)).raw(); + + // Rescale and downcast. + using gemmlowp::RoundingDivideByPOT; + int32_t output_in_q23 = + RoundingDivideByPOT(output_in_q0, 31 - kOutputIntegerBits); + output_in_q23 = std::min(std::max(output_in_q23 + kOutputZeroPoint, + static_cast(kMinInt8)), + static_cast(kMaxInt8)); + output_data[i] = static_cast(output_in_q23); + } + } +} + +inline void Logistic(int32_t input_multiplier, int32_t input_left_shift, + int32_t input_size, const int16_t *ptr_input_data, + int16_t *ptr_output_data) +{ + // We use the LUT for sigmoid and take into account, that + // tanh(x) = 2*sigmoid(2*x) - 1 + + // We scale by 3/4 to expand range [-8,8]->[-10.7,10.7]. + // In case of general parameter scale, multiplier 3 is taken into account + // in TanhPrepare function and it is included in + // input_multiplier already. + + TFLITE_DCHECK_GE(input_left_shift, 0); + if (input_multiplier == 0) { // power of two case + input_multiplier = 3 << input_left_shift; + input_left_shift = 0; + } + + int32_t round = (input_left_shift > 0) ? 1 << (input_left_shift - 1) : 0; + + for (int i = 0; i < input_size; ++i, ptr_input_data++, ptr_output_data++) { + int32_t input_data = + ((*ptr_input_data) * input_multiplier + round) >> input_left_shift; + + // We do interpolation on unsigned values. + uint32_t abs_input_data = abs(input_data); + + // We divide by 2 power of 9, because + // we need to divide by 2 in power of 7 for + // the input conversion + 1/4 from the scale above. + + // Define uh as uint32_t type not to make this function overflow. + uint32_t uh = abs_input_data >> 9; + uint32_t result; + + if (uh >= 255) { + // Saturate to maximum. + result = 0x7FFF << 10; + } else { + uint32_t ua = sigmoid_table_uint16[uh]; + uint32_t ub = sigmoid_table_uint16[uh + 1]; + uint32_t ut = abs_input_data & 0x1ff; + // Interpolation is done using the fractional bit. + result = (ua << 9) + ut * (ub - ua); + } + + result = (input_data >= 0) ? (result + (1 << 9)) : ((1 << (16 + 9)) - result + (1 << 9) - 1); + + // Back to 16-bit. + result >>= 10; + + *ptr_output_data = result; + } +} + +} // namespace reference_integer_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_LOGISTIC_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/mean.h b/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/mean.h new file mode 100644 index 00000000..0b22070a --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/mean.h @@ -0,0 +1,76 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_MEAN_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_MEAN_H_ + +#include "tensorflow/lite/kernels/internal/common.h" + +namespace tflite { +namespace reference_integer_ops { +template +inline void Mean(const tflite::MeanParams &op_params, int32_t multiplier, + int32_t shift, const RuntimeShape &unextended_input_shape, + const integer_type *input_data, int32_t input_zero_point, + const RuntimeShape &unextended_output_shape, + integer_type *output_data, int32_t output_zero_point) +{ + // Current implementation only supports dimension equals 4 and simultaneous + // reduction over width and height. + TFLITE_CHECK_EQ(unextended_input_shape.DimensionsCount(), 4); + TFLITE_CHECK_LE(unextended_output_shape.DimensionsCount(), 4); + const RuntimeShape input_shape = + RuntimeShape::ExtendedShape(4, unextended_input_shape); + const RuntimeShape output_shape = + RuntimeShape::ExtendedShape(4, unextended_output_shape); + const int output_batch = output_shape.Dims(0); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + const int output_depth = output_shape.Dims(3); + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int num_elements_in_axis = input_width * input_height; + + TFLITE_CHECK_EQ(op_params.axis_count, 2); + TFLITE_CHECK((op_params.axis[0] == 1 && op_params.axis[1] == 2) || + (op_params.axis[0] == 2 && op_params.axis[1] == 1)); + TFLITE_CHECK_EQ(output_height, 1); + TFLITE_CHECK_EQ(output_width, 1); + + static constexpr int32_t kMinInt = std::numeric_limits::min(); + static constexpr int32_t kMaxInt = std::numeric_limits::max(); + + for (int out_b = 0; out_b < output_batch; ++out_b) { + for (int out_d = 0; out_d < output_depth; ++out_d) { + int32_t acc = 0; + for (int in_h = 0; in_h < input_height; ++in_h) { + for (int in_w = 0; in_w < input_width; ++in_w) { + acc += input_data[Offset(input_shape, out_b, in_h, in_w, out_d)] - + input_zero_point; + } + } + acc = MultiplyByQuantizedMultiplier(acc, multiplier, shift); + acc = acc > 0 ? (acc + num_elements_in_axis / 2) / num_elements_in_axis : (acc - num_elements_in_axis / 2) / num_elements_in_axis; + acc += output_zero_point; + acc = std::min(std::max(acc, kMinInt), kMaxInt); + output_data[Offset(output_shape, out_b, 0, 0, out_d)] = + static_cast(acc); + } + } +} + +} // namespace reference_integer_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_MEAN_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/mul.h b/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/mul.h new file mode 100644 index 00000000..20120a77 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/mul.h @@ -0,0 +1,134 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_MUL_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_MUL_H_ + +#include "fixedpoint/fixedpoint.h" +#include "ruy/profiler/instrumentation.h" // from @ruy +#include "tensorflow/lite/kernels/internal/common.h" + +namespace tflite { +namespace reference_integer_ops { +template +inline void MulElementwise(int size, const ArithmeticParams ¶ms, + const T *input1_data, const T *input2_data, + T *output_data) +{ + for (int i = 0; i < size; ++i) { + const int32_t input1_val = params.input1_offset + input1_data[i]; + const int32_t input2_val = params.input2_offset + input2_data[i]; + const int32_t unclamped_result = + params.output_offset + + MultiplyByQuantizedMultiplier(input1_val * input2_val, + params.output_multiplier, + params.output_shift); + const int32_t clamped_output = + std::min(params.quantized_activation_max, + std::max(params.quantized_activation_min, unclamped_result)); + output_data[i] = static_cast(clamped_output); + } +} + +template +inline void Mul(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, const T *input1_data, + const RuntimeShape &input2_shape, const T *input2_data, + const RuntimeShape &output_shape, T *output_data) +{ + TFLITE_DCHECK_LE(params.quantized_activation_min, + params.quantized_activation_max); + ruy::profiler::ScopeLabel label("Mul/8bit"); + const int flat_size = + MatchingElementsSize(input1_shape, input2_shape, output_shape); + + MulElementwise(flat_size, params, input1_data, input2_data, output_data); +} + +// Mul with 16 bit inputs and int8_t outputs. +inline void Mul(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, const int16_t *input1_data, + const RuntimeShape &input2_shape, const int16_t *input2_data, + const RuntimeShape &output_shape, int8_t *output_data) +{ + ruy::profiler::ScopeLabel label("Mul/Int16Int8"); + int32_t output_offset = params.output_offset; + int32_t output_activation_min = params.quantized_activation_min; + int32_t output_activation_max = params.quantized_activation_max; + TFLITE_DCHECK_LE(output_activation_min, output_activation_max); + + const int flat_size = + MatchingElementsSize(input1_shape, input2_shape, output_shape); + + for (int i = 0; i < flat_size; i++) { + // F0 uses 0 integer bits, range [-1, 1]. + using F0 = gemmlowp::FixedPoint; + + F0 unclamped_result = + F0::FromRaw(input1_data[i]) * F0::FromRaw(input2_data[i]); + int16_t rescaled_result = + gemmlowp::RoundingDivideByPOT(unclamped_result.raw(), 8); + int16_t clamped_result = std::min( + output_activation_max - output_offset, rescaled_result); + clamped_result = std::max(output_activation_min - output_offset, + clamped_result); + output_data[i] = output_offset + clamped_result; + } +} + +template +inline void BroadcastMul4DSlow( + const ArithmeticParams ¶ms, const RuntimeShape &input1_shape, + const T *input1_data, const RuntimeShape &input2_shape, + const T *input2_data, const RuntimeShape &output_shape, T *output_data) +{ + ruy::profiler::ScopeLabel label("BroadcastMul4DSlow"); + + NdArrayDesc<4> desc1; + NdArrayDesc<4> desc2; + // The input shapes are extended as part of NdArrayDesc initialization. + NdArrayDescsForElementwiseBroadcast(input1_shape, input2_shape, &desc1, + &desc2); + const RuntimeShape extended_output_shape = + RuntimeShape::ExtendedShape(4, output_shape); + + for (int b = 0; b < extended_output_shape.Dims(0); ++b) { + for (int y = 0; y < extended_output_shape.Dims(1); ++y) { + for (int x = 0; x < extended_output_shape.Dims(2); ++x) { + for (int c = 0; c < extended_output_shape.Dims(3); ++c) { + const int32_t input1_val = + params.input1_offset + + input1_data[SubscriptToIndex(desc1, b, y, x, c)]; + const int32_t input2_val = + params.input2_offset + + input2_data[SubscriptToIndex(desc2, b, y, x, c)]; + const int32_t unclamped_result = + params.output_offset + + MultiplyByQuantizedMultiplier(input1_val * input2_val, + params.output_multiplier, + params.output_shift); + const int32_t clamped_output = std::min( + params.quantized_activation_max, + std::max(params.quantized_activation_min, unclamped_result)); + output_data[Offset(extended_output_shape, b, y, x, c)] = + static_cast(clamped_output); + } + } + } + } +} + +} // namespace reference_integer_ops +} // namespace tflite +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_MUL_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/pooling.h b/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/pooling.h new file mode 100644 index 00000000..7f2180f0 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/pooling.h @@ -0,0 +1,259 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_POOLING_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_POOLING_H_ + +#include +#include "tensorflow/lite/kernels/internal/common.h" + +namespace tflite { +namespace reference_integer_ops { +inline void AveragePool(const PoolParams ¶ms, + const RuntimeShape &input_shape, + const int8_t *input_data, + const RuntimeShape &output_shape, int8_t *output_data) +{ + TFLITE_DCHECK_LE(params.quantized_activation_min, + params.quantized_activation_max); + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int depth = MatchingDim(input_shape, 3, output_shape, 3); + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + const int stride_height = params.stride_height; + const int stride_width = params.stride_width; + for (int batch = 0; batch < batches; ++batch) { + for (int out_y = 0; out_y < output_height; ++out_y) { + for (int out_x = 0; out_x < output_width; ++out_x) { + for (int channel = 0; channel < depth; ++channel) { + const int in_x_origin = + (out_x * stride_width) - params.padding_values.width; + const int in_y_origin = + (out_y * stride_height) - params.padding_values.height; + // Compute the boundaries of the filter region clamped so as to + // ensure that the filter window fits in the input array. + const int filter_x_start = std::max(0, -in_x_origin); + const int filter_x_end = + std::min(params.filter_width, input_width - in_x_origin); + const int filter_y_start = std::max(0, -in_y_origin); + const int filter_y_end = + std::min(params.filter_height, input_height - in_y_origin); + int32_t acc = 0; + int filter_count = 0; + for (int filter_y = filter_y_start; filter_y < filter_y_end; + ++filter_y) { + for (int filter_x = filter_x_start; filter_x < filter_x_end; + ++filter_x) { + const int in_x = in_x_origin + filter_x; + const int in_y = in_y_origin + filter_y; + acc += + input_data[Offset(input_shape, batch, in_y, in_x, channel)]; + filter_count++; + } + } + // Round to the closest integer value. + acc = acc > 0 ? (acc + filter_count / 2) / filter_count : (acc - filter_count / 2) / filter_count; + acc = std::max(acc, params.quantized_activation_min); + acc = std::min(acc, params.quantized_activation_max); + output_data[Offset(output_shape, batch, out_y, out_x, channel)] = + static_cast(acc); + } + } + } + } +} + +inline void MaxPool(const PoolParams ¶ms, const RuntimeShape &input_shape, + const int8_t *input_data, const RuntimeShape &output_shape, + int8_t *output_data) +{ + TFLITE_DCHECK_LE(params.quantized_activation_min, + params.quantized_activation_max); + TFLITE_DCHECK_GE(params.quantized_activation_min, + std::numeric_limits::min()); + TFLITE_DCHECK_LE(params.quantized_activation_max, + std::numeric_limits::max()); + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int depth = MatchingDim(input_shape, 3, output_shape, 3); + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + const int stride_height = params.stride_height; + const int stride_width = params.stride_width; + for (int batch = 0; batch < batches; ++batch) { + for (int out_y = 0; out_y < output_height; ++out_y) { + for (int out_x = 0; out_x < output_width; ++out_x) { + for (int channel = 0; channel < depth; ++channel) { + const int in_x_origin = + (out_x * stride_width) - params.padding_values.width; + const int in_y_origin = + (out_y * stride_height) - params.padding_values.height; + // Compute the boundaries of the filter region clamped so as to + // ensure that the filter window fits in the input array. + const int filter_x_start = std::max(0, -in_x_origin); + const int filter_x_end = + std::min(params.filter_width, input_width - in_x_origin); + const int filter_y_start = std::max(0, -in_y_origin); + const int filter_y_end = + std::min(params.filter_height, input_height - in_y_origin); + int8_t max = std::numeric_limits::lowest(); + for (int filter_y = filter_y_start; filter_y < filter_y_end; + ++filter_y) { + for (int filter_x = filter_x_start; filter_x < filter_x_end; + ++filter_x) { + const int in_x = in_x_origin + filter_x; + const int in_y = in_y_origin + filter_y; + max = std::max( + max, + input_data[Offset(input_shape, batch, in_y, in_x, channel)]); + } + } + max = std::max(max, params.quantized_activation_min); + max = std::min(max, params.quantized_activation_max); + output_data[Offset(output_shape, batch, out_y, out_x, channel)] = + static_cast(max); + } + } + } + } +} + +inline void AveragePool(const PoolParams ¶ms, + const RuntimeShape &input_shape, + const int16_t *input_data, + const RuntimeShape &output_shape, + int16_t *output_data) +{ + TFLITE_DCHECK_LE(params.quantized_activation_min, + params.quantized_activation_max); + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int depth = MatchingDim(input_shape, 3, output_shape, 3); + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + const int stride_height = params.stride_height; + const int stride_width = params.stride_width; + for (int batch = 0; batch < batches; ++batch) { + for (int out_y = 0; out_y < output_height; ++out_y) { + for (int out_x = 0; out_x < output_width; ++out_x) { + for (int channel = 0; channel < depth; ++channel) { + const int in_x_origin = + (out_x * stride_width) - params.padding_values.width; + const int in_y_origin = + (out_y * stride_height) - params.padding_values.height; + // Compute the boundaries of the filter region clamped so as to + // ensure that the filter window fits in the input array. + const int filter_x_start = std::max(0, -in_x_origin); + const int filter_x_end = + std::min(params.filter_width, input_width - in_x_origin); + const int filter_y_start = std::max(0, -in_y_origin); + const int filter_y_end = + std::min(params.filter_height, input_height - in_y_origin); + int32_t acc = 0; + int filter_count = 0; + for (int filter_y = filter_y_start; filter_y < filter_y_end; + ++filter_y) { + for (int filter_x = filter_x_start; filter_x < filter_x_end; + ++filter_x) { + const int in_x = in_x_origin + filter_x; + const int in_y = in_y_origin + filter_y; + acc += + input_data[Offset(input_shape, batch, in_y, in_x, channel)]; + filter_count++; + } + } + // Round to the closest integer value. + acc = acc > 0 ? (acc + filter_count / 2) / filter_count : (acc - filter_count / 2) / filter_count; + acc = std::max(acc, params.quantized_activation_min); + acc = std::min(acc, params.quantized_activation_max); + output_data[Offset(output_shape, batch, out_y, out_x, channel)] = + static_cast(acc); + } + } + } + } +} + +inline void MaxPool(const PoolParams ¶ms, const RuntimeShape &input_shape, + const int16_t *input_data, const RuntimeShape &output_shape, + int16_t *output_data) +{ + TFLITE_DCHECK_LE(params.quantized_activation_min, + params.quantized_activation_max); + TFLITE_DCHECK_GE(params.quantized_activation_min, + std::numeric_limits::min()); + TFLITE_DCHECK_LE(params.quantized_activation_max, + std::numeric_limits::max()); + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int depth = MatchingDim(input_shape, 3, output_shape, 3); + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + const int stride_height = params.stride_height; + const int stride_width = params.stride_width; + for (int batch = 0; batch < batches; ++batch) { + for (int out_y = 0; out_y < output_height; ++out_y) { + for (int out_x = 0; out_x < output_width; ++out_x) { + for (int channel = 0; channel < depth; ++channel) { + const int in_x_origin = + (out_x * stride_width) - params.padding_values.width; + const int in_y_origin = + (out_y * stride_height) - params.padding_values.height; + // Compute the boundaries of the filter region clamped so as to + // ensure that the filter window fits in the input array. + const int filter_x_start = std::max(0, -in_x_origin); + const int filter_x_end = + std::min(params.filter_width, input_width - in_x_origin); + const int filter_y_start = std::max(0, -in_y_origin); + const int filter_y_end = + std::min(params.filter_height, input_height - in_y_origin); + int16_t max = std::numeric_limits::lowest(); + for (int filter_y = filter_y_start; filter_y < filter_y_end; + ++filter_y) { + for (int filter_x = filter_x_start; filter_x < filter_x_end; + ++filter_x) { + const int in_x = in_x_origin + filter_x; + const int in_y = in_y_origin + filter_y; + max = std::max( + max, + input_data[Offset(input_shape, batch, in_y, in_x, channel)]); + } + } + max = std::max(max, params.quantized_activation_min); + max = std::min(max, params.quantized_activation_max); + output_data[Offset(output_shape, batch, out_y, out_x, channel)] = + static_cast(max); + } + } + } + } +} + +} // namespace reference_integer_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_POOLING_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/tanh.h b/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/tanh.h new file mode 100644 index 00000000..762c7f18 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/tanh.h @@ -0,0 +1,115 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_TANH_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_TANH_H_ + +#include + +#include "fixedpoint/fixedpoint.h" +#include "tensorflow/lite/kernels/internal/common.h" + +namespace tflite { +namespace reference_integer_ops { +inline void Tanh(int32_t input_zero_point, int32_t input_range_radius, + int32_t input_multiplier, int32_t input_shift, + const RuntimeShape &input_shape, const int8_t *input_data, + const RuntimeShape &output_shape, int8_t *output_data) +{ + // Integer bits must be in sync with Prepare() function. + static constexpr int32_t kInputIntegerBits = 4; + static constexpr int32_t kOutputScale = 7; + static constexpr int32_t kMinInt8 = std::numeric_limits::min(); + static constexpr int32_t kMaxInt8 = std::numeric_limits::max(); + using F4 = gemmlowp::FixedPoint; + + const int flat_size = MatchingFlatSize(input_shape, output_shape); + + for (int i = 0; i < flat_size; ++i) { + const int32_t input = + static_cast(input_data[i]) - input_zero_point; + if (input <= -input_range_radius) { + output_data[i] = kMinInt8; + } else if (input >= input_range_radius) { + output_data[i] = kMaxInt8; + } else { + const int32_t input_in_q4 = + MultiplyByQuantizedMultiplier(input, input_multiplier, input_shift); + const int32_t output_in_q0 = + gemmlowp::tanh(F4::FromRaw(input_in_q4)).raw(); + + // Rescale and downcast. + using gemmlowp::RoundingDivideByPOT; + int32_t output_in_q24 = + RoundingDivideByPOT(output_in_q0, 31 - kOutputScale); + output_in_q24 = std::min(std::max(output_in_q24, kMinInt8), kMaxInt8); + output_data[i] = static_cast(output_in_q24); + } + } +} + +inline void Tanh(int32_t input_multiplier, int32_t input_left_shift, + const RuntimeShape &input_shape, const int16_t *ptr_input_data, + const RuntimeShape &output_shape, int16_t *ptr_output_data) +{ + // We use the LUT for sigmoid and take into account, that + // tanh(x) = 2*sigmoid(2*x) - 1 + + // We scale by 3/4 to expand range [-8,8]->[-10.7,10.7]. + // In case of general parameter scale, multiplier 3 is taken into account + // in TanhPrepare function and it is included in + // input_multiplier already. + + if (input_multiplier == 0) { // power of two case + input_multiplier = 3 << input_left_shift; + input_left_shift = 0; + } + + int32_t round = (input_left_shift > 0) ? 1 << (input_left_shift - 1) : 0; + + int flat_size = MatchingFlatSize(input_shape, output_shape); + + for (int i = 0; i < flat_size; ++i, ptr_input_data++, ptr_output_data++) { + int32_t input_data = + ((*ptr_input_data) * input_multiplier + round) >> input_left_shift; + + uint32_t abs_input_data = abs(input_data); + uint32_t uh = abs_input_data >> 8; + int32_t result; + + if (uh >= 255) { + // Saturate to maximum. + result = 0xFFFF << 8; + } else { + uint32_t ua = sigmoid_table_uint16[uh]; + uint32_t ub = sigmoid_table_uint16[uh + 1]; + + uint8_t ut = abs_input_data & 0xFF; + + result = (ua << 8) + ut * (ub - ua); + } + + result = (input_data >= 0) ? (result - (1 << (14 + 9)) + (1 << (9 - 2))) : (-result + (1 << (14 + 9)) + (1 << (9 - 2)) - 1); + + // Convert back to 16-bit. + result >>= (9 - 1); + + *ptr_output_data = result; + } +} + +} // namespace reference_integer_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_TANH_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/transpose_conv.h b/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/transpose_conv.h new file mode 100644 index 00000000..d1bcb4a0 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/integer_ops/transpose_conv.h @@ -0,0 +1,222 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_TRANSPOSE_CONV_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_TRANSPOSE_CONV_H_ + +#include "tensorflow/lite/kernels/internal/common.h" + +namespace tflite { +namespace reference_integer_ops { +// Fixed-point per-channel-quantization transpose convolution reference kernel. +inline void TransposeConv( + const ConvParams ¶ms, const int32_t *output_multiplier, + const int32_t *output_shift, const RuntimeShape &input_shape, + const int8_t *input_data, const RuntimeShape &filter_shape, + const int8_t *filter_data, const RuntimeShape &bias_shape, + const int32_t *bias_data, const RuntimeShape &output_shape, + int8_t *output_data, const RuntimeShape &im2col_shape, int8_t *im2col_data, + int32_t *scratch_buffer) +{ + const int stride_width = params.stride_width; + const int stride_height = params.stride_height; + const int pad_width = params.padding_values.width; + const int pad_height = params.padding_values.height; + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + (void)im2col_data; // only used in optimized code. + (void)im2col_shape; // only used in optimized code. + + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int input_depth = MatchingDim(input_shape, 3, filter_shape, 3); + const int output_depth = MatchingDim(filter_shape, 0, output_shape, 3); + if (bias_data) { + TFLITE_DCHECK_EQ(bias_shape.FlatSize(), output_depth); + } + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int filter_height = filter_shape.Dims(1); + const int filter_width = filter_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + const int32_t input_offset = params.input_offset; + const int32_t output_offset = params.output_offset; + const int32_t output_activation_min = std::numeric_limits::min(); + const int32_t output_activation_max = std::numeric_limits::max(); + TFLITE_DCHECK_LE(output_activation_min, output_activation_max); + + const int num_elements = output_shape.FlatSize(); + // We need to initialize scratch_buffer to all 0s, as we apply the same + // 'scatter' based trick as in float version. + memset(scratch_buffer, 0, num_elements * sizeof(int32_t)); + + // Loop through input elements one at a time. + for (int batch = 0; batch < batches; ++batch) { + for (int in_y = 0; in_y < input_height; ++in_y) { + for (int in_x = 0; in_x < input_width; ++in_x) { + for (int in_channel = 0; in_channel < input_depth; ++in_channel) { + // Loop through the output elements it will influence. + const int out_x_origin = (in_x * stride_width) - pad_width; + const int out_y_origin = (in_y * stride_height) - pad_height; + for (int filter_y = 0; filter_y < filter_height; ++filter_y) { + for (int filter_x = 0; filter_x < filter_width; ++filter_x) { + for (int out_channel = 0; out_channel < output_depth; + ++out_channel) { + // Compute output element location. + const int out_x = out_x_origin + filter_x; + const int out_y = out_y_origin + filter_y; + // We cannot accumulate out of bounds. + if ((out_x >= 0) && (out_x < output_width) && (out_y >= 0) && + (out_y < output_height)) { + const int8_t input_value = input_data[Offset( + input_shape, batch, in_y, in_x, in_channel)]; + const int8_t filter_value = + filter_data[Offset(filter_shape, out_channel, filter_y, + filter_x, in_channel)]; + scratch_buffer[Offset(output_shape, batch, out_y, out_x, + out_channel)] += + (input_value + input_offset) * filter_value; + } + } + } + } + } + } + } + } + + for (int batch = 0; batch < batches; ++batch) { + for (int out_y = 0; out_y < output_height; ++out_y) { + for (int out_x = 0; out_x < output_width; ++out_x) { + for (int out_channel = 0; out_channel < output_depth; ++out_channel) { + int32_t acc = scratch_buffer[Offset(output_shape, batch, out_y, out_x, + out_channel)]; + if (bias_data) { + acc += bias_data[out_channel]; + } + acc = MultiplyByQuantizedMultiplier( + acc, output_multiplier[out_channel], output_shift[out_channel]); + acc += output_offset; + acc = std::max(acc, output_activation_min); + acc = std::min(acc, output_activation_max); + output_data[Offset(output_shape, batch, out_y, out_x, out_channel)] = + static_cast(acc); + } + } + } + } +} + +// int16_t input (zero_point=0), int8_t filter, int64 accumulator +inline void TransposeConv( + const ConvParams ¶ms, const int32_t *output_multiplier, + const int32_t *output_shift, const RuntimeShape &input_shape, + const int16_t *input_data, const RuntimeShape &filter_shape, + const int8_t *filter_data, const RuntimeShape &bias_shape, + const std::int64_t *bias_data, const RuntimeShape &output_shape, + int16_t *output_data, const RuntimeShape &im2col_shape, int8_t *im2col_data, + std::int64_t *scratch_buffer) +{ + const int stride_width = params.stride_width; + const int stride_height = params.stride_height; + const int pad_width = params.padding_values.width; + const int pad_height = params.padding_values.height; + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + (void)im2col_data; // only used in optimized code. + (void)im2col_shape; // only used in optimized code. + + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int input_depth = MatchingDim(input_shape, 3, filter_shape, 3); + const int output_depth = MatchingDim(filter_shape, 0, output_shape, 3); + if (bias_data) { + TFLITE_DCHECK_EQ(bias_shape.FlatSize(), output_depth); + } + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int filter_height = filter_shape.Dims(1); + const int filter_width = filter_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + const int32_t output_activation_min = std::numeric_limits::min(); + const int32_t output_activation_max = std::numeric_limits::max(); + TFLITE_DCHECK_LE(output_activation_min, output_activation_max); + + const int num_elements = output_shape.FlatSize(); + // We need to initialize scratch_buffer to all 0s, as we apply the same + // 'scatter' based trick as in float version. + memset(scratch_buffer, 0, num_elements * sizeof(std::int64_t)); + + // Loop through input elements one at a time. + for (int batch = 0; batch < batches; ++batch) { + for (int in_y = 0; in_y < input_height; ++in_y) { + for (int in_x = 0; in_x < input_width; ++in_x) { + for (int in_channel = 0; in_channel < input_depth; ++in_channel) { + // Loop through the output elements it will influence. + const int out_x_origin = (in_x * stride_width) - pad_width; + const int out_y_origin = (in_y * stride_height) - pad_height; + for (int filter_y = 0; filter_y < filter_height; ++filter_y) { + for (int filter_x = 0; filter_x < filter_width; ++filter_x) { + for (int out_channel = 0; out_channel < output_depth; + ++out_channel) { + // Compute output element location. + const int out_x = out_x_origin + filter_x; + const int out_y = out_y_origin + filter_y; + // We cannot accumulate out of bounds. + if ((out_x >= 0) && (out_x < output_width) && (out_y >= 0) && + (out_y < output_height)) { + const int32_t input_value = input_data[Offset( + input_shape, batch, in_y, in_x, in_channel)]; + const int32_t filter_value = + filter_data[Offset(filter_shape, out_channel, filter_y, + filter_x, in_channel)]; + scratch_buffer[Offset(output_shape, batch, out_y, out_x, + out_channel)] += + input_value * filter_value; + } + } + } + } + } + } + } + } + + for (int batch = 0; batch < batches; ++batch) { + for (int out_y = 0; out_y < output_height; ++out_y) { + for (int out_x = 0; out_x < output_width; ++out_x) { + for (int out_channel = 0; out_channel < output_depth; ++out_channel) { + std::int64_t acc = scratch_buffer[Offset(output_shape, batch, out_y, + out_x, out_channel)]; + if (bias_data) { + acc += bias_data[out_channel]; + } + int32_t scaled_acc = MultiplyByQuantizedMultiplier( + acc, output_multiplier[out_channel], output_shift[out_channel]); + scaled_acc = std::max(scaled_acc, output_activation_min); + scaled_acc = std::min(scaled_acc, output_activation_max); + output_data[Offset(output_shape, batch, out_y, out_x, out_channel)] = + static_cast(scaled_acc); + } + } + } + } +} + +} // namespace reference_integer_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_TRANSPOSE_CONV_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/l2normalization.h b/components/tflite/tensorflow/lite/kernels/internal/reference/l2normalization.h new file mode 100644 index 00000000..b6d6e354 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/l2normalization.h @@ -0,0 +1,90 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_L2NORMALIZATION_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_L2NORMALIZATION_H_ + +#include +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +inline void L2Normalization(const tflite::L2NormalizationParams &op_params, + const RuntimeShape &input_shape, + const float *input_data, + const RuntimeShape &output_shape, + float *output_data, float epsilon = 1e-6) +{ + const int trailing_dim = input_shape.DimensionsCount() - 1; + const int outer_size = + MatchingFlatSizeSkipDim(input_shape, trailing_dim, output_shape); + const int depth = + MatchingDim(input_shape, trailing_dim, output_shape, trailing_dim); + for (int i = 0; i < outer_size; ++i) { + float squared_l2_norm = 0; + for (int c = 0; c < depth; ++c) { + const float val = input_data[depth * i + c]; + squared_l2_norm += val * val; + } + float l2_norm = std::sqrt(squared_l2_norm); + l2_norm = std::max(l2_norm, epsilon); + for (int c = 0; c < depth; ++c) { + output_data[depth * i + c] = input_data[depth * i + c] / l2_norm; + } + } +} + +inline void L2Normalization(const tflite::L2NormalizationParams &op_params, + const RuntimeShape &input_shape, + const uint8_t *input_data, + const RuntimeShape &output_shape, + uint8_t *output_data) +{ + const int trailing_dim = input_shape.DimensionsCount() - 1; + const int depth = + MatchingDim(input_shape, trailing_dim, output_shape, trailing_dim); + const int outer_size = + MatchingFlatSizeSkipDim(input_shape, trailing_dim, output_shape); + const int32_t input_zero_point = op_params.input_zero_point; + + for (int i = 0; i < outer_size; ++i) { + int32_t square_l2_norm = 0; + for (int c = 0; c < depth; c++) { + int32_t diff = input_data[depth * i + c] - input_zero_point; + square_l2_norm += diff * diff; + } + int32_t inv_l2norm_multiplier; + int inv_l2norm_shift; + GetInvSqrtQuantizedMultiplierExp(square_l2_norm, kReverseShift, + &inv_l2norm_multiplier, &inv_l2norm_shift); + for (int c = 0; c < depth; c++) { + int32_t diff = input_data[depth * i + c] - input_zero_point; + int32_t rescaled_diff = MultiplyByQuantizedMultiplierSmallerThanOneExp( + 128 * diff, inv_l2norm_multiplier, inv_l2norm_shift); + int32_t unclamped_output_val = 128 + rescaled_diff; + int32_t output_val = + std::min(static_cast(255), + std::max(static_cast(0), unclamped_output_val)); + output_data[depth * i + c] = static_cast(output_val); + } + } +} + +} // namespace reference_ops +} // namespace tflite +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_L2NORMALIZATION_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/leaky_relu.h b/components/tflite/tensorflow/lite/kernels/internal/reference/leaky_relu.h new file mode 100644 index 00000000..f20d5d89 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/leaky_relu.h @@ -0,0 +1,70 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_LEAKY_RELU_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_LEAKY_RELU_H_ + +#include +#include + +#include "tensorflow/lite/kernels/internal/common.h" + +namespace tflite { +namespace reference_ops { +inline void LeakyRelu(const tflite::LeakyReluParams ¶ms, + const RuntimeShape &input_shape, const float *input_data, + const RuntimeShape &output_shape, float *output_data) +{ + const int flat_size = MatchingFlatSize(input_shape, output_shape); + for (int i = 0; i < flat_size; ++i) { + const float val = input_data[i]; + // Note that alpha might be > 1 or < 0, so we don't use std::max here. + output_data[i] = val > 0 ? val : val * params.alpha; + } +} + +template +inline void QuantizeLeakyRelu(const LeakyReluParams ¶ms, + const RuntimeShape &input_shape, + const T *input_data, + const RuntimeShape &output_shape, + T *output_data) +{ + const int flat_size = MatchingFlatSize(input_shape, output_shape); + static const int32_t quantized_min = std::numeric_limits::min(); + static const int32_t quantized_max = std::numeric_limits::max(); + for (int i = 0; i < flat_size; ++i) { + const int32_t input_value = input_data[i] - params.input_offset; + int32_t unclamped_output; + if (input_value >= 0) { + unclamped_output = params.output_offset + + MultiplyByQuantizedMultiplier( + input_value, params.output_multiplier_identity, + params.output_shift_identity); + } else { + unclamped_output = params.output_offset + + MultiplyByQuantizedMultiplier( + input_value, params.output_multiplier_alpha, + params.output_shift_alpha); + } + const T clamped_output = + std::min(quantized_max, std::max(quantized_min, unclamped_output)); + output_data[i] = static_cast(clamped_output); + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_LEAKY_RELU_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/log_softmax.h b/components/tflite/tensorflow/lite/kernels/internal/reference/log_softmax.h new file mode 100644 index 00000000..d64b6fe4 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/log_softmax.h @@ -0,0 +1,259 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_LOG_SOFTMAX_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_LOG_SOFTMAX_H_ + +#include +#include +#include + +#include "fixedpoint/fixedpoint.h" +#include "tensorflow/lite/kernels/internal/common.h" + +namespace tflite { +namespace reference_ops { +inline void LogSoftmax(const SoftmaxParams ¶ms, + const RuntimeShape &input_shape, const float *input_data, + const RuntimeShape &output_shape, float *output_data) +{ + const int trailing_dim = input_shape.DimensionsCount() - 1; + const int outer_size = + MatchingFlatSizeSkipDim(input_shape, trailing_dim, output_shape); + const int depth = + MatchingDim(input_shape, trailing_dim, output_shape, trailing_dim); + + for (int i = 0; i < outer_size; ++i) { + // Find max element value which we'll use to ensure numerical stability + // taking advantage of the following equality: + // log(exp(x[i])/sum(exp(x[i]))) == log(exp(x[i]+C)/sum(exp(x[i]+C))) + float max = std::numeric_limits::lowest(); + for (int c = 0; c < depth; ++c) { + max = std::max(max, input_data[i * depth + c]); + } + + // Compute sum. + float sum = 0.f; + for (int c = 0; c < depth; ++c) { + sum += std::exp(input_data[i * depth + c] - max); + } + + // Compute result. + const float log_sum = std::log(sum); + for (int c = 0; c < depth; ++c) { + output_data[i * depth + c] = input_data[i * depth + c] - max - log_sum; + } + } +} + +inline void LogSoftmax(const SoftmaxParams ¶ms, + const RuntimeShape &input_shape, + const uint8_t *input_data, + const RuntimeShape &output_shape, uint8_t *output_data) +{ + const int32_t input_multiplier = params.input_multiplier; + const int32_t input_left_shift = params.input_left_shift; + const int32_t reverse_scaling_divisor = params.reverse_scaling_divisor; + const int32_t reverse_scaling_right_shift = + params.reverse_scaling_right_shift; + const int diff_min = params.diff_min; + // The representation chosen for the input to the exp() function is Q5.26. + // We need to leave extra space since values that we skip might be as large + // as -32 before multiplying by input_beta_multiplier, and therefore as + // large as -16 afterwards. Note that exp(-8) is definitely not + // insignificant to accumulation, but exp(-16) definitely is. + static constexpr int kScaledDiffIntegerBits = 5; + static constexpr int kAccumulationIntegerBits = 12; + static constexpr int kOutputIntegerBits = 4; + using FixedPointScaledDiff = + gemmlowp::FixedPoint; + using FixedPointAccum = + gemmlowp::FixedPoint; + + const int trailing_dim = input_shape.DimensionsCount() - 1; + const int outer_size = + MatchingFlatSizeSkipDim(input_shape, trailing_dim, output_shape); + const int depth = + MatchingDim(input_shape, trailing_dim, output_shape, trailing_dim); + + for (int i = 0; i < outer_size; ++i) { + uint8_t max_in_row = 0; + for (int c = 0; c < depth; ++c) { + max_in_row = std::max(max_in_row, input_data[i * depth + c]); + } + + FixedPointAccum sum_of_exps = FixedPointAccum::Zero(); + for (int c = 0; c < depth; ++c) { + int32_t input_diff = + static_cast(input_data[i * depth + c]) - max_in_row; + if (input_diff >= diff_min) { + const int32_t input_diff_rescaled = + MultiplyByQuantizedMultiplierGreaterThanOne( + input_diff, input_multiplier, input_left_shift); + const FixedPointScaledDiff scaled_diff_f8 = + FixedPointScaledDiff::FromRaw(input_diff_rescaled); + sum_of_exps = sum_of_exps + gemmlowp::Rescale( + exp_on_negative_values(scaled_diff_f8)); + } + } + + const int32_t fixed_log_sum_of_exps = + log_x_for_x_greater_than_or_equal_to_1( + sum_of_exps) + .raw(); + + // rescaled_diff_min is smallest representable in + // Q(kScaledDiffIntegerBits).(31-kScaledDiffIntegerBits) plus the + // log-sub-exps that will be subtracted in the loop. + // + // The thresholds diff_min, etc are negative. + const int rescaled_diff_min = + fixed_log_sum_of_exps + std::numeric_limits::lowest(); + const int adjusted_diff_min = + std::max(static_cast( + diff_min - 1), // Note use of > below instead of >= above. + MultiplyByQuantizedMultiplierSmallerThanOneExp( + rescaled_diff_min, reverse_scaling_divisor, + -reverse_scaling_right_shift)); + + for (int c = 0; c < depth; ++c) { + int32_t input_diff = + static_cast(input_data[i * depth + c]) - max_in_row; + if (input_diff > adjusted_diff_min) { + const int32_t input_diff_rescaled = + MultiplyByQuantizedMultiplierGreaterThanOne( + input_diff, input_multiplier, input_left_shift); + int32_t unsat_output = + gemmlowp::RoundingDivideByPOT( + (input_diff_rescaled - fixed_log_sum_of_exps), + 31 - kScaledDiffIntegerBits - kOutputIntegerBits) + + 255; + + output_data[i * depth + c] = static_cast( + std::max(std::min(unsat_output, static_cast(255)), + static_cast(0))); + } else { + // Set output to smallest value. + output_data[i * depth + c] = 0; + } + } + } +} + +template +inline void LogSoftmaxQuantized(const SoftmaxParams ¶ms, + const size_t outer_size, const size_t depth, + const RuntimeShape &input_shape, + const T *input_data, + const RuntimeShape &output_shape, + T *output_data) +{ + const int32_t input_multiplier = params.input_multiplier; + const int32_t input_left_shift = params.input_left_shift; + const int32_t reverse_scaling_divisor = params.reverse_scaling_divisor; + const int32_t reverse_scaling_right_shift = + params.reverse_scaling_right_shift; + const int diff_min = params.diff_min; + + static constexpr T kMinT8 = std::numeric_limits::min(); + static constexpr T kMaxT8 = std::numeric_limits::max(); + static constexpr int32_t kMinInt32 = std::numeric_limits::min(); + + // All IntegerBits must agree with Prepare function. + // Input is chosen as Q5.26 so exp(-1 * 2^5 * 2^-1) = exp(-16) is negligible. + static constexpr int kInputIntegerBits = 5; + static constexpr int kAccumulationIntegerBits = 12; + static constexpr int kOutputIntegerBits = 4; + using F5 = gemmlowp::FixedPoint; + using F12 = gemmlowp::FixedPoint; + + for (size_t outer_index = 0; outer_index < outer_size; ++outer_index) { + T max_in_row = kMinT8; + for (size_t inner_index = 0; inner_index < depth; ++inner_index) { + max_in_row = + std::max(max_in_row, input_data[outer_index * depth + inner_index]); + } + + // Accumulator "sum_of_exps_in_q12" is safe from overflowing in 2^12 steps. + F12 sum_of_exps_in_q12 = F12::FromRaw(0); + for (size_t inner_index = 0; inner_index < depth; ++inner_index) { + int32_t input_diff = + static_cast(input_data[outer_index * depth + inner_index]) - + max_in_row; + if (input_diff >= diff_min) { + const int32_t input_diff_in_q5 = MultiplyByQuantizedMultiplier( + input_diff, input_multiplier, input_left_shift); + sum_of_exps_in_q12 = + sum_of_exps_in_q12 + + gemmlowp::Rescale( + exp_on_negative_values(F5::FromRaw(input_diff_in_q5))); + } + } + + const int32_t log_sum_of_exps_in_q5 = + log_x_for_x_greater_than_or_equal_to_1( + sum_of_exps_in_q12) + .raw(); + + // Potentially reduced the valid range. shifted_log_sum_of_exps_in_q5 is + // smallest representable in Q5.26 plus the log_sum_of_exps. + const int32_t shifted_log_sum_of_exps_in_q5 = + log_sum_of_exps_in_q5 + kMinInt32; + const int32_t adjusted_diff_min = + std::max(static_cast(diff_min - 1), + MultiplyByQuantizedMultiplier(shifted_log_sum_of_exps_in_q5, + reverse_scaling_divisor, + -reverse_scaling_right_shift)); + + for (size_t inner_index = 0; inner_index < depth; ++inner_index) { + int32_t input_diff = + static_cast(input_data[outer_index * depth + inner_index]) - + max_in_row; + // Note use of > below instead of >= above. + if (input_diff > adjusted_diff_min) { + const int32_t input_diff_in_q5 = MultiplyByQuantizedMultiplier( + input_diff, input_multiplier, input_left_shift); + + // Rescale and downcast. + int32_t output_in_q27 = + gemmlowp::RoundingDivideByPOT( + (input_diff_in_q5 - log_sum_of_exps_in_q5), + 31 - kInputIntegerBits - kOutputIntegerBits) + + kMaxT8; + + output_in_q27 = + std::max(std::min(output_in_q27, static_cast(kMaxT8)), + static_cast(kMinT8)); + output_data[outer_index * depth + inner_index] = + static_cast(output_in_q27); + } else { + output_data[outer_index * depth + inner_index] = kMinT8; + } + } + } +} + +inline void LogSoftmax(const SoftmaxParams ¶ms, const size_t outer_size, + const size_t depth, const RuntimeShape &input_shape, + const int8_t *input_data, + const RuntimeShape &output_shape, int8_t *output_data) +{ + LogSoftmaxQuantized(params, outer_size, depth, input_shape, input_data, + output_shape, output_data); +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_LOG_SOFTMAX_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/logistic.h b/components/tflite/tensorflow/lite/kernels/internal/reference/logistic.h new file mode 100644 index 00000000..5300293a --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/logistic.h @@ -0,0 +1,135 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_LOGISTIC_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_LOGISTIC_H_ + +#include + +#include "fixedpoint/fixedpoint.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/cppmath.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/types.h" +#include "tensorflow/lite/kernels/op_macros.h" + +namespace tflite { +namespace reference_ops { +inline void Logistic(const RuntimeShape &input_shape, const float *input_data, + const RuntimeShape &output_shape, float *output_data) +{ + const float cutoff_upper = 16.619047164916992188f; + const float cutoff_lower = -9.f; + + const int flat_size = MatchingFlatSize(input_shape, output_shape); + + // Rational for using approximation in reference kernel. + // 0. This approximation gives enough precision for float. + // 1. This works around an issue on an embedded chipset where exp() does not + // return correctly as expected - exp(x) should return inf when overflown + // not 1.701417 IEEE 754 defines representation for inf. + // 2. This will speed up calculation and is matching the behavior in the + // optimized kernels. (check the definition of scalar_logistic_op) + + for (int i = 0; i < flat_size; i++) { + float val = input_data[i]; + float result; + if (val > cutoff_upper) { + result = 1.0f; + } else if (val < cutoff_lower) { + result = std::exp(val); + } else { + result = 1.f / (1.f + std::exp(-val)); + } + output_data[i] = result; + } +} + +// Convenience version that allows, for example, generated-code calls to be +// uniform between data types. +inline void Logistic(const LogisticParams &, const RuntimeShape &input_shape, + const float *input_data, const RuntimeShape &output_shape, + float *output_data) +{ + // Drop params: not needed. + Logistic(input_shape, input_data, output_shape, output_data); +} + +inline void Logistic(const LogisticParams ¶ms, + const RuntimeShape &input_shape, const int16_t *input_data, + const RuntimeShape &output_shape, int16_t *output_data) +{ + const int flat_size = MatchingFlatSize(input_shape, output_shape); + + for (int i = 0; i < flat_size; i++) { + // F0 uses 0 integer bits, range [-1, 1]. + // This is the return type of math functions such as tanh, logistic, + // whose range is in [-1, 1]. + using F0 = gemmlowp::FixedPoint; + // F3 uses 3 integer bits, range [-8, 8], the input range expected here. + using F3 = gemmlowp::FixedPoint; + + const F3 input = F3::FromRaw(input_data[i]); + F0 output = gemmlowp::logistic(input); + output_data[i] = output.raw(); + } +} + +// Quantized int8_t logistic activation. Cheats by dequantizing and +// requantizing around the floating point logistic method. This implementation +// is slow on platforms without a floating point unit. + +// TODO(b/141211002): Delete this int8_t implementation once we can reuse the +// approach used in TFLite for int8_t Logistic. +inline void Logistic(const RuntimeShape &input_shape, const int8_t *input_data, + float input_scale, int input_zero_point, + const RuntimeShape &output_shape, int8_t *output_data, + float output_scale, int output_zero_point) +{ + const float cutoff_upper = 16.619047164916992188f; + const float cutoff_lower = -9.f; + + const int flat_size = MatchingFlatSize(input_shape, output_shape); + + // Rational for using approximation in reference kernel. + // 0. This approximation gives enough precision for float. + // 1. This works around an issue on an embedded chipset where exp() does not + // return correctly as expected - exp(x) should return inf when overflown + // not 1.701417 IEEE 754 defines representation for inf. + // 2. This will speed up calculation and is matching the behavior in the + // optimized kernels. (check the definition of scalar_logistic_op) + + for (int i = 0; i < flat_size; i++) { + // Dequantize. + float val = + static_cast((input_data[i] - input_zero_point) * input_scale); + float result; + if (val > cutoff_upper) { + result = 1.0f; + } else if (val < cutoff_lower) { + result = std::exp(val); + } else { + result = 1.f / (1.f + std::exp(-val)); + } + // Requantize + int8_t output = + static_cast(result / output_scale + output_zero_point); + output_data[i] = output; + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_LOGISTIC_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/maximum_minimum.h b/components/tflite/tensorflow/lite/kernels/internal/reference/maximum_minimum.h new file mode 100644 index 00000000..1f5872c9 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/maximum_minimum.h @@ -0,0 +1,64 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_MAXIMUM_MINIMUM_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_MAXIMUM_MINIMUM_H_ + +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +template +void MaximumMinimumBroadcastSlow(const RuntimeShape &unextended_input1_shape, + const T *input1_data, + const RuntimeShape &unextended_input2_shape, + const T *input2_data, + const RuntimeShape &unextended_output_shape, + T *output_data, Op op) +{ + // Uses element-wise calculation if broadcast is not required. + if (unextended_input1_shape == unextended_input2_shape) { + const int flat_size = + MatchingElementsSize(unextended_input1_shape, unextended_input2_shape, + unextended_output_shape); + for (int i = 0; i < flat_size; ++i) { + output_data[i] = op(input1_data[i], input2_data[i]); + } + } else { + TFLITE_DCHECK_LE(unextended_input1_shape.DimensionsCount(), N); + TFLITE_DCHECK_LE(unextended_input2_shape.DimensionsCount(), N); + TFLITE_DCHECK_LE(unextended_output_shape.DimensionsCount(), N); + + NdArrayDesc desc1; + NdArrayDesc desc2; + NdArrayDesc output_desc; + NdArrayDescsForElementwiseBroadcast( + unextended_input1_shape, unextended_input2_shape, &desc1, &desc2); + CopyDimsToDesc(RuntimeShape::ExtendedShape(N, unextended_output_shape), + &output_desc); + + auto maxmin_func = [&](int indexes[N]) { + output_data[SubscriptToIndex(output_desc, indexes)] = + op(input1_data[SubscriptToIndex(desc1, indexes)], + input2_data[SubscriptToIndex(desc2, indexes)]); + }; + NDOpsHelper(output_desc, maxmin_func); + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_MAXIMUM_MINIMUM_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/mul.h b/components/tflite/tensorflow/lite/kernels/internal/reference/mul.h new file mode 100644 index 00000000..9969bd0f --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/mul.h @@ -0,0 +1,169 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_MUL_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_MUL_H_ + +#include "tensorflow/lite/kernels/internal/common.h" + +namespace tflite { +namespace reference_ops { +// Element-wise mul that can often be used for inner loop of broadcast Mul as +// well as the non-broadcast Mul. +inline void MulElementwise(int size, const ArithmeticParams ¶ms, + const uint8_t *input1_data, + const uint8_t *input2_data, uint8_t *output_data) +{ + for (int i = 0; i < size; ++i) { + const int32_t input1_val = params.input1_offset + input1_data[i]; + const int32_t input2_val = params.input2_offset + input2_data[i]; + const int32_t unclamped_result = + params.output_offset + + MultiplyByQuantizedMultiplier(input1_val * input2_val, + params.output_multiplier, + params.output_shift); + const int32_t clamped_output = + std::min(params.quantized_activation_max, + std::max(params.quantized_activation_min, unclamped_result)); + output_data[i] = static_cast(clamped_output); + } +} + +template +inline void Mul(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, const T *input1_data, + const RuntimeShape &input2_shape, const T *input2_data, + const RuntimeShape &output_shape, T *output_data) +{ + T output_activation_min; + T output_activation_max; + GetActivationParams(params, &output_activation_min, &output_activation_max); + + const int flat_size = + MatchingFlatSize(input1_shape, input2_shape, output_shape); + for (int i = 0; i < flat_size; ++i) { + output_data[i] = ActivationFunctionWithMinMax( + input1_data[i] * input2_data[i], output_activation_min, + output_activation_max); + } +} + +inline void Mul(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, const uint8_t *input1_data, + const RuntimeShape &input2_shape, const uint8_t *input2_data, + const RuntimeShape &output_shape, uint8_t *output_data) +{ + TFLITE_DCHECK_LE(params.quantized_activation_min, + params.quantized_activation_max); + const int flat_size = + MatchingFlatSize(input1_shape, input2_shape, output_shape); + + MulElementwise(flat_size, params, input1_data, input2_data, output_data); +} + +inline void BroadcastMul4DSlow(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, + const uint8_t *input1_data, + const RuntimeShape &input2_shape, + const uint8_t *input2_data, + const RuntimeShape &output_shape, + uint8_t *output_data) +{ + NdArrayDesc<4> desc1; + NdArrayDesc<4> desc2; + NdArrayDescsForElementwiseBroadcast(input1_shape, input2_shape, &desc1, + &desc2); + const RuntimeShape extended_output_shape = + RuntimeShape::ExtendedShape(4, output_shape); + + for (int b = 0; b < extended_output_shape.Dims(0); ++b) { + for (int y = 0; y < extended_output_shape.Dims(1); ++y) { + for (int x = 0; x < extended_output_shape.Dims(2); ++x) { + for (int c = 0; c < extended_output_shape.Dims(3); ++c) { + const int32_t input1_val = + params.input1_offset + + input1_data[SubscriptToIndex(desc1, b, y, x, c)]; + const int32_t input2_val = + params.input2_offset + + input2_data[SubscriptToIndex(desc2, b, y, x, c)]; + const int32_t unclamped_result = + params.output_offset + + MultiplyByQuantizedMultiplier(input1_val * input2_val, + params.output_multiplier, + params.output_shift); + const int32_t clamped_output = std::min( + params.quantized_activation_max, + std::max(params.quantized_activation_min, unclamped_result)); + output_data[Offset(extended_output_shape, b, y, x, c)] = + static_cast(clamped_output); + } + } + } + } +} + +template +void BroadcastMul4DSlow(const ArithmeticParams ¶ms, + const RuntimeShape &unextended_input1_shape, + const T *input1_data, + const RuntimeShape &unextended_input2_shape, + const T *input2_data, + const RuntimeShape &unextended_output_shape, + T *output_data) +{ + T output_activation_min; + T output_activation_max; + GetActivationParams(params, &output_activation_min, &output_activation_max); + + TFLITE_DCHECK_LE(unextended_input1_shape.DimensionsCount(), 4); + TFLITE_DCHECK_LE(unextended_input2_shape.DimensionsCount(), 4); + TFLITE_DCHECK_LE(unextended_output_shape.DimensionsCount(), 4); + const RuntimeShape output_shape = + RuntimeShape::ExtendedShape(4, unextended_output_shape); + + NdArrayDesc<4> desc1; + NdArrayDesc<4> desc2; + NdArrayDescsForElementwiseBroadcast(unextended_input1_shape, + unextended_input2_shape, &desc1, &desc2); + + // In Tensorflow, the dimensions are canonically named (batch_number, row, + // col, channel), with extents (batches, height, width, depth), with the + // trailing dimension changing most rapidly (channels has the smallest stride, + // typically 1 element). + // + // In generated C code, we store arrays with the dimensions reversed. The + // first dimension has smallest stride. + // + // We name our variables by their Tensorflow convention, but generate C code + // nesting loops such that the innermost loop has the smallest stride for the + // best cache behavior. + for (int b = 0; b < output_shape.Dims(0); ++b) { + for (int y = 0; y < output_shape.Dims(1); ++y) { + for (int x = 0; x < output_shape.Dims(2); ++x) { + for (int c = 0; c < output_shape.Dims(3); ++c) { + output_data[Offset(output_shape, b, y, x, c)] = + ActivationFunctionWithMinMax( + input1_data[SubscriptToIndex(desc1, b, y, x, c)] * + input2_data[SubscriptToIndex(desc2, b, y, x, c)], + output_activation_min, output_activation_max); + } + } + } + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_MUL_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/neg.h b/components/tflite/tensorflow/lite/kernels/internal/reference/neg.h new file mode 100644 index 00000000..1f2014ed --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/neg.h @@ -0,0 +1,36 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_NEG_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_NEG_H_ + +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +template +inline void Negate(const RuntimeShape &input_shape, const T *input_data, + const RuntimeShape &output_shape, T *output_data) +{ + const int flat_size = MatchingFlatSize(input_shape, output_shape); + + for (int i = 0; i < flat_size; ++i) { + output_data[i] = -input_data[i]; + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_NEG_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/pad.h b/components/tflite/tensorflow/lite/kernels/internal/reference/pad.h new file mode 100644 index 00000000..8af3b74b --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/pad.h @@ -0,0 +1,176 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_PAD_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_PAD_H_ + +#include + +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +// TFLite Pad supports activation tensors with up to 5 dimensions. +constexpr int PadKernelMaxDimensionCount() +{ + return 5; +} + +// There are two versions of pad: Pad and PadV2. In PadV2 there is a second +// scalar input that provides the padding value. Therefore pad_value_ptr can be +// equivalent to a simple input1_data. For Pad, it should point to a zero +// value. +// +// Note that two typenames are required, so that T=P=int32_t is considered a +// specialization distinct from P=int32_t. +template +inline void PadImpl(const tflite::PadParams &op_params, + const RuntimeShape &input_shape, const T *input_data, + const P *pad_value_ptr, const RuntimeShape &output_shape, + T *output_data) +{ + const RuntimeShape ext_input_shape = + RuntimeShape::ExtendedShape(PadKernelMaxDimensionCount(), input_shape); + const RuntimeShape ext_output_shape = + RuntimeShape::ExtendedShape(PadKernelMaxDimensionCount(), output_shape); + TFLITE_DCHECK_LE(op_params.left_padding_count, PadKernelMaxDimensionCount()); + TFLITE_DCHECK_LE(op_params.right_padding_count, PadKernelMaxDimensionCount()); + + // Runtime calls are currently fixed at 5 dimensions. Copy inputs so we can + // pad them to 5 dims (yes, we are "padding the padding"). + int left_padding_copy[PadKernelMaxDimensionCount()]; + for (int i = 0; i < PadKernelMaxDimensionCount(); i++) { + left_padding_copy[i] = 0; + } + for (int i = 0; i < op_params.left_padding_count; ++i) { + left_padding_copy[i + PadKernelMaxDimensionCount() - + op_params.left_padding_count] = op_params.left_padding[i]; + } + int right_padding_copy[PadKernelMaxDimensionCount()]; + for (int i = 0; i < PadKernelMaxDimensionCount(); i++) { + right_padding_copy[i] = 0; + } + for (int i = 0; i < op_params.right_padding_count; ++i) { + right_padding_copy[i + PadKernelMaxDimensionCount() - + op_params.right_padding_count] = + op_params.right_padding[i]; + } + + const int output_batch = ext_output_shape.Dims(0); + const int output_plane = ext_output_shape.Dims(1); + const int output_height = ext_output_shape.Dims(2); + const int output_width = ext_output_shape.Dims(3); + const int output_depth = ext_output_shape.Dims(4); + + const int left_b_padding = left_padding_copy[0]; + const int left_p_padding = left_padding_copy[1]; + const int left_h_padding = left_padding_copy[2]; + const int left_w_padding = left_padding_copy[3]; + const int left_d_padding = left_padding_copy[4]; + + const int right_b_padding = right_padding_copy[0]; + const int right_p_padding = right_padding_copy[1]; + const int right_h_padding = right_padding_copy[2]; + const int right_w_padding = right_padding_copy[3]; + const int right_d_padding = right_padding_copy[4]; + + const T pad_value = *pad_value_ptr; + + const T *in_ptr = input_data; + T *out_ptr = output_data; + for (int out_b = 0; out_b < output_batch; ++out_b) { + for (int out_p = 0; out_p < output_plane; ++out_p) { + for (int out_h = 0; out_h < output_height; ++out_h) { + for (int out_w = 0; out_w < output_width; ++out_w) { + for (int out_d = 0; out_d < output_depth; ++out_d) { + if (out_b < left_b_padding || + out_b >= output_batch - right_b_padding || + out_p < left_p_padding || + out_p >= output_plane - right_p_padding || + out_h < left_h_padding || + out_h >= output_height - right_h_padding || + out_w < left_w_padding || + out_w >= output_width - right_w_padding || + out_d < left_d_padding || + out_d >= output_depth - right_d_padding) { + *out_ptr++ = pad_value; + } else { + *out_ptr++ = *in_ptr++; + } + } + } + } + } + } +} + +template +inline void Pad(const tflite::PadParams &op_params, + const RuntimeShape &input_shape, const T *input_data, + const P *pad_value_ptr, const RuntimeShape &output_shape, + T *output_data) +{ + PadImpl(op_params, input_shape, input_data, pad_value_ptr, output_shape, + output_data); +} + +// The second (pad-value) input can be int32_t when, say, the first is uint8_t. +template +inline void Pad(const tflite::PadParams &op_params, + const RuntimeShape &input_shape, const T *input_data, + const int32_t *pad_value_ptr, const RuntimeShape &output_shape, + T *output_data) +{ + const T converted_pad_value = static_cast(*pad_value_ptr); + PadImpl(op_params, input_shape, input_data, &converted_pad_value, + output_shape, output_data); +} + +// This version avoids conflicting template matching. +template <> +inline void Pad(const tflite::PadParams &op_params, + const RuntimeShape &input_shape, const int32_t *input_data, + const int32_t *pad_value_ptr, const RuntimeShape &output_shape, + int32_t *output_data) +{ + PadImpl(op_params, input_shape, input_data, pad_value_ptr, output_shape, + output_data); +} + +template +inline void PadImageStyle(const tflite::PadParams &op_params, + const RuntimeShape &input_shape, const T *input_data, + const P *pad_value_ptr, + const RuntimeShape &output_shape, T *output_data) +{ + Pad(op_params, input_shape, input_data, pad_value_ptr, output_shape, + output_data); +} + +template +inline void PadImageStyle(const tflite::PadParams &op_params, + const RuntimeShape &input_shape, + const float *input_data, const P *pad_value_ptr, + const RuntimeShape &output_shape, + float *output_data) +{ + Pad(op_params, input_shape, input_data, pad_value_ptr, output_shape, + output_data); +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_PAD_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/pooling.h b/components/tflite/tensorflow/lite/kernels/internal/reference/pooling.h new file mode 100644 index 00000000..477c5098 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/pooling.h @@ -0,0 +1,301 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_POOLING_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_POOLING_H_ + +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/cppmath.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +inline void AveragePool(const PoolParams ¶ms, + const RuntimeShape &input_shape, + const float *input_data, + const RuntimeShape &output_shape, float *output_data) +{ + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int depth = MatchingDim(input_shape, 3, output_shape, 3); + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + const int stride_height = params.stride_height; + const int stride_width = params.stride_width; + for (int batch = 0; batch < batches; ++batch) { + for (int out_y = 0; out_y < output_height; ++out_y) { + for (int out_x = 0; out_x < output_width; ++out_x) { + for (int channel = 0; channel < depth; ++channel) { + const int in_x_origin = + (out_x * stride_width) - params.padding_values.width; + const int in_y_origin = + (out_y * stride_height) - params.padding_values.height; + // Compute the boundaries of the filter region clamped so as to + // ensure that the filter window fits in the input array. + const int filter_x_start = std::max(0, -in_x_origin); + const int filter_x_end = + std::min(params.filter_width, input_width - in_x_origin); + const int filter_y_start = std::max(0, -in_y_origin); + const int filter_y_end = + std::min(params.filter_height, input_height - in_y_origin); + float total = 0.f; + float filter_count = 0; + for (int filter_y = filter_y_start; filter_y < filter_y_end; + ++filter_y) { + for (int filter_x = filter_x_start; filter_x < filter_x_end; + ++filter_x) { + const int in_x = in_x_origin + filter_x; + const int in_y = in_y_origin + filter_y; + total += + input_data[Offset(input_shape, batch, in_y, in_x, channel)]; + filter_count++; + } + } + const float average = total / filter_count; + output_data[Offset(output_shape, batch, out_y, out_x, channel)] = + ActivationFunctionWithMinMax(average, params.float_activation_min, + params.float_activation_max); + } + } + } + } +} + +inline void AveragePool(const PoolParams ¶ms, + const RuntimeShape &input_shape, + const uint8_t *input_data, + const RuntimeShape &output_shape, + uint8_t *output_data) +{ + TFLITE_DCHECK_LE(params.quantized_activation_min, + params.quantized_activation_max); + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int depth = MatchingDim(input_shape, 3, output_shape, 3); + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + const int stride_height = params.stride_height; + const int stride_width = params.stride_width; + for (int batch = 0; batch < batches; ++batch) { + for (int out_y = 0; out_y < output_height; ++out_y) { + for (int out_x = 0; out_x < output_width; ++out_x) { + for (int channel = 0; channel < depth; ++channel) { + const int in_x_origin = + (out_x * stride_width) - params.padding_values.width; + const int in_y_origin = + (out_y * stride_height) - params.padding_values.height; + // Compute the boundaries of the filter region clamped so as to + // ensure that the filter window fits in the input array. + const int filter_x_start = std::max(0, -in_x_origin); + const int filter_x_end = + std::min(params.filter_width, input_width - in_x_origin); + const int filter_y_start = std::max(0, -in_y_origin); + const int filter_y_end = + std::min(params.filter_height, input_height - in_y_origin); + int32_t acc = 0; + int filter_count = 0; + for (int filter_y = filter_y_start; filter_y < filter_y_end; + ++filter_y) { + for (int filter_x = filter_x_start; filter_x < filter_x_end; + ++filter_x) { + const int in_x = in_x_origin + filter_x; + const int in_y = in_y_origin + filter_y; + acc += + input_data[Offset(input_shape, batch, in_y, in_x, channel)]; + filter_count++; + } + } + acc = (acc + filter_count / 2) / filter_count; + acc = std::max(acc, params.quantized_activation_min); + acc = std::min(acc, params.quantized_activation_max); + output_data[Offset(output_shape, batch, out_y, out_x, channel)] = + static_cast(acc); + } + } + } + } +} + +inline void L2Pool(const PoolParams ¶ms, const RuntimeShape &input_shape, + const float *input_data, const RuntimeShape &output_shape, + float *output_data) +{ + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int depth = MatchingDim(input_shape, 3, output_shape, 3); + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + const int stride_height = params.stride_height; + const int stride_width = params.stride_width; + for (int batch = 0; batch < batches; ++batch) { + for (int out_y = 0; out_y < output_height; ++out_y) { + for (int out_x = 0; out_x < output_width; ++out_x) { + for (int channel = 0; channel < depth; ++channel) { + const int in_x_origin = + (out_x * stride_width) - params.padding_values.width; + const int in_y_origin = + (out_y * stride_height) - params.padding_values.height; + // Compute the boundaries of the filter region clamped so as to + // ensure that the filter window fits in the input array. + const int filter_x_start = std::max(0, -in_x_origin); + const int filter_x_end = + std::min(params.filter_width, input_width - in_x_origin); + const int filter_y_start = std::max(0, -in_y_origin); + const int filter_y_end = + std::min(params.filter_height, input_height - in_y_origin); + float sum_squares = 0.f; + int filter_count = 0; + for (int filter_y = filter_y_start; filter_y < filter_y_end; + ++filter_y) { + for (int filter_x = filter_x_start; filter_x < filter_x_end; + ++filter_x) { + const int in_x = in_x_origin + filter_x; + const int in_y = in_y_origin + filter_y; + const float val = + input_data[Offset(input_shape, batch, in_y, in_x, channel)]; + sum_squares += val * val; + filter_count++; + } + } + const float l2pool_result = std::sqrt(sum_squares / filter_count); + output_data[Offset(output_shape, batch, out_y, out_x, channel)] = + ActivationFunctionWithMinMax(l2pool_result, + params.float_activation_min, + params.float_activation_max); + } + } + } + } +} + +inline void MaxPool(const PoolParams ¶ms, const RuntimeShape &input_shape, + const float *input_data, const RuntimeShape &output_shape, + float *output_data) +{ + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int depth = MatchingDim(input_shape, 3, output_shape, 3); + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + const int stride_height = params.stride_height; + const int stride_width = params.stride_width; + for (int batch = 0; batch < batches; ++batch) { + for (int out_y = 0; out_y < output_height; ++out_y) { + for (int out_x = 0; out_x < output_width; ++out_x) { + for (int channel = 0; channel < depth; ++channel) { + const int in_x_origin = + (out_x * stride_width) - params.padding_values.width; + const int in_y_origin = + (out_y * stride_height) - params.padding_values.height; + // Compute the boundaries of the filter region clamped so as to + // ensure that the filter window fits in the input array. + const int filter_x_start = std::max(0, -in_x_origin); + const int filter_x_end = + std::min(params.filter_width, input_width - in_x_origin); + const int filter_y_start = std::max(0, -in_y_origin); + const int filter_y_end = + std::min(params.filter_height, input_height - in_y_origin); + float max = std::numeric_limits::lowest(); + for (int filter_y = filter_y_start; filter_y < filter_y_end; + ++filter_y) { + for (int filter_x = filter_x_start; filter_x < filter_x_end; + ++filter_x) { + const int in_x = in_x_origin + filter_x; + const int in_y = in_y_origin + filter_y; + max = std::max( + max, + input_data[Offset(input_shape, batch, in_y, in_x, channel)]); + } + } + output_data[Offset(output_shape, batch, out_y, out_x, channel)] = + ActivationFunctionWithMinMax(max, params.float_activation_min, + params.float_activation_max); + } + } + } + } +} + +inline void MaxPool(const PoolParams ¶ms, const RuntimeShape &input_shape, + const uint8_t *input_data, const RuntimeShape &output_shape, + uint8_t *output_data) +{ + TFLITE_DCHECK_LE(params.quantized_activation_min, + params.quantized_activation_max); + TFLITE_DCHECK_GE(params.quantized_activation_min, 0); + TFLITE_DCHECK_LE(params.quantized_activation_max, 255); + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int depth = MatchingDim(input_shape, 3, output_shape, 3); + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + const int stride_height = params.stride_height; + const int stride_width = params.stride_width; + for (int batch = 0; batch < batches; ++batch) { + for (int out_y = 0; out_y < output_height; ++out_y) { + for (int out_x = 0; out_x < output_width; ++out_x) { + for (int channel = 0; channel < depth; ++channel) { + const int in_x_origin = + (out_x * stride_width) - params.padding_values.width; + const int in_y_origin = + (out_y * stride_height) - params.padding_values.height; + // Compute the boundaries of the filter region clamped so as to + // ensure that the filter window fits in the input array. + const int filter_x_start = std::max(0, -in_x_origin); + const int filter_x_end = + std::min(params.filter_width, input_width - in_x_origin); + const int filter_y_start = std::max(0, -in_y_origin); + const int filter_y_end = + std::min(params.filter_height, input_height - in_y_origin); + uint8_t max = 0; + for (int filter_y = filter_y_start; filter_y < filter_y_end; + ++filter_y) { + for (int filter_x = filter_x_start; filter_x < filter_x_end; + ++filter_x) { + const int in_x = in_x_origin + filter_x; + const int in_y = in_y_origin + filter_y; + max = std::max( + max, + input_data[Offset(input_shape, batch, in_y, in_x, channel)]); + } + } + max = std::max(max, params.quantized_activation_min); + max = std::min(max, params.quantized_activation_max); + output_data[Offset(output_shape, batch, out_y, out_x, channel)] = + static_cast(max); + } + } + } + } +} +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_POOLING_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/prelu.h b/components/tflite/tensorflow/lite/kernels/internal/reference/prelu.h new file mode 100644 index 00000000..ca3d794e --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/prelu.h @@ -0,0 +1,109 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_PRELU_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_PRELU_H_ + +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +// Broadcast prelu to output_shape for quantized uint8_t/int8_t data. +template +inline void BroadcastPrelu4DSlow( + const PreluParams ¶ms, const RuntimeShape &input_shape, + const T *input_data, const RuntimeShape &alpha_shape, const T *alpha_data, + const RuntimeShape &output_shape, T *output_data) +{ + TFLITE_DCHECK_LE(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_LE(alpha_shape.DimensionsCount(), 4); + TFLITE_DCHECK_LE(output_shape.DimensionsCount(), 4); + const RuntimeShape extended_output_shape = + RuntimeShape::ExtendedShape(4, output_shape); + NdArrayDesc<4> desc1; + NdArrayDesc<4> desc2; + NdArrayDescsForElementwiseBroadcast(input_shape, alpha_shape, &desc1, &desc2); + + for (int b = 0; b < extended_output_shape.Dims(0); ++b) { + for (int y = 0; y < extended_output_shape.Dims(1); ++y) { + for (int x = 0; x < extended_output_shape.Dims(2); ++x) { + for (int c = 0; c < extended_output_shape.Dims(3); ++c) { + int output_index = Offset(extended_output_shape, b, y, x, c); + int input_index = SubscriptToIndex(desc1, b, y, x, c); + const int32_t input_value = + params.input_offset + input_data[input_index]; + int32_t output_value; + if (input_value >= 0) { + output_value = MultiplyByQuantizedMultiplier( + input_value, params.output_multiplier_1, params.output_shift_1); + } else { + auto alpha_index = SubscriptToIndex(desc2, b, y, x, c); + const int32_t alpha_value = + params.alpha_offset + alpha_data[alpha_index]; + + output_value = MultiplyByQuantizedMultiplier( + input_value * alpha_value, params.output_multiplier_2, + params.output_shift_2); + } + output_value += params.output_offset; + + const int32_t quantized_min = std::numeric_limits::min(); + const int32_t quantized_max = std::numeric_limits::max(); + const int32_t clamped_output = + std::min(quantized_max, std::max(quantized_min, output_value)); + output_data[output_index] = static_cast(clamped_output); + } + } + } + } +} + +template +inline void Prelu(const PreluParams ¶ms, const RuntimeShape &input_shape, + const T *input_data, const RuntimeShape &alpha_shape, + const T *alpha_data, const RuntimeShape &output_shape, + T *output_data) +{ + const int32_t quantized_min = std::numeric_limits::min(); + const int32_t quantized_max = std::numeric_limits::max(); + + const int flat_size = + MatchingElementsSize(input_shape, alpha_shape, output_shape); + for (int i = 0; i < flat_size; ++i) { + const int32_t input_value = params.input_offset + input_data[i]; + int32_t output_value; + if (input_value >= 0) { + output_value = MultiplyByQuantizedMultiplier( + input_value, params.output_multiplier_1, params.output_shift_1); + } else { + const int32_t alpha_value = params.alpha_offset + alpha_data[i]; + + output_value = MultiplyByQuantizedMultiplier(input_value * alpha_value, + params.output_multiplier_2, + params.output_shift_2); + } + output_value += params.output_offset; + + const int32_t clamped_output = + std::min(quantized_max, std::max(quantized_min, output_value)); + output_data[i] = static_cast(clamped_output); + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_PRELU_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/process_broadcast_shapes.h b/components/tflite/tensorflow/lite/kernels/internal/reference/process_broadcast_shapes.h new file mode 100644 index 00000000..d348273b --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/process_broadcast_shapes.h @@ -0,0 +1,137 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_PROCESS_BROADCAST_SHAPES_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_PROCESS_BROADCAST_SHAPES_H_ + +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +// Consolidates dimensions in broadcast inputs, checks for five-fold pattern. +// +// For example, if sequence of dimensions of one input is +// ..., 1, 3, 1, 7, 9, 5,... and the other is ..., 2, 3, 1, 7, 1, 1, ... +// we can consolidate these as +// ..., 1, 3*7, 9*5, ... and 2, 3*7, 1. +// +// The category is updated in the less-frequent case of shapes that are +// not suited to a fivefold-loop broadcast. +// +// Falls back to generic pattern when it does not know how to process properly. +// +// Returns true iff there is some sort of broadcast, which includes five-fold +// patterns and falling back to generic broadcast. +inline bool ProcessBroadcastShapes(const RuntimeShape &shape0, + const RuntimeShape &shape1, + tflite::ArithmeticParams *params) +{ + const int dims_count = + std::max(shape0.DimensionsCount(), shape1.DimensionsCount()); + + params->broadcast_category = BroadcastableOpCategory::kGenericBroadcast; + RuntimeShape scalar_shape(dims_count, 1); + + auto extended_shape0 = RuntimeShape::ExtendedShape(dims_count, shape0); + auto extended_shape1 = RuntimeShape::ExtendedShape(dims_count, shape1); + + // Check for "exact" match, implicitly accepting any scalar shapes. + if (extended_shape0 == extended_shape1) { + params->broadcast_category = BroadcastableOpCategory::kNonBroadcast; + return false; + } + + for (int i = dims_count - 1; i >= 0; --i) { + if (extended_shape0.Dims(i) == extended_shape1.Dims(i)) { + continue; + } else if (extended_shape0.Dims(i) == 1) { + params->broadcast_category = + BroadcastableOpCategory::kFirstInputBroadcastsFast; + break; + } else if (extended_shape1.Dims(i) == 1) { + params->broadcast_category = + BroadcastableOpCategory::kSecondInputBroadcastsFast; + break; + } else { + // This case is erroneous: there is a dimension that does not match and + // is not a broadcast from one shape to the other. + params->broadcast_category = BroadcastableOpCategory::kGenericBroadcast; + return true; + } + } + + if (params->broadcast_category != + BroadcastableOpCategory::kFirstInputBroadcastsFast && + params->broadcast_category != + BroadcastableOpCategory::kSecondInputBroadcastsFast) { + // This is unreachable because at least one else clause in the above loop + // must be reached. + TFLITE_DCHECK(false); + params->broadcast_category = BroadcastableOpCategory::kNonBroadcast; + return false; + } + + // From this point it is assumed contractually that corresponding dimensions + // in shape0 and shape1 are either (a) equal or (b) one or other equals 1. + const bool swap_inputs = params->broadcast_category == + BroadcastableOpCategory::kSecondInputBroadcastsFast; + const RuntimeShape *shape_a = + swap_inputs ? &extended_shape1 : &extended_shape0; + const RuntimeShape *shape_b = + swap_inputs ? &extended_shape0 : &extended_shape1; + + int i = dims_count - 1; + params->broadcast_shape[0] = 1; + params->broadcast_shape[1] = 1; + params->broadcast_shape[2] = 1; + params->broadcast_shape[3] = 1; + params->broadcast_shape[4] = 1; + // y_0 is greedy: include dims if both or neither equal 1: in other words, + // test for equality rather than (shape_a->Dims(i) != 1). + while (i >= 0 && shape_a->Dims(i) == shape_b->Dims(i)) { + params->broadcast_shape[4] *= shape_b->Dims(i); + --i; + } + // Here either input_a or input_b has dim of 1 (if i >= 0). If it is input_b + // that has the unit dimension, the next two loops are not entered. + while (i >= 0 && shape_a->Dims(i) == 1) { + params->broadcast_shape[3] *= shape_b->Dims(i); + --i; + } + while (i >= 0 && shape_a->Dims(i) == shape_b->Dims(i)) { + params->broadcast_shape[2] *= shape_a->Dims(i); + --i; + } + // Here either input_a or input_b has dim of 1 (if i >= 0). + while (i >= 0 && shape_b->Dims(i) == 1) { + params->broadcast_shape[1] *= shape_a->Dims(i); + --i; + } + while (i >= 0 && shape_a->Dims(i) == shape_b->Dims(i)) { + params->broadcast_shape[0] *= shape_b->Dims(i); + --i; + } + + // Rarer case is when the broadcast dimensions cannot be handled by a fivefold + // loop. + if (i >= 0) { + params->broadcast_category = BroadcastableOpCategory::kGenericBroadcast; + } + return true; +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_PROCESS_BROADCAST_SHAPES_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/quantize.h b/components/tflite/tensorflow/lite/kernels/internal/reference/quantize.h new file mode 100644 index 00000000..23e2aa31 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/quantize.h @@ -0,0 +1,54 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_QUANTIZE_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_QUANTIZE_H_ + +#include +#include + +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/kernels/internal/cppmath.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +template +inline void AffineQuantize(const tflite::QuantizationParams &op_params, + const RuntimeShape &input_shape, + const InputT *input_data, + const RuntimeShape &output_shape, + OutputT *output_data) +{ + const int32_t zero_point = op_params.zero_point; + const double scale = op_params.scale; + const int flat_size = MatchingFlatSize(input_shape, output_shape); + static constexpr int32_t min_val = std::numeric_limits::min(); + static constexpr int32_t max_val = std::numeric_limits::max(); + + for (int i = 0; i < flat_size; i++) { + const InputT val = input_data[i]; + int32_t unclamped = + static_cast(TfLiteRound(val / static_cast(scale))) + + zero_point; + int32_t clamped = std::min(std::max(unclamped, min_val), max_val); + output_data[i] = clamped; + } +} + +} // namespace reference_ops + +} // namespace tflite +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_QUANTIZE_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/reduce.h b/components/tflite/tensorflow/lite/kernels/internal/reference/reduce.h new file mode 100644 index 00000000..44bf50c3 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/reduce.h @@ -0,0 +1,420 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_REDUCE_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_REDUCE_H_ + +#include "ruy/profiler/instrumentation.h" // from @ruy +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/cppmath.h" +#include "tensorflow/lite/kernels/internal/max.h" +#include "tensorflow/lite/kernels/internal/min.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +// A generic reduce method that can be used for reduce_sum, reduce_mean, etc. +// This method iterates through input data and reduce elements along the +// dimensions given in axis. +template +inline bool Reduce(const In *input_data, const int *input_dims, + const int *output_dims, const int input_num_dims, + const int output_num_dims, const int *axis, + const int num_axis, int *input_iter, + Out reducer(const Out current, const In in), + Out *output_data) +{ + // Reset input iterator. + for (int idx = 0; idx < input_num_dims; ++idx) { + input_iter[idx] = 0; + } + // Iterate through input_data. + do { + size_t input_offset = + ReducedOutputOffset(input_num_dims, input_dims, input_iter, 0, nullptr); + size_t output_offset = ReducedOutputOffset(input_num_dims, input_dims, + input_iter, num_axis, axis); + output_data[output_offset] = + reducer(output_data[output_offset], input_data[input_offset]); + } while (NextIndex(input_num_dims, input_dims, input_iter)); + return true; +} + +// This method parses the input 'axis' to remove duplicates and handle negative +// values, and returns a valid 'out_axis' +inline bool ResolveAxis(const int num_dims, const int *axis, + const int64_t num_axis, int *out_axis, + int *out_num_axis) +{ + *out_num_axis = 0; // Just in case. + // Short-circuit axis resolution for scalars; the axis will go unused. + if (num_dims == 0) { + return true; + } + // o(n^2) is fine since out_num_axis should be really small, mostly <= 4 + for (int64_t idx = 0; idx < num_axis; ++idx) { + // Handle negative index. A positive index 'p_idx' can be represented as a + // negative index 'n_idx' as: n_idx = p_idx-num_dims + // eg: For num_dims=3, [0, 1, 2] is the same as [-3, -2, -1] */ + int current = axis[idx] < 0 ? (axis[idx] + num_dims) : axis[idx]; + TFLITE_DCHECK(current >= 0 && current < num_dims); + if (current < 0 || current >= num_dims) { + return false; + } + bool is_dup = false; + for (int j = 0; j < *out_num_axis; ++j) { + if (out_axis[j] == current) { + is_dup = true; + break; + } + } + if (!is_dup) { + out_axis[*out_num_axis] = current; + *out_num_axis += 1; + } + } + return true; +} + +// This method expects that output_data has been initialized. +template +inline bool ReduceSumImpl(const In *input_data, const int *input_dims, + const int *output_dims, const int input_num_dims, + const int output_num_dims, const int *axis, + const int num_axis, int *input_iter, + Out *output_data) +{ + auto reducer = [](const Out current, const In in) -> Out { + const Out actual_in = static_cast(in); + return current + actual_in; + }; + return Reduce(input_data, input_dims, output_dims, input_num_dims, + output_num_dims, axis, num_axis, input_iter, reducer, + output_data); +} + +template +inline bool InitTensorDataForReduce(const int *dims, const int num_dims, + const T init_value, T *data) +{ + size_t num_elements = 1; + for (int idx = 0; idx < num_dims; ++idx) { + size_t current = static_cast(dims[idx]); + // Overflow prevention. + if (num_elements > std::numeric_limits::max() / current) { + return false; + } + num_elements *= current; + } + for (size_t idx = 0; idx < num_elements; ++idx) { + data[idx] = init_value; + } + return true; +} + +// Computes the generic value (i.e., sum/max/min/prod) of elements across +// dimensions given in axis. It needs to pass in init_value and reducer. +template +inline bool ReduceGeneric(const T *input_data, const int *input_dims, + const int input_num_dims, T *output_data, + const int *output_dims, const int output_num_dims, + const int *axis, const int64_t num_axis_dimensions, + bool keep_dims, int *temp_index, int *resolved_axis, + T init_value, + T reducer(const T current, const T in)) +{ + // Return early when input shape has zero dim. + for (int i = 0; i < input_num_dims; ++i) { + if (input_dims[i] == 0) + return true; + } + + // Reset output data. + if (!InitTensorDataForReduce(output_dims, output_num_dims, init_value, + output_data)) { + return false; + } + + // Resolve axis. + int num_resolved_axis = 0; + if (!ResolveAxis(input_num_dims, axis, num_axis_dimensions, resolved_axis, + &num_resolved_axis)) { + return false; + } + + return Reduce(input_data, input_dims, output_dims, input_num_dims, + output_num_dims, resolved_axis, num_resolved_axis, + temp_index, reducer, output_data); +} + +// Computes the mean of elements across dimensions given in axis. +// It does so in two stages, first calculates the sum of elements along the axis +// then divides it by the number of element in axis. +template +inline bool Mean(const T *input_data, const int *input_dims, + const int input_num_dims, T *output_data, + const int *output_dims, const int output_num_dims, + const int *axis, const int num_axis_dimensions, bool keep_dims, + int *temp_index, int *resolved_axis, U *temp_sum) +{ + ruy::profiler::ScopeLabel label("Mean"); + // Reset output data. + size_t num_outputs = 1; + for (int idx = 0; idx < output_num_dims; ++idx) { + size_t current = static_cast(output_dims[idx]); + // Overflow prevention. + if (num_outputs > std::numeric_limits::max() / current) { + return false; + } + num_outputs *= current; + } + for (size_t idx = 0; idx < num_outputs; ++idx) { + output_data[idx] = T(); + temp_sum[idx] = U(); + } + + // Resolve axis. + int num_resolved_axis = 0; + if (!ResolveAxis(input_num_dims, axis, num_axis_dimensions, resolved_axis, + &num_resolved_axis)) { + return false; + } + + if (!ReduceSumImpl(input_data, input_dims, output_dims, input_num_dims, + output_num_dims, resolved_axis, num_resolved_axis, + temp_index, temp_sum)) { + return false; + } + + // Calculate mean by dividing output_data by num of aggregated element. + size_t num_elements_in_axis = 1; + for (int idx = 0; idx < num_resolved_axis; ++idx) { + size_t current = static_cast(input_dims[resolved_axis[idx]]); + // Overflow prevention. + if (current > (std::numeric_limits::max() / num_elements_in_axis)) { + return false; + } + num_elements_in_axis *= current; + } + + if (num_elements_in_axis > 0) { + for (size_t idx = 0; idx < num_outputs; ++idx) { + output_data[idx] = + static_cast(temp_sum[idx] / static_cast(num_elements_in_axis)); + } + } + return true; +} + +template +inline void Mean(const tflite::MeanParams &op_params, + const RuntimeShape &unextended_input_shape, + const T *input_data, + const RuntimeShape &unextended_output_shape, T *output_data) +{ + ruy::profiler::ScopeLabel label("Mean4D"); + + // Current implementation only supports dimension equals 4 and simultaneous + // reduction over width and height. + TFLITE_CHECK_EQ(unextended_input_shape.DimensionsCount(), 4); + TFLITE_CHECK_LE(unextended_output_shape.DimensionsCount(), 4); + const RuntimeShape input_shape = + RuntimeShape::ExtendedShape(4, unextended_input_shape); + const RuntimeShape output_shape = + RuntimeShape::ExtendedShape(4, unextended_output_shape); + + const int output_batch = output_shape.Dims(0); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + const int output_depth = output_shape.Dims(3); + + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + + TFLITE_CHECK_EQ(op_params.axis_count, 2); + TFLITE_CHECK((op_params.axis[0] == 1 && op_params.axis[1] == 2) || + (op_params.axis[0] == 2 && op_params.axis[1] == 1)); + TFLITE_CHECK_EQ(output_height, 1); + TFLITE_CHECK_EQ(output_width, 1); + + for (int out_b = 0; out_b < output_batch; ++out_b) { + for (int out_d = 0; out_d < output_depth; ++out_d) { + float value = 0; + for (int in_h = 0; in_h < input_height; ++in_h) { + for (int in_w = 0; in_w < input_width; ++in_w) { + value += input_data[Offset(input_shape, out_b, in_h, in_w, out_d)]; + } + } + output_data[Offset(output_shape, out_b, 0, 0, out_d)] = + value / (input_width * input_height); + } + } +} + +inline void Mean(const tflite::MeanParams &op_params, + const RuntimeShape &unextended_input_shape, + const uint8_t *input_data, int32_t input_zero_point, + float input_scale, const RuntimeShape &unextended_output_shape, + uint8_t *output_data, int32_t output_zero_point, + float output_scale) +{ + ruy::profiler::ScopeLabel label("Mean4D/Uint8"); + + // Current implementation only supports dimension equals 4 and simultaneous + // reduction over width and height. + TFLITE_CHECK_EQ(unextended_input_shape.DimensionsCount(), 4); + TFLITE_CHECK_LE(unextended_output_shape.DimensionsCount(), 4); + const RuntimeShape input_shape = + RuntimeShape::ExtendedShape(4, unextended_input_shape); + const RuntimeShape output_shape = + RuntimeShape::ExtendedShape(4, unextended_output_shape); + const int output_batch = output_shape.Dims(0); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + const int output_depth = output_shape.Dims(3); + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const float num_elements_in_axis = input_width * input_height; + + TFLITE_CHECK_EQ(op_params.axis_count, 2); + TFLITE_CHECK((op_params.axis[0] == 1 && op_params.axis[1] == 2) || + (op_params.axis[0] == 2 && op_params.axis[1] == 1)); + TFLITE_CHECK_EQ(output_height, 1); + TFLITE_CHECK_EQ(output_width, 1); + + constexpr int32_t kMinValue = std::numeric_limits::min(); + constexpr int32_t kMaxValue = std::numeric_limits::max(); + + float temp = input_zero_point * input_scale / output_scale; + temp = temp > 0 ? temp + 0.5f : temp - 0.5f; + int32_t bias = output_zero_point - static_cast(temp); + double real_scale = + static_cast(input_scale / (num_elements_in_axis * output_scale)); + + int32_t multiplier; + int shift; + QuantizeMultiplier(real_scale, &multiplier, &shift); + for (int out_b = 0; out_b < output_batch; ++out_b) { + for (int out_d = 0; out_d < output_depth; ++out_d) { + int32_t acc = 0; + for (int in_h = 0; in_h < input_height; ++in_h) { + for (int in_w = 0; in_w < input_width; ++in_w) { + acc += input_data[Offset(input_shape, out_b, in_h, in_w, out_d)]; + } + } + acc = MultiplyByQuantizedMultiplier(acc, multiplier, shift); + acc += bias; + acc = std::min(std::max(acc, kMinValue), kMaxValue); + output_data[Offset(output_shape, out_b, 0, 0, out_d)] = + static_cast(acc); + } + } +} + +// Computes the mean of elements across dimensions given in axis. +// It does so in two stages, first calculates the sum of elements along the axis +// then divides it by the number of element in axis for quantized values. +template +inline bool QuantizedMeanOrSum(const T *input_data, int32_t input_zero_point, + float input_scale, const int *input_dims, + const int input_num_dims, T *output_data, + int32_t output_zero_point, float output_scale, + const int *output_dims, + const int output_num_dims, const int *axis, + const int num_axis_dimensions, bool keep_dims, + int *temp_index, int *resolved_axis, U *temp_sum, + bool compute_sum) +{ + const bool uint8_case = std::is_same::value; + const bool int16_case = std::is_same::value; + if (uint8_case) { + ruy::profiler::ScopeLabel label(compute_sum ? "Sum/Uint8" : "Mean/Uint8"); + } else if (int16_case) { + ruy::profiler::ScopeLabel label(compute_sum ? "Sum/Int16" : "Mean/Int16"); + } else { + ruy::profiler::ScopeLabel label(compute_sum ? "Sum/Int8" : "Mean/Int8"); + } + // Reset output data. + size_t num_outputs = 1; + for (int idx = 0; idx < output_num_dims; ++idx) { + size_t current = static_cast(output_dims[idx]); + // Overflow prevention. + if (num_outputs > std::numeric_limits::max() / current) { + return false; + } + num_outputs *= current; + } + for (size_t idx = 0; idx < num_outputs; ++idx) { + output_data[idx] = T(); + temp_sum[idx] = U(); + } + + // Resolve axis. + int num_resolved_axis = 0; + if (!ResolveAxis(input_num_dims, axis, num_axis_dimensions, resolved_axis, + &num_resolved_axis)) { + return false; + } + + if (!ReduceSumImpl(input_data, input_dims, output_dims, input_num_dims, + output_num_dims, resolved_axis, num_resolved_axis, + temp_index, temp_sum)) { + return false; + } + + // Calculate mean by dividing output_data by num of aggregated element. + size_t num_elements_in_axis = 1; + for (int idx = 0; idx < num_resolved_axis; ++idx) { + size_t current = static_cast(input_dims[resolved_axis[idx]]); + // Overflow prevention. + if (current > (std::numeric_limits::max() / num_elements_in_axis)) { + return false; + } + num_elements_in_axis *= current; + } + + if (num_elements_in_axis > 0) { + const float scale = input_scale / output_scale; + if (compute_sum) { + // TODO(b/116341117): Eliminate float and do this completely in 8bit. + const float bias = -input_zero_point * scale * num_elements_in_axis; + for (size_t idx = 0; idx < num_outputs; ++idx) { + const U value = + static_cast(TfLiteRound(temp_sum[idx] * scale + bias)) + + output_zero_point; + output_data[idx] = static_cast(value); + } + } else { + const float bias = -input_zero_point * scale; + for (size_t idx = 0; idx < num_outputs; ++idx) { + float float_mean = static_cast(temp_sum[idx]) / + static_cast(num_elements_in_axis); + float result = TfLiteMin( + TfLiteRound(float_mean * scale + bias) + output_zero_point, + static_cast(std::numeric_limits::max())); + result = TfLiteMax(result, + static_cast(std::numeric_limits::min())); + output_data[idx] = static_cast(result); + } + } + } + return true; +} + +} // namespace reference_ops + +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_REDUCE_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/requantize.h b/components/tflite/tensorflow/lite/kernels/internal/reference/requantize.h new file mode 100644 index 00000000..b73477d4 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/requantize.h @@ -0,0 +1,68 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_REQUANTIZE_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_REQUANTIZE_H_ + +#include "ruy/profiler/instrumentation.h" // from @ruy +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +template +inline void Requantize(const input_type *input_data, int32_t size, + int32_t effective_scale_multiplier, + int32_t effective_scale_shift, int32_t input_zeropoint, + int32_t output_zeropoint, output_type *output_data) +{ + ruy::profiler::ScopeLabel label("Requantize"); + const bool same_scale = + (effective_scale_multiplier == 1 << 30 && effective_scale_shift == 1); + if (same_scale) { + const bool mixed_type_int8_uint8 = + std::is_same::value && + std::is_same::value; + const bool mixed_type_uint8_int8 = + std::is_same::value && + std::is_same::value; + const int32_t zero_point_diff = input_zeropoint - output_zeropoint; + // Fast path to do requantization for the case when just a shift of 128 is + // needed. + if ((mixed_type_int8_uint8 && zero_point_diff == -128) || + (mixed_type_uint8_int8 && zero_point_diff == 128)) { + for (int i = 0; i < size; ++i) { + output_data[i] = input_data[i] ^ 0x80; + } + return; + } + } + static constexpr int32_t kMinOutput = std::numeric_limits::min(); + static constexpr int32_t kMaxOutput = std::numeric_limits::max(); + for (int i = 0; i < size; ++i) { + const int32_t input = input_data[i] - input_zeropoint; + const int32_t output = + MultiplyByQuantizedMultiplier(input, effective_scale_multiplier, + effective_scale_shift) + + output_zeropoint; + const int32_t clamped_output = + std::max(std::min(output, kMaxOutput), kMinOutput); + output_data[i] = static_cast(clamped_output); + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_REQUANTIZE_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/resize_bilinear.h b/components/tflite/tensorflow/lite/kernels/internal/reference/resize_bilinear.h new file mode 100644 index 00000000..6e24b38f --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/resize_bilinear.h @@ -0,0 +1,231 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_RESIZE_BILINEAR_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_RESIZE_BILINEAR_H_ + +#include +#include +#include +#include + +#include "tensorflow/lite/kernels/internal/cppmath.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +inline void ComputeInterpolationValues(const float value, const float scale, + const bool half_pixel_centers, + int32_t input_size, float *scaled_value, + int32_t *lower_bound, + int32_t *upper_bound) +{ + if (half_pixel_centers) { + *scaled_value = (value + 0.5f) * scale - 0.5f; + } else { + *scaled_value = value * scale; + } + float scaled_value_floor = std::floor(*scaled_value); + *lower_bound = std::max(static_cast(scaled_value_floor), + static_cast(0)); + *upper_bound = + std::min(static_cast(std::ceil(*scaled_value)), input_size - 1); +} + +template +inline void ResizeBilinear(const tflite::ResizeBilinearParams &op_params, + const RuntimeShape &unextended_input_shape, + const T *input_data, + const RuntimeShape &unextended_output_size_shape, + const int32_t *output_size_data, + const RuntimeShape &unextended_output_shape, + T *output_data) +{ + // If half_pixel_centers is True, align_corners must be False. + TFLITE_DCHECK(!op_params.half_pixel_centers || !op_params.align_corners); + TFLITE_DCHECK_LE(unextended_input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_LE(unextended_output_size_shape.DimensionsCount(), 4); + TFLITE_DCHECK_LE(unextended_output_shape.DimensionsCount(), 4); + const RuntimeShape input_shape = + RuntimeShape::ExtendedShape(4, unextended_input_shape); + const RuntimeShape output_size_shape = + RuntimeShape::ExtendedShape(4, unextended_output_size_shape); + const RuntimeShape output_shape = + RuntimeShape::ExtendedShape(4, unextended_output_shape); + + int32_t batches = MatchingDim(input_shape, 0, output_shape, 0); + int32_t input_height = input_shape.Dims(1); + int32_t input_width = input_shape.Dims(2); + int32_t depth = MatchingDim(input_shape, 3, output_shape, 3); + + TFLITE_DCHECK_EQ(output_size_shape.Dims(0), 1); + TFLITE_DCHECK_EQ(output_size_shape.Dims(1), 1); + TFLITE_DCHECK_EQ(output_size_shape.Dims(2), 1); + TFLITE_DCHECK_EQ(output_size_shape.Dims(3), 2); + int32_t output_height = + output_size_data[Offset(output_size_shape, 0, 0, 0, 0)]; + int32_t output_width = + output_size_data[Offset(output_size_shape, 0, 0, 0, 1)]; + + float height_scale = static_cast(input_height) / output_height; + float width_scale = static_cast(input_width) / output_width; + if (op_params.align_corners && output_height > 1) { + height_scale = static_cast(input_height - 1) / (output_height - 1); + } + if (op_params.align_corners && output_width > 1) { + width_scale = static_cast(input_width - 1) / (output_width - 1); + } + const float rounding_offset = std::numeric_limits::is_integer ? .5f : .0f; + + for (int b = 0; b < batches; ++b) { + for (int y = 0; y < output_height; ++y) { + float input_y; + int32_t y0, y1; + ComputeInterpolationValues(y, height_scale, op_params.half_pixel_centers, + input_height, &input_y, &y0, &y1); + for (int x = 0; x < output_width; ++x) { + float input_x; + int32_t x0, x1; + ComputeInterpolationValues(x, width_scale, op_params.half_pixel_centers, + input_width, &input_x, &x0, &x1); + for (int c = 0; c < depth; ++c) { + T interpolation = + static_cast(input_data[Offset(input_shape, b, y0, x0, c)] * + (1 - (input_y - y0)) * (1 - (input_x - x0)) + + input_data[Offset(input_shape, b, y1, x0, c)] * + (input_y - y0) * (1 - (input_x - x0)) + + input_data[Offset(input_shape, b, y0, x1, c)] * + (1 - (input_y - y0)) * (input_x - x0) + + input_data[Offset(input_shape, b, y1, x1, c)] * + (input_y - y0) * (input_x - x0) + + rounding_offset); + output_data[Offset(output_shape, b, y, x, c)] = interpolation; + } + } + } + } +} + +inline void ComputeInterpolationValuesInteger( + const int32_t value, const int32_t scale_10, const bool half_pixel_centers, + int32_t input_size, int32_t *scaled_value, int32_t *lower_bound, + int32_t *upper_bound) +{ + if (half_pixel_centers) { + *scaled_value = value * scale_10 + scale_10 / 2 - (1 << 9); + } else { + *scaled_value = value * scale_10; + } + constexpr int32_t zero = 0; + *lower_bound = std::max(*scaled_value / (1 << 10), zero); + *upper_bound = + std::min((*scaled_value + (1 << 10) - 1) / (1 << 10), input_size - 1); +} + +// Same as above but doesn't use any floating-point for the resize +template +inline void ResizeBilinearInteger( + const tflite::ResizeBilinearParams &op_params, + const RuntimeShape &unextended_input_shape, const T *input_data, + const RuntimeShape &unextended_output_size_shape, + const int32_t *output_size_data, + const RuntimeShape &unextended_output_shape, T *output_data) +{ + // If half_pixel_centers is True, align_corners must be False. + TFLITE_DCHECK(!op_params.half_pixel_centers || !op_params.align_corners); + TFLITE_DCHECK_LE(unextended_input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_LE(unextended_output_size_shape.DimensionsCount(), 4); + TFLITE_DCHECK_LE(unextended_output_shape.DimensionsCount(), 4); + const RuntimeShape input_shape = + RuntimeShape::ExtendedShape(4, unextended_input_shape); + const RuntimeShape output_size_shape = + RuntimeShape::ExtendedShape(4, unextended_output_size_shape); + const RuntimeShape output_shape = + RuntimeShape::ExtendedShape(4, unextended_output_shape); + + const int32_t batches = MatchingDim(input_shape, 0, output_shape, 0); + const int32_t input_height = input_shape.Dims(1); + const int32_t input_width = input_shape.Dims(2); + const int32_t depth = MatchingDim(input_shape, 3, output_shape, 3); + + TFLITE_DCHECK_EQ(output_size_shape.Dims(0), 1); + TFLITE_DCHECK_EQ(output_size_shape.Dims(1), 1); + TFLITE_DCHECK_EQ(output_size_shape.Dims(2), 1); + TFLITE_DCHECK_EQ(output_size_shape.Dims(3), 2); + const int32_t output_height = + output_size_data[Offset(output_size_shape, 0, 0, 0, 0)]; + const int32_t output_width = + output_size_data[Offset(output_size_shape, 0, 0, 0, 1)]; + + int32_t height_scale_10 = + ((1 << 10) * input_height + output_height / 2) / output_height; + int32_t width_scale_10 = + ((1 << 10) * input_width + output_width / 2) / output_width; + if (op_params.align_corners && output_height > 1) { + height_scale_10 = + ((1 << 10) * (input_height - 1) + (output_height - 1) / 2) / + (output_height - 1); + } + if (op_params.align_corners && output_width > 1) { + width_scale_10 = ((1 << 10) * (input_width - 1) + (output_width - 1) / 2) / + (output_width - 1); + } + + for (int b = 0; b < batches; ++b) { + for (int y = 0; y < output_height; ++y) { + int32_t input_y, y0, y1; + ComputeInterpolationValuesInteger(y, height_scale_10, + op_params.half_pixel_centers, + input_height, &input_y, &y0, &y1); + for (int x = 0; x < output_width; ++x) { + int32_t input_x, x0, x1; + ComputeInterpolationValuesInteger(x, width_scale_10, + op_params.half_pixel_centers, + input_width, &input_x, &x0, &x1); + for (int c = 0; c < depth; ++c) { + const int64_t output_20_ll = + static_cast( + input_data[Offset(input_shape, b, y0, x0, c)]) * + ((1 << 10) - (input_y - (1 << 10) * y0)) * + ((1 << 10) - (input_x - (1 << 10) * x0)); + const int64_t output_20_lu = + static_cast( + input_data[Offset(input_shape, b, y1, x0, c)]) * + (input_y - (1 << 10) * y0) * + ((1 << 10) - (input_x - (1 << 10) * x0)); + const int64_t output_20_rl = + static_cast( + input_data[Offset(input_shape, b, y0, x1, c)]) * + ((1 << 10) - (input_y - (1 << 10) * y0)) * + (input_x - (1 << 10) * x0); + const int64_t output_20_ru = + static_cast( + input_data[Offset(input_shape, b, y1, x1, c)]) * + (input_y - (1 << 10) * y0) * (input_x - (1 << 10) * x0); + const int64_t output_20 = + output_20_ll + output_20_lu + output_20_rl + output_20_ru; + const int64_t round = (output_20 > 0) ? (1 << 19) : -(1 << 19); + const T interpolation = + static_cast((output_20 + round) / (1 << 20)); + output_data[Offset(output_shape, b, y, x, c)] = interpolation; + } + } + } + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_RESIZE_BILINEAR_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/resize_nearest_neighbor.h b/components/tflite/tensorflow/lite/kernels/internal/reference/resize_nearest_neighbor.h new file mode 100644 index 00000000..1c308a3e --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/resize_nearest_neighbor.h @@ -0,0 +1,97 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_RESIZE_NEAREST_NEIGHBOR_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_RESIZE_NEAREST_NEIGHBOR_H_ + +#include + +#include "tensorflow/lite/kernels/internal/cppmath.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +inline int32_t GetNearestNeighbor(const int input_value, + const int32_t input_size, + const int32_t output_size, + const bool align_corners, + const bool half_pixel_centers) +{ + const float scale = + (align_corners && output_size > 1) ? (input_size - 1) / static_cast(output_size - 1) : input_size / static_cast(output_size); + const float offset = half_pixel_centers ? 0.5f : 0.0f; + int32_t output_value = std::min( + align_corners ? static_cast(TfLiteRound((input_value + offset) * scale)) : static_cast(std::floor((input_value + offset) * scale)), + input_size - 1); + if (half_pixel_centers) { + output_value = std::max(static_cast(0), output_value); + } + return output_value; +} + +template +inline void ResizeNearestNeighbor( + const tflite::ResizeNearestNeighborParams &op_params, + const RuntimeShape &unextended_input_shape, const T *input_data, + const RuntimeShape &output_size_shape, const int32_t *output_size_data, + const RuntimeShape &unextended_output_shape, T *output_data) +{ + TFLITE_DCHECK_LE(unextended_input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_LE(unextended_output_shape.DimensionsCount(), 4); + + const RuntimeShape input_shape = + RuntimeShape::ExtendedShape(4, unextended_input_shape); + const RuntimeShape output_shape = + RuntimeShape::ExtendedShape(4, unextended_output_shape); + + int32_t batches = MatchingDim(input_shape, 0, output_shape, 0); + int32_t input_height = input_shape.Dims(1); + int32_t input_width = input_shape.Dims(2); + int32_t depth = MatchingDim(input_shape, 3, output_shape, 3); + + // The Tensorflow version of this op allows resize on the width and height + // axis only. + TFLITE_DCHECK_EQ(output_size_shape.FlatSize(), 2); + int32_t output_height = output_size_data[0]; + int32_t output_width = output_size_data[1]; + + const int col_offset = input_shape.Dims(3); + const int row_offset = input_shape.Dims(2) * col_offset; + const int batch_offset = input_shape.Dims(1) * row_offset; + + const T *input_ptr = input_data; + T *output_ptr = output_data; + for (int b = 0; b < batches; ++b) { + for (int y = 0; y < output_height; ++y) { + int32_t in_y = GetNearestNeighbor(y, input_height, output_height, + op_params.align_corners, + op_params.half_pixel_centers); + const T *y_input_ptr = input_ptr + in_y * row_offset; + for (int x = 0; x < output_width; ++x) { + int32_t in_x = GetNearestNeighbor(x, input_width, output_width, + op_params.align_corners, + op_params.half_pixel_centers); + const T *x_input_ptr = y_input_ptr + in_x * col_offset; + memcpy(output_ptr, x_input_ptr, depth * sizeof(T)); + output_ptr += depth; + } + } + input_ptr += batch_offset; + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_RESIZE_NEAREST_NEIGHBOR_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/round.h b/components/tflite/tensorflow/lite/kernels/internal/reference/round.h new file mode 100644 index 00000000..70b8cdba --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/round.h @@ -0,0 +1,51 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ROUND_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ROUND_H_ + +#include + +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +inline float RoundToNearest(float value) +{ + auto floor_val = std::floor(value); + auto diff = value - floor_val; + if ((diff < 0.5f) || + ((diff == 0.5f) && (static_cast(floor_val) % 2 == 0))) { + return floor_val; + } else { + return floor_val = floor_val + 1.0f; + } +} + +inline void Round(const RuntimeShape &input_shape, const float *input_data, + const RuntimeShape &output_shape, float *output_data) +{ + const int flat_size = MatchingFlatSize(input_shape, output_shape); + for (int i = 0; i < flat_size; ++i) { + // Note that this implementation matches that of tensorFlow tf.round + // and corresponds to the bankers rounding method. + // cfenv (for fesetround) is not yet supported universally on Android, so + // using a work around. + output_data[i] = RoundToNearest(input_data[i]); + } +} + +} // namespace reference_ops +} // namespace tflite +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ROUND_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/softmax.h b/components/tflite/tensorflow/lite/kernels/internal/reference/softmax.h new file mode 100644 index 00000000..bab27b0d --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/softmax.h @@ -0,0 +1,235 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_SOFTMAX_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_SOFTMAX_H_ + +#include + +#include "fixedpoint/fixedpoint.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/cppmath.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/types.h" +#include "tensorflow/lite/kernels/op_macros.h" + +namespace tflite { +namespace reference_ops { +inline void Softmax(const SoftmaxParams ¶ms, + const RuntimeShape &input_shape, const float *input_data, + const RuntimeShape &output_shape, float *output_data) +{ + const int trailing_dim = input_shape.DimensionsCount() - 1; + const int outer_size = + MatchingFlatSizeSkipDim(input_shape, trailing_dim, output_shape); + const int depth = + MatchingDim(input_shape, trailing_dim, output_shape, trailing_dim); + + for (int i = 0; i < outer_size; ++i) { + // Find max element value which we'll use to ensure numerical stability + // taking advantage of the following equality: + // exp(x[i])/sum(exp(x[i])) == exp(x[i]+C)/sum(exp(x[i]+C)) + float max = std::numeric_limits::lowest(); + for (int c = 0; c < depth; ++c) { + max = std::max(max, input_data[i * depth + c]); + } + + // Compute sum. + float sum = 0.f; + for (int c = 0; c < depth; ++c) { + const float exp_c = std::exp((input_data[i * depth + c] - max) * + static_cast(params.beta)); + output_data[i * depth + c] = exp_c; + sum += exp_c; + } + + // Compute result. + for (int c = 0; c < depth; ++c) { + output_data[i * depth + c] = output_data[i * depth + c] / sum; + } + } +} + +// Quantized softmax with int8_t/uint8_t input and int8_t/uint8_t/int16_t +// output. +template +inline void Softmax(const SoftmaxParams ¶ms, + const RuntimeShape &input_shape, const InputT *input_data, + const RuntimeShape &output_shape, OutputT *output_data) +{ + const int32_t input_beta_multiplier = params.input_multiplier; + const int32_t input_beta_left_shift = params.input_left_shift; + const int diff_min = params.diff_min; + // The representation chosen for the input to the exp() function is Q5.26. + // We need to leave extra space since values that we skip might be as large as + // -32 before multiplying by input_beta_multiplier, and therefore as large as + // -16 afterwards. Note that exp(-8) is definitely not insignificant to + // accumulation, but exp(-16) definitely is. + static const int kScaledDiffIntegerBits = 5; + static const int kAccumulationIntegerBits = 12; + using FixedPointScaledDiff = + gemmlowp::FixedPoint; + using FixedPointAccum = + gemmlowp::FixedPoint; + using FixedPoint0 = gemmlowp::FixedPoint; + + const int trailing_dim = input_shape.DimensionsCount() - 1; + const int outer_size = + MatchingFlatSizeSkipDim(input_shape, trailing_dim, output_shape); + const int depth = + MatchingDim(input_shape, trailing_dim, output_shape, trailing_dim); + + for (int i = 0; i < outer_size; ++i) { + InputT max_in_row = std::numeric_limits::min(); + for (int c = 0; c < depth; ++c) { + max_in_row = std::max(max_in_row, input_data[i * depth + c]); + } + + FixedPointAccum sum_of_exps = FixedPointAccum::Zero(); + for (int c = 0; c < depth; ++c) { + int32_t input_diff = + static_cast(input_data[i * depth + c]) - max_in_row; + if (input_diff >= diff_min) { + const int32_t input_diff_rescaled = + MultiplyByQuantizedMultiplierGreaterThanOne( + input_diff, input_beta_multiplier, input_beta_left_shift); + const FixedPointScaledDiff scaled_diff_f8 = + FixedPointScaledDiff::FromRaw(input_diff_rescaled); + sum_of_exps = sum_of_exps + gemmlowp::Rescale( + exp_on_negative_values(scaled_diff_f8)); + } + } + + int num_bits_over_unit; + FixedPoint0 shifted_scale = FixedPoint0::FromRaw(GetReciprocal( + sum_of_exps.raw(), kAccumulationIntegerBits, &num_bits_over_unit)); + + for (int c = 0; c < depth; ++c) { + int32_t input_diff = + static_cast(input_data[i * depth + c]) - max_in_row; + if (input_diff >= diff_min) { + const int32_t input_diff_rescaled = + MultiplyByQuantizedMultiplierGreaterThanOne( + input_diff, input_beta_multiplier, input_beta_left_shift); + const FixedPointScaledDiff scaled_diff_f8 = + FixedPointScaledDiff::FromRaw(input_diff_rescaled); + + FixedPoint0 exp_in_0 = exp_on_negative_values(scaled_diff_f8); + int32_t unsat_output = gemmlowp::RoundingDivideByPOT( + (shifted_scale * exp_in_0).raw(), + num_bits_over_unit + 31 - (sizeof(OutputT) * 8)); + + const int32_t shifted_output = + unsat_output + + static_cast(std::numeric_limits::min()); + + output_data[i * depth + c] = static_cast(std::max( + std::min(shifted_output, + static_cast(std::numeric_limits::max())), + static_cast(std::numeric_limits::min()))); + } else { + output_data[i * depth + c] = std::numeric_limits::min(); + } + } + } +} + +// Computes exp(input - max_input) +inline int16_t SoftMaxCalculateExp(const SoftmaxParams ¶ms, + const int16_t *input_data, const int depth, + int16_t max_in_row, int i, int c) +{ + int32_t input_diff = input_data[i * depth + c] - max_in_row; + // scale the input_diff such that [-65535, 0] correspond to [-10.0, 0.0] + // exp lut generated with range [-10, 0], as exp(-10) is negligible. + int32_t scaled_diff = MultiplyByQuantizedMultiplier( + input_diff, params.input_multiplier, params.input_left_shift); + // recenter to [-32768, 32767] + int32_t sym_scaled_diff = scaled_diff + 32767; + int16_t sat_sym_scaled_diff = + std::min(std::max(sym_scaled_diff, static_cast(-32768)), + static_cast(32767)); + // apply the exp() LUT activation function + return generic_int16_table_lookup(sat_sym_scaled_diff, params.exp_lut); +} +// Quantized softmax with int16_t input and int16_t output. +inline void SoftmaxInt16(const SoftmaxParams ¶ms, + const RuntimeShape &input_shape, + const int16_t *input_data, + const RuntimeShape &output_shape, + int16_t *output_data) +{ + const int trailing_dim = input_shape.DimensionsCount() - 1; + const int outer_size = + MatchingFlatSizeSkipDim(input_shape, trailing_dim, output_shape); + const int depth = + MatchingDim(input_shape, trailing_dim, output_shape, trailing_dim); + + for (int i = 0; i < outer_size; ++i) { + // Find the largest element + int16_t max_in_row = std::numeric_limits::min(); + for (int c = 0; c < depth; ++c) { + max_in_row = std::max(max_in_row, input_data[i * depth + c]); + } + + // This loops computes the exp values and their sum. We will need the exp + // values later on in the function so we cache them in the output_data + // buffer. This is an optimization done to avoid calculating the exp values + // twice making use of the output_data buffer as scratch memory. + int32_t sum_of_exps = 0; // Q16.15 fixed point format. + int16_t *exp_results_Q015 = output_data + i * depth; + for (int c = 0; c < depth; ++c) { + exp_results_Q015[c] = + SoftMaxCalculateExp(params, input_data, depth, max_in_row, i, c); + sum_of_exps += exp_results_Q015[c]; + } + + // Compute the reciprocal 1/sum_of_exps + uint8_t headroom_plus_one = + CountLeadingZeros(static_cast(sum_of_exps)); + int32_t shifted_sum = + ((static_cast(sum_of_exps) << (headroom_plus_one - 1)) + + (1 << 13)) >> + 14; + // since the LUT computes 1/(1 + x) we need to first compute x = (sum - 1). + // also, the LUT expects a symmetrical input, so we must also recenter x + // from [0, 65535] to [-32768, 32767]. + int32_t sym_shifted_sum = shifted_sum + (-((1 << 15) + (1 << 16))); + int16_t sat_sym_shifted_sum = static_cast( + std::min(std::max(sym_shifted_sum, static_cast(-32768)), + static_cast(32767))); + // apply 1/(1 + x) LUT activation function + int16_t reciprocal_scale_Q015 = generic_int16_table_lookup( + sat_sym_shifted_sum, params.one_over_one_plus_x_lut); + + // Rescale the exp_result with reciprocal + // range of output is [0, 32767] correspond to [0.0, 1.0] + for (int c = 0; c < depth; ++c) { + uint8_t right_shift = 31 - headroom_plus_one; + int64_t round = 1 << (right_shift - 1); + int32_t result = (static_cast(exp_results_Q015[c]) * + static_cast(reciprocal_scale_Q015) + + round) >> + right_shift; + output_data[i * depth + c] = static_cast( + std::min(std::max(result, static_cast(0)), + static_cast(32767))); + } + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_SOFTMAX_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/space_to_batch_nd.h b/components/tflite/tensorflow/lite/kernels/internal/reference/space_to_batch_nd.h new file mode 100644 index 00000000..48b6b0cb --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/space_to_batch_nd.h @@ -0,0 +1,110 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_SPACE_TO_BATCH_ND_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_SPACE_TO_BATCH_ND_H_ + +#include + +#include "ruy/profiler/instrumentation.h" // from @ruy +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +// TODO(b/135760455): Move this method anonymous namespace in a cc file. +inline RuntimeShape ExtendShapeSpaceToBatch(const RuntimeShape &shape) +{ + if (shape.DimensionsCount() == 4) { + return shape; + } + RuntimeShape new_shape(4, 1); + new_shape.SetDim(0, shape.Dims(0)); + new_shape.SetDim(1, shape.Dims(1)); + new_shape.SetDim(3, shape.Dims(2)); + return new_shape; +} + +template +inline void SpaceToBatchND(const SpaceToBatchParams ¶ms, + const RuntimeShape &unextended_input1_shape, + const T *input1_data, + const RuntimeShape &unextended_input2_shape, + const int32_t *block_shape_data, + const RuntimeShape &unextended_input3_shape, + const int32_t *paddings_data, + const RuntimeShape &unextended_output_shape, + T *output_data) +{ + ruy::profiler::ScopeLabel label("SpaceToBatchND"); + TFLITE_DCHECK_GE(unextended_input1_shape.DimensionsCount(), 3); + TFLITE_DCHECK_LE(unextended_input1_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(unextended_input1_shape.DimensionsCount(), + unextended_output_shape.DimensionsCount()); + + // Extends the input/output shape from 3D to 4D if needed, NHC -> NH1C. + const RuntimeShape input1_shape = + ExtendShapeSpaceToBatch(unextended_input1_shape); + const RuntimeShape output_shape = + ExtendShapeSpaceToBatch(unextended_output_shape); + + const int depth = input1_shape.Dims(3); + const int input_width = input1_shape.Dims(2); + const int input_height = input1_shape.Dims(1); + const int input_batch_size = input1_shape.Dims(0); + + const int output_width = output_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_batch_size = output_shape.Dims(0); + + const int block_shape_height = block_shape_data[0]; + const int block_shape_width = + unextended_input1_shape.DimensionsCount() == 4 ? block_shape_data[1] : 1; + const int padding_top = paddings_data[0]; + const int padding_left = + unextended_input1_shape.DimensionsCount() == 4 ? paddings_data[2] : 0; + + // For uint8 quantized, the correct padding "zero value" is the output offset. + const int32_t pad_value = params.output_offset; + for (int out_b = 0; out_b < output_batch_size; ++out_b) { + int input_batch = out_b % input_batch_size; + int shift_w = (out_b / input_batch_size) % block_shape_width; + int shift_h = (out_b / input_batch_size) / block_shape_width; + for (int out_h = 0; out_h < output_height; ++out_h) { + for (int out_w = 0; out_w < output_width; ++out_w) { + T *out = output_data + Offset(output_shape, out_b, out_h, out_w, 0); + if (out_h * block_shape_height + shift_h < padding_top || + out_h * block_shape_height + shift_h >= + padding_top + input_height || + out_w * block_shape_width + shift_w < padding_left || + out_w * block_shape_width + shift_w >= padding_left + input_width) { + // This may not execute correctly when pad_value != 0 and T != uint8. + memset(out, pad_value, depth * sizeof(T)); + } else { + const T *in = + input1_data + + Offset(input1_shape, input_batch, + (out_h * block_shape_height + shift_h) - padding_top, + (out_w * block_shape_width + shift_w) - padding_left, 0); + memcpy(out, in, depth * sizeof(T)); + } + } + } + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_SPACE_TO_BATCH_ND_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/space_to_depth.h b/components/tflite/tensorflow/lite/kernels/internal/reference/space_to_depth.h new file mode 100644 index 00000000..cb48f3c8 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/space_to_depth.h @@ -0,0 +1,78 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_SPACE_TO_DEPTH_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_SPACE_TO_DEPTH_H_ + +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +template +inline void SpaceToDepth(const tflite::SpaceToDepthParams &op_params, + const RuntimeShape &unextended_input_shape, + const T *input_data, + const RuntimeShape &unextended_output_shape, + T *output_data) +{ + TFLITE_DCHECK_LE(unextended_input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_LE(unextended_output_shape.DimensionsCount(), 4); + const RuntimeShape input_shape = + RuntimeShape::ExtendedShape(4, unextended_input_shape); + const RuntimeShape output_shape = + RuntimeShape::ExtendedShape(4, unextended_output_shape); + + const int input_depth = input_shape.Dims(3); + const int input_width = input_shape.Dims(2); + const int input_height = input_shape.Dims(1); + const int input_batch = input_shape.Dims(0); + + const int output_depth = output_shape.Dims(3); + const int output_width = output_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_batch = output_shape.Dims(0); + + const int32_t block_size = op_params.block_size; + + TFLITE_DCHECK_EQ(input_width, output_width * block_size); + TFLITE_DCHECK_EQ(input_height, output_height * block_size); + TFLITE_DCHECK_EQ(input_depth * block_size * block_size, output_depth); + TFLITE_DCHECK_EQ(input_batch, output_batch); + + for (int in_b = 0; in_b < input_batch; ++in_b) { + for (int in_h = 0; in_h < input_height; ++in_h) { + for (int in_w = 0; in_w < input_width; ++in_w) { + for (int in_d = 0; in_d < input_depth; ++in_d) { + const int out_d = + in_d + ((in_h % block_size) * block_size + in_w % block_size) * + input_depth; + const int out_w = in_w / block_size; + const int out_h = in_h / block_size; + const int out_b = in_b; + + const int input_index = Offset(input_shape, in_b, in_h, in_w, in_d); + const int output_index = + Offset(output_shape, out_b, out_h, out_w, out_d); + + output_data[output_index] = input_data[input_index]; + } + } + } + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_SPACE_TO_DEPTH_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/strided_slice.h b/components/tflite/tensorflow/lite/kernels/internal/reference/strided_slice.h new file mode 100644 index 00000000..165fa2b7 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/strided_slice.h @@ -0,0 +1,122 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_STRIDED_SLICE_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_STRIDED_SLICE_H_ + +#include "ruy/profiler/instrumentation.h" // from @ruy +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/kernels/internal/portable_tensor.h" +#include "tensorflow/lite/kernels/internal/strided_slice_logic.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +template +inline void StridedSlice(const tflite::StridedSliceParams &op_params, + const RuntimeShape &unextended_input_shape, + const RuntimeShape &unextended_output_shape, + SequentialTensorWriter *writer) +{ + using strided_slice::LoopCondition; + using strided_slice::StartForAxis; + using strided_slice::StopForAxis; + + ruy::profiler::ScopeLabel label("StridedSlice"); + + // Note that the output_shape is not used herein. + tflite::StridedSliceParams params_copy = op_params; + + TFLITE_DCHECK_LE(unextended_input_shape.DimensionsCount(), 5); + TFLITE_DCHECK_LE(unextended_output_shape.DimensionsCount(), 5); + const RuntimeShape input_shape = + RuntimeShape::ExtendedShape(5, unextended_input_shape); + const RuntimeShape output_shape = + RuntimeShape::ExtendedShape(5, unextended_output_shape); + + // Reverse and pad to 5 dimensions because that is what the runtime code + // requires (ie. all shapes must be 5D and are given backwards). + strided_slice::StridedSlicePadIndices(¶ms_copy, 5); + + const int start_0 = StartForAxis(params_copy, input_shape, 0); + const int stop_0 = StopForAxis(params_copy, input_shape, 0, start_0); + const int start_1 = StartForAxis(params_copy, input_shape, 1); + const int stop_1 = StopForAxis(params_copy, input_shape, 1, start_1); + const int start_2 = StartForAxis(params_copy, input_shape, 2); + const int stop_2 = StopForAxis(params_copy, input_shape, 2, start_2); + const int start_3 = StartForAxis(params_copy, input_shape, 3); + const int stop_3 = StopForAxis(params_copy, input_shape, 3, start_3); + const int start_4 = StartForAxis(params_copy, input_shape, 4); + const int stop_4 = StopForAxis(params_copy, input_shape, 4, start_4); + + for (int offset_0 = start_0 * input_shape.Dims(1), + end_0 = stop_0 * input_shape.Dims(1), + step_0 = params_copy.strides[0] * input_shape.Dims(1); + !LoopCondition(offset_0, end_0, params_copy.strides[0]); + offset_0 += step_0) { + for (int offset_1 = (offset_0 + start_1) * input_shape.Dims(2), + end_1 = (offset_0 + stop_1) * input_shape.Dims(2), + step_1 = params_copy.strides[1] * input_shape.Dims(2); + !LoopCondition(offset_1, end_1, params_copy.strides[1]); + offset_1 += step_1) { + for (int offset_2 = (offset_1 + start_2) * input_shape.Dims(3), + end_2 = (offset_1 + stop_2) * input_shape.Dims(3), + step_2 = params_copy.strides[2] * input_shape.Dims(3); + !LoopCondition(offset_2, end_2, params_copy.strides[2]); + offset_2 += step_2) { + for (int offset_3 = (offset_2 + start_3) * input_shape.Dims(4), + end_3 = (offset_2 + stop_3) * input_shape.Dims(4), + step_3 = params_copy.strides[3] * input_shape.Dims(4); + !LoopCondition(offset_3, end_3, params_copy.strides[3]); + offset_3 += step_3) { + for (int offset_4 = offset_3 + start_4, end_4 = offset_3 + stop_4; + !LoopCondition(offset_4, end_4, params_copy.strides[4]); + offset_4 += params_copy.strides[4]) { + writer->Write(offset_4); + } + } + } + } + } +} + +template +inline void StridedSlice(const tflite::StridedSliceParams &op_params, + const RuntimeShape &unextended_input_shape, + const T *input_data, + const RuntimeShape &unextended_output_shape, + T *output_data) +{ + SequentialTensorWriter writer(input_data, output_data); + StridedSlice(op_params, unextended_input_shape, unextended_output_shape, + &writer); +} + +template +inline void StridedSlice(const tflite::StridedSliceParams &op_params, + const RuntimeShape &unextended_input_shape, + const TfLiteTensor *input, + const RuntimeShape &unextended_output_shape, + TfLiteTensor *output) +{ + SequentialTensorWriter writer(input, output); + StridedSlice(op_params, unextended_input_shape, unextended_output_shape, + &writer); +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_STRIDED_SLICE_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/sub.h b/components/tflite/tensorflow/lite/kernels/internal/reference/sub.h new file mode 100644 index 00000000..b8326416 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/sub.h @@ -0,0 +1,572 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_SUB_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_SUB_H_ + +#include + +#include +#include + +#include "ruy/profiler/instrumentation.h" // from @ruy +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +inline void SubNonBroadcast(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, + const float *input1_data, + const RuntimeShape &input2_shape, + const float *input2_data, + const RuntimeShape &output_shape, + float *output_data) +{ + const int flat_size = + MatchingElementsSize(input1_shape, input2_shape, output_shape); + for (int i = 0; i < flat_size; ++i) { + output_data[i] = ActivationFunctionWithMinMax( + input1_data[i] - input2_data[i], params.float_activation_min, + params.float_activation_max); + } +} + +inline void SubNonBroadcast(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, + const int32_t *input1_data, + const RuntimeShape &input2_shape, + const int32_t *input2_data, + const RuntimeShape &output_shape, + int32_t *output_data) +{ + const int flat_size = + MatchingElementsSize(input1_shape, input2_shape, output_shape); + for (int i = 0; i < flat_size; ++i) { + output_data[i] = ActivationFunctionWithMinMax( + input1_data[i] - input2_data[i], params.quantized_activation_min, + params.quantized_activation_max); + } +} + +// TODO(b/151345304): We can implement BroadcastSub on buffers of arbitrary +// dimensionality if the runtime code does a single loop over one dimension +// that handles broadcasting as the base case. The code generator would then +// generate max(D1, D2) nested for loops. +template +inline void BroadcastSubSlow(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, + const float *input1_data, + const RuntimeShape &input2_shape, + const float *input2_data, + const RuntimeShape &output_shape, + float *output_data) +{ + ruy::profiler::ScopeLabel label("BroadcastSubSlow/float"); + TFLITE_DCHECK_LE(input1_shape.DimensionsCount(), N); + TFLITE_DCHECK_LE(input2_shape.DimensionsCount(), N); + TFLITE_DCHECK_LE(output_shape.DimensionsCount(), N); + NdArrayDesc desc1; + NdArrayDesc desc2; + NdArrayDesc output_desc; + NdArrayDescsForElementwiseBroadcast(input1_shape, input2_shape, &desc1, + &desc2); + CopyDimsToDesc(RuntimeShape::ExtendedShape(N, output_shape), &output_desc); + + // In Tensorflow, the dimensions are canonically named (batch_number, row, + // col, channel), with extents (batches, height, width, depth), with the + // trailing dimension changing most rapidly (channels has the smallest stride, + // typically 1 element). + // + // In generated C code, we store arrays with the dimensions reversed. The + // first dimension has smallest stride. + // + // We name our variables by their Tensorflow convention, but generate C code + // nesting loops such that the innermost loop has the smallest stride for the + // best cache behavior. + auto sub_func = [&](int indexes[N]) { + output_data[SubscriptToIndex(output_desc, indexes)] = + ActivationFunctionWithMinMax( + input1_data[SubscriptToIndex(desc1, indexes)] - + input2_data[SubscriptToIndex(desc2, indexes)], + params.float_activation_min, params.float_activation_max); + }; + NDOpsHelper(output_desc, sub_func); +} + +template +inline void BroadcastSubSlow(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, + const uint8_t *input1_data, + const RuntimeShape &input2_shape, + const uint8_t *input2_data, + const RuntimeShape &output_shape, + uint8_t *output_data) +{ + ruy::profiler::ScopeLabel label("BroadcastSubSlow/uint8_t"); + TFLITE_DCHECK_LE(input1_shape.DimensionsCount(), N); + TFLITE_DCHECK_LE(input2_shape.DimensionsCount(), N); + TFLITE_DCHECK_LE(output_shape.DimensionsCount(), N); + NdArrayDesc desc1; + NdArrayDesc desc2; + NdArrayDesc output_desc; + NdArrayDescsForElementwiseBroadcast(input1_shape, input2_shape, &desc1, + &desc2); + CopyDimsToDesc(RuntimeShape::ExtendedShape(N, output_shape), &output_desc); + + // In Tensorflow, the dimensions are canonically named (batch_number, row, + // col, channel), with extents (batches, height, width, depth), with the + // trailing dimension changing most rapidly (channels has the smallest stride, + // typically 1 element). + // + // In generated C code, we store arrays with the dimensions reversed. The + // first dimension has smallest stride. + // + // We name our variables by their Tensorflow convention, but generate C code + // nesting loops such that the innermost loop has the smallest stride for the + // best cache behavior. + auto sub_func = [&](int indexes[N]) { + const int32_t input1_val = + params.input1_offset + input1_data[SubscriptToIndex(desc1, indexes)]; + const int32_t input2_val = + params.input2_offset + input2_data[SubscriptToIndex(desc2, indexes)]; + const int32_t shifted_input1_val = input1_val * (1 << params.left_shift); + const int32_t shifted_input2_val = input2_val * (1 << params.left_shift); + const int32_t scaled_input1_val = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + shifted_input1_val, params.input1_multiplier, params.input1_shift); + const int32_t scaled_input2_val = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + shifted_input2_val, params.input2_multiplier, params.input2_shift); + const int32_t raw_sub = scaled_input1_val - scaled_input2_val; + const int32_t raw_output = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + raw_sub, params.output_multiplier, params.output_shift) + + params.output_offset; + const int32_t clamped_output = + std::min(params.quantized_activation_max, + std::max(params.quantized_activation_min, raw_output)); + output_data[SubscriptToIndex(output_desc, indexes)] = + static_cast(clamped_output); + }; + NDOpsHelper(output_desc, sub_func); +} + +template +inline void BroadcastSubSlow(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, + const int32_t *input1_data, + const RuntimeShape &input2_shape, + const int32_t *input2_data, + const RuntimeShape &output_shape, + int32_t *output_data) +{ + ruy::profiler::ScopeLabel label("BroadcastSubSlow/int32_t"); + TFLITE_DCHECK_LE(input1_shape.DimensionsCount(), N); + TFLITE_DCHECK_LE(input2_shape.DimensionsCount(), N); + TFLITE_DCHECK_LE(output_shape.DimensionsCount(), N); + NdArrayDesc desc1; + NdArrayDesc desc2; + NdArrayDesc output_desc; + NdArrayDescsForElementwiseBroadcast(input1_shape, input2_shape, &desc1, + &desc2); + CopyDimsToDesc(RuntimeShape::ExtendedShape(N, output_shape), &output_desc); + + // In Tensorflow, the dimensions are canonically named (batch_number, row, + // col, channel), with extents (batches, height, width, depth), with the + // trailing dimension changing most rapidly (channels has the smallest stride, + // typically 1 element). + // + // In generated C code, we store arrays with the dimensions reversed. The + // first dimension has smallest stride. + // + // We name our variables by their Tensorflow convention, but generate C code + // nesting loops such that the innermost loop has the smallest stride for the + // best cache behavior. + auto sub_func = [&](int indexes[N]) { + output_data[SubscriptToIndex(output_desc, indexes)] = + ActivationFunctionWithMinMax( + input1_data[SubscriptToIndex(desc1, indexes)] - + input2_data[SubscriptToIndex(desc2, indexes)], + params.quantized_activation_min, params.quantized_activation_max); + }; + NDOpsHelper(output_desc, sub_func); +} + +template +inline void BroadcastSubSlow(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, + const int8_t *input1_data, + const RuntimeShape &input2_shape, + const int8_t *input2_data, + const RuntimeShape &output_shape, + int8_t *output_data) +{ + ruy::profiler::ScopeLabel label("BroadcastSubSlow/int8_t"); + NdArrayDesc desc1; + NdArrayDesc desc2; + NdArrayDesc output_desc; + NdArrayDescsForElementwiseBroadcast(input1_shape, input2_shape, &desc1, + &desc2); + CopyDimsToDesc(RuntimeShape::ExtendedShape(N, output_shape), &output_desc); + + // In Tensorflow, the dimensions are canonically named (batch_number, row, + // col, channel), with extents (batches, height, width, depth), with the + // trailing dimension changing most rapidly (channels has the smallest stride, + // typically 1 element). + // + // In generated C code, we store arrays with the dimensions reversed. The + // first dimension has smallest stride. + // + // We name our variables by their Tensorflow convention, but generate C code + // nesting loops such that the innermost loop has the smallest stride for the + // best cache behavior. + auto sub_func = [&](int indexes[N]) { + const int32_t input1_val = + params.input1_offset + input1_data[SubscriptToIndex(desc1, indexes)]; + const int32_t input2_val = + params.input2_offset + input2_data[SubscriptToIndex(desc2, indexes)]; + const int32_t shifted_input1_val = input1_val * (1 << params.left_shift); + const int32_t shifted_input2_val = input2_val * (1 << params.left_shift); + const int32_t scaled_input1_val = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + shifted_input1_val, params.input1_multiplier, params.input1_shift); + const int32_t scaled_input2_val = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + shifted_input2_val, params.input2_multiplier, params.input2_shift); + const int32_t raw_sub = scaled_input1_val - scaled_input2_val; + const int32_t raw_output = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + raw_sub, params.output_multiplier, params.output_shift) + + params.output_offset; + const int32_t clamped_output = + std::min(params.quantized_activation_max, + std::max(params.quantized_activation_min, raw_output)); + output_data[SubscriptToIndex(output_desc, indexes)] = + static_cast(clamped_output); + }; + NDOpsHelper(output_desc, sub_func); +} + +template +void BroadcastSubSlow(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, + const int64_t *input1_data, + const RuntimeShape &input2_shape, + const int64_t *input2_data, + const RuntimeShape &output_shape, int64_t *output_data) +{ + ruy::profiler::ScopeLabel label("BroadcastSubSlow/int64_t"); + TFLITE_DCHECK_LE(input1_shape.DimensionsCount(), N); + TFLITE_DCHECK_LE(input2_shape.DimensionsCount(), N); + TFLITE_DCHECK_LE(output_shape.DimensionsCount(), N); + NdArrayDesc desc1; + NdArrayDesc desc2; + NdArrayDesc output_desc; + NdArrayDescsForElementwiseBroadcast(input1_shape, input2_shape, &desc1, + &desc2); + CopyDimsToDesc(RuntimeShape::ExtendedShape(N, output_shape), &output_desc); + + // In Tensorflow, the dimensions are canonically named (batch_number, row, + // col, channel), with extents (batches, height, width, depth), with the + // trailing dimension changing most rapidly (channels has the smallest stride, + // typically 1 element). + // + // In generated C code, we store arrays with the dimensions reversed. The + // first dimension has smallest stride. + // + // We name our variables by their Tensorflow convention, but generate C code + // nesting loops such that the innermost loop has the smallest stride for the + // best cache behavior. + auto sub_func = [&](int indexes[N]) { + output_data[SubscriptToIndex(output_desc, indexes)] = + ActivationFunctionWithMinMax( + input1_data[SubscriptToIndex(desc1, indexes)] - + input2_data[SubscriptToIndex(desc2, indexes)], + params.int64_activation_min, params.int64_activation_max); + }; + NDOpsHelper(output_desc, sub_func); +} + +template +void BroadcastSubSlow(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, const T *input1_data, + const RuntimeShape &input2_shape, const T *input2_data, + const RuntimeShape &output_shape, T *output_data) +{ + ruy::profiler::ScopeLabel label("BroadcastSubSlow/templated"); + TFLITE_DCHECK_LE(input1_shape.DimensionsCount(), N); + TFLITE_DCHECK_LE(input2_shape.DimensionsCount(), N); + TFLITE_DCHECK_LE(output_shape.DimensionsCount(), N); + NdArrayDesc desc1; + NdArrayDesc desc2; + NdArrayDesc output_desc; + NdArrayDescsForElementwiseBroadcast(input1_shape, input2_shape, &desc1, + &desc2); + CopyDimsToDesc(RuntimeShape::ExtendedShape(N, output_shape), &output_desc); + + // In Tensorflow, the dimensions are canonically named (batch_number, row, + // col, channel), with extents (batches, height, width, depth), with the + // trailing dimension changing most rapidly (channels has the smallest stride, + // typically 1 element). + // + // In generated C code, we store arrays with the dimensions reversed. The + // first dimension has smallest stride. + // + // We name our variables by their Tensorflow convention, but generate C code + // nesting loops such that the innermost loop has the smallest stride for the + // best cache behavior. + auto sub_func = [&](int indexes[N]) { + output_data[SubscriptToIndex(output_desc, indexes)] = + ActivationFunctionWithMinMax( + input1_data[SubscriptToIndex(desc1, indexes)] - + input2_data[SubscriptToIndex(desc2, indexes)], + params.quantized_activation_min, params.quantized_activation_max); + }; + NDOpsHelper(output_desc, sub_func); +} + +template +inline void BroadcastSub16POTSlow(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, + const int16_t *input1_data, + const RuntimeShape &input2_shape, + const int16_t *input2_data, + const RuntimeShape &output_shape, + int16_t *output_data) +{ + ruy::profiler::ScopeLabel label("BroadcastSub16POTSlow/int16_t"); + NdArrayDesc desc1; + NdArrayDesc desc2; + NdArrayDesc output_desc; + NdArrayDescsForElementwiseBroadcast(input1_shape, input2_shape, &desc1, + &desc2); + CopyDimsToDesc(RuntimeShape::ExtendedShape(N, output_shape), &output_desc); + + // In Tensorflow, the dimensions are canonically named (batch_number, row, + // col, channel), with extents (batches, height, width, depth), with the + // trailing dimension changing most rapidly (channels has the smallest stride, + // typically 1 element). + // + // In generated C code, we store arrays with the dimensions reversed. The + // first dimension has smallest stride. + // + // We name our variables by their Tensorflow convention, but generate C code + // nesting loops such that the innermost loop has the smallest stride for the + // best cache behavior. + auto sub_func = [&](int indexes[N]) { + const int32_t input1_val = input1_data[SubscriptToIndex(desc1, indexes)]; + const int32_t input2_val = input2_data[SubscriptToIndex(desc2, indexes)]; + const int32_t scaled_input1_val = + gemmlowp::RoundingDivideByPOT(input1_val, -params.input1_shift); + const int32_t scaled_input2_val = + gemmlowp::RoundingDivideByPOT(input2_val, -params.input2_shift); + const int32_t raw_output = scaled_input1_val - scaled_input2_val; + const int32_t clamped_output = + std::min(params.quantized_activation_max, + std::max(params.quantized_activation_min, raw_output)); + output_data[SubscriptToIndex(output_desc, indexes)] = + static_cast(clamped_output); + }; + NDOpsHelper(output_desc, sub_func); +} + +// Element-wise Sub that can often be used for inner loop of broadcast sub as +// well as the non-broadcast sub. +inline void SubElementwise(int size, const ArithmeticParams ¶ms, + const uint8_t *input1_data, + const uint8_t *input2_data, uint8_t *output_data) +{ + TFLITE_DCHECK_GT(params.input1_offset, -256); + TFLITE_DCHECK_GT(params.input2_offset, -256); + TFLITE_DCHECK_LT(params.input1_offset, 256); + TFLITE_DCHECK_LT(params.input2_offset, 256); + + for (int i = 0; i < size; ++i) { + const int32_t input1_val = params.input1_offset + input1_data[i]; + const int32_t input2_val = params.input2_offset + input2_data[i]; + const int32_t shifted_input1_val = input1_val * (1 << params.left_shift); + const int32_t shifted_input2_val = input2_val * (1 << params.left_shift); + const int32_t scaled_input1_val = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + shifted_input1_val, params.input1_multiplier, params.input1_shift); + const int32_t scaled_input2_val = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + shifted_input2_val, params.input2_multiplier, params.input2_shift); + const int32_t raw_sub = scaled_input1_val - scaled_input2_val; + const int32_t raw_output = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + raw_sub, params.output_multiplier, params.output_shift) + + params.output_offset; + const int32_t clamped_output = + std::min(params.quantized_activation_max, + std::max(params.quantized_activation_min, raw_output)); + output_data[i] = static_cast(clamped_output); + } +} + +// Element-wise add that can often be used for inner loop of broadcast add as +// well as the non-broadcast add. +inline void SubElementwise(int size, const ArithmeticParams ¶ms, + const int8_t *input1_data, const int8_t *input2_data, + int8_t *output_data) +{ + const int32_t int8_max_value = std::numeric_limits::max(); + TFLITE_DCHECK_GE(params.input1_offset, -1 * int8_max_value); + TFLITE_DCHECK_GE(params.input2_offset, -1 * int8_max_value); + TFLITE_DCHECK_LE(params.input1_offset, int8_max_value); + TFLITE_DCHECK_LE(params.input2_offset, int8_max_value); + + for (int i = 0; i < size; ++i) { + const int32_t input1_val = params.input1_offset + input1_data[i]; + const int32_t input2_val = params.input2_offset + input2_data[i]; + const int32_t shifted_input1_val = input1_val * (1 << params.left_shift); + const int32_t shifted_input2_val = input2_val * (1 << params.left_shift); + const int32_t scaled_input1_val = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + shifted_input1_val, params.input1_multiplier, params.input1_shift); + const int32_t scaled_input2_val = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + shifted_input2_val, params.input2_multiplier, params.input2_shift); + const int32_t raw_sub = scaled_input1_val - scaled_input2_val; + const int32_t raw_output = + MultiplyByQuantizedMultiplierSmallerThanOneExp( + raw_sub, params.output_multiplier, params.output_shift) + + params.output_offset; + const int32_t clamped_output = + std::min(params.quantized_activation_max, + std::max(params.quantized_activation_min, raw_output)); + output_data[i] = static_cast(clamped_output); + } +} + +inline void Sub(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, const uint8_t *input1_data, + const RuntimeShape &input2_shape, const uint8_t *input2_data, + const RuntimeShape &output_shape, uint8_t *output_data) +{ + TFLITE_DCHECK_LE(params.quantized_activation_min, + params.quantized_activation_max); + const int flat_size = + MatchingElementsSize(input1_shape, input2_shape, output_shape); + + TFLITE_DCHECK_GT(params.input1_offset, -256); + TFLITE_DCHECK_GT(params.input2_offset, -256); + TFLITE_DCHECK_LT(params.input1_offset, 256); + TFLITE_DCHECK_LT(params.input2_offset, 256); + SubElementwise(flat_size, params, input1_data, input2_data, output_data); +} + +inline void Sub(const ArithmeticParams ¶ms, + const RuntimeShape &input1_shape, const int8_t *input1_data, + const RuntimeShape &input2_shape, const int8_t *input2_data, + const RuntimeShape &output_shape, int8_t *output_data) +{ + TFLITE_DCHECK_LE(params.quantized_activation_min, + params.quantized_activation_max); + + const int flat_size = + MatchingElementsSize(input1_shape, input2_shape, output_shape); + + const int32_t int8_max_value = std::numeric_limits::max(); + TFLITE_DCHECK_GE(params.input1_offset, -1 * int8_max_value); + TFLITE_DCHECK_GE(params.input2_offset, -1 * int8_max_value); + TFLITE_DCHECK_LE(params.input1_offset, int8_max_value); + TFLITE_DCHECK_LE(params.input2_offset, int8_max_value); + SubElementwise(flat_size, params, input1_data, input2_data, output_data); +} + +template +void Sub(const ArithmeticParams ¶ms, const RuntimeShape &input1_shape, + const T *input1_data, const RuntimeShape &input2_shape, + const T *input2_data, const RuntimeShape &output_shape, + T *output_data) +{ + NdArrayDesc<4> desc1; + NdArrayDesc<4> desc2; + NdArrayDescsForElementwiseBroadcast(input1_shape, input2_shape, &desc1, + &desc2); + const RuntimeShape extended_output_shape = + RuntimeShape::ExtendedShape(4, output_shape); + + // In Tensorflow, the dimensions are canonically named (batch_number, row, + // col, channel), with extents (batches, height, width, depth), with the + // trailing dimension changing most rapidly (channels has the smallest stride, + // typically 1 element). + // + // In generated C code, we store arrays with the dimensions reversed. The + // first dimension has smallest stride. + // + // We name our variables by their Tensorflow convention, but generate C code + // nesting loops such that the innermost loop has the smallest stride for the + // best cache behavior. + for (int b = 0; b < extended_output_shape.Dims(0); ++b) { + for (int y = 0; y < extended_output_shape.Dims(1); ++y) { + for (int x = 0; x < extended_output_shape.Dims(2); ++x) { + for (int c = 0; c < extended_output_shape.Dims(3); ++c) { + output_data[Offset(extended_output_shape, b, y, x, c)] = + input1_data[SubscriptToIndex(desc1, b, y, x, c)] - + input2_data[SubscriptToIndex(desc2, b, y, x, c)]; + } + } + } + } +} + +inline void SetActivationMinMax(const ArithmeticParams ¶ms, + int32_t *activation_min, + int32_t *activation_max) +{ + *activation_min = params.quantized_activation_min; + *activation_max = params.quantized_activation_max; +} + +inline void SetActivationMinMax(const ArithmeticParams ¶ms, + float *activation_min, float *activation_max) +{ + *activation_min = params.float_activation_min; + *activation_max = params.float_activation_max; +} + +inline void SetActivationMinMax(const ArithmeticParams ¶ms, + int64_t *activation_min, + int64_t *activation_max) +{ + *activation_min = params.int64_activation_min; + *activation_max = params.int64_activation_max; +} + +template +inline void SubWithActivation( + const ArithmeticParams ¶ms, const RuntimeShape &input1_shape, + const T *input1_data, const RuntimeShape &input2_shape, + const T *input2_data, const RuntimeShape &output_shape, T *output_data) +{ + ruy::profiler::ScopeLabel label("SubWithActivation"); + const int flat_size = + MatchingElementsSize(input1_shape, input2_shape, output_shape); + T activation_min, activation_max; + SetActivationMinMax(params, &activation_min, &activation_max); + + for (int i = 0; i < flat_size; ++i) { + output_data[i] = ActivationFunctionWithMinMax( + input1_data[i] - input2_data[i], activation_min, activation_max); + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_SUB_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/tanh.h b/components/tflite/tensorflow/lite/kernels/internal/reference/tanh.h new file mode 100644 index 00000000..bfdd9125 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/tanh.h @@ -0,0 +1,132 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_TANH_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_TANH_H_ + +#include + +#include "fixedpoint/fixedpoint.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/cppmath.h" +#include "tensorflow/lite/kernels/internal/types.h" +#include "tensorflow/lite/kernels/op_macros.h" + +namespace tflite { +namespace reference_ops { +inline void Tanh(const RuntimeShape &input_shape, const float *input_data, + const RuntimeShape &output_shape, float *output_data) +{ + const int flat_size = MatchingFlatSize(input_shape, output_shape); + + for (int i = 0; i < flat_size; i++) { + float val = input_data[i]; + float result = std::tanh(val); + output_data[i] = result; + } +} + +// Convenience version that allows, for example, generated-code calls to be +// uniform between data types. +inline void Tanh(const TanhParams &, const RuntimeShape &input_shape, + const float *input_data, const RuntimeShape &output_shape, + float *output_data) +{ + // Drop params: not needed. + Tanh(input_shape, input_data, output_shape, output_data); +} + +inline void Tanh(const TanhParams ¶ms, const RuntimeShape &input_shape, + const int16_t *input_data, const RuntimeShape &output_shape, + int16_t *output_data) +{ + const int input_left_shift = params.input_left_shift; + // Support for shifts is limited until we have a parameterized version of + // SaturatingRoundingMultiplyByPOT(). + TFLITE_DCHECK_GE(input_left_shift, 0); + TFLITE_DCHECK_LE(input_left_shift, 1); + + const int flat_size = MatchingFlatSize(input_shape, output_shape); + + // F0 uses 0 integer bits, range [-1, 1]. + // This is the return type of math functions such as tanh, logistic, + // whose range is in [-1, 1]. + using F0 = gemmlowp::FixedPoint; + // F3 uses 3 integer bits, range [-8, 8], the input range expected here. + using F3 = gemmlowp::FixedPoint; + + if (input_left_shift == 0) { + for (int i = 0; i < flat_size; i++) { + F3 input = F3::FromRaw(input_data[i]); + F0 output = gemmlowp::tanh(input); + output_data[i] = output.raw(); + } + } else { + for (int i = 0; i < flat_size; i++) { + F3 input = F3::FromRaw( + gemmlowp::SaturatingRoundingMultiplyByPOT<1>(input_data[i])); + F0 output = gemmlowp::tanh(input); + output_data[i] = output.raw(); + } + } +} + +inline void Tanh(const TanhParams ¶ms, const RuntimeShape &input_shape, + const uint8_t *input_data, const RuntimeShape &output_shape, + uint8_t *output_data) +{ + const int32_t input_zero_point = params.input_zero_point; + const int32_t input_range_radius = params.input_range_radius; + const int32_t input_multiplier = params.input_multiplier; + const int input_left_shift = params.input_left_shift; + const int32_t output_zero_point = 128; + const int flat_size = MatchingFlatSize(input_shape, output_shape); + + for (int i = 0; i < flat_size; i++) { + const uint8_t input_val_u8 = input_data[i]; + const int32_t input_val_centered = + static_cast(input_val_u8) - input_zero_point; + uint8_t output_val; + if (input_val_centered <= -input_range_radius) { + output_val = 0; + } else if (input_val_centered >= input_range_radius) { + output_val = 255; + } else { + const int32_t input_val_rescaled = + MultiplyByQuantizedMultiplierGreaterThanOne( + input_val_centered, input_multiplier, input_left_shift); + using FixedPoint4 = gemmlowp::FixedPoint; + using FixedPoint0 = gemmlowp::FixedPoint; + const FixedPoint4 input_val_f4 = FixedPoint4::FromRaw(input_val_rescaled); + const FixedPoint0 output_val_f0 = gemmlowp::tanh(input_val_f4); + // Convert from Q0.31 to Q24.7. + using gemmlowp::RoundingDivideByPOT; + int32_t output_val_s32 = RoundingDivideByPOT(output_val_f0.raw(), 24); + output_val_s32 += output_zero_point; + if (output_val_s32 == 256) { + output_val_s32 = 255; + } + // Reinterpret as Q0.7, encoded in uint8_t. + TFLITE_DCHECK_GE(output_val_s32, 0); + TFLITE_DCHECK_LE(output_val_s32, 255); + output_val = static_cast(output_val_s32); + } + output_data[i] = output_val; + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_TANH_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/transpose.h b/components/tflite/tensorflow/lite/kernels/internal/reference/transpose.h new file mode 100644 index 00000000..c04abf69 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/transpose.h @@ -0,0 +1,109 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_TRANSPOSE_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_TRANSPOSE_H_ + +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +template +void TransposeImpl(const TransposeParams ¶ms, + const RuntimeShape &unextended_input_shape, + const T *input_data, + const RuntimeShape &unextended_output_shape, + T *output_data) +{ + const int unextended_input_size = unextended_input_shape.DimensionsCount(); + const int unextended_output_size = unextended_output_shape.DimensionsCount(); + TFLITE_DCHECK_LE(unextended_input_size, N); + TFLITE_DCHECK_LE(unextended_output_size, N); + TFLITE_DCHECK_EQ(unextended_output_size, params.perm_count); + const int input_ext_size = N - unextended_input_size; + const int output_ext_size = N - unextended_output_size; + NdArrayDesc input_desc; + NdArrayDesc output_desc; + CopyDimsToDesc(RuntimeShape::ExtendedShape(N, unextended_input_shape), + &input_desc); + CopyDimsToDesc(RuntimeShape::ExtendedShape(N, unextended_output_shape), + &output_desc); + + // The perm data is extended to match the output, each index incremented by + // the amount of front padding of the input shape. + int extended_perm[N]; + for (int i = 0; i < N; ++i) { + extended_perm[i] = i < output_ext_size ? i : params.perm[i - output_ext_size] + input_ext_size; + } + + // Permutes the input shape so we don't need to permute the indexes inside + // the loop. Check to make sure output_dims is matching input_dims. + NdArrayDesc perm_input_desc; + for (int k = 0; k < N; ++k) { + TFLITE_DCHECK_EQ(input_desc.extents[extended_perm[k]], + output_desc.extents[k]); + perm_input_desc.extents[k] = input_desc.extents[extended_perm[k]]; + perm_input_desc.strides[k] = input_desc.strides[extended_perm[k]]; + } + + // Naive transpose loop (iterate on output index and compute input index). + auto tranpose_func = [&](int indexes[N]) { + output_data[SubscriptToIndex(output_desc, indexes)] = + input_data[SubscriptToIndex(perm_input_desc, indexes)]; + }; + NDOpsHelper(output_desc, tranpose_func); +} + +template +void Transpose(const TransposeParams ¶ms, + const RuntimeShape &unextended_input_shape, const T *input_data, + const RuntimeShape &unextended_output_shape, T *output_data) +{ + // Transpose kernel only does rearranging values not numeric evaluations on + // each cell. It's safe to implement per size of scalar type and this trick + // keeps the total code size in a reasonable range. + switch (sizeof(T)) { + case 1: + TransposeImpl(params, unextended_input_shape, + reinterpret_cast(input_data), + unextended_output_shape, + reinterpret_cast(output_data)); + break; + case 2: + TransposeImpl(params, unextended_input_shape, + reinterpret_cast(input_data), + unextended_output_shape, + reinterpret_cast(output_data)); + break; + + case 4: + TransposeImpl(params, unextended_input_shape, + reinterpret_cast(input_data), + unextended_output_shape, + reinterpret_cast(output_data)); + break; + case 8: + TransposeImpl(params, unextended_input_shape, + reinterpret_cast(input_data), + unextended_output_shape, + reinterpret_cast(output_data)); + break; + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_TRANSPOSE_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/reference/transpose_conv.h b/components/tflite/tensorflow/lite/kernels/internal/reference/transpose_conv.h new file mode 100644 index 00000000..76cac4cc --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/reference/transpose_conv.h @@ -0,0 +1,217 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_TRANSPOSE_CONV_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_TRANSPOSE_CONV_H_ + +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace reference_ops { +inline void TransposeConv( + const ConvParams ¶ms, const RuntimeShape &input_shape, + const float *input_data, const RuntimeShape &filter_shape, + const float *filter_data, const RuntimeShape &bias_shape, + const float *bias_data, const RuntimeShape &output_shape, + float *output_data, const RuntimeShape &im2col_shape, float *im2col_data) +{ + const int stride_width = params.stride_width; + const int stride_height = params.stride_height; + const int pad_width = params.padding_values.width; + const int pad_height = params.padding_values.height; + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + (void)im2col_data; // only used in optimized code. + (void)im2col_shape; // only used in optimized code. + + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int input_depth = MatchingDim(input_shape, 3, filter_shape, 3); + const int output_depth = MatchingDim(filter_shape, 0, output_shape, 3); + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int filter_height = filter_shape.Dims(1); + const int filter_width = filter_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + if (bias_data) { + TFLITE_DCHECK_EQ(bias_shape.FlatSize(), output_depth); + } + + // Although transpose convolution simplifies to convolution with transposed + // weights for strides of 1, non-unitary striding complicates matters. To + // keep this reference implementation as clear as possible, we use a + // "scatter" access pattern, where we loop through all the input elements, + // computing their influence on the output, rather than looping through the + // output elements in the typical "gather" access pattern of a conv. We + // therefore must initialize the output array to zero. + const int num_elements = output_shape.FlatSize(); + for (int i = 0; i < num_elements; i++) { + output_data[i] = 0.0f; + } + + // Loop through input elements one at a time. + for (int batch = 0; batch < batches; ++batch) { + for (int in_y = 0; in_y < input_height; ++in_y) { + for (int in_x = 0; in_x < input_width; ++in_x) { + for (int in_channel = 0; in_channel < input_depth; ++in_channel) { + // Loop through the output elements it will influence + const int out_x_origin = (in_x * stride_width) - pad_width; + const int out_y_origin = (in_y * stride_height) - pad_height; + for (int filter_y = 0; filter_y < filter_height; ++filter_y) { + for (int filter_x = 0; filter_x < filter_width; ++filter_x) { + for (int out_channel = 0; out_channel < output_depth; + ++out_channel) { + // Compute output element location + const int out_x = out_x_origin + filter_x; + const int out_y = out_y_origin + filter_y; + // We cannot accumulate out of bounds + if ((out_x >= 0) && (out_x < output_width) && (out_y >= 0) && + (out_y < output_height)) { + float input_value = input_data[Offset( + input_shape, batch, in_y, in_x, in_channel)]; + float filter_value = + filter_data[Offset(filter_shape, out_channel, filter_y, + filter_x, in_channel)]; + output_data[Offset(output_shape, batch, out_y, out_x, + out_channel)] += + input_value * filter_value; + } + } + } + } + } + } + } + } + if (bias_data) { + for (int batch = 0; batch < batches; ++batch) { + for (int out_y = 0; out_y < output_height; ++out_y) { + for (int out_x = 0; out_x < output_width; ++out_x) { + for (int out_channel = 0; out_channel < output_depth; ++out_channel) { + output_data[Offset(output_shape, batch, out_y, out_x, + out_channel)] += bias_data[out_channel]; + } + } + } + } + } +} + +inline void TransposeConv( + const ConvParams ¶ms, const RuntimeShape &input_shape, + const uint8_t *input_data, const RuntimeShape &filter_shape, + const uint8_t *filter_data, const RuntimeShape &bias_shape, + const int32_t *bias_data, const RuntimeShape &output_shape, + uint8_t *output_data, const RuntimeShape &im2col_shape, + uint8_t *im2col_data, int32_t *scratch_buffer) +{ + const int stride_width = params.stride_width; + const int stride_height = params.stride_height; + const int pad_width = params.padding_values.width; + const int pad_height = params.padding_values.height; + TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4); + TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4); + (void)im2col_data; // only used in optimized code. + (void)im2col_shape; // only used in optimized code. + + const int batches = MatchingDim(input_shape, 0, output_shape, 0); + const int input_depth = MatchingDim(input_shape, 3, filter_shape, 3); + const int output_depth = MatchingDim(filter_shape, 0, output_shape, 3); + const int input_height = input_shape.Dims(1); + const int input_width = input_shape.Dims(2); + const int filter_height = filter_shape.Dims(1); + const int filter_width = filter_shape.Dims(2); + const int output_height = output_shape.Dims(1); + const int output_width = output_shape.Dims(2); + const int32_t input_offset = params.input_offset; + const int32_t filter_offset = params.weights_offset; + const int32_t output_offset = params.output_offset; + const int32_t output_multiplier = params.output_multiplier; + const int output_shift = params.output_shift; + const int32_t output_activation_min = params.quantized_activation_min; + const int32_t output_activation_max = params.quantized_activation_max; + TFLITE_DCHECK_LE(output_activation_min, output_activation_max); + if (bias_data) { + TFLITE_DCHECK_EQ(bias_shape.FlatSize(), output_depth); + } + + const int num_elements = output_shape.FlatSize(); + // We need to initialize scratch_buffer to all 0s, as we apply the same + // 'scatter' based trick as in float version. + memset(scratch_buffer, 0, num_elements * sizeof(int32_t)); + + // Loop through input elements one at a time. + for (int batch = 0; batch < batches; ++batch) { + for (int in_y = 0; in_y < input_height; ++in_y) { + for (int in_x = 0; in_x < input_width; ++in_x) { + for (int in_channel = 0; in_channel < input_depth; ++in_channel) { + // Loop through the output elements it will influence. + const int out_x_origin = (in_x * stride_width) - pad_width; + const int out_y_origin = (in_y * stride_height) - pad_height; + for (int filter_y = 0; filter_y < filter_height; ++filter_y) { + for (int filter_x = 0; filter_x < filter_width; ++filter_x) { + for (int out_channel = 0; out_channel < output_depth; + ++out_channel) { + // Compute output element location. + const int out_x = out_x_origin + filter_x; + const int out_y = out_y_origin + filter_y; + // We cannot accumulate out of bounds. + if ((out_x >= 0) && (out_x < output_width) && (out_y >= 0) && + (out_y < output_height)) { + uint8_t input_value = input_data[Offset( + input_shape, batch, in_y, in_x, in_channel)]; + uint8_t filter_value = + filter_data[Offset(filter_shape, out_channel, filter_y, + filter_x, in_channel)]; + scratch_buffer[Offset(output_shape, batch, out_y, out_x, + out_channel)] += + (input_value + input_offset) * + (filter_value + filter_offset); + } + } + } + } + } + } + } + } + for (int batch = 0; batch < batches; ++batch) { + for (int out_y = 0; out_y < output_height; ++out_y) { + for (int out_x = 0; out_x < output_width; ++out_x) { + for (int out_channel = 0; out_channel < output_depth; ++out_channel) { + int32_t acc = scratch_buffer[Offset(output_shape, batch, out_y, out_x, + out_channel)]; + if (bias_data) { + acc += bias_data[out_channel]; + } + int32_t scaled_acc = MultiplyByQuantizedMultiplier( + acc, output_multiplier, output_shift); + scaled_acc += output_offset; + scaled_acc = std::max(scaled_acc, output_activation_min); + scaled_acc = std::min(scaled_acc, output_activation_max); + output_data[Offset(output_shape, batch, out_y, out_x, out_channel)] = + static_cast(scaled_acc); + } + } + } + } +} + +} // namespace reference_ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_TRANSPOSE_CONV_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/strided_slice_logic.h b/components/tflite/tensorflow/lite/kernels/internal/strided_slice_logic.h new file mode 100644 index 00000000..c72bcdb3 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/strided_slice_logic.h @@ -0,0 +1,218 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_STRIDED_SLICE_LOGIC_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_STRIDED_SLICE_LOGIC_H_ + +#include +#include + +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace strided_slice { +// Use until std::clamp() is available from C++17. +inline int Clamp(const int v, const int lo, const int hi) +{ + TFLITE_DCHECK(!(hi < lo)); + if (hi < v) + return hi; + if (v < lo) + return lo; + return v; +} + +inline void StridedSlicePadIndices(tflite::StridedSliceParams *p, + int dim_count) +{ + // Add indices and mask bits to fully include extra dimensions + TFLITE_CHECK_LE(dim_count, 5); + TFLITE_CHECK_GE(dim_count, p->start_indices_count); + TFLITE_CHECK_EQ(p->start_indices_count, p->stop_indices_count); + TFLITE_CHECK_EQ(p->stop_indices_count, p->strides_count); + + const int pad_count = dim_count - p->start_indices_count; + + // Pad indices at start, so move arrays by pad_count. + for (int i = p->start_indices_count - 1; i >= 0; --i) { + p->strides[i + pad_count] = p->strides[i]; + p->start_indices[i + pad_count] = p->start_indices[i]; + p->stop_indices[i + pad_count] = p->stop_indices[i]; + } + for (int i = 0; i < pad_count; ++i) { + p->start_indices[i] = 0; + p->stop_indices[i] = 1; + p->strides[i] = 1; + } + + // Pad masks with 0s or 1s as required. + p->shrink_axis_mask <<= pad_count; + p->ellipsis_mask <<= pad_count; + p->new_axis_mask <<= pad_count; + p->begin_mask <<= pad_count; + p->end_mask <<= pad_count; + p->begin_mask |= (1 << pad_count) - 1; + p->end_mask |= (1 << pad_count) - 1; + + p->start_indices_count = dim_count; + p->stop_indices_count = dim_count; + p->strides_count = dim_count; +} + +// Return the index for the first element along that axis. This index will be a +// positive integer between [0, axis_size] (or [-1, axis_size -1] if stride < 0) +// that can be used to index directly into the data. +inline int StartForAxis(const tflite::StridedSliceParams ¶ms, + const RuntimeShape &input_shape, int axis) +{ + const auto begin_mask = params.begin_mask; + const auto *start_indices = params.start_indices; + const auto *strides = params.strides; + const int axis_size = input_shape.Dims(axis); + if (axis_size == 0) { + return 0; + } + // Begin with the specified index. + int start = start_indices[axis]; + + // begin_mask override + if (begin_mask & 1 << axis) { + if (strides[axis] > 0) { + // Forward iteration - use the first element. These values will get + // clamped below (Note: We could have set them to 0 and axis_size-1, but + // use lowest() and max() to maintain symmetry with StopForAxis()) + start = std::numeric_limits::lowest(); + } else { + // Backward iteration - use the last element. + start = std::numeric_limits::max(); + } + } + + // Handle negative indices + if (start < 0) { + start += axis_size; + } + + // Clamping + if (strides[axis] > 0) { + // Forward iteration + start = Clamp(start, 0, axis_size); + } else { + // Backward iteration + start = Clamp(start, -1, axis_size - 1); + } + + return start; +} + +// Return the "real" index for the end of iteration along that axis. This is an +// "end" in the traditional C sense, in that it points to one past the last +// element. ie. So if you were iterating through all elements of a 1D array of +// size 4, this function would return 4 as the stop, because it is one past the +// "real" indices of 0, 1, 2 & 3. +inline int StopForAxis(const tflite::StridedSliceParams ¶ms, + const RuntimeShape &input_shape, int axis, + int start_for_axis) +{ + const auto end_mask = params.end_mask; + const auto shrink_axis_mask = params.shrink_axis_mask; + const auto *stop_indices = params.stop_indices; + const auto *strides = params.strides; + const int axis_size = input_shape.Dims(axis); + if (axis_size == 0) { + return 0; + } + + // Begin with the specified index + const bool shrink_axis = shrink_axis_mask & (1 << axis); + int stop = stop_indices[axis]; + + // When shrinking an axis, the end position does not matter (and can be + // incorrect when negative indexing is used, see Issue #19260). Always use + // start_for_axis + 1 to generate a length 1 slice, since start_for_axis has + // already been adjusted for negative indices. + if (shrink_axis) { + return start_for_axis + 1; + } + + // end_mask override + if (end_mask & (1 << axis)) { + if (strides[axis] > 0) { + // Forward iteration - use the last element. These values will get + // clamped below + stop = std::numeric_limits::max(); + } else { + // Backward iteration - use the first element. + stop = std::numeric_limits::lowest(); + } + } + + // Handle negative indices + if (stop < 0) { + stop += axis_size; + } + + // Clamping + // Because the end index points one past the last element, we need slightly + // different clamping ranges depending on the direction. + if (strides[axis] > 0) { + // Forward iteration + stop = Clamp(stop, 0, axis_size); + } else { + // Backward iteration + stop = Clamp(stop, -1, axis_size - 1); + } + + return stop; +} + +inline bool LoopCondition(int index, int stop, int stride) +{ + // True when we have reached the end of an axis and should loop. + return stride > 0 ? index >= stop : index <= stop; +} + +inline tflite::StridedSliceParams BuildStridedSliceParams( + int begin_mask, int end_mask, int shrink_axis_mask, + const std::vector &start_indices, const std::vector &stop_indices, + const std::vector &strides) +{ + tflite::StridedSliceParams op_params; + const int dims_count = start_indices.size(); + + op_params.start_indices_count = dims_count; + op_params.stop_indices_count = dims_count; + op_params.strides_count = dims_count; + for (int i = 0; i < dims_count; ++i) { + op_params.start_indices[i] = start_indices[i]; + op_params.stop_indices[i] = stop_indices[i]; + op_params.strides[i] = strides[i]; + } + + op_params.begin_mask = begin_mask; + op_params.ellipsis_mask = 0; + op_params.end_mask = end_mask; + op_params.new_axis_mask = 0; + op_params.shrink_axis_mask = shrink_axis_mask; + + return op_params; +} + +} // namespace strided_slice + +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_STRIDED_SLICE_LOGIC_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/tensor_ctypes.h b/components/tflite/tensorflow/lite/kernels/internal/tensor_ctypes.h new file mode 100644 index 00000000..97536730 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/tensor_ctypes.h @@ -0,0 +1,48 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_TENSOR_CTYPES_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_TENSOR_CTYPES_H_ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +template +inline T *GetTensorData(TfLiteTensor *tensor) +{ + return tensor != nullptr ? reinterpret_cast(tensor->data.raw) : nullptr; +} + +template +inline const T *GetTensorData(const TfLiteTensor *tensor) +{ + return tensor != nullptr ? reinterpret_cast(tensor->data.raw) : nullptr; +} + +inline RuntimeShape GetTensorShape(const TfLiteTensor *tensor) +{ + if (tensor == nullptr) { + return RuntimeShape(); + } + + TfLiteIntArray *dims = tensor->dims; + const int dims_size = dims->size; + const int32_t *dims_data = reinterpret_cast(dims->data); + return RuntimeShape(dims_size, dims_data); +} + +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_TENSOR_CTYPES_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/tensor_utils_common.h b/components/tflite/tensorflow/lite/kernels/internal/tensor_utils_common.h new file mode 100644 index 00000000..e6fe0f4e --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/tensor_utils_common.h @@ -0,0 +1,472 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_TENSOR_UTILS_COMMON_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_TENSOR_UTILS_COMMON_H_ + +#include +#include + +#if defined(_MSC_VER) +#define __restrict__ __restrict +#endif + +namespace tflite { +namespace tensor_utils { +// Checks if all entries of vector are zero for float. +bool IsZeroVector(const float *vector, int v_size); + +// Checks if all entries of vector are zero for int8. +bool IsZeroVector(const int8_t *vector, int v_size); + +// Quantizes a buffer of floating point values using a symmetric quantization +// (i.e. linear quantization without an offset) to 8-bit signed integers. +// It also outputs the range (min, max) of the floating point buffer, and the +// scaling factor used to quantize the values. +void SymmetricQuantizeFloats(const float *values, const int size, + int8_t *quantized_values, float *min_value, + float *max_value, float *scaling_factor); + +// Quantizes a buffer of floating point values using a symmetric quantization +// (i.e. linear quantization without an offset) to 8-bit signed integers. +// It uses the range (min, max) provided to the function to calculate the +// appropriate scaling factor to quantize the values. +void SymmetricQuantizeFloats(const float *values, const int size, + int8_t *quantized_values, float min_value, + float max_value, float *scaling_factor); + +void AsymmetricQuantizeFloats(const float *values, const int size, + int8_t *quantized_values, float *scaling_factor, + int32_t *offset); + +// Helper function to quantize floats. +// float_data_ptr input float vectors +// n_batch number of input vectors +// n_data size of a single input vector +// quantized_data_ptr (out) vector with quantized data +// scaling_factors (out) scaling factors (one per vector) +// zero_points (out) zero points (one per vector) +// do_asymmetric controls if the quantization should be asymmetric. +inline void BatchQuantizeFloats(const float *float_data_ptr, int n_batch, + int n_data, int8_t *quantized_data_ptr, + float *scaling_factors, int32_t *zero_points, + bool do_asymmetric) +{ + for (int b = 0; b < n_batch; ++b) { + const int offset = b * n_data; + if (do_asymmetric) { + tensor_utils::AsymmetricQuantizeFloats( + float_data_ptr + offset, n_data, quantized_data_ptr + offset, + &scaling_factors[b], &zero_points[b]); + } else { + float unused_min, unused_max; + tensor_utils::SymmetricQuantizeFloats( + float_data_ptr + offset, n_data, quantized_data_ptr + offset, + &unused_min, &unused_max, &scaling_factors[b]); + } + } +} + +// Multiplies a matrix by a "batched" vector (i.e. a matrix with a batch +// dimension composed by input vectors independent from each other). The result +// of the multiplication is accumulated to the passed result buffer. +// More specifically, for a matrix M of shape [n, i] and a batched-vector +// of shape [i, batch] it will first compute the product of shape [n, batch]. +// This product will be accumulated to the result buffer. +void MatrixBatchVectorMultiplyAccumulate(const float *matrix, int m_rows, + int m_cols, const float *vector, + int n_batch, float *result); + +// Same as the function above, but the matrix is a sparse tensor with block +// pattern 1x4. +// This function assumes that m_cols is a multiple of the block size (4 in this +// case) so that there's no incomplete block. +void SparseMatrixBatchVectorMultiplyAccumulate1x4( + const float *__restrict__ matrix, const int32_t *__restrict__ segments, + const int32_t *__restrict__ indices, int m_rows, int m_cols, + const float *__restrict__ vector, int n_batch, float *__restrict__ result); + +// Same as the function above, but the matrix is stored in block compressed +// sparse row format with block pattern 1x16 which consists of two arrays: +// 1. A matrix array stores non-zero blocks of the matrix in row major. +// 2. A ledger array stores nrows groups, one group per row. Each group starts +// with an integer representing the number of non-zero blocks for the +// corresponding row and follows with column indexes of the first element +// of each non-zero block. +// This function assumes that +// 1. m_cols is a multiple of 16 so that all blocks are full blocks. +// 2. m_cols < 254 * 16 so that block index can be represented by uint8. +void SparseMatrixBatchVectorMultiplyAccumulate( + const float *__restrict__ matrix, const uint8_t *__restrict__ ledger, + int m_rows, int m_cols, const float *__restrict__ vector, int n_batch, + float *__restrict__ result); + +// Same as the function above, but for values quantized using symmetric +// quantization (e.g. by calling SymmetricQuantizeFloats). +// The passed scaling factors is a buffer of the quantization scaling factors +// that will be used to dequentize the products into the final result buffer. +// These scaling factors are the multiplication of the matrix scaling factor +// by the vector's scaling factor, one per batch (i.e. this allows quantizing +// each batch in the batch-vector matrix independently). +void MatrixBatchVectorMultiplyAccumulate( + const int8_t *__restrict__ matrix, const int m_rows, const int m_cols, + const int8_t *__restrict__ vectors, + const float *__restrict__ scaling_factors, int n_batch, + float *__restrict__ result); + +// Same as the function above except that vector values +// are quantized with asymmetric quantization per-batch and the matrix +// is quantized per row. +void MatrixBatchVectorMultiplyAccumulate( + const int8_t *__restrict__ matrix, const int m_rows, const int m_cols, + const int8_t *__restrict__ vectors, + const float *__restrict__ scaling_factors, int n_batch, + float *__restrict__ result, const float *__restrict__ per_channel_scale, + const int32_t *__restrict__ input_offset); + +// Same as the function above, but the matrix is stored in block compressed +// sparse row format with block pattern 1x16 which consists of two arrays: +// 1. A matrix array stores non-zero blocks of the matrix in row major. +// 2. A ledger array stores nrows groups, one group per row. Each group starts +// with an integer representing the number of non-zero blocks for the +// corresponding row followed by column index of the first element of +// each non-zero block. +// This function assumes that +// 1. m_cols is a multiple of 16 so that all blocks are full blocks. +// 2. m_cols < 254 * 16 so that block index can be represented by uint8. +void SparseMatrixBatchVectorMultiplyAccumulate( + const int8_t *__restrict__ matrix, const uint8_t *__restrict__ ledger, + const int m_rows, const int m_cols, const int8_t *__restrict__ vectors, + const float *__restrict__ scaling_factors, int n_batch, + float *__restrict__ result); + +// Same as the above 8, 8, 8 integer matmul except for the presence of zero +// point and non-accumulative. +// TODO(b/148688698): remove this function by folding zero point calculation in +// prepare() function. +void MatrixBatchVectorMultiply(const int8_t *input, int32_t input_zeropoint, + const int8_t *input_to_gate_weights, + int32_t input_to_gate_effective_scale_a, + int32_t input_to_gate_effective_scale_b, + int32_t n_batch, int32_t n_input, int32_t n_cell, + int8_t *gate_output, int8_t gate_output_zp); + +// Same as above but has 16 bit and 8 bit input and 8 bit output. +// Used in projection when hidden is 16bit. +void MatrixBatchVectorMultiply(const int16_t *hidden, + const int8_t *hidden_to_output_weights, + int32_t proj_effective_scale_a, + int32_t proj_effective_scale_b, + const int32_t *gate_bias, int32_t n_batch, + int32_t n_hidden, int32_t n_output, + int32_t output_zp, int8_t *proj_output); + +// Multiplies a matrix with a scalar and reduce the result on each row to a +// scalar. +// Parameters: +// - matrix: matrix of size n_row * n_col +// - scalar: the scalar that is multiplied to each element in the matrix +// - n_row: the row count of the matrix +// - n_col: the column count of the matrix +// - output: the 32bit output +// Note: We do not need saturation because the int8 * int8 is safe from overflow +// in (2^31-1) / (2^14) = 131072, which is bigger than the n_row. Non-zero +// initial output value is not exceptionally large. +void MatrixScalarMultiplyAccumulate(const int8_t *matrix, int32_t scalar, + int32_t n_row, int32_t n_col, + int32_t *output); + +// Apply Layer Normalization (https://arxiv.org/abs/1607.06450) to a Quantized +// vector. +// Parameters: +// - input: batch vector of size n_batch * n_input; 16 bit. +// - layer_norm_weights: the quantized layer normalization weights. +// - bias: the bias for the layer normalization. +// - layer_norm_scale_a: multiplier for scale factor. +// - layer_norm_scale_b: shift for scale factor. +// - variance_limit: the guard to make sure the inverse does not overflow. +// - n_batch: the number of batches. +// - n_input: the size for input and output. +// - output: the 16 bit output +void ApplyLayerNorm(const int16_t *input, const int16_t *layer_norm_weights, + const int32_t *bias, int32_t layer_norm_scale_a, + int32_t layer_norm_scale_b, int32_t variance_limit, + int n_batch, int n_input, int16_t *output); + +// Same as above but the internal calculation is done in float. +void ApplyLayerNormFloat(const int16_t *input, + const int16_t *layer_norm_weights, + int32_t layer_norm_scale_a, int32_t layer_norm_scale_b, + const int32_t *bias, int n_batch, int n_input, + int16_t *output); + +// Apply Sigmoid to a quantized vector. +// Parameters: +// - input: batch vector of size n_batch * n_input; 16 bit. +// - n_batch: the number of batches. +// - n_input: the size for input and output. +// - output: the 16 bit output +// The input is in Q3.12 format and the output is in Q0.15 format. +void ApplySigmoid(const int16_t *input, int32_t n_batch, int32_t n_input, + int16_t *output); + +// Same as above but the internal calcualtion is float. +void ApplySigmoidFloat(const int16_t *input, int32_t n_batch, int32_t n_input, + int16_t *output); + +// Apply Tanh to a quantized vector. +// Parameters: +// - integer_bits: the integer bits of the input. +// Currently supports 0, 1, 2, 3, 4, 5, 6. +// - input: batch vector of size n_batch * n_input; 16 bit. +// - n_batch: the number of batches. +// - n_input: the size for input and output. +// - output: the 16 bit output +// The input is in Qm.15-m format and the output is in Q0.15 format. +void ApplyTanh(int32_t integer_bits, const int16_t *input, int32_t n_batch, + int32_t n_input, int16_t *output); + +// Apply Tanh to a quantized vector. Tbe internal calculation is in float. +// - Input has 2^(integer_bits) as scale. +// - Output has Q0.15 as scale. +void ApplyTanhFloat(const int16_t *input, int32_t n_batch, int32_t n_input, + int32_t integer_bits, int16_t *output); + +// Element-wise multiplication of two quantized vectors. +// Parameters: +// - input_1: batch vector of size n_batch * n_input; 16 bit. +// - input_2: batch vector of size n_batch * n_input; 16 bit. +// - n_batch: the number of batches. +// - n_input: the size for input and output. +// - shift: the shift needed to produce the output. +// - output: the 16 bit output of size n_batch * n_input. +// Output does not need to be initialized. +void CwiseMul(const int16_t *input_1, const int16_t *input_2, int n_batch, + int n_input, int shift, int16_t *output); + +// Element-wise multiplication of two quantized vectors. +// Parameters: +// - input_1: batch vector of size n_batch * n_input; 16 bit. +// - input_2: batch vector of size n_batch * n_input; 16 bit. +// - n_batch: the number of batches. +// - n_input: the size for input and output. +// - shift: the shift needed to produce the output. +// - output: the 8 bit output of size n_batch * n_input. +// Output does not need to be initialized. +void CwiseMul(const int16_t *input_1, const int16_t *input_2, int n_batch, + int n_input, int shift, int8_t *output); + +// Element-wise multiplication of two quantized vectors with rescaling. +// Parameters: +// - input_1: batch vector of size n_batch * n_input; 16 bit. +// - input_2: batch vector of size n_batch * n_input; 16 bit. +// - multiplier: the multiplier part of scale. +// - shift: the shift part of scale. +// - n_batch: the number of batches. +// - n_input: the size for input and output. +// - output: the 8 bit output of size n_batch * n_input. +// - output_zp: the zero point of output. +// Output does not need to be initialized. +// Multiplier ("m") and shift ("s") are connected to scale ("s") with s = m * +// 2^(s - 31). +void CwiseMul(const int16_t *input_1, const int16_t *input_2, + int32_t multiplier, int32_t shift, int32_t n_batch, + int32_t n_input, int32_t output_zp, int8_t *output); + +// Element-wise saturating addition of two quantized vectors without rescaling. +// Parameters: +// - input_1: batch vector of size n_batch * n_input; 16 bit. +// - input_2: batch vector of size n_batch * n_input; 16 bit. +// - n_batch: the number of batches. +// - n_input: the size for input and output. +// - output: the 8 bit output of size n_batch * n_input. +// Output does not need to be initialized. +void CwiseAdd(const int16_t *input_1, const int16_t *input_2, int n_batch, + int n_input, int16_t *output); + +// Element-wise in-place clipping of a vector. Overloaded for float, int16_t, +// int8_t. Parameters: +// - vector: vector of size v_size. +// - v_size: the size of the vector. +// - clipping_value: the value used for clipping. +void CwiseClipping(float *vector, const int v_size, const float clipping_value); +void CwiseClipping(int16_t *vector, const int v_size, + const int16_t clipping_value); +void CwiseClipping(int8_t *vector, const int v_size, + const int8_t clipping_value); + +// Cwise product of two vectors. +template +inline void VectorVectorCwiseProduct(const T *__restrict__ vector1, + const T *__restrict__ vector2, int v_size, + T *__restrict__ result) +{ + for (int v = 0; v < v_size; v++) { + *result++ = *vector1++ * *vector2++; + } +} + +// Cwise product and accumulate of two vectors. Since it's a MAC operation, the +// assumption here is that result array is initialized to valid values. +template +inline void VectorVectorCwiseProductAccumulate(const T *__restrict__ vector1, + const T *__restrict__ vector2, + int v_size, + T *__restrict__ result) +{ + for (int v = 0; v < v_size; v++) { + *result++ += *vector1++ * *vector2++; + } +} + +// Dot product of two vectors. +float VectorVectorDotProduct(const float *vector1, const float *vector2, + int v_size); + +// Dot product of two batch vectors of size n_batch * v_size: +// vector1 = [x_1_1, x_1_2, ..., x_1_vsize, +// x_2_1, x_2_2, ..., x_2_vsize, +// ... +// x_nbatch_1,..., x_nbatch_vsize] +// vector2 = [y_1_1, y_1_2, ..., y_1_vsize, +// y_2_1, y_2_2, ..., y_2_vsize, +// ... +// y_nbatch_1,..., y_nbatch_vsize] +// Then result will be a vector of n_batch size starting from 'result': +// [x_1_1 * y_1_1 + x_1_2 * y_1_2 + ... + x_1_vsize * y_1_vsize, +// x_2_1 * y_2_1 + x_2_2 * y_2_2 + ... + x_2_vsize * y_2_vsize, +// ... +// x_nbatch_1 * y_nbatch_1 + ... + x_nbatch_vsize * y_nbatch_vsize] +template +inline void BatchVectorBatchVectorDotProduct(const T *vector1, const T *vector2, + int v_size, int n_batch, + T *result) +{ + for (int b = 0; b < n_batch; b++) { + result[b] = VectorVectorDotProduct(vector1, vector2, v_size); + vector1 += v_size; + vector2 += v_size; + } +} + +// Same as above but input is 16bit and output is 32bit. +void BatchVectorBatchVectorDotProduct(const int16_t *vector1, + const int16_t *vector2, int v_size, + int n_batch, int32_t *result); + +// Cwise product of a vector and a batch-vector. +template +inline void VectorBatchVectorCwiseProduct(const T *vector, int v_size, + const T *batch_vector, int n_batch, + T *result) +{ + for (int b = 0; b < n_batch; b++) { + VectorVectorCwiseProduct(vector, batch_vector, v_size, result); + // Update the pointers. + result += v_size; + batch_vector += v_size; + } +} + +// Cwise product and accumulate of a vector and a batch-vector. Since it's a MAC +// operation, the assumption here is that result array is initialized to valid +// values. +template +inline void VectorBatchVectorCwiseProductAccumulate(const T *vector, int v_size, + const T *batch_vector, + int n_batch, T *result) +{ + for (int b = 0; b < n_batch; b++) { + VectorVectorCwiseProductAccumulate(vector, batch_vector, v_size, result); + // Update the pointers. + result += v_size; + batch_vector += v_size; + } +} + +// Same as above, but inputs are 16bit integer and output is 16bit integer. +void VectorBatchVectorCwiseProductAccumulate(const int16_t *vector, int v_size, + const int16_t *batch_vector, + int n_batch, int32_t multiplier, + int shift, int16_t *result); + +// Add another vector for each batch in the batch vector. +template +void VectorBatchVectorAdd(const T *vector, int v_size, int n_batch, + T *batch_vector) +{ + for (int b = 0; b < n_batch; b++) { + for (int i = 0; i < v_size; ++i) { + batch_vector[i] += vector[i]; + } + batch_vector += v_size; + } +} + +// Batch vector initialization with another vector. +template +void VectorBatchVectorAssign(const T *vector, int v_size, int n_batch, + T *batch_vector) +{ + for (int b = 0; b < n_batch; b++) { + std::copy_n(vector, v_size, batch_vector + b * v_size); + } +} + +// Compute "1.0f - elements of vector" (used in CIFG). +void Sub1Vector(const float *vector, int v_size, float *result); + +// Compute "1.0f - elements of vector" (used in CIFG) for int16 input. +// "vector" has range [0, 32767] because it is the output of sigmoid function. +void Sub1Vector(const int16_t *vector, int v_size, int16_t *result); + +// Multiply all elements of vector with a scalar. +void VectorScalarMultiply(const int8_t *vector, int v_size, float scale, + float *result); + +// Reduce-sum on a float input vector: +// input_vector: float pointer to input vector. +// output_vector: float pointer to vector. +// output_size: output vector size. +// reduction_size: number of consecutive elements from input vector which are +// added to get one element of output. +void ReductionSumVector(const float *input_vector, float *output_vector, + int output_size, int reduction_size); + +// Same as above but input/output is 32 bit integer. +void ReductionSumVector(const int32_t *input_vector, int32_t *output_vector, + int output_size, int reduction_size); + +// Same as above but input is 8 bit integer. +void ReductionSumVector(const int8_t *input_vector, int32_t *output_vector, + int output_size, int reduction_size); + +// Layer norm for each batch. +void MeanStddevNormalization(const float *__restrict__ input_vector, + float *__restrict__ output_vector, int v_size, + int n_batch); + +// Saturate Add with rescale on both inputs. +void TwoGateSaturatingAdd(const int8_t *input, int8_t input_zp, + const int8_t *recurrent, int8_t recurrent_zp, + int32_t input_effective_scale_a, + int32_t input_effective_scale_b, + int32_t recurrent_effective_scale_a, + int32_t recurrent_effective_scale_b, int32_t n_batch, + int32_t n_cell, int16_t *output); + +} // namespace tensor_utils +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_TENSOR_UTILS_COMMON_H_ diff --git a/components/tflite/tensorflow/lite/kernels/internal/types.h b/components/tflite/tensorflow/lite/kernels/internal/types.h new file mode 100644 index 00000000..8dc26d8a --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/internal/types.h @@ -0,0 +1,1303 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_TYPES_H_ +#define TENSORFLOW_LITE_KERNELS_INTERNAL_TYPES_H_ + +#include +#include +#include +#include + +#include "tensorflow/lite/kernels/internal/compatibility.h" + +namespace tflite { +enum class FusedActivationFunctionType : uint8_t { + kNone, + kRelu6, + kRelu1, + kRelu +}; +enum class PaddingType : uint8_t { kNone, + kSame, + kValid }; + +struct PaddingValues { + int16_t width; + int16_t height; + // offset is used for calculating "remaining" padding, for example, `width` + // is 1 and `width_offset` is 1, so padding_left is 1 while padding_right is + // 1 + 1 = 2. + int16_t width_offset; + // Same as width_offset except it's over the height dimension. + int16_t height_offset; +}; + +struct Padding3DValues { + int16_t width; + int16_t height; + int16_t depth; + // offset is used for calculating "remaining" padding, for example, `width` + // is 1 and `width_offset` is 1, so padding_left is 1 while padding_right is + // 1 + 1 = 2. + int16_t width_offset; + // Same as width_offset except it's over the height dimension. + int16_t height_offset; + // Same as width_offset except it's over the depth dimension. + int16_t depth_offset; +}; + +// This enumeration allows for non-default formats for the weights array +// of a fully-connected operator, allowing the use of special optimized +// runtime paths. +enum class FullyConnectedWeightsFormat : uint8_t { + // Default format (flat 2D layout, the inner contiguous dimension + // is input_depth, the outer non-contiguous dimension is output_depth) + kDefault, + // Summary: optimized layout for fast CPU runtime implementation, + // aimed specifically at ARM CPUs at the moment, and specialized for + // 8-bit quantized layers. + // + // The use case we're concerned with here is: 8-bit quantization, + // large weights matrix that doesn't fit in cache (e.g. 4096x2048 in + // a key application that drove this), very small batch size (e.g. 1 -- 4). + // + // Even with 8-bit quantization of weights, the performance of memory + // accesses to the weights can become the dominant issue when + // the batch size is small, so each weight value is used in only a few + // arithmetic ops, i.e. the fully-connected node has a low arithmetic + // intensity. The specific issues that arise are of three kinds: + // (1) One may, ideally, max out DRAM bandwidth, i.e. be truly memory + // bound. That's the "good" issue to run into. + // (2) One may run into sub-optimal pre-fetching: the data hasn't been + // prefetched into the cache by the time we need it. + // (3) One may run into cache aliasing: multiple values that are + // pre-fetched, alias each other in the L1 cache (which typically + // has only 4-way set associativity in ARM CPUs) and thus evict + // each other before we get to using them. + // + // The point of this shuffling is to avoid issues (2) and (3) so that + // we get as fast as possible given only the hard constraint (1). + // This is achieved by turning the difficulty into a solution: the + // difficulty, that each value loaded from memory is used only in + // one kernel iteration, making this operation memory-intensive, hints at + // the solution, of shuffling the weights so that they are stored in the + // exact order as the kernel needs to load them, so that the memory + // accesses made by the kernel are trivial. This solves (2) because the + // trivial memory access pattern allows the CPU's automatic prefetching + // to perform very well (no need even for preload instructions), and this + // solves (3) because the values being loaded concurrently are now + // contiguous in the address space, thus don't alias each other in the cache. + // + // On ARM, we typically want our kernel to process a 4x16 block of weights + // at a time, because: + // - 16 is the number of bytes in a NEON register. + // - 4 is how many rows we need to handle concurrently in the kernel in + // order to have sufficient mutual independence of instructions to + // maximize arithmetic throughput. + // + // Finally, the 'Int8' part in the name refers to the fact that this + // weights format has each weights value encoded as a signed int8_t value, + // even if the data type of the weights buffer is uint8_t. This is intended + // to save runtime kernels the effort to have to XOR the top bit of these + // bytes before using them in signed arithmetic, see this file for more + // explanations on the 'signed int8_t trick' in matrix multiplication kernels: + // + // tensorflow/lite/toco/graph_transformations/ensure_uint8_weights_safe_for_fast_int8_kernels.cc + // + kShuffled4x16Int8, +}; + +// Quantization parameters, determining the mapping of quantized values +// to real values (i.e. determining how quantized values are mathematically +// interpreted). +// +// The correspondence is as follows: +// +// real_value = scale * (quantized_value - zero_point); +// +// In other words, zero_point designates which quantized value corresponds to +// the real 0 value, and scale designates the difference between the real values +// corresponding to consecutive quantized values differing by 1. +struct QuantizationParams { + int32_t zero_point = 0; + double scale = 0.0; +}; + +inline bool operator==(const QuantizationParams &qp1, + const QuantizationParams &qp2) +{ + return qp1.zero_point == qp2.zero_point && qp1.scale == qp2.scale; +} + +template +struct Dims { + int sizes[N]; + int strides[N]; +}; + +class RuntimeShape { +public: + // Shapes with dimensions up to 5 are stored directly in the structure, while + // larger shapes are separately allocated. + static constexpr int kMaxSmallSize = 5; + + RuntimeShape &operator=(RuntimeShape const &) = delete; + + RuntimeShape() + : size_(0) + { + } + + explicit RuntimeShape(int dimensions_count) + : size_(dimensions_count) + { + if (dimensions_count > kMaxSmallSize) { +#ifdef TF_LITE_STATIC_MEMORY + TFLITE_CHECK(false && "No shape resizing supported on this platform"); +#else // TF_LITE_STATIC_MEMORY + dims_pointer_ = new int32_t[dimensions_count]; +#endif // TF_LITE_STATIC_MEMORY + } + } + + RuntimeShape(int shape_size, int32_t value) + : size_(0) + { + Resize(shape_size); + for (int i = 0; i < shape_size; ++i) { + SetDim(i, value); + } + } + + RuntimeShape(int dimensions_count, const int32_t *dims_data) + : size_(0) + { + ReplaceWith(dimensions_count, dims_data); + } + + RuntimeShape(const std::initializer_list init_list) + : size_(0) + { + BuildFrom(init_list); + } + + // Avoid using this constructor. We should be able to delete it when C++17 + // rolls out. + RuntimeShape(RuntimeShape const &other) + : size_(other.DimensionsCount()) + { + if (size_ > kMaxSmallSize) { +#ifdef TF_LITE_STATIC_MEMORY + TFLITE_CHECK(false && "No shape resizing supported on this platform"); +#else + dims_pointer_ = new int32_t[size_]; +#endif + } + std::memcpy(DimsData(), other.DimsData(), sizeof(int32_t) * size_); + } + + bool operator==(const RuntimeShape &comp) const + { + return this->size_ == comp.size_ && + std::memcmp(DimsData(), comp.DimsData(), size_ * sizeof(int32_t)) == + 0; + } + + ~RuntimeShape() + { + if (size_ > kMaxSmallSize) { +#ifdef TF_LITE_STATIC_MEMORY + TFLITE_CHECK(false && "No shape resizing supported on this platform"); +#else // TF_LITE_STATIC_MEMORY + delete[] dims_pointer_; +#endif // TF_LITE_STATIC_MEMORY + } + } + + inline int32_t DimensionsCount() const + { + return size_; + } + inline int32_t Dims(int i) const + { + TFLITE_DCHECK_GE(i, 0); + TFLITE_DCHECK_LT(i, size_); + return size_ > kMaxSmallSize ? dims_pointer_[i] : dims_[i]; + } + inline void SetDim(int i, int32_t val) + { + TFLITE_DCHECK_GE(i, 0); + TFLITE_DCHECK_LT(i, size_); + if (size_ > kMaxSmallSize) { + dims_pointer_[i] = val; + } else { + dims_[i] = val; + } + } + + inline int32_t *DimsData() + { + return size_ > kMaxSmallSize ? dims_pointer_ : dims_; + } + inline const int32_t *DimsData() const + { + return size_ > kMaxSmallSize ? dims_pointer_ : dims_; + } + // The caller must ensure that the shape is no bigger than 5-D. + inline const int32_t *DimsDataUpTo5D() const + { + return dims_; + } + + inline void Resize(int dimensions_count) + { + if (size_ > kMaxSmallSize) { +#ifdef TF_LITE_STATIC_MEMORY + TFLITE_CHECK(false && "No shape resizing supported on this platform"); +#else // TF_LITE_STATIC_MEMORY + delete[] dims_pointer_; +#endif // TF_LITE_STATIC_MEMORY + } + size_ = dimensions_count; + if (dimensions_count > kMaxSmallSize) { +#ifdef TF_LITE_STATIC_MEMORY + TFLITE_CHECK(false && "No shape resizing supported on this platform"); +#else // TF_LITE_STATIC_MEMORY + dims_pointer_ = new int32_t[dimensions_count]; +#endif // TF_LITE_STATIC_MEMORY + } + } + + inline void ReplaceWith(int dimensions_count, const int32_t *dims_data) + { + Resize(dimensions_count); + int32_t *dst_dims = DimsData(); + std::memcpy(dst_dims, dims_data, dimensions_count * sizeof(int32_t)); + } + + template + inline void BuildFrom(const T &src_iterable) + { + const int dimensions_count = + std::distance(src_iterable.begin(), src_iterable.end()); + Resize(dimensions_count); + int32_t *data = DimsData(); + for (auto it : src_iterable) { + *data = it; + ++data; + } + } + + // This will probably be factored out. Old code made substantial use of 4-D + // shapes, and so this function is used to extend smaller shapes. Note that + // (a) as Dims<4>-dependent code is eliminated, the reliance on this should be + // reduced, and (b) some kernels are stricly 4-D, but then the shapes of their + // inputs should already be 4-D, so this function should not be needed. + inline static RuntimeShape ExtendedShape(int new_shape_size, + const RuntimeShape &shape) + { + return RuntimeShape(new_shape_size, shape, 1); + } + + inline void BuildFrom(const std::initializer_list init_list) + { + BuildFrom >(init_list); + } + + // Returns the total count of elements, that is the size when flattened into a + // vector. + inline int FlatSize() const + { + int buffer_size = 1; + const int *dims_data = reinterpret_cast(DimsData()); + for (int i = 0; i < size_; i++) { + buffer_size *= dims_data[i]; + } + return buffer_size; + } + + bool operator!=(const RuntimeShape &comp) const + { + return !((*this) == comp); + } + +private: + // For use only by ExtendedShape(), written to guarantee (return-value) copy + // elision in C++17. + // This creates a shape padded to the desired size with the specified value. + RuntimeShape(int new_shape_size, const RuntimeShape &shape, int pad_value) + : size_(0) + { + // If the following check fails, it is likely because a 4D-only kernel is + // being used with an array of larger dimension count. + TFLITE_CHECK_GE(new_shape_size, shape.DimensionsCount()); + Resize(new_shape_size); + const int size_increase = new_shape_size - shape.DimensionsCount(); + for (int i = 0; i < size_increase; ++i) { + SetDim(i, pad_value); + } + std::memcpy(DimsData() + size_increase, shape.DimsData(), + sizeof(int32_t) * shape.DimensionsCount()); + } + + int32_t size_; + union { + int32_t dims_[kMaxSmallSize]; + int32_t *dims_pointer_; + }; +}; + +// Converts inference-style shape to legacy tflite::Dims<4>. +inline tflite::Dims<4> ToRuntimeDims(const tflite::RuntimeShape &array_shape) +{ + tflite::Dims<4> result; + const int dimensions_count = array_shape.DimensionsCount(); + TFLITE_CHECK_LE(dimensions_count, 4); + int cum_prod = 1; + for (int i = 0; i < 4; i++) { + const int new_dim = + (i < dimensions_count) ? array_shape.Dims(dimensions_count - 1 - i) : 1; + result.sizes[i] = new_dim; + result.strides[i] = cum_prod; + cum_prod *= new_dim; + } + return result; +} + +// TODO(b/80418076): Move to legacy ops file, update invocations. +inline RuntimeShape DimsToShape(const tflite::Dims<4> &dims) +{ + return RuntimeShape( + { dims.sizes[3], dims.sizes[2], dims.sizes[1], dims.sizes[0] }); +} + +// Gets next index to iterate through a multidimensional array. +inline bool NextIndex(const int num_dims, const int *dims, int *current) +{ + if (num_dims == 0) { + return false; + } + TFLITE_DCHECK(dims != nullptr); + TFLITE_DCHECK(current != nullptr); + int carry = 1; + for (int idx = num_dims - 1; idx >= 0; --idx) { + int current_val = current[idx] + carry; + TFLITE_DCHECK_GE(dims[idx], current_val); + if (dims[idx] == current_val) { + current[idx] = 0; + } else { + current[idx] = current_val; + carry = 0; + break; + } + } + return (carry == 0); +} + +// Gets offset of index if reducing on axis. When reducing, the flattened offset +// will not change, if the input index changes on the given axis. For example, +// if you have a 3D tensor and you are reducing to 2D by eliminating axis 0, +// then index (0, 1, 2) and index (1, 1, 2) will map to the same flattened +// offset. +// TODO(kanlig): uses Dims to represent dimensions. +inline size_t ReducedOutputOffset(const int num_dims, const int *dims, + const int *index, const int num_axis, + const int *axis) +{ + if (num_dims == 0) { + return 0; + } + TFLITE_DCHECK(dims != nullptr); + TFLITE_DCHECK(index != nullptr); + size_t offset = 0; + for (int idx = 0; idx < num_dims; ++idx) { + // if we need to skip this axis + bool is_axis = false; + if (axis != nullptr) { + for (int axis_idx = 0; axis_idx < num_axis; ++axis_idx) { + if (idx == axis[axis_idx]) { + is_axis = true; + break; + } + } + } + if (!is_axis) { + offset = offset * static_cast(dims[idx]) + + static_cast(index[idx]); + } + } + return offset; +} + +inline int Offset(const RuntimeShape &shape, int i0, int i1, int i2, int i3) +{ + TFLITE_DCHECK_EQ(shape.DimensionsCount(), 4); + const int *dims_data = reinterpret_cast(shape.DimsDataUpTo5D()); + TFLITE_DCHECK(i0 >= 0 && i0 < dims_data[0]); + TFLITE_DCHECK(i1 >= 0 && i1 < dims_data[1]); + TFLITE_DCHECK(i2 >= 0 && i2 < dims_data[2]); + TFLITE_DCHECK(i3 >= 0 && i3 < dims_data[3]); + return ((i0 * dims_data[1] + i1) * dims_data[2] + i2) * dims_data[3] + i3; +} + +inline int Offset(const RuntimeShape &shape, int i0, int i1, int i2, int i3, + int i4) +{ + TFLITE_DCHECK_EQ(shape.DimensionsCount(), 5); + const int *dims_data = reinterpret_cast(shape.DimsDataUpTo5D()); + TFLITE_DCHECK(i0 >= 0 && i0 < dims_data[0]); + TFLITE_DCHECK(i1 >= 0 && i1 < dims_data[1]); + TFLITE_DCHECK(i2 >= 0 && i2 < dims_data[2]); + TFLITE_DCHECK(i3 >= 0 && i3 < dims_data[3]); + TFLITE_DCHECK(i4 >= 0 && i4 < dims_data[4]); + return (((i0 * dims_data[1] + i1) * dims_data[2] + i2) * dims_data[3] + i3) * + dims_data[4] + + i4; +} + +inline int Offset(const Dims<4> &dims, int i0, int i1, int i2, int i3) +{ + TFLITE_DCHECK(i0 >= 0 && i0 < dims.sizes[0]); + TFLITE_DCHECK(i1 >= 0 && i1 < dims.sizes[1]); + TFLITE_DCHECK(i2 >= 0 && i2 < dims.sizes[2]); + TFLITE_DCHECK(i3 >= 0 && i3 < dims.sizes[3]); + return i0 * dims.strides[0] + i1 * dims.strides[1] + i2 * dims.strides[2] + + i3 * dims.strides[3]; +} + +inline int Offset(const Dims<4> &dims, int *index) +{ + return Offset(dims, index[0], index[1], index[2], index[3]); +} + +inline int Offset(const RuntimeShape &shape, int *index) +{ + return Offset(shape, index[0], index[1], index[2], index[3]); +} + +// Get array size, DCHECKing that the dim index is in range. +// +// Note that this will be phased out with Dims<4>, since RuntimeShape::Dims() +// already performs this check. +template +int ArraySize(const Dims &array, int index) +{ + TFLITE_DCHECK(index >= 0 && index < N); + return array.sizes[index]; +} + +// Get common array size, DCHECKing that they all agree. +template +int MatchingArraySize(const ArrayType1 &array1, int index1, + const ArrayType2 &array2, int index2) +{ + TFLITE_DCHECK_EQ(ArraySize(array1, index1), ArraySize(array2, index2)); + return ArraySize(array1, index1); +} + +template +int MatchingArraySize(const ArrayType1 &array1, int index1, + const ArrayType2 &array2, int index2, Args... args) +{ + TFLITE_DCHECK_EQ(ArraySize(array1, index1), ArraySize(array2, index2)); + return MatchingArraySize(array1, index1, args...); +} + +// Get common shape dim, DCHECKing that they all agree. +inline int MatchingDim(const RuntimeShape &shape1, int index1, + const RuntimeShape &shape2, int index2) +{ + TFLITE_DCHECK_EQ(shape1.Dims(index1), shape2.Dims(index2)); + return std::min(shape1.Dims(index1), shape2.Dims(index2)); +} + +template +int MatchingDim(const RuntimeShape &shape1, int index1, + const RuntimeShape &shape2, int index2, Args... args) +{ + TFLITE_DCHECK_EQ(shape1.Dims(index1), shape2.Dims(index2)); + return MatchingDim(shape1, index1, args...); +} + +// Will be phased out with Dims<4>, replaced by RuntimeShape::FlatSize(). +template +inline int FlatSize(const Dims &dims) +{ + int flat_size = 1; + for (int i = 0; i < N; ++i) { + flat_size *= dims.sizes[i]; + } + return flat_size; +} + +TFLITE_DEPRECATED("Prefer FlatSize.") +inline int RequiredBufferSizeForDims(const Dims<4> &dims) +{ + return FlatSize(dims); +} + +inline int MatchingElementsSize(const RuntimeShape &shape, + const RuntimeShape &check_shape_0) +{ + const int size_1 = shape.FlatSize(); + const int size_2 = check_shape_0.FlatSize(); + TFLITE_CHECK_EQ(size_1, size_2); + return size_1; +} + +inline int MatchingElementsSize(const RuntimeShape &shape, + const RuntimeShape &check_shape_0, + const RuntimeShape &check_shape_1) +{ + const int size_1 = shape.FlatSize(); + const int size_2 = check_shape_0.FlatSize(); + const int size_3 = check_shape_1.FlatSize(); + TFLITE_CHECK_EQ(size_1, size_2); + TFLITE_CHECK_EQ(size_2, size_3); + return size_1; +} + +// Flat size calculation, checking that dimensions match with one or more other +// arrays. +inline int MatchingFlatSize(const RuntimeShape &shape, + const RuntimeShape &check_shape_0) +{ + TFLITE_DCHECK_EQ(shape.DimensionsCount(), check_shape_0.DimensionsCount()); + const int dims_count = shape.DimensionsCount(); + for (int i = 0; i < dims_count; ++i) { + TFLITE_DCHECK_EQ(shape.Dims(i), check_shape_0.Dims(i)); + } + return shape.FlatSize(); +} + +inline int MatchingFlatSize(const RuntimeShape &shape, + const RuntimeShape &check_shape_0, + const RuntimeShape &check_shape_1) +{ + TFLITE_DCHECK_EQ(shape.DimensionsCount(), check_shape_0.DimensionsCount()); + const int dims_count = shape.DimensionsCount(); + for (int i = 0; i < dims_count; ++i) { + TFLITE_DCHECK_EQ(shape.Dims(i), check_shape_0.Dims(i)); + } + return MatchingFlatSize(shape, check_shape_1); +} + +inline int MatchingFlatSize(const RuntimeShape &shape, + const RuntimeShape &check_shape_0, + const RuntimeShape &check_shape_1, + const RuntimeShape &check_shape_2) +{ + TFLITE_DCHECK_EQ(shape.DimensionsCount(), check_shape_0.DimensionsCount()); + const int dims_count = shape.DimensionsCount(); + for (int i = 0; i < dims_count; ++i) { + TFLITE_DCHECK_EQ(shape.Dims(i), check_shape_0.Dims(i)); + } + return MatchingFlatSize(shape, check_shape_1, check_shape_2); +} + +inline int MatchingFlatSize(const RuntimeShape &shape, + const RuntimeShape &check_shape_0, + const RuntimeShape &check_shape_1, + const RuntimeShape &check_shape_2, + const RuntimeShape &check_shape_3) +{ + TFLITE_DCHECK_EQ(shape.DimensionsCount(), check_shape_0.DimensionsCount()); + const int dims_count = shape.DimensionsCount(); + for (int i = 0; i < dims_count; ++i) { + TFLITE_DCHECK_EQ(shape.Dims(i), check_shape_0.Dims(i)); + } + return MatchingFlatSize(shape, check_shape_1, check_shape_2, check_shape_3); +} + +// Flat size calculation, checking that dimensions match with one or more other +// arrays. +template +inline int MatchingFlatSize(const Dims &dims, const Dims &check_dims_0) +{ + for (int i = 0; i < N; ++i) { + TFLITE_DCHECK_EQ(ArraySize(dims, i), ArraySize(check_dims_0, i)); + } + return FlatSize(dims); +} + +template +inline int MatchingFlatSize(const Dims &dims, const Dims &check_dims_0, + const Dims &check_dims_1) +{ + for (int i = 0; i < N; ++i) { + TFLITE_DCHECK_EQ(ArraySize(dims, i), ArraySize(check_dims_0, i)); + } + return MatchingFlatSize(dims, check_dims_1); +} + +template +inline int MatchingFlatSize(const Dims &dims, const Dims &check_dims_0, + const Dims &check_dims_1, + const Dims &check_dims_2) +{ + for (int i = 0; i < N; ++i) { + TFLITE_DCHECK_EQ(ArraySize(dims, i), ArraySize(check_dims_0, i)); + } + return MatchingFlatSize(dims, check_dims_1, check_dims_2); +} + +template +inline int MatchingFlatSize(const Dims &dims, const Dims &check_dims_0, + const Dims &check_dims_1, + const Dims &check_dims_2, + const Dims &check_dims_3) +{ + for (int i = 0; i < N; ++i) { + TFLITE_DCHECK_EQ(ArraySize(dims, i), ArraySize(check_dims_0, i)); + } + return MatchingFlatSize(dims, check_dims_1, check_dims_2, check_dims_3); +} + +// Data is required to be contiguous, and so many operators can use either the +// full array flat size or the flat size with one dimension skipped (commonly +// the depth). +template +inline int FlatSizeSkipDim(const Dims &dims, int skip_dim) +{ + TFLITE_DCHECK(skip_dim >= 0 && skip_dim < N); + int flat_size = 1; + for (int i = 0; i < N; ++i) { + flat_size *= (i == skip_dim) ? 1 : dims.sizes[i]; + } + return flat_size; +} + +// A combination of MatchingFlatSize() and FlatSizeSkipDim(). +template +inline int MatchingFlatSizeSkipDim(const Dims &dims, int skip_dim, + const Dims &check_dims_0) +{ + for (int i = 0; i < N; ++i) { + if (i != skip_dim) { + TFLITE_DCHECK_EQ(ArraySize(dims, i), ArraySize(check_dims_0, i)); + } + } + return FlatSizeSkipDim(dims, skip_dim); +} + +template +inline int MatchingFlatSizeSkipDim(const Dims &dims, int skip_dim, + const Dims &check_dims_0, + const Dims &check_dims_1) +{ + for (int i = 0; i < N; ++i) { + if (i != skip_dim) { + TFLITE_DCHECK_EQ(ArraySize(dims, i), ArraySize(check_dims_0, i)); + } + } + return MatchingFlatSizeSkipDim(dims, skip_dim, check_dims_1); +} + +template +inline int MatchingFlatSizeSkipDim(const Dims &dims, int skip_dim, + const Dims &check_dims_0, + const Dims &check_dims_1, + const Dims &check_dims_2) +{ + for (int i = 0; i < N; ++i) { + if (i != skip_dim) { + TFLITE_DCHECK_EQ(ArraySize(dims, i), ArraySize(check_dims_0, i)); + } + } + return MatchingFlatSizeSkipDim(dims, skip_dim, check_dims_1, check_dims_2); +} + +template +inline int MatchingFlatSizeSkipDim(const Dims &dims, int skip_dim, + const Dims &check_dims_0, + const Dims &check_dims_1, + const Dims &check_dims_2, + const Dims &check_dims_3) +{ + for (int i = 0; i < N; ++i) { + if (i != skip_dim) { + TFLITE_DCHECK_EQ(ArraySize(dims, i), ArraySize(check_dims_0, i)); + } + } + return MatchingFlatSizeSkipDim(dims, skip_dim, check_dims_1, check_dims_2, + check_dims_3); +} + +// Data is required to be contiguous, and so many operators can use either the +// full array flat size or the flat size with one dimension skipped (commonly +// the depth). +inline int FlatSizeSkipDim(const RuntimeShape &shape, int skip_dim) +{ + const int dims_count = shape.DimensionsCount(); + TFLITE_DCHECK(skip_dim >= 0 && skip_dim < dims_count); + const auto *dims_data = shape.DimsData(); + int flat_size = 1; + for (int i = 0; i < dims_count; ++i) { + flat_size *= (i == skip_dim) ? 1 : dims_data[i]; + } + return flat_size; +} + +// A combination of MatchingFlatSize() and FlatSizeSkipDim(). +inline int MatchingFlatSizeSkipDim(const RuntimeShape &shape, int skip_dim, + const RuntimeShape &check_shape_0) +{ + const int dims_count = shape.DimensionsCount(); + for (int i = 0; i < dims_count; ++i) { + if (i != skip_dim) { + TFLITE_DCHECK_EQ(shape.Dims(i), check_shape_0.Dims(i)); + } + } + return FlatSizeSkipDim(shape, skip_dim); +} + +inline int MatchingFlatSizeSkipDim(const RuntimeShape &shape, int skip_dim, + const RuntimeShape &check_shape_0, + const RuntimeShape &check_shape_1) +{ + const int dims_count = shape.DimensionsCount(); + for (int i = 0; i < dims_count; ++i) { + if (i != skip_dim) { + TFLITE_DCHECK_EQ(shape.Dims(i), check_shape_0.Dims(i)); + } + } + return MatchingFlatSizeSkipDim(shape, skip_dim, check_shape_1); +} + +inline int MatchingFlatSizeSkipDim(const RuntimeShape &shape, int skip_dim, + const RuntimeShape &check_shape_0, + const RuntimeShape &check_shape_1, + const RuntimeShape &check_shape_2) +{ + const int dims_count = shape.DimensionsCount(); + for (int i = 0; i < dims_count; ++i) { + if (i != skip_dim) { + TFLITE_DCHECK_EQ(shape.Dims(i), check_shape_0.Dims(i)); + } + } + return MatchingFlatSizeSkipDim(shape, skip_dim, check_shape_1, check_shape_2); +} + +inline int MatchingFlatSizeSkipDim(const RuntimeShape &shape, int skip_dim, + const RuntimeShape &check_shape_0, + const RuntimeShape &check_shape_1, + const RuntimeShape &check_shape_2, + const RuntimeShape &check_shape_3) +{ + const int dims_count = shape.DimensionsCount(); + for (int i = 0; i < dims_count; ++i) { + if (i != skip_dim) { + TFLITE_DCHECK_EQ(shape.Dims(i), check_shape_0.Dims(i)); + } + } + return MatchingFlatSizeSkipDim(shape, skip_dim, check_shape_1, check_shape_2, + check_shape_3); +} + +template +bool IsPackedWithoutStrides(const Dims &dims) +{ + int expected_stride = 1; + for (int d = 0; d < N; d++) { + if (dims.strides[d] != expected_stride) + return false; + expected_stride *= dims.sizes[d]; + } + return true; +} + +template +void ComputeStrides(Dims *dims) +{ + dims->strides[0] = 1; + for (int d = 1; d < N; d++) { + dims->strides[d] = dims->strides[d - 1] * dims->sizes[d - 1]; + } +} + +enum class BroadcastableOpCategory : uint8_t { + kNone, + kNonBroadcast, // Matching input shapes. + kFirstInputBroadcastsFast, // Fivefold nested loops. + kSecondInputBroadcastsFast, // Fivefold nested loops. + kGenericBroadcast, // Fall-back. +}; + +struct MinMax { + float min; + float max; +}; +static_assert(sizeof(MinMax) == 8, ""); + +struct ActivationParams { + FusedActivationFunctionType activation_type; + // uint8_t, etc, activation params. + int32_t quantized_activation_min; + int32_t quantized_activation_max; +}; + +struct ReluParams : public ActivationParams { + int32_t input_offset; + int32_t output_offset; + int32_t output_multiplier; + int output_shift; +}; + +// Styles of resizing op usages. For example, kImageStyle can be used with a Pad +// op for pattern-specific optimization. +enum class ResizingCategory : uint8_t { + kNone, + kImageStyle, // 4D, operating on inner dimensions, say {0, a, b, 0}. + kGenericResize, +}; + +// For Add, Sub, Mul ops. +struct ArithmeticParams { + // Shape dependent / common to data / op types. + BroadcastableOpCategory broadcast_category; + // uint8_t inference params. + int32_t input1_offset; + int32_t input2_offset; + int32_t output_offset; + int32_t output_multiplier; + int output_shift; + // Add / Sub, not Mul, uint8_t inference params. + int left_shift; + int32_t input1_multiplier; + int input1_shift; + int32_t input2_multiplier; + int input2_shift; + + // TODO(b/158622529): Union the following activation params. + // uint8_t, etc, activation params. + int32_t quantized_activation_min; + int32_t quantized_activation_max; + // float activation params. + float float_activation_min; + float float_activation_max; + // int64_t activation params. + int64_t int64_activation_min; + int64_t int64_activation_max; + + // Processed output dimensions. + // Let input "a" be the one that broadcasts in the faster-changing dimension. + // Then, after coalescing, for shapes {a0, a1, a2, a3, a4} and + // {b0, b1, b2, b3, b4}, + // broadcast_shape[4] = b0 = a0. + // broadcast_shape[3] = b1; a1 = 1. + // broadcast_shape[2] = b2 = a2. + // broadcast_shape[1] = a3; b3 = 1. + // broadcast_shape[0] = b4 = a4. + int broadcast_shape[5]; +}; + +struct ConcatenationParams { + int8_t axis; + const int32_t *input_zeropoint; + const float *input_scale; + uint16_t inputs_count; + int32_t output_zeropoint; + float output_scale; +}; + +struct ComparisonParams { + // uint8_t inference params. + int left_shift; + int32_t input1_offset; + int32_t input1_multiplier; + int input1_shift; + int32_t input2_offset; + int32_t input2_multiplier; + int input2_shift; + // Shape dependent / common to inference types. + bool is_broadcast; +}; + +struct ConvParams { + PaddingType padding_type; + PaddingValues padding_values; + // TODO(starka): This was just "stride", so check that width+height is OK. + int16_t stride_width; + int16_t stride_height; + int16_t dilation_width_factor; + int16_t dilation_height_factor; + // uint8_t inference params. + // TODO(b/65838351): Use smaller types if appropriate. + int32_t input_offset; + int32_t weights_offset; + int32_t output_offset; + int32_t output_multiplier; + int output_shift; + // uint8_t, etc, activation params. + int32_t quantized_activation_min; + int32_t quantized_activation_max; + // float activation params. + float float_activation_min; + float float_activation_max; +}; + +struct Conv3DParams { + Padding3DValues padding_values; + int stride_width; + int stride_height; + int stride_depth; + int dilation_width; + int dilation_height; + int dilation_depth; + // float activation params. + float float_activation_min; + float float_activation_max; +}; + +typedef Conv3DParams Conv3DTransposeParams; + +struct DepthToSpaceParams { + int32_t block_size; +}; + +struct DepthwiseParams { + PaddingType padding_type; + PaddingValues padding_values; + int16_t stride_width; + int16_t stride_height; + int16_t dilation_width_factor; + int16_t dilation_height_factor; + int16_t depth_multiplier; + // uint8_t inference params. + // TODO(b/65838351): Use smaller types if appropriate. + int32_t input_offset; + int32_t weights_offset; + int32_t output_offset; + int32_t output_multiplier; + int output_shift; + // uint8_t, etc, activation params. + int32_t quantized_activation_min; + int32_t quantized_activation_max; + // float activation params. + float float_activation_min; + float float_activation_max; + const int32_t *output_multiplier_per_channel; + const int32_t *output_shift_per_channel; +}; + +struct DequantizationParams { + double scale; + int32_t zero_point; +}; + +struct PerChannelDequantizationParams { + const float *scale; + const int32_t *zero_point; + int32_t quantized_dimension; +}; + +struct FakeQuantParams { + MinMax minmax; + int32_t num_bits; +}; + +struct FullyConnectedParams { + // uint8_t inference params. + // TODO(b/65838351): Use smaller types if appropriate. + int32_t input_offset; + int32_t weights_offset; + int32_t output_offset; + int32_t output_multiplier; + int output_shift; + // uint8_t, etc, activation params. + int32_t quantized_activation_min; + int32_t quantized_activation_max; + // float activation params. + float float_activation_min; + float float_activation_max; + // Mark the operands as cacheable if they are unchanging, e.g. weights. + bool lhs_cacheable; + bool rhs_cacheable; + FullyConnectedWeightsFormat weights_format; +}; + +struct GatherParams { + int16_t axis; + int16_t batch_dims; +}; + +struct L2NormalizationParams { + // uint8_t inference params. + int32_t input_zero_point; +}; + +struct LocalResponseNormalizationParams { + int32_t range; + double bias; + double alpha; + double beta; +}; + +struct HardSwishParams { + // zero_point of the input activations. + int16_t input_zero_point; + // zero_point of the output activations. + int16_t output_zero_point; + // 16bit fixed-point component of the multiplier to apply to go from the + // "high-res input scale", which is the input scale multiplied by 2^7, to the + // "relu-ish scale", which 3.0/32768. + // See the implementation of HardSwishPrepare. + int16_t reluish_multiplier_fixedpoint_int16; + // exponent/bit-shift component of the aforementioned multiplier. + int reluish_multiplier_exponent; + // 16bit fixed-point component of the multiplier to apply to go from the + // "high-res input scale", which is the input scale multiplied by 2^7, to the + // output scale. + // See the implementation of HardSwishPrepare. + int16_t output_multiplier_fixedpoint_int16; + // exponent/bit-shift component of the aforementioned multiplier. + int output_multiplier_exponent; +}; + +struct LogisticParams { + // uint8_t inference params. + int32_t input_zero_point; + int32_t input_range_radius; + int32_t input_multiplier; + int input_left_shift; +}; + +struct LstmCellParams { + int32_t weights_zero_point; + int32_t accum_multiplier; + int accum_shift; + int state_integer_bits; +}; + +struct MeanParams { + int8_t axis_count; + int16_t axis[4]; +}; + +struct PackParams { + int8_t axis; + const int32_t *input_zeropoint; + const float *input_scale; + uint16_t inputs_count; + int32_t output_zeropoint; + float output_scale; +}; + +struct PadParams { + int8_t left_padding_count; + int32_t left_padding[5]; + int8_t right_padding_count; + int32_t right_padding[5]; + ResizingCategory resizing_category; +}; + +struct PreluParams { + int32_t input_offset; + int32_t alpha_offset; + int32_t output_offset; + int32_t output_multiplier_1; + int output_shift_1; + int32_t output_multiplier_2; + int output_shift_2; +}; + +struct PoolParams { + FusedActivationFunctionType activation; + PaddingType padding_type; + PaddingValues padding_values; + int stride_height; + int stride_width; + int filter_height; + int filter_width; + // uint8_t, etc, activation params. + int32_t quantized_activation_min; + int32_t quantized_activation_max; + // float activation params. + float float_activation_min; + float float_activation_max; +}; + +struct ReshapeParams { + int8_t shape_count; + int32_t shape[4]; +}; + +struct ResizeBilinearParams { + bool align_corners; + // half_pixel_centers assumes pixels are of half the actual dimensions, and + // yields more accurate resizes. Corresponds to the same argument for the + // original TensorFlow op in TF2.0. + bool half_pixel_centers; +}; + +struct ResizeNearestNeighborParams { + bool align_corners; + bool half_pixel_centers; +}; + +struct SliceParams { + int8_t begin_count; + int32_t begin[5]; + int8_t size_count; + int32_t size[5]; +}; + +struct SoftmaxParams { + // beta is not really used (not a Tensorflow parameter) and not implemented + // for LogSoftmax. + double beta; + // uint8_t inference params. Used even when beta defaults to 1.0. + int32_t input_multiplier; + int32_t input_left_shift; + // Reverse scaling is only used by LogSoftmax. + int32_t reverse_scaling_divisor; + int32_t reverse_scaling_right_shift; + int diff_min; + int32_t zero_point; + float scale; + float *table; + // int16 LUT for exp(x), where x uniform distributed between [-10.0 , 0.0] + int16_t *exp_lut; + // int16 LUT for 1 / (1 + x), where x uniform distributed between [0.0 , 1.0] + int16_t *one_over_one_plus_x_lut; + uint8_t *uint8_table1; + uint8_t *uint8_table2; +}; + +struct SpaceToBatchParams { + // "Zero" padding for uint8_t means padding with the output offset. + int32_t output_offset; +}; + +struct SpaceToDepthParams { + int32_t block_size; +}; + +struct SplitParams { + // Graphs that split into, say, 2000 nodes are encountered. The indices in + // OperatorEdges are of type uint16_t. + uint16_t num_split; + int16_t axis; +}; + +struct SqueezeParams { + int8_t squeeze_dims_count; + int32_t squeeze_dims[4]; +}; + +struct StridedSliceParams { + int8_t start_indices_count; + int32_t start_indices[5]; + int8_t stop_indices_count; + int32_t stop_indices[5]; + int8_t strides_count; + int32_t strides[5]; + + int16_t begin_mask; + int16_t ellipsis_mask; + int16_t end_mask; + int16_t new_axis_mask; + int16_t shrink_axis_mask; +}; + +struct TanhParams { + int32_t input_zero_point; + int32_t input_range_radius; + int32_t input_multiplier; + int input_left_shift; +}; + +struct TransposeParams { + int8_t perm_count; + int32_t perm[5]; +}; + +struct UnpackParams { + uint16_t num_split; + int16_t axis; +}; + +struct LeakyReluParams { + float alpha; + int32_t input_offset; + int32_t output_offset; + int32_t output_multiplier_alpha; + int32_t output_shift_alpha; + int32_t output_multiplier_identity; + int32_t output_shift_identity; +}; + +template +inline void SetActivationParams(float min, float max, P *params) +{ + params->float_activation_min = min; + params->float_activation_max = max; +} + +template +inline void SetActivationParams(int32_t min, int32_t max, P *params) +{ + params->quantized_activation_min = min; + params->quantized_activation_max = max; +} + +template +inline void SetActivationParams(int64_t min, int64_t max, P *params) +{ + params->int64_activation_min = min; + params->int64_activation_max = max; +} + +template +inline void GetActivationParams(const P ¶ms, int32_t *min, int32_t *max) +{ + *min = params.quantized_activation_min; + *max = params.quantized_activation_max; +} + +template +inline void GetActivationParams(const P ¶ms, float *min, float *max) +{ + *min = params.float_activation_min; + *max = params.float_activation_max; +} + +template +inline void GetActivationParams(const P ¶ms, int64_t *min, int64_t *max) +{ + *min = params.int64_activation_min; + *max = params.int64_activation_max; +} + +// Type trait to check of given type has size smaller than 4 bytes. +template +struct is_small_integer + : public std::integral_constant::value || + std::is_same::value || + std::is_same::value || + std::is_same::value> { +}; + +// Type trait to check of given type is int32 or int64. +template +struct is_int32_or_int64 + : public std::integral_constant::value || + std::is_same::value> { +}; + +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_TYPES_H_ diff --git a/components/tflite/tensorflow/lite/kernels/kernel_util.cc b/components/tflite/tensorflow/lite/kernels/kernel_util.cc new file mode 100644 index 00000000..24c5dd8e --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/kernel_util.cc @@ -0,0 +1,576 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/kernels/kernel_util.h" + +#include +#include + +#include +#include +#include +#include +#ifndef TF_LITE_STATIC_MEMORY +#include +#endif // TF_LITE_STATIC_MEMORY + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/cppmath.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" + +#if defined(__APPLE__) +#include "TargetConditionals.h" +#endif + +namespace tflite { + +namespace { + +// Assumes tensor_index is a valid index (in bounds) +inline TfLiteTensor *GetTensorAtIndex(const TfLiteContext *context, + int tensor_index) +{ + if (context->tensors != nullptr) { + return &context->tensors[tensor_index]; + } else { + return context->GetTensor(context, tensor_index); + } +} + +// Validate in a single place to reduce binary size +inline TfLiteStatus ValidateTensorIndexingSafe(const TfLiteContext *context, + int index, int max_size, + const int *tensor_indices, + int *tensor_index) +{ + if (index < 0 || index >= max_size) { + TF_LITE_KERNEL_LOG(const_cast(context), + "Invalid tensor index %d (not in [0, %d))\n", index, + max_size); + return kTfLiteError; + } + if (tensor_indices[index] == kTfLiteOptionalTensor) { + TF_LITE_KERNEL_LOG(const_cast(context), + "Tensor at index %d was optional but was expected\n", + index); + return kTfLiteError; + } + + *tensor_index = tensor_indices[index]; + return kTfLiteOk; +} + +// Same as above but returns -1 for invalid inputs instead of status + logging +// error. +inline int ValidateTensorIndexing(const TfLiteContext *context, int index, + int max_size, const int *tensor_indices) +{ + if (index >= 0 && index < max_size) { + const int tensor_index = tensor_indices[index]; + if (tensor_index != kTfLiteOptionalTensor) { + return tensor_index; + } + } + return -1; +} + +inline TfLiteTensor *GetMutableInput(const TfLiteContext *context, + const TfLiteNode *node, int index) +{ + const int tensor_index = ValidateTensorIndexing( + context, index, node->inputs->size, node->inputs->data); + if (tensor_index < 0) { + return nullptr; + } + return GetTensorAtIndex(context, tensor_index); +} + +inline TfLiteStatus GetMutableInputSafe(const TfLiteContext *context, + const TfLiteNode *node, int index, + const TfLiteTensor **tensor) +{ + int tensor_index; + TF_LITE_ENSURE_OK( + context, ValidateTensorIndexingSafe(context, index, node->inputs->size, + node->inputs->data, &tensor_index)); + *tensor = GetTensorAtIndex(context, tensor_index); + return kTfLiteOk; +} + +} // anonymous namespace. + +const TfLiteTensor *GetInput(const TfLiteContext *context, + const TfLiteNode *node, int index) +{ + return GetMutableInput(context, node, index); +} + +TfLiteStatus GetInputSafe(const TfLiteContext *context, const TfLiteNode *node, + int index, const TfLiteTensor **tensor) +{ + return GetMutableInputSafe(context, node, index, tensor); +} + +TfLiteTensor *GetVariableInput(TfLiteContext *context, const TfLiteNode *node, + int index) +{ + TfLiteTensor *tensor = GetMutableInput(context, node, index); + return tensor->is_variable ? tensor : nullptr; +} + +TfLiteTensor *GetOutput(TfLiteContext *context, const TfLiteNode *node, + int index) +{ + const int tensor_index = ValidateTensorIndexing( + context, index, node->outputs->size, node->outputs->data); + if (tensor_index < 0) { + return nullptr; + } + return GetTensorAtIndex(context, tensor_index); +} + +TfLiteStatus GetOutputSafe(const TfLiteContext *context, const TfLiteNode *node, + int index, TfLiteTensor **tensor) +{ + int tensor_index; + TF_LITE_ENSURE_OK( + context, ValidateTensorIndexingSafe(context, index, node->outputs->size, + node->outputs->data, &tensor_index)); + *tensor = GetTensorAtIndex(context, tensor_index); + return kTfLiteOk; +} + +const TfLiteTensor *GetOptionalInputTensor(const TfLiteContext *context, + const TfLiteNode *node, int index) +{ + return GetInput(context, node, index); +} + +#ifndef TF_LITE_STATIC_MEMORY +TfLiteTensor *GetTemporary(TfLiteContext *context, const TfLiteNode *node, + int index) +{ + const int tensor_index = ValidateTensorIndexing( + context, index, node->temporaries->size, node->temporaries->data); + if (tensor_index < 0) { + return nullptr; + } + return GetTensorAtIndex(context, tensor_index); +} + +TfLiteStatus GetTemporarySafe(const TfLiteContext *context, + const TfLiteNode *node, int index, + TfLiteTensor **tensor) +{ + int tensor_index; + TF_LITE_ENSURE_OK(context, ValidateTensorIndexingSafe( + context, index, node->temporaries->size, + node->temporaries->data, &tensor_index)); + *tensor = GetTensorAtIndex(context, tensor_index); + return kTfLiteOk; +} + +const TfLiteTensor *GetIntermediates(TfLiteContext *context, + const TfLiteNode *node, int index) +{ + const int tensor_index = ValidateTensorIndexing( + context, index, node->intermediates->size, node->intermediates->data); + if (tensor_index < 0) { + return nullptr; + } + return GetTensorAtIndex(context, tensor_index); +} + +TfLiteStatus GetIntermediatesSafe(const TfLiteContext *context, + const TfLiteNode *node, int index, + TfLiteTensor **tensor) +{ + int tensor_index; + TF_LITE_ENSURE_OK(context, ValidateTensorIndexingSafe( + context, index, node->intermediates->size, + node->intermediates->data, &tensor_index)); + *tensor = GetTensorAtIndex(context, tensor_index); + return kTfLiteOk; +} +#endif // TF_LITE_STATIC_MEMORY + +// Per-axis +TfLiteStatus PopulateConvolutionQuantizationParams( + TfLiteContext *context, const TfLiteTensor *input, + const TfLiteTensor *filter, const TfLiteTensor *bias, TfLiteTensor *output, + const TfLiteFusedActivation &activation, int32_t *multiplier, int *shift, + int32_t *output_activation_min, int32_t *output_activation_max, + int32_t *per_channel_multiplier, int32_t *per_channel_shift) +{ + const auto *affine_quantization = + reinterpret_cast(filter->quantization.params); + return PopulateConvolutionQuantizationParams( + context, input, filter, bias, output, activation, multiplier, shift, + output_activation_min, output_activation_max, per_channel_multiplier, + per_channel_shift, affine_quantization->scale->size); +} + +// Per-axis & per-tensor +TfLiteStatus PopulateConvolutionQuantizationParams( + TfLiteContext *context, const TfLiteTensor *input, + const TfLiteTensor *filter, const TfLiteTensor *bias, TfLiteTensor *output, + const TfLiteFusedActivation &activation, int32_t *multiplier, int *shift, + int32_t *output_activation_min, int32_t *output_activation_max, + int32_t *per_channel_multiplier, int32_t *per_channel_shift, + int num_channels) +{ + TF_LITE_ENSURE_EQ(context, input->quantization.type, + kTfLiteAffineQuantization); + TF_LITE_ENSURE_EQ(context, filter->quantization.type, + kTfLiteAffineQuantization); + // TODO(jianlijianli): Enable bias type check and bias scale == input scale + // * filter scale for each channel in affine quantization once bias + // quantization is properly populated. + // TF_LITE_ENSURE_EQ(context, bias->quantization.type, + // kTfLiteAffineQuantization); + + // Check data type. + const auto *affine_quantization = + reinterpret_cast(filter->quantization.params); + TF_LITE_ENSURE(context, affine_quantization); + TF_LITE_ENSURE(context, affine_quantization->scale); + const bool is_per_channel = affine_quantization->scale->size > 1; + if (is_per_channel) { + // Currently only Int8/Int16 is supported for per channel quantization. + TF_LITE_ENSURE(context, + input->type == kTfLiteInt8 || input->type == kTfLiteInt16); + TF_LITE_ENSURE_EQ(context, filter->type, kTfLiteInt8); + TF_LITE_ENSURE_EQ(context, affine_quantization->scale->size, num_channels); + TF_LITE_ENSURE_EQ( + context, num_channels, + filter->dims->data[affine_quantization->quantized_dimension]); + } + + // Populate multiplier and shift using affine quantization. + const float input_scale = input->params.scale; + const float output_scale = output->params.scale; + const float *filter_scales = affine_quantization->scale->data; + for (int i = 0; i < num_channels; ++i) { + // If per-tensor quantization parameter is specified, broadcast it along the + // quantization dimension (channels_out). + const float scale = is_per_channel ? filter_scales[i] : filter_scales[0]; + const double filter_scale = static_cast(scale); + const double effective_output_scale = static_cast(input_scale) * + filter_scale / + static_cast(output_scale); + int32_t significand; + int channel_shift; + QuantizeMultiplier(effective_output_scale, &significand, &channel_shift); + per_channel_multiplier[i] = significand; + per_channel_shift[i] = channel_shift; + } + + // Populate scalar quantization parameters. + // This check on legacy quantization parameters is kept only for backward + // compatibility. + if (input->type == kTfLiteUInt8) { + // Check bias scale == input scale * filter scale. + double real_multiplier = 0.0; + TF_LITE_ENSURE_STATUS(GetQuantizedConvolutionMultipler( + context, input, filter, bias, output, &real_multiplier)); + int exponent; + + // Populate quantization parameters with multiplier and shift. + QuantizeMultiplier(real_multiplier, multiplier, &exponent); + *shift = -exponent; + } + if (input->type == kTfLiteInt8 || input->type == kTfLiteUInt8 || + input->type == kTfLiteInt16) { + TF_LITE_ENSURE_STATUS(CalculateActivationRangeQuantized( + context, activation, output, output_activation_min, + output_activation_max)); + } + return kTfLiteOk; +} + +TfLiteStatus GetQuantizedConvolutionMultipler(TfLiteContext *context, + const TfLiteTensor *input, + const TfLiteTensor *filter, + const TfLiteTensor *bias, + TfLiteTensor *output, + double *multiplier) +{ + const double input_product_scale = static_cast(input->params.scale) * + static_cast(filter->params.scale); + // The following conditions must be guaranteed by the training pipeline. + if (bias) { + const double bias_scale = static_cast(bias->params.scale); + // Here we're making sure the input_product_scale & bias_scale are about the + // same. Since we have: + // (output - output_zp) * output_scale = + // input_product_scale * input_product + bias * bias_scale ---- (0) + // + // (0) equals: + // (input_product + bias) * input_product_scale ----- (1) + // + + // bias * (bias_scale - input_product_scale) ------ (2) + // + // For the real kernel computation, we're doing (1), so we really need to + // make sure (2) has minimum impact on the output, so: + // bias * (bias_scale - input_product_scale) / output_scale should be + // a small number for an integer. + // Since normally bias should be within a small range. + // We should expect (bias_scale - input_product_scale) / output_scale to + // be a small number like 0.02. + const double scale_diff = std::abs(input_product_scale - bias_scale); + const double output_scale = static_cast(output->params.scale); + + TF_LITE_ENSURE(context, scale_diff / output_scale <= 0.02); + } + return GetQuantizedConvolutionMultipler(context, input, filter, output, + multiplier); +} + +TfLiteStatus GetQuantizedConvolutionMultipler(TfLiteContext *context, + const TfLiteTensor *input, + const TfLiteTensor *filter, + TfLiteTensor *output, + double *multiplier) +{ + const double input_product_scale = + static_cast(input->params.scale * filter->params.scale); + TF_LITE_ENSURE(context, input_product_scale >= 0); + *multiplier = input_product_scale / static_cast(output->params.scale); + + return kTfLiteOk; +} + +namespace { + +inline TfLiteStatus Quantize(TfLiteContext *context, float scale, + int32_t zero_point, float f, int32_t &q) +{ + const float tmp = TfLiteRound(f / scale); + const bool no_integer_overflow_from_quantization = + (tmp >= static_cast(std::numeric_limits::min()) && + tmp <= static_cast(std::numeric_limits::max())); + TF_LITE_ENSURE(context, no_integer_overflow_from_quantization); + q = zero_point + static_cast(tmp); + return kTfLiteOk; +} + +TfLiteStatus CalculateActivationRangeQuantizedImpl( + TfLiteContext *context, TfLiteFusedActivation activation, int32_t qmin, + int32_t qmax, TfLiteTensor *output, int32_t *act_min, int32_t *act_max) +{ + const auto scale = output->params.scale; + const auto zero_point = output->params.zero_point; + + int32_t tmp_q; + if (activation == kTfLiteActRelu) { + TF_LITE_ENSURE_OK(context, + Quantize(context, scale, zero_point, 0.0, tmp_q)); + *act_min = std::max(qmin, tmp_q); + *act_max = qmax; + } else if (activation == kTfLiteActRelu6) { + TF_LITE_ENSURE_OK(context, + Quantize(context, scale, zero_point, 0.0, tmp_q)); + *act_min = std::max(qmin, tmp_q); + TF_LITE_ENSURE_OK(context, + Quantize(context, scale, zero_point, 6.0, tmp_q)); + *act_max = std::min(qmax, tmp_q); + } else if (activation == kTfLiteActReluN1To1) { + TF_LITE_ENSURE_OK(context, + Quantize(context, scale, zero_point, -1.0, tmp_q)); + *act_min = std::max(qmin, tmp_q); + TF_LITE_ENSURE_OK(context, + Quantize(context, scale, zero_point, 1.0, tmp_q)); + *act_max = std::min(qmax, tmp_q); + } else { + *act_min = qmin; + *act_max = qmax; + } + return kTfLiteOk; +} +} // namespace + +TfLiteStatus CalculateActivationRangeQuantized(TfLiteContext *context, + TfLiteFusedActivation activation, + TfLiteTensor *output, + int32_t *act_min, + int32_t *act_max) +{ + int32_t qmin = 0; + int32_t qmax = 0; + if (output->type == kTfLiteUInt8) { + qmin = std::numeric_limits::min(); + qmax = std::numeric_limits::max(); + } else if (output->type == kTfLiteInt8) { + qmin = std::numeric_limits::min(); + qmax = std::numeric_limits::max(); + } else if (output->type == kTfLiteInt16) { + qmin = std::numeric_limits::min(); + qmax = std::numeric_limits::max(); + } else { + TF_LITE_ENSURE(context, false); + } + + return CalculateActivationRangeQuantizedImpl(context, activation, qmin, qmax, + output, act_min, act_max); +} + +bool HaveSameShapes(const TfLiteTensor *input1, const TfLiteTensor *input2) +{ + return TfLiteIntArrayEqual(input1->dims, input2->dims); +} + +#ifndef TF_LITE_STATIC_MEMORY + +// TODO(b/172067338): Having this function be part of TF_LITE_STATIC_MEMORY +// build results in a 6KB size increase, even though the function is unsused for +// that build. What appears to be happening is that while the linker drops the +// unsused function, the string library that gets pulled in is not dropped, +// resulting in the increased binary size. +std::string GetShapeDebugString(const TfLiteIntArray *shape) +{ + std::string str; + for (int d = 0; d < shape->size; ++d) { + if (str.empty()) + str = "[" + std::to_string(shape->data[d]); + else + str += ", " + std::to_string(shape->data[d]); + } + str += "]"; + return str; +} + +TfLiteStatus CalculateShapeForBroadcast(TfLiteContext *context, + const TfLiteTensor *input1, + const TfLiteTensor *input2, + TfLiteIntArray **output_shape) +{ + int dims1 = NumDimensions(input1); + int dims2 = NumDimensions(input2); + int out_dims = std::max(dims1, dims2); + if (NumElements(input1) == 0) { + *output_shape = TfLiteIntArrayCopy(input1->dims); + return kTfLiteOk; + } + std::unique_ptr shape( + TfLiteIntArrayCreate(out_dims), TfLiteIntArrayFree); + for (int i = 0; i < out_dims; ++i) { + int d1 = i >= dims1 ? 1 : SizeOfDimension(input1, dims1 - i - 1); + int d2 = i >= dims2 ? 1 : SizeOfDimension(input2, dims2 - i - 1); + if (!(d1 == d2 || d1 == 1 || d2 == 1)) { + context->ReportError(context, + "Given shapes, %s and %s, are not broadcastable.", + GetShapeDebugString(input1->dims).c_str(), + GetShapeDebugString(input2->dims).c_str()); + return kTfLiteError; + } + shape->data[out_dims - i - 1] = std::max(d1, d2); + } + *output_shape = shape.release(); + return kTfLiteOk; +} + +TfLiteStatus CalculateShapeForBroadcast(TfLiteContext *context, + const TfLiteTensor *input1, + const TfLiteTensor *input2, + const TfLiteTensor *input3, + TfLiteIntArray **output_shape) +{ + int dims1 = NumDimensions(input1); + int dims2 = NumDimensions(input2); + int dims3 = NumDimensions(input3); + int out_dims = std::max(std::max(dims1, dims2), dims3); + std::unique_ptr shape( + TfLiteIntArrayCreate(out_dims), TfLiteIntArrayFree); + for (int i = 0; i < out_dims; ++i) { + int d1 = i >= dims1 ? 1 : SizeOfDimension(input1, dims1 - i - 1); + int d2 = i >= dims2 ? 1 : SizeOfDimension(input2, dims2 - i - 1); + int d3 = i >= dims3 ? 1 : SizeOfDimension(input3, dims3 - i - 1); + int max_value = std::max(std::max(d1, d2), d3); + if (!(d1 == 1 || d1 == max_value) || !(d2 == 1 || d2 == max_value) || + !(d3 == 1 || d3 == max_value)) { + context->ReportError( + context, "Given shapes, %s, %s and %s, are not broadcastable.", + GetShapeDebugString(input1->dims).c_str(), + GetShapeDebugString(input2->dims).c_str(), + GetShapeDebugString(input3->dims).c_str()); + return kTfLiteError; + } + shape->data[out_dims - i - 1] = max_value; + } + *output_shape = shape.release(); + return kTfLiteOk; +} +#endif // TF_LITE_STATIC_MEMORY + +// Size of string is not constant, return 0 in such case. +int TfLiteTypeGetSize(TfLiteType type) +{ + switch (type) { + case kTfLiteUInt8: + TF_LITE_ASSERT_EQ(sizeof(uint8_t), 1); + return 1; + case kTfLiteInt8: + TF_LITE_ASSERT_EQ(sizeof(int8_t), 1); + return 1; + case kTfLiteBool: + return sizeof(bool); + case kTfLiteInt16: + TF_LITE_ASSERT_EQ(sizeof(int16_t), 2); + return 2; + case kTfLiteFloat16: + TF_LITE_ASSERT_EQ(sizeof(int16_t), 2); + return 2; + case kTfLiteFloat32: + TF_LITE_ASSERT_EQ(sizeof(float), 4); + return 4; + case kTfLiteInt32: + TF_LITE_ASSERT_EQ(sizeof(int32_t), 4); + return 4; + case kTfLiteUInt32: + TF_LITE_ASSERT_EQ(sizeof(uint32_t), 4); + return 4; + case kTfLiteInt64: + TF_LITE_ASSERT_EQ(sizeof(int64_t), 8); + return 8; + case kTfLiteUInt64: + TF_LITE_ASSERT_EQ(sizeof(uint64_t), 8); + return 8; + case kTfLiteFloat64: + TF_LITE_ASSERT_EQ(sizeof(double), 8); + return 8; + case kTfLiteComplex64: + TF_LITE_ASSERT_EQ(sizeof(std::complex), 8); + return 8; + case kTfLiteComplex128: + TF_LITE_ASSERT_EQ(sizeof(std::complex), 16); + return 16; + default: + return 0; + } +} + +bool IsMobilePlatform() +{ +#if defined(ANDROID) || defined(__ANDROID__) + return true; +#elif defined(__APPLE__) +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + return true; +#endif +#endif + return false; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/kernels/kernel_util.h b/components/tflite/tensorflow/lite/kernels/kernel_util.h new file mode 100644 index 00000000..47c7e466 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/kernel_util.h @@ -0,0 +1,315 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_KERNEL_UTIL_H_ +#define TENSORFLOW_LITE_KERNELS_KERNEL_UTIL_H_ + +#include + +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" + +namespace tflite { +// A fair number of functions in this header have historically been inline. +// It is ok to change functions to not be inline if the latency with +// benchmark_model for MobileNet + MobileBERT is unaffected. If such a change is +// made, move the newly non-inlined function declarations to the top of this +// header file. + +// Note: You must check if result is not null: +// +// TfLiteTensor* my_tensor = GetInput(context, node, kMyTensorIdx); +// TF_LITE_ENSURE(context, my_tensor != nullptr); +// +// This is because the index might point to the optional tensor constant +// (kTfLiteOptionalTensor) in which case there is no tensor to return. +const TfLiteTensor *GetInput(const TfLiteContext *context, + const TfLiteNode *node, int index); + +// Same as `GetInput` but returns boolean and uses output argument for tensor. +// +// TfLiteTensor* my_tensor; +// TF_LITE_ENSURE_OK(context, +// GetInputSafe(context, node, kMyTensorIdx, &my_tensor)); +// // can use my_tensor directly from here onwards, it is not nullptr +// +// Should be used in cases where the binary size is too large. +TfLiteStatus GetInputSafe(const TfLiteContext *context, const TfLiteNode *node, + int index, const TfLiteTensor **tensor); + +// Note: You must check if result is not null: +// +// TfLiteTensor* my_tensor = GetVariableInput(context, node, kMyTensorIdx); +// TF_LITE_ENSURE(context, my_tensor != nullptr); +// +// This is because the index might point to the optional tensor constant +// (kTfLiteOptionalTensor) in which case there is no tensor to return. +TfLiteTensor *GetVariableInput(TfLiteContext *context, const TfLiteNode *node, + int index); + +// Note: You must check if result is not null: +// +// TfLiteTensor* my_tensor = GetOutput(context, node, kMyTensorIdx); +// TF_LITE_ENSURE(context, my_tensor != nullptr); +// +// This is because the index might point to the optional tensor constant +// (kTfLiteOptionalTensor) in which case there is no tensor to return. +TfLiteTensor *GetOutput(TfLiteContext *context, const TfLiteNode *node, + int index); + +// Same as `GetOutput` but returns boolean and uses output argument for tensor. +// +// TfLiteTensor* my_tensor; +// TF_LITE_ENSURE_OK(context, +// GetOutputSafe(context, node, kMyTensorIdx, &my_tensor)); +// // can use my_tensor directly from here onwards, it is not nullptr +// +// Should be used in cases where the binary size is too large. +TfLiteStatus GetOutputSafe(const TfLiteContext *context, const TfLiteNode *node, + int index, TfLiteTensor **tensor); + +// Note: You must check if result is not null: +// +// TfLiteTensor* my_tensor = GetOptionalInputTensor(context, node, kIdx); +// TF_LITE_ENSURE(context, my_tensor != nullptr); +// +// This is because the index might point to the optional tensor constant +// (kTfLiteOptionalTensor) in which case there is no tensor to return. +// +// Deprecated. GetInput has the same functionality. +const TfLiteTensor *GetOptionalInputTensor(const TfLiteContext *context, + const TfLiteNode *node, int index); + +#ifndef TF_LITE_STATIC_MEMORY +// Note: You must check if result is not null: +// +// TfLiteTensor* my_tensor = GetTemporary(context, node, kMyTensorIdx); +// TF_LITE_ENSURE(context, my_tensor != nullptr); +// +// This is because the index might point to the optional tensor constant +// (kTfLiteOptionalTensor) in which case there is no tensor to return. +TfLiteTensor *GetTemporary(TfLiteContext *context, const TfLiteNode *node, + int index); + +// Same as `GetTemporary` but returns boolean and uses output argument for +// tensor. +// +// TfLiteTensor* my_tensor; +// TF_LITE_ENSURE_OK(context, +// GetTemporarySafe(context, node, kMyTensorIdx, +// &my_tensor)); +// // can use my_tensor directly from here onwards, it is not nullptr +// +// Should be used in cases where the binary size is too large. +TfLiteStatus GetTemporarySafe(const TfLiteContext *context, + const TfLiteNode *node, int index, + TfLiteTensor **tensor); + +// Note: You must check if result is not null: +// +// TfLiteTensor* my_tensor = GetIntermediates(context, node, kMyTensorIdx); +// TF_LITE_ENSURE(context, my_tensor != nullptr); +// +// This is because the index might point to the optional tensor constant +// (kTfLiteOptionalTensor) in which case there is no tensor to return. +const TfLiteTensor *GetIntermediates(TfLiteContext *context, + const TfLiteNode *node, int index); + +// Same as `GetIntermediates` but returns boolean and uses output argument for +// tensor. +// +// TfLiteTensor* my_tensor; +// TF_LITE_ENSURE_OK(context, +// GetIntermediatesSafe(context, node, kMyTensorIdx, +// &my_tensor)); +// // can use my_tensor directly from here onwards, it is not nullptr +// +// Should be used in cases where the binary size is too large. +TfLiteStatus GetIntermediatesSafe(const TfLiteContext *context, + const TfLiteNode *node, int index, + TfLiteTensor **tensor); +#endif // TF_LITE_STATIC_MEMORY + +inline int NumDimensions(const TfLiteTensor *t) +{ + return t->dims->size; +} +inline int SizeOfDimension(const TfLiteTensor *t, int dim) +{ + return t->dims->data[dim]; +} + +inline int NumInputs(const TfLiteNode *node) +{ + return node->inputs->size; +} +inline int NumOutputs(const TfLiteNode *node) +{ + return node->outputs->size; +} + +#ifndef TF_LITE_STATIC_MEMORY +inline int NumIntermediates(const TfLiteNode *node) +{ + return node->intermediates->size; +} +#endif // TF_LITE_STATIC_MEMORY + +inline int64_t NumElements(const TfLiteIntArray *dims) +{ + int64_t count = 1; + for (int i = 0; i < dims->size; ++i) { + count *= dims->data[i]; + } + return count; +} + +inline int64_t NumElements(const TfLiteTensor *t) +{ + return NumElements(t->dims); +} + +// Determines whether tensor is constant. +// TODO(b/138199592): Introduce new query which checks for constant OR +// persistent-read-only, which would be useful for most tensor kernels that +// are potentially dynamic based on the input tensor value availability at the +// time of prepare. +inline bool IsConstantTensor(const TfLiteTensor *tensor) +{ + return tensor->allocation_type == kTfLiteMmapRo; +} + +// Determines whether tensor is dynamic. Note that a tensor can be non-const and +// not dynamic. This function specifically checks for a dynamic tensor. +inline bool IsDynamicTensor(const TfLiteTensor *tensor) +{ + return tensor->allocation_type == kTfLiteDynamic; +} + +// Sets tensor to dynamic. +inline void SetTensorToDynamic(TfLiteTensor *tensor) +{ + if (tensor->allocation_type != kTfLiteDynamic) { + tensor->allocation_type = kTfLiteDynamic; + tensor->data.raw = nullptr; + } +} + +// Sets tensor to persistent and read-only. +inline void SetTensorToPersistentRo(TfLiteTensor *tensor) +{ + if (tensor->allocation_type != kTfLitePersistentRo) { + tensor->allocation_type = kTfLitePersistentRo; + tensor->data.raw = nullptr; + } +} + +// Determines whether it is a hybrid op - one that has float inputs and +// quantized weights. +inline bool IsHybridOp(const TfLiteTensor *input, const TfLiteTensor *weight) +{ + return ((weight->type == kTfLiteUInt8 || weight->type == kTfLiteInt8) && + input->type == kTfLiteFloat32); +} + +// Check dimensionality match and populate OpData for Conv and DepthwiseConv. +TfLiteStatus PopulateConvolutionQuantizationParams( + TfLiteContext *context, const TfLiteTensor *input, + const TfLiteTensor *filter, const TfLiteTensor *bias, TfLiteTensor *output, + const TfLiteFusedActivation &activation, int32_t *multiplier, int *shift, + int32_t *output_activation_min, int32_t *output_activation_max, + int32_t *per_channel_multiplier, int32_t *per_channel_shift); + +TfLiteStatus PopulateConvolutionQuantizationParams( + TfLiteContext *context, const TfLiteTensor *input, + const TfLiteTensor *filter, const TfLiteTensor *bias, TfLiteTensor *output, + const TfLiteFusedActivation &activation, int32_t *multiplier, int *shift, + int32_t *output_activation_min, int32_t *output_activation_max, + int32_t *per_channel_multiplier, int32_t *per_channel_shift, + int num_channels); + +// Calculates the multiplication factor for a quantized convolution (or +// quantized depthwise convolution) involving the given tensors. Returns an +// error if the scales of the tensors are not compatible. +TfLiteStatus GetQuantizedConvolutionMultipler(TfLiteContext *context, + const TfLiteTensor *input, + const TfLiteTensor *filter, + const TfLiteTensor *bias, + TfLiteTensor *output, + double *multiplier); + +TfLiteStatus GetQuantizedConvolutionMultipler(TfLiteContext *context, + const TfLiteTensor *input, + const TfLiteTensor *filter, + TfLiteTensor *output, + double *multiplier); + +// Calculates the useful quantized range of an activation layer given its +// activation tensor. +TfLiteStatus CalculateActivationRangeQuantized(TfLiteContext *context, + TfLiteFusedActivation activation, + TfLiteTensor *output, + int32_t *act_min, + int32_t *act_max); + +// Calculates the useful range of an activation layer given its activation +// tensor.a +template +void CalculateActivationRange(TfLiteFusedActivation activation, + T *activation_min, T *activation_max) +{ + if (activation == kTfLiteActRelu) { + *activation_min = 0; + *activation_max = std::numeric_limits::max(); + } else if (activation == kTfLiteActRelu6) { + *activation_min = 0; + *activation_max = 6; + } else if (activation == kTfLiteActReluN1To1) { + *activation_min = -1; + *activation_max = 1; + } else { + *activation_min = std::numeric_limits::lowest(); + *activation_max = std::numeric_limits::max(); + } +} + +// Return true if the given tensors have the same shape. +bool HaveSameShapes(const TfLiteTensor *input1, const TfLiteTensor *input2); + +// Calculates the output_shape that is necessary for element-wise operations +// with broadcasting involving the two input tensors. +TfLiteStatus CalculateShapeForBroadcast(TfLiteContext *context, + const TfLiteTensor *input1, + const TfLiteTensor *input2, + TfLiteIntArray **output_shape); + +// Calculates the output_shape that is necessary for element-wise operations +// with broadcasting involving the three input tensors. +TfLiteStatus CalculateShapeForBroadcast(TfLiteContext *context, + const TfLiteTensor *input1, + const TfLiteTensor *input2, + const TfLiteTensor *input3, + TfLiteIntArray **output_shape); + +// Return the size of given type in bytes. Return 0 in in case of string. +int TfLiteTypeGetSize(TfLiteType type); + +// Whether the current platform is mobile (Android or iOS). +bool IsMobilePlatform(); + +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_KERNEL_UTIL_H_ diff --git a/components/tflite/tensorflow/lite/kernels/op_macros.h b/components/tflite/tensorflow/lite/kernels/op_macros.h new file mode 100644 index 00000000..51ccd204 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/op_macros.h @@ -0,0 +1,86 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_OP_MACROS_H_ +#define TENSORFLOW_LITE_KERNELS_OP_MACROS_H_ + +// If we're on a platform without standard IO functions, fall back to a +// non-portable function. +#ifdef TF_LITE_MCU_DEBUG_LOG + +#include "tensorflow/lite/micro/debug_log.h" + +#define DEBUG_LOG(x) \ + do { \ + DebugLog(x); \ + } while (0) + +inline void InfiniteLoop() +{ + DEBUG_LOG("HALTED\n"); + while (1) { + } +} + +#define TFLITE_ABORT InfiniteLoop(); + +#else // TF_LITE_MCU_DEBUG_LOG + +#include +#include + +#define DEBUG_LOG(x) \ + do { \ + fprintf(stderr, "%s", (x)); \ + } while (0) + +// Report Error for unsupported type by op 'op_name' and returns kTfLiteError. +#define TF_LITE_UNSUPPORTED_TYPE(context, type, op_name) \ + do { \ + TF_LITE_KERNEL_LOG((context), "%s:%d Type %s is unsupported by op %s.", \ + __FILE__, __LINE__, TfLiteTypeGetName(type), \ + (op_name)); \ + return kTfLiteError; \ + } while (0) + +#define TFLITE_ABORT abort() + +#endif // TF_LITE_MCU_DEBUG_LOG + +#if defined(NDEBUG) || defined(ARDUINO) +#define TFLITE_ASSERT_FALSE (static_cast(0)) +#else +#define TFLITE_ASSERT_FALSE TFLITE_ABORT +#endif + +#define TF_LITE_FATAL(msg) \ + do { \ + DEBUG_LOG(msg); \ + DEBUG_LOG("\nFATAL\n"); \ + TFLITE_ABORT; \ + } while (0) + +#define TF_LITE_ASSERT(x) \ + do { \ + if (!(x)) \ + TF_LITE_FATAL(#x); \ + } while (0) + +#define TF_LITE_ASSERT_EQ(x, y) \ + do { \ + if ((x) != (y)) \ + TF_LITE_FATAL(#x " didn't equal " #y); \ + } while (0) + +#endif // TENSORFLOW_LITE_KERNELS_OP_MACROS_H_ diff --git a/components/tflite/tensorflow/lite/kernels/padding.h b/components/tflite/tensorflow/lite/kernels/padding.h new file mode 100644 index 00000000..6a956406 --- /dev/null +++ b/components/tflite/tensorflow/lite/kernels/padding.h @@ -0,0 +1,120 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_KERNELS_PADDING_H_ +#define TENSORFLOW_LITE_KERNELS_PADDING_H_ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +inline int ComputePadding(int stride, int dilation_rate, int in_size, + int filter_size, int out_size) +{ + int effective_filter_size = (filter_size - 1) * dilation_rate + 1; + int padding = ((out_size - 1) * stride + effective_filter_size - in_size) / 2; + return padding > 0 ? padding : 0; +} + +// It's not guaranteed that padding is symmetric. It's important to keep +// offset for algorithms need all paddings. +inline int ComputePaddingWithOffset(int stride, int dilation_rate, int in_size, + int filter_size, int out_size, + int *offset) +{ + int effective_filter_size = (filter_size - 1) * dilation_rate + 1; + int total_padding = + ((out_size - 1) * stride + effective_filter_size - in_size); + total_padding = total_padding > 0 ? total_padding : 0; + *offset = total_padding % 2; + return total_padding / 2; +} + +// Matching GetWindowedOutputSize in TensorFlow. +inline int ComputeOutSize(TfLitePadding padding, int image_size, + int filter_size, int stride, int dilation_rate = 1) +{ + int effective_filter_size = (filter_size - 1) * dilation_rate + 1; + + // TODO(b/186448822): This uses 0 since the function has no other way to + // report error case + if (stride == 0) + return 0; + + switch (padding) { + case kTfLitePaddingSame: + return (image_size + stride - 1) / stride; + case kTfLitePaddingValid: + return (image_size + stride - effective_filter_size) / stride; + default: + return 0; + } +} + +inline TfLitePaddingValues ComputePaddingHeightWidth( + int stride_height, int stride_width, int dilation_rate_height, + int dilation_rate_width, int in_height, int in_width, int filter_height, + int filter_width, TfLitePadding padding, int *out_height, int *out_width) +{ + *out_width = ComputeOutSize(padding, in_width, filter_width, stride_width, + dilation_rate_width); + *out_height = ComputeOutSize(padding, in_height, filter_height, stride_height, + dilation_rate_height); + + TfLitePaddingValues padding_values; + int offset = 0; + padding_values.height = + ComputePaddingWithOffset(stride_height, dilation_rate_height, in_height, + filter_height, *out_height, &offset); + padding_values.height_offset = offset; + padding_values.width = + ComputePaddingWithOffset(stride_width, dilation_rate_width, in_width, + filter_width, *out_width, &offset); + padding_values.width_offset = offset; + return padding_values; +} + +inline Padding3DValues ComputePadding3DValues( + int stride_height, int stride_width, int stride_depth, + int dilation_rate_height, int dilation_rate_width, int dilation_rate_depth, + int in_height, int in_width, int in_depth, int filter_height, + int filter_width, int filter_depth, TfLitePadding padding, int *out_height, + int *out_width, int *out_depth) +{ + *out_width = ComputeOutSize(padding, in_width, filter_width, stride_width, + dilation_rate_width); + *out_height = ComputeOutSize(padding, in_height, filter_height, stride_height, + dilation_rate_height); + *out_depth = ComputeOutSize(padding, in_depth, filter_depth, stride_depth, + dilation_rate_depth); + + Padding3DValues padding_values; + int offset = 0; + padding_values.depth = + ComputePaddingWithOffset(stride_depth, dilation_rate_depth, in_depth, + filter_depth, *out_depth, &offset); + padding_values.depth_offset = offset; + padding_values.height = + ComputePaddingWithOffset(stride_height, dilation_rate_height, in_height, + filter_height, *out_height, &offset); + padding_values.height_offset = offset; + padding_values.width = + ComputePaddingWithOffset(stride_width, dilation_rate_width, in_width, + filter_width, *out_width, &offset); + padding_values.width_offset = offset; + return padding_values; +} +} // namespace tflite + +#endif // TENSORFLOW_LITE_KERNELS_PADDING_H_ diff --git a/components/tflite/tensorflow/lite/micro/CONTRIBUTING.md b/components/tflite/tensorflow/lite/micro/CONTRIBUTING.md new file mode 100644 index 00000000..1e4b85f6 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/CONTRIBUTING.md @@ -0,0 +1,378 @@ + + + + + + * [Contributing Guidelines](#contributing-guidelines) + * [General Pull Request Guidelines](#general-pull-request-guidelines) + * [Guidelines for Specific Contribution Categories](#guidelines-for-specific-contribution-categories) + * [Bug Fixes](#bug-fixes) + * [Reference Kernel Implementations](#reference-kernel-implementations) + * [Optimized Kernel Implementations](#optimized-kernel-implementations) + * [New Target / Platform / IDE / Examples](#new-target--platform--ide--examples) + * [New Features](#new-features) + * [Development Workflow Notes](#development-workflow-notes) + * [Initial Setup](#initial-setup) + * [Before submitting your PR](#before-submitting-your-pr) + * [During the PR review](#during-the-pr-review) + * [Reviewer notes](#reviewer-notes) + * [Python notes](#python-notes) + * [Continuous Integration System](#continuous-integration-system) + + + + + +# Contributing Guidelines + +We look forward to your contributions to the TensorFlow Lite Micro codebase and +provide guidelines with the goal of enabling community contributions while still +maintaining code health, maintainability, and consistency in style. + +Please note that while these guidelines may seem onerous to some developers, +they are derived from Google's software engineering best practices. + +Before we describe project-specific guidelines, we recommend that external +contributors read these tips from the Google Testing Blog: + +* [Code Health: Providing Context with Commit Messages and Bug Reports](https://testing.googleblog.com/2017/09/code-health-providing-context-with.html) +* [Code Health: Understanding Code In Review](https://testing.googleblog.com/2018/05/code-health-understanding-code-in-review.html) +* [Code Health: Too Many Comments on Your Code Reviews?](https://testing.googleblog.com/2017/06/code-health-too-many-comments-on-your.html) +* [Code Health: To Comment or Not to Comment?](https://testing.googleblog.com/2017/07/code-health-to-comment-or-not-to-comment.html) + +We also recommend that contributors take a look at the +[Tensorflow Contributing Guidelines](https://github.com/tensorflow/tensorflow/blob/master/CONTRIBUTING.md). + +## General Pull Request Guidelines + +We strongly recommend that contributors: + +1. Initiate a conversation with the TFLM team via a + [TF Lite Micro Github issue](https://github.com/tensorflow/tensorflow/issues/new?labels=comp%3Amicro&template=70-tflite-micro-issue.md) + as early as possible. + + * This enables us to give guidance on how to proceed, prevent duplicated + effort and also point to alternatives as well as context if we are not + able to accept a particular contribution at a given time. + + * Ideally, you should make an issue ***before*** starting to work on a + pull request and provide context on both what you want to contribute and + why. + +1. Once step 1. is complete and it is determined that a PR from an external + contributor is the way to go, please follow these guidelines from + [Google's Engineering Practices documentation](https://google.github.io/eng-practices/): + + * [Send Small Pull Requests](https://google.github.io/eng-practices/review/developer/small-cls.html) + + * If a pull request is doing more than one thing, the reviewer will + request that it be broken up into two or more PRs. + + * [Write Good Pull Request Descriptions](https://google.github.io/eng-practices/review/developer/cl-descriptions.html) + + * We require that all PR descriptions link to the github issue created + in step 1. + + * While github offers flexibility in linking + [commits and issues](https://github.blog/2011-04-09-issues-2-0-the-next-generation/#commits-issues), + we require that the PR description have a separate line with either + `Fixes #nn` (if the PR fixes the issue) or `Issue #nn` if the PR + addresses some aspect of an issue without fixing it. + + * We will be adding internal checks that automate this requirement by + matching the PR description to the regexp: `(Fixes|Issue) #` + +1. Unit tests are critical to a healthy codebase. PRs without tests should be + the exception rather than the norm. And contributions to improve, simplify, + or make the unit tests more exhaustive are welcome! Please refer to + [this guideline](https://google.github.io/eng-practices/review/developer/small-cls.html#test_code) + on how test code and writing small PRs should be reconciled. + +## Guidelines for Specific Contribution Categories + +We provide some additional guidelines for different categories of contributions. + +### Bug Fixes + +Pull requests that fix bugs are always welcome and often uncontroversial, unless +there is a conflict between different requirements from the platform, or if +fixing a bug needs a bigger architectural change. + +1. Create a + [TF Lite Micro Github issue](https://github.com/tensorflow/tensorflow/issues/new?labels=comp%3Amicro&template=70-tflite-micro-issue.md) + to determine the scope of the bug fix. +1. Send a PR (if that is determined to be the best path forward). +1. Bugfix PRs should be accompanied by a test case that fails prior to the fix + and passes with the fix. This validates that the fix works as expected, and + helps prevent future regressions. + +### Reference Kernel Implementations + +Pull requests that port reference kernels from TF Lite Mobile to TF Lite Micro +are welcome once we have enough context from the contributor on why the +additional kernel is needed. + +1. Please create a + [TF Lite Micro Github issue](https://github.com/tensorflow/tensorflow/issues/new?labels=comp%3Amicro&template=70-tflite-micro-issue.md) + before starting on any such PRs with as much context as possible, such as: + + * What is the model architecture? + * What is the application that you are targetting? + * What embedded target(s) are you planning to run on? + * Motivate your use-case and the need for adding support for this + additional OP. + +1. In the interest of having + [small pull requests](https://google.github.io/eng-practices/review/developer/small-cls.html), + limit each pull request to porting a single kernel (and the corresponding + test). + +1. TODO(b/165627437): Create and link to a guide to porting reference ops. + +### Optimized Kernel Implementations + +In order to have the TFLM codebase be a central repository of optimized kernel +implementations, we would like to make some improvements to the current +infrastructure to enable adding and maintaining optimized kernel implementations +in a scalable way. + +Until that work is complete, we are requesting a ***pause*** on contributions that +add new optimized kernel implementations. We plan to make these improvements by +October 2020 and will provide additional guidelines at that time. + +* If you would like to have an exception to this pause, with the understanding + that your optimized kernels will break as we improve the underlying + framework, then please send an email to the [SIG Micro email + group](https://groups.google.com/a/tensorflow.org/g/micro) to figure out + a middle ground. + +* Every optimized kernel directory must have a README.md with the github IDs + of the maintainers and any other relevant documentation. PRs that add + maintainers to the existing optimized kernels are always welcome. + +### New Target / Platform / IDE / Examples + +As discussed in the +[SIG-micro Aug 12, 2020 meeting](http://doc/1YHq9rmhrOUdcZnrEnVCWvd87s2wQbq4z17HbeRl-DBc), +we are currently ***pausing*** accepting pull requests that add new targets, +platforms, IDE integration or examples while we revisit some of the +infrastructure to enable us to make this process easier and more scalable. + +In the meantime, snapshotting and/or forking the tensorflow repo could be a +viable way to prototype platform support. + +Having said that, we still invite +[TF Lite Micro Github issues](https://github.com/tensorflow/tensorflow/issues/new?labels=comp%3Amicro&template=70-tflite-micro-issue.md) +on this topic as we would like to enable such integration in the future. + +### New Features + +As discussed in the +[SIG-micro Aug 12, 2020 meeting](http://doc/1YHq9rmhrOUdcZnrEnVCWvd87s2wQbq4z17HbeRl-DBc), +we are currently ***pausing*** accepting pull requests that add new features while +we revisit some of the infrastructure to enable us to make this process easier +and more scalable. + +Having said that, we still invite feature requests via +[TF Lite Micro Github issues](https://github.com/tensorflow/tensorflow/issues/new?labels=comp%3Amicro&template=70-tflite-micro-issue.md) +to determine if the requested feature aligns with the TFLM roadmap. + +# Development Workflow Notes + +## Initial Setup + +Below are some tips that might be useful and improve the development experience. + +* Add the [Refined GitHub](https://github.com/sindresorhus/refined-github) + plugin to make the github experience even better. + +* Code search the [TfLite Micro codebase](https://sourcegraph.com/github.com/tensorflow/tensorflow@master/-/tree/tensorflow/lite/micro) + on Sourcegraph. And optionally install the [plugin that enables GitHub integration](https://docs.sourcegraph.com/integration/github#github-integration-with-sourcegraph). + +* Install [bazel](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/ci_build/install/install_bazel.sh) and [buildifier](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/ci_build/install/install_buildifier.sh). + +* Install the latest clang and clang-format. For example, + [here](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/ci_build/Dockerfile.micro) + is the what we do for the TFLM continuous integration Docker container. + +* Get a copy of [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint) + +* Add a git hook to check for code style etc. prior to creating a pull request: + ``` + cp tensorflow/lite/micro/tools/dev_setup/pre-push.tflm .git/hooks/pre-push + ``` + +## Before submitting your PR + +1. Run in-place clang-format on all the files that are modified in your git + tree with + + ``` + clang-format -i -style=google `git ls-files -m | grep "\.cc"` + clang-format -i -style=google `git ls-files -m | grep "\.h"` + ``` + +1. Make sure your code is lint-free. + + ``` + cpplint.py `git ls-files -m` + ``` + +1. Run all the tests for x86, and any other platform that you are modifying. + + ``` + tensorflow/lite/micro/tools/ci_build/test_x86.sh + ``` + + Please check the READMEs in the optimized kernel directories for specific + instructions. + +1. Sometimes, bugs are caught by the sanitizers that can go unnoticed + via the Makefile. To run a test with the different sanitizers, use the + following commands (replace `micro_interpreter_test` with the target that you + want to test: + + ``` + CC=clang bazel run --config=asan tensorflow/lite/micro:micro_interpreter_test + CC=clang bazel run --config=msan tensorflow/lite/micro:micro_interpreter_test + CC=clang bazel run --config=ubsan tensorflow/lite/micro:micro_interpreter_test + ``` + +## During the PR review + +1. Do not change the git version history. + + * Always merge upstream/master (***do not rebase***) and no force-pushes + please. + + * Having an extra merge commit it ok as the github review tool handles + that gracefully. + + Assuming that you forked tensorflow and added a remote called upstream with: + + `git remote add upstream https://github.com/tensorflow/tensorflow.git` + + Fetch the latest changes from upstream and merge into your local branch. + + ``` + git fetch upstream + git merge upstream/master + ``` + + In case of a merge conflict, resolve via: + + ``` + git mergetool + + # Use your favorite diff tools (e.g. meld) to resolve the conflicts. + + git add + + git commit + ``` + +1. If a force push seems to be the only path forward, please stop and let your + PR reviewer know ***before*** force pushing. We will attempt to do the merge + for you. This will also help us better understand in what conditions a + force-push may be unavoidable. + +## Reviewer notes + +* [GIthub CLI](https://cli.github.com) can be useful to quickly checkout a PR + to test locally. + + `gh pr checkout ` + +* Google engineers on the Tensorflow team will have the permissions to push + edits to most PRs. This can be useful to make some small fixes as a result + of errors due to internal checks that are not easily reproducible via + github. + + One example of this is + [this comment](https://github.com/tensorflow/tensorflow/pull/38634#issuecomment-683190474). + + And a sketch of the steps: + + ``` + git remote add git@github.com:/tensorflow.git + git fetch + + git checkout -b / + + # make changes and commit to local branch + + # push changes to remove branch + + git push + + # remove the temp remote to clean up your git environment. + + git remote rm + ``` + +## Python notes + +Most PRs for TensorFlow Lite Micro will be C++ only. Adding some notes on Python +that can be expanded and improved as necessary. + +* [TensorFlow guide](https://www.tensorflow.org/community/contribute/code_style#python_style) + for Python development + +* [yapf](https://github.com/google/yapf/) should be used for formatting. + + ``` + yapf log_parser.py -i --style='{based_on_style: pep8, indent_width: 2}' + ``` + +# Continuous Integration System + +* As a contributor, please make sure that the TfLite Micro build is green. + You can click on the details link to see what the errors are: + +[![TfLite Micro Build](docs/images/tflm_continuous_integration_1.png)](https://storage.googleapis.com/tensorflow-kokoro-build-badges/tflite-micro.html) + +* Tests that are run as part of the CI are with the + [micro/tools/ci_build/test_all.sh](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/micro/tools/ci_build/test_all.sh) + script when run with the `GITHUB_PRESUBMIT` command line parameter: + ``` + tensorflow/lite/micro/tools/ci_build/test_all.sh GITHUB_PRESUBMIT + ``` + +* If an error is not reproducible on your development machine, you can + recreate the docker container that is used on the CI servers. + + * First, create a build a TFLM docker image with: + ``` + tensorflow/tools/ci_build/ci_build.sh micro bash + ``` + The second parameter to the ci_build.sh script is not important. It can + be any command. + + * Next, mount the tensorflow repo on your machine to the docker container. + Please be careful (or make a separate clone of tensorflow) since any + changes docker container will also be reflected in the directory in the + host machine. + ``` + docker run -v `pwd`:/tensorflow -it tf_ci.micro bash + # cd tensorflow + ``` + + * If you would prefer to not mount your local folder on the docker image, + you can also simply download the branch: + ``` + docker run -it tf_ci.micro bash + # wget https://github.com//tensorflow/archive/.zip + # unzip .zip + # cd tensorflow- + ``` + + * Within the docker container, you can now run the TFLM test script, or + any other command that you would like to test. For example, the following + commands will run all of the TFLM checks: + ``` + # tensorflow/lite/micro/tools/ci_build/test_all.sh GITHUB_PRESUBMIT + ``` + diff --git a/components/tflite/tensorflow/lite/micro/README.md b/components/tflite/tensorflow/lite/micro/README.md new file mode 100644 index 00000000..0a8f7ce1 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/README.md @@ -0,0 +1,76 @@ + + + + + + * [TensorFlow Lite for Microcontrollers](#tensorflow-lite-for-microcontrollers) + * [Continuous Build Status](#continuous-build-status) + * [Official Builds](#official-builds) + * [Community Supported Builds](#community-supported-builds) + * [Getting Help and Involved](#getting-help-and-involved) + * [Additional Documentation](#additional-documentation) + + + + + +# TensorFlow Lite for Microcontrollers + +TensorFlow Lite for Microcontrollers is a port of TensorFlow Lite designed to +run machine learning models on microcontrollers and other devices with only +kilobytes of memory. + +To learn how to use the framework, visit the developer documentation at +[tensorflow.org/lite/microcontrollers](https://www.tensorflow.org/lite/microcontrollers). + +# Continuous Build Status + +## Official Builds +Build Type | Status | Artifacts +---------- | ----------- | --------- +Linux | [![Status](https://storage.googleapis.com/tensorflow-kokoro-build-badges/tflite-micro.svg)](https://storage.googleapis.com/tensorflow-kokoro-build-badges/tflite-micro.html) | + +## Community Supported Builds +Build Type | Status | Artifacts +---------- | ----------- | --------- +Arduino | [![Status](https://github.com/antmicro/tensorflow-arduino-examples/actions/workflows/test_examples.yml/badge.svg)](https://github.com/antmicro/tensorflow-arduino-examples/actions/workflows/test_examples.yml) | +Xtensa | [![Status](https://github.com/advaitjain/tensorflow/blob/local-continuous-builds/tensorflow/lite/micro/docs/local_continuous_builds/xtensa-build-status.svg)](https://github.com/advaitjain/tensorflow/tree/local-continuous-builds/tensorflow/lite/micro/docs/local_continuous_builds/xtensa.md) | + + +# Getting Help and Involved + +A +[TF Lite Micro Github issue](https://github.com/tensorflow/tensorflow/issues/new?labels=comp%3Amicro&template=70-tflite-micro-issue.md) +should be the primary method of getting in touch with the TensorFlow Lite Micro +(TFLM) team. + +The following resources may also be useful: + +1. SIG Micro [email group](https://groups.google.com/a/tensorflow.org/g/micro) + and + [monthly meetings](http://doc/1YHq9rmhrOUdcZnrEnVCWvd87s2wQbq4z17HbeRl-DBc). + +1. SIG Micro [gitter chat room](https://gitter.im/tensorflow/sig-micro). + +If you are interested in contributing code to TensorFlow Lite for +Microcontrollers then please read our [contributions guide](CONTRIBUTING.md). + +# Additional Documentation + +For developers that are interested in more details of the internals of the +project, we have additional documentation in the [docs](docs/) folder. + +* [Benchmarks](benchmarks/README.md) +* [Profiling](docs/profiling.md) +* [Memory Management](docs/memory_management.md) +* [Optimized Kernel Implementations](docs/optimized_kernel_implementations.md) +* [New Platform Support](docs/new_platform_support.md) +* [Software Emulation with Renode](docs/renode.md) + +# RFCs + +1. [Pre-allocated tensors](docs/rfc/001_preallocated_tensors.md) +1. [TensorFlow Lite for Microcontrollers Port of 16x8 Quantized Operators](docs/rfc/002_16x8_quantization_port.md) diff --git a/components/tflite/tensorflow/lite/micro/all_ops_resolver.cc b/components/tflite/tensorflow/lite/micro/all_ops_resolver.cc new file mode 100644 index 00000000..df05fdf1 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/all_ops_resolver.cc @@ -0,0 +1,100 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/all_ops_resolver.h" + +#include "tensorflow/lite/micro/kernels/micro_ops.h" + +namespace tflite { + +AllOpsResolver::AllOpsResolver() +{ + // Please keep this list of Builtin Operators in alphabetical order. + AddAbs(); + AddAdd(); + AddAddN(); + AddArgMax(); + AddArgMin(); + AddAveragePool2D(); + AddBatchToSpaceNd(); + AddCeil(); + AddConcatenation(); + AddConv2D(); + AddCos(); + AddCumSum(); + AddDepthToSpace(); + AddDepthwiseConv2D(); + AddDequantize(); + AddDetectionPostprocess(); + AddElu(); + AddEqual(); + AddEthosU(); + AddFloor(); + AddFloorDiv(); + AddFloorMod(); + AddFullyConnected(); + AddGreater(); + AddGreaterEqual(); + AddHardSwish(); + AddL2Normalization(); + AddL2Pool2D(); + AddLeakyRelu(); + AddLess(); + AddLessEqual(); + AddLog(); + AddLogicalAnd(); + AddLogicalNot(); + AddLogicalOr(); + AddLogistic(); + AddMaxPool2D(); + AddMaximum(); + AddMean(); + AddMinimum(); + AddMul(); + AddNeg(); + AddNotEqual(); + AddPack(); + AddPad(); + AddPadV2(); + AddPrelu(); + AddQuantize(); + AddReduceMax(); + AddRelu(); + AddRelu6(); + AddReshape(); + AddResizeBilinear(); + AddResizeNearestNeighbor(); + AddRound(); + AddRsqrt(); + AddShape(); + AddSin(); + AddSoftmax(); + AddSpaceToBatchNd(); + AddSpaceToDepth(); + AddSplit(); + AddSplitV(); + AddSqrt(); + AddSquare(); + AddSqueeze(); + AddStridedSlice(); + AddSub(); + AddSvdf(); + AddTanh(); + AddTransposeConv(); + AddTranspose(); + AddUnpack(); +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/all_ops_resolver.h b/components/tflite/tensorflow/lite/micro/all_ops_resolver.h new file mode 100644 index 00000000..f19a7fdf --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/all_ops_resolver.h @@ -0,0 +1,37 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_MICRO_ALL_OPS_RESOLVER_H_ +#define TENSORFLOW_LITE_MICRO_ALL_OPS_RESOLVER_H_ + +#include "tensorflow/lite/micro/compatibility.h" +#include "tensorflow/lite/micro/micro_mutable_op_resolver.h" + +namespace tflite { +// The magic number in the template parameter is the maximum number of ops that +// can be added to AllOpsResolver. It can be increased if needed. And most +// applications that care about the memory footprint will want to directly use +// MicroMutableOpResolver and have an application specific template parameter. +// The examples directory has sample code for this. +class AllOpsResolver : public MicroMutableOpResolver<128> { +public: + AllOpsResolver(); + +private: + TF_LITE_REMOVE_VIRTUAL_DELETE +}; + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_ALL_OPS_RESOLVER_H_ diff --git a/components/tflite/tensorflow/lite/micro/benchmarks/README.md b/components/tflite/tensorflow/lite/micro/benchmarks/README.md new file mode 100644 index 00000000..7ee59780 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/benchmarks/README.md @@ -0,0 +1,98 @@ +# TFLite for Microcontrollers Benchmarks + +These benchmarks are for measuring the performance of key models and workloads. +They are meant to be used as part of the model optimization process for a given +platform. + +## Table of contents + +- [Keyword Benchmark](#keyword-benchmark) +- [Person Detection Benchmark](#person-detection-benchmark) +- [Run on x86](#run-on-x86) +- [Run on Xtensa XPG Simulator](#run-on-xtensa-xpg-simulator) +- [Run on Sparkfun Edge](#run-on-sparkfun-edge) +- [Run on FVP based on Arm Corstone-300 software](#run-on-fvp-based-on-arm-corstone-300-software) + +## Keyword benchmark + +The keyword benchmark contains a model for keyword detection with scrambled +weights and biases. This model is meant to test performance on a platform only. +Since the weights are scrambled, the output is meaningless. In order to validate +the accuracy of optimized kernels, please run the kernel tests. + +## Person detection benchmark + +The keyword benchmark provides a way to evaluate the performance of the 250KB +visual wakewords model. + +## Run on x86 + +To run the keyword benchmark on x86, run + +``` +make -f tensorflow/lite/micro/tools/make/Makefile run_keyword_benchmark +``` + +To run the person detection benchmark on x86, run + +``` +make -f tensorflow/lite/micro/tools/make/Makefile run_person_detection_benchmark +``` + +## Run on Xtensa XPG Simulator + +To run the keyword benchmark on the Xtensa XPG simulator, you will need a valid +Xtensa toolchain and license. With these set up, run: + +``` +make -f tensorflow/lite/micro/tools/make/Makefile TARGET=xtensa OPTIMIZED_KERNEL_DIR=xtensa TARGET_ARCH= XTENSA_CORE= run_keyword_benchmark -j18 +``` + +## Run on Sparkfun Edge +The following instructions will help you build and deploy this benchmark on the +[SparkFun Edge development board](https://sparkfun.com/products/15170). + + +If you're new to using this board, we recommend walking through the +[AI on a microcontroller with TensorFlow Lite and SparkFun Edge](https://codelabs.developers.google.com/codelabs/sparkfun-tensorflow) +codelab to get an understanding of the workflow. + +Build binary using + +``` +make -f tensorflow/lite/micro/tools/make/Makefile TARGET=sparkfun_edge person_detection_benchmark_bin +``` + +Refer to flashing instructions in the [Person Detection Example](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/micro/examples/person_detection/README.md#running-on-sparkfun-edge). + +## Run on FVP based on Arm Corstone-300 software + +For more info about the Corstone-300 software see: +[tensorflow/lite/micro/cortex_m_corstone_300/README.md](../cortex_m_corstone_300/README.md). + +Disclaimer: Executing the benchmark test on the Corstone-300 software will +provide a general metric of instructions executed. The estimates are not cycle +accurate, however it aligns to instruction per cycle, and is a consistent +environment. This means it can detect if code changes changed performance. + +The person detection benchmark can also run with Ethos-U enabled, as the +downloaded model will be optimized for Ethos-U. For more info see: +[tensorflow/lite/micro/kernels/ethos_u/README.md](../kernels/ethos_u/README.md). + +To run the keyword benchmark on FVP: + +``` +make -j -f tensorflow/lite/micro/tools/make/Makefile TARGET=cortex_m_corstone_300 TARGET_ARCH=cortex-m55 run_keyword_benchmark +``` + +To run the person detection benchmark on FVP: + +``` +make -j -f tensorflow/lite/micro/tools/make/Makefile TARGET=cortex_m_corstone_300 TARGET_ARCH=cortex-m55 run_person_detection_benchmark +``` + +To run the person detection benchmark on FVP with Ethos-U: + +``` +make -j -f tensorflow/lite/micro/tools/make/Makefile CO_PROCESSOR=ethos_u TARGET=cortex_m_corstone_300 TARGET_ARCH=cortex-m55 run_person_detection_benchmark +``` diff --git a/components/tflite/tensorflow/lite/micro/benchmarks/keyword_benchmark.cc b/components/tflite/tensorflow/lite/micro/benchmarks/keyword_benchmark.cc new file mode 100644 index 00000000..1bde360c --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/benchmarks/keyword_benchmark.cc @@ -0,0 +1,111 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/benchmarks/keyword_scrambled_model_data.h" +#include "tensorflow/lite/micro/benchmarks/micro_benchmark.h" +#include "tensorflow/lite/micro/kernels/fully_connected.h" +#include "tensorflow/lite/micro/kernels/softmax.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/micro_mutable_op_resolver.h" +#include "tensorflow/lite/micro/micro_profiler.h" +#include "tensorflow/lite/micro/system_setup.h" + +/* + * Keyword Spotting Benchmark for performance optimizations. The model used in + * this benchmark only serves as a reference. The values assigned to the model + * weights and parameters are not representative of the original model. + */ + +namespace tflite { + +using KeywordBenchmarkRunner = MicroBenchmarkRunner; +using KeywordOpResolver = MicroMutableOpResolver<6>; + +#if defined(HEXAGON) +// TODO(b/174781826): reduce arena usage for optimized Hexagon kernels. +constexpr int kOptimizedKernelArenaIncrement = 21000; +#else +constexpr int kOptimizedKernelArenaIncrement = 0; +#endif + +// Create an area of memory to use for input, output, and intermediate arrays. +// Align arena to 16 bytes to avoid alignment warnings on certain platforms. +constexpr int kTensorArenaSize = 21 * 1024 + kOptimizedKernelArenaIncrement; +alignas(16) uint8_t tensor_arena[kTensorArenaSize]; + +uint8_t benchmark_runner_buffer[sizeof(KeywordBenchmarkRunner)]; +uint8_t op_resolver_buffer[sizeof(KeywordOpResolver)]; + +// Initialize benchmark runner instance explicitly to avoid global init order +// issues on Sparkfun. Use new since static variables within a method +// are automatically surrounded by locking, which breaks bluepill and stm32f4. +KeywordBenchmarkRunner *CreateBenchmarkRunner(MicroProfiler *profiler) +{ + // We allocate the KeywordOpResolver from a global buffer because the object's + // lifetime must exceed that of the KeywordBenchmarkRunner object. + KeywordOpResolver *op_resolver = new (op_resolver_buffer) KeywordOpResolver(); + op_resolver->AddFullyConnected(tflite::Register_FULLY_CONNECTED_INT8()); + op_resolver->AddQuantize(); + op_resolver->AddSoftmax(tflite::Register_SOFTMAX_INT8_INT16()); + op_resolver->AddSvdf(); + + return new (benchmark_runner_buffer) + KeywordBenchmarkRunner(g_keyword_scrambled_model_data, op_resolver, + tensor_arena, kTensorArenaSize, profiler); +} + +void KeywordRunNIerations(int iterations, const char *tag, + KeywordBenchmarkRunner &benchmark_runner, + MicroProfiler &profiler) +{ + int32_t ticks = 0; + for (int i = 0; i < iterations; ++i) { + benchmark_runner.SetRandomInput(i); + profiler.ClearEvents(); + benchmark_runner.RunSingleIteration(); + ticks += profiler.GetTotalTicks(); + } + MicroPrintf("%s took %d ticks (%d ms)", tag, ticks, TicksToMs(ticks)); +} + +} // namespace tflite + +int main(int argc, char **argv) +{ + tflite::InitializeTarget(); + tflite::MicroProfiler profiler; + + uint32_t event_handle = profiler.BeginEvent("InitializeKeywordRunner"); + tflite::KeywordBenchmarkRunner *benchmark_runner = + CreateBenchmarkRunner(&profiler); + profiler.EndEvent(event_handle); + profiler.Log(); + MicroPrintf(""); // null MicroPrintf serves as a newline. + + tflite::KeywordRunNIerations(1, "KeywordRunNIerations(1)", *benchmark_runner, + profiler); + profiler.Log(); + MicroPrintf(""); // null MicroPrintf serves as a newline. + + tflite::KeywordRunNIerations(10, "KeywordRunNIerations(10)", + *benchmark_runner, profiler); + MicroPrintf(""); // null MicroPrintf serves as a newline. + + benchmark_runner->PrintAllocations(); +} diff --git a/components/tflite/tensorflow/lite/micro/benchmarks/keyword_scrambled_model_data.cc b/components/tflite/tensorflow/lite/micro/benchmarks/keyword_scrambled_model_data.cc new file mode 100644 index 00000000..ff39ac22 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/benchmarks/keyword_scrambled_model_data.cc @@ -0,0 +1,2904 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/benchmarks/keyword_scrambled_model_data.h" + +// Keep model aligned to 8 bytes to guarantee aligned 64-bit accesses. +alignas(8) const unsigned char g_keyword_scrambled_model_data[] = { + 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, + 0x00, 0x00, 0x10, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0xa8, 0x85, 0x00, 0x00, 0x5c, 0x6f, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x48, 0x6f, 0x00, 0x00, 0x2c, 0x57, 0x00, 0x00, + 0x18, 0x53, 0x00, 0x00, 0x04, 0x52, 0x00, 0x00, 0xf0, 0x4d, 0x00, 0x00, + 0x9c, 0x4d, 0x00, 0x00, 0x88, 0x49, 0x00, 0x00, 0x74, 0x45, 0x00, 0x00, + 0x60, 0x44, 0x00, 0x00, 0x4c, 0x40, 0x00, 0x00, 0xf8, 0x3f, 0x00, 0x00, + 0xe4, 0x3b, 0x00, 0x00, 0xd0, 0x37, 0x00, 0x00, 0xbc, 0x36, 0x00, 0x00, + 0xa8, 0x32, 0x00, 0x00, 0x54, 0x32, 0x00, 0x00, 0x40, 0x2e, 0x00, 0x00, + 0x2c, 0x2a, 0x00, 0x00, 0x18, 0x29, 0x00, 0x00, 0x04, 0x25, 0x00, 0x00, + 0xb0, 0x24, 0x00, 0x00, 0x9c, 0x22, 0x00, 0x00, 0x88, 0x1a, 0x00, 0x00, + 0xf4, 0x19, 0x00, 0x00, 0xe0, 0x15, 0x00, 0x00, 0xcc, 0x0d, 0x00, 0x00, + 0x38, 0x0d, 0x00, 0x00, 0x24, 0x09, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, + 0x7c, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x8a, 0x90, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x34, 0xe1, 0x4f, 0xa1, 0x63, 0xa4, 0x62, 0xbf, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0x90, 0xff, 0xff, + 0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0xa3, 0xb2, 0x8f, 0xee, + 0x35, 0xe6, 0xf2, 0xcc, 0x68, 0xa0, 0x33, 0xc4, 0x7d, 0x4e, 0xbb, 0xa9, + 0x10, 0x32, 0x8e, 0x3d, 0x76, 0x14, 0x1c, 0x33, 0x0e, 0x77, 0xf7, 0xc8, + 0x7b, 0x45, 0xc7, 0xdb, 0xcf, 0x87, 0xc7, 0x70, 0xa9, 0x29, 0xfd, 0x70, + 0x32, 0x96, 0x35, 0x7d, 0xe9, 0xac, 0x6d, 0x9b, 0xfd, 0xe4, 0xbc, 0x4a, + 0x57, 0xcd, 0x43, 0xcc, 0x73, 0x72, 0xdf, 0x07, 0x68, 0xc5, 0x67, 0xbd, + 0x00, 0x00, 0x00, 0x00, 0xfa, 0x90, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, + 0x80, 0x00, 0x00, 0x00, 0xb0, 0xfb, 0x5f, 0xdf, 0x0e, 0xb9, 0xa2, 0xfd, + 0x66, 0x86, 0x13, 0x1b, 0x6d, 0x1d, 0x53, 0xdb, 0x83, 0xbf, 0x44, 0x29, + 0x3f, 0x93, 0xee, 0x42, 0x9a, 0xf4, 0x31, 0x6e, 0xc3, 0x15, 0x7e, 0x48, + 0x72, 0x50, 0xc3, 0x53, 0xef, 0x35, 0x1f, 0xc2, 0x29, 0x42, 0xb4, 0xd7, + 0x4b, 0xd7, 0x98, 0x60, 0xb9, 0x3e, 0xbb, 0x31, 0x35, 0xc3, 0xf6, 0x15, + 0x7a, 0x9a, 0x2c, 0xfd, 0xff, 0x04, 0xd9, 0x04, 0x57, 0x52, 0xae, 0x99, + 0xa3, 0x95, 0xae, 0x6a, 0x66, 0x52, 0x5f, 0x91, 0x17, 0x83, 0x0d, 0x27, + 0x16, 0x02, 0x06, 0x64, 0x80, 0x05, 0x99, 0x1c, 0x6c, 0xab, 0xb1, 0xa1, + 0x0e, 0x44, 0x1f, 0x63, 0xe9, 0xc1, 0xab, 0x8d, 0x08, 0x79, 0x56, 0xe0, + 0x90, 0xa5, 0xb8, 0x3b, 0xc4, 0x1e, 0xa5, 0x1f, 0x64, 0xe4, 0x0b, 0x72, + 0x62, 0x19, 0x5f, 0x66, 0xc0, 0x9b, 0x7b, 0xc4, 0xe5, 0x9f, 0x82, 0xa7, + 0x00, 0x00, 0x00, 0x00, 0x8a, 0x91, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x08, 0x00, 0x00, 0x3e, 0x3d, 0xf4, 0x61, 0x45, 0x2a, 0x48, 0x53, + 0x1f, 0x22, 0x74, 0x65, 0xea, 0x5a, 0x00, 0x83, 0x68, 0xf9, 0xbb, 0xa3, + 0xc2, 0x1a, 0x8f, 0xe1, 0xfb, 0x76, 0x6a, 0xe9, 0x1a, 0x0e, 0x4d, 0x32, + 0xc6, 0xf3, 0x8d, 0x85, 0x54, 0xa1, 0xe9, 0xb8, 0x35, 0xee, 0xba, 0x53, + 0x40, 0xa2, 0xea, 0x7f, 0xc3, 0x99, 0x71, 0x17, 0xdd, 0xd5, 0xfe, 0xdf, + 0x5e, 0x15, 0xa0, 0x73, 0xf8, 0x78, 0x49, 0x73, 0xcc, 0xf0, 0x18, 0x12, + 0x06, 0x81, 0xd6, 0x19, 0x2c, 0xa8, 0xd7, 0x80, 0x19, 0x19, 0xbf, 0x1e, + 0x50, 0xb1, 0xfb,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, 0x3b, 0x4f, 0xc7, 0x71, 0xf1, + 0x98, 0xe6, 0xb0, 0x96, 0x25, 0xd7, 0xac, 0x75, 0xfc, 0x92, 0xe0, 0x69, + 0x72, 0x37, 0x8d, 0x40, 0x31, 0xaa, 0x2c, 0x86, 0xfb, 0x95, 0x3f, 0x9c, + 0x23, 0xd4, 0x39, 0x99, 0xff, 0xea, 0x95, 0x79, 0xb9, 0x2e, 0xb0, 0x33, + 0xf1, 0xe8, 0xd0, 0x42, 0xb5, 0x70, 0x5c, 0xca, 0x69, 0x48, 0x28, 0x23, + 0x58, 0xb4, 0x07, 0xfc, 0x3e, 0x15, 0x29, 0x00, 0xa9, 0x22, 0x44, 0x70, + 0xd0, 0xc7, 0x01, 0x0d, 0x3e, 0xfc, 0x57, 0xb7, 0x54, 0x3a, 0xc3, 0x43, + 0xd6, 0x2f, 0x55, 0x09, 0x52, 0x4a, 0x6b, 0x8e, 0x4c, 0x82, 0xbb, 0x4e, + 0x3e, 0x38, 0xe1, 0x9e, 0x72, 0x83, 0xec, 0x40, 0xf5, 0xf7, 0x0e, 0x3c, + 0x24, 0xed, 0xda, 0xf2, 0x39, 0x6c, 0xad, 0xeb, 0xff, 0xfb, 0x4a, 0x38, + 0x50, 0x49, 0x28, 0x3d, 0x05, 0xb2, 0x98, 0x44, 0x2b, 0x61, 0xa2, 0x9b, + 0x3a, 0x3c, 0xad, 0xd9, 0x8c, 0xef, 0x3c, 0x72, 0x50, 0x74, 0x13, 0x80, + 0xc4, 0x7e, 0x6e, 0xf3, 0xc9, 0xdf, 0x63, 0xf6, 0x41, 0xb2, 0x08, 0x78, + 0x9b, 0x7c, 0xa9, 0x13, 0xd1, 0x21, 0xe7, 0x5e, 0x6a, 0x0d, 0x64, 0xf7, + 0x52, 0x75, 0xf2, 0x80, 0x69, 0xbe, 0x43, 0xf8, 0xd4, 0xad, 0x49, 0xfc, + 0x97, 0x76, 0x1c, 0xb6, 0x43, 0x9e, 0xcb, 0x45, 0x4d, 0x75,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 0x96, 0xd7, 0xc1, 0xfe, 0x9b, 0xc8, 0xfb, + 0x86, 0x5a, 0xad, 0xce, 0xf8, 0xd5, 0x32, 0x62, 0x96, 0x63, 0xaf, 0x4c, + 0x4a, 0xae, 0xec, 0x26, 0x3d, 0x84, 0x69, 0x50, 0x5f, 0x37, 0x9b, 0x29, + 0xac, 0x15, 0x76, 0x3d, 0x33, 0x96, 0x06, 0xde, 0xc1, 0x6d, 0xa2, 0xc7, + 0xc3, 0x8a, 0x20, 0x2e, 0xf7, 0x08, 0x55, 0x83, 0x23, 0x9c, 0x23, 0x2d, + 0x3a, 0xa1, 0x32, 0xbc, 0x47, 0x48, 0xd5, 0x6a, 0x71, 0xb9, 0xcc, 0x2d, + 0x99, 0xa0, 0x37, 0x07, 0x46, 0x45, 0xbe, 0xf0, 0x27, 0x5a, 0x25, 0x72, + 0x58, 0x47, 0x6d, 0xbf, 0x23, 0xdc, 0x48, 0x44, 0x45, 0x95, 0xb1, 0x62, + 0xf1, 0x7e, 0x4c, 0x95, 0x1c, 0xb4, 0x17, 0x8b, 0x59, 0x2e, 0xf3, 0x4f, + 0x45, 0x3b, 0x5d, 0x67, 0x92, 0x52, 0xd8, 0xc1, 0x91, 0xfa, 0x53, 0xaa, + 0x87, 0xc0, 0xa7, 0xb0, 0x9f, 0x10, 0xe8, 0xac, 0x45, 0x52, 0xbb, 0x17, + 0xee, 0xf6, 0x18, 0xbe, 0x02, 0x70, 0xce, 0x79, 0x66, 0x72, 0xf9, 0xf6, + 0xca, 0x66, 0xff, 0xa4, 0x9a, 0xd9, 0xb7, 0x07, 0xa9, 0xc1, 0x23, 0x7e, + 0x7b, 0x9c, 0xe3, 0x02, 0x7a, 0xcc, 0xa3, 0x67, 0xb7, 0xb0, 0x37, 0xba, + 0xae, 0x12, 0xda, 0x48, 0x6e, 0x7f, 0xde, 0x5f, 0x75, 0x15, 0xca, 0xd2, + 0x46, 0xdd, 0xb0, 0x82, 0xbf, 0x6d, 0xe9, 0x51, 0x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 0xed, 0x2e, + 0x29, 0x62, 0x7b, 0xb0, 0xe6, 0xa3, 0xb4, 0x61, 0x73, 0x10, 0xff, 0x0e, + 0x0c, 0x98, 0x74, 0xef, 0xbb, 0xc4, 0xca, 0x03, 0x88, 0xa4, 0x96, 0x61, + 0xef, 0x36, 0x6d, 0xa2, 0xb1, 0xc8, 0xf0, 0xac, 0xf1, 0xb2, 0x08, 0x56, + 0xc7, 0x99, 0xcf, 0xae, 0x0a, 0x37, 0x85, 0x60, 0x78, 0x2d, 0x14, 0xda, + 0xb1, 0xa7, 0x00, 0xb6, 0x00, 0x04, 0x76, 0x80, 0x0e, 0x9f, 0x2a, 0x30, + 0x8b, 0x85, 0xd9, 0xc1, 0xaf, 0xee, 0x27, 0x80, 0x20, 0xed, 0xef, 0x25, + 0x5c, 0x98, 0x6b, 0xcc, 0xf8, 0x72, 0xfb, 0x3f, 0x13, 0xe6, 0x9b, 0x47, + 0xee, 0xa1, 0x18, 0x55, 0xa0, 0x68, 0xbe, 0xd4, 0x21, 0x59, 0x72, 0xa8, + 0xa4, 0xd2, 0x33, 0x57, 0x50, 0xfc, 0x6b, 0xa8, 0x49, 0x1b, 0x74, 0xdb, + 0x5a, 0x16, 0xb8, 0x52, 0x0c, 0xda, 0xa0, 0xa3, 0xff, 0x33, 0x56, 0x82, + 0x0f, 0x0a, 0x90, 0x82, 0xee, 0xf1, 0x1b, 0xb3, 0x05, 0x44, 0x39, 0x01, + 0xf7, 0x1e, 0xff, 0xcb, 0xea, 0xd0, 0xb6, 0x20, 0xbc, 0x84, 0xb1, 0xf9, + 0xa2, 0xc1, 0x56, 0xe6, 0xfa, 0x47, 0xc9, 0xfd, 0x45, 0x77, 0x51, 0x8e, + 0x01, 0xe4, 0x17, 0x20, 0x6f, 0x99, 0xe3, 0x90, 0x2f, 0xcc, 0xaf, 0xd9, + 0x61, 0x32, 0x91, 0x62, 0x58, 0xf4, 0x98, 0xf5, 0xf4, 0xeb, 0x13, 0xeb, + 0xdc, 0x8a, 0xac, 0xb2, 0x9e, 0xcf, 0xe7, 0xa7, 0xd4, 0x97, 0x22, 0x12, + 0x08, 0x10, 0x6d, 0x40, 0xea, 0x26, 0xea, 0x42, 0x29, 0x6e, 0x75, 0x62, + 0x47, 0x08, 0x17, 0xa8, 0x69, 0x0f, 0xf7, 0x35, 0x59, 0x23, 0x86, 0x83, + 0xfd, 0xb5, 0x61, 0x98, 0x9c, 0x4d, 0x37, 0xda, 0x9f, 0xfc, 0xfb, 0x16, + 0xb7, 0x6c, 0x52, 0xee, 0xa8, 0x9c, 0x3e, 0x93, 0x43, 0xc5, 0x2b, 0xd4, + 0xd0, 0x9f, 0x69, 0x2c, 0xc9, 0x1f, 0x2e, 0xdf, 0x5b, 0xe6, 0xc6, 0x5f, + 0x71, 0xd1, 0xd7, 0xb2, 0x8f, 0x3a, 0xba, 0x60, 0x75, 0x3d, 0x34, 0x41, + 0x43, 0x9b, 0x13, 0xc0, 0x3b, 0x30, 0xc5, 0xe9, 0x84, 0x81, 0xde, 0x85, + 0x4e, 0x65, 0x7b, 0x21, 0x37, 0xb8, 0xef, 0x24, 0x19, 0xaa, 0x26, 0x0c, + 0x27, 0xa7, 0xd9, 0x29, 0x47, 0x1a, 0x15, 0x42, 0x1e, 0x30, 0x79, 0x79, + 0x96, 0x09, 0x62, 0x26, 0xad, 0x98, 0x8b, 0xcb, 0x3d, 0xeb, 0x66, 0x83, + 0x77, 0xd9, 0x79, 0x4d, 0x05, 0x81, 0x72, 0xe9, 0xe0, 0x6f, 0x13, 0x00, + 0x7e, 0xa3, 0x92, 0x82, 0x1c, 0x90, 0x83, 0x4b, 0x15, 0x97, 0x0f, 0x92, + 0xe2, 0xd3, 0x3d, 0xd7, 0x6c, 0xb9, 0x60, 0x9a, 0x23, 0x52, 0xbe, 0x59, + 0xc9, 0x36, 0x9e, 0xf7, 0x77, 0x09, 0x79, 0x01, 0xcc, 0xec, 0x17, 0xd1, + 0x74, 0xbc, 0x58, 0x65, 0x45, 0x3c, 0x86, 0xf1, 0xbc, 0xbd, 0x95, 0x54, + 0x46, 0x45, 0x7b, 0x4c, 0xa2, 0xea, 0x2a, 0x6e, 0xa8, 0xd1, 0x66, 0x03, + 0xb2, 0x6a, 0xe0, 0xd3, 0x07, 0x8d, 0xe0, 0x09, 0x81, 0x42, 0xe3, 0x97, + 0xc4, 0xe7, 0x37, 0xc5, 0x82, 0xcf, 0xb1, 0xec, 0xba, 0xbd, 0xf4, 0xb6, + 0x41, 0xb2, 0xb8, 0xa6, 0x3a, 0x85, 0x4b, 0x4f, 0x46, 0x48, 0xe9, 0x9b, + 0x72, 0xf5, 0xb0, 0x64, 0x66, 0x75, 0x42, 0xb4, 0x00, 0xbe, 0x11, 0x6d, + 0x86, 0x93, 0x07, 0x50, 0xa7, 0xef, 0x55, 0x42, 0xcf, 0xe8, 0x61, 0xd0, + 0x9b, 0x11, 0x84, 0x8c, 0x74, 0xe4, 0xb8, 0x3f, 0x48, 0xb3, 0x61, 0xe3, + 0xea, 0x66, 0x86, 0x94, 0x95, 0x12, 0x77, 0x26, 0x75, 0x30, 0xb5, 0xd3, + 0x7a, 0xad, 0x2d, 0x58, 0x46, 0x1b, 0x4b, 0xd9, 0x2d, 0x1e, 0x0b, 0xff, + 0xd7, 0x03, 0x56, 0x3b, 0xbd, 0x65, 0xb0, 0xf9, 0xfe, 0x43, 0x1c, 0x9c, + 0x18, 0x82, 0x78, 0x5e, 0x06, 0x02, 0x21, 0x70, 0xb2, 0x7f, 0xb5, 0x63, + 0x71, 0x85, 0x95, 0x79, 0xae, 0x1e, 0xc6, 0x62, 0x7a, 0x7c, 0x63, 0x46, + 0x70, 0x1c, 0x58, 0x72, 0x1d, 0xde, 0xca, 0xb4, 0xfc, 0xc8, 0x56, 0x38, + 0x32, 0xf4, 0x0b, 0x56, 0x87, 0x6b, 0x5b, 0x53, 0xd2, 0x2c, 0x35, 0xef, + 0x5b, 0x33, 0x59, 0x13, 0x76, 0x82, 0x30, 0x80, 0x23, 0x10, 0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, 0xd3, 0xf7, 0x4a, 0x15, 0xcc, 0x27, 0x26, 0x00, 0xba, 0xf3, + 0xfa, 0x4e, 0xc6, 0xe9, 0xc3, 0x05, 0x3d, 0x3a, 0x89, 0x96, 0x7d, 0x41, + 0xac, 0xca, 0x28, 0x7f, 0x69, 0x02, 0x40, 0x03, 0x93, 0x86, 0x85, 0x85, + 0x73, 0x00, 0x09, 0x5a, 0xcf, 0x5f, 0x1d, 0xaa, 0x46, 0x41, 0x9d, 0x08, + 0xbf, 0xea, 0x45, 0x9b, 0x93, 0xda, 0x9e, 0x81, 0x00, 0x00, 0x00, 0x00, + 0x3a, 0x9e, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, + 0x6a, 0x1f, 0x9b, 0x03, 0xdd, 0xe4, 0x16, 0x07, 0x7f, 0x5b, 0xb0, 0xee, + 0xac, 0x55, 0xc4, 0x50, 0xe6, 0x2b, 0x17, 0xed, 0x7f, 0x50, 0x4d, 0x71, + 0x73, 0xae, 0xe0, 0x4d, 0xce, 0x08, 0xd9, 0x8b, 0x83, 0x2c, 0x01, 0x48, + 0x02, 0xd3, 0xbb, 0xca, 0x86, 0xd7, 0xca, 0x5f, 0xc7, 0xce, 0x59, 0xdf, + 0xc1, 0xcc, 0xf7, 0x7b, 0x54, 0xf8, 0x0d, 0x4f, 0x81, 0x9e, 0x50, 0x6a, + 0x65, 0x66, 0x4a, 0xec, 0x7a, 0x1b, 0x92, 0xb2, 0x39, 0x8f, 0x5d, 0x41, + 0x33, 0xcf, 0xe6, 0x1b, 0x34, 0x5d, 0xe1, 0xf6, 0xef, 0xcb, 0xa0, 0x55, + 0x7e, 0x1f, 0x45, 0x38, 0xb9, 0x56, 0x15, 0x3b, 0x70, 0xab, 0xc8, 0x2f, + 0x1c, 0xb9, 0x7d, 0x37, 0xe1, 0xb4, 0x03, 0x44, 0x5a, 0xf6, 0x57, 0x97, + 0x03, 0x54, 0x4c, 0x22, 0x88, 0xc3, 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3, 0x95, 0x95, 0x6f, 0xd7, + 0xae, 0x80, 0xc9, 0xd5, 0x95, 0xb7, 0xcf, 0xe2, 0x9d, 0x98, 0x65, 0x80, + 0xfd, 0x2e, 0xee, 0x46, 0x5e, 0x46, 0x8c, 0xde, 0x52, 0xb4, 0xdc, 0xce, + 0xa8, 0xab, 0x4e, 0x0c, 0x12, 0x9f, 0x89, 0x9c, 0x84, 0x80, 0xfe, 0x08, + 0x64, 0x12, 0x12, 0x95, 0x62, 0xea, 0x65, 0xcc, 0x34, 0x80, 0xcf, 0x92, + 0x5f, 0xc2, 0xae, 0x76, 0xe7, 0x2f, 0xbb, 0xa8, 0xdb, 0x6a, 0x66, 0x60, + 0xaf, 0x88, 0xba, 0x65, 0x32, 0xcf, 0xf7, 0x6e, 0xd8, 0xd0, 0x69, 0xb0, + 0x12, 0x23, 0xd6, 0xc2, 0x32, 0xe5, 0x8e, 0x51, 0xc5, 0x61, 0x28, 0x45, + 0xf7, 0xf9, 0xea, 0x73, 0xce, 0x04, 0x2d, 0x56, 0x43, 0x10, 0x8b, 0x4f, + 0x6b, 0xfa, 0x32, 0xa8, 0x92, 0x8f, 0xd9, 0xb4, 0xfd, 0xa4, 0x74, 0xa8, + 0xea, 0xca, 0xd3, 0x84, 0xbb, 0x5a, 0x34, 0x57, 0xf9, 0xda, 0x25, 0x40, + 0x1f, 0x5e, 0xc2, 0x66, 0x43, 0x05, 0xdd, 0x13, 0x88, 0x91, 0x60, 0xa1, + 0x75, 0xd3, 0xc4, 0x27, 0xff, 0xda, 0x24, 0x3d, 0xd9, 0xd7, 0x47, 0x46, + 0x30, 0xd0, 0x76, 0xc4, 0x9e, 0x97, 0xe3, 0x43, 0xd7, 0x45, 0xaf, 0x49, + 0x36, 0xf2, 0x18, 0xdd, 0x3f, 0x86, 0x9a, 0xec, 0x9a, 0x70, 0xeb, 0x5a, + 0xe2, 0xa0, 0x4b, 0x45, 0x21, 0xb3, 0x32, 0x3d, 0x0c, 0x8c, 0x03, 0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0x3a, 0x21, 0xa5, 0x0a, 0x1c, 0xd9, + 0xa9, 0x78, 0xbb, 0xc9, 0x01, 0x65, 0xe4, 0xb3, 0x48, 0xb8, 0xe1, 0xe7, + 0xb5, 0xf4, 0x4e, 0xa9, 0xb6, 0xe2, 0x5b, 0xeb, 0xf5, 0x76, 0x06, 0x1a, + 0xd9, 0x08, 0x40, 0xff, 0x72, 0xb2, 0xe3, 0x01, 0x50, 0xb1, 0xad, 0xb3, + 0xa3, 0xf6, 0xef, 0x72, 0x05, 0x0c, 0xf4, 0xce, 0x24, 0x2c, 0x63, 0x89, + 0x63, 0x9e, 0x21, 0xb8, 0xb0, 0xbe, 0xc7, 0x45, 0xae, 0x47, 0x2b, 0x9e, + 0x61, 0x81, 0x4c, 0x76, 0x96, 0x7b, 0x18, 0x37, 0x74, 0xcb, 0x00, 0xef, + 0x38, 0x72, 0x24, 0x0a, 0x63, 0xc1, 0x64, 0xd6, 0x41, 0xc8, 0x6a, 0xf1, + 0xe7, 0x11, 0x20, 0x4b, 0xc2, 0x95, 0x70, 0xb8, 0xf8, 0x8f, 0xd9, 0xae, + 0x8c, 0x12, 0xd8, 0x6f, 0x63, 0x30, 0xca, 0x56, 0x46, 0x11, 0xda, 0x49, + 0x1f, 0x84, 0x3d, 0xae, 0xab, 0x78, 0x29, 0x02, 0x6c, 0x43, 0xa3, 0xef, + 0x9d, 0x97, 0x59, 0x15, 0x53, 0xcd, 0xc7, 0x47, 0x65, 0x30, 0xc7, 0xae, + 0x31, 0x4a, 0x41, 0xb4, 0x66, 0x9c, 0xbb, 0x51, 0x0b, 0xbd, 0xe2, 0x7d, + 0x41, 0x2c, 0xd0, 0x75, 0x57, 0x93, 0xce, 0x2e, 0xeb, 0x31, 0x7f, 0x56, + 0xb2, 0xa4, 0x2b, 0x9f, 0xcc, 0xef, 0x6f, 0xf0, 0x77, 0x19, 0xad, 0x4d, + 0x2e, 0x37, 0x00, 0x75, 0x53, 0xae, 0x22, 0x44, 0x69, 0x1c,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 0xc6, + 0xa6, 0xeb, 0x2f, 0xdf, 0x2f, 0x0d, 0x2f, 0xd3, 0x6e, 0x70, 0x71, 0xfe, + 0xf0, 0x2e, 0xe9, 0x84, 0xd3, 0xc1, 0xd1, 0x70, 0x4b, 0x8f, 0x7b, 0x60, + 0xb0, 0xb7, 0xe3, 0x79, 0x52, 0x6a, 0x6b, 0x26, 0x03, 0x8f, 0x6a, 0x0f, + 0x8d, 0x85, 0xd7, 0x5f, 0xf7, 0x39, 0x31, 0x0e, 0x26, 0x73, 0x84, 0x3f, + 0x9b, 0x10, 0x6f, 0x29, 0x63, 0x14, 0x36, 0xa2, 0xec, 0x44, 0x7d, 0x84, + 0xc6, 0x4a, 0xec, 0xfe, 0xac, 0xcb, 0xe4, 0xfa, 0xf6, 0x68, 0x83, 0x68, + 0xe0, 0x8f, 0xd3, 0x8a, 0x60, 0x73, 0xf1, 0x5c, 0x71, 0x02, 0x0c, 0xa2, + 0x88, 0x2c, 0xa2, 0x35, 0x35, 0x5c, 0x3f, 0xb1, 0xbe, 0xb3, 0x6b, 0x5c, + 0xe1, 0x78, 0x75, 0x40, 0x20, 0x87, 0x67, 0xca, 0x07, 0x1c, 0x9c, 0x02, + 0xc7, 0xf2, 0x9d, 0x1c, 0xda, 0x1b, 0x86, 0x1b, 0x00, 0x00, 0x00, 0x00, + 0x4a, 0xa6, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, + 0x93, 0xca, 0x30, 0xae, 0xea, 0x26, 0x6a, 0x1b, 0x15, 0x46, 0x0a, 0xe3, + 0x57, 0x23, 0x4c, 0x0c, 0x98, 0x8e, 0x3e, 0xbb, 0x43, 0x14, 0x73, 0xdf, + 0x17, 0x91, 0xe2, 0xee, 0x39, 0xf9, 0xc2, 0x2f, 0xdc, 0xad, 0x0e, 0x00, + 0xf5, 0xdd, 0xe3, 0x97, 0xba, 0x8c, 0xee, 0x53, 0xc4, 0x70, 0x37, 0x46, + 0xcf, 0x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e6, 0x22, 0xaf, 0x76, + 0xd2, 0x90, 0x00, 0x05, 0x46, 0xb8, 0xa4, 0xf5, 0x4c, 0xaa, 0x04, 0x63, + 0xa0, 0x57, 0xe0, 0x20, 0x6e, 0x1a, 0xed, 0x21, 0x86, 0xd0, 0x38, 0x5b, + 0xe6, 0xa7, 0xb0, 0xe7, 0x75, 0xe3, 0x76, 0xb3, 0x15, 0x8b, 0xdc, 0x10, + 0x52, 0x15, 0x21, 0x7b, 0xd0, 0xc4, 0x75, 0x26, 0x1d, 0x6e, 0x0d, 0x4c, + 0x08, 0x5b, 0x95, 0x9a, 0xd0, 0xda, 0xbe, 0x23, 0x98, 0xde, 0x60, 0x2a, + 0xe9, 0xa4, 0x92, 0xf0, 0x92, 0x84, 0xdc, 0x86, 0x60, 0xf5, 0x23, 0x31, + 0xf5, 0xe9, 0xd6, 0x00, 0xc1, 0x78, 0xab, 0x05, 0x94, 0xd3, 0x47, 0x4d, + 0x32, 0x0f, 0x82, 0xa0, 0x99, 0x0b, 0xfe, 0x6b, 0x58, 0xf9, 0x24, 0xf6, + 0x17, 0xa0, 0x5f, 0x24, 0x6a, 0xc6, 0x01, 0xa8, 0xfa, 0xca, 0xdc, 0xb6, + 0x83, 0xcb, 0xd2, 0x3b, 0xb7, 0x0b, 0x04, 0x3e, 0x6a, 0xaf, 0x23, 0x17, + 0x3e, 0x14, 0xce, 0x52, 0x1c, 0xe3, 0x06, 0x66, 0x29, 0x17, 0x6f, 0x7e, + 0x66, 0x06, 0xa9, 0x68, 0x7f, 0xca, 0xad, 0xa8, 0xb7, 0x2d, 0xa4, 0x5d, + 0xa6, 0x16, 0xcd, 0xed, 0xee, 0x14, 0x96, 0xc8, 0x12, 0x69, 0x4e, 0x70, + 0x72, 0x2a, 0x75, 0x82, 0x08, 0x3f, 0x3e, 0x27, 0xa0, 0xea, 0x43, 0x84, + 0xa9, 0x9a, 0x91, 0x87, 0x4f, 0x20, 0x61, 0x55, 0x8d, 0x70, 0xad, 0x6c, + 0x59, 0x5d, 0x13, 0x80, 0xbb, 0x52, 0x55, 0x81, 0x8b, 0x59, 0x94, 0x0f, + 0xc2, 0x54, 0x79, 0x59, 0xe8, 0x9d, 0x58, 0xe5, 0x91, 0x10, 0xb3, 0xef, + 0x1c, 0xda, 0xaa, 0xdd, 0x91, 0x0b, 0xb0, 0x14, 0x3b, 0xad, 0x02, 0x98, + 0x40, 0x3c, 0x54, 0xc4, 0x23, 0xb9, 0x40, 0x54, 0x7e, 0x88, 0x10, 0x3e, + 0x24, 0xe5, 0xf6, 0xdf, 0x5c, 0x9e, 0x7a, 0x9f, 0xd0, 0xff, 0x5e, 0x9c, + 0xb6, 0x30, 0x17, 0x94, 0x00, 0x00, 0x00, 0x00, 0x5a, 0xaa, 0xff, 0xff, + 0x04, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x96, 0xff, 0x2f, 0x01, + 0x60, 0x2c, 0x1b, 0xe3, 0xc6, 0xcb, 0xa4, 0x41, 0xa1, 0x44, 0x13, 0x14, + 0xe2, 0x44, 0x77, 0x1c, 0x96, 0xe8, 0xe6, 0x4f, 0x70, 0x99, 0x3a, 0xef, + 0xa1, 0x6f, 0x1f, 0x7f, 0xb9, 0xe9, 0x1e, 0x35, 0x37, 0x5b, 0x94, 0x90, + 0x78, 0xcc, 0x8d, 0xcd, 0x6c, 0x9f, 0xf6, 0x73, 0xed, 0x23, 0xa2, 0x28, + 0x64, 0x58, 0x50, 0x64, 0x05, 0xbc, 0xc9, 0x9b, 0x5a, 0xec, 0x3f, 0x2b, + 0x61, 0xcf, 0xa7, 0x35, 0x56, 0x8c, 0x77, 0x68, 0xd6, 0xcf, 0x9b, 0xc5, + 0x62, 0xee, 0x3a, 0xb2, 0xfe, 0x78, 0xba, 0x02, 0xe7, 0x26, 0x8a, 0x89, + 0x30, 0x19, 0xcc, 0xb0, 0x98, 0xbf, 0x30, 0x2c, 0xae, 0x13, 0x6c, 0x93, + 0x86, 0x19, 0x84, 0x13, 0x01, 0x2f, 0x39, 0x4e, 0x33, 0xd1, 0x15, 0x99, + 0xf7, 0x1e, 0xb8, 0x86, 0xdb, 0xb6, 0xf9, 0x56, 0x42, 0x0e, 0x4a, 0xb1, + 0x5e, 0xf0, 0x9a, 0x06, 0x00, 0x00, 0x00, 0x00, 0xea, 0xaa, 0xff, 0xff, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0xcd, 0xde, 0xad, 0x40, + 0x34, 0xcd, 0x79, 0x0a, 0x29, 0x84, 0x05, 0x3f, 0xb5, 0xbe, 0x49, 0x84, + 0x43, 0xcc, 0xa6, 0xe3, 0xe9, 0xdc, 0x84, 0x14, 0xe7, 0xb3, 0x1b, 0x96, + 0xe8, 0xda, 0x35, 0x15, 0x38, 0xf5, 0xb3, 0xb5, 0x91, 0xc3, 0xc3, 0x94, + 0xc6, 0x79, 0xeb, 0xf5, 0x22, 0x78, 0xf0, 0x0b, 0xda, 0xb0, 0x91, 0xa7, + 0x43, 0x71, 0x8e, 0xa6, 0x52, 0x0f, 0x81, 0x06, 0xc8, 0xdf, 0xb5, 0x1f, + 0x92, 0xb0, 0xfe, 0x93, 0x38, 0x4c, 0xf4, 0x17, 0x66, 0x31, 0xea, 0x08, + 0x72, 0xb9, 0xaa, 0xfd, 0x40, 0x8d, 0xbf, 0x56, 0x19, 0xb1, 0xb5, 0x8e, + 0x4e, 0x4e, 0x73, 0x7f, 0x4b, 0x0c, 0x70, 0x94, 0x7c, 0x9f, 0xfc, 0x23, + 0x35, 0xba, 0xd2, 0x23, 0x88, 0x1d, 0x83, 0x28, 0x45, 0xd7, 0x1b, 0x63, + 0xfb, 0x36, 0x86, 0x06, 0xf3, 0x99, 0x81, 0x6e, 0xd7, 0xf1, 0xd4, 0x53, + 0x6d, 0x30, 0x3c, 0x8d, 0xac, 0xc6, 0x9a, 0xd5, 0xe8, 0x4f, 0x11, 0x58, + 0xba, 0xfd, 0x67, 0x06, 0xe7, 0x1a, 0xb4, 0xa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 0x52, + 0x52, 0x77, 0xe1, 0x5e, 0xa6, 0x21, 0xe4, 0xad, 0x59, 0xca, 0xa3, 0x77, + 0xea, 0x66, 0x28, 0x15, 0x73, 0x3a, 0xfd, 0xe4, 0x75, 0x46, 0x99, 0x59, + 0x5c, 0x7a, 0x9b, 0x9d, 0x11, 0xb4, 0x76, 0x45, 0x06, 0x45, 0x41, 0x1e, + 0x94, 0xb7, 0xd9, 0xb8, 0xcb, 0xbf, 0x71, 0xec, 0xba, 0x9f, 0x4a, 0x1b, + 0xbc, 0xfd, 0x5c, 0x06, 0x64, 0xfd, 0x31, 0x52, 0xc0, 0xe4, 0xa7, 0x21, + 0x2f, 0x22, 0x92, 0xf0, 0x51, 0x33, 0x92, 0x1d, 0x40, 0x3c, 0x01, 0x81, + 0x3b, 0xa8, 0x2e, 0x4e, 0xb6, 0x60, 0xcd, 0xd4, 0x36, 0x3b, 0x2e, 0x1d, + 0x5e, 0x43, 0xd9, 0x94, 0xf1, 0x51, 0xd3, 0x59, 0x94, 0x6a, 0xd5, 0x5f, + 0x1f, 0xd3, 0xa6, 0x55, 0xda, 0x15, 0xf1, 0x3e, 0x2c, 0x60, 0xb8, 0xc3, + 0xda, 0x0e, 0x56, 0x53, 0xea, 0xcd, 0x39, 0x27, 0x94, 0x86, 0x94, 0xb2, + 0x5b, 0xd8, 0x9a, 0x12, 0x94, 0xb0, 0xb6, 0x77, 0x28, 0xba, 0xde, 0xb6, + 0x60, 0x4d, 0x2b, 0x6e, 0x3d, 0xf6, 0xf1, 0x48, 0xf7, 0x77, 0xa1, 0x49, + 0xe0, 0x9f, 0x1e, 0xc9, 0xe6, 0xcb, 0x95, 0x26, 0x61, 0x5a, 0xc9, 0xed, + 0x49, 0x40, 0x17, 0x57, 0x15, 0xfc, 0x3c, 0xb8, 0x28, 0x79, 0xb8, 0x42, + 0x2a, 0xf9, 0xd4, 0x19, 0xb9, 0x5f, 0x41, 0xc2, 0x25, 0xd7, 0x88, 0x34, + 0xb3, 0x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, 0x44, 0x13, 0xf7, 0x00, 0xa6, 0x20, 0xad, 0x65, + 0x1d, 0xb7, 0x96, 0x2f, 0x79, 0x7b, 0x04, 0xa3, 0x10, 0x90, 0x29, 0x8c, + 0xa3, 0x2e, 0x14, 0x39, 0xd3, 0xe4, 0x6e, 0x46, 0xf7, 0x6e, 0x96, 0x68, + 0xd9, 0xef, 0x45, 0xf7, 0x3c, 0xcd, 0xc7, 0xca, 0x33, 0x64, 0x8e, 0x31, + 0x80, 0x48, 0x7b, 0x7c, 0x81, 0x9a, 0x48, 0xff, 0xd5, 0x0d, 0x74, 0xe7, + 0x77, 0x46, 0x61, 0x9b, 0xde, 0xed, 0x83, 0xe9, 0x4f, 0x92, 0xc1, 0x16, + 0xad, 0x44, 0x40, 0x23, 0xce, 0x04, 0x31, 0xbf, 0xcf, 0xe2, 0x5a, 0x68, + 0x5a, 0xf4, 0x0f, 0xe1, 0x87, 0x79, 0xb0, 0x32, 0x0b, 0x09, 0x6b, 0x72, + 0x2b, 0x16, 0x06, 0x67, 0x82, 0x0b, 0x92, 0x35, 0xdb, 0x4c, 0xe2, 0x4a, + 0x60, 0x99, 0xaf, 0x52, 0x10, 0x4b, 0xa5, 0xcf, 0xac, 0x66, 0x49, 0x56, + 0x04, 0xc0, 0xd6, 0x6f, 0x62, 0x53, 0x6f, 0xcb, 0x62, 0xe9, 0xa5, 0xca, + 0x18, 0x8e, 0x86, 0x3f, 0x36, 0xfd, 0xea, 0x55, 0x16, 0x6d, 0x6c, 0x6a, + 0x8f, 0xa7, 0x9c, 0x70, 0x15, 0xd7, 0xf4, 0x57, 0x68, 0x04, 0x84, 0x60, + 0x3b, 0xb0, 0x32, 0xc4, 0xea, 0x9d, 0x70, 0xb9, 0xa6, 0x34, 0xe5, 0xfa, + 0xa1, 0x24, 0x54, 0x7f, 0xef, 0xac, 0xb4, 0x5f, 0xa0, 0xc0, 0x40, 0x3f, + 0x73, 0xdf, 0x56, 0xa6, 0xd9, 0x17, 0xf4, 0xff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, 0xac, + 0x84, 0x06, 0x8e, 0xfe, 0xd0, 0x7c, 0xce, 0x4a, 0x43, 0x49, 0x3b, 0xe1, + 0xab, 0x57, 0xc0, 0x12, 0xd6, 0x9d, 0xa4, 0xee, 0x91, 0x10, 0x81, 0xe2, + 0xfc, 0x02, 0x26, 0x7a, 0xca, 0x81, 0x5b, 0x2f, 0x34, 0x51, 0xdd, 0x25, + 0x4d, 0xc8, 0xf9, 0x3e, 0x59, 0x0f, 0x3d, 0x64, 0x51, 0xbf, 0x42, 0xc4, + 0x92, 0x9d, 0x8f, 0x39, 0x8a, 0x31, 0x09, 0x24, 0x19, 0x44, 0xc0, 0xf4, + 0xea, 0xca, 0x59, 0xcb, 0x86, 0x6c, 0x02, 0x7a, 0xe5, 0x30, 0x79, 0xe2, + 0x2c, 0x76, 0x08, 0x8f, 0x98, 0x0d, 0x4d, 0x12, 0xc3, 0x98, 0xb4, 0x24, + 0x04, 0x4f, 0x51, 0xec, 0x4e, 0xec, 0xbd, 0x8c, 0xc4, 0x79, 0x51, 0x7f, + 0xe1, 0xce, 0x76, 0x28, 0x0b, 0x7b, 0xc5, 0x3f, 0x5b, 0x48, 0x19, 0x76, + 0x68, 0x31, 0x8e, 0x28, 0xff, 0x18, 0x24, 0xe3, 0x91, 0xe7, 0x49, 0x0d, + 0x10, 0xbd, 0x00, 0xc6, 0x58, 0xfd, 0xb6, 0x88, 0x63, 0xbd, 0xb4, 0x4b, + 0xb8, 0xed, 0xdd, 0xb7, 0x53, 0xce, 0x89, 0xdb, 0x7f, 0xf4, 0xc3, 0x21, + 0x31, 0xad, 0x20, 0x78, 0x06, 0x71, 0xaf, 0xc0, 0xe3, 0xdc, 0xb8, 0xf4, + 0x80, 0xc8, 0x33, 0x1d, 0x8b, 0xff, 0x5a, 0x92, 0x68, 0x4d, 0xc1, 0x5b, + 0x58, 0x3e, 0xf6, 0x7f, 0xba, 0x42, 0xa5, 0x6d, 0xec, 0x03, 0x36, 0xc9, + 0x3f, 0x83, 0x1f, 0x0c, 0x33, 0x57, 0x6a, 0x43, 0x5f, 0x11, 0x72, 0x19, + 0x2c, 0xda, 0x71, 0x58, 0xf2, 0x50, 0x50, 0x06, 0x97, 0xd0, 0xdf, 0xd1, + 0x4f, 0x0b, 0x00, 0x1a, 0xea, 0x85, 0x3b, 0x37, 0x2f, 0xf0, 0x40, 0x52, + 0xd9, 0x2a, 0xe8, 0x54, 0xa5, 0xee, 0x0f, 0x49, 0x74, 0x39, 0x96, 0x5d, + 0x60, 0x8f, 0x14, 0x59, 0x86, 0x59, 0x86, 0xfb, 0x67, 0x71, 0x5c, 0x26, + 0x5f, 0xe9, 0xab, 0x32, 0x77, 0x83, 0xdf, 0x02, 0x19, 0x85, 0xae, 0x4d, + 0x7d, 0x9c, 0x8d, 0x4f, 0x61, 0x05, 0x3c, 0x0c, 0xc6, 0x74, 0x9e, 0x36, + 0x33, 0xb8, 0x14, 0x85, 0xab, 0xa2, 0x0b, 0x5d, 0x22, 0xf2, 0x50, 0x3e, + 0xa4, 0x88, 0xac, 0x67, 0xf9, 0x06, 0xe5, 0x30, 0x8e, 0xf9, 0x67, 0x34, + 0xd5, 0x94, 0x5b, 0x35, 0xb7, 0x3d, 0x39, 0x5f, 0x4e, 0xae, 0xfe, 0xf7, + 0x57, 0xd3, 0x95, 0x7b, 0x0a, 0xd9, 0x92, 0x4a, 0x66, 0x29, 0xa0, 0x18, + 0x35, 0x54, 0x14, 0x44, 0x79, 0x72, 0xc3, 0xbc, 0xa8, 0x1a, 0xd3, 0xa3, + 0xbe, 0x6f, 0x9e, 0xcc, 0x68, 0xb6, 0x5f, 0xd4, 0x42, 0xab, 0xe8, 0x09, + 0x60, 0x57, 0x2e, 0xb2, 0x9a, 0x5b, 0x62, 0x38, 0xfb, 0x0a, 0x35, 0x9c, + 0x4f, 0xf7, 0xe0, 0xd2, 0x06, 0x04, 0x1f, 0x79, 0x7f, 0xa7, 0x7b, 0xd3, + 0x63, 0xc9, 0xbd, 0x16, 0x58, 0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2, 0x56, 0x08, 0xc4, 0x3a, + 0xb0, 0x55, 0xb0, 0x24, 0x96, 0xa6, 0x3e, 0x28, 0xd0, 0x35, 0xfb, 0x58, + 0x47, 0xba, 0x2d, 0x51, 0xbb, 0x72, 0x20, 0x59, 0xd2, 0xdd, 0x9c, 0xe2, + 0xb5, 0x31, 0x90, 0xac, 0x74, 0x5d, 0x9f, 0x3d, 0x8c, 0x1c, 0x96, 0xc0, + 0x60, 0x61, 0xa8, 0xbb, 0x3c, 0xb3, 0x6d, 0x6d, 0x92, 0x4a, 0xca, 0xbb, + 0x60, 0x5e, 0x82, 0x0d, 0x7f, 0xab, 0x4b, 0x36, 0x4c, 0x93, 0x0d, 0x88, + 0x71, 0xaf, 0xb6, 0x53, 0xb0, 0x38, 0xb4, 0x1c, 0xb4, 0x7b, 0xd4, 0x13, + 0x32, 0x6c, 0xe4, 0xee, 0x00, 0x00, 0x00, 0x00, 0xfa, 0xb2, 0xff, 0xff, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x88, 0x83, 0x91, 0x4c, + 0x2e, 0x1e, 0xbe, 0xa4, 0xb5, 0x96, 0xff, 0x67, 0x50, 0xe9, 0x81, 0x0e, + 0x5d, 0x0e, 0xad, 0xc4, 0x1f, 0xeb, 0x98, 0x38, 0xcc, 0x54, 0x9d, 0x27, + 0xa6, 0xf1, 0x37, 0x23, 0xce, 0xb4, 0x5b, 0xff, 0x12, 0xb1, 0xb8, 0x35, + 0x5e, 0x03, 0x02, 0x04, 0xad, 0xa6, 0x6f, 0x43, 0xfc, 0xe4, 0xbe, 0x0c, + 0xe0, 0x93, 0xd5, 0xef, 0x09, 0xfa, 0x04, 0xe9, 0x5a, 0x22, 0xd4, 0x81, + 0xc1, 0x27, 0x4f, 0x5f, 0x6e, 0x83, 0x5a, 0x8a, 0x2d, 0xbb, 0x8f, 0xa4, + 0x91, 0xcc, 0x82, 0x37, 0x3b, 0x14, 0x98, 0x58, 0x86, 0x44, 0xb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, 0x12, 0xcc, 0x86, 0xfd, 0xc6, 0x57, 0xf0, 0x02, 0x4e, 0x45, + 0xcb, 0x54, 0x34, 0xdd, 0x66, 0x26, 0xab, 0xda, 0x95, 0xa5, 0x85, 0xec, + 0x02, 0x03, 0xb6, 0x29, 0x30, 0x11, 0x40, 0x54, 0x9a, 0x6a, 0x87, 0x2e, + 0x97, 0xa1, 0x7e, 0xeb, 0x34, 0x39, 0x78, 0x3b, 0xbc, 0x5f, 0x8e, 0xc5, + 0x0e, 0x21, 0x29, 0x4b, 0xb7, 0x1b, 0xe7, 0x14, 0x08, 0x34, 0xb7, 0x9a, + 0x0a, 0xb2, 0x6c, 0x25, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xb5, 0xff, 0xff, + 0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0xe2, 0x7d, 0x48, 0xdd, + 0x1a, 0xcb, 0xb6, 0x5c, 0x6f, 0xbe, 0x32, 0x9d, 0xd2, 0x2b, 0x9e, 0x10, + 0x65, 0xd7, 0x1e, 0xec, 0xc8, 0xb5, 0x10, 0x64, 0x8f, 0x5d, 0xef, 0xfe, + 0x9b, 0x6c, 0x9b, 0x02, 0x6a, 0x6d, 0xf7, 0x98, 0x7b, 0xf7, 0x17, 0xfd, + 0x49, 0x1b, 0x6a, 0xc5, 0x3c, 0xa0, 0xfc, 0xa8, 0x94, 0x95, 0xed, 0x48, + 0x81, 0x04, 0x53, 0x8c, 0xbe, 0xe4, 0x4e, 0xaf, 0xc1, 0x9d, 0xc3, 0xdf, + 0x00, 0x00, 0x00, 0x00, 0x5a, 0xb5, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x04, 0x00, 0x00, 0xae, 0xb0, 0x67, 0x5b, 0x99, 0x26, 0x07, 0xfb, + 0x6c, 0x98, 0xfe, 0xbb, 0x35, 0xf1, 0x5b, 0x02, 0xc6, 0x03, 0xfc, 0x97, + 0x21, 0x16, 0x8d, 0x48, 0xd4, 0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1, 0x88, 0xac, 0x62, + 0xff, 0xbc, 0x69, 0x57, 0xad, 0x0f, 0x08, 0xf8, 0x32, 0xfd, 0x79, 0xcb, + 0x30, 0xbc, 0xd2, 0xe5, 0x20, 0xd9, 0x0f, 0xd1, 0x33, 0xbf, 0xe4, 0x49, + 0x7a, 0x2b, 0x5c, 0xb3, 0x63, 0x13, 0x4d, 0xed, 0x17, 0xe7, 0x5b, 0xf4, + 0x36, 0x9d, 0x3c, 0x4e, 0x51, 0xb2, 0xf7, 0xf2, 0xcd, 0xfb, 0xec, 0x42, + 0x79, 0x46, 0xae, 0x18, 0x50, 0xdf, 0xbf, 0x5b, 0xb1, 0x9a, 0x49, 0x22, + 0xae, 0xe9, 0xf3, 0x86, 0x3f, 0xe0, 0xb4, 0xc6, 0x9c, 0x08, 0xd6, 0xd9, + 0xf4, 0x68, 0xbb, 0x33, 0x0e, 0x59, 0x3d, 0x76, 0xf0, 0xd7, 0x54, 0x04, + 0x19, 0x66, 0xee, 0x61, 0x11, 0x0d, 0x48, 0x10, 0x21, 0x16, 0x7c, 0xac, + 0x49, 0xab, 0xe0, 0x19, 0x85, 0x93, 0x48, 0x65, 0x7c, 0x5e, 0x6c, 0x1a, + 0xf5, 0xb0, 0xc6, 0x80, 0xa1, 0x2a, 0xd5, 0x71, 0x42, 0xec, 0x2f, 0x25, + 0xf7, 0xb8, 0x84, 0xcd, 0xf0, 0x5c, 0xcd, 0xee, 0x44, 0xcb, 0xeb, 0x74, + 0x96, 0x3c, 0xb0, 0x56, 0xcb, 0xaf, 0x7e, 0x9e, 0x4a, 0x12, 0x06, 0xae, + 0x57, 0x43, 0x2d, 0xb2, 0x11, 0x96, 0x05, 0xdb, 0xb3, 0x1a, 0x01, 0xa7, + 0x1d, 0x02, 0x81, 0x1c, 0x36, 0x41, 0x65, 0xf0, 0x67, 0xd6, 0xd0, 0x0f, + 0xec, 0x34, 0x7d, 0xd3, 0x89, 0xac, 0x60, 0x67, 0x95, 0x81, 0x84, 0xe7, + 0xbb, 0x9a, 0x59, 0x36, 0x3b, 0xde, 0xa4, 0x88, 0xda, 0xf2, 0xd2, 0xa2, + 0x0c, 0xba, 0xfb, 0x93, 0xbf, 0xc8, 0xad, 0xe8, 0x57, 0xa0, 0x2b, 0xbb, + 0x4e, 0xa9, 0x38, 0xe7, 0x86, 0x6b, 0x95, 0x34, 0x24, 0x96, 0xc0, 0x09, + 0xd9, 0xfd, 0x5f, 0x1c, 0x93, 0xd9, 0x72, 0xfa, 0xc4, 0x14, 0x72, 0x9c, + 0x19, 0x6f, 0xee, 0x12, 0x17, 0xee, 0x65, 0xb4, 0x8c, 0x83, 0x39, 0x3c, + 0x0f, 0xbf, 0x25, 0xcf, 0xee, 0x05, 0x8c, 0x6a, 0x56, 0x18, 0xf0, 0x20, + 0x72, 0xc1, 0xbf, 0xe4, 0xce, 0x37, 0xbf, 0x2b, 0xba, 0x70, 0x1e, 0xc2, + 0xc8, 0xcd, 0x58, 0xb9, 0x60, 0xc7, 0xfb, 0xd0, 0x00, 0x00, 0x00, 0x00, + 0x6a, 0xb9, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x7c, 0x63, 0x50, 0x90, 0xcb, 0x9c, 0xce, 0x59, 0xb1, 0x47, 0xb0, 0x49, + 0x9b, 0xfc, 0xfb, 0x3d, 0x3d, 0x62, 0xcf, 0x58, 0x4c, 0x2a, 0x79, 0xf0, + 0x72, 0x7f, 0x81, 0x41, 0xac, 0x82, 0x2d, 0xa9, 0xf0, 0x0e, 0x4d, 0xd2, + 0xe0, 0xbd, 0xca, 0x17, 0xb7, 0x59, 0x9f, 0xdb, 0xfe, 0x51, 0x90, 0x88, + 0xb9, 0xeb, 0x4e, 0xac, 0x80, 0x30, 0x64, 0xc4, 0x49, 0xd1, 0xb6, 0x65, + 0x67, 0xef, 0x9d, 0x5c, 0x04, 0xe0, 0x9d, 0xbe, 0x47, 0x75, 0x9b, 0x6e, + 0x30, 0x76, 0xad, 0x37, 0x9a, 0x56, 0xff, 0xcd, 0x40, 0x26, 0x3e, 0xe2, + 0x7d, 0x30, 0x55, 0x09, 0x92, 0x25, 0x36, 0x2f, 0xf8, 0x55, 0xb8, 0x9b, + 0x66, 0x49, 0x41, 0x9d, 0x78, 0x6d, 0x3f, 0x54, 0x41, 0x01, 0x93, 0x9c, + 0x5e, 0x0c, 0x4a, 0x38, 0x79, 0x76, 0xb4, 0x98, 0xae, 0xf9, 0x99, 0x21, + 0x05, 0x6a, 0xfb, 0xbc, 0x44, 0xf7, 0xdc, 0x85, 0x5e, 0x5f, 0x18, 0x49, + 0x22, 0x11, 0x6d, 0xa5, 0x9e, 0x6b, 0x59, 0x60, 0xf8, 0x73, 0x8b, 0xcb, + 0x38, 0xbb, 0xc9, 0xbf, 0x49, 0x0e, 0x57, 0x65, 0x48, 0x41, 0x41, 0xa2, + 0x40, 0x67, 0x91, 0x1d, 0x54, 0xac, 0xa7, 0xef, 0x16, 0x8b, 0xc7, 0xd1, + 0xe6, 0xdb, 0xc5, 0x9c, 0xd4, 0x04, 0x67, 0xd8, 0x75, 0x21, 0x2b, 0x1d, + 0x11, 0xc1, 0x79, 0x45, 0xb4, 0x91, 0x7a, 0x97, 0x00, 0xde, 0xc6, 0xc5, + 0x8a, 0xd1, 0xd7, 0xea, 0xc1, 0x22, 0xe1, 0x58, 0x61, 0xf2, 0x89, 0x3d, + 0xdb, 0x04, 0x3d, 0xe4, 0xe9, 0xe7, 0xbf, 0x4b, 0x99, 0x8a, 0xc6, 0xf2, + 0x09, 0xc4, 0xe2, 0x6d, 0x0b, 0xda, 0x13, 0xfb, 0xff, 0xbf, 0x0b, 0xfc, + 0x78, 0x33, 0xb8, 0x7b, 0x3e, 0xd8, 0xba, 0x27, 0xba, 0xae, 0xdf, 0xce, + 0xea, 0x80, 0x08, 0x38, 0xd8, 0x33, 0x00, 0xa9, 0xb6, 0x88, 0x48, 0xa9, + 0x3b, 0x54, 0xf0, 0x95, 0x00, 0x00, 0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0xed, 0x37, 0x42, 0x4b, 0x4b, 0x6d, 0xb7, 0x10, 0x02, 0x5f, 0x00, 0x1f, + 0x24, 0xce, 0xb2, 0x8b, 0x3e, 0x7d, 0xc6, 0x6e, 0x6c, 0x90, 0x75, 0xad, + 0x3f, 0x9d, 0x63, 0x04, 0x76, 0x20, 0x7a, 0x56, 0x48, 0xa1, 0x6a, 0x37, + 0x74, 0xd2, 0xb7, 0x4f, 0xa3, 0x64, 0x62, 0xaa, 0xce, 0x75, 0x8c, 0x15, + 0x75, 0x79, 0xa0, 0xbd, 0xdd, 0x01, 0x46, 0xca, 0xa0, 0x31, 0x1a, 0x16, + 0x1f, 0xef, 0x8b, 0xc6, 0x54, 0x57, 0xfa, 0x6e, 0x43, 0xdf, 0xb0, 0x99, + 0xed, 0xa4, 0xcb, 0xeb, 0x91, 0x35, 0x14, 0x0c, 0xa9, 0x1d, 0xb5, 0xa9, + 0x32, 0x99, 0xe3, 0x89, 0x74, 0xaa, 0xa4, 0x65, 0x1e, 0x82, 0x47, 0xfa, + 0x37, 0x23, 0xe5, 0x86, 0xb6, 0xc0, 0xb6, 0x89, 0x9a, 0xd9, 0xae, 0x29, + 0x39, 0x7b, 0x66, 0xc7, 0x5b, 0x02, 0x08, 0x86, 0xd4, 0xf0, 0x75, 0xc2, + 0x05, 0x86, 0xc3, 0x75, 0xd2, 0x2a, 0x1e, 0xec, 0x6e, 0x75, 0x29, 0x58, + 0x8c, 0x25, 0x3b, 0x95, 0x21, 0xde, 0x42, 0xd5, 0xb7, 0x15, 0x30, 0x09, + 0x49, 0x78, 0x55, 0xd5, 0xf2, 0x30, 0x80, 0x93, 0x8a, 0xce, 0x84, 0x27, + 0xdb, 0x4a, 0x09, 0x30, 0x0c, 0x7f, 0x4d, 0xd1, 0x0f, 0xda, 0x66, 0x58, + 0xe1, 0x01, 0xfd, 0x75, 0x83, 0xf5, 0x39, 0x2e, 0xe2, 0x6b, 0xde, 0xff, + 0x20, 0x8a, 0xf7, 0xcc, 0x81, 0x8e, 0x99, 0xb4, 0xeb, 0x76, 0x74, 0x38, + 0x2b, 0xe0, 0x6d, 0x61, 0x8f, 0x39, 0x59, 0x10, 0x7d, 0xb5, 0xd3, 0x14, + 0x96, 0x04, 0x1d, 0x22, 0x89, 0xef, 0x15, 0x7c, 0x28, 0x5a, 0xd6, 0x8d, + 0xf3, 0xb7, 0x6a, 0x9a, 0xce, 0x21, 0x77, 0xfd, 0x4f, 0x22, 0x26, 0x28, + 0xb8, 0xb5, 0xb3, 0x73, 0xfd, 0x2a, 0x7b, 0x42, 0x26, 0x77, 0x41, 0x93, + 0xed, 0xf9, 0x8f, 0xa9, 0x92, 0xd5, 0x9f, 0x2e, 0x60, 0xec, 0x60, 0x98, + 0xf1, 0xd5, 0x11, 0xe2, 0xe0, 0xd7, 0x45, 0xa7, 0xe4, 0xf2, 0x82, 0x61, + 0x2f, 0x41, 0x1b, 0xd9, 0x8e, 0x78, 0xd5, 0x6b, 0x68, 0x74, 0xf0, 0xc3, + 0x83, 0x01, 0x16, 0x60, 0x6e, 0x34, 0x88, 0x45, 0x8a, 0x86, 0x44, 0x5b, + 0xa5, 0xa8, 0x55, 0xbc, 0xfa, 0x8f, 0xbd, 0x93, 0x95, 0x3f, 0xab, 0x19, + 0x54, 0x8f, 0x06, 0x8e, 0xca, 0x0b, 0x4a, 0x18, 0x3f, 0x7a, 0x9c, 0x3f, + 0x00, 0x00, 0x00, 0x00, 0x8a, 0xbe, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x04, 0x00, 0x00, 0x81, 0x32, 0x41, 0x46, 0x59, 0x26, 0xf4, 0xef, + 0x93, 0x9f, 0x04, 0xc2, 0x67, 0x13, 0x32, 0x45, 0xc0, 0x79, 0x70, 0x27, + 0x21, 0x2b, 0xaf, 0x35, 0xf3, 0xc4, 0x88, 0x52, 0x28, 0xea, 0xca, 0x8a, + 0x08, 0x01, 0x6f, 0x61, 0xab, 0x10, 0xa3, 0xf0, 0x6b, 0x3b, 0x54, 0x64, + 0xf1, 0x63, 0x83, 0x38, 0x2b, 0x26, 0x18, 0x5a, 0x67, 0xc4, 0x67, 0x38, + 0x3f, 0x2c, 0x9a, 0xc9, 0x48, 0x33, 0x77, 0xb4, 0xb2, 0xc2, 0xc7, 0x08, + 0x21, 0x5e, 0xc4, 0x19, 0x59, 0xe1, 0xfa, 0x32, 0xa4, 0x4c, 0x3e, 0xba, + 0x65, 0x92, 0x98, 0x39, 0x71, 0x2f, 0x99, 0x08, 0xf8, 0xb3, 0x7a, 0x03, + 0x53, 0xd7, 0x68, 0xb2, 0x5e, 0xb0, 0xef, 0xe0, 0x1e, 0x7d, 0xb2, 0x23, + 0x5d, 0x2b, 0xd7, 0x09, 0xa6, 0x78, 0xa4, 0x7c, 0x08, 0xed, 0x8a, 0xf6, + 0x96, 0xa0, 0x10, 0x17, 0x62, 0x8b, 0x8a, 0xa0, 0xac, 0x22, 0x67, 0x02, + 0xa8, 0x66, 0x1a, 0xb5, 0x02, 0xde, 0xa5, 0xfa, 0x69, 0x29, 0x5f, 0x24, + 0x89, 0x46, 0x68, 0xd6, 0x51, 0x2a, 0xfe, 0x88, 0xf0, 0x40, 0xde, 0xd1, + 0x12, 0x2e, 0xed, 0x13, 0x7b, 0x49, 0xf6, 0xe1, 0x7a, 0xcf, 0x61, 0xcb, + 0x70, 0x9d, 0xaa, 0x51, 0x07, 0xc2, 0x54, 0x76, 0x89, 0x29, 0x94, 0x29, + 0x8b, 0x0e, 0xf5, 0xe8, 0x81, 0xc7, 0xdb, 0x59, 0x1e, 0x75, 0xda, 0x6a, + 0x94, 0x18, 0x16, 0xae, 0xbb, 0x43, 0x87, 0x56, 0x66, 0x8b, 0x84, 0xe9, + 0xa9, 0xd0, 0xd2, 0x8f, 0x5b, 0xbf, 0x1d, 0x24, 0x3a, 0xb7, 0x64, 0xff, + 0xe9, 0x22, 0x21, 0x65, 0xaf, 0x2b, 0x45, 0x8d, 0x28, 0xea, 0xbc, 0x07, + 0x10, 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b, 0x19, 0xfc, 0x2a, 0x40, 0x24, + 0x74, 0x20, 0x57, 0x78, 0xb9, 0x55, 0xb7, 0x70, 0x86, 0x65, 0x43, 0x1c, + 0x76, 0x2e, 0x91, 0x83, 0x5e, 0x33, 0xc2, 0xd4, 0xcc, 0xb5, 0x1c, 0x45, + 0xaf, 0xa3, 0x87, 0x95, 0x9b, 0x77, 0x50, 0x44, 0x7e, 0xdd, 0xca, 0x3f, + 0x51, 0x21, 0xae, 0xf2, 0x15, 0xa9, 0x32, 0x94, 0xca, 0xde, 0x3b, 0x97, + 0x13, 0x6b, 0xff, 0xe0, 0x79, 0x39, 0x40, 0xf0, 0x66, 0x7d, 0x5e, 0xef, + 0xec, 0x0a, 0x35, 0xd2, 0x0d, 0x09, 0x19, 0x13, 0x00, 0x00, 0x00, 0x00, + 0x9a, 0xc2, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0xdc, 0x07, 0x2e, 0x46, 0xab, 0x4d, 0x6d, 0xf7, 0x24, 0xba, 0x02, 0xe3, + 0xc5, 0xe3, 0xed, 0x64, 0xc6, 0x77, 0x5a, 0x14, 0xae, 0x38, 0x52, 0x8c, + 0x16, 0x2c, 0x52, 0x0e, 0xf6, 0x65, 0x99, 0xcc, 0xf6, 0x9f, 0x77, 0xcc, + 0x2e, 0xaf, 0x14, 0xd1, 0xf0, 0x0f, 0xa7, 0x3e, 0x5b, 0x74, 0xff, 0xb9, + 0xd3, 0x30, 0x02, 0x5e, 0x52, 0xc8, 0x6f, 0x57, 0xef, 0x28, 0xf5, 0xfa, + 0x9e, 0x70, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0xea, 0xc2, 0xff, 0xff, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0xaa, 0x9f, 0x86, 0xb0, + 0x6d, 0xa1, 0x0c, 0xfa, 0xef, 0xb3, 0x6a, 0x50, 0xa6, 0xfe, 0xff, 0xa9, + 0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, 0x2e, 0x21, 0x8c, 0xf1, + 0xbd, 0xad, 0x7c, 0x28, 0xcc, 0xbd, 0x58, 0x72, 0xe9, 0x6a, 0x04, 0x56, + 0x67, 0x0f, 0x62, 0x98, 0x5a, 0x97, 0x4b, 0xe2, 0x67, 0x70, 0xbb, 0x17, + 0xb1, 0x84, 0x5b, 0xd4, 0x6e, 0xab, 0x90, 0x29, 0x20, 0x93, 0x34, 0xa8, + 0x03, 0x0f, 0xed, 0x1a, 0xf0, 0x1b, 0x92, 0x87, 0x43, 0xa5, 0x6a, 0x1c, + 0xdc, 0xd7, 0x22, 0x68, 0x83, 0x98, 0x74, 0x2a, 0x4c, 0x51, 0xef, 0x71, + 0x19, 0xd5, 0x3d, 0x05, 0x19, 0x61, 0xb2, 0x52, 0xa8, 0x6e, 0xda, 0x72, + 0x51, 0x66, 0x9f, 0xf0, 0x12, 0xf6, 0x18, 0x60, 0xcc, 0xd7, 0x2f, 0x2e, + 0x83, 0x14, 0x09, 0xdb, 0x55, 0x1c, 0xf2, 0xaf, 0xfd, 0xa4, 0x40, 0xf1, + 0x00, 0x00, 0x00, 0x00, 0xfa, 0xc6, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x9c, 0x52, 0xff, 0x48, 0x06, 0x61, 0x76, 0x6d, + 0xd7, 0x44, 0xb1, 0x0c, 0x32, 0x62, 0x15, 0xa1, 0xc3, 0x97, 0x03, 0xdd, + 0xed, 0x20, 0x3c, 0x3a, 0x09, 0x16, 0xe5, 0x7d, 0x8c, 0xf9, 0x7b, 0x22, + 0x5e, 0x3a, 0xdd, 0xf0, 0xc6, 0xf0, 0x3a, 0xd4, 0x94, 0x85, 0x1c, 0x60, + 0x74, 0x91, 0xa3, 0xe2, 0x8a, 0xe5, 0x3e, 0xd4, 0x95, 0x28, 0x8b, 0x1a, + 0x7b, 0xbe, 0x07, 0xc0, 0xe3, 0x6b, 0xb9, 0x85, 0x82, 0x0b, 0x24, 0x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0xea, 0x61, + 0xbc, 0x0d, 0x24, 0x3a, 0x20, 0xc2, 0x76, 0xfc, 0x2e, 0xce, 0xfb, 0x75, + 0x00, 0xca, 0x58, 0xbd, 0xab, 0x61, 0x9b, 0x13, 0x2b, 0xa3, 0xf6, 0x15, + 0x55, 0x83, 0x23, 0xc4, 0xf3, 0x4c, 0x89, 0xc5, 0x4a, 0x18, 0x5c, 0x8d, + 0x41, 0xcc, 0x06, 0x7b, 0xe3, 0x2a, 0x1f, 0x6a, 0x57, 0xbc, 0x54, 0x61, + 0x0c, 0xf2, 0xec, 0xbf, 0xb0, 0xf0, 0x21, 0xde, 0xfc, 0xe4, 0xef, 0xce, + 0x47, 0xc8, 0xdc, 0x11, 0xc7, 0x8a, 0x12, 0x97, 0x68, 0x1d, 0x9e, 0x9a, + 0xbf, 0xad, 0x62, 0x7e, 0x4b, 0x88, 0xd7, 0x20, 0x22, 0xce, 0x5e, 0xe3, + 0x87, 0x12, 0xa3, 0x05, 0xef, 0x1f, 0x05, 0xb1, 0xbd, 0x1b, 0x80, 0x43, + 0x84, 0x33, 0x8b, 0x87, 0xa5, 0xc2, 0xe1, 0x49, 0xa8, 0x75, 0x49, 0x9b, + 0x1b, 0x64, 0x8a, 0xd0, 0x86, 0x10, 0xa8, 0x72, 0xeb, 0x2e, 0xe7, 0x3f, + 0xaa, 0x6b, 0x4a, 0x22, 0xae, 0x17, 0x8f, 0x10, 0x22, 0x03, 0x66, 0x67, + 0x35, 0x40, 0x29, 0x1e, 0xf2, 0x05, 0x36, 0xd5, 0xed, 0xe2, 0x2a, 0xcc, + 0x77, 0xe2, 0x16, 0xef, 0xa7, 0x9b, 0xe1, 0x1b, 0xba, 0xf3, 0xf5, 0x74, + 0x6c, 0x2a, 0x98, 0x8a, 0x14, 0xaf, 0x2c, 0xab, 0xfb, 0x51, 0x53, 0x75, + 0x17, 0xcb, 0x5c, 0x86, 0xb5, 0x60, 0x70, 0x29, 0x65, 0x69, 0x49, 0x42, + 0x4f, 0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0x15, 0xce, 0x3e, 0xbf, 0x49, 0x58, 0xb0, 0xb5, 0xd7, + 0xbe, 0x01, 0x55, 0xee, 0x60, 0x14, 0x9d, 0x5b, 0x57, 0x48, 0x05, 0x72, + 0x6a, 0x23, 0x29, 0xeb, 0xf3, 0x36, 0x2a, 0xc1, 0xda, 0x5e, 0x4a, 0x63, + 0xc4, 0x6b, 0x04, 0xe8, 0xe8, 0xc1, 0xb5, 0xc4, 0x2d, 0x60, 0x1f, 0xa0, + 0x2b, 0x33, 0xa5, 0xb7, 0x82, 0x59, 0x21, 0xba, 0x13, 0xda, 0x79, 0xda, + 0x5a, 0xb1, 0x82, 0x5b, 0x52, 0x7f, 0x0c, 0x70, 0x75, 0x65, 0xe0, 0x44, + 0xb3, 0xca, 0xd0, 0x09, 0x38, 0x24, 0x83, 0x8e, 0x0c, 0x4c, 0xef, 0x96, + 0xe4, 0x04, 0x30, 0x46, 0x23, 0x6a, 0x28, 0x13, 0x1d, 0x37, 0x14, 0x75, + 0x00, 0x00, 0x00, 0x00, 0x2a, 0xd0, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x21, 0xa2, 0xf0, 0x7d, 0x29, 0x8f, 0x62, 0x2e, + 0xf4, 0x0e, 0x14, 0x9b, 0x60, 0x38, 0xc0, 0x95, 0xfb, 0x3c, 0x90, 0x5a, + 0xa0, 0x1f, 0x30, 0x09, 0xfc, 0x6d, 0xa9, 0xd1, 0x7b, 0x0b, 0x7c, 0x78, + 0xf9, 0xf6, 0xa8, 0x5e, 0xa6, 0x7a, 0xf6, 0x1c, 0xab, 0x1b, 0x0e, 0xa9, + 0x08, 0xfd, 0xd9, 0x97, 0x08, 0x24, 0x2b, 0xda, 0x08, 0x8b, 0x0c, 0x07, + 0x70, 0x15, 0xa8, 0x0c, 0x86, 0xfc, 0xd1, 0x84, 0x00, 0x00, 0x00, 0x00, + 0x7a, 0xd0, 0xff, 0xff, 0x04, 0x00, 0x00, 0x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x7d, 0x9f, 0x64, 0x12, 0x54, 0x09, 0xb7, 0xc2, 0x4d, 0x6e, 0xcc, + 0x60, 0x07, 0x36, 0x31, 0x64, 0x3d, 0x1e, 0xd3, 0x86, 0x47, 0x47, 0x42, + 0x76, 0xb6, 0xf0, 0xe5, 0xb4, 0xe7, 0xbe, 0x47, 0x91, 0x78, 0xbe, 0x06, + 0xf1, 0x6e, 0x58, 0xce, 0x32, 0x13, 0x26, 0x34, 0x92, 0xae, 0xb2, 0x29, + 0xd0, 0x30, 0x55, 0xfd, 0x89, 0x6a, 0xbf, 0x3e, 0xdf, 0x11, 0x39, 0xe4, + 0xfd, 0x56, 0xd7, 0x2f, 0x89, 0x96, 0x08, 0x54, 0xaa, 0xab, 0x8b, 0xfa, + 0x65, 0xe5, 0x64, 0xff, 0x24, 0x25, 0x8f, 0x7d, 0xf6, 0xb1, 0x7f, 0x2f, + 0xa6, 0xf6, 0x46, 0xab, 0x61, 0xfd, 0x47, 0xad, 0x6d, 0x38, 0x6d, 0xc1, + 0xe9, 0x4a, 0xf1, 0x85, 0x05, 0x0e, 0x69, 0x48, 0x7c, 0xa6, 0x76, 0x61, + 0xe3, 0x94, 0xf2, 0xd6, 0x7a, 0x9c, 0x79, 0xc0, 0x2a, 0x51, 0x23, 0xc6, + 0xaf, 0x29, 0x04, 0x0f, 0x47, 0xc2, 0x93, 0xd7, 0x64, 0xe5, 0x37, 0x2e, + 0x53, 0x3b, 0xb7, 0x7c, 0x9c, 0xb4, 0x63, 0x13, 0xc7, 0x56, 0x90, 0xe9, + 0x53, 0xd5, 0x86, 0x2b, 0x96, 0x41, 0x42, 0x56, 0xc5, 0x16, 0xd7, 0x9e, + 0x30, 0xce, 0xa1, 0x0d, 0x93, 0x5d, 0x11, 0x07, 0xb2, 0x95, 0xfd, 0xf6, + 0x0b, 0x28, 0x95, 0x1a, 0x8f, 0xfa, 0xe1, 0x57, 0x7e, 0x06, 0xff, 0x18, + 0xaf, 0xe3, 0x4f, 0x3c, 0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, 0xc0, 0xd4, 0xa7, 0x80, 0x10, 0x35, + 0x09, 0xae, 0xf7, 0xe1, 0x5e, 0x7c, 0x31, 0x20, 0x43, 0x82, 0xda, 0x07, + 0x39, 0xfe, 0x8f, 0x9d, 0x70, 0x3c, 0x57, 0x43, 0x01, 0x51, 0x37, 0x2e, + 0x97, 0xef, 0xcf, 0x05, 0x44, 0x75, 0x69, 0xf7, 0xdb, 0xda, 0x80, 0x78, + 0x0c, 0xcc, 0xc1, 0x49, 0xac, 0x3b, 0x7e, 0x27, 0x6a, 0xbb, 0xdf, 0x45, + 0x5b, 0x3b, 0x29, 0xf6, 0x1b, 0xa9, 0x25, 0xf9, 0x2f, 0xcf, 0x37, 0x71, + 0x33, 0xb4, 0x90, 0xd7, 0x9b, 0x87, 0x41, 0x15, 0xd1, 0xa6, 0x39, 0xa7, + 0xa9, 0xcd, 0x66, 0x29, 0x59, 0xb4, 0x53, 0x12, 0xa1, 0x20, 0xd5, 0x04, + 0xca, 0x40, 0x31, 0xfa, 0x6f, 0xbb, 0x92, 0x04, 0xf3, 0xc2, 0x10, 0x0d, + 0xc1, 0x19, 0x78, 0x8c, 0x82, 0xed, 0x92, 0x3a, 0x6b, 0xd1, 0x3d, 0xe8, + 0xac, 0x55, 0xe4, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x8a, 0xd4, 0xff, 0xff, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xc2, 0x1d, 0x86, 0xe4, + 0xf6, 0xa1, 0xbe, 0xf5, 0xf3, 0x36, 0x9d, 0x32, 0x80, 0x17, 0x3b, 0x1f, + 0x18, 0x21, 0xed, 0xa7, 0xf5, 0xaf, 0xf1, 0x94, 0xe2, 0xa7, 0x08, 0xd5, + 0xca, 0x18, 0x45, 0xf5, 0x68, 0x94, 0x82, 0x61, 0xf7, 0xb7, 0xb2, 0xfa, + 0xd4, 0x5e, 0x32, 0xd0, 0xf0, 0x20, 0x66, 0x83, 0xd1, 0x6b,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7, + 0x3d, 0x0e, 0xb7, 0x55, 0x6d, 0xa7, 0x9f, 0x10, 0x7e, 0x7e, 0xff, 0x39, + 0xee, 0x8e, 0xa7, 0x81, 0x7d, 0x11, 0xea, 0xa9, 0xd6, 0xed, 0x54, 0xf8, + 0x00, 0x00, 0x00, 0x00, 0x9a, 0xd5, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x04, 0x00, 0x00, 0xf9, 0xde, 0x41, 0xe7, 0xa6, 0x88, 0x53, 0x76, + 0x5a, 0x26, 0xc3, 0x5c, 0xf2, 0x58, 0x68, 0x9c, 0xc7, 0x4e, 0x53, 0x18, + 0x53, 0x67, 0x39, 0x23, 0x96, 0xb0, 0xef, 0x58, 0x29, 0xe1, 0x68, 0xd8, + 0xce, 0xc0, 0x41, 0xc2, 0x35, 0x5f, 0x74, 0xfa, 0xdf, 0xc7, 0x0f, 0x80, + 0x50, 0xd1, 0xf6, 0x5a, 0x3a, 0x81, 0xe0, 0xd9, 0x9b, 0x47, 0x96, 0xcd, + 0xc5, 0x0f, 0x91, 0x12, 0x81, 0x77, 0x1e, 0xef, 0x2e, 0xba, 0x16, 0x51, + 0x70, 0x78, 0xdc, 0xa3, 0x84, 0x12, 0x7c, 0x9e, 0x21, 0x7d, 0xa3, 0x5f, + 0xce, 0xa1, 0x25, 0x84, 0x99, 0xa4, 0x2d, 0xa6, 0x0f, 0x95, 0xef, 0xef, + 0x31, 0xe6, 0xf2, 0x18, 0x08, 0x47, 0xd2, 0x5a, 0x39, 0x01, 0x7a, 0xca, + 0xd3, 0x03, 0xb1, 0xc2, 0x48, 0xf4, 0x1f, 0x6d, 0xc2, 0x8c, 0x5c, 0xda, + 0xf5, 0x10, 0xed, 0xfc, 0x2e, 0x0c, 0xb3, 0x52, 0xaa, 0xa9, 0xed, 0xbc, + 0x41, 0xcc, 0xd4, 0x4b, 0x1c, 0xd0, 0xa3, 0x1d, 0xf4, 0xe7, 0x48, 0x34, + 0x4e, 0xcf, 0x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 0xd4, 0x71, 0x5a, + 0xca, 0xbb, 0xfe, 0x0e, 0x54, 0xf9, 0xb4, 0x25, 0xa5, 0x71, 0x13, 0x95, + 0x14, 0xdc, 0x86, 0xb8, 0x21, 0xa7, 0x2e, 0x13, 0xc6, 0x2f, 0xce, 0xe7, + 0x6c, 0xb8, 0x0d, 0xc9, 0xe4, 0xc4, 0x64, 0x12, 0x78, 0x1c, 0x95, 0x92, + 0xc2, 0xec, 0xaa, 0xd3, 0xc3, 0x3a, 0xd2, 0xe8, 0x95, 0xf0, 0x6b, 0x03, + 0x8c, 0xcf, 0x6b, 0xdb, 0x21, 0xa0, 0xcf, 0xf4, 0x05, 0xc8, 0xe7, 0x77, + 0x05, 0x55, 0x7b, 0x6b, 0xfa, 0x96, 0xf1, 0x7c, 0x30, 0x62, 0x75, 0xbe, + 0x6e, 0xea, 0xba, 0x9f, 0x40, 0x2e, 0x9a, 0x86, 0x93, 0xcc, 0x38, 0xf7, + 0xee, 0xd8, 0xbb, 0x24, 0xcd, 0x85, 0x3e, 0x85, 0x16, 0x8c, 0x33, 0x23, + 0x73, 0xe6, 0x43, 0xc4, 0x67, 0xbf, 0xef, 0x85, 0xb1, 0x44, 0xf9, 0x55, + 0x93, 0x4d, 0x0b, 0x8e, 0xc1, 0x42, 0x13, 0xc6, 0xc8, 0x09, 0x63, 0xab, + 0xb3, 0xc7, 0xc4, 0xa4, 0x8b, 0x72, 0xfb, 0xa5, 0x99, 0xa1, 0x5d, 0x07, + 0x02, 0x82, 0x56, 0x11, 0x3c, 0xc2, 0x5a, 0x55, 0xf9, 0x3a, 0x93, 0x61, + 0x89, 0x46, 0xb7, 0x6a, 0x42, 0x76, 0x1e, 0x70, 0x00, 0x00, 0x00, 0x00, + 0xaa, 0xd9, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, + 0x32, 0xc1, 0x61, 0xaa, 0xdb, 0xe9, 0xae, 0x88, 0xcb, 0xf7, 0x28, 0xdd, + 0x82, 0x62, 0x61, 0x41, 0x4e, 0xbb, 0xf9, 0xb7, 0xe8, 0x81, 0x99, 0x18, + 0xe2, 0xa7, 0xb4, 0x7c, 0xb7, 0x08, 0x44, 0x6f, 0x24, 0xb3, 0xda, 0x57, + 0x62, 0x29, 0xc7, 0xa6, 0x84, 0xb1, 0x5d, 0xc5, 0x00, 0x4c, 0x30, 0x16, + 0xf0, 0x0a, 0x74, 0x73, 0xec, 0xaf, 0xb5, 0xde, 0xb0, 0xa7, 0x75, 0x22, + 0x8f, 0x9e, 0x43, 0x01, 0x68, 0xae, 0x91, 0xeb, 0x46, 0x52, 0x3f, 0x2c, + 0x4e, 0xc5, 0xd0, 0xc8, 0x15, 0xea, 0x99, 0xc2, 0x37, 0x5b, 0x68, 0xb5, + 0xce, 0x41, 0x92, 0xbf, 0xd6, 0xdb, 0x85, 0xad, 0x08, 0xd1, 0x11, 0x93, + 0xe8, 0xd4, 0x78, 0x43, 0x3b, 0x7d, 0xcb, 0x42, 0x84, 0xf3, 0x61, 0x88, + 0x9e, 0x6a, 0x73, 0xb9, 0x78, 0x17, 0x9a, 0x9f, 0xfb, 0x97, 0xcb, 0xd6, + 0xb5, 0x3f, 0x00, 0x41, 0xb0, 0x30, 0x2f, 0x6f, 0x89, 0xdd, 0xfa, 0x13, + 0xd1, 0x07, 0xbe, 0x2f, 0xea, 0x91, 0x62, 0xaa, 0xed, 0xcb, 0xfd, 0x07, + 0x82, 0xbb, 0x3f, 0xf4, 0xa6, 0x94, 0x66, 0x71, 0x20, 0x61, 0xac, 0x84, + 0x04, 0x70, 0xf2, 0xd3, 0xdf, 0xac, 0x44, 0xfd, 0x47, 0x26, 0x81, 0x64, + 0xb3, 0xa6, 0x90, 0x2b, 0xd2, 0x2c, 0xd0, 0x77, 0x81, 0x53, 0x45, 0x78, + 0x5f, 0x30, 0x77, 0x91, 0x83, 0x13, 0x33, 0xd1, 0x91, 0xa6, 0x35, 0x21, + 0xcb, 0x26, 0x54, 0x0a, 0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1b, 0x04, 0x75, + 0x92, 0x6c, 0x08, 0x9e, 0x38, 0x72, 0xd9, 0x7d, 0x9b, 0xbc, 0xfd, 0xca, + 0xb8, 0x06, 0x0e, 0x24, 0x89, 0x90, 0xde, 0x52, 0xe4, 0xd1, 0xcc, 0x99, + 0x87, 0x0b, 0x87, 0xbb, 0x5c, 0xa9, 0xab, 0xec, 0xb5, 0xe4, 0xdd, 0x5d, + 0xfa, 0xb1, 0x97, 0x5f, 0x61, 0xf7, 0x58, 0xd6, 0x08, 0x02, 0xf2, 0x51, + 0x7c, 0x7a, 0xe6, 0xf1, 0xcb, 0x43, 0xd0, 0x21, 0x09, 0xb8, 0x82, 0xa9, + 0x52, 0xd9, 0xa8, 0x7f, 0x2b, 0xe1, 0x0f, 0x31, 0xbc, 0x16, 0xa2, 0xce, + 0x35, 0x55, 0x2e, 0xd6, 0xda, 0x38, 0xd9, 0xc2, 0x5e, 0xca, 0x27, 0xd9, + 0xa6, 0xd6, 0x4b, 0xa2, 0x73, 0xc4, 0xce, 0x66, 0x30, 0x60, 0xa2, 0x01, + 0xfa, 0xc1, 0xd6, 0xc8, 0x00, 0x00, 0x00, 0x00, 0xba, 0xdd, 0xff, 0xff, + 0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x70, 0xe2, 0x62, 0x68, + 0xff, 0x60, 0x67, 0x64, 0x88, 0xdd, 0x81, 0x79, 0x82, 0xf5, 0x46, 0xf9, + 0x7e, 0x0e, 0xa9, 0x26, 0xf6, 0xcf, 0x5d, 0xef, 0x10, 0x11, 0xe1, 0x71, + 0x72, 0x77, 0xcf, 0x02, 0x7b, 0xf1, 0x6e, 0xc4, 0xb4, 0xfa, 0x2a, 0x12, + 0xfe, 0x7e, 0x3c, 0x66, 0xef, 0x41, 0x98, 0x3a, 0x1f, 0xa9, 0x14, 0x8f, + 0x46, 0x22, 0xa0, 0xc2, 0xee, 0x93, 0x25, 0x34, 0xf2, 0xb7, 0x6d, 0x0a, + 0x00, 0x00, 0x00, 0x00, 0x0a, 0xde, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x04, 0x00, 0x00, 0xd4, 0x17, 0x62, 0x25, 0xfd, 0x5b, 0x75, 0xeb, + 0xec, 0x06, 0xc9, 0x39, 0x86, 0x6d, 0xc5, 0x60, 0x2d, 0x33, 0x3d, 0xce, + 0x6a, 0x9f, 0x07, 0x3b, 0xb9, 0x70, 0x0f, 0xc7, 0x13, 0x46, 0x35, 0x46, + 0x26, 0xe4, 0xbc, 0x6e, 0x54, 0x89, 0x29, 0xd5, 0xa4, 0x94, 0xa0, 0x3a, + 0x7a, 0x61, 0xcf, 0xd1, 0x48, 0x27, 0x7a, 0x72, 0x95, 0xde, 0x93, 0xd1, + 0x19, 0x1f, 0xc9, 0xc8, 0x8f, 0x0d, 0xce, 0x34, 0x03, 0x39, 0x0a, 0x92, + 0x16, 0x09, 0xc4, 0x49, 0xf9, 0x30, 0x2e, 0x19, 0xd1, 0x69, 0x7e, 0x78, + 0x00, 0x25, 0x30, 0x6f, 0x6b, 0xe1, 0xbe, 0xad, 0xb2, 0x05, 0xde, 0xc7, + 0xc2, 0xf7, 0xd5, 0xa7, 0x4d, 0x03, 0x6f, 0x6b, 0xcd, 0xcb, 0x42, 0xfa, + 0x88, 0x16, 0xd5, 0xa6, 0x60, 0x08, 0xd4, 0xa5, 0x5b, 0x3b, 0x7b, 0xa2, + 0xca, 0xa3, 0xa2, 0x5d, 0x63, 0x7f, 0xc0, 0x37, 0xc5, 0x7e, 0x99, 0x04, + 0x5d, 0x9a, 0xb9, 0xa5, 0xac, 0xd1, 0xe2, 0x5d, 0xb2, 0x2b, 0x7e, 0xbb, + 0xb9, 0x66, 0x13, 0xa7, 0x30, 0xbf, 0x80, 0x0c, 0x2b, 0x8d, 0x45, 0xe1, + 0x8d, 0x96, 0x25, 0x27, 0x47, 0x3d, 0x21, 0x7d, 0x1c, 0x42, 0xac, 0x31, + 0x26, 0x47, 0x59, 0xb3,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x92, 0x20, + 0x2a, 0x71, 0xed, 0x22, 0x0b, 0xfb, 0x42, 0xb5, 0xd9, 0xc3, 0xaa, 0xed, + 0x45, 0x03, 0x64, 0xde, 0x6f, 0x25, 0x8e, 0x3b, 0x9a, 0xef, 0xc5, 0x63, + 0xc2, 0x7f, 0x34, 0xd0, 0x1b, 0x20, 0xa3, 0xab, 0x9d, 0x54, 0x41, 0x0e, + 0x7b, 0x2e, 0x96, 0x12, 0x75, 0x58, 0xdf, 0xd5, 0xaa, 0x3c, 0xf2, 0x26, + 0xc1, 0xf1, 0x18, 0x37, 0x56, 0xf2, 0xd2, 0x86, 0x6f, 0xd4, 0x9f, 0x57, + 0x2b, 0x32, 0xe9, 0x08, 0x94, 0x53, 0x40, 0xc5, 0x4d, 0x77, 0x39, 0xc6, + 0x4c, 0x63, 0x53, 0xf9, 0xbf, 0x35, 0x08, 0xc5, 0x0d, 0xd0, 0x89, 0x82, + 0xa7, 0x2d, 0x6a, 0xb4, 0x22, 0xb1, 0x10, 0x7f, 0xcf, 0x2e, 0x21, 0x27, + 0x9c, 0x12, 0xc6, 0x0e, 0xca, 0xd2, 0x32, 0xb1, 0x6d, 0xfd, 0x59, 0x12, + 0x23, 0x60, 0x46, 0x89, 0xe0, 0x75, 0x5e, 0xc9, 0xf4, 0x3d, 0x8a, 0x89, + 0xd4, 0x23, 0xc2, 0xbe, 0x30, 0x32, 0x4a, 0x95, 0x00, 0x00, 0x00, 0x00, + 0x1a, 0xe2, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0xa7, 0x0b, 0x48, 0xe2, 0xeb, 0xd7, 0x12, 0x42, 0x4c, 0x71, 0xfb, 0x25, + 0x17, 0x23, 0x0e, 0x01, 0xa6, 0x21, 0xb9, 0x17, 0x6e, 0xf0, 0x24, 0x66, + 0x9e, 0x9d, 0x0f, 0x71, 0xf8, 0x5b, 0x79, 0xb0, 0x1b, 0x1f, 0xe7, 0xa2, + 0xc0, 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, 0x29, 0x87, 0xbf, 0x6a, 0xdc, 0xb1, 0x2f, 0x01, 0xf4, 0x0d, + 0x7c, 0x25, 0x95, 0x39, 0x81, 0xdd, 0x1a, 0x81, 0x36, 0xc0, 0x6b, 0xbf, + 0x6b, 0x4d, 0xea, 0x23, 0xc0, 0x3e, 0x5c, 0x39, 0xe5, 0x6b, 0x59, 0xa0, + 0x50, 0x02, 0x99, 0xdf, 0x00, 0x00, 0x00, 0x00, 0x2a, 0xe3, 0xff, 0xff, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x17, 0x88, 0xf8, 0xda, + 0x3d, 0x57, 0x83, 0x63, 0x76, 0xa0, 0x5c, 0x13, 0x1a, 0x00, 0x64, 0x30, + 0x19, 0xfd, 0x2e, 0x9c, 0x64, 0xb6, 0xda, 0x51, 0x7b, 0x55, 0xe8, 0xc4, + 0x67, 0x1b, 0xda, 0xfc, 0x4c, 0xd0, 0x27, 0x58, 0x56, 0xa1, 0x52, 0xd2, + 0xb8, 0xd8, 0xd5, 0x94, 0x69, 0xcf, 0xd0, 0xd5, 0x72, 0xeb, 0x2b, 0x05, + 0xf3, 0x12, 0xa6, 0xac, 0xa6, 0xf7, 0x90, 0x24, 0x1f, 0x22, 0x97, 0x5e, + 0x8b, 0x7c, 0x2c, 0x30, 0x61, 0x11, 0x9b, 0xdf, 0x83, 0x2b, 0x10, 0x09, + 0x42, 0x77, 0x2b, 0xd9, 0x43, 0xb3, 0x27, 0x69, 0x75, 0xf2, 0x2e, 0x72, + 0xed, 0x50, 0xea, 0xbf, 0x7f, 0x47, 0x39, 0x9c, 0xf8, 0x1e, 0xce, 0x6f, + 0xdd, 0xe8, 0x40, 0xc5, 0x14, 0x01, 0x7e, 0xbb, 0x0f, 0x43, 0x2d, 0x36, + 0x70, 0x54, 0xc6, 0xbe, 0x69, 0x24, 0xd1, 0x65, 0x49, 0x77, 0xf0, 0xd2, + 0x99, 0xb4, 0x50, 0x8d, 0x98, 0xcb,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, 0xef, + 0x63, 0x52, 0x03, 0x88, 0x36, 0xc5, 0x83, 0x65, 0xf8, 0xf1, 0x87, 0xce, + 0x43, 0xfe, 0x89, 0x58, 0x07, 0x6a, 0xad, 0x85, 0x37, 0x0f, 0xdf, 0x9e, + 0xa5, 0x62, 0xa9, 0xd2, 0x41, 0x3f, 0x7f, 0xb7, 0xf1, 0xe2, 0x58, 0xb5, + 0xda, 0xdf, 0xd1, 0xba, 0x36, 0x2c, 0xe7, 0x43, 0x31, 0x07, 0xc5, 0xf5, + 0x79, 0xc9, 0x31, 0xd7, 0x1d, 0x97, 0x57, 0x9a, 0x8e, 0x3f, 0xac, 0x00, + 0x49, 0x00, 0x2f, 0xad, 0xac, 0xe7, 0x65, 0x7c, 0xbf, 0xec, 0x85, 0x57, + 0xe6, 0xcc, 0x07, 0x34, 0x02, 0x36, 0xa8, 0x6a, 0x9f, 0x3a, 0x9a, 0x2f, + 0x34, 0x93, 0x1f, 0x7d, 0x38, 0x54, 0xe3, 0x54, 0x54, 0xee, 0x84, 0x55, + 0xe1, 0x0d, 0xc1, 0x08, 0x3e, 0x33, 0x9e, 0x2a, 0xc3, 0x6a, 0x83, 0xc4, + 0x75, 0xed, 0xbc, 0x5f, 0xd9, 0x04, 0xd7, 0x77, 0x91, 0xb1, 0xa0, 0xf2, + 0xef, 0x81, 0xb0, 0x8b, 0x53, 0x5f, 0x71, 0xec, 0xa5, 0x0b, 0xbe, 0xf2, + 0x92, 0x7e, 0x0a, 0x34, 0xeb, 0x5d, 0x65, 0xc7, 0xa9, 0x44, 0x10, 0xfb, + 0xd3, 0xef, 0xe1, 0xbc, 0x06, 0x65, 0x68, 0x22, 0xfb, 0x43, 0x2c, 0xcf, + 0x8e, 0x6a, 0x28, 0xdb, 0x0b, 0xf4, 0xaf, 0x01, 0x65, 0x97, 0xd6, 0xe5, + 0x91, 0x20, 0x13, 0x2c, 0xb1, 0xc2, 0xd3, 0xc3, 0x76, 0x90, 0xf8, 0xcd, + 0x00, 0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x40, 0xab, 0x68, 0x72, 0xe3, + 0x92, 0x30, 0x47, 0xd6, 0x30, 0x60, 0x42, 0x5b, 0x88, 0x8d, 0xa6, 0x56, + 0xe4, 0xac, 0x33, 0x2e, 0xca, 0x05, 0x1f, 0x60, 0xaf, 0xde, 0x7f, 0xa9, + 0xda, 0x3f, 0xa8, 0x21, 0xf6, 0xfc, 0x98, 0x7d, 0xc4, 0x1e, 0xb0, 0xa9, + 0x56, 0x2d, 0x8d, 0xea, 0x03, 0x51, 0x48, 0xac, 0xe8, 0x22, 0xc7, 0x8b, + 0xef, 0x91, 0x0e, 0xcf, 0x0c, 0xe9, 0x38, 0x43, 0x99, 0xa8, 0x98, 0x4f, + 0xfa, 0xe3, 0x03, 0xa6, 0x4f, 0xd4, 0x0d, 0x98, 0x5b, 0x50, 0x28, 0xd7, + 0xe7, 0x46, 0xd7, 0xad, 0x43, 0xb8, 0x56, 0x2a, 0x2f, 0x7c, 0x39, 0x67, + 0xf4, 0x62, 0x0e, 0xc0, 0xa8, 0x87, 0xb5, 0x81, 0xe2, 0x13, 0x9f, 0xe4, + 0xdd, 0x72, 0xf2, 0x07, 0xca, 0xac, 0x6d, 0xb2, 0x96, 0x53, 0x5a, 0x8f, + 0x66, 0x3c, 0xb4, 0xc1, 0x4f, 0x9a, 0x82, 0x55, 0xcf, 0x0e, 0x27, 0x5f, + 0xc7, 0xd2, 0x28, 0x27, 0x7f, 0x22, 0x6e, 0xa5, 0xe7, 0x32, 0x56, 0x51, + 0x18, 0xe0, 0x85, 0x6d, 0x1f, 0xfc, 0x25, 0x08, 0x18, 0x60, 0x57, 0xfc, + 0x66, 0x94, 0x2c, 0x4c, 0xbe, 0x00, 0xab, 0x9e, 0x73, 0x9b, 0x06, 0xd3, + 0xb5, 0x24, 0xa8, 0x8f, 0xb1, 0x33, 0x99, 0x4c, 0xb4, 0x13, 0x07, 0xcd, + 0x04, 0xdd, 0x77, 0xdc, 0xee, 0x96, 0x02, 0x59, 0xe8, 0x22, 0x07, 0x16, + 0x2e, 0x41, 0xc9, 0xc4, 0x59, 0x70, 0x37, 0x0f, 0x14, 0xc9, 0xcf, 0x90, + 0x57, 0xc2, 0x0d, 0xa3, 0xd7, 0x66, 0xb6, 0x7d, 0x10, 0xd4, 0xfc, 0x18, + 0x66, 0xad, 0xea, 0x5e, 0x64, 0x6c, 0x12, 0x66, 0x3d, 0x96, 0xa5, 0xa8, + 0x9c, 0x49, 0x5c, 0xd4, 0x8d, 0x1c, 0xc3, 0x38, 0xfe, 0x53, 0xc2, 0x71, + 0xd1, 0xc6, 0x41, 0xe2, 0xb9, 0x17, 0x74, 0x6e, 0xcc, 0xf8, 0x72, 0x28, + 0x38, 0x4e, 0x54, 0x9b, 0x0e, 0xa3, 0x3a, 0x43, 0x5c, 0xd5, 0x83, 0x06, + 0xbb, 0x46, 0x16, 0x6e, 0xe3, 0x8a, 0xd5, 0x1e, 0x7f, 0x88, 0x62, 0xac, + 0x35, 0x89, 0xfb, 0xbe, 0x96, 0x1d, 0x87, 0x37, 0xb7, 0x91, 0x63, 0xae, + 0x77, 0x7b, 0x66, 0x60, 0xc1, 0x3e, 0x80, 0x56, 0xb1, 0xc8, 0x0d, 0x16, + 0xde, 0x38, 0x82, 0x66, 0x99, 0x2b, 0x35, 0xd8, 0xb4, 0x5b, 0x4b, 0x3e, + 0x93, 0x96, 0x59, 0xf8, 0x96, 0x7e, 0x7b, 0x27, 0xf4, 0x62, 0xb7, 0xda, + 0x89, 0xa7, 0x34, 0x47, 0xed, 0xb3, 0x42, 0x20, 0xeb, 0xcd, 0xf6, 0xa3, + 0x9f, 0xf7, 0x48, 0x91, 0x17, 0xd2, 0x21, 0xed, 0x5a, 0x22, 0x39, 0xc9, + 0x76, 0x95, 0x36, 0xd9, 0x97, 0x0f, 0x19, 0xce, 0xd3, 0xbc, 0x74, 0x7d, + 0x53, 0x37, 0x3b, 0x4a, 0x97, 0xb7, 0xf8, 0x7e, 0xdd, 0x4c, 0x5f, 0xae, + 0x5c, 0x0b, 0xab, 0x4c, 0x34, 0xa1, 0x7e, 0x34, 0x35, 0xf4, 0xfc, 0x92, + 0xab, 0x2e, 0x6a, 0x15, 0xce, 0x84, 0xae, 0x70, 0xae, 0x85, 0x21, 0xe6, + 0x41, 0x13, 0x31, 0xe0, 0x8f, 0xab, 0x82, 0xe3, 0x09, 0xaf, 0xa4, 0x7c, + 0xb4, 0xb9, 0xb7, 0xc0, 0x67, 0x08, 0xc9, 0x9d, 0xcd, 0x0b, 0x3c, 0xa0, + 0x0c, 0xde, 0x49, 0x2f, 0x40, 0x19, 0x95, 0x64, 0xb9, 0x7c, 0x2a, 0x72, + 0xdd, 0xa2, 0x92, 0x0a, 0x21, 0xeb, 0x8c, 0xc3, 0x6d, 0x52, 0xe7, 0x05, + 0x50, 0x01, 0x55, 0x19, 0x2f, 0xbd, 0x1b, 0x72, 0x73, 0xfe, 0x82, 0x9f, + 0xbf, 0xa0, 0xfe, 0x19, 0x7c, 0x42, 0x6d, 0x76, 0x32, 0x47, 0x36, 0x15, + 0x2e, 0xde, 0xe8, 0xe6, 0xca, 0x07, 0xa3, 0x6b, 0x40, 0x99, 0x96, 0xcd, + 0x19, 0xea, 0x7e, 0xc9, 0x87, 0x9d, 0x3d, 0xa0, 0x82, 0x88, 0xe7, 0xe4, + 0x34, 0x9f, 0xa5, 0x27, 0xdf, 0xae, 0x03, 0x37, 0xa8, 0x35, 0x64, 0x02, + 0x09, 0x09, 0x9e, 0xec, 0x38, 0x0a, 0xff, 0x79, 0x8c, 0x9a, 0x87, 0x66, + 0xcd, 0xe4, 0xf4, 0x9d, 0xa9, 0x07, 0x96, 0x36, 0xae, 0x2e, 0x4e, 0xc5, + 0xe9, 0x86, 0xb2, 0x8e, 0x71, 0x5d, 0xe8, 0xee, 0x84, 0xf3, 0x30, 0x2a, + 0x58, 0x1a, 0x80, 0xb8, 0xaa, 0xb8, 0x1d, 0xc4, 0xae, 0x59, 0x91, 0xf3, + 0x16, 0x9b, 0xa3, 0x8a, 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f5, 0xb2, 0x70, 0x9f, 0x0e, 0xfb, + 0x46, 0x8a, 0x69, 0xbf, 0x07, 0x92, 0xdc, 0x74, 0x03, 0x70, 0xc6, 0x44, + 0x81, 0x66, 0x40, 0xc7, 0xf5, 0xb8, 0xf0, 0x45, 0x0f, 0xca, 0xd8, 0xb0, + 0x9e, 0x48, 0x94, 0xff, 0x85, 0xcb, 0x7b, 0xec, 0x67, 0x5d, 0xfe, 0xe9, + 0x13, 0xd1, 0x67, 0x95, 0xd9, 0x35, 0x9e, 0x8a, 0x53, 0x4d, 0x6b, 0x9d, + 0x42, 0x53, 0xb1, 0x6b, 0x51, 0x1e, 0x35, 0x40, 0x81, 0x92, 0x91, 0x5f, + 0x1f, 0x8e, 0xbe, 0x37, 0xd3, 0x85, 0xab, 0x85, 0x37, 0x1c, 0x0f, 0xae, + 0xd9, 0xf7, 0xa2, 0x75, 0x3d, 0xd9, 0xd7, 0x2a, 0x80, 0xb0, 0x4c, 0x14, + 0x04, 0x40, 0xc5, 0xba, 0x0e, 0xbe, 0xab, 0xcc, 0x38, 0x35, 0x62, 0x6c, + 0xa5, 0xce, 0x49, 0x15, 0x2a, 0x10, 0xb5, 0x6a, 0xd2, 0x3b, 0xd2, 0x6a, + 0xad, 0x2e, 0x34, 0x46, 0x8b, 0x78, 0x57, 0x6e, 0xc4, 0xde, 0x65, 0x68, + 0x05, 0x8f, 0xd6, 0x6e, 0x34, 0xb9, 0xaa, 0x80, 0x77, 0xff, 0x6c, 0x1a, + 0x37, 0x87, 0xdd, 0x33, 0x13, 0x33, 0xa7, 0xa9, 0x3a, 0x90, 0x32, 0x7b, + 0x9b, 0x21, 0x31, 0xc8, 0xf5, 0x4c, 0xa6, 0x73, 0x42, 0x79, 0x46, 0x14, + 0x1b, 0xef, 0xf4, 0x78, 0xd9, 0x7e, 0x6f, 0x31, 0xaa, 0x59, 0x97, 0x34, + 0xe5, 0xe6, 0x67, 0xf3, 0x86, 0xf5, 0x61, 0xe7, 0x51, 0x6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1e, + 0xdd, 0xe6, 0xfa, 0x54, 0x6e, 0x38, 0x30, 0x6f, 0xcc, 0xa4, 0x8d, 0x76, + 0x1e, 0xa3, 0x8e, 0x2c, 0x5e, 0x37, 0xeb, 0x0b, 0xf4, 0xb5, 0x80, 0xde, + 0x58, 0x13, 0x5a, 0x52, 0xdc, 0x65, 0x99, 0x1a, 0x1b, 0x75, 0x0c, 0xbd, + 0x83, 0xe8, 0x90, 0x8e, 0xa9, 0xbf, 0x42, 0x22, 0xe1, 0x3a, 0x31, 0x4e, + 0x54, 0xad, 0xd4, 0x6f, 0x80, 0xb4, 0xb5, 0x82, 0x05, 0x20, 0xd7, 0x38, + 0xd7, 0xeb, 0x25, 0x33, 0xe9, 0x4b, 0xc3, 0x5e, 0xd1, 0x11, 0xb0, 0xd9, + 0x8e, 0x90, 0x48, 0x2a, 0xe3, 0xa0, 0x60, 0x16, 0x70, 0xe3, 0xd1, 0x45, + 0x11, 0x64, 0x91, 0x69, 0x87, 0x1c, 0xbb, 0x91, 0xc4, 0x43, 0x12, 0x62, + 0x99, 0x69, 0xe5, 0x96, 0x01, 0x15, 0xdb, 0xdf, 0x05, 0x55, 0x34, 0xbb, + 0xd6, 0x76, 0x89, 0xcd, 0xb5, 0x4f, 0x2e, 0xa7, 0x6e, 0x15, 0xc9, 0xc0, + 0x8e, 0xa8, 0x63, 0x79, 0x12, 0xfb, 0x7e, 0x69, 0x8f, 0x52, 0x5e, 0xe7, + 0x76, 0x16, 0x28, 0x76, 0xca, 0xcb, 0xd8, 0x0e, 0x4a, 0x93, 0x9d, 0x16, + 0x68, 0x98, 0xf8, 0xc3, 0x39, 0xb2, 0x2d, 0xea, 0xba, 0x72, 0x16, 0x33, + 0xb7, 0xec, 0x61, 0x9e, 0x94, 0x32, 0x01, 0x22, 0xde, 0x66, 0xfd, 0x68, + 0xfa, 0xcf, 0xf2, 0x52, 0x4f, 0x02, 0xe8, 0x25, 0xd3, 0xa3, 0x5b, 0x29, + 0xae, 0xe9, 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0xab, 0xda, 0xb3, 0x74, 0x39, 0xd2, 0xf8, + 0x2d, 0xef, 0x9b, 0x0f, 0xae, 0xf5, 0x3c, 0x99, 0x34, 0xbe, 0x15, 0x5c, + 0x9f, 0x5d, 0xae, 0xf4, 0x72, 0xc2, 0xac, 0x06, 0xbe, 0xad, 0xe4, 0x68, + 0xea, 0xd5, 0xa1, 0xdc, 0xdb, 0xf4, 0x61, 0x51, 0xf5, 0x1a, 0x62, 0x15, + 0xfd, 0x00, 0x51, 0x35, 0x53, 0x6c, 0x39, 0x3e, 0xdb, 0x60, 0x0a, 0x52, + 0xc1, 0x52, 0x3c, 0xd7, 0xab, 0x73, 0xea, 0x1e, 0x38, 0x38, 0x65, 0x35, + 0x35, 0x2b, 0x28, 0x04, 0x5c, 0x82, 0xea, 0x4a, 0x9e, 0x96, 0x72, 0xa4, + 0x8e, 0x42, 0xfd, 0x55, 0xa8, 0x66, 0x7a, 0x40, 0xc9, 0xf2, 0xc2, 0x1e, + 0x5d, 0x09, 0x90, 0x32, 0x18, 0xdb, 0x11, 0x4c, 0x6c, 0x9c, 0x27, 0x62, + 0x0a, 0xe6, 0xc1, 0xdf, 0xf2, 0x6a, 0x8c, 0x26, 0xb4, 0xfb, 0xda, 0xa9, + 0x08, 0x10, 0x3a, 0xf0, 0xe1, 0x64, 0xe5, 0x03, 0x81, 0x7d, 0x15, 0x74, + 0xa1, 0x8d, 0x10, 0xc8, 0xbb, 0x6a, 0x7c, 0x60, 0xa1, 0x09, 0x35, 0x19, + 0x2d, 0x70, 0xb5, 0x36, 0xc8, 0x8b, 0x66, 0x5f, 0xe0, 0xe7, 0xea, 0x70, + 0x2f, 0x5d, 0x3f, 0xae, 0x5e, 0x25, 0x84, 0xdd, 0x9b, 0x69, 0x44, 0x37, + 0x7c, 0x6b, 0x9e, 0x81, 0x18, 0x36, 0x4b, 0xff, 0x86, 0x44, 0x2a, 0x39, + 0x66, 0x7f, 0x71, 0x43, 0xe7, 0x65, 0xfe, 0xfd, 0x34, 0xb9, 0xd9, 0x5a, + 0x00, 0xd1, 0x41, 0x43, 0xc7, 0xbc, 0x65, 0x68, 0xb7, 0x73, 0xff, 0x19, + 0xd3, 0xed, 0x15, 0xa4, 0x67, 0xa1, 0x53, 0x0e, 0xa6, 0xfb, 0x25, 0xce, + 0x9d, 0x5b, 0x73, 0x08, 0xf3, 0x3b, 0x69, 0xe4, 0x94, 0x9b, 0x94, 0x03, + 0xb3, 0x8a, 0x2e, 0x07, 0x0c, 0xef, 0x18, 0x4c, 0x2b, 0x1c, 0x83, 0x9f, + 0x25, 0x20, 0x29, 0x72, 0x11, 0xa0, 0xaa, 0xed, 0x0c, 0xf9, 0xce, 0x94, + 0x0d, 0x7a, 0xb6, 0xb3, 0xa4, 0x57, 0xd6, 0x61, 0xca, 0x1a, 0x0e, 0x89, + 0x6d, 0x99, 0x4d, 0x06, 0xcd, 0x83, 0x7e, 0x09, 0x14, 0x5b, 0xe7, 0x4c, + 0x72, 0xa8, 0x98, 0xc8, 0x27, 0xf3, 0x70, 0x89, 0x87, 0x11, 0xbb, 0x98, + 0x82, 0x77, 0x9d, 0xaa, 0x95, 0x8c, 0xc1, 0xf8, 0x39, 0x27, 0xd5, 0x64, + 0x59, 0x6a, 0x8c, 0xbe, 0xe2, 0xe1, 0xd1, 0x6b, 0xe3, 0xaf, 0x30, 0x6f, + 0xf4, 0x9e, 0x35, 0x0b, 0x10, 0x24, 0x77, 0xd8, 0xa4, 0x30, 0x2e, 0xf7, + 0x97, 0xfd, 0xef, 0x1e, 0x9e, 0xf2, 0xbd, 0xf2, 0x41, 0x73, 0x19, 0xe6, + 0x7b, 0x7f, 0x74, 0x11, 0x91, 0x38, 0xc5, 0xac, 0xd5, 0xb0, 0x48, 0xc4, + 0xe9, 0x41, 0xd4, 0x50, 0x76, 0x13, 0xbf, 0xec, 0xe8, 0x3a, 0xa8, 0x84, + 0x42, 0x98, 0x12, 0x64, 0x95, 0x85, 0x79, 0x29, 0xea, 0x3a, 0xf9, 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f, 0x32, 0x95, 0xc5, 0xcc, 0xad, 0xee, 0x30, 0x23, + 0x7c, 0x54, 0xea, 0x60, 0xb8, 0x88, 0x12, 0x45, 0x03, 0xbc, 0xe3, 0x92, + 0x9f, 0xa8, 0x5b, 0x07, 0x97, 0x53, 0x0d, 0xe1, 0xe3, 0x3d, 0xdf, 0xf2, + 0x2a, 0x12, 0xee, 0xdf, 0x73, 0x8d, 0x41, 0xf4, 0xe4, 0x2c, 0xb4, 0xd4, + 0x9e, 0xfe, 0xf2, 0xe6, 0xa0, 0x9e, 0x2a, 0x3a, 0x36, 0x26, 0x7e, 0xd9, + 0xe1, 0x22, 0xee, 0x0b, 0x5b, 0x48, 0xd2, 0xa9, 0x55, 0xab, 0x50, 0x7c, + 0xf6, 0xc8, 0x56, 0x31, 0xbb, 0x51, 0xe9, 0x31, 0x4d, 0xaa, 0x13, 0x3a, + 0x99, 0x9f, 0x8c, 0x59, 0x6a, 0xc9, 0xf1, 0x0a, 0x89, 0xcc, 0x39, 0x98, + 0xbd, 0xc3, 0x93, 0x97, 0x28, 0xe5, 0x73, 0x94, 0xf2, 0x0a, 0x7a, 0x09, + 0x38, 0x0b, 0xab, 0xd8, 0x49, 0x98, 0x14, 0x34, 0x32, 0x9d, 0xef, 0x9d, + 0x47, 0xdb, 0x82, 0xb9, 0x84, 0xd6, 0xd7, 0x9f, 0xf7, 0xdf, 0x79, 0x5b, + 0xe8, 0x92, 0x44, 0x31, 0x5d, 0x42, 0x80, 0x90, 0x8d, 0x36, 0xa2, 0x39, + 0x02, 0x64, 0x21, 0xa2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xa4, 0xfc, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x10, 0xea, 0xff, 0xff, + 0xfc, 0x03, 0x00, 0x00, 0xf0, 0x03, 0x00, 0x00, 0xe4, 0x03, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xb8, 0x03, 0x00, 0x00, + 0x60, 0x03, 0x00, 0x00, 0x14, 0x03, 0x00, 0x00, 0xbc, 0x02, 0x00, 0x00, + 0x84, 0x02, 0x00, 0x00, 0x3c, 0x02, 0x00, 0x00, 0x04, 0x02, 0x00, 0x00, + 0xbc, 0x01, 0x00, 0x00, 0x84, 0x01, 0x00, 0x00, 0x3c, 0x01, 0x00, 0x00, + 0xf4, 0x00, 0x00, 0x00, 0xac, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, + 0x38, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x8e, 0xfc, 0xff, 0xff, + 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x35, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x1a, 0x00, 0x08, 0x00, + 0x0c, 0x00, 0x10, 0x00, 0x07, 0x00, 0x14, 0x00, 0x0e, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x09, 0x0c, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, + 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, + 0x01, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x32, 0x00, 0x00, 0x00, 0x96, 0xfd, 0xff, 0xff, 0x00, 0x00, 0x00, 0x08, + 0x0b, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x88, 0xfd, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, + 0x32, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0xca, 0xfd, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x06, 0x0a, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x78, 0xfd, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x2f, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, + 0x2b, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x00, 0x00, + 0x2e, 0x00, 0x00, 0x00, 0x0e, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x06, + 0x09, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xbc, 0xfd, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, + 0x27, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, + 0x52, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x06, 0x08, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, + 0x23, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x96, 0xfe, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x08, 0x07, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x88, 0xfe, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x1d, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, + 0xca, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x06, 0x06, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x78, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, + 0x1b, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x0e, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x08, 0x05, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x15, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, + 0x42, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x06, 0x04, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xf0, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, + 0x13, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x86, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x08, 0x03, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x78, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x0d, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, + 0xba, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x06, 0x02, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x68, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, + 0x0b, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, + 0x18, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x07, 0x00, 0x14, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x01, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x10, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x28, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, + 0x08, 0x00, 0x07, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0a, 0x00, 0x10, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, + 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x35, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, + 0x36, 0x00, 0x00, 0x00, 0xdc, 0x11, 0x00, 0x00, 0x70, 0x11, 0x00, 0x00, + 0x04, 0x11, 0x00, 0x00, 0xa8, 0x10, 0x00, 0x00, 0x5c, 0x10, 0x00, 0x00, + 0xf4, 0x0f, 0x00, 0x00, 0x94, 0x0f, 0x00, 0x00, 0x50, 0x0f, 0x00, 0x00, + 0xf8, 0x0e, 0x00, 0x00, 0x98, 0x0e, 0x00, 0x00, 0x3c, 0x0e, 0x00, 0x00, + 0xe0, 0x0d, 0x00, 0x00, 0xa0, 0x0d, 0x00, 0x00, 0x44, 0x0d, 0x00, 0x00, + 0xe4, 0x0c, 0x00, 0x00, 0xa0, 0x0c, 0x00, 0x00, 0x48, 0x0c, 0x00, 0x00, + 0xe8, 0x0b, 0x00, 0x00, 0x8c, 0x0b, 0x00, 0x00, 0x30, 0x0b, 0x00, 0x00, + 0xf0, 0x0a, 0x00, 0x00, 0x94, 0x0a, 0x00, 0x00, 0x34, 0x0a, 0x00, 0x00, + 0xf0, 0x09, 0x00, 0x00, 0x98, 0x09, 0x00, 0x00, 0x38, 0x09, 0x00, 0x00, + 0xdc, 0x08, 0x00, 0x00, 0x80, 0x08, 0x00, 0x00, 0x40, 0x08, 0x00, 0x00, + 0xe4, 0x07, 0x00, 0x00, 0x84, 0x07, 0x00, 0x00, 0x40, 0x07, 0x00, 0x00, + 0xe8, 0x06, 0x00, 0x00, 0x88, 0x06, 0x00, 0x00, 0x2c, 0x06, 0x00, 0x00, + 0xd0, 0x05, 0x00, 0x00, 0x90, 0x05, 0x00, 0x00, 0x34, 0x05, 0x00, 0x00, + 0xd4, 0x04, 0x00, 0x00, 0x78, 0x04, 0x00, 0x00, 0x1c, 0x04, 0x00, 0x00, + 0xdc, 0x03, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x20, 0x03, 0x00, 0x00, + 0xc4, 0x02, 0x00, 0x00, 0x68, 0x02, 0x00, 0x00, 0x28, 0x02, 0x00, 0x00, + 0xcc, 0x01, 0x00, 0x00, 0x6c, 0x01, 0x00, 0x00, 0x28, 0x01, 0x00, 0x00, + 0xd0, 0x00, 0x00, 0x00, 0x8c, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x0a, 0xef, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, + 0x2c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6c, 0xf0, 0xff, 0xff, + 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x38, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x4a, 0xef, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x07, 0x2c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xac, 0xf0, 0xff, 0xff, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0a, 0xd7, 0x23, 0x3a, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, + 0x8a, 0xef, 0xff, 0xff, 0x00, 0x00, 0x00, 0x07, 0x2c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xec, 0xf0, 0xff, 0xff, 0x18, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x80, 0x00, 0x80, 0x37, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0xca, 0xef, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, + 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xbc, 0xef, 0xff, 0xff, + 0x2c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x9f, 0x48, 0x8f, 0x3d, + 0x01, 0x00, 0x00, 0x00, 0x2f, 0xd9, 0x0b, 0x41, 0x01, 0x00, 0x00, 0x00, + 0x7e, 0x99, 0x11, 0xc1, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x86, 0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, + 0x30, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x84, 0xf1, 0xff, 0xff, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x44, 0xab, 0x0b, 0x3a, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xc6, 0xf0, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x09, 0x48, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x54, 0xf0, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x23, 0x20, 0xb6, 0x3b, + 0x01, 0x00, 0x00, 0x00, 0xe3, 0xb3, 0x34, 0x3f, 0x01, 0x00, 0x00, 0x00, + 0xe6, 0x5c, 0x12, 0xbf, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0xba, 0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, + 0x44, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xac, 0xf0, 0xff, 0xff, + 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x75, 0x52, 0xc4, 0x3d, 0x01, 0x00, 0x00, 0x00, 0x23, 0x8e, 0xc3, 0x41, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x84, 0xf2, 0xff, 0xff, + 0x00, 0x00, 0x07, 0x01, 0x28, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x74, 0xf2, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xe4, 0xb1, 0x2c, 0x3a, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0xb6, 0xf1, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x02, 0x48, 0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x44, 0xf1, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xc5, 0xcf, 0xd7, 0x35, + 0x01, 0x00, 0x00, 0x00, 0x8c, 0xcd, 0x6b, 0x3f, 0x01, 0x00, 0x00, 0x00, + 0x14, 0xd8, 0xc4, 0xbe, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x0e, 0xf2, 0xff, 0xff, 0x00, 0x00, 0x00, 0x07, 0x44, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x9c, 0xf1, 0xff, 0xff, + 0x2c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2f, 0xf5, 0x1f, 0x3b, + 0x01, 0x00, 0x00, 0x00, 0x53, 0x17, 0x59, 0x3f, 0x01, 0x00, 0x00, 0x00, + 0x2f, 0xf5, 0x9f, 0xbf, 0x02, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x66, 0xf2, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, + 0x48, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xf4, 0xf1, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xc7, 0xea, 0x1a, 0x3c, 0x01, 0x00, 0x00, 0x00, + 0xf1, 0xb4, 0x99, 0x3f, 0x01, 0x00, 0x00, 0x00, 0x93, 0x3e, 0x49, 0xbf, + 0x02, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x5a, 0xf2, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, 0x44, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x4c, 0xf2, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x9c, 0x67, 0x85, 0x3d, + 0x01, 0x00, 0x00, 0x00, 0x34, 0xe2, 0x84, 0x41, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x24, 0xf4, 0xff, 0xff, 0x00, 0x00, 0x07, 0x01, + 0x28, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x14, 0xf4, 0xff, 0xff, + 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x0f, 0xa3, 0x06, 0x3a, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x04, 0x00, 0x00, 0x56, 0xf3, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, + 0x48, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xe4, 0xf2, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x31, 0x1b, 0xa1, 0x35, 0x01, 0x00, 0x00, 0x00, + 0x5c, 0xcf, 0x87, 0x3f, 0x01, 0x00, 0x00, 0x00, 0xa0, 0xa5, 0xe6, 0xbe, + 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xae, 0xf3, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x07, 0x44, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x3c, 0xf3, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x1a, 0x2a, 0x19, 0x3b, 0x01, 0x00, 0x00, 0x00, + 0x62, 0xbf, 0x8c, 0x3f, 0x01, 0x00, 0x00, 0x00, 0x1a, 0x2a, 0x99, 0xbf, + 0x02, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x06, 0xf4, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, 0x48, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x94, 0xf3, 0xff, 0xff, + 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0xe9, 0x36, 0xdd, 0x3b, 0x01, 0x00, 0x00, 0x00, 0x7b, 0x7c, 0x5b, 0x3f, + 0x01, 0x00, 0x00, 0x00, 0x4f, 0x8e, 0x37, 0xbf, 0x02, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xfa, 0xf3, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x09, 0x44, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xec, 0xf3, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x57, 0x66, 0xa3, 0x3d, 0x01, 0x00, 0x00, 0x00, + 0xf1, 0xc2, 0xa2, 0x41, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0xc4, 0xf5, 0xff, 0xff, 0x00, 0x00, 0x07, 0x01, 0x28, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xb4, 0xf5, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x90, 0xd6, 0x03, 0x3a, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, + 0xf6, 0xf4, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, 0x48, 0x00, 0x00, 0x00, + 0x17, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x84, 0xf4, 0xff, 0xff, + 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x39, 0x9e, 0xa3, 0x35, 0x01, 0x00, 0x00, 0x00, 0xef, 0xc9, 0x24, 0x3f, + 0x01, 0x00, 0x00, 0x00, 0xbf, 0xb3, 0x75, 0xbf, 0x01, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x4e, 0xf5, 0xff, 0xff, 0x00, 0x00, 0x00, 0x07, + 0x44, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xdc, 0xf4, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0xd0, 0xda, 0x1e, 0x3b, 0x01, 0x00, 0x00, 0x00, 0xc5, 0x6e, 0x84, 0x3f, + 0x01, 0x00, 0x00, 0x00, 0xd0, 0xda, 0x9e, 0xbf, 0x02, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xa6, 0xf5, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x09, 0x48, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x34, 0xf5, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x8e, 0x0b, 0xa8, 0x3b, + 0x01, 0x00, 0x00, 0x00, 0x5f, 0x8a, 0x23, 0x3f, 0x01, 0x00, 0x00, 0x00, + 0x77, 0xbb, 0x26, 0xbf, 0x02, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x9a, 0xf5, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, + 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x8c, 0xf5, 0xff, 0xff, + 0x2c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x98, 0x1d, 0x9d, 0x3d, + 0x01, 0x00, 0x00, 0x00, 0x9e, 0x3f, 0x1e, 0x41, 0x01, 0x00, 0x00, 0x00, + 0x56, 0xc1, 0x1a, 0xc1, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x56, 0xf6, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, + 0x30, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x54, 0xf7, 0xff, 0xff, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xb6, 0xf7, 0x5d, 0x39, + 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x96, 0xf6, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x09, 0x48, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x24, 0xf6, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xa4, 0x34, 0xab, 0x3b, + 0x01, 0x00, 0x00, 0x00, 0x12, 0xea, 0x23, 0x3f, 0x01, 0x00, 0x00, 0x00, + 0x3b, 0xde, 0x29, 0xbf, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x8a, 0xf6, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, + 0x44, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x7c, 0xf6, 0xff, 0xff, + 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x9f, 0xf3, 0x25, 0x3d, 0x01, 0x00, 0x00, 0x00, 0xab, 0x4d, 0x25, 0x41, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x54, 0xf8, 0xff, 0xff, + 0x00, 0x00, 0x07, 0x01, 0x28, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x44, 0xf8, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x8b, 0xd3, 0x0d, 0x3a, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x86, 0xf7, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x02, 0x48, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x14, 0xf7, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xb2, 0xe0, 0x57, 0x35, + 0x01, 0x00, 0x00, 0x00, 0x60, 0x08, 0x1d, 0x3f, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x97, 0x0f, 0xbf, 0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0xde, 0xf7, 0xff, 0xff, 0x00, 0x00, 0x00, 0x07, 0x44, 0x00, 0x00, 0x00, + 0x11, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6c, 0xf7, 0xff, 0xff, + 0x2c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0xd5, 0xc2, 0x3a, + 0x01, 0x00, 0x00, 0x00, 0x10, 0xd5, 0x42, 0x3f, 0x01, 0x00, 0x00, 0x00, + 0x1a, 0x4c, 0x1d, 0xbf, 0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x36, 0xf8, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, + 0x48, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xc4, 0xf7, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x8f, 0x84, 0xa2, 0x3b, 0x01, 0x00, 0x00, 0x00, + 0xb0, 0x34, 0x21, 0x3f, 0x01, 0x00, 0x00, 0x00, 0x86, 0x3f, 0x21, 0xbf, + 0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x2a, 0xf8, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, 0x40, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x1c, 0xf8, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xf3, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0xfd, 0x5a, 0x12, 0x3e, 0x01, 0x00, 0x00, 0x00, + 0x1d, 0xcf, 0x9f, 0x41, 0x01, 0x00, 0x00, 0x00, 0x28, 0xc2, 0x83, 0xc1, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0xe6, 0xf8, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, 0x30, 0x00, 0x00, 0x00, + 0x0f, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xe4, 0xf9, 0xff, 0xff, + 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xbc, 0x09, 0xdf, 0x39, 0x01, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x26, 0xf9, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, + 0x48, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xb4, 0xf8, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x58, 0x76, 0xb9, 0x3b, 0x01, 0x00, 0x00, 0x00, + 0x6b, 0x03, 0x38, 0x3f, 0x01, 0x00, 0x00, 0x00, 0x43, 0x4b, 0x2e, 0xbf, + 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x1a, 0xf9, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, 0x44, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x0c, 0xf9, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xfd, 0xee, 0x99, 0x3d, + 0x01, 0x00, 0x00, 0x00, 0x0e, 0x55, 0x99, 0x41, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, 0xe4, 0xfa, 0xff, 0xff, 0x00, 0x00, 0x07, 0x01, + 0x28, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xd4, 0xfa, 0xff, 0xff, + 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x26, 0xcb, 0xbb, 0x3a, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x02, 0x00, 0x00, 0x16, 0xfa, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, + 0x48, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xa4, 0xf9, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x15, 0x16, 0x17, 0x36, 0x01, 0x00, 0x00, 0x00, + 0xd0, 0x8a, 0x49, 0x3f, 0x01, 0x00, 0x00, 0x00, 0x55, 0xb3, 0x10, 0xbf, + 0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x6e, 0xfa, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x07, 0x44, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xfc, 0xf9, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xed, 0xf5, 0xcd, 0x3a, 0x01, 0x00, 0x00, 0x00, + 0xed, 0xf5, 0x4d, 0x3f, 0x01, 0x00, 0x00, 0x00, 0x9c, 0x34, 0x35, 0xbf, + 0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0xc6, 0xfa, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, 0x48, 0x00, 0x00, 0x00, + 0x0b, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x54, 0xfa, 0xff, 0xff, + 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x9d, 0xca, 0xd4, 0x3b, 0x01, 0x00, 0x00, 0x00, 0x7c, 0xc5, 0x40, 0x3f, + 0x01, 0x00, 0x00, 0x00, 0x08, 0x21, 0x53, 0xbf, 0x02, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0xba, 0xfa, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x09, 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xac, 0xfa, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, + 0xe2, 0x1f, 0x5d, 0x3e, 0x01, 0x00, 0x00, 0x00, 0x69, 0x49, 0xe9, 0x41, + 0x01, 0x00, 0x00, 0x00, 0x1c, 0x3c, 0xcf, 0xc1, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x76, 0xfb, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x02, 0x30, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x74, 0xfc, 0xff, 0xff, 0x18, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x66, 0xc3, 0x4d, 0x3a, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0xb6, 0xfb, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, 0x48, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x44, 0xfb, 0xff, 0xff, + 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0xf8, 0xb6, 0xc3, 0x3b, 0x01, 0x00, 0x00, 0x00, 0x8a, 0x2f, 0x42, 0x3f, + 0x01, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x24, 0xbf, 0x02, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0xaa, 0xfb, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x09, 0x44, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x9c, 0xfb, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x67, 0x92, 0x06, 0x3e, 0x01, 0x00, 0x00, 0x00, + 0xd5, 0x0b, 0x06, 0x42, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x74, 0xfd, 0xff, 0xff, 0x00, 0x00, 0x07, 0x01, 0x28, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x64, 0xfd, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xb7, 0xbe, 0xf0, 0x3a, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, + 0xa6, 0xfc, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, 0x48, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x34, 0xfc, 0xff, 0xff, + 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0xa6, 0xe2, 0x52, 0x36, 0x01, 0x00, 0x00, 0x00, 0x88, 0xb8, 0x36, 0x3f, + 0x01, 0x00, 0x00, 0x00, 0x1c, 0x81, 0x32, 0xbf, 0x01, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, 0xfe, 0xfc, 0xff, 0xff, 0x00, 0x00, 0x00, 0x07, + 0x44, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x8c, 0xfc, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x8f, 0x3f, 0xe0, 0x3a, 0x01, 0x00, 0x00, 0x00, 0x8f, 0x3f, 0x60, 0x3f, + 0x01, 0x00, 0x00, 0x00, 0x26, 0x23, 0x52, 0xbf, 0x02, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x56, 0xfd, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x09, 0x48, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xe4, 0xfc, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x25, 0xd7, 0xa9, 0x3b, + 0x01, 0x00, 0x00, 0x00, 0xfc, 0x9a, 0x19, 0x3f, 0x01, 0x00, 0x00, 0x00, + 0x77, 0x83, 0x28, 0xbf, 0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x4a, 0xfd, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, + 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x3c, 0xfd, 0xff, 0xff, + 0x2c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xf9, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x37, 0x36, 0xde, 0x3e, + 0x01, 0x00, 0x00, 0x00, 0x69, 0xf1, 0x67, 0x42, 0x01, 0x00, 0x00, 0x00, + 0x99, 0xbe, 0x52, 0xc2, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x06, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, + 0x30, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x04, 0xff, 0xff, 0xff, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x91, 0x0c, 0xb9, 0x3a, + 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x46, 0xfe, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x09, 0x48, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xd4, 0xfd, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xd7, 0xdf, 0xc3, 0x3b, + 0x01, 0x00, 0x00, 0x00, 0x17, 0x58, 0x42, 0x3f, 0x01, 0x00, 0x00, 0x00, + 0xa3, 0x73, 0x33, 0xbf, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x3a, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, + 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x2c, 0xfe, 0xff, 0xff, + 0x2c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x0e, 0xda, 0x71, 0x3e, + 0x01, 0x00, 0x00, 0x00, 0x34, 0xe8, 0x70, 0x42, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x08, 0x00, 0x06, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x07, 0x01, 0x34, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x9a, 0x33, 0x8f, 0x3b, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x4e, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x02, 0x48, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xdc, 0xfe, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xa6, 0xd7, 0x87, 0x37, + 0x01, 0x00, 0x00, 0x00, 0x38, 0x61, 0xb3, 0x3f, 0x01, 0x00, 0x00, 0x00, + 0xc7, 0x2b, 0x8c, 0xbf, 0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0xa6, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x07, 0x44, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x34, 0xff, 0xff, 0xff, + 0x2c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x14, 0xd8, 0x72, 0x3b, + 0x01, 0x00, 0x00, 0x00, 0xbe, 0x99, 0xea, 0x3f, 0x01, 0x00, 0x00, 0x00, + 0x14, 0xd8, 0xf2, 0xbf, 0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x08, 0x00, + 0x07, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0e, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x09, 0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x9c, 0xff, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xd4, 0x42, 0x16, 0x3c, 0x01, 0x00, 0x00, 0x00, + 0x09, 0x1f, 0x90, 0x3f, 0x01, 0x00, 0x00, 0x00, 0x4e, 0x16, 0x95, 0xbf, + 0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0e, 0x00, 0x10, 0x00, 0x08, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0c, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, + 0x4c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x14, 0x00, + 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x2c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x70, 0x84, 0x72, 0x3d, + 0x01, 0x00, 0x00, 0x00, 0xec, 0x91, 0x71, 0x41, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x60, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x30, 0x01, 0x00, 0x00, + 0x10, 0x01, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xe8, 0x00, 0x00, 0x00, + 0xd4, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xac, 0x00, 0x00, 0x00, + 0x98, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, + 0x5c, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x18, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x06, 0x02, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0x72, 0x00, 0x00, 0x00, + 0x40, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x19, 0x02, 0x00, 0x00, 0x00, + 0x19, 0x00, 0x00, 0x00, 0x50, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, + 0x04, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x60, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x1b, 0x03, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, + 0x70, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x1b, 0x03, 0x00, 0x00, 0x00, + 0x1b, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x1b, + 0x03, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x90, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x09, 0x04, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, + 0xa0, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x1b, 0x03, 0x00, 0x00, 0x00, + 0x1b, 0x00, 0x00, 0x00, 0xb0, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, + 0x04, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x1b, 0x03, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, + 0xd0, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, 0x04, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x1b, + 0x03, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x09, 0x04, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x10, 0x00, 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1b, 0x03, 0x00, 0x00, 0x00, + 0x1b, 0x00, 0x00, 0x00 +}; + +const unsigned int g_keyword_scrambled_model_data_length = 34576; diff --git a/components/tflite/tensorflow/lite/micro/benchmarks/keyword_scrambled_model_data.h b/components/tflite/tensorflow/lite/micro/benchmarks/keyword_scrambled_model_data.h new file mode 100644 index 00000000..754f6b75 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/benchmarks/keyword_scrambled_model_data.h @@ -0,0 +1,22 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_BENCHMARKS_KEYWORD_SCRAMBLED_MODEL_DATA_H_ +#define TENSORFLOW_LITE_MICRO_BENCHMARKS_KEYWORD_SCRAMBLED_MODEL_DATA_H_ + +extern const unsigned char g_keyword_scrambled_model_data[]; +extern const unsigned int g_keyword_scrambled_model_data_length; + +#endif // TENSORFLOW_LITE_MICRO_BENCHMARKS_KEYWORD_SCRAMBLED_MODEL_DATA_H_ diff --git a/components/tflite/tensorflow/lite/micro/benchmarks/micro_benchmark.h b/components/tflite/tensorflow/lite/micro/benchmarks/micro_benchmark.h new file mode 100644 index 00000000..bbbee1d5 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/benchmarks/micro_benchmark.h @@ -0,0 +1,90 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_BENCHMARKS_MICRO_BENCHMARK_H_ +#define TENSORFLOW_LITE_MICRO_BENCHMARKS_MICRO_BENCHMARK_H_ + +#include + +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/micro_op_resolver.h" +#include "tensorflow/lite/micro/micro_profiler.h" +#include "tensorflow/lite/micro/micro_time.h" +#include "tensorflow/lite/micro/recording_micro_interpreter.h" + +namespace tflite { +template +class MicroBenchmarkRunner { +public: + // The lifetimes of model, op_resolver, tensor_arena, profiler must exceed + // that of the created MicroBenchmarkRunner object. + MicroBenchmarkRunner(const uint8_t *model, + const tflite::MicroOpResolver *op_resolver, + uint8_t *tensor_arena, int tensor_arena_size, + MicroProfiler *profiler) + : interpreter_(GetModel(model), *op_resolver, tensor_arena, + tensor_arena_size, GetMicroErrorReporter(), profiler) + { + interpreter_.AllocateTensors(); + } + + void RunSingleIteration() + { + // Run the model on this input and make sure it succeeds. + TfLiteStatus invoke_status = interpreter_.Invoke(); + if (invoke_status == kTfLiteError) { + MicroPrintf("Invoke failed."); + } + } + + void SetRandomInput(const int random_seed) + { + // The pseudo-random number generator is initialized to a constant seed + std::srand(random_seed); + TfLiteTensor *input = interpreter_.input(0); + + // Pre-populate input tensor with random values. + int input_length = input->bytes / sizeof(inputT); + inputT *input_values = tflite::GetTensorData(input); + for (int i = 0; i < input_length; i++) { + // Pre-populate input tensor with a random value based on a constant seed. + input_values[i] = static_cast( + std::rand() % (std::numeric_limits::max() - + std::numeric_limits::min() + 1)); + } + } + + void SetInput(const inputT *custom_input) + { + TfLiteTensor *input = interpreter_.input(0); + inputT *input_buffer = tflite::GetTensorData(input); + int input_length = input->bytes / sizeof(inputT); + for (int i = 0; i < input_length; i++) { + input_buffer[i] = custom_input[i]; + } + } + + void PrintAllocations() const + { + interpreter_.GetMicroAllocator().PrintAllocations(); + } + +private: + tflite::RecordingMicroInterpreter interpreter_; +}; + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_BENCHMARKS_MICRO_BENCHMARK_H_ diff --git a/components/tflite/tensorflow/lite/micro/benchmarks/person_detection_benchmark.cc b/components/tflite/tensorflow/lite/micro/benchmarks/person_detection_benchmark.cc new file mode 100644 index 00000000..e70e57bb --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/benchmarks/person_detection_benchmark.cc @@ -0,0 +1,122 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/benchmarks/micro_benchmark.h" +#include "tensorflow/lite/micro/examples/person_detection/model_settings.h" +#include "tensorflow/lite/micro/examples/person_detection/no_person_image_data.h" +#include "tensorflow/lite/micro/examples/person_detection/person_detect_model_data.h" +#include "tensorflow/lite/micro/examples/person_detection/person_image_data.h" +#include "tensorflow/lite/micro/kernels/conv.h" +#include "tensorflow/lite/micro/kernels/fully_connected.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/micro_interpreter.h" +#include "tensorflow/lite/micro/micro_mutable_op_resolver.h" +#include "tensorflow/lite/micro/micro_utils.h" +#include "tensorflow/lite/micro/system_setup.h" +#include "tensorflow/lite/schema/schema_generated.h" + +/* + * Person Detection benchmark. Evaluates runtime performance of the visual + * wakewords person detection model. This is the same model found in + * exmaples/person_detection. + */ + +namespace tflite { + +using PersonDetectionOpResolver = MicroMutableOpResolver<6>; +using PersonDetectionBenchmarkRunner = MicroBenchmarkRunner; + +// Create an area of memory to use for input, output, and intermediate arrays. +// Align arena to 16 bytes to avoid alignment warnings on certain platforms. +constexpr int kTensorArenaSize = 135 * 1024; +alignas(16) uint8_t tensor_arena[kTensorArenaSize]; + +uint8_t op_resolver_buffer[sizeof(PersonDetectionOpResolver)]; +uint8_t benchmark_runner_buffer[sizeof(PersonDetectionBenchmarkRunner)]; + +// Initialize benchmark runner instance explicitly to avoid global init order +// issues on Sparkfun. Use new since static variables within a method +// are automatically surrounded by locking, which breaks bluepill and stm32f4. +PersonDetectionBenchmarkRunner *CreateBenchmarkRunner(MicroProfiler *profiler) +{ + // We allocate PersonDetectionOpResolver from a global buffer + // because the object's lifetime must exceed that of the + // PersonDetectionBenchmarkRunner object. + PersonDetectionOpResolver *op_resolver = + new (op_resolver_buffer) PersonDetectionOpResolver(); + op_resolver->AddFullyConnected(tflite::Register_FULLY_CONNECTED_INT8()); + op_resolver->AddConv2D(tflite::Register_CONV_2D_INT8REF()); + op_resolver->AddDepthwiseConv2D(); + op_resolver->AddSoftmax(); + op_resolver->AddAveragePool2D(); + op_resolver->AddReshape(); + return new (benchmark_runner_buffer) + PersonDetectionBenchmarkRunner(g_person_detect_model_data, op_resolver, + tensor_arena, kTensorArenaSize, profiler); +} + +void PersonDetectionNIerations(const int8_t *input, int iterations, + const char *tag, + PersonDetectionBenchmarkRunner &benchmark_runner, + MicroProfiler &profiler) +{ + benchmark_runner.SetInput(input); + uint32_t ticks = 0; + for (int i = 0; i < iterations; ++i) { + profiler.ClearEvents(); + benchmark_runner.RunSingleIteration(); + ticks += profiler.GetTotalTicks(); + } + MicroPrintf("%s took %u ticks (%u ms)", tag, ticks, TicksToMs(ticks)); +} + +} // namespace tflite + +int main(int argc, char **argv) +{ + tflite::InitializeTarget(); + + tflite::MicroProfiler profiler; + + uint32_t event_handle = profiler.BeginEvent("InitializeBenchmarkRunner"); + tflite::PersonDetectionBenchmarkRunner *benchmark_runner = + CreateBenchmarkRunner(&profiler); + profiler.EndEvent(event_handle); + profiler.Log(); + MicroPrintf(""); // null MicroPrintf serves as a newline. + + tflite::PersonDetectionNIerations( + reinterpret_cast(g_person_data), 1, + "WithPersonDataIterations(1)", *benchmark_runner, profiler); + profiler.Log(); + MicroPrintf(""); // null MicroPrintf serves as a newline. + + tflite::PersonDetectionNIerations( + reinterpret_cast(g_no_person_data), 1, + "NoPersonDataIterations(1)", *benchmark_runner, profiler); + profiler.Log(); + MicroPrintf(""); // null MicroPrintf serves as a newline. + + tflite::PersonDetectionNIerations( + reinterpret_cast(g_person_data), 10, + "WithPersonDataIterations(10)", *benchmark_runner, profiler); + MicroPrintf(""); // null MicroPrintf serves as a newline. + + tflite::PersonDetectionNIerations( + reinterpret_cast(g_no_person_data), 10, + "NoPersonDataIterations(10)", *benchmark_runner, profiler); + MicroPrintf(""); // null MicroPrintf serves as a newline. +} diff --git a/components/tflite/tensorflow/lite/micro/compatibility.h b/components/tflite/tensorflow/lite/micro/compatibility.h new file mode 100644 index 00000000..19191fdb --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/compatibility.h @@ -0,0 +1,34 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_MICRO_COMPATIBILITY_H_ +#define TENSORFLOW_LITE_MICRO_COMPATIBILITY_H_ + +// C++ will automatically create class-specific delete operators for virtual +// objects, which by default call the global delete function. For embedded +// applications we want to avoid this, and won't be calling new/delete on these +// objects, so we need to override the default implementation with one that does +// nothing to avoid linking in ::delete(). +// This macro needs to be included in all subclasses of a virtual base class in +// the private section. +#ifdef TF_LITE_STATIC_MEMORY +#define TF_LITE_REMOVE_VIRTUAL_DELETE \ + void operator delete(void *p) \ + { \ + } +#else +#define TF_LITE_REMOVE_VIRTUAL_DELETE +#endif + +#endif // TENSORFLOW_LITE_MICRO_COMPATIBILITY_H_ diff --git a/components/tflite/tensorflow/lite/micro/debug_log.cc b/components/tflite/tensorflow/lite/micro/debug_log.cc new file mode 100644 index 00000000..d9751cee --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/debug_log.cc @@ -0,0 +1,51 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// Reference implementation of the DebugLog() function that's required for a +// platform to support the TensorFlow Lite for Microcontrollers library. This is +// the only function that's absolutely required to be available on a target +// device, since it's used for communicating test results back to the host so +// that we can verify the implementation is working correctly. +// It's designed to be as easy as possible to supply an implementation though. +// On platforms that have a POSIX stack or C library, it can be written as a +// single call to `fprintf(stderr, "%s", s)` to output a string to the error +// stream of the console, but if there's no OS or C library available, there's +// almost always an equivalent way to write out a string to some serial +// interface that can be used instead. For example on Arm M-series MCUs, calling +// the `bkpt #0xAB` assembler instruction will output the string in r1 to +// whatever debug serial connection is available. If you're running mbed, you +// can do the same by creating `Serial pc(USBTX, USBRX)` and then calling +// `pc.printf("%s", s)`. +// To add an equivalent function for your own platform, create your own +// implementation file, and place it in a subfolder with named after the OS +// you're targeting. For example, see the Cortex M bare metal version in +// tensorflow/lite/micro/bluepill/debug_log.cc or the mbed one on +// tensorflow/lite/micro/mbed/debug_log.cc. + +#include "tensorflow/lite/micro/debug_log.h" + +#ifndef TF_LITE_STRIP_ERROR_STRINGS +#include +#endif + +extern "C" void DebugLog(const char *s) +{ +#ifndef TF_LITE_STRIP_ERROR_STRINGS + // Reusing TF_LITE_STRIP_ERROR_STRINGS to disable DebugLog completely to get + // maximum reduction in binary size. This is because we have DebugLog calls + // via TF_LITE_CHECK that are not stubbed out by TF_LITE_REPORT_ERROR. + fprintf(stderr, "%s", s); +#endif +} diff --git a/components/tflite/tensorflow/lite/micro/debug_log.h b/components/tflite/tensorflow/lite/micro/debug_log.h new file mode 100644 index 00000000..6c3b5c89 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/debug_log.h @@ -0,0 +1,31 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_MICRO_DEBUG_LOG_H_ +#define TENSORFLOW_LITE_MICRO_DEBUG_LOG_H_ + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +// This function should be implemented by each target platform, and provide a +// way for strings to be output to some text stream. For more information, see +// tensorflow/lite/micro/debug_log.cc. +void DebugLog(const char *s); + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus + +#endif // TENSORFLOW_LITE_MICRO_DEBUG_LOG_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/hello_world/README.md b/components/tflite/tensorflow/lite/micro/examples/hello_world/README.md new file mode 100644 index 00000000..e79a5d36 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/hello_world/README.md @@ -0,0 +1,596 @@ + + +# Hello World Example + +This example is designed to demonstrate the absolute basics of using [TensorFlow +Lite for Microcontrollers](https://www.tensorflow.org/lite/microcontrollers). +It includes the full end-to-end workflow of training a model, converting it for +use with TensorFlow Lite for Microcontrollers for running inference on a +microcontroller. + +The model is trained to replicate a `sine` function and generates a pattern of +data to either blink LEDs or control an animation, depending on the capabilities +of the device. + +![Animation on STM32F746](images/animation_on_STM32F746.gif) + +## Table of contents + +- [Deploy to ARC EM SDP](#deploy-to-arc-em-sdp) +- [Deploy to Arduino](#deploy-to-arduino) +- [Deploy to ESP32](#deploy-to-esp32) +- [Deploy to Himax WE1 EVB](#deploy-to-himax-we1-evb) +- [Deploy to SparkFun Edge](#deploy-to-sparkfun-edge) +- [Deploy to STM32F746](#deploy-to-STM32F746) +- [Run the tests on a development machine](#run-the-tests-on-a-development-machine) +- [Train your own model](#train-your-own-model) + +## Deploy to ARC EM SDP + +The following instructions will help you to build and deploy this example to +[ARC EM SDP](https://www.synopsys.com/dw/ipdir.php?ds=arc-em-software-development-platform) +board. General information and instructions on using the board with TensorFlow +Lite Micro can be found in the common +[ARC targets description](/tensorflow/lite/micro/tools/make/targets/arc/README.md). + +### Initial Setup + +Follow the instructions on the +[ARC EM SDP Initial Setup](/tensorflow/lite/micro/tools/make/targets/arc/README.md#ARC-EM-Software-Development-Platform-ARC-EM-SDP) +to get and install all required tools for work with ARC EM SDP. + +### Generate Example Project + +The example project for ARC EM SDP platform can be generated with the following +command: + +``` +make -f tensorflow/lite/micro/tools/make/Makefile TARGET=arc_emsdp OPTIMIZED_KERNEL_DIR=arc_mli ARC_TAGS=no_arc_mli generate_hello_world_make_project +``` + +### Build and Run Example + +For more detailed information on building and running examples see the +appropriate sections of general descriptions of the +[ARC EM SDP usage with TFLM](/tensorflow/lite/micro/tools/make/targets/arc/README.md#ARC-EM-Software-Development-Platform-ARC-EM-SDP). +In the directory with generated project you can also find a +*README_ARC_EMSDP.md* file with instructions and options on building and +running. Here we only briefly mention main steps which are typically enough to +get it started. + +1. You need to + [connect the board](/tensorflow/lite/micro/tools/make/targets/arc/README.md#connect-the-board) + and open an serial connection. + +2. Go to the generated example project director + + ``` + cd tensorflow/lite/micro/tools/make/gen/arc_emsdp_arc/prj/hello_world/make + ``` + +3. Build the example using + + ``` + make app + ``` + +4. To generate artefacts for self-boot of example from the board use + + ``` + make flash + ``` + +5. To run application from the board using microSD card: + + * Copy the content of the created /bin folder into the root of microSD + card. Note that the card must be formatted as FAT32 with default cluster + size (but less than 32 Kbytes) + * Plug in the microSD card into the J11 connector. + * Push the RST button. If a red LED is lit beside RST button, push the CFG + button. + * Type or copy next commands one-by-another into serial terminal: `setenv + loadaddr 0x10800000 setenv bootfile app.elf setenv bootdelay 1 setenv + bootcmd fatload mmc 0 \$\{loadaddr\} \$\{bootfile\} \&\& bootelf + saveenv` + * Push the RST button. + +6. If you have the MetaWare Debugger installed in your environment: + + * To run application from the console using it type `make run`. + * To stop the execution type `Ctrl+C` in the console several times. + +In both cases (step 5 and 6) you will see the application output in the serial +terminal. + +## Deploy to Arduino + +The following instructions will help you build and deploy this sample +to [Arduino](https://www.arduino.cc/) devices. + +![Animation on Arduino MKRZERO](images/animation_on_arduino_mkrzero.gif) + +The sample has been tested with the following devices: + +- [Arduino Nano 33 BLE Sense](https://store.arduino.cc/usa/nano-33-ble-sense-with-headers) +- [Arduino MKRZERO](https://store.arduino.cc/usa/arduino-mkrzero) + +The sample will use PWM to fade an LED on and off according to the model's +output. In the code, the `LED_BUILTIN` constant is used to specify the board's +built-in LED as the one being controlled. However, on some boards, this built-in +LED is not attached to a pin with PWM capabilities. In this case, the LED will +blink instead of fading. + +### Install the Arduino_TensorFlowLite library + +This example application is included as part of the official TensorFlow Lite +Arduino library. To install it, open the Arduino library manager in +`Tools -> Manage Libraries...` and search for `Arduino_TensorFlowLite`. + +### Load and run the example + +Once the library has been added, go to `File -> Examples`. You should see an +example near the bottom of the list named `TensorFlowLite:hello_world`. Select +it and click `hello_world` to load the example. + +Use the Arduino IDE to build and upload the example. Once it is running, +you should see the built-in LED on your device flashing. + +The Arduino Desktop IDE includes a plotter that we can use to display the sine +wave graphically. To view it, go to `Tools -> Serial Plotter`. You will see one +datapoint being logged for each inference cycle, expressed as a number between 0 +and 255. + +## Deploy to ESP32 + +The following instructions will help you build and deploy this sample +to [ESP32](https://www.espressif.com/en/products/hardware/esp32/overview) +devices using the [ESP IDF](https://github.com/espressif/esp-idf). + +The sample has been tested on ESP-IDF version 4.0 with the following devices: +- [ESP32-DevKitC](http://esp-idf.readthedocs.io/en/latest/get-started/get-started-devkitc.html) +- [ESP-EYE](https://github.com/espressif/esp-who/blob/master/docs/en/get-started/ESP-EYE_Getting_Started_Guide.md) + +### Install the ESP IDF + +Follow the instructions of the +[ESP-IDF get started guide](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html) +to setup the toolchain and the ESP-IDF itself. + +The next steps assume that the +[IDF environment variables are set](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html#step-4-set-up-the-environment-variables) : + + * The `IDF_PATH` environment variable is set + * `idf.py` and Xtensa-esp32 tools (e.g. `xtensa-esp32-elf-gcc`) are in `$PATH` + +### Generate the examples +The example project can be generated with the following command: +``` +make -f tensorflow/lite/micro/tools/make/Makefile TARGET=esp generate_hello_world_esp_project +``` + +### Building the example + +Go to the example project directory `cd +tensorflow/lite/micro/tools/make/gen/esp_xtensa-esp32/prj/hello_world/esp-idf` + +Then build with `idf.py` +``` +idf.py build +``` + +### Load and run the example + +To flash (replace `/dev/ttyUSB0` with the device serial port): +``` +idf.py --port /dev/ttyUSB0 flash +``` + +Monitor the serial output: +``` +idf.py --port /dev/ttyUSB0 monitor +``` + +Use `Ctrl+]` to exit. + +The previous two commands can be combined: +``` +idf.py --port /dev/ttyUSB0 flash monitor +``` + +## Deploy to Himax WE1 EVB + +The following instructions will help you build and deploy this example to +[HIMAX WE1 EVB](https://github.com/HimaxWiseEyePlus/bsp_tflu/tree/master/HIMAX_WE1_EVB_board_brief) +board. To understand more about using this board, please check +[HIMAX WE1 EVB user guide](https://github.com/HimaxWiseEyePlus/bsp_tflu/tree/master/HIMAX_WE1_EVB_user_guide). + +### Initial Setup + +To use the HIMAX WE1 EVB, please make sure following software are installed: + +#### MetaWare Development Toolkit + +See +[Install the Synopsys DesignWare ARC MetaWare Development Toolkit](/tensorflow/lite/micro/tools/make/targets/arc/README.md#install-the-synopsys-designware-arc-metaware-development-toolkit) +section for instructions on toolchain installation. + +#### Make Tool version + +A `'make'` tool is required for deploying Tensorflow Lite Micro applications on +HIMAX WE1 EVB, See +[Check make tool version](/tensorflow/lite/micro/tools/make/targets/arc/README.md#make-tool) +section for proper environment. + +#### Serial Terminal Emulation Application + +There are 2 main purposes for HIMAX WE1 EVB Debug UART port + +- print application output +- burn application to flash by using xmodem send application binary + +You can use any terminal emulation program (like [PuTTY](https://www.putty.org/) +or [minicom](https://linux.die.net/man/1/minicom)). + +### Generate Example Project + +The example project for HIMAX WE1 EVB platform can be generated with the +following command: + +Download related third party data + +``` +make -f tensorflow/lite/micro/tools/make/Makefile TARGET=himax_we1_evb third_party_downloads +``` + +Generate hello world project + +``` +make -f tensorflow/lite/micro/tools/make/Makefile generate_hello_world_make_project TARGET=himax_we1_evb ARC_TAGS=no_arc_mli +``` + +### Build and Burn Example + +Following the Steps to run hello world example at HIMAX WE1 EVB platform. + +1. Go to the generated example project directory. + + ``` + cd tensorflow/lite/micro/tools/make/gen/himax_we1_evb_arc/prj/hello_world/make + ``` + +2. Build the example using + + ``` + make app + ``` + +3. After example build finish, copy ELF file and map file to image generate + tool directory. \ + image generate tool directory located at + `'tensorflow/lite/micro/tools/make/downloads/himax_we1_sdk/image_gen_linux_v3/'` + + ``` + cp hello_world.elf himax_we1_evb.map ../../../../../downloads/himax_we1_sdk/image_gen_linux_v3/ + ``` + +4. Go to flash image generate tool directory. + + ``` + cd ../../../../../downloads/himax_we1_sdk/image_gen_linux_v3/ + ``` + + make sure this tool directory is in $PATH. You can permanently set it to + PATH by + + ``` + export PATH=$PATH:$(pwd) + ``` + +5. run image generate tool, generate flash image file. + + * Before running image generate tool, by typing `sudo chmod +x image_gen` + and `sudo chmod +x sign_tool` to make sure it is executable. + + ``` + image_gen -e hello_world.elf -m himax_we1_evb.map -o out.img + ``` + +6. Download flash image file to HIMAX WE1 EVB by UART: + + * more detail about download image through UART can be found at + [HIMAX WE1 EVB update Flash image](https://github.com/HimaxWiseEyePlus/bsp_tflu/tree/master/HIMAX_WE1_EVB_user_guide#flash-image-update) + +After these steps, press reset button on the HIMAX WE1 EVB, you will see +application output in the serial terminal. + +## Deploy to SparkFun Edge + +The following instructions will help you build and deploy this sample on the +[SparkFun Edge development board](https://sparkfun.com/products/15170). + +![Animation on SparkFun Edge](images/animation_on_sparkfun_edge.gif) + +If you're new to using this board, we recommend walking through the +[AI on a microcontroller with TensorFlow Lite and SparkFun Edge](https://codelabs.developers.google.com/codelabs/sparkfun-tensorflow) +codelab to get an understanding of the workflow. + +### Compile the binary + +The following command will download the required dependencies and then compile a +binary for the SparkFun Edge: + +``` +make -f tensorflow/lite/micro/tools/make/Makefile TARGET=sparkfun_edge hello_world_bin +``` + +The binary will be created in the following location: + +``` +tensorflow/lite/micro/tools/make/gen/sparkfun_edge_cortex-m4/bin/hello_world.bin +``` + +### Sign the binary + +The binary must be signed with cryptographic keys to be deployed to the device. +We'll now run some commands that will sign our binary so it can be flashed to +the SparkFun Edge. The scripts we are using come from the Ambiq SDK, which is +downloaded when the `Makefile` is run. + +Enter the following command to set up some dummy cryptographic keys we can use +for development: + +``` +cp tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.2.0/tools/apollo3_scripts/keys_info0.py \ +tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.2.0/tools/apollo3_scripts/keys_info.py +``` + +Next, run the following command to create a signed binary: + +``` +python3 tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.2.0/tools/apollo3_scripts/create_cust_image_blob.py \ +--bin tensorflow/lite/micro/tools/make/gen/sparkfun_edge_cortex-m4/bin/hello_world.bin \ +--load-address 0xC000 \ +--magic-num 0xCB \ +-o main_nonsecure_ota \ +--version 0x0 +``` + +This will create the file `main_nonsecure_ota.bin`. We'll now run another +command to create a final version of the file that can be used to flash our +device with the bootloader script we will use in the next step: + +``` +python3 tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.2.0/tools/apollo3_scripts/create_cust_wireupdate_blob.py \ +--load-address 0x20000 \ +--bin main_nonsecure_ota.bin \ +-i 6 \ +-o main_nonsecure_wire \ +--options 0x1 +``` + +You should now have a file called `main_nonsecure_wire.bin` in the directory +where you ran the commands. This is the file we'll be flashing to the device. + +### Flash the binary + +Next, attach the board to your computer via a USB-to-serial adapter. + +**Note:** If you're using the [SparkFun Serial Basic Breakout](https://www.sparkfun.com/products/15096), +you should [install the latest drivers](https://learn.sparkfun.com/tutorials/sparkfun-serial-basic-ch340c-hookup-guide#drivers-if-you-need-them) +before you continue. + +Once connected, assign the USB device name to an environment variable: + +``` +export DEVICENAME=put your device name here +``` + +Set another variable with the baud rate: + +``` +export BAUD_RATE=921600 +``` + +Now, hold the button marked `14` on the device. While still holding the button, +hit the button marked `RST`. Continue holding the button marked `14` while +running the following command: + +``` +python3 tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.2.0/tools/apollo3_scripts/uart_wired_update.py \ +-b ${BAUD_RATE} ${DEVICENAME} \ +-r 1 \ +-f main_nonsecure_wire.bin \ +-i 6 +``` + +You should see a long stream of output as the binary is flashed to the device. +Once you see the following lines, flashing is complete: + +``` +Sending Reset Command. +Done. +``` + +If you don't see these lines, flashing may have failed. Try running through the +steps in [Flash the binary](#flash-the-binary) again (you can skip over setting +the environment variables). If you continue to run into problems, follow the +[AI on a microcontroller with TensorFlow Lite and SparkFun Edge](https://codelabs.developers.google.com/codelabs/sparkfun-tensorflow) +codelab, which includes more comprehensive instructions for the flashing +process. + +The binary should now be deployed to the device. Hit the button marked `RST` to +reboot the board. You should see the device's four LEDs flashing in sequence. + +Debug information is logged by the board while the program is running. To view +it, establish a serial connection to the board using a baud rate of `115200`. +On OSX and Linux, the following command should work: + +``` +screen ${DEVICENAME} 115200 +``` + +You will see a lot of output flying past! To stop the scrolling, hit `Ctrl+A`, +immediately followed by `Esc`. You can then use the arrow keys to explore the +output, which will contain the results of running inference on various `x` +values: + +``` +x_value: 1.1843798*2^2, y_value: -1.9542645*2^-1 +``` + +To stop viewing the debug output with `screen`, hit `Ctrl+A`, immediately +followed by the `K` key, then hit the `Y` key. + + +## Deploy to STM32F746 + +The following instructions will help you build and deploy the sample to the +[STM32F7 discovery kit](https://os.mbed.com/platforms/ST-Discovery-F746NG/) +using [ARM Mbed](https://github.com/ARMmbed/mbed-cli). + +![Animation on STM32F746](images/animation_on_STM32F746.gif) + +Before we begin, you'll need the following: + +- STM32F7 discovery kit board +- Mini-USB cable +- ARM Mbed CLI ([installation instructions](https://os.mbed.com/docs/mbed-os/v6.9/quick-start/build-with-mbed-cli.html). Check it out for MacOS Catalina - [mbed-cli is broken on MacOS Catalina #930](https://github.com/ARMmbed/mbed-cli/issues/930#issuecomment-660550734)) +- Python 3 and pip3 + +Since Mbed requires a special folder structure for projects, we'll first run a +command to generate a subfolder containing the required source files in this +structure: + +``` +make -f tensorflow/lite/micro/tools/make/Makefile TARGET=disco_f746ng OPTIMIZED_KERNEL_DIR=cmsis_nn generate_hello_world_mbed_project +``` + +This will result in the creation of a new folder: + +``` +tensorflow/lite/micro/tools/make/gen/disco_f746ng_cortex-m4_default/prj/hello_world/mbed +``` + +This folder contains all of the example's dependencies structured in the correct +way for Mbed to be able to build it. + +Change into the directory and run the following commands. + +First, tell Mbed that the current directory is the root of an Mbed project: + +``` +mbed config root . +``` + +Next, tell Mbed to download the dependencies and prepare to build: + +``` +mbed deploy +``` + +Older versions of Mbed will build the project using C++98. However, TensorFlow Lite +requires C++11. If needed, run the following Python snippet to modify the Mbed +configuration files so that it uses C++11: + +``` +python -c 'import fileinput, glob; +for filename in glob.glob("mbed-os/tools/profiles/*.json"): + for line in fileinput.input(filename, inplace=True): + print(line.replace("\"-std=gnu++98\"","\"-std=c++11\", \"-fpermissive\""))' + +``` + +Note: Mbed has a dependency to an old version of arm_math.h and cmsis_gcc.h (adapted from the general [CMSIS-NN MBED example](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/micro/kernels/cmsis_nn#example-2---mbed)). Therefore you need to copy the newer version as follows: +```bash +cp tensorflow/lite/micro/tools/make/downloads/cmsis/CMSIS/DSP/Include/\ +arm_math.h mbed-os/cmsis/TARGET_CORTEX_M/arm_math.h +cp tensorflow/lite/micro/tools/make/downloads/cmsis/CMSIS/Core/Include/\ +cmsis_gcc.h mbed-os/cmsis/TARGET_CORTEX_M/cmsis_gcc.h +``` + +Finally, run the following command to compile: + +``` +mbed compile -m DISCO_F746NG -t GCC_ARM +``` + +This should result in a binary at the following path: + +``` +./BUILD/DISCO_F746NG/GCC_ARM/mbed.bin +``` + +To deploy, plug in your STM board and copy the file to it. On MacOS, you can do +this with the following command: + +``` +cp ./BUILD/DISCO_F746NG/GCC_ARM/mbed.bin /Volumes/DIS_F746NG/ +``` + +Copying the file will initiate the flashing process. Once this is complete, you +should see an animation on the device's screen. + + +``` +screen /dev/tty.usbmodem14403 9600 +``` + +In addition to this animation, debug information is logged by the board while +the program is running. To view it, establish a serial connection to the board +using a baud rate of `9600`. On OSX and Linux, the following command should +work, replacing `/dev/tty.devicename` with the name of your device as it appears +in `/dev`: + +``` +screen /dev/tty.devicename 9600 +``` + +You will see a lot of output flying past! To stop the scrolling, hit `Ctrl+A`, +immediately followed by `Esc`. You can then use the arrow keys to explore the +output, which will contain the results of running inference on various `x` +values: + +``` +x_value: 1.1843798*2^2, y_value: -1.9542645*2^-1 +``` + +To stop viewing the debug output with `screen`, hit `Ctrl+A`, immediately +followed by the `K` key, then hit the `Y` key. + +## Run the tests on a development machine + +To compile and test this example on a desktop Linux or macOS machine, first +clone the TensorFlow repository from GitHub to a convenient place: + +```bash +git clone --depth 1 https://github.com/tensorflow/tensorflow.git +``` + +Next, `cd` into the source directory from a terminal, and then run the following +command: + +```bash +make -f tensorflow/lite/micro/tools/make/Makefile test_hello_world_test +``` + +This will take a few minutes, and downloads frameworks the code uses. Once the +process has finished, you should see a series of files get compiled, followed by +some logging output from a test, which should conclude with +`~~~ALL TESTS PASSED~~~`. + +If you see this, it means that a small program has been built and run that loads +the trained TensorFlow model, runs some example inputs through it, and got the +expected outputs. + +To understand how TensorFlow Lite does this, you can look at the source in +[hello_world_test.cc](hello_world_test.cc). +It's a fairly small amount of code that creates an interpreter, gets a handle to +a model that's been compiled into the program, and then invokes the interpreter +with the model and sample inputs. + +## Train your own model + +So far you have used an existing trained model to run inference on +microcontrollers. If you wish to train your own model, follow the instructions +given in the [train/](train/) directory. + diff --git a/components/tflite/tensorflow/lite/micro/examples/hello_world/constants.cc b/components/tflite/tensorflow/lite/micro/examples/hello_world/constants.cc new file mode 100644 index 00000000..3eccb724 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/hello_world/constants.cc @@ -0,0 +1,19 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/hello_world/constants.h" + +// This is a small number so that it's easy to read the logs +const int kInferencesPerCycle = 20; diff --git a/components/tflite/tensorflow/lite/micro/examples/hello_world/constants.h b/components/tflite/tensorflow/lite/micro/examples/hello_world/constants.h new file mode 100644 index 00000000..11fc4fd4 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/hello_world/constants.h @@ -0,0 +1,32 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_CONSTANTS_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_CONSTANTS_H_ + +// This constant represents the range of x values our model was trained on, +// which is from 0 to (2 * Pi). We approximate Pi to avoid requiring additional +// libraries. +const float kXrange = 2.f * 3.14159265359f; + +// This constant determines the number of inferences to perform across the range +// of x values defined above. Since each inference takes time, the higher this +// number, the more time it will take to run through the entire range. The value +// of this constant can be tuned so that one full cycle takes a desired amount +// of time. Since different devices take different amounts of time to perform +// inference, this value should be defined per-device. +extern const int kInferencesPerCycle; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_CONSTANTS_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/hello_world/create_sine_model.ipynb b/components/tflite/tensorflow/lite/micro/examples/hello_world/create_sine_model.ipynb new file mode 100644 index 00000000..b34c0bb3 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/hello_world/create_sine_model.ipynb @@ -0,0 +1 @@ +{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"Redirect","provenance":[],"collapsed_sections":[],"authorship_tag":"ABX9TyO1u6oks1qPVEQNnHFD3Cyo"},"kernelspec":{"name":"python3","display_name":"Python 3"}},"cells":[{"cell_type":"markdown","metadata":{"id":"86C-FMxpdZxv","colab_type":"text"},"source":["This Colab notebook has been moved to [https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/micro/examples/hello_world/train/train_hello_world_model.ipynb](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/micro/examples/hello_world/train/train_hello_world_model.ipynb)\n"]}]} \ No newline at end of file diff --git a/components/tflite/tensorflow/lite/micro/examples/hello_world/hello_world_binary_test.sh b/components/tflite/tensorflow/lite/micro/examples/hello_world/hello_world_binary_test.sh new file mode 100644 index 00000000..fe7683e5 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/hello_world/hello_world_binary_test.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +# +# Bash unit tests for the example binary. + +set -e + +OUTPUT_LOG_FILE=${TEST_TMPDIR}/output_log.txt + +# Needed for copybara compatibility. +SCRIPT_BASE_DIR=/org_"tensor"flow +${TEST_SRCDIR}${SCRIPT_BASE_DIR}/tensorflow/lite/micro/examples/hello_world/hello_world 2>&1 | head > ${OUTPUT_LOG_FILE} + +if ! grep -q 'x_value:.*y_value:' ${OUTPUT_LOG_FILE}; then + echo "ERROR: Expected logs not found in output '${OUTPUT_LOG_FILE}'" + exit 1 +fi + +echo +echo "SUCCESS: hello_world_binary_test PASSED" diff --git a/components/tflite/tensorflow/lite/micro/examples/hello_world/hello_world_test.cc b/components/tflite/tensorflow/lite/micro/examples/hello_world/hello_world_test.cc new file mode 100644 index 00000000..45ddfadf --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/hello_world/hello_world_test.cc @@ -0,0 +1,132 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/examples/hello_world/model.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/micro_interpreter.h" +#include "tensorflow/lite/micro/testing/micro_test.h" +#include "tensorflow/lite/schema/schema_generated.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(LoadModelAndPerformInference) +{ + // Define the input and the expected output + float x = 0.0f; + float y_true = sin(x); + + // Set up logging + tflite::MicroErrorReporter micro_error_reporter; + + // Map the model into a usable data structure. This doesn't involve any + // copying or parsing, it's a very lightweight operation. + const tflite::Model *model = ::tflite::GetModel(g_model); + if (model->version() != TFLITE_SCHEMA_VERSION) { + TF_LITE_REPORT_ERROR(µ_error_reporter, + "Model provided is schema version %d not equal " + "to supported version %d.\n", + model->version(), TFLITE_SCHEMA_VERSION); + } + + // This pulls in all the operation implementations we need + tflite::AllOpsResolver resolver; + + constexpr int kTensorArenaSize = 2000; + uint8_t tensor_arena[kTensorArenaSize]; + + // Build an interpreter to run the model with + tflite::MicroInterpreter interpreter(model, resolver, tensor_arena, + kTensorArenaSize, µ_error_reporter); + // Allocate memory from the tensor_arena for the model's tensors + TF_LITE_MICRO_EXPECT_EQ(interpreter.AllocateTensors(), kTfLiteOk); + + // Obtain a pointer to the model's input tensor + TfLiteTensor *input = interpreter.input(0); + + // Make sure the input has the properties we expect + TF_LITE_MICRO_EXPECT_NE(nullptr, input); + // The property "dims" tells us the tensor's shape. It has one element for + // each dimension. Our input is a 2D tensor containing 1 element, so "dims" + // should have size 2. + TF_LITE_MICRO_EXPECT_EQ(2, input->dims->size); + // The value of each element gives the length of the corresponding tensor. + // We should expect two single element tensors (one is contained within the + // other). + TF_LITE_MICRO_EXPECT_EQ(1, input->dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(1, input->dims->data[1]); + // The input is an 8 bit integer value + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt8, input->type); + + // Get the input quantization parameters + float input_scale = input->params.scale; + int input_zero_point = input->params.zero_point; + + // Quantize the input from floating-point to integer + int8_t x_quantized = x / input_scale + input_zero_point; + // Place the quantized input in the model's input tensor + input->data.int8[0] = x_quantized; + + // Run the model and check that it succeeds + TfLiteStatus invoke_status = interpreter.Invoke(); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, invoke_status); + + // Obtain a pointer to the output tensor and make sure it has the + // properties we expect. It should be the same as the input tensor. + TfLiteTensor *output = interpreter.output(0); + TF_LITE_MICRO_EXPECT_EQ(2, output->dims->size); + TF_LITE_MICRO_EXPECT_EQ(1, output->dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(1, output->dims->data[1]); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt8, output->type); + + // Get the output quantization parameters + float output_scale = output->params.scale; + int output_zero_point = output->params.zero_point; + + // Obtain the quantized output from model's output tensor + int8_t y_pred_quantized = output->data.int8[0]; + // Dequantize the output from integer to floating-point + float y_pred = (y_pred_quantized - output_zero_point) * output_scale; + + // Check if the output is within a small range of the expected output + float epsilon = 0.05f; + TF_LITE_MICRO_EXPECT_NEAR(y_true, y_pred, epsilon); + + // Run inference on several more values and confirm the expected outputs + x = 1.f; + y_true = sin(x); + input->data.int8[0] = x / input_scale + input_zero_point; + interpreter.Invoke(); + y_pred = (output->data.int8[0] - output_zero_point) * output_scale; + TF_LITE_MICRO_EXPECT_NEAR(y_true, y_pred, epsilon); + + x = 3.f; + y_true = sin(x); + input->data.int8[0] = x / input_scale + input_zero_point; + interpreter.Invoke(); + y_pred = (output->data.int8[0] - output_zero_point) * output_scale; + TF_LITE_MICRO_EXPECT_NEAR(y_true, y_pred, epsilon); + + x = 5.f; + y_true = sin(x); + input->data.int8[0] = x / input_scale + input_zero_point; + interpreter.Invoke(); + y_pred = (output->data.int8[0] - output_zero_point) * output_scale; + TF_LITE_MICRO_EXPECT_NEAR(y_true, y_pred, epsilon); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/examples/hello_world/images/animation_on_STM32F746.gif b/components/tflite/tensorflow/lite/micro/examples/hello_world/images/animation_on_STM32F746.gif new file mode 100644 index 00000000..e427bc86 Binary files /dev/null and b/components/tflite/tensorflow/lite/micro/examples/hello_world/images/animation_on_STM32F746.gif differ diff --git a/components/tflite/tensorflow/lite/micro/examples/hello_world/images/animation_on_arduino_mkrzero.gif b/components/tflite/tensorflow/lite/micro/examples/hello_world/images/animation_on_arduino_mkrzero.gif new file mode 100644 index 00000000..d8965347 Binary files /dev/null and b/components/tflite/tensorflow/lite/micro/examples/hello_world/images/animation_on_arduino_mkrzero.gif differ diff --git a/components/tflite/tensorflow/lite/micro/examples/hello_world/images/animation_on_sparkfun_edge.gif b/components/tflite/tensorflow/lite/micro/examples/hello_world/images/animation_on_sparkfun_edge.gif new file mode 100644 index 00000000..057a52d4 Binary files /dev/null and b/components/tflite/tensorflow/lite/micro/examples/hello_world/images/animation_on_sparkfun_edge.gif differ diff --git a/components/tflite/tensorflow/lite/micro/examples/hello_world/images/model_architecture.png b/components/tflite/tensorflow/lite/micro/examples/hello_world/images/model_architecture.png new file mode 100644 index 00000000..792d18fa Binary files /dev/null and b/components/tflite/tensorflow/lite/micro/examples/hello_world/images/model_architecture.png differ diff --git a/components/tflite/tensorflow/lite/micro/examples/hello_world/main.cc b/components/tflite/tensorflow/lite/micro/examples/hello_world/main.cc new file mode 100644 index 00000000..f6b297fd --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/hello_world/main.cc @@ -0,0 +1,28 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/hello_world/main_functions.h" + +// This is the default main used on systems that have the standard C entry +// point. Other devices (for example FreeRTOS or ESP32) that have different +// requirements for entry code (like an app_main function) should specialize +// this main.cc file in a target-specific subfolder. +int main(int argc, char *argv[]) +{ + setup(); + while (true) { + loop(); + } +} diff --git a/components/tflite/tensorflow/lite/micro/examples/hello_world/main_functions.cc b/components/tflite/tensorflow/lite/micro/examples/hello_world/main_functions.cc new file mode 100644 index 00000000..0b293442 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/hello_world/main_functions.cc @@ -0,0 +1,124 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/hello_world/main_functions.h" + +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/examples/hello_world/constants.h" +#include "tensorflow/lite/micro/examples/hello_world/model.h" +#include "tensorflow/lite/micro/examples/hello_world/output_handler.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/micro_interpreter.h" +#include "tensorflow/lite/micro/system_setup.h" +#include "tensorflow/lite/schema/schema_generated.h" + +// Globals, used for compatibility with Arduino-style sketches. +namespace { +tflite::ErrorReporter *error_reporter = nullptr; +const tflite::Model *model = nullptr; +tflite::MicroInterpreter *interpreter = nullptr; +TfLiteTensor *input = nullptr; +TfLiteTensor *output = nullptr; +int inference_count = 0; + +constexpr int kTensorArenaSize = 2000; +uint8_t tensor_arena[kTensorArenaSize]; +} // namespace + +// The name of this function is important for Arduino compatibility. +void setup() +{ + tflite::InitializeTarget(); + + // Set up logging. Google style is to avoid globals or statics because of + // lifetime uncertainty, but since this has a trivial destructor it's okay. + // NOLINTNEXTLINE(runtime-global-variables) + static tflite::MicroErrorReporter micro_error_reporter; + error_reporter = µ_error_reporter; + + // Map the model into a usable data structure. This doesn't involve any + // copying or parsing, it's a very lightweight operation. + model = tflite::GetModel(g_model); + if (model->version() != TFLITE_SCHEMA_VERSION) { + TF_LITE_REPORT_ERROR(error_reporter, + "Model provided is schema version %d not equal " + "to supported version %d.", + model->version(), TFLITE_SCHEMA_VERSION); + return; + } + + // This pulls in all the operation implementations we need. + // NOLINTNEXTLINE(runtime-global-variables) + static tflite::AllOpsResolver resolver; + + // Build an interpreter to run the model with. + static tflite::MicroInterpreter static_interpreter( + model, resolver, tensor_arena, kTensorArenaSize, error_reporter); + interpreter = &static_interpreter; + + // Allocate memory from the tensor_arena for the model's tensors. + TfLiteStatus allocate_status = interpreter->AllocateTensors(); + if (allocate_status != kTfLiteOk) { + TF_LITE_REPORT_ERROR(error_reporter, "AllocateTensors() failed"); + return; + } + + // Obtain pointers to the model's input and output tensors. + input = interpreter->input(0); + output = interpreter->output(0); + + // Keep track of how many inferences we have performed. + inference_count = 0; +} + +// The name of this function is important for Arduino compatibility. +void loop() +{ + // Calculate an x value to feed into the model. We compare the current + // inference_count to the number of inferences per cycle to determine + // our position within the range of possible x values the model was + // trained on, and use this to calculate a value. + float position = static_cast(inference_count) / + static_cast(kInferencesPerCycle); + float x = position * kXrange; + + // Quantize the input from floating-point to integer + int8_t x_quantized = x / input->params.scale + input->params.zero_point; + // Place the quantized input in the model's input tensor + input->data.int8[0] = x_quantized; + + // Run inference, and report any error + TfLiteStatus invoke_status = interpreter->Invoke(); + if (invoke_status != kTfLiteOk) { + TF_LITE_REPORT_ERROR(error_reporter, "Invoke failed on x: %f\n", + static_cast(x)); + return; + } + + // Obtain the quantized output from model's output tensor + int8_t y_quantized = output->data.int8[0]; + // Dequantize the output from integer to floating-point + float y = (y_quantized - output->params.zero_point) * output->params.scale; + + // Output the results. A custom HandleOutput function can be implemented + // for each supported hardware target. + HandleOutput(error_reporter, x, y); + + // Increment the inference_counter, and reset it if we have reached + // the total number per cycle + inference_count += 1; + if (inference_count >= kInferencesPerCycle) + inference_count = 0; +} diff --git a/components/tflite/tensorflow/lite/micro/examples/hello_world/main_functions.h b/components/tflite/tensorflow/lite/micro/examples/hello_world/main_functions.h new file mode 100644 index 00000000..b276b3e8 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/hello_world/main_functions.h @@ -0,0 +1,37 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_MAIN_FUNCTIONS_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_MAIN_FUNCTIONS_H_ + +// Expose a C friendly interface for main functions. +#ifdef __cplusplus +extern "C" { +#endif + +// Initializes all data needed for the example. The name is important, and needs +// to be setup() for Arduino compatibility. +void setup(); + +// Runs one iteration of data gathering and inference. This should be called +// repeatedly from the application code. The name needs to be loop() for Arduino +// compatibility. +void loop(); + +#ifdef __cplusplus +} +#endif + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_MAIN_FUNCTIONS_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/hello_world/model.cc b/components/tflite/tensorflow/lite/micro/examples/hello_world/model.cc new file mode 100644 index 00000000..ec48ccd9 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/hello_world/model.cc @@ -0,0 +1,238 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// Automatically created from a TensorFlow Lite flatbuffer using the command: +// xxd -i model.tflite > model.cc + +// This is a standard TensorFlow Lite model file that has been converted into a +// C data array, so it can be easily compiled into a binary for devices that +// don't have a file system. + +// See train/README.md for a full description of the creation process. + +#include "tensorflow/lite/micro/examples/hello_world/model.h" + +// Keep model aligned to 8 bytes to guarantee aligned 64-bit accesses. +alignas(8) const unsigned char g_model[] = { + 0x1c, 0x00, 0x00, 0x00, 0x54, 0x46, 0x4c, 0x33, 0x14, 0x00, 0x20, 0x00, + 0x1c, 0x00, 0x18, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x98, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x1c, 0x03, 0x00, 0x00, + 0x2c, 0x03, 0x00, 0x00, 0x30, 0x09, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x60, 0xf7, 0xff, 0xff, + 0x10, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, + 0x44, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x73, 0x65, 0x72, 0x76, + 0x65, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x73, 0x65, 0x72, 0x76, + 0x69, 0x6e, 0x67, 0x5f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xbc, 0xff, 0xff, 0xff, + 0x09, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x34, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x76, 0xfd, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, + 0x0d, 0x00, 0x00, 0x00, 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x32, 0x5f, + 0x69, 0x6e, 0x70, 0x75, 0x74, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x13, 0x00, 0x00, 0x00, 0x6d, 0x69, 0x6e, 0x5f, 0x72, 0x75, 0x6e, 0x74, + 0x69, 0x6d, 0x65, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x50, 0x02, 0x00, 0x00, 0x48, 0x02, 0x00, 0x00, + 0x34, 0x02, 0x00, 0x00, 0xdc, 0x01, 0x00, 0x00, 0x8c, 0x01, 0x00, 0x00, + 0x6c, 0x01, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, + 0x34, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xfa, 0xfd, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x31, 0x2e, 0x35, 0x2e, 0x30, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0xfd, 0xff, 0xff, + 0x88, 0xfd, 0xff, 0xff, 0x8c, 0xfd, 0xff, 0xff, 0x22, 0xfe, 0xff, 0xff, + 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x21, 0xa5, 0x8b, 0xca, + 0x5e, 0x1d, 0xce, 0x42, 0x9d, 0xce, 0x1f, 0xb0, 0xdf, 0x54, 0x2f, 0x81, + 0x3e, 0xfe, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0xee, 0xfc, 0x00, 0xec, 0x05, 0x17, 0xef, 0xec, 0xe6, 0xf8, 0x03, 0x01, + 0x00, 0xfa, 0xf8, 0xf5, 0xdc, 0xeb, 0x27, 0x14, 0xf1, 0xde, 0xe2, 0xdb, + 0xf0, 0xde, 0x31, 0x06, 0x02, 0xe6, 0xee, 0xf9, 0x00, 0x16, 0x07, 0xe0, + 0xfe, 0xff, 0xe9, 0x06, 0xe7, 0xef, 0x81, 0x1b, 0x18, 0xea, 0xc9, 0x01, + 0x0f, 0x00, 0xda, 0xf7, 0x0e, 0xec, 0x13,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, 0x12, 0xeb, 0x3b, 0x0c, + 0xb4, 0xcb, 0xe6, 0x13, 0xfa, 0xeb, 0xf1, 0x06, 0x1c, 0xfa, 0x18, 0xe5, + 0xeb, 0xcb, 0x0c, 0xf4, 0x4a, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x75, 0x1c, 0x11, 0xe1, 0x0c, 0x81, 0xa5, 0x42, + 0xfe, 0xd5, 0xd4, 0xb2, 0x61, 0x78, 0x19, 0xdf, 0x66, 0xff, 0xff, 0xff, + 0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x77, 0x0b, 0x00, 0x00, 0x53, 0xf6, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x77, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xd3, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x72, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2f, 0x07, 0x00, 0x00, + 0x67, 0xf5, 0xff, 0xff, 0x34, 0xf0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0xb2, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xb5, 0x04, 0x00, 0x00, 0x78, 0x0a, 0x00, 0x00, + 0x2d, 0x06, 0x00, 0x00, 0x71, 0xf8, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x9a, 0x0a, 0x00, 0x00, 0xfe, 0xf7, 0xff, 0xff, 0x0e, 0x05, 0x00, 0x00, + 0xd4, 0x09, 0x00, 0x00, 0x47, 0xfe, 0xff, 0xff, 0xb6, 0x04, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xac, 0xf7, 0xff, 0xff, 0x4b, 0xf9, 0xff, 0xff, + 0x4a, 0x05, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x8c, 0xef, 0xff, 0xff, 0x84, 0xff, 0xff, 0xff, 0x88, 0xff, 0xff, 0xff, + 0x0f, 0x00, 0x00, 0x00, 0x4d, 0x4c, 0x49, 0x52, 0x20, 0x43, 0x6f, 0x6e, + 0x76, 0x65, 0x72, 0x74, 0x65, 0x64, 0x2e, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, + 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0xdc, 0x00, 0x00, 0x00, + 0xe0, 0x00, 0x00, 0x00, 0xe4, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x84, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x96, 0xff, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, + 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xca, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0xba, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, + 0x16, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x04, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, + 0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, + 0x08, 0x00, 0x07, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x4c, 0x04, 0x00, 0x00, + 0xd0, 0x03, 0x00, 0x00, 0x68, 0x03, 0x00, 0x00, 0x0c, 0x03, 0x00, 0x00, + 0x98, 0x02, 0x00, 0x00, 0x24, 0x02, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, + 0x24, 0x01, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xf0, 0xfb, 0xff, 0xff, 0x18, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x54, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, + 0x6c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0xdc, 0xfb, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x4a, 0xce, 0x0a, 0x3c, 0x01, 0x00, 0x00, 0x00, + 0x34, 0x84, 0x85, 0x3f, 0x01, 0x00, 0x00, 0x00, 0xc5, 0x02, 0x8f, 0xbf, + 0x1e, 0x00, 0x00, 0x00, 0x53, 0x74, 0x61, 0x74, 0x65, 0x66, 0x75, 0x6c, + 0x50, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x65, 0x64, 0x43, + 0x61, 0x6c, 0x6c, 0x3a, 0x30, 0x5f, 0x69, 0x6e, 0x74, 0x38, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x80, 0xfc, 0xff, 0xff, 0x18, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x54, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, + 0x64, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, + 0x10, 0x00, 0x00, 0x00, 0x6c, 0xfc, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x93, 0xd0, 0xc0, 0x3b, 0x01, 0x00, 0x00, 0x00, + 0xc2, 0x0f, 0xc0, 0x3f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x74, 0x66, 0x6c, 0x2e, 0x66, 0x75, 0x6c, 0x6c, + 0x79, 0x5f, 0x63, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x31, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x08, 0xfd, 0xff, 0xff, 0x18, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x09, 0x64, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0xf4, 0xfc, 0xff, 0xff, + 0x10, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0xe0, 0xdb, 0x47, 0x3c, 0x01, 0x00, 0x00, 0x00, 0x04, 0x14, 0x47, 0x40, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, + 0x74, 0x66, 0x6c, 0x2e, 0x66, 0x75, 0x6c, 0x6c, 0x79, 0x5f, 0x63, 0x6f, + 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x02, 0xfe, 0xff, 0xff, + 0x14, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x09, 0x50, 0x00, 0x00, 0x00, 0x6c, 0xfd, 0xff, 0xff, + 0x10, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xfb, 0x4b, 0x0b, 0x3c, + 0x01, 0x00, 0x00, 0x00, 0x40, 0x84, 0x4b, 0x3f, 0x01, 0x00, 0x00, 0x00, + 0x63, 0x35, 0x8a, 0xbf, 0x0d, 0x00, 0x00, 0x00, 0x73, 0x74, 0x64, 0x2e, + 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x32, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x72, 0xfe, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x50, 0x00, 0x00, 0x00, + 0xdc, 0xfd, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x60, 0x01, 0x4f, 0x3c, 0x01, 0x00, 0x00, 0x00, 0x47, 0x6d, 0xb3, 0x3f, + 0x01, 0x00, 0x00, 0x00, 0x5d, 0x63, 0xcd, 0xbf, 0x0d, 0x00, 0x00, 0x00, + 0x73, 0x74, 0x64, 0x2e, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, + 0x31, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0xe2, 0xfe, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, + 0x48, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, + 0x50, 0x00, 0x00, 0x00, 0x4c, 0xfe, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xd5, 0x6b, 0x8a, 0x3b, 0x01, 0x00, 0x00, 0x00, + 0xab, 0x49, 0x01, 0x3f, 0x01, 0x00, 0x00, 0x00, 0xfd, 0x56, 0x09, 0xbf, + 0x0c, 0x00, 0x00, 0x00, 0x73, 0x74, 0x64, 0x2e, 0x63, 0x6f, 0x6e, 0x73, + 0x74, 0x61, 0x6e, 0x74, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x52, 0xff, 0xff, 0xff, + 0x14, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x3c, 0x00, 0x00, 0x00, 0x44, 0xff, 0xff, 0xff, + 0x08, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x28, 0xb3, 0xd9, 0x38, 0x0c, 0x00, 0x00, 0x00, + 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x32, 0x2f, 0x62, 0x69, 0x61, 0x73, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0xaa, 0xff, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x38, 0x00, 0x00, 0x00, + 0x9c, 0xff, 0xff, 0xff, 0x08, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xdd, 0x9b, 0x21, 0x39, 0x0c, 0x00, 0x00, 0x00, + 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x33, 0x2f, 0x62, 0x69, 0x61, 0x73, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, 0x13, 0x00, 0x0c, 0x00, + 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x48, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0xf4, 0xd4, 0x51, 0x38, 0x0c, 0x00, 0x00, 0x00, 0x64, 0x65, 0x6e, 0x73, + 0x65, 0x5f, 0x34, 0x2f, 0x62, 0x69, 0x61, 0x73, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x1c, 0x00, + 0x18, 0x00, 0x17, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x2c, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x09, 0x84, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x14, 0x00, + 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x5d, 0x4f, 0xc9, 0x3c, 0x01, 0x00, 0x00, 0x00, 0x0e, 0x86, 0xc8, 0x40, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x73, 0x65, 0x72, 0x76, 0x69, 0x6e, 0x67, 0x5f, 0x64, 0x65, 0x66, 0x61, + 0x75, 0x6c, 0x74, 0x5f, 0x64, 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x32, 0x5f, + 0x69, 0x6e, 0x70, 0x75, 0x74, 0x3a, 0x30, 0x5f, 0x69, 0x6e, 0x74, 0x38, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xd8, 0xff, 0xff, 0xff, + 0x06, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, + 0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, + 0x0c, 0x00, 0x10, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x09 +}; +const int g_model_len = 2488; diff --git a/components/tflite/tensorflow/lite/micro/examples/hello_world/model.h b/components/tflite/tensorflow/lite/micro/examples/hello_world/model.h new file mode 100644 index 00000000..ffa87402 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/hello_world/model.h @@ -0,0 +1,31 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// Automatically created from a TensorFlow Lite flatbuffer using the command: +// xxd -i model.tflite > model.cc + +// This is a standard TensorFlow Lite model file that has been converted into a +// C data array, so it can be easily compiled into a binary for devices that +// don't have a file system. + +// See train/README.md for a full description of the creation process. + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_MODEL_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_MODEL_H_ + +extern const unsigned char g_model[]; +extern const int g_model_len; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_MODEL_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/hello_world/output_handler.cc b/components/tflite/tensorflow/lite/micro/examples/hello_world/output_handler.cc new file mode 100644 index 00000000..e114d4cd --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/hello_world/output_handler.cc @@ -0,0 +1,25 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/hello_world/output_handler.h" + +void HandleOutput(tflite::ErrorReporter *error_reporter, float x_value, + float y_value) +{ + // Log the current X and Y values + TF_LITE_REPORT_ERROR(error_reporter, "x_value: %f, y_value: %f\n", + static_cast(x_value), + static_cast(y_value)); +} diff --git a/components/tflite/tensorflow/lite/micro/examples/hello_world/output_handler.h b/components/tflite/tensorflow/lite/micro/examples/hello_world/output_handler.h new file mode 100644 index 00000000..9bb2be65 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/hello_world/output_handler.h @@ -0,0 +1,26 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_OUTPUT_HANDLER_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_OUTPUT_HANDLER_H_ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" + +// Called by the main loop to produce some output based on the x and y values +void HandleOutput(tflite::ErrorReporter *error_reporter, float x_value, + float y_value); + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_HELLO_WORLD_OUTPUT_HANDLER_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/hello_world/output_handler_test.cc b/components/tflite/tensorflow/lite/micro/examples/hello_world/output_handler_test.cc new file mode 100644 index 00000000..755b6af5 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/hello_world/output_handler_test.cc @@ -0,0 +1,32 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/hello_world/output_handler.h" + +#include "tensorflow/lite/micro/testing/micro_test.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestCallability) +{ + tflite::MicroErrorReporter micro_error_reporter; + + // This will have external side-effects (like printing to the debug console + // or lighting an LED) that are hard to observe, so the most we can do is + // make sure the call doesn't crash. + HandleOutput(µ_error_reporter, 0, 0); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/Makefile.inc b/components/tflite/tensorflow/lite/micro/examples/magic_wand/Makefile.inc new file mode 100644 index 00000000..e956230c --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/Makefile.inc @@ -0,0 +1,84 @@ +ifeq ($(TARGET), sparkfun_edge) + INCLUDES += \ + -I$(APOLLO3_SDK)/$(SF_BSPS_DEST)/common/third_party/lis2dh12/ + + THIRD_PARTY_CC_SRCS += \ + $(APOLLO3_SDK)/$(SF_BSPS_DEST)/common/third_party/lis2dh12/lis2dh12_platform_apollo3.c \ + $(APOLLO3_SDK)/boards_sfe/common/third_party/lis2dh12/lis2dh12_reg.c + + THIRD_PARTY_CC_HDRS += \ + $(APOLLO3_SDK)/boards_sfe/common/third_party/lis2dh12/lis2dh12_platform_apollo3.h \ + $(APOLLO3_SDK)/boards_sfe/common/third_party/lis2dh12/lis2dh12_reg.h +endif + +ACCELEROMETER_HANDLER_TEST_SRCS := \ +tensorflow/lite/micro/examples/magic_wand/accelerometer_handler.cc \ +tensorflow/lite/micro/examples/magic_wand/accelerometer_handler_test.cc + +ACCELEROMETER_HANDLER_TEST_HDRS := \ +tensorflow/lite/micro/examples/magic_wand/accelerometer_handler.h + +OUTPUT_HANDLER_TEST_SRCS := \ +tensorflow/lite/micro/examples/magic_wand/output_handler.cc \ +tensorflow/lite/micro/examples/magic_wand/output_handler_test.cc + +OUTPUT_HANDLER_TEST_HDRS := \ +tensorflow/lite/micro/examples/magic_wand/output_handler.h + +GESTURE_PREDICTOR_TEST_SRCS := \ +tensorflow/lite/micro/examples/magic_wand/gesture_predictor.cc \ +tensorflow/lite/micro/examples/magic_wand/gesture_predictor_test.cc + +GESTURE_PREDICTOR_TEST_HDRS := \ +tensorflow/lite/micro/examples/magic_wand/constants.h \ +tensorflow/lite/micro/examples/magic_wand/gesture_predictor.h \ + +magic_wand_TEST_SRCS := \ +tensorflow/lite/micro/examples/magic_wand/magic_wand_test.cc \ +tensorflow/lite/micro/examples/magic_wand/magic_wand_model_data.cc \ +tensorflow/lite/micro/examples/magic_wand/slope_micro_features_data.cc \ +tensorflow/lite/micro/examples/magic_wand/ring_micro_features_data.cc + +magic_wand_TEST_HDRS := \ +tensorflow/lite/micro/examples/magic_wand/magic_wand_model_data.h \ +tensorflow/lite/micro/examples/magic_wand/slope_micro_features_data.h \ +tensorflow/lite/micro/examples/magic_wand/ring_micro_features_data.h + +magic_wand_SRCS := \ +tensorflow/lite/micro/examples/magic_wand/main.cc \ +tensorflow/lite/micro/examples/magic_wand/main_functions.cc \ +tensorflow/lite/micro/examples/magic_wand/magic_wand_model_data.cc \ +tensorflow/lite/micro/examples/magic_wand/accelerometer_handler.cc \ +tensorflow/lite/micro/examples/magic_wand/gesture_predictor.cc \ +tensorflow/lite/micro/examples/magic_wand/output_handler.cc + +magic_wand_HDRS := \ +tensorflow/lite/micro/examples/magic_wand/main_functions.h \ +tensorflow/lite/micro/examples/magic_wand/constants.h \ +tensorflow/lite/micro/examples/magic_wand/magic_wand_model_data.h \ +tensorflow/lite/micro/examples/magic_wand/accelerometer_handler.h \ +tensorflow/lite/micro/examples/magic_wand/gesture_predictor.h \ +tensorflow/lite/micro/examples/magic_wand/output_handler.h + +#Find any platform - specific rules for this example. +include $(wildcard tensorflow/lite/micro/examples/magic_wand/*/Makefile.inc) + +# Tests the accelerometer handler +$(eval $(call microlite_test,gesture_accelerometer_handler_test,\ +$(ACCELEROMETER_HANDLER_TEST_SRCS),$(ACCELEROMETER_HANDLER_TEST_HDRS))) + +# Tests the output handler +$(eval $(call microlite_test,gesture_output_handler_test,\ +$(OUTPUT_HANDLER_TEST_SRCS),$(OUTPUT_HANDLER_TEST_HDRS))) + +# Tests the gesture predictor +$(eval $(call microlite_test,gesture_predictor_test,\ +$(GESTURE_PREDICTOR_TEST_SRCS),$(GESTURE_PREDICTOR_TEST_HDRS))) + +# Tests loading and running the gesture recognition model +$(eval $(call microlite_test,magic_wand_test,\ +$(magic_wand_TEST_SRCS),$(magic_wand_TEST_HDRS))) + +# Builds a standalone binary +$(eval $(call microlite_test,magic_wand,\ +$(magic_wand_SRCS),$(magic_wand_HDRS))) diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/README.md b/components/tflite/tensorflow/lite/micro/examples/magic_wand/README.md new file mode 100644 index 00000000..d9f0c754 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/README.md @@ -0,0 +1,493 @@ +# Magic wand example + +This example shows how you can use TensorFlow Lite to run a 20 kilobyte neural +network model to recognize gestures with an accelerometer. It's designed to run +on systems with very small amounts of memory, such as microcontrollers. + +The example application reads data from the accelerometer on an Arduino Nano 33 +BLE Sense or SparkFun Edge board and indicates when it has detected a gesture, +then outputs the gesture to the serial port. + +## Table of contents + +- [Getting started](#getting-started) +- [Deploy to Arduino](#deploy-to-arduino) +- [Deploy to Himax WE1 EVB](#deploy-to-himax-we1-evb) +- [Deploy to SparkFun Edge](#deploy-to-sparkfun-edge) +- [Run the tests on a development machine](#run-the-tests-on-a-development-machine) +- [Train your own model](#train-your-own-model) + +## Deploy to Arduino + +The following instructions will help you build and deploy this sample +to [Arduino](https://www.arduino.cc/) devices. + +The sample has been tested with the following devices: + +- [Arduino Nano 33 BLE Sense](https://store.arduino.cc/usa/nano-33-ble-sense-with-headers) + +### Install the Arduino_TensorFlowLite library + +This example application is included as part of the official TensorFlow Lite +Arduino library. To install it, open the Arduino library manager in +`Tools -> Manage Libraries...` and search for `Arduino_TensorFlowLite`. + +### Install and patch the accelerometer driver + +This example depends on the [Arduino_LSM9DS1](https://github.com/arduino-libraries/Arduino_LSM9DS1) +library to communicate with the device's accelerometer. However, the library +must be patched in order to enable the accelerometer's FIFO buffer. + +Follow these steps to install and patch the driver: + +#### Install the correct version + +In the Arduino IDE, go to `Tools -> Manage Libraries...` and search for +`Arduino_LSM9DS1`. **Install version 1.0.0 of the driver** to ensure the +following instructions work. + +#### Patch the driver + +The driver will be installed to your `Arduino/libraries` directory, in the +subdirectory `Arduino_LSM9DS1`. + +Open the following file: + +``` +Arduino_LSM9DS1/src/LSM9DS1.cpp +``` + +Go to the function named `LSM9DS1Class::begin()`. Insert the following lines at +the end of the function, immediately before the `return 1` statement: + +```cpp +// Enable FIFO (see docs https://www.st.com/resource/en/datasheet/DM00103319.pdf) +writeRegister(LSM9DS1_ADDRESS, 0x23, 0x02); +// Set continuous mode +writeRegister(LSM9DS1_ADDRESS, 0x2E, 0xC0); +``` + +Next, go to the function named `LSM9DS1Class::accelerationAvailable()`. You will +see the following lines: + +```cpp +if (readRegister(LSM9DS1_ADDRESS, LSM9DS1_STATUS_REG) & 0x01) { + return 1; +} +``` + +Comment out those lines and replace them with the following: + +```cpp +// Read FIFO_SRC. If any of the rightmost 8 bits have a value, there is data +if (readRegister(LSM9DS1_ADDRESS, 0x2F) & 63) { + return 1; +} +``` + +Next, save the file. Patching is now complete. + +### Load and run the example + +Once the library has been added, go to `File -> Examples`. You should see an +example near the bottom of the list named `TensorFlowLite`. Select +it and click `magic_wand` to load the example. + +Use the Arduino Desktop IDE to build and upload the example. Once it is running, +you should see the built-in LED on your device flashing. + +Open the Arduino Serial Monitor (`Tools -> Serial Monitor`). + +You will see the following message: + +``` +Magic starts! +``` + +Hold the Arduino with its components facing upwards and the USB cable to your +left. Perform the gestures "WING", "RING"(clockwise), and "SLOPE", and you +should see the corresponding output: + +``` +WING: +* * * + * * * * + * * * * + * * * * + * * * * + * * +``` + +``` +RING: + * + * * + * * + * * + * * + * * + * +``` + +``` +SLOPE: + * + * + * + * + * + * + * + * * * * * * * * +``` + +## Deploy to Himax WE1 EVB + +The following instructions will help you build and deploy this example to +[HIMAX WE1 EVB](https://github.com/HimaxWiseEyePlus/bsp_tflu/tree/master/HIMAX_WE1_EVB_board_brief) +board. To understand more about using this board, please check +[HIMAX WE1 EVB user guide](https://github.com/HimaxWiseEyePlus/bsp_tflu/tree/master/HIMAX_WE1_EVB_user_guide). + +### Initial Setup + +To use the HIMAX WE1 EVB, please make sure following software are installed: + +#### MetaWare Development Toolkit + +See +[Install the Synopsys DesignWare ARC MetaWare Development Toolkit](/tensorflow/lite/micro/tools/make/targets/arc/README.md#install-the-synopsys-designware-arc-metaware-development-toolkit) +section for instructions on toolchain installation. + +#### Make Tool version + +A `'make'` tool is required for deploying Tensorflow Lite Micro applications on +HIMAX WE1 EVB, See +[Check make tool version](/tensorflow/lite/micro/tools/make/targets/arc/README.md#make-tool) +section for proper environment. + +#### Serial Terminal Emulation Application + +There are 2 main purposes for HIMAX WE1 EVB Debug UART port + +- print application output +- burn application to flash by using xmodem send application binary + +You can use any terminal emulation program (like [PuTTY](https://www.putty.org/) +or [minicom](https://linux.die.net/man/1/minicom)). + +### Generate Example Project + +The example project for HIMAX WE1 EVB platform can be generated with the +following command: + +Download related third party data + +``` +make -f tensorflow/lite/micro/tools/make/Makefile TARGET=himax_we1_evb third_party_downloads +``` + +Generate magic wand project + +``` +make -f tensorflow/lite/micro/tools/make/Makefile generate_magic_wand_make_project TARGET=himax_we1_evb +``` + +### Build and Burn Example + +Following the Steps to run magic wand example at HIMAX WE1 EVB platform. + +1. Go to the generated example project directory. + + ``` + cd tensorflow/lite/micro/tools/make/gen/himax_we1_evb_arc/prj/magic_wand/make + ``` + +2. Build the example using + + ``` + make app + ``` + +3. After example build finish, copy ELF file and map file to image generate + tool directory. \ + image generate tool directory located at + `'tensorflow/lite/micro/tools/make/downloads/himax_we1_sdk/image_gen_linux_v3/'` + + ``` + cp magic_wand.elf himax_we1_evb.map ../../../../../downloads/himax_we1_sdk/image_gen_linux_v3/ + ``` + +4. Go to flash image generate tool directory. + + ``` + cd ../../../../../downloads/himax_we1_sdk/image_gen_linux_v3/ + ``` + + make sure this tool directory is in $PATH. You can permanently set it to + PATH by + + ``` + export PATH=$PATH:$(pwd) + ``` + +5. run image generate tool, generate flash image file. + + * Before running image generate tool, by typing `sudo chmod +x image_gen` + and `sudo chmod +x sign_tool` to make sure it is executable. + + ``` + image_gen -e magic_wand.elf -m himax_we1_evb.map -o out.img + ``` + +6. Download flash image file to HIMAX WE1 EVB by UART: + + * more detail about download image through UART can be found at + [HIMAX WE1 EVB update Flash image](https://github.com/HimaxWiseEyePlus/bsp_tflu/tree/master/HIMAX_WE1_EVB_user_guide#flash-image-update) + +After these steps, press reset button on the HIMAX WE1 EVB, you will see +application output in the serial terminal. Perform following gestures +`'Wing'`,`'Ring'`,`'Slope'` and you can see the output in serial terminal. + +``` +WING: +* * * + * * * * + * * * * + * * * * + * * * * + * * +``` + +``` +RING: + * + * * + * * + * * + * * + * * + * +``` + +``` +SLOPE: + * + * + * + * + * + * + * + * * * * * * * * +``` + +## Deploy to SparkFun Edge + +The following instructions will help you build and deploy this sample on the +[SparkFun Edge development board](https://sparkfun.com/products/15170). + +If you're new to using this board, we recommend walking through the +[AI on a microcontroller with TensorFlow Lite and SparkFun Edge](https://codelabs.developers.google.com/codelabs/sparkfun-tensorflow) +codelab to get an understanding of the workflow. + +### Compile the binary + +Run the following command to build a binary for SparkFun Edge. + +``` +make -f tensorflow/lite/micro/tools/make/Makefile TARGET=sparkfun_edge magic_wand_bin +``` + +The binary will be created in the following location: + +``` +tensorflow/lite/micro/tools/make/gen/sparkfun_edge_cortex-m4/bin/magic_wand.bin +``` + +### Sign the binary + +The binary must be signed with cryptographic keys to be deployed to the device. +We'll now run some commands that will sign our binary so it can be flashed to +the SparkFun Edge. The scripts we are using come from the Ambiq SDK, which is +downloaded when the `Makefile` is run. + +Enter the following command to set up some dummy cryptographic keys we can use +for development: + +``` +cp tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.2.0/tools/apollo3_scripts/keys_info0.py \ +tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.2.0/tools/apollo3_scripts/keys_info.py +``` + +Next, run the following command to create a signed binary: + +``` +python3 tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.2.0/tools/apollo3_scripts/create_cust_image_blob.py \ +--bin tensorflow/lite/micro/tools/make/gen/sparkfun_edge_cortex-m4/bin/magic_wand.bin \ +--load-address 0xC000 \ +--magic-num 0xCB \ +-o main_nonsecure_ota \ +--version 0x0 +``` + +This will create the file `main_nonsecure_ota.bin`. We'll now run another +command to create a final version of the file that can be used to flash our +device with the bootloader script we will use in the next step: + +``` +python3 tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.2.0/tools/apollo3_scripts/create_cust_wireupdate_blob.py \ +--load-address 0x20000 \ +--bin main_nonsecure_ota.bin \ +-i 6 \ +-o main_nonsecure_wire \ +--options 0x1 +``` + +You should now have a file called `main_nonsecure_wire.bin` in the directory +where you ran the commands. This is the file we'll be flashing to the device. + +### Flash the binary + +Next, attach the board to your computer via a USB-to-serial adapter. + +**Note:** If you're using the +[SparkFun Serial Basic Breakout](https://www.sparkfun.com/products/15096), you +should +[install the latest drivers](https://learn.sparkfun.com/tutorials/sparkfun-serial-basic-ch340c-hookup-guide#drivers-if-you-need-them) +before you continue. + +Once connected, assign the USB device name to an environment variable: + +``` +export DEVICENAME=put your device name here +``` + +Set another variable with the baud rate: + +``` +export BAUD_RATE=921600 +``` + +Now, hold the button marked `14` on the device. While still holding the button, +hit the button marked `RST`. Continue holding the button marked `14` while +running the following command: + +``` +python3 tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.2.0/tools/apollo3_scripts/uart_wired_update.py \ +-b ${BAUD_RATE} ${DEVICENAME} \ +-r 1 \ +-f main_nonsecure_wire.bin \ +-i 6 +``` + +You should see a long stream of output as the binary is flashed to the device. +Once you see the following lines, flashing is complete: + +``` +Sending Reset Command. +Done. +``` + +If you don't see these lines, flashing may have failed. Try running through the +steps in [Flash the binary](#flash-the-binary) again (you can skip over setting +the environment variables). If you continue to run into problems, follow the +[AI on a microcontroller with TensorFlow Lite and SparkFun Edge](https://codelabs.developers.google.com/codelabs/sparkfun-tensorflow) +codelab, which includes more comprehensive instructions for the flashing +process. + +The binary should now be deployed to the device. Hit the button marked `RST` to +reboot the board. + +Do the three magic gestures and you will see the corresponding LED light on! Red +for "Wing", blue for "Ring" and green for "Slope". + +Debug information is logged by the board while the program is running. To view +it, establish a serial connection to the board using a baud rate of `115200`. On +OSX and Linux, the following command should work: + +``` +screen ${DEVICENAME} 115200 +``` + +You will see the following message: + +``` +Magic starts! +``` + +Keep the chip face up, do magic gestures "WING", "RING"(clockwise), and "SLOPE" +with your wand, and you will see the corresponding output like this! + +``` +WING: +* * * + * * * * + * * * * + * * * * + * * * * + * * +``` + +``` +RING: + * + * * + * * + * * + * * + * * + * +``` + +``` +SLOPE: + * + * + * + * + * + * + * + * * * * * * * * +``` + +To stop viewing the debug output with `screen`, hit `Ctrl+A`, immediately +followed by the `K` key, then hit the `Y` key. + +## Run the tests on a development machine + +To compile and test this example on a desktop Linux or macOS machine, first +clone the TensorFlow repository from GitHub to a convenient place: + +```bash +git clone --depth 1 https://github.com/tensorflow/tensorflow.git +``` + +Next, put this folder under the +tensorflow/tensorflow/lite/micro/examples/ folder, then `cd` into +the source directory from a terminal and run the following command: + +```bash +make -f tensorflow/lite/micro/tools/make/Makefile test_magic_wand_test +``` + +This will take a few minutes, and downloads frameworks the code uses like +[CMSIS](https://developer.arm.com/embedded/cmsis) and +[flatbuffers](https://google.github.io/flatbuffers/). Once that process has +finished, you should see a series of files get compiled, followed by some +logging output from a test, which should conclude with `~~~ALL TESTS PASSED~~~`. + +If you see this, it means that a small program has been built and run that loads +the trained TensorFlow model, runs some example inputs through it, and got the +expected outputs. + +To understand how TensorFlow Lite does this, you can look at the source in +[hello_world_test.cc](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/micro/examples/hello_world/hello_world_test.cc). +It's a fairly small amount of code that creates an interpreter, gets a handle to +a model that's been compiled into the program, and then invokes the interpreter +with the model and sample inputs. + +## Train your own model + +To train your own model, or create a new model for a new set of gestures, +follow the instructions in [magic_wand/train/README.md](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/micro/examples/magic_wand/train/README.md). diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/accelerometer_handler.cc b/components/tflite/tensorflow/lite/micro/examples/magic_wand/accelerometer_handler.cc new file mode 100644 index 00000000..b53d10d4 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/accelerometer_handler.cc @@ -0,0 +1,42 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/magic_wand/accelerometer_handler.h" + +int begin_index = 0; + +TfLiteStatus SetupAccelerometer(tflite::ErrorReporter *error_reporter) +{ + return kTfLiteOk; +} + +bool ReadAccelerometer(tflite::ErrorReporter *error_reporter, float *input, + int length) +{ + begin_index += 3; + // Reset begin_index to simulate behavior of loop buffer + if (begin_index >= 600) + begin_index = 0; + // Only return true after the function was called 100 times, simulating the + // desired behavior of a real implementation (which does not return data until + // a sufficient amount is available) + if (begin_index > 300) { + for (int i = 0; i < length; ++i) + input[i] = 0; + return true; + } else { + return false; + } +} diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/accelerometer_handler.h b/components/tflite/tensorflow/lite/micro/examples/magic_wand/accelerometer_handler.h new file mode 100644 index 00000000..daa67f67 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/accelerometer_handler.h @@ -0,0 +1,29 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_ACCELEROMETER_HANDLER_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_ACCELEROMETER_HANDLER_H_ + +#define kChannelNumber 3 + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" + +extern int begin_index; +extern TfLiteStatus SetupAccelerometer(tflite::ErrorReporter *error_reporter); +extern bool ReadAccelerometer(tflite::ErrorReporter *error_reporter, + float *input, int length); + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_ACCELEROMETER_HANDLER_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/accelerometer_handler_test.cc b/components/tflite/tensorflow/lite/micro/examples/magic_wand/accelerometer_handler_test.cc new file mode 100644 index 00000000..333266a8 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/accelerometer_handler_test.cc @@ -0,0 +1,49 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/magic_wand/accelerometer_handler.h" + +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestSetup) +{ + tflite::MicroErrorReporter micro_error_reporter; + TfLiteStatus setup_status = SetupAccelerometer(µ_error_reporter); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, setup_status); +} + +TF_LITE_MICRO_TEST(TestAccelerometer) +{ + float input[384] = { 0.0 }; + tflite::MicroErrorReporter micro_error_reporter; + // Test that the function returns false before insufficient data is available + bool inference_flag = ReadAccelerometer(µ_error_reporter, input, 384); + TF_LITE_MICRO_EXPECT_EQ(inference_flag, false); + + // Test that the function returns true once sufficient data is available to + // fill the model's input buffer (128 sets of values) + for (int i = 1; i <= 128; i++) { + inference_flag = ReadAccelerometer(µ_error_reporter, input, 384); + } + TF_LITE_MICRO_EXPECT_EQ(inference_flag, true); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/constants.h b/components/tflite/tensorflow/lite/micro/examples/magic_wand/constants.h new file mode 100644 index 00000000..4c64a0db --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/constants.h @@ -0,0 +1,38 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_CONSTANTS_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_CONSTANTS_H_ + +// The expected accelerometer data sample frequency +const float kTargetHz = 25; + +// What gestures are supported. +constexpr int kGestureCount = 4; +constexpr int kWingGesture = 0; +constexpr int kRingGesture = 1; +constexpr int kSlopeGesture = 2; +constexpr int kNoGesture = 3; + +// These control the sensitivity of the detection algorithm. If you're seeing +// too many false positives or not enough true positives, you can try tweaking +// these thresholds. Often, increasing the size of the training set will give +// more robust results though, so consider retraining if you are seeing poor +// predictions. +constexpr float kDetectionThreshold = 0.8f; +constexpr int kPredictionHistoryLength = 5; +constexpr int kPredictionSuppressionDuration = 25; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_CONSTANTS_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/gesture_predictor.cc b/components/tflite/tensorflow/lite/micro/examples/magic_wand/gesture_predictor.cc new file mode 100644 index 00000000..d0dbd6f3 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/gesture_predictor.cc @@ -0,0 +1,73 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/magic_wand/gesture_predictor.h" + +#include "tensorflow/lite/micro/examples/magic_wand/constants.h" + +namespace { +// State for the averaging algorithm we're using. +float prediction_history[kGestureCount][kPredictionHistoryLength] = {}; +int prediction_history_index = 0; +int prediction_suppression_count = 0; +} // namespace + +// Return the result of the last prediction +// 0: wing("W"), 1: ring("O"), 2: slope("angle"), 3: unknown +int PredictGesture(float *output) +{ + // Record the latest predictions in our rolling history buffer. + for (int i = 0; i < kGestureCount; ++i) { + prediction_history[i][prediction_history_index] = output[i]; + } + // Figure out which slot to put the next predictions into. + ++prediction_history_index; + if (prediction_history_index >= kPredictionHistoryLength) { + prediction_history_index = 0; + } + + // Average the last n predictions for each gesture, and find which has the + // highest score. + int max_predict_index = -1; + float max_predict_score = 0.0f; + for (int i = 0; i < kGestureCount; i++) { + float prediction_sum = 0.0f; + for (int j = 0; j < kPredictionHistoryLength; ++j) { + prediction_sum += prediction_history[i][j]; + } + const float prediction_average = prediction_sum / kPredictionHistoryLength; + if ((max_predict_index == -1) || (prediction_average > max_predict_score)) { + max_predict_index = i; + max_predict_score = prediction_average; + } + } + + // If there's been a recent prediction, don't trigger a new one too soon. + if (prediction_suppression_count > 0) { + --prediction_suppression_count; + } + // If we're predicting no gesture, or the average score is too low, or there's + // been a gesture recognised too recently, return no gesture. + if ((max_predict_index == kNoGesture) || + (max_predict_score < kDetectionThreshold) || + (prediction_suppression_count > 0)) { + return kNoGesture; + } else { + // Reset the suppression counter so we don't come up with another prediction + // too soon. + prediction_suppression_count = kPredictionSuppressionDuration; + return max_predict_index; + } +} diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/gesture_predictor.h b/components/tflite/tensorflow/lite/micro/examples/magic_wand/gesture_predictor.h new file mode 100644 index 00000000..6ff80a12 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/gesture_predictor.h @@ -0,0 +1,21 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_GESTURE_PREDICTOR_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_GESTURE_PREDICTOR_H_ + +extern int PredictGesture(float *output); + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_GESTURE_PREDICTOR_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/gesture_predictor_test.cc b/components/tflite/tensorflow/lite/micro/examples/magic_wand/gesture_predictor_test.cc new file mode 100644 index 00000000..e61a8e3b --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/gesture_predictor_test.cc @@ -0,0 +1,69 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/magic_wand/gesture_predictor.h" + +#include "tensorflow/lite/micro/examples/magic_wand/constants.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(SuccessfulPrediction) +{ + // Use the threshold from the 0th gesture. + float probabilities[kGestureCount] = { kDetectionThreshold, 0.0, 0.0, 0.0 }; + int prediction; + // Loop just too few times to trigger a prediction. + for (int i = 0; i < kPredictionHistoryLength - 1; i++) { + prediction = PredictGesture(probabilities); + TF_LITE_MICRO_EXPECT_EQ(prediction, kNoGesture); + } + // Call once more, triggering a prediction + // for category 0. + prediction = PredictGesture(probabilities); + TF_LITE_MICRO_EXPECT_EQ(prediction, 0); +} + +TF_LITE_MICRO_TEST(FailPartWayThere) +{ + // Use the threshold from the 0th gesture. + float probabilities[kGestureCount] = { kDetectionThreshold, 0.0, 0.0, 0.0 }; + int prediction; + // Loop just too few times to trigger a prediction. + for (int i = 0; i <= kPredictionHistoryLength - 1; i++) { + prediction = PredictGesture(probabilities); + TF_LITE_MICRO_EXPECT_EQ(prediction, kNoGesture); + } + // Call with a different prediction, triggering a failure. + probabilities[0] = 0.0; + probabilities[2] = 1.0; + prediction = PredictGesture(probabilities); + TF_LITE_MICRO_EXPECT_EQ(prediction, kNoGesture); +} + +TF_LITE_MICRO_TEST(InsufficientProbability) +{ + // Just below the detection threshold. + float probabilities[kGestureCount] = { kDetectionThreshold - 0.1f, 0.0, 0.0, + 0.0 }; + int prediction; + // Loop the exact right number of times + for (int i = 0; i <= kPredictionHistoryLength; i++) { + prediction = PredictGesture(probabilities); + TF_LITE_MICRO_EXPECT_EQ(prediction, kNoGesture); + } +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/magic_wand_model_data.cc b/components/tflite/tensorflow/lite/micro/examples/magic_wand/magic_wand_model_data.cc new file mode 100644 index 00000000..e314ab8b --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/magic_wand_model_data.cc @@ -0,0 +1,1660 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// Automatically created from a TensorFlow Lite flatbuffer using the command: +// xxd -i magic_wand_model.tflite > magic_wand_model_data.cc +// See the README for a full description of the creation process. + +#include "tensorflow/lite/micro/examples/magic_wand/magic_wand_model_data.h" + +// Keep model aligned to 8 bytes to guarantee aligned 64-bit accesses. +alignas(8) const unsigned char g_magic_wand_model_data[] = { + 0x1c, 0x00, 0x00, 0x00, 0x54, 0x46, 0x4c, 0x33, 0x00, 0x00, 0x12, 0x00, + 0x1c, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00, + 0x00, 0x00, 0x18, 0x00, 0x12, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x24, 0x4c, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x2c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x14, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xdc, 0x00, 0x00, 0x00, + 0x0f, 0x00, 0x00, 0x00, 0x54, 0x4f, 0x43, 0x4f, 0x20, 0x43, 0x6f, 0x6e, + 0x76, 0x65, 0x72, 0x74, 0x65, 0x64, 0x2e, 0x00, 0x12, 0x00, 0x00, 0x00, + 0xb0, 0x00, 0x00, 0x00, 0xa4, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, + 0x8c, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, + 0x68, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, + 0x50, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x38, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x6e, 0xb6, 0xff, 0xff, 0x68, 0x00, 0x00, 0x00, 0x30, 0xb6, 0xff, 0xff, + 0x34, 0xb6, 0xff, 0xff, 0x7e, 0xb6, 0xff, 0xff, 0xf0, 0x01, 0x00, 0x00, + 0x86, 0xb6, 0xff, 0xff, 0xc8, 0x03, 0x00, 0x00, 0x48, 0xb6, 0xff, 0xff, + 0x4c, 0xb6, 0xff, 0xff, 0x50, 0xb6, 0xff, 0xff, 0x54, 0xb6, 0xff, 0xff, + 0x58, 0xb6, 0xff, 0xff, 0x5c, 0xb6, 0xff, 0xff, 0xa6, 0xb6, 0xff, 0xff, + 0xc0, 0x0d, 0x00, 0x00, 0xae, 0xb6, 0xff, 0xff, 0x00, 0x46, 0x00, 0x00, + 0xb6, 0xb6, 0xff, 0xff, 0x60, 0x46, 0x00, 0x00, 0xbe, 0xb6, 0xff, 0xff, + 0xe0, 0x46, 0x00, 0x00, 0xc6, 0xb6, 0xff, 0xff, 0x48, 0x47, 0x00, 0x00, + 0xce, 0xb6, 0xff, 0xff, 0x98, 0x48, 0x00, 0x00, 0x90, 0xb6, 0xff, 0xff, + 0x05, 0x00, 0x00, 0x00, 0x31, 0x2e, 0x35, 0x2e, 0x30, 0x00, 0x00, 0x00, + 0x54, 0xf4, 0xff, 0xff, 0x08, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, + 0x13, 0x00, 0x00, 0x00, 0x6d, 0x69, 0x6e, 0x5f, 0x72, 0x75, 0x6e, 0x74, + 0x69, 0x6d, 0x65, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x00, + 0x0c, 0x00, 0x14, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x88, 0x48, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x9c, 0x0c, 0x00, 0x00, 0x14, 0x0b, 0x00, 0x00, + 0xd4, 0x00, 0x00, 0x00, 0x24, 0x45, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, + 0xa4, 0x02, 0x00, 0x00, 0x80, 0x45, 0x00, 0x00, 0x9c, 0x0b, 0x00, 0x00, + 0xb0, 0x0c, 0x00, 0x00, 0xc4, 0x47, 0x00, 0x00, 0x50, 0x0b, 0x00, 0x00, + 0x2c, 0x0c, 0x00, 0x00, 0x48, 0x46, 0x00, 0x00, 0xec, 0x45, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0xc8, 0x0b, 0x00, 0x00, 0x66, 0xb8, 0xff, 0xff, + 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x2a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, + 0x61, 0x6c, 0x2f, 0x6d, 0x61, 0x78, 0x5f, 0x70, 0x6f, 0x6f, 0x6c, 0x69, + 0x6e, 0x67, 0x32, 0x64, 0x2f, 0x4d, 0x61, 0x78, 0x50, 0x6f, 0x6f, 0x6c, + 0x00, 0x00, 0x00, 0x00, 0x88, 0xb7, 0xff, 0xff, 0xba, 0xb8, 0xff, 0xff, + 0x10, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x34, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x80, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x16, 0x00, 0x00, 0x00, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, + 0x61, 0x6c, 0x2f, 0x63, 0x6f, 0x6e, 0x76, 0x32, 0x64, 0x2f, 0x52, 0x65, + 0x6c, 0x75, 0x00, 0x00, 0xd0, 0xb7, 0xff, 0xff, 0x02, 0xb9, 0xff, 0xff, + 0x10, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x44, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x27, 0x00, 0x00, 0x00, 0x73, 0x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c, 0xea, 0x45, 0x40, 0xbc, 0x04, 0xd3, 0x9d, 0xb7, + 0xe3, 0xdf, 0xae, 0xbd, 0x80, 0x5e, 0x59, 0xbe, 0x88, 0x15, 0xc0, 0xbd, + 0xea, 0x86, 0xaa, 0xbd, 0x3b, 0x4a, 0x64, 0x3d, 0x89, 0x25, 0x42, 0xbe, + 0xc2, 0x29, 0x93, 0xbe, 0x62, 0x85, 0x00, 0x3e, 0xf1, 0x0e, 0xda, 0xbd, + 0x48, 0x09, 0xb8, 0xbe, 0xad, 0xe2, 0x4d, 0xbe, 0x69, 0x26, 0x99, 0xbe, + 0x86, 0x3c, 0xcd, 0xbe, 0x05, 0xe6, 0x4e, 0xbd, 0xdb, 0x8f, 0xfb, 0x3d, + 0xc6, 0xf5, 0x97, 0x3e, 0xde, 0xba, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x0d, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, + 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x63, + 0x6f, 0x6e, 0x76, 0x32, 0x64, 0x5f, 0x31, 0x2f, 0x43, 0x6f, 0x6e, 0x76, + 0x32, 0x44, 0x2f, 0x52, 0x65, 0x61, 0x64, 0x56, 0x61, 0x72, 0x69, 0x61, + 0x62, 0x6c, 0x65, 0x4f, 0x70, 0x00, 0x00, 0x00, 0x08, 0xba, 0xff, 0xff, + 0x00, 0x08, 0x00, 0x00, 0x40, 0x7a, 0x10, 0xbf, 0x9b, 0xf1, 0xcc, 0xbe, + 0x78, 0x88, 0x1d, 0xbf, 0xc2, 0xb7, 0x09, 0xbf, 0xbd, 0xd6, 0xaf, 0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0a, 0xbe, 0xc4, 0xb8, 0x0f, 0xbe, + 0xaa, 0xb2, 0xab, 0xbd, 0x93, 0x40, 0x5c, 0xbd, 0x35, 0xf0, 0x19, 0xbd, + 0x4a, 0xa8, 0x02, 0x3b, 0x3c, 0x51, 0x1a, 0x3c, 0xbe, 0x2d, 0xdd, 0xbb, + 0x55, 0x5d, 0xc3, 0x3d, 0x10, 0x6f, 0x7c, 0xbd, 0x62, 0xf7, 0x45, 0xbe, + 0xd5, 0xda, 0xe1, 0x3d, 0x25, 0xd5, 0x13, 0x3e, 0xf0, 0xd6, 0xea, 0xbd, + 0x62, 0x2b, 0x56, 0xbd, 0x80, 0x0c, 0xb1, 0x3d, 0x19, 0xbe, 0xa5, 0x3d, + 0x3e, 0xc3, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x63, 0x6f, 0x6e, 0x76, + 0x32, 0x64, 0x5f, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x0c, 0x00, 0x04, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x7f, 0x43, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x9e, 0xc3, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, + 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x64, + 0x65, 0x6e, 0x73, 0x65, 0x2f, 0x52, 0x65, 0x6c, 0x75, 0x00, 0x00, 0x00, + 0xac, 0xc2, 0xff, 0xff, 0xde, 0xc3, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x0a, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x63, + 0x6f, 0x6e, 0x76, 0x32, 0x64, 0x5f, 0x31, 0x2f, 0x52, 0x65, 0x6c, 0x75, + 0x00, 0x00, 0x00, 0x00, 0xf8, 0xc2, 0xff, 0xff, 0x2a, 0xc4, 0xff, 0xff, + 0x10, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x22, 0x00, 0x00, 0x00, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, + 0x61, 0x6c, 0x2f, 0x6d, 0x61, 0x78, 0x5f, 0x70, 0x6f, 0x6f, 0x6c, 0x69, + 0x6e, 0x67, 0x32, 0x64, 0x5f, 0x31, 0x2f, 0x4d, 0x61, 0x78, 0x50, 0x6f, + 0x6f, 0x6c, 0x00, 0x00, 0x4c, 0xc3, 0xff, 0xff, 0x7e, 0xc4, 0xff, 0xff, + 0x10, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x73, 0x65, 0x71, 0x75, + 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x64, 0x65, 0x6e, 0x73, 0x65, + 0x5f, 0x31, 0x2f, 0x42, 0x69, 0x61, 0x73, 0x41, 0x64, 0x64, 0x00, 0x00, + 0x90, 0xc3, 0xff, 0xff, 0xc2, 0xc4, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, + 0x00, 0x00, 0x00, 0x00, 0xc4, 0xc3, 0xff, 0xff, 0xf6, 0xc4, 0xff, 0xff, + 0x10, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x48, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0xe0, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x73, 0x65, 0x71, 0x75, + 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x64, 0x65, 0x6e, 0x73, 0x65, + 0x2f, 0x4d, 0x61, 0x74, 0x4d, 0x75, 0x6c, 0x2f, 0x52, 0x65, 0x61, 0x64, + 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x4f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xf6, 0x01, 0x3e, + 0x90, 0xf0, 0xb4, 0xbd, 0xd0, 0x21, 0x9a, 0xbe, 0x74, 0x43, 0x14, 0x3e, + 0x4d, 0xe8, 0x0b, 0xbe, 0x80, 0x2b, 0x93, 0xbd, 0x87, 0x39, 0x35, 0x3e, + 0x90, 0x63, 0xb8, 0x3d, 0xcf, 0x2c, 0x83, 0x3e, 0xbd, 0xe5, 0x0b, 0xbf, + 0x5f, 0xf7, 0x90, 0x3c, 0xa0, 0x61, 0x52, 0xbc, 0x8f, 0x88, 0xac, 0xbc, + 0x0c, 0x64, 0xd3, 0x3d, 0x9c, 0xd9, 0x8b, 0x3d, 0x80, 0xb7, 0x39, 0xbe, + 0x4e, 0x30, 0x95, 0x3e, 0x73, 0x3e, 0xda, 0xbe, 0x51, 0x56, 0x84, 0x3d, + 0xe6, 0x28, 0x85, 0x3d, 0xb9, 0xe9, 0x87, 0xbe, 0x46, 0x01, 0x6c, 0xbd, + 0x4b, 0x64, 0xd5, 0x3d, 0x56, 0xfd, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, + 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x63, + 0x6f, 0x6e, 0x76, 0x32, 0x64, 0x2f, 0x43, 0x6f, 0x6e, 0x76, 0x32, 0x44, + 0x5f, 0x62, 0x69, 0x61, 0x73, 0x00, 0x00, 0x00, 0x68, 0xfc, 0xff, 0xff, + 0x20, 0x00, 0x00, 0x00, 0xe4, 0xe5, 0x3e, 0xc0, 0x22, 0xe7, 0x92, 0x3f, + 0x57, 0x04, 0xde, 0xbf, 0xda, 0x8f, 0x1c, 0x3e, 0x47, 0xbf, 0x05, 0xc0, + 0x53, 0xab, 0xcb, 0xbf, 0x68, 0x6a, 0x6a, 0xbf, 0xd2, 0x0b, 0xe4, 0xbf, + 0xbe, 0xfd, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x73, 0x65, 0x71, 0x75, + 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x63, 0x6f, 0x6e, 0x76, 0x32, + 0x64, 0x5f, 0x31, 0x2f, 0x43, 0x6f, 0x6e, 0x76, 0x32, 0x44, 0x5f, 0x62, + 0x69, 0x61, 0x73, 0x00, 0xd0, 0xfc, 0xff, 0xff, 0x40, 0x00, 0x00, 0x00, + 0xa3, 0x15, 0xb7, 0x3e, 0x29, 0x67, 0x95, 0x3f, 0x4b, 0x96, 0x62, 0xbe, + 0x61, 0x5f, 0xfc, 0x3e, 0xa2, 0xd4, 0x3e, 0xbf, 0x45, 0x1c, 0x0d, 0xbf, + 0x29, 0xdd, 0x70, 0xbe, 0x9a, 0x75, 0x97, 0xbf, 0xfc, 0x0a, 0x6f, 0xbe, + 0xcc, 0x56, 0x25, 0x3f, 0xdf, 0xac, 0x98, 0xbf, 0x0e, 0x1c, 0x8b, 0xbf, + 0xa5, 0xd8, 0x8c, 0x3f, 0xa5, 0x42, 0xd5, 0x3c, 0xa9, 0x8e, 0x7a, 0xbf, + 0x9e, 0xdb, 0x71, 0xbe, 0x46, 0xfe, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, + 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x64, + 0x65, 0x6e, 0x73, 0x65, 0x5f, 0x31, 0x2f, 0x4d, 0x61, 0x74, 0x4d, 0x75, + 0x6c, 0x5f, 0x62, 0x69, 0x61, 0x73, 0x00, 0x00, 0x58, 0xfd, 0xff, 0xff, + 0x10, 0x00, 0x00, 0x00, 0xc3, 0x99, 0xb6, 0xbf, 0xe9, 0x87, 0x8b, 0x3f, + 0xac, 0x83, 0x9a, 0xbf, 0x4c, 0x49, 0x3d, 0xbe, 0x9e, 0xfe, 0xff, 0xff, + 0x10, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x48, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x73, 0x65, 0x71, 0x75, + 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x64, 0x65, 0x6e, 0x73, 0x65, + 0x5f, 0x31, 0x2f, 0x4d, 0x61, 0x74, 0x4d, 0x75, 0x6c, 0x2f, 0x52, 0x65, + 0x61, 0x64, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x4f, 0x70, + 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x73, 0x65, 0x00, 0x00, + 0xc8, 0xfd, 0xff, 0xff, 0x00, 0x01, 0x00, 0x00, 0x40, 0x5c, 0x8a, 0xbe, + 0xc5, 0x88, 0xaa, 0x3e, 0xb0, 0x76, 0x1f, 0xbe, 0x35, 0x3a, 0x58, 0x3e, + 0x84, 0xa5, 0xa3, 0x3e, 0x38, 0xd9, 0x49, 0x3d, 0x58, 0x63, 0x78, 0xbc, + 0x82, 0x94, 0x2e, 0xbe, 0x97, 0xde, 0x6e, 0xbe, 0xea, 0x27, 0x9f, 0xbe, + 0x1d, 0x24, 0xc0, 0x3d, 0x21, 0x31, 0x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6e, 0xa2, 0xbe, 0x84, 0x4a, 0x12, 0x3e, + 0x32, 0xd9, 0xcb, 0x3d, 0xad, 0x16, 0xd4, 0x3e, 0xf5, 0xa8, 0x85, 0xbe, + 0x5c, 0x34, 0xc8, 0xbd, 0x31, 0x02, 0xac, 0xbe, 0x3e, 0x15, 0x9e, 0x3e, + 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, + 0x0c, 0x00, 0x10, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x64, + 0x65, 0x6e, 0x73, 0x65, 0x2f, 0x4d, 0x61, 0x74, 0x4d, 0x75, 0x6c, 0x5f, + 0x62, 0x69, 0x61, 0x73, 0x00, 0x00, 0x00, 0x00, 0x20, 0xff, 0xff, 0xff, + 0x40, 0x00, 0x00, 0x00, 0xa9, 0xa9, 0x93, 0x3f, 0x3c, 0xda, 0x21, 0xbe, + 0x33, 0xe3, 0x3d, 0x3d, 0xd8, 0xed, 0x33, 0xbf, 0x4c, 0x9d, 0x3e, 0xbf, + 0xba, 0x40, 0xa6, 0x3f, 0x6e, 0x4e, 0x25, 0xbe, 0x6e, 0x5e, 0x93, 0x3f, + 0x48, 0xa2, 0xc5, 0xbe, 0x67, 0xaa, 0x33, 0x3e, 0xc0, 0x66, 0x20, 0x3f, + 0xb3, 0x25, 0x7e, 0xbe, 0x8a, 0x2f, 0xd9, 0xbe, 0xda, 0x64, 0xc8, 0x3f, + 0x1a, 0x14, 0x89, 0xbd, 0xea, 0x48, 0x89, 0x3e, 0x07, 0x00, 0x00, 0x00, + 0x00, 0x02, 0x00, 0x00, 0x90, 0x01, 0x00, 0x00, 0x3c, 0x01, 0x00, 0x00, + 0xd0, 0x00, 0x00, 0x00, 0x8c, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x30, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, + 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x0b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x70, 0xfe, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x08, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x0d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xb0, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x08, 0x02, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2e, 0xfe, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x01, 0xf0, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x05, + 0x03, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x2c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x0e, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x14, 0x00, 0x18, 0x00, 0x00, 0x00, 0x08, 0x00, + 0x0c, 0x00, 0x07, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x08, 0x00, + 0x0c, 0x00, 0x07, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xa8, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x05, 0x03, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, + 0x18, 0x00, 0x07, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x1c, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x07, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, + 0x48, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xce, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x19, + 0xd6, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, 0xde, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x09, 0xe6, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x11, + 0xfa, 0xff, 0xff, 0xff, 0x00, 0x03, 0x06, 0x00, 0x06, 0x00, 0x05, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x11, 0x06, 0x00, 0x08, 0x00, 0x07, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04 +}; +unsigned int model_tflite_len = 19616; diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/magic_wand_model_data.h b/components/tflite/tensorflow/lite/micro/examples/magic_wand/magic_wand_model_data.h new file mode 100644 index 00000000..42a73c86 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/magic_wand_model_data.h @@ -0,0 +1,27 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// This is a standard TensorFlow Lite model file that has been converted into a +// C data array, so it can be easily compiled into a binary for devices that +// don't have a file system. It was created using the command: +// xxd -i magic_wand_model.tflite > magic_wand_model_data.cc + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_MAGIC_WAND_MODEL_DATA_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_MAGIC_WAND_MODEL_DATA_H_ + +extern const unsigned char g_magic_wand_model_data[]; +extern const int g_magic_wand_model_data_len; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_MAGIC_WAND_MODEL_DATA_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/magic_wand_test.cc b/components/tflite/tensorflow/lite/micro/examples/magic_wand/magic_wand_test.cc new file mode 100644 index 00000000..838e2b86 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/magic_wand_test.cc @@ -0,0 +1,150 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/magic_wand/magic_wand_model_data.h" +#include "tensorflow/lite/micro/examples/magic_wand/ring_micro_features_data.h" +#include "tensorflow/lite/micro/examples/magic_wand/slope_micro_features_data.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/micro_interpreter.h" +#include "tensorflow/lite/micro/micro_mutable_op_resolver.h" +#include "tensorflow/lite/micro/testing/micro_test.h" +#include "tensorflow/lite/schema/schema_generated.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(LoadModelAndPerformInference) +{ + // Set up logging + tflite::MicroErrorReporter micro_error_reporter; + + // Map the model into a usable data structure. This doesn't involve any + // copying or parsing, it's a very lightweight operation. + const tflite::Model *model = ::tflite::GetModel(g_magic_wand_model_data); + if (model->version() != TFLITE_SCHEMA_VERSION) { + TF_LITE_REPORT_ERROR(µ_error_reporter, + "Model provided is schema version %d not equal " + "to supported version %d.\n", + model->version(), TFLITE_SCHEMA_VERSION); + } + + // Pull in only the operation implementations we need. + // This relies on a complete list of all the ops needed by this graph. + // An easier approach is to just use the AllOpsResolver, but this will + // incur some penalty in code space for op implementations that are not + // needed by this graph. + static tflite::MicroMutableOpResolver<5> micro_op_resolver; // NOLINT + micro_op_resolver.AddConv2D(); + micro_op_resolver.AddDepthwiseConv2D(); + micro_op_resolver.AddFullyConnected(); + micro_op_resolver.AddMaxPool2D(); + micro_op_resolver.AddSoftmax(); + + // Create an area of memory to use for input, output, and intermediate arrays. + // Finding the minimum value for your model may require some trial and error. + const int tensor_arena_size = 60 * 1024; + uint8_t tensor_arena[tensor_arena_size]; + + // Build an interpreter to run the model with + tflite::MicroInterpreter interpreter(model, micro_op_resolver, tensor_arena, + tensor_arena_size, + µ_error_reporter); + + // Allocate memory from the tensor_arena for the model's tensors + interpreter.AllocateTensors(); + + // Obtain a pointer to the model's input tensor + TfLiteTensor *input = interpreter.input(0); + + // Make sure the input has the properties we expect + TF_LITE_MICRO_EXPECT_NE(nullptr, input); + TF_LITE_MICRO_EXPECT_EQ(4, input->dims->size); + // The value of each element gives the length of the corresponding tensor. + TF_LITE_MICRO_EXPECT_EQ(1, input->dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(128, input->dims->data[1]); + TF_LITE_MICRO_EXPECT_EQ(3, input->dims->data[2]); + TF_LITE_MICRO_EXPECT_EQ(1, input->dims->data[3]); + // The input is a 32 bit floating point value + TF_LITE_MICRO_EXPECT_EQ(kTfLiteFloat32, input->type); + + // Provide an input value + const float *ring_features_data = g_ring_micro_f9643d42_nohash_4_data; + TF_LITE_REPORT_ERROR(µ_error_reporter, "%d", input->bytes); + for (size_t i = 0; i < (input->bytes / sizeof(float)); ++i) { + input->data.f[i] = ring_features_data[i]; + } + + // Run the model on this input and check that it succeeds + TfLiteStatus invoke_status = interpreter.Invoke(); + if (invoke_status != kTfLiteOk) { + TF_LITE_REPORT_ERROR(µ_error_reporter, "Invoke failed\n"); + } + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, invoke_status); + + // Obtain a pointer to the output tensor and make sure it has the + // properties we expect. + TfLiteTensor *output = interpreter.output(0); + TF_LITE_MICRO_EXPECT_EQ(2, output->dims->size); + TF_LITE_MICRO_EXPECT_EQ(1, output->dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(4, output->dims->data[1]); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteFloat32, output->type); + + // There are four possible classes in the output, each with a score. + const int kWingIndex = 0; + const int kRingIndex = 1; + const int kSlopeIndex = 2; + const int kNegativeIndex = 3; + + // Make sure that the expected "Ring" score is higher than the other + // classes. + float wing_score = output->data.f[kWingIndex]; + float ring_score = output->data.f[kRingIndex]; + float slope_score = output->data.f[kSlopeIndex]; + float negative_score = output->data.f[kNegativeIndex]; + TF_LITE_MICRO_EXPECT_GT(ring_score, wing_score); + TF_LITE_MICRO_EXPECT_GT(ring_score, slope_score); + TF_LITE_MICRO_EXPECT_GT(ring_score, negative_score); + + // Now test with a different input, from a recording of "Slope". + const float *slope_features_data = g_slope_micro_f2e59fea_nohash_1_data; + for (size_t i = 0; i < (input->bytes / sizeof(float)); ++i) { + input->data.f[i] = slope_features_data[i]; + } + + // Run the model on this "Slope" input. + invoke_status = interpreter.Invoke(); + if (invoke_status != kTfLiteOk) { + TF_LITE_REPORT_ERROR(µ_error_reporter, "Invoke failed\n"); + } + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, invoke_status); + + // Get the output from the model, and make sure it's the expected size and + // type. + output = interpreter.output(0); + TF_LITE_MICRO_EXPECT_EQ(2, output->dims->size); + TF_LITE_MICRO_EXPECT_EQ(1, output->dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(4, output->dims->data[1]); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteFloat32, output->type); + + // Make sure that the expected "Slope" score is higher than the other classes. + wing_score = output->data.f[kWingIndex]; + ring_score = output->data.f[kRingIndex]; + slope_score = output->data.f[kSlopeIndex]; + negative_score = output->data.f[kNegativeIndex]; + TF_LITE_MICRO_EXPECT_GT(slope_score, wing_score); + TF_LITE_MICRO_EXPECT_GT(slope_score, ring_score); + TF_LITE_MICRO_EXPECT_GT(slope_score, negative_score); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/main.cc b/components/tflite/tensorflow/lite/micro/examples/magic_wand/main.cc new file mode 100644 index 00000000..c1d014fd --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/main.cc @@ -0,0 +1,28 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/magic_wand/main_functions.h" + +// This is the default main used on systems that have the standard C entry +// point. Other devices (for example FreeRTOS or ESP32) that have different +// requirements for entry code (like an app_main function) should specialize +// this main.cc file in a target-specific subfolder. +int main(int argc, char *argv[]) +{ + setup(); + while (true) { + loop(); + } +} diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/main_functions.cc b/components/tflite/tensorflow/lite/micro/examples/magic_wand/main_functions.cc new file mode 100644 index 00000000..5c51f804 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/main_functions.cc @@ -0,0 +1,125 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/magic_wand/main_functions.h" + +#include "tensorflow/lite/micro/examples/magic_wand/accelerometer_handler.h" +#include "tensorflow/lite/micro/examples/magic_wand/constants.h" +#include "tensorflow/lite/micro/examples/magic_wand/gesture_predictor.h" +#include "tensorflow/lite/micro/examples/magic_wand/magic_wand_model_data.h" +#include "tensorflow/lite/micro/examples/magic_wand/output_handler.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/micro_interpreter.h" +#include "tensorflow/lite/micro/micro_mutable_op_resolver.h" +#include "tensorflow/lite/micro/system_setup.h" +#include "tensorflow/lite/schema/schema_generated.h" + +// Globals, used for compatibility with Arduino-style sketches. +namespace { +tflite::ErrorReporter *error_reporter = nullptr; +const tflite::Model *model = nullptr; +tflite::MicroInterpreter *interpreter = nullptr; +TfLiteTensor *model_input = nullptr; +int input_length; + +// Create an area of memory to use for input, output, and intermediate arrays. +// The size of this will depend on the model you're using, and may need to be +// determined by experimentation. +constexpr int kTensorArenaSize = 60 * 1024; +uint8_t tensor_arena[kTensorArenaSize]; +} // namespace + +// The name of this function is important for Arduino compatibility. +void setup() +{ + tflite::InitializeTarget(); + + // Set up logging. Google style is to avoid globals or statics because of + // lifetime uncertainty, but since this has a trivial destructor it's okay. + static tflite::MicroErrorReporter micro_error_reporter; // NOLINT + error_reporter = µ_error_reporter; + + // Map the model into a usable data structure. This doesn't involve any + // copying or parsing, it's a very lightweight operation. + model = tflite::GetModel(g_magic_wand_model_data); + if (model->version() != TFLITE_SCHEMA_VERSION) { + TF_LITE_REPORT_ERROR(error_reporter, + "Model provided is schema version %d not equal " + "to supported version %d.", + model->version(), TFLITE_SCHEMA_VERSION); + return; + } + + // Pull in only the operation implementations we need. + // This relies on a complete list of all the ops needed by this graph. + // An easier approach is to just use the AllOpsResolver, but this will + // incur some penalty in code space for op implementations that are not + // needed by this graph. + static tflite::MicroMutableOpResolver<5> micro_op_resolver; // NOLINT + micro_op_resolver.AddConv2D(); + micro_op_resolver.AddDepthwiseConv2D(); + micro_op_resolver.AddFullyConnected(); + micro_op_resolver.AddMaxPool2D(); + micro_op_resolver.AddSoftmax(); + + // Build an interpreter to run the model with. + static tflite::MicroInterpreter static_interpreter( + model, micro_op_resolver, tensor_arena, kTensorArenaSize, error_reporter); + interpreter = &static_interpreter; + + // Allocate memory from the tensor_arena for the model's tensors. + interpreter->AllocateTensors(); + + // Obtain pointer to the model's input tensor. + model_input = interpreter->input(0); + if ((model_input->dims->size != 4) || (model_input->dims->data[0] != 1) || + (model_input->dims->data[1] != 128) || + (model_input->dims->data[2] != kChannelNumber) || + (model_input->type != kTfLiteFloat32)) { + TF_LITE_REPORT_ERROR(error_reporter, + "Bad input tensor parameters in model"); + return; + } + + input_length = model_input->bytes / sizeof(float); + + TfLiteStatus setup_status = SetupAccelerometer(error_reporter); + if (setup_status != kTfLiteOk) { + TF_LITE_REPORT_ERROR(error_reporter, "Set up failed\n"); + } +} + +void loop() +{ + // Attempt to read new data from the accelerometer. + bool got_data = + ReadAccelerometer(error_reporter, model_input->data.f, input_length); + // If there was no new data, wait until next time. + if (!got_data) + return; + + // Run inference, and report any error. + TfLiteStatus invoke_status = interpreter->Invoke(); + if (invoke_status != kTfLiteOk) { + TF_LITE_REPORT_ERROR(error_reporter, "Invoke failed on index: %d\n", + begin_index); + return; + } + // Analyze the results to obtain a prediction + int gesture_index = PredictGesture(interpreter->output(0)->data.f); + + // Produce an output + HandleOutput(error_reporter, gesture_index); +} diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/main_functions.h b/components/tflite/tensorflow/lite/micro/examples/magic_wand/main_functions.h new file mode 100644 index 00000000..976f8a34 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/main_functions.h @@ -0,0 +1,37 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_MAIN_FUNCTIONS_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_MAIN_FUNCTIONS_H_ + +// Expose a C friendly interface for main functions. +#ifdef __cplusplus +extern "C" { +#endif + +// Initializes all data needed for the example. The name is important, and needs +// to be setup() for Arduino compatibility. +void setup(); + +// Runs one iteration of data gathering and inference. This should be called +// repeatedly from the application code. The name needs to be loop() for Arduino +// compatibility. +void loop(); + +#ifdef __cplusplus +} +#endif + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_MAIN_FUNCTIONS_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/output_handler.cc b/components/tflite/tensorflow/lite/micro/examples/magic_wand/output_handler.cc new file mode 100644 index 00000000..6d65c17d --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/output_handler.cc @@ -0,0 +1,39 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/magic_wand/output_handler.h" + +void HandleOutput(tflite::ErrorReporter *error_reporter, int kind) +{ + // light (red: wing, blue: ring, green: slope) + if (kind == 0) { + TF_LITE_REPORT_ERROR( + error_reporter, + "WING:\n\r* * *\n\r * * * " + "*\n\r * * * *\n\r * * * *\n\r * * " + "* *\n\r * *\n\r"); + } else if (kind == 1) { + TF_LITE_REPORT_ERROR( + error_reporter, + "RING:\n\r *\n\r * *\n\r * *\n\r " + " * *\n\r * *\n\r * *\n\r " + " *\n\r"); + } else if (kind == 2) { + TF_LITE_REPORT_ERROR( + error_reporter, + "SLOPE:\n\r *\n\r *\n\r *\n\r *\n\r " + "*\n\r *\n\r *\n\r * * * * * * * *\n\r"); + } +} diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/output_handler.h b/components/tflite/tensorflow/lite/micro/examples/magic_wand/output_handler.h new file mode 100644 index 00000000..a997e110 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/output_handler.h @@ -0,0 +1,24 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_OUTPUT_HANDLER_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_OUTPUT_HANDLER_H_ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" + +void HandleOutput(tflite::ErrorReporter *error_reporter, int kind); + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_OUTPUT_HANDLER_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/output_handler_test.cc b/components/tflite/tensorflow/lite/micro/examples/magic_wand/output_handler_test.cc new file mode 100644 index 00000000..8faeeeff --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/output_handler_test.cc @@ -0,0 +1,31 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/magic_wand/output_handler.h" + +#include "tensorflow/lite/micro/testing/micro_test.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestCallability) +{ + tflite::MicroErrorReporter micro_error_reporter; + HandleOutput(µ_error_reporter, 0); + HandleOutput(µ_error_reporter, 1); + HandleOutput(µ_error_reporter, 2); + HandleOutput(µ_error_reporter, 3); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/ring_micro_features_data.cc b/components/tflite/tensorflow/lite/micro/examples/magic_wand/ring_micro_features_data.cc new file mode 100644 index 00000000..432c0f0c --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/ring_micro_features_data.cc @@ -0,0 +1,406 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/magic_wand/ring_micro_features_data.h" + +const int g_ring_micro_f9643d42_nohash_4_length = 128; +const int g_ring_micro_f9643d42_nohash_4_dim = 3; +// Raw accelerometer data with a sample rate of 25Hz +const float g_ring_micro_f9643d42_nohash_4_data[] = { + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + -665.0, + 228.0, + 827.0, + -680.0, + 339.0, + 716.0, + -680.0, + 564.0, + 812.0, + -679.0, + 552.0, + 818.0, + -665.0, + 528.0, + 751.0, + -658.0, + 432.0, + 618.0, + -655.0, + 445.0, + 592.0, + -667.0, + 484.0, + 556.0, + -684.0, + 590.0, + 510.0, + -674.0, + 672.0, + 475.0, + -660.0, + 786.0, + 390.0, + -562.0, + 1124.0, + 128.0, + -526.0, + 1140.0, + 111.0, + -486.0, + 1044.0, + 33.0, + -416.0, + 652.0, + -134.0, + -390.0, + 534.0, + -143.0, + -365.0, + 381.0, + -117.0, + -314.0, + 60.0, + 94.0, + -322.0, + 7.0, + 190.0, + -338.0, + -95.0, + 342.0, + -360.0, + -106.0, + 842.0, + -351.0, + -41.0, + 965.0, + -352.0, + 12.0, + 960.0, + -366.0, + 42.0, + 1124.0, + -322.0, + 56.0, + 1178.0, + -312.0, + 15.0, + 1338.0, + -254.0, + 10.0, + 1532.0, + -241.0, + 5.0, + 1590.0, + -227.0, + 60.0, + 1565.0, + -204.0, + 282.0, + 1560.0, + -180.0, + 262.0, + 1524.0, + -138.0, + 385.0, + 1522.0, + -84.0, + 596.0, + 1626.0, + -55.0, + 639.0, + 1604.0, + -19.0, + 771.0, + 1511.0, + 16.0, + 932.0, + 1132.0, + 15.0, + 924.0, + 1013.0, + 1.0, + 849.0, + 812.0, + -88.0, + 628.0, + 500.0, + -114.0, + 609.0, + 463.0, + -155.0, + 559.0, + 382.0, + -234.0, + 420.0, + 278.0, + -254.0, + 390.0, + 272.0, + -327.0, + 200.0, + 336.0, + -558.0, + -556.0, + 630.0, + -640.0, + -607.0, + 740.0, + -706.0, + -430.0, + 868.0, + -778.0, + 42.0, + 1042.0, + -763.0, + 84.0, + 973.0, + -735.0, + 185.0, + 931.0, + -682.0, + 252.0, + 766.0, + -673.0, + 230.0, + 757.0, + -671.0, + 218.0, + 757.0, + -656.0, + 222.0, + 714.0, + -659.0, + 238.0, + 746.0, + -640.0, + 276.0, + 731.0, + -634.0, + 214.0, + 754.0, + -637.0, + 207.0, + 735.0, + -637.0, + 194.0, + 742.0, + -634.0, + 248.0, + 716.0, + -631.0, + 265.0, + 697.0, + -628.0, + 252.0, + 797.0, + -592.0, + 204.0, + 816.0, + -618.0, + 218.0, + 812.0, + -633.0, + 231.0, + 828.0, + -640.0, + 222.0, + 736.0, + -634.0, + 221.0, + 787.0, +}; diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/ring_micro_features_data.h b/components/tflite/tensorflow/lite/micro/examples/magic_wand/ring_micro_features_data.h new file mode 100644 index 00000000..11a183c7 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/ring_micro_features_data.h @@ -0,0 +1,23 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_RING_MICRO_FEATURES_DATA_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_RING_MICRO_FEATURES_DATA_H_ + +extern const int g_ring_micro_f9643d42_nohash_4_length; +extern const int g_ring_micro_f9643d42_nohash_4_dim; +extern const float g_ring_micro_f9643d42_nohash_4_data[]; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_RING_MICRO_FEATURES_DATA_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/slope_micro_features_data.cc b/components/tflite/tensorflow/lite/micro/examples/magic_wand/slope_micro_features_data.cc new file mode 100644 index 00000000..0306721b --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/slope_micro_features_data.cc @@ -0,0 +1,406 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/magic_wand/slope_micro_features_data.h" + +const int g_slope_micro_f2e59fea_nohash_1_length = 128; +const int g_slope_micro_f2e59fea_nohash_1_dim = 3; +// Raw accelerometer data with a sample rate of 25Hz +const float g_slope_micro_f2e59fea_nohash_1_data[] = { + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + -766.0, + 132.0, + 709.0, + -751.0, + 249.0, + 659.0, + -714.0, + 314.0, + 630.0, + -709.0, + 244.0, + 623.0, + -707.0, + 230.0, + 659.0, + -704.0, + 202.0, + 748.0, + -714.0, + 219.0, + 728.0, + -722.0, + 239.0, + 710.0, + -744.0, + 116.0, + 612.0, + -753.0, + -49.0, + 570.0, + -748.0, + -279.0, + 527.0, + -668.0, + -664.0, + 592.0, + -601.0, + -635.0, + 609.0, + -509.0, + -559.0, + 606.0, + -286.0, + -162.0, + 536.0, + -255.0, + -144.0, + 495.0, + -209.0, + -85.0, + 495.0, + 6.0, + 416.0, + 698.0, + -33.0, + 304.0, + 1117.0, + -82.0, + 405.0, + 1480.0, + -198.0, + 1008.0, + 1908.0, + -229.0, + 990.0, + 1743.0, + -234.0, + 934.0, + 1453.0, + -126.0, + 838.0, + 896.0, + -78.0, + 792.0, + 911.0, + -27.0, + 741.0, + 918.0, + 114.0, + 734.0, + 960.0, + 135.0, + 613.0, + 959.0, + 152.0, + 426.0, + 1015.0, + 106.0, + -116.0, + 1110.0, + 63.0, + -314.0, + 1129.0, + -12.0, + -486.0, + 1179.0, + -118.0, + -656.0, + 1510.0, + -116.0, + -558.0, + 1553.0, + -126.0, + -361.0, + 1367.0, + -222.0, + -76.0, + 922.0, + -210.0, + -26.0, + 971.0, + -194.0, + 50.0, + 1053.0, + -178.0, + 72.0, + 1082.0, + -169.0, + 100.0, + 1073.0, + -162.0, + 133.0, + 1050.0, + -156.0, + 226.0, + 976.0, + -154.0, + 323.0, + 886.0, + -130.0, + 240.0, + 1154.0, + -116.0, + 124.0, + 916.0, + -132.0, + 124.0, + 937.0, + -153.0, + 115.0, + 981.0, + -184.0, + 94.0, + 962.0, + -177.0, + 85.0, + 1017.0, + -173.0, + 92.0, + 1027.0, + -168.0, + 158.0, + 1110.0, + -181.0, + 101.0, + 1030.0, + -180.0, + 139.0, + 1054.0, + -152.0, + 10.0, + 1044.0, + -169.0, + 74.0, + 1007.0, +}; diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/slope_micro_features_data.h b/components/tflite/tensorflow/lite/micro/examples/magic_wand/slope_micro_features_data.h new file mode 100644 index 00000000..d3df20da --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/slope_micro_features_data.h @@ -0,0 +1,23 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_SLOPE_MICRO_FEATURES_DATA_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_SLOPE_MICRO_FEATURES_DATA_H_ + +extern const int g_slope_micro_f2e59fea_nohash_1_length; +extern const int g_slope_micro_f2e59fea_nohash_1_dim; +extern const float g_slope_micro_f2e59fea_nohash_1_data[]; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MAGIC_WAND_SLOPE_MICRO_FEATURES_DATA_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/README.md b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/README.md new file mode 100644 index 00000000..115fd353 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/README.md @@ -0,0 +1,191 @@ +# Gesture Recognition Magic Wand Training Scripts + +## Introduction + +The scripts in this directory can be used to train a TensorFlow model that +classifies gestures based on accelerometer data. The code uses Python 3.7 and +TensorFlow 2.0. The resulting model is less than 20KB in size. + +The following document contains instructions on using the scripts to train a +model, and capturing your own training data. + +This project was inspired by the [Gesture Recognition Magic Wand](https://github.com/jewang/gesture-demo) +project by Jennifer Wang. + +## Training + +### Dataset + +Three magic gestures were chosen, and data were collected from 7 +different people. Some random long movement sequences were collected and divided +into shorter pieces, which made up "negative" data along with some other +automatically generated random data. + +The dataset can be downloaded from the following URL: + +[download.tensorflow.org/models/tflite/magic_wand/data.tar.gz](http://download.tensorflow.org/models/tflite/magic_wand/data.tar.gz) + +### Training in Colab + +The following [Google Colaboratory](https://colab.research.google.com) +notebook demonstrates how to train the model. It's the easiest way to get +started: + + + + +
+ Run in Google Colab + + View source on GitHub +
+ +If you'd prefer to run the scripts locally, use the following instructions. + +### Running the scripts + +Use the following command to install the required dependencies: + +```shell +pip install -r requirements.txt +``` + +There are two ways to train the model: + +- Random data split, which mixes different people's data together and randomly + splits them into training, validation, and test sets +- Person data split, which splits the data by person + +#### Random data split + +Using a random split results in higher training accuracy than a person split, +but inferior performance on new data. + +```shell +$ python data_prepare.py + +$ python data_split.py + +$ python train.py --model CNN --person false +``` + +#### Person data split + +Using a person data split results in lower training accuracy but better +performance on new data. + +```shell +$ python data_prepare.py + +$ python data_split_person.py + +$ python train.py --model CNN --person true +``` + +#### Model type + +In the `--model` argument, you can provide `CNN` or `LSTM`. The CNN model has a +smaller size and lower latency. + +## Collecting new data + +To obtain new training data using the +[SparkFun Edge development board](https://sparkfun.com/products/15170), you can +modify one of the examples in the [SparkFun Edge BSP](https://github.com/sparkfun/SparkFun_Edge_BSP) +and deploy it using the Ambiq SDK. + +### Install the Ambiq SDK and SparkFun Edge BSP + +Follow SparkFun's +[Using SparkFun Edge Board with Ambiq Apollo3 SDK](https://learn.sparkfun.com/tutorials/using-sparkfun-edge-board-with-ambiq-apollo3-sdk/all) +guide to set up the Ambiq SDK and SparkFun Edge BSP. + +#### Modify the example code + +First, `cd` into +`AmbiqSuite-Rel2.2.0/boards/SparkFun_Edge_BSP/examples/example1_edge_test`. + +##### Modify `src/tf_adc/tf_adc.c` + +Add `true` in line 62 as the second parameter of function +`am_hal_adc_samples_read`. + +##### Modify `src/main.c` + +Add the line below in `int main(void)`, just before the line `while(1)`: + +```cc +am_util_stdio_printf("-,-,-\r\n"); +``` + +Change the following lines in `while(1){...}` + +```cc +am_util_stdio_printf("Acc [mg] %04.2f x, %04.2f y, %04.2f z, Temp [deg C] %04.2f, MIC0 [counts / 2^14] %d\r\n", acceleration_mg[0], acceleration_mg[1], acceleration_mg[2], temperature_degC, (audioSample) ); +``` + +to: + +```cc +am_util_stdio_printf("%04.2f,%04.2f,%04.2f\r\n", acceleration_mg[0], acceleration_mg[1], acceleration_mg[2]); +``` + +#### Flash the binary + +Follow the instructions in +[SparkFun's guide](https://learn.sparkfun.com/tutorials/using-sparkfun-edge-board-with-ambiq-apollo3-sdk/all#example-applications) +to flash the binary to the device. + +#### Collect accelerometer data + +First, in a new terminal window, run the following command to begin logging +output to `output.txt`: + +```shell +$ script output.txt +``` + +Next, in the same window, use `screen` to connect to the device: + +```shell +$ screen ${DEVICENAME} 115200 +``` + +Output information collected from accelerometer sensor will be shown on the +screen and saved in `output.txt`, in the format of "x,y,z" per line. + +Press the `RST` button to start capturing a new gesture, then press Button 14 +when it ends. New data will begin with a line "-,-,-". + +To exit `screen`, hit +Ctrl\\+A+, immediately followed by the +K+ key, +then hit the +Y+ key. Then run + +```shell +$ exit +``` + +to stop logging data. Data will be saved in `output.txt`. For compatibility +with the training scripts, change the file name to include person's name and +the gesture name, in the following format: + +``` +output_{gesture_name}_{person_name}.txt +``` + +#### Edit and run the scripts + +Edit the following files to include your new gesture names (replacing +"wing", "ring", and "slope") + +- `data_load.py` +- `data_prepare.py` +- `data_split.py` + +Edit the following files to include your new person names (replacing "hyw", +"shiyun", "tangsy", "dengyl", "jiangyh", "xunkai", "lsj", "pengxl", "liucx", +and "zhangxy"): + +- `data_prepare.py` +- `data_split_person.py` + +Finally, run the commands described earlier to train a new model. diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_augmentation.py b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_augmentation.py new file mode 100644 index 00000000..8d30fa19 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_augmentation.py @@ -0,0 +1,74 @@ +# Lint as: python3 +# Copyright 2019 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +# pylint: disable=g-bad-import-order + +"""Data augmentation that will be used in data_load.py.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import random + +import numpy as np + + +def time_wrapping(molecule, denominator, data): + """Generate (molecule/denominator)x speed data.""" + tmp_data = [[0 + for i in range(len(data[0]))] + for j in range((int(len(data) / molecule) - 1) * denominator)] + for i in range(int(len(data) / molecule) - 1): + for j in range(len(data[i])): + for k in range(denominator): + tmp_data[denominator * i + + k][j] = (data[molecule * i + k][j] * (denominator - k) + + data[molecule * i + k + 1][j] * k) / denominator + return tmp_data + + +def augment_data(original_data, original_label): + """Perform data augmentation.""" + new_data = [] + new_label = [] + for idx, (data, label) in enumerate(zip(original_data, original_label)): # pylint: disable=unused-variable + # Original data + new_data.append(data) + new_label.append(label) + # Sequence shift + for num in range(5): # pylint: disable=unused-variable + new_data.append((np.array(data, dtype=np.float32) + + (random.random() - 0.5) * 200).tolist()) + new_label.append(label) + # Random noise + tmp_data = [[0 for i in range(len(data[0]))] for j in range(len(data))] + for num in range(5): + for i in range(len(tmp_data)): + for j in range(len(tmp_data[i])): + tmp_data[i][j] = data[i][j] + 5 * random.random() + new_data.append(tmp_data) + new_label.append(label) + # Time warping + fractions = [(3, 2), (5, 3), (2, 3), (3, 4), (9, 5), (6, 5), (4, 5)] + for molecule, denominator in fractions: + new_data.append(time_wrapping(molecule, denominator, data)) + new_label.append(label) + # Movement amplification + for molecule, denominator in fractions: + new_data.append( + (np.array(data, dtype=np.float32) * molecule / denominator).tolist()) + new_label.append(label) + return new_data, new_label diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_augmentation_test.py b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_augmentation_test.py new file mode 100644 index 00000000..76bac658 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_augmentation_test.py @@ -0,0 +1,58 @@ +# Lint as: python3 +# Copyright 2019 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +# pylint: disable=g-bad-import-order + +"""Test for data_augmentation.py.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import unittest + +import numpy as np + +from data_augmentation import augment_data +from data_augmentation import time_wrapping + + +class TestAugmentation(unittest.TestCase): + + def test_time_wrapping(self): + original_data = np.random.rand(10, 3).tolist() + wrapped_data = time_wrapping(4, 5, original_data) + self.assertEqual(len(wrapped_data), int(len(original_data) / 4 - 1) * 5) + self.assertEqual(len(wrapped_data[0]), len(original_data[0])) + + def test_augment_data(self): + original_data = [ + np.random.rand(128, 3).tolist(), + np.random.rand(66, 2).tolist(), + np.random.rand(9, 1).tolist() + ] + original_label = ["data", "augmentation", "test"] + augmented_data, augmented_label = augment_data(original_data, + original_label) + self.assertEqual(25 * len(original_data), len(augmented_data)) + self.assertIsInstance(augmented_data, list) + self.assertEqual(25 * len(original_label), len(augmented_label)) + self.assertIsInstance(augmented_label, list) + for i in range(len(original_label)): + self.assertEqual(augmented_label[25 * i], original_label[i]) + + +if __name__ == "__main__": + unittest.main() diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_load.py b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_load.py new file mode 100644 index 00000000..fc9ba718 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_load.py @@ -0,0 +1,106 @@ +# Lint as: python3 +# Copyright 2019 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +# pylint: disable=g-bad-import-order + +"""Load data from the specified paths and format them for training.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import json + +import numpy as np +import tensorflow as tf + +from data_augmentation import augment_data + +LABEL_NAME = "gesture" +DATA_NAME = "accel_ms2_xyz" + + +class DataLoader(object): + """Loads data and prepares for training.""" + + def __init__(self, train_data_path, valid_data_path, test_data_path, + seq_length): + self.dim = 3 + self.seq_length = seq_length + self.label2id = {"wing": 0, "ring": 1, "slope": 2, "negative": 3} + self.train_data, self.train_label, self.train_len = self.get_data_file( + train_data_path, "train") + self.valid_data, self.valid_label, self.valid_len = self.get_data_file( + valid_data_path, "valid") + self.test_data, self.test_label, self.test_len = self.get_data_file( + test_data_path, "test") + + def get_data_file(self, data_path, data_type): + """Get train, valid and test data from files.""" + data = [] + label = [] + with open(data_path, "r") as f: + lines = f.readlines() + for idx, line in enumerate(lines): # pylint: disable=unused-variable + dic = json.loads(line) + data.append(dic[DATA_NAME]) + label.append(dic[LABEL_NAME]) + if data_type == "train": + data, label = augment_data(data, label) + length = len(label) + print(data_type + "_data_length:" + str(length)) + return data, label, length + + def pad(self, data, seq_length, dim): + """Get neighbour padding.""" + noise_level = 20 + padded_data = [] + # Before- Neighbour padding + tmp_data = (np.random.rand(seq_length, dim) - 0.5) * noise_level + data[0] + tmp_data[(seq_length - + min(len(data), seq_length)):] = data[:min(len(data), seq_length)] + padded_data.append(tmp_data) + # After- Neighbour padding + tmp_data = (np.random.rand(seq_length, dim) - 0.5) * noise_level + data[-1] + tmp_data[:min(len(data), seq_length)] = data[:min(len(data), seq_length)] + padded_data.append(tmp_data) + return padded_data + + def format_support_func(self, padded_num, length, data, label): + """Support function for format.(Helps format train, valid and test.)""" + # Add 2 padding, initialize data and label + length *= padded_num + features = np.zeros((length, self.seq_length, self.dim)) + labels = np.zeros(length) + # Get padding for train, valid and test + for idx, (data, label) in enumerate(zip(data, label)): + padded_data = self.pad(data, self.seq_length, self.dim) + for num in range(padded_num): + features[padded_num * idx + num] = padded_data[num] + labels[padded_num * idx + num] = self.label2id[label] + # Turn into tf.data.Dataset + dataset = tf.data.Dataset.from_tensor_slices( + (features, labels.astype("int32"))) + return length, dataset + + def format(self): + """Format data(including padding, etc.) and get the dataset for the model.""" + padded_num = 2 + self.train_len, self.train_data = self.format_support_func( + padded_num, self.train_len, self.train_data, self.train_label) + self.valid_len, self.valid_data = self.format_support_func( + padded_num, self.valid_len, self.valid_data, self.valid_label) + self.test_len, self.test_data = self.format_support_func( + padded_num, self.test_len, self.test_data, self.test_label) diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_load_test.py b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_load_test.py new file mode 100644 index 00000000..8a4ef45c --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_load_test.py @@ -0,0 +1,95 @@ +# Lint as: python3 +# Copyright 2019 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +# pylint: disable=g-bad-import-order + +"""Test for data_load.py.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import unittest +from data_load import DataLoader + +import tensorflow as tf + + +class TestLoad(unittest.TestCase): + + def setUp(self): # pylint: disable=g-missing-super-call + self.loader = DataLoader( + "./data/train", "./data/valid", "./data/test", seq_length=512) + + def test_get_data(self): + self.assertIsInstance(self.loader.train_data, list) + self.assertIsInstance(self.loader.train_label, list) + self.assertIsInstance(self.loader.valid_data, list) + self.assertIsInstance(self.loader.valid_label, list) + self.assertIsInstance(self.loader.test_data, list) + self.assertIsInstance(self.loader.test_label, list) + self.assertEqual(self.loader.train_len, len(self.loader.train_data)) + self.assertEqual(self.loader.train_len, len(self.loader.train_label)) + self.assertEqual(self.loader.valid_len, len(self.loader.valid_data)) + self.assertEqual(self.loader.valid_len, len(self.loader.valid_label)) + self.assertEqual(self.loader.test_len, len(self.loader.test_data)) + self.assertEqual(self.loader.test_len, len(self.loader.test_label)) + + def test_pad(self): + original_data1 = [[2, 3], [1, 1]] + expected_data1_0 = [[2, 3], [2, 3], [2, 3], [2, 3], [1, 1]] + expected_data1_1 = [[2, 3], [1, 1], [1, 1], [1, 1], [1, 1]] + original_data2 = [[-2, 3], [-77, -681], [5, 6], [9, -7], [22, 3333], + [9, 99], [-100, 0]] + expected_data2 = [[-2, 3], [-77, -681], [5, 6], [9, -7], [22, 3333]] + padding_data1 = self.loader.pad(original_data1, seq_length=5, dim=2) + padding_data2 = self.loader.pad(original_data2, seq_length=5, dim=2) + for i in range(len(padding_data1[0])): + for j in range(len(padding_data1[0].tolist()[0])): + self.assertLess( + abs(padding_data1[0].tolist()[i][j] - expected_data1_0[i][j]), + 10.001) + for i in range(len(padding_data1[1])): + for j in range(len(padding_data1[1].tolist()[0])): + self.assertLess( + abs(padding_data1[1].tolist()[i][j] - expected_data1_1[i][j]), + 10.001) + self.assertEqual(padding_data2[0].tolist(), expected_data2) + self.assertEqual(padding_data2[1].tolist(), expected_data2) + + def test_format(self): + self.loader.format() + expected_train_label = int(self.loader.label2id[self.loader.train_label[0]]) + expected_valid_label = int(self.loader.label2id[self.loader.valid_label[0]]) + expected_test_label = int(self.loader.label2id[self.loader.test_label[0]]) + for feature, label in self.loader.train_data: # pylint: disable=unused-variable + format_train_label = label.numpy() + break + for feature, label in self.loader.valid_data: + format_valid_label = label.numpy() + break + for feature, label in self.loader.test_data: + format_test_label = label.numpy() + break + self.assertEqual(expected_train_label, format_train_label) + self.assertEqual(expected_valid_label, format_valid_label) + self.assertEqual(expected_test_label, format_test_label) + self.assertIsInstance(self.loader.train_data, tf.data.Dataset) + self.assertIsInstance(self.loader.valid_data, tf.data.Dataset) + self.assertIsInstance(self.loader.test_data, tf.data.Dataset) + + +if __name__ == "__main__": + unittest.main() diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_prepare.py b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_prepare.py new file mode 100644 index 00000000..b5f1fcfd --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_prepare.py @@ -0,0 +1,164 @@ +# Lint as: python3 +# coding=utf-8 +# Copyright 2019 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== + +"""Prepare data for further process. + +Read data from "/slope", "/ring", "/wing", "/negative" and save them +in "/data/complete_data" in python dict format. + +It will generate a new file with the following structure: +├── data +│   └── complete_data +""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import csv +import json +import os +import random + +LABEL_NAME = "gesture" +DATA_NAME = "accel_ms2_xyz" +folders = ["wing", "ring", "slope"] +names = [ + "hyw", "shiyun", "tangsy", "dengyl", "zhangxy", "pengxl", "liucx", + "jiangyh", "xunkai" +] + + +def prepare_original_data(folder, name, data, file_to_read): # pylint: disable=redefined-outer-name + """Read collected data from files.""" + if folder != "negative": + with open(file_to_read, "r") as f: + lines = csv.reader(f) + data_new = {} + data_new[LABEL_NAME] = folder + data_new[DATA_NAME] = [] + data_new["name"] = name + for idx, line in enumerate(lines): # pylint: disable=unused-variable,redefined-outer-name + if len(line) == 3: + if line[2] == "-" and data_new[DATA_NAME]: + data.append(data_new) + data_new = {} + data_new[LABEL_NAME] = folder + data_new[DATA_NAME] = [] + data_new["name"] = name + elif line[2] != "-": + data_new[DATA_NAME].append([float(i) for i in line[0:3]]) + data.append(data_new) + else: + with open(file_to_read, "r") as f: + lines = csv.reader(f) + data_new = {} + data_new[LABEL_NAME] = folder + data_new[DATA_NAME] = [] + data_new["name"] = name + for idx, line in enumerate(lines): + if len(line) == 3 and line[2] != "-": + if len(data_new[DATA_NAME]) == 120: + data.append(data_new) + data_new = {} + data_new[LABEL_NAME] = folder + data_new[DATA_NAME] = [] + data_new["name"] = name + else: + data_new[DATA_NAME].append([float(i) for i in line[0:3]]) + data.append(data_new) + + +def generate_negative_data(data): # pylint: disable=redefined-outer-name + """Generate negative data labeled as 'negative6~8'.""" + # Big movement -> around straight line + for i in range(100): + if i > 80: + dic = {DATA_NAME: [], LABEL_NAME: "negative", "name": "negative8"} + elif i > 60: + dic = {DATA_NAME: [], LABEL_NAME: "negative", "name": "negative7"} + else: + dic = {DATA_NAME: [], LABEL_NAME: "negative", "name": "negative6"} + start_x = (random.random() - 0.5) * 2000 + start_y = (random.random() - 0.5) * 2000 + start_z = (random.random() - 0.5) * 2000 + x_increase = (random.random() - 0.5) * 10 + y_increase = (random.random() - 0.5) * 10 + z_increase = (random.random() - 0.5) * 10 + for j in range(128): + dic[DATA_NAME].append([ + start_x + j * x_increase + (random.random() - 0.5) * 6, + start_y + j * y_increase + (random.random() - 0.5) * 6, + start_z + j * z_increase + (random.random() - 0.5) * 6 + ]) + data.append(dic) + # Random + for i in range(100): + if i > 80: + dic = {DATA_NAME: [], LABEL_NAME: "negative", "name": "negative8"} + elif i > 60: + dic = {DATA_NAME: [], LABEL_NAME: "negative", "name": "negative7"} + else: + dic = {DATA_NAME: [], LABEL_NAME: "negative", "name": "negative6"} + for j in range(128): + dic[DATA_NAME].append([(random.random() - 0.5) * 1000, + (random.random() - 0.5) * 1000, + (random.random() - 0.5) * 1000]) + data.append(dic) + # Stay still + for i in range(100): + if i > 80: + dic = {DATA_NAME: [], LABEL_NAME: "negative", "name": "negative8"} + elif i > 60: + dic = {DATA_NAME: [], LABEL_NAME: "negative", "name": "negative7"} + else: + dic = {DATA_NAME: [], LABEL_NAME: "negative", "name": "negative6"} + start_x = (random.random() - 0.5) * 2000 + start_y = (random.random() - 0.5) * 2000 + start_z = (random.random() - 0.5) * 2000 + for j in range(128): + dic[DATA_NAME].append([ + start_x + (random.random() - 0.5) * 40, + start_y + (random.random() - 0.5) * 40, + start_z + (random.random() - 0.5) * 40 + ]) + data.append(dic) + + +# Write data to file +def write_data(data_to_write, path): + with open(path, "w") as f: + for idx, item in enumerate(data_to_write): # pylint: disable=unused-variable,redefined-outer-name + dic = json.dumps(item, ensure_ascii=False) + f.write(dic) + f.write("\n") + + +if __name__ == "__main__": + data = [] # pylint: disable=redefined-outer-name + for idx1, folder in enumerate(folders): + for idx2, name in enumerate(names): + prepare_original_data(folder, name, data, + "./%s/output_%s_%s.txt" % (folder, folder, name)) + for idx in range(5): + prepare_original_data("negative", "negative%d" % (idx + 1), data, + "./negative/output_negative_%d.txt" % (idx + 1)) + generate_negative_data(data) + print("data_length: " + str(len(data))) + if not os.path.exists("./data"): + os.makedirs("./data") + write_data(data, "./data/complete_data") diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_prepare_test.py b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_prepare_test.py new file mode 100644 index 00000000..a2af0992 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_prepare_test.py @@ -0,0 +1,75 @@ +# Lint as: python3 +# Copyright 2019 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== + +"""Test for data_prepare.py.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import csv +import json +import os +import unittest +from data_prepare import generate_negative_data +from data_prepare import prepare_original_data +from data_prepare import write_data + + +class TestPrepare(unittest.TestCase): + + def setUp(self): # pylint: disable=g-missing-super-call + self.file = "./%s/output_%s_%s.txt" % (folders[0], folders[0], names[0]) # pylint: disable=undefined-variable + self.data = [] + prepare_original_data(folders[0], names[0], self.data, self.file) # pylint: disable=undefined-variable + + def test_prepare_data(self): + num = 0 + with open(self.file, "r") as f: + lines = csv.reader(f) + for idx, line in enumerate(lines): # pylint: disable=unused-variable + if len(line) == 3 and line[2] == "-": + num += 1 + self.assertEqual(len(self.data), num) + self.assertIsInstance(self.data, list) + self.assertIsInstance(self.data[0], dict) + self.assertEqual(list(self.data[-1]), ["gesture", "accel_ms2_xyz", "name"]) + self.assertEqual(self.data[0]["name"], names[0]) # pylint: disable=undefined-variable + + def test_generate_negative(self): + original_len = len(self.data) + generate_negative_data(self.data) + self.assertEqual(original_len + 300, len(self.data)) + generated_num = 0 + for idx, data in enumerate(self.data): # pylint: disable=undefined-variable, unused-variable + if data["name"] == "negative6" or data["name"] == "negative7" or data[ + "name"] == "negative8": + generated_num += 1 + self.assertEqual(generated_num, 300) + + def test_write_data(self): + data_path_test = "./data/data0" + write_data(self.data, data_path_test) + with open(data_path_test, "r") as f: + lines = f.readlines() + self.assertEqual(len(lines), len(self.data)) + self.assertEqual(json.loads(lines[0]), self.data[0]) + self.assertEqual(json.loads(lines[-1]), self.data[-1]) + os.remove(data_path_test) + + +if __name__ == "__main__": + unittest.main() diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_split.py b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_split.py new file mode 100644 index 00000000..3bf47472 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_split.py @@ -0,0 +1,90 @@ +# Lint as: python3 +# coding=utf-8 +# Copyright 2019 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +"""Mix and split data. + +Mix different people's data together and randomly split them into train, +validation and test. These data would be saved separately under "/data". +It will generate new files with the following structure: + +├── data +│   ├── complete_data +│   ├── test +│   ├── train +│   └── valid +""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import json +import random +from data_prepare import write_data + + +# Read data +def read_data(path): + data = [] # pylint: disable=redefined-outer-name + with open(path, "r") as f: + lines = f.readlines() + for idx, line in enumerate(lines): # pylint: disable=unused-variable + dic = json.loads(line) + data.append(dic) + print("data_length:" + str(len(data))) + return data + + +def split_data(data, train_ratio, valid_ratio): # pylint: disable=redefined-outer-name + """Splits data into train, validation and test according to ratio.""" + train_data = [] # pylint: disable=redefined-outer-name + valid_data = [] # pylint: disable=redefined-outer-name + test_data = [] # pylint: disable=redefined-outer-name + num_dic = {"wing": 0, "ring": 0, "slope": 0, "negative": 0} + for idx, item in enumerate(data): # pylint: disable=unused-variable + for i in num_dic: + if item["gesture"] == i: + num_dic[i] += 1 + print(num_dic) + train_num_dic = {} + valid_num_dic = {} + for i in num_dic: + train_num_dic[i] = int(train_ratio * num_dic[i]) + valid_num_dic[i] = int(valid_ratio * num_dic[i]) + random.seed(30) + random.shuffle(data) + for idx, item in enumerate(data): + for i in num_dic: + if item["gesture"] == i: + if train_num_dic[i] > 0: + train_data.append(item) + train_num_dic[i] -= 1 + elif valid_num_dic[i] > 0: + valid_data.append(item) + valid_num_dic[i] -= 1 + else: + test_data.append(item) + print("train_length:" + str(len(train_data))) + print("test_length:" + str(len(test_data))) + return train_data, valid_data, test_data + + +if __name__ == "__main__": + data = read_data("./data/complete_data") + train_data, valid_data, test_data = split_data(data, 0.6, 0.2) + write_data(train_data, "./data/train") + write_data(valid_data, "./data/valid") + write_data(test_data, "./data/test") diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_split_person.py b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_split_person.py new file mode 100644 index 00000000..be052134 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_split_person.py @@ -0,0 +1,75 @@ +# Lint as: python3 +# coding=utf-8 +# Copyright 2019 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== + +"""Split data into train, validation and test dataset according to person. + +That is, use some people's data as train, some other people's data as +validation, and the rest ones' data as test. These data would be saved +separately under "/person_split". + +It will generate new files with the following structure: +├──person_split +│   ├── test +│   ├── train +│   └──valid +""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import os +import random +from data_split import read_data +from data_split import write_data + + +def person_split(whole_data, train_names, valid_names, test_names): # pylint: disable=redefined-outer-name + """Split data by person.""" + random.seed(30) + random.shuffle(whole_data) + train_data = [] # pylint: disable=redefined-outer-name + valid_data = [] # pylint: disable=redefined-outer-name + test_data = [] # pylint: disable=redefined-outer-name + for idx, data in enumerate(whole_data): # pylint: disable=redefined-outer-name,unused-variable + if data["name"] in train_names: + train_data.append(data) + elif data["name"] in valid_names: + valid_data.append(data) + elif data["name"] in test_names: + test_data.append(data) + print("train_length:" + str(len(train_data))) + print("valid_length:" + str(len(valid_data))) + print("test_length:" + str(len(test_data))) + return train_data, valid_data, test_data + + +if __name__ == "__main__": + data = read_data("./data/complete_data") + train_names = [ + "hyw", "shiyun", "tangsy", "dengyl", "jiangyh", "xunkai", "negative3", + "negative4", "negative5", "negative6" + ] + valid_names = ["lsj", "pengxl", "negative2", "negative7"] + test_names = ["liucx", "zhangxy", "negative1", "negative8"] + train_data, valid_data, test_data = person_split(data, train_names, + valid_names, test_names) + if not os.path.exists("./person_split"): + os.makedirs("./person_split") + write_data(train_data, "./person_split/train") + write_data(valid_data, "./person_split/valid") + write_data(test_data, "./person_split/test") diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_split_person_test.py b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_split_person_test.py new file mode 100644 index 00000000..3a91ce42 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_split_person_test.py @@ -0,0 +1,54 @@ +# Lint as: python3 +# Copyright 2019 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== + +"""Test for data_split_person.py.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import unittest +from data_split_person import person_split +from data_split_person import read_data + + +class TestSplitPerson(unittest.TestCase): + + def setUp(self): # pylint: disable=g-missing-super-call + self.data = read_data("./data/complete_data") + + def test_person_split(self): + train_names = ["dengyl"] + valid_names = ["liucx"] + test_names = ["tangsy"] + dengyl_num = 63 + liucx_num = 63 + tangsy_num = 30 + train_data, valid_data, test_data = person_split(self.data, train_names, + valid_names, test_names) + self.assertEqual(len(train_data), dengyl_num) + self.assertEqual(len(valid_data), liucx_num) + self.assertEqual(len(test_data), tangsy_num) + self.assertIsInstance(train_data, list) + self.assertIsInstance(valid_data, list) + self.assertIsInstance(test_data, list) + self.assertIsInstance(train_data[0], dict) + self.assertIsInstance(valid_data[0], dict) + self.assertIsInstance(test_data[0], dict) + + +if __name__ == "__main__": + unittest.main() diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_split_test.py b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_split_test.py new file mode 100644 index 00000000..9a8f1519 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/data_split_test.py @@ -0,0 +1,77 @@ +# Lint as: python3 +# Copyright 2019 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== + +"""Test for data_split.py.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import json +import unittest +from data_split import read_data +from data_split import split_data + + +class TestSplit(unittest.TestCase): + + def setUp(self): # pylint: disable=g-missing-super-call + self.data = read_data("./data/complete_data") + self.num_dic = {"wing": 0, "ring": 0, "slope": 0, "negative": 0} + with open("./data/complete_data", "r") as f: + lines = f.readlines() + self.num = len(lines) + + def test_read_data(self): + self.assertEqual(len(self.data), self.num) + self.assertIsInstance(self.data, list) + self.assertIsInstance(self.data[0], dict) + self.assertEqual( + set(list(self.data[-1])), set(["gesture", "accel_ms2_xyz", "name"])) + + def test_split_data(self): + with open("./data/complete_data", "r") as f: + lines = f.readlines() + for idx, line in enumerate(lines): # pylint: disable=unused-variable + dic = json.loads(line) + for ges in self.num_dic: + if dic["gesture"] == ges: + self.num_dic[ges] += 1 + train_data_0, valid_data_0, test_data_100 = split_data(self.data, 0, 0) + train_data_50, valid_data_50, test_data_0 = split_data(self.data, 0.5, 0.5) + train_data_60, valid_data_20, test_data_20 = split_data(self.data, 0.6, 0.2) + len_60 = int(self.num_dic["wing"] * 0.6) + int( + self.num_dic["ring"] * 0.6) + int(self.num_dic["slope"] * 0.6) + int( + self.num_dic["negative"] * 0.6) + len_50 = int(self.num_dic["wing"] * 0.5) + int( + self.num_dic["ring"] * 0.5) + int(self.num_dic["slope"] * 0.5) + int( + self.num_dic["negative"] * 0.5) + len_20 = int(self.num_dic["wing"] * 0.2) + int( + self.num_dic["ring"] * 0.2) + int(self.num_dic["slope"] * 0.2) + int( + self.num_dic["negative"] * 0.2) + self.assertEqual(len(train_data_0), 0) + self.assertEqual(len(train_data_50), len_50) + self.assertEqual(len(train_data_60), len_60) + self.assertEqual(len(valid_data_0), 0) + self.assertEqual(len(valid_data_50), len_50) + self.assertEqual(len(valid_data_20), len_20) + self.assertEqual(len(test_data_100), self.num) + self.assertEqual(len(test_data_0), (self.num - 2 * len_50)) + self.assertEqual(len(test_data_20), (self.num - len_60 - len_20)) + + +if __name__ == "__main__": + unittest.main() diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/netmodels/CNN/weights.h5 b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/netmodels/CNN/weights.h5 new file mode 100644 index 00000000..1d825b3a Binary files /dev/null and b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/netmodels/CNN/weights.h5 differ diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/requirements.txt b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/requirements.txt new file mode 100644 index 00000000..cdced91c --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/requirements.txt @@ -0,0 +1,2 @@ +numpy==1.16.2 +tensorflow==2.5.0 diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/train.py b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/train.py new file mode 100644 index 00000000..bca441f4 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/train.py @@ -0,0 +1,203 @@ +# Lint as: python3 +# Copyright 2019 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +# pylint: disable=redefined-outer-name +# pylint: disable=g-bad-import-order + +"""Build and train neural networks.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import argparse +import datetime +import os +from data_load import DataLoader + +import numpy as np +import tensorflow as tf + +logdir = "logs/scalars/" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S") +tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=logdir) + + +def reshape_function(data, label): + reshaped_data = tf.reshape(data, [-1, 3, 1]) + return reshaped_data, label + + +def calculate_model_size(model): + print(model.summary()) + var_sizes = [ + np.product(list(map(int, v.shape))) * v.dtype.size + for v in model.trainable_variables + ] + print("Model size:", sum(var_sizes) / 1024, "KB") + + +def build_cnn(seq_length): + """Builds a convolutional neural network in Keras.""" + model = tf.keras.Sequential([ + tf.keras.layers.Conv2D( + 8, (4, 3), + padding="same", + activation="relu", + input_shape=(seq_length, 3, 1)), # output_shape=(batch, 128, 3, 8) + tf.keras.layers.MaxPool2D((3, 3)), # (batch, 42, 1, 8) + tf.keras.layers.Dropout(0.1), # (batch, 42, 1, 8) + tf.keras.layers.Conv2D(16, (4, 1), padding="same", + activation="relu"), # (batch, 42, 1, 16) + tf.keras.layers.MaxPool2D((3, 1), padding="same"), # (batch, 14, 1, 16) + tf.keras.layers.Dropout(0.1), # (batch, 14, 1, 16) + tf.keras.layers.Flatten(), # (batch, 224) + tf.keras.layers.Dense(16, activation="relu"), # (batch, 16) + tf.keras.layers.Dropout(0.1), # (batch, 16) + tf.keras.layers.Dense(4, activation="softmax") # (batch, 4) + ]) + model_path = os.path.join("./netmodels", "CNN") + print("Built CNN.") + if not os.path.exists(model_path): + os.makedirs(model_path) + model.load_weights("./netmodels/CNN/weights.h5") + return model, model_path + + +def build_lstm(seq_length): + """Builds an LSTM in Keras.""" + model = tf.keras.Sequential([ + tf.keras.layers.Bidirectional( + tf.keras.layers.LSTM(22), + input_shape=(seq_length, 3)), # output_shape=(batch, 44) + tf.keras.layers.Dense(4, activation="sigmoid") # (batch, 4) + ]) + model_path = os.path.join("./netmodels", "LSTM") + print("Built LSTM.") + if not os.path.exists(model_path): + os.makedirs(model_path) + return model, model_path + + +def load_data(train_data_path, valid_data_path, test_data_path, seq_length): + data_loader = DataLoader( + train_data_path, valid_data_path, test_data_path, seq_length=seq_length) + data_loader.format() + return data_loader.train_len, data_loader.train_data, data_loader.valid_len, \ + data_loader.valid_data, data_loader.test_len, data_loader.test_data + + +def build_net(args, seq_length): + if args.model == "CNN": + model, model_path = build_cnn(seq_length) + elif args.model == "LSTM": + model, model_path = build_lstm(seq_length) + else: + print("Please input correct model name.(CNN LSTM)") + return model, model_path + + +def train_net( + model, + model_path, # pylint: disable=unused-argument + train_len, # pylint: disable=unused-argument + train_data, + valid_len, + valid_data, # pylint: disable=unused-argument + test_len, + test_data, + kind): + """Trains the model.""" + calculate_model_size(model) + epochs = 50 + batch_size = 64 + model.compile( + optimizer="adam", + loss="sparse_categorical_crossentropy", + metrics=["accuracy"]) + if kind == "CNN": + train_data = train_data.map(reshape_function) + test_data = test_data.map(reshape_function) + valid_data = valid_data.map(reshape_function) + test_labels = np.zeros(test_len) + idx = 0 + for data, label in test_data: # pylint: disable=unused-variable + test_labels[idx] = label.numpy() + idx += 1 + train_data = train_data.batch(batch_size).repeat() + valid_data = valid_data.batch(batch_size) + test_data = test_data.batch(batch_size) + model.fit( + train_data, + epochs=epochs, + validation_data=valid_data, + steps_per_epoch=1000, + validation_steps=int((valid_len - 1) / batch_size + 1), + callbacks=[tensorboard_callback]) + loss, acc = model.evaluate(test_data) + pred = np.argmax(model.predict(test_data), axis=1) + confusion = tf.math.confusion_matrix( + labels=tf.constant(test_labels), + predictions=tf.constant(pred), + num_classes=4) + print(confusion) + print("Loss {}, Accuracy {}".format(loss, acc)) + # Convert the model to the TensorFlow Lite format without quantization + converter = tf.lite.TFLiteConverter.from_keras_model(model) + tflite_model = converter.convert() + + # Save the model to disk + open("model.tflite", "wb").write(tflite_model) + + # Convert the model to the TensorFlow Lite format with quantization + converter = tf.lite.TFLiteConverter.from_keras_model(model) + converter.optimizations = [tf.lite.Optimize.DEFAULT] + tflite_model = converter.convert() + + # Save the model to disk + open("model_quantized.tflite", "wb").write(tflite_model) + + basic_model_size = os.path.getsize("model.tflite") + print("Basic model is %d bytes" % basic_model_size) + quantized_model_size = os.path.getsize("model_quantized.tflite") + print("Quantized model is %d bytes" % quantized_model_size) + difference = basic_model_size - quantized_model_size + print("Difference is %d bytes" % difference) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--model", "-m") + parser.add_argument("--person", "-p") + args = parser.parse_args() + + seq_length = 128 + + print("Start to load data...") + if args.person == "true": + train_len, train_data, valid_len, valid_data, test_len, test_data = \ + load_data("./person_split/train", "./person_split/valid", + "./person_split/test", seq_length) + else: + train_len, train_data, valid_len, valid_data, test_len, test_data = \ + load_data("./data/train", "./data/valid", "./data/test", seq_length) + + print("Start to build net...") + model, model_path = build_net(args, seq_length) + + print("Start training...") + train_net(model, model_path, train_len, train_data, valid_len, valid_data, + test_len, test_data, args.model) + + print("Training finished!") diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/train_magic_wand_model.ipynb b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/train_magic_wand_model.ipynb new file mode 100644 index 00000000..0f33efb6 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/train_magic_wand_model.ipynb @@ -0,0 +1,238 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "1BtkMGSYQOTQ" + }, + "source": [ + "# Train a gesture recognition model for microcontroller use" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "BaFfr7DHRmGF" + }, + "source": [ + "This notebook demonstrates how to train a 20kb gesture recognition model for [TensorFlow Lite for Microcontrollers](https://tensorflow.org/lite/microcontrollers/overview). It will produce the same model used in the [magic_wand](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/micro/examples/magic_wand) example application.\n", + "\n", + "The model is designed to be used with [Google Colaboratory](https://colab.research.google.com).\n", + "\n", + "\u003ctable class=\"tfo-notebook-buttons\" align=\"left\"\u003e\n", + " \u003ctd\u003e\n", + " \u003ca target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/tensorflow/blob/master/tensorflow/lite/micro/examples/magic_wand/train/train_magic_wand_model.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /\u003eRun in Google Colab\u003c/a\u003e\n", + " \u003c/td\u003e\n", + " \u003ctd\u003e\n", + " \u003ca target=\"_blank\" href=\"https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/micro/examples/magic_wand/train/train_magic_wand_model.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /\u003eView source on GitHub\u003c/a\u003e\n", + " \u003c/td\u003e\n", + "\u003c/table\u003e\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "xXgS6rxyT7Qk" + }, + "source": [ + "Training is much faster using GPU acceleration. Before you proceed, ensure you are using a GPU runtime by going to **Runtime -\u003e Change runtime type** and selecting **GPU**. Training will take around 5 minutes on a GPU runtime." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "LG6ErX5FRIaV" + }, + "source": [ + "## Configure dependencies\n", + "\n", + "Run the following cell to ensure the correct version of TensorFlow is used." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "STNft9TrfoVh" + }, + "source": [ + "We'll also clone the TensorFlow repository, which contains the training scripts, and copy them into our workspace." + ] + }, + { + "cell_type": "code", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "ygkWw73dRNda" + }, + "outputs": [], + "source": [ + "# Clone the repository from GitHub\n", + "!git clone --depth 1 -q https://github.com/tensorflow/tensorflow\n", + "# Copy the training scripts into our workspace\n", + "!cp -r tensorflow/tensorflow/lite/micro/examples/magic_wand/train train" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "pXI7R4RehFdU" + }, + "source": [ + "## Prepare the data\n", + "\n", + "Next, we'll download the data and extract it into the expected location within the training scripts' directory." + ] + }, + { + "cell_type": "code", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "W2Sg2AKzVr2L" + }, + "outputs": [], + "source": [ + "# Download the data we will use to train the model\n", + "!wget http://download.tensorflow.org/models/tflite/magic_wand/data.tar.gz\n", + "# Extract the data into the train directory\n", + "!tar xvzf data.tar.gz -C train 1\u003e/dev/null" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "DNjukI1Sgl2C" + }, + "source": [ + "We'll then run the scripts that split the data into training, validation, and test sets." + ] + }, + { + "cell_type": "code", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "XBqSVpi6Vxss" + }, + "outputs": [], + "source": [ + "# The scripts must be run from within the train directory\n", + "%cd train\n", + "# Prepare the data\n", + "!python data_prepare.py\n", + "# Split the data by person\n", + "!python data_split_person.py" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "5-cmVbFvhTvy" + }, + "source": [ + "## Load TensorBoard\n", + "\n", + "Now, we set up TensorBoard so that we can graph our accuracy and loss as training proceeds." + ] + }, + { + "cell_type": "code", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "CCx6SN9NWRPw" + }, + "outputs": [], + "source": [ + "# Load TensorBoard\n", + "%load_ext tensorboard\n", + "%tensorboard --logdir logs/scalars" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "ERC2Cr4PhaOl" + }, + "source": [ + "## Begin training\n", + "\n", + "The following cell will begin the training process. Training will take around 5 minutes on a GPU runtime. You'll see the metrics in TensorBoard after a few epochs." + ] + }, + { + "cell_type": "code", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "DXmQZgbuWQFO" + }, + "outputs": [], + "source": [ + "!python train.py --model CNN --person true" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "4gXbVzcXhvGD" + }, + "source": [ + "## Create a C source file\n", + "\n", + "The `train.py` script writes a model, `model.tflite`, to the training scripts' directory.\n", + "\n", + "In the following cell, we convert this model into a C++ source file we can use with TensorFlow Lite for Microcontrollers." + ] + }, + { + "cell_type": "code", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "8wgei4OGe3Nz" + }, + "outputs": [], + "source": [ + "# Install xxd if it is not available\n", + "!apt-get -qq install xxd\n", + "# Save the file as a C source file\n", + "!xxd -i model.tflite \u003e /content/model.cc\n", + "# Print the source file\n", + "!cat /content/model.cc" + ] + } + ], + "metadata": { + "accelerator": "GPU", + "colab": { + "collapsed_sections": [], + "name": "Train a gesture recognition model for microcontroller use", + "provenance": [], + "toc_visible": true + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/train_test.py b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/train_test.py new file mode 100644 index 00000000..4790eb28 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/magic_wand/train/train_test.py @@ -0,0 +1,78 @@ +# Lint as: python3 +# Copyright 2019 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== + +"""Test for train.py.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import unittest + +import numpy as np +import tensorflow as tf +from train import build_cnn +from train import build_lstm +from train import load_data +from train import reshape_function + + +class TestTrain(unittest.TestCase): + + def setUp(self): # pylint: disable=g-missing-super-call + self.seq_length = 128 + self.train_len, self.train_data, self.valid_len, self.valid_data, \ + self.test_len, self.test_data = \ + load_data("./data/train", "./data/valid", "./data/test", + self.seq_length) + + def test_load_data(self): + self.assertIsInstance(self.train_data, tf.data.Dataset) + self.assertIsInstance(self.valid_data, tf.data.Dataset) + self.assertIsInstance(self.test_data, tf.data.Dataset) + + def test_build_net(self): + cnn, cnn_path = build_cnn(self.seq_length) + lstm, lstm_path = build_lstm(self.seq_length) + cnn_data = np.random.rand(60, 128, 3, 1) + lstm_data = np.random.rand(60, 128, 3) + cnn_prob = cnn(tf.constant(cnn_data, dtype="float32")).numpy() + lstm_prob = lstm(tf.constant(lstm_data, dtype="float32")).numpy() + self.assertIsInstance(cnn, tf.keras.Sequential) + self.assertIsInstance(lstm, tf.keras.Sequential) + self.assertEqual(cnn_path, "./netmodels/CNN") + self.assertEqual(lstm_path, "./netmodels/LSTM") + self.assertEqual(cnn_prob.shape, (60, 4)) + self.assertEqual(lstm_prob.shape, (60, 4)) + + def test_reshape_function(self): + for data, label in self.train_data: + original_data_shape = data.numpy().shape + original_label_shape = label.numpy().shape + break + self.train_data = self.train_data.map(reshape_function) + for data, label in self.train_data: + reshaped_data_shape = data.numpy().shape + reshaped_label_shape = label.numpy().shape + break + self.assertEqual( + reshaped_data_shape, + (int(original_data_shape[0] * original_data_shape[1] / 3), 3, 1)) + self.assertEqual(reshaped_label_shape, original_label_shape) + + +if __name__ == "__main__": + unittest.main() diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/.gitignore b/components/tflite/tensorflow/lite/micro/examples/micro_speech/.gitignore new file mode 100644 index 00000000..d8dd7532 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/.gitignore @@ -0,0 +1 @@ +*.wav diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/Makefile.inc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/Makefile.inc new file mode 100644 index 00000000..a4ec24f4 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/Makefile.inc @@ -0,0 +1,286 @@ + +INCLUDES += \ + -I$(MAKEFILE_DIR)/downloads/kissfft + +GENERATED_PROJECT_INCLUDES += \ +-I./third_party/kissfft + +PROJECT_INCLUDES += \ +third_party/kissfft + +KISSFFT_LIB_SRCS := \ +$(MAKEFILE_DIR)/downloads/kissfft/kiss_fft.c \ +$(MAKEFILE_DIR)/downloads/kissfft/tools/kiss_fftr.c + +KISSFFT_LIB_HDRS := \ +$(MAKEFILE_DIR)/downloads/kissfft/COPYING \ +$(MAKEFILE_DIR)/downloads/kissfft/kiss_fft.h \ +$(MAKEFILE_DIR)/downloads/kissfft/_kiss_fft_guts.h \ +$(MAKEFILE_DIR)/downloads/kissfft/tools/kiss_fftr.h + +$(eval $(call add_third_party_download,$(KISSFFT_URL),$(KISSFFT_MD5),kissfft,patch_kissfft)) + +THIRD_PARTY_CC_HDRS += \ +third_party/kissfft/COPYING \ +third_party/kissfft/kiss_fft.h \ +third_party/kissfft/_kiss_fft_guts.h \ +third_party/kissfft/tools/kiss_fftr.h + +MICRO_SPEECH_TEST_SRCS := \ +tensorflow/lite/micro/examples/micro_speech/micro_speech_test.cc \ +tensorflow/lite/micro/examples/micro_speech/micro_features/model.cc \ +tensorflow/lite/micro/examples/micro_speech/micro_features/no_micro_features_data.cc \ +tensorflow/lite/micro/examples/micro_speech/micro_features/yes_micro_features_data.cc + +MICRO_SPEECH_TEST_HDRS := \ +tensorflow/lite/micro/examples/micro_speech/micro_features/model.h \ +tensorflow/lite/micro/examples/micro_speech/micro_features/no_micro_features_data.h \ +tensorflow/lite/micro/examples/micro_speech/micro_features/yes_micro_features_data.h \ + +SIMPLE_FEATURES_GENERATOR_TEST_SRCS := \ +tensorflow/lite/micro/examples/micro_speech/simple_features/simple_features_generator.cc \ +tensorflow/lite/micro/examples/micro_speech/simple_features/simple_features_generator_test.cc \ +tensorflow/lite/micro/examples/micro_speech/no_30ms_sample_data.cc \ +tensorflow/lite/micro/examples/micro_speech/yes_30ms_sample_data.cc \ +tensorflow/lite/micro/examples/micro_speech/simple_features/no_power_spectrum_data.cc \ +tensorflow/lite/micro/examples/micro_speech/simple_features/yes_power_spectrum_data.cc + +SIMPLE_FEATURES_GENERATOR_TEST_HDRS := \ +tensorflow/lite/micro/examples/micro_speech/simple_features/simple_model_settings.h \ +tensorflow/lite/micro/examples/micro_speech/simple_features/simple_features_generator.h \ +tensorflow/lite/micro/examples/micro_speech/no_30ms_sample_data.h \ +tensorflow/lite/micro/examples/micro_speech/yes_30ms_sample_data.h \ +tensorflow/lite/micro/examples/micro_speech/simple_features/no_power_spectrum_data.h \ +tensorflow/lite/micro/examples/micro_speech/simple_features/yes_power_spectrum_data.h + +MICRO_FEATURES_LIB_SRCS := \ +tensorflow/lite/experimental/microfrontend/lib/fft.cc \ +tensorflow/lite/experimental/microfrontend/lib/fft_util.cc \ +tensorflow/lite/experimental/microfrontend/lib/filterbank.c \ +tensorflow/lite/experimental/microfrontend/lib/filterbank_util.c \ +tensorflow/lite/experimental/microfrontend/lib/frontend.c \ +tensorflow/lite/experimental/microfrontend/lib/frontend_util.c \ +tensorflow/lite/experimental/microfrontend/lib/log_lut.c \ +tensorflow/lite/experimental/microfrontend/lib/log_scale.c \ +tensorflow/lite/experimental/microfrontend/lib/log_scale_util.c \ +tensorflow/lite/experimental/microfrontend/lib/noise_reduction.c \ +tensorflow/lite/experimental/microfrontend/lib/noise_reduction_util.c \ +tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.c \ +tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control_util.c \ +tensorflow/lite/experimental/microfrontend/lib/window.c \ +tensorflow/lite/experimental/microfrontend/lib/window_util.c \ +$(KISSFFT_LIB_SRCS) + +MICRO_FEATURES_LIB_HDRS := \ +tensorflow/lite/experimental/microfrontend/lib/bits.h \ +tensorflow/lite/experimental/microfrontend/lib/fft.h \ +tensorflow/lite/experimental/microfrontend/lib/fft_util.h \ +tensorflow/lite/experimental/microfrontend/lib/filterbank.h \ +tensorflow/lite/experimental/microfrontend/lib/filterbank_util.h \ +tensorflow/lite/experimental/microfrontend/lib/frontend.h \ +tensorflow/lite/experimental/microfrontend/lib/frontend_util.h \ +tensorflow/lite/experimental/microfrontend/lib/log_lut.h \ +tensorflow/lite/experimental/microfrontend/lib/log_scale.h \ +tensorflow/lite/experimental/microfrontend/lib/log_scale_util.h \ +tensorflow/lite/experimental/microfrontend/lib/noise_reduction.h \ +tensorflow/lite/experimental/microfrontend/lib/noise_reduction_util.h \ +tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.h \ +tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control_util.h \ +tensorflow/lite/experimental/microfrontend/lib/window.h \ +tensorflow/lite/experimental/microfrontend/lib/window_util.h \ +$(KISSFFT_LIB_HDRS) + +MICRO_FEATURES_GENERATOR_SRCS := \ +tensorflow/lite/micro/examples/micro_speech/micro_features/micro_features_generator.cc \ +tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.cc \ +$(MICRO_FEATURES_LIB_SRCS) + +MICRO_FEATURES_GENERATOR_HDRS := \ +tensorflow/lite/micro/examples/micro_speech/micro_features/micro_features_generator.h \ +tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.h \ +$(MICRO_FEATURES_LIB_HDRS) + +MICRO_FEATURES_GENERATOR_TEST_SRCS := \ +tensorflow/lite/micro/examples/micro_speech/micro_features/micro_features_generator_test.cc \ +tensorflow/lite/micro/examples/micro_speech/micro_features/no_feature_data_slice.cc \ +tensorflow/lite/micro/examples/micro_speech/micro_features/yes_feature_data_slice.cc \ +tensorflow/lite/micro/examples/micro_speech/no_30ms_sample_data.cc \ +tensorflow/lite/micro/examples/micro_speech/yes_30ms_sample_data.cc \ +$(MICRO_FEATURES_GENERATOR_SRCS) + +MICRO_FEATURES_GENERATOR_TEST_HDRS := \ +tensorflow/lite/micro/examples/micro_speech/micro_features/no_feature_data_slice.h \ +tensorflow/lite/micro/examples/micro_speech/micro_features/yes_feature_data_slice.h \ +tensorflow/lite/micro/examples/micro_speech/no_30ms_sample_data.h \ +tensorflow/lite/micro/examples/micro_speech/yes_30ms_sample_data.h \ +$(MICRO_FEATURES_GENERATOR_HDRS) + +AUDIO_PROVIDER_TEST_SRCS := \ +tensorflow/lite/micro/examples/micro_speech/audio_provider_test.cc \ +tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.cc \ +tensorflow/lite/micro/examples/micro_speech/audio_provider.cc + +AUDIO_PROVIDER_TEST_HDRS := \ +tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.h \ +tensorflow/lite/micro/examples/micro_speech/audio_provider.h \ + +AUDIO_PROVIDER_MOCK_TEST_SRCS := \ +tensorflow/lite/micro/examples/micro_speech/audio_provider_mock_test.cc \ +tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.cc \ +tensorflow/lite/micro/examples/micro_speech/no_1000ms_sample_data.cc \ +tensorflow/lite/micro/examples/micro_speech/yes_1000ms_sample_data.cc \ +tensorflow/lite/micro/examples/micro_speech/audio_provider_mock.cc + +AUDIO_PROVIDER_MOCK_TEST_HDRS := \ +tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.h \ +tensorflow/lite/micro/examples/micro_speech/no_1000ms_sample_data.h \ +tensorflow/lite/micro/examples/micro_speech/yes_1000ms_sample_data.h \ +tensorflow/lite/micro/examples/micro_speech/audio_provider.h \ + +FEATURE_PROVIDER_TEST_SRCS := \ +tensorflow/lite/micro/examples/micro_speech/feature_provider_test.cc \ +tensorflow/lite/micro/examples/micro_speech/audio_provider.cc \ +tensorflow/lite/micro/examples/micro_speech/feature_provider.cc \ +$(MICRO_FEATURES_GENERATOR_SRCS) + +FEATURE_PROVIDER_TEST_HDRS := \ +tensorflow/lite/micro/examples/micro_speech/audio_provider.h \ +tensorflow/lite/micro/examples/micro_speech/feature_provider.h \ +$(MICRO_FEATURES_GENERATOR_HDRS) + +FEATURE_PROVIDER_MOCK_TEST_SRCS := \ +tensorflow/lite/micro/examples/micro_speech/feature_provider_test.cc \ +tensorflow/lite/micro/examples/micro_speech/audio_provider_mock.cc \ +tensorflow/lite/micro/examples/micro_speech/no_1000ms_sample_data.cc \ +tensorflow/lite/micro/examples/micro_speech/yes_1000ms_sample_data.cc \ +tensorflow/lite/micro/examples/micro_speech/feature_provider.cc \ +tensorflow/lite/micro/examples/micro_speech/micro_features/no_micro_features_data.cc \ +tensorflow/lite/micro/examples/micro_speech/micro_features/yes_micro_features_data.cc \ +$(MICRO_FEATURES_GENERATOR_SRCS) + +FEATURE_PROVIDER_MOCK_TEST_HDRS := \ +tensorflow/lite/micro/examples/micro_speech/audio_provider.h \ +tensorflow/lite/micro/examples/micro_speech/no_1000ms_sample_data.h \ +tensorflow/lite/micro/examples/micro_speech/yes_1000ms_sample_data.h \ +tensorflow/lite/micro/examples/micro_speech/feature_provider.h \ +tensorflow/lite/micro/examples/micro_speech/micro_features/no_micro_features_data.h \ +tensorflow/lite/micro/examples/micro_speech/micro_features/yes_micro_features_data.h \ +$(MICRO_FEATURES_GENERATOR_HDRS) + +RECOGNIZE_COMMANDS_TEST_SRCS := \ +tensorflow/lite/micro/examples/micro_speech/recognize_commands_test.cc \ +tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.cc \ +tensorflow/lite/micro/examples/micro_speech/recognize_commands.cc + +RECOGNIZE_COMMANDS_TEST_HDRS := \ +tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.h \ +tensorflow/lite/micro/examples/micro_speech/recognize_commands.h + +COMMAND_RESPONDER_TEST_SRCS := \ +tensorflow/lite/micro/examples/micro_speech/command_responder_test.cc \ +tensorflow/lite/micro/examples/micro_speech/command_responder.cc + +COMMAND_RESPONDER_TEST_HDRS := \ +tensorflow/lite/micro/examples/micro_speech/command_responder.h + +MICRO_SPEECH_SRCS := \ +tensorflow/lite/micro/examples/micro_speech/main.cc \ +tensorflow/lite/micro/examples/micro_speech/main_functions.cc \ +tensorflow/lite/micro/examples/micro_speech/audio_provider.cc \ +tensorflow/lite/micro/examples/micro_speech/feature_provider.cc \ +tensorflow/lite/micro/examples/micro_speech/micro_features/no_micro_features_data.cc \ +tensorflow/lite/micro/examples/micro_speech/micro_features/yes_micro_features_data.cc \ +tensorflow/lite/micro/examples/micro_speech/micro_features/model.cc \ +tensorflow/lite/micro/examples/micro_speech/recognize_commands.cc \ +tensorflow/lite/micro/examples/micro_speech/command_responder.cc \ +$(MICRO_FEATURES_GENERATOR_SRCS) + +MICRO_SPEECH_HDRS := \ +tensorflow/lite/micro/examples/micro_speech/audio_provider.h \ +tensorflow/lite/micro/examples/micro_speech/feature_provider.h \ +tensorflow/lite/micro/examples/micro_speech/micro_features/no_micro_features_data.h \ +tensorflow/lite/micro/examples/micro_speech/micro_features/yes_micro_features_data.h \ +tensorflow/lite/micro/examples/micro_speech/micro_features/model.h \ +tensorflow/lite/micro/examples/micro_speech/recognize_commands.h \ +tensorflow/lite/micro/examples/micro_speech/command_responder.h \ +tensorflow/lite/micro/examples/micro_speech/main_functions.h \ +$(MICRO_FEATURES_GENERATOR_HDRS) + +MICRO_SPEECH_MOCK_SRCS := \ +tensorflow/lite/micro/examples/micro_speech/main.cc \ +tensorflow/lite/micro/examples/micro_speech/main_functions.cc \ +tensorflow/lite/micro/examples/micro_speech/audio_provider_mock.cc \ +tensorflow/lite/micro/examples/micro_speech/no_1000ms_sample_data.cc \ +tensorflow/lite/micro/examples/micro_speech/yes_1000ms_sample_data.cc \ +tensorflow/lite/micro/examples/micro_speech/feature_provider.cc \ +tensorflow/lite/micro/examples/micro_speech/micro_features/no_micro_features_data.cc \ +tensorflow/lite/micro/examples/micro_speech/micro_features/yes_micro_features_data.cc \ +tensorflow/lite/micro/examples/micro_speech/micro_features/model.cc \ +tensorflow/lite/micro/examples/micro_speech/recognize_commands.cc \ +tensorflow/lite/micro/examples/micro_speech/command_responder.cc \ +$(MICRO_FEATURES_GENERATOR_SRCS) + +MICRO_SPEECH_MOCK_HDRS := \ +tensorflow/lite/micro/examples/micro_speech/audio_provider.h \ +tensorflow/lite/micro/examples/micro_speech/no_1000ms_sample_data.h \ +tensorflow/lite/micro/examples/micro_speech/yes_1000ms_sample_data.h \ +tensorflow/lite/micro/examples/micro_speech/feature_provider.h \ +tensorflow/lite/micro/examples/micro_speech/micro_features/micro_features_generator.h \ +tensorflow/lite/micro/examples/micro_speech/micro_features/no_micro_features_data.h \ +tensorflow/lite/micro/examples/micro_speech/micro_features/yes_micro_features_data.h \ +tensorflow/lite/micro/examples/micro_speech/micro_features/model.h \ +tensorflow/lite/micro/examples/micro_speech/recognize_commands.h \ +tensorflow/lite/micro/examples/micro_speech/command_responder.h \ +tensorflow/lite/micro/examples/micro_speech/main_functions.h \ +$(MICRO_FEATURES_GENERATOR_HDRS) + +#Find any platform - specific rules for this example. +include $(wildcard tensorflow/lite/micro/examples/micro_speech/*/Makefile.inc) + +# TODO(b/161489252): Disabling warnings for this example until we have a better +# way to build third_party code with a reduced list of CFLAGS. +CCFLAGS := $(filter-out $(CC_WARNINGS),$(CCFLAGS)) + +# Test the code for feature generation. +$(eval $(call microlite_test,micro_features_generator_test,\ +$(MICRO_FEATURES_GENERATOR_TEST_SRCS), $(MICRO_FEATURES_GENERATOR_TEST_HDRS))) + +# Tests loading and running a speech model. +$(eval $(call microlite_test,micro_speech_test,\ +$(MICRO_SPEECH_TEST_SRCS),$(MICRO_SPEECH_TEST_HDRS))) + +# Test the code for feature generation. +$(eval $(call microlite_test,simple_features_generator_test,\ +$(SIMPLE_FEATURES_GENERATOR_TEST_SRCS), $(SIMPLE_FEATURES_GENERATOR_TEST_HDRS))) + +# Tests the audio provider module. +$(eval $(call microlite_test,audio_provider_test,\ +$(AUDIO_PROVIDER_TEST_SRCS),$(AUDIO_PROVIDER_TEST_HDRS))) + +# Tests the audio provider mock module. +$(eval $(call microlite_test,audio_provider_mock_test,\ +$(AUDIO_PROVIDER_MOCK_TEST_SRCS),$(AUDIO_PROVIDER_MOCK_TEST_HDRS))) + +# Tests the feature provider module. +$(eval $(call microlite_test,feature_provider_test,\ +$(FEATURE_PROVIDER_TEST_SRCS),$(FEATURE_PROVIDER_TEST_HDRS))) + +# Tests the feature provider module using the mock audio provider. +$(eval $(call microlite_test,feature_provider_mock_test,\ +$(FEATURE_PROVIDER_MOCK_TEST_SRCS),$(FEATURE_PROVIDER_MOCK_TEST_HDRS))) + +# Tests the command recognizer module. +$(eval $(call microlite_test,recognize_commands_test,\ +$(RECOGNIZE_COMMANDS_TEST_SRCS),$(RECOGNIZE_COMMANDS_TEST_HDRS))) + +# Tests responding to a command. +$(eval $(call microlite_test,command_responder_test,\ +$(COMMAND_RESPONDER_TEST_SRCS),$(COMMAND_RESPONDER_TEST_HDRS))) + +# Builds a standalone speech command recognizer binary. +$(eval $(call microlite_test,micro_speech,\ +$(MICRO_SPEECH_SRCS),$(MICRO_SPEECH_HDRS))) + +# Builds a standalone speech command recognizer binary using fake audio input. +$(eval $(call microlite_test,micro_speech_mock,\ +$(MICRO_SPEECH_MOCK_SRCS),$(MICRO_SPEECH_MOCK_HDRS))) diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/README.md b/components/tflite/tensorflow/lite/micro/examples/micro_speech/README.md new file mode 100644 index 00000000..41a2081b --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/README.md @@ -0,0 +1,802 @@ + + +# Micro Speech Example + +This example shows how to run a 20 kB model that can recognize 2 keywords, +"yes" and "no", from speech data. + +The application listens to its surroundings with a microphone and indicates +when it has detected a word by lighting an LED or displaying data on a +screen, depending on the capabilities of the device. + +![Animation on Arduino](images/animation_on_arduino.gif) + +The code has a small footprint (for example, around 22 kilobytes on a Cortex +M3) and only uses about 10 kilobytes of RAM for working memory, so it's able to +run on systems like an STM32F103 with only 20 kilobytes of total SRAM and 64 +kilobytes of Flash. + +## Table of contents + +- [Deploy to ARC EM SDP](#deploy-to-arc-em-sdp) +- [Deploy to Arduino](#deploy-to-arduino) +- [Deploy to ESP32](#deploy-to-esp32) +- [Deploy to SparkFun Edge](#deploy-to-sparkfun-edge) +- [Deploy to STM32F746](#deploy-to-STM32F746) +- [Deploy to NXP FRDM K66F](#deploy-to-nxp-frdm-k66f) +- [Deploy to HIMAX WE1 EVB](#deploy-to-himax-we1-evb) +- [Deploy to CEVA BX1/SP500](#deploy-to-ceva-bx1) +- [Run on macOS](#run-on-macos) +- [Run the tests on a development machine](#run-the-tests-on-a-development-machine) +- [Train your own model](#train-your-own-model) + +## Deploy to ARC EM SDP + +The following instructions will help you to build and deploy this example to +[ARC EM SDP](https://www.synopsys.com/dw/ipdir.php?ds=arc-em-software-development-platform) +board. General information and instructions on using the board with TensorFlow +Lite Micro can be found in the common +[ARC targets description](/tensorflow/lite/micro/tools/make/targets/arc/README.md). + +This example uses asymmetric int8 quantization and can therefore leverage +optimized int8 kernels from the embARC MLI library + +The ARC EM SDP board contains a rich set of extension interfaces. You can choose +any compatible microphone and modify +[audio_provider.cc](/tensorflow/lite/micro/examples/micro_speech/audio_provider.cc) +file accordingly to use input from your specific microphone. By default, results +of running this example are printed to the console. If you would like to instead +implement some target-specific actions, you need to modify +[command_responder.cc](/tensorflow/lite/micro/examples/micro_speech/command_responder.cc) +accordingly. + +The reference implementations of these files are used by default on the EM SDP. + +### Initial setup + +Follow the instructions on the +[ARC EM SDP Initial Setup](/tensorflow/lite/micro/tools/make/targets/arc/README.md#ARC-EM-Software-Development-Platform-ARC-EM-SDP) +to get and install all required tools for work with ARC EM SDP. + +### Generate Example Project + +As default example doesn’t provide any output without real audio, it is +recommended to get started with example for mock data. The project for ARC EM +SDP platform can be generated with the following command: + +``` +make -f tensorflow/lite/micro/tools/make/Makefile \ +TARGET=arc_emsdp ARC_TAGS=reduce_codesize \ +OPTIMIZED_KERNEL_DIR=arc_mli \ +generate_micro_speech_mock_make_project +``` + +Note that `ARC_TAGS=reduce_codesize` applies example specific changes of code to +reduce total size of application. It can be omitted. + +### Build and Run Example + +For more detailed information on building and running examples see the +appropriate sections of general descriptions of the +[ARC EM SDP usage with TFLM](/tensorflow/lite/micro/tools/make/targets/arc/README.md#ARC-EM-Software-Development-Platform-ARC-EM-SDP). +In the directory with generated project you can also find a +*README_ARC_EMSDP.md* file with instructions and options on building and +running. Here we only briefly mention main steps which are typically enough to +get it started. + +1. You need to + [connect the board](/tensorflow/lite/micro/tools/make/targets/arc/README.md#connect-the-board) + and open an serial connection. + +2. Go to the generated example project director + + ``` + cd tensorflow/lite/micro/tools/make/gen/arc_emsdp_arc/prj/micro_speech_mock/make + ``` + +3. Build the example using + + ``` + make app + ``` + +4. To generate artefacts for self-boot of example from the board use + + ``` + make flash + ``` + +5. To run application from the board using microSD card: + + * Copy the content of the created /bin folder into the root of microSD + card. Note that the card must be formatted as FAT32 with default cluster + size (but less than 32 Kbytes) + * Plug in the microSD card into the J11 connector. + * Push the RST button. If a red LED is lit beside RST button, push the CFG + button. + * Type or copy next commands one-by-another into serial terminal: `setenv + loadaddr 0x10800000 setenv bootfile app.elf setenv bootdelay 1 setenv + bootcmd fatload mmc 0 \$\{loadaddr\} \$\{bootfile\} \&\& bootelf + saveenv` + * Push the RST button. + +6. If you have the MetaWare Debugger installed in your environment: + + * To run application from the console using it type `make run`. + * To stop the execution type `Ctrl+C` in the console several times. + +In both cases (step 5 and 6) you will see the application output in the serial +terminal. + +## Deploy to Arduino + +The following instructions will help you build and deploy this example to +[Arduino](https://www.arduino.cc/) devices. + +The example has been tested with the following devices: + +- [Arduino Nano 33 BLE Sense](https://store.arduino.cc/usa/nano-33-ble-sense-with-headers) + +The Arduino Nano 33 BLE Sense is currently the only Arduino with a built-in +microphone. If you're using a different Arduino board and attaching your own +microphone, you'll need to implement your own +audio_provider.cc+. It also has a +built-in LED, which is used to indicate that a word has been recognized. + +### Install the Arduino_TensorFlowLite library + +This example application is included as part of the official TensorFlow Lite +Arduino library. To install it, open the Arduino library manager in +`Tools -> Manage Libraries...` and search for `Arduino_TensorFlowLite`. + +### Load and run the example + +Once the library has been added, go to `File -> Examples`. You should see an +example near the bottom of the list named `TensorFlowLite:micro_speech`. Select +it and click `micro_speech` to load the example. + +Use the Arduino IDE to build and upload the example. Once it is running, you +should see the built-in LED on your device flashing. Saying the word "yes" will +cause the LED to remain on for 3 seconds. The current model has fairly low +accuracy, so you may have to repeat "yes" a few times. + +The program also outputs inference results to the serial port, which appear as +follows: + +``` +Heard yes (201) @4056ms +Heard no (205) @6448ms +Heard unknown (201) @13696ms +Heard yes (205) @15000ms +``` + +The number after each detected word is its score. By default, the program only +considers matches as valid if their score is over 200, so all of the scores you +see will be at least 200. + +When the program is run, it waits 5 seconds for a USB-serial connection to be +available. If there is no connection available, it will not output data. To see +the serial output in the Arduino desktop IDE, do the following: + +1. Open the Arduino IDE +1. Connect the Arduino board to your computer via USB +1. Press the reset button on the Arduino board +1. Within 5 seconds, go to `Tools -> Serial Monitor` in the Arduino IDE. You may + have to try several times, since the board will take a moment to connect. + +If you don't see any output, repeat the process again. + +## Deploy to ESP32 + +The following instructions will help you build and deploy this example to +[ESP32](https://www.espressif.com/en/products/hardware/esp32/overview) devices +using the [ESP IDF](https://github.com/espressif/esp-idf). + +The example has been tested on ESP-IDF version 4.0 with the following devices: - +[ESP32-DevKitC](http://esp-idf.readthedocs.io/en/latest/get-started/get-started-devkitc.html) - +[ESP-EYE](https://github.com/espressif/esp-who/blob/master/docs/en/get-started/ESP-EYE_Getting_Started_Guide.md) + +ESP-EYE is a board which has a built-in microphone which can be used to run this +example , if you want to use other esp boards you will have to connect +microphone externally and write your own +[audio_provider.cc](esp/audio_provider.cc). +You can also edit the +[command_responder.cc](command_responder.cc) +to define your own actions after detecting command. + +### Install the ESP IDF + +Follow the instructions of the +[ESP-IDF get started guide](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html) +to setup the toolchain and the ESP-IDF itself. + +The next steps assume that the +[IDF environment variables are set](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html#step-4-set-up-the-environment-variables) : + +* The `IDF_PATH` environment variable is set +* `idf.py` and Xtensa-esp32 tools (e.g. `xtensa-esp32-elf-gcc`) are in `$PATH` + +### Generate the examples + +The example project can be generated with the following command: +``` +make -f tensorflow/lite/micro/tools/make/Makefile TARGET=esp generate_micro_speech_esp_project +``` + +### Building the example + +Go to the example project directory +``` +cd tensorflow/lite/micro/tools/make/gen/esp_xtensa-esp32/prj/micro_speech/esp-idf +``` + +Then build with `idf.py` `idf.py build` + +### Load and run the example + +To flash (replace `/dev/ttyUSB0` with the device serial port): +``` +idf.py --port /dev/ttyUSB0 flash +``` + +Monitor the serial output: +```idf.py --port /dev/ttyUSB0 monitor``` + +Use `Ctrl+]` to exit. + +The previous two commands can be combined: +``` +idf.py --port /dev/ttyUSB0 flash monitor +``` + +## Deploy to SparkFun Edge + +The following instructions will help you build and deploy this example on the +[SparkFun Edge development board](https://sparkfun.com/products/15170). + +The program will toggle the blue LED on and off with each inference. It will +switch on the yellow LED when a "yes" is heard, the red LED when a "no" is +heard, and the green LED when an unknown command is heard. + +The [AI on a microcontroller with TensorFlow Lite and SparkFun Edge](https://codelabs.developers.google.com/codelabs/sparkfun-tensorflow) +walks through the deployment process in detail. The steps are also +summarized below. + +### Compile the binary + +The following command will download the required dependencies and then compile a +binary for the SparkFun Edge: + +``` +make -f tensorflow/lite/micro/tools/make/Makefile TARGET=sparkfun_edge OPTIMIZED_KERNEL_DIR=cmsis_nn micro_speech_bin +``` + +The binary will be created in the following location: + +``` +tensorflow/lite/micro/tools/make/gen/sparkfun_edge_cortex-m4/bin/micro_speech.bin +``` + +### Sign the binary + +The binary must be signed with cryptographic keys to be deployed to the device. +We'll now run some commands that will sign our binary so it can be flashed to +the SparkFun Edge. The scripts we are using come from the Ambiq SDK, which is +downloaded when the `Makefile` is run. + +Enter the following command to set up some dummy cryptographic keys we can use +for development: + +``` +cp tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.2.0/tools/apollo3_scripts/keys_info0.py \ +tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.2.0/tools/apollo3_scripts/keys_info.py +``` + +Next, run the following command to create a signed binary: + +``` +python3 tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.2.0/tools/apollo3_scripts/create_cust_image_blob.py \ +--bin tensorflow/lite/micro/tools/make/gen/sparkfun_edge_cortex-m4/bin/micro_speech.bin \ +--load-address 0xC000 \ +--magic-num 0xCB \ +-o main_nonsecure_ota \ +--version 0x0 +``` + +This will create the file `main_nonsecure_ota.bin`. We'll now run another +command to create a final version of the file that can be used to flash our +device with the bootloader script we will use in the next step: + +``` +python3 tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.2.0/tools/apollo3_scripts/create_cust_wireupdate_blob.py \ +--load-address 0x20000 \ +--bin main_nonsecure_ota.bin \ +-i 6 \ +-o main_nonsecure_wire \ +--options 0x1 +``` + +You should now have a file called `main_nonsecure_wire.bin` in the directory +where you ran the commands. This is the file we'll be flashing to the device. + +### Flash the binary + +Next, attach the board to your computer via a USB-to-serial adapter. + +**Note:** If you're using the [SparkFun Serial Basic Breakout](https://www.sparkfun.com/products/15096), +you should [install the latest drivers](https://learn.sparkfun.com/tutorials/sparkfun-serial-basic-ch340c-hookup-guide#drivers-if-you-need-them) +before you continue. + +Once connected, assign the USB device name to an environment variable: + +``` +export DEVICENAME=put your device name here +``` + +Set another variable with the baud rate: + +``` +export BAUD_RATE=921600 +``` + +Now, hold the button marked `14` on the device. While still holding the button, +hit the button marked `RST`. Continue holding the button marked `14` while +running the following command: + +``` +python3 tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.2.0/tools/apollo3_scripts/uart_wired_update.py \ +-b ${BAUD_RATE} ${DEVICENAME} \ +-r 1 \ +-f main_nonsecure_wire.bin \ +-i 6 +``` + +You should see a long stream of output as the binary is flashed to the device. +Once you see the following lines, flashing is complete: + +``` +Sending Reset Command. +Done. +``` + +If you don't see these lines, flashing may have failed. Try running through the +steps in [Flash the binary](#flash-the-binary) again (you can skip over setting +the environment variables). If you continue to run into problems, follow the +[AI on a microcontroller with TensorFlow Lite and SparkFun Edge](https://codelabs.developers.google.com/codelabs/sparkfun-tensorflow) +codelab, which includes more comprehensive instructions for the flashing +process. + +The binary should now be deployed to the device. Hit the button marked `RST` to +reboot the board. + +You should see the device's blue LED flashing. The yellow LED should light when +a "yes" is heard, the red LED when a "no" is heard, and the green LED when an +unknown command is heard. The current model has fairly low accuracy, so you may +have to repeat "yes" a few times. + +Debug information is logged by the board while the program is running. To view +it, establish a serial connection to the board using a baud rate of `115200`. +On OSX and Linux, the following command should work: + +``` +screen ${DEVICENAME} 115200 +``` + +You will see a line output for every word that is detected: + +``` +Heard yes (201) @4056ms +Heard no (205) @6448ms +Heard unknown (201) @13696ms +Heard yes (205) @15000ms +``` + +The number after each detected word is its score. By default, the program only +considers matches as valid if their score is over 200, so all of the scores you +see will be at least 200. + +To stop viewing the debug output with `screen`, hit `Ctrl+A`, immediately +followed by the `K` key, then hit the `Y` key. + +## Deploy to STM32F746 + +The following instructions will help you build and deploy the example to the +[STM32F7 discovery kit](https://os.mbed.com/platforms/ST-Discovery-F746NG/) +using [ARM Mbed](https://github.com/ARMmbed/mbed-cli). + +Before we begin, you'll need the following: + +- STM32F7 discovery kit board +- Mini-USB cable +- ARM Mbed CLI ([installation instructions](https://os.mbed.com/docs/mbed-os/v6.9/quick-start/build-with-mbed-cli.html). Check it out for MacOS Catalina - [mbed-cli is broken on MacOS Catalina #930](https://github.com/ARMmbed/mbed-cli/issues/930#issuecomment-660550734)) +- Python 3 and pip3 + +Since Mbed requires a special folder structure for projects, we'll first run a +command to generate a subfolder containing the required source files in this +structure: + +``` +make -f tensorflow/lite/micro/tools/make/Makefile TARGET=disco_f746ng OPTIMIZED_KERNEL_DIR=cmsis_nn generate_micro_speech_mbed_project +``` + +Running the make command will result in the creation of a new folder: + +``` +tensorflow/lite/micro/tools/make/gen/disco_f746ng_cortex-m4_default/prj/micro_speech/mbed +``` + +This folder contains all of the example's dependencies structured in the correct +way for Mbed to be able to build it. + +Change into the directory and run the following commands. + +First, tell Mbed that the current directory is the root of an Mbed project: + +``` +mbed config root . +``` + +Next, tell Mbed to download the dependencies and prepare to build: + +``` +mbed deploy +``` + +Older versions of Mbed will build the project using C++98. However, TensorFlow Lite +requires C++11. If needed, run the following Python snippet to modify the Mbed +configuration files so that it uses C++11: + +``` +python -c 'import fileinput, glob; +for filename in glob.glob("mbed-os/tools/profiles/*.json"): + for line in fileinput.input(filename, inplace=True): + print(line.replace("\"-std=gnu++98\"","\"-std=c++11\", \"-fpermissive\""))' +``` + +Note: Mbed has a dependency to an old version of arm_math.h and cmsis_gcc.h (adapted from the general [CMSIS-NN MBED example](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/micro/kernels/cmsis_nn#example-2---mbed)). Therefore you need to copy the newer version as follows: +```bash +cp tensorflow/lite/micro/tools/make/downloads/cmsis/CMSIS/DSP/Include/\ +arm_math.h mbed-os/cmsis/TARGET_CORTEX_M/arm_math.h +cp tensorflow/lite/micro/tools/make/downloads/cmsis/CMSIS/Core/Include/\ +cmsis_gcc.h mbed-os/cmsis/TARGET_CORTEX_M/cmsis_gcc.h +``` + +Finally, run the following command to compile: + +``` +mbed compile -m DISCO_F746NG -t GCC_ARM +``` + +This should result in a binary at the following path: + +``` +./BUILD/DISCO_F746NG/GCC_ARM/mbed.bin +``` + +To deploy, plug in your STM board and copy the file to it. On macOS, you can do +this with the following command: + +``` +cp ./BUILD/DISCO_F746NG/GCC_ARM/mbed.bin /Volumes/DIS_F746NG/ +``` + +Copying the file will initiate the flashing process. + +The inference results are logged by the board while the program is running. +To view it, establish a serial connection to the board +using a baud rate of `9600`. On OSX and Linux, the following command should +work, replacing `/dev/tty.devicename` with the name of your device as it appears +in `/dev`: + +``` +screen /dev/tty.devicename 9600 +``` + +You will see a line output for every word that is detected: + +``` +Heard yes (201) @4056ms +Heard no (205) @6448ms +Heard unknown (201) @13696ms +Heard yes (205) @15000ms +``` + +The number after each detected word is its score. By default, the program only +considers matches as valid if their score is over 200, so all of the scores you +see will be at least 200. + +To stop viewing the debug output with `screen`, hit `Ctrl+A`, immediately +followed by the `K` key, then hit the `Y` key. + +## Deploy to NXP FRDM K66F + +The following instructions will help you build and deploy the example to the +[NXP FRDM K66F](https://www.nxp.com/design/development-boards/freedom-development-boards/mcu-boards/freedom-development-platform-for-kinetis-k66-k65-and-k26-mcus:FRDM-K66F) +using [ARM Mbed](https://github.com/ARMmbed/mbed-cli). + +1. Download + [the TensorFlow source code](https://github.com/tensorflow/tensorflow). +2. Follow instructions from + [mbed website](https://os.mbed.com/docs/mbed-os/v5.13/tools/installation-and-setup.html) + to setup and install mbed CLI. +3. Compile TensorFlow with the following command to generate mbed project: + + ``` + make -f tensorflow/lite/micro/tools/make/Makefile TARGET=mbed TAGS="nxp_k66f" generate_micro_speech_mbed_project + ``` + +4. Change into the following directory that has been generated: + `tensorflow/lite/micro/tools/make/gen/mbed_cortex-m4/prj/micro_speech/mbed` + +5. Create an Mbed project using the generated files, run ensuring your + environment is using Python 2.7: `mbed config root .` + +6. Next, tell Mbed to download the dependencies and prepare to build: `mbed + deploy` + +7. Finally, we can run the following command to compile the code: `mbed compile + -m K66F -t GCC_ARM` + +8. For some Mbed compilers (such as GCC), you may get compile error in + mbed_rtc_time.cpp. Go to `mbed-os/platform/mbed_rtc_time.h` and comment line + 32 and line 37: + + ``` + //#if !defined(__GNUC__) || defined(__CC_ARM) || defined(__clang__) + struct timeval { + time_t tv_sec; + int32_t tv_usec; + }; + //#endif + ``` + +9. If your system does not recognize the board with the `mbed detect` command. + Follow the instructions for setting up + [DAPLink](https://armmbed.github.io/DAPLink/?board=FRDM-K66F) for the + [K66F](https://os.mbed.com/platforms/FRDM-K66F/). + +10. Connect the USB cable to the micro USB port. When the Ethernet port is + facing towards you, the micro USB port is left of the Ethernet port. + +11. To compile and flash in a single step, add the `--flash` option: + + ``` + mbed compile -m K66F -t GCC_ARM --flash + ``` + +12. Disconnect USB cable from the device to power down the device and connect + back the power cable to start running the model. + +13. Connect to serial port with baud rate of 9600 and correct serial device to + view the output from the MCU. In linux, you can run the following screen + command if the serial device is `/dev/ttyACM0`: + + ``` + sudo screen /dev/ttyACM0 9600 + ``` + +14. Saying "Yes" will print "Yes" and "No" will print "No" on the serial port. + +15. A loopback path from microphone to headset jack is enabled. Headset jack is + in black color. If there is no output on the serial port, you can connect + headphone to headphone port to check if audio loopback path is working. + +## Deploy to HIMAX WE1 EVB + +The following instructions will help you build and deploy this example to +[HIMAX WE1 EVB](https://github.com/HimaxWiseEyePlus/bsp_tflu/tree/master/HIMAX_WE1_EVB_board_brief) +board. To understand more about using this board, please check +[HIMAX WE1 EVB user guide](https://github.com/HimaxWiseEyePlus/bsp_tflu/tree/master/HIMAX_WE1_EVB_user_guide). + +### Initial Setup + +To use the HIMAX WE1 EVB, please make sure following software are installed: + +#### MetaWare Development Toolkit + +See +[Install the Synopsys DesignWare ARC MetaWare Development Toolkit](/tensorflow/lite/micro/tools/make/targets/arc/README.md#install-the-synopsys-designware-arc-metaware-development-toolkit) +section for instructions on toolchain installation. + +#### Make Tool version + +A `'make'` tool is required for deploying Tensorflow Lite Micro applications on +HIMAX WE1 EVB, See +[Check make tool version](/tensorflow/lite/micro/tools/make/targets/arc/README.md#make-tool) +section for proper environment. + +#### Serial Terminal Emulation Application + +There are 2 main purposes for HIMAX WE1 EVB Debug UART port + +- print application output +- burn application to flash by using xmodem send application binary + +You can use any terminal emulation program (like [PuTTY](https://www.putty.org/) +or [minicom](https://linux.die.net/man/1/minicom)). + +### Generate Example Project + +The example project for HIMAX WE1 EVB platform can be generated with the +following command: + +Download related third party data + +``` +make -f tensorflow/lite/micro/tools/make/Makefile TARGET=himax_we1_evb third_party_downloads +``` + +Generate micro speech project + +``` +make -f tensorflow/lite/micro/tools/make/Makefile generate_micro_speech_make_project TARGET=himax_we1_evb +``` + +### Build and Burn Example + +Following the Steps to run micro speech example at HIMAX WE1 EVB platform. + +1. Go to the generated example project directory. + + ``` + cd tensorflow/lite/micro/tools/make/gen/himax_we1_evb_arc/prj/micro_speech/make + ``` + +2. Build the example using + + ``` + make app + ``` + +3. After example build finish, copy ELF file and map file to image generate + tool directory. \ + image generate tool directory located at + `'tensorflow/lite/micro/tools/make/downloads/himax_we1_sdk/image_gen_linux_v3/'` + + ``` + cp micro_speech.elf himax_we1_evb.map ../../../../../downloads/himax_we1_sdk/image_gen_linux_v3/ + ``` + +4. Go to flash image generate tool directory. + + ``` + cd ../../../../../downloads/himax_we1_sdk/image_gen_linux_v3/ + ``` + + make sure this tool directory is in $PATH. You can permanently set it to + PATH by + + ``` + export PATH=$PATH:$(pwd) + ``` + +5. run image generate tool, generate flash image file. + + * Before running image generate tool, by typing `sudo chmod +x image_gen` + and `sudo chmod +x sign_tool` to make sure it is executable. + + ``` + image_gen -e micro_speech.elf -m himax_we1_evb.map -o out.img + ``` + +6. Download flash image file to HIMAX WE1 EVB by UART: + + * more detail about download image through UART can be found at + [HIMAX WE1 EVB update Flash image](https://github.com/HimaxWiseEyePlus/bsp_tflu/tree/master/HIMAX_WE1_EVB_user_guide#flash-image-update) + +After these steps, press reset button on the HIMAX WE1 EVB, you will see +application output in the serial terminal and lighting LED. + +![Animation on Himax WE1 EVB](https://raw.githubusercontent.com/HimaxWiseEyePlus/bsp_tflu/master/HIMAX_WE1_EVB_user_guide/images/tflm_example_micro_speech_int8_led.gif) + +## Deploy to CEVA-BX1 + +The following instructions will help you build and deploy the sample to the +[CEVA-BX1](https://www.ceva-dsp.com/product/ceva-bx1-sound/) or [CEVA-SP500](https://www.ceva-dsp.com/product/ceva-senspro/) + +1. Contact CEVA at [sales@ceva-dsp.com](mailto:sales@ceva-dsp.com) +2. For BX1: +2.1. Download and install CEVA-BX Toolbox v18.0.2 +2.2. Set the TARGET_TOOLCHAIN_ROOT variable in + /tensorflow/lite/micro/tools/make/templates/ceva_bx1/ceva_app_makefile.tpl + To your installation location. For example: TARGET_TOOLCHAIN_ROOT := + /home/myuser/work/CEVA-ToolBox/V18/BX +2.3. Generate the Makefile for the project: /tensorflow$ make -f + tensorflow/lite/micro/tools/make/Makefile TARGET=ceva TARGET_ARCH=CEVA_BX1 + generate_micro_speech_make_project +3. For SensPro (SP500): +3.1. Download and install CEVA-SP Toolbox v20 +3.2. Set the TARGET_TOOLCHAIN_ROOT variable in + /tensorflow/lite/micro/tools/make/templates/ceva_SP500/ceva_app_makefile.tpl + To your installation location. For example: TARGET_TOOLCHAIN_ROOT := + /home/myuser/work/CEVA-ToolBox/V20/SensPro +3.3. Generate the Makefile for the project: /tensorflow$ make -f + tensorflow/lite/micro/tools/make/Makefile TARGET=ceva TARGET_ARCH=CEVA_SP500 + generate_micro_speech_make_project +5. Build the project: + /tensorflow/lite/micro/tools/make/gen/ceva_bx1/prj/micro_speech/make$ make +6. This should build the project and create a file called micro_speech.elf. +7. The supplied configuration reads input from a files and expects a file + called input.wav (easily changed in audio_provider.cc) to be placed in the + same directory of the .elf file +8. We used Google's speech command dataset: V0.0.2: + http://download.tensorflow.org/data/speech_commands_v0.02.tar.gz V0.0.1: + http://download.tensorflow.org/data/speech_commands_v0.01.tar.gz +9. Follow CEVA Toolbox instructions for creating a debug target and running the + project. +10. Output should look like: Heard silence (208) @352ms Heard no (201) @1696ms + Heard yes (203) @3904ms + +## Run on macOS + +The example contains an audio provider compatible with macOS. If you have access +to a Mac, you can run the example on your development machine. + +First, use the following command to build it: + +``` +make -f tensorflow/lite/micro/tools/make/Makefile micro_speech +``` + +Once the build completes, you can run the example with the following command: + +``` +tensorflow/lite/micro/tools/make/gen/osx_x86_64/bin/micro_speech +``` + +You might see a pop-up asking for microphone access. If so, grant it, and the +program will start. + +Try saying "yes" and "no". You should see output that looks like the following: + +``` +Heard yes (201) @4056ms +Heard no (205) @6448ms +Heard unknown (201) @13696ms +Heard yes (205) @15000ms +Heard yes (205) @16856ms +Heard unknown (204) @18704ms +Heard no (206) @21000ms +``` + +The number after each detected word is its score. By default, the recognize +commands component only considers matches as valid if their score is over 200, +so all of the scores you see will be at least 200. + +The number after the score is the number of milliseconds since the program was +started. + +If you don't see any output, make sure your Mac's internal microphone is +selected in the Mac's *Sound* menu, and that its input volume is turned up high +enough. + +## Run the tests on a development machine + +To compile and test this example on a desktop Linux or macOS machine, download +[the TensorFlow source code](https://github.com/tensorflow/tensorflow), `cd` +into the source directory from a terminal, and then run the following command: + +``` +make -f tensorflow/lite/micro/tools/make/Makefile test_micro_speech_test +``` + +This will take a few minutes, and downloads frameworks the code uses like +[CMSIS](https://developer.arm.com/embedded/cmsis) and +[flatbuffers](https://google.github.io/flatbuffers/). Once that process has +finished, you should see a series of files get compiled, followed by some +logging output from a test, which should conclude with `~~~ALL TESTS PASSED~~~`. + +If you see this, it means that a small program has been built and run that loads +the trained TensorFlow model, runs some example inputs through it, and got the +expected outputs. + +To understand how TensorFlow Lite does this, you can look at the source in +[micro_speech_test.cc](micro_speech_test.cc). +It's a fairly small amount of code that creates an interpreter, gets a handle to +a model that's been compiled into the program, and then invokes the interpreter +with the model and sample inputs. + +## Train your own model + +So far you have used an existing trained model to run inference on +microcontrollers. If you wish to train your own model, follow the instructions +given in the [train/](train/) directory. diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/audio_provider.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/audio_provider.cc new file mode 100644 index 00000000..9ffee175 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/audio_provider.cc @@ -0,0 +1,41 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/micro_speech/audio_provider.h" + +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.h" + +namespace { +int16_t g_dummy_audio_data[kMaxAudioSampleSize]; +int32_t g_latest_audio_timestamp = 0; +} // namespace + +TfLiteStatus GetAudioSamples(tflite::ErrorReporter *error_reporter, + int start_ms, int duration_ms, + int *audio_samples_size, int16_t **audio_samples) +{ + for (int i = 0; i < kMaxAudioSampleSize; ++i) { + g_dummy_audio_data[i] = 0; + } + *audio_samples_size = kMaxAudioSampleSize; + *audio_samples = g_dummy_audio_data; + return kTfLiteOk; +} + +int32_t LatestAudioTimestamp() +{ + g_latest_audio_timestamp += 100; + return g_latest_audio_timestamp; +} diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/audio_provider.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/audio_provider.h new file mode 100644 index 00000000..f1ebe7a0 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/audio_provider.h @@ -0,0 +1,46 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_AUDIO_PROVIDER_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_AUDIO_PROVIDER_H_ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" + +// This is an abstraction around an audio source like a microphone, and is +// expected to return 16-bit PCM sample data for a given point in time. The +// sample data itself should be used as quickly as possible by the caller, since +// to allow memory optimizations there are no guarantees that the samples won't +// be overwritten by new data in the future. In practice, implementations should +// ensure that there's a reasonable time allowed for clients to access the data +// before any reuse. +// The reference implementation can have no platform-specific dependencies, so +// it just returns an array filled with zeros. For real applications, you should +// ensure there's a specialized implementation that accesses hardware APIs. +TfLiteStatus GetAudioSamples(tflite::ErrorReporter *error_reporter, + int start_ms, int duration_ms, + int *audio_samples_size, int16_t **audio_samples); + +// Returns the time that audio data was last captured in milliseconds. There's +// no contract about what time zero represents, the accuracy, or the granularity +// of the result. Subsequent calls will generally not return a lower value, but +// even that's not guaranteed if there's an overflow wraparound. +// The reference implementation of this function just returns a constantly +// incrementing value for each call, since it would need a non-portable platform +// call to access time information. For real applications, you'll need to write +// your own platform-specific implementation. +int32_t LatestAudioTimestamp(); + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_AUDIO_PROVIDER_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/audio_provider_mock.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/audio_provider_mock.cc new file mode 100644 index 00000000..d3403842 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/audio_provider_mock.cc @@ -0,0 +1,57 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/micro_speech/audio_provider.h" +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.h" +#include "tensorflow/lite/micro/examples/micro_speech/no_1000ms_sample_data.h" +#include "tensorflow/lite/micro/examples/micro_speech/yes_1000ms_sample_data.h" + +namespace { +int16_t g_dummy_audio_data[kMaxAudioSampleSize]; +int32_t g_latest_audio_timestamp = 0; +} // namespace + +TfLiteStatus GetAudioSamples(tflite::ErrorReporter *error_reporter, + int start_ms, int duration_ms, + int *audio_samples_size, int16_t **audio_samples) +{ + const int yes_start = (0 * kAudioSampleFrequency) / 1000; + const int yes_end = (1000 * kAudioSampleFrequency) / 1000; + const int no_start = (4000 * kAudioSampleFrequency) / 1000; + const int no_end = (5000 * kAudioSampleFrequency) / 1000; + const int wraparound = (8000 * kAudioSampleFrequency) / 1000; + const int start_sample = (start_ms * kAudioSampleFrequency) / 1000; + for (int i = 0; i < kMaxAudioSampleSize; ++i) { + const int sample_index = (start_sample + i) % wraparound; + int16_t sample; + if ((sample_index >= yes_start) && (sample_index < yes_end)) { + sample = g_yes_1000ms_sample_data[sample_index - yes_start]; + } else if ((sample_index >= no_start) && (sample_index < no_end)) { + sample = g_no_1000ms_sample_data[sample_index - no_start]; + } else { + sample = 0; + } + g_dummy_audio_data[i] = sample; + } + *audio_samples_size = kMaxAudioSampleSize; + *audio_samples = g_dummy_audio_data; + return kTfLiteOk; +} + +int32_t LatestAudioTimestamp() +{ + g_latest_audio_timestamp += 100; + return g_latest_audio_timestamp; +} diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/audio_provider_mock_test.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/audio_provider_mock_test.cc new file mode 100644 index 00000000..e400f560 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/audio_provider_mock_test.cc @@ -0,0 +1,77 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/examples/micro_speech/audio_provider.h" +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.h" +#include "tensorflow/lite/micro/examples/micro_speech/no_1000ms_sample_data.h" +#include "tensorflow/lite/micro/examples/micro_speech/yes_1000ms_sample_data.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestAudioProviderMock) +{ + tflite::MicroErrorReporter micro_error_reporter; + + int audio_samples_size = 0; + int16_t *audio_samples = nullptr; + TfLiteStatus get_status = + GetAudioSamples(µ_error_reporter, 0, kFeatureSliceDurationMs, + &audio_samples_size, &audio_samples); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, get_status); + TF_LITE_MICRO_EXPECT_LE(audio_samples_size, kMaxAudioSampleSize); + TF_LITE_MICRO_EXPECT_NE(audio_samples, nullptr); + for (int i = 0; i < audio_samples_size; ++i) { + TF_LITE_MICRO_EXPECT_EQ(g_yes_1000ms_sample_data[i], audio_samples[i]); + } + + get_status = + GetAudioSamples(µ_error_reporter, 500, kFeatureSliceDurationMs, + &audio_samples_size, &audio_samples); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, get_status); + TF_LITE_MICRO_EXPECT_LE(audio_samples_size, kMaxAudioSampleSize); + TF_LITE_MICRO_EXPECT_NE(audio_samples, nullptr); + for (int i = 0; i < audio_samples_size; ++i) { + TF_LITE_MICRO_EXPECT_EQ(g_yes_1000ms_sample_data[i + 8000], + audio_samples[i]); + } + + get_status = + GetAudioSamples(µ_error_reporter, 1500, kFeatureSliceDurationMs, + &audio_samples_size, &audio_samples); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, get_status); + TF_LITE_MICRO_EXPECT_LE(audio_samples_size, kMaxAudioSampleSize); + TF_LITE_MICRO_EXPECT_NE(audio_samples, nullptr); + for (int i = 0; i < audio_samples_size; ++i) { + TF_LITE_MICRO_EXPECT_EQ(0, audio_samples[i]); + } + + get_status = + GetAudioSamples(µ_error_reporter, 12250, kFeatureSliceDurationMs, + &audio_samples_size, &audio_samples); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, get_status); + TF_LITE_MICRO_EXPECT_LE(audio_samples_size, kMaxAudioSampleSize); + TF_LITE_MICRO_EXPECT_NE(audio_samples, nullptr); + for (int i = 0; i < audio_samples_size; ++i) { + TF_LITE_MICRO_EXPECT_EQ(g_no_1000ms_sample_data[i + 4000], + audio_samples[i]); + } +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/audio_provider_test.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/audio_provider_test.cc new file mode 100644 index 00000000..89fb4841 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/audio_provider_test.cc @@ -0,0 +1,71 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/micro_speech/audio_provider.h" + +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestAudioProvider) +{ + tflite::MicroErrorReporter micro_error_reporter; + + int audio_samples_size = 0; + int16_t *audio_samples = nullptr; + TfLiteStatus get_status = + GetAudioSamples(µ_error_reporter, 0, kFeatureSliceDurationMs, + &audio_samples_size, &audio_samples); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, get_status); + TF_LITE_MICRO_EXPECT_LE(audio_samples_size, kMaxAudioSampleSize); + TF_LITE_MICRO_EXPECT_NE(audio_samples, nullptr); + + // Make sure we can read all of the returned memory locations. + int total = 0; + for (int i = 0; i < audio_samples_size; ++i) { + total += audio_samples[i]; + } +} + +TF_LITE_MICRO_TEST(TestTimer) +{ + // Make sure that the technically-undefined overflow behavior we rely on below + // works on this platform. It's still not guaranteed, but at least this is a + // smoke check. Turn off when running with ASan, as it will complain about + // the following undefined behavior. +#ifndef ADDRESS_SANITIZER + int32_t overflow_value = std::numeric_limits::max(); + overflow_value += 1; + TF_LITE_MICRO_EXPECT_EQ(std::numeric_limits::min(), overflow_value); +#endif + + const int32_t first_time = LatestAudioTimestamp(); + const int32_t second_time = LatestAudioTimestamp(); + + // It's possible that the timer may have wrapped around from +BIG_NUM to + // -BIG_NUM between the first and second calls, since we're storing + // milliseconds in a 32-bit integer. It's not reasonable that the call itself + // would have taken more than 2^31 milliseconds though, so look at the + // difference and rely on integer overflow to ensure it's accurate. + const int32_t time_delta = (second_time - first_time); + TF_LITE_MICRO_EXPECT_LE(0, time_delta); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/command_responder.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/command_responder.cc new file mode 100644 index 00000000..41ab092c --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/command_responder.cc @@ -0,0 +1,29 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/micro_speech/command_responder.h" + +// The default implementation writes out the name of the recognized command +// to the error console. Real applications will want to take some custom +// action instead, and should implement their own versions of this function. +void RespondToCommand(tflite::ErrorReporter *error_reporter, + int32_t current_time, const char *found_command, + uint8_t score, bool is_new_command) +{ + if (is_new_command) { + TF_LITE_REPORT_ERROR(error_reporter, "Heard %s (%d) @%dms", found_command, + score, current_time); + } +} diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/command_responder.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/command_responder.h new file mode 100644 index 00000000..e4c42f61 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/command_responder.h @@ -0,0 +1,32 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// Provides an interface to take an action based on an audio command. + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_COMMAND_RESPONDER_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_COMMAND_RESPONDER_H_ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" + +// Called every time the results of an audio recognition run are available. The +// human-readable name of any recognized command is in the `found_command` +// argument, `score` has the numerical confidence, and `is_new_command` is set +// if the previous command was different to this one. +void RespondToCommand(tflite::ErrorReporter *error_reporter, + int32_t current_time, const char *found_command, + uint8_t score, bool is_new_command); + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_COMMAND_RESPONDER_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/command_responder_test.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/command_responder_test.cc new file mode 100644 index 00000000..6231d95f --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/command_responder_test.cc @@ -0,0 +1,32 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/micro_speech/command_responder.h" + +#include "tensorflow/lite/micro/testing/micro_test.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestCallability) +{ + tflite::MicroErrorReporter micro_error_reporter; + + // This will have external side-effects (like printing to the debug console + // or lighting an LED) that are hard to observe, so the most we can do is + // make sure the call doesn't crash. + RespondToCommand(µ_error_reporter, 0, "foo", 0, true); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/feature_provider.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/feature_provider.cc new file mode 100644 index 00000000..fe5f5bce --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/feature_provider.cc @@ -0,0 +1,124 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/micro_speech/feature_provider.h" + +#include "tensorflow/lite/micro/examples/micro_speech/audio_provider.h" +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/micro_features_generator.h" +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.h" + +FeatureProvider::FeatureProvider(int feature_size, int8_t *feature_data) + : feature_size_(feature_size), + feature_data_(feature_data), + is_first_run_(true) +{ + // Initialize the feature data to default values. + for (int n = 0; n < feature_size_; ++n) { + feature_data_[n] = 0; + } +} + +FeatureProvider::~FeatureProvider() +{ +} + +TfLiteStatus FeatureProvider::PopulateFeatureData( + tflite::ErrorReporter *error_reporter, int32_t last_time_in_ms, + int32_t time_in_ms, int *how_many_new_slices) +{ + if (feature_size_ != kFeatureElementCount) { + TF_LITE_REPORT_ERROR(error_reporter, + "Requested feature_data_ size %d doesn't match %d", + feature_size_, kFeatureElementCount); + return kTfLiteError; + } + + // Quantize the time into steps as long as each window stride, so we can + // figure out which audio data we need to fetch. + const int last_step = (last_time_in_ms / kFeatureSliceStrideMs); + const int current_step = (time_in_ms / kFeatureSliceStrideMs); + + int slices_needed = current_step - last_step; + // If this is the first call, make sure we don't use any cached information. + if (is_first_run_) { + TfLiteStatus init_status = InitializeMicroFeatures(error_reporter); + if (init_status != kTfLiteOk) { + return init_status; + } + is_first_run_ = false; + slices_needed = kFeatureSliceCount; + } + if (slices_needed > kFeatureSliceCount) { + slices_needed = kFeatureSliceCount; + } + *how_many_new_slices = slices_needed; + + const int slices_to_keep = kFeatureSliceCount - slices_needed; + const int slices_to_drop = kFeatureSliceCount - slices_to_keep; + // If we can avoid recalculating some slices, just move the existing data + // up in the spectrogram, to perform something like this: + // last time = 80ms current time = 120ms + // +-----------+ +-----------+ + // | data@20ms | --> | data@60ms | + // +-----------+ -- +-----------+ + // | data@40ms | -- --> | data@80ms | + // +-----------+ -- -- +-----------+ + // | data@60ms | -- -- | | + // +-----------+ -- +-----------+ + // | data@80ms | -- | | + // +-----------+ +-----------+ + if (slices_to_keep > 0) { + for (int dest_slice = 0; dest_slice < slices_to_keep; ++dest_slice) { + int8_t *dest_slice_data = + feature_data_ + (dest_slice * kFeatureSliceSize); + const int src_slice = dest_slice + slices_to_drop; + const int8_t *src_slice_data = + feature_data_ + (src_slice * kFeatureSliceSize); + for (int i = 0; i < kFeatureSliceSize; ++i) { + dest_slice_data[i] = src_slice_data[i]; + } + } + } + // Any slices that need to be filled in with feature data have their + // appropriate audio data pulled, and features calculated for that slice. + if (slices_needed > 0) { + for (int new_slice = slices_to_keep; new_slice < kFeatureSliceCount; + ++new_slice) { + const int new_step = (current_step - kFeatureSliceCount + 1) + new_slice; + const int32_t slice_start_ms = (new_step * kFeatureSliceStrideMs); + int16_t *audio_samples = nullptr; + int audio_samples_size = 0; + // TODO(petewarden): Fix bug that leads to non-zero slice_start_ms + GetAudioSamples(error_reporter, (slice_start_ms > 0 ? slice_start_ms : 0), + kFeatureSliceDurationMs, &audio_samples_size, + &audio_samples); + if (audio_samples_size < kMaxAudioSampleSize) { + TF_LITE_REPORT_ERROR(error_reporter, + "Audio data size %d too small, want %d", + audio_samples_size, kMaxAudioSampleSize); + return kTfLiteError; + } + int8_t *new_slice_data = feature_data_ + (new_slice * kFeatureSliceSize); + size_t num_samples_read; + TfLiteStatus generate_status = GenerateMicroFeatures( + error_reporter, audio_samples, audio_samples_size, kFeatureSliceSize, + new_slice_data, &num_samples_read); + if (generate_status != kTfLiteOk) { + return generate_status; + } + } + } + return kTfLiteOk; +} diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/feature_provider.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/feature_provider.h new file mode 100644 index 00000000..da0c2fe7 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/feature_provider.h @@ -0,0 +1,52 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_FEATURE_PROVIDER_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_FEATURE_PROVIDER_H_ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" + +// Binds itself to an area of memory intended to hold the input features for an +// audio-recognition neural network model, and fills that data area with the +// features representing the current audio input, for example from a microphone. +// The audio features themselves are a two-dimensional array, made up of +// horizontal slices representing the frequencies at one point in time, stacked +// on top of each other to form a spectrogram showing how those frequencies +// changed over time. +class FeatureProvider { +public: + // Create the provider, and bind it to an area of memory. This memory should + // remain accessible for the lifetime of the provider object, since subsequent + // calls will fill it with feature data. The provider does no memory + // management of this data. + FeatureProvider(int feature_size, int8_t *feature_data); + ~FeatureProvider(); + + // Fills the feature data with information from audio inputs, and returns how + // many feature slices were updated. + TfLiteStatus PopulateFeatureData(tflite::ErrorReporter *error_reporter, + int32_t last_time_in_ms, int32_t time_in_ms, + int *how_many_new_slices); + +private: + int feature_size_; + int8_t *feature_data_; + // Make sure we don't try to use cached information if this is the first call + // into the provider. + bool is_first_run_; +}; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_FEATURE_PROVIDER_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/feature_provider_mock_test.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/feature_provider_mock_test.cc new file mode 100644 index 00000000..eafd86df --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/feature_provider_mock_test.cc @@ -0,0 +1,66 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/examples/micro_speech/feature_provider.h" +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.h" +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/no_micro_features_data.h" +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/yes_micro_features_data.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestFeatureProviderMockYes) +{ + tflite::MicroErrorReporter micro_error_reporter; + + int8_t feature_data[kFeatureElementCount]; + FeatureProvider feature_provider(kFeatureElementCount, feature_data); + + int how_many_new_slices = 0; + TfLiteStatus populate_status = feature_provider.PopulateFeatureData( + µ_error_reporter, /* last_time_in_ms= */ 0, /* time_in_ms= */ 970, + &how_many_new_slices); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, populate_status); + TF_LITE_MICRO_EXPECT_EQ(kFeatureSliceCount, how_many_new_slices); + + for (int i = 0; i < kFeatureElementCount; ++i) { + TF_LITE_MICRO_EXPECT_EQ(g_yes_micro_f2e59fea_nohash_1_data[i], + feature_data[i]); + } +} + +TF_LITE_MICRO_TEST(TestFeatureProviderMockNo) +{ + tflite::MicroErrorReporter micro_error_reporter; + + int8_t feature_data[kFeatureElementCount]; + FeatureProvider feature_provider(kFeatureElementCount, feature_data); + + int how_many_new_slices = 0; + TfLiteStatus populate_status = feature_provider.PopulateFeatureData( + µ_error_reporter, /* last_time_in_ms= */ 4000, + /* time_in_ms= */ 4970, &how_many_new_slices); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, populate_status); + TF_LITE_MICRO_EXPECT_EQ(kFeatureSliceCount, how_many_new_slices); + + for (int i = 0; i < kFeatureElementCount; ++i) { + TF_LITE_MICRO_EXPECT_EQ(g_no_micro_f9643d42_nohash_4_data[i], + feature_data[i]); + } +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/feature_provider_test.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/feature_provider_test.cc new file mode 100644 index 00000000..f6245993 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/feature_provider_test.cc @@ -0,0 +1,40 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/micro_speech/feature_provider.h" + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestFeatureProvider) +{ + tflite::MicroErrorReporter micro_error_reporter; + + int8_t feature_data[kFeatureElementCount]; + FeatureProvider feature_provider(kFeatureElementCount, feature_data); + + int how_many_new_slices = 0; + TfLiteStatus populate_status = feature_provider.PopulateFeatureData( + µ_error_reporter, /* last_time_in_ms= */ 0, /* time_in_ms= */ 10000, + &how_many_new_slices); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, populate_status); + TF_LITE_MICRO_EXPECT_EQ(kFeatureSliceCount, how_many_new_slices); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/images/animation_on_arduino.gif b/components/tflite/tensorflow/lite/micro/examples/micro_speech/images/animation_on_arduino.gif new file mode 100644 index 00000000..66ab9c1a Binary files /dev/null and b/components/tflite/tensorflow/lite/micro/examples/micro_speech/images/animation_on_arduino.gif differ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/images/model_architecture.png b/components/tflite/tensorflow/lite/micro/examples/micro_speech/images/model_architecture.png new file mode 100644 index 00000000..ce91fadd Binary files /dev/null and b/components/tflite/tensorflow/lite/micro/examples/micro_speech/images/model_architecture.png differ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/main.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/main.cc new file mode 100644 index 00000000..30a71dd7 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/main.cc @@ -0,0 +1,28 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/micro_speech/main_functions.h" + +// This is the default main used on systems that have the standard C entry +// point. Other devices (for example FreeRTOS or ESP32) that have different +// requirements for entry code (like an app_main function) should specialize +// this main.cc file in a target-specific subfolder. +int main(int argc, char *argv[]) +{ + setup(); + while (true) { + loop(); + } +} diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/main_functions.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/main_functions.cc new file mode 100644 index 00000000..39e2757b --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/main_functions.cc @@ -0,0 +1,179 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/micro_speech/main_functions.h" + +#include "tensorflow/lite/micro/examples/micro_speech/audio_provider.h" +#include "tensorflow/lite/micro/examples/micro_speech/command_responder.h" +#include "tensorflow/lite/micro/examples/micro_speech/feature_provider.h" +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.h" +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/model.h" +#include "tensorflow/lite/micro/examples/micro_speech/recognize_commands.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/micro_interpreter.h" +#include "tensorflow/lite/micro/micro_mutable_op_resolver.h" +#include "tensorflow/lite/micro/system_setup.h" +#include "tensorflow/lite/schema/schema_generated.h" + +// Globals, used for compatibility with Arduino-style sketches. +namespace { +tflite::ErrorReporter *error_reporter = nullptr; +const tflite::Model *model = nullptr; +tflite::MicroInterpreter *interpreter = nullptr; +TfLiteTensor *model_input = nullptr; +FeatureProvider *feature_provider = nullptr; +RecognizeCommands *recognizer = nullptr; +int32_t previous_time = 0; + +// Create an area of memory to use for input, output, and intermediate arrays. +// The size of this will depend on the model you're using, and may need to be +// determined by experimentation. +constexpr int kTensorArenaSize = 10 * 1024; +uint8_t tensor_arena[kTensorArenaSize]; +int8_t feature_buffer[kFeatureElementCount]; +int8_t *model_input_buffer = nullptr; +} // namespace + +// The name of this function is important for Arduino compatibility. +void setup() +{ + tflite::InitializeTarget(); + + // Set up logging. Google style is to avoid globals or statics because of + // lifetime uncertainty, but since this has a trivial destructor it's okay. + // NOLINTNEXTLINE(runtime-global-variables) + static tflite::MicroErrorReporter micro_error_reporter; + error_reporter = µ_error_reporter; + + // Map the model into a usable data structure. This doesn't involve any + // copying or parsing, it's a very lightweight operation. + model = tflite::GetModel(g_model); + if (model->version() != TFLITE_SCHEMA_VERSION) { + TF_LITE_REPORT_ERROR(error_reporter, + "Model provided is schema version %d not equal " + "to supported version %d.", + model->version(), TFLITE_SCHEMA_VERSION); + return; + } + + // Pull in only the operation implementations we need. + // This relies on a complete list of all the ops needed by this graph. + // An easier approach is to just use the AllOpsResolver, but this will + // incur some penalty in code space for op implementations that are not + // needed by this graph. + // + // tflite::AllOpsResolver resolver; + // NOLINTNEXTLINE(runtime-global-variables) + static tflite::MicroMutableOpResolver<4> micro_op_resolver(error_reporter); + if (micro_op_resolver.AddDepthwiseConv2D() != kTfLiteOk) { + return; + } + if (micro_op_resolver.AddFullyConnected() != kTfLiteOk) { + return; + } + if (micro_op_resolver.AddSoftmax() != kTfLiteOk) { + return; + } + if (micro_op_resolver.AddReshape() != kTfLiteOk) { + return; + } + + // Build an interpreter to run the model with. + static tflite::MicroInterpreter static_interpreter( + model, micro_op_resolver, tensor_arena, kTensorArenaSize, error_reporter); + interpreter = &static_interpreter; + + // Allocate memory from the tensor_arena for the model's tensors. + TfLiteStatus allocate_status = interpreter->AllocateTensors(); + if (allocate_status != kTfLiteOk) { + TF_LITE_REPORT_ERROR(error_reporter, "AllocateTensors() failed"); + return; + } + + // Get information about the memory area to use for the model's input. + model_input = interpreter->input(0); + if ((model_input->dims->size != 2) || (model_input->dims->data[0] != 1) || + (model_input->dims->data[1] != + (kFeatureSliceCount * kFeatureSliceSize)) || + (model_input->type != kTfLiteInt8)) { + TF_LITE_REPORT_ERROR(error_reporter, + "Bad input tensor parameters in model"); + return; + } + model_input_buffer = model_input->data.int8; + + // Prepare to access the audio spectrograms from a microphone or other source + // that will provide the inputs to the neural network. + // NOLINTNEXTLINE(runtime-global-variables) + static FeatureProvider static_feature_provider(kFeatureElementCount, + feature_buffer); + feature_provider = &static_feature_provider; + + static RecognizeCommands static_recognizer(error_reporter); + recognizer = &static_recognizer; + + previous_time = 0; +} + +// The name of this function is important for Arduino compatibility. +void loop() +{ + // Fetch the spectrogram for the current time. + const int32_t current_time = LatestAudioTimestamp(); + int how_many_new_slices = 0; + TfLiteStatus feature_status = feature_provider->PopulateFeatureData( + error_reporter, previous_time, current_time, &how_many_new_slices); + if (feature_status != kTfLiteOk) { + TF_LITE_REPORT_ERROR(error_reporter, "Feature generation failed"); + return; + } + previous_time = current_time; + // If no new audio samples have been received since last time, don't bother + // running the network model. + if (how_many_new_slices == 0) { + return; + } + + // Copy feature buffer to input tensor + for (int i = 0; i < kFeatureElementCount; i++) { + model_input_buffer[i] = feature_buffer[i]; + } + + // Run the model on the spectrogram input and make sure it succeeds. + TfLiteStatus invoke_status = interpreter->Invoke(); + if (invoke_status != kTfLiteOk) { + TF_LITE_REPORT_ERROR(error_reporter, "Invoke failed"); + return; + } + + // Obtain a pointer to the output tensor + TfLiteTensor *output = interpreter->output(0); + // Determine whether a command was recognized based on the output of inference + const char *found_command = nullptr; + uint8_t score = 0; + bool is_new_command = false; + TfLiteStatus process_status = recognizer->ProcessLatestResults( + output, current_time, &found_command, &score, &is_new_command); + if (process_status != kTfLiteOk) { + TF_LITE_REPORT_ERROR(error_reporter, + "RecognizeCommands::ProcessLatestResults() failed"); + return; + } + // Do something based on the recognized command. The default implementation + // just prints to the error console, but you should replace this with your + // own function for a real application. + RespondToCommand(error_reporter, current_time, found_command, score, + is_new_command); +} diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/main_functions.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/main_functions.h new file mode 100644 index 00000000..d2219ade --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/main_functions.h @@ -0,0 +1,37 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MAIN_FUNCTIONS_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MAIN_FUNCTIONS_H_ + +// Expose a C friendly interface for main functions. +#ifdef __cplusplus +extern "C" { +#endif + +// Initializes all data needed for the example. The name is important, and needs +// to be setup() for Arduino compatibility. +void setup(); + +// Runs one iteration of data gathering and inference. This should be called +// repeatedly from the application code. The name needs to be loop() for Arduino +// compatibility. +void loop(); + +#ifdef __cplusplus +} +#endif + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MAIN_FUNCTIONS_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/micro_features_generator.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/micro_features_generator.cc new file mode 100644 index 00000000..23ea3c63 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/micro_features_generator.cc @@ -0,0 +1,119 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/micro_features_generator.h" + +#include +#include + +#include "tensorflow/lite/experimental/microfrontend/lib/frontend.h" +#include "tensorflow/lite/experimental/microfrontend/lib/frontend_util.h" +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.h" + +// Configure FFT to output 16 bit fixed point. +#define FIXED_POINT 16 + +namespace { + +FrontendState g_micro_features_state; +bool g_is_first_time = true; + +} // namespace + +TfLiteStatus InitializeMicroFeatures(tflite::ErrorReporter *error_reporter) +{ + FrontendConfig config; + config.window.size_ms = kFeatureSliceDurationMs; + config.window.step_size_ms = kFeatureSliceStrideMs; + config.noise_reduction.smoothing_bits = 10; + config.filterbank.num_channels = kFeatureSliceSize; + config.filterbank.lower_band_limit = 125.0; + config.filterbank.upper_band_limit = 7500.0; + config.noise_reduction.smoothing_bits = 10; + config.noise_reduction.even_smoothing = 0.025; + config.noise_reduction.odd_smoothing = 0.06; + config.noise_reduction.min_signal_remaining = 0.05; + config.pcan_gain_control.enable_pcan = 1; + config.pcan_gain_control.strength = 0.95; + config.pcan_gain_control.offset = 80.0; + config.pcan_gain_control.gain_bits = 21; + config.log_scale.enable_log = 1; + config.log_scale.scale_shift = 6; + if (!FrontendPopulateState(&config, &g_micro_features_state, + kAudioSampleFrequency)) { + TF_LITE_REPORT_ERROR(error_reporter, "FrontendPopulateState() failed"); + return kTfLiteError; + } + g_is_first_time = true; + return kTfLiteOk; +} + +// This is not exposed in any header, and is only used for testing, to ensure +// that the state is correctly set up before generating results. +void SetMicroFeaturesNoiseEstimates(const uint32_t *estimate_presets) +{ + for (int i = 0; i < g_micro_features_state.filterbank.num_channels; ++i) { + g_micro_features_state.noise_reduction.estimate[i] = estimate_presets[i]; + } +} + +TfLiteStatus GenerateMicroFeatures(tflite::ErrorReporter *error_reporter, + const int16_t *input, int input_size, + int output_size, int8_t *output, + size_t *num_samples_read) +{ + const int16_t *frontend_input; + if (g_is_first_time) { + frontend_input = input; + g_is_first_time = false; + } else { + frontend_input = input + 160; + } + FrontendOutput frontend_output = FrontendProcessSamples( + &g_micro_features_state, frontend_input, input_size, num_samples_read); + + for (size_t i = 0; i < frontend_output.size; ++i) { + // These scaling values are derived from those used in input_data.py in the + // training pipeline. + // The feature pipeline outputs 16-bit signed integers in roughly a 0 to 670 + // range. In training, these are then arbitrarily divided by 25.6 to get + // float values in the rough range of 0.0 to 26.0. This scaling is performed + // for historical reasons, to match up with the output of other feature + // generators. + // The process is then further complicated when we quantize the model. This + // means we have to scale the 0.0 to 26.0 real values to the -128 to 127 + // signed integer numbers. + // All this means that to get matching values from our integer feature + // output into the tensor input, we have to perform: + // input = (((feature / 25.6) / 26.0) * 256) - 128 + // To simplify this and perform it in 32-bit integer math, we rearrange to: + // input = (feature * 256) / (25.6 * 26.0) - 128 + constexpr int32_t value_scale = 256; + constexpr int32_t value_div = static_cast((25.6f * 26.0f) + 0.5f); + int32_t value = + ((frontend_output.values[i] * value_scale) + (value_div / 2)) / + value_div; + value -= 128; + if (value < -128) { + value = -128; + } + if (value > 127) { + value = 127; + } + output[i] = value; + } + + return kTfLiteOk; +} diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/micro_features_generator.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/micro_features_generator.h new file mode 100644 index 00000000..3d47e545 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/micro_features_generator.h @@ -0,0 +1,32 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MICRO_FEATURES_GENERATOR_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MICRO_FEATURES_GENERATOR_H_ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" + +// Sets up any resources needed for the feature generation pipeline. +TfLiteStatus InitializeMicroFeatures(tflite::ErrorReporter *error_reporter); + +// Converts audio sample data into a more compact form that's appropriate for +// feeding into a neural network. +TfLiteStatus GenerateMicroFeatures(tflite::ErrorReporter *error_reporter, + const int16_t *input, int input_size, + int output_size, int8_t *output, + size_t *num_samples_read); + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MICRO_FEATURES_GENERATOR_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/micro_features_generator_test.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/micro_features_generator_test.cc new file mode 100644 index 00000000..757c922e --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/micro_features_generator_test.cc @@ -0,0 +1,176 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/micro_features_generator.h" + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/no_feature_data_slice.h" +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/yes_feature_data_slice.h" +#include "tensorflow/lite/micro/examples/micro_speech/no_30ms_sample_data.h" +#include "tensorflow/lite/micro/examples/micro_speech/yes_30ms_sample_data.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +// This is a test-only API, not exposed in any public headers, so declare it. +void SetMicroFeaturesNoiseEstimates(const uint32_t *estimate_presets); + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestMicroFeaturesGeneratorYes) +{ + tflite::MicroErrorReporter micro_error_reporter; + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + InitializeMicroFeatures(µ_error_reporter)); + + // The micro features pipeline retains state from previous calls to help + // estimate the background noise. Unfortunately this makes it harder to + // exactly reproduce results in a test environment, so use a known snapshot + // of the parameters at the point that the golden feature values were + // created. + const uint32_t yes_estimate_presets[] = { + 1062898, + 2644477, + 1257642, + 1864718, + 412722, + 725703, + 395721, + 474082, + 173046, + 255856, + 158966, + 153736, + 69181, + 199100, + 144493, + 227740, + 110573, + 164330, + 79666, + 144650, + 122947, + 476799, + 398553, + 497493, + 322152, + 1140005, + 566716, + 690605, + 308902, + 347481, + 109891, + 170457, + 73901, + 100975, + 42963, + 72325, + 34183, + 20207, + 6640, + 9468, + }; + SetMicroFeaturesNoiseEstimates(yes_estimate_presets); + + int8_t yes_calculated_data[g_yes_feature_data_slice_size]; + size_t num_samples_read; + TfLiteStatus yes_status = GenerateMicroFeatures( + µ_error_reporter, g_yes_30ms_sample_data, + g_yes_30ms_sample_data_size, g_yes_feature_data_slice_size, + yes_calculated_data, &num_samples_read); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, yes_status); + + for (int i = 0; i < g_yes_feature_data_slice_size; ++i) { + const int expected = g_yes_feature_data_slice[i]; + const int actual = yes_calculated_data[i]; + TF_LITE_MICRO_EXPECT_EQ(expected, actual); + if (expected != actual) { + TF_LITE_REPORT_ERROR(µ_error_reporter, + "Expected value %d but found %d", expected, actual); + } + } +} + +TF_LITE_MICRO_TEST(TestMicroFeaturesGeneratorNo) +{ + tflite::MicroErrorReporter micro_error_reporter; + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + InitializeMicroFeatures(µ_error_reporter)); + // As we did for the previous features, set known good noise state + // parameters. + const uint32_t no_estimate_presets[] = { + 2563964, + 1909393, + 559801, + 538670, + 203643, + 175959, + 75088, + 139491, + 59691, + 95307, + 43865, + 129263, + 52517, + 80058, + 51330, + 100731, + 76674, + 76262, + 15497, + 22598, + 13778, + 21460, + 8946, + 17806, + 10023, + 18810, + 8002, + 10842, + 7578, + 9983, + 6267, + 10759, + 8946, + 18488, + 9691, + 39785, + 9939, + 17835, + 9671, + 18512, + }; + SetMicroFeaturesNoiseEstimates(no_estimate_presets); + + int8_t no_calculated_data[g_no_feature_data_slice_size]; + size_t num_samples_read; + TfLiteStatus no_status = GenerateMicroFeatures( + µ_error_reporter, g_no_30ms_sample_data, g_no_30ms_sample_data_size, + g_no_feature_data_slice_size, no_calculated_data, &num_samples_read); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, no_status); + + for (size_t i = 0; i < g_no_feature_data_slice_size; ++i) { + const int expected = g_no_feature_data_slice[i]; + const int actual = no_calculated_data[i]; + TF_LITE_MICRO_EXPECT_EQ(expected, actual); + if (expected != actual) { + TF_LITE_REPORT_ERROR(µ_error_reporter, + "Expected value %d but found %d", expected, actual); + } + } +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.cc new file mode 100644 index 00000000..ce8d768b --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.cc @@ -0,0 +1,23 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.h" + +const char *kCategoryLabels[kCategoryCount] = { + "silence", + "unknown", + "yes", + "no", +}; diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.h new file mode 100644 index 00000000..05dbb788 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.h @@ -0,0 +1,43 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MICRO_MODEL_SETTINGS_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MICRO_MODEL_SETTINGS_H_ + +// Keeping these as constant expressions allow us to allocate fixed-sized arrays +// on the stack for our working memory. + +// The size of the input time series data we pass to the FFT to produce the +// frequency information. This has to be a power of two, and since we're dealing +// with 30ms of 16KHz inputs, which means 480 samples, this is the next value. +constexpr int kMaxAudioSampleSize = 512; +constexpr int kAudioSampleFrequency = 16000; + +// The following values are derived from values used during model training. +// If you change the way you preprocess the input, update all these constants. +constexpr int kFeatureSliceSize = 40; +constexpr int kFeatureSliceCount = 49; +constexpr int kFeatureElementCount = (kFeatureSliceSize * kFeatureSliceCount); +constexpr int kFeatureSliceStrideMs = 20; +constexpr int kFeatureSliceDurationMs = 30; + +// Variables for the model's output categories. +constexpr int kSilenceIndex = 0; +constexpr int kUnknownIndex = 1; +// If you modify the output categories, you need to update the following values. +constexpr int kCategoryCount = 4; +extern const char *kCategoryLabels[kCategoryCount]; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MICRO_MODEL_SETTINGS_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/model.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/model.cc new file mode 100644 index 00000000..a4e5cb30 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/model.cc @@ -0,0 +1,1597 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// This is a standard TensorFlow Lite FlatBuffer model file that has been +// converted into a C data array, so it can be easily compiled into a binary +// for devices that don't have a file system. It was created using the command: +// xxd -i model.tflite > model.cc + +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/model.h" + +// We need to keep the data array aligned on some architectures. +#ifdef __has_attribute +#define HAVE_ATTRIBUTE(x) __has_attribute(x) +#else +#define HAVE_ATTRIBUTE(x) 0 +#endif +#if HAVE_ATTRIBUTE(aligned) || (defined(__GNUC__) && !defined(__clang__)) +#define DATA_ALIGN_ATTRIBUTE __attribute__((aligned(4))) +#else +#define DATA_ALIGN_ATTRIBUTE +#endif + +const unsigned char g_model[] DATA_ALIGN_ATTRIBUTE = { + 0x20, 0x00, 0x00, 0x00, 0x54, 0x46, 0x4c, 0x33, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x12, 0x00, 0x1c, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, + 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x18, 0x00, 0x12, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x94, 0x48, 0x00, 0x00, 0x34, 0x42, 0x00, 0x00, + 0x1c, 0x42, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, + 0x04, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x0b, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x6d, 0x69, 0x6e, 0x5f, + 0x72, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x76, 0x65, 0x72, 0x73, + 0x69, 0x6f, 0x6e, 0x00, 0x0c, 0x00, 0x00, 0x00, 0xd4, 0x41, 0x00, 0x00, + 0xb4, 0x41, 0x00, 0x00, 0x24, 0x03, 0x00, 0x00, 0xf4, 0x02, 0x00, 0x00, + 0xec, 0x02, 0x00, 0x00, 0xe4, 0x02, 0x00, 0x00, 0xc4, 0x02, 0x00, 0x00, + 0xbc, 0x02, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x16, 0xbd, 0xff, 0xff, + 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x31, 0x2e, 0x35, 0x2e, + 0x30, 0x00, 0x00, 0x00, 0x94, 0xba, 0xff, 0xff, 0x98, 0xba, 0xff, 0xff, + 0x32, 0xbd, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, + 0xfa, 0xee, 0x28, 0xc4, 0xee, 0xfe, 0xcf, 0x0f, 0x1e, 0xf7, 0x1f, 0x06, + 0x0d, 0xed, 0xe9, 0x83, 0x5c, 0xc9, 0x18, 0xe3, 0xf9, 0x14, 0x28, 0x2a, + 0x09, 0xf2, 0x18, 0x34, 0x62, 0xea, 0xef, 0xd6, 0x36, 0xb7, 0x1e, 0xf7, + 0x3b, 0x22, 0x28, 0x39, 0xc2, 0x9d, 0xf1, 0x07, 0x5e, 0x0b, 0x1e, 0x2c, + 0x07, 0xdd, 0xfd, 0xc3, 0xd8, 0x4a, 0xf3, 0x28, 0xa7, 0x16, 0xd5, 0xf1, + 0xc3, 0x05, 0xfd, 0x27, 0xcc, 0xba, 0x1e, 0xcb, 0xd7, 0x3d, 0xd4, 0x29, + 0x00, 0xfd, 0x28, 0x44, 0xfb, 0xf2, 0xf3, 0xb6, 0x4f, 0xcf, 0x09, 0xf0, + 0xfa, 0x45, 0x41, 0x49, 0x05, 0xc5, 0x17, 0x5d, 0x64, 0x00, 0xf8, 0xee, + 0x48, 0x17, 0xf4, 0xe9, 0x2e, 0x4b, 0x2e, 0x3f, 0xdf, 0xee, 0xe4, 0x08, + 0x38, 0xf1, 0x16, 0x13, 0x2f, 0x2a, 0xed, 0xc2, 0xbf, 0x36, 0xf4, 0x02, + 0xcf, 0xaa, 0xd2, 0xfa, 0xac, 0x13, 0xf6, 0xe8, 0xb5, 0x68, 0x12, 0xb6, + 0xce, 0x0e, 0xdf, 0x58, 0xe4, 0x49, 0x14, 0x15, 0x03, 0xed, 0xfa, 0xd4, + 0x40, 0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e6, 0x16, 0xf3, 0x09, 0xfd, 0x08, 0x08, 0x06, + 0x06, 0x23, 0xdf, 0xfc, 0x08, 0xf4, 0xea, 0x0c, 0xf2, 0xe6, 0x18, 0xf5, + 0x02, 0xf9, 0x50, 0x09, 0x01, 0xda, 0x0b, 0x05, 0x12, 0x18, 0xef, 0x04, + 0x0e, 0xd9, 0xff, 0xdc, 0xf6, 0x16, 0xf9, 0xf4, 0xec, 0xff, 0xea, 0xe6, + 0xfa, 0x0a, 0xed, 0xef, 0x02, 0xf0, 0x25, 0x21, 0xf1, 0x26, 0xf5, 0xed, + 0x09, 0xea, 0xea, 0x24, 0xfa, 0x11, 0xfc, 0xdf, 0xf3, 0x0a, 0x28, 0x0c, + 0x19, 0xff, 0xf5, 0xd6, 0x0e, 0xe2, 0x2a, 0x06, 0xfa, 0x03, 0xf9, 0xe6, + 0xef, 0x23, 0xf9, 0xfa, 0xe6, 0xfe, 0xfc, 0x03, 0x06, 0x1a, 0xf9, 0x08, + 0xe0, 0xe5, 0xff, 0x05, 0x01, 0xe7, 0x12, 0x02, 0x1d, 0x05, 0x03, 0x05, + 0x0b, 0xee, 0xed, 0xfc, 0x0f, 0xf3, 0x02, 0xe0, 0x15, 0xdf, 0x02, 0xed, + 0x10, 0x26, 0xef, 0x0d, 0x06, 0xee, 0xef, 0xf6, 0xeb, 0x11, 0x09, 0xf4, + 0xf7, 0x06, 0x0f, 0x01, 0x2a, 0x0b, 0x01, 0xdd, 0xfc, 0xf4, 0xf1, 0x17, + 0x03, 0x04, 0x07, 0xfc, 0x22, 0xfc, 0xde, 0xfe, 0x0b, 0x03, 0xf3, 0xfb, + 0x0c, 0x25, 0x04, 0x19, 0x04, 0x03, 0x01, 0xfa, 0xfb, 0xf7, 0xf6, 0x0e, + 0x15, 0x0e, 0x09, 0xff, 0x06, 0xfa, 0xfb, 0x1e, 0xfb, 0x05, 0x22, 0xf9, + 0xfe, 0xf7, 0x1d, 0xed, 0xdf, 0x18, 0x09, 0xeb, 0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xfe, 0xee, 0x12, 0xf2, 0x0c, 0xec, + 0x02, 0x10, 0xef, 0x01, 0xf2, 0x0b, 0xf3, 0xf7, 0xfa, 0x25, 0xfb, 0x0d, + 0x11, 0x15, 0x04, 0xfc, 0x0c, 0x21, 0x12, 0x29, 0x00, 0xfa, 0xf6, 0xf5, + 0x06, 0x22, 0xea, 0xe2, 0xee, 0x00, 0xfd, 0xf0, 0x0b, 0x1d, 0xd3, 0xe4, + 0xe4, 0x0a, 0xfc, 0xe8, 0xea, 0x2c, 0xed, 0xed, 0xef, 0xe8, 0xf2, 0x05, + 0xfd, 0x15, 0xd8, 0xda, 0xca, 0xee, 0xfa, 0x00, 0xfe, 0x0e, 0xf2, 0xf0, + 0x0e, 0xf5, 0x04, 0x03, 0x1d, 0x2b, 0xee, 0x05, 0x0f, 0x10, 0x13, 0x35, + 0xe2, 0x04, 0x10, 0xdf, 0xcf, 0xeb, 0x40, 0x26, 0xe4, 0x03, 0xf3, 0xf9, + 0xf5, 0x14, 0x24, 0x2a, 0xdf, 0xfe, 0xab, 0xe5, 0xfe, 0x1c, 0x27, 0x35, + 0xdb, 0xff, 0xac, 0x01, 0xf6, 0xfc, 0x19, 0x1a, 0x11, 0x1f, 0xa8, 0xf5, + 0x02, 0x0f, 0x1a, 0x1f, 0xf7, 0xf2, 0xa2, 0x00, 0x15, 0x22, 0xe4, 0x13, + 0x00, 0x09, 0xd9, 0xd5, 0x02, 0x19, 0xfd, 0xf8, 0xe7, 0xff, 0xfb, 0xe0, + 0xef, 0xf7, 0xee, 0xf3, 0xf3, 0x19, 0xb0, 0xdf, 0x00, 0x0f, 0x08, 0xf3, + 0x15, 0x17, 0xec, 0x0f, 0x11, 0x14, 0x02, 0x08, 0x10, 0x17, 0xe6, 0x08, + 0xf7, 0x00, 0xed, 0xf7, 0x29, 0x07, 0x10, 0x05, 0x05, 0xe7, 0xed, 0xf4, + 0xf9, 0x15, 0xf9, 0xf0, 0x08, 0x00, 0x03, 0x09, 0x21, 0x28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00, 0xd8, + 0x08, 0xf6, 0xec, 0x17, 0xf9, 0x10, 0x00, 0xd9, 0x18, 0xf1, 0xee, 0x0f, + 0xf4, 0x03, 0xee, 0xeb, 0xf0, 0xef, 0xf2, 0x06, 0x04, 0x00, 0xf4, 0x0f, + 0x09, 0x06, 0xf7, 0x0b, 0xfd, 0x01, 0x03, 0x03, 0xf4, 0xf6, 0xdd, 0x14, + 0x1c, 0xef, 0xf1, 0xdd, 0xf7, 0x13, 0xd9, 0x15, 0xef, 0x02, 0xd2, 0xe7, + 0x05, 0x05, 0xe2, 0x09, 0xf2, 0x11, 0xf5, 0xba, 0xf0, 0x04, 0xe0, 0x01, + 0x06, 0x10, 0xe6, 0xef, 0xfc, 0x12, 0xf9, 0xf4, 0x1b, 0x2f, 0xe3, 0x0f, + 0xd7, 0xf6, 0x0b, 0x11, 0xf7, 0x0c, 0x00, 0x06, 0x18, 0xef, 0x06, 0x03, + 0x0a, 0x09, 0xf6, 0x1a, 0x0d, 0xed, 0xfe, 0x2c, 0x43, 0xf4, 0xe5, 0xde, + 0xf5, 0x02, 0x25, 0x5a, 0x49, 0xd4, 0xe6, 0x24, 0x1e, 0xf7, 0x0e, 0x5c, + 0x5d, 0xf0, 0xf9, 0xe4, 0x1c, 0xeb, 0x28, 0x7f, 0x5b, 0xec, 0xfa, 0xdb, + 0x0c, 0xf5, 0x20, 0x49, 0x51, 0xe1, 0xed, 0xe6, 0x0e, 0x26, 0x28, 0x33, + 0x35, 0x05, 0xe1, 0xe4, 0x1f, 0xfc, 0xf9, 0x39, 0x18, 0x04, 0xed, 0xed, + 0x01, 0xe7, 0xe6, 0x08, 0x09, 0x03, 0xe7, 0xf9, 0x0e, 0x06, 0xec, 0x08, + 0x12, 0x1a, 0xda, 0xef, 0xdf, 0xf9, 0xe2, 0x1e, 0x1c, 0x00, 0x12, 0xd7, + 0x01, 0xf7, 0x21, 0x17, 0x13, 0x19, 0xde, 0xe0, 0xec, 0x16, 0x01, 0x1b, + 0x06, 0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1b, 0x19, 0x06, 0x0e, 0x02, 0x0d, 0xf9, 0x06, 0xfc, 0x15, + 0x07, 0xfa, 0x0c, 0xe1, 0x18, 0x1a, 0xe8, 0x1b, 0xe9, 0xef, 0x0a, 0x18, + 0xfc, 0x05, 0xf9, 0x14, 0xdc, 0x04, 0x01, 0xff, 0x07, 0xfd, 0xf0, 0x2c, + 0xf2, 0xec, 0x0e, 0xe7, 0x1a, 0x05, 0xe8, 0x35, 0x13, 0x09, 0xf9, 0x07, + 0xfe, 0xfa, 0x0d, 0x40, 0x0c, 0xea, 0xf4, 0x04, 0x01, 0x11, 0xfc, 0x23, + 0xeb, 0xf4, 0xe9, 0x04, 0xeb, 0xe7, 0x07, 0x09, 0xfb, 0xf1, 0xf6, 0xfd, + 0x02, 0xfa, 0x02, 0xff, 0x00, 0xff, 0xf1, 0xf1, 0x1a, 0xe9, 0x10, 0xe3, + 0x0b, 0x0c, 0x08, 0x04, 0x1b, 0x0a, 0x2b, 0x10, 0xe1, 0x01, 0x1f, 0x06, + 0x04, 0xec, 0x19, 0x49, 0xee, 0xf8, 0x22, 0x0c, 0x20, 0x02, 0x07, 0x31, + 0xe7, 0xff, 0x0f, 0xf0, 0xfd, 0xea, 0x13, 0x26, 0xce, 0xfa, 0xff, 0xee, + 0xe9, 0xfe, 0x15, 0x08, 0x04, 0x05, 0x0d, 0xfa, 0xdd, 0xf8, 0x07, 0x0b, + 0x33, 0xef, 0xec, 0xf9, 0xd9, 0xe6, 0x1d, 0x10, 0x41, 0xf6, 0xdf, 0x11, + 0xe3, 0x14, 0x1d, 0xfb, 0x2b, 0x15, 0xdc, 0x09, 0xf6, 0x05, 0x16, 0x00, + 0x1c, 0x27, 0xe4, 0xfc, 0xf7, 0x16, 0x08, 0x08, 0x2f, 0xdd, 0xf8, 0xfa, + 0xe9, 0x0e, 0x0b, 0x0b, 0x02, 0x12, 0x02, 0xfd, 0x19, 0x03, 0xeb, 0x11, + 0xf4, 0x09, 0x09, 0x15, 0x12, 0x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, 0x04, 0xff, 0xfa, 0xf3, 0xff, 0x40, + 0xee, 0x06, 0xfc, 0x0d, 0x00, 0xf7, 0x13, 0x3f, 0xf7, 0x13, 0x06, 0x08, + 0xf9, 0x13, 0xf2, 0x19, 0xfd, 0xf9, 0xf3, 0xe6, 0xfc, 0x07, 0xf6, 0xfd, + 0x0a, 0x22, 0x00, 0x01, 0x19, 0xff, 0xe7, 0xff, 0x08, 0xfd, 0x03, 0xfd, + 0x1f, 0xe7, 0x28, 0x08, 0xde, 0xf3, 0x43, 0xf6, 0x0c, 0xfe, 0x1e, 0x52, + 0xf2, 0x04, 0x17, 0xf2, 0x08, 0x0d, 0x04, 0x38, 0xde, 0x0c, 0x10, 0xef, + 0xdf, 0x0f, 0x01, 0x24, 0xde, 0xe1, 0x0d, 0xfd, 0xd4, 0xf6, 0x12, 0x0e, + 0xed, 0x01, 0xf0, 0xf3, 0xfd, 0xff, 0x18, 0xf3, 0x36, 0xda, 0xf6, 0xef, + 0xe8, 0xef, 0x37, 0x27, 0x4e, 0xf8, 0xf4, 0xff, 0xe5, 0xf3, 0x32, 0x0b, + 0x36, 0x08, 0xe9, 0xf6, 0xe2, 0x13, 0x21, 0xfe, 0x12, 0xed, 0xdd, 0xfb, + 0xf8, 0x05, 0x0f, 0x03, 0x1c, 0x04, 0xfc, 0xf2, 0x23, 0x0e, 0x03, 0xfc, + 0xf9, 0x18, 0xf7, 0x01, 0x1b, 0x03, 0xf5, 0xfd, 0xde, 0xf3, 0x19, 0xfc, + 0x11, 0x02, 0xe7, 0x13, 0xde, 0xd8, 0xf2, 0x05, 0x28, 0x02, 0x02, 0x27, + 0x07, 0x08, 0xff, 0x07, 0x27, 0x0e, 0x19, 0x40, 0xfb, 0x02, 0x0c, 0xf6, + 0x0d, 0x07, 0x0f, 0x47, 0xf8, 0x05, 0x0e, 0xfd, 0x03, 0x1e, 0x07, 0x32, + 0xe7, 0xf6, 0x24, 0x01, 0x01, 0x02, 0x0a, 0xff, 0xf6, 0x26, 0x15, 0xf0, + 0x04, 0x13, 0x03, 0xfa, 0xfe, 0xf6, 0xf1, 0x09, 0x2a, 0xe6, 0xea, 0xf6, + 0x17, 0x13, 0xeb, 0xff, 0x15, 0xeb, 0x23, 0x06, 0xc8, 0xf6, 0x33, 0xeb, + 0xf4, 0xe7, 0x12, 0x2a, 0xe3, 0xe6, 0x32, 0xfa, 0x16, 0x15, 0x17, 0x40, + 0xf1, 0x08, 0x1a, 0xf3, 0xf6, 0x0c, 0x0c, 0x11, 0xd0, 0x22, 0x02, 0xee, + 0xea, 0xf4, 0xf8, 0xf9, 0x13, 0x10, 0x17, 0xf5, 0xf1, 0x0a, 0x0e, 0xfd, + 0x32, 0xda, 0xf1, 0xe2, 0xdb, 0xf2, 0x34, 0x1f, 0x53, 0xfc, 0xe4, 0xf2, + 0xf6, 0xf2, 0x1d, 0x04, 0x4a, 0xec, 0xee, 0x06, 0xdf, 0x01, 0x1a, 0x04, + 0x27, 0xfc, 0xe6, 0xfd, 0xd9, 0xfd, 0x0e, 0x00, 0x0c, 0x16, 0xf3, 0x03, + 0xf7, 0xfc, 0x0e, 0x0f, 0x09, 0x06, 0x06, 0x04, 0x08, 0x02, 0xed, 0xf5, + 0xe4, 0xe6, 0x07, 0x06, 0x03, 0x18, 0xea, 0x13, 0xe2, 0xfa, 0x10, 0xf2, + 0x02, 0xec, 0x03, 0x3c, 0xf6, 0xf6, 0x0a, 0x10, 0x09, 0xf8, 0x15, 0x24, + 0xfd, 0x0d, 0x09, 0x01, 0x00, 0xff, 0x00, 0x1a, 0xf0, 0xee, 0x08, 0x03, + 0x1d, 0x05, 0x16, 0x46, 0xe6, 0xf8, 0x08, 0x00, 0x09, 0x09, 0xff, 0x01, + 0xfc, 0x20, 0xfc, 0xec, 0x05, 0x1b, 0x03, 0xf1, 0x12, 0xe4, 0xfa, 0x24, + 0x1c, 0xf5, 0xf2, 0x05, 0x11, 0xe7, 0xfa, 0x02, 0x20, 0xea, 0x31, 0x10, + 0xcf, 0xd8, 0x33, 0xee, 0xff, 0x09, 0x20, 0x3f, 0xe2, 0x0a, 0x29, 0xee, + 0x3a, 0xf2, 0x1e, 0x39, 0x02, 0x1e, 0xfe, 0xf2, 0xef, 0xe2, 0x0d, 0x0f, + 0xf1, 0x19, 0x02, 0xe7, 0xec, 0xff, 0xfe, 0xe4, 0xfe, 0xfb, 0x02, 0xf6, + 0xf1, 0xf4, 0x07, 0x1a, 0x2a, 0xf9, 0x06, 0xf9, 0xda, 0xf4, 0x22, 0x02, + 0x4f, 0x0a, 0xf3, 0xfc, 0xf3, 0xf6, 0x25, 0x0a, 0x28, 0x01, 0xf7, 0x09, + 0xe6, 0x05, 0x28, 0xf7, 0x1e, 0xf2, 0xee, 0x13, 0xee, 0x05, 0x0f, 0x0a, + 0x09, 0xe8, 0xe8, 0x0e, 0x05, 0x12, 0x0f, 0x15, 0x02, 0xec, 0xf8, 0x02, + 0xf7, 0x05, 0xf8, 0xff, 0xdc, 0x00, 0x01, 0x00, 0x12, 0x17, 0xec, 0x19, + 0xfa, 0x09, 0xfa, 0xf3, 0x1d, 0x0b, 0x07, 0x25, 0xea, 0x0c, 0xf5, 0xfa, + 0x04, 0xf7, 0xfe, 0x33, 0xfe, 0x14, 0xef, 0x04, 0xf0, 0x00, 0x00, 0x3a, + 0xea, 0xfa, 0x10, 0x01, 0xe4, 0x00, 0xff, 0x23, 0xe9, 0x26, 0x15, 0x10, + 0x04, 0x14, 0x0d, 0x08, 0xf8, 0xfd, 0x10, 0xfb, 0x00, 0x21, 0x06, 0xfa, + 0x0f, 0x08, 0xf1, 0x09, 0x28, 0xf0, 0xd8, 0x0d, 0x08, 0x09, 0x02, 0xfb, + 0x12, 0x03, 0x0e, 0xfb, 0xce, 0xf0, 0x39, 0xe5, 0x09, 0xf6, 0x1f, 0x35, + 0xdd, 0x1c, 0x25, 0xef, 0x17, 0x0c, 0xf6, 0x3e, 0xf0, 0x21, 0x08, 0xff, + 0xd7, 0xfc, 0xfd, 0x1f, 0xe5, 0x18, 0x12, 0xe9, 0xf5, 0xe9, 0x12, 0xf6, + 0x02, 0x13, 0xf4, 0x0a, 0xfd, 0x03, 0x09, 0x08, 0x2f, 0x07, 0xee, 0xfd, + 0xd7, 0x00, 0x2b, 0x29, 0x3b, 0xdb, 0xde, 0xf1, 0xe1, 0xf7, 0x47, 0x12, + 0x35, 0x0c, 0xe4, 0x09, 0xef, 0x17, 0x2b, 0xea, 0x2d, 0xf8, 0xe8, 0x18, + 0xef, 0x03, 0x11, 0x0a, 0x10, 0xff, 0xe8, 0x07, 0x0c, 0x07, 0x03, 0x18, + 0x05, 0x08, 0xf8, 0xf8, 0x06, 0x18, 0xe9, 0xf9, 0xe0, 0x0f, 0x0d, 0x18, + 0x04, 0x01, 0xf0, 0x1c, 0xf6, 0x14, 0xfd, 0x12, 0x0c, 0x0c, 0x02, 0x34, + 0xf6, 0xe6, 0xfd, 0xf9, 0xf9, 0xfd, 0x00, 0x2a, 0xfc, 0xf9, 0xff, 0x0a, + 0xfe, 0x1b, 0xf5, 0x34, 0xdc, 0xf9, 0x15, 0x13, 0xe7, 0x1b, 0xf7, 0x25, + 0xfd, 0x09, 0x08, 0x0a, 0xf0, 0x17, 0x0f, 0x04, 0xf4, 0xe9, 0x06, 0x07, + 0xf5, 0x02, 0xfc, 0xf5, 0x09, 0xee, 0xf1, 0x07, 0x38, 0x03, 0x05, 0x0f, + 0x16, 0x0f, 0xed, 0xff, 0x21, 0xf8, 0x34, 0x07, 0xd1, 0xf9, 0x27, 0x00, + 0x0c, 0x21, 0x18, 0x42, 0xe6, 0x02, 0x1a, 0xf1, 0x2f, 0xf1, 0x0e, 0x3b, + 0xee, 0xf8, 0x08, 0xea, 0xfe, 0xf9, 0x03, 0x18, 0xf5, 0xf8, 0x0d, 0xeb, + 0x01, 0x10, 0x09, 0x02, 0x15, 0xfb, 0xf1, 0x0b, 0xf2, 0x06, 0x08, 0x09, + 0x2f, 0x19, 0x02, 0xfe, 0xe4, 0x06, 0x1f, 0x17, 0x49, 0xf2, 0xe2, 0x02, + 0xef, 0x04, 0x26, 0x16, 0x3f, 0x08, 0xf1, 0x0a, 0xfd, 0xf9, 0x28, 0x01, + 0x15, 0x0b, 0xf9, 0x10, 0xdc, 0x02, 0x20, 0xf7, 0x16, 0xe6, 0x09, 0x03, + 0xf1, 0xf5, 0x12, 0x1c, 0xfb, 0x2a, 0x08, 0xfa, 0x0a, 0x16, 0xf6, 0x15, + 0xf0, 0x06, 0x11, 0xfd, 0x0e, 0xf9, 0xf6, 0x12, 0xed, 0xf3, 0xfd, 0x1f, + 0x0b, 0xfa, 0x08, 0x30, 0xf8, 0xff, 0x0b, 0xeb, 0x10, 0xff, 0x07, 0x22, + 0x0d, 0x07, 0x09, 0x03, 0xf6, 0xf8, 0xfc, 0x26, 0xf8, 0xee, 0x11, 0x02, + 0x03, 0x0a, 0xef, 0x38, 0xfe, 0x13, 0x1b, 0x09, 0xfe, 0x06, 0x05, 0xf3, + 0x04, 0xdf, 0xfc, 0x00, 0xe7, 0x15, 0xec, 0xf1, 0xf8, 0xfc, 0xed, 0x05, + 0x0e, 0xf3, 0x15, 0x09, 0x01, 0x0d, 0xfd, 0x00, 0x24, 0xe2, 0x31, 0x13, + 0xd5, 0x1b, 0x2b, 0xe8, 0x03, 0x08, 0x1d, 0x33, 0xdc, 0xfd, 0x24, 0xe4, + 0x20, 0xfa, 0x07, 0x33, 0x01, 0x12, 0x06, 0xf5, 0xef, 0xf7, 0xfa, 0x13, + 0x01, 0xec, 0xee, 0xe0, 0xfd, 0x0d, 0xff, 0x09, 0xf6, 0x00, 0xed, 0x07, + 0xea, 0x0e, 0xff, 0x0e, 0x26, 0xfc, 0xf0, 0xe7, 0xe7, 0xfe, 0x30, 0xff, + 0x24, 0x04, 0x06, 0xf4, 0xf5, 0xf8, 0x23, 0x0e, 0x3d, 0xf2, 0xfd, 0x04, + 0xe8, 0xfb, 0x23, 0xfe, 0x33, 0xe1, 0x01, 0xfd, 0xdc, 0xfb, 0x0e, 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0x0e, 0xfb, 0xfb, 0x05, 0x07, 0x19, 0xe8, 0xe7, 0x12, 0x11, + 0x15, 0xf7, 0x0c, 0x1a, 0xf6, 0x28, 0x08, 0xeb, 0xf2, 0x25, 0xee, 0x01, + 0x03, 0xec, 0xed, 0xfa, 0xf0, 0xf2, 0xef, 0xf1, 0x02, 0x23, 0xef, 0x01, + 0x41, 0xfa, 0xf4, 0xf4, 0x15, 0xf5, 0xf5, 0xf9, 0x28, 0xde, 0x20, 0xf6, + 0xc7, 0xde, 0x21, 0xe4, 0xfe, 0xec, 0x0d, 0x2c, 0xee, 0x24, 0x10, 0xf0, + 0x1d, 0x12, 0x0e, 0x2b, 0x06, 0xf8, 0xfd, 0x01, 0x08, 0xef, 0xfd, 0x0f, + 0xeb, 0xed, 0xe1, 0xdf, 0xf1, 0xe5, 0x16, 0xe3, 0x08, 0xfc, 0xf6, 0xf6, + 0xd8, 0xf0, 0x23, 0xfc, 0x2b, 0xf5, 0xff, 0xe7, 0xf4, 0xe9, 0x29, 0x09, + 0x2b, 0x0c, 0xff, 0x08, 0x0b, 0xed, 0x29, 0x14, 0x3c, 0xf5, 0xeb, 0x18, + 0xf6, 0x10, 0x22, 0xf9, 0x17, 0x23, 0x02, 0x0c, 0xf6, 0xfa, 0x2f, 0xfe, + 0x1e, 0xeb, 0xfd, 0x03, 0xf0, 0x07, 0x1c, 0x09, 0xfa, 0xe1, 0x0d, 0x0f, + 0x18, 0x03, 0xfe, 0xf0, 0xec, 0x0b, 0x10, 0x02, 0x14, 0x06, 0xef, 0xf7, + 0xea, 0x0b, 0x05, 0xfe, 0x1f, 0x06, 0x0e, 0x07, 0x00, 0xe1, 0x01, 0x01, + 0x07, 0x05, 0x09, 0xf7, 0xef, 0x15, 0xf7, 0x12, 0x05, 0x03, 0x04, 0x1d, + 0x04, 0x10, 0x12, 0x06, 0x05, 0x00, 0x08, 0x18, 0xd6, 0xf2, 0xfa, 0x07, + 0xf8, 0x12, 0x07, 0xfd, 0xdd, 0x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xfd, 0xfa, 0xf9, 0x03, 0xf5, + 0xf4, 0xf4, 0xd5, 0xea, 0x01, 0x08, 0x22, 0xf1, 0xf2, 0x06, 0xd1, 0xe5, + 0x0c, 0xef, 0x12, 0x03, 0x08, 0x02, 0xf7, 0x05, 0x1b, 0x07, 0x39, 0x34, + 0x21, 0xe2, 0xe3, 0x0b, 0x0c, 0xf6, 0x29, 0xf7, 0x24, 0x0a, 0xfc, 0xff, + 0x1a, 0xfd, 0x05, 0xff, 0xff, 0x0e, 0x0a, 0x1a, 0x09, 0xfb, 0x15, 0x04, + 0x03, 0xf7, 0xfe, 0x00, 0xfc, 0xfb, 0x11, 0xfa, 0x1d, 0x0e, 0x06, 0xed, + 0xfc, 0x23, 0xd8, 0xf2, 0x04, 0xe5, 0x0f, 0x16, 0x29, 0xfe, 0xf5, 0xec, + 0xe2, 0x0e, 0xeb, 0x09, 0x1d, 0x11, 0x05, 0x11, 0xe4, 0x29, 0x12, 0x02, + 0x12, 0x19, 0x0e, 0x1a, 0xee, 0xf9, 0x05, 0x09, 0xf5, 0xfd, 0x05, 0x04, + 0xe4, 0xf1, 0x17, 0x01, 0xf2, 0xfe, 0x0b, 0xf4, 0x0d, 0x04, 0x06, 0xfe, + 0xff, 0xec, 0xe9, 0x00, 0xff, 0x03, 0x03, 0xfd, 0xf1, 0x15, 0xfc, 0xf3, + 0xff, 0xfe, 0x09, 0xee, 0x3c, 0x01, 0xec, 0x02, 0xf0, 0xf6, 0x20, 0xeb, + 0x16, 0x07, 0x32, 0xf3, 0xce, 0xf0, 0x02, 0xd4, 0x11, 0xe6, 0x28, 0x0e, + 0xe3, 0x21, 0xee, 0xce, 0x1e, 0xd9, 0x23, 0x26, 0x06, 0xfa, 0xf9, 0xf1, + 0x01, 0xe6, 0x0b, 0x07, 0xdc, 0x21, 0xbc, 0xe3, 0xef, 0xf8, 0x12, 0xfc, + 0xe6, 0xfe, 0xf5, 0xd4, 0x15, 0x0a, 0x00, 0x13, 0xfc, 0xec, 0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, 0xf8, + 0x14, 0x19, 0x0f, 0x0b, 0x01, 0x10, 0x09, 0x12, 0x03, 0xf5, 0x18, 0xf3, + 0xfb, 0xf5, 0x02, 0x0e, 0x0d, 0x00, 0x07, 0xfc, 0x18, 0x25, 0x0b, 0xf0, + 0xf9, 0xe6, 0x08, 0x01, 0x24, 0x14, 0xfa, 0xed, 0xe5, 0x1f, 0x09, 0xfe, + 0x08, 0xee, 0x1a, 0x1a, 0x05, 0x00, 0xff, 0x0c, 0xfe, 0xf9, 0x11, 0x11, + 0xea, 0xfe, 0x08, 0xf9, 0xf0, 0xe4, 0x01, 0x0d, 0xf1, 0x00, 0x0b, 0xea, + 0x19, 0xea, 0xf3, 0xf8, 0x08, 0x12, 0x1c, 0x1f, 0xfb, 0xef, 0xf0, 0xf2, + 0x14, 0xe1, 0x03, 0xfa, 0xf9, 0xda, 0xe9, 0xfc, 0xf3, 0xff, 0x12, 0x04, + 0xf7, 0xfc, 0x17, 0x0f, 0xfc, 0x29, 0x03, 0xe5, 0xf2, 0xee, 0x1e, 0xfa, + 0x04, 0xed, 0x25, 0xf4, 0xe1, 0x15, 0x10, 0x1e, 0xef, 0x1c, 0x04, 0xde, + 0xe5, 0x08, 0x21, 0xfd, 0xfd, 0xea, 0x03, 0xca, 0xda, 0x26, 0x00, 0x0a, + 0xfd, 0x05, 0xf0, 0xd4, 0xe1, 0x1a, 0xe4, 0xf5, 0x07, 0xe7, 0xfa, 0xdf, + 0xd4, 0x03, 0xf0, 0x10, 0x15, 0x0c, 0xf4, 0xed, 0xe3, 0xfb, 0x0f, 0x1e, + 0x16, 0x09, 0x00, 0xec, 0xea, 0x13, 0x16, 0x0b, 0x01, 0xfb, 0xff, 0x00, + 0xfb, 0x07, 0x13, 0x08, 0xf4, 0xe4, 0x12, 0x00, 0xfb, 0xfa, 0xfc, 0x08, + 0xeb, 0x19, 0x02, 0x1c, 0xe8, 0x26, 0xf3, 0x10, 0x09, 0x0f, 0x19, 0x02, + 0xfb, 0xec, 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, 0x08, 0x01, 0x06, 0xfe, 0x04, 0x08, 0xfb, 0xfb, + 0x08, 0xf4, 0xf6, 0x28, 0x10, 0xf9, 0x28, 0x0b, 0xf8, 0x0d, 0x01, 0x00, + 0xff, 0x02, 0x05, 0x08, 0xea, 0xe9, 0xf4, 0xf6, 0x01, 0xea, 0xdf, 0x1f, + 0xfe, 0x0a, 0xf9, 0xf7, 0x0c, 0x1b, 0x06, 0xed, 0xf6, 0xf2, 0x03, 0x03, + 0xfd, 0x04, 0xf5, 0x10, 0x0a, 0x0b, 0xf4, 0xf8, 0xf1, 0xe7, 0x05, 0xfe, + 0xe7, 0x0b, 0xf1, 0xec, 0xf4, 0xec, 0x06, 0xee, 0xde, 0x05, 0x1b, 0xfe, + 0x13, 0xf3, 0xd9, 0xea, 0x04, 0x10, 0x05, 0xed, 0x15, 0x02, 0x0b, 0x10, + 0xfa, 0x02, 0x05, 0x0b, 0x02, 0x07, 0xfc, 0xf5, 0x15, 0x14, 0x05, 0xf7, + 0x0c, 0xfe, 0xf6, 0xf4, 0xfa, 0x06, 0xfc, 0x13, 0xdc, 0xe4, 0x09, 0xfa, + 0x02, 0x23, 0xec, 0x06, 0x11, 0x13, 0xf8, 0xfa, 0x27, 0x28, 0x0b, 0x23, + 0xec, 0xf1, 0x09, 0x17, 0x0f, 0x13, 0xff, 0xf2, 0xfc, 0x0a, 0xf5, 0x0d, + 0x03, 0x26, 0x01, 0x0f, 0xfe, 0xf1, 0xfb, 0xe6, 0xf0, 0x02, 0xf2, 0xff, + 0x02, 0x11, 0xff, 0xfd, 0x1c, 0x02, 0x0b, 0xf6, 0x14, 0x0c, 0x0b, 0x21, + 0x28, 0xf0, 0x11, 0x05, 0x06, 0xed, 0xf9, 0x0a, 0xf2, 0xef, 0xf8, 0xf1, + 0xfe, 0x0d, 0xf9, 0xf7, 0xea, 0x00, 0x08, 0xdb, 0x02, 0x0f, 0xfe, 0x04, + 0xef, 0x20, 0x16, 0x01, 0xe8, 0xed, 0xe4, 0x22, 0xf6, 0x19, 0x00, 0x04, + 0x01, 0x13, 0xeb, 0x0d, 0xec, 0x01, 0x08, 0x05, 0x0c, 0x0e, 0xfe, 0x02, + 0x12, 0xf7, 0x27, 0xf9, 0xfd, 0x18, 0xfe, 0x24, 0xf7, 0x13, 0xed, 0x1e, + 0x09, 0xff, 0xd8, 0xf4, 0x12, 0xf8, 0x04, 0x0c, 0x1c, 0x11, 0xfd, 0x17, + 0x1d, 0x01, 0x13, 0xee, 0x11, 0xf3, 0xf8, 0x06, 0xf6, 0x16, 0xfe, 0x15, + 0x16, 0xdc, 0x1f, 0x00, 0x25, 0xee, 0xff, 0xf7, 0xf6, 0x02, 0xdd, 0x15, + 0xf1, 0x14, 0x08, 0xe8, 0xe5, 0x21, 0xea, 0xf0, 0x1a, 0x07, 0xea, 0x08, + 0xea, 0xe4, 0x1e, 0x00, 0x13, 0x17, 0xec, 0x11, 0xd6, 0x11, 0x18, 0x17, + 0x04, 0x15, 0x03, 0x3a, 0xd6, 0x02, 0x07, 0x04, 0xe6, 0xe5, 0xfe, 0x0e, + 0xff, 0xed, 0xfc, 0xfb, 0xff, 0x1c, 0x06, 0x0a, 0xfb, 0xf9, 0xea, 0x1a, + 0x21, 0xf5, 0x04, 0x06, 0x0a, 0xe3, 0x16, 0xea, 0x04, 0xe2, 0xf9, 0xf9, + 0xe6, 0xfb, 0x0f, 0xfc, 0x06, 0xfb, 0x10, 0x07, 0x07, 0x13, 0x07, 0xfc, + 0x16, 0xef, 0x07, 0xdc, 0x12, 0x1f, 0x08, 0xf4, 0xe9, 0x14, 0x06, 0xf7, + 0xf1, 0x0c, 0x01, 0x0c, 0xe6, 0x04, 0xf3, 0xf2, 0xe5, 0xf3, 0xef, 0x1d, + 0xf6, 0x20, 0x07, 0xfe, 0xf4, 0x05, 0xee, 0x10, 0xfd, 0x0e, 0x0b, 0x02, + 0x0d, 0xd8, 0x07, 0xfb, 0x26, 0x0a, 0x1c, 0x21, 0x06, 0x1f, 0xf4, 0x06, + 0x37, 0x18, 0xfa, 0x16, 0x1e, 0x24, 0xfb, 0xf0, 0x12, 0xf9, 0x02, 0x09, + 0x17, 0x16, 0xf3, 0xf9, 0x17, 0xf2, 0x02, 0x0a, 0x2d, 0xe7, 0xe3, 0x25, + 0xf0, 0xf9, 0x0f, 0xdd, 0x15, 0xe6, 0x04, 0xfc, 0xf1, 0x17, 0x0a, 0xea, + 0x24, 0x07, 0xf1, 0x11, 0x13, 0x29, 0xf4, 0xc5, 0xfb, 0x07, 0xef, 0x13, + 0x0b, 0xe1, 0xf1, 0xeb, 0xf8, 0x1b, 0x09, 0x08, 0x1f, 0x15, 0xf2, 0x05, + 0x02, 0xdd, 0x09, 0x0f, 0x16, 0x10, 0x01, 0x30, 0xf2, 0xe0, 0x27, 0xfe, + 0xf1, 0x0e, 0x0e, 0x07, 0xe6, 0x07, 0x0b, 0x18, 0xfe, 0x0f, 0x01, 0x07, + 0xf4, 0x07, 0x10, 0xe7, 0xfb, 0xf3, 0xf7, 0x0b, 0xf9, 0x15, 0x18, 0x25, + 0x0c, 0x14, 0x02, 0x08, 0x0a, 0x0f, 0x10, 0xec, 0xee, 0x1a, 0x03, 0x14, + 0x0f, 0xfa, 0x25, 0xff, 0x18, 0x0d, 0x0b, 0xea, 0x1f, 0x28, 0x10, 0x0c, + 0xe7, 0xee, 0xf7, 0xfa, 0x03, 0x15, 0x0c, 0x1d, 0x01, 0x00, 0x12, 0xee, + 0x01, 0xf1, 0xf8, 0x0b, 0xf3, 0xfd, 0x04, 0xf8, 0x02, 0x1e, 0x0e, 0xf3, + 0x02, 0x10, 0xfd, 0x07, 0x0b, 0x09, 0x03, 0x10, 0x3e, 0x08, 0x0e, 0x0c, + 0xf4, 0xe7, 0xfd, 0x1c, 0x27, 0x1a, 0xed, 0xe1, 0x08, 0xdc, 0xd9, 0xf1, + 0x1e, 0x07, 0x12, 0xf1, 0x10, 0xfb, 0xc8, 0x08, 0x0f, 0x03, 0x1d, 0xdc, + 0x23, 0x04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 0xc7, 0xff, 0x03, 0x08, + 0xfe, 0xf2, 0x19, 0xe0, 0xe4, 0x0c, 0x22, 0x1e, 0x05, 0xf7, 0x16, 0xf2, + 0xf9, 0x06, 0x17, 0xf6, 0x0c, 0x1e, 0x23, 0x08, 0xfe, 0xdc, 0xfd, 0x17, + 0x11, 0xdf, 0xf5, 0x0f, 0x01, 0x03, 0x08, 0xee, 0x1b, 0x02, 0x0b, 0x1b, + 0x0c, 0x16, 0x1a, 0x00, 0x0f, 0x26, 0x14, 0xf8, 0xf4, 0xf3, 0x19, 0x16, + 0x22, 0x0a, 0xd0, 0xf9, 0xf1, 0x05, 0x2b, 0x1e, 0x1e, 0xef, 0xf5, 0x06, + 0x05, 0xe7, 0x3f, 0x2a, 0x06, 0xf0, 0x15, 0x14, 0x13, 0x20, 0x1b, 0xde, + 0x10, 0x05, 0x33, 0xf8, 0x08, 0x04, 0x17, 0x0d, 0x0f, 0xf6, 0x01, 0xed, + 0x28, 0x25, 0x1c, 0x13, 0xfb, 0xea, 0xfb, 0xf3, 0x1c, 0xf9, 0x1f, 0xf0, + 0xfb, 0x17, 0xf8, 0xff, 0x10, 0xf7, 0x0b, 0x24, 0x04, 0x00, 0x0d, 0x0c, + 0xf7, 0x0a, 0x16, 0x13, 0xf8, 0x05, 0x0a, 0xf1, 0xf5, 0xee, 0xf8, 0x14, + 0x0e, 0xed, 0xfe, 0x1b, 0xfe, 0x17, 0x13, 0x10, 0x12, 0x21, 0x1c, 0xfa, + 0xe5, 0x0b, 0x08, 0x0c, 0x10, 0x1b, 0x03, 0xef, 0x0d, 0x05, 0x0a, 0xf0, + 0x04, 0x11, 0x15, 0x00, 0xfd, 0xef, 0x02, 0x18, 0xf4, 0x09, 0xfa, 0xf6, + 0x02, 0xf7, 0xfd, 0x13, 0xef, 0x13, 0xf7, 0xf9, 0x17, 0x0f, 0xfa, 0xf8, + 0x15, 0xff, 0x04, 0xef, 0xf0, 0x15, 0xfa, 0xfe, 0xf0, 0xf4, 0xed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, 0x0a, 0xd9, 0xf8, 0xfd, + 0xf5, 0x12, 0xff, 0x06, 0x1b, 0xe6, 0xfe, 0xfe, 0xde, 0xee, 0xf6, 0x18, + 0xf1, 0xf8, 0x06, 0xf3, 0x02, 0xea, 0x04, 0x14, 0xfc, 0xee, 0xe6, 0x09, + 0xf9, 0xee, 0xe3, 0xe7, 0xfc, 0xd9, 0xef, 0xfc, 0x0a, 0x0c, 0x03, 0xf6, + 0xe2, 0x11, 0x0f, 0x19, 0x18, 0x10, 0xef, 0xe5, 0x22, 0xf5, 0xe5, 0xe9, + 0x4b, 0xf7, 0xdb, 0x0c, 0x4f, 0xde, 0x22, 0x16, 0x09, 0x16, 0xd1, 0xf8, + 0x19, 0xe0, 0x24, 0xfe, 0xb8, 0xfb, 0xe5, 0x12, 0x1c, 0xe3, 0x22, 0x09, + 0x05, 0x29, 0xf7, 0x10, 0x31, 0xe1, 0x33, 0x3f, 0xfd, 0xed, 0x04, 0x03, + 0x2e, 0xed, 0x30, 0x36, 0xee, 0x16, 0x2f, 0xf5, 0x1b, 0xdc, 0x3a, 0x56, + 0xe5, 0xef, 0x26, 0xff, 0x03, 0xd7, 0x31, 0x16, 0xef, 0xf1, 0x08, 0x13, + 0x01, 0x02, 0x03, 0xf1, 0xf2, 0x08, 0xff, 0x05, 0x12, 0xf2, 0xee, 0xda, + 0xed, 0xec, 0xea, 0xf7, 0x0c, 0xf1, 0x09, 0xe6, 0xe6, 0x00, 0xcc, 0x10, + 0x0d, 0x0d, 0x20, 0xf4, 0x18, 0x23, 0xec, 0xf9, 0x00, 0xe4, 0x07, 0xd4, + 0xfb, 0x16, 0xd2, 0x01, 0xe6, 0x01, 0x06, 0xf0, 0xfe, 0x03, 0xf3, 0x09, + 0x01, 0x0d, 0x05, 0xf7, 0xd4, 0x02, 0xfb, 0xfb, 0x08, 0xf0, 0x1f, 0xf3, + 0xfe, 0xeb, 0x02, 0x0e, 0x1b, 0x0f, 0x04, 0xf5, 0xf0, 0x1f, 0x14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 0xed, 0x11, 0xf3, 0xe9, + 0xff, 0xde, 0x0a, 0x18, 0x0f, 0x02, 0xfb, 0xf9, 0xfb, 0xe8, 0x12, 0x18, + 0x01, 0xf4, 0xf6, 0xf8, 0xf0, 0x1f, 0x24, 0x15, 0xf5, 0x00, 0x1c, 0xf9, + 0x01, 0x0a, 0x11, 0xd5, 0x01, 0x12, 0x02, 0xec, 0xfd, 0x07, 0xf2, 0xea, + 0xf9, 0xff, 0xf7, 0xfb, 0x15, 0xec, 0xe5, 0x01, 0xeb, 0x05, 0xf9, 0x10, + 0xfe, 0x28, 0xe5, 0x0a, 0xeb, 0x1b, 0x0e, 0xf9, 0xde, 0x02, 0x15, 0x0a, + 0xff, 0xfe, 0x11, 0x24, 0x03, 0xf8, 0x00, 0x08, 0xfd, 0x0e, 0xeb, 0xf3, + 0xf6, 0xf7, 0x14, 0x0e, 0xfc, 0xf5, 0xde, 0xf5, 0x9e, 0xfe, 0xff, 0xff, + 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0xab, 0x01, 0x00, 0x00, + 0xfa, 0xfd, 0xff, 0xff, 0xa2, 0xff, 0xff, 0xff, 0xba, 0x00, 0x00, 0x00, + 0x24, 0xfc, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x54, 0x4f, 0x43, 0x4f, + 0x20, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x65, 0x64, 0x2e, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x24, 0xfb, 0xff, 0xff, + 0x68, 0x01, 0x00, 0x00, 0x5c, 0x01, 0x00, 0x00, 0x50, 0x01, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xf4, 0x00, 0x00, 0x00, + 0x90, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xce, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, 0x03, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x1a, 0xff, 0xff, 0xff, 0x00, 0x00, 0x80, 0x3f, 0x01, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, + 0x07, 0x00, 0x14, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, + 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xc4, 0xfc, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, + 0x16, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x10, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x38, 0x00, 0x00, 0x00, + 0x2c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x07, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, + 0x1a, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x07, 0x00, 0x14, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x02, 0x00, 0x00, 0x00, + 0x38, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, + 0x31, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x0a, 0x00, 0x00, 0x00, 0x34, 0x04, 0x00, 0x00, 0xcc, 0x03, 0x00, 0x00, + 0x4c, 0x03, 0x00, 0x00, 0xdc, 0x02, 0x00, 0x00, 0x60, 0x02, 0x00, 0x00, + 0x20, 0x02, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x44, 0x01, 0x00, 0x00, + 0x70, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0xfc, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x09, 0x44, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x28, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xf4, 0xfb, 0xff, 0xff, + 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x3b, 0x0e, 0x00, 0x00, 0x00, 0x6c, 0x61, 0x62, 0x65, + 0x6c, 0x73, 0x5f, 0x73, 0x6f, 0x66, 0x74, 0x6d, 0x61, 0x78, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0e, 0x00, 0x1a, 0x00, 0x08, 0x00, 0x07, 0x00, 0x0c, 0x00, + 0x10, 0x00, 0x14, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, + 0xb4, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, + 0x12, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x11, 0x1e, 0x23, 0x3a, 0x9e, 0xa1, 0x15, 0x39, + 0x23, 0x69, 0x45, 0x3a, 0x09, 0xe4, 0xe4, 0x39, 0x65, 0xd7, 0x13, 0x3a, + 0xe0, 0xb2, 0xfd, 0x39, 0x1b, 0xc1, 0x53, 0x3a, 0xc2, 0x50, 0x2d, 0x3a, + 0x12, 0x00, 0x00, 0x00, 0x66, 0x69, 0x72, 0x73, 0x74, 0x5f, 0x77, 0x65, + 0x69, 0x67, 0x68, 0x74, 0x73, 0x2f, 0x72, 0x65, 0x61, 0x64, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x3a, 0xfd, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x09, 0x54, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x28, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x2c, 0xfd, 0xff, 0xff, + 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0xb5, 0xfa, 0xfa, 0x39, 0x1f, 0x00, 0x00, 0x00, 0x66, 0x69, 0x6e, 0x61, + 0x6c, 0x5f, 0x66, 0x63, 0x5f, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x73, + 0x2f, 0x72, 0x65, 0x61, 0x64, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, + 0x6f, 0x73, 0x65, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xa0, 0x0f, 0x00, 0x00, 0xa2, 0xfd, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, + 0x58, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x74, 0xfe, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xf2, 0xdd, 0xbb, 0x3d, + 0x01, 0x00, 0x00, 0x00, 0x32, 0xa3, 0x25, 0x41, 0x01, 0x00, 0x00, 0x00, + 0xf6, 0xa0, 0x50, 0xc1, 0x05, 0x00, 0x00, 0x00, 0x61, 0x64, 0x64, 0x5f, + 0x31, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x0e, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, + 0x2c, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x0f, 0x00, 0x00, 0x00, 0x52, 0x65, 0x73, 0x68, 0x61, 0x70, 0x65, 0x5f, + 0x32, 0x2f, 0x73, 0x68, 0x61, 0x70, 0x65, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x4a, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, + 0x5c, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x1c, 0xff, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x50, 0x50, 0xd0, 0x3d, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0xcf, 0x41, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x52, 0x65, 0x73, 0x68, + 0x61, 0x70, 0x65, 0x5f, 0x32, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xc2, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, + 0x58, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x94, 0xff, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x50, 0x50, 0xd0, 0x3d, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x80, 0xcf, 0x41, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x52, 0x65, 0x73, 0x68, 0x61, 0x70, 0x65, 0x5f, + 0x31, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0xa8, 0x07, 0x00, 0x00, 0x2e, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, + 0x60, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x14, 0x00, 0x04, 0x00, 0x08, 0x00, + 0x0c, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x3a, 0x6a, 0xac, 0x3d, 0x01, 0x00, 0x00, 0x00, + 0xd0, 0xbd, 0xab, 0x41, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x52, 0x65, 0x6c, 0x75, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0xaa, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x02, 0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x2c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x9c, 0xff, 0xff, 0xff, + 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x96, 0x08, 0x29, 0x38, 0x0b, 0x00, 0x00, 0x00, + 0x4d, 0x61, 0x74, 0x4d, 0x75, 0x6c, 0x5f, 0x62, 0x69, 0x61, 0x73, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, + 0x18, 0x00, 0x08, 0x00, 0x07, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xa0, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x9a, 0xbb, 0x84, 0x38, 0x83, 0x84, 0x73, 0x37, 0x5b, 0xa3, 0xa0, 0x38, + 0x16, 0x41, 0x3a, 0x38, 0xc7, 0x9a, 0x70, 0x38, 0xed, 0x70, 0x4e, 0x38, + 0x54, 0x4f, 0xac, 0x38, 0xfd, 0x07, 0x8d, 0x38, 0x0b, 0x00, 0x00, 0x00, + 0x43, 0x6f, 0x6e, 0x76, 0x32, 0x44, 0x5f, 0x62, 0x69, 0x61, 0x73, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x4c, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xe6, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x19, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x06, 0x00, 0x05, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x16, 0x0a, 0x00, 0x0e, 0x00, 0x07, 0x00, + 0x00, 0x00, 0x08, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x07, 0x00, + 0x00, 0x00, 0x08, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, + 0x03, 0x00, 0x00, 0x00 +}; +const int g_model_len = 18712; diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/model.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/model.h new file mode 100644 index 00000000..8979c20d --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/model.h @@ -0,0 +1,27 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// This is a standard TensorFlow Lite FlatBuffer model file that has been +// converted into a C data array, so it can be easily compiled into a binary +// for devices that don't have a file system. It was created using the command: +// xxd -i model.tflite > model.cc + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MODEL_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MODEL_H_ + +extern const unsigned char g_model[]; +extern const int g_model_len; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MODEL_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/no_feature_data_slice.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/no_feature_data_slice.cc new file mode 100644 index 00000000..8168acdc --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/no_feature_data_slice.cc @@ -0,0 +1,61 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// See the header for documentation on the meaning of this data. + +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/no_feature_data_slice.h" + +const int8_t g_no_feature_data_slice[g_no_feature_data_slice_size] = { + 89, + 68, + 96, + 83, + 111, + 96, + 115, + 87, + 99, + 76, + 105, + 84, + 105, + 86, + 113, + 91, + 108, + 87, + 110, + 78, + 80, + 46, + 22, + 74, + 88, + 72, + 103, + 86, + 80, + 68, + 48, + 24, + 68, + 48, + 55, + 36, + 108, + 90, + 90, + 63, +}; diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/no_feature_data_slice.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/no_feature_data_slice.h new file mode 100644 index 00000000..33598a99 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/no_feature_data_slice.h @@ -0,0 +1,29 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// This data was extracted from the larger feature data held in +// no_features_data.cc and consists of the 29th spectrogram slice of 43 values. +// This is the expected result of running the sample data in +// no_30ms_sample_data.cc through the preprocessing pipeline. + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_NO_FEATURE_DATA_SLICE_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_NO_FEATURE_DATA_SLICE_H_ + +#include + +constexpr int g_no_feature_data_slice_size = 40; +extern const int8_t g_no_feature_data_slice[]; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_NO_FEATURE_DATA_SLICE_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/no_micro_features_data.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/no_micro_features_data.cc new file mode 100644 index 00000000..0b7dd40b --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/no_micro_features_data.cc @@ -0,0 +1,1984 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/no_micro_features_data.h" + +// Golden test values for the expected spectrogram from a "no" sample file +// speech_commands_test_set_v0.02/no/f9643d42_nohash_4.wav. + +const int g_no_micro_f9643d42_nohash_4_width = 40; +const int g_no_micro_f9643d42_nohash_4_height = 49; +const signed char g_no_micro_f9643d42_nohash_4_data[] = { + 103, + 78, + 64, + 76, + 75, + 54, + 53, + 67, + 77, + 60, + 56, + 70, + 76, + 71, + 68, + 58, + 74, + 32, + 23, + -2, + -18, + 11, + 13, + 15, + 9, + 20, + 5, + -7, + -18, + -2, + -10, + -18, + -10, + -12, + 9, + 7, + -33, + -12, + -4, + -18, + 57, + 17, + 55, + 62, + 70, + 45, + 61, + 37, + 67, + 52, + 48, + 47, + 55, + 46, + 57, + 47, + 73, + 17, + 27, + 20, + 19, + 8, + 15, + -6, + -1, + 10, + -12, + -29, + -6, + -23, + -18, + -3, + -1, + 5, + 3, + -4, + -12, + -8, + -1, + -14, + 65, + 48, + 58, + 43, + 48, + 19, + 39, + 39, + 57, + 57, + 58, + 55, + 67, + 58, + 49, + 50, + 70, + 27, + 9, + 16, + 37, + 4, + 25, + 4, + 11, + 9, + 7, + -33, + -7, + -12, + 3, + -6, + -29, + -7, + -7, + -18, + -12, + -18, + -2, + -1, + 0, + 31, + 60, + -8, + 51, + 59, + 70, + 40, + 71, + 57, + 52, + 38, + 66, + 48, + 17, + 6, + 59, + 8, + 15, + 7, + 18, + 4, + 18, + -23, + -8, + -4, + -3, + -12, + -3, + -26, + 1, + 10, + 2, + -29, + -29, + -37, + -7, + -4, + 6, + -33, + 67, + 44, + 59, + -4, + 64, + 51, + 68, + 55, + 74, + 9, + 40, + 15, + 57, + 33, + 60, + 18, + 40, + 25, + 27, + -20, + 25, + -16, + 6, + 17, + -10, + -12, + -23, + -43, + -23, + -23, + -29, + -37, + -4, + -16, + -16, + -60, + -20, + -23, + -10, + -29, + -12, + 15, + 12, + -37, + 27, + 15, + 61, + 44, + 50, + 8, + 48, + 22, + 49, + -18, + 46, + 33, + 42, + 34, + 46, + -8, + 4, + -18, + -43, + -43, + -10, + 1, + -10, + -16, + -10, + -77, + -16, + -33, + 11, + -26, + -23, + -37, + 0, + -8, + -16, + -29, + 42, + 40, + 68, + 24, + 47, + 46, + 53, + -128, + 30, + 2, + 42, + 21, + 21, + -4, + 43, + 2, + 43, + 5, + 32, + -26, + 7, + -37, + -43, + -23, + -2, + -8, + 2, + -37, + -50, + -60, + -1, + -7, + -33, + -77, + -6, + -18, + -16, + -50, + -12, + -33, + 53, + 8, + 52, + 18, + 51, + 35, + 69, + 26, + 44, + 8, + 27, + -128, + 21, + -33, + 17, + -14, + 38, + -128, + -14, + -18, + 17, + -20, + -14, + -37, + 8, + -60, + -33, + -33, + -33, + -43, + -12, + -29, + -12, + -128, + -33, + -60, + -26, + -77, + -26, + -50, + 57, + 29, + 11, + 30, + 53, + -10, + 45, + 15, + 18, + -10, + 42, + 2, + 31, + -29, + 10, + -4, + 42, + -37, + -50, + -128, + -4, + -43, + -20, + -77, + -14, + -26, + -33, + -128, + -12, + -43, + -8, + -33, + -33, + -60, + -43, + -77, + -12, + -60, + -26, + -50, + 40, + -23, + 36, + 35, + 50, + -2, + 37, + 27, + 26, + -77, + 49, + -7, + 28, + -43, + 6, + 11, + 41, + -37, + 33, + -26, + -14, + -12, + -6, + -33, + -16, + -26, + -20, + -77, + -14, + -43, + -8, + -50, + -14, + -37, + -26, + -77, + -26, + -77, + -14, + -29, + 50, + -60, + 25, + -26, + 57, + 38, + 51, + 1, + 50, + 1, + 53, + -18, + 30, + -23, + 11, + -128, + 18, + -43, + 20, + -26, + -10, + -26, + -12, + -128, + -50, + -60, + -37, + -77, + -20, + -43, + -50, + -128, + -77, + -128, + -77, + -128, + -33, + -77, + -20, + -60, + 53, + -10, + -37, + -128, + 10, + -128, + 60, + 18, + -8, + 13, + 37, + -37, + 8, + -128, + 3, + -77, + 32, + -29, + 14, + 10, + -12, + -77, + -37, + -77, + -37, + -60, + -23, + -128, + -43, + -50, + -16, + -77, + -6, + -33, + 0, + -60, + -43, + -128, + -16, + -60, + 20, + -2, + 51, + 19, + 43, + 2, + 63, + 20, + 60, + -4, + 42, + -50, + 4, + -128, + 2, + -3, + 32, + -33, + -26, + -128, + -18, + -128, + -33, + -43, + -7, + -60, + -50, + -77, + -29, + -77, + -23, + -128, + -16, + -26, + -23, + -60, + -37, + -77, + -37, + -128, + -1, + -33, + 39, + 48, + 60, + 5, + 8, + -128, + 44, + 11, + 4, + 0, + 13, + -77, + -2, + -20, + 33, + -128, + -33, + -77, + -8, + -128, + -14, + -128, + -33, + -18, + -12, + -77, + -16, + -128, + -37, + -128, + -12, + -77, + -60, + -128, + -23, + -60, + -23, + -128, + 36, + -50, + 46, + -128, + 66, + 39, + 18, + -14, + -12, + -77, + -20, + -6, + 24, + -128, + 28, + -26, + 21, + -77, + -6, + -33, + 1, + -128, + -43, + -128, + -1, + -50, + -37, + -128, + -50, + -128, + -33, + -128, + -18, + -128, + -60, + -8, + -7, + -60, + -60, + -128, + -6, + -29, + 20, + -1, + 73, + 40, + -43, + -14, + 33, + -43, + 33, + -3, + 15, + -29, + 29, + -43, + 20, + -60, + -29, + -128, + -20, + -26, + 4, + -77, + -16, + -60, + -33, + -50, + -29, + -128, + -60, + -128, + -77, + -128, + -37, + -50, + 0, + -77, + -33, + -128, + 39, + 8, + 47, + 10, + 62, + 16, + 2, + 1, + 10, + 7, + 4, + -7, + 6, + -128, + -77, + -50, + 19, + -77, + -77, + -128, + -77, + -128, + -50, + -128, + -60, + -60, + -33, + -50, + -37, + -128, + -128, + -128, + -60, + -128, + -37, + -60, + -18, + -128, + -33, + -77, + 37, + 23, + 29, + -128, + -128, + -128, + -16, + -128, + -16, + -33, + 21, + -20, + -8, + -60, + -2, + -60, + 11, + -128, + -50, + -128, + -50, + -128, + -29, + -77, + -16, + -128, + -26, + -128, + -50, + -77, + -43, + -128, + -128, + -128, + -50, + -128, + -33, + -128, + -33, + -50, + -23, + -128, + 24, + -128, + -128, + -77, + 4, + -23, + 32, + -128, + 1, + -26, + -14, + -128, + 10, + -77, + -4, + -128, + 1, + -50, + -8, + -77, + -77, + -77, + -23, + -128, + -50, + -43, + -33, + -128, + -43, + -128, + -128, + -128, + -43, + -128, + -50, + -128, + -128, + -128, + 44, + 15, + 14, + -128, + 9, + -128, + 21, + 0, + 29, + -7, + 18, + -7, + -7, + -128, + -33, + -50, + 14, + -60, + -60, + -128, + -60, + -128, + -37, + -128, + -43, + -128, + -20, + -128, + -50, + -128, + -43, + -77, + -26, + -128, + -60, + -50, + -60, + -128, + -77, + -128, + -3, + -128, + 14, + -77, + -26, + 11, + 47, + -77, + -7, + -77, + 45, + -43, + -12, + 14, + 37, + -60, + 22, + -4, + 5, + -77, + -14, + -128, + -10, + -60, + 22, + -77, + -12, + -60, + -50, + -128, + -60, + -128, + -60, + -128, + -43, + -128, + -50, + -128, + -77, + -50, + 27, + -37, + 33, + -128, + 4, + -29, + -4, + -50, + -20, + -128, + 6, + -37, + -33, + -128, + -50, + -128, + 34, + 15, + -43, + -128, + -20, + -50, + -3, + -37, + -37, + -77, + -77, + -128, + -43, + -128, + -128, + -128, + 4, + -26, + -26, + 27, + 0, + -128, + -29, + -60, + 35, + -26, + 23, + -128, + -29, + -77, + 19, + 14, + 28, + -128, + -16, + -7, + 31, + -1, + 17, + 11, + 60, + 44, + 8, + 11, + 18, + -128, + -33, + -60, + -1, + -128, + -43, + -128, + -23, + -128, + -128, + -128, + 59, + 43, + 35, + 61, + 37, + -77, + -77, + -50, + 116, + 88, + 98, + 69, + 78, + 53, + 78, + 40, + 48, + 7, + 29, + -18, + -2, + -14, + 5, + 12, + 65, + 35, + 31, + -12, + 33, + -2, + -6, + -1, + 44, + -29, + -14, + -60, + -4, + -43, + -37, + -128, + 29, + 18, + 38, + 51, + 8, + -128, + -12, + -37, + 115, + 91, + 113, + 77, + 89, + 36, + 60, + 44, + 49, + 36, + 27, + 31, + 63, + 30, + 62, + 14, + 55, + 49, + 42, + 0, + 45, + 17, + -23, + 1, + 30, + -37, + -50, + -77, + -8, + -60, + 9, + -60, + -12, + -50, + 13, + 4, + 23, + -6, + 28, + 13, + 107, + 78, + 101, + 73, + 89, + 46, + 63, + 17, + 34, + -43, + -6, + 30, + 67, + 40, + 77, + 21, + 53, + 39, + 38, + 12, + -6, + 5, + 28, + -2, + 18, + -43, + 0, + -128, + -29, + -77, + 18, + -128, + -2, + -77, + 39, + 35, + 38, + 35, + 50, + 29, + 100, + 70, + 94, + 69, + 86, + 50, + 45, + 38, + 45, + 12, + 58, + 64, + 74, + 36, + 77, + 45, + 78, + 62, + 8, + -60, + 38, + 6, + 21, + 7, + 8, + -37, + -1, + -20, + 48, + -37, + 8, + -10, + 8, + 13, + 45, + 39, + 38, + 22, + 49, + 25, + 94, + 63, + 87, + 66, + 84, + -128, + 29, + 20, + 55, + 51, + 80, + 36, + 62, + 30, + 81, + 72, + 68, + 37, + 51, + 27, + 54, + 22, + 16, + -29, + 4, + 9, + 57, + 15, + 35, + -43, + -77, + -20, + 4, + 6, + 37, + -1, + 40, + 31, + 47, + 14, + 89, + 68, + 96, + 83, + 111, + 96, + 115, + 87, + 99, + 76, + 105, + 84, + 105, + 86, + 113, + 91, + 108, + 87, + 110, + 78, + 80, + 46, + 22, + 74, + 88, + 72, + 103, + 86, + 80, + 68, + 48, + 24, + 68, + 48, + 55, + 36, + 108, + 90, + 90, + 63, + 83, + 63, + 87, + 64, + 90, + 92, + 113, + 88, + 102, + 79, + 109, + 83, + 100, + 89, + 109, + 60, + 56, + 21, + 75, + 62, + 81, + 45, + 63, + 73, + 93, + 65, + 94, + 80, + 89, + 81, + 73, + 3, + 43, + 60, + 102, + 70, + 84, + 67, + 99, + 74, + 78, + 57, + 79, + 50, + 93, + 82, + 98, + 56, + 77, + 70, + 91, + 71, + 85, + 82, + 86, + 13, + 45, + -18, + 48, + 40, + 53, + 28, + 85, + 60, + 65, + 52, + 86, + 78, + 76, + 46, + 73, + 19, + 35, + 54, + 75, + 40, + 71, + 60, + 82, + 37, + 69, + 42, + 62, + 40, + 96, + 70, + 85, + 77, + 70, + 68, + 103, + 84, + 94, + 69, + 81, + -128, + -128, + -128, + -43, + -37, + 40, + 2, + 48, + 45, + 76, + 37, + 65, + 16, + 43, + 18, + 58, + 20, + 27, + 12, + 71, + 31, + 53, + 44, + 88, + 47, + 50, + 33, + 39, + 8, + 89, + 57, + 88, + 69, + 72, + 63, + 100, + 68, + 81, + -77, + -10, + -128, + -128, + -128, + -128, + -128, + 13, + -77, + 8, + 27, + 60, + 28, + 41, + -128, + -37, + -128, + 28, + -43, + -18, + -128, + 47, + -37, + 45, + 27, + 51, + -29, + 15, + 39, + 52, + 30, + 49, + -33, + 65, + 15, + 76, + 71, + 90, + 19, + 46, + -128, + -16, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -18, + -128, + -20, + -128, + 32, + -128, + 21, + -33, + 45, + -128, + -128, + -128, + -12, + -128, + -6, + -14, + 43, + -128, + -128, + -128, + -128, + -128, + 52, + -18, + 69, + -43, + 78, + 55, + 42, + -128, + -29, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + 14, + -128, + -16, + -128, + -128, + -128, + 7, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + 12, + -128, + -128, + -128, + -128, + -16, + 59, + -50, + 35, + -128, + 42, + 0, + 47, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -33, + -128, + -23, + -128, + -128, + -128, + -23, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -33, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -8, + -128, + 36, + -50, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -37, + -128, + -128, + -60, + -10, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + 21, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -12, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -77, + -128, + -128, + -128, + -29, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -29, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -50, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, +}; diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/no_micro_features_data.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/no_micro_features_data.h new file mode 100644 index 00000000..e86826f3 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/no_micro_features_data.h @@ -0,0 +1,23 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_NO_MICRO_FEATURES_DATA_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_NO_MICRO_FEATURES_DATA_H_ + +extern const int g_no_micro_f9643d42_nohash_4_width; +extern const int g_no_micro_f9643d42_nohash_4_height; +extern const signed char g_no_micro_f9643d42_nohash_4_data[]; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_NO_MICRO_FEATURES_DATA_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/static_alloc.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/static_alloc.h new file mode 100644 index 00000000..f64e49db --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/static_alloc.h @@ -0,0 +1,33 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_STATIC_ALLOC_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_STATIC_ALLOC_H_ + +// Checks to ensure that the C-style array passed in has a compile-time size of +// at least the number of bytes requested. This doesn't work with raw pointers +// since sizeof() doesn't know their actual length, so only use this to check +// statically-allocated arrays with known sizes. +#define STATIC_ALLOC_ENSURE_ARRAY_SIZE(A, N) \ + do { \ + if (sizeof(A) < (N)) { \ + TF_LITE_REPORT_ERROR(error_reporter, \ + #A " too small (%d bytes, wanted %d) at %s:%d", \ + sizeof(A), (N), __FILE__, __LINE__); \ + return 0; \ + } \ + } while (0) + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_STATIC_ALLOC_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/yes_feature_data_slice.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/yes_feature_data_slice.cc new file mode 100644 index 00000000..4acf4001 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/yes_feature_data_slice.cc @@ -0,0 +1,61 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// See the header for documentation on the meaning of this data. + +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/yes_feature_data_slice.h" + +const int8_t g_yes_feature_data_slice[g_yes_feature_data_slice_size] = { + 86, + 88, + 108, + 75, + 108, + 76, + 98, + 64, + 75, + 61, + 71, + 66, + 85, + -1, + -77, + -128, + 46, + 61, + 92, + 69, + 100, + 93, + 113, + 80, + 108, + 93, + 113, + 91, + 110, + 80, + 85, + 15, + -33, + -128, + 12, + -50, + 34, + 50, + 70, + 55, +}; diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/yes_feature_data_slice.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/yes_feature_data_slice.h new file mode 100644 index 00000000..90530283 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/yes_feature_data_slice.h @@ -0,0 +1,29 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// This data was extracted from the larger feature data held in +// no_micro_features_data.cc and consists of the 26th spectrogram slice of 40 +// values. This is the expected result of running the sample data in +// yes_30ms_sample_data.cc through the preprocessing pipeline. + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_YES_FEATURE_DATA_SLICE_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_YES_FEATURE_DATA_SLICE_H_ + +#include + +constexpr int g_yes_feature_data_slice_size = 40; +extern const int8_t g_yes_feature_data_slice[]; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_YES_FEATURE_DATA_SLICE_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/yes_micro_features_data.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/yes_micro_features_data.cc new file mode 100644 index 00000000..bb22bc7b --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/yes_micro_features_data.cc @@ -0,0 +1,1984 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/yes_micro_features_data.h" + +// Golden test values for the expected spectrogram from a "yes" sample file +// speech_commands_test_set_v0.02/yes/f2e59fea_nohash_1.wav. + +const int g_yes_micro_f2e59fea_nohash_1_width = 40; +const int g_yes_micro_f2e59fea_nohash_1_height = 49; +const signed char g_yes_micro_f2e59fea_nohash_1_data[] = { + 116, + 98, + 118, + 95, + 106, + 85, + 101, + 81, + 67, + -18, + -33, + -12, + -26, + -128, + 9, + 34, + 56, + 45, + 9, + -12, + 5, + 30, + 23, + 28, + 0, + -18, + 0, + -128, + -60, + -50, + -50, + -37, + -60, + -60, + -50, + -26, + -33, + -50, + -33, + -50, + 83, + 61, + 81, + 55, + 76, + 61, + 73, + 64, + 38, + -8, + -37, + -20, + -18, + -20, + 48, + 29, + 52, + 41, + 55, + 18, + 25, + 37, + 44, + 37, + 8, + 15, + -6, + -60, + -128, + -50, + -37, + -37, + -18, + -37, + -26, + -29, + -37, + -60, + -50, + -60, + 95, + 59, + 52, + -4, + 54, + -18, + 68, + 43, + 31, + -18, + -26, + -33, + -37, + -29, + 33, + 7, + -3, + 8, + 26, + 24, + 36, + 6, + 36, + 23, + 14, + 8, + -29, + -37, + -37, + -37, + -50, + -50, + -26, + -8, + -26, + -37, + -18, + -37, + -60, + -77, + 50, + 48, + 83, + 44, + 56, + -128, + -33, + -60, + 1, + -26, + -60, + -43, + -14, + -23, + -18, + -43, + -26, + -33, + 13, + -77, + -43, + -77, + -33, + -37, + 16, + -12, + -37, + -50, + -50, + -77, + -20, + -43, + -60, + -128, + -60, + -77, + -37, + -77, + -60, + -128, + 37, + -10, + 65, + -7, + 28, + -128, + 10, + -77, + -37, + -128, + -77, + -128, + -77, + -43, + -128, + -128, + -77, + -128, + -128, + -128, + -128, + -128, + -14, + -128, + -43, + -50, + -37, + -77, + -128, + -128, + -77, + -43, + -29, + -43, + -20, + -60, + -37, + -43, + -50, + -128, + -77, + -128, + -18, + -128, + -60, + -128, + -128, + -128, + -77, + -128, + -77, + -128, + -128, + -128, + -60, + -37, + -20, + -128, + -60, + -128, + -128, + -128, + -60, + -128, + -77, + -60, + -128, + -50, + -60, + -128, + -77, + -128, + -50, + -60, + -37, + -60, + -50, + -77, + -77, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -37, + -128, + -128, + -128, + -128, + -128, + -77, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -77, + -60, + -128, + -128, + -50, + -128, + -50, + -128, + -50, + -128, + -77, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -77, + -128, + -77, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -77, + -128, + -77, + -128, + -77, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -77, + -128, + -128, + -128, + -128, + -77, + -50, + -128, + -128, + -77, + -77, + -128, + -128, + -128, + -50, + -128, + 85, + 43, + 65, + 53, + 69, + 60, + 45, + 3, + 46, + -12, + 9, + -23, + 32, + -1, + -128, + -128, + -128, + -128, + -1, + 37, + 38, + 33, + 43, + 36, + 58, + 70, + 68, + 39, + 6, + 10, + 32, + 6, + 8, + -23, + -77, + -128, + -29, + -128, + -77, + -128, + 101, + 87, + 102, + 91, + 110, + 88, + 101, + 83, + 110, + 95, + 111, + 83, + 81, + 84, + 106, + 90, + 93, + 82, + 98, + 91, + 108, + 95, + 118, + 97, + 118, + 97, + 116, + 96, + 113, + 90, + 110, + 96, + 107, + 85, + 94, + 66, + 69, + 36, + 29, + 0, + 100, + 60, + 105, + 68, + 92, + 93, + 113, + 92, + 107, + 85, + 107, + 83, + 104, + 91, + 105, + 85, + 112, + 88, + 101, + 80, + 101, + 79, + 96, + 80, + 98, + 80, + 105, + 83, + 98, + 81, + 103, + 71, + 100, + 79, + 83, + 78, + 91, + 47, + 50, + 13, + 108, + 81, + 93, + 78, + 98, + 76, + 105, + 76, + 98, + 40, + 77, + 72, + 81, + 62, + 93, + 77, + 96, + 80, + 98, + 61, + 97, + 69, + 88, + 61, + 71, + 56, + 98, + 68, + 97, + 72, + 89, + 51, + 81, + 61, + 88, + 75, + 86, + 56, + 48, + 13, + 71, + 22, + 84, + 66, + 76, + -7, + 48, + 61, + 77, + 62, + 91, + 65, + 95, + 74, + 88, + 59, + 75, + 58, + 83, + 55, + 87, + 55, + 76, + 43, + 76, + -3, + 56, + 60, + 79, + 57, + 71, + 54, + 82, + 33, + 74, + 71, + 91, + 45, + 18, + -7, + 61, + 56, + 77, + 41, + 73, + 42, + 82, + 49, + 59, + 63, + 82, + 65, + 66, + 38, + 83, + 34, + 48, + -8, + 46, + 20, + 54, + 33, + 54, + 6, + 48, + 16, + 60, + 37, + 58, + 22, + 58, + 14, + 65, + 53, + 75, + -4, + 42, + 16, + 16, + -50, + 22, + -128, + 80, + 54, + 43, + -50, + 42, + -128, + -10, + -77, + 28, + -29, + 68, + 43, + 73, + 2, + 25, + -60, + 47, + 14, + 45, + 7, + 66, + 4, + 62, + 37, + 71, + 7, + 46, + -10, + 44, + 22, + 55, + 53, + 57, + -29, + 26, + -10, + -3, + -128, + 38, + -128, + 46, + -10, + 16, + -128, + -10, + -26, + 60, + -7, + 65, + 38, + 70, + -60, + 35, + -8, + 42, + -29, + 6, + -128, + 34, + -128, + 36, + -60, + 44, + -12, + -2, + -128, + -7, + -60, + -60, + -128, + -23, + -128, + 31, + -33, + 22, + -77, + -37, + -43, + -128, + -128, + 3, + -128, + -23, + -128, + 17, + -77, + 43, + -77, + -7, + -128, + -20, + -128, + 17, + -43, + 32, + -128, + -43, + -128, + -128, + -77, + 21, + -128, + -50, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -37, + -128, + -16, + -128, + -50, + -26, + -6, + -128, + -128, + -128, + -128, + -128, + -23, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -16, + -128, + 36, + -7, + 16, + -128, + -128, + -128, + -128, + -128, + -77, + -128, + -37, + -128, + -50, + -128, + -128, + -128, + -128, + -128, + -18, + -128, + 11, + -128, + -16, + -77, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -26, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -20, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -50, + -128, + -77, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -77, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -1, + -18, + 5, + -128, + 40, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + 4, + -128, + 63, + 66, + 75, + -128, + 70, + 60, + 34, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + 87, + 86, + 95, + 76, + 91, + 62, + 72, + -6, + -50, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + 64, + 83, + 104, + 70, + 98, + 90, + 111, + 89, + 109, + 80, + 71, + -128, + -128, + -128, + -128, + -128, + -20, + -6, + 27, + 33, + 86, + 88, + 108, + 75, + 108, + 76, + 98, + 64, + 75, + 61, + 71, + 66, + 85, + -1, + -77, + -128, + 46, + 61, + 92, + 69, + 100, + 93, + 113, + 80, + 108, + 93, + 113, + 91, + 110, + 80, + 85, + 15, + -33, + -128, + 12, + -50, + 34, + 50, + 70, + 55, + 84, + 72, + 108, + 81, + 111, + 88, + 100, + 80, + 84, + 73, + 97, + 86, + 99, + 65, + 85, + 43, + 96, + 78, + 107, + 94, + 118, + 98, + 115, + 92, + 118, + 94, + 111, + 93, + 111, + 86, + 99, + 52, + 32, + -16, + 48, + 31, + 81, + 74, + 85, + 64, + 78, + 64, + 98, + 70, + 110, + 92, + 96, + 73, + 100, + 72, + 94, + 73, + 98, + 76, + 85, + 67, + 101, + 83, + 101, + 83, + 112, + 89, + 98, + 85, + 105, + 78, + 98, + 72, + 102, + 80, + 95, + 23, + 19, + -8, + 52, + 57, + 103, + 91, + 95, + 65, + 74, + 8, + 77, + 49, + 96, + 76, + 100, + 87, + 105, + 81, + 94, + 62, + 94, + 78, + 81, + 72, + 99, + 82, + 101, + 78, + 108, + 65, + 82, + 70, + 100, + 63, + 79, + 58, + 80, + 59, + 87, + 48, + 50, + 57, + 93, + 67, + 86, + 80, + 103, + 56, + 77, + 31, + 81, + 57, + 62, + 41, + 96, + 85, + 91, + 71, + 101, + 76, + 89, + 78, + 95, + 76, + 96, + 79, + 103, + 81, + 103, + 48, + 70, + 57, + 88, + 66, + 84, + 11, + 85, + 67, + 104, + 37, + 38, + 67, + 90, + 54, + 81, + 62, + 90, + 52, + 78, + -60, + 54, + -8, + 68, + 40, + 55, + 8, + 77, + 52, + 66, + 31, + 55, + 13, + 60, + 26, + 69, + 42, + 63, + -29, + 57, + -128, + -3, + -128, + 3, + -128, + -29, + -60, + 52, + -43, + 63, + 56, + 86, + 75, + 95, + 75, + 85, + 63, + 82, + 10, + 50, + -128, + 31, + -77, + 0, + -77, + -23, + -128, + 12, + -77, + 51, + -3, + 58, + -14, + 44, + 0, + 48, + 4, + 53, + 47, + 28, + -128, + -128, + -128, + -37, + -128, + -3, + -128, + 49, + 61, + 100, + 90, + 117, + 88, + 107, + 94, + 112, + 64, + 96, + 83, + -128, + -128, + 7, + -128, + -77, + -128, + -23, + -128, + -23, + -128, + 16, + -37, + 65, + -8, + 48, + 20, + 14, + -77, + 57, + -18, + -43, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + 24, + 12, + 74, + 76, + 105, + 76, + 99, + 80, + 108, + 79, + 103, + 85, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + 42, + -128, + -8, + -128, + -50, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -60, + -128, + -128, + 5, + 73, + 53, + 93, + 70, + 101, + 73, + 94, + 57, + 86, + 66, + -18, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -50, + -128, + 36, + -128, + -128, + -128, + -128, + -128, + -20, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + 23, + 37, + 75, + 54, + 97, + 70, + 83, + 52, + 85, + 65, + 7, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -43, + -128, + 23, + -128, + -43, + -128, + -33, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -26, + -37, + 65, + 33, + 76, + 37, + 73, + 50, + 77, + 47, + -12, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -7, + -14, + -4, + -128, + -14, + -128, + 18, + -60, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -26, + -60, + 71, + 42, + 68, + 53, + 81, + 49, + 73, + 36, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -18, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + 15, + -26, + 44, + -18, + 59, + 39, + 57, + 20, + 62, + 26, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + 49, + -128, + 30, + 8, + 69, + 27, + 62, + 38, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -43, + -128, + 28, + -37, + 48, + -10, + 48, + 11, + 74, + 37, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -77, + -128, + 11, + -128, + -7, + -60, + -77, + -4, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -8, + -128, + -50, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, + -128, +}; diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/yes_micro_features_data.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/yes_micro_features_data.h new file mode 100644 index 00000000..3820f8ff --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_features/yes_micro_features_data.h @@ -0,0 +1,23 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_YES_MICRO_FEATURES_DATA_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_YES_MICRO_FEATURES_DATA_H_ + +extern const int g_yes_micro_f2e59fea_nohash_1_width; +extern const int g_yes_micro_f2e59fea_nohash_1_height; +extern const signed char g_yes_micro_f2e59fea_nohash_1_data[]; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_YES_MICRO_FEATURES_DATA_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_speech_binary_mock_test.sh b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_speech_binary_mock_test.sh new file mode 100644 index 00000000..f18b7fa2 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_speech_binary_mock_test.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +# +# Bash unit tests for the example binary. + +set -e + +OUTPUT_LOG_FILE=${TEST_TMPDIR}/output_log.txt + +# Needed for copybara compatibility. +SCRIPT_BASE_DIR=/org_"tensor"flow +${TEST_SRCDIR}${SCRIPT_BASE_DIR}/tensorflow/lite/micro/examples/micro_speech/micro_speech_mock 2>&1 | head > ${OUTPUT_LOG_FILE} + +if ! grep -q 'Heard ' ${OUTPUT_LOG_FILE}; then + echo "ERROR: Expected logs not found in output '${OUTPUT_LOG_FILE}'" + exit 1 +fi + +echo +echo "SUCCESS: micro_speech_binary_mock_test PASSED" diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_speech_test.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_speech_test.cc new file mode 100644 index 00000000..4dd950df --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/micro_speech_test.cc @@ -0,0 +1,149 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/model.h" +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/no_micro_features_data.h" +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/yes_micro_features_data.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/micro_interpreter.h" +#include "tensorflow/lite/micro/micro_mutable_op_resolver.h" +#include "tensorflow/lite/micro/testing/micro_test.h" +#include "tensorflow/lite/schema/schema_generated.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestInvoke) +{ + // Set up logging. + tflite::MicroErrorReporter micro_error_reporter; + + // Map the model into a usable data structure. This doesn't involve any + // copying or parsing, it's a very lightweight operation. + const tflite::Model *model = ::tflite::GetModel(g_model); + if (model->version() != TFLITE_SCHEMA_VERSION) { + TF_LITE_REPORT_ERROR(µ_error_reporter, + "Model provided is schema version %d not equal " + "to supported version %d.\n", + model->version(), TFLITE_SCHEMA_VERSION); + } + + // Pull in only the operation implementations we need. + // This relies on a complete list of all the ops needed by this graph. + // An easier approach is to just use the AllOpsResolver, but this will + // incur some penalty in code space for op implementations that are not + // needed by this graph. + // + // tflite::AllOpsResolver resolver; + tflite::MicroMutableOpResolver<4> micro_op_resolver; + micro_op_resolver.AddDepthwiseConv2D(); + micro_op_resolver.AddFullyConnected(); + micro_op_resolver.AddReshape(); + micro_op_resolver.AddSoftmax(); + + // Create an area of memory to use for input, output, and intermediate arrays. +#if defined(XTENSA) + constexpr int tensor_arena_size = 15 * 1024; +#else + constexpr int tensor_arena_size = 10 * 1024; +#endif + uint8_t tensor_arena[tensor_arena_size]; + + // Build an interpreter to run the model with. + tflite::MicroInterpreter interpreter(model, micro_op_resolver, tensor_arena, + tensor_arena_size, + µ_error_reporter); + interpreter.AllocateTensors(); + + // Get information about the memory area to use for the model's input. + TfLiteTensor *input = interpreter.input(0); + + // Make sure the input has the properties we expect. + TF_LITE_MICRO_EXPECT_NE(nullptr, input); + TF_LITE_MICRO_EXPECT_EQ(2, input->dims->size); + TF_LITE_MICRO_EXPECT_EQ(1, input->dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(1960, input->dims->data[1]); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt8, input->type); + + // Copy a spectrogram created from a .wav audio file of someone saying "Yes", + // into the memory area used for the input. + const int8_t *yes_features_data = g_yes_micro_f2e59fea_nohash_1_data; + for (size_t i = 0; i < input->bytes; ++i) { + input->data.int8[i] = yes_features_data[i]; + } + + // Run the model on this input and make sure it succeeds. + TfLiteStatus invoke_status = interpreter.Invoke(); + if (invoke_status != kTfLiteOk) { + TF_LITE_REPORT_ERROR(µ_error_reporter, "Invoke failed\n"); + } + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, invoke_status); + + // Get the output from the model, and make sure it's the expected size and + // type. + TfLiteTensor *output = interpreter.output(0); + TF_LITE_MICRO_EXPECT_EQ(2, output->dims->size); + TF_LITE_MICRO_EXPECT_EQ(1, output->dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(4, output->dims->data[1]); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt8, output->type); + + // There are four possible classes in the output, each with a score. + const int kSilenceIndex = 0; + const int kUnknownIndex = 1; + const int kYesIndex = 2; + const int kNoIndex = 3; + + // Make sure that the expected "Yes" score is higher than the other classes. + uint8_t silence_score = output->data.int8[kSilenceIndex] + 128; + uint8_t unknown_score = output->data.int8[kUnknownIndex] + 128; + uint8_t yes_score = output->data.int8[kYesIndex] + 128; + uint8_t no_score = output->data.int8[kNoIndex] + 128; + TF_LITE_MICRO_EXPECT_GT(yes_score, silence_score); + TF_LITE_MICRO_EXPECT_GT(yes_score, unknown_score); + TF_LITE_MICRO_EXPECT_GT(yes_score, no_score); + + // Now test with a different input, from a recording of "No". + const int8_t *no_features_data = g_no_micro_f9643d42_nohash_4_data; + for (size_t i = 0; i < input->bytes; ++i) { + input->data.int8[i] = no_features_data[i]; + } + + // Run the model on this "No" input. + invoke_status = interpreter.Invoke(); + if (invoke_status != kTfLiteOk) { + TF_LITE_REPORT_ERROR(µ_error_reporter, "Invoke failed\n"); + } + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, invoke_status); + + // Get the output from the model, and make sure it's the expected size and + // type. + output = interpreter.output(0); + TF_LITE_MICRO_EXPECT_EQ(2, output->dims->size); + TF_LITE_MICRO_EXPECT_EQ(1, output->dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(4, output->dims->data[1]); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt8, output->type); + + // Make sure that the expected "No" score is higher than the other classes. + silence_score = output->data.int8[kSilenceIndex] + 128; + unknown_score = output->data.int8[kUnknownIndex] + 128; + yes_score = output->data.int8[kYesIndex] + 128; + no_score = output->data.int8[kNoIndex] + 128; + TF_LITE_MICRO_EXPECT_GT(no_score, silence_score); + TF_LITE_MICRO_EXPECT_GT(no_score, unknown_score); + TF_LITE_MICRO_EXPECT_GT(no_score, yes_score); + + TF_LITE_REPORT_ERROR(µ_error_reporter, "Ran successfully\n"); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/no_1000ms_sample_data.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/no_1000ms_sample_data.cc new file mode 100644 index 00000000..4ff45a54 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/no_1000ms_sample_data.cc @@ -0,0 +1,16022 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// See the header for documentation on the meaning of this data. + +#include "tensorflow/lite/micro/examples/micro_speech/no_1000ms_sample_data.h" + +const int g_no_1000ms_sample_data_size = 16000; +const int16_t g_no_1000ms_sample_data[16000] = { + 5, + 1, + -10, + -16, + -14, + -10, + -4, + -5, + -10, + -15, + -13, + -17, + -22, + -21, + -23, + -25, + -22, + -26, + -28, + -31, + -28, + -25, + -20, + -24, + -21, + -13, + -7, + -1, + -1, + 3, + 3, + 4, + -4, + -6, + -8, + -10, + -13, + -4, + -2, + 5, + 8, + 11, + 26, + 28, + 34, + 32, + 34, + 30, + 21, + 18, + 15, + 13, + 8, + 5, + 14, + 13, + 7, + 8, + 4, + -5, + -7, + -4, + -9, + -13, + -17, + -21, + -16, + -14, + -12, + -12, + -14, + -11, + -9, + -2, + 5, + -1, + 2, + 0, + 2, + 1, + -3, + -13, + -14, + -16, + -11, + -10, + -9, + -13, + -17, + -19, + -25, + -21, + -21, + -20, + -13, + -5, + -3, + 0, + 3, + 6, + 5, + 1, + 0, + -1, + -7, + -10, + -11, + -9, + -6, + -7, + -11, + -10, + -5, + -14, + -20, + -23, + -22, + -22, + -19, + -15, + -12, + -6, + -5, + 3, + 13, + 16, + 17, + 25, + 26, + 28, + 34, + 34, + 33, + 34, + 30, + 21, + 22, + 18, + 13, + 20, + 22, + 24, + 27, + 26, + 23, + 21, + 18, + 9, + 5, + -2, + -7, + -8, + -10, + -8, + -8, + -4, + 2, + 2, + -1, + -7, + -10, + -8, + -12, + -13, + -15, + -9, + -5, + -4, + -3, + -6, + -11, + -11, + -18, + -16, + -13, + -10, + -12, + -6, + 0, + -2, + 0, + -3, + -4, + -8, + -12, + -19, + -16, + -17, + -19, + -23, + -30, + -33, + -36, + -38, + -39, + -40, + -36, + -37, + -32, + -27, + -25, + -31, + -38, + -41, + -47, + -52, + -50, + -42, + -32, + -16, + -7, + -3, + 0, + -1, + -1, + -5, + -16, + -23, + -29, + -34, + -33, + -27, + -17, + -11, + 1, + 4, + 10, + 18, + 21, + 24, + 24, + 25, + 30, + 34, + 30, + 29, + 26, + 23, + 20, + 15, + 14, + 13, + 14, + 16, + 23, + 28, + 21, + 23, + 21, + 13, + 12, + 12, + 14, + 17, + 21, + 26, + 27, + 30, + 30, + 26, + 20, + 15, + 15, + 9, + 8, + 9, + 10, + 7, + 8, + 7, + 1, + -2, + -6, + -10, + -10, + -12, + -15, + -10, + -7, + -6, + -5, + 0, + -3, + -3, + -12, + -25, + -35, + -49, + -53, + -49, + -51, + -48, + -46, + -48, + -39, + -33, + -31, + -37, + -42, + -47, + -49, + -46, + -47, + -47, + -46, + -42, + -39, + -33, + -26, + -23, + -14, + -8, + -9, + -7, + -10, + -11, + -13, + -13, + -19, + -20, + -16, + -11, + -9, + 7, + 16, + 21, + 29, + 27, + 29, + 28, + 21, + 14, + 13, + 17, + 19, + 20, + 18, + 13, + 17, + 16, + 18, + 20, + 17, + 13, + 16, + 23, + 26, + 26, + 25, + 27, + 31, + 30, + 31, + 34, + 32, + 35, + 32, + 36, + 31, + 26, + 23, + 27, + 27, + 29, + 27, + 26, + 32, + 31, + 28, + 26, + 23, + 14, + 6, + 0, + -4, + -7, + -9, + -10, + -8, + -3, + 4, + 12, + 11, + 15, + 11, + 8, + 2, + -3, + -3, + -4, + -6, + -11, + -14, + -20, + -28, + -32, + -38, + -46, + -42, + -44, + -40, + -34, + -26, + -29, + -25, + -23, + -24, + -17, + -21, + -26, + -23, + -25, + -19, + -10, + -11, + -10, + -10, + -12, + -9, + -3, + 0, + -3, + -7, + -10, + -13, + -10, + -14, + -13, + -17, + -22, + -22, + -30, + -28, + -29, + -26, + -18, + -6, + -1, + -3, + -4, + -6, + -10, + -13, + -10, + -14, + -16, + -11, + -15, + -9, + -3, + -6, + -1, + 2, + 3, + 4, + 6, + 6, + 3, + 4, + 12, + 14, + 17, + 21, + 19, + 20, + 16, + 17, + 15, + 21, + 21, + 22, + 20, + 17, + 16, + 16, + 20, + 17, + 15, + 9, + 5, + 11, + 18, + 24, + 28, + 26, + 23, + 23, + 26, + 22, + 18, + 21, + 23, + 26, + 27, + 25, + 27, + 29, + 26, + 20, + 10, + 7, + 11, + 8, + 16, + 25, + 33, + 37, + 38, + 39, + 35, + 30, + 20, + 13, + 9, + 6, + 5, + 13, + 13, + 14, + 15, + 12, + 8, + 3, + 3, + 3, + 2, + 9, + 11, + 10, + 5, + 5, + 0, + -7, + -11, + -12, + -15, + -17, + -12, + -13, + -18, + -19, + -21, + -24, + -22, + -27, + -34, + -36, + -36, + -32, + -20, + -16, + -15, + -5, + -5, + -9, + -10, + -9, + -17, + -19, + -20, + -14, + -13, + -10, + -4, + -7, + -7, + -14, + -19, + -28, + -31, + -30, + -31, + -23, + -19, + -20, + -12, + -11, + -14, + -16, + -20, + -18, + -20, + -21, + -24, + -29, + -30, + -30, + -34, + -31, + -25, + -21, + -18, + -11, + -4, + 2, + 2, + 3, + 3, + 2, + 4, + -1, + -4, + -8, + -3, + -1, + 7, + 15, + 18, + 22, + 20, + 20, + 16, + 16, + 14, + 13, + 21, + 25, + 26, + 35, + 28, + 28, + 28, + 25, + 21, + 19, + 18, + 21, + 24, + 20, + 25, + 28, + 19, + 16, + 15, + 8, + 3, + -1, + 3, + 5, + 13, + 18, + 25, + 31, + 33, + 39, + 36, + 36, + 32, + 36, + 37, + 39, + 42, + 36, + 32, + 27, + 30, + 24, + 18, + 15, + 10, + 7, + 5, + 6, + -1, + -4, + -10, + -17, + -15, + -19, + -15, + -7, + -4, + 3, + 0, + 3, + 4, + -2, + -7, + -13, + -21, + -23, + -28, + -27, + -26, + -25, + -15, + -10, + -4, + -6, + -5, + -9, + -5, + -3, + 1, + 2, + -1, + 1, + -4, + -7, + -8, + -17, + -17, + -15, + -14, + -9, + -5, + -7, + -6, + -9, + -16, + -15, + -15, + -16, + -16, + -11, + -15, + -15, + -6, + -6, + -5, + -2, + 0, + -9, + -10, + -12, + -13, + -10, + -4, + 0, + 8, + 5, + 4, + 2, + 0, + -5, + -8, + -16, + -15, + -12, + -3, + 9, + 17, + 24, + 26, + 30, + 28, + 22, + 17, + 14, + 9, + 8, + 9, + 8, + 11, + 12, + 12, + 15, + 14, + 18, + 20, + 17, + 19, + 22, + 21, + 12, + 5, + 0, + 3, + -3, + -4, + -6, + -7, + 1, + 8, + 8, + 8, + 10, + 2, + -3, + -8, + -15, + -20, + -24, + -22, + -23, + -13, + -6, + -7, + -5, + -10, + -8, + -15, + -19, + -22, + -20, + -17, + -18, + -13, + -10, + -1, + 6, + 5, + 3, + 1, + -5, + -11, + -10, + -14, + -19, + -15, + -13, + -8, + -2, + -3, + -4, + -3, + -4, + -1, + 1, + 0, + -3, + -4, + -8, + -18, + -21, + -25, + -24, + -16, + -9, + -2, + 1, + 5, + 1, + 3, + -2, + -7, + -10, + -23, + -30, + -29, + -23, + -9, + -3, + 4, + 11, + 11, + 6, + 2, + 0, + -12, + -20, + -28, + -24, + -22, + -17, + -22, + -19, + -14, + -21, + -17, + -17, + -12, + -8, + -3, + 2, + 0, + -6, + -5, + -8, + -12, + -17, + -27, + -34, + -31, + -30, + -27, + -19, + -14, + -14, + -14, + -14, + -19, + -22, + -21, + -19, + -14, + -1, + 5, + 9, + 8, + 6, + 5, + -4, + -2, + -3, + -3, + -1, + -2, + -3, + 2, + 7, + 8, + 7, + 6, + 6, + 3, + 2, + 1, + -2, + 0, + 6, + 11, + 18, + 18, + 19, + 17, + 14, + 9, + 4, + 3, + 3, + 0, + -1, + 3, + -1, + -5, + 0, + -2, + 0, + 1, + 7, + 7, + 8, + 20, + 29, + 33, + 31, + 24, + 14, + 5, + -6, + -11, + -8, + -11, + -2, + 6, + 10, + 12, + 16, + 26, + 26, + 24, + 18, + 12, + 10, + 4, + 7, + 6, + -2, + -12, + -17, + -17, + -20, + -23, + -23, + -18, + -8, + 1, + 3, + 5, + 6, + 3, + 0, + -6, + -12, + -12, + -15, + -12, + -7, + 3, + 3, + 8, + 7, + 7, + 7, + 1, + -1, + -1, + 4, + 11, + 17, + 25, + 32, + 35, + 42, + 50, + 52, + 56, + 50, + 55, + 53, + 52, + 47, + 40, + 38, + 30, + 26, + 27, + 28, + 29, + 25, + 23, + 23, + 28, + 30, + 25, + 26, + 21, + 19, + 14, + 9, + 16, + 22, + 25, + 33, + 39, + 45, + 49, + 48, + 55, + 51, + 43, + 35, + 20, + 14, + 13, + 23, + 25, + 24, + 20, + 22, + 28, + 22, + 22, + 17, + 16, + 13, + 10, + 10, + 10, + 9, + 9, + 14, + 11, + 10, + 10, + 4, + 0, + 0, + -2, + -3, + -5, + -7, + -3, + 1, + -8, + -8, + -9, + -4, + 4, + 9, + 11, + 14, + 11, + 6, + 8, + 3, + -6, + -10, + -19, + -22, + -24, + -27, + -22, + -16, + -21, + -25, + -33, + -33, + -32, + -30, + -21, + -13, + -6, + -5, + 2, + 1, + 4, + 9, + 7, + 5, + 1, + 1, + 8, + 6, + 7, + 6, + 0, + -6, + -15, + -18, + -23, + -22, + -23, + -25, + -22, + -21, + -19, + -17, + -13, + -10, + -10, + -16, + -17, + -15, + -13, + -8, + -9, + -14, + -13, + -17, + -20, + -26, + -28, + -31, + -29, + -26, + -23, + -13, + -10, + -6, + -1, + 5, + 7, + 2, + -3, + -7, + -20, + -18, + -16, + -21, + -27, + -33, + -25, + -27, + -22, + -22, + -21, + -16, + -11, + -7, + -2, + 2, + 11, + 18, + 11, + 9, + 4, + 1, + -1, + -6, + -4, + -5, + -9, + -12, + -16, + -25, + -29, + -37, + -37, + -38, + -37, + -33, + -23, + -16, + -14, + -7, + -1, + -4, + -3, + -4, + -5, + -11, + -14, + -8, + -8, + -8, + -8, + -9, + -4, + -14, + -21, + -22, + -21, + -18, + -15, + -2, + 3, + -3, + 0, + -2, + 0, + -4, + -7, + -1, + -2, + 3, + 3, + -3, + -10, + -13, + -10, + -16, + -19, + -17, + -17, + -14, + -7, + 5, + 5, + 7, + 8, + 12, + 7, + 0, + -5, + -13, + -17, + -18, + -14, + -7, + -4, + 3, + 11, + 11, + 12, + 11, + 8, + 4, + -5, + -5, + -11, + -15, + -17, + -23, + -22, + -18, + -14, + -14, + -12, + -6, + -4, + -1, + 3, + 1, + -4, + -10, + -22, + -29, + -30, + -26, + -15, + -2, + 6, + 16, + 21, + 28, + 32, + 25, + 24, + 20, + 9, + 5, + 0, + 3, + 7, + 10, + 11, + 13, + 17, + 15, + 16, + 13, + 11, + 11, + 8, + 7, + 1, + 1, + -5, + -2, + -2, + -1, + 4, + 8, + 17, + 22, + 24, + 24, + 26, + 23, + 20, + 17, + 16, + 9, + 4, + 6, + 5, + 8, + 2, + -1, + -5, + -4, + -10, + -14, + -14, + -17, + -19, + -18, + -16, + -14, + -6, + -3, + 1, + 3, + 0, + -4, + -6, + -4, + -1, + -1, + 2, + 5, + 3, + 8, + 7, + 7, + 14, + 13, + 20, + 24, + 29, + 24, + 12, + 7, + -1, + -6, + -15, + -22, + -20, + -27, + -22, + -14, + -6, + 2, + 7, + 9, + 9, + 2, + -3, + -7, + -8, + -10, + -9, + -3, + -6, + -11, + -12, + -8, + -5, + -4, + -5, + -3, + 0, + 3, + 6, + 6, + 7, + 5, + -7, + -10, + -14, + -13, + -14, + -17, + -11, + -7, + -4, + 1, + 1, + 4, + -4, + -8, + -18, + -23, + -23, + -25, + -19, + -16, + -15, + -9, + 3, + 10, + 19, + 25, + 30, + 31, + 26, + 27, + 23, + 19, + 16, + 8, + 7, + 2, + 0, + -1, + -1, + 1, + 5, + 6, + 6, + 1, + 3, + -1, + -7, + -11, + -17, + -19, + -19, + -7, + 0, + 3, + 11, + 12, + 18, + 20, + 16, + 9, + -2, + -7, + -14, + -19, + -22, + -30, + -33, + -34, + -36, + -26, + -14, + -11, + -9, + -3, + 0, + -2, + 1, + -2, + -3, + -5, + -12, + -15, + -19, + -14, + -9, + -8, + -2, + -6, + -13, + -15, + -19, + -22, + -25, + -26, + -21, + -20, + -11, + -1, + 1, + 5, + 9, + 13, + 15, + 12, + 11, + 3, + 1, + -1, + 0, + 8, + 13, + 16, + 16, + 15, + 16, + 15, + 12, + 9, + 7, + 8, + 4, + 6, + 4, + 3, + 3, + 7, + 0, + -4, + -8, + -11, + -18, + -18, + -15, + -20, + -23, + -21, + -22, + -21, + -27, + -25, + -15, + -7, + -2, + 8, + 9, + 8, + 8, + 3, + 3, + 7, + 8, + 8, + 8, + 12, + 11, + 12, + 4, + -1, + -7, + -11, + -15, + -18, + -17, + -17, + -20, + -19, + -13, + -11, + -3, + -3, + -1, + 1, + -3, + 1, + 1, + 8, + 10, + 15, + 24, + 26, + 29, + 34, + 36, + 26, + 20, + 12, + -2, + -6, + -9, + -7, + -6, + 1, + 10, + 13, + 19, + 22, + 22, + 18, + 21, + 24, + 28, + 35, + 37, + 34, + 33, + 34, + 34, + 30, + 19, + 15, + 10, + 19, + 21, + 23, + 24, + 21, + 19, + 18, + 21, + 22, + 22, + 27, + 30, + 31, + 32, + 33, + 32, + 32, + 24, + 18, + 10, + 8, + 10, + 10, + 6, + 2, + -7, + -14, + -22, + -29, + -27, + -29, + -32, + -30, + -28, + -23, + -22, + -11, + -11, + -13, + -3, + 2, + -1, + 1, + 1, + -3, + -7, + -5, + -7, + -11, + -17, + -23, + -25, + -26, + -27, + -26, + -23, + -14, + -5, + -3, + -1, + -2, + -2, + -1, + 1, + -2, + -7, + -4, + 2, + 4, + 10, + 13, + 6, + 3, + -2, + -6, + -7, + -11, + -17, + -21, + -15, + -7, + -2, + 11, + 16, + 22, + 25, + 25, + 23, + 24, + 23, + 21, + 22, + 25, + 23, + 17, + 17, + 12, + 8, + -2, + -4, + 1, + 0, + 4, + 9, + 8, + 10, + 9, + 9, + 15, + 13, + 10, + 8, + 1, + 1, + -3, + 1, + 4, + 11, + 10, + 9, + 5, + 5, + 4, + 1, + -1, + -4, + 0, + 8, + 7, + 4, + 3, + 3, + 0, + -9, + -16, + -19, + -20, + -21, + -18, + -16, + -11, + -10, + -9, + -13, + -12, + -19, + -25, + -21, + -15, + -5, + 8, + 14, + 21, + 24, + 18, + 20, + 17, + 6, + 1, + -2, + -2, + 1, + 1, + 4, + 1, + -3, + 2, + 0, + -3, + -3, + -4, + 1, + 0, + -5, + -11, + -17, + -21, + -20, + -20, + -20, + -14, + -9, + -3, + 3, + 7, + 5, + 3, + 1, + -1, + -3, + -4, + -1, + 1, + -5, + -1, + -1, + -7, + -11, + -14, + -12, + -14, + -17, + -18, + -23, + -29, + -24, + -27, + -19, + -12, + -13, + -2, + -3, + 4, + 4, + 0, + -3, + -5, + -2, + -1, + -5, + -6, + -7, + -7, + -7, + -9, + -13, + -9, + -4, + 1, + 1, + 1, + -4, + -11, + -8, + -15, + -19, + -19, + -12, + -5, + 1, + 7, + 12, + 8, + 10, + 10, + 10, + 11, + 11, + 19, + 12, + 9, + 9, + 2, + -4, + -13, + -22, + -24, + -25, + -24, + -26, + -19, + -14, + -10, + -1, + 5, + 4, + -1, + -4, + -5, + -10, + -14, + -11, + -8, + -10, + -8, + -9, + -7, + -8, + -6, + -1, + -5, + -10, + -18, + -27, + -29, + -24, + -19, + -11, + -7, + 1, + 10, + 8, + 8, + 5, + 2, + -5, + -1, + -1, + 0, + 2, + 2, + -2, + -8, + -8, + -14, + -26, + -25, + -23, + -18, + -9, + 2, + 2, + 7, + 13, + 6, + 7, + 5, + 4, + 3, + 2, + 1, + 7, + 2, + -1, + 1, + -2, + 2, + 0, + -2, + -6, + -3, + 5, + 7, + 9, + 6, + 5, + 4, + 2, + 0, + -1, + -3, + 3, + 7, + 6, + 14, + 18, + 22, + 20, + 22, + 19, + 13, + 9, + 2, + -8, + -11, + -6, + -2, + -3, + -3, + 0, + 0, + 0, + 1, + -1, + -2, + 1, + 7, + 11, + 10, + 11, + 17, + 17, + 11, + 11, + 4, + 6, + 6, + 13, + 19, + 22, + 23, + 27, + 25, + 24, + 22, + 14, + 11, + 13, + 7, + 0, + -3, + -9, + -11, + -7, + -7, + -6, + -4, + 1, + 7, + 9, + 15, + 18, + 18, + 10, + 5, + 3, + -3, + -6, + -5, + -8, + -5, + 4, + 8, + 8, + 11, + 10, + 9, + 4, + 4, + 1, + -3, + -10, + -11, + -8, + -16, + -20, + -22, + -19, + -12, + -7, + -10, + -10, + -13, + -14, + -11, + -11, + -13, + -18, + -21, + -19, + -17, + -22, + -18, + -22, + -22, + -16, + -9, + -3, + 0, + 3, + 6, + 3, + 3, + -3, + -6, + -9, + -14, + -1, + 14, + 21, + 30, + 37, + 33, + 27, + 26, + 19, + 15, + 14, + 11, + 20, + 12, + 9, + 10, + 19, + 20, + 19, + 22, + 20, + 22, + 17, + 13, + 14, + 10, + 8, + 12, + 15, + 13, + 12, + 12, + 12, + 9, + 10, + 11, + 11, + 9, + 6, + 4, + 5, + -2, + 1, + 1, + -1, + 5, + 1, + 8, + 6, + 3, + -1, + -4, + -15, + -24, + -27, + -26, + -23, + -19, + -9, + -3, + -4, + -9, + -9, + -10, + -16, + -22, + -19, + -18, + -15, + -2, + 3, + 5, + 6, + 7, + 8, + 11, + 3, + 1, + 2, + 1, + 1, + 0, + -4, + -13, + -18, + -19, + -19, + -20, + -23, + -15, + -10, + -5, + -3, + -1, + -1, + -1, + 3, + -1, + 0, + -8, + -11, + -13, + -14, + -13, + -8, + -6, + -3, + 1, + 1, + 0, + 0, + 5, + 4, + 5, + 5, + 5, + 4, + 0, + -1, + -4, + -13, + -22, + -21, + -28, + -26, + -22, + -28, + -23, + -23, + -14, + -11, + -10, + -7, + -8, + -5, + -4, + 1, + 9, + 10, + 15, + 19, + 21, + 17, + 18, + 19, + 16, + 13, + 16, + 21, + 27, + 29, + 22, + 22, + 13, + 4, + 1, + 0, + -5, + -6, + -2, + 3, + 5, + 8, + 6, + 9, + 10, + 2, + -3, + -9, + -8, + -4, + -2, + -7, + -6, + -4, + -8, + -6, + -8, + -11, + -8, + -8, + -6, + 2, + -2, + -2, + -1, + 2, + 4, + 8, + 5, + -1, + -8, + -10, + -7, + -6, + -5, + -6, + -5, + 6, + 13, + 22, + 28, + 33, + 31, + 38, + 35, + 28, + 27, + 22, + 22, + 23, + 26, + 23, + 21, + 28, + 28, + 23, + 23, + 22, + 21, + 20, + 14, + 6, + -1, + -5, + -8, + -5, + -1, + 2, + 5, + 5, + 7, + 8, + 5, + 4, + 0, + 3, + 6, + 10, + 13, + 13, + 6, + 4, + 4, + 0, + -2, + -3, + 0, + 3, + 5, + 7, + 9, + 7, + 6, + 10, + 8, + 3, + 4, + -1, + -4, + -2, + 0, + -2, + -2, + -2, + -3, + 5, + 8, + 6, + 4, + -1, + -7, + -6, + -7, + -12, + -18, + -11, + -2, + -1, + -1, + -1, + -2, + -7, + -7, + -3, + -3, + -5, + -6, + -6, + -6, + -6, + -6, + -9, + -12, + -9, + -5, + 1, + 3, + 5, + 5, + 8, + 7, + 3, + -5, + -3, + -2, + 2, + 3, + 5, + 5, + -1, + -2, + -4, + -8, + -9, + -9, + -7, + -12, + -13, + -17, + -19, + -16, + -19, + -21, + -21, + -19, + -11, + -6, + -3, + 7, + 8, + 6, + 2, + 0, + 1, + 1, + -2, + -5, + 0, + -2, + 2, + 1, + 2, + 0, + -2, + -1, + -10, + -21, + -25, + -24, + -21, + -19, + -14, + -8, + -3, + -5, + 0, + 0, + -5, + -6, + -3, + -6, + -9, + -13, + -19, + -20, + -21, + -21, + -24, + -25, + -27, + -27, + -29, + -26, + -19, + -14, + -14, + -13, + -8, + -5, + -10, + -10, + -6, + 1, + 4, + 14, + 22, + 23, + 24, + 20, + 20, + 18, + 14, + 11, + 9, + 6, + 8, + 12, + 15, + 18, + 18, + 12, + 8, + 9, + 9, + 9, + 7, + 4, + 9, + 5, + 6, + 5, + 3, + 3, + -1, + -1, + -6, + -10, + -6, + -8, + -3, + 0, + -2, + -3, + -2, + -6, + -6, + -7, + -3, + -3, + -3, + -2, + 1, + -1, + -10, + -7, + -13, + -21, + -23, + -20, + -19, + -18, + -18, + -19, + -15, + -16, + -7, + -6, + -9, + -13, + -12, + -6, + -1, + 3, + 6, + 7, + 5, + 3, + -3, + -11, + -18, + -20, + -26, + -29, + -27, + -27, + -24, + -30, + -29, + -28, + -23, + -18, + -21, + -18, + -15, + -9, + 1, + 9, + 17, + 21, + 23, + 18, + 14, + 5, + -1, + -2, + -1, + 0, + 3, + 6, + 5, + 4, + 4, + 0, + -1, + 1, + -4, + -9, + -13, + -11, + -20, + -21, + -19, + -14, + -9, + -4, + 1, + 6, + 10, + 16, + 24, + 30, + 35, + 31, + 38, + 37, + 35, + 39, + 36, + 36, + 32, + 30, + 33, + 31, + 24, + 19, + 12, + 4, + -1, + -7, + -11, + -7, + -5, + -3, + 2, + 6, + 10, + 16, + 19, + 21, + 21, + 16, + 10, + 14, + 12, + 14, + 13, + 12, + 12, + 5, + 6, + 2, + 0, + 1, + 3, + 4, + 6, + 9, + 6, + 2, + -1, + -3, + -10, + -15, + -13, + -17, + -19, + -15, + -16, + -15, + -13, + -8, + -8, + -7, + -10, + -5, + -2, + 1, + 5, + 5, + 11, + 10, + 12, + 10, + 9, + 9, + 15, + 23, + 33, + 35, + 33, + 34, + 34, + 35, + 34, + 24, + 30, + 26, + 23, + 21, + 20, + 15, + 10, + 3, + 4, + 0, + -7, + -8, + -9, + -9, + -8, + -4, + 0, + 5, + 5, + 2, + 3, + -2, + 0, + 0, + -1, + 0, + -1, + 1, + 2, + 6, + 3, + 1, + -9, + -5, + -6, + -2, + -8, + -12, + -9, + -10, + -7, + -8, + -8, + -6, + -2, + -2, + -1, + 0, + -2, + -1, + -8, + -18, + -19, + -27, + -37, + -42, + -40, + -39, + -33, + -30, + -23, + -16, + -16, + -9, + -13, + -11, + -10, + -10, + -8, + -3, + -1, + 2, + 0, + -1, + 2, + 6, + 4, + 8, + 10, + 17, + 21, + 28, + 31, + 33, + 28, + 20, + 12, + 8, + -3, + -5, + -4, + -3, + 2, + 6, + 9, + 8, + 2, + 7, + 4, + -6, + -9, + -15, + -13, + -15, + -17, + -14, + -11, + -12, + -5, + -6, + -4, + -6, + -11, + -11, + -7, + -4, + -6, + -8, + -13, + -10, + -7, + -12, + -11, + -12, + -13, + -12, + -9, + -9, + -10, + -10, + -6, + -8, + -8, + -7, + -9, + -9, + -7, + 2, + 5, + 5, + 6, + 3, + 4, + 6, + 3, + -1, + -2, + -2, + -2, + 1, + 5, + 3, + 4, + 2, + -2, + -7, + -9, + -13, + -11, + -8, + 2, + 12, + 23, + 31, + 37, + 41, + 40, + 37, + 36, + 31, + 31, + 27, + 28, + 24, + 13, + 16, + 14, + 15, + 9, + 4, + 4, + 5, + 4, + 7, + 12, + 16, + 14, + 11, + 13, + 6, + -2, + -4, + -1, + -3, + 3, + 6, + 6, + 9, + 7, + 9, + 7, + 5, + 0, + 1, + -1, + -2, + -4, + -1, + 0, + 0, + -4, + 0, + -4, + -9, + -15, + -16, + -18, + -15, + -10, + -6, + -8, + -5, + -2, + -2, + 0, + 4, + 7, + 0, + -2, + -3, + 4, + 3, + 2, + -1, + -3, + -8, + -19, + -19, + -19, + -16, + -8, + -5, + 0, + 1, + 2, + 1, + -1, + -2, + -10, + -12, + -10, + -4, + 3, + 4, + 2, + 7, + 8, + 4, + 1, + -5, + -5, + -4, + -1, + 9, + 10, + 12, + 15, + 15, + 14, + 11, + 20, + 16, + 19, + 18, + 26, + 29, + 21, + 23, + 16, + 16, + 3, + -3, + -4, + -10, + -12, + -10, + -6, + -7, + -12, + -17, + -14, + -16, + -19, + -13, + -10, + -13, + -13, + -2, + 2, + 3, + 7, + 13, + 22, + 21, + 21, + 21, + 24, + 27, + 23, + 22, + 20, + 17, + 17, + 16, + 13, + 11, + 5, + 1, + 1, + 5, + 5, + 3, + 2, + -1, + 2, + -5, + -6, + -3, + -11, + -9, + -6, + -5, + -10, + -4, + -1, + 1, + 2, + -1, + -4, + -4, + -9, + -9, + -7, + -3, + 3, + -2, + 1, + 1, + 4, + -4, + -8, + -8, + -17, + -17, + -13, + -13, + -18, + -18, + -25, + -27, + -21, + -22, + -18, + -7, + -1, + 5, + 9, + 11, + 11, + 11, + 15, + 11, + 4, + 1, + 6, + 8, + 17, + 12, + 10, + 5, + -2, + -3, + -14, + -17, + -25, + -26, + -22, + -20, + -13, + -12, + -12, + -13, + -10, + -4, + -6, + -6, + -4, + -6, + -4, + 0, + -3, + -7, + -7, + -10, + -17, + -14, + -9, + -3, + 4, + 4, + 6, + 1, + 0, + 0, + -6, + -3, + -4, + -3, + -6, + -9, + -9, + -5, + 0, + 1, + 2, + -2, + 3, + -1, + -4, + -5, + -11, + -14, + -17, + -14, + -12, + -14, + -19, + -21, + -25, + -35, + -40, + -39, + -31, + -24, + -13, + -4, + -1, + 0, + 0, + 2, + -2, + -5, + -8, + -8, + -9, + -6, + -2, + 0, + -5, + -6, + 2, + 5, + 4, + 1, + 6, + 8, + 9, + 14, + 13, + 19, + 15, + 19, + 13, + 14, + 20, + 16, + 16, + 14, + 14, + 17, + 13, + 12, + 11, + 6, + -1, + -7, + -9, + -10, + -11, + -2, + 8, + 12, + 12, + 12, + 8, + 4, + 1, + -3, + -4, + -4, + -3, + 1, + 9, + 14, + 16, + 10, + 12, + 9, + 6, + 4, + -1, + 8, + 6, + 3, + 6, + 1, + -11, + -10, + -10, + -13, + -9, + -6, + -2, + -2, + 9, + 13, + 17, + 17, + 19, + 17, + 16, + 9, + -2, + -5, + -5, + -3, + -9, + -8, + -8, + -12, + -17, + -16, + -18, + -15, + -9, + -7, + 1, + 10, + 17, + 18, + 23, + 25, + 23, + 20, + 15, + 17, + 18, + 23, + 33, + 40, + 43, + 45, + 51, + 53, + 47, + 36, + 27, + 10, + 5, + 1, + 4, + 5, + 4, + 0, + 0, + 6, + 7, + 8, + 9, + 3, + 2, + 1, + 0, + -1, + 3, + 5, + 5, + 13, + 7, + 4, + 4, + 3, + 11, + 17, + 21, + 31, + 31, + 31, + 31, + 28, + 26, + 23, + 19, + 16, + 17, + 16, + 10, + 10, + 12, + 9, + 7, + -1, + -7, + -12, + -15, + -15, + -15, + -13, + -13, + -16, + -19, + -19, + -23, + -31, + -34, + -38, + -39, + -31, + -30, + -21, + -21, + -18, + -11, + -16, + -20, + -25, + -22, + -18, + -14, + -7, + -8, + -3, + 2, + 10, + 13, + 12, + 10, + 6, + 2, + 0, + 0, + 0, + -6, + -4, + -1, + 0, + 0, + -1, + -2, + 1, + 3, + 8, + 9, + 3, + 6, + 2, + -4, + -2, + -3, + -7, + -4, + -3, + 2, + 6, + 8, + 10, + 12, + 15, + 11, + 15, + 12, + 13, + 14, + 15, + 18, + 14, + 8, + 4, + 4, + 3, + -4, + -5, + -4, + -2, + -3, + -2, + 4, + 9, + 13, + 18, + 21, + 20, + 18, + 15, + 11, + 6, + 7, + 10, + 8, + 6, + 3, + -3, + -7, + -14, + -21, + -29, + -33, + -32, + -26, + -17, + -12, + -11, + -9, + -3, + -10, + -13, + -18, + -23, + -21, + -26, + -26, + -24, + -28, + -25, + -29, + -30, + -30, + -27, + -17, + -7, + 2, + 10, + 13, + 16, + 16, + 17, + 18, + 17, + 19, + 19, + 20, + 15, + 14, + 16, + 14, + 10, + 5, + 0, + -4, + -18, + -21, + -25, + -20, + -16, + -13, + -8, + -5, + 2, + 6, + 11, + 12, + 18, + 16, + 18, + 15, + 13, + 17, + 18, + 22, + 21, + 25, + 26, + 25, + 26, + 28, + 31, + 27, + 20, + 10, + 3, + -6, + -10, + -16, + -19, + -18, + -15, + -13, + -10, + -2, + 0, + 2, + 4, + 3, + 5, + -1, + 0, + 1, + 2, + 0, + -2, + -1, + -6, + -5, + -7, + -12, + -10, + -9, + -4, + -1, + 3, + 4, + 2, + 4, + 4, + 3, + -3, + -6, + -11, + -14, + -15, + -23, + -25, + -29, + -30, + -28, + -25, + -22, + -19, + -21, + -19, + -11, + -7, + -7, + -3, + -3, + -6, + -8, + -13, + -10, + -10, + -5, + 1, + 4, + 9, + 7, + 6, + 6, + 4, + -5, + -11, + -8, + -6, + -3, + 0, + 3, + 7, + 11, + 7, + 3, + 5, + 6, + 10, + 12, + 14, + 16, + 8, + 5, + -1, + -1, + 4, + 0, + 0, + -3, + -5, + -5, + -4, + -2, + -2, + 1, + 4, + 7, + 5, + 10, + 9, + 6, + 9, + 12, + 19, + 28, + 32, + 32, + 33, + 31, + 29, + 20, + 17, + 16, + 14, + 15, + 6, + -2, + -5, + -7, + -10, + -10, + -11, + -9, + -6, + -3, + 8, + 10, + 10, + 10, + 12, + 12, + 7, + 7, + 5, + 3, + 2, + 2, + -2, + -5, + -4, + -7, + -2, + -6, + -5, + -6, + -11, + -14, + -13, + -10, + -11, + -15, + -16, + -11, + -11, + -11, + -10, + -16, + -15, + -15, + -16, + -10, + -11, + -11, + -5, + -1, + 2, + 1, + 2, + 0, + 1, + 4, + 8, + 5, + -4, + -2, + -4, + -12, + -18, + -24, + -20, + -25, + -14, + -3, + 4, + 11, + 13, + 13, + 7, + 4, + -4, + -9, + -13, + -17, + -10, + -6, + -1, + 0, + 2, + 2, + -1, + 1, + -8, + -18, + -22, + -19, + -19, + -22, + -20, + -22, + -20, + -17, + -12, + -9, + -4, + 3, + 9, + 9, + 9, + 7, + 6, + 13, + 10, + 11, + 8, + 4, + -1, + 5, + 7, + 7, + 8, + 4, + 2, + 2, + -2, + -8, + -11, + -16, + -18, + -12, + -12, + -9, + -2, + 3, + 3, + 5, + 5, + 6, + 9, + 11, + 20, + 22, + 26, + 30, + 28, + 22, + 15, + 15, + 10, + 11, + 9, + 6, + 9, + 9, + 11, + 10, + 12, + 10, + 8, + 8, + 7, + 9, + 4, + 3, + 9, + 5, + 1, + 2, + 0, + -3, + -3, + 0, + 3, + 0, + -2, + 1, + 4, + 6, + 4, + 0, + 1, + -4, + -13, + -13, + -11, + -20, + -21, + -15, + -17, + -23, + -22, + -24, + -29, + -24, + -29, + -32, + -21, + -13, + -11, + -9, + -9, + -8, + -13, + -11, + -11, + -11, + -11, + -17, + -17, + -21, + -23, + -27, + -32, + -33, + -32, + -31, + -35, + -31, + -26, + -24, + -18, + -10, + -1, + 5, + 13, + 17, + 15, + 13, + 8, + 4, + 6, + 9, + 10, + 13, + 11, + 12, + 13, + 9, + 5, + 6, + 8, + 12, + 21, + 25, + 24, + 23, + 16, + 8, + 7, + 0, + -3, + -8, + -9, + -2, + 1, + 11, + 18, + 25, + 30, + 31, + 27, + 21, + 19, + 19, + 18, + 18, + 22, + 24, + 16, + 14, + 8, + 2, + -4, + -9, + -7, + -10, + -6, + -8, + -8, + -13, + -14, + -11, + -13, + -8, + -7, + 6, + 9, + 10, + 15, + 17, + 11, + 11, + 9, + 2, + 2, + -2, + 2, + -6, + -6, + -7, + -14, + -11, + -12, + -13, + -17, + -22, + -25, + -30, + -24, + -16, + -4, + 5, + 2, + 7, + 5, + 2, + -1, + 1, + -4, + -4, + 4, + 8, + 8, + 5, + 6, + 6, + 2, + 1, + -2, + -9, + -14, + -17, + -16, + -15, + -14, + -12, + -11, + -6, + -6, + -2, + -3, + -3, + 6, + 13, + 18, + 27, + 27, + 26, + 24, + 22, + 19, + 18, + 19, + 12, + 8, + 7, + -2, + 0, + -6, + -8, + -6, + -4, + -6, + -14, + -16, + -16, + -15, + -12, + -2, + 6, + 12, + 16, + 18, + 14, + 16, + 13, + 12, + 17, + 16, + 17, + 17, + 12, + 13, + 10, + 14, + 14, + 10, + 2, + -1, + -3, + -5, + -10, + -15, + -13, + -20, + -21, + -21, + -21, + -19, + -20, + -18, + -8, + -4, + -1, + -1, + 4, + 2, + -3, + 0, + -5, + -5, + -3, + -1, + 0, + 6, + 5, + 6, + 7, + 7, + 3, + 2, + 1, + -5, + -3, + 0, + 3, + 5, + 7, + 4, + 10, + 15, + 15, + 11, + 6, + 8, + 9, + 14, + 19, + 18, + 14, + 12, + 16, + 15, + 11, + 9, + 9, + 5, + 4, + 0, + -7, + -12, + -18, + -22, + -29, + -32, + -36, + -37, + -38, + -39, + -32, + -24, + -20, + -14, + -10, + -2, + 0, + 1, + 9, + 13, + 21, + 26, + 31, + 35, + 40, + 38, + 32, + 33, + 25, + 14, + 11, + 7, + 1, + -1, + -6, + -5, + -11, + -20, + -22, + -19, + -16, + -9, + 2, + 9, + 14, + 14, + 13, + 13, + 12, + 10, + 3, + 2, + 1, + 0, + 6, + 5, + -1, + -4, + -13, + -17, + -21, + -25, + -29, + -30, + -23, + -14, + -4, + 4, + 11, + 11, + 12, + 13, + 13, + 5, + 6, + 6, + 7, + 5, + 5, + 9, + -2, + 3, + 0, + -2, + -3, + -5, + -1, + 3, + 9, + 16, + 18, + 17, + 17, + 11, + 5, + 1, + -4, + -13, + -12, + -7, + -7, + 1, + 6, + 4, + 2, + 3, + 1, + 1, + 0, + -1, + -5, + -5, + -3, + -5, + -1, + 8, + 9, + 7, + 12, + 7, + 6, + 4, + 3, + -1, + -1, + -4, + -14, + -16, + -18, + -24, + -34, + -44, + -37, + -37, + -36, + -28, + -19, + -15, + -6, + -2, + -3, + 2, + 5, + 6, + 3, + 6, + 6, + 9, + 7, + 3, + -4, + -15, + -25, + -34, + -37, + -41, + -41, + -38, + -33, + -27, + -22, + -14, + -15, + -18, + -18, + -15, + -8, + -7, + -2, + 2, + 0, + 4, + 12, + 13, + 10, + 17, + 20, + 16, + 17, + 23, + 24, + 22, + 24, + 22, + 28, + 26, + 24, + 22, + 26, + 28, + 27, + 23, + 17, + 10, + 4, + 4, + 1, + -1, + 0, + 4, + 9, + 15, + 14, + 15, + 14, + 14, + 13, + 8, + 0, + -1, + -11, + -13, + -4, + -3, + -5, + -3, + -1, + -6, + -5, + -7, + -4, + -2, + 2, + 7, + 15, + 20, + 14, + 13, + 8, + 2, + -6, + -15, + -23, + -25, + -20, + -22, + -20, + -14, + -10, + -4, + -2, + 1, + -10, + -15, + -12, + -8, + -8, + -7, + -5, + -10, + -12, + -20, + -28, + -26, + -24, + -16, + -8, + -5, + 3, + 8, + 9, + 12, + 12, + 12, + 14, + 13, + 12, + 10, + 13, + 23, + 29, + 28, + 33, + 36, + 32, + 28, + 23, + 25, + 26, + 30, + 34, + 27, + 22, + 16, + 12, + 3, + -6, + -13, + -13, + -15, + -14, + -9, + -11, + -13, + -13, + -16, + -15, + -20, + -22, + -20, + -32, + -30, + -29, + -24, + -18, + -18, + -18, + -13, + -15, + -15, + -16, + -17, + -10, + -11, + -12, + -15, + -17, + -17, + -19, + -21, + -22, + -26, + -28, + -21, + -18, + -14, + -5, + 2, + 6, + 7, + 5, + 3, + -2, + 0, + -4, + -2, + -3, + -6, + -9, + -12, + -11, + -11, + -19, + -23, + -20, + -21, + -16, + -19, + -23, + -22, + -24, + -21, + -22, + -17, + -15, + -8, + -1, + 4, + 14, + 18, + 23, + 24, + 25, + 25, + 18, + 15, + 7, + 2, + 14, + 19, + 22, + 20, + 23, + 22, + 20, + 19, + 20, + 17, + 16, + 21, + 22, + 21, + 18, + 9, + 3, + -6, + -14, + -19, + -30, + -36, + -40, + -32, + -22, + -21, + -16, + -7, + -1, + 3, + 2, + 3, + 6, + 9, + 16, + 20, + 22, + 26, + 27, + 29, + 32, + 30, + 23, + 19, + 20, + 21, + 18, + 22, + 24, + 15, + 14, + 9, + 9, + 7, + 6, + 9, + 9, + 16, + 22, + 20, + 18, + 18, + 9, + -1, + -10, + -16, + -19, + -22, + -22, + -20, + -16, + -11, + -5, + 0, + 1, + 4, + 2, + 0, + 3, + 5, + 10, + 8, + 12, + 10, + 11, + 9, + 8, + 7, + -3, + -4, + -10, + -11, + -5, + 2, + 8, + 12, + 12, + 13, + 14, + 15, + 14, + 12, + 10, + 14, + 13, + 8, + 0, + -2, + -3, + -9, + -6, + -13, + -21, + -12, + -12, + -8, + -9, + -14, + -16, + -19, + -23, + -22, + -23, + -30, + -26, + -17, + -14, + -9, + -2, + 3, + 11, + 16, + 17, + 17, + 11, + 12, + 13, + 12, + 9, + 8, + 7, + 10, + 17, + 14, + 13, + 9, + 7, + 6, + 5, + 10, + 10, + 6, + 10, + 9, + 1, + -5, + -10, + -12, + -17, + -16, + -14, + -13, + -10, + -6, + -2, + 0, + -1, + 2, + 2, + -1, + 2, + 6, + 12, + 18, + 23, + 22, + 23, + 24, + 20, + 16, + 10, + 6, + 9, + 16, + 15, + 15, + 16, + 14, + 8, + 4, + 0, + -3, + -7, + -4, + -5, + -5, + 0, + -4, + 1, + 1, + 1, + -4, + -10, + -17, + -25, + -25, + -28, + -28, + -27, + -25, + -20, + -20, + -20, + -22, + -14, + -11, + -4, + 4, + 6, + 11, + 10, + 12, + 9, + 6, + 2, + -6, + -10, + -12, + -7, + -1, + -6, + 0, + 1, + 2, + 5, + 1, + -1, + 1, + -3, + -6, + -4, + -5, + -4, + -6, + -5, + -7, + -10, + -10, + -8, + -11, + -9, + -2, + 9, + 15, + 14, + 20, + 19, + 19, + 16, + 16, + 11, + 3, + 2, + 2, + 5, + 4, + 5, + 3, + -1, + -1, + -6, + -11, + -16, + -18, + -18, + -12, + -17, + -18, + -13, + -15, + -5, + -4, + -3, + -1, + 2, + 6, + 7, + 11, + 14, + 17, + 17, + 18, + 21, + 18, + 19, + 18, + 23, + 27, + 36, + 32, + 35, + 30, + 24, + 25, + 18, + 10, + 3, + -1, + -4, + -11, + -16, + -21, + -33, + -37, + -35, + -36, + -35, + -30, + -26, + -26, + -21, + -10, + -7, + -3, + -4, + -3, + -3, + -9, + -12, + -16, + -25, + -22, + -11, + -6, + 2, + 5, + 7, + 4, + -2, + -8, + -16, + -23, + -30, + -28, + -23, + -20, + -11, + -11, + -8, + 5, + 2, + -3, + -1, + -11, + -15, + -10, + -13, + -8, + -8, + -12, + -9, + -10, + -15, + -8, + -4, + -3, + 7, + 6, + 13, + 20, + 25, + 24, + 25, + 27, + 28, + 25, + 23, + 22, + 27, + 28, + 27, + 30, + 28, + 26, + 20, + 16, + 13, + 7, + 2, + 1, + 6, + 3, + -4, + -6, + -13, + -18, + -19, + -21, + -15, + -3, + -1, + 10, + 16, + 17, + 20, + 24, + 28, + 28, + 26, + 26, + 28, + 27, + 24, + 23, + 20, + 20, + 24, + 20, + 17, + 14, + 6, + 0, + 2, + 1, + 0, + -3, + -7, + -12, + -18, + -29, + -28, + -30, + -32, + -23, + -27, + -25, + -20, + -17, + -13, + -11, + -14, + -17, + -21, + -22, + -18, + -11, + -12, + -6, + -8, + -9, + -5, + -6, + -10, + -18, + -19, + -16, + -13, + -9, + -6, + -7, + -13, + -10, + -14, + -22, + -30, + -37, + -35, + -37, + -35, + -34, + -36, + -30, + -23, + -17, + -16, + -16, + -11, + -6, + -2, + 3, + 7, + 7, + 6, + 7, + 7, + 13, + 21, + 20, + 22, + 23, + 22, + 24, + 17, + 5, + -1, + -2, + -8, + -13, + -14, + -17, + -24, + -28, + -23, + -22, + -19, + -12, + -14, + -10, + -14, + -21, + -20, + -21, + -22, + -13, + -6, + -1, + 6, + 4, + 10, + 11, + 8, + 10, + 10, + 17, + 20, + 27, + 34, + 32, + 26, + 26, + 24, + 17, + 13, + 6, + 9, + 12, + 15, + 17, + 12, + 11, + 9, + 3, + -3, + -3, + -8, + -9, + -4, + -2, + -2, + 2, + 1, + -1, + -3, + -7, + -8, + -11, + -15, + -8, + -5, + 1, + 9, + 7, + 10, + 13, + 17, + 14, + 12, + 8, + 6, + 3, + 6, + 9, + 8, + 5, + 0, + -2, + 1, + 1, + -3, + -6, + -12, + -17, + -17, + -23, + -28, + -33, + -31, + -29, + -30, + -35, + -28, + -25, + -17, + -5, + 0, + 6, + 10, + 14, + 27, + 31, + 26, + 31, + 30, + 32, + 41, + 42, + 42, + 43, + 34, + 32, + 21, + 12, + 2, + 1, + -3, + -1, + 8, + 13, + 20, + 19, + 18, + 19, + 13, + 8, + 5, + 7, + 6, + 7, + 6, + 4, + 3, + -2, + 0, + 2, + -4, + -1, + -3, + 2, + 12, + 22, + 33, + 32, + 31, + 35, + 35, + 34, + 32, + 26, + 27, + 26, + 21, + 17, + 10, + 1, + -3, + -14, + -21, + -19, + -21, + -19, + -24, + -24, + -19, + -16, + -13, + -16, + -13, + -15, + -17, + -12, + -9, + -4, + 7, + 19, + 27, + 33, + 37, + 34, + 35, + 30, + 24, + 23, + 25, + 21, + 20, + 18, + 15, + 12, + 13, + 8, + 2, + -4, + -12, + -18, + -17, + -14, + -10, + -14, + -8, + -14, + -14, + -12, + -14, + -19, + -23, + -31, + -32, + -28, + -30, + -22, + -20, + -13, + 1, + 0, + 6, + 14, + 15, + 20, + 22, + 20, + 16, + 9, + 2, + 1, + 3, + 6, + 7, + 9, + 10, + 14, + 17, + 16, + 14, + 4, + -7, + -16, + -31, + -40, + -41, + -40, + -38, + -34, + -40, + -37, + -33, + -28, + -22, + -17, + -11, + -10, + -12, + -5, + -5, + -8, + -4, + 0, + -1, + 1, + 1, + 6, + 11, + 14, + 22, + 25, + 28, + 31, + 32, + 32, + 31, + 31, + 20, + 13, + 12, + 5, + 4, + 4, + 2, + 0, + -3, + -6, + -8, + -4, + -4, + -4, + -1, + 7, + 9, + 10, + 13, + 13, + 16, + 10, + 7, + 3, + 6, + 8, + 8, + 15, + 20, + 23, + 18, + 15, + 12, + 4, + 1, + 0, + -4, + -4, + -1, + 8, + 11, + 13, + 21, + 24, + 19, + 12, + 2, + -5, + -11, + -15, + -17, + -17, + -19, + -23, + -28, + -34, + -33, + -37, + -29, + -27, + -24, + -17, + -13, + -8, + -6, + -2, + 5, + 3, + 4, + -2, + -5, + -4, + 0, + 2, + 3, + 1, + -5, + -5, + -6, + -11, + -11, + -15, + -15, + -19, + -17, + -17, + -21, + -23, + -21, + -22, + -24, + -28, + -27, + -25, + -15, + -8, + -1, + 2, + 2, + 3, + 3, + 2, + -2, + 0, + 1, + -1, + 2, + 5, + 7, + 2, + 0, + 2, + -6, + -9, + -8, + -6, + -3, + -3, + 3, + 0, + 5, + 0, + 0, + -5, + -12, + -13, + -20, + -14, + -14, + -6, + -5, + -2, + 0, + 6, + 11, + 9, + 9, + 11, + 10, + 13, + 19, + 26, + 29, + 36, + 37, + 40, + 35, + 27, + 20, + 13, + 6, + 3, + -1, + -1, + -1, + -3, + -6, + -8, + -14, + -16, + -25, + -28, + -23, + -21, + -24, + -22, + -22, + -22, + -24, + -28, + -35, + -43, + -42, + -37, + -29, + -20, + -5, + 2, + 10, + 23, + 28, + 30, + 31, + 30, + 39, + 43, + 40, + 41, + 43, + 43, + 38, + 29, + 18, + 14, + 12, + 3, + 6, + 3, + 3, + 0, + -1, + -3, + -5, + -5, + -8, + -8, + -10, + -6, + -1, + 1, + 5, + 1, + 2, + 6, + 0, + -3, + -7, + -13, + -10, + -7, + -8, + -7, + -3, + -5, + -4, + -4, + -4, + -5, + -2, + 2, + 3, + 6, + 4, + 3, + -1, + -2, + -5, + -16, + -22, + -31, + -39, + -38, + -42, + -47, + -42, + -42, + -35, + -27, + -30, + -28, + -25, + -26, + -24, + -20, + -19, + -19, + -19, + -19, + -14, + -16, + -13, + -9, + -10, + -1, + 8, + 17, + 21, + 28, + 26, + 28, + 24, + 14, + 8, + 2, + 0, + -4, + -4, + -13, + -16, + -16, + -13, + -12, + -7, + -5, + 0, + -4, + -1, + 2, + 4, + 8, + 8, + 10, + 10, + 10, + 14, + 16, + 17, + 23, + 20, + 27, + 27, + 27, + 21, + 14, + 11, + 0, + -4, + -8, + -8, + -1, + -1, + 1, + 6, + 8, + 23, + 22, + 23, + 23, + 25, + 26, + 26, + 22, + 21, + 20, + 22, + 17, + 12, + 8, + 3, + -2, + -2, + -4, + -5, + -3, + 1, + 7, + 6, + 8, + 9, + 12, + 6, + 1, + -4, + -8, + -6, + -3, + -4, + -5, + -3, + -7, + -6, + -6, + -11, + -11, + -19, + -23, + -26, + -28, + -34, + -41, + -41, + -44, + -45, + -47, + -40, + -39, + -33, + -29, + -21, + -14, + -16, + -6, + -7, + -3, + 1, + 6, + 8, + 11, + 14, + 14, + 15, + 15, + 18, + 18, + 16, + 17, + 12, + 15, + 20, + 21, + 19, + 21, + 23, + 22, + 21, + 16, + 12, + 8, + 7, + 7, + 10, + 13, + 13, + 16, + 16, + 16, + 16, + 15, + 15, + 12, + 14, + 14, + 15, + 12, + 11, + 17, + 19, + 19, + 14, + 13, + 15, + 17, + 18, + 20, + 24, + 27, + 24, + 19, + 11, + 10, + 1, + 0, + 0, + -1, + 3, + 8, + 16, + 18, + 17, + 22, + 22, + 21, + 19, + 7, + 0, + 1, + -1, + -2, + -1, + -6, + -8, + -12, + -14, + -20, + -21, + -24, + -19, + -9, + -4, + -3, + 2, + 2, + 3, + 0, + -10, + -19, + -23, + -29, + -31, + -35, + -29, + -33, + -28, + -25, + -25, + -19, + -22, + -23, + -24, + -21, + -17, + -15, + -17, + -13, + -15, + -12, + -15, + -14, + -14, + -12, + -9, + -5, + 1, + 9, + 13, + 13, + 17, + 17, + 15, + 11, + 12, + 8, + 13, + 20, + 24, + 30, + 29, + 33, + 30, + 26, + 23, + 13, + 9, + 4, + 3, + 3, + 5, + 3, + 2, + 5, + 3, + 2, + 1, + 3, + 6, + 10, + 14, + 19, + 23, + 21, + 20, + 21, + 17, + 11, + 5, + -3, + -7, + -12, + -15, + -16, + -13, + -15, + -13, + -7, + -4, + -5, + -5, + -1, + 5, + 11, + 8, + 7, + -2, + -2, + -5, + -6, + -1, + -2, + 0, + 2, + 8, + 13, + 15, + 17, + 15, + 16, + 10, + 13, + 3, + -1, + -4, + -4, + -4, + 0, + 8, + 13, + 15, + 9, + 11, + 9, + 12, + 9, + 10, + 10, + 5, + 11, + 16, + 21, + 20, + 15, + 13, + 5, + 3, + -3, + 1, + 1, + 0, + -4, + -7, + -9, + -7, + -9, + -10, + -7, + -6, + -3, + -2, + -3, + -3, + -6, + -12, + -16, + -22, + -21, + -26, + -28, + -25, + -24, + -23, + -23, + -28, + -32, + -29, + -26, + -26, + -23, + -29, + -23, + -16, + -11, + -7, + -9, + -10, + -12, + -18, + -20, + -20, + -26, + -23, + -16, + -17, + -10, + -7, + 0, + 3, + -2, + 0, + -4, + -7, + -8, + -6, + -3, + -7, + -5, + -5, + 1, + 0, + -3, + -2, + -3, + 5, + 7, + 10, + 19, + 17, + 22, + 21, + 20, + 16, + 8, + 9, + 10, + 12, + 20, + 28, + 31, + 28, + 28, + 26, + 21, + 14, + 8, + 5, + 4, + 5, + 8, + 9, + 9, + 13, + 17, + 16, + 14, + 20, + 17, + 13, + 16, + 17, + 18, + 18, + 15, + 11, + 5, + -2, + -8, + -15, + -17, + -17, + -24, + -24, + -23, + -18, + -13, + -13, + -9, + -7, + -4, + 0, + 3, + 6, + 2, + 2, + -4, + -5, + -5, + -4, + -4, + -2, + 2, + 6, + 10, + 7, + 4, + 2, + -2, + -3, + -8, + -10, + -14, + -27, + -29, + -37, + -36, + -29, + -27, + -19, + -7, + -3, + 0, + -2, + 2, + 8, + 13, + 18, + 15, + 10, + 10, + 6, + 1, + -5, + -12, + -17, + -20, + -23, + -23, + -22, + -19, + -17, + -10, + -6, + -3, + 2, + 0, + 4, + 11, + 14, + 19, + 16, + 6, + 7, + 3, + 3, + 4, + 1, + 7, + 8, + 7, + 3, + -2, + 0, + 0, + 0, + -1, + -2, + 0, + 4, + 3, + 5, + 9, + 9, + 12, + 7, + 5, + 0, + 0, + 1, + 0, + 2, + -6, + -10, + -9, + -13, + -15, + -19, + -15, + -18, + -16, + -17, + -9, + -5, + -2, + 2, + 2, + 3, + 7, + 2, + -3, + -8, + -13, + -8, + 1, + 8, + 12, + 15, + 17, + 17, + 11, + 7, + 0, + -4, + -8, + -8, + -3, + -1, + -4, + -6, + -6, + -13, + -12, + -12, + -13, + -12, + -8, + -9, + -5, + -4, + -2, + 0, + -1, + -6, + -7, + -6, + -10, + -10, + -8, + -6, + 1, + 5, + 6, + 15, + 18, + 16, + 12, + 12, + 12, + 10, + 13, + 7, + 0, + -9, + -10, + -11, + -6, + -8, + -8, + -4, + 0, + 6, + 10, + 11, + 15, + 15, + 15, + 12, + 10, + 6, + 6, + 11, + 12, + 20, + 25, + 23, + 25, + 18, + 12, + 6, + -1, + -4, + -10, + -12, + -9, + -13, + -16, + -15, + -18, + -18, + -22, + -22, + -17, + -14, + -12, + -8, + -3, + 1, + 4, + 11, + 13, + 7, + 0, + -8, + -11, + -11, + -13, + -14, + -12, + -11, + -9, + -6, + -5, + -2, + 1, + 5, + 6, + 10, + 18, + 17, + 15, + 13, + 11, + 12, + 13, + 10, + 9, + 13, + 16, + 16, + 13, + 11, + 6, + 5, + 0, + -5, + -4, + -3, + 2, + 6, + 5, + 6, + 11, + 14, + 20, + 23, + 28, + 27, + 22, + 24, + 23, + 22, + 16, + 17, + 12, + 7, + -1, + -9, + -10, + -9, + -9, + -13, + -11, + -9, + -2, + -2, + -7, + -8, + -6, + -7, + -12, + -12, + -10, + 0, + 5, + 11, + 13, + 11, + 10, + 7, + 3, + 0, + 0, + 3, + 10, + 14, + 16, + 18, + 19, + 21, + 14, + 15, + 12, + 7, + 6, + 7, + 9, + 7, + 11, + 6, + 4, + 4, + -1, + -9, + -12, + -12, + -14, + -9, + -9, + -6, + -5, + -4, + -6, + -7, + -12, + -15, + -17, + -27, + -23, + -20, + -19, + -19, + -18, + -24, + -20, + -25, + -28, + -33, + -31, + -29, + -27, + -15, + -12, + -7, + -3, + 1, + -3, + -3, + -5, + -8, + -6, + 0, + 13, + 17, + 24, + 25, + 23, + 24, + 18, + 8, + -3, + -4, + -4, + -7, + -3, + 1, + 4, + 7, + 9, + 10, + 14, + 14, + 20, + 28, + 35, + 38, + 42, + 43, + 43, + 39, + 30, + 27, + 19, + 15, + 8, + 10, + 12, + 19, + 25, + 26, + 27, + 23, + 22, + 15, + 10, + 6, + 8, + 4, + 6, + 6, + 3, + 7, + 7, + 15, + 11, + 7, + 6, + 5, + 9, + 6, + 0, + -3, + -14, + -21, + -21, + -30, + -39, + -42, + -40, + -37, + -37, + -36, + -32, + -30, + -24, + -21, + -22, + -23, + -24, + -28, + -31, + -31, + -29, + -27, + -30, + -31, + -31, + -31, + -34, + -33, + -34, + -26, + -21, + -15, + -10, + -5, + -3, + -2, + -3, + -6, + -5, + -11, + -14, + -10, + -5, + 0, + 9, + 10, + 18, + 21, + 19, + 21, + 11, + 7, + 4, + 6, + 6, + 7, + 3, + -6, + -9, + -16, + -23, + -24, + -23, + -26, + -18, + -16, + -11, + -8, + 0, + 6, + 5, + 6, + 10, + 8, + 8, + 16, + 24, + 24, + 23, + 24, + 24, + 24, + 18, + 9, + 4, + -3, + -11, + -16, + -15, + -18, + -14, + -12, + -9, + -3, + -4, + -1, + 8, + 11, + 10, + 19, + 21, + 21, + 23, + 20, + 22, + 15, + 9, + 7, + 5, + 3, + 1, + 12, + 13, + 10, + 18, + 23, + 31, + 37, + 40, + 36, + 38, + 40, + 40, + 38, + 27, + 24, + 21, + 14, + 12, + 12, + 7, + 7, + 15, + 18, + 19, + 18, + 17, + 18, + 14, + 12, + 11, + 7, + 5, + 7, + 9, + 9, + 15, + 14, + 15, + 18, + 16, + 7, + 0, + -5, + -6, + -6, + -6, + -1, + 7, + 9, + 12, + 6, + 4, + 4, + 2, + -1, + 2, + 3, + 3, + 5, + 4, + -1, + -13, + -19, + -29, + -34, + -39, + -43, + -49, + -54, + -53, + -55, + -55, + -56, + -59, + -58, + -49, + -41, + -32, + -19, + -10, + -2, + -4, + -1, + -6, + -19, + -27, + -26, + -27, + -27, + -21, + -22, + -20, + -26, + -26, + -20, + -20, + -20, + -21, + -17, + -18, + -7, + -6, + -6, + -5, + -1, + 7, + 18, + 10, + 16, + 25, + 24, + 31, + 30, + 32, + 30, + 26, + 24, + 22, + 23, + 21, + 23, + 21, + 24, + 19, + 17, + 13, + 12, + 15, + 6, + 2, + -5, + -9, + -13, + -10, + -5, + 1, + 10, + 13, + 17, + 13, + 8, + 5, + 5, + 6, + 5, + 13, + 19, + 16, + 14, + 12, + 7, + 15, + 18, + 19, + 16, + 4, + -1, + 0, + -1, + -2, + -9, + -15, + -19, + -21, + -13, + -13, + -10, + -7, + -7, + -7, + -6, + -11, + -22, + -18, + -19, + -22, + -22, + -19, + -18, + -10, + -7, + -9, + -7, + -12, + -16, + -20, + -27, + -35, + -37, + -37, + -33, + -24, + -14, + -4, + 8, + 14, + 19, + 19, + 16, + 12, + 6, + 2, + -5, + -6, + -11, + -17, + -16, + -14, + -13, + -12, + -17, + -21, + -22, + -24, + -18, + -14, + -12, + -1, + 4, + 9, + 17, + 14, + 9, + 13, + 14, + 13, + 14, + 14, + 12, + 11, + 15, + 11, + 16, + 21, + 20, + 20, + 22, + 31, + 30, + 26, + 15, + 13, + 6, + 8, + 5, + 1, + -5, + -3, + 2, + 9, + 14, + 13, + 16, + 17, + 18, + 13, + 10, + 8, + 7, + 9, + 12, + 21, + 23, + 23, + 21, + 19, + 16, + 14, + 5, + -4, + -12, + -15, + -16, + -12, + -9, + -12, + -14, + -17, + -16, + -15, + -14, + -15, + -28, + -27, + -24, + -12, + -8, + -3, + 3, + 9, + 15, + 18, + 25, + 25, + 31, + 32, + 35, + 36, + 33, + 36, + 24, + 13, + 2, + -11, + -19, + -18, + -18, + -10, + -6, + -4, + 0, + -3, + -3, + -15, + -18, + -17, + -9, + -7, + 2, + 5, + 7, + 6, + 2, + -2, + -12, + -16, + -16, + -9, + -3, + 6, + 8, + 15, + 17, + 16, + 18, + 11, + 5, + -4, + -8, + -17, + -16, + -22, + -24, + -25, + -28, + -23, + -19, + -11, + -3, + 5, + 11, + 22, + 26, + 29, + 24, + 14, + 12, + 7, + 6, + -2, + -1, + 2, + 10, + 23, + 33, + 36, + 32, + 31, + 16, + 3, + -4, + -3, + -3, + 1, + 8, + 11, + 13, + 12, + 8, + 3, + 5, + 3, + 1, + -1, + 4, + 2, + 3, + 8, + 5, + 5, + 1, + -2, + -1, + -3, + -1, + 5, + 8, + 10, + 17, + 17, + 15, + 19, + 27, + 18, + 21, + 23, + 19, + 20, + 15, + 1, + -7, + -18, + -24, + -24, + -33, + -28, + -32, + -30, + -30, + -30, + -30, + -29, + -30, + -41, + -43, + -50, + -51, + -49, + -42, + -32, + -19, + -10, + 0, + 4, + -2, + 5, + 9, + 8, + 12, + 19, + 17, + 10, + 9, + 3, + 1, + -4, + -8, + -4, + 0, + 5, + 7, + 10, + 9, + 12, + 0, + -6, + -7, + -13, + -16, + -10, + -10, + -9, + -1, + -1, + -2, + -6, + -11, + -14, + -17, + -18, + -10, + -3, + -3, + 0, + 6, + 1, + 6, + 4, + 3, + 3, + 9, + 16, + 22, + 28, + 27, + 32, + 18, + 21, + 25, + 20, + 21, + 18, + 18, + 22, + 23, + 15, + 8, + -3, + -9, + -10, + -13, + -8, + 3, + 7, + 18, + 26, + 23, + 26, + 30, + 17, + 11, + 9, + -1, + 0, + 2, + 2, + 12, + 15, + 6, + 1, + 0, + -5, + 2, + 1, + -3, + -1, + -6, + -2, + -4, + -11, + -18, + -30, + -38, + -36, + -33, + -32, + -27, + -19, + -18, + -14, + -13, + -16, + -11, + -12, + -12, + -4, + 0, + 7, + 13, + 13, + 10, + 11, + 6, + 3, + 3, + 3, + 4, + 10, + 4, + -1, + -3, + -11, + -21, + -27, + -34, + -33, + -31, + -33, + -28, + -22, + -21, + -14, + -8, + -13, + -10, + -8, + -12, + -7, + -11, + -3, + 3, + 5, + 7, + 7, + -1, + -12, + -13, + -17, + -21, + -8, + -2, + 4, + 7, + 13, + 18, + 18, + 16, + 15, + 13, + 11, + 15, + 13, + 12, + 17, + 18, + 15, + 15, + 11, + -3, + -1, + 2, + 11, + 15, + 10, + 18, + 13, + 10, + 12, + 9, + 2, + 2, + 4, + -1, + 6, + 9, + 11, + 5, + 7, + 13, + 8, + 9, + 10, + 11, + 9, + 7, + 11, + 5, + 3, + 1, + -9, + -19, + -31, + -40, + -42, + -33, + -27, + -24, + -22, + -20, + -25, + -20, + -12, + -17, + -23, + -23, + -25, + -25, + -20, + -18, + -17, + -19, + -15, + -22, + -20, + -19, + -13, + -8, + -12, + 0, + 2, + -6, + -1, + -5, + -15, + -10, + -12, + -19, + -8, + -6, + -3, + 9, + 5, + 12, + 22, + 10, + 9, + 12, + 5, + 8, + 28, + 13, + 20, + 25, + 11, + 16, + 19, + 10, + 15, + 14, + 6, + 23, + 19, + 18, + 32, + 17, + 12, + 19, + -1, + -8, + 11, + -4, + -8, + 9, + -4, + -6, + 0, + -10, + -7, + -3, + -8, + -11, + -11, + -23, + -7, + -4, + -4, + 14, + 6, + 4, + 9, + 3, + -4, + 4, + 2, + 9, + 26, + 19, + 26, + 33, + 22, + 22, + 24, + 13, + 20, + 18, + 18, + 28, + 28, + 19, + 24, + 16, + -1, + 1, + -12, + -34, + -28, + -25, + -27, + -13, + 6, + 8, + 21, + 25, + 22, + 19, + 3, + 4, + 0, + -5, + 6, + 8, + 1, + 6, + 8, + -4, + -3, + -10, + -23, + -17, + -9, + -10, + 3, + 6, + -1, + 3, + -10, + -22, + -28, + -49, + -49, + -36, + -29, + -10, + 8, + -1, + 4, + 14, + -3, + -14, + -5, + -16, + -10, + 8, + 7, + 21, + 24, + 17, + 25, + 15, + -4, + 13, + -7, + -23, + 0, + -7, + -14, + 12, + 1, + -18, + -10, + -27, + -43, + -31, + -34, + -19, + -3, + -10, + 15, + 20, + -7, + 10, + 9, + -20, + 7, + 28, + 14, + 42, + 54, + 32, + 34, + 24, + 5, + 10, + -11, + -13, + 11, + -6, + -4, + 31, + 7, + 0, + 34, + 3, + -9, + 5, + -24, + -33, + -14, + -11, + -1, + 8, + 0, + 10, + 7, + -7, + 11, + 10, + -6, + 17, + 16, + 0, + 10, + 3, + -26, + -23, + -33, + -39, + -26, + -29, + -18, + -6, + -9, + -1, + 5, + -11, + -6, + 7, + -6, + 1, + 13, + 8, + 1, + 3, + -13, + -23, + -25, + -33, + -28, + -21, + -9, + 2, + 4, + 1, + 8, + 4, + -13, + -5, + -12, + -14, + 3, + 14, + 18, + 26, + 30, + 21, + 20, + 15, + 15, + 10, + 5, + 13, + 11, + 20, + 25, + 29, + 18, + 19, + 9, + -10, + -15, + -13, + -12, + 1, + 16, + 20, + 30, + 39, + 37, + 21, + 15, + 3, + -7, + -9, + -1, + 2, + -6, + -7, + -10, + -20, + -19, + -19, + -31, + -25, + -12, + -15, + -13, + -17, + -18, + -14, + -24, + -24, + -18, + -28, + -24, + -3, + 1, + 17, + 46, + 48, + 43, + 46, + 34, + 12, + 6, + -14, + -19, + -10, + -14, + 3, + 15, + 3, + 7, + 7, + -13, + 4, + 9, + -2, + 3, + 22, + 19, + 25, + 41, + 48, + 46, + 36, + 42, + 40, + 24, + 33, + 50, + 29, + 30, + 57, + 35, + 13, + 29, + 17, + -9, + 5, + 15, + 7, + 13, + 38, + 47, + 40, + 56, + 72, + 42, + 29, + 40, + 18, + 14, + 36, + 52, + 50, + 58, + 55, + 42, + 22, + 20, + 13, + -8, + 8, + 32, + 26, + 41, + 70, + 48, + 51, + 65, + 36, + 27, + 23, + 4, + 5, + 1, + -3, + 2, + -8, + -23, + -6, + -30, + -46, + -24, + -40, + -45, + -22, + -32, + -35, + -24, + -50, + -41, + -35, + -56, + -38, + -29, + -55, + -25, + -7, + -40, + -26, + -25, + -63, + -51, + -40, + -61, + -47, + -38, + -38, + -5, + 2, + 3, + 26, + -1, + -7, + 8, + -20, + -17, + 10, + -14, + -6, + 41, + 24, + 27, + 52, + 26, + 13, + 25, + 5, + -6, + 2, + -7, + -2, + 10, + 4, + 29, + 36, + 30, + 74, + 93, + 91, + 131, + 150, + 132, + 167, + 177, + 158, + 189, + 188, + 178, + 200, + 199, + 187, + 212, + 202, + 188, + 210, + 188, + 173, + 187, + 175, + 183, + 215, + 218, + 236, + 264, + 253, + 279, + 296, + 275, + 290, + 288, + 261, + 261, + 261, + 230, + 216, + 199, + 157, + 160, + 147, + 115, + 108, + 84, + 50, + 32, + 7, + -30, + -56, + -96, + -130, + -146, + -179, + -199, + -223, + -255, + -280, + -293, + -326, + -341, + -352, + -391, + -410, + -429, + -464, + -489, + -507, + -538, + -559, + -577, + -602, + -634, + -656, + -679, + -696, + -702, + -700, + -699, + -700, + -687, + -666, + -665, + -656, + -634, + -626, + -609, + -572, + -539, + -518, + -484, + -462, + -444, + -418, + -390, + -364, + -336, + -295, + -245, + -210, + -175, + -127, + -97, + -63, + -28, + 10, + 45, + 83, + 121, + 167, + 222, + 272, + 324, + 369, + 396, + 439, + 485, + 502, + 536, + 571, + 585, + 618, + 656, + 676, + 705, + 729, + 744, + 767, + 776, + 786, + 798, + 796, + 813, + 849, + 855, + 865, + 883, + 862, + 843, + 834, + 794, + 781, + 778, + 767, + 746, + 744, + 721, + 702, + 681, + 638, + 607, + 562, + 521, + 490, + 447, + 398, + 361, + 313, + 255, + 204, + 123, + 20, + -59, + -143, + -217, + -270, + -328, + -400, + -462, + -529, + -607, + -666, + -737, + -797, + -854, + -906, + -936, + -944, + -955, + -965, + -976, + -993, + -1003, + -1007, + -1032, + -1040, + -1045, + -1055, + -1039, + -1016, + -1003, + -990, + -995, + -1026, + -1046, + -1070, + -1079, + -1058, + -1060, + -1062, + -1028, + -1010, + -1006, + -991, + -1000, + -1004, + -987, + -981, + -958, + -921, + -890, + -852, + -798, + -754, + -713, + -681, + -682, + -658, + -617, + -585, + -524, + -452, + -404, + -332, + -258, + -224, + -183, + -144, + -132, + -94, + -64, + -31, + 37, + 99, + 147, + 219, + 280, + 329, + 389, + 439, + 483, + 563, + 632, + 702, + 799, + 884, + 965, + 1050, + 1107, + 1150, + 1209, + 1260, + 1308, + 1383, + 1446, + 1514, + 1582, + 1632, + 1679, + 1727, + 1770, + 1804, + 1837, + 1872, + 1916, + 1961, + 1999, + 2038, + 2071, + 2089, + 2097, + 2107, + 2091, + 2084, + 2072, + 2051, + 2021, + 1998, + 1940, + 1868, + 1814, + 1734, + 1641, + 1559, + 1480, + 1395, + 1305, + 1213, + 1115, + 1015, + 901, + 785, + 667, + 520, + 381, + 256, + 110, + -26, + -141, + -284, + -417, + -528, + -670, + -805, + -935, + -1080, + -1206, + -1324, + -1438, + -1527, + -1622, + -1725, + -1798, + -1879, + -1956, + -2006, + -2063, + -2128, + -2166, + -2201, + -2238, + -2257, + -2292, + -2316, + -2337, + -2357, + -2356, + -2362, + -2382, + -2375, + -2368, + -2367, + -2358, + -2337, + -2329, + -2318, + -2296, + -2273, + -2240, + -2195, + -2140, + -2095, + -2044, + -1990, + -1932, + -1872, + -1803, + -1737, + -1673, + -1602, + -1520, + -1428, + -1325, + -1219, + -1112, + -1006, + -896, + -780, + -681, + -591, + -481, + -388, + -294, + -189, + -85, + 30, + 148, + 252, + 348, + 466, + 579, + 692, + 811, + 918, + 1041, + 1162, + 1271, + 1389, + 1507, + 1611, + 1735, + 1864, + 1965, + 2085, + 2203, + 2312, + 2436, + 2536, + 2614, + 2697, + 2760, + 2812, + 2886, + 2956, + 3010, + 3066, + 3088, + 3098, + 3120, + 3110, + 3101, + 3106, + 3108, + 3130, + 3149, + 3139, + 3122, + 3085, + 3016, + 2951, + 2874, + 2770, + 2671, + 2559, + 2435, + 2315, + 2198, + 2059, + 1915, + 1761, + 1570, + 1387, + 1185, + 984, + 787, + 601, + 413, + 224, + 40, + -158, + -348, + -560, + -760, + -960, + -1147, + -1312, + -1471, + -1621, + -1779, + -1925, + -2069, + -2206, + -2333, + -2463, + -2570, + -2664, + -2743, + -2811, + -2860, + -2886, + -2934, + -2976, + -3015, + -3057, + -3074, + -3076, + -3079, + -3060, + -3032, + -2998, + -2950, + -2920, + -2893, + -2863, + -2837, + -2806, + -2761, + -2715, + -2662, + -2607, + -2554, + -2486, + -2402, + -2325, + -2264, + -2190, + -2127, + -2063, + -1989, + -1932, + -1862, + -1788, + -1724, + -1640, + -1545, + -1455, + -1346, + -1234, + -1112, + -984, + -859, + -735, + -610, + -494, + -384, + -280, + -176, + -68, + 40, + 140, + 244, + 363, + 478, + 596, + 739, + 876, + 1001, + 1128, + 1240, + 1352, + 1474, + 1595, + 1717, + 1853, + 1972, + 2093, + 2215, + 2328, + 2432, + 2533, + 2641, + 2744, + 2855, + 2949, + 3055, + 3157, + 3242, + 3329, + 3415, + 3479, + 3528, + 3569, + 3588, + 3617, + 3649, + 3676, + 3708, + 3747, + 3751, + 3753, + 3744, + 3693, + 3640, + 3576, + 3470, + 3369, + 3248, + 3098, + 2976, + 2838, + 2690, + 2557, + 2395, + 2222, + 2055, + 1872, + 1675, + 1488, + 1279, + 1057, + 851, + 623, + 393, + 180, + -74, + -315, + -537, + -771, + -979, + -1161, + -1373, + -1558, + -1729, + -1932, + -2110, + -2294, + -2478, + -2636, + -2785, + -2917, + -3007, + -3094, + -3183, + -3247, + -3319, + -3402, + -3450, + -3510, + -3564, + -3595, + -3622, + -3635, + -3627, + -3635, + -3639, + -3620, + -3620, + -3610, + -3596, + -3581, + -3535, + -3495, + -3455, + -3410, + -3361, + -3323, + -3265, + -3202, + -3141, + -3078, + -3001, + -2919, + -2830, + -2739, + -2640, + -2540, + -2430, + -2320, + -2192, + -2057, + -1909, + -1761, + -1603, + -1422, + -1244, + -1059, + -887, + -726, + -570, + -425, + -256, + -92, + 69, + 238, + 411, + 557, + 728, + 910, + 1066, + 1229, + 1403, + 1561, + 1727, + 1895, + 2050, + 2208, + 2352, + 2492, + 2638, + 2765, + 2893, + 3025, + 3145, + 3263, + 3387, + 3496, + 3595, + 3707, + 3804, + 3884, + 3975, + 4046, + 4105, + 4167, + 4204, + 4220, + 4237, + 4243, + 4247, + 4260, + 4255, + 4251, + 4246, + 4201, + 4143, + 4092, + 3996, + 3885, + 3772, + 3604, + 3435, + 3283, + 3086, + 2923, + 2742, + 2535, + 2341, + 2130, + 1887, + 1649, + 1411, + 1137, + 915, + 659, + 398, + 163, + -81, + -351, + -580, + -814, + -1069, + -1262, + -1476, + -1689, + -1850, + -2043, + -2237, + -2395, + -2591, + -2763, + -2918, + -3095, + -3224, + -3319, + -3435, + -3508, + -3582, + -3698, + -3772, + -3858, + -3950, + -4008, + -4047, + -4088, + -4093, + -4085, + -4098, + -4064, + -4052, + -4057, + -4033, + -4028, + -4018, + -3991, + -3971, + -3933, + -3865, + -3802, + -3727, + -3633, + -3562, + -3477, + -3392, + -3300, + -3210, + -3115, + -3018, + -2924, + -2819, + -2721, + -2606, + -2490, + -2381, + -2246, + -2111, + -1963, + -1810, + -1638, + -1460, + -1293, + -1132, + -980, + -828, + -666, + -496, + -322, + -125, + 72, + 264, + 470, + 676, + 879, + 1087, + 1280, + 1457, + 1633, + 1799, + 1970, + 2152, + 2327, + 2501, + 2678, + 2840, + 3007, + 3165, + 3301, + 3434, + 3558, + 3667, + 3791, + 3912, + 4023, + 4140, + 4257, + 4359, + 4475, + 4554, + 4614, + 4656, + 4682, + 4697, + 4726, + 4749, + 4775, + 4810, + 4812, + 4812, + 4810, + 4768, + 4697, + 4620, + 4502, + 4368, + 4210, + 4031, + 3860, + 3663, + 3472, + 3291, + 3076, + 2849, + 2642, + 2392, + 2140, + 1890, + 1610, + 1325, + 1064, + 782, + 494, + 231, + -50, + -329, + -593, + -861, + -1112, + -1345, + -1588, + -1812, + -2022, + -2257, + -2467, + -2682, + -2924, + -3126, + -3317, + -3495, + -3630, + -3737, + -3855, + -3941, + -4031, + -4128, + -4200, + -4281, + -4348, + -4388, + -4427, + -4449, + -4444, + -4450, + -4458, + -4452, + -4464, + -4460, + -4451, + -4444, + -4425, + -4384, + -4344, + -4289, + -4234, + -4160, + -4076, + -4000, + -3917, + -3837, + -3753, + -3669, + -3558, + -3460, + -3354, + -3230, + -3111, + -2966, + -2824, + -2665, + -2495, + -2333, + -2151, + -1951, + -1752, + -1554, + -1367, + -1222, + -1053, + -882, + -716, + -520, + -331, + -141, + 62, + 270, + 476, + 707, + 923, + 1133, + 1349, + 1534, + 1735, + 1943, + 2124, + 2317, + 2511, + 2668, + 2839, + 3002, + 3140, + 3317, + 3481, + 3615, + 3771, + 3920, + 4050, + 4196, + 4319, + 4430, + 4556, + 4657, + 4765, + 4868, + 4945, + 4999, + 5057, + 5075, + 5100, + 5123, + 5133, + 5134, + 5127, + 5104, + 5084, + 5058, + 4968, + 4896, + 4750, + 4575, + 4381, + 4179, + 3971, + 3776, + 3590, + 3394, + 3209, + 2991, + 2800, + 2535, + 2269, + 1972, + 1654, + 1319, + 998, + 697, + 384, + 105, + -187, + -476, + -759, + -1047, + -1316, + -1579, + -1841, + -2085, + -2317, + -2550, + -2745, + -2938, + -3145, + -3326, + -3523, + -3706, + -3859, + -3998, + -4124, + -4218, + -4288, + -4346, + -4386, + -4437, + -4495, + -4550, + -4619, + -4680, + -4732, + -4779, + -4813, + -4820, + -4842, + -4825, + -4791, + -4773, + -4742, + -4715, + -4709, + -4683, + -4652, + -4605, + -4527, + -4428, + -4315, + -4194, + -4086, + -3978, + -3872, + -3779, + -3685, + -3569, + -3458, + -3313, + -3121, + -2921, + -2693, + -2454, + -2230, + -1998, + -1783, + -1588, + -1414, + -1240, + -1069, + -886, + -690, + -473, + -256, + -36, + 170, + 384, + 594, + 797, + 1015, + 1235, + 1449, + 1664, + 1882, + 2098, + 2311, + 2504, + 2681, + 2843, + 3019, + 3171, + 3337, + 3534, + 3709, + 3885, + 4072, + 4235, + 4380, + 4524, + 4641, + 4746, + 4864, + 4979, + 5087, + 5213, + 5308, + 5393, + 5450, + 5468, + 5475, + 5472, + 5452, + 5462, + 5467, + 5453, + 5451, + 5425, + 5342, + 5255, + 5113, + 4914, + 4725, + 4512, + 4273, + 4053, + 3866, + 3632, + 3436, + 3205, + 2955, + 2705, + 2420, + 2095, + 1794, + 1503, + 1195, + 941, + 639, + 342, + 56, + -269, + -601, + -894, + -1208, + -1499, + -1736, + -1994, + -2239, + -2426, + -2652, + -2891, + -3099, + -3361, + -3588, + -3793, + -4013, + -4183, + -4302, + -4439, + -4523, + -4613, + -4734, + -4809, + -4891, + -4999, + -5056, + -5090, + -5131, + -5092, + -5061, + -5044, + -4987, + -4954, + -4955, + -4924, + -4911, + -4873, + -4809, + -4755, + -4673, + -4555, + -4440, + -4316, + -4187, + -4088, + -3986, + -3881, + -3802, + -3717, + -3605, + -3495, + -3359, + -3207, + -3063, + -2889, + -2698, + -2504, + -2306, + -2088, + -1861, + -1627, + -1415, + -1201, + -1000, + -799, + -593, + -410, + -220, + -7, + 203, + 412, + 634, + 865, + 1126, + 1367, + 1602, + 1838, + 2052, + 2257, + 2474, + 2659, + 2863, + 3076, + 3255, + 3429, + 3617, + 3773, + 3939, + 4102, + 4222, + 4358, + 4501, + 4611, + 4733, + 4846, + 4939, + 5056, + 5147, + 5217, + 5301, + 5357, + 5388, + 5428, + 5417, + 5400, + 5430, + 5422, + 5406, + 5442, + 5446, + 5431, + 5437, + 5381, + 5304, + 5212, + 5057, + 4874, + 4683, + 4465, + 4249, + 4026, + 3767, + 3545, + 3304, + 3021, + 2741, + 2450, + 2113, + 1807, + 1490, + 1151, + 841, + 544, + 212, + -102, + -439, + -788, + -1091, + -1413, + -1730, + -2033, + -2336, + -2627, + -2854, + -3118, + -3350, + -3560, + -3781, + -4008, + -4194, + -4376, + -4524, + -4640, + -4757, + -4865, + -4945, + -5016, + -5083, + -5131, + -5170, + -5184, + -5198, + -5208, + -5211, + -5210, + -5209, + -5192, + -5174, + -5154, + -5108, + -5052, + -5002, + -4932, + -4854, + -4780, + -4704, + -4604, + -4514, + -4421, + -4309, + -4208, + -4111, + -4004, + -3880, + -3751, + -3622, + -3496, + -3367, + -3210, + -3047, + -2867, + -2654, + -2430, + -2177, + -1897, + -1651, + -1417, + -1182, + -983, + -793, + -593, + -406, + -211, + 17, + 232, + 461, + 716, + 958, + 1197, + 1441, + 1674, + 1899, + 2130, + 2355, + 2573, + 2788, + 3004, + 3220, + 3419, + 3612, + 3809, + 3973, + 4120, + 4277, + 4433, + 4573, + 4742, + 4902, + 5037, + 5165, + 5282, + 5377, + 5460, + 5539, + 5596, + 5654, + 5716, + 5741, + 5759, + 5770, + 5776, + 5762, + 5751, + 5737, + 5706, + 5675, + 5644, + 5550, + 5446, + 5324, + 5169, + 4974, + 4767, + 4530, + 4289, + 4067, + 3823, + 3621, + 3391, + 3145, + 2878, + 2575, + 2228, + 1890, + 1525, + 1149, + 807, + 473, + 145, + -152, + -454, + -769, + -1057, + -1374, + -1703, + -2033, + -2372, + -2701, + -2977, + -3258, + -3495, + -3694, + -3897, + -4089, + -4270, + -4483, + -4668, + -4840, + -5015, + -5140, + -5225, + -5304, + -5334, + -5350, + -5390, + -5398, + -5403, + -5428, + -5438, + -5449, + -5472, + -5463, + -5441, + -5401, + -5333, + -5252, + -5151, + -5051, + -4974, + -4880, + -4805, + -4729, + -4626, + -4526, + -4403, + -4248, + -4088, + -3939, + -3778, + -3617, + -3464, + -3308, + -3173, + -3027, + -2852, + -2669, + -2461, + -2233, + -1979, + -1713, + -1455, + -1216, + -996, + -796, + -610, + -397, + -198, + 21, + 272, + 517, + 775, + 1037, + 1295, + 1544, + 1790, + 2007, + 2211, + 2423, + 2634, + 2848, + 3081, + 3319, + 3551, + 3792, + 4000, + 4171, + 4303, + 4418, + 4518, + 4596, + 4679, + 4807, + 4913, + 5044, + 5172, + 5288, + 5405, + 5518, + 5609, + 5664, + 5713, + 5735, + 5735, + 5737, + 5701, + 5691, + 5656, + 5633, + 5611, + 5552, + 5475, + 5394, + 5293, + 5177, + 5064, + 4924, + 4737, + 4599, + 4420, + 4237, + 4048, + 3828, + 3623, + 3413, + 3183, + 2915, + 2622, + 2308, + 1980, + 1657, + 1261, + 901, + 549, + 205, + -85, + -383, + -688, + -969, + -1246, + -1530, + -1850, + -2206, + -2561, + -2915, + -3224, + -3482, + -3713, + -3921, + -4107, + -4287, + -4470, + -4660, + -4850, + -5057, + -5239, + -5395, + -5540, + -5619, + -5697, + -5724, + -5697, + -5675, + -5633, + -5590, + -5579, + -5530, + -5486, + -5442, + -5426, + -5391, + -5348, + -5276, + -5197, + -5124, + -5039, + -4925, + -4808, + -4677, + -4581, + -4479, + -4343, + -4218, + -4087, + -3970, + -3858, + -3729, + -3570, + -3384, + -3206, + -3020, + -2839, + -2636, + -2453, + -2287, + -2185, + -2154, + -1926, + -1562, + -1223, + -758, + -473, + -64, + 395, + 599, + 880, + 814, + 938, + 1172, + 1498, + 1928, + 2127, + 2422, + 2608, + 2841, + 2937, + 2886, + 2815, + 2985, + 3324, + 3757, + 4152, + 4481, + 4652, + 4917, + 4965, + 4766, + 4583, + 4328, + 4503, + 4815, + 5118, + 5408, + 5682, + 5956, + 6082, + 6055, + 5744, + 5426, + 5341, + 5427, + 5606, + 5882, + 6065, + 6226, + 6428, + 6477, + 6385, + 6009, + 5728, + 5552, + 5439, + 5339, + 5200, + 5008, + 4947, + 4835, + 4614, + 4330, + 3887, + 3521, + 3111, + 2460, + 1983, + 1297, + 650, + 279, + -353, + -720, + -1044, + -1518, + -1668, + -2117, + -2496, + -2743, + -3266, + -3607, + -3790, + -4149, + -4075, + -4042, + -4096, + -3981, + -4138, + -4226, + -4214, + -4503, + -4455, + -4577, + -4642, + -4346, + -4351, + -4270, + -4263, + -4522, + -4521, + -4673, + -4814, + -4731, + -4950, + -5011, + -5004, + -5288, + -5341, + -5566, + -5833, + -5783, + -5929, + -5847, + -5765, + -5828, + -5644, + -5613, + -5615, + -5428, + -5291, + -5014, + -4554, + -4277, + -3964, + -3854, + -3829, + -3612, + -3603, + -3438, + -3137, + -2831, + -2164, + -1438, + -939, + -330, + -156, + 46, + 242, + 73, + 242, + 220, + 239, + 542, + 565, + 739, + 872, + 801, + 857, + 676, + 543, + 586, + 567, + 828, + 1142, + 1490, + 1985, + 2508, + 2982, + 3438, + 3699, + 3939, + 4069, + 4178, + 4420, + 4622, + 4917, + 5338, + 5801, + 6285, + 6658, + 6963, + 7213, + 7233, + 7328, + 7176, + 7038, + 7031, + 6860, + 6957, + 6767, + 6599, + 6523, + 6212, + 6147, + 6063, + 5860, + 6020, + 6015, + 6033, + 6184, + 5722, + 5607, + 5016, + 4337, + 4063, + 3229, + 3080, + 3006, + 2804, + 3035, + 2541, + 2136, + 1879, + 1012, + 401, + -575, + -1584, + -1930, + -2278, + -2485, + -2477, + -2712, + -2747, + -2766, + -3320, + -3592, + -4188, + -4669, + -4672, + -4939, + -4789, + -4426, + -4203, + -3674, + -3563, + -3656, + -3759, + -4067, + -4257, + -4522, + -4970, + -5204, + -5237, + -5139, + -4907, + -4911, + -4917, + -4921, + -5007, + -5230, + -5654, + -6122, + -6464, + -6733, + -6948, + -7067, + -6972, + -6800, + -6520, + -6132, + -5830, + -5382, + -5091, + -4797, + -4546, + -4472, + -4362, + -4350, + -4235, + -3851, + -3454, + -3144, + -2735, + -2341, + -1845, + -1262, + -958, + -549, + -166, + 66, + 382, + 366, + 352, + 341, + 85, + -13, + -176, + -303, + -235, + -341, + -309, + -227, + -249, + -50, + 143, + 384, + 874, + 1149, + 1552, + 2155, + 2767, + 3499, + 3994, + 4460, + 4920, + 5288, + 5569, + 5704, + 5881, + 6094, + 6461, + 6653, + 6803, + 7115, + 7311, + 7521, + 7612, + 7443, + 7380, + 7124, + 6742, + 6495, + 5964, + 5656, + 5415, + 5167, + 5656, + 5813, + 6027, + 6401, + 6351, + 6787, + 7019, + 6581, + 6512, + 5965, + 5308, + 5140, + 4336, + 4147, + 3899, + 3398, + 3360, + 2830, + 2624, + 1968, + 1026, + 395, + -699, + -1424, + -2327, + -3006, + -3192, + -3435, + -3337, + -3686, + -3513, + -3350, + -3502, + -3261, + -3878, + -4005, + -4063, + -4187, + -3767, + -3598, + -3384, + -3300, + -3094, + -2857, + -3023, + -3274, + -3851, + -4352, + -4523, + -4943, + -5477, + -5612, + -5682, + -5733, + -5714, + -5965, + -6110, + -5950, + -6158, + -6548, + -6897, + -7165, + -7281, + -7352, + -7258, + -7185, + -6659, + -5946, + -5470, + -4738, + -4046, + -3707, + -3210, + -3108, + -3270, + -3227, + -3222, + -3218, + -3017, + -2943, + -2668, + -2296, + -1593, + -1061, + -811, + -403, + -513, + -361, + -128, + -595, + -633, + -991, + -1205, + -1159, + -1284, + -1330, + -1164, + -999, + -729, + -538, + -336, + 27, + 350, + 794, + 1245, + 1646, + 2446, + 3210, + 4017, + 4835, + 5271, + 5739, + 6028, + 6140, + 6212, + 6161, + 6066, + 5984, + 6081, + 5995, + 6152, + 6301, + 6278, + 6424, + 6377, + 6396, + 6362, + 6152, + 5788, + 5309, + 5071, + 4860, + 4704, + 4804, + 4919, + 5258, + 5869, + 6121, + 6365, + 6694, + 6692, + 6694, + 6532, + 6187, + 5808, + 5704, + 5302, + 4816, + 4611, + 4043, + 3775, + 3249, + 2600, + 1933, + 982, + 336, + -848, + -1538, + -2242, + -3103, + -3374, + -3756, + -3975, + -4017, + -4061, + -3972, + -3749, + -3609, + -3853, + -3850, + -3714, + -3760, + -3736, + -3914, + -3923, + -3830, + -3541, + -3649, + -3757, + -3661, + -3913, + -4038, + -4231, + -4594, + -4769, + -5009, + -5273, + -5588, + -5676, + -5937, + -5997, + -6060, + -6164, + -6414, + -6623, + -6765, + -6857, + -6771, + -6921, + -6914, + -6535, + -6187, + -5626, + -5206, + -4742, + -4189, + -3618, + -3120, + -2823, + -2606, + -2550, + -2703, + -2736, + -2626, + -2498, + -2406, + -2133, + -1852, + -1348, + -753, + -318, + 162, + 330, + 524, + 375, + 9, + -204, + -866, + -1249, + -1532, + -1669, + -1455, + -1235, + -723, + -283, + 262, + 535, + 862, + 1340, + 1712, + 2316, + 2625, + 3171, + 4015, + 4698, + 5516, + 6006, + 6452, + 6838, + 6921, + 7003, + 6735, + 6339, + 6138, + 5768, + 5575, + 5593, + 5568, + 5728, + 6041, + 6233, + 6260, + 6175, + 6048, + 5728, + 5366, + 4931, + 4340, + 4194, + 4174, + 4330, + 4743, + 5028, + 5754, + 6250, + 6598, + 7120, + 7114, + 6962, + 6675, + 6157, + 5373, + 4797, + 4081, + 3237, + 3153, + 2588, + 2143, + 1639, + 1021, + 681, + -149, + -816, + -1987, + -3003, + -3493, + -4138, + -4420, + -4607, + -4841, + -4725, + -4254, + -4033, + -3845, + -3842, + -4063, + -4035, + -4099, + -4582, + -4718, + -4779, + -4689, + -4437, + -4327, + -4352, + -4119, + -3881, + -4061, + -4345, + -4768, + -5248, + -5610, + -5920, + -6383, + -6779, + -6731, + -6673, + -6677, + -6597, + -6659, + -6619, + -6417, + -6516, + -6862, + -7017, + -7069, + -6944, + -6715, + -6376, + -6000, + -5162, + -4333, + -3577, + -2884, + -2355, + -1807, + -1366, + -1380, + -1590, + -1869, + -1962, + -1945, + -2006, + -2141, + -1960, + -1516, + -1025, + -471, + -135, + 85, + 348, + 239, + -8, + -475, + -951, + -1245, + -1520, + -1569, + -1448, + -1188, + -517, + 134, + 827, + 1585, + 2114, + 2792, + 3214, + 3651, + 4230, + 4546, + 4894, + 5321, + 5588, + 6105, + 6583, + 6877, + 7014, + 7087, + 7068, + 6876, + 6695, + 6280, + 5684, + 5385, + 5205, + 5064, + 5033, + 5028, + 5080, + 5322, + 5510, + 5461, + 5390, + 5541, + 5494, + 5443, + 5306, + 5065, + 5193, + 5338, + 5513, + 5818, + 5911, + 6345, + 6506, + 6514, + 6543, + 5981, + 5703, + 5082, + 4228, + 3517, + 2424, + 1880, + 1245, + 562, + -130, + -864, + -1156, + -1561, + -1970, + -2597, + -3357, + -3707, + -4189, + -4521, + -4975, + -5477, + -5478, + -5585, + -5445, + -5353, + -5327, + -4971, + -4580, + -4431, + -4469, + -4432, + -4422, + -4275, + -4227, + -4507, + -4745, + -4758, + -4752, + -4845, + -4933, + -5118, + -5117, + -5124, + -5324, + -5673, + -5971, + -6152, + -6366, + -6702, + -6970, + -7159, + -7136, + -6929, + -6917, + -6703, + -6520, + -6302, + -5794, + -5484, + -5123, + -4694, + -4254, + -3722, + -3334, + -2917, + -2410, + -1721, + -1010, + -584, + -312, + 27, + 321, + 327, + 214, + -17, + -363, + -402, + -550, + -638, + -469, + -315, + -86, + 142, + 242, + 387, + 448, + 458, + 423, + 321, + 194, + 285, + 417, + 717, + 1176, + 1673, + 2402, + 3144, + 3985, + 4764, + 5406, + 6056, + 6507, + 6783, + 6891, + 6868, + 6850, + 6717, + 6532, + 6359, + 6248, + 6303, + 6279, + 6140, + 6071, + 5927, + 5687, + 5480, + 5146, + 4835, + 4572, + 4447, + 4481, + 4578, + 4840, + 4936, + 5246, + 5659, + 5732, + 5856, + 5658, + 5403, + 5282, + 5004, + 4949, + 4843, + 4681, + 4884, + 4886, + 4967, + 5108, + 4781, + 4647, + 4240, + 3443, + 2768, + 1830, + 983, + 309, + -769, + -1382, + -1987, + -2553, + -2750, + -3346, + -3555, + -4052, + -4400, + -4599, + -5196, + -5437, + -5945, + -6340, + -6343, + -6554, + -6611, + -6381, + -6184, + -5681, + -5398, + -5098, + -4751, + -4529, + -4138, + -4100, + -4088, + -4044, + -4186, + -4189, + -4263, + -4453, + -4465, + -4598, + -4651, + -4726, + -4919, + -4926, + -5142, + -5286, + -5490, + -5831, + -6002, + -6341, + -6492, + -6562, + -6710, + -6553, + -6506, + -6219, + -5766, + -5521, + -5008, + -4556, + -4002, + -3293, + -2769, + -2069, + -1467, + -824, + -34, + 509, + 1034, + 1385, + 1560, + 1650, + 1664, + 1419, + 1016, + 834, + 511, + 353, + 381, + 299, + 523, + 833, + 956, + 1280, + 1492, + 1425, + 1547, + 1350, + 1143, + 1114, + 931, + 1054, + 1217, + 1583, + 2217, + 2917, + 4017, + 4965, + 5827, + 6816, + 7393, + 7875, + 8197, + 8175, + 7924, + 7578, + 7040, + 6566, + 6242, + 5746, + 5530, + 5334, + 5222, + 5237, + 5074, + 5146, + 5011, + 4902, + 4753, + 4442, + 4482, + 4254, + 4247, + 4319, + 4187, + 4516, + 4690, + 4935, + 5193, + 5229, + 5350, + 5332, + 5486, + 5386, + 5143, + 4999, + 4494, + 4304, + 3961, + 3421, + 2781, + 2032, + 1404, + 614, + -88, + -956, + -1714, + -2155, + -2684, + -3038, + -3237, + -3368, + -3423, + -3569, + -3809, + -4213, + -4533, + -4973, + -5514, + -6011, + -6663, + -7084, + -7258, + -7158, + -6947, + -6639, + -6111, + -5548, + -4887, + -4362, + -4043, + -3895, + -3940, + -4107, + -4452, + -4836, + -5143, + -5500, + -5532, + -5510, + -5485, + -5096, + -4739, + -4375, + -4065, + -4063, + -4094, + -4252, + -4576, + -4904, + -5431, + -5837, + -6190, + -6402, + -6310, + -6292, + -5992, + -5516, + -5025, + -4342, + -3899, + -3386, + -2697, + -2077, + -1493, + -994, + -392, + 232, + 931, + 1608, + 1988, + 2360, + 2589, + 2639, + 2623, + 2471, + 2121, + 1708, + 1478, + 1181, + 1167, + 1296, + 1279, + 1648, + 1859, + 2107, + 2368, + 2359, + 2390, + 2122, + 1904, + 1629, + 1418, + 1502, + 1524, + 1859, + 2357, + 3041, + 3909, + 4810, + 5751, + 6449, + 7128, + 7534, + 7767, + 7908, + 7699, + 7460, + 7032, + 6647, + 6301, + 5876, + 5556, + 5190, + 4948, + 4762, + 4576, + 4464, + 4370, + 4338, + 4275, + 4287, + 4265, + 4320, + 4221, + 4066, + 3947, + 3514, + 3379, + 3003, + 2635, + 2534, + 2078, + 2040, + 1950, + 1958, + 2152, + 2085, + 2390, + 2321, + 2319, + 2359, + 1851, + 1643, + 877, + 168, + -527, + -1245, + -1704, + -2519, + -2739, + -3251, + -3382, + -3236, + -3527, + -3294, + -3523, + -3732, + -3916, + -4434, + -4888, + -5615, + -6161, + -6729, + -7283, + -7543, + -7920, + -7865, + -7660, + -7430, + -7034, + -6758, + -6224, + -5866, + -5441, + -5076, + -4998, + -4760, + -4673, + -4539, + -4410, + -4308, + -4131, + -3992, + -3791, + -3611, + -3448, + -3213, + -3070, + -3046, + -3048, + -3168, + -3244, + -3354, + -3607, + -3834, + -4170, + -4439, + -4648, + -4864, + -4892, + -4928, + -4821, + -4524, + -4211, + -3576, + -2819, + -1968, + -929, + -19, + 1029, + 2064, + 2949, + 3716, + 4159, + 4450, + 4536, + 4503, + 4301, + 3968, + 3655, + 3242, + 2979, + 2856, + 2744, + 2750, + 2771, + 2749, + 2859, + 2850, + 2793, + 2702, + 2402, + 2179, + 1877, + 1672, + 1581, + 1543, + 1769, + 1967, + 2485, + 3089, + 3783, + 4662, + 5406, + 6246, + 6950, + 7542, + 8016, + 8200, + 8245, + 8027, + 7584, + 6958, + 6241, + 5494, + 4710, + 3974, + 3255, + 2653, + 2274, + 2038, + 1986, + 1964, + 2141, + 2321, + 2513, + 2772, + 2756, + 2743, + 2636, + 2406, + 2125, + 1836, + 1456, + 1247, + 1145, + 995, + 1077, + 1140, + 1290, + 1561, + 1685, + 1762, + 1609, + 1391, + 1147, + 544, + 84, + -754, + -1546, + -2107, + -2806, + -3137, + -3522, + -3732, + -3826, + -3834, + -3609, + -3493, + -3340, + -3254, + -3499, + -3621, + -3981, + -4455, + -4859, + -5513, + -6080, + -6626, + -7061, + -7372, + -7556, + -7573, + -7515, + -7366, + -7091, + -6799, + -6366, + -5887, + -5484, + -5098, + -4746, + -4334, + -3941, + -3558, + -3269, + -3053, + -2844, + -2663, + -2497, + -2314, + -2227, + -2185, + -2141, + -2139, + -2070, + -2037, + -2031, + -2062, + -2205, + -2348, + -2544, + -2774, + -2979, + -3298, + -3520, + -3647, + -3622, + -3395, + -3054, + -2513, + -1829, + -948, + 64, + 1090, + 2169, + 3127, + 3987, + 4712, + 5229, + 5560, + 5754, + 5741, + 5619, + 5401, + 5005, + 4666, + 4287, + 3967, + 3734, + 3476, + 3322, + 3203, + 3147, + 3144, + 3116, + 3080, + 3011, + 2871, + 2735, + 2544, + 2363, + 2245, + 2075, + 2032, + 2118, + 2263, + 2688, + 3066, + 3605, + 4244, + 4746, + 5384, + 5819, + 6151, + 6319, + 6194, + 5938, + 5495, + 4929, + 4305, + 3581, + 2924, + 2279, + 1713, + 1372, + 1086, + 1006, + 983, + 1006, + 1146, + 1249, + 1349, + 1360, + 1231, + 1084, + 794, + 502, + 264, + -85, + -238, + -411, + -504, + -394, + -322, + -51, + 188, + 420, + 589, + 624, + 666, + 573, + 338, + -86, + -564, + -1056, + -1560, + -1925, + -2434, + -2806, + -3017, + -3341, + -3320, + -3375, + -3480, + -3410, + -3567, + -3553, + -3595, + -3805, + -3919, + -4284, + -4482, + -4754, + -5190, + -5354, + -5806, + -6050, + -6136, + -6387, + -6343, + -6330, + -6206, + -5851, + -5468, + -4960, + -4549, + -4080, + -3542, + -3150, + -2698, + -2440, + -2318, + -2132, + -2067, + -2081, + -2017, + -2099, + -2151, + -2060, + -2067, + -1916, + -1823, + -1718, + -1523, + -1386, + -1221, + -1189, + -1141, + -1014, + -1008, + -966, + -996, + -1015, + -916, + -809, + -648, + -467, + -128, + 237, + 735, + 1358, + 1969, + 2697, + 3399, + 4060, + 4732, + 5295, + 5720, + 6077, + 6169, + 6139, + 5928, + 5614, + 5292, + 4766, + 4247, + 3705, + 3262, + 3030, + 2827, + 2702, + 2684, + 2728, + 2887, + 3092, + 3216, + 3310, + 3313, + 3214, + 3098, + 2873, + 2620, + 2343, + 2031, + 1799, + 1589, + 1491, + 1537, + 1645, + 1913, + 2210, + 2548, + 2922, + 3295, + 3650, + 3951, + 4100, + 4099, + 3972, + 3740, + 3421, + 2948, + 2427, + 1762, + 1136, + 574, + 44, + -330, + -642, + -846, + -852, + -751, + -520, + -229, + 44, + 272, + 446, + 502, + 443, + 329, + 66, + -191, + -492, + -841, + -1002, + -1240, + -1237, + -1199, + -1177, + -936, + -867, + -660, + -456, + -508, + -464, + -706, + -997, + -1265, + -1780, + -2178, + -2724, + -3270, + -3735, + -4142, + -4378, + -4609, + -4666, + -4749, + -4575, + -4355, + -4137, + -3767, + -3563, + -3218, + -2970, + -2834, + -2630, + -2716, + -2776, + -2920, + -3210, + -3363, + -3764, + -4023, + -4125, + -4268, + -4194, + -4223, + -4005, + -3639, + -3258, + -2891, + -2644, + -2297, + -1987, + -1751, + -1587, + -1570, + -1485, + -1415, + -1342, + -1194, + -1100, + -889, + -613, + -267, + 161, + 482, + 865, + 1269, + 1639, + 2005, + 2202, + 2381, + 2549, + 2628, + 2700, + 2625, + 2559, + 2481, + 2357, + 2319, + 2192, + 2142, + 2199, + 2283, + 2514, + 2670, + 2919, + 3214, + 3510, + 3830, + 3971, + 4080, + 4073, + 3911, + 3700, + 3359, + 2954, + 2549, + 2094, + 1766, + 1556, + 1442, + 1462, + 1560, + 1808, + 2070, + 2357, + 2606, + 2730, + 2831, + 2737, + 2582, + 2309, + 1931, + 1585, + 1178, + 834, + 529, + 288, + 214, + 218, + 302, + 470, + 679, + 944, + 1211, + 1420, + 1562, + 1674, + 1631, + 1548, + 1355, + 1072, + 776, + 375, + 25, + -320, + -614, + -818, + -992, + -991, + -906, + -755, + -525, + -291, + -17, + 225, + 447, + 528, + 546, + 466, + 270, + 96, + -205, + -536, + -861, + -1148, + -1383, + -1586, + -1688, + -1814, + -1783, + -1772, + -1745, + -1630, + -1611, + -1505, + -1488, + -1462, + -1409, + -1519, + -1489, + -1609, + -1723, + -1755, + -1977, + -2042, + -2132, + -2215, + -2184, + -2268, + -2205, + -2170, + -2107, + -1978, + -1990, + -1909, + -1886, + -1943, + -1997, + -2152, + -2326, + -2500, + -2762, + -2987, + -3227, + -3392, + -3522, + -3630, + -3579, + -3469, + -3262, + -2916, + -2555, + -2103, + -1581, + -1090, + -531, + -20, + 457, + 873, + 1228, + 1561, + 1809, + 1999, + 2105, + 2139, + 2196, + 2201, + 2149, + 2113, + 2038, + 1990, + 1913, + 1787, + 1705, + 1595, + 1490, + 1372, + 1201, + 1113, + 998, + 917, + 917, + 894, + 961, + 1007, + 1098, + 1321, + 1470, + 1681, + 1882, + 2067, + 2317, + 2465, + 2626, + 2750, + 2777, + 2783, + 2694, + 2569, + 2431, + 2142, + 1843, + 1597, + 1306, + 1069, + 824, + 622, + 532, + 430, + 388, + 357, + 377, + 438, + 414, + 481, + 468, + 431, + 454, + 383, + 374, + 305, + 207, + 187, + 133, + 157, + 115, + 113, + 206, + 244, + 382, + 475, + 591, + 753, + 821, + 916, + 908, + 855, + 754, + 577, + 399, + 123, + -159, + -399, + -647, + -784, + -923, + -1010, + -965, + -918, + -806, + -647, + -504, + -355, + -253, + -179, + -130, + -138, + -156, + -262, + -339, + -401, + -552, + -600, + -671, + -697, + -662, + -673, + -616, + -597, + -522, + -495, + -513, + -490, + -624, + -701, + -804, + -961, + -1073, + -1328, + -1503, + -1656, + -1798, + -1801, + -1913, + -1863, + -1785, + -1720, + -1453, + -1309, + -1051, + -846, + -715, + -487, + -457, + -357, + -331, + -400, + -427, + -627, + -765, + -873, + -1021, + -1105, + -1255, + -1312, + -1357, + -1370, + -1288, + -1261, + -1165, + -1139, + -1062, + -917, + -808, + -680, + -597, + -452, + -277, + -104, + 122, + 312, + 558, + 771, + 919, + 1110, + 1205, + 1312, + 1355, + 1302, + 1280, + 1151, + 1049, + 946, + 818, + 733, + 569, + 451, + 429, + 388, + 408, + 387, + 376, + 426, + 463, + 542, + 576, + 632, + 666, + 673, + 740, + 766, + 791, + 845, + 829, + 857, + 841, + 822, + 835, + 796, + 773, + 671, + 600, + 560, + 484, + 460, + 371, + 311, + 284, + 242, + 277, + 261, + 261, + 277, + 273, + 358, + 380, + 410, + 433, + 435, + 471, + 432, + 414, + 386, + 330, + 294, + 194, + 149, + 108, + 69, + 84, + 69, + 92, + 83, + 75, + 88, + 53, + 12, + -96, + -194, + -269, + -369, + -438, + -523, + -553, + -528, + -500, + -392, + -277, + -136, + 53, + 240, + 466, + 678, + 870, + 1050, + 1178, + 1294, + 1336, + 1310, + 1247, + 1080, + 916, + 677, + 387, + 120, + -182, + -471, + -740, + -972, + -1148, + -1273, + -1343, + -1402, + -1363, + -1263, + -1129, + -922, + -724, + -518, + -288, + -79, + 111, + 250, + 364, + 405, + 405, + 395, + 284, + 199, + 83, + -43, + -126, + -244, + -313, + -400, + -451, + -497, + -610, + -672, + -807, + -951, + -1087, + -1325, + -1517, + -1736, + -1929, + -2086, + -2260, + -2318, + -2356, + -2271, + -2125, + -1967, + -1685, + -1379, + -1000, + -598, + -238, + 149, + 481, + 790, + 1042, + 1185, + 1287, + 1274, + 1195, + 1068, + 868, + 654, + 386, + 138, + -65, + -273, + -450, + -598, + -665, + -670, + -669, + -620, + -553, + -425, + -288, + -179, + -72, + 15, + 122, + 205, + 263, + 324, + 357, + 435, + 518, + 603, + 709, + 779, + 892, + 1006, + 1107, + 1170, + 1183, + 1190, + 1173, + 1116, + 1016, + 890, + 750, + 628, + 488, + 331, + 197, + 95, + 43, + 25, + 1, + 22, + 97, + 209, + 363, + 495, + 615, + 724, + 833, + 937, + 984, + 990, + 933, + 884, + 851, + 747, + 678, + 573, + 497, + 469, + 401, + 391, + 352, + 339, + 352, + 337, + 354, + 361, + 370, + 402, + 411, + 418, + 440, + 468, + 526, + 576, + 619, + 683, + 766, + 857, + 965, + 1038, + 1114, + 1159, + 1172, + 1167, + 1106, + 1006, + 840, + 644, + 426, + 177, + -110, + -390, + -665, + -929, + -1160, + -1375, + -1497, + -1550, + -1592, + -1553, + -1507, + -1394, + -1201, + -1084, + -863, + -685, + -540, + -322, + -234, + -68, + 29, + 59, + 160, + 141, + 170, + 140, + 79, + 77, + -11, + -53, + -179, + -274, + -327, + -480, + -564, + -736, + -884, + -995, + -1185, + -1300, + -1461, + -1617, + -1711, + -1832, + -1831, + -1863, + -1865, + -1776, + -1691, + -1516, + -1353, + -1168, + -954, + -729, + -490, + -305, + -93, + 81, + 211, + 322, + 364, + 392, + 384, + 332, + 264, + 146, + 29, + -101, + -230, + -357, + -486, + -616, + -705, + -752, + -801, + -809, + -788, + -750, + -654, + -546, + -456, + -328, + -200, + -78, + 45, + 137, + 232, + 316, + 388, + 447, + 485, + 528, + 578, + 630, + 697, + 760, + 835, + 910, + 988, + 1068, + 1124, + 1154, + 1157, + 1166, + 1163, + 1116, + 1070, + 1024, + 994, + 986, + 988, + 1030, + 1110, + 1212, + 1303, + 1411, + 1498, + 1551, + 1599, + 1587, + 1565, + 1481, + 1336, + 1212, + 1028, + 847, + 669, + 466, + 330, + 187, + 61, + -9, + -54, + -55, + -20, + 11, + 69, + 133, + 195, + 244, + 253, + 225, + 182, + 133, + 62, + -11, + -96, + -168, + -199, + -214, + -213, + -197, + -167, + -127, + -105, + -86, + -83, + -109, + -140, + -217, + -323, + -448, + -588, + -717, + -854, + -971, + -1086, + -1185, + -1211, + -1227, + -1180, + -1135, + -1099, + -992, + -918, + -788, + -704, + -651, + -562, + -542, + -470, + -421, + -431, + -391, + -429, + -386, + -344, + -336, + -260, + -257, + -162, + -61, + -6, + 100, + 120, + 178, + 215, + 179, + 132, + 15, + -106, + -238, + -416, + -595, + -765, + -929, + -1066, + -1170, + -1252, + -1278, + -1290, + -1258, + -1173, + -1114, + -1012, + -945, + -868, + -741, + -695, + -612, + -547, + -494, + -388, + -332, + -225, + -110, + 22, + 182, + 318, + 496, + 677, + 835, + 992, + 1104, + 1162, + 1166, + 1133, + 1054, + 916, + 709, + 430, + 164, + -90, + -340, + -600, + -853, + -1033, + -1135, + -1177, + -1146, + -1079, + -946, + -746, + -500, + -208, + 83, + 377, + 673, + 950, + 1183, + 1356, + 1503, + 1627, + 1707, + 1735, + 1708, + 1678, + 1668, + 1645, + 1588, + 1494, + 1419, + 1354, + 1291, + 1194, + 1052, + 900, + 718, + 524, + 325, + 110, + -114, + -330, + -500, + -630, + -729, + -803, + -834, + -795, + -727, + -627, + -492, + -325, + -125, + 54, + 238, + 393, + 528, + 642, + 691, + 706, + 661, + 585, + 504, + 380, + 245, + 87, + -61, + -195, + -320, + -435, + -556, + -663, + -742, + -814, + -883, + -952, + -1009, + -1038, + -1047, + -1067, + -1063, + -1050, + -1020, + -949, + -888, + -795, + -698, + -574, + -405, + -257, + -70, + 68, + 203, + 381, + 479, + 580, + 619, + 623, + 645, + 565, + 492, + 364, + 206, + 106, + -71, + -191, + -331, + -460, + -469, + -527, + -471, + -441, + -386, + -222, + -123, + 60, + 168, + 245, + 404, + 470, + 596, + 605, + 581, + 633, + 548, + 562, + 468, + 355, + 334, + 192, + 161, + 62, + -36, + -39, + -146, + -121, + -167, + -243, + -229, + -302, + -276, + -327, + -415, + -419, + -444, + -396, + -433, + -455, + -407, + -357, + -244, + -221, + -158, + -63, + 36, + 172, + 210, + 296, + 326, + 351, + 424, + 367, + 369, + 300, + 224, + 235, + 124, + 54, + -39, + -122, + -118, + -239, + -304, + -360, + -403, + -361, + -418, + -427, + -394, + -342, + -259, + -232, + -176, + -110, + -48, + 27, + 48, + 78, + 90, + 86, + 91, + 76, + 57, + -1, + -34, + -53, + -103, + -151, + -209, + -239, + -261, + -319, + -354, + -372, + -382, + -385, + -411, + -432, + -428, + -431, + -446, + -471, + -496, + -512, + -532, + -562, + -570, + -567, + -543, + -499, + -457, + -379, + -290, + -204, + -94, + -11, + 78, + 155, + 196, + 234, + 222, + 198, + 160, + 113, + 64, + 5, + -57, + -108, + -136, + -175, + -186, + -196, + -184, + -125, + -90, + -25, + 58, + 146, + 271, + 372, + 472, + 562, + 636, + 709, + 741, + 760, + 752, + 730, + 710, + 688, + 655, + 608, + 595, + 570, + 556, + 540, + 517, + 513, + 511, + 497, + 481, + 449, + 417, + 401, + 347, + 325, + 295, + 248, + 261, + 238, + 250, + 294, + 295, + 367, + 380, + 416, + 454, + 430, + 479, + 443, + 431, + 430, + 386, + 397, + 333, + 292, + 238, + 176, + 153, + 54, + 24, + -37, + -84, + -109, + -172, + -155, + -199, + -220, + -219, + -261, + -227, + -255, + -280, + -266, + -293, + -277, + -273, + -243, + -214, + -221, + -179, + -153, + -130, + -109, + -154, + -149, + -151, + -155, + -186, + -243, + -253, + -311, + -326, + -358, + -434, + -427, + -491, + -533, + -554, + -598, + -596, + -655, + -668, + -679, + -714, + -671, + -694, + -643, + -607, + -602, + -532, + -496, + -409, + -408, + -377, + -309, + -289, + -211, + -223, + -196, + -145, + -147, + -104, + -157, + -123, + -125, + -177, + -152, + -229, + -192, + -204, + -243, + -213, + -259, + -194, + -190, + -172, + -98, + -123, + -43, + -12, + 41, + 103, + 87, + 148, + 150, + 166, + 154, + 113, + 118, + 80, + 54, + 8, + 4, + 25, + 12, + 59, + 70, + 162, + 260, + 305, + 387, + 427, + 501, + 549, + 564, + 571, + 517, + 488, + 423, + 355, + 294, + 206, + 165, + 113, + 92, + 77, + 62, + 115, + 116, + 154, + 162, + 171, + 218, + 210, + 221, + 208, + 192, + 215, + 176, + 169, + 114, + 89, + 89, + 52, + 62, + 29, + 35, + 73, + 98, + 167, + 195, + 261, + 325, + 349, + 401, + 382, + 393, + 368, + 302, + 254, + 174, + 104, + 6, + -78, + -136, + -203, + -229, + -291, + -303, + -284, + -294, + -241, + -235, + -222, + -186, + -187, + -156, + -160, + -149, + -122, + -114, + -71, + -44, + -28, + 6, + 20, + 47, + 57, + 54, + 52, + 55, + 53, + 23, + 9, + -16, + -59, + -86, + -158, + -223, + -292, + -372, + -421, + -498, + -532, + -561, + -570, + -531, + -512, + -456, + -367, + -297, + -206, + -125, + -37, + 26, + 88, + 147, + 157, + 188, + 169, + 152, + 152, + 131, + 99, + 62, + 44, + 46, + 53, + 61, + 61, + 79, + 110, + 159, + 175, + 185, + 237, + 220, + 278, + 276, + 239, + 264, + 203, + 190, + 138, + 70, + 34, + -9, + 18, + 1, + 10, + 71, + 115, + 191, + 220, + 255, + 265, + 296, + 319, + 270, + 266, + 214, + 189, + 187, + 155, + 145, + 123, + 149, + 166, + 172, + 186, + 179, + 195, + 213, + 201, + 182, + 161, + 150, + 116, + 76, + 41, + -29, + -58, + -101, + -183, + -209, + -269, + -314, + -342, + -385, + -379, + -380, + -348, + -304, + -273, + -197, + -144, + -88, + -28, + -5, + 11, + 20, + 27, + -5, + -24, + -22, + -61, + -73, + -87, + -124, + -118, + -133, + -150, + -160, + -198, + -196, + -219, + -228, + -239, + -281, + -276, + -275, + -288, + -277, + -305, + -324, + -302, + -294, + -292, + -266, + -261, + -224, + -203, + -210, + -190, + -198, + -176, + -180, + -201, + -196, + -198, + -175, + -166, + -151, + -127, + -114, + -59, + -48, + -8, + 39, + 75, + 126, + 131, + 168, + 160, + 152, + 142, + 82, + 36, + -13, + -49, + -81, + -105, + -105, + -103, + -65, + -38, + -16, + 19, + 33, + 67, + 82, + 95, + 110, + 98, + 111, + 98, + 87, + 67, + 54, + 66, + 52, + 49, + 53, + 71, + 106, + 139, + 186, + 224, + 270, + 320, + 361, + 413, + 433, + 462, + 473, + 478, + 480, + 459, + 441, + 391, + 339, + 298, + 239, + 206, + 159, + 149, + 120, + 114, + 117, + 95, + 106, + 81, + 67, + 61, + 30, + 11, + -29, + -42, + -76, + -97, + -98, + -124, + -107, + -107, + -103, + -69, + -71, + -36, + -12, + 23, + 69, + 86, + 129, + 152, + 158, + 162, + 152, + 127, + 81, + 48, + -9, + -80, + -120, + -172, + -201, + -225, + -276, + -297, + -311, + -330, + -339, + -361, + -375, + -389, + -376, + -365, + -374, + -378, + -375, + -370, + -358, + -347, + -355, + -338, + -314, + -289, + -244, + -212, + -168, + -129, + -80, + -26, + -12, + 47, + 79, + 92, + 105, + 105, + 113, + 99, + 85, + 29, + -18, + -53, + -110, + -133, + -167, + -186, + -196, + -199, + -176, + -177, + -150, + -122, + -106, + -73, + -61, + -30, + -34, + -29, + -40, + -68, + -63, + -85, + -84, + -71, + -65, + -40, + -16, + 23, + 56, + 87, + 144, + 167, + 196, + 206, + 221, + 243, + 226, + 233, + 210, + 192, + 190, + 150, + 140, + 110, + 91, + 77, + 43, + 27, + -10, + -5, + -5, + -22, + -9, + -7, + 27, + 48, + 59, + 64, + 70, + 87, + 104, + 139, + 151, + 188, + 239, + 270, + 317, + 311, + 336, + 349, + 341, + 330, + 274, + 254, + 223, + 195, + 163, + 102, + 81, + 43, + 20, + 8, + -37, + -28, + -31, + -29, + -21, + -39, + -16, + -22, + -11, + -21, + -41, + -32, + -47, + -39, + -60, + -75, + -71, + -94, + -98, + -131, + -147, + -139, + -145, + -146, + -165, + -150, + -136, + -112, + -90, + -106, + -86, + -91, + -87, + -98, + -136, + -121, + -135, + -124, + -132, + -144, + -114, + -108, + -87, + -74, + -75, + -50, + -30, + -5, + -18, + -24, + -3, + -3, + -6, + -41, + -76, + -98, + -127, + -159, + -215, + -257, + -263, + -268, + -266, + -262, + -237, + -194, + -144, + -113, + -99, + -61, + -28, + 12, + 21, + 46, + 76, + 92, + 130, + 115, + 123, + 132, + 135, + 149, + 134, + 133, + 132, + 135, + 138, + 94, + 76, + 51, + 19, + -15, + -72, + -98, + -125, + -135, + -154, + -174, + -171, + -164, + -139, + -130, + -99, + -74, + -40, + 9, + 34, + 86, + 129, + 176, + 214, + 226, + 245, + 250, + 280, + 271, + 256, + 250, + 226, + 234, + 212, + 187, + 178, + 148, + 144, + 104, + 79, + 64, + 37, + 36, + 9, + -10, + -23, + -38, + -35, + -62, + -67, + -67, + -82, + -70, + -80, + -75, + -59, + -34, + -3, + 9, + 48, + 76, + 101, + 120, + 120, + 123, + 126, + 131, + 112, + 92, + 77, + 61, + 54, + 32, + 3, + -18, + -28, + -39, + -56, + -71, + -91, + -92, + -100, + -124, + -134, + -142, + -144, + -155, + -177, + -178, + -175, + -171, + -168, + -160, + -141, + -123, + -89, + -73, + -64, + -46, + -39, + -18, + -19, + -34, + -32, + -46, + -51, + -63, + -74, + -73, + -81, + -70, + -83, + -71, + -49, + -39, + -12, + -1, + 30, + 48, + 65, + 94, + 100, + 125, + 136, + 148, + 156, + 138, + 140, + 124, + 115, + 86, + 58, + 57, + 32, + 43, + 40, + 44, + 63, + 60, + 83, + 90, + 99, + 115, + 113, + 135, + 140, + 148, + 164, + 172, + 187, + 182, + 190, + 183, + 171, + 171, + 146, + 139, + 121, + 105, + 94, + 61, + 46, + 17, + -6, + -34, + -70, + -89, + -121, + -138, + -158, + -178, + -190, + -206, + -206, + -210, + -214, + -204, + -196, + -173, + -154, + -128, + -97, + -81, + -58, + -51, + -46, + -38, + -47, + -49, + -57, + -58, + -57, + -59, + -49, + -58, + -58, + -54, + -60, + -48, + -65, + -72, + -72, + -78, + -70, + -77, + -73, + -76, + -79, + -76, + -90, + -90, + -91, + -88, + -76, + -67, + -43, + -16, + 6, + 27, + 39, + 55, + 69, + 71, + 74, + 65, + 56, + 60, + 47, + 37, + 27, + 8, + -5, + -29, + -50, + -71, + -89, + -96, + -114, + -111, + -113, + -115, + -105, + -112, + -90, + -78, + -68, + -49, + -46, + -26, + -14, + 5, + 18, + 10, + 14, + 3, + 5, + -9, + -20, + -15, + -30, + -26, + -33, + -31, + -23, + -23, + -12, + -21, + -20, + -16, + -23, + -20, + -13, + -7, + 6, + 28, + 47, + 69, + 96, + 115, + 134, + 147, + 154, + 166, + 174, + 186, + 196, + 202, + 204, + 198, + 193, + 181, + 164, + 144, + 125, + 113, + 102, + 96, + 90, + 92, + 91, + 96, + 99, + 99, + 100, + 99, + 99, + 93, + 94, + 86, + 68, + 55, + 44, + 36, + 22, + 13, + 15, + 13, + 15, + 21, + 16, + 11, + 3, + -15, + -31, + -50, + -75, + -105, + -125, + -145, + -154, + -155, + -164, + -178, + -189, + -186, + -177, + -174, + -169, + -152, + -134, + -114, + -93, + -65, + -42, + -23, + -4, + -1, + 6, + 6, + 2, + -4, + -18, + -26, + -25, + -25, + -23, + -32, + -31, + -33, + -39, + -50, + -68, + -69, + -74, + -79, + -78, + -83, + -85, + -85, + -77, + -71, + -61, + -42, + -27, + -3, + 28, + 59, + 95, + 123, + 146, + 155, + 160, + 162, + 144, + 130, + 112, + 94, + 82, + 67, + 60, + 46, + 35, + 35, + 22, + 4, + -14, + -27, + -35, + -45, + -52, + -61, + -62, + -65, + -68, + -55, + -52, + -43, + -38, + -34, + -20, + -8, + 8, + 18, + 24, + 34, + 36, + 37, + 42, + 46, + 51, + 50, + 58, + 76, + 75, + 70, + 67, + 58, + 53, + 48, + 36, + 23, + 18, + 10, + 3, + 9, + 14, + 24, + 39, + 43, + 53, + 62, + 63, + 66, + 62, + 66, + 64, + 59, + 51, + 25, + 19, + 6, + -10, + -19, + -26, + -35, + -43, + -44, + -37, + -47, + -43, + -50, + -54, + -60, + -69, + -75, + -84, + -91, + -93, + -98, + -96, + -99, + -91, + -87, + -91, + -88, + -84, + -80, + -75, + -61, + -48, + -44, + -40, + -37, + -34, + -45, + -52, + -58, + -72, + -82, + -84, + -78, + -68, + -65, + -63, + -51, + -42, + -27, + -22, + -13, + -3, + 8, + 20, + 26, + 31, + 31, + 37, + 33, + 29, + 33, + 31, + 32, + 31, + 34, + 44, + 55, + 68, + 74, + 69, + 75, + 73, + 72, + 65, + 63, + 67, + 70, + 83, + 81, + 81, + 85, + 84, + 80, + 75, + 69, + 53, + 44, + 36, + 27, + 20, + 11, + 1, + -4, + -19, + -26, + -27, + -25, + -21, + -14, + -12, + -12, + -14, + -9, + -21, + -29, + -40, + -50, + -50, + -54, + -46, + -35, + -17, + -4, + -1, + 7, + 20, + 28, + 26, + 22, + 23, + 21, + 23, + 18, + 13, + 12, + 7, + 6, + 3, + 2, + -1, + -1, + 4, + 6, + 17, + 29, + 35, + 34, + 34, + 32, + 28, + 33, + 26, + 22, + 16, + 16, + 22, + 20, + 13, + -1, + -1, + -7, + -15, + -20, + -30, + -32, + -38, + -39, + -45, + -45, + -53, + -63, + -70, + -83, + -96, + -107, + -113, + -122, + -122, + -118, + -114, + -114, + -113, + -112, + -111, + -110, + -107, + -103, + -102, + -94, + -80, + -71, + -58, + -52, + -47, + -40, + -43, + -47, + -48, + -50, + -39, + -46, + -44, + -44, + -44, + -43, + -45, + -41, + -40, + -34, + -32, + -23, + -12, + -6, + -1, + -1, + 6, + 12, + 18, + 20, + 22, + 32, + 48, + 65, + 80, + 93, + 109, + 122, + 128, + 131, + 135, + 135, + 129, + 126, + 130, + 127, + 124, + 125, + 121, + 122, + 115, + 118, + 122, + 128, + 137, + 143, + 143, + 141, + 142, + 134, + 131, + 121, + 109, + 105, + 97, + 93, + 99, + 96, + 96, + 94, + 83, + 84, + 80, + 77, + 66, + 59, + 46, + 42, + 44, + 32, + 28, + 20, + 12, + 8, + 4, + 4, + 5, + 3, + -4, + -7, + -6, + -14, + -19, + -24, + -34, + -40, + -45, + -52, + -61, + -62, + -60, + -57, + -57, + -61, + -63, + -61, + -65, + -73, + -81, + -89, + -94, + -93, + -89, + -87, + -82, + -82, + -84, + -81, + -86, + -82, + -84, + -86, + -90, + -86, + -83, + -82, + -81, + -80, + -80, + -76, + -75, + -76, + -70, + -69, + -68, + -61, + -53, + -50, + -43, + -38, + -42, + -43, + -41, + -41, + -39, + -34, + -27, + -21, + -16, + -20, + -22, + -27, + -36, + -39, + -38, + -40, + -37, + -35, + -28, + -14, + -6, + -3, + -2, + 2, + 4, + 5, + 15, + 18, + 25, + 35, + 36, + 41, + 45, + 48, + 52, + 54, + 52, + 50, + 60, + 67, + 76, + 85, + 85, + 90, + 86, + 83, + 84, + 77, + 77, + 72, + 77, + 81, + 89, + 91, + 93, + 99, + 101, + 102, + 98, + 94, + 87, + 77, + 70, + 69, + 63, + 62, + 55, + 59, + 58, + 54, + 51, + 53, + 57, + 62, + 65, + 60, + 54, + 48, + 45, + 40, + 29, + 17, + 8, + -3, + -14, + -17, + -18, + -20, + -25, + -34, + -40, + -44, + -53, + -56, + -63, + -71, + -71, + -69, + -66, + -62, + -66, + -67, + -68, + -71, + -75, + -79, + -79, + -73, + -67, + -60, + -49, + -46, + -45, + -45, + -46, + -55, + -64, + -67, + -72, + -74, + -70, + -68, + -67, + -69, + -70, + -64, + -56, + -55, + -54, + -51, + -41, + -30, + -26, + -28, + -29, + -30, + -28, + -25, + -27, + -20, + -12, + -5, + -2, + 2, + 3, + -3, + 0, + -7, + -8, + -14, + -15, + -9, + -7, + 4, + 12, + 24, + 36, + 41, + 52, + 58, + 59, + 51, + 45, + 48, + 44, + 46, + 43, + 40, + 42, + 47, + 53, + 52, + 52, + 63, + 69, + 74, + 75, + 80, + 78, + 69, + 68, + 59, + 60, + 54, + 54, + 54, + 58, + 66, + 71, + 78, + 78, + 75, + 78, + 72, + 71, + 61, + 55, + 53, + 42, + 36, + 31, + 28, + 29, + 23, + 19, + 25, + 27, + 27, + 23, + 29, + 29, + 20, + 11, + 5, + -4, + -10, + -31, + -38, + -39, + -36, + -33, + -27, + -17, + -15, + -14, + -17, + -13, + -14, + -25, + -33, + -44, + -51, + -61, + -63, + -63, + -65, + -67, + -66, + -63, + -59, + -52, + -48, + -45, + -44, + -50, + -62, + -74, + -84, + -89, + -100, + -101, + -102, + -96, + -95, + -85, + -76, + -78, + -72, + -71, + -66, + -61, + -63, + -60, + -62, + -72, + -69, + -69, + -58, + -56, + -50, + -37, + -28, + -17, + -17, + -16, + -17, + -18, + -18, + -13, + -7, + -4, + 6, + 17, + 23, + 25, + 28, + 24, + 21, + 17, + 21, + 27, + 30, + 33, + 35, + 46, + 49, + 48, + 54, + 56, + 57, + 58, + 60, + 64, + 62, + 64, + 66, + 67, + 64, + 70, + 77, + 83, + 82, + 84, + 88, + 89, + 95, + 86, + 75, + 64, + 51, + 36, + 29, + 26, + 21, + 26, + 31, + 38, + 40, + 55, + 63, + 65, + 65, + 64, + 60, + 54, + 54, + 49, + 41, + 34, + 26, + 21, + 9, + 6, + 6, + 5, + -1, + 3, + 5, + 3, + 2, + -4, + -13, + -13, + -24, + -32, + -33, + -36, + -33, + -24, + -18, + -15, + -9, + -5, + -5, + -14, + -17, + -24, + -34, + -36, + -42, + -43, + -36, + -42, + -43, + -43, + -38, + -36, + -27, + -20, + -23, + -21, + -28, + -25, + -22, + -24, + -25, + -23, + -22, + -30, + -31, + -26, + -25, + -20, + -15, + -8, + -10, + -11, + -13, + -18, + -22, + -30, + -36, + -35, + -39, + -35, + -34, + -27, + -24, + -19, + -15, + -7, + -6, + -7, + -2, + 0, + 7, + 12, + 14, + 19, + 20, + 26, + 26, + 24, + 16, + 10, + 4, + 1, + 3, + 2, + 9, + 11, + 17, + 19, + 27, + 31, + 31, + 32, + 30, + 27, + 25, + 28, + 27, + 25, + 22, + 23, + 23, + 20, + 21, + 25, + 36, + 38, + 40, + 43, + 40, + 32, + 27, + 20, + 9, + 4, + 1, + 12, + 27, + 37, + 49, + 63, + 73, + 72, + 73, + 70, + 67, + 53, + 39, + 33, + 26, + 23, + 13, + 9, + 6, + 0, + -2, + -3, + 0, + -1, + 0, + -1, + -4, + -9, + -16, + -22, + -21, + -24, + -21, + -19, + -12, + -3, + 0, + 12, + 14, + 13, + 3, + -6, + -13, + -27, + -34, + -42, + -41, + -44, + -42, + -43, + -46, + -42, + -40, + -39, + -36, + -31, + -29, + -30, + -22, + -19, + -21, + -20, + -17, + -17, + -22, + -31, + -41, + -45, + -54, + -65, + -64, + -68, + -70, + -74, + -70, + -64, + -62, + -61, + -60, + -58, + -52, + -46, + -43, + -37, + -35, + -40, + -41, + -47, + -52, + -58, + -62, + -61, + -53, + -54, + -46, + -41, + -40, + -34, + -29, + -20, + -15, + -8, + 2, + 12, + 28, + 35, + 41, + 42, + 42, + 43, + 41, + 43, + 39, + 45, + 44, + 46, + 55, + 54, + 55, + 55, + 51, + 48, + 42, + 43, + 39, + 40, + 46, + 54, + 65, + 70, + 76, + 81, + 86, + 89, + 79, + 73, + 70, + 62, + 56, + 52, + 39, + 32, + 28, + 17, + 18, + 19, + 18, + 15, + 19, + 20, + 15, + 13, + 13, + 10, + 6, + 5, + 12, + 10, + 15, + 20, + 24, + 30, + 31, + 28, + 22, + 17, + 2, + -15, + -24, + -39, + -52, + -53, + -55, + -46, + -40, + -34, + -26, + -21, + -22, + -31, + -32, + -38, + -36, + -35, + -32, + -33, + -34, + -30, + -28, + -27, + -35, + -40, + -42, + -45, + -44, + -45, + -44, + -52, + -54, + -57, + -57, + -53, + -60, + -63, + -63, + -65, + -51, + -45, + -40, + -40, + -39, + -39, + -43, + -44, + -46, + -52, + -46, + -51, + -49, + -45, + -45, + -47, + -47, + -45, + -50, + -47, + -40, + -35, + -32, + -24, + -17, + -19, + -14, + -13, + -9, + -7, + -7, + -7, + -9, + 0, + 3, + 7, + 13, + 12, + 14, + 15, + 13, + 6, + -1, + -3, + -9, + -10, + -5, + -2, + 6, + 9, + 11, + 12, + 15, + 19, + 24, + 37, + 47, + 47, + 56, + 53, + 51, + 52, + 52, + 47, + 39, + 38, + 40, + 41, + 43, + 44, + 42, + 43, + 42, + 41, + 43, + 40, + 41, + 35, + 37, + 39, + 40, + 41, + 38, + 30, + 21, + 14, + 5, + 2, + -1, + -2, + 1, + -2, + 6, + 2, + 4, + 2, + -1, + -11, + -16, + -23, + -25, + -20, + -18, + -25, + -27, + -32, + -27, + -24, + -16, + -15, + -11, + -9, + -3, + -4, + -2, + -9, + -10, + -18, + -28, + -33, + -38, + -37, + -41, + -41, + -33, + -24, + -22, + -25, + -25, + -25, + -24, + -33, + -38, + -42, + -52, + -57, + -55, + -50, + -51, + -53, + -52, + -48, + -49, + -49, + -53, + -55, + -58, + -51, + -34, + -19, + -12, + -12, + -5, + 1, + 1, + 0, + -6, + -2, + -10, + -11, + -11, + -6, + 0, + -6, + 2, + -2, + -6, + 2, + 5, + 16, + 18, + 18, + 21, + 16, + 18, + 18, + 20, + 20, + 13, + 18, + 9, + 7, + 12, + 7, + 8, + 10, + 16, + 17, + 18, + 23, + 26, + 36, + 44, + 51, + 55, + 60, + 64, + 69, + 68, + 71, + 70, + 62, + 58, + 52, + 44, + 35, + 31, + 34, + 32, + 33, + 36, + 37, + 38, + 41, + 47, + 55, + 56, + 58, + 60, + 60, + 57, + 48, + 41, + 29, + 19, + 7, + 4, + 8, + 9, + 10, + 8, + 13, + 15, + 13, + 8, + 8, + 6, + 4, + 10, + 8, + -4, + -6, + -9, + -20, + -28, + -39, + -38, + -27, + -24, + -22, + -19, + -23, + -32, + -35, + -36, + -41, + -48, + -51, + -50, + -52, + -55, + -60, + -67, + -72, + -76, + -84, + -82, + -80, + -81, + -75, + -64, + -50, + -36, + -28, + -18, + -14, + -12, + -15, + -12, + -18, + -24, + -21, + -22, + -19, + -21, + -19, + -22, + -20, + -18, + -16, + -17, + -19, + -15, + -7, + 1, + 0, + 0, + 9, + 14, + 20, + 24, + 20, + 16, + 17, + 20, + 20, + 25, + 27, + 26, + 32, + 33, + 35, + 38, + 42, + 38, + 37, + 39, + 46, + 44, + 43, + 45, + 45, + 42, + 37, + 34, + 25, + 21, + 22, + 33, + 44, + 49, + 54, + 53, + 58, + 54, + 51, + 46, + 40, + 37, + 37, + 39, + 34, + 37, + 39, + 31, + 39, + 38, + 36, + 35, + 32, + 33, + 33, + 32, + 28, + 23, + 18, + 22, + 28, + 31, + 27, + 18, + 3, + 4, + 0, + -4, + -7, + -15, + -18, + -24, + -32, + -34, + -39, + -42, + -36, + -31, + -24, + -12, + -10, + -10, + -13, + -20, + -28, + -34, + -44, + -49, + -50, + -53, + -56, + -54, + -52, + -53, + -47, + -43, + -41, + -45, + -41, + -38, + -38, + -33, + -32, + -34, + -35, + -33, + -40, + -45, + -53, + -62, + -61, + -67, + -72, + -70, + -67, + -68, + -59, + -51, + -47, + -38, + -31, + -20, + -13, + -13, + -13, + -14, + -17, + -21, + -22, + -29, + -31, + -27, + -23, + -13, + -6, + 4, + 12, + 17, + 25, + 23, + 23, + 25, + 30, + 30, + 32, + 31, + 28, + 27, + 18, + 14, + 13, + 3, + 5, + 7, + 19, + 35, + 47, + 61, + 70, + 84, + 90, + 95, + 92, + 94, + 89, + 77, + 71, + 66, + 59, + 50, + 51, + 50, + 51, + 53, + 56, + 65, + 67, + 69, + 75, + 74, + 69, + 67, + 56, + 51, + 44, + 34, + 25, + 17, + 10, + 6, + 7, + 7, + 4, + 6, + -1, + -1, + -2, + -9, + -9, + -9, + -7, + -5, + 1, + -2, + -5, + -11, + -19, + -27, + -39, + -38, + -44, + -45, + -48, + -48, + -54, + -59, + -53, + -51, + -49, + -52, + -50, + -50, + -47, + -42, + -32, + -28, + -28, + -26, + -27, + -34, + -40, + -40, + -36, + -37, + -37, + -34, + -37, + -36, + -41, + -36, + -40, + -46, + -48, + -52, + -47, + -44, + -40, + -40, + -38, + -43, + -43, + -47, + -59, + -62, + -59, + -59, + -51, + -41, + -29, + -19, + -8, + -2, + 1, + 1, + -4, + -9, + -19, + -23, + -29, + -29, + -25, + -23, + -15, + -7, + -2, + 6, + 8, + 15, + 27, + 35, + 43, + 40, + 36, + 35, + 32, + 25, + 22, + 19, + 17, + 13, + 13, + 21, + 25, + 28, + 36, + 44, + 50, + 57, + 56, + 58, + 59, + 62, + 66, + 70, + 73, + 69, + 66, + 66, + 66, + 62, + 53, + 48, + 44, + 38, + 39, + 44, + 52, + 51, + 55, + 57, + 52, + 49, + 44, + 36, + 26, + 16, + 13, + 13, + 14, + 14, + 17, + 14, + 10, + 6, + -5, + -14, + -23, + -24, + -21, + -28, + -25, + -27, + -29, + -29, + -33, + -33, + -39, + -42, + -43, + -41, + -40, + -43, + -46, + -45, + -43, + -42, + -41, + -41, + -46, + -46, + -52, + -52, + -52, + -59, + -63, + -70, + -68, + -73, + -77, + -73, + -68, + -66, + -62, + -64, + -66, + -58, + -54, + -51, + -52, + -48, + -47, + -43, + -40, + -39, + -33, + -26, + -19, + -17, + -16, + -17, + -14, + -9, + -10, + -3, + 5, + 5, + 9, + 5, + 9, + 8, + 4, + 3, + 0, + -5, + -10, + -3, + 2, + 8, + 14, + 16, + 20, + 27, + 39, + 40, + 44, + 48, + 43, + 39, + 34, + 29, + 22, + 12, + 8, + 5, + 0, + -2, + -3, + 5, + 12, + 16, + 19, + 22, + 25, + 28, + 35, + 28, + 30, + 31, + 30, + 39, + 43, + 47, + 43, + 42, + 41, + 41, + 41, + 37, + 37, + 39, + 37, + 38, + 43, + 44, + 41, + 43, + 34, + 28, + 25, + 23, + 30, + 34, + 32, + 33, + 29, + 21, + 18, + 13, + 14, + 11, + 3, + 2, + 1, + 3, + 1, + -1, + 0, + -3, + -1, + -3, + -8, + -9, + -7, + -9, + -2, + 0, + -3, + 0, + 1, + 5, + 0, + -1, + -9, + -13, + -8, + -11, + -18, + -23, + -25, + -29, + -29, + -26, + -27, + -29, + -25, + -24, + -23, + -18, + -19, + -18, + -17, + -21, + -22, + -30, + -38, + -42, + -42, + -42, + -40, + -41, + -43, + -39, + -38, + -37, + -36, + -33, + -31, + -28, + -27, + -18, + -15, + -7, + -8, + -8, + -1, + 1, + 3, + -5, + 0, + -4, + -5, + -4, + -8, + -10, + -14, + -21, + -24, + -25, + -20, + -11, + -4, + 3, + 6, + 13, + 15, + 12, + 17, + 16, + 17, + 17, + 15, + 21, + 28, + 33, + 36, + 35, + 35, + 29, + 31, + 29, + 28, + 23, + 21, + 14, + 15, + 27, + 36, + 40, + 40, + 43, + 51, + 56, + 62, + 69, + 77, + 80, + 88, + 88, + 88, + 82, + 76, + 63, + 52, + 44, + 36, + 26, + 23, + 25, + 24, + 27, + 26, + 31, + 21, + 13, + 8, + -8, + -8, + -11, + -14, + -18, + -28, + -28, + -30, + -32, + -29, + -26, + -26, + -27, + -24, + -20, + -14, + -8, + -6, + -8, + -5, + -10, + -14, + -18, + -26, + -34, + -36, + -38, + -44, + -51, + -57, + -66, + -64, + -68, + -72, + -75, + -75, + -70, + -68, + -65, + -64, + -62, + -68, + -63, + -60, + -65, + -65, + -69, + -68, + -67, + -57, + -46, + -41, + -38, + -34, + -31, + -39, + -40, + -45, + -45, + -48, + -47, + -40, + -39, + -32, + -26, + -24, + -14, + -9, + -7, + -3, + -2, + 3, + 4, + 0, + -2, + -2, + -2, + 1, + 3, + 2, + 3, + 8, + 13, + 20, + 25, + 29, + 31, + 26, + 17, + 11, + 3, + -5, + 2, + 6, + 9, + 11, + 19, + 26, + 40, + 51, + 61, + 60, + 58, + 61, + 55, + 55, + 57, + 60, + 54, + 40, + 42, + 38, + 34, + 38, + 37, + 34, + 32, + 35, + 36, + 35, + 41, + 36, + 32, + 29, + 23, + 22, + 23, + 22, + 14, + 13, + 19, + 19, + 20, + 22, + 22, + 17, + 13, + 6, + 9, + 13, + 15, + 17, + 19, + 11, + 15, + 8, + 4, + 6, + -1, + -3, + 3, + 7, + 11, + 8, + 10, + 7, + 6, + 4, + -4, + -5, + -11, + -9, + -16, + -14, + -14, + -16, + -16, + -22, + -19, + -19, + -13, + -9, + -4, + 1, + 1, + 2, + -6, + -14, + -25, + -32, + -41, + -46, + -50, + -49, + -42, + -39, + -34, + -24, + -14, + -18, + -15, + -17, + -21, + -23, + -21, + -19, + -21, + -20, + -19, + -20, + -19, + -16, + -17, + -19, + -20, + -20, + -20, + -20, + -22, + -22, + -23, + -22, + -22, + -14, + -5, + 5, + 8, + 13, + 16, + 19, + 23, + 19, + 21, + 16, + 16, + 18, + 13, + 18, + 13, + 15, + 18, + 12, + 12, + 6, + 11, + 8, + 5, + 5, + 9, + 17, + 14, + 15, + 14, + 16, + 14, + 14, + 12, + 9, + 7, + 9, + 11, + 13, + 15, + 15, + 19, + 17, + 14, + 8, + 7, + 4, + 0, + 3, + 8, + 10, + 7, + 8, + 19, + 15, + 19, + 18, + 19, + 17, + 9, + 14, + 10, + 4, + -3, + -11, + -19, + -25, + -31, + -35, + -36, + -28, + -21, + -8, + 5, + 8, + 11, + 13, + 7, + 4, + 1, + -7, + -15, + -17, + -17, + -21, + -28, + -33, + -37, + -40, + -39, + -41, + -45, + -46, + -44, + -40, + -41, + -36, + -31, + -41, + -40, + -42, + -44, + -47, + -50, + -49, + -55, + -52, + -52, + -52, + -45, + -50, + -52, + -56, + -58, + -60, + -69, + -75, + -82, + -86, + -91, + -87, + -80, + -80, + -72, + -58, + -52, + -45, + -33, + -21, + -13, + -12, + -10, + -6, + -1, + -2, + -7, + -7, + -5, + -6, + -3, + 9, + 15, + 25, + 36, + 35, + 39, + 28, + 16, + 11, + 8, + 11, + 17, + 27, + 34, + 36, + 47, + 49, + 52, + 52, + 42, + 46, + 49, + 55, + 65, + 66, + 67, + 62, + 56, + 53, + 49, + 50, + 55, + 53, + 62, + 69, + 72, + 73, + 68, + 61, + 54, + 46, + 43, + 38, + 34, + 39, + 43, + 42, + 39, + 36, + 31, + 26, + 24, + 17, + 13, + 14, + 14, + 21, + 26, + 29, + 28, + 26, + 24, + 18, + 19, + 16, + 11, + 6, + 2, + -2, + 1, + 3, + 2, + -4, + -3, + -1, + -3, + -2, + -2, + -5, + -3, + 0, + 3, + -3, + -6, + -6, + -15, + -19, + -25, + -30, + -35, + -39, + -34, + -34, + -34, + -31, + -17, + -17, + -8, + -2, + -2, + 8, + 14, + 25, + 24, + 26, + 22, + 16, + 10, + 2, + -3, + -5, + -12, + -15, + -11, + -14, + -16, + -17, + -17, + -16, + -21, + -18, + -18, + -21, + -23, + -21, + -15, + -11, + -4, + -2, + 3, + 8, + 10, + 17, + 18, + 25, + 24, + 24, + 24, + 21, + 24, + 23, + 24, + 22, + 23, + 31, + 39, + 49, + 58, + 64, + 67, + 63, + 57, + 53, + 52, + 44, + 45, + 43, + 40, + 45, + 42, + 49, + 50, + 49, + 52, + 51, + 48, + 46, + 38, + 37, + 35, + 36, + 37, + 37, + 37, + 44, + 45, + 47, + 42, + 42, + 36, + 35, + 44, + 40, + 40, + 28, + 24, + 23, + 18, + 12, + 9, + 8, + 10, + 17, + 17, + 18, + 12, + 5, + -2, + -12, + -16, + -20, + -27, + -29, + -29, + -26, + -22, + -17, + -16, + -15, + -14, + -15, + -11, + -11, + -15, + -19, + -15, + -20, + -22, + -24, + -37, + -52, + -62, + -63, + -68, + -64, + -59, + -51, + -43, + -42, + -36, + -32, + -33, + -33, + -33, + -41, + -48, + -51, + -49, + -48, + -47, + -42, + -45, + -42, + -41, + -40, + -39, + -33, + -29, + -25, + -14, + -1, + -4, + -6, + -11, + -16, + -19, + -26, + -29, + -28, + -25, + -17, + -10, + -1, + -1, + 3, + 7, + -1, + -3, + -8, + -18, + -20, + -20, + -16, + -13, + -11, + -8, + 0, + 6, + 8, + 11, + 14, + 15, + 20, + 26, + 26, + 26, + 24, + 23, + 24, + 30, + 34, + 41, + 52, + 61, + 70, + 80, + 85, + 86, + 89, + 84, + 87, + 79, + 67, + 60, + 57, + 59, + 63, + 68, + 74, + 78, + 84, + 89, + 91, + 87, + 81, + 74, + 69, + 63, + 59, + 59, + 56, + 58, + 60, + 60, + 59, + 54, + 49, + 41, + 40, + 34, + 25, + 19, + 11, + 1, + 0, + -1, + -4, + -8, + -12, + -12, + -17, + -22, + -31, + -44, + -54, + -58, + -68, + -74, + -80, + -80, + -73, + -65, + -61, + -61, + -55, + -50, + -50, + -59, + -65, + -69, + -73, + -73, + -78, + -79, + -83, + -87, + -87, + -88, + -94, + -103, + -107, + -107, + -109, + -106, + -113, + -115, + -110, + -105, + -100, + -100, + -92, + -78, + -62, + -49, + -39, + -35, + -27, + -26, + -25, + -24, + -22, + -23, + -28, + -26, + -22, + -15, + -11, + -4, + 4, + 13, + 21, + 32, + 31, + 28, + 30, + 30, + 28, + 23, + 25, + 23, + 21, + 25, + 21, + 26, + 27, + 32, + 40, + 48, + 53, + 55, + 54, + 55, + 55, + 54, + 48, + 44, + 47, + 48, + 54, + 60, + 71, + 79, + 79, + 74, + 72, + 59, + 48, + 42, + 32, + 26, + 22, + 21, + 23, + 22, + 31, + 42, + 44, + 41, + 36, + 30, + 30, + 33, + 38, + 35, + 30, + 28, + 20, + 15, + 8, + 4, + 6, + 9, + 16, + 26, + 27, + 23, + 19, + 16, + 10, + 4, + -4, + -12, + -12, + -16, + -16, + -19, + -24, + -23, + -23, + -31, + -34, + -38, + -40, + -41, + -39, + -39, + -36, + -36, + -40, + -45, + -48, + -53, + -66, + -73, + -76, + -76, + -78, + -75, + -71, + -65, + -59, + -58, + -59, + -56, + -60, + -62, + -62, + -62, + -64, + -68, + -73, + -79, + -80, + -85, + -87, + -85, + -78, + -72, + -66, + -56, + -48, + -42, + -37, + -35, + -32, + -33, + -31, + -25, + -26, + -27, + -16, + -18, + -18, + -13, + -14, + -17, + -22, + -24, + -25, + -23, + -19, + -14, + -12, + -11, + -7, + -4, + -1, + 2, + 5, + 8, + 10, + 10, + 18, + 28, + 29, + 25, + 22, + 29, + 21, + 20, + 21, + 22, + 30, + 32, + 41, + 41, + 45, + 46, + 49, + 52, + 57, + 59, + 58, + 52, + 46, + 47, + 56, + 58, + 49, + 49, + 46, + 40, + 33, + 23, + 14, + 11, + 16, + 29, + 34, + 37, + 41, + 42, + 48, + 54, + 60, + 61, + 62, + 62, + 69, + 79, + 76, + 71, + 72, + 71, + 64, + 59, + 54, + 49, + 40, + 42, + 34, + 23, + 27, + 18, + 13, + 9, + 3, + -4, + -8, + -16, + -18, + -20, + -26, + -28, + -30, + -32, + -29, + -32, + -35, + -39, + -41, + -38, + -34, + -31, + -26, + -18, + -21, + -20, + -22, + -28, + -35, + -34, + -31, + -33, + -31, + -31, + -40, + -43, + -45, + -53, + -64, + -67, + -74, + -75, + -74, + -75, + -70, + -61, + -56, + -45, + -37, + -30, + -33, + -35, + -32, + -31, + -27, + -25, + -19, + -17, + -14, + -9, + -4, + -1, + -3, + -4, + 1, + 8, + 14, + 20, + 24, + 25, + 18, + 11, + 7, + -3, + -9, + -3, + 4, + 15, + 30, + 29, + 33, + 33, + 36, + 35, + 31, + 33, + 34, + 42, + 43, + 42, + 47, + 49, + 53, + 61, + 69, + 73, + 74, + 79, + 81, + 84, + 76, + 69, + 62, + 47, + 39, + 31, + 19, + 8, + 2, + -6, + -5, + -3, + -3, + -1, + 1, + -2, + -3, + -3, + -6, + -12, + -13, + -15, + -11, + -5, + -4, + -8, + -14, + -9, + -3, + 0, + -3, + -4, + 0, + 3, + 0, + -6, + -14, + -23, + -33, + -38, + -41, + -38, + -38, + -34, + -30, + -29, + -29, + -26, + -31, + -33, + -41, + -49, + -50, + -56, + -57, + -58, + -54, + -46, + -39, + -39, + -34, + -31, + -28, + -30, + -30, + -31, + -29, + -27, + -16, + -18, + -17, + -15, + -13, + -15, + -12, + -7, + -11, + -9, + -9, + -4, + -11, + -7, + -7, + -8, + -9, + -10, + -7, + -9, + 1, + 9, + 15, + 12, + 19, + 19, + 18, + 17, + 13, + 11, + 8, + 6, + 10, + 17, + 20, + 26, + 28, + 33, + 39, + 30, + 25, + 25, + 18, + 16, + 21, + 26, + 30, + 33, + 32, + 36, + 42, + 49, + 46, + 39, + 44, + 44, + 37, + 35, + 30, + 24, + 22, + 23, + 26, + 23, + 25, + 21, + 24, + 24, + 22, +}; diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/no_1000ms_sample_data.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/no_1000ms_sample_data.h new file mode 100644 index 00000000..fd891313 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/no_1000ms_sample_data.h @@ -0,0 +1,29 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// This data was created from the PCM data in a WAV file held in v2 of the +// Speech Commands test dataset, at the path: +// speech_commands_test_set_v0.02/no/f9643d42_nohash_4.wav +// This should contain all 16,000 samples from the one-second file. + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_NO_1000MS_SAMPLE_DATA_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_NO_1000MS_SAMPLE_DATA_H_ + +#include + +extern const int g_no_1000ms_sample_data_size; +extern const int16_t g_no_1000ms_sample_data[]; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_NO_1000MS_SAMPLE_DATA_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/no_30ms_sample_data.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/no_30ms_sample_data.cc new file mode 100644 index 00000000..591502d7 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/no_30ms_sample_data.cc @@ -0,0 +1,502 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// See the header for documentation on the meaning of this data. + +#include "tensorflow/lite/micro/examples/micro_speech/no_30ms_sample_data.h" + +const int g_no_30ms_sample_data_size = 480; +const int16_t g_no_30ms_sample_data[480] = { + 5713, + 5735, + 5735, + 5737, + 5701, + 5691, + 5656, + 5633, + 5611, + 5552, + 5475, + 5394, + 5293, + 5177, + 5064, + 4924, + 4737, + 4599, + 4420, + 4237, + 4048, + 3828, + 3623, + 3413, + 3183, + 2915, + 2622, + 2308, + 1980, + 1657, + 1261, + 901, + 549, + 205, + -85, + -383, + -688, + -969, + -1246, + -1530, + -1850, + -2206, + -2561, + -2915, + -3224, + -3482, + -3713, + -3921, + -4107, + -4287, + -4470, + -4660, + -4850, + -5057, + -5239, + -5395, + -5540, + -5619, + -5697, + -5724, + -5697, + -5675, + -5633, + -5590, + -5579, + -5530, + -5486, + -5442, + -5426, + -5391, + -5348, + -5276, + -5197, + -5124, + -5039, + -4925, + -4808, + -4677, + -4581, + -4479, + -4343, + -4218, + -4087, + -3970, + -3858, + -3729, + -3570, + -3384, + -3206, + -3020, + -2839, + -2636, + -2453, + -2287, + -2185, + -2154, + -1926, + -1562, + -1223, + -758, + -473, + -64, + 395, + 599, + 880, + 814, + 938, + 1172, + 1498, + 1928, + 2127, + 2422, + 2608, + 2841, + 2937, + 2886, + 2815, + 2985, + 3324, + 3757, + 4152, + 4481, + 4652, + 4917, + 4965, + 4766, + 4583, + 4328, + 4503, + 4815, + 5118, + 5408, + 5682, + 5956, + 6082, + 6055, + 5744, + 5426, + 5341, + 5427, + 5606, + 5882, + 6065, + 6226, + 6428, + 6477, + 6385, + 6009, + 5728, + 5552, + 5439, + 5339, + 5200, + 5008, + 4947, + 4835, + 4614, + 4330, + 3887, + 3521, + 3111, + 2460, + 1983, + 1297, + 650, + 279, + -353, + -720, + -1044, + -1518, + -1668, + -2117, + -2496, + -2743, + -3266, + -3607, + -3790, + -4149, + -4075, + -4042, + -4096, + -3981, + -4138, + -4226, + -4214, + -4503, + -4455, + -4577, + -4642, + -4346, + -4351, + -4270, + -4263, + -4522, + -4521, + -4673, + -4814, + -4731, + -4950, + -5011, + -5004, + -5288, + -5341, + -5566, + -5833, + -5783, + -5929, + -5847, + -5765, + -5828, + -5644, + -5613, + -5615, + -5428, + -5291, + -5014, + -4554, + -4277, + -3964, + -3854, + -3829, + -3612, + -3603, + -3438, + -3137, + -2831, + -2164, + -1438, + -939, + -330, + -156, + 46, + 242, + 73, + 242, + 220, + 239, + 542, + 565, + 739, + 872, + 801, + 857, + 676, + 543, + 586, + 567, + 828, + 1142, + 1490, + 1985, + 2508, + 2982, + 3438, + 3699, + 3939, + 4069, + 4178, + 4420, + 4622, + 4917, + 5338, + 5801, + 6285, + 6658, + 6963, + 7213, + 7233, + 7328, + 7176, + 7038, + 7031, + 6860, + 6957, + 6767, + 6599, + 6523, + 6212, + 6147, + 6063, + 5860, + 6020, + 6015, + 6033, + 6184, + 5722, + 5607, + 5016, + 4337, + 4063, + 3229, + 3080, + 3006, + 2804, + 3035, + 2541, + 2136, + 1879, + 1012, + 401, + -575, + -1584, + -1930, + -2278, + -2485, + -2477, + -2712, + -2747, + -2766, + -3320, + -3592, + -4188, + -4669, + -4672, + -4939, + -4789, + -4426, + -4203, + -3674, + -3563, + -3656, + -3759, + -4067, + -4257, + -4522, + -4970, + -5204, + -5237, + -5139, + -4907, + -4911, + -4917, + -4921, + -5007, + -5230, + -5654, + -6122, + -6464, + -6733, + -6948, + -7067, + -6972, + -6800, + -6520, + -6132, + -5830, + -5382, + -5091, + -4797, + -4546, + -4472, + -4362, + -4350, + -4235, + -3851, + -3454, + -3144, + -2735, + -2341, + -1845, + -1262, + -958, + -549, + -166, + 66, + 382, + 366, + 352, + 341, + 85, + -13, + -176, + -303, + -235, + -341, + -309, + -227, + -249, + -50, + 143, + 384, + 874, + 1149, + 1552, + 2155, + 2767, + 3499, + 3994, + 4460, + 4920, + 5288, + 5569, + 5704, + 5881, + 6094, + 6461, + 6653, + 6803, + 7115, + 7311, + 7521, + 7612, + 7443, + 7380, + 7124, + 6742, + 6495, + 5964, + 5656, + 5415, + 5167, + 5656, + 5813, + 6027, + 6401, + 6351, + 6787, + 7019, + 6581, + 6512, + 5965, + 5308, + 5140, + 4336, + 4147, + 3899, + 3398, + 3360, + 2830, + 2624, + 1968, + 1026, + 395, + -699, + -1424, + -2327, + -3006, + -3192, + -3435, + -3337, + -3686, + -3513, + -3350, + -3502, + -3261, + -3878, + -4005, + -4063, + -4187, + -3767, + -3598, + -3384, + -3300, + -3094, + -2857, + -3023, + -3274, + -3851, + -4352, + -4523, + -4943, + -5477, + -5612, + -5682, + -5733, + -5714, + -5965, + -6110, + -5950, + -6158, + -6548, + -6897, + -7165, + -7281, + -7352, + -7258, + -7185, + -6659, + -5946, + -5470, +}; diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/no_30ms_sample_data.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/no_30ms_sample_data.h new file mode 100644 index 00000000..026ff3a1 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/no_30ms_sample_data.h @@ -0,0 +1,32 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// This data was created from the PCM data in a WAV file held in v2 of the +// Speech Commands test dataset, at the path: +// speech_commands_test_set_v0.02/no/f9643d42_nohash_4.wav +// The data was extracted starting at an offset of 8,960, which corresponds to +// the 29th spectrogram slice. It's designed to be used to test the +// preprocessing pipeline, to ensure that the expected spectrogram slice is +// produced given this input. + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_NO_30MS_SAMPLE_DATA_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_NO_30MS_SAMPLE_DATA_H_ + +#include + +extern const int g_no_30ms_sample_data_size; +extern const int16_t g_no_30ms_sample_data[]; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_NO_30MS_SAMPLE_DATA_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/recognize_commands.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/recognize_commands.cc new file mode 100644 index 00000000..0837432a --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/recognize_commands.cc @@ -0,0 +1,144 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/micro_speech/recognize_commands.h" + +#include + +RecognizeCommands::RecognizeCommands(tflite::ErrorReporter *error_reporter, + int32_t average_window_duration_ms, + uint8_t detection_threshold, + int32_t suppression_ms, + int32_t minimum_count) + : error_reporter_(error_reporter), + average_window_duration_ms_(average_window_duration_ms), + detection_threshold_(detection_threshold), + suppression_ms_(suppression_ms), + minimum_count_(minimum_count), + previous_results_(error_reporter) +{ + previous_top_label_ = "silence"; + previous_top_label_time_ = std::numeric_limits::min(); +} + +TfLiteStatus RecognizeCommands::ProcessLatestResults( + const TfLiteTensor *latest_results, const int32_t current_time_ms, + const char **found_command, uint8_t *score, bool *is_new_command) +{ + if ((latest_results->dims->size != 2) || + (latest_results->dims->data[0] != 1) || + (latest_results->dims->data[1] != kCategoryCount)) { + TF_LITE_REPORT_ERROR( + error_reporter_, + "The results for recognition should contain %d elements, but there are " + "%d in an %d-dimensional shape", + kCategoryCount, latest_results->dims->data[1], + latest_results->dims->size); + return kTfLiteError; + } + + if (latest_results->type != kTfLiteInt8) { + TF_LITE_REPORT_ERROR( + error_reporter_, + "The results for recognition should be int8_t elements, but are %d", + latest_results->type); + return kTfLiteError; + } + + if ((!previous_results_.empty()) && + (current_time_ms < previous_results_.front().time_)) { + TF_LITE_REPORT_ERROR( + error_reporter_, + "Results must be fed in increasing time order, but received a " + "timestamp of %d that was earlier than the previous one of %d", + current_time_ms, previous_results_.front().time_); + return kTfLiteError; + } + + // Add the latest results to the head of the queue. + previous_results_.push_back({ current_time_ms, latest_results->data.int8 }); + + // Prune any earlier results that are too old for the averaging window. + const int64_t time_limit = current_time_ms - average_window_duration_ms_; + while ((!previous_results_.empty()) && + previous_results_.front().time_ < time_limit) { + previous_results_.pop_front(); + } + + // If there are too few results, assume the result will be unreliable and + // bail. + const int64_t how_many_results = previous_results_.size(); + const int64_t earliest_time = previous_results_.front().time_; + const int64_t samples_duration = current_time_ms - earliest_time; + if ((how_many_results < minimum_count_) || + (samples_duration < (average_window_duration_ms_ / 4))) { + *found_command = previous_top_label_; + *score = 0; + *is_new_command = false; + return kTfLiteOk; + } + + // Calculate the average score across all the results in the window. + int32_t average_scores[kCategoryCount]; + for (int offset = 0; offset < previous_results_.size(); ++offset) { + PreviousResultsQueue::Result previous_result = + previous_results_.from_front(offset); + const int8_t *scores = previous_result.scores; + for (int i = 0; i < kCategoryCount; ++i) { + if (offset == 0) { + average_scores[i] = scores[i] + 128; + } else { + average_scores[i] += scores[i] + 128; + } + } + } + for (int i = 0; i < kCategoryCount; ++i) { + average_scores[i] /= how_many_results; + } + + // Find the current highest scoring category. + int current_top_index = 0; + int32_t current_top_score = 0; + for (int i = 0; i < kCategoryCount; ++i) { + if (average_scores[i] > current_top_score) { + current_top_score = average_scores[i]; + current_top_index = i; + } + } + const char *current_top_label = kCategoryLabels[current_top_index]; + + // If we've recently had another label trigger, assume one that occurs too + // soon afterwards is a bad result. + int64_t time_since_last_top; + if ((previous_top_label_ == kCategoryLabels[0]) || + (previous_top_label_time_ == std::numeric_limits::min())) { + time_since_last_top = std::numeric_limits::max(); + } else { + time_since_last_top = current_time_ms - previous_top_label_time_; + } + if ((current_top_score > detection_threshold_) && + ((current_top_label != previous_top_label_) || + (time_since_last_top > suppression_ms_))) { + previous_top_label_ = current_top_label; + previous_top_label_time_ = current_time_ms; + *is_new_command = true; + } else { + *is_new_command = false; + } + *found_command = current_top_label; + *score = current_top_score; + + return kTfLiteOk; +} diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/recognize_commands.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/recognize_commands.h new file mode 100644 index 00000000..87ccd3d4 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/recognize_commands.h @@ -0,0 +1,179 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_RECOGNIZE_COMMANDS_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_RECOGNIZE_COMMANDS_H_ + +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" + +// Partial implementation of std::dequeue, just providing the functionality +// that's needed to keep a record of previous neural network results over a +// short time period, so they can be averaged together to produce a more +// accurate overall prediction. This doesn't use any dynamic memory allocation +// so it's a better fit for microcontroller applications, but this does mean +// there are hard limits on the number of results it can store. +class PreviousResultsQueue { +public: + PreviousResultsQueue(tflite::ErrorReporter *error_reporter) + : error_reporter_(error_reporter), front_index_(0), size_(0) + { + } + + // Data structure that holds an inference result, and the time when it + // was recorded. + struct Result { + Result() + : time_(0), scores() + { + } + Result(int32_t time, int8_t *input_scores) + : time_(time) + { + for (int i = 0; i < kCategoryCount; ++i) { + scores[i] = input_scores[i]; + } + } + int32_t time_; + int8_t scores[kCategoryCount]; + }; + + int size() + { + return size_; + } + bool empty() + { + return size_ == 0; + } + Result &front() + { + return results_[front_index_]; + } + Result &back() + { + int back_index = front_index_ + (size_ - 1); + if (back_index >= kMaxResults) { + back_index -= kMaxResults; + } + return results_[back_index]; + } + + void push_back(const Result &entry) + { + if (size() >= kMaxResults) { + TF_LITE_REPORT_ERROR( + error_reporter_, + "Couldn't push_back latest result, too many already!"); + return; + } + size_ += 1; + back() = entry; + } + + Result pop_front() + { + if (size() <= 0) { + TF_LITE_REPORT_ERROR(error_reporter_, + "Couldn't pop_front result, none present!"); + return Result(); + } + Result result = front(); + front_index_ += 1; + if (front_index_ >= kMaxResults) { + front_index_ = 0; + } + size_ -= 1; + return result; + } + + // Most of the functions are duplicates of dequeue containers, but this + // is a helper that makes it easy to iterate through the contents of the + // queue. + Result &from_front(int offset) + { + if ((offset < 0) || (offset >= size_)) { + TF_LITE_REPORT_ERROR(error_reporter_, + "Attempt to read beyond the end of the queue!"); + offset = size_ - 1; + } + int index = front_index_ + offset; + if (index >= kMaxResults) { + index -= kMaxResults; + } + return results_[index]; + } + +private: + tflite::ErrorReporter *error_reporter_; + static constexpr int kMaxResults = 50; + Result results_[kMaxResults]; + + int front_index_; + int size_; +}; + +// This class is designed to apply a very primitive decoding model on top of the +// instantaneous results from running an audio recognition model on a single +// window of samples. It applies smoothing over time so that noisy individual +// label scores are averaged, increasing the confidence that apparent matches +// are real. +// To use it, you should create a class object with the configuration you +// want, and then feed results from running a TensorFlow model into the +// processing method. The timestamp for each subsequent call should be +// increasing from the previous, since the class is designed to process a stream +// of data over time. +class RecognizeCommands { +public: + // labels should be a list of the strings associated with each one-hot score. + // The window duration controls the smoothing. Longer durations will give a + // higher confidence that the results are correct, but may miss some commands. + // The detection threshold has a similar effect, with high values increasing + // the precision at the cost of recall. The minimum count controls how many + // results need to be in the averaging window before it's seen as a reliable + // average. This prevents erroneous results when the averaging window is + // initially being populated for example. The suppression argument disables + // further recognitions for a set time after one has been triggered, which can + // help reduce spurious recognitions. + explicit RecognizeCommands(tflite::ErrorReporter *error_reporter, + int32_t average_window_duration_ms = 1000, + uint8_t detection_threshold = 200, + int32_t suppression_ms = 1500, + int32_t minimum_count = 3); + + // Call this with the results of running a model on sample data. + TfLiteStatus ProcessLatestResults(const TfLiteTensor *latest_results, + const int32_t current_time_ms, + const char **found_command, uint8_t *score, + bool *is_new_command); + +private: + // Configuration + tflite::ErrorReporter *error_reporter_; + int32_t average_window_duration_ms_; + uint8_t detection_threshold_; + int32_t suppression_ms_; + int32_t minimum_count_; + + // Working variables + PreviousResultsQueue previous_results_; + const char *previous_top_label_; + int32_t previous_top_label_time_; +}; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_RECOGNIZE_COMMANDS_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/recognize_commands_test.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/recognize_commands_test.cc new file mode 100644 index 00000000..bbc3f77b --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/recognize_commands_test.cc @@ -0,0 +1,220 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/micro_speech/recognize_commands.h" + +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(PreviousResultsQueueBasic) +{ + tflite::MicroErrorReporter micro_error_reporter; + + PreviousResultsQueue queue(µ_error_reporter); + TF_LITE_MICRO_EXPECT_EQ(0, queue.size()); + + int8_t scores_a[4] = { 0, 0, 0, 1 }; + queue.push_back({ 0, scores_a }); + TF_LITE_MICRO_EXPECT_EQ(1, queue.size()); + TF_LITE_MICRO_EXPECT_EQ(0, queue.front().time_); + TF_LITE_MICRO_EXPECT_EQ(0, queue.back().time_); + + int8_t scores_b[4] = { 0, 0, 1, 0 }; + queue.push_back({ 1, scores_b }); + TF_LITE_MICRO_EXPECT_EQ(2, queue.size()); + TF_LITE_MICRO_EXPECT_EQ(0, queue.front().time_); + TF_LITE_MICRO_EXPECT_EQ(1, queue.back().time_); + + PreviousResultsQueue::Result pop_result = queue.pop_front(); + TF_LITE_MICRO_EXPECT_EQ(0, pop_result.time_); + TF_LITE_MICRO_EXPECT_EQ(1, queue.size()); + TF_LITE_MICRO_EXPECT_EQ(1, queue.front().time_); + TF_LITE_MICRO_EXPECT_EQ(1, queue.back().time_); + + int8_t scores_c[4] = { 0, 1, 0, 0 }; + queue.push_back({ 2, scores_c }); + TF_LITE_MICRO_EXPECT_EQ(2, queue.size()); + TF_LITE_MICRO_EXPECT_EQ(1, queue.front().time_); + TF_LITE_MICRO_EXPECT_EQ(2, queue.back().time_); +} + +TF_LITE_MICRO_TEST(PreviousResultsQueuePushPop) +{ + tflite::MicroErrorReporter micro_error_reporter; + + PreviousResultsQueue queue(µ_error_reporter); + TF_LITE_MICRO_EXPECT_EQ(0, queue.size()); + + for (int i = 0; i < 123; ++i) { + int8_t scores[4] = { 0, 0, 0, 1 }; + queue.push_back({ i, scores }); + TF_LITE_MICRO_EXPECT_EQ(1, queue.size()); + TF_LITE_MICRO_EXPECT_EQ(i, queue.front().time_); + TF_LITE_MICRO_EXPECT_EQ(i, queue.back().time_); + + PreviousResultsQueue::Result pop_result = queue.pop_front(); + TF_LITE_MICRO_EXPECT_EQ(i, pop_result.time_); + TF_LITE_MICRO_EXPECT_EQ(0, queue.size()); + } +} + +TF_LITE_MICRO_TEST(RecognizeCommandsTestBasic) +{ + tflite::MicroErrorReporter micro_error_reporter; + + RecognizeCommands recognize_commands(µ_error_reporter); + + const int8_t result_data[] = { 127, -128, -128, -128 }; + int result_dims[] = { 2, 1, 4 }; + TfLiteTensor results = tflite::testing::CreateQuantizedTensor( + result_data, tflite::testing::IntArrayFromInts(result_dims), -128.0f, + 127.0f); + + const char *found_command; + uint8_t score; + bool is_new_command; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, recognize_commands.ProcessLatestResults( + &results, 0, &found_command, &score, &is_new_command)); +} + +TF_LITE_MICRO_TEST(RecognizeCommandsTestFindCommands) +{ + tflite::MicroErrorReporter micro_error_reporter; + + RecognizeCommands recognize_commands(µ_error_reporter, 1000, 51); + + const int8_t yes_data[] = { -128, -128, 127, -128 }; + int yes_dims[] = { 2, 1, 4 }; + TfLiteTensor yes_results = tflite::testing::CreateQuantizedTensor( + yes_data, tflite::testing::IntArrayFromInts(yes_dims), -128.0f, 127.0f); + + bool has_found_new_command = false; + const char *new_command; + for (int i = 0; i < 10; ++i) { + const char *found_command; + uint8_t score; + bool is_new_command; + int32_t current_time_ms = 0 + (i * 100); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, recognize_commands.ProcessLatestResults( + &yes_results, current_time_ms, &found_command, &score, + &is_new_command)); + if (is_new_command) { + TF_LITE_MICRO_EXPECT(!has_found_new_command); + has_found_new_command = true; + new_command = found_command; + } + } + TF_LITE_MICRO_EXPECT(has_found_new_command); + if (has_found_new_command) { + TF_LITE_MICRO_EXPECT_EQ(0, tflite::testing::TestStrcmp("yes", new_command)); + } + + const int8_t no_data[] = { -128, -128, -128, 127 }; + int no_dims[] = { 2, 1, 4 }; + TfLiteTensor no_results = tflite::testing::CreateQuantizedTensor( + no_data, tflite::testing::IntArrayFromInts(no_dims), -128.0f, 127.0f); + has_found_new_command = false; + new_command = ""; + uint8_t score; + for (int i = 0; i < 10; ++i) { + const char *found_command; + bool is_new_command; + int32_t current_time_ms = 1000 + (i * 100); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, recognize_commands.ProcessLatestResults( + &no_results, current_time_ms, &found_command, &score, + &is_new_command)); + if (is_new_command) { + TF_LITE_MICRO_EXPECT(!has_found_new_command); + has_found_new_command = true; + new_command = found_command; + } + } + TF_LITE_MICRO_EXPECT(has_found_new_command); + if (has_found_new_command) { + TF_LITE_MICRO_EXPECT_EQ(231, score); + TF_LITE_MICRO_EXPECT_EQ(0, tflite::testing::TestStrcmp("no", new_command)); + } +} + +TF_LITE_MICRO_TEST(RecognizeCommandsTestBadInputLength) +{ + tflite::MicroErrorReporter micro_error_reporter; + + RecognizeCommands recognize_commands(µ_error_reporter, 1000, 51); + + const int8_t bad_data[] = { -128, -128, 127 }; + int bad_dims[] = { 2, 1, 3 }; + TfLiteTensor bad_results = tflite::testing::CreateQuantizedTensor( + bad_data, tflite::testing::IntArrayFromInts(bad_dims), -128.0f, 127.0f); + + const char *found_command; + uint8_t score; + bool is_new_command; + TF_LITE_MICRO_EXPECT_NE( + kTfLiteOk, recognize_commands.ProcessLatestResults( + &bad_results, 0, &found_command, &score, &is_new_command)); +} + +TF_LITE_MICRO_TEST(RecognizeCommandsTestBadInputTimes) +{ + tflite::MicroErrorReporter micro_error_reporter; + + RecognizeCommands recognize_commands(µ_error_reporter, 1000, 51); + + const int8_t result_data[] = { -128, -128, 127, -128 }; + int result_dims[] = { 2, 1, 4 }; + TfLiteTensor results = tflite::testing::CreateQuantizedTensor( + result_data, tflite::testing::IntArrayFromInts(result_dims), -128.0f, + 127.0f); + + const char *found_command; + uint8_t score; + bool is_new_command; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, recognize_commands.ProcessLatestResults( + &results, 100, &found_command, &score, &is_new_command)); + TF_LITE_MICRO_EXPECT_NE( + kTfLiteOk, recognize_commands.ProcessLatestResults( + &results, 0, &found_command, &score, &is_new_command)); +} + +TF_LITE_MICRO_TEST(RecognizeCommandsTestTooFewInputs) +{ + tflite::MicroErrorReporter micro_error_reporter; + + RecognizeCommands recognize_commands(µ_error_reporter, 1000, 51); + + const int8_t result_data[] = { -128, -128, 127, -128 }; + int result_dims[] = { 2, 1, 4 }; + TfLiteTensor results = tflite::testing::CreateQuantizedTensor( + result_data, tflite::testing::IntArrayFromInts(result_dims), -128.0f, + 127.0f); + + const char *found_command; + uint8_t score; + bool is_new_command; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, recognize_commands.ProcessLatestResults( + &results, 100, &found_command, &score, &is_new_command)); + TF_LITE_MICRO_EXPECT_EQ(0, score); + TF_LITE_MICRO_EXPECT_EQ(false, is_new_command); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/fixed_point/simple_features_generator.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/fixed_point/simple_features_generator.cc new file mode 100644 index 00000000..eda2fc2b --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/fixed_point/simple_features_generator.cc @@ -0,0 +1,221 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// Reference implementation of the preprocessing pipeline, with the same +// results as the audio tutorial at +// https://www.tensorflow.org/tutorials/sequences/audio_recognition +// This module takes 30ms of PCM-encoded signed 16-bit audio samples (at 16KHz, +// so 480 values), and extracts a power spectrum of frequencies. There are 43 +// frequency bands in the result, derived from the original 256 output from the +// discrete Fourier transform, and averaged together in groups of 6. +// It's expected that most platforms will have optimized versions of the +// functions used here, for example replacing the DFT with an FFT, so this +// version shouldn't be used where performance is critical. +// This implementation uses fixed point for any non-constant calculations, +// instead of floating point, to help show how this can work on platforms that +// don't have good float support. + +#include "tensorflow/lite/micro/examples/micro_speech/simple_features/simple_features_generator.h" + +#include + +#include "tensorflow/lite/micro/examples/micro_speech/simple_features/simple_model_settings.h" + +namespace { + +// q format notation: qx.y => 1 sign bit, x-1 integer bits, y fraction bits. +// Use standard (non-saturating) arithmetic with signed ints of size x+y bits. +// Sacrifice some precision to avoid use of 64-bit ints. + +// q1.15 * q1.15 => q2.30 +inline int32_t Q1_15_FixedMultiply_Q2_30(int16_t a, int16_t b) +{ + int32_t big_a = a; + int32_t big_b = b; + return big_a * big_b; +} + +// q2.30 * q2.30 => q10.22 +inline int32_t Q2_30_FixedMultiply_Q10_22(int32_t a, int32_t b) +{ + // q2.30 result + int32_t tmp = (a >> 15) * (b >> 15); + // q10.22 result + return tmp >> 8; +} + +// q10.22 * q10.22 => q10.22 +// Will overflow if product is >= 512. +// Largest product in small test set is 465.25 +inline int32_t Q10_22_FixedMultiply_Q10_22(int32_t a, int32_t b) +{ + // q10.22 result + return (a >> 11) * (b >> 11); +} + +// float => q2.30 +// No checking for saturation. Only used for inputs in range [-1, 1]. +inline int32_t FloatToFixed_Q2_30(float input) +{ + return static_cast(roundf(input * (1 << 30))); +} + +// Performs a discrete Fourier transform on the real inputs. This corresponds to +// rdft() in the FFT package at http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html, +// and to kiss_fftr() in KISSFFT at https://github.com/mborgerding/kissfft. +// It takes in an array of float real values, and returns a result of the same +// length with q10.22 fixed point real and imaginary components interleaved, so +// fourier_output[0] is the first real value, fourier_output[1] is the first +// imaginary, fourier_output[2] is the second real, and so on. +// The calling function should ensure that the array passed in as fourier_output +// is at least time_series_size in length. Most optimized FFT implementations +// require the length to be a power of two as well, but this version doesn't +// enforce that. + +// input: q2.30 fixed point. output: q10.22 fixed point. +// Outputs interpreted as q10.22 fixed point are un-scaled. +void CalculateDiscreteFourierTransform(int32_t *time_series, + int time_series_size, + int32_t *fourier_output) +{ + for (int i = 0; i < time_series_size / 2; ++i) { + int32_t real = 0; + for (int j = 0; j < time_series_size; ++j) { + const int32_t real_scale = + FloatToFixed_Q2_30(cos(j * i * M_PI * 2 / time_series_size)); + real += Q2_30_FixedMultiply_Q10_22(time_series[j], real_scale); + } + int32_t imaginary = 0; + for (int j = 0; j < time_series_size; ++j) { + const int32_t imaginary_scale = + FloatToFixed_Q2_30(sin(j * i * M_PI * 2 / time_series_size)); + imaginary -= Q2_30_FixedMultiply_Q10_22(time_series[j], imaginary_scale); + } + fourier_output[(i * 2) + 0] = real; + fourier_output[(i * 2) + 1] = imaginary; + } +} + +// Produces a simple sine curve that is used to ensure frequencies at the center +// of the current sample window are weighted more heavily than those at the end. +// q1.15 output format. +void CalculatePeriodicHann(int window_length, int16_t *window_function) +{ + for (int i = 0; i < window_length; ++i) { + const float real_value = (0.5 - 0.5 * cos((2 * M_PI * i) / window_length)); + int tmp = static_cast(roundf(real_value * (1 << 15))); + // Saturate the 0x8000 value to 0x7fff + if (tmp > 0x7fff) + tmp = 0x7fff; + window_function[i] = tmp; + } +} + +} // namespace + +TfLiteStatus GenerateSimpleFeatures(tflite::ErrorReporter *error_reporter, + const int16_t *input, int input_size, + int output_size, uint8_t *output) +{ + // Ensure our input and output data arrays are valid. + if (input_size > kMaxAudioSampleSize) { + TF_LITE_REPORT_ERROR(error_reporter, "Input size %d larger than %d", + input_size, kMaxAudioSampleSize); + return kTfLiteError; + } + if (output_size != kFeatureSliceSize) { + TF_LITE_REPORT_ERROR(error_reporter, + "Requested output size %d doesn't match %d", + output_size, kFeatureSliceSize); + return kTfLiteError; + } + + // Pre-calculate the window function we'll be applying to the input data. + // In a real application, we'd calculate this table once in an initialization + // function and store it for repeated reuse. + // q1.15 format. + int16_t window_function[kMaxAudioSampleSize]; + CalculatePeriodicHann(input_size, window_function); + + // Apply the window function to our time series input, and pad it with zeroes + // to the next power of two. + int32_t fixed_input[kMaxAudioSampleSize]; + for (int i = 0; i < kMaxAudioSampleSize; ++i) { + if (i < input_size) { + // input is int16_t. Treat as q1.15 fixed point value in range [-1,1) + // window_function is also q1.15 fixed point number + fixed_input[i] = Q1_15_FixedMultiply_Q2_30(input[i], window_function[i]); + } else { + fixed_input[i] = 0; + } + } + + // Pull the frequency data from the time series sample. + // Calculated in q10.22 format from q2.30 inputs. + int32_t fourier_values[kMaxAudioSampleSize]; + CalculateDiscreteFourierTransform(fixed_input, kMaxAudioSampleSize, + fourier_values); + + // We have the complex numbers giving us information about each frequency + // band, but all we want to know is how strong each frequency is, so calculate + // the squared magnitude by adding together the squares of each component. + int32_t power_spectrum[kMaxAudioSampleSize / 2]; + for (int i = 0; i < (kMaxAudioSampleSize / 2); ++i) { + const int32_t real = fourier_values[(i * 2) + 0]; + const int32_t imaginary = fourier_values[(i * 2) + 1]; + // q10.22 results + power_spectrum[i] = Q10_22_FixedMultiply_Q10_22(real, real) + + Q10_22_FixedMultiply_Q10_22(imaginary, imaginary); + } + + // Finally, reduce the size of the output by averaging together six adjacent + // frequencies into each slot, producing an array of 43 values. + // Power_spectrum numbers are q10.22. Divide by kAverageWindowSize inside + // loop to prevent overflow. + for (int i = 0; i < kFeatureSliceSize; ++i) { + int32_t average = 0; + for (int j = 0; j < kAverageWindowSize; ++j) { + const int index = (i * kAverageWindowSize) + j; + if (index < (kMaxAudioSampleSize / 2)) { + average += power_spectrum[index] / kAverageWindowSize; + } + } + // Quantize the result into eight bits, effectively multiplying by two. + // The 127.5 constant here has to match the features_max value defined in + // tensorflow/examples/speech_commands/input_data.py, and this also assumes + // that features_min is zero. + // + // q10.22 input + // integer output + // + // output = (input - features_min) * + // (output_max - output_min) / (features_max - features_min) + // == (input) * (255) / (127.5) + // == input * 2 + // == input << 1 + // Also want to round to nearest integer and only keep integer bits + // => ((input << 1) + 0x200000) >> 22 + // == (input + 0x100000) >> 21 + int32_t quantized_average = (average + 0x100000) >> 21; + if (quantized_average < 0) { + quantized_average = 0; + } + if (quantized_average > 255) { + quantized_average = 255; + } + output[i] = quantized_average; + } + return kTfLiteOk; +} diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/model.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/model.cc new file mode 100644 index 00000000..e3ec0615 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/model.cc @@ -0,0 +1,1675 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// This is a standard TensorFlow Lite FlatBuffer model file that has been +// converted into a C data array, so it can be easily compiled into a binary +// for devices that don't have a file system. It was created using the command: +// xxd -i model.tflite > model.cc + +#include "tensorflow/lite/micro/examples/micro_speech/simple_features/model.h" + +const unsigned char g_model[] = { + 0x18, 0x00, 0x00, 0x00, 0x54, 0x46, 0x4c, 0x33, 0x00, 0x00, 0x0e, 0x00, + 0x18, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x4d, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xf4, 0x47, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, + 0x54, 0x4f, 0x43, 0x4f, 0x20, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, + 0x65, 0x64, 0x2e, 0x00, 0x09, 0x00, 0x00, 0x00, 0xd4, 0x47, 0x00, 0x00, + 0xb4, 0x47, 0x00, 0x00, 0xe4, 0x02, 0x00, 0x00, 0xb4, 0x02, 0x00, 0x00, + 0xac, 0x02, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xb8, 0xb3, 0xff, 0xff, + 0xbc, 0xb3, 0xff, 0xff, 0xc0, 0xb3, 0xff, 0xff, 0x1e, 0xb4, 0xff, 0xff, + 0x04, 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x89, 0xa5, 0xe8, 0xc1, + 0xb1, 0x89, 0x5b, 0xc6, 0x4f, 0x9b, 0xd3, 0x74, 0x93, 0x88, 0xff, 0xaf, + 0x89, 0xff, 0xf4, 0x70, 0xcc, 0x75, 0x78, 0xbf, 0x92, 0xcd, 0xa9, 0xa8, + 0xd6, 0x6a, 0x6f, 0x7b, 0x7f, 0xd8, 0xa8, 0xb1, 0xe6, 0x32, 0x21, 0x70, + 0xa0, 0x9c, 0x6f, 0xc8, 0xc6, 0x59, 0x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, 0xa8, 0xaa, 0xb2, 0xbc, 0x51, 0xda, 0xa3, 0x80, 0x8b, 0xa2, 0xc8, + 0xd1, 0x94, 0xe1, 0xc4, 0xbd, 0xae, 0xae, 0xcc, 0xb3, 0xca, 0xd5, 0xa1, + 0xd5, 0xa7, 0xaf, 0xd2, 0xb4, 0x8d, 0xcc, 0xc8, 0x63, 0xa3, 0xa4, 0xdf, + 0x6f, 0x7e, 0x98, 0xdf, 0x1b, 0x7b, 0x43, 0x99, 0xb0, 0x99, 0x71, 0xdb, + 0x63, 0x7b, 0x69, 0x9c, 0xba, 0xcd, 0x90, 0xd0, 0xb6, 0xa6, 0x9e, 0x95, + 0x50, 0xb6, 0xff, 0xff, 0xae, 0xb6, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xc7, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, + 0xda, 0xb6, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0xc0, 0x44, 0x00, 0x00, + 0x2c, 0x30, 0x38, 0x5a, 0x3d, 0x4c, 0x44, 0x3b, 0x48, 0x48, 0x44, 0x57, + 0x3f, 0x43, 0x45, 0x3a, 0x24, 0x32, 0x21, 0x5c, 0x3f, 0x3a, 0x38, 0x3a, + 0x35, 0x35, 0x2f, 0x51, 0x3c, 0x3a, 0x45, 0x3a, 0x3b, 0x41, 0x39, 0x55, + 0x3c, 0x41, 0x39, 0x44, 0x3a, 0x40, 0x37, 0x48, 0x33, 0x47, 0x36, 0x3e, + 0x3c, 0x41, 0x3f, 0x3e, 0x3e, 0x47, 0x36, 0x3e, 0x41, 0x33, 0x3e, 0x3b, + 0x3a, 0x46, 0x45, 0x40, 0x48, 0x3a, 0x35, 0x4b, 0x45, 0x4d, 0x3c, 0x49, + 0x42, 0x44, 0x3c, 0x4c, 0x3e, 0x3c, 0x44, 0x32, 0x33, 0x41, 0x36, 0x4b, + 0x38, 0x3b, 0x3c, 0x38, 0x3b, 0x45, 0x34, 0x46, 0x40, 0x4e, 0x44, 0x35, + 0x43, 0x36, 0x3d, 0x40, 0x3e, 0x48, 0x40, 0x34, 0x3a, 0x46, 0x45, 0x43, + 0x45, 0x3f, 0x47, 0x37, 0x36, 0x35, 0x44, 0x3a, 0x3e, 0x37, 0x39, 0x40, + 0x3a, 0x3f, 0x3f, 0x4c, 0x3e, 0x41, 0x43, 0x35, 0x3f, 0x3d, 0x3d, 0x4c, + 0x3c, 0x4a, 0x46, 0x3c, 0x3a, 0x41, 0x40, 0x4e, 0x36, 0x47, 0x40, 0x3b, + 0x47, 0x42, 0x38, 0x4d, 0x48, 0x47, 0x3c, 0x3c, 0x33, 0x3b, 0x3e, 0x42, + 0x3f, 0x3e, 0x3a, 0x3d, 0x32, 0x39, 0x41, 0x46, 0x3a, 0x3a, 0x3e, 0x3e, + 0x47, 0x48, 0x4e, 0x36, 0x44, 0x40, 0x41, 0x45, 0x3a, 0x3c, 0x38, 0x55, + 0x2e, 0x26, 0x2f, 0x32, 0x3f, 0x41, 0x3e, 0x4c, 0x45, 0x36, 0x40, 0x31, + 0x17, 0x2e, 0x14, 0x53, 0x34, 0x30, 0x34, 0x3f, 0x2e, 0x44, 0x2b, 0x4e, + 0x34, 0x3e, 0x34, 0x43, 0x3d, 0x35, 0x3f, 0x46, 0x39, 0x40, 0x38, 0x3e, + 0x35, 0x3b, 0x35, 0x45, 0x3d, 0x40, 0x38, 0x37, 0x40, 0x3e, 0x32, 0x3e, + 0x41, 0x39, 0x30, 0x41, 0x3a, 0x32, 0x3e, 0x3d, 0x39, 0x31, 0x33, 0x3e, + 0x41, 0x47, 0x40, 0x47, 0x35, 0x33, 0x3c, 0x32, 0x40, 0x3c, 0x42, 0x49, + 0x34, 0x38, 0x39, 0x37, 0x39, 0x35, 0x40, 0x4d, 0x37, 0x43, 0x42, 0x3e, + 0x3f, 0x3c, 0x3e, 0x51, 0x36, 0x37, 0x42, 0x41, 0x36, 0x31, 0x43, 0x3d, + 0x46, 0x43, 0x37, 0x46, 0x32, 0x45, 0x42, 0x36, 0x3f, 0x42, 0x42, 0x41, + 0x3d, 0x46, 0x39, 0x41, 0x3c, 0x3f, 0x38, 0x3c, 0x43, 0x43, 0x3d, 0x3c, + 0x3d, 0x41, 0x38, 0x42, 0x3a, 0x3d, 0x43, 0x42, 0x41, 0x40, 0x39, 0x36, + 0x3a, 0x3c, 0x3c, 0x4f, 0x44, 0x36, 0x39, 0x35, 0x46, 0x46, 0x36, 0x4a, + 0x3a, 0x42, 0x43, 0x39, 0x3f, 0x3d, 0x3c, 0x47, 0x38, 0x3f, 0x43, 0x40, + 0x36, 0x3c, 0x45, 0x3b, 0x33, 0x36, 0x3b, 0x39, 0x3c, 0x35, 0x40, 0x38, + 0x40, 0x3e, 0x3f, 0x48, 0x3f, 0x34, 0x40, 0x53, 0x26, 0x2c, 0x29, 0x39, + 0x2a, 0x38, 0x3f, 0x45, 0x32, 0x31, 0x4a, 0x37, 0x1c, 0x28, 0x09, 0x43, + 0x35, 0x3b, 0x33, 0x3c, 0x32, 0x3f, 0x28, 0x41, 0x36, 0x35, 0x3a, 0x37, + 0x41, 0x39, 0x32, 0x3c, 0x40, 0x3c, 0x3c, 0x32, 0x38, 0x39, 0x37, 0x44, + 0x3a, 0x33, 0x41, 0x36, 0x37, 0x3c, 0x35, 0x3a, 0x3d, 0x30, 0x3d, 0x41, + 0x37, 0x3c, 0x45, 0x3a, 0x37, 0x2f, 0x36, 0x3c, 0x3a, 0x3d, 0x39, 0x48, + 0x46, 0x33, 0x3a, 0x3e, 0x40, 0x3d, 0x3b, 0x52, 0x38, 0x45, 0x34, 0x47, + 0x39, 0x36, 0x37, 0x56, 0x42, 0x3f, 0x33, 0x36, 0x38, 0x3f, 0x40, 0x53, + 0x3e, 0x37, 0x3d, 0x3c, 0x48, 0x3a, 0x3d, 0x33, 0x39, 0x40, 0x3e, 0x35, + 0x3d, 0x46, 0x38, 0x36, 0x37, 0x43, 0x3a, 0x3c, 0x40, 0x38, 0x39, 0x3b, + 0x39, 0x3a, 0x42, 0x3d, 0x34, 0x3f, 0x35, 0x43, 0x3a, 0x35, 0x46, 0x3a, + 0x48, 0x38, 0x3b, 0x48, 0x3c, 0x35, 0x42, 0x3d, 0x3a, 0x3d, 0x38, 0x42, + 0x3e, 0x3c, 0x33, 0x39, 0x34, 0x30, 0x42, 0x44, 0x41, 0x3d, 0x3c, 0x39, + 0x3c, 0x3a, 0x39, 0x41, 0x3d, 0x44, 0x3c, 0x40, 0x3f, 0x3e, 0x42, 0x3f, + 0x37, 0x40, 0x39, 0x3b, 0x42, 0x43, 0x49, 0x37, 0x39, 0x46, 0x35, 0x3c, + 0x3e, 0x39, 0x45, 0x52, 0x24, 0x2d, 0x38, 0x35, 0x3a, 0x3a, 0x3c, 0x44, + 0x39, 0x32, 0x51, 0x3f, 0x16, 0x34, 0x0a, 0x49, 0x39, 0x38, 0x39, 0x3e, + 0x2f, 0x36, 0x24, 0x3f, 0x37, 0x34, 0x38, 0x3b, 0x34, 0x34, 0x30, 0x3b, + 0x3d, 0x36, 0x35, 0x42, 0x33, 0x40, 0x37, 0x35, 0x43, 0x3f, 0x3f, 0x39, + 0x3a, 0x43, 0x36, 0x3e, 0x39, 0x3d, 0x3f, 0x3d, 0x47, 0x3b, 0x39, 0x37, + 0x35, 0x42, 0x3f, 0x3b, 0x41, 0x3a, 0x42, 0x4b, 0x3d, 0x3f, 0x3d, 0x3e, + 0x38, 0x3b, 0x34, 0x4e, 0x3f, 0x39, 0x36, 0x43, 0x39, 0x35, 0x41, 0x4d, + 0x3c, 0x39, 0x43, 0x33, 0x37, 0x3b, 0x41, 0x48, 0x3c, 0x3f, 0x39, 0x32, + 0x35, 0x3d, 0x42, 0x35, 0x3d, 0x3e, 0x37, 0x3b, 0x38, 0x3a, 0x44, 0x36, + 0x42, 0x35, 0x48, 0x40, 0x3a, 0x44, 0x44, 0x39, 0x43, 0x41, 0x3c, 0x37, + 0x47, 0x3b, 0x42, 0x42, 0x45, 0x3a, 0x40, 0x46, 0x35, 0x3f, 0x3a, 0x48, + 0x35, 0x44, 0x3f, 0x37, 0x33, 0x3e, 0x45, 0x49, 0x39, 0x43, 0x47, 0x37, + 0x3f, 0x3f, 0x3b, 0x44, 0x38, 0x3d, 0x39, 0x42, 0x37, 0x3e, 0x40, 0x45, + 0x3b, 0x3f, 0x40, 0x34, 0x42, 0x3f, 0x43, 0x3c, 0x43, 0x41, 0x38, 0x38, + 0x38, 0x41, 0x55, 0x33, 0x33, 0x39, 0x39, 0x3c, 0x35, 0x39, 0x38, 0x42, + 0x27, 0x26, 0x32, 0x41, 0x41, 0x32, 0x3f, 0x47, 0x3a, 0x38, 0x48, 0x37, + 0x11, 0x27, 0x08, 0x49, 0x35, 0x42, 0x3c, 0x2e, 0x34, 0x43, 0x25, 0x3b, + 0x3a, 0x33, 0x37, 0x30, 0x3c, 0x36, 0x2d, 0x3c, 0x3b, 0x39, 0x3b, 0x40, + 0x46, 0x3a, 0x30, 0x42, 0x35, 0x32, 0x36, 0x3a, 0x3a, 0x34, 0x34, 0x33, + 0x3d, 0x30, 0x3b, 0x42, 0x41, 0x3f, 0x3d, 0x3b, 0x44, 0x3d, 0x41, 0x41, + 0x3d, 0x3f, 0x40, 0x51, 0x42, 0x42, 0x36, 0x45, 0x30, 0x40, 0x32, 0x4f, + 0x3a, 0x3c, 0x40, 0x39, 0x3d, 0x3b, 0x3e, 0x4b, 0x3d, 0x37, 0x42, 0x46, + 0x40, 0x40, 0x47, 0x3d, 0x35, 0x3c, 0x3f, 0x46, 0x37, 0x37, 0x3a, 0x2e, + 0x3d, 0x3c, 0x3a, 0x46, 0x3a, 0x44, 0x3c, 0x3a, 0x32, 0x44, 0x31, 0x41, + 0x43, 0x36, 0x49, 0x39, 0x3d, 0x37, 0x3f, 0x41, 0x3b, 0x3b, 0x3c, 0x42, + 0x3c, 0x34, 0x3f, 0x3b, 0x40, 0x3e, 0x48, 0x47, 0x3e, 0x3c, 0x38, 0x39, + 0x3f, 0x35, 0x39, 0x3f, 0x3e, 0x3e, 0x3b, 0x43, 0x41, 0x40, 0x43, 0x41, + 0x3f, 0x37, 0x39, 0x41, 0x46, 0x32, 0x3d, 0x41, 0x36, 0x3f, 0x3e, 0x3f, + 0x36, 0x48, 0x43, 0x3d, 0x43, 0x3f, 0x34, 0x3d, 0x34, 0x35, 0x4f, 0x32, + 0x3c, 0x3f, 0x3d, 0x3f, 0x39, 0x3c, 0x3d, 0x47, 0x23, 0x36, 0x33, 0x45, + 0x37, 0x2e, 0x42, 0x42, 0x39, 0x34, 0x4f, 0x3f, 0x19, 0x2b, 0x01, 0x50, + 0x35, 0x3f, 0x37, 0x3c, 0x33, 0x35, 0x25, 0x32, 0x38, 0x3e, 0x40, 0x40, + 0x2f, 0x38, 0x35, 0x3d, 0x31, 0x42, 0x44, 0x3c, 0x3a, 0x3d, 0x2d, 0x3e, + 0x3b, 0x3e, 0x3d, 0x31, 0x3b, 0x37, 0x35, 0x31, 0x36, 0x35, 0x34, 0x31, + 0x41, 0x3a, 0x33, 0x32, 0x3c, 0x31, 0x3e, 0x3d, 0x40, 0x3b, 0x34, 0x45, + 0x36, 0x39, 0x3e, 0x3f, 0x3c, 0x45, 0x37, 0x4b, 0x42, 0x3d, 0x33, 0x43, + 0x3e, 0x40, 0x35, 0x4e, 0x38, 0x36, 0x3a, 0x33, 0x38, 0x44, 0x3f, 0x3c, + 0x3f, 0x40, 0x3a, 0x3c, 0x3c, 0x3c, 0x44, 0x29, 0x3a, 0x40, 0x35, 0x3a, + 0x3d, 0x48, 0x3b, 0x30, 0x45, 0x41, 0x45, 0x40, 0x37, 0x32, 0x3a, 0x35, + 0x3f, 0x38, 0x3b, 0x43, 0x3b, 0x3f, 0x33, 0x40, 0x3b, 0x40, 0x38, 0x33, + 0x39, 0x3c, 0x3c, 0x3f, 0x43, 0x33, 0x43, 0x40, 0x43, 0x3d, 0x33, 0x42, + 0x40, 0x32, 0x3e, 0x36, 0x40, 0x38, 0x43, 0x40, 0x44, 0x38, 0x34, 0x3c, + 0x3e, 0x39, 0x47, 0x43, 0x40, 0x3b, 0x3f, 0x3f, 0x3c, 0x3b, 0x4b, 0x33, + 0x36, 0x49, 0x32, 0x41, 0x48, 0x45, 0x57, 0x3a, 0x40, 0x42, 0x40, 0x46, + 0x36, 0x35, 0x3c, 0x46, 0x22, 0x2e, 0x33, 0x3e, 0x3c, 0x39, 0x44, 0x4d, + 0x3f, 0x41, 0x51, 0x44, 0x15, 0x2e, 0x02, 0x4e, 0x39, 0x3a, 0x3c, 0x35, + 0x30, 0x38, 0x1e, 0x31, 0x40, 0x3b, 0x39, 0x3d, 0x3a, 0x37, 0x35, 0x36, + 0x46, 0x36, 0x3c, 0x3e, 0x39, 0x3e, 0x32, 0x40, 0x3b, 0x35, 0x42, 0x41, + 0x41, 0x38, 0x41, 0x35, 0x42, 0x36, 0x3c, 0x42, 0x3d, 0x41, 0x35, 0x31, + 0x3f, 0x44, 0x3e, 0x41, 0x3f, 0x35, 0x42, 0x4b, 0x3e, 0x36, 0x37, 0x34, + 0x36, 0x3d, 0x40, 0x49, 0x41, 0x3e, 0x3d, 0x3b, 0x38, 0x37, 0x40, 0x47, + 0x35, 0x32, 0x43, 0x38, 0x36, 0x3b, 0x33, 0x47, 0x33, 0x34, 0x3d, 0x47, + 0x3c, 0x37, 0x3d, 0x2b, 0x3a, 0x36, 0x3b, 0x3d, 0x43, 0x38, 0x35, 0x32, + 0x32, 0x37, 0x43, 0x36, 0x3f, 0x48, 0x38, 0x30, 0x3a, 0x3c, 0x42, 0x34, + 0x37, 0x3c, 0x37, 0x40, 0x48, 0x3e, 0x35, 0x3b, 0x3f, 0x38, 0x39, 0x3e, + 0x37, 0x35, 0x36, 0x3d, 0x3b, 0x3c, 0x40, 0x3d, 0x34, 0x40, 0x46, 0x42, + 0x3f, 0x3c, 0x3c, 0x3e, 0x40, 0x40, 0x3d, 0x3f, 0x3f, 0x44, 0x46, 0x41, + 0x32, 0x43, 0x40, 0x41, 0x3c, 0x42, 0x39, 0x38, 0x48, 0x44, 0x3d, 0x38, + 0x34, 0x40, 0x4e, 0x31, 0x3c, 0x42, 0x39, 0x48, 0x3c, 0x33, 0x3e, 0x40, + 0x20, 0x27, 0x39, 0x45, 0x45, 0x36, 0x47, 0x4c, 0x35, 0x3e, 0x4a, 0x36, + 0x16, 0x2f, 0x04, 0x4f, 0x3a, 0x35, 0x36, 0x3a, 0x2d, 0x36, 0x21, 0x34, + 0x3b, 0x32, 0x3d, 0x3c, 0x3c, 0x3f, 0x3b, 0x3b, 0x41, 0x46, 0x40, 0x3d, + 0x3b, 0x44, 0x33, 0x42, 0x34, 0x33, 0x3e, 0x45, 0x3f, 0x46, 0x39, 0x33, + 0x3b, 0x37, 0x37, 0x37, 0x42, 0x47, 0x3c, 0x35, 0x31, 0x41, 0x44, 0x3a, + 0x3b, 0x33, 0x39, 0x44, 0x42, 0x33, 0x3d, 0x3f, 0x43, 0x33, 0x41, 0x4a, + 0x35, 0x46, 0x36, 0x3e, 0x39, 0x41, 0x41, 0x4c, 0x34, 0x3d, 0x38, 0x33, + 0x3c, 0x3f, 0x43, 0x44, 0x37, 0x35, 0x35, 0x3c, 0x43, 0x34, 0x3e, 0x2d, + 0x3f, 0x35, 0x38, 0x3c, 0x33, 0x35, 0x43, 0x2a, 0x40, 0x33, 0x34, 0x40, + 0x3d, 0x38, 0x36, 0x2d, 0x36, 0x3c, 0x43, 0x3d, 0x37, 0x3d, 0x39, 0x38, + 0x3b, 0x3e, 0x3c, 0x46, 0x35, 0x35, 0x43, 0x44, 0x39, 0x40, 0x34, 0x39, + 0x3d, 0x34, 0x40, 0x45, 0x38, 0x35, 0x3e, 0x39, 0x3c, 0x44, 0x48, 0x44, + 0x41, 0x3e, 0x3c, 0x45, 0x3a, 0x3c, 0x3c, 0x46, 0x3a, 0x40, 0x39, 0x43, + 0x35, 0x35, 0x3e, 0x45, 0x3a, 0x34, 0x3c, 0x39, 0x46, 0x3a, 0x4f, 0x35, + 0x32, 0x3d, 0x36, 0x41, 0x32, 0x38, 0x3f, 0x45, 0x2d, 0x34, 0x2a, 0x35, + 0x43, 0x3f, 0x41, 0x49, 0x41, 0x3c, 0x4b, 0x3f, 0x17, 0x31, 0x02, 0x4f, + 0x30, 0x38, 0x39, 0x40, 0x33, 0x3a, 0x25, 0x38, 0x35, 0x3c, 0x39, 0x35, + 0x34, 0x41, 0x34, 0x43, 0x40, 0x40, 0x46, 0x3d, 0x40, 0x38, 0x3f, 0x3b, + 0x35, 0x39, 0x3c, 0x39, 0x34, 0x38, 0x3f, 0x36, 0x3a, 0x38, 0x44, 0x3f, + 0x3f, 0x38, 0x3c, 0x33, 0x41, 0x42, 0x38, 0x33, 0x3c, 0x3b, 0x3c, 0x46, + 0x38, 0x3b, 0x3f, 0x33, 0x3f, 0x48, 0x3b, 0x49, 0x3f, 0x3a, 0x3d, 0x3f, + 0x47, 0x3d, 0x30, 0x45, 0x36, 0x42, 0x3d, 0x36, 0x43, 0x38, 0x3b, 0x3d, + 0x3c, 0x30, 0x3b, 0x43, 0x3d, 0x41, 0x34, 0x2e, 0x43, 0x3d, 0x43, 0x46, + 0x43, 0x3c, 0x3c, 0x2e, 0x3c, 0x43, 0x34, 0x43, 0x3e, 0x43, 0x3f, 0x2b, + 0x45, 0x40, 0x3a, 0x43, 0x36, 0x39, 0x3f, 0x3d, 0x3a, 0x3c, 0x35, 0x3b, + 0x36, 0x3f, 0x45, 0x3e, 0x45, 0x40, 0x3f, 0x36, 0x45, 0x42, 0x35, 0x3e, + 0x3a, 0x3a, 0x3f, 0x40, 0x3e, 0x3c, 0x39, 0x46, 0x43, 0x3e, 0x3f, 0x3f, + 0x40, 0x3c, 0x40, 0x4b, 0x41, 0x35, 0x3b, 0x3e, 0x49, 0x32, 0x3e, 0x41, + 0x31, 0x37, 0x3d, 0x3b, 0x3f, 0x45, 0x50, 0x3a, 0x3f, 0x3c, 0x44, 0x36, + 0x43, 0x37, 0x3d, 0x4b, 0x29, 0x39, 0x2f, 0x38, 0x45, 0x36, 0x40, 0x4e, + 0x39, 0x3f, 0x48, 0x43, 0x23, 0x3c, 0x06, 0x51, 0x37, 0x3b, 0x3e, 0x3b, + 0x28, 0x45, 0x2b, 0x37, 0x3f, 0x33, 0x3f, 0x41, 0x31, 0x36, 0x33, 0x3a, + 0x3a, 0x35, 0x3b, 0x33, 0x3e, 0x36, 0x35, 0x40, 0x3a, 0x34, 0x3a, 0x38, + 0x34, 0x3a, 0x3a, 0x34, 0x42, 0x45, 0x40, 0x3e, 0x40, 0x38, 0x39, 0x34, + 0x38, 0x37, 0x3f, 0x3e, 0x3c, 0x32, 0x3f, 0x46, 0x3f, 0x44, 0x3b, 0x3e, + 0x44, 0x45, 0x36, 0x3e, 0x36, 0x3f, 0x3b, 0x40, 0x39, 0x34, 0x38, 0x41, + 0x42, 0x3e, 0x3d, 0x47, 0x3e, 0x45, 0x33, 0x40, 0x3e, 0x3a, 0x44, 0x3d, + 0x3c, 0x3a, 0x3a, 0x2c, 0x3a, 0x3d, 0x35, 0x45, 0x3c, 0x41, 0x36, 0x30, + 0x32, 0x32, 0x3a, 0x3b, 0x35, 0x3c, 0x43, 0x2d, 0x35, 0x3f, 0x41, 0x37, + 0x3f, 0x46, 0x34, 0x39, 0x3c, 0x43, 0x40, 0x3e, 0x3e, 0x36, 0x3e, 0x3c, + 0x37, 0x3a, 0x3d, 0x3a, 0x3c, 0x38, 0x44, 0x41, 0x3f, 0x3b, 0x3c, 0x47, + 0x40, 0x3b, 0x41, 0x47, 0x3e, 0x45, 0x39, 0x3e, 0x37, 0x45, 0x4b, 0x4c, + 0x37, 0x37, 0x37, 0x3c, 0x3c, 0x3d, 0x40, 0x38, 0x39, 0x3e, 0x43, 0x3f, + 0x38, 0x45, 0x51, 0x3c, 0x31, 0x34, 0x3b, 0x48, 0x46, 0x41, 0x40, 0x40, + 0x2c, 0x39, 0x32, 0x42, 0x3c, 0x2e, 0x49, 0x4d, 0x3c, 0x3f, 0x45, 0x38, + 0x20, 0x38, 0x03, 0x55, 0x33, 0x3e, 0x32, 0x39, 0x32, 0x3b, 0x24, 0x2b, + 0x42, 0x35, 0x45, 0x32, 0x2e, 0x3b, 0x2f, 0x3f, 0x3c, 0x37, 0x39, 0x3b, + 0x34, 0x34, 0x3d, 0x36, 0x3d, 0x39, 0x3b, 0x30, 0x3c, 0x3e, 0x40, 0x32, + 0x3d, 0x3c, 0x3c, 0x3e, 0x33, 0x33, 0x3f, 0x3a, 0x33, 0x3e, 0x46, 0x36, + 0x3a, 0x3d, 0x40, 0x40, 0x3f, 0x41, 0x3a, 0x42, 0x34, 0x32, 0x34, 0x46, + 0x3b, 0x31, 0x40, 0x37, 0x37, 0x32, 0x3e, 0x47, 0x3f, 0x3b, 0x3e, 0x43, + 0x49, 0x45, 0x3a, 0x3d, 0x3e, 0x44, 0x40, 0x31, 0x39, 0x3e, 0x3b, 0x2d, + 0x3b, 0x3a, 0x33, 0x3d, 0x39, 0x37, 0x3e, 0x32, 0x41, 0x3c, 0x3a, 0x37, + 0x3b, 0x40, 0x39, 0x2f, 0x3e, 0x3f, 0x47, 0x32, 0x3e, 0x3b, 0x3e, 0x3e, + 0x40, 0x3e, 0x40, 0x3c, 0x41, 0x39, 0x38, 0x46, 0x45, 0x32, 0x47, 0x31, + 0x36, 0x47, 0x37, 0x49, 0x3a, 0x3f, 0x47, 0x3a, 0x41, 0x3b, 0x3c, 0x4f, + 0x3e, 0x36, 0x3b, 0x47, 0x35, 0x39, 0x41, 0x4e, 0x3d, 0x3e, 0x3b, 0x46, + 0x38, 0x39, 0x3b, 0x45, 0x3e, 0x3f, 0x44, 0x42, 0x44, 0x3f, 0x55, 0x3b, + 0x41, 0x3d, 0x43, 0x43, 0x37, 0x3f, 0x3d, 0x4c, 0x28, 0x3d, 0x36, 0x3c, + 0x3e, 0x3e, 0x48, 0x50, 0x3e, 0x39, 0x45, 0x41, 0x22, 0x37, 0x07, 0x4f, + 0x2e, 0x33, 0x38, 0x3f, 0x31, 0x3a, 0x1b, 0x36, 0x34, 0x38, 0x3c, 0x37, + 0x37, 0x3e, 0x36, 0x35, 0x36, 0x3b, 0x3d, 0x38, 0x42, 0x48, 0x3d, 0x40, + 0x40, 0x44, 0x3d, 0x39, 0x37, 0x3b, 0x3d, 0x33, 0x3d, 0x35, 0x42, 0x3c, + 0x39, 0x3e, 0x43, 0x2d, 0x3c, 0x40, 0x43, 0x43, 0x45, 0x35, 0x3c, 0x44, + 0x34, 0x3c, 0x3d, 0x31, 0x39, 0x40, 0x39, 0x3d, 0x3e, 0x34, 0x3e, 0x3b, + 0x40, 0x38, 0x42, 0x4a, 0x40, 0x3b, 0x35, 0x3d, 0x36, 0x38, 0x35, 0x42, + 0x3c, 0x3c, 0x3d, 0x3b, 0x38, 0x39, 0x45, 0x28, 0x3a, 0x37, 0x37, 0x35, + 0x3a, 0x3d, 0x35, 0x2a, 0x3c, 0x3f, 0x37, 0x34, 0x37, 0x3f, 0x3e, 0x2b, + 0x39, 0x43, 0x3b, 0x45, 0x35, 0x36, 0x36, 0x42, 0x33, 0x38, 0x3b, 0x35, + 0x31, 0x3f, 0x41, 0x41, 0x3c, 0x41, 0x45, 0x42, 0x3b, 0x3c, 0x39, 0x46, + 0x3c, 0x3e, 0x3a, 0x41, 0x39, 0x3d, 0x41, 0x4b, 0x40, 0x3f, 0x43, 0x3d, + 0x39, 0x39, 0x44, 0x44, 0x37, 0x42, 0x3f, 0x44, 0x3e, 0x37, 0x42, 0x35, + 0x44, 0x3f, 0x40, 0x42, 0x3f, 0x3a, 0x47, 0x3d, 0x38, 0x3a, 0x3b, 0x3a, + 0x42, 0x36, 0x3a, 0x97, 0x32, 0x31, 0x30, 0x36, 0x47, 0x3e, 0x46, 0x51, + 0x42, 0x34, 0x50, 0x34, 0x26, 0x3b, 0x06, 0x55, 0x3c, 0x3b, 0x2d, 0x3a, + 0x37, 0x37, 0x1b, 0x32, 0x39, 0x3d, 0x36, 0x40, 0x3b, 0x3f, 0x33, 0x33, + 0x3d, 0x37, 0x35, 0x37, 0x44, 0x3f, 0x35, 0x39, 0x33, 0x3c, 0x43, 0x39, + 0x3f, 0x42, 0x3e, 0x34, 0x38, 0x38, 0x39, 0x3c, 0x48, 0x3c, 0x2f, 0x30, + 0x40, 0x3c, 0x41, 0x3e, 0x3f, 0x3e, 0x36, 0x43, 0x40, 0x3c, 0x36, 0x43, + 0x43, 0x38, 0x3a, 0x47, 0x3e, 0x37, 0x39, 0x3a, 0x43, 0x45, 0x38, 0x43, + 0x3b, 0x45, 0x37, 0x44, 0x36, 0x45, 0x3a, 0x3e, 0x3e, 0x3e, 0x3d, 0x33, + 0x39, 0x36, 0x48, 0x33, 0x30, 0x42, 0x33, 0x39, 0x37, 0x3a, 0x3f, 0x34, + 0x34, 0x40, 0x40, 0x40, 0x3f, 0x3d, 0x3f, 0x33, 0x41, 0x40, 0x3b, 0x43, + 0x3b, 0x3a, 0x40, 0x3a, 0x38, 0x3e, 0x38, 0x3b, 0x38, 0x42, 0x40, 0x40, + 0x41, 0x35, 0x37, 0x38, 0x3b, 0x3c, 0x39, 0x4b, 0x32, 0x39, 0x42, 0x3c, + 0x36, 0x3d, 0x32, 0x52, 0x3a, 0x31, 0x40, 0x40, 0x3a, 0x43, 0x3d, 0x46, + 0x3c, 0x3e, 0x3e, 0x33, 0x3f, 0x41, 0x4d, 0x37, 0x39, 0x39, 0x3e, 0x3b, + 0x40, 0x39, 0x53, 0x2d, 0x46, 0x3c, 0x32, 0x42, 0x3d, 0x40, 0x40, 0x4d, + 0x2e, 0x34, 0x39, 0x3b, 0x46, 0x3b, 0x42, 0x4f, 0x3d, 0x39, 0x4e, 0x36, + 0x1a, 0x31, 0x0e, 0x56, 0x36, 0x42, 0x38, 0x44, 0x36, 0x3a, 0x20, 0x30, + 0x36, 0x34, 0x37, 0x38, 0x40, 0x41, 0x2a, 0x35, 0x3b, 0x3b, 0x3a, 0x38, + 0x33, 0x39, 0x36, 0x41, 0x43, 0x39, 0x35, 0x3d, 0x37, 0x3d, 0x33, 0x31, + 0x45, 0x33, 0x3f, 0x3b, 0x44, 0x38, 0x39, 0x34, 0x38, 0x39, 0x38, 0x3d, + 0x3a, 0x3a, 0x41, 0x40, 0x44, 0x3e, 0x3f, 0x45, 0x34, 0x31, 0x34, 0x43, + 0x3b, 0x34, 0x42, 0x3c, 0x3c, 0x43, 0x35, 0x45, 0x36, 0x38, 0x3d, 0x3c, + 0x3f, 0x3d, 0x3e, 0x45, 0x41, 0x43, 0x35, 0x3f, 0x40, 0x3f, 0x3a, 0x34, + 0x3d, 0x32, 0x41, 0x3d, 0x48, 0x42, 0x37, 0x2a, 0x3c, 0x3a, 0x3e, 0x49, + 0x38, 0x36, 0x38, 0x2e, 0x36, 0x37, 0x34, 0x3e, 0x3c, 0x43, 0x43, 0x39, + 0x39, 0x3b, 0x44, 0x46, 0x44, 0x43, 0x37, 0x46, 0x43, 0x34, 0x3b, 0x35, + 0x42, 0x41, 0x3f, 0x3d, 0x3d, 0x3a, 0x42, 0x3e, 0x38, 0x47, 0x3d, 0x49, + 0x45, 0x49, 0x3a, 0x3c, 0x3e, 0x37, 0x40, 0x46, 0x41, 0x33, 0x45, 0x36, + 0x37, 0x44, 0x49, 0x3b, 0x44, 0x40, 0x33, 0x46, 0x37, 0x39, 0x4e, 0x3a, + 0x43, 0x38, 0x3a, 0x42, 0x3a, 0x3d, 0x45, 0x50, 0x26, 0x34, 0x3b, 0x3c, + 0x46, 0x46, 0x4c, 0x54, 0x3f, 0x35, 0x4e, 0x47, 0x21, 0x39, 0x0e, 0x54, + 0x3a, 0x3a, 0x2f, 0x40, 0x2d, 0x3a, 0x1f, 0x31, 0x31, 0x42, 0x34, 0x45, + 0x37, 0x36, 0x30, 0x3b, 0x3a, 0x3a, 0x36, 0x40, 0x32, 0x36, 0x3c, 0x3c, + 0x37, 0x42, 0x35, 0x3e, 0x39, 0x47, 0x36, 0x32, 0x41, 0x30, 0x42, 0x39, + 0x39, 0x44, 0x37, 0x30, 0x41, 0x3b, 0x3d, 0x3d, 0x43, 0x3b, 0x38, 0x45, + 0x3b, 0x3a, 0x39, 0x3a, 0x31, 0x33, 0x43, 0x46, 0x3f, 0x41, 0x44, 0x3f, + 0x3b, 0x44, 0x3a, 0x4c, 0x33, 0x33, 0x33, 0x3e, 0x37, 0x3e, 0x45, 0x45, + 0x36, 0x42, 0x3e, 0x43, 0x40, 0x34, 0x36, 0x31, 0x38, 0x34, 0x41, 0x3b, + 0x32, 0x38, 0x3e, 0x29, 0x47, 0x33, 0x37, 0x45, 0x3c, 0x3d, 0x43, 0x2c, + 0x36, 0x3a, 0x3c, 0x40, 0x3d, 0x46, 0x3c, 0x37, 0x40, 0x44, 0x37, 0x38, + 0x3e, 0x41, 0x3c, 0x40, 0x33, 0x3f, 0x44, 0x32, 0x44, 0x3a, 0x43, 0x42, + 0x3e, 0x38, 0x44, 0x3b, 0x41, 0x48, 0x3f, 0x4e, 0x3f, 0x44, 0x35, 0x45, + 0x34, 0x3f, 0x42, 0x4b, 0x37, 0x37, 0x3e, 0x45, 0x46, 0x45, 0x46, 0x3d, + 0x3e, 0x39, 0x3b, 0x3a, 0x46, 0x3a, 0x56, 0x35, 0x46, 0x3d, 0x40, 0x3b, + 0x36, 0x39, 0x3f, 0x54, 0x27, 0x2b, 0x34, 0x3c, 0x48, 0x3d, 0x49, 0x4c, + 0x3e, 0x3d, 0x4e, 0x42, 0x25, 0x3b, 0x10, 0x4d, 0x30, 0x36, 0x3e, 0x36, + 0x2e, 0x31, 0x1d, 0x37, 0x3a, 0x39, 0x33, 0x3f, 0x39, 0x38, 0x2e, 0x36, + 0x44, 0x3e, 0x41, 0x37, 0x3b, 0x30, 0x3b, 0x48, 0x31, 0x39, 0x41, 0x3e, + 0x37, 0x37, 0x34, 0x2f, 0x35, 0x3b, 0x3a, 0x3e, 0x45, 0x3e, 0x3f, 0x35, + 0x39, 0x39, 0x3b, 0x44, 0x43, 0x3c, 0x3e, 0x46, 0x40, 0x3a, 0x36, 0x45, + 0x41, 0x40, 0x36, 0x44, 0x3a, 0x37, 0x47, 0x47, 0x3d, 0x36, 0x43, 0x4e, + 0x3b, 0x38, 0x40, 0x48, 0x44, 0x43, 0x45, 0x3f, 0x43, 0x3c, 0x3b, 0x37, + 0x43, 0x41, 0x39, 0x2f, 0x3d, 0x45, 0x3e, 0x3e, 0x42, 0x40, 0x41, 0x2f, + 0x47, 0x38, 0x3a, 0x48, 0x3e, 0x35, 0x37, 0x2a, 0x34, 0x38, 0x41, 0x3b, + 0x3d, 0x37, 0x3b, 0x35, 0x38, 0x3e, 0x41, 0x3c, 0x41, 0x43, 0x3d, 0x46, + 0x47, 0x47, 0x3d, 0x35, 0x48, 0x41, 0x3d, 0x3e, 0x34, 0x47, 0x38, 0x38, + 0x39, 0x3e, 0x38, 0x4d, 0x43, 0x36, 0x42, 0x40, 0x3e, 0x41, 0x3f, 0x4c, + 0x3e, 0x3e, 0x37, 0x44, 0x3e, 0x3b, 0x47, 0x3e, 0x3f, 0x3b, 0x39, 0x3c, + 0x3c, 0x3c, 0x53, 0x3b, 0x3b, 0x32, 0x3e, 0x3f, 0x32, 0x3c, 0x37, 0x4b, + 0x33, 0x30, 0x2f, 0x41, 0x47, 0x42, 0x49, 0x4f, 0x3b, 0x42, 0x4c, 0x44, + 0x1f, 0x37, 0x16, 0x4e, 0x3b, 0x3f, 0x30, 0x36, 0x35, 0x38, 0x26, 0x36, + 0x32, 0x3b, 0x38, 0x3c, 0x30, 0x3e, 0x34, 0x3e, 0x3d, 0x34, 0x39, 0x3c, + 0x36, 0x47, 0x34, 0x41, 0x31, 0x39, 0x44, 0x3e, 0x39, 0x41, 0x32, 0x36, + 0x3b, 0x3f, 0x32, 0x3d, 0x36, 0x3e, 0x40, 0x3d, 0x45, 0x32, 0x45, 0x42, + 0x38, 0x43, 0x40, 0x42, 0x34, 0x3a, 0x43, 0x38, 0x47, 0x3f, 0x41, 0x47, + 0x34, 0x44, 0x41, 0x39, 0x3c, 0x46, 0x36, 0x4f, 0x41, 0x3e, 0x38, 0x38, + 0x3a, 0x3b, 0x43, 0x44, 0x37, 0x3f, 0x35, 0x43, 0x34, 0x3d, 0x40, 0x32, + 0x3a, 0x3b, 0x3d, 0x34, 0x35, 0x43, 0x31, 0x2c, 0x3b, 0x36, 0x38, 0x41, + 0x3c, 0x38, 0x3d, 0x31, 0x45, 0x46, 0x42, 0x41, 0x33, 0x3f, 0x3f, 0x3a, + 0x36, 0x3f, 0x3c, 0x3c, 0x3c, 0x3e, 0x39, 0x3e, 0x40, 0x37, 0x47, 0x3e, + 0x35, 0x39, 0x3d, 0x3d, 0x37, 0x36, 0x3e, 0x45, 0x38, 0x3d, 0x45, 0x43, + 0x3a, 0x32, 0x3b, 0x3a, 0x32, 0x3c, 0x3d, 0x43, 0x3d, 0x33, 0x3b, 0x3d, + 0x46, 0x3a, 0x44, 0x45, 0x3b, 0x3e, 0x3c, 0x42, 0x37, 0x37, 0x52, 0x2a, + 0x3a, 0x35, 0x35, 0x3f, 0x40, 0x38, 0x40, 0x5b, 0x35, 0x32, 0x2b, 0x3d, + 0x4a, 0x3c, 0x46, 0x56, 0x44, 0x30, 0x4d, 0x39, 0x20, 0x32, 0x0f, 0x4f, + 0x33, 0x3c, 0x35, 0x35, 0x3a, 0x45, 0x29, 0x3b, 0x31, 0x38, 0x34, 0x38, + 0x42, 0x45, 0x37, 0x3e, 0x37, 0x2e, 0x36, 0x43, 0x3f, 0x38, 0x2f, 0x41, + 0x3f, 0x41, 0x3c, 0x31, 0x37, 0x36, 0x37, 0x39, 0x41, 0x3a, 0x3a, 0x40, + 0x3e, 0x47, 0x3d, 0x37, 0x3c, 0x38, 0x35, 0x39, 0x3a, 0x43, 0x3f, 0x42, + 0x42, 0x38, 0x3e, 0x40, 0x3c, 0x3a, 0x45, 0x48, 0x37, 0x3a, 0x3e, 0x35, + 0x3a, 0x3d, 0x45, 0x4a, 0x3d, 0x37, 0x38, 0x3a, 0x3d, 0x46, 0x46, 0x41, + 0x37, 0x41, 0x40, 0x48, 0x37, 0x34, 0x3b, 0x2c, 0x39, 0x34, 0x37, 0x35, + 0x3a, 0x43, 0x39, 0x2e, 0x39, 0x3f, 0x40, 0x3e, 0x40, 0x40, 0x3c, 0x2d, + 0x3e, 0x3c, 0x37, 0x39, 0x3c, 0x3b, 0x3d, 0x3f, 0x41, 0x48, 0x3b, 0x3d, + 0x3b, 0x41, 0x45, 0x3e, 0x3a, 0x38, 0x3f, 0x3c, 0x3d, 0x3e, 0x40, 0x42, + 0x46, 0x38, 0x43, 0x34, 0x35, 0x47, 0x3d, 0x46, 0x3f, 0x3e, 0x32, 0x3f, + 0x3e, 0x3d, 0x47, 0x46, 0x38, 0x41, 0x45, 0x3f, 0x34, 0x3f, 0x41, 0x43, + 0x3e, 0x3e, 0x44, 0x3b, 0x3b, 0x36, 0x51, 0x32, 0x37, 0x3c, 0x42, 0x43, + 0x33, 0x39, 0x42, 0x61, 0x2c, 0x3b, 0x2e, 0x39, 0x42, 0x39, 0x42, 0x54, + 0x3c, 0x3a, 0x48, 0x35, 0x26, 0x34, 0x15, 0x51, 0x35, 0x40, 0x36, 0x3c, + 0x2d, 0x37, 0x25, 0x38, 0x33, 0x3d, 0x3d, 0x39, 0x3e, 0x3b, 0x2e, 0x4b, + 0x3d, 0x3b, 0x42, 0x37, 0x37, 0x40, 0x37, 0x40, 0x35, 0x45, 0x37, 0x37, + 0x3f, 0x41, 0x36, 0x39, 0x3c, 0x32, 0x3e, 0x38, 0x41, 0x40, 0x3e, 0x3f, + 0x3b, 0x3c, 0x43, 0x35, 0x3e, 0x3d, 0x44, 0x44, 0x3a, 0x36, 0x39, 0x3f, + 0x3a, 0x31, 0x42, 0x4d, 0x40, 0x33, 0x40, 0x45, 0x44, 0x3d, 0x40, 0x49, + 0x41, 0x3f, 0x42, 0x3a, 0x34, 0x46, 0x38, 0x46, 0x42, 0x34, 0x3a, 0x40, + 0x40, 0x41, 0x3d, 0x32, 0x35, 0x48, 0x35, 0x3e, 0x44, 0x41, 0x40, 0x2c, + 0x46, 0x38, 0x38, 0x3f, 0x36, 0x40, 0x38, 0x2a, 0x43, 0x41, 0x3e, 0x35, + 0x46, 0x3a, 0x45, 0x46, 0x46, 0x42, 0x3a, 0x3b, 0x40, 0x38, 0x35, 0x43, + 0x38, 0x3d, 0x3b, 0x41, 0x36, 0x44, 0x3f, 0x3f, 0x34, 0x3e, 0x3c, 0x3d, + 0x49, 0x36, 0x37, 0x4b, 0x38, 0x3c, 0x43, 0x37, 0x3a, 0x3f, 0x31, 0x45, + 0x3b, 0x39, 0x3f, 0x40, 0x37, 0x3c, 0x42, 0x3f, 0x3c, 0x33, 0x40, 0x3b, + 0x32, 0x3c, 0x52, 0x31, 0x3d, 0x44, 0x3b, 0x31, 0x46, 0x38, 0x40, 0x60, + 0x2b, 0x3c, 0x37, 0x34, 0x43, 0x38, 0x45, 0x57, 0x37, 0x39, 0x49, 0x33, + 0x2d, 0x3f, 0x18, 0x4e, 0x39, 0x39, 0x32, 0x3b, 0x34, 0x3b, 0x2c, 0x45, + 0x33, 0x37, 0x45, 0x42, 0x3d, 0x37, 0x2a, 0x4c, 0x3d, 0x3f, 0x3c, 0x36, + 0x37, 0x3c, 0x39, 0x47, 0x3d, 0x44, 0x3d, 0x40, 0x3d, 0x41, 0x34, 0x3e, + 0x40, 0x34, 0x3b, 0x3a, 0x41, 0x36, 0x37, 0x40, 0x3e, 0x3f, 0x3a, 0x36, + 0x3e, 0x35, 0x3b, 0x48, 0x41, 0x40, 0x3c, 0x42, 0x34, 0x41, 0x3f, 0x44, + 0x34, 0x39, 0x33, 0x39, 0x39, 0x47, 0x40, 0x48, 0x38, 0x3a, 0x43, 0x43, + 0x48, 0x3a, 0x3f, 0x46, 0x35, 0x3a, 0x33, 0x36, 0x32, 0x3c, 0x40, 0x34, + 0x40, 0x3a, 0x42, 0x3a, 0x39, 0x38, 0x41, 0x35, 0x3a, 0x3f, 0x35, 0x40, + 0x3f, 0x39, 0x39, 0x36, 0x38, 0x40, 0x3e, 0x3e, 0x3a, 0x31, 0x32, 0x44, + 0x40, 0x47, 0x3a, 0x3c, 0x43, 0x43, 0x46, 0x48, 0x40, 0x35, 0x3d, 0x37, + 0x44, 0x37, 0x33, 0x44, 0x3b, 0x3e, 0x3f, 0x37, 0x36, 0x3a, 0x38, 0x47, + 0x3a, 0x44, 0x36, 0x42, 0x3e, 0x44, 0x34, 0x46, 0x33, 0x43, 0x44, 0x3e, + 0x30, 0x48, 0x37, 0x38, 0x33, 0x3c, 0x46, 0x42, 0x38, 0x3d, 0x50, 0x39, + 0x33, 0x38, 0x3e, 0x40, 0x3b, 0x2b, 0x3b, 0x5f, 0x2b, 0x32, 0x2f, 0x37, + 0x3f, 0x3a, 0x40, 0x4e, 0x34, 0x38, 0x47, 0x37, 0x27, 0x2b, 0x1b, 0x4f, + 0x36, 0x38, 0x3a, 0x3a, 0x3b, 0x38, 0x2e, 0x3f, 0x3f, 0x42, 0x42, 0x42, + 0x36, 0x3e, 0x3c, 0x55, 0x39, 0x40, 0x44, 0x43, 0x3e, 0x33, 0x3c, 0x43, + 0x38, 0x44, 0x3b, 0x46, 0x3f, 0x45, 0x34, 0x38, 0x3c, 0x41, 0x42, 0x3d, + 0x42, 0x36, 0x43, 0x3f, 0x3c, 0x39, 0x3e, 0x39, 0x39, 0x42, 0x33, 0x47, + 0x36, 0x3d, 0x3f, 0x3b, 0x40, 0x39, 0x3b, 0x49, 0x36, 0x40, 0x3d, 0x41, + 0x40, 0x34, 0x3b, 0x4e, 0x3b, 0x36, 0x3b, 0x45, 0x40, 0x32, 0x3b, 0x49, + 0x37, 0x38, 0x3a, 0x47, 0x37, 0x40, 0x3e, 0x38, 0x40, 0x3f, 0x3c, 0x3a, + 0x47, 0x41, 0x42, 0x30, 0x40, 0x3c, 0x42, 0x3f, 0x31, 0x44, 0x39, 0x38, + 0x3b, 0x38, 0x42, 0x43, 0x41, 0x35, 0x3a, 0x39, 0x3e, 0x38, 0x39, 0x3e, + 0x3c, 0x42, 0x3d, 0x49, 0x47, 0x3c, 0x3f, 0x35, 0x41, 0x3a, 0x36, 0x43, + 0x43, 0x3b, 0x39, 0x3b, 0x36, 0x43, 0x43, 0x4e, 0x3e, 0x35, 0x37, 0x3b, + 0x3f, 0x37, 0x41, 0x48, 0x32, 0x44, 0x43, 0x32, 0x38, 0x39, 0x45, 0x39, + 0x3e, 0x3d, 0x35, 0x39, 0x35, 0x39, 0x50, 0x37, 0x39, 0x40, 0x43, 0x47, + 0x32, 0x2a, 0x40, 0x62, 0x24, 0x30, 0x36, 0x3e, 0x41, 0x32, 0x47, 0x58, + 0x39, 0x36, 0x44, 0x34, 0x26, 0x34, 0x1e, 0x50, 0x3c, 0x3b, 0x3f, 0x42, + 0x35, 0x3d, 0x2a, 0x4e, 0x40, 0x38, 0x36, 0x31, 0x3a, 0x30, 0x37, 0x4b, + 0x3c, 0x3b, 0x3b, 0x41, 0x3b, 0x3c, 0x2e, 0x45, 0x44, 0x3f, 0x3b, 0x35, + 0x3e, 0x33, 0x37, 0x3d, 0x40, 0x39, 0x39, 0x37, 0x40, 0x3e, 0x3a, 0x3e, + 0x3c, 0x3c, 0x45, 0x40, 0x3c, 0x3f, 0x3a, 0x51, 0x47, 0x3a, 0x34, 0x39, + 0x3b, 0x34, 0x44, 0x4c, 0x36, 0x3d, 0x3a, 0x35, 0x34, 0x36, 0x38, 0x4b, + 0x3f, 0x40, 0x3f, 0x3e, 0x40, 0x41, 0x47, 0x43, 0x32, 0x38, 0x46, 0x44, + 0x46, 0x43, 0x43, 0x37, 0x39, 0x49, 0x37, 0x36, 0x3e, 0x3d, 0x37, 0x3c, + 0x39, 0x37, 0x34, 0x43, 0x45, 0x32, 0x3a, 0x3a, 0x38, 0x43, 0x3b, 0x40, + 0x3b, 0x3f, 0x3d, 0x41, 0x40, 0x3d, 0x3a, 0x3b, 0x48, 0x37, 0x3d, 0x41, + 0x40, 0x3e, 0x38, 0x41, 0x3d, 0x3a, 0x38, 0x49, 0x40, 0x3c, 0x42, 0x41, + 0x3a, 0x38, 0x38, 0x4c, 0x3e, 0x41, 0x40, 0x3b, 0x3d, 0x3e, 0x3c, 0x46, + 0x3e, 0x42, 0x41, 0x38, 0x42, 0x42, 0x41, 0x3e, 0x3e, 0x37, 0x3c, 0x43, + 0x43, 0x3b, 0x54, 0x2b, 0x45, 0x3b, 0x43, 0x41, 0x41, 0x26, 0x3f, 0x60, + 0x25, 0x2b, 0x2e, 0x3a, 0x40, 0x31, 0x40, 0x49, 0x40, 0x31, 0x46, 0x3c, + 0x1e, 0x2a, 0x1a, 0x47, 0x33, 0x37, 0x37, 0x34, 0x31, 0x36, 0x25, 0x41, + 0x2e, 0x36, 0x35, 0x33, 0x33, 0x34, 0x31, 0x45, 0x3a, 0x3f, 0x3d, 0x40, + 0x3c, 0x41, 0x30, 0x3c, 0x3f, 0x46, 0x37, 0x3c, 0x3a, 0x3c, 0x36, 0x3a, + 0x47, 0x3d, 0x31, 0x3f, 0x40, 0x3e, 0x36, 0x44, 0x41, 0x3d, 0x36, 0x3f, + 0x37, 0x3f, 0x34, 0x4b, 0x31, 0x47, 0x43, 0x3e, 0x3e, 0x3a, 0x3b, 0x4b, + 0x37, 0x32, 0x38, 0x3d, 0x37, 0x47, 0x46, 0x4d, 0x36, 0x3c, 0x3f, 0x3a, + 0x41, 0x31, 0x47, 0x43, 0x3d, 0x3d, 0x3e, 0x35, 0x3d, 0x46, 0x49, 0x2a, + 0x37, 0x3c, 0x39, 0x3d, 0x47, 0x3c, 0x34, 0x2c, 0x3e, 0x38, 0x47, 0x32, + 0x36, 0x36, 0x41, 0x38, 0x35, 0x44, 0x48, 0x3b, 0x39, 0x3e, 0x38, 0x3e, + 0x40, 0x36, 0x37, 0x46, 0x39, 0x3b, 0x34, 0x45, 0x40, 0x3b, 0x48, 0x36, + 0x34, 0x44, 0x37, 0x46, 0x3f, 0x42, 0x33, 0x36, 0x43, 0x3c, 0x41, 0x46, + 0x31, 0x42, 0x43, 0x44, 0x44, 0x3e, 0x42, 0x3b, 0x3b, 0x3a, 0x3c, 0x37, + 0x42, 0x41, 0x46, 0x38, 0x41, 0x3b, 0x40, 0x44, 0x37, 0x3c, 0x4c, 0x2e, + 0x3a, 0x3e, 0x3b, 0x36, 0x33, 0x27, 0x37, 0x5d, 0x27, 0x34, 0x32, 0x41, + 0x41, 0x3f, 0x40, 0x5d, 0x40, 0x3d, 0x48, 0x39, 0x2e, 0x30, 0x1f, 0x3f, + 0x38, 0x3f, 0x40, 0x33, 0x40, 0x38, 0x31, 0x3f, 0x42, 0x3e, 0x3b, 0x3a, + 0x42, 0x36, 0x3a, 0x42, 0x3c, 0x3b, 0x3d, 0x41, 0x3d, 0x40, 0x40, 0x3e, + 0x36, 0x41, 0x47, 0x3d, 0x33, 0x32, 0x33, 0x44, 0x3e, 0x3a, 0x3e, 0x3d, + 0x45, 0x3f, 0x38, 0x3f, 0x40, 0x3a, 0x3c, 0x46, 0x32, 0x42, 0x3c, 0x51, + 0x33, 0x38, 0x3a, 0x38, 0x41, 0x34, 0x45, 0x4e, 0x35, 0x3c, 0x42, 0x3e, + 0x3f, 0x45, 0x44, 0x4e, 0x39, 0x47, 0x3a, 0x33, 0x3e, 0x3b, 0x45, 0x42, + 0x37, 0x3a, 0x3e, 0x33, 0x41, 0x48, 0x32, 0x2a, 0x3b, 0x37, 0x3f, 0x3d, + 0x3a, 0x42, 0x41, 0x2f, 0x34, 0x3e, 0x49, 0x3b, 0x38, 0x3e, 0x3d, 0x3a, + 0x37, 0x3c, 0x44, 0x41, 0x39, 0x42, 0x3f, 0x39, 0x40, 0x35, 0x3d, 0x41, + 0x3b, 0x45, 0x44, 0x48, 0x3d, 0x42, 0x36, 0x33, 0x3e, 0x44, 0x3f, 0x41, + 0x42, 0x40, 0x49, 0x34, 0x48, 0x41, 0x3f, 0x40, 0x3c, 0x45, 0x47, 0x34, + 0x41, 0x37, 0x47, 0x3e, 0x41, 0x41, 0x39, 0x42, 0x3f, 0x3a, 0x46, 0x33, + 0x39, 0x41, 0x38, 0x38, 0x3e, 0x42, 0x41, 0x38, 0x35, 0x32, 0x33, 0x38, + 0x3a, 0x3f, 0x45, 0x66, 0x33, 0x47, 0x38, 0x3c, 0x41, 0x2f, 0x48, 0x55, + 0x33, 0x3e, 0x49, 0x3b, 0x3c, 0x30, 0x24, 0x45, 0x3c, 0x44, 0x43, 0x32, + 0x3d, 0x3f, 0x35, 0x3b, 0x3e, 0x36, 0x38, 0x3a, 0x36, 0x37, 0x3b, 0x41, + 0x38, 0x42, 0x3e, 0x43, 0x39, 0x3f, 0x3c, 0x40, 0x37, 0x43, 0x3e, 0x3b, + 0x3d, 0x35, 0x35, 0x3d, 0x43, 0x3f, 0x3a, 0x35, 0x37, 0x3c, 0x31, 0x47, + 0x44, 0x45, 0x40, 0x32, 0x44, 0x36, 0x38, 0x51, 0x3c, 0x41, 0x45, 0x37, + 0x39, 0x44, 0x3e, 0x4f, 0x3c, 0x3a, 0x38, 0x40, 0x3f, 0x34, 0x39, 0x4e, + 0x3d, 0x39, 0x45, 0x3f, 0x3e, 0x3c, 0x3b, 0x42, 0x3b, 0x3b, 0x34, 0x3d, + 0x41, 0x44, 0x39, 0x2e, 0x37, 0x44, 0x45, 0x37, 0x3d, 0x41, 0x3f, 0x33, + 0x3f, 0x3e, 0x3e, 0x40, 0x44, 0x3f, 0x37, 0x32, 0x35, 0x3e, 0x43, 0x41, + 0x39, 0x37, 0x35, 0x3f, 0x48, 0x3d, 0x43, 0x49, 0x38, 0x35, 0x3f, 0x48, + 0x3b, 0x3a, 0x34, 0x3f, 0x3c, 0x44, 0x3a, 0x40, 0x36, 0x35, 0x44, 0x36, + 0x44, 0x3b, 0x3d, 0x38, 0x3c, 0x44, 0x47, 0x3a, 0x3b, 0x45, 0x41, 0x3a, + 0x39, 0x35, 0x44, 0x3a, 0x49, 0x36, 0x48, 0x31, 0x42, 0x43, 0x42, 0x34, + 0x41, 0x40, 0x4d, 0x36, 0x3e, 0x35, 0x39, 0x3b, 0x3f, 0x41, 0x38, 0x39, + 0x3c, 0x44, 0x3f, 0x39, 0x3a, 0x36, 0x3d, 0x36, 0x3a, 0x3a, 0x34, 0x3b, + 0x38, 0x2f, 0x40, 0x34, 0x32, 0x4d, 0x43, 0x45, 0x4e, 0x3f, 0x48, 0x35, + 0x3b, 0x4d, 0x4f, 0x39, 0x42, 0x36, 0x46, 0x36, 0x4a, 0x3c, 0x37, 0x41, + 0x40, 0x43, 0x50, 0x36, 0x3e, 0x39, 0x44, 0x40, 0x36, 0x47, 0x3f, 0x36, + 0x45, 0x40, 0x45, 0x41, 0x3b, 0x37, 0x41, 0x39, 0x3b, 0x48, 0x37, 0x34, + 0x41, 0x45, 0x49, 0x3f, 0x39, 0x49, 0x3f, 0x3a, 0x42, 0x34, 0x38, 0x37, + 0x44, 0x34, 0x3c, 0x3d, 0x40, 0x47, 0x3a, 0x36, 0x3f, 0x3c, 0x41, 0x3e, + 0x47, 0x46, 0x46, 0x43, 0x3f, 0x38, 0x3b, 0x40, 0x3f, 0x48, 0x3b, 0x4c, + 0x3d, 0x4b, 0x34, 0x3b, 0x44, 0x43, 0x3c, 0x49, 0x38, 0x42, 0x41, 0x36, + 0x33, 0x36, 0x40, 0x46, 0x40, 0x3a, 0x42, 0x3c, 0x3d, 0x35, 0x3c, 0x52, + 0x3e, 0x40, 0x43, 0x43, 0x41, 0x3b, 0x3e, 0x44, 0x3f, 0x40, 0x40, 0x43, + 0x3d, 0x3f, 0x36, 0x42, 0x3f, 0x3c, 0x34, 0x3d, 0x33, 0x41, 0x3c, 0x39, + 0x34, 0x43, 0x3f, 0x34, 0x3c, 0x3a, 0x3a, 0x37, 0x42, 0x41, 0x40, 0x3e, + 0x3d, 0x3c, 0x41, 0x3c, 0x38, 0x33, 0x49, 0x46, 0x40, 0x40, 0x3a, 0x46, + 0x38, 0x3c, 0x37, 0x34, 0x3e, 0x3d, 0x32, 0x38, 0x3c, 0x4c, 0x3a, 0x34, + 0x35, 0x32, 0x39, 0x40, 0x3a, 0x58, 0x40, 0x46, 0x42, 0x33, 0x45, 0x39, + 0x34, 0x4f, 0x53, 0x45, 0x43, 0x3e, 0x41, 0x36, 0x3e, 0x3f, 0x40, 0x47, + 0x4e, 0x3d, 0x53, 0x2b, 0x41, 0x36, 0x3e, 0x38, 0x47, 0x41, 0x3f, 0x34, + 0x47, 0x40, 0x38, 0x39, 0x3d, 0x42, 0x3f, 0x3c, 0x48, 0x3a, 0x35, 0x3c, + 0x45, 0x49, 0x3c, 0x33, 0x33, 0x3f, 0x3c, 0x46, 0x43, 0x3f, 0x45, 0x31, + 0x35, 0x43, 0x46, 0x3a, 0x45, 0x3c, 0x37, 0x3a, 0x37, 0x36, 0x35, 0x3f, + 0x38, 0x49, 0x34, 0x3f, 0x3c, 0x42, 0x49, 0x3e, 0x3e, 0x3c, 0x39, 0x49, + 0x3e, 0x3c, 0x3b, 0x43, 0x44, 0x45, 0x39, 0x4b, 0x47, 0x47, 0x3e, 0x33, + 0x3c, 0x31, 0x34, 0x4f, 0x45, 0x43, 0x40, 0x3d, 0x42, 0x3b, 0x43, 0x50, + 0x3c, 0x3b, 0x37, 0x42, 0x47, 0x42, 0x3e, 0x4a, 0x3f, 0x3a, 0x48, 0x3d, + 0x48, 0x45, 0x3e, 0x40, 0x3a, 0x3c, 0x3d, 0x39, 0x41, 0x42, 0x3c, 0x42, + 0x43, 0x3c, 0x3b, 0x3d, 0x47, 0x49, 0x38, 0x3c, 0x46, 0x3a, 0x3c, 0x3f, + 0x3a, 0x46, 0x3a, 0x3b, 0x3d, 0x3a, 0x49, 0x46, 0x38, 0x40, 0x3e, 0x38, + 0x37, 0x32, 0x40, 0x3c, 0x42, 0x3d, 0x3b, 0x40, 0x3a, 0x38, 0x49, 0x33, + 0x40, 0x38, 0x2b, 0x3a, 0x3c, 0x4f, 0x4d, 0x3e, 0x35, 0x3d, 0x3b, 0x40, + 0x3a, 0x54, 0x3e, 0x3e, 0x43, 0x30, 0x47, 0x3d, 0x3b, 0x53, 0x52, 0x4a, + 0x43, 0x41, 0x49, 0x37, 0x3b, 0x35, 0x44, 0x3c, 0x45, 0x40, 0x4f, 0x36, + 0x4b, 0x42, 0x41, 0x3a, 0x41, 0x44, 0x47, 0x32, 0x43, 0x35, 0x3f, 0x37, + 0x43, 0x41, 0x43, 0x36, 0x3f, 0x3b, 0x3d, 0x38, 0x3d, 0x40, 0x42, 0x36, + 0x44, 0x3a, 0x39, 0x47, 0x37, 0x34, 0x42, 0x3a, 0x37, 0x38, 0x37, 0x3f, + 0x36, 0x3b, 0x45, 0x3f, 0x3f, 0x3d, 0x39, 0x3d, 0x39, 0x41, 0x37, 0x3f, + 0x3f, 0x3d, 0x3f, 0x41, 0x43, 0x41, 0x45, 0x43, 0x41, 0x3c, 0x3e, 0x40, + 0x40, 0x39, 0x41, 0x4f, 0x47, 0x42, 0x46, 0x48, 0x3b, 0x3b, 0x3c, 0x46, + 0x47, 0x3e, 0x46, 0x37, 0x38, 0x3d, 0x38, 0x52, 0x36, 0x46, 0x3c, 0x3a, + 0x3b, 0x37, 0x48, 0x4b, 0x3f, 0x42, 0x3c, 0x36, 0x40, 0x37, 0x33, 0x4c, + 0x39, 0x34, 0x41, 0x34, 0x3f, 0x3b, 0x35, 0x4b, 0x3b, 0x45, 0x43, 0x31, + 0x3e, 0x39, 0x30, 0x3d, 0x32, 0x43, 0x44, 0x3c, 0x3e, 0x38, 0x43, 0x41, + 0x3e, 0x37, 0x41, 0x39, 0x39, 0x44, 0x43, 0x38, 0x3f, 0x37, 0x48, 0x3f, + 0x3b, 0x44, 0x37, 0x3f, 0x3a, 0x3f, 0x3b, 0x33, 0x42, 0x3e, 0x2f, 0x42, + 0x44, 0x4f, 0x52, 0x3c, 0x34, 0x33, 0x39, 0x46, 0x31, 0x55, 0x43, 0x4e, + 0x49, 0x38, 0x4d, 0x48, 0x34, 0x4d, 0x5c, 0x4d, 0x49, 0x37, 0x4f, 0x40, + 0x3c, 0x3d, 0x41, 0x42, 0x3f, 0x51, 0x4b, 0x2f, 0x46, 0x35, 0x39, 0x3c, + 0x49, 0x3d, 0x4e, 0x32, 0x43, 0x47, 0x31, 0x3e, 0x42, 0x4a, 0x4c, 0x39, + 0x43, 0x46, 0x3e, 0x3f, 0x44, 0x3c, 0x42, 0x30, 0x3e, 0x34, 0x3b, 0x3b, + 0x3a, 0x3c, 0x42, 0x3d, 0x3d, 0x48, 0x48, 0x36, 0x3a, 0x45, 0x38, 0x40, + 0x3c, 0x41, 0x3f, 0x49, 0x42, 0x41, 0x38, 0x3d, 0x3d, 0x44, 0x3b, 0x3d, + 0x35, 0x48, 0x43, 0x3b, 0x32, 0x41, 0x3e, 0x3a, 0x46, 0x41, 0x40, 0x54, + 0x38, 0x3f, 0x3c, 0x36, 0x3b, 0x36, 0x43, 0x50, 0x38, 0x3c, 0x44, 0x3b, + 0x43, 0x47, 0x32, 0x50, 0x3d, 0x46, 0x3d, 0x3b, 0x39, 0x37, 0x3b, 0x4a, + 0x47, 0x43, 0x46, 0x3d, 0x3d, 0x41, 0x43, 0x45, 0x3b, 0x3c, 0x39, 0x47, + 0x43, 0x42, 0x39, 0x4c, 0x34, 0x41, 0x45, 0x3b, 0x38, 0x3e, 0x37, 0x3f, + 0x45, 0x43, 0x39, 0x42, 0x3c, 0x3d, 0x3d, 0x3c, 0x48, 0x39, 0x3b, 0x3a, + 0x46, 0x45, 0x3d, 0x3a, 0x3f, 0x3a, 0x45, 0x36, 0x3d, 0x43, 0x36, 0x43, + 0x42, 0x3d, 0x41, 0x3f, 0x3a, 0x3f, 0x31, 0x37, 0x48, 0x4f, 0x4e, 0x36, + 0x30, 0x3a, 0x3e, 0x3e, 0x38, 0x57, 0x40, 0x47, 0x47, 0x38, 0x4f, 0x46, + 0x3d, 0x4a, 0x50, 0x4c, 0x42, 0x3b, 0x4d, 0x3d, 0x3d, 0x33, 0x40, 0x41, + 0x48, 0x4b, 0x46, 0x39, 0x4d, 0x30, 0x45, 0x38, 0x48, 0x3c, 0x48, 0x3b, + 0x4d, 0x40, 0x3b, 0x40, 0x46, 0x41, 0x51, 0x34, 0x40, 0x43, 0x3f, 0x42, + 0x45, 0x42, 0x3e, 0x35, 0x3d, 0x38, 0x37, 0x3a, 0x42, 0x40, 0x43, 0x3c, + 0x3c, 0x3d, 0x43, 0x40, 0x45, 0x3a, 0x3e, 0x3a, 0x3e, 0x40, 0x43, 0x35, + 0x37, 0x3f, 0x3f, 0x3e, 0x39, 0x3f, 0x47, 0x38, 0x3e, 0x44, 0x3b, 0x3c, + 0x3b, 0x32, 0x40, 0x3e, 0x42, 0x45, 0x3a, 0x52, 0x3a, 0x3e, 0x45, 0x40, + 0x41, 0x48, 0x3f, 0x4e, 0x3e, 0x42, 0x3d, 0x39, 0x3a, 0x33, 0x3f, 0x4b, + 0x3e, 0x38, 0x36, 0x3e, 0x31, 0x41, 0x3a, 0x40, 0x3b, 0x37, 0x3f, 0x3e, + 0x3e, 0x3f, 0x35, 0x44, 0x3d, 0x42, 0x3d, 0x44, 0x42, 0x3f, 0x3e, 0x44, + 0x3e, 0x45, 0x37, 0x3a, 0x3b, 0x42, 0x3f, 0x41, 0x3b, 0x3f, 0x41, 0x41, + 0x3e, 0x34, 0x47, 0x39, 0x46, 0x46, 0x37, 0x39, 0x3f, 0x45, 0x39, 0x39, + 0x3a, 0x40, 0x38, 0x3a, 0x31, 0x34, 0x3a, 0x41, 0x38, 0x41, 0x3a, 0x41, + 0x44, 0x37, 0x2d, 0x41, 0x43, 0x4d, 0x4b, 0x3b, 0x2c, 0x30, 0x42, 0x3b, + 0x31, 0x56, 0x43, 0x47, 0x47, 0x38, 0x50, 0x44, 0x40, 0x52, 0x5a, 0x50, + 0x44, 0x3f, 0x4b, 0x35, 0x3a, 0x36, 0x41, 0x44, 0x47, 0x4e, 0x52, 0x36, + 0x45, 0x39, 0x38, 0x3c, 0x42, 0x44, 0x40, 0x3b, 0x4b, 0x38, 0x35, 0x35, + 0x3f, 0x40, 0x4f, 0x39, 0x3d, 0x37, 0x34, 0x3e, 0x41, 0x4c, 0x40, 0x37, + 0x3d, 0x3b, 0x37, 0x37, 0x40, 0x42, 0x35, 0x39, 0x41, 0x42, 0x3d, 0x34, + 0x3c, 0x37, 0x3a, 0x3d, 0x46, 0x46, 0x46, 0x3f, 0x44, 0x3d, 0x3c, 0x40, + 0x3c, 0x3a, 0x3d, 0x3b, 0x3b, 0x41, 0x47, 0x3a, 0x43, 0x43, 0x43, 0x3b, + 0x3e, 0x3e, 0x42, 0x46, 0x36, 0x37, 0x45, 0x35, 0x3c, 0x3b, 0x31, 0x4b, + 0x3c, 0x3e, 0x3a, 0x3a, 0x42, 0x42, 0x34, 0x47, 0x37, 0x34, 0x41, 0x3d, + 0x3e, 0x39, 0x43, 0x47, 0x31, 0x3b, 0x40, 0x3b, 0x42, 0x3d, 0x44, 0x44, + 0x37, 0x39, 0x44, 0x3b, 0x40, 0x3a, 0x3d, 0x44, 0x3c, 0x40, 0x42, 0x3b, + 0x40, 0x3e, 0x32, 0x3d, 0x3c, 0x3e, 0x44, 0x3e, 0x47, 0x3d, 0x3f, 0x2e, + 0x3e, 0x3d, 0x3f, 0x3b, 0x3b, 0x43, 0x43, 0x3c, 0x3a, 0x3c, 0x3a, 0x36, + 0x38, 0x46, 0x30, 0x3e, 0x3f, 0x35, 0x3e, 0x34, 0x3c, 0x34, 0x32, 0x4a, + 0x41, 0x48, 0x48, 0x3f, 0x34, 0x37, 0x42, 0x43, 0x36, 0x59, 0x42, 0x3f, + 0x4b, 0x3d, 0x5d, 0x45, 0x3b, 0x51, 0x51, 0x4c, 0x41, 0x40, 0x4d, 0x36, + 0x3f, 0x34, 0x39, 0x3d, 0x4a, 0x4b, 0x4f, 0x33, 0x48, 0x32, 0x3c, 0x32, + 0x48, 0x4c, 0x4d, 0x3a, 0x49, 0x3a, 0x3a, 0x2e, 0x4b, 0x44, 0x4f, 0x33, + 0x3a, 0x48, 0x34, 0x43, 0x38, 0x45, 0x44, 0x35, 0x3b, 0x3f, 0x40, 0x37, + 0x35, 0x34, 0x38, 0x3e, 0x41, 0x3e, 0x3b, 0x47, 0x41, 0x47, 0x3c, 0x3c, + 0x39, 0x40, 0x3e, 0x45, 0x36, 0x41, 0x3f, 0x3f, 0x3c, 0x44, 0x3f, 0x43, + 0x3d, 0x3c, 0x49, 0x42, 0x3e, 0x3f, 0x48, 0x37, 0x43, 0x37, 0x43, 0x3d, + 0x32, 0x42, 0x44, 0x39, 0x36, 0x37, 0x40, 0x46, 0x47, 0x3d, 0x3a, 0x42, + 0x3f, 0x38, 0x37, 0x48, 0x39, 0x40, 0x3c, 0x37, 0x33, 0x38, 0x38, 0x40, + 0x41, 0x3c, 0x3f, 0x3b, 0x40, 0x3a, 0x47, 0x46, 0x3a, 0x37, 0x42, 0x47, + 0x3b, 0x3f, 0x3b, 0x40, 0x33, 0x3f, 0x3a, 0x3c, 0x38, 0x3a, 0x36, 0x38, + 0x36, 0x40, 0x48, 0x42, 0x48, 0x3c, 0x43, 0x36, 0x32, 0x3b, 0x34, 0x39, + 0x38, 0x46, 0x37, 0x3b, 0x44, 0x34, 0x36, 0x38, 0x3c, 0x43, 0x33, 0x3c, + 0x3b, 0x45, 0x38, 0x38, 0x44, 0x33, 0x36, 0x4a, 0x46, 0x4c, 0x4a, 0x34, + 0x36, 0x37, 0x43, 0x42, 0x33, 0x58, 0x43, 0x48, 0x44, 0x38, 0x5f, 0x3f, + 0x3c, 0x4d, 0x53, 0x52, 0x43, 0x47, 0x52, 0x3e, 0x3b, 0x2d, 0x3b, 0x3a, + 0x4b, 0x49, 0x53, 0x38, 0x4c, 0x2f, 0x38, 0x31, 0x42, 0x40, 0x48, 0x3f, + 0x44, 0x3c, 0x3c, 0x34, 0x46, 0x3f, 0x49, 0x3a, 0x43, 0x3d, 0x34, 0x42, + 0x36, 0x47, 0x51, 0x3c, 0x3d, 0x39, 0x39, 0x3a, 0x3b, 0x35, 0x35, 0x41, + 0x47, 0x3c, 0x3b, 0x43, 0x3f, 0x45, 0x3e, 0x40, 0x3c, 0x3f, 0x3c, 0x42, + 0x3b, 0x3e, 0x38, 0x3f, 0x3f, 0x41, 0x39, 0x39, 0x3d, 0x43, 0x4f, 0x3d, + 0x48, 0x3b, 0x44, 0x45, 0x3d, 0x3b, 0x49, 0x43, 0x44, 0x3d, 0x37, 0x3b, + 0x3c, 0x45, 0x46, 0x44, 0x35, 0x3e, 0x32, 0x35, 0x34, 0x3b, 0x40, 0x43, + 0x3e, 0x45, 0x37, 0x3d, 0x3f, 0x43, 0x36, 0x3f, 0x3f, 0x43, 0x39, 0x44, + 0x3e, 0x3e, 0x45, 0x40, 0x3e, 0x44, 0x3b, 0x3e, 0x42, 0x42, 0x3b, 0x3d, + 0x3a, 0x40, 0x39, 0x3a, 0x32, 0x36, 0x41, 0x30, 0x39, 0x46, 0x33, 0x3f, + 0x46, 0x40, 0x3c, 0x31, 0x41, 0x3a, 0x3f, 0x3f, 0x3b, 0x36, 0x3f, 0x38, + 0x36, 0x3e, 0x35, 0x35, 0x3b, 0x3d, 0x3f, 0x39, 0x46, 0x37, 0x3a, 0x47, + 0x37, 0x39, 0x2c, 0x55, 0x40, 0x4b, 0x4a, 0x39, 0x35, 0x42, 0x3d, 0x40, + 0x3a, 0x54, 0x41, 0x48, 0x51, 0x3b, 0x61, 0x3e, 0x3e, 0x4d, 0x51, 0x52, + 0x3e, 0x43, 0x52, 0x41, 0x48, 0x2d, 0x35, 0x35, 0x4b, 0x44, 0x4d, 0x3c, + 0x54, 0x33, 0x39, 0x27, 0x4a, 0x44, 0x4a, 0x41, 0x3c, 0x3a, 0x31, 0x2f, + 0x3d, 0x42, 0x48, 0x3f, 0x42, 0x40, 0x44, 0x3b, 0x40, 0x3e, 0x49, 0x3a, + 0x3c, 0x35, 0x30, 0x3e, 0x3e, 0x3d, 0x36, 0x3a, 0x3e, 0x3a, 0x4a, 0x3e, + 0x3d, 0x49, 0x40, 0x43, 0x3e, 0x45, 0x3f, 0x3c, 0x3b, 0x42, 0x3a, 0x39, + 0x3b, 0x47, 0x3f, 0x39, 0x49, 0x46, 0x3d, 0x34, 0x32, 0x44, 0x46, 0x42, + 0x47, 0x39, 0x49, 0x48, 0x3b, 0x38, 0x45, 0x45, 0x37, 0x38, 0x46, 0x46, + 0x37, 0x42, 0x35, 0x34, 0x45, 0x42, 0x35, 0x43, 0x3b, 0x3a, 0x43, 0x43, + 0x40, 0x42, 0x35, 0x3f, 0x38, 0x3f, 0x3a, 0x3a, 0x3b, 0x3f, 0x3e, 0x36, + 0x3f, 0x3c, 0x48, 0x3b, 0x3a, 0x41, 0x41, 0x35, 0x33, 0x3f, 0x3b, 0x45, + 0x48, 0x36, 0x40, 0x38, 0x47, 0x3d, 0x35, 0x40, 0x41, 0x42, 0x41, 0x37, + 0x41, 0x3e, 0x36, 0x48, 0x3e, 0x3c, 0x32, 0x39, 0x41, 0x40, 0x38, 0x3f, + 0x46, 0x43, 0x33, 0x40, 0x43, 0x43, 0x3a, 0x49, 0x3f, 0x35, 0x2c, 0x5d, + 0x43, 0x49, 0x52, 0x3b, 0x3c, 0x41, 0x40, 0x4a, 0x33, 0x50, 0x41, 0x46, + 0x52, 0x41, 0x68, 0x48, 0x44, 0x53, 0x54, 0x55, 0x42, 0x42, 0x57, 0x44, + 0x47, 0x35, 0x35, 0x3e, 0x4b, 0x44, 0x4e, 0x38, 0x55, 0x2f, 0x36, 0x2d, + 0x40, 0x48, 0x4b, 0x41, 0x48, 0x36, 0x32, 0x32, 0x44, 0x42, 0x47, 0x42, + 0x48, 0x3d, 0x3d, 0x39, 0x3e, 0x35, 0x4b, 0x39, 0x38, 0x3a, 0x39, 0x46, + 0x38, 0x3f, 0x3a, 0x42, 0x4b, 0x45, 0x3e, 0x32, 0x46, 0x43, 0x3b, 0x40, + 0x45, 0x41, 0x3e, 0x43, 0x37, 0x3d, 0x43, 0x3b, 0x46, 0x48, 0x42, 0x3b, + 0x3d, 0x48, 0x4a, 0x3c, 0x3b, 0x42, 0x40, 0x3c, 0x3a, 0x42, 0x38, 0x47, + 0x3b, 0x3b, 0x3d, 0x41, 0x3f, 0x38, 0x3f, 0x4a, 0x44, 0x3f, 0x47, 0x3a, + 0x47, 0x44, 0x43, 0x43, 0x34, 0x3d, 0x3a, 0x3c, 0x47, 0x3f, 0x3e, 0x39, + 0x42, 0x4a, 0x40, 0x36, 0x40, 0x41, 0x42, 0x3f, 0x3f, 0x43, 0x39, 0x38, + 0x3c, 0x3b, 0x4c, 0x2f, 0x41, 0x39, 0x40, 0x42, 0x3f, 0x42, 0x40, 0x36, + 0x3b, 0x45, 0x41, 0x41, 0x44, 0x45, 0x42, 0x37, 0x3d, 0x3a, 0x33, 0x3e, + 0x3b, 0x3b, 0x3c, 0x3d, 0x38, 0x49, 0x44, 0x39, 0x3f, 0x48, 0x3d, 0x41, + 0x42, 0x43, 0x44, 0x3e, 0x41, 0x3d, 0x32, 0x59, 0x45, 0x4b, 0x4b, 0x38, + 0x37, 0x3d, 0x48, 0x42, 0x3d, 0x52, 0x43, 0x46, 0x54, 0x48, 0x67, 0x4d, + 0x45, 0x4e, 0x49, 0x52, 0x45, 0x45, 0x58, 0x3b, 0x41, 0x38, 0x3f, 0x3f, + 0x49, 0x44, 0x4f, 0x48, 0x57, 0x31, 0x3c, 0x2a, 0x3e, 0x4c, 0x41, 0x40, + 0x47, 0x3f, 0x33, 0x34, 0x3f, 0x42, 0x48, 0x43, 0x4b, 0x38, 0x39, 0x3d, + 0x3f, 0x3e, 0x4b, 0x3f, 0x35, 0x36, 0x3c, 0x46, 0x3c, 0x45, 0x37, 0x3b, + 0x3c, 0x39, 0x41, 0x40, 0x41, 0x43, 0x44, 0x41, 0x45, 0x4f, 0x44, 0x43, + 0x44, 0x3c, 0x45, 0x34, 0x42, 0x45, 0x3f, 0x46, 0x3f, 0x43, 0x3d, 0x3a, + 0x39, 0x47, 0x45, 0x3d, 0x3f, 0x3b, 0x3d, 0x42, 0x38, 0x48, 0x48, 0x3b, + 0x3c, 0x3a, 0x3f, 0x41, 0x44, 0x4b, 0x44, 0x48, 0x41, 0x3c, 0x3d, 0x3c, + 0x3e, 0x3a, 0x4a, 0x3b, 0x49, 0x35, 0x3a, 0x3d, 0x41, 0x3f, 0x49, 0x39, + 0x44, 0x37, 0x3f, 0x3c, 0x42, 0x40, 0x4a, 0x46, 0x39, 0x38, 0x46, 0x37, + 0x41, 0x46, 0x41, 0x45, 0x40, 0x3b, 0x3b, 0x33, 0x3b, 0x39, 0x3c, 0x43, + 0x37, 0x3c, 0x44, 0x3d, 0x46, 0x39, 0x3c, 0x3c, 0x44, 0x48, 0x41, 0x44, + 0x41, 0x43, 0x46, 0x3b, 0x47, 0x41, 0x31, 0x41, 0x44, 0x40, 0x43, 0x42, + 0x3e, 0x43, 0x34, 0x65, 0x4f, 0x50, 0x4d, 0x3a, 0x37, 0x43, 0x4d, 0x4a, + 0x3d, 0x54, 0x40, 0x42, 0x5b, 0x3b, 0x71, 0x49, 0x44, 0x4f, 0x54, 0x56, + 0x48, 0x40, 0x52, 0x41, 0x42, 0x38, 0x3c, 0x49, 0x4a, 0x45, 0x51, 0x35, + 0x54, 0x2f, 0x35, 0x25, 0x4d, 0x3f, 0x4d, 0x43, 0x49, 0x33, 0x32, 0x3a, + 0x46, 0x48, 0x48, 0x3d, 0x43, 0x3a, 0x3c, 0x3a, 0x48, 0x40, 0x4b, 0x3b, + 0x45, 0x3b, 0x3f, 0x38, 0x37, 0x41, 0x31, 0x3b, 0x41, 0x43, 0x43, 0x37, + 0x48, 0x3f, 0x48, 0x37, 0x40, 0x4a, 0x43, 0x45, 0x3d, 0x39, 0x37, 0x37, + 0x3c, 0x3f, 0x47, 0x48, 0x43, 0x3e, 0x41, 0x3f, 0x3e, 0x38, 0x3e, 0x37, + 0x45, 0x45, 0x35, 0x44, 0x38, 0x3a, 0x49, 0x43, 0x40, 0x41, 0x40, 0x44, + 0x3c, 0x3e, 0x40, 0x38, 0x42, 0x41, 0x3c, 0x41, 0x3a, 0x3b, 0x3c, 0x3a, + 0x49, 0x3c, 0x42, 0x44, 0x3f, 0x39, 0x45, 0x32, 0x45, 0x43, 0x45, 0x39, + 0x43, 0x41, 0x4b, 0x39, 0x32, 0x3c, 0x3c, 0x36, 0x39, 0x3f, 0x46, 0x32, + 0x39, 0x35, 0x4f, 0x32, 0x3e, 0x40, 0x3d, 0x3e, 0x3a, 0x39, 0x4c, 0x38, + 0x43, 0x38, 0x49, 0x3b, 0x33, 0x39, 0x3b, 0x36, 0x36, 0x43, 0x3b, 0x3c, + 0x32, 0x3c, 0x3a, 0x45, 0x31, 0x3d, 0x37, 0x40, 0x3f, 0x3f, 0x35, 0xff, + 0x49, 0x4e, 0x4c, 0x3c, 0x36, 0x43, 0x46, 0x45, 0x41, 0x59, 0x44, 0x4a, + 0x53, 0x44, 0x71, 0x4a, 0x39, 0x4f, 0x50, 0x4b, 0x47, 0x42, 0x5a, 0x3c, + 0x45, 0x38, 0x3e, 0x42, 0x53, 0x43, 0x52, 0x3a, 0x52, 0x34, 0x31, 0x20, + 0x49, 0x4e, 0x46, 0x43, 0x4b, 0x3d, 0x2b, 0x27, 0x46, 0x46, 0x47, 0x41, + 0x42, 0x37, 0x39, 0x38, 0x45, 0x3f, 0x51, 0x3d, 0x48, 0x3f, 0x33, 0x3f, + 0x38, 0x45, 0x31, 0x38, 0x41, 0x3d, 0x47, 0x39, 0x42, 0x40, 0x4c, 0x3f, + 0x40, 0x42, 0x41, 0x41, 0x41, 0x42, 0x39, 0x35, 0x3f, 0x46, 0x45, 0x36, + 0x3f, 0x43, 0x3b, 0x39, 0x41, 0x38, 0x43, 0x37, 0x3d, 0x44, 0x3b, 0x40, + 0x36, 0x3d, 0x42, 0x41, 0x41, 0x3d, 0x38, 0x4a, 0x40, 0x4a, 0x4c, 0x38, + 0x3f, 0x40, 0x45, 0x3c, 0x3f, 0x4b, 0x43, 0x41, 0x43, 0x3e, 0x43, 0x3f, + 0x36, 0x40, 0x40, 0x39, 0x3f, 0x3a, 0x3a, 0x30, 0x41, 0x3c, 0x3c, 0x34, + 0x46, 0x38, 0x43, 0x34, 0x3a, 0x42, 0x43, 0x42, 0x40, 0x41, 0x49, 0x34, + 0x35, 0x40, 0x47, 0x3d, 0x3d, 0x3e, 0x4c, 0x33, 0x3c, 0x3b, 0x39, 0x43, + 0x3a, 0x3e, 0x3b, 0x37, 0x3f, 0x42, 0x31, 0x3d, 0x41, 0x3e, 0x32, 0x47, + 0x34, 0x41, 0x3d, 0x35, 0x39, 0x40, 0x38, 0x69, 0x4f, 0x4a, 0x49, 0x37, + 0x37, 0x44, 0x43, 0x46, 0x40, 0x58, 0x43, 0x48, 0x54, 0x46, 0x6c, 0x50, + 0x3a, 0x50, 0x50, 0x57, 0x47, 0x46, 0x5c, 0x40, 0x40, 0x39, 0x3e, 0x46, + 0x53, 0x46, 0x5c, 0x36, 0x4f, 0x32, 0x30, 0x2d, 0x4a, 0x48, 0x41, 0x45, + 0x47, 0x2f, 0x32, 0x2b, 0x43, 0x40, 0x43, 0x3c, 0x40, 0x44, 0x3e, 0x37, + 0x39, 0x3e, 0x48, 0x42, 0x45, 0x36, 0x47, 0x3f, 0x3b, 0x41, 0x35, 0x35, + 0x3b, 0x3e, 0x35, 0x43, 0x3e, 0x41, 0x3d, 0x36, 0x41, 0x3c, 0x40, 0x44, + 0x3d, 0x40, 0x35, 0x32, 0x48, 0x3e, 0x39, 0x42, 0x44, 0x3d, 0x39, 0x3b, + 0x3b, 0x45, 0x40, 0x4a, 0x3f, 0x41, 0x43, 0x39, 0x42, 0x44, 0x4c, 0x3c, + 0x3f, 0x3e, 0x3f, 0x43, 0x40, 0x42, 0x4c, 0x3b, 0x3e, 0x3d, 0x49, 0x42, + 0x40, 0x44, 0x40, 0x34, 0x36, 0x40, 0x45, 0x39, 0x42, 0x40, 0x3e, 0x44, + 0x45, 0x37, 0x3c, 0x38, 0x3e, 0x49, 0x3e, 0x3c, 0x41, 0x3d, 0x42, 0x32, + 0x40, 0x45, 0x3e, 0x36, 0x44, 0x3a, 0x4e, 0x38, 0x43, 0x38, 0x40, 0x38, + 0x49, 0x42, 0x40, 0x3d, 0x42, 0x48, 0x48, 0x3d, 0x41, 0x3a, 0x3f, 0x41, + 0x38, 0x3c, 0x44, 0x39, 0x3a, 0x32, 0x3a, 0x3e, 0x3d, 0x3b, 0x39, 0x38, + 0x3a, 0x43, 0x3a, 0x6b, 0x45, 0x50, 0x47, 0x33, 0x38, 0x48, 0x4d, 0x4f, + 0x39, 0x4b, 0x46, 0x4a, 0x4f, 0x42, 0x6f, 0x4b, 0x40, 0x55, 0x54, 0x50, + 0x42, 0x47, 0x5e, 0x46, 0x40, 0x34, 0x40, 0x47, 0x52, 0x46, 0x55, 0x3b, + 0x4f, 0x2b, 0x35, 0x33, 0x4c, 0x44, 0x44, 0x48, 0x47, 0x37, 0x35, 0x27, + 0x4a, 0x3b, 0x41, 0x40, 0x40, 0x3e, 0x36, 0x39, 0x3e, 0x3c, 0x45, 0x3f, + 0x4d, 0x41, 0x3d, 0x48, 0x47, 0x46, 0x33, 0x3d, 0x3d, 0x3e, 0x34, 0x3f, + 0x3e, 0x3a, 0x41, 0x35, 0x3b, 0x3e, 0x42, 0x3c, 0x42, 0x42, 0x40, 0x31, + 0x37, 0x40, 0x36, 0x42, 0x48, 0x39, 0x3d, 0x3c, 0x3a, 0x43, 0x39, 0x3d, + 0x47, 0x49, 0x43, 0x3d, 0x45, 0x39, 0x44, 0x37, 0x3e, 0x4d, 0x3d, 0x40, + 0x3d, 0x4c, 0x4d, 0x44, 0x3c, 0x3d, 0x46, 0x41, 0x41, 0x42, 0x40, 0x40, + 0x41, 0x3a, 0x3c, 0x3b, 0x3c, 0x44, 0x40, 0x34, 0x44, 0x38, 0x3b, 0x33, + 0x45, 0x45, 0x44, 0x3f, 0x3e, 0x3a, 0x3b, 0x3b, 0x43, 0x39, 0x3a, 0x45, + 0x3b, 0x3a, 0x4b, 0x39, 0x3d, 0x38, 0x41, 0x39, 0x42, 0x45, 0x43, 0x40, + 0x3e, 0x35, 0x44, 0x3f, 0x45, 0x41, 0x40, 0x3e, 0x43, 0x42, 0x37, 0x3a, + 0x38, 0x35, 0x3a, 0x48, 0x3e, 0x3b, 0x40, 0x38, 0x3c, 0x3c, 0x3b, 0x6a, + 0x48, 0x4d, 0x4d, 0x34, 0x38, 0x40, 0x4a, 0x45, 0x3c, 0x4f, 0x41, 0x4b, + 0x58, 0x46, 0x71, 0x49, 0x3d, 0x53, 0x44, 0x52, 0x42, 0x3e, 0x57, 0x4c, + 0x4c, 0x38, 0x40, 0x3b, 0x5c, 0x4c, 0x52, 0x3e, 0x4c, 0x2d, 0x32, 0x37, + 0x49, 0x3f, 0x41, 0x47, 0x4a, 0x3b, 0x2f, 0x26, 0x45, 0x40, 0x47, 0x42, + 0x3d, 0x39, 0x2d, 0x2c, 0x3f, 0x45, 0x46, 0x44, 0x48, 0x43, 0x42, 0x48, + 0x40, 0x41, 0x3b, 0x3b, 0x41, 0x3b, 0x39, 0x40, 0x3b, 0x47, 0x3f, 0x38, + 0x3f, 0x49, 0x3b, 0x35, 0x40, 0x45, 0x38, 0x35, 0x36, 0x34, 0x3e, 0x3d, + 0x46, 0x3e, 0x33, 0x38, 0x43, 0x48, 0x3f, 0x45, 0x31, 0x44, 0x38, 0x35, + 0x3c, 0x41, 0x4b, 0x44, 0x3d, 0x43, 0x38, 0x48, 0x3c, 0x39, 0x4a, 0x42, + 0x3d, 0x43, 0x3f, 0x49, 0x3e, 0x47, 0x49, 0x41, 0x3b, 0x3c, 0x47, 0x3a, + 0x3d, 0x40, 0x4a, 0x38, 0x3d, 0x3b, 0x47, 0x3a, 0x36, 0x47, 0x42, 0x46, + 0x3c, 0x3d, 0x45, 0x3b, 0x48, 0x3f, 0x38, 0x36, 0x39, 0x46, 0x43, 0x3a, + 0x41, 0x3d, 0x39, 0x39, 0x46, 0x37, 0x3f, 0x3f, 0x3a, 0x46, 0x3f, 0x39, + 0x49, 0x44, 0x42, 0x3a, 0x3a, 0x43, 0x3e, 0x42, 0x3d, 0x3d, 0x43, 0x40, + 0x43, 0x3c, 0x3f, 0x43, 0x40, 0x42, 0x3b, 0x57, 0x4a, 0x4f, 0x4a, 0x2d, + 0x3b, 0x48, 0x45, 0x42, 0x34, 0x4c, 0x3e, 0x4f, 0x4d, 0x40, 0x6c, 0x4b, + 0x3b, 0x4d, 0x4c, 0x57, 0x49, 0x3d, 0x5d, 0x44, 0x43, 0x29, 0x42, 0x3f, + 0x5b, 0x47, 0x4f, 0x3e, 0x54, 0x2e, 0x34, 0x34, 0x4b, 0x47, 0x46, 0x46, + 0x4b, 0x34, 0x36, 0x28, 0x3e, 0x3f, 0x42, 0x40, 0x3b, 0x38, 0x39, 0x42, + 0x49, 0x3d, 0x49, 0x47, 0x47, 0x3b, 0x43, 0x34, 0x39, 0x36, 0x42, 0x3d, + 0x37, 0x40, 0x37, 0x38, 0x46, 0x42, 0x49, 0x37, 0x44, 0x3f, 0x38, 0x3e, + 0x36, 0x32, 0x33, 0x38, 0x40, 0x46, 0x42, 0x34, 0x41, 0x42, 0x3e, 0x38, + 0x44, 0x3e, 0x3f, 0x43, 0x3f, 0x43, 0x35, 0x3f, 0x4d, 0x3b, 0x43, 0x39, + 0x40, 0x47, 0x3f, 0x4a, 0x3a, 0x3f, 0x45, 0x45, 0x48, 0x42, 0x3b, 0x47, + 0x42, 0x4b, 0x47, 0x3e, 0x3c, 0x42, 0x46, 0x39, 0x41, 0x3f, 0x48, 0x33, + 0x45, 0x34, 0x3d, 0x30, 0x40, 0x4c, 0x40, 0x40, 0x39, 0x37, 0x40, 0x33, + 0x49, 0x42, 0x45, 0x38, 0x3c, 0x43, 0x45, 0x35, 0x37, 0x33, 0x34, 0x3b, + 0x3b, 0x38, 0x39, 0x41, 0x42, 0x40, 0x3e, 0x3e, 0x41, 0x33, 0x3a, 0x36, + 0x40, 0x3a, 0x3c, 0x45, 0x43, 0x3c, 0x40, 0x41, 0x49, 0x47, 0x35, 0x34, + 0x3a, 0x3d, 0x3a, 0x68, 0x4f, 0x48, 0x43, 0x36, 0x37, 0x3e, 0x45, 0x49, + 0x3a, 0x4d, 0x41, 0x3d, 0x46, 0x45, 0x65, 0x46, 0x38, 0x4d, 0x4a, 0x53, + 0x43, 0x41, 0x5d, 0x47, 0x41, 0x34, 0x39, 0x43, 0x4e, 0x48, 0x50, 0x38, + 0x53, 0x32, 0x30, 0x2e, 0x49, 0x4c, 0x4d, 0x3f, 0x46, 0x38, 0x34, 0x2b, + 0x44, 0x44, 0x41, 0x41, 0x36, 0x40, 0x3f, 0x32, 0x46, 0x38, 0x50, 0x45, + 0x3f, 0x3d, 0x3b, 0x36, 0x3b, 0x43, 0x3a, 0x34, 0x36, 0x3f, 0x39, 0x35, + 0x3c, 0x40, 0x40, 0x37, 0x3c, 0x39, 0x3d, 0x36, 0x48, 0x3d, 0x43, 0x34, + 0x3b, 0x46, 0x43, 0x41, 0x33, 0x3e, 0x44, 0x3d, 0x44, 0x44, 0x4c, 0x3c, + 0x37, 0x49, 0x42, 0x35, 0x45, 0x3a, 0x3c, 0x41, 0x3a, 0x45, 0x46, 0x41, + 0x3c, 0x48, 0x46, 0x36, 0x36, 0x42, 0x3b, 0x46, 0x42, 0x45, 0x44, 0x47, + 0x3f, 0x44, 0x3a, 0x35, 0x37, 0x46, 0x40, 0x38, 0x40, 0x3d, 0x36, 0x2c, + 0x34, 0x47, 0x40, 0x38, 0x3f, 0x3f, 0x44, 0x2d, 0x3b, 0x3d, 0x3e, 0x44, + 0x3c, 0x40, 0x3e, 0x33, 0x3c, 0x3a, 0x49, 0x40, 0x42, 0x42, 0x3a, 0x3b, + 0x33, 0x3d, 0x3c, 0x43, 0x3e, 0x3d, 0x3a, 0x3a, 0x48, 0x3e, 0x3c, 0x39, + 0x3f, 0x44, 0x37, 0x40, 0x3f, 0x3c, 0x3e, 0x3d, 0x38, 0x42, 0x34, 0x62, + 0x51, 0x47, 0x44, 0x3f, 0x32, 0x3c, 0x3f, 0x46, 0x3d, 0x46, 0x3e, 0x45, + 0x4a, 0x3e, 0x5d, 0x43, 0x45, 0x49, 0x4a, 0x55, 0x41, 0x3c, 0x5a, 0x44, + 0x43, 0x3b, 0x3c, 0x3a, 0x4b, 0x4e, 0x4d, 0x42, 0x49, 0x30, 0x3b, 0x38, + 0x42, 0x44, 0x51, 0x40, 0x48, 0x33, 0x3f, 0x2b, 0x3c, 0x41, 0x3c, 0x45, + 0x35, 0x39, 0x42, 0x37, 0x40, 0x46, 0x46, 0x3f, 0x41, 0x45, 0x42, 0x3d, + 0x43, 0x38, 0x3e, 0x38, 0x3c, 0x39, 0x40, 0x38, 0x37, 0x36, 0x3d, 0x3d, + 0x38, 0x47, 0x45, 0x3b, 0x45, 0x44, 0x42, 0x2e, 0x37, 0x40, 0x42, 0x42, + 0x3c, 0x36, 0x3b, 0x39, 0x44, 0x4d, 0x42, 0x3f, 0x3a, 0x3e, 0x45, 0x34, + 0x3c, 0x43, 0x47, 0x43, 0x3f, 0x48, 0x3b, 0x44, 0x3d, 0x44, 0x43, 0x3e, + 0x40, 0x4a, 0x31, 0x42, 0x42, 0x43, 0x48, 0x45, 0x3a, 0x42, 0x36, 0x2f, + 0x3c, 0x3e, 0x3b, 0x3b, 0x44, 0x3f, 0x3a, 0x2c, 0x47, 0x3f, 0x4a, 0x40, + 0x40, 0x40, 0x3c, 0x2a, 0x3e, 0x44, 0x40, 0x43, 0x3a, 0x42, 0x39, 0x34, + 0x49, 0x3e, 0x36, 0x42, 0x3f, 0x42, 0x33, 0x3b, 0x3c, 0x45, 0x39, 0x3f, + 0x3e, 0x3f, 0x41, 0x3d, 0x32, 0x3b, 0x31, 0x40, 0x3f, 0x44, 0x3c, 0x3f, + 0x40, 0x46, 0x45, 0x36, 0x36, 0x42, 0x30, 0x57, 0x47, 0x44, 0x48, 0x3f, + 0x35, 0x37, 0x3f, 0x3f, 0x38, 0x4a, 0x41, 0x46, 0x50, 0x3d, 0x5b, 0x41, + 0x3e, 0x3c, 0x4a, 0x54, 0x45, 0x41, 0x5b, 0x46, 0x3d, 0x3b, 0x43, 0x33, + 0x45, 0x4e, 0x43, 0x3b, 0x44, 0x37, 0x37, 0x32, 0x4c, 0x3d, 0x4c, 0x3f, + 0x49, 0x3b, 0x37, 0x3a, 0x33, 0x43, 0x3f, 0x40, 0x44, 0x36, 0x3b, 0x44, + 0x45, 0x40, 0x3c, 0x3c, 0x41, 0x44, 0x3b, 0x3d, 0x33, 0x37, 0x3c, 0x35, + 0x3d, 0x3f, 0x39, 0x38, 0x33, 0x43, 0x3e, 0x39, 0x3b, 0x3e, 0x41, 0x35, + 0x40, 0x46, 0x43, 0x35, 0x41, 0x3d, 0x32, 0x39, 0x3c, 0x40, 0x3e, 0x3f, + 0x42, 0x38, 0x3b, 0x45, 0x3a, 0x3d, 0x40, 0x36, 0x3a, 0x40, 0x46, 0x44, + 0x48, 0x45, 0x3f, 0x3a, 0x45, 0x45, 0x3c, 0x3b, 0x40, 0x4c, 0x39, 0x3a, + 0x38, 0x39, 0x46, 0x3a, 0x3e, 0x4b, 0x34, 0x39, 0x3d, 0x3f, 0x40, 0x39, + 0x45, 0x31, 0x45, 0x29, 0x3f, 0x38, 0x3a, 0x3f, 0x38, 0x3b, 0x36, 0x2d, + 0x43, 0x3d, 0x45, 0x3c, 0x46, 0x3f, 0x40, 0x3c, 0x3a, 0x3e, 0x3d, 0x38, + 0x3f, 0x3c, 0x3f, 0x42, 0x35, 0x3f, 0x3a, 0x43, 0x3d, 0x43, 0x3d, 0x33, + 0x3d, 0x48, 0x42, 0x3d, 0x45, 0x46, 0x3d, 0x35, 0x32, 0x44, 0x42, 0x37, + 0x3d, 0x40, 0x3c, 0x47, 0x4a, 0x45, 0x47, 0x2f, 0x33, 0x36, 0x3f, 0x42, + 0x38, 0x43, 0x3e, 0x3a, 0x41, 0x3f, 0x5f, 0x3f, 0x48, 0x3a, 0x44, 0x47, + 0x41, 0x3e, 0x57, 0x42, 0x41, 0x33, 0x34, 0x39, 0x42, 0x44, 0x42, 0x3c, + 0x49, 0x34, 0x37, 0x33, 0x47, 0x38, 0x43, 0x3d, 0x43, 0x3e, 0x3e, 0x36, + 0x41, 0x41, 0x37, 0x40, 0x39, 0x3e, 0x3b, 0x3b, 0x3e, 0x41, 0x3d, 0x3b, + 0x43, 0x3e, 0x39, 0x43, 0x2f, 0x3e, 0x33, 0x40, 0x45, 0x47, 0x30, 0x46, + 0x3f, 0x3f, 0x37, 0x42, 0x3d, 0x42, 0x43, 0x37, 0x38, 0x3c, 0x35, 0x34, + 0x41, 0x43, 0x3e, 0x3e, 0x3f, 0x49, 0x35, 0x35, 0x38, 0x36, 0x3a, 0x43, + 0x38, 0x46, 0x48, 0x36, 0x3f, 0x39, 0x3b, 0x3e, 0x48, 0x47, 0x41, 0x34, + 0x3b, 0x3c, 0x37, 0x3e, 0x40, 0x41, 0x3b, 0x3d, 0x43, 0x42, 0x3a, 0x39, + 0x3b, 0x43, 0x38, 0x2b, 0x43, 0x41, 0x48, 0x35, 0x44, 0x44, 0x3e, 0x2c, + 0x46, 0x40, 0x3e, 0x41, 0x38, 0x34, 0x35, 0x37, 0x34, 0x3f, 0x3d, 0x46, + 0x33, 0x3c, 0x3c, 0x2e, 0x3b, 0x45, 0x3d, 0x3e, 0x3a, 0x42, 0x3c, 0x36, + 0x3a, 0x42, 0x39, 0x43, 0x35, 0x39, 0x40, 0x44, 0x47, 0x41, 0x44, 0x3d, + 0x41, 0x3e, 0x38, 0x39, 0x45, 0x3a, 0x35, 0x43, 0x3f, 0x44, 0x41, 0x49, + 0x47, 0x3f, 0x44, 0x40, 0x38, 0x43, 0x40, 0x3e, 0x39, 0x42, 0x32, 0x3b, + 0x42, 0x47, 0x57, 0x37, 0x36, 0x38, 0x43, 0x49, 0x3b, 0x34, 0x54, 0x42, + 0x3d, 0x3f, 0x3e, 0x3b, 0x38, 0x41, 0x43, 0x3a, 0x44, 0x39, 0x34, 0x2c, + 0x38, 0x43, 0x4b, 0x3f, 0x40, 0x3e, 0x32, 0x33, 0x3d, 0x44, 0x45, 0x44, + 0x3e, 0x35, 0x37, 0x39, 0x40, 0x3e, 0x40, 0x3c, 0x34, 0x43, 0x37, 0x40, + 0x39, 0x3e, 0x3d, 0x43, 0x3a, 0x44, 0x43, 0x44, 0x3d, 0x3b, 0x45, 0x3b, + 0x3a, 0x3a, 0x3f, 0x37, 0x43, 0x3b, 0x33, 0x35, 0x40, 0x47, 0x3e, 0x3c, + 0x39, 0x3c, 0x34, 0x29, 0x3c, 0x3e, 0x46, 0x3e, 0x3c, 0x38, 0x3f, 0x2d, + 0x3d, 0x3d, 0x3f, 0x3f, 0x3d, 0x45, 0x3b, 0x32, 0x39, 0x3f, 0x41, 0x38, + 0x36, 0x3e, 0x3a, 0x35, 0x40, 0x3f, 0x3b, 0x32, 0x3c, 0x39, 0x3e, 0x35, + 0x3e, 0x45, 0x34, 0x38, 0x44, 0x39, 0x3f, 0x31, 0x34, 0x39, 0x3f, 0x38, + 0x44, 0x42, 0x3f, 0x3b, 0x39, 0x3d, 0x39, 0x3b, 0x44, 0x46, 0x38, 0x3d, + 0x45, 0x37, 0x40, 0x3a, 0x3a, 0x39, 0x35, 0x3c, 0x39, 0x40, 0x47, 0x3e, + 0x38, 0x42, 0x41, 0x3b, 0x48, 0x3f, 0x3a, 0x3e, 0x3d, 0x3f, 0x32, 0x3b, + 0x3f, 0x3d, 0x3e, 0x44, 0x43, 0x41, 0x44, 0x47, 0x48, 0x41, 0x41, 0x36, + 0x3a, 0x33, 0x3c, 0x3c, 0x37, 0x3e, 0x40, 0x34, 0x3f, 0x42, 0x53, 0x40, + 0x3f, 0x35, 0x3e, 0x46, 0x3a, 0x3e, 0x4b, 0x41, 0x46, 0x32, 0x39, 0x36, + 0x3b, 0x4f, 0x36, 0x3c, 0x40, 0x3a, 0x40, 0x40, 0x47, 0x3e, 0x49, 0x37, + 0x3f, 0x31, 0x3e, 0x40, 0x3b, 0x3f, 0x43, 0x44, 0x3a, 0x3d, 0x31, 0x41, + 0x41, 0x33, 0x43, 0x40, 0x3c, 0x3a, 0x41, 0x40, 0x37, 0x3f, 0x34, 0x3e, + 0x44, 0x42, 0x3d, 0x3f, 0x3f, 0x34, 0x36, 0x34, 0x31, 0x41, 0x32, 0x39, + 0x3e, 0x3d, 0x42, 0x35, 0x3e, 0x3a, 0x41, 0x47, 0x3d, 0x42, 0x33, 0x32, + 0x43, 0x42, 0x36, 0x41, 0x3e, 0x39, 0x46, 0x39, 0x35, 0x3d, 0x3d, 0x40, + 0x38, 0x44, 0x3d, 0x31, 0x44, 0x39, 0x3a, 0x45, 0x42, 0x41, 0x3d, 0x36, + 0x3f, 0x3c, 0x39, 0x3d, 0x32, 0x39, 0x42, 0x34, 0x3f, 0x38, 0x44, 0x3c, + 0x43, 0x45, 0x41, 0x2d, 0x44, 0x42, 0x3d, 0x3f, 0x44, 0x38, 0x3d, 0x35, + 0x3a, 0x48, 0x40, 0x3b, 0x3d, 0x36, 0x3b, 0x40, 0x3f, 0x3a, 0x3a, 0x3f, + 0x3c, 0x33, 0x39, 0x3c, 0x3c, 0x38, 0x47, 0x36, 0x3d, 0x41, 0x46, 0x41, + 0x34, 0x46, 0x48, 0x46, 0x3d, 0x3c, 0x40, 0x43, 0x3d, 0x41, 0x37, 0x3e, + 0x39, 0x47, 0x3f, 0x39, 0x46, 0x43, 0x3f, 0x41, 0x45, 0x37, 0x40, 0x3a, + 0x3d, 0x44, 0x3f, 0x3b, 0x3b, 0x40, 0x4f, 0x3d, 0x3d, 0x41, 0x3c, 0x43, + 0x3e, 0x46, 0x4e, 0x40, 0x3f, 0x34, 0x48, 0x29, 0x45, 0x44, 0x46, 0x41, + 0x45, 0x32, 0x3e, 0x38, 0x39, 0x3a, 0x3e, 0x3e, 0x4c, 0x34, 0x3c, 0x40, + 0x4a, 0x44, 0x3d, 0x46, 0x3b, 0x3e, 0x42, 0x42, 0x3a, 0x41, 0x43, 0x41, + 0x39, 0x3f, 0x3e, 0x3c, 0x36, 0x48, 0x3f, 0x3e, 0x3e, 0x37, 0x3f, 0x3f, + 0x3b, 0x40, 0x3e, 0x35, 0x32, 0x35, 0x3f, 0x33, 0x3f, 0x38, 0x43, 0x37, + 0x49, 0x38, 0x37, 0x3c, 0x3c, 0x40, 0x40, 0x3a, 0x3a, 0x46, 0x37, 0x34, + 0x34, 0x3b, 0x3d, 0x2f, 0x3a, 0x38, 0x3d, 0x46, 0x3d, 0x3b, 0x3d, 0x38, + 0x35, 0x37, 0x44, 0x3c, 0x3d, 0x3e, 0x40, 0x3a, 0x40, 0x33, 0x3e, 0x38, + 0x40, 0x3e, 0x45, 0x37, 0x3f, 0x3b, 0x3c, 0x40, 0x3b, 0x3c, 0x3b, 0x33, + 0x41, 0x3f, 0x3b, 0x42, 0x31, 0x3b, 0x3a, 0x39, 0x3d, 0x41, 0x39, 0x40, + 0x43, 0x45, 0x39, 0x3b, 0x3a, 0x42, 0x43, 0x3d, 0x3f, 0x40, 0x47, 0x39, + 0x37, 0x3f, 0x47, 0x3f, 0x45, 0x41, 0x39, 0x3a, 0x41, 0x38, 0x3c, 0x3c, + 0x39, 0x40, 0x39, 0x3b, 0x3b, 0x3e, 0x38, 0x3b, 0x37, 0x48, 0x41, 0x3f, + 0x3e, 0x37, 0x3d, 0x44, 0x3c, 0x3e, 0x40, 0x39, 0x41, 0x42, 0x3d, 0x45, + 0x3b, 0x3e, 0x4c, 0x3b, 0x3a, 0x3a, 0x3e, 0x47, 0x3c, 0x3f, 0x48, 0x3f, + 0x46, 0x3f, 0x39, 0x25, 0x44, 0x3a, 0x3b, 0x40, 0x41, 0x39, 0x39, 0x47, + 0x3b, 0x32, 0x49, 0x42, 0x41, 0x3a, 0x43, 0x41, 0x3e, 0x35, 0x37, 0x3d, + 0x49, 0x40, 0x45, 0x3b, 0x3c, 0x38, 0x48, 0x3c, 0x3c, 0x35, 0x3f, 0x41, + 0x41, 0x4c, 0x36, 0x39, 0x37, 0x3d, 0x3b, 0x3e, 0x44, 0x32, 0x3d, 0x3f, + 0x3a, 0x3b, 0x3a, 0x47, 0x38, 0x42, 0x36, 0x34, 0x43, 0x3f, 0x3e, 0x40, + 0x34, 0x31, 0x36, 0x33, 0x42, 0x37, 0x41, 0x41, 0x40, 0x3d, 0x3d, 0x37, + 0x43, 0x3a, 0x3e, 0x44, 0x43, 0x3c, 0x35, 0x38, 0x38, 0x3c, 0x43, 0x36, + 0x3a, 0x38, 0x40, 0x3f, 0x3d, 0x3e, 0x37, 0x3b, 0x41, 0x3a, 0x3b, 0x3d, + 0x3c, 0x41, 0x3c, 0x41, 0x47, 0x3f, 0x3f, 0x3b, 0x3d, 0x3f, 0x3b, 0x45, + 0x38, 0x38, 0x40, 0x38, 0x46, 0x42, 0x39, 0x3d, 0x3d, 0x3b, 0x42, 0x36, + 0x42, 0x41, 0x3e, 0x3e, 0x36, 0x3f, 0x37, 0x3f, 0x36, 0x48, 0x3b, 0x39, + 0x3d, 0x3f, 0x43, 0x3e, 0x3c, 0x40, 0x48, 0x46, 0x43, 0x36, 0x42, 0x39, + 0x46, 0x3c, 0x37, 0x38, 0x49, 0x37, 0x36, 0x39, 0x3e, 0x42, 0x48, 0x3a, + 0x3c, 0x3e, 0x42, 0x30, 0x3e, 0x34, 0x39, 0x3b, 0x46, 0x61, 0x46, 0x1e, + 0x4c, 0x3b, 0x40, 0x2d, 0x3c, 0x42, 0x32, 0x30, 0x49, 0x3e, 0x39, 0x34, + 0x30, 0x40, 0x31, 0x38, 0x40, 0x3d, 0x3c, 0x35, 0x3a, 0x36, 0x40, 0x3b, + 0x41, 0x40, 0x3b, 0x39, 0x37, 0x37, 0x3f, 0x3b, 0x3c, 0x3a, 0x40, 0x3a, + 0x36, 0x3c, 0x42, 0x39, 0x3e, 0x36, 0x40, 0x42, 0x39, 0x40, 0x3b, 0x34, + 0x37, 0x33, 0x36, 0x3f, 0x43, 0x33, 0x33, 0x27, 0x3d, 0x46, 0x40, 0x31, + 0x38, 0x3e, 0x41, 0x20, 0x3f, 0x39, 0x42, 0x35, 0x35, 0x45, 0x40, 0x1e, + 0x32, 0x35, 0x32, 0x3c, 0x35, 0x44, 0x46, 0x29, 0x3a, 0x3d, 0x37, 0x42, + 0x3b, 0x45, 0x3a, 0x26, 0x38, 0x40, 0x30, 0x37, 0x41, 0x40, 0x39, 0x2b, + 0x49, 0x3f, 0x43, 0x43, 0x40, 0x3a, 0x38, 0x29, 0x43, 0x3a, 0x37, 0x40, + 0x3f, 0x35, 0x3a, 0x28, 0x36, 0x3e, 0x3f, 0x43, 0x3c, 0x39, 0x42, 0x2c, + 0x38, 0x42, 0x38, 0x3d, 0x42, 0x38, 0x35, 0x2d, 0x34, 0x38, 0x3d, 0x43, + 0x46, 0x3e, 0x3c, 0x27, 0x3e, 0x40, 0x46, 0x39, 0x35, 0x3d, 0x42, 0x35, + 0x42, 0x36, 0x40, 0x3e, 0x3a, 0x3e, 0x3c, 0x37, 0x3a, 0x3c, 0x48, 0x48, + 0x48, 0x37, 0x3d, 0x38, 0x4b, 0x40, 0x43, 0x3b, 0x41, 0x46, 0x3c, 0x34, + 0x46, 0x3c, 0x3c, 0x3c, 0x4b, 0x64, 0x4a, 0x22, 0x52, 0x41, 0x42, 0x3b, + 0x42, 0x4a, 0x34, 0x37, 0x4b, 0x44, 0x3b, 0x4a, 0x38, 0x3f, 0x38, 0x3a, + 0x40, 0x41, 0x42, 0x3c, 0x33, 0x3e, 0x3c, 0x42, 0x2c, 0x4e, 0x47, 0x3f, + 0x38, 0x33, 0x39, 0x3f, 0x3b, 0x45, 0x37, 0x3a, 0x42, 0x42, 0x44, 0x3f, + 0x3c, 0x3c, 0x3e, 0x3d, 0x3c, 0x3c, 0x40, 0x2c, 0x3c, 0x3d, 0x42, 0x39, + 0x3a, 0x37, 0x43, 0x2a, 0x3d, 0x40, 0x41, 0x41, 0x46, 0x46, 0x42, 0x28, + 0x39, 0x3c, 0x37, 0x44, 0x46, 0x41, 0x47, 0x2b, 0x44, 0x33, 0x39, 0x3f, + 0x3f, 0x43, 0x3d, 0x23, 0x3a, 0x43, 0x41, 0x3b, 0x41, 0x42, 0x33, 0x1f, + 0x43, 0x3e, 0x3d, 0x40, 0x37, 0x33, 0x42, 0x28, 0x3b, 0x38, 0x37, 0x3c, + 0x34, 0x40, 0x44, 0x2a, 0x3c, 0x3a, 0x41, 0x37, 0x45, 0x3f, 0x3e, 0x26, + 0x41, 0x40, 0x35, 0x3d, 0x45, 0x3e, 0x3d, 0x29, 0x3c, 0x39, 0x3f, 0x3c, + 0x3d, 0x39, 0x38, 0x2d, 0x39, 0x38, 0x38, 0x44, 0x3c, 0x3e, 0x38, 0x26, + 0x40, 0x36, 0x39, 0x38, 0x3f, 0x32, 0x39, 0x35, 0x3d, 0x3e, 0x35, 0x3a, + 0x3f, 0x3f, 0x31, 0x35, 0x34, 0x45, 0x3e, 0x43, 0x48, 0x3b, 0x37, 0x39, + 0x4d, 0x46, 0x54, 0x40, 0x41, 0x4e, 0x3d, 0x38, 0x4d, 0x38, 0x3a, 0x3b, + 0x49, 0x5a, 0x4a, 0x1e, 0x5e, 0x39, 0x38, 0x37, 0x3a, 0x51, 0x3a, 0x3c, + 0x50, 0x3f, 0x40, 0x42, 0x33, 0x3b, 0x2e, 0x4a, 0x3f, 0x4a, 0x3b, 0x43, + 0x36, 0x3e, 0x3d, 0x42, 0x39, 0x46, 0x4b, 0x3c, 0x3b, 0x3b, 0x35, 0x3e, + 0x3d, 0x4b, 0x3f, 0x41, 0x3f, 0x3b, 0x42, 0x42, 0x38, 0x3a, 0x41, 0x3d, + 0x36, 0x41, 0x37, 0x2f, 0x38, 0x37, 0x3f, 0x34, 0x35, 0x35, 0x45, 0x30, + 0x31, 0x42, 0x31, 0x3a, 0x3a, 0x3e, 0x3d, 0x23, 0x3f, 0x43, 0x3b, 0x41, + 0x35, 0x3b, 0x40, 0x25, 0x45, 0x3e, 0x42, 0x3b, 0x31, 0x40, 0x36, 0x28, + 0x43, 0x42, 0x30, 0x42, 0x32, 0x32, 0x36, 0x2c, 0x35, 0x3a, 0x3d, 0x3a, + 0x3c, 0x36, 0x3e, 0x30, 0x41, 0x42, 0x38, 0x41, 0x41, 0x3e, 0x3c, 0x23, + 0x37, 0x40, 0x3c, 0x3e, 0x3e, 0x3a, 0x37, 0x2b, 0x36, 0x40, 0x41, 0x42, + 0x3e, 0x38, 0x44, 0x22, 0x46, 0x38, 0x33, 0x3b, 0x3a, 0x3a, 0x3a, 0x24, + 0x36, 0x3b, 0x38, 0x44, 0x34, 0x38, 0x40, 0x28, 0x38, 0x3d, 0x36, 0x44, + 0x31, 0x3e, 0x37, 0x37, 0x36, 0x3f, 0x47, 0x38, 0x3b, 0x3e, 0x2c, 0x4c, + 0x36, 0x3c, 0x3b, 0x41, 0x4c, 0x3d, 0x3d, 0x40, 0x49, 0x44, 0x52, 0x3f, + 0x3b, 0x4d, 0x3c, 0x3a, 0x4f, 0x3b, 0x36, 0x3b, 0x4a, 0x5f, 0x4e, 0x1f, + 0x57, 0x3c, 0x3d, 0x3d, 0x46, 0x59, 0x42, 0x45, 0x52, 0x3d, 0x3a, 0x41, + 0x31, 0x39, 0x39, 0x4f, 0x43, 0x4e, 0x3e, 0x37, 0x3a, 0x37, 0x33, 0x47, + 0x32, 0x45, 0x47, 0x43, 0x31, 0x33, 0x38, 0x43, 0x3e, 0x47, 0x3d, 0x32, + 0x3b, 0x39, 0x3c, 0x42, 0x3d, 0x47, 0x42, 0x40, 0x3d, 0x3f, 0x3c, 0x34, + 0x3b, 0x3e, 0x42, 0x3d, 0x43, 0x35, 0x42, 0x2c, 0x35, 0x3d, 0x3c, 0x3d, + 0x3a, 0x3c, 0x46, 0x25, 0x43, 0x35, 0x3d, 0x39, 0x3a, 0x3c, 0x40, 0x2b, + 0x33, 0x40, 0x3d, 0x46, 0x45, 0x37, 0x3c, 0x36, 0x43, 0x37, 0x3e, 0x3a, + 0x3c, 0x47, 0x3f, 0x38, 0x36, 0x3e, 0x3a, 0x42, 0x3c, 0x42, 0x33, 0x39, + 0x3c, 0x3a, 0x3c, 0x40, 0x48, 0x3b, 0x40, 0x32, 0x37, 0x47, 0x34, 0x38, + 0x33, 0x3d, 0x49, 0x2d, 0x36, 0x42, 0x3d, 0x3e, 0x47, 0x3c, 0x42, 0x2c, + 0x3b, 0x31, 0x3f, 0x3c, 0x3d, 0x3c, 0x3f, 0x2b, 0x41, 0x35, 0x33, 0x43, + 0x47, 0x39, 0x34, 0x2a, 0x3a, 0x3a, 0x40, 0x3d, 0x44, 0x3c, 0x39, 0x34, + 0x43, 0x40, 0x33, 0x3a, 0x3b, 0x42, 0x38, 0x3b, 0x34, 0x35, 0x40, 0x43, + 0x4b, 0x41, 0x3d, 0x38, 0x49, 0x44, 0x4d, 0x37, 0x3a, 0x4b, 0x40, 0x39, + 0x4e, 0x3b, 0x30, 0x38, 0x47, 0x5d, 0x50, 0x1f, 0x54, 0x35, 0x3a, 0x39, + 0x40, 0x4c, 0x46, 0x42, 0x52, 0x39, 0x39, 0x45, 0x41, 0x3c, 0x30, 0x5b, + 0x43, 0x4d, 0x4a, 0x3e, 0x31, 0x39, 0x41, 0x4c, 0x36, 0x44, 0x4c, 0x39, + 0x32, 0x41, 0x47, 0x3e, 0x34, 0x49, 0x45, 0x3b, 0x34, 0x3a, 0x3b, 0x47, + 0x43, 0x3e, 0x43, 0x32, 0x40, 0x3e, 0x3e, 0x38, 0x37, 0x3e, 0x37, 0x3a, + 0x3a, 0x40, 0x48, 0x2f, 0x3e, 0x3e, 0x46, 0x3a, 0x3e, 0x35, 0x49, 0x30, + 0x3a, 0x41, 0x3e, 0x39, 0x34, 0x45, 0x3d, 0x34, 0x48, 0x43, 0x43, 0x42, + 0x33, 0x39, 0x3b, 0x3f, 0x30, 0x46, 0x41, 0x39, 0x48, 0x3a, 0x3c, 0x3e, + 0x3f, 0x36, 0x40, 0x3d, 0x43, 0x40, 0x3e, 0x39, 0x44, 0x40, 0x44, 0x3b, + 0x43, 0x42, 0x39, 0x38, 0x3a, 0x3f, 0x3b, 0x3f, 0x38, 0x3d, 0x34, 0x30, + 0x34, 0x3d, 0x3f, 0x42, 0x44, 0x3e, 0x34, 0x32, 0x37, 0x46, 0x44, 0x38, + 0x3c, 0x45, 0x39, 0x2b, 0x41, 0x3c, 0x40, 0x40, 0x3a, 0x3a, 0x3c, 0x32, + 0x45, 0x42, 0x3d, 0x46, 0x38, 0x3b, 0x34, 0x35, 0x38, 0x43, 0x3d, 0x34, + 0x42, 0x3b, 0x38, 0x3d, 0x37, 0x43, 0x3f, 0x39, 0x4e, 0x39, 0x40, 0x3f, + 0x4d, 0x43, 0x49, 0x3f, 0x36, 0x41, 0x44, 0x39, 0x48, 0x3a, 0x35, 0x39, + 0x48, 0x59, 0x4e, 0x25, 0x58, 0x39, 0x42, 0x35, 0x43, 0x4e, 0x42, 0x3f, + 0x4a, 0x43, 0x3b, 0x3f, 0x3b, 0x37, 0x2b, 0x5a, 0x3d, 0x44, 0x3b, 0x40, + 0x31, 0x38, 0x37, 0x44, 0x32, 0x3e, 0x41, 0x3d, 0x2c, 0x42, 0x42, 0x3c, + 0x37, 0x45, 0x41, 0x41, 0x3d, 0x39, 0x41, 0x40, 0x3a, 0x46, 0x41, 0x40, + 0x40, 0x3d, 0x38, 0x31, 0x37, 0x3f, 0x42, 0x38, 0x3f, 0x3c, 0x48, 0x30, + 0x3e, 0x39, 0x3f, 0x3d, 0x3d, 0x44, 0x52, 0x35, 0x3b, 0x32, 0x42, 0x32, + 0x3a, 0x43, 0x39, 0x3b, 0x31, 0x43, 0x36, 0x3c, 0x3c, 0x3c, 0x41, 0x45, + 0x42, 0x49, 0x41, 0x3b, 0x42, 0x3e, 0x41, 0x44, 0x36, 0x41, 0x3f, 0x3c, + 0x3e, 0x47, 0x45, 0x41, 0x38, 0x41, 0x3f, 0x43, 0x35, 0x32, 0x41, 0x39, + 0x36, 0x47, 0x35, 0x42, 0x44, 0x3b, 0x3f, 0x34, 0x48, 0x41, 0x43, 0x42, + 0x36, 0x3e, 0x3c, 0x3d, 0x3d, 0x3b, 0x42, 0x44, 0x3a, 0x44, 0x36, 0x2a, + 0x41, 0x39, 0x3a, 0x41, 0x46, 0x3c, 0x44, 0x2f, 0x36, 0x39, 0x3b, 0x3f, + 0x38, 0x45, 0x3c, 0x3c, 0x3e, 0x41, 0x3c, 0x39, 0x3e, 0x40, 0x2f, 0x45, + 0x3b, 0x41, 0x40, 0x3c, 0x4e, 0x38, 0x3e, 0x48, 0x46, 0x40, 0x48, 0x44, + 0x40, 0x4a, 0x45, 0x3c, 0x4f, 0x39, 0x37, 0x3a, 0x4e, 0x59, 0x5c, 0x22, + 0x58, 0x32, 0x38, 0x34, 0x40, 0x4b, 0x43, 0x43, 0x4f, 0x3e, 0x39, 0x40, + 0x37, 0x3e, 0x2f, 0x55, 0x3f, 0x40, 0x38, 0x3f, 0x3a, 0x33, 0x37, 0x3d, + 0x34, 0x4c, 0x37, 0x3f, 0x32, 0x39, 0x45, 0x34, 0x44, 0x4c, 0x3f, 0x3b, + 0x3c, 0x36, 0x36, 0x43, 0x36, 0x47, 0x41, 0x46, 0x41, 0x3e, 0x41, 0x3a, + 0x43, 0x3a, 0x48, 0x42, 0x42, 0x3e, 0x4c, 0x36, 0x3d, 0x39, 0x43, 0x46, + 0x3d, 0x42, 0x42, 0x3b, 0x45, 0x43, 0x3c, 0x40, 0x39, 0x37, 0x34, 0x45, + 0x3f, 0x40, 0x34, 0x38, 0x43, 0x3f, 0x36, 0x47, 0x3f, 0x3b, 0x49, 0x3c, + 0x3a, 0x3a, 0x42, 0x4c, 0x37, 0x3e, 0x3b, 0x32, 0x47, 0x40, 0x45, 0x4d, + 0x39, 0x3b, 0x39, 0x40, 0x3e, 0x3c, 0x3d, 0x3a, 0x3d, 0x3b, 0x3e, 0x43, + 0x3e, 0x3f, 0x3a, 0x3c, 0x41, 0x40, 0x39, 0x3c, 0x3a, 0x38, 0x39, 0x37, + 0x36, 0x33, 0x43, 0x45, 0x3f, 0x45, 0x41, 0x30, 0x3b, 0x34, 0x3c, 0x39, + 0x3b, 0x45, 0x37, 0x2e, 0x36, 0x34, 0x36, 0x44, 0x3d, 0x40, 0x3a, 0x3c, + 0x3d, 0x3b, 0x38, 0x41, 0x42, 0x3a, 0x32, 0x4b, 0x38, 0x3e, 0x41, 0x46, + 0x57, 0x3a, 0x44, 0x48, 0x47, 0x45, 0x47, 0x3e, 0x43, 0x42, 0x45, 0x3b, + 0x50, 0x39, 0x37, 0x3f, 0x47, 0x51, 0x5e, 0x22, 0x59, 0x33, 0x3c, 0x37, + 0x43, 0x50, 0x49, 0x47, 0x46, 0x42, 0x39, 0x44, 0x44, 0x3d, 0x2f, 0x53, + 0x35, 0x41, 0x40, 0x3d, 0x2d, 0x35, 0x2f, 0x3e, 0x3f, 0x37, 0x38, 0x3e, + 0x30, 0x45, 0x46, 0x38, 0x33, 0x3c, 0x3e, 0x3b, 0x44, 0x42, 0x47, 0x49, + 0x43, 0x40, 0x3d, 0x3c, 0x38, 0x43, 0x3e, 0x38, 0x3d, 0x40, 0x36, 0x43, + 0x43, 0x3e, 0x40, 0x3c, 0x44, 0x47, 0x43, 0x3d, 0x41, 0x39, 0x3e, 0x45, + 0x39, 0x3d, 0x39, 0x40, 0x42, 0x40, 0x3b, 0x4a, 0x40, 0x41, 0x3f, 0x37, + 0x43, 0x41, 0x37, 0x4c, 0x3f, 0x3d, 0x38, 0x3a, 0x42, 0x46, 0x43, 0x4d, + 0x3c, 0x3a, 0x43, 0x3e, 0x3b, 0x3d, 0x46, 0x4a, 0x38, 0x3d, 0x3d, 0x39, + 0x3e, 0x3c, 0x3b, 0x3e, 0x3a, 0x40, 0x40, 0x34, 0x41, 0x3f, 0x3e, 0x3f, + 0x47, 0x3c, 0x32, 0x3a, 0x3c, 0x44, 0x3f, 0x42, 0x41, 0x43, 0x3e, 0x3a, + 0x3b, 0x42, 0x41, 0x39, 0x39, 0x37, 0x39, 0x3e, 0x3d, 0x33, 0x3e, 0x35, + 0x44, 0x37, 0x40, 0x35, 0x3f, 0x47, 0x37, 0x41, 0x35, 0x38, 0x47, 0x40, + 0x43, 0x44, 0x2e, 0x48, 0x35, 0x44, 0x41, 0x3c, 0x47, 0x3d, 0x3d, 0x52, + 0x48, 0x41, 0x44, 0x41, 0x42, 0x4b, 0x3e, 0x3d, 0x4e, 0x32, 0x34, 0x47, + 0x55, 0x57, 0x5f, 0x22, 0x57, 0x33, 0x40, 0x37, 0x40, 0x4a, 0x4d, 0x47, + 0x48, 0x38, 0x3e, 0x46, 0x37, 0x42, 0x28, 0x57, 0x38, 0x42, 0x36, 0x43, + 0x35, 0x37, 0x39, 0x39, 0x42, 0x39, 0x38, 0x3c, 0x35, 0x3c, 0x3c, 0x3a, + 0x3c, 0x4c, 0x45, 0x3f, 0x43, 0x3d, 0x45, 0x45, 0x40, 0x47, 0x3e, 0x3e, + 0x3d, 0x4b, 0x49, 0x35, 0x43, 0x3c, 0x36, 0x46, 0x3c, 0x46, 0x42, 0x44, + 0x3c, 0x42, 0x3d, 0x42, 0x44, 0x3c, 0x4a, 0x40, 0x40, 0x3c, 0x3b, 0x3c, + 0x35, 0x34, 0x2e, 0x46, 0x38, 0x3d, 0x38, 0x44, 0x41, 0x40, 0x3c, 0x52, + 0x3b, 0x3d, 0x3b, 0x3f, 0x42, 0x47, 0x44, 0x52, 0x44, 0x44, 0x39, 0x3f, + 0x43, 0x35, 0x3c, 0x4d, 0x39, 0x3d, 0x3b, 0x37, 0x3e, 0x38, 0x3e, 0x49, + 0x3a, 0x37, 0x3c, 0x49, 0x40, 0x41, 0x3c, 0x40, 0x3d, 0x38, 0x39, 0x3f, + 0x44, 0x3e, 0x42, 0x3e, 0x47, 0x40, 0x34, 0x46, 0x48, 0x37, 0x45, 0x3e, + 0x46, 0x3f, 0x35, 0x39, 0x38, 0x3f, 0x36, 0x2c, 0x40, 0x38, 0x3e, 0x3c, + 0x32, 0x3c, 0x46, 0x3a, 0x3f, 0x41, 0x36, 0x49, 0x42, 0x38, 0x36, 0x43, + 0x3d, 0x41, 0x46, 0x35, 0x4f, 0x3a, 0x41, 0x5c, 0x4a, 0x42, 0x4e, 0x42, + 0x46, 0x54, 0x3f, 0x45, 0x4c, 0x30, 0x33, 0x44, 0x56, 0x5d, 0x68, 0x26, + 0x60, 0x33, 0x3e, 0x3a, 0x42, 0x49, 0x52, 0x47, 0x51, 0x46, 0x40, 0x47, + 0x41, 0x3b, 0x1b, 0x4f, 0x3c, 0x45, 0x3d, 0x3d, 0x32, 0x2f, 0x3e, 0x3c, + 0x3c, 0x3f, 0x3b, 0x3c, 0x2c, 0x3a, 0x41, 0x3c, 0x35, 0x3e, 0x3e, 0x3c, + 0x3d, 0x3f, 0x3e, 0x40, 0x40, 0x44, 0x42, 0x3c, 0x3c, 0x3c, 0x41, 0x3c, + 0x3c, 0x3d, 0x3e, 0x3d, 0x3c, 0x3d, 0x4a, 0x46, 0x3f, 0x35, 0x33, 0x43, + 0x42, 0x41, 0x4d, 0x48, 0x48, 0x44, 0x3e, 0x41, 0x41, 0x36, 0x3c, 0x4c, + 0x34, 0x47, 0x42, 0x39, 0x3e, 0x43, 0x3a, 0x53, 0x3b, 0x3b, 0x42, 0x3d, + 0x41, 0x3c, 0x3e, 0x52, 0x3a, 0x44, 0x34, 0x43, 0x3d, 0x3d, 0x3a, 0x50, + 0x3e, 0x33, 0x41, 0x40, 0x3f, 0x38, 0x43, 0x42, 0x3b, 0x37, 0x3e, 0x43, + 0x3f, 0x3c, 0x41, 0x49, 0x40, 0x32, 0x40, 0x3e, 0x3b, 0x3e, 0x44, 0x3c, + 0x35, 0x37, 0x3d, 0x41, 0x34, 0x3f, 0x3a, 0x3c, 0x47, 0x32, 0x41, 0x3d, + 0x3c, 0x3a, 0x4a, 0x31, 0x43, 0x38, 0x45, 0x37, 0x49, 0x3c, 0x34, 0x3f, + 0x3d, 0x3d, 0x3d, 0x45, 0x47, 0x3e, 0x37, 0x48, 0x40, 0x3b, 0x45, 0x3d, + 0x4e, 0x42, 0x3f, 0x57, 0x4b, 0x43, 0x4b, 0x3d, 0x3f, 0x47, 0x4a, 0x43, + 0x4e, 0x30, 0x38, 0x45, 0x59, 0x60, 0x64, 0x2d, 0x5a, 0x2d, 0x34, 0x35, + 0x47, 0x54, 0x4e, 0x3f, 0x44, 0x45, 0x3c, 0x43, 0x3d, 0x40, 0x1c, 0x5a, + 0x36, 0x3f, 0x3a, 0x39, 0x37, 0x3c, 0x32, 0x3b, 0x2d, 0x4a, 0x42, 0x35, + 0x30, 0x41, 0x43, 0x3d, 0x3d, 0x45, 0x38, 0x36, 0x3e, 0x40, 0x3a, 0x4a, + 0x34, 0x3d, 0x44, 0x3c, 0x39, 0x3b, 0x52, 0x38, 0x40, 0x3b, 0x3f, 0x3f, + 0x35, 0x37, 0x46, 0x48, 0x38, 0x3b, 0x40, 0x36, 0x3d, 0x3a, 0x4f, 0x45, + 0x35, 0x3a, 0x35, 0x33, 0x37, 0x43, 0x42, 0x52, 0x37, 0x3b, 0x3d, 0x42, + 0x44, 0x3d, 0x48, 0x58, 0x33, 0x3f, 0x41, 0x44, 0x44, 0x3f, 0x3b, 0x52, + 0x47, 0x39, 0x32, 0x3b, 0x38, 0x35, 0x48, 0x50, 0x34, 0x30, 0x39, 0x43, + 0x42, 0x40, 0x3b, 0x4b, 0x43, 0x3d, 0x34, 0x44, 0x33, 0x39, 0x44, 0x4b, + 0x45, 0x3e, 0x3c, 0x3f, 0x3a, 0x3e, 0x3c, 0x45, 0x36, 0x3e, 0x3d, 0x40, + 0x43, 0x46, 0x37, 0x3d, 0x3b, 0x42, 0x43, 0x3f, 0x3a, 0x41, 0x48, 0x2f, + 0x3e, 0x39, 0x3a, 0x39, 0x3f, 0x3a, 0x41, 0x40, 0x40, 0x3c, 0x3b, 0x3b, + 0x3f, 0x40, 0x3e, 0x42, 0x38, 0x3f, 0x38, 0x3c, 0x49, 0x45, 0x3f, 0x62, + 0x55, 0x47, 0x4c, 0x3c, 0x3c, 0x4a, 0x4c, 0x46, 0x4f, 0x39, 0x3a, 0x3b, + 0x5e, 0x58, 0x6f, 0x2b, 0x5a, 0x2f, 0x3a, 0x35, 0x4b, 0x47, 0x4a, 0x46, + 0x45, 0x3e, 0x38, 0x4f, 0x3b, 0x3d, 0x21, 0x4b, 0x3d, 0x40, 0x37, 0x40, + 0x2d, 0x2c, 0x43, 0x3f, 0x2b, 0x3e, 0x3d, 0x39, 0x2f, 0x39, 0x44, 0x3c, + 0x39, 0x39, 0x43, 0x3b, 0x3d, 0x3b, 0x44, 0x39, 0x42, 0x42, 0x3e, 0x40, + 0x3b, 0x42, 0x53, 0x40, 0x32, 0x3d, 0x35, 0x3f, 0x3d, 0x45, 0x48, 0x46, + 0x3d, 0x43, 0x3c, 0x36, 0x35, 0x39, 0x3d, 0x4a, 0x39, 0x39, 0x3e, 0x41, + 0x38, 0x36, 0x3b, 0x53, 0x3c, 0x36, 0x32, 0x3b, 0x43, 0x3d, 0x42, 0x57, + 0x35, 0x2f, 0x38, 0x40, 0x2f, 0x3d, 0x3c, 0x4c, 0x40, 0x2f, 0x3a, 0x36, + 0x39, 0x3c, 0x3a, 0x51, 0x3d, 0x37, 0x39, 0x3c, 0x42, 0x40, 0x43, 0x52, + 0x3e, 0x42, 0x3e, 0x45, 0x36, 0x34, 0x42, 0x4b, 0x3a, 0x38, 0x37, 0x3f, + 0x36, 0x41, 0x3a, 0x45, 0x3e, 0x38, 0x35, 0x41, 0x35, 0x34, 0x37, 0x3c, + 0x3f, 0x31, 0x3c, 0x35, 0x33, 0x43, 0x36, 0x28, 0x44, 0x42, 0x3e, 0x42, + 0x3a, 0x41, 0x43, 0x35, 0x3d, 0x3f, 0x40, 0x3e, 0x3d, 0x33, 0x31, 0x41, + 0x3d, 0x40, 0x3b, 0x40, 0x51, 0x40, 0x3f, 0xfb, 0x51, 0x49, 0x4c, 0x3d, + 0x44, 0x4e, 0x47, 0x42, 0x50, 0x39, 0x39, 0x40, 0x59, 0x5d, 0x70, 0x2c, + 0x59, 0x39, 0x38, 0x2f, 0x46, 0x50, 0x51, 0x47, 0x4c, 0x3c, 0x39, 0x48, + 0x44, 0x3a, 0x1a, 0x51, 0x35, 0x3e, 0x34, 0x3a, 0x3d, 0x2b, 0x41, 0x39, + 0x37, 0x4d, 0x3e, 0x43, 0x38, 0x3b, 0x3a, 0x35, 0x36, 0x3a, 0x43, 0x39, + 0x39, 0x3a, 0x46, 0x3b, 0x39, 0x3c, 0x46, 0x36, 0x3e, 0x3d, 0x4b, 0x3d, + 0x3b, 0x46, 0x3a, 0x41, 0x31, 0x3c, 0x44, 0x4a, 0x37, 0x42, 0x39, 0x43, + 0x43, 0x3e, 0x40, 0x47, 0x3c, 0x3e, 0x3b, 0x43, 0x34, 0x3a, 0x43, 0x53, + 0x3f, 0x37, 0x39, 0x37, 0x3e, 0x3b, 0x46, 0x59, 0x37, 0x37, 0x33, 0x3d, + 0x38, 0x42, 0x36, 0x58, 0x2e, 0x32, 0x2b, 0x45, 0x32, 0x33, 0x36, 0x50, + 0x41, 0x3f, 0x37, 0x3d, 0x3f, 0x3d, 0x46, 0x49, 0x41, 0x38, 0x33, 0x3d, + 0x33, 0x32, 0x3a, 0x49, 0x41, 0x41, 0x3d, 0x33, 0x3b, 0x3b, 0x3a, 0x46, + 0x34, 0x44, 0x3f, 0x3b, 0x2f, 0x3f, 0x32, 0x3c, 0x3f, 0x43, 0x3e, 0x45, + 0x3a, 0x3c, 0x43, 0x26, 0x46, 0x37, 0x38, 0x3e, 0x36, 0x31, 0x3e, 0x34, + 0x39, 0x3a, 0x38, 0x42, 0x38, 0x3e, 0x32, 0x42, 0x37, 0x37, 0x3c, 0x3a, + 0x48, 0x44, 0x3a, 0x68, 0x56, 0x46, 0x4d, 0x47, 0x40, 0x4e, 0x42, 0x46, + 0x51, 0x40, 0x38, 0x43, 0x58, 0x5d, 0x6a, 0x31, 0x57, 0x32, 0x3c, 0x36, + 0x49, 0x56, 0x52, 0x48, 0x4b, 0x41, 0x2f, 0x4d, 0x31, 0x43, 0x1b, 0x4c, + 0x30, 0x44, 0x33, 0x36, 0x2c, 0x3d, 0x45, 0x3a, 0x35, 0x46, 0x3d, 0x39, + 0x2e, 0x38, 0x3f, 0x37, 0x41, 0x44, 0x46, 0x31, 0x33, 0x46, 0x37, 0x37, + 0x3f, 0x41, 0x45, 0x30, 0x46, 0x3b, 0x50, 0x3b, 0x40, 0x39, 0x42, 0x43, + 0x35, 0x37, 0x40, 0x44, 0x3b, 0x41, 0x3d, 0x37, 0x3a, 0x41, 0x3d, 0x46, + 0x36, 0x41, 0x38, 0x41, 0x38, 0x3d, 0x45, 0x58, 0x3d, 0x3a, 0x3d, 0x44, + 0x45, 0x38, 0x48, 0x5c, 0x3d, 0x39, 0x43, 0x45, 0x41, 0x3e, 0x4a, 0x56, + 0x40, 0x33, 0x30, 0x31, 0x42, 0x39, 0x38, 0x56, 0x30, 0x3a, 0x35, 0x3e, + 0x3f, 0x38, 0x36, 0x47, 0x3c, 0x3a, 0x3d, 0x3f, 0x37, 0x35, 0x3b, 0x4d, + 0x43, 0x36, 0x39, 0x37, 0x3e, 0x42, 0x3d, 0x3f, 0x40, 0x3f, 0x34, 0x3b, + 0x3f, 0x3e, 0x3b, 0x39, 0x3b, 0x3a, 0x3a, 0x3c, 0x34, 0x3f, 0x3c, 0x2a, + 0x49, 0x3b, 0x36, 0x3c, 0x35, 0x46, 0x38, 0x3b, 0x3c, 0x39, 0x38, 0x42, + 0x39, 0x36, 0x2e, 0x4a, 0x3d, 0x39, 0x3f, 0x3f, 0x4b, 0x45, 0x3e, 0x67, + 0x4b, 0x4b, 0x49, 0x3e, 0x3f, 0x53, 0x4c, 0x55, 0x47, 0x32, 0x3b, 0x39, + 0x54, 0x5b, 0x6f, 0x29, 0x5a, 0x34, 0x3e, 0x26, 0x45, 0x52, 0x59, 0x44, + 0x59, 0x39, 0x3c, 0x47, 0x36, 0x46, 0x16, 0x50, 0x32, 0x46, 0x34, 0x35, + 0x35, 0x2d, 0x39, 0x38, 0x2c, 0x42, 0x43, 0x3b, 0x32, 0x3f, 0x37, 0x2f, + 0x34, 0x43, 0x46, 0x3b, 0x3b, 0x41, 0x3c, 0x37, 0x3e, 0x43, 0x4b, 0x36, + 0x3e, 0x3c, 0x4c, 0x42, 0x40, 0x3f, 0x49, 0x40, 0x3c, 0x40, 0x3c, 0x48, + 0x35, 0x42, 0x3f, 0x42, 0x44, 0x40, 0x45, 0x4f, 0x3f, 0x3f, 0x40, 0x42, + 0x3b, 0x3d, 0x49, 0x55, 0x42, 0x39, 0x41, 0x3b, 0x3f, 0x38, 0x44, 0x60, + 0x34, 0x40, 0x3b, 0x3b, 0x35, 0x3d, 0x41, 0x4e, 0x35, 0x33, 0x30, 0x3a, + 0x3a, 0x32, 0x42, 0x4f, 0x33, 0x34, 0x2f, 0x38, 0x49, 0x38, 0x40, 0x4c, + 0x35, 0x38, 0x3e, 0x46, 0x3f, 0x3a, 0x3a, 0x45, 0x3b, 0x34, 0x2e, 0x39, + 0x32, 0x3e, 0x40, 0x48, 0x35, 0x44, 0x3a, 0x34, 0x3f, 0x35, 0x3b, 0x32, + 0x40, 0x43, 0x3e, 0x38, 0x3b, 0x43, 0x3c, 0x2b, 0x46, 0x43, 0x40, 0x32, + 0x42, 0x3b, 0x49, 0x2e, 0x3b, 0x3a, 0x3e, 0x41, 0x3c, 0x3f, 0x31, 0x3b, + 0x41, 0x33, 0x41, 0x3c, 0x4d, 0x40, 0x38, 0x68, 0x4c, 0x4c, 0x4e, 0x3f, + 0x3f, 0x54, 0x4a, 0x3d, 0x4c, 0x33, 0x3b, 0x3a, 0x5d, 0x60, 0x71, 0x2b, + 0x59, 0x33, 0x3c, 0x2c, 0x47, 0x52, 0x4f, 0x51, 0x56, 0x3d, 0x39, 0x44, + 0x35, 0x41, 0x1b, 0x4a, 0x35, 0x41, 0x37, 0x35, 0x2c, 0x35, 0x37, 0x35, + 0x38, 0x41, 0x38, 0x3e, 0x3c, 0x40, 0x3c, 0x2f, 0x38, 0x3e, 0x3f, 0x45, + 0x40, 0x3d, 0x3c, 0x35, 0x3c, 0x46, 0x43, 0x39, 0x37, 0x42, 0x4e, 0x3c, + 0x42, 0x46, 0x37, 0x33, 0x43, 0x3f, 0x47, 0x4a, 0x3d, 0x3e, 0x40, 0x40, + 0x40, 0x3f, 0x4b, 0x54, 0x36, 0x3f, 0x37, 0x40, 0x39, 0x39, 0x47, 0x51, + 0x3d, 0x39, 0x36, 0x36, 0x40, 0x40, 0x41, 0x5a, 0x38, 0x39, 0x42, 0x38, + 0x40, 0x39, 0x43, 0x50, 0x3a, 0x3a, 0x32, 0x3c, 0x3c, 0x35, 0x44, 0x4a, + 0x37, 0x35, 0x36, 0x3c, 0x35, 0x30, 0x48, 0x4b, 0x3c, 0x33, 0x37, 0x3e, + 0x42, 0x3c, 0x42, 0x4e, 0x41, 0x32, 0x3e, 0x33, 0x49, 0x39, 0x3e, 0x42, + 0x3d, 0x39, 0x37, 0x36, 0x35, 0x41, 0x3e, 0x37, 0x37, 0x3e, 0x3d, 0x38, + 0x3a, 0x3c, 0x41, 0x29, 0x3c, 0x3b, 0x39, 0x40, 0x43, 0x3d, 0x3e, 0x33, + 0x3f, 0x3f, 0x3e, 0x43, 0x43, 0x38, 0x38, 0x41, 0x3b, 0x38, 0x35, 0x3a, + 0x4b, 0x44, 0x44, 0x55, 0x4e, 0x44, 0x4d, 0x49, 0x3e, 0x53, 0x45, 0x3f, + 0x45, 0x3d, 0x36, 0x36, 0x4f, 0x5b, 0x6b, 0x28, 0x59, 0x34, 0x39, 0x34, + 0x4f, 0x4d, 0x52, 0x3e, 0x51, 0x34, 0x35, 0x4a, 0x3b, 0x3f, 0x21, 0x45, + 0x36, 0x3f, 0x38, 0x33, 0x2c, 0x37, 0x32, 0x2f, 0x2b, 0x44, 0x47, 0x3f, + 0x38, 0x3a, 0x3f, 0x2e, 0x41, 0x3f, 0x3d, 0x41, 0x35, 0x48, 0x43, 0x40, + 0x33, 0x44, 0x40, 0x38, 0x47, 0x44, 0x4c, 0x3d, 0x41, 0x3b, 0x39, 0x36, + 0x3e, 0x44, 0x49, 0x48, 0x3c, 0x3b, 0x34, 0x34, 0x3f, 0x3c, 0x42, 0x52, + 0x43, 0x41, 0x3c, 0x3c, 0x3d, 0x43, 0x48, 0x54, 0x39, 0x35, 0x39, 0x3c, + 0x43, 0x3c, 0x44, 0x5f, 0x39, 0x3d, 0x38, 0x3f, 0x36, 0x3d, 0x43, 0x58, + 0x33, 0x3d, 0x43, 0x33, 0x3f, 0x36, 0x39, 0x54, 0x3a, 0x37, 0x2d, 0x46, + 0x43, 0x41, 0x47, 0x46, 0x3e, 0x42, 0x34, 0x49, 0x3a, 0x3f, 0x38, 0x50, + 0x3a, 0x3b, 0x42, 0x3a, 0x3e, 0x3c, 0x3b, 0x40, 0x42, 0x45, 0x37, 0x3b, + 0x2f, 0x3b, 0x46, 0x30, 0x42, 0x3b, 0x3b, 0x44, 0x3b, 0x3e, 0x40, 0x1e, + 0x33, 0x40, 0x40, 0x3d, 0x39, 0x3a, 0x41, 0x33, 0x45, 0x3e, 0x3c, 0x3f, + 0x3f, 0x38, 0x31, 0x46, 0x3b, 0x35, 0x42, 0x39, 0x49, 0x3e, 0x3d, 0x66, + 0x53, 0x3f, 0x44, 0x40, 0x43, 0x45, 0x48, 0x45, 0x49, 0x2d, 0x3e, 0x3a, + 0x4f, 0x5a, 0x62, 0x27, 0x54, 0x37, 0x35, 0x34, 0x42, 0x50, 0x54, 0x43, + 0x4d, 0x38, 0x39, 0x48, 0x38, 0x4c, 0x21, 0x3f, 0x40, 0x3a, 0x3a, 0x2f, + 0x37, 0x2f, 0x29, 0x2c, 0x36, 0x47, 0x3f, 0x41, 0x31, 0x33, 0x3e, 0x32, + 0x3e, 0x40, 0x42, 0x40, 0x42, 0x3a, 0x46, 0x33, 0x44, 0x40, 0x3c, 0x43, + 0x3d, 0x41, 0x4d, 0x3d, 0x3c, 0x47, 0x46, 0x43, 0x42, 0x3e, 0x44, 0x4e, + 0x41, 0x3a, 0x44, 0x38, 0x45, 0x3b, 0x49, 0x4c, 0x40, 0x3f, 0x37, 0x3e, + 0x3e, 0x46, 0x41, 0x51, 0x3f, 0x39, 0x30, 0x40, 0x3e, 0x38, 0x43, 0x5b, + 0x33, 0x3e, 0x31, 0x42, 0x3d, 0x2f, 0x49, 0x57, 0x37, 0x31, 0x46, 0x44, + 0x3e, 0x35, 0x40, 0x55, 0x36, 0x35, 0x3d, 0x3c, 0x38, 0x33, 0x42, 0x52, + 0x3b, 0x39, 0x34, 0x31, 0x45, 0x34, 0x3c, 0x51, 0x33, 0x39, 0x3c, 0x40, + 0x36, 0x36, 0x42, 0x3e, 0x37, 0x3e, 0x3b, 0x40, 0x3d, 0x36, 0x41, 0x30, + 0x42, 0x45, 0x40, 0x49, 0x3d, 0x32, 0x46, 0x26, 0x40, 0x44, 0x3a, 0x3f, + 0x3d, 0x46, 0x45, 0x31, 0x33, 0x34, 0x3e, 0x37, 0x46, 0x3b, 0x32, 0x3a, + 0x3d, 0x31, 0x3c, 0x36, 0x50, 0x41, 0x3b, 0x5d, 0x53, 0x42, 0x44, 0x37, + 0x3e, 0x4d, 0x41, 0x4b, 0x49, 0x2f, 0x35, 0x3a, 0x4e, 0x59, 0x5d, 0x27, + 0x5c, 0x30, 0x3d, 0x3a, 0x46, 0x50, 0x57, 0x4a, 0x4c, 0x36, 0x37, 0x46, + 0x48, 0x41, 0x24, 0x49, 0x36, 0x3e, 0x41, 0x45, 0x37, 0x38, 0x2e, 0x2e, + 0x34, 0x3c, 0x38, 0x41, 0x36, 0x3d, 0x43, 0x36, 0x3e, 0x3e, 0x41, 0x3b, + 0x42, 0x3c, 0x43, 0x38, 0x3e, 0x3d, 0x41, 0x48, 0x47, 0x4c, 0x45, 0x3b, + 0x37, 0x41, 0x38, 0x41, 0x3d, 0x41, 0x46, 0x4e, 0x36, 0x45, 0x38, 0x39, + 0x42, 0x42, 0x37, 0x4c, 0x34, 0x46, 0x3c, 0x44, 0x4a, 0x39, 0x45, 0x53, + 0x3c, 0x3f, 0x41, 0x35, 0x3c, 0x45, 0x4c, 0x5a, 0x44, 0x41, 0x30, 0x35, + 0x40, 0x39, 0x42, 0x5a, 0x36, 0x36, 0x3a, 0x3b, 0x43, 0x35, 0x3c, 0x56, + 0x35, 0x38, 0x2b, 0x4a, 0x3c, 0x40, 0x45, 0x54, 0x37, 0x37, 0x3a, 0x44, + 0x42, 0x3b, 0x3d, 0x4a, 0x3f, 0x37, 0x3b, 0x35, 0x34, 0x3f, 0x40, 0x48, + 0x45, 0x3e, 0x37, 0x38, 0x41, 0x41, 0x3d, 0x37, 0x43, 0x3d, 0x3d, 0x45, + 0x3a, 0x38, 0x3f, 0x23, 0x4a, 0x37, 0x42, 0x3c, 0x3f, 0x43, 0x42, 0x33, + 0x37, 0x39, 0x35, 0x3b, 0x41, 0x36, 0x2f, 0x3b, 0x41, 0x3a, 0x44, 0x3d, + 0x3e, 0x45, 0x44, 0x50, 0x47, 0x47, 0x48, 0x3c, 0x3f, 0x45, 0x43, 0x3f, + 0x4a, 0x33, 0x3c, 0x3a, 0x52, 0x52, 0x5a, 0x23, 0x58, 0x31, 0x3b, 0x3b, + 0x47, 0x44, 0x54, 0x45, 0x42, 0x38, 0x38, 0x40, 0x43, 0x3f, 0x2a, 0x46, + 0x3b, 0x46, 0x3b, 0x46, 0x35, 0x37, 0x29, 0x35, 0x38, 0x41, 0x3a, 0x31, + 0x44, 0x41, 0x39, 0x36, 0x45, 0x41, 0x40, 0x3e, 0x40, 0x44, 0x47, 0x37, + 0x3f, 0x42, 0x49, 0x34, 0x46, 0x3d, 0x4b, 0x3d, 0x42, 0x3b, 0x42, 0x3e, + 0x41, 0x3b, 0x3f, 0x43, 0x47, 0x45, 0x47, 0x41, 0x40, 0x3a, 0x3d, 0x45, + 0x40, 0x36, 0x3b, 0x3b, 0x44, 0x37, 0x46, 0x55, 0x35, 0x42, 0x3f, 0x3a, + 0x41, 0x41, 0x44, 0x5c, 0x31, 0x44, 0x3d, 0x46, 0x39, 0x38, 0x46, 0x59, + 0x41, 0x3b, 0x3d, 0x39, 0x33, 0x3e, 0x41, 0x58, 0x33, 0x44, 0x34, 0x31, + 0x48, 0x3e, 0x4d, 0x56, 0x36, 0x3c, 0x37, 0x46, 0x46, 0x38, 0x45, 0x53, + 0x35, 0x3d, 0x3a, 0x31, 0x42, 0x48, 0x45, 0x44, 0x3b, 0x3b, 0x3c, 0x41, + 0x3d, 0x42, 0x3f, 0x2f, 0x38, 0x3c, 0x3e, 0x41, 0x44, 0x3a, 0x4a, 0x24, + 0x37, 0x3e, 0x37, 0x48, 0x40, 0x3f, 0x46, 0x3c, 0x47, 0x4a, 0x38, 0x47, + 0x34, 0x45, 0x31, 0x42, 0x43, 0x44, 0x3f, 0x3f, 0x49, 0x40, 0x3c, 0x41, + 0x4d, 0x43, 0x42, 0x39, 0x39, 0x48, 0x41, 0x38, 0x47, 0x3c, 0x3c, 0x42, + 0x44, 0x55, 0x62, 0x2a, 0x5c, 0x32, 0x3a, 0x37, 0x4c, 0x44, 0x4f, 0x3e, + 0x4e, 0x42, 0x3a, 0x42, 0x41, 0x4a, 0x35, 0x44, 0x45, 0x3b, 0x43, 0x41, + 0x33, 0x38, 0x28, 0x36, 0x40, 0x47, 0x3e, 0x3e, 0x3e, 0x39, 0x3a, 0x37, + 0x44, 0x44, 0x3f, 0x3b, 0x41, 0x3c, 0x45, 0x36, 0x38, 0x3a, 0x3c, 0x42, + 0x42, 0x3f, 0x59, 0x3c, 0x47, 0x3d, 0x38, 0x3a, 0x42, 0x44, 0x41, 0x46, + 0x3f, 0x43, 0x48, 0x42, 0x44, 0x35, 0x3f, 0x45, 0x36, 0x3f, 0x38, 0x3a, + 0x44, 0x3d, 0x3d, 0x4e, 0x3e, 0x45, 0x40, 0x42, 0x3c, 0x33, 0x43, 0x5a, + 0x38, 0x3e, 0x45, 0x3a, 0x3e, 0x42, 0x45, 0x52, 0x3c, 0x42, 0x3a, 0x38, + 0x3d, 0x3b, 0x4a, 0x57, 0x38, 0x37, 0x47, 0x44, 0x3e, 0x3c, 0x38, 0x48, + 0x36, 0x41, 0x3f, 0x41, 0x3a, 0x3a, 0x46, 0x47, 0x42, 0x40, 0x32, 0x33, + 0x43, 0x37, 0x41, 0x43, 0x3e, 0x40, 0x3d, 0x3a, 0x3e, 0x38, 0x42, 0x30, + 0x3e, 0x40, 0x46, 0x42, 0x40, 0x44, 0x42, 0x23, 0x31, 0x40, 0x3f, 0x3d, + 0x3b, 0x33, 0x40, 0x33, 0x41, 0x33, 0x43, 0x41, 0x3a, 0x3e, 0x36, 0x40, + 0x40, 0x45, 0x37, 0x42, 0x46, 0x42, 0x39, 0x48, 0x44, 0x40, 0x40, 0x45, + 0x3c, 0x49, 0x41, 0x3f, 0x4c, 0x3d, 0x2f, 0x3f, 0x47, 0x52, 0x54, 0x2c, + 0x55, 0x42, 0x44, 0x3b, 0x46, 0x4f, 0x48, 0x3c, 0x45, 0x39, 0x3f, 0x4b, + 0x3f, 0x3f, 0x36, 0x42, 0x41, 0x48, 0x44, 0x44, 0x36, 0x3b, 0x37, 0x40, + 0x39, 0x49, 0x3a, 0x35, 0x3e, 0x48, 0x31, 0x30, 0x44, 0x38, 0x4c, 0x3c, + 0x41, 0x3e, 0x46, 0x32, 0x44, 0x3b, 0x42, 0x3c, 0x38, 0x3a, 0x47, 0x3f, + 0x3a, 0x42, 0x3a, 0x43, 0x40, 0x4b, 0x47, 0x3c, 0x42, 0x46, 0x45, 0x42, + 0x3c, 0x46, 0x3d, 0x3f, 0x3e, 0x36, 0x38, 0x3e, 0x46, 0x3c, 0x4d, 0x43, + 0x49, 0x41, 0x48, 0x3c, 0x3d, 0x39, 0x43, 0x58, 0x3a, 0x41, 0x3f, 0x38, + 0x37, 0x3f, 0x46, 0x5d, 0x3c, 0x3c, 0x39, 0x36, 0x3d, 0x46, 0x43, 0x50, + 0x3a, 0x47, 0x39, 0x36, 0x41, 0x3f, 0x3e, 0x51, 0x31, 0x36, 0x3e, 0x3c, + 0x3c, 0x3a, 0x48, 0x41, 0x3a, 0x43, 0x49, 0x3e, 0x42, 0x46, 0x3f, 0x41, + 0x49, 0x33, 0x42, 0x41, 0x45, 0x40, 0x3d, 0x2b, 0x3d, 0x38, 0x40, 0x37, + 0x3a, 0x31, 0x45, 0x26, 0x33, 0x3d, 0x3f, 0x39, 0x36, 0x3c, 0x38, 0x33, + 0x34, 0x3f, 0x35, 0x44, 0x3a, 0x39, 0x32, 0x41, 0x35, 0x40, 0x3c, 0x3b, + 0x4a, 0x3f, 0x3e, 0x3e, 0x4a, 0x3e, 0x42, 0x35, 0x38, 0x43, 0x3c, 0x37, + 0x3d, 0x3c, 0x39, 0x43, 0x3f, 0x4e, 0x54, 0x33, 0x4b, 0x37, 0x43, 0x3b, + 0x43, 0x48, 0x43, 0x42, 0x3d, 0x46, 0x45, 0x49, 0x3a, 0x39, 0x36, 0x4a, + 0x48, 0x48, 0x37, 0x4b, 0x42, 0x47, 0x34, 0x34, 0x43, 0x42, 0x3a, 0x3d, + 0x3c, 0x46, 0x34, 0x39, 0x40, 0x3b, 0x3e, 0x3e, 0x37, 0x3d, 0x53, 0x3b, + 0x48, 0x3c, 0x43, 0x44, 0x3b, 0x3f, 0x57, 0x3d, 0x39, 0x3c, 0x39, 0x3a, + 0x3e, 0x3f, 0x43, 0x3e, 0x41, 0x47, 0x3c, 0x41, 0x40, 0x41, 0x37, 0x3f, + 0x3b, 0x43, 0x35, 0x3e, 0x45, 0x40, 0x47, 0x59, 0x41, 0x49, 0x3b, 0x3f, + 0x47, 0x49, 0x4b, 0x61, 0x39, 0x48, 0x39, 0x3e, 0x44, 0x34, 0x3b, 0x59, + 0x3c, 0x42, 0x45, 0x35, 0x42, 0x41, 0x39, 0x52, 0x42, 0x3c, 0x3d, 0x3e, + 0x3d, 0x4a, 0x4a, 0x4d, 0x3c, 0x34, 0x44, 0x3c, 0x41, 0x34, 0x38, 0x46, + 0x38, 0x45, 0x40, 0x45, 0x40, 0x3a, 0x3d, 0x44, 0x3a, 0x37, 0x3a, 0x3a, + 0x3b, 0x42, 0x40, 0x34, 0x3b, 0x3c, 0x42, 0x40, 0x3d, 0x32, 0x40, 0x27, + 0x37, 0x39, 0x37, 0x46, 0x48, 0x31, 0x40, 0x30, 0x42, 0x42, 0x3a, 0x40, + 0x3d, 0x37, 0x2a, 0x40, 0x41, 0x37, 0x3c, 0x4a, 0x46, 0x45, 0x3d, 0x34, + 0x48, 0x41, 0x42, 0x3e, 0x3f, 0x39, 0x3c, 0x3a, 0x4f, 0x3b, 0x32, 0x3e, + 0x43, 0x51, 0x4f, 0x2a, 0x46, 0x3a, 0x3d, 0x3b, 0x40, 0x3d, 0x4c, 0x3c, + 0x48, 0x40, 0x36, 0x4a, 0x3a, 0x38, 0x42, 0x43, 0x4c, 0x3d, 0x47, 0x47, + 0x33, 0x3f, 0x2d, 0x37, 0x4a, 0x43, 0x38, 0x3e, 0x49, 0x42, 0x42, 0x3d, + 0x43, 0x47, 0x41, 0x38, 0x46, 0x37, 0x46, 0x38, 0x47, 0x42, 0x49, 0x3d, + 0x3b, 0x37, 0x4c, 0x3c, 0x3a, 0x45, 0x3f, 0x37, 0x36, 0x3d, 0x3c, 0x40, + 0x3e, 0x45, 0x46, 0x41, 0x41, 0x40, 0x3c, 0x44, 0x47, 0x43, 0x37, 0x3f, + 0x3e, 0x3a, 0x3a, 0x4b, 0x3a, 0x36, 0x3d, 0x3f, 0x38, 0x3f, 0x3c, 0x58, + 0x40, 0x49, 0x3d, 0x42, 0x38, 0x3a, 0x47, 0x50, 0x3b, 0x49, 0x40, 0x44, + 0x3e, 0x3c, 0x38, 0x52, 0x3a, 0x3e, 0x44, 0x3c, 0x35, 0x44, 0x3a, 0x47, + 0x3e, 0x49, 0x3f, 0x47, 0x45, 0x39, 0x3b, 0x46, 0x44, 0x3e, 0x41, 0x46, + 0x40, 0x41, 0x40, 0x40, 0x3a, 0x35, 0x3e, 0x36, 0x3e, 0x3e, 0x3d, 0x35, + 0x3b, 0x3c, 0x38, 0x46, 0x3b, 0x3c, 0x41, 0x2c, 0x3f, 0x42, 0x38, 0x3b, + 0x36, 0x3b, 0x39, 0x40, 0x40, 0x38, 0x36, 0x33, 0x34, 0x42, 0x2f, 0x44, + 0x41, 0x40, 0x39, 0x35, 0x3b, 0x44, 0x42, 0x2c, 0x41, 0x3b, 0x44, 0x41, + 0x35, 0x44, 0x3b, 0x34, 0x44, 0x49, 0x36, 0x39, 0x3a, 0x52, 0x4d, 0x2b, + 0x40, 0x40, 0x3e, 0x39, 0x48, 0x42, 0x3c, 0x44, 0x46, 0x49, 0x3f, 0x54, + 0x43, 0x40, 0x2e, 0x40, 0x4f, 0x36, 0x3e, 0x3f, 0x38, 0x48, 0x44, 0x3c, + 0x44, 0x43, 0x41, 0x47, 0x40, 0x46, 0x40, 0x37, 0x41, 0x34, 0x3a, 0x41, + 0x41, 0x3b, 0x49, 0x39, 0x42, 0x38, 0x3d, 0x39, 0x34, 0x35, 0x43, 0x36, + 0x3e, 0x44, 0x3f, 0x40, 0x43, 0x40, 0x40, 0x3a, 0x47, 0x42, 0x3e, 0x42, + 0x46, 0x35, 0x3a, 0x46, 0x3c, 0x3c, 0x3c, 0x3d, 0x3f, 0x40, 0x43, 0x4c, + 0x3a, 0x37, 0x3f, 0x43, 0x47, 0x38, 0x42, 0x58, 0x42, 0x3b, 0x34, 0x37, + 0x3e, 0x48, 0x3c, 0x57, 0x44, 0x3c, 0x3d, 0x3a, 0x36, 0x48, 0x3c, 0x51, + 0x3d, 0x48, 0x45, 0x45, 0x38, 0x45, 0x40, 0x3f, 0x3b, 0x35, 0x3d, 0x3f, + 0x38, 0x47, 0x39, 0x3b, 0x36, 0x49, 0x43, 0x40, 0x3f, 0x46, 0x38, 0x40, + 0x3f, 0x3e, 0x39, 0x32, 0x47, 0x42, 0x35, 0x33, 0x39, 0x47, 0x3c, 0x36, + 0x3b, 0x37, 0x43, 0x35, 0x3b, 0x3b, 0x34, 0x3b, 0x38, 0x3d, 0x3e, 0x3a, + 0x35, 0x49, 0x38, 0x40, 0x3f, 0x3f, 0x3e, 0x37, 0x43, 0x3b, 0x3e, 0x3e, + 0x3b, 0x40, 0x44, 0x39, 0x3d, 0x3f, 0x31, 0x42, 0x42, 0x3b, 0x41, 0x3d, + 0x3e, 0x3c, 0x37, 0x34, 0x48, 0x3d, 0x49, 0x4a, 0x47, 0x36, 0x3a, 0x34, + 0x37, 0x36, 0x3e, 0x38, 0x33, 0x45, 0x39, 0x44, 0x34, 0x49, 0x3a, 0x3d, + 0x34, 0x31, 0x31, 0x3d, 0x34, 0x3d, 0x41, 0x3e, 0x49, 0x41, 0x34, 0x3f, + 0x3a, 0x42, 0x3e, 0x40, 0x3f, 0x33, 0x46, 0x3f, 0x34, 0x39, 0x37, 0x46, + 0x3e, 0x32, 0x3f, 0x45, 0x45, 0x41, 0x3b, 0x4b, 0x35, 0x35, 0x3b, 0x4a, + 0x3d, 0x43, 0x3b, 0x44, 0x3c, 0x38, 0x31, 0x43, 0x39, 0x35, 0x41, 0x45, + 0x37, 0x3e, 0x43, 0x47, 0x39, 0x40, 0x41, 0x41, 0x40, 0x32, 0x37, 0x3e, + 0x3d, 0x39, 0x3b, 0x49, 0x33, 0x35, 0x38, 0x41, 0x45, 0x37, 0x3c, 0x49, + 0x3b, 0x34, 0x34, 0x41, 0x3a, 0x3f, 0x3e, 0x47, 0x39, 0x3c, 0x34, 0x3a, + 0x38, 0x44, 0x40, 0x51, 0x3a, 0x37, 0x3b, 0x3f, 0x3d, 0x3a, 0x45, 0x48, + 0x3f, 0x46, 0x35, 0x43, 0x38, 0x43, 0x35, 0x4c, 0x42, 0x47, 0x44, 0x3d, + 0x40, 0x3a, 0x39, 0x4e, 0x3d, 0x37, 0x3c, 0x42, 0x40, 0x48, 0x44, 0x4c, + 0x31, 0x40, 0x42, 0x3b, 0x45, 0x45, 0x3f, 0x3e, 0x3d, 0x44, 0x3f, 0x31, + 0x3f, 0x44, 0x45, 0x37, 0x3e, 0x3d, 0x35, 0x3b, 0x2d, 0x44, 0x4a, 0x3a, + 0x2b, 0x37, 0x38, 0x46, 0x41, 0x39, 0x3c, 0x3c, 0x46, 0x33, 0x36, 0x3c, + 0x4b, 0x34, 0x49, 0x50, 0x30, 0x3c, 0x33, 0x41, 0x44, 0x33, 0x43, 0x39, + 0x36, 0x45, 0x33, 0x3b, 0x3d, 0x36, 0x47, 0x30, 0x42, 0x37, 0x49, 0x3e, + 0x3b, 0x49, 0x3d, 0x3b, 0x3a, 0x41, 0x38, 0x44, 0x42, 0x3b, 0x3f, 0x40, + 0x46, 0x35, 0x38, 0x3c, 0x48, 0x3a, 0x46, 0x41, 0x36, 0x36, 0x41, 0x3e, + 0x43, 0x3e, 0x32, 0x39, 0x3a, 0x41, 0x30, 0x3e, 0x40, 0x3e, 0x36, 0x3a, + 0x45, 0x45, 0x3a, 0x3c, 0x31, 0x3b, 0x47, 0x3f, 0x36, 0x3a, 0x3c, 0x41, + 0x3b, 0x41, 0x39, 0x46, 0x3f, 0x3c, 0x34, 0x3e, 0x41, 0x45, 0x41, 0x42, + 0x39, 0x40, 0x40, 0x44, 0x45, 0x42, 0x34, 0x3f, 0x3e, 0x31, 0x3b, 0x41, + 0x33, 0x43, 0x37, 0x44, 0x44, 0x3a, 0x36, 0x36, 0x48, 0x3c, 0x37, 0x47, + 0x39, 0x3e, 0x3e, 0x3c, 0x3c, 0x41, 0x3c, 0x44, 0x3b, 0x42, 0x3f, 0x3a, + 0x43, 0x3b, 0x3e, 0x48, 0x36, 0x3f, 0x3d, 0x34, 0x40, 0x43, 0x35, 0x4f, + 0x34, 0x39, 0x3b, 0x41, 0x40, 0x39, 0x37, 0x4c, 0x39, 0x36, 0x39, 0x39, + 0x47, 0x41, 0x43, 0x3f, 0x3f, 0x33, 0x42, 0x3f, 0x42, 0x40, 0x37, 0x40, + 0x3f, 0x34, 0x45, 0x3d, 0x2d, 0x3c, 0x44, 0x3b, 0x43, 0x37, 0x26, 0x50, + 0x43, 0x44, 0x3d, 0x43, 0x42, 0x2d, 0x3c, 0x33, 0x4a, 0x32, 0x4a, 0x53, + 0x33, 0x38, 0x27, 0x36, 0x42, 0x30, 0x47, 0x3d, 0x36, 0x45, 0x46, 0x36, + 0x3b, 0x3b, 0x40, 0x33, 0x37, 0x36, 0x44, 0x46, 0x3d, 0x35, 0x40, 0x38, + 0x3b, 0x40, 0x36, 0x3c, 0x3d, 0x37, 0x31, 0x41, 0x33, 0x3c, 0x38, 0x3f, + 0x43, 0x3a, 0x40, 0x49, 0x38, 0x39, 0x38, 0x3d, 0x43, 0x3d, 0x39, 0x3b, + 0x3d, 0x3f, 0x38, 0x42, 0x34, 0x43, 0x33, 0x3e, 0x43, 0x3e, 0x40, 0x42, + 0x3b, 0x45, 0x37, 0x44, 0x43, 0x39, 0x3c, 0x3d, 0x37, 0x44, 0x3a, 0x3b, + 0x47, 0x3f, 0x3a, 0x3c, 0x3a, 0x3b, 0x3f, 0x43, 0x3e, 0x3d, 0x46, 0x3e, + 0x37, 0x36, 0x3f, 0x40, 0x42, 0x42, 0x37, 0x36, 0x48, 0x35, 0x44, 0x44, + 0x39, 0x3c, 0x3b, 0x41, 0x44, 0x49, 0x3a, 0x40, 0x41, 0x36, 0x33, 0x3a, + 0x3c, 0x3d, 0x40, 0x3f, 0x43, 0x36, 0x3c, 0x3a, 0x3f, 0x4b, 0x32, 0x49, + 0x49, 0x3e, 0x3a, 0x3e, 0x3f, 0x41, 0x3c, 0x47, 0x40, 0x41, 0x45, 0x3e, + 0x47, 0x47, 0x3f, 0x47, 0x45, 0x3e, 0x31, 0x43, 0x4a, 0x44, 0x36, 0x40, + 0x41, 0x47, 0x3e, 0x42, 0x37, 0x40, 0x3b, 0x46, 0x37, 0x41, 0x3e, 0x3c, + 0x27, 0x40, 0x49, 0x42, 0x42, 0x39, 0x30, 0x49, 0x43, 0x38, 0x3d, 0x42, + 0x43, 0x2f, 0x3b, 0x37, 0x4b, 0x2d, 0x4f, 0x52, 0x30, 0x31, 0x2f, 0x3a, + 0x49, 0x38, 0x4f, 0x45, 0x2e, 0x47, 0x3a, 0x32, 0x33, 0x3f, 0x4a, 0x2e, + 0x33, 0x3b, 0x3e, 0x3e, 0x49, 0x45, 0x44, 0x38, 0x3c, 0x35, 0x45, 0x47, + 0x41, 0x3b, 0x3c, 0x48, 0x46, 0x39, 0x39, 0x3b, 0x3f, 0x41, 0x38, 0x42, + 0x3d, 0x46, 0x33, 0x41, 0x36, 0x3f, 0x3f, 0x3c, 0x33, 0x3e, 0x3e, 0x40, + 0x44, 0x40, 0x3c, 0x38, 0x46, 0x3a, 0x40, 0x36, 0x42, 0x35, 0x3f, 0x3b, + 0x3b, 0x43, 0x3c, 0x40, 0x40, 0x49, 0x2e, 0x39, 0x40, 0x3f, 0x45, 0x41, + 0x3f, 0x30, 0x42, 0x3d, 0x40, 0x3c, 0x3a, 0x3b, 0x3b, 0x40, 0x39, 0x42, + 0x3a, 0x3f, 0x3f, 0x3e, 0x35, 0x3b, 0x38, 0x45, 0x47, 0x35, 0x44, 0x3e, + 0x3b, 0x3f, 0x3f, 0x40, 0x3a, 0x35, 0x30, 0x49, 0x45, 0x35, 0x3b, 0x39, + 0x3b, 0x48, 0x3f, 0x37, 0x39, 0x40, 0x43, 0x45, 0x3d, 0x40, 0x41, 0x3a, + 0x33, 0x3d, 0x3a, 0x4b, 0x40, 0x42, 0x40, 0x42, 0x43, 0x39, 0x3c, 0x49, + 0x3e, 0x47, 0x3e, 0x44, 0x3f, 0x3a, 0x40, 0x41, 0x3f, 0x42, 0x42, 0x37, + 0x3e, 0x3b, 0x36, 0x3e, 0x3b, 0x3c, 0x48, 0x43, 0x2d, 0x46, 0x4a, 0x38, + 0x45, 0x3a, 0x29, 0x46, 0x40, 0x3c, 0x40, 0x44, 0x40, 0x33, 0x2f, 0x33, + 0x48, 0x2e, 0x51, 0x4f, 0x2b, 0x32, 0x2e, 0x2d, 0x45, 0x33, 0x4d, 0x41, + 0x29, 0x4b, 0x41, 0x39, 0x2f, 0x3a, 0x49, 0x31, 0x37, 0x40, 0x47, 0x4c, + 0x3e, 0x31, 0x41, 0x3f, 0x43, 0x37, 0x45, 0x4f, 0x41, 0x3c, 0x30, 0x4a, + 0x37, 0x37, 0x36, 0x39, 0x31, 0x3d, 0x36, 0x4b, 0x37, 0x44, 0x3c, 0x43, + 0x44, 0x36, 0x3f, 0x3b, 0x34, 0x3e, 0x3a, 0x35, 0x38, 0x3f, 0x33, 0x37, + 0x3b, 0x3d, 0x46, 0x38, 0x3b, 0x37, 0x38, 0x3b, 0x31, 0x3e, 0x3d, 0x3b, + 0x3d, 0x39, 0x35, 0x33, 0x33, 0x3c, 0x39, 0x39, 0x48, 0x39, 0x39, 0x3f, + 0x3e, 0x36, 0x47, 0x3a, 0x44, 0x40, 0x32, 0x3c, 0x37, 0x35, 0x40, 0x3f, + 0x3a, 0x38, 0x3b, 0x3d, 0x46, 0x45, 0x36, 0x43, 0x40, 0x3d, 0x41, 0x41, + 0x47, 0x3a, 0x3d, 0x3e, 0x43, 0x42, 0x32, 0x36, 0x41, 0x37, 0x3b, 0x35, + 0x36, 0x44, 0x36, 0x3c, 0x43, 0x32, 0x3e, 0x3e, 0x42, 0x45, 0x32, 0x3c, + 0x3a, 0x3b, 0x35, 0x43, 0x41, 0x3d, 0x44, 0x50, 0x43, 0x31, 0x3e, 0x44, + 0x44, 0x41, 0x3a, 0x44, 0x36, 0x39, 0x3b, 0x3c, 0x32, 0x38, 0x3b, 0x45, + 0x38, 0x43, 0x40, 0x42, 0x33, 0x3e, 0x4a, 0x42, 0x45, 0x39, 0x2f, 0x42, + 0x39, 0x35, 0x44, 0x3e, 0x39, 0x2f, 0x34, 0x33, 0x49, 0x29, 0x50, 0x4f, + 0x2b, 0x36, 0x34, 0x2d, 0x47, 0x33, 0x49, 0x3c, 0x33, 0x51, 0x49, 0x3f, + 0x34, 0x39, 0x4a, 0x2c, 0x34, 0x45, 0x4f, 0x47, 0x34, 0x42, 0x3a, 0x3d, + 0x36, 0x4a, 0x3b, 0x43, 0x36, 0x3f, 0x39, 0x4b, 0x38, 0x3a, 0x31, 0x3d, + 0x32, 0x42, 0x3a, 0x47, 0x48, 0x3e, 0x44, 0x3f, 0x39, 0x3e, 0x44, 0x35, + 0x41, 0x3c, 0x45, 0x3a, 0x3e, 0x3b, 0x3d, 0x2f, 0x37, 0x40, 0x3e, 0x43, + 0x39, 0x39, 0x33, 0x3b, 0x37, 0x3b, 0x37, 0x37, 0x37, 0x39, 0x36, 0x31, + 0x39, 0x3b, 0x41, 0x39, 0x3b, 0x40, 0x36, 0x37, 0x42, 0x39, 0x3a, 0x46, + 0x3f, 0x30, 0x38, 0x39, 0x35, 0x32, 0x3e, 0x3a, 0x43, 0x43, 0x3e, 0x33, + 0x42, 0x3f, 0x41, 0x3c, 0x46, 0x34, 0x34, 0x40, 0x43, 0x37, 0x32, 0x43, + 0x3c, 0x37, 0x36, 0x33, 0x3d, 0x36, 0x3a, 0x40, 0x39, 0x38, 0x32, 0x3e, + 0x32, 0x3d, 0x37, 0x49, 0x42, 0x47, 0x41, 0x3b, 0x3d, 0x3c, 0x3a, 0x37, + 0x3c, 0x45, 0x3a, 0x45, 0x36, 0x44, 0x3a, 0x3a, 0x3a, 0x3c, 0x43, 0x3b, + 0x3b, 0x35, 0x38, 0x47, 0x36, 0x40, 0x32, 0x43, 0x3e, 0x39, 0x42, 0x40, + 0x2c, 0x3c, 0x4c, 0x4c, 0x43, 0x3b, 0x37, 0x4a, 0x3f, 0x3c, 0x45, 0x44, + 0x3f, 0x30, 0x36, 0x31, 0x4f, 0x2f, 0x5d, 0x4b, 0x34, 0x34, 0x2d, 0x2b, + 0x44, 0x31, 0x4e, 0x40, 0x2e, 0x4d, 0x48, 0x3e, 0x37, 0x2b, 0x49, 0x25, + 0x31, 0x49, 0x44, 0x49, 0x39, 0x39, 0x4b, 0x3a, 0x3a, 0x41, 0x3e, 0x42, + 0x3c, 0x36, 0x36, 0x4a, 0x32, 0x44, 0x3e, 0x48, 0x3e, 0x3c, 0x37, 0x49, + 0x3d, 0x34, 0x3f, 0x37, 0x33, 0x36, 0x46, 0x3a, 0x3a, 0x31, 0x45, 0x3f, + 0x3a, 0x31, 0x3b, 0x33, 0x41, 0x42, 0x35, 0x39, 0x38, 0x44, 0x36, 0x3a, + 0x3f, 0x3b, 0x37, 0x3e, 0x3b, 0x38, 0x2f, 0x32, 0x44, 0x3d, 0x44, 0x41, + 0x39, 0x36, 0x3a, 0x34, 0x39, 0x38, 0x34, 0x3f, 0x3b, 0x37, 0x34, 0x34, + 0x40, 0x3d, 0x34, 0x3a, 0x46, 0x42, 0x3f, 0x34, 0x38, 0x33, 0x39, 0x44, + 0x3f, 0x41, 0x3c, 0x31, 0x40, 0x32, 0x3f, 0x37, 0x37, 0x41, 0x3e, 0x35, + 0x37, 0x48, 0x3b, 0x41, 0x3d, 0x3a, 0x3f, 0x35, 0x33, 0x3c, 0x36, 0x3b, + 0x3a, 0x48, 0x33, 0x42, 0x37, 0x33, 0x39, 0x41, 0x3c, 0x3d, 0x3b, 0x4d, + 0x39, 0x3a, 0x3e, 0x44, 0x3d, 0x41, 0x3b, 0x38, 0x49, 0x41, 0x3a, 0x38, + 0x34, 0x38, 0x38, 0x3c, 0x45, 0x3c, 0x37, 0x3b, 0x36, 0x3e, 0x4a, 0x4b, + 0x42, 0x3f, 0x32, 0x45, 0x46, 0x35, 0x46, 0x41, 0x38, 0x33, 0x39, 0x37, + 0x44, 0x2b, 0x60, 0x4a, 0x2a, 0x2e, 0x35, 0x2d, 0x43, 0x37, 0x51, 0x47, + 0x2f, 0x4d, 0x50, 0x3e, 0x3a, 0x33, 0x4f, 0x2a, 0x35, 0x45, 0x4a, 0x4c, + 0x3b, 0x3d, 0x43, 0x44, 0x3d, 0x3f, 0x4a, 0x3e, 0x49, 0x37, 0x2e, 0x4f, + 0x39, 0x3f, 0x32, 0x3c, 0x37, 0x3b, 0x39, 0x4d, 0x34, 0x3f, 0x46, 0x44, + 0x3d, 0x40, 0x3f, 0x40, 0x39, 0x33, 0x39, 0x3e, 0x3d, 0x40, 0x31, 0x30, + 0x35, 0x3d, 0x3e, 0x3a, 0x3e, 0x32, 0x31, 0x3e, 0x48, 0x3c, 0x40, 0x43, + 0x3f, 0x3f, 0x34, 0x2e, 0x3a, 0x3e, 0x3b, 0x43, 0x45, 0x32, 0x3a, 0x31, + 0x37, 0x38, 0x31, 0x35, 0x34, 0x3d, 0x42, 0x36, 0x46, 0x37, 0x32, 0x47, + 0x41, 0x3c, 0x35, 0x35, 0x36, 0x41, 0x3a, 0x3b, 0x42, 0x44, 0x36, 0x31, + 0x3c, 0x3d, 0x34, 0x34, 0x3b, 0x40, 0x40, 0x2e, 0x40, 0x46, 0x3b, 0x43, + 0x3f, 0x40, 0x3b, 0x3a, 0x32, 0x40, 0x46, 0x39, 0x3c, 0x49, 0x2f, 0x3d, + 0x49, 0x3e, 0x44, 0x3c, 0x3e, 0x35, 0x3f, 0x44, 0x41, 0x40, 0x3e, 0x47, + 0x3d, 0x40, 0x3f, 0x41, 0x3b, 0x41, 0x41, 0x3f, 0x40, 0x3f, 0x3e, 0x3e, + 0x3f, 0x43, 0x35, 0x40, 0x2b, 0x42, 0x45, 0x56, 0x40, 0x3c, 0x2f, 0x44, + 0x44, 0x3d, 0x3e, 0x3d, 0x40, 0x2d, 0x39, 0x31, 0x54, 0x2f, 0x61, 0x48, + 0x2e, 0x37, 0x37, 0x32, 0x3e, 0x2d, 0x52, 0x4d, 0x2d, 0x4d, 0x4c, 0x3a, + 0x3a, 0x31, 0x4e, 0x2d, 0x31, 0x48, 0x47, 0x54, 0x45, 0x38, 0x3b, 0x3d, + 0x42, 0x41, 0x44, 0x4a, 0x48, 0x42, 0x2f, 0x4d, 0x31, 0x34, 0x3a, 0x46, + 0x37, 0x44, 0x2c, 0x45, 0x46, 0x43, 0x40, 0x3f, 0x34, 0x33, 0x40, 0x39, + 0x32, 0x35, 0x3a, 0x40, 0x3f, 0x3f, 0x36, 0x32, 0x3f, 0x3d, 0x35, 0x48, + 0x3c, 0x48, 0x37, 0x39, 0x35, 0x3f, 0x37, 0x3d, 0x44, 0x46, 0x2d, 0x2a, + 0x47, 0x38, 0x3a, 0x39, 0x45, 0x3b, 0x40, 0x2d, 0x37, 0x33, 0x41, 0x3c, + 0x40, 0x35, 0x3f, 0x32, 0x3a, 0x36, 0x40, 0x41, 0x3a, 0x3c, 0x33, 0x31, + 0x42, 0x3f, 0x41, 0x3a, 0x41, 0x46, 0x38, 0x2f, 0x3c, 0x3d, 0x3d, 0x39, + 0x3b, 0x46, 0x41, 0x31, 0x46, 0x36, 0x40, 0x48, 0x3c, 0x33, 0x42, 0x32, + 0x3b, 0x40, 0x3f, 0x36, 0x37, 0x44, 0x34, 0x35, 0x32, 0x32, 0x37, 0x38, + 0x33, 0x3b, 0x37, 0x4a, 0x3f, 0x46, 0x3a, 0x41, 0x32, 0x37, 0x30, 0x3e, + 0x40, 0x35, 0x41, 0x40, 0x37, 0x41, 0x2b, 0x40, 0x3d, 0x3d, 0x32, 0x38, + 0x34, 0x3e, 0x47, 0x61, 0x43, 0x3b, 0x3c, 0x42, 0x46, 0x3d, 0x40, 0x4a, + 0x3c, 0x2d, 0x33, 0x35, 0x55, 0x38, 0x69, 0x4f, 0x33, 0x37, 0x30, 0x39, + 0x44, 0x2e, 0x58, 0x4b, 0x2a, 0x51, 0x4b, 0x3c, 0x39, 0x2e, 0x51, 0x2d, + 0x30, 0x4a, 0x42, 0x53, 0x3f, 0x39, 0x3e, 0x44, 0x3b, 0x40, 0x47, 0x44, + 0x47, 0x3e, 0x39, 0x4b, 0x40, 0x3d, 0x42, 0x39, 0x3b, 0x39, 0x32, 0x42, + 0x36, 0x36, 0x36, 0x42, 0x44, 0x34, 0x33, 0x40, 0x40, 0x40, 0x3a, 0x3a, + 0x41, 0x3f, 0x31, 0x30, 0x3f, 0x31, 0x30, 0x39, 0x46, 0x36, 0x35, 0x34, + 0x40, 0x43, 0x3c, 0x41, 0x31, 0x46, 0x35, 0x26, 0x44, 0x32, 0x3d, 0x35, + 0x3d, 0x3c, 0x36, 0x32, 0x39, 0x3a, 0x30, 0x40, 0x48, 0x3e, 0x38, 0x37, + 0x44, 0x3b, 0x3d, 0x42, 0x3d, 0x3c, 0x32, 0x2b, 0x3f, 0x41, 0x39, 0x3d, + 0x3e, 0x3f, 0x35, 0x2f, 0x46, 0x3d, 0x3d, 0x3b, 0x45, 0x37, 0x31, 0x35, + 0x44, 0x40, 0x3a, 0x45, 0x3a, 0x3c, 0x39, 0x31, 0x3b, 0x3d, 0x3b, 0x3a, + 0x43, 0x44, 0x39, 0x47, 0x44, 0x36, 0x3e, 0x39, 0x48, 0x3f, 0x39, 0x4b, + 0x3c, 0x36, 0x3d, 0x44, 0x44, 0x3f, 0x39, 0x43, 0x3f, 0x37, 0x3f, 0x37, + 0x3b, 0x3b, 0x38, 0x3b, 0x3f, 0x40, 0x31, 0x44, 0x30, 0x44, 0x46, 0x5b, + 0x46, 0x3f, 0x39, 0x40, 0x40, 0x37, 0x4a, 0x46, 0x3f, 0x36, 0x40, 0x39, + 0x59, 0x3e, 0x66, 0x57, 0x32, 0x34, 0x2e, 0x33, 0x46, 0x31, 0x58, 0x44, + 0x26, 0x4c, 0x4b, 0x3c, 0x39, 0x2e, 0x4d, 0x35, 0x32, 0x46, 0x52, 0x52, + 0x3e, 0x40, 0x39, 0x3c, 0x39, 0x3d, 0x53, 0x48, 0x41, 0x3c, 0x3b, 0x4d, + 0x3c, 0x3e, 0x38, 0x44, 0x3a, 0x3a, 0x29, 0x4a, 0x3c, 0x37, 0x36, 0x38, + 0x3a, 0x31, 0x37, 0x39, 0x3a, 0x40, 0x46, 0x32, 0x42, 0x38, 0x32, 0x2e, + 0x3a, 0x45, 0x44, 0x34, 0x34, 0x38, 0x32, 0x2e, 0x35, 0x40, 0x3a, 0x41, + 0x42, 0x3d, 0x37, 0x2c, 0x3f, 0x37, 0x3c, 0x3d, 0x3a, 0x36, 0x33, 0x35, + 0x3c, 0x34, 0x3c, 0x39, 0x3c, 0x3a, 0x37, 0x30, 0x30, 0x3e, 0x3d, 0x3a, + 0x44, 0x37, 0x36, 0x32, 0x36, 0x37, 0x36, 0x3a, 0x3c, 0x41, 0x3a, 0x35, + 0x36, 0x3a, 0x34, 0x40, 0x39, 0x40, 0x3e, 0x32, 0x34, 0x46, 0x33, 0x3f, + 0x36, 0x45, 0x3e, 0x35, 0x3f, 0x38, 0x3f, 0x3e, 0x3b, 0x3a, 0x36, 0x3b, + 0x36, 0x38, 0x32, 0x3f, 0x44, 0x3c, 0x35, 0x48, 0x38, 0x39, 0x31, 0x49, + 0x3d, 0x43, 0x36, 0x3f, 0x31, 0x43, 0x36, 0x3e, 0x3e, 0x41, 0x39, 0x3b, + 0x40, 0x42, 0x3c, 0x43, 0x36, 0x4a, 0x48, 0x67, 0x4e, 0x43, 0x36, 0x46, + 0x44, 0x3f, 0x4b, 0x4b, 0x3f, 0x38, 0x3c, 0x3c, 0x5e, 0x38, 0x70, 0x52, + 0x38, 0x32, 0x3b, 0x36, 0x4a, 0x2c, 0x52, 0x46, 0x29, 0x4f, 0x48, 0x42, + 0x2d, 0x2e, 0x4f, 0x28, 0x28, 0x45, 0x4d, 0x52, 0x42, 0x3e, 0x3f, 0x41, + 0x3c, 0x3a, 0x47, 0x50, 0x44, 0x45, 0x33, 0x4b, 0x3e, 0x3f, 0x42, 0x3d, + 0x43, 0x34, 0x27, 0x3f, 0x42, 0x3e, 0x43, 0x3e, 0x3a, 0x3c, 0x37, 0x3b, + 0x3f, 0x30, 0x3a, 0x3e, 0x3c, 0x34, 0x37, 0x24, 0x3d, 0x43, 0x40, 0x44, + 0x40, 0x46, 0x31, 0x2f, 0x43, 0x38, 0x38, 0x39, 0x3c, 0x34, 0x2d, 0x2a, + 0x38, 0x31, 0x43, 0x3b, 0x39, 0x3b, 0x32, 0x34, 0x3e, 0x39, 0x41, 0x3b, + 0x3e, 0x33, 0x3a, 0x2a, 0x41, 0x3f, 0x3c, 0x43, 0x3b, 0x3e, 0x35, 0x2c, + 0x38, 0x41, 0x33, 0x31, 0x3e, 0x3f, 0x3a, 0x3c, 0x3b, 0x35, 0x3f, 0x3d, + 0x42, 0x3a, 0x3c, 0x35, 0x3f, 0x40, 0x3c, 0x3e, 0x37, 0x41, 0x3d, 0x38, + 0x34, 0x31, 0x36, 0x3d, 0x3d, 0x47, 0x36, 0x44, 0x3f, 0x45, 0x3c, 0x3c, + 0x35, 0x36, 0x31, 0x4f, 0x46, 0x3a, 0x41, 0x42, 0x40, 0x32, 0x33, 0x41, + 0x34, 0x40, 0x3d, 0x43, 0x3b, 0x3a, 0x32, 0x3c, 0x42, 0x42, 0x3d, 0x43, + 0x37, 0x45, 0x45, 0xff, 0x4b, 0x45, 0x3b, 0x40, 0x43, 0x3e, 0x47, 0x49, + 0x3d, 0x3b, 0x3e, 0x33, 0x58, 0x35, 0x71, 0x54, 0x2f, 0x38, 0x38, 0x33, + 0x47, 0x35, 0x5b, 0x46, 0x2c, 0x4c, 0x43, 0x37, 0x36, 0x39, 0x4f, 0x30, + 0x26, 0x48, 0x51, 0x48, 0x46, 0x45, 0x3b, 0x39, 0x42, 0x50, 0x47, 0x4c, + 0x4b, 0x3b, 0x3d, 0x4d, 0x41, 0x34, 0x40, 0x44, 0x38, 0x32, 0x2d, 0x43, + 0x39, 0x36, 0x3b, 0x3b, 0x40, 0x3d, 0x37, 0x3c, 0x44, 0x39, 0x42, 0x37, + 0x38, 0x38, 0x32, 0x2f, 0x41, 0x40, 0x3f, 0x3a, 0x37, 0x35, 0x3b, 0x2a, + 0x37, 0x30, 0x3c, 0x37, 0x40, 0x38, 0x3a, 0x27, 0x44, 0x3d, 0x43, 0x40, + 0x35, 0x3f, 0x3e, 0x32, 0x3e, 0x3c, 0x40, 0x39, 0x39, 0x3a, 0x41, 0x31, + 0x3b, 0x3f, 0x34, 0x43, 0x3a, 0x38, 0x42, 0x2a, 0x47, 0x46, 0x3b, 0x38, + 0x47, 0x45, 0x39, 0x31, 0x43, 0x40, 0x37, 0x3a, 0x3d, 0x3e, 0x39, 0x30, + 0x36, 0x37, 0x3a, 0x43, 0x3f, 0x32, 0x31, 0x41, 0x45, 0x3e, 0x43, 0x38, + 0x3f, 0x37, 0x3c, 0x49, 0x3b, 0x33, 0x3d, 0x3a, 0x37, 0x44, 0x32, 0x50, + 0x39, 0x44, 0x3e, 0x3f, 0x3d, 0x41, 0x3e, 0x3e, 0x42, 0x44, 0x45, 0x3f, + 0x36, 0x3f, 0x37, 0x39, 0x3b, 0x3d, 0x3b, 0x3b, 0x2f, 0x46, 0x40, 0x6d, + 0x50, 0x45, 0x3b, 0x45, 0x46, 0x3b, 0x42, 0x48, 0x42, 0x3c, 0x39, 0x37, + 0x57, 0x3b, 0x6c, 0x5b, 0x32, 0x35, 0x3d, 0x39, 0x48, 0x31, 0x5c, 0x46, + 0x29, 0x4c, 0x3f, 0x3e, 0x37, 0x33, 0x58, 0x32, 0x2a, 0x43, 0x4c, 0x50, + 0x3b, 0x44, 0x3c, 0x41, 0x39, 0x48, 0x55, 0x4c, 0x42, 0x38, 0x3b, 0x51, + 0x3f, 0x38, 0x44, 0x46, 0x36, 0x3b, 0x38, 0x4a, 0x3f, 0x37, 0x36, 0x3c, + 0x31, 0x3d, 0x32, 0x39, 0x3b, 0x3f, 0x3e, 0x35, 0x38, 0x3f, 0x34, 0x2b, + 0x37, 0x36, 0x39, 0x40, 0x37, 0x41, 0x32, 0x27, 0x36, 0x33, 0x40, 0x3a, + 0x3f, 0x44, 0x3f, 0x25, 0x38, 0x34, 0x42, 0x3c, 0x3a, 0x40, 0x38, 0x31, + 0x49, 0x3e, 0x33, 0x3d, 0x31, 0x36, 0x39, 0x2b, 0x44, 0x2f, 0x43, 0x34, + 0x34, 0x37, 0x39, 0x33, 0x3b, 0x34, 0x42, 0x3c, 0x40, 0x45, 0x36, 0x31, + 0x43, 0x47, 0x3e, 0x3f, 0x40, 0x3a, 0x33, 0x34, 0x41, 0x44, 0x3a, 0x43, + 0x3e, 0x38, 0x36, 0x31, 0x42, 0x44, 0x40, 0x41, 0x44, 0x43, 0x33, 0x42, + 0x3d, 0x41, 0x3d, 0x3e, 0x3c, 0x39, 0x3e, 0x4f, 0x3f, 0x37, 0x31, 0x40, + 0x3b, 0x38, 0x35, 0x3b, 0x44, 0x41, 0x41, 0x37, 0x40, 0x42, 0x2d, 0x3d, + 0x39, 0x48, 0x44, 0x3e, 0x34, 0x48, 0x49, 0x6d, 0x45, 0x4b, 0x3a, 0x44, + 0x49, 0x40, 0x4d, 0x51, 0x3f, 0x34, 0x3b, 0x40, 0x52, 0x34, 0x6f, 0x56, + 0x33, 0x3e, 0x40, 0x39, 0x41, 0x32, 0x5d, 0x45, 0x2e, 0x51, 0x48, 0x3c, + 0x2e, 0x2e, 0x51, 0x39, 0x32, 0x45, 0x4a, 0x4c, 0x3b, 0x40, 0x40, 0x3b, + 0x36, 0x41, 0x54, 0x4e, 0x4a, 0x49, 0x3b, 0x4d, 0x3c, 0x41, 0x38, 0x47, + 0x3d, 0x3c, 0x37, 0x48, 0x3f, 0x42, 0x3e, 0x36, 0x39, 0x46, 0x37, 0x3e, + 0x3b, 0x38, 0x40, 0x3b, 0x39, 0x32, 0x3e, 0x29, 0x37, 0x35, 0x3c, 0x3d, + 0x37, 0x3b, 0x35, 0x2f, 0x32, 0x3b, 0x37, 0x3c, 0x40, 0x3e, 0x39, 0x27, + 0x3b, 0x38, 0x37, 0x36, 0x39, 0x37, 0x37, 0x35, 0x42, 0x3e, 0x3b, 0x43, + 0x41, 0x3c, 0x37, 0x2a, 0x3a, 0x3e, 0x38, 0x40, 0x36, 0x3e, 0x44, 0x2e, + 0x3e, 0x3a, 0x37, 0x3b, 0x3e, 0x41, 0x3d, 0x30, 0x3b, 0x3f, 0x41, 0x45, + 0x3a, 0x48, 0x37, 0x2f, 0x3a, 0x37, 0x34, 0x43, 0x42, 0x3d, 0x38, 0x41, + 0x3b, 0x3c, 0x39, 0x3c, 0x39, 0x47, 0x2e, 0x41, 0x42, 0x40, 0x32, 0x36, + 0x43, 0x40, 0x3d, 0x4c, 0x38, 0x3e, 0x3b, 0x41, 0x3d, 0x3b, 0x34, 0x43, + 0x43, 0x3f, 0x44, 0x3c, 0x3a, 0x33, 0x39, 0x42, 0x43, 0x3f, 0x33, 0x3d, + 0x33, 0x3e, 0x48, 0x6b, 0x48, 0x43, 0x36, 0x47, 0x49, 0x44, 0x4a, 0x49, + 0x3c, 0x31, 0x35, 0x3e, 0x5c, 0x34, 0x73, 0x53, 0x33, 0x3c, 0x32, 0x3b, + 0x43, 0x27, 0x59, 0x4e, 0x2b, 0x51, 0x4f, 0x37, 0x36, 0x34, 0x56, 0x34, + 0x32, 0x4f, 0x46, 0x50, 0x40, 0x40, 0x3c, 0x3e, 0x34, 0x37, 0x50, 0x49, + 0x43, 0x47, 0x3e, 0x52, 0x44, 0x38, 0x3b, 0x4f, 0x3a, 0x3d, 0x2b, 0x4c, + 0x40, 0x38, 0x3a, 0x35, 0x3a, 0x3a, 0x3d, 0x38, 0x3d, 0x3b, 0x37, 0x48, + 0x3d, 0x3d, 0x32, 0x30, 0x3a, 0x34, 0x3f, 0x3a, 0x3b, 0x3e, 0x35, 0x2f, + 0x3b, 0x3a, 0x45, 0x3d, 0x42, 0x33, 0x33, 0x24, 0x44, 0x39, 0x3c, 0x3d, + 0x41, 0x3c, 0x37, 0x2c, 0x3b, 0x36, 0x34, 0x41, 0x3d, 0x3f, 0x39, 0x32, + 0x3c, 0x40, 0x44, 0x3d, 0x41, 0x3d, 0x3a, 0x29, 0x3e, 0x3e, 0x43, 0x33, + 0x3f, 0x3e, 0x3e, 0x31, 0x38, 0x3a, 0x34, 0x3d, 0x3f, 0x3e, 0x3a, 0x3d, + 0x3e, 0x48, 0x45, 0x3d, 0x44, 0x37, 0x33, 0x3d, 0x45, 0x39, 0x40, 0x40, + 0x42, 0x3f, 0x3f, 0x3d, 0x3a, 0x3b, 0x41, 0x33, 0x41, 0x3c, 0x32, 0x55, + 0x43, 0x3a, 0x32, 0x40, 0x3c, 0x3e, 0x40, 0x43, 0x37, 0x3f, 0x40, 0x38, + 0x43, 0x41, 0x36, 0x42, 0x44, 0x3c, 0x32, 0x3f, 0x38, 0x42, 0x46, 0x59, + 0x4c, 0x41, 0x39, 0x47, 0x46, 0x46, 0x44, 0x44, 0x35, 0x42, 0x32, 0x39, + 0x4f, 0x34, 0x6d, 0x55, 0x31, 0x3b, 0x3a, 0x3f, 0x44, 0x2c, 0x5d, 0x43, + 0x26, 0x4a, 0x4f, 0x40, 0x36, 0x32, 0x4d, 0x33, 0x2f, 0x50, 0x4d, 0x57, + 0x3b, 0x40, 0x42, 0x44, 0x41, 0x3f, 0x52, 0x4e, 0x35, 0x41, 0x44, 0x52, + 0x40, 0x35, 0x39, 0x4b, 0x45, 0x34, 0x2c, 0x4a, 0x3b, 0x41, 0x31, 0x33, + 0x3f, 0x3a, 0x36, 0x3c, 0x3c, 0x33, 0x30, 0x38, 0x43, 0x3f, 0x32, 0x2d, + 0x3f, 0x3a, 0x38, 0x41, 0x39, 0x45, 0x36, 0x2e, 0x3c, 0x38, 0x45, 0x3f, + 0x40, 0x3f, 0x3e, 0x26, 0x41, 0x37, 0x3c, 0x44, 0x3f, 0x3f, 0x35, 0x37, + 0x46, 0x34, 0x37, 0x3e, 0x48, 0x38, 0x36, 0x34, 0x33, 0x39, 0x40, 0x3c, + 0x42, 0x3d, 0x3b, 0x31, 0x38, 0x3b, 0x44, 0x42, 0x45, 0x38, 0x41, 0x30, + 0x3d, 0x42, 0x36, 0x3f, 0x3b, 0x45, 0x37, 0x32, 0x3c, 0x37, 0x3d, 0x42, + 0x38, 0x3d, 0x2f, 0x31, 0x39, 0x40, 0x3f, 0x44, 0x3a, 0x41, 0x44, 0x46, + 0x3d, 0x3a, 0x32, 0x3b, 0x34, 0x47, 0x36, 0x4c, 0x47, 0x35, 0x3c, 0x33, + 0x3b, 0x3c, 0x30, 0x43, 0x43, 0x3f, 0x31, 0x40, 0x3a, 0x37, 0x30, 0x46, + 0x39, 0x3b, 0x42, 0x40, 0x2d, 0x3f, 0x3e, 0x6a, 0x50, 0x3b, 0x31, 0x54, + 0x47, 0x3d, 0x48, 0x4e, 0x3b, 0x41, 0x3a, 0x39, 0x49, 0x36, 0x64, 0x4e, + 0x32, 0x39, 0x3d, 0x37, 0x42, 0x2c, 0x5c, 0x43, 0x2a, 0x4b, 0x4b, 0x46, + 0x30, 0x29, 0x52, 0x31, 0x35, 0x44, 0x4a, 0x4b, 0x3d, 0x3b, 0x4e, 0x42, + 0x3d, 0x39, 0x42, 0x52, 0x3f, 0x36, 0x3e, 0x50, 0x3f, 0x32, 0x35, 0x3a, + 0x40, 0x39, 0x35, 0x48, 0x3b, 0x3e, 0x41, 0x43, 0x43, 0x45, 0x2f, 0x36, + 0x38, 0x34, 0x3f, 0x44, 0x32, 0x3f, 0x37, 0x33, 0x33, 0x35, 0x2e, 0x41, + 0x37, 0x3e, 0x38, 0x28, 0x49, 0x30, 0x46, 0x39, 0x3b, 0x30, 0x38, 0x28, + 0x3b, 0x3d, 0x3a, 0x43, 0x3f, 0x34, 0x43, 0x36, 0x39, 0x3c, 0x3e, 0x3e, + 0x39, 0x3b, 0x39, 0x32, 0x3c, 0x36, 0x3e, 0x38, 0x34, 0x3c, 0x3a, 0x2a, + 0x46, 0x3d, 0x40, 0x37, 0x3b, 0x39, 0x3b, 0x34, 0x38, 0x31, 0x43, 0x46, + 0x3b, 0x43, 0x39, 0x2b, 0x38, 0x40, 0x3e, 0x39, 0x35, 0x3d, 0x2c, 0x36, + 0x37, 0x40, 0x36, 0x40, 0x41, 0x38, 0x32, 0x3f, 0x36, 0x46, 0x34, 0x31, + 0x40, 0x3e, 0x3c, 0x4e, 0x42, 0x3d, 0x36, 0x3f, 0x42, 0x3f, 0x33, 0x40, + 0x34, 0x37, 0x3c, 0x3b, 0x31, 0x47, 0x32, 0x3c, 0x34, 0x3d, 0x42, 0x3b, + 0x37, 0x41, 0x3b, 0x64, 0x52, 0x40, 0x36, 0x4e, 0x46, 0x3f, 0x3f, 0x47, + 0x3c, 0x3a, 0x3a, 0x41, 0x4a, 0x32, 0x5e, 0x50, 0x2d, 0x39, 0x3a, 0x38, + 0x3d, 0x2c, 0x5a, 0x3e, 0x2e, 0x47, 0x3e, 0x3e, 0x33, 0x29, 0x4c, 0x35, + 0x30, 0x4d, 0x4d, 0x4d, 0x38, 0x42, 0x51, 0x47, 0x39, 0x3c, 0x43, 0x4b, + 0x42, 0x3f, 0x3a, 0x4b, 0x44, 0x3f, 0x3a, 0x44, 0x3e, 0x37, 0x30, 0x45, + 0x3d, 0x36, 0x34, 0x3f, 0x36, 0x35, 0x37, 0x36, 0x43, 0x3b, 0x37, 0x3e, + 0x35, 0x3e, 0x32, 0x34, 0x32, 0x38, 0x3c, 0x3a, 0x3a, 0x3c, 0x30, 0x2b, + 0x31, 0x37, 0x30, 0x42, 0x36, 0x37, 0x36, 0x2c, 0x3c, 0x31, 0x41, 0x37, + 0x44, 0x41, 0x3b, 0x37, 0x41, 0x3f, 0x38, 0x3b, 0x3a, 0x3a, 0x3c, 0x2f, + 0x47, 0x41, 0x3e, 0x33, 0x42, 0x3a, 0x32, 0x34, 0x44, 0x40, 0x43, 0x3d, + 0x34, 0x41, 0x38, 0x35, 0x35, 0x3b, 0x45, 0x38, 0x32, 0x37, 0x3c, 0x2e, + 0x39, 0x40, 0x30, 0x3e, 0x42, 0x35, 0x3d, 0x36, 0x3e, 0x3d, 0x39, 0x46, + 0x3f, 0x36, 0x37, 0x49, 0x41, 0x39, 0x3d, 0x3d, 0x33, 0x44, 0x42, 0x50, + 0x3d, 0x3c, 0x3e, 0x3f, 0x42, 0x42, 0x3b, 0x3d, 0x41, 0x31, 0x39, 0x3a, + 0x44, 0x34, 0x38, 0x47, 0x44, 0x38, 0x3b, 0x42, 0x30, 0x42, 0x44, 0x57, + 0x49, 0x3a, 0x39, 0x4f, 0x41, 0x3e, 0x40, 0x43, 0x37, 0x42, 0x3b, 0x48, + 0x50, 0x29, 0x5b, 0x44, 0x2c, 0x40, 0x3f, 0x3c, 0x46, 0x34, 0x5c, 0x41, + 0x2c, 0x48, 0x46, 0x46, 0x35, 0x32, 0x4c, 0x35, 0x2f, 0x3b, 0x48, 0x44, + 0x41, 0x41, 0x49, 0x45, 0x34, 0x37, 0x44, 0x45, 0x43, 0x3b, 0x42, 0x44, + 0x3a, 0x37, 0x48, 0x49, 0x34, 0x39, 0x33, 0x4a, 0x40, 0x3d, 0x33, 0x39, + 0x39, 0x3b, 0x30, 0x31, 0x3d, 0x47, 0x3c, 0x3a, 0x34, 0x3c, 0x3a, 0x2b, + 0x3a, 0x34, 0x41, 0x40, 0x42, 0x36, 0x44, 0x2c, 0x40, 0x47, 0x3b, 0x37, + 0x38, 0x42, 0x44, 0x29, 0x36, 0x3d, 0x3d, 0x36, 0x42, 0x3b, 0x35, 0x36, + 0x43, 0x39, 0x41, 0x3d, 0x45, 0x41, 0x31, 0x32, 0x40, 0x3d, 0x3c, 0x41, + 0x3e, 0x3d, 0x35, 0x34, 0x32, 0x38, 0x36, 0x3f, 0x3b, 0x3d, 0x39, 0x36, + 0x40, 0x3e, 0x3d, 0x3a, 0x3a, 0x3b, 0x3c, 0x32, 0x40, 0x34, 0x3a, 0x36, + 0x42, 0x47, 0x3e, 0x33, 0x3a, 0x44, 0x30, 0x39, 0x40, 0x3a, 0x36, 0x44, + 0x3c, 0x3b, 0x3f, 0x33, 0x3e, 0x3c, 0x35, 0x53, 0x43, 0x3c, 0x3f, 0x43, + 0x3d, 0x44, 0x33, 0x47, 0x42, 0x40, 0x37, 0x3b, 0x43, 0x3f, 0x33, 0x41, + 0x38, 0x42, 0x44, 0x3d, 0x2d, 0x3f, 0x46, 0x49, 0x4e, 0x3f, 0x36, 0x45, + 0x45, 0x39, 0x40, 0x42, 0x39, 0x39, 0x3a, 0x42, 0x45, 0x2c, 0x61, 0x44, + 0x30, 0x45, 0x38, 0x3a, 0x40, 0x37, 0x58, 0x39, 0x31, 0x3e, 0x3a, 0x3e, + 0x37, 0x32, 0x4a, 0x39, 0x2e, 0x47, 0x3e, 0x4e, 0x3f, 0x3e, 0x48, 0x45, + 0x3f, 0x48, 0x3a, 0x3f, 0x40, 0x36, 0x3a, 0x44, 0x36, 0x3e, 0x3d, 0x41, + 0x45, 0x36, 0x36, 0x4b, 0x3a, 0x3d, 0x45, 0x48, 0x38, 0x45, 0x39, 0x38, + 0x38, 0x3a, 0x42, 0x34, 0x3f, 0x34, 0x39, 0x34, 0x32, 0x3f, 0x3c, 0x3d, + 0x3d, 0x47, 0x3a, 0x2f, 0x3c, 0x3e, 0x3f, 0x39, 0x35, 0x42, 0x3c, 0x2a, + 0x3b, 0x35, 0x42, 0x44, 0x46, 0x39, 0x38, 0x39, 0x43, 0x3a, 0x38, 0x42, + 0x3d, 0x3a, 0x40, 0x35, 0x34, 0x39, 0x3a, 0x38, 0x43, 0x42, 0x42, 0x2d, + 0x31, 0x3b, 0x33, 0x40, 0x3b, 0x47, 0x35, 0x30, 0x3a, 0x3c, 0x3b, 0x47, + 0x3a, 0x3c, 0x38, 0x35, 0x3c, 0x35, 0x3e, 0x3e, 0x39, 0x3d, 0x39, 0x40, + 0x37, 0x33, 0x49, 0x38, 0x3c, 0x43, 0x34, 0x40, 0x39, 0x42, 0x3c, 0x3b, + 0x3e, 0x45, 0x3e, 0x51, 0x3d, 0x3f, 0x3b, 0x34, 0x37, 0x3c, 0x40, 0x47, + 0x3c, 0x41, 0x3f, 0x41, 0x37, 0x3e, 0x36, 0x3c, 0x42, 0x40, 0x3f, 0x3a, + 0x3b, 0x42, 0x44, 0x4b, 0x4b, 0x37, 0x41, 0x4d, 0x41, 0x45, 0x40, 0x41, + 0x40, 0x38, 0x37, 0x40, 0x42, 0x2c, 0x57, 0x43, 0x2d, 0x49, 0x3a, 0x3e, + 0x37, 0x2f, 0x52, 0x37, 0x31, 0x42, 0x3b, 0x3f, 0x39, 0x38, 0x48, 0x3c, + 0x37, 0x3d, 0x3a, 0x39, 0x3a, 0x45, 0x4b, 0x49, 0x3e, 0x44, 0x48, 0x49, + 0x3d, 0x39, 0x3c, 0x41, 0x41, 0x38, 0x45, 0x38, 0x33, 0x3d, 0x37, 0x47, + 0x34, 0x3f, 0x3b, 0x3d, 0x39, 0x34, 0x30, 0x39, 0x44, 0x36, 0x34, 0x3c, + 0x37, 0x38, 0x45, 0x34, 0x40, 0x33, 0x41, 0x3a, 0x3e, 0x3c, 0x3b, 0x3a, + 0x40, 0x3f, 0x3b, 0x3d, 0x3b, 0x46, 0x41, 0x2a, 0x3a, 0x3c, 0x42, 0x46, + 0x33, 0x3f, 0x2d, 0x3a, 0x45, 0x45, 0x38, 0x3b, 0x44, 0x34, 0x35, 0x3f, + 0x34, 0x43, 0x38, 0x3e, 0x41, 0x3b, 0x42, 0x38, 0x3d, 0x3f, 0x38, 0x45, + 0x3b, 0x35, 0x39, 0x3c, 0x43, 0x43, 0x38, 0x34, 0x44, 0x43, 0x2e, 0x39, + 0x39, 0x40, 0x39, 0x41, 0x41, 0x34, 0x3e, 0x44, 0x3d, 0x43, 0x3a, 0x3a, + 0x3b, 0x3b, 0x36, 0x45, 0x3c, 0x43, 0x3d, 0x48, 0x36, 0x36, 0x39, 0x55, + 0x35, 0x40, 0x3e, 0x49, 0x40, 0x3a, 0x3d, 0x3d, 0x34, 0x47, 0x40, 0x41, + 0x40, 0x47, 0x39, 0x3e, 0x3b, 0x38, 0x3c, 0x3a, 0x35, 0x3e, 0x41, 0x4a, + 0x4b, 0x3f, 0x36, 0x3d, 0x40, 0x3c, 0x39, 0x32, 0x33, 0x36, 0x30, 0x42, + 0x42, 0x36, 0x54, 0x48, 0x2e, 0x4c, 0x34, 0x3c, 0x39, 0x36, 0x4e, 0x37, + 0x2f, 0x3e, 0x30, 0x3d, 0x36, 0x3b, 0x45, 0x36, 0x37, 0x3e, 0x41, 0x4b, + 0x3b, 0x36, 0x45, 0x3b, 0x38, 0x45, 0x3e, 0x43, 0x48, 0x46, 0x44, 0x44, + 0x3e, 0x3b, 0x37, 0x3b, 0x3a, 0x3f, 0x3d, 0x44, 0x39, 0x38, 0x45, 0x43, + 0x3d, 0x35, 0x39, 0x2c, 0x44, 0x41, 0x36, 0x40, 0x3d, 0x39, 0x3d, 0x2f, + 0x3d, 0x39, 0x42, 0x3d, 0x36, 0x46, 0x43, 0x2c, 0x41, 0x3a, 0x30, 0x45, + 0x3f, 0x41, 0x35, 0x2b, 0x3b, 0x38, 0x3a, 0x44, 0x32, 0x32, 0x39, 0x3c, + 0x3a, 0x3a, 0x3c, 0x3a, 0x35, 0x40, 0x3b, 0x31, 0x36, 0x33, 0x35, 0x34, + 0x3c, 0x3b, 0x3d, 0x36, 0x48, 0x3b, 0x3f, 0x42, 0x3e, 0x33, 0x2f, 0x3a, + 0x49, 0x41, 0x39, 0x3e, 0x3c, 0x44, 0x3c, 0x39, 0x33, 0x39, 0x36, 0x35, + 0x3d, 0x42, 0x34, 0x3e, 0x38, 0x45, 0x40, 0x45, 0x3d, 0x48, 0x42, 0x4a, + 0x3f, 0x45, 0x38, 0x42, 0x44, 0x40, 0x34, 0x49, 0x44, 0x3d, 0x3a, 0x39, + 0x3e, 0x3a, 0x42, 0x3e, 0x48, 0x42, 0x3e, 0x3a, 0x3f, 0x3f, 0x32, 0x3b, + 0x38, 0x41, 0x3c, 0x39, 0x33, 0x45, 0x44, 0x3c, 0x48, 0x41, 0x41, 0x3d, + 0x3a, 0x3c, 0x37, 0x33, 0x41, 0x3f, 0x38, 0x3a, 0x3f, 0x37, 0x51, 0x3c, + 0x37, 0x3a, 0x43, 0x37, 0x40, 0x31, 0x4f, 0x34, 0x3b, 0x44, 0x45, 0x39, + 0x40, 0x33, 0x49, 0x33, 0x3e, 0x35, 0x44, 0x3d, 0x3b, 0x3f, 0x43, 0x41, + 0x43, 0x43, 0x48, 0x44, 0x46, 0x3b, 0x43, 0x3f, 0x3c, 0x3f, 0x3e, 0x3d, + 0x3b, 0x41, 0x3c, 0x43, 0x30, 0x34, 0x39, 0x33, 0x3f, 0x38, 0x36, 0x2e, + 0x33, 0x3f, 0x3c, 0x40, 0x3d, 0x3b, 0x3b, 0x31, 0x36, 0x41, 0x3b, 0x38, + 0x46, 0x36, 0x34, 0x31, 0x42, 0x44, 0x33, 0x35, 0x3f, 0x36, 0x3c, 0x30, + 0x3f, 0x31, 0x39, 0x3e, 0x3f, 0x47, 0x3e, 0x34, 0x36, 0x36, 0x34, 0x39, + 0x37, 0x46, 0x40, 0x33, 0x3b, 0x3a, 0x3f, 0x41, 0x37, 0x44, 0x3a, 0x3f, + 0x34, 0x45, 0x37, 0x33, 0x3f, 0x47, 0x41, 0x36, 0x39, 0x3e, 0x40, 0x38, + 0x41, 0x3d, 0x3d, 0x36, 0x40, 0x3a, 0x3b, 0x3b, 0x41, 0x3b, 0x3a, 0x3f, + 0x3f, 0x3b, 0x35, 0x42, 0x46, 0x3a, 0x30, 0x45, 0x40, 0x37, 0x39, 0x39, + 0x3d, 0x38, 0x3f, 0x45, 0x3f, 0x31, 0x32, 0x3b, 0x35, 0x3e, 0x3b, 0x38, + 0x3b, 0x44, 0x37, 0x39, 0x37, 0x42, 0x3f, 0x44, 0x38, 0x36, 0x37, 0x44, + 0x45, 0x46, 0x41, 0x3b, 0x46, 0x42, 0x43, 0x43, 0x3a, 0x4b, 0x37, 0x35, + 0x3b, 0x40, 0x32, 0x38, 0x41, 0x38, 0x4f, 0x3e, 0x36, 0x3f, 0x47, 0x3b, + 0x47, 0x3b, 0x4a, 0x2e, 0x3d, 0x45, 0x3b, 0x46, 0x3e, 0x38, 0x43, 0x38, + 0x41, 0x48, 0x3a, 0x39, 0x40, 0x45, 0x3b, 0x43, 0x40, 0x3e, 0x43, 0x41, + 0x41, 0x3e, 0x39, 0x3f, 0x35, 0x42, 0x33, 0x3f, 0x3d, 0x32, 0x45, 0x3c, + 0x41, 0x31, 0x45, 0x38, 0x43, 0x45, 0x41, 0x35, 0x35, 0x40, 0x44, 0x36, + 0x3a, 0x3b, 0x3c, 0x2c, 0x3e, 0x41, 0x33, 0x3d, 0x46, 0x34, 0x3b, 0x30, + 0x30, 0x42, 0x43, 0x3d, 0x3d, 0x3d, 0x43, 0x31, 0x3f, 0x40, 0x3a, 0x3f, + 0x48, 0x3e, 0x3b, 0x39, 0x44, 0x43, 0x3b, 0x3a, 0x42, 0x38, 0x38, 0x3b, + 0x3f, 0x44, 0x37, 0x3e, 0x45, 0x40, 0x41, 0x3b, 0x3c, 0x3a, 0x38, 0x37, + 0x3b, 0x33, 0x3f, 0x35, 0x43, 0x3d, 0x33, 0x41, 0x3b, 0x46, 0x39, 0x32, + 0x39, 0x3f, 0x3b, 0x39, 0x47, 0x3c, 0x3f, 0x39, 0x34, 0x3d, 0x3c, 0x46, + 0x3f, 0x3e, 0x3e, 0x44, 0x34, 0x40, 0x3f, 0x39, 0x3c, 0x38, 0x36, 0x45, + 0x42, 0x46, 0x3b, 0x44, 0x3a, 0x3d, 0x3b, 0x42, 0x3b, 0x3b, 0x3c, 0x45, + 0x42, 0x3d, 0x36, 0x37, 0x3d, 0x43, 0x3f, 0x48, 0xa6, 0xfb, 0xff, 0xff, + 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0xb3, 0x00, 0x00, 0x00, + 0x39, 0xff, 0xff, 0xff, 0xe5, 0xff, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, + 0x68, 0xfb, 0xff, 0xff, 0xbc, 0xfc, 0xff, 0xff, 0x20, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0xe8, 0x03, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x70, 0x02, 0x00, 0x00, + 0x70, 0x03, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0xf0, 0x01, 0x00, 0x00, + 0x80, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x50, 0x01, 0x00, 0x00, + 0xa4, 0x02, 0x00, 0x00, 0xba, 0xfc, 0xff, 0xff, 0x00, 0x00, 0x00, 0x03, + 0x24, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x6c, 0x61, 0x62, 0x65, + 0x6c, 0x73, 0x5f, 0x73, 0x6f, 0x66, 0x74, 0x6d, 0x61, 0x78, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x3c, 0xfd, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x3b, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x3f, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2a, 0xfd, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x03, 0x1c, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x61, 0x64, 0x64, 0x5f, 0x31, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xa4, 0xfd, 0xff, 0xff, + 0x2c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x09, 0x97, 0xf5, 0x3f, + 0x01, 0x00, 0x00, 0x00, 0x87, 0x35, 0xa0, 0x43, 0x01, 0x00, 0x00, 0x00, + 0xd6, 0xd7, 0x28, 0xc3, 0x92, 0xfd, 0xff, 0xff, 0x00, 0x00, 0x00, 0x03, + 0x1c, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x52, 0x65, 0x6c, 0x75, + 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x19, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x14, 0xfe, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x05, 0x80, 0xbf, 0x3f, 0x01, 0x00, 0x00, 0x00, 0x85, 0xc0, 0xbe, 0x43, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xfe, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x03, 0x3c, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, + 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x73, 0x5f, 0x71, 0x75, 0x61, 0x6e, + 0x74, 0x2f, 0x46, 0x61, 0x6b, 0x65, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x57, + 0x69, 0x74, 0x68, 0x4d, 0x69, 0x6e, 0x4d, 0x61, 0x78, 0x56, 0x61, 0x72, + 0x73, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x0a, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0xa4, 0xfe, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0xae, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x17, 0xac, 0x6e, 0x3a, 0x01, 0x00, 0x00, 0x00, + 0x20, 0x4e, 0x97, 0x3d, 0x01, 0x00, 0x00, 0x00, 0xaf, 0x27, 0x21, 0xbe, + 0x96, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x03, 0x20, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x52, 0x65, 0x73, 0x68, 0x61, 0x70, 0x65, 0x5f, + 0x31, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x31, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x1c, 0xff, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x3f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x42, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, + 0x43, 0x6f, 0x6e, 0x76, 0x32, 0x44, 0x5f, 0x62, 0x69, 0x61, 0x73, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0xfc, 0xfe, 0xff, 0xff, + 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x17, 0xac, 0xee, 0x39, 0x5a, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x03, + 0x48, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x54, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x77, 0x65, 0x69, 0x67, + 0x68, 0x74, 0x73, 0x5f, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x5f, 0x31, 0x2f, + 0x46, 0x61, 0x6b, 0x65, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x57, 0x69, 0x74, + 0x68, 0x4d, 0x69, 0x6e, 0x4d, 0x61, 0x78, 0x56, 0x61, 0x72, 0x73, 0x2f, + 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x73, 0x65, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x30, 0x11, 0x00, 0x00, + 0x0c, 0x00, 0x14, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x9d, 0xaf, 0xd0, 0x3a, 0x01, 0x00, 0x00, 0x00, + 0xe7, 0x29, 0x9e, 0x3e, 0x01, 0x00, 0x00, 0x00, 0x5b, 0x91, 0xc3, 0xbd, + 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x08, 0x00, 0x07, 0x00, 0x0c, 0x00, + 0x10, 0x00, 0x14, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x28, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x4d, 0x61, 0x74, 0x4d, + 0x75, 0x6c, 0x5f, 0x62, 0x69, 0x61, 0x73, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x62, 0x1b, 0x1c, 0x3b, + 0x03, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, + 0x02, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x14, 0x00, 0x1c, 0x00, + 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x07, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x18, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, + 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x28, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x14, 0x00, 0x18, 0x00, + 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x07, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x14, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x1c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xfa, 0xff, 0xff, 0xff, 0x00, 0x19, 0x06, 0x00, + 0x06, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x09, 0x06, 0x00, + 0x08, 0x00, 0x07, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04 +}; +const int g_model_len = 19800; diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/model.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/model.h new file mode 100644 index 00000000..fecf8169 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/model.h @@ -0,0 +1,27 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// This is a standard TensorFlow Lite FlatBuffer model file that has been +// converted into a C data array, so it can be easily compiled into a binary +// for devices that don't have a file system. It was created using the command: +// xxd -i model.tflite > model.cc + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_MODEL_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_MODEL_H_ + +extern const unsigned char g_model[]; +extern const int g_model_len; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_MODEL_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/no_power_spectrum_data.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/no_power_spectrum_data.cc new file mode 100644 index 00000000..1fe4dfae --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/no_power_spectrum_data.cc @@ -0,0 +1,64 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// See the header for documentation on the meaning of this data. + +#include "tensorflow/lite/micro/examples/micro_speech/simple_features/no_power_spectrum_data.h" + +const uint8_t g_no_power_spectrum_data[g_no_power_spectrum_data_size] = { + 255, + 7, + 6, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +}; diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/no_power_spectrum_data.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/no_power_spectrum_data.h new file mode 100644 index 00000000..fe3007e9 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/no_power_spectrum_data.h @@ -0,0 +1,29 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// This data was extracted from the larger feature data held in +// no_features_data.cc and consists of the 29th spectrogram slice of 43 values. +// This is the expected result of running the sample data in +// no_30ms_sample_data.cc through the preprocessing pipeline. + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_NO_POWER_SPECTRUM_DATA_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_NO_POWER_SPECTRUM_DATA_H_ + +#include + +constexpr int g_no_power_spectrum_data_size = 43; +extern const uint8_t g_no_power_spectrum_data[]; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_NO_POWER_SPECTRUM_DATA_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/no_simple_features_data.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/no_simple_features_data.cc new file mode 100644 index 00000000..09123420 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/no_simple_features_data.cc @@ -0,0 +1,2141 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/micro_speech/simple_features/no_simple_features_data.h" + +/* File automatically created by + * tensorflow/examples/speech_commands/wav_to_features.py \ + * --sample_rate=16000 \ + * --clip_duration_ms=1000 \ + * --window_size_ms=30 \ + * --window_stride_ms=20 \ + * --feature_bin_count=40 \ + * --quantize=1 \ + * --preprocess="average" \ + * --input_wav="speech_commands_test_set_v0.02/no/f9643d42_nohash_4.wav" \ + * --output_c_file="no_simple_features_data.cc" \ + */ + +const int g_no_simple_f9643d42_nohash_4_width = 43; +const int g_no_simple_f9643d42_nohash_4_height = 49; +const unsigned char g_no_simple_f9643d42_nohash_4_data[] = { + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 5, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 67, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 139, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 195, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 230, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 255, + 7, + 6, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 255, + 7, + 16, + 1, + 1, + 0, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 255, + 7, + 22, + 0, + 1, + 0, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 238, + 5, + 20, + 3, + 4, + 1, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 144, + 4, + 19, + 3, + 5, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 42, + 6, + 3, + 1, + 3, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 3, + 1, + 5, + 0, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 5, + 1, + 3, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +}; diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/no_simple_features_data.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/no_simple_features_data.h new file mode 100644 index 00000000..ea6075e7 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/no_simple_features_data.h @@ -0,0 +1,23 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_NO_SIMPLE_FEATURES_DATA_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_NO_SIMPLE_FEATURES_DATA_H_ + +extern const int g_no_simple_f9643d42_nohash_4_width; +extern const int g_no_simple_f9643d42_nohash_4_height; +extern const unsigned char g_no_simple_f9643d42_nohash_4_data[]; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_NO_SIMPLE_FEATURES_DATA_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/simple_features_generator.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/simple_features_generator.cc new file mode 100644 index 00000000..1404e2ce --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/simple_features_generator.cc @@ -0,0 +1,153 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// Reference implementation of the preprocessing pipeline, with the same +// results as the audio tutorial at +// https://www.tensorflow.org/tutorials/sequences/audio_recognition +// This module takes 30ms of PCM-encoded signed 16-bit audio samples (at 16KHz, +// so 480 values), and extracts a power spectrum of frequencies. There are 43 +// frequency bands in the result, derived from the original 256 output from the +// discrete Fourier transform, and averaged together in groups of 6. +// It's expected that most platforms will have optimized versions of the +// functions used here, for example replacing the DFT with an FFT, so this +// version shouldn't be used where performance is critical. + +#include "tensorflow/lite/micro/examples/micro_speech/simple_features/simple_features_generator.h" + +#include + +#include "tensorflow/lite/micro/examples/micro_speech/simple_features/simple_model_settings.h" + +namespace { + +// Needed because some platforms don't have M_PI defined. +constexpr float kPi = 3.14159265358979323846f; + +// Performs a discrete Fourier transform on the real inputs. This corresponds to +// rdft() in the FFT package at http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html, +// and to kiss_fftr() in KISSFFT at https://github.com/mborgerding/kissfft. +// It takes in an array of float real values, and returns a result of the same +// length with float real and imaginary components interleaved, so +// fourier_output[0] is the first real value, fourier_output[1] is the first +// imaginary, fourier_output[2] is the second real, and so on. +// The calling function should ensure that the array passed in as fourier_output +// is at least time_series_size in length. Most optimized FFT implementations +// require the length to be a power of two as well, but this version doesn't +// enforce that. +void CalculateDiscreteFourierTransform(float *time_series, int time_series_size, + float *fourier_output) +{ + for (int i = 0; i < time_series_size / 2; ++i) { + float real = 0; + for (int j = 0; j < time_series_size; ++j) { + real += time_series[j] * std::cos(j * i * kPi * 2 / time_series_size); + } + float imaginary = 0; + for (int j = 0; j < time_series_size; ++j) { + imaginary -= + time_series[j] * std::sin(j * i * kPi * 2 / time_series_size); + } + fourier_output[(i * 2) + 0] = real; + fourier_output[(i * 2) + 1] = imaginary; + } +} + +// Produces a simple sine curve that is used to ensure frequencies at the center +// of the current sample window are weighted more heavily than those at the end. +void CalculatePeriodicHann(int window_length, float *window_function) +{ + for (int i = 0; i < window_length; ++i) { + window_function[i] = 0.5f - 0.5f * std::cos((2 * kPi * i) / window_length); + } +} + +} // namespace + +TfLiteStatus GenerateSimpleFeatures(tflite::ErrorReporter *error_reporter, + const int16_t *input, int input_size, + int output_size, uint8_t *output) +{ + // Ensure our input and output data arrays are valid. + if (input_size > kMaxAudioSampleSize) { + TF_LITE_REPORT_ERROR(error_reporter, "Input size %d larger than %d", + input_size, kMaxAudioSampleSize); + return kTfLiteError; + } + if (output_size != kFeatureSliceSize) { + TF_LITE_REPORT_ERROR(error_reporter, + "Requested output size %d doesn't match %d", + output_size, kFeatureSliceSize); + return kTfLiteError; + } + + // Pre-calculate the window function we'll be applying to the input data. + // In a real application, we'd calculate this table once in an initialization + // function and store it for repeated reuse. + float window_function[kMaxAudioSampleSize]; + CalculatePeriodicHann(input_size, window_function); + + // Apply the window function to our time series input, and pad it with zeroes + // to the next power of two. + float float_input[kMaxAudioSampleSize]; + for (int i = 0; i < kMaxAudioSampleSize; ++i) { + if (i < input_size) { + float_input[i] = + (input[i] * window_function[i]) / static_cast(1 << 15); + } else { + float_input[i] = 0.0f; + } + } + + // Pull the frequency data from the time series sample. + float fourier_values[kMaxAudioSampleSize]; + CalculateDiscreteFourierTransform(float_input, kMaxAudioSampleSize, + fourier_values); + + // We have the complex numbers giving us information about each frequency + // band, but all we want to know is how strong each frequency is, so calculate + // the squared magnitude by adding together the squares of each component. + float power_spectrum[kMaxAudioSampleSize / 2]; + for (int i = 0; i < (kMaxAudioSampleSize / 2); ++i) { + const float real = fourier_values[(i * 2) + 0]; + const float imaginary = fourier_values[(i * 2) + 1]; + power_spectrum[i] = (real * real) + (imaginary * imaginary); + } + + // Finally, reduce the size of the output by averaging together six adjacent + // frequencies into each slot, producing an array of 43 values. + for (int i = 0; i < kFeatureSliceSize; ++i) { + float total = 0.0f; + for (int j = 0; j < kAverageWindowSize; ++j) { + const int index = (i * kAverageWindowSize) + j; + if (index < (kMaxAudioSampleSize / 2)) { + total += power_spectrum[index]; + } + } + const float average = total / kAverageWindowSize; + // Quantize the result into eight bits, effectively multiplying by two. + // The 127.5 constant here has to match the features_max value defined in + // tensorflow/examples/speech_commands/input_data.py, and this also assumes + // that features_min is zero. If it wasn't, we'd have to subtract it first. + int quantized_average = roundf(average * (255.0f / 127.5f)); + if (quantized_average < 0) { + quantized_average = 0; + } + if (quantized_average > 255) { + quantized_average = 255; + } + output[i] = quantized_average; + } + return kTfLiteOk; +} diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/simple_features_generator.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/simple_features_generator.h new file mode 100644 index 00000000..8f3a8228 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/simple_features_generator.h @@ -0,0 +1,31 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_SIMPLE_FEATURES_GENERATOR_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_SIMPLE_FEATURES_GENERATOR_H_ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" + +// Converts audio sample data into a more compact form that's appropriate for +// feeding into a neural network. There are reference implementations that use +// both floating point and fixed point available, but because the calculations +// involved can be time-consuming, it's recommended that you use or write +// specialized versions for your platform. +TfLiteStatus GenerateSimpleFeatures(tflite::ErrorReporter *error_reporter, + const int16_t *input, int input_size, + int output_size, uint8_t *output); + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_SIMPLE_FEATURES_GENERATOR_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/simple_features_generator_test.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/simple_features_generator_test.cc new file mode 100644 index 00000000..b3481743 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/simple_features_generator_test.cc @@ -0,0 +1,65 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/micro_speech/simple_features/simple_features_generator.h" + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/examples/micro_speech/no_30ms_sample_data.h" +#include "tensorflow/lite/micro/examples/micro_speech/simple_features/no_power_spectrum_data.h" +#include "tensorflow/lite/micro/examples/micro_speech/simple_features/yes_power_spectrum_data.h" +#include "tensorflow/lite/micro/examples/micro_speech/yes_30ms_sample_data.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestSimpleFeaturesGenerator) +{ + tflite::MicroErrorReporter micro_error_reporter; + + uint8_t yes_calculated_data[g_yes_power_spectrum_data_size]; + TfLiteStatus yes_status = GenerateSimpleFeatures( + µ_error_reporter, g_yes_30ms_sample_data, + g_yes_30ms_sample_data_size, g_yes_power_spectrum_data_size, + yes_calculated_data); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, yes_status); + + for (int i = 0; i < g_yes_power_spectrum_data_size; ++i) { + TF_LITE_MICRO_EXPECT_EQ(g_yes_power_spectrum_data[i], + yes_calculated_data[i]); + if (g_yes_power_spectrum_data[i] != yes_calculated_data[i]) { + TF_LITE_REPORT_ERROR( + µ_error_reporter, "Expected value %d but found %d", + g_yes_power_spectrum_data[i], yes_calculated_data[i]); + } + } + + uint8_t no_calculated_data[g_yes_power_spectrum_data_size]; + TfLiteStatus no_status = GenerateSimpleFeatures( + µ_error_reporter, g_no_30ms_sample_data, g_no_30ms_sample_data_size, + g_no_power_spectrum_data_size, no_calculated_data); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, no_status); + + for (int i = 0; i < g_no_power_spectrum_data_size; ++i) { + TF_LITE_MICRO_EXPECT_EQ(g_no_power_spectrum_data[i], no_calculated_data[i]); + if (g_no_power_spectrum_data[i] != no_calculated_data[i]) { + TF_LITE_REPORT_ERROR(µ_error_reporter, + "Expected value %d but found %d", + g_no_power_spectrum_data[i], no_calculated_data[i]); + } + } +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/simple_model_settings.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/simple_model_settings.cc new file mode 100644 index 00000000..aadba1c5 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/simple_model_settings.cc @@ -0,0 +1,23 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/micro_speech/simple_features/simple_model_settings.h" + +const char *kCategoryLabels[kCategoryCount] = { + "silence", + "unknown", + "yes", + "no", +}; diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/simple_model_settings.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/simple_model_settings.h new file mode 100644 index 00000000..53602de6 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/simple_model_settings.h @@ -0,0 +1,43 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_SIMPLE_MODEL_SETTINGS_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_SIMPLE_MODEL_SETTINGS_H_ + +// Keeping these as constant expressions allow us to allocate fixed-sized arrays +// on the stack for our working memory. + +// The size of the input time series data we pass to the FFT to produce the +// frequency information. This has to be a power of two, and since we're dealing +// with 30ms of 16KHz inputs, which means 480 samples, this is the next value. +constexpr int kMaxAudioSampleSize = 512; +constexpr int kAudioSampleFrequency = 16000; + +// All of these values are derived from the values used during model training, +// if you change your model you'll need to update these constants. +constexpr int kAverageWindowSize = 6; +constexpr int kFeatureSliceSize = + ((kMaxAudioSampleSize / 2) + (kAverageWindowSize - 1)) / kAverageWindowSize; +constexpr int kFeatureSliceCount = 49; +constexpr int kFeatureElementCount = (kFeatureSliceSize * kFeatureSliceCount); +constexpr int kFeatureSliceStrideMs = 20; +constexpr int kFeatureSliceDurationMs = 30; + +constexpr int kCategoryCount = 4; +constexpr int kSilenceIndex = 0; +constexpr int kUnknownIndex = 1; +extern const char *kCategoryLabels[kCategoryCount]; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_SIMPLE_MODEL_SETTINGS_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/yes_power_spectrum_data.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/yes_power_spectrum_data.cc new file mode 100644 index 00000000..4335c366 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/yes_power_spectrum_data.cc @@ -0,0 +1,64 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// See the header for documentation on the meaning of this data. + +#include "tensorflow/lite/micro/examples/micro_speech/simple_features/yes_power_spectrum_data.h" + +const uint8_t g_yes_power_spectrum_data[g_yes_power_spectrum_data_size] = { + 8, + 89, + 8, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 4, + 13, + 1, + 6, + 23, + 20, + 6, + 4, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +}; diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/yes_power_spectrum_data.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/yes_power_spectrum_data.h new file mode 100644 index 00000000..7fb3b7ee --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/yes_power_spectrum_data.h @@ -0,0 +1,29 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// This data was extracted from the larger feature data held in +// no_features_data.cc and consists of the 26th spectrogram slice of 43 values. +// This is the expected result of running the sample data in +// yes_30ms_sample_data.cc through the preprocessing pipeline. + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_YES_POWER_SPECTRUM_DATA_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_YES_POWER_SPECTRUM_DATA_H_ + +#include + +constexpr int g_yes_power_spectrum_data_size = 43; +extern const uint8_t g_yes_power_spectrum_data[]; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_YES_POWER_SPECTRUM_DATA_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/yes_simple_features_data.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/yes_simple_features_data.cc new file mode 100644 index 00000000..0d2d640b --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/yes_simple_features_data.cc @@ -0,0 +1,2141 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/micro_speech/simple_features/yes_simple_features_data.h" + +/* File automatically created by + * tensorflow/examples/speech_commands/wav_to_features.py \ + * --sample_rate=16000 \ + * --clip_duration_ms=1000 \ + * --window_size_ms=30 \ + * --window_stride_ms=20 \ + * --feature_bin_count=40 \ + * --quantize=1 \ + * --preprocess="average" \ + * --input_wav="speech_commands_test_set_v0.02/yes/f2e59fea_nohash_1.wav" \ + * --output_c_file="yes_simple_features_data.cc" \ + */ + +const int g_yes_simple_f2e59fea_nohash_1_width = 43; +const int g_yes_simple_f2e59fea_nohash_1_height = 49; +const unsigned char g_yes_simple_f2e59fea_nohash_1_data[] = { + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 4, + 5, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 19, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 1, + 3, + 3, + 1, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 8, + 89, + 8, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 4, + 13, + 1, + 6, + 23, + 20, + 6, + 4, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 19, + 177, + 42, + 1, + 1, + 0, + 0, + 0, + 0, + 2, + 3, + 119, + 51, + 5, + 139, + 92, + 58, + 58, + 15, + 2, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 13, + 165, + 176, + 3, + 1, + 1, + 0, + 0, + 1, + 1, + 32, + 214, + 26, + 19, + 113, + 103, + 28, + 22, + 27, + 3, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 12, + 55, + 128, + 27, + 1, + 1, + 0, + 1, + 4, + 2, + 52, + 93, + 10, + 28, + 156, + 10, + 21, + 21, + 3, + 3, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 14, + 99, + 32, + 65, + 7, + 1, + 2, + 2, + 6, + 13, + 121, + 36, + 15, + 11, + 112, + 125, + 14, + 5, + 13, + 4, + 4, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 24, + 25, + 32, + 5, + 1, + 0, + 0, + 0, + 1, + 0, + 7, + 5, + 1, + 1, + 3, + 3, + 0, + 3, + 3, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 13, + 13, + 5, + 1, + 0, + 0, + 0, + 0, + 0, + 3, + 4, + 1, + 0, + 1, + 2, + 3, + 1, + 1, + 1, + 4, + 8, + 1, + 2, + 1, + 3, + 1, + 1, + 0, + 1, + 1, + 3, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 8, + 2, + 1, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 0, + 0, + 1, + 1, + 2, + 0, + 2, + 1, + 0, + 2, + 0, + 2, + 2, + 3, + 1, + 1, + 0, + 1, + 1, + 4, + 5, + 1, + 0, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 0, + 1, + 2, + 1, + 0, + 1, + 3, + 1, + 1, + 3, + 1, + 1, + 6, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 0, + 1, + 2, + 6, + 2, + 4, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 3, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 1, + 2, + 1, + 1, + 2, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 4, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 2, + 1, + 0, + 0, + 2, + 3, + 5, + 2, + 0, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 2, + 2, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 1, + 2, + 3, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +}; diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/yes_simple_features_data.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/yes_simple_features_data.h new file mode 100644 index 00000000..2d2cb559 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/simple_features/yes_simple_features_data.h @@ -0,0 +1,23 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_YES_SIMPLE_FEATURES_DATA_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_YES_SIMPLE_FEATURES_DATA_H_ + +extern const int g_yes_simple_f2e59fea_nohash_1_width; +extern const int g_yes_simple_f2e59fea_nohash_1_height; +extern const unsigned char g_yes_simple_f2e59fea_nohash_1_data[]; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_SIMPLE_FEATURES_YES_SIMPLE_FEATURES_DATA_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/train/README.md b/components/tflite/tensorflow/lite/micro/examples/micro_speech/train/README.md new file mode 100644 index 00000000..2ffe3e26 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/train/README.md @@ -0,0 +1,207 @@ + +# Micro Speech Training + +This example shows how to train a 20 kB model that can recognize 2 keywords, +"yes" and "no", from speech data. + +If the input does not belong to either categories, it is classified as "unknown" +and if the input is silent, it is classified as "silence". + +You can retrain it to recognize any combination of words (2 or more) from this +list: + +``` +yes +no +up +down +left +right +on +off +stop +go +``` + +The scripts used in training the model have been sourced from the +[Simple Audio Recognition](https://www.tensorflow.org/tutorials/audio/simple_audio) +tutorial. + +## Table of contents + +- [Overview](#overview) +- [Training](#training) +- [Trained Models](#trained-models) +- [Model Architecture](#model-architecture) +- [Dataset](#dataset) +- [Preprocessing Speech Input](#preprocessing-speech-input) +- [Other Training Methods](#other-training-methods) + +## Overview + +1. Dataset: Speech Commands, Version 2. + ([Download Link](https://storage.cloud.google.com/download.tensorflow.org/data/speech_commands_v0.02.tar.gz), + [Paper](https://arxiv.org/abs/1804.03209)) +2. Dataset Type: **Speech** +3. Deep Learning Framework: **TensorFlow 1.5** +4. Language: **Python 3.7** +5. Model Size: **<20 kB** +6. Model Category: **Multiclass Classification** + +## Training + +Train the model in the cloud using Google Colaboratory or locally using a +Jupyter Notebook. + + + + +
+ Google Colaboratory + + Jupyter Notebook +
+ +*Estimated Training Time: ~2 Hours.* + +For more options, refer to the [Other Training Methods](#other-training-methods) +section. + +## Trained Models + +| Download Link | [speech_commands.zip](https://storage.googleapis.com/download.tensorflow.org/models/tflite/micro/micro_speech_2020_04_13.zip) | +| ------------- |-------------| + +The `models` directory in the above zip file can be generated by following the +instructions in the [Training](#training) section above. It +includes the following 3 model files: + +| Name | Format | Target Framework | Target Device | +| :------------- | :----------- | :--------------- | :------------------------ | +| `model.pb` | Frozen | TensorFlow | Large-Scale/Cloud/Servers | +: : GraphDef : : : +| `model.tflite` | Fully | TensorFlow Lite | Mobile Devices | +: *(<20 kB)* : Quantized* : : : +: : TFLite Model : : : +| `model.cc` | C Source | TensorFlow Lite | Microcontrollers | +: : File : for : : +: : : Microcontrollers : : + +**Fully quantized implies that the model is **strictly int8** quantized +**including** the input(s) and output(s).* + + +## Model Architecture + +This is a simple model comprising of a Convolutional 2D layer, a Fully Connected +Layer or a MatMul Layer (output: logits) and a Softmax layer +(output: probabilities) as shown below. Refer to the [`tiny_conv`](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/speech_commands/models.py#L673) +model architecture. + +![model_architecture.png](../images/model_architecture.png) + +*This image was derived from visualizing the 'model.tflite' file in +[Netron](https://github.com/lutzroeder/netron)* + +This doesn't produce a highly accurate model, but it's designed to be used as +the first stage of a pipeline, running on a low-energy piece of hardware that +can always be on, and then wake higher-power chips when a possible utterance has +been found, so that more accurate analysis can be done. Additionally, the model +takes in preprocessed speech input as a result of which we can leverage a +simpler model for accurate results. + +## Dataset + +The Speech Commands Dataset. ([Download Link](https://storage.cloud.google.com/download.tensorflow.org/data/speech_commands_v0.02.tar.gz), +[Paper](https://arxiv.org/abs/1804.03209)) consists of over 105,000 WAVE audio +files of people saying thirty different words. This data was collected by +Google and released under a CC BY license. You can help improve it by +contributing five minutes of your own voice. The archive is over 2GB, so this +part may take a while, but you should see progress logs, and once it's been +downloaded you won't need to do this again. + +## Preprocessing Speech Input + +In this section we discuss spectrograms, the preprocessed speech input to the +model. Here's an illustration of the process: + +![spectrogram diagram](https://storage.googleapis.com/download.tensorflow.org/example_images/spectrogram_diagram.png) + +The model doesn't take in raw audio sample data, instead it works with +spectrograms which are two dimensional arrays that are made up of slices of +frequency information, each taken from a different time window. + +The recipe for creating the spectrogram data is that each frequency slice is +created by running an FFT across a 30ms section of the audio sample data. The +input samples are treated as being between -1 and +1 as real values (encoded as +-32,768 and 32,767 in 16-bit signed integer samples). + +This results in an FFT with 256 entries. Every sequence of six entries is +averaged together, giving a total of 43 frequency buckets in the final slice. +The results are stored as unsigned eight-bit values, where 0 represents a real +number of zero, and 255 represents 127.5 as a real number. + +Each adjacent frequency entry is stored in ascending memory order (frequency +bucket 0 at data[0], bucket 1 at data[1], etc). The window for the frequency +analysis is then moved forward by 20ms, and the process repeated, storing the +results in the next memory row (for example bucket 0 in this moved window would +be in data[43 + 0], etc). This process happens 49 times in total, producing a +single channel image that is 43 pixels wide, and 49 rows high. + +In a complete application these spectrograms would be calculated at runtime from +microphone inputs, but the code for doing that is not yet included in this +sample code. The test uses spectrograms that have been pre-calculated from +one-second WAV files in the test dataset generated by running the following +commands: + +``` +python tensorflow/tensorflow/examples/speech_commands/wav_to_features.py \ +--input_wav=/tmp/speech_dataset/yes/f2e59fea_nohash_1.wav \ +--output_c_file=/tmp/yes_features_data.cc \ +--window_stride=20 --preprocess=average --quantize=1 + +python tensorflow/tensorflow/examples/speech_commands/wav_to_features.py \ +--input_wav=/tmp/speech_dataset/no/f9643d42_nohash_4.wav \ +--output_c_file=/tmp/no_features_data.cc \ +--window_stride=20 --preprocess=average --quantize=1 +``` + + +## Other Training Methods + +### Use [Google Cloud](https://cloud.google.com/). + +*Note: Google Cloud isn't free. You need to pay depending on how long you use +run the VM and what resources you use.* + +1. Create a Virtual Machine (VM) using a pre-configured Deep Learning VM Image. + +``` +export IMAGE_FAMILY="tf-latest-cpu" +export ZONE="us-west1-b" # Or any other required region +export INSTANCE_NAME="model-trainer" +export INSTANCE_TYPE="n1-standard-8" # or any other instance type +gcloud compute instances create $INSTANCE_NAME \ + --zone=$ZONE \ + --image-family=$IMAGE_FAMILY \ + --image-project=deeplearning-platform-release \ + --machine-type=$INSTANCE_TYPE \ + --boot-disk-size=120GB \ + --min-cpu-platform=Intel\ Skylake +``` + +2. As soon as instance has been created you can SSH to it: + +``` +gcloud compute ssh "jupyter@${INSTANCE_NAME}" +``` + +3. Train a model by following the instructions in the [`train_micro_speech_model.ipynb`](train_micro_speech_model.ipynb) +jupyter notebook. + +4. Finally, don't forget to remove the instance when training is done: + +``` +gcloud compute instances delete "${INSTANCE_NAME}" --zone="${ZONE}" +``` diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/train/train_micro_speech_model.ipynb b/components/tflite/tensorflow/lite/micro/examples/micro_speech/train/train_micro_speech_model.ipynb new file mode 100644 index 00000000..1a1d5ff2 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/train/train_micro_speech_model.ipynb @@ -0,0 +1,599 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "train_micro_speech_model.ipynb", + "provenance": [], + "collapsed_sections": [], + "toc_visible": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "accelerator": "GPU" + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "pO4-CY_TCZZS", + "colab_type": "text" + }, + "source": [ + "# Train a Simple Audio Recognition Model" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "BaFfr7DHRmGF", + "colab_type": "text" + }, + "source": [ + "This notebook demonstrates how to train a 20 kB [Simple Audio Recognition](https://www.tensorflow.org/tutorials/sequences/audio_recognition) model to recognize keywords in speech.\n", + "\n", + "The model created in this notebook is used in the [micro_speech](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/micro/examples/micro_speech) example for [TensorFlow Lite for MicroControllers](https://www.tensorflow.org/lite/microcontrollers/overview).\n", + "\n", + "\n", + " \n", + " \n", + "
\n", + " Run in Google Colab\n", + " \n", + " View source on GitHub\n", + "
\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "XaVtYN4nlCft", + "colab_type": "text" + }, + "source": [ + "**Training is much faster using GPU acceleration.** Before you proceed, ensure you are using a GPU runtime by going to **Runtime -> Change runtime type** and set **Hardware accelerator: GPU**. Training 15,000 iterations will take 1.5 - 2 hours on a GPU runtime.\n", + "\n", + "## Configure Defaults\n", + "\n", + "**MODIFY** the following constants for your specific use case." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "ludfxbNIaegy", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# A comma-delimited list of the words you want to train for.\n", + "# The options are: yes,no,up,down,left,right,on,off,stop,go\n", + "# All the other words will be used to train an \"unknown\" label and silent\n", + "# audio data with no spoken words will be used to train a \"silence\" label.\n", + "WANTED_WORDS = \"yes,no\"\n", + "\n", + "# The number of steps and learning rates can be specified as comma-separated\n", + "# lists to define the rate at each stage. For example,\n", + "# TRAINING_STEPS=12000,3000 and LEARNING_RATE=0.001,0.0001\n", + "# will run 12,000 training loops in total, with a rate of 0.001 for the first\n", + "# 8,000, and 0.0001 for the final 3,000.\n", + "TRAINING_STEPS = \"12000,3000\"\n", + "LEARNING_RATE = \"0.001,0.0001\"\n", + "\n", + "# Calculate the total number of steps, which is used to identify the checkpoint\n", + "# file name.\n", + "TOTAL_STEPS = str(sum(map(lambda string: int(string), TRAINING_STEPS.split(\",\"))))\n", + "\n", + "# Print the configuration to confirm it\n", + "print(\"Training these words: %s\" % WANTED_WORDS)\n", + "print(\"Training steps in each stage: %s\" % TRAINING_STEPS)\n", + "print(\"Learning rate in each stage: %s\" % LEARNING_RATE)\n", + "print(\"Total number of training steps: %s\" % TOTAL_STEPS)" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "gCgeOpvY9pAi", + "colab_type": "text" + }, + "source": [ + "**DO NOT MODIFY** the following constants as they include filepaths used in this notebook and data that is shared during training and inference." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "Nd1iM1o2ymvA", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Calculate the percentage of 'silence' and 'unknown' training samples required\n", + "# to ensure that we have equal number of samples for each label.\n", + "number_of_labels = WANTED_WORDS.count(',') + 1\n", + "number_of_total_labels = number_of_labels + 2 # for 'silence' and 'unknown' label\n", + "equal_percentage_of_training_samples = int(100.0/(number_of_total_labels))\n", + "SILENT_PERCENTAGE = equal_percentage_of_training_samples\n", + "UNKNOWN_PERCENTAGE = equal_percentage_of_training_samples\n", + "\n", + "# Constants which are shared during training and inference\n", + "PREPROCESS = 'micro'\n", + "WINDOW_STRIDE = 20\n", + "MODEL_ARCHITECTURE = 'tiny_conv' # Other options include: single_fc, conv,\n", + " # low_latency_conv, low_latency_svdf, tiny_embedding_conv\n", + "\n", + "# Constants used during training only\n", + "VERBOSITY = 'WARN'\n", + "EVAL_STEP_INTERVAL = '1000'\n", + "SAVE_STEP_INTERVAL = '1000'\n", + "\n", + "# Constants for training directories and filepaths\n", + "DATASET_DIR = 'dataset/'\n", + "LOGS_DIR = 'logs/'\n", + "TRAIN_DIR = 'train/' # for training checkpoints and other files.\n", + "\n", + "# Constants for inference directories and filepaths\n", + "import os\n", + "MODELS_DIR = 'models'\n", + "if not os.path.exists(MODELS_DIR):\n", + " os.mkdir(MODELS_DIR)\n", + "MODEL_TF = os.path.join(MODELS_DIR, 'model.pb')\n", + "MODEL_TFLITE = os.path.join(MODELS_DIR, 'model.tflite')\n", + "FLOAT_MODEL_TFLITE = os.path.join(MODELS_DIR, 'float_model.tflite')\n", + "MODEL_TFLITE_MICRO = os.path.join(MODELS_DIR, 'model.cc')\n", + "SAVED_MODEL = os.path.join(MODELS_DIR, 'saved_model')\n", + "\n", + "QUANT_INPUT_MIN = 0.0\n", + "QUANT_INPUT_MAX = 26.0\n", + "QUANT_INPUT_RANGE = QUANT_INPUT_MAX - QUANT_INPUT_MIN" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "6rLYpvtg9P4o", + "colab_type": "text" + }, + "source": [ + "## Setup Environment\n", + "\n", + "Install Dependencies" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "ed_XpUrU5DvY", + "colab_type": "code", + "colab": {} + }, + "source": [ + "%tensorflow_version 1.x\n", + "import tensorflow as tf" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "T9Ty5mR58E4i", + "colab_type": "text" + }, + "source": [ + "**DELETE** any old data from previous runs\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "APGx0fEh7hFF", + "colab_type": "code", + "colab": {} + }, + "source": [ + "!rm -rf {DATASET_DIR} {LOGS_DIR} {TRAIN_DIR} {MODELS_DIR}" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "GfEUlfFBizio", + "colab_type": "text" + }, + "source": [ + "Clone the TensorFlow Github Repository, which contains the relevant code required to run this tutorial." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "yZArmzT85SLq", + "colab_type": "code", + "colab": {} + }, + "source": [ + "!git clone -q --depth 1 https://github.com/tensorflow/tensorflow" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "nS9swHLSi7Bi", + "colab_type": "text" + }, + "source": [ + "Load TensorBoard to visualize the accuracy and loss as training proceeds.\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "q4qF1VxP3UE4", + "colab_type": "code", + "colab": {} + }, + "source": [ + "%load_ext tensorboard\n", + "%tensorboard --logdir {LOGS_DIR}" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "x1J96Ron-O4R", + "colab_type": "text" + }, + "source": [ + "## Training\n", + "\n", + "The following script downloads the dataset and begin training." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "VJsEZx6lynbY", + "colab_type": "code", + "colab": {} + }, + "source": [ + "!python tensorflow/tensorflow/examples/speech_commands/train.py \\\n", + "--data_dir={DATASET_DIR} \\\n", + "--wanted_words={WANTED_WORDS} \\\n", + "--silence_percentage={SILENT_PERCENTAGE} \\\n", + "--unknown_percentage={UNKNOWN_PERCENTAGE} \\\n", + "--preprocess={PREPROCESS} \\\n", + "--window_stride={WINDOW_STRIDE} \\\n", + "--model_architecture={MODEL_ARCHITECTURE} \\\n", + "--how_many_training_steps={TRAINING_STEPS} \\\n", + "--learning_rate={LEARNING_RATE} \\\n", + "--train_dir={TRAIN_DIR} \\\n", + "--summaries_dir={LOGS_DIR} \\\n", + "--verbosity={VERBOSITY} \\\n", + "--eval_step_interval={EVAL_STEP_INTERVAL} \\\n", + "--save_step_interval={SAVE_STEP_INTERVAL}" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "UczQKtqLi7OJ", + "colab_type": "text" + }, + "source": [ + "# Skipping the training\n", + "\n", + "If you don't want to spend an hour or two training the model from scratch, you can download pretrained checkpoints by uncommenting the lines below (removing the '#'s at the start of each line) and running them." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "RZw3VNlnla-J", + "colab_type": "code", + "colab": {} + }, + "source": [ + "#!curl -O \"https://storage.googleapis.com/download.tensorflow.org/models/tflite/speech_micro_train_2020_05_10.tgz\"\n", + "#!tar xzf speech_micro_train_2020_05_10.tgz" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "XQUJLrdS-ftl", + "colab_type": "text" + }, + "source": [ + "## Generate a TensorFlow Model for Inference\n", + "\n", + "Combine relevant training results (graph, weights, etc) into a single file for inference. This process is known as freezing a model and the resulting model is known as a frozen model/graph, as it cannot be further re-trained after this process." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "xyc3_eLh9sAg", + "colab_type": "code", + "colab": {} + }, + "source": [ + "!rm -rf {SAVED_MODEL}\n", + "!python tensorflow/tensorflow/examples/speech_commands/freeze.py \\\n", + "--wanted_words=$WANTED_WORDS \\\n", + "--window_stride_ms=$WINDOW_STRIDE \\\n", + "--preprocess=$PREPROCESS \\\n", + "--model_architecture=$MODEL_ARCHITECTURE \\\n", + "--start_checkpoint=$TRAIN_DIR$MODEL_ARCHITECTURE'.ckpt-'{TOTAL_STEPS} \\\n", + "--save_format=saved_model \\\n", + "--output_file={SAVED_MODEL}" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "_DBGDxVI-nKG", + "colab_type": "text" + }, + "source": [ + "## Generate a TensorFlow Lite Model\n", + "\n", + "Convert the frozen graph into a TensorFlow Lite model, which is fully quantized for use with embedded devices.\n", + "\n", + "The following cell will also print the model size, which will be under 20 kilobytes." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "RIitkqvGWmre", + "colab_type": "code", + "colab": {} + }, + "source": [ + "import sys\n", + "# We add this path so we can import the speech processing modules.\n", + "sys.path.append(\"/content/tensorflow/tensorflow/examples/speech_commands/\")\n", + "import input_data\n", + "import models\n", + "import numpy as np" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "kzqECqMxgBh4", + "colab_type": "code", + "colab": {} + }, + "source": [ + "SAMPLE_RATE = 16000\n", + "CLIP_DURATION_MS = 1000\n", + "WINDOW_SIZE_MS = 30.0\n", + "FEATURE_BIN_COUNT = 40\n", + "BACKGROUND_FREQUENCY = 0.8\n", + "BACKGROUND_VOLUME_RANGE = 0.1\n", + "TIME_SHIFT_MS = 100.0\n", + "\n", + "DATA_URL = 'https://storage.googleapis.com/download.tensorflow.org/data/speech_commands_v0.02.tar.gz'\n", + "VALIDATION_PERCENTAGE = 10\n", + "TESTING_PERCENTAGE = 10" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "rNQdAplJV1fz", + "colab_type": "code", + "colab": {} + }, + "source": [ + "model_settings = models.prepare_model_settings(\n", + " len(input_data.prepare_words_list(WANTED_WORDS.split(','))),\n", + " SAMPLE_RATE, CLIP_DURATION_MS, WINDOW_SIZE_MS,\n", + " WINDOW_STRIDE, FEATURE_BIN_COUNT, PREPROCESS)\n", + "audio_processor = input_data.AudioProcessor(\n", + " DATA_URL, DATASET_DIR,\n", + " SILENT_PERCENTAGE, UNKNOWN_PERCENTAGE,\n", + " WANTED_WORDS.split(','), VALIDATION_PERCENTAGE,\n", + " TESTING_PERCENTAGE, model_settings, LOGS_DIR)" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "lBj_AyCh1cC0", + "colab_type": "code", + "colab": {} + }, + "source": [ + "with tf.Session() as sess:\n", + " float_converter = tf.lite.TFLiteConverter.from_saved_model(SAVED_MODEL)\n", + " float_tflite_model = float_converter.convert()\n", + " float_tflite_model_size = open(FLOAT_MODEL_TFLITE, \"wb\").write(float_tflite_model)\n", + " print(\"Float model is %d bytes\" % float_tflite_model_size)\n", + "\n", + " converter = tf.lite.TFLiteConverter.from_saved_model(SAVED_MODEL)\n", + " converter.optimizations = [tf.lite.Optimize.DEFAULT]\n", + " converter.inference_input_type = tf.lite.constants.INT8\n", + " converter.inference_output_type = tf.lite.constants.INT8\n", + " def representative_dataset_gen():\n", + " for i in range(100):\n", + " data, _ = audio_processor.get_data(1, i*1, model_settings,\n", + " BACKGROUND_FREQUENCY, \n", + " BACKGROUND_VOLUME_RANGE,\n", + " TIME_SHIFT_MS,\n", + " 'testing',\n", + " sess)\n", + " flattened_data = np.array(data.flatten(), dtype=np.float32).reshape(1, 1960)\n", + " yield [flattened_data]\n", + " converter.representative_dataset = representative_dataset_gen\n", + " tflite_model = converter.convert()\n", + " tflite_model_size = open(MODEL_TFLITE, \"wb\").write(tflite_model)\n", + " print(\"Quantized model is %d bytes\" % tflite_model_size)\n" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "EeLiDZTbLkzv", + "colab_type": "text" + }, + "source": [ + "## Testing the TensorFlow Lite model's accuracy\n", + "\n", + "Verify that the model we've exported is still accurate, using the TF Lite Python API and our test set." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "wQsEteKRLryJ", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Helper function to run inference\n", + "def run_tflite_inference(tflite_model_path, model_type=\"Float\"):\n", + " # Load test data\n", + " np.random.seed(0) # set random seed for reproducible test results.\n", + " with tf.Session() as sess:\n", + " test_data, test_labels = audio_processor.get_data(\n", + " -1, 0, model_settings, BACKGROUND_FREQUENCY, BACKGROUND_VOLUME_RANGE,\n", + " TIME_SHIFT_MS, 'testing', sess)\n", + " test_data = np.expand_dims(test_data, axis=1).astype(np.float32)\n", + "\n", + " # Initialize the interpreter\n", + " interpreter = tf.lite.Interpreter(tflite_model_path)\n", + " interpreter.allocate_tensors()\n", + "\n", + " input_details = interpreter.get_input_details()[0]\n", + " output_details = interpreter.get_output_details()[0]\n", + "\n", + " # For quantized models, manually quantize the input data from float to integer\n", + " if model_type == \"Quantized\":\n", + " input_scale, input_zero_point = input_details[\"quantization\"]\n", + " test_data = test_data / input_scale + input_zero_point\n", + " test_data = test_data.astype(input_details[\"dtype\"])\n", + "\n", + " correct_predictions = 0\n", + " for i in range(len(test_data)):\n", + " interpreter.set_tensor(input_details[\"index\"], test_data[i])\n", + " interpreter.invoke()\n", + " output = interpreter.get_tensor(output_details[\"index\"])[0]\n", + " top_prediction = output.argmax()\n", + " correct_predictions += (top_prediction == test_labels[i])\n", + "\n", + " print('%s model accuracy is %f%% (Number of test samples=%d)' % (\n", + " model_type, (correct_predictions * 100) / len(test_data), len(test_data)))" + ], + "execution_count": 110, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "l-pD52Na6jRa", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Compute float model accuracy\n", + "run_tflite_inference(FLOAT_MODEL_TFLITE)\n", + "\n", + "# Compute quantized model accuracy\n", + "run_tflite_inference(MODEL_TFLITE, model_type='Quantized')" + ], + "execution_count": 111, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "dt6Zqbxu-wIi", + "colab_type": "text" + }, + "source": [ + "## Generate a TensorFlow Lite for MicroControllers Model\n", + "Convert the TensorFlow Lite model into a C source file that can be loaded by TensorFlow Lite for Microcontrollers." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "XohZOTjR8ZyE", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Install xxd if it is not available\n", + "!apt-get update && apt-get -qq install xxd\n", + "# Convert to a C source file\n", + "!xxd -i {MODEL_TFLITE} > {MODEL_TFLITE_MICRO}\n", + "# Update variable names\n", + "REPLACE_TEXT = MODEL_TFLITE.replace('/', '_').replace('.', '_')\n", + "!sed -i 's/'{REPLACE_TEXT}'/g_model/g' {MODEL_TFLITE_MICRO}" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "2pQnN0i_-0L2", + "colab_type": "text" + }, + "source": [ + "## Deploy to a Microcontroller\n", + "\n", + "Follow the instructions in the [micro_speech](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/micro/examples/micro_speech) README.md for [TensorFlow Lite for MicroControllers](https://www.tensorflow.org/lite/microcontrollers/overview) to deploy this model on a specific microcontroller.\n", + "\n", + "**Reference Model:** If you have not modified this notebook, you can follow the instructions as is, to deploy the model. Refer to the [`micro_speech/train/models`](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/micro/examples/micro_speech/train/models) directory to access the models generated in this notebook.\n", + "\n", + "**New Model:** If you have generated a new model to identify different words: (i) Update `kCategoryCount` and `kCategoryLabels` in [`micro_speech/micro_features/micro_model_settings.h`](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.h) and (ii) Update the values assigned to the variables defined in [`micro_speech/micro_features/model.cc`](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/micro/examples/micro_speech/micro_features/model.cc) with values displayed after running the following cell." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "eoYyh0VU8pca", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Print the C source file\n", + "!cat {MODEL_TFLITE_MICRO}" + ], + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/train_speech_model.ipynb b/components/tflite/tensorflow/lite/micro/examples/micro_speech/train_speech_model.ipynb new file mode 100644 index 00000000..fb56dc3a --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/train_speech_model.ipynb @@ -0,0 +1 @@ +{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"Redirect","provenance":[],"collapsed_sections":[],"authorship_tag":"ABX9TyO1u6oks1qPVEQNnHFD3Cyo"},"kernelspec":{"name":"python3","display_name":"Python 3"}},"cells":[{"cell_type":"markdown","metadata":{"id":"86C-FMxpdZxv","colab_type":"text"},"source":["This Colab notebook has been moved to [https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/micro/examples/micro_speech/train/train_micro_speech_model.ipynb](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/micro/examples/micro_speech/train/train_micro_speech_model.ipynb)\n"]}]} \ No newline at end of file diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/yes_1000ms_sample_data.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/yes_1000ms_sample_data.cc new file mode 100644 index 00000000..009bf1bf --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/yes_1000ms_sample_data.cc @@ -0,0 +1,16022 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// See the header for documentation on the meaning of this data. + +#include "tensorflow/lite/micro/examples/micro_speech/yes_1000ms_sample_data.h" + +const int g_yes_1000ms_sample_data_size = 16000; +const int16_t g_yes_1000ms_sample_data[16000] = { + -7, + -12, + -18, + -20, + -20, + -21, + -21, + -25, + -29, + -31, + -31, + -30, + -30, + -29, + -30, + -30, + -29, + -28, + -24, + -22, + -17, + -12, + -8, + -7, + -6, + -1, + 2, + 5, + 7, + 8, + 11, + 15, + 18, + 19, + 23, + 24, + 24, + 27, + 27, + 26, + 25, + 28, + 30, + 32, + 33, + 31, + 29, + 27, + 28, + 30, + 28, + 26, + 26, + 24, + 22, + 17, + 16, + 15, + 13, + 10, + 5, + 0, + -4, + -4, + -7, + -9, + -12, + -14, + -14, + -13, + -11, + -10, + -8, + -6, + -3, + 3, + 7, + 8, + 12, + 15, + 18, + 21, + 19, + 19, + 21, + 23, + 24, + 23, + 22, + 19, + 17, + 11, + 5, + -3, + -12, + -22, + -28, + -35, + -45, + -54, + -62, + -69, + -76, + -84, + -92, + -100, + -109, + -116, + -117, + -120, + -120, + -120, + -122, + -124, + -126, + -123, + -121, + -116, + -113, + -107, + -97, + -88, + -75, + -61, + -50, + -41, + -27, + -12, + 4, + 21, + 37, + 58, + 76, + 93, + 108, + 121, + 137, + 156, + 172, + 184, + 196, + 205, + 215, + 224, + 235, + 242, + 245, + 242, + 240, + 238, + 231, + 223, + 214, + 205, + 195, + 178, + 158, + 135, + 112, + 90, + 69, + 46, + 19, + -11, + -45, + -76, + -105, + -133, + -159, + -186, + -211, + -236, + -260, + -280, + -294, + -308, + -320, + -331, + -336, + -338, + -335, + -326, + -316, + -301, + -286, + -267, + -246, + -225, + -203, + -180, + -154, + -124, + -91, + -59, + -34, + -8, + 19, + 42, + 64, + 87, + 103, + 119, + 134, + 148, + 162, + 174, + 182, + 188, + 190, + 189, + 187, + 184, + 180, + 177, + 171, + 162, + 154, + 144, + 137, + 129, + 118, + 106, + 95, + 81, + 69, + 58, + 48, + 37, + 26, + 14, + 3, + -7, + -22, + -31, + -42, + -52, + -62, + -69, + -75, + -79, + -82, + -87, + -88, + -92, + -94, + -91, + -87, + -85, + -81, + -74, + -70, + -64, + -55, + -47, + -40, + -33, + -25, + -19, + -12, + -6, + -4, + -1, + 1, + 1, + -2, + -9, + -15, + -17, + -18, + -20, + -22, + -22, + -26, + -31, + -33, + -35, + -31, + -26, + -17, + -4, + 8, + 19, + 31, + 44, + 54, + 64, + 71, + 79, + 86, + 92, + 102, + 109, + 111, + 109, + 104, + 96, + 84, + 70, + 60, + 51, + 38, + 27, + 13, + 4, + -3, + -9, + -13, + -18, + -26, + -33, + -32, + -27, + -20, + -10, + -4, + 2, + 6, + 10, + 14, + 16, + 21, + 25, + 29, + 31, + 33, + 35, + 37, + 33, + 22, + 15, + 13, + 11, + 12, + 9, + 5, + 2, + 1, + -3, + -9, + -17, + -27, + -32, + -35, + -36, + -36, + -42, + -50, + -56, + -66, + -77, + -85, + -96, + -100, + -106, + -113, + -118, + -121, + -119, + -117, + -119, + -122, + -124, + -123, + -112, + -94, + -77, + -64, + -51, + -37, + -22, + -3, + 17, + 37, + 54, + 68, + 86, + 100, + 114, + 134, + 154, + 167, + 174, + 178, + 182, + 189, + 189, + 187, + 185, + 179, + 177, + 174, + 171, + 157, + 138, + 123, + 108, + 94, + 76, + 50, + 25, + 6, + -8, + -20, + -37, + -59, + -86, + -110, + -132, + -147, + -159, + -169, + -178, + -191, + -203, + -213, + -217, + -215, + -208, + -199, + -194, + -195, + -190, + -178, + -165, + -155, + -144, + -134, + -123, + -103, + -80, + -56, + -35, + -18, + -4, + 11, + 23, + 36, + 50, + 65, + 78, + 93, + 111, + 122, + 129, + 132, + 131, + 127, + 125, + 126, + 126, + 128, + 127, + 125, + 122, + 118, + 111, + 108, + 104, + 99, + 93, + 89, + 90, + 87, + 82, + 78, + 75, + 68, + 65, + 67, + 69, + 66, + 61, + 54, + 39, + 28, + 15, + 3, + -7, + -18, + -25, + -29, + -35, + -42, + -52, + -66, + -78, + -83, + -85, + -86, + -86, + -82, + -83, + -84, + -83, + -81, + -75, + -62, + -57, + -53, + -49, + -46, + -41, + -34, + -26, + -16, + -10, + -7, + -2, + 2, + 6, + 12, + 15, + 19, + 18, + 15, + 17, + 21, + 24, + 30, + 33, + 27, + 22, + 21, + 20, + 23, + 24, + 21, + 15, + 13, + 8, + 3, + 1, + -1, + -3, + -4, + -6, + -9, + -11, + -11, + -8, + -10, + -13, + -15, + -19, + -17, + -11, + -2, + 1, + 2, + 6, + 9, + 10, + 12, + 13, + 9, + 8, + 10, + 13, + 20, + 18, + 13, + 10, + 4, + 1, + -2, + -6, + -11, + -13, + -16, + -18, + -15, + -18, + -21, + -21, + -22, + -23, + -25, + -23, + -22, + -20, + -19, + -16, + -12, + -10, + -9, + -11, + -15, + -19, + -22, + -19, + -14, + -11, + -9, + -11, + -17, + -20, + -18, + -19, + -15, + -11, + -8, + -2, + 8, + 19, + 30, + 36, + 37, + 36, + 38, + 45, + 57, + 69, + 77, + 81, + 79, + 75, + 76, + 74, + 69, + 66, + 60, + 53, + 45, + 36, + 28, + 22, + 17, + 10, + 0, + -5, + -11, + -15, + -18, + -26, + -31, + -33, + -34, + -34, + -35, + -37, + -37, + -35, + -28, + -24, + -29, + -37, + -45, + -46, + -41, + -36, + -31, + -32, + -33, + -37, + -37, + -36, + -36, + -34, + -27, + -19, + -14, + -11, + -8, + -1, + 6, + 14, + 19, + 21, + 25, + 30, + 34, + 38, + 38, + 33, + 26, + 22, + 19, + 20, + 18, + 17, + 15, + 10, + 2, + -3, + -5, + -10, + -13, + -13, + -13, + -16, + -16, + -16, + -15, + -13, + -14, + -13, + -16, + -19, + -20, + -18, + -17, + -18, + -16, + -16, + -24, + -28, + -28, + -28, + -23, + -21, + -21, + -20, + -24, + -27, + -23, + -18, + -14, + -7, + 4, + 11, + 15, + 19, + 21, + 25, + 33, + 39, + 41, + 45, + 47, + 50, + 56, + 58, + 57, + 59, + 59, + 55, + 50, + 47, + 39, + 34, + 30, + 24, + 18, + 11, + 8, + 3, + 0, + -3, + -8, + -14, + -15, + -13, + -13, + -12, + -14, + -17, + -17, + -12, + -10, + -4, + -7, + -12, + -10, + -14, + -17, + -17, + -19, + -25, + -28, + -27, + -29, + -30, + -31, + -35, + -38, + -43, + -47, + -51, + -52, + -50, + -49, + -48, + -47, + -45, + -39, + -32, + -30, + -31, + -35, + -35, + -31, + -24, + -17, + -12, + -11, + -14, + -15, + -17, + -16, + -9, + -5, + -3, + -1, + 0, + 1, + 0, + 3, + 12, + 21, + 26, + 33, + 35, + 38, + 45, + 50, + 53, + 53, + 54, + 58, + 61, + 64, + 69, + 67, + 66, + 64, + 58, + 54, + 51, + 46, + 44, + 45, + 41, + 35, + 31, + 27, + 25, + 27, + 25, + 20, + 13, + 12, + 16, + 17, + 17, + 12, + 7, + 3, + 2, + -2, + -4, + -8, + -14, + -19, + -25, + -29, + -38, + -49, + -60, + -69, + -73, + -71, + -74, + -82, + -89, + -98, + -103, + -104, + -103, + -99, + -98, + -98, + -98, + -99, + -97, + -94, + -91, + -85, + -82, + -78, + -74, + -74, + -71, + -68, + -61, + -54, + -52, + -47, + -41, + -36, + -32, + -21, + -12, + -3, + 11, + 26, + 36, + 44, + 48, + 55, + 64, + 77, + 92, + 100, + 108, + 117, + 120, + 122, + 128, + 130, + 129, + 130, + 127, + 124, + 122, + 121, + 118, + 114, + 110, + 102, + 92, + 85, + 80, + 77, + 68, + 55, + 46, + 39, + 36, + 34, + 31, + 27, + 15, + 5, + -1, + -5, + -11, + -20, + -29, + -37, + -43, + -46, + -47, + -54, + -61, + -65, + -74, + -82, + -84, + -91, + -94, + -96, + -104, + -109, + -111, + -111, + -112, + -113, + -111, + -112, + -110, + -104, + -99, + -96, + -93, + -89, + -87, + -81, + -71, + -63, + -54, + -45, + -43, + -37, + -30, + -24, + -17, + -12, + -8, + -2, + 2, + 15, + 23, + 28, + 35, + 41, + 42, + 44, + 52, + 58, + 66, + 74, + 78, + 80, + 82, + 85, + 88, + 90, + 92, + 92, + 88, + 87, + 87, + 79, + 73, + 69, + 64, + 62, + 55, + 50, + 45, + 41, + 36, + 29, + 24, + 20, + 16, + 12, + 8, + 5, + 2, + 1, + 1, + 0, + 1, + -4, + -4, + -4, + -4, + -1, + 1, + 2, + 1, + -3, + -6, + -1, + 5, + 6, + 7, + 8, + 4, + 2, + 0, + -2, + -3, + 0, + -3, + -4, + -3, + -4, + -5, + -8, + -15, + -20, + -25, + -28, + -32, + -37, + -38, + -39, + -43, + -48, + -55, + -62, + -69, + -75, + -75, + -78, + -81, + -83, + -89, + -89, + -92, + -91, + -91, + -89, + -83, + -81, + -74, + -66, + -63, + -54, + -45, + -39, + -31, + -23, + -15, + -4, + 6, + 14, + 23, + 29, + 35, + 41, + 45, + 49, + 55, + 61, + 69, + 75, + 75, + 76, + 75, + 74, + 74, + 73, + 74, + 72, + 69, + 69, + 65, + 62, + 57, + 52, + 44, + 35, + 33, + 29, + 24, + 14, + 7, + 3, + -4, + -12, + -17, + -20, + -22, + -27, + -32, + -34, + -39, + -42, + -43, + -42, + -43, + -40, + -38, + -36, + -36, + -37, + -36, + -33, + -31, + -27, + -24, + -23, + -22, + -17, + -11, + -7, + -7, + -7, + -3, + 5, + 13, + 19, + 25, + 27, + 25, + 27, + 35, + 40, + 40, + 41, + 45, + 47, + 50, + 54, + 52, + 50, + 45, + 43, + 44, + 40, + 34, + 28, + 24, + 18, + 11, + 6, + -2, + -9, + -14, + -21, + -27, + -35, + -39, + -43, + -50, + -57, + -62, + -66, + -68, + -71, + -72, + -73, + -74, + -76, + -76, + -77, + -75, + -75, + -74, + -67, + -61, + -55, + -49, + -45, + -40, + -30, + -21, + -11, + -4, + 4, + 13, + 23, + 34, + 44, + 52, + 59, + 65, + 70, + 77, + 84, + 87, + 88, + 90, + 91, + 90, + 89, + 85, + 80, + 75, + 72, + 71, + 64, + 56, + 48, + 41, + 34, + 27, + 21, + 12, + 1, + -11, + -19, + -28, + -33, + -39, + -46, + -50, + -53, + -58, + -63, + -66, + -71, + -73, + -76, + -76, + -74, + -73, + -71, + -67, + -65, + -62, + -60, + -55, + -51, + -45, + -39, + -35, + -31, + -27, + -20, + -13, + -6, + -3, + 1, + 8, + 12, + 18, + 24, + 26, + 30, + 35, + 38, + 44, + 47, + 47, + 51, + 53, + 52, + 53, + 52, + 50, + 51, + 49, + 50, + 51, + 50, + 48, + 48, + 45, + 43, + 42, + 37, + 34, + 31, + 31, + 30, + 26, + 24, + 21, + 15, + 12, + 11, + 7, + 4, + 1, + -3, + -5, + -7, + -9, + -15, + -21, + -26, + -28, + -31, + -35, + -39, + -46, + -48, + -49, + -53, + -58, + -63, + -67, + -69, + -71, + -72, + -74, + -75, + -77, + -77, + -73, + -72, + -69, + -65, + -60, + -55, + -50, + -47, + -43, + -38, + -30, + -25, + -20, + -12, + -4, + 4, + 9, + 16, + 20, + 24, + 28, + 35, + 43, + 50, + 58, + 61, + 65, + 72, + 74, + 74, + 76, + 79, + 78, + 76, + 78, + 76, + 76, + 74, + 70, + 64, + 59, + 52, + 46, + 41, + 33, + 26, + 19, + 12, + 5, + -2, + -8, + -15, + -20, + -26, + -31, + -37, + -39, + -41, + -44, + -44, + -47, + -51, + -52, + -52, + -48, + -45, + -46, + -48, + -45, + -42, + -40, + -36, + -32, + -27, + -24, + -22, + -18, + -16, + -11, + -10, + -5, + 0, + 3, + 8, + 11, + 16, + 18, + 21, + 23, + 25, + 26, + 27, + 28, + 30, + 31, + 31, + 30, + 29, + 27, + 26, + 23, + 19, + 17, + 13, + 10, + 6, + 0, + -2, + -5, + -10, + -12, + -15, + -19, + -23, + -26, + -29, + -30, + -30, + -32, + -33, + -34, + -35, + -34, + -31, + -29, + -29, + -28, + -28, + -23, + -19, + -17, + -12, + -12, + -10, + -5, + -2, + 3, + 7, + 10, + 13, + 14, + 19, + 22, + 26, + 31, + 34, + 34, + 35, + 36, + 39, + 43, + 45, + 47, + 47, + 48, + 49, + 51, + 48, + 47, + 50, + 45, + 41, + 41, + 38, + 34, + 34, + 30, + 23, + 17, + 11, + 7, + 4, + -4, + -9, + -15, + -23, + -28, + -32, + -35, + -39, + -45, + -46, + -49, + -53, + -52, + -53, + -55, + -56, + -56, + -55, + -54, + -53, + -53, + -51, + -47, + -44, + -42, + -40, + -37, + -33, + -28, + -25, + -23, + -18, + -15, + -8, + -6, + -2, + 3, + 8, + 15, + 18, + 23, + 26, + 27, + 32, + 36, + 36, + 36, + 39, + 38, + 38, + 40, + 39, + 35, + 31, + 29, + 25, + 23, + 19, + 15, + 11, + 7, + 5, + 3, + 1, + -1, + -6, + -8, + -7, + -10, + -9, + -10, + -11, + -10, + -7, + -6, + -8, + -6, + -5, + -4, + 1, + 2, + 4, + 7, + 7, + 9, + 11, + 11, + 9, + 9, + 10, + 11, + 13, + 17, + 15, + 15, + 15, + 17, + 19, + 17, + 17, + 17, + 15, + 15, + 13, + 11, + 12, + 8, + 7, + 5, + 3, + 0, + -4, + -4, + -6, + -9, + -12, + -14, + -15, + -15, + -16, + -20, + -19, + -20, + -20, + -20, + -18, + -18, + -21, + -22, + -21, + -21, + -23, + -20, + -20, + -23, + -24, + -23, + -25, + -25, + -25, + -25, + -26, + -24, + -23, + -23, + -23, + -23, + -22, + -19, + -18, + -15, + -14, + -10, + -8, + -4, + -1, + 1, + 3, + 6, + 8, + 9, + 14, + 19, + 22, + 24, + 26, + 29, + 32, + 31, + 34, + 39, + 42, + 42, + 46, + 49, + 50, + 50, + 52, + 53, + 52, + 49, + 49, + 48, + 48, + 46, + 45, + 40, + 34, + 30, + 25, + 21, + 17, + 13, + 10, + 6, + 2, + -4, + -9, + -12, + -15, + -18, + -21, + -26, + -28, + -31, + -32, + -33, + -35, + -35, + -38, + -37, + -36, + -34, + -35, + -35, + -33, + -33, + -34, + -30, + -26, + -27, + -25, + -23, + -22, + -18, + -15, + -16, + -12, + -9, + -9, + -6, + -1, + 2, + 3, + 5, + 8, + 7, + 9, + 12, + 15, + 17, + 18, + 18, + 19, + 18, + 20, + 19, + 18, + 21, + 20, + 19, + 18, + 16, + 15, + 15, + 15, + 14, + 12, + 9, + 9, + 10, + 8, + 6, + 4, + 2, + 1, + -1, + -3, + -1, + -3, + -2, + -4, + -5, + -5, + -8, + -8, + -10, + -10, + -8, + -8, + -8, + -7, + -8, + -8, + -8, + -9, + -11, + -12, + -11, + -9, + -7, + -8, + -8, + -8, + -10, + -8, + -7, + -8, + -7, + -6, + -7, + -5, + -3, + -3, + -3, + -3, + -2, + 0, + 3, + 3, + 5, + 7, + 10, + 11, + 10, + 10, + 12, + 13, + 16, + 16, + 16, + 17, + 15, + 16, + 17, + 16, + 14, + 16, + 13, + 11, + 11, + 9, + 9, + 6, + 4, + 4, + 3, + 0, + -2, + -4, + -7, + -7, + -7, + -13, + -15, + -13, + -14, + -16, + -15, + -15, + -17, + -16, + -16, + -18, + -19, + -19, + -20, + -19, + -16, + -15, + -13, + -12, + -10, + -7, + -6, + -4, + -4, + -2, + 0, + 2, + 6, + 8, + 10, + 12, + 14, + 15, + 14, + 13, + 13, + 13, + 15, + 15, + 17, + 17, + 17, + 18, + 17, + 16, + 15, + 15, + 14, + 11, + 9, + 8, + 8, + 9, + 8, + 5, + 5, + 3, + -1, + -1, + -4, + -5, + -7, + -8, + -8, + -8, + -9, + -10, + -8, + -11, + -12, + -12, + -12, + -12, + -13, + -11, + -11, + -9, + -8, + -7, + -8, + -7, + -6, + -7, + -6, + -5, + -4, + -4, + -2, + -2, + -3, + -2, + -2, + -3, + 0, + -1, + -3, + 1, + 1, + 2, + 4, + 3, + 5, + 6, + 3, + 3, + 4, + 3, + 3, + 4, + 5, + 4, + 6, + 7, + 7, + 7, + 6, + 3, + 3, + 5, + 3, + 3, + 6, + 6, + 7, + 6, + 4, + 5, + 2, + 1, + 1, + 0, + 0, + 2, + 1, + 1, + 1, + -1, + -2, + -3, + -5, + -4, + -5, + -4, + -4, + -6, + -4, + -4, + -4, + -5, + -6, + -5, + -6, + -5, + -4, + -5, + -4, + -3, + -4, + 0, + 2, + 2, + 2, + 2, + 2, + 2, + 3, + 3, + 5, + 6, + 6, + 5, + 6, + 7, + 6, + 8, + 6, + 5, + 5, + 5, + 6, + 6, + 6, + 5, + 5, + 2, + 2, + 1, + 2, + 0, + -1, + -1, + -1, + -1, + 0, + -1, + -4, + -6, + -8, + -8, + -9, + -8, + -7, + -6, + -5, + -5, + -6, + -3, + -4, + -5, + -4, + -7, + -6, + -4, + -2, + -1, + -1, + 1, + 1, + 1, + 1, + 1, + 2, + 2, + 1, + 3, + 4, + 4, + 6, + 6, + 6, + 6, + 4, + 4, + 4, + 4, + 3, + 2, + 2, + 2, + 2, + 1, + 1, + 1, + 0, + 1, + 1, + 0, + -2, + -2, + -3, + -3, + -3, + -3, + -5, + -4, + -3, + -5, + -5, + -3, + -5, + -4, + -4, + -2, + -2, + -2, + -1, + -3, + -2, + -2, + -1, + -3, + -2, + -1, + -2, + -2, + -2, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 1, + 2, + 3, + 3, + 3, + 4, + 5, + 4, + 3, + 4, + 5, + 5, + 7, + 7, + 6, + 9, + 8, + 6, + 7, + 8, + 6, + 5, + 7, + 8, + 8, + 8, + 7, + 6, + 5, + 4, + 4, + 4, + 5, + 4, + 2, + 1, + 2, + 1, + 0, + -2, + -3, + -2, + -4, + -6, + -6, + -7, + -7, + -8, + -9, + -9, + -9, + -9, + -9, + -9, + -9, + -10, + -10, + -10, + -8, + -7, + -8, + -6, + -5, + -4, + -3, + -5, + -2, + -2, + -2, + -1, + -1, + 0, + 1, + 1, + 2, + 3, + 2, + 4, + 3, + 3, + 5, + 3, + 3, + 5, + 4, + 5, + 6, + 5, + 4, + 5, + 3, + 2, + 2, + 3, + 4, + 4, + 4, + 4, + 4, + 3, + 4, + 4, + 4, + 3, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 1, + 1, + 1, + 2, + 1, + 1, + 2, + 1, + 1, + 2, + 1, + 1, + 1, + -1, + 0, + 1, + 0, + -1, + 1, + -1, + -1, + -1, + -2, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -2, + -1, + 0, + -1, + -1, + 1, + 1, + 2, + 0, + -1, + 0, + -1, + -1, + 0, + 0, + 1, + 2, + 2, + 2, + 1, + 1, + 0, + 0, + 0, + 0, + 1, + 1, + 0, + 0, + 0, + 0, + 0, + -1, + -2, + -1, + -3, + -4, + -4, + -4, + -4, + -4, + -4, + -4, + -3, + -3, + -5, + -6, + -4, + -2, + -2, + -1, + -1, + -1, + -2, + 1, + -1, + 1, + 0, + 0, + 1, + 1, + 1, + 1, + 2, + 1, + 2, + 2, + 3, + 3, + 3, + 3, + 4, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 6, + 6, + 5, + 5, + 5, + 6, + 6, + 5, + 3, + 6, + 5, + 4, + 5, + 3, + 2, + 2, + 2, + 2, + 1, + 1, + 2, + 0, + -1, + 0, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -3, + -3, + -3, + -3, + -4, + -4, + -5, + -6, + -6, + -6, + -6, + -6, + -6, + -5, + -5, + -6, + -5, + -4, + -4, + -4, + -4, + -2, + -2, + -2, + -1, + -2, + 0, + 1, + 0, + 1, + 3, + 4, + 4, + 4, + 4, + 4, + 4, + 5, + 4, + 4, + 4, + 5, + 7, + 5, + 4, + 4, + 4, + 4, + 3, + 2, + 2, + 2, + 2, + 2, + 0, + 1, + 1, + 0, + 1, + 1, + -1, + 0, + -1, + -2, + -1, + -3, + -4, + -4, + -3, + -5, + -5, + -5, + -5, + -5, + -5, + -4, + -3, + -3, + -2, + -3, + -2, + -2, + -5, + -3, + -3, + -3, + -2, + 0, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 3, + 3, + 4, + 4, + 4, + 4, + 5, + 5, + 2, + 3, + 4, + 3, + 5, + 4, + 3, + 4, + 3, + 3, + 5, + 5, + 3, + 4, + 2, + 1, + 1, + 3, + 4, + 3, + 1, + 3, + 2, + 1, + 2, + 1, + 0, + 1, + 0, + 1, + 0, + 1, + 1, + 1, + 1, + 0, + -1, + 0, + 0, + -1, + -1, + -2, + -1, + -1, + -2, + 0, + -1, + -2, + -1, + -1, + -2, + -2, + -1, + -3, + -3, + -3, + -3, + -3, + -4, + -3, + -5, + -6, + -4, + -4, + -5, + -4, + -3, + -5, + -6, + -4, + -5, + -6, + -4, + -3, + -5, + -4, + -3, + -4, + -3, + -2, + -2, + -2, + 0, + 0, + 1, + 1, + 0, + 0, + 0, + 1, + 1, + 3, + 3, + 3, + 4, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 1, + -2, + -1, + 1, + 0, + -1, + -2, + -2, + 0, + 1, + 0, + 1, + 1, + 1, + 1, + 0, + 0, + 1, + 0, + 0, + 2, + 1, + 0, + 1, + 1, + 1, + 1, + 3, + 3, + 3, + 4, + 3, + 3, + 4, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 1, + 2, + 2, + 2, + 2, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -3, + -3, + -3, + -5, + -4, + -5, + -5, + -5, + -5, + -7, + -7, + -7, + -8, + -7, + -8, + -7, + -8, + -8, + -7, + -8, + -8, + -8, + -8, + -7, + -6, + -6, + -6, + -7, + -6, + -6, + -5, + -5, + -3, + -2, + -2, + -1, + 0, + -1, + 0, + 1, + 2, + 2, + 3, + 3, + 3, + 6, + 7, + 7, + 7, + 8, + 9, + 8, + 10, + 10, + 9, + 10, + 11, + 9, + 10, + 12, + 11, + 10, + 9, + 9, + 9, + 9, + 10, + 9, + 6, + 6, + 5, + 5, + 6, + 3, + 1, + 1, + 0, + 1, + 0, + 0, + 1, + -1, + -2, + -2, + -1, + -3, + -3, + -2, + -4, + -4, + -3, + -2, + -4, + -4, + -4, + -5, + -3, + -3, + -5, + -3, + -3, + -5, + -4, + -2, + -2, + -3, + -3, + -1, + 0, + -1, + 0, + 0, + 0, + -2, + -1, + 0, + -1, + -2, + -2, + -2, + -2, + -1, + -3, + -2, + -3, + -4, + -3, + -3, + -3, + -3, + -3, + -3, + -3, + -2, + -4, + -6, + -5, + -3, + -2, + -4, + -3, + -2, + -4, + -4, + -4, + -3, + -4, + -5, + -4, + -5, + -3, + -2, + -5, + -2, + -4, + -4, + -3, + -2, + -1, + -1, + -1, + 0, + 2, + 2, + 1, + 1, + 3, + 3, + 3, + 3, + 4, + 4, + 5, + 6, + 5, + 5, + 6, + 7, + 7, + 7, + 8, + 8, + 7, + 9, + 9, + 9, + 9, + 10, + 9, + 9, + 9, + 9, + 9, + 9, + 8, + 7, + 9, + 9, + 6, + 7, + 5, + 2, + 3, + 2, + 1, + 1, + 0, + -2, + -2, + -2, + -3, + -3, + -2, + -2, + -4, + -5, + -4, + -4, + -4, + -4, + -5, + -4, + -4, + -5, + -4, + -5, + -4, + -5, + -6, + -4, + -4, + -5, + -5, + -5, + -5, + -6, + -4, + -4, + -4, + -3, + -2, + -3, + -3, + -2, + -2, + -1, + -2, + -3, + -1, + 0, + -1, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + -1, + 1, + 1, + 1, + 0, + -2, + -2, + -3, + -3, + -4, + -4, + -6, + -7, + -5, + -4, + -5, + -5, + -4, + -6, + -8, + -7, + -6, + -5, + -5, + -5, + -4, + -4, + -5, + -4, + -3, + -3, + 0, + 0, + -2, + -1, + 0, + 0, + 1, + 1, + 2, + 2, + 2, + 2, + 2, + 4, + 5, + 5, + 5, + 6, + 7, + 7, + 9, + 10, + 10, + 10, + 12, + 12, + 13, + 14, + 14, + 14, + 15, + 15, + 15, + 15, + 15, + 15, + 14, + 15, + 15, + 12, + 13, + 13, + 12, + 10, + 11, + 11, + 11, + 10, + 8, + 6, + 5, + 7, + 6, + 6, + 4, + 3, + 4, + 5, + 3, + 2, + 2, + 1, + 1, + 2, + 3, + 1, + 0, + 0, + 1, + 0, + -2, + -1, + -2, + -3, + -3, + -3, + -3, + -4, + -6, + -8, + -9, + -9, + -10, + -12, + -14, + -15, + -18, + -21, + -21, + -21, + -21, + -22, + -24, + -26, + -26, + -27, + -27, + -28, + -26, + -25, + -26, + -28, + -27, + -24, + -23, + -23, + -24, + -21, + -17, + -17, + -15, + -12, + -12, + -12, + -12, + -9, + -7, + -6, + -5, + -3, + -3, + -2, + 0, + 0, + 1, + 3, + 7, + 6, + 4, + 6, + 7, + 8, + 11, + 10, + 10, + 13, + 15, + 14, + 13, + 18, + 20, + 18, + 19, + 21, + 23, + 24, + 23, + 22, + 24, + 26, + 26, + 26, + 27, + 25, + 23, + 25, + 27, + 28, + 28, + 28, + 23, + 19, + 23, + 24, + 20, + 20, + 21, + 15, + 13, + 15, + 16, + 14, + 11, + 8, + 7, + 8, + 11, + 11, + 6, + 4, + 8, + 7, + 6, + 7, + 6, + 4, + 7, + 13, + 12, + 7, + 8, + 8, + 4, + 1, + 1, + 1, + 2, + -4, + -12, + -18, + -24, + -25, + -25, + -32, + -41, + -55, + -59, + -61, + -75, + -87, + -96, + -109, + -122, + -133, + -141, + -148, + -157, + -168, + -180, + -191, + -198, + -202, + -207, + -206, + -207, + -211, + -211, + -208, + -203, + -189, + -171, + -153, + -132, + -114, + -96, + -75, + -54, + -30, + -5, + 19, + 43, + 61, + 77, + 93, + 106, + 123, + 143, + 161, + 182, + 198, + 202, + 201, + 209, + 229, + 242, + 240, + 235, + 239, + 249, + 258, + 255, + 242, + 233, + 245, + 268, + 278, + 256, + 223, + 223, + 253, + 263, + 235, + 198, + 178, + 188, + 215, + 230, + 200, + 143, + 113, + 128, + 158, + 158, + 128, + 99, + 90, + 82, + 70, + 56, + 32, + 7, + 14, + 46, + 36, + -23, + -71, + -76, + -54, + -36, + -39, + -74, + -118, + -134, + -122, + -101, + -104, + -129, + -164, + -174, + -129, + -86, + -109, + -184, + -219, + -191, + -147, + -141, + -183, + -249, + -290, + -269, + -236, + -266, + -346, + -394, + -366, + -325, + -353, + -431, + -472, + -406, + -313, + -316, + -398, + -449, + -401, + -287, + -194, + -164, + -193, + -245, + -212, + -55, + 75, + 67, + 26, + 67, + 165, + 237, + 269, + 293, + 319, + 333, + 368, + 414, + 432, + 463, + 488, + 448, + 404, + 391, + 377, + 361, + 365, + 376, + 308, + 197, + 150, + 129, + 73, + 53, + 91, + 43, + -107, + -165, + -54, + 1, + -148, + -312, + -273, + -125, + -62, + -128, + -258, + -294, + -141, + 70, + 57, + -217, + -378, + -145, + 198, + 289, + 169, + -47, + -219, + -101, + 264, + 458, + 217, + -163, + -199, + 13, + 121, + 101, + -51, + -293, + -319, + -62, + 24, + -274, + -474, + -296, + -170, + -336, + -422, + -285, + -248, + -302, + -130, + 98, + -11, + -257, + -146, + 184, + 278, + 264, + 331, + 192, + -35, + 235, + 805, + 830, + 315, + 82, + 322, + 503, + 522, + 619, + 557, + 242, + 163, + 399, + 507, + 489, + 618, + 602, + 156, + -164, + 112, + 476, + 406, + 94, + -154, + -242, + -132, + 56, + 5, + -325, + -566, + -527, + -478, + -624, + -692, + -561, + -551, + -744, + -836, + -671, + -520, + -626, + -736, + -647, + -581, + -639, + -687, + -702, + -739, + -665, + -383, + -236, + -414, + -513, + -321, + -114, + -43, + 32, + 65, + -98, + -236, + 34, + 608, + 924, + 680, + 218, + 56, + 329, + 847, + 1214, + 1006, + 341, + 11, + 340, + 667, + 553, + 353, + 355, + 415, + 416, + 364, + 257, + 108, + 6, + 113, + 293, + 233, + 46, + 4, + 25, + -10, + -12, + 55, + 40, + -65, + -56, + -26, + -101, + -61, + 143, + 229, + 78, + -161, + -210, + 103, + 424, + 377, + 86, + -274, + -491, + -328, + -37, + 60, + 128, + 188, + -105, + -625, + -823, + -464, + 138, + 389, + 111, + -343, + -526, + -306, + 13, + 205, + 250, + -35, + -554, + -764, + -498, + -42, + 167, + -210, + -639, + -448, + -101, + -110, + -171, + -74, + -39, + 47, + 424, + 616, + 324, + 98, + 367, + 853, + 942, + 416, + -184, + -130, + 339, + 472, + 369, + 239, + -165, + -418, + 101, + 742, + 659, + 325, + 365, + 476, + 233, + -14, + 270, + 785, + 719, + -29, + -533, + -220, + 237, + 305, + 179, + -190, + -644, + -610, + -380, + -526, + -601, + -237, + 48, + -36, + -124, + -49, + -6, + 23, + 117, + 55, + -199, + -428, + -512, + -338, + -238, + -424, + -323, + -135, + -464, + -657, + -189, + 100, + -379, + -964, + -893, + -346, + -64, + -322, + -650, + -480, + 32, + 238, + 201, + 386, + 616, + 611, + 400, + 195, + 357, + 842, + 1051, + 832, + 712, + 829, + 1070, + 1307, + 1081, + 551, + 363, + 544, + 623, + 239, + -374, + -609, + -230, + 375, + 486, + -52, + -446, + -270, + 181, + 645, + 601, + -135, + -654, + -256, + 567, + 840, + 380, + -54, + 18, + 334, + 386, + 21, + -214, + 83, + 243, + -316, + -937, + -1074, + -1006, + -896, + -674, + -424, + -331, + -354, + -380, + -481, + -392, + 80, + 358, + 171, + -170, + -624, + -796, + -130, + 706, + 803, + 381, + 152, + 367, + 620, + 685, + 655, + 347, + 36, + 180, + 417, + 412, + 358, + 288, + 189, + 150, + 16, + -240, + -428, + -428, + -266, + -335, + -819, + -1150, + -946, + -587, + -437, + -580, + -961, + -1218, + -1065, + -704, + -431, + -350, + -315, + -214, + -162, + -81, + 26, + -8, + -52, + -117, + -226, + -40, + 285, + 241, + -2, + -69, + 57, + 207, + 81, + -144, + -69, + 65, + 84, + 49, + -168, + -248, + 126, + 502, + 472, + 192, + 120, + 442, + 667, + 551, + 512, + 634, + 814, + 1014, + 1098, + 1156, + 1112, + 974, + 1144, + 1330, + 1099, + 825, + 847, + 877, + 555, + 2, + -243, + -102, + -196, + -471, + -377, + -235, + -439, + -622, + -547, + -470, + -495, + -431, + -197, + -21, + 21, + -9, + -246, + -438, + -238, + -31, + 0, + 96, + 137, + -25, + -211, + -181, + -149, + -350, + -368, + -33, + 21, + -308, + -323, + 32, + 379, + 605, + 531, + 85, + -374, + -367, + 9, + 277, + 147, + -356, + -698, + -494, + -140, + -126, + -354, + -549, + -673, + -642, + -428, + -269, + -273, + -246, + -216, + -349, + -323, + -16, + 32, + -387, + -742, + -662, + -434, + -223, + 41, + 140, + -58, + -227, + -80, + 93, + 20, + -166, + -360, + -536, + -555, + -305, + -33, + -23, + -86, + -75, + -9, + 82, + -1, + -156, + 24, + 532, + 916, + 956, + 835, + 901, + 1127, + 1279, + 1417, + 1435, + 1144, + 822, + 862, + 1214, + 1352, + 1001, + 611, + 539, + 532, + 369, + 189, + 170, + 308, + 465, + 430, + 232, + 64, + 14, + 51, + -37, + -244, + -321, + -276, + -144, + 57, + 77, + -215, + -467, + -335, + -186, + -245, + -133, + -81, + -588, + -1130, + -959, + -520, + -631, + -1122, + -1270, + -971, + -873, + -1118, + -1157, + -1078, + -1296, + -1365, + -1010, + -873, + -1138, + -1061, + -379, + 89, + 51, + 177, + 372, + 185, + -14, + 63, + 197, + 125, + -123, + -60, + 243, + 195, + 88, + 201, + 115, + -63, + -12, + -79, + -492, + -751, + -489, + 49, + 163, + -293, + -424, + -52, + 229, + 302, + 212, + 217, + 315, + 70, + -207, + -210, + -173, + 129, + 619, + 556, + 213, + 181, + 170, + 112, + 167, + 322, + 451, + 206, + -136, + 58, + 426, + 526, + 524, + 394, + 387, + 568, + 481, + 297, + 164, + 8, + 263, + 664, + 777, + 943, + 989, + 934, + 1283, + 1495, + 1153, + 861, + 738, + 582, + 614, + 692, + 655, + 629, + 432, + 127, + -119, + -338, + -313, + -138, + -204, + -561, + -994, + -1168, + -948, + -700, + -658, + -788, + -1053, + -1027, + -684, + -566, + -528, + -355, + -335, + -323, + -28, + 206, + 87, + 56, + 387, + 585, + 296, + 24, + 261, + 492, + 248, + -132, + -469, + -674, + -502, + -235, + -255, + -517, + -847, + -1038, + -965, + -707, + -630, + -767, + -639, + -298, + -193, + -290, + -310, + -118, + 74, + -77, + -337, + -324, + -120, + 187, + 323, + -72, + -552, + -454, + -14, + 29, + -427, + -803, + -735, + -586, + -762, + -918, + -783, + -649, + -723, + -857, + -786, + -626, + -591, + -417, + -83, + 167, + 262, + 49, + -161, + 157, + 842, + 1298, + 1356, + 1206, + 1041, + 1194, + 1461, + 1323, + 1070, + 1221, + 1687, + 2051, + 2002, + 1673, + 1464, + 1550, + 1851, + 1907, + 1531, + 1327, + 1399, + 1342, + 1287, + 1264, + 1152, + 1030, + 878, + 716, + 601, + 454, + 264, + 264, + 352, + 151, + -193, + -296, + -161, + -93, + -215, + -423, + -617, + -668, + -547, + -416, + -464, + -807, + -1175, + -1174, + -1045, + -1076, + -1023, + -829, + -710, + -745, + -1069, + -1443, + -1417, + -1099, + -939, + -1165, + -1307, + -1056, + -843, + -638, + -304, + -190, + -334, + -578, + -770, + -705, + -675, + -947, + -957, + -565, + -437, + -617, + -843, + -1015, + -813, + -489, + -584, + -904, + -1054, + -797, + -229, + -26, + -208, + -66, + 398, + 710, + 644, + 390, + 413, + 726, + 992, + 1204, + 1337, + 1234, + 1104, + 1038, + 1001, + 1043, + 982, + 847, + 885, + 1024, + 1098, + 1138, + 1108, + 1038, + 966, + 885, + 882, + 878, + 929, + 1005, + 944, + 1008, + 1284, + 1415, + 1289, + 1007, + 760, + 812, + 947, + 806, + 455, + 111, + -72, + -290, + -611, + -626, + -559, + -765, + -1034, + -1375, + -1632, + -1565, + -1588, + -1728, + -1585, + -1477, + -1547, + -1533, + -1371, + -1103, + -995, + -1090, + -1102, + -947, + -686, + -403, + -295, + -250, + -107, + -86, + -171, + -150, + 12, + 234, + 283, + 185, + 300, + 461, + 393, + 382, + 434, + 378, + 306, + 202, + 195, + 253, + -8, + -307, + -105, + 264, + 342, + 212, + 34, + -57, + 78, + 435, + 571, + 180, + -165, + -51, + 339, + 705, + 683, + 464, + 658, + 958, + 825, + 579, + 465, + 390, + 241, + 61, + 202, + 429, + 128, + -122, + 241, + 406, + 39, + -167, + -60, + 15, + -31, + -68, + 146, + 402, + 344, + 227, + 208, + 87, + -25, + -31, + -66, + -169, + -249, + -87, + 75, + -181, + -438, + -249, + 49, + 87, + -40, + -16, + 53, + -86, + -74, + 98, + 78, + 110, + 169, + -84, + -323, + -251, + -102, + -172, + -513, + -750, + -675, + -568, + -587, + -583, + -523, + -450, + -302, + -245, + -356, + -480, + -590, + -495, + -183, + -105, + -191, + -215, + -308, + -206, + 39, + 4, + -77, + -21, + 74, + 186, + 218, + 356, + 611, + 489, + 83, + 13, + 246, + 371, + 348, + 240, + 61, + -66, + -107, + -170, + -205, + -74, + 200, + 277, + 45, + -11, + 180, + 263, + 100, + -74, + 102, + 246, + 6, + -154, + -162, + -197, + -128, + -189, + -227, + -49, + -238, + -490, + -333, + -188, + 1, + 215, + 150, + 144, + 128, + -33, + 187, + 532, + 676, + 911, + 773, + 283, + 351, + 673, + 620, + 349, + 105, + 205, + 425, + 325, + 295, + 372, + 340, + 511, + 628, + 394, + 224, + 187, + 91, + -174, + -556, + -482, + -37, + -9, + -226, + -382, + -568, + -466, + -208, + -241, + -426, + -656, + -814, + -788, + -902, + -1065, + -946, + -860, + -896, + -831, + -744, + -672, + -685, + -743, + -723, + -783, + -813, + -570, + -341, + -239, + -57, + 137, + 348, + 576, + 593, + 454, + 429, + 503, + 449, + 238, + 173, + 350, + 423, + 419, + 530, + 501, + 272, + 156, + 207, + 295, + 404, + 568, + 676, + 419, + 30, + 113, + 463, + 550, + 473, + 349, + 126, + 33, + 144, + 207, + 193, + 267, + 304, + 81, + -252, + -401, + -368, + -347, + -404, + -452, + -408, + -272, + -40, + 234, + 281, + 48, + -72, + -18, + 54, + 208, + 309, + 285, + 245, + 164, + 38, + -20, + 148, + 430, + 563, + 655, + 679, + 453, + 300, + 319, + 219, + 25, + -15, + 54, + -117, + -444, + -431, + -135, + -147, + -468, + -667, + -722, + -593, + -301, + -217, + -428, + -642, + -598, + -400, + -422, + -602, + -628, + -554, + -509, + -501, + -541, + -488, + -250, + -129, + -284, + -441, + -358, + -161, + -82, + 4, + 134, + 157, + 290, + 516, + 582, + 702, + 859, + 871, + 858, + 759, + 615, + 616, + 754, + 839, + 725, + 464, + 259, + 187, + 127, + 150, + 280, + 238, + 92, + 78, + 5, + -86, + 6, + 67, + -14, + -92, + -143, + -211, + -89, + 213, + 300, + 107, + -91, + -154, + -153, + -238, + -355, + -314, + -227, + -168, + -92, + -142, + -219, + -156, + -47, + 53, + -15, + -195, + -161, + -186, + -382, + -395, + -297, + -238, + -240, + -390, + -502, + -336, + -97, + -29, + -116, + -290, + -289, + -67, + 74, + 112, + 119, + 182, + 358, + 382, + 315, + 341, + 290, + 218, + 190, + 101, + -51, + -168, + -132, + -41, + -39, + -15, + 104, + 186, + 151, + 68, + 89, + 154, + 67, + 10, + 143, + 120, + -185, + -382, + -365, + -263, + -145, + -111, + -159, + -190, + -53, + 151, + 177, + 179, + 384, + 553, + 502, + 490, + 572, + 600, + 573, + 442, + 119, + -212, + -260, + -166, + -318, + -506, + -413, + -279, + -285, + -354, + -390, + -278, + -142, + -85, + -18, + -19, + -121, + -143, + -32, + 88, + 118, + 42, + -96, + -187, + -167, + -113, + -172, + -270, + -256, + -178, + -192, + -249, + -128, + 103, + 132, + -47, + -147, + -104, + -56, + -9, + 45, + 35, + 109, + 315, + 381, + 326, + 336, + 457, + 667, + 786, + 675, + 489, + 460, + 569, + 595, + 470, + 303, + 272, + 448, + 620, + 545, + 226, + -92, + -128, + 91, + 172, + -98, + -385, + -378, + -264, + -284, + -362, + -314, + -148, + -72, + -198, + -350, + -353, + -344, + -389, + -353, + -292, + -327, + -413, + -473, + -519, + -588, + -577, + -546, + -737, + -989, + -1030, + -997, + -1010, + -861, + -683, + -731, + -690, + -419, + -197, + -47, + 112, + 167, + 74, + 41, + 176, + 309, + 438, + 671, + 781, + 793, + 868, + 904, + 991, + 1099, + 987, + 812, + 816, + 869, + 766, + 605, + 633, + 728, + 592, + 424, + 460, + 405, + 170, + 75, + 30, + -105, + -58, + 63, + -58, + -242, + -359, + -415, + -255, + -44, + -127, + -266, + -191, + -187, + -296, + -273, + -260, + -341, + -345, + -324, + -384, + -467, + -421, + -233, + -125, + -227, + -341, + -256, + -168, + -217, + -249, + -302, + -447, + -425, + -274, + -289, + -299, + -229, + -275, + -272, + -103, + -57, + -117, + -106, + -162, + -256, + -184, + -31, + 51, + 69, + 31, + -19, + 72, + 256, + 318, + 331, + 254, + 28, + -7, + 121, + 48, + -64, + 58, + 183, + 152, + 161, + 201, + 167, + 190, + 287, + 278, + 157, + 56, + 103, + 332, + 460, + 299, + 166, + 238, + 308, + 374, + 508, + 509, + 373, + 275, + 270, + 298, + 229, + 185, + 192, + 23, + -160, + -80, + 67, + 31, + -170, + -378, + -384, + -330, + -500, + -648, + -615, + -686, + -716, + -510, + -510, + -771, + -752, + -475, + -434, + -556, + -480, + -403, + -515, + -464, + -255, + -177, + -105, + 29, + 95, + 152, + 210, + 190, + 180, + 279, + 408, + 325, + 225, + 462, + 607, + 537, + 759, + 1022, + 973, + 945, + 964, + 846, + 818, + 952, + 907, + 584, + 313, + 302, + 428, + 533, + 479, + 260, + 178, + 262, + 185, + 18, + -77, + -263, + -370, + -208, + -240, + -589, + -739, + -572, + -444, + -405, + -357, + -475, + -738, + -771, + -542, + -441, + -529, + -651, + -803, + -823, + -556, + -285, + -227, + -233, + -202, + -168, + -110, + -78, + -220, + -302, + -56, + 129, + -60, + -149, + 54, + 130, + 169, + 324, + 231, + 24, + 89, + 269, + 320, + 262, + 231, + 225, + 138, + 67, + 153, + 310, + 399, + 269, + -21, + -197, + -183, + -59, + 144, + 234, + -13, + -274, + -168, + 32, + -37, + -277, + -417, + -441, + -416, + -324, + -312, + -467, + -540, + -373, + -166, + -161, + -297, + -365, + -341, + -246, + -69, + 81, + 99, + -3, + 11, + 305, + 540, + 449, + 394, + 586, + 667, + 606, + 685, + 665, + 425, + 410, + 585, + 509, + 360, + 424, + 538, + 583, + 482, + 250, + 159, + 310, + 423, + 217, + -131, + -280, + -204, + -51, + -12, + -204, + -338, + -232, + -143, + -201, + -306, + -374, + -336, + -229, + -257, + -453, + -576, + -497, + -379, + -326, + -302, + -372, + -504, + -453, + -229, + -133, + -226, + -328, + -326, + -261, + -151, + -6, + 97, + 143, + 164, + 143, + 138, + 267, + 433, + 500, + 470, + 297, + 143, + 279, + 504, + 556, + 475, + 333, + 233, + 225, + 228, + 198, + 128, + 24, + -17, + 4, + -55, + -187, + -251, + -213, + -119, + -94, + -214, + -357, + -349, + -246, + -195, + -183, + -261, + -440, + -533, + -476, + -341, + -213, + -170, + -220, + -299, + -220, + -8, + 51, + -11, + 19, + 172, + 292, + 189, + 9, + -6, + 102, + 238, + 384, + 477, + 448, + 353, + 304, + 354, + 473, + 543, + 400, + 229, + 275, + 380, + 425, + 415, + 371, + 398, + 460, + 377, + 202, + 154, + 199, + 110, + -123, + -365, + -524, + -524, + -360, + -134, + -47, + -182, + -348, + -453, + -542, + -503, + -376, + -398, + -521, + -595, + -621, + -560, + -439, + -284, + -115, + -80, + -123, + -57, + 28, + -15, + -60, + -9, + 47, + 119, + 203, + 288, + 435, + 571, + 635, + 706, + 750, + 627, + 436, + 345, + 330, + 398, + 460, + 368, + 213, + 127, + 140, + 215, + 202, + 58, + -99, + -244, + -387, + -470, + -527, + -637, + -754, + -791, + -768, + -742, + -739, + -735, + -704, + -649, + -552, + -479, + -491, + -494, + -454, + -433, + -422, + -398, + -315, + -115, + 75, + 175, + 244, + 307, + 360, + 398, + 460, + 532, + 529, + 446, + 422, + 497, + 541, + 504, + 541, + 702, + 803, + 744, + 645, + 621, + 727, + 877, + 873, + 734, + 593, + 513, + 523, + 516, + 412, + 336, + 334, + 274, + 199, + 163, + 123, + 125, + 117, + 107, + 140, + 72, + -73, + -114, + -68, + -15, + 13, + -122, + -338, + -367, + -325, + -386, + -497, + -608, + -634, + -546, + -477, + -427, + -377, + -412, + -464, + -436, + -343, + -276, + -327, + -390, + -313, + -149, + -17, + 2, + -93, + -146, + -104, + -76, + -87, + -131, + -224, + -280, + -194, + -46, + 12, + -76, + -189, + -151, + 18, + 160, + 200, + 99, + -81, + -149, + -95, + -31, + -6, + -45, + -93, + -97, + -71, + 0, + 73, + 34, + -82, + -129, + -102, + -84, + -96, + -107, + -69, + -5, + 6, + 18, + 48, + 35, + 27, + 32, + -4, + -71, + -30, + 119, + 205, + 266, + 352, + 325, + 237, + 282, + 352, + 358, + 342, + 265, + 203, + 200, + 159, + 120, + 159, + 195, + 185, + 133, + 37, + 20, + 152, + 312, + 363, + 316, + 255, + 251, + 259, + 211, + 160, + 86, + -4, + -30, + -79, + -154, + -213, + -271, + -243, + -146, + -147, + -211, + -283, + -319, + -219, + -157, + -207, + -237, + -252, + -245, + -136, + 0, + 42, + -22, + -108, + -82, + 34, + 130, + 179, + 152, + 98, + 105, + 110, + 116, + 180, + 175, + 66, + -9, + -9, + 36, + 82, + 75, + 12, + -39, + -14, + 23, + 1, + 12, + 31, + -61, + -155, + -184, + -158, + -86, + -60, + -67, + -63, + -84, + -100, + -81, + -115, + -171, + -157, + -150, + -179, + -191, + -209, + -245, + -217, + -128, + -54, + -42, + -73, + -100, + -88, + -10, + 104, + 199, + 249, + 227, + 201, + 204, + 151, + 83, + 75, + 87, + 84, + 67, + 34, + 18, + 44, + 110, + 218, + 275, + 232, + 190, + 209, + 263, + 294, + 256, + 174, + 108, + 37, + -54, + -110, + -129, + -179, + -293, + -360, + -339, + -282, + -190, + -135, + -188, + -239, + -234, + -227, + -182, + -127, + -89, + -51, + -73, + -136, + -151, + -85, + 0, + 72, + 129, + 122, + 65, + 44, + 103, + 202, + 272, + 252, + 170, + 148, + 167, + 152, + 130, + 127, + 79, + 14, + 70, + 157, + 142, + 109, + 70, + -25, + -57, + -6, + 46, + 98, + 135, + 135, + 82, + 16, + 10, + 68, + 87, + -20, + -120, + -116, + -98, + -102, + -129, + -204, + -271, + -282, + -252, + -216, + -215, + -221, + -156, + -70, + -66, + -120, + -156, + -146, + -126, + -84, + -15, + -21, + -76, + -8, + 131, + 146, + 86, + 42, + 12, + 44, + 110, + 169, + 171, + 91, + 68, + 173, + 262, + 248, + 160, + 36, + -90, + -109, + -24, + -12, + -57, + -64, + -78, + -89, + -75, + -87, + -101, + -82, + -72, + -76, + -81, + -63, + -34, + -4, + 61, + 87, + 46, + 23, + -1, + -8, + 40, + 63, + 46, + 45, + 39, + 14, + -11, + -25, + -16, + 36, + 78, + 85, + 110, + 120, + 132, + 189, + 228, + 217, + 154, + 89, + 57, + 14, + -14, + -6, + 0, + 13, + 8, + -50, + -68, + -60, + -107, + -140, + -126, + -122, + -151, + -147, + -118, + -105, + -85, + -83, + -100, + -139, + -195, + -194, + -168, + -183, + -173, + -148, + -166, + -168, + -123, + -59, + -11, + 20, + 64, + 98, + 80, + 58, + 83, + 111, + 143, + 176, + 171, + 152, + 146, + 165, + 174, + 143, + 93, + 30, + 5, + 21, + 42, + 35, + -37, + -94, + -61, + -12, + -5, + -27, + -58, + -85, + -81, + -11, + 79, + 65, + -14, + -17, + 15, + -4, + -2, + 39, + 20, + -29, + -19, + 3, + -11, + -39, + -62, + -43, + -34, + -60, + -77, + -119, + -163, + -128, + -5, + 87, + 73, + 51, + 116, + 189, + 217, + 240, + 234, + 177, + 192, + 295, + 344, + 313, + 263, + 236, + 240, + 230, + 179, + 99, + 19, + -25, + -16, + -9, + -35, + -66, + -53, + -16, + -40, + -70, + -81, + -102, + -86, + -87, + -156, + -225, + -228, + -145, + -52, + -22, + -57, + -171, + -255, + -247, + -208, + -165, + -187, + -242, + -275, + -261, + -168, + -75, + -13, + 8, + -62, + -125, + -136, + -133, + -81, + -11, + -17, + -80, + -115, + -103, + -27, + 71, + 134, + 137, + 44, + -48, + -24, + 69, + 156, + 194, + 175, + 112, + 55, + 54, + 101, + 148, + 157, + 142, + 100, + 44, + 27, + 63, + 106, + 107, + 89, + 67, + 37, + 17, + 30, + 63, + 69, + 61, + 21, + -37, + -55, + -72, + -53, + -26, + -53, + -77, + -87, + -109, + -119, + -80, + -36, + -29, + -38, + -48, + -57, + -65, + -16, + 52, + 83, + 83, + 24, + -27, + -14, + 9, + 27, + 52, + 50, + 45, + 90, + 132, + 117, + 75, + 16, + -1, + 60, + 95, + 55, + 25, + 26, + 20, + 61, + 119, + 89, + 1, + -61, + -68, + -46, + -36, + -40, + -39, + -49, + -58, + -16, + 30, + 13, + -12, + 18, + 35, + 6, + 3, + 30, + 22, + 25, + 52, + 32, + 12, + 9, + -5, + -16, + -25, + -33, + -38, + -44, + -76, + -118, + -118, + -96, + -54, + -3, + 9, + -31, + -82, + -84, + -35, + 18, + 25, + -26, + -72, + -48, + 8, + 25, + 8, + -20, + -66, + -105, + -102, + -80, + -73, + -79, + -80, + -70, + -59, + -55, + -82, + -113, + -85, + -51, + -59, + -57, + -38, + -13, + -7, + -18, + -6, + 20, + 51, + 55, + 18, + -8, + -7, + 24, + 78, + 119, + 137, + 135, + 139, + 153, + 144, + 155, + 179, + 166, + 128, + 56, + 8, + 38, + 85, + 94, + 72, + 20, + -32, + -9, + 25, + 17, + -15, + -84, + -123, + -106, + -82, + -62, + -60, + -43, + -4, + -12, + -45, + -68, + -108, + -100, + -47, + -49, + -64, + -50, + -9, + 37, + 59, + 68, + 62, + 53, + 49, + 25, + 13, + 32, + 40, + 60, + 109, + 82, + 18, + 10, + -1, + 21, + 102, + 111, + 40, + -10, + -9, + 20, + 31, + 0, + -51, + -108, + -135, + -89, + -21, + 1, + -54, + -125, + -129, + -113, + -144, + -205, + -227, + -167, + -118, + -114, + -100, + -71, + 5, + 34, + -51, + -119, + -120, + -72, + 10, + 56, + 51, + 58, + 65, + 98, + 135, + 84, + 20, + -3, + -1, + 57, + 135, + 137, + 90, + 88, + 107, + 102, + 45, + -4, + 9, + 48, + 95, + 99, + 65, + 42, + 44, + 78, + 80, + 29, + 11, + 39, + 27, + 0, + 7, + 19, + 10, + -45, + -99, + -86, + -77, + -74, + -57, + -74, + -84, + -92, + -134, + -114, + -65, + -73, + -76, + -96, + -105, + -50, + -31, + -17, + 17, + 9, + 18, + 62, + 75, + 55, + 63, + 76, + 61, + 61, + 80, + 103, + 107, + 110, + 131, + 134, + 120, + 94, + 66, + 70, + 78, + 59, + 52, + 57, + 53, + 72, + 76, + 31, + -18, + -53, + -57, + -35, + -17, + -9, + -27, + -34, + -7, + -17, + -26, + -13, + -60, + -86, + -53, + -42, + -36, + -36, + -46, + -13, + 19, + -16, + -47, + -15, + 11, + -9, + -18, + -26, + -24, + 14, + 8, + -53, + -54, + 15, + 43, + 15, + -9, + -5, + 5, + -12, + -40, + -57, + -74, + -94, + -105, + -91, + -20, + 30, + -10, + -50, + -58, + -52, + -42, + -47, + -54, + -61, + -83, + -64, + -30, + -3, + 31, + 9, + -35, + -43, + -31, + 6, + 50, + 54, + 55, + 67, + 53, + 43, + 30, + 27, + 62, + 37, + -26, + -52, + -54, + -29, + 3, + -12, + -23, + 11, + 26, + 23, + 31, + 57, + 66, + 46, + 32, + 35, + 83, + 124, + 111, + 124, + 157, + 143, + 101, + 80, + 60, + 27, + 11, + 21, + 22, + 9, + -4, + -26, + -41, + -35, + -50, + -103, + -138, + -116, + -90, + -89, + -90, + -79, + -74, + -58, + -18, + -12, + -29, + -36, + -17, + 22, + 30, + -1, + -8, + 8, + 10, + 19, + 31, + 36, + 38, + 41, + 28, + -7, + -14, + -6, + -20, + -30, + -11, + -2, + -9, + 0, + 25, + 56, + 78, + 68, + 40, + 34, + 47, + 50, + 40, + 37, + 26, + 28, + 53, + 61, + 57, + 25, + -35, + -75, + -65, + -48, + -65, + -81, + -67, + -53, + -41, + 3, + 19, + -3, + -9, + -2, + -1, + -24, + -36, + -23, + -26, + -29, + -9, + 0, + -15, + -17, + -9, + 12, + 50, + 45, + 14, + 19, + 37, + 24, + 9, + 16, + 13, + -16, + -19, + 3, + -3, + -12, + -10, + -23, + -43, + -47, + -38, + -46, + -44, + -7, + 3, + -19, + -13, + -26, + -52, + -29, + -19, + -32, + 0, + 11, + -26, + -24, + -20, + -41, + -30, + -24, + -53, + -67, + -26, + 23, + 20, + 9, + 6, + -8, + 3, + 16, + 7, + 3, + -5, + 2, + 33, + 53, + 72, + 94, + 86, + 69, + 96, + 118, + 95, + 91, + 78, + 32, + 26, + 48, + 48, + 37, + 21, + 7, + -6, + -8, + 8, + 1, + -17, + -2, + 18, + 1, + -28, + -51, + -84, + -93, + -74, + -46, + -18, + -19, + -31, + -10, + 10, + 10, + 7, + -5, + -30, + -39, + -28, + -9, + 10, + 17, + 11, + 14, + 20, + -1, + 2, + 18, + 7, + 15, + 40, + 40, + 32, + 27, + 23, + 31, + 43, + 33, + 7, + -3, + 18, + 51, + 53, + 31, + 21, + 14, + 16, + 14, + 4, + 11, + 16, + 1, + -24, + -38, + -33, + -27, + -50, + -74, + -70, + -60, + -54, + -44, + -22, + -22, + -43, + -33, + -16, + -35, + -36, + -18, + -27, + -42, + -46, + -36, + -17, + -15, + -22, + -21, + -20, + -2, + 15, + 12, + 22, + 27, + 22, + 41, + 57, + 60, + 63, + 54, + 56, + 65, + 62, + 68, + 58, + 34, + 53, + 70, + 58, + 60, + 51, + 33, + 41, + 39, + 16, + -3, + -16, + -18, + -15, + -18, + -32, + -76, + -85, + -62, + -82, + -87, + -68, + -84, + -75, + -40, + -48, + -55, + -45, + -42, + -24, + -14, + -1, + 27, + 23, + -1, + -2, + 12, + 15, + 32, + 55, + 52, + 55, + 82, + 81, + 58, + 62, + 59, + 37, + 24, + 20, + 17, + 18, + 19, + 15, + 14, + 5, + -18, + -27, + -20, + -19, + -34, + -39, + -29, + -30, + -27, + -27, + -48, + -52, + -54, + -77, + -48, + -18, + -36, + -34, + -13, + -21, + -38, + -28, + -15, + -7, + -6, + -20, + -18, + 2, + 4, + -11, + -5, + 7, + 1, + 1, + 12, + -2, + -17, + 7, + 15, + 2, + 15, + 34, + 48, + 78, + 94, + 82, + 66, + 66, + 64, + 47, + 44, + 57, + 64, + 74, + 65, + 34, + 26, + 31, + 32, + 33, + 18, + 5, + -1, + -18, + -22, + -31, + -54, + -37, + -32, + -74, + -89, + -77, + -73, + -65, + -72, + -75, + -39, + -21, + -31, + -31, + -24, + -19, + -8, + -4, + 7, + 26, + 22, + 15, + 13, + 11, + 28, + 47, + 42, + 35, + 28, + 5, + 18, + 55, + 55, + 45, + 44, + 18, + 9, + 18, + -2, + -5, + 6, + -15, + -16, + -12, + -20, + -4, + 4, + -15, + -18, + -10, + -5, + -2, + -16, + -24, + -14, + -7, + -14, + -33, + -33, + -20, + -17, + -17, + -18, + -30, + -37, + -35, + -34, + -13, + -3, + -28, + -28, + -10, + -21, + -17, + -4, + -12, + -16, + -20, + -27, + -16, + -8, + -4, + 14, + 24, + 11, + 17, + 30, + 27, + 14, + 7, + 28, + 30, + 22, + 45, + 47, + 23, + 31, + 23, + -5, + 10, + 17, + -5, + 2, + 15, + 9, + 20, + 29, + 11, + -9, + -8, + 8, + 10, + -1, + -14, + -30, + -30, + -8, + -9, + -20, + -17, + -17, + -12, + 1, + 6, + -7, + -18, + -6, + 10, + -6, + -7, + 29, + 35, + 21, + 16, + 9, + 25, + 44, + 26, + 21, + 34, + 28, + 40, + 41, + 9, + -2, + 1, + 12, + 34, + 18, + -12, + -10, + -16, + -29, + -24, + -25, + -20, + -17, + -35, + -29, + -12, + -29, + -39, + -32, + -30, + -17, + -12, + -28, + -20, + -5, + -4, + 7, + 14, + 10, + 3, + -3, + 0, + 19, + 27, + 4, + -21, + -18, + -7, + -4, + 0, + 1, + -6, + -17, + -30, + -24, + -11, + -9, + 0, + -1, + 0, + -3, + -12, + 1, + 15, + -2, + 3, + 16, + -3, + -8, + 7, + 3, + 13, + 32, + 23, + 10, + -6, + -11, + 8, + 4, + -12, + -9, + 3, + 12, + -2, + -31, + -36, + -33, + -37, + -17, + -5, + -20, + -14, + 4, + 5, + 4, + 6, + 17, + 31, + 27, + 23, + 16, + -1, + -4, + 15, + 24, + 21, + 18, + 7, + -7, + -14, + 18, + 41, + 25, + 14, + 13, + 2, + 5, + 12, + 8, + 15, + 10, + 2, + 13, + 10, + 3, + 5, + -1, + 0, + 11, + 10, + 6, + 2, + 7, + 10, + -4, + -3, + 2, + -13, + -4, + 14, + -4, + -17, + -11, + -4, + 8, + 3, + -8, + -1, + -7, + -20, + -4, + 23, + 23, + 8, + 5, + 24, + 21, + -5, + -2, + 7, + -9, + -15, + -8, + -6, + 6, + 2, + -26, + -19, + 1, + -19, + -31, + -27, + -34, + -41, + -47, + -39, + -12, + -12, + -29, + -32, + -41, + -36, + -26, + -36, + -35, + -33, + -29, + -1, + 5, + -13, + -21, + -21, + -3, + 12, + 1, + -7, + -1, + 2, + 12, + 9, + -1, + 15, + 21, + 18, + 25, + 4, + -13, + 5, + 12, + 16, + 33, + 33, + 19, + 21, + 26, + 30, + 30, + 24, + 23, + 19, + 22, + 34, + 39, + 28, + 15, + 14, + 24, + 24, + 18, + 12, + 10, + 4, + 8, + 28, + 29, + 2, + -7, + 6, + 8, + 10, + 2, + -13, + -8, + -2, + 0, + 12, + 13, + -1, + 3, + 21, + 26, + 24, + 17, + 11, + 15, + 19, + 19, + 19, + 11, + 1, + 3, + 3, + 0, + -5, + -11, + -16, + -26, + -18, + 3, + -5, + -17, + 2, + 10, + 6, + 6, + -8, + -11, + 4, + -3, + -17, + -10, + -17, + -37, + -31, + -17, + -26, + -37, + -42, + -53, + -49, + -34, + -40, + -39, + -21, + -17, + -23, + -23, + -25, + -30, + -24, + -13, + -10, + -10, + 1, + 1, + -7, + 7, + 19, + 11, + 4, + -3, + -8, + 1, + 6, + 7, + 25, + 22, + -5, + 3, + 20, + 7, + -1, + 14, + 17, + 18, + 20, + 12, + 25, + 41, + 23, + 19, + 37, + 39, + 21, + 17, + 23, + 17, + 6, + 9, + 15, + 4, + -15, + -8, + 8, + 7, + 1, + -12, + -18, + -14, + -15, + -10, + 0, + -3, + 3, + 13, + -8, + -21, + -8, + -26, + -29, + -1, + -9, + -24, + -19, + -22, + -24, + -18, + -25, + -27, + -28, + -34, + -26, + -9, + -14, + -14, + -8, + -8, + -5, + 4, + 4, + -10, + -12, + -7, + -8, + -10, + -15, + -19, + -10, + -5, + -9, + -9, + -19, + -33, + -27, + -14, + -15, + -14, + -16, + -25, + -10, + 5, + -7, + -11, + 2, + 3, + 7, + 17, + 28, + 33, + 32, + 33, + 39, + 49, + 57, + 63, + 62, + 64, + 67, + 59, + 55, + 67, + 71, + 58, + 53, + 53, + 44, + 38, + 44, + 51, + 51, + 45, + 35, + 34, + 46, + 55, + 48, + 36, + 21, + 3, + -5, + 2, + 7, + 0, + -17, + -30, + -34, + -48, + -62, + -64, + -66, + -66, + -62, + -79, + -90, + -85, + -88, + -88, + -85, + -88, + -103, + -112, + -112, + -102, + -99, + -102, + -103, + -110, + -100, + -80, + -60, + -57, + -68, + -59, + -45, + -35, + -6, + 9, + -3, + 2, + 32, + 45, + 48, + 51, + 40, + 51, + 78, + 85, + 83, + 87, + 94, + 101, + 104, + 105, + 100, + 86, + 82, + 96, + 102, + 96, + 85, + 68, + 63, + 65, + 55, + 50, + 46, + 28, + 32, + 43, + 33, + 30, + 27, + 8, + 18, + 36, + 27, + 20, + 13, + -14, + -19, + 8, + 12, + 0, + -1, + -12, + -24, + -20, + -27, + -39, + -39, + -39, + -44, + -38, + -32, + -42, + -38, + -33, + -43, + -55, + -57, + -60, + -61, + -56, + -57, + -55, + -43, + -46, + -58, + -55, + -50, + -50, + -51, + -48, + -46, + -44, + -36, + -26, + -20, + -13, + -11, + -8, + 1, + 5, + 0, + 8, + 21, + 31, + 42, + 39, + 43, + 56, + 48, + 37, + 45, + 45, + 47, + 52, + 46, + 40, + 26, + 18, + 28, + 30, + 22, + 14, + 0, + -3, + 8, + 0, + -7, + 0, + -10, + -13, + -9, + -13, + -13, + -18, + -33, + -32, + -26, + -37, + -41, + -32, + -26, + -30, + -34, + -31, + -38, + -40, + -24, + -25, + -29, + -15, + -18, + -23, + -4, + 2, + -7, + 0, + 5, + 10, + 22, + 23, + 25, + 31, + 33, + 37, + 38, + 39, + 43, + 46, + 41, + 44, + 46, + 37, + 35, + 46, + 63, + 67, + 52, + 38, + 30, + 35, + 41, + 41, + 41, + 29, + 15, + 16, + 4, + -4, + 3, + -12, + -18, + -13, + -27, + -39, + -47, + -55, + -44, + -43, + -53, + -45, + -36, + -37, + -37, + -38, + -40, + -49, + -57, + -41, + -24, + -28, + -31, + -26, + -20, + -15, + -21, + -23, + -18, + -19, + -14, + -10, + -11, + 1, + -6, + -26, + -14, + -1, + -7, + -10, + -11, + -9, + 0, + -4, + -9, + 3, + 8, + 0, + -2, + 1, + 16, + 20, + 7, + 9, + 10, + 8, + 18, + 12, + 11, + 17, + -6, + -19, + 0, + 0, + -10, + -6, + -12, + -14, + -11, + -9, + -2, + -10, + -19, + -9, + -11, + -4, + 18, + 7, + -3, + 9, + 17, + 23, + 28, + 25, + 19, + 19, + 24, + 33, + 37, + 30, + 28, + 35, + 44, + 43, + 33, + 31, + 30, + 26, + 33, + 39, + 35, + 31, + 27, + 19, + 23, + 24, + 19, + 13, + 0, + 0, + 2, + -7, + -9, + -10, + -13, + -6, + -6, + -23, + -28, + -15, + -9, + -20, + -34, + -30, + -15, + -12, + -11, + -3, + -4, + -4, + 6, + 15, + 9, + -11, + -20, + 3, + 26, + 23, + 1, + -16, + -3, + 12, + 2, + -22, + -36, + -35, + -28, + -20, + -13, + -19, + -38, + -43, + -29, + -11, + -5, + -15, + -37, + -40, + -9, + 12, + -1, + -23, + -30, + -16, + 12, + 21, + -1, + -25, + -21, + 4, + 34, + 55, + 34, + -12, + -11, + 47, + 99, + 107, + 58, + 0, + 8, + 78, + 148, + 151, + 56, + -40, + -2, + 142, + 215, + 99, + -67, + -64, + 76, + 153, + 99, + -21, + -107, + -92, + -1, + 106, + 107, + -123, + -395, + -334, + 60, + 274, + -69, + -597, + -626, + -126, + 238, + 18, + -447, + -577, + -312, + -34, + 20, + -89, + -242, + -332, + -222, + 74, + 262, + 64, + -285, + -232, + 259, + 563, + 294, + -138, + -130, + 312, + 642, + 515, + 189, + 57, + 187, + 415, + 538, + 467, + 277, + 109, + 134, + 334, + 441, + 299, + 59, + -7, + 128, + 228, + 146, + -20, + -99, + -34, + 60, + 24, + -108, + -188, + -147, + -57, + -48, + -142, + -224, + -210, + -144, + -122, + -175, + -212, + -176, + -150, + -199, + -256, + -210, + -100, + -79, + -195, + -298, + -248, + -107, + -48, + -110, + -192, + -224, + -189, + -112, + -40, + -31, + -124, + -238, + -193, + -3, + 87, + -53, + -221, + -165, + 48, + 132, + -2, + -150, + -109, + 61, + 147, + 83, + -20, + -60, + -13, + 85, + 157, + 130, + 17, + -68, + -10, + 147, + 217, + 116, + -20, + -21, + 103, + 200, + 158, + 52, + 35, + 105, + 155, + 132, + 81, + 74, + 110, + 114, + 74, + 48, + 68, + 100, + 77, + 27, + 30, + 48, + 19, + -15, + 7, + 63, + 53, + -56, + -123, + -41, + 81, + 75, + -61, + -154, + -84, + 45, + 68, + -24, + -105, + -76, + 22, + 53, + -13, + -63, + -21, + 54, + 59, + -1, + -34, + 16, + 80, + 81, + 48, + 37, + 61, + 89, + 88, + 101, + 134, + 132, + 100, + 83, + 125, + 188, + 173, + 101, + 95, + 172, + 214, + 149, + 68, + 94, + 181, + 177, + 103, + 83, + 132, + 165, + 122, + 83, + 140, + 191, + 153, + 92, + 106, + 198, + 226, + 138, + 85, + 146, + 215, + 187, + 110, + 77, + 115, + 146, + 115, + 91, + 96, + 78, + 27, + -3, + 42, + 102, + 71, + -23, + -46, + 30, + 95, + 63, + -18, + -25, + 77, + 174, + 138, + 13, + -25, + 96, + 218, + 181, + 34, + -70, + -45, + 17, + 2, + -67, + -174, + -346, + -516, + -553, + -446, + -455, + -789, + -1213, + -1308, + -1046, + -878, + -1179, + -1691, + -1839, + -1528, + -1219, + -1292, + -1623, + -1772, + -1538, + -1147, + -921, + -951, + -1038, + -929, + -549, + -95, + 155, + 127, + 97, + 387, + 931, + 1339, + 1380, + 1234, + 1276, + 1661, + 2102, + 2223, + 2027, + 1848, + 1942, + 2198, + 2295, + 2119, + 1856, + 1725, + 1745, + 1752, + 1601, + 1335, + 1102, + 993, + 952, + 830, + 570, + 286, + 139, + 133, + 85, + -135, + -436, + -638, + -645, + -571, + -620, + -835, + -1064, + -1151, + -1069, + -951, + -964, + -1109, + -1209, + -1162, + -1044, + -961, + -944, + -977, + -1001, + -912, + -687, + -517, + -623, + -887, + -897, + -469, + 10, + -35, + -590, + -934, + -545, + 184, + 427, + -53, + -619, + -563, + 40, + 489, + 339, + -128, + -306, + -6, + 403, + 497, + 232, + -55, + 0, + 388, + 704, + 584, + 145, + -76, + 260, + 816, + 942, + 485, + 2, + 65, + 575, + 923, + 744, + 290, + 76, + 276, + 596, + 662, + 419, + 134, + 92, + 280, + 434, + 344, + 88, + -66, + 8, + 151, + 126, + -81, + -239, + -176, + -29, + -74, + -351, + -574, + -487, + -208, + -132, + -426, + -780, + -797, + -577, + -595, + -978, + -1169, + -667, + -36, + -548, + -2285, + -3281, + -1756, + 927, + 1236, + -1911, + -5006, + -4073, + -66, + 2017, + -295, + -3701, + -3797, + -892, + 975, + -165, + -1978, + -1636, + 374, + 1482, + 679, + -567, + -591, + 706, + 2337, + 3224, + 2743, + 1269, + 287, + 1221, + 3597, + 5083, + 4106, + 1858, + 972, + 2334, + 4096, + 4167, + 2806, + 1916, + 2383, + 3045, + 2508, + 1220, + 820, + 1784, + 2669, + 1981, + 204, + -876, + -470, + 510, + 803, + 170, + -787, + -1568, + -1893, + -1598, + -1027, + -992, + -1803, + -2610, + -2484, + -1905, + -2113, + -3113, + -3399, + -2267, + -1261, + -2007, + -3637, + -3909, + -2340, + -893, + -1158, + -2272, + -2486, + -1639, + -915, + -777, + -596, + -91, + 196, + 85, + 210, + 875, + 1373, + 1247, + 1219, + 1958, + 2718, + 2328, + 1196, + 1008, + 2350, + 3677, + 3269, + 1503, + 366, + 922, + 2264, + 2810, + 1996, + 608, + -168, + 75, + 680, + 811, + 395, + -56, + -318, + -607, + -966, + -1108, + -925, + -613, + -368, + -369, + -919, + -1926, + -2460, + -1685, + -300, + 155, + -611, + -1524, + -2204, + -3227, + -3859, + -2037, + 1622, + 2382, + -2583, + -8448, + -7544, + -84, + 4814, + 915, + -6423, + -7558, + -1746, + 2515, + -59, + -4587, + -3858, + 1260, + 3625, + 187, + -4148, + -3500, + 1542, + 5467, + 4780, + 1256, + -1127, + -403, + 2481, + 5332, + 6346, + 5014, + 2536, + 1216, + 2467, + 5039, + 6238, + 5070, + 3381, + 3269, + 4173, + 3905, + 2248, + 1586, + 3299, + 5240, + 4362, + 1004, + -1382, + -489, + 2113, + 3168, + 1620, + -742, + -1824, + -1435, + -897, + -1058, + -1500, + -1545, + -1398, + -1965, + -3266, + -4136, + -3756, + -2609, + -1804, + -1986, + -3087, + -4599, + -5296, + -4051, + -1731, + -781, + -2228, + -4092, + -3977, + -2325, + -1353, + -1568, + -1490, + -428, + 178, + -672, + -1650, + -1058, + 749, + 2039, + 2079, + 1540, + 897, + 310, + 572, + 2266, + 4265, + 4265, + 1869, + -231, + 559, + 3332, + 4752, + 3229, + 768, + 101, + 1364, + 2463, + 1984, + 819, + 411, + 723, + 675, + -162, + -923, + -743, + -32, + 185, + -516, + -1653, + -2359, + -2103, + -986, + 42, + -205, + -1702, + -2870, + -2337, + -809, + -221, + -982, + -1544, + -946, + -598, + -2117, + -4291, + -4100, + -857, + 1948, + 338, + -4799, + -7972, + -5403, + 173, + 2371, + -1063, + -5533, + -5578, + -1777, + 605, + -985, + -3249, + -2213, + 1184, + 2691, + 560, + -2356, + -2288, + 1233, + 5244, + 6441, + 4004, + 370, + -663, + 2555, + 7404, + 9282, + 6573, + 2612, + 1836, + 4662, + 7467, + 7393, + 5421, + 4262, + 4741, + 5362, + 4705, + 3163, + 2397, + 3337, + 4887, + 4810, + 2254, + -749, + -1316, + 772, + 2706, + 2016, + -573, + -2552, + -2746, + -2012, + -1647, + -1978, + -2579, + -3105, + -3473, + -3911, + -4484, + -4891, + -4795, + -4163, + -3543, + -3538, + -4275, + -5356, + -5743, + -4637, + -2614, + -1301, + -1825, + -3341, + -4011, + -2937, + -751, + 1007, + 1245, + 235, + -639, + -61, + 1626, + 2864, + 2967, + 2734, + 3013, + 3329, + 2914, + 2312, + 2666, + 3839, + 4308, + 3162, + 1453, + 768, + 1255, + 1887, + 2006, + 1715, + 1031, + -297, + -1660, + -1690, + -277, + 813, + -30, + -2137, + -3370, + -2854, + -1553, + -593, + -413, + -1146, + -2567, + -3440, + -2369, + -205, + 379, + -1258, + -2315, + -812, + 262, + -3205, + -8576, + -7894, + 738, + 7492, + 1951, + -11595, + -17098, + -6934, + 7139, + 8065, + -4575, + -14199, + -8946, + 3606, + 7504, + -547, + -8242, + -5113, + 4406, + 8113, + 2134, + -5040, + -4089, + 4157, + 10934, + 10158, + 4167, + -565, + -192, + 4428, + 9765, + 12201, + 9861, + 4512, + 1225, + 3451, + 8483, + 10133, + 6497, + 2574, + 3333, + 6806, + 6986, + 2487, + -1214, + 623, + 5416, + 6647, + 2204, + -3289, + -4556, + -1565, + 1544, + 1525, + -1236, + -4293, + -5695, + -5174, + -3995, + -3403, + -3449, + -3750, + -4505, + -6014, + -7296, + -6523, + -3849, + -2096, + -3288, + -5722, + -6004, + -3581, + -1497, + -1960, + -3330, + -2800, + -434, + 964, + -111, + -1739, + -1136, + 1736, + 4151, + 3736, + 1274, + -451, + 469, + 3386, + 5833, + 5898, + 3646, + 1085, + 272, + 1743, + 4061, + 5108, + 3837, + 1490, + 246, + 967, + 1866, + 859, + -1069, + -974, + 1542, + 2835, + 47, + -4285, + -5068, + -1567, + 1781, + 1223, + -1997, + -4227, + -3747, + -1720, + 41, + 245, + -1228, + -2972, + -2673, + 22, + 1980, + -930, + -7721, + -11271, + -5725, + 4974, + 8484, + -2007, + -16979, + -19255, + -4670, + 11057, + 9690, + -6417, + -17537, + -10841, + 4262, + 9292, + 206, + -9128, + -6224, + 4828, + 10018, + 3699, + -5183, + -5121, + 4702, + 14279, + 14466, + 5778, + -2633, + -2185, + 7036, + 16118, + 16305, + 8081, + 390, + 499, + 6580, + 11150, + 10036, + 5704, + 2902, + 3378, + 4664, + 3786, + 863, + -796, + 1216, + 4609, + 4493, + -338, + -5670, + -6486, + -2751, + 884, + 571, + -3095, + -6446, + -6997, + -5770, + -5041, + -5016, + -4216, + -2579, + -2468, + -5088, + -8129, + -7964, + -4228, + -323, + 497, + -1556, + -3653, + -3615, + -1718, + 464, + 1808, + 2386, + 2832, + 3085, + 2905, + 2676, + 3473, + 5501, + 7094, + 6442, + 3929, + 1663, + 1436, + 3254, + 5807, + 7100, + 5044, + -34, + -4091, + -2992, + 2149, + 5333, + 2562, + -3067, + -5877, + -4480, + -2080, + -1793, + -3026, + -3838, + -3735, + -3663, + -4472, + -5756, + -5753, + -3576, + -640, + -274, + -3965, + -7787, + -6757, + -717, + 4380, + 3595, + -1553, + -5936, + -8603, + -10223, + -8952, + -922, + 9700, + 9355, + -7788, + -25795, + -22413, + 2268, + 20887, + 12133, + -11291, + -20129, + -5899, + 10236, + 8585, + -3645, + -6300, + 4667, + 14216, + 9346, + -3593, + -8558, + 715, + 15085, + 21179, + 14887, + 3733, + -2703, + -675, + 7170, + 15131, + 18360, + 13959, + 4205, + -2825, + -656, + 7594, + 11845, + 7182, + 319, + -439, + 3255, + 3213, + -3299, + -8972, + -6318, + 2300, + 7190, + 2254, + -9247, + -17334, + -15064, + -4452, + 5160, + 5127, + -4268, + -14501, + -17256, + -11145, + -1830, + 3786, + 2984, + -2498, + -8101, + -9587, + -5703, + 622, + 4570, + 4035, + 1442, + 729, + 2493, + 3534, + 2433, + 2239, + 5944, + 11438, + 12371, + 6496, + -211, + -156, + 7092, + 13566, + 11979, + 3928, + -2545, + -2226, + 2713, + 6150, + 5117, + 1270, + -1851, + -2859, + -2376, + -1909, + -2364, + -3401, + -4183, + -3897, + -2875, + -3205, + -5503, + -7822, + -7501, + -3934, + -942, + -1572, + -4262, + -5939, + -4671, + -2353, + -1387, + -1159, + -1270, + -1328, + -606, + 474, + 1044, + -2647, + -11603, + -17081, + -10374, + 5922, + 14849, + 2056, + -22033, + -31238, + -14612, + 11094, + 17910, + 1778, + -15538, + -15417, + -2045, + 6690, + 2855, + -2559, + 473, + 8823, + 11423, + 3782, + -4649, + -2775, + 9111, + 20847, + 21610, + 11572, + 962, + -1465, + 5731, + 15559, + 20008, + 16950, + 9230, + 2204, + 114, + 3088, + 8130, + 10523, + 7643, + 2045, + -2107, + -2945, + -2538, + -3593, + -5210, + -4403, + -857, + 1328, + -2497, + -11667, + -18881, + -16866, + -6286, + 3400, + 2835, + -7811, + -18322, + -19279, + -10025, + 1525, + 6930, + 3766, + -4647, + -11401, + -9904, + -322, + 10100, + 12428, + 5874, + -274, + 926, + 6762, + 9360, + 6778, + 5904, + 10509, + 15077, + 12681, + 3846, + -1653, + 2460, + 11036, + 14737, + 8967, + -1021, + -6168, + -3899, + 2328, + 6041, + 3404, + -2878, + -7672, + -6869, + -1918, + 801, + -2188, + -7419, + -8083, + -2687, + 1898, + -692, + -8121, + -11198, + -5642, + 2830, + 5915, + 1120, + -5666, + -8314, + -5770, + 118, + 4614, + 4713, + 1482, + -2544, + -3331, + -3779, + -8931, + -13840, + -10273, + 3355, + 13432, + 2906, + -20058, + -30890, + -17080, + 7759, + 16047, + 2886, + -12525, + -15117, + -5998, + 1614, + 2294, + 2684, + 4610, + 6236, + 5486, + 2514, + 1346, + 1962, + 4564, + 11022, + 17438, + 18182, + 10179, + -796, + -3019, + 5456, + 15942, + 18468, + 11176, + 2796, + -143, + 1670, + 3922, + 3836, + 3337, + 3330, + 1623, + -2609, + -7177, + -7654, + -4250, + -2210, + -3491, + -5312, + -4380, + -3103, + -6738, + -13209, + -14278, + -6529, + 3346, + 4931, + -2861, + -11176, + -12097, + -5552, + 2679, + 7102, + 6050, + 1301, + -3350, + -3378, + 1785, + 7413, + 9059, + 7013, + 5043, + 5331, + 5197, + 3143, + 1862, + 3790, + 8037, + 10159, + 7236, + 1450, + -3393, + -3980, + 598, + 6251, + 7410, + 1502, + -7144, + -10260, + -5116, + 2386, + 4197, + -894, + -6255, + -6026, + -1493, + 873, + -1639, + -4426, + -2720, + 2252, + 4206, + 158, + -4631, + -4466, + 537, + 4709, + 4528, + 1691, + -828, + -1394, + -455, + 756, + 2662, + 3101, + 1730, + -3579, + -12987, + -18531, + -12998, + 1944, + 11963, + 1503, + -19826, + -29919, + -18138, + 2254, + 7644, + -1829, + -9260, + -6516, + 134, + -793, + -5234, + -2336, + 6264, + 12828, + 11829, + 6589, + 3429, + 2592, + 4795, + 11433, + 19490, + 21681, + 13136, + 379, + -4138, + 3585, + 14812, + 17633, + 10124, + 623, + -2287, + 696, + 2273, + -926, + -5000, + -4391, + -386, + 139, + -4657, + -11003, + -13946, + -11930, + -7460, + -1932, + 1277, + -2311, + -10543, + -16920, + -14512, + -4039, + 4987, + 7518, + 3175, + -4213, + -7535, + -4747, + 3590, + 12231, + 13419, + 8429, + 2377, + 1080, + 5563, + 8497, + 7304, + 5331, + 5656, + 8235, + 6997, + 998, + -3131, + -1857, + 3017, + 5883, + 3744, + -408, + -4503, + -6489, + -4796, + -374, + 3254, + 1651, + -2830, + -5206, + -3690, + -681, + -969, + -2819, + -2616, + 19, + 3379, + 2359, + -2476, + -6413, + -6111, + -463, + 4664, + 4106, + -565, + -4801, + -4960, + -1242, + 2479, + 3706, + 2168, + -1104, + -3048, + -1563, + 1217, + 2013, + -5714, + -17921, + -21743, + -10839, + 7751, + 13091, + -4648, + -26509, + -29653, + -9872, + 10100, + 9523, + -4335, + -12121, + -5509, + 4923, + 6380, + 1839, + -508, + 3312, + 10704, + 14545, + 12317, + 5508, + -243, + 2421, + 11485, + 19096, + 18306, + 8626, + -1357, + -5542, + -1695, + 7815, + 13549, + 10229, + -23, + -8373, + -7496, + -2775, + -1016, + -2900, + -4868, + -4103, + -4535, + -6851, + -8099, + -8137, + -6414, + -4023, + -1790, + -45, + -1513, + -4791, + -6160, + -4105, + 1060, + 5970, + 7099, + 3934, + -996, + -2213, + 1973, + 6975, + 7927, + 4726, + 2474, + 3951, + 5221, + 2642, + -2359, + -3579, + 1362, + 6614, + 6282, + 116, + -5643, + -5733, + -1884, + 2107, + 3418, + 2566, + 684, + -2319, + -3803, + -2133, + 1512, + 2943, + 475, + -1004, + 753, + 3095, + 1652, + -3074, + -4562, + -932, + 3815, + 4486, + -22, + -4199, + -4666, + -2201, + 284, + 316, + -914, + -2297, + -2441, + -1538, + -435, + 909, + 626, + -1222, + -1534, + -429, + 1711, + 2386, + -1786, + -10676, + -18200, + -16272, + -3805, + 9505, + 8238, + -9397, + -24577, + -22256, + -4907, + 8659, + 5940, + -3701, + -6764, + 40, + 6190, + 4239, + 208, + 238, + 7081, + 14458, + 15143, + 10726, + 3479, + -706, + 1700, + 9131, + 17577, + 17708, + 7959, + -5009, + -11508, + -5347, + 5635, + 10789, + 6499, + -3121, + -9303, + -9814, + -6625, + -3333, + -3193, + -4349, + -5615, + -6188, + -5123, + -4441, + -4550, + -4074, + -2769, + -61, + 2441, + 2881, + 1395, + -578, + -341, + 2509, + 6034, + 8202, + 6377, + 2696, + 1272, + 2589, + 4787, + 4611, + 2378, + 2124, + 3911, + 4872, + 2049, + -3374, + -5770, + -2705, + 3179, + 5905, + 2589, + -2792, + -5419, + -3176, + 1056, + 2875, + 2483, + 1205, + 605, + 856, + 1012, + 892, + 105, + -411, + 707, + 2924, + 4184, + 1755, + -2553, + -4857, + -3556, + 401, + 2466, + 945, + -2315, + -5556, + -5549, + -2241, + 534, + 601, + -1774, + -3034, + -1962, + -886, + -448, + -720, + -467, + 864, + 760, + -22, + -2546, + -10211, + -17121, + -15877, + -4803, + 7993, + 7254, + -6563, + -18374, + -17755, + -6143, + 3291, + 4322, + 1822, + 416, + 2788, + 5190, + 4256, + 2627, + 2590, + 6398, + 12709, + 15757, + 12829, + 5542, + -667, + 167, + 7241, + 14346, + 14826, + 6392, + -3516, + -7434, + -4607, + 1054, + 2988, + 847, + -1549, + -2641, + -3046, + -5363, + -8256, + -9130, + -6906, + -1460, + 2260, + 1568, + -2911, + -8580, + -9418, + -3675, + 5021, + 10127, + 7909, + 1478, + -4015, + -3331, + 2450, + 7291, + 7632, + 2567, + -2022, + -899, + 3418, + 5544, + 1349, + -4117, + -3409, + 1758, + 6000, + 3526, + -3975, + -7331, + -3931, + 2747, + 7037, + 4962, + -21, + -2902, + -2008, + 1306, + 4461, + 6364, + 5956, + 3623, + 1734, + 793, + 44, + -893, + -1041, + 1633, + 5264, + 4870, + -943, + -7404, + -8611, + -4974, + -1192, + 185, + -1334, + -3672, + -4910, + -5132, + -4387, + -3532, + -3233, + -2430, + -469, + 1245, + 892, + -969, + -2441, + -2140, + 320, + 4999, + 5954, + -4638, + -20056, + -24424, + -8954, + 13558, + 16089, + -3145, + -20665, + -19447, + -4802, + 4488, + 3733, + 943, + 683, + 3109, + 6219, + 9247, + 7736, + 782, + -1410, + 8024, + 20877, + 20174, + 4723, + -7148, + -2758, + 11240, + 17896, + 11462, + 414, + -6134, + -4913, + 113, + 2818, + 98, + -5900, + -8369, + -4446, + 924, + 1657, + -3389, + -10569, + -13223, + -7690, + 2339, + 7741, + 1634, + -9014, + -10982, + -1172, + 9642, + 9098, + 1310, + -2795, + -1040, + 2790, + 3808, + 3559, + 3064, + -527, + -3160, + -1391, + 3120, + 5224, + -144, + -6714, + -6416, + -719, + 5630, + 7253, + 2735, + -2973, + -4325, + 679, + 7146, + 8220, + 4055, + -42, + 814, + 5288, + 7658, + 6592, + 3051, + -746, + -541, + 3401, + 6030, + 1953, + -6340, + -8619, + -2689, + 4076, + 3217, + -4875, + -9612, + -7826, + -4293, + -2441, + -4080, + -5740, + -5529, + -3656, + -506, + -1035, + -5787, + -9518, + -7034, + 2323, + 9287, + 6495, + -1853, + -6110, + -3281, + -1708, + -8958, + -19544, + -18870, + -2771, + 13029, + 10762, + -7491, + -21837, + -18923, + -4183, + 8733, + 12580, + 9779, + 4597, + 738, + 1460, + 6302, + 9711, + 8375, + 8143, + 12512, + 15808, + 11272, + 389, + -5554, + 161, + 11080, + 15851, + 10426, + 692, + -6372, + -6808, + -2525, + 652, + 827, + -219, + -349, + -622, + -3328, + -7883, + -11020, + -8961, + -3240, + 1884, + 4155, + 1995, + -3530, + -7816, + -6444, + -218, + 6086, + 9279, + 7901, + 3113, + -2352, + -5757, + -3836, + 2022, + 4572, + 894, + -3519, + -3311, + -534, + -618, + -3716, + -5515, + -3290, + 1495, + 4374, + 4455, + 2961, + -645, + -3247, + -656, + 5273, + 9838, + 9751, + 5755, + 1863, + 158, + 1457, + 4585, + 6390, + 5379, + 2894, + 2284, + 1867, + -2279, + -7051, + -6578, + 70, + 4745, + 1660, + -4524, + -8007, + -7088, + -5690, + -5467, + -4178, + -2679, + -2218, + -3422, + -4167, + -4313, + -6105, + -6633, + -4202, + 864, + 5119, + 4084, + -163, + -5331, + -8699, + -8710, + -7313, + -4649, + -2471, + -1419, + -1136, + -3199, + -6428, + -8048, + -4902, + 1089, + 4681, + 5723, + 5535, + 5146, + 4006, + 2052, + 2314, + 5274, + 8680, + 9907, + 8776, + 6722, + 2548, + -2403, + -3303, + 1224, + 7406, + 9468, + 5089, + -1197, + -4384, + -3570, + -298, + 1776, + 2005, + 2041, + 1326, + 971, + -180, + -2334, + -1170, + 1913, + 4281, + 4732, + 2874, + 1174, + -1341, + -3384, + -2503, + 368, + 4031, + 3270, + -986, + -3519, + -5360, + -6004, + -5576, + -3603, + 208, + 708, + -2137, + -4940, + -5349, + -3588, + -2796, + -1399, + 1017, + 3144, + 4196, + 2483, + 828, + 338, + 919, + 3842, + 6202, + 7189, + 7499, + 6330, + 4847, + 3252, + 2136, + 3698, + 5845, + 5566, + 3019, + 267, + -55, + -1091, + -4220, + -5041, + -3430, + -280, + 171, + -4649, + -8723, + -9280, + -5975, + -3192, + -3974, + -3912, + -4053, + -3748, + -3570, + -5871, + -5499, + -3552, + -1691, + 320, + 341, + 748, + -313, + -3436, + -4687, + -3681, + 21, + 2550, + 643, + -2123, + -3254, + -2226, + -1044, + -1617, + -1510, + 183, + 1250, + 726, + -1662, + -3388, + -1759, + 933, + 3817, + 5242, + 3025, + 248, + -1339, + -514, + 2022, + 3410, + 3970, + 3324, + 2632, + 2603, + 2240, + 2166, + 1271, + 487, + 1076, + 2039, + 3296, + 3836, + 3610, + 2913, + 2718, + 4213, + 5555, + 6023, + 4769, + 2442, + 2067, + 2173, + 1623, + 1201, + 348, + 52, + -124, + -1528, + -2834, + -3604, + -3463, + -2357, + -2564, + -3775, + -3801, + -1929, + -465, + -2109, + -3743, + -2657, + 200, + 2580, + 954, + -1304, + -95, + 1549, + 2303, + 1795, + 1633, + 3356, + 3699, + 2361, + 792, + 1148, + 4045, + 4820, + 3851, + 3197, + 2449, + 2704, + 1722, + -652, + -1154, + -393, + 113, + -1010, + -3328, + -4342, + -3939, + -3345, + -3697, + -5115, + -5610, + -4202, + -3639, + -5088, + -5351, + -3216, + -862, + -414, + -1839, + -3996, + -4831, + -2467, + 147, + 1055, + 1288, + -247, + -2225, + -2233, + -1562, + -1278, + -936, + -961, + -935, + -367, + -323, + -459, + -1940, + -3974, + -2262, + -13, + 2, + -401, + -1825, + -2308, + -1124, + 448, + 2154, + 2434, + 1300, + -812, + -1337, + 1325, + 3374, + 3466, + 2500, + 2156, + 3439, + 3549, + 2068, + 1392, + 1986, + 3025, + 3944, + 3898, + 3259, + 4467, + 6347, + 5356, + 2893, + 1690, + 2072, + 4136, + 5313, + 2776, + -236, + -1063, + -794, + 524, + 802, + -1377, + -2879, + -2167, + -1439, + -1595, + -1539, + -1666, + -2495, + -2375, + -1253, + -515, + -187, + -1409, + -2847, + -511, + 2411, + 1761, + 492, + -18, + 607, + 2350, + 3288, + 3505, + 2741, + 1099, + 699, + 2017, + 3214, + 3333, + 1567, + 33, + 1260, + 1925, + 808, + -377, + -2558, + -3781, + -1677, + 164, + -580, + -1727, + -2619, + -3421, + -3586, + -3957, + -4562, + -3646, + -2285, + -3437, + -5293, + -4792, + -4128, + -4012, + -2920, + -2249, + -2439, + -3737, + -5607, + -4427, + -1259, + 71, + 609, + 555, + -1039, + -3354, + -5388, + -3760, + 415, + 2513, + 2513, + 819, + -1436, + -2780, + -2740, + -501, + 2727, + 3936, + 1491, + -965, + -766, + -484, + -223, + 361, + 695, + 1771, + 1130, + -1839, + -1764, + 797, + -31, + -2549, + -1790, + 2108, + 4043, + 887, + -154, + 2411, + 2605, + 2012, + 1977, + 3923, + 6630, + 4176, + 107, + -311, + 1731, + 1910, + 1011, + 3119, + 3219, + 998, + -1282, + -2832, + -1645, + -685, + 945, + 2574, + 2543, + -267, + -5015, + -3819, + -342, + 1228, + 2055, + -619, + -1233, + 2069, + 2896, + 1095, + 62, + 1365, + 3366, + 4584, + 4956, + 3323, + -19, + -50, + 4024, + 5222, + 3695, + 3118, + 1933, + 1256, + 1443, + 128, + -119, + 2043, + 2477, + 1823, + 1324, + 30, + -1363, + -3023, + -3074, + -188, + 621, + -1775, + -2806, + -2961, + -2753, + -4359, + -5350, + -1220, + -116, + -4157, + -4811, + -2793, + -1040, + -1957, + -2862, + -1901, + -3192, + -3720, + -2357, + -1727, + -387, + -2131, + -5011, + -3650, + -454, + 596, + -1298, + -3716, + -3122, + 496, + 136, + -2415, + -1675, + -811, + -837, + 140, + -1243, + -187, + -1431, + -5320, + -2121, + 100, + -467, + 2465, + 681, + -2093, + 1224, + 1632, + 1428, + 1776, + 648, + 2480, + 3622, + 876, + 259, + 1403, + 2139, + 3117, + 497, + -763, + -170, + 279, + 1769, + 342, + -871, + -25, + -1549, + -2290, + 290, + 1042, + -796, + -4291, + -3895, + 159, + 1264, + -540, + -2328, + -702, + 1972, + 852, + -2274, + -798, + 1126, + -579, + -480, + 3481, + 3833, + 1004, + 901, + 1536, + 1809, + 3103, + 2521, + 3183, + 5220, + 1800, + -266, + 4663, + 4230, + -790, + 159, + 2274, + 5114, + 4304, + -1998, + 344, + 4921, + -343, + -2048, + 1180, + 2112, + 3109, + -10, + -1818, + 552, + -1360, + -2889, + -1302, + -1918, + -37, + 1406, + -1762, + -3054, + -1446, + -2073, + -4292, + -3214, + 1163, + 2333, + -712, + -2583, + -2058, + -1034, + -600, + -3796, + -2395, + 2137, + -1122, + -1927, + 702, + -2196, + -4374, + -3257, + -1558, + -256, + -728, + -395, + -176, + -1529, + -2772, + -1121, + -340, + -1147, + -250, + -4079, + -473, + 4241, + -2818, + -3523, + 3255, + 2355, + -2550, + -1082, + 1197, + 2213, + -94, + -237, + 3123, + 1314, + -1075, + 977, + 1081, + 2045, + 2966, + -1328, + -1069, + -741, + -524, + -380, + -2766, + -986, + 926, + -3281, + -1554, + 2554, + -3620, + -6394, + -1680, + -321, + 2889, + 243, + -1567, + 2276, + -1294, + -525, + 2010, + -4883, + -1495, + 6778, + 2085, + -873, + 2496, + 418, + -1156, + -1179, + 1604, + 6173, + 1190, + -2381, + 5788, + 2431, + -4941, + -242, + 1248, + 1023, + 4426, + 3399, + 2726, + 1388, + -922, + 595, + 392, + 1414, + 6260, + 2673, + -973, + 2237, + 1776, + -2393, + -757, + 4158, + 2842, + -2327, + 505, + 1230, + -3623, + -917, + 336, + -1400, + -1018, + 1771, + 2696, + -570, + -2435, + 886, + 2309, + -2865, + -1328, + 2077, + -1967, + -3486, + -411, + 961, + -1661, + -1979, + 1179, + -493, + -2597, + 1995, + 284, + -3300, + -2213, + 184, + 312, + -1665, + -641, + -1325, + -1276, + 90, + 69, + 476, + -778, + -1099, + 853, + 1515, + 1630, + 1188, + -877, + -1751, + 702, + 2983, + -201, + 664, + 4018, + -352, + -1864, + 875, + 2367, + 813, + -2463, + -702, + 886, + -2204, + -2216, + 399, + -1729, + -2408, + 1412, + -2757, + -3530, + 449, + -2554, + -3910, + 906, + 697, + -1696, + 566, + -1360, + -1991, + 81, + -1756, + -159, + 1180, + -667, + -584, + -359, + 183, + 1943, + -412, + -1747, + 1659, + 1961, + 280, + 294, + 222, + 2000, + 2076, + 829, + -43, + -880, + 3353, + 3615, + 1279, + 1746, + -1031, + 1301, + 3477, + -777, + 2567, + 1215, + -2344, + 3556, + 561, + -2166, + 1119, + 2377, + -391, + -1825, + -2359, + 49, + 1764, + 391, + -291, + 325, + 1223, + 1443, + -624, + -2828, + 1381, + 2438, + 28, + -652, + -166, + 581, + -2039, + -374, + -20, + -2459, + -1149, + 1505, + 2008, + -1798, + -3848, + -1796, + -2208, + -2224, + -878, + 728, + -154, + -534, + 1061, + 538, + -1465, + 73, + 1147, + 82, + -119, + 3800, + 4797, + -873, + 784, + 1458, + -148, + 3180, + 1319, + 908, + 4951, + 584, + -57, + 2394, + -967, + 586, + 405, + -1601, + 3566, + -285, + -3949, + -1301, + -1953, + -1223, + -1831, + -3477, + -779, + -389, + -3169, + -1828, + -1496, + -1451, + -556, + -3327, + -209, + 534, + -4908, + 131, + -386, + -5232, + 1373, + 2129, + -1740, + -1957, + -1102, + 76, + 396, + -1426, + -179, + 1357, + -3276, + -1420, + 3819, + -44, + 56, + 2777, + -1202, + 1908, + 1410, + 2031, + 3495, + -2197, + -163, + 1565, + 239, + 2803, + 480, + -1636, + 1180, + 616, + 1206, + 1166, + -1579, + 1572, + 814, + -774, + 2310, + 740, + -2606, + 1234, + -603, + -362, + 1562, + -2134, + 652, + -777, + -2353, + 5464, + 377, + -2490, + 1012, + 157, + 680, + -1389, + -1898, + 1135, + -1, + -1730, + 1800, + -1466, + -1687, + -1469, + -3250, + -1081, + 1381, + -81, + -204, + -26, + 353, + 1941, + 174, + 104, + 2009, + 1032, + -871, + 3280, + 3398, + -651, + -154, + 3309, + 1964, + 448, + 812, + -17, + 887, + 2405, + 3295, + -54, + -2396, + 1410, + 1380, + -1156, + 296, + -1706, + -1729, + 401, + -970, + -878, + -723, + -2285, + 1259, + 1320, + -1960, + -1039, + -211, + -661, + -763, + -1599, + -43, + 308, + -1841, + 72, + -2075, + -3010, + -497, + 506, + -377, + 247, + 1932, + -1788, + -2419, + 257, + 208, + -2176, + 488, + 2827, + -1720, + -1649, + -619, + 520, + 1103, + -1231, + -1327, + 2162, + 1535, + -383, + 315, + -1488, + -235, + 1761, + -27, + -232, + 515, + 127, + -2239, + 654, + 2871, + -379, + -1274, + 2445, + 874, + -2444, + 514, + -206, + -1289, + 1314, + 1869, + 1316, + 1878, + -1454, + -982, + 476, + 359, + 2084, + -708, + 405, + -246, + -1071, + 1757, + -866, + -2331, + 783, + 501, + -853, + 896, + 36, + -2468, + -1138, + 1445, + -613, + -687, + 1999, + -449, + -731, + 1478, + 384, + -45, + 96, + 1530, + 1919, + 186, + -94, + 1347, + -329, + -348, + 1631, + 574, + 1062, + 735, + -1652, + 675, + 244, + 1241, + 1137, + -2469, + 621, + 45, + -612, + 1308, + -2015, + -208, + 2392, + -1646, + -67, + 77, + -1558, + 113, + 1263, + -236, + -971, + -333, + -733, + -555, + 2024, + -135, + -3817, + -398, + 1696, + -1179, + -1473, + 1175, + -166, + 618, + 1132, + -2504, + -575, + 146, + -688, + 1323, + 150, + -2021, + 15, + 1673, + 347, + -1535, + -106, + 235, + -32, + 1167, + -471, + -503, + -1260, + 416, + -13, + -1082, + 1036, + -790, + -1676, + 487, + 985, + 77, + 57, + -1175, + 1146, + 2023, + -1706, + -404, + 3249, + -739, + -979, + 3044, + -514, + -168, + 2201, + -2863, + 1009, + 1833, + -2309, + 1565, + 476, + -1698, + 1667, + -496, + -2193, + 1686, + 532, + 336, + -1095, + -1655, + 578, + -909, + -1263, + 2569, + -2833, + -1808, + 2860, + -822, + 27, + 1098, + -1371, + 1585, + -284, + -1074, + 2944, + -764, + -2871, + 2484, + 1179, + -1213, + -670, + -1226, + 1112, + 1837, + -299, + -388, + -51, + 1, + 992, + -723, + -361, + 1723, + -1115, + -2012, + 1261, + -9, + -127, + -510, + -1550, + 1448, + 957, + -1930, + 171, + 776, + -2104, + 14, + 764, + -599, + -745, + -438, + -371, + -659, + 1075, + 282, + -3116, + 684, + 3747, + 22, + -2139, + 816, + 1413, + -333, + 458, + 906, + 483, + -1084, + 797, + 1039, + -467, + -377, + 1386, + -1182, + 610, + 1787, + -1354, + -2800, + 2638, + 424, + -2372, + 1153, + -51, + -689, + 290, + -2199, + 818, + 3755, + -2674, + -1689, + 3497, + -507, + -1978, + 1729, + 1413, + 215, + -76, + 53, + 759, + 371, + -1529, + 1005, + -770, + -685, + 1754, + -908, + -653, + 1047, + -1066, + -784, + -199, + -526, + 86, + -1750, + -916, + 1839, + 580, + -1884, + 319, + 226, + -977, + 212, + 202, + -741, + -1013, + 2057, + 69, + -2961, + 974, + 1964, + -512, + -224, + 1554, + -79, + -1142, + 1853, + -71, + 1009, + 1174, + -718, + 2040, + -158, + -1508, + 1042, + 0, + -1219, + 1212, + 448, + -208, + -47, + -779, + -867, + 1924, + -254, + -1085, + -221, + -1283, + 1543, + -584, + -951, + 225, + -1089, + -464, + -853, + -615, + 1576, + -2313, + -1214, + 950, + -2548, + -314, + 1201, + -1527, + 952, + 764, + -1915, + 528, + 169, + -1676, + 1742, + 425, + -2346, + 932, + 290, + 109, + 492, + -379, + 932, + 70, + 582, + 135, + 769, + 1665, + -1751, + 576, + 1013, + 366, + 2339, + 71, + 637, + 1500, + 576, + 111, + 494, + 765, + 1170, + 1421, + -5, + -892, + 2054, + -640, + 160, + 1426, + -651, + 348, + -841, + -558, + 1563, + 277, + -408, + -1468, + 482, + -1538, + -2255, + 968, + -1307, + -454, + 1306, + -3085, + -1680, + 2624, + -2191, + -1719, + 1891, + -3826, + -1441, + 2736, + -3694, + -266, + 1897, + -4468, + 841, + 2828, + -4060, + -318, + 2305, + -1662, + 528, + 3056, + -2429, + -156, + 2045, + -753, + 475, + 419, + -597, + 1100, + 1845, + 504, + 1067, + -402, + -824, + 1807, + 1192, + 459, + 200, + 1728, + 50, + -497, + 678, + -355, + 938, + 1239, + -1223, + 360, + 1251, + -95, + 981, + 1029, + -1940, + 260, + 1627, + -2387, + 3426, + 519, + -3141, + 1822, + -506, + -1471, + 1101, + -2137, + 1069, + 885, + -2618, + 1673, + -463, + -1558, + 1439, + -386, + -1923, + 1538, + -1313, + -1735, + 540, + -1433, + -915, + 494, + -839, + -1527, + -1143, + 480, + -1081, + 27, + 1732, + -1285, + -1833, + 1952, + -667, + -1626, + 1819, + -1293, + -1323, + 2139, + -376, + -1392, + 1277, + -1172, + -240, + 2907, + -1875, + -238, + 2573, + -1068, + -471, + 2065, + -686, + -1315, + 2575, + 233, + -1005, + 1135, + 706, + 534, + 278, + -182, + 1091, + -21, + -222, + 1413, + -371, + -54, + 1108, + -103, + 382, + -70, + 787, + 894, + -108, + 1308, + 1113, + -1412, + 574, + 1140, + -2032, + 500, + 569, + -1251, + 951, + -50, + -1398, + 772, + -474, + -1536, + 1297, + 251, + -2321, + 109, + -703, + -425, + 40, + -1354, + -773, + -225, + -1743, + -1839, + 1244, + 261, + -3082, + -424, + 1162, + -937, + 123, + -322, + -407, + -561, + -331, + 1369, + -1142, + -1050, + 1024, + 1116, + -213, + -752, + 1521, + -383, + -415, + 1011, + 947, + -713, + 743, + 1945, + -237, + 881, + 600, + -757, + 885, + -835, + 756, + 2454, + -1985, + 699, + 1572, + -1652, + 673, + 232, + -42, + 1975, + -736, + -270, + 1660, + -704, + -96, + 1264, + -428, + 278, + 774, + -954, + -1325, + 756, + 1275, + -594, + -353, + 204, + -1130, + -782, + -432, + -979, + 268, + 378, + 20, + -870, + 405, + -357, + -1661, + 637, + 473, + 293, + -314, + -895, + 3, + -175, + -1016, + -643, + 204, + -588, + -1007, + -131, + 401, + -849, + -476, + 271, + 320, + -198, + 533, + -25, + -1994, + 1421, + 525, + -1611, + 1261, + 507, + -488, + 1093, + 361, + -1814, + 2230, + 312, + -196, + 3242, + -803, + -962, + 1714, + -1479, + 1426, + 1612, + -1953, + 1376, + -581, + -669, + 1370, + -1251, + 426, + 1274, + -470, + 1757, + 807, + -589, + 1275, + 126, + -871, + 1025, + -1331, + 287, + 1258, + -1813, + 146, + -839, + -1471, + 828, + -402, + -281, + 1704, + -1341, + -231, + 939, + -1035, + -472, + -197, + -764, + -380, + -816, + -266, + 382, + -497, + -1708, + -591, + 1119, + -1941, + 178, + 969, + -1656, + 685, + 1004, + -1114, + -127, + -1473, + -678, + 1610, + -1253, + 277, + 1807, + -1642, + -461, + 2033, + -1449, + 392, + 98, + -157, + 1525, + -860, + 2455, + 413, + -2159, + 2457, + 475, + -374, + 1532, + -981, + 843, + 973, + 324, + 1168, + 225, + -407, + 1487, + 681, + -680, + 1098, + 117, + 245, + 1238, + -223, + 1076, + -428, + -466, + 2593, + -663, + -1225, + 1303, + -933, + -561, + 1190, + -1071, + -1229, + 406, + -284, + -13, + 198, + -1494, + -637, + 352, + -1960, + 420, + 49, + -1472, + -761, + -234, + -2213, + -1750, + -521, + -1554, + -813, + 662, + -633, + -1388, + -15, + -947, + -391, + -152, + -894, + 631, + -461, + -885, + 633, + -51, + -1063, + 218, + 1149, + -61, + -274, + 988, + -140, + 7, + 1774, + 1558, + -623, + 755, + 1352, + -511, + 1106, + 744, + 17, + 2640, + -91, + 697, + 1547, + -1757, + 1832, + 1859, + -206, + 1505, + 575, + -444, + 556, + 250, + 1786, + 792, + -125, + -266, + 407, + 501, + 798, + -536, + -1214, + 58, + 6, + 354, + -685, + 613, + 99, + -2022, + -116, + -236, + -182, + 263, + -824, + -1187, + -142, + -138, + -1228, + -1008, + 786, + -1421, + -1127, + -269, + -2278, + 841, + 222, + -2423, + 678, + -1153, + -2082, + 574, + -570, + -729, + 180, + -777, + 212, + 270, + -274, + 1077, + -493, + 118, + 804, + -1260, + 349, + 799, + 545, + 481, + 971, + 1099, + 1146, + -273, + 34, + 1728, + 1128, + 411, + 758, + 308, + -808, + 950, + 1490, + 209, + -265, + 1154, + -11, + -460, + 2644, + -122, + -728, + 2033, + -1100, + -305, + 1774, + -208, + -1567, + -57, + -140, + -670, + -454, + -1390, + -80, + 978, + -438, + -731, + -684, + 344, + -458, + -199, + -126, + -1663, + -883, + 642, + -1517, + -1144, + -375, + -422, + -452, + -1815, + -791, + 763, + -1502, + -205, + 684, + -1641, + 448, + 1399, + -2160, + 804, + 1088, + -2214, + 1030, + 1585, + -1093, + -11, + 1718, + -360, + -81, + 1294, + 398, + 218, + 1225, + 644, + 505, + 2090, + -385, + 526, + 2111, + -303, + -316, + 1550, + 1323, + -459, + 881, + 1874, + -1256, + 1429, + 2485, + -1003, + -552, + 14, + 432, + 952, + 471, + -633, + 408, + -358, + 140, + 554, + -1260, + -404, + 245, + -2572, + 954, + 1005, + -1621, + -82, + -175, + -957, + 112, + 106, + -1117, + -819, + -62, + -785, + 71, + 93, + -1296, + -1680, + 242, + -956, + -2696, + 302, + -204, + -1404, + 254, + -558, + -201, + -630, + 16, + -436, + -1647, + 1649, + -1096, + -1267, + 2273, + -1270, + 20, + 1749, + -2509, + 780, + 942, + -1859, + 2762, + 304, + -300, + 2617, + -947, + 861, + 2601, + -1153, + 754, + 1629, + -681, + 686, + 1443, + -235, + 1900, + 5, + -565, + 1559, + 285, + -170, + 757, + 480, + 547, + 752, + -427, + 50, + 839, + -95, + -791, + -1698, + -291, + -62, + -1730, + 524, + 1008, + -2176, + -369, + 165, + -749, + -972, + -287, + 889, + -1218, + -1712, + 833, + -855, + -995, + -14, + -793, + -1815, + 605, + -607, + -1890, + 769, + -781, + 230, + 1155, + -2000, + 876, + 1835, + -1617, + 9, + 1058, + -1232, + 859, + 1486, + -1301, + 1595, + 501, + -951, + 2935, + -921, + -634, + 2826, + -793, + 655, + 2660, + -232, + 235, + 1879, + 481, + -51, + 804, + 987, + -360, + -331, + 2099, + -302, + -149, + 1966, + -1233, + -12, + 1330, + -2265, + 1256, + -116, + -1394, + 2937, + -995, + -1572, + 2964, + -2257, + -2587, + 1820, + -2132, + -1609, + 778, + -1596, + -486, + 560, + -1749, + 274, + -706, + -1714, + 1304, + -360, + -2657, + 1833, + -750, + -1729, + 433, + -1461, + -794, + -1545, + -892, + 385, + -891, + -374, + 1261, + -589, + 235, + 815, + -773, + -669, + 636, + -471, + 136, + 871, + -392, + 782, + 677, + -472, + 1130, + 1029, + -1262, + 1070, + 2171, + 575, + 675, + 600, + 2104, + 1077, + -182, + 2621, + -604, + -30, + 3302, + -1331, + 599, + 742, + 291, + 1329, + -551, + 1043, + 1729, + -1754, + 1220, + 1113, + -2174, + 1281, + 743, + -2027, + 851, + -205, + -1576, + 214, + -1629, + -605, + -394, + -1508, + -254, + -63, + -489, + -847, + -26, + -997, + -1065, + -120, + -376, + -1283, + -1393, + 83, + -212, + -1610, + 419, + -1120, + -590, + 395, + -1210, + -21, + -273, + -622, + 899, + -196, + -1059, + 1130, + 616, + -529, + -166, + 794, + 22, + -216, + 862, + 664, + -390, + 980, + 228, + 789, + 182, + 402, + 2149, + -1133, + 799, + 2637, + -799, + 176, + 1306, + 905, + -93, + 677, + 338, + 121, + 483, + 297, + 339, + 347, + 249, + 731, + 40, + 66, + 112, + -889, + -128, + 582, + -1191, + -67, + -1364, + -233, + 488, + -1734, + -634, + 1517, + -1657, + -1015, + 594, + -1422, + 1396, + -1357, + -1617, + 1254, + -1596, + -941, + 789, + -1860, + -77, + 245, + -327, + 569, + -723, + 104, + 905, + -543, + -918, + 1387, + -42, + -440, + 619, + 68, + 45, + 1364, + -880, + 19, + 1491, + -561, + 1174, + 1403, + -1411, + 1351, + 1222, + -612, + 864, + 877, + -658, + 382, + 864, + -552, + 1286, + 309, + -105, + 1083, + -170, + -289, + 1049, + -248, + -537, + 625, + -48, + 337, + -385, + 532, + -315, + -1398, + 588, + -628, + -1192, + 649, + -806, + -170, + 541, + -2267, + 1052, + 274, + -1970, + 833, + 253, + -1345, + -290, + -120, + -959, + -94, + -189, + -1397, + -136, + -155, + -654, + 207, + -706, + 617, + 415, + -1962, + 1169, + 670, + -1132, + 319, + 297, + -589, + 100, + 510, + -620, + 610, + -153, + -15, + 1327, + -99, + 229, + 281, + 169, + 1015, + -106, + 1197, + 577, + -698, + 577, + 931, + -964, + 1605, + 505, + -1713, + 2369, + 115, + -1585, + 1839, + 664, + -1411, + 867, + 620, + 329, + 491, + -1119, + 420, + 266, + -1708, + 499, + -69, + -1037, + 795, + -321, + -959, + 32, + 235, + -1748, + 295, + -249, + -230, + 485, + -1185, + -97, + 489, + -2036, + 711, + 405, + -2800, + 593, + 434, + -1038, + 536, + 347, + -570, + 705, + -806, + -290, + 818, + -999, + 53, + 1585, + -756, + -657, + 1180, + 115, + -364, + 217, + -226, + 1033, + 347, + -20, + 611, + 658, + 590, + -128, + -451, + 1676, + -660, + -21, + 805, + -880, + 1481, + 412, + -1534, + 1522, + 221, + -132, + 662, + -407, + 613, + 1132, + -551, + -187, + 1184, + -577, + -444, + 953, + -1034, + -472, + 461, + -865, + -99, + 637, + -572, + 300, + 450, + -591, + 137, + 404, + -972, + 306, + -524, + -1167, + 433, + 124, + -1326, + -368, + -305, + -917, + 452, + -626, + -695, + 656, + 258, + -1401, + 270, + 446, + -1045, + 636, + -357, + -1072, + 913, + 512, + -1732, + 489, + 952, + -747, + 58, + 673, + -453, + 1125, + -488, + 46, + 1723, + -1244, + 417, + 1803, + -1215, + 623, + 659, + -560, + 676, + -9, + 92, + 701, + 1100, + -623, + 142, + 283, + -512, + 547, + 576, + -525, + -155, + 1143, + -1286, + -329, + 1959, + -1302, + -459, + 1188, + -1199, + 1020, + -118, + -1303, + 956, + -905, + -647, + 595, + -356, + -1354, + -74, + 750, + -791, + -335, + 56, + -862, + -36, + 276, + -279, + 46, + -485, + -181, + 196, + -584, + -238, + 259, + -314, + -77, + 383, + 509, + -386, + -180, + 859, + -542, + 955, + 372, + -362, + 1458, + 113, + -106, + 1495, + -534, + 63, + 1295, + -505, + 846, + 983, + -1097, + 1764, + 320, + -185, + 1061, + -525, + 115, + 217, + -328, + 326, + 312, + 374, + 179, + -683, + 485, + -1286, + 147, + -583, + -979, + 888, + -504, + -1235, + 715, + -1050, + -1111, + 848, + -828, + -1043, + -115, + -327, + 22, + -451, + -1008, + 98, + -262, + -545, + -363, + -48, + -257, + -731, + 878, + 96, + -1186, + 426, + 359, + -1101, + 1074, + -267, + 521, + -375, + -166, + 1398, + -994, + 780, + 550, + 124, + -298, + 581, + 236, + 305, + -111, + 396, + 741, + -10, + 662, + 155, + 271, + 563, + 65, + -318, + 812, + -483, + 843, + 75, + -714, + 1152, + -26, + -190, + -97, + 533, + -111, + -564, + 724, + -24, + -820, + 835, + -473, + -632, + 154, + -104, + -932, + 919, + -606, + -619, + 496, + -310, + -271, + -360, + 120, + -630, + 126, + 65, + -931, + 548, + -207, + -455, + 410, + -282, + -931, + 944, + -354, + 69, + 412, + -661, + 1068, + -969, + -443, + 1894, + -1281, + -442, + 2003, + -1640, + 713, + 852, + -1344, + 1338, + -457, + 243, + 498, + -697, + -129, + 993, + -388, + -76, + 1039, + -768, + 492, + -104, + -58, + 951, + -854, + 181, + 1093, + -1111, + 491, + 544, + -1061, + 118, + 586, + -477, + -411, + 392, + 233, + 91, + -908, + 532, + 218, + -1176, + 670, + -74, + -674, + 696, + -801, + 194, + 592, + -1790, + 762, + -564, + -791, + 595, + -145, + -727, + 228, + 434, + -246, + -232, + -169, + 281, + -324, + 289, + -120, + -270, + -49, + 282, + 250, + -56, + -405, + 507, + 27, + -1060, + 1329, + -203, + -204, + 1677, + -767, + -313, + 1272, + -968, + 717, + 183, + -1652, + 2157, + -75, + -1906, + 2590, + -428, + -1614, + 2564, + -1511, + -240, + 1421, + -1911, + 1420, + 396, + -1397, + 1691, + -694, + -1500, + 1942, + -823, + -784, + 841, + -635, + 759, + -447, + 351, + 44, + -946, + 227, + 441, + -564, + 155, + -719, + 182, + 509, + -320, + -300, + 205, + -662, + 726, + 469, + -1240, + 191, + 664, + -269, + -152, + -18, + 214, + -149, + -257, + 347, + 76, + -79, + -384, + 874, + -387, + -269, + 892, + -783, + 537, + 46, + 27, + 251, + -332, + 133, + 377, + -522, + 232, + 626, + -362, + -499, + 1112, + -342, + -522, + 362, + -187, + 547, + -384, + -155, + 517, + -551, + 227, + 651, + -825, + -88, + 579, + -758, + -40, + 456, + -774, + 542, + -164, + -482, + 968, + -1000, + -394, + 1094, + -885, + 431, + 74, + -348, + 403, + -959, + 831, + -465, + -330, + 762, + -717, + -645, + 1342, + -499, + -416, + 944, + -417, + -438, + 737, + -368, + -42, + 740, + -1234, + 689, + 29, + -106, + 619, + -824, + -10, + 1047, + -824, + 146, + -59, + 210, + 163, + -43, + 522, + -352, + 213, + 460, + -1049, + 599, + 308, + -843, + 632, + 223, + -504, + 296, + 530, + -931, + 751, + -176, + -524, + 379, + 236, + -626, + 66, + 662, + -575, + 191, + -175, + -619, + 660, + -424, + -217, + 704, + -498, + 200, + 62, + -543, + 280, + 91, + -378, + 54, + 168, + -554, + 670, + -215, + -1097, + 1805, + -1015, + -617, + 1642, + -1560, + 727, + 61, + 7, + -48, + -659, + 1308, + -752, + -613, + 914, + 160, + -469, + 164, + -167, + 274, + 326, + -667, + 497, + 333, + -757, + 1252, + -481, + -1257, + 2019, + -949, + -719, + 1676, + -1078, + 250, + 323, + -1100, + 1550, + 145, + -1697, + 972, + 522, + -966, + 374, + -365, + 846, + -276, + -756, + 629, + -278, + 302, + -151, + -243, + -363, + 841, + -7, + -1092, + 476, + 45, + 201, + -378, + -456, + 1113, + -926, + 97, + 178, + -240, + 326, + -597, + 472, + -10, + -190, + 394, + -501, + -259, + 307, + 133, + 240, + -433, + -192, + 472, + -190, + 12, + 398, + -191, + -605, + 1295, + -576, + -154, + 474, + -661, + 866, + -968, + 172, + 887, + -736, + 36, + 259, + -201, + 265, + 460, + -859, + 622, + 102, + -690, + 776, + -80, + -745, + 919, + 140, + -750, + 224, + 134, + -236, + -196, + 456, + 409, + -1069, + 600, + 239, + -306, + -383, + 541, + -213, + -323, + -121, + 700, + -735, + 179, + 222, + -613, + 653, + -711, + -81, + 592, + -694, + 117, + 703, + -772, + -264, + 644, + -117, + -422, + 276, + 64, + -355, + -430, + 800, + -74, + -619, + 1207, + -1057, + 4, + 960, + -1219, + 977, + -78, + -1186, + 1536, + 267, + -1388, + 1144, + -90, + -1052, + 1889, + -1255, + -387, + 1815, + -1763, + 1037, + 421, + -1003, + 767, + -24, + -277, + -54, + 759, + -285, + -1015, + 1422, + -581, + -121, + 547, + -687, + 288, + 440, + -626, + -623, + 1261, + -248, + -1133, + 1204, + -714, + 382, + 219, + -851, + 240, + -161, + 672, + -261, + -855, + 1043, + -599, + 111, + -362, + 225, + 641, + -913, + -122, + 1075, + -1165, + 432, + 131, + -803, + 978, + 33, + -1291, + 992, + 224, + -1054, + 789, + -121, + -215, + 262, + -11, + 89, + -174, + 365, + -240, + 114, + 406, + -813, + 291, + 233, + 158, + -377, + 194, + 216, + -477, + 635, + -228, + -512, + 599, + 23, + -273, + 71, + 258, + 10, + -155, + -198, + 354, + 61, + -749, + 768, + -19, + -709, + 596, + 97, + -276, + 164, + 69, + -144, + -20, + 529, + -897, + 188, + 480, + -703, + 836, + -874, + 259, + 917, + -1044, + -7, + 566, + -97, + -439, + 256, + -466, + 998, + -360, + -1134, + 1619, + -762, + -752, + 1446, + -707, + -177, + 652, + -899, + 579, + 253, + -410, + 146, + -262, + 275, + 353, + -610, + 52, + 671, + -862, + 419, + -140, + 273, + 247, + -1062, + 1005, + -175, + -497, + 772, + -431, + -101, + 450, + -598, + 266, + 428, + -842, + 477, + -11, + -554, + 642, + 17, + -787, + 544, + 445, + -625, + -205, + 796, + -222, + -733, + 764, + -572, + 423, + 166, + -994, + 931, + -228, + -303, + 362, + -214, + 104, + 448, + -1091, + 722, + 570, + -1311, + 773, + 259, + -648, + 477, + 193, + -682, + 302, + 459, + -464, + -383, + 1120, + -561, + -564, + 1083, + -372, + -354, + 864, + -586, + -200, + 502, + -331, + 27, + 446, + -657, + 281, + 571, + -888, + 502, + 251, + -423, + 116, + 277, + -263, + 118, + -170, + 168, + 367, + -723, + 202, + 438, + -793, + 451, + -30, + -292, + 202, + 38, + -188, + -66, + 221, + -90, + -105, + 7, + 346, + -578, + 337, + 247, + -371, + -14, + 22, + 36, + 151, + -322, + -244, + 692, + -556, + -5, + 550, + -560, + 200, + 161, + -347, + 191, + 258, + -520, + 441, + -212, + -215, + 584, + -428, + -251, + 213, + 90, + -187, + 109, + 138, + -211, + -17, + 191, + 111, + -259, + 161, + -141, + 232, + -175, + 0, + 154, + -369, + 539, + -171, + -438, + 484, + 43, + -375, + -37, + 249, + 196, + -328, + -106, + 541, + -531, + 103, + 240, + -191, + 186, + -363, + 40, + 585, + -573, + 258, + 170, + -593, + 515, + -261, + -86, + 407, + -339, + 164, + -214, + -34, + 464, + -377, + -206, + 336, + -230, + 239, + -85, + -69, + 322, + -503, + 322, + 142, + -748, + 867, + -160, + -753, + 836, + -249, + -362, + 750, + -374, + -222, + 448, + -82, + -246, + 399, + 13, + -429, + 441, + -47, + -127, + -29, + 337, + -502, + 318, + 132, + -457, + 498, + -145, + -91, + 98, + 208, + -179, + 54, + 62, + -260, + 237, + 96, + -161, + 32, + -150, + 93, + 21, + -31, + 74, + 75, + -322, + 164, + 168, + -191, + 119, + -121, + -66, + -195, + 296, + -128, + -251, + 381, + -56, + -338, + 281, + -29, + -472, + 664, + -301, + -275, + 423, + -285, + -77, + 258, + -82, + -139, + 160, + -54, + -26, + 27, + 75, + -49, + -196, + 305, + -131, + -187, + 262, + -37, + -206, + 65, + 269, + -240, + -144, + 261, + 54, + -338, + 355, + 3, + -503, + 535, + -253, + -210, + 433, + -290, + -33, + 381, + -546, + 173, + 252, + -364, + 271, + -329, + 166, + 266, + -564, + 507, + -32, + -648, + 861, + -400, + -357, + 819, + -519, + -74, + 392, + -423, + 426, + -306, + -93, + 691, + -991, + 537, + 467, + -992, + 614, + 426, + -823, + 491, + 182, + -371, + 174, + 84, + -64, + 98, + -96, + 23, + 182, + -69, + -211, + 226, + 18, + -134, + 334, + -514, + 352, + 378, + -623, + 363, + 266, + -592, + 493, + -46, + -369, + 594, + -440, + -10, + 295, + -368, + 326, + -192, + -140, + 306, + -305, + 140, + 198, + -396, + 202, + 154, + -341, + 208, + -8, + -169, + -76, + 106, + 20, + -347, + 233, + 30, + -193, + 117, + -9, + -165, + 182, + -4, + -195, + 96, + 131, + -188, + -106, + 166, + -71, + -99, + 57, + 4, + -31, + -131, + 101, + 63, + -199, + 225, + -25, + -281, + 342, + -247, + -170, + 516, + -289, + -263, + 422, + -158, + -148, + 363, + -192, + -138, + 122, + 62, + -105, + 7, + 194, + -53, + -224, + 83, + 173, + -182, + 20, + 178, + -274, + 182, + 74, + -109, + -5, + 319, + -303, + -72, + 428, + -371, + 50, + 271, + -204, + 17, + 161, + -256, + 169, + 93, + -169, + 94, + -89, + 139, + 80, + -199, + 325, + -67, + -83, + 202, + -154, + 16, + 202, + -325, + 162, + 61, + -93, + 201, + -278, + 236, + 108, + -477, + 594, + -145, + -370, + 647, + -261, + -356, + 669, + -369, + -181, + 420, + -266, + -154, + 159, + -25, + 53, + -40, + -22, + 68, + -203, + 144, + -2, + -173, + 88, + -3, + -62, + 2, + 75, + 55, + -95, + -130, + 219, + -142, + -191, + 164, + -170, + 44, + 0, + -246, + 249, + -27, + -413, + 461, + 27, + -490, + 292, + 19, + -145, + 13, + 99, + 91, + -466, + 209, + 295, + -773, + 465, + 210, + -680, + 410, + 163, + -358, + 399, + -201, + 87, + 23, + -212, + 270, + -230, + 86, + 159, + -353, + 381, + -73, + -456, + 726, + -353, + -357, + 754, + -367, + -344, + 657, + -59, + -417, + 432, + 35, + -309, + 153, + 97, + -69, + 89, + -101, + 63, + 107, + -127, + 106, + 112, + -26, + -236, + 376, + 43, + -479, + 544, + -57, + -407, + 447, + -148, + -103, + 195, + -198, + 80, + 156, + -228, + 35, + 145, + -77, + -55, + 130, + -33, + -190, + 123, + 41, + -170, + 74, + 114, + -241, + 67, + 192, + -195, + -76, + 186, + -136, + -133, + 213, + -105, + -110, + 144, + -51, + -126, + 154, + -59, + -124, + 147, + -49, + -132, + 82, + 26, + -130, + 63, + 68, + -211, + 97, + 131, + -224, + 59, + 184, + -250, + 59, + 205, + -225, + -67, + 163, + -135, + -24, + 74, + -22, + -4, + -81, + 21, + 71, + -137, + 71, + 47, + -120, + 71, + 34, + -65, + 138, + -6, + -116, + 112, + -47, + -39, + 20, + -75, + 64, + -7, + 2, + 35, + 52, + -61, + -29, + 81, + -61, + -30, + 195, + -91, + -136, + 261, + -11, + -186, + 162, + -86, + -35, + 152, + -106, + -32, + 126, + -4, + 49, + 33, + -9, + -11, + 46, + 111, + -132, + -3, + 204, + -175, + -10, + 281, + -146, + -94, + 226, + -126, + -36, + 58, + -14, + 61, + -172, + 48, + 193, + -221, + 83, + 149, + -279, + 195, + 130, + -357, + 226, + 102, + -260, + 191, + 16, + -223, + 124, + 14, + -144, + 90, + -31, + -81, + -66, + 54, + 103, + -181, + 29, + 174, + -281, + 92, + 81, + -226, + 139, + -133, + -41, + 167, + -147, + 44, + 27, + -132, + 107, + -34, + -122, + 105, + -54, + 17, + 52, + -131, + 138, + 33, + -206, + 158, + 43, + -80, + 24, + 10, + -27, + 33, + 43, + -71, + 15, + 71, + -42, + 14, + 18, + 0, + -3, + -14, + -14, + 58, + 46, + -99, + 122, + 105, + -202, + 125, + 119, + -238, + 112, + 133, + -242, + 113, + 129, + -301, + 52, + 161, + -177, + 82, + 73, + -139, + 46, + 122, + -119, + 22, + 155, + -230, + 23, + 242, + -211, + -12, + 182, + -184, + -57, + 190, + -34, + -101, + 58, + -20, + 6, + 103, + -61, + -78, + 12, + 18, + 12, + 86, + -71, + -27, + 43, + -24, + 8, + 39, + -109, + 21, + -4, + -44, + 66, + 13, + -59, + 61, + -39, + 35, + 113, + -179, + 19, + 171, + -158, + 14, + 112, + -133, + 26, + 9, + -43, + -9, + 6, + 41, + -77, + 22, + 80, + -61, + -63, + 65, + -32, + -32, + 125, + -105, + -11, + 114, + -120, + 42, + 42, + -92, + 45, + -56, + -25, + 131, + -83, + -24, + 97, + -51, + -5, + 67, + -69, + 7, + 41, + -27, + 8, + 3, + -10, + 8, + -3, + -87, + -28, + 122, + -33, + -58, + 124, + -53, + -50, + 67, + -115, + -17, + 111, + -112, + -30, + 101, + -24, + -13, + 41, + 3, + 45, + -13, + -34, + 23, + 23, + -19, + 13, + -49, + -49, + 68, + -68, + -32, + 91, + -58, + -18, + 73, + -19, + -27, + 17, + -33, + -35, + 99, + -38, + -99, + 78, + -31, + -62, + 95, + -71, + -124, + 184, + -15, + -146, + 160, + -27, + -109, + 140, + -25, + -63, + 84, + -34, + -18, + 58, + -68, + -16, + 22, + -87, + 86, + 23, + -130, + 61, + 62, + -132, + 51, + 168, + -139, + 35, + 133, + -121, + 50, + 102, + -120, + 40, + 126, + -87, + -40, + 119, + -14, + -59, + 78, + 11, + -68, + 41, + 24, + -25, + 55, + -2, + 15, + 21, + -73, + 56, + 88, + -74, + -41, + 4, + -10, + -4, + 5, + 7, + -39, + -3, + -4, + -39, + 94, + 52, + -135, + 42, + 90, + -86, + 12, + 21, + -55, + -70, + -37, + 55, + -63, + -35, + 50, + -100, + 21, + 84, + -151, + 24, + 87, + -94, + 51, + 2, + -58, + 104, + -61, + -70, + 60, + -25, + -42, + -31, + 55, + 35, + -129, + 47, + 69, + -65, + 77, + 2, + -60, + 110, + -32, + -69, + 84, + -54, + -26, + 98, + -28, + -7, + 49, + -49, + -19, + 119, + -11, + -157, + 20, + 106, + 29, + -8, + -38, + -30, + 72, + 30, + -3, + 1, + -32, + -11, + -9, + 52, + 46, + -144, + -38, + 86, + -31, + -9, + -42, + -75, + 142, + 34, + -64, + 79, + -109, + -55, + 195, + -69, + -80, + 48, + -49, + 62, + 25, + -111, + -42, + 52, + 19, + -41, + 1, + -16, + -33, + 44, + 30, + -21, + 17, + -2, + -30, + 111, + 34, + -111, + 83, + 55, + -119, + 66, + 62, + -89, + 63, + -39, + -143, + 168, + 21, + -158, + 158, + 32, + -132, + 134, + -3, + -77, + 88, + -45, + -18, + 117, + -51, + -71, + 10, + 30, + 35, + -27, + -63, + 13, + 34, + 23, + -23, + 19, + -4, + -92, + 34, + 74, + -69, + -15, + 20, + -36, + 56, + -36, + -96, + 69, + -34, + -122, + 32, + 31, + -51, + -3, + -21, + 4, + 43, + -44, + 6, + 81, + -39, + -35, + 26, + -38, + -24, + 29, + -16, + -47, + -6, + 19, + -7, + -9, + 41, + 32, + 13, + -2, + -21, + 3, + 24, + 49, + -3, + -66, + 14, + 95, + -7, + -52, + 80, + 68, + -72, + -14, + 39, + 2, + 24, + -6, + -53, + 86, + 21, + -78, + 67, + 28, + -34, + 16, + -23, + -1, + 70, + -3, + -58, + 45, + 33, + -94, + -34, + 62, + 41, + -11, + -27, + 27, + 46, + 14, + -33, + -12, + 44, + -16, + -59, + 6, + 45, + -3, + -42, + 2, + 13, + 19, + -1, + -71, + 3, + 42, + -36, + 6, + 17, + 26, + 5, + -46, + 6, + -68, + -75, + 86, + -20, + -90, + 80, + 4, + -86, + 5, + 2, + -33, + -15, + -2, + -8, + -18, + 15, + -7, + -25, + 27, + -28, + -88, + 39, + -2, + -85, + 58, + 40, + -45, + 3, + 17, + 0, + 11, + -4, + -3, + 84, + 22, + -113, + 8, + 94, + 10, + 9, + 28, + 6, + -3, + 5, + -2, + 23, + 23, + -1, + -40, + 20, + 48, + -40, + -21, + 72, + 7, + -40, + -1, + 27, + 16, + 30, + 31, + -16, + 11, + 9, + -71, + -7, + 62, + 21, + -61, + -19, + 78, + -2, + -22, + 67, + -42, + -12, + 75, + -79, + 47, + 86, + -124, + -42, + 21, + 4, + 23, + -32, + -7, + 19, + 1, + -13, + -46, + 2, + 32, + -43, + -7, + 86, + -16, + -22, + 46, + -61, + -35, + 11, + -64, + -38, + 17, + -12, + -27, + 20, + 41, + 6, + -58, + -61, + 58, + -51, + -77, + 36, + -25, + 19, + 93, + -76, + 1, + 72, + -92, + 15, + 40, + -56, + 65, + 13, + -29, + 82, + -9, + -21, + 24, + -83, + -5, + 4, + -63, + 77, + 80, + -58, + -6, + -19, + -43, + 100, + 5, + -36, + 63, + 33, + -26, + -48, + 26, + -18, + -75, + 34, + 24, + -45, + -1, + 6, + -35, + -24, + -23, + -22, + 47, + -15, + -46, + 31, + -40, + -41, + 74, + -32, + -73, + 59, + -51, + -26, + 143, + -29, + -42, + 93, + -44, + -21, + 56, + -7, + 55, + 51, + -61, + 74, + 111, + -71, + 35, + 124, + -123, + -3, + 62, + -79, + 100, + 49, + -122, + 143, + 79, + -137, + 72, + 30, + -82, + 75, + -10, + -48, + 35, + -23, + -25, + 34, + 0, + -54, + -6, + 34, + -46, + -59, + -7, + -72, + -6, + 70, + -41, + -39, + 23, + -33, + 11, + 104, + -44, + -30, + 54, + -69, + -20, + 62, + -75, + 1, + 45, + -69, + 1, + 40, + -59, + -15, + 18, + -16, + 38, + -1, + -52, + 8, + 14, + -32, + 11, + -15, + -58, + 18, + -22, + -44, + 69, + 40, + -50, + -21, + 1, + -35, + -3, + -5, + -20, + 40, + 36, + -41, + -36, + -43, + -11, + 48, + -34, + -40, + 51, + -10, + -9, + 30, + 10, + 12, + 51, + 51, + -8, + -16, + 32, + -6, + 31, + 24, + -38, + 43, + 18, + -15, + 53, + -10, + -55, + 9, + 8, + -28, + 21, + 10, + -26, + 21, + 10, + -9, + 5, + -29, + -13, + 38, + -1, + -11, + 49, + 0, + -41, + 10, + 23, + -25, + -35, + -2, + -32, + -10, + 58, + -6, + -18, + 16, + -9, + 4, + 11, + 17, + 21, + 21, + 12, + -2, + 49, + -16, + -128, + 21, + 75, + -32, + 22, + 34, + -59, + 48, + 75, + -69, + -11, + -2, + -65, + 39, + 57, + -54, + -79, + -11, + -20, + -13, + 38, + 4, + -9, + -22, + -22, + 33, + -7, + -52, + 10, + -10, + -19, + 54, + 47, + -21, + -35, + -6, + -4, + 11, + 8, + -28, + 1, + 8, + -4, + 30, + 1, + -22, + 26, + -7, + -24, + 56, + 25, + -45, + 13, + 24, + -32, + 13, + 22, + -46, + -2, + 15, + -39, + 28, + 32, + -69, + 0, + 27, + -69, + 0, + 39, + -40, + 28, + 55, + -27, + -13, + 0, + -14, + 37, + 25, + -25, + 34, + -3, + -69, + 26, + 39, + -41, + -6, + 29, + -7, + 5, + 66, + 41, + -27, + -17, + 6, + -14, + -21, + 0, + 29, + -9, + -26, + 32, + -5, + -34, + 60, + 15, + -60, + 20, + 13, + 11, + 43, + -48, + -15, + 88, + -13, + -55, + 26, + -32, + -46, + 35, + 14, + -37, + -11, + 12, + -20, + 11, + 9, + -64, + -16, + 17, + 5, + 38, + 7, + -30, + -9, + -49, + -11, + 52, + -15, + -38, + -27, + -12, + 36, + 53, + 1, + -37, + -17, + -12, + 0, + 31, + 1, + 13, + 40, + -15, + 2, + 47, + -15, + -17, + 28, + -2, + -4, + 25, + -6, + -12, + 2, + -17, + -9, + 5, + -15, + 17, + 21, + -28, + 0, + 15, + -43, + -63, + -6, + -14, + -8, + 37, + -34, + -40, + 30, + -12, + -14, + 37, + -13, + -16, + 26, + -15, + -2, + 13, + -37, + -13, + 32, + 13, + -8, + -2, + -12, + -8, + 9, + 9, + -3, + 4, + 13, + 34, + -2, + -22, + 40, + 19, + 29, + 25, + -48, + -17, + 23, + 17, + 7, + 3, + 0, + 12, + 37, + -1, + -25, + 30, + 41, + -7, + 7, + 29, + -31, + -31, + -23, + -27, + 5, + 2, + -18, + -2, + 22, + 9, + -6, + 5, + -7, + -24, + 9, + 0, + -28, + 19, + 61, + -11, + -45, + 21, + -28, + -65, + 28, + 33, + -44, + -27, + -6, + -26, + -8, + 4, + 5, + 9, + -10, + -46, + -20, + 20, + -7, + -7, + -33, + -26, + 50, + 9, + -65, + -22, + -3, + -20, + 15, + 21, + 20, + 24, + -16, + -27, + -13, + 14, + 21, + -38, + -48, + 9, + 35, + 28, + 21, + 3, + -31, + -8, + 57, + 32, + -35, + -22, + 20, + 14, + 12, + 28, + 39, + 0, + -18, + 44, + -2, + -17, + 53, + 0, + -27, + 33, + 43, + 5, + -10, + 25, + 47, + -3, + -4, + 36, + 15, + -12, + -3, + 29, + 41, + 23, + 23, + -8, + -32, + 15, + 37, + 0, + 3, + 22, + 31, + 1, + -20, + 27, + 2, + -50, + 0, + 33, + 16, + -16, + -17, + 18, + -26, + -34, + 31, + -27, + -84, + -33, + 4, + -5, + -22, + -17, + -28, + -66, + -24, + 8, + -16, + -25, + -51, + -13, + 45, + -11, + -49, + -26, + -49, + -38, + 21, + 10, + -52, + -58, + -19, + -4, + 9, + -31, + -29, + 55, + 2, + -45, + 29, + 10, + -22, + 49, + 33, + -27, + -19, + -5, + 30, + 47, + 11, + -11, + -2, + 8, + 5, + 17, + 8, + 3, + 57, + 63, + 28, + 24, + 11, + 2, + 14, + 22, + 7, + 7, + 2, + 23, + 33, + -2, + -8, + 14, + 7, + 20, + 57, + 32, + -5, + 12, + 23, + 10, + 17, + 26, + -18, + -72, + -6, + 74, + 61, + 13, + -17, + -21, + -7, + 29, + 45, + 5, + -52, + -49, + 1, + 10, + 35, + 40, + -46, + -66, + 7, + 31, + -27, + -44, + -12, + -41, + -22, + 32, + -12, + -32, + -3, + -17, + -22, + -22, + -31, + -30, + -23, + -13, + 3, + 0, + -21, + -19, + -7, + -17, + -9, + 18, + -40, + -64, + 1, + 4, + -4, + 8, + -17, + -28, + -1, + 9, + -7, + -9, + 27, + 6, + -63, + -32, + 52, + 25, + -46, + -23, + -6, + -11, + 35, + 29, + -50, + -44, + 17, + -6, + -12, + 53, + 28, + -17, + -9, + 28, + 34, + -20, + -18, + 22, + 43, + 28, + -6, + 8, + 14, + 19, + 28, + 14, + 27, + 26, + 12, + 76, + 66, + -18, + -2, + 18, + -12, + -1, + -2, + -1, + 51, + 30, + -18, + 5, + 14, + -12, + 2, + 13, + -25, + -9, + 32, + 7, + -5, + 15, + -12, + -33, + -18, + -13, + 6, + 0, + -25, + -12, + 1, + -17, + 0, + 13, + -24, + -27, + 4, + 35, + 14, + -22, + 5, + 13, + -18, + -30, + -10, + -7, + -7, + 31, + 23, + -27, + -26, + 9, + 47, + 6, + -50, + -11, + 19, + 1, + 11, + 12, + -19, + -43, + -18, + 10, + -6, + -3, + 12, + 2, + -12, + -16, + 10, + 9, + -25, + -21, + -10, + -13, + 0, + 8, + -1, + -9, + 10, + 4, + -34, + 14, + 46, + 5, + 18, + 24, + -15, + -7, + 20, + -1, + -13, + 7, + 11, + 14, + 11, + -2, + 8, + 27, + 10, + -1, + 13, + -2, + -7, + 48, + 44, + -15, + -16, + -6, + 3, + 7, + -35, + -25, + 8, + -31, + -16, + 30, + 36, + 22, + -13, + -21, + -10, + 8, + 2, + -58, + -37, + 32, + 25, + -1, + -25, + -21, + 3, + 3, + -6, + -11, + -3, + 2, + 4, + 34, + 22, + -25, + -19, + 0, + -6, + -10, + -8, + -35, + -32, + 8, + -3, + -20, + -11, + -6, + 3, + 8, + -8, + 3, + 25, + 23, + -7, + -35, + -15, + 8, + -20, + -6, + 15, + -44, + -29, + 19, + -5, + -1, + 18, + 28, + 6, + -21, + 9, + 11, + -20, + -10, + 18, + 22, + 6, + -2, + 12, + 6, + 23, + 34, + -20, + -19, + 1, + -10, + 34, + 41, + 13, + 6, + 3, + 22, + 11, + -4, + 4, + -12, + -8, + 17, + 18, + 12, + -1, + 5, + 9, + -6, + -2, + 4, + 1, + 3, + 2, + -6, + -32, + -25, + 9, + 18, + 27, + -4, + -54, + -29, + 2, + -3, + -18, + -38, + -28, + -10, + 9, + 20, + 5, + -9, + -15, + -3, + 2, + -14, + -15, + -6, + 5, + 10, + 6, + 3, + -11, + -9, + -5, + -20, + -13, + 8, + 3, + -14, + 6, + 20, + -15, + -21, + 9, + 19, + 21, + 12, + -4, + -21, + -17, + 16, + 27, + -4, + -28, + -2, + 26, + 9, + -12, + -16, + -28, + -28, + -4, + 4, + -15, + -9, + 3, + -10, + -16, + 2, + 17, + -10, + -26, + 3, + 16, + 26, + 17, + -12, + -9, + 2, + -2, + -5, + -11, + 5, + 28, + 1, + -14, + 13, + 14, + 5, + 18, + 6, + -17, + -5, + 7, + 2, + -3, + 11, + 10, + -1, + 50, + 36, + -28, + 21, + 39, + -9, + -6, + 2, + 10, + 36, + 20, + -2, + -3, + -11, + -10, + -6, + -5, + -4, + -8, + 2, + 17, + 1, + -13, + 11, + -13, + -36, + 11, + 14, + -19, + -6, + 3, + 0, + 20, + -5, + -24, + 12, + 7, + -11, + 2, + -15, + -28, + -1, + 6, + -14, + -31, + -39, + -19, + 19, + 37, + 3, + -32, + -27, + -6, + 13, + 31, + 15, + -41, + -41, + 25, + 35, + -3, + -16, + -25, + -19, + -10, + -3, + 19, + 10, + -4, + 7, + -4, + -19, + -12, + -13, + -9, + 6, + 2, + -12, + -6, + 12, + 6, + -1, + -5, + -19, + -7, + 7, + 40, + 56, + -3, + -13, + 21, + 24, + 7, + -11, + -9, + -3, + 24, + 28, + -10, + 1, + 12, + 21, + 24, + -16, + -15, + 4, + -7, + -2, + 19, + 13, + -11, + -7, + -8, + 15, + 41, + 5, + -16, + -18, + -11, + 26, + 26, + -5, + -12, + -14, + -6, + 10, + 8, + -8, + -16, + -16, + -3, + 10, + 1, + -3, + -3, + -2, + -15, + -18, + 6, + -4, + -4, + 21, + 4, + -2, + 15, + 13, + 0, + -2, + 12, + 7, + -15, + -9, + 1, + -2, + 2, + -1, + -9, + -15, + -17, + -14, + -10, + 1, + -4, + -16, + -17, + -1, + 18, + 8, + 1, + 22, + 11, + -19, + -10, + 4, + -23, + -29, + 0, + -2, + -14, + -6, + 13, + 7, + -23, + -13, + 10, + 9, + 11, + 10, + 4, + -4, + -4, + 1, + 6, + 14, + 9, + 2, + 0, + 2, + 6, + 4, + -9, + -18, + -8, + 8, + 18, + 8, + 13, + 9, + -27, + -22, + -10, + -24, + -9, + 17, + 11, + 2, + 9, + 3, + -13, + -10, + -1, + -7, + -1, + 10, + -4, + 1, + 16, + 12, + -6, + -14, + -2, + -5, + -1, + 0, + -1, + 6, + -9, + -3, + 12, + 4, + 1, + -2, + 2, + 17, + 24, + 22, + 9, + 8, + 21, + 14, + -2, + -2, + 4, + -1, + -7, + -7, + -6, + -1, + -6, + 17, + 30, + -7, + -10, + -3, + -19, + -18, + 2, + 21, + 4, + -20, + -6, + -1, + -18, + -14, + -6, + -7, + -1, + 6, + 10, + 8, + -5, + 0, + 10, + -22, + -40, + -22, + 4, + 34, + 16, + -19, + -16, + -12, + -17, + -16, + -17, + -29, + -28, + -4, + 10, + 16, + 22, + 13, + 4, + -1, + -5, + 16, + 15, + -11, + -6, + 9, + 3, + -14, + -22, + -19, + -12, + 5, + -5, + -15, + 3, + 9, + 27, + 17, + -4, + 8, + -2, + 1, + 16, + 11, + 9, + 9, + 8, + -14, + -16, + 7, + -5, + -15, + -11, + -5, + 19, + 25, + 25, + 43, + 21, + -9, + -9, + -19, + -10, + 14, + -11, + -19, + 8, + 3, + 1, + 11, + -1, + -24, + -20, + -1, + 2, + 7, + 24, + 22, + 11, + 8, + 6, + -2, + -11, + -3, + -2, + -4, + 0, + -7, + 0, + 6, + -1, + -16, + -35, + -8, + 8, + -11, + -6, + 6, + 18, + 16, + 7, + 12, + 5, + -2, + -3, + -10, + -21, + -27, + -10, + -3, + -3, + 8, + 0, + -9, + -10, + -3, + 0, + -5, + 6, + 9, + 19, + 23, + 8, + -5, + -19, + -16, + -5, + -6, + -27, + -22, + 1, + 6, + 8, + 2, + -9, + -13, + -15, + -18, + -13, + 4, + 25, + 29, + 26, + -2, + -22, + 1, + 8, + 1, + -6, + -6, + -7, + -20, + 0, + 13, + -14, + -24, + -24, + -21, + 2, + 14, + 16, + 23, + 15, + 10, + 10, + 5, + 0, + -26, + -32, + 3, + 19, + 5, + -8, + -7, + -8, + -3, + 17, + 27, + -7, + -28, + 10, + 32, + 10, + 1, + 10, + 3, + -4, + 22, + 24, + -31, + -40, + 0, + 6, + 5, + 17, + 17, + 1, + 10, + 30, + 8, + -12, + -6, + 9, + 6, + -12, + -5, + 1, + -4, + 6, + 11, + 0, + -9, + -4, + -3, + -4, + -3, + 2, + 0, + -2, + -9, + -27, + -23, + 2, + 13, + -6, + -9, + -3, + -12, + -2, + 10, + 6, + -7, + -19, + -31, + -13, + 16, + 11, + -3, + -13, + -15, + 0, + 7, + -3, + -7, + -1, + -4, + 7, + 15, + 0, + -12, + -8, + -1, + -7, + -12, + -21, + -17, + 5, + 30, + 25, + -6, + -6, + 0, + -12, + -8, + 2, + 13, + 11, + 1, + 5, + 4, + 4, + 10, + -1, + -20, + -12, + -4, + 3, + 15, + 11, + -7, + -24, + -4, + 8, + -2, + -14, + -25, + -17, + 7, + 21, + 14, + 1, + 0, + 12, + 17, + 13, + 6, + 1, + 6, + 14, + 11, + -10, + -21, + -12, + -4, + 3, + -2, + -21, + -24, + -2, + 12, + 14, + 17, + 4, + -2, + 11, + 11, + 11, + 1, + -34, + -32, + -5, + 10, + 7, + -11, + -12, + 6, + 7, + -4, + -10, + -15, + -5, + 17, + 21, + 0, + -15, + -15, + -1, + 5, + -18, + -18, + -10, + -9, + 24, + 27, + -9, + -14, + 0, + 9, + 25, + 22, + 1, + -7, + -2, + 16, + 13, + -14, + -10, + 7, + 0, + 2, + 15, + 2, + -9, + 5, + 10, + -5, + -3, + 10, + 3, + 0, + 15, + 15, + -1, + -3, + 8, + 6, + -7, + -7, + 2, + 0, + -4, + 5, + -8, + -37, + -28, + -1, + 8, + 6, + 10, + -1, + -12, + 12, + 28, + 8, + -17, + -16, + -15, + -17, + 1, + 6, + -4, + -8, + -4, + -15, + -15, + 6, + -9, + -15, + 10, + 9, + -13, + -8, + 5, + -2, + -10, + 5, + 12, + -27, + -33, + 9, + 8, + -16, + -3, + 16, + -3, + -7, + 22, + 22, + 10, + 5, + -11, + -16, + -4, + 9, + 12, + 6, + -3, + 2, + 2, + -1, + 4, + -7, + -8, + 1, + 8, + 19, +}; diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/yes_1000ms_sample_data.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/yes_1000ms_sample_data.h new file mode 100644 index 00000000..10ae971f --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/yes_1000ms_sample_data.h @@ -0,0 +1,29 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// This data was created from the PCM data in a WAV file held in v2 of the +// Speech Commands test dataset, at the path: +// speech_commands_test_set_v0.02/yes/f2e59fea_nohash_1.wav +// This should contain all 16,000 samples from the one-second file. + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_YES_1000MS_SAMPLE_DATA_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_YES_1000MS_SAMPLE_DATA_H_ + +#include + +extern const int g_yes_1000ms_sample_data_size; +extern const int16_t g_yes_1000ms_sample_data[]; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_YES_1000MS_SAMPLE_DATA_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/yes_30ms_sample_data.cc b/components/tflite/tensorflow/lite/micro/examples/micro_speech/yes_30ms_sample_data.cc new file mode 100644 index 00000000..048ecb8f --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/yes_30ms_sample_data.cc @@ -0,0 +1,502 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// See the header for documentation on the meaning of this data. + +#include "tensorflow/lite/micro/examples/micro_speech/yes_30ms_sample_data.h" + +const int g_yes_30ms_sample_data_size = 480; +const int16_t g_yes_30ms_sample_data[480] = { + -876, + -470, + 510, + 803, + 170, + -787, + -1568, + -1893, + -1598, + -1027, + -992, + -1803, + -2610, + -2484, + -1905, + -2113, + -3113, + -3399, + -2267, + -1261, + -2007, + -3637, + -3909, + -2340, + -893, + -1158, + -2272, + -2486, + -1639, + -915, + -777, + -596, + -91, + 196, + 85, + 210, + 875, + 1373, + 1247, + 1219, + 1958, + 2718, + 2328, + 1196, + 1008, + 2350, + 3677, + 3269, + 1503, + 366, + 922, + 2264, + 2810, + 1996, + 608, + -168, + 75, + 680, + 811, + 395, + -56, + -318, + -607, + -966, + -1108, + -925, + -613, + -368, + -369, + -919, + -1926, + -2460, + -1685, + -300, + 155, + -611, + -1524, + -2204, + -3227, + -3859, + -2037, + 1622, + 2382, + -2583, + -8448, + -7544, + -84, + 4814, + 915, + -6423, + -7558, + -1746, + 2515, + -59, + -4587, + -3858, + 1260, + 3625, + 187, + -4148, + -3500, + 1542, + 5467, + 4780, + 1256, + -1127, + -403, + 2481, + 5332, + 6346, + 5014, + 2536, + 1216, + 2467, + 5039, + 6238, + 5070, + 3381, + 3269, + 4173, + 3905, + 2248, + 1586, + 3299, + 5240, + 4362, + 1004, + -1382, + -489, + 2113, + 3168, + 1620, + -742, + -1824, + -1435, + -897, + -1058, + -1500, + -1545, + -1398, + -1965, + -3266, + -4136, + -3756, + -2609, + -1804, + -1986, + -3087, + -4599, + -5296, + -4051, + -1731, + -781, + -2228, + -4092, + -3977, + -2325, + -1353, + -1568, + -1490, + -428, + 178, + -672, + -1650, + -1058, + 749, + 2039, + 2079, + 1540, + 897, + 310, + 572, + 2266, + 4265, + 4265, + 1869, + -231, + 559, + 3332, + 4752, + 3229, + 768, + 101, + 1364, + 2463, + 1984, + 819, + 411, + 723, + 675, + -162, + -923, + -743, + -32, + 185, + -516, + -1653, + -2359, + -2103, + -986, + 42, + -205, + -1702, + -2870, + -2337, + -809, + -221, + -982, + -1544, + -946, + -598, + -2117, + -4291, + -4100, + -857, + 1948, + 338, + -4799, + -7972, + -5403, + 173, + 2371, + -1063, + -5533, + -5578, + -1777, + 605, + -985, + -3249, + -2213, + 1184, + 2691, + 560, + -2356, + -2288, + 1233, + 5244, + 6441, + 4004, + 370, + -663, + 2555, + 7404, + 9282, + 6573, + 2612, + 1836, + 4662, + 7467, + 7393, + 5421, + 4262, + 4741, + 5362, + 4705, + 3163, + 2397, + 3337, + 4887, + 4810, + 2254, + -749, + -1316, + 772, + 2706, + 2016, + -573, + -2552, + -2746, + -2012, + -1647, + -1978, + -2579, + -3105, + -3473, + -3911, + -4484, + -4891, + -4795, + -4163, + -3543, + -3538, + -4275, + -5356, + -5743, + -4637, + -2614, + -1301, + -1825, + -3341, + -4011, + -2937, + -751, + 1007, + 1245, + 235, + -639, + -61, + 1626, + 2864, + 2967, + 2734, + 3013, + 3329, + 2914, + 2312, + 2666, + 3839, + 4308, + 3162, + 1453, + 768, + 1255, + 1887, + 2006, + 1715, + 1031, + -297, + -1660, + -1690, + -277, + 813, + -30, + -2137, + -3370, + -2854, + -1553, + -593, + -413, + -1146, + -2567, + -3440, + -2369, + -205, + 379, + -1258, + -2315, + -812, + 262, + -3205, + -8576, + -7894, + 738, + 7492, + 1951, + -11595, + -17098, + -6934, + 7139, + 8065, + -4575, + -14199, + -8946, + 3606, + 7504, + -547, + -8242, + -5113, + 4406, + 8113, + 2134, + -5040, + -4089, + 4157, + 10934, + 10158, + 4167, + -565, + -192, + 4428, + 9765, + 12201, + 9861, + 4512, + 1225, + 3451, + 8483, + 10133, + 6497, + 2574, + 3333, + 6806, + 6986, + 2487, + -1214, + 623, + 5416, + 6647, + 2204, + -3289, + -4556, + -1565, + 1544, + 1525, + -1236, + -4293, + -5695, + -5174, + -3995, + -3403, + -3449, + -3750, + -4505, + -6014, + -7296, + -6523, + -3849, + -2096, + -3288, + -5722, + -6004, + -3581, + -1497, + -1960, + -3330, + -2800, + -434, + 964, + -111, + -1739, + -1136, + 1736, + 4151, + 3736, + 1274, + -451, + 469, + 3386, + 5833, + 5898, + 3646, + 1085, + 272, + 1743, + 4061, + 5108, + 3837, + 1490, + 246, + 967, + 1866, + 859, + -1069, + -974, + 1542, + 2835, + 47, + -4285, + -5068, + -1567, + 1781, + 1223, + -1997, + -4227, + -3747, + -1720, + 41, + 245, + -1228, + -2972, + -2673, + 22, + 1980, + -930, + -7721, + -11271, + -5725, + 4974, + 8484, + -2007, + -16979, + -19255, + -4670, + 11057, + 9690, + -6417, + -17537, + -10841, + 4262, + 9292, +}; diff --git a/components/tflite/tensorflow/lite/micro/examples/micro_speech/yes_30ms_sample_data.h b/components/tflite/tensorflow/lite/micro/examples/micro_speech/yes_30ms_sample_data.h new file mode 100644 index 00000000..caa555c0 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/micro_speech/yes_30ms_sample_data.h @@ -0,0 +1,32 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// This data was created from the PCM data in a WAV file held in v2 of the +// Speech Commands test dataset, at the path: +// speech_commands_test_set_v0.02/yes/f2e59fea_nohash_1.wav +// The data was extracted starting at an offset of 8,000, which corresponds to +// the 26th spectrogram slice. It's designed to be used to test the +// preprocessing pipeline, to ensure that the expected spectrogram slice is +// produced given this input. + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_YES_30MS_SAMPLE_DATA_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_YES_30MS_SAMPLE_DATA_H_ + +#include + +extern const int g_yes_30ms_sample_data_size; +extern const int16_t g_yes_30ms_sample_data[]; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_YES_30MS_SAMPLE_DATA_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/network_tester/README.md b/components/tflite/tensorflow/lite/micro/examples/network_tester/README.md new file mode 100644 index 00000000..7729f35d --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/network_tester/README.md @@ -0,0 +1,64 @@ +The aim of this application is to provide a quick way to test different +networks. + +It contains one testcase and a default network model (network_model.h), default +input data (input_data.h) and default expected output data +(expected_output_data.h). The header files were created using the `xxd` command. + +The default model is a single int8 DepthwiseConv2D operator, with an input shape +of {1, 8, 8, 16}, {1, 2, 2, 16} and {16} and an output shape of {1, 4, 4, 16}. + +When building the FVP target for Ethos-U (CO_PROCESSOR=ethos_u) the person +detect int8 model is used instead. The downloaded model is optimized for Ethos-U +with Ethos-U Vela. For more info see the following readmes: +tensorflow/lite/micro/kernels/ethos_u/README.md +tensorflow/lite/micro/cortex_m_corstone_300/README.md +tensorflow/lite/micro/examples/person_detection/README.md The following Vela +configuration has been used, which is compatible with the FVP build target +(TARGET=cortex_m_corstone_300). + +``` +vela --accelerator-config=ethos-u55-256 +``` + +In order to use another model, input data, or expected output data, simply +specify the path to the new header files when running make as seen below. + +The variables in the specified header files (array and array length) need to +have the same name and type as the ones in the default header files. The include +guards also needs to be the same. When swapping out the network model, it is +likely that the memory allocated by the interpreter needs to be increased to fit +the new model. This is done by using the `ARENA_SIZE` option when running +`make`. + +``` +make -f tensorflow/lite/micro/tools/make/Makefile network_tester_test \ + NETWORK_MODEL=path/to/network_model.h \ + INPUT_DATA=path/to/input_data.h \ + OUTPUT_DATA=path/to/expected_output_data.h \ + ARENA_SIZE= \ + NUM_BYTES_TO_PRINT= \ + COMPARE_OUTPUT_DATA=no +``` + +`NETWORK_MODEL`: The path to the network model header. \ +`INPUT_DATA`: The path to the input data. \ +`OUTPUT_DATA`: The path to the expected output data. \ +`ARENA_SIZE`: The size of the memory to be allocated (in bytes) by the +interpreter. \ +`NUM_BYTES_TO_PRINT`: The number of bytes of the output data to print. \ +If set to 0, all bytes of the output are printed. \ +`COMPARE_OUTPUT_DATA`: If set to "no" the output data is not compared to the +expected output data. This could be useful e.g. if the execution time needs to +be minimized, or there is no expected output data. If omitted, the output data +is compared to the expected output. `NUM_INFERENCES`: Define how many inferences +that are made. Defaults to 1. \ + +The output is printed in JSON format using printf: `num_of_outputs: 1 +output_begin [ { "dims": [4,1,2,2,1], "data_address": "0x000000", +"data":"0x06,0x08,0x0e,0x10" }] output_end` + +If there are multiple output tensors, the output will look like this: +`num_of_outputs: 2 output_begin [ { "dims": [4,1,2,2,1], "data_address": +"0x000000", "data":"0x06,0x08,0x0e,0x10" }, { "dims": [4,1,2,2,1], +"data_address": "0x111111", "data":"0x06,0x08,0x0e,0x10" }] output_end` diff --git a/components/tflite/tensorflow/lite/micro/examples/network_tester/expected_output_data.h b/components/tflite/tensorflow/lite/micro/examples/network_tester/expected_output_data.h new file mode 100644 index 00000000..7e913945 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/network_tester/expected_output_data.h @@ -0,0 +1,48 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_NETWORK_TESTER_EXPECTED_OUTPUT_DATA_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_NETWORK_TESTER_EXPECTED_OUTPUT_DATA_H_ + +#ifdef ETHOS_U +static unsigned char expected_output_data[] = { 143, 113 }; +#else +static unsigned char expected_output_data[] = { + 0x07, 0xf3, 0x16, 0xf3, 0x3a, 0x1f, 0xb1, 0x45, 0xce, 0x12, 0xc2, 0xbb, + 0xf5, 0x47, 0x45, 0x91, 0x13, 0x21, 0xc7, 0x07, 0xa2, 0x2c, 0xf2, 0xf7, + 0xd1, 0xe1, 0x08, 0xf5, 0x0a, 0x58, 0x40, 0xb0, 0xd9, 0xf1, 0x37, 0x1e, + 0xf1, 0x0d, 0xea, 0x05, 0xf9, 0xee, 0xfa, 0xca, 0x37, 0xb9, 0xc4, 0xd8, + 0x15, 0xe3, 0xd7, 0xd3, 0x36, 0x14, 0xb7, 0xed, 0x43, 0xfa, 0x29, 0xbe, + 0xff, 0xdb, 0x38, 0xc7, 0x00, 0xf1, 0x06, 0xbe, 0x31, 0x5b, 0xe9, 0x02, + 0xf0, 0x07, 0x13, 0x25, 0xe1, 0xf0, 0x0e, 0x12, 0x17, 0xd2, 0x51, 0x48, + 0x2a, 0x24, 0xf2, 0x0a, 0x3d, 0x05, 0x0b, 0x67, 0xc3, 0xea, 0x0a, 0xbf, + 0x22, 0x40, 0x20, 0x18, 0x54, 0xd3, 0x31, 0xef, 0xe7, 0x04, 0x3c, 0xf6, + 0xcf, 0xe2, 0x79, 0xed, 0xec, 0xff, 0xfa, 0xcf, 0xc2, 0x42, 0x1f, 0x0d, + 0xf8, 0xc2, 0x36, 0x1d, 0x09, 0x01, 0xd2, 0x09, 0xda, 0xdf, 0xe8, 0x1f, + 0x06, 0xdf, 0xf7, 0x3c, 0x4d, 0xe5, 0xb4, 0xc1, 0xfa, 0x03, 0x22, 0xbc, + 0x08, 0xea, 0x72, 0x3a, 0xc8, 0x0b, 0xe6, 0x1c, 0x00, 0xef, 0xf1, 0x34, + 0x01, 0xbe, 0xf7, 0x92, 0xe6, 0xc1, 0xe3, 0x25, 0xe5, 0x4c, 0xf1, 0xbb, + 0x6f, 0x07, 0x63, 0x80, 0x2a, 0xae, 0x46, 0xf1, 0x3c, 0x01, 0xe8, 0xda, + 0xed, 0x15, 0xfc, 0x56, 0x18, 0x16, 0x16, 0xc1, 0xf5, 0xef, 0x64, 0x03, + 0xa5, 0x0c, 0x15, 0x25, 0xe0, 0x51, 0x23, 0xec, 0x31, 0xfe, 0xe9, 0xd9, + 0x0c, 0x09, 0x42, 0xd8, 0xbc, 0x15, 0xe1, 0x21, 0xe4, 0x09, 0x4f, 0xb5, + 0xd6, 0x0c, 0x04, 0x20, 0xdf, 0x99, 0x2e, 0xe8, 0x06, 0xad, 0xf5, 0x04, + 0xf7, 0x1b, 0x5b, 0x63, 0xaa, 0xf3, 0xf0, 0xfc, 0x05, 0x35, 0xf1, 0x1d, + 0x40, 0x2d, 0xf6, 0xfa, 0xdd, 0x07, 0xfe, 0x32, 0x6d, 0x1b, 0x01, 0x31, + 0x39, 0xcb, 0x22, 0xf8 +}; +#endif + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_NETWORK_TESTER_EXPECTED_OUTPUT_DATA_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/network_tester/input_data.h b/components/tflite/tensorflow/lite/micro/examples/network_tester/input_data.h new file mode 100644 index 00000000..9ae193b8 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/network_tester/input_data.h @@ -0,0 +1,109 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_NETWORK_TESTER_INPUT_DATA_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_NETWORK_TESTER_INPUT_DATA_H_ + +static const int input_data_len = 1024; +static const unsigned char input_data[] = { + 0x2c, 0x8a, 0xff, 0x0c, 0xaf, 0x2a, 0x44, 0x17, 0xf5, 0x26, 0x96, 0x37, + 0x40, 0x4c, 0xa1, 0x58, 0xc3, 0x33, 0xce, 0x1a, 0x7b, 0xd2, 0x22, 0x5b, + 0x43, 0xf6, 0xfd, 0x0b, 0xe7, 0xfd, 0x65, 0x58, 0x89, 0x24, 0xf4, 0xec, + 0x53, 0x5e, 0x21, 0x1f, 0x95, 0xd1, 0xd9, 0x25, 0x72, 0x56, 0xe6, 0xe2, + 0xa4, 0x37, 0x85, 0xf0, 0xd7, 0xba, 0xab, 0xcc, 0xc6, 0xbc, 0xcb, 0x64, + 0x58, 0x3d, 0x04, 0x8e, 0xd8, 0x1a, 0x32, 0x76, 0x0c, 0x4d, 0x4c, 0xc5, + 0xba, 0xb9, 0xa9, 0xe2, 0x41, 0xc2, 0xc8, 0xfa, 0x66, 0xfd, 0x2e, 0x4a, + 0xa7, 0xca, 0x6a, 0x4f, 0xd7, 0x28, 0xe5, 0x07, 0x2e, 0x48, 0x5f, 0xfa, + 0xd8, 0xde, 0xeb, 0x11, 0xd1, 0x0b, 0x0d, 0xe4, 0x25, 0x66, 0x73, 0x6c, + 0x99, 0xc2, 0x89, 0x56, 0xcd, 0xeb, 0xaf, 0x92, 0xc8, 0x18, 0xdf, 0xd6, + 0x89, 0x9b, 0xce, 0x96, 0x14, 0x17, 0x6e, 0x25, 0xf3, 0x88, 0xad, 0x85, + 0x50, 0x93, 0xc5, 0xde, 0x73, 0x12, 0xa6, 0x55, 0x45, 0x9e, 0x88, 0x75, + 0x7e, 0xc7, 0xb5, 0x47, 0xcf, 0x87, 0x6e, 0xa3, 0x2f, 0x9d, 0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e, 0x4f, 0xf6, 0xf2, 0xe0, 0x1f, 0x7e, 0xf2, + 0x84, 0xbd, 0x2e, 0x58, 0x43, 0x1f, 0x03, 0x7a, 0x6d, 0x92, 0x91, 0x33, + 0x0b, 0xe8, 0x3f, 0x9d, 0x7c, 0x53, 0xa4, 0xcc, 0xd6, 0x2a, 0xdb, 0x44, + 0x4d, 0x8d, 0xd5, 0x50, 0xf9, 0x8b, 0xed, 0xe9, 0xed, 0xe6, 0x01, 0xe5, + 0xcb, 0x13, 0x69, 0x2c, 0x38, 0x7a, 0x0f, 0x61, 0x90, 0x26, 0x72, 0xbf, + 0x18, 0xcc, 0x4e, 0x14, 0x1d, 0x93, 0xaf, 0xd0, 0x15, 0xe8, 0x39, 0x61, + 0xee, 0x04, 0xa5, 0x77, 0x99, 0x40, 0xc9, 0x31, 0x50, 0x25, 0x25, 0x16, + 0x3c, 0xc3, 0x2a, 0x39, 0xf9, 0x87, 0x60, 0x28, 0xf6, 0x4b, 0xd6, 0x00, + 0xf5, 0xb4, 0x00, 0x08, 0x3d, 0x65, 0x41, 0x74, 0xd3, 0xb6, 0x84, 0xbb, + 0x21, 0x0a, 0x5c, 0x24, 0xe8, 0xa7, 0x96, 0xe5, 0x20, 0x43, 0x01, 0xec, + 0x64, 0xbc, 0xea, 0x1e, 0x7b, 0x15, 0xbc, 0x1b, 0x7b, 0x6a, 0x10, 0xf9, + 0xf9, 0x58, 0x69, 0x84, 0xc6, 0x15, 0xda, 0xf8, 0x55, 0x81, 0xb4, 0xcd, + 0x9f, 0x29, 0xd0, 0x37 +}; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_NETWORK_TESTER_INPUT_DATA_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/network_tester/network_model.h b/components/tflite/tensorflow/lite/micro/examples/network_tester/network_model.h new file mode 100644 index 00000000..d6315bd8 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/network_tester/network_model.h @@ -0,0 +1,167 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_NETWORK_TESTER_NETWORK_MODEL_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_NETWORK_TESTER_NETWORK_MODEL_H_ + +const unsigned char network_model[] = { + 0x1c, 0x00, 0x00, 0x00, 0x54, 0x46, 0x4c, 0x33, 0x00, 0x00, 0x12, 0x00, + 0x1c, 0x00, 0x18, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, + 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x48, 0x00, 0x00, 0x00, 0x2c, 0x01, 0x00, 0x00, 0x3c, 0x01, 0x00, 0x00, + 0x34, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x13, 0x00, 0x00, 0x00, 0x6d, 0x69, 0x6e, 0x5f, 0x72, 0x75, 0x6e, 0x74, + 0x69, 0x6d, 0x65, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x00, + 0x06, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00, + 0x84, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x92, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x31, 0x2e, 0x35, 0x2e, 0x30, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0xff, 0xff, 0xff, + 0xb2, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x0d, 0x52, 0x1b, 0x0f, 0xec, 0x2f, 0xee, 0x7f, 0x7f, 0xc4, 0x68, 0x08, + 0x19, 0x7f, 0x81, 0x81, 0x81, 0x7f, 0x49, 0x7f, 0x7c, 0x5f, 0xf5, 0x5b, + 0x97, 0x48, 0x81, 0x7f, 0x08, 0xe7, 0xba, 0x54, 0xf4, 0x1a, 0x81, 0x28, + 0x1d, 0x25, 0x7f, 0x3b, 0xda, 0xe0, 0x46, 0x82, 0x3e, 0x33, 0xaa, 0x8e, + 0xcf, 0xcc, 0x13, 0xeb, 0x7f, 0x81, 0xad, 0x92, 0x2a, 0x81, 0xf4, 0xb7, + 0x81, 0x8c, 0x2e, 0x91, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x04, 0x00, 0x04, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x4d, 0x4c, 0x49, 0x52, + 0x20, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x65, 0x64, 0x2e, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, + 0x18, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x78, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x04, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x24, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xbc, 0x03, 0x00, 0x00, + 0x78, 0x02, 0x00, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x62, 0xfc, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x70, 0x00, 0x00, 0x00, + 0x54, 0xfc, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xb6, 0xdb, 0x56, 0x3c, 0x01, 0x00, 0x00, 0x00, + 0x36, 0x14, 0xda, 0x3f, 0x01, 0x00, 0x00, 0x00, 0x7d, 0xf5, 0xd1, 0xbf, + 0x2a, 0x00, 0x00, 0x00, 0x73, 0x65, 0x70, 0x61, 0x72, 0x61, 0x62, 0x6c, + 0x65, 0x30, 0x2f, 0x64, 0x65, 0x70, 0x74, 0x68, 0x77, 0x69, 0x73, 0x65, + 0x5f, 0x63, 0x6f, 0x6e, 0x76, 0x32, 0x64, 0x2f, 0x64, 0x65, 0x70, 0x74, + 0x68, 0x77, 0x69, 0x73, 0x65, 0x5f, 0x69, 0x6e, 0x74, 0x38, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0xfa, 0xfc, 0xff, 0xff, + 0x28, 0x00, 0x00, 0x00, 0x8c, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x09, 0xac, 0x01, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, + 0x18, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x00, 0x00, + 0x10, 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x19, 0x95, 0xf7, 0x3b, + 0x6f, 0xa4, 0xab, 0x3b, 0xd3, 0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2e, 0xbf, 0xe9, 0x7c, 0x47, 0xbf, 0x29, 0xa1, 0x5b, 0xbf, + 0xca, 0x63, 0x53, 0xbf, 0x26, 0x00, 0x00, 0x00, 0x73, 0x65, 0x70, 0x61, + 0x72, 0x61, 0x62, 0x6c, 0x65, 0x30, 0x2f, 0x64, 0x65, 0x70, 0x74, 0x68, + 0x77, 0x69, 0x73, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x76, 0x32, 0x64, 0x2f, + 0x64, 0x65, 0x70, 0x74, 0x68, 0x77, 0x69, 0x73, 0x65, 0x32, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0xce, 0xfe, 0xff, 0xff, + 0x20, 0x00, 0x00, 0x00, 0xf4, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x14, 0x01, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x8c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0xba, 0x5e, 0x78, 0x38, 0x38, 0x30, 0x2c, 0x38, + 0x0e, 0x1c, 0x79, 0x38, 0x9b, 0x8b, 0x3f, 0x38, 0x68, 0xd1, 0x7c, 0x38, + 0xbd, 0x02, 0x4e, 0x38, 0x69, 0xb7, 0x65, 0x38, 0x74, 0xcf, 0x4a, 0x38, + 0x97, 0x06, 0x70, 0x38, 0xb9, 0x6d, 0xff, 0x37, 0x5d, 0xa0, 0x38, 0x38, + 0x71, 0x31, 0x66, 0x38, 0xd3, 0x8a, 0x30, 0x38, 0xe7, 0x51, 0x5c, 0x38, + 0x27, 0x10, 0x5e, 0x38, 0x68, 0xbb, 0x55, 0x38, 0x26, 0x00, 0x00, 0x00, + 0x73, 0x65, 0x70, 0x61, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x30, 0x2f, 0x64, + 0x65, 0x70, 0x74, 0x68, 0x77, 0x69, 0x73, 0x65, 0x5f, 0x63, 0x6f, 0x6e, + 0x76, 0x32, 0x64, 0x2f, 0x64, 0x65, 0x70, 0x74, 0x68, 0x77, 0x69, 0x73, + 0x65, 0x31, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x14, 0x00, 0x13, 0x00, 0x0c, 0x00, + 0x08, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x58, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, + 0x68, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0c, 0x00, + 0x08, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x1c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3e, 0x68, 0x00, 0x3c, + 0x01, 0x00, 0x00, 0x00, 0xe9, 0xe6, 0x7f, 0x3f, 0x01, 0x00, 0x00, 0x00, + 0x70, 0xb8, 0x7f, 0xbf, 0x16, 0x00, 0x00, 0x00, 0x64, 0x61, 0x74, 0x61, + 0x30, 0x2f, 0x50, 0x6c, 0x61, 0x63, 0x65, 0x68, 0x6f, 0x6c, 0x64, 0x65, + 0x72, 0x5f, 0x69, 0x6e, 0x74, 0x38, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xd8, 0xff, 0xff, 0xff, + 0x06, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, + 0x0c, 0x00, 0x0c, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, + 0x0c, 0x00, 0x10, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x04 +}; +const unsigned int network_model_len = 1720; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_NETWORK_TESTER_NETWORK_MODEL_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/network_tester/network_tester_test.cc b/components/tflite/tensorflow/lite/micro/examples/network_tester/network_tester_test.cc new file mode 100644 index 00000000..4ba799ec --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/network_tester/network_tester_test.cc @@ -0,0 +1,155 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/examples/network_tester/expected_output_data.h" +#include "tensorflow/lite/micro/examples/network_tester/input_data.h" +#include "tensorflow/lite/micro/examples/network_tester/network_model.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/micro_interpreter.h" +#include "tensorflow/lite/micro/micro_utils.h" +#include "tensorflow/lite/micro/testing/micro_test.h" +#include "tensorflow/lite/schema/schema_generated.h" + +#ifdef ETHOS_U +#include "tensorflow/lite/micro/examples/person_detection/person_detect_model_data.h" +#include "tensorflow/lite/micro/examples/person_detection/person_image_data.h" +#endif + +#ifndef TENSOR_ARENA_SIZE +#ifdef ETHOS_U +#define TENSOR_ARENA_SIZE (136 * 1024) +#else +#define TENSOR_ARENA_SIZE (3 * 1024) +#endif +#endif + +#ifndef NUM_INFERENCES +#define NUM_INFERENCES 1 +#endif + +uint8_t tensor_arena[TENSOR_ARENA_SIZE]; + +#ifdef NUM_BYTES_TO_PRINT +inline void print_output_data(TfLiteTensor *output) +{ + int num_bytes_to_print = + ((output->bytes < NUM_BYTES_TO_PRINT) || NUM_BYTES_TO_PRINT == 0) ? output->bytes : NUM_BYTES_TO_PRINT; + + int dims_size = output->dims->size; + printf("{\n"); + printf("\"dims\": [%d,", dims_size); + for (int i = 0; i < output->dims->size - 1; ++i) { + printf("%d,", output->dims->data[i]); + } + printf("%d],\n", output->dims->data[dims_size - 1]); + + printf("\"data_address\": \"%p\",\n", output->data.raw); + printf("\"data\":\""); + for (int i = 0; i < num_bytes_to_print - 1; ++i) { + if (i % 16 == 0 && i != 0) { + printf("\n"); + } + printf("0x%02x,", output->data.uint8[i]); + } + printf("0x%02x\"\n", output->data.uint8[num_bytes_to_print - 1]); + printf("}"); +} +#endif + +template +void check_output_elem(TfLiteTensor *output, const T *expected_output, + const int index) +{ + TF_LITE_MICRO_EXPECT_EQ(tflite::GetTensorData(output)[index], + expected_output[index]); +} + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestInvoke) +{ + tflite::MicroErrorReporter micro_error_reporter; + +#ifdef ETHOS_U + const tflite::Model *model = ::tflite::GetModel(g_person_detect_model_data); +#else + const tflite::Model *model = ::tflite::GetModel(network_model); +#endif + if (model->version() != TFLITE_SCHEMA_VERSION) { + TF_LITE_REPORT_ERROR(µ_error_reporter, + "Model provided is schema version %d not equal " + "to supported version %d.\n", + model->version(), TFLITE_SCHEMA_VERSION); + return kTfLiteError; + } + + tflite::AllOpsResolver resolver; + + tflite::MicroInterpreter interpreter( + model, resolver, tensor_arena, TENSOR_ARENA_SIZE, µ_error_reporter); + + TfLiteStatus allocate_status = interpreter.AllocateTensors(); + if (allocate_status != kTfLiteOk) { + TF_LITE_REPORT_ERROR(µ_error_reporter, "Tensor allocation failed\n"); + return kTfLiteError; + } + + for (int n = 0; n < NUM_INFERENCES; n++) { + for (size_t i = 0; i < interpreter.inputs_size(); ++i) { + TfLiteTensor *input = interpreter.input(i); +#ifdef ETHOS_U + memcpy(input->data.int8, g_person_data, input->bytes); +#else + memcpy(input->data.data, &input_data[i], input->bytes); +#endif + } + TfLiteStatus invoke_status = interpreter.Invoke(); + if (invoke_status != kTfLiteOk) { + TF_LITE_REPORT_ERROR(µ_error_reporter, "Invoke failed\n"); + return kTfLiteError; + } + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, invoke_status); + +#ifdef NUM_BYTES_TO_PRINT + // Print all of the output data, or the first NUM_BYTES_TO_PRINT bytes, + // whichever comes first as well as the output shape. + printf("num_of_outputs: %d\n", interpreter.outputs_size()); + printf("output_begin\n"); + printf("[\n"); + for (int i = 0; i < interpreter.outputs_size(); i++) { + TfLiteTensor *output = interpreter.output(i); + print_output_data(output); + if (i != interpreter.outputs_size() - 1) { + printf(",\n"); + } + } + printf("]\n"); + printf("output_end\n"); +#endif + +#ifndef NO_COMPARE_OUTPUT_DATA + for (size_t i = 0; i < interpreter.outputs_size(); i++) { + TfLiteTensor *output = interpreter.output(i); + for (int j = 0; j < tflite::ElementCount(*(output->dims)); ++j) { + check_output_elem(output, &expected_output_data[i], j); + } + } +#endif + } + TF_LITE_REPORT_ERROR(µ_error_reporter, "Ran successfully\n"); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/examples/person_detection/README.md b/components/tflite/tensorflow/lite/micro/examples/person_detection/README.md new file mode 100644 index 00000000..c52d8c1a --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/person_detection/README.md @@ -0,0 +1,646 @@ +# Person detection example + +This example shows how you can use Tensorflow Lite to run a 250 kilobyte neural +network to recognize people in images captured by a camera. It is designed to +run on systems with small amounts of memory such as microcontrollers and DSPs. +This uses the experimental int8 quantized version of the person detection model. + +## Table of contents + +- [Getting started](#getting-started) +- [Running on ARC EM SDP](#running-on-arc-em-sdp) +- [Running on Arduino](#running-on-arduino) +- [Running on ESP32](#running-on-esp32) +- [Running on HIMAX WE1 EVB](#running-on-himax-we1-evb) +- [Running on SparkFun Edge](#running-on-sparkfun-edge) +- [Run the tests on a development machine](#run-the-tests-on-a-development-machine) +- [Debugging image capture](#debugging-image-capture) +- [Training your own model](#training-your-own-model) + +## Running on ARC EM SDP + +The following instructions will help you to build and deploy this example to +[ARC EM SDP](https://www.synopsys.com/dw/ipdir.php?ds=arc-em-software-development-platform) +board. General information and instructions on using the board with TensorFlow +Lite Micro can be found in the common +[ARC targets description](/tensorflow/lite/micro/tools/make/targets/arc/README.md). + +This example uses asymmetric int8 quantization and can therefore leverage +optimized int8 kernels from the embARC MLI library + +The ARC EM SDP board contains a rich set of extension interfaces. You can choose +any compatible camera and modify +[image_provider.cc](/tensorflow/lite/micro/examples/person_detection/image_provider.cc) +file accordingly to use input from your specific camera. By default, results of +running this example are printed to the console. If you would like to instead +implement some target-specific actions, you need to modify +[detection_responder.cc](/tensorflow/lite/micro/examples/person_detection/detection_responder.cc) +accordingly. + +The reference implementations of these files are used by default on the EM SDP. + +### Initial setup + +Follow the instructions on the +[ARC EM SDP Initial Setup](/tensorflow/lite/micro/tools/make/targets/arc/README.md#ARC-EM-Software-Development-Platform-ARC-EM-SDP) +to get and install all required tools for work with ARC EM SDP. + +### Generate Example Project + +The example project for ARC EM SDP platform can be generated with the following +command: + +``` +make -f tensorflow/lite/micro/tools/make/Makefile \ +TARGET=arc_emsdp ARC_TAGS=reduce_codesize \ +OPTIMIZED_KERNEL_DIR=arc_mli \ +generate_person_detection_int8_make_project +``` + +Note that `ARC_TAGS=reduce_codesize` applies example specific changes of code to +reduce total size of application. It can be omitted. + +### Build and Run Example + +For more detailed information on building and running examples see the +appropriate sections of general descriptions of the +[ARC EM SDP usage with TFLM](/tensorflow/lite/micro/tools/make/targets/arc/README.md#ARC-EM-Software-Development-Platform-ARC-EM-SDP). +In the directory with generated project you can also find a +*README_ARC_EMSDP.md* file with instructions and options on building and +running. Here we only briefly mention main steps which are typically enough to +get it started. + +1. You need to + [connect the board](/tensorflow/lite/micro/tools/make/targets/arc/README.md#connect-the-board) + and open an serial connection. + +2. Go to the generated example project director + + ``` + cd tensorflow/lite/micro/tools/make/gen/arc_emsdp_arc/prj/person_detection_int8/make + ``` + +3. Build the example using + + ``` + make app + ``` + +4. To generate artefacts for self-boot of example from the board use + + ``` + make flash + ``` + +5. To run application from the board using microSD card: + + * Copy the content of the created /bin folder into the root of microSD + card. Note that the card must be formatted as FAT32 with default cluster + size (but less than 32 Kbytes) + * Plug in the microSD card into the J11 connector. + * Push the RST button. If a red LED is lit beside RST button, push the CFG + button. + * Type or copy next commands one-by-another into serial terminal: `setenv + loadaddr 0x10800000 setenv bootfile app.elf setenv bootdelay 1 setenv + bootcmd fatload mmc 0 \$\{loadaddr\} \$\{bootfile\} \&\& bootelf + saveenv` + * Push the RST button. + +6. If you have the MetaWare Debugger installed in your environment: + + * To run application from the console using it type `make run`. + * To stop the execution type `Ctrl+C` in the console several times. + +In both cases (step 5 and 6) you will see the application output in the serial +terminal. + +## Running on Arduino + +The following instructions will help you build and deploy this sample +to [Arduino](https://www.arduino.cc/) devices. + +The sample has been tested with the following device: + +- [Arduino Nano 33 BLE Sense](https://store.arduino.cc/usa/nano-33-ble-sense-with-headers) + +You will also need the following camera module: + +- [Arducam Mini 2MP Plus](https://www.amazon.com/Arducam-Module-Megapixels-Arduino-Mega2560/dp/B012UXNDOY) + +### Hardware + +Connect the Arducam pins as follows: + +|Arducam pin name|Arduino pin name| +|----------------|----------------| +|CS|D7 (unlabelled, immediately to the right of D6)| +|MOSI|D11| +|MISO|D12| +|SCK|D13| +|GND|GND (either pin marked GND is fine)| +|VCC|3.3 V| +|SDA|A4| +|SCL|A5| + +### Install the Arduino_TensorFlowLite library + +Download the current nightly build of the library: +[person_detection.zip](https://storage.googleapis.com/download.tensorflow.org/data/tf_lite_micro_person_data_int8_grayscale_2020_01_13.zip) + +This example application is included as part of the official TensorFlow Lite +Arduino library. To install it, open the Arduino library manager in +`Tools -> Manage Libraries...` and search for `Arduino_TensorFlowLite`. + +### Install other libraries + +In addition to the TensorFlow library, you'll also need to install two +libraries: + +* The Arducam library, so our code can interface with the hardware +* The JPEGDecoder library, so we can decode JPEG-encoded images + +The Arducam Arduino library is available from GitHub at +[https://github.com/ArduCAM/Arduino](https://github.com/ArduCAM/Arduino). +To install it, download or clone the repository. Next, copy its `ArduCAM` +subdirectory into your `Arduino/libraries` directory. To find this directory on +your machine, check the *Sketchbook location* in the Arduino IDE's +*Preferences* window. + +After downloading the library, you'll need to edit one of its files to make sure +it is configured for the Arducam Mini 2MP Plus. To do so, open the following +file: + +``` +Arduino/libraries/ArduCAM/memorysaver.h +``` + +You'll see a bunch of `#define` statements listed. Make sure that they are all +commented out, except for `#define OV2640_MINI_2MP_PLUS`, as so: + +``` +//Step 1: select the hardware platform, only one at a time +//#define OV2640_MINI_2MP +//#define OV3640_MINI_3MP +//#define OV5642_MINI_5MP +//#define OV5642_MINI_5MP_BIT_ROTATION_FIXED +#define OV2640_MINI_2MP_PLUS +//#define OV5642_MINI_5MP_PLUS +//#define OV5640_MINI_5MP_PLUS +``` + +Once you save the file, we're done configuring the Arducam library. + +Our next step is to install the JPEGDecoder library. We can do this from within +the Arduino IDE. First, go to the *Manage Libraries...* option in the *Tools* +menu and search for `JPEGDecoder`. You should install version _1.8.0_ of the +library. + +Once the library has installed, we'll need to configure it to disable some +optional components that are not compatible with the Arduino Nano 33 BLE Sense. +Open the following file: + +``` +Arduino/libraries/JPEGDecoder/src/User_Config.h +``` + +Make sure that both `#define LOAD_SD_LIBRARY` and `#define LOAD_SDFAT_LIBRARY` +are commented out, as shown in this excerpt from the file: + +```c++ +// Comment out the next #defines if you are not using an SD Card to store the JPEGs +// Commenting out the line is NOT essential but will save some FLASH space if +// SD Card access is not needed. Note: use of SdFat is currently untested! + +//#define LOAD_SD_LIBRARY // Default SD Card library +//#define LOAD_SDFAT_LIBRARY // Use SdFat library instead, so SD Card SPI can be bit bashed +``` + +Once you've saved the file, you are done installing libraries. + +### Load and run the example + +Go to `File -> Examples`. You should see an +example near the bottom of the list named `TensorFlowLite`. Select +it and click `person_detection` to load the example. Connect your device, then +build and upload the example. + +To test the camera, start by pointing the device's camera at something that is +definitely not a person, or just covering it up. The next time the blue LED +flashes, the device will capture a frame from the camera and begin to run +inference. The vision model we are using for person detection is relatively +large, but with cmsis-nn optimizations it only takes around 800ms to run the +model. + +After a moment, the inference result will be translated into another LED being +lit. Since you pointed the camera at something that isn't a person, the red LED +should light up. + +Now, try pointing the device's camera at yourself! The next time the blue LED +flashes, the device will capture another image and begin to run inference. After +a brief puase, the green LED should light up! + +Remember, image data is captured as a snapshot before each inference, whenever +the blue LED flashes. Whatever the camera is pointed at during that moment is +what will be fed into the model. It doesn't matter where the camera is pointed +until the next time an image is captured, when the blue LED will flash again. + +If you're getting seemingly incorrect results, make sure you are in an +environment with good lighting. You should also make sure that the camera is +oriented correctly, with the pins pointing downwards, so that the images it +captures are the right way up—the model was not trained to recognize upside-down +people! In addition, it's good to remember that this is a tiny model, which +trades accuracy for small size. It works very well, but it isn't accurate 100% +of the time. + +We can also see the results of inference via the Arduino Serial Monitor. To do +this, open the *Serial Monitor* from the *Tools* menu. You'll see a detailed +log of what is happening while our application runs. It's also interesting to +check the *Show timestamp* box, so you can see how long each part of the process +takes: + +``` +14:17:50.714 -> Starting capture +14:17:50.714 -> Image captured +14:17:50.784 -> Reading 3080 bytes from ArduCAM +14:17:50.887 -> Finished reading +14:17:50.887 -> Decoding JPEG and converting to greyscale +14:17:51.074 -> Image decoded and processed +14:18:09.710 -> Person score: 246 No person score: 66 +``` + +From the log, we can see that it took around 170 ms to capture and read the +image data from the camera module, 180 ms to decode the JPEG and convert it to +greyscale, and 18.6 seconds to run inference. + +## Running on ESP32 + +The following instructions will help you build and deploy this sample to +[ESP32](https://www.espressif.com/en/products/hardware/esp32/overview) devices +using the [ESP IDF](https://github.com/espressif/esp-idf). + +The sample has been tested on ESP-IDF version 4.0 with the following devices: - +[ESP32-DevKitC](http://esp-idf.readthedocs.io/en/latest/get-started/get-started-devkitc.html) - +[ESP-EYE](https://github.com/espressif/esp-who/blob/master/docs/en/get-started/ESP-EYE_Getting_Started_Guide.md) + +ESP-EYE is a board which has a built-in camera which can be used to run this +example , if you want to use other esp boards you will have to connect camera +externally and write your own +[image_provider.cc](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/micro/examples/person_detection/esp/image_provider.cc). +and +[app_camera_esp.c](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/micro/examples/person_detection/esp/app_camera_esp.c). +You can also write you own +[detection_responder.cc](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/micro/examples/person_detection/detection_responder.cc). + +### Install the ESP IDF + +Follow the instructions of the +[ESP-IDF get started guide](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html) +to setup the toolchain and the ESP-IDF itself. + +The next steps assume that the +[IDF environment variables are set](https://docs.espressif.com/projects/esp-idf/en/latest/get-started/index.html#step-4-set-up-the-environment-variables) : + +* The `IDF_PATH` environment variable is set +* `idf.py` and Xtensa-esp32 tools (e.g. `xtensa-esp32-elf-gcc`) are in `$PATH` +* `esp32-camera` should be downloaded in `components/` dir of example as + explained in `Building the example`(below) + +### Generate the examples + +The example project can be generated with the following command: +``` +make -f tensorflow/lite/micro/tools/make/Makefile TARGET=esp generate_person_detection_esp_project +``` + +### Building the example + +Go to the example project directory +``` +cd tensorflow/lite/micro/tools/make/gen/esp_xtensa-esp32/prj/person_detection/esp-idf +``` + +As the `person_detection` example requires an external component `esp32-camera` +for functioning hence we will have to manually clone it in `components/` +directory of the example with following command. +``` +git clone https://github.com/espressif/esp32-camera.git components/esp32-camera +``` + +Then build with `idf.py` `idf.py build` + +### Load and run the example + +To flash (replace `/dev/ttyUSB0` with the device serial port): +``` +idf.py --port /dev/ttyUSB0 flash +``` + +Monitor the serial output: +``` +idf.py --port /dev/ttyUSB0 monitor +``` + +Use `Ctrl+]` to exit. + +The previous two commands can be combined: +``` +idf.py --port /dev/ttyUSB0 flash monitor +``` + +## Running on HIMAX WE1 EVB + +The following instructions will help you build and deploy this example to +[HIMAX WE1 EVB](https://github.com/HimaxWiseEyePlus/bsp_tflu/tree/master/HIMAX_WE1_EVB_board_brief) +board. To understand more about using this board, please check +[HIMAX WE1 EVB user guide](https://github.com/HimaxWiseEyePlus/bsp_tflu/tree/master/HIMAX_WE1_EVB_user_guide). + +### Initial Setup + +To use the HIMAX WE1 EVB, please make sure following software are installed: + +#### MetaWare Development Toolkit + +See +[Install the Synopsys DesignWare ARC MetaWare Development Toolkit](/tensorflow/lite/micro/tools/make/targets/arc/README.md#install-the-synopsys-designware-arc-metaware-development-toolkit) +section for instructions on toolchain installation. + +#### Make Tool version + +A `'make'` tool is required for deploying Tensorflow Lite Micro applications on +HIMAX WE1 EVB, See +[Check make tool version](/tensorflow/lite/micro/tools/make/targets/arc/README.md#make-tool) +section for proper environment. + +#### Serial Terminal Emulation Application + +There are 2 main purposes for HIMAX WE1 EVB Debug UART port + +- print application output +- burn application to flash by using xmodem send application binary + +You can use any terminal emulation program (like [PuTTY](https://www.putty.org/) +or [minicom](https://linux.die.net/man/1/minicom)). + +### Generate Example Project + +The example project for HIMAX WE1 EVB platform can be generated with the +following command: + +Download related third party data + +``` +make -f tensorflow/lite/micro/tools/make/Makefile TARGET=himax_we1_evb third_party_downloads +``` + +Generate person detection project + +``` +make -f tensorflow/lite/micro/tools/make/Makefile generate_person_detection_int8_make_project TARGET=himax_we1_evb +``` + +### Build and Burn Example + +Following the Steps to run person detection example at HIMAX WE1 EVB platform. + +1. Go to the generated example project directory. + + ``` + cd tensorflow/lite/micro/tools/make/gen/himax_we1_evb_arc/prj/person_detection_int8/make + ``` + +2. Build the example using + + ``` + make app + ``` + +3. After example build finish, copy ELF file and map file to image generate + tool directory. \ + image generate tool directory located at + `'tensorflow/lite/micro/tools/make/downloads/himax_we1_sdk/image_gen_linux_v3/'` + + ``` + cp person_detection_int8.elf himax_we1_evb.map ../../../../../downloads/himax_we1_sdk/image_gen_linux_v3/ + ``` + +4. Go to flash image generate tool directory. + + ``` + cd ../../../../../downloads/himax_we1_sdk/image_gen_linux_v3/ + ``` + + make sure this tool directory is in $PATH. You can permanently set it to + PATH by + + ``` + export PATH=$PATH:$(pwd) + ``` + +5. run image generate tool, generate flash image file. + + * Before running image generate tool, by typing `sudo chmod +x image_gen` + and `sudo chmod +x sign_tool` to make sure it is executable. + + ``` + image_gen -e person_detection_int8.elf -m himax_we1_evb.map -o out.img + ``` + +6. Download flash image file to HIMAX WE1 EVB by UART: + + * more detail about download image through UART can be found at + [HIMAX WE1 EVB update Flash image](https://github.com/HimaxWiseEyePlus/bsp_tflu/tree/master/HIMAX_WE1_EVB_user_guide#flash-image-update) + +After these steps, press reset button on the HIMAX WE1 EVB, you will see +application output in the serial terminal. + +## Running on SparkFun Edge + +The following instructions will help you build and deploy this sample on the +[SparkFun Edge development board](https://sparkfun.com/products/15170). This +sample requires the Sparkfun Himax camera for the Sparkfun Edge board. It is +not available for purchase yet. + +If you're new to using this board, we recommend walking through the +[AI on a microcontroller with TensorFlow Lite and SparkFun Edge](https://codelabs.developers.google.com/codelabs/sparkfun-tensorflow) +codelab to get an understanding of the workflow. + +### Compile the binary + +The following command will download the required dependencies and then compile a +binary for the SparkFun Edge: + +``` +make -f tensorflow/lite/micro/tools/make/Makefile TARGET=sparkfun_edge person_detection_int8_bin +``` + +The binary will be created in the following location: + +``` +tensorflow/lite/micro/tools/make/gen/sparkfun_edge_cortex-m4/bin/person_detection_int8.bin +``` + +### Sign the binary + +The binary must be signed with cryptographic keys to be deployed to the device. +We'll now run some commands that will sign our binary so it can be flashed to +the SparkFun Edge. The scripts we are using come from the Ambiq SDK, which is +downloaded when the `Makefile` is run. + +Enter the following command to set up some dummy cryptographic keys we can use +for development: + +``` +cp tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.0.0/tools/apollo3_scripts/keys_info0.py \ +tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.0.0/tools/apollo3_scripts/keys_info.py +``` + +Next, run the following command to create a signed binary: + +``` +python3 tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.0.0/tools/apollo3_scripts/create_cust_image_blob.py \ +--bin tensorflow/lite/micro/tools/make/gen/sparkfun_edge_cortex-m4/bin/person_detection_int8.bin \ +--load-address 0xC000 \ +--magic-num 0xCB \ +-o main_nonsecure_ota \ +--version 0x0 +``` + +This will create the file `main_nonsecure_ota.bin`. We'll now run another +command to create a final version of the file that can be used to flash our +device with the bootloader script we will use in the next step: + +``` +python3 tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.0.0/tools/apollo3_scripts/create_cust_wireupdate_blob.py \ +--load-address 0x20000 \ +--bin main_nonsecure_ota.bin \ +-i 6 \ +-o main_nonsecure_wire \ +--options 0x1 +``` + +You should now have a file called `main_nonsecure_wire.bin` in the directory +where you ran the commands. This is the file we'll be flashing to the device. + +### Flash the binary + +Next, attach the board to your computer via a USB-to-serial adapter. + +**Note:** If you're using the [SparkFun Serial Basic Breakout](https://www.sparkfun.com/products/15096), +you should [install the latest drivers](https://learn.sparkfun.com/tutorials/sparkfun-serial-basic-ch340c-hookup-guide#drivers-if-you-need-them) +before you continue. + +Once connected, assign the USB device name to an environment variable: + +``` +export DEVICENAME=put your device name here +``` + +Set another variable with the baud rate: + +``` +export BAUD_RATE=921600 +``` + +Now, hold the button marked `14` on the device. While still holding the button, +hit the button marked `RST`. Continue holding the button marked `14` while +running the following command: + +``` +python3 tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.0.0/tools/apollo3_scripts/uart_wired_update.py \ +-b ${BAUD_RATE} ${DEVICENAME} \ +-r 1 \ +-f main_nonsecure_wire.bin \ +-i 6 +``` + +You should see a long stream of output as the binary is flashed to the device. +Once you see the following lines, flashing is complete: + +``` +Sending Reset Command. +Done. +``` + +If you don't see these lines, flashing may have failed. Try running through the +steps in [Flash the binary](#flash-the-binary) again (you can skip over setting +the environment variables). If you continue to run into problems, follow the +[AI on a microcontroller with TensorFlow Lite and SparkFun Edge](https://codelabs.developers.google.com/codelabs/sparkfun-tensorflow) +codelab, which includes more comprehensive instructions for the flashing +process. + +The binary should now be deployed to the device. Hit the button marked `RST` to +reboot the board. You should see the device's four LEDs flashing in sequence. + +Debug information is logged by the board while the program is running. To view +it, establish a serial connection to the board using a baud rate of `115200`. +On OSX and Linux, the following command should work: + +``` +screen ${DEVICENAME} 115200 +``` + +To stop viewing the debug output with `screen`, hit `Ctrl+A`, immediately +followed by the `K` key, then hit the `Y` key. + +## Run the tests on a development machine + +To compile and test this example on a desktop Linux or MacOS machine, download +[the TensorFlow source code](https://github.com/tensorflow/tensorflow), `cd` +into the source directory from a terminal, and then run the following command: + +``` +make -f tensorflow/lite/micro/tools/make/Makefile +``` + +This will take a few minutes, and downloads frameworks the code uses like +[CMSIS](https://developer.arm.com/embedded/cmsis) and +[flatbuffers](https://google.github.io/flatbuffers/). Once that process has +finished, run: + +``` +make -f tensorflow/lite/micro/tools/make/Makefile test_person_detection_test_int8 +``` + +You should see a series of files get compiled, followed by some logging output +from a test, which should conclude with `~~~ALL TESTS PASSED~~~`. If you see +this, it means that a small program has been built and run that loads a trained +TensorFlow model, runs some example images through it, and got the expected +outputs. This particular test runs images with a and without a person in them, +and checks that the network correctly identifies them. + +To understand how TensorFlow Lite does this, you can look at the `TestInvoke()` +function in +[person_detection_test.cc](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/micro/examples/person_detection/person_detection_test.cc). +It's a fairly small amount of code, creating an interpreter, getting a handle to +a model that's been compiled into the program, and then invoking the interpreter +with the model and sample inputs. + +## Debugging image capture +When the sample is running, check the LEDs to determine whether the inference is +running correctly. If the red light is stuck on, it means there was an error +communicating with the camera. This is likely due to an incorrectly connected +or broken camera. + +During inference, the blue LED will toggle every time inference is complete. The +orange LED indicates that no person was found, and the green LED indicates a +person was found. The red LED should never turn on, since it indicates an error. + +In order to view the captured image, set the DUMP_IMAGE define in main.cc.  This +causes the board to log raw image info to the console. After the board has been +flashed and reset, dump the log to a text file: + + +``` +screen -L -Logfile ${DEVICENAME} 115200 +``` + +Next, run the raw to bitmap converter to view captured images: + +``` +python3 raw_to_bitmap.py -r GRAY -i +``` + +## Training your own model + +You can train your own model with some easy-to-use scripts. See +[training_a_model.md](training_a_model.md) for instructions. diff --git a/components/tflite/tensorflow/lite/micro/examples/person_detection/detection_responder.cc b/components/tflite/tensorflow/lite/micro/examples/person_detection/detection_responder.cc new file mode 100644 index 00000000..560551aa --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/person_detection/detection_responder.cc @@ -0,0 +1,26 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/person_detection/detection_responder.h" + +// This dummy implementation writes person and no person scores to the error +// console. Real applications will want to take some custom action instead, and +// should implement their own versions of this function. +void RespondToDetection(tflite::ErrorReporter *error_reporter, + int8_t person_score, int8_t no_person_score) +{ + TF_LITE_REPORT_ERROR(error_reporter, "person score:%d no person score %d", + person_score, no_person_score); +} diff --git a/components/tflite/tensorflow/lite/micro/examples/person_detection/detection_responder.h b/components/tflite/tensorflow/lite/micro/examples/person_detection/detection_responder.h new file mode 100644 index 00000000..acadf963 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/person_detection/detection_responder.h @@ -0,0 +1,34 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// Provides an interface to take an action based on the output from the person +// detection model. + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_DETECTION_RESPONDER_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_DETECTION_RESPONDER_H_ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" + +// Called every time the results of a person detection run are available. The +// `person_score` has the numerical confidence that the captured image contains +// a person, and `no_person_score` has the numerical confidence that the image +// does not contain a person. Typically if person_score > no person score, the +// image is considered to contain a person. This threshold may be adjusted for +// particular applications. +void RespondToDetection(tflite::ErrorReporter *error_reporter, + int8_t person_score, int8_t no_person_score); + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_DETECTION_RESPONDER_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/person_detection/detection_responder_test.cc b/components/tflite/tensorflow/lite/micro/examples/person_detection/detection_responder_test.cc new file mode 100644 index 00000000..06826868 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/person_detection/detection_responder_test.cc @@ -0,0 +1,33 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/person_detection/detection_responder.h" + +#include "tensorflow/lite/micro/testing/micro_test.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestCallability) +{ + tflite::MicroErrorReporter micro_error_reporter; + + // This will have external side-effects (like printing to the debug console + // or lighting an LED) that are hard to observe, so the most we can do is + // make sure the call doesn't crash. + RespondToDetection(µ_error_reporter, -100, 100); + RespondToDetection(µ_error_reporter, 100, 50); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/examples/person_detection/image_provider.cc b/components/tflite/tensorflow/lite/micro/examples/person_detection/image_provider.cc new file mode 100644 index 00000000..8ad57919 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/person_detection/image_provider.cc @@ -0,0 +1,27 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/person_detection/image_provider.h" + +#include "tensorflow/lite/micro/examples/person_detection/model_settings.h" + +TfLiteStatus GetImage(tflite::ErrorReporter *error_reporter, int image_width, + int image_height, int channels, int8_t *image_data) +{ + for (int i = 0; i < image_width * image_height * channels; ++i) { + image_data[i] = 0; + } + return kTfLiteOk; +} diff --git a/components/tflite/tensorflow/lite/micro/examples/person_detection/image_provider.h b/components/tflite/tensorflow/lite/micro/examples/person_detection/image_provider.h new file mode 100644 index 00000000..bf35d81d --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/person_detection/image_provider.h @@ -0,0 +1,39 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_IMAGE_PROVIDER_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_IMAGE_PROVIDER_H_ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" + +// This is an abstraction around an image source like a camera, and is +// expected to return 8-bit sample data. The assumption is that this will be +// called in a low duty-cycle fashion in a low-power application. In these +// cases, the imaging sensor need not be run in a streaming mode, but rather can +// be idled in a relatively low-power mode between calls to GetImage(). The +// assumption is that the overhead and time of bringing the low-power sensor out +// of this standby mode is commensurate with the expected duty cycle of the +// application. The underlying sensor may actually be put into a streaming +// configuration, but the image buffer provided to GetImage should not be +// overwritten by the driver code until the next call to GetImage(); +// +// The reference implementation can have no platform-specific dependencies, so +// it just returns a static image. For real applications, you should +// ensure there's a specialized implementation that accesses hardware APIs. +TfLiteStatus GetImage(tflite::ErrorReporter *error_reporter, int image_width, + int image_height, int channels, int8_t *image_data); + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_IMAGE_PROVIDER_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/person_detection/image_provider_test.cc b/components/tflite/tensorflow/lite/micro/examples/person_detection/image_provider_test.cc new file mode 100644 index 00000000..1f17c06a --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/person_detection/image_provider_test.cc @@ -0,0 +1,44 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/person_detection/image_provider.h" + +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/examples/person_detection/model_settings.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestImageProvider) +{ + tflite::MicroErrorReporter micro_error_reporter; + + int8_t image_data[kMaxImageSize]; + TfLiteStatus get_status = GetImage(µ_error_reporter, kNumCols, kNumRows, + kNumChannels, image_data); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, get_status); + TF_LITE_MICRO_EXPECT_NE(image_data, nullptr); + + // Make sure we can read all of the returned memory locations. + uint32_t total = 0; + for (int i = 0; i < kMaxImageSize; ++i) { + total += image_data[i]; + } +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/examples/person_detection/main.cc b/components/tflite/tensorflow/lite/micro/examples/person_detection/main.cc new file mode 100644 index 00000000..4536d4c6 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/person_detection/main.cc @@ -0,0 +1,28 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/person_detection/main_functions.h" + +// This is the default main used on systems that have the standard C entry +// point. Other devices (for example FreeRTOS or ESP32) that have different +// requirements for entry code (like an app_main function) should specialize +// this main.cc file in a target-specific subfolder. +int main(int argc, char *argv[]) +{ + setup(); + while (true) { + loop(); + } +} diff --git a/components/tflite/tensorflow/lite/micro/examples/person_detection/main_functions.cc b/components/tflite/tensorflow/lite/micro/examples/person_detection/main_functions.cc new file mode 100644 index 00000000..edd28e0d --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/person_detection/main_functions.cc @@ -0,0 +1,121 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/person_detection/main_functions.h" + +#include "tensorflow/lite/micro/examples/person_detection/detection_responder.h" +#include "tensorflow/lite/micro/examples/person_detection/image_provider.h" +#include "tensorflow/lite/micro/examples/person_detection/model_settings.h" +#include "tensorflow/lite/micro/examples/person_detection/person_detect_model_data.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/micro_interpreter.h" +#include "tensorflow/lite/micro/micro_mutable_op_resolver.h" +#include "tensorflow/lite/micro/system_setup.h" +#include "tensorflow/lite/schema/schema_generated.h" + +// Globals, used for compatibility with Arduino-style sketches. +namespace { +tflite::ErrorReporter *error_reporter = nullptr; +const tflite::Model *model = nullptr; +tflite::MicroInterpreter *interpreter = nullptr; +TfLiteTensor *input = nullptr; + +// In order to use optimized tensorflow lite kernels, a signed int8_t quantized +// model is preferred over the legacy unsigned model format. This means that +// throughout this project, input images must be converted from unisgned to +// signed format. The easiest and quickest way to convert from unsigned to +// signed 8-bit integers is to subtract 128 from the unsigned value to get a +// signed value. + +// An area of memory to use for input, output, and intermediate arrays. +constexpr int kTensorArenaSize = 136 * 1024; +static uint8_t tensor_arena[kTensorArenaSize]; +} // namespace + +// The name of this function is important for Arduino compatibility. +void setup() +{ + tflite::InitializeTarget(); + + // Set up logging. Google style is to avoid globals or statics because of + // lifetime uncertainty, but since this has a trivial destructor it's okay. + // NOLINTNEXTLINE(runtime-global-variables) + static tflite::MicroErrorReporter micro_error_reporter; + error_reporter = µ_error_reporter; + + // Map the model into a usable data structure. This doesn't involve any + // copying or parsing, it's a very lightweight operation. + model = tflite::GetModel(g_person_detect_model_data); + if (model->version() != TFLITE_SCHEMA_VERSION) { + TF_LITE_REPORT_ERROR(error_reporter, + "Model provided is schema version %d not equal " + "to supported version %d.", + model->version(), TFLITE_SCHEMA_VERSION); + return; + } + + // Pull in only the operation implementations we need. + // This relies on a complete list of all the ops needed by this graph. + // An easier approach is to just use the AllOpsResolver, but this will + // incur some penalty in code space for op implementations that are not + // needed by this graph. + // + // tflite::AllOpsResolver resolver; + // NOLINTNEXTLINE(runtime-global-variables) + static tflite::MicroMutableOpResolver<5> micro_op_resolver; + micro_op_resolver.AddAveragePool2D(); + micro_op_resolver.AddConv2D(); + micro_op_resolver.AddDepthwiseConv2D(); + micro_op_resolver.AddReshape(); + micro_op_resolver.AddSoftmax(); + + // Build an interpreter to run the model with. + // NOLINTNEXTLINE(runtime-global-variables) + static tflite::MicroInterpreter static_interpreter( + model, micro_op_resolver, tensor_arena, kTensorArenaSize, error_reporter); + interpreter = &static_interpreter; + + // Allocate memory from the tensor_arena for the model's tensors. + TfLiteStatus allocate_status = interpreter->AllocateTensors(); + if (allocate_status != kTfLiteOk) { + TF_LITE_REPORT_ERROR(error_reporter, "AllocateTensors() failed"); + return; + } + + // Get information about the memory area to use for the model's input. + input = interpreter->input(0); +} + +// The name of this function is important for Arduino compatibility. +void loop() +{ + // Get image from provider. + if (kTfLiteOk != GetImage(error_reporter, kNumCols, kNumRows, kNumChannels, + input->data.int8)) { + TF_LITE_REPORT_ERROR(error_reporter, "Image capture failed."); + } + + // Run the model on this input and make sure it succeeds. + if (kTfLiteOk != interpreter->Invoke()) { + TF_LITE_REPORT_ERROR(error_reporter, "Invoke failed."); + } + + TfLiteTensor *output = interpreter->output(0); + + // Process the inference results. + int8_t person_score = output->data.uint8[kPersonIndex]; + int8_t no_person_score = output->data.uint8[kNotAPersonIndex]; + RespondToDetection(error_reporter, person_score, no_person_score); +} diff --git a/components/tflite/tensorflow/lite/micro/examples/person_detection/main_functions.h b/components/tflite/tensorflow/lite/micro/examples/person_detection/main_functions.h new file mode 100644 index 00000000..d21130b4 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/person_detection/main_functions.h @@ -0,0 +1,37 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_MAIN_FUNCTIONS_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_MAIN_FUNCTIONS_H_ + +// Expose a C friendly interface for main functions. +#ifdef __cplusplus +extern "C" { +#endif + +// Initializes all data needed for the example. The name is important, and needs +// to be setup() for Arduino compatibility. +void setup(); + +// Runs one iteration of data gathering and inference. This should be called +// repeatedly from the application code. The name needs to be loop() for Arduino +// compatibility. +void loop(); + +#ifdef __cplusplus +} +#endif + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_MAIN_FUNCTIONS_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/person_detection/model_settings.cc b/components/tflite/tensorflow/lite/micro/examples/person_detection/model_settings.cc new file mode 100644 index 00000000..3b47c63b --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/person_detection/model_settings.cc @@ -0,0 +1,21 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/examples/person_detection/model_settings.h" + +const char *kCategoryLabels[kCategoryCount] = { + "notperson", + "person", +}; diff --git a/components/tflite/tensorflow/lite/micro/examples/person_detection/model_settings.h b/components/tflite/tensorflow/lite/micro/examples/person_detection/model_settings.h new file mode 100644 index 00000000..d790afab --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/person_detection/model_settings.h @@ -0,0 +1,35 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_MODEL_SETTINGS_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_MODEL_SETTINGS_H_ + +// Keeping these as constant expressions allow us to allocate fixed-sized arrays +// on the stack for our working memory. + +// All of these values are derived from the values used during model training, +// if you change your model you'll need to update these constants. +constexpr int kNumCols = 96; +constexpr int kNumRows = 96; +constexpr int kNumChannels = 1; + +constexpr int kMaxImageSize = kNumCols * kNumRows * kNumChannels; + +constexpr int kCategoryCount = 2; +constexpr int kPersonIndex = 1; +constexpr int kNotAPersonIndex = 0; +extern const char *kCategoryLabels[kCategoryCount]; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_MODEL_SETTINGS_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/person_detection/no_person_image_data.h b/components/tflite/tensorflow/lite/micro/examples/person_detection/no_person_image_data.h new file mode 100644 index 00000000..f2fc9149 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/person_detection/no_person_image_data.h @@ -0,0 +1,30 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// This data was created from a sample image from without a person in it. +// Convert original image to simpler format: +// convert -resize 96x96\! noperson.PNG noperson.bmp3 +// Skip the 54 byte bmp3 header and add the reset of the bytes to a C array: +// xxd -s 54 -i /tmp/noperson.bmp3 > /tmp/noperson.cc + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_NO_PERSON_IMAGE_DATA_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_NO_PERSON_IMAGE_DATA_H_ + +#include + +extern const int g_no_person_data_size; +extern const uint8_t g_no_person_data[]; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_NO_PERSON_IMAGE_DATA_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/person_detection/person_detect_model_data.h b/components/tflite/tensorflow/lite/micro/examples/person_detection/person_detect_model_data.h new file mode 100644 index 00000000..ab2b03a2 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/person_detection/person_detect_model_data.h @@ -0,0 +1,27 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// This is a standard TensorFlow Lite model file that has been converted into a +// C data array, so it can be easily compiled into a binary for devices that +// don't have a file system. It was created using the command: +// xxd -i person_detect.tflite > person_detect_model_data.cc + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_PERSON_DETECT_MODEL_DATA_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_PERSON_DETECT_MODEL_DATA_H_ + +extern const unsigned char g_person_detect_model_data[]; +extern const int g_person_detect_model_data_len; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_PERSON_DETECT_MODEL_DATA_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/person_detection/person_detection_binary_test.sh b/components/tflite/tensorflow/lite/micro/examples/person_detection/person_detection_binary_test.sh new file mode 100644 index 00000000..00d985d1 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/person_detection/person_detection_binary_test.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +# +# Bash unit tests for the example binary. + +set -e + +OUTPUT_LOG_FILE=${TEST_TMPDIR}/output_log.txt + +# Needed for copybara compatibility. +SCRIPT_BASE_DIR=/org_"tensor"flow +${TEST_SRCDIR}${SCRIPT_BASE_DIR}/tensorflow/lite/micro/examples/person_detection/person_detection 2>&1 | head > ${OUTPUT_LOG_FILE} + +if ! grep -q 'person score' ${OUTPUT_LOG_FILE}; then + echo "ERROR: Expected logs not found in output '${OUTPUT_LOG_FILE}'" + exit 1 +fi + +echo +echo "SUCCESS: person_detection_binary_test PASSED" diff --git a/components/tflite/tensorflow/lite/micro/examples/person_detection/person_detection_test.cc b/components/tflite/tensorflow/lite/micro/examples/person_detection/person_detection_test.cc new file mode 100644 index 00000000..b32130e4 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/person_detection/person_detection_test.cc @@ -0,0 +1,135 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/examples/person_detection/model_settings.h" +#include "tensorflow/lite/micro/examples/person_detection/no_person_image_data.h" +#include "tensorflow/lite/micro/examples/person_detection/person_detect_model_data.h" +#include "tensorflow/lite/micro/examples/person_detection/person_image_data.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/micro_interpreter.h" +#include "tensorflow/lite/micro/micro_mutable_op_resolver.h" +#include "tensorflow/lite/micro/testing/micro_test.h" +#include "tensorflow/lite/schema/schema_generated.h" + +// Create an area of memory to use for input, output, and intermediate arrays. +constexpr int tensor_arena_size = 136 * 1024; +uint8_t tensor_arena[tensor_arena_size]; + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestInvoke) +{ + // Set up logging. + tflite::MicroErrorReporter micro_error_reporter; + + // Map the model into a usable data structure. This doesn't involve any + // copying or parsing, it's a very lightweight operation. + const tflite::Model *model = ::tflite::GetModel(g_person_detect_model_data); + if (model->version() != TFLITE_SCHEMA_VERSION) { + TF_LITE_REPORT_ERROR(µ_error_reporter, + "Model provided is schema version %d not equal " + "to supported version %d.\n", + model->version(), TFLITE_SCHEMA_VERSION); + } + + // Pull in only the operation implementations we need. + // This relies on a complete list of all the ops needed by this graph. + // An easier approach is to just use the AllOpsResolver, but this will + // incur some penalty in code space for op implementations that are not + // needed by this graph. + tflite::MicroMutableOpResolver<5> micro_op_resolver; + micro_op_resolver.AddAveragePool2D(); + micro_op_resolver.AddConv2D(); + micro_op_resolver.AddDepthwiseConv2D(); + micro_op_resolver.AddReshape(); + micro_op_resolver.AddSoftmax(); + + // Build an interpreter to run the model with. + tflite::MicroInterpreter interpreter(model, micro_op_resolver, tensor_arena, + tensor_arena_size, + µ_error_reporter); + interpreter.AllocateTensors(); + + // Get information about the memory area to use for the model's input. + TfLiteTensor *input = interpreter.input(0); + + // Make sure the input has the properties we expect. + TF_LITE_MICRO_EXPECT_NE(nullptr, input); + TF_LITE_MICRO_EXPECT_EQ(4, input->dims->size); + TF_LITE_MICRO_EXPECT_EQ(1, input->dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(kNumRows, input->dims->data[1]); + TF_LITE_MICRO_EXPECT_EQ(kNumCols, input->dims->data[2]); + TF_LITE_MICRO_EXPECT_EQ(kNumChannels, input->dims->data[3]); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt8, input->type); + + // Copy an image with a person into the memory area used for the input. + TFLITE_DCHECK_EQ(input->bytes, static_cast(g_person_data_size)); + memcpy(input->data.int8, g_person_data, input->bytes); + + // Run the model on this input and make sure it succeeds. + TfLiteStatus invoke_status = interpreter.Invoke(); + if (invoke_status != kTfLiteOk) { + TF_LITE_REPORT_ERROR(µ_error_reporter, "Invoke failed\n"); + } + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, invoke_status); + + // Get the output from the model, and make sure it's the expected size and + // type. + TfLiteTensor *output = interpreter.output(0); + TF_LITE_MICRO_EXPECT_EQ(2, output->dims->size); + TF_LITE_MICRO_EXPECT_EQ(1, output->dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(kCategoryCount, output->dims->data[1]); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt8, output->type); + + // Make sure that the expected "Person" score is higher than the other class. + int8_t person_score = output->data.int8[kPersonIndex]; + int8_t no_person_score = output->data.int8[kNotAPersonIndex]; + TF_LITE_REPORT_ERROR(µ_error_reporter, + "person data. person score: %d, no person score: %d\n", + person_score, no_person_score); + TF_LITE_MICRO_EXPECT_GT(person_score, no_person_score); + + // TODO(b/161461076): Update model to make this work on real negative inputs. + memset(input->data.int8, 0, input->bytes); + + // Run the model on this "No Person" input. + invoke_status = interpreter.Invoke(); + if (invoke_status != kTfLiteOk) { + TF_LITE_REPORT_ERROR(µ_error_reporter, "Invoke failed\n"); + } + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, invoke_status); + + // Get the output from the model, and make sure it's the expected size and + // type. + output = interpreter.output(0); + TF_LITE_MICRO_EXPECT_EQ(2, output->dims->size); + TF_LITE_MICRO_EXPECT_EQ(1, output->dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(kCategoryCount, output->dims->data[1]); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt8, output->type); + + // Make sure that the expected "No Person" score is higher. + person_score = output->data.int8[kPersonIndex]; + no_person_score = output->data.int8[kNotAPersonIndex]; + TF_LITE_REPORT_ERROR( + µ_error_reporter, + "no person data. person score: %d, no person score: %d\n", person_score, + no_person_score); + TF_LITE_MICRO_EXPECT_GT(no_person_score, person_score); + + TF_LITE_REPORT_ERROR(µ_error_reporter, "Ran successfully\n"); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/examples/person_detection/person_image_data.h b/components/tflite/tensorflow/lite/micro/examples/person_detection/person_image_data.h new file mode 100644 index 00000000..d1313252 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/person_detection/person_image_data.h @@ -0,0 +1,30 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// This data was created from a sample image from with a person in it. +// Convert original image to simpler format: +// convert -resize 96x96\! person.PNG person.bmp3 +// Skip the 54 byte bmp3 header and add the reset of the bytes to a C array: +// xxd -s 54 -i /tmp/person.bmp3 > /tmp/person.cc + +#ifndef TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_PERSON_IMAGE_DATA_H_ +#define TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_PERSON_IMAGE_DATA_H_ + +#include + +extern const int g_person_data_size; +extern const uint8_t g_person_data[]; + +#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_PERSON_DETECTION_PERSON_IMAGE_DATA_H_ diff --git a/components/tflite/tensorflow/lite/micro/examples/person_detection/training_a_model.md b/components/tflite/tensorflow/lite/micro/examples/person_detection/training_a_model.md new file mode 100644 index 00000000..81ac39bb --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/person_detection/training_a_model.md @@ -0,0 +1,455 @@ +## Training a model + +The following document will walk you through the process of training your own +250 KB embedded vision model using scripts that are easy to run. You can use +either the [Visual Wake Words dataset](https://arxiv.org/abs/1906.05721) for +person detection, or choose one of the [80 +categories from the MSCOCO dataset](http://cocodataset.org/#explore). + +This model will take several days to train on a powerful machine with GPUs. We +recommend using a [Google Cloud Deep +Learning VM](https://cloud.google.com/deep-learning-vm/). + +### Training framework choice + +Keras is the recommended interface for building models in TensorFlow, but when +the person detector model was being created it didn't yet support all the +features we needed. For that reason, we'll be showing you how to train a model +using tf.slim, an older interface. It is still widely used but deprecated, so +future versions of TensorFlow may not support this approach. We hope to publish +Keras instructions in the future. + +The model definitions for Slim are part of the +[TensorFlow models repository](https://github.com/tensorflow/models), so to get +started you'll need to download it from GitHub using a command like this: + +``` +! cd ~ +! git clone https://github.com/tensorflow/models.git +``` + +The following guide is going to assume that you've done this from your home +directory, so the model repository code is at ~/models, and that all commands +are run from the home directory too unless otherwise noted. You can place the +repository somewhere else, but you'll need to update all references to it. + +To use Slim, you'll need to make sure its modules can be found by Python, and +install one dependency. Here's how to do this in an iPython notebook: + +``` +! pip install contextlib2 +import os +new_python_path = (os.environ.get("PYTHONPATH") or '') + ":models/research/slim" +%env PYTHONPATH=$new_python_path +``` + +Updating `PYTHONPATH` through an `EXPORT` statement like this only works for the +current Jupyter session, so if you're using bash directly, you should add it to +a persistent startup script, running something like this: + +``` +echo 'export PYTHONPATH=$PYTHONPATH:models/research/slim' >> ~/.bashrc +source ~/.bashrc +``` + +If you see import errors running the slim scripts, you should make sure the +`PYTHONPATH` is set up correctly, and that contextlib2 has been installed. You +can find more general information on tf.slim in the +[repository's +README](https://github.com/tensorflow/models/tree/master/research/slim). + +### Building the dataset + +In order to train a person detector model, we need a large collection of images +that are labeled depending on whether or not they have people in them. The +ImageNet one-thousand class data that's widely used for training image +classifiers doesn't include labels for people, but luckily the +[COCO dataset](http://cocodataset.org/#home) does. You can also download this +data without manually registering too, and Slim provides a convenient script to +grab it automatically: + +``` +! chmod +x models/research/slim/datasets/download_mscoco.sh +! bash models/research/slim/datasets/download_mscoco.sh coco +``` + +This is a large download, about 40GB, so it will take a while and you'll need +to make sure you have at least 100GB free on your drive to allow space for +unpacking and further processing. The argument to the script is the path that +the data will be downloaded to. If you change this, you'll also need to update +the commands below that use it. + +The dataset is designed to be used for training models for localization, so the +images aren't labeled with the "contains a person", "doesn't contain a person" +categories that we want to train for. Instead each image comes with a list of +bounding boxes for all of the objects it contains. "Person" is one of these +object categories, so to get to the classification labels we want, we have to +look for images with bounding boxes for people. To make sure that they aren't +too tiny to be recognizable we also need to exclude very small bounding boxes. +Slim contains a script to convert the bounding box into labels: + +``` +! python models/research/slim/datasets/build_visualwakewords_data.py +--logtostderr \ +--train_image_dir=coco/raw-data/train2014 \ +--val_image_dir=coco/raw-data/val2014 \ +--train_annotations_file=coco/raw-data/annotations/instances_train2014.json \ +--val_annotations_file=coco/raw-data/annotations/instances_val2014.json \ +--output_dir=coco/processed \ +--small_object_area_threshold=0.005 \ +--foreground_class_of_interest='person' +``` + +Don't be surprised if this takes up to twenty minutes to complete. When it's +done, you'll have a set of TFRecords in `coco/processed` holding the labeled +image information. This data was created by Aakanksha Chowdhery and is known as +the [Visual Wake Words dataset](https://arxiv.org/abs/1906.05721). It's designed +to be useful for benchmarking and testing embedded computer vision, since it +represents a very common task that we need to accomplish with tight resource +constraints. We're hoping to see it drive even better models for this and +similar tasks. + +### Training the model + +One of the nice things about using tf.slim to handle the training is that the +parameters you commonly need to modify are available as command line arguments, +so we can just call the standard `train_image_classifier.py` script to train +our model. You can use this command to build the model we use in the example: + +``` +! python models/research/slim/train_image_classifier.py \ + --train_dir=vww_96_grayscale \ + --dataset_name=visualwakewords \ + --dataset_split_name=train \ + --dataset_dir=coco/processed \ + --model_name=mobilenet_v1_025 \ + --preprocessing_name=mobilenet_v1 \ + --train_image_size=96 \ + --input_grayscale=True \ + --save_summaries_secs=300 \ + --learning_rate=0.045 \ + --label_smoothing=0.1 \ + --learning_rate_decay_factor=0.98 \ + --num_epochs_per_decay=2.5 \ + --moving_average_decay=0.9999 \ + --batch_size=96 \ + --max_number_of_steps=1000000 +``` + +This will take a couple of days on a single-GPU v100 instance to complete all +one-million steps, but you should be able to get a fairly accurate model after +a few hours if you want to experiment early. + +- The checkpoints and summaries will the saved in the folder given in the + `--train_dir` argument, so that's where you'll have to look for the results. +- The `--dataset_dir` parameter should match the one where you saved the + TFRecords from the Visual Wake Words build script. +- The architecture we'll be using is defined by the `--model_name` argument. + The 'mobilenet_v1' prefix tells the script to use the first version of + MobileNet. We did experiment with later versions, but these used more RAM + for their intermediate activation buffers, so for now we kept with the + original. The '025' is the depth multiplier to use, which mostly affects the + number of weight parameters, this low setting ensures the model fits within + 250KB of Flash. +- `--preprocessing_name` controls how input images are modified before they're + fed into the model. The 'mobilenet_v1' version shrinks the width and height + of the images to the size given in `--train_image_size` (in our case 96 + pixels since we want to reduce the compute requirements). It also scales the + pixel values from 0 to 255 integers into -1.0 to +1.0 floating point numbers + (though we'll be quantizing those after training). +- The + [HM01B0](https://himax.com.tw/products/cmos-image-sensor/image-sensors/hm01b0/) + camera we're using on the SparkFun Edge board is monochrome, so to get the + best results we have to train our model on black and white images too, so we + pass in the `--input_grayscale` flag to enable that preprocessing. +- The `--learning_rate`, `--label_smoothing`, `--learning_rate_decay_factor`, + `--num_epochs_per_decay`, `--moving_average_decay` and `--batch_size` are + all parameters that control how weights are updated during the training + process. Training deep networks is still a bit of a dark art, so these exact + values we found through experimentation for this particular model. You can + try tweaking them to speed up training or gain a small boost in accuracy, + but we can't give much guidance for how to make those changes, and it's easy + to get combinations where the training accuracy never converges. +- The `--max_number_of_steps` defines how long the training should continue. + There's no good way to figure out this threshold in advance, you have to + experiment to tell when the accuracy of the model is no longer improving to + tell when to cut it off. In our case we default to a million steps, since + with this particular model we know that's a good point to stop. + +Once you start the script, you should see output that looks something like this: + +``` +INFO:tensorflow:global step 4670: loss = 0.7112 (0.251 sec/step) +I0928 00:16:21.774756 140518023943616 learning.py:507] global step 4670: loss = +0.7112 (0.251 sec/step) +INFO:tensorflow:global step 4680: loss = 0.6596 (0.227 sec/step) +I0928 00:16:24.365901 140518023943616 learning.py:507] global step 4680: loss = +0.6596 (0.227 sec/step) +``` + +Don't worry about the line duplication, this is just a side-effect of the way +TensorFlow log printing interacts with Python. Each line has two key bits of +information about the training process. The global step is a count of how far +through the training we are. Since we've set the limit as a million steps, in +this case we're nearly five percent complete. The steps per second estimate is +also useful, since you can use it to estimate a rough duration for the whole +training process. In this case, we're completing about four steps a second, so +a million steps will take about 70 hours, or three days. The other crucial +piece of information is the loss. This is a measure of how close the +partially-trained model's predictions are to the correct values, and lower +values are better. This will show a lot of variation but should on average +decrease during training if the model is learning. Because it's so noisy, the +amounts will bounce around a lot over short time periods, but if things are +working well you should see a noticeable drop if you wait an hour or so and +check back. This kind of variation is a lot easier to see in a graph, which is +one of the main reasons to try TensorBoard. + +### TensorBoard + +TensorBoard is a web application that lets you view data visualizations from +TensorFlow training sessions, and it's included by default in most cloud +instances. If you're using Google Cloud's AI Platform, you can start up a new +TensorBoard session by open the command palette from the left tabs on the +notebook interface, and scrolling down to select "Create a new tensorboard". +You'll be prompted for the location of the summary logs, enter the path you +used for `--train_dir` in the training script, in our example +'vww_96_grayscale'. One common error to watch out for is adding a slash to the +end of the path, which will cause tensorboard to fail to find the directory. If +you're starting tensorboard from the command line in a different environment +you'll have to pass in this path as the `--logdir` argument to the tensorboard +command line tool, and point your browser to http://localhost:6006 (or the +address of the machine you're running it on). + +It may take a little while for the graphs to have anything useful in them, since +the script only saves summaries every five minutes. The most important graph is +called 'clone_loss', and this shows the progression of the same loss value +that's displayed on the logging output. It fluctuates a lot, but the +overall trend is downwards over time. If you don't see this sort of progression +after a few hours of training, it's a good sign that your model isn't +converging to a good solution, and you may need to debug what's going wrong +either with your dataset or the training parameters. + +Tensorboard defaults to the 'Scalars' tab when it opens, but the other section +that can be useful during training is 'Images'. This shows a +random selection of the pictures the model is currently being trained on, +including any distortions and other preprocessing. This information isn't as +essential as the loss graphs, but it can be useful to ensure the dataset is what +you expect, and it is interesting to see the examples updating as training +progresses. + +### Evaluating the model + +The loss function correlates with how well your model is training, but it isn't +a direct, understandable metric. What we really care about is how many people +our model detects correctly, but to get calculate this we need to run a +separate script. You don't need to wait until the model is fully trained, you +can check the accuracy of any checkpoints in the `--train_dir` folder. + +``` +! python models/research/slim/eval_image_classifier.py \ + --alsologtostderr \ + --checkpoint_path=vww_96_grayscale/model.ckpt-698580 \ + --dataset_dir=coco/processed/ \ + --dataset_name=visualwakewords \ + --dataset_split_name=val \ + --model_name=mobilenet_v1_025 \ + --preprocessing_name=mobilenet_v1 \ + --input_grayscale=True \ + --train_image_size=96 +``` + +You'll need to make sure that `--checkpoint_path` is pointing to a valid set of +checkpoint data. Checkpoints are stored in three separate files, so the value +should be their common prefix. For example if you have a checkpoint file called +'model.ckpt-5179.data-00000-of-00001', the prefix would be 'model.ckpt-5179'. +The script should produce output that looks something like this: + +``` +INFO:tensorflow:Evaluation [406/406] +I0929 22:52:59.936022 140225887045056 evaluation.py:167] Evaluation [406/406] +eval/Accuracy[0.717438412]eval/Recall_5[1] +``` + +The important number here is the accuracy. It shows the proportion of the +images that were classified correctly, which is 72% in this case, after +converting to a percentage. If you follow the example script, you should expect +a fully-trained model to achieve an accuracy of around 84% after one million +steps, and show a loss of around 0.4. + +### Exporting the model to TensorFlow Lite + +When the model has trained to an accuracy you're happy with, you'll need to +convert the results from the TensorFlow training environment into a form you +can run on an embedded device. As we've seen in previous chapters, this can be +a complex process, and tf.slim adds a few of its own wrinkles too. + +#### Exporting to a GraphDef protobuf file + +Slim generates the architecture from the model_name every time one of its +scripts is run, so for a model to be used outside of Slim it needs to be saved +in a common format. We're going to use the GraphDef protobuf serialization +format, since that's understood by both Slim and the rest of TensorFlow. + +``` +! python models/research/slim/export_inference_graph.py \ + --alsologtostderr \ + --dataset_name=visualwakewords \ + --model_name=mobilenet_v1_025 \ + --image_size=96 \ + --input_grayscale=True \ + --output_file=vww_96_grayscale_graph.pb +``` + +If this succeeds, you should have a new 'vww_96_grayscale_graph.pb' file in +your home folder. This contains the layout of the operations in the model, but +doesn't yet have any of the weight data. + +#### Freezing the weights + +The process of storing the trained weights together with the operation graph is +known as freezing. This converts all of the variables in the graph to +constants, after loading their values from a checkpoint file. The command below +uses a checkpoint from the millionth training step, but you can supply any +valid checkpoint path. The graph freezing script is stored inside the main +tensorflow repository, so we have to download this from GitHub before running +this command. + +``` +! git clone https://github.com/tensorflow/tensorflow +! python tensorflow/tensorflow/python/tools/freeze_graph.py \ +--input_graph=vww_96_grayscale_graph.pb \ +--input_checkpoint=vww_96_grayscale/model.ckpt-1000000 \ +--input_binary=true --output_graph=vww_96_grayscale_frozen.pb \ +--output_node_names=MobilenetV1/Predictions/Reshape_1 +``` + +After this, you should see a file called 'vww_96_grayscale_frozen.pb'. + +#### Quantizing and converting to TensorFlow Lite + +Quantization is a tricky and involved process, and it's still very much an +active area of research, so taking the float graph that we've trained so far +and converting it down to eight bit takes quite a bit of code. You can find +more of an explanation of what quantization is and how it works in the chapter +on latency optimization, but here we'll show you how to use it with the model +we've trained. The majority of the code is preparing example images to feed +into the trained network, so that the ranges of the activation layers in +typical use can be measured. We rely on the TFLiteConverter class to handle the +quantization and conversion into the TensorFlow Lite flatbuffer file that we +need for the inference engine. + +``` +import tensorflow as tf +import io +import PIL +import numpy as np + +def representative_dataset_gen(): + + record_iterator = +tf.python_io.tf_record_iterator(path='coco/processed/val.record-00000-of-00010') + + count = 0 + for string_record in record_iterator: + example = tf.train.Example() + example.ParseFromString(string_record) + image_stream = +io.BytesIO(example.features.feature['image/encoded'].bytes_list.value[0]) + image = PIL.Image.open(image_stream) + image = image.resize((96, 96)) + image = image.convert('L') + array = np.array(image) + array = np.expand_dims(array, axis=2) + array = np.expand_dims(array, axis=0) + array = ((array / 127.5) - 1.0).astype(np.float32) + yield([array]) + count += 1 + if count > 300: + break + +converter = +tf.lite.TFLiteConverter.from_frozen_graph('vww_96_grayscale_frozen.pb', +['input'], ['MobilenetV1/Predictions/Reshape_1']) +converter.optimizations = [tf.lite.Optimize.DEFAULT] +converter.representative_dataset = representative_dataset_gen +converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8] +converter.inference_input_type = tf.int8 +converter.inference_output_type = tf.int8 + +tflite_quant_model = converter.convert() +open("vww_96_grayscale_quantized.tflite", "wb").write(tflite_quant_model) +``` + +#### Converting into a C source file + +The converter writes out a file, but most embedded devices don't have a file +system. To access the serialized data from our program, we have to compile it +into the executable and store it in Flash. The easiest way to do that is to +convert the file into a C data array. + +``` +# Install xxd if it is not available +!apt-get -qq install xxd +# Save the file as a C source file +!xxd -i vww_96_grayscale_quantized.tflite > person_detect_model_data.cc +``` + +You can now replace the existing person_detect_model_data.cc file with the +version you've trained, and be able to run your own model on embedded devices. + +### Training for other categories + +There are over 60 different object types in the MS-COCO dataset, so an easy way +to customize your model would be to choose one of those instead of 'person' +when you build the training dataset. Here's an example that looks for cars: + +``` +! python models/research/slim/datasets/build_visualwakewords_data.py +--logtostderr \ +--train_image_dir=coco/raw-data/train2014 \ +--val_image_dir=coco/raw-data/val2014 \ +--train_annotations_file=coco/raw-data/annotations/instances_train2014.json \ +--val_annotations_file=coco/raw-data/annotations/instances_val2014.json \ +--output_dir=coco/processed_cars \ +--small_object_area_threshold=0.005 \ +--foreground_class_of_interest='car' +``` + +You should be able to follow the same steps you did for the person detector, +but substitute the new 'coco/processed_cars' path wherever 'coco/processed' +used to be. + +If the kind of object you're interested in isn't present in MS-COCO, you may be +able to use transfer learning to help you train on a custom dataset you've +gathered, even if it's much smaller. We don't have an example of this +yet, but we hope to share one soon. + +### Understanding the architecture + +[MobileNets](https://arxiv.org/abs/1704.04861) are a family of architectures +designed to provide good accuracy for as few weight parameters and arithmetic +operations as possible. There are now multiple versions, but in our case we're +using the original v1 since it required the smallest amount of RAM at runtime. +The core concept behind the architecture is depthwise separable convolution. +This is a variant of classical two-dimensional convolutions that works in a +much more efficient way, without sacrificing very much accuracy. Regular +convolution calculates an output value based on applying a filter of a +particular size across all channels of the input. This means the number of +calculations involved in each output is width of the filter multiplied by +height, multiplied by the number of input channels. Depthwise convolution +breaks this large calculation into separate parts. First each input channel is +filtered by one or more rectangular filters to produce intermediate values. +These values are then combined using pointwise convolutions. This dramatically +reduces the number of calculations needed, and in practice produces similar +results to regular convolution. + +MobileNet v1 is a stack of 14 of these depthwise separable convolution layers +with an average pool, then a fully-connected layer followed by a softmax at the +end. We've specified a 'width multiplier' of 0.25, which has the effect of +reducing the number of computations down to around 60 million per inference, by +shrinking the number of channels in each activation layer by 75% compared to +the standard model. In essence it's very similar to a normal convolutional +neural network in operation, with each layer learning patterns in the input. +Earlier layers act more like edge recognition filters, spotting low-level +structure in the image, and later layers synthesize that information into more +abstract patterns that help with the final object classification. diff --git a/components/tflite/tensorflow/lite/micro/examples/person_detection/utils/raw_to_bitmap.py b/components/tflite/tensorflow/lite/micro/examples/person_detection/utils/raw_to_bitmap.py new file mode 100644 index 00000000..4ebb8490 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/person_detection/utils/raw_to_bitmap.py @@ -0,0 +1,200 @@ +# Copyright 2019 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +"""Convert raw bytes to a bitmap. + +Converts a raw image dumped to a file into a bitmap. The file must contain +complete bitmap images in 324 x 244 resolution, formatted as follows: + ++++ frame +++ + <16 one-byte values separated by spaces> +--- frame --- + +For example, the first line might look like: +0x00000000 C5 C3 CE D1 D9 DA D6 E3 E2 EB E9 EB DB E4 F5 FF + +The bitmaps are automatically saved to the same directory as the log file, and +are displayed by the script. +""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import argparse +import os +import os.path +import re + +import numpy as np + +_DICT_RESOLUTIONS = { + 'QVGA': (324, 244, 1), + 'GRAY': (96, 96, 1), + 'RGB': (96, 96, 3), +} + +_VERSION = 0 +_SUBVERSION = 1 + + +def check_file_existence(x): + if not os.path.isfile(x): + # Argparse uses the ArgumentTypeError to give a rejection message like: + # error: argument input: x does not exist + raise argparse.ArgumentTypeError('{0} does not exist'.format(x)) + return x + + +def show_and_save_bitmaps(input_file, bitmap_list, channels): + """Display and save a list of bitmaps. + + Args: + input_file: input file name + bitmap_list: list of numpy arrays to represent bitmap images + channels: color channel count + """ + try: + from PIL import Image # pylint: disable=g-import-not-at-top + except ImportError: + raise NotImplementedError('Image display and save not implemented.') + + for idx, bitmap in enumerate(bitmap_list): + path = os.path.dirname(os.path.abspath(input_file)) + basename = os.path.split(os.path.splitext(input_file)[0])[-1] + outputfile = os.path.join(path, basename + '_' + str(idx) + '.bmp') + + if channels == 3: + img = Image.fromarray(bitmap, 'RGB') + else: + img = Image.fromarray(bitmap, 'L') + + img.save(outputfile) + img.show() + + +def reshape_bitmaps(frame_list, width, height, channels): + """Reshape flat integer arrays. + + Args: + frame_list: list of 1-D arrays to represent raw image data + width: image width in pixels + height: image height in pixels + channels: color channel count + + Returns: + list of numpy arrays to represent bitmap images + """ + + bitmap_list = [] + for frame in frame_list: + shape = (height, width, channels) if channels > 1 else (height, width) + bitmap = np.reshape(frame, shape) + bitmap = np.flip(bitmap, 0) + bitmap_list.append(bitmap) + return bitmap_list + + +def parse_file(inputfile, width, height, channels): + """Convert log file to array of pixels. + + Args: + inputfile: log file to parse + width: image width in pixels + height: image height in pixels + channels: color channel count + + Returns: + list 1-D arrays to represent raw image data. + """ + + data = None + bytes_written = 0 + frame_start = False + frame_stop = False + frame_list = list() + + # collect all pixel data into an int array + for line in inputfile: + if line == '+++ frame +++\n': + frame_start = True + data = np.zeros(height * width * channels, dtype=np.uint8) + bytes_written = 0 + continue + elif line == '--- frame ---\n': + frame_stop = True + + if frame_start and not frame_stop: + linelist = re.findall(r"[\w']+", line) + + if len(linelist) != 17: + # drop this frame + frame_start = False + continue + + for item in linelist[1:]: + data[bytes_written] = int(item, base=16) + bytes_written += 1 + + elif frame_start and frame_stop: + if bytes_written == height * width * channels: + frame_list.append(data) + frame_start = False + frame_stop = False + + return frame_list + + +def main(): + parser = argparse.ArgumentParser( + description='This program converts raw data from HM01B0 to a bmp file.') + + parser.add_argument( + '-i', + '--input', + dest='inputfile', + required=True, + help='input file', + metavar='FILE', + type=check_file_existence) + + parser.add_argument( + '-r', + '--resolution', + dest='resolution', + required=False, + help='Resolution', + choices=['QVGA', 'RGB', 'GRAY'], + default='QVGA', + ) + + parser.add_argument( + '-v', + '--version', + help='Program version', + action='version', + version='%(prog)s {ver}'.format(ver='v%d.%d' % (_VERSION, _SUBVERSION))) + + args = parser.parse_args() + + (width, height, + channels) = _DICT_RESOLUTIONS.get(args.resolution, + ('Resolution not supported', 0, 0, 0)) + frame_list = parse_file(open(args.inputfile), width, height, channels) + bitmap_list = reshape_bitmaps(frame_list, width, height, channels) + show_and_save_bitmaps(args.inputfile, bitmap_list, channels) + + +if __name__ == '__main__': + main() diff --git a/components/tflite/tensorflow/lite/micro/examples/person_detection/utils/raw_to_bitmap_test.py b/components/tflite/tensorflow/lite/micro/examples/person_detection/utils/raw_to_bitmap_test.py new file mode 100644 index 00000000..ade895d6 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/examples/person_detection/utils/raw_to_bitmap_test.py @@ -0,0 +1,120 @@ +# Copyright 2018 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +"""Tests for raw to bitmap converter utility.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import io + +import numpy as np + +from tensorflow.lite.micro.examples.person_detection.utils.raw_to_bitmap import parse_file +from tensorflow.lite.micro.examples.person_detection.utils.raw_to_bitmap import reshape_bitmaps +from tensorflow.python.platform import googletest + +_RGB_RAW = u""" ++++ frame +++ +0x0000 0x00 0x00 0x00 0x01 0x01 0x01 0x02 0x02 0x02 0x03 0x03 0x03 0x04 0x04 0x04 0x05 +0x0010 0x05 0x05 0x06 0x06 0x06 0x07 0x07 0x07 0x08 0x08 0x08 0x09 0x09 0x09 0x0a 0x0a +0x0020 0x0a 0x0b 0x0b 0x0b 0x0c 0x0c 0x0c 0x0d 0x0d 0x0d 0x0e 0x0e 0x0e 0x0f 0x0f 0x0f +--- frame --- +""" + +_RGB_FLAT = np.array([[ + 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, + 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, + 15, 15, 15 +]]) + +_RGB_RESHAPED = np.array([[[[12, 12, 12], [13, 13, 13], [14, 14, 14], + [15, 15, 15]], + [[8, 8, 8], [9, 9, 9], [10, 10, 10], [11, 11, 11]], + [[4, 4, 4], [5, 5, 5], [6, 6, 6], [7, 7, 7]], + [[0, 0, 0], [1, 1, 1], [2, 2, 2], [3, 3, 3]]]]) + +_GRAYSCALE_RAW = u""" ++++ frame +++ +0x0000 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f +--- frame --- +""" + +_GRAYSCALE_FLAT = np.array( + [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]]) + +_GRAYSCALE_RESHAPED = np.array([[[12, 13, 14, 15], [8, 9, 10, 11], [4, 5, 6, 7], + [0, 1, 2, 3]]]) + +_GRAYSCALE_RAW_MULTI = u""" ++++ frame +++ +0x0000 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f +--- frame --- ++++ frame +++ +0x0000 0x10 0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 0x1a 0x1b 0x1c 0x1d 0x1e 0x1f +--- frame --- ++++ frame +++ +0x0000 0x20 0x21 0x22 0x23 0x24 0x25 0x26 0x27 0x28 0x29 0x2a 0x2b 0x2c 0x2d 0x2e 0x2f +--- frame --- ++++ frame +++ +0x0000 0x30 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x3a 0x3b 0x3c 0x3d 0x3e 0x3f +--- frame --- +""" + +_GRAYSCALE_FLAT_MULTI = [ + np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]), + np.array([16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]), + np.array([32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47]), + np.array([48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]) +] + +_GRAYSCALE_RESHAPED_MULTI = [ + np.array([[12, 13, 14, 15], [8, 9, 10, 11], [4, 5, 6, 7], [0, 1, 2, 3]]), + np.array([[28, 29, 30, 31], [24, 25, 26, 27], [20, 21, 22, 23], + [16, 17, 18, 19]]), + np.array([[44, 45, 46, 47], [40, 41, 42, 43], [36, 37, 38, 39], + [32, 33, 34, 35]]), + np.array([[60, 61, 62, 63], [56, 57, 58, 59], [52, 53, 54, 55], + [48, 49, 50, 51]]) +] + + +class RawToBitmapTest(googletest.TestCase): + + def test_parse_rgb(self): + frame_list = parse_file(io.StringIO(_RGB_RAW), 4, 4, 3) + self.assertTrue(np.array_equal(_RGB_FLAT, frame_list)) + + def test_parse_grayscale(self): + frame_list = parse_file(io.StringIO(_GRAYSCALE_RAW), 4, 4, 1) + self.assertTrue(np.array_equal(_GRAYSCALE_FLAT, frame_list)) + + def test_reshape_rgb(self): + reshaped = reshape_bitmaps(_RGB_FLAT, 4, 4, 3) + self.assertTrue(np.array_equal(_RGB_RESHAPED, reshaped)) + + def test_reshape_grayscale(self): + reshaped = reshape_bitmaps(_GRAYSCALE_FLAT, 4, 4, 1) + self.assertTrue(np.array_equal(_GRAYSCALE_RESHAPED, reshaped)) + + def test_multiple_grayscale(self): + frame_list = parse_file(io.StringIO(_GRAYSCALE_RAW_MULTI), 4, 4, 1) + self.assertTrue(np.array_equal(_GRAYSCALE_FLAT_MULTI, frame_list)) + reshaped = reshape_bitmaps(frame_list, 4, 4, 1) + self.assertTrue(np.array_equal(_GRAYSCALE_RESHAPED_MULTI, reshaped)) + + +if __name__ == '__main__': + googletest.main() diff --git a/components/tflite/tensorflow/lite/micro/kernels/README.md b/components/tflite/tensorflow/lite/micro/kernels/README.md new file mode 100644 index 00000000..fa18bcfe --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/README.md @@ -0,0 +1,5 @@ +# Info + +* [Porting Ops from Lite to Micro](../docs/porting_reference_ops.md) explains, + step-by-step, the code changes necessary to port an op from lite to micro, + and the process of submitting them for review and acceptance by the project. diff --git a/components/tflite/tensorflow/lite/micro/kernels/activation_utils.h b/components/tflite/tensorflow/lite/micro/kernels/activation_utils.h new file mode 100644 index 00000000..3d356471 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/activation_utils.h @@ -0,0 +1,57 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_KERNELS_ACTIVATION_UTILS_H_ +#define TENSORFLOW_LITE_MICRO_KERNELS_ACTIVATION_UTILS_H_ + +#include +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/kernels/internal/cppmath.h" +#include "tensorflow/lite/kernels/internal/max.h" +#include "tensorflow/lite/kernels/internal/min.h" + +namespace tflite { +namespace ops { +namespace micro { +// Returns the floating point value for a fused activation: +inline float ActivationValFloat(TfLiteFusedActivation act, float a) +{ + switch (act) { + case kTfLiteActNone: + return a; + case kTfLiteActRelu: + return TfLiteMax(0.0f, a); + case kTfLiteActReluN1To1: + return TfLiteMax(-1.0f, TfLiteMin(a, 1.0f)); + case kTfLiteActRelu6: + return TfLiteMax(0.0f, TfLiteMin(a, 6.0f)); + case kTfLiteActTanh: + return std::tanh(a); + case kTfLiteActSignBit: + return std::signbit(a); + case kTfLiteActSigmoid: + return 1.0f / (1.0f + std::exp(-a)); + } + return 0.0f; // To indicate an unsupported activation (i.e. when a new fused + // activation is added to the enum and not handled here). +} + +} // namespace micro +} // namespace ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_KERNELS_ACTIVATION_UTILS_H_ diff --git a/components/tflite/tensorflow/lite/micro/kernels/activations.cc b/components/tflite/tensorflow/lite/micro/kernels/activations.cc new file mode 100644 index 00000000..1690ea2c --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/activations.cc @@ -0,0 +1,298 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/internal/types.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/micro_utils.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace activations { +namespace { + +struct ReluOpData { + ReluParams params; +}; + +struct Relu6OpData { + int8_t six_int8; + int8_t zero_int8; + uint8_t six_uint8; + uint8_t zero_uint8; +}; + +} // namespace + +constexpr int kInputTensor = 0; +constexpr int kOutputTensor = 0; + +template +inline void ReluQuantized(const ReluOpData &data, + const RuntimeShape &input_shape, + const RuntimeShape &output_shape, const T *input_data, + T *output_data) +{ + const int flat_size = MatchingFlatSize(input_shape, output_shape); + for (int i = 0; i < flat_size; ++i) { + const int32_t val = static_cast(input_data[i]); + int32_t clamped = + data.params.output_offset + + MultiplyByQuantizedMultiplier(val - data.params.input_offset, + data.params.output_multiplier, + data.params.output_shift); + clamped = std::max(data.params.quantized_activation_min, clamped); + clamped = std::min(data.params.quantized_activation_max, clamped); + output_data[i] = static_cast(clamped); + } +} + +template +inline void CalculateReluOpData(const TfLiteTensor *input, TfLiteTensor *output, + ReluOpData *data) +{ + float act_min = 0.0; + float act_max = std::numeric_limits::infinity(); + double real_multiplier = + static_cast(input->params.scale / output->params.scale); + + const RuntimeShape input_shape = GetTensorShape(input); + const RuntimeShape output_shape = GetTensorShape(output); + + QuantizeMultiplier(real_multiplier, &data->params.output_multiplier, + &data->params.output_shift); + + data->params.quantized_activation_min = std::max( + static_cast(std::numeric_limits::min()), + output->params.zero_point + + static_cast(roundf(act_min / output->params.scale))); + data->params.quantized_activation_max = + act_max == std::numeric_limits::infinity() ? static_cast(std::numeric_limits::max()) : std::min(static_cast(std::numeric_limits::max()), output->params.zero_point + static_cast(roundf(act_max / output->params.scale))); + data->params.input_offset = input->params.zero_point; + data->params.output_offset = output->params.zero_point; +} + +inline void ReluFloat(const RuntimeShape &input_shape, const float *input_data, + const RuntimeShape &output_shape, float *output_data) +{ + const int flat_size = MatchingFlatSize(input_shape, output_shape); + for (int i = 0; i < flat_size; ++i) { + const float val = input_data[i]; + const float lower = 0.0f; + const float clamped = val < lower ? lower : val; + output_data[i] = clamped; + } +} + +inline void Relu6Float(const RuntimeShape &input_shape, const float *input_data, + const RuntimeShape &output_shape, float *output_data) +{ + const int flat_size = MatchingFlatSize(input_shape, output_shape); + for (int i = 0; i < flat_size; ++i) { + const float val = input_data[i]; + const float upper = 6.0f; + const float lower = 0.0f; + const float clamped = val > upper ? upper : val < lower ? lower : + val; + output_data[i] = clamped; + } +} + +template +inline void Relu6Quantized(Q lower, Q upper, const RuntimeShape &input_shape, + const Q *input_data, + const RuntimeShape &output_shape, Q *output_data) +{ + const int flat_size = MatchingFlatSize(input_shape, output_shape); + for (int i = 0; i < flat_size; ++i) { + const Q val = input_data[i]; + const Q clamped = val > upper ? upper : val < lower ? lower : + val; + output_data[i] = clamped; + } +} + +void *ReluInit(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(ReluOpData)); +} + +TfLiteStatus ReluPrepare(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + ReluOpData *data = static_cast(node->user_data); + + const TfLiteTensor *input = GetInput(context, node, kInputTensor); + TF_LITE_ENSURE(context, input != nullptr); + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + + if (input->type == kTfLiteInt8) { + CalculateReluOpData(input, output, data); + } else if (input->type == kTfLiteUInt8) { + CalculateReluOpData(input, output, data); + } + + return kTfLiteOk; +} + +TfLiteStatus ReluEval(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + const ReluOpData &data = *(static_cast(node->user_data)); + + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + switch (input->type) { + case kTfLiteFloat32: { + ReluFloat(tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + + return kTfLiteOk; + } + case kTfLiteInt8: { + ReluQuantized(data, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorData(output)); + return kTfLiteOk; + } + case kTfLiteUInt8: { + ReluQuantized(data, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorData(output)); + return kTfLiteOk; + } + default: { + TF_LITE_KERNEL_LOG(context, "Only float32 is supported currently, got %s", + TfLiteTypeGetName(input->type)); + return kTfLiteError; + } + } +} + +void *Relu6Init(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(Relu6OpData)); +} + +TfLiteStatus Relu6Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + Relu6OpData *data = static_cast(node->user_data); + + const TfLiteTensor *input = GetInput(context, node, kInputTensor); + TF_LITE_ENSURE(context, input != nullptr); + + if (input->type == kTfLiteInt8) { + data->six_int8 = FloatToQuantizedType(6.0f, input->params.scale, + input->params.zero_point); + data->zero_int8 = input->params.zero_point; + } else if (input->type == kTfLiteUInt8) { + data->six_uint8 = FloatToQuantizedType(6.0f, input->params.scale, + input->params.zero_point); + data->zero_uint8 = input->params.zero_point; + } + + return kTfLiteOk; +} + +TfLiteStatus Relu6Eval(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + const Relu6OpData &data = *(static_cast(node->user_data)); + + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + switch (input->type) { + case kTfLiteFloat32: { + Relu6Float(tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + + return kTfLiteOk; + } + case kTfLiteInt8: { + Relu6Quantized(data.zero_int8, data.six_int8, + tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + return kTfLiteOk; + } + case kTfLiteUInt8: { + Relu6Quantized(data.zero_uint8, data.six_uint8, + tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + return kTfLiteOk; + } + default: { + TF_LITE_KERNEL_LOG(context, "Only float32 is supported currently, got %s", + TfLiteTypeGetName(input->type)); + return kTfLiteError; + } + } +} + +} // namespace activations + +TfLiteRegistration Register_RELU() +{ + return { /*init=*/activations::ReluInit, + /*free=*/nullptr, + /*prepare=*/activations::ReluPrepare, + /*invoke=*/activations::ReluEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +TfLiteRegistration Register_RELU6() +{ + return { /*init=*/activations::Relu6Init, + /*free=*/nullptr, + /*prepare=*/activations::Relu6Prepare, + /*invoke=*/activations::Relu6Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/activations_test.cc b/components/tflite/tensorflow/lite/micro/kernels/activations_test.cc new file mode 100644 index 00000000..1a4cd893 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/activations_test.cc @@ -0,0 +1,407 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +void TestReluFloat(int *input_dims_data, const float *input_data, + int *output_dims_data, const float *golden, + float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_elements_count = ElementCount(*output_dims); + + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims), + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = ops::micro::Register_RELU(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_elements_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(golden[i], output_data[i], 1e-5f); + } +} + +void TestRelu6Float(int *input_dims_data, const float *input_data, + int *output_dims_data, const float *golden, + float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_elements_count = ElementCount(*output_dims); + + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims), + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = ops::micro::Register_RELU6(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_elements_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(golden[i], output_data[i], 1e-5f); + } +} + +void TestReluUint8(int *input_dims_data, const float *input_data, + uint8_t *input_data_quantized, const float input_scale, + const int input_zero_point, const float *golden, + uint8_t *golden_quantized, int *output_dims_data, + const float output_scale, const int output_zero_point, + uint8_t *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_elements_count = ElementCount(*output_dims); + + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(input_data, input_data_quantized, input_dims, + input_scale, input_zero_point), + CreateQuantizedTensor(output_data, output_dims, output_scale, + output_zero_point), + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = ops::micro::Register_RELU(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + Quantize(golden, golden_quantized, output_elements_count, output_scale, + output_zero_point); + + for (int i = 0; i < output_elements_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(golden_quantized[i], output_data[i]); + } +} + +void TestRelu6Uint8(int *input_dims_data, const float *input_data, + uint8_t *input_data_quantized, const float input_scale, + const int input_zero_point, const float *golden, + uint8_t *golden_quantized, int *output_dims_data, + const float output_scale, const int output_zero_point, + uint8_t *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_elements_count = ElementCount(*output_dims); + + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(input_data, input_data_quantized, input_dims, + input_scale, input_zero_point), + CreateQuantizedTensor(output_data, output_dims, output_scale, + output_zero_point), + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = ops::micro::Register_RELU6(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + Quantize(golden, golden_quantized, output_elements_count, output_scale, + output_zero_point); + + for (int i = 0; i < output_elements_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(golden_quantized[i], output_data[i]); + } +} + +void TestReluInt8(int *input_dims_data, const float *input_data, + int8_t *input_data_quantized, const float input_scale, + const int input_zero_point, const float *golden, + int8_t *golden_quantized, int *output_dims_data, + const float output_scale, const int output_zero_point, + int8_t *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_elements_count = ElementCount(*output_dims); + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(input_data, input_data_quantized, input_dims, + input_scale, input_zero_point), + CreateQuantizedTensor(output_data, output_dims, output_scale, + output_zero_point), + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = ops::micro::Register_RELU(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + Quantize(golden, golden_quantized, output_elements_count, output_scale, + output_zero_point); + + for (int i = 0; i < output_elements_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(golden_quantized[i], output_data[i]); + } +} + +void TestRelu6Int8(int *input_dims_data, const float *input_data, + int8_t *input_data_quantized, const float input_scale, + const int input_zero_point, const float *golden, + int8_t *golden_quantized, int *output_dims_data, + const float output_scale, const int output_zero_point, + int8_t *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_elements_count = ElementCount(*output_dims); + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(input_data, input_data_quantized, input_dims, + input_scale, input_zero_point), + CreateQuantizedTensor(output_data, output_dims, output_scale, + output_zero_point), + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = ops::micro::Register_RELU6(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + Quantize(golden, golden_quantized, output_elements_count, output_scale, + output_zero_point); + + for (int i = 0; i < output_elements_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(golden_quantized[i], output_data[i]); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(SimpleReluTestFloat) +{ + const int output_elements_count = 10; + int input_shape[] = { 2, 1, 5 }; + const float input_data[] = { + 1.0, + 2.0, + 3.0, + 4.0, + 5.0, + -1.0, + -2.0, + -3.0, + -4.0, + -5.0, + }; + const float golden[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 0, 0, 0, 0, 0 }; + int output_shape[] = { 2, 1, 5 }; + float output_data[output_elements_count]; + tflite::testing::TestReluFloat(input_shape, input_data, output_shape, golden, + output_data); +} + +TF_LITE_MICRO_TEST(SimpleRelu6TestFloat) +{ + const int output_elements_count = 10; + float output_data[output_elements_count]; + int input_shape[] = { 2, 1, 5 }; + const float input_data[] = { 4.0, 5.0, 6.0, 7.0, 8.0, + -4.0, -5.0, -6.0, -7.0, -8.0 }; + int output_shape[] = { 2, 1, 5 }; + const float golden[] = { + 4.0, + 5.0, + 6.0, + 6.0, + 6.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + }; + + tflite::testing::TestRelu6Float(input_shape, input_data, output_shape, golden, + output_data); +} + +TF_LITE_MICRO_TEST(SimpleReluTestUint8) +{ + const int elements_count = 10; + + int input_shape[] = { 2, 1, 5 }; + const float input_data[] = { 1, 2, 3, 4, 5, -1, -2, -3, -4, -5 }; + uint8_t input_quantized[elements_count]; + int output_shape[] = { 2, 1, 5 }; + const float golden[] = { 1, 2, 3, 4, 5, 0, 0, 0, 0, 0 }; + uint8_t golden_quantized[elements_count]; + uint8_t output_data[elements_count]; + + const float input_scale = 0.5f; + const int input_zero_point = 127; + const float output_scale = 0.5f; + const int output_zero_point = 127; + + tflite::testing::TestReluUint8(input_shape, input_data, input_quantized, + input_scale, input_zero_point, golden, + golden_quantized, output_shape, output_scale, + output_zero_point, output_data); +} + +TF_LITE_MICRO_TEST(SimpleRelu6TestUint8) +{ + const int elements_count = 10; + + int input_shape[] = { 2, 1, 5 }; + const float input_data[] = { 4, 5, 6, 7, 8, -1, -2, -3, -4, -5 }; + uint8_t input_quantized[elements_count]; + int output_shape[] = { 2, 1, 5 }; + const float golden[] = { 4, 5, 6, 6, 6, 0, 0, 0, 0, 0 }; + uint8_t golden_quantized[elements_count]; + uint8_t output_data[elements_count]; + + const float input_scale = 0.5f; + const int input_zero_point = 127; + const float output_scale = 0.5f; + const int output_zero_point = 127; + + tflite::testing::TestRelu6Uint8(input_shape, input_data, input_quantized, + input_scale, input_zero_point, golden, + golden_quantized, output_shape, output_scale, + output_zero_point, output_data); +} + +TF_LITE_MICRO_TEST(SimpleReluTestInt8) +{ + const int elements_count = 10; + + int input_shape[] = { 2, 1, 5 }; + const float input_data[] = { 1, 2, 3, 4, 5, -1, -2, -3, -4, -5 }; + int8_t input_quantized[elements_count]; + int output_shape[] = { 2, 1, 5 }; + const float golden[] = { 1, 2, 3, 4, 5, 0, 0, 0, 0, 0 }; + int8_t golden_quantized[elements_count]; + int8_t output_data[elements_count]; + + const float input_scale = 0.5f; + const int input_zero_point = 0; + const float output_scale = 0.5f; + const int output_zero_point = 0; + + tflite::testing::TestReluInt8(input_shape, input_data, input_quantized, + input_scale, input_zero_point, golden, + golden_quantized, output_shape, output_scale, + output_zero_point, output_data); +} + +TF_LITE_MICRO_TEST(SimpleRelu6TestInt8) +{ + const int elements_count = 10; + + int input_shape[] = { 2, 1, 5 }; + const float input_data[] = { 4, 5, 6, 7, 8, -1, -2, -3, -4, -5 }; + int8_t input_quantized[elements_count]; + int output_shape[] = { 2, 1, 5 }; + const float golden[] = { 4, 5, 6, 6, 6, 0, 0, 0, 0, 0 }; + int8_t golden_quantized[elements_count]; + int8_t output_data[elements_count]; + + const float input_scale = 0.5f; + const int input_zero_point = 127; + const float output_scale = 0.5f; + const int output_zero_point = 127; + + tflite::testing::TestRelu6Int8(input_shape, input_data, input_quantized, + input_scale, input_zero_point, golden, + golden_quantized, output_shape, output_scale, + output_zero_point, output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/add.cc b/components/tflite/tensorflow/lite/micro/kernels/add.cc new file mode 100644 index 00000000..afa2635c --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/add.cc @@ -0,0 +1,247 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/add.h" + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/integer_ops/add.h" +#include "tensorflow/lite/kernels/internal/reference/process_broadcast_shapes.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/memory_helpers.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace add { + +constexpr int kInputTensor1 = 0; +constexpr int kInputTensor2 = 1; +constexpr int kOutputTensor = 0; + +struct OpData { + bool requires_broadcast; + + // These fields are used in both the general 8-bit -> 8bit quantized path, + // and the special 16-bit -> 16bit quantized path + int input1_shift; + int input2_shift; + int32_t output_activation_min; + int32_t output_activation_max; + + // These fields are used only in the general 8-bit -> 8bit quantized path + int32_t input1_multiplier; + int32_t input2_multiplier; + int32_t output_multiplier; + int output_shift; + int left_shift; + int32_t input1_offset; + int32_t input2_offset; + int32_t output_offset; + + // Used only for float evals: + float output_activation_min_f32; + float output_activation_max_f32; +}; + +TfLiteStatus CalculateOpData(TfLiteContext *context, TfLiteAddParams *params, + const TfLiteTensor *input1, + const TfLiteTensor *input2, TfLiteTensor *output, + OpData *data) +{ + data->requires_broadcast = !HaveSameShapes(input1, input2); + + if (output->type == kTfLiteInt8) { + // 8bit -> 8bit general quantized path, with general rescalings + data->input1_offset = -input1->params.zero_point; + data->input2_offset = -input2->params.zero_point; + data->output_offset = output->params.zero_point; + data->left_shift = 20; + const double twice_max_input_scale = + 2 * static_cast( + std::max(input1->params.scale, input2->params.scale)); + const double real_input1_multiplier = + static_cast(input1->params.scale) / twice_max_input_scale; + const double real_input2_multiplier = + static_cast(input2->params.scale) / twice_max_input_scale; + const double real_output_multiplier = + twice_max_input_scale / + ((1 << data->left_shift) * static_cast(output->params.scale)); + + QuantizeMultiplierSmallerThanOneExp( + real_input1_multiplier, &data->input1_multiplier, &data->input1_shift); + + QuantizeMultiplierSmallerThanOneExp( + real_input2_multiplier, &data->input2_multiplier, &data->input2_shift); + + QuantizeMultiplierSmallerThanOneExp( + real_output_multiplier, &data->output_multiplier, &data->output_shift); + + TF_LITE_ENSURE_STATUS(CalculateActivationRangeQuantized( + context, params->activation, output, &data->output_activation_min, + &data->output_activation_max)); + } else if (output->type == kTfLiteFloat32) { + CalculateActivationRange(params->activation, + &data->output_activation_min_f32, + &data->output_activation_max_f32); + } + + return kTfLiteOk; +} + +void EvalAdd(TfLiteContext *context, TfLiteNode *node, TfLiteAddParams *params, + const OpData *data, const TfLiteEvalTensor *input1, + const TfLiteEvalTensor *input2, TfLiteEvalTensor *output) +{ + tflite::ArithmeticParams op_params; + SetActivationParams(data->output_activation_min_f32, + data->output_activation_max_f32, &op_params); + if (data->requires_broadcast) { + reference_ops::BroadcastAdd4DSlow( + op_params, tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorData(input1), + tflite::micro::GetTensorShape(input2), + tflite::micro::GetTensorData(input2), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } else { + reference_ops::Add(op_params, tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorData(input1), + tflite::micro::GetTensorShape(input2), + tflite::micro::GetTensorData(input2), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } +} + +TfLiteStatus EvalAddQuantized(TfLiteContext *context, TfLiteNode *node, + TfLiteAddParams *params, const OpData *data, + const TfLiteEvalTensor *input1, + const TfLiteEvalTensor *input2, + TfLiteEvalTensor *output) +{ + tflite::ArithmeticParams op_params; + op_params.left_shift = data->left_shift; + op_params.input1_offset = data->input1_offset; + op_params.input1_multiplier = data->input1_multiplier; + op_params.input1_shift = data->input1_shift; + op_params.input2_offset = data->input2_offset; + op_params.input2_multiplier = data->input2_multiplier; + op_params.input2_shift = data->input2_shift; + op_params.output_offset = data->output_offset; + op_params.output_multiplier = data->output_multiplier; + op_params.output_shift = data->output_shift; + SetActivationParams(data->output_activation_min, data->output_activation_max, + &op_params); + bool need_broadcast = reference_ops::ProcessBroadcastShapes( + tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorShape(input2), &op_params); + + if (need_broadcast) { + reference_integer_ops::BroadcastAdd4DSlow( + op_params, tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorData(input1), + tflite::micro::GetTensorShape(input2), + tflite::micro::GetTensorData(input2), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } else { + reference_integer_ops::Add(op_params, tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorData(input1), + tflite::micro::GetTensorShape(input2), + tflite::micro::GetTensorData(input2), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } + + return kTfLiteOk; +} + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(OpData)); +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + TFLITE_DCHECK(node->builtin_data != nullptr); + + const TfLiteTensor *input1 = GetInput(context, node, kInputTensor1); + TF_LITE_ENSURE(context, input1 != nullptr); + const TfLiteTensor *input2 = GetInput(context, node, kInputTensor2); + TF_LITE_ENSURE(context, input2 != nullptr); + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + + OpData *data = static_cast(node->user_data); + auto *params = reinterpret_cast(node->builtin_data); + + TF_LITE_ENSURE_STATUS( + CalculateOpData(context, params, input1, input2, output, data)); + + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + auto *params = reinterpret_cast(node->builtin_data); + + TFLITE_DCHECK(node->user_data != nullptr); + const OpData *data = static_cast(node->user_data); + + const TfLiteEvalTensor *input1 = + tflite::micro::GetEvalInput(context, node, kInputTensor1); + const TfLiteEvalTensor *input2 = + tflite::micro::GetEvalInput(context, node, kInputTensor2); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + if (output->type == kTfLiteFloat32) { + EvalAdd(context, node, params, data, input1, input2, output); + } else if (output->type == kTfLiteInt8) { + TF_LITE_ENSURE_OK(context, EvalAddQuantized(context, node, params, data, + input1, input2, output)); + } else { + TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.", + TfLiteTypeGetName(output->type), output->type); + return kTfLiteError; + } + + return kTfLiteOk; +} + +} // namespace add + +TfLiteRegistration Register_ADD() +{ + return { /*init=*/add::Init, + /*free=*/nullptr, + /*prepare=*/add::Prepare, + /*invoke=*/add::Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/add_n.cc b/components/tflite/tensorflow/lite/micro/kernels/add_n.cc new file mode 100644 index 00000000..7431f37c --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/add_n.cc @@ -0,0 +1,222 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/add_n.h" + +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace { + +constexpr int kInputTensor0 = 0; +constexpr int kOutputTensor = 0; + +constexpr int kAddNIntegerShift = 20; + +// only used with INT8 tensors +struct OpData { + int32_t output_activation_min; + int32_t output_activation_max; + int32_t input_offset; + int32_t output_offset; + int32_t input_multiplier; + int32_t output_multiplier; + int input_shift; + int output_shift; + int left_shift; + int scratch_index; +}; + +TfLiteStatus CalculateOpData(TfLiteContext *context, TfLiteNode *node) +{ + int num_inputs = NumInputs(node); + TF_LITE_ENSURE(context, num_inputs >= 2); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + + const TfLiteTensor *input_tensor_first; + TF_LITE_ENSURE_OK( + context, GetInputSafe(context, node, kInputTensor0, &input_tensor_first)); + TfLiteTensor *output; + TF_LITE_ENSURE_OK(context, + GetOutputSafe(context, node, kOutputTensor, &output)); + + // Check that all tensors have the same shape and type. + TF_LITE_ENSURE_TYPES_EQ(context, output->type, input_tensor_first->type); + for (int i = kInputTensor0 + 1; i < num_inputs; ++i) { + const TfLiteTensor *input; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, i, &input)); + TF_LITE_ENSURE(context, HaveSameShapes(input_tensor_first, input)); + TF_LITE_ENSURE_TYPES_EQ(context, input_tensor_first->type, input->type); + + // Check that all INT8 input tensors have the same zero-point and scale. + if (input_tensor_first->type == kTfLiteInt8) { + TF_LITE_ENSURE(context, input_tensor_first->params.zero_point == + input->params.zero_point); + TF_LITE_ENSURE(context, + input_tensor_first->params.scale == input->params.scale); + } + } + + if (output->type == kTfLiteFloat32) { + // Allocate scratch buffer space for pointer to each tensor's data + // and store the scratch buffer index in the node's user_data + int scratch_index; + size_t scratch_size = sizeof(float *) * num_inputs; + TF_LITE_ENSURE_OK(context, context->RequestScratchBufferInArena( + context, scratch_size, &scratch_index)); + node->user_data = + reinterpret_castuser_data)>(scratch_index); + } else if (output->type == kTfLiteInt8) { + node->user_data = + context->AllocatePersistentBuffer(context, sizeof(OpData)); + OpData *data = static_cast(node->user_data); + + // Allocate scratch buffer space for pointer to each tensor's data + // and store the scratch buffer index in OpData + size_t scratch_size = sizeof(int8_t *) * num_inputs; + TF_LITE_ENSURE_OK( + context, context->RequestScratchBufferInArena(context, scratch_size, + &data->scratch_index)); + + // 8bit -> 8bit general quantized path, with general rescalings + data->input_offset = -input_tensor_first->params.zero_point; + data->output_offset = output->params.zero_point; + data->left_shift = kAddNIntegerShift; + const double twice_max_input_scale = + 2 * static_cast(input_tensor_first->params.scale); + const double real_input_multiplier = + static_cast(input_tensor_first->params.scale) / + twice_max_input_scale; + const double real_output_multiplier = + twice_max_input_scale / + ((1 << data->left_shift) * static_cast(output->params.scale)); + + QuantizeMultiplierSmallerThanOneExp( + real_input_multiplier, &data->input_multiplier, &data->input_shift); + + QuantizeMultiplierSmallerThanOneExp( + real_output_multiplier, &data->output_multiplier, &data->output_shift); + + TF_LITE_ENSURE_STATUS(CalculateActivationRangeQuantized( + context, kTfLiteActNone, output, &data->output_activation_min, + &data->output_activation_max)); + } else { + TF_LITE_KERNEL_LOG(context, "ADD_N only supports FLOAT32 and INT8, got %s.", + TfLiteTypeGetName(output->type)); + return kTfLiteError; + } + + return kTfLiteOk; +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + return CalculateOpData(context, node); +} + +template +inline const T **CopyInputsToScratchBuffer(TfLiteContext *context, + TfLiteNode *node, + const int scratch_index) +{ + int num_inputs = NumInputs(node); + void *scratch_buffer = context->GetScratchBuffer(context, scratch_index); + const T **all_inputs = static_cast(scratch_buffer); + for (int i = 0; i < num_inputs; i++) { + const TfLiteEvalTensor *next_input = + tflite::micro::GetEvalInput(context, node, kInputTensor0 + i); + all_inputs[i] = tflite::micro::GetTensorData(next_input); + } + + return all_inputs; +} + +template +void EvalAddN(TfLiteContext *context, TfLiteNode *node, + TfLiteEvalTensor *output) +{ + int num_inputs = NumInputs(node); + + int scratch_index = + static_cast(reinterpret_cast(node->user_data)); + const T **all_inputs = + CopyInputsToScratchBuffer(context, node, scratch_index); + + reference_ops::AddN(tflite::micro::GetTensorShape(output), num_inputs, + all_inputs, tflite::micro::GetTensorData(output)); +} + +template +void EvalAddNQuantized(TfLiteContext *context, TfLiteNode *node, + TfLiteEvalTensor *output) +{ + int num_inputs = NumInputs(node); + + OpData *data = static_cast(node->user_data); + const T **all_inputs = + CopyInputsToScratchBuffer(context, node, data->scratch_index); + + ArithmeticParams params; + params.left_shift = data->left_shift; + params.input1_offset = data->input_offset; + params.input1_multiplier = data->input_multiplier; + params.input1_shift = data->input_shift; + params.output_offset = data->output_offset; + params.output_multiplier = data->output_multiplier; + params.output_shift = data->output_shift; + SetActivationParams(data->output_activation_min, data->output_activation_max, + ¶ms); + + reference_ops::AddN(params, tflite::micro::GetTensorShape(output), num_inputs, + all_inputs, tflite::micro::GetTensorData(output)); +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + if (output->type == kTfLiteFloat32) { + EvalAddN(context, node, output); + } else if (output->type == kTfLiteInt8) { + EvalAddNQuantized(context, node, output); + } else { + TF_LITE_KERNEL_LOG(context, "ADD_N only supports FLOAT32 and INT8, got %s.", + TfLiteTypeGetName(output->type)); + return kTfLiteError; + } + return kTfLiteOk; +} + +} // namespace + +TfLiteRegistration Register_ADD_N() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/add_n_test.cc b/components/tflite/tensorflow/lite/micro/kernels/add_n_test.cc new file mode 100644 index 00000000..dc5f4efc --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/add_n_test.cc @@ -0,0 +1,175 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +constexpr int kMaxInputTensors = 3; +constexpr int kMaxOutputTensors = 1; + +void ExecuteAddN(TfLiteTensor *tensors, int tensors_count) +{ + int input_array_data[kMaxInputTensors + kMaxOutputTensors] = { tensors_count - + 1 }; + for (int i = 1; i < tensors_count; i++) { + input_array_data[i] = i - 1; + } + TfLiteIntArray *inputs_array = IntArrayFromInts(input_array_data); + int kOutputArrayData[] = { 1, tensors_count - 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(kOutputArrayData); + + const TfLiteRegistration registration = tflite::Register_ADD_N(); + micro::KernelRunner runner(registration, tensors, tensors_count, inputs_array, + outputs_array, nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); +} + +template +void TestAddN(int *input_dims_data, const T *const *input_data, + int input_data_count, int *expected_dims, const T *expected_data, + T *output_data) +{ + TF_LITE_MICRO_EXPECT_LE(input_data_count, kMaxInputTensors); + + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(expected_dims); + const int output_count = ElementCount(*output_dims); + + TfLiteTensor tensors[kMaxInputTensors + kMaxOutputTensors] = {}; + for (int i = 0; i < input_data_count; i++) { + tensors[i] = CreateTensor(input_data[i], input_dims); + } + tensors[input_data_count] = CreateTensor(output_data, output_dims); + + ExecuteAddN(tensors, input_data_count + 1); + + for (int i = 0; i < output_count; i++) { + TF_LITE_MICRO_EXPECT_EQ(expected_data[i], output_data[i]); + } +} + +// min/max are used to compute scale, zero-point, compare tolerance +template +struct TestQuantParams { + float data_min; // input and output data minimum value + float data_max; // input and output data maximum value + T input_data[kNumInputs][kOutputSize]; // quantized input storage + T output_data[kOutputSize]; // quantized output storage +}; + +// for quantized Add, the error shouldn't exceed step +template +float GetTolerance(float min, float max) +{ + float kQuantizedStep = + 2.0f * (max - min) / + (std::numeric_limits::max() - std::numeric_limits::min()); + return kQuantizedStep; +} + +template +void TestAddNQuantized(TestQuantParams *params, + int *input_dims_data, const float *const *input_data, + int *expected_dims, const float *expected_data, + float *output_data) +{ + TF_LITE_MICRO_EXPECT_LE(kNumInputs, kMaxInputTensors); + + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(expected_dims); + + const float scale = ScaleFromMinMax(params->data_min, params->data_max); + const int zero_point = + ZeroPointFromMinMax(params->data_min, params->data_max); + + TfLiteTensor tensors[kMaxInputTensors + kMaxOutputTensors] = {}; + for (int i = 0; i < kNumInputs; i++) { + tensors[i] = CreateQuantizedTensor(input_data[i], params->input_data[i], + input_dims, scale, zero_point); + } + tensors[kNumInputs] = CreateQuantizedTensor(params->output_data, output_dims, + scale, zero_point); + + ExecuteAddN(tensors, kNumInputs + 1); + + Dequantize(params->output_data, kOutputSize, scale, zero_point, output_data); + const float kTolerance = GetTolerance(params->data_min, params->data_max); + for (int i = 0; i < kOutputSize; i++) { + TF_LITE_MICRO_EXPECT_NEAR(expected_data[i], output_data[i], kTolerance); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(FloatAddNOpAddMultipleTensors) +{ + int kDims[] = { 4, 1, 2, 2, 1 }; + constexpr float kInput1[] = { -2.0, 0.2, 0.7, 0.8 }; + constexpr float kInput2[] = { 0.1, 0.2, 0.3, 0.5 }; + constexpr float kInput3[] = { 0.5, 0.1, 0.1, 0.2 }; + constexpr float kExpect[] = { -1.4, 0.5, 1.1, 1.5 }; + const float *kInputs[tflite::testing::kMaxInputTensors] = { + kInput1, + kInput2, + kInput3, + }; + constexpr int kInputCount = std::extent::value; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + tflite::testing::TestAddN(kDims, kInputs, kInputCount, kDims, kExpect, + output_data); +} + +TF_LITE_MICRO_TEST(Int8AddNOpAddMultipleTensors) +{ + int kDims[] = { 4, 1, 2, 2, 1 }; + constexpr float kInput1[] = { -2.0, 0.2, 0.7, 0.8 }; + constexpr float kInput2[] = { 0.1, 0.2, 0.3, 0.5 }; + constexpr float kInput3[] = { 0.5, 0.1, 0.1, 0.2 }; + constexpr float kExpect[] = { -1.4, 0.5, 1.1, 1.5 }; + const float *kInputs[tflite::testing::kMaxInputTensors] = { + kInput1, + kInput2, + kInput3, + }; + constexpr int kInputCount = std::extent::value; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + tflite::testing::TestQuantParams params = {}; + params.data_min = -3.0; + params.data_max = 3.0; + + tflite::testing::TestAddNQuantized( + ¶ms, kDims, kInputs, kDims, kExpect, output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/add_test.cc b/components/tflite/tensorflow/lite/micro/kernels/add_test.cc new file mode 100644 index 00000000..2cf18bb2 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/add_test.cc @@ -0,0 +1,378 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +// Shapes and values for mixed broadcast tests. +const int broadcast_output_dims_count = 36; +const int broadcast_num_shapes = 4; + +int broadcast_input1_shape[] = { 4, 2, 3, 1, 2 }; +const float broadcast_input1_values[] = { -0.3, 2.3, 0.9, 0.5, 0.8, -1.1, + 1.2, 2.8, -1.6, 0.0, 0.7, -2.2 }; +const float broadcast_input2_values[] = { 0.2, 0.3, -0.4, 0.5, 1.0, 0.9 }; +const float + broadcast_goldens[broadcast_num_shapes][broadcast_output_dims_count] = { + { -0.1, 2.6, -0.7, 2.8, 0.7, 3.2, 1.1, 0.8, 0.5, 1.0, 1.9, 1.4, + 1.0, -0.8, 0.4, -0.6, 1.8, -0.2, 1.4, 3.1, 0.8, 3.3, 2.2, 3.7, + -1.4, 0.3, -2.0, 0.5, -0.6, 0.9, 0.9, -1.9, 0.3, -1.7, 1.7, -1.3 }, + { -0.1, 2.6, 0.5, 1.0, 1.8, -0.2, 1.4, 3.1, -2.0, 0.5, 1.7, -1.3 }, + { -0.1, 2.5, 0.0, 2.6, -0.7, 1.9, 1.1, 0.7, 1.2, 0.8, 0.5, 0.1, + 1.0, -0.9, 1.1, -0.8, 0.4, -1.5, 1.7, 3.3, 2.2, 3.8, 2.1, 3.7, + -1.1, 0.5, -0.6, 1.0, -0.7, 0.9, 1.2, -1.7, 1.7, -1.2, 1.6, -1.3 }, + { -0.1, 2.5, 1.2, 0.8, 0.4, -1.5, 1.7, 3.3, -0.6, 1.0, 1.6, -1.3 }, + }; + +const int broadcast_max_shape_size = 5; +int broadcast_input2_shapes[broadcast_num_shapes][broadcast_max_shape_size] = { + { 4, 1, 1, 3, 2 }, + { 4, 1, 3, 1, 2 }, + { 4, 2, 1, 3, 1 }, + { 4, 2, 3, 1, 1 }, +}; +int broadcast_output_shapes[broadcast_num_shapes][broadcast_max_shape_size] = { + { 4, 2, 3, 3, 2 }, + { 4, 2, 3, 1, 2 }, + { 4, 2, 3, 3, 2 }, + { 4, 2, 3, 1, 2 }, +}; + +template +void ValidateAddGoldens(TfLiteTensor *tensors, int tensors_size, + const T *golden, T *output, int output_size, + TfLiteFusedActivation activation, + float tolerance = 1e-5) +{ + TfLiteAddParams builtin_data; + builtin_data.activation = activation; + + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = ops::micro::Register_ADD(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, &builtin_data); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_size; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(golden[i], output[i], tolerance); + } +} + +void TestAddFloat(int *input1_dims_data, const float *input1_data, + int *input2_dims_data, const float *input2_data, + int *output_dims_data, const float *expected_output, + TfLiteFusedActivation activation, float *output_data) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input1_data, input1_dims), + CreateTensor(input2_data, input2_dims), + CreateTensor(output_data, output_dims), + }; + + ValidateAddGoldens(tensors, tensors_size, expected_output, output_data, + ElementCount(*output_dims), activation); +} + +template +void TestAddQuantized(int *input1_dims_data, const float *input1_data, + T *input1_quantized, float input1_scale, + int input1_zero_point, int *input2_dims_data, + const float *input2_data, T *input2_quantized, + float input2_scale, int input2_zero_point, + int *output_dims_data, const float *golden, + T *golden_quantized, float output_scale, + int output_zero_point, TfLiteFusedActivation activation, + T *output_data) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + tflite::testing::CreateQuantizedTensor(input1_data, input1_quantized, + input1_dims, input1_scale, + input1_zero_point), + tflite::testing::CreateQuantizedTensor(input2_data, input2_quantized, + input2_dims, input2_scale, + input2_zero_point), + tflite::testing::CreateQuantizedTensor(output_data, output_dims, + output_scale, output_zero_point), + }; + tflite::Quantize(golden, golden_quantized, ElementCount(*output_dims), + output_scale, output_zero_point); + + ValidateAddGoldens(tensors, tensors_size, golden_quantized, output_data, + ElementCount(*output_dims), activation); +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(FloatAddNoActivation) +{ + const int output_dims_count = 4; + int inout_shape[] = { 4, 1, 2, 2, 1 }; + const float input1_values[] = { -2.0, 0.2, 0.7, 0.8 }; + const float input2_values[] = { 0.1, 0.2, 0.3, 0.5 }; + const float golden_values[] = { -1.9, 0.4, 1.0, 1.3 }; + float output_data[output_dims_count]; + tflite::testing::TestAddFloat(inout_shape, input1_values, inout_shape, + input2_values, inout_shape, golden_values, + kTfLiteActNone, output_data); +} + +TF_LITE_MICRO_TEST(FloatAddActivationRelu1) +{ + const int output_dims_count = 4; + int inout_shape[] = { 4, 1, 2, 2, 1 }; + const float input1_values[] = { -2.0, 0.2, 0.7, 0.8 }; + const float input2_values[] = { 0.1, 0.2, 0.3, 0.5 }; + const float golden_values[] = { -1.0, 0.4, 1.0, 1.0 }; + + float output_data[output_dims_count]; + tflite::testing::TestAddFloat(inout_shape, input1_values, inout_shape, + input2_values, inout_shape, golden_values, + kTfLiteActReluN1To1, output_data); +} + +TF_LITE_MICRO_TEST(FloatAddVariousInputShapes) +{ + const int output_dims_count = 6; + float output_data[output_dims_count]; + + const float input1_values[] = { -2.0, 0.2, 0.7, 0.8, 1.1, 2.0 }; + const float input2_values[] = { 0.1, 0.2, 0.3, 0.5, 1.1, 0.1 }; + const float expected_output[] = { -1.9, 0.4, 1.0, 1.3, 2.2, 2.1 }; + + constexpr int num_shapes = 4; + constexpr int max_shape_size = 5; + int test_shapes[num_shapes][max_shape_size] = { + { 1, 6 }, + { 2, 2, 3 }, + { 3, 2, 1, 3 }, + { 4, 1, 3, 1, 2 }, + }; + + for (int i = 0; i < num_shapes; ++i) { + tflite::testing::TestAddFloat(test_shapes[i], input1_values, test_shapes[i], + input2_values, test_shapes[i], + expected_output, kTfLiteActNone, output_data); + } +} + +TF_LITE_MICRO_TEST(FloatAddWithScalarBroadcast) +{ + const int output_dims_count = 6; + float output_data[output_dims_count]; + + const float input1_values[] = { -2.0, 0.2, 0.7, 0.8, 1.1, 2.0 }; + int input2_shape[] = { 0 }; + const float input2_values[] = { 0.1 }; + const float expected_output[] = { -1.9, 0.3, 0.8, 0.9, 1.2, 2.1 }; + + constexpr int num_shapes = 4; + constexpr int max_shape_size = 5; + int test_shapes[num_shapes][max_shape_size] = { + { 1, 6 }, + { 2, 2, 3 }, + { 3, 2, 1, 3 }, + { 4, 1, 3, 1, 2 }, + }; + + for (int i = 0; i < num_shapes; ++i) { + tflite::testing::TestAddFloat(test_shapes[i], input1_values, input2_shape, + input2_values, test_shapes[i], + expected_output, kTfLiteActNone, output_data); + } +} + +TF_LITE_MICRO_TEST(QuantizedAddNoActivationInt8) +{ + const float scales[] = { 0.25, 0.5, 1.0 }; + const int zero_points[] = { -10, 4, 13 }; + const int output_dims_count = 4; + int inout_shape[] = { 4, 1, 2, 2, 1 }; + const float input1_values[] = { -2.01, -1.01, -0.01, 0.98 }; + const float input2_values[] = { 1.01, 1.99, 2.99, 4.02 }; + const float golden_values[] = { -1, 1, 3, 5 }; + + int8_t input1_quantized[output_dims_count]; + int8_t input2_quantized[output_dims_count]; + int8_t golden_quantized[output_dims_count]; + int8_t output[output_dims_count]; + + tflite::testing::TestAddQuantized( + inout_shape, input1_values, input1_quantized, scales[0], zero_points[0], + inout_shape, input2_values, input2_quantized, scales[1], zero_points[1], + inout_shape, golden_values, golden_quantized, scales[2], zero_points[2], + kTfLiteActNone, output); +} + +TF_LITE_MICRO_TEST(QuantizedAddActivationRelu1Int8) +{ + const float scales[] = { 0.25, 0.5, 1.0 }; + const int zero_points[] = { -10, 4, 13 }; + const int output_dims_count = 4; + int inout_shape[] = { 4, 1, 2, 2, 1 }; + const float input1_values[] = { -2.01, -1.01, -0.01, 0.98 }; + const float input2_values[] = { 1.01, 1.99, 2.99, 4.02 }; + const float golden_values[] = { -1, 1, 1, 1 }; + + int8_t input1_quantized[output_dims_count]; + int8_t input2_quantized[output_dims_count]; + int8_t golden_quantized[output_dims_count]; + int8_t output[output_dims_count]; + + tflite::testing::TestAddQuantized( + inout_shape, input1_values, input1_quantized, scales[0], zero_points[0], + inout_shape, input2_values, input2_quantized, scales[1], zero_points[1], + inout_shape, golden_values, golden_quantized, scales[2], zero_points[2], + kTfLiteActReluN1To1, output); +} + +TF_LITE_MICRO_TEST(QuantizedAddVariousInputShapesInt8) +{ + const float scales[] = { 0.1, 0.05, 0.1 }; + const int zero_points[] = { -9, 5, 14 }; + const int output_dims_count = 6; + + constexpr int num_shapes = 4; + constexpr int max_shape_size = 5; + int test_shapes[num_shapes][max_shape_size] = { + { 1, 6 }, + { 2, 2, 3 }, + { 3, 2, 1, 3 }, + { 4, 1, 3, 1, 2 }, + }; + + const float input1_values[] = { -2.0, 0.2, 0.7, 0.8, 1.1, 2.0 }; + const float input2_values[] = { 0.1, 0.2, 0.3, 0.5, 1.1, 0.1 }; + const float golden_values[] = { -1.9, 0.4, 1.0, 1.3, 2.2, 2.1 }; + + int8_t input1_quantized[output_dims_count]; + int8_t input2_quantized[output_dims_count]; + int8_t golden_quantized[output_dims_count]; + int8_t output[output_dims_count]; + + for (int i = 0; i < num_shapes; i++) { + tflite::testing::TestAddQuantized( + test_shapes[i], input1_values, input1_quantized, scales[0], + zero_points[0], test_shapes[i], input2_values, input2_quantized, + scales[1], zero_points[1], test_shapes[i], golden_values, + golden_quantized, scales[2], zero_points[2], kTfLiteActNone, output); + } +} + +TF_LITE_MICRO_TEST(QuantizedAddWithScalarBroadcastFloat) +{ + float output_float[tflite::testing::broadcast_output_dims_count]; + + for (int i = 0; i < tflite::testing::broadcast_num_shapes; ++i) { + tflite::testing::TestAddFloat(tflite::testing::broadcast_input1_shape, + tflite::testing::broadcast_input1_values, + tflite::testing::broadcast_input2_shapes[i], + tflite::testing::broadcast_input2_values, + tflite::testing::broadcast_output_shapes[i], + tflite::testing::broadcast_goldens[i], + kTfLiteActNone, output_float); + } +} + +TF_LITE_MICRO_TEST(QuantizedAddWithScalarBroadcastInt8) +{ + const int output_dims_count = 6; + + const float input1_values[] = { -2.0, 0.2, 0.7, 0.8, 1.1, 2.0 }; + int input2_shape[] = { 0 }; + const float input2_values[] = { 0.1 }; + const float golden[] = { -1.9, 0.3, 0.8, 0.9, 1.2, 2.1 }; + + constexpr int num_shapes = 4; + constexpr int max_shape_size = 5; + int test_shapes[num_shapes][max_shape_size] = { + { 1, 6 }, + { 2, 2, 3 }, + { 3, 2, 1, 3 }, + { 4, 1, 3, 1, 2 }, + }; + + const float scales[] = { 0.1, 0.05, 0.05 }; + const int zero_points[] = { -8, 4, 12 }; + + int8_t input1_quantized[output_dims_count]; + int8_t input2_quantized[output_dims_count]; + int8_t golden_quantized[output_dims_count]; + int8_t output[output_dims_count]; + + for (int i = 0; i < num_shapes; ++i) { + tflite::testing::TestAddQuantized( + test_shapes[i], input1_values, input1_quantized, scales[0], + zero_points[0], input2_shape, input2_values, input2_quantized, + scales[1], zero_points[1], test_shapes[i], golden, golden_quantized, + scales[2], zero_points[2], kTfLiteActNone, output); + } +} + +TF_LITE_MICRO_TEST(QuantizedAddWithMixedBroadcastInt8) +{ + const float scales[] = { 0.1, 0.05, 0.1 }; + const int zero_points[] = { -10, -5, 7 }; + int8_t input1_quantized[tflite::testing::broadcast_output_dims_count]; + int8_t input2_quantized[tflite::testing::broadcast_output_dims_count]; + int8_t golden_quantized[tflite::testing::broadcast_output_dims_count]; + int8_t output[tflite::testing::broadcast_output_dims_count]; + + for (int i = 0; i < tflite::testing::broadcast_num_shapes; ++i) { + tflite::testing::TestAddQuantized( + tflite::testing::broadcast_input1_shape, + tflite::testing::broadcast_input1_values, input1_quantized, scales[0], + zero_points[0], tflite::testing::broadcast_input2_shapes[i], + tflite::testing::broadcast_input2_values, input2_quantized, scales[1], + zero_points[1], tflite::testing::broadcast_output_shapes[i], + tflite::testing::broadcast_goldens[i], golden_quantized, scales[2], + zero_points[2], kTfLiteActNone, output); + } +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/arg_min_max.cc b/components/tflite/tensorflow/lite/micro/kernels/arg_min_max.cc new file mode 100644 index 00000000..4594fc08 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/arg_min_max.cc @@ -0,0 +1,139 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/arg_min_max.h" + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/micro_utils.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace arg_min_max { + +constexpr int kInputTensor = 0; +constexpr int kAxis = 1; +constexpr int kOutputTensor = 0; + +template +inline void ArgMinMaxHelper(const RuntimeShape &input1_shape, + const T1 *input1_data, const T3 *input2_data, + const RuntimeShape &output_shape, T2 *output_data, + bool is_arg_max) +{ + if (is_arg_max) { + reference_ops::ArgMinMax(input1_shape, input1_data, input2_data, + output_shape, output_data, micro::Greater()); + } else { + reference_ops::ArgMinMax(input1_shape, input1_data, input2_data, + output_shape, output_data, micro::Less()); + } +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node, bool is_arg_max) +{ + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + const TfLiteEvalTensor *axis = + tflite::micro::GetEvalInput(context, node, kAxis); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + +#define TF_LITE_ARG_MIN_MAX(data_type, axis_type, output_type) \ + ArgMinMaxHelper(tflite::micro::GetTensorShape(input), \ + tflite::micro::GetTensorData(input), \ + tflite::micro::GetTensorData(axis), \ + tflite::micro::GetTensorShape(output), \ + tflite::micro::GetTensorData(output), \ + is_arg_max) + if (axis->type == kTfLiteInt32) { + if (output->type == kTfLiteInt32) { + switch (input->type) { + case kTfLiteFloat32: + TF_LITE_ARG_MIN_MAX(float, int32_t, int32_t); + break; + case kTfLiteUInt8: + TF_LITE_ARG_MIN_MAX(uint8_t, int32_t, int32_t); + break; + case kTfLiteInt8: + TF_LITE_ARG_MIN_MAX(int8_t, int32_t, int32_t); + break; + default: + TF_LITE_KERNEL_LOG(context, + "Only float32, uint8_t and int8_t are " + "supported currently, got %s.", + TfLiteTypeGetName(input->type)); + return kTfLiteError; + } + } else { + TF_LITE_KERNEL_LOG(context, + "Only int32_t are supported currently, got %s.", + TfLiteTypeGetName(output->type)); + return kTfLiteError; + } + } else { + TF_LITE_KERNEL_LOG(context, "Only int32_t are supported currently, got %s.", + TfLiteTypeGetName(axis->type)); + return kTfLiteError; + } + +#undef TF_LITE_ARG_MIN_MAX + + return kTfLiteOk; +} + +TfLiteStatus ArgMinEval(TfLiteContext *context, TfLiteNode *node) +{ + return Eval(context, node, false); +} + +TfLiteStatus ArgMaxEval(TfLiteContext *context, TfLiteNode *node) +{ + return Eval(context, node, true); +} + +} // namespace arg_min_max + +TfLiteRegistration Register_ARG_MAX() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/nullptr, + /*invoke=*/arg_min_max::ArgMaxEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +TfLiteRegistration Register_ARG_MIN() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/nullptr, + /*invoke=*/arg_min_max::ArgMinEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/arg_min_max_test.cc b/components/tflite/tensorflow/lite/micro/kernels/arg_min_max_test.cc new file mode 100644 index 00000000..99f06a54 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/arg_min_max_test.cc @@ -0,0 +1,276 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +void ValidateArgMinMaxGoldens(TfLiteTensor *tensors, int tensors_size, + const int32_t *golden, int32_t *output, + int output_size, bool using_min) +{ + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = using_min ? ops::micro::Register_ARG_MIN() : ops::micro::Register_ARG_MAX(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_size; ++i) { + TF_LITE_MICRO_EXPECT_EQ(golden[i], output[i]); + } +} + +void TestArgMinMaxFloat(int *input_dims_data, const float *input_values, + int *axis_dims_data, const int32_t *axis_values, + int *output_dims_data, int32_t *output, + const int32_t *goldens, bool using_min) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *axis_dims = IntArrayFromInts(axis_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_values, input_dims), + CreateTensor(axis_values, axis_dims), + CreateTensor(output, output_dims), + }; + + ValidateArgMinMaxGoldens(tensors, tensors_size, goldens, output, + output_dims_count, using_min); +} + +template +void TestArgMinMaxQuantized(int *input_dims_data, const float *input_values, + T *input_quantized, float input_scale, + int input_zero_point, int *axis_dims_data, + const int32_t *axis_values, int *output_dims_data, + int32_t *output, const int32_t *goldens, + bool using_min) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *axis_dims = IntArrayFromInts(axis_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(input_values, input_quantized, input_dims, + input_scale, input_zero_point), + CreateTensor(axis_values, axis_dims), + CreateTensor(output, output_dims), + }; + + ValidateArgMinMaxGoldens(tensors, tensors_size, goldens, output, + output_dims_count, using_min); +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(GetMaxArgFloat) +{ + int32_t output_data[1]; + int input_dims[] = { 4, 1, 1, 1, 4 }; + const float input_values[] = { 0.1, 0.9, 0.7, 0.3 }; + int axis_dims[] = { 3, 1, 1, 1 }; + const int32_t axis_values[] = { 3 }; + int output_dims[] = { 3, 1, 1, 1 }; + const int32_t goldens[] = { 1 }; + + tflite::testing::TestArgMinMaxFloat(input_dims, input_values, axis_dims, + axis_values, output_dims, output_data, + goldens, false); +} + +TF_LITE_MICRO_TEST(GetMinArgFloat) +{ + int32_t output_data[1]; + int input_dims[] = { 4, 1, 1, 1, 4 }; + const float input_values[] = { 0.1, 0.9, 0.7, 0.3 }; + int axis_dims[] = { 3, 1, 1, 1 }; + const int32_t axis_values[] = { 3 }; + int output_dims[] = { 3, 1, 1, 1 }; + const int32_t goldens[] = { 0 }; + + tflite::testing::TestArgMinMaxFloat(input_dims, input_values, axis_dims, + axis_values, output_dims, output_data, + goldens, true); +} + +TF_LITE_MICRO_TEST(GetMaxArgUInt8) +{ + int32_t output_data[1]; + const int input_size = 4; + int input_dims[] = { 4, 1, 1, 1, input_size }; + const float input_values[] = { 1, 9, 7, 3 }; + int axis_dims[] = { 3, 1, 1, 1 }; + const int32_t axis_values[] = { 3 }; + int output_dims[] = { 3, 1, 1, 1 }; + const int32_t goldens[] = { 1 }; + + float input_scale = 0.5; + int input_zero_point = 124; + uint8_t input_quantized[input_size]; + + tflite::testing::TestArgMinMaxQuantized( + input_dims, input_values, input_quantized, input_scale, input_zero_point, + axis_dims, axis_values, output_dims, output_data, goldens, false); +} + +TF_LITE_MICRO_TEST(GetMinArgUInt8) +{ + int32_t output_data[1]; + const int input_size = 4; + int input_dims[] = { 4, 1, 1, 1, input_size }; + const float input_values[] = { 1, 9, 7, 3 }; + int axis_dims[] = { 3, 1, 1, 1 }; + const int32_t axis_values[] = { 3 }; + int output_dims[] = { 3, 1, 1, 1 }; + const int32_t goldens[] = { 0 }; + + float input_scale = 0.5; + int input_zero_point = 124; + uint8_t input_quantized[input_size]; + + tflite::testing::TestArgMinMaxQuantized( + input_dims, input_values, input_quantized, input_scale, input_zero_point, + axis_dims, axis_values, output_dims, output_data, goldens, true); +} + +TF_LITE_MICRO_TEST(GetMaxArgInt8) +{ + int32_t output_data[1]; + const int input_size = 4; + int input_dims[] = { 4, 1, 1, 1, input_size }; + const float input_values[] = { 1, 9, 7, 3 }; + int axis_dims[] = { 3, 1, 1, 1 }; + const int32_t axis_values[] = { 3 }; + int output_dims[] = { 3, 1, 1, 1 }; + const int32_t goldens[] = { 1 }; + + float input_scale = 0.5; + int input_zero_point = -9; + int8_t input_quantized[input_size]; + + tflite::testing::TestArgMinMaxQuantized( + input_dims, input_values, input_quantized, input_scale, input_zero_point, + axis_dims, axis_values, output_dims, output_data, goldens, false); +} + +TF_LITE_MICRO_TEST(GetMinArgInt8) +{ + int32_t output_data[1]; + const int input_size = 4; + int input_dims[] = { 4, 1, 1, 1, input_size }; + const float input_values[] = { 1, 9, 7, 3 }; + int axis_dims[] = { 3, 1, 1, 1 }; + const int32_t axis_values[] = { 3 }; + int output_dims[] = { 3, 1, 1, 1 }; + const int32_t goldens[] = { 0 }; + + float input_scale = 0.5; + int input_zero_point = -9; + int8_t input_quantized[input_size]; + + tflite::testing::TestArgMinMaxQuantized( + input_dims, input_values, input_quantized, input_scale, input_zero_point, + axis_dims, axis_values, output_dims, output_data, goldens, true); +} + +TF_LITE_MICRO_TEST(GetMaxArgMulDimensions) +{ + int32_t output_data[2]; + const int input_size = 8; + int input_dims[] = { 4, 1, 1, 2, 4 }; + const float input_values[] = { 1, 2, 7, 8, 1, 9, 7, 3 }; + int axis_dims[] = { 3, 1, 1, 1 }; + const int32_t axis_values[] = { 3 }; + int output_dims[] = { 3, 1, 1, 2 }; + const int32_t goldens[] = { 3, 1 }; + + float input_scale = 0.5; + int input_zero_point = -9; + int8_t input_quantized[input_size]; + + tflite::testing::TestArgMinMaxQuantized( + input_dims, input_values, input_quantized, input_scale, input_zero_point, + axis_dims, axis_values, output_dims, output_data, goldens, false); +} + +TF_LITE_MICRO_TEST(GetMinArgMulDimensions) +{ + int32_t output_data[2]; + const int input_size = 8; + int input_dims[] = { 4, 1, 1, 2, 4 }; + const float input_values[] = { 1, 2, 7, 8, 1, 9, 7, 3 }; + int axis_dims[] = { 3, 1, 1, 1 }; + const int32_t axis_values[] = { 3 }; + int output_dims[] = { 3, 1, 1, 2 }; + const int32_t goldens[] = { 0, 0 }; + + float input_scale = 0.5; + int input_zero_point = -9; + int8_t input_quantized[input_size]; + + tflite::testing::TestArgMinMaxQuantized( + input_dims, input_values, input_quantized, input_scale, input_zero_point, + axis_dims, axis_values, output_dims, output_data, goldens, true); +} + +TF_LITE_MICRO_TEST(GetMaxArgNegativeAxis) +{ + const int input_size = 8; + const int output_size = 4; + int input_dims[] = { 4, 1, 1, 2, 4 }; + const float input_values[] = { 1, 2, 7, 8, 1, 9, 7, 3 }; + int axis_dims[] = { 3, 1, 1, 1 }; + const int32_t axis_values[] = { -2 }; + int output_dims[] = { 3, 1, 1, 4 }; + const int32_t goldens[] = { 0, 1, 0, 0 }; + + float input_scale = 0.5; + int input_zero_point = -9; + int32_t output_data[output_size]; + int8_t input_quantized[input_size]; + + tflite::testing::TestArgMinMaxQuantized( + input_dims, input_values, input_quantized, input_scale, input_zero_point, + axis_dims, axis_values, output_dims, output_data, goldens, false); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/batch_to_space_nd.cc b/components/tflite/tensorflow/lite/micro/kernels/batch_to_space_nd.cc new file mode 100644 index 00000000..f2b62f3f --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/batch_to_space_nd.cc @@ -0,0 +1,114 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/batch_to_space_nd.h" + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/micro_utils.h" + +namespace tflite { + +namespace { + +constexpr int kInputTensor = 0; +constexpr int kBlockShapeTensor = 1; +constexpr int kCropsTensor = 2; +constexpr int kOutputTensor = 0; + +// Currently, only 3D NHC and 4D NHWC input/output op_context are supported. +// In case of 3D input, it will be extended to 3D NHWC by adding W=1. +// The 4D array need to have exactly 2 spatial dimensions. +// TODO(b/149952582): Support arbitrary dimension in SpaceToBatchND. +const int kInputOutputMinDimensionNum = 3; +const int kInputOutputMaxDimensionNum = 4; + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE_EQ(context, NumInputs(node), 3); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + + const TfLiteTensor *input = GetInput(context, node, kInputTensor); + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + TF_LITE_ENSURE(context, input != nullptr && output != nullptr); + + TF_LITE_ENSURE(context, NumDimensions(input) >= kInputOutputMinDimensionNum); + TF_LITE_ENSURE(context, NumDimensions(output) >= kInputOutputMinDimensionNum); + TF_LITE_ENSURE(context, NumDimensions(input) <= kInputOutputMaxDimensionNum); + TF_LITE_ENSURE(context, NumDimensions(output) <= kInputOutputMaxDimensionNum); + TF_LITE_ENSURE_TYPES_EQ(context, input->type, output->type); + + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + const TfLiteEvalTensor *block_shape = + tflite::micro::GetEvalInput(context, node, kBlockShapeTensor); + const TfLiteEvalTensor *crops = + tflite::micro::GetEvalInput(context, node, kCropsTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + switch (input->type) { // Already know in/out types are same. + case kTfLiteFloat32: + reference_ops::BatchToSpaceND( + tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(block_shape), + tflite::micro::GetTensorData(block_shape), + tflite::micro::GetTensorShape(crops), + tflite::micro::GetTensorData(crops), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + break; + case kTfLiteInt8: + reference_ops::BatchToSpaceND( + tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(block_shape), + tflite::micro::GetTensorData(block_shape), + tflite::micro::GetTensorShape(crops), + tflite::micro::GetTensorData(crops), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + break; + default: + TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.", + TfLiteTypeGetName(input->type), input->type); + return kTfLiteError; + } + return kTfLiteOk; +} + +} // namespace. + +TfLiteRegistration Register_BATCH_TO_SPACE_ND() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/batch_to_space_nd_test.cc b/components/tflite/tensorflow/lite/micro/kernels/batch_to_space_nd_test.cc new file mode 100644 index 00000000..dae45378 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/batch_to_space_nd_test.cc @@ -0,0 +1,160 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +constexpr int kBasicInputOutputSize = 16; +int basic_input_dims[] = { 4, 4, 2, 2, 1 }; +const float basic_input[kBasicInputOutputSize] = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 +}; +int basic_block_shape_dims[] = { 1, 2 }; +const int32_t basic_block_shape[] = { 2, 2 }; +int basic_crops_dims[] = { 1, 4 }; +const int32_t basic_crops[] = { 0, 0, 0, 0 }; +int basic_output_dims[] = { 4, 1, 4, 4, 1 }; +const float basic_golden[kBasicInputOutputSize] = { 1, 5, 2, 6, 9, 13, 10, 14, + 3, 7, 4, 8, 11, 15, 12, 16 }; + +template +TfLiteStatus ValidateBatchToSpaceNdGoldens(TfLiteTensor *tensors, + int tensors_size, const T *golden, + T *output, int output_size) +{ + int inputs_array_data[] = { 3, 0, 1, 2 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 3 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = Register_BATCH_TO_SPACE_ND(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, nullptr); + + TF_LITE_ENSURE_STATUS(runner.InitAndPrepare()); + TF_LITE_ENSURE_STATUS(runner.Invoke()); + + for (int i = 0; i < output_size; ++i) { + // TODO(b/158102673): workaround for not having fatal test assertions. + TF_LITE_MICRO_EXPECT_EQ(golden[i], output[i]); + if (golden[i] != output[i]) { + return kTfLiteError; + } + } + return kTfLiteOk; +} + +TfLiteStatus TestBatchToSpaceNdFloat( + int *input_dims_data, const float *input_data, int *block_shape_dims_data, + const int32_t *block_shape_data, int *crops_dims_data, + const int32_t *crops_data, int *output_dims_data, const float *golden, + float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *block_shape_dims = IntArrayFromInts(block_shape_dims_data); + TfLiteIntArray *crops_dims = IntArrayFromInts(crops_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + + constexpr int inputs_size = 3; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(block_shape_data, block_shape_dims), + CreateTensor(crops_data, crops_dims), + CreateTensor(output_data, output_dims), + }; + + return ValidateBatchToSpaceNdGoldens(tensors, tensors_size, golden, + output_data, ElementCount(*output_dims)); +} + +template +TfLiteStatus TestBatchToSpaceNdQuantized( + int *input_dims_data, const float *input_data, T *input_quantized, + float input_scale, int input_zero_point, int *block_shape_dims_data, + const int32_t *block_shape_data, int *crops_dims_data, + const int32_t *crops_data, int *output_dims_data, const float *golden, + T *golden_quantized, float output_scale, int output_zero_point, + T *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *block_shape_dims = IntArrayFromInts(block_shape_dims_data); + TfLiteIntArray *crops_dims = IntArrayFromInts(crops_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + + constexpr int inputs_size = 3; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + tflite::testing::CreateQuantizedTensor(input_data, input_quantized, + input_dims, input_scale, + input_zero_point), + tflite::testing::CreateTensor(block_shape_data, block_shape_dims), + tflite::testing::CreateTensor(crops_data, crops_dims), + tflite::testing::CreateQuantizedTensor(output_data, output_dims, + output_scale, output_zero_point), + }; + tflite::Quantize(golden, golden_quantized, ElementCount(*output_dims), + output_scale, output_zero_point); + + return ValidateBatchToSpaceNdGoldens(tensors, tensors_size, golden_quantized, + output_data, ElementCount(*output_dims)); +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(BatchToSpaceBasicFloat) +{ + float output[tflite::testing::kBasicInputOutputSize]; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, + tflite::testing::TestBatchToSpaceNdFloat( + tflite::testing::basic_input_dims, tflite::testing::basic_input, + tflite::testing::basic_block_shape_dims, + tflite::testing::basic_block_shape, tflite::testing::basic_crops_dims, + tflite::testing::basic_crops, tflite::testing::basic_output_dims, + tflite::testing::basic_golden, output)); +} + +TF_LITE_MICRO_TEST(BatchToSpaceBasicInt8) +{ + int8_t output[tflite::testing::kBasicInputOutputSize]; + int8_t input_quantized[tflite::testing::kBasicInputOutputSize]; + int8_t golden_quantized[tflite::testing::kBasicInputOutputSize]; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, + tflite::testing::TestBatchToSpaceNdQuantized( + tflite::testing::basic_input_dims, tflite::testing::basic_input, + input_quantized, 1.0f, 0, tflite::testing::basic_block_shape_dims, + tflite::testing::basic_block_shape, tflite::testing::basic_crops_dims, + tflite::testing::basic_crops, tflite::testing::basic_output_dims, + tflite::testing::basic_golden, golden_quantized, 1.0f, 0, output)); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/cast.cc b/components/tflite/tensorflow/lite/micro/kernels/cast.cc new file mode 100644 index 00000000..d6851b0c --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/cast.cc @@ -0,0 +1,101 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace { + +constexpr int kInputTensor = 0; +constexpr int kOutputTensor = 0; + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + const TfLiteTensor *input = GetInput(context, node, kInputTensor); + TF_LITE_ENSURE(context, input != nullptr); + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + + return kTfLiteOk; +} + +template +void copyCast(const FromT *in, ToT *out, int num_elements) +{ + std::transform(in, in + num_elements, out, + [](FromT a) { return static_cast(a); }); +} + +template +TfLiteStatus copyToTensor(TfLiteContext *context, const FromT *in, + TfLiteEvalTensor *out, int num_elements) +{ + switch (out->type) { + case kTfLiteInt8: + copyCast(in, out->data.int8, num_elements); + break; + case kTfLiteFloat32: + copyCast(in, tflite::micro::GetTensorData(out), num_elements); + break; + default: + // Unsupported type. + TF_LITE_KERNEL_LOG(context, "Output type %s (%d) not supported.", + TfLiteTypeGetName(out->type), out->type); + } + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + int num_elements = MatchingFlatSize(tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorShape(output)); + + switch (input->type) { + case kTfLiteInt8: + return copyToTensor(context, input->data.int8, output, num_elements); + case kTfLiteFloat32: + return copyToTensor(context, tflite::micro::GetTensorData(input), + output, num_elements); + default: + // Unsupported type. + TF_LITE_KERNEL_LOG(context, "Input type %s (%d) not supported.", + TfLiteTypeGetName(input->type), input->type); + } + return kTfLiteOk; +} +} // namespace + +TfLiteRegistration Register_CAST() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/cast_test.cc b/components/tflite/tensorflow/lite/micro/kernels/cast_test.cc new file mode 100644 index 00000000..e99c6411 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/cast_test.cc @@ -0,0 +1,121 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +void TestCastFloatToInt8(int *input_dims_data, const float *input_data, + const int8_t *expected_output_data, + int8_t *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(input_dims_data); + const int output_dims_count = ElementCount(*output_dims); + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims), + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = Register_CAST(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output_data[i], output_data[i]); + } +} + +void TestCastInt8ToFloat(int *input_dims_data, const int8_t *input_data, + const float *expected_output_data, + float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(input_dims_data); + const int output_dims_count = ElementCount(*output_dims); + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims), + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = Register_CAST(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output_data[i], output_data[i]); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(CastFloatToInt8) +{ + int8_t output_data[6]; + int input_dims[] = { 2, 3, 2 }; + + // TODO(b/178391195): Test negative and out-of-range numbers. + const float input_values[] = { 100.f, 1.0f, 0.f, 0.4f, 1.999f, 1.1f }; + const int8_t golden[] = { 100, 1, 0, 0, 1, 1 }; + tflite::testing::TestCastFloatToInt8(input_dims, input_values, golden, + output_data); +} + +TF_LITE_MICRO_TEST(CastInt8ToFloat) +{ + float output_data[6]; + int input_dims[] = { 2, 3, 2 }; + const int8_t input_values[] = { 123, 0, 1, 2, 3, 4 }; + const float golden[] = { 123.f, 0.f, 1.f, 2.f, 3.f, 4.f }; + tflite::testing::TestCastInt8ToFloat(input_dims, input_values, golden, + output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/ceil.cc b/components/tflite/tensorflow/lite/micro/kernels/ceil.cc new file mode 100644 index 00000000..68fa16ad --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/ceil.cc @@ -0,0 +1,79 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/ceil.h" + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace ceil { + +constexpr int kInputTensor = 0; +constexpr int kOutputTensor = 0; + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteTensor *input = GetInput(context, node, kInputTensor); + TF_LITE_ENSURE(context, input != nullptr); + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + TF_LITE_ENSURE_TYPES_EQ(context, input->type, kTfLiteFloat32); + TF_LITE_ENSURE_TYPES_EQ(context, output->type, input->type); + TF_LITE_ENSURE_EQ(context, output->bytes, input->bytes); + TF_LITE_ENSURE_EQ(context, output->dims->size, input->dims->size); + for (int i = 0; i < output->dims->size; ++i) { + TF_LITE_ENSURE_EQ(context, output->dims->data[i], input->dims->data[i]); + } + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + reference_ops::Ceil(tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + + return kTfLiteOk; +} +} // namespace ceil + +TfLiteRegistration Register_CEIL() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/ceil::Prepare, + /*invoke=*/ceil::Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/ceil_test.cc b/components/tflite/tensorflow/lite/micro/kernels/ceil_test.cc new file mode 100644 index 00000000..9c7f292b --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/ceil_test.cc @@ -0,0 +1,94 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +void TestCeil(int *input_dims_data, const float *input_data, + const float *expected_output_data, float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(input_dims_data); + const int output_dims_count = ElementCount(*output_dims); + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims), + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = ops::micro::Register_CEIL(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output_data[i], output_data[i], 1e-5f); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(SingleDim) +{ + float output_data[2]; + int input_dims[] = { 1, 2 }; + const float input_values[] = { 8.5, 0.0 }; + const float golden[] = { 9, 0 }; + tflite::testing::TestCeil(input_dims, input_values, golden, output_data); +} + +TF_LITE_MICRO_TEST(MultiDims) +{ + float output_data[10]; + int input_dims[] = { 4, 2, 1, 1, 5 }; + const float input_values[] = { + 0.0001, + 8.0001, + 0.9999, + 9.9999, + 0.5, + -0.0001, + -8.0001, + -0.9999, + -9.9999, + -0.5, + }; + const float golden[] = { 1, 9, 1, 10, 1, 0, -8, 0, -9, 0 }; + tflite::testing::TestCeil(input_dims, input_values, golden, output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/circular_buffer.cc b/components/tflite/tensorflow/lite/micro/kernels/circular_buffer.cc new file mode 100644 index 00000000..fe14781b --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/circular_buffer.cc @@ -0,0 +1,198 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +/* + * The circular buffer custom operator is used to implement strided streaming + * convolutions on TFLite Micro. Each time this operator is invoked, it checks + * whether or not to run, based on a predetermined stride in time. If the op + * runs, it inserts the input into the end of the output buffer and shifts the + * output values towards the start of the buffer. It discards the oldest value + * in the output buffer. + * + * Input: [, , , ] + * + * After shifting: + * Output: [, , , ] + * + * We make some assumptions in this custom operator: + * - Input shape must be [1, 1, 1, depth] + * - Output shape must be [1, num_slots, 1, depth] + * - Input and output types must match. + * - Input and output quantization params must be identical. + */ +namespace tflite { +namespace ops { +namespace micro { +namespace circular_buffer { + +namespace { + +// The CircularBuffer op has one input and one output tensor. +constexpr int kInputTensor = 0; +constexpr int kOutputTensor = 0; + +// TODO(b/149795762): Add this to TfLiteStatus enum. +constexpr TfLiteStatus kTfLiteAbort = static_cast(-9); + +// These fields control the stride period of a strided streaming model. This op +// returns kTfLiteAbort until cycles_until_run-- is zero. At this time, +// cycles_until_run is reset to cycles_max. +struct OpData { + int cycles_until_run; + int cycles_max; +}; + +} // namespace + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + OpData *op_data = static_cast( + context->AllocatePersistentBuffer(context, sizeof(OpData))); + + if (buffer != nullptr && length > 0) { + const uint8_t *buffer_t = reinterpret_cast(buffer); + const flexbuffers::Map &m = + tflite::micro::FlexbuffersWrapperGetRootAsMap(buffer_t, length); + op_data->cycles_max = + tflite::micro::FlexbuffersWrapperAsInt32(m, "cycles_max"); + } else { + op_data->cycles_max = 0; + } + + return op_data; +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteTensor *input = GetInput(context, node, kInputTensor); + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + + TFLITE_DCHECK(node->user_data != nullptr); + OpData *op_data = static_cast(node->user_data); + + TF_LITE_ENSURE(context, input != nullptr); + TF_LITE_ENSURE(context, output != nullptr); + TF_LITE_ENSURE_EQ(context, input->dims->data[0], output->dims->data[0]); + TF_LITE_ENSURE_EQ(context, 1, input->dims->data[1]); + TF_LITE_ENSURE_EQ(context, input->dims->data[2], output->dims->data[2]); + TF_LITE_ENSURE_EQ(context, output->dims->data[3], input->dims->data[3]); + + TF_LITE_ENSURE_TYPES_EQ(context, input->type, output->type); + + // The circular buffer custom operator currently only supports int8. + TF_LITE_ENSURE_TYPES_EQ(context, input->type, kTfLiteInt8); + + if (op_data->cycles_max <= 0) { + // The last circular buffer layer simply accumulates outputs, and does not + // run periodically. + // TODO(b/150001379): Move this special case logic to the tflite flatbuffer. + static int cb_prepare_count = 0; + cb_prepare_count++; + // These checks specifically work for the only two streaming models + // supported on TFLM. They use the shape of the output tensor along with the + // layer number to determine if the circular buffer period should be 1 or 2. + + // These models are outlined int the following documents: + // https://docs.google.com/document/d/1lc_G2ZFhjiKFo02UHjBaljye1xsL0EkfybkaVELEE3Q/edit?usp=sharing + // https://docs.google.com/document/d/1pGc42PuWyrk-Jy1-9qeqtggvsmHr1ifz8Lmqfpr2rKA/edit?usp=sharing + if (output->dims->data[1] == 5 || output->dims->data[1] == 13 || + output->dims->data[1] == 25 || + (cb_prepare_count == 5 && output->dims->data[2] == 2 && + output->dims->data[3] == 96)) { + op_data->cycles_max = 1; + cb_prepare_count = 0; + } else { + op_data->cycles_max = 2; + } + } + op_data->cycles_until_run = op_data->cycles_max; + node->user_data = op_data; + + return kTfLiteOk; +} + +// Shifts buffer over by the output depth, and write new input to end of buffer. +// num_slots is the number of samples stored in the output buffer. +// depth is the size of each sample. +void EvalInt8(const int8_t *input, int num_slots, int depth, int8_t *output) +{ + memmove(output, &output[depth], (num_slots - 1) * depth); + memcpy(&output[(num_slots - 1) * depth], input, depth); +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + TFLITE_DCHECK(node->user_data != nullptr); + OpData *data = reinterpret_cast(node->user_data); + + int num_slots = output->dims->data[1]; + int depth = output->dims->data[2] * output->dims->data[3]; + + if (input->type == kTfLiteInt8) { + EvalInt8(tflite::micro::GetTensorData(input), num_slots, depth, + tflite::micro::GetTensorData(output)); + } else { + TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.", + TfLiteTypeGetName(input->type), input->type); + return kTfLiteError; + } + + if (--data->cycles_until_run != 0) { + // Signal the interpreter to end current run if the delay before op invoke + // has not been reached. + // TODO(b/149795762): Add kTfLiteAbort to TfLiteStatus enum. + return static_cast(kTfLiteAbort); + } + + data->cycles_until_run = data->cycles_max; + + return kTfLiteOk; +} + +} // namespace circular_buffer + +TfLiteRegistration *Register_CIRCULAR_BUFFER() +{ + static TfLiteRegistration r = { /*init=*/circular_buffer::Init, + /*free=*/nullptr, + /*prepare=*/circular_buffer::Prepare, + /*invoke=*/circular_buffer::Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; + return &r; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/circular_buffer_flexbuffers_generated_data.cc b/components/tflite/tensorflow/lite/micro/kernels/circular_buffer_flexbuffers_generated_data.cc new file mode 100644 index 00000000..915f9fb0 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/circular_buffer_flexbuffers_generated_data.cc @@ -0,0 +1,44 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// This file is generated. See: +// third_party/tensorflow/lite/micro/kernels/test_data_generation/README.md + +#include "tensorflow/lite/micro/kernels/circular_buffer_flexbuffers_generated_data.h" + +const int g_gen_data_size_circular_buffer_config = 21; +const unsigned char g_gen_data_circular_buffer_config[] = { + 0x63, + 0x79, + 0x63, + 0x6c, + 0x65, + 0x73, + 0x5f, + 0x6d, + 0x61, + 0x78, + 0x00, + 0x01, + 0x0c, + 0x01, + 0x01, + 0x01, + 0x01, + 0x04, + 0x02, + 0x24, + 0x01, +}; diff --git a/components/tflite/tensorflow/lite/micro/kernels/circular_buffer_flexbuffers_generated_data.h b/components/tflite/tensorflow/lite/micro/kernels/circular_buffer_flexbuffers_generated_data.h new file mode 100644 index 00000000..2fbf4fe9 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/circular_buffer_flexbuffers_generated_data.h @@ -0,0 +1,22 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_KERNELS_FLEXBUFFERS_GENERATED_DATA_H +#define TENSORFLOW_LITE_MICRO_KERNELS_FLEXBUFFERS_GENERATED_DATA_H + +extern const int g_gen_data_size_circular_buffer_config; +extern const unsigned char g_gen_data_circular_buffer_config[]; + +#endif diff --git a/components/tflite/tensorflow/lite/micro/kernels/circular_buffer_test.cc b/components/tflite/tensorflow/lite/micro/kernels/circular_buffer_test.cc new file mode 100644 index 00000000..b9b769a4 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/circular_buffer_test.cc @@ -0,0 +1,250 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/circular_buffer_flexbuffers_generated_data.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/kernels/micro_ops.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +constexpr int kRunPeriod = 2; + +// TODO(b/149795762): Add this to TfLiteStatus enum. +constexpr TfLiteStatus kTfLiteAbort = static_cast(-9); + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(OutputTensorLength4) +{ + constexpr int depth = 3; + constexpr int num_slots = 4; + int8_t input_data[depth]; + int8_t output_data[depth * num_slots]; + + memset(output_data, 0, sizeof(output_data)); + + // There are four input dimensions - [1, 1, 1, depth]. + int input_dims[] = { 4, 1, 1, 1, depth }; + // There are four output dimensions - [1, num_slots, 1, depth]. + int output_dims[] = { 4, 1, num_slots, 1, depth }; + + TfLiteIntArray *input_tensor_dims = + tflite::testing::IntArrayFromInts(input_dims); + TfLiteIntArray *output_tensor_dims = + tflite::testing::IntArrayFromInts(output_dims); + + const int output_dims_count = tflite::ElementCount(*output_tensor_dims); + + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + tflite::testing::CreateQuantizedTensor(input_data, input_tensor_dims, 1, + 0), + tflite::testing::CreateQuantizedTensor(output_data, output_tensor_dims, 1, + 0), + }; + + // There is one input - tensor 0. + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = + tflite::testing::IntArrayFromInts(inputs_array_data); + // There is one output - tensor 1. + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = + tflite::testing::IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration *registration = + tflite::ops::micro::Register_CIRCULAR_BUFFER(); + tflite::micro::KernelRunner runner = tflite::micro::KernelRunner( + *registration, tensors, tensors_size, inputs_array, outputs_array, + /*builtin_data=*/nullptr); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + + const int8_t goldens[5][16] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 }, + { 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6 }, + { 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }, + { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } }; + + // Expect the circular buffer to run every other invoke for 4xN output. + for (int i = 0; i < 5; i++) { + for (int j = 0; j < depth; j++) { + input_data[j] = i * depth + j + 1; + } + TfLiteStatus status = runner.Invoke(); + + for (int j = 0; j < output_dims_count; ++j) { + TF_LITE_MICRO_EXPECT_EQ(goldens[i][j], output_data[j]); + } + + // Every kRunPeriod iterations, the circular buffer should return kTfLiteOk. + if (i % tflite::testing::kRunPeriod == tflite::testing::kRunPeriod - 1) { + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, status); + } else { + TF_LITE_MICRO_EXPECT_EQ(tflite::testing::kTfLiteAbort, status); + } + } +} + +TF_LITE_MICRO_TEST(OutputTensorOnEveryIterationLength4) +{ + constexpr int depth = 3; + constexpr int num_slots = 4; + int8_t input_data[depth]; + int8_t output_data[depth * num_slots]; + + memset(output_data, 0, sizeof(output_data)); + + // There are four input dimensions - [1, 1, 1, depth]. + int input_dims[] = { 4, 1, 1, 1, depth }; + // There are four output dimensions - [1, num_slots, 1, depth]. + int output_dims[] = { 4, 1, num_slots, 1, depth }; + + TfLiteIntArray *input_tensor_dims = + tflite::testing::IntArrayFromInts(input_dims); + TfLiteIntArray *output_tensor_dims = + tflite::testing::IntArrayFromInts(output_dims); + + const int output_dims_count = tflite::ElementCount(*output_tensor_dims); + + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + tflite::testing::CreateQuantizedTensor(input_data, input_tensor_dims, 1, + 0), + tflite::testing::CreateQuantizedTensor(output_data, output_tensor_dims, 1, + 0), + }; + + // There is one input - tensor 0. + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = + tflite::testing::IntArrayFromInts(inputs_array_data); + // There is one output - tensor 1. + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = + tflite::testing::IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration *registration = + tflite::ops::micro::Register_CIRCULAR_BUFFER(); + tflite::micro::KernelRunner runner = tflite::micro::KernelRunner( + *registration, tensors, tensors_size, inputs_array, outputs_array, + /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, runner.InitAndPrepare(reinterpret_cast( + g_gen_data_circular_buffer_config), + g_gen_data_size_circular_buffer_config)); + + const int8_t goldens[5][16] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 }, + { 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6 }, + { 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }, + { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } }; + + // Expect the circular buffer to run every other invoke for 4xN output. + for (int i = 0; i < 5; i++) { + for (int j = 0; j < depth; j++) { + input_data[j] = i * depth + j + 1; + } + TfLiteStatus status = runner.Invoke(); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, status); + + for (int j = 0; j < output_dims_count; ++j) { + TF_LITE_MICRO_EXPECT_EQ(goldens[i][j], output_data[j]); + } + } +} + +TF_LITE_MICRO_TEST(OutputTensorLength5) +{ + constexpr int depth = 4; + constexpr int num_slots = 5; + int8_t input_data[depth]; + int8_t output_data[depth * num_slots]; + + memset(output_data, 0, sizeof(output_data)); + int input_dims[] = { 4, 1, 1, 1, depth }; + int output_dims[] = { 4, 1, num_slots, 1, depth }; + TfLiteIntArray *input_tensor_dims = + tflite::testing::IntArrayFromInts(input_dims); + TfLiteIntArray *output_tensor_dims = + tflite::testing::IntArrayFromInts(output_dims); + + const int output_dims_count = tflite::ElementCount(*output_tensor_dims); + + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + tflite::testing::CreateQuantizedTensor(input_data, input_tensor_dims, 1, + 0), + tflite::testing::CreateQuantizedTensor(output_data, output_tensor_dims, 1, + 0), + }; + + // There is one input - tensor 0. + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = + tflite::testing::IntArrayFromInts(inputs_array_data); + // There is one output - tensor 1. + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = + tflite::testing::IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration *registration = + tflite::ops::micro::Register_CIRCULAR_BUFFER(); + tflite::micro::KernelRunner runner = tflite::micro::KernelRunner( + *registration, tensors, tensors_size, inputs_array, outputs_array, + /*builtin_data=*/nullptr); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + + const int8_t goldens[6][20] = { + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8 }, + { 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }, + { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }, + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }, + { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 } + }; + + // Expect circular buffer to run every cycle for 5xN output. + for (int i = 0; i < 6; i++) { + for (int j = 0; j < depth; j++) { + input_data[j] = i * depth + j + 1; + } + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int j = 0; j < output_dims_count; ++j) { + TF_LITE_MICRO_EXPECT_EQ(goldens[i][j], output_data[j]); + } + } +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/comparisons.cc b/components/tflite/tensorflow/lite/micro/kernels/comparisons.cc new file mode 100644 index 00000000..0ee9e28c --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/comparisons.cc @@ -0,0 +1,706 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/kernels/internal/reference/comparisons.h" + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace comparisons { +namespace { + +struct OpData { + ComparisonParams params; +}; + +constexpr int kInputTensor1 = 0; +constexpr int kInputTensor2 = 1; +constexpr int kOutputTensor = 0; + +TfLiteStatus EqualEval(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + const OpData *data = static_cast(node->user_data); + + const TfLiteEvalTensor *input1 = + tflite::micro::GetEvalInput(context, node, kInputTensor1); + const TfLiteEvalTensor *input2 = + tflite::micro::GetEvalInput(context, node, kInputTensor2); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + RuntimeShape input1_shape = tflite::micro::GetTensorShape(input1); + RuntimeShape input2_shape = tflite::micro::GetTensorShape(input2); + RuntimeShape output_shape = tflite::micro::GetTensorShape(output); + bool *output_data = tflite::micro::GetTensorData(output); + + bool requires_broadcast = !tflite::micro::HaveSameShapes(input1, input2); + switch (input1->type) { + case kTfLiteBool: + requires_broadcast ? reference_ops::Broadcast4DSlowEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::EqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteFloat32: + requires_broadcast ? reference_ops::Broadcast4DSlowEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::EqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteInt32: + requires_broadcast ? reference_ops::Broadcast4DSlowEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::EqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteInt64: + requires_broadcast ? reference_ops::Broadcast4DSlowEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::EqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteUInt8: + requires_broadcast ? reference_ops::Broadcast4DSlowEqualWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::EqualWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteInt8: + requires_broadcast ? reference_ops::Broadcast4DSlowEqualWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::EqualWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + default: + TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.", + TfLiteTypeGetName(input1->type), input1->type); + return kTfLiteError; + } + return kTfLiteOk; +} + +// TODO(renjieliu): Refactor the logic to avoid duplications. +TfLiteStatus NotEqualEval(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + const OpData *data = static_cast(node->user_data); + + const TfLiteEvalTensor *input1 = + tflite::micro::GetEvalInput(context, node, kInputTensor1); + const TfLiteEvalTensor *input2 = + tflite::micro::GetEvalInput(context, node, kInputTensor2); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + RuntimeShape input1_shape = tflite::micro::GetTensorShape(input1); + RuntimeShape input2_shape = tflite::micro::GetTensorShape(input2); + RuntimeShape output_shape = tflite::micro::GetTensorShape(output); + bool *output_data = tflite::micro::GetTensorData(output); + + bool requires_broadcast = !tflite::micro::HaveSameShapes(input1, input2); + switch (input1->type) { + case kTfLiteBool: + requires_broadcast ? reference_ops::Broadcast4DSlowNotEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::NotEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteFloat32: + requires_broadcast ? reference_ops::Broadcast4DSlowNotEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::NotEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteInt32: + requires_broadcast ? reference_ops::Broadcast4DSlowNotEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::NotEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteInt64: + requires_broadcast ? reference_ops::Broadcast4DSlowNotEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::NotEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteUInt8: + requires_broadcast ? reference_ops::Broadcast4DSlowNotEqualWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::NotEqualWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteInt8: + requires_broadcast ? reference_ops::Broadcast4DSlowNotEqualWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::NotEqualWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + default: + TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.", + TfLiteTypeGetName(input1->type), input1->type); + return kTfLiteError; + } + return kTfLiteOk; +} + +TfLiteStatus GreaterEval(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + const OpData *data = static_cast(node->user_data); + + const TfLiteEvalTensor *input1 = + tflite::micro::GetEvalInput(context, node, kInputTensor1); + const TfLiteEvalTensor *input2 = + tflite::micro::GetEvalInput(context, node, kInputTensor2); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + RuntimeShape input1_shape = tflite::micro::GetTensorShape(input1); + RuntimeShape input2_shape = tflite::micro::GetTensorShape(input2); + RuntimeShape output_shape = tflite::micro::GetTensorShape(output); + bool *output_data = tflite::micro::GetTensorData(output); + + bool requires_broadcast = !tflite::micro::HaveSameShapes(input1, input2); + switch (input1->type) { + case kTfLiteFloat32: + requires_broadcast ? reference_ops::Broadcast4DSlowGreaterNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::GreaterNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteInt32: + requires_broadcast ? reference_ops::Broadcast4DSlowGreaterNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::GreaterNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteInt64: + requires_broadcast ? reference_ops::Broadcast4DSlowGreaterNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::GreaterNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteUInt8: + requires_broadcast ? reference_ops::Broadcast4DSlowGreaterWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::GreaterWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteInt8: + requires_broadcast ? reference_ops::Broadcast4DSlowGreaterWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::GreaterWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + default: + TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.", + TfLiteTypeGetName(input1->type), input1->type); + return kTfLiteError; + } + return kTfLiteOk; +} + +TfLiteStatus GreaterEqualEval(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + const OpData *data = static_cast(node->user_data); + + const TfLiteEvalTensor *input1 = + tflite::micro::GetEvalInput(context, node, kInputTensor1); + const TfLiteEvalTensor *input2 = + tflite::micro::GetEvalInput(context, node, kInputTensor2); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + RuntimeShape input1_shape = tflite::micro::GetTensorShape(input1); + RuntimeShape input2_shape = tflite::micro::GetTensorShape(input2); + RuntimeShape output_shape = tflite::micro::GetTensorShape(output); + bool *output_data = tflite::micro::GetTensorData(output); + + bool requires_broadcast = !tflite::micro::HaveSameShapes(input1, input2); + switch (input1->type) { + case kTfLiteFloat32: + requires_broadcast ? reference_ops::Broadcast4DSlowGreaterEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::GreaterEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteInt32: + requires_broadcast ? reference_ops::Broadcast4DSlowGreaterEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::GreaterEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteInt64: + requires_broadcast ? reference_ops::Broadcast4DSlowGreaterEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::GreaterEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteUInt8: + requires_broadcast ? reference_ops::Broadcast4DSlowGreaterEqualWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::GreaterEqualWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteInt8: + requires_broadcast ? reference_ops::Broadcast4DSlowGreaterEqualWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::GreaterEqualWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + default: + TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.", + TfLiteTypeGetName(input1->type), input1->type); + return kTfLiteError; + } + return kTfLiteOk; +} + +TfLiteStatus LessEval(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + const OpData *data = static_cast(node->user_data); + + const TfLiteEvalTensor *input1 = + tflite::micro::GetEvalInput(context, node, kInputTensor1); + const TfLiteEvalTensor *input2 = + tflite::micro::GetEvalInput(context, node, kInputTensor2); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + RuntimeShape input1_shape = tflite::micro::GetTensorShape(input1); + RuntimeShape input2_shape = tflite::micro::GetTensorShape(input2); + RuntimeShape output_shape = tflite::micro::GetTensorShape(output); + bool *output_data = tflite::micro::GetTensorData(output); + + bool requires_broadcast = !tflite::micro::HaveSameShapes(input1, input2); + switch (input1->type) { + case kTfLiteFloat32: + requires_broadcast ? reference_ops::Broadcast4DSlowLessNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::LessNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteInt32: + requires_broadcast ? reference_ops::Broadcast4DSlowLessNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::LessNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteInt64: + requires_broadcast ? reference_ops::Broadcast4DSlowLessNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::LessNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteUInt8: + requires_broadcast ? reference_ops::Broadcast4DSlowLessWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::LessWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteInt8: + requires_broadcast ? reference_ops::Broadcast4DSlowLessWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::LessWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + default: + TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.", + TfLiteTypeGetName(input1->type), input1->type); + return kTfLiteError; + } + return kTfLiteOk; +} + +TfLiteStatus LessEqualEval(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + const OpData *data = static_cast(node->user_data); + + const TfLiteEvalTensor *input1 = + tflite::micro::GetEvalInput(context, node, kInputTensor1); + const TfLiteEvalTensor *input2 = + tflite::micro::GetEvalInput(context, node, kInputTensor2); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + RuntimeShape input1_shape = tflite::micro::GetTensorShape(input1); + RuntimeShape input2_shape = tflite::micro::GetTensorShape(input2); + RuntimeShape output_shape = tflite::micro::GetTensorShape(output); + bool *output_data = tflite::micro::GetTensorData(output); + + bool requires_broadcast = !tflite::micro::HaveSameShapes(input1, input2); + switch (input1->type) { + case kTfLiteFloat32: + requires_broadcast ? reference_ops::Broadcast4DSlowLessEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::LessEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteInt32: + requires_broadcast ? reference_ops::Broadcast4DSlowLessEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::LessEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteInt64: + requires_broadcast ? reference_ops::Broadcast4DSlowLessEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::LessEqualNoScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteUInt8: + requires_broadcast ? reference_ops::Broadcast4DSlowLessEqualWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::LessEqualWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + case kTfLiteInt8: + requires_broadcast ? reference_ops::Broadcast4DSlowLessEqualWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data) : + reference_ops::LessEqualWithScaling( + data->params, input1_shape, + tflite::micro::GetTensorData(input1), input2_shape, + tflite::micro::GetTensorData(input2), output_shape, + output_data); + break; + default: + TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.", + TfLiteTypeGetName(input1->type), input1->type); + return kTfLiteError; + } + return kTfLiteOk; +} + +} // namespace + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(OpData)); +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + OpData *data = static_cast(node->user_data); + + const TfLiteTensor *input1 = GetInput(context, node, kInputTensor1); + TF_LITE_ENSURE(context, input1 != nullptr); + const TfLiteTensor *input2 = GetInput(context, node, kInputTensor2); + TF_LITE_ENSURE(context, input2 != nullptr); + + if (input1->type == kTfLiteUInt8 || input1->type == kTfLiteInt8) { + auto input1_offset = -input1->params.zero_point; + auto input2_offset = -input2->params.zero_point; + const int kLeftShift = 8; + + int32_t input1_multiplier; + int input1_shift; + QuantizeMultiplierSmallerThanOneExp( + static_cast(input1->params.scale), &input1_multiplier, + &input1_shift); + int32_t input2_multiplier; + int input2_shift; + QuantizeMultiplierSmallerThanOneExp( + static_cast(input2->params.scale), &input2_multiplier, + &input2_shift); + + data->params.left_shift = kLeftShift; + data->params.input1_offset = input1_offset; + data->params.input1_multiplier = input1_multiplier; + data->params.input1_shift = input1_shift; + data->params.input2_offset = input2_offset; + data->params.input2_multiplier = input2_multiplier; + data->params.input2_shift = input2_shift; + } + + return kTfLiteOk; +} + +} // namespace comparisons + +TfLiteRegistration Register_EQUAL() +{ + return { /*init=*/comparisons::Init, + /*free=*/nullptr, + /*prepare=*/comparisons::Prepare, + /*invoke=*/comparisons::EqualEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +TfLiteRegistration Register_NOT_EQUAL() +{ + return { /*init=*/comparisons::Init, + /*free=*/nullptr, + /*prepare=*/comparisons::Prepare, + /*invoke=*/comparisons::NotEqualEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +TfLiteRegistration Register_GREATER() +{ + return { /*init=*/comparisons::Init, + /*free=*/nullptr, + /*prepare=*/comparisons::Prepare, + /*invoke=*/comparisons::GreaterEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +TfLiteRegistration Register_GREATER_EQUAL() +{ + return { /*init=*/comparisons::Init, + /*free=*/nullptr, + /*prepare=*/comparisons::Prepare, + /*invoke=*/comparisons::GreaterEqualEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +TfLiteRegistration Register_LESS() +{ + return { /*init=*/comparisons::Init, + /*free=*/nullptr, + /*prepare=*/comparisons::Prepare, + /*invoke=*/comparisons::LessEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +TfLiteRegistration Register_LESS_EQUAL() +{ + return { /*init=*/comparisons::Init, + /*free=*/nullptr, + /*prepare=*/comparisons::Prepare, + /*invoke=*/comparisons::LessEqualEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/comparisons_test.cc b/components/tflite/tensorflow/lite/micro/kernels/comparisons_test.cc new file mode 100644 index 00000000..5ec73210 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/comparisons_test.cc @@ -0,0 +1,1172 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +constexpr int inputs_size = 2; +constexpr int outputs_size = 1; +constexpr int tensors_size = inputs_size + outputs_size; + +void TestComparison(const TfLiteRegistration ®istration, + TfLiteTensor *tensors, bool *expected_output_data, + bool *output_data) +{ + const int output_dims_count = ElementCount(*tensors[inputs_size].dims); + + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output_data[i], output_data[i]); + } +} + +void TestComparisonFloat(const TfLiteRegistration ®istration, + int *input1_dims_data, float *input1_data, + int *input2_dims_data, float *input2_data, + bool *expected_output_data, int *output_dims_data, + bool *output_data) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input1_data, input1_dims), + CreateTensor(input2_data, input2_dims), + CreateTensor(output_data, output_dims), + }; + + TestComparison(registration, tensors, expected_output_data, output_data); +} + +void TestComparisonBool(const TfLiteRegistration ®istration, + int *input1_dims_data, bool *input1_data, + int *input2_dims_data, bool *input2_data, + bool *expected_output_data, int *output_dims_data, + bool *output_data) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input1_data, input1_dims), + CreateTensor(input2_data, input2_dims), + CreateTensor(output_data, output_dims), + }; + + TestComparison(registration, tensors, expected_output_data, output_data); +} + +void TestComparisonInt(const TfLiteRegistration ®istration, + int *input1_dims_data, int32_t *input1_data, + int *input2_dims_data, int32_t *input2_data, + bool *expected_output_data, int *output_dims_data, + bool *output_data) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input1_data, input1_dims), + CreateTensor(input2_data, input2_dims), + CreateTensor(output_data, output_dims), + }; + + TestComparison(registration, tensors, expected_output_data, output_data); +} + +void TestComparisonQuantizedUInt8(const TfLiteRegistration ®istration, + int *input1_dims_data, float *input1_data, + uint8_t *input1_quantized, float input1_scale, + int input1_zero_point, int *input2_dims_data, + float *input2_data, uint8_t *input2_quantized, + float input2_scale, int input2_zero_point, + bool *expected_output_data, + int *output_dims_data, bool *output_data) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(input1_data, input1_quantized, input1_dims, + input1_scale, input1_zero_point), + CreateQuantizedTensor(input2_data, input2_quantized, input2_dims, + input2_scale, input2_zero_point), + CreateTensor(output_data, output_dims), + }; + + TestComparison(registration, tensors, expected_output_data, output_data); +} + +void TestComparisonQuantizedInt8(const TfLiteRegistration ®istration, + int *input1_dims_data, float *input1_data, + int8_t *input1_quantized, float input1_scale, + int input1_zero_point, int *input2_dims_data, + float *input2_data, int8_t *input2_quantized, + float input2_scale, int input2_zero_point, + bool *expected_output_data, + int *output_dims_data, bool *output_data) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(input1_data, input1_quantized, input1_dims, + input1_scale, input1_zero_point), + CreateQuantizedTensor(input2_data, input2_quantized, input2_dims, + input2_scale, input2_zero_point), + CreateTensor(output_data, output_dims), + }; + + TestComparison(registration, tensors, expected_output_data, output_data); +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(EqualBool) +{ + int input1_dim[] = { 4, 1, 1, 1, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 4 }; + + bool input1_data[] = { true, false, true, false }; + bool input2_data[] = { true, true, false, false }; + + bool expected_data[] = { true, false, false, true }; + int expected_dim[] = { 4, 1, 1, 1, 4 }; + + bool output_data[4]; + tflite::testing::TestComparisonBool( + tflite::ops::micro::Register_EQUAL(), input1_dim, input1_data, input2_dim, + input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(EqualFloat) +{ + int input1_dim[] = { 4, 1, 1, 1, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 4 }; + + float input1_data[] = { 0.1, 0.9, 0.7, 0.3 }; + float input2_data[] = { 0.1, 0.2, 0.6, 0.5 }; + + bool expected_data[] = { true, false, false, false }; + int expected_dim[] = { 4, 1, 1, 1, 4 }; + + bool output_data[4]; + tflite::testing::TestComparisonFloat( + tflite::ops::micro::Register_EQUAL(), input1_dim, input1_data, input2_dim, + input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(EqualInt) +{ + int input1_dim[] = { 4, 1, 1, 1, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 4 }; + + int32_t input1_data[] = { -1, 9, 7, 3 }; + int32_t input2_data[] = { 1, 2, 7, 5 }; + + bool expected_data[] = { false, false, true, false }; + int expected_dim[] = { 4, 1, 1, 1, 4 }; + bool output_data[4]; + tflite::testing::TestComparisonInt( + tflite::ops::micro::Register_EQUAL(), input1_dim, input1_data, input2_dim, + input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(EqualBroadcast) +{ + int input1_dim[] = { 4, 1, 1, 1, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 1 }; + + int32_t input1_data[] = { -1, 9, 7, 3 }; + int32_t input2_data[] = { 7 }; + + bool expected_data[] = { false, false, true, false }; + int expected_dim[] = { 4, 1, 1, 1, 4 }; + + bool output_data[4]; + tflite::testing::TestComparisonInt( + tflite::ops::micro::Register_EQUAL(), input1_dim, input1_data, input2_dim, + input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(EqualBroadcastTwoD) +{ + int input1_dim[] = { 4, 1, 1, 2, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 4 }; + + int32_t input1_data[] = { -1, 9, 7, 3, 2, 4, 2, 8 }; + int32_t input2_data[] = { 7, 1, 2, 4 }; + + bool expected_data[] = { false, false, false, false, + false, false, true, false }; + int expected_dim[] = { 4, 1, 1, 2, 4 }; + + bool output_data[8]; + tflite::testing::TestComparisonInt( + tflite::ops::micro::Register_EQUAL(), input1_dim, input1_data, input2_dim, + input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(NotEqualBool) +{ + int input1_dim[] = { 4, 1, 1, 1, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 4 }; + + bool input1_data[] = { true, false, true, false }; + bool input2_data[] = { true, true, false, false }; + + bool expected_data[] = { false, true, true, false }; + int expected_dim[] = { 4, 1, 1, 1, 4 }; + + bool output_data[4]; + tflite::testing::TestComparisonBool( + tflite::ops::micro::Register_NOT_EQUAL(), input1_dim, input1_data, + input2_dim, input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(NotEqualFloat) +{ + int input1_dim[] = { 4, 1, 1, 1, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 4 }; + + float input1_data[] = { 0.1, 0.9, 0.7, 0.3 }; + float input2_data[] = { 0.1, 0.2, 0.6, 0.5 }; + + bool expected_data[] = { false, true, true, true }; + int expected_dim[] = { 4, 1, 1, 1, 4 }; + + bool output_data[4]; + tflite::testing::TestComparisonFloat( + tflite::ops::micro::Register_NOT_EQUAL(), input1_dim, input1_data, + input2_dim, input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(NotEqualInt) +{ + int input1_dim[] = { 4, 1, 1, 1, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 4 }; + + int32_t input1_data[] = { -1, 9, 7, 3 }; + int32_t input2_data[] = { 1, 2, 7, 5 }; + + bool expected_data[] = { true, true, false, true }; + int expected_dim[] = { 4, 1, 1, 1, 4 }; + + bool output_data[4]; + tflite::testing::TestComparisonInt( + tflite::ops::micro::Register_NOT_EQUAL(), input1_dim, input1_data, + input2_dim, input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(NotEqualBroadcast) +{ + int input1_dim[] = { 4, 1, 1, 1, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 1 }; + + int32_t input1_data[] = { -1, 9, 7, 3 }; + int32_t input2_data[] = { 7 }; + + bool expected_data[] = { true, true, false, true }; + int expected_dim[] = { 4, 1, 1, 1, 4 }; + + bool output_data[4]; + tflite::testing::TestComparisonInt( + tflite::ops::micro::Register_NOT_EQUAL(), input1_dim, input1_data, + input2_dim, input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(NotEqualBroadcastTwoD) +{ + int input1_dim[] = { 4, 1, 1, 2, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 4 }; + + int32_t input1_data[] = { -1, 9, 7, 3, 2, 4, 2, 8 }; + int32_t input2_data[] = { 7, 1, 2, 4 }; + + bool expected_data[] = { true, true, true, true, true, true, false, true }; + int expected_dim[] = { 4, 1, 1, 2, 4 }; + + bool output_data[8]; + tflite::testing::TestComparisonInt( + tflite::ops::micro::Register_NOT_EQUAL(), input1_dim, input1_data, + input2_dim, input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(GreaterFloat) +{ + int input1_dim[] = { 4, 1, 1, 1, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 4 }; + + float input1_data[] = { 0.1, 0.9, 0.7, 0.3 }; + float input2_data[] = { 0.1, 0.2, 0.6, 0.5 }; + + bool expected_data[] = { false, true, true, false }; + int expected_dim[] = { 4, 1, 1, 1, 4 }; + + bool output_data[4]; + tflite::testing::TestComparisonFloat( + tflite::ops::micro::Register_GREATER(), input1_dim, input1_data, + input2_dim, input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(GreaterInt) +{ + int input1_dim[] = { 4, 1, 1, 1, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 4 }; + + int32_t input1_data[] = { -1, 9, 7, 3 }; + int32_t input2_data[] = { 1, 2, 7, 5 }; + + bool expected_data[] = { false, true, false, false }; + int expected_dim[] = { 4, 1, 1, 1, 4 }; + + bool output_data[4]; + tflite::testing::TestComparisonInt( + tflite::ops::micro::Register_GREATER(), input1_dim, input1_data, + input2_dim, input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(GreaterBroadcast) +{ + int input1_dim[] = { 4, 1, 1, 1, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 1 }; + + int32_t input1_data[] = { -1, 9, 7, 3 }; + int32_t input2_data[] = { 7 }; + + bool expected_data[] = { false, true, false, false }; + int expected_dim[] = { 4, 1, 1, 1, 4 }; + + bool output_data[4]; + tflite::testing::TestComparisonInt( + tflite::ops::micro::Register_GREATER(), input1_dim, input1_data, + input2_dim, input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(GreaterBroadcastTwoD) +{ + int input1_dim[] = { 4, 1, 1, 2, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 4 }; + + int32_t input1_data[] = { -1, 9, 7, 3, 2, 4, 2, 8 }; + int32_t input2_data[] = { 7, 1, 2, 4 }; + + bool expected_data[] = { false, true, true, false, false, true, false, true }; + int expected_dim[] = { 4, 1, 1, 2, 4 }; + + bool output_data[8]; + tflite::testing::TestComparisonInt( + tflite::ops::micro::Register_GREATER(), input1_dim, input1_data, + input2_dim, input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(GreaterEqualFloat) +{ + int input1_dim[] = { 4, 1, 1, 1, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 4 }; + + float input1_data[] = { 0.1, 0.9, 0.7, 0.3 }; + float input2_data[] = { 0.1, 0.2, 0.6, 0.5 }; + + bool expected_data[] = { true, true, true, false }; + int expected_dim[] = { 4, 1, 1, 1, 4 }; + + bool output_data[4]; + tflite::testing::TestComparisonFloat( + tflite::ops::micro::Register_GREATER_EQUAL(), input1_dim, input1_data, + input2_dim, input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(GreaterEqualInt) +{ + int input1_dim[] = { 4, 1, 1, 1, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 4 }; + + int32_t input1_data[] = { -1, 9, 7, 3 }; + int32_t input2_data[] = { 1, 2, 7, 5 }; + + bool expected_data[] = { false, true, true, false }; + int expected_dim[] = { 4, 1, 1, 1, 4 }; + + bool output_data[4]; + tflite::testing::TestComparisonInt( + tflite::ops::micro::Register_GREATER_EQUAL(), input1_dim, input1_data, + input2_dim, input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(GreaterEqualBroadcast) +{ + int input1_dim[] = { 4, 1, 1, 1, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 1 }; + + int32_t input1_data[] = { -1, 9, 7, 3 }; + int32_t input2_data[] = { 7 }; + + bool expected_data[] = { false, true, true, false }; + int expected_dim[] = { 4, 1, 1, 1, 4 }; + + bool output_data[4]; + tflite::testing::TestComparisonInt( + tflite::ops::micro::Register_GREATER_EQUAL(), input1_dim, input1_data, + input2_dim, input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(GreaterEqualBroadcastTwoD) +{ + int input1_dim[] = { 4, 1, 1, 2, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 4 }; + + int32_t input1_data[] = { -1, 9, 7, 3, 2, 4, 2, 8 }; + int32_t input2_data[] = { 7, 1, 2, 4 }; + + bool expected_data[] = { false, true, true, false, false, true, true, true }; + int expected_dim[] = { 4, 1, 1, 2, 4 }; + + bool output_data[8]; + tflite::testing::TestComparisonInt( + tflite::ops::micro::Register_GREATER_EQUAL(), input1_dim, input1_data, + input2_dim, input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(LessFloat) +{ + int input1_dim[] = { 4, 1, 1, 1, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 4 }; + + float input1_data[] = { 0.1, 0.9, 0.7, 0.3 }; + float input2_data[] = { 0.1, 0.2, 0.6, 0.5 }; + + bool expected_data[] = { false, false, false, true }; + int expected_dim[] = { 4, 1, 1, 1, 4 }; + + bool output_data[4]; + tflite::testing::TestComparisonFloat( + tflite::ops::micro::Register_LESS(), input1_dim, input1_data, input2_dim, + input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(LessInt) +{ + int input1_dim[] = { 4, 1, 1, 1, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 4 }; + + int32_t input1_data[] = { -1, 9, 7, 3 }; + int32_t input2_data[] = { 1, 2, 6, 5 }; + + bool expected_data[] = { true, false, false, true }; + int expected_dim[] = { 4, 1, 1, 1, 4 }; + + bool output_data[4]; + tflite::testing::TestComparisonInt( + tflite::ops::micro::Register_LESS(), input1_dim, input1_data, input2_dim, + input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(LessBroadcast) +{ + int input1_dim[] = { 4, 1, 1, 1, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 1 }; + + int32_t input1_data[] = { -1, 9, 7, 3 }; + int32_t input2_data[] = { 7 }; + + bool expected_data[] = { true, false, false, true }; + int expected_dim[] = { 4, 1, 1, 1, 4 }; + + bool output_data[4]; + tflite::testing::TestComparisonInt( + tflite::ops::micro::Register_LESS(), input1_dim, input1_data, input2_dim, + input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(LessBroadcastTwoD) +{ + int input1_dim[] = { 4, 1, 1, 2, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 4 }; + + int32_t input1_data[] = { -1, 9, 7, 3, 2, 4, 6, 8 }; + int32_t input2_data[] = { 7, 1, 2, 4 }; + + bool expected_data[] = { true, false, false, true, true, false, false, false }; + int expected_dim[] = { 4, 1, 1, 2, 4 }; + + bool output_data[8]; + tflite::testing::TestComparisonInt( + tflite::ops::micro::Register_LESS(), input1_dim, input1_data, input2_dim, + input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(LessEqualFloat) +{ + int input1_dim[] = { 4, 1, 1, 1, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 4 }; + + float input1_data[] = { 0.1, 0.9, 0.7, 0.3 }; + float input2_data[] = { 0.1, 0.2, 0.6, 0.5 }; + + bool expected_data[] = { true, false, false, true }; + int expected_dim[] = { 4, 1, 1, 1, 4 }; + + bool output_data[4]; + tflite::testing::TestComparisonFloat( + tflite::ops::micro::Register_LESS_EQUAL(), input1_dim, input1_data, + input2_dim, input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(LessEqualInt) +{ + int input1_dim[] = { 4, 1, 1, 1, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 4 }; + + int32_t input1_data[] = { -1, 9, 7, 3 }; + int32_t input2_data[] = { 1, 2, 7, 5 }; + + bool expected_data[] = { true, false, true, true }; + int expected_dim[] = { 4, 1, 1, 1, 4 }; + + bool output_data[4]; + tflite::testing::TestComparisonInt( + tflite::ops::micro::Register_LESS_EQUAL(), input1_dim, input1_data, + input2_dim, input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(LessEqualBroadcast) +{ + int input1_dim[] = { 4, 1, 1, 1, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 1 }; + + int32_t input1_data[] = { -1, 9, 7, 3 }; + int32_t input2_data[] = { 7 }; + + bool expected_data[] = { true, false, true, true }; + int expected_dim[] = { 4, 1, 1, 1, 4 }; + + bool output_data[4]; + tflite::testing::TestComparisonInt( + tflite::ops::micro::Register_LESS_EQUAL(), input1_dim, input1_data, + input2_dim, input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(LessEqualBroadcastTwoD) +{ + int input1_dim[] = { 4, 1, 1, 2, 4 }; + int input2_dim[] = { 4, 1, 1, 1, 4 }; + + int32_t input1_data[] = { -1, 9, 7, 3, 2, 4, 2, 8 }; + int32_t input2_data[] = { 7, 1, 2, 4 }; + + bool expected_data[] = { true, false, false, true, true, false, true, false }; + int expected_dim[] = { 4, 1, 1, 2, 4 }; + + bool output_data[8]; + tflite::testing::TestComparisonInt( + tflite::ops::micro::Register_LESS_EQUAL(), input1_dim, input1_data, + input2_dim, input2_data, expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(EqualQuantizedUInt8) +{ + int input1_dim[] = { 4, 1, 2, 2, 1 }; + int input2_dim[] = { 4, 1, 2, 2, 1 }; + float input1_data[] = { 1, 9, 7, 3 }; + float input2_data[] = { 1, 2, 7, 5 }; + + bool expected_data[] = { true, false, true, false }; + int expected_dim[] = { 4, 1, 2, 2, 1 }; + + const float input1_scale = 0.5; + const int input1_zero_point = 128; + const float input2_scale = 0.25; + const int input2_zero_point = 125; + uint8_t input1_quantized[4]; + uint8_t input2_quantized[4]; + + bool output_data[4]; + tflite::testing::TestComparisonQuantizedUInt8( + tflite::ops::micro::Register_EQUAL(), input1_dim, input1_data, + input1_quantized, input1_scale, input1_zero_point, input2_dim, + input2_data, input2_quantized, input2_scale, input2_zero_point, + expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(EqualQuantizedInt8) +{ + int input1_dim[] = { 4, 1, 2, 2, 1 }; + int input2_dim[] = { 4, 1, 2, 2, 1 }; + + float input1_data[] = { 1, -9, 7, 3 }; + float input2_data[] = { -1, 2, 7, 5 }; + + bool expected_data[] = { false, false, true, false }; + int expected_dim[] = { 4, 1, 2, 2, 1 }; + + const float input1_scale = 0.5; + const int input1_zero_point = -5; + const float input2_scale = 0.25; + const int input2_zero_point = 5; + int8_t input1_quantized[4]; + int8_t input2_quantized[4]; + + bool output_data[4]; + tflite::testing::TestComparisonQuantizedInt8( + tflite::ops::micro::Register_EQUAL(), input1_dim, input1_data, + input1_quantized, input1_scale, input1_zero_point, input2_dim, + input2_data, input2_quantized, input2_scale, input2_zero_point, + expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(NotEqualQuantizedUInt8) +{ + int input1_dim[] = { 4, 1, 2, 2, 1 }; + int input2_dim[] = { 4, 1, 2, 2, 1 }; + float input1_data[] = { 1, 9, 7, 3 }; + float input2_data[] = { 1, 2, 7, 0 }; + + bool expected_data[] = { false, true, false, true }; + int expected_dim[] = { 4, 1, 2, 2, 1 }; + + const float input1_scale = 0.5; + const int input1_zero_point = 128; + const float input2_scale = 0.25; + const int input2_zero_point = 125; + uint8_t input1_quantized[4]; + uint8_t input2_quantized[4]; + + bool output_data[4]; + tflite::testing::TestComparisonQuantizedUInt8( + tflite::ops::micro::Register_NOT_EQUAL(), input1_dim, input1_data, + input1_quantized, input1_scale, input1_zero_point, input2_dim, + input2_data, input2_quantized, input2_scale, input2_zero_point, + expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(NotEqualQuantizedInt8) +{ + int input1_dim[] = { 4, 1, 2, 2, 1 }; + int input2_dim[] = { 4, 1, 2, 2, 1 }; + + float input1_data[] = { 1, -9, 7, 3 }; + float input2_data[] = { 1, 2, 7, 5 }; + + bool expected_data[] = { false, true, false, true }; + int expected_dim[] = { 4, 1, 2, 2, 1 }; + + const float input1_scale = 0.5; + const int input1_zero_point = -5; + const float input2_scale = 0.25; + const int input2_zero_point = 5; + int8_t input1_quantized[4]; + int8_t input2_quantized[4]; + + bool output_data[4]; + tflite::testing::TestComparisonQuantizedInt8( + tflite::ops::micro::Register_NOT_EQUAL(), input1_dim, input1_data, + input1_quantized, input1_scale, input1_zero_point, input2_dim, + input2_data, input2_quantized, input2_scale, input2_zero_point, + expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(GreaterQuantizedUInt8) +{ + int input1_dim[] = { 4, 1, 2, 2, 1 }; + int input2_dim[] = { 4, 1, 2, 2, 1 }; + float input1_data[] = { 1, 9, 7, 3 }; + float input2_data[] = { 1, 2, 6, 5 }; + + bool expected_data[] = { false, true, true, false }; + int expected_dim[] = { 4, 1, 2, 2, 1 }; + + const float input1_scale = 0.5; + const int input1_zero_point = 128; + const float input2_scale = 0.25; + const int input2_zero_point = 125; + uint8_t input1_quantized[4]; + uint8_t input2_quantized[4]; + + bool output_data[4]; + tflite::testing::TestComparisonQuantizedUInt8( + tflite::ops::micro::Register_GREATER(), input1_dim, input1_data, + input1_quantized, input1_scale, input1_zero_point, input2_dim, + input2_data, input2_quantized, input2_scale, input2_zero_point, + expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(GreaterQuantizedUInt8SmallRange) +{ + int input1_dim[] = { 4, 1, 2, 2, 1 }; + int input2_dim[] = { 4, 1, 2, 2, 1 }; + float input1_data[] = { 1, 0.5, 0.35, 0.1 }; + float input2_data[] = { 1.01, 0.25, 0.3, 0.4 }; + + bool expected_data[] = { false, true, true, false }; + int expected_dim[] = { 4, 1, 2, 2, 1 }; + + const float input1_scale = 0.5; + const int input1_zero_point = 128; + const float input2_scale = 0.25; + const int input2_zero_point = 125; + uint8_t input1_quantized[4]; + uint8_t input2_quantized[4]; + + bool output_data[4]; + tflite::testing::TestComparisonQuantizedUInt8( + tflite::ops::micro::Register_GREATER(), input1_dim, input1_data, + input1_quantized, input1_scale, input1_zero_point, input2_dim, + input2_data, input2_quantized, input2_scale, input2_zero_point, + expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(GreaterUInt8EqualQuantized) +{ + int input1_dim[] = { 4, 1, 2, 2, 1 }; + int input2_dim[] = { 4, 1, 2, 2, 1 }; + + float input1_data[] = { 1, 9, 7, 3 }; + float input2_data[] = { 1, 2, 6, 5 }; + + bool expected_data[] = { true, true, true, false }; + int expected_dim[] = { 4, 1, 2, 2, 1 }; + + const float input1_scale = 0.5; + const int input1_zero_point = 128; + uint8_t input1_quantized[4]; + uint8_t input2_quantized[4]; + + bool output_data[4]; + tflite::testing::TestComparisonQuantizedUInt8( + tflite::ops::micro::Register_GREATER_EQUAL(), input1_dim, input1_data, + input1_quantized, input1_scale, input1_zero_point, input2_dim, + input2_data, input2_quantized, input1_scale, input1_zero_point, + expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(LessQuantizedUInt8) +{ + int input1_dim[] = { 4, 1, 2, 2, 1 }; + int input2_dim[] = { 4, 1, 2, 2, 1 }; + + float input1_data[] = { 1, 9, 7, 3 }; + float input2_data[] = { 1, 2, 6, 5 }; + + bool expected_data[] = { false, false, false, true }; + int expected_dim[] = { 4, 1, 2, 2, 1 }; + + const float input1_scale = 0.5; + const int input1_zero_point = 128; + uint8_t input1_quantized[4]; + uint8_t input2_quantized[4]; + + bool output_data[4]; + tflite::testing::TestComparisonQuantizedUInt8( + tflite::ops::micro::Register_LESS(), input1_dim, input1_data, + input1_quantized, input1_scale, input1_zero_point, input2_dim, + input2_data, input2_quantized, input1_scale, input1_zero_point, + expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(LessEqualQuantizedUInt8) +{ + int input1_dim[] = { 4, 1, 2, 2, 1 }; + int input2_dim[] = { 4, 1, 2, 2, 1 }; + + float input1_data[] = { 1, 9, 7, 3 }; + float input2_data[] = { 1, 2, 6, 5 }; + + bool expected_data[] = { true, false, false, true }; + int expected_dim[] = { 4, 1, 2, 2, 1 }; + + const float input1_scale = 0.5; + const int input1_zero_point = 128; + uint8_t input1_quantized[4]; + uint8_t input2_quantized[4]; + + bool output_data[4]; + tflite::testing::TestComparisonQuantizedUInt8( + tflite::ops::micro::Register_LESS_EQUAL(), input1_dim, input1_data, + input1_quantized, input1_scale, input1_zero_point, input2_dim, + input2_data, input2_quantized, input1_scale, input1_zero_point, + expected_data, expected_dim, output_data); +} + +TF_LITE_MICRO_TEST(EqualQuantizedUInt8WithBroadcast) +{ + const int num_shapes = 4; + const int max_shape_size = 5; + int test_shapes[num_shapes][max_shape_size] = { + { 1, 6 }, { 2, 2, 3 }, { 3, 2, 1, 3 }, { 4, 1, 3, 1, 2 } + }; + + for (int i = 0; i < num_shapes; ++i) { + int *input1_dim = test_shapes[i]; + int input2_dim[] = { 1, 1 }; + float input1_data[] = { 20, 2, 7, 8, 11, 20, 2 }; + float input2_data[] = { 2 }; + + bool expected_data[] = { false, true, false, false, false, false }; + int *expected_dim = input1_dim; + + const float input1_scale = 0.5; + const int input1_zero_point = 128; + uint8_t input1_quantized[6]; + uint8_t input2_quantized[6]; + + bool output_data[6]; + tflite::testing::TestComparisonQuantizedUInt8( + tflite::ops::micro::Register_EQUAL(), input1_dim, input1_data, + input1_quantized, input1_scale, input1_zero_point, input2_dim, + input2_data, input2_quantized, input1_scale, input1_zero_point, + expected_data, expected_dim, output_data); + } +} + +TF_LITE_MICRO_TEST(NotEqualQuantizedUInt8WithBroadcast) +{ + const int num_shapes = 4; + const int max_shape_size = 5; + int test_shapes[num_shapes][max_shape_size] = { + { 1, 6 }, { 2, 2, 3 }, { 3, 2, 1, 3 }, { 4, 1, 3, 1, 2 } + }; + + for (int i = 0; i < num_shapes; ++i) { + int *input1_dim = test_shapes[i]; + int input2_dim[] = { 1, 1 }; + float input1_data[] = { 20, 2, 7, 8, 11, 20 }; + float input2_data[] = { 2 }; + + bool expected_data[] = { true, false, true, true, true, true }; + int *expected_dim = input1_dim; + + const float input1_scale = 0.5; + const int input1_zero_point = 128; + uint8_t input1_quantized[6]; + uint8_t input2_quantized[6]; + + bool output_data[6]; + tflite::testing::TestComparisonQuantizedUInt8( + tflite::ops::micro::Register_NOT_EQUAL(), input1_dim, input1_data, + input1_quantized, input1_scale, input1_zero_point, input2_dim, + input2_data, input2_quantized, input1_scale, input1_zero_point, + expected_data, expected_dim, output_data); + } +} + +TF_LITE_MICRO_TEST(NotEqualQuantizedInt8WithBroadcast) +{ + const int num_shapes = 4; + const int max_shape_size = 5; + int test_shapes[num_shapes][max_shape_size] = { + { 1, 6 }, { 2, 2, 3 }, { 3, 2, 1, 3 }, { 4, 1, 3, 1, 2 } + }; + + for (int i = 0; i < num_shapes; ++i) { + int *input1_dim = test_shapes[i]; + int input2_dim[] = { 1, 1 }; + float input1_data[] = { 20, -2, -71, 8, 11, 20 }; + float input2_data[] = { 8 }; + + bool expected_data[] = { true, true, true, false, true, true }; + int *expected_dim = input1_dim; + + const float input1_scale = 0.5; + const int input1_zero_point = -9; + int8_t input1_quantized[6]; + int8_t input2_quantized[6]; + + bool output_data[6]; + tflite::testing::TestComparisonQuantizedInt8( + tflite::ops::micro::Register_NOT_EQUAL(), input1_dim, input1_data, + input1_quantized, input1_scale, input1_zero_point, input2_dim, + input2_data, input2_quantized, input1_scale, input1_zero_point, + expected_data, expected_dim, output_data); + } +} + +TF_LITE_MICRO_TEST(GreaterQuantizedUInt8WithBroadcast) +{ + const int num_shapes = 4; + const int max_shape_size = 5; + int test_shapes[num_shapes][max_shape_size] = { + { 1, 6 }, { 2, 2, 3 }, { 3, 2, 1, 3 }, { 4, 1, 3, 1, 2 } + }; + + for (int i = 0; i < num_shapes; ++i) { + int *input1_dim = test_shapes[i]; + int input2_dim[] = { 1, 1 }; + float input1_data[] = { 20, 2, 7, 8, 11, 20 }; + float input2_data[] = { 2 }; + + bool expected_data[] = { true, false, true, true, true, true }; + int *expected_dim = input1_dim; + + const float input1_scale = 0.5; + const int input1_zero_point = 128; + uint8_t input1_quantized[6]; + uint8_t input2_quantized[6]; + + bool output_data[6]; + tflite::testing::TestComparisonQuantizedUInt8( + tflite::ops::micro::Register_GREATER(), input1_dim, input1_data, + input1_quantized, input1_scale, input1_zero_point, input2_dim, + input2_data, input2_quantized, input1_scale, input1_zero_point, + expected_data, expected_dim, output_data); + } +} + +TF_LITE_MICRO_TEST(GreaterQuantizedInt8WithBroadcast) +{ + const int num_shapes = 4; + const int max_shape_size = 5; + int test_shapes[num_shapes][max_shape_size] = { + { 1, 6 }, { 2, 2, 3 }, { 3, 2, 1, 3 }, { 4, 1, 3, 1, 2 } + }; + + for (int i = 0; i < num_shapes; ++i) { + int *input1_dim = test_shapes[i]; + int input2_dim[] = { 1, 1 }; + float input1_data[] = { 20, -2, -71, 8, 11, 20 }; + float input2_data[] = { 8 }; + + bool expected_data[] = { true, false, false, false, true, true }; + int *expected_dim = input1_dim; + + const float input1_scale = 0.5; + const int input1_zero_point = -9; + int8_t input1_quantized[6]; + int8_t input2_quantized[6]; + + bool output_data[6]; + tflite::testing::TestComparisonQuantizedInt8( + tflite::ops::micro::Register_GREATER(), input1_dim, input1_data, + input1_quantized, input1_scale, input1_zero_point, input2_dim, + input2_data, input2_quantized, input1_scale, input1_zero_point, + expected_data, expected_dim, output_data); + } +} + +TF_LITE_MICRO_TEST(GreaterEqualQuantizedUInt8WithBroadcast) +{ + const int num_shapes = 4; + const int max_shape_size = 5; + int test_shapes[num_shapes][max_shape_size] = { + { 1, 6 }, { 2, 2, 3 }, { 3, 2, 1, 3 }, { 4, 1, 3, 1, 2 } + }; + + for (int i = 0; i < num_shapes; ++i) { + int *input1_dim = test_shapes[i]; + int input2_dim[] = { 1, 1 }; + float input1_data[] = { 20, 2, 7, 8, 11, 20 }; + float input2_data[] = { 2 }; + + bool expected_data[] = { true, true, true, true, true, true }; + int *expected_dim = input1_dim; + + const float input1_scale = 0.5; + const int input1_zero_point = 128; + uint8_t input1_quantized[6]; + uint8_t input2_quantized[6]; + + bool output_data[6]; + tflite::testing::TestComparisonQuantizedUInt8( + tflite::ops::micro::Register_GREATER_EQUAL(), input1_dim, input1_data, + input1_quantized, input1_scale, input1_zero_point, input2_dim, + input2_data, input2_quantized, input1_scale, input1_zero_point, + expected_data, expected_dim, output_data); + } +} + +TF_LITE_MICRO_TEST(GreaterEqualQuantizedInt8WithBroadcast) +{ + const int num_shapes = 4; + const int max_shape_size = 5; + int test_shapes[num_shapes][max_shape_size] = { + { 1, 6 }, { 2, 2, 3 }, { 3, 2, 1, 3 }, { 4, 1, 3, 1, 2 } + }; + + for (int i = 0; i < num_shapes; ++i) { + int *input1_dim = test_shapes[i]; + int input2_dim[] = { 1, 1 }; + float input1_data[] = { 20, -2, -71, 8, 11, 20 }; + float input2_data[] = { 8 }; + + bool expected_data[] = { true, false, false, true, true, true }; + int *expected_dim = input1_dim; + + const float input1_scale = 0.5; + const int input1_zero_point = -9; + int8_t input1_quantized[6]; + int8_t input2_quantized[6]; + + bool output_data[6]; + tflite::testing::TestComparisonQuantizedInt8( + tflite::ops::micro::Register_GREATER_EQUAL(), input1_dim, input1_data, + input1_quantized, input1_scale, input1_zero_point, input2_dim, + input2_data, input2_quantized, input1_scale, input1_zero_point, + expected_data, expected_dim, output_data); + } +} + +TF_LITE_MICRO_TEST(LessQuantizedUInt8WithBroadcast) +{ + const int num_shapes = 4; + const int max_shape_size = 5; + int test_shapes[num_shapes][max_shape_size] = { + { 1, 6 }, { 2, 2, 3 }, { 3, 2, 1, 3 }, { 4, 1, 3, 1, 2 } + }; + + for (int i = 0; i < num_shapes; ++i) { + int *input1_dim = test_shapes[i]; + int input2_dim[] = { 1, 1 }; + float input1_data[] = { 20, 2, -1, 8, 11, 20 }; + float input2_data[] = { 2 }; + + bool expected_data[] = { false, false, true, false, false, false }; + int *expected_dim = input1_dim; + + const float input1_scale = 0.5; + const int input1_zero_point = 128; + uint8_t input1_quantized[6]; + uint8_t input2_quantized[6]; + + bool output_data[6]; + tflite::testing::TestComparisonQuantizedUInt8( + tflite::ops::micro::Register_LESS(), input1_dim, input1_data, + input1_quantized, input1_scale, input1_zero_point, input2_dim, + input2_data, input2_quantized, input1_scale, input1_zero_point, + expected_data, expected_dim, output_data); + } +} + +TF_LITE_MICRO_TEST(LessQuantizedInt8WithBroadcast) +{ + const int num_shapes = 4; + const int max_shape_size = 5; + int test_shapes[num_shapes][max_shape_size] = { + { 1, 6 }, { 2, 2, 3 }, { 3, 2, 1, 3 }, { 4, 1, 3, 1, 2 } + }; + + for (int i = 0; i < num_shapes; ++i) { + int *input1_dim = test_shapes[i]; + int input2_dim[] = { 1, 1 }; + float input1_data[] = { 20, -2, -71, 8, 11, 20 }; + float input2_data[] = { 8 }; + + bool expected_data[] = { false, true, true, false, false, false }; + int *expected_dim = input1_dim; + + const float input1_scale = 0.5; + const int input1_zero_point = -9; + int8_t input1_quantized[6]; + int8_t input2_quantized[6]; + + bool output_data[6]; + tflite::testing::TestComparisonQuantizedInt8( + tflite::ops::micro::Register_LESS(), input1_dim, input1_data, + input1_quantized, input1_scale, input1_zero_point, input2_dim, + input2_data, input2_quantized, input1_scale, input1_zero_point, + expected_data, expected_dim, output_data); + } +} + +TF_LITE_MICRO_TEST(LessEqualQuantizedUInt8WithBroadcast) +{ + const int num_shapes = 4; + const int max_shape_size = 5; + int test_shapes[num_shapes][max_shape_size] = { + { 1, 6 }, { 2, 2, 3 }, { 3, 2, 1, 3 }, { 4, 1, 3, 1, 2 } + }; + + for (int i = 0; i < num_shapes; ++i) { + int *input1_dim = test_shapes[i]; + int input2_dim[] = { 1, 1 }; + float input1_data[] = { 20, 2, -1, 8, 11, 20 }; + float input2_data[] = { 2 }; + + bool expected_data[] = { false, true, true, false, false, false }; + int *expected_dim = input1_dim; + + const float input1_scale = 0.5; + const int input1_zero_point = 128; + uint8_t input1_quantized[6]; + uint8_t input2_quantized[6]; + + bool output_data[6]; + tflite::testing::TestComparisonQuantizedUInt8( + tflite::ops::micro::Register_LESS_EQUAL(), input1_dim, input1_data, + input1_quantized, input1_scale, input1_zero_point, input2_dim, + input2_data, input2_quantized, input1_scale, input1_zero_point, + expected_data, expected_dim, output_data); + } +} + +TF_LITE_MICRO_TEST(LessEqualQuantizedInt8WithBroadcast) +{ + const int num_shapes = 4; + const int max_shape_size = 5; + int test_shapes[num_shapes][max_shape_size] = { + { 1, 6 }, { 2, 2, 3 }, { 3, 2, 1, 3 }, { 4, 1, 3, 1, 2 } + }; + + for (int i = 0; i < num_shapes; ++i) { + int *input1_dim = test_shapes[i]; + int input2_dim[] = { 1, 1 }; + float input1_data[] = { 20, -2, -71, 8, 11, 20 }; + float input2_data[] = { 8 }; + + bool expected_data[] = { false, true, true, true, false, false }; + int *expected_dim = input1_dim; + + const float input1_scale = 0.5; + const int input1_zero_point = -9; + int8_t input1_quantized[6]; + int8_t input2_quantized[6]; + + bool output_data[6]; + tflite::testing::TestComparisonQuantizedInt8( + tflite::ops::micro::Register_LESS_EQUAL(), input1_dim, input1_data, + input1_quantized, input1_scale, input1_zero_point, input2_dim, + input2_data, input2_quantized, input1_scale, input1_zero_point, + expected_data, expected_dim, output_data); + } +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/concatenation.cc b/components/tflite/tensorflow/lite/micro/kernels/concatenation.cc new file mode 100644 index 00000000..d3d2c9c2 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/concatenation.cc @@ -0,0 +1,290 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/kernels/internal/reference/concatenation.h" + +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/portable_tensor.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/internal/types.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace concatenation { + +constexpr int kMaxInputNum = 10; // Maximum number of input tensors +constexpr int kOutputTensor = 0; + +struct OpData { + ConcatenationParams params; +}; + +// Handles negative axis index, coerces to positive index value. +inline int CalculatePositiveAxis(int axis, const TfLiteTensor *output_tensor) +{ + if (axis >= 0) { + return axis; + } else { + return NumDimensions(output_tensor) + axis; + } +} + +// The following functions are helpers to get tensor data in the format that the +// reference op implementation expects. They provide the same functionality as +// class VectorOfTensors and class VectorOfQuantizedTensors in TFLite. + +// Gets shapes from a list of tensors. +inline void GetAllInputTensorShapes(const TfLiteContext *context, + const TfLiteNode *node, + RuntimeShape all_shapes[kMaxInputNum]) +{ + TFLITE_DCHECK(context != nullptr); + TFLITE_DCHECK(node != nullptr); + for (int i = 0; i < node->inputs->size; ++i) { + const TfLiteEvalTensor *t = tflite::micro::GetEvalInput(context, node, i); + RuntimeShape shape = tflite::micro::GetTensorShape(t); + all_shapes[i].ReplaceWith(shape.DimensionsCount(), shape.DimsData()); + } +} + +// Get shape pointers from a list of shapes. +inline void GetShapesPointers(const RuntimeShape *shapes, size_t num, + const RuntimeShape *pointers[]) +{ + for (size_t i = 0; i < num; ++i) { + pointers[i] = &shapes[i]; + } +} + +// Gets data pointers from a list of tensors. +template +inline void GetAllInputTensorData(const TfLiteContext *context, + const TfLiteNode *node, + T *all_data[kMaxInputNum]) +{ + TFLITE_DCHECK(context != nullptr); + TFLITE_DCHECK(node != nullptr); + for (int i = 0; i < node->inputs->size; ++i) { + const TfLiteEvalTensor *t = tflite::micro::GetEvalInput(context, node, i); + all_data[i] = tflite::micro::GetTensorData(t); + } +} + +template +void EvalUnquantized(TfLiteContext *context, TfLiteNode *node) +{ + // Collect the shapes and data pointer of input tensors + RuntimeShape inputs_shape[kMaxInputNum]; + const RuntimeShape *inputs_shape_ptr[kMaxInputNum]; + const data_type *inputs_data[kMaxInputNum]; + GetAllInputTensorShapes(context, node, inputs_shape); + GetShapesPointers(inputs_shape, node->inputs->size, inputs_shape_ptr); + GetAllInputTensorData(context, node, inputs_data); + + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + TFLITE_DCHECK(node->user_data != nullptr); + const OpData *data = static_cast(node->user_data); + + reference_ops::Concatenation(data->params, inputs_shape_ptr, inputs_data, + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); +} + +void EvalQuantizedUInt8(TfLiteContext *context, TfLiteNode *node) +{ + // Collect the shapes and data pointer of input tensors + RuntimeShape inputs_shape[kMaxInputNum]; + const RuntimeShape *inputs_shape_ptr[kMaxInputNum]; + const uint8_t *inputs_data[kMaxInputNum]; + GetAllInputTensorShapes(context, node, inputs_shape); + GetShapesPointers(inputs_shape, node->inputs->size, inputs_shape_ptr); + GetAllInputTensorData(context, node, inputs_data); + + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + TFLITE_DCHECK(node->user_data != nullptr); + const OpData *data = static_cast(node->user_data); + + reference_ops::ConcatenationWithScaling( + data->params, inputs_shape_ptr, inputs_data, + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); +} + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(OpData)); +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + // This function only checks the types. Additional shape validations are + // performed in the reference implementation called during Eval(). + const TfLiteConcatenationParams *params = + reinterpret_cast(node->builtin_data); + + const TfLiteTensor *input_tensor = GetInput(context, node, 0); + TF_LITE_ENSURE(context, input_tensor != nullptr); + TfLiteType input_type = input_tensor->type; + const TfLiteTensor *output_tensor = GetOutput(context, node, kOutputTensor); + TF_LITE_ENSURE(context, output_tensor != nullptr); + TfLiteType output_type = output_tensor->type; + + // Check activation and input type + TF_LITE_ENSURE_EQ(context, params->activation, kTfLiteActNone); + TF_LITE_ENSURE(context, + input_type == kTfLiteFloat32 || input_type == kTfLiteUInt8 || + input_type == kTfLiteInt8 || input_type == kTfLiteInt16 || + input_type == kTfLiteInt32 || input_type == kTfLiteInt64); + + // Output type must match input type + TF_LITE_ENSURE_EQ(context, output_type, input_type); + + // This implementation does not support large number of input tensors + const int num_inputs = NumInputs(node); + TF_LITE_ENSURE(context, num_inputs <= kMaxInputNum); + + // Shapes with dimensions >4 are not yet supported with static allocation. + for (int i = 0; i < num_inputs; ++i) { + const TfLiteTensor *input = GetInput(context, node, i); + TF_LITE_ENSURE(context, input != nullptr); + int num_dimensions = NumDimensions(input); + + if (num_dimensions > 4) { + TF_LITE_KERNEL_LOG( + context, + "Op Concatenation does not currently support num dimensions >4 " + "Tensor has %d dimensions.", + num_dimensions); + return kTfLiteError; + } + } + + // Calculate OpData. + TFLITE_DCHECK(node->user_data != nullptr); + OpData *data = static_cast(node->user_data); + + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + + switch (output_type) { // Already know in/outtypes are same. + case kTfLiteFloat32: + case kTfLiteInt16: + case kTfLiteInt32: + case kTfLiteInt64: { + data->params.axis = CalculatePositiveAxis(params->axis, output); + data->params.inputs_count = node->inputs->size; + break; + } + case kTfLiteUInt8: + case kTfLiteInt8: { + data->params.axis = CalculatePositiveAxis(params->axis, output); + data->params.inputs_count = node->inputs->size; + + float *input_scales = + reinterpret_cast(context->AllocatePersistentBuffer( + context, node->inputs->size * sizeof(float))); + + int32_t *input_zero_points = + reinterpret_cast(context->AllocatePersistentBuffer( + context, node->inputs->size * sizeof(int32_t))); + + // Allocate persistent scale and zeropoint buffers. + // Store input scale and zero point values in OpParams: + for (int i = 0; i < node->inputs->size; ++i) { + const TfLiteTensor *t = GetInput(context, node, i); + TF_LITE_ENSURE(context, t != nullptr); + input_scales[i] = t->params.scale; + input_zero_points[i] = t->params.zero_point; + } + + data->params.input_scale = input_scales; + data->params.input_zeropoint = input_zero_points; + data->params.output_zeropoint = output->params.zero_point; + data->params.output_scale = output->params.scale; + break; + } + default: + TF_LITE_KERNEL_LOG( + context, "Op Concatenation does not currently support Type '%s'.", + TfLiteTypeGetName(output_type)); + return kTfLiteError; + } + + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteTensor *output_tensor = GetOutput(context, node, kOutputTensor); + TF_LITE_ENSURE(context, output_tensor != nullptr); + TfLiteType output_type = output_tensor->type; + + switch (output_type) { // Already know in/outtypes are same. + case kTfLiteFloat32: + EvalUnquantized(context, node); + break; + case kTfLiteInt32: + EvalUnquantized(context, node); + break; + case kTfLiteUInt8: + EvalQuantizedUInt8(context, node); + break; + case kTfLiteInt8: + EvalUnquantized(context, node); + break; + case kTfLiteInt64: + EvalUnquantized(context, node); + break; + case kTfLiteInt16: + EvalUnquantized(context, node); + break; + + default: + TF_LITE_KERNEL_LOG( + context, "Op Concatenation does not currently support Type '%s'.", + TfLiteTypeGetName(output_type)); + return kTfLiteError; + } + + return kTfLiteOk; +} + +} // namespace concatenation + +TfLiteRegistration Register_CONCATENATION() +{ + return { /*init=*/concatenation::Init, + /*free=*/nullptr, + /*prepare=*/concatenation::Prepare, + /*invoke=*/concatenation::Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/concatenation_test.cc b/components/tflite/tensorflow/lite/micro/kernels/concatenation_test.cc new file mode 100644 index 00000000..545a2214 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/concatenation_test.cc @@ -0,0 +1,266 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +void TestConcatenateTwoInputs(int *input1_dims_data, const float *input1_data, + int *input2_dims_data, const float *input2_data, + int axis, int *output_dims_data, + const float *expected_output_data, + float *output_data) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + + constexpr int input_size = 2; + constexpr int output_size = 1; + constexpr int tensors_size = input_size + output_size; + TfLiteTensor tensors[tensors_size] = { CreateTensor(input1_data, input1_dims), + CreateTensor(input2_data, input2_dims), + CreateTensor(output_data, output_dims) }; + + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + TfLiteConcatenationParams builtin_data = { + .axis = axis, + .activation = kTfLiteActNone // Only activation supported in this impl + }; + + const TfLiteRegistration registration = + tflite::ops::micro::Register_CONCATENATION(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + reinterpret_cast(&builtin_data)); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + const int output_dims_count = ElementCount(*output_dims); + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output_data[i], output_data[i], 1e-5f); + } +} + +template +void TestConcatenateQuantizedTwoInputs( + int *input1_dims_data, const T *input1_data, int *input2_dims_data, + const T *input2_data, const float input_scale, const int input_zero_point, + int axis, int *output_dims_data, const T *expected_output_data, + const float output_scale, const int output_zero_point, T *output_data) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + + constexpr int input_size = 2; + constexpr int output_size = 1; + constexpr int tensors_size = input_size + output_size; + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(input1_data, input1_dims, input_scale, + input_zero_point), + CreateQuantizedTensor(input2_data, input2_dims, input_scale, + input_zero_point), + CreateQuantizedTensor(output_data, output_dims, output_scale, + output_zero_point) + }; + + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + TfLiteConcatenationParams builtin_data = { + .axis = axis, + .activation = kTfLiteActNone // Only activation supported in this impl + }; + + const TfLiteRegistration registration = + tflite::ops::micro::Register_CONCATENATION(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + reinterpret_cast(&builtin_data)); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + const int output_dims_count = ElementCount(*output_dims); + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output_data[i], output_data[i]); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TwoInputsAllAxesCombinations) +{ + // Concatenate the same two input tensors along all possible axes. + + int input_shape[] = { 2, 2, 3 }; + const float input1_value[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f }; + const float input2_value[] = { 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f }; + + // expected output when concatenating on axis 0 + int output_shape_axis0[] = { 2, 4, 3 }; + const float output_value_axis0[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, + 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f }; + + // expected output when concatenating on axis 1 + int output_shape_axis1[] = { 2, 2, 6 }; + const float output_value_axis1[] = { 1.0f, 2.0f, 3.0f, 7.0f, 8.0f, 9.0f, + 4.0f, 5.0f, 6.0f, 10.0f, 11.0f, 12.0f }; + + float output_data[12]; + + // Axis = 0 + tflite::testing::TestConcatenateTwoInputs( + input_shape, input1_value, input_shape, input2_value, /* axis */ 0, + output_shape_axis0, output_value_axis0, output_data); + + // Axis = -2 (equivalent to axis = 0) + tflite::testing::TestConcatenateTwoInputs( + input_shape, input1_value, input_shape, input2_value, /* axis */ -2, + output_shape_axis0, output_value_axis0, output_data); + + // Axis = 1 + tflite::testing::TestConcatenateTwoInputs( + input_shape, input1_value, input_shape, input2_value, /* axis */ 1, + output_shape_axis1, output_value_axis1, output_data); + + // Axis = -1 (equivalent to axis = 1) + tflite::testing::TestConcatenateTwoInputs( + input_shape, input1_value, input_shape, input2_value, /* axis */ -1, + output_shape_axis1, output_value_axis1, output_data); +} + +TF_LITE_MICRO_TEST(TwoInputsQuantizedUint8) +{ + const int axis = 2; + int input_shape[] = { 3, 2, 1, 2 }; + int output_shape[] = { 3, 2, 1, 4 }; + + const float input_scale = 0.1f; + const int input_zero_point = 127; + const float output_scale = 0.1f; + const int output_zero_point = 127; + + const uint8_t input1_values[] = { 137, 157, 167, 197 }; + + const uint8_t input2_values[] = { 138, 158, 168, 198 }; + + const uint8_t output_value[] = { + 137, + 157, + 138, + 158, + 167, + 197, + 168, + 198, + }; + + uint8_t output_data[8]; + tflite::testing::TestConcatenateQuantizedTwoInputs( + input_shape, input1_values, input_shape, input2_values, input_scale, + input_zero_point, axis, output_shape, output_value, output_scale, + output_zero_point, output_data); +} + +TF_LITE_MICRO_TEST(TwoInputsQuantizedInt8) +{ + const int axis = 2; + int input_shape[] = { 3, 2, 1, 2 }; + int output_shape[] = { 3, 2, 1, 4 }; + + const float input_scale = 0.1f; + const int input_zero_point = 0; + const float output_scale = 0.1f; + const int output_zero_point = 0; + + const int8_t input1_values[] = { 1, 2, 3, 4 }; + + const int8_t input2_values[] = { 5, 6, 7, 8 }; + + const int8_t output_value[] = { 1, 2, 5, 6, 3, 4, 7, 8 }; + + int8_t output_data[8]; + tflite::testing::TestConcatenateQuantizedTwoInputs( + input_shape, input1_values, input_shape, input2_values, input_scale, + input_zero_point, axis, output_shape, output_value, output_scale, + output_zero_point, output_data); +} + +TF_LITE_MICRO_TEST(TwoInputsQuantizedInt16) +{ + const int axis = 2; + int input_shape[] = { 3, 2, 1, 2 }; + int output_shape[] = { 3, 2, 1, 4 }; + + const float input_scale = 0.1f; + const int input_zero_point = 0; + const float output_scale = 0.1f; + const int output_zero_point = 0; + + const int16_t input1_values[] = { 1, 2, 3, 4 }; + + const int16_t input2_values[] = { 5, 6, 7, 8 }; + + const int16_t output_value[] = { 1, 2, 5, 6, 3, 4, 7, 8 }; + + int16_t output_data[8]; + tflite::testing::TestConcatenateQuantizedTwoInputs( + input_shape, input1_values, input_shape, input2_values, input_scale, + input_zero_point, axis, output_shape, output_value, output_scale, + output_zero_point, output_data); +} + +TF_LITE_MICRO_TEST(ThreeDimensionalTwoInputsDifferentShapes) +{ + const int axis = 1; + + int input1_shape[] = { 3, 2, 1, 2 }; + int input2_shape[] = { 3, 2, 3, 2 }; + int output_shape[] = { 3, 2, 4, 2 }; + + const float input1_values[] = { 1.0f, 3.0f, 4.0f, 7.0f }; + const float input2_values[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, + 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f }; + const float output_values[] = { 1.0f, 3.0f, 1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 4.0f, 7.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f }; + + float output_data[16]; + tflite::testing::TestConcatenateTwoInputs( + input1_shape, input1_values, input2_shape, input2_values, axis, + output_shape, output_values, output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/conv.cc b/components/tflite/tensorflow/lite/micro/kernels/conv.cc new file mode 100644 index 00000000..447e4e74 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/conv.cc @@ -0,0 +1,124 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/kernels/conv.h" + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/conv.h" +#include "tensorflow/lite/kernels/internal/reference/integer_ops/conv.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/padding.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace { + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(OpDataConv)); +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kConvInputTensor); + const TfLiteEvalTensor *filter = + tflite::micro::GetEvalInput(context, node, kConvWeightsTensor); + const TfLiteEvalTensor *bias = + (NumInputs(node) == 3) ? tflite::micro::GetEvalInput(context, node, kConvBiasTensor) : nullptr; + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kConvOutputTensor); + + TFLITE_DCHECK(node->builtin_data != nullptr); + const auto ¶ms = + *(reinterpret_cast(node->builtin_data)); + TFLITE_DCHECK(node->user_data != nullptr); + const auto &data = *(static_cast(node->user_data)); + + TF_LITE_ENSURE_EQ(context, input->type, output->type); + TF_LITE_ENSURE_MSG( + context, + input->type == filter->type || + (input->type == kTfLiteInt16 && filter->type == kTfLiteInt8), + "Hybrid models are not supported on TFLite Micro."); + + switch (input->type) { // Already know in/out types are same. + case kTfLiteFloat32: { + tflite::reference_ops::Conv( + ConvParamsFloat(params, data), tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(filter), + tflite::micro::GetTensorData(filter), + tflite::micro::GetTensorShape(bias), + tflite::micro::GetTensorData(bias), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output), + tflite::micro::GetTensorShape(nullptr), nullptr); + break; + } + case kTfLiteInt16: { + reference_integer_ops::ConvPerChannel( + ConvParamsQuantized(params, data), data.per_channel_output_multiplier, + data.per_channel_output_shift, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(filter), + tflite::micro::GetTensorData(filter), + tflite::micro::GetTensorShape(bias), + tflite::micro::GetTensorData(bias), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + break; + } + case kTfLiteInt8: { + reference_integer_ops::ConvPerChannel( + ConvParamsQuantized(params, data), data.per_channel_output_multiplier, + data.per_channel_output_shift, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(filter), + tflite::micro::GetTensorData(filter), + tflite::micro::GetTensorShape(bias), + tflite::micro::GetTensorData(bias), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + break; + } + default: + TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.", + TfLiteTypeGetName(input->type), input->type); + return kTfLiteError; + } + return kTfLiteOk; +} + +} // namespace + +TfLiteRegistration Register_CONV_2D() +{ + return { /*init=*/Init, + /*free=*/nullptr, + /*prepare=*/ConvPrepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/conv.h b/components/tflite/tensorflow/lite/micro/kernels/conv.h new file mode 100644 index 00000000..d667bbb4 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/conv.h @@ -0,0 +1,92 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_KERNELS_CONV_H_ +#define TENSORFLOW_LITE_MICRO_KERNELS_CONV_H_ + +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +struct OpDataConv { + TfLitePaddingValues padding; + + // Cached tensor zero point values for quantized operations. + int32_t input_zero_point; + int32_t filter_zero_point; + int32_t output_zero_point; + + // The scaling factor from input to output (aka the 'real multiplier') can + // be represented as a fixed point multiplier plus a left shift. + int32_t output_multiplier; + int output_shift; + + // Per channel output multiplier and shift. + int32_t *per_channel_output_multiplier; + int32_t *per_channel_output_shift; + + // The range of the fused activation layer. For example for kNone and + // uint8_t these would be 0 and 255. + int32_t output_activation_min; + int32_t output_activation_max; +}; + +extern const int kConvInputTensor; +extern const int kConvWeightsTensor; +extern const int kConvBiasTensor; +extern const int kConvOutputTensor; +extern const int kConvQuantizedDimension; + +// Returns a ConvParams struct with all the parameters needed for a +// float computation. +ConvParams ConvParamsFloat(const TfLiteConvParams ¶ms, + const OpDataConv &data); + +// Returns a ConvParams struct with all the parameters needed for a +// quantized computation. +ConvParams ConvParamsQuantized(const TfLiteConvParams ¶ms, + const OpDataConv &data); + +TfLiteStatus CalculateOpDataConv(TfLiteContext *context, TfLiteNode *node, + const TfLiteConvParams ¶ms, int width, + int height, int filter_width, + int filter_height, int out_width, + int out_height, const TfLiteType data_type, + OpDataConv *data); + +TfLiteStatus ConvPrepare(TfLiteContext *context, TfLiteNode *node); + +// This is the most generic TfLiteRegistration. The actual supported types may +// still be target dependent. The only requirement is that every implementation +// (reference or optimized) must define this function. +TfLiteRegistration Register_CONV_2D(); + +#if defined(XTENSA) +// Returns a TfLiteRegistration struct for kernel variant that only supports +// int8 inputs and outputs. +TfLiteRegistration Register_CONV_2D_INT8REF(); +#else +inline TfLiteRegistration Register_CONV_2D_INT8REF() +{ + return Register_CONV_2D(); +} +#endif + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_KERNELS_CONV_H_ diff --git a/components/tflite/tensorflow/lite/micro/kernels/conv_common.cc b/components/tflite/tensorflow/lite/micro/kernels/conv_common.cc new file mode 100644 index 00000000..e53ae45e --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/conv_common.cc @@ -0,0 +1,185 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/conv.h" +#include "tensorflow/lite/kernels/internal/reference/integer_ops/conv.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/padding.h" +#include "tensorflow/lite/micro/kernels/conv.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { + +const int kConvInputTensor = 0; +const int kConvWeightsTensor = 1; +const int kConvBiasTensor = 2; +const int kConvOutputTensor = 0; + +// Conv is quantized along dimension 0: +// https://www.tensorflow.org/lite/performance/quantization_spec +const int kConvQuantizedDimension = 0; + +// Returns a ConvParams struct with all the parameters needed for a +// float computation. +ConvParams ConvParamsFloat(const TfLiteConvParams ¶ms, + const OpDataConv &data) +{ + ConvParams op_params; + CalculateActivationRange(params.activation, &op_params.float_activation_min, + &op_params.float_activation_max); + op_params.padding_type = tflite::micro::RuntimePaddingType(params.padding); + op_params.padding_values.width = data.padding.width; + op_params.padding_values.height = data.padding.height; + op_params.stride_width = params.stride_width; + op_params.stride_height = params.stride_height; + op_params.dilation_width_factor = params.dilation_width_factor; + op_params.dilation_height_factor = params.dilation_height_factor; + return op_params; +} + +// Returns a ConvParams struct with all the parameters needed for a +// quantized computation. +ConvParams ConvParamsQuantized(const TfLiteConvParams ¶ms, + const OpDataConv &data) +{ + ConvParams op_params; + op_params.input_offset = -data.input_zero_point; + op_params.weights_offset = -data.filter_zero_point; + op_params.output_offset = data.output_zero_point; + op_params.output_multiplier = data.output_multiplier; + op_params.output_shift = -data.output_shift; + op_params.padding_type = tflite::micro::RuntimePaddingType(params.padding); + op_params.padding_values.height = data.padding.height; + op_params.padding_values.width = data.padding.width; + op_params.stride_height = params.stride_height; + op_params.stride_width = params.stride_width; + op_params.dilation_height_factor = params.dilation_height_factor; + op_params.dilation_width_factor = params.dilation_width_factor; + op_params.quantized_activation_min = data.output_activation_min; + op_params.quantized_activation_max = data.output_activation_max; + return op_params; +} + +TfLiteStatus CalculateOpDataConv(TfLiteContext *context, TfLiteNode *node, + const TfLiteConvParams ¶ms, int width, + int height, int filter_width, + int filter_height, int out_width, + int out_height, const TfLiteType data_type, + OpDataConv *data) +{ + bool has_bias = node->inputs->size == 3; + // Check number of inputs/outputs + TF_LITE_ENSURE(context, has_bias || node->inputs->size == 2); + TF_LITE_ENSURE_EQ(context, node->outputs->size, 1); + + // Matching GetWindowedOutputSize in TensorFlow. + auto padding = params.padding; + data->padding = ComputePaddingHeightWidth( + params.stride_height, params.stride_width, params.dilation_height_factor, + params.dilation_width_factor, height, width, filter_height, filter_width, + padding, &out_height, &out_width); + + const TfLiteTensor *input = GetInput(context, node, kConvInputTensor); + TF_LITE_ENSURE(context, input != nullptr); + const TfLiteTensor *filter = GetInput(context, node, kConvWeightsTensor); + TF_LITE_ENSURE(context, filter != nullptr); + const TfLiteTensor *bias = + GetOptionalInputTensor(context, node, kConvBiasTensor); + TfLiteTensor *output = GetOutput(context, node, kConvOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + + // Note that quantized inference requires that all tensors have their + // parameters set. This is usually done during quantized training. + if (data_type != kTfLiteFloat32) { + int output_channels = filter->dims->data[kConvQuantizedDimension]; + + TF_LITE_ENSURE_STATUS(tflite::PopulateConvolutionQuantizationParams( + context, input, filter, bias, output, params.activation, + &data->output_multiplier, &data->output_shift, + &data->output_activation_min, &data->output_activation_max, + data->per_channel_output_multiplier, data->per_channel_output_shift, + output_channels)); + } + + data->input_zero_point = input->params.zero_point; + data->filter_zero_point = filter->params.zero_point; + data->output_zero_point = output->params.zero_point; + + return kTfLiteOk; +} + +TfLiteStatus ConvPrepare(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + TFLITE_DCHECK(node->builtin_data != nullptr); + + OpDataConv *data = static_cast(node->user_data); + const auto ¶ms = + *(static_cast(node->builtin_data)); + + TfLiteTensor *output = GetOutput(context, node, kConvOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + const TfLiteTensor *input = GetInput(context, node, kConvInputTensor); + TF_LITE_ENSURE(context, input != nullptr); + const TfLiteTensor *filter = GetInput(context, node, kConvWeightsTensor); + TF_LITE_ENSURE(context, filter != nullptr); + + const int input_width = input->dims->data[2]; + const int input_height = input->dims->data[1]; + const int filter_width = filter->dims->data[2]; + const int filter_height = filter->dims->data[1]; + const int output_width = output->dims->data[2]; + const int output_height = output->dims->data[1]; + + // Dynamically allocate per-channel quantization parameters. + const int num_channels = filter->dims->data[kConvQuantizedDimension]; + data->per_channel_output_multiplier = + static_cast(context->AllocatePersistentBuffer( + context, num_channels * sizeof(int32_t))); + data->per_channel_output_shift = + static_cast(context->AllocatePersistentBuffer( + context, num_channels * sizeof(int32_t))); + + // All per-channel quantized tensors need valid zero point and scale arrays. + if (input->type == kTfLiteInt8 || input->type == kTfLiteInt16) { + TF_LITE_ENSURE_EQ(context, filter->quantization.type, + kTfLiteAffineQuantization); + + const auto *affine_quantization = + static_cast(filter->quantization.params); + TFLITE_DCHECK(affine_quantization != nullptr); + TFLITE_DCHECK(affine_quantization->scale != nullptr); + TFLITE_DCHECK(affine_quantization->zero_point != nullptr); + + TF_LITE_ENSURE(context, + affine_quantization->scale->size == 1 || + affine_quantization->scale->size == + filter->dims->data[kConvQuantizedDimension]); + TF_LITE_ENSURE_EQ(context, affine_quantization->scale->size, + affine_quantization->zero_point->size); + } + + TF_LITE_ENSURE_STATUS(CalculateOpDataConv( + context, node, params, input_width, input_height, filter_width, + filter_height, output_width, output_height, input->type, data)); + + return kTfLiteOk; +} +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/conv_test.cc b/components/tflite/tensorflow/lite/micro/kernels/conv_test.cc new file mode 100644 index 00000000..22db3c07 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/conv_test.cc @@ -0,0 +1,820 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/kernels/conv_test.h" + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/micro_utils.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +// Common inputs and outputs. +constexpr int kInputElements = 16; +static int kInputShape[] = { 4, 2, 2, 4, 1 }; +static const float kInputData[kInputElements] = { 1, 1, 1, 1, 2, 2, 2, 2, + 1, 2, 3, 4, 1, 2, 3, 4 }; + +constexpr int kFilterElements = 12; +static int kFilterShape[] = { 4, 3, 2, 2, 1 }; +static const float kFilterData[kFilterElements] = { 1, 2, 3, 4, -1, 1, + -1, 1, -1, -1, 1, 1 }; + +constexpr int kBiasElements = 3; +static int kBiasShape[] = { 1, 3 }; +static const float kBiasData[kBiasElements] = { 1, 2, 3 }; + +constexpr int kOutputElements = 12; +static int kOutputShape[] = { 4, 2, 1, 2, 3 }; +static const float kGoldenData[kOutputElements] = { 18, 2, 5, 18, 2, 5, + 17, 4, 3, 37, 4, 3 }; + +static TfLiteConvParams common_conv_params = { + kTfLitePaddingValid, // padding + 2, // stride_width + 2, // stride_height + kTfLiteActNone, // activation + 1, // dilation_width_factor + 1, // dilation_height_factor +}; + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +#if !defined(XTENSA) // TODO(b/170321206): xtensa kernels are less general than \ + // reference kernels and we ifdef out test cases that are \ + // currently known to fail. +TF_LITE_MICRO_TEST(SimpleTestFloat) +{ + float output_data[tflite::testing::kOutputElements]; + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, + tflite::testing::TestConvFloat( + tflite::testing::kInputShape, tflite::testing::kInputData, + tflite::testing::kFilterShape, tflite::testing::kFilterData, + tflite::testing::kBiasShape, tflite::testing::kBiasData, + tflite::testing::kOutputShape, tflite::testing::kGoldenData, + &tflite::testing::common_conv_params, tflite::Register_CONV_2D(), + output_data)); +} + +TF_LITE_MICRO_TEST(InputAndFilterSameWidthHeight) +{ + const int output_dims_count = 2; + float output_data[output_dims_count]; + + int kFilterShape[] = { 4, 1, 2, 4, 1 }; + const float filter_values[] = { 1, 2, 3, 4, -1, -1, 1, 1 }; + int kBiasShape[] = { 1, 1 }; + const float bias_values[] = { 0 }; + int kOutputShape[] = { 4, 2, 1, 1, 1 }; + const float expected_output[] = { 10, 34 }; + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, + tflite::testing::TestConvFloat( + tflite::testing::kInputShape, tflite::testing::kInputData, + kFilterShape, filter_values, kBiasShape, bias_values, kOutputShape, + expected_output, &tflite::testing::common_conv_params, + tflite::Register_CONV_2D(), output_data)); +} + +TF_LITE_MICRO_TEST(InputOutputDifferentTypeIsError) +{ + using tflite::testing::CreateQuantizedTensor; + using tflite::testing::CreateTensor; + using tflite::testing::IntArrayFromInts; + + TfLiteIntArray *input_dims = IntArrayFromInts(tflite::testing::kInputShape); + TfLiteIntArray *filter_dims = IntArrayFromInts(tflite::testing::kFilterShape); + TfLiteIntArray *bias_dims = IntArrayFromInts(tflite::testing::kBiasShape); + TfLiteIntArray *output_dims = IntArrayFromInts(tflite::testing::kOutputShape); + const int output_dims_count = tflite::ElementCount(*output_dims); + constexpr int inputs_size = 3; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + + int8_t output_data[tflite::testing::kOutputElements]; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(tflite::testing::kInputData, input_dims), + CreateTensor(tflite::testing::kFilterData, filter_dims), + CreateTensor(tflite::testing::kBiasData, bias_dims), + CreateQuantizedTensor(output_data, output_dims, /*scale=*/0.0f, + /*zero_point=*/0), + }; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteError, + tflite::testing::InvokeConv(tensors, tensors_size, output_dims_count, + &tflite::testing::common_conv_params, + tflite::Register_CONV_2D(), output_data)); +} + +TF_LITE_MICRO_TEST(HybridModeIsError) +{ + using tflite::testing::CreateQuantizedTensor; + using tflite::testing::CreateTensor; + using tflite::testing::IntArrayFromInts; + + TfLiteIntArray *input_dims = IntArrayFromInts(tflite::testing::kInputShape); + TfLiteIntArray *filter_dims = IntArrayFromInts(tflite::testing::kFilterShape); + TfLiteIntArray *bias_dims = IntArrayFromInts(tflite::testing::kBiasShape); + TfLiteIntArray *output_dims = IntArrayFromInts(tflite::testing::kOutputShape); + const int output_dims_count = tflite::ElementCount(*output_dims); + constexpr int inputs_size = 3; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + + int8_t filter_data[tflite::testing::kFilterElements] = {}; + float output_data[tflite::testing::kOutputElements]; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(tflite::testing::kInputData, input_dims), + CreateQuantizedTensor(filter_data, filter_dims, + /*scale=*/0.0f, + /*zero_point=*/0), + CreateTensor(tflite::testing::kBiasData, bias_dims), + CreateTensor(output_data, output_dims), + }; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteError, + tflite::testing::InvokeConv(tensors, tensors_size, output_dims_count, + &tflite::testing::common_conv_params, + tflite::Register_CONV_2D(), output_data)); +} + +TF_LITE_MICRO_TEST(SimpleTestQuantizedPerChannel) +{ + const int output_dims_count = 12; + int8_t output_data[output_dims_count]; + + const float input_scale = 0.5f; + const float output_scale = 1.0f; + const int input_zero_point = 0; + const int output_zero_point = 0; + + int8_t input_quantized[tflite::testing::kInputElements]; + int8_t filter_quantized[tflite::testing::kFilterElements]; + int32_t bias_quantized[tflite::testing::kBiasElements]; + int8_t golden_quantized[tflite::testing::kOutputElements]; + int zero_points[tflite::testing::kBiasElements + 1]; + float scales[tflite::testing::kBiasElements + 1]; + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, + tflite::testing::TestConvQuantizedPerChannel( + tflite::testing::kInputShape, tflite::testing::kInputData, + input_quantized, input_scale, input_zero_point, + tflite::testing::kFilterShape, tflite::testing::kFilterData, + filter_quantized, tflite::testing::kBiasShape, + tflite::testing::kBiasData, bias_quantized, scales, zero_points, + tflite::testing::kOutputShape, tflite::testing::kGoldenData, + golden_quantized, output_scale, output_zero_point, + &tflite::testing::common_conv_params, tflite::Register_CONV_2D(), + output_data)); +} + +TF_LITE_MICRO_TEST(SimpleTestQuantized16x8PerChannel) +{ + const int output_dims_count = 12; + int16_t output_data[output_dims_count]; + + const float input_scale = 0.5f; + const float output_scale = 1.0f; + const int input_zero_point = 0; + const int output_zero_point = 0; + + int16_t input_quantized[tflite::testing::kInputElements]; + int8_t filter_quantized[tflite::testing::kFilterElements]; + std::int64_t bias_quantized[tflite::testing::kBiasElements]; + int16_t golden_quantized[tflite::testing::kOutputElements]; + int zero_points[tflite::testing::kBiasElements + 1]; + float scales[tflite::testing::kBiasElements + 1]; + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, + tflite::testing::TestConvQuantizedPerChannel( + tflite::testing::kInputShape, tflite::testing::kInputData, + input_quantized, input_scale, input_zero_point, + tflite::testing::kFilterShape, tflite::testing::kFilterData, + filter_quantized, tflite::testing::kBiasShape, + tflite::testing::kBiasData, bias_quantized, scales, zero_points, + tflite::testing::kOutputShape, tflite::testing::kGoldenData, + golden_quantized, output_scale, output_zero_point, + &tflite::testing::common_conv_params, tflite::Register_CONV_2D(), + output_data)); +} + +TF_LITE_MICRO_TEST(SimpleTestDilatedQuantizedPerChannel) +{ + const int output_dims_count = 24; + int8_t output_data[output_dims_count]; + + const float input_scale = 0.5f; + const float output_scale = 1.0f; + const int input_zero_point = 0; + const int output_zero_point = 0; + + const int input_elements = 48; + int input_shape[] = { 4, 2, 4, 6, 1 }; + const float input_data[] = { + // b = 0 + 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, + // b = 1 + 1, 2, 3, 4, 5, 6, 2, 6, 2, 4, 4, 2, 3, 2, 6, 5, 1, 4, 1, 2, 1, 4, 6, 3 + }; + const int output_elements = 24; + int output_shape[] = { 4, 2, 2, 2, 3 }; + const float golden_data[] = { 25, 2, 7, 25, 2, 7, 10, 2, -3, 10, 2, -3, + 39, 7, 6, 50, 3, 4, 14, 4, -5, 15, 0, -7 }; + + int8_t input_quantized[input_elements]; + int8_t filter_quantized[tflite::testing::kFilterElements]; + int32_t bias_quantized[tflite::testing::kBiasElements]; + int8_t golden_quantized[output_elements]; + int zero_points[tflite::testing::kBiasElements + 1]; + float scales[tflite::testing::kBiasElements + 1]; + + TfLiteConvParams conv_params{ tflite::testing::common_conv_params }; + conv_params.dilation_width_factor = 3; + conv_params.dilation_height_factor = 2; + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, + tflite::testing::TestConvQuantizedPerChannel( + input_shape, input_data, input_quantized, input_scale, + input_zero_point, tflite::testing::kFilterShape, + tflite::testing::kFilterData, filter_quantized, + tflite::testing::kBiasShape, tflite::testing::kBiasData, + bias_quantized, scales, zero_points, output_shape, golden_data, + golden_quantized, output_scale, output_zero_point, &conv_params, + tflite::Register_CONV_2D(), output_data)); +} + +TF_LITE_MICRO_TEST(SimpleTestQuantizedPerChannelRelu6) +{ + const int output_dims_count = 12; + int8_t output_data[output_dims_count]; + + const float bias_values[] = { 1, 2, -3 }; + const float golden_data[] = { 6, 2, 0, 6, 2, 0, 6, 4, 0, 6, 4, 0 }; + + const float input_scale = 0.023529f; + const float output_scale = 0.023529f; + const int input_zero_point = -128; + const int output_zero_point = -128; + + int8_t input_quantized[tflite::testing::kInputElements]; + int8_t filter_quantized[tflite::testing::kFilterElements]; + int32_t bias_quantized[tflite::testing::kBiasElements]; + int8_t golden_quantized[tflite::testing::kOutputElements]; + int zero_points[tflite::testing::kBiasElements + 1]; + float scales[tflite::testing::kBiasElements + 1]; + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, + tflite::testing::TestConvQuantizedPerChannel( + tflite::testing::kInputShape, tflite::testing::kInputData, + input_quantized, input_scale, input_zero_point, + tflite::testing::kFilterShape, tflite::testing::kFilterData, + filter_quantized, tflite::testing::kBiasShape, bias_values, + bias_quantized, scales, zero_points, tflite::testing::kOutputShape, + golden_data, golden_quantized, output_scale, output_zero_point, + &tflite::testing::common_conv_params, tflite::Register_CONV_2D(), + output_data)); +} + +TF_LITE_MICRO_TEST(SimpleTestQuantized16x8PerChannelRelu6) +{ + const int output_dims_count = 12; + int16_t output_data[output_dims_count]; + + const float bias_values[] = { 1, 2, -3 }; + const float golden_data[] = { 6, 2, 0, 6, 2, 0, 6, 4, 0, 6, 4, 0 }; + + const float input_scale = 0.023529f; + const float output_scale = 0.023529f; + const int input_zero_point = 0; + const int output_zero_point = 0; + + int16_t input_quantized[tflite::testing::kInputElements]; + int8_t filter_quantized[tflite::testing::kFilterElements]; + std::int64_t bias_quantized[tflite::testing::kBiasElements]; + int16_t golden_quantized[tflite::testing::kOutputElements]; + int zero_points[tflite::testing::kBiasElements + 1]; + float scales[tflite::testing::kBiasElements + 1]; + + TfLiteConvParams conv_params{ tflite::testing::common_conv_params }; + conv_params.activation = kTfLiteActRelu6; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, + tflite::testing::TestConvQuantizedPerChannel( + tflite::testing::kInputShape, tflite::testing::kInputData, + input_quantized, input_scale, input_zero_point, + tflite::testing::kFilterShape, tflite::testing::kFilterData, + filter_quantized, tflite::testing::kBiasShape, bias_values, + bias_quantized, scales, zero_points, tflite::testing::kOutputShape, + golden_data, golden_quantized, output_scale, output_zero_point, + &conv_params, tflite::Register_CONV_2D(), output_data)); +} + +TF_LITE_MICRO_TEST(Kernel1x1QuantizedPerChannel) +{ + // conv params: + // padding, stride_, activation, dilation_ + TfLiteConvParams conv_params = { kTfLitePaddingValid, 1, 1, + kTfLiteActNone, 1, 1 }; + + int input_shape[] = { 4, 1, 2, 2, 4 }; // [len,N,H,W,C] + constexpr int input_elements = + 1 * 2 * 2 * + 4; // input_shape[1] * input_shape[2] * input_shape[3] * input_shape[4]; + constexpr float input_data[input_elements] = { 1, 1, 1, 1, 2, 2, 2, 2, + 1, 2, 3, 4, 1, 2, 3, 4 }; + + int filter_shape[] = { 4, 3, 1, 1, 4 }; + constexpr int filter_elements = + 3 * 1 * 1 * 4; // filter_shape[1] * filter_shape[2] * + // filter_shape[3] * filter_shape[4]; + const float filter_data[filter_elements] = { 1, 2, 3, 4, -1, 1, + -1, 1, -1, -1, 1, 1 }; + + constexpr int bias_elements = 3; // filter_shape[1]; + int bias_shape[] = { 1, bias_elements }; + constexpr float bias_data[bias_elements] = { 1, 2, 3 }; + + int output_shape[] = { 4, 1, 2, 2, bias_elements }; + constexpr int output_elements = 4 * 3; + int8_t output_data[output_elements]; + + const float golden_data[output_elements] = { 11, 2, 3, 21, 2, 3, + 31, 4, 7, 31, 4, 7 }; + + const float input_scale = 0.5f; + const float output_scale = 1.0f; + const int input_zero_point = 0; + const int output_zero_point = 0; + + int8_t input_quantized[input_elements]; + int8_t filter_quantized[filter_elements]; + int32_t bias_quantized[bias_elements]; + int8_t golden_quantized[output_elements]; + int zero_points[bias_elements + 1]; + float scales[bias_elements + 1]; + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, tflite::testing::TestConvQuantizedPerChannel( + input_shape, input_data, input_quantized, input_scale, + input_zero_point, filter_shape, filter_data, + filter_quantized, bias_shape, bias_data, bias_quantized, + scales, zero_points, output_shape, golden_data, + golden_quantized, output_scale, output_zero_point, + &conv_params, tflite::Register_CONV_2D(), output_data)); +} + +TF_LITE_MICRO_TEST(Kernel1x1QuantizedPerChannelRelu6) +{ + // conv params: + // padding, stride_, activation, dilation_ + TfLiteConvParams conv_params = { kTfLitePaddingValid, 1, 1, + kTfLiteActRelu6, 1, 1 }; + + int input_shape[] = { 4, 1, 2, 2, 4 }; // [len,N,H,W,C] + constexpr int input_elements = + 1 * 2 * 2 * + 4; // input_shape[1] * input_shape[2] * input_shape[3] * input_shape[4]; + constexpr float input_data[input_elements] = { 1, 1, 1, 1, 2, 2, 2, 2, + 1, 2, 3, 4, 1, 2, 3, 4 }; + + int filter_shape[] = { 4, 3, 1, 1, 4 }; + constexpr int filter_elements = + 3 * 1 * 1 * 4; // filter_shape[1] * filter_shape[2] * + // filter_shape[3] * filter_shape[4]; + const float filter_data[filter_elements] = { 1, 2, 3, 4, -1, 1, + -1, 1, -1, -1, 1, 1 }; + + constexpr int bias_elements = 3; // filter_shape[1]; + int bias_shape[] = { 1, bias_elements }; + constexpr float bias_data[bias_elements] = { 1, 2, -3 }; + + int output_shape[] = { 4, 1, 2, 2, bias_elements }; + constexpr int output_elements = 4 * 3; + int8_t output_data[output_elements]; + + const float golden_data[output_elements] = { 6, 2, 0, 6, 2, 0, + 6, 4, 1, 6, 4, 1 }; + + const float input_scale = 0.023529f; + const float output_scale = 0.023529f; + const int input_zero_point = -128; + const int output_zero_point = -128; + + int8_t input_quantized[input_elements]; + int8_t filter_quantized[filter_elements]; + int32_t bias_quantized[bias_elements]; + int8_t golden_quantized[output_elements]; + int zero_points[bias_elements + 1]; + float scales[bias_elements + 1]; + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, tflite::testing::TestConvQuantizedPerChannel( + input_shape, input_data, input_quantized, input_scale, + input_zero_point, filter_shape, filter_data, + filter_quantized, bias_shape, bias_data, bias_quantized, + scales, zero_points, output_shape, golden_data, + golden_quantized, output_scale, output_zero_point, + &conv_params, tflite::Register_CONV_2D(), output_data)); +} + +TF_LITE_MICRO_TEST(Kernel1x1Quantized16x8PerChannelRelu6) +{ + // conv params: + // padding, stride_, activation, dilation_ + TfLiteConvParams conv_params = { kTfLitePaddingValid, 1, 1, + kTfLiteActRelu6, 1, 1 }; + + int input_shape[] = { 4, 1, 2, 2, 4 }; // [len,N,H,W,C] + const int input_elements = 1 * 2 * 2 * 4; + const float input_data[input_elements] = { 1, 1, 1, 1, 2, 2, 2, 2, + 1, 2, 3, 4, 1, 2, 3, 4 }; + + int filter_shape[] = { 4, 3, 1, 1, 4 }; + const int filter_elements = 3 * 1 * 1 * 4; + const float filter_data[filter_elements] = { 1, 2, 3, 4, -1, 1, + -1, 1, -1, -1, 1, 1 }; + + const int bias_elements = 3; + int bias_shape[] = { 1, bias_elements }; + const float bias_data[bias_elements] = { 1, 2, -3 }; + + int output_shape[] = { 4, 1, 2, 2, bias_elements }; + const int output_elements = 4 * 3; + int16_t output_data[output_elements]; + + const float golden_data[output_elements] = { 6, 2, 0, 6, 2, 0, + 6, 4, 1, 6, 4, 1 }; + + const float input_scale = 0.023529f; + const float output_scale = 0.023529f; + const int input_zero_point = 0; + const int output_zero_point = 0; + + int16_t input_quantized[input_elements]; + int8_t filter_quantized[filter_elements]; + std::int64_t bias_quantized[bias_elements]; + int16_t golden_quantized[output_elements]; + int zero_points[bias_elements + 1]; + float scales[bias_elements + 1]; + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, tflite::testing::TestConvQuantizedPerChannel( + input_shape, input_data, input_quantized, input_scale, + input_zero_point, filter_shape, filter_data, + filter_quantized, bias_shape, bias_data, bias_quantized, + scales, zero_points, output_shape, golden_data, + golden_quantized, output_scale, output_zero_point, + &conv_params, tflite::Register_CONV_2D(), output_data)); +} + +TF_LITE_MICRO_TEST(BroadcastPerLayerQuantizationToPerChannelShouldMatchGolden) +{ + const int output_dims_count = 12; + int8_t output_data[output_dims_count]; + + const float input_scale = 1.0f; + const float filter_scale = 1.0f; + const float output_scale = 1.0f; + + int8_t input_quantized[tflite::testing::kInputElements]; + int8_t filter_quantized[tflite::testing::kFilterElements]; + int32_t bias_quantized[tflite::testing::kBiasElements]; + int8_t golden_quantized[tflite::testing::kOutputElements]; + + TfLiteIntArray *input_dims = + tflite::testing::IntArrayFromInts(tflite::testing::kInputShape); + TfLiteIntArray *filter_dims = + tflite::testing::IntArrayFromInts(tflite::testing::kFilterShape); + TfLiteIntArray *bias_dims = + tflite::testing::IntArrayFromInts(tflite::testing::kBiasShape); + TfLiteIntArray *output_dims = + tflite::testing::IntArrayFromInts(tflite::testing::kOutputShape); + + // Create per-layer quantized int8_t input tensor. + TfLiteTensor input_tensor = tflite::testing::CreateQuantizedTensor( + tflite::testing::kInputData, input_quantized, input_dims, input_scale, 0); + int input_zero_points[2] = { 1, 0 }; + float input_scales[2] = { 1, input_scale }; + TfLiteAffineQuantization input_quant = { + tflite::testing::FloatArrayFromFloats(input_scales), + tflite::testing::IntArrayFromInts(input_zero_points), 0 + }; + input_tensor.quantization = { kTfLiteAffineQuantization, &input_quant }; + + // Create per-layer quantized int8_t filter tensor. + TfLiteTensor filter_tensor = tflite::testing::CreateQuantizedTensor( + tflite::testing::kFilterData, filter_quantized, filter_dims, filter_scale, + 0); + int filter_zero_points[2] = { 1, 0 }; + float filter_scales[2] = { 1, filter_scale }; + TfLiteAffineQuantization filter_quant = { + tflite::testing::FloatArrayFromFloats(filter_scales), + tflite::testing::IntArrayFromInts(filter_zero_points), 0 + }; + filter_tensor.quantization = { kTfLiteAffineQuantization, &filter_quant }; + + // Create per-layer quantized int32_t bias tensor. + tflite::SymmetricQuantize(tflite::testing::kBiasData, bias_quantized, + tflite::testing::kBiasElements, + input_scale * output_scale); + TfLiteTensor bias_tensor = + tflite::testing::CreateTensor(bias_quantized, bias_dims); + + int bias_zero_points[2] = { 1, 0 }; + float bias_scales[2] = { 1, input_scale * filter_scale }; + TfLiteAffineQuantization bias_quant = { + tflite::testing::FloatArrayFromFloats(bias_scales), + tflite::testing::IntArrayFromInts(bias_zero_points), 0 + }; + bias_tensor.quantization = { kTfLiteAffineQuantization, &bias_quant }; + + // Create per-layer quantized int8_t output tensor. + TfLiteTensor output_tensor = tflite::testing::CreateQuantizedTensor( + output_data, output_dims, output_scale, 0 /* quantized dimension */); + int output_zero_points[2] = { 1, 0 }; + float output_scales[2] = { 1, output_scale }; + TfLiteAffineQuantization output_quant = { + tflite::testing::FloatArrayFromFloats(output_scales), + tflite::testing::IntArrayFromInts(output_zero_points), 0 + }; + output_tensor.quantization = { kTfLiteAffineQuantization, &output_quant }; + + constexpr int inputs_size = 3; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + input_tensor, + filter_tensor, + bias_tensor, + output_tensor, + }; + + tflite::Quantize(tflite::testing::kGoldenData, golden_quantized, + output_dims_count, output_scale, 0); + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, tflite::testing::ValidateConvGoldens( + tensors, tensors_size, golden_quantized, output_dims_count, + &tflite::testing::common_conv_params, + tflite::Register_CONV_2D(), output_data)); +} + +#endif // !defined(XTENSA) + +TF_LITE_MICRO_TEST(FilterDimsNotMatchingAffineQuantization) +{ + const int output_dims_count = 12; + int8_t output_data[output_dims_count]; + + const float input_scale = 0.5f; + const float output_scale = 1.0f; + + int8_t input_quantized[tflite::testing::kInputElements]; + int8_t filter_quantized[tflite::testing::kFilterElements]; + int32_t bias_quantized[tflite::testing::kBiasElements]; + int8_t golden_quantized[tflite::testing::kOutputElements]; + int zero_points[tflite::testing::kBiasElements + 1]; + float scales[tflite::testing::kBiasElements + 1]; + + TfLiteIntArray *input_dims = + tflite::testing::IntArrayFromInts(tflite::testing::kInputShape); + TfLiteIntArray *filter_dims = + tflite::testing::IntArrayFromInts(tflite::testing::kFilterShape); + TfLiteIntArray *bias_dims = + tflite::testing::IntArrayFromInts(tflite::testing::kBiasShape); + TfLiteIntArray *output_dims = + tflite::testing::IntArrayFromInts(tflite::testing::kOutputShape); + + int filter_zero_points[5]; + float filter_scales[5]; + TfLiteAffineQuantization filter_quant; + TfLiteAffineQuantization bias_quant; + TfLiteTensor input_tensor = tflite::testing::CreateQuantizedTensor( + tflite::testing::kInputData, input_quantized, input_dims, input_scale, 0); + TfLiteTensor filter_tensor = + tflite::testing::CreateSymmetricPerChannelQuantizedTensor( + tflite::testing::kFilterData, filter_quantized, filter_dims, + filter_scales, filter_zero_points, &filter_quant, + 0 /* quantized dimension */); + TfLiteTensor bias_tensor = + tflite::testing::CreatePerChannelQuantizedBiasTensor( + tflite::testing::kBiasData, bias_quantized, bias_dims, input_scale, + &filter_scales[1], scales, zero_points, &bias_quant, 0); + TfLiteTensor output_tensor = tflite::testing::CreateQuantizedTensor( + output_data, output_dims, output_scale, 0 /* quantized dimension */); + + float input_scales[] = { 1, input_scale }; + int input_zero_points[] = { 1, 128 }; + TfLiteAffineQuantization input_quant = { + tflite::testing::FloatArrayFromFloats(input_scales), + tflite::testing::IntArrayFromInts(input_zero_points), 0 + }; + input_tensor.quantization = { kTfLiteAffineQuantization, &input_quant }; + + constexpr int inputs_size = 3; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + input_tensor, + filter_tensor, + bias_tensor, + output_tensor, + }; + + tflite::Quantize(tflite::testing::kGoldenData, golden_quantized, + output_dims_count, output_scale, 0); + + // Set filter quant to mismatched dimension. + TfLiteAffineQuantization *quant = reinterpret_cast( + filter_tensor.quantization.params); + + // Choose arbitrary incorrect scale and zero point sizes which are neither 1 + // (for broadcast case) nor the quantized dimension size. + quant->scale->size = 2; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteError, tflite::testing::ValidateConvGoldens( + tensors, tensors_size, golden_quantized, + output_dims_count, &tflite::testing::common_conv_params, + tflite::Register_CONV_2D(), output_data)); + + // Set scale back to correct dimension, and make zero point array too short. + quant->scale->size = tflite::testing::kFilterShape[0]; + quant->zero_point->size = 2; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteError, tflite::testing::ValidateConvGoldens( + tensors, tensors_size, golden_quantized, + output_dims_count, &tflite::testing::common_conv_params, + tflite::Register_CONV_2D(), output_data)); +} + +TF_LITE_MICRO_TEST(Int8Input32x1Filter32x32ShouldMatchGolden) +{ + constexpr int kSampleSize = 32; + constexpr int kNumFilters = 32; + int input_shape[] = { 4, 1, 1, 1, kSampleSize }; + int filter_shape[] = { 4, kNumFilters, 1, 1, kSampleSize }; + int bias_shape[] = { 1, kSampleSize }; + int output_shape[] = { 4, 1, 1, 1, kSampleSize }; + float filter_values[kNumFilters * kSampleSize]; + float input_values[kSampleSize]; + float bias_values[kSampleSize]; + + // Generated these outputs using the floating point reference conv kernel. + // TODO(b/149942509): Do this comparison automatically on random inputs. + float expected_output[kSampleSize] = { + 5168.000000, 3377.000000, 306.000000, -4045.000000, -4556.000000, + -1227.000000, 822.000000, 1591.000000, 5176.000000, 3385.000000, + 314.000000, -4037.000000, -4548.000000, -1219.000000, 830.000000, + 1599.000000, 5184.000000, 3393.000000, 322.000000, -4029.000000, + -4540.000000, -1211.000000, 838.000000, 1607.000000, 5192.000000, + 3401.000000, 330.000000, -4021.000000, -4532.000000, -1203.000000, + 846.000000, 1615.000000 + }; + + for (int i = 0; i < kSampleSize; i++) { + bias_values[i] = i; + // Generate inputs from -16 to 15. + input_values[i] = i - 16; + } + + // Generate samples of varying values between -128 and 127. + for (int i = 0; i < kNumFilters * kSampleSize; i++) { + filter_values[i] = (i * 25) % 256 - 128; + } + + TfLiteConvParams conv_params; + conv_params.activation = kTfLiteActNone; + conv_params.dilation_height_factor = 1; + conv_params.dilation_width_factor = 1; + conv_params.stride_height = 1; + conv_params.stride_width = 1; + conv_params.padding = kTfLitePaddingValid; + + TfLiteIntArray *input_dims = tflite::testing::IntArrayFromInts(input_shape); + TfLiteIntArray *filter_dims = tflite::testing::IntArrayFromInts(filter_shape); + TfLiteIntArray *bias_dims = tflite::testing::IntArrayFromInts(bias_shape); + TfLiteIntArray *output_dims = tflite::testing::IntArrayFromInts(output_shape); + const int output_dims_count = tflite::ElementCount(*output_dims); + + // Quantization Parameters. All scales except output are 1.0, and all zero + // points are 0. This direct-maps the values to floating point and makes it + // easy to reson about them. + int input_zero_point = 0; + float input_scale = 1.0f; + int filter_zero_point = 0; + float filter_scale = 1.0f; + int output_zero_point = 0; + // Output scale of 50 is needed to accomodate a float range of [-6400, 6350] + float output_scale = 50.0f; + + // Create per-tensor quantized int8_t input tensor. + int8_t input_quantized[kSampleSize]; + TfLiteTensor input_tensor = tflite::testing::CreateQuantizedTensor( + input_values, input_quantized, input_dims, input_scale, input_zero_point); + // Set zero point and scale arrays with a single element for each. + int input_zero_points[] = { 1, input_zero_point }; + float input_scales[] = { 1, input_scale }; + TfLiteAffineQuantization input_quant = { + tflite::testing::FloatArrayFromFloats(input_scales), + tflite::testing::IntArrayFromInts(input_zero_points), 0 + }; + input_tensor.quantization = { kTfLiteAffineQuantization, &input_quant }; + + // Create per-tensor quantized int8_t filter tensor. + int8_t filter_quantized[kNumFilters * kSampleSize]; + TfLiteTensor filter_tensor = tflite::testing::CreateQuantizedTensor( + filter_values, filter_quantized, filter_dims, filter_scale, + filter_zero_point); + // Set zero point and scale arrays with a single element for each. + int filter_zero_points[] = { 1, filter_zero_point }; + float filter_scales[] = { 1, filter_scale }; + TfLiteAffineQuantization filter_quant = { + tflite::testing::FloatArrayFromFloats(filter_scales), + tflite::testing::IntArrayFromInts(filter_zero_points), 0 + }; + filter_tensor.quantization = { kTfLiteAffineQuantization, &filter_quant }; + + // Create per-tensor quantized int32_t bias tensor. + int32_t bias_quantized[kSampleSize]; + tflite::SymmetricQuantize(bias_values, bias_quantized, kSampleSize, + input_scale * output_scale); + TfLiteTensor bias_tensor = + tflite::testing::CreateTensor(bias_quantized, bias_dims); + + // There is a single zero point of 0, and a single scale of + // input_scale * filter_scale. + int bias_zero_points[] = { 1, 0 }; + float bias_scales[] = { 1, input_scale * filter_scale }; + TfLiteAffineQuantization bias_quant = { + tflite::testing::FloatArrayFromFloats(bias_scales), + tflite::testing::IntArrayFromInts(bias_zero_points), 0 + }; + bias_tensor.quantization = { kTfLiteAffineQuantization, &bias_quant }; + + // Create per-tensor quantized int8_t output tensor. + int8_t output_quantized[kSampleSize]; + TfLiteTensor output_tensor = tflite::testing::CreateQuantizedTensor( + output_quantized, output_dims, output_scale, output_zero_point); + // Set zero point and scale arrays with a single element for each. + int output_zero_points[] = { 1, output_zero_point }; + float output_scales[] = { 1, output_scale }; + TfLiteAffineQuantization output_quant = { + tflite::testing::FloatArrayFromFloats(output_scales), + tflite::testing::IntArrayFromInts(output_zero_points), 0 + }; + output_tensor.quantization = { kTfLiteAffineQuantization, &output_quant }; + + // The 3 inputs include the input, filter and bias tensors. + constexpr int kInputsSize = 3; + constexpr int kOutputsSize = 1; + constexpr int kTensorsSize = kInputsSize + kOutputsSize; + TfLiteTensor tensors[kTensorsSize] = { + input_tensor, + filter_tensor, + bias_tensor, + output_tensor, + }; + + int8_t golden_quantized[kSampleSize]; + tflite::Quantize(expected_output, golden_quantized, output_dims_count, + output_scale, output_zero_point); + + // Rounding errors due to quantization should not exceed 1. + constexpr int kQuantizationTolerance = 1; + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, tflite::testing::ValidateConvGoldens( + tensors, kTensorsSize, golden_quantized, output_dims_count, + &conv_params, tflite::Register_CONV_2D(), output_quantized, + kQuantizationTolerance)); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/conv_test.h b/components/tflite/tensorflow/lite/micro/kernels/conv_test.h new file mode 100644 index 00000000..4ca53a04 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/conv_test.h @@ -0,0 +1,102 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_KERNELS_CONV_TEST_H_ +#define TENSORFLOW_LITE_MICRO_KERNELS_CONV_TEST_H_ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/kernels/micro_ops.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +TfLiteStatus InvokeConv(TfLiteTensor *tensors, int tensors_size, + int output_length, TfLiteConvParams *conv_params, + TfLiteRegistration registration, float *output_data); + +TfLiteStatus InvokeConv(TfLiteTensor *tensors, int tensors_size, + int output_length, TfLiteConvParams *conv_params, + TfLiteRegistration registration, int8_t *output_data); + +TfLiteStatus InvokeConv(TfLiteTensor *tensors, int tensors_size, + int output_length, TfLiteConvParams *conv_params, + TfLiteRegistration registration, uint8_t *output_data); + +TfLiteStatus ValidateConvGoldens(TfLiteTensor *tensors, int tensors_size, + const float *expected_output_data, + int output_length, + TfLiteConvParams *conv_params, + TfLiteRegistration registration, + float *output_data, float tolerance = 1e-5); + +TfLiteStatus ValidateConvGoldens(TfLiteTensor *tensors, int tensors_size, + const int8_t *expected_output_data, + int output_length, + TfLiteConvParams *conv_params, + TfLiteRegistration registration, + int8_t *output_data, float tolerance = 1e-5); + +TfLiteStatus ValidateConvGoldens(TfLiteTensor *tensors, int tensors_size, + const uint8_t *expected_output_data, + int output_length, + TfLiteConvParams *conv_params, + TfLiteRegistration registration, + uint8_t *output_data, float tolerance = 1e-5); + +TfLiteStatus TestConvFloat(int *input_dims_data, const float *input_data, + int *filter_dims_data, const float *filter_data, + int *bias_dims_data, const float *bias_data, + int *output_dims_data, + const float *expected_output_data, + TfLiteConvParams *conv_params, + TfLiteRegistration registration, float *output_data); + +TfLiteStatus TestConvQuantizedPerLayer( + int *input_dims_data, const float *input_data, uint8_t *input_quantized, + float input_scale, int *filter_dims_data, const float *filter_data, + uint8_t *filter_quantized, float filter_scale, int *bias_dims_data, + const float *bias_data, int32_t *bias_quantized, int *output_dims_data, + const float *expected_output_data, uint8_t *expected_output_quantized, + float output_scale, TfLiteConvParams *conv_params, + TfLiteRegistration registration, uint8_t *output_data); + +TfLiteStatus TestConvQuantizedPerChannel( + int *input_dims_data, const float *input_data, int8_t *input_quantized, + float input_scale, int input_zero_point, int *filter_dims_data, + const float *filter_data, int8_t *filter_data_quantized, + int *bias_dims_data, const float *bias_data, int32_t *bias_data_quantized, + float *bias_scales, int *bias_zero_points, int *output_dims_data, + const float *expected_output_data, int8_t *expected_output_data_quantized, + float output_scale, int output_zero_point, TfLiteConvParams *conv_params, + TfLiteRegistration registration, int8_t *output_data); + +TfLiteStatus TestConvQuantizedPerChannel( + int *input_dims_data, const float *input_data, int16_t *input_quantized, + float input_scale, int input_zero_point, int *filter_dims_data, + const float *filter_data, int8_t *filter_data_quantized, + int *bias_dims_data, const float *bias_data, + std::int64_t *bias_data_quantized, float *bias_scales, + int *bias_zero_points, int *output_dims_data, + const float *expected_output_data, int16_t *expected_output_data_quantized, + float output_scale, int output_zero_point, TfLiteConvParams *conv_params, + TfLiteRegistration registration, int16_t *output_data); + +} // namespace testing +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_KERNELS_CONV_TEST_H_ diff --git a/components/tflite/tensorflow/lite/micro/kernels/conv_test_common.cc b/components/tflite/tensorflow/lite/micro/kernels/conv_test_common.cc new file mode 100644 index 00000000..6fe6ee6d --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/conv_test_common.cc @@ -0,0 +1,234 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/kernels/conv_test.h" + +namespace tflite { +namespace testing { + +template +TfLiteStatus InvokeConv(TfLiteTensor *tensors, int tensors_size, + int output_length, TfLiteConvParams *conv_params, + TfLiteRegistration registration, T *output_data) +{ + int inputs_array_data[] = { 3, 0, 1, 2 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 3 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, conv_params); + + const char *init_data = reinterpret_cast(conv_params); + TfLiteStatus status = runner.InitAndPrepare(init_data); + if (status != kTfLiteOk) { + return status; + } + return runner.Invoke(); +} + +template +TfLiteStatus ValidateConvGoldens(TfLiteTensor *tensors, int tensors_size, + const T *expected_output_data, + int output_length, + TfLiteConvParams *conv_params, + TfLiteRegistration registration, + T *output_data, float tolerance) +{ + TfLiteStatus status = InvokeConv(tensors, tensors_size, output_length, + conv_params, registration, output_data); + if (status != kTfLiteOk) { + return status; + } + for (int i = 0; i < output_length; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output_data[i], output_data[i], + tolerance); + } + return kTfLiteOk; +} + +TfLiteStatus InvokeConv(TfLiteTensor *tensors, int tensors_size, + int output_length, TfLiteConvParams *conv_params, + TfLiteRegistration registration, float *output_data) +{ + return InvokeConv(tensors, tensors_size, output_length, conv_params, + registration, output_data); +} + +TfLiteStatus InvokeConv(TfLiteTensor *tensors, int tensors_size, + int output_length, TfLiteConvParams *conv_params, + TfLiteRegistration registration, int8_t *output_data) +{ + return InvokeConv(tensors, tensors_size, output_length, conv_params, + registration, output_data); +} + +TfLiteStatus ValidateConvGoldens(TfLiteTensor *tensors, int tensors_size, + const float *expected_output_data, + int output_length, + TfLiteConvParams *conv_params, + TfLiteRegistration registration, + float *output_data, float tolerance) +{ + return ValidateConvGoldens(tensors, tensors_size, expected_output_data, + output_length, conv_params, registration, + output_data, tolerance); +} + +TfLiteStatus ValidateConvGoldens(TfLiteTensor *tensors, int tensors_size, + const int8_t *expected_output_data, + int output_length, + TfLiteConvParams *conv_params, + TfLiteRegistration registration, + int8_t *output_data, float tolerance) +{ + return ValidateConvGoldens( + tensors, tensors_size, expected_output_data, output_length, conv_params, + registration, output_data, tolerance); +} + +TfLiteStatus TestConvFloat(int *input_dims_data, const float *input_data, + int *filter_dims_data, const float *filter_data, + int *bias_dims_data, const float *bias_data, + int *output_dims_data, + const float *expected_output_data, + TfLiteConvParams *conv_params, + TfLiteRegistration registration, + float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *filter_dims = IntArrayFromInts(filter_dims_data); + TfLiteIntArray *bias_dims = IntArrayFromInts(bias_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + constexpr int inputs_size = 3; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(filter_data, filter_dims), + CreateTensor(bias_data, bias_dims), + CreateTensor(output_data, output_dims), + }; + + return ValidateConvGoldens(tensors, tensors_size, expected_output_data, + output_dims_count, conv_params, registration, + output_data); +} + +template +TfLiteStatus TestConvQuantizedPerChannel( + int *input_dims_data, const float *input_data, T *input_quantized, + float input_scale, int input_zero_point, int *filter_dims_data, + const float *filter_data, int8_t *filter_data_quantized, + int *bias_dims_data, const float *bias_data, BiasT *bias_data_quantized, + float *bias_scales, int *bias_zero_points, int *output_dims_data, + const float *expected_output_data, T *expected_output_data_quantized, + float output_scale, int output_zero_point, TfLiteConvParams *conv_params, + TfLiteRegistration registration, T *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *filter_dims = IntArrayFromInts(filter_dims_data); + TfLiteIntArray *bias_dims = IntArrayFromInts(bias_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + int filter_zero_points[5]; + float filter_scales[5]; + TfLiteAffineQuantization filter_quant; + TfLiteAffineQuantization bias_quant; + TfLiteTensor input_tensor = CreateQuantizedTensor( + input_data, input_quantized, input_dims, input_scale, input_zero_point); + TfLiteTensor filter_tensor = CreateSymmetricPerChannelQuantizedTensor( + filter_data, filter_data_quantized, filter_dims, filter_scales, + filter_zero_points, &filter_quant, 0 /* quantized dimension */); + TfLiteTensor bias_tensor = CreatePerChannelQuantizedBiasTensor( + bias_data, bias_data_quantized, bias_dims, input_scale, &filter_scales[1], + bias_scales, bias_zero_points, &bias_quant, 0 /* quantized dimension */); + TfLiteTensor output_tensor = CreateQuantizedTensor( + output_data, output_dims, output_scale, output_zero_point); + + float input_scales[] = { 1, input_scale }; + int input_zero_points[] = { 1, input_zero_point }; + TfLiteAffineQuantization input_quant = { FloatArrayFromFloats(input_scales), + IntArrayFromInts(input_zero_points), + 0 }; + input_tensor.quantization = { kTfLiteAffineQuantization, &input_quant }; + + float output_scales[] = { 1, output_scale }; + int output_zero_points[] = { 1, output_zero_point }; + TfLiteAffineQuantization output_quant = { FloatArrayFromFloats(output_scales), + IntArrayFromInts(output_zero_points), + 0 }; + output_tensor.quantization = { kTfLiteAffineQuantization, &output_quant }; + + constexpr int inputs_size = 3; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + input_tensor, + filter_tensor, + bias_tensor, + output_tensor, + }; + + tflite::Quantize(expected_output_data, expected_output_data_quantized, + output_dims_count, output_scale, output_zero_point); + return ValidateConvGoldens( + tensors, tensors_size, expected_output_data_quantized, output_dims_count, + conv_params, registration, output_data, 1.0 /* tolerance */); +} + +TfLiteStatus TestConvQuantizedPerChannel( + int *input_dims_data, const float *input_data, int8_t *input_quantized, + float input_scale, int input_zero_point, int *filter_dims_data, + const float *filter_data, int8_t *filter_data_quantized, + int *bias_dims_data, const float *bias_data, int32_t *bias_data_quantized, + float *bias_scales, int *bias_zero_points, int *output_dims_data, + const float *expected_output_data, int8_t *expected_output_data_quantized, + float output_scale, int output_zero_point, TfLiteConvParams *conv_params, + TfLiteRegistration registration, int8_t *output_data) +{ + return TestConvQuantizedPerChannel( + input_dims_data, input_data, input_quantized, input_scale, + input_zero_point, filter_dims_data, filter_data, filter_data_quantized, + bias_dims_data, bias_data, bias_data_quantized, bias_scales, + bias_zero_points, output_dims_data, expected_output_data, + expected_output_data_quantized, output_scale, output_zero_point, + conv_params, registration, output_data); +} + +TfLiteStatus TestConvQuantizedPerChannel( + int *input_dims_data, const float *input_data, int16_t *input_quantized, + float input_scale, int input_zero_point, int *filter_dims_data, + const float *filter_data, int8_t *filter_data_quantized, + int *bias_dims_data, const float *bias_data, + std::int64_t *bias_data_quantized, float *bias_scales, + int *bias_zero_points, int *output_dims_data, + const float *expected_output_data, int16_t *expected_output_data_quantized, + float output_scale, int output_zero_point, TfLiteConvParams *conv_params, + TfLiteRegistration registration, int16_t *output_data) +{ + return TestConvQuantizedPerChannel( + input_dims_data, input_data, input_quantized, input_scale, + input_zero_point, filter_dims_data, filter_data, filter_data_quantized, + bias_dims_data, bias_data, bias_data_quantized, bias_scales, + bias_zero_points, output_dims_data, expected_output_data, + expected_output_data_quantized, output_scale, output_zero_point, + conv_params, registration, output_data); +} + +} // namespace testing +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/cumsum.cc b/components/tflite/tensorflow/lite/micro/kernels/cumsum.cc new file mode 100644 index 00000000..8113fe4a --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/cumsum.cc @@ -0,0 +1,178 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/cumsum.h" + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/types.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace { + +constexpr int kInputTensor = 0; +constexpr int kAxisTensor = 1; +constexpr int kOutputTensor = 0; + +constexpr int kCumSumIntegerShift = 20; + +// only used with INT8 tensors +struct OpData { + int32_t output_activation_min; + int32_t output_activation_max; + int32_t input_offset; + int32_t output_offset; + int32_t input_multiplier; + int32_t output_multiplier; + int input_shift; + int output_shift; + int left_shift; +}; + +TfLiteStatus CalculateOpData(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE_EQ(context, NumInputs(node), 2); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + + const TfLiteTensor *input = GetInput(context, node, kInputTensor); + const TfLiteTensor *axis = GetInput(context, node, kAxisTensor); + + TF_LITE_ENSURE(context, + input->type == kTfLiteFloat32 || input->type == kTfLiteInt8); + TF_LITE_ENSURE_EQ(context, axis->type, kTfLiteInt32); + + TF_LITE_ENSURE_EQ(context, NumElements(axis), 1); + + TF_LITE_ENSURE(context, NumDimensions(input) >= 1); + + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + + TF_LITE_ENSURE_EQ(context, input->type, output->type); + TF_LITE_ENSURE(context, HaveSameShapes(input, output)); + + if (output->type == kTfLiteInt8) { + node->user_data = + context->AllocatePersistentBuffer(context, sizeof(OpData)); + OpData *data = static_cast(node->user_data); + + // 8bit -> 8bit general quantized path, with general rescalings + data->input_offset = -input->params.zero_point; + data->output_offset = output->params.zero_point; + data->left_shift = kCumSumIntegerShift; + const double twice_max_input_scale = + 2 * static_cast(input->params.scale); + const double real_input_multiplier = + static_cast(input->params.scale) / twice_max_input_scale; + const double real_output_multiplier = + twice_max_input_scale / + ((1 << data->left_shift) * static_cast(output->params.scale)); + + QuantizeMultiplierSmallerThanOneExp( + real_input_multiplier, &data->input_multiplier, &data->input_shift); + + QuantizeMultiplierSmallerThanOneExp( + real_output_multiplier, &data->output_multiplier, &data->output_shift); + + TF_LITE_ENSURE_STATUS(CalculateActivationRangeQuantized( + context, kTfLiteActNone, output, &data->output_activation_min, + &data->output_activation_max)); + } + + return kTfLiteOk; +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + return CalculateOpData(context, node); +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + const TfLiteEvalTensor *axis_tensor = + tflite::micro::GetEvalInput(context, node, kAxisTensor); + + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + auto *cs_params = static_cast(node->builtin_data); + auto input_shape = tflite::micro::GetTensorShape(input); + + int32_t axis = *tflite::micro::GetTensorData(axis_tensor); + if (axis < 0) + axis += input_shape.DimensionsCount(); + + if (axis < 0 || axis >= input_shape.DimensionsCount()) { + TF_LITE_KERNEL_LOG(context, "CUMSUM Invalid axis: %d", axis); + return kTfLiteError; + } + + switch (input->type) { + case kTfLiteFloat32: { + reference_ops::CumSum(tflite::micro::GetTensorData(input), + input_shape, axis, cs_params->exclusive, + cs_params->reverse, + tflite::micro::GetTensorData(output)); + return kTfLiteOk; + } break; + + case kTfLiteInt8: { + auto *data = static_cast(node->user_data); + ArithmeticParams params; + params.left_shift = data->left_shift; + params.input1_offset = data->input_offset; + params.input1_multiplier = data->input_multiplier; + params.input1_shift = data->input_shift; + params.output_offset = data->output_offset; + params.output_multiplier = data->output_multiplier; + params.output_shift = data->output_shift; + SetActivationParams(data->output_activation_min, + data->output_activation_max, ¶ms); + reference_ops::CumSum(params, tflite::micro::GetTensorData(input), + input_shape, axis, cs_params->exclusive, + cs_params->reverse, + tflite::micro::GetTensorData(output)); + return kTfLiteOk; + } break; + + default: { + TF_LITE_KERNEL_LOG(context, + "CUMSUM only supports FLOAT32 and INT8, got %s.", + TfLiteTypeGetName(output->type)); + return kTfLiteError; + } + } + + return kTfLiteError; +} + +} // namespace + +TfLiteRegistration Register_CUMSUM() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/cumsum_test.cc b/components/tflite/tensorflow/lite/micro/kernels/cumsum_test.cc new file mode 100644 index 00000000..7c5da303 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/cumsum_test.cc @@ -0,0 +1,366 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +struct CumSumTestParams { + bool exclusive = false; + bool reverse = false; + int32_t axis = std::numeric_limits::max(); +}; + +void ExecuteCumSumTest(CumSumTestParams &test_params, TfLiteTensor *tensors, + int tensors_count) +{ + int kInputArrayData[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(kInputArrayData); + int kOutputArrayData[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(kOutputArrayData); + + TfLiteCumsumParams params; + params.exclusive = test_params.exclusive; + params.reverse = test_params.reverse; + + const TfLiteRegistration registration = tflite::Register_CUMSUM(); + micro::KernelRunner runner(registration, tensors, tensors_count, inputs_array, + outputs_array, static_cast(¶ms)); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); +} + +template +void TestCumSum(CumSumTestParams &test_params, int *input_dims_data, + const T *input_data, int *expected_dims, const T *expected_data, + T *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(expected_dims); + const int output_count = ElementCount(*output_dims); + + int axis_dims_data[] = { 1, 1 }; + TfLiteIntArray *axis_dims = IntArrayFromInts(axis_dims_data); + const int32_t axis_data[] = { test_params.axis }; + + TfLiteTensor tensors[] = { + CreateTensor(input_data, input_dims), + CreateTensor(axis_data, axis_dims), + CreateTensor(output_data, output_dims), + }; + constexpr int tensors_count = std::extent::value; + ExecuteCumSumTest(test_params, tensors, tensors_count); + + constexpr float kTolerance = 1e-5; + for (int i = 0; i < output_count; i++) { + TF_LITE_MICRO_EXPECT_NEAR(expected_data[i], output_data[i], kTolerance); + } +} + +// min/max are used to compute scale, zero-point, compare tolerance +template +struct TestQuantParams { + float data_min; // input and output data minimum value + float data_max; // input and output data maximum value + T input_data[kOutputSize]; // quantized input storage + T output_data[kOutputSize]; // quantized output storage +}; + +// for quantized int, the error shouldn't exceed step +template +float GetTolerance(float min, float max) +{ + float kQuantizedStep = + 2.0f * (max - min) / + (std::numeric_limits::max() - std::numeric_limits::min()); + return kQuantizedStep; +} + +template +void TestCumSumQuantized(CumSumTestParams &test_params, + TestQuantParams *params, + int *input_dims_data, const float *input_data, + int *expected_dims, const float *expected_data, + float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(expected_dims); + + int axis_dims_data[] = { 1, 1 }; + TfLiteIntArray *axis_dims = IntArrayFromInts(axis_dims_data); + const int32_t axis_data[] = { test_params.axis }; + + const float scale = ScaleFromMinMax(params->data_min, params->data_max); + const int zero_point = + ZeroPointFromMinMax(params->data_min, params->data_max); + + TfLiteTensor tensors[] = { + CreateQuantizedTensor(input_data, params->input_data, input_dims, scale, + zero_point), + CreateTensor(axis_data, axis_dims), + CreateQuantizedTensor(params->output_data, output_dims, scale, + zero_point), + }; + + constexpr int tensors_count = std::extent::value; + ExecuteCumSumTest(test_params, tensors, tensors_count); + + Dequantize(params->output_data, kOutputSize, scale, zero_point, output_data); + const float kTolerance = GetTolerance(params->data_min, params->data_max); + for (int i = 0; i < kOutputSize; i++) { + TF_LITE_MICRO_EXPECT_NEAR(expected_data[i], output_data[i], kTolerance); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(CumSumOpTestSimpleTest) +{ + int kDims[] = { 2, 2, 4 }; + constexpr float kInput[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + constexpr float kExpect[] = { 1, 3, 6, 10, 5, 11, 18, 26 }; + + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + tflite::testing::CumSumTestParams test_params; + test_params.axis = 1; + + tflite::testing::TestCumSum(test_params, kDims, kInput, kDims, kExpect, + output_data); +} + +TF_LITE_MICRO_TEST(CumSumOpTestSimpleAxis0Test) +{ + int kDims[] = { 2, 2, 4 }; + constexpr float kInput[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + constexpr float kExpect[] = { 1, 2, 3, 4, 6, 8, 10, 12 }; + + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + tflite::testing::CumSumTestParams test_params; + test_params.axis = 0; + + tflite::testing::TestCumSum(test_params, kDims, kInput, kDims, kExpect, + output_data); +} + +TF_LITE_MICRO_TEST(CumSumOpTestSimple1DTest) +{ + int kDims[] = { 1, 8 }; + constexpr float kInput[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + constexpr float kExpect[] = { 1, 3, 6, 10, 15, 21, 28, 36 }; + + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + tflite::testing::CumSumTestParams test_params; + test_params.axis = 0; + + tflite::testing::TestCumSum(test_params, kDims, kInput, kDims, kExpect, + output_data); +} + +TF_LITE_MICRO_TEST(CumSumOpTestSimpleReverseTest) +{ + int kDims[] = { 2, 2, 4 }; + constexpr float kInput[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + constexpr float kExpect[] = { 10, 9, 7, 4, 26, 21, 15, 8 }; + + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + tflite::testing::CumSumTestParams test_params; + test_params.axis = 1; + test_params.reverse = true; + + tflite::testing::TestCumSum(test_params, kDims, kInput, kDims, kExpect, + output_data); +} + +TF_LITE_MICRO_TEST(CumSumOpTestSimpleExclusiveTest) +{ + int kDims[] = { 2, 2, 4 }; + constexpr float kInput[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + constexpr float kExpect[] = { 0, 1, 3, 6, 0, 5, 11, 18 }; + + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + tflite::testing::CumSumTestParams test_params; + test_params.axis = 1; + test_params.exclusive = true; + + tflite::testing::TestCumSum(test_params, kDims, kInput, kDims, kExpect, + output_data); +} + +TF_LITE_MICRO_TEST(CumSumOpTestSimpleReverseExclusiveTest) +{ + int kDims[] = { 2, 2, 4 }; + constexpr float kInput[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + constexpr float kExpect[] = { 9, 7, 4, 0, 21, 15, 8, 0 }; + + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + tflite::testing::CumSumTestParams test_params; + test_params.axis = -1; + test_params.exclusive = true; + test_params.reverse = true; + + tflite::testing::TestCumSum(test_params, kDims, kInput, kDims, kExpect, + output_data); +} + +TF_LITE_MICRO_TEST(CumSumOpTestSimpleTestInt8) +{ + int kDims[] = { 2, 2, 4 }; + constexpr float kInput[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + constexpr float kExpect[] = { 1, 3, 6, 10, 5, 11, 18, 26 }; + + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + tflite::testing::CumSumTestParams test_params; + test_params.axis = 1; + + tflite::testing::TestQuantParams params = {}; + params.data_min = -26.0f; + params.data_max = 26.0f; + + tflite::testing::TestCumSumQuantized( + test_params, ¶ms, kDims, kInput, kDims, kExpect, output_data); +} + +TF_LITE_MICRO_TEST(CumSumOpTestSimpleAxis0TestInt8) +{ + int kDims[] = { 2, 2, 4 }; + constexpr float kInput[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + constexpr float kExpect[] = { 1, 2, 3, 4, 6, 8, 10, 12 }; + + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + tflite::testing::CumSumTestParams test_params; + test_params.axis = 0; + + tflite::testing::TestQuantParams params = {}; + params.data_min = -12.0f; + params.data_max = 12.0f; + + tflite::testing::TestCumSumQuantized( + test_params, ¶ms, kDims, kInput, kDims, kExpect, output_data); +} + +TF_LITE_MICRO_TEST(CumSumOpTestSimple1DTestInt8) +{ + int kDims[] = { 1, 8 }; + constexpr float kInput[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + constexpr float kExpect[] = { 1, 3, 6, 10, 15, 21, 28, 36 }; + + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + tflite::testing::CumSumTestParams test_params; + test_params.axis = 0; + + tflite::testing::TestQuantParams params = {}; + params.data_min = -36.0f; + params.data_max = 36.0f; + + tflite::testing::TestCumSumQuantized( + test_params, ¶ms, kDims, kInput, kDims, kExpect, output_data); +} + +TF_LITE_MICRO_TEST(CumSumOpTestSimpleReverseTestInt8) +{ + int kDims[] = { 2, 2, 4 }; + constexpr float kInput[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + constexpr float kExpect[] = { 10, 9, 7, 4, 26, 21, 15, 8 }; + + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + tflite::testing::CumSumTestParams test_params; + test_params.axis = 1; + test_params.reverse = true; + + tflite::testing::TestQuantParams params = {}; + params.data_min = -26.0f; + params.data_max = 26.0f; + + tflite::testing::TestCumSumQuantized( + test_params, ¶ms, kDims, kInput, kDims, kExpect, output_data); +} + +TF_LITE_MICRO_TEST(CumSumOpTestSimpleExclusiveTestInt8) +{ + int kDims[] = { 2, 2, 4 }; + constexpr float kInput[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + constexpr float kExpect[] = { 0, 1, 3, 6, 0, 5, 11, 18 }; + + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + tflite::testing::CumSumTestParams test_params; + test_params.axis = 1; + test_params.exclusive = true; + + tflite::testing::TestQuantParams params = {}; + params.data_min = -18.0f; + params.data_max = 18.0f; + + tflite::testing::TestCumSumQuantized( + test_params, ¶ms, kDims, kInput, kDims, kExpect, output_data); +} + +TF_LITE_MICRO_TEST(CumSumOpTestSimpleReverseExclusiveTestInt8) +{ + int kDims[] = { 2, 2, 4 }; + constexpr float kInput[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + constexpr float kExpect[] = { 9, 7, 4, 0, 21, 15, 8, 0 }; + + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + tflite::testing::CumSumTestParams test_params; + test_params.axis = -1; + test_params.exclusive = true; + test_params.reverse = true; + + tflite::testing::TestQuantParams params = {}; + params.data_min = -21.0f; + params.data_max = 21.0f; + + tflite::testing::TestCumSumQuantized( + test_params, ¶ms, kDims, kInput, kDims, kExpect, output_data); +} +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/depth_to_space.cc b/components/tflite/tensorflow/lite/micro/kernels/depth_to_space.cc new file mode 100644 index 00000000..c2c98284 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/depth_to_space.cc @@ -0,0 +1,147 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/kernels/internal/reference/depth_to_space.h" + +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/types.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace { + +constexpr int kInputTensor = 0; +constexpr int kOutputTensor = 0; + +// input/output tensor shape rank associations +constexpr int kBatchRank = 0; +constexpr int kHeightRank = 1; +constexpr int kWidthRank = 2; +constexpr int kDepthRank = 3; + +TfLiteStatus CalculateOpData(TfLiteContext *context, TfLiteNode *node) +{ + auto *params = + reinterpret_cast(node->builtin_data); + + TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + + const TfLiteTensor *input; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, kInputTensor, &input)); + TfLiteTensor *output; + TF_LITE_ENSURE_OK(context, + GetOutputSafe(context, node, kOutputTensor, &output)); + + TF_LITE_ENSURE_EQ(context, NumDimensions(input), 4); + + auto data_type = output->type; + TF_LITE_ENSURE(context, + data_type == kTfLiteFloat32 || data_type == kTfLiteInt8); + TF_LITE_ENSURE_TYPES_EQ(context, input->type, output->type); + + const int block_size = params->block_size; + TF_LITE_ENSURE(context, block_size > 0); + const int input_height = input->dims->data[kHeightRank]; + const int input_width = input->dims->data[kWidthRank]; + const int input_channels = input->dims->data[kDepthRank]; + int output_height = input_height * block_size; + int output_width = input_width * block_size; + int output_channels = input_channels / block_size / block_size; + + TF_LITE_ENSURE_EQ(context, input_height, output_height / block_size); + TF_LITE_ENSURE_EQ(context, input_width, output_width / block_size); + TF_LITE_ENSURE_EQ(context, input_channels, + output_channels * block_size * block_size); + + // We must update the output tensor dimensions. + // The dims storage is expected to be the same area in memory + // for both TfLiteTensor and TfLiteEvalTensor. This is important + // because TfLiteTensor in the MicroInterpreter is a temporary + // allocation. For the KernelRunner interpreter, TfLiteEvalTensor + // is a temporary allocation. We must therefore relocate the dims + // from the FlatBuffer to the persistant storage arena. + TfLiteEvalTensor *output_eval = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + TF_LITE_ENSURE_OK(context, tflite::micro::CreateWritableTensorDimsWithCopy( + context, output, output_eval)); + output->dims->data[kBatchRank] = input->dims->data[kBatchRank]; + output->dims->data[kHeightRank] = output_height; + output->dims->data[kWidthRank] = output_width; + output->dims->data[kDepthRank] = output_channels; + + return kTfLiteOk; +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + return CalculateOpData(context, node); +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + auto *params = + reinterpret_cast(node->builtin_data); + + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + tflite::DepthToSpaceParams op_params; + op_params.block_size = static_cast(params->block_size); + + switch (input->type) { // Already know in/out types are same. + case kTfLiteFloat32: + reference_ops::DepthToSpace(op_params, + tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + break; + case kTfLiteInt8: + reference_ops::DepthToSpace(op_params, + tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + break; + default: + TF_LITE_KERNEL_LOG( + context, "DEPTH_TO_SPACE only supports FLOAT32 and INT8, got %s.", + TfLiteTypeGetName(output->type)); + return kTfLiteError; + } + + return kTfLiteOk; +} + +} // namespace + +TfLiteRegistration Register_DEPTH_TO_SPACE() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/depth_to_space_test.cc b/components/tflite/tensorflow/lite/micro/kernels/depth_to_space_test.cc new file mode 100644 index 00000000..d35cca3b --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/depth_to_space_test.cc @@ -0,0 +1,321 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +constexpr int kOutputDimsCount = 4; + +struct DepthToSpaceTestParams { + int block_size; + // output_dims_data is a TfLiteIntArray + int output_dims_data[kOutputDimsCount + 1] = { kOutputDimsCount, 0, 0, 0, 0 }; +}; + +void ExecuteDepthToSpaceTest(const DepthToSpaceTestParams ¶ms, + TfLiteTensor *tensors, int tensors_count) +{ + int kInputArrayData[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(kInputArrayData); + int kOutputArrayData[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(kOutputArrayData); + + TfLiteDepthToSpaceParams op_params = {}; + op_params.block_size = params.block_size; + + const TfLiteRegistration registration = tflite::Register_DEPTH_TO_SPACE(); + micro::KernelRunner runner(registration, tensors, tensors_count, inputs_array, + outputs_array, static_cast(&op_params)); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); +} + +template +void TestDepthToSpace(DepthToSpaceTestParams ¶ms, int *input_dims_data, + const T *input_data, int *expected_dims_data, + const T *expected_data, T *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *expected_dims = IntArrayFromInts(expected_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(params.output_dims_data); + const int expected_count = ElementCount(*expected_dims); + + TfLiteTensor tensors[] = { + CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims), + }; + constexpr int tensors_count = std::extent::value; + ExecuteDepthToSpaceTest(params, tensors, tensors_count); + + constexpr float kTolerance = 1e-5; + for (int i = 0; i < expected_count; i++) { + TF_LITE_MICRO_EXPECT_NEAR(expected_data[i], output_data[i], kTolerance); + } + for (int i = 0; i < expected_dims->size; i++) { + // output dims will have been relocated during prepare phase, + // so use the tensor dims pointer. + TF_LITE_MICRO_EXPECT_EQ(expected_dims->data[i], tensors[1].dims->data[i]); + } +} + +// min/max are used to compute scale, zero-point, compare tolerance +template +struct TestQuantParams { + float data_min; // input and output data minimum value + float data_max; // input and output data maximum value + T input_data[kOutputSize]; // quantized input storage + T output_data[kOutputSize]; // quantized output storage +}; + +// for quantized, the error shouldn't exceed step +template +float GetTolerance(float min, float max) +{ + float kQuantizedStep = + 2.0f * (max - min) / + (std::numeric_limits::max() - std::numeric_limits::min()); + return kQuantizedStep; +} + +template +void TestDepthToSpaceQuantized(DepthToSpaceTestParams ¶ms, + TestQuantParams *quant_params, + int *input_dims_data, const float *input_data, + int *expected_dims_data, + const float *expected_data, float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *expected_dims = IntArrayFromInts(expected_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(params.output_dims_data); + + const float scale = + ScaleFromMinMax(quant_params->data_min, quant_params->data_max); + const int zero_point = + ZeroPointFromMinMax(quant_params->data_min, quant_params->data_max); + + TfLiteTensor tensors[] = { + CreateQuantizedTensor(input_data, quant_params->input_data, input_dims, + scale, zero_point), + CreateQuantizedTensor(quant_params->output_data, output_dims, scale, + zero_point), + }; + constexpr int kTensorsCount = std::extent::value; + + ExecuteDepthToSpaceTest(params, tensors, kTensorsCount); + + Dequantize(quant_params->output_data, kOutputSize, scale, zero_point, + output_data); + const float kTolerance = + GetTolerance(quant_params->data_min, quant_params->data_max); + for (int i = 0; i < kOutputSize; i++) { + TF_LITE_MICRO_EXPECT_NEAR(expected_data[i], output_data[i], kTolerance); + } + for (int i = 0; i < expected_dims->size; i++) { + // output dims will have been relocated during prepare phase, + // so use the tensor dims pointer. + TF_LITE_MICRO_EXPECT_EQ(expected_dims->data[i], tensors[1].dims->data[i]); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(DepthToSpaceOpModelFloat32_1114_2) +{ + int kInputDims[] = { 4, 1, 1, 1, 4 }; + constexpr float kInput[] = { 1.4, 2.3, 3.2, 4.1 }; + int kExpectDims[] = { 4, 1, 2, 2, 1 }; + constexpr float kExpect[] = { 1.4, 2.3, 3.2, 4.1 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + tflite::testing::DepthToSpaceTestParams params; + params.block_size = 2; + + tflite::testing::TestDepthToSpace(params, kInputDims, kInput, kExpectDims, + kExpect, output_data); +} + +TF_LITE_MICRO_TEST(DepthToSpaceOpModelFloat32_1124_2) +{ + int kInputDims[] = { 4, 1, 1, 2, 4 }; + constexpr float kInput[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + int kExpectDims[] = { 4, 1, 2, 4, 1 }; + constexpr float kExpect[] = { 1, 2, 5, 6, 3, 4, 7, 8 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + tflite::testing::DepthToSpaceTestParams params; + params.block_size = 2; + + tflite::testing::TestDepthToSpace(params, kInputDims, kInput, kExpectDims, + kExpect, output_data); +} + +TF_LITE_MICRO_TEST(DepthToSpaceOpModelFloat32_1214_2) +{ + int kInputDims[] = { 4, 1, 2, 1, 4 }; + constexpr float kInput[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + int kExpectDims[] = { 4, 1, 4, 2, 1 }; + constexpr float kExpect[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + tflite::testing::DepthToSpaceTestParams params; + params.block_size = 2; + + tflite::testing::TestDepthToSpace(params, kInputDims, kInput, kExpectDims, + kExpect, output_data); +} + +TF_LITE_MICRO_TEST(DepthToSpaceOpModelFloat32_1224_2) +{ + int kInputDims[] = { 4, 1, 2, 2, 4 }; + constexpr float kInput[] = { 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16 }; + int kExpectDims[] = { 4, 1, 4, 4, 1 }; + constexpr float kExpect[] = { 1, 2, 5, 6, 3, 4, 7, 8, + 9, 10, 13, 14, 11, 12, 15, 16 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + tflite::testing::DepthToSpaceTestParams params; + params.block_size = 2; + + tflite::testing::TestDepthToSpace(params, kInputDims, kInput, kExpectDims, + kExpect, output_data); +} + +TF_LITE_MICRO_TEST(DepthToSpaceOpModelFloat32_1111_1) +{ + int kInputDims[] = { 4, 1, 1, 1, 1 }; + constexpr float kInput[] = { 4 }; + int kExpectDims[] = { 4, 1, 1, 1, 1 }; + constexpr float kExpect[] = { 4 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + tflite::testing::DepthToSpaceTestParams params; + params.block_size = 1; + + tflite::testing::TestDepthToSpace(params, kInputDims, kInput, kExpectDims, + kExpect, output_data); +} + +TF_LITE_MICRO_TEST(DepthToSpaceOpModelInt8_1114_2) +{ + int kInputDims[] = { 4, 1, 1, 1, 4 }; + constexpr float kInput[] = { 1.4, 2.3, 3.2, 4.1 }; + int kExpectDims[] = { 4, 1, 2, 2, 1 }; + constexpr float kExpect[] = { 1.4, 2.3, 3.2, 4.1 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + tflite::testing::DepthToSpaceTestParams params; + params.block_size = 2; + tflite::testing::TestQuantParams quant_params = {}; + quant_params.data_min = 0.0; + quant_params.data_max = 5.0; + + tflite::testing::TestDepthToSpaceQuantized( + params, &quant_params, kInputDims, kInput, kExpectDims, kExpect, + output_data); +} + +TF_LITE_MICRO_TEST(DepthToSpaceOpModelInt8_1124_2) +{ + int kInputDims[] = { 4, 1, 1, 2, 4 }; + constexpr float kInput[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + int kExpectDims[] = { 4, 1, 2, 4, 1 }; + constexpr float kExpect[] = { 1, 2, 5, 6, 3, 4, 7, 8 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + tflite::testing::DepthToSpaceTestParams params; + params.block_size = 2; + tflite::testing::TestQuantParams quant_params = {}; + quant_params.data_min = 0.0; + quant_params.data_max = 9.0; + + tflite::testing::TestDepthToSpaceQuantized( + params, &quant_params, kInputDims, kInput, kExpectDims, kExpect, + output_data); +} + +TF_LITE_MICRO_TEST(DepthToSpaceOpModelInt8_1214_2) +{ + int kInputDims[] = { 4, 1, 2, 1, 4 }; + constexpr float kInput[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + int kExpectDims[] = { 4, 1, 4, 2, 1 }; + constexpr float kExpect[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + tflite::testing::DepthToSpaceTestParams params; + params.block_size = 2; + tflite::testing::TestQuantParams quant_params = {}; + quant_params.data_min = 0.0; + quant_params.data_max = 9.0; + + tflite::testing::TestDepthToSpaceQuantized( + params, &quant_params, kInputDims, kInput, kExpectDims, kExpect, + output_data); +} + +TF_LITE_MICRO_TEST(DepthToSpaceOpModelInt8_1224_2) +{ + int kInputDims[] = { 4, 1, 2, 2, 4 }; + constexpr float kInput[] = { 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16 }; + int kExpectDims[] = { 4, 1, 4, 4, 1 }; + constexpr float kExpect[] = { 1, 2, 5, 6, 3, 4, 7, 8, + 9, 10, 13, 14, 11, 12, 15, 16 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + tflite::testing::DepthToSpaceTestParams params; + params.block_size = 2; + tflite::testing::TestQuantParams quant_params = {}; + quant_params.data_min = 0.0; + quant_params.data_max = 17.0; + + tflite::testing::TestDepthToSpaceQuantized( + params, &quant_params, kInputDims, kInput, kExpectDims, kExpect, + output_data); +} + +TF_LITE_MICRO_TEST(DepthToSpaceOpModelInt8_1111_1) +{ + int kInputDims[] = { 4, 1, 1, 1, 1 }; + constexpr float kInput[] = { 4 }; + int kExpectDims[] = { 4, 1, 1, 1, 1 }; + constexpr float kExpect[] = { 4 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + tflite::testing::DepthToSpaceTestParams params; + params.block_size = 1; + tflite::testing::TestQuantParams quant_params = {}; + quant_params.data_min = 3.0; + quant_params.data_max = 5.0; + + tflite::testing::TestDepthToSpaceQuantized( + params, &quant_params, kInputDims, kInput, kExpectDims, kExpect, + output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/depthwise_conv.cc b/components/tflite/tensorflow/lite/micro/kernels/depthwise_conv.cc new file mode 100644 index 00000000..84079027 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/depthwise_conv.cc @@ -0,0 +1,106 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/kernels/depthwise_conv.h" + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/depthwiseconv_float.h" +#include "tensorflow/lite/kernels/internal/reference/integer_ops/depthwise_conv.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/padding.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace { + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(OpDataConv)); +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + TFLITE_DCHECK(node->builtin_data != nullptr); + + auto ¶ms = + *(reinterpret_cast(node->builtin_data)); + const OpDataConv &data = *(static_cast(node->user_data)); + + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kDepthwiseConvOutputTensor); + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kDepthwiseConvInputTensor); + const TfLiteEvalTensor *filter = + tflite::micro::GetEvalInput(context, node, kDepthwiseConvWeightsTensor); + const TfLiteEvalTensor *bias = + (NumInputs(node) == 3) ? tflite::micro::GetEvalInput(context, node, kDepthwiseConvBiasTensor) : nullptr; + + switch (input->type) { // Already know in/out types are same. + case kTfLiteFloat32: { + tflite::reference_ops::DepthwiseConv( + DepthwiseConvParamsFloat(params, data), + tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(filter), + tflite::micro::GetTensorData(filter), + tflite::micro::GetTensorShape(bias), + tflite::micro::GetTensorData(bias), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + break; + } + case kTfLiteInt8: { + reference_integer_ops::DepthwiseConvPerChannel( + DepthwiseConvParamsQuantized(params, data), + data.per_channel_output_multiplier, data.per_channel_output_shift, + tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(filter), + tflite::micro::GetTensorData(filter), + tflite::micro::GetTensorShape(bias), + tflite::micro::GetTensorData(bias), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + break; + } + default: + TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.", + TfLiteTypeGetName(input->type), input->type); + return kTfLiteError; + } + return kTfLiteOk; +} + +} // namespace + +TfLiteRegistration Register_DEPTHWISE_CONV_2D() +{ + return { /*init=*/Init, + /*free=*/nullptr, + /*prepare=*/DepthwiseConvPrepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/depthwise_conv.h b/components/tflite/tensorflow/lite/micro/kernels/depthwise_conv.h new file mode 100644 index 00000000..01c43d35 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/depthwise_conv.h @@ -0,0 +1,53 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_KERNELS_DEPTHWISE_CONV_H_ +#define TENSORFLOW_LITE_MICRO_KERNELS_DEPTHWISE_CONV_H_ + +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/types.h" +#include "tensorflow/lite/micro/kernels/conv.h" + +namespace tflite { +extern const int kDepthwiseConvInputTensor; +extern const int kDepthwiseConvWeightsTensor; +extern const int kDepthwiseConvBiasTensor; +extern const int kDepthwiseConvOutputTensor; +extern const int kDepthwiseConvQuantizedDimension; + +// Returns a DepthwiseParams struct with all the parameters needed for a +// float computation. +DepthwiseParams DepthwiseConvParamsFloat( + const TfLiteDepthwiseConvParams ¶ms, const OpDataConv &data); + +// Returns a DepthwiseParams struct with all the parameters needed for a +// quantized computation. +DepthwiseParams DepthwiseConvParamsQuantized( + const TfLiteDepthwiseConvParams ¶ms, const OpDataConv &data); + +TfLiteStatus CalculateOpDataDepthwiseConv( + TfLiteContext *context, TfLiteNode *node, + const TfLiteDepthwiseConvParams ¶ms, int width, int height, + int filter_width, int filter_height, int out_width, int out_height, + const TfLiteType data_type, OpDataConv *data); + +TfLiteStatus DepthwiseConvPrepare(TfLiteContext *context, TfLiteNode *node); + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_KERNELS_DEPTHWISE_CONV_H_ diff --git a/components/tflite/tensorflow/lite/micro/kernels/depthwise_conv_common.cc b/components/tflite/tensorflow/lite/micro/kernels/depthwise_conv_common.cc new file mode 100644 index 00000000..3901939d --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/depthwise_conv_common.cc @@ -0,0 +1,190 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/depthwiseconv_float.h" +#include "tensorflow/lite/kernels/internal/reference/integer_ops/depthwise_conv.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/padding.h" +#include "tensorflow/lite/micro/kernels/depthwise_conv.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { + +const int kDepthwiseConvInputTensor = 0; +const int kDepthwiseConvWeightsTensor = 1; +const int kDepthwiseConvBiasTensor = 2; +const int kDepthwiseConvOutputTensor = 0; + +// DepthwiseConv is quantized along dimension 3: +// https://www.tensorflow.org/lite/performance/quantization_spec +const int kDepthwiseConvQuantizedDimension = 3; + +// Returns a DepthwiseParams struct with all the parameters needed for a +// float computation. +DepthwiseParams DepthwiseConvParamsFloat( + const TfLiteDepthwiseConvParams ¶ms, const OpDataConv &data) +{ + DepthwiseParams op_params; + CalculateActivationRange(params.activation, &op_params.float_activation_min, + &op_params.float_activation_max); + op_params.padding_type = tflite::micro::RuntimePaddingType(params.padding); + op_params.padding_values.width = data.padding.width; + op_params.padding_values.height = data.padding.height; + op_params.stride_width = params.stride_width; + op_params.stride_height = params.stride_height; + op_params.dilation_width_factor = params.dilation_width_factor; + op_params.dilation_height_factor = params.dilation_height_factor; + op_params.depth_multiplier = params.depth_multiplier; + return op_params; +} + +// Returns a DepthwiseParams struct with all the parameters needed for a +// quantized computation. +DepthwiseParams DepthwiseConvParamsQuantized( + const TfLiteDepthwiseConvParams ¶ms, const OpDataConv &data) +{ + DepthwiseParams op_params; + op_params.input_offset = -data.input_zero_point; + op_params.weights_offset = -data.filter_zero_point; + op_params.output_offset = data.output_zero_point; + op_params.output_multiplier = data.output_multiplier; + op_params.output_shift = -data.output_shift; + op_params.padding_type = tflite::micro::RuntimePaddingType(params.padding); + op_params.padding_values.height = data.padding.height; + op_params.padding_values.width = data.padding.width; + op_params.stride_height = params.stride_height; + op_params.stride_width = params.stride_width; + op_params.dilation_height_factor = params.dilation_height_factor; + op_params.dilation_width_factor = params.dilation_width_factor; + op_params.depth_multiplier = params.depth_multiplier; + op_params.quantized_activation_min = data.output_activation_min; + op_params.quantized_activation_max = data.output_activation_max; + return op_params; +} + +TfLiteStatus CalculateOpDataDepthwiseConv( + TfLiteContext *context, TfLiteNode *node, + const TfLiteDepthwiseConvParams ¶ms, int width, int height, + int filter_width, int filter_height, int out_width, int out_height, + const TfLiteType data_type, OpDataConv *data) +{ + bool has_bias = node->inputs->size == 3; + // Check number of inputs/outputs + TF_LITE_ENSURE(context, has_bias || node->inputs->size == 2); + TF_LITE_ENSURE_EQ(context, node->outputs->size, 1); + + // Matching GetWindowedOutputSize in TensorFlow. + auto padding = params.padding; + data->padding = ComputePaddingHeightWidth( + params.stride_height, params.stride_width, params.dilation_height_factor, + params.dilation_width_factor, height, width, filter_height, filter_width, + padding, &out_height, &out_width); + + const TfLiteTensor *input = GetInput(context, node, kConvInputTensor); + TF_LITE_ENSURE(context, input != nullptr); + const TfLiteTensor *filter = GetInput(context, node, kConvWeightsTensor); + TF_LITE_ENSURE(context, filter != nullptr); + const TfLiteTensor *bias = + GetOptionalInputTensor(context, node, kConvBiasTensor); + TfLiteTensor *output = GetOutput(context, node, kConvOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + + // Note that quantized inference requires that all tensors have their + // parameters set. This is usually done during quantized training. + if (data_type != kTfLiteFloat32) { + int output_channels = filter->dims->data[kDepthwiseConvQuantizedDimension]; + + TF_LITE_ENSURE_STATUS(tflite::PopulateConvolutionQuantizationParams( + context, input, filter, bias, output, params.activation, + &data->output_multiplier, &data->output_shift, + &data->output_activation_min, &data->output_activation_max, + data->per_channel_output_multiplier, data->per_channel_output_shift, + output_channels)); + } + + data->input_zero_point = input->params.zero_point; + data->filter_zero_point = filter->params.zero_point; + data->output_zero_point = output->params.zero_point; + + return kTfLiteOk; +} + +TfLiteStatus DepthwiseConvPrepare(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + TFLITE_DCHECK(node->builtin_data != nullptr); + + OpDataConv *data = static_cast(node->user_data); + const auto ¶ms = + *(static_cast(node->builtin_data)); + + TfLiteTensor *output = GetOutput(context, node, kDepthwiseConvOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + const TfLiteTensor *input = + GetInput(context, node, kDepthwiseConvInputTensor); + TF_LITE_ENSURE(context, input != nullptr); + const TfLiteTensor *filter = + GetInput(context, node, kDepthwiseConvWeightsTensor); + TF_LITE_ENSURE(context, filter != nullptr); + + const int input_width = input->dims->data[2]; + const int input_height = input->dims->data[1]; + const int filter_width = filter->dims->data[2]; + const int filter_height = filter->dims->data[1]; + const int output_width = output->dims->data[2]; + const int output_height = output->dims->data[1]; + + // Dynamically allocate per-channel quantization parameters. + const int num_channels = filter->dims->data[kDepthwiseConvQuantizedDimension]; + data->per_channel_output_multiplier = + static_cast(context->AllocatePersistentBuffer( + context, num_channels * sizeof(int32_t))); + data->per_channel_output_shift = + static_cast(context->AllocatePersistentBuffer( + context, num_channels * sizeof(int32_t))); + + // All per-channel quantized tensors need valid zero point and scale arrays. + if (input->type == kTfLiteInt8) { + TF_LITE_ENSURE_EQ(context, filter->quantization.type, + kTfLiteAffineQuantization); + + const auto *affine_quantization = + static_cast(filter->quantization.params); + TFLITE_DCHECK(affine_quantization != nullptr); + TFLITE_DCHECK(affine_quantization->scale != nullptr); + TFLITE_DCHECK(affine_quantization->zero_point != nullptr); + + TF_LITE_ENSURE( + context, affine_quantization->scale->size == 1 || + affine_quantization->scale->size == + filter->dims->data[kDepthwiseConvQuantizedDimension]); + + TF_LITE_ENSURE_EQ(context, affine_quantization->scale->size, + affine_quantization->zero_point->size); + } + + TF_LITE_ENSURE_STATUS(CalculateOpDataDepthwiseConv( + context, node, params, input_width, input_height, filter_width, + filter_height, output_width, output_height, input->type, data)); + + return kTfLiteOk; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/depthwise_conv_test.cc b/components/tflite/tensorflow/lite/micro/kernels/depthwise_conv_test.cc new file mode 100644 index 00000000..ff7eb2de --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/depthwise_conv_test.cc @@ -0,0 +1,1004 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +#if !defined(XTENSA) // Needed to avoid build errors from unused variables. +constexpr int kMaxFilterChannels = 64; +constexpr int kMaxBiasChannels = 64; +#endif // !defined(XTENSA) + +// Index of the output tensor in context->tensors, specific to +// DepthwiseConv. +constexpr int kOutputTensorIndex = 3; + +// Creates a DepthwiseConv opeerator, calls it with the provided input tensors +// and some defaults parameters, and compares the output with +// expected_output_data. +// +// The tensors parameter contains both the input tensors as well as a +// preallocated output tensor into which the output is stored. +template +TfLiteStatus ValidateDepthwiseConvGoldens( + const T *expected_output_data, int output_length, + TfLiteDepthwiseConvParams *conv_params, float tolerance, int tensors_size, + TfLiteTensor *tensors) +{ + int inputs_array_data[] = { 3, 0, 1, 2 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 3 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = Register_DEPTHWISE_CONV_2D(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + reinterpret_cast(conv_params)); + + int input_depth = tensors[0].dims->data[3]; + int output_depth = tensors[1].dims->data[3]; + int depth_mul = output_depth / input_depth; + + conv_params->padding = kTfLitePaddingValid; + conv_params->depth_multiplier = depth_mul; + + const char *init_data = reinterpret_cast(conv_params); + + // TODO(b/154240825): Use a test macro here which fails and returns. + TfLiteStatus status = runner.InitAndPrepare(init_data); + if (status != kTfLiteOk) { + return status; + } + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + const T *output_data = tflite::GetTensorData(&tensors[kOutputTensorIndex]); + + for (int i = 0; i < output_length; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output_data[i], output_data[i], + tolerance); + } + return kTfLiteOk; +} + +#if !defined(XTENSA) // Needed to avoid build errors from unsused functions. +void TestDepthwiseConvFloat(int *input_dims_data, const float *input_data, + int *filter_dims_data, const float *filter_data, + int *bias_dims_data, const float *bias_data, + const float *expected_output_data, + int *output_dims_data, + TfLiteDepthwiseConvParams *conv_params, + float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *filter_dims = IntArrayFromInts(filter_dims_data); + TfLiteIntArray *bias_dims = IntArrayFromInts(bias_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int inputs_size = 3; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(filter_data, filter_dims), + CreateTensor(bias_data, bias_dims), + CreateTensor(output_data, output_dims), + }; + + ValidateDepthwiseConvGoldens(expected_output_data, output_dims_count, + conv_params, 1e-5, tensors_size, tensors); +} + +void TestDepthwiseConvQuantizedPerChannel( + int *input_dims_data, const float *input_data, int8_t *input_quantized, + float input_scale, int input_zero_point, int *filter_dims_data, + const float *filter_data, int8_t *filter_data_quantized, + int *bias_dims_data, const float *bias_data, int32_t *bias_data_quantized, + int *output_dims_data, const float *expected_output_data, + int8_t *expected_output_data_quantized, int8_t *output_data, + float output_scale, int output_zero_point, + TfLiteDepthwiseConvParams *conv_params) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *filter_dims = IntArrayFromInts(filter_dims_data); + TfLiteIntArray *bias_dims = IntArrayFromInts(bias_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + int filter_zero_points[kMaxFilterChannels]; + float filter_scales[kMaxFilterChannels]; + int bias_zero_points[kMaxBiasChannels]; + float bias_scales[kMaxBiasChannels]; + TfLiteAffineQuantization filter_quant; + TfLiteAffineQuantization bias_quant; + TfLiteTensor input_tensor = CreateQuantizedTensor( + input_data, input_quantized, input_dims, input_scale, input_zero_point); + TfLiteTensor filter_tensor = CreateSymmetricPerChannelQuantizedTensor( + filter_data, filter_data_quantized, filter_dims, filter_scales, + filter_zero_points, &filter_quant, 3 /* quantized dimension */ + ); + TfLiteTensor bias_tensor = CreatePerChannelQuantizedBiasTensor( + bias_data, bias_data_quantized, bias_dims, input_scale, &filter_scales[1], + bias_scales, bias_zero_points, &bias_quant, 3 /* quantized dimension */ + ); + TfLiteTensor output_tensor = CreateQuantizedTensor( + output_data, output_dims, output_scale, input_zero_point); + + // TODO(njeff): Affine Quantization Params should be set on tensor creation. + float input_scales[] = { 1, input_scale }; + int input_zero_points[] = { 1, input_zero_point }; + TfLiteAffineQuantization input_quant = { FloatArrayFromFloats(input_scales), + IntArrayFromInts(input_zero_points), + 0 }; + input_tensor.quantization = { kTfLiteAffineQuantization, &input_quant }; + + float output_scales[] = { 1, output_scale }; + int output_zero_points[] = { 1, output_zero_point }; + TfLiteAffineQuantization output_quant = { FloatArrayFromFloats(output_scales), + IntArrayFromInts(output_zero_points), + 0 }; + output_tensor.quantization = { kTfLiteAffineQuantization, &output_quant }; + + constexpr int inputs_size = 3; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + input_tensor, + filter_tensor, + bias_tensor, + output_tensor, + }; + + Quantize(expected_output_data, expected_output_data_quantized, + output_dims_count, output_scale, output_zero_point); + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, ValidateDepthwiseConvGoldens(expected_output_data_quantized, + output_dims_count, conv_params, + 1.0, tensors_size, tensors)); +} + +#endif // !defined(XTENSA) + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +#if !defined(XTENSA) // TODO(b/170322965): xtensa kernels are less general than \ + // reference kernels and we ifdef out test cases that are \ + // currently known to fail. +TF_LITE_MICRO_TEST(SimpleTest) +{ + int input_shape[] = { 4, 1, 3, 2, 2 }; + const float input_values[] = { 1, 2, 7, 8, 3, 4, 9, 10, 5, 6, 11, 12 }; + int filter_shape[] = { 4, 1, 2, 2, 4 }; + const float filter_values[] = { 1, 2, 3, 4, -9, 10, -11, 12, + 5, 6, 7, 8, 13, -14, 15, -16 }; + int bias_shape[] = { 4, 1, 1, 1, 4 }; + const float bias_values[] = { 1, 2, 3, 4 }; + const float golden[] = { + 71, + -34, + 99, + -20, + 91, + -26, + 127, + -4, + }; + int output_shape[] = { 4, 1, 2, 1, 4 }; + const int output_dims_count = 8; + float output_data[output_dims_count]; + + TfLiteDepthwiseConvParams conv_params; + conv_params.activation = kTfLiteActNone; + conv_params.dilation_width_factor = 1; + conv_params.dilation_height_factor = 1; + conv_params.stride_height = 1; + conv_params.stride_width = 1; + + tflite::testing::TestDepthwiseConvFloat( + input_shape, input_values, filter_shape, filter_values, bias_shape, + bias_values, golden, output_shape, &conv_params, output_data); +} + +TF_LITE_MICRO_TEST(SimpleTestRelu) +{ + int input_shape[] = { 4, 1, 3, 2, 2 }; + const float input_values[] = { 1, 2, 7, 8, 3, 4, 9, 10, 5, 6, 11, 12 }; + int filter_shape[] = { 4, 1, 2, 2, 4 }; + const float filter_values[] = { 1, 2, 3, 4, -9, 10, -11, 12, + 5, 6, 7, 8, 13, -14, 15, -16 }; + int bias_shape[] = { 4, 1, 1, 1, 4 }; + const float bias_values[] = { 1, 2, 3, 4 }; + int output_shape[] = { 4, 1, 2, 1, 4 }; + const int output_dims_count = 8; + const float golden_relu[] = { 71, 0, 99, 0, 91, 0, 127, 0 }; + float output_data[output_dims_count]; + + TfLiteDepthwiseConvParams conv_params; + conv_params.activation = kTfLiteActRelu; + conv_params.dilation_width_factor = 1; + conv_params.dilation_height_factor = 1; + conv_params.stride_height = 1; + conv_params.stride_width = 1; + + tflite::testing::TestDepthwiseConvFloat( + input_shape, input_values, filter_shape, filter_values, bias_shape, + bias_values, golden_relu, output_shape, &conv_params, output_data); +} + +TF_LITE_MICRO_TEST(SimpleTestQuantizedPerChannel) +{ + const int input_elements = 12; + int input_shape[] = { 4, 1, 3, 2, 2 }; + const float input_values[] = { 1, 2, 7, 8, 3, 4, 9, 10, 5, 6, 11, 12 }; + const int filter_elements = 16; + int filter_shape[] = { 4, 1, 2, 2, 4 }; + const float filter_values[] = { 1, 2, 3, 4, -9, 10, -11, 12, + 5, 6, 7, 8, 13, -14, 15, -16 }; + const int bias_elements = 4; + int bias_shape[] = { 4, 1, 1, 1, 4 }; + const int output_elements = 8; + const float bias_values[] = { 1, 2, 3, 4 }; + const float golden[] = { + 71, + -34, + 99, + -20, + 91, + -26, + 127, + -4, + }; + int output_shape[] = { 4, 1, 2, 1, 4 }; + const int output_dims_count = 8; + int8_t output_data[output_dims_count]; + + const float input_scale = 0.5; + const float output_scale = 1.0f; + const int input_zero_point = 0; + const int output_zero_point = 0; + + int8_t input_quantized[input_elements]; + int8_t filter_quantized[filter_elements]; + int32_t bias_quantized[bias_elements]; + int8_t golden_quantized[output_elements]; + + TfLiteDepthwiseConvParams conv_params; + conv_params.activation = kTfLiteActNone; + conv_params.dilation_width_factor = 1; + conv_params.dilation_height_factor = 1; + conv_params.stride_height = 1; + conv_params.stride_width = 1; + + tflite::testing::TestDepthwiseConvQuantizedPerChannel( + input_shape, input_values, input_quantized, input_scale, input_zero_point, + filter_shape, filter_values, filter_quantized, bias_shape, bias_values, + bias_quantized, output_shape, golden, golden_quantized, output_data, + output_scale, output_zero_point, &conv_params); +} + +TF_LITE_MICRO_TEST(SimpleTestQuantizedPerChannelDepthMultiplier1) +{ + const int input_elements = 12; + int input_shape[] = { 4, 1, 3, 2, 2 }; + const float input_values[] = { 1, 2, 7, 8, 3, 4, 9, 10, 5, 6, 11, 12 }; + const int filter_elements = 8; + int filter_shape[] = { 4, 1, 2, 2, 2 }; + const float filter_values[] = { 1, 2, 3, 4, -9, 10, -11, 12 }; + const int bias_elements = 2; + int bias_shape[] = { 4, 1, 1, 1, 2 }; + const int output_elements = 4; + const float bias_values[] = { 1, 2 }; + const float golden[] = { + -103, + 127, + -128, + 127, + }; + int output_shape[] = { 4, 1, 2, 1, 2 }; + const int output_dims_count = 4; + int8_t output_data[output_dims_count]; + + const float input_scale = 1.0f; + const float output_scale = 1.0f; + const int input_zero_point = 0; + const int output_zero_point = 0; + + int8_t input_quantized[input_elements]; + int8_t filter_quantized[filter_elements]; + int32_t bias_quantized[bias_elements]; + int8_t golden_quantized[output_elements]; + + TfLiteDepthwiseConvParams conv_params; + conv_params.activation = kTfLiteActNone; + conv_params.dilation_width_factor = 1; + conv_params.dilation_height_factor = 1; + conv_params.stride_height = 1; + conv_params.stride_width = 1; + + tflite::testing::TestDepthwiseConvQuantizedPerChannel( + input_shape, input_values, input_quantized, input_scale, input_zero_point, + filter_shape, filter_values, filter_quantized, bias_shape, bias_values, + bias_quantized, output_shape, golden, golden_quantized, output_data, + output_scale, output_zero_point, &conv_params); +} + +TF_LITE_MICRO_TEST(TestQuantizedPerChannelDepthMultiplier1Relu6) +{ + const int input_elements = 24; + int input_shape[] = { 4, 1, 3, 2, 4 }; + const float input_values[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; + const int filter_elements = 16; + int filter_shape[] = { 4, 1, 2, 2, 4 }; + const float filter_values[] = { 0, 1, 8, -2, -1, 2, -10, 0, + -1, 3, -18, 0, 0, 4, 20, -3 }; + const int bias_elements = 4; + int bias_shape[] = { 4, 1, 1, 1, 4 }; + const int output_elements = 8; + const float bias_values[] = { 1, 2, 3, 4 }; + const float golden[] = { + 0, + 6, + 3, + 0, + 0, + 6, + 3, + 0, + }; + int output_shape[] = { 4, 1, 2, 1, 4 }; + int8_t output_data[output_elements]; + + const float input_scale = 0.023529f; + const float output_scale = 0.023529f; + const int input_zero_point = -128; + const int output_zero_point = -128; + + int8_t input_quantized[input_elements]; + int8_t filter_quantized[filter_elements]; + int32_t bias_quantized[bias_elements]; + int8_t golden_quantized[output_elements]; + + TfLiteDepthwiseConvParams conv_params; + conv_params.activation = kTfLiteActRelu6; + conv_params.dilation_width_factor = 1; + conv_params.dilation_height_factor = 1; + conv_params.stride_height = 1; + conv_params.stride_width = 1; + + tflite::testing::TestDepthwiseConvQuantizedPerChannel( + input_shape, input_values, input_quantized, input_scale, input_zero_point, + filter_shape, filter_values, filter_quantized, bias_shape, bias_values, + bias_quantized, output_shape, golden, golden_quantized, output_data, + output_scale, output_zero_point, &conv_params); +} + +TF_LITE_MICRO_TEST(SimpleTestDilatedQuantizedPerChannel) +{ + const int input_elements = 48; + int input_shape[] = { 4, 1, 4, 6, 2 }; + const float input_values[] = { 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, // h = 0 + 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, // h = 1 + 1, 2, 3, 4, 5, 6, 2, 6, 2, 4, 4, 2, // h = 2 + 3, 2, 6, 5, 1, 4, 1, 2, 1, 4, 6, 3 }; // h = 3 + const int filter_elements = 16; + int filter_shape[] = { 4, 1, 2, 2, 4 }; + const float filter_values[] = { 1, 2, 3, 4, -9, 10, -11, 12, + 5, 6, 7, 8, 13, -14, 15, -16 }; + const int bias_elements = 4; + int bias_shape[] = { 4, 1, 1, 1, 4 }; + const int output_elements = 24; + const float bias_values[] = { 1, 2, 3, 4 }; + const float golden[] = { + 15, 2, 88, -48, 25, 14, 72, 0, 61, -2, 56, 48, // h = 0 + -4, 52, 12, 48, 11, 70, 63, 40, 51, -30, 41, 48 // h = 1 + }; + int output_shape[] = { 4, 1, 2, 3, 4 }; + int8_t output_data[output_elements]; + + const float input_scale = 0.5; + const float output_scale = 1.0f; + const int input_zero_point = 0; + const int output_zero_point = 0; + + int8_t input_quantized[input_elements]; + int8_t filter_quantized[filter_elements]; + int32_t bias_quantized[bias_elements]; + int8_t golden_quantized[output_elements]; + + TfLiteDepthwiseConvParams conv_params; + conv_params.activation = kTfLiteActNone; + conv_params.dilation_width_factor = 3; + conv_params.dilation_height_factor = 2; + conv_params.stride_height = 1; + conv_params.stride_width = 1; + + tflite::testing::TestDepthwiseConvQuantizedPerChannel( + input_shape, input_values, input_quantized, input_scale, input_zero_point, + filter_shape, filter_values, filter_quantized, bias_shape, bias_values, + bias_quantized, output_shape, golden, golden_quantized, output_data, + output_scale, output_zero_point, &conv_params); +} + +TF_LITE_MICRO_TEST(TestQuantizedPerChannelCompareWithFloat) +{ + int input_dims[] = { 4, 1, 2, 3, 2 }; + const float input_data[] = { 3, 2, 1, -1, -2, -3, 4, 3, 2, -2, -3, -4 }; + int filter_dims[] = { 4, 1, 2, 2, 4 }; + const float filter_data[] = { 1, 2, 3, 4, 3, 4, 5, 6, 7, 8, 5, 6, 3, 4, 1, 2 }; + int bias_dims[] = { 4, 1, 1, 1, 4 }; + const float bias_data[] = { 3, -2, 4, 6 }; + int output_dims[] = { 4, 1, 1, 2, 4 }; + const float golden[] = { 43, 48, 18, 22, 3, -4, -28, -36 }; + + const int input_size = 12; + const int filter_size = 16; + const int output_size = 8; + const int bias_size = 4; + int8_t input_quantized[input_size]; + int8_t filter_quantized[filter_size]; + int32_t bias_quantized[bias_size]; + int8_t golden_quantized[output_size]; + int8_t output_data[output_size]; + float output_float[output_size]; + + const float input_scale = 0.5; + const float output_scale = 1.0; + const int input_zero_point = 0; + const int output_zero_point = 0; + + TfLiteDepthwiseConvParams conv_params; + conv_params.activation = kTfLiteActNone; + conv_params.dilation_width_factor = 1; + conv_params.dilation_height_factor = 1; + conv_params.stride_height = 1; + conv_params.stride_width = 1; + + tflite::testing::TestDepthwiseConvQuantizedPerChannel( + input_dims, input_data, input_quantized, input_scale, input_zero_point, + filter_dims, filter_data, filter_quantized, bias_dims, bias_data, + bias_quantized, output_dims, golden, golden_quantized, output_data, + output_scale, output_zero_point, &conv_params); + + tflite::testing::TestDepthwiseConvFloat( + input_dims, input_data, filter_dims, filter_data, bias_dims, bias_data, + golden, output_dims, &conv_params, output_float); +} + +TF_LITE_MICRO_TEST(PerChannelBroadcastQuantizationParams) +{ + const float input_scale = 1.0f; + const float filter_scale = 1.0f; + const float output_scale = 1.0f; + + const int input_elements = 12; + int input_shape[] = { 4, 1, 3, 2, 2 }; + const float input_values[] = { 1, 2, 7, 8, 3, 4, 9, 10, 5, 6, 11, 12 }; + const int filter_elements = 16; + int filter_shape[] = { 4, 1, 2, 2, 4 }; + const float filter_values[] = { 1, 2, 3, 4, -9, 10, -11, 12, + 5, 6, 7, 8, 13, -14, 15, -16 }; + const int bias_elements = 4; + int bias_shape[] = { 4, 1, 1, 1, 4 }; + const int output_elements = 8; + const float bias_values[] = { 1, 2, 3, 4 }; + const float golden[] = { + 71, + -34, + 99, + -20, + 91, + -26, + 127, + -4, + }; + int output_shape[] = { 4, 1, 2, 1, 4 }; + const int output_dims_count = 8; + int8_t output_data[output_dims_count]; + + int8_t input_quantized[input_elements]; + int8_t filter_quantized[filter_elements]; + int32_t bias_quantized[bias_elements]; + int8_t golden_quantized[output_elements]; + + TfLiteIntArray *input_dims = tflite::testing::IntArrayFromInts(input_shape); + TfLiteIntArray *filter_dims = tflite::testing::IntArrayFromInts(filter_shape); + TfLiteIntArray *bias_dims = tflite::testing::IntArrayFromInts(bias_shape); + TfLiteIntArray *output_dims = tflite::testing::IntArrayFromInts(output_shape); + + // Create per-layer quantized int8_t input tensor. + TfLiteTensor input_tensor = tflite::testing::CreateQuantizedTensor( + input_values, input_quantized, input_dims, input_scale, 0); + int input_zero_points[2] = { 1, 0 }; + float input_scales[2] = { 1, input_scale }; + TfLiteAffineQuantization input_quant = { + tflite::testing::FloatArrayFromFloats(input_scales), + tflite::testing::IntArrayFromInts(input_zero_points), 0 + }; + input_tensor.quantization = { kTfLiteAffineQuantization, &input_quant }; + + // Create per-layer quantized int8_t filter tensor. + TfLiteTensor filter_tensor = tflite::testing::CreateQuantizedTensor( + filter_values, filter_quantized, filter_dims, filter_scale, 0); + int filter_zero_points[2] = { 1, 0 }; + float filter_scales[2] = { 1, filter_scale }; + TfLiteAffineQuantization filter_quant = { + tflite::testing::FloatArrayFromFloats(filter_scales), + tflite::testing::IntArrayFromInts(filter_zero_points), 0 + }; + filter_tensor.quantization = { kTfLiteAffineQuantization, &filter_quant }; + + // Create per-layer quantized int32_t bias tensor. + tflite::SymmetricQuantize(bias_values, bias_quantized, bias_elements, + input_scale * output_scale); + TfLiteTensor bias_tensor = + tflite::testing::CreateTensor(bias_quantized, bias_dims); + + int bias_zero_points[2] = { 1, 0 }; + float bias_scales[2] = { 1, input_scale * filter_scale }; + TfLiteAffineQuantization bias_quant = { + tflite::testing::FloatArrayFromFloats(bias_scales), + tflite::testing::IntArrayFromInts(bias_zero_points), 0 + }; + bias_tensor.quantization = { kTfLiteAffineQuantization, &bias_quant }; + + // Create per-layer quantized int8_t output tensor. + TfLiteTensor output_tensor = tflite::testing::CreateQuantizedTensor( + output_data, output_dims, output_scale, 0); + int output_zero_points[2] = { 1, 0 }; + float output_scales[2] = { 1, output_scale }; + TfLiteAffineQuantization output_quant = { + tflite::testing::FloatArrayFromFloats(output_scales), + tflite::testing::IntArrayFromInts(output_zero_points), 0 + }; + output_tensor.quantization = { kTfLiteAffineQuantization, &output_quant }; + + constexpr int inputs_size = 3; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + input_tensor, + filter_tensor, + bias_tensor, + output_tensor, + }; + + tflite::Quantize(golden, golden_quantized, output_dims_count, output_scale, + 0); + + TfLiteDepthwiseConvParams conv_params; + conv_params.activation = kTfLiteActNone; + conv_params.dilation_width_factor = 1; + conv_params.dilation_height_factor = 1; + conv_params.stride_height = 1; + conv_params.stride_width = 1; + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, tflite::testing::ValidateDepthwiseConvGoldens( + golden_quantized, output_dims_count, &conv_params, 1e-5, + tensors_size, tensors)); +} + +#endif // !defined(XTENSA) + +TF_LITE_MICRO_TEST(FilterDimsNotMatchingAffineQuantization) +{ + int input_shape[] = { 4, 1, 2, 3, 2 }; + const float input_data[] = { 3, 2, 1, -1, -2, -3, 4, 3, 2, -2, -3, -4 }; + int filter_shape[] = { 4, 1, 2, 2, 4 }; + const float filter_data[] = { 1, 2, 3, 4, 3, 4, 5, 6, 7, 8, 5, 6, 3, 4, 1, 2 }; + int bias_shape[] = { 4, 1, 1, 1, 4 }; + const float bias_data[] = { 3, -2, 4, 6 }; + int output_shape[] = { 4, 1, 1, 2, 4 }; + + const int input_size = 12; + const int filter_size = 16; + const int output_size = 8; + const int bias_size = 4; + int8_t input_quantized[input_size]; + int8_t filter_quantized[filter_size]; + int32_t bias_quantized[bias_size]; + int8_t golden_quantized[output_size]; + int zero_points[bias_size + 1]; + float scales[bias_size + 1]; + int8_t output_data[output_size]; + + const float input_scale = 0.5; + const float output_scale = 1.0; + const int input_zero_point = 0; + const int output_zero_point = 0; + + TfLiteIntArray *input_dims = tflite::testing::IntArrayFromInts(input_shape); + TfLiteIntArray *filter_dims = tflite::testing::IntArrayFromInts(filter_shape); + TfLiteIntArray *bias_dims = tflite::testing::IntArrayFromInts(bias_shape); + TfLiteIntArray *output_dims = tflite::testing::IntArrayFromInts(output_shape); + + int filter_zero_points[5]; + float filter_scales[5]; + TfLiteAffineQuantization filter_quant; + TfLiteAffineQuantization bias_quant; + TfLiteTensor input_tensor = tflite::testing::CreateQuantizedTensor( + input_data, input_quantized, input_dims, input_scale, input_zero_point); + TfLiteTensor filter_tensor = + tflite::testing::CreateSymmetricPerChannelQuantizedTensor( + filter_data, filter_quantized, filter_dims, filter_scales, + filter_zero_points, &filter_quant, 0 /* quantized dimension */); + TfLiteTensor bias_tensor = + tflite::testing::CreatePerChannelQuantizedBiasTensor( + bias_data, bias_quantized, bias_dims, input_scale, &filter_scales[1], + scales, zero_points, &bias_quant, 0); + TfLiteTensor output_tensor = tflite::testing::CreateQuantizedTensor( + output_data, output_dims, output_scale, output_zero_point); + + float input_scales[] = { 1, input_scale }; + int input_zero_points[] = { 1, input_zero_point }; + TfLiteAffineQuantization input_quant = { + tflite::testing::FloatArrayFromFloats(input_scales), + tflite::testing::IntArrayFromInts(input_zero_points), 0 + }; + input_tensor.quantization = { kTfLiteAffineQuantization, &input_quant }; + + constexpr int inputs_size = 3; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + input_tensor, + filter_tensor, + bias_tensor, + output_tensor, + }; + + TfLiteDepthwiseConvParams conv_params; + conv_params.activation = kTfLiteActNone; + conv_params.dilation_width_factor = 1; + conv_params.dilation_height_factor = 1; + conv_params.stride_height = 1; + conv_params.stride_width = 1; + + // Set filter quant to mismatched dimension. + TfLiteAffineQuantization *quant = reinterpret_cast( + filter_tensor.quantization.params); + quant->scale->size = 2; + TF_LITE_MICRO_EXPECT_EQ(kTfLiteError, + tflite::testing::ValidateDepthwiseConvGoldens( + golden_quantized, output_size, &conv_params, 1e-5, + tensors_size, tensors)); + + // Set scale back to correct dimension, and make zero point array too short. + quant->scale->size = filter_shape[0]; + quant->zero_point->size = 2; + TF_LITE_MICRO_EXPECT_EQ(kTfLiteError, + tflite::testing::ValidateDepthwiseConvGoldens( + golden_quantized, output_size, &conv_params, 1e-5, + tensors_size, tensors)); +} + +TF_LITE_MICRO_TEST(Int8Input32x4Filter32x4ShouldMatchGolden) +{ + const int input_elements = 32 * 4; + const int filter_elements = 32 * 4; + const int bias_elements = 32; + const int output_elements = 32; + int input_shape[] = { 4, 1, 4, 1, 32 }; + int filter_shape[] = { 4, 1, 4, 1, 32 }; + int bias_shape[] = { 1, 32 }; + int output_shape[] = { 4, 1, 1, 1, 32 }; + const float input_values[] = { + 11.0589, 10.8824, 11.1766, 11.5295, 10.8236, 9.5295, 9.5295, 10.0001, + 11.2354, 10.8824, 9.1765, 9.0589, 9.6471, 8.9412, 7.9412, 9.0001, + 9.3530, 7.5295, 9.2354, 9.5883, 7.5883, 8.1765, 7.5883, 9.2942, + 9.1177, 8.5883, 8.2354, 8.6471, 8.0589, 8.0001, 7.4118, 7.3530, + 11.0001, 11.1177, 11.0589, 11.2354, 10.5883, 9.2942, 9.2942, 10.1177, + 11.2354, 10.8824, 8.9412, 8.8236, 9.2354, 8.8824, 7.0001, 9.1177, + 9.5883, 8.2354, 9.1765, 9.5295, 7.4118, 8.5883, 8.1177, 9.1765, + 9.0001, 9.0589, 8.9412, 8.2942, 7.8824, 8.4118, 7.2942, 7.2354, + 10.4118, 10.8824, 11.1177, 11.0001, 10.0001, 9.7060, 9.7648, 10.1766, + 11.1766, 10.6471, 8.6471, 8.5295, 9.5295, 9.0001, 7.0001, 9.4118, + 9.8236, 8.0001, 9.2354, 9.5883, 7.5295, 9.0001, 8.5295, 9.0589, + 8.9412, 9.1177, 8.9412, 8.0001, 8.0589, 8.8824, 7.0589, 7.3530, + 11.3530, 11.0589, 10.7060, 10.7648, 9.9413, 9.1177, 9.1177, 9.7648, + 10.7060, 10.2354, 8.5883, 8.8236, 9.7648, 9.2942, 7.5295, 9.2354, + 9.7060, 8.1177, 9.2942, 9.5883, 7.7648, 9.6471, 9.1177, 9.4707, + 9.3530, 8.8236, 8.5295, 8.0589, 8.6471, 9.5883, 7.4118, 7.5883 + }; + const float filter_values[] = { + -0.1617, -0.1948, 0.1419, -0.2311, -0.0891, 0.1551, 0.0033, 0.3037, + -0.1683, 0.1353, 0.1518, -0.1683, -0.1386, 0.1452, 0.1816, 0.1716, + -0.1948, 0.2080, 0.2245, -0.1981, -0.2410, 0.1849, 0.1981, 0.1584, + 0.2509, 0.1783, -0.2146, -0.1518, 0.2080, -0.2872, 0.2014, 0.2476, + -0.4126, -0.0561, -0.3235, -0.0594, -0.0957, 0.2014, -0.1056, 0.1386, + -0.2542, -0.1617, 0.1287, -0.1816, -0.0363, 0.1419, -0.0594, 0.2344, + -0.0099, 0.4192, 0.1287, -0.2311, -0.2212, -0.0528, -0.2080, 0.1816, + -0.1452, 0.1221, 0.1254, -0.1056, -0.0759, 0.1221, 0.1023, 0.1485, + 0.2707, 0.1716, -0.1882, -0.1783, 0.1650, -0.2740, 0.1915, 0.2080, + -0.2971, -0.2575, -0.3169, 0.0198, -0.0231, 0.2410, -0.0429, 0.0660, + -0.1816, 0.1981, 0.2014, -0.1386, -0.1915, 0.1716, 0.1320, 0.1419, + 0.1320, 0.1353, -0.1386, -0.1716, 0.1320, -0.1650, 0.1386, 0.0825, + -0.1419, -0.1023, 0.1783, 0.0462, 0.2047, -0.2179, -0.1518, -0.1551, + 0.1518, 0.3334, 0.3103, -0.2047, -0.2047, -0.0957, -0.1650, 0.1221, + 0.0990, 0.1353, -0.1617, -0.1485, 0.1650, -0.1816, 0.1518, 0.1254, + -0.0363, -0.1254, 0.1386, 0.0429, 0.2113, -0.2839, -0.1056, -0.2278 + }; + const float bias_values[] = { + 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, + 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, + 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, + 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000 + }; + const float golden[] = { + -5.1194, -2.0075, -2.1751, -4.7958, 1.7073, -1.2963, -0.4641, 5.0416, + -6.4424, 0.3836, 2.4684, -4.7643, -3.8913, 3.8382, -0.5164, 5.4304, + -2.7400, 7.7016, 3.6115, -6.8545, -3.6290, 0.8509, 2.3247, 5.6117, + 1.8215, 2.7645, -0.7032, -3.2156, 3.9689, -5.4583, 2.4346, 1.7731 + }; + + // Quantization Parameters. All scales except output are 1.0, and all zero + // points are 0. This direct-maps the values to floating point and makes it + // easy to reson about them. + const float input_scale = 0.058824; + const float filter_scale = 0.003301; + const float output_scale = 0.092596; + const int input_zero_point = -128; + const int output_zero_point = 0; + + TfLiteIntArray *input_dims = tflite::testing::IntArrayFromInts(input_shape); + TfLiteIntArray *filter_dims = tflite::testing::IntArrayFromInts(filter_shape); + TfLiteIntArray *bias_dims = tflite::testing::IntArrayFromInts(bias_shape); + TfLiteIntArray *output_dims = tflite::testing::IntArrayFromInts(output_shape); + + // Create per-tensor quantized int8_t input tensor. + int8_t input_quantized[input_elements]; + TfLiteTensor input_tensor = tflite::testing::CreateQuantizedTensor( + input_values, input_quantized, input_dims, input_scale, input_zero_point); + + // Set zero point and scale arrays with a single element for each. + int input_zero_points[] = { 1, input_zero_point }; + float input_scales[] = { 1, input_scale }; + TfLiteAffineQuantization input_quant = { + tflite::testing::FloatArrayFromFloats(input_scales), + tflite::testing::IntArrayFromInts(input_zero_points), 0 + }; + input_tensor.quantization = { kTfLiteAffineQuantization, &input_quant }; + + // Create per-tensor quantized int8_t filter tensor. + int8_t filter_quantized[filter_elements]; + TfLiteTensor filter_tensor = tflite::testing::CreateQuantizedTensor( + filter_values, filter_quantized, filter_dims, filter_scale, 0); + + // Set zero point and scale arrays with a single element for each. + int filter_zero_points[] = { 1, 0 }; + float filter_scales[] = { 1, filter_scale }; + TfLiteAffineQuantization filter_quant = { + tflite::testing::FloatArrayFromFloats(filter_scales), + tflite::testing::IntArrayFromInts(filter_zero_points), 0 + }; + filter_tensor.quantization = { kTfLiteAffineQuantization, &filter_quant }; + + // Create per-tensor quantized int32_t bias tensor. + int32_t bias_quantized[bias_elements]; + // See https://www.tensorflow.org/lite/performance/quantization_spec for a + // detailed explanation of why bias scale is input_scale * filter_scale. + tflite::SymmetricQuantize(bias_values, bias_quantized, bias_elements, + input_scale * output_scale); + TfLiteTensor bias_tensor = + tflite::testing::CreateTensor(bias_quantized, bias_dims); + + // Set zero point and scale arrays with a single element for each. + int bias_zero_points[] = { 1, 0 }; + float bias_scales[] = { 1, input_scale * filter_scale }; + TfLiteAffineQuantization bias_quant = { + tflite::testing::FloatArrayFromFloats(bias_scales), + tflite::testing::IntArrayFromInts(bias_zero_points), 0 + }; + bias_tensor.quantization = { kTfLiteAffineQuantization, &bias_quant }; + + // Create per-tensor quantized int8_t output tensor. + int8_t output_quantized[output_elements]; + TfLiteTensor output_tensor = tflite::testing::CreateQuantizedTensor( + output_quantized, output_dims, output_scale, output_zero_point); + + // Set zero point and scale arrays with a single element for each. + int output_zero_points[] = { 1, output_zero_point }; + float output_scales[] = { 1, output_scale }; + TfLiteAffineQuantization output_quant = { + tflite::testing::FloatArrayFromFloats(output_scales), + tflite::testing::IntArrayFromInts(output_zero_points), 0 + }; + output_tensor.quantization = { kTfLiteAffineQuantization, &output_quant }; + + // The 3 inputs include the input, filter and bias tensors. + constexpr int kInputsSize = 3; + constexpr int kOutputsSize = 1; + constexpr int kTensorsSize = kInputsSize + kOutputsSize; + TfLiteTensor tensors[kTensorsSize] = { + input_tensor, + filter_tensor, + bias_tensor, + output_tensor, + }; + + int8_t golden_quantized[output_elements]; + tflite::Quantize(golden, golden_quantized, output_elements, output_scale, 0); + + // Errors due to quantization should not exceed 1. + constexpr int kQuantizationTolerance = 1; + + TfLiteDepthwiseConvParams conv_params; + conv_params.activation = kTfLiteActNone; + conv_params.dilation_width_factor = 1; + conv_params.dilation_height_factor = 1; + conv_params.stride_height = 1; + conv_params.stride_width = 1; + tflite::testing::ValidateDepthwiseConvGoldens( + golden_quantized, output_elements, &conv_params, kQuantizationTolerance, + kTensorsSize, tensors); +} + +#if !defined(HIFIMINI) +// TODO(b/184087246): Remove this ifdef once the hifimini implementation is +// updated to be more general. +TF_LITE_MICRO_TEST(Int8Input32x1Filter32x1ShouldMatchGolden) +{ + const int input_elements = 32 * 1; + const int filter_elements = 32 * 1; + const int bias_elements = 32; + const int output_elements = 32; + int input_shape[] = { 4, 1, 1, 1, 32 }; + int filter_shape[] = { 4, 1, 1, 1, 32 }; + int bias_shape[] = { 1, 32 }; + int output_shape[] = { 4, 1, 1, 1, 32 }; + const float input_values[] = { + 11.0589, 10.8824, 11.1766, 11.5295, 10.8236, 9.5295, 9.5295, 10.0001, + 11.2354, 10.8824, 9.1765, 9.0589, 9.6471, 8.9412, 7.9412, 9.0001, + 9.3530, 7.5295, 9.2354, 9.5883, 7.5883, 8.1765, 7.5883, 9.2942, + 9.3530, 8.8236, 8.5295, 8.0589, 8.6471, 9.5883, 7.4118, 7.5883 + }; + const float filter_values[] = { + -0.1419, -0.1023, 0.1783, 0.0462, 0.2047, -0.2179, -0.1518, -0.1551, + 0.1518, 0.3334, 0.3103, -0.2047, -0.2047, -0.0957, -0.1650, 0.1221, + 0.0990, 0.1353, -0.1617, -0.1485, 0.1650, -0.1816, 0.1518, 0.1254, + -0.0363, -0.1254, 0.1386, 0.0429, 0.2113, -0.2839, -0.1056, -0.2278 + }; + const float bias_values[] = { + 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, + 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, + 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, + 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000 + }; + const float golden[] = { + -1.5741, -1.1112, 2.0371, 0.5556, 2.2223, -2.0371, -1.4815, -1.5741, + 1.6667, 3.6112, 2.8705, -1.8519, -1.9445, -0.8334, -1.2963, 1.1112, + 0.9260, 1.0186, -1.4815, -1.3889, 1.2963, -1.4815, 1.1112, 1.2037, + -0.3704, -1.1112, 1.2037, 0.3704, 1.8519, -2.6853, -0.7408, -1.7593 + }; + + // Quantization Parameters. All scales except output are 1.0, and all zero + // points are 0. This direct-maps the values to floating point and makes it + // easy to reson about them. + const float input_scale = 0.058824; + const float filter_scale = 0.003301; + const float output_scale = 0.092596; + const int input_zero_point = -128; + const int output_zero_point = 0; + + TfLiteIntArray *input_dims = tflite::testing::IntArrayFromInts(input_shape); + TfLiteIntArray *filter_dims = tflite::testing::IntArrayFromInts(filter_shape); + TfLiteIntArray *bias_dims = tflite::testing::IntArrayFromInts(bias_shape); + TfLiteIntArray *output_dims = tflite::testing::IntArrayFromInts(output_shape); + + // Create per-tensor quantized int8_t input tensor. + int8_t input_quantized[input_elements]; + TfLiteTensor input_tensor = tflite::testing::CreateQuantizedTensor( + input_values, input_quantized, input_dims, input_scale, input_zero_point); + + // Set zero point and scale arrays with a single element for each. + int input_zero_points[] = { 1, input_zero_point }; + float input_scales[] = { 1, input_scale }; + TfLiteAffineQuantization input_quant = { + tflite::testing::FloatArrayFromFloats(input_scales), + tflite::testing::IntArrayFromInts(input_zero_points), 0 + }; + input_tensor.quantization = { kTfLiteAffineQuantization, &input_quant }; + + // Create per-tensor quantized int8_t filter tensor. + int8_t filter_quantized[filter_elements]; + TfLiteTensor filter_tensor = tflite::testing::CreateQuantizedTensor( + filter_values, filter_quantized, filter_dims, filter_scale, 0); + + // Set zero point and scale arrays with a single element for each. + int filter_zero_points[] = { 1, 0 }; + float filter_scales[] = { 1, filter_scale }; + TfLiteAffineQuantization filter_quant = { + tflite::testing::FloatArrayFromFloats(filter_scales), + tflite::testing::IntArrayFromInts(filter_zero_points), 0 + }; + filter_tensor.quantization = { kTfLiteAffineQuantization, &filter_quant }; + + // Create per-tensor quantized int32_t bias tensor. + int32_t bias_quantized[bias_elements]; + // See https://www.tensorflow.org/lite/performance/quantization_spec for a + // detailed explanation of why bias scale is input_scale * filter_scale. + tflite::SymmetricQuantize(bias_values, bias_quantized, bias_elements, + input_scale * output_scale); + TfLiteTensor bias_tensor = + tflite::testing::CreateTensor(bias_quantized, bias_dims); + + // Set zero point and scale arrays with a single element for each. + int bias_zero_points[] = { 1, 0 }; + float bias_scales[] = { 1, input_scale * filter_scale }; + TfLiteAffineQuantization bias_quant = { + tflite::testing::FloatArrayFromFloats(bias_scales), + tflite::testing::IntArrayFromInts(bias_zero_points), 0 + }; + bias_tensor.quantization = { kTfLiteAffineQuantization, &bias_quant }; + + // Create per-tensor quantized int8_t output tensor. + int8_t output_quantized[output_elements]; + TfLiteTensor output_tensor = tflite::testing::CreateQuantizedTensor( + output_quantized, output_dims, output_scale, output_zero_point); + + // Set zero point and scale arrays with a single element for each. + int output_zero_points[] = { 1, output_zero_point }; + float output_scales[] = { 1, output_scale }; + TfLiteAffineQuantization output_quant = { + tflite::testing::FloatArrayFromFloats(output_scales), + tflite::testing::IntArrayFromInts(output_zero_points), 0 + }; + output_tensor.quantization = { kTfLiteAffineQuantization, &output_quant }; + + // The 3 inputs include the input, filter and bias tensors. + constexpr int kInputsSize = 3; + constexpr int kOutputsSize = 1; + constexpr int kTensorsSize = kInputsSize + kOutputsSize; + TfLiteTensor tensors[kTensorsSize] = { + input_tensor, + filter_tensor, + bias_tensor, + output_tensor, + }; + + int8_t golden_quantized[output_elements]; + tflite::Quantize(golden, golden_quantized, output_elements, output_scale, 0); + + // Errors due to quantization should not exceed 1. + constexpr int kQuantizationTolerance = 1; + + TfLiteDepthwiseConvParams conv_params; + conv_params.activation = kTfLiteActNone; + conv_params.dilation_width_factor = 1; + conv_params.dilation_height_factor = 1; + conv_params.stride_height = 2; + conv_params.stride_width = 2; + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + tflite::testing::ValidateDepthwiseConvGoldens( + golden_quantized, output_elements, &conv_params, + kQuantizationTolerance, kTensorsSize, tensors)); +} +#endif // !defined(HIFIMINI) + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/dequantize.cc b/components/tflite/tensorflow/lite/micro/kernels/dequantize.cc new file mode 100644 index 00000000..14cb268e --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/dequantize.cc @@ -0,0 +1,143 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/dequantize.h" + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/quantize.h" +#include "tensorflow/lite/kernels/internal/reference/requantize.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace dequantize { + +struct OpData { + tflite::DequantizationParams quantization_params; + // The scaling factor from input to output (aka the 'real multiplier') can + // be represented as a fixed point multiplier plus a left shift. + int32_t output_multiplier; + int output_shift; + int32_t output_zero_point; +}; + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(OpData)); +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + OpData *data = static_cast(node->user_data); + + TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + + // TODO(b/140515557): Add cached dequant to improve hybrid model performance. + const TfLiteTensor *input = GetInput(context, node, 0); + TF_LITE_ENSURE(context, input != nullptr); + TfLiteTensor *output = GetOutput(context, node, 0); + TF_LITE_ENSURE(context, output != nullptr); + + TF_LITE_ENSURE(context, input->type == kTfLiteUInt8 || + input->type == kTfLiteInt8 || + input->type == kTfLiteInt16); + TF_LITE_ENSURE(context, output->type == kTfLiteFloat32); + + if (output->type == kTfLiteInt32) { + const double effective_output_scale = + static_cast(input->params.scale) / + static_cast(output->params.scale); + QuantizeMultiplier(effective_output_scale, &data->output_multiplier, + &data->output_shift); + } + + data->quantization_params.zero_point = input->params.zero_point; + data->quantization_params.scale = static_cast(input->params.scale); + data->output_zero_point = output->params.zero_point; + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + OpData *data = static_cast(node->user_data); + + const TfLiteEvalTensor *input = tflite::micro::GetEvalInput(context, node, 0); + TfLiteEvalTensor *output = tflite::micro::GetEvalOutput(context, node, 0); + + if (output->type == kTfLiteFloat32) { + switch (input->type) { + case kTfLiteUInt8: + reference_ops::Dequantize(data->quantization_params, + tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + break; + case kTfLiteInt8: + reference_ops::Dequantize(data->quantization_params, + tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + break; + case kTfLiteInt16: + reference_ops::Dequantize(data->quantization_params, + tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + break; + default: + TF_LITE_KERNEL_LOG(context, "Input %s, output %s not supported.", + TfLiteTypeGetName(input->type), + TfLiteTypeGetName(output->type)); + return kTfLiteError; + } + } else { + TF_LITE_KERNEL_LOG(context, "Input %s, output %s not supported.", + TfLiteTypeGetName(input->type), + TfLiteTypeGetName(output->type)); + return kTfLiteError; + } + + return kTfLiteOk; +} + +} // namespace dequantize + +TfLiteRegistration Register_DEQUANTIZE() +{ + return { /*init=*/dequantize::Init, + /*free=*/nullptr, + /*prepare=*/dequantize::Prepare, + /*invoke=*/dequantize::Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/dequantize_test.cc b/components/tflite/tensorflow/lite/micro/kernels/dequantize_test.cc new file mode 100644 index 00000000..e0e7a75f --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/dequantize_test.cc @@ -0,0 +1,148 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +template +void ValidateDequantizeGoldens(TfLiteTensor *tensors, int tensors_size, + const T *expected_output_data, T *output_data, + int output_length, float tolerance = 1e-5) +{ + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = + tflite::ops::micro::Register_DEQUANTIZE(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_length; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output_data[i], output_data[i], 0.001f); + } +} + +template +void TestDequantizeToFloat(int *input_dims_data, const float *input_data, + T *input_data_quantized, float scale, int zero_point, + int *output_dims_data, + const float *expected_output_data, + float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_length = ElementCount(*output_dims); + + // 1 input, 1 output. + const int tensors_size = 2; + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(input_data, input_data_quantized, input_dims, scale, + zero_point), + CreateTensor(output_data, output_dims), + }; + + ValidateDequantizeGoldens(tensors, tensors_size, expected_output_data, + output_data, output_length); +} + +template +void TestDequantizeToInt32(int *input_dims_data, const float *input_data, + T *input_data_quantized, float input_scale, + int input_zero_point, int *output_dims_data, + const int32_t *expected_output_data, + float output_scale, int output_zero_point, + int32_t *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_length = ElementCount(*output_dims); + + // 1 input, 1 output. + const int tensors_size = 2; + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(input_data, input_data_quantized, input_dims, + input_scale, input_zero_point), + CreateTensor(output_data, output_dims), + }; + + tensors[1].params.scale = output_scale; + tensors[1].params.zero_point = output_zero_point; + + ValidateDequantizeGoldens(tensors, tensors_size, expected_output_data, + output_data, output_length); +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(DequantizeOpTestUint8) +{ + const int length = 10; + int dims[] = { 2, 5, 2 }; + const float values[] = { -63.5, -63, -62.5, -62, -61.5, + 62, 62.5, 63, 63.5, 64 }; + const float scale = 0.5; + const int zero_point = 127; + uint8_t input_quantized[length]; + float output[length]; + tflite::testing::TestDequantizeToFloat(dims, values, input_quantized, scale, + zero_point, dims, values, output); +} + +TF_LITE_MICRO_TEST(DequantizeOpTestInt8) +{ + const int length = 10; + int dims[] = { 2, 5, 2 }; + const float values[] = { -63.5, -63, -62.5, -62, -61.5, + 62, 62.5, 63, 63.5, 64 }; + const float scale = 0.5; + const int zero_point = -1; + int8_t input_quantized[length]; + float output[length]; + tflite::testing::TestDequantizeToFloat(dims, values, input_quantized, scale, + zero_point, dims, values, output); +} + +TF_LITE_MICRO_TEST(DequantizeOpTestInt16) +{ + const int length = 10; + int dims[] = { 2, 5, 2 }; + const float values[] = { -63.5, -63, -62.5, -62, -61.5, + 62, 62.5, 63, 63.5, 64 }; + const float scale = 0.5; + const int zero_point = -1; + int16_t input_quantized[length]; + float output[length]; + tflite::testing::TestDequantizeToFloat(dims, values, input_quantized, scale, + zero_point, dims, values, output); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/detection_postprocess.cc b/components/tflite/tensorflow/lite/micro/kernels/detection_postprocess.cc new file mode 100644 index 00000000..d522b385 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/detection_postprocess.cc @@ -0,0 +1,835 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/micro_utils.h" + +namespace tflite { +namespace { + +/** + * This version of detection_postprocess is specific to TFLite Micro. It + * contains the following differences between the TFLite version: + * + * 1.) Temporaries (temporary tensors) - Micro use instead scratch buffer API. + * 2.) Output dimensions - the TFLite version does not support undefined out + * dimensions. So model must have static out dimensions. + */ + +// Input tensors +constexpr int kInputTensorBoxEncodings = 0; +constexpr int kInputTensorClassPredictions = 1; +constexpr int kInputTensorAnchors = 2; + +// Output tensors +constexpr int kOutputTensorDetectionBoxes = 0; +constexpr int kOutputTensorDetectionClasses = 1; +constexpr int kOutputTensorDetectionScores = 2; +constexpr int kOutputTensorNumDetections = 3; + +constexpr int kNumCoordBox = 4; +constexpr int kBatchSize = 1; + +constexpr int kNumDetectionsPerClass = 100; + +// Object Detection model produces axis-aligned boxes in two formats: +// BoxCorner represents the lower left corner (xmin, ymin) and +// the upper right corner (xmax, ymax). +// CenterSize represents the center (xcenter, ycenter), height and width. +// BoxCornerEncoding and CenterSizeEncoding are related as follows: +// ycenter = y / y_scale * anchor.h + anchor.y; +// xcenter = x / x_scale * anchor.w + anchor.x; +// half_h = 0.5*exp(h/ h_scale)) * anchor.h; +// half_w = 0.5*exp(w / w_scale)) * anchor.w; +// ymin = ycenter - half_h +// ymax = ycenter + half_h +// xmin = xcenter - half_w +// xmax = xcenter + half_w +struct BoxCornerEncoding { + float ymin; + float xmin; + float ymax; + float xmax; +}; + +struct CenterSizeEncoding { + float y; + float x; + float h; + float w; +}; +// We make sure that the memory allocations are contiguous with static_assert. +static_assert(sizeof(BoxCornerEncoding) == sizeof(float) * kNumCoordBox, + "Size of BoxCornerEncoding is 4 float values"); +static_assert(sizeof(CenterSizeEncoding) == sizeof(float) * kNumCoordBox, + "Size of CenterSizeEncoding is 4 float values"); + +struct OpData { + int max_detections; + int max_classes_per_detection; // Fast Non-Max-Suppression + int detections_per_class; // Regular Non-Max-Suppression + float non_max_suppression_score_threshold; + float intersection_over_union_threshold; + int num_classes; + bool use_regular_non_max_suppression; + CenterSizeEncoding scale_values; + + // Scratch buffers indexes + int active_candidate_idx; + int decoded_boxes_idx; + int scores_idx; + int score_buffer_idx; + int keep_scores_idx; + int scores_after_regular_non_max_suppression_idx; + int sorted_values_idx; + int keep_indices_idx; + int sorted_indices_idx; + int buffer_idx; + int selected_idx; + + // Cached tensor scale and zero point values for quantized operations + TfLiteQuantizationParams input_box_encodings; + TfLiteQuantizationParams input_class_predictions; + TfLiteQuantizationParams input_anchors; +}; + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + OpData *op_data = nullptr; + + const uint8_t *buffer_t = reinterpret_cast(buffer); + + op_data = reinterpret_cast( + context->AllocatePersistentBuffer(context, sizeof(OpData))); + + const flexbuffers::Map &m = + micro::FlexbuffersWrapperGetRootAsMap(buffer_t, length); + + op_data->max_detections = + micro::FlexbuffersWrapperAsInt32(m, "max_detections"); + op_data->max_classes_per_detection = + micro::FlexbuffersWrapperAsInt32(m, "max_classes_per_detection"); + if (micro::FlexbuffersWrapperIsNull(m, "detections_per_class")) + op_data->detections_per_class = kNumDetectionsPerClass; + else + op_data->detections_per_class = + micro::FlexbuffersWrapperAsInt32(m, "detections_per_class"); + if (micro::FlexbuffersWrapperIsNull(m, "use_regular_nms")) + op_data->use_regular_non_max_suppression = false; + else + op_data->use_regular_non_max_suppression = + micro::FlexbuffersWrapperAsBool(m, "use_regular_nms"); + + op_data->non_max_suppression_score_threshold = + micro::FlexbuffersWrapperAsFloat(m, "nms_score_threshold"); + + op_data->intersection_over_union_threshold = + micro::FlexbuffersWrapperAsFloat(m, "nms_iou_threshold"); + op_data->num_classes = micro::FlexbuffersWrapperAsInt32(m, "num_classes"); + op_data->scale_values.y = micro::FlexbuffersWrapperAsFloat(m, "y_scale"); + op_data->scale_values.x = micro::FlexbuffersWrapperAsFloat(m, "x_scale"); + op_data->scale_values.h = micro::FlexbuffersWrapperAsFloat(m, "h_scale"); + op_data->scale_values.w = micro::FlexbuffersWrapperAsFloat(m, "w_scale"); + + return op_data; +} + +void Free(TfLiteContext *context, void *buffer) +{ +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + auto *op_data = static_cast(node->user_data); + + // Inputs: box_encodings, scores, anchors + TF_LITE_ENSURE_EQ(context, NumInputs(node), 3); + const TfLiteTensor *input_box_encodings = + GetInput(context, node, kInputTensorBoxEncodings); + const TfLiteTensor *input_class_predictions = + GetInput(context, node, kInputTensorClassPredictions); + const TfLiteTensor *input_anchors = + GetInput(context, node, kInputTensorAnchors); + TF_LITE_ENSURE_EQ(context, NumDimensions(input_box_encodings), 3); + TF_LITE_ENSURE_EQ(context, NumDimensions(input_class_predictions), 3); + TF_LITE_ENSURE_EQ(context, NumDimensions(input_anchors), 2); + + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 4); + const int num_boxes = input_box_encodings->dims->data[1]; + const int num_classes = op_data->num_classes; + + op_data->input_box_encodings.scale = input_box_encodings->params.scale; + op_data->input_box_encodings.zero_point = + input_box_encodings->params.zero_point; + op_data->input_class_predictions.scale = + input_class_predictions->params.scale; + op_data->input_class_predictions.zero_point = + input_class_predictions->params.zero_point; + op_data->input_anchors.scale = input_anchors->params.scale; + op_data->input_anchors.zero_point = input_anchors->params.zero_point; + + // Scratch tensors + context->RequestScratchBufferInArena(context, num_boxes, + &op_data->active_candidate_idx); + context->RequestScratchBufferInArena(context, + num_boxes * kNumCoordBox * sizeof(float), + &op_data->decoded_boxes_idx); + context->RequestScratchBufferInArena( + context, + input_class_predictions->dims->data[1] * + input_class_predictions->dims->data[2] * sizeof(float), + &op_data->scores_idx); + + // Additional buffers + context->RequestScratchBufferInArena(context, num_boxes * sizeof(float), + &op_data->score_buffer_idx); + context->RequestScratchBufferInArena(context, num_boxes * sizeof(float), + &op_data->keep_scores_idx); + context->RequestScratchBufferInArena( + context, op_data->max_detections * num_boxes * sizeof(float), + &op_data->scores_after_regular_non_max_suppression_idx); + context->RequestScratchBufferInArena( + context, op_data->max_detections * num_boxes * sizeof(float), + &op_data->sorted_values_idx); + context->RequestScratchBufferInArena(context, num_boxes * sizeof(int), + &op_data->keep_indices_idx); + context->RequestScratchBufferInArena( + context, op_data->max_detections * num_boxes * sizeof(int), + &op_data->sorted_indices_idx); + int buffer_size = std::max(num_classes, op_data->max_detections); + context->RequestScratchBufferInArena( + context, buffer_size * num_boxes * sizeof(int), &op_data->buffer_idx); + buffer_size = std::min(num_boxes, op_data->max_detections); + context->RequestScratchBufferInArena( + context, buffer_size * num_boxes * sizeof(int), &op_data->selected_idx); + + // Outputs: detection_boxes, detection_scores, detection_classes, + // num_detections + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 4); + + return kTfLiteOk; +} + +class Dequantizer { +public: + Dequantizer(int zero_point, float scale) + : zero_point_(zero_point), scale_(scale) + { + } + float operator()(uint8_t x) + { + return (static_cast(x) - zero_point_) * scale_; + } + +private: + int zero_point_; + float scale_; +}; + +void DequantizeBoxEncodings(const TfLiteEvalTensor *input_box_encodings, + int idx, float quant_zero_point, float quant_scale, + int length_box_encoding, + CenterSizeEncoding *box_centersize) +{ + const uint8_t *boxes = + tflite::micro::GetTensorData(input_box_encodings) + + length_box_encoding * idx; + Dequantizer dequantize(quant_zero_point, quant_scale); + // See definition of the KeyPointBoxCoder at + // https://github.com/tensorflow/models/blob/master/research/object_detection/box_coders/keypoint_box_coder.py + // The first four elements are the box coordinates, which is the same as the + // FastRnnBoxCoder at + // https://github.com/tensorflow/models/blob/master/research/object_detection/box_coders/faster_rcnn_box_coder.py + box_centersize->y = dequantize(boxes[0]); + box_centersize->x = dequantize(boxes[1]); + box_centersize->h = dequantize(boxes[2]); + box_centersize->w = dequantize(boxes[3]); +} + +template +T ReInterpretTensor(const TfLiteEvalTensor *tensor) +{ + const float *tensor_base = tflite::micro::GetTensorData(tensor); + return reinterpret_cast(tensor_base); +} + +template +T ReInterpretTensor(TfLiteEvalTensor *tensor) +{ + float *tensor_base = tflite::micro::GetTensorData(tensor); + return reinterpret_cast(tensor_base); +} + +TfLiteStatus DecodeCenterSizeBoxes(TfLiteContext *context, TfLiteNode *node, + OpData *op_data) +{ + // Parse input tensor boxencodings + const TfLiteEvalTensor *input_box_encodings = + tflite::micro::GetEvalInput(context, node, kInputTensorBoxEncodings); + TF_LITE_ENSURE_EQ(context, input_box_encodings->dims->data[0], kBatchSize); + const int num_boxes = input_box_encodings->dims->data[1]; + TF_LITE_ENSURE(context, input_box_encodings->dims->data[2] >= kNumCoordBox); + const TfLiteEvalTensor *input_anchors = + tflite::micro::GetEvalInput(context, node, kInputTensorAnchors); + + // Decode the boxes to get (ymin, xmin, ymax, xmax) based on the anchors + CenterSizeEncoding box_centersize; + CenterSizeEncoding scale_values = op_data->scale_values; + CenterSizeEncoding anchor; + for (int idx = 0; idx < num_boxes; ++idx) { + switch (input_box_encodings->type) { + // Quantized + case kTfLiteUInt8: + DequantizeBoxEncodings( + input_box_encodings, idx, + static_cast(op_data->input_box_encodings.zero_point), + static_cast(op_data->input_box_encodings.scale), + input_box_encodings->dims->data[2], &box_centersize); + DequantizeBoxEncodings( + input_anchors, idx, + static_cast(op_data->input_anchors.zero_point), + static_cast(op_data->input_anchors.scale), kNumCoordBox, + &anchor); + break; + // Float + case kTfLiteFloat32: { + // Please see DequantizeBoxEncodings function for the support detail. + const int box_encoding_idx = idx * input_box_encodings->dims->data[2]; + const float *boxes = &(tflite::micro::GetTensorData( + input_box_encodings)[box_encoding_idx]); + box_centersize = *reinterpret_cast(boxes); + anchor = + ReInterpretTensor(input_anchors)[idx]; + break; + } + default: + // Unsupported type. + return kTfLiteError; + } + + float ycenter = static_cast(static_cast(box_centersize.y) / + static_cast(scale_values.y) * + static_cast(anchor.h) + + static_cast(anchor.y)); + + float xcenter = static_cast(static_cast(box_centersize.x) / + static_cast(scale_values.x) * + static_cast(anchor.w) + + static_cast(anchor.x)); + + float half_h = + static_cast(0.5 * + (std::exp(static_cast(box_centersize.h) / + static_cast(scale_values.h))) * + static_cast(anchor.h)); + float half_w = + static_cast(0.5 * + (std::exp(static_cast(box_centersize.w) / + static_cast(scale_values.w))) * + static_cast(anchor.w)); + + float *decoded_boxes = reinterpret_cast( + context->GetScratchBuffer(context, op_data->decoded_boxes_idx)); + auto &box = reinterpret_cast(decoded_boxes)[idx]; + box.ymin = ycenter - half_h; + box.xmin = xcenter - half_w; + box.ymax = ycenter + half_h; + box.xmax = xcenter + half_w; + } + return kTfLiteOk; +} + +void DecreasingPartialArgSort(const float *values, int num_values, + int num_to_sort, int *indices) +{ + std::iota(indices, indices + num_values, 0); + std::partial_sort( + indices, indices + num_to_sort, indices + num_values, + [&values](const int i, const int j) { return values[i] > values[j]; }); +} + +int SelectDetectionsAboveScoreThreshold(const float *values, int size, + const float threshold, + float *keep_values, int *keep_indices) +{ + int counter = 0; + for (int i = 0; i < size; i++) { + if (values[i] >= threshold) { + keep_values[counter] = values[i]; + keep_indices[counter] = i; + counter++; + } + } + return counter; +} + +bool ValidateBoxes(const float *decoded_boxes, const int num_boxes) +{ + for (int i = 0; i < num_boxes; ++i) { + // ymax>=ymin, xmax>=xmin + auto &box = reinterpret_cast(decoded_boxes)[i]; + if (box.ymin >= box.ymax || box.xmin >= box.xmax) { + return false; + } + } + return true; +} + +float ComputeIntersectionOverUnion(const float *decoded_boxes, const int i, + const int j) +{ + auto &box_i = reinterpret_cast(decoded_boxes)[i]; + auto &box_j = reinterpret_cast(decoded_boxes)[j]; + const float area_i = (box_i.ymax - box_i.ymin) * (box_i.xmax - box_i.xmin); + const float area_j = (box_j.ymax - box_j.ymin) * (box_j.xmax - box_j.xmin); + if (area_i <= 0 || area_j <= 0) + return 0.0; + const float intersection_ymin = std::max(box_i.ymin, box_j.ymin); + const float intersection_xmin = std::max(box_i.xmin, box_j.xmin); + const float intersection_ymax = std::min(box_i.ymax, box_j.ymax); + const float intersection_xmax = std::min(box_i.xmax, box_j.xmax); + const float intersection_area = + std::max(intersection_ymax - intersection_ymin, 0.0) * + std::max(intersection_xmax - intersection_xmin, 0.0); + return intersection_area / (area_i + area_j - intersection_area); +} + +// NonMaxSuppressionSingleClass() prunes out the box locations with high overlap +// before selecting the highest scoring boxes (max_detections in number) +// It assumes all boxes are good in beginning and sorts based on the scores. +// If lower-scoring box has too much overlap with a higher-scoring box, +// we get rid of the lower-scoring box. +// Complexity is O(N^2) pairwise comparison between boxes +TfLiteStatus NonMaxSuppressionSingleClassHelper( + TfLiteContext *context, TfLiteNode *node, OpData *op_data, + const float *scores, int *selected, int *selected_size, + int max_detections) +{ + const TfLiteEvalTensor *input_box_encodings = + tflite::micro::GetEvalInput(context, node, kInputTensorBoxEncodings); + const int num_boxes = input_box_encodings->dims->data[1]; + const float non_max_suppression_score_threshold = + op_data->non_max_suppression_score_threshold; + const float intersection_over_union_threshold = + op_data->intersection_over_union_threshold; + // Maximum detections should be positive. + TF_LITE_ENSURE(context, (max_detections >= 0)); + // intersection_over_union_threshold should be positive + // and should be less than 1. + TF_LITE_ENSURE(context, (intersection_over_union_threshold > 0.0f) && + (intersection_over_union_threshold <= 1.0f)); + // Validate boxes + float *decoded_boxes = reinterpret_cast( + context->GetScratchBuffer(context, op_data->decoded_boxes_idx)); + + TF_LITE_ENSURE(context, ValidateBoxes(decoded_boxes, num_boxes)); + + // threshold scores + int *keep_indices = reinterpret_cast( + context->GetScratchBuffer(context, op_data->keep_indices_idx)); + float *keep_scores = reinterpret_cast( + context->GetScratchBuffer(context, op_data->keep_scores_idx)); + int num_scores_kept = SelectDetectionsAboveScoreThreshold( + scores, num_boxes, non_max_suppression_score_threshold, keep_scores, + keep_indices); + int *sorted_indices = reinterpret_cast( + context->GetScratchBuffer(context, op_data->sorted_indices_idx)); + + DecreasingPartialArgSort(keep_scores, num_scores_kept, num_scores_kept, + sorted_indices); + + const int num_boxes_kept = num_scores_kept; + const int output_size = std::min(num_boxes_kept, max_detections); + *selected_size = 0; + + int num_active_candidate = num_boxes_kept; + uint8_t *active_box_candidate = reinterpret_cast( + context->GetScratchBuffer(context, op_data->active_candidate_idx)); + + for (int row = 0; row < num_boxes_kept; row++) { + active_box_candidate[row] = 1; + } + for (int i = 0; i < num_boxes_kept; ++i) { + if (num_active_candidate == 0 || *selected_size >= output_size) + break; + if (active_box_candidate[i] == 1) { + selected[(*selected_size)++] = keep_indices[sorted_indices[i]]; + active_box_candidate[i] = 0; + num_active_candidate--; + } else { + continue; + } + for (int j = i + 1; j < num_boxes_kept; ++j) { + if (active_box_candidate[j] == 1) { + float intersection_over_union = ComputeIntersectionOverUnion( + decoded_boxes, keep_indices[sorted_indices[i]], + keep_indices[sorted_indices[j]]); + + if (intersection_over_union > intersection_over_union_threshold) { + active_box_candidate[j] = 0; + num_active_candidate--; + } + } + } + } + + return kTfLiteOk; +} + +// This function implements a regular version of Non Maximal Suppression (NMS) +// for multiple classes where +// 1) we do NMS separately for each class across all anchors and +// 2) keep only the highest anchor scores across all classes +// 3) The worst runtime of the regular NMS is O(K*N^2) +// where N is the number of anchors and K the number of +// classes. +TfLiteStatus NonMaxSuppressionMultiClassRegularHelper(TfLiteContext *context, + TfLiteNode *node, + OpData *op_data, + const float *scores) +{ + const TfLiteEvalTensor *input_box_encodings = + tflite::micro::GetEvalInput(context, node, kInputTensorBoxEncodings); + const TfLiteEvalTensor *input_class_predictions = + tflite::micro::GetEvalInput(context, node, kInputTensorClassPredictions); + TfLiteEvalTensor *detection_boxes = + tflite::micro::GetEvalOutput(context, node, kOutputTensorDetectionBoxes); + TfLiteEvalTensor *detection_classes = tflite::micro::GetEvalOutput( + context, node, kOutputTensorDetectionClasses); + TfLiteEvalTensor *detection_scores = + tflite::micro::GetEvalOutput(context, node, kOutputTensorDetectionScores); + TfLiteEvalTensor *num_detections = + tflite::micro::GetEvalOutput(context, node, kOutputTensorNumDetections); + + const int num_boxes = input_box_encodings->dims->data[1]; + const int num_classes = op_data->num_classes; + const int num_detections_per_class = op_data->detections_per_class; + const int max_detections = op_data->max_detections; + const int num_classes_with_background = + input_class_predictions->dims->data[2]; + // The row index offset is 1 if background class is included and 0 otherwise. + int label_offset = num_classes_with_background - num_classes; + TF_LITE_ENSURE(context, num_detections_per_class > 0); + + // For each class, perform non-max suppression. + float *class_scores = reinterpret_cast( + context->GetScratchBuffer(context, op_data->score_buffer_idx)); + int *box_indices_after_regular_non_max_suppression = reinterpret_cast( + context->GetScratchBuffer(context, op_data->buffer_idx)); + float *scores_after_regular_non_max_suppression = + reinterpret_cast(context->GetScratchBuffer( + context, op_data->scores_after_regular_non_max_suppression_idx)); + + int size_of_sorted_indices = 0; + int *sorted_indices = reinterpret_cast( + context->GetScratchBuffer(context, op_data->sorted_indices_idx)); + float *sorted_values = reinterpret_cast( + context->GetScratchBuffer(context, op_data->sorted_values_idx)); + + for (int col = 0; col < num_classes; col++) { + for (int row = 0; row < num_boxes; row++) { + // Get scores of boxes corresponding to all anchors for single class + class_scores[row] = + *(scores + row * num_classes_with_background + col + label_offset); + } + // Perform non-maximal suppression on single class + int selected_size = 0; + int *selected = reinterpret_cast( + context->GetScratchBuffer(context, op_data->selected_idx)); + TF_LITE_ENSURE_STATUS(NonMaxSuppressionSingleClassHelper( + context, node, op_data, class_scores, selected, &selected_size, + num_detections_per_class)); + // Add selected indices from non-max suppression of boxes in this class + int output_index = size_of_sorted_indices; + for (int i = 0; i < selected_size; i++) { + int selected_index = selected[i]; + + box_indices_after_regular_non_max_suppression[output_index] = + (selected_index * num_classes_with_background + col + label_offset); + scores_after_regular_non_max_suppression[output_index] = + class_scores[selected_index]; + output_index++; + } + // Sort the max scores among the selected indices + // Get the indices for top scores + int num_indices_to_sort = std::min(output_index, max_detections); + DecreasingPartialArgSort(scores_after_regular_non_max_suppression, + output_index, num_indices_to_sort, sorted_indices); + + // Copy values to temporary vectors + for (int row = 0; row < num_indices_to_sort; row++) { + int temp = sorted_indices[row]; + sorted_indices[row] = box_indices_after_regular_non_max_suppression[temp]; + sorted_values[row] = scores_after_regular_non_max_suppression[temp]; + } + // Copy scores and indices from temporary vectors + for (int row = 0; row < num_indices_to_sort; row++) { + box_indices_after_regular_non_max_suppression[row] = sorted_indices[row]; + scores_after_regular_non_max_suppression[row] = sorted_values[row]; + } + size_of_sorted_indices = num_indices_to_sort; + } + + // Allocate output tensors + for (int output_box_index = 0; output_box_index < max_detections; + output_box_index++) { + if (output_box_index < size_of_sorted_indices) { + const int anchor_index = floor( + box_indices_after_regular_non_max_suppression[output_box_index] / + num_classes_with_background); + const int class_index = + box_indices_after_regular_non_max_suppression[output_box_index] - + anchor_index * num_classes_with_background - label_offset; + const float selected_score = + scores_after_regular_non_max_suppression[output_box_index]; + // detection_boxes + float *decoded_boxes = reinterpret_cast( + context->GetScratchBuffer(context, op_data->decoded_boxes_idx)); + ReInterpretTensor(detection_boxes)[output_box_index] = + reinterpret_cast(decoded_boxes)[anchor_index]; + // detection_classes + tflite::micro::GetTensorData(detection_classes)[output_box_index] = + class_index; + // detection_scores + tflite::micro::GetTensorData(detection_scores)[output_box_index] = + selected_score; + } else { + ReInterpretTensor( + detection_boxes)[output_box_index] = { 0.0f, 0.0f, 0.0f, 0.0f }; + // detection_classes + tflite::micro::GetTensorData(detection_classes)[output_box_index] = + 0.0f; + // detection_scores + tflite::micro::GetTensorData(detection_scores)[output_box_index] = + 0.0f; + } + } + tflite::micro::GetTensorData(num_detections)[0] = + size_of_sorted_indices; + + return kTfLiteOk; +} + +// This function implements a fast version of Non Maximal Suppression for +// multiple classes where +// 1) we keep the top-k scores for each anchor and +// 2) during NMS, each anchor only uses the highest class score for sorting. +// 3) Compared to standard NMS, the worst runtime of this version is O(N^2) +// instead of O(KN^2) where N is the number of anchors and K the number of +// classes. +TfLiteStatus NonMaxSuppressionMultiClassFastHelper(TfLiteContext *context, + TfLiteNode *node, + OpData *op_data, + const float *scores) +{ + const TfLiteEvalTensor *input_box_encodings = + tflite::micro::GetEvalInput(context, node, kInputTensorBoxEncodings); + const TfLiteEvalTensor *input_class_predictions = + tflite::micro::GetEvalInput(context, node, kInputTensorClassPredictions); + TfLiteEvalTensor *detection_boxes = + tflite::micro::GetEvalOutput(context, node, kOutputTensorDetectionBoxes); + + TfLiteEvalTensor *detection_classes = tflite::micro::GetEvalOutput( + context, node, kOutputTensorDetectionClasses); + TfLiteEvalTensor *detection_scores = + tflite::micro::GetEvalOutput(context, node, kOutputTensorDetectionScores); + TfLiteEvalTensor *num_detections = + tflite::micro::GetEvalOutput(context, node, kOutputTensorNumDetections); + + const int num_boxes = input_box_encodings->dims->data[1]; + const int num_classes = op_data->num_classes; + const int max_categories_per_anchor = op_data->max_classes_per_detection; + const int num_classes_with_background = + input_class_predictions->dims->data[2]; + + // The row index offset is 1 if background class is included and 0 otherwise. + int label_offset = num_classes_with_background - num_classes; + TF_LITE_ENSURE(context, (max_categories_per_anchor > 0)); + const int num_categories_per_anchor = + std::min(max_categories_per_anchor, num_classes); + float *max_scores = reinterpret_cast( + context->GetScratchBuffer(context, op_data->score_buffer_idx)); + int *sorted_class_indices = reinterpret_cast( + context->GetScratchBuffer(context, op_data->buffer_idx)); + + for (int row = 0; row < num_boxes; row++) { + const float *box_scores = + scores + row * num_classes_with_background + label_offset; + int *class_indices = sorted_class_indices + row * num_classes; + DecreasingPartialArgSort(box_scores, num_classes, num_categories_per_anchor, + class_indices); + max_scores[row] = box_scores[class_indices[0]]; + } + + // Perform non-maximal suppression on max scores + int selected_size = 0; + int *selected = reinterpret_cast( + context->GetScratchBuffer(context, op_data->selected_idx)); + TF_LITE_ENSURE_STATUS(NonMaxSuppressionSingleClassHelper( + context, node, op_data, max_scores, selected, &selected_size, + op_data->max_detections)); + + // Allocate output tensors + int output_box_index = 0; + + for (int i = 0; i < selected_size; i++) { + int selected_index = selected[i]; + + const float *box_scores = + scores + selected_index * num_classes_with_background + label_offset; + const int *class_indices = + sorted_class_indices + selected_index * num_classes; + + for (int col = 0; col < num_categories_per_anchor; ++col) { + int box_offset = num_categories_per_anchor * output_box_index + col; + + // detection_boxes + float *decoded_boxes = reinterpret_cast( + context->GetScratchBuffer(context, op_data->decoded_boxes_idx)); + ReInterpretTensor(detection_boxes)[box_offset] = + reinterpret_cast(decoded_boxes)[selected_index]; + + // detection_classes + tflite::micro::GetTensorData(detection_classes)[box_offset] = + class_indices[col]; + + // detection_scores + tflite::micro::GetTensorData(detection_scores)[box_offset] = + box_scores[class_indices[col]]; + + output_box_index++; + } + } + + tflite::micro::GetTensorData(num_detections)[0] = output_box_index; + return kTfLiteOk; +} + +void DequantizeClassPredictions(const TfLiteEvalTensor *input_class_predictions, + const int num_boxes, + const int num_classes_with_background, + float *scores, OpData *op_data) +{ + float quant_zero_point = + static_cast(op_data->input_class_predictions.zero_point); + float quant_scale = + static_cast(op_data->input_class_predictions.scale); + Dequantizer dequantize(quant_zero_point, quant_scale); + const uint8_t *scores_quant = + tflite::micro::GetTensorData(input_class_predictions); + for (int idx = 0; idx < num_boxes * num_classes_with_background; ++idx) { + scores[idx] = dequantize(scores_quant[idx]); + } +} + +TfLiteStatus NonMaxSuppressionMultiClass(TfLiteContext *context, + TfLiteNode *node, OpData *op_data) +{ + // Get the input tensors + const TfLiteEvalTensor *input_box_encodings = + tflite::micro::GetEvalInput(context, node, kInputTensorBoxEncodings); + const TfLiteEvalTensor *input_class_predictions = + tflite::micro::GetEvalInput(context, node, kInputTensorClassPredictions); + const int num_boxes = input_box_encodings->dims->data[1]; + const int num_classes = op_data->num_classes; + + TF_LITE_ENSURE_EQ(context, input_class_predictions->dims->data[0], + kBatchSize); + TF_LITE_ENSURE_EQ(context, input_class_predictions->dims->data[1], num_boxes); + const int num_classes_with_background = + input_class_predictions->dims->data[2]; + + TF_LITE_ENSURE(context, (num_classes_with_background - num_classes <= 1)); + TF_LITE_ENSURE(context, (num_classes_with_background >= num_classes)); + + const float *scores; + switch (input_class_predictions->type) { + case kTfLiteUInt8: { + float *temporary_scores = reinterpret_cast( + context->GetScratchBuffer(context, op_data->scores_idx)); + DequantizeClassPredictions(input_class_predictions, num_boxes, + num_classes_with_background, temporary_scores, + op_data); + scores = temporary_scores; + } break; + case kTfLiteFloat32: + scores = tflite::micro::GetTensorData(input_class_predictions); + break; + default: + // Unsupported type. + return kTfLiteError; + } + + if (op_data->use_regular_non_max_suppression) { + TF_LITE_ENSURE_STATUS(NonMaxSuppressionMultiClassRegularHelper( + context, node, op_data, scores)); + } else { + TF_LITE_ENSURE_STATUS( + NonMaxSuppressionMultiClassFastHelper(context, node, op_data, scores)); + } + + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE(context, (kBatchSize == 1)); + auto *op_data = static_cast(node->user_data); + + // These two functions correspond to two blocks in the Object Detection model. + // In future, we would like to break the custom op in two blocks, which is + // currently not feasible because we would like to input quantized inputs + // and do all calculations in float. Mixed quantized/float calculations are + // currently not supported in TFLite. + + // This fills in temporary decoded_boxes + // by transforming input_box_encodings and input_anchors from + // CenterSizeEncodings to BoxCornerEncoding + TF_LITE_ENSURE_STATUS(DecodeCenterSizeBoxes(context, node, op_data)); + + // This fills in the output tensors + // by choosing effective set of decoded boxes + // based on Non Maximal Suppression, i.e. selecting + // highest scoring non-overlapping boxes. + TF_LITE_ENSURE_STATUS(NonMaxSuppressionMultiClass(context, node, op_data)); + + return kTfLiteOk; +} +} // namespace + +TfLiteRegistration *Register_DETECTION_POSTPROCESS() +{ + static TfLiteRegistration r = { /*init=*/Init, + /*free=*/Free, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; + return &r; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/detection_postprocess_flexbuffers_generated_data.cc b/components/tflite/tensorflow/lite/micro/kernels/detection_postprocess_flexbuffers_generated_data.cc new file mode 100644 index 00000000..9f05f66c --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/detection_postprocess_flexbuffers_generated_data.cc @@ -0,0 +1,510 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// This file is generated. See: +// tensorflow/lite/micro/kernels/detection_postprocess_test/README.md + +#include "tensorflow/lite/micro/kernels/detection_postprocess_flexbuffers_generated_data.h" + +const int g_gen_data_size_none_regular_nms = 242; +const unsigned char g_gen_data_none_regular_nms[] = { + 0x6d, + 0x61, + 0x78, + 0x5f, + 0x64, + 0x65, + 0x74, + 0x65, + 0x63, + 0x74, + 0x69, + 0x6f, + 0x6e, + 0x73, + 0x00, + 0x6d, + 0x61, + 0x78, + 0x5f, + 0x63, + 0x6c, + 0x61, + 0x73, + 0x73, + 0x65, + 0x73, + 0x5f, + 0x70, + 0x65, + 0x72, + 0x5f, + 0x64, + 0x65, + 0x74, + 0x65, + 0x63, + 0x74, + 0x69, + 0x6f, + 0x6e, + 0x00, + 0x64, + 0x65, + 0x74, + 0x65, + 0x63, + 0x74, + 0x69, + 0x6f, + 0x6e, + 0x73, + 0x5f, + 0x70, + 0x65, + 0x72, + 0x5f, + 0x63, + 0x6c, + 0x61, + 0x73, + 0x73, + 0x00, + 0x75, + 0x73, + 0x65, + 0x5f, + 0x72, + 0x65, + 0x67, + 0x75, + 0x6c, + 0x61, + 0x72, + 0x5f, + 0x6e, + 0x6d, + 0x73, + 0x00, + 0x6e, + 0x6d, + 0x73, + 0x5f, + 0x73, + 0x63, + 0x6f, + 0x72, + 0x65, + 0x5f, + 0x74, + 0x68, + 0x72, + 0x65, + 0x73, + 0x68, + 0x6f, + 0x6c, + 0x64, + 0x00, + 0x6e, + 0x6d, + 0x73, + 0x5f, + 0x69, + 0x6f, + 0x75, + 0x5f, + 0x74, + 0x68, + 0x72, + 0x65, + 0x73, + 0x68, + 0x6f, + 0x6c, + 0x64, + 0x00, + 0x6e, + 0x75, + 0x6d, + 0x5f, + 0x63, + 0x6c, + 0x61, + 0x73, + 0x73, + 0x65, + 0x73, + 0x00, + 0x79, + 0x5f, + 0x73, + 0x63, + 0x61, + 0x6c, + 0x65, + 0x00, + 0x78, + 0x5f, + 0x73, + 0x63, + 0x61, + 0x6c, + 0x65, + 0x00, + 0x68, + 0x5f, + 0x73, + 0x63, + 0x61, + 0x6c, + 0x65, + 0x00, + 0x77, + 0x5f, + 0x73, + 0x63, + 0x61, + 0x6c, + 0x65, + 0x00, + 0x0b, + 0x78, + 0x12, + 0x94, + 0xa4, + 0x43, + 0x58, + 0x33, + 0x6a, + 0x11, + 0x22, + 0x2b, + 0x0b, + 0x00, + 0x00, + 0x00, + 0x01, + 0x00, + 0x00, + 0x00, + 0x0b, + 0x00, + 0x00, + 0x00, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0xa0, + 0x40, + 0x01, + 0x00, + 0x00, + 0x00, + 0x03, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x3f, + 0x00, + 0x00, + 0x00, + 0x00, + 0x02, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0xa0, + 0x40, + 0x00, + 0x00, + 0x20, + 0x41, + 0x00, + 0x00, + 0x20, + 0x41, + 0x06, + 0x0e, + 0x06, + 0x06, + 0x0e, + 0x0e, + 0x06, + 0x6a, + 0x0e, + 0x0e, + 0x0e, + 0x37, + 0x26, + 0x01, +}; +const int g_gen_data_size_regular_nms = 242; +const unsigned char g_gen_data_regular_nms[] = { + 0x6d, + 0x61, + 0x78, + 0x5f, + 0x64, + 0x65, + 0x74, + 0x65, + 0x63, + 0x74, + 0x69, + 0x6f, + 0x6e, + 0x73, + 0x00, + 0x6d, + 0x61, + 0x78, + 0x5f, + 0x63, + 0x6c, + 0x61, + 0x73, + 0x73, + 0x65, + 0x73, + 0x5f, + 0x70, + 0x65, + 0x72, + 0x5f, + 0x64, + 0x65, + 0x74, + 0x65, + 0x63, + 0x74, + 0x69, + 0x6f, + 0x6e, + 0x00, + 0x64, + 0x65, + 0x74, + 0x65, + 0x63, + 0x74, + 0x69, + 0x6f, + 0x6e, + 0x73, + 0x5f, + 0x70, + 0x65, + 0x72, + 0x5f, + 0x63, + 0x6c, + 0x61, + 0x73, + 0x73, + 0x00, + 0x75, + 0x73, + 0x65, + 0x5f, + 0x72, + 0x65, + 0x67, + 0x75, + 0x6c, + 0x61, + 0x72, + 0x5f, + 0x6e, + 0x6d, + 0x73, + 0x00, + 0x6e, + 0x6d, + 0x73, + 0x5f, + 0x73, + 0x63, + 0x6f, + 0x72, + 0x65, + 0x5f, + 0x74, + 0x68, + 0x72, + 0x65, + 0x73, + 0x68, + 0x6f, + 0x6c, + 0x64, + 0x00, + 0x6e, + 0x6d, + 0x73, + 0x5f, + 0x69, + 0x6f, + 0x75, + 0x5f, + 0x74, + 0x68, + 0x72, + 0x65, + 0x73, + 0x68, + 0x6f, + 0x6c, + 0x64, + 0x00, + 0x6e, + 0x75, + 0x6d, + 0x5f, + 0x63, + 0x6c, + 0x61, + 0x73, + 0x73, + 0x65, + 0x73, + 0x00, + 0x79, + 0x5f, + 0x73, + 0x63, + 0x61, + 0x6c, + 0x65, + 0x00, + 0x78, + 0x5f, + 0x73, + 0x63, + 0x61, + 0x6c, + 0x65, + 0x00, + 0x68, + 0x5f, + 0x73, + 0x63, + 0x61, + 0x6c, + 0x65, + 0x00, + 0x77, + 0x5f, + 0x73, + 0x63, + 0x61, + 0x6c, + 0x65, + 0x00, + 0x0b, + 0x78, + 0x12, + 0x94, + 0xa4, + 0x43, + 0x58, + 0x33, + 0x6a, + 0x11, + 0x22, + 0x2b, + 0x0b, + 0x00, + 0x00, + 0x00, + 0x01, + 0x00, + 0x00, + 0x00, + 0x0b, + 0x00, + 0x00, + 0x00, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0xa0, + 0x40, + 0x01, + 0x00, + 0x00, + 0x00, + 0x03, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x3f, + 0x00, + 0x00, + 0x00, + 0x00, + 0x02, + 0x00, + 0x00, + 0x00, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0xa0, + 0x40, + 0x00, + 0x00, + 0x20, + 0x41, + 0x00, + 0x00, + 0x20, + 0x41, + 0x06, + 0x0e, + 0x06, + 0x06, + 0x0e, + 0x0e, + 0x06, + 0x6a, + 0x0e, + 0x0e, + 0x0e, + 0x37, + 0x26, + 0x01, +}; diff --git a/components/tflite/tensorflow/lite/micro/kernels/detection_postprocess_flexbuffers_generated_data.h b/components/tflite/tensorflow/lite/micro/kernels/detection_postprocess_flexbuffers_generated_data.h new file mode 100644 index 00000000..f5b9eae0 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/detection_postprocess_flexbuffers_generated_data.h @@ -0,0 +1,25 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_KERNELS_FLEXBUFFERS_GENERATED_DATA_H +#define TENSORFLOW_LITE_MICRO_KERNELS_FLEXBUFFERS_GENERATED_DATA_H + +extern const int g_gen_data_size_none_regular_nms; +extern const unsigned char g_gen_data_none_regular_nms[]; + +extern const int g_gen_data_size_regular_nms; +extern const unsigned char g_gen_data_regular_nms[]; + +#endif diff --git a/components/tflite/tensorflow/lite/micro/kernels/detection_postprocess_test.cc b/components/tflite/tensorflow/lite/micro/kernels/detection_postprocess_test.cc new file mode 100644 index 00000000..97eef858 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/detection_postprocess_test.cc @@ -0,0 +1,472 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "flatbuffers/flexbuffers.h" +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +// See: tensorflow/lite/micro/kernels/detection_postprocess_test/README.md +#include "tensorflow/lite/micro/kernels/detection_postprocess_flexbuffers_generated_data.h" + +namespace tflite { +namespace testing { +namespace { + +// Common inputs and outputs. + +int kInputShape1[] = { 3, 1, 6, 4 }; +int kInputShape2[] = { 3, 1, 6, 3 }; +int kInputShape3[] = { 2, 6, 4 }; +int kOutputShape1[] = { 3, 1, 3, 4 }; +int kOutputShape2[] = { 2, 1, 3 }; +int kOutputShape3[] = { 2, 1, 3 }; +int kOutputShape4[] = { 1, 1 }; + +// six boxes in center-size encoding +constexpr float kInputData1[] = { + 0.0, 0.0, 0.0, 0.0, // box #1 + 0.0, 1.0, 0.0, 0.0, // box #2 + 0.0, -1.0, 0.0, 0.0, // box #3 + 0.0, 0.0, 0.0, 0.0, // box #4 + 0.0, 1.0, 0.0, 0.0, // box #5 + 0.0, 0.0, 0.0, 0.0 // box #6 +}; + +// class scores - two classes with background +constexpr float kInputData2[] = { 0., .9, .8, 0., .75, .72, 0., .6, .5, + 0., .93, .95, 0., .5, .4, 0., .3, .2 }; + +// six anchors in center-size encoding +constexpr float kInputData3[] = { + 0.5, 0.5, 1.0, 1.0, // anchor #1 + 0.5, 0.5, 1.0, 1.0, // anchor #2 + 0.5, 0.5, 1.0, 1.0, // anchor #3 + 0.5, 10.5, 1.0, 1.0, // anchor #4 + 0.5, 10.5, 1.0, 1.0, // anchor #5 + 0.5, 100.5, 1.0, 1.0 // anchor #6 +}; +// Same boxes in box-corner encoding: +// { 0.0, 0.0, 1.0, 1.0, +// 0.0, 0.1, 1.0, 1.1, +// 0.0, -0.1, 1.0, 0.9, +// 0.0, 10.0, 1.0, 11.0, +// 0.0, 10.1, 1.0, 11.1, +// 0.0, 100.0, 1.0, 101.0} + +constexpr float kGolden1[] = { 0.0, 10.0, 1.0, 11.0, 0.0, 0.0, + 1.0, 1.0, 0.0, 100.0, 1.0, 101.0 }; +constexpr float kGolden2[] = { 1, 0, 0 }; +constexpr float kGolden3[] = { 0.95, 0.9, 0.3 }; +constexpr float kGolden4[] = { 3.0 }; + +void TestDetectionPostprocess( + int *input_dims_data1, const float *input_data1, int *input_dims_data2, + const float *input_data2, int *input_dims_data3, const float *input_data3, + int *output_dims_data1, float *output_data1, int *output_dims_data2, + float *output_data2, int *output_dims_data3, float *output_data3, + int *output_dims_data4, float *output_data4, const float *golden1, + const float *golden2, const float *golden3, const float *golden4, + const float tolerance, bool use_regular_nms, + uint8_t *input_data_quantized1 = nullptr, + uint8_t *input_data_quantized2 = nullptr, + uint8_t *input_data_quantized3 = nullptr, const float input_min1 = 0, + const float input_max1 = 0, const float input_min2 = 0, + const float input_max2 = 0, const float input_min3 = 0, + const float input_max3 = 0) +{ + TfLiteIntArray *input_dims1 = IntArrayFromInts(input_dims_data1); + TfLiteIntArray *input_dims2 = IntArrayFromInts(input_dims_data2); + TfLiteIntArray *input_dims3 = IntArrayFromInts(input_dims_data3); + TfLiteIntArray *output_dims1 = IntArrayFromInts(output_dims_data1); + TfLiteIntArray *output_dims2 = IntArrayFromInts(output_dims_data2); + TfLiteIntArray *output_dims3 = IntArrayFromInts(output_dims_data3); + TfLiteIntArray *output_dims4 = IntArrayFromInts(output_dims_data4); + + constexpr int inputs_size = 3; + constexpr int outputs_size = 4; + constexpr int tensors_size = inputs_size + outputs_size; + + TfLiteTensor tensors[tensors_size]; + if (input_min1 != 0 || input_max1 != 0 || input_min2 != 0 || + input_max2 != 0 || input_min3 != 0 || input_max3 != 0) { + const float input_scale1 = ScaleFromMinMax(input_min1, input_max1); + const int input_zero_point1 = + ZeroPointFromMinMax(input_min1, input_max1); + const float input_scale2 = ScaleFromMinMax(input_min2, input_max2); + const int input_zero_point2 = + ZeroPointFromMinMax(input_min2, input_max2); + const float input_scale3 = ScaleFromMinMax(input_min3, input_max3); + const int input_zero_point3 = + ZeroPointFromMinMax(input_min3, input_max3); + + tensors[0] = + CreateQuantizedTensor(input_data1, input_data_quantized1, input_dims1, + input_scale1, input_zero_point1); + tensors[1] = + CreateQuantizedTensor(input_data2, input_data_quantized2, input_dims2, + input_scale2, input_zero_point2); + tensors[2] = + CreateQuantizedTensor(input_data3, input_data_quantized3, input_dims3, + input_scale3, input_zero_point3); + } else { + tensors[0] = CreateTensor(input_data1, input_dims1); + tensors[1] = CreateTensor(input_data2, input_dims2); + tensors[2] = CreateTensor(input_data3, input_dims3); + } + tensors[3] = CreateTensor(output_data1, output_dims1); + tensors[4] = CreateTensor(output_data2, output_dims2); + tensors[5] = CreateTensor(output_data3, output_dims3); + tensors[6] = CreateTensor(output_data4, output_dims4); + + ::tflite::AllOpsResolver resolver; + const TfLiteRegistration *registration = + resolver.FindOp("TFLite_Detection_PostProcess"); + TF_LITE_MICRO_EXPECT_NE(nullptr, registration); + + int inputs_array_data[] = { 3, 0, 1, 2 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 4, 3, 4, 5, 6 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + micro::KernelRunner runner(*registration, tensors, tensors_size, inputs_array, + outputs_array, nullptr); + + // Using generated data as input to operator. + int data_size = 0; + const unsigned char *init_data = nullptr; + if (use_regular_nms) { + init_data = g_gen_data_regular_nms; + data_size = g_gen_data_size_regular_nms; + } else { + init_data = g_gen_data_none_regular_nms; + data_size = g_gen_data_size_none_regular_nms; + } + + // TfLite uses a char* for the raw bytes whereas flexbuffers use an unsigned + // char*. This small discrepancy results in compiler warnings unless we + // reinterpret_cast right before passing in the flexbuffer bytes to the + // KernelRunner. + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, runner.InitAndPrepare(reinterpret_cast(init_data), + data_size)); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + int output_elements_count1 = ElementCount(*tensors[3].dims); + int output_elements_count2 = ElementCount(*tensors[4].dims); + int output_elements_count3 = ElementCount(*tensors[5].dims); + int output_elements_count4 = ElementCount(*tensors[6].dims); + + for (int i = 0; i < output_elements_count1; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(golden1[i], output_data1[i], tolerance); + } + for (int i = 0; i < output_elements_count2; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(golden2[i], output_data2[i], tolerance); + } + for (int i = 0; i < output_elements_count3; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(golden3[i], output_data3[i], tolerance); + } + for (int i = 0; i < output_elements_count4; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(golden4[i], output_data4[i], tolerance); + } +} +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(DetectionPostprocessFloatFastNMS) +{ + float output_data1[12]; + float output_data2[3]; + float output_data3[3]; + float output_data4[1]; + + tflite::testing::TestDetectionPostprocess( + tflite::testing::kInputShape1, tflite::testing::kInputData1, + tflite::testing::kInputShape2, tflite::testing::kInputData2, + tflite::testing::kInputShape3, tflite::testing::kInputData3, + tflite::testing::kOutputShape1, output_data1, + tflite::testing::kOutputShape2, output_data2, + tflite::testing::kOutputShape3, output_data3, + tflite::testing::kOutputShape4, output_data4, tflite::testing::kGolden1, + tflite::testing::kGolden2, tflite::testing::kGolden3, + tflite::testing::kGolden4, + /* tolerance */ 0, /* Use regular NMS: */ false); +} + +TF_LITE_MICRO_TEST(DetectionPostprocessQuantizedFastNMS) +{ + int kInputShape1[] = { 3, 1, 6, 4 }; + int kInputShape2[] = { 3, 1, 6, 3 }; + int kInputShape3[] = { 2, 6, 4 }; + int kOutputShape1[] = { 3, 1, 3, 4 }; + int kOutputShape2[] = { 2, 1, 3 }; + int kOutputShape3[] = { 2, 1, 3 }; + int kOutputShape4[] = { 1, 1 }; + + float output_data1[12]; + float output_data2[3]; + float output_data3[3]; + float output_data4[1]; + constexpr int kInputElements1 = + 1 * 6 * + 4; // tflite::testing::kInputShape1[1] * tflite::testing::kInputShape1[2] + // * tflite::testing::kInputShape1[3]; + constexpr int kInputElements2 = + 1 * 6 * + 3; // tflite::testing::kInputShape2[1] * tflite::testing::kInputShape2[2] + // * tflite::testing::kInputShape2[3]; + constexpr int kInputElements3 = 6 * 4; // tflite::testing::kInputShape3[1] * + // tflite::testing::kInputShape3[2]; + + uint8_t input_data_quantized1[kInputElements1]; + uint8_t input_data_quantized2[kInputElements2]; + uint8_t input_data_quantized3[kInputElements3]; + + tflite::testing::TestDetectionPostprocess( + kInputShape1, tflite::testing::kInputData1, kInputShape2, + tflite::testing::kInputData2, kInputShape3, tflite::testing::kInputData3, + kOutputShape1, output_data1, kOutputShape2, output_data2, kOutputShape3, + output_data3, kOutputShape4, output_data4, tflite::testing::kGolden1, + tflite::testing::kGolden2, tflite::testing::kGolden3, + tflite::testing::kGolden4, + /* tolerance */ 3e-1, /* Use regular NMS: */ false, input_data_quantized1, + input_data_quantized2, input_data_quantized3, + /* input1 min/max*/ -1.0, 1.0, /* input2 min/max */ 0.0, 1.0, + /* input3 min/max */ 0.0, 100.5); +} + +TF_LITE_MICRO_TEST(DetectionPostprocessFloatRegularNMS) +{ + float output_data1[12]; + float output_data2[3]; + float output_data3[3]; + float output_data4[1]; + const float kGolden1[] = { 0.0, 10.0, 1.0, 11.0, 0.0, 10.0, + 1.0, 11.0, 0.0, 0.0, 0.0, 0.0 }; + const float kGolden3[] = { 0.95, 0.9, 0.0 }; + const float kGolden4[] = { 2.0 }; + + tflite::testing::TestDetectionPostprocess( + tflite::testing::kInputShape1, tflite::testing::kInputData1, + tflite::testing::kInputShape2, tflite::testing::kInputData2, + tflite::testing::kInputShape3, tflite::testing::kInputData3, + tflite::testing::kOutputShape1, output_data1, + tflite::testing::kOutputShape2, output_data2, + tflite::testing::kOutputShape3, output_data3, + tflite::testing::kOutputShape4, output_data4, kGolden1, + tflite::testing::kGolden2, kGolden3, kGolden4, + /* tolerance */ 1e-1, /* Use regular NMS: */ true); +} + +TF_LITE_MICRO_TEST(DetectionPostprocessQuantizedRegularNMS) +{ + float output_data1[12]; + float output_data2[3]; + float output_data3[3]; + float output_data4[1]; + + constexpr int kInputElements1 = + 1 * 6 * + 4; // tflite::testing::kInputShape1[1] * tflite::testing::kInputShape1[2] + // * tflite::testing::kInputShape1[3]; + constexpr int kInputElements2 = + 1 * 6 * + 3; // tflite::testing::kInputShape2[1] * tflite::testing::kInputShape2[2] + // * tflite::testing::kInputShape2[3]; + constexpr int kInputElements3 = + 6 * 4; // tflite::testing::kInputShape3[1] * + // tflite::testing::kInputShape3[2]; + + uint8_t input_data_quantized1[kInputElements1]; + uint8_t input_data_quantized2[kInputElements2]; + uint8_t input_data_quantized3[kInputElements3]; + + const float kGolden1[] = { 0.0, 10.0, 1.0, 11.0, 0.0, 10.0, + 1.0, 11.0, 0.0, 0.0, 0.0, 0.0 }; + const float kGolden3[] = { 0.95, 0.9, 0.0 }; + const float kGolden4[] = { 2.0 }; + + tflite::testing::TestDetectionPostprocess( + tflite::testing::kInputShape1, tflite::testing::kInputData1, + tflite::testing::kInputShape2, tflite::testing::kInputData2, + tflite::testing::kInputShape3, tflite::testing::kInputData3, + tflite::testing::kOutputShape1, output_data1, + tflite::testing::kOutputShape2, output_data2, + tflite::testing::kOutputShape3, output_data3, + tflite::testing::kOutputShape4, output_data4, kGolden1, + tflite::testing::kGolden2, kGolden3, kGolden4, + /* tolerance */ 3e-1, /* Use regular NMS: */ true, input_data_quantized1, + input_data_quantized2, input_data_quantized3, + /* input1 min/max*/ -1.0, 1.0, /* input2 min/max */ 0.0, 1.0, + /* input3 min/max */ 0.0, 100.5); +} + +TF_LITE_MICRO_TEST( + DetectionPostprocessFloatFastNMSwithNoBackgroundClassAndKeypoints) +{ + int kInputShape1[] = { 3, 1, 6, 5 }; + int kInputShape2[] = { 3, 1, 6, 2 }; + + // six boxes in center-size encoding + const float kInputData1[] = { + 0.0, 0.0, 0.0, 0.0, 1.0, // box #1 + 0.0, 1.0, 0.0, 0.0, 1.0, // box #2 + 0.0, -1.0, 0.0, 0.0, 1.0, // box #3 + 0.0, 0.0, 0.0, 0.0, 1.0, // box #4 + 0.0, 1.0, 0.0, 0.0, 1.0, // box #5 + 0.0, 0.0, 0.0, 0.0, 1.0, // box #6 + }; + + // class scores - two classes without background + const float kInputData2[] = { .9, .8, .75, .72, .6, .5, + .93, .95, .5, .4, .3, .2 }; + + float output_data1[12]; + float output_data2[3]; + float output_data3[3]; + float output_data4[1]; + + tflite::testing::TestDetectionPostprocess( + kInputShape1, kInputData1, kInputShape2, kInputData2, + tflite::testing::kInputShape3, tflite::testing::kInputData3, + tflite::testing::kOutputShape1, output_data1, + tflite::testing::kOutputShape2, output_data2, + tflite::testing::kOutputShape3, output_data3, + tflite::testing::kOutputShape4, output_data4, tflite::testing::kGolden1, + tflite::testing::kGolden2, tflite::testing::kGolden3, + tflite::testing::kGolden4, + /* tolerance */ 0, /* Use regular NMS: */ false); +} + +TF_LITE_MICRO_TEST( + DetectionPostprocessFloatRegularNMSwithNoBackgroundClassAndKeypoints) +{ + int kInputShape2[] = { 3, 1, 6, 2 }; + + // class scores - two classes without background + const float kInputData2[] = { .9, .8, .75, .72, .6, .5, + .93, .95, .5, .4, .3, .2 }; + + const float kGolden1[] = { 0.0, 10.0, 1.0, 11.0, 0.0, 10.0, + 1.0, 11.0, 0.0, 0.0, 0.0, 0.0 }; + const float kGolden3[] = { 0.95, 0.9, 0.0 }; + const float kGolden4[] = { 2.0 }; + + float output_data1[12]; + float output_data2[3]; + float output_data3[3]; + float output_data4[1]; + + tflite::testing::TestDetectionPostprocess( + tflite::testing::kInputShape1, tflite::testing::kInputData1, kInputShape2, + kInputData2, tflite::testing::kInputShape3, tflite::testing::kInputData3, + tflite::testing::kOutputShape1, output_data1, + tflite::testing::kOutputShape2, output_data2, + tflite::testing::kOutputShape3, output_data3, + tflite::testing::kOutputShape4, output_data4, kGolden1, + tflite::testing::kGolden2, kGolden3, kGolden4, + /* tolerance */ 1e-1, /* Use regular NMS: */ true); +} + +TF_LITE_MICRO_TEST( + DetectionPostprocessFloatFastNMSWithBackgroundClassAndKeypoints) +{ + int kInputShape1[] = { 3, 1, 6, 5 }; + + // six boxes in center-size encoding + const float kInputData1[] = { + 0.0, 0.0, 0.0, 0.0, 1.0, // box #1 + 0.0, 1.0, 0.0, 0.0, 1.0, // box #2 + 0.0, -1.0, 0.0, 0.0, 1.0, // box #3 + 0.0, 0.0, 0.0, 0.0, 1.0, // box #4 + 0.0, 1.0, 0.0, 0.0, 1.0, // box #5 + 0.0, 0.0, 0.0, 0.0, 1.0, // box #6 + }; + + float output_data1[12]; + float output_data2[3]; + float output_data3[3]; + float output_data4[1]; + + tflite::testing::TestDetectionPostprocess( + kInputShape1, kInputData1, tflite::testing::kInputShape2, + tflite::testing::kInputData2, tflite::testing::kInputShape3, + tflite::testing::kInputData3, tflite::testing::kOutputShape1, + output_data1, tflite::testing::kOutputShape2, output_data2, + tflite::testing::kOutputShape3, output_data3, + tflite::testing::kOutputShape4, output_data4, tflite::testing::kGolden1, + tflite::testing::kGolden2, tflite::testing::kGolden3, + tflite::testing::kGolden4, + /* tolerance */ 0, /* Use regular NMS: */ false); +} + +TF_LITE_MICRO_TEST( + DetectionPostprocessQuantizedFastNMSwithNoBackgroundClassAndKeypoints) +{ + int kInputShape1[] = { 3, 1, 6, 5 }; + int kInputShape2[] = { 3, 1, 6, 2 }; + + // six boxes in center-size encoding + const float kInputData1[] = { + 0.0, 0.0, 0.0, 0.0, 1.0, // box #1 + 0.0, 1.0, 0.0, 0.0, 1.0, // box #2 + 0.0, -1.0, 0.0, 0.0, 1.0, // box #3 + 0.0, 0.0, 0.0, 0.0, 1.0, // box #4 + 0.0, 1.0, 0.0, 0.0, 1.0, // box #5 + 0.0, 0.0, 0.0, 0.0, 1.0, // box #6 + }; + + // class scores - two classes without background + const float kInputData2[] = { .9, .8, .75, .72, .6, .5, + .93, .95, .5, .4, .3, .2 }; + + constexpr int kInputElements1 = + 1 * 6 * 5; // kInputShape1[1] * kInputShape1[2] * kInputShape1[3]; + constexpr int kInputElements2 = + 1 * 6 * 2; // kInputShape2[1] * kInputShape2[2] * kInputShape2[3]; + constexpr int kInputElements3 = 6 * 4; // tflite::testing::kInputShape3[1] * + // tflite::testing::kInputShape3[2]; + + uint8_t input_data_quantized1[kInputElements1]; + uint8_t input_data_quantized2[kInputElements2]; + uint8_t input_data_quantized3[kInputElements3]; + + float output_data1[12]; + float output_data2[3]; + float output_data3[3]; + float output_data4[1]; + + tflite::testing::TestDetectionPostprocess( + kInputShape1, kInputData1, kInputShape2, kInputData2, + tflite::testing::kInputShape3, tflite::testing::kInputData3, + tflite::testing::kOutputShape1, output_data1, + tflite::testing::kOutputShape2, output_data2, + tflite::testing::kOutputShape3, output_data3, + tflite::testing::kOutputShape4, output_data4, tflite::testing::kGolden1, + tflite::testing::kGolden2, tflite::testing::kGolden3, + tflite::testing::kGolden4, + /* tolerance */ 3e-1, /* Use regular NMS: */ false, input_data_quantized1, + input_data_quantized2, input_data_quantized3, + /* input1 min/max*/ -1.0, 1.0, /* input2 min/max */ 0.0, 1.0, + /* input3 min/max */ 0.0, 100.5); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/elementwise.cc b/components/tflite/tensorflow/lite/micro/kernels/elementwise.cc new file mode 100644 index 00000000..4b704efa --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/elementwise.cc @@ -0,0 +1,236 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/micro_utils.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace elementwise { +namespace { + +bool IsNumericSupportedType(const TfLiteType type) +{ + return type == kTfLiteFloat32; +} + +bool IsLogicalSupportedType(const TfLiteType type) +{ + return type == kTfLiteBool; +} + +typedef bool (*IsSupportedType)(TfLiteType); +template +TfLiteStatus GenericPrepare(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + const TfLiteTensor *input = GetInput(context, node, 0); + TF_LITE_ENSURE(context, input != nullptr); + TfLiteTensor *output = GetOutput(context, node, 0); + TF_LITE_ENSURE(context, output != nullptr); + TF_LITE_ENSURE_TYPES_EQ(context, input->type, output->type); + if (!IsSupportedType(input->type)) { + TF_LITE_KERNEL_LOG(context, "Input data type %s (%d) is not supported.", + TfLiteTypeGetName(input->type), input->type); + return kTfLiteError; + } + return kTfLiteOk; +} + +template +inline TfLiteStatus EvalImpl(TfLiteContext *context, TfLiteNode *node, + T func(T), TfLiteType expected_type) +{ + const TfLiteEvalTensor *input = tflite::micro::GetEvalInput(context, node, 0); + TfLiteEvalTensor *output = tflite::micro::GetEvalOutput(context, node, 0); + TF_LITE_ENSURE_TYPES_EQ(context, input->type, expected_type); + const size_t num_elements = ElementCount(*input->dims); + const T *in_data = tflite::micro::GetTensorData(input); + T *out_data = tflite::micro::GetTensorData(output); + for (size_t i = 0; i < num_elements; ++i) { + out_data[i] = func(in_data[i]); + } + return kTfLiteOk; +} + +inline TfLiteStatus EvalNumeric(TfLiteContext *context, TfLiteNode *node, + float float_func(float)) +{ + return EvalImpl(context, node, float_func, kTfLiteFloat32); +} + +inline TfLiteStatus EvalLogical(TfLiteContext *context, TfLiteNode *node, + bool bool_func(bool)) +{ + return EvalImpl(context, node, bool_func, kTfLiteBool); +} + +TfLiteStatus AbsEval(TfLiteContext *context, TfLiteNode *node) +{ + return EvalNumeric(context, node, std::abs); +} + +TfLiteStatus SinEval(TfLiteContext *context, TfLiteNode *node) +{ + return EvalNumeric(context, node, std::sin); +} + +TfLiteStatus CosEval(TfLiteContext *context, TfLiteNode *node) +{ + return EvalNumeric(context, node, std::cos); +} + +TfLiteStatus LogEval(TfLiteContext *context, TfLiteNode *node) +{ + return EvalNumeric(context, node, std::log); +} + +TfLiteStatus SqrtEval(TfLiteContext *context, TfLiteNode *node) +{ + return EvalNumeric(context, node, std::sqrt); +} + +TfLiteStatus RsqrtEval(TfLiteContext *context, TfLiteNode *node) +{ + return EvalNumeric(context, node, [](float f) { return 1.f / std::sqrt(f); }); +} + +TfLiteStatus SquareEval(TfLiteContext *context, TfLiteNode *node) +{ + return EvalNumeric(context, node, [](float f) { return f * f; }); +} + +TfLiteStatus LogicalNotEval(TfLiteContext *context, TfLiteNode *node) +{ + return EvalLogical(context, node, [](bool v) { return !v; }); +} + +} // namespace +} // namespace elementwise + +TfLiteRegistration Register_ABS() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/ + elementwise::GenericPrepare, + /*invoke=*/elementwise::AbsEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +TfLiteRegistration Register_SIN() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/ + elementwise::GenericPrepare, + /*invoke=*/elementwise::SinEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +TfLiteRegistration Register_COS() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/ + elementwise::GenericPrepare, + /*invoke=*/elementwise::CosEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +TfLiteRegistration Register_LOG() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/ + elementwise::GenericPrepare, + /*invoke=*/elementwise::LogEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +TfLiteRegistration Register_SQRT() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/ + elementwise::GenericPrepare, + /*invoke=*/elementwise::SqrtEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +TfLiteRegistration Register_RSQRT() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/ + elementwise::GenericPrepare, + /*invoke=*/elementwise::RsqrtEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +TfLiteRegistration Register_SQUARE() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/ + elementwise::GenericPrepare, + /*invoke=*/elementwise::SquareEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +TfLiteRegistration Register_LOGICAL_NOT() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/ + elementwise::GenericPrepare, + /*invoke=*/elementwise::LogicalNotEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/elementwise_test.cc b/components/tflite/tensorflow/lite/micro/kernels/elementwise_test.cc new file mode 100644 index 00000000..9f92d324 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/elementwise_test.cc @@ -0,0 +1,202 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/debug_log.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { + +void TestElementwiseFloat(const TfLiteRegistration ®istration, + int *input_dims_data, const float *input_data, + int *output_dims_data, + const float *expected_output_data, + float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int input_size = 1; + constexpr int output_size = 1; + constexpr int tensors_size = input_size + output_size; + TfLiteTensor tensors[tensors_size] = { CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims) }; + + // Place a unique value in the uninitialized output buffer. + for (int i = 0; i < output_dims_count; ++i) { + output_data[i] = 23; + } + + static int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + static int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output_data[i], output_data[i], 1e-5f); + } +} + +void TestElementwiseBool(const TfLiteRegistration ®istration, + int *input_dims_data, const bool *input_data, + int *output_dims_data, + const bool *expected_output_data, bool *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int input_size = 1; + constexpr int output_size = 1; + constexpr int tensors_size = input_size + output_size; + TfLiteTensor tensors[tensors_size] = { CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims) }; + + // Place false in the uninitialized output buffer. + for (int i = 0; i < output_dims_count; ++i) { + output_data[i] = false; + } + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output_data[i], output_data[i]); + } +} + +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(Abs) +{ + constexpr int output_dims_count = 4; + int shape[] = { 2, 2, 2 }; + const float input[] = { 0.01, -0.01, 10, -10 }; + const float golden[] = { 0.01, 0.01, 10, 10 }; + float output_data[output_dims_count]; + tflite::testing::TestElementwiseFloat(tflite::ops::micro::Register_ABS(), + shape, input, shape, golden, + output_data); +} + +TF_LITE_MICRO_TEST(Sin) +{ + constexpr int output_dims_count = 4; + int shape[] = { 2, 2, 2 }; + const float input[] = { 0, 3.1415926, -3.1415926, 1 }; + const float golden[] = { 0, 0, 0, 0.84147 }; + float output_data[output_dims_count]; + tflite::testing::TestElementwiseFloat(tflite::ops::micro::Register_SIN(), + shape, input, shape, golden, + output_data); +} + +TF_LITE_MICRO_TEST(Cos) +{ + constexpr int output_dims_count = 4; + int shape[] = { 2, 2, 2 }; + const float input[] = { 0, 3.1415926, -3.1415926, 1 }; + const float golden[] = { 1, -1, -1, 0.54030 }; + float output_data[output_dims_count]; + tflite::testing::TestElementwiseFloat(tflite::ops::micro::Register_COS(), + shape, input, shape, golden, + output_data); +} + +TF_LITE_MICRO_TEST(Log) +{ + constexpr int output_dims_count = 4; + int shape[] = { 2, 2, 2 }; + const float input[] = { 1, 2.7182818, 0.5, 2 }; + const float golden[] = { 0, 1, -0.6931472, 0.6931472 }; + float output_data[output_dims_count]; + tflite::testing::TestElementwiseFloat(tflite::ops::micro::Register_LOG(), + shape, input, shape, golden, + output_data); +} + +TF_LITE_MICRO_TEST(Sqrt) +{ + constexpr int output_dims_count = 4; + int shape[] = { 2, 2, 2 }; + const float input[] = { 0, 1, 2, 4 }; + const float golden[] = { 0, 1, 1.41421, 2 }; + float output_data[output_dims_count]; + tflite::testing::TestElementwiseFloat(tflite::ops::micro::Register_SQRT(), + shape, input, shape, golden, + output_data); +} + +TF_LITE_MICRO_TEST(Rsqrt) +{ + constexpr int output_dims_count = 4; + int shape[] = { 2, 2, 2 }; + const float input[] = { 1, 2, 4, 9 }; + const float golden[] = { 1, 0.7071, 0.5, 0.33333 }; + float output_data[output_dims_count]; + tflite::testing::TestElementwiseFloat(tflite::ops::micro::Register_RSQRT(), + shape, input, shape, golden, + output_data); +} + +TF_LITE_MICRO_TEST(Square) +{ + constexpr int output_dims_count = 4; + int shape[] = { 2, 2, 2 }; + const float input[] = { 1, 2, 0.5, -3.0 }; + const float golden[] = { 1, 4.0, 0.25, 9.0 }; + float output_data[output_dims_count]; + tflite::testing::TestElementwiseFloat(tflite::ops::micro::Register_SQUARE(), + shape, input, shape, golden, + output_data); +} + +TF_LITE_MICRO_TEST(LogicalNot) +{ + constexpr int output_dims_count = 4; + int shape[] = { 2, 2, 2 }; + const bool input[] = { true, false, false, true }; + const bool golden[] = { false, true, true, false }; + bool output_data[output_dims_count]; + tflite::testing::TestElementwiseBool( + tflite::ops::micro::Register_LOGICAL_NOT(), shape, input, shape, golden, + output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/elu.cc b/components/tflite/tensorflow/lite/micro/kernels/elu.cc new file mode 100644 index 00000000..f468d30e --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/elu.cc @@ -0,0 +1,159 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/elu.h" + +#include +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/cppmath.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/process_broadcast_shapes.h" +#include "tensorflow/lite/kernels/internal/types.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace { + +// Input/output tensor index. +constexpr int kInputTensor = 0; +constexpr int kOutputTensor = 0; + +// OLD-TODO(b/142762739): We should figure out a multi-threading plan for most +// of the activation ops below. + +struct OpData { + int8_t table[256]; +}; + +using TransformFunc = float (*)(float); + +template +void PopulateLookupTable(const TfLiteTensor *input, const TfLiteTensor *output, + const TransformFunc transform, OpData *data) +{ + if (sizeof(T) != 1) + TF_LITE_FATAL("Lookup table valid only for 8bit"); + + const float inverse_scale = 1 / output->params.scale; + int32_t maxval = std::numeric_limits::max(); + int32_t minval = std::numeric_limits::min(); + for (int32_t val = minval; val <= maxval; ++val) { + const float dequantized = + input->params.scale * (val - input->params.zero_point); + const float transformed = transform(dequantized); + const float rescaled = TfLiteRound(transformed * inverse_scale); + const int32_t quantized = + static_cast(rescaled + output->params.zero_point); + data->table[static_cast(static_cast(val))] = + static_cast(std::max(std::min(maxval, quantized), minval)); + } +} + +// OLD-TODO(b/143696793): move this to optimized_ops. +void EvalUsingLookupTable(const OpData *data, const TfLiteEvalTensor *input, + TfLiteEvalTensor *output) +{ + const int size = MatchingFlatSize(tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorShape(output)); + int8_t *output_data = tflite::micro::GetTensorData(output); + const int8_t *input_data = tflite::micro::GetTensorData(input); + + for (int i = 0; i < size; ++i) { + output_data[i] = data->table[static_cast(input_data[i])]; + } +} + +TfLiteStatus CalculateOpData(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + const TfLiteTensor *input; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, kInputTensor, &input)); + TfLiteTensor *output; + TF_LITE_ENSURE_OK(context, + GetOutputSafe(context, node, kOutputTensor, &output)); + TF_LITE_ENSURE_TYPES_EQ(context, input->type, output->type); + + // Use LUT to handle quantized elu path. + if (input->type == kTfLiteInt8) { + OpData *data = static_cast(node->user_data); + TransformFunc transform = [](float value) { + return value < 0.0f ? std::exp(value) - 1.0f : value; + }; + PopulateLookupTable(input, output, transform, data); + } + + return kTfLiteOk; +} + +void *EluInit(TfLiteContext *context, const char *buffer, size_t length) +{ + // This is a builtin op, so we don't use the contents in 'buffer', if any. + // Instead, we allocate a new object to carry information from Prepare() to + // Eval(). + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(OpData)); +} + +TfLiteStatus EluPrepare(TfLiteContext *context, TfLiteNode *node) +{ + return CalculateOpData(context, node); +} + +TfLiteStatus EluEval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + switch (input->type) { + case kTfLiteFloat32: { + reference_ops::Elu(tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + return kTfLiteOk; + } + case kTfLiteInt8: { + const OpData *data = static_cast(node->user_data); + EvalUsingLookupTable(data, input, output); + return kTfLiteOk; + } + default: + TF_LITE_KERNEL_LOG( + context, "ELU only supports float32 and int8 currently, got %s.", + TfLiteTypeGetName(input->type)); + return kTfLiteError; + } +} + +} // namespace + +TfLiteRegistration Register_ELU() +{ + return { /*init=*/EluInit, + /*free=*/nullptr, + /*prepare=*/EluPrepare, + /*invoke=*/EluEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/elu_test.cc b/components/tflite/tensorflow/lite/micro/kernels/elu_test.cc new file mode 100644 index 00000000..0dd10d9a --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/elu_test.cc @@ -0,0 +1,174 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +// min/max are used to compute scale, zero-point +template +struct TestEluParams { + // quantization parameters + float data_min; // input and output data minimum value + float data_max; // input and output data maximum value + T *input_data; // quantized input storage + T *output_data; // quantized output storage + float tolerance; // output vs expected value tolerance +}; + +// Our fixed-point math function implementations have roughly 12 bits of +// accuracy, when specialized to 16-bit fixed-point arithmetic. +// That is purely an implementation compromise, it would have been possible +// to get closer to 16 bits of accuracy but that would be more expensive, +// and not needed for our purposes as ultimately the output is either +// immediately down-quantized to 8 bits, or will typically be at the output +// of the surrounding LSTM cell. +// So we can require roughly 2^-12 accuracy when the output is 16-bit, and +// we can more or less expect the full 2^-8 accuracy when the output is 8-bit. +// +// However, the representable output interval is often [-1, 1] (it has to be +// for tanh, and even for logistic, when we implement it in fixed-point, we +// typically have to do so on such a symmetric interval, e.g. ARM NEON only +// has signed fixed-point arithmetic (SQRDMULH)). As the width of [-1, 1] +// is 2, our representable values are often diluted by a factor of 2, whence +// the factor of 2 below. +constexpr float kQuantizedTolerance = 2 * (1. / 256); + +void ExecuteEluTest(TfLiteTensor *tensors, int tensors_count) +{ + int kInputArrayData[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(kInputArrayData); + int kOutputArrayData[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(kOutputArrayData); + + const TfLiteRegistration registration = tflite::Register_ELU(); + micro::KernelRunner runner(registration, tensors, tensors_count, inputs_array, + outputs_array, nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); +} + +template +void TestElu(int *input_dims_data, const T *input_data, int *expected_dims, + const T *expected_data, T *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(expected_dims); + const int output_count = ElementCount(*output_dims); + + TfLiteTensor tensors[] = { + CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims), + }; + constexpr int tensors_count = std::extent::value; + ExecuteEluTest(tensors, tensors_count); + + constexpr float kTolerance = 1e-5; + for (int i = 0; i < output_count; i++) { + TF_LITE_MICRO_EXPECT_NEAR(expected_data[i], output_data[i], kTolerance); + } +} + +template +void TestEluQuantized(const TestEluParams ¶ms, int *input_dims_data, + const float *input_data, int *expected_dims, + const float *expected_data, float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(expected_dims); + const int output_count = ElementCount(*output_dims); + + const float scale = ScaleFromMinMax(params.data_min, params.data_max); + const int zero_point = + ZeroPointFromMinMax(params.data_min, params.data_max); + + TfLiteTensor tensors[] = { + CreateQuantizedTensor(input_data, params.input_data, input_dims, scale, + zero_point), + CreateQuantizedTensor(params.output_data, output_dims, scale, zero_point), + }; + constexpr int kTensorsCount = std::extent::value; + + ExecuteEluTest(tensors, kTensorsCount); + + Dequantize(params.output_data, output_count, scale, zero_point, output_data); + const float kTolerance = params.tolerance; + for (int i = 0; i < output_count; i++) { + TF_LITE_MICRO_EXPECT_NEAR(expected_data[i], output_data[i], kTolerance); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(FloatActivationsOpTestElu) +{ + int kDims[] = { 4, 1, 2, 4, 1 }; + constexpr float kInput[] = { + 0, -6, 2, -4, // + 3, -2, 10, -0.1, // + }; + constexpr float kExpect[] = { + 0.0, -0.997521, 2.0, -0.981684, // + 3.0, -0.864665, 10.0, -0.0951626, // + }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + tflite::testing::TestElu(kDims, kInput, kDims, kExpect, output_data); +} + +TF_LITE_MICRO_TEST(QuantizedActivationsOpTestEluInt8) +{ + int kDims[] = { 4, 1, 2, 4, 1 }; + constexpr float kInput[] = { + 0, -6, 2, -4, // + 3, -2, 6, -0.1, // + }; + constexpr float kExpect[] = { + 0, -1.0, 2.0, -1, // + 3.0, -0.875, 6.0, -0.125, // + }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + // setup quantization storage and parameters + int8_t q_output_data[kOutputCount]; + int8_t q_input_data[kOutputCount]; + constexpr float kMin = -1; + constexpr float kMax = 127.f / 128.f; + tflite::testing::TestEluParams params = {}; + params.data_min = 8 * kMin; + params.data_max = 8 * kMax; + params.input_data = q_input_data; + params.output_data = q_output_data; + params.tolerance = tflite::testing::kQuantizedTolerance; + + tflite::testing::TestEluQuantized(params, kDims, kInput, kDims, kExpect, + output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/ethosu.cc b/components/tflite/tensorflow/lite/micro/kernels/ethosu.cc new file mode 100644 index 00000000..af16221f --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/ethosu.cc @@ -0,0 +1,33 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// +// This is a stub file for non-Ethos platforms +// +#include "tensorflow/lite/c/common.h" + +namespace tflite { + +TfLiteRegistration *Register_ETHOSU() +{ + return nullptr; +} + +const char *GetString_ETHOSU() +{ + return ""; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/ethosu.h b/components/tflite/tensorflow/lite/micro/kernels/ethosu.h new file mode 100644 index 00000000..c9678419 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/ethosu.h @@ -0,0 +1,27 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_MICRO_KERNELS_ETHOSU_H_ +#define TENSORFLOW_LITE_MICRO_KERNELS_ETHOSU_H_ + +#include "tensorflow/lite/c/common.h" + +namespace tflite { +TfLiteRegistration *Register_ETHOSU(); + +const char *GetString_ETHOSU(); + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_KERNELS_ETHOSU_H_ diff --git a/components/tflite/tensorflow/lite/micro/kernels/exp.cc b/components/tflite/tensorflow/lite/micro/kernels/exp.cc new file mode 100644 index 00000000..38311625 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/exp.cc @@ -0,0 +1,81 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/exp.h" + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace { + +constexpr int kInputTensor = 0; +constexpr int kOutputTensor = 0; + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + const TfLiteTensor *input = GetInput(context, node, kInputTensor); + TF_LITE_ENSURE(context, input != nullptr); + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + TF_LITE_ENSURE_TYPES_EQ(context, input->type, kTfLiteFloat32); + TF_LITE_ENSURE_TYPES_EQ(context, output->type, input->type); + TF_LITE_ENSURE_EQ(context, output->bytes, input->bytes); + TF_LITE_ENSURE_EQ(context, output->dims->size, input->dims->size); + for (int i = 0; i < output->dims->size; ++i) { + TF_LITE_ENSURE_EQ(context, output->dims->data[i], input->dims->data[i]); + } + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + int flat_size = MatchingFlatSize(tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorShape(output)); + + if (input->type == kTfLiteFloat32) { + reference_ops::Exp(tflite::micro::GetTensorData(input), + static_cast(flat_size), + tflite::micro::GetTensorData(output)); + } else { + TF_LITE_KERNEL_LOG(context, "Type %s (%d) currently not supported by Exp.", + TfLiteTypeGetName(input->type), input->type); + return kTfLiteError; + } + return kTfLiteOk; +} +} // namespace + +TfLiteRegistration Register_EXP() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/exp_test.cc b/components/tflite/tensorflow/lite/micro/kernels/exp_test.cc new file mode 100644 index 00000000..2b2803c5 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/exp_test.cc @@ -0,0 +1,79 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +void TestExp(int *input_dims_data, const float *input_data, + const float *expected_output_data, float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(input_dims_data); + const int output_dims_count = ElementCount(*output_dims); + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims), + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = Register_EXP(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output_data[i], output_data[i], 1e-5f); + } +} +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(SingleDim) +{ + constexpr int kInputSize = 7; + float output_data[kInputSize]; + int input_dims[] = { 2, 1, kInputSize }; + const float input_values[kInputSize] = { 0.0f, 1.0f, -1.0f, 100.0f, + -100.0f, 0.01f, -0.01f }; + float golden[kInputSize]; + for (int i = 0; i < kInputSize; ++i) { + golden[i] = std::exp(input_values[i]); + } + + tflite::testing::TestExp(input_dims, input_values, golden, output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/expand_dims.cc b/components/tflite/tensorflow/lite/micro/kernels/expand_dims.cc new file mode 100644 index 00000000..a533744a --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/expand_dims.cc @@ -0,0 +1,158 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/micro_utils.h" + +namespace tflite { +namespace { + +constexpr int kInputTensor = 0; +constexpr int kAxisTensor = 1; +constexpr int kOutputTensor = 0; + +TfLiteStatus ExpandTensorDim(TfLiteContext *context, + const TfLiteEvalTensor *input, int32_t axis, + TfLiteEvalTensor *output) +{ + const TfLiteIntArray *input_dims = input->dims; + TfLiteIntArray *output_dims = output->dims; + if (axis < 0) { + axis = input_dims->size + 1 + axis; + } + TF_LITE_ENSURE(context, (axis <= input_dims->size)); + + output_dims->size = input_dims->size + 1; + for (int i = 0; i < output_dims->size; ++i) { + if (i < axis) { + output_dims->data[i] = input_dims->data[i]; + } else if (i == axis) { + output_dims->data[i] = 1; + } else { + output_dims->data[i] = input_dims->data[i - 1]; + } + } + return kTfLiteOk; +} + +TfLiteStatus GetAxisValueFromTensor(TfLiteContext *context, + const TfLiteEvalTensor *axis, + int32_t *axis_value) +{ + const int axis_dims = (tflite::micro::GetTensorShape(axis)).DimensionsCount(); + if (axis_dims > 1) { + TF_LITE_KERNEL_LOG(context, "Axis has only one element for Expand_Dims.", + axis_dims); + return kTfLiteError; + } + + if (kTfLiteInt32 == (axis->type)) { + const int32_t *axis_ptr = tflite::micro::GetTensorData(axis); + *axis_value = axis_ptr[0]; + return kTfLiteOk; + } else { + TF_LITE_KERNEL_LOG(context, + "Axis type %s (%d) not supported by Expand_Dims.", + TfLiteTypeGetName(axis->type), axis->type); + return kTfLiteError; + } +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE_EQ(context, NumInputs(node), 2); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + const TfLiteTensor *input; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, kInputTensor, &input)); + const TfLiteTensor *axis; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, kAxisTensor, &axis)); + TfLiteTensor *output; + TF_LITE_ENSURE_OK(context, + GetOutputSafe(context, node, kOutputTensor, &output)); + output->type = input->type; + if (IsDynamicTensor(axis)) { + TF_LITE_KERNEL_LOG(context, + "DynamicTensor is not yet supported by Expand_Dims."); + return kTfLiteError; + } + return kTfLiteOk; +} + +template +void memCopyN(T *out, const T *in, const int num_elements) +{ + for (int i = 0; i < num_elements; ++i) { + out[i] = in[i]; + } +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + const TfLiteEvalTensor *axis = + tflite::micro::GetEvalInput(context, node, kAxisTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + const int flat_size = ElementCount(*input->dims); + const int input_dims = input->dims->size; + + int32_t axis_value; + TF_LITE_ENSURE_OK(context, + GetAxisValueFromTensor(context, axis, &axis_value)); + if ((axis_value > static_cast(input_dims)) || + (axis_value < static_cast(-(input_dims + 1)))) { + TF_LITE_KERNEL_LOG(context, "Invalid Expand_Dims axis value (%d).", + axis_value); + return kTfLiteError; + } + ExpandTensorDim(context, input, axis_value, output); + + switch (input->type) { + case kTfLiteFloat32: { + memCopyN(tflite::micro::GetTensorData(output), + tflite::micro::GetTensorData(input), flat_size); + } break; + case kTfLiteInt8: { + memCopyN(tflite::micro::GetTensorData(output), + tflite::micro::GetTensorData(input), flat_size); + } break; + default: + TF_LITE_KERNEL_LOG( + context, + "Expand_Dims only currently supports int8 and float32, got %d.", + input->type); + return kTfLiteError; + } + return kTfLiteOk; +} +} // namespace + +TfLiteRegistration Register_EXPAND_DIMS() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/expand_dims_test.cc b/components/tflite/tensorflow/lite/micro/kernels/expand_dims_test.cc new file mode 100644 index 00000000..f2fdf12f --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/expand_dims_test.cc @@ -0,0 +1,183 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +template +void TestExpandDims(int *input_dims, const T *input_data, int *axis_dims, + const int32_t *axis_data, int *expected_output_dims, + int *output_dims, const T *expected_output_data, + T *output_data) +{ + TfLiteIntArray *in_dims = IntArrayFromInts(input_dims); + TfLiteIntArray *ax_dims = IntArrayFromInts(axis_dims); + TfLiteIntArray *out_dims = IntArrayFromInts(output_dims); + const int in_dims_size = in_dims->size; + + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, in_dims), + CreateTensor(axis_data, ax_dims), + CreateTensor(output_data, out_dims, true), + }; + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = Register_EXPAND_DIMS(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + // The output tensor's data and shape have been updated by the kernel. + TfLiteTensor *actual_out_tensor = &tensors[2]; + TfLiteIntArray *actual_out_dims = actual_out_tensor->dims; + const int actual_out_dims_size = actual_out_dims->size; + const int output_size = ElementCount(*actual_out_dims); + TF_LITE_MICRO_EXPECT_EQ(actual_out_dims_size, (in_dims_size + 1)); + for (int i = 0; i < actual_out_dims_size; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output_dims[i], actual_out_dims->data[i]); + } + for (int i = 0; i < output_size; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output_data[i], output_data[i]); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(ExpandDimsPositiveAxisTest0) +{ + int8_t output_data[4]; + int input_dims[] = { 2, 2, 2 }; + const int8_t input_data[] = { -1, 1, -2, 2 }; + const int8_t golden_data[] = { -1, 1, -2, 2 }; + int axis_dims[] = { 1, 1 }; + const int32_t axis_data[] = { 0 }; + int golden_dims[] = { 1, 2, 2 }; + int output_dims[] = { 3, 0, 0, 0 }; + tflite::testing::TestExpandDims(input_dims, input_data, axis_dims, + axis_data, golden_dims, output_dims, + golden_data, output_data); +} + +TF_LITE_MICRO_TEST(ExpandDimsPositiveAxisTest1) +{ + float output_data[4]; + int input_dims[] = { 2, 2, 2 }; + const float input_data[] = { -1.1, 1.2, -2.1, 2.2 }; + const float golden_data[] = { -1.1, 1.2, -2.1, 2.2 }; + int axis_dims[] = { 1, 1 }; + const int32_t axis_data[] = { 1 }; + int golden_dims[] = { 2, 1, 2 }; + int output_dims[] = { 3, 0, 0, 0 }; + tflite::testing::TestExpandDims(input_dims, input_data, axis_dims, + axis_data, golden_dims, output_dims, + golden_data, output_data); +} + +TF_LITE_MICRO_TEST(ExpandDimsPositiveAxisTest2) +{ + int8_t output_data[4]; + int input_dims[] = { 2, 2, 2 }; + const int8_t input_data[] = { -1, 1, -2, 2 }; + const int8_t golden_data[] = { -1, 1, -2, 2 }; + int axis_dims[] = { 1, 1 }; + const int32_t axis_data[] = { 2 }; + int golden_dims[] = { 2, 2, 1 }; + int output_dims[] = { 3, 0, 0, 0 }; + tflite::testing::TestExpandDims(input_dims, input_data, axis_dims, + axis_data, golden_dims, output_dims, + golden_data, output_data); +} + +TF_LITE_MICRO_TEST(ExpandDimsNegativeAxisTest4) +{ + int8_t output_data[6]; + int input_dims[] = { 3, 3, 1, 2 }; + const int8_t input_data[] = { -1, 1, 2, -2, 0, 3 }; + const int8_t golden_data[] = { -1, 1, 2, -2, 0, 3 }; + int axis_dims[] = { 1, 1 }; + const int32_t axis_data[] = { -4 }; + int golden_dims[] = { 1, 3, 1, 2 }; + int output_dims[] = { 4, 0, 0, 0, 0 }; + tflite::testing::TestExpandDims(input_dims, input_data, axis_dims, + axis_data, golden_dims, output_dims, + golden_data, output_data); +} + +TF_LITE_MICRO_TEST(ExpandDimsNegativeAxisTest3) +{ + float output_data[6]; + int input_dims[] = { 3, 3, 1, 2 }; + const float input_data[] = { 0.1, -0.8, -1.2, -0.5, 0.9, 1.3 }; + const float golden_data[] = { 0.1, -0.8, -1.2, -0.5, 0.9, 1.3 }; + int axis_dims[] = { 1, 1 }; + const int32_t axis_data[] = { -3 }; + int golden_dims[] = { 3, 1, 1, 2 }; + int output_dims[] = { 4, 0, 0, 0, 0 }; + tflite::testing::TestExpandDims(input_dims, input_data, axis_dims, + axis_data, golden_dims, output_dims, + golden_data, output_data); +} + +TF_LITE_MICRO_TEST(ExpandDimsNegativeAxisTest2) +{ + int8_t output_data[6]; + int input_dims[] = { 3, 1, 2, 3 }; + const int8_t input_data[] = { -1, 1, 2, -2, 0, 3 }; + const int8_t golden_data[] = { -1, 1, 2, -2, 0, 3 }; + int axis_dims[] = { 1, 1 }; + const int32_t axis_data[] = { -2 }; + int golden_dims[] = { 1, 2, 1, 3 }; + int output_dims[] = { 4, 0, 0, 0, 0 }; + tflite::testing::TestExpandDims(input_dims, input_data, axis_dims, + axis_data, golden_dims, output_dims, + golden_data, output_data); +} + +TF_LITE_MICRO_TEST(ExpandDimsNegativeAxisTest1) +{ + float output_data[6]; + int input_dims[] = { 3, 1, 3, 2 }; + const float input_data[] = { 0.1, -0.8, -1.2, -0.5, 0.9, 1.3 }; + const float golden_data[] = { 0.1, -0.8, -1.2, -0.5, 0.9, 1.3 }; + int axis_dims[] = { 1, 1 }; + const int32_t axis_data[] = { -1 }; + int golden_dims[] = { 1, 3, 2, 1 }; + int output_dims[] = { 4, 0, 0, 0, 0 }; + tflite::testing::TestExpandDims(input_dims, input_data, axis_dims, + axis_data, golden_dims, output_dims, + golden_data, output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/fill.cc b/components/tflite/tensorflow/lite/micro/kernels/fill.cc new file mode 100644 index 00000000..e6baa74f --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/fill.cc @@ -0,0 +1,137 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/fill.h" + +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { + +namespace { + +template +TfLiteStatus EnsureEqImpl(TfLiteContext *context, const TfLiteIntArray *array, + const TfLiteTensor *tensor) +{ + for (int i = 0; i < array->size; ++i) { + TF_LITE_ENSURE_EQ(context, array->data[i], GetTensorData(tensor)[i]); + } + return kTfLiteOk; +} + +// Ensure the equality of an int array and a tensor, which must be +// one-dimensional and of an integer type. +TfLiteStatus EnsureEq(TfLiteContext *context, const TfLiteIntArray *array, + const TfLiteTensor *tensor) +{ + TF_LITE_ENSURE_EQ(context, NumDimensions(tensor), 1); + const auto tensor_len = tensor->dims->data[0]; + TF_LITE_ENSURE_EQ(context, array->size, tensor_len); + + switch (tensor->type) { + case kTfLiteInt8: + return EnsureEqImpl(context, array, tensor); + case kTfLiteUInt8: + return EnsureEqImpl(context, array, tensor); + case kTfLiteInt16: + return EnsureEqImpl(context, array, tensor); + case kTfLiteInt32: + return EnsureEqImpl(context, array, tensor); + case kTfLiteInt64: + return EnsureEqImpl(context, array, tensor); + default: + TF_LITE_KERNEL_LOG(context, + "cannot compare int array to tensor of type %d.", + tensor->type); + return kTfLiteError; + } +} + +constexpr int kDimsTensor = 0; +constexpr int kValueTensor = 1; +constexpr int kOutputTensor = 0; + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + // Ensure inputs and outputs exist. + const TfLiteTensor *dims; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, kDimsTensor, &dims)); + const TfLiteTensor *value; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, kValueTensor, &value)); + TfLiteTensor *output; + TF_LITE_ENSURE_OK(context, + GetOutputSafe(context, node, kOutputTensor, &output)); + + // The value tensor must be a scalar. + TF_LITE_ENSURE_EQ(context, NumDimensions(value), 0); + + // The value type and output type must match. + TF_LITE_ENSURE_EQ(context, value->type, output->type); + + // The dims tensor must match the output tensor shape. As a byproduct, + // ensures the dims tensor is of an integer type. + TF_LITE_ENSURE_OK(context, EnsureEq(context, output->dims, dims)); + + return kTfLiteOk; +} + +template +void FillImpl(const TfLiteEvalTensor *value, TfLiteEvalTensor *output) +{ + reference_ops::Fill( + micro::GetTensorShape(value), micro::GetTensorData(value), + micro::GetTensorShape(output), micro::GetTensorData(output)); +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *value = + micro::GetEvalInput(context, node, kValueTensor); + TfLiteEvalTensor *output = micro::GetEvalOutput(context, node, kOutputTensor); + + switch (value->type) { + case kTfLiteFloat32: + FillImpl(value, output); + break; + default: + TF_LITE_KERNEL_LOG( + context, "Fill only currently supports float32 for input 1, got %d.", + TfLiteTypeGetName(value->type)); + return kTfLiteError; + } + + return kTfLiteOk; +} + +} // namespace + +TfLiteRegistration Register_FILL() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/fill_test.cc b/components/tflite/tensorflow/lite/micro/kernels/fill_test.cc new file mode 100644 index 00000000..8cba1a0b --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/fill_test.cc @@ -0,0 +1,133 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/micro_utils.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace { + +template +void TestFill(int *dims_shape, DimsType *dims_data, int *value_shape, + ValueType *value_data, int *output_shape, + OutputType *output_data) +{ + using tflite::testing::CreateTensor; + using tflite::testing::IntArrayFromInts; + + TfLiteTensor tensors[] = { + CreateTensor(dims_data, IntArrayFromInts(dims_shape)), + CreateTensor(value_data, IntArrayFromInts(value_shape)), + CreateTensor(output_data, IntArrayFromInts(output_shape)) + }; + constexpr int dims_index = 0; + constexpr int value_index = 1; + constexpr int output_index = 2; + int inputs[] = { 2, dims_index, value_index }; + int outputs[] = { 1, output_index }; + const auto registration = tflite::Register_FILL(); + tflite::micro::KernelRunner runner{ registration, + tensors, + sizeof(tensors) / sizeof(TfLiteTensor), + IntArrayFromInts(inputs), + IntArrayFromInts(outputs), + /*builtin_data=*/nullptr }; + + TF_LITE_MICRO_EXPECT_EQ(runner.InitAndPrepare(), kTfLiteOk); + TF_LITE_MICRO_EXPECT_EQ(runner.Invoke(), kTfLiteOk); + + // The output shape must match the shape requested via dims. + const auto output_rank = output_shape[0]; + const auto requested_rank = dims_shape[1]; // yes, 1 + if (output_rank == requested_rank) { + for (int i = 0; i < requested_rank; ++i) { + TF_LITE_MICRO_EXPECT_EQ(output_shape[i + 1], dims_data[i]); + } + } else { + TF_LITE_MICRO_FAIL("output shape does not match shape requested via dims"); + } + + // The output type matches the value type. + TF_LITE_MICRO_EXPECT_EQ(tensors[output_index].type, + tensors[value_index].type); + + // The output elements contain the fill value. + const auto elements = tflite::ElementCount(*IntArrayFromInts(output_shape)); + for (int i = 0; i < elements; ++i) { + TF_LITE_MICRO_EXPECT_EQ(output_data[i], value_data[0]); + } +} + +} // namespace + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(FillFloatInt64Dims) +{ + constexpr int kDim1 = 2; + constexpr int kDim2 = 2; + constexpr int kDim3 = 2; + + int dims_shape[] = { 1, 3 }; + int64_t dims_data[] = { kDim1, kDim2, kDim3 }; + + int value_shape[] = { 0 }; + float value_data[] = { 4.0 }; + + int output_shape[] = { 3, kDim1, kDim2, kDim3 }; + float output_data[kDim1 * kDim2 * kDim3]; + + TestFill(dims_shape, dims_data, value_shape, value_data, output_shape, + output_data); +} + +TF_LITE_MICRO_TEST(FillFloatInt32Dims) +{ + constexpr int kDim1 = 2; + constexpr int kDim2 = 2; + constexpr int kDim3 = 2; + + int dims_shape[] = { 1, 3 }; + int32_t dims_data[] = { kDim1, kDim2, kDim3 }; + + int value_shape[] = { 0 }; + float value_data[] = { 4.0 }; + + int output_shape[] = { 3, kDim1, kDim2, kDim3 }; + float output_data[kDim1 * kDim2 * kDim3]; + + TestFill(dims_shape, dims_data, value_shape, value_data, output_shape, + output_data); +} + +TF_LITE_MICRO_TEST(FillScalar) +{ + int dims_shape[] = { 1, 0 }; + int64_t dims_data[] = { 0 }; + + int value_shape[] = { 0 }; + float value_data[] = { 4.0 }; + + int output_shape[] = { 0 }; + float output_data[] = { 0 }; + + TestFill(dims_shape, dims_data, value_shape, value_data, output_shape, + output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/floor.cc b/components/tflite/tensorflow/lite/micro/kernels/floor.cc new file mode 100644 index 00000000..1a386721 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/floor.cc @@ -0,0 +1,59 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/floor.h" + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace floor { + +constexpr int kInputTensor = 0; +constexpr int kOutputTensor = 0; + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + TF_LITE_ENSURE_TYPES_EQ(context, input->type, kTfLiteFloat32); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + reference_ops::Floor(tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + return kTfLiteOk; +} +} // namespace floor + +TfLiteRegistration Register_FLOOR() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/nullptr, + /*invoke=*/floor::Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/floor_div.cc b/components/tflite/tensorflow/lite/micro/kernels/floor_div.cc new file mode 100644 index 00000000..5e86c737 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/floor_div.cc @@ -0,0 +1,136 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/floor_div.h" + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/reference/binary_function.h" +#include "tensorflow/lite/kernels/internal/types.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/micro_utils.h" + +namespace tflite { +namespace { + +// Input/output tensor index. +constexpr int kInputTensor1 = 0; +constexpr int kInputTensor2 = 1; +constexpr int kOutputTensor = 0; + +TfLiteStatus CalculateOpData(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE_EQ(context, NumInputs(node), 2); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + + const TfLiteTensor *input1; + TF_LITE_ENSURE_OK(context, + GetInputSafe(context, node, kInputTensor1, &input1)); + const TfLiteTensor *input2; + TF_LITE_ENSURE_OK(context, + GetInputSafe(context, node, kInputTensor2, &input2)); + TfLiteTensor *output; + TF_LITE_ENSURE_OK(context, + GetOutputSafe(context, node, kOutputTensor, &output)); + + TF_LITE_ENSURE_TYPES_EQ(context, input1->type, input2->type); + TF_LITE_ENSURE_TYPES_EQ(context, input1->type, output->type); + + return kTfLiteOk; +} + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + return nullptr; +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + return CalculateOpData(context, node); +} + +template +TfLiteStatus EvalFloorDiv(TfLiteContext *context, + const TfLiteEvalTensor *input1, + const TfLiteEvalTensor *input2, + TfLiteEvalTensor *output) +{ + const T *denominator_data = tflite::micro::GetTensorData(input2); + + // Validate the denominator. + for (int i = 0; i < tflite::ElementCount(*input2->dims); ++i) { + if (std::equal_to()(denominator_data[i], 0)) { + TF_LITE_KERNEL_LOG(context, "Division by 0"); + return kTfLiteError; + } + } + + bool requires_broadcast = !tflite::micro::HaveSameShapes(input1, input2); + + if (requires_broadcast) { + reference_ops::BroadcastBinaryFunction4DSlow( + tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorData(input1), + tflite::micro::GetTensorShape(input2), denominator_data, + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output), reference_ops::FloorDiv); + } else { + reference_ops::BinaryFunction( + tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorData(input1), + tflite::micro::GetTensorShape(input2), denominator_data, + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output), reference_ops::FloorDiv); + } + + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input1 = + tflite::micro::GetEvalInput(context, node, kInputTensor1); + const TfLiteEvalTensor *input2 = + tflite::micro::GetEvalInput(context, node, kInputTensor2); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + switch (input1->type) { + case kTfLiteFloat32: { + return EvalFloorDiv(context, input1, input2, output); + } + default: { + TF_LITE_KERNEL_LOG(context, "Type '%s' is not supported by FLOOR_DIV.", + TfLiteTypeGetName(input1->type)); + return kTfLiteError; + } + } +} + +} // namespace + +TfLiteRegistration Register_FLOOR_DIV() +{ + return { /*init=*/Init, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/floor_div_test.cc b/components/tflite/tensorflow/lite/micro/kernels/floor_div_test.cc new file mode 100644 index 00000000..98456110 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/floor_div_test.cc @@ -0,0 +1,113 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +void ExecuteFloorDivTest(TfLiteTensor *tensors, int tensors_count) +{ + int kInputArrayData[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(kInputArrayData); + int kOutputArrayData[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(kOutputArrayData); + + const TfLiteRegistration registration = tflite::Register_FLOOR_DIV(); + micro::KernelRunner runner(registration, tensors, tensors_count, inputs_array, + outputs_array, nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); +} + +template +void TestFloorDiv(int *input1_dims_data, const T *input1_data, + int *input2_dims_data, const T *input2_data, + int *expected_dims, const T *expected_data, T *output_data) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(expected_dims); + const int output_count = ElementCount(*output_dims); + + TfLiteTensor tensors[] = { + CreateTensor(input1_data, input1_dims), + CreateTensor(input2_data, input2_dims), + CreateTensor(output_data, output_dims), + }; + constexpr int tensors_count = std::extent::value; + + ExecuteFloorDivTest(tensors, tensors_count); + + for (int i = 0; i < output_count; i++) { + TF_LITE_MICRO_EXPECT_EQ(expected_data[i], output_data[i]); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(FloorDivTestSimpleFloat) +{ + int kDims[] = { 4, 1, 2, 2, 1 }; + constexpr float kInput1[] = { 10.05, 9.09, 11.9, 3.01 }; + constexpr float kInput2[] = { 2.05, 2.03, 3.03, 4.03 }; + constexpr float kExpect[] = { 4.0, 4.0, 3.0, 0.0 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + tflite::testing::TestFloorDiv(kDims, kInput1, kDims, kInput2, kDims, kExpect, + output_data); +} + +TF_LITE_MICRO_TEST(FloorDivTestNegativeValueFloat) +{ + int kDims[] = { 4, 1, 2, 2, 1 }; + constexpr float kInput1[] = { 10.03, -9.9, -11.0, 7.0 }; + constexpr float kInput2[] = { 2.0, 2.3, -3.0, -4.1 }; + constexpr float kExpect[] = { 5.0, -5.0, 3.0, -2.0 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + tflite::testing::TestFloorDiv(kDims, kInput1, kDims, kInput2, kDims, kExpect, + output_data); +} + +TF_LITE_MICRO_TEST(FloorDivTestBroadcastFloat) +{ + int kDims1[] = { 4, 1, 2, 2, 1 }; + int kDims2[] = { 1, 1 }; + constexpr float kInput1[] = { 10.03, -9.9, -11.0, 7.0 }; + constexpr float kInput2[] = { -3.3 }; + constexpr float kExpect[] = { -4.0, 2.0, 3.0, -3.0 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + tflite::testing::TestFloorDiv(kDims1, kInput1, kDims2, kInput2, kDims1, + kExpect, output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/floor_mod.cc b/components/tflite/tensorflow/lite/micro/kernels/floor_mod.cc new file mode 100644 index 00000000..9a20075f --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/floor_mod.cc @@ -0,0 +1,134 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/floor_mod.h" + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/reference/binary_function.h" +#include "tensorflow/lite/kernels/internal/reference/process_broadcast_shapes.h" +#include "tensorflow/lite/kernels/internal/types.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/micro_utils.h" + +// OLD-TODO(b/117523611): We should factor out a binary_op and put binary ops +// there. +namespace tflite { +namespace { + +// Input/output tensor index. +constexpr int kInputTensor1 = 0; +constexpr int kInputTensor2 = 1; +constexpr int kOutputTensor = 0; + +// OLD-TODO(b/117912880): Support quantization. + +TfLiteStatus CalculateOpData(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE_EQ(context, NumInputs(node), 2); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + + const TfLiteTensor *input1; + TF_LITE_ENSURE_OK(context, + GetInputSafe(context, node, kInputTensor1, &input1)); + const TfLiteTensor *input2; + TF_LITE_ENSURE_OK(context, + GetInputSafe(context, node, kInputTensor2, &input2)); + TfLiteTensor *output; + TF_LITE_ENSURE_OK(context, + GetOutputSafe(context, node, kOutputTensor, &output)); + + TF_LITE_ENSURE_TYPES_EQ(context, input1->type, input2->type); + TF_LITE_ENSURE_TYPES_EQ(context, input1->type, output->type); + + return kTfLiteOk; +} + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + return nullptr; +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + return CalculateOpData(context, node); +} + +template +TfLiteStatus EvalFloorMod(TfLiteContext *context, bool requires_broadcast, + const TfLiteEvalTensor *input1, + const TfLiteEvalTensor *input2, + TfLiteEvalTensor *output) +{ + const T *denominator_data = tflite::micro::GetTensorData(input2); + + if (requires_broadcast) { + reference_ops::BroadcastBinaryFunction4DSlow( + tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorData(input1), + tflite::micro::GetTensorShape(input2), denominator_data, + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output), reference_ops::FloorMod); + } else { + reference_ops::BinaryFunction( + tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorData(input1), + tflite::micro::GetTensorShape(input2), denominator_data, + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output), reference_ops::FloorMod); + } + + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input1 = + tflite::micro::GetEvalInput(context, node, kInputTensor1); + const TfLiteEvalTensor *input2 = + tflite::micro::GetEvalInput(context, node, kInputTensor2); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + bool requires_broadcast = !tflite::micro::HaveSameShapes(input1, input2); + + switch (input1->type) { + case kTfLiteFloat32: { + return EvalFloorMod(context, requires_broadcast, input1, input2, + output); + } + default: { + TF_LITE_KERNEL_LOG(context, "Type '%s' is not supported by FLOOR_MOD.", + TfLiteTypeGetName(input1->type)); + return kTfLiteError; + } + } +} + +} // namespace + +TfLiteRegistration Register_FLOOR_MOD() +{ + return { /*init=*/Init, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/floor_mod_test.cc b/components/tflite/tensorflow/lite/micro/kernels/floor_mod_test.cc new file mode 100644 index 00000000..6edd5f9f --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/floor_mod_test.cc @@ -0,0 +1,113 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +void ExecuteFloorModTest(TfLiteTensor *tensors, int tensors_count) +{ + int kInputArrayData[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(kInputArrayData); + int kOutputArrayData[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(kOutputArrayData); + + const TfLiteRegistration registration = tflite::Register_FLOOR_MOD(); + micro::KernelRunner runner(registration, tensors, tensors_count, inputs_array, + outputs_array, nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); +} + +template +void TestFloorMod(int *input1_dims_data, const T *input1_data, + int *input2_dims_data, const T *input2_data, + int *expected_dims, const T *expected_data, T *output_data) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(expected_dims); + const int output_count = ElementCount(*output_dims); + + TfLiteTensor tensors[] = { + CreateTensor(input1_data, input1_dims), + CreateTensor(input2_data, input2_dims), + CreateTensor(output_data, output_dims), + }; + constexpr int tensors_count = std::extent::value; + + ExecuteFloorModTest(tensors, tensors_count); + + for (int i = 0; i < output_count; i++) { + TF_LITE_MICRO_EXPECT_EQ(expected_data[i], output_data[i]); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(FloorModFloatSimple) +{ + int kDims[] = { 4, 1, 2, 2, 1 }; + constexpr float kInput1[] = { 10, 9, 11, 3 }; + constexpr float kInput2[] = { 2, 2, 3, 4 }; + constexpr float kExpect[] = { 0, 1, 2, 3 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + tflite::testing::TestFloorMod(kDims, kInput1, kDims, kInput2, kDims, kExpect, + output_data); +} + +TF_LITE_MICRO_TEST(FloorModFloatNegativeValue) +{ + int kDims[] = { 4, 1, 2, 2, 1 }; + constexpr float kInput1[] = { 10, -9, -11, 7 }; + constexpr float kInput2[] = { 2, 2, -3, -4 }; + constexpr float kExpect[] = { 0, 1, -2, -1 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + tflite::testing::TestFloorMod(kDims, kInput1, kDims, kInput2, kDims, kExpect, + output_data); +} + +TF_LITE_MICRO_TEST(FloorModFloatBroadcast) +{ + int kDims1[] = { 4, 1, 2, 2, 1 }; + int kDims2[] = { 1, 1 }; + constexpr float kInput1[] = { 10, -9, -11, 7 }; + constexpr float kInput2[] = { -3 }; + constexpr float kExpect[] = { -2, 0, -2, -2 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + tflite::testing::TestFloorMod(kDims1, kInput1, kDims2, kInput2, kDims1, + kExpect, output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/floor_test.cc b/components/tflite/tensorflow/lite/micro/kernels/floor_test.cc new file mode 100644 index 00000000..0987fa2f --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/floor_test.cc @@ -0,0 +1,85 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +void TestFloor(int *input_dims_data, const float *input_data, + const float *expected_output_data, int *output_dims_data, + float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims), + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = tflite::ops::micro::Register_FLOOR(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output_data[i], output_data[i], 1e-5f); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(FloorOpSingleDimFloat32) +{ + int dims[] = { 1, 2 }; + const float input[] = { 8.5f, 0.0f }; + const float golden[] = { 8, 0 }; + float output_data[2]; + tflite::testing::TestFloor(dims, input, golden, dims, output_data); +} + +TF_LITE_MICRO_TEST(FloorOpMultiDimFloat32) +{ + int dims[] = { 4, 2, 1, 1, 5 }; + const float input[] = { 0.0001f, 8.0001f, 0.9999f, 9.9999f, 0.5f, + -0.0001f, -8.0001f, -0.9999f, -9.9999f, -0.5f }; + const float golden[] = { 0.0f, 8.0f, 0.0f, 9.0f, 0.0f, + -1.0f, -9.0f, -1.0f, -10.0f, -1.0f }; + float output_data[10]; + tflite::testing::TestFloor(dims, input, golden, dims, output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/fully_connected.cc b/components/tflite/tensorflow/lite/micro/kernels/fully_connected.cc new file mode 100644 index 00000000..ea45af8b --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/fully_connected.cc @@ -0,0 +1,138 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/kernels/fully_connected.h" + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/fully_connected.h" +#include "tensorflow/lite/kernels/internal/reference/integer_ops/fully_connected.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace { + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, + sizeof(OpDataFullyConnected)); +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + TFLITE_DCHECK(node->builtin_data != nullptr); + + auto *data = static_cast(node->user_data); + const auto params = + static_cast(node->builtin_data); + + const TfLiteTensor *input = + GetInput(context, node, kFullyConnectedInputTensor); + TF_LITE_ENSURE(context, input != nullptr); + const TfLiteTensor *filter = + GetInput(context, node, kFullyConnectedWeightsTensor); + TF_LITE_ENSURE(context, filter != nullptr); + const TfLiteTensor *bias = + GetOptionalInputTensor(context, node, kFullyConnectedBiasTensor); + TfLiteTensor *output = GetOutput(context, node, kFullyConnectedOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + + TF_LITE_ENSURE_TYPES_EQ(context, input->type, output->type); + TF_LITE_ENSURE_MSG(context, input->type == filter->type, + "Hybrid models are not supported on TFLite Micro."); + + return CalculateOpDataFullyConnected(context, params->activation, input->type, + input, filter, bias, output, data); +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->builtin_data != nullptr); + const auto *params = + static_cast(node->builtin_data); + + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kFullyConnectedInputTensor); + const TfLiteEvalTensor *filter = + tflite::micro::GetEvalInput(context, node, kFullyConnectedWeightsTensor); + const TfLiteEvalTensor *bias = + tflite::micro::GetEvalInput(context, node, kFullyConnectedBiasTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kFullyConnectedOutputTensor); + + TFLITE_DCHECK(node->user_data != nullptr); + const auto &data = + *(static_cast(node->user_data)); + + // Checks in Prepare ensure input, output and filter types are all the same. + switch (input->type) { + case kTfLiteFloat32: { + tflite::reference_ops::FullyConnected( + FullyConnectedParamsFloat(params->activation), + tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(filter), + tflite::micro::GetTensorData(filter), + tflite::micro::GetTensorShape(bias), + tflite::micro::GetTensorData(bias), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + break; + } + + case kTfLiteInt8: { + tflite::reference_integer_ops::FullyConnected( + FullyConnectedParamsQuantized(data), + tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(filter), + tflite::micro::GetTensorData(filter), + tflite::micro::GetTensorShape(bias), + tflite::micro::GetTensorData(bias), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + break; + } + + default: { + TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.", + TfLiteTypeGetName(input->type), input->type); + return kTfLiteError; + } + } + return kTfLiteOk; +} + +} // namespace + +TfLiteRegistration Register_FULLY_CONNECTED() +{ + return { /*init=*/Init, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/fully_connected.h b/components/tflite/tensorflow/lite/micro/kernels/fully_connected.h new file mode 100644 index 00000000..4f66709b --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/fully_connected.h @@ -0,0 +1,91 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_MICRO_KERNELS_FULLY_CONNECTED_H_ +#define TENSORFLOW_LITE_MICRO_KERNELS_FULLY_CONNECTED_H_ + +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +struct OpDataFullyConnected { + // The scaling factor from input to output (aka the 'real multiplier') can + // be represented as a fixed point multiplier plus a left shift. + int32_t output_multiplier; + int output_shift; + // The range of the fused activation layer. For example for kNone and + // uint8_t these would be 0 and 255. + int32_t output_activation_min; + int32_t output_activation_max; + // The index of the temporary tensor where the quantized inputs are cached. + int input_quantized_index; + // Cached zero point values of tensors. + int32_t input_zero_point; + int32_t filter_zero_point; + int32_t output_zero_point; +}; + +extern const int kFullyConnectedInputTensor; +extern const int kFullyConnectedWeightsTensor; +extern const int kFullyConnectedBiasTensor; +extern const int kFullyConnectedOutputTensor; + +// Returns a FullyConnectedParams struct with all the parameters needed for a +// float computation. +FullyConnectedParams FullyConnectedParamsFloat( + TfLiteFusedActivation activation); + +// Returns a FullyConnectedParams struct with all the parameters needed for a +// quantized computation. +FullyConnectedParams FullyConnectedParamsQuantized( + const OpDataFullyConnected &op_data); + +TfLiteStatus CalculateOpDataFullyConnected( + TfLiteContext *context, TfLiteFusedActivation activation, + TfLiteType data_type, const TfLiteTensor *input, const TfLiteTensor *filter, + const TfLiteTensor *bias, TfLiteTensor *output, OpDataFullyConnected *data); + +// This is the most generic TfLiteRegistration. The actual supported types may +// still be target dependent. The only requirement is that every implementation +// (reference or optimized) must define this function. +TfLiteRegistration Register_FULLY_CONNECTED(); + +#if defined(CMSIS_NN) || defined(ARDUINO) +// The Arduino is a special case where we use the CMSIS kernels, but because of +// the current approach to building for Arduino, we do not support -DCMSIS_NN as +// part of the build. As a result, we use defined(ARDUINO) as proxy for the +// CMSIS kernels for this one special case. + +// Returns a TfLiteRegistration struct for cmsis_nn kernel variant that only +// supports int8. +TfLiteRegistration Register_FULLY_CONNECTED_INT8(); + +#else +// Note that while this block gets used for both reference and optimized kernels +// that do not have any specialized implementations, the only goal here is to +// define fallback implementation that allow reference kernels to still be used +// from applications that call a more specific kernel variant. + +inline TfLiteRegistration Register_FULLY_CONNECTED_INT8() +{ + return Register_FULLY_CONNECTED(); +} + +#endif +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_KERNELS_FULLY_CONNECTED_H_ diff --git a/components/tflite/tensorflow/lite/micro/kernels/fully_connected_common.cc b/components/tflite/tensorflow/lite/micro/kernels/fully_connected_common.cc new file mode 100644 index 00000000..e6ed5ace --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/fully_connected_common.cc @@ -0,0 +1,86 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/fully_connected.h" +#include "tensorflow/lite/kernels/internal/reference/integer_ops/fully_connected.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/fully_connected.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { + +const int kFullyConnectedInputTensor = 0; +const int kFullyConnectedWeightsTensor = 1; +const int kFullyConnectedBiasTensor = 2; +const int kFullyConnectedOutputTensor = 0; + +FullyConnectedParams FullyConnectedParamsQuantized( + const OpDataFullyConnected &op_data) +{ + FullyConnectedParams op_params; + op_params.input_offset = -op_data.input_zero_point; + op_params.weights_offset = -op_data.filter_zero_point; + op_params.output_offset = op_data.output_zero_point; + op_params.output_multiplier = op_data.output_multiplier; + op_params.output_shift = op_data.output_shift; + op_params.quantized_activation_min = op_data.output_activation_min; + op_params.quantized_activation_max = op_data.output_activation_max; + return op_params; +} + +FullyConnectedParams FullyConnectedParamsFloat( + TfLiteFusedActivation activation) +{ + FullyConnectedParams op_params; + CalculateActivationRange(activation, &op_params.float_activation_min, + &op_params.float_activation_max); + return op_params; +} + +TfLiteStatus CalculateOpDataFullyConnected( + TfLiteContext *context, TfLiteFusedActivation activation, + TfLiteType data_type, const TfLiteTensor *input, const TfLiteTensor *filter, + const TfLiteTensor *bias, TfLiteTensor *output, + OpDataFullyConnected *data) +{ + if (data_type != kTfLiteFloat32) { + double real_multiplier = 0.0; + TF_LITE_ENSURE_STATUS(GetQuantizedConvolutionMultipler( + context, input, filter, bias, output, &real_multiplier)); + QuantizeMultiplier(real_multiplier, &data->output_multiplier, + &data->output_shift); + + data->input_zero_point = input->params.zero_point; + // Filter weights will always be symmetric quantized since we only support + // int8 quantization. See + // https://github.com/tensorflow/tensorflow/issues/44912 for additional + // context. + TFLITE_DCHECK(filter->params.zero_point == 0); + data->filter_zero_point = filter->params.zero_point; + data->output_zero_point = output->params.zero_point; + + return CalculateActivationRangeQuantized(context, activation, output, + &data->output_activation_min, + &data->output_activation_max); + } + return kTfLiteOk; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/fully_connected_test.cc b/components/tflite/tensorflow/lite/micro/kernels/fully_connected_test.cc new file mode 100644 index 00000000..e1aa5a19 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/fully_connected_test.cc @@ -0,0 +1,541 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/micro_utils.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +// Simple test data for 2x2x10 input 2x3x10 weights. +const int simple_input_size = 20; +int simple_input_dims[] = { 2, 2, 10 }; +const float simple_input_data[] = { + 1, 2, 3, 4, 5, 6, 7, 8, -9, -10, // b = 0 + 1, 2, 3, 4, 5, 6, 7, -8, 9, -10, // b = 1 +}; +const int simple_weights_size = 30; +int simple_weights_dims[] = { 2, 3, 10 }; +const float simple_weights_data[] = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // u = 0 + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // u = 1 + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // u = 2 +}; +int simple_bias_dims[] = { 1, 3 }; +const float simple_bias_data[] = { 1, 2, 3 }; +const float simple_golden[] = { + 24, + 25, + 26, + 58, + 59, + 60, +}; +const int simple_output_size = 6; +int simple_output_dims[] = { 2, 2, 3 }; + +// Test data for 2x2x10 input 2x3x10 weights with negative outputs to test relu. +const int relu_input_size = 20; +int relu_input_dims[] = { 2, 2, 10 }; +const float relu_input_data[] = { + 1, 2, 3, 4, 5, 6, 7, 8, -9, -10, // b = 0 + 1, 2, 3, 4, 5, 6, 7, -8, 9, -10, // b = 1 +}; +const int relu_weights_size = 30; +int relu_weights_dims[] = { 2, 3, 10 }; +const float relu_weights_data[] = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // u = 0 + -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, // u = 1 + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // u = 2 +}; +int relu_bias_dims[] = { 1, 3 }; +const float relu_bias_data[] = { 1, -2, 3 }; +const float relu_golden[] = { + 24, + 0, + 26, + 58, + 0, + 60, +}; +const int relu_output_size = 6; +int relu_output_dims[] = { 2, 2, 3 }; + +// Input and filter similar to real model. Input shape is 1x64 and output is +// 1x16. +const int representative_64x16_input_size = 64; +int representative_64x16_input_dims[] = { 2, 1, 64 }; +const float representative_64x16_input_data[] = { + 0.0000, 0.1543, 0.0000, 0.0000, 1.8520, 0.0000, 4.7844, 1.1832, + 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 1.5948, 0.0000, + 1.5948, 1.9549, 0.0000, 1.2347, 0.0000, 1.5948, 1.5948, 0.5145, + 0.0000, 0.0000, 0.0000, 0.0000, 2.6237, 0.0000, 0.0000, 0.0000, + 1.3890, 5.3503, 2.3665, 2.9838, 0.0000, 1.2861, 0.0000, 3.0867, + 0.9775, 0.0000, 5.9676, 0.0000, 0.0000, 1.4405, 0.5145, 2.5723, + 3.1896, 4.4757, 0.0000, 0.0000, 0.0000, 0.0000, 4.1671, 0.0000, + 2.8295, 3.0353, 0.0000, 2.7780, 0.0000, 0.0000, 0.0000, 0.0000 +}; +const int representative_64x16_weights_size = 64 * 16; +int representative_64x16_weights_dims[] = { 2, 16, 64 }; +const float representative_64x16_weights_data[] = { + -0.1075, 0.1245, 0.1811, -0.1302, -0.1868, 0.0679, 0.1245, 0.2321, + -0.1981, -0.2094, 0.1358, -0.1698, 0.0113, 0.0566, 0.1358, -0.2490, + 0.0000, -0.1189, -0.0170, -0.0396, -0.3113, 0.1641, -0.4188, 0.0566, + -0.4471, 0.4754, -0.0396, 0.0113, -0.0340, 0.0170, 0.0170, 0.1811, + -0.0792, 0.4981, 0.2490, -0.1924, 0.0792, 0.1868, -0.1075, -0.3962, + 0.1358, 0.2547, -0.1245, -0.0962, -0.0283, 0.4132, -0.0057, -0.5150, + 0.1019, 0.1585, -0.0962, -0.2207, -0.2377, 0.2830, 0.4471, 0.0170, + 0.0566, 0.2038, 0.1019, -0.0226, 0.2830, 0.1415, 0.0283, -0.0792, + 0.4301, 0.3226, -0.1132, 0.4981, -0.3849, -0.2943, -0.2547, -0.2264, + 0.0453, -0.0170, 0.0396, 0.1415, 0.3000, 0.2547, 0.0962, 0.2151, + -0.1585, -0.1302, -0.0057, -0.2773, 0.0283, -0.0906, 0.1302, -0.1075, + -0.0566, 0.1755, 0.2773, 0.0283, 0.0566, 0.1528, -0.0736, -0.2830, + 0.0792, 0.0962, -0.2321, -0.0113, 0.2660, -0.2887, -0.0566, 0.0057, + -0.2547, -0.0679, -0.2321, 0.0340, 0.1868, 0.2490, 0.2264, -0.3509, + 0.1585, -0.0849, -0.0623, 0.1132, 0.3396, -0.2490, 0.1528, 0.0679, + 0.1755, 0.4754, -0.0057, -0.2151, -0.1415, -0.1302, -0.2717, 0.1641, + 0.5037, -0.2321, 0.0170, -0.1755, -0.1075, -0.0226, 0.2038, -0.0340, + -0.5150, -0.3113, 0.1472, -0.0226, 0.1528, 0.1189, -0.1472, 0.0396, + -0.3000, -0.1924, -0.0283, 0.0283, 0.1641, 0.0736, 0.1472, -0.1755, + -0.1132, 0.0113, -0.1868, -0.2604, -0.3283, -0.0509, 0.0283, -0.0679, + 0.0623, 0.0792, -0.0283, -0.0962, 0.0396, 0.1641, 0.4584, 0.3226, + 0.0226, -0.1811, 0.2377, -0.1019, 0.2321, 0.1811, -0.1924, -0.0057, + 0.0736, 0.0113, 0.2547, -0.2264, -0.0170, -0.0396, 0.1245, -0.1415, + 0.1755, 0.3679, -0.2377, -0.0396, -0.1585, -0.3000, -0.1641, -0.1302, + -0.0396, -0.1698, 0.1189, 0.2434, 0.1132, -0.1245, -0.1415, 0.0453, + 0.1868, -0.0906, -0.1189, -0.0509, 0.0057, -0.1189, -0.0057, 0.0170, + -0.1924, 0.2207, 0.0792, -0.4641, -0.2660, 0.2943, 0.1358, -0.0340, + -0.3339, -0.1189, 0.0906, -0.4358, 0.0453, -0.1755, 0.1415, 0.0340, + 0.1924, -0.0057, 0.2321, -0.2094, -0.1132, 0.0000, 0.1924, -0.3000, + 0.0340, -0.3396, -0.0906, -0.0340, 0.1641, -0.0226, -0.1472, -0.1019, + 0.2377, -0.0962, -0.3396, -0.5433, 0.0906, 0.2151, -0.0679, 0.1755, + 0.1528, 0.0283, -0.4188, -0.0340, -0.0057, -0.0679, 0.0509, 0.1472, + -0.3849, -0.0113, 0.3962, 0.0849, 0.1472, 0.0340, -0.1358, 0.1641, + -0.2038, 0.2151, -0.1189, -0.3679, 0.0906, -0.0679, 0.5716, -0.0057, + -0.0736, 0.0113, 0.2830, -0.2887, 0.0396, 0.0849, -0.0736, -0.0736, + -0.3679, 0.2264, 0.0113, -0.1641, 0.0396, -0.1132, -0.0623, 0.3113, + 0.5999, -0.1415, 0.1472, -0.2038, -0.1132, -0.2377, 0.0566, 0.1755, + -0.0057, -0.0453, 0.0226, 0.1132, 0.1698, 0.0340, -0.0226, 0.0226, + 0.4415, -0.3792, 0.0792, 0.3736, -0.5999, -0.3056, -0.1924, -0.1132, + -0.0962, 0.0283, 0.0000, -0.3339, -0.3226, 0.3679, -0.0453, -0.1641, + 0.0170, 0.1302, -0.0170, -0.0509, 0.1755, -0.0283, -0.1302, -0.2887, + -0.0679, 0.0340, 0.4641, 0.2321, 0.7188, 0.3339, -0.1075, 0.4754, + -0.0226, 0.3226, -0.1528, -0.0849, 0.0509, -0.1981, 0.0113, 0.2321, + 0.2773, -0.1019, 0.4075, 0.0396, 0.0792, 0.1132, -0.0906, -0.4188, + 0.1924, -0.3679, -0.6396, 0.1358, 0.4981, 0.4132, -0.0283, 0.3849, + -0.3509, -0.0566, -0.0962, 0.3113, -0.1811, 0.4019, 0.0453, -0.0057, + -0.1868, -0.2490, -0.0792, -0.3622, 0.1924, -0.0453, -0.1528, -0.1811, + 0.5943, -0.1302, 0.3170, -0.0170, 0.0509, -0.1528, -0.1755, 0.5547, + 0.2490, -0.0906, 0.0000, 0.1698, 0.0000, 0.0340, -0.1132, -0.0509, + -0.1755, -0.2943, 0.1472, 0.0849, 0.0000, 0.1528, -0.0566, 0.1528, + -0.5264, -0.5320, -0.0736, 0.0566, 0.2604, -0.4075, 0.0962, -0.3453, + -0.1415, 0.0057, 0.3905, 0.2830, 0.3679, 0.5320, -0.2660, 0.0340, + 0.0736, 0.0057, 0.2207, 0.4471, 0.0849, 0.3000, -0.0057, -0.0623, + 0.1415, -0.0566, 0.5264, -0.0340, 0.0226, -0.0623, -0.0113, -0.5037, + -0.4471, 0.0170, -0.0396, -0.1358, -0.1698, 0.1924, 0.0057, -0.1585, + 0.0849, -0.1698, 0.0057, -0.1245, -0.0170, -0.1755, -0.0792, 0.5264, + 0.1358, 0.2434, 0.1585, -0.4188, -0.1472, -0.1358, -0.0849, -0.1189, + 0.5037, 0.0736, -0.0453, -0.2434, 0.1868, -0.0679, 0.1415, -0.2717, + 0.2604, 0.0057, -0.1528, -0.1811, 0.0226, -0.1641, 0.3170, -0.1981, + 0.1245, 0.0226, 0.0566, 0.2830, -0.1755, 0.0396, -0.2094, 0.1924, + 0.1698, 0.0283, 0.1641, 0.0849, 0.0000, -0.1698, -0.1415, -0.3000, + 0.4471, 0.3056, -0.0283, -0.4245, -0.0453, 0.0226, 0.0000, -0.1075, + -0.1528, -0.3226, 0.2773, -0.2264, -0.1811, 0.1755, -0.3566, -0.4188, + 0.1755, -0.0057, 0.2038, 0.1075, 0.3679, -0.0792, 0.2207, -0.0453, + 0.3736, 0.2943, -0.0113, -0.0623, 0.2264, 0.0113, -0.0396, -0.2207, + 0.0453, -0.2830, -0.1302, 0.0623, -0.1924, -0.1811, -0.2717, 0.2830, + 0.2094, 0.0170, -0.3170, -0.0283, -0.1189, -0.0509, -0.0566, -0.3622, + 0.1132, -0.0906, 0.1132, 0.4019, -0.4698, -0.1019, -0.1075, -0.2094, + -0.2207, -0.0509, 0.0057, 0.1019, -0.0509, 0.2264, -0.5716, 0.0226, + -0.4019, 0.1641, -0.3000, 0.3849, 0.1245, 0.0679, 0.3056, 0.2377, + 0.0679, -0.0170, -0.5377, -0.0170, 0.0057, 0.1358, -0.1132, -0.2038, + 0.0679, 0.1075, -0.2773, 0.5943, 0.0623, -0.1472, 0.3566, 0.0396, + -0.2377, 0.2604, 0.0849, 0.1358, -0.3792, -0.0340, -0.1415, 0.3566, + -0.3736, 0.1245, 0.0566, 0.3396, 0.0736, 0.4019, -0.1528, 0.1075, + 0.0792, -0.2547, 0.0453, -0.1755, 0.1868, -0.2547, 0.1075, 0.0623, + 0.1698, -0.0170, 0.1585, -0.0736, -0.4358, -0.0113, -0.6792, -0.0849, + -0.0396, -0.6056, 0.1358, 0.1189, 0.2547, 0.1528, 0.2887, 0.0453, + -0.1075, -0.3283, -0.0453, -0.0509, 0.2038, 0.2547, 0.0849, -0.0566, + -0.1698, 0.0509, -0.0113, -0.1585, 0.1924, -0.0792, -0.1868, 0.0509, + -0.1698, -0.0849, -0.0170, 0.0453, 0.3170, 0.0906, -0.5943, -0.1245, + 0.1585, -0.1755, -0.2151, 0.0906, 0.1924, 0.3170, -0.2490, -0.5660, + -0.0283, 0.0962, -0.1358, 0.1585, 0.0057, -0.2604, 0.1189, -0.0170, + 0.3509, 0.0623, 0.0679, -0.1302, -0.0792, 0.0906, -0.0792, 0.0849, + -0.1924, 0.2604, -0.1245, -0.3679, 0.0340, 0.0113, -0.1698, 0.2490, + 0.0283, 0.1019, -0.3736, 0.1019, -0.2207, -0.0340, 0.3170, 0.1755, + 0.0962, 0.3226, -0.0113, -0.1189, -0.2321, -0.0226, -0.2434, -0.0170, + -0.1585, -0.0283, -0.1132, 0.0679, -0.4188, -0.0453, 0.1528, -0.1302, + -0.3792, 0.1415, -0.1358, -0.1811, 0.1302, 0.1415, 0.5207, 0.0509, + -0.1358, -0.0396, -0.2434, 0.0396, 0.0792, -0.2264, -0.1415, 0.0906, + 0.1245, 0.0170, 0.0623, -0.1415, 0.2773, -0.3566, -0.0396, 0.2887, + 0.4188, 0.1698, -0.2547, 0.1132, -0.0453, -0.0113, -0.1358, 0.1075, + 0.0566, 0.1075, 0.2604, -0.0849, -0.2490, 0.1415, 0.0509, -0.2151, + 0.0340, 0.1698, 0.0509, -0.0906, 0.0566, -0.1075, -0.2151, 0.2038, + -0.1924, -0.0113, 0.2830, 0.1358, -0.1189, 0.0113, -0.5603, -0.2830, + -0.2943, 0.0453, -0.0396, 0.1358, 0.0566, 0.2038, -0.3283, -0.0509, + 0.0509, 0.1641, 0.2094, -0.2038, -0.1868, -0.1585, -0.2207, -0.1302, + 0.0396, -0.1019, -0.0679, 0.1075, -0.4584, -0.2207, 0.2434, -0.0113, + 0.0849, 0.1755, -0.3056, 0.1585, -0.2547, 0.0453, 0.0906, -0.1358, + -0.0679, -0.0509, 0.0679, -0.3509, 0.0057, 0.0453, 0.4132, -0.1981, + 0.2264, -0.0736, 0.1075, 0.0679, -0.0906, -0.3113, 0.0509, 0.0849, + 0.2604, 0.0623, -0.3113, 0.3849, 0.0000, 0.6396, -0.2038, -0.1019, + 0.1245, -0.0453, 0.1641, 0.1075, -0.1075, -0.2660, -0.4528, -0.0566, + -0.0170, 0.0453, 0.0340, 0.1189, -0.2434, -0.0283, -0.1811, 0.2547, + 0.0000, -0.0226, 0.4471, 0.1019, -0.1472, 0.0849, 0.1075, 0.1075, + 0.0283, -0.2773, 0.4415, -0.1811, 0.2717, 0.3170, 0.0509, 0.0623, + -0.0962, 0.1585, -0.0792, -0.1811, -0.0792, -0.3283, 0.0962, -0.1698, + -0.0736, 0.0453, 0.0962, -0.3566, -0.4584, 0.3396, -0.4811, 0.3056, + -0.1755, 0.2490, -0.1698, -0.2377, -0.3339, -0.0453, 0.1811, 0.0736, + 0.0340, -0.0962, -0.0113, -0.3056, -0.3339, 0.2038, 0.2038, -0.1924, + 0.2547, -0.4471, -0.0849, -0.2038, 0.3566, -0.4811, 0.3453, 0.0849, + 0.1189, 0.3170, -0.1358, 0.2717, 0.0113, -0.4754, -0.1924, 0.4245, + -0.2773, 0.3453, 0.2264, 0.2943, 0.5320, 0.2773, -0.2264, -0.1019, + -0.1132, -0.3962, 0.3679, 0.0509, -0.0623, -0.0906, -0.5603, -0.1641, + -0.3170, -0.2377, 0.1415, -0.0509, 0.0792, 0.0170, -0.0226, -0.0057, + -0.1358, -0.4245, 0.3905, 0.3113, 0.0340, -0.1189, 0.2887, -0.2943, + -0.3056, 0.2434, 0.1019, -0.0170, 0.3849, 0.1528, -0.0736, -0.0170, + 0.0792, 0.1755, 0.0509, 0.3509, 0.1472, 0.1528, 0.1472, 0.0057, + 0.0113, -0.0113, -0.3283, -0.3962, -0.0792, -0.1245, -0.0283, -0.1868, + 0.4019, 0.2943, -0.0906, -0.2321, 0.6056, 0.1189, 0.0340, -0.2207, + -0.0453, 0.3339, 0.2377, -0.1641, 0.3736, 0.2151, -0.2547, 0.0453, + 0.1924, -0.1019, -0.0340, -0.2207, 0.3962, -0.4471, -0.2547, -0.2151, + -0.3736, 0.0283, 0.1189, 0.0283, 0.0736, 0.0396, 0.1019, 0.0283, + 0.0170, 0.2321, 0.3509, -0.0226, -0.0226, 0.0736, 0.0283, 0.1641, + -0.0906, 0.1811, 0.0226, 0.5716, -0.0396, -0.0509, -0.1641, -0.0509, + 0.4132, -0.2604, 0.1019, -0.0283, -0.0340, 0.0453, 0.1472, -0.0057, + 0.2717, -0.2094, 0.3396, 0.0340, 0.1245, 0.2547, -0.5886, 0.2717, + -0.0906, 0.1641, 0.0962, -0.0792, -0.0113, 0.2264, -0.0736, 0.3170, + 0.0623, 0.0679, 0.0623, -0.0792, -0.2207, 0.1924, 0.1245, -0.2773 +}; +int representative_64x16_bias_dims[] = { 1, 16 }; +const float representative_64x16_bias_data[] = { + -0.0084, 0.0006, 0.0000, 0.0000, -0.0087, -0.0006, -0.0003, -0.0003, + 0.0006, -0.0003, -0.0003, -0.0003, -0.0253, 0.0012, 0.0000, 0.0000 +}; +const float representative_64x16_golden[] = { + 3.8624, -2.9580, 4.3043, -1.2844, -1.5769, -2.7998, -0.1011, -3.4029, + -1.0557, -7.1931, -1.4852, -0.4163, 1.7186, -0.6965, 0.3580, 2.7378 +}; +const int representative_64x16_output_size = 16; +int representative_64x16_output_dims[] = { 2, 1, 16 }; + +template +TfLiteStatus ValidateFullyConnectedGoldens( + TfLiteTensor *tensors, const int tensors_size, + const TfLiteFusedActivation activation, const float tolerance, + const int output_len, const T *golden, T *output_data) +{ + TfLiteFullyConnectedParams builtin_data = { + activation, kTfLiteFullyConnectedWeightsFormatDefault, false, false + }; + + int inputs_array_data[] = { 3, 0, 1, 2 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 3 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = Register_FULLY_CONNECTED(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + reinterpret_cast(&builtin_data)); + + TfLiteStatus status = runner.InitAndPrepare(); + if (status != kTfLiteOk) { + return status; + } + + status = runner.Invoke(); + if (status != kTfLiteOk) { + return status; + } + + for (int i = 0; i < output_len; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(golden[i], output_data[i], tolerance); + } + return kTfLiteOk; +} + +#if !defined(XTENSA) // Needed to avoid build error from unused functions. +TfLiteStatus TestFullyConnectedFloat( + int *input_dims_data, const float *input_data, int *weights_dims_data, + const float *weights_data, int *bias_dims_data, const float *bias_data, + const float *golden, int *output_dims_data, + TfLiteFusedActivation activation, float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *weights_dims = IntArrayFromInts(weights_dims_data); + TfLiteIntArray *bias_dims = IntArrayFromInts(bias_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int inputs_size = 3; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(weights_data, weights_dims), + CreateTensor(bias_data, bias_dims), + CreateTensor(output_data, output_dims), + }; + + return ValidateFullyConnectedGoldens(tensors, tensors_size, activation, 1e-4f, + output_dims_count, golden, output_data); +} +#endif + +template +TfLiteStatus TestFullyConnectedQuantized( + int *input_dims_data, const float *input_data, T *input_quantized, + const float input_scale, const int input_zero_point, int *weights_dims_data, + const float *weights_data, T *weights_quantized, const float weights_scale, + const int weights_zero_point, int *bias_dims_data, const float *bias_data, + int32_t *bias_quantized, const float *golden, T *golden_quantized, + int *output_dims_data, const float output_scale, + const int output_zero_point, TfLiteFusedActivation activation, + T *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *weights_dims = IntArrayFromInts(weights_dims_data); + TfLiteIntArray *bias_dims = IntArrayFromInts(bias_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int inputs_size = 3; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(input_data, input_quantized, input_dims, + input_scale, input_zero_point), + CreateQuantizedTensor(weights_data, weights_quantized, weights_dims, + weights_scale, weights_zero_point), + CreateQuantizedBiasTensor(bias_data, bias_quantized, bias_dims, + input_scale, weights_scale), + CreateQuantizedTensor(output_data, output_dims, output_scale, + output_zero_point), + }; + + Quantize(golden, golden_quantized, output_dims_count, output_scale, + output_zero_point); + + return ValidateFullyConnectedGoldens(tensors, tensors_size, activation, 0.0f, + output_dims_count, golden_quantized, + output_data); +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +#if !defined(XTENSA) && !defined(CEVA_BX1) && !defined(CEVA_SP500) +// TODO(b/170503075): xtensa kernels are less general +// than reference kernels and we ifdef out test cases that are currently known +// to fail. + +// CEVA's fully connected implementation assumes weights_zero_point=0 as +// described in TFLite's quantization specification. tests which use a different +// zero point will so ifdefed out. +// See tflite quantization spec: +// https://www.tensorflow.org/lite/performance/quantization_spec +TF_LITE_MICRO_TEST(SimpleTest) +{ + float output_data[tflite::testing::simple_output_size]; + TF_LITE_MICRO_EXPECT_EQ( + tflite::testing::TestFullyConnectedFloat( + tflite::testing::simple_input_dims, + tflite::testing::simple_input_data, + tflite::testing::simple_weights_dims, + tflite::testing::simple_weights_data, + tflite::testing::simple_bias_dims, tflite::testing::simple_bias_data, + tflite::testing::simple_golden, tflite::testing::simple_output_dims, + kTfLiteActNone, output_data), + kTfLiteOk); +} + +#endif + +TF_LITE_MICRO_TEST(SimpleTestQuantizedInt8) +{ + const float input_scale = 1.0f; + const int input_zero_point = -1; + const float weights_scale = 1.0f; + const int weights_zero_point = 0; + const float output_scale = 0.5f; + const int output_zero_point = -1; + + int8_t input_quantized[tflite::testing::simple_input_size]; + int8_t weights_quantized[tflite::testing::simple_weights_size]; + int32_t bias_quantized[tflite::testing::simple_output_size]; + int8_t golden_quantized[tflite::testing::simple_output_size]; + int8_t output_data[tflite::testing::simple_output_size]; + + TF_LITE_MICRO_EXPECT_EQ( + tflite::testing::TestFullyConnectedQuantized( + tflite::testing::simple_input_dims, + tflite::testing::simple_input_data, input_quantized, input_scale, + input_zero_point, tflite::testing::simple_weights_dims, + tflite::testing::simple_weights_data, weights_quantized, + weights_scale, weights_zero_point, tflite::testing::simple_bias_dims, + tflite::testing::simple_bias_data, bias_quantized, + tflite::testing::simple_golden, golden_quantized, + tflite::testing::simple_output_dims, output_scale, output_zero_point, + kTfLiteActNone, output_data), + kTfLiteOk); +} + +TF_LITE_MICRO_TEST(SimpleTest4DInputQuantizedInt8) +{ + const float input_scale = 1.0f; + const int input_zero_point = -1; + const float weights_scale = 1.0f; + const int weights_zero_point = 0; + + const float output_scale = 0.5f; + const int output_zero_point = -1; + + int input_dims_4d[] = { 4, 1, 1, 2, 10 }; + + int8_t input_quantized[tflite::testing::simple_input_size]; + int8_t weights_quantized[tflite::testing::simple_weights_size]; + int32_t bias_quantized[tflite::testing::simple_output_size]; + int8_t golden_quantized[tflite::testing::simple_output_size]; + int8_t output_data[tflite::testing::simple_output_size]; + + TF_LITE_MICRO_EXPECT_EQ( + tflite::testing::TestFullyConnectedQuantized( + input_dims_4d, tflite::testing::simple_input_data, input_quantized, + input_scale, input_zero_point, tflite::testing::simple_weights_dims, + tflite::testing::simple_weights_data, weights_quantized, + weights_scale, weights_zero_point, tflite::testing::simple_bias_dims, + tflite::testing::simple_bias_data, bias_quantized, + tflite::testing::simple_golden, golden_quantized, + tflite::testing::simple_output_dims, output_scale, output_zero_point, + kTfLiteActNone, output_data), + kTfLiteOk); +} + +TF_LITE_MICRO_TEST(SimpleTestQuantizedInt8Relu) +{ + const float input_scale = 1.0f; + const int input_zero_point = -1; + const float weights_scale = 1.0f; + const int weights_zero_point = 0; + + const float output_scale = 0.5f; + const int output_zero_point = -128; + + int8_t input_quantized[tflite::testing::relu_input_size]; + int8_t weights_quantized[tflite::testing::relu_weights_size]; + int32_t bias_quantized[tflite::testing::relu_output_size]; + int8_t golden_quantized[tflite::testing::relu_output_size]; + int8_t output_data[tflite::testing::relu_output_size]; + + TF_LITE_MICRO_EXPECT_EQ( + tflite::testing::TestFullyConnectedQuantized( + tflite::testing::relu_input_dims, tflite::testing::relu_input_data, + input_quantized, input_scale, input_zero_point, + tflite::testing::relu_weights_dims, + tflite::testing::relu_weights_data, weights_quantized, weights_scale, + weights_zero_point, tflite::testing::relu_bias_dims, + tflite::testing::relu_bias_data, bias_quantized, + tflite::testing::relu_golden, golden_quantized, + tflite::testing::relu_output_dims, output_scale, output_zero_point, + kTfLiteActRelu, output_data), + kTfLiteOk); +} + +#if !defined(XTENSA) // TODO(b/170503075): xtensa kernels are less general than \ + // reference kernels and we ifdef out test cases that are \ + // currently known to fail. +TF_LITE_MICRO_TEST(SimpleTest4DInput) +{ + int input_dims_4d[] = { 4, 1, 1, 2, 10 }; + + float output_data[tflite::testing::simple_output_size]; + + TF_LITE_MICRO_EXPECT_EQ( + tflite::testing::TestFullyConnectedFloat( + input_dims_4d, tflite::testing::simple_input_data, + tflite::testing::simple_weights_dims, + tflite::testing::simple_weights_data, + tflite::testing::simple_bias_dims, tflite::testing::simple_bias_data, + tflite::testing::simple_golden, tflite::testing::simple_output_dims, + kTfLiteActNone, output_data), + kTfLiteOk); +} + +TF_LITE_MICRO_TEST(Representative1x64Input1x16Output) +{ + float output_data[tflite::testing::representative_64x16_output_size]; + + TF_LITE_MICRO_EXPECT_EQ( + tflite::testing::TestFullyConnectedFloat( + tflite::testing::representative_64x16_input_dims, + tflite::testing::representative_64x16_input_data, + tflite::testing::representative_64x16_weights_dims, + tflite::testing::representative_64x16_weights_data, + tflite::testing::representative_64x16_bias_dims, + tflite::testing::representative_64x16_bias_data, + tflite::testing::representative_64x16_golden, + tflite::testing::representative_64x16_output_dims, kTfLiteActNone, + output_data), + kTfLiteOk); +} + +#endif + +TF_LITE_MICRO_TEST(Representative1x64Input1x16OutputQuantizedInt8) +{ + const float input_scale = 0.051445; + const int input_zero_point = -128; + const float weights_scale = 0.005660; + const int weights_zero_point = 0; + + const float output_scale = 0.069785; + const int output_zero_point = -9; + + int8_t input_quantized[tflite::testing::representative_64x16_input_size]; + int8_t weights_quantized[tflite::testing::representative_64x16_weights_size]; + int32_t bias_quantized[tflite::testing::representative_64x16_output_size]; + int8_t golden_quantized[tflite::testing::representative_64x16_output_size]; + int8_t output_data[tflite::testing::representative_64x16_output_size]; + + TF_LITE_MICRO_EXPECT_EQ( + tflite::testing::TestFullyConnectedQuantized( + tflite::testing::representative_64x16_input_dims, + tflite::testing::representative_64x16_input_data, input_quantized, + input_scale, input_zero_point, + tflite::testing::representative_64x16_weights_dims, + tflite::testing::representative_64x16_weights_data, weights_quantized, + weights_scale, weights_zero_point, + tflite::testing::representative_64x16_bias_dims, + tflite::testing::representative_64x16_bias_data, bias_quantized, + tflite::testing::representative_64x16_golden, golden_quantized, + tflite::testing::representative_64x16_output_dims, output_scale, + output_zero_point, kTfLiteActNone, output_data), + kTfLiteOk); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/gather.cc b/components/tflite/tensorflow/lite/micro/kernels/gather.cc new file mode 100644 index 00000000..faa14bcd --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/gather.cc @@ -0,0 +1,226 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/micro_utils.h" + +namespace tflite { +namespace { + +constexpr int kInputTensor = 0; +constexpr int kInputPositions = 1; +constexpr int kOutputTensor = 0; + +template +TfLiteStatus Gather(const TfLiteGatherParams *params, + const TfLiteEvalTensor *input, + const TfLiteEvalTensor *coords, TfLiteEvalTensor *output) +{ + const InputT *input_data = tflite::micro::GetTensorData(input); + const CoordsT *coords_data = tflite::micro::GetTensorData(coords); + InputT *output_data = tflite::micro::GetTensorData(output); + const TfLiteIntArray *input_dims = input->dims; + const int input_dims_size = input_dims->size; + int axis = params->axis; + if (axis < 0) { + axis += input_dims_size; + } + TFLITE_DCHECK_GE(axis, 0); + TFLITE_DCHECK_LT(axis, input_dims_size); + + int batch_dims = params->batch_dims; + // batch_dims should be in range: [-rank(coords), rank(coords)]. + // Negative batch_dims is added with rank of coords. + const TfLiteIntArray *coords_dims = coords->dims; + const int coords_dims_size = coords_dims->size; + if (batch_dims < 0) { + batch_dims += coords_dims_size; + } + TFLITE_DCHECK_GE(batch_dims, 0); + TFLITE_DCHECK_LT(batch_dims, input_dims_size); + TFLITE_DCHECK_LE(batch_dims, coords_dims_size); + TFLITE_DCHECK_GE(axis, batch_dims); + for (int i = 0; i < batch_dims; ++i) { + TFLITE_DCHECK_EQ(input_dims->data[i], coords_dims->data[i]); + } + + const int axis_size = input_dims->data[axis]; + + int batch_size = 1; + for (int i = 0; i < batch_dims; ++i) { + batch_size *= input_dims->data[i]; + } + int outer_size = 1; + for (int i = batch_dims; i < axis; ++i) { + outer_size *= input_dims->data[i]; + } + int inner_size = 1; + for (int i = axis + 1; i < input_dims_size; ++i) { + inner_size *= input_dims->data[i]; + } + int coord_size = 1; + for (int i = batch_dims; i < coords_dims_size; ++i) { + coord_size *= coords_dims->data[i]; + } + + for (int batch = 0; batch < batch_size; ++batch) { + for (int outer = 0; outer < outer_size; ++outer) { + for (int coord = 0; coord < coord_size; ++coord) { + TFLITE_DCHECK_GE(coords_data[coord], 0); + TFLITE_DCHECK_LT(coords_data[coord], axis_size); + std::memcpy(output_data + + (((batch * outer_size) + outer) * coord_size + coord) * + inner_size, + input_data + (((batch * outer_size) + outer) * axis_size + + coords_data[batch * coord_size + coord]) * + inner_size, + sizeof(InputT) * inner_size); + } + } + } + return kTfLiteOk; +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE_EQ(context, NumInputs(node), 2); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + + const auto *params = + reinterpret_cast(node->builtin_data); + const TfLiteTensor *input; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, kInputTensor, &input)); + const TfLiteTensor *coords; + TF_LITE_ENSURE_OK(context, + GetInputSafe(context, node, kInputPositions, &coords)); + TfLiteTensor *output; + TF_LITE_ENSURE_OK(context, + GetOutputSafe(context, node, kOutputTensor, &output)); + switch (coords->type) { + case kTfLiteInt32: + break; + default: + TF_LITE_KERNEL_LOG(context, + "Positions of type '%s' are not supported by gather.", + TfLiteTypeGetName(coords->type)); + return kTfLiteError; + break; + } + + // Assign to output the input type. + output->type = input->type; + + // Check conditions for different types. + switch (input->type) { + case kTfLiteFloat32: + case kTfLiteInt8: + break; + default: + TF_LITE_KERNEL_LOG(context, "Type '%s' is not supported by gather.", + TfLiteTypeGetName(input->type)); + return kTfLiteError; + break; + } + + int axis = params->axis; + if (axis < 0) { + axis += NumDimensions(input); + } + TF_LITE_ENSURE(context, 0 <= axis && axis < NumDimensions(input)); + + int batch_dims = params->batch_dims; + // batch_dims should be in range: [-rank(coords), rank(coords)]. + // Negative batch_dims is added with rank of coords. + if (batch_dims < 0) { + batch_dims += NumDimensions(coords); + } + TF_LITE_ENSURE(context, batch_dims <= axis); + TF_LITE_ENSURE(context, 0 <= batch_dims && batch_dims < NumDimensions(input)); + TF_LITE_ENSURE(context, batch_dims <= NumDimensions(coords)); + for (int i = 0; i < batch_dims; ++i) { + TF_LITE_ENSURE_EQ(context, input->dims->data[i], coords->dims->data[i]); + } + + // GATHER updates the output tensor dimensions, but TfLiteTensor in the + // MicroInterpreter is a temporary allocation. We must therefore relocate the + // dims from the FlatBuffer to the persistant storage arena. + TfLiteEvalTensor *output_eval = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + TF_LITE_ENSURE_OK(context, tflite::micro::CreateWritableTensorDimsWithCopy( + context, output, output_eval)); + + TfLiteIntArray *output_shape = output->dims; + output_shape->size = + NumDimensions(input) + NumDimensions(coords) - 1 - batch_dims; + int output_index = 0; + for (int i = 0; i < axis; ++i) { + output_shape->data[output_index++] = input->dims->data[i]; + } + for (int i = batch_dims; i < coords->dims->size; ++i) { + output_shape->data[output_index++] = coords->dims->data[i]; + } + for (int i = axis + 1; i < input->dims->size; ++i) { + output_shape->data[output_index++] = input->dims->data[i]; + } + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const auto *params = + reinterpret_cast(node->builtin_data); + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + const TfLiteEvalTensor *coords = + tflite::micro::GetEvalInput(context, node, kInputPositions); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + if (coords->type == kTfLiteInt32) { + switch (input->type) { + case kTfLiteFloat32: + return Gather(params, input, coords, output); + break; + case kTfLiteInt8: + return Gather(params, input, coords, output); + break; + default: + TF_LITE_KERNEL_LOG(context, "Type '%s' is not supported by gather.", + TfLiteTypeGetName(input->type)); + return kTfLiteError; + break; + } + } + return kTfLiteOk; +} +} // namespace + +TfLiteRegistration Register_GATHER() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/gather_nd.cc b/components/tflite/tensorflow/lite/micro/kernels/gather_nd.cc new file mode 100644 index 00000000..1b64786c --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/gather_nd.cc @@ -0,0 +1,206 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/micro_utils.h" + +namespace tflite { +namespace { + +constexpr int kParams = 0; +constexpr int kIndices = 1; +constexpr int kOutputTensor = 0; +constexpr int MAX_INDICES_ND = 5; + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE_EQ(context, NumInputs(node), 2); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + + const TfLiteTensor *params; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, kParams, ¶ms)); + const TfLiteTensor *indices; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, kIndices, &indices)); + TfLiteTensor *output; + TF_LITE_ENSURE_OK(context, + GetOutputSafe(context, node, kOutputTensor, &output)); + + switch (params->type) { + case kTfLiteFloat32: + case kTfLiteInt8: + break; + default: + TF_LITE_KERNEL_LOG(context, + "Params of type '%s' are not supported by gather_nd.", + TfLiteTypeGetName(params->type)); + return kTfLiteError; + break; + } + switch (indices->type) { + case kTfLiteInt32: + break; + default: + TF_LITE_KERNEL_LOG(context, + "Indices of type '%s' are not supported by gather_nd.", + TfLiteTypeGetName(indices->type)); + return kTfLiteError; + } + + const int params_rank = NumDimensions(params); + const int indices_rank = NumDimensions(indices); + const int indices_nd = SizeOfDimension(indices, indices_rank - 1); + if (params_rank < 1) { + TF_LITE_KERNEL_LOG(context, "Params must be at least a vector."); + return kTfLiteError; + } + if (indices_rank < 1) { + TF_LITE_KERNEL_LOG(context, "Indices must be at least a vector."); + return kTfLiteError; + } + if (indices_nd > params_rank) { + TF_LITE_KERNEL_LOG( + context, "Index innermost dimension length must be <= params rank."); + return kTfLiteError; + } + if (indices_nd > MAX_INDICES_ND) { + TF_LITE_KERNEL_LOG(context, + "Index innermost dimension length must not exceed %d.", + MAX_INDICES_ND); + return kTfLiteError; + } + + // Assign to output the input type. + output->type = params->type; + + // TFLM gather_nd does not create the output tensor, but it needs to ensure + // that the output shape is correct. The result shape is + // indices.shape[:-1] + params.shape[indices.shape[-1]:] + TfLiteIntArray *output_shape = output->dims; + int output_index = 0; + for (int i = 0; i < indices_rank - 1; ++i) { + output_shape->data[output_index++] = indices->dims->data[i]; + } + for (int i = indices_nd; i < params_rank; ++i) { + output_shape->data[output_index++] = params->dims->data[i]; + } + output_shape->size = output_index; + return kTfLiteOk; +} + +template +TfLiteStatus GatherNd(const TfLiteEvalTensor *params, + const TfLiteEvalTensor *indices, + TfLiteEvalTensor *output) +{ + const int indices_dims = indices->dims->size; + const int indices_nd = indices->dims->data[indices_dims - 1]; + const int params_dims = params->dims->size; + const IndicesT *index_data = tflite::micro::GetTensorData(indices); + const ParamsT *param_data = tflite::micro::GetTensorData(params); + ParamsT *output_data = tflite::micro::GetTensorData(output); + + int n_slices = 1; + for (int i = 0; i < indices_dims - 1; ++i) { + n_slices *= indices->dims->data[i]; + } + + // If indices[-1] == params.rank, fetch single elements. + // If indices[-1] < params.rank, fetch slices. + int slice_size = 1; + for (int i = indices_nd; i < params_dims; ++i) { + slice_size *= params->dims->data[i]; + } + + int remain_flat_size = ElementCount(*params->dims); + + // Number of elements per dimension + int dims_to_count[MAX_INDICES_ND]; + for (int i = 0; i < indices_nd; ++i) { + dims_to_count[i] = remain_flat_size / params->dims->data[i]; + remain_flat_size = dims_to_count[i]; + } + + for (int i = 0; i < n_slices; ++i) { + int from_pos = 0; + for (int j = 0; j < indices_nd; ++j) { + int offset = i * indices_nd + j; + IndicesT index = index_data[offset]; + from_pos += index * dims_to_count[j]; + } + std::memcpy(output_data + i * slice_size, param_data + from_pos, + sizeof(ParamsT) * slice_size); + } + return kTfLiteOk; +} + +template +TfLiteStatus EvalGatherNd(TfLiteContext *context, + const TfLiteEvalTensor *params, + const TfLiteEvalTensor *indices, + TfLiteEvalTensor *output) +{ + switch (params->type) { + case kTfLiteFloat32: + return GatherNd(params, indices, output); + break; + case kTfLiteInt8: + return GatherNd(params, indices, output); + break; + default: + TF_LITE_KERNEL_LOG(context, + "Params type '%s' are not supported by gather_nd.", + TfLiteTypeGetName(params->type)); + return kTfLiteError; + } +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *params = + tflite::micro::GetEvalInput(context, node, kParams); + const TfLiteEvalTensor *indices = + tflite::micro::GetEvalInput(context, node, kIndices); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + switch (indices->type) { + case kTfLiteInt32: + return EvalGatherNd(context, params, indices, output); + break; + default: + TF_LITE_KERNEL_LOG(context, + "Indices of type '%s' are not supported by gather_nd.", + TfLiteTypeGetName(indices->type)); + return kTfLiteError; + } +} +} // namespace + +TfLiteRegistration Register_GATHER_ND() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/gather_nd_test.cc b/components/tflite/tensorflow/lite/micro/kernels/gather_nd_test.cc new file mode 100644 index 00000000..1255bfba --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/gather_nd_test.cc @@ -0,0 +1,316 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +template +void TestGatherNd(int *param_dims, const ParamType *param_data, int *index_dims, + const IndexType *index_data, int *output_dims, + ParamType *output_data, + const ParamType *expected_output_data) +{ + TfLiteIntArray *pdims = IntArrayFromInts(param_dims); + TfLiteIntArray *idims = IntArrayFromInts(index_dims); + TfLiteIntArray *odims = IntArrayFromInts(output_dims); + + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(param_data, pdims), + CreateTensor(index_data, idims), + CreateTensor(output_data, odims), + }; + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = Register_GATHER_ND(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, /*builtin_data=*/nullptr); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + // The output tensor's data and shape have been updated by the kernel. + TfLiteTensor *actual_output_tensor = &tensors[2]; + TfLiteIntArray *actual_output_dims = actual_output_tensor->dims; + const int output_size = ElementCount(*actual_output_dims); + for (int i = 0; i < output_size; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output_data[i], output_data[i]); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(GatherNd_ElementIndexingIntoMatrix) +{ + // For input_dims[], index_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + int input_dims[] = { 2, 2, 2 }; + int index_dims[] = { 2, 2, 2 }; + const int32_t index_data[] = { 0, 0, 1, 1 }; + const float input_data[] = { 1.1, 1.2, 2.1, 2.2 }; + const float golden_data[] = { 1.1, 2.2 }; + float output_data[2]; + int output_dims[] = { 1, 0 }; + tflite::testing::TestGatherNd( + input_dims, input_data, index_dims, index_data, output_dims, output_data, + golden_data); +} + +TF_LITE_MICRO_TEST(GatherNd_SliceIndexingIntoMatrix) +{ + // For input_dims[], index_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + int input_dims[] = { 2, 2, 2 }; + int index_dims[] = { 2, 2, 1 }; + const int32_t index_data[] = { 1, 0 }; + const float input_data[] = { 1.1, 1.2, 2.1, 2.2 }; + const float golden_data[] = { 2.1, 2.2, 1.1, 1.2 }; + float output_data[4]; + int output_dims[] = { 2, 0, 0 }; + tflite::testing::TestGatherNd( + input_dims, input_data, index_dims, index_data, output_dims, output_data, + golden_data); +} + +TF_LITE_MICRO_TEST(GatherNd_BatchedIndexingIntoMatrix1) +{ + // For input_dims[], index_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + int input_dims[] = { 2, 2, 2 }; + int index_dims[] = { 3, 2, 1, 1 }; + const int32_t index_data[] = { 1, 0 }; + const float input_data[] = { 1.1, 1.2, 2.1, 2.2 }; + const float golden_data[] = { 2.1, 2.2, 1.1, 1.2 }; + float output_data[4]; + int output_dims[] = { 3, 0, 0, 0 }; + tflite::testing::TestGatherNd( + input_dims, input_data, index_dims, index_data, output_dims, output_data, + golden_data); +} + +TF_LITE_MICRO_TEST(GatherNd_BatchedIndexingIntoMatrix2) +{ + // For input_dims[], index_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + int input_dims[] = { 2, 2, 2 }; + int index_dims[] = { 3, 2, 1, 2 }; + const int32_t index_data[] = { 0, 0, 1, 1 }; + const float input_data[] = { 1.1, 1.2, 2.1, 2.2 }; + const float golden_data[] = { 1.1, 2.2 }; + float output_data[2]; + int output_dims[] = { 3, 0, 0, 0 }; + tflite::testing::TestGatherNd( + input_dims, input_data, index_dims, index_data, output_dims, output_data, + golden_data); +} + +TF_LITE_MICRO_TEST(GatherNd_DuplicateIndexingIntoMatrix) +{ + // For input_dims[], index_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + int input_dims[] = { 2, 2, 2 }; + int index_dims[] = { 2, 2, 2 }; + const int32_t index_data[] = { 0, 0, 0, 0 }; + const float input_data[] = { 1.1, 1.2, 2.1, 2.2 }; + const float golden_data[] = { 1.1, 1.1 }; + float output_data[2]; + int output_dims[] = { 1, 0 }; + tflite::testing::TestGatherNd( + input_dims, input_data, index_dims, index_data, output_dims, output_data, + golden_data); +} + +TF_LITE_MICRO_TEST(GatherNd_ElementIndexingIntoRank3Tensor) +{ + // For input_dims[], index_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + int input_dims[] = { 3, 3, 2, 3 }; + int index_dims[] = { 3, 1, 2, 3 }; + const int32_t index_data[] = { 0, 0, 1, 1, 1, 0 }; + const float input_data[] = { 1.1, -1.2, 1.3, -2.1, 2.2, 2.3, // + 3.1, 3.2, -3.3, -4.1, -4.2, 4.3, // + 5.1, -5.2, 5.3, 6.1, -6.2, 6.3 }; + const float golden_data[] = { -1.2, -4.1 }; + float output_data[2]; + int output_dims[] = { 2, 0, 0 }; + tflite::testing::TestGatherNd( + input_dims, input_data, index_dims, index_data, output_dims, output_data, + golden_data); +} + +TF_LITE_MICRO_TEST(GatherNd_SliceIndexingIntoRank3Tensor) +{ + // For input_dims[], index_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + int input_dims[] = { 3, 3, 2, 3 }; + int index_dims[] = { 2, 2, 1 }; + const int32_t index_data[] = { 0, 2 }; + const float input_data[] = { 1.1, -1.2, 1.3, -2.1, 2.2, 2.3, // + 3.1, 3.2, -3.3, -4.1, -4.2, 4.3, // + 5.1, -5.2, 5.3, 6.1, -6.2, 6.3 }; + const float golden_data[] = { 1.1, -1.2, 1.3, -2.1, 2.2, 2.3, + 5.1, -5.2, 5.3, 6.1, -6.2, 6.3 }; + float output_data[12]; + int output_dims[] = { 3, 0, 0, 0 }; + tflite::testing::TestGatherNd( + input_dims, input_data, index_dims, index_data, output_dims, output_data, + golden_data); +} + +TF_LITE_MICRO_TEST(GatherNd_BatchedIndexingIntoRank3Tensor1) +{ + // For input_dims[], index_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + int input_dims[] = { 3, 3, 2, 3 }; + int index_dims[] = { 3, 2, 1, 3 }; + const int32_t index_data[] = { 0, 0, 1, 1, 1, 0 }; + const float input_data[] = { 1.1, -1.2, 1.3, -2.1, 2.2, 2.3, // + 3.1, 3.2, -3.3, -4.1, -4.2, 4.3, // + 5.1, -5.2, 5.3, 6.1, -6.2, 6.3 }; + const float golden_data[] = { -1.2, -4.1 }; + float output_data[2]; + int output_dims[] = { 2, 0, 0 }; + tflite::testing::TestGatherNd( + input_dims, input_data, index_dims, index_data, output_dims, output_data, + golden_data); +} + +TF_LITE_MICRO_TEST(GatherNd_BatchedIndexingIntoRank3Tensor2) +{ + // For input_dims[], index_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + int input_dims[] = { 3, 3, 2, 3 }; + int index_dims[] = { 3, 3, 1, 1 }; + const int32_t index_data[] = { 1, 2, 0 }; + const float input_data[] = { 1.1, -1.2, 1.3, -2.1, 2.2, 2.3, // + 3.1, 3.2, -3.3, -4.1, -4.2, 4.3, // + 5.1, -5.2, 5.3, 6.1, -6.2, 6.3 }; + const float golden_data[] = { 3.1, 3.2, -3.3, -4.1, -4.2, 4.3, + 5.1, -5.2, 5.3, 6.1, -6.2, 6.3, + 1.1, -1.2, 1.3, -2.1, 2.2, 2.3 }; + float output_data[18]; + int output_dims[] = { 4, 0, 0, 0, 0 }; + tflite::testing::TestGatherNd( + input_dims, input_data, index_dims, index_data, output_dims, output_data, + golden_data); +} + +TF_LITE_MICRO_TEST(GatherNd_BatchedIndexingIntoRank3Tensor3) +{ + // For input_dims[], index_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + int input_dims[] = { 3, 3, 2, 3 }; + int index_dims[] = { 3, 2, 2, 2 }; + const int32_t index_data[] = { 0, 1, 1, 0, 0, 0, 2, 1 }; + const float input_data[] = { 1.1, -1.2, 1.3, -2.1, 2.2, 2.3, // + 3.1, 3.2, -3.3, -4.1, -4.2, 4.3, // + 5.1, -5.2, 5.3, 6.1, -6.2, 6.3 }; + const float golden_data[] = { -2.1, 2.2, 2.3, 3.1, 3.2, -3.3, + 1.1, -1.2, 1.3, 6.1, -6.2, 6.3 }; + float output_data[12]; + int output_dims[] = { 3, 0, 0, 0 }; + tflite::testing::TestGatherNd( + input_dims, input_data, index_dims, index_data, output_dims, output_data, + golden_data); +} + +TF_LITE_MICRO_TEST(GatherNd_BatchedIndexingIntoRank3Tensor4) +{ + // For input_dims[], index_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + int input_dims[] = { 3, 3, 2, 3 }; + int index_dims[] = { 3, 2, 2, 3 }; + const int32_t index_data[] = { 0, 0, 1, 1, 0, 1, 1, 1, 2, 2, 1, 2 }; + const float input_data[] = { 1.1, -1.2, 1.3, -2.1, 2.2, 2.3, // + 3.1, 3.2, -3.3, -4.1, -4.2, 4.3, // + 5.1, -5.2, 5.3, 6.1, -6.2, 6.3 }; + const float golden_data[] = { -1.2, 3.2, 4.3, 6.3 }; + float output_data[4]; + int output_dims[] = { 2, 0, 0 }; + tflite::testing::TestGatherNd( + input_dims, input_data, index_dims, index_data, output_dims, output_data, + golden_data); +} + +TF_LITE_MICRO_TEST(GatherNd_DuplicateIndexingIntoRank3Tensor) +{ + // For input_dims[], index_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + int input_dims[] = { 3, 3, 2, 3 }; + int index_dims[] = { 2, 2, 2 }; + const int32_t index_data[] = { 0, 1, 0, 1 }; + const float input_data[] = { 1.1, -1.2, 1.3, -2.1, 2.2, 2.3, // + 3.1, 3.2, -3.3, -4.1, -4.2, 4.3, // + 5.1, -5.2, 5.3, 6.1, -6.2, 6.3 }; + const float golden_data[] = { -2.1, 2.2, 2.3, -2.1, 2.2, 2.3 }; + float output_data[6]; + int output_dims[] = { 2, 0, 0 }; + tflite::testing::TestGatherNd( + input_dims, input_data, index_dims, index_data, output_dims, output_data, + golden_data); +} + +TF_LITE_MICRO_TEST(GatherNd_Float32Int32) +{ + // For input_dims[], index_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + int input_dims[] = { 3, 3, 2, 3 }; + int index_dims[] = { 2, 2, 2 }; + const int32_t index_data[] = { 0, 1, 1, 0 }; + const float input_data[] = { 1.1, -1.2, 1.3, -2.1, 2.2, 2.3, // + 3.1, 3.2, -3.3, -4.1, -4.2, 4.3, // + 5.1, -5.2, 5.3, 6.1, -6.2, 6.3 }; + const float golden_data[] = { -2.1, 2.2, 2.3, 3.1, 3.2, -3.3 }; + float output_data[6]; + int output_dims[] = { 2, 0, 0 }; + tflite::testing::TestGatherNd( + input_dims, input_data, index_dims, index_data, output_dims, output_data, + golden_data); +} + +TF_LITE_MICRO_TEST(GatherNd_Int8Int32) +{ + // For input_dims[], index_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + int input_dims[] = { 3, 3, 2, 3 }; + int index_dims[] = { 2, 2, 2 }; + const int32_t index_data[] = { 0, 1, 1, 0 }; + const int8_t input_data[] = { 1, -1, 1, -2, 2, 2, // + 3, 3, -3, -4, -4, 4, // + 5, -5, 5, 6, -6, 6 }; + const int8_t golden_data[] = { -2, 2, 2, 3, 3, -3 }; + int8_t output_data[6]; + int output_dims[] = { 2, 0, 0 }; + tflite::testing::TestGatherNd( + input_dims, input_data, index_dims, index_data, output_dims, output_data, + golden_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/gather_test.cc b/components/tflite/tensorflow/lite/micro/kernels/gather_test.cc new file mode 100644 index 00000000..9ca3fa05 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/gather_test.cc @@ -0,0 +1,486 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +template +void TestGather(int *input_dims, const InType *input_data, int *positions_dims, + const PosType *positions_data, int *output_dims, + InType *output_data, const int *expected_output_dims, + const InType *expected_output_data, const int axis = 0, + const int batch_dims = 0) +{ + TfLiteIntArray *in_dims = IntArrayFromInts(input_dims); + TfLiteIntArray *pos_dims = IntArrayFromInts(positions_dims); + TfLiteIntArray *out_dims = IntArrayFromInts(output_dims); + TfLiteGatherParams params = { axis, batch_dims }; + + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, in_dims), + CreateTensor(positions_data, pos_dims), + CreateTensor(output_data, out_dims, true), + }; + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = Register_GATHER(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, ¶ms); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + // The output tensor's data and shape have been updated by the kernel. + TfLiteTensor *actual_output_tensor = &tensors[2]; + TfLiteIntArray *actual_output_dims = actual_output_tensor->dims; + const int actual_output_dims_size = actual_output_dims->size; + const int output_size = ElementCount(*actual_output_dims); + for (int i = 0; i < output_size; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output_data[i], output_data[i]); + } + + // Compare output tensor's shape if expected_output_dims[] is provided. + for (int i = 0; i < actual_output_dims_size; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output_dims[i], + actual_output_dims->data[i]); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +// For all test functions below, dims[0] is the dimension count. +TF_LITE_MICRO_TEST(GatherOp_Shuffle) +{ + // For input_dims[], positions_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + int input_dims[] = { 2, 2, 2 }; + int positions_dims[] = { 1, 2 }; + const int32_t positions_data[] = { 1, 0 }; + const float input_data[] = { -2.0, 0.2, 0.7, 0.8 }; + const float golden_data[] = { 0.7, 0.8, -2, 0.2 }; + float output_data[4]; + + // The kernel under test will fill output_dims[1] onward, to be compared + // against golden_dims[0] onward. + const int golden_dims[] = { 2, 2 }; + int output_dims[] = { 2, 0, 0 }; + tflite::testing::TestGather( + input_dims, input_data, positions_dims, positions_data, output_dims, + output_data, golden_dims, golden_data); +} + +TF_LITE_MICRO_TEST(GatherOp_Test0DIndex) +{ + // For input_dims[], positions_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + int input_dims[] = { 2, 2, 2 }; + int positions_dims[] = { 0 }; + const int32_t positions_data[] = { 1 }; + const float input_data[] = { -2.0, 0.2, 0.7, 0.8 }; + const float golden_data[] = { 0.7, 0.8 }; + float output_data[2]; + + // The kernel under test will fill output_dims[1] onward, to be compared + // against golden_dims[0] onward. + const int golden_dims[] = { 2 }; + int output_dims[] = { 1, 0 }; + tflite::testing::TestGather( + input_dims, input_data, positions_dims, positions_data, output_dims, + output_data, golden_dims, golden_data); +} + +TF_LITE_MICRO_TEST(GatherOp_Test0DIndexWith0DResult) +{ + // 0D tensor is special case in current TFLite. Test it once to make sure + // existing workarounds are fine with it. + // For input_dims[], positions_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + int input_dims[] = { 1, 3 }; + int positions_dims[] = { 0 }; + const int32_t positions_data[] = { 1 }; + const float input_data[] = { 1.0, 2.0, 3.0 }; + const float golden_data[] = { 2.0 }; + float output_data[1]; + + // The kernel under test will fill output_dims[1] onward, to be compared + // against golden_dims[0] onward. + const int golden_dims[] = { 0 }; + int output_dims[] = { 1, 0 }; + tflite::testing::TestGather( + input_dims, input_data, positions_dims, positions_data, output_dims, + output_data, golden_dims, golden_data); +} + +TF_LITE_MICRO_TEST(GatherOp_Test1DInput1DIndex) +{ + // For input_dims[], positions_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + int input_dims[] = { 1, 3 }; + int positions_dims[] = { 1, 1 }; + const int32_t positions_data[] = { 1 }; + const float input_data[] = { 1.0, 3.0, 5.0 }; + const float golden_data[] = { 3.0 }; + float output_data[1]; + + // The kernel under test will fill output_dims[1] onward, to be compared + // against golden_dims[0] onward. + const int golden_dims[] = { 1 }; + int output_dims[] = { 1, 0 }; + tflite::testing::TestGather( + input_dims, input_data, positions_dims, positions_data, output_dims, + output_data, golden_dims, golden_data); +} + +TF_LITE_MICRO_TEST(GatherOp_Test2DIndexWith2DResult) +{ + // For input_dims[], positions_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + int input_dims[] = { 1, 3 }; + int positions_dims[] = { 2, 1, 2 }; + const int32_t positions_data[] = { 1, 0 }; + const float input_data[] = { 1.0, 2.0, 3.0 }; + const float golden_data[] = { 2.0, 1.0 }; + float output_data[2]; + + // The kernel under test will fill output_dims[1] onward, to be compared + // against golden_dims[0] onward. + const int golden_dims[] = { 1, 2 }; + int output_dims[] = { 2, 0, 0 }; + tflite::testing::TestGather( + input_dims, input_data, positions_dims, positions_data, output_dims, + output_data, golden_dims, golden_data); +} + +TF_LITE_MICRO_TEST(GatherOp_Duplicate) +{ + // For input_dims[], positions_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + int input_dims[] = { 3, 1, 2, 2 }; + int positions_dims[] = { 1, 2 }; + const int32_t positions_data[] = { 0, 0 }; + const float input_data[] = { -2.0, 0.2, 0.7, 0.8 }; + const float golden_data[] = { -2, 0.2, 0.7, 0.8, -2, 0.2, 0.7, 0.8 }; + float output_data[8]; + + // The kernel under test will fill output_dims[1] onward, to be compared + // against golden_dims[0] onward. + const int golden_dims[] = { 2, 2, 2 }; + int output_dims[] = { 3, 0, 0, 0 }; + tflite::testing::TestGather( + input_dims, input_data, positions_dims, positions_data, output_dims, + output_data, golden_dims, golden_data); +} + +TF_LITE_MICRO_TEST(GatherOp_Slice) +{ + // For input_dims[], positions_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + int input_dims[] = { 2, 4, 1 }; + int positions_dims[] = { 1, 2 }; + const int32_t positions_data[] = { 1, 3 }; + const float input_data[] = { -2.0, 0.2, 0.7, 0.8 }; + const float golden_data[] = { 0.2, 0.8 }; + float output_data[2]; + + // The kernel under test will fill output_dims[1] onward, to be compared + // against golden_dims[0] onward. + const int golden_dims[] = { 2, 1 }; + int output_dims[] = { 2, 0, 0 }; + tflite::testing::TestGather( + input_dims, input_data, positions_dims, positions_data, output_dims, + output_data, golden_dims, golden_data); +} + +TF_LITE_MICRO_TEST(GatherOp_Axis1) +{ + // For input_dims[], positions_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + const int axis = 1; + int input_dims[] = { 3, 1, 2, 3 }; + int positions_dims[] = { 1, 2 }; + const int32_t positions_data[] = { 1, 0 }; + const float input_data[] = { 1, 2, 3, 4, 5, 6 }; + const float golden_data[] = { 4, 5, 6, 1, 2, 3 }; + float output_data[6]; + + // The kernel under test will fill output_dims[1] onward, to be compared + // against golden_dims[0] onward. + const int golden_dims[] = { 1, 2, 3 }; + int output_dims[] = { 3, 0, 0, 0 }; + tflite::testing::TestGather( + input_dims, input_data, positions_dims, positions_data, output_dims, + output_data, golden_dims, golden_data, axis); +} + +TF_LITE_MICRO_TEST(GatherOp_Axis1_0DIndex) +{ + // For input_dims[], positions_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + const int axis = 1; + int input_dims[] = { 3, 1, 3, 2 }; + int positions_dims[] = { 0 }; + const int32_t positions_data[] = { 1 }; + const float input_data[] = { 1, 2, 3, 4, 5, 6 }; + const float golden_data[] = { 3, 4 }; + float output_data[2]; + + // The kernel under test will fill output_dims[1] onward, to be compared + // against golden_dims[0] onward. + const int golden_dims[] = { 1, 2 }; + int output_dims[] = { 2, 0, 0 }; + tflite::testing::TestGather( + input_dims, input_data, positions_dims, positions_data, output_dims, + output_data, golden_dims, golden_data, axis); +} + +TF_LITE_MICRO_TEST(GatherOp_Axis1Slice) +{ + // For input_dims[], positions_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + const int axis = 1; + int input_dims[] = { 3, 1, 4, 2 }; + int positions_dims[] = { 1, 2 }; + const int32_t positions_data[] = { 3, 1 }; + const float input_data[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + const float golden_data[] = { 7, 8, 3, 4 }; + float output_data[4]; + + // The kernel under test will fill output_dims[1] onward, to be compared + // against golden_dims[0] onward. + const int golden_dims[] = { 1, 2, 2 }; + int output_dims[] = { 3, 0, 0, 0 }; + tflite::testing::TestGather( + input_dims, input_data, positions_dims, positions_data, output_dims, + output_data, golden_dims, golden_data, axis); +} + +TF_LITE_MICRO_TEST(GatherOp_LastAxis) +{ + // For input_dims[], positions_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + const int axis = -1; + int input_dims[] = { 3, 1, 2, 3 }; + int positions_dims[] = { 1, 2 }; + const int32_t positions_data[] = { 2, 0 }; + const float input_data[] = { 1, 2, 3, 4, 5, 6 }; + const float golden_data[] = { 3, 1, 6, 4 }; + float output_data[4]; + + // The kernel under test will fill output_dims[1] onward, to be compared + // against golden_dims[0] onward. + const int golden_dims[] = { 1, 2, 2 }; + int output_dims[] = { 3, 0, 0, 0 }; + tflite::testing::TestGather( + input_dims, input_data, positions_dims, positions_data, output_dims, + output_data, golden_dims, golden_data, axis); +} + +TF_LITE_MICRO_TEST(GatherOp_LastAxis0DIndex) +{ + // For input_dims[], positions_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + const int axis = -1; + int input_dims[] = { 3, 1, 2, 3 }; + int positions_dims[] = { 0 }; + const int32_t positions_data[] = { 2 }; + const float input_data[] = { 1, 2, 3, 4, 5, 6 }; + const float golden_data[] = { 3, 6 }; + float output_data[2]; + + // The kernel under test will fill output_dims[1] onward, to be compared + // against golden_dims[0] onward. + const int golden_dims[] = { 1, 2 }; + int output_dims[] = { 2, 0, 0 }; + tflite::testing::TestGather( + input_dims, input_data, positions_dims, positions_data, output_dims, + output_data, golden_dims, golden_data, axis); +} + +TF_LITE_MICRO_TEST(GatherOp_Float32Int32) +{ + // For input_dims[], positions_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + int input_dims[] = { 2, 2, 2 }; + int positions_dims[] = { 1, 2 }; + const int32_t positions_data[] = { 1, 0 }; + const float input_data[] = { 13.3, -13.4, -1.4, 1.5 }; + const float golden_data[] = { -1.4, 1.5, 13.3, -13.4 }; + float output_data[4]; + + // The kernel under test will fill output_dims[1] onward, to be compared + // against golden_dims[0] onward. + const int golden_dims[] = { 2, 2 }; + int output_dims[] = { 2, 0, 0 }; + tflite::testing::TestGather( + input_dims, input_data, positions_dims, positions_data, output_dims, + output_data, golden_dims, golden_data); +} + +TF_LITE_MICRO_TEST(GatherOp_Int8Int32) +{ + // For input_dims[], positions_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + int input_dims[] = { 2, 2, 2 }; + int positions_dims[] = { 1, 2 }; + const int32_t positions_data[] = { 1, 0 }; + const int8_t input_data[] = { -13, -120, 14, 15 }; + const int8_t golden_data[] = { 14, 15, -13, -120 }; + int8_t output_data[4]; + + // The kernel under test will fill output_dims[1] onward, to be compared + // against golden_dims[0] onward. + const int golden_dims[] = { 2, 2 }; + int output_dims[] = { 2, 0, 0 }; + tflite::testing::TestGather( + input_dims, input_data, positions_dims, positions_data, output_dims, + output_data, golden_dims, golden_data); +} + +TF_LITE_MICRO_TEST(GatherOp_BatchDims2) +{ + // For input_dims[], positions_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + const int axis = 2; + const int batch_dims = 2; + int input_dims[] = { 4, 2, 2, 3, 5 }; + int positions_dims[] = { 3, 2, 2, 2 }; + const int32_t positions_data[] = { 1, 0, 0, 1, 1, 0, 0, 1 }; + const float input_data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59 }; + const float golden_data[] = { 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 35, 36, 37, 38, 39, 30, 31, 32, 33, 34, + 45, 46, 47, 48, 49, 50, 51, 52, 53, 54 }; + float output_data[40]; + + // The kernel under test will fill output_dims[1] onward, to be compared + // against golden_dims[0] onward. + const int golden_dims[] = { 2, 2, 2, 5 }; + int output_dims[] = { 4, 0, 0, 0, 0 }; + tflite::testing::TestGather( + input_dims, input_data, positions_dims, positions_data, output_dims, + output_data, golden_dims, golden_data, axis, batch_dims); +} + +TF_LITE_MICRO_TEST(GatherOp_BatchDims1) +{ + // For input_dims[], positions_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + const int axis = 2; + const int batch_dims = 1; + int input_dims[] = { 4, 2, 2, 3, 5 }; + int positions_dims[] = { 3, 2, 2, 2 }; + const int32_t positions_data[] = { 1, 0, 0, 1, 1, 0, 0, 1 }; + const int8_t input_data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59 }; + const int8_t golden_data[] = { + 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, + 6, 7, 8, 9, 20, 21, 22, 23, 24, 15, 16, 17, 18, 19, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 35, 36, 37, 38, 39, 30, 31, 32, + 33, 34, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 50, 51, 52, 53, + 54, 45, 46, 47, 48, 49, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54 + }; + int8_t output_data[80]; + + // The kernel under test will fill output_dims[1] onward, to be compared + // against golden_dims[0] onward. + const int golden_dims[] = { 2, 2, 2, 2, 5 }; + int output_dims[] = { 5, 0, 0, 0, 0, 0 }; + tflite::testing::TestGather( + input_dims, input_data, positions_dims, positions_data, output_dims, + output_data, golden_dims, golden_data, axis, batch_dims); +} + +TF_LITE_MICRO_TEST(GatherOp_NegativeBatchDims) +{ + // For input_dims[], positions_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + const int axis = 2; + const int batch_dims = -2; + int input_dims[] = { 4, 2, 2, 3, 5 }; + int positions_dims[] = { 3, 2, 2, 2 }; + const int32_t positions_data[] = { 1, 0, 0, 1, 1, 0, 0, 1 }; + const int8_t input_data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59 }; + const int8_t golden_data[] = { + 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, + 6, 7, 8, 9, 20, 21, 22, 23, 24, 15, 16, 17, 18, 19, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 35, 36, 37, 38, 39, 30, 31, 32, + 33, 34, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 50, 51, 52, 53, + 54, 45, 46, 47, 48, 49, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54 + }; + int8_t output_data[80]; + + // The kernel under test will fill output_dims[1] onward, to be compared + // against golden_dims[0] onward. + const int golden_dims[] = { 2, 2, 2, 2, 5 }; + int output_dims[] = { 5, 0, 0, 0, 0, 0 }; + tflite::testing::TestGather( + input_dims, input_data, positions_dims, positions_data, output_dims, + output_data, golden_dims, golden_data, axis, batch_dims); +} + +TF_LITE_MICRO_TEST(GatherOp_BatchDimsEqualIndiceDims) +{ + // For input_dims[], positions_dims[], or output_dims[], element 0 is the + // number of dimensions in that array, not the actual dimension data. + const int axis = 3; + const int batch_dims = 3; + int input_dims[] = { 4, 2, 2, 2, 5 }; + int positions_dims[] = { 3, 2, 2, 2 }; + const int32_t positions_data[] = { 1, 0, 0, 1, 1, 0, 0, 1 }; + const int8_t input_data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39 }; + const int8_t golden_data[] = { 1, 5, 10, 16, 21, 25, 30, 36 }; + int8_t output_data[8]; + + // The kernel under test will fill output_dims[1] onward, to be compared + // against golden_dims[0] onward. + const int golden_dims[] = { 2, 2, 2 }; + int output_dims[] = { 3, 0, 0, 0 }; + tflite::testing::TestGather( + input_dims, input_data, positions_dims, positions_data, output_dims, + output_data, golden_dims, golden_data, axis, batch_dims); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/hard_swish.cc b/components/tflite/tensorflow/lite/micro/kernels/hard_swish.cc new file mode 100644 index 00000000..c7b9c1e0 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/hard_swish.cc @@ -0,0 +1,146 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/hard_swish.h" + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/internal/types.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/micro_utils.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace hard_swish { + +constexpr int kInputTensor = 0; +constexpr int kOutputTensor = 0; + +void *HardSwishInit(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(HardSwishParams)); +} + +TfLiteStatus HardSwishPrepare(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + + const TfLiteTensor *input = GetInput(context, node, kInputTensor); + TF_LITE_ENSURE(context, input != nullptr); + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + + if (input->type == kTfLiteUInt8 || input->type == kTfLiteInt8) { + HardSwishParams *params = static_cast(node->user_data); + + params->input_zero_point = input->params.zero_point; + params->output_zero_point = output->params.zero_point; + + const float input_scale = input->params.scale; + const float hires_input_scale = (1.0f / 128.0f) * input_scale; + const float reluish_scale = 3.0f / 32768.0f; + const float output_scale = output->params.scale; + + const double output_multiplier = + static_cast(hires_input_scale / output_scale); + int32_t output_multiplier_fixedpoint_int32; + QuantizeMultiplier(output_multiplier, &output_multiplier_fixedpoint_int32, + ¶ms->output_multiplier_exponent); + DownScaleInt32ToInt16Multiplier( + output_multiplier_fixedpoint_int32, + ¶ms->output_multiplier_fixedpoint_int16); + + TF_LITE_ENSURE(context, params->output_multiplier_exponent <= 0); + + const double reluish_multiplier = + static_cast(hires_input_scale / reluish_scale); + int32_t reluish_multiplier_fixedpoint_int32; + QuantizeMultiplier(reluish_multiplier, &reluish_multiplier_fixedpoint_int32, + ¶ms->reluish_multiplier_exponent); + DownScaleInt32ToInt16Multiplier( + reluish_multiplier_fixedpoint_int32, + ¶ms->reluish_multiplier_fixedpoint_int16); + } + + return kTfLiteOk; +} + +TfLiteStatus HardSwishEval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + HardSwishParams *params = static_cast(node->user_data); + + switch (input->type) { + case kTfLiteFloat32: { + tflite::reference_ops::HardSwish( + tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } break; + case kTfLiteUInt8: { + tflite::reference_ops::HardSwish( + *params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } break; + case kTfLiteInt8: { + tflite::reference_ops::HardSwish( + *params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } break; + default: { + TF_LITE_KERNEL_LOG( + context, + "Only float32/int8_t/uint8_t are supported currently, got %s", + TfLiteTypeGetName(input->type)); + return kTfLiteError; + } + } + return kTfLiteOk; +} + +} // namespace hard_swish + +TfLiteRegistration Register_HARD_SWISH() +{ + return { /*init=*/hard_swish::HardSwishInit, + /*free=*/nullptr, + /*prepare=*/hard_swish::HardSwishPrepare, + /*invoke=*/hard_swish::HardSwishEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/hard_swish_test.cc b/components/tflite/tensorflow/lite/micro/kernels/hard_swish_test.cc new file mode 100644 index 00000000..b1ad474e --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/hard_swish_test.cc @@ -0,0 +1,353 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +void GenerateUniformRandomVector(int size, float min, float max, + std::minstd_rand *random_engine, + float *result) +{ + // Never use std::uniform_*_distribution in tests, it's + // implementation-defined. Likewise, don't use std::default_random_engine, + // implementation-defined. Implementation-defined is bad because it means that + // any toolchain update or new platform may run into test failures. + // std::minstd_rand is a standard instantiation of + // std::linear_congruential_engine, the cheapest generator in c++11 stdlib, + // it's good enough here. + for (int i = 0; i < size; i++) { + // We don't care whether the `max` value may ever be produced exactly. + // It may actually be thanks to rounding, as std::minstd_rand::modulus + // is 2^31 - 1 is greater than the inverse float epsilon. + float random_value_scaled_0_1 = + (*random_engine)() * + (1.0f / static_cast(std::minstd_rand::modulus)); + result[i] = min + (max - min) * random_value_scaled_0_1; + } +} + +void EvalTestReferenceHardSwish(int size, float *input, float *result) +{ + for (int i = 0; i < size; i++) { + const float in = input[i]; + result[i] = in * std::min(6.0f, std::max(0.0f, in + 3)) * (1.0f / 6.0f); + } +} + +template +void TestHardSwishQuantized(int size, const T *output_data, + T *input_data_quantized, float *dequantized_output, + float input_min, float input_max, float output_min, + float output_max, std::minstd_rand *random_engine, + float *float_input_values, + float *float_ref_output_values) +{ + int input_dims_data[] = { 2, 1, size }; + int output_dims_data[] = { 2, 1, size }; + const float input_scale = ScaleFromMinMax(input_min, input_max); + const int input_zero_point = ZeroPointFromMinMax(input_min, input_max); + const float output_scale = ScaleFromMinMax(output_min, output_max); + const int output_zero_point = ZeroPointFromMinMax(output_min, output_max); + + // The numerical error for any 8bit quantized function is at least one half + // times the quantization step: 0.5 * (kOutMax - kOutMin) / 256. + // To that we add again the quantization step (kOutMax - kOutMin) / 256 + // to allow for an off-by-one rounding error. + const float kTolerance = + std::max(input_max - input_min, output_max - output_min) * (1.5f / 256.f); + + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_elements_count = ElementCount(*output_dims); + + TF_LITE_MICRO_EXPECT_EQ(output_elements_count, size); + + GenerateUniformRandomVector(size, input_min, input_max, random_engine, + float_input_values); + EvalTestReferenceHardSwish(size, float_input_values, float_ref_output_values); + for (int i = 0; i < size; i++) { + float val = float_ref_output_values[i]; + float_ref_output_values[i] = + std::min(output_max, std::max(output_min, val)); + } + + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(float_input_values, input_data_quantized, + input_dims, input_scale, input_zero_point), + CreateQuantizedTensor(output_data, output_dims, output_scale, + output_zero_point), + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = + tflite::ops::micro::Register_HARD_SWISH(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + Dequantize(output_data, output_elements_count, output_scale, + output_zero_point, dequantized_output); + + for (int i = 0; i < output_elements_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(float_ref_output_values[i], dequantized_output[i], + kTolerance); + } +} + +template +void TestHardSwishQuantizedBias(const int size, const T *output_data, + T *input_data_quantized, + float *dequantized_output, float input_min, + float input_max, float output_min, + float output_max, float tolerated_bias, + float *float_input_values, + float *float_ref_output_values) +{ + const float input_scale = ScaleFromMinMax(input_min, input_max); + const float output_scale = ScaleFromMinMax(output_min, output_max); + + const int input_zero_point = ZeroPointFromMinMax(input_min, input_max); + const int output_zero_point = ZeroPointFromMinMax(output_min, output_max); + + const float max_scale = std::max(output_scale, input_scale); + + // In this bias-focused test case, no need for randomly generated input + // values. + TF_LITE_MICRO_EXPECT_LE(input_min, -3.0f); + TF_LITE_MICRO_EXPECT_GE(input_max, 3.0f); + const int quantized_input_negative_three = + round(std::numeric_limits::min() + (-3.0f - input_min) / input_scale); + const int quantized_input_positive_three = + round(std::numeric_limits::min() + (3.0f - input_min) / input_scale); + + for (int i = quantized_input_negative_three; + i < size && i <= quantized_input_positive_three; i++) { + float_input_values[i] = + input_min + (i - std::numeric_limits::min()) * input_scale; + } + + EvalTestReferenceHardSwish(size, float_input_values, float_ref_output_values); + for (int i = 0; i < size; i++) { + float val = float_ref_output_values[i]; + float_ref_output_values[i] = + std::min(output_max, std::max(output_min, val)); + } + + int input_dims_data[] = { 2, 1, size }; + int output_dims_data[] = { 2, 1, size }; + + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_elements_count = ElementCount(*output_dims); + + TF_LITE_MICRO_EXPECT_EQ(output_elements_count, size); + + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(float_input_values, input_data_quantized, + input_dims, input_scale, input_zero_point), + CreateQuantizedTensor(output_data, output_dims, output_scale, + output_zero_point), + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = + tflite::ops::micro::Register_HARD_SWISH(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + Dequantize(output_data, output_elements_count, output_scale, + output_zero_point, dequantized_output); + + float sum_diff = 0; + for (int i = 0; i < size; i++) { + sum_diff += dequantized_output[i] - float_ref_output_values[i]; + } + const float bias = sum_diff / (size * max_scale); + TF_LITE_MICRO_EXPECT_LE(std::abs(bias), tolerated_bias); +} + +void TestHardSwishFloat(const int size, float *output_data, + std::minstd_rand *random_engine, + float *float_input_values, + float *float_ref_output_values) +{ + const float kMin = -10.0f; + const float kMax = 10.0f; + GenerateUniformRandomVector(size, kMin, kMax, random_engine, + float_input_values); + + EvalTestReferenceHardSwish(size, float_input_values, float_ref_output_values); + + int input_dims_data[] = { 1, size }; + int output_dims_data[] = { 1, size }; + + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_elements_count = ElementCount(*output_dims); + + TF_LITE_MICRO_EXPECT_EQ(output_elements_count, size); + + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(float_input_values, input_dims), + CreateTensor(output_data, output_dims), + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = + tflite::ops::micro::Register_HARD_SWISH(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_elements_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(float_ref_output_values[i], output_data[i], + 1e-5f); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(SimpleHardSwishTestFloat) +{ + std::minstd_rand random_engine; + constexpr int size = 100; + float output_data[size] = { 0.f }; + float input_values[size] = { 0.f }; + float output_values[size] = { 0.f }; + + tflite::testing::TestHardSwishFloat(size, output_data, &random_engine, + input_values, output_values); +} + +TF_LITE_MICRO_TEST(SimpleHardSwishTestInt8) +{ + std::minstd_rand random_engine; + constexpr int pairs = 4, one_pair = 2; + constexpr int size = 101; + constexpr float minmax_pairs[pairs][one_pair] = { + { 0.f, 1.f }, { -2.f, 1.f }, { -5.f, 10.f }, { -40.f, 60.f } + }; + int8_t output_data[size] = { 0 }; + int8_t input_data_quantized[size] = { 0 }; + float dequantized_output[size] = { 0.f }; + float input_values[size] = { 0.f }; + float output_values[size] = { 0.f }; + + for (int x = 0; x < pairs; x++) { + for (int y = 0; y < pairs; y++) { + float input_min = minmax_pairs[x][0]; + float input_max = minmax_pairs[x][1]; + float output_min = minmax_pairs[y][0]; + float output_max = minmax_pairs[y][1]; + + tflite::testing::TestHardSwishQuantized( + size, output_data, input_data_quantized, dequantized_output, + input_min, input_max, output_min, output_max, &random_engine, + input_values, output_values); + } + } +} + +TF_LITE_MICRO_TEST(SimpleHardSwishTestUint8) +{ + std::minstd_rand random_engine; + constexpr int size = 99; + constexpr int pairs = 4, one_pair = 2; + constexpr float minmax_pairs[pairs][one_pair] = { + { 0.f, 1.f }, { -2.f, 1.f }, { -5.f, 10.f }, { -40.f, 60.f } + }; + uint8_t output_data[size] = { 0 }; + uint8_t input_data_quantized[size] = { 0 }; + float dequantized_output[size] = { 0.f }; + float input_values[size] = { 0.f }; + float output_values[size] = { 0.f }; + + for (int x = 0; x < pairs; x++) { + for (int y = 0; y < pairs; y++) { + float input_min = minmax_pairs[x][0]; + float input_max = minmax_pairs[x][1]; + float output_min = minmax_pairs[y][0]; + float output_max = minmax_pairs[y][1]; + + tflite::testing::TestHardSwishQuantized( + size, output_data, input_data_quantized, dequantized_output, + input_min, input_max, output_min, output_max, &random_engine, + input_values, output_values); + } + } +} + +// See the comment in the reference implementation of quantized HardSwish: +// A numerical issue significantly affecting ImageNet classification accuracy +// with MobileNet v3 is only observable at the scale of HardSwish unit tests +// if we monitor specifically bias. This testcase is extracted from one of the +// HardSwish nodes in that MobileNet v3 that exhibited this issue. +TF_LITE_MICRO_TEST(SimpleHardSwishTestQuantizedBias) +{ + constexpr int size = 43; + uint8_t output_data[size] = { 0 }; + uint8_t input_data_quantized[size] = { 0 }; + float dequantized_output[size] = { 0.f }; + float input_values[size] = { 0.f }; + float output_values[size] = { 0.f }; + + tflite::testing::TestHardSwishQuantizedBias( + size, output_data, input_data_quantized, dequantized_output, -11.654928f, + 25.036512f, -0.3905796f, 24.50887f, 0.035, input_values, output_values); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/if.cc b/components/tflite/tensorflow/lite/micro/kernels/if.cc new file mode 100644 index 00000000..12632436 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/if.cc @@ -0,0 +1,170 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/memory_helpers.h" +#include "tensorflow/lite/micro/micro_graph.h" +#include "tensorflow/lite/schema/schema_generated.h" + +namespace tflite { + +namespace { + +struct OpData { + int then_subgraph_index; + int else_subgraph_index; +}; + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(OpData)); +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + OpData *op_data = reinterpret_cast(node->user_data); + const auto *params = + reinterpret_cast(node->builtin_data); + op_data->then_subgraph_index = params->then_subgraph_index; + op_data->else_subgraph_index = params->else_subgraph_index; + + TF_LITE_ENSURE(context, node->inputs->size > 0); + + // The first input is the condition. + const TfLiteTensor *cond; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, 0, &cond)); + TF_LITE_ENSURE_EQ(context, cond->type, kTfLiteBool); + TF_LITE_ENSURE_EQ(context, NumElements(cond), 1); + + // The first input of the node is the condition. The rest of inputs are + // passed to the branch subgraphs. Therefore, the number of subgraph inputs + // will be the number of node inputs - 1. + size_t num_inputs = node->inputs->size - 1; + size_t num_outputs = node->outputs->size; + + // Casting to TfliteIntArray is required since we are re-using + // GetExecutionPlan from TfLiteContext. On TFLM this method returns a + // MicroGraph. + // TODO(b/188226309): Design a cleaner way to get a graph from kernel context. + MicroGraph *graph_info; + context->GetExecutionPlan(context, + reinterpret_cast(&graph_info)); + + TF_LITE_ENSURE(context, + op_data->then_subgraph_index < graph_info->NumSubgraphs()); + TF_LITE_ENSURE(context, + op_data->else_subgraph_index < graph_info->NumSubgraphs()); + + TF_LITE_ENSURE_EQ( + context, num_inputs, + graph_info->NumSubgraphInputs(op_data->then_subgraph_index)); + TF_LITE_ENSURE_EQ( + context, num_outputs, + graph_info->NumSubgraphOutputs(op_data->then_subgraph_index)); + + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const OpData *op_data = reinterpret_cast(node->user_data); + + const TfLiteTensor *cond; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, 0, &cond)); + bool cond_value = cond->data.b[0]; + + // Casting to TfliteIntArray is required since we are re-using + // GetExecutionPlan from TfLiteContext. On TFLM this method returns a + // MicroGraph. + // TODO(b/188226309): Design a cleaner way to get a graph from kernel context. + MicroGraph *graph_info; + context->GetExecutionPlan(context, + reinterpret_cast(&graph_info)); + + // Currently we copy the input / output between the subgraphs. This isn't + // optimized yet. + int active_branch_subgraph_index = + cond_value ? op_data->then_subgraph_index : op_data->else_subgraph_index; + + for (size_t i = 0; + i < graph_info->NumSubgraphInputs(active_branch_subgraph_index); ++i) { + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, i + 1); + + TfLiteEvalTensor *subgraph_input = + graph_info->GetSubgraphInput(active_branch_subgraph_index, i); + + // These checks must occur in Eval since TfLiteEvalTensors are not available + // during Prepare. + size_t input_bytes; + size_t subgraph_input_bytes; + TF_LITE_ENSURE_OK(context, TfLiteEvalTensorByteLength(input, &input_bytes)); + TF_LITE_ENSURE_OK(context, TfLiteEvalTensorByteLength( + subgraph_input, &subgraph_input_bytes)); + TF_LITE_ENSURE_TYPES_EQ(context, input->type, subgraph_input->type); + TF_LITE_ENSURE_EQ(context, input_bytes, subgraph_input_bytes); + memcpy(subgraph_input->data.raw, input->data.raw, input_bytes); + } + + TF_LITE_ENSURE_OK(context, + graph_info->InvokeSubgraph(active_branch_subgraph_index)); + + for (size_t i = 0; + i < graph_info->NumSubgraphOutputs(active_branch_subgraph_index); ++i) { + const TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, i); + + TfLiteEvalTensor *subgraph_output = + graph_info->GetSubgraphOutput(active_branch_subgraph_index, i); + + // These checks must occur in Eval since TfLiteEvalTensors are not available + // during Prepare. + size_t output_bytes; + size_t subgraph_output_bytes; + TF_LITE_ENSURE_OK(context, + TfLiteEvalTensorByteLength(output, &output_bytes)); + TF_LITE_ENSURE_OK(context, TfLiteEvalTensorByteLength( + subgraph_output, &subgraph_output_bytes)); + TF_LITE_ENSURE_TYPES_EQ(context, output->type, subgraph_output->type); + TF_LITE_ENSURE_EQ(context, output_bytes, subgraph_output_bytes); + memcpy(output->data.raw, subgraph_output->data.raw, output_bytes); + } + return kTfLiteOk; +} + +} // namespace. + +TfLiteRegistration Register_IF() +{ + return { /*init=*/Init, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/if_test.cc b/components/tflite/tensorflow/lite/micro/kernels/if_test.cc new file mode 100644 index 00000000..54f0e66d --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/if_test.cc @@ -0,0 +1,168 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/micro_interpreter.h" +#include "tensorflow/lite/micro/mock_micro_graph.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +void TestIf(int *input1_dims_data, const bool *input1_data, + int *input2_dims_data, const float *input2_data, + int *output_dims_data, const float *expected_output_data, + const int subgraph1_invoke_count_golden, + const int subgraph2_invoke_count_golden, float *output_data) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input1_data, input1_dims), + CreateTensor(input2_data, input2_dims), + CreateTensor(output_data, output_dims), + }; + + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + TfLiteIfParams params; + params.then_subgraph_index = 1; + params.else_subgraph_index = 2; + + const TfLiteRegistration registration = tflite::Register_IF(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, ¶ms); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + TF_LITE_MICRO_EXPECT_EQ(output_dims_count, 2); + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output_data[i], output_data[i]); + } + + TF_LITE_MICRO_EXPECT_EQ(subgraph1_invoke_count_golden, + runner.GetMockGraph()->get_invoke_count(1)); + TF_LITE_MICRO_EXPECT_EQ(subgraph2_invoke_count_golden, + runner.GetMockGraph()->get_invoke_count(2)); +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(IfShouldInvokeSubgraphWithMockModelConditionTrue) +{ + int shape[] = { 2, 1, 2 }; + int condition_shape[] = { 1, 1 }; + const bool condition[] = { true }; + const float input[] = { 5.0, 2.0 }; + const float golden[] = { 5.0, 2.0 }; + float output_data[2] = { 0 }; + tflite::testing::TestIf(condition_shape, condition, shape, input, shape, + golden, 1, 0, output_data); +} + +TF_LITE_MICRO_TEST(IfShouldInvokeSubgraphWithMockModelConditionFalse) +{ + int shape[] = { 2, 1, 2 }; + int condition_shape[] = { 1, 1 }; + const bool condition[] = { false }; + const float input[] = { 5.0, 2.0 }; + const float golden[] = { 5.0, 2.0 }; + float output_data[2] = { 0 }; + tflite::testing::TestIf(condition_shape, condition, shape, input, shape, + golden, 0, 1, output_data); +} + +TF_LITE_MICRO_TEST(IfShouldInvokeSubgraphConditionTrue) +{ + constexpr int kArenaSize = 5000; + uint8_t arena[kArenaSize]; + + const tflite::Model *model = + tflite::testing::GetSimpleModelWithSubgraphsAndIf(); + tflite::MicroMutableOpResolver<3> resolver; + tflite::MicroErrorReporter reporter; + resolver.AddIf(); + resolver.AddAdd(); + resolver.AddMul(); + tflite::MicroInterpreter interpreter(model, resolver, arena, kArenaSize, + &reporter); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, interpreter.AllocateTensors()); + TfLiteTensor *condition = interpreter.input(0); + TfLiteTensor *input1 = interpreter.input(1); + TfLiteTensor *input2 = interpreter.input(2); + TfLiteTensor *output = interpreter.output(0); + float input1_data[] = { 2.0, 5.0 }; + float input2_data[] = { 3.0, 7.0 }; + memcpy(input1->data.f, input1_data, 2 * sizeof(float)); + memcpy(input2->data.f, input2_data, 2 * sizeof(float)); + condition->data.b[0] = true; + + interpreter.Invoke(); + + TF_LITE_MICRO_EXPECT_EQ(output->data.f[0], 5.0f); + TF_LITE_MICRO_EXPECT_EQ(output->data.f[1], 12.0f); +} + +TF_LITE_MICRO_TEST(IfShouldInvokeSubgraphConditionFalse) +{ + constexpr int kArenaSize = 5000; + uint8_t arena[kArenaSize]; + + const tflite::Model *model = + tflite::testing::GetSimpleModelWithSubgraphsAndIf(); + tflite::MicroMutableOpResolver<3> resolver; + tflite::MicroErrorReporter reporter; + resolver.AddIf(); + resolver.AddAdd(); + resolver.AddMul(); + tflite::MicroInterpreter interpreter(model, resolver, arena, kArenaSize, + &reporter); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, interpreter.AllocateTensors()); + TfLiteTensor *condition = interpreter.input(0); + TfLiteTensor *input1 = interpreter.input(1); + TfLiteTensor *input2 = interpreter.input(2); + TfLiteTensor *output = interpreter.output(0); + float input1_data[] = { 2.0, 5.0 }; + float input2_data[] = { 3.0, 7.0 }; + memcpy(input1->data.f, input1_data, 2 * sizeof(float)); + memcpy(input2->data.f, input2_data, 2 * sizeof(float)); + condition->data.b[0] = false; + + interpreter.Invoke(); + + TF_LITE_MICRO_EXPECT_EQ(output->data.f[0], 6.0f); + TF_LITE_MICRO_EXPECT_EQ(output->data.f[1], 35.0f); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/kernel_runner.cc b/components/tflite/tensorflow/lite/micro/kernels/kernel_runner.cc new file mode 100644 index 00000000..533f1bc6 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/kernel_runner.cc @@ -0,0 +1,186 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/kernels/kernel_runner.h" + +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/simple_memory_allocator.h" +#include "tensorflow/lite/micro/test_helpers.h" + +namespace tflite { +namespace micro { + +namespace { +constexpr size_t kBufferAlignment = 16; +} // namespace + +// TODO(b/161841696): Consider moving away from global arena buffers: +constexpr int KernelRunner::kNumScratchBuffers_; +constexpr int KernelRunner::kKernelRunnerBufferSize_; +uint8_t KernelRunner::kKernelRunnerBuffer_[]; + +KernelRunner::KernelRunner(const TfLiteRegistration ®istration, + TfLiteTensor *tensors, int tensors_size, + TfLiteIntArray *inputs, TfLiteIntArray *outputs, + void *builtin_data) + : allocator_(SimpleMemoryAllocator::Create(GetMicroErrorReporter(), + kKernelRunnerBuffer_, + kKernelRunnerBufferSize_)), + registration_(registration), + tensors_(tensors), + mock_micro_graph_(allocator_) +{ + // Prepare TfLiteContext: + context_.impl_ = static_cast(this); + context_.ReportError = ReportOpError; + context_.recommended_num_threads = 1; + context_.GetTensor = GetTensor; + context_.GetEvalTensor = GetEvalTensor; + context_.AllocatePersistentBuffer = AllocatePersistentBuffer; + context_.RequestScratchBufferInArena = RequestScratchBufferInArena; + context_.GetScratchBuffer = GetScratchBuffer; + context_.GetExecutionPlan = GetGraph; + context_.recommended_num_threads = 0; + + // Prepare TfLiteNode: + node_.inputs = inputs; + node_.outputs = outputs; + node_.builtin_data = builtin_data; +} + +TfLiteStatus KernelRunner::InitAndPrepare(const char *init_data, + size_t length) +{ + if (registration_.init) { + node_.user_data = registration_.init(&context_, init_data, length); + } + if (registration_.prepare) { + TF_LITE_ENSURE_STATUS(registration_.prepare(&context_, &node_)); + } + return kTfLiteOk; +} + +TfLiteStatus KernelRunner::Invoke() +{ + if (registration_.invoke == nullptr) { + MicroPrintf("TfLiteRegistration missing invoke function pointer!"); + return kTfLiteError; + } + return registration_.invoke(&context_, &node_); +} + +TfLiteTensor *KernelRunner::GetTensor(const struct TfLiteContext *context, + int tensor_index) +{ + TFLITE_DCHECK(context != nullptr); + KernelRunner *runner = reinterpret_cast(context->impl_); + TFLITE_DCHECK(runner != nullptr); + + return &runner->tensors_[tensor_index]; +} + +TfLiteEvalTensor *KernelRunner::GetEvalTensor( + const struct TfLiteContext *context, int tensor_index) +{ + TFLITE_DCHECK(context != nullptr); + KernelRunner *runner = reinterpret_cast(context->impl_); + TFLITE_DCHECK(runner != nullptr); + + TfLiteEvalTensor *eval_tensor = + reinterpret_cast(runner->allocator_->AllocateTemp( + sizeof(TfLiteEvalTensor), alignof(TfLiteEvalTensor))); + TFLITE_DCHECK(eval_tensor != nullptr); + + // In unit tests, the TfLiteTensor pointer contains the source of truth for + // buffers and values: + eval_tensor->data = runner->tensors_[tensor_index].data; + eval_tensor->dims = runner->tensors_[tensor_index].dims; + eval_tensor->type = runner->tensors_[tensor_index].type; + return eval_tensor; +} + +void *KernelRunner::AllocatePersistentBuffer(TfLiteContext *context, + size_t bytes) +{ + TFLITE_DCHECK(context != nullptr); + KernelRunner *runner = reinterpret_cast(context->impl_); + TFLITE_DCHECK(runner != nullptr); + + return runner->allocator_->AllocateFromTail(bytes, kBufferAlignment); +} + +TfLiteStatus KernelRunner::RequestScratchBufferInArena(TfLiteContext *context, + size_t bytes, + int *buffer_index) +{ + TFLITE_DCHECK(context != nullptr); + TFLITE_DCHECK(buffer_index != nullptr); + + KernelRunner *runner = reinterpret_cast(context->impl_); + TFLITE_DCHECK(runner != nullptr); + + if (runner->scratch_buffer_count_ == kNumScratchBuffers_) { + MicroPrintf("Exceeded the maximum number of scratch tensors allowed (%d).", + kNumScratchBuffers_); + return kTfLiteError; + } + + // For tests, we allocate scratch buffers from the tail and keep them around + // for the lifetime of model. This means that the arena size in the tests will + // be more than what we would have if the scratch buffers could share memory. + runner->scratch_buffers_[runner->scratch_buffer_count_] = + runner->allocator_->AllocateFromTail(bytes, kBufferAlignment); + TFLITE_DCHECK(runner->scratch_buffers_[runner->scratch_buffer_count_] != + nullptr); + + *buffer_index = runner->scratch_buffer_count_++; + return kTfLiteOk; +} + +void *KernelRunner::GetScratchBuffer(TfLiteContext *context, int buffer_index) +{ + TFLITE_DCHECK(context != nullptr); + KernelRunner *runner = reinterpret_cast(context->impl_); + TFLITE_DCHECK(runner != nullptr); + + TFLITE_DCHECK(runner->scratch_buffer_count_ <= kNumScratchBuffers_); + if (buffer_index >= runner->scratch_buffer_count_) { + return nullptr; + } + return runner->scratch_buffers_[buffer_index]; +} + +void KernelRunner::ReportOpError(struct TfLiteContext *context, + const char *format, ...) +{ + va_list args; + va_start(args, format); + GetMicroErrorReporter()->Report(format, args); + va_end(args); +} + +TfLiteStatus KernelRunner::GetGraph(struct TfLiteContext *context, + TfLiteIntArray **args) +{ + TFLITE_DCHECK(context != nullptr); + KernelRunner *runner = reinterpret_cast(context->impl_); + TFLITE_DCHECK(runner != nullptr); + // TODO(b/188226309): Design a cleaner way to get a graph from kernel context. + *args = reinterpret_cast(runner->GetMockGraph()); + return kTfLiteOk; +} + +} // namespace micro +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/kernel_runner.h b/components/tflite/tensorflow/lite/micro/kernels/kernel_runner.h new file mode 100644 index 00000000..eebcad03 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/kernel_runner.h @@ -0,0 +1,94 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_KERNELS_KERNEL_RUNNER_H_ +#define TENSORFLOW_LITE_MICRO_KERNELS_KERNEL_RUNNER_H_ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/micro/mock_micro_graph.h" +#include "tensorflow/lite/micro/simple_memory_allocator.h" + +namespace tflite { +namespace micro { +// Helper class to perform a simulated kernel (i.e. TfLiteRegistration) +// lifecycle (init, prepare, invoke). All internal allocations are handled by +// this class. Simply pass in the registration, list of required tensors, inputs +// array, outputs array, and any pre-builtin data. Calling Invoke() will +// automatically walk the kernel and outputs will be ready on the TfLiteTensor +// output provided during construction. +class KernelRunner { +public: + KernelRunner(const TfLiteRegistration ®istration, TfLiteTensor *tensors, + int tensors_size, TfLiteIntArray *inputs, + TfLiteIntArray *outputs, void *builtin_data); + + // Calls init and prepare on the kernel (i.e. TfLiteRegistration) struct. Any + // exceptions will be DebugLog'd and returned as a status code. + TfLiteStatus InitAndPrepare(const char *init_data = nullptr, + size_t length = 0); + + // Calls init, prepare, and invoke on a given TfLiteRegistration pointer. + // After successful invoke, results will be available in the output tensor as + // passed into the constructor of this class. + TfLiteStatus Invoke(); + + // Returns a pointer to the internal MockMicroGraph which KernelRunner uses + // to stub out MicroGraph methods and track invocations on each subgraph. + MockMicroGraph *GetMockGraph() + { + return &mock_micro_graph_; + } + +protected: + static TfLiteTensor *GetTensor(const struct TfLiteContext *context, + int tensor_index); + static TfLiteEvalTensor *GetEvalTensor(const struct TfLiteContext *context, + int tensor_index); + static void *AllocatePersistentBuffer(TfLiteContext *context, size_t bytes); + static TfLiteStatus RequestScratchBufferInArena(TfLiteContext *context, + size_t bytes, + int *buffer_index); + static void *GetScratchBuffer(TfLiteContext *context, int buffer_index); + static void ReportOpError(struct TfLiteContext *context, const char *format, + ...); + // This method matches GetExecutionPlan from TfLiteContext since TFLM reuses + // this method to get the MicroGraph from an operator context. + // TODO(b/188226309): Design a cleaner way to get a graph from kernel context. + static TfLiteStatus GetGraph(struct TfLiteContext *context, + TfLiteIntArray **args); + +private: + static constexpr int kNumScratchBuffers_ = 12; + + static constexpr int kKernelRunnerBufferSize_ = 10000; + static uint8_t kKernelRunnerBuffer_[kKernelRunnerBufferSize_]; + + SimpleMemoryAllocator *allocator_ = nullptr; + const TfLiteRegistration ®istration_; + TfLiteTensor *tensors_ = nullptr; + MockMicroGraph mock_micro_graph_; + + TfLiteContext context_ = {}; + TfLiteNode node_ = {}; + + int scratch_buffer_count_ = 0; + uint8_t *scratch_buffers_[kNumScratchBuffers_]; +}; + +} // namespace micro +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_KERNELS_KERNEL_RUNNER_H_ diff --git a/components/tflite/tensorflow/lite/micro/kernels/kernel_util.cc b/components/tflite/tensorflow/lite/micro/kernels/kernel_util.cc new file mode 100644 index 00000000..f9ad5264 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/kernel_util.cc @@ -0,0 +1,108 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +#include "tensorflow/lite/c/common.h" + +namespace tflite { +namespace micro { + +const flexbuffers::Map FlexbuffersWrapperGetRootAsMap(const uint8_t *buffer, + size_t size) +{ + return flexbuffers::GetRoot(buffer, size).AsMap(); +} + +int32_t FlexbuffersWrapperAsInt32(const flexbuffers::Map &m, const char *key) +{ + return m[key].AsInt32(); +} + +bool FlexbuffersWrapperAsBool(const flexbuffers::Map &m, const char *key) +{ + return m[key].AsBool(); +} + +float FlexbuffersWrapperAsFloat(const flexbuffers::Map &m, const char *key) +{ + return m[key].AsFloat(); +} + +bool FlexbuffersWrapperIsNull(const flexbuffers::Map &m, const char *key) +{ + return m[key].IsNull(); +} + +bool HaveSameShapes(const TfLiteEvalTensor *input1, + const TfLiteEvalTensor *input2) +{ + TFLITE_DCHECK(input1 != nullptr); + TFLITE_DCHECK(input2 != nullptr); + return TfLiteIntArrayEqual(input1->dims, input2->dims); +} + +const RuntimeShape GetTensorShape(const TfLiteEvalTensor *tensor) +{ + if (tensor == nullptr || tensor->dims == nullptr) { + return RuntimeShape(); + } + TfLiteIntArray *dims = tensor->dims; + const int dims_size = dims->size; + const int32_t *dims_data = reinterpret_cast(dims->data); + return RuntimeShape(dims_size, dims_data); +} + +PaddingType RuntimePaddingType(TfLitePadding padding) +{ + switch (padding) { + case TfLitePadding::kTfLitePaddingSame: + return PaddingType::kSame; + case TfLitePadding::kTfLitePaddingValid: + return PaddingType::kValid; + case TfLitePadding::kTfLitePaddingUnknown: + default: + return PaddingType::kNone; + } +} + +// Relocate tensor dims from FlatBuffer to the persistent storage arena. +// The old dims data is copied to the new storage area. +// The tensor and eval_tensor must be the same tensor. +// Only use during Prepare phase. +TfLiteStatus CreateWritableTensorDimsWithCopy(TfLiteContext *context, + TfLiteTensor *tensor, + TfLiteEvalTensor *eval_tensor) +{ + TF_LITE_ENSURE(context, tensor != nullptr); + TF_LITE_ENSURE(context, eval_tensor != nullptr); + TF_LITE_ENSURE(context, context->AllocatePersistentBuffer != nullptr); + int ranks = tensor->dims->size; + size_t alloc_size = TfLiteIntArrayGetSizeInBytes(ranks); + TfLiteIntArray *new_dims = static_cast( + context->AllocatePersistentBuffer(context, alloc_size)); + TfLiteIntArray *old_dims = tensor->dims; + new_dims->size = ranks; + tensor->dims = new_dims; + eval_tensor->dims = new_dims; + for (int i = 0; i < ranks; i++) { + new_dims->data[i] = old_dims->data[i]; + } + + return kTfLiteOk; +} + +} // namespace micro +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/kernel_util.h b/components/tflite/tensorflow/lite/micro/kernels/kernel_util.h new file mode 100644 index 00000000..e4b49472 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/kernel_util.h @@ -0,0 +1,106 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_KERNELS_KERNEL_UTIL_H_ +#define TENSORFLOW_LITE_MICRO_KERNELS_KERNEL_UTIL_H_ + +#include + +#define FLATBUFFERS_LOCALE_INDEPENDENT 0 +#include "flatbuffers/flexbuffers.h" +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +namespace micro { +// The Flexbuffer library is inline heavy, which causes code bloat when +// custom ops are used. Wrapping with a function is a portable way to avoid +// this bloat +const flexbuffers::Map FlexbuffersWrapperGetRootAsMap(const uint8_t *buffer, + size_t size); + +int32_t FlexbuffersWrapperAsInt32(const flexbuffers::Map &m, const char *key); + +bool FlexbuffersWrapperAsBool(const flexbuffers::Map &m, const char *key); + +float FlexbuffersWrapperAsFloat(const flexbuffers::Map &m, const char *key); + +bool FlexbuffersWrapperIsNull(const flexbuffers::Map &m, const char *key); + +// Returns a mutable tensor for a given input index. is_variable must be checked +// during prepare when the full TfLiteTensor is available. +inline TfLiteEvalTensor *GetMutableEvalInput(const TfLiteContext *context, + const TfLiteNode *node, + int index) +{ + TFLITE_DCHECK(context != nullptr); + TFLITE_DCHECK(node != nullptr); + return context->GetEvalTensor(context, node->inputs->data[index]); +} + +// Returns the TfLiteEvalTensor struct for a given input index in a node. +inline const TfLiteEvalTensor *GetEvalInput(const TfLiteContext *context, + const TfLiteNode *node, int index) +{ + return GetMutableEvalInput(context, node, index); +} + +// Returns the TfLiteEvalTensor struct for a given output index in a node. +inline TfLiteEvalTensor *GetEvalOutput(const TfLiteContext *context, + const TfLiteNode *node, int index) +{ + TFLITE_DCHECK(context != nullptr); + TFLITE_DCHECK(node != nullptr); + return context->GetEvalTensor(context, node->outputs->data[index]); +} + +// Returns data for a TfLiteEvalTensor struct. +template +T *GetTensorData(TfLiteEvalTensor *tensor) +{ + return tensor != nullptr ? reinterpret_cast(tensor->data.raw) : nullptr; +} + +// Returns const data for a TfLiteEvalTensor struct. +template +const T *GetTensorData(const TfLiteEvalTensor *tensor) +{ + TFLITE_DCHECK(tensor != nullptr); + return reinterpret_cast(tensor->data.raw); +} + +// Returns the shape of a TfLiteEvalTensor struct. +const RuntimeShape GetTensorShape(const TfLiteEvalTensor *tensor); + +// Return true if the given tensors have the same shape. +bool HaveSameShapes(const TfLiteEvalTensor *input1, + const TfLiteEvalTensor *input2); + +PaddingType RuntimePaddingType(TfLitePadding padding); + +// Relocate tensor dims from FlatBuffer to the persistent storage arena. +// The old dims data is copied to the new storage area. +// The tensor and eval_tensor must be the same tensor. +// Only use during Prepare phase. +TfLiteStatus CreateWritableTensorDimsWithCopy(TfLiteContext *context, + TfLiteTensor *tensor, + TfLiteEvalTensor *eval_tensor); + +} // namespace micro +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_KERNELS_KERNEL_UTIL_H_ diff --git a/components/tflite/tensorflow/lite/micro/kernels/l2_pool_2d.cc b/components/tflite/tensorflow/lite/micro/kernels/l2_pool_2d.cc new file mode 100644 index 00000000..e201e081 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/l2_pool_2d.cc @@ -0,0 +1,150 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/reference/pooling.h" +#include "tensorflow/lite/kernels/internal/types.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/padding.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace { + +// Input/output tensor index. +constexpr int kInputTensor = 0; +constexpr int kOutputTensor = 0; + +// required rank for input/output tensor shape +constexpr int kTensorShapeRank = 4; + +// input/output tensor shape rank associations +enum { kBatchRank = 0, + kHeightRank, + kWidthRank, + kChannelRank }; + +TfLiteStatus L2Prepare(TfLiteContext *context, TfLiteNode *node) +{ + auto *params = static_cast(node->builtin_data); + + TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + TfLiteTensor *output; + TF_LITE_ENSURE_OK(context, + GetOutputSafe(context, node, kOutputTensor, &output)); + const TfLiteTensor *input; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, kInputTensor, &input)); + TF_LITE_ENSURE_EQ(context, NumDimensions(input), kTensorShapeRank); + TF_LITE_ENSURE_EQ(context, NumDimensions(output), kTensorShapeRank); + TF_LITE_ENSURE_TYPES_EQ(context, input->type, output->type); + + int batches = SizeOfDimension(input, kBatchRank); + int height = SizeOfDimension(input, kHeightRank); + int width = SizeOfDimension(input, kWidthRank); + int channels_out = SizeOfDimension(input, kChannelRank); + + // Matching GetWindowedOutputSize in TensorFlow. + auto padding = params->padding; + int out_width, out_height; + + params->computed.padding = ComputePaddingHeightWidth( + params->stride_height, params->stride_width, 1, 1, height, width, + params->filter_height, params->filter_width, padding, &out_height, + &out_width); + + // We currently don't have a quantized implementation of L2Pool + TF_LITE_ENSURE_TYPES_EQ(context, input->type, kTfLiteFloat32); + + // We must update the output tensor dimensions. + // The dims storage is expected to be the same area in memory + // for both TfLiteTensor and TfLiteEvalTensor. This is important + // because TfLiteTensor in the MicroInterpreter is a temporary + // allocation. For the KernelRunner interpreter, TfLiteEvalTensor + // is a temporary allocation. We must therefore relocate the dims + // from the FlatBuffer to the persistant storage arena. + TfLiteEvalTensor *output_eval = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + TF_LITE_ENSURE_OK(context, tflite::micro::CreateWritableTensorDimsWithCopy( + context, output, output_eval)); + output->dims->data[kBatchRank] = batches; + output->dims->data[kHeightRank] = out_height; + output->dims->data[kWidthRank] = out_width; + output->dims->data[kChannelRank] = channels_out; + + return kTfLiteOk; +} + +void L2EvalFloat(const TfLitePoolParams ¶ms, const TfLiteEvalTensor &input, + tflite::PoolParams *op_params, TfLiteEvalTensor *output) +{ + float activation_min, activation_max; + CalculateActivationRange(params.activation, &activation_min, &activation_max); + + op_params->float_activation_min = activation_min; + op_params->float_activation_max = activation_max; + reference_ops::L2Pool(*op_params, tflite::micro::GetTensorShape(&input), + tflite::micro::GetTensorData(&input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); +} + +TfLiteStatus L2Eval(TfLiteContext *context, TfLiteNode *node) +{ + auto *params = static_cast(node->builtin_data); + + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + + tflite::PoolParams op_params; + op_params.stride_height = params->stride_height; + op_params.stride_width = params->stride_width; + op_params.filter_height = params->filter_height; + op_params.filter_width = params->filter_width; + op_params.padding_values.height = params->computed.padding.height; + op_params.padding_values.width = params->computed.padding.width; + + switch (input->type) { // Already know in/out types are same. + case kTfLiteFloat32: + L2EvalFloat(*params, *input, &op_params, output); + break; + default: + TF_LITE_KERNEL_LOG(context, + "L2_POOL_2D only supports float32 currently, got %s.", + TfLiteTypeGetName(input->type)); + return kTfLiteError; + } + return kTfLiteOk; +} + +} // namespace + +TfLiteRegistration Register_L2_POOL_2D() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/L2Prepare, + /*invoke=*/L2Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/l2_pool_2d_test.cc b/components/tflite/tensorflow/lite/micro/kernels/l2_pool_2d_test.cc new file mode 100644 index 00000000..68215f62 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/l2_pool_2d_test.cc @@ -0,0 +1,231 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +constexpr float kTolerance = 1e-5; + +constexpr int kOutputDimsCount = 4; + +struct L2Pool2DTestParams { + TfLitePadding padding = kTfLitePaddingValid; + int stride_width = 2; + int stride_height = 2; + int filter_width = 2; + int filter_height = 2; + TfLiteFusedActivation activation = kTfLiteActNone; + float compare_tolerance = kTolerance; + // output_dims_data is a TfLiteIntArray + int output_dims_data[kOutputDimsCount + 1] = { kOutputDimsCount, 0, 0, 0, 0 }; +}; + +void ExecuteL2Pool2DTest(const L2Pool2DTestParams ¶ms, + TfLiteTensor *tensors, int tensors_count) +{ + int kInputArrayData[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(kInputArrayData); + int kOutputArrayData[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(kOutputArrayData); + + TfLitePoolParams op_params = {}; + op_params.activation = params.activation; + op_params.filter_height = params.filter_height; + op_params.filter_width = params.filter_width; + op_params.padding = params.padding; + op_params.stride_height = params.stride_height; + op_params.stride_width = params.stride_width; + + const TfLiteRegistration registration = tflite::Register_L2_POOL_2D(); + micro::KernelRunner runner(registration, tensors, tensors_count, inputs_array, + outputs_array, static_cast(&op_params)); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); +} + +template +void TestL2Pool2D(L2Pool2DTestParams ¶ms, int *input_dims_data, + const T *input_data, int *expected_dims_data, + const T *expected_data, T *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *expected_dims = IntArrayFromInts(expected_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(params.output_dims_data); + const int expected_count = ElementCount(*expected_dims); + + TfLiteTensor tensors[] = { + CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims), + }; + constexpr int tensors_count = std::extent::value; + ExecuteL2Pool2DTest(params, tensors, tensors_count); + + for (int i = 0; i < expected_count; i++) { + TF_LITE_MICRO_EXPECT_NEAR(expected_data[i], output_data[i], + params.compare_tolerance); + } + for (int i = 0; i < expected_dims->size; i++) { + // output dims will have been relocated during prepare phase, + // so use the tensor dims pointer. + TF_LITE_MICRO_EXPECT_EQ(expected_dims->data[i], tensors[1].dims->data[i]); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(FloatPoolingOpTestL2Pool) +{ + int kInputDims[] = { 4, 1, 2, 4, 1 }; + constexpr float kInput[] = { + 0, 6, 2, 4, // + 3, 2, 10, 7, // + }; + int kExpectDims[] = { 4, 1, 1, 2, 1 }; + constexpr float kExpect[] = { 3.5, 6.5 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + tflite::testing::L2Pool2DTestParams params; + + tflite::testing::TestL2Pool2D(params, kInputDims, kInput, kExpectDims, + kExpect, output_data); +} + +TF_LITE_MICRO_TEST(FloatPoolingOpTestL2PoolActivationRelu) +{ + int kInputDims[] = { 4, 1, 2, 4, 1 }; + constexpr float kInput[] = { + -1, -6, 2, 4, // + -3, -2, 10, 7, // + }; + int kExpectDims[] = { 4, 1, 1, 2, 1 }; + constexpr float kExpect[] = { 3.53553, 6.5 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + tflite::testing::L2Pool2DTestParams params; + params.activation = kTfLiteActRelu; + + tflite::testing::TestL2Pool2D(params, kInputDims, kInput, kExpectDims, + kExpect, output_data); +} + +TF_LITE_MICRO_TEST(FloatPoolingOpTestL2PoolActivationRelu1) +{ + int kInputDims[] = { 4, 1, 2, 4, 1 }; + constexpr float kInput[] = { + -0.1, -0.6, 2, 4, // + -0.3, -0.2, 10, 7, // + }; + int kExpectDims[] = { 4, 1, 1, 2, 1 }; + constexpr float kExpect[] = { 0.353553, 1.0 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + tflite::testing::L2Pool2DTestParams params; + params.activation = kTfLiteActReluN1To1; + + tflite::testing::TestL2Pool2D(params, kInputDims, kInput, kExpectDims, + kExpect, output_data); +} + +TF_LITE_MICRO_TEST(FloatPoolingOpTestL2PoolActivationRelu6) +{ + int kInputDims[] = { 4, 1, 2, 4, 1 }; + constexpr float kInput[] = { + -0.1, -0.6, 2, 4, // + -0.3, -0.2, 10, 7, // + }; + int kExpectDims[] = { 4, 1, 1, 2, 1 }; + constexpr float kExpect[] = { 0.353553, 6.0 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + tflite::testing::L2Pool2DTestParams params; + params.activation = kTfLiteActRelu6; + + tflite::testing::TestL2Pool2D(params, kInputDims, kInput, kExpectDims, + kExpect, output_data); +} + +TF_LITE_MICRO_TEST(FloatPoolingOpTestL2PoolPaddingSame) +{ + int kInputDims[] = { 4, 1, 2, 4, 1 }; + constexpr float kInput[] = { + 0, 6, 2, 4, // + 3, 2, 10, 7, // + }; + int kExpectDims[] = { 4, 1, 1, 2, 1 }; + constexpr float kExpect[] = { 3.5, 6.5 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + tflite::testing::L2Pool2DTestParams params; + params.padding = kTfLitePaddingSame; + + tflite::testing::TestL2Pool2D(params, kInputDims, kInput, kExpectDims, + kExpect, output_data); +} + +TF_LITE_MICRO_TEST(FloatPoolingOpTestL2PoolPaddingSameStride1) +{ + int kInputDims[] = { 4, 1, 2, 4, 1 }; + constexpr float kInput[] = { + 0, 6, 2, 4, // + 3, 2, 10, 7, // + }; + int kExpectDims[] = { 4, 1, 2, 4, 1 }; + constexpr float kExpect[] = { 3.5, 6.0, 6.5, 5.70088, + 2.54951, 7.2111, 8.63134, 7.0 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + tflite::testing::L2Pool2DTestParams params; + params.padding = kTfLitePaddingSame; + params.compare_tolerance = 1e-4; + params.stride_width = 1; + params.stride_height = 1; + + tflite::testing::TestL2Pool2D(params, kInputDims, kInput, kExpectDims, + kExpect, output_data); +} + +TF_LITE_MICRO_TEST(FloatPoolingOpTestL2PoolPaddingValidStride1) +{ + int kInputDims[] = { 4, 1, 2, 4, 1 }; + constexpr float kInput[] = { + 0, 6, 2, 4, // + 3, 2, 10, 7, // + }; + int kExpectDims[] = { 4, 1, 1, 3, 1 }; + constexpr float kExpect[] = { 3.5, 6.0, 6.5 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + tflite::testing::L2Pool2DTestParams params; + params.stride_width = 1; + params.stride_height = 1; + + tflite::testing::TestL2Pool2D(params, kInputDims, kInput, kExpectDims, + kExpect, output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/l2norm.cc b/components/tflite/tensorflow/lite/micro/kernels/l2norm.cc new file mode 100644 index 00000000..8a0cc5a5 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/l2norm.cc @@ -0,0 +1,163 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/portable_tensor.h" +#include "tensorflow/lite/kernels/internal/reference/integer_ops/l2normalization.h" +#include "tensorflow/lite/kernels/internal/reference/l2normalization.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace l2norm { + +namespace { + +// This file has two implementation of L2Norm. +enum KernelType { + kReference, + kGenericOptimized, +}; + +constexpr int kInputTensor = 0; +constexpr int kOutputTensor = 0; + +} // namespace + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + TFLITE_DCHECK(node->builtin_data != nullptr); + + auto *params = reinterpret_cast(node->builtin_data); + L2NormalizationParams *data = + static_cast(node->user_data); + + TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + + const TfLiteTensor *input = GetInput(context, node, kInputTensor); + TF_LITE_ENSURE(context, input != nullptr); + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + + TF_LITE_ENSURE(context, NumDimensions(input) <= 4); + + TF_LITE_ENSURE(context, output->type == kTfLiteFloat32 || + output->type == kTfLiteUInt8 || + output->type == kTfLiteInt8); + TF_LITE_ENSURE_TYPES_EQ(context, input->type, output->type); + + if (output->type == kTfLiteUInt8 || output->type == kTfLiteInt8) { + data->input_zero_point = input->params.zero_point; + } else if (output->type == kTfLiteFloat32) { + data->input_zero_point = 0; + } + + // Our implementations don't currently support activations. + TF_LITE_ENSURE_EQ(context, params->activation, kTfLiteActNone); + + return kTfLiteOk; +} + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, + sizeof(L2NormalizationParams)); +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + const L2NormalizationParams &data = + *(static_cast(node->user_data)); + + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + // TODO(b/143912164): instead of hardcode the epsilon here, we should read it + // from tensorflow, i.e., adding a params. + // We don't compute epsilon for quantized kernel: + // + // epsilon_float = (epsilon_quant - zp) * scale + // so + // espsilon_quant = epsilon_float / scale + zp + // We know epsilon_float is just a very small number to avoid division by + // zero error, and scale is > 1, so the integer value of epsilon for quant + // is just dominated by the zero point. + // Also, GetInvSqrtQuantizedMultiplierExp handles the scenario where the sum + // of input value squared is zero case well. + // So we don't even need to do handle the epsilon for quantized kernel case. + const float epsilon = 1e-6f; + if (output->type == kTfLiteFloat32) { + reference_ops::L2Normalization(data, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output), + epsilon); + } else if (output->type == kTfLiteUInt8) { + reference_ops::L2Normalization( + data, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } else if (output->type == kTfLiteInt8) { + const auto input_shape = tflite::micro::GetTensorShape(input); + const auto output_shape = tflite::micro::GetTensorShape(output); + const int trailing_dim = input_shape.DimensionsCount() - 1; + const int depth = + MatchingDim(input_shape, trailing_dim, output_shape, trailing_dim); + const int outer_size = + MatchingFlatSizeSkipDim(input_shape, trailing_dim, output_shape); + reference_integer_ops::L2Normalization( + data.input_zero_point, outer_size, depth, + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorData(output)); + } else { + TF_LITE_KERNEL_LOG(context, "Output type is %s, requires float.", + TfLiteTypeGetName(output->type)); + return kTfLiteError; + } + + return kTfLiteOk; +} + +} // namespace l2norm + +TfLiteRegistration Register_L2NORM_REF() +{ + return { /*init=*/l2norm::Init, + /*free=*/nullptr, + /*prepare=*/l2norm::Prepare, + /*invoke=*/l2norm::Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +TfLiteRegistration Register_L2_NORMALIZATION() +{ + return Register_L2NORM_REF(); +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/l2norm_test.cc b/components/tflite/tensorflow/lite/micro/kernels/l2norm_test.cc new file mode 100644 index 00000000..fea06893 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/l2norm_test.cc @@ -0,0 +1,254 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +// used to set the quantization parameters for the int8_t and uint8_t tests +constexpr float kInputMin = -2.0; +constexpr float kInputMax = 2.0; +constexpr float kOutputMin = -1.0; +constexpr float kOutputMax = 127.0 / 128.0; + +TfLiteTensor CreateL2NormTensor(const float *data, TfLiteIntArray *dims, + bool is_input) +{ + return CreateTensor(data, dims); +} + +template +TfLiteTensor CreateL2NormTensor(const T *data, TfLiteIntArray *dims, + bool is_input) +{ + float kInputScale = ScaleFromMinMax(kInputMin, kInputMax); + int kInputZeroPoint = ZeroPointFromMinMax(kInputMin, kInputMax); + float kOutputScale = ScaleFromMinMax(kOutputMin, kOutputMax); + int kOutputZeroPoint = ZeroPointFromMinMax(kOutputMin, kOutputMax); + TfLiteTensor tensor; + if (is_input) { + tensor = CreateQuantizedTensor(data, dims, kInputScale, kInputZeroPoint); + } else { + tensor = CreateQuantizedTensor(data, dims, kOutputScale, kOutputZeroPoint); + } + + tensor.quantization.type = kTfLiteAffineQuantization; + return tensor; +} + +template +void TestL2Normalization(int *input_dims_data, const T *input_data, + const T *expected_output_data, T *output_data) +{ + TfLiteIntArray *dims = IntArrayFromInts(input_dims_data); + + const int output_dims_count = ElementCount(*dims); + + constexpr int tensors_size = 2; + TfLiteTensor tensors[tensors_size] = { + CreateL2NormTensor(input_data, dims, true), + CreateL2NormTensor(output_data, dims, false), + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + TfLiteL2NormParams builtin_data = { + .activation = kTfLiteActNone, + }; + + const TfLiteRegistration registration = + ops::micro::Register_L2_NORMALIZATION(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + reinterpret_cast(&builtin_data)); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output_data[i], output_data[i]); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(SimpleFloatTest) +{ + int input_dims[] = { 4, 1, 1, 1, 6 }; + constexpr int data_length = 6; + const float input_data[data_length] = { -1.1, 0.6, 0.7, 1.2, -0.7, 0.1 }; + const float expected_output_data[data_length] = { -0.55, 0.3, 0.35, + 0.6, -0.35, 0.05 }; + float output_data[data_length]; + + tflite::testing::TestL2Normalization( + input_dims, input_data, expected_output_data, output_data); +} + +TF_LITE_MICRO_TEST(ZerosVectorFloatTest) +{ + int input_dims[] = { 4, 1, 1, 1, 6 }; + constexpr int data_length = 6; + const float input_data[data_length] = { 0, 0, 0, 0, 0, 0 }; + const float expected_output_data[data_length] = { 0, 0, 0, 0, 0, 0 }; + float output_data[data_length]; + + tflite::testing::TestL2Normalization( + input_dims, input_data, expected_output_data, output_data); +} + +TF_LITE_MICRO_TEST(SimpleFloatWithRankLessThanFourTest) +{ + int input_dims[] = { 4, 1, 1, 1, 6 }; + constexpr int data_length = 6; + const float input_data[data_length] = { -1.1, 0.6, 0.7, 1.2, -0.7, 0.1 }; + const float expected_output_data[data_length] = { -0.55, 0.3, 0.35, + 0.6, -0.35, 0.05 }; + float output_data[data_length]; + + tflite::testing::TestL2Normalization( + input_dims, input_data, expected_output_data, output_data); +} + +TF_LITE_MICRO_TEST(MultipleBatchFloatTest) +{ + int input_dims[] = { 4, 3, 1, 1, 6 }; + constexpr int data_length = 18; + const float input_data[data_length] = { + -1.1, 0.6, 0.7, 1.2, -0.7, 0.1, // batch 1 + -1.1, 0.6, 0.7, 1.2, -0.7, 0.1, // batch 2 + -1.1, 0.6, 0.7, 1.2, -0.7, 0.1, // batch 3 + }; + const float expected_output_data[data_length] = { + -0.55, 0.3, 0.35, 0.6, -0.35, 0.05, // batch 1 + -0.55, 0.3, 0.35, 0.6, -0.35, 0.05, // batch 2 + -0.55, 0.3, 0.35, 0.6, -0.35, 0.05, // batch 3 + }; + float output_data[data_length]; + + tflite::testing::TestL2Normalization( + input_dims, input_data, expected_output_data, output_data); +} + +TF_LITE_MICRO_TEST(ZerosVectorUint8Test) +{ + int input_dims[] = { 4, 1, 1, 1, 6 }; + constexpr int data_length = 6; + const uint8_t input_data[data_length] = { 127, 127, 127, 127, 127, 127 }; + const uint8_t expected_output[data_length] = { 128, 128, 128, 128, 128, 128 }; + uint8_t output_data[data_length]; + + tflite::testing::TestL2Normalization(input_dims, input_data, + expected_output, output_data); +} + +TF_LITE_MICRO_TEST(SimpleUint8Test) +{ + int input_dims[] = { 4, 1, 1, 1, 6 }; + constexpr int data_length = 6; + const uint8_t input_data[data_length] = { 57, 165, 172, 204, 82, 133 }; + const uint8_t expected_output[data_length] = { + 58, + 166, + 173, + 205, + 83, + 134, + }; + uint8_t output_data[data_length]; + + tflite::testing::TestL2Normalization(input_dims, input_data, + expected_output, output_data); +} + +TF_LITE_MICRO_TEST(SimpleInt8Test) +{ + int input_dims[] = { 4, 1, 1, 1, 6 }; + constexpr int data_length = 6; + const int8_t input_data[data_length] = { -71, 37, 44, 76, -46, 5 }; + const int8_t expected_output[data_length] = { -70, 38, 45, 77, -45, 6 }; + int8_t output_data[data_length]; + + tflite::testing::TestL2Normalization(input_dims, input_data, + expected_output, output_data); +} + +TF_LITE_MICRO_TEST(ZerosVectorInt8Test) +{ + int input_dims[] = { 4, 1, 1, 1, 6 }; + constexpr int data_length = 6; + const int8_t input_data[data_length] = { -1, -1, -1, -1, -1, -1 }; + const int8_t expected_output[data_length] = { 0, 0, 0, 0, 0, 0 }; + int8_t output_data[data_length]; + + tflite::testing::TestL2Normalization(input_dims, input_data, + expected_output, output_data); +} + +TF_LITE_MICRO_TEST(MultipleBatchUint8Test) +{ + int input_dims[] = { 2, 3, 6 }; + constexpr int data_length = 18; + const uint8_t input_data[data_length] = { + 57, 165, 172, 204, 82, 133, // batch 1 + 57, 165, 172, 204, 82, 133, // batch 2 + 57, 165, 172, 204, 82, 133, // batch 3 + }; + const uint8_t expected_output[data_length] = { + 58, 166, 173, 205, 83, 134, // batch 1 + 58, 166, 173, 205, 83, 134, // batch 2 + 58, 166, 173, 205, 83, 134, // batch 3 + }; + uint8_t output_data[data_length]; + + tflite::testing::TestL2Normalization(input_dims, input_data, + expected_output, output_data); +} + +TF_LITE_MICRO_TEST(MultipleBatchInt8Test) +{ + int input_dims[] = { 2, 3, 6 }; + constexpr int data_length = 18; + const int8_t input_data[data_length] = { + -71, 37, 44, 76, -46, 5, // batch 1 + -71, 37, 44, 76, -46, 5, // batch 2 + -71, 37, 44, 76, -46, 5, // batch 3 + }; + const int8_t expected_output[data_length] = { + -70, 38, 45, 77, -45, 6, // batch 1 + -70, 38, 45, 77, -45, 6, // batch 2 + -70, 38, 45, 77, -45, 6, // batch 3 + }; + int8_t output_data[data_length]; + + tflite::testing::TestL2Normalization(input_dims, input_data, + expected_output, output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/leaky_relu.cc b/components/tflite/tensorflow/lite/micro/kernels/leaky_relu.cc new file mode 100644 index 00000000..265245d9 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/leaky_relu.cc @@ -0,0 +1,163 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/leaky_relu.h" + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/process_broadcast_shapes.h" +#include "tensorflow/lite/kernels/internal/types.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace { + +// Input/output tensor index. +constexpr int kInputTensor = 0; +constexpr int kOutputTensor = 0; + +struct LeakyReluOpData { + // quantization parameters + int32_t output_multiplier_alpha; + int32_t output_shift_alpha; + int32_t output_multiplier_identity; + int32_t output_shift_identity; + int32_t input_zero_point; + int32_t output_zero_point; +}; + +template +void QuantizeLeakyRelu(const LeakyReluOpData &data, + const TfLiteEvalTensor *input, + TfLiteEvalTensor *output) +{ + LeakyReluParams op_params = {}; + + op_params.input_offset = data.input_zero_point; + op_params.output_offset = data.output_zero_point; + op_params.output_multiplier_alpha = data.output_multiplier_alpha; + op_params.output_shift_alpha = data.output_shift_alpha; + op_params.output_multiplier_identity = data.output_multiplier_identity; + op_params.output_shift_identity = data.output_shift_identity; + reference_ops::QuantizeLeakyRelu(op_params, + tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); +} + +TfLiteStatus CalculateOpData(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + const TfLiteTensor *input; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, kInputTensor, &input)); + TfLiteTensor *output; + TF_LITE_ENSURE_OK(context, + GetOutputSafe(context, node, kOutputTensor, &output)); + TF_LITE_ENSURE_TYPES_EQ(context, input->type, output->type); + + if (output->type == kTfLiteInt8 || output->type == kTfLiteInt16) { + LeakyReluOpData *data = static_cast(node->user_data); + const auto *params = + static_cast(node->builtin_data); + + data->input_zero_point = input->params.zero_point; + data->output_zero_point = output->params.zero_point; + + int output_shift_alpha; + double alpha_multiplier = static_cast( + input->params.scale * params->alpha / output->params.scale); + QuantizeMultiplier(alpha_multiplier, &data->output_multiplier_alpha, + &output_shift_alpha); + data->output_shift_alpha = static_cast(output_shift_alpha); + + int output_shift_identity; + double identity_multiplier = + static_cast(input->params.scale / output->params.scale); + QuantizeMultiplier(identity_multiplier, &data->output_multiplier_identity, + &output_shift_identity); + data->output_shift_identity = static_cast(output_shift_identity); + } + + return kTfLiteOk; +} + +void *LeakyReluInit(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(LeakyReluOpData)); +} + +TfLiteStatus LeakyReluPrepare(TfLiteContext *context, TfLiteNode *node) +{ + return CalculateOpData(context, node); +} + +TfLiteStatus LeakyReluEval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + const LeakyReluOpData &data = *static_cast(node->user_data); + + switch (input->type) { + case kTfLiteFloat32: { + LeakyReluParams op_params = {}; + const auto *params = + static_cast(node->builtin_data); + + op_params.alpha = params->alpha; + reference_ops::LeakyRelu(op_params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + return kTfLiteOk; + } break; + case kTfLiteInt8: { + QuantizeLeakyRelu(data, input, output); + return kTfLiteOk; + } break; + case kTfLiteInt16: { + QuantizeLeakyRelu(data, input, output); + return kTfLiteOk; + } break; + default: + TF_LITE_KERNEL_LOG( + context, "Only float32, int8 are supported by LEAKY_RELU, got %s.", + TfLiteTypeGetName(input->type)); + return kTfLiteError; + } + + return kTfLiteError; +} + +} // namespace + +TfLiteRegistration Register_LEAKY_RELU() +{ + return { /*init=*/LeakyReluInit, + /*free=*/nullptr, + /*prepare=*/LeakyReluPrepare, + /*invoke=*/LeakyReluEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/leaky_relu_test.cc b/components/tflite/tensorflow/lite/micro/kernels/leaky_relu_test.cc new file mode 100644 index 00000000..8356a5b7 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/leaky_relu_test.cc @@ -0,0 +1,250 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +// min/max are used to compute scale, zero-point, compare tolerance +template +struct TestLeakyReluParams { + // general parameters + float alpha; // alpha multiplier + + // quantization parameters + float scale; // quantization scale of input and output + int zero_point; // quantization zero_point of input and output + T *input_data; // quantized input storage + T *output_data; // quantized output storage + float tolerance; // output vs expected value tolerance +}; + +void ExecuteLeakyReluTest(const float alpha, const int tensors_count, + TfLiteTensor *tensors) +{ + TfLiteLeakyReluParams builtin_data = {}; + builtin_data.alpha = alpha; + + int kInputArrayData[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(kInputArrayData); + int kOutputArrayData[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(kOutputArrayData); + + const TfLiteRegistration registration = tflite::Register_LEAKY_RELU(); + micro::KernelRunner runner(registration, tensors, tensors_count, inputs_array, + outputs_array, static_cast(&builtin_data)); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); +} + +template +void TestLeakyRelu(const TestLeakyReluParams ¶ms, int *input_dims_data, + const T *input_data, int *expected_dims, + const T *expected_data, T *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(expected_dims); + const int output_count = ElementCount(*output_dims); + + TfLiteTensor tensors[] = { + CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims), + }; + constexpr int tensors_count = std::extent::value; + ExecuteLeakyReluTest(params.alpha, tensors_count, tensors); + + for (int i = 0; i < output_count; i++) { + TF_LITE_MICRO_EXPECT_EQ(expected_data[i], output_data[i]); + } +} + +template +void TestLeakyReluQuantized(const TestLeakyReluParams ¶ms, + int *input_dims_data, const float *input_data, + int *expected_dims, const float *expected_data, + float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(expected_dims); + const int output_count = ElementCount(*output_dims); + + TfLiteTensor tensors[] = { + CreateQuantizedTensor(input_data, params.input_data, input_dims, + params.scale, params.zero_point), + CreateQuantizedTensor(params.output_data, output_dims, params.scale, + params.zero_point), + }; + constexpr int kTensorsCount = std::extent::value; + ExecuteLeakyReluTest(params.alpha, kTensorsCount, tensors); + + Dequantize(params.output_data, output_count, params.scale, params.zero_point, + output_data); + const float kTolerance = params.tolerance; + for (int i = 0; i < output_count; i++) { + TF_LITE_MICRO_EXPECT_NEAR(expected_data[i], output_data[i], kTolerance); + } +} + +// Our fixed-point math function implementations have roughly 12 bits of +// accuracy, when specialized to 16-bit fixed-point arithmetic. +// That is purely an implementation compromise, it would have been possible +// to get closer to 16 bits of accuracy but that would be more expensive, +// and not needed for our purposes as ultimately the output is either +// immediately down-quantized to 8 bits, or will typically be at the output +// of the surrounding LSTM cell. +// So we can require roughly 2^-12 accuracy when the output is 16-bit, and +// we can more or less expect the full 2^-8 accuracy when the output is 8-bit. +// +// However, the representable output interval is often [-1, 1] (it has to be +// for tanh, and even for logistic, when we implement it in fixed-point, we +// typically have to do so on such a symmetric interval, e.g. ARM NEON only +// has signed fixed-point arithmetic (SQRDMULH)). As the width of [-1, 1] +// is 2, our representable values are often diluted by a factor of 2, whence +// the factor of 2 below. +const float kQuantizedTolerance = 2 * (1. / 256); + +template +void QuantizedActivationsOpTestLeakyRelu() +{ + int kDims[] = { 2, 5, 5 }; + constexpr float kInput[] = { + -5.0f, -4.6f, -4.2f, -3.8f, -3.4f, // Row 1 + -3.0f, -2.6f, -2.2f, -1.8f, -1.4f, // Row 2 + -1.0f, -0.6f, -0.2f, 0.2f, 0.6f, // Row 3 + 1.0f, 1.4f, 1.8f, 2.2f, 2.6f, // Row 4 + 3.0f, 3.4f, 3.8f, 4.2f, 4.6f, // Row 5 + }; + constexpr float kExpect[] = { + -0.50f, -0.46f, -0.42f, -0.38f, -0.34f, // Row 1 + -0.30f, -0.26f, -0.22f, -0.18f, -0.14f, // Row 2 + -0.10f, -0.06f, -0.02f, 0.20f, 0.60f, // Row 3 + 1.00f, 1.40f, 1.80f, 2.20f, 2.60f, // Row 4 + 3.00f, 3.40f, 3.80f, 4.20f, 4.60f, // Row 5 + }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + // setup quantization storage and parameters + integer_dtype q_output_data[kOutputCount]; + integer_dtype q_input_data[kOutputCount]; + + constexpr float kMin = -1; + constexpr float kMax = + std::numeric_limits::max() / + static_cast(std::numeric_limits::max() + 1); + // Quantize with a symmetric input / output range of {-5, 5}. + constexpr float kDataMin = 5 * kMin; + constexpr float kDataMax = 5 * kMax; + + TestLeakyReluParams params = {}; + params.alpha = 0.1f; + params.scale = ScaleFromMinMax(kDataMin, kDataMax); + params.zero_point = ZeroPointFromMinMax(kDataMin, kDataMax); + params.input_data = q_input_data; + params.output_data = q_output_data; + params.tolerance = kQuantizedTolerance * 5; + + TestLeakyReluQuantized(params, kDims, kInput, kDims, kExpect, output_data); +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(QuantizedActivationsOpTestLeakyReluInt8_1) +{ + int kDims[] = { 2, 2, 3 }; + constexpr float kInput[] = { 0.0f, 1.0f, 3.0f, 1.0f, -1.0f, -2.0f }; + constexpr float kExpect[] = { 0.0f, 1.0f, 3.0f, 1.0f, -0.5f, -1.0f }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + // setup quantization storage and parameters + int8_t q_output_data[kOutputCount]; + int8_t q_input_data[kOutputCount]; + + tflite::testing::TestLeakyReluParams params = {}; + params.alpha = 0.5f; + params.scale = 0.1f; + params.zero_point = 0; + params.input_data = q_input_data; + params.output_data = q_output_data; + params.tolerance = tflite::testing::kQuantizedTolerance; + + tflite::testing::TestLeakyReluQuantized(params, kDims, kInput, kDims, kExpect, + output_data); +} + +TF_LITE_MICRO_TEST(QuantizedActivationsOpTestLeakyReluInt8_2) +{ + tflite::testing::QuantizedActivationsOpTestLeakyRelu(); +} + +TF_LITE_MICRO_TEST(QuantizedActivationsOpTestLeakyReluInt16_1) +{ + int kDims[] = { 2, 2, 3 }; + constexpr float kInput[] = { 0.0f, 1.0f, 3.0f, 1.0f, -1.0f, -2.0f }; + constexpr float kExpect[] = { 0.0f, 1.0f, 3.0f, 1.0f, -0.5f, -1.0f }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + // setup quantization storage and parameters + int16_t q_output_data[kOutputCount]; + int16_t q_input_data[kOutputCount]; + + tflite::testing::TestLeakyReluParams params = {}; + params.alpha = 0.5f; + params.scale = 0.01f; + params.zero_point = 0; + params.input_data = q_input_data; + params.output_data = q_output_data; + params.tolerance = tflite::testing::kQuantizedTolerance; + + tflite::testing::TestLeakyReluQuantized(params, kDims, kInput, kDims, kExpect, + output_data); +} + +TF_LITE_MICRO_TEST(QuantizedActivationsOpTestLeakyReluInt16_2) +{ + tflite::testing::QuantizedActivationsOpTestLeakyRelu(); +} + +TF_LITE_MICRO_TEST(FloatActivationsOpTestLeakyRelu) +{ + int kDims[] = { 2, 2, 3 }; + constexpr float kInput[] = { 0.0f, 1.0f, 3.0f, 1.0f, -1.0f, -2.0f }; + constexpr float kExpect[] = { 0.0f, 1.0f, 3.0f, 1.0f, -0.5f, -1.0f }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + tflite::testing::TestLeakyReluParams params = {}; + params.alpha = 0.5f; + + tflite::testing::TestLeakyRelu(params, kDims, kInput, kDims, kExpect, + output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/log_softmax.cc b/components/tflite/tensorflow/lite/micro/kernels/log_softmax.cc new file mode 100644 index 00000000..13c4e9c5 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/log_softmax.cc @@ -0,0 +1,154 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/kernels/internal/reference/log_softmax.h" + +#include +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/internal/types.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace { + +// used only with quantized data +struct LogSoftmaxOpData { + int32_t input_multiplier; + int32_t input_left_shift; + int32_t reverse_scaling_divisor; + int32_t reverse_scaling_right_shift; + int diff_min; + size_t outer_size; // number of tensor elements skipping computation axis + size_t depth; // number of tensor elements on computation axis +}; + +// input/output tensor index +constexpr int kInputTensor = 0; +constexpr int kOutputTensor = 0; + +TfLiteStatus CalculateOpData(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + const TfLiteTensor *input; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, kInputTensor, &input)); + TfLiteTensor *output; + TF_LITE_ENSURE_OK(context, + GetOutputSafe(context, node, kOutputTensor, &output)); + TF_LITE_ENSURE_TYPES_EQ(context, input->type, output->type); + + TF_LITE_ENSURE(context, HaveSameShapes(input, output)); + + if (input->type == kTfLiteInt8) { + node->user_data = + context->AllocatePersistentBuffer(context, sizeof(LogSoftmaxOpData)); + auto data = static_cast(node->user_data); + + // quantization datum + constexpr int32_t kOutputZeroPoint = 127; + constexpr float kOutputScale = 16.0 / 256; + constexpr double kBeta = 1.0; + constexpr int kScaledDiffIntegerBits = 5; + + TF_LITE_ENSURE(context, output->params.scale == kOutputScale); + TF_LITE_ENSURE(context, output->params.zero_point == kOutputZeroPoint); + + int input_left_shift; + int reverse_scaling_right_shift; + tflite::PreprocessLogSoftmaxScalingExp( + kBeta, static_cast(input->params.scale), kScaledDiffIntegerBits, + &data->input_multiplier, &input_left_shift, + &data->reverse_scaling_divisor, &reverse_scaling_right_shift); + data->input_left_shift = static_cast(input_left_shift); + data->reverse_scaling_right_shift = + static_cast(-reverse_scaling_right_shift); + // diff_min has a negative value, and is used to limit the maximum magnitude + // of the diffs, which are <= 0. + data->diff_min = + -tflite::CalculateInputRadius(kScaledDiffIntegerBits, input_left_shift); + + RuntimeShape input_shape = GetTensorShape(input); + const int trailing_dim = input_shape.DimensionsCount() - 1; + data->outer_size = + static_cast(FlatSizeSkipDim(input_shape, trailing_dim)); + data->depth = static_cast(input_shape.Dims(trailing_dim)); + } + + return kTfLiteOk; +} + +TfLiteStatus LogSoftmaxPrepare(TfLiteContext *context, TfLiteNode *node) +{ + return CalculateOpData(context, node); +} + +TfLiteStatus LogSoftmaxEval(TfLiteContext *context, TfLiteNode *node) +{ + const LogSoftmaxOpData *data = + static_cast(node->user_data); + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + switch (input->type) { + case kTfLiteFloat32: { + SoftmaxParams op_params = {}; + reference_ops::LogSoftmax(op_params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + return kTfLiteOk; + } + case kTfLiteInt8: { + SoftmaxParams op_params = {}; + op_params.input_multiplier = data->input_multiplier; + op_params.input_left_shift = data->input_left_shift; + op_params.reverse_scaling_divisor = data->reverse_scaling_divisor; + op_params.reverse_scaling_right_shift = data->reverse_scaling_right_shift; + op_params.diff_min = data->diff_min; + reference_ops::LogSoftmax(op_params, data->outer_size, data->depth, + tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + return kTfLiteOk; + } + default: + TF_LITE_KERNEL_LOG(context, + "LOG_SOFTMAX only supports float32, int8, got %s.", + TfLiteTypeGetName(input->type)); + return kTfLiteError; + } +} + +} // namespace + +TfLiteRegistration Register_LOG_SOFTMAX() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/LogSoftmaxPrepare, + /*invoke=*/LogSoftmaxEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/log_softmax_test.cc b/components/tflite/tensorflow/lite/micro/kernels/log_softmax_test.cc new file mode 100644 index 00000000..77927a4b --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/log_softmax_test.cc @@ -0,0 +1,270 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +void ExecuteLogSoftmaxTest(int tensors_count, TfLiteTensor *tensors) +{ + int kInputArrayData[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(kInputArrayData); + int kOutputArrayData[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(kOutputArrayData); + + const TfLiteRegistration registration = tflite::Register_LOG_SOFTMAX(); + micro::KernelRunner runner(registration, tensors, tensors_count, inputs_array, + outputs_array, nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); +} + +template +void TestLogSoftmax(const float tolerance, int *input_dims_data, + const T *input_data, int *expected_dims, + const T *expected_data, T *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(expected_dims); + const int output_count = ElementCount(*output_dims); + + TfLiteTensor tensors[] = { + CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims), + }; + constexpr int kTensorsCount = std::extent::value; + ExecuteLogSoftmaxTest(kTensorsCount, tensors); + + for (int i = 0; i < output_count; i++) { + TF_LITE_MICRO_EXPECT_NEAR(expected_data[i], output_data[i], tolerance); + } +} + +// min/max are used to compute scale, zero-point +template +struct TestLogSoftmaxParams { + // quantization parameters + float data_min; // input and output data minimum value + float data_max; // input and output data maximum value + T *input_data; // quantized input storage + T *output_data; // quantized output storage + float tolerance; // maximum compare difference +}; + +template +void TestLogSoftmaxQuantized(const TestLogSoftmaxParams ¶ms, + int *input_dims_data, const float *input_data, + int *expected_dims, const float *expected_data, + const T *expected_data_quantized, + float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(expected_dims); + const int output_count = ElementCount(*output_dims); + + constexpr float kOutputScale = 16.0 / 256; + constexpr int kOutputZeroPoint = 127; + const float scale = ScaleFromMinMax(params.data_min, params.data_max); + const int zero_point = + ZeroPointFromMinMax(params.data_min, params.data_max); + + TfLiteTensor tensors[] = { + CreateQuantizedTensor(input_data, params.input_data, input_dims, scale, + zero_point), + CreateQuantizedTensor(params.output_data, output_dims, kOutputScale, + kOutputZeroPoint), + }; + constexpr int kTensorsCount = std::extent::value; + + ExecuteLogSoftmaxTest(kTensorsCount, tensors); + + for (int i = 0; i < output_count; i++) { + TF_LITE_MICRO_EXPECT_EQ(expected_data_quantized[i], params.output_data[i]); + } + Dequantize(params.output_data, output_count, kOutputScale, kOutputZeroPoint, + output_data); + for (int i = 0; i < output_count; i++) { + TF_LITE_MICRO_EXPECT_NEAR(expected_data[i], output_data[i], + params.tolerance); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +// This contains the same test values as the Softmax test, but reference answer +// generated via the following snippet of python: +// logits1 = tf.constant([[0, -6, 2, 4],[3, -2, 10, 1]], dtype=tf.float32) +// logits2 = tf.constant([[0,-6],[2,4],[3,-2],[10,1]], dtype=tf.float32) +// lsm1 = tf.nn.log_softmax(logits1) +// lsm2 = tf.nn.log_softmax(logits2) +// with tf.Session() as sess: +// print('lsm1', sess.run(lsm1)) +// print('lsm2', sess.run(lsm2)) +TF_LITE_MICRO_TEST(FloatActivationsOpTestLogSoftmax) +{ + int kDims1[] = { 2, 2, 4 }; + constexpr float kInput[] = { + 0, + -6, + 2, + 4, + 3, + -2, + 10, + 1, + }; + constexpr float kExpect1[] = { + -4.14297, -10.14297, -2.14297, -.142971, // + -7.00104, -12.00104, -.00104087, -9.00104, // + }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + constexpr float kTolerance = 1e-5; + + tflite::testing::TestLogSoftmax(kTolerance, kDims1, kInput, kDims1, kExpect1, + output_data); + + // Same input, but a different shape. + int kDims2[] = { 2, 4, 2 }; + constexpr float kExpect2[] = { + -.00247565, + -6.00247, + -2.12692, + -.126928, + -.00671534, + -5.00671, + -.000123374, + -9.00012, + }; + + tflite::testing::TestLogSoftmax(kTolerance, kDims2, kInput, kDims2, kExpect2, + output_data); +} + +TF_LITE_MICRO_TEST(LogSoftmaxOpTestSimpleTest) +{ + int kDims[] = { 2, 2, 5 }; + constexpr float kInput[] = { + 1.0, 2.0, 3.0, 4.0, 5.0, // + -1.0, -2.0, -3.0, -4.0, -5.0, // + }; + constexpr float kExpect[] = { + -4.45191431, -3.45191431, -2.45191431, -1.45191443, -0.4519144, // + -0.4519144, -1.45191443, -2.45191431, -3.45191431, -4.45191431 // + }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + constexpr float kTolerance = 1e-6; + + tflite::testing::TestLogSoftmax(kTolerance, kDims, kInput, kDims, kExpect, + output_data); +} + +TF_LITE_MICRO_TEST(QuantizedActivationsOpTestLogSoftmaxInt8) +{ + int kDims[] = { 2, 2, 4 }; + constexpr float kInput[] = { + 0, + -6, + 2, + 4, + 3, + -2, + 10, + 1, + }; + constexpr float kExpect[] = { + -4.14297, + -10.14297, + -2.14297, + -.142971, + -7.00104, + -12.00104, + -.00104087, + -9.00104, + }; + constexpr int8_t kExpectQuantized[] = { + 61, + -36, + 93, + 125, + 15, + -65, + 127, + -16, + }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + // setup quantization storage and parameters + int8_t q_output_data[kOutputCount]; + int8_t q_input_data[kOutputCount]; + constexpr float kMin = -10; + constexpr float kMax = 10; + constexpr float kLogSoftmaxQuantizedTolerance = 0.06355; + tflite::testing::TestLogSoftmaxParams params = {}; + params.data_min = kMin; + params.data_max = kMax; + params.input_data = q_input_data; + params.output_data = q_output_data; + params.tolerance = kLogSoftmaxQuantizedTolerance; + + tflite::testing::TestLogSoftmaxQuantized( + params, kDims, kInput, kDims, kExpect, kExpectQuantized, output_data); +} + +TF_LITE_MICRO_TEST(ExtraTestLogSoftmaxInt8) +{ + int kDims[] = { 2, 3, 1 }; + constexpr float kInput[] = { 0, -1, 1 }; + constexpr float kExpect[] = { 0, 0, 0 }; + constexpr int8_t kExpectQuantized[] = { 127, 127, 127 }; + constexpr int kOutputCount = std::extent::value; + float output_data[kOutputCount]; + + // setup quantization storage and parameters + int8_t q_output_data[kOutputCount]; + int8_t q_input_data[kOutputCount]; + constexpr float kMin = -1; + constexpr float kMax = 1; + constexpr float kLogSoftmaxQuantizedTolerance = 0.06355; + tflite::testing::TestLogSoftmaxParams params = {}; + params.data_min = kMin; + params.data_max = kMax; + params.input_data = q_input_data; + params.output_data = q_output_data; + params.tolerance = kLogSoftmaxQuantizedTolerance; + + tflite::testing::TestLogSoftmaxQuantized( + params, kDims, kInput, kDims, kExpect, kExpectQuantized, output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/logical.cc b/components/tflite/tensorflow/lite/micro/kernels/logical.cc new file mode 100644 index 00000000..ea670018 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/logical.cc @@ -0,0 +1,116 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/reference/binary_function.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace logical { +namespace { + +// Input/output tensor index. +constexpr int kInputTensor1 = 0; +constexpr int kInputTensor2 = 1; +constexpr int kOutputTensor = 0; + +TfLiteStatus LogicalImpl(TfLiteContext *context, TfLiteNode *node, + bool (*func)(bool, bool)) +{ + const TfLiteEvalTensor *input1 = + tflite::micro::GetEvalInput(context, node, kInputTensor1); + const TfLiteEvalTensor *input2 = + tflite::micro::GetEvalInput(context, node, kInputTensor2); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + if (tflite::micro::HaveSameShapes(input1, input2)) { + reference_ops::BinaryFunction( + tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorData(input1), + tflite::micro::GetTensorShape(input2), + tflite::micro::GetTensorData(input2), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output), func); + } else { + reference_ops::BroadcastBinaryFunction4DSlow( + tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorData(input1), + tflite::micro::GetTensorShape(input2), + tflite::micro::GetTensorData(input2), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output), func); + } + + return kTfLiteOk; +} + +bool LogicalOr(bool x, bool y) +{ + return x || y; +} + +TfLiteStatus LogicalOrEval(TfLiteContext *context, TfLiteNode *node) +{ + return LogicalImpl(context, node, LogicalOr); +} + +bool LogicalAnd(bool x, bool y) +{ + return x && y; +} + +TfLiteStatus LogicalAndEval(TfLiteContext *context, TfLiteNode *node) +{ + return LogicalImpl(context, node, LogicalAnd); +} + +} // namespace +} // namespace logical + +TfLiteRegistration Register_LOGICAL_OR() +{ + // Init, Free, Prepare, Eval are satisfying the Interface required by + // TfLiteRegistration. + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/nullptr, + /*invoke=*/logical::LogicalOrEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +TfLiteRegistration Register_LOGICAL_AND() +{ + // Init, Free, Prepare, Eval are satisfying the Interface required by + // TfLiteRegistration. + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/nullptr, + /*invoke=*/logical::LogicalAndEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/logical_test.cc b/components/tflite/tensorflow/lite/micro/kernels/logical_test.cc new file mode 100644 index 00000000..4bf203ed --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/logical_test.cc @@ -0,0 +1,121 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +void TestLogicalOp(const TfLiteRegistration ®istration, + int *input1_dims_data, const bool *input1_data, + int *input2_dims_data, const bool *input2_data, + int *output_dims_data, const bool *expected_output_data, + bool *output_data) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input1_data, input1_dims), + CreateTensor(input2_data, input2_dims), + CreateTensor(output_data, output_dims), + }; + + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + TF_LITE_MICRO_EXPECT_EQ(output_dims_count, 4); + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output_data[i], output_data[i]); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(LogicalOr) +{ + int shape[] = { 4, 1, 1, 1, 4 }; + const bool input1[] = { true, false, false, true }; + const bool input2[] = { true, false, true, false }; + const bool golden[] = { true, false, true, true }; + bool output_data[4]; + tflite::testing::TestLogicalOp(tflite::ops::micro::Register_LOGICAL_OR(), + shape, input1, shape, input2, shape, golden, + output_data); +} + +TF_LITE_MICRO_TEST(BroadcastLogicalOr) +{ + int input1_shape[] = { 4, 1, 1, 1, 4 }; + const bool input1[] = { true, false, false, true }; + int input2_shape[] = { 4, 1, 1, 1, 1 }; + const bool input2[] = { false }; + const bool golden[] = { true, false, false, true }; + bool output_data[4]; + tflite::testing::TestLogicalOp(tflite::ops::micro::Register_LOGICAL_OR(), + input1_shape, input1, input2_shape, input2, + input1_shape, golden, output_data); +} + +TF_LITE_MICRO_TEST(LogicalAnd) +{ + int shape[] = { 4, 1, 1, 1, 4 }; + const bool input1[] = { true, false, false, true }; + const bool input2[] = { true, false, true, false }; + const bool golden[] = { true, false, false, false }; + bool output_data[4]; + tflite::testing::TestLogicalOp(tflite::ops::micro::Register_LOGICAL_AND(), + shape, input1, shape, input2, shape, golden, + output_data); +} + +TF_LITE_MICRO_TEST(BroadcastLogicalAnd) +{ + int input1_shape[] = { 4, 1, 1, 1, 4 }; + const bool input1[] = { true, false, false, true }; + int input2_shape[] = { 4, 1, 1, 1, 1 }; + const bool input2[] = { true }; + const bool golden[] = { true, false, false, true }; + bool output_data[4]; + tflite::testing::TestLogicalOp(tflite::ops::micro::Register_LOGICAL_AND(), + input1_shape, input1, input2_shape, input2, + input1_shape, golden, output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/logistic.cc b/components/tflite/tensorflow/lite/micro/kernels/logistic.cc new file mode 100644 index 00000000..8f2396f0 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/logistic.cc @@ -0,0 +1,155 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/integer_ops/logistic.h" + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/logistic.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace activations { +namespace { +constexpr int kInputTensor = 0; +constexpr int kOutputTensor = 0; + +struct OpData { + int32_t input_zero_point; + int32_t input_range_radius; + int32_t input_multiplier; + int input_left_shift; +}; + +TfLiteStatus CalculateArithmeticOpData(TfLiteContext *context, TfLiteNode *node, + OpData *data) +{ + const TfLiteTensor *input = GetInput(context, node, kInputTensor); + TF_LITE_ENSURE(context, input != nullptr); + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + + TF_LITE_ENSURE_TYPES_EQ(context, input->type, output->type); + if (input->type == kTfLiteInt8) { + TF_LITE_ENSURE_EQ(context, output->params.zero_point, + std::numeric_limits::min()); + + static constexpr int kInputIntegerBits = 4; + const double input_real_multiplier = + static_cast(input->params.scale) * + static_cast(1 << (31 - kInputIntegerBits)); + + data->input_zero_point = input->params.zero_point; + + const double q = std::frexp(input_real_multiplier, &data->input_left_shift); + data->input_multiplier = static_cast(TfLiteRound(q * (1ll << 31))); + + data->input_range_radius = + CalculateInputRadius(kInputIntegerBits, data->input_left_shift, 31); + } + return kTfLiteOk; +} +} // namespace + +void *LogisticInit(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(OpData)); +} + +TfLiteStatus LogisticPrepare(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + OpData *data = static_cast(node->user_data); + + return CalculateArithmeticOpData(context, node, data); +} + +TfLiteStatus LogisticEval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + TFLITE_DCHECK(node->user_data != nullptr); + OpData *data = static_cast(node->user_data); + + if (input->type == kTfLiteFloat32) { + switch (output->type) { + case kTfLiteFloat32: { + reference_ops::Logistic(tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + return kTfLiteOk; + } + default: + TF_LITE_KERNEL_LOG(context, "Input %s, output %s not supported.", + TfLiteTypeGetName(input->type), + TfLiteTypeGetName(output->type)); + return kTfLiteError; + } + } else if (input->type == kTfLiteInt8) { + switch (output->type) { + case kTfLiteInt8: { + reference_integer_ops::Logistic( + data->input_zero_point, data->input_range_radius, + data->input_multiplier, data->input_left_shift, + NumElements(input->dims), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorData(output)); + return kTfLiteOk; + } + default: + TF_LITE_KERNEL_LOG(context, "Input %s, output %s not supported.", + TfLiteTypeGetName(input->type), + TfLiteTypeGetName(output->type)); + return kTfLiteError; + } + } else { + // TODO(b/141211002): Also support other data types once we have supported + // temporary tensors in TFLM. + TF_LITE_KERNEL_LOG(context, "Input %s, output %s not supported.", + TfLiteTypeGetName(input->type), + TfLiteTypeGetName(output->type)); + return kTfLiteError; + } + return kTfLiteOk; +} + +} // namespace activations + +TfLiteRegistration Register_LOGISTIC() +{ + return { /*init=*/activations::LogisticInit, + /*free=*/nullptr, + /*prepare=*/activations::LogisticPrepare, + /*invoke=*/activations::LogisticEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/logistic_test.cc b/components/tflite/tensorflow/lite/micro/kernels/logistic_test.cc new file mode 100644 index 00000000..78be5f2c --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/logistic_test.cc @@ -0,0 +1,193 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +// The Logistic kernel assumes an output in the range [0, 1.0], leading to these +// quantization parameters. +const float quantized_output_scale = 1.0 / 255.0; +const int quantized_output_zero_point_int8 = -128; + +const int flat_size_basic = 10; +int shape_basic[] = { 2, 2, 5 }; +const float input_data_basic[] = { 1, 2, 3, 4, 5, -1, -2, -3, -4, -5 }; +const float golden_basic[] = { 0.73105858, 0.88079708, 0.95257413, 0.98201379, + 0.99330715, 0.26894142, 0.11920292, 0.04742587, + 0.01798621, 0.00669285 }; + +const int flat_size_wide_range = 10; +int shape_wide_range[] = { 2, 1, 5 }; +const float input_data_wide_range[]{ + 1.0, + 2.0, + 3.0, + 4.0, + 93.0, + -1.0, + -2.0, + -3.0, + -4.0, + -93.0, +}; +const float golden_wide_range[] = { + 0.73105858, + 0.88079708, + 0.95257413, + 0.98201379, + 1.0, + 0.26894142, + 0.11920292, + 0.04742587, + 0.01798621, + 0.0, +}; + +template +void ValidateLogisticGoldens(TfLiteTensor *tensors, const int tensor_count, + T *output_data, const T *golden, + int output_dims_count, float tolerance) +{ + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = + tflite::ops::micro::Register_LOGISTIC(); + micro::KernelRunner runner(registration, tensors, tensor_count, inputs_array, + outputs_array, nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(golden[i], output_data[i], tolerance); + } +} + +void TestLogisticFloat(int *input_dims_data, const float *input_data, + const float *golden, int *output_dims_data, + float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_elements_count = ElementCount(*output_dims); + + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims), + }; + + ValidateLogisticGoldens(tensors, tensors_size, output_data, golden, + output_elements_count, 1e-5); +} + +template +void TestLogisticQuantized(int *input_dims_data, const float *input_data, + T *input_quantized, const float input_scale, + const int input_zero_point, const float *golden, + T *golden_quantized, int *output_dims_data, + const float output_scale, + const int output_zero_point, int8_t *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_elements_count = ElementCount(*output_dims); + + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(input_data, input_quantized, input_dims, + input_scale, input_zero_point), + CreateQuantizedTensor(output_data, output_dims, output_scale, + output_zero_point), + }; + + tflite::Quantize(golden, golden_quantized, output_elements_count, + output_scale, output_zero_point); + ValidateLogisticGoldens(tensors, tensors_size, output_data, golden_quantized, + output_elements_count, 1.0); +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(LogisticFloatBasicShouldMatchGolden) +{ + float output_data[tflite::testing::flat_size_basic]; + tflite::testing::TestLogisticFloat( + tflite::testing::shape_basic, tflite::testing::input_data_basic, + tflite::testing::golden_basic, tflite::testing::shape_basic, output_data); +} + +TF_LITE_MICRO_TEST(LogisticQuantizedInt8BasicShouldMatchGolden) +{ + const float input_scale = 0.1; + const int input_zero_point = 0; + int8_t input_quantized[tflite::testing::flat_size_basic]; + int8_t golden_quantized[tflite::testing::flat_size_basic]; + int8_t output_data[tflite::testing::flat_size_basic]; + + tflite::testing::TestLogisticQuantized( + tflite::testing::shape_basic, tflite::testing::input_data_basic, + input_quantized, input_scale, input_zero_point, + tflite::testing::golden_basic, golden_quantized, + tflite::testing::shape_basic, tflite::testing::quantized_output_scale, + tflite::testing::quantized_output_zero_point_int8, output_data); +} + +TF_LITE_MICRO_TEST(LogisticFloatWideRangeShouldMatchGolden) +{ + float output_data[tflite::testing::flat_size_wide_range]; + tflite::testing::TestLogisticFloat( + tflite::testing::shape_wide_range, tflite::testing::input_data_wide_range, + tflite::testing::golden_wide_range, tflite::testing::shape_wide_range, + output_data); +} + +TF_LITE_MICRO_TEST(LogisticQuantizedInt8WideRangeShouldMatchGolden) +{ + const float input_scale = 1.0; + const int input_zero_point = 0; + int8_t input_quantized[tflite::testing::flat_size_wide_range]; + int8_t golden_quantized[tflite::testing::flat_size_wide_range]; + int8_t output_data[tflite::testing::flat_size_wide_range]; + + tflite::testing::TestLogisticQuantized( + tflite::testing::shape_wide_range, tflite::testing::input_data_wide_range, + input_quantized, input_scale, input_zero_point, + tflite::testing::golden_wide_range, golden_quantized, + tflite::testing::shape_wide_range, + tflite::testing::quantized_output_scale, + tflite::testing::quantized_output_zero_point_int8, output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/maximum_minimum.cc b/components/tflite/tensorflow/lite/micro/kernels/maximum_minimum.cc new file mode 100644 index 00000000..608f6aaf --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/maximum_minimum.cc @@ -0,0 +1,155 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/maximum_minimum.h" + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace maximum_minimum { +namespace { + +// This file has a reference implementation of TFMaximum/TFMinimum. +enum KernelType { + kReference, +}; + +constexpr int kInputTensor1 = 0; +constexpr int kInputTensor2 = 1; +constexpr int kOutputTensor = 0; + +struct OpContext { + OpContext(TfLiteContext *context, TfLiteNode *node) + { + input1 = tflite::micro::GetEvalInput(context, node, kInputTensor1); + input2 = tflite::micro::GetEvalInput(context, node, kInputTensor2); + output = tflite::micro::GetEvalOutput(context, node, kOutputTensor); + } + const TfLiteEvalTensor *input1; + const TfLiteEvalTensor *input2; + TfLiteEvalTensor *output; +}; + +struct MaximumOp { + template + static data_type op(data_type el1, data_type el2) + { + return el1 > el2 ? el1 : el2; + } +}; + +struct MinimumOp { + template + static data_type op(data_type el1, data_type el2) + { + return el1 < el2 ? el1 : el2; + } +}; + +} // namespace + +template +void TFLiteOperation(TfLiteContext *context, TfLiteNode *node, + const OpContext &op_context) +{ + reference_ops::MaximumMinimumBroadcastSlow( + tflite::micro::GetTensorShape(op_context.input1), + tflite::micro::GetTensorData(op_context.input1), + tflite::micro::GetTensorShape(op_context.input2), + tflite::micro::GetTensorData(op_context.input2), + tflite::micro::GetTensorShape(op_context.output), + tflite::micro::GetTensorData(op_context.output), + op_type::template op); +} + +template +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + OpContext op_context(context, node); + + if (kernel_type == kReference) { + switch (op_context.output->type) { + case kTfLiteFloat32: + TFLiteOperation(context, node, op_context); + break; + case kTfLiteUInt8: + TFLiteOperation(context, node, op_context); + break; + case kTfLiteInt8: + TFLiteOperation(context, node, op_context); + break; + case kTfLiteInt32: + TFLiteOperation(context, node, op_context); + break; + case kTfLiteInt64: + TFLiteOperation(context, node, op_context); + break; + default: + TF_LITE_KERNEL_LOG(context, + "Type %s (%d) is not supported by Maximum/Minimum.", + TfLiteTypeGetName(op_context.output->type), + op_context.output->type); + return kTfLiteError; + } + } else { + TF_LITE_KERNEL_LOG(context, + "Kernel type not supported by Maximum/Minimum."); + return kTfLiteError; + } + return kTfLiteOk; +} + +} // namespace maximum_minimum + +TfLiteRegistration Register_MAXIMUM() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/nullptr, + /*invoke=*/ + maximum_minimum::Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +TfLiteRegistration Register_MINIMUM() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/nullptr, + /*invoke=*/ + maximum_minimum::Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/maximum_minimum_test.cc b/components/tflite/tensorflow/lite/micro/kernels/maximum_minimum_test.cc new file mode 100644 index 00000000..f38f92a6 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/maximum_minimum_test.cc @@ -0,0 +1,232 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +void TestMaxMinFloat(const TfLiteRegistration ®istration, + int *input1_dims_data, const float *input1_data, + int *input2_dims_data, const float *input2_data, + const float *expected_output_data, int *output_dims_data, + float *output_data) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input1_data, input1_dims), + CreateTensor(input2_data, input2_dims), + CreateTensor(output_data, output_dims), + }; + + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output_data[i], output_data[i], 1e-5f); + } +} + +void TestMaxMinQuantized(const TfLiteRegistration ®istration, + int *input1_dims_data, const uint8_t *input1_data, + float const input1_scale, const int input1_zero_point, + int *input2_dims_data, const uint8_t *input2_data, + const float input2_scale, const int input2_zero_point, + const uint8_t *expected_output_data, + const float output_scale, const int output_zero_point, + int *output_dims_data, uint8_t *output_data) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(input1_data, input1_dims, input1_scale, + input1_zero_point), + CreateQuantizedTensor(input2_data, input2_dims, input2_scale, + input2_zero_point), + CreateQuantizedTensor(output_data, output_dims, output_scale, + output_zero_point), + }; + + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output_data[i], output_data[i]); + } +} + +void TestMaxMinQuantizedInt32(const TfLiteRegistration ®istration, + int *input1_dims_data, const int32_t *input1_data, + int *input2_dims_data, const int32_t *input2_data, + const int32_t *expected_output_data, + int *output_dims_data, int32_t *output_data) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input1_data, input1_dims), + CreateTensor(input2_data, input2_dims), + CreateTensor(output_data, output_dims), + }; + + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output_data[i], output_data[i]); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(FloatTest) +{ + int dims[] = { 3, 3, 1, 2 }; + const float data1[] = { 1.0, 0.0, -1.0, 11.0, -2.0, -1.44 }; + const float data2[] = { -1.0, 0.0, 1.0, 12.0, -3.0, -1.43 }; + const float golden_max[] = { 1.0, 0.0, 1.0, 12.0, -2.0, -1.43 }; + const float golden_min[] = { -1.0, 0.0, -1.0, 11.0, -3.0, -1.44 }; + float output_data[6]; + + tflite::testing::TestMaxMinFloat(tflite::ops::micro::Register_MAXIMUM(), dims, + data1, dims, data2, golden_max, dims, + output_data); + + tflite::testing::TestMaxMinFloat(tflite::ops::micro::Register_MINIMUM(), dims, + data1, dims, data2, golden_min, dims, + output_data); +} + +TF_LITE_MICRO_TEST(Uint8Test) +{ + int dims[] = { 3, 3, 1, 2 }; + const uint8_t data1[] = { 1, 0, 2, 11, 2, 23 }; + const uint8_t data2[] = { 0, 0, 1, 12, 255, 1 }; + const uint8_t golden_max[] = { 1, 0, 2, 12, 255, 23 }; + const uint8_t golden_min[] = { 0, 0, 1, 11, 2, 1 }; + + const float input_scale = 1.0; + const int input_zero_point = 0; + const float output_scale = 1.0; + const int output_zero_point = 0; + + uint8_t output_data[6]; + + tflite::testing::TestMaxMinQuantized( + tflite::ops::micro::Register_MAXIMUM(), dims, data1, input_scale, + input_zero_point, dims, data2, input_scale, input_zero_point, golden_max, + output_scale, output_zero_point, dims, output_data); + + tflite::testing::TestMaxMinQuantized( + tflite::ops::micro::Register_MINIMUM(), dims, data1, input_scale, + input_zero_point, dims, data2, input_scale, input_zero_point, golden_min, + output_scale, output_zero_point, dims, output_data); +} + +TF_LITE_MICRO_TEST(FloatWithBroadcastTest) +{ + int dims[] = { 3, 3, 1, 2 }; + int dims_scalar[] = { 1, 2 }; + const float data1[] = { 1.0, 0.0, -1.0, -2.0, -1.44, 11.0 }; + const float data2[] = { 0.5, 2.0 }; + const float golden_max[] = { 1.0, 2.0, 0.5, 2.0, 0.5, 11.0 }; + const float golden_min[] = { 0.5, 0.0, -1.0, -2.0, -1.44, 2.0 }; + float output_data[6]; + + tflite::testing::TestMaxMinFloat(tflite::ops::micro::Register_MAXIMUM(), dims, + data1, dims_scalar, data2, golden_max, dims, + output_data); + + tflite::testing::TestMaxMinFloat(tflite::ops::micro::Register_MINIMUM(), dims, + data1, dims_scalar, data2, golden_min, dims, + output_data); +} + +TF_LITE_MICRO_TEST(Int32WithBroadcastTest) +{ + int dims[] = { 3, 3, 1, 2 }; + int dims_scalar[] = { 1, 1 }; + const int32_t data1[] = { 1, 0, -1, -2, 3, 11 }; + const int32_t data2[] = { 2 }; + const int32_t golden_max[] = { 2, 2, 2, 2, 3, 11 }; + const int32_t golden_min[] = { 1, 0, -1, -2, 2, 2 }; + int32_t output_data[6]; + + tflite::testing::TestMaxMinQuantizedInt32( + tflite::ops::micro::Register_MAXIMUM(), dims, data1, dims_scalar, data2, + golden_max, dims, output_data); + + tflite::testing::TestMaxMinQuantizedInt32( + tflite::ops::micro::Register_MINIMUM(), dims, data1, dims_scalar, data2, + golden_min, dims, output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/micro_ops.h b/components/tflite/tensorflow/lite/micro/kernels/micro_ops.h new file mode 100644 index 00000000..a5c8717c --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/micro_ops.h @@ -0,0 +1,121 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_MICRO_KERNELS_MICRO_OPS_H_ +#define TENSORFLOW_LITE_MICRO_KERNELS_MICRO_OPS_H_ + +#include "tensorflow/lite/c/common.h" + +// Forward declaration of all micro op kernel registration methods. These +// registrations are included with the standard `BuiltinOpResolver`. +// +// This header is particularly useful in cases where only a subset of ops are +// needed. In such cases, the client can selectively add only the registrations +// their model requires, using a custom `(Micro)MutableOpResolver`. Selective +// registration in turn allows the linker to strip unused kernels. + +namespace tflite { +// TFLM is incrementally moving towards a flat tflite namespace +// (https://abseil.io/tips/130). Any new ops (or cleanup of existing ops should +// have their Register function declarations in the tflite namespace. + +TfLiteRegistration Register_ADD_N(); +TfLiteRegistration Register_AVERAGE_POOL_2D(); +TfLiteRegistration Register_BATCH_TO_SPACE_ND(); +TfLiteRegistration Register_CAST(); +TfLiteRegistration Register_CUMSUM(); +TfLiteRegistration Register_DEPTH_TO_SPACE(); +TfLiteRegistration Register_DEPTHWISE_CONV_2D(); +TfLiteRegistration Register_DIV(); +TfLiteRegistration Register_ELU(); +TfLiteRegistration Register_EXP(); +TfLiteRegistration Register_EXPAND_DIMS(); +TfLiteRegistration Register_FILL(); +TfLiteRegistration Register_FLOOR_DIV(); +TfLiteRegistration Register_FLOOR_MOD(); +TfLiteRegistration Register_GATHER(); +TfLiteRegistration Register_GATHER_ND(); +TfLiteRegistration Register_IF(); +TfLiteRegistration Register_L2_POOL_2D(); +TfLiteRegistration Register_LEAKY_RELU(); +TfLiteRegistration Register_LOG_SOFTMAX(); +TfLiteRegistration Register_MAX_POOL_2D(); +TfLiteRegistration Register_QUANTIZE(); +TfLiteRegistration Register_RESIZE_BILINEAR(); +TfLiteRegistration Register_SHAPE(); +TfLiteRegistration Register_SPACE_TO_BATCH_ND(); +TfLiteRegistration Register_SPACE_TO_DEPTH(); +TfLiteRegistration Register_SQUEEZE(); +TfLiteRegistration Register_SVDF(); +TfLiteRegistration Register_TRANSPOSE(); +TfLiteRegistration Register_TRANSPOSE_CONV(); +TfLiteRegistration Register_ZEROS_LIKE(); + +namespace ops { +namespace micro { +TfLiteRegistration Register_ABS(); +TfLiteRegistration Register_ADD(); +TfLiteRegistration Register_ARG_MAX(); +TfLiteRegistration Register_ARG_MIN(); +TfLiteRegistration Register_CEIL(); +// TODO(b/160234179): Change custom OPs to also return by value. +TfLiteRegistration *Register_CIRCULAR_BUFFER(); +TfLiteRegistration Register_CONCATENATION(); +TfLiteRegistration Register_COS(); +TfLiteRegistration Register_DEQUANTIZE(); +TfLiteRegistration Register_EQUAL(); +TfLiteRegistration Register_FLOOR(); +TfLiteRegistration Register_GREATER(); +TfLiteRegistration Register_GREATER_EQUAL(); +TfLiteRegistration Register_HARD_SWISH(); +TfLiteRegistration Register_LESS(); +TfLiteRegistration Register_LESS_EQUAL(); +TfLiteRegistration Register_LOG(); +TfLiteRegistration Register_LOGICAL_AND(); +TfLiteRegistration Register_LOGICAL_NOT(); +TfLiteRegistration Register_LOGICAL_OR(); +TfLiteRegistration Register_LOGISTIC(); +TfLiteRegistration Register_MAXIMUM(); +TfLiteRegistration Register_MEAN(); +TfLiteRegistration Register_MINIMUM(); +TfLiteRegistration Register_MUL(); +TfLiteRegistration Register_NEG(); +TfLiteRegistration Register_NOT_EQUAL(); +TfLiteRegistration Register_PACK(); +TfLiteRegistration Register_PAD(); +TfLiteRegistration Register_PADV2(); +TfLiteRegistration Register_PRELU(); +TfLiteRegistration Register_REDUCE_MAX(); +TfLiteRegistration Register_RELU(); +TfLiteRegistration Register_RELU6(); +TfLiteRegistration Register_RESHAPE(); +TfLiteRegistration Register_RESIZE_NEAREST_NEIGHBOR(); +TfLiteRegistration Register_ROUND(); +TfLiteRegistration Register_RSQRT(); +TfLiteRegistration Register_SIN(); +TfLiteRegistration Register_SPLIT(); +TfLiteRegistration Register_SPLIT_V(); +TfLiteRegistration Register_SQRT(); +TfLiteRegistration Register_SQUARE(); +TfLiteRegistration Register_STRIDED_SLICE(); +TfLiteRegistration Register_SUB(); +TfLiteRegistration Register_UNPACK(); +TfLiteRegistration Register_L2_NORMALIZATION(); +TfLiteRegistration Register_TANH(); + +} // namespace micro +} // namespace ops +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_KERNELS_MICRO_OPS_H_ diff --git a/components/tflite/tensorflow/lite/micro/kernels/micro_utils.h b/components/tflite/tensorflow/lite/micro/kernels/micro_utils.h new file mode 100644 index 00000000..c3cbf9ec --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/micro_utils.h @@ -0,0 +1,41 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_MICRO_KERNELS_MICRO_UTILS_H_ +#define TENSORFLOW_LITE_MICRO_KERNELS_MICRO_UTILS_H_ +namespace tflite { +namespace ops { +namespace micro { +// Same as gtl::Greater but defined here to reduce dependencies and +// binary size for micro environment. +struct Greater { + template + bool operator()(const T &x, const T &y) const + { + return x > y; + } +}; + +struct Less { + template + bool operator()(const T &x, const T &y) const + { + return x < y; + } +}; + +} // namespace micro +} // namespace ops +} // namespace tflite +#endif // TENSORFLOW_LITE_MICRO_KERNELS_MICRO_UTILS_H_ diff --git a/components/tflite/tensorflow/lite/micro/kernels/mul.cc b/components/tflite/tensorflow/lite/micro/kernels/mul.cc new file mode 100644 index 00000000..f59db1c2 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/mul.cc @@ -0,0 +1,221 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/mul.h" + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/integer_ops/mul.h" +#include "tensorflow/lite/kernels/internal/reference/process_broadcast_shapes.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/memory_helpers.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace mul { +namespace { + +constexpr int kInput1Tensor = 0; +constexpr int kInput2Tensor = 1; +constexpr int kOutputTensor = 0; + +struct OpData { + int32_t input1_zero_point; + int32_t input2_zero_point; + + int32_t output_activation_min; + int32_t output_activation_max; + int32_t output_zero_point; + int32_t output_multiplier; + int output_shift; + + float output_activation_min_f32; + float output_activation_max_f32; +}; + +TfLiteStatus CalculateOpData(TfLiteContext *context, TfLiteNode *node, + TfLiteMulParams *params, OpData *data) +{ + const TfLiteTensor *input1 = GetInput(context, node, kInput1Tensor); + TF_LITE_ENSURE(context, input1 != nullptr); + const TfLiteTensor *input2 = GetInput(context, node, kInput2Tensor); + TF_LITE_ENSURE(context, input2 != nullptr); + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + + TF_LITE_ENSURE_EQ(context, NumInputs(node), 2); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + + TF_LITE_ENSURE_TYPES_EQ(context, input1->type, input2->type); + + if (output->type == kTfLiteInt8) { + TF_LITE_ENSURE_STATUS(CalculateActivationRangeQuantized( + context, params->activation, output, &data->output_activation_min, + &data->output_activation_max)); + + double real_multiplier = static_cast(input1->params.scale) * + static_cast(input2->params.scale) / + static_cast(output->params.scale); + QuantizeMultiplier(real_multiplier, &data->output_multiplier, + &data->output_shift); + + data->input1_zero_point = input1->params.zero_point; + data->input2_zero_point = input2->params.zero_point; + data->output_zero_point = output->params.zero_point; + } else { + CalculateActivationRange(params->activation, + &data->output_activation_min_f32, + &data->output_activation_max_f32); + } + + return kTfLiteOk; +} + +} // namespace + +void EvalQuantized(TfLiteContext *context, TfLiteNode *node, const OpData *data, + const TfLiteEvalTensor *input1, + const TfLiteEvalTensor *input2, TfLiteEvalTensor *output) +{ + tflite::ArithmeticParams op_params = {}; + op_params.quantized_activation_min = data->output_activation_min; + op_params.quantized_activation_max = data->output_activation_max; + op_params.float_activation_max = data->output_activation_max_f32; + op_params.input1_offset = -data->input1_zero_point; + op_params.input2_offset = -data->input2_zero_point; + op_params.output_offset = data->output_zero_point; + op_params.output_multiplier = data->output_multiplier; + op_params.output_shift = data->output_shift; + + bool need_broadcast = reference_ops::ProcessBroadcastShapes( + tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorShape(input2), &op_params); + + if (need_broadcast) { + reference_integer_ops::BroadcastMul4DSlow( + op_params, tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorData(input1), + tflite::micro::GetTensorShape(input2), + tflite::micro::GetTensorData(input2), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } else { + reference_integer_ops::Mul(op_params, tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorData(input1), + tflite::micro::GetTensorShape(input2), + tflite::micro::GetTensorData(input2), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } +} + +void EvalFloat(TfLiteContext *context, TfLiteNode *node, + TfLiteMulParams *params, const OpData *data, + const TfLiteEvalTensor *input1, const TfLiteEvalTensor *input2, + TfLiteEvalTensor *output) +{ + tflite::ArithmeticParams op_params = {}; + op_params.float_activation_min = data->output_activation_min_f32; + op_params.float_activation_max = data->output_activation_max_f32; + + bool need_broadcast = reference_ops::ProcessBroadcastShapes( + tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorShape(input2), &op_params); + + if (need_broadcast) { + reference_ops::BroadcastMul4DSlow( + op_params, tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorData(input1), + tflite::micro::GetTensorShape(input2), + tflite::micro::GetTensorData(input2), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } else { + reference_ops::Mul(op_params, tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorData(input1), + tflite::micro::GetTensorShape(input2), + tflite::micro::GetTensorData(input2), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } +} + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(OpData)); +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->builtin_data != nullptr); + auto *params = reinterpret_cast(node->builtin_data); + + TFLITE_DCHECK(node->user_data != nullptr); + OpData *data = static_cast(node->user_data); + + return CalculateOpData(context, node, params, data); +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->builtin_data != nullptr); + auto *params = reinterpret_cast(node->builtin_data); + + TFLITE_DCHECK(node->user_data != nullptr); + const OpData *data = static_cast(node->user_data); + + const TfLiteEvalTensor *input1 = + tflite::micro::GetEvalInput(context, node, kInput1Tensor); + const TfLiteEvalTensor *input2 = + tflite::micro::GetEvalInput(context, node, kInput2Tensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + switch (input1->type) { + case kTfLiteInt8: + EvalQuantized(context, node, data, input1, input2, output); + break; + case kTfLiteFloat32: + EvalFloat(context, node, params, data, input1, input2, output); + break; + default: + TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.", + TfLiteTypeGetName(input1->type), input1->type); + return kTfLiteError; + } + + return kTfLiteOk; +} +} // namespace mul + +TfLiteRegistration Register_MUL() +{ + return { /*init=*/mul::Init, + /*free=*/nullptr, + /*prepare=*/mul::Prepare, + /*invoke=*/mul::Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/mul_test.cc b/components/tflite/tensorflow/lite/micro/kernels/mul_test.cc new file mode 100644 index 00000000..29213b63 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/mul_test.cc @@ -0,0 +1,212 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +const int flat_size_simple = 4; +const float scale_simple = 0.01; +int dims_simple[] = { 4, 1, 2, 2, 1 }; +const float input1_simple[] = { -0.8, 0.2, 0.9, 0.7 }; +const float input2_simple[] = { 0.6, 0.4, 0.9, 0.8 }; +const float golden_simple[] = { -0.48, 0.08, 0.81, 0.56 }; +const float golden_simple_relu[] = { 0.0, 0.08, 0.81, 0.56 }; + +const int flat_size_broadcast = 6; +const float input_scale_broadcast = 0.05f; +const float output_scale_broadcast = 0.01f; +int dims_broadcast[] = { 4, 1, 3, 1, 2 }; +int dims_scalar_broadcast[] = { 1, 1 }; +const float input1_broadcast[] = { -2.0, 0.2, 0.7, 0.8, 1.1, 2.0 }; +const float input2_broadcast[] = { 0.1 }; +const float golden_broadcast[] = { -0.2, 0.02, 0.07, 0.08, 0.11, 0.2 }; +const float golden_broadcast_relu[] = { 0, 0.02, 0.07, 0.08, 0.11, 0.2 }; + +template +void ValidateMulGoldens(TfLiteTensor *tensors, int tensors_size, + TfLiteFusedActivation activation, const T *golden, + int output_len, float tolerance, T *output) +{ + TfLiteMulParams builtin_data = { + .activation = activation, + }; + + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = tflite::ops::micro::Register_MUL(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + reinterpret_cast(&builtin_data)); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_len; i++) { + TF_LITE_MICRO_EXPECT_NEAR(golden[i], output[i], tolerance); + } +} + +void TestMulFloat(int *input1_dims_data, const float *input1_data, + int *input2_dims_data, const float *input2_data, + int *output_dims_data, const float *golden, + float *output_data, TfLiteFusedActivation activation) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input1_data, input1_dims), + CreateTensor(input2_data, input2_dims), + CreateTensor(output_data, output_dims), + }; + + ValidateMulGoldens(tensors, tensors_size, activation, golden, + output_dims_count, 1e-5, output_data); +} + +template +void TestMulQuantized(int *input1_dims_data, const float *input1_data, + T *input1_quantized, int *input2_dims_data, + const float *input2_data, T *input2_quantized, + const float input_scale, const int input_zero_point, + int *output_dims_data, const float *golden, + T *golden_quantized, const float output_scale, + const int output_zero_point, T *output_data, + TfLiteFusedActivation activation) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(input1_data, input1_quantized, input1_dims, + input_scale, input_zero_point), + CreateQuantizedTensor(input2_data, input2_quantized, input2_dims, + input_scale, input_zero_point), + CreateQuantizedTensor(output_data, output_dims, output_scale, + output_zero_point) + }; + + Quantize(golden, golden_quantized, output_dims_count, output_scale, + output_zero_point); + + ValidateMulGoldens(tensors, tensors_size, activation, golden_quantized, + output_dims_count, 1.0f, output_data); +} + +} // namespace + +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(SimpleFloatNoAcativationShouldMatchGolden) +{ + float output_data[tflite::testing::flat_size_simple]; + + tflite::testing::TestMulFloat( + tflite::testing::dims_simple, tflite::testing::input1_simple, + tflite::testing::dims_simple, tflite::testing::input2_simple, + tflite::testing::dims_simple, tflite::testing::golden_simple, output_data, + kTfLiteActNone); +} + +TF_LITE_MICRO_TEST(SimpleFloatReluShouldMatchGolden) +{ + float output_data[tflite::testing::flat_size_simple]; + + tflite::testing::TestMulFloat( + tflite::testing::dims_simple, tflite::testing::input1_simple, + tflite::testing::dims_simple, tflite::testing::input2_simple, + tflite::testing::dims_simple, tflite::testing::golden_simple_relu, + output_data, kTfLiteActRelu); +} + +TF_LITE_MICRO_TEST(SimpleInt8NoAcativationShouldMatchGolden) +{ + int8_t input1_quantized[tflite::testing::flat_size_simple]; + int8_t input2_quantized[tflite::testing::flat_size_simple]; + int8_t golden_quantized[tflite::testing::flat_size_simple]; + int8_t output_data[tflite::testing::flat_size_simple]; + + tflite::testing::TestMulQuantized( + tflite::testing::dims_simple, tflite::testing::input1_simple, + input1_quantized, tflite::testing::dims_simple, + tflite::testing::input2_simple, input2_quantized, + tflite::testing::scale_simple, 0, tflite::testing::dims_simple, + tflite::testing::golden_simple, golden_quantized, + tflite::testing::scale_simple, 0, output_data, kTfLiteActNone); +} + +TF_LITE_MICRO_TEST(BroadcastFloatNoActivationShouldMatchGolden) +{ + float output_data[tflite::testing::flat_size_broadcast]; + + tflite::testing::TestMulFloat( + tflite::testing::dims_broadcast, tflite::testing::input1_broadcast, + tflite::testing::dims_scalar_broadcast, tflite::testing::input2_broadcast, + tflite::testing::dims_broadcast, tflite::testing::golden_broadcast, + output_data, kTfLiteActNone); +} + +TF_LITE_MICRO_TEST(BroadcastFloatReluShouldMatchGolden) +{ + float output_data[tflite::testing::flat_size_broadcast]; + + tflite::testing::TestMulFloat( + tflite::testing::dims_broadcast, tflite::testing::input1_broadcast, + tflite::testing::dims_scalar_broadcast, tflite::testing::input2_broadcast, + tflite::testing::dims_broadcast, tflite::testing::golden_broadcast_relu, + output_data, kTfLiteActRelu); +} + +TF_LITE_MICRO_TEST(BroadcastInt8NoAcativationShouldMatchGolden) +{ + int8_t input1_quantized[tflite::testing::flat_size_broadcast]; + int8_t input2_quantized[tflite::testing::flat_size_broadcast]; + int8_t golden_quantized[tflite::testing::flat_size_broadcast]; + int8_t output_data[tflite::testing::flat_size_broadcast]; + + tflite::testing::TestMulQuantized( + tflite::testing::dims_broadcast, tflite::testing::input1_broadcast, + input1_quantized, tflite::testing::dims_scalar_broadcast, + tflite::testing::input2_broadcast, input2_quantized, + tflite::testing::input_scale_broadcast, 0, + tflite::testing::dims_broadcast, tflite::testing::golden_broadcast, + golden_quantized, tflite::testing::output_scale_broadcast, 0, output_data, + kTfLiteActNone); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/neg.cc b/components/tflite/tensorflow/lite/micro/kernels/neg.cc new file mode 100644 index 00000000..5d846a14 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/neg.cc @@ -0,0 +1,68 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/neg.h" + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace neg { + +constexpr int kInputTensor = 0; +constexpr int kOutputTensor = 0; + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + switch (input->type) { + // TODO(wangtz): handle for kTfLiteInt8 + case kTfLiteFloat32: + reference_ops::Negate(tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + break; + default: + TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.", + TfLiteTypeGetName(input->type), input->type); + return kTfLiteError; + } + return kTfLiteOk; +} + +} // namespace neg + +TfLiteRegistration Register_NEG() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/nullptr, + /*invoke=*/neg::Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/neg_test.cc b/components/tflite/tensorflow/lite/micro/kernels/neg_test.cc new file mode 100644 index 00000000..09f77a94 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/neg_test.cc @@ -0,0 +1,87 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +void TestNegFloat(int *input_dims_data, const float *input_data, + const float *expected_output_data, int *output_dims_data, + float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims), + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = tflite::ops::micro::Register_NEG(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + TF_LITE_MICRO_EXPECT_EQ(expected_output_data[0], output_data[0]); + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output_data[i], output_data[i]); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(NegOpSingleFloat) +{ + int dims[] = { 1, 2 }; + const float input_data[] = { 8.5, 0.0 }; + const float golden[] = { -8.5, 0.0 }; + float output_data[2]; + + tflite::testing::TestNegFloat(dims, input_data, golden, dims, output_data); +} + +TF_LITE_MICRO_TEST(NegOpFloat) +{ + int dims[] = { 2, 2, 3 }; + const float input_data[] = { -2.0f, -1.0f, 0.f, 1.0f, 2.0f, 3.0f }; + const float golden[] = { 2.0f, 1.0f, -0.f, -1.0f, -2.0f, -3.0f }; + float output_data[6]; + + tflite::testing::TestNegFloat(dims, input_data, golden, dims, output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/pack.cc b/components/tflite/tensorflow/lite/micro/kernels/pack.cc new file mode 100644 index 00000000..543f4631 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/pack.cc @@ -0,0 +1,131 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace pack { +namespace { + +constexpr int kOutputTensor = 0; + +template +TfLiteStatus PackImpl(TfLiteContext *context, TfLiteNode *node, + TfLiteEvalTensor *output, int values_count, int axis) +{ + const TfLiteEvalTensor *input0 = + tflite::micro::GetEvalInput(context, node, 0); + + const int dimensions = output->dims->size; + const TfLiteIntArray *input_dims = input0->dims; + const TfLiteIntArray *output_dims = output->dims; + + if (axis < 0) { + axis += dimensions; + } + + int outer_size = 1; + for (int i = 0; i < axis; ++i) { + outer_size *= output_dims->data[i]; + } + int copy_size = 1; + for (int i = axis + 1; i < dimensions; ++i) { + copy_size *= output_dims->data[i]; + } + int input_size = 1; + for (int i = 0; i < input_dims->size; ++i) { + input_size *= input_dims->data[i]; + } + TFLITE_DCHECK_EQ(input_size, copy_size * outer_size); + + T *output_data = tflite::micro::GetTensorData(output); + + for (int i = 0; i < values_count; ++i) { + const TfLiteEvalTensor *t = tflite::micro::GetEvalInput(context, node, i); + const T *input_data = tflite::micro::GetTensorData(t); + for (int k = 0; k < outer_size; ++k) { + const T *input_ptr = input_data + copy_size * k; + int loc = k * values_count * copy_size + i * copy_size; + T *output_ptr = output_data + loc; + for (int j = 0; j < copy_size; ++j) + output_ptr[j] = input_ptr[j]; + } + } + + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLitePackParams *data = + reinterpret_cast(node->builtin_data); + + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + switch (output->type) { + case kTfLiteFloat32: { + return PackImpl(context, node, output, data->values_count, + data->axis); + } + case kTfLiteUInt8: { + return PackImpl(context, node, output, data->values_count, + data->axis); + } + case kTfLiteInt8: { + return PackImpl(context, node, output, data->values_count, + data->axis); + } + case kTfLiteInt32: { + return PackImpl(context, node, output, data->values_count, + data->axis); + } + case kTfLiteInt64: { + return PackImpl(context, node, output, data->values_count, + data->axis); + } + default: { + TF_LITE_KERNEL_LOG(context, "Type '%s' is not supported by pack.", + TfLiteTypeGetName(output->type)); + return kTfLiteError; + } + } + + return kTfLiteOk; +} + +} // namespace +} // namespace pack + +TfLiteRegistration Register_PACK() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/nullptr, + /*invoke=*/pack::Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/pack_test.cc b/components/tflite/tensorflow/lite/micro/kernels/pack_test.cc new file mode 100644 index 00000000..42541570 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/pack_test.cc @@ -0,0 +1,287 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/debug_log.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { + +template +void ValidatePackGoldens(TfLiteTensor *tensors, int tensors_size, + TfLitePackParams params, TfLiteIntArray *inputs_array, + TfLiteIntArray *outputs_array, const T *golden, + int output_len, float tolerance, T *output) +{ + // Place a unique value in the uninitialized output buffer. + for (int i = 0; i < output_len; ++i) { + output[i] = 23; + } + + const TfLiteRegistration registration = tflite::ops::micro::Register_PACK(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, reinterpret_cast(¶ms)); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_len; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(golden[i], output[i], tolerance); + } +} + +void TestPackTwoInputsFloat(int *input1_dims_data, const float *input1_data, + int *input2_dims_data, const float *input2_data, + int axis, int *output_dims_data, + const float *expected_output_data, + float *output_data) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int input_size = 2; + constexpr int output_size = 1; + constexpr int tensors_size = input_size + output_size; + TfLiteTensor tensors[tensors_size] = { CreateTensor(input1_data, input1_dims), + CreateTensor(input2_data, input2_dims), + CreateTensor(output_data, output_dims) }; + + TfLitePackParams builtin_data = { + .values_count = 2, + .axis = axis, + }; + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + ValidatePackGoldens(tensors, tensors_size, builtin_data, inputs_array, + outputs_array, expected_output_data, output_dims_count, + 1e-5f, output_data); +} + +void TestPackThreeInputsFloat(int *input1_dims_data, const float *input1_data, + int *input2_dims_data, const float *input2_data, + int *input3_dims_data, const float *input3_data, + int axis, int *output_dims_data, + const float *expected_output_data, + float *output_data) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *input3_dims = IntArrayFromInts(input3_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int input_size = 3; + constexpr int output_size = 1; + constexpr int tensors_size = input_size + output_size; + TfLiteTensor tensors[tensors_size] = { CreateTensor(input1_data, input1_dims), + CreateTensor(input2_data, input2_dims), + CreateTensor(input3_data, input3_dims), + CreateTensor(output_data, output_dims) }; + + TfLitePackParams builtin_data = { + .values_count = 3, + .axis = axis, + }; + int inputs_array_data[] = { 3, 0, 1, 2 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 3 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + ValidatePackGoldens(tensors, tensors_size, builtin_data, inputs_array, + outputs_array, expected_output_data, output_dims_count, + 1e-5f, output_data); +} + +void TestPackTwoInputsQuantized( + int *input1_dims_data, const uint8_t *input1_data, int *input2_dims_data, + const uint8_t *input2_data, int axis, int *output_dims_data, + const uint8_t *expected_output_data, uint8_t *output_data) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int input_size = 2; + constexpr int output_size = 1; + constexpr int tensors_size = input_size + output_size; + TfLiteTensor tensors[tensors_size] = { + // CreateQuantizedTensor needs scale/zero_point values as input, but these + // values don't matter as to the functionality of PACK, so just set as 1.0 + // and 128. + CreateQuantizedTensor(input1_data, input1_dims, 1.0, 128), + CreateQuantizedTensor(input2_data, input2_dims, 1.0, 128), + CreateQuantizedTensor(output_data, output_dims, 1.0, 128) + }; + + TfLitePackParams builtin_data = { + .values_count = 2, + .axis = axis, + }; + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + ValidatePackGoldens(tensors, tensors_size, builtin_data, inputs_array, + outputs_array, expected_output_data, output_dims_count, + 1e-5f, output_data); +} + +void TestPackTwoInputsQuantized32( + int *input1_dims_data, const int32_t *input1_data, int *input2_dims_data, + const int32_t *input2_data, int axis, int *output_dims_data, + const int32_t *expected_output_data, int32_t *output_data) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int input_size = 2; + constexpr int output_size = 1; + constexpr int tensors_size = input_size + output_size; + TfLiteTensor tensors[tensors_size] = { CreateTensor(input1_data, input1_dims), + CreateTensor(input2_data, input2_dims), + CreateTensor(output_data, output_dims) }; + + TfLitePackParams builtin_data = { + .values_count = 2, + .axis = axis, + }; + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + ValidatePackGoldens(tensors, tensors_size, builtin_data, inputs_array, + outputs_array, expected_output_data, output_dims_count, + 1e-5f, output_data); +} + +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(PackFloatThreeInputs) +{ + int input_shape[] = { 1, 2 }; + int output_shape[] = { 2, 3, 2 }; + const float input1_values[] = { 1, 4 }; + const float input2_values[] = { 2, 5 }; + const float input3_values[] = { 3, 6 }; + const float golden[] = { 1, 4, 2, 5, 3, 6 }; + const int axis = 0; + constexpr int output_dims_count = 6; + float output_data[output_dims_count]; + + tflite::testing::TestPackThreeInputsFloat( + input_shape, input1_values, input_shape, input2_values, input_shape, + input3_values, axis, output_shape, golden, output_data); +} + +TF_LITE_MICRO_TEST(PackFloatThreeInputsDifferentAxis) +{ + int input_shape[] = { 1, 2 }; + int output_shape[] = { 2, 2, 3 }; + const float input1_values[] = { 1, 4 }; + const float input2_values[] = { 2, 5 }; + const float input3_values[] = { 3, 6 }; + const float golden[] = { 1, 2, 3, 4, 5, 6 }; + const int axis = 1; + constexpr int output_dims_count = 6; + float output_data[output_dims_count]; + + tflite::testing::TestPackThreeInputsFloat( + input_shape, input1_values, input_shape, input2_values, input_shape, + input3_values, axis, output_shape, golden, output_data); +} + +TF_LITE_MICRO_TEST(PackFloatThreeInputsNegativeAxis) +{ + int input_shape[] = { 1, 2 }; + int output_shape[] = { 2, 2, 3 }; + const float input1_values[] = { 1, 4 }; + const float input2_values[] = { 2, 5 }; + const float input3_values[] = { 3, 6 }; + const float golden[] = { 1, 2, 3, 4, 5, 6 }; + const int axis = -1; + constexpr int output_dims_count = 6; + float output_data[output_dims_count]; + + tflite::testing::TestPackThreeInputsFloat( + input_shape, input1_values, input_shape, input2_values, input_shape, + input3_values, axis, output_shape, golden, output_data); +} + +TF_LITE_MICRO_TEST(PackFloatMultilDimensions) +{ + int input_shape[] = { 2, 2, 3 }; + int output_shape[] = { 3, 2, 2, 3 }; + const float input1_values[] = { 1, 2, 3, 4, 5, 6 }; + const float input2_values[] = { 7, 8, 9, 10, 11, 12 }; + const float golden[] = { 1, 2, 3, 7, 8, 9, 4, 5, 6, 10, 11, 12 }; + const int axis = 1; + constexpr int output_dims_count = 12; + float output_data[output_dims_count]; + + tflite::testing::TestPackTwoInputsFloat(input_shape, input1_values, + input_shape, input2_values, axis, + output_shape, golden, output_data); +} + +TF_LITE_MICRO_TEST(PackQuantizedMultilDimensions) +{ + int input_shape[] = { 2, 2, 3 }; + int output_shape[] = { 3, 2, 2, 3 }; + const uint8_t input1_values[] = { 1, 2, 3, 4, 5, 6 }; + const uint8_t input2_values[] = { 7, 8, 9, 10, 11, 12 }; + const uint8_t golden[] = { 1, 2, 3, 7, 8, 9, 4, 5, 6, 10, 11, 12 }; + const int axis = 1; + constexpr int output_dims_count = 12; + uint8_t output_data[output_dims_count]; + + tflite::testing::TestPackTwoInputsQuantized( + input_shape, input1_values, input_shape, input2_values, axis, + output_shape, golden, output_data); +} + +TF_LITE_MICRO_TEST(PackQuantized32MultilDimensions) +{ + int input_shape[] = { 2, 2, 3 }; + int output_shape[] = { 3, 2, 2, 3 }; + const int32_t input1_values[] = { 1, 2, 3, 4, 5, 6 }; + const int32_t input2_values[] = { 7, 8, 9, 10, 11, 12 }; + const int32_t golden[] = { 1, 2, 3, 7, 8, 9, 4, 5, 6, 10, 11, 12 }; + const int axis = 1; + constexpr int output_dims_count = 12; + int32_t output_data[output_dims_count]; + + tflite::testing::TestPackTwoInputsQuantized32( + input_shape, input1_values, input_shape, input2_values, axis, + output_shape, golden, output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/pad.cc b/components/tflite/tensorflow/lite/micro/kernels/pad.cc new file mode 100644 index 00000000..34a12ea1 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/pad.cc @@ -0,0 +1,253 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/kernels/internal/reference/pad.h" + +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/portable_tensor.h" +#include "tensorflow/lite/kernels/internal/types.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace pad { +namespace { + +struct OpData { + PadParams params; + int32_t output_zero_point; +}; + +} // namespace + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(OpData)); +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + OpData *data = static_cast(node->user_data); + + TF_LITE_ENSURE(context, NumInputs(node) == 2 || NumInputs(node) == 3); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + + const TfLiteTensor *input = GetInput(context, node, /*index=*/0); + TF_LITE_ENSURE(context, input != nullptr); + const TfLiteTensor *paddings = GetInput(context, node, /*index=*/1); + TF_LITE_ENSURE(context, paddings != nullptr); + const TfLiteTensor *constant_values = + NumInputs(node) == 3 ? GetInput(context, node, /*index=*/2) : nullptr; + TfLiteTensor *output = GetOutput(context, node, /*index=*/0); + TF_LITE_ENSURE(context, output != nullptr); + + TF_LITE_ENSURE_EQ(context, input->type, output->type); + + // Current implementations rely on the inputs being <= 4D. + TF_LITE_ENSURE(context, NumDimensions(input) <= + reference_ops::PadKernelMaxDimensionCount()); + + if (constant_values != nullptr) { + TF_LITE_ENSURE_EQ(context, input->type, constant_values->type); + // Ensure that constant_values is a scalar. + TF_LITE_ENSURE_EQ(context, NumElements(constant_values), 1); + } + + // There must be a pair of paddings for each output dimension. + TF_LITE_ENSURE_EQ(context, GetTensorShape(paddings).FlatSize(), + output->dims->size * 2); + + // On Micro, outputs must be properly sized by the converter. + // NOTE: This data is only available because the paddings buffer is stored in + // the flatbuffer: + TF_LITE_ENSURE(context, IsConstantTensor(paddings)); + const int32_t *paddings_data = GetTensorData(paddings); + for (int i = 0; i < output->dims->size; i++) { + int output_dim = output->dims->data[i]; + int expected_dim = + input->dims->data[i] + paddings_data[i * 2] + paddings_data[i * 2 + 1]; + TF_LITE_ENSURE_EQ(context, output_dim, expected_dim); + } + + // Calculate OpData: + data->params.resizing_category = ResizingCategory::kGenericResize; + const int paddings_total = GetTensorShape(paddings).FlatSize(); + if (paddings_total == 8 && (paddings_data[0] == 0 && paddings_data[1] == 0) && + (paddings_data[6] == 0 && paddings_data[7] == 0)) { + data->params.resizing_category = ResizingCategory::kImageStyle; + } + + const int num_input_dimensions = NumDimensions(input); + data->params.left_padding_count = num_input_dimensions; + data->params.right_padding_count = num_input_dimensions; + + for (int idx = num_input_dimensions - 1; idx >= 0; --idx) { + data->params.left_padding[idx] = paddings_data[idx * 2]; + data->params.right_padding[idx] = paddings_data[idx * 2 + 1]; + } + + if (input->type == kTfLiteInt8 || input->type == kTfLiteUInt8) { + if (constant_values == nullptr) { + // Quantized Pad requires that 0 is represented in the quantized + // range. + if (input->type == kTfLiteUInt8) { + TF_LITE_ENSURE(context, output->params.zero_point >= + std::numeric_limits::min()); + TF_LITE_ENSURE(context, output->params.zero_point <= + std::numeric_limits::max()); + } else { + TF_LITE_ENSURE(context, output->params.zero_point >= + std::numeric_limits::min()); + TF_LITE_ENSURE(context, output->params.zero_point <= + std::numeric_limits::max()); + } + } else { + // Quantized Pad requires that 'constant_values' is represented in the + // same quantized range as the input and output tensors. + TF_LITE_ENSURE_EQ(context, output->params.zero_point, + constant_values->params.zero_point); + TF_LITE_ENSURE_EQ(context, static_cast(output->params.scale), + static_cast(constant_values->params.scale)); + } + data->output_zero_point = output->params.zero_point; + } + + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + const OpData *data = static_cast(node->user_data); + + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, /*index=*/0); + const TfLiteEvalTensor *constant_values = + NumInputs(node) == 3 ? tflite::micro::GetEvalInput(context, node, /*index=*/2) : nullptr; + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, /*index=*/0); + + switch (input->type) { + case kTfLiteFloat32: { + float pad_value = + constant_values == nullptr ? 0.f : *tflite::micro::GetTensorData(constant_values); + if (data->params.resizing_category == ResizingCategory::kImageStyle) { + reference_ops::PadImageStyle( + data->params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), &pad_value, + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } else { + reference_ops::Pad(data->params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + &pad_value, tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } + } break; + case kTfLiteUInt8: { + uint8_t pad_value; + if (constant_values == nullptr) { + pad_value = static_cast(data->output_zero_point); + } else { + pad_value = *tflite::micro::GetTensorData(constant_values); + } + if (data->params.resizing_category == ResizingCategory::kImageStyle) { + reference_ops::PadImageStyle( + data->params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), &pad_value, + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } else { + reference_ops::Pad(data->params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + &pad_value, tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } + } break; + case kTfLiteInt8: { + int8_t pad_value; + if (constant_values == nullptr) { + pad_value = static_cast(data->output_zero_point); + } else { + pad_value = *tflite::micro::GetTensorData(constant_values); + } + if (data->params.resizing_category == ResizingCategory::kImageStyle) { + reference_ops::PadImageStyle( + data->params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), &pad_value, + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } else { + reference_ops::Pad(data->params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + &pad_value, tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } + } break; + case kTfLiteInt32: { + int32_t pad_value = + constant_values == nullptr ? 0 : *tflite::micro::GetTensorData(constant_values); + reference_ops::Pad(data->params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + &pad_value, tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } break; + default: + + TF_LITE_KERNEL_LOG(context, "Type %s not currently supported by Pad.", + TfLiteTypeGetName(input->type)); + return kTfLiteError; + } +#undef TF_LITE_PAD + return kTfLiteOk; +} + +} // namespace pad + +TfLiteRegistration Register_PAD() +{ + return { /*init=*/pad::Init, + /*free=*/nullptr, + /*prepare=*/pad::Prepare, + /*invoke=*/pad::Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +// Also register Pad as PadV2. +TfLiteRegistration Register_PADV2() +{ + return { /*init=*/pad::Init, + /*free=*/nullptr, + /*prepare=*/pad::Prepare, + /*invoke=*/pad::Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/pad_test.cc b/components/tflite/tensorflow/lite/micro/kernels/pad_test.cc new file mode 100644 index 00000000..3d5afd79 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/pad_test.cc @@ -0,0 +1,437 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +template +TfLiteStatus ValidatePadGoldens(TfLiteTensor *tensors, int tensors_size, + const T *golden, T *output_data, + int output_length) +{ + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = tflite::ops::micro::Register_PAD(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + // Prepare should catch dimension mismatches. + TfLiteStatus prepare_status = runner.InitAndPrepare(); + if (prepare_status != kTfLiteOk) { + return prepare_status; + } + + // Eval should catch quantization mismatches. + TfLiteStatus invoke_status = runner.Invoke(); + if (invoke_status != kTfLiteOk) { + return invoke_status; + } + + for (int i = 0; i < output_length; ++i) { + TF_LITE_MICRO_EXPECT_EQ(golden[i], output_data[i]); + } + return kTfLiteOk; +} + +template +TfLiteStatus ValidatePadV2Goldens(TfLiteTensor *tensors, int tensors_size, + const T *golden, T *output_data, + int output_length) +{ + int inputs_array_data[] = { 3, 0, 1, 2 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 3 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = tflite::ops::micro::Register_PADV2(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + // Prepare should catch dimension mismatches. + TfLiteStatus prepare_status = runner.InitAndPrepare(); + if (prepare_status != kTfLiteOk) { + return prepare_status; + } + + // Eval should catch quantization mismatches. + TfLiteStatus invoke_status = runner.Invoke(); + if (invoke_status != kTfLiteOk) { + return invoke_status; + } + + for (int i = 0; i < output_length; ++i) { + TF_LITE_MICRO_EXPECT_EQ(golden[i], output_data[i]); + } + return kTfLiteOk; +} + +// output data and golden must be shaped correctly +void TestPadFloat(int *input_dims_data, const float *input_data, + int *pad_dims_data, const int32_t *pad_data, + int *output_dims_data, const float *golden, + float *output_data, + TfLiteStatus expected_status = kTfLiteOk) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *pad_dims = IntArrayFromInts(pad_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { CreateTensor(input_data, input_dims), + CreateTensor(pad_data, pad_dims), + CreateTensor(output_data, output_dims) }; + + // Pad tensor must be constant. + tensors[1].allocation_type = kTfLiteMmapRo; + + TF_LITE_MICRO_EXPECT_EQ(expected_status, + ValidatePadGoldens(tensors, tensors_size, golden, + output_data, output_dims_count)); +} + +// output data and golden must be shaped correctly +void TestPadV2Float(int *input_dims_data, const float *input_data, + int *pad_dims_data, const int32_t *pad_data, + const float pad_value, int *output_dims_data, + const float *golden, float *output_data, + TfLiteStatus expected_status = kTfLiteOk) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *pad_dims = IntArrayFromInts(pad_dims_data); + int pad_value_dims_data[] = { 1, 1 }; // Only one padding value allowed. + TfLiteIntArray *pad_value_dims = IntArrayFromInts(pad_value_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + constexpr int inputs_size = 3; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), CreateTensor(pad_data, pad_dims), + CreateTensor(&pad_value, pad_value_dims), + CreateTensor(output_data, output_dims) + }; + + // Pad tensor must be constant. + tensors[1].allocation_type = kTfLiteMmapRo; + + TF_LITE_MICRO_EXPECT_EQ(expected_status, + ValidatePadV2Goldens(tensors, tensors_size, golden, + output_data, output_dims_count)); +} + +template +void TestPadQuantized(int *input_dims_data, const float *input_data, + T *input_quantized, float input_scale, + int input_zero_point, int *pad_dims_data, + const int32_t *pad_data, int *output_dims_data, + const float *golden, T *golden_quantized, + float output_scale, int output_zero_point, T *output_data, + TfLiteStatus expected_status = kTfLiteOk) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *pad_dims = IntArrayFromInts(pad_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(input_data, input_quantized, input_dims, + input_scale, input_zero_point), + CreateTensor(pad_data, pad_dims), + CreateQuantizedTensor(output_data, output_dims, output_scale, + output_zero_point) + }; + + // Pad tensor must be constant. + tensors[1].allocation_type = kTfLiteMmapRo; + + tflite::Quantize(golden, golden_quantized, output_dims_count, output_scale, + output_zero_point); + TF_LITE_MICRO_EXPECT_EQ( + expected_status, + ValidatePadGoldens(tensors, tensors_size, golden_quantized, output_data, + output_dims_count)); +} + +template +void TestPadV2Quantized( + int *input_dims_data, const float *input_data, T *input_quantized, + float input_scale, int input_zero_point, int *pad_dims_data, + const int32_t *pad_data, const float pad_value, const float pad_value_scale, + const int pad_value_zero_point, int *output_dims_data, const float *golden, + T *golden_quantized, float output_scale, int output_zero_point, + T *output_data, TfLiteStatus expected_status = kTfLiteOk) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *pad_dims = IntArrayFromInts(pad_dims_data); + int pad_value_dims_data[] = { 1, 1 }; // Only one padding value allowed. + TfLiteIntArray *pad_value_dims = IntArrayFromInts(pad_value_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + T pad_value_quantized; + const int output_dims_count = ElementCount(*output_dims); + constexpr int inputs_size = 3; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(input_data, input_quantized, input_dims, + input_scale, input_zero_point), + CreateTensor(pad_data, pad_dims), + CreateQuantizedTensor(&pad_value, &pad_value_quantized, pad_value_dims, + pad_value_scale, pad_value_zero_point), + CreateQuantizedTensor(output_data, output_dims, output_scale, + output_zero_point) + }; + + // Pad tensor must be constant. + tensors[1].allocation_type = kTfLiteMmapRo; + tensors[2].params.scale = pad_value_scale; + tensors[3].params.scale = output_scale; + + tflite::Quantize(golden, golden_quantized, output_dims_count, output_scale, + output_zero_point); + TF_LITE_MICRO_EXPECT_EQ( + expected_status, + ValidatePadV2Goldens(tensors, tensors_size, golden_quantized, output_data, + output_dims_count)); +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(Test2DFloat) +{ + int input_dims[] = { 4, 1, 2, 2, 1 }; + const float input_values[] = { 1, 2, 3, 4 }; + int pad_dims[] = { 2, 4, 2 }; + const int32_t pad_values[] = { 1, 1, 0, 0, 1, 1, 0, 0 }; + int output_dims[] = { 4, 3, 2, 4, 1 }; + const float golden[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, + 0, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + float output_data[24]; + + tflite::testing::TestPadFloat(input_dims, input_values, pad_dims, pad_values, + output_dims, golden, output_data); +} + +TF_LITE_MICRO_TEST(Test4DFloat) +{ + int input_dims[] = { 4, 1, 1, 1, 1 }; + const float input_values[] = { 42 }; + int pad_dims[] = { 2, 4, 2 }; + const int32_t pad_values[] = { 1, 1, 1, 1, 1, 1, 1, 1 }; + int output_dims[] = { 4, 3, 3, 3, 3 }; + const int kOutputLen = 81; // 3 * 3 * 3 * 3 + float golden[kOutputLen]; + for (int i = 0; i < kOutputLen; i++) { + golden[i] = 0; + } + golden[40] = 42; + float output_data[kOutputLen]; + + tflite::testing::TestPadFloat(input_dims, input_values, pad_dims, pad_values, + output_dims, const_cast(golden), + output_data); +} + +TF_LITE_MICRO_TEST(Test2DFloatV2) +{ + int input_dims[] = { 4, 1, 2, 2, 1 }; + const float input_values[] = { 1, 2, 3, 4 }; + int pad_dims[] = { 2, 4, 2 }; + const int32_t pad_values[] = { 1, 1, 0, 0, 1, 1, 0, 0 }; + const float pad_value = 42; + int output_dims[] = { 4, 3, 2, 4, 1 }; + const float golden[] = { 42, 42, 42, 42, 42, 42, 42, 42, 42, 1, 2, 42, + 42, 3, 4, 42, 42, 42, 42, 42, 42, 42, 42, 42 }; + float output_data[24]; + + tflite::testing::TestPadV2Float(input_dims, input_values, pad_dims, + pad_values, pad_value, output_dims, golden, + output_data); +} + +TF_LITE_MICRO_TEST(Test2DUInt8) +{ + int input_dims[] = { 4, 1, 2, 2, 1 }; + const float input_values[] = { 1, 2, 3, 4 }; + const float input_scale = 1.0f; + const int input_zero_point = 127; + int pad_dims[] = { 2, 4, 2 }; + const int32_t pad_values[] = { 1, 1, 0, 0, 1, 1, 0, 0 }; + int output_dims[] = { 4, 3, 2, 4, 1 }; + const float golden[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, + 0, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + const float output_scale = 1.0f; + const int output_zero_point = 127; + uint8_t output_data[24]; + uint8_t input_quantized[4]; + uint8_t golden_quantized[24]; + + tflite::testing::TestPadQuantized( + input_dims, input_values, input_quantized, input_scale, input_zero_point, + pad_dims, pad_values, output_dims, golden, golden_quantized, output_scale, + output_zero_point, output_data); +} + +TF_LITE_MICRO_TEST(Test2DUInt8V2) +{ + int input_dims[] = { 4, 1, 2, 2, 1 }; + const float input_values[] = { 1, 2, 3, 4 }; + const float input_scale = 1.0f; + const int input_zero_point = 127; + int pad_dims[] = { 2, 4, 2 }; + const int32_t pad_values[] = { 1, 1, 0, 0, 1, 1, 0, 0 }; + const float pad_value = 42; + const float pad_value_scale = 1.0; + const float pad_value_zero_point = 127; + int output_dims[] = { 4, 3, 2, 4, 1 }; + const float golden[] = { 42, 42, 42, 42, 42, 42, 42, 42, 42, 1, 2, 42, + 42, 3, 4, 42, 42, 42, 42, 42, 42, 42, 42, 42 }; + const float output_scale = 1.0f; + const int output_zero_point = 127; + uint8_t output_data[24]; + uint8_t input_quantized[4]; + uint8_t golden_quantized[24]; + + tflite::testing::TestPadV2Quantized( + input_dims, input_values, input_quantized, input_scale, input_zero_point, + pad_dims, pad_values, pad_value, pad_value_scale, pad_value_zero_point, + output_dims, golden, golden_quantized, output_scale, output_zero_point, + output_data); +} + +TF_LITE_MICRO_TEST(Test2DInt8) +{ + int input_dims[] = { 4, 1, 2, 2, 1 }; + const float input_values[] = { 1, 2, 3, 4 }; + const float input_scale = 1.0f; + const int input_zero_point = 0; + int pad_dims[] = { 2, 4, 2 }; + const int32_t pad_values[] = { 1, 1, 0, 0, 1, 1, 0, 0 }; + int output_dims[] = { 4, 3, 2, 4, 1 }; + const float golden[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, + 0, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + const float output_scale = 1.0f; + const int output_zero_point = 0; + int8_t output_data[24]; + int8_t input_quantized[4]; + int8_t golden_quantized[24]; + + tflite::testing::TestPadQuantized( + input_dims, input_values, input_quantized, input_scale, input_zero_point, + pad_dims, pad_values, output_dims, golden, golden_quantized, output_scale, + output_zero_point, output_data); +} + +TF_LITE_MICRO_TEST(Test2DInt8V2) +{ + int input_dims[] = { 4, 1, 2, 2, 1 }; + const float input_values[] = { 1, 2, 3, 4 }; + const float input_scale = 1.0f; + const int input_zero_point = 0; + int pad_dims[] = { 2, 4, 2 }; + const int32_t pad_values[] = { 1, 1, 0, 0, 1, 1, 0, 0 }; + const float pad_value = 42; + const float pad_value_scale = 1.0; + const float pad_value_zero_point = 0; + int output_dims[] = { 4, 3, 2, 4, 1 }; + const float golden[] = { 42, 42, 42, 42, 42, 42, 42, 42, 42, 1, 2, 42, + 42, 3, 4, 42, 42, 42, 42, 42, 42, 42, 42, 42 }; + const float output_scale = 1.0f; + const int output_zero_point = 0; + int8_t output_data[24]; + int8_t input_quantized[4]; + int8_t golden_quantized[24]; + + tflite::testing::TestPadV2Quantized( + input_dims, input_values, input_quantized, input_scale, input_zero_point, + pad_dims, pad_values, pad_value, pad_value_scale, pad_value_zero_point, + output_dims, golden, golden_quantized, output_scale, output_zero_point, + output_data); +} + +TF_LITE_MICRO_TEST(Test2DInt8V2ExpectFailurePadValueQuantizationMismatch) +{ + int input_dims[] = { 4, 1, 2, 2, 1 }; + const float input_values[] = { 1, 2, 3, 4 }; + const float input_scale = 1.0f; + const int input_zero_point = 0; + int pad_dims[] = { 2, 4, 2 }; + const int32_t pad_values[] = { 1, 1, 0, 0, 1, 1, 0, 0 }; + const float pad_value = 42; + // Causes failure since this is in a different quantization space than input. + const float pad_value_scale = .5; + const float pad_value_zero_point = 0; + int output_dims[] = { 4, 3, 2, 4, 1 }; + const float golden[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + const float output_scale = 1.0f; + const int output_zero_point = 0; + int8_t output_data[24] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + int8_t input_quantized[4]; + int8_t golden_quantized[24]; + + tflite::testing::TestPadV2Quantized( + input_dims, input_values, input_quantized, input_scale, input_zero_point, + pad_dims, pad_values, pad_value, pad_value_scale, pad_value_zero_point, + output_dims, golden, golden_quantized, output_scale, output_zero_point, + output_data, kTfLiteError); +} + +TF_LITE_MICRO_TEST(Test2DInt8ExpectFailureQuantizationRangeExcludesZero) +{ + int input_dims[] = { 4, 1, 2, 2, 1 }; + const float input_values[] = { 1, 2, 3, 4 }; + const float input_scale = 1.0f; + const int input_zero_point = 0; + int pad_dims[] = { 2, 4, 2 }; + const int32_t pad_values[] = { 1, 1, 0, 0, 1, 1, 0, 0 }; + int output_dims[] = { 4, 3, 2, 4, 1 }; + const float golden[] = { 42, 42, 42, 42, 42, 42, 42, 42, 42, 1, 2, 42, + 42, 3, 4, 42, 42, 42, 42, 42, 42, 42, 42, 42 }; + // Causes failure since this quantization zero point excludes zero. + const float output_scale = 1.0f; + const int output_zero_point = 129; + int8_t output_data[24]; + int8_t input_quantized[4]; + int8_t golden_quantized[24]; + + tflite::testing::TestPadQuantized( + input_dims, input_values, input_quantized, input_scale, input_zero_point, + pad_dims, pad_values, output_dims, golden, golden_quantized, output_scale, + output_zero_point, output_data, kTfLiteError); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/pooling.cc b/components/tflite/tensorflow/lite/micro/kernels/pooling.cc new file mode 100644 index 00000000..219a0a54 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/pooling.cc @@ -0,0 +1,117 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/kernels/internal/reference/pooling.h" + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/pooling.h" + +namespace tflite { + +namespace { + +TfLiteStatus AverageEval(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->builtin_data != nullptr); + auto *params = reinterpret_cast(node->builtin_data); + + TFLITE_DCHECK(node->user_data != nullptr); + const OpDataPooling *data = + static_cast(node->user_data); + + const TfLiteEvalTensor *input = + micro::GetEvalInput(context, node, kPoolingInputTensor); + TfLiteEvalTensor *output = + micro::GetEvalOutput(context, node, kPoolingOutputTensor); + + // Inputs and outputs share the same type, guaranteed by the converter. + switch (input->type) { + case kTfLiteFloat32: + AveragePoolingEvalFloat(context, node, params, data, input, output); + break; + case kTfLiteInt8: + AveragePoolingEvalQuantized(context, node, params, data, input, output); + break; + default: + TF_LITE_KERNEL_LOG(context, "Input type %s is not currently supported", + TfLiteTypeGetName(input->type)); + return kTfLiteError; + } + return kTfLiteOk; +} + +TfLiteStatus MaxEval(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->builtin_data != nullptr); + auto *params = reinterpret_cast(node->builtin_data); + + TFLITE_DCHECK(node->user_data != nullptr); + const OpDataPooling *data = + static_cast(node->user_data); + + const TfLiteEvalTensor *input = + micro::GetEvalInput(context, node, kPoolingInputTensor); + TfLiteEvalTensor *output = + micro::GetEvalOutput(context, node, kPoolingOutputTensor); + + switch (input->type) { + case kTfLiteFloat32: + MaxPoolingEvalFloat(context, node, params, data, input, output); + break; + case kTfLiteInt8: + MaxPoolingEvalQuantized(context, node, params, data, input, output); + break; + default: + TF_LITE_KERNEL_LOG(context, "Type %s not currently supported.", + TfLiteTypeGetName(input->type)); + return kTfLiteError; + } + return kTfLiteOk; +} + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(OpDataPooling)); +} + +} // namespace + +TfLiteRegistration Register_AVERAGE_POOL_2D() +{ + return { /*init=*/Init, + /*free=*/nullptr, + /*prepare=*/PoolingPrepare, + /*invoke=*/AverageEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +TfLiteRegistration Register_MAX_POOL_2D() +{ + return { /*init=*/Init, + /*free=*/nullptr, + /*prepare=*/PoolingPrepare, + /*invoke=*/MaxEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/pooling.h b/components/tflite/tensorflow/lite/micro/kernels/pooling.h new file mode 100644 index 00000000..f106030e --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/pooling.h @@ -0,0 +1,70 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_KERNELS_POOLING_H_ +#define TENSORFLOW_LITE_MICRO_KERNELS_POOLING_H_ + +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" + +namespace tflite { +extern const int kPoolingInputTensor; +extern const int kPoolingOutputTensor; + +struct OpDataPooling { + TfLitePaddingValues padding; + int32_t activation_min; + int32_t activation_max; + float activation_min_f32; + float activation_max_f32; +}; + +TfLiteStatus CalculateOpDataPooling(const TfLiteContext *context, + const TfLitePoolParams *params, + const TfLiteTensor *input, + const TfLiteTensor *output, + OpDataPooling *data); + +TfLiteStatus PoolingPrepare(TfLiteContext *context, TfLiteNode *node); + +void AveragePoolingEvalFloat(const TfLiteContext *context, + const TfLiteNode *node, + const TfLitePoolParams *params, + const OpDataPooling *data, + const TfLiteEvalTensor *input, + TfLiteEvalTensor *output); + +void AveragePoolingEvalQuantized(TfLiteContext *context, const TfLiteNode *node, + const TfLitePoolParams *params, + const OpDataPooling *data, + const TfLiteEvalTensor *input, + TfLiteEvalTensor *output); + +void MaxPoolingEvalFloat(TfLiteContext *context, TfLiteNode *node, + TfLitePoolParams *params, const OpDataPooling *data, + const TfLiteEvalTensor *input, + TfLiteEvalTensor *output); + +void MaxPoolingEvalQuantized(TfLiteContext *context, TfLiteNode *node, + TfLitePoolParams *params, + const OpDataPooling *data, + const TfLiteEvalTensor *input, + TfLiteEvalTensor *output); + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_KERNELS_POOLING_H_ diff --git a/components/tflite/tensorflow/lite/micro/kernels/pooling_common.cc b/components/tflite/tensorflow/lite/micro/kernels/pooling_common.cc new file mode 100644 index 00000000..30f5dd83 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/pooling_common.cc @@ -0,0 +1,169 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/kernels/internal/reference/integer_ops/pooling.h" +#include "tensorflow/lite/kernels/internal/reference/pooling.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/padding.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/pooling.h" + +namespace tflite { + +const int kPoolingInputTensor = 0; +const int kPoolingOutputTensor = 0; + +TfLiteStatus CalculateOpDataPooling(const TfLiteContext *context, + const TfLitePoolParams *params, + const TfLiteTensor *input, + const TfLiteTensor *output, + OpDataPooling *data) +{ + // input: batch, height, width, channel + int height = SizeOfDimension(input, 1); + int width = SizeOfDimension(input, 2); + + int out_height, out_width; + + data->padding = ComputePaddingHeightWidth( + params->stride_height, params->stride_width, + /*dilation_rate_height=*/1, + /*dilation_rate_width=*/1, height, width, params->filter_height, + params->filter_width, params->padding, &out_height, &out_width); + + return kTfLiteOk; +} + +TfLiteStatus PoolingPrepare(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->builtin_data != nullptr); + auto *params = reinterpret_cast(node->builtin_data); + + TFLITE_DCHECK(node->user_data != nullptr); + OpDataPooling *data = static_cast(node->user_data); + + const TfLiteTensor *input = GetInput(context, node, kPoolingInputTensor); + TF_LITE_ENSURE(context, input != nullptr); + TfLiteTensor *output = GetOutput(context, node, kPoolingOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + + TF_LITE_ENSURE_STATUS( + CalculateOpDataPooling(context, params, input, output, data)); + + if (input->type == kTfLiteFloat32) { + CalculateActivationRange(params->activation, &data->activation_min_f32, + &data->activation_max_f32); + } else if (input->type == kTfLiteInt8) { + CalculateActivationRangeQuantized(context, params->activation, output, + &data->activation_min, + &data->activation_max); + } + + return kTfLiteOk; +} + +void AveragePoolingEvalFloat(const TfLiteContext *context, + const TfLiteNode *node, + const TfLitePoolParams *params, + const OpDataPooling *data, + const TfLiteEvalTensor *input, + TfLiteEvalTensor *output) +{ + PoolParams op_params; + op_params.stride_height = params->stride_height; + op_params.stride_width = params->stride_width; + op_params.filter_height = params->filter_height; + op_params.filter_width = params->filter_width; + op_params.padding_values.height = data->padding.height; + op_params.padding_values.width = data->padding.width; + op_params.float_activation_min = data->activation_min_f32; + op_params.float_activation_max = data->activation_max_f32; + reference_ops::AveragePool(op_params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); +} + +void AveragePoolingEvalQuantized(TfLiteContext *context, const TfLiteNode *node, + const TfLitePoolParams *params, + const OpDataPooling *data, + const TfLiteEvalTensor *input, + TfLiteEvalTensor *output) +{ + TFLITE_DCHECK(input->type == kTfLiteInt8); + + PoolParams op_params; + op_params.stride_height = params->stride_height; + op_params.stride_width = params->stride_width; + op_params.filter_height = params->filter_height; + op_params.filter_width = params->filter_width; + op_params.padding_values.height = data->padding.height; + op_params.padding_values.width = data->padding.width; + op_params.quantized_activation_min = data->activation_min; + op_params.quantized_activation_max = data->activation_max; + + reference_integer_ops::AveragePool( + op_params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); +} + +void MaxPoolingEvalFloat(TfLiteContext *context, TfLiteNode *node, + TfLitePoolParams *params, const OpDataPooling *data, + const TfLiteEvalTensor *input, + TfLiteEvalTensor *output) +{ + tflite::PoolParams op_params; + op_params.stride_height = params->stride_height; + op_params.stride_width = params->stride_width; + op_params.filter_height = params->filter_height; + op_params.filter_width = params->filter_width; + op_params.padding_values.height = data->padding.height; + op_params.padding_values.width = data->padding.width; + op_params.float_activation_min = data->activation_min_f32; + op_params.float_activation_max = data->activation_max_f32; + reference_ops::MaxPool(op_params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); +} + +void MaxPoolingEvalQuantized(TfLiteContext *context, TfLiteNode *node, + TfLitePoolParams *params, + const OpDataPooling *data, + const TfLiteEvalTensor *input, + TfLiteEvalTensor *output) +{ + tflite::PoolParams op_params; + op_params.stride_height = params->stride_height; + op_params.stride_width = params->stride_width; + op_params.filter_height = params->filter_height; + op_params.filter_width = params->filter_width; + op_params.padding_values.height = data->padding.height; + op_params.padding_values.width = data->padding.width; + op_params.quantized_activation_min = data->activation_min; + op_params.quantized_activation_max = data->activation_max; + + reference_integer_ops::MaxPool(op_params, + tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/pooling_test.cc b/components/tflite/tensorflow/lite/micro/kernels/pooling_test.cc new file mode 100644 index 00000000..6bf9ccd1 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/pooling_test.cc @@ -0,0 +1,526 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +template +void ValidatePoolingGoldens(TfLiteTensor *tensors, int tensors_size, + const TfLiteRegistration registration, + const int filter_height, const int filter_width, + const int stride_height, const int stride_width, + const T *golden, const int output_length, + TfLitePadding padding, + TfLiteFusedActivation activation, T *output_data) +{ + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + TfLitePoolParams builtin_data = { padding, + stride_width, + stride_height, + filter_width, + filter_height, + activation, + {} }; + + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + reinterpret_cast(&builtin_data)); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_length; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(golden[i], output_data[i], 1e-5f); + } +} + +void TestAveragePoolFloat(int *input_dims_data, const float *input_data, + const int filter_height, const int filter_width, + const int stride_height, const int stride_width, + const float *expected_output_data, + int *output_dims_data, TfLitePadding padding, + TfLiteFusedActivation activation, + float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims), + }; + + const TfLiteRegistration registration = Register_AVERAGE_POOL_2D(); + + ValidatePoolingGoldens(tensors, tensors_size, registration, filter_height, + filter_width, stride_height, stride_width, + expected_output_data, output_dims_count, padding, + activation, output_data); +} + +template +void TestAveragePoolQuantized( + int *input_dims_data, const T *input_data, const float input_scale, + const int input_zero_point, const int filter_height, const int filter_width, + const int stride_height, const int stride_width, + const T *expected_output_data, int *output_dims_data, + const float output_scale, const int output_zero_point, + TfLitePadding padding, TfLiteFusedActivation activation, T *output_data) +{ + static_assert(sizeof(T) == 1, "Only int8_t/uint8_t data types allowed."); + + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(input_data, input_dims, input_scale, + input_zero_point), + CreateQuantizedTensor(output_data, output_dims, output_scale, + output_zero_point), + }; + + const TfLiteRegistration registration = Register_AVERAGE_POOL_2D(); + ValidatePoolingGoldens(tensors, tensors_size, registration, filter_height, + filter_width, stride_height, stride_width, + expected_output_data, output_dims_count, padding, + activation, output_data); +} + +void TestMaxPoolFloat(int *input_dims_data, const float *input_data, + int filter_width, int filter_height, int stride_width, + int stride_height, const float *expected_output_data, + int *output_dims_data, TfLitePadding padding, + TfLiteFusedActivation activation, float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims), + }; + + const TfLiteRegistration registration = Register_MAX_POOL_2D(); + ValidatePoolingGoldens(tensors, tensors_size, registration, filter_height, + filter_width, stride_height, stride_width, + expected_output_data, output_dims_count, padding, + activation, output_data); +} + +template +void TestMaxPoolQuantized(int *input_dims_data, const T *input_data, + const float input_scale, const int input_zero_point, + const int filter_height, const int filter_width, + const int stride_height, const int stride_width, + const T *expected_output_data, int *output_dims_data, + const float output_scale, const int output_zero_point, + TfLitePadding padding, + TfLiteFusedActivation activation, T *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(input_data, input_dims, input_scale, + input_zero_point), + CreateQuantizedTensor(output_data, output_dims, output_scale, + output_zero_point), + }; + + const TfLiteRegistration registration = Register_MAX_POOL_2D(); + ValidatePoolingGoldens(tensors, tensors_size, registration, filter_height, + filter_width, stride_height, stride_width, + expected_output_data, output_dims_count, padding, + activation, output_data); +} + +} // namespace + +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(SimpleAveragePoolTestFloat) +{ + int input_shape[] = { 4, 1, 2, 4, 1 }; + const float input_values[] = { 0, 6, 2, 4, 3, 2, 10, 7 }; + const int filter_width = 2; + const int filter_height = 2; + const int stride_width = 2; + const int stride_height = 2; + const float golden[] = { 2.75, 5.75 }; + int output_shape[] = { 4, 1, 1, 2, 1 }; + float output_data[2]; + tflite::testing::TestAveragePoolFloat( + input_shape, input_values, filter_height, filter_width, stride_height, + stride_width, golden, output_shape, kTfLitePaddingValid, kTfLiteActNone, + output_data); +} + +TF_LITE_MICRO_TEST(SimpleAveragePoolTestInt8PaddingValidStride2ActNone) +{ + int input_shape[] = { 4, 1, 2, 4, 1 }; + const int8_t input_values[] = { 0, -24, 8, 16, 12, 8, -40, 28 }; + const int filter_width = 2; + const int filter_height = 2; + const int stride_width = 2; + const int stride_height = 2; + const int8_t golden[] = { -1, 3 }; + int output_shape[] = { 4, 1, 1, 2, 1 }; + int8_t output_data[2]; + + const float input_scale = .25; + const int input_zero_point = 0; + const float output_scale = .25; + const int output_zero_point = 0; + tflite::testing::TestAveragePoolQuantized( + input_shape, input_values, input_scale, input_zero_point, filter_height, + filter_width, stride_height, stride_width, golden, output_shape, + output_scale, output_zero_point, kTfLitePaddingValid, kTfLiteActNone, + output_data); +} + +TF_LITE_MICRO_TEST(SimpleAveragePoolTestInt8PaddingValidStride1Stride2Relu) +{ + int input_shape[] = { 4, 1, 2, 4, 1 }; + const int8_t input_values[] = { 0, -24, 8, 16, 12, 8, -40, 28 }; + const int filter_width = 2; + const int filter_height = 2; + const int stride_width = 1; + const int stride_height = 2; + const int8_t golden[] = { 0, 0, 3 }; + int output_shape[] = { 4, 1, 1, 3, 1 }; + int8_t output_data[3]; + + const float input_scale = .25; + const int input_zero_point = 0; + const float output_scale = .25; + const int output_zero_point = 0; + tflite::testing::TestAveragePoolQuantized( + input_shape, input_values, input_scale, input_zero_point, filter_height, + filter_width, stride_height, stride_width, golden, output_shape, + output_scale, output_zero_point, kTfLitePaddingValid, kTfLiteActRelu, + output_data); +} + +TF_LITE_MICRO_TEST( + SimpleAveragePoolTestInt8PaddingValidStride2Stride1ReluN1To1) +{ + int input_shape[] = { 4, 1, 2, 4, 1 }; + const int8_t input_values[] = { 0, -24, 8, 16, 12, 8, -40, 28 }; + const int filter_width = 2; + const int filter_height = 2; + const int stride_width = 2; + const int stride_height = 1; + const int8_t golden[] = { -1, 3 }; + int output_shape[] = { 4, 1, 1, 2, 1 }; + int8_t output_data[2]; + + const float input_scale = .25; + const int input_zero_point = 0; + const float output_scale = .25; + const int output_zero_point = 0; + tflite::testing::TestAveragePoolQuantized( + input_shape, input_values, input_scale, input_zero_point, filter_height, + filter_width, stride_height, stride_width, golden, output_shape, + output_scale, output_zero_point, kTfLitePaddingValid, kTfLiteActReluN1To1, + output_data); +} + +TF_LITE_MICRO_TEST(SimpleAveragePoolTestInt8PaddingValidStride2Relu6) +{ + int input_shape[] = { 4, 1, 2, 4, 1 }; + const int8_t input_values[] = { 12, -24, 32, 16, 12, 8, 40, 28 }; + const int filter_width = 2; + const int filter_height = 2; + const int stride_width = 2; + const int stride_height = 2; + const int8_t golden[] = { 2, 24 }; + int output_shape[] = { 4, 1, 1, 2, 1 }; + int8_t output_data[2]; + + const float input_scale = .25; + const int input_zero_point = 0; + const float output_scale = .25; + const int output_zero_point = 0; + tflite::testing::TestAveragePoolQuantized( + input_shape, input_values, input_scale, input_zero_point, filter_height, + filter_width, stride_height, stride_width, golden, output_shape, + output_scale, output_zero_point, kTfLitePaddingValid, kTfLiteActRelu6, + output_data); +} + +TF_LITE_MICRO_TEST(SimpleAveragePoolTestInt8PaddingSameStride1ActNone) +{ + int input_shape[] = { 4, 1, 2, 4, 1 }; + const int8_t input_values[] = { 12, -24, 32, 16, 12, 8, 40, 28 }; + const int filter_width = 2; + const int filter_height = 2; + const int stride_width = 1; + const int stride_height = 1; + const int8_t golden[] = { 2, 14, 29, 22, 10, 24, 34, 28 }; + int output_shape[] = { 4, 1, 2, 4, 1 }; + int8_t output_data[8]; + + const float input_scale = .25; + const int input_zero_point = 0; + const float output_scale = .25; + const int output_zero_point = 0; + tflite::testing::TestAveragePoolQuantized( + input_shape, input_values, input_scale, input_zero_point, filter_height, + filter_width, stride_height, stride_width, golden, output_shape, + output_scale, output_zero_point, kTfLitePaddingValid, kTfLiteActNone, + output_data); +} + +TF_LITE_MICRO_TEST(SimpleMaxPoolTestFloat) +{ + int input_shape[] = { 4, 1, 2, 4, 1 }; + const float input_values[] = { 0, 6, 2, 4, 3, 2, 10, 7 }; + const int filter_width = 2; + const int filter_height = 2; + const int stride_width = 2; + const int stride_height = 2; + const float golden[] = { 6, 10 }; + int output_shape[] = { 4, 1, 1, 2, 1 }; + float output_data[2]; + tflite::testing::TestMaxPoolFloat(input_shape, input_values, filter_height, + filter_width, stride_height, stride_width, + golden, output_shape, kTfLitePaddingValid, + kTfLiteActNone, output_data); +} + +TF_LITE_MICRO_TEST(SimpleMaxPoolTestFloatRelu) +{ + int input_shape[] = { 4, 1, 2, 4, 1 }; + const float input_values[] = { -1, -6, 2, 4, -3, -2, 10.5, 7 }; + const int filter_width = 2; + const int filter_height = 2; + const int stride_width = 2; + const int stride_height = 2; + const float golden[] = { 0, 10.5 }; + int output_shape[] = { 4, 1, 1, 2, 1 }; + float output_data[2]; + tflite::testing::TestMaxPoolFloat(input_shape, input_values, filter_height, + filter_width, stride_height, stride_width, + golden, output_shape, kTfLitePaddingValid, + kTfLiteActRelu, output_data); +} + +TF_LITE_MICRO_TEST(SimpleMaxPoolTestFloatReluN1To1) +{ + int input_shape[] = { 4, 1, 2, 4, 1 }; + const float input_values1[] = { -2.75, -6, 0.2, 0.4, -3, -2, -0.3, 0.7 }; + const int filter_width = 2; + const int filter_height = 2; + const int stride_width = 2; + const int stride_height = 2; + const float golden1[] = { -1.0, 0.7 }; + int output_shape[] = { 4, 1, 1, 2, 1 }; + float output_data[2]; + tflite::testing::TestMaxPoolFloat(input_shape, input_values1, filter_height, + filter_width, stride_height, stride_width, + golden1, output_shape, kTfLitePaddingValid, + kTfLiteActReluN1To1, output_data); + + const float input_values2[] = { -2.75, -6, -2, -4, -3, -2, 10, -7 }; + const float golden2[] = { -1.0, 1.0 }; + tflite::testing::TestMaxPoolFloat(input_shape, input_values2, filter_height, + filter_width, stride_height, stride_width, + golden2, output_shape, kTfLitePaddingValid, + kTfLiteActReluN1To1, output_data); +} + +TF_LITE_MICRO_TEST(SimpleMaxPoolTestFloatRelu6) +{ + int input_shape[] = { 4, 1, 2, 4, 1 }; + const float input_values1[] = { -1.5, -6, 12, 4, -3, -2, 10, 7 }; + const int filter_width = 2; + const int filter_height = 2; + const int stride_width = 2; + const int stride_height = 2; + const float golden1[] = { 0, 6 }; + int output_shape[] = { 4, 1, 1, 2, 1 }; + float output_data[2]; + tflite::testing::TestMaxPoolFloat(input_shape, input_values1, filter_height, + filter_width, stride_height, stride_width, + golden1, output_shape, kTfLitePaddingValid, + kTfLiteActRelu6, output_data); + + const float input_values2[] = { 0, 4.5, 12, 4, 3, 2, 10, 7 }; + const float golden2[] = { 4.5, 6 }; + tflite::testing::TestMaxPoolFloat(input_shape, input_values2, filter_height, + filter_width, stride_height, stride_width, + golden2, output_shape, kTfLitePaddingValid, + kTfLiteActRelu6, output_data); +} + +TF_LITE_MICRO_TEST(SimpleMaxPoolTestPaddingSameStride1) +{ + int input_shape[] = { 4, 1, 2, 4, 1 }; + const float input_values[] = { 0, 6, 2, 4, 3, 2, 10, 7 }; + const int filter_width = 2; + const int filter_height = 2; + const int stride_width = 1; + const int stride_height = 1; + const float golden[] = { 6, 10, 10, 7, 3, 10, 10, 7 }; + int output_shape[] = { 4, 1, 2, 4, 1 }; + float output_data[8]; + tflite::testing::TestMaxPoolFloat(input_shape, input_values, filter_height, + filter_width, stride_height, stride_width, + golden, output_shape, kTfLitePaddingSame, + kTfLiteActNone, output_data); +} + +TF_LITE_MICRO_TEST(SimpleMaxPoolTestPaddingValidStride1) +{ + int input_shape[] = { 4, 1, 2, 4, 1 }; + const float input_values[] = { 0, 6, 2, 4, 3, 2, 10, 7 }; + const int filter_width = 2; + const int filter_height = 2; + const int stride_width = 1; + const int stride_height = 1; + const float golden[] = { 6, 10, 10 }; + int output_shape[] = { 4, 1, 1, 3, 1 }; + float output_data[8]; + tflite::testing::TestMaxPoolFloat(input_shape, input_values, filter_height, + filter_width, stride_height, stride_width, + golden, output_shape, kTfLitePaddingValid, + kTfLiteActNone, output_data); +} + +TF_LITE_MICRO_TEST(SimpleMaxPoolTestInt8ActNone) +{ + int input_shape[] = { 4, 1, 2, 4, 1 }; + const int8_t input_values1[] = { 0, 6, 2, 4, 3, 2, 10, 7 }; + const int filter_width = 2; + const int filter_height = 2; + const int stride_width = 2; + const int stride_height = 2; + const int8_t golden1[] = { 6, 10 }; + int output_shape[] = { 4, 1, 1, 2, 1 }; + int8_t output_data[2]; + + const float input_scale = 1.0; + const int input_zero_point = 0; + const float output_scale = 1.0; + const int output_zero_point = 0; + tflite::testing::TestMaxPoolQuantized( + input_shape, input_values1, input_scale, input_zero_point, filter_height, + filter_width, stride_height, stride_width, golden1, output_shape, + output_scale, output_zero_point, kTfLitePaddingValid, kTfLiteActNone, + output_data); +} + +TF_LITE_MICRO_TEST(MaxPoolTestInt8ActRelu) +{ + int input_shape[] = { 4, 1, 2, 4, 1 }; + const int8_t input_values1[] = { -3, -12, 4, 8, -6, -4, 20, 14 }; + const int filter_width = 2; + const int filter_height = 2; + const int stride_width = 2; + const int stride_height = 2; + const int8_t golden1[] = { 0, 20 }; + int output_shape[] = { 4, 1, 1, 2, 1 }; + int8_t output_data[2]; + + const float input_scale = 0.5; + const int input_zero_point = 0; + const float output_scale = 0.5; + const int output_zero_point = 0; + tflite::testing::TestMaxPoolQuantized( + input_shape, input_values1, input_scale, input_zero_point, filter_height, + filter_width, stride_height, stride_width, golden1, output_shape, + output_scale, output_zero_point, kTfLitePaddingValid, kTfLiteActRelu, + output_data); +} + +TF_LITE_MICRO_TEST(MaxPoolTestInt8ActReluN1To1) +{ + int input_shape[] = { 4, 1, 2, 4, 1 }; + const int8_t input_values1[] = { -2, -6, -2, -4, -3, -2, 10, 7 }; + const int filter_width = 2; + const int filter_height = 2; + const int stride_width = 2; + const int stride_height = 2; + const int8_t golden1[] = { -1, 1 }; + int output_shape[] = { 4, 1, 1, 2, 1 }; + int8_t output_data[2]; + + const float input_scale = 1.0; + const int input_zero_point = 0; + const float output_scale = 1.0; + const int output_zero_point = 0; + tflite::testing::TestMaxPoolQuantized( + input_shape, input_values1, input_scale, input_zero_point, filter_height, + filter_width, stride_height, stride_width, golden1, output_shape, + output_scale, output_zero_point, kTfLitePaddingValid, kTfLiteActReluN1To1, + output_data); +} + +TF_LITE_MICRO_TEST(MaxPoolTestInt8ActRelu6) +{ + int input_shape[] = { 4, 1, 2, 4, 1 }; + const int8_t input_values1[] = { 0, -6, 12, 4, -3, -2, 10, 7 }; + const int filter_width = 2; + const int filter_height = 2; + const int stride_width = 2; + const int stride_height = 2; + const int8_t golden1[] = { 0, 6 }; + int output_shape[] = { 4, 1, 1, 2, 1 }; + int8_t output_data[2]; + + const float input_scale = 1.0; + const int input_zero_point = 0; + const float output_scale = 1.0; + const int output_zero_point = 0; + tflite::testing::TestMaxPoolQuantized( + input_shape, input_values1, input_scale, input_zero_point, filter_height, + filter_width, stride_height, stride_width, golden1, output_shape, + output_scale, output_zero_point, kTfLitePaddingValid, kTfLiteActRelu6, + output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/prelu.cc b/components/tflite/tensorflow/lite/micro/kernels/prelu.cc new file mode 100644 index 00000000..50df2e56 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/prelu.cc @@ -0,0 +1,175 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/prelu.h" + +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace activations { +namespace { + +TfLiteStatus CalculatePreluParams(const TfLiteTensor *input, + const TfLiteTensor *alpha, + TfLiteTensor *output, PreluParams *params) +{ + if (output->type == kTfLiteInt8 || output->type == kTfLiteUInt8 || + output->type == kTfLiteInt16) { + double real_multiplier_1 = static_cast(input->params.scale) / + static_cast(output->params.scale); + double real_multiplier_2 = static_cast(input->params.scale) * + static_cast(alpha->params.scale) / + static_cast(output->params.scale); + QuantizeMultiplier(real_multiplier_1, ¶ms->output_multiplier_1, + ¶ms->output_shift_1); + QuantizeMultiplier(real_multiplier_2, ¶ms->output_multiplier_2, + ¶ms->output_shift_2); + + params->input_offset = -input->params.zero_point; + params->alpha_offset = -alpha->params.zero_point; + params->output_offset = output->params.zero_point; + } + + return kTfLiteOk; +} + +} // namespace + +inline void BroadcastPrelu4DSlowFloat( + const RuntimeShape &unextended_input1_shape, const float *input1_data, + const RuntimeShape &unextended_input2_shape, const float *input2_data, + const RuntimeShape &unextended_output_shape, float *output_data) +{ + TFLITE_DCHECK_LE(unextended_input1_shape.DimensionsCount(), 4); + TFLITE_DCHECK_LE(unextended_input2_shape.DimensionsCount(), 4); + TFLITE_DCHECK_LE(unextended_output_shape.DimensionsCount(), 4); + const RuntimeShape output_shape = + RuntimeShape::ExtendedShape(4, unextended_output_shape); + + NdArrayDesc<4> desc1; + NdArrayDesc<4> desc2; + NdArrayDescsForElementwiseBroadcast(unextended_input1_shape, + unextended_input2_shape, &desc1, &desc2); + + for (int b = 0; b < output_shape.Dims(0); ++b) { + for (int y = 0; y < output_shape.Dims(1); ++y) { + for (int x = 0; x < output_shape.Dims(2); ++x) { + for (int c = 0; c < output_shape.Dims(3); ++c) { + auto out_idx = Offset(output_shape, b, y, x, c); + auto in1_idx = SubscriptToIndex(desc1, b, y, x, c); + auto in2_idx = SubscriptToIndex(desc2, b, y, x, c); + auto in1_val = input1_data[in1_idx]; + auto in2_val = input2_data[in2_idx]; + output_data[out_idx] = in1_val >= 0.0f ? in1_val : in1_val * in2_val; + } + } + } + } +} + +void *PreluInit(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(PreluParams)); +} + +TfLiteStatus PreluPrepare(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + PreluParams *params = static_cast(node->user_data); + + const TfLiteTensor *input = GetInput(context, node, 0); + TF_LITE_ENSURE(context, input != nullptr); + const TfLiteTensor *alpha = GetInput(context, node, 1); + TF_LITE_ENSURE(context, alpha != nullptr); + TfLiteTensor *output = GetOutput(context, node, 0); + TF_LITE_ENSURE(context, output != nullptr); + + return CalculatePreluParams(input, alpha, output, params); +} + +TfLiteStatus PreluEval(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + const PreluParams ¶ms = + *(static_cast(node->user_data)); + + const TfLiteEvalTensor *input = tflite::micro::GetEvalInput(context, node, 0); + const TfLiteEvalTensor *alpha = tflite::micro::GetEvalInput(context, node, 1); + TfLiteEvalTensor *output = tflite::micro::GetEvalOutput(context, node, 0); + + switch (input->type) { + case kTfLiteFloat32: { + BroadcastPrelu4DSlowFloat(tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(alpha), + tflite::micro::GetTensorData(alpha), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + return kTfLiteOk; + } break; + case kTfLiteUInt8: { + reference_ops::BroadcastPrelu4DSlow( + params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(alpha), + tflite::micro::GetTensorData(alpha), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + return kTfLiteOk; + } break; + case kTfLiteInt8: { + reference_ops::BroadcastPrelu4DSlow( + params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(alpha), + tflite::micro::GetTensorData(alpha), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + return kTfLiteOk; + } break; + default: + TF_LITE_KERNEL_LOG( + context, "Only float32 and uint8_t are supported currently, got %d.", + TfLiteTypeGetName(input->type)); + return kTfLiteError; + } +} + +} // namespace activations + +TfLiteRegistration Register_PRELU() +{ + return { /*init=*/activations::PreluInit, + /*free=*/nullptr, + /*prepare=*/activations::PreluPrepare, + /*invoke=*/activations::PreluEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/prelu_test.cc b/components/tflite/tensorflow/lite/micro/kernels/prelu_test.cc new file mode 100644 index 00000000..80c48f68 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/prelu_test.cc @@ -0,0 +1,200 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +template +void ValidatePreluGoldens(TfLiteTensor *tensors, int tensors_size, + const T *golden, const int output_length, + T *output_data) +{ + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = tflite::ops::micro::Register_PRELU(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_length; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(golden[i], output_data[i], 1e-5f); + } +} + +void TestPreluFloat(int *input_dims_data, const float *input_data, + int *alpha_dims_data, const float *alpha_data, + const float *expected_output_data, int *output_dims_data, + float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *alpha_dims = IntArrayFromInts(alpha_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(alpha_data, alpha_dims), + CreateTensor(output_data, output_dims), + }; + + ValidatePreluGoldens(tensors, tensors_size, expected_output_data, + output_dims_count, output_data); +} + +// Template argument T can be either uint8_t or int8_t depending on which type +// of quantization required to be tested. +template +void TestPreluQuantized(int *input_dims_data, const float *input_data, + T *input_quantized, const float input_scale, + const int input_zero_point, int *alpha_dims_data, + const float *alpha_data, T *alpha_quantized, + const float alpha_scale, const int alpha_zero_point, + const float *golden, T *golden_quantized, + const float output_scale, const int output_zero_point, + int *output_dims_data, T *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *alpha_dims = IntArrayFromInts(alpha_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(input_data, input_quantized, input_dims, + input_scale, input_zero_point), + CreateQuantizedTensor(alpha_data, alpha_quantized, alpha_dims, + alpha_scale, alpha_zero_point), + CreateQuantizedTensor(output_data, output_dims, output_scale, + output_zero_point), + }; + + Quantize(golden, golden_quantized, output_dims_count, output_scale, + output_zero_point); + + ValidatePreluGoldens(tensors, tensors_size, golden_quantized, + output_dims_count, output_data); +} +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(FloatPreluActivationsOpTest) +{ + int input_shape[] = { 3, 2, 2, 3 }; + const float input_values[] = { + 0.0f, 0.0f, 0.0f, // Row 1, Column 1 + 1.0f, 1.0f, 1.0f, // Row 1, Column 2 + -1.0f, -1.0f, -1.0f, // Row 2, Column 1 + -2.0f, -2.0f, -2.0f, // Row 1, Column 2 + }; + int alpha_shape[] = { 3, 1, 1, 3 }; + const float alpha_values[] = { 0.0f, 1.0f, 2.0f }; + int output_shape[] = { 3, 2, 2, 3 }; + const float golden[] = { + 0.0f, 0.0f, 0.0f, // Row 1, Column 1 + 1.0f, 1.0f, 1.0f, // Row 1, Column 2 + 0.0f, -1.0f, -2.0f, // Row 2, Column 1 + 0.0f, -2.0f, -4.0f, // Row 1, Column 2 + }; + const int output_dims_count = 12; + float output_data[output_dims_count]; + tflite::testing::TestPreluFloat(input_shape, input_values, alpha_shape, + alpha_values, golden, output_shape, + output_data); +} + +TF_LITE_MICRO_TEST(QuantizedUint8PreluActivationsOpTest) +{ + int input_shape[] = { 3, 2, 2, 3 }; + const float input_values[] = { + 0.0f, 0.0f, 0.0f, // Row 1, Column 1 + 0.5f, 0.5f, 0.5f, // Row 1, Column 2 + -1.0f, -1.0f, -1.0f, // Row 2, Column 1 + -0.25f, -0.25f, -0.25f, // Row 1, Column 2 + }; + int alpha_shape[] = { 3, 1, 1, 3 }; + const float alpha_values[] = { 0.0f, 0.5f, -0.5f }; + int output_shape[] = { 3, 2, 2, 3 }; + const float golden[] = { + 0.0f, 0.0f, 0.0f, // Row 1, Column 1 + 0.5f, 0.5f, 0.5f, // Row 1, Column 2 + 0.0f, -0.5f, 0.5f, // Row 2, Column 1 + 0.0f, -0.125f, 0.125f, // Row 1, Column 2 + }; + + const int dims_count = 12; + + uint8_t input_quantized[dims_count]; + uint8_t alpha_quantized[3]; + uint8_t golden_quantized[dims_count]; + float scale = 0.125; + int zero_point = 127; + uint8_t output_data[dims_count]; + + tflite::testing::TestPreluQuantized( + input_shape, input_values, input_quantized, scale, zero_point, + alpha_shape, alpha_values, alpha_quantized, scale, zero_point, golden, + golden_quantized, scale, zero_point, output_shape, output_data); +} + +TF_LITE_MICRO_TEST(QuantizedInt8PreluActivationsOpTest) +{ + int input_shape[] = { 3, 2, 2, 3 }; + const float input_values[] = { + 0.0f, 0.0f, 0.0f, // Row 1, Column 1 + 0.5f, 0.5f, 0.5f, // Row 1, Column 2 + -1.0f, -1.0f, -1.0f, // Row 2, Column 1 + -0.25f, -0.25f, -0.25f, // Row 1, Column 2 + }; + int alpha_shape[] = { 3, 1, 1, 3 }; + const float alpha_values[] = { 0.0f, 0.5f, -0.5f }; + int output_shape[] = { 3, 2, 2, 3 }; + const float golden[] = { + 0.0f, 0.0f, 0.0f, // Row 1, Column 1 + 0.5f, 0.5f, 0.5f, // Row 1, Column 2 + 0.0f, -0.5f, 0.5f, // Row 2, Column 1 + 0.0f, -0.125f, 0.125f, // Row 1, Column 2 + }; + const int dims_count = 12; + int8_t input_quantized[dims_count]; + int8_t alpha_quantized[3]; + int8_t golden_quantized[dims_count]; + float scale = 2.0 / 255.0; + int zero_point = 0; + int8_t output_data[dims_count]; + tflite::testing::TestPreluQuantized( + input_shape, input_values, input_quantized, scale, zero_point, + alpha_shape, alpha_values, alpha_quantized, scale, zero_point, golden, + golden_quantized, scale, zero_point, output_shape, output_data); +} +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/quantization_util_test.cc b/components/tflite/tensorflow/lite/micro/kernels/quantization_util_test.cc new file mode 100644 index 00000000..53bfa888 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/quantization_util_test.cc @@ -0,0 +1,479 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/quantization_util.h" + +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace { + +template +void RunSafeCastTests() +{ + const IntOut imax = std::numeric_limits::max(); + TF_LITE_MICRO_EXPECT_GT(imax, 0); + const IntOut imin = std::numeric_limits::min(); + const bool s = std::numeric_limits::is_signed; + if (s) { + TF_LITE_MICRO_EXPECT_LT(static_cast(imin), 0); + } else { + TF_LITE_MICRO_EXPECT_EQ(static_cast(0), imin); + } + + // Some basic tests. + TF_LITE_MICRO_EXPECT_EQ(SafeCast(static_cast(0.0)), + static_cast(0)); + TF_LITE_MICRO_EXPECT_EQ(SafeCast(static_cast(-0.0)), + static_cast(0)); + TF_LITE_MICRO_EXPECT_EQ(SafeCast(static_cast(0.99)), + static_cast(0)); + TF_LITE_MICRO_EXPECT_EQ(SafeCast(static_cast(1.0)), + static_cast(1)); + TF_LITE_MICRO_EXPECT_EQ(SafeCast(static_cast(1.01)), + static_cast(1)); + TF_LITE_MICRO_EXPECT_EQ(SafeCast(static_cast(1.99)), + static_cast(1)); + TF_LITE_MICRO_EXPECT_EQ(SafeCast(static_cast(2.0)), + static_cast(2)); + TF_LITE_MICRO_EXPECT_EQ(SafeCast(static_cast(2.01)), + static_cast(2)); + TF_LITE_MICRO_EXPECT_EQ(SafeCast(static_cast(-0.99)), + static_cast(0)); + TF_LITE_MICRO_EXPECT_EQ(SafeCast(static_cast(-1.0)), + s ? static_cast(-1) : static_cast(0)); + TF_LITE_MICRO_EXPECT_EQ(SafeCast(static_cast(-1.01)), + s ? static_cast(-1) : static_cast(0)); + TF_LITE_MICRO_EXPECT_EQ(SafeCast(static_cast(-1.99)), + s ? static_cast(-1) : static_cast(0)); + TF_LITE_MICRO_EXPECT_EQ(SafeCast(static_cast(-2.0)), + s ? static_cast(-2) : static_cast(0)); + TF_LITE_MICRO_EXPECT_EQ(SafeCast(static_cast(-2.01)), + s ? static_cast(-2) : static_cast(0)); + TF_LITE_MICRO_EXPECT_EQ(SafeCast(static_cast(117.9)), + static_cast(117)); + TF_LITE_MICRO_EXPECT_EQ(SafeCast(static_cast(118.0)), + static_cast(118)); + TF_LITE_MICRO_EXPECT_EQ(SafeCast(static_cast(118.1)), + static_cast(118)); + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(static_cast(-117.9)), + s ? static_cast(-117) : static_cast(0)); + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(static_cast(-118.0)), + s ? static_cast(-118) : static_cast(0)); + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(static_cast(-118.1)), + s ? static_cast(-118) : static_cast(0)); + + // Some edge cases. + TF_LITE_MICRO_EXPECT_EQ(SafeCast(std::numeric_limits::max()), + imax); + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(std::numeric_limits::lowest()), imin); + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(std::numeric_limits::infinity()), imax); + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(-std::numeric_limits::infinity()), imin); + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(std::numeric_limits::quiet_NaN()), + static_cast(0)); + + // Some larger numbers. + if (sizeof(IntOut) >= static_cast(4) && + sizeof(FloatIn) > static_cast(4)) { + TF_LITE_MICRO_EXPECT_EQ(SafeCast(static_cast(0x76543210)), + static_cast(0x76543210)); + } + + if (sizeof(FloatIn) > sizeof(IntOut)) { + // Check values near imax. + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(static_cast(static_cast(imax) + + static_cast(0.1))), + imax); + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(static_cast(static_cast(imax) + + static_cast(0.99))), + imax); + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(static_cast(static_cast(imax) + + static_cast(1.0))), + imax); + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(static_cast(static_cast(imax) + + static_cast(1.99))), + imax); + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(static_cast(static_cast(imax) + + static_cast(2.0))), + imax); + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(static_cast(static_cast(imax) - + static_cast(0.1))), + imax - 1); + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(static_cast(static_cast(imax) - + static_cast(0.99))), + imax - 1); + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(static_cast(static_cast(imax) - + static_cast(1.0))), + imax - 1); + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(static_cast(static_cast(imax) - + static_cast(1.01))), + imax - 2); + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(static_cast(static_cast(imax) - + static_cast(1.99))), + imax - 2); + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(static_cast(static_cast(imax) - + static_cast(2.0))), + imax - 2); + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(static_cast(static_cast(imax) - + static_cast(2.01))), + imax - 3); + } + + // Check values considerably larger in magnitude than imin and imax + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(static_cast(static_cast(imax) * 2)), + imax); + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(static_cast(static_cast(imax) * 20)), + imax); + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(static_cast(static_cast(imax) * 100)), + imax); + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(static_cast(static_cast(imin) * 2)), + imin); + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(static_cast(static_cast(imin) * 20)), + imin); + TF_LITE_MICRO_EXPECT_EQ( + SafeCast(static_cast(static_cast(imin) * 100)), + imin); +} + +} // namespace +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(QuantizationUtilTest_SafeCast) +{ + tflite::RunSafeCastTests(); + tflite::RunSafeCastTests(); + tflite::RunSafeCastTests(); + tflite::RunSafeCastTests(); + tflite::RunSafeCastTests(); + tflite::RunSafeCastTests(); + tflite::RunSafeCastTests(); + tflite::RunSafeCastTests(); + tflite::RunSafeCastTests(); + tflite::RunSafeCastTests(); + tflite::RunSafeCastTests(); + tflite::RunSafeCastTests(); + tflite::RunSafeCastTests(); + tflite::RunSafeCastTests(); + tflite::RunSafeCastTests(); + tflite::RunSafeCastTests(); +} + +// Example taken from http://www.tensorflow.org/performance/quantization +// +// Quantized | Float +// --------- | ----- +// 0 | -10.0 +// 255 | 30.0 +// 128 | 10.0 +TF_LITE_MICRO_TEST(QuantizationUtilTest_ChooseQuantizationParams) +{ + tflite::QuantizationParams qp = + tflite::ChooseQuantizationParams(-10.0, 30.0); + TF_LITE_MICRO_EXPECT_NEAR(qp.scale, 0.156863, 1e-5); + TF_LITE_MICRO_EXPECT_EQ(qp.zero_point, 64); +} + +TF_LITE_MICRO_TEST( + QuantizationUtilTest_ChooseQuantizationParamsZeroPointOnMinBoundary) +{ + tflite::QuantizationParams qp = + tflite::ChooseQuantizationParams(0.0, 30.0); + TF_LITE_MICRO_EXPECT_NEAR(qp.scale, 0.117647, 1e-5); + TF_LITE_MICRO_EXPECT_EQ(qp.zero_point, 0); +} + +TF_LITE_MICRO_TEST( + QuantizationUtilTest_ChooseQuantizationParamsEmptyRangeZero) +{ + tflite::QuantizationParams qp = + tflite::ChooseQuantizationParams(0.0, 0.0); + TF_LITE_MICRO_EXPECT_NEAR(qp.scale, 0.0, 1e-5); + TF_LITE_MICRO_EXPECT_EQ(qp.zero_point, 0); +} + +TF_LITE_MICRO_TEST( + QuantizationUtilTest_ChooseQuantizationParamsZeroPointOnMaxBoundary) +{ + tflite::QuantizationParams qp = + tflite::ChooseQuantizationParams(-10.0, 0.0); + TF_LITE_MICRO_EXPECT_NEAR(qp.scale, 0.039216, 1e-5); + TF_LITE_MICRO_EXPECT_EQ(qp.zero_point, 255); +} + +TF_LITE_MICRO_TEST(QuantizationUtilTest_IntegerFrExp) +{ + int shift; + int64_t result = tflite::IntegerFrExp(0.0, &shift); + TF_LITE_MICRO_EXPECT_EQ(0, result); + TF_LITE_MICRO_EXPECT_EQ(0, shift); + + result = tflite::IntegerFrExp(1.0, &shift); + TF_LITE_MICRO_EXPECT_NEAR(0x40000000, result, 1ll); + TF_LITE_MICRO_EXPECT_EQ(1, shift); + + result = tflite::IntegerFrExp(0.25, &shift); + TF_LITE_MICRO_EXPECT_NEAR(0x40000000, result, 1ll); + TF_LITE_MICRO_EXPECT_EQ(-1, shift); + + result = tflite::IntegerFrExp(-1.0, &shift); + TF_LITE_MICRO_EXPECT_NEAR(-(1 << 30), result, 1ll); + TF_LITE_MICRO_EXPECT_EQ(1, shift); + + result = tflite::IntegerFrExp(123.45, &shift); + TF_LITE_MICRO_EXPECT_NEAR(2071147315, result, 1ll); + TF_LITE_MICRO_EXPECT_EQ(7, shift); + + result = tflite::IntegerFrExp(static_cast(NAN), &shift); + TF_LITE_MICRO_EXPECT_NEAR(0, result, 1); + TF_LITE_MICRO_EXPECT_EQ(0x7fffffff, shift); + + result = tflite::IntegerFrExp(static_cast(INFINITY), &shift); + TF_LITE_MICRO_EXPECT_NEAR(std::numeric_limits::max(), result, 1); + TF_LITE_MICRO_EXPECT_EQ(0x7fffffff, shift); + + result = tflite::IntegerFrExp(-static_cast(INFINITY), &shift); + TF_LITE_MICRO_EXPECT_NEAR(std::numeric_limits::min(), result, 1); + TF_LITE_MICRO_EXPECT_EQ(0x7fffffff, shift); +} + +TF_LITE_MICRO_TEST(QuantizationUtilTest_IntegerFrExpVersusDouble) +{ + int shift; + int32_t result = tflite::IntegerFrExp(0.0, &shift); + TF_LITE_MICRO_EXPECT_EQ(result, 0); + TF_LITE_MICRO_EXPECT_EQ(shift, 0); + + int double_shift; + double double_result = std::frexp(0.0, &double_shift); + TF_LITE_MICRO_EXPECT_EQ(double_result, 0); + TF_LITE_MICRO_EXPECT_EQ(double_shift, 0); + + result = tflite::IntegerFrExp(1.0, &shift); + TF_LITE_MICRO_EXPECT_NEAR(result, 0x40000000, 1); + TF_LITE_MICRO_EXPECT_EQ(shift, 1); + double_result = std::frexp(1.0, &double_shift); + TF_LITE_MICRO_EXPECT_NEAR(double_result, 0.5, 1e-5); + TF_LITE_MICRO_EXPECT_EQ(double_shift, 1); + + result = tflite::IntegerFrExp(0.25, &shift); + TF_LITE_MICRO_EXPECT_NEAR(result, 0x40000000, 1); + TF_LITE_MICRO_EXPECT_EQ(shift, -1); + double_result = std::frexp(0.25, &double_shift); + TF_LITE_MICRO_EXPECT_NEAR(double_result, 0.5, 1e-5); + TF_LITE_MICRO_EXPECT_EQ(double_shift, -1); + + result = tflite::IntegerFrExp(-1.0, &shift); + TF_LITE_MICRO_EXPECT_NEAR(result, -(1 << 30), 1); + TF_LITE_MICRO_EXPECT_EQ(shift, 1); + double_result = std::frexp(-1.0, &double_shift); + TF_LITE_MICRO_EXPECT_NEAR(double_result, -0.5, 1e-5); + TF_LITE_MICRO_EXPECT_EQ(double_shift, 1); + + result = tflite::IntegerFrExp(123.45, &shift); + TF_LITE_MICRO_EXPECT_NEAR(result, (0.964453 * (1LL << 31)), 1000); + TF_LITE_MICRO_EXPECT_EQ(shift, 7); + double_result = std::frexp(123.45, &double_shift); + TF_LITE_MICRO_EXPECT_NEAR(double_result, 0.964453, 1e-5); + TF_LITE_MICRO_EXPECT_EQ(double_shift, 7); +} + +TF_LITE_MICRO_TEST(QuantizationUtilTest_DoubleFromFractionAndShift) +{ + double result = tflite::DoubleFromFractionAndShift(0, 0); + TF_LITE_MICRO_EXPECT_EQ(0, result); + + result = tflite::DoubleFromFractionAndShift(0x40000000, 1); + TF_LITE_MICRO_EXPECT_NEAR(1.0, result, 1e-5); + + result = tflite::DoubleFromFractionAndShift(0x40000000, 2); + TF_LITE_MICRO_EXPECT_NEAR(2.0, result, 1e-5); + + int shift; + int64_t fraction = tflite::IntegerFrExp(3.0, &shift); + result = tflite::DoubleFromFractionAndShift(fraction, shift); + TF_LITE_MICRO_EXPECT_NEAR(3.0, result, 1e-5); + + fraction = tflite::IntegerFrExp(123.45, &shift); + result = tflite::DoubleFromFractionAndShift(fraction, shift); + TF_LITE_MICRO_EXPECT_NEAR(123.45, result, 1e-5); + + fraction = tflite::IntegerFrExp(-23.232323, &shift); + result = tflite::DoubleFromFractionAndShift(fraction, shift); + TF_LITE_MICRO_EXPECT_NEAR(-23.232323, result, 1e-5); + + fraction = tflite::IntegerFrExp(static_cast(NAN), &shift); + result = tflite::DoubleFromFractionAndShift(fraction, shift); + TF_LITE_MICRO_EXPECT_TRUE(std::isnan(result)); + + fraction = tflite::IntegerFrExp(static_cast(INFINITY), &shift); + result = tflite::DoubleFromFractionAndShift(fraction, shift); + TF_LITE_MICRO_EXPECT_FALSE(std::isfinite(result)); +} + +TF_LITE_MICRO_TEST(QuantizationUtilTest_IntegerDoubleMultiply) +{ + TF_LITE_MICRO_EXPECT_NEAR(1.0, tflite::IntegerDoubleMultiply(1.0, 1.0), 1e-5); + TF_LITE_MICRO_EXPECT_NEAR(2.0, tflite::IntegerDoubleMultiply(1.0, 2.0), 1e-5); + TF_LITE_MICRO_EXPECT_NEAR(2.0, tflite::IntegerDoubleMultiply(2.0, 1.0), 1e-5); + TF_LITE_MICRO_EXPECT_NEAR(4.0, tflite::IntegerDoubleMultiply(2.0, 2.0), 1e-5); + TF_LITE_MICRO_EXPECT_NEAR(0.5, tflite::IntegerDoubleMultiply(1.0, 0.5), 1e-5); + TF_LITE_MICRO_EXPECT_NEAR(0.25, tflite::IntegerDoubleMultiply(0.5, 0.5), + 1e-5); + TF_LITE_MICRO_EXPECT_NEAR(-1.0, tflite::IntegerDoubleMultiply(1.0, -1.0), + 1e-5); + TF_LITE_MICRO_EXPECT_NEAR(-1.0, tflite::IntegerDoubleMultiply(-1.0, 1.0), + 1e-5); + TF_LITE_MICRO_EXPECT_NEAR(1.0, tflite::IntegerDoubleMultiply(-1.0, -1.0), + 1e-5); + TF_LITE_MICRO_EXPECT_NEAR( + 15000000.0, tflite::IntegerDoubleMultiply(3000.0, 5000.0), 1e-5); + TF_LITE_MICRO_EXPECT_TRUE(std::isnan( + tflite::IntegerDoubleMultiply(static_cast(NAN), 5000.0))); + TF_LITE_MICRO_EXPECT_TRUE(std::isnan( + tflite::IntegerDoubleMultiply(3000.0, static_cast(NAN)))); +} + +TF_LITE_MICRO_TEST(QuantizationUtilTest_IntegerDoubleCompare) +{ + TF_LITE_MICRO_EXPECT_EQ(-1, tflite::IntegerDoubleCompare(0.0, 1.0)); + TF_LITE_MICRO_EXPECT_EQ(1, tflite::IntegerDoubleCompare(1.0, 0.0)); + TF_LITE_MICRO_EXPECT_EQ(0, tflite::IntegerDoubleCompare(1.0, 1.0)); + TF_LITE_MICRO_EXPECT_EQ(0, tflite::IntegerDoubleCompare(0.0, 0.0)); + TF_LITE_MICRO_EXPECT_EQ(-1, tflite::IntegerDoubleCompare(-10.0, 10.0)); + TF_LITE_MICRO_EXPECT_EQ(1, tflite::IntegerDoubleCompare(123.45, 10.0)); + TF_LITE_MICRO_EXPECT_EQ( + 1, tflite::IntegerDoubleCompare(static_cast(NAN), + static_cast(INFINITY))); + TF_LITE_MICRO_EXPECT_EQ( + 1, tflite::IntegerDoubleCompare(static_cast(INFINITY), + static_cast(NAN))); +} + +TF_LITE_MICRO_TEST(QuantizationUtilTest_PreprocessSoftmaxScaling) +{ + auto quantize = [](double beta, double scale, int integer_bits) { + int32_t q; + int s; + tflite::PreprocessSoftmaxScaling(beta, scale, integer_bits, &q, &s); + return std::pair{ q, s }; + }; + + // If beta * scale is greater than fits in the number of integer bits, the + // result is move near the maximum. Otherwise they quantize as expected. + // With 4 integer bits we can represent up to 16.0. + + auto r = quantize(1.0, 16.0, 4); + TF_LITE_MICRO_EXPECT_EQ(r.first, 2147483647); + TF_LITE_MICRO_EXPECT_EQ(r.second, 31); + + r = quantize(1.0, 8.0, 4); + TF_LITE_MICRO_EXPECT_EQ(r.first, 1073741824); + TF_LITE_MICRO_EXPECT_EQ(r.second, 31); + + // But with 5 bits we can go further. + r = quantize(2.0, 16.0, 5); + TF_LITE_MICRO_EXPECT_EQ(r.first, 2147483647); + TF_LITE_MICRO_EXPECT_EQ(r.second, 31); + + r = quantize(2.0, 8.0, 5); + TF_LITE_MICRO_EXPECT_EQ(r.first, 1073741824); + TF_LITE_MICRO_EXPECT_EQ(r.second, 31); +} + +TF_LITE_MICRO_TEST(QuantizationUtilTest_CalculateInputRadius) +{ + TF_LITE_MICRO_EXPECT_EQ(tflite::CalculateInputRadius(4, 27), 15); + TF_LITE_MICRO_EXPECT_EQ(tflite::CalculateInputRadius(3, 27), 14); + TF_LITE_MICRO_EXPECT_EQ(tflite::CalculateInputRadius(3, 28), 7); + TF_LITE_MICRO_EXPECT_EQ(tflite::CalculateInputRadius(4, 2), 503316480); +} + +TF_LITE_MICRO_TEST(QuantizationUtilTest_QuantizeMultiplierArray) +{ + const double weights[] = { -4, -2, -1, -0.5, -0.25, -0.125, 0, + 0.125, 0.25, 0.5, 1, 2, 4 }; + + const int size = 13; + int32_t effective_scale_significand[size]; + int effective_scale_shift[size]; + tflite::QuantizeMultiplierArray(weights, size, effective_scale_significand, + effective_scale_shift); + const int32_t expected_effective_scale_significand[] = { + -1073741824, // float scale = -4 + -1073741824, // float scale = -2 + -1073741824, // float scale = -1 + -1073741824, // float scale = -0.5 + -1073741824, // float scale = -0.25 + -1073741824, // float scale = -0.125 + 0, // float scale = 0 + 1073741824, // float scale = 0.125 + 1073741824, // float scale = 0.25 + 1073741824, // float scale = 0.5 + 1073741824, // float scale = 1 + 1073741824, // float scale = 2 + 1073741824, // float scale = 4 + }; + + const int expected_effective_scale_shift[] = { + 3, // float scale = -4 + 2, // float scale = -2 + 1, // float scale = -1 + 0, // float scale = -0.5 + -1, // float scale = -0.25 + -2, // float scale = -0.125 + 0, // float scale = 0 + -2, // float scale = 0.125 + -1, // float scale = 0.25 + 0, // float scale = 0.5 + 1, // float scale = 1 + 2, // float scale = 2 + 3, // float scale = 4 + }; + + for (int i = 0; i < size; i++) { + TF_LITE_MICRO_EXPECT_EQ(effective_scale_significand[i], + expected_effective_scale_significand[i]); + TF_LITE_MICRO_EXPECT_EQ(effective_scale_shift[i], + expected_effective_scale_shift[i]); + } +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/quantize.cc b/components/tflite/tensorflow/lite/micro/kernels/quantize.cc new file mode 100644 index 00000000..d80e9d71 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/quantize.cc @@ -0,0 +1,49 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/kernels/quantize.h" + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/micro_utils.h" + +namespace tflite { +namespace { + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, + sizeof(OpDataQuantizeReference)); +} + +} // namespace + +TfLiteRegistration Register_QUANTIZE() +{ + return { /*init=*/Init, + /*free=*/nullptr, + /*prepare=*/PrepareQuantizeReference, + /*invoke=*/EvalQuantizeReference, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/quantize.h b/components/tflite/tensorflow/lite/micro/kernels/quantize.h new file mode 100644 index 00000000..28c76396 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/quantize.h @@ -0,0 +1,36 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_MICRO_KERNELS_QUANTIZE_H_ +#define TENSORFLOW_LITE_MICRO_KERNELS_QUANTIZE_H_ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +struct OpDataQuantizeReference { + tflite::QuantizationParams quantization_params; + // The scaling factor from input to output (aka the 'real multiplier') can + // be represented as a fixed point multiplier plus a left shift. + int32_t requantize_output_multiplier; + int requantize_output_shift; + + int32_t input_zero_point; +}; + +TfLiteStatus EvalQuantizeReference(TfLiteContext *context, TfLiteNode *node); +TfLiteStatus PrepareQuantizeReference(TfLiteContext *context, TfLiteNode *node); +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_KERNELS_QUANTIZE_H_ diff --git a/components/tflite/tensorflow/lite/micro/kernels/quantize_common.cc b/components/tflite/tensorflow/lite/micro/kernels/quantize_common.cc new file mode 100644 index 00000000..5fc57d81 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/quantize_common.cc @@ -0,0 +1,173 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/quantize.h" +#include "tensorflow/lite/kernels/internal/reference/requantize.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/quantize.h" +#include "tensorflow/lite/micro/micro_utils.h" + +namespace tflite { + +TfLiteStatus PrepareQuantizeReference(TfLiteContext *context, + TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + auto *data = static_cast(node->user_data); + + TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + + const TfLiteTensor *input = GetInput(context, node, 0); + TF_LITE_ENSURE(context, input != nullptr); + TfLiteTensor *output = GetOutput(context, node, 0); + TF_LITE_ENSURE(context, output != nullptr); + + // TODO(b/128934713): Add support for fixed-point per-channel quantization. + // Currently this only support affine per-layer quantization. + TF_LITE_ENSURE_EQ(context, output->quantization.type, + kTfLiteAffineQuantization); + const auto *affine_quantization = + reinterpret_cast(output->quantization.params); + TF_LITE_ENSURE(context, affine_quantization); + TF_LITE_ENSURE(context, affine_quantization->scale); + TF_LITE_ENSURE(context, affine_quantization->scale->size == 1); + + TF_LITE_ENSURE(context, input->type == kTfLiteFloat32 || + input->type == kTfLiteInt16 || + input->type == kTfLiteInt8); + TF_LITE_ENSURE(context, output->type == kTfLiteInt8 || + output->type == kTfLiteInt16 || + output->type == kTfLiteInt32); + + if ((input->type == kTfLiteInt16 && output->type == kTfLiteInt8) || + (input->type == kTfLiteInt8 && output->type == kTfLiteInt8) || + (input->type == kTfLiteInt8 && output->type == kTfLiteInt32) || + (input->type == kTfLiteInt16 && output->type == kTfLiteInt16) || + (input->type == kTfLiteInt16 && output->type == kTfLiteInt32)) { + double effective_scale = static_cast(input->params.scale) / + static_cast(output->params.scale); + + QuantizeMultiplier(effective_scale, &data->requantize_output_multiplier, + &data->requantize_output_shift); + } + + data->quantization_params.zero_point = output->params.zero_point; + data->quantization_params.scale = static_cast(output->params.scale); + + data->input_zero_point = input->params.zero_point; + return kTfLiteOk; +} + +TfLiteStatus EvalQuantizeReference(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + auto *data = static_cast(node->user_data); + + const TfLiteEvalTensor *input = tflite::micro::GetEvalInput(context, node, 0); + TfLiteEvalTensor *output = tflite::micro::GetEvalOutput(context, node, 0); + + if (input->type == kTfLiteFloat32) { + switch (output->type) { + case kTfLiteInt8: + reference_ops::AffineQuantize( + data->quantization_params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + break; + case kTfLiteInt16: + reference_ops::AffineQuantize( + data->quantization_params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + return kTfLiteOk; + default: + TF_LITE_KERNEL_LOG(context, "Input %s, output %s not supported.", + TfLiteTypeGetName(input->type), + TfLiteTypeGetName(output->type)); + return kTfLiteError; + } + } else if (input->type == kTfLiteInt16) { + size_t size = ElementCount(*input->dims); + switch (output->type) { + case kTfLiteInt8: + reference_ops::Requantize( + tflite::micro::GetTensorData(input), size, + data->requantize_output_multiplier, data->requantize_output_shift, + data->input_zero_point, data->quantization_params.zero_point, + tflite::micro::GetTensorData(output)); + break; + case kTfLiteInt16: + reference_ops::Requantize( + tflite::micro::GetTensorData(input), size, + data->requantize_output_multiplier, data->requantize_output_shift, + data->input_zero_point, data->quantization_params.zero_point, + tflite::micro::GetTensorData(output)); + return kTfLiteOk; + case kTfLiteInt32: + reference_ops::Requantize( + tflite::micro::GetTensorData(input), size, + data->requantize_output_multiplier, data->requantize_output_shift, + data->input_zero_point, data->quantization_params.zero_point, + tflite::micro::GetTensorData(output)); + return kTfLiteOk; + default: + TF_LITE_KERNEL_LOG(context, "Input %s, output %s not supported.", + TfLiteTypeGetName(input->type), + TfLiteTypeGetName(output->type)); + return kTfLiteError; + } + } else if (input->type == kTfLiteInt8) { + // Int8 to Int8 requantization, required if the input and output tensors + // have different scales and/or zero points. + size_t size = ElementCount(*input->dims); + switch (output->type) { + case kTfLiteInt8: + reference_ops::Requantize( + tflite::micro::GetTensorData(input), size, + data->requantize_output_multiplier, data->requantize_output_shift, + data->input_zero_point, data->quantization_params.zero_point, + tflite::micro::GetTensorData(output)); + break; + case kTfLiteInt32: + reference_ops::Requantize( + tflite::micro::GetTensorData(input), size, + data->requantize_output_multiplier, data->requantize_output_shift, + data->input_zero_point, data->quantization_params.zero_point, + tflite::micro::GetTensorData(output)); + break; + default: + TF_LITE_KERNEL_LOG(context, "Input %s, output %s not supported.", + TfLiteTypeGetName(input->type), + TfLiteTypeGetName(output->type)); + return kTfLiteError; + } + } else { + TF_LITE_KERNEL_LOG(context, "Input %s, output %s not supported.", + TfLiteTypeGetName(input->type), + TfLiteTypeGetName(output->type)); + return kTfLiteError; + } + + return kTfLiteOk; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/quantize_test.cc b/components/tflite/tensorflow/lite/micro/kernels/quantize_test.cc new file mode 100644 index 00000000..54094a7d --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/quantize_test.cc @@ -0,0 +1,307 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +template +void ValidateQuantizeGoldens(TfLiteTensor *tensors, int tensors_size, + const float *golden, T *golden_quantized, + float scale, int zero_point, int output_len, + T *output_data) +{ + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + // Version 1 of quantize supports int8_t and uint8_t quantization. + const TfLiteRegistration registration = Register_QUANTIZE(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + // Use reference quantization from test utils to compare against op output. + Quantize(golden, golden_quantized, output_len, scale, zero_point); + for (int i = 0; i < output_len; ++i) { + TF_LITE_MICRO_EXPECT_EQ(golden_quantized[i], output_data[i]); + } +} + +#if !defined(XTENSA) +template +void TestQuantizeFloat(int *input_dims_data, const float *input_data, + int *output_dims_data, const float *golden, + T *golden_quantized, const float scale, + const int zero_point, T *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + TfLiteTensor output_tensor = + CreateQuantizedTensor(output_data, output_dims, scale, zero_point); + + TfLiteAffineQuantization quant; + float scales[] = { 1, scale }; + int zero_points[] = { 1, zero_point }; + quant.scale = FloatArrayFromFloats(scales); + quant.zero_point = IntArrayFromInts(zero_points); + output_tensor.quantization = { kTfLiteAffineQuantization, &quant }; + + // 1 input, 1 output. + constexpr int tensors_size = 2; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + output_tensor, + }; + + ValidateQuantizeGoldens(tensors, tensors_size, golden, golden_quantized, + scale, zero_point, output_dims_count, output_data); +} +#endif // defined(XTENSA) + +template +void TestRequantize(int *input_dims_data, const float *input_data, + InputType *input_quantized, const float input_scale, + const int input_zero_point, int *output_dims_data, + const float *golden, OutputType *golden_quantized, + const float output_scale, const int output_zero_point, + OutputType *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + TfLiteTensor output_tensor = CreateQuantizedTensor( + output_data, output_dims, output_scale, output_zero_point); + + TfLiteAffineQuantization quant; + float scales[] = { 1, output_scale }; + int zero_points[] = { 1, output_zero_point }; + quant.scale = FloatArrayFromFloats(scales); + quant.zero_point = IntArrayFromInts(zero_points); + output_tensor.quantization = { kTfLiteAffineQuantization, &quant }; + + // 1 input, 1 output. + constexpr int tensors_size = 2; + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(input_data, input_quantized, input_dims, + input_scale, input_zero_point), + output_tensor, + }; + + ValidateQuantizeGoldens(tensors, tensors_size, golden, golden_quantized, + output_scale, output_zero_point, output_dims_count, + output_data); +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +#if !defined(XTENSA) +TF_LITE_MICRO_TEST(QuantizeOpTestInt16) +{ + const int length = 10; + int dims[] = { 2, 2, 5 }; + const float values[] = { -63.5, -63, -62.5, -62, -61.5, + 62, 62.5, 63, 63.5, 64 }; + const float scale = 0.5; + const int zero_point = -1; + int16_t output[length]; + int16_t values_quantized[length]; + tflite::testing::TestQuantizeFloat( + dims, values, dims, values, values_quantized, scale, zero_point, output); +} + +TF_LITE_MICRO_TEST(QuantizeOpTestInt16NoScale) +{ + const int length = 10; + int dims[] = { 2, 2, 5 }; + const float values[] = { -128, -127, -126, -125, -124, + 123, 124, 125, 126, 127 }; + const float scale = 1.0; + const int zero_point = 0; + int16_t output[length]; + int16_t values_quantized[length]; + tflite::testing::TestQuantizeFloat( + dims, values, dims, values, values_quantized, scale, zero_point, output); +} + +TF_LITE_MICRO_TEST(QuantizeOpTestInt16toInt16) +{ + const int length = 10; + int dims[] = { 2, 2, 5 }; + const float values[] = { -64, -62, -60, -58, -56, 54, 56, 58, 60, 62 }; + const float input_scale = 2.f; + const int input_zero_point = 0; + const float output_scale = 0.5; + const int output_zero_point = 32; + int16_t output_quantized[length]; + int16_t values_quantized[length]; + int16_t input_quantized[length]; + tflite::testing::TestRequantize(dims, values, input_quantized, input_scale, + input_zero_point, dims, values, + values_quantized, output_scale, + output_zero_point, output_quantized); +} + +TF_LITE_MICRO_TEST(QuantizeOpTestInt16toInt16NoZeroPoint) +{ + const int length = 10; + int dims[] = { 2, 2, 5 }; + const float values[] = { -32, -31, -30, -29, -28, 27, 28, 29, 30, 31 }; + const float input_scale = 1.f; + const int input_zero_point = 0; + const float output_scale = 0.5; + const int output_zero_point = 0; + int16_t output_quantized[length]; + int16_t values_quantized[length]; + int16_t input_quantized[length]; + tflite::testing::TestRequantize(dims, values, input_quantized, input_scale, + input_zero_point, dims, values, + values_quantized, output_scale, + output_zero_point, output_quantized); +} + +TF_LITE_MICRO_TEST(QuantizeOpTestInt8toInt8) +{ + const int length = 10; + int dims[] = { 2, 2, 5 }; + const float values[] = { -64, -62, -60, -58, -56, 54, 56, 58, 60, 62 }; + const float input_scale = 2.f; + const int input_zero_point = 0; + const float output_scale = 0.5; + const int output_zero_point = 32; + int8_t output_quantized[length]; + int8_t values_quantized[length]; + int8_t input_quantized[length]; + tflite::testing::TestRequantize(dims, values, input_quantized, input_scale, + input_zero_point, dims, values, + values_quantized, output_scale, + output_zero_point, output_quantized); +} + +TF_LITE_MICRO_TEST(QuantizeOpTestInt8toInt8NoZeroPoint) +{ + const int length = 10; + int dims[] = { 2, 2, 5 }; + const float values[] = { -32, -31, -30, -29, -28, 27, 28, 29, 30, 31 }; + const float input_scale = 1.f; + const int input_zero_point = 0; + const float output_scale = 0.5; + const int output_zero_point = 0; + int8_t output_quantized[length]; + int8_t values_quantized[length]; + int8_t input_quantized[length]; + tflite::testing::TestRequantize(dims, values, input_quantized, input_scale, + input_zero_point, dims, values, + values_quantized, output_scale, + output_zero_point, output_quantized); +} +#endif // defined(XTENSA) + +#if !defined(XTENSA) +// TODO(b/155682734): Hifimini optimized quantize requires input scale to be +// smaller then output scale. +TF_LITE_MICRO_TEST(QuantizeOpTestInt16toInt8) +{ + const int length = 10; + int dims[] = { 2, 2, 5 }; + const float values[] = { -64, -62, -60, -58, -56, 54, 56, 58, 60, 62 }; + const float input_scale = 2.f; + const int input_zero_point = 0; + const float output_scale = 0.5; + const int output_zero_point = 0; + int8_t output_quantized[length]; + int8_t values_quantized[length]; + int16_t input_quantized[length]; + tflite::testing::TestRequantize(dims, values, input_quantized, input_scale, + input_zero_point, dims, values, + values_quantized, output_scale, + output_zero_point, output_quantized); +} +#endif // defined(XTENSA) + +TF_LITE_MICRO_TEST(QuantizeOpTestInt8toInt32) +{ + const int length = 10; + int dims[] = { 2, 2, 5 }; + const float values[] = { -32, -31, -30, -29, -28, 27, 28, 29, 30, 31 }; + const float input_scale = 1.f; + const int input_zero_point = 0; + const float output_scale = 0.5; + const int output_zero_point = 0; + int32_t output_quantized[length]; + int32_t values_quantized[length]; + int8_t input_quantized[length]; + tflite::testing::TestRequantize(dims, values, input_quantized, input_scale, + input_zero_point, dims, values, + values_quantized, output_scale, + output_zero_point, output_quantized); +} + +TF_LITE_MICRO_TEST(QuantizeOpTestInt16toInt32) +{ + const int length = 10; + int dims[] = { 2, 2, 5 }; + const float values[] = { -32, -31, -30, -29, -28, 27, 28, 29, 30, 31 }; + const float input_scale = 1.f; + const int input_zero_point = 0; + const float output_scale = 0.5; + const int output_zero_point = 0; + int32_t output_quantized[length]; + int32_t values_quantized[length]; + int16_t input_quantized[length]; + tflite::testing::TestRequantize(dims, values, input_quantized, input_scale, + input_zero_point, dims, values, + values_quantized, output_scale, + output_zero_point, output_quantized); +} + +TF_LITE_MICRO_TEST(QuantizeOpTestInt16toInt8) +{ + constexpr int length = 10; + int dims[] = { 2, 2, 5 }; + const float values[] = { -32, -31, -30, -29, -28, 27, 28, 29, 30, 31 }; + // TODO(b/155682734): Input scale must be smaller than output scale for + // xtensa. + const float input_scale = 0.4f; + const int input_zero_point = 0; + const float output_scale = 1.0f; + const int output_zero_point = 0; + int8_t output_quantized[length]; + int8_t values_quantized[length]; + int16_t input_quantized[length]; + tflite::testing::TestRequantize(dims, values, input_quantized, input_scale, + input_zero_point, dims, values, + values_quantized, output_scale, + output_zero_point, output_quantized); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/reduce.cc b/components/tflite/tensorflow/lite/micro/kernels/reduce.cc new file mode 100644 index 00000000..2d61c2f7 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/reduce.cc @@ -0,0 +1,351 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/reduce.h" + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/integer_ops/mean.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/internal/types.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/micro_utils.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace reduce { + +constexpr int kMaxNumberOfAxis = 4; +constexpr int kMaxNumberOfReducedAxis = 2; + +struct OpData { + int32_t multiplier; + int shift; + int temp_buffer_idx; + int resolved_axis_idx; + int input_zp; + float input_scale; + int output_zp; + float output_scale; + int num_output_elements; +}; + +void *InitReduce(TfLiteContext *context, const char *buffer, size_t length) +{ + return context->AllocatePersistentBuffer(context, sizeof(OpData)); +} + +TfLiteStatus PrepareSimple(TfLiteContext *context, TfLiteNode *node) +{ + // Inputs Tensor (dtype depends on quantization): + // [0] = Input + // [1] = Axis + const TfLiteTensor *input = GetInput(context, node, 0); + + // Outputs Tensor (dtype depends on quantization): + // [0] = Output + + // Validate number of inputs and outputs + TF_LITE_ENSURE_EQ(context, node->inputs->size, 2); + TF_LITE_ENSURE_EQ(context, node->outputs->size, 1); + + // Validate axis type + const TfLiteTensor *axis = GetInput(context, node, 1); + TF_LITE_ENSURE(context, axis != nullptr); + TF_LITE_ENSURE_TYPES_EQ(context, axis->type, kTfLiteInt32); + + if (input->type == kTfLiteInt8) { + OpData *data = static_cast(node->user_data); + const TfLiteTensor *output = GetOutput(context, node, 0); + const double real_multiplier = static_cast(input->params.scale) / + static_cast(output->params.scale); + QuantizeMultiplier(real_multiplier, &data->multiplier, &data->shift); + } + + return kTfLiteOk; +} + +TfLiteStatus PrepareMax(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE_OK(context, PrepareSimple(context, node)); + + OpData *op_data = static_cast(node->user_data); + const TfLiteTensor *input = GetInput(context, node, 0); + const TfLiteTensor *output = GetOutput(context, node, 0); + const TfLiteTensor *axis = GetInput(context, node, 1); + + op_data->input_scale = input->params.scale; + op_data->output_scale = output->params.scale; + op_data->num_output_elements = NumElements(output); + + context->RequestScratchBufferInArena(context, sizeof(int) * input->dims->size, + &op_data->temp_buffer_idx); + context->RequestScratchBufferInArena( + context, sizeof(int) * static_cast(ElementCount(*axis->dims)), + &op_data->resolved_axis_idx); + + return kTfLiteOk; +} + +TfLiteStatus PrepareMeanOrSum(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteTensor *input = GetInput(context, node, 0); + OpData *op_data = reinterpret_cast(node->user_data); + const TfLiteTensor *output = GetOutput(context, node, 0); + if (input->type == kTfLiteInt8) { + const double real_multiplier = static_cast(input->params.scale) / + static_cast(output->params.scale); + QuantizeMultiplier(real_multiplier, &op_data->multiplier, &op_data->shift); + } + + int output_size = NumElements(output); + if (input->type == kTfLiteInt8 || input->type == kTfLiteUInt8) { + context->RequestScratchBufferInArena(context, output_size * sizeof(int32_t), + &op_data->temp_buffer_idx); + op_data->input_zp = input->params.zero_point; + op_data->input_scale = input->params.scale; + op_data->output_zp = output->params.zero_point; + op_data->output_scale = output->params.scale; + } + + TF_LITE_ENSURE_OK(context, PrepareSimple(context, node)); + // TODO(b/144955155): Support uint8_t(b/144955155) and int8_t(b/144955018) + return kTfLiteOk; +} + +void ResolveAxis(const int *axis_data, int axis_count, + tflite::MeanParams *op_params) +{ + int i = 0; + for (; i < axis_count; ++i) { + op_params->axis[i] = static_cast(axis_data[i]); + } + for (; i < 4; ++i) { + op_params->axis[i] = 1; + } + op_params->axis_count = axis_count; +} + +TfLiteStatus EvalMean(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = tflite::micro::GetEvalInput(context, node, 0); + const TfLiteEvalTensor *axis = tflite::micro::GetEvalInput(context, node, 1); + TfLiteEvalTensor *output = tflite::micro::GetEvalOutput(context, node, 0); + TfLiteReducerParams *params = + reinterpret_cast(node->builtin_data); + OpData *op_data = reinterpret_cast(node->user_data); + + int num_axis = static_cast(ElementCount(*axis->dims)); + int temp_index[kMaxNumberOfAxis]; + int resolved_axis[kMaxNumberOfReducedAxis]; + + tflite::MeanParams op_params; + ResolveAxis(tflite::micro::GetTensorData(axis), num_axis, &op_params); + + // Special case mean implementation exists for 4D mean across axes 1 and 2. + bool special_case_4d_axes_1_and_2 = + input->dims->size == 4 && op_params.axis_count == 2 && + ((op_params.axis[0] == 1 && op_params.axis[1] == 2) || + (op_params.axis[0] == 2 && op_params.axis[1] == 1)); + + switch (input->type) { + case kTfLiteFloat32: { + // Defer to specialized implementation for 4D Mean across axes 1 & 2. + if (params->keep_dims && special_case_4d_axes_1_and_2) { + reference_ops::Mean(op_params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } else { + TF_LITE_ENSURE( + context, + reference_ops::Mean( + tflite::micro::GetTensorData(input), input->dims->data, + input->dims->size, tflite::micro::GetTensorData(output), + output->dims->data, output->dims->size, + tflite::micro::GetTensorData(axis), num_axis, + params->keep_dims, temp_index, resolved_axis, + tflite::micro::GetTensorData(output))); + } + } break; + case kTfLiteInt8: { + // Defer to specialized implementation for 4D Mean across axes 1 & 2. + if (params->keep_dims && special_case_4d_axes_1_and_2) { + reference_integer_ops::Mean( + op_params, op_data->multiplier, op_data->shift, + tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), op_data->input_zp, + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output), op_data->output_zp); + } else if (op_data->input_zp == op_data->output_zp && + op_data->input_scale == op_data->output_scale) { + int32_t *temp_buffer = static_cast( + context->GetScratchBuffer(context, op_data->temp_buffer_idx)); + TF_LITE_ENSURE( + context, + reference_ops::Mean( + tflite::micro::GetTensorData(input), input->dims->data, + input->dims->size, tflite::micro::GetTensorData(output), + output->dims->data, output->dims->size, + tflite::micro::GetTensorData(axis), num_axis, + params->keep_dims, temp_index, resolved_axis, temp_buffer)); + } else { + int32_t *temp_buffer = static_cast( + context->GetScratchBuffer(context, op_data->temp_buffer_idx)); + TF_LITE_ENSURE( + context, + reference_ops::QuantizedMeanOrSum( + tflite::micro::GetTensorData(input), op_data->input_zp, + op_data->input_scale, input->dims->data, input->dims->size, + tflite::micro::GetTensorData(output), + op_data->output_zp, op_data->output_scale, output->dims->data, + output->dims->size, tflite::micro::GetTensorData(axis), + num_axis, params->keep_dims, temp_index, resolved_axis, + temp_buffer, false)); + } + } break; + case kTfLiteUInt8: { + // Defer to specialized implementation for 4D Mean across axes 1 & 2. + if (params->keep_dims && special_case_4d_axes_1_and_2) { + reference_ops::Mean(op_params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + op_data->input_zp, op_data->input_scale, + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output), + op_data->output_zp, op_data->output_scale); + } else if (op_data->input_zp == op_data->output_zp && + op_data->input_scale == op_data->output_scale) { + uint32_t *temp_buffer = static_cast( + context->GetScratchBuffer(context, op_data->temp_buffer_idx)); + TF_LITE_ENSURE( + context, + reference_ops::Mean(tflite::micro::GetTensorData(input), + input->dims->data, input->dims->size, + tflite::micro::GetTensorData(output), + output->dims->data, output->dims->size, + tflite::micro::GetTensorData(axis), + num_axis, params->keep_dims, temp_index, + resolved_axis, temp_buffer)); + } else { + uint32_t *temp_buffer = static_cast( + context->GetScratchBuffer(context, op_data->temp_buffer_idx)); + TF_LITE_ENSURE( + context, + reference_ops::QuantizedMeanOrSum( + tflite::micro::GetTensorData(input), op_data->input_zp, + op_data->input_scale, input->dims->data, input->dims->size, + tflite::micro::GetTensorData(output), + op_data->output_zp, op_data->output_scale, output->dims->data, + output->dims->size, tflite::micro::GetTensorData(axis), + num_axis, params->keep_dims, temp_index, resolved_axis, + temp_buffer, false)); + } + } break; + default: + TF_LITE_ENSURE_MSG(context, false, + "Currently, only float32, int8 or uint8 input type " + "is supported."); + } + return kTfLiteOk; +} + +TfLiteStatus EvalMax(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = tflite::micro::GetEvalInput(context, node, 0); + const TfLiteEvalTensor *axis = tflite::micro::GetEvalInput(context, node, 1); + TfLiteEvalTensor *output = tflite::micro::GetEvalOutput(context, node, 0); + TF_LITE_ENSURE_TYPES_EQ(context, input->type, output->type); + TfLiteReducerParams *params = + static_cast(node->builtin_data); + OpData *op_data = static_cast(node->user_data); + + // Interpret an axis tensor with null dimensions as a scalar + int num_axis = static_cast(ElementCount(*axis->dims)); + int *temp_buffer = static_cast( + context->GetScratchBuffer(context, op_data->temp_buffer_idx)); + int *resolved_axis = static_cast( + context->GetScratchBuffer(context, op_data->resolved_axis_idx)); + switch (input->type) { + case kTfLiteFloat32: + TF_LITE_ENSURE( + context, + reference_ops::ReduceGeneric( + tflite::micro::GetTensorData(input), input->dims->data, + input->dims->size, tflite::micro::GetTensorData(output), + output->dims->data, output->dims->size, + tflite::micro::GetTensorData(axis), num_axis, + params->keep_dims, temp_buffer, resolved_axis, + std::numeric_limits::lowest(), + [](const float current, const float in) -> float { + return (in > current) ? in : current; + })); + break; + case kTfLiteInt8: + TF_LITE_ENSURE_EQ(context, static_cast(op_data->input_scale), + static_cast(op_data->output_scale)); + TF_LITE_ENSURE_EQ(context, op_data->input_zp, op_data->output_zp); + TF_LITE_ENSURE( + context, + reference_ops::ReduceGeneric( + tflite::micro::GetTensorData(input), input->dims->data, + input->dims->size, tflite::micro::GetTensorData(output), + output->dims->data, output->dims->size, + tflite::micro::GetTensorData(axis), num_axis, + params->keep_dims, temp_buffer, resolved_axis, + std::numeric_limits::lowest(), + [](const int8_t current, const int8_t in) -> int8_t { + return (in > current) ? in : current; + })); + break; + default: + TF_LITE_KERNEL_LOG(context, + "Only float32 and int8 types are supported.\n"); + return kTfLiteError; + } + return kTfLiteOk; +} + +} // namespace reduce + +TfLiteRegistration Register_MEAN() +{ + return { /*init=*/reduce::InitReduce, + /*free=*/nullptr, + /*prepare=*/reduce::PrepareMeanOrSum, + /*invoke=*/reduce::EvalMean, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +TfLiteRegistration Register_REDUCE_MAX() +{ + return { /*init=*/reduce::InitReduce, + /*free=*/nullptr, + /*prepare=*/reduce::PrepareMax, + /*invoke=*/reduce::EvalMax, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/reduce_test.cc b/components/tflite/tensorflow/lite/micro/kernels/reduce_test.cc new file mode 100644 index 00000000..cc4c5242 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/reduce_test.cc @@ -0,0 +1,644 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +// Common 2D inputs, outputs and axis. +static const int kInputElements2D = 8; +static int kInputShape2D[] = { 2, 2, 4 }; +static const float kInputData2D[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + +static int kAxisShape2D[] = { 1, 1 }; +static const int32_t kAxisData2D[] = { 1 }; + +static const int kOutputElements2D = 2; +static int kOutputShape2D[] = { 2, 1, 2 }; +static const float kGoldenData2D[] = { 2.5, 6.5 }; + +// Common 3D inputs, outputs and axis. +static const int kInputElements3D = 8; +static int kInputShape3D[] = { 3, 2, 2, 2 }; +static const float kInputData3D[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + +static int kAxisShape3D[] = { 1, 2 }; +static const int32_t kAxisData3D[] = { 1, 2 }; + +static const int kOutputElements3D = 2; +static int kOutputShape3D[] = { 2, 1, 2 }; +static const float kGoldenData3D[] = { 2.5, 6.5 }; + +// Common 4D inputs, outputs and axis. +static const int kInputElements4D = 24; +static int kInputShape4D[] = { 4, 2, 2, 3, 2 }; +static const float kInputData4D[] = { + 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, + 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0 +}; + +static int kAxisShape4D[] = { 1, 2 }; +static const int32_t kAxisData4D[] = { 1, 2 }; + +static const int kOutputElements4D = 4; +static int kOutputShape4D[] = { 4, 2, 1, 1, 2 }; +static const float kGoldenData4D[] = { 6, 7, 18, 19 }; + +// Axis shape and contents are independent of input / output dimensions. + +template +TfLiteStatus ValidateReduceGoldens(TfLiteTensor *tensors, int tensors_size, + const T *expected_output_data, + T *output_data, int output_length, + const TfLiteRegistration ®istration, + TfLiteReducerParams *params, + float tolerance = 1e-5) +{ + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, params); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_length; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output_data[i], output_data[i], + tolerance); + } + return kTfLiteOk; +} + +void TestMeanFloatInput4D(int *input_dims_data, const float *input_data, + int *axis_dims_data, const int32_t *axis_data, + int *output_dims_data, + const float *expected_output_data, float *output_data, + TfLiteReducerParams *params, float tolerance = 1e-5) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *axis_dims = IntArrayFromInts(axis_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + const TfLiteRegistration registration = tflite::ops::micro::Register_MEAN(); + + constexpr int num_of_inputs = 2; // input and axis + constexpr int num_of_outputs = 1; // output + + constexpr int tensors_size = num_of_inputs + num_of_outputs; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(axis_data, axis_dims), + CreateTensor(output_data, output_dims), + }; + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, ValidateReduceGoldens( + tensors, tensors_size, expected_output_data, output_data, + output_dims_count, registration, params, tolerance)); +} + +void TestReduceOpFloat(int *input_dims_data, const float *input_data, + int *axis_dims_data, const int32_t *axis_data, + int *output_dims_data, float *output_data, + const float *expected_output_data, + const TfLiteRegistration ®istration, + TfLiteReducerParams *params, float tolerance = 1e-5) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *axis_dims = IntArrayFromInts(axis_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int num_of_inputs = 2; // input and axis + constexpr int num_of_outputs = 1; // output + + constexpr int tensors_size = num_of_inputs + num_of_outputs; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(axis_data, axis_dims), + CreateTensor(output_data, output_dims), + }; + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, ValidateReduceGoldens( + tensors, tensors_size, expected_output_data, output_data, + output_dims_count, registration, params, tolerance)); +} + +template +void TestReduceOpQuantized(int *input_dims_data, const float *input_data, + T *input_data_quant, float input_scale, + int input_zero_point, int *axis_dims_data, + const int32_t *axis_data, int *output_dims_data, + const float *expected_output_data, + T *output_data_quant, T *expected_output_data_quant, + float output_scale, int output_zero_point, + const TfLiteRegistration ®istration, + TfLiteReducerParams *params) +{ + // Convert dimesion arguments to TfLiteArrays + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *axis_dims = IntArrayFromInts(axis_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + + // Get number of elements in input and output tensors + const int output_dims_count = ElementCount(*output_dims); + + // Initialize tensors + constexpr int tensors_size = 3; + TfLiteTensor tensors[] = { + CreateQuantizedTensor(input_data, input_data_quant, input_dims, + input_scale, input_zero_point), + CreateTensor(axis_data, axis_dims), + CreateQuantizedTensor(output_data_quant, output_dims, output_scale, + output_zero_point), + }; + + // Quantize expected output + tflite::Quantize(expected_output_data, expected_output_data_quant, + output_dims_count, output_scale, output_zero_point); + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, + ValidateReduceGoldens(tensors, tensors_size, expected_output_data_quant, + output_data_quant, output_dims_count, registration, + params, 0.01)); +} + +template +void TestMeanOpQuantized(int *input_dims_data, const float *input_data, + T *input_data_quant, float input_scale, + int input_zero_point, int *axis_dims_data, + const int32_t *axis_data, int *output_dims_data, + const float *expected_output_data, + T *output_data_quant, T *expected_output_data_quant, + float output_scale, int output_zero_point, + TfLiteReducerParams *params) +{ + // Convert dimesion arguments to TfLiteArrays + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *axis_dims = IntArrayFromInts(axis_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + + // Get number of elements in input and output tensors + const int output_dims_count = ElementCount(*output_dims); + + // Initialize tensors + constexpr int tensors_size = 3; + TfLiteTensor tensors[] = { + CreateQuantizedTensor(input_data, input_data_quant, input_dims, + input_scale, input_zero_point), + CreateTensor(axis_data, axis_dims), + CreateQuantizedTensor(output_data_quant, output_dims, output_scale, + output_zero_point), + }; + + // Quantize expected output + tflite::Quantize(expected_output_data, expected_output_data_quant, + output_dims_count, output_scale, output_zero_point); + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, + ValidateReduceGoldens(tensors, tensors_size, expected_output_data_quant, + output_data_quant, output_dims_count, + tflite::ops::micro::Register_MEAN(), params, 1.0)); +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(MeanFloat2DKeepDims) +{ + float output_data[tflite::testing::kOutputElements2D]; + + TfLiteReducerParams params = { true }; + + tflite::testing::TestMeanFloatInput4D( + tflite::testing::kInputShape2D, tflite::testing::kInputData2D, + tflite::testing::kAxisShape2D, tflite::testing::kAxisData2D, + tflite::testing::kOutputShape2D, tflite::testing::kGoldenData2D, + output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(MeanInt82DKeepDims) +{ + int8_t expected_output_data_quant[tflite::testing::kOutputElements2D]; + int8_t output_data_quant[tflite::testing::kOutputElements2D]; + int8_t input_data_quant[tflite::testing::kInputElements2D]; + + float input_scale = 0.5f; + int input_zero_point = 0; + float output_scale = 0.5f; + int output_zero_point = 0; + + TfLiteReducerParams params = { + true // keep_dims + }; + + tflite::testing::TestMeanOpQuantized( + tflite::testing::kInputShape2D, tflite::testing::kInputData2D, + input_data_quant, input_scale, input_zero_point, + tflite::testing::kAxisShape2D, tflite::testing::kAxisData2D, + tflite::testing::kOutputShape2D, tflite::testing::kGoldenData2D, + output_data_quant, expected_output_data_quant, output_scale, + output_zero_point, ¶ms); +} + +TF_LITE_MICRO_TEST(MeanUInt82DKeepDims) +{ + uint8_t expected_output_data_quant[tflite::testing::kOutputElements2D]; + uint8_t output_data_quant[tflite::testing::kOutputElements2D]; + uint8_t input_data_quant[tflite::testing::kInputElements2D]; + + float input_scale = 0.5f; + int input_zero_point = 128; + float output_scale = 0.5f; + int output_zero_point = 128; + + TfLiteReducerParams params = { + true // keep_dims + }; + + tflite::testing::TestMeanOpQuantized( + tflite::testing::kInputShape2D, tflite::testing::kInputData2D, + input_data_quant, input_scale, input_zero_point, + tflite::testing::kAxisShape2D, tflite::testing::kAxisData2D, + tflite::testing::kOutputShape2D, tflite::testing::kGoldenData2D, + output_data_quant, expected_output_data_quant, output_scale, + output_zero_point, ¶ms); +} + +TF_LITE_MICRO_TEST(MeanFloat3DKeepDims) +{ + float output_data[tflite::testing::kOutputElements3D]; + + TfLiteReducerParams params = { true }; + + tflite::testing::TestMeanFloatInput4D( + tflite::testing::kInputShape3D, tflite::testing::kInputData3D, + tflite::testing::kAxisShape3D, tflite::testing::kAxisData3D, + tflite::testing::kOutputShape3D, tflite::testing::kGoldenData3D, + output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(MeanInt83DKeepDims) +{ + int8_t expected_output_data_quant[tflite::testing::kOutputElements3D]; + int8_t output_data_quant[tflite::testing::kOutputElements3D]; + int8_t input_data_quant[tflite::testing::kInputElements3D]; + + float input_scale = 0.5f; + int input_zero_point = 0; + float output_scale = 0.5f; + int output_zero_point = 0; + + TfLiteReducerParams params = { + true // keep_dims + }; + + tflite::testing::TestMeanOpQuantized( + tflite::testing::kInputShape3D, tflite::testing::kInputData3D, + input_data_quant, input_scale, input_zero_point, + tflite::testing::kAxisShape3D, tflite::testing::kAxisData3D, + tflite::testing::kOutputShape3D, tflite::testing::kGoldenData3D, + output_data_quant, expected_output_data_quant, output_scale, + output_zero_point, ¶ms); +} + +TF_LITE_MICRO_TEST(MeanUInt83DKeepDims) +{ + uint8_t expected_output_data_quant[tflite::testing::kOutputElements3D]; + uint8_t output_data_quant[tflite::testing::kOutputElements3D]; + uint8_t input_data_quant[tflite::testing::kInputElements3D]; + + float input_scale = 0.5f; + int input_zero_point = 138; + float output_scale = 0.5f; + int output_zero_point = 138; + + TfLiteReducerParams params = { + true // keep_dims + }; + + tflite::testing::TestMeanOpQuantized( + tflite::testing::kInputShape3D, tflite::testing::kInputData3D, + input_data_quant, input_scale, input_zero_point, + tflite::testing::kAxisShape3D, tflite::testing::kAxisData3D, + tflite::testing::kOutputShape3D, tflite::testing::kGoldenData3D, + output_data_quant, expected_output_data_quant, output_scale, + output_zero_point, ¶ms); +} + +TF_LITE_MICRO_TEST(MeanFloat4DKeepDims) +{ + float output_data[tflite::testing::kOutputElements4D]; + + TfLiteReducerParams params = { + true // keep_dims + }; + + tflite::testing::TestMeanFloatInput4D( + tflite::testing::kInputShape4D, tflite::testing::kInputData4D, + tflite::testing::kAxisShape4D, tflite::testing::kAxisData4D, + tflite::testing::kOutputShape4D, tflite::testing::kGoldenData4D, + output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(MeanInt84DKeepDims) +{ + int8_t expected_output_data_quant[tflite::testing::kOutputElements4D]; + int8_t output_data_quant[tflite::testing::kOutputElements4D]; + int8_t input_data_quant[tflite::testing::kInputElements4D]; + + float input_scale = 0.5f; + int input_zero_point = 0; + float output_scale = 0.5f; + int output_zero_point = 0; + + TfLiteReducerParams params = { + true // keep_dims + }; + + tflite::testing::TestMeanOpQuantized( + tflite::testing::kInputShape4D, tflite::testing::kInputData4D, + input_data_quant, input_scale, input_zero_point, + tflite::testing::kAxisShape4D, tflite::testing::kAxisData4D, + tflite::testing::kOutputShape4D, tflite::testing::kGoldenData4D, + output_data_quant, expected_output_data_quant, output_scale, + output_zero_point, ¶ms); +} + +TF_LITE_MICRO_TEST(MeanUInt84DKeepDims) +{ + uint8_t expected_output_data_quant[tflite::testing::kOutputElements4D]; + uint8_t output_data_quant[tflite::testing::kOutputElements4D]; + uint8_t input_data_quant[tflite::testing::kInputElements4D]; + + float input_scale = 0.5f; + int input_zero_point = 128; + float output_scale = 0.5f; + int output_zero_point = 128; + + TfLiteReducerParams params = { + true // keep_dims + }; + + tflite::testing::TestMeanOpQuantized( + tflite::testing::kInputShape4D, tflite::testing::kInputData4D, + input_data_quant, input_scale, input_zero_point, + tflite::testing::kAxisShape4D, tflite::testing::kAxisData4D, + tflite::testing::kOutputShape4D, tflite::testing::kGoldenData4D, + output_data_quant, expected_output_data_quant, output_scale, + output_zero_point, ¶ms); +} + +TF_LITE_MICRO_TEST(MeanFloat4DWithoutKeepDims) +{ + int kOutputShape4D[] = { 2, 2, 2 }; + float output_data[tflite::testing::kOutputElements4D]; + TfLiteReducerParams params = { + false // keep_dims + }; + + tflite::testing::TestMeanFloatInput4D( + tflite::testing::kInputShape4D, tflite::testing::kInputData4D, + tflite::testing::kAxisShape4D, tflite::testing::kAxisData4D, + kOutputShape4D, tflite::testing::kGoldenData4D, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(MeanInt84DWithoutKeepDims) +{ + int8_t expected_output_data_quant[tflite::testing::kOutputElements4D]; + int8_t output_data_quant[tflite::testing::kOutputElements4D]; + int8_t input_data_quant[tflite::testing::kInputElements4D]; + + int kOutputShape4D[] = { 2, 2, 2 }; + TfLiteReducerParams params = { + false // keep_dims + }; + float input_scale = 0.5f; + int input_zero_point = 0; + float output_scale = 0.5f; + int output_zero_point = 0; + + tflite::testing::TestMeanOpQuantized( + tflite::testing::kInputShape4D, tflite::testing::kInputData4D, + input_data_quant, input_scale, input_zero_point, + tflite::testing::kAxisShape4D, tflite::testing::kAxisData4D, + kOutputShape4D, tflite::testing::kGoldenData4D, output_data_quant, + expected_output_data_quant, output_scale, output_zero_point, ¶ms); +} + +TF_LITE_MICRO_TEST(MeanUInt84DWithoutKeepDims) +{ + uint8_t expected_output_data_quant[tflite::testing::kOutputElements4D]; + uint8_t output_data_quant[tflite::testing::kOutputElements4D]; + uint8_t input_data_quant[tflite::testing::kInputElements4D]; + + int kOutputShape4D[] = { 2, 2, 2 }; + TfLiteReducerParams params = { + false // keep_dims + }; + float input_scale = 0.5f; + int input_zero_point = 128; + float output_scale = 0.5f; + int output_zero_point = 128; + + tflite::testing::TestMeanOpQuantized( + tflite::testing::kInputShape4D, tflite::testing::kInputData4D, + input_data_quant, input_scale, input_zero_point, + tflite::testing::kAxisShape4D, tflite::testing::kAxisData4D, + kOutputShape4D, tflite::testing::kGoldenData4D, output_data_quant, + expected_output_data_quant, output_scale, output_zero_point, ¶ms); +} + +TF_LITE_MICRO_TEST(MeanFloat4DWithoutKeepDimsWithPrecision) +{ + int kInputShape4D[] = { 4, 2, 2, 3, 1 }; + const float kInputData4D[] = { 1.0, 24.0, 13.0, 3.0, 9.0, 17.0, + 11.0, 36.0, 14.0, 19.0, 17.0, 22.0 }; + const int kOutputElements4D = 2; + int kOutputShape4D[] = { 2, 2, 1 }; + const float kGoldenData4D[] = { 11.166667, 19.833334 }; + float output_data[kOutputElements4D]; + TfLiteReducerParams params = { + false // keep_dims + }; + + tflite::testing::TestMeanFloatInput4D( + kInputShape4D, kInputData4D, tflite::testing::kAxisShape4D, + tflite::testing::kAxisData4D, kOutputShape4D, kGoldenData4D, output_data, + ¶ms); +} + +TF_LITE_MICRO_TEST(FloatMaxOpTestNotKeepDims) +{ + int input_shape[] = { 3, 4, 3, 2 }; + const float input_data[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, + 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, + 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0 }; + int axis_shape[] = { 1, 4 }; + const int32_t axis_data[] = { 1, 0, -3, -3 }; + int output_shape[] = { 1, 2 }; + const float expected_output_data[] = { 23, 24 }; + float output_data[2]; + + TfLiteReducerParams params = { false }; + + tflite::testing::TestReduceOpFloat( + input_shape, input_data, axis_shape, axis_data, output_shape, output_data, + expected_output_data, tflite::ops::micro::Register_REDUCE_MAX(), ¶ms); +} + +TF_LITE_MICRO_TEST(FloatMaxOpTestKeepDims) +{ + int input_shape[] = { 3, 4, 3, 2 }; + const float input_data[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, + 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, + 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0 }; + int axis_shape[] = { 1, 2 }; + const int32_t axis_data[] = { 0, 2 }; + int output_shape[] = { 1, 3 }; + const float expected_output_data[] = { 20, 22, 24 }; + float output_data[3]; + + TfLiteReducerParams params = { true }; + + tflite::testing::TestReduceOpFloat( + input_shape, input_data, axis_shape, axis_data, output_shape, output_data, + expected_output_data, tflite::ops::micro::Register_REDUCE_MAX(), ¶ms); +} + +TF_LITE_MICRO_TEST(Int8MaxOpTestKeepDims) +{ + int input_shape[] = { 3, 1, 3, 2 }; + const float input_data[] = { 0.4, 0.2, 0.3, 0.4, 0.5, 0.6 }; + int axis_shape[] = { 1, 1 }; + const int32_t axis_data[] = { 1, 1 }; + int output_shape[] = { 1, 2 }; + const float expected_output_data[] = { 0.5, 0.6 }; + + float input_scale = 2 / 255.0; + int input_zp = 0; + + TfLiteReducerParams params = { true }; + + int8_t input_data_quant[6]; + int8_t output_data_quant[2]; + int8_t expected_output_data_quant[2]; + + tflite::testing::TestReduceOpQuantized( + input_shape, input_data, input_data_quant, input_scale, input_zp, + axis_shape, axis_data, output_shape, expected_output_data, + output_data_quant, expected_output_data_quant, input_scale, input_zp, + tflite::ops::micro::Register_REDUCE_MAX(), ¶ms); +} + +TF_LITE_MICRO_TEST(Int8MaxOpTestWithoutKeepDims) +{ + int input_shape[] = { 3, 1, 3, 2 }; + const float input_data[] = { 0.4, 0.2, 0.3, 0.4, 0.5, 0.6 }; + int axis_shape[] = { 1, 1 }; + const int32_t axis_data[] = { 1, 1 }; + int output_shape[] = { 1, 2 }; + const float expected_output_data[] = { 0.5, 0.6 }; + + float input_scale = 2 / 255.0; + int input_zp = 0; + float output_scale = 2 / 255.0; + int output_zp = 0; + + TfLiteReducerParams params = { false }; + + int8_t input_data_quant[6]; + int8_t output_data_quant[2]; + int8_t expected_output_data_quant[2]; + + tflite::testing::TestReduceOpQuantized( + input_shape, input_data, input_data_quant, input_scale, input_zp, + axis_shape, axis_data, output_shape, expected_output_data, + output_data_quant, expected_output_data_quant, output_scale, output_zp, + tflite::ops::micro::Register_REDUCE_MAX(), ¶ms); +} + +TF_LITE_MICRO_TEST(MeanInt84DWithoutKeepDimsWithPrecision) +{ + int kInputShape4D[] = { 4, 2, 2, 3, 1 }; + const float kInputData4D[] = { 1.0, 24.0, 13.0, 3.0, 9.0, 17.0, + 11.0, 36.0, 14.0, 19.0, 17.0, 22.0 }; + int kOutputShape4D[] = { 2, 2, 1 }; + const float kGoldenData4D[] = { 11.166667, 19.833334 }; + TfLiteReducerParams params = { + false // keep_dims + }; + float input_scale = 0.5f; + int input_zero_point = 0; + float output_scale = 0.5f; + int output_zero_point = 0; + + int8_t output_data_quant[2]; + int8_t expected_output_data_quant[2]; + int8_t input_data_quant[12]; + + tflite::testing::TestMeanOpQuantized( + kInputShape4D, kInputData4D, input_data_quant, input_scale, + input_zero_point, tflite::testing::kAxisShape4D, + tflite::testing::kAxisData4D, kOutputShape4D, kGoldenData4D, + output_data_quant, expected_output_data_quant, output_scale, + output_zero_point, ¶ms); +} + +TF_LITE_MICRO_TEST(MeanUInt84DWithoutKeepDimsWithPrecision) +{ + int kInputShape4D[] = { 4, 2, 2, 3, 1 }; + const float kInputData4D[] = { 1.0, 24.0, 13.0, 3.0, 9.0, 17.0, + 11.0, 36.0, 14.0, 19.0, 17.0, 22.0 }; + int kOutputShape4D[] = { 2, 2, 1 }; + const float kGoldenData4D[] = { 11.166667, 19.833334 }; + TfLiteReducerParams params = { + false // keep_dims + }; + + float input_scale = 0.5f; + int input_zero_point = 128; + float output_scale = 0.5f; + int output_zero_point = 128; + + uint8_t output_data_quant[2]; + uint8_t expected_output_data_quant[2]; + uint8_t input_data_quant[12]; + + tflite::testing::TestMeanOpQuantized( + kInputShape4D, kInputData4D, input_data_quant, input_scale, + input_zero_point, tflite::testing::kAxisShape4D, + tflite::testing::kAxisData4D, kOutputShape4D, kGoldenData4D, + output_data_quant, expected_output_data_quant, output_scale, + output_zero_point, ¶ms); +} +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/reshape.cc b/components/tflite/tensorflow/lite/micro/kernels/reshape.cc new file mode 100644 index 00000000..656bd45f --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/reshape.cc @@ -0,0 +1,122 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/memory_helpers.h" +#include "tensorflow/lite/micro/micro_utils.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace reshape { + +constexpr int kInputTensor = 0; +constexpr int kOutputTensor = 0; + +TfLiteStatus ReshapeOutput(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteTensor *input = GetInput(context, node, kInputTensor); + TF_LITE_ENSURE(context, input != nullptr); + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + // Tensorflow's Reshape allows one of the shape components to have the + // special -1 value, meaning it will be calculated automatically based on the + // input. Here we calculate what that dimension should be so that the number + // of output elements in the same as the number of input elements. + int num_input_elements = NumElements(input); + TfLiteIntArray *output_shape = output->dims; + + if (NumInputs(node) == 1 && // Legacy scalar supported with params. + output_shape->size == 1 && output_shape->data[0] == 0) { + // Legacy tflite models use a shape parameter of [0] to indicate scalars, + // so adjust accordingly. TODO(b/111614235): Allow zero-sized buffers during + // toco conversion. + output_shape->size = 0; + } + + int num_output_elements = 1; + int stretch_dim = -1; + for (int i = 0; i < output_shape->size; ++i) { + int value = output_shape->data[i]; + if (value == -1) { + TF_LITE_ENSURE_EQ(context, stretch_dim, -1); + stretch_dim = i; + } else { + num_output_elements *= value; + } + } + if (stretch_dim != -1) { + output_shape->data[stretch_dim] = num_input_elements / num_output_elements; + num_output_elements *= output_shape->data[stretch_dim]; + } + + TF_LITE_ENSURE_TYPES_EQ(context, input->type, output->type); + TF_LITE_ENSURE_EQ(context, num_input_elements, num_output_elements); + return kTfLiteOk; +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE(context, NumInputs(node) == 1 || NumInputs(node) == 2); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + TF_LITE_ENSURE_EQ(context, ReshapeOutput(context, node), kTfLiteOk); + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + // TODO(b/162522304): storing input bytes in OpData increases some models + // significantly, possibly due to alignment issues. + size_t input_bytes; + TF_LITE_ENSURE_STATUS(TfLiteTypeSizeOf(input->type, &input_bytes)); + input_bytes *= ElementCount(*input->dims); + + // Do nothing for in-place reshape. + if (input->data.raw != output->data.raw) { + // Otherwise perform reshape with copy. + for (size_t i = 0; i < input_bytes; ++i) { + output->data.raw[i] = input->data.raw[i]; + } + } + return kTfLiteOk; +} + +} // namespace reshape + +TfLiteRegistration Register_RESHAPE() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/reshape::Prepare, + /*invoke=*/reshape::Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/reshape_test.cc b/components/tflite/tensorflow/lite/micro/kernels/reshape_test.cc new file mode 100644 index 00000000..b0fc2532 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/reshape_test.cc @@ -0,0 +1,388 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/micro_utils.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +// TODO(b/162356196): Cleanup this unit test more. + +template +void ValidateReshapeGoldens(TfLiteTensor *tensors, int tensors_size, + TfLiteIntArray *inputs_array, + TfLiteIntArray *outputs_array, + const T *expected_output, + const size_t expected_output_len, + int *expected_dims, const size_t expected_dims_len, + bool expect_failure) +{ + const TfLiteRegistration registration = + tflite::ops::micro::Register_RESHAPE(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + if (expect_failure) { + TF_LITE_MICRO_EXPECT_NE(kTfLiteOk, runner.InitAndPrepare()); + return; + } + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + TfLiteTensor *output_tensor = &tensors[outputs_array->data[0]]; + const T *output_data = GetTensorData(output_tensor); + for (size_t i = 0; i < expected_output_len; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output[i], output_data[i], 1e-5f); + } + TF_LITE_MICRO_EXPECT_EQ(expected_dims_len, + static_cast(output_tensor->dims->size)); + for (size_t i = 0; i < expected_dims_len; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_dims[i], output_tensor->dims->data[i]); + } +} +template +void TestReshapeWithShape(TfLiteTensor *input_tensor, + TfLiteTensor *shape_tensor, + TfLiteTensor *output_tensor, const T *expected_output, + const size_t expected_output_len, int *expected_dims, + const size_t expected_dims_len, bool expect_failure) +{ + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size]; + tensors[0] = *input_tensor; + tensors[1] = *shape_tensor; + tensors[2] = *output_tensor; + + int inputs_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_data); + int outputs_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_data); + + ValidateReshapeGoldens(tensors, tensors_size, inputs_array, outputs_array, + expected_output, expected_output_len, expected_dims, + expected_dims_len, expect_failure); +} + +// If expected output is empty, the test is expected to fail. +template +void TestReshapeWithoutShape(TfLiteTensor *input_tensor, + TfLiteTensor *output_tensor, + const T *expected_output, + const size_t expected_output_len, + int *expected_dims, const size_t expected_dims_len, + bool expect_failure) +{ + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size]; + tensors[0] = *input_tensor; + tensors[1] = *output_tensor; + + int inputs_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_data); + int outputs_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_data); + + ValidateReshapeGoldens(tensors, tensors_size, inputs_array, outputs_array, + expected_output, expected_output_len, expected_dims, + expected_dims_len, expect_failure); +} + +void TestReshape(int *input_dims_data, const float *input_data, + int *shape_dims_data, const int32_t *shape_data, + int *output_dims_data, float *output_data, + const float *expected_output, const size_t expected_output_len, + int *expected_dims, const size_t expected_dims_len, + bool expect_failure = false) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *shape_dims = IntArrayFromInts(shape_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + TfLiteTensor input_tensor = CreateTensor(input_data, input_dims); + TfLiteTensor shape_tensor = CreateTensor(shape_data, shape_dims); + TfLiteTensor output_tensor = CreateTensor(output_data, output_dims); + + TestReshapeWithShape(&input_tensor, &shape_tensor, &output_tensor, + expected_output, expected_output_len, expected_dims, + expected_dims_len, expect_failure); +} + +template +void TestReshapeQuantized(int *input_dims_data, const T *input_data, + int *shape_dims_data, const int32_t *shape_data, + int *output_dims_data, T *output_data, + const T *expected_output, + const size_t expected_output_len, int *expected_dims, + const size_t expected_dims_len, + bool expect_failure = false) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *shape_dims = IntArrayFromInts(shape_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + TfLiteTensor input_tensor = CreateQuantizedTensor( + input_data, input_dims, /*scale=*/1.f, /*zero_point=*/0); + TfLiteTensor shape_tensor = CreateTensor(shape_data, shape_dims); + TfLiteTensor output_tensor = CreateQuantizedTensor( + output_data, output_dims, /*scale=*/1.f, /*zero_point=*/0); + + TestReshapeWithShape(&input_tensor, &shape_tensor, &output_tensor, + expected_output, expected_output_len, expected_dims, + expected_dims_len, expect_failure); +} +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(ReshapeWithMismatchedDimensionsShouldFail) +{ + float output_data[32]; + int input_dims[] = { 4, 1, 2, 4, 1 }; + const float input_data[] = { 3 }; + int shape_dims[] = { 1, 2 }; + const int32_t shape_int32[] = { 2, 1 }; + int output_dims[] = { 2, 2, 1 }; + const int golden_output_len = 0; + const float golden_output[] = {}; + const int golden_dims_len = 0; + int golden_dims[] = {}; + tflite::testing::TestReshape( + input_dims, input_data, shape_dims, shape_int32, output_dims, output_data, + golden_output, golden_output_len, golden_dims, golden_dims_len, true); +} + +TF_LITE_MICRO_TEST(ReshapeWithTooManyDimensionsShouldFail) +{ + float output_data[32]; + int input_dims[] = { 9, 1, 1, 2, 1, 1, 1, 1, 1, 1 }; + const float input[] = { 3, 2 }; + int shape_dims[] = { 1, 9 }; + const int32_t shape_int32[] = { 1, 1, 1, 1, 1, 1, 1, 1, 2 }; + int output_dims[] = { 9, 1, 1, 1, 1, 1, 1, 1, 1, 2 }; + const int golden_output_len = 2; + const float golden_output[] = { 3, 2 }; + const int golden_dims_len = 9; + int golden_dims[] = { 1, 1, 1, 1, 1, 1, 1, 1, 2 }; + tflite::testing::TestReshape( + input_dims, input, shape_dims, shape_int32, output_dims, output_data, + golden_output, golden_output_len, golden_dims, golden_dims_len, false); +} + +TF_LITE_MICRO_TEST(ReshapeWithTooManySpecialDimensionsShouldFail) +{ + float output_data[32]; + int input_dims[] = { 4, 1, 2, 4, 11 }; + const float input[] = { 3 }; + int shape_dims[] = { 1, 4 }; + const int32_t shape_int32[] = { -1, -1, 2, 4 }; + int output_dims[] = { 4, -1, -1, 2, 4 }; + const int golden_output_len = 2; + const float golden_output[] = {}; + const int golden_dims_len = 9; + int golden_dims[] = {}; + tflite::testing::TestReshape( + input_dims, input, shape_dims, shape_int32, output_dims, output_data, + golden_output, golden_output_len, golden_dims, golden_dims_len, true); +} + +// Create the model with a 2x2 shape. Processing still works because the new +// shape ends up being hardcoded as a flat vector. +TF_LITE_MICRO_TEST(ReshapeWithInvalidShapeShouldFail) +{ + int input_dims_data[] = { 3, 1, 2, 2 }; + TfLiteIntArray *input_dims = + tflite::testing::IntArrayFromInts(input_dims_data); + const float input_data[] = { 3.0f }; + auto input_tensor = tflite::testing::CreateTensor(input_data, input_dims); + float output_data[4]; + int output_dims_data[6] = { 2, 2, 1, 2, 2, 1 }; + TfLiteIntArray *output_dims = + tflite::testing::IntArrayFromInts(output_dims_data); + auto output_tensor = tflite::testing::CreateTensor(output_data, output_dims); + const int expected_output[] = {}; + const int expected_output_len = 0; + int expected_dims[] = {}; + const int expected_dims_len = 0; + tflite::testing::TestReshapeWithoutShape( + &input_tensor, &output_tensor, expected_output, expected_output_len, + expected_dims, expected_dims_len, true); +} + +TF_LITE_MICRO_TEST(ReshapeWithRegularShapesShouldSucceed) +{ + float output_data_float[32]; + int8_t output_data_int8[32]; + uint8_t output_data_uint8[32]; + int16_t output_data_int16[32]; + int input_dims[] = { 4, 1, 2, 4, 1 }; + const float input_float[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + const int8_t input_int8[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + const uint8_t input_uint8[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + const int16_t input_int16[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + int shape_dims[] = { 1, 3 }; + const int32_t shape_int32[] = { 2, 2, 2 }; + int output_dims[] = { 3, 2, 2, 2 }; + const int golden_output_len = 8; + const float golden_output_float[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + const int8_t golden_output_int8[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + const uint8_t golden_output_uint8[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + const int16_t golden_output_int16[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + const int golden_dims_len = 3; + int golden_dims[] = { 2, 2, 2 }; + tflite::testing::TestReshape(input_dims, input_float, shape_dims, shape_int32, + output_dims, output_data_float, + golden_output_float, golden_output_len, + golden_dims, golden_dims_len, false); + tflite::testing::TestReshapeQuantized( + input_dims, input_int8, shape_dims, shape_int32, output_dims, + output_data_int8, golden_output_int8, golden_output_len, golden_dims, + golden_dims_len, false); + tflite::testing::TestReshapeQuantized( + input_dims, input_uint8, shape_dims, shape_int32, output_dims, + output_data_uint8, golden_output_uint8, golden_output_len, golden_dims, + golden_dims_len, false); + tflite::testing::TestReshapeQuantized( + input_dims, input_int16, shape_dims, shape_int32, output_dims, + output_data_int16, golden_output_int16, golden_output_len, golden_dims, + golden_dims_len, false); +} + +// Stretch is not supported with TF Micro +TF_LITE_MICRO_TEST(ReshapeWithStretchDimensionShouldSucceed) +{ + float output_data_float[32]; + int8_t output_data_int8[32]; + uint8_t output_data_uint8[32]; + int16_t output_data_int16[32]; + int input_dims[] = { 4, 1, 2, 4, 1 }; + const float input_float[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + const int8_t input_int8[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + const uint8_t input_uint8[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + const int16_t input_int16[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + int shape_dims[] = { 1, 3 }; + const int32_t shape_int32[] = { 2, 1, -1 }; + int output_dims[] = { 3, 2, 1, -1 }; + const int golden_output_len = 8; + const float golden_output_float[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + const int8_t golden_output_int8[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + const uint8_t golden_output_uint8[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + const int16_t golden_output_int16[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + const int golden_dims_len = 3; + int golden_dims[] = { 2, 1, 4 }; + tflite::testing::TestReshape(input_dims, input_float, shape_dims, shape_int32, + output_dims, output_data_float, + golden_output_float, golden_output_len, + golden_dims, golden_dims_len, false); + tflite::testing::TestReshapeQuantized( + input_dims, input_int8, shape_dims, shape_int32, output_dims, + output_data_int8, golden_output_int8, golden_output_len, golden_dims, + golden_dims_len, false); + tflite::testing::TestReshapeQuantized( + input_dims, input_uint8, shape_dims, shape_int32, output_dims, + output_data_uint8, golden_output_uint8, golden_output_len, golden_dims, + golden_dims_len, false); + tflite::testing::TestReshapeQuantized( + input_dims, input_int16, shape_dims, shape_int32, output_dims, + output_data_int16, golden_output_int16, golden_output_len, golden_dims, + golden_dims_len, false); +} + +// Empty shape indicates scalar output. +TF_LITE_MICRO_TEST(ReshapeWithScalarOutputShouldSucceed) +{ + float output_data_float[4]; + int8_t output_data_int8[4]; + uint8_t output_data_uint8[4]; + int input_dims[] = { 1, 1 }; + const float input_float[] = { 3 }; + const int8_t input_int8[] = { 3 }; + const uint8_t input_uint8[] = { 3 }; + int shape_dims[] = { 0 }; + const int32_t shape_int32[] = {}; + int output_dims[] = { 0 }; + const int golden_output_len = 1; + const float golden_output_float[] = { 3 }; + const int8_t golden_output_int8[] = { 3 }; + const uint8_t golden_output_uint8[] = { 3 }; + const int golden_dims_len = 0; + int golden_dims[] = {}; + tflite::testing::TestReshape(input_dims, input_float, shape_dims, shape_int32, + output_dims, output_data_float, + golden_output_float, golden_output_len, + golden_dims, golden_dims_len, false); + tflite::testing::TestReshapeQuantized( + input_dims, input_int8, shape_dims, shape_int32, output_dims, + output_data_int8, golden_output_int8, golden_output_len, golden_dims, + golden_dims_len, false); + tflite::testing::TestReshapeQuantized( + input_dims, input_uint8, shape_dims, shape_int32, output_dims, + output_data_uint8, golden_output_uint8, golden_output_len, golden_dims, + golden_dims_len, false); +} + +// Some old models specify '[0]' as the new shape, indicating that both input +// and output are scalars. +TF_LITE_MICRO_TEST(ReshapeWithLegacyScalarOutputShouldSucceed) +{ + using tflite::testing::CreateTensor; + using tflite::testing::IntArrayFromInts; + + int input_dims_data[] = { 1, 1 }; + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + const float input_data[] = { 3.0f }; + auto input_tensor = CreateTensor(input_data, input_dims); + + float output_data[1]; + int output_dims_data[2] = { 1, 0 }; + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + auto output_tensor = CreateTensor(output_data, output_dims); + + int shape_dims_data[] = { 1, 0 }; + TfLiteIntArray *shape_dims = IntArrayFromInts(shape_dims_data); + + const int32_t shape_data[] = { 0 }; + auto shape_tensor = tflite::testing::CreateTensor(shape_data, shape_dims); + const float expected_output_with_shape[] = {}; + const int expected_output_with_shape_len = 0; + const float expected_output_no_shape[] = { 3 }; + const int expected_output_no_shape_len = 1; + int expected_dims[] = {}; + const int expected_dims_len = 0; + tflite::testing::TestReshapeWithShape( + &input_tensor, &shape_tensor, &output_tensor, expected_output_with_shape, + expected_output_with_shape_len, expected_dims, expected_dims_len, true); + + tflite::testing::TestReshapeWithoutShape( + &input_tensor, &output_tensor, expected_output_no_shape, + expected_output_no_shape_len, expected_dims, expected_dims_len, false); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/resize_bilinear.cc b/components/tflite/tensorflow/lite/micro/kernels/resize_bilinear.cc new file mode 100644 index 00000000..7e5aadd8 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/resize_bilinear.cc @@ -0,0 +1,119 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/kernels/internal/reference/resize_bilinear.h" + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/micro_utils.h" + +namespace tflite { +namespace { + +constexpr int kInputTensor = 0; +constexpr int kSizeTensor = 1; +constexpr int kOutputTensor = 0; + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE_EQ(context, NumInputs(node), 2); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + + const TfLiteTensor *input = GetInput(context, node, kInputTensor); + const TfLiteTensor *size = GetInput(context, node, kSizeTensor); + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + + TF_LITE_ENSURE_EQ(context, NumDimensions(input), 4); + TF_LITE_ENSURE_EQ(context, NumDimensions(size), 1); + + TF_LITE_ENSURE_EQ(context, size->type, kTfLiteInt32); + output->type = input->type; + + TF_LITE_ENSURE_MSG(context, IsConstantTensor(size), + "Non constant size tensor not supported"); + + // Ensure params are valid. + auto *params = + reinterpret_cast(node->builtin_data); + if (params->half_pixel_centers && params->align_corners) { + TF_LITE_KERNEL_LOG( + context, "If half_pixel_centers is True, align_corners must be False."); + return kTfLiteError; + } + + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + auto *params = + reinterpret_cast(node->builtin_data); + + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + const TfLiteEvalTensor *size = + tflite::micro::GetEvalInput(context, node, kSizeTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + if (output->type == kTfLiteFloat32) { + tflite::ResizeBilinearParams op_params; + op_params.align_corners = params->align_corners; + op_params.half_pixel_centers = params->half_pixel_centers; + reference_ops::ResizeBilinear(op_params, + tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(size), + tflite::micro::GetTensorData(size), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } else if (output->type == kTfLiteInt8) { + tflite::ResizeBilinearParams op_params; + op_params.align_corners = params->align_corners; + op_params.half_pixel_centers = params->half_pixel_centers; + reference_ops::ResizeBilinearInteger( + op_params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(size), + tflite::micro::GetTensorData(size), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } else { + TF_LITE_KERNEL_LOG(context, "Output type is %d, requires float or int8.", + output->type); + return kTfLiteError; + } + + return kTfLiteOk; +} + +} // namespace + +TfLiteRegistration Register_RESIZE_BILINEAR() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/resize_bilinear_test.cc b/components/tflite/tensorflow/lite/micro/kernels/resize_bilinear_test.cc new file mode 100644 index 00000000..97eeaa11 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/resize_bilinear_test.cc @@ -0,0 +1,344 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +TfLiteTensor TestCreateTensor(const float *data, TfLiteIntArray *dims) +{ + return CreateTensor(data, dims); +} + +TfLiteTensor TestCreateTensor(const int8_t *data, TfLiteIntArray *dims) +{ + return CreateQuantizedTensor(data, dims, -128, 127); +} + +template +TfLiteStatus ValidateGoldens(TfLiteTensor *tensors, int tensors_size, + const T *expected_output_data, T *output_data, + int output_length, + TfLiteResizeBilinearParams *params, + float tolerance = 1e-5) +{ + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = Register_RESIZE_BILINEAR(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, params); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_length; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output_data[i], output_data[i], + tolerance); + } + + return kTfLiteOk; +} + +template +void TestResizeBilinear(int *input_dims_data, const T *input_data, + const int32_t *expected_size_data, + const T *expected_output_data, int *output_dims_data, + T *output_data, TfLiteResizeBilinearParams *params, + float tolerance = 1e-5) +{ + int expected_size_dims_data[] = { 1, 2 }; + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *expected_size_dims = + IntArrayFromInts(expected_size_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + + const int output_dims_count = ElementCount(*output_dims); + + // Hack to pass ConstantTensor check in prepare + TfLiteTensor t = CreateTensor(expected_size_data, expected_size_dims); + t.allocation_type = kTfLiteMmapRo; + + constexpr int tensors_size = 3; + TfLiteTensor tensors[tensors_size]{ + TestCreateTensor(input_data, input_dims), + t, + TestCreateTensor(output_data, output_dims), + }; + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, + ValidateGoldens(tensors, tensors_size, expected_output_data, output_data, + output_dims_count, params, tolerance)); +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(HorizontalResize) +{ + int input_dims[] = { 4, 1, 1, 2, 1 }; + const float input_data[] = { 3, 6 }; + const int32_t expected_size_data[] = { 1, 3 }; + const float expected_output_data[] = { 3, 5, 6 }; + int output_dims[] = { 4, 1, 1, 3, 1 }; + float output_data[3]; + + TfLiteResizeBilinearParams params = { + false, /*align_corners*/ + false /*half pixel centers*/ + }; + + tflite::testing::TestResizeBilinear(input_dims, input_data, + expected_size_data, expected_output_data, + output_dims, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(HorizontalResizeInt8) +{ + int input_dims[] = { 4, 1, 1, 2, 1 }; + const int8_t input_data[] = { 3, 6 }; + const int32_t expected_size_data[] = { 1, 3 }; + const int8_t expected_output_data[] = { 3, 5, 6 }; + int output_dims[] = { 4, 1, 1, 3, 1 }; + int8_t output_data[3]; + + TfLiteResizeBilinearParams params = { + false, /*align_corners*/ + false /*half pixel centers*/ + }; + + tflite::testing::TestResizeBilinear( + input_dims, input_data, expected_size_data, expected_output_data, + output_dims, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(VerticalResize) +{ + int input_dims[] = { 4, 1, 2, 1, 1 }; + const float input_data[] = { 3, 9 }; + const int32_t expected_size_data[] = { 3, 1 }; + const float expected_output_data[] = { 3, 7, 9 }; + int output_dims[] = { 4, 1, 3, 1, 1 }; + float output_data[3]; + + TfLiteResizeBilinearParams params = { + false, /*align_corners*/ + false /*half pixel centers*/ + }; + + tflite::testing::TestResizeBilinear(input_dims, input_data, + expected_size_data, expected_output_data, + output_dims, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(VerticalResizeInt8) +{ + int input_dims[] = { 4, 1, 2, 1, 1 }; + const int8_t input_data[] = { 3, 9 }; + const int32_t expected_size_data[] = { 3, 1 }; + const int8_t expected_output_data[] = { 3, 7, 9 }; + int output_dims[] = { 4, 1, 3, 1, 1 }; + int8_t output_data[3]; + + TfLiteResizeBilinearParams params = { + false, /*align_corners*/ + false /*half pixel centers*/ + }; + + tflite::testing::TestResizeBilinear( + input_dims, input_data, expected_size_data, expected_output_data, + output_dims, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(TwoDimensionalResize) +{ + int input_dims[] = { 4, 1, 2, 2, 1 }; + const float input_data[] = { + 3, 6, // + 9, 12, // + }; + const int32_t expected_size_data[] = { 3, 3 }; + const float expected_output_data[] = { + 3, 5, 6, // + 7, 9, 10, // + 9, 11, 12 // + }; + + int output_dims[] = { 4, 1, 3, 3, 1 }; + float output_data[9]; + + TfLiteResizeBilinearParams params = { + false, /*align_corners*/ + false /*half pixel centers*/ + }; + + tflite::testing::TestResizeBilinear(input_dims, input_data, + expected_size_data, expected_output_data, + output_dims, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(TwoDimensionalResizeInt8) +{ + int input_dims[] = { 4, 1, 2, 2, 1 }; + const int8_t input_data[] = { + 3, 6, // + 9, 12, // + }; + const int32_t expected_size_data[] = { 3, 3 }; + const int8_t expected_output_data[] = { + 3, 5, 6, // + 7, 9, 10, // + 9, 11, 12, // + }; + int output_dims[] = { 4, 1, 3, 3, 1 }; + int8_t output_data[9]; + + TfLiteResizeBilinearParams params = { + false, /*align_corners*/ + false /*half pixel centers*/ + }; + + tflite::testing::TestResizeBilinear( + input_dims, input_data, expected_size_data, expected_output_data, + output_dims, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(TwoDimensionalResizeWithTwoBatches) +{ + int input_dims[] = { 4, 2, 2, 2, 1 }; + const float input_data[] = { + 3, 6, // + 9, 12, // + 4, 10, // + 10, 16 // + }; + const int32_t expected_size_data[] = { 3, 3 }; + const float expected_output_data[] = { + 3, 5, 6, // + 7, 9, 10, // + 9, 11, 12, // + 4, 8, 10, // + 8, 12, 14, // + 10, 14, 16, // + }; + int output_dims[] = { 4, 2, 3, 3, 1 }; + float output_data[18]; + + TfLiteResizeBilinearParams params = { + false, /*align_corners*/ + false /*half pixel centers*/ + }; + + tflite::testing::TestResizeBilinear(input_dims, input_data, + expected_size_data, expected_output_data, + output_dims, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(TwoDimensionalResizeWithTwoBatchesInt8) +{ + int input_dims[] = { 4, 2, 2, 2, 1 }; + const int8_t input_data[] = { + 3, 6, // + 9, 12, // + 4, 10, // + 12, 16 // + }; + const int32_t expected_size_data[] = { 3, 3 }; + const int8_t expected_output_data[] = { + 3, 5, 6, // + 7, 9, 10, // + 9, 11, 12, // + 4, 8, 10, // + 9, 12, 13, // + 12, 14, 16, // + }; + int output_dims[] = { 4, 2, 3, 3, 1 }; + int8_t output_data[18]; + + TfLiteResizeBilinearParams params = { + false, /*align_corners*/ + false /*half pixel centers*/ + }; + + tflite::testing::TestResizeBilinear( + input_dims, input_data, expected_size_data, expected_output_data, + output_dims, output_data, ¶ms, /*tolerance=*/1); +} + +TF_LITE_MICRO_TEST(ThreeDimensionalResize) +{ + int input_dims[] = { 4, 1, 2, 2, 2 }; + const float input_data[] = { + 3, 4, 6, 10, // + 9, 10, 12, 16, // + }; + const int32_t expected_size_data[] = { 3, 3 }; + const float expected_output_data[] = { + 3, 4, 5, 8, 6, 10, // + 7, 8, 9, 12, 10, 14, // + 9, 10, 11, 14, 12, 16, // + }; + int output_dims[] = { 4, 1, 3, 3, 2 }; + float output_data[18]; + + TfLiteResizeBilinearParams params = { + false, /*align_corners*/ + false /*half pixel centers*/ + }; + + tflite::testing::TestResizeBilinear(input_dims, input_data, + expected_size_data, expected_output_data, + output_dims, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(ThreeDimensionalResizeInt8) +{ + int input_dims[] = { 4, 1, 2, 2, 2 }; + const int8_t input_data[] = { + 3, 4, 6, 10, // + 10, 12, 14, 16, // + }; + const int32_t expected_size_data[] = { 3, 3 }; + const int8_t expected_output_data[] = { + 3, 4, 5, 8, 6, 10, // + 7, 9, 10, 12, 11, 13, // + 10, 12, 12, 14, 14, 16, // + }; + int output_dims[] = { 4, 1, 3, 3, 2 }; + int8_t output_data[18]; + + TfLiteResizeBilinearParams params = { + false, /*align_corners*/ + false /*half pixel centers*/ + }; + + tflite::testing::TestResizeBilinear( + input_dims, input_data, expected_size_data, expected_output_data, + output_dims, output_data, ¶ms, /*tolerance=*/1); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/resize_nearest_neighbor.cc b/components/tflite/tensorflow/lite/micro/kernels/resize_nearest_neighbor.cc new file mode 100644 index 00000000..19e055a2 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/resize_nearest_neighbor.cc @@ -0,0 +1,124 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/resize_nearest_neighbor.h" + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace resize_nearest_neighbor { + +constexpr int kInputTensor = 0; +constexpr int kSizeTensor = 1; +constexpr int kOutputTensor = 0; + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE_EQ(context, NumInputs(node), 2); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + + const TfLiteTensor *input = GetInput(context, node, kInputTensor); + const TfLiteTensor *size = GetInput(context, node, kSizeTensor); + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + + // Our current implementations rely on the input being 4D, + // and the size being 1D tensor with exactly 2 elements. + TF_LITE_ENSURE_EQ(context, NumDimensions(input), 4); + TF_LITE_ENSURE_EQ(context, NumDimensions(size), 1); + TF_LITE_ENSURE_EQ(context, size->type, kTfLiteInt32); + TF_LITE_ENSURE_EQ(context, size->dims->data[0], 2); + + output->type = input->type; + + if (!IsConstantTensor(size)) { + TF_LITE_KERNEL_LOG(context, "Dynamic tensors are unsupported in tfmicro."); + return kTfLiteError; + } + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + auto *params = + reinterpret_cast(node->builtin_data); + + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + const TfLiteEvalTensor *size = + tflite::micro::GetEvalInput(context, node, kSizeTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + tflite::ResizeNearestNeighborParams op_params; + op_params.align_corners = params->align_corners; + op_params.half_pixel_centers = false; + + if (output->type == kTfLiteFloat32) { + reference_ops::ResizeNearestNeighbor( + op_params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(size), + tflite::micro::GetTensorData(size), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } else if (output->type == kTfLiteUInt8) { + reference_ops::ResizeNearestNeighbor( + op_params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(size), + tflite::micro::GetTensorData(size), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } else if (output->type == kTfLiteInt8) { + reference_ops::ResizeNearestNeighbor( + op_params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(size), + tflite::micro::GetTensorData(size), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } else { + TF_LITE_KERNEL_LOG(context, + "Output type is %d, requires float, uint8_t or int8_t.", + output->type); + return kTfLiteError; + } + + return kTfLiteOk; +} +} // namespace resize_nearest_neighbor + +TfLiteRegistration Register_RESIZE_NEAREST_NEIGHBOR() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/resize_nearest_neighbor::Prepare, + /*invoke=*/resize_nearest_neighbor::Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/resize_nearest_neighbor_test.cc b/components/tflite/tensorflow/lite/micro/kernels/resize_nearest_neighbor_test.cc new file mode 100644 index 00000000..d8d6bae7 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/resize_nearest_neighbor_test.cc @@ -0,0 +1,374 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +using uint8_t = std::uint8_t; +using int32_t = std::int32_t; + +TfLiteTensor TestCreateTensor(const float *data, TfLiteIntArray *dims) +{ + return CreateTensor(data, dims); +} + +TfLiteTensor TestCreateTensor(const uint8_t *data, TfLiteIntArray *dims) +{ + return CreateQuantizedTensor(data, dims, 0, 255); +} + +TfLiteTensor TestCreateTensor(const int8_t *data, TfLiteIntArray *dims) +{ + return CreateQuantizedTensor(data, dims, -128, 127); +} + +// Input data expects a 4-D tensor of [batch, height, width, channels] +// Output data should match input datas batch and channels +// Expected sizes should be a 1-D tensor with 2 elements: new_height & new_width +template +void TestResizeNearestNeighbor(int *input_dims_data, const T *input_data, + const int32_t *expected_size_data, + const T *expected_output_data, + int *output_dims_data, T *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + + int expected_size_dims_data[] = { 1, 2 }; + TfLiteIntArray *expected_size_dims = + IntArrayFromInts(expected_size_dims_data); + + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + + const int output_dims_count = ElementCount(*output_dims); + + constexpr int tensors_size = 3; + TfLiteTensor tensors[tensors_size] = { + TestCreateTensor(input_data, input_dims), + CreateTensor(expected_size_data, expected_size_dims), + TestCreateTensor(output_data, output_dims), + }; + + tensors[1].allocation_type = kTfLiteMmapRo; + + TfLiteResizeNearestNeighborParams builtin_data = { false, false }; + + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = + tflite::ops::micro::Register_RESIZE_NEAREST_NEIGHBOR(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, &builtin_data); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + // compare results + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output_data[i], output_data[i]); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(HorizontalResize) +{ + int input_dims[] = { 4, 1, 1, 2, 1 }; + const float input_data[] = { 3, 6 }; + const int32_t expected_size_data[] = { 1, 3 }; + const float expected_output_data[] = { 3, 3, 6 }; + int output_dims[] = { 4, 1, 1, 3, 1 }; + float output_data[3]; + + tflite::testing::TestResizeNearestNeighbor( + input_dims, input_data, expected_size_data, expected_output_data, + output_dims, output_data); +} +TF_LITE_MICRO_TEST(HorizontalResizeUInt8) +{ + int input_dims[] = { 4, 1, 1, 2, 1 }; + const uint8_t input_data[] = { 3, 6 }; + const int32_t expected_size_data[] = { 1, 3 }; + const uint8_t expected_output_data[] = { 3, 3, 6 }; + int output_dims[] = { 4, 1, 1, 3, 1 }; + uint8_t output_data[3]; + + tflite::testing::TestResizeNearestNeighbor( + input_dims, input_data, expected_size_data, expected_output_data, + output_dims, output_data); +} +TF_LITE_MICRO_TEST(HorizontalResizeInt8) +{ + int input_dims[] = { 4, 1, 1, 2, 1 }; + const int8_t input_data[] = { -3, 6 }; + const int32_t expected_size_data[] = { 1, 3 }; + const int8_t expected_output_data[] = { -3, -3, 6 }; + int output_dims[] = { 4, 1, 1, 3, 1 }; + int8_t output_data[3]; + + tflite::testing::TestResizeNearestNeighbor( + input_dims, input_data, expected_size_data, expected_output_data, + output_dims, output_data); +} +TF_LITE_MICRO_TEST(VerticalResize) +{ + int input_dims[] = { 4, 1, 2, 1, 1 }; + const float input_data[] = { 3, 9 }; + const int32_t expected_size_data[] = { 3, 1 }; + const float expected_output_data[] = { 3, 3, 9 }; + int output_dims[] = { 4, 1, 3, 1, 1 }; + float output_data[3]; + + tflite::testing::TestResizeNearestNeighbor( + input_dims, input_data, expected_size_data, expected_output_data, + output_dims, output_data); +} +TF_LITE_MICRO_TEST(VerticalResizeUInt8) +{ + int input_dims[] = { 4, 1, 2, 1, 1 }; + const uint8_t input_data[] = { 3, 9 }; + const int32_t expected_size_data[] = { 3, 1 }; + const uint8_t expected_output_data[] = { 3, 3, 9 }; + int output_dims[] = { 4, 1, 3, 1, 1 }; + uint8_t output_data[3]; + + tflite::testing::TestResizeNearestNeighbor( + input_dims, input_data, expected_size_data, expected_output_data, + output_dims, output_data); +} +TF_LITE_MICRO_TEST(VerticalResizeInt8) +{ + int input_dims[] = { 4, 1, 2, 1, 1 }; + const int8_t input_data[] = { 3, -9 }; + const int32_t expected_size_data[] = { 3, 1 }; + const int8_t expected_output_data[] = { 3, 3, -9 }; + int output_dims[] = { 4, 1, 3, 1, 1 }; + int8_t output_data[3]; + + tflite::testing::TestResizeNearestNeighbor( + input_dims, input_data, expected_size_data, expected_output_data, + output_dims, output_data); +} +TF_LITE_MICRO_TEST(TwoDimensionalResize) +{ + int input_dims[] = { 4, 1, 2, 2, 1 }; + const float input_data[] = { + 3, 6, // + 9, 12, // + }; + const int32_t expected_size_data[] = { 3, 3 }; + const float expected_output_data[] = { + 3, 3, 6, // + 3, 3, 6, // + 9, 9, 12 // + }; + + int output_dims[] = { 4, 1, 3, 3, 1 }; + float output_data[9]; + + tflite::testing::TestResizeNearestNeighbor( + input_dims, input_data, expected_size_data, expected_output_data, + output_dims, output_data); +} +TF_LITE_MICRO_TEST(TwoDimensionalResizeUInt8) +{ + int input_dims[] = { 4, 1, 2, 2, 1 }; + const uint8_t input_data[] = { + 3, 6, // + 9, 12 // + }; + const int32_t expected_size_data[] = { 3, 3 }; + const uint8_t expected_output_data[] = { + 3, 3, 6, // + 3, 3, 6, // + 9, 9, 12 // + }; + int output_dims[] = { 4, 1, 3, 3, 1 }; + uint8_t output_data[9]; + + tflite::testing::TestResizeNearestNeighbor( + input_dims, input_data, expected_size_data, expected_output_data, + output_dims, output_data); +} +TF_LITE_MICRO_TEST(TwoDimensionalResizeInt8) +{ + int input_dims[] = { 4, 1, 2, 2, 1 }; + const int8_t input_data[] = { + 3, -6, // + 9, 12, // + }; + const int32_t expected_size_data[] = { 3, 3 }; + const int8_t expected_output_data[] = { + 3, 3, -6, // + 3, 3, -6, // + 9, 9, 12, // + }; + int output_dims[] = { 4, 1, 3, 3, 1 }; + int8_t output_data[9]; + + tflite::testing::TestResizeNearestNeighbor( + input_dims, input_data, expected_size_data, expected_output_data, + output_dims, output_data); +} +TF_LITE_MICRO_TEST(TwoDimensionalResizeWithTwoBatches) +{ + int input_dims[] = { 4, 2, 2, 2, 1 }; + const float input_data[] = { + 3, 6, // + 9, 12, // + 4, 10, // + 10, 16 // + }; + const int32_t expected_size_data[] = { 3, 3 }; + const float expected_output_data[] = { + 3, 3, 6, // + 3, 3, 6, // + 9, 9, 12, // + 4, 4, 10, // + 4, 4, 10, // + 10, 10, 16, // + }; + int output_dims[] = { 4, 2, 3, 3, 1 }; + float output_data[18]; + + tflite::testing::TestResizeNearestNeighbor( + input_dims, input_data, expected_size_data, expected_output_data, + output_dims, output_data); +} +TF_LITE_MICRO_TEST(TwoDimensionalResizeWithTwoBatchesUInt8) +{ + int input_dims[] = { 4, 2, 2, 2, 1 }; + const uint8_t input_data[] = { + 3, 6, // + 9, 12, // + 4, 10, // + 10, 16 // + }; + const int32_t expected_size_data[] = { 3, 3 }; + const uint8_t expected_output_data[] = { + 3, 3, 6, // + 3, 3, 6, // + 9, 9, 12, // + 4, 4, 10, // + 4, 4, 10, // + 10, 10, 16, // + }; + int output_dims[] = { 4, 2, 3, 3, 1 }; + uint8_t output_data[18]; + + tflite::testing::TestResizeNearestNeighbor( + input_dims, input_data, expected_size_data, expected_output_data, + output_dims, output_data); +} +TF_LITE_MICRO_TEST(TwoDimensionalResizeWithTwoBatchesInt8) +{ + int input_dims[] = { 4, 2, 2, 2, 1 }; + const int8_t input_data[] = { + 3, 6, // + 9, -12, // + -4, 10, // + 10, 16 // + }; + const int32_t expected_size_data[] = { 3, 3 }; + const int8_t expected_output_data[] = { + 3, 3, 6, // + 3, 3, 6, // + 9, 9, -12, // + -4, -4, 10, // + -4, -4, 10, // + 10, 10, 16, // + }; + int output_dims[] = { 4, 2, 3, 3, 1 }; + int8_t output_data[18]; + + tflite::testing::TestResizeNearestNeighbor( + input_dims, input_data, expected_size_data, expected_output_data, + output_dims, output_data); +} +TF_LITE_MICRO_TEST(ThreeDimensionalResize) +{ + int input_dims[] = { 4, 1, 2, 2, 2 }; + const float input_data[] = { + 3, 4, 6, 10, // + 9, 10, 12, 16, // + }; + const int32_t expected_size_data[] = { 3, 3 }; + const float expected_output_data[] = { + 3, 4, 3, 4, 6, 10, // + 3, 4, 3, 4, 6, 10, // + 9, 10, 9, 10, 12, 16, // + }; + int output_dims[] = { 4, 1, 3, 3, 2 }; + float output_data[18]; + + tflite::testing::TestResizeNearestNeighbor( + input_dims, input_data, expected_size_data, expected_output_data, + output_dims, output_data); +} +TF_LITE_MICRO_TEST(ThreeDimensionalResizeUInt8) +{ + int input_dims[] = { 4, 1, 2, 2, 2 }; + const uint8_t input_data[] = { + 3, 4, 6, 10, // + 10, 12, 14, 16, // + }; + const int32_t expected_size_data[] = { 3, 3 }; + const uint8_t expected_output_data[] = { + 3, 4, 3, 4, 6, 10, // + 3, 4, 3, 4, 6, 10, // + 10, 12, 10, 12, 14, 16, // + }; + int output_dims[] = { 4, 1, 3, 3, 2 }; + uint8_t output_data[18]; + + tflite::testing::TestResizeNearestNeighbor( + input_dims, input_data, expected_size_data, expected_output_data, + output_dims, output_data); +} +TF_LITE_MICRO_TEST(ThreeDimensionalResizeInt8) +{ + int input_dims[] = { 4, 1, 2, 2, 2 }; + const int8_t input_data[] = { + 3, 4, -6, 10, // + 10, 12, -14, 16, // + }; + const int32_t expected_size_data[] = { 3, 3 }; + const int8_t expected_output_data[] = { + 3, 4, 3, 4, -6, 10, // + 3, 4, 3, 4, -6, 10, // + 10, 12, 10, 12, -14, 16, // + }; + int output_dims[] = { 4, 1, 3, 3, 2 }; + int8_t output_data[18]; + + tflite::testing::TestResizeNearestNeighbor( + input_dims, input_data, expected_size_data, expected_output_data, + output_dims, output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/round.cc b/components/tflite/tensorflow/lite/micro/kernels/round.cc new file mode 100644 index 00000000..c3235543 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/round.cc @@ -0,0 +1,79 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/round.h" + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace round { + +constexpr int kInputTensor = 0; +constexpr int kOutputTensor = 0; + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteTensor *input = GetInput(context, node, kInputTensor); + TF_LITE_ENSURE(context, input != nullptr); + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + TF_LITE_ENSURE_TYPES_EQ(context, input->type, kTfLiteFloat32); + TF_LITE_ENSURE_TYPES_EQ(context, output->type, input->type); + TF_LITE_ENSURE_EQ(context, output->bytes, input->bytes); + TF_LITE_ENSURE_EQ(context, output->dims->size, input->dims->size); + for (int i = 0; i < output->dims->size; ++i) { + TF_LITE_ENSURE_EQ(context, output->dims->data[i], input->dims->data[i]); + } + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + reference_ops::Round(tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + + return kTfLiteOk; +} +} // namespace round + +TfLiteRegistration Register_ROUND() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/round::Prepare, + /*invoke=*/round::Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/round_test.cc b/components/tflite/tensorflow/lite/micro/kernels/round_test.cc new file mode 100644 index 00000000..ec527c0b --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/round_test.cc @@ -0,0 +1,83 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +void TestRound(int *input_dims_data, const float *input_data, + const float *expected_output_data, float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(input_dims_data); + const int output_dims_count = ElementCount(*output_dims); + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims), + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = tflite::ops::micro::Register_ROUND(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output_data[i], output_data[i], 1e-5f); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(SingleDim) +{ + int input_dims[] = { 1, 6 }; + const float input_data[] = { 8.5, 0.0, 3.5, 4.2, -3.5, -4.5 }; + const float golden[] = { 8, 0, 4, 4, -4, -4 }; + float output_data[6]; + tflite::testing::TestRound(input_dims, input_data, golden, output_data); +} + +TF_LITE_MICRO_TEST(MultiDims) +{ + int input_dims[] = { 4, 2, 1, 1, 6 }; + const float input_data[] = { 0.0001, 8.0001, 0.9999, 9.9999, 0.5, -0.0001, + -8.0001, -0.9999, -9.9999, -0.5, -2.5, 1.5 }; + const float golden[] = { 0, 8, 1, 10, 0, 0, -8, -1, -10, -0, -2, 2 }; + float output_data[12]; + tflite::testing::TestRound(input_dims, input_data, golden, output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/shape.cc b/components/tflite/tensorflow/lite/micro/kernels/shape.cc new file mode 100644 index 00000000..c2ce038b --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/shape.cc @@ -0,0 +1,77 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/memory_helpers.h" +#include "tensorflow/lite/micro/micro_utils.h" + +namespace tflite { + +namespace { +constexpr int kInputTensor = 0; +constexpr int kOutputTensor = 0; + +void ExtractShape(const TfLiteEvalTensor *input, int32_t *output_data) +{ + for (int i = 0; i < input->dims->size; ++i) { + output_data[i] = input->dims->data[i]; + } +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + if (output->type != kTfLiteInt32) { + TF_LITE_KERNEL_LOG(context, "Output type %s (%d) not supported.", + TfLiteTypeGetName(output->type), output->type); + return kTfLiteError; + } else { + ExtractShape(input, tflite::micro::GetTensorData(output)); + } + + return kTfLiteOk; +} + +} // namespace + +TfLiteRegistration Register_SHAPE() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/shape_test.cc b/components/tflite/tensorflow/lite/micro/kernels/shape_test.cc new file mode 100644 index 00000000..d5887bec --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/shape_test.cc @@ -0,0 +1,146 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +void ValidateShape(TfLiteTensor *tensors, const int tensor_count, + int32_t *output_data, const int32_t *expected_output, + int output_dims_count) +{ + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = tflite::Register_SHAPE(); + micro::KernelRunner runner(registration, tensors, tensor_count, inputs_array, + outputs_array, nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output[i], output_data[i]); + } +} + +void TestShape(int *input_dims_data, const float *input_data, + int *output_dims_data, const int32_t *expected_output_data, + int32_t *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims, true), + }; + + ValidateShape(tensors, tensors_size, output_data, expected_output_data, + output_dims_count); +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestShape0) +{ + int input_shape[] = { 1, 5 }; + float input_values[] = { 1, 3, 1, 3, 5 }; + int output_dims[] = { 1, 1 }; // this is actually input_shapes shape + int32_t expected_output_data[] = { 5 }; + int32_t output_data[1]; + + tflite::testing::TestShape(input_shape, input_values, output_dims, + expected_output_data, output_data); +} + +TF_LITE_MICRO_TEST(TestShape1) +{ + int input_shape[] = { 2, 4, 3 }; + float input_values[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + int output_dims[] = { 2, 1, 1 }; + int32_t expected_output_data[] = { 4, 3 }; + int32_t output_data[2]; + + tflite::testing::TestShape(input_shape, input_values, output_dims, + expected_output_data, output_data); +} + +TF_LITE_MICRO_TEST(TestShape2) +{ + int input_shape[] = { 2, 12, 1 }; + float input_values[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + int output_dims[] = { 2, 1, 1 }; + int32_t expected_output_data[] = { 12, 1 }; + int32_t output_data[2]; + + tflite::testing::TestShape(input_shape, input_values, output_dims, + expected_output_data, output_data); +} + +TF_LITE_MICRO_TEST(TestShape3) +{ + int input_shape[] = { 2, 2, 6 }; + float input_values[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + int output_dims[] = { 2, 1, 1 }; + int32_t expected_output_data[] = { 2, 6 }; + int32_t output_data[2]; + + tflite::testing::TestShape(input_shape, input_values, output_dims, + expected_output_data, output_data); +} + +TF_LITE_MICRO_TEST(TestShape4) +{ + int input_shape[] = { 2, 2, 2, 3 }; + float input_values[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + int output_dims[] = { 3, 1, 1, 1 }; + int32_t expected_output_data[] = { 2, 2, 3 }; + int32_t output_data[3]; + + tflite::testing::TestShape(input_shape, input_values, output_dims, + expected_output_data, output_data); +} + +TF_LITE_MICRO_TEST(TestShape5) +{ + int input_shape[] = { 1, 1 }; + float input_values[] = { 1 }; + int output_dims[] = { 1, 1 }; + int32_t expected_output_data[] = { 1 }; + int32_t output_data[1]; + + tflite::testing::TestShape(input_shape, input_values, output_dims, + expected_output_data, output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/softmax.cc b/components/tflite/tensorflow/lite/micro/kernels/softmax.cc new file mode 100644 index 00000000..a7b76862 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/softmax.cc @@ -0,0 +1,99 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/kernels/softmax.h" + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/softmax.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace { + +void SoftmaxQuantized(const TfLiteEvalTensor *input, TfLiteEvalTensor *output, + const SoftmaxParams &op_data) +{ + if (input->type == kTfLiteInt8) { + if (output->type == kTfLiteInt16) { + tflite::reference_ops::Softmax( + op_data, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } else { + tflite::reference_ops::Softmax( + op_data, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } + } else { + tflite::reference_ops::SoftmaxInt16( + op_data, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } +} + +TfLiteStatus SoftmaxEval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = tflite::micro::GetEvalInput(context, node, 0); + TfLiteEvalTensor *output = tflite::micro::GetEvalOutput(context, node, 0); + + TFLITE_DCHECK(node->user_data != nullptr); + SoftmaxParams op_data = *static_cast(node->user_data); + + switch (input->type) { + case kTfLiteFloat32: { + tflite::reference_ops::Softmax( + op_data, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + return kTfLiteOk; + } + case kTfLiteInt8: + case kTfLiteInt16: { + SoftmaxQuantized(input, output, op_data); + return kTfLiteOk; + } + default: + TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.", + TfLiteTypeGetName(input->type), input->type); + return kTfLiteError; + } +} +} // namespace + +TfLiteRegistration Register_SOFTMAX() +{ + return { /*init=*/SoftmaxInit, + /*free=*/nullptr, + /*prepare=*/SoftmaxPrepare, + /*invoke=*/SoftmaxEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/softmax.h b/components/tflite/tensorflow/lite/micro/kernels/softmax.h new file mode 100644 index 00000000..d2954b76 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/softmax.h @@ -0,0 +1,45 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_MICRO_KERNELS_SOFTMAX_H_ +#define TENSORFLOW_LITE_MICRO_KERNELS_SOFTMAX_H_ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/types.h" + +namespace tflite { +void *SoftmaxInit(TfLiteContext *context, const char *buffer, size_t length); + +TfLiteStatus SoftmaxPrepare(TfLiteContext *context, TfLiteNode *node); + +// This is the most generic TfLiteRegistration. The actual supported types may +// still be target dependent. The only requirement is that every implementation +// (reference or optimized) must define this function. +TfLiteRegistration Register_SOFTMAX(); + +#if defined(XTENSA) +// Returns a TfLiteRegistration struct for kernel variant that only supports +// int8 input and int16 output. +TfLiteRegistration Register_SOFTMAX_INT8_INT16(); +#else +inline TfLiteRegistration Register_SOFTMAX_INT8_INT16() +{ + return Register_SOFTMAX(); +} +#endif + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_KERNELS_SOFTMAX_H_ diff --git a/components/tflite/tensorflow/lite/micro/kernels/softmax_common.cc b/components/tflite/tensorflow/lite/micro/kernels/softmax_common.cc new file mode 100644 index 00000000..65370d60 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/softmax_common.cc @@ -0,0 +1,143 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/softmax.h" + +namespace tflite { + +namespace { +// Softmax parameter data that persists in user_data +const int kInt16LUTArraySize = 513; + +TfLiteStatus CalculateSoftmaxParams(TfLiteContext *context, + const TfLiteTensor *input, + TfLiteTensor *output, + const TfLiteSoftmaxParams *params, + SoftmaxParams *op_data) +{ + if (input->type == kTfLiteInt8 || input->type == kTfLiteInt16) { + if (input->type == kTfLiteInt16) { + TF_LITE_ENSURE_EQ(context, output->params.zero_point, 0); + TF_LITE_ENSURE_NEAR(context, output->params.scale, 1.f / 32768, + (0.001f * 1.f / 32768)); + } else { // input->type == kTfLiteInt8 + TF_LITE_ENSURE_TYPES_EQ(context, input->type, kTfLiteInt8); + if (output->type == kTfLiteInt16) { + TF_LITE_ENSURE_EQ(context, output->params.zero_point, -32768); + TF_LITE_ENSURE_NEAR(context, output->params.scale, 1.f / 65536, + (0.001f * 1.f / 65536)); + } else { // output->type == kTfLiteint8 + TF_LITE_ENSURE_TYPES_EQ(context, output->type, kTfLiteInt8); + TF_LITE_ENSURE_EQ(context, output->params.zero_point, -128); + TF_LITE_ENSURE(context, output->params.scale == 1.f / 256); + } + } + + static const int kScaledDiffIntegerBits = 5; + + // Calculate input_multiplier and input_left_shift + if (input->type == kTfLiteInt16) { + int input_left_shift; + double input_scale_beta_rescale = + static_cast(input->params.scale) * + static_cast(params->beta) / + (10.0 / 65535.0); // scale the input_diff such that [-65535, 0] + // correspond to [-10.0, 0.0] + QuantizeMultiplier(input_scale_beta_rescale, &op_data->input_multiplier, + &input_left_shift); + op_data->input_left_shift = input_left_shift; + } else { + int input_left_shift; + tflite::PreprocessSoftmaxScaling( + static_cast(params->beta), + static_cast(input->params.scale), kScaledDiffIntegerBits, + &op_data->input_multiplier, &input_left_shift); + op_data->input_left_shift = input_left_shift; + op_data->diff_min = + -1.0 * tflite::CalculateInputRadius(kScaledDiffIntegerBits, + op_data->input_left_shift); + } + } else { + TF_LITE_ENSURE_TYPES_EQ(context, input->type, kTfLiteFloat32); + TF_LITE_ENSURE_TYPES_EQ(context, output->type, kTfLiteFloat32); + op_data->beta = static_cast(params->beta); + } + return kTfLiteOk; +} + +} // namespace + +void *SoftmaxInit(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(SoftmaxParams)); +} + +TfLiteStatus SoftmaxPrepare(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + const TfLiteTensor *input = GetInput(context, node, 0); + TF_LITE_ENSURE(context, input != nullptr); + TF_LITE_ENSURE(context, NumDimensions(input) >= 1); + TfLiteTensor *output = GetOutput(context, node, 0); + TF_LITE_ENSURE(context, output != nullptr); + + TF_LITE_ENSURE(context, node->user_data != nullptr); + SoftmaxParams *op_data = static_cast(node->user_data); + // Only allocate LUTs for KTfLiteInt16 data type + if (input->type == kTfLiteInt16) { + void *raw_exp_lut = context->AllocatePersistentBuffer( + context, sizeof(int16_t) * kInt16LUTArraySize); + TF_LITE_ENSURE(context, raw_exp_lut != nullptr); + op_data->exp_lut = reinterpret_cast(raw_exp_lut); + void *one_over_one_plus_x_lut = context->AllocatePersistentBuffer( + context, sizeof(int16_t) * kInt16LUTArraySize); + TF_LITE_ENSURE(context, one_over_one_plus_x_lut != nullptr); + op_data->one_over_one_plus_x_lut = + reinterpret_cast(one_over_one_plus_x_lut); + } + + if (output->type == kTfLiteInt16) { + TF_LITE_ENSURE(context, + input->type == kTfLiteInt8 || input->type == kTfLiteInt16); + } else { + TF_LITE_ENSURE_EQ(context, input->type, output->type); + } + + // Populate LUT if required + if (input->type == kTfLiteInt16) { + TF_LITE_ENSURE_EQ(context, output->params.zero_point, 0); + // exp LUT only used on negative values + // we consider exp(-10.0) is insignificant to accumulation + gen_lut([](float value) { return std::exp(value); }, -10.0f, 0.0f, + op_data->exp_lut, kInt16LUTArraySize); + gen_lut([](float value) { return 1.0f / (1.0f + value); }, 0.0f, 1.0f, + op_data->one_over_one_plus_x_lut, kInt16LUTArraySize); + op_data->zero_point = output->params.zero_point; + op_data->scale = output->params.scale; + } + + auto *params = static_cast(node->builtin_data); + return CalculateSoftmaxParams(context, input, output, params, op_data); +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/softmax_test.cc b/components/tflite/tensorflow/lite/micro/kernels/softmax_test.cc new file mode 100644 index 00000000..1fb1adbc --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/softmax_test.cc @@ -0,0 +1,509 @@ +/* Copyright 2017 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +// The Softmax kernel assumes an output in the range [0, 1.0], leading to these +// quantization parameters. +const float output_scale_int8 = 1.0f / 256.0f; +const float output_scale_int16 = 1.0f / 32768.0f; +const int output_zero_point_int8 = -128; +const int output_zero_point_int16 = 0; + +// Empirical tolerance in quantization space +const float tolerance_int16 = 7.0; + +// 1-dimensional test data. +const int flat_size_1d = 5; +int shape_1d[] = { 1, 5 }; +const float input_data_1d[] = { 1.0, 2.0, 3.0, 4.0, 5.0 }; +const float golden_1d[] = { 0.011656231, 0.031684921, 0.086128544, 0.234121657, + 0.636408647 }; + +// 2-dimensional test data. +const int flat_size_2d = 10; +int shape_2d[] = { 2, 2, 5 }; +const float input_data_2d[] = { 1.0, 2.0, 3.0, 4.0, 5.0, + -1.0, -2.0, -3.0, -4.0, -5.0 }; +const float golden_2d[] = { 0.011656231, 0.031684921, 0.086128544, 0.234121657, + 0.636408647, 0.636408647, 0.234121657, 0.086128544, + 0.031684921, 0.011656231 }; + +// 3-dimensional test data. +const int flat_size_3d = 60; +int shape_3d[] = { 3, 3, 4, 5 }; +const float input_data_3d[] = { + // c = 0 + // h = 0 + 3.00, 6.00, -5.00, 4.00, -9.00, + // h = 1 + -10.00, -10.00, -8.00, 2.00, 2.00, + // h = 2 + 8.00, -5.00, -8.00, 5.00, -6.00, + // h = 3 + -8.00, 6.00, 1.00, -10.00, -8.00, + + // c = 1 + // h = 0 + 7.00, 6.00, -10.00, -4.00, -5.00, + // h = 1 + 2.00, 7.00, 9.00, -9.00, 7.00, + // h = 2 + -4.00, -2.00, 8.00, 2.00, 2.00, + // h = 3 + 3.00, 6.00, 6.00, 2.00, 4.00, + + // c = 2 + // h = 0 + 9.00, 7.00, -7.00, 0.00, 4.00, + // h = 1 + -3.00, 8.00, 8.00, -3.00, -4.00, + // h = 2 + -9.00, -9.00, 4.00, -8.00, -1.00, + // h = 3 + -10.00, -2.00, 6.00, -7.00, 0.00 +}; + +float golden_3d[] = { + // c = 0 + // h = 0 + 0.042009463, 0.843782625, 0.000014093, 0.114193561, 0.000000258, + // h = 1 + 0.000003072, 0.000003072, 0.000022699, 0.499985578, 0.499985578, + // h = 2 + 0.952571219, 0.000002153, 0.000000107, 0.047425728, 0.000000792, + // h = 3 + 0.000000826, 0.993305397, 0.006692839, 0.000000112, 0.000000826, + + // c = 1 + // h = 0 + 0.731046347, 0.268936922, 0.000000030, 0.000012210, 0.000004492, + // h = 1 + 0.000717124, 0.106430599, 0.786421666, 0.000000012, 0.106430599, + // h = 2 + 0.000006114, 0.000045174, 0.995015917, 0.002466398, 0.002466398, + // h = 3 + 0.022595176, 0.453836234, 0.453836234, 0.008312301, 0.061420055, + + // c = 2 + // h = 0 + 0.875505904, 0.118486839, 0.000000099, 0.000108046, 0.005899112, + // h = 1 + 0.000008351, 0.499990113, 0.499990113, 0.000008351, 0.000003072, + // h = 2 + 0.000002245, 0.000002245, 0.993296627, 0.000006103, 0.006692780, + // h = 3 + 0.000000112, 0.000334520, 0.997191323, 0.000002254, 0.002471790 +}; + +// 4-dimensional test data. +const int flat_size_4d = 120; +int shape_4d[] = { 4, 2, 3, 4, 5 }; +const float input_data_4d[] = { + // n = 0 + // c = 0 + // h = 0 + 3.00, 6.00, -5.00, 4.00, -9.00, + // h = 1 + -10.00, -10.00, -8.00, 2.00, 2.00, + // h = 2 + 8.00, -5.00, -8.00, 5.00, -6.00, + // h = 3 + -8.00, 6.00, 1.00, -10.00, -8.00, + + // c = 1 + // h = 0 + 7.00, 6.00, -10.00, -4.00, -5.00, + // h = 1 + 2.00, 7.00, 9.00, -9.00, 7.00, + // h = 2 + -4.00, -2.00, 8.00, 2.00, 2.00, + // h = 3 + 3.00, 6.00, 6.00, 2.00, 4.00, + + // c = 2 + // h = 0 + 9.00, 7.00, -7.00, 0.00, 4.00, + // h = 1 + -3.00, 8.00, 8.00, -3.00, -4.00, + // h = 2 + -9.00, -9.00, 4.00, -8.00, -1.00, + // h = 3 + -10.00, -2.00, 6.00, -7.00, 0.00, + + // n = 1 + // c = 0 + // h = 0 + -9.00, -8.00, 6.00, -1.00, -5.00, + // h = 1 + -10.00, -5.00, -10.00, 7.00, -2.00, + // h = 2 + -5.00, -4.00, 1.00, 2.00, 2.00, + // h = 3 + -2.00, -2.00, 1.00, 1.00, -4.00, + + // c = 1 + // h = 0 + -8.00, -3.00, 1.00, 1.00, -1.00, + // h = 1 + -2.00, 6.00, -1.00, -5.00, 6.00, + // h = 2 + -7.00, 8.00, 9.00, 0.00, 9.00, + // h = 3 + -9.00, -5.00, -2.00, 0.00, 8.00, + + // c = 2 + // h = 0 + 4.00, 2.00, -3.00, 5.00, 8.00, + // h = 1 + -1.00, 1.00, -4.00, -9.00, 7.00, + // h = 2 + 3.00, -8.00, 0.00, 9.00, -4.00, + // h = 3 + 8.00, -1.00, 9.00, -9.00, 1.00 +}; + +const float golden_4d[] = { + // n = 0 + // c = 0 + // h = 0 + 0.042009463, 0.843782625, 0.000014093, 0.114193561, 0.000000258, + // h = 1 + 0.000003072, 0.000003072, 0.000022699, 0.499985578, 0.499985578, + // h = 2 + 0.952571219, 0.000002153, 0.000000107, 0.047425728, 0.000000792, + // h = 3 + 0.000000826, 0.993305397, 0.006692839, 0.000000112, 0.000000826, + + // c = 1 + // h = 0 + 0.731046347, 0.268936922, 0.000000030, 0.000012210, 0.000004492, + // h = 1 + 0.000717124, 0.106430599, 0.786421666, 0.000000012, 0.106430599, + // h = 2 + 0.000006114, 0.000045174, 0.995015917, 0.002466398, 0.002466398, + // h = 3 + 0.022595176, 0.453836234, 0.453836234, 0.008312301, 0.061420055, + + // c = 2 + // h = 0 + 0.875505904, 0.118486839, 0.000000099, 0.000108046, 0.005899112, + // h = 1 + 0.000008351, 0.499990113, 0.499990113, 0.000008351, 0.000003072, + // h = 2 + 0.000002245, 0.000002245, 0.993296627, 0.000006103, 0.006692780, + // h = 3 + 0.000000112, 0.000334520, 0.997191323, 0.000002254, 0.002471790, + + // n = 1 + // c = 0 + // h = 0 + 0.000000306, 0.000000831, 0.999071142, 0.000911035, 0.000016686, + // h = 1 + 0.000000041, 0.000006143, 0.000000041, 0.999870380, 0.000123394, + // h = 2 + 0.000384554, 0.001045327, 0.155140254, 0.421714933, 0.421714933, + // h = 3 + 0.023637081, 0.023637081, 0.474763454, 0.474763454, 0.003198931, + + // c = 1 + // h = 0 + 0.000057299, 0.008503973, 0.464301197, 0.464301197, 0.062836334, + // h = 1 + 0.000167625, 0.499684188, 0.000455653, 0.000008346, 0.499684188, + // h = 2 + 0.000000048, 0.155354299, 0.422296769, 0.000052116, 0.422296769, + // h = 3 + 0.000000041, 0.000002259, 0.000045383, 0.000335334, 0.999616982, + + // c = 2 + // h = 0 + 0.017107856, 0.002315297, 0.000015600, 0.046503973, 0.934057274, + // h = 1 + 0.000334516, 0.002471755, 0.000016655, 0.000000112, 0.997176963, + // h = 2 + 0.002472313, 0.000000041, 0.000123089, 0.997402302, 0.000002254, + // h = 3 + 0.268866557, 0.000033181, 0.730855076, 0.000000011, 0.000245175 +}; + +template +void ValidateSoftmaxGoldens(TfLiteTensor *tensors, const int tensor_count, + T *output_data, const T *expected_output, + int output_dims_count, float tolerance) +{ + TfLiteSoftmaxParams builtin_data = { 1.0f }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = Register_SOFTMAX(); + micro::KernelRunner runner(registration, tensors, tensor_count, inputs_array, + outputs_array, &builtin_data); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output[i], output_data[i], tolerance); + } +} + +void TestSoftmaxFloat(int *input_dims_data, const float *input_data, + int *output_dims_data, const float *expected_output_data, + float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims), + }; + + ValidateSoftmaxGoldens(tensors, tensors_size, output_data, + expected_output_data, output_dims_count, 1e-5); +} + +template +void TestSoftmaxQuantized(int *input_dims_data, const float *input_data, + inputT *input_quantized, float input_scale, + int input_zero_point, int *output_dims_data, + const float *golden, outputT *golden_quantized, + float output_scale, int output_zero_point, + outputT *output_data, float tolerance = 1.0) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(input_data, input_quantized, input_dims, + input_scale, input_zero_point), + CreateQuantizedTensor(output_data, output_dims, output_scale, + output_zero_point), + }; + + Quantize(golden, golden_quantized, output_dims_count, output_scale, + output_zero_point); + + ValidateSoftmaxGoldens(tensors, tensors_size, output_data, golden_quantized, + output_dims_count, tolerance); +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(Softmax1DFloatShouldMatchGolden) +{ + float output_data[tflite::testing::flat_size_1d]; + tflite::testing::TestSoftmaxFloat( + tflite::testing ::shape_1d, tflite::testing::input_data_1d, + tflite::testing::shape_1d, tflite::testing::golden_1d, output_data); +} + +TF_LITE_MICRO_TEST(Softmax1DQuantizedInt8ShouldMatchGolden) +{ + const float input_scale = 0.1f; + const int input_zero_point = 0; + + int8_t input_quantized[tflite::testing::flat_size_1d]; + int8_t golden_quantized[tflite::testing::flat_size_1d]; + int8_t output_data[tflite::testing::flat_size_1d]; + tflite::testing::TestSoftmaxQuantized( + tflite::testing::shape_1d, tflite::testing::input_data_1d, + input_quantized, input_scale, input_zero_point, tflite::testing::shape_1d, + tflite::testing::golden_1d, golden_quantized, + tflite::testing::output_scale_int8, + tflite::testing::output_zero_point_int8, output_data); +} + +TF_LITE_MICRO_TEST(Softmax1DQuantizedInt16ShouldMatchGolden) +{ + const float input_scale = 0.1f; + const int input_zero_point = 0; + + int16_t input_quantized[tflite::testing::flat_size_1d]; + int16_t golden_quantized[tflite::testing::flat_size_1d]; + int16_t output_data[tflite::testing::flat_size_1d]; + tflite::testing::TestSoftmaxQuantized( + tflite::testing::shape_1d, tflite::testing::input_data_1d, + input_quantized, input_scale, input_zero_point, tflite::testing::shape_1d, + tflite::testing::golden_1d, golden_quantized, + tflite::testing::output_scale_int16, + tflite::testing::output_zero_point_int16, output_data); +} + +TF_LITE_MICRO_TEST(Softmax2DFloatShouldMatchGolden) +{ + float output_data[tflite::testing::flat_size_2d]; + tflite::testing::TestSoftmaxFloat( + tflite::testing ::shape_2d, tflite::testing::input_data_2d, + tflite::testing::shape_2d, tflite::testing::golden_2d, output_data); +} + +TF_LITE_MICRO_TEST(Softmax2DQuantizedInt8ShouldMatchGolden) +{ + const float input_scale = 0.1f; + const int input_zero_point = 0; + + int8_t input_quantized[tflite::testing::flat_size_2d]; + int8_t golden_quantized[tflite::testing::flat_size_2d]; + int8_t output_data[tflite::testing::flat_size_2d]; + tflite::testing::TestSoftmaxQuantized( + tflite::testing::shape_2d, tflite::testing::input_data_2d, + input_quantized, input_scale, input_zero_point, tflite::testing::shape_2d, + tflite::testing::golden_2d, golden_quantized, + tflite::testing::output_scale_int8, + tflite::testing::output_zero_point_int8, output_data); +} + +TF_LITE_MICRO_TEST(Softmax2DQuantizedInt16ShouldMatchGolden) +{ + const float input_scale = 0.1f; + const int input_zero_point = 0; + + int16_t input_quantized[tflite::testing::flat_size_2d]; + int16_t golden_quantized[tflite::testing::flat_size_2d]; + int16_t output_data[tflite::testing::flat_size_2d]; + tflite::testing::TestSoftmaxQuantized( + tflite::testing::shape_2d, tflite::testing::input_data_2d, + input_quantized, input_scale, input_zero_point, tflite::testing::shape_2d, + tflite::testing::golden_2d, golden_quantized, + tflite::testing::output_scale_int16, + tflite::testing::output_zero_point_int16, output_data); +} + +TF_LITE_MICRO_TEST(Softmax3DFloatShouldMatchGolden) +{ + float output_data[tflite::testing::flat_size_3d]; + tflite::testing::TestSoftmaxFloat( + tflite::testing ::shape_3d, tflite::testing::input_data_3d, + tflite::testing::shape_3d, tflite::testing::golden_3d, output_data); +} + +TF_LITE_MICRO_TEST(Softmax3DQuantizedInt8ShouldMatchGolden) +{ + const float input_scale = 0.1f; + const int input_zero_point = 0; + + int8_t input_quantized[tflite::testing::flat_size_3d]; + int8_t golden_quantized[tflite::testing::flat_size_3d]; + int8_t output_data[tflite::testing::flat_size_3d]; + tflite::testing::TestSoftmaxQuantized( + tflite::testing::shape_3d, tflite::testing::input_data_3d, + input_quantized, input_scale, input_zero_point, tflite::testing::shape_3d, + tflite::testing::golden_3d, golden_quantized, + tflite::testing::output_scale_int8, + tflite::testing::output_zero_point_int8, output_data); +} + +TF_LITE_MICRO_TEST(Softmax3DQuantizedInt16ShouldMatchGolden) +{ + const float input_scale = 0.1f; + const int input_zero_point = 0; + + int16_t input_quantized[tflite::testing::flat_size_3d]; + int16_t golden_quantized[tflite::testing::flat_size_3d]; + int16_t output_data[tflite::testing::flat_size_3d]; + tflite::testing::TestSoftmaxQuantized( + tflite::testing::shape_3d, tflite::testing::input_data_3d, + input_quantized, input_scale, input_zero_point, tflite::testing::shape_3d, + tflite::testing::golden_3d, golden_quantized, + tflite::testing::output_scale_int16, + tflite::testing::output_zero_point_int16, output_data, + tflite::testing::tolerance_int16); +} + +TF_LITE_MICRO_TEST(Softmax4DFloatShouldMatchGolden) +{ + float output_data[tflite::testing::flat_size_4d]; + tflite::testing::TestSoftmaxFloat( + tflite::testing ::shape_4d, tflite::testing::input_data_4d, + tflite::testing::shape_4d, tflite::testing::golden_4d, output_data); +} + +TF_LITE_MICRO_TEST(Softmax4DQuantizedInt8ShouldMatchGolden) +{ + const float input_scale = 0.1f; + const int input_zero_point = 0; + + int8_t input_quantized[tflite::testing::flat_size_4d]; + int8_t golden_quantized[tflite::testing::flat_size_4d]; + int8_t output_data[tflite::testing::flat_size_4d]; + tflite::testing::TestSoftmaxQuantized( + tflite::testing::shape_4d, tflite::testing::input_data_4d, + input_quantized, input_scale, input_zero_point, tflite::testing::shape_4d, + tflite::testing::golden_4d, golden_quantized, + tflite::testing::output_scale_int8, + tflite::testing::output_zero_point_int8, output_data); +} + +TF_LITE_MICRO_TEST(Softmax4DQuantizedInt16ShouldMatchGolden) +{ + const float input_scale = 0.1f; + const int input_zero_point = 0; + + int16_t input_quantized[tflite::testing::flat_size_4d]; + int16_t golden_quantized[tflite::testing::flat_size_4d]; + int16_t output_data[tflite::testing::flat_size_4d]; + tflite::testing::TestSoftmaxQuantized( + tflite::testing::shape_4d, tflite::testing::input_data_4d, + input_quantized, input_scale, input_zero_point, tflite::testing::shape_4d, + tflite::testing::golden_4d, golden_quantized, + tflite::testing::output_scale_int16, + tflite::testing::output_zero_point_int16, output_data, + tflite::testing::tolerance_int16); +} + +TF_LITE_MICRO_TEST(Softmax2DQuantizedInt8InputInt16OutputShouldMatchGolden) +{ + const float input_scale = 0.1f; + const int input_zero_point = 0; + const float output_scale = 1.0f / 65536.0f; + const int output_zero_point = -32768; + + int8_t input_quantized[tflite::testing::flat_size_2d]; + int16_t golden_quantized[tflite::testing::flat_size_2d]; + int16_t output_data[tflite::testing::flat_size_2d]; + tflite::testing::TestSoftmaxQuantized( + tflite::testing::shape_2d, tflite::testing::input_data_2d, + input_quantized, input_scale, input_zero_point, tflite::testing::shape_2d, + tflite::testing::golden_2d, golden_quantized, output_scale, + output_zero_point, output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/space_to_batch_nd.cc b/components/tflite/tensorflow/lite/micro/kernels/space_to_batch_nd.cc new file mode 100644 index 00000000..0ec8a173 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/space_to_batch_nd.cc @@ -0,0 +1,125 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/space_to_batch_nd.h" + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/internal/types.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/micro_utils.h" + +namespace tflite { + +namespace { + +constexpr int kInputTensor = 0; +constexpr int kBlockShapeTensor = 1; +constexpr int kCropsTensor = 2; +constexpr int kOutputTensor = 0; + +// Currently, only 3D NHC and 4D NHWC input/output op_context are supported. +// In case of 3D input, it will be extended to 3D NHWC by adding W=1. +// The 4D array need to have exactly 2 spatial dimensions. +// TODO(b/149952582): Support arbitrary dimension in SpaceToBatchND. +const int kInputOutputMinDimensionNum = 3; +const int kInputOutputMaxDimensionNum = 4; + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(SpaceToBatchParams)); +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE_EQ(context, NumInputs(node), 3); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + + const TfLiteTensor *input = GetInput(context, node, kInputTensor); + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + TF_LITE_ENSURE(context, input != nullptr && output != nullptr); + + TF_LITE_ENSURE(context, NumDimensions(input) >= kInputOutputMinDimensionNum); + TF_LITE_ENSURE(context, NumDimensions(output) >= kInputOutputMinDimensionNum); + TF_LITE_ENSURE(context, NumDimensions(input) <= kInputOutputMaxDimensionNum); + TF_LITE_ENSURE(context, NumDimensions(output) <= kInputOutputMaxDimensionNum); + TF_LITE_ENSURE_TYPES_EQ(context, input->type, output->type); + + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + const SpaceToBatchParams ¶ms = + *(static_cast(node->user_data)); + + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + const TfLiteEvalTensor *block_shape = + tflite::micro::GetEvalInput(context, node, kBlockShapeTensor); + const TfLiteEvalTensor *crops = + tflite::micro::GetEvalInput(context, node, kCropsTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + switch (input->type) { // Already know in/out types are same. + case kTfLiteFloat32: + reference_ops::SpaceToBatchND( + params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(block_shape), + tflite::micro::GetTensorData(block_shape), + tflite::micro::GetTensorShape(crops), + tflite::micro::GetTensorData(crops), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + break; + case kTfLiteInt8: + reference_ops::SpaceToBatchND( + params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(block_shape), + tflite::micro::GetTensorData(block_shape), + tflite::micro::GetTensorShape(crops), + tflite::micro::GetTensorData(crops), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + break; + default: + TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.", + TfLiteTypeGetName(input->type), input->type); + return kTfLiteError; + } + return kTfLiteOk; +} + +} // namespace. + +TfLiteRegistration Register_SPACE_TO_BATCH_ND() +{ + return { /*init=*/Init, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/space_to_batch_nd_test.cc b/components/tflite/tensorflow/lite/micro/kernels/space_to_batch_nd_test.cc new file mode 100644 index 00000000..bc639497 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/space_to_batch_nd_test.cc @@ -0,0 +1,160 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +constexpr int kBasicInputOutputSize = 16; +int basic_input_dims[] = { 4, 1, 4, 4, 1 }; +const float basic_input[kBasicInputOutputSize] = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 +}; +int basic_block_shape_dims[] = { 1, 2 }; +const int32_t basic_block_shape[] = { 2, 2 }; +int basic_crops_dims[] = { 1, 4 }; +const int32_t basic_crops[] = { 0, 0, 0, 0 }; +int basic_output_dims[] = { 4, 4, 2, 2, 1 }; +const float basic_golden[kBasicInputOutputSize] = { 1, 3, 9, 11, 2, 4, 10, 12, + 5, 7, 13, 15, 6, 8, 14, 16 }; + +template +TfLiteStatus ValidateSpaceToBatchNdGoldens(TfLiteTensor *tensors, + int tensors_size, const T *golden, + T *output, int output_size) +{ + int inputs_array_data[] = { 3, 0, 1, 2 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 3 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = Register_SPACE_TO_BATCH_ND(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, nullptr); + + TF_LITE_ENSURE_STATUS(runner.InitAndPrepare()); + TF_LITE_ENSURE_STATUS(runner.Invoke()); + + for (int i = 0; i < output_size; ++i) { + // TODO(b/158102673): workaround for not having fatal test assertions. + TF_LITE_MICRO_EXPECT_EQ(golden[i], output[i]); + if (golden[i] != output[i]) { + return kTfLiteError; + } + } + return kTfLiteOk; +} + +TfLiteStatus TestSpaceToBatchNdFloat( + int *input_dims_data, const float *input_data, int *block_shape_dims_data, + const int32_t *block_shape_data, int *crops_dims_data, + const int32_t *crops_data, int *output_dims_data, const float *golden, + float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *block_shape_dims = IntArrayFromInts(block_shape_dims_data); + TfLiteIntArray *crops_dims = IntArrayFromInts(crops_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + + constexpr int inputs_size = 3; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(block_shape_data, block_shape_dims), + CreateTensor(crops_data, crops_dims), + CreateTensor(output_data, output_dims), + }; + + return ValidateSpaceToBatchNdGoldens(tensors, tensors_size, golden, + output_data, ElementCount(*output_dims)); +} + +template +TfLiteStatus TestSpaceToBatchNdQuantized( + int *input_dims_data, const float *input_data, T *input_quantized, + float input_scale, int input_zero_point, int *block_shape_dims_data, + const int32_t *block_shape_data, int *crops_dims_data, + const int32_t *crops_data, int *output_dims_data, const float *golden, + T *golden_quantized, float output_scale, int output_zero_point, + T *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *block_shape_dims = IntArrayFromInts(block_shape_dims_data); + TfLiteIntArray *crops_dims = IntArrayFromInts(crops_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + + constexpr int inputs_size = 3; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + tflite::testing::CreateQuantizedTensor(input_data, input_quantized, + input_dims, input_scale, + input_zero_point), + tflite::testing::CreateTensor(block_shape_data, block_shape_dims), + tflite::testing::CreateTensor(crops_data, crops_dims), + tflite::testing::CreateQuantizedTensor(output_data, output_dims, + output_scale, output_zero_point), + }; + tflite::Quantize(golden, golden_quantized, ElementCount(*output_dims), + output_scale, output_zero_point); + + return ValidateSpaceToBatchNdGoldens(tensors, tensors_size, golden_quantized, + output_data, ElementCount(*output_dims)); +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(SpaceToBatchBasicFloat) +{ + float output[tflite::testing::kBasicInputOutputSize]; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, + tflite::testing::TestSpaceToBatchNdFloat( + tflite::testing::basic_input_dims, tflite::testing::basic_input, + tflite::testing::basic_block_shape_dims, + tflite::testing::basic_block_shape, tflite::testing::basic_crops_dims, + tflite::testing::basic_crops, tflite::testing::basic_output_dims, + tflite::testing::basic_golden, output)); +} + +TF_LITE_MICRO_TEST(SpaceToBatchBasicInt8) +{ + int8_t output[tflite::testing::kBasicInputOutputSize]; + int8_t input_quantized[tflite::testing::kBasicInputOutputSize]; + int8_t golden_quantized[tflite::testing::kBasicInputOutputSize]; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, + tflite::testing::TestSpaceToBatchNdQuantized( + tflite::testing::basic_input_dims, tflite::testing::basic_input, + input_quantized, 1.0f, 0, tflite::testing::basic_block_shape_dims, + tflite::testing::basic_block_shape, tflite::testing::basic_crops_dims, + tflite::testing::basic_crops, tflite::testing::basic_output_dims, + tflite::testing::basic_golden, golden_quantized, 1.0f, 0, output)); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/space_to_depth.cc b/components/tflite/tensorflow/lite/micro/kernels/space_to_depth.cc new file mode 100644 index 00000000..5e114290 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/space_to_depth.cc @@ -0,0 +1,131 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/kernels/internal/reference/space_to_depth.h" + +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/types.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { + +namespace { + +constexpr int kInputTensor = 0; +constexpr int kOutputTensor = 0; +constexpr int kBatchRank = 0; +constexpr int kHeightRank = 1; +constexpr int kWidthRank = 2; +constexpr int kDepthRank = 3; + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + auto *params = + reinterpret_cast(node->builtin_data); + + TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + + const TfLiteTensor *input; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, kInputTensor, &input)); + TfLiteTensor *output; + TF_LITE_ENSURE_OK(context, + GetOutputSafe(context, node, kOutputTensor, &output)); + + TF_LITE_ENSURE_EQ(context, NumDimensions(input), 4); + + auto data_type = output->type; + TF_LITE_ENSURE(context, + data_type == kTfLiteFloat32 || data_type == kTfLiteInt8); + TF_LITE_ENSURE_TYPES_EQ(context, input->type, output->type); + + const int block_size = params->block_size; + const int input_height = input->dims->data[kHeightRank]; + const int input_width = input->dims->data[kWidthRank]; + int output_height = input_height / block_size; + int output_width = input_width / block_size; + + TF_LITE_ENSURE_EQ(context, input_height, output_height * block_size); + TF_LITE_ENSURE_EQ(context, input_width, output_width * block_size); + + // Relocate dims to the persistent storage arena before changing them, + // otherwise we'd be modifying temporary copies made by the interpreters each + // time they process the layer. + TfLiteEvalTensor *output_eval = + micro::GetEvalOutput(context, node, kOutputTensor); + TF_LITE_ENSURE_OK(context, micro::CreateWritableTensorDimsWithCopy( + context, output, output_eval)); + + output->dims->data[kBatchRank] = input->dims->data[kBatchRank]; + output->dims->data[kHeightRank] = output_height; + output->dims->data[kWidthRank] = output_width; + output->dims->data[kDepthRank] = + input->dims->data[kDepthRank] * block_size * block_size; + + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + auto *params = + reinterpret_cast(node->builtin_data); + + const TfLiteEvalTensor *input = + micro::GetEvalInput(context, node, kInputTensor); + TfLiteEvalTensor *output = micro::GetEvalOutput(context, node, kOutputTensor); + + SpaceToDepthParams op_params; + op_params.block_size = params->block_size; + + switch (input->type) { // Already know in/out types are same. + case kTfLiteFloat32: + reference_ops::SpaceToDepth(op_params, micro::GetTensorShape(input), + micro::GetTensorData(input), + micro::GetTensorShape(output), + micro::GetTensorData(output)); + break; + case kTfLiteInt8: + reference_ops::SpaceToDepth(op_params, micro::GetTensorShape(input), + micro::GetTensorData(input), + micro::GetTensorShape(output), + micro::GetTensorData(output)); + break; + default: + TF_LITE_KERNEL_LOG( + context, "SPACE_TO_DEPTH only supports FLOAT32 and INT8, got %s.", + TfLiteTypeGetName(input->type)); + return kTfLiteError; + } + + return kTfLiteOk; +} + +} // namespace + +TfLiteRegistration Register_SPACE_TO_DEPTH() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/space_to_depth_test.cc b/components/tflite/tensorflow/lite/micro/kernels/space_to_depth_test.cc new file mode 100644 index 00000000..6740f013 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/space_to_depth_test.cc @@ -0,0 +1,192 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/micro_utils.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +using tflite::ElementCount; +using tflite::testing::CreateTensor; +using tflite::testing::IntArrayFromInts; + +namespace { + +void ExpectEq(TfLiteIntArray *a, TfLiteIntArray *b) +{ + for (int i = 0; i < a->size; ++i) { + TF_LITE_MICRO_EXPECT_EQ(a->data[i], b->data[i]); + } +} + +template +void ExpectNear(const T a[], const T b[], int size, float tolerance = 1e-5) +{ + for (int i = 0; i < size; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(a[i], b[i], tolerance); + } +} + +template +constexpr int ArrayLength(const T &) +{ + return std::extent::value; +} + +template +struct SpaceToDepthTest { + int *input_dims; + const T *input_data; + int block_size; + int *expect_dims; + const T *expect_data; + T *output_data; +}; + +template +void TestSpaceToDepth(const SpaceToDepthTest &args) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(args.input_dims); + constexpr int kOutputDims = 4; + int output_dims_data[] = { kOutputDims, 0, 0, 0, 0 }; + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + TfLiteTensor tensors[] = { CreateTensor(args.input_data, input_dims), + CreateTensor(args.output_data, output_dims) }; + + const TfLiteRegistration registration = tflite::Register_SPACE_TO_DEPTH(); + constexpr int tensor_count = ArrayLength(tensors); + constexpr int kInputIndex = 0; + int input_indexes_data[] = { 1, kInputIndex }; + TfLiteIntArray *input_indexes = IntArrayFromInts(input_indexes_data); + constexpr int kOutputIndex = 1; + int output_indexes_data[] = { 1, kOutputIndex }; + TfLiteIntArray *output_indexes = IntArrayFromInts(output_indexes_data); + TfLiteSpaceToDepthParams op_params = {}; + op_params.block_size = args.block_size; + + tflite::micro::KernelRunner runner(registration, tensors, tensor_count, + input_indexes, output_indexes, + static_cast(&op_params)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + const TfLiteTensor *output_tensor = &tensors[kOutputIndex]; + TfLiteIntArray *expect_dims = IntArrayFromInts(args.expect_dims); + ExpectEq(output_tensor->dims, expect_dims); + ExpectNear(args.output_data, args.expect_data, ElementCount(*expect_dims)); +} + +} // namespace + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(SpaceToDepth_Float32_1222) +{ + using value_type = float; + SpaceToDepthTest test; + + int input_dims[] = { 4, 1, 2, 2, 2 }; + test.input_dims = input_dims; + constexpr value_type kInputData[] = { 1.4, 2.3, 3.2, 4.1, 5.4, 6.3, 7.2, 8.1 }; + test.input_data = kInputData; + + test.block_size = 2; + + int expect_dims[] = { 4, 1, 1, 1, 8 }; + test.expect_dims = expect_dims; + test.expect_data = kInputData; + + constexpr int kExpectElements = ArrayLength(kInputData); + value_type output_data[kExpectElements]; + test.output_data = output_data; + + TestSpaceToDepth(test); +} + +TF_LITE_MICRO_TEST(SpaceToDepth_Int8_1221) +{ + using value_type = int8_t; + SpaceToDepthTest test; + + int input_dims[] = { 4, 1, 2, 2, 1 }; + test.input_dims = input_dims; + constexpr value_type kInputData[] = { 1, 2, 3, 4 }; + test.input_data = kInputData; + + test.block_size = 2; + + int expect_dims[] = { 4, 1, 1, 1, 4 }; + test.expect_dims = expect_dims; + test.expect_data = kInputData; + + constexpr int kExpectElements = ArrayLength(kInputData); + value_type output_data[kExpectElements]; + test.output_data = output_data; + + TestSpaceToDepth(test); +} + +TF_LITE_MICRO_TEST(SpaceToDepth_Int8_1223) +{ + using value_type = int8_t; + SpaceToDepthTest test; + + int input_dims[] = { 4, 1, 2, 2, 3 }; + test.input_dims = input_dims; + constexpr value_type kInputData[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + test.input_data = kInputData; + + test.block_size = 2; + + int expect_dims[] = { 4, 1, 1, 1, 12 }; + test.expect_dims = expect_dims; + test.expect_data = kInputData; + + constexpr int kExpectElements = ArrayLength(kInputData); + value_type output_data[kExpectElements]; + test.output_data = output_data; + + TestSpaceToDepth(test); +} + +TF_LITE_MICRO_TEST(SpaceToDepth_Int8_1441) +{ + using value_type = int8_t; + SpaceToDepthTest test; + + int input_dims[] = { 4, 1, 4, 4, 1 }; + test.input_dims = input_dims; + constexpr value_type kInputData[] = { 1, 2, 5, 6, 3, 4, 7, 8, + 9, 10, 13, 14, 11, 12, 15, 16 }; + test.input_data = kInputData; + + test.block_size = 2; + + int expect_dims[] = { 4, 1, 2, 2, 4 }; + test.expect_dims = expect_dims; + constexpr value_type kExpectData[] = { 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16 }; + test.expect_data = kExpectData; + + constexpr int kExpectElements = ArrayLength(kInputData); + value_type output_data[kExpectElements]; + test.output_data = output_data; + + TestSpaceToDepth(test); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/split.cc b/components/tflite/tensorflow/lite/micro/kernels/split.cc new file mode 100644 index 00000000..da5b4b48 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/split.cc @@ -0,0 +1,140 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace split { + +template +TfLiteStatus SplitImpl(TfLiteContext *context, TfLiteNode *node, + const TfLiteEvalTensor *input, int axis_value) +{ + const int output_count = NumOutputs(node); + const TfLiteIntArray *input_dims = input->dims; + const TfLiteEvalTensor *output0 = + tflite::micro::GetEvalOutput(context, node, 0); + const TfLiteIntArray *output_dims = output0->dims; + + const int split_dimensions = input_dims->size; + int axis = axis_value < 0 ? axis_value + split_dimensions : axis_value; + + TFLITE_DCHECK_LT(axis, split_dimensions); + TFLITE_DCHECK_EQ(output_dims->size, split_dimensions); + + int64_t split_size = output_dims->data[axis] * output_count; + + TFLITE_DCHECK_EQ(split_size, input_dims->data[axis]); + int64_t outer_size = 1; + for (int i = 0; i < axis; ++i) { + outer_size *= input_dims->data[i]; + } + + int64_t base_inner_size = 1; + for (int i = axis + 1; i < split_dimensions; ++i) { + base_inner_size *= input_dims->data[i]; + } + + const T *input_ptr = tflite::micro::GetTensorData(input); + for (int k = 0; k < outer_size; ++k) { + for (int i = 0; i < output_count; ++i) { + TfLiteEvalTensor *t = tflite::micro::GetEvalOutput(context, node, i); + T *output_data = tflite::micro::GetTensorData(t); + const int copy_size = output_dims->data[axis] * base_inner_size; + T *output_ptr = output_data + k * copy_size; + for (int j = 0; j < copy_size; ++j) + output_ptr[j] = input_ptr[j]; + input_ptr += copy_size; + } + } + + return kTfLiteOk; +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteTensor *axis = GetInput(context, node, 0); + TF_LITE_ENSURE(context, axis != nullptr); + + // Dynamic output tensors are needed if axis tensor is not constant. + // But Micro doesn't support dynamic memory allocation, so we only support + // constant axis tensor for now. + TF_LITE_ENSURE_MSG(context, IsConstantTensor(axis), + "Non constant axis tensor not supported"); + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *axis = tflite::micro::GetEvalInput(context, node, 0); + const TfLiteEvalTensor *input = tflite::micro::GetEvalInput(context, node, 1); + + int axis_value = tflite::micro::GetTensorData(axis)[0]; + if (axis_value < 0) { + axis_value += input->dims->size; + } + + TF_LITE_ENSURE(context, axis_value >= 0); + TF_LITE_ENSURE(context, axis_value < input->dims->size); + + switch (input->type) { + case kTfLiteFloat32: { + return SplitImpl(context, node, input, axis_value); + } + case kTfLiteUInt8: { + return SplitImpl(context, node, input, axis_value); + } + case kTfLiteInt8: { + return SplitImpl(context, node, input, axis_value); + } + case kTfLiteInt16: { + return SplitImpl(context, node, input, axis_value); + } + case kTfLiteInt32: { + return SplitImpl(context, node, input, axis_value); + } + default: + TF_LITE_KERNEL_LOG(context, "Type %s currently not supported.", + TfLiteTypeGetName(input->type)); + return kTfLiteError; + } +#undef TF_LITE_SPLIT + + return kTfLiteOk; +} + +} // namespace split + +TfLiteRegistration Register_SPLIT() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/split::Prepare, + /*invoke=*/split::Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/split_test.cc b/components/tflite/tensorflow/lite/micro/kernels/split_test.cc new file mode 100644 index 00000000..79885c01 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/split_test.cc @@ -0,0 +1,475 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/debug_log.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { + +void TestSplitTwoOutputsFloat(int *input_dims_data, const float *input_data, + int *axis_dims_data, const int32_t *axis_data, + int *output1_dims_data, + const float *expected_output1_data, + int *output2_dims_data, + const float *expected_output2_data, + float *output1_data, float *output2_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *axis_dims = IntArrayFromInts(axis_dims_data); + TfLiteIntArray *output1_dims = IntArrayFromInts(output1_dims_data); + TfLiteIntArray *output2_dims = IntArrayFromInts(output2_dims_data); + const int output1_dims_count = ElementCount(*output1_dims); + const int output2_dims_count = ElementCount(*output2_dims); + + constexpr int input_size = 1; + constexpr int output_size = 2; + constexpr int axis_size = 1; + constexpr int tensors_size = input_size + output_size + axis_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(axis_data, axis_dims), CreateTensor(input_data, input_dims), + CreateTensor(output1_data, output1_dims), + CreateTensor(output2_data, output2_dims) + }; + + // Currently only support constant axis tensor. + tensors[0].allocation_type = kTfLiteMmapRo; + // Place a unique value in the uninitialized output buffer. + for (int i = 0; i < output1_dims_count; ++i) { + output1_data[i] = 23; + } + + for (int i = 0; i < output2_dims_count; ++i) { + output2_data[i] = 23; + } + + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 2, 2, 3 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = tflite::ops::micro::Register_SPLIT(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output1_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output1_data[i], output1_data[i], 1e-5f); + } + + for (int i = 0; i < output2_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output2_data[i], output2_data[i], 1e-5f); + } +} + +void TestSplitFourOutputsFloat( + int *input_dims_data, const float *input_data, int *axis_dims_data, + const int32_t *axis_data, int *output1_dims_data, + const float *expected_output1_data, int *output2_dims_data, + const float *expected_output2_data, int *output3_dims_data, + const float *expected_output3_data, int *output4_dims_data, + const float *expected_output4_data, float *output1_data, + float *output2_data, float *output3_data, float *output4_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *axis_dims = IntArrayFromInts(axis_dims_data); + TfLiteIntArray *output1_dims = IntArrayFromInts(output1_dims_data); + TfLiteIntArray *output2_dims = IntArrayFromInts(output2_dims_data); + TfLiteIntArray *output3_dims = IntArrayFromInts(output3_dims_data); + TfLiteIntArray *output4_dims = IntArrayFromInts(output4_dims_data); + const int output1_dims_count = ElementCount(*output1_dims); + const int output2_dims_count = ElementCount(*output2_dims); + const int output3_dims_count = ElementCount(*output3_dims); + const int output4_dims_count = ElementCount(*output4_dims); + + constexpr int input_size = 1; + constexpr int output_size = 4; + constexpr int axis_size = 1; + constexpr int tensors_size = input_size + output_size + axis_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(axis_data, axis_dims), + CreateTensor(input_data, input_dims), + CreateTensor(output1_data, output1_dims), + CreateTensor(output2_data, output2_dims), + CreateTensor(output3_data, output1_dims), + CreateTensor(output4_data, output1_dims) + }; + + // Currently only support constant axis tensor. + tensors[0].allocation_type = kTfLiteMmapRo; + // Place a unique value in the uninitialized output buffer. + for (int i = 0; i < output1_dims_count; ++i) { + output1_data[i] = 23; + } + for (int i = 0; i < output2_dims_count; ++i) { + output2_data[i] = 23; + } + for (int i = 0; i < output3_dims_count; ++i) { + output3_data[i] = 23; + } + for (int i = 0; i < output4_dims_count; ++i) { + output4_data[i] = 23; + } + + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 4, 2, 3, 4, 5 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = tflite::ops::micro::Register_SPLIT(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output1_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output1_data[i], output1_data[i], 1e-5f); + } + for (int i = 0; i < output2_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output2_data[i], output2_data[i], 1e-5f); + } + for (int i = 0; i < output3_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output3_data[i], output3_data[i], 1e-5f); + } + for (int i = 0; i < output4_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output4_data[i], output4_data[i], 1e-5f); + } +} + +void TestSplitTwoOutputsQuantized( + int *input_dims_data, const uint8_t *input_data, int *axis_dims_data, + const int32_t *axis_data, int *output1_dims_data, + const uint8_t *expected_output1_data, int *output2_dims_data, + const uint8_t *expected_output2_data, uint8_t *output1_data, + uint8_t *output2_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *axis_dims = IntArrayFromInts(axis_dims_data); + TfLiteIntArray *output1_dims = IntArrayFromInts(output1_dims_data); + TfLiteIntArray *output2_dims = IntArrayFromInts(output2_dims_data); + const int output1_dims_count = ElementCount(*output1_dims); + const int output2_dims_count = ElementCount(*output2_dims); + + constexpr int input_size = 1; + constexpr int output_size = 2; + constexpr int axis_size = 1; + constexpr int tensors_size = input_size + output_size + axis_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(axis_data, axis_dims), + CreateQuantizedTensor(input_data, input_dims, 0, 10), + CreateQuantizedTensor(output1_data, output1_dims, 0, 10), + CreateQuantizedTensor(output2_data, output2_dims, 0, 10) + }; + + // Currently only support constant axis tensor. + tensors[0].allocation_type = kTfLiteMmapRo; + + // Place a unique value in the uninitialized output buffer. + for (int i = 0; i < output1_dims_count; ++i) { + output1_data[i] = 23; + } + + for (int i = 0; i < output2_dims_count; ++i) { + output2_data[i] = 23; + } + + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 2, 2, 3 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = tflite::ops::micro::Register_SPLIT(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output1_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output1_data[i], output1_data[i]); + } + + for (int i = 0; i < output2_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output2_data[i], output2_data[i]); + } +} + +void TestSplitTwoOutputsQuantized32( + int *input_dims_data, const int32_t *input_data, int *axis_dims_data, + const int32_t *axis_data, int *output1_dims_data, + const int32_t *expected_output1_data, int *output2_dims_data, + const int32_t *expected_output2_data, int32_t *output1_data, + int32_t *output2_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *axis_dims = IntArrayFromInts(axis_dims_data); + TfLiteIntArray *output1_dims = IntArrayFromInts(output1_dims_data); + TfLiteIntArray *output2_dims = IntArrayFromInts(output2_dims_data); + const int output1_dims_count = ElementCount(*output1_dims); + const int output2_dims_count = ElementCount(*output2_dims); + + constexpr int input_size = 1; + constexpr int output_size = 2; + constexpr int axis_size = 1; + constexpr int tensors_size = input_size + output_size + axis_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(axis_data, axis_dims), CreateTensor(input_data, input_dims), + CreateTensor(output1_data, output1_dims), + CreateTensor(output2_data, output2_dims) + }; + + // Currently only support constant axis tensor. + tensors[0].allocation_type = kTfLiteMmapRo; + + // Place a unique value in the uninitialized output buffer. + for (int i = 0; i < output1_dims_count; ++i) { + output1_data[i] = 23; + } + + for (int i = 0; i < output2_dims_count; ++i) { + output2_data[i] = 23; + } + + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 2, 2, 3 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = tflite::ops::micro::Register_SPLIT(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output1_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output1_data[i], output1_data[i]); + } + + for (int i = 0; i < output2_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output2_data[i], output2_data[i]); + } +} + +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TwoSplitFourDimensionalAxisZero) +{ + int input_shape[] = { 4, 2, 2, 2, 2 }; + const float input_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16 }; + int axis_shape[] = { 1, 1 }; + const int32_t axis_data[] = { 0 }; + int output1_shape[] = { 4, 1, 2, 2, 2 }; + const float golden1[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + int output2_shape[] = { 4, 1, 2, 2, 2 }; + const float golden2[] = { 9, 10, 11, 12, 13, 14, 15, 16 }; + + constexpr int output1_dims_count = 8; + constexpr int output2_dims_count = 8; + float output1_data[output1_dims_count]; + float output2_data[output2_dims_count]; + tflite::testing::TestSplitTwoOutputsFloat( + input_shape, input_data, axis_shape, axis_data, output1_shape, golden1, + output2_shape, golden2, output1_data, output2_data); +} + +TF_LITE_MICRO_TEST(TwoSplitFourDimensionalAxisOne) +{ + int input_shape[] = { 4, 2, 2, 2, 2 }; + const float input_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16 }; + int axis_shape[] = { 1, 1 }; + const int32_t axis_data[] = { 1 }; + int output1_shape[] = { 4, 2, 1, 2, 2 }; + const float golden1[] = { 1, 2, 3, 4, 9, 10, 11, 12 }; + int output2_shape[] = { 4, 2, 1, 2, 2 }; + const float golden2[] = { 5, 6, 7, 8, 13, 14, 15, 16 }; + + constexpr int output1_dims_count = 8; + constexpr int output2_dims_count = 8; + float output1_data[output1_dims_count]; + float output2_data[output2_dims_count]; + tflite::testing::TestSplitTwoOutputsFloat( + input_shape, input_data, axis_shape, axis_data, output1_shape, golden1, + output2_shape, golden2, output1_data, output2_data); +} + +TF_LITE_MICRO_TEST(TwoSplitFourDimensionalAxisTwo) +{ + int input_shape[] = { 4, 2, 2, 2, 2 }; + const float input_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16 }; + int axis_shape[] = { 1, 1 }; + const int32_t axis_data[] = { 2 }; + int output1_shape[] = { 4, 2, 2, 1, 2 }; + const float golden1[] = { 1, 2, 5, 6, 9, 10, 13, 14 }; + int output2_shape[] = { 4, 2, 2, 1, 2 }; + const float golden2[] = { 3, 4, 7, 8, 11, 12, 15, 16 }; + + constexpr int output1_dims_count = 8; + constexpr int output2_dims_count = 8; + float output1_data[output1_dims_count]; + float output2_data[output2_dims_count]; + tflite::testing::TestSplitTwoOutputsFloat( + input_shape, input_data, axis_shape, axis_data, output1_shape, golden1, + output2_shape, golden2, output1_data, output2_data); +} + +TF_LITE_MICRO_TEST(TwoSplitFourDimensionalAxisThree) +{ + int input_shape[] = { 4, 2, 2, 2, 2 }; + const float input_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16 }; + int axis_shape[] = { 1, 1 }; + const int32_t axis_data[] = { 3 }; + int output1_shape[] = { 4, 2, 2, 2, 1 }; + const float golden1[] = { 1, 3, 5, 7, 9, 11, 13, 15 }; + int output2_shape[] = { 4, 2, 2, 2, 1 }; + const float golden2[] = { 2, 4, 6, 8, 10, 12, 14, 16 }; + + constexpr int output1_dims_count = 8; + constexpr int output2_dims_count = 8; + float output1_data[output1_dims_count]; + float output2_data[output2_dims_count]; + tflite::testing::TestSplitTwoOutputsFloat( + input_shape, input_data, axis_shape, axis_data, output1_shape, golden1, + output2_shape, golden2, output1_data, output2_data); +} + +TF_LITE_MICRO_TEST(TwoSplitFourDimensionalNegativeAxis) +{ + int input_shape[] = { 4, 2, 2, 2, 2 }; + const float input_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16 }; + int axis_shape[] = { 1, 1 }; + const int32_t axis_data[] = { -4 }; + int output1_shape[] = { 4, 1, 2, 2, 2 }; + const float golden1[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + int output2_shape[] = { 4, 1, 2, 2, 2 }; + const float golden2[] = { 9, 10, 11, 12, 13, 14, 15, 16 }; + + constexpr int output1_dims_count = 8; + constexpr int output2_dims_count = 8; + float output1_data[output1_dims_count]; + float output2_data[output2_dims_count]; + tflite::testing::TestSplitTwoOutputsFloat( + input_shape, input_data, axis_shape, axis_data, output1_shape, golden1, + output2_shape, golden2, output1_data, output2_data); +} + +TF_LITE_MICRO_TEST(FourSplit) +{ + int input_shape[] = { 1, 4 }; + const float input_data[] = { 1, 2, 3, 4 }; + int axis_shape[] = { 1, 1 }; + const int32_t axis_data[] = { 0 }; + int output1_shape[] = { 1, 1 }; + const float golden1[] = { 1 }; + int output2_shape[] = { 1, 1 }; + const float golden2[] = { 2 }; + int output3_shape[] = { 1, 1 }; + const float golden3[] = { 3 }; + int output4_shape[] = { 1, 1 }; + const float golden4[] = { 4 }; + + constexpr int output1_dims_count = 1; + constexpr int output2_dims_count = 1; + constexpr int output3_dims_count = 1; + constexpr int output4_dims_count = 1; + float output1_data[output1_dims_count]; + float output2_data[output2_dims_count]; + float output3_data[output3_dims_count]; + float output4_data[output4_dims_count]; + tflite::testing::TestSplitFourOutputsFloat( + input_shape, input_data, axis_shape, axis_data, output1_shape, golden1, + output2_shape, golden2, output3_shape, golden3, output4_shape, golden4, + output1_data, output2_data, output3_data, output4_data); +} + +TF_LITE_MICRO_TEST(TwoSplitOneDimensional) +{ + int input_shape[] = { 1, 2 }; + const float input_data[] = { 1, 2 }; + int axis_shape[] = { 1, 1 }; + const int32_t axis_data[] = { 0 }; + int output1_shape[] = { 1, 1 }; + const float golden1[] = { 1 }; + int output2_shape[] = { 1, 1 }; + const float golden2[] = { 2 }; + + constexpr int output1_dims_count = 8; + constexpr int output2_dims_count = 8; + float output1_data[output1_dims_count]; + float output2_data[output2_dims_count]; + tflite::testing::TestSplitTwoOutputsFloat( + input_shape, input_data, axis_shape, axis_data, output1_shape, golden1, + output2_shape, golden2, output1_data, output2_data); +} + +TF_LITE_MICRO_TEST(TwoSplitFourDimensionalQuantized) +{ + int input_shape[] = { 4, 2, 2, 2, 2 }; + const uint8_t input_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16 }; + int axis_shape[] = { 1, 1 }; + const int32_t axis_data[] = { 1 }; + int output1_shape[] = { 4, 2, 1, 2, 2 }; + const uint8_t golden1[] = { 1, 2, 3, 4, 9, 10, 11, 12 }; + int output2_shape[] = { 4, 2, 1, 2, 2 }; + const uint8_t golden2[] = { 5, 6, 7, 8, 13, 14, 15, 16 }; + + constexpr int output1_dims_count = 8; + constexpr int output2_dims_count = 8; + uint8_t output1_data[output1_dims_count]; + uint8_t output2_data[output2_dims_count]; + tflite::testing::TestSplitTwoOutputsQuantized( + input_shape, input_data, axis_shape, axis_data, output1_shape, golden1, + output2_shape, golden2, output1_data, output2_data); +} + +TF_LITE_MICRO_TEST(TwoSplitFourDimensionalQuantized32) +{ + int input_shape[] = { 4, 2, 2, 2, 2 }; + const int32_t input_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16 }; + int axis_shape[] = { 1, 1 }; + const int32_t axis_data[] = { 1 }; + int output1_shape[] = { 4, 2, 1, 2, 2 }; + const int32_t golden1[] = { 1, 2, 3, 4, 9, 10, 11, 12 }; + int output2_shape[] = { 4, 2, 1, 2, 2 }; + const int32_t golden2[] = { 5, 6, 7, 8, 13, 14, 15, 16 }; + + constexpr int output1_dims_count = 8; + constexpr int output2_dims_count = 8; + int32_t output1_data[output1_dims_count]; + int32_t output2_data[output2_dims_count]; + tflite::testing::TestSplitTwoOutputsQuantized32( + input_shape, input_data, axis_shape, axis_data, output1_shape, golden1, + output2_shape, golden2, output1_data, output2_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/split_v.cc b/components/tflite/tensorflow/lite/micro/kernels/split_v.cc new file mode 100644 index 00000000..cb01d4a6 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/split_v.cc @@ -0,0 +1,140 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace split_v { + +template +TfLiteStatus SplitImpl(TfLiteContext *context, TfLiteNode *node, + const TfLiteEvalTensor *input, int axis_value) +{ + const TfLiteIntArray *input_dims = input->dims; + const TfLiteEvalTensor *output0 = + tflite::micro::GetEvalOutput(context, node, 0); + + const int split_dimensions = input_dims->size; + + TFLITE_DCHECK_LT(axis_value, split_dimensions); + TFLITE_DCHECK_EQ(output0->dims->size, split_dimensions); + + int64_t split_size = 0; + const int output_count = NumOutputs(node); + for (int i = 0; i < output_count; i++) { + split_size += + tflite::micro::GetEvalOutput(context, node, i)->dims->data[axis_value]; + } + TFLITE_DCHECK_EQ(split_size, input_dims->data[axis_value]); + int64_t outer_size = 1; + for (int i = 0; i < axis_value; ++i) { + outer_size *= input_dims->data[i]; + } + + int64_t base_inner_size = 1; + for (int i = axis_value + 1; i < split_dimensions; ++i) { + base_inner_size *= input_dims->data[i]; + } + + const T *input_ptr = tflite::micro::GetTensorData(input); + for (int k = 0; k < outer_size; ++k) { + for (int i = 0; i < output_count; ++i) { + TfLiteEvalTensor *output_tensor = + tflite::micro::GetEvalOutput(context, node, i); + T *output_data = tflite::micro::GetTensorData(output_tensor); + const int copy_size = + output_tensor->dims->data[axis_value] * base_inner_size; + T *output_ptr = output_data + k * copy_size; + for (int j = 0; j < copy_size; ++j) + output_ptr[j] = input_ptr[j]; + input_ptr += copy_size; + } + } + + return kTfLiteOk; +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE_EQ(context, NumInputs(node), 3); + + // Dynamic output tensors are needed if axis tensor is not constant. + // But Micro doesn't support dynamic memory allocation, so we only support + // constant axis tensor for now. + const TfLiteTensor *axis = GetInput(context, node, 2); + TF_LITE_ENSURE_MSG(context, IsConstantTensor(axis), + "Non constant axis tensor not supported"); + + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = tflite::micro::GetEvalInput(context, node, 0); + const TfLiteEvalTensor *axis = tflite::micro::GetEvalInput(context, node, 2); + + int axis_value = tflite::micro::GetTensorData(axis)[0]; + if (axis_value < 0) { + axis_value += input->dims->size; + } + + TF_LITE_ENSURE(context, axis_value >= 0); + TF_LITE_ENSURE(context, axis_value < input->dims->size); + + switch (input->type) { + case kTfLiteFloat32: { + return SplitImpl(context, node, input, axis_value); + } + case kTfLiteInt8: { + return SplitImpl(context, node, input, axis_value); + } + case kTfLiteInt16: { + return SplitImpl(context, node, input, axis_value); + } + case kTfLiteInt32: { + return SplitImpl(context, node, input, axis_value); + } + default: + TF_LITE_KERNEL_LOG(context, "Type %s currently not supported.", + TfLiteTypeGetName(input->type)); + return kTfLiteError; + } + return kTfLiteOk; +} + +} // namespace split_v + +TfLiteRegistration Register_SPLIT_V() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/split_v::Prepare, + /*invoke=*/split_v::Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/split_v_test.cc b/components/tflite/tensorflow/lite/micro/kernels/split_v_test.cc new file mode 100644 index 00000000..c9762221 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/split_v_test.cc @@ -0,0 +1,478 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/debug_log.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { + +template +struct OutputTensors { + float *data[N]; + int *dims[N]; + float *expected_output_data[N]; +}; +template +void TestSplitVFloat(int *input_dims_data, const float *input_data, + int *axis_dims_data, const int32_t *axis_data, + int *split_dims_data, const int32_t *split_data, + const OutputTensors &output_tensors) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *axis_dims = IntArrayFromInts(axis_dims_data); + TfLiteIntArray *split_dims = IntArrayFromInts(split_dims_data); + TfLiteIntArray *output_dims[N]; + for (int i = 0; i < N; i++) + output_dims[i] = IntArrayFromInts(output_tensors.dims[i]); + + // Place a unique value in the uninitialized output buffer. + for (int i = 0; i < N; i++) { + int dim_count = ElementCount(*output_dims[i]); + for (int j = 0; j < dim_count; j++) { + (output_tensors.data[i])[j] = 23; + } + } + constexpr int input_size = 1; + constexpr int axis_size = 1; + constexpr int split_size = 1; + constexpr int output_size = N; + + constexpr int tensors_size = + input_size + output_size + axis_size + split_size; + + // first input tensor is data + // second is size_splits + // third is axis + // then come outputs + + TfLiteTensor tensors[tensors_size]; + tensors[0] = CreateTensor(input_data, input_dims); + tensors[1] = CreateTensor(split_data, split_dims); + tensors[2] = CreateTensor(axis_data, axis_dims); + + // add output tensors + for (int i = 0; i < N; i++) + tensors[3 + i] = CreateTensor(output_tensors.data[i], output_dims[i]); + + tensors[2].allocation_type = kTfLiteMmapRo; + tensors[1].allocation_type = kTfLiteMmapRo; + + int inputs_array_data[] = { 3, 0, 1, 2 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[N + 1]; + outputs_array_data[0] = N; + for (int i = 0; i < N; i++) + outputs_array_data[i + 1] = i + 3; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = + tflite::ops::micro::Register_SPLIT_V(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < N; i++) { + int dim_count = ElementCount(*output_dims[i]); + for (int j = 0; j < dim_count; j++) { + TF_LITE_MICRO_EXPECT_NEAR((output_tensors.expected_output_data[i])[j], + (output_tensors.data[i])[j], 1e-5f); + } + } +} + +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(SPLIT_V_ThreeOutputs) +{ + constexpr int output1_dims_count = 3; + constexpr int output2_dims_count = 3; + constexpr int output3_dims_count = 6; + float output1_data[output1_dims_count]; + float output2_data[output2_dims_count]; + float output3_data[output3_dims_count]; + int input_shape[] = { 2, 4, 3 }; + float input_values[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + int axis_shape[] = { 1, 1 }; + int32_t axis_values[] = { 0 }; + int split_shape[] = { 1, 3 }; + int32_t split_values[] = { 1, 1, 2 }; + int output1_shape[] = { 2, 1, 3 }; + float output1_values[] = { 1, 2, 3 }; + int output2_shape[] = { 2, 1, 3 }; + float output2_values[] = { 4, 5, 6 }; + int output3_shape[] = { 2, 2, 3 }; + float output3_values[] = { 7, 8, 9, 10, 11, 12 }; + + tflite::testing::OutputTensors<3> output_tensors; + output_tensors.data[0] = output1_data; + output_tensors.data[1] = output2_data; + output_tensors.data[2] = output3_data; + + output_tensors.dims[0] = output1_shape; + output_tensors.dims[1] = output2_shape; + output_tensors.dims[2] = output3_shape; + + output_tensors.expected_output_data[0] = output1_values; + output_tensors.expected_output_data[1] = output2_values; + output_tensors.expected_output_data[2] = output3_values; + + tflite::testing::TestSplitVFloat(input_shape, input_values, axis_shape, + axis_values, split_shape, split_values, + output_tensors); +} + +TF_LITE_MICRO_TEST(SPLIT_V_FourDimensionalFloatAxis0) +{ + constexpr int output1_dims_count = 8; + constexpr int output2_dims_count = 8; + float output1_data[output1_dims_count]; + float output2_data[output2_dims_count]; + + int input_shape[] = { 4, 2, 2, 2, 2 }; + float input_values[] = { 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16 }; + int axis_shape[] = { 1, 1 }; + int32_t axis_values[] = { 0 }; + int split_shape[] = { 1, 2 }; + int32_t split_values[] = { 1, 1 }; + int output1_shape[] = { 4, 1, 2, 2, 2 }; + float output1_values[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + int output2_shape[] = { 4, 1, 2, 2, 2 }; + float output2_values[] = { 9, 10, 11, 12, 13, 14, 15, 16 }; + + tflite::testing::OutputTensors<2> output_tensors; + + output_tensors.data[0] = output1_data; + output_tensors.data[1] = output2_data; + + output_tensors.dims[0] = output1_shape; + output_tensors.dims[1] = output2_shape; + + output_tensors.expected_output_data[0] = output1_values; + output_tensors.expected_output_data[1] = output2_values; + + tflite::testing::TestSplitVFloat(input_shape, input_values, axis_shape, + axis_values, split_shape, split_values, + output_tensors); +} + +TF_LITE_MICRO_TEST(SPLIT_V_FourDimensionalFloatAxis1) +{ + constexpr int output1_dims_count = 8; + constexpr int output2_dims_count = 8; + float output1_data[output1_dims_count]; + float output2_data[output2_dims_count]; + + int input_shape[] = { 4, 2, 2, 2, 2 }; + float input_values[] = { 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16 }; + int axis_shape[] = { 1, 1 }; + int32_t axis_values[] = { 1 }; + int split_shape[] = { 1, 2 }; + int32_t split_values[] = { 1, 1 }; + int output1_shape[] = { 4, 2, 1, 2, 2 }; + float output1_values[] = { 1, 2, 3, 4, 9, 10, 11, 12 }; + int output2_shape[] = { 4, 2, 1, 2, 2 }; + float output2_values[] = { 5, 6, 7, 8, 13, 14, 15, 16 }; + + tflite::testing::OutputTensors<2> output_tensors; + + output_tensors.data[0] = output1_data; + output_tensors.data[1] = output2_data; + + output_tensors.dims[0] = output1_shape; + output_tensors.dims[1] = output2_shape; + + output_tensors.expected_output_data[0] = output1_values; + output_tensors.expected_output_data[1] = output2_values; + + tflite::testing::TestSplitVFloat(input_shape, input_values, axis_shape, + axis_values, split_shape, split_values, + output_tensors); +} + +TF_LITE_MICRO_TEST(SPLIT_VFourDimensionalFloatAxis2) +{ + constexpr int output1_dims_count = 8; + constexpr int output2_dims_count = 8; + float output1_data[output1_dims_count]; + float output2_data[output2_dims_count]; + + int input_shape[] = { 4, 2, 2, 2, 2 }; + float input_values[] = { 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16 }; + int axis_shape[] = { 1, 1 }; + int32_t axis_values[] = { 2 }; + int split_shape[] = { 1, 2 }; + int32_t split_values[] = { 1, 1 }; + int output1_shape[] = { 4, 2, 2, 1, 2 }; + float output1_values[] = { 1, 2, 5, 6, 9, 10, 13, 14 }; + int output2_shape[] = { 4, 2, 2, 1, 2 }; + float output2_values[] = { 3, 4, 7, 8, 11, 12, 15, 16 }; + + tflite::testing::OutputTensors<2> output_tensors; + + output_tensors.data[0] = output1_data; + output_tensors.data[1] = output2_data; + + output_tensors.dims[0] = output1_shape; + output_tensors.dims[1] = output2_shape; + + output_tensors.expected_output_data[0] = output1_values; + output_tensors.expected_output_data[1] = output2_values; + + tflite::testing::TestSplitVFloat(input_shape, input_values, axis_shape, + axis_values, split_shape, split_values, + output_tensors); +} + +TF_LITE_MICRO_TEST(SPLIT_V_FourDimensionalFloatAxis3) +{ + constexpr int output1_dims_count = 8; + constexpr int output2_dims_count = 8; + float output1_data[output1_dims_count]; + float output2_data[output2_dims_count]; + int input_shape[] = { 4, 2, 2, 2, 2 }; + float input_values[] = { 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16 }; + int axis_shape[] = { 1, 1 }; + int32_t axis_values[] = { 3 }; + int split_shape[] = { 1, 2 }; + int32_t split_values[] = { 1, 1 }; + int output1_shape[] = { 4, 2, 2, 2, 1 }; + float output1_values[] = { 1, 3, 5, 7, 9, 11, 13, 15 }; + int output2_shape[] = { 4, 2, 2, 2, 1 }; + float output2_values[] = { 2, 4, 6, 8, 10, 12, 14, 16 }; + + tflite::testing::OutputTensors<2> output_tensors; + + output_tensors.data[0] = output1_data; + output_tensors.data[1] = output2_data; + + output_tensors.dims[0] = output1_shape; + output_tensors.dims[1] = output2_shape; + + output_tensors.expected_output_data[0] = output1_values; + output_tensors.expected_output_data[1] = output2_values; + + tflite::testing::TestSplitVFloat(input_shape, input_values, axis_shape, + axis_values, split_shape, split_values, + output_tensors); +} + +TF_LITE_MICRO_TEST(SPLIT_V_FourDimensionalFloatNegativeAxis) +{ + constexpr int output1_dims_count = 8; + constexpr int output2_dims_count = 8; + float output1_data[output1_dims_count]; + float output2_data[output2_dims_count]; + + int input_shape[] = { 4, 2, 2, 2, 2 }; + float input_values[] = { 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16 }; + int axis_shape[] = { 1, 1 }; + int32_t axis_values[] = { -4 }; + int split_shape[] = { 1, 2 }; + int32_t split_values[] = { 1, 1 }; + int output1_shape[] = { 4, 1, 2, 2, 2 }; + float output1_values[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + int output2_shape[] = { 4, 1, 2, 2, 2 }; + float output2_values[] = { 9, 10, 11, 12, 13, 14, 15, 16 }; + + tflite::testing::OutputTensors<2> output_tensors; + + output_tensors.data[0] = output1_data; + output_tensors.data[1] = output2_data; + + output_tensors.dims[0] = output1_shape; + output_tensors.dims[1] = output2_shape; + + output_tensors.expected_output_data[0] = output1_values; + output_tensors.expected_output_data[1] = output2_values; + + tflite::testing::TestSplitVFloat(input_shape, input_values, axis_shape, + axis_values, split_shape, split_values, + output_tensors); +} + +TF_LITE_MICRO_TEST(SPLIT_V_OneDimensionalFloatAxis0) +{ + constexpr int output1_dims_count = 1; + constexpr int output2_dims_count = 1; + constexpr int output3_dims_count = 1; + constexpr int output4_dims_count = 1; + constexpr int output5_dims_count = 1; + constexpr int output6_dims_count = 1; + constexpr int output7_dims_count = 1; + constexpr int output8_dims_count = 1; + + float output1_data[output1_dims_count]; + float output2_data[output2_dims_count]; + float output3_data[output3_dims_count]; + float output4_data[output4_dims_count]; + float output5_data[output5_dims_count]; + float output6_data[output6_dims_count]; + float output7_data[output7_dims_count]; + float output8_data[output8_dims_count]; + int input_shape[] = { 1, 8 }; + float input_values[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + int axis_shape[] = { 1, 1 }; + int32_t axis_value[] = { 0 }; + int split_size_shape[] = { 1, 8 }; + int32_t split[] = { 1, 1, 1, 1, 1, 1, 1, 1 }; + int output1_shape[] = { 1, 1 }; + float output1_values[] = { 1 }; + int output2_shape[] = { 1, 1 }; + float output2_values[] = { 2 }; + + int output3_shape[] = { 1, 1 }; + float output3_values[] = { 3 }; + int output4_shape[] = { 1, 1 }; + float output4_values[] = { 4 }; + + int output5_shape[] = { 1, 1 }; + float output5_values[] = { 5 }; + int output6_shape[] = { 1, 1 }; + float output6_values[] = { 6 }; + + int output7_shape[] = { 1, 1 }; + float output7_values[] = { 7 }; + int output8_shape[] = { 1, 1 }; + float output8_values[] = { 8 }; + + tflite::testing::OutputTensors<8> output_tensors; + + output_tensors.data[0] = output1_data; + output_tensors.data[1] = output2_data; + output_tensors.data[2] = output3_data; + output_tensors.data[3] = output4_data; + output_tensors.data[4] = output5_data; + output_tensors.data[5] = output6_data; + output_tensors.data[6] = output7_data; + output_tensors.data[7] = output8_data; + + output_tensors.dims[0] = output1_shape; + output_tensors.dims[1] = output2_shape; + output_tensors.dims[2] = output3_shape; + output_tensors.dims[3] = output4_shape; + output_tensors.dims[4] = output5_shape; + output_tensors.dims[5] = output6_shape; + output_tensors.dims[6] = output7_shape; + output_tensors.dims[7] = output8_shape; + + output_tensors.expected_output_data[0] = output1_values; + output_tensors.expected_output_data[1] = output2_values; + output_tensors.expected_output_data[2] = output3_values; + output_tensors.expected_output_data[3] = output4_values; + output_tensors.expected_output_data[4] = output5_values; + output_tensors.expected_output_data[5] = output6_values; + output_tensors.expected_output_data[6] = output7_values; + output_tensors.expected_output_data[7] = output8_values; + + tflite::testing::TestSplitVFloat(input_shape, input_values, axis_shape, + axis_value, split_size_shape, split, + output_tensors); +} + +TF_LITE_MICRO_TEST(SPLIT_V_OneDimensionalFloatTest2) +{ + constexpr int output1_dims_count = 1; + constexpr int output2_dims_count = 1; + constexpr int output3_dims_count = 1; + constexpr int output4_dims_count = 1; + constexpr int output5_dims_count = 1; + constexpr int output6_dims_count = 1; + constexpr int output7_dims_count = 2; + + float output1_data[output1_dims_count]; + float output2_data[output2_dims_count]; + float output3_data[output3_dims_count]; + float output4_data[output4_dims_count]; + float output5_data[output5_dims_count]; + float output6_data[output6_dims_count]; + float output7_data[output7_dims_count]; + + int input_shape[] = { 1, 8 }; + float input_values[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + int axis_shape[] = { 1, 1 }; + int32_t axis_value[] = { 0 }; + int split_size_shape[] = { 1, 8 }; + int32_t split[] = { 1, 1, 1, 1, 1, 1, 2, -1 }; + int output1_shape[] = { 1, 1 }; + float output1_values[] = { 1 }; + int output2_shape[] = { 1, 1 }; + float output2_values[] = { 2 }; + + int output3_shape[] = { 1, 1 }; + float output3_values[] = { 3 }; + int output4_shape[] = { 1, 1 }; + float output4_values[] = { 4 }; + + int output5_shape[] = { 1, 1 }; + float output5_values[] = { 5 }; + int output6_shape[] = { 1, 1 }; + float output6_values[] = { 6 }; + + int output7_shape[] = { 1, 2 }; + float output7_values[] = { 7, 8 }; + int output8_shape[] = { 1, 0 }; + float output8_values[1] = {}; + + tflite::testing::OutputTensors<8> output_tensors; + + output_tensors.data[0] = output1_data; + output_tensors.data[1] = output2_data; + output_tensors.data[2] = output3_data; + output_tensors.data[3] = output4_data; + output_tensors.data[4] = output5_data; + output_tensors.data[5] = output6_data; + output_tensors.data[6] = output7_data; + output_tensors.data[7] = NULL; + + output_tensors.dims[0] = output1_shape; + output_tensors.dims[1] = output2_shape; + output_tensors.dims[2] = output3_shape; + output_tensors.dims[3] = output4_shape; + output_tensors.dims[4] = output5_shape; + output_tensors.dims[5] = output6_shape; + output_tensors.dims[6] = output7_shape; + output_tensors.dims[7] = output8_shape; + + output_tensors.expected_output_data[0] = output1_values; + output_tensors.expected_output_data[1] = output2_values; + output_tensors.expected_output_data[2] = output3_values; + output_tensors.expected_output_data[3] = output4_values; + output_tensors.expected_output_data[4] = output5_values; + output_tensors.expected_output_data[5] = output6_values; + output_tensors.expected_output_data[6] = output7_values; + output_tensors.expected_output_data[7] = output8_values; + + tflite::testing::TestSplitVFloat(input_shape, input_values, axis_shape, + axis_value, split_size_shape, split, + output_tensors); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/squeeze.cc b/components/tflite/tensorflow/lite/micro/kernels/squeeze.cc new file mode 100644 index 00000000..eeee6e9f --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/squeeze.cc @@ -0,0 +1,115 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/process_broadcast_shapes.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/memory_helpers.h" + +namespace tflite { +namespace { + +struct SqueezeContext { + SqueezeContext(TfLiteContext *context, TfLiteNode *node) + : params(reinterpret_cast(node->builtin_data)), + input(GetInput(context, node, 0)), + output(GetOutput(context, node, 0)) + { + } + TfLiteSqueezeParams *params; + const TfLiteTensor *const input; + TfLiteTensor *output; +}; + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + + SqueezeContext op_context(context, node); + const int input_num_dims = NumDimensions(op_context.input); + const int num_squeeze_dims = op_context.params->num_squeeze_dims; + + // Determines number of dimensions of output tensor after squeeze. + const TfLiteIntArray *input_dims = op_context.input->dims; + const TfLiteIntArray *output_dims = op_context.output->dims; + const int *squeeze_dims = op_context.params->squeeze_dims; + + constexpr int max_squeeze_dims = 8; + TF_LITE_ENSURE(context, input_num_dims <= max_squeeze_dims); + bool should_squeeze[max_squeeze_dims] = {}; + + if (num_squeeze_dims == 0) { + for (int idx = 0; idx < input_num_dims; ++idx) { + if (input_dims->data[idx] == 1) { + should_squeeze[idx] = true; + } + } + } else { + for (int idx = 0; idx < num_squeeze_dims; ++idx) { + int current = squeeze_dims[idx] < 0 ? squeeze_dims[idx] + input_num_dims : squeeze_dims[idx]; + TF_LITE_ENSURE(context, current >= 0 && current < input_num_dims && + input_dims->data[current] == 1); + should_squeeze[current] = true; + } + } + + // Ensure output dimensions are big enough. + for (int in_idx = 0, out_idx = 0; in_idx < input_num_dims; ++in_idx) { + if (!should_squeeze[in_idx]) { + TFLITE_CHECK_GE(output_dims->data[out_idx++], input_dims->data[in_idx]); + } + } + + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + SqueezeContext op_context(context, node); + + if (op_context.input->type == kTfLiteString) { + TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.", + TfLiteTypeGetName(op_context.input->type), + op_context.input->type); + return kTfLiteError; + } + + TF_LITE_ENSURE_EQ(context, op_context.input->bytes, op_context.output->bytes); + memcpy(op_context.output->data.raw, op_context.input->data.raw, + op_context.input->bytes); + return kTfLiteOk; +} + +} // namespace + +TfLiteRegistration Register_SQUEEZE() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/squeeze_test.cc b/components/tflite/tensorflow/lite/micro/kernels/squeeze_test.cc new file mode 100644 index 00000000..67504d05 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/squeeze_test.cc @@ -0,0 +1,131 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +int input_dims_data_common[] = { 3, 1, 24, 1 }; +int output_dims_data_common[] = { 1, 24 }; +const int input_data_common[] = { 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24 }; +const int golden_common[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 }; +const int expected_output_size_common = 24; + +void TestSqueezeOp(int *input_dims_data, const int *input_data, + int *output_dims_data, int *output_data, const int *golden, + int expected_output_size, + TfLiteSqueezeParams *squeeze_params) +{ + TfLiteIntArray *input_dims1 = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims1 = IntArrayFromInts(output_dims_data); + + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + + TfLiteTensor tensors[tensors_size]; + tensors[0] = CreateTensor(input_data, input_dims1); + tensors[1] = CreateTensor(output_data, output_dims1); + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = Register_SQUEEZE(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + reinterpret_cast(squeeze_params)); + + const char *init_data = reinterpret_cast(squeeze_params); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare(init_data)); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < expected_output_size; ++i) { + TF_LITE_MICRO_EXPECT_EQ(golden[i], output_data[i]); + } +} +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(SqueezeAll) +{ + int output_data[24]; + TfLiteSqueezeParams squeeze_params = { {}, 0 }; + + tflite::testing::TestSqueezeOp(tflite::testing::input_dims_data_common, + tflite::testing::input_data_common, + tflite::testing::output_dims_data_common, + output_data, tflite::testing::golden_common, + tflite::testing::expected_output_size_common, + &squeeze_params); +} + +TF_LITE_MICRO_TEST(SqueezeSelectedAxis) +{ + int output_data[24]; + TfLiteSqueezeParams squeeze_params = { { 2 }, 1 }; + int output_dims_data_common[] = { 2, 1, 24 }; + + tflite::testing::TestSqueezeOp( + tflite::testing::input_dims_data_common, + tflite::testing::input_data_common, output_dims_data_common, output_data, + tflite::testing::golden_common, + tflite::testing::expected_output_size_common, &squeeze_params); +} + +TF_LITE_MICRO_TEST(SqueezeNegativeAxis) +{ + int output_data[24]; + TfLiteSqueezeParams squeeze_params = { { -1, 0 }, 2 }; + + tflite::testing::TestSqueezeOp(tflite::testing::input_dims_data_common, + tflite::testing::input_data_common, + tflite::testing::output_dims_data_common, + output_data, tflite::testing::golden_common, + tflite::testing::expected_output_size_common, + &squeeze_params); +} + +TF_LITE_MICRO_TEST(SqueezeAllDims) +{ + int input_dims_data[] = { 7, 1, 1, 1, 1, 1, 1, 1 }; + int output_dims_data[] = { 1, 1 }; + const int input_data[] = { 3 }; + const int golden[] = { 3 }; + const int expected_output_size = 1; + + int output_data[24]; + TfLiteSqueezeParams squeeze_params = { {}, 0 }; + + tflite::testing::TestSqueezeOp(input_dims_data, input_data, output_dims_data, + output_data, golden, expected_output_size, + &squeeze_params); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/strided_slice.cc b/components/tflite/tensorflow/lite/micro/kernels/strided_slice.cc new file mode 100644 index 00000000..497a8147 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/strided_slice.cc @@ -0,0 +1,206 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/kernels/internal/reference/strided_slice.h" + +#include +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace strided_slice { + +constexpr int kInputTensor = 0; +constexpr int kBeginTensor = 1; +constexpr int kEndTensor = 2; +constexpr int kStridesTensor = 3; +constexpr int kOutputTensor = 0; + +struct StridedSliceContext { + StridedSliceContext(TfLiteContext *context, TfLiteNode *node) + { + params = reinterpret_cast(node->builtin_data); + input = GetInput(context, node, kInputTensor); + begin = GetInput(context, node, kBeginTensor); + end = GetInput(context, node, kEndTensor); + strides = GetInput(context, node, kStridesTensor); + output = GetOutput(context, node, kOutputTensor); + dims = NumDimensions(input); + } + const TfLiteStridedSliceParams *params; + const TfLiteTensor *input; + const TfLiteTensor *begin; + const TfLiteTensor *end; + const TfLiteTensor *strides; + TfLiteTensor *output; + int dims; +}; + +// This Op only supports 1-4D cases and since we use the reference 4D +// implementation, the 1-3D tensors are mapped to 4D. +const int kMaxDim = 4; + +tflite::StridedSliceParams BuildStridedSliceParams( + StridedSliceContext *op_context) +{ + tflite::StridedSliceParams op_params; + op_params.start_indices_count = op_context->dims; + op_params.stop_indices_count = op_context->dims; + op_params.strides_count = op_context->dims; + + for (int i = 0; i < op_context->dims; ++i) { + op_params.start_indices[i] = GetTensorData(op_context->begin)[i]; + op_params.stop_indices[i] = GetTensorData(op_context->end)[i]; + op_params.strides[i] = GetTensorData(op_context->strides)[i]; + } + + op_params.begin_mask = op_context->params->begin_mask; + op_params.ellipsis_mask = 0; + op_params.end_mask = op_context->params->end_mask; + op_params.new_axis_mask = 0; + op_params.shrink_axis_mask = op_context->params->shrink_axis_mask; + return op_params; +} + +// Processes the indexing tensors (begin, end and strides) to resize the +// output tensor. This function is callable from both Prepare() and Eval() as +// long as the caller ensures the indexing tensors are present. +TfLiteStatus CheckOutputSize(TfLiteContext *context, + StridedSliceContext *op_context) +{ + using ::tflite::strided_slice::StartForAxis; + using ::tflite::strided_slice::StopForAxis; + TfLiteIntArray *output_shape = op_context->output->dims; + int shape_size = 0; + auto op_params = BuildStridedSliceParams(op_context); + auto input_shape = GetTensorShape(op_context->input); + for (int idx = 0; idx < op_context->dims; ++idx) { + int32_t stride = GetTensorData(op_context->strides)[idx]; + TF_LITE_ENSURE_MSG(context, stride != 0, "stride value has to be non-zero"); + int32_t begin = StartForAxis(op_params, input_shape, idx); + int32_t end = StopForAxis(op_params, input_shape, idx, begin); + + // When shrinking an axis, the end position does not matter (and can be + // incorrect when negative indexing is used, see Issue #19260). Always use + // begin + 1 to generate a length 1 slice, since begin has + // already been adjusted for negative indices by StartForAxis. + const bool shrink_axis = op_context->params->shrink_axis_mask & (1 << idx); + if (shrink_axis) { + end = begin + 1; + } + + // This is valid for both positive and negative strides + int32_t dim_shape = std::ceil((end - begin) / static_cast(stride)); + dim_shape = dim_shape < 0 ? 0 : dim_shape; + if (!shrink_axis) { + TF_LITE_ENSURE_EQ(context, output_shape->data[shape_size], dim_shape); + shape_size++; + } + } + TF_LITE_ENSURE_EQ(context, output_shape->size, shape_size); + return kTfLiteOk; +} + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(StridedSliceParams)); +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + StridedSliceParams *op_params = + static_cast(node->user_data); + TF_LITE_ENSURE_EQ(context, NumInputs(node), 4); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + StridedSliceContext op_context(context, node); + TF_LITE_ENSURE_MSG(context, op_context.dims <= kMaxDim, + "input dim should not exceed 4"); + auto params = BuildStridedSliceParams(&op_context); + memcpy(op_params, ¶ms, sizeof(StridedSliceParams)); + return CheckOutputSize(context, &op_context); +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + const StridedSliceParams &op_params = + *(static_cast(node->user_data)); + + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + switch (output->type) { + case kTfLiteFloat32: + reference_ops::StridedSlice(op_params, + tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + break; + case kTfLiteUInt8: + reference_ops::StridedSlice( + op_params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + break; + case kTfLiteInt8: + reference_ops::StridedSlice(op_params, + tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + break; + case kTfLiteInt16: + reference_ops::StridedSlice( + op_params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + break; + default: + TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.", + TfLiteTypeGetName(input->type), input->type); + return kTfLiteError; + } + return kTfLiteOk; +} +} // namespace strided_slice + +TfLiteRegistration Register_STRIDED_SLICE() +{ + return { /*init=*/strided_slice::Init, + /*free=*/nullptr, + /*prepare=*/strided_slice::Prepare, + /*invoke=*/strided_slice::Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/strided_slice_test.cc b/components/tflite/tensorflow/lite/micro/kernels/strided_slice_test.cc new file mode 100644 index 00000000..897ec78c --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/strided_slice_test.cc @@ -0,0 +1,1144 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +template +void ValidateStridedSliceGoldens(TfLiteTensor *tensors, int tensors_size, + const T *golden, T *output, int output_len, + TfLiteStridedSliceParams *params, + const bool expect_prepare_err, int num_invoke, + float tolerance = 1e-5) +{ + int inputs_array_data[] = { 4, 0, 1, 2, 3 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 4 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = + tflite::ops::micro::Register_STRIDED_SLICE(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, reinterpret_cast(params)); + if (expect_prepare_err) { + TF_LITE_MICRO_EXPECT_EQ(kTfLiteError, runner.InitAndPrepare()); + return; + } else { + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + } + + for (int i = 0; i < num_invoke; i++) { + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + } + + for (int i = 0; i < output_len; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(golden[i], output[i], 1e-5f); + } +} + +void TestStridedSliceFloat(int *input_shape, int *begin_shape, int *end_shape, + int *strides_shape, + TfLiteStridedSliceParams *builtin_data, + float *input_data, const int32_t *begin_data, + const int32_t *end_data, const int32_t *strides_data, + int *output_shape, float *output_data, + const float *expected_output, + bool expect_prepare_err, int num_invoke = 1) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_shape); + TfLiteIntArray *begin_dims = IntArrayFromInts(begin_shape); + TfLiteIntArray *end_dims = IntArrayFromInts(end_shape); + TfLiteIntArray *strides_dims = IntArrayFromInts(strides_shape); + TfLiteIntArray *output_dims = IntArrayFromInts(output_shape); + constexpr int inputs_size = 4; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(begin_data, begin_dims), + CreateTensor(end_data, end_dims), + CreateTensor(strides_data, strides_dims), + CreateTensor(output_data, output_dims), + }; + + ValidateStridedSliceGoldens(tensors, tensors_size, expected_output, + output_data, ElementCount(*output_dims), + builtin_data, expect_prepare_err, num_invoke, + 1.0); +} + +template +void TestStridedSliceQuantized(int *input_shape, int *begin_shape, + int *end_shape, int *strides_shape, + TfLiteStridedSliceParams *builtin_data, + const T *input_data, const int32_t *begin_data, + const int32_t *end_data, + const int32_t *strides_data, int *output_shape, + T *output_data, const T *expected_output, + bool expect_prepare_err, int num_invoke = 1) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_shape); + TfLiteIntArray *begin_dims = IntArrayFromInts(begin_shape); + TfLiteIntArray *end_dims = IntArrayFromInts(end_shape); + TfLiteIntArray *strides_dims = IntArrayFromInts(strides_shape); + TfLiteIntArray *output_dims = IntArrayFromInts(output_shape); + constexpr int inputs_size = 4; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + int zero_point = + std::numeric_limits::max() + std::numeric_limits::min() / 2; + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(input_data, input_dims, 1.0, zero_point), + CreateTensor(begin_data, begin_dims), + CreateTensor(end_data, end_dims), + CreateTensor(strides_data, strides_dims), + CreateQuantizedTensor(output_data, output_dims, 1.0, zero_point), + }; + + ValidateStridedSliceGoldens(tensors, tensors_size, expected_output, + output_data, ElementCount(*output_dims), + builtin_data, expect_prepare_err, num_invoke, + 1.0); +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(UnsupportedInputSize) +{ + int input_shape[] = { 5, 2, 2, 2, 2, 2 }; + int begin_shape[] = { 1, 5 }; + int end_shape[] = { 1, 5 }; + int strides_shape[] = { 1, 5 }; + int output_shape[] = { 0 }; + float input_data[] = {}; + int32_t begin_data[] = {}; + int32_t end_data[] = {}; + int32_t strides_data[] = {}; + float golden[] = {}; + float output_data[4]; + + TfLiteStridedSliceParams builtin_data = {}; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, true); +} + +TF_LITE_MICRO_TEST(In1D) +{ + int input_shape[] = { 1, 4 }; + int begin_shape[] = { 1, 1 }; + int end_shape[] = { 1, 1 }; + int strides_shape[] = { 1, 1 }; + int output_shape[] = { 1, 2 }; + float input_data[] = { 1, 2, 3, 4 }; + int32_t begin_data[] = { 1 }; + int32_t end_data[] = { 3 }; + int32_t strides_data[] = { 1 }; + float golden[] = { 2, 3 }; + float output_data[4]; + + TfLiteStridedSliceParams builtin_data = {}; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In1D_EmptyOutput) +{ + int input_shape[] = { 1, 4 }; + int begin_shape[] = { 1, 1 }; + int end_shape[] = { 1, 1 }; + int strides_shape[] = { 1, 1 }; + int output_shape[] = { 1, 0 }; + float input_data[] = { 1, 2, 3, 4 }; + int32_t begin_data[] = { 10 }; + int32_t end_data[] = { 3 }; + int32_t strides_data[] = { 1 }; + float golden[] = {}; + float output_data[4]; + + TfLiteStridedSliceParams builtin_data = {}; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In1D_NegativeBegin) +{ + int input_shape[] = { 1, 4 }; + int begin_shape[] = { 1, 1 }; + int end_shape[] = { 1, 1 }; + int strides_shape[] = { 1, 1 }; + int output_shape[] = { 1, 2 }; + float input_data[] = { 1, 2, 3, 4 }; + int32_t begin_data[] = { -3 }; + int32_t end_data[] = { 3 }; + int32_t strides_data[] = { 1 }; + float golden[] = { 2, 3 }; + float output_data[4]; + + TfLiteStridedSliceParams builtin_data = {}; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In1D_OutOfRangeBegin) +{ + int input_shape[] = { 1, 4 }; + int begin_shape[] = { 1, 1 }; + int end_shape[] = { 1, 1 }; + int strides_shape[] = { 1, 1 }; + int output_shape[] = { 1, 3 }; + float input_data[] = { 1, 2, 3, 4 }; + int32_t begin_data[] = { -5 }; + int32_t end_data[] = { 3 }; + int32_t strides_data[] = { 1 }; + float golden[] = { 1, 2, 3 }; + float output_data[4]; + + TfLiteStridedSliceParams builtin_data = {}; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In1D_NegativeEnd) +{ + int input_shape[] = { 1, 4 }; + int begin_shape[] = { 1, 1 }; + int end_shape[] = { 1, 1 }; + int strides_shape[] = { 1, 1 }; + int output_shape[] = { 1, 1 }; + float input_data[] = { 1, 2, 3, 4 }; + int32_t begin_data[] = { 1 }; + int32_t end_data[] = { -2 }; + int32_t strides_data[] = { 1 }; + float golden[] = { 2 }; + float output_data[4]; + + TfLiteStridedSliceParams builtin_data = {}; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In1D_OutOfRangeEnd) +{ + int input_shape[] = { 1, 4 }; + int begin_shape[] = { 1, 1 }; + int end_shape[] = { 1, 1 }; + int strides_shape[] = { 1, 1 }; + int output_shape[] = { 1, 3 }; + float input_data[] = { 1, 2, 3, 4 }; + int32_t begin_data[] = { -3 }; + int32_t end_data[] = { 5 }; + int32_t strides_data[] = { 1 }; + float golden[] = { 2, 3, 4 }; + float output_data[4]; + + TfLiteStridedSliceParams builtin_data = {}; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In1D_BeginMask) +{ + int input_shape[] = { 1, 4 }; + int begin_shape[] = { 1, 1 }; + int end_shape[] = { 1, 1 }; + int strides_shape[] = { 1, 1 }; + int output_shape[] = { 1, 3 }; + float input_data[] = { 1, 2, 3, 4 }; + int32_t begin_data[] = { 1 }; + int32_t end_data[] = { 3 }; + int32_t strides_data[] = { 1 }; + float golden[] = { 1, 2, 3 }; + float output_data[4]; + + TfLiteStridedSliceParams builtin_data = { 1, 0, 0, 0, 0 }; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In1D_NegativeBeginNegativeStride) +{ + int input_shape[] = { 1, 4 }; + int begin_shape[] = { 1, 1 }; + int end_shape[] = { 1, 1 }; + int strides_shape[] = { 1, 1 }; + int output_shape[] = { 1, 1 }; + float input_data[] = { 1, 2, 3, 4 }; + int32_t begin_data[] = { -2 }; + int32_t end_data[] = { -3 }; + int32_t strides_data[] = { -1 }; + float golden[] = { 3 }; + float output_data[4]; + + TfLiteStridedSliceParams builtin_data = {}; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In1D_OutOfRangeBeginNegativeStride) +{ + int input_shape[] = { 1, 4 }; + int begin_shape[] = { 1, 1 }; + int end_shape[] = { 1, 1 }; + int strides_shape[] = { 1, 1 }; + int output_shape[] = { 1, 1 }; + float input_data[] = { 1, 2, 3, 4 }; + int32_t begin_data[] = { 5 }; + int32_t end_data[] = { 2 }; + int32_t strides_data[] = { -1 }; + float golden[] = { 4 }; + float output_data[4]; + + TfLiteStridedSliceParams builtin_data = {}; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In1D_NegativeEndNegativeStride) +{ + int input_shape[] = { 1, 4 }; + int begin_shape[] = { 1, 1 }; + int end_shape[] = { 1, 1 }; + int strides_shape[] = { 1, 1 }; + int output_shape[] = { 1, 2 }; + float input_data[] = { 1, 2, 3, 4 }; + int32_t begin_data[] = { 2 }; + int32_t end_data[] = { -4 }; + int32_t strides_data[] = { -1 }; + float golden[] = { 3, 2 }; + float output_data[4]; + + TfLiteStridedSliceParams builtin_data = {}; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In1D_OutOfRangeEndNegativeStride) +{ + int input_shape[] = { 1, 4 }; + int begin_shape[] = { 1, 1 }; + int end_shape[] = { 1, 1 }; + int strides_shape[] = { 1, 1 }; + int output_shape[] = { 1, 2 }; + float input_data[] = { 1, 2, 3, 4 }; + int32_t begin_data[] = { -3 }; + int32_t end_data[] = { -5 }; + int32_t strides_data[] = { -1 }; + float golden[] = { 2, 1 }; + float output_data[4]; + + TfLiteStridedSliceParams builtin_data = {}; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In1D_EndMask) +{ + int input_shape[] = { 1, 4 }; + int begin_shape[] = { 1, 1 }; + int end_shape[] = { 1, 1 }; + int strides_shape[] = { 1, 1 }; + int output_shape[] = { 1, 3 }; + float input_data[] = { 1, 2, 3, 4 }; + int32_t begin_data[] = { 1 }; + int32_t end_data[] = { 3 }; + int32_t strides_data[] = { 1 }; + float golden[] = { 2, 3, 4 }; + float output_data[4]; + + TfLiteStridedSliceParams builtin_data = { 0, 1, 0, 0, 0 }; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In1D_NegStride) +{ + int input_shape[] = { 1, 3 }; + int begin_shape[] = { 1, 1 }; + int end_shape[] = { 1, 1 }; + int strides_shape[] = { 1, 1 }; + int output_shape[] = { 1, 3 }; + float input_data[] = { 1, 2, 3 }; + int32_t begin_data[] = { -1 }; + int32_t end_data[] = { -4 }; + int32_t strides_data[] = { -1 }; + float golden[] = { 3, 2, 1 }; + float output_data[4]; + + TfLiteStridedSliceParams builtin_data = {}; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In1D_EvenLenStride2) +{ + int input_shape[] = { 1, 2 }; + int begin_shape[] = { 1, 1 }; + int end_shape[] = { 1, 1 }; + int strides_shape[] = { 1, 1 }; + int output_shape[] = { 1, 1 }; + float input_data[] = { 1, 2, 3, 4 }; + int32_t begin_data[] = { 0 }; + int32_t end_data[] = { 4 }; + int32_t strides_data[] = { 2 }; + float golden[] = { 1 }; + float output_data[4]; + + TfLiteStridedSliceParams builtin_data = {}; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In1D_OddLenStride2) +{ + int input_shape[] = { 1, 3 }; + int begin_shape[] = { 1, 1 }; + int end_shape[] = { 1, 1 }; + int strides_shape[] = { 1, 1 }; + int output_shape[] = { 1, 2 }; + float input_data[] = { 1, 2, 3, 4 }; + int32_t begin_data[] = { 0 }; + int32_t end_data[] = { 3 }; + int32_t strides_data[] = { 2 }; + float golden[] = { 1, 3 }; + float output_data[4]; + + TfLiteStridedSliceParams builtin_data = {}; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In2D_Identity) +{ + int input_shape[] = { 2, 2, 3 }; + int begin_shape[] = { 1, 2 }; + int end_shape[] = { 1, 2 }; + int strides_shape[] = { 1, 2 }; + int output_shape[] = { 2, 2, 3 }; + float input_data[] = { 1, 2, 3, 4, 5, 6 }; + int32_t begin_data[] = { 0, 0 }; + int32_t end_data[] = { 2, 3 }; + int32_t strides_data[] = { 1, 1 }; + float golden[] = { 1, 2, 3, 4, 5, 6 }; + float output_data[8]; + + TfLiteStridedSliceParams builtin_data = {}; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In2D) +{ + int input_shape[] = { 2, 2, 3 }; + int begin_shape[] = { 1, 2 }; + int end_shape[] = { 1, 2 }; + int strides_shape[] = { 1, 2 }; + int output_shape[] = { 2, 1, 2 }; + float input_data[] = { 1, 2, 3, 4, 5, 6 }; + int32_t begin_data[] = { 1, 0 }; + int32_t end_data[] = { 2, 2 }; + int32_t strides_data[] = { 1, 1 }; + float golden[] = { 4, 5 }; + float output_data[8]; + + TfLiteStridedSliceParams builtin_data = {}; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In2D_Stride2) +{ + int input_shape[] = { 2, 2, 3 }; + int begin_shape[] = { 1, 2 }; + int end_shape[] = { 1, 2 }; + int strides_shape[] = { 1, 2 }; + int output_shape[] = { 2, 1, 2 }; + float input_data[] = { 1, 2, 3, 4, 5, 6 }; + int32_t begin_data[] = { 0, 0 }; + int32_t end_data[] = { 2, 3 }; + int32_t strides_data[] = { 2, 2 }; + float golden[] = { 1, 3 }; + float output_data[8]; + + TfLiteStridedSliceParams builtin_data = {}; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In2D_NegStride) +{ + int input_shape[] = { 2, 2, 3 }; + int begin_shape[] = { 1, 2 }; + int end_shape[] = { 1, 2 }; + int strides_shape[] = { 1, 2 }; + int output_shape[] = { 2, 1, 3 }; + float input_data[] = { 1, 2, 3, 4, 5, 6 }; + int32_t begin_data[] = { 1, -1 }; + int32_t end_data[] = { 2, -4 }; + int32_t strides_data[] = { 2, -1 }; + float golden[] = { 6, 5, 4 }; + float output_data[8]; + + TfLiteStridedSliceParams builtin_data = {}; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In2D_BeginMask) +{ + int input_shape[] = { 2, 2, 3 }; + int begin_shape[] = { 1, 2 }; + int end_shape[] = { 1, 2 }; + int strides_shape[] = { 1, 2 }; + int output_shape[] = { 2, 2, 2 }; + float input_data[] = { 1, 2, 3, 4, 5, 6 }; + int32_t begin_data[] = { 1, 0 }; + int32_t end_data[] = { 2, 2 }; + int32_t strides_data[] = { 1, 1 }; + float golden[] = { 1, 2, 4, 5 }; + float output_data[8]; + + TfLiteStridedSliceParams builtin_data = { 1, 0, 0, 0, 0 }; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In2D_EndMask) +{ + int input_shape[] = { 2, 2, 3 }; + int begin_shape[] = { 1, 2 }; + int end_shape[] = { 1, 2 }; + int strides_shape[] = { 1, 2 }; + int output_shape[] = { 2, 1, 3 }; + float input_data[] = { 1, 2, 3, 4, 5, 6 }; + int32_t begin_data[] = { 1, 0 }; + int32_t end_data[] = { 2, 2 }; + int32_t strides_data[] = { 1, 1 }; + float golden[] = { 4, 5, 6 }; + float output_data[8]; + + TfLiteStridedSliceParams builtin_data = { 0, 2, 0, 0, 0 }; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In2D_NegStrideBeginMask) +{ + int input_shape[] = { 2, 2, 3 }; + int begin_shape[] = { 1, 2 }; + int end_shape[] = { 1, 2 }; + int strides_shape[] = { 1, 2 }; + int output_shape[] = { 2, 1, 3 }; + float input_data[] = { 1, 2, 3, 4, 5, 6 }; + int32_t begin_data[] = { 1, -2 }; + int32_t end_data[] = { 2, -4 }; + int32_t strides_data[] = { 1, -1 }; + float golden[] = { 6, 5, 4 }; + float output_data[8]; + + TfLiteStridedSliceParams builtin_data = { 2, 0, 0, 0, 0 }; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In2D_NegStrideEndMask) +{ + int input_shape[] = { 2, 2, 3 }; + int begin_shape[] = { 1, 2 }; + int end_shape[] = { 1, 2 }; + int strides_shape[] = { 1, 2 }; + int output_shape[] = { 2, 1, 2 }; + float input_data[] = { 1, 2, 3, 4, 5, 6 }; + int32_t begin_data[] = { 1, -2 }; + int32_t end_data[] = { 2, -3 }; + int32_t strides_data[] = { 1, -1 }; + float golden[] = { 5, 4 }; + float output_data[8]; + + TfLiteStridedSliceParams builtin_data = { 0, 2, 0, 0, 0 }; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In3D_Identity) +{ + int input_shape[] = { 3, 2, 3, 2 }; + int begin_shape[] = { 1, 3 }; + int end_shape[] = { 1, 3 }; + int strides_shape[] = { 1, 3 }; + int output_shape[] = { 3, 2, 3, 2 }; + float input_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + int32_t begin_data[] = { 0, 0, 0 }; + int32_t end_data[] = { 2, 3, 2 }; + int32_t strides_data[] = { 1, 1, 1 }; + float golden[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + float output_data[16]; + + TfLiteStridedSliceParams builtin_data = {}; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In3D_NegStride) +{ + int input_shape[] = { 3, 2, 3, 2 }; + int begin_shape[] = { 1, 3 }; + int end_shape[] = { 1, 3 }; + int strides_shape[] = { 1, 3 }; + int output_shape[] = { 3, 2, 3, 2 }; + float input_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + int32_t begin_data[] = { 0, 0, 0 }; + int32_t end_data[] = { 2, 3, 2 }; + int32_t strides_data[] = { 1, 1, 1 }; + float golden[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + float output_data[16]; + + TfLiteStridedSliceParams builtin_data = {}; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In3D_Strided2) +{ + int input_shape[] = { 3, 2, 3, 2 }; + int begin_shape[] = { 1, 3 }; + int end_shape[] = { 1, 3 }; + int strides_shape[] = { 1, 3 }; + int output_shape[] = { 3, 1, 2, 1 }; + float input_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + int32_t begin_data[] = { 0, 0, 0 }; + int32_t end_data[] = { 2, 3, 2 }; + int32_t strides_data[] = { 2, 2, 2 }; + float golden[] = { 1, 5 }; + float output_data[16]; + + TfLiteStridedSliceParams builtin_data = {}; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In1D_ShrinkAxisMask1) +{ + int input_shape[] = { 3, 2, 3, 2 }; + int begin_shape[] = { 1, 3 }; + int end_shape[] = { 1, 3 }; + int strides_shape[] = { 1, 3 }; + int output_shape[] = { 3, 2, 3, 2 }; + float input_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + int32_t begin_data[] = { 0, 0, 0 }; + int32_t end_data[] = { 2, 3, 2 }; + int32_t strides_data[] = { 1, 1, 1 }; + float golden[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + float output_data[16]; + + TfLiteStridedSliceParams builtin_data = {}; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In1D_ShrinkAxisMask1_NegativeSlice) +{ + int input_shape[] = { 1, 4 }; + int begin_shape[] = { 1, 1 }; + int end_shape[] = { 1, 1 }; + int strides_shape[] = { 1, 1 }; + int output_shape[] = { 0 }; + float input_data[] = { 0, 1, 2, 3 }; + int32_t begin_data[] = { -1 }; + int32_t end_data[] = { 0 }; + int32_t strides_data[] = { 1 }; + float golden[] = { 3 }; + float output_data[4]; + + TfLiteStridedSliceParams builtin_data = { 0, 0, 0, 0, 1 }; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In2D_ShrinkAxis3_NegativeSlice) +{ + int input_shape[] = { 2, 4, 1 }; + int begin_shape[] = { 1, 2 }; + int end_shape[] = { 1, 2 }; + int strides_shape[] = { 1, 2 }; + int output_shape[] = { 0 }; + float input_data[] = { 0, 1, 2, 3 }; + int32_t begin_data[] = { -2, -1 }; + int32_t end_data[] = { -1, 0 }; + int32_t strides_data[] = { 1, 1 }; + float golden[] = { 2 }; + float output_data[4]; + + TfLiteStridedSliceParams builtin_data = { 0, 0, 0, 0, 3 }; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In2D_ShrinkAxis2_BeginEndAxis1_NegativeSlice) +{ + int input_shape[] = { 2, 4, 1 }; + int begin_shape[] = { 1, 2 }; + int end_shape[] = { 1, 2 }; + int strides_shape[] = { 1, 2 }; + int output_shape[] = { 1, 4 }; + float input_data[] = { 0, 1, 2, 3 }; + int32_t begin_data[] = { 0, -1 }; + int32_t end_data[] = { 0, 0 }; + int32_t strides_data[] = { 1, 1 }; + float golden[] = { 0, 1, 2, 3 }; + float output_data[4]; + + TfLiteStridedSliceParams builtin_data = { 1, 1, 0, 0, 2 }; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In1D_BeginMaskShrinkAxisMask1) +{ + int input_shape[] = { 1, 4 }; + int begin_shape[] = { 1, 1 }; + int end_shape[] = { 1, 1 }; + int strides_shape[] = { 1, 1 }; + int output_shape[] = { 0 }; + float input_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + int32_t begin_data[] = { 1 }; + int32_t end_data[] = { 1 }; + int32_t strides_data[] = { 1 }; + float golden[] = { 1 }; + float output_data[4]; + + TfLiteStridedSliceParams builtin_data = { 1, 0, 0, 0, 1 }; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In2D_ShrinkAxisMask1) +{ + int input_shape[] = { 2, 2, 3 }; + int begin_shape[] = { 1, 2 }; + int end_shape[] = { 1, 2 }; + int strides_shape[] = { 1, 2 }; + int output_shape[] = { 1, 3 }; + float input_data[] = { 1, 2, 3, 4, 5, 6 }; + int32_t begin_data[] = { 0, 0 }; + int32_t end_data[] = { 1, 3 }; + int32_t strides_data[] = { 1, 1 }; + float golden[] = { 1, 2, 3 }; + float output_data[6]; + + TfLiteStridedSliceParams builtin_data = { 0, 0, 0, 0, 1 }; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In2D_ShrinkAxisMask2) +{ + int input_shape[] = { 2, 2, 3 }; + int begin_shape[] = { 1, 2 }; + int end_shape[] = { 1, 2 }; + int strides_shape[] = { 1, 2 }; + int output_shape[] = { 1, 2 }; + float input_data[] = { 1, 2, 3, 4, 5, 6 }; + int32_t begin_data[] = { 0, 0 }; + int32_t end_data[] = { 2, 1 }; + int32_t strides_data[] = { 1, 1 }; + float golden[] = { 1, 4 }; + float output_data[6]; + + TfLiteStridedSliceParams builtin_data = { 0, 0, 0, 0, 2 }; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In2D_ShrinkAxisMask3) +{ + int input_shape[] = { 2, 2, 3 }; + int begin_shape[] = { 1, 2 }; + int end_shape[] = { 1, 2 }; + int strides_shape[] = { 1, 2 }; + int output_shape[] = { 0 }; + float input_data[] = { 1, 2, 3, 4, 5, 6 }; + int32_t begin_data[] = { 0, 0 }; + int32_t end_data[] = { 1, 1 }; + int32_t strides_data[] = { 1, 1 }; + float golden[] = { 1 }; + float output_data[6]; + + TfLiteStridedSliceParams builtin_data = { 0, 0, 0, 0, 3 }; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In3D_IdentityShrinkAxis1) +{ + int input_shape[] = { 3, 2, 3, 2 }; + int begin_shape[] = { 1, 3 }; + int end_shape[] = { 1, 3 }; + int strides_shape[] = { 1, 3 }; + int output_shape[] = { 2, 3, 2 }; + float input_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + int32_t begin_data[] = { 0, 0, 0 }; + int32_t end_data[] = { 1, 3, 2 }; + int32_t strides_data[] = { 1, 1, 1 }; + float golden[] = { 1, 2, 3, 4, 5, 6 }; + float output_data[16]; + + TfLiteStridedSliceParams builtin_data = { 0, 0, 0, 0, 1 }; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In3D_IdentityShrinkAxis2) +{ + int input_shape[] = { 3, 2, 3, 2 }; + int begin_shape[] = { 1, 3 }; + int end_shape[] = { 1, 3 }; + int strides_shape[] = { 1, 3 }; + int output_shape[] = { 2, 2, 2 }; + float input_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + int32_t begin_data[] = { 0, 0, 0 }; + int32_t end_data[] = { 2, 1, 2 }; + int32_t strides_data[] = { 1, 1, 1 }; + float golden[] = { 1, 2, 7, 8 }; + float output_data[16]; + + TfLiteStridedSliceParams builtin_data = { 0, 0, 0, 0, 2 }; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In3D_IdentityShrinkAxis3) +{ + int input_shape[] = { 3, 2, 3, 2 }; + int begin_shape[] = { 1, 3 }; + int end_shape[] = { 1, 3 }; + int strides_shape[] = { 1, 3 }; + int output_shape[] = { 1, 2 }; + float input_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + int32_t begin_data[] = { 0, 0, 0 }; + int32_t end_data[] = { 1, 1, 2 }; + int32_t strides_data[] = { 1, 1, 1 }; + float golden[] = { 1, 2 }; + float output_data[16]; + + TfLiteStridedSliceParams builtin_data = { 0, 0, 0, 0, 3 }; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In3D_IdentityShrinkAxis4) +{ + int input_shape[] = { 3, 2, 3, 2 }; + int begin_shape[] = { 1, 3 }; + int end_shape[] = { 1, 3 }; + int strides_shape[] = { 1, 3 }; + int output_shape[] = { 2, 2, 3 }; + float input_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + int32_t begin_data[] = { 0, 0, 0 }; + int32_t end_data[] = { 2, 3, 2 }; + int32_t strides_data[] = { 1, 1, 1 }; + float golden[] = { 1, 3, 5, 7, 9, 11 }; + float output_data[16]; + + TfLiteStridedSliceParams builtin_data = { 0, 0, 0, 0, 4 }; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In3D_IdentityShrinkAxis5) +{ + int input_shape[] = { 3, 2, 3, 2 }; + int begin_shape[] = { 1, 3 }; + int end_shape[] = { 1, 3 }; + int strides_shape[] = { 1, 3 }; + int output_shape[] = { 1, 3 }; + float input_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + int32_t begin_data[] = { 0, 0, 0 }; + int32_t end_data[] = { 1, 3, 1 }; + int32_t strides_data[] = { 1, 1, 1 }; + float golden[] = { 1, 3, 5 }; + float output_data[16]; + + TfLiteStridedSliceParams builtin_data = { 0, 0, 0, 0, 5 }; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In3D_IdentityShrinkAxis6) +{ + int input_shape[] = { 3, 2, 3, 2 }; + int begin_shape[] = { 1, 3 }; + int end_shape[] = { 1, 3 }; + int strides_shape[] = { 1, 3 }; + int output_shape[] = { 1, 2 }; + float input_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + int32_t begin_data[] = { 0, 0, 0 }; + int32_t end_data[] = { 2, 1, 1 }; + int32_t strides_data[] = { 1, 1, 1 }; + float golden[] = { 1, 7 }; + float output_data[16]; + + TfLiteStridedSliceParams builtin_data = { 0, 0, 0, 0, 6 }; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In3D_IdentityShrinkAxis7) +{ + int input_shape[] = { 3, 2, 3, 2 }; + int begin_shape[] = { 1, 3 }; + int end_shape[] = { 1, 3 }; + int strides_shape[] = { 1, 3 }; + int output_shape[] = { 0 }; + float input_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + int32_t begin_data[] = { 0, 0, 0 }; + int32_t end_data[] = { 1, 1, 1 }; + int32_t strides_data[] = { 1, 1, 1 }; + float golden[] = { 1 }; + float output_data[16]; + + TfLiteStridedSliceParams builtin_data = { 0, 0, 0, 0, 7 }; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +// This tests catches a very subtle bug that was fixed by cl/188403234. +TF_LITE_MICRO_TEST(RunTwice) +{ + int input_shape[] = { 2, 2, 3 }; + int begin_shape[] = { 1, 2 }; + int end_shape[] = { 1, 2 }; + int strides_shape[] = { 1, 2 }; + int output_shape[] = { 2, 2, 2 }; + float input_data[] = { 1, 2, 3, 4, 5, 6 }; + int32_t begin_data[] = { 1, 0 }; + int32_t end_data[] = { 2, 2 }; + int32_t strides_data[] = { 1, 1 }; + float golden[] = { 1, 2, 4, 5 }; + float output_data[16]; + + TfLiteStridedSliceParams builtin_data = { 1, 0, 0, 0, 0 }; + + tflite::testing::TestStridedSliceFloat( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false, 2); +} + +TF_LITE_MICRO_TEST(In3D_IdentityShrinkAxis1Uint8) +{ + int input_shape[] = { 3, 2, 3, 2 }; + int begin_shape[] = { 1, 3 }; + int end_shape[] = { 1, 3 }; + int strides_shape[] = { 1, 3 }; + int output_shape[] = { 2, 3, 2 }; + uint8_t input_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + int32_t begin_data[] = { 0, 0, 0 }; + int32_t end_data[] = { 1, 3, 2 }; + int32_t strides_data[] = { 1, 1, 1 }; + uint8_t golden[] = { 1, 2, 3, 4, 5, 6 }; + uint8_t output_data[12]; + + TfLiteStridedSliceParams builtin_data = { 0, 0, 0, 0, 1 }; + + tflite::testing::TestStridedSliceQuantized( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In3D_IdentityShrinkAxis1int8) +{ + int input_shape[] = { 3, 2, 3, 2 }; + int begin_shape[] = { 1, 3 }; + int end_shape[] = { 1, 3 }; + int strides_shape[] = { 1, 3 }; + int output_shape[] = { 2, 3, 2 }; + int8_t input_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + int32_t begin_data[] = { 0, 0, 0 }; + int32_t end_data[] = { 1, 3, 2 }; + int32_t strides_data[] = { 1, 1, 1 }; + int8_t golden[] = { 1, 2, 3, 4, 5, 6 }; + int8_t output_data[12]; + + TfLiteStridedSliceParams builtin_data = { 0, 0, 0, 0, 1 }; + + tflite::testing::TestStridedSliceQuantized( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TEST(In3D_IdentityShrinkAxis1int16) +{ + int input_shape[] = { 3, 2, 3, 2 }; + int begin_shape[] = { 1, 3 }; + int end_shape[] = { 1, 3 }; + int strides_shape[] = { 1, 3 }; + int output_shape[] = { 2, 3, 2 }; + int16_t input_data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + int32_t begin_data[] = { 0, 0, 0 }; + int32_t end_data[] = { 1, 3, 2 }; + int32_t strides_data[] = { 1, 1, 1 }; + int16_t golden[] = { 1, 2, 3, 4, 5, 6 }; + int16_t output_data[12]; + + TfLiteStridedSliceParams builtin_data = { 0, 0, 0, 0, 1 }; + + tflite::testing::TestStridedSliceQuantized( + input_shape, begin_shape, end_shape, strides_shape, &builtin_data, + input_data, begin_data, end_data, strides_data, output_shape, output_data, + golden, false); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/sub.cc b/components/tflite/tensorflow/lite/micro/kernels/sub.cc new file mode 100644 index 00000000..772ff79b --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/sub.cc @@ -0,0 +1,299 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/sub.h" + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/add.h" +#include "tensorflow/lite/kernels/internal/reference/process_broadcast_shapes.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/internal/types.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace sub { + +constexpr int kInputTensor1 = 0; +constexpr int kInputTensor2 = 1; +constexpr int kOutputTensor = 0; + +struct OpData { + bool requires_broadcast; + + // These fields are used in both the general 8-bit -> 8bit quantized path, + // and the special 16-bit -> 16bit quantized path + int input1_shift; + int input2_shift; + int32_t output_activation_min; + int32_t output_activation_max; + + // These fields are used only in the general 8-bit -> 8bit quantized path + int32_t input1_multiplier; + int32_t input2_multiplier; + int32_t output_multiplier; + int output_shift; + int left_shift; + int32_t input1_offset; + int32_t input2_offset; + int32_t output_offset; +}; + +TfLiteStatus CalculateOpData(TfLiteContext *context, TfLiteSubParams *params, + const TfLiteTensor *input1, + const TfLiteTensor *input2, TfLiteTensor *output, + OpData *data) +{ + data->requires_broadcast = !HaveSameShapes(input1, input2); + + if (output->type == kTfLiteUInt8 || output->type == kTfLiteInt8 || + output->type == kTfLiteInt16) { + // 8bit -> 8bit general quantized path, with general rescalings + data->input1_offset = -input1->params.zero_point; + data->input2_offset = -input2->params.zero_point; + data->output_offset = output->params.zero_point; + + // The shift is set to 15 in case of 16-bit and 20 in case of 8-bit, + // accordingly. In case of 16-bit we have 65535 << 15 which is less than 1 + // << 31, therefore the addition will still fit in a 32 bit accumulator. + data->left_shift = output->type == kTfLiteInt16 ? 15 : 20; + const float twice_max_input_scale = + 2 * std::max(input1->params.scale, input2->params.scale); + const double real_input1_multiplier = + static_cast(input1->params.scale / twice_max_input_scale); + const double real_input2_multiplier = + static_cast(input2->params.scale / twice_max_input_scale); + const double real_output_multiplier = + static_cast(twice_max_input_scale / + ((1 << data->left_shift) * output->params.scale)); + + QuantizeMultiplierSmallerThanOneExp( + real_input1_multiplier, &data->input1_multiplier, &data->input1_shift); + + QuantizeMultiplierSmallerThanOneExp( + real_input2_multiplier, &data->input2_multiplier, &data->input2_shift); + + // Use add kernel for 16-bit sub, since it supports output requantization. + // This matches behavior in TFLite. + data->input2_multiplier *= (output->type == kTfLiteInt16) ? -1 : 1; + QuantizeMultiplierSmallerThanOneExp( + real_output_multiplier, &data->output_multiplier, &data->output_shift); + + TF_LITE_ENSURE_STATUS(CalculateActivationRangeQuantized( + context, params->activation, output, &data->output_activation_min, + &data->output_activation_max)); + } + + return kTfLiteOk; +} + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(OpData)); +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + TFLITE_DCHECK(node->builtin_data != nullptr); + + OpData *data = static_cast(node->user_data); + auto *params = reinterpret_cast(node->builtin_data); + + const TfLiteTensor *input1 = GetInput(context, node, kInputTensor1); + TF_LITE_ENSURE(context, input1 != nullptr); + const TfLiteTensor *input2 = GetInput(context, node, kInputTensor2); + TF_LITE_ENSURE(context, input2 != nullptr); + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + + TF_LITE_ENSURE_STATUS( + CalculateOpData(context, params, input1, input2, output, data)); + return kTfLiteOk; +} + +void EvalSub(TfLiteContext *context, TfLiteNode *node, TfLiteSubParams *params, + const OpData *data, const TfLiteEvalTensor *input1, + const TfLiteEvalTensor *input2, TfLiteEvalTensor *output) +{ + float output_activation_min, output_activation_max; + CalculateActivationRange(params->activation, &output_activation_min, + &output_activation_max); + tflite::ArithmeticParams op_params; + SetActivationParams(output_activation_min, output_activation_max, &op_params); + if (data->requires_broadcast) { + tflite::reference_ops::BroadcastSubSlow( + op_params, tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorData(input1), + tflite::micro::GetTensorShape(input2), + tflite::micro::GetTensorData(input2), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } else { + tflite::reference_ops::SubWithActivation( + op_params, tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorData(input1), + tflite::micro::GetTensorShape(input2), + tflite::micro::GetTensorData(input2), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } +} + +TfLiteStatus EvalSubQuantized(TfLiteContext *context, TfLiteNode *node, + TfLiteSubParams *params, const OpData *data, + const TfLiteEvalTensor *input1, + const TfLiteEvalTensor *input2, + TfLiteEvalTensor *output) +{ + tflite::ArithmeticParams op_params; + op_params.left_shift = data->left_shift; + op_params.input1_offset = data->input1_offset; + op_params.input1_multiplier = data->input1_multiplier; + op_params.input1_shift = data->input1_shift; + op_params.input2_offset = data->input2_offset; + op_params.input2_multiplier = data->input2_multiplier; + op_params.input2_shift = data->input2_shift; + op_params.output_offset = data->output_offset; + op_params.output_multiplier = data->output_multiplier; + op_params.output_shift = data->output_shift; + SetActivationParams(data->output_activation_min, data->output_activation_max, + &op_params); + bool need_broadcast = reference_ops::ProcessBroadcastShapes( + tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorShape(input2), &op_params); + + switch (output->type) { + case kTfLiteInt8: { + if (need_broadcast) { + tflite::reference_ops::BroadcastSubSlow( + op_params, tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorData(input1), + tflite::micro::GetTensorShape(input2), + tflite::micro::GetTensorData(input2), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } else { + tflite::reference_ops::Sub( + op_params, tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorData(input1), + tflite::micro::GetTensorShape(input2), + tflite::micro::GetTensorData(input2), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } + break; + } + case kTfLiteInt16: { + if (need_broadcast) { + tflite::reference_ops::BroadcastAdd4DSlow( + op_params, tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorData(input1), + tflite::micro::GetTensorShape(input2), + tflite::micro::GetTensorData(input2), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } else { + tflite::reference_ops::Add( + op_params, tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorData(input1), + tflite::micro::GetTensorShape(input2), + tflite::micro::GetTensorData(input2), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output), false); + } + break; + } + case kTfLiteUInt8: { + if (need_broadcast) { + tflite::reference_ops::BroadcastSubSlow( + op_params, tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorData(input1), + tflite::micro::GetTensorShape(input2), + tflite::micro::GetTensorData(input2), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } else { + tflite::reference_ops::Sub( + op_params, tflite::micro::GetTensorShape(input1), + tflite::micro::GetTensorData(input1), + tflite::micro::GetTensorShape(input2), + tflite::micro::GetTensorData(input2), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + } + break; + } + default: + TF_LITE_KERNEL_LOG(context, "Quantized type %s not currently supported.", + TfLiteTypeGetName(output->type)); + return kTfLiteError; + } + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + auto *params = reinterpret_cast(node->builtin_data); + + const TfLiteEvalTensor *input1 = + tflite::micro::GetEvalInput(context, node, kInputTensor1); + const TfLiteEvalTensor *input2 = + tflite::micro::GetEvalInput(context, node, kInputTensor2); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + TFLITE_DCHECK(node->user_data != nullptr); + const OpData &data = *(static_cast(node->user_data)); + + if (output->type == kTfLiteFloat32) { + EvalSub(context, node, params, &data, input1, input2, output); + } else if (output->type == kTfLiteUInt8 || output->type == kTfLiteInt8 || + output->type == kTfLiteInt16) { + TF_LITE_ENSURE_OK(context, EvalSubQuantized(context, node, params, &data, + input1, input2, output)); + } else { + TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.", + TfLiteTypeGetName(output->type), output->type); + return kTfLiteError; + } + + return kTfLiteOk; +} + +} // namespace sub + +TfLiteRegistration Register_SUB() +{ + return { /*init=*/sub::Init, + /*free=*/nullptr, + /*prepare=*/sub::Prepare, + /*invoke=*/sub::Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/sub_test.cc b/components/tflite/tensorflow/lite/micro/kernels/sub_test.cc new file mode 100644 index 00000000..617f65f8 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/sub_test.cc @@ -0,0 +1,620 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +// Shapes and values for mixed broadcast tests. +const int broadcast_output_dims_count = 36; +const int broadcast_num_shapes = 4; + +int broadcast_input1_shape[] = { 4, 2, 3, 1, 2 }; +const float broadcast_input1_values[] = { -0.3, 2.3, 0.9, 0.5, 0.8, -1.1, + 1.2, 2.8, -1.6, 0.0, 0.7, -2.2 }; +const float broadcast_input2_values[] = { -0.2, -0.3, 0.4, -0.5, -1.0, -0.9 }; +const float + broadcast_goldens[broadcast_num_shapes][broadcast_output_dims_count] = { + { -0.1, 2.6, -0.7, 2.8, 0.7, 3.2, 1.1, 0.8, 0.5, 1.0, 1.9, 1.4, + 1.0, -0.8, 0.4, -0.6, 1.8, -0.2, 1.4, 3.1, 0.8, 3.3, 2.2, 3.7, + -1.4, 0.3, -2.0, 0.5, -0.6, 0.9, 0.9, -1.9, 0.3, -1.7, 1.7, -1.3 }, + { -0.1, 2.6, 0.5, 1.0, 1.8, -0.2, 1.4, 3.1, -2.0, 0.5, 1.7, -1.3 }, + { -0.1, 2.5, 0.0, 2.6, -0.7, 1.9, 1.1, 0.7, 1.2, 0.8, 0.5, 0.1, + 1.0, -0.9, 1.1, -0.8, 0.4, -1.5, 1.7, 3.3, 2.2, 3.8, 2.1, 3.7, + -1.1, 0.5, -0.6, 1.0, -0.7, 0.9, 1.2, -1.7, 1.7, -1.2, 1.6, -1.3 }, + { -0.1, 2.5, 1.2, 0.8, 0.4, -1.5, 1.7, 3.3, -0.6, 1.0, 1.6, -1.3 }, + }; + +const int broadcast_max_shape_size = 5; +int broadcast_input2_shapes[broadcast_num_shapes][broadcast_max_shape_size] = { + { 4, 1, 1, 3, 2 }, + { 4, 1, 3, 1, 2 }, + { 4, 2, 1, 3, 1 }, + { 4, 2, 3, 1, 1 }, +}; +int broadcast_output_shapes[broadcast_num_shapes][broadcast_max_shape_size] = { + { 4, 2, 3, 3, 2 }, + { 4, 2, 3, 1, 2 }, + { 4, 2, 3, 3, 2 }, + { 4, 2, 3, 1, 2 }, +}; + +template +void ValidateSubGoldens(TfLiteTensor *tensors, int tensors_size, + const T *golden, T *output, int output_size, + TfLiteFusedActivation activation, + float tolerance = 1e-5) +{ + TfLiteSubParams builtin_data; + builtin_data.activation = activation; + + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = tflite::ops::micro::Register_SUB(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, &builtin_data); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_size; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(golden[i], output[i], tolerance); + } +} + +void TestSubFloat(int *input1_dims_data, const float *input1_data, + int *input2_dims_data, const float *input2_data, + int *output_dims_data, const float *expected_output, + TfLiteFusedActivation activation, float *output_data) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input1_data, input1_dims), + CreateTensor(input2_data, input2_dims), + CreateTensor(output_data, output_dims), + }; + + ValidateSubGoldens(tensors, tensors_size, expected_output, output_data, + ElementCount(*output_dims), activation); +} + +template +void TestSubQuantized(int *input1_dims_data, const float *input1_data, + T *input1_quantized, float input1_scale, + int input1_zero_point, int *input2_dims_data, + const float *input2_data, T *input2_quantized, + float input2_scale, int input2_zero_point, + int *output_dims_data, const float *golden, + T *golden_quantized, float output_scale, + int output_zero_point, TfLiteFusedActivation activation, + T *output_data) +{ + TfLiteIntArray *input1_dims = IntArrayFromInts(input1_dims_data); + TfLiteIntArray *input2_dims = IntArrayFromInts(input2_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + tflite::testing::CreateQuantizedTensor(input1_data, input1_quantized, + input1_dims, input1_scale, + input1_zero_point), + tflite::testing::CreateQuantizedTensor(input2_data, input2_quantized, + input2_dims, input2_scale, + input2_zero_point), + tflite::testing::CreateQuantizedTensor(output_data, output_dims, + output_scale, output_zero_point), + }; + tflite::Quantize(golden, golden_quantized, ElementCount(*output_dims), + output_scale, output_zero_point); + + ValidateSubGoldens(tensors, tensors_size, golden_quantized, output_data, + ElementCount(*output_dims), activation); +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(FloatSubNoActivation) +{ + const int output_dims_count = 4; + int inout_shape[] = { 4, 1, 2, 2, 1 }; + const float input1_values[] = { -2.0, 0.2, 0.7, 0.8 }; + const float input2_values[] = { 0.1, 0.2, 0.3, 0.5 }; + const float golden_values[] = { -2.1, 0.0, 0.4, 0.3 }; + float output_data[output_dims_count]; + tflite::testing::TestSubFloat(inout_shape, input1_values, inout_shape, + input2_values, inout_shape, golden_values, + kTfLiteActNone, output_data); +} + +TF_LITE_MICRO_TEST(FloatSubActivationRelu1) +{ + const int output_dims_count = 4; + int inout_shape[] = { 4, 1, 2, 2, 1 }; + const float input1_values[] = { -2.0, 0.2, 2.0, 0.8 }; + const float input2_values[] = { 2.0, 0.2, 0.3, 0.5 }; + const float golden_values[] = { -1.0, 0.0, 1.0, 0.3 }; + + float output_data[output_dims_count]; + tflite::testing::TestSubFloat(inout_shape, input1_values, inout_shape, + input2_values, inout_shape, golden_values, + kTfLiteActReluN1To1, output_data); +} + +TF_LITE_MICRO_TEST(FloatSubVariousInputShapes) +{ + const int output_dims_count = 6; + float output_data[output_dims_count]; + + const float input1_values[] = { -2.0, 0.2, 0.7, 0.8, 1.1, 2.0 }; + const float input2_values[] = { 0.1, 0.2, 0.3, 0.5, 1.1, 0.1 }; + const float expected_output[] = { -2.1, 0.0, 0.4, 0.3, 0.0, 1.9 }; + + constexpr int num_shapes = 4; + constexpr int max_shape_size = 5; + int test_shapes[num_shapes][max_shape_size] = { + { 1, 6 }, + { 2, 2, 3 }, + { 3, 2, 1, 3 }, + { 4, 1, 3, 1, 2 }, + }; + + for (int i = 0; i < num_shapes; ++i) { + tflite::testing::TestSubFloat(test_shapes[i], input1_values, test_shapes[i], + input2_values, test_shapes[i], + expected_output, kTfLiteActNone, output_data); + } +} + +TF_LITE_MICRO_TEST(FloatSubWithScalarBroadcast) +{ + const int output_dims_count = 6; + float output_data[output_dims_count]; + + const float input1_values[] = { -2.0, 0.2, 0.7, 0.8, 1.1, 2.0 }; + int input2_shape[] = { 0 }; + const float input2_values[] = { 0.1 }; + const float expected_output[] = { -2.1, 0.1, 0.6, 0.7, 1.0, 1.9 }; + + constexpr int num_shapes = 4; + constexpr int max_shape_size = 5; + int test_shapes[num_shapes][max_shape_size] = { + { 1, 6 }, + { 2, 2, 3 }, + { 3, 2, 1, 3 }, + { 4, 1, 3, 1, 2 }, + }; + + for (int i = 0; i < num_shapes; ++i) { + tflite::testing::TestSubFloat(test_shapes[i], input1_values, input2_shape, + input2_values, test_shapes[i], + expected_output, kTfLiteActNone, output_data); + } +} + +TF_LITE_MICRO_TEST(QuantizedSubNoActivationUint8) +{ + const float scales[] = { 0.25, 0.5, 1.0 }; + const int zero_points[] = { 125, 129, 135 }; + const int output_dims_count = 4; + int inout_shape[] = { 4, 1, 2, 2, 1 }; + const float input1_values[] = { -2.01, -1.01, -0.01, 0.98 }; + const float input2_values[] = { -1.01, -1.99, -2.99, -4.02 }; + const float golden_values[] = { -1, 1, 3, 5 }; + + uint8_t input1_quantized[output_dims_count]; + uint8_t input2_quantized[output_dims_count]; + uint8_t golden_quantized[output_dims_count]; + uint8_t output[output_dims_count]; + + tflite::testing::TestSubQuantized( + inout_shape, input1_values, input1_quantized, scales[0], zero_points[0], + inout_shape, input2_values, input2_quantized, scales[1], zero_points[1], + inout_shape, golden_values, golden_quantized, scales[2], zero_points[2], + kTfLiteActNone, output); +} + +TF_LITE_MICRO_TEST(QuantizedSubNoActivationInt8) +{ + const float scales[] = { 0.25, 0.5, 1.0 }; + const int zero_points[] = { -10, 4, 13 }; + const int output_dims_count = 4; + int inout_shape[] = { 4, 1, 2, 2, 1 }; + const float input1_values[] = { -2.01, -1.01, -0.01, 0.98 }; + const float input2_values[] = { -1.01, -1.99, -2.99, -4.02 }; + const float golden_values[] = { -1, 1, 3, 5 }; + + int8_t input1_quantized[output_dims_count]; + int8_t input2_quantized[output_dims_count]; + int8_t golden_quantized[output_dims_count]; + int8_t output[output_dims_count]; + + tflite::testing::TestSubQuantized( + inout_shape, input1_values, input1_quantized, scales[0], zero_points[0], + inout_shape, input2_values, input2_quantized, scales[1], zero_points[1], + inout_shape, golden_values, golden_quantized, scales[2], zero_points[2], + kTfLiteActNone, output); +} + +TF_LITE_MICRO_TEST(QuantizedSubActivationRelu1Uint8) +{ + const float scales[] = { 0.25, 0.5, 1.0 }; + const int zero_points[] = { 125, 129, 135 }; + const int output_dims_count = 4; + int inout_shape[] = { 4, 1, 2, 2, 1 }; + const float input1_values[] = { -2.01, -1.01, -0.01, 0.98 }; + const float input2_values[] = { -1.01, -1.99, -2.99, -4.02 }; + const float golden_values[] = { -1, 1, 1, 1 }; + + uint8_t input1_quantized[output_dims_count]; + uint8_t input2_quantized[output_dims_count]; + uint8_t golden_quantized[output_dims_count]; + uint8_t output[output_dims_count]; + + tflite::testing::TestSubQuantized( + inout_shape, input1_values, input1_quantized, scales[0], zero_points[0], + inout_shape, input2_values, input2_quantized, scales[1], zero_points[1], + inout_shape, golden_values, golden_quantized, scales[2], zero_points[2], + kTfLiteActReluN1To1, output); +} + +TF_LITE_MICRO_TEST(QuantizedSubActivationRelu1Int8) +{ + const float scales[] = { 0.25, 0.5, 1.0 }; + const int zero_points[] = { -10, 4, 13 }; + const int output_dims_count = 4; + int inout_shape[] = { 4, 1, 2, 2, 1 }; + const float input1_values[] = { -2.01, -1.01, -0.01, 0.98 }; + const float input2_values[] = { -1.01, -1.99, -2.99, -4.02 }; + const float golden_values[] = { -1, 1, 1, 1 }; + + int8_t input1_quantized[output_dims_count]; + int8_t input2_quantized[output_dims_count]; + int8_t golden_quantized[output_dims_count]; + int8_t output[output_dims_count]; + + tflite::testing::TestSubQuantized( + inout_shape, input1_values, input1_quantized, scales[0], zero_points[0], + inout_shape, input2_values, input2_quantized, scales[1], zero_points[1], + inout_shape, golden_values, golden_quantized, scales[2], zero_points[2], + kTfLiteActReluN1To1, output); +} + +TF_LITE_MICRO_TEST(QuantizedSubActivationRelu1Int16) +{ + const float scales[] = { 0.25, 0.5, 1.0 }; + const int zero_points[] = { 0, 0, 0 }; + const int output_dims_count = 4; + int inout_shape[] = { 4, 1, 2, 2, 1 }; + const float input1_values[] = { -2.01, -1.01, -0.01, 0.98 }; + const float input2_values[] = { -1.01, -1.99, -2.99, -4.02 }; + const float golden_values[] = { -1, 1, 1, 1 }; + + int16_t input1_quantized[output_dims_count]; + int16_t input2_quantized[output_dims_count]; + int16_t golden_quantized[output_dims_count]; + int16_t output[output_dims_count]; + + tflite::testing::TestSubQuantized( + inout_shape, input1_values, input1_quantized, scales[0], zero_points[0], + inout_shape, input2_values, input2_quantized, scales[1], zero_points[1], + inout_shape, golden_values, golden_quantized, scales[2], zero_points[2], + kTfLiteActReluN1To1, output); +} + +TF_LITE_MICRO_TEST(QuantizedSubVariousInputShapesUint8) +{ + const float scales[] = { 0.1, 0.05, 0.1 }; + const int zero_points[] = { 120, 130, 139 }; + const int output_dims_count = 6; + + constexpr int num_shapes = 4; + constexpr int max_shape_size = 5; + int test_shapes[num_shapes][max_shape_size] = { + { 1, 6 }, + { 2, 2, 3 }, + { 3, 2, 1, 3 }, + { 4, 1, 3, 1, 2 }, + }; + + const float input1_values[] = { -2.0, 0.2, 0.7, 0.8, 1.1, 2.0 }; + const float input2_values[] = { -0.1, -0.2, -0.3, -0.5, -1.1, -0.1 }; + const float golden_values[] = { -1.9, 0.4, 1.0, 1.3, 2.2, 2.1 }; + + uint8_t input1_quantized[output_dims_count]; + uint8_t input2_quantized[output_dims_count]; + uint8_t golden_quantized[output_dims_count]; + uint8_t output[output_dims_count]; + + for (int i = 0; i < num_shapes; i++) { + tflite::testing::TestSubQuantized( + test_shapes[i], input1_values, input1_quantized, scales[0], + zero_points[0], test_shapes[i], input2_values, input2_quantized, + scales[1], zero_points[1], test_shapes[i], golden_values, + golden_quantized, scales[2], zero_points[2], kTfLiteActNone, output); + } +} + +TF_LITE_MICRO_TEST(QuantizedSubVariousInputShapesInt8) +{ + const float scales[] = { 0.1, 0.05, 0.1 }; + const int zero_points[] = { -9, 5, 14 }; + const int output_dims_count = 6; + + constexpr int num_shapes = 4; + constexpr int max_shape_size = 5; + int test_shapes[num_shapes][max_shape_size] = { + { 1, 6 }, + { 2, 2, 3 }, + { 3, 2, 1, 3 }, + { 4, 1, 3, 1, 2 }, + }; + + const float input1_values[] = { -2.0, 0.2, 0.7, 0.8, 1.1, 2.0 }; + const float input2_values[] = { -0.1, -0.2, -0.3, -0.5, -1.1, -0.1 }; + const float golden_values[] = { -1.9, 0.4, 1.0, 1.3, 2.2, 2.1 }; + + int8_t input1_quantized[output_dims_count]; + int8_t input2_quantized[output_dims_count]; + int8_t golden_quantized[output_dims_count]; + int8_t output[output_dims_count]; + + for (int i = 0; i < num_shapes; i++) { + tflite::testing::TestSubQuantized( + test_shapes[i], input1_values, input1_quantized, scales[0], + zero_points[0], test_shapes[i], input2_values, input2_quantized, + scales[1], zero_points[1], test_shapes[i], golden_values, + golden_quantized, scales[2], zero_points[2], kTfLiteActNone, output); + } +} + +TF_LITE_MICRO_TEST(QuantizedSubVariousInputShapesInt16) +{ + const float scales[] = { 0.1, 0.05, 0.1 }; + const int zero_points[] = { 0, 0, 0 }; + const int output_dims_count = 6; + + constexpr int num_shapes = 4; + constexpr int max_shape_size = 5; + int test_shapes[num_shapes][max_shape_size] = { + { 1, 6 }, + { 2, 2, 3 }, + { 3, 2, 1, 3 }, + { 4, 1, 3, 1, 2 }, + }; + + const float input1_values[] = { -2.0, 0.2, 0.7, 0.8, 1.1, 2.0 }; + const float input2_values[] = { -0.1, -0.2, -0.3, -0.5, -1.1, -0.1 }; + const float golden_values[] = { -1.9, 0.4, 1.0, 1.3, 2.2, 2.1 }; + + int16_t input1_quantized[output_dims_count]; + int16_t input2_quantized[output_dims_count]; + int16_t golden_quantized[output_dims_count]; + int16_t output[output_dims_count]; + + for (int i = 0; i < num_shapes; i++) { + tflite::testing::TestSubQuantized( + test_shapes[i], input1_values, input1_quantized, scales[0], + zero_points[0], test_shapes[i], input2_values, input2_quantized, + scales[1], zero_points[1], test_shapes[i], golden_values, + golden_quantized, scales[2], zero_points[2], kTfLiteActNone, output); + } +} + +TF_LITE_MICRO_TEST(QuantizedSubWithScalarBroadcastUint8) +{ + const int output_dims_count = 6; + + const float input1_values[] = { -2.0, 0.2, 0.7, 0.8, 1.1, 2.0 }; + int input2_shape[] = { 0 }; + const float input2_values[] = { -0.1 }; + const float golden[] = { -1.9, 0.3, 0.8, 0.9, 1.2, 2.1 }; + + constexpr int num_shapes = 4; + constexpr int max_shape_size = 5; + int test_shapes[num_shapes][max_shape_size] = { + { 1, 6 }, + { 2, 2, 3 }, + { 3, 2, 1, 3 }, + { 4, 1, 3, 1, 2 }, + }; + + const float scales[] = { 0.1, 0.1, 0.1 }; + const int zero_points[] = { 120, 131, 139 }; + + uint8_t input1_quantized[output_dims_count]; + uint8_t input2_quantized[output_dims_count]; + uint8_t golden_quantized[output_dims_count]; + uint8_t output[output_dims_count]; + + for (int i = 0; i < num_shapes; ++i) { + tflite::testing::TestSubQuantized( + test_shapes[i], input1_values, input1_quantized, scales[0], + zero_points[0], input2_shape, input2_values, input2_quantized, + scales[1], zero_points[1], test_shapes[i], golden, golden_quantized, + scales[2], zero_points[2], kTfLiteActNone, output); + } +} +TF_LITE_MICRO_TEST(QuantizedSubWithScalarBroadcastFloat) +{ + float output_float[tflite::testing::broadcast_output_dims_count]; + + for (int i = 0; i < tflite::testing::broadcast_num_shapes; ++i) { + tflite::testing::TestSubFloat(tflite::testing::broadcast_input1_shape, + tflite::testing::broadcast_input1_values, + tflite::testing::broadcast_input2_shapes[i], + tflite::testing::broadcast_input2_values, + tflite::testing::broadcast_output_shapes[i], + tflite::testing::broadcast_goldens[i], + kTfLiteActNone, output_float); + } +} + +TF_LITE_MICRO_TEST(QuantizedSubWithScalarBroadcastInt8) +{ + const int output_dims_count = 6; + + const float input1_values[] = { -2.0, 0.2, 0.7, 0.8, 1.1, 2.0 }; + int input2_shape[] = { 0 }; + const float input2_values[] = { -0.1 }; + const float golden[] = { -1.9, 0.3, 0.8, 0.9, 1.2, 2.1 }; + + constexpr int num_shapes = 4; + constexpr int max_shape_size = 5; + int test_shapes[num_shapes][max_shape_size] = { + { 1, 6 }, + { 2, 2, 3 }, + { 3, 2, 1, 3 }, + { 4, 1, 3, 1, 2 }, + }; + + const float scales[] = { 0.1, 0.05, 0.05 }; + const int zero_points[] = { -8, 4, 12 }; + + int8_t input1_quantized[output_dims_count]; + int8_t input2_quantized[output_dims_count]; + int8_t golden_quantized[output_dims_count]; + int8_t output[output_dims_count]; + + for (int i = 0; i < num_shapes; ++i) { + tflite::testing::TestSubQuantized( + test_shapes[i], input1_values, input1_quantized, scales[0], + zero_points[0], input2_shape, input2_values, input2_quantized, + scales[1], zero_points[1], test_shapes[i], golden, golden_quantized, + scales[2], zero_points[2], kTfLiteActNone, output); + } +} + +TF_LITE_MICRO_TEST(QuantizedSubWithScalarBroadcastInt16) +{ + const int output_dims_count = 6; + + const float input1_values[] = { -2.0, 0.2, 0.7, 0.8, 1.1, 2.0 }; + int input2_shape[] = { 0 }; + const float input2_values[] = { -0.1 }; + const float golden[] = { -1.9, 0.3, 0.8, 0.9, 1.2, 2.1 }; + + constexpr int num_shapes = 4; + constexpr int max_shape_size = 5; + int test_shapes[num_shapes][max_shape_size] = { + { 1, 6 }, + { 2, 2, 3 }, + { 3, 2, 1, 3 }, + { 4, 1, 3, 1, 2 }, + }; + + const float scales[] = { 0.1, 0.05, 0.05 }; + const int zero_points[] = { 0, 0, 0 }; + + int16_t input1_quantized[output_dims_count]; + int16_t input2_quantized[output_dims_count]; + int16_t golden_quantized[output_dims_count]; + int16_t output[output_dims_count]; + + for (int i = 0; i < num_shapes; ++i) { + tflite::testing::TestSubQuantized( + test_shapes[i], input1_values, input1_quantized, scales[0], + zero_points[0], input2_shape, input2_values, input2_quantized, + scales[1], zero_points[1], test_shapes[i], golden, golden_quantized, + scales[2], zero_points[2], kTfLiteActNone, output); + } +} + +TF_LITE_MICRO_TEST(QuantizedSubWithMixedBroadcastUint8) +{ + const float scales[] = { 0.1, 0.05, 0.1 }; + const int zero_points[] = { 127, 131, 139 }; + uint8_t input1_quantized[tflite::testing::broadcast_output_dims_count]; + uint8_t input2_quantized[tflite::testing::broadcast_output_dims_count]; + uint8_t golden_quantized[tflite::testing::broadcast_output_dims_count]; + uint8_t output[tflite::testing::broadcast_output_dims_count]; + + for (int i = 0; i < tflite::testing::broadcast_num_shapes; ++i) { + tflite::testing::TestSubQuantized( + tflite::testing::broadcast_input1_shape, + tflite::testing::broadcast_input1_values, input1_quantized, scales[0], + zero_points[0], tflite::testing::broadcast_input2_shapes[i], + tflite::testing::broadcast_input2_values, input2_quantized, scales[1], + zero_points[1], tflite::testing::broadcast_output_shapes[i], + tflite::testing::broadcast_goldens[i], golden_quantized, scales[2], + zero_points[2], kTfLiteActNone, output); + } +} + +TF_LITE_MICRO_TEST(QuantizedSubWithMixedBroadcastInt8) +{ + const float scales[] = { 0.1, 0.05, 0.1 }; + const int zero_points[] = { -10, -5, 7 }; + int8_t input1_quantized[tflite::testing::broadcast_output_dims_count]; + int8_t input2_quantized[tflite::testing::broadcast_output_dims_count]; + int8_t golden_quantized[tflite::testing::broadcast_output_dims_count]; + int8_t output[tflite::testing::broadcast_output_dims_count]; + + for (int i = 0; i < tflite::testing::broadcast_num_shapes; ++i) { + tflite::testing::TestSubQuantized( + tflite::testing::broadcast_input1_shape, + tflite::testing::broadcast_input1_values, input1_quantized, scales[0], + zero_points[0], tflite::testing::broadcast_input2_shapes[i], + tflite::testing::broadcast_input2_values, input2_quantized, scales[1], + zero_points[1], tflite::testing::broadcast_output_shapes[i], + tflite::testing::broadcast_goldens[i], golden_quantized, scales[2], + zero_points[2], kTfLiteActNone, output); + } +} + +TF_LITE_MICRO_TEST(QuantizedSubWithMixedBroadcastInt16) +{ + const float scales[] = { 0.1, 0.05, 0.1 }; + const int zero_points[] = { 0, 0, 0 }; + int16_t input1_quantized[tflite::testing::broadcast_output_dims_count]; + int16_t input2_quantized[tflite::testing::broadcast_output_dims_count]; + int16_t golden_quantized[tflite::testing::broadcast_output_dims_count]; + int16_t output[tflite::testing::broadcast_output_dims_count]; + + for (int i = 0; i < tflite::testing::broadcast_num_shapes; ++i) { + tflite::testing::TestSubQuantized( + tflite::testing::broadcast_input1_shape, + tflite::testing::broadcast_input1_values, input1_quantized, scales[0], + zero_points[0], tflite::testing::broadcast_input2_shapes[i], + tflite::testing::broadcast_input2_values, input2_quantized, scales[1], + zero_points[1], tflite::testing::broadcast_output_shapes[i], + tflite::testing::broadcast_goldens[i], golden_quantized, scales[2], + zero_points[2], kTfLiteActNone, output); + } +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/svdf.cc b/components/tflite/tensorflow/lite/micro/kernels/svdf.cc new file mode 100644 index 00000000..46a849f1 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/svdf.cc @@ -0,0 +1,98 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/kernels/svdf.h" + +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/activation_utils.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/micro_utils.h" + +namespace tflite { +namespace { + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(OpData)); +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + auto *params = reinterpret_cast(node->builtin_data); + TFLITE_DCHECK(node->user_data != nullptr); + const OpData &data = *(static_cast(node->user_data)); + + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kSvdfInputTensor); + const TfLiteEvalTensor *weights_feature = + tflite::micro::GetEvalInput(context, node, kSvdfWeightsFeatureTensor); + const TfLiteEvalTensor *weights_time = + tflite::micro::GetEvalInput(context, node, kSvdfWeightsTimeTensor); + const TfLiteEvalTensor *bias = + (NumInputs(node) == 5) ? tflite::micro::GetEvalInput(context, node, kSvdfBiasTensor) : nullptr; + TfLiteEvalTensor *activation_state = tflite::micro::GetMutableEvalInput( + context, node, kSvdfInputActivationStateTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kSvdfOutputTensor); + + switch (weights_feature->type) { + case kTfLiteFloat32: { + EvalFloatSvdfReference( + context, node, input, weights_feature, weights_time, bias, params, + data.scratch_tensor_index, activation_state, output); + return kTfLiteOk; + break; + } + + case kTfLiteInt8: { + EvalIntegerSvdfReference(context, node, input, weights_feature, + weights_time, bias, params, activation_state, + output, data); + return kTfLiteOk; + break; + } + + default: + TF_LITE_KERNEL_LOG(context, "Type %s not currently supported.", + TfLiteTypeGetName(weights_feature->type)); + return kTfLiteError; + } + return kTfLiteOk; +} + +} // namespace + +TfLiteRegistration Register_SVDF() +{ + return { /*init=*/Init, + /*free=*/nullptr, + /*prepare=*/PrepareSvdf, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/svdf.h b/components/tflite/tensorflow/lite/micro/kernels/svdf.h new file mode 100644 index 00000000..87477a4c --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/svdf.h @@ -0,0 +1,70 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_MICRO_KERNELS_SVDF_H_ +#define TENSORFLOW_LITE_MICRO_KERNELS_SVDF_H_ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" + +namespace tflite { +struct OpData { + int32_t effective_scale_1_a; + int32_t effective_scale_2_a; + // b versions of each scale are kept at int since the numbers are just the + // shift value - typically between [-32, 32]. + int effective_scale_1_b; + int effective_scale_2_b; + int scratch_tensor_index; + int scratch_output_tensor_index; + + // Cached tensor zero point values for quantized operations. + int input_zero_point; + int output_zero_point; +}; + +// Input tensors. +extern const int kSvdfInputTensor; +extern const int kSvdfWeightsFeatureTensor; +extern const int kSvdfWeightsTimeTensor; +extern const int kSvdfBiasTensor; +// This is a variable tensor, and will be modified by this op. +extern const int kSvdfInputActivationStateTensor; + +// Output tensor. +extern const int kSvdfOutputTensor; + +// TensorflowLite Micro-specific reference implementation for Integer SVDF. +void EvalIntegerSvdfReference(TfLiteContext *context, TfLiteNode *node, + const TfLiteEvalTensor *input_tensor, + const TfLiteEvalTensor *weights_feature_tensor, + const TfLiteEvalTensor *weights_time_tensor, + const TfLiteEvalTensor *bias_tensor, + const TfLiteSVDFParams *params, + TfLiteEvalTensor *activation_state_tensor, + TfLiteEvalTensor *output_tensor, + const OpData &data); + +void EvalFloatSvdfReference( + TfLiteContext *context, TfLiteNode *node, const TfLiteEvalTensor *input, + const TfLiteEvalTensor *weights_feature, + const TfLiteEvalTensor *weights_time, const TfLiteEvalTensor *bias, + const TfLiteSVDFParams *params, int scratch_tensor_index, + TfLiteEvalTensor *activation_state, TfLiteEvalTensor *output); + +TfLiteStatus PrepareSvdf(TfLiteContext *context, TfLiteNode *node); + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_KERNELS_SVDF_H_ diff --git a/components/tflite/tensorflow/lite/micro/kernels/svdf_common.cc b/components/tflite/tensorflow/lite/micro/kernels/svdf_common.cc new file mode 100644 index 00000000..5ce9970c --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/svdf_common.cc @@ -0,0 +1,473 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/activation_utils.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/svdf.h" +#include "tensorflow/lite/micro/micro_utils.h" + +namespace tflite { + +/** + * This version of SVDF is specific to TFLite Micro. It contains the following + * differences between the TFLite version: + * + * 1.) Scratch tensor allocation - scratch tensors must be known ahead of time + * for the Micro interpreter. + * 2.) Output dimensions - the TFLite version determines output size and runtime + * and resizes the output tensor. Micro runtime does not support tensor + * resizing. + */ + +const int kSvdfInputTensor = 0; +const int kSvdfWeightsFeatureTensor = 1; +const int kSvdfWeightsTimeTensor = 2; +const int kSvdfBiasTensor = 3; +const int kSvdfInputActivationStateTensor = + 4; // This is a variable tensor, and will be modified by this op. +const int kSvdfOutputTensor = 0; + +void EvalIntegerSvdfReference(TfLiteContext *context, TfLiteNode *node, + const TfLiteEvalTensor *input_tensor, + const TfLiteEvalTensor *weights_feature_tensor, + const TfLiteEvalTensor *weights_time_tensor, + const TfLiteEvalTensor *bias_tensor, + const TfLiteSVDFParams *params, + TfLiteEvalTensor *activation_state_tensor, + TfLiteEvalTensor *output_tensor, + const OpData &data) +{ + const int n_rank = params->rank; + const int n_batch = input_tensor->dims->data[0]; + const int n_input = input_tensor->dims->data[1]; + const int n_filter = weights_feature_tensor->dims->data[0]; + const int n_unit = n_filter / n_rank; + const int n_memory = weights_time_tensor->dims->data[1]; + + TFLITE_DCHECK(context != nullptr); + TFLITE_DCHECK(context->GetScratchBuffer != nullptr); + + int32_t *scratch_tensor = static_cast( + context->GetScratchBuffer(context, data.scratch_tensor_index)); + int32_t *scratch_output_tensor = static_cast( + context->GetScratchBuffer(context, data.scratch_output_tensor_index)); + + // Shift states. + int16_t *const state_ptr = + tflite::micro::GetTensorData(activation_state_tensor); + + // Left shift the activation_state. + { + int16_t *new_state_start = state_ptr; + const int16_t *old_state_start = state_ptr + 1; + const int16_t *old_state_end = state_ptr + n_batch * n_filter * n_memory; + while (old_state_start != old_state_end) { + *new_state_start++ = *old_state_start++; + } + } + + // Note: no need to clear the latest activation, matmul is not accumulative. + + // Feature matmul. + { + int16_t *state = + tflite::micro::GetTensorData(activation_state_tensor); + const int8_t *input = tflite::micro::GetTensorData(input_tensor); + const int8_t *weight_feature = + tflite::micro::GetTensorData(weights_feature_tensor); + const int32_t output_max = std::numeric_limits::max(); + const int32_t output_min = std::numeric_limits::min(); + int16_t *result_in_batch = state + (n_memory - 1); + for (int b = 0; b < n_batch; b++) { + const int8_t *matrix_ptr = weight_feature; + for (int r = 0; r < n_filter; r++) { + int32_t dot_prod = 0; + const int8_t *vector_in_batch = input + b * n_input; + for (int c = 0; c < n_input; c++) { + dot_prod += + *matrix_ptr++ * (*vector_in_batch++ - data.input_zero_point); + } + dot_prod = MultiplyByQuantizedMultiplier( + dot_prod, data.effective_scale_1_a, data.effective_scale_1_b); + dot_prod = std::min(std::max(output_min, dot_prod), output_max); + // This assumes state is symmetrically quantized. Otherwise last bit of + // state should be initialized to its zero point and accumulate the + // dot_prod. + // Equivalent as the following: + // result_in_batch = zero point, which happens to be zero. + // result_in_batch += dot_prod_56. + *result_in_batch = dot_prod; + result_in_batch += n_memory; + } + } + } + + // Time. + { + for (int b = 0; b < n_batch; ++b) { + int32_t *scratch_ptr_batch = scratch_tensor + b * n_filter; + + // Perform batched vector dot product: + const int16_t *vector1_ptr = + tflite::micro::GetTensorData(weights_time_tensor); + const int16_t *vector2_ptr = + tflite::micro::GetTensorData(activation_state_tensor) + + b * n_memory * n_filter; + + for (int i = 0; i < n_filter; i++) { + *scratch_ptr_batch = 0; + for (int j = 0; j < n_memory; j++) { + *scratch_ptr_batch += *vector1_ptr++ * *vector2_ptr++; + } + scratch_ptr_batch++; + } + } + } + + // Reduce, add bias, rescale, activation. + { + // Add bias. + if (bias_tensor) { + // Vector batch assign: + const int32_t *bias_data = + tflite::micro::GetTensorData(bias_tensor); + for (int i = 0; i < n_batch; ++i) { + int32_t *output_ptr = scratch_output_tensor + i * n_unit; + const int32_t *bias_ptr = bias_data; + for (int j = 0; j < n_unit; ++j) { + *output_ptr++ = *bias_ptr++; + } + } + } else { + int32_t *output_ptr = scratch_output_tensor; + for (int i = 0; i < n_batch * n_unit; ++i) { + *output_ptr++ = 0; + } + } + + // Reduce. + for (int b = 0; b < n_batch; ++b) { + int32_t *output_temp_ptr = scratch_output_tensor + b * n_unit; + int32_t *scratch_ptr_batch = scratch_tensor + b * n_filter; + + // Reduction sum vector + for (int i = 0; i < n_unit; ++i) { + for (int j = 0; j < n_rank; ++j) { + output_temp_ptr[i] += *scratch_ptr_batch++; + } + } + } + + // Rescale. + const int32_t output_max = std::numeric_limits::max(); + const int32_t output_min = std::numeric_limits::min(); + for (int i = 0; i < n_batch * n_unit; ++i) { + int32_t x1 = scratch_output_tensor[i]; + int32_t x2 = MultiplyByQuantizedMultiplier(x1, data.effective_scale_2_a, + data.effective_scale_2_b); + int32_t x3 = x2 + data.output_zero_point; + int32_t x4 = std::min(std::max(output_min, x3), output_max); + tflite::micro::GetTensorData(output_tensor)[i] = + static_cast(x4); + } + } +} +static inline void ApplyTimeWeightsBiasAndActivation( + int batch_size, int memory_size, int num_filters, int num_units, int rank, + const float *const __restrict__ weights_time_ptr, + const float *const __restrict__ bias_ptr, TfLiteFusedActivation activation, + float *const __restrict__ state_ptr, float *const __restrict__ scratch_ptr, + float *const __restrict__ output_ptr) +{ + // Compute matmul(activation_state, weights_time). + for (int b = 0; b < batch_size; ++b) { + // Perform batched vector dot product: + float *scratch_ptr_batch = scratch_ptr + b * num_filters; + const float *vector1_ptr = weights_time_ptr; + const float *vector2_ptr = state_ptr + b * memory_size * num_filters; + for (int i = 0; i < num_filters; ++i) { + *scratch_ptr_batch = 0.f; + for (int j = 0; j < memory_size; ++j) { + *scratch_ptr_batch += *vector1_ptr++ * *vector2_ptr++; + } + scratch_ptr_batch++; + } + } + + // Initialize output with bias if provided. + if (bias_ptr) { + // VectorBatchVectorAssign + for (int i = 0; i < batch_size; ++i) { + float *output_data = output_ptr + i * num_units; + const float *bias_data = bias_ptr; + for (int j = 0; j < num_units; ++j) { + *output_data++ = *bias_data++; + } + } + } else { + float *output_data = output_ptr; + for (int i = 0; i < batch_size * num_units; ++i) { + *output_data++ = 0.0f; + } + } + + // Reduction sum. + for (int b = 0; b < batch_size; ++b) { + float *output_ptr_batch = output_ptr + b * num_units; + float *scratch_ptr_batch = scratch_ptr + b * num_filters; + + // Reduction sum vector + for (int i = 0; i < num_units; ++i) { + for (int j = 0; j < rank; j++) { + output_ptr_batch[i] += *scratch_ptr_batch++; + } + } + } + + // Apply activation. + for (int b = 0; b < batch_size; ++b) { + float *output_ptr_batch = output_ptr + b * num_units; + for (int i = 0; i < num_units; ++i) { + *output_ptr_batch = + tflite::ops::micro::ActivationValFloat(activation, *output_ptr_batch); + ++output_ptr_batch; + } + } +} + +void EvalFloatSvdfReference( + TfLiteContext *context, TfLiteNode *node, const TfLiteEvalTensor *input, + const TfLiteEvalTensor *weights_feature, + const TfLiteEvalTensor *weights_time, const TfLiteEvalTensor *bias, + const TfLiteSVDFParams *params, int scratch_tensor_index, + TfLiteEvalTensor *activation_state, TfLiteEvalTensor *output) +{ + const int rank = params->rank; + const int batch_size = input->dims->data[0]; + const int input_size = input->dims->data[1]; + const int num_filters = weights_feature->dims->data[0]; + const int num_units = num_filters / rank; + const int memory_size = weights_time->dims->data[1]; + + const float *weights_feature_ptr = + tflite::micro::GetTensorData(weights_feature); + const float *weights_time_ptr = + tflite::micro::GetTensorData(weights_time); + const float *bias_ptr = tflite::micro::GetTensorData(bias); + const float *input_ptr = tflite::micro::GetTensorData(input); + + float *state_ptr = tflite::micro::GetTensorData(activation_state); + + TFLITE_DCHECK(context != nullptr); + TFLITE_DCHECK(context->GetScratchBuffer != nullptr); + + float *scratch_ptr = static_cast( + context->GetScratchBuffer(context, scratch_tensor_index)); + + float *output_ptr = tflite::micro::GetTensorData(output); + + // Left shift the activation_state. + { + float *new_state_start = state_ptr; + const float *old_state_start = state_ptr + 1; + const float *old_state_end = + state_ptr + batch_size * num_filters * memory_size; + while (old_state_start != old_state_end) { + *new_state_start++ = *old_state_start++; + } + } + + // Note: no need to clear the latest activation, matmul is not accumulative. + + // Compute conv1d(inputs, weights_feature). + // The activation_state's rightmost column is used to save current cycle + // activation. This is achieved by starting at state_ptr[memory_size - 1] and + // having the stride equal to memory_size. + + // Perform batched matrix vector multiply operation: + { + const float *matrix = weights_feature_ptr; + const float *vector = input_ptr; + float *result = &state_ptr[memory_size - 1]; + float *result_in_batch = result; + for (int i = 0; i < batch_size; ++i) { + const float *matrix_ptr = matrix; + for (int j = 0; j < num_filters; ++j) { + float dot_prod = 0.0f; + const float *vector_in_batch = vector + i * input_size; + for (int k = 0; k < input_size; ++k) { + dot_prod += *matrix_ptr++ * *vector_in_batch++; + } + *result_in_batch = dot_prod; + result_in_batch += memory_size; + } + } + } + + ApplyTimeWeightsBiasAndActivation( + batch_size, memory_size, num_filters, num_units, rank, weights_time_ptr, + bias_ptr, params->activation, state_ptr, scratch_ptr, output_ptr); +} + +TfLiteStatus PrepareSvdf(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->builtin_data != nullptr); + + const auto *params = static_cast(node->builtin_data); + + // Validate Tensor Inputs (dtype depends on quantization): + // [0] = Input, {2, batch_size, input_size} + // [1] = Weights Feature, {2, num_filters, input_size} + // [2] = Weights Time, {2, num_filters, memory_size} + // [3] = Bias (optional), {1, num_units} + // [4] = Activation State (variable), + // {2, batch_size, memory_size * num_filters} + const TfLiteTensor *input = GetInput(context, node, kSvdfInputTensor); + TF_LITE_ENSURE(context, input != nullptr); + const TfLiteTensor *weights_feature = + GetInput(context, node, kSvdfWeightsFeatureTensor); + TF_LITE_ENSURE(context, weights_feature != nullptr); + const TfLiteTensor *weights_time = + GetInput(context, node, kSvdfWeightsTimeTensor); + TF_LITE_ENSURE(context, weights_time != nullptr); + const TfLiteTensor *bias = + GetOptionalInputTensor(context, node, kSvdfBiasTensor); + const TfLiteTensor *activation_state = + GetInput(context, node, kSvdfInputActivationStateTensor); + TF_LITE_ENSURE(context, activation_state != nullptr); + + // Define input constants based on input tensor definition above: + const int rank = params->rank; + const int input_size = input->dims->data[1]; + const int batch_size = input->dims->data[0]; + const int num_filters = weights_feature->dims->data[0]; + TF_LITE_ENSURE_EQ(context, num_filters % rank, 0); + const int num_units = num_filters / rank; + const int memory_size = weights_time->dims->data[1]; + + // Validate Input Tensor: + TF_LITE_ENSURE(context, + input->type == kTfLiteFloat32 || input->type == kTfLiteInt8); + TF_LITE_ENSURE_EQ(context, NumDimensions(input), 2); + + // Validate Tensor Output: + // [0] = float/int8_t, {2, batch_size, num_units} + TF_LITE_ENSURE_EQ(context, node->outputs->size, 1); + TfLiteTensor *output = GetOutput(context, node, kSvdfOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + TF_LITE_ENSURE_EQ(context, NumDimensions(output), 2); + TF_LITE_ENSURE_EQ(context, output->dims->data[0], batch_size); + TF_LITE_ENSURE_EQ(context, output->dims->data[1], num_units); + + // Validate Weights Feature Input Tensor: + TF_LITE_ENSURE_EQ(context, NumDimensions(weights_feature), 2); + TF_LITE_ENSURE_EQ(context, weights_feature->dims->data[1], input_size); + + // Validate Weights Time Input Tensor: + TF_LITE_ENSURE_EQ(context, NumDimensions(weights_time), 2); + TF_LITE_ENSURE_EQ(context, weights_time->dims->data[0], num_filters); + TF_LITE_ENSURE_EQ(context, weights_time->dims->data[1], memory_size); + + // Validate Optional Bias Input Tensor: + if (bias != nullptr) { + TF_LITE_ENSURE_EQ(context, bias->dims->data[0], num_units); + } + + // Validate Activation State Input Tensor: + TF_LITE_ENSURE_EQ(context, NumDimensions(activation_state), 2); + TF_LITE_ENSURE_EQ(context, activation_state->dims->data[0], batch_size); + TF_LITE_ENSURE_EQ(context, activation_state->dims->data[1], + memory_size * num_filters); + // Since is_variable is not part of TFLiteEvalTensor, check is_variable here. + TF_LITE_ENSURE_EQ(context, activation_state->is_variable, true); + + TF_LITE_ENSURE_EQ(context, node->inputs->size, 5); + + TFLITE_DCHECK(node->user_data != nullptr); + OpData *data = static_cast(node->user_data); + + if (input->type == kTfLiteInt8) { + TF_LITE_ENSURE_EQ(context, weights_feature->type, kTfLiteInt8); + TF_LITE_ENSURE_EQ(context, weights_time->type, kTfLiteInt16); + TF_LITE_ENSURE_EQ(context, activation_state->type, kTfLiteInt16); + if (bias != nullptr) { + TF_LITE_ENSURE_EQ(context, bias->type, kTfLiteInt32); + } + + TF_LITE_ENSURE_TYPES_EQ(context, output->type, kTfLiteInt8); + + const double effective_scale_1 = static_cast( + input->params.scale * weights_feature->params.scale / + activation_state->params.scale); + const double effective_scale_2 = + static_cast(activation_state->params.scale * + weights_time->params.scale / output->params.scale); + + // TODO(b/162018098): Use TF_LITE_ENSURE_NEAR when it is ready. + TF_LITE_ENSURE( + context, + std::abs(static_cast(bias->params.scale) - + static_cast(activation_state->params.scale * + weights_time->params.scale)) < 1e-5); + + QuantizeMultiplier(effective_scale_1, &(data->effective_scale_1_a), + &(data->effective_scale_1_b)); + QuantizeMultiplier(effective_scale_2, &(data->effective_scale_2_a), + &(data->effective_scale_2_b)); + + data->input_zero_point = input->params.zero_point; + data->output_zero_point = output->params.zero_point; + + TFLITE_DCHECK(context->RequestScratchBufferInArena != nullptr); + + const TfLiteStatus scratch_status = context->RequestScratchBufferInArena( + context, batch_size * num_filters * sizeof(int32_t), + &(data->scratch_tensor_index)); + TF_LITE_ENSURE_OK(context, scratch_status); + + const TfLiteStatus scratch_output_status = + context->RequestScratchBufferInArena( + context, batch_size * num_units * sizeof(int32_t), + &(data->scratch_output_tensor_index)); + TF_LITE_ENSURE_OK(context, scratch_output_status); + } else { + TF_LITE_ENSURE_EQ(context, weights_feature->type, kTfLiteFloat32); + TF_LITE_ENSURE_EQ(context, weights_time->type, kTfLiteFloat32); + TF_LITE_ENSURE_EQ(context, activation_state->type, kTfLiteFloat32); + if (bias != nullptr) { + TF_LITE_ENSURE_EQ(context, bias->type, kTfLiteFloat32); + } + TF_LITE_ENSURE_TYPES_EQ(context, output->type, kTfLiteFloat32); + + TFLITE_DCHECK(context->RequestScratchBufferInArena != nullptr); + const TfLiteStatus scratch_status = context->RequestScratchBufferInArena( + context, batch_size * num_filters * sizeof(float), + &(data->scratch_tensor_index)); + TF_LITE_ENSURE_OK(context, scratch_status); + } + + return kTfLiteOk; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/svdf_test.cc b/components/tflite/tensorflow/lite/micro/kernels/svdf_test.cc new file mode 100644 index 00000000..e8adeb31 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/svdf_test.cc @@ -0,0 +1,989 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" +namespace tflite { +namespace testing { +namespace { + +// naming as follows: _xx + +// 10 inputs each with shape {2, 2}. +const float input_data_2x2x10[] = { + 0.12609188, + -0.46347019, + 0.35867718, + 0.36897406, + + 0.14278367, + -1.64410412, + -0.57290924, + 0.12729003, + + 0.49837467, + 0.19278903, + 0.17660543, + 0.52949083, + + -0.11186574, + 0.13164264, + -0.72674477, + -0.5683046, + + -0.68892461, + 0.37783599, + -0.63690937, + 0.44483393, + + -0.81299269, + -0.86831826, + -0.95760226, + 1.82078898, + + -1.45006323, + -0.82251364, + -1.65087092, + -1.89238167, + + 0.03966608, + -0.24936394, + 2.06740379, + -1.51439476, + + 0.11771342, + -0.23761693, + 0.31088525, + -1.55601168, + + -0.89477462, + 1.67204106, + -0.6230064, + 0.29819036, +}; + +// Feature filter of shape {8, 2}. +const float feature_weights_data_2x2x10[] = { + -0.31930989, 0.0079667, 0.39296314, 0.37613347, 0.12416199, 0.15785322, + 0.27901134, 0.3905206, 0.21931258, -0.36137494, -0.10640851, 0.31053296, + -0.36118156, -0.0976817, -0.36916667, 0.22197971 +}; + +// Time filter of shape {8, 10}. +const float time_weights_data_2x2x10[] = { + -0.31930989, 0.37613347, 0.27901134, -0.36137494, -0.36118156, + 0.22197971, 0.27557442, -0.06634006, 0.0079667, 0.12416199, + + 0.3905206, -0.10640851, -0.0976817, 0.15294972, 0.39635518, + -0.02702999, 0.39296314, 0.15785322, 0.21931258, 0.31053296, + + -0.36916667, 0.38031587, -0.21580373, 0.27072677, 0.23622236, + 0.34936687, 0.18174365, 0.35907319, -0.17493086, 0.324846, + + -0.10781813, 0.27201805, 0.14324132, -0.23681851, -0.27115166, + -0.01580888, -0.14943552, 0.15465137, 0.09784451, -0.0337657, + + -0.14884081, 0.19931212, -0.36002168, 0.34663299, -0.11405486, + 0.12672701, 0.39463779, -0.07886535, -0.06384811, 0.08249187, + + -0.26816407, -0.19905911, 0.29211238, 0.31264046, -0.28664589, + 0.05698794, 0.11613581, 0.14078894, 0.02187902, -0.21781836, + + -0.15567942, 0.08693647, -0.38256618, 0.36580828, -0.22922277, + -0.0226903, 0.12878349, -0.28122205, -0.10850525, -0.11955214, + + 0.27179423, -0.04710215, 0.31069002, 0.22672787, 0.09580326, + 0.08682203, 0.1258215, 0.1851041, 0.29228821, 0.12366763 +}; + +// Activation state with shape {2, 80}. These initial values must be copied into +// a mutable activation state tensor. + +const float initial_activation_state_data_2x2x10[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +// Bias with shape {8} +const float bias_data_2x2x10[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; + +// 10 outputs each of shape {2, 4} +const float golden_output_2x2x10[] = { + -0.044205, -0.013757, 0.050369, -0.018447, + 0.073010, 0.025142, -0.021154, 0.013551, + + -0.209613, -0.062421, 0.150209, -0.108334, + 0.028256, -0.006950, -0.030885, 0.009603, + + -0.076800, -0.037075, -0.087198, -0.155183, + 0.091069, 0.098446, -0.016083, 0.106475, + + -0.082123, -0.162238, -0.084434, -0.141074, + -0.029340, -0.090685, 0.053302, -0.030604, + + -0.201440, 0.088424, 0.139877, 0.012416, + -0.113212, 0.103893, -0.100842, 0.122780, + + -0.166632, -0.116705, 0.175298, -0.047163, + 0.313077, -0.166485, -0.285860, 0.129069, + + -0.625911, 0.046134, 0.138081, -0.129581, + -0.521455, -0.061579, 0.230289, 0.114963, + + -0.216693, -0.161643, -0.179177, -0.052599, + -0.213239, 0.029502, 0.260858, 0.275045, + + -0.213689, -0.323608, -0.285635, -0.317687, + -0.324092, -0.317972, -0.208450, -0.462504, + + -0.255126, -0.218576, -0.041528, 0.179421, + -0.440583, 0.072127, -0.284136, 0.241570 +}; + +// Simulated real-world inputs, weights and expected outputs. + +// Input of shape {1x16} +const float input_data_16x1x1[] = { + -0.488494, + 2.023762, + -2.233117, + -0.488494, + 3.559030, + 9.490748, + -3.210106, + -1.953977, + -0.279140, + 0.907204, + 1.674838, + 0.000000, + -0.279140, + -0.628064, + -0.069785, + -0.628064, +}; + +// Feature filter of shape {64, 16}. +const float feature_weights_data_16x1x1[] = { + 0.173588, 0.173588, -0.024798, 0.193426, -0.099193, 0.044637, 0.183507, + 0.183507, 0.044637, 0.198386, -0.069435, 0.084314, 0.312458, 0.024798, + 0.173588, -0.049596, -0.352135, -0.550521, -0.009919, -0.099193, -0.074395, + -0.128951, 0.193426, 0.357095, -0.317418, -0.119032, -0.218225, -0.004960, + -0.386853, -0.133911, 0.252942, -0.019839, -0.024798, -0.054556, -0.069435, + -0.128951, 0.029758, -0.099193, -0.312458, -0.029758, 0.064475, 0.183507, + 0.114072, -0.178547, -0.247982, -0.119032, 0.243023, -0.119032, -0.034718, + -0.178547, 0.019839, 0.128951, -0.223184, -0.009919, -0.213265, 0.168628, + -0.143830, -0.322377, -0.218225, -0.193426, -0.252942, -0.049596, 0.064475, + -0.267821, -0.580279, -0.099193, 0.213265, 0.119032, -0.119032, -0.178547, + 0.610037, 0.109112, 0.049596, -0.014879, -0.049596, -0.193426, 0.039677, + -0.148789, -0.114072, -0.158709, -0.158709, 0.094233, 0.099193, -0.114072, + 0.104153, -0.123991, 0.198386, -0.173588, 0.089274, -0.247982, -0.054556, + 0.123991, 0.183507, 0.114072, 0.188467, 0.302539, 0.044637, 0.039677, + -0.099193, 0.168628, -0.024798, -0.054556, -0.109112, 0.014879, -0.009919, + 0.069435, -0.396772, -0.287660, -0.079354, -0.104153, 0.054556, 0.089274, + -0.099193, 0.114072, 0.034718, 0.119032, 0.282700, -0.119032, -0.505884, + -0.233104, -0.114072, -0.257902, -0.233104, -0.178547, 0.153749, 0.128951, + 0.143830, -0.188467, -0.183507, 0.104153, -0.024798, 0.193426, -0.287660, + 0.168628, -0.009919, 0.119032, -0.024798, -0.099193, -0.203346, 0.099193, + 0.084314, -0.168628, 0.123991, -0.148789, 0.114072, -0.029758, 0.228144, + -0.238063, 0.089274, -0.064475, 0.307498, -0.188467, -0.004960, -0.252942, + -0.173588, -0.158709, -0.044637, -0.009919, 0.312458, -0.262861, 0.059516, + 0.158709, 0.069435, -0.282700, 0.074395, -0.322377, -0.183507, -0.123991, + -0.233104, 0.009919, 0.252942, -0.243023, 0.555481, -0.099193, -0.119032, + -0.441409, 0.148789, 0.084314, -0.168628, -0.183507, 0.188467, 0.024798, + -0.302539, 0.223184, 0.143830, -0.193426, -0.054556, -0.218225, -0.297579, + 0.104153, 0.272781, -0.034718, 0.114072, -0.059516, 0.044637, 0.342216, + 0.421570, 0.138870, -0.024798, -0.039677, -0.163668, -0.034718, 0.396772, + -0.128951, -0.044637, -0.173588, 0.302539, 0.079354, 0.049596, 0.133911, + -0.029758, -0.312458, -0.029758, 0.079354, 0.128951, 0.252942, 0.213265, + 0.014879, 0.287660, 0.178547, 0.297579, 0.352135, 0.401732, 0.024798, + -0.277740, -0.411651, -0.069435, 0.342216, -0.158709, -0.104153, -0.009919, + 0.223184, 0.228144, -0.019839, 0.059516, -0.104153, -0.510844, 0.029758, + -0.406691, 0.089274, 0.421570, 0.163668, -0.143830, -0.019839, -0.039677, + 0.104153, -0.044637, -0.128951, 0.203346, 0.079354, -0.069435, 0.094233, + -0.138870, 0.466207, -0.163668, 0.049596, 0.029758, 0.267821, 0.029758, + -0.049596, 0.009919, 0.004960, -0.099193, 0.094233, -0.262861, 0.089274, + -0.302539, 0.332297, -0.307498, -0.014879, 0.168628, -0.094233, -0.272781, + 0.034718, -0.133911, -0.228144, 0.094233, 0.257902, -0.228144, 0.153749, + -0.054556, -0.252942, 0.054556, 0.218225, -0.054556, 0.302539, 0.282700, + 0.054556, -0.044637, -0.133911, 0.233104, -0.049596, 0.411651, 0.044637, + -0.297579, -0.029758, -0.114072, 0.114072, -0.580279, 0.079354, -0.024798, + -0.347175, -0.128951, -0.099193, 0.238063, -0.104153, -0.009919, 0.158709, + -0.034718, 0.123991, -0.163668, 0.059516, 0.342216, 0.009919, 0.064475, + -0.307498, -0.520763, -0.238063, 0.163668, 0.362054, 0.034718, -0.178547, + -0.104153, -0.257902, 0.322377, 0.054556, 0.148789, -0.178547, 0.084314, + 0.004960, 0.257902, 0.029758, 0.079354, -0.223184, -0.193426, 0.282700, + 0.000000, -0.019839, -0.114072, 0.491005, -0.193426, -0.029758, -0.243023, + 0.009919, 0.089274, -0.277740, -0.089274, 0.104153, 0.337256, 0.138870, + -0.307498, -0.054556, 0.352135, 0.133911, -0.044637, 0.133911, -0.089274, + -0.357095, -0.272781, 0.069435, 0.059516, -0.109112, 0.148789, -0.044637, + -0.019839, -0.153749, 0.123991, -0.223184, 0.322377, 0.074395, -0.312458, + 0.024798, -0.223184, 0.109112, -0.138870, 0.218225, -0.074395, -0.406691, + 0.009919, -0.198386, -0.009919, 0.416611, 0.178547, 0.148789, 0.133911, + -0.004960, 0.069435, -0.054556, -0.044637, 0.297579, 0.059516, -0.456288, + -0.148789, -0.004960, 0.054556, 0.094233, -0.104153, 0.198386, -0.302539, + 0.133911, 0.411651, 0.054556, 0.525723, -0.089274, 0.079354, 0.238063, + 0.079354, -0.039677, 0.039677, 0.029758, 0.332297, -0.014879, -0.367014, + -0.143830, -0.123991, -0.064475, 0.014879, 0.173588, -0.168628, 0.386853, + 0.009919, 0.173588, 0.163668, 0.123991, 0.163668, 0.198386, 0.203346, + -0.401732, -0.009919, 0.272781, -0.173588, 0.044637, 0.238063, 0.133911, + 0.049596, 0.208305, -0.024798, 0.049596, -0.049596, 0.034718, -0.446368, + 0.466207, -0.089274, -0.099193, -0.128951, -0.228144, 0.014879, -0.252942, + 0.074395, -0.223184, -0.168628, -0.292619, 0.178547, 0.153749, -0.014879, + 0.054556, 0.000000, 0.193426, 0.158709, 0.178547, -0.327337, -0.138870, + -0.114072, 0.168628, 0.297579, -0.109112, -0.029758, -0.029758, -0.416611, + 0.059516, 0.000000, -0.168628, -0.322377, 0.238063, -0.128951, -0.029758, + 0.500925, 0.292619, 0.123991, -0.099193, 0.074395, 0.317418, -0.148789, + 0.064475, -0.104153, -0.044637, -0.094233, 0.188467, -0.044637, 0.213265, + -0.233104, -0.049596, 0.004960, -0.198386, 0.287660, -0.148789, -0.257902, + 0.004960, -0.218225, -0.044637, -0.386853, -0.243023, -0.163668, 0.094233, + 0.029758, -0.019839, -0.009919, -0.143830, -0.158709, 0.158709, -0.243023, + -0.039677, -0.297579, 0.069435, 0.049596, 0.302539, 0.059516, 0.074395, + -0.019839, 0.352135, -0.019839, -0.138870, -0.178547, -0.243023, 0.233104, + 0.252942, -0.228144, -0.049596, 0.173588, 0.173588, -0.074395, -0.034718, + -0.292619, 0.362054, 0.183507, 0.243023, -0.203346, -0.044637, 0.054556, + 0.059516, -0.158709, -0.158709, 0.000000, 0.327337, 0.119032, 0.034718, + -0.044637, -0.089274, 0.089274, -0.233104, 0.000000, -0.317418, 0.371974, + 0.213265, 0.307498, -0.178547, -0.367014, 0.039677, -0.059516, 0.168628, + -0.014879, 0.143830, 0.123991, -0.084314, -0.332297, -0.416611, 0.183507, + 0.109112, -0.039677, 0.014879, 0.292619, -0.213265, -0.054556, 0.004960, + 0.123991, 0.119032, 0.000000, -0.332297, -0.312458, -0.198386, -0.213265, + 0.119032, 0.322377, 0.168628, 0.104153, -0.262861, 0.327337, -0.049596, + -0.228144, -0.074395, 0.168628, 0.123991, 0.396772, 0.044637, 0.322377, + 0.193426, 0.267821, -0.178547, 0.297579, 0.148789, -0.218225, -0.138870, + 0.044637, 0.049596, 0.133911, 0.064475, 0.069435, 0.064475, -0.158709, + -0.044637, -0.173588, 0.267821, 0.327337, 0.079354, -0.228144, 0.029758, + 0.014879, 0.198386, -0.109112, -0.133911, 0.431490, 0.099193, 0.421570, + 0.233104, -0.054556, 0.054556, -0.317418, -0.133911, -0.123991, -0.287660, + 0.342216, -0.049596, -0.153749, 0.228144, -0.213265, 0.262861, 0.406691, + -0.084314, -0.004960, 0.193426, 0.188467, -0.099193, -0.223184, 0.163668, + -0.257902, -0.153749, 0.441409, 0.099193, 0.128951, -0.089274, -0.208305, + -0.009919, -0.004960, -0.109112, 0.024798, -0.119032, 0.019839, 0.391812, + -0.024798, 0.198386, 0.327337, -0.505884, -0.099193, 0.510844, -0.148789, + 0.094233, -0.153749, -0.039677, 0.352135, 0.272781, -0.228144, -0.287660, + -0.272781, 0.148789, 0.277740, 0.074395, 0.109112, -0.064475, 0.044637, + 0.074395, -0.292619, 0.153749, -0.064475, -0.114072, 0.198386, -0.039677, + -0.128951, -0.004960, 0.257902, -0.228144, -0.094233, 0.064475, 0.014879, + 0.188467, -0.416611, 0.099193, 0.362054, -0.208305, 0.198386, -0.079354, + 0.009919, 0.119032, 0.332297, 0.243023, -0.168628, 0.158709, 0.039677, + 0.143830, 0.277740, -0.168628, 0.009919, 0.099193, -0.004960, -0.257902, + -0.297579, 0.208305, -0.104153, 0.119032, 0.247982, 0.381893, -0.223184, + -0.367014, -0.327337, -0.168628, -0.094233, 0.208305, -0.019839, 0.183507, + 0.084314, 0.133911, 0.109112, -0.148789, -0.183507, -0.411651, -0.024798, + -0.114072, -0.029758, -0.009919, 0.173588, -0.059516, -0.049596, 0.039677, + 0.317418, 0.138870, -0.247982, -0.084314, 0.158709, 0.054556, -0.084314, + -0.049596, 0.074395, 0.019839, -0.282700, -0.119032, -0.262861, 0.163668, + -0.069435, -0.064475, -0.059516, 0.094233, 0.123991, -0.079354, -0.272781, + -0.267821, 0.233104, 0.114072, -0.218225, 0.540602, 0.089274, 0.262861, + 0.079354, 0.267821, -0.119032, -0.109112, -0.128951, 0.128951, -0.044637, + -0.272781, 0.277740, 0.297579, -0.054556, -0.084314, -0.049596, 0.123991, + 0.059516, 0.238063, -0.168628, -0.009919, 0.163668, -0.307498, 0.109112, + -0.064475, 0.218225, -0.168628, -0.004960, -0.168628, 0.119032, 0.094233, + -0.183507, -0.089274, -0.292619, -0.094233, 0.064475, -0.183507, -0.168628, + 0.089274, 0.074395, -0.367014, -0.024798, -0.069435, 0.119032, -0.302539, + -0.376933, -0.123991, -0.009919, -0.069435, -0.208305, -0.119032, 0.014879, + -0.183507, -0.238063, 0.163668, -0.332297, -0.148789, -0.391812, -0.024798, + -0.133911, -0.059516, -0.123991, 0.123991, -0.292619, -0.044637, 0.059516, + -0.069435, 0.049596, -0.069435, 0.034718, 0.158709, -0.347175, -0.044637, + 0.352135, -0.347175, -0.282700, -0.054556, 0.307498, 0.029758, 0.357095, + -0.148789, 0.208305, -0.317418, 0.009919, 0.004960, -0.243023, 0.049596, + -0.099193, 0.213265, -0.342216, 0.158709, 0.123991, -0.332297, 0.386853, + -0.262861, -0.208305, 0.123991, -0.044637, 0.148789, 0.084314, -0.297579, + -0.307498, -0.163668, 0.337256, -0.014879, 0.074395, 0.178547, -0.004960, + -0.257902, -0.019839, -0.228144, -0.034718, -0.277740, -0.158709, -0.119032, + -0.153749, 0.629876, 0.277740, 0.178547, -0.267821, -0.004960, 0.247982, + 0.084314, -0.094233, 0.000000, -0.039677, 0.332297, 0.178547, 0.009919, + -0.213265, -0.208305, -0.044637, 0.019839, 0.218225, -0.297579, 0.014879, + -0.247982, -0.004960, -0.128951, 0.421570, -0.059516, 0.362054, -0.203346, + -0.143830, -0.099193, -0.024798, 0.094233, -0.123991, 0.163668, 0.109112, + -0.104153, -0.233104, 0.009919, -0.218225, 0.376933, 0.104153, -0.059516, + 0.049596, -0.054556, 0.019839, -0.044637, -0.019839, 0.371974, -0.019839, + 0.104153, 0.168628, -0.024798, -0.272781, -0.158709, 0.223184, 0.044637, + 0.039677, -0.168628, -0.287660, -0.109112, 0.094233, -0.089274, -0.148789, + 0.178547, -0.039677, -0.089274, -0.049596, -0.024798, 0.064475, -0.158709, + 0.089274, 0.029758, -0.247982, 0.362054, 0.024798, -0.004960, -0.099193, + 0.173588, -0.059516, 0.188467, -0.629876, 0.094233, 0.371974, 0.069435, + 0.252942, -0.357095, -0.272781, -0.367014, 0.014879, -0.049596, -0.262861, + 0.009919, -0.094233, -0.094233, 0.059516, 0.223184, 0.133911, 0.411651, + -0.044637, -0.044637, 0.109112, 0.228144, 0.386853, -0.233104, 0.069435, + 0.228144, -0.302539, 0.029758, 0.089274, 0.044637, -0.238063, -0.138870, + -0.158709, -0.019839, 0.049596, 0.039677, 0.000000, -0.069435, 0.109112, + -0.213265, -0.188467, -0.262861, -0.267821, -0.094233, 0.133911, 0.391812, + 0.123991, -0.317418, 0.233104, -0.029758, -0.099193, -0.193426, 0.074395, + -0.009919, 0.252942, 0.322377, -0.530683, 0.208305, 0.252942, 0.203346, + -0.069435, -0.262861 +}; + +// Time filter of shape {64, 8}. +const float time_weights_data_16x1x1[] = { + -0.052026, 0.043107, 0.053512, 0.013378, 0.011892, -0.182834, -0.108511, + 0.153105, 0.050539, -0.173915, 0.145672, 0.208103, -0.221481, 0.108511, + -0.496475, 0.181347, -0.016351, -0.132294, -0.234859, -0.243778, 0.028243, + -0.228914, -0.130808, -0.167969, -0.041621, -0.306209, -0.193239, -0.028243, + -0.057972, -0.057972, -0.497962, 0.054999, 0.181347, 0.047566, -0.099592, + -0.111484, -0.130808, -0.071350, 0.380532, 0.010405, 0.041621, 0.052026, + 0.022297, 0.081755, 0.098106, 0.099592, -0.584176, -0.023783, 0.062431, + -0.090674, -0.279453, -0.486070, -0.273507, 0.004459, -0.062431, 0.095133, + 0.056485, 0.022297, -0.105538, -0.184320, 0.358235, 0.254183, 0.049053, + 0.084728, 0.218508, 0.078782, -0.136754, -0.017837, -0.124862, -0.118916, + -0.001486, 0.043107, 0.254183, 0.087701, 0.261616, 0.309182, -0.404315, + -0.040134, -0.046080, -0.052026, -0.034188, -0.475665, -0.025270, -0.049053, + -0.046080, -0.062431, 0.020810, 0.040134, -0.135267, -0.169456, -0.050539, + -0.576743, 0.034188, 0.075809, 0.101079, 0.136754, 0.083241, 0.077296, + -0.050539, 0.761064, -0.335938, -0.080268, 0.025270, 0.257156, 0.227427, + 0.252697, 0.065404, 0.115943, 0.222968, -0.026756, -0.054999, 0.107025, + -0.093646, 0.041621, -0.092160, -0.474178, -0.016351, 0.004459, 0.049053, + 0.019324, 0.019324, 0.074323, 0.038648, -0.613905, 0.182834, 0.075809, + 0.028243, 0.019324, 0.010405, -0.011892, 0.001486, -0.492016, -0.224454, + -0.474178, -0.147159, 0.002973, 0.102565, 0.136754, -0.267561, -0.001486, + -0.095133, -0.040134, 0.066890, 0.074323, 0.104052, 0.532150, 0.090674, + 0.072836, -0.053512, -0.004459, 0.020810, 0.046080, 0.062431, 0.477151, + 0.133781, -0.029729, -0.026756, 0.031215, 0.156077, 0.096619, 0.251210, + 0.352289, 0.657012, 0.047566, -0.014865, -0.072836, -0.016351, 0.008919, + -0.053512, 0.016351, 0.300263, 0.047566, 0.020810, 0.169456, 0.001486, + 0.007432, 0.111484, 0.044594, -0.188779, -0.096619, 0.074323, -0.040134, + 0.160537, 0.138240, 0.184320, 0.377559, -0.092160, -0.049053, 0.056485, + -0.032702, 0.001486, -0.083241, -0.472692, -0.114457, -0.117430, -0.075809, + 0.026756, 0.163510, 0.172428, 0.127835, -0.199185, -0.218508, -0.057972, + -0.132294, -0.162023, -0.019324, -0.245265, -0.395396, -0.254183, 0.084728, + 0.248238, 0.191752, 0.221481, 0.173915, 0.173915, -0.208103, -0.077296, + 0.384991, -0.313641, -0.313641, -0.147159, -0.090674, 0.035675, 0.059458, + -0.010405, 0.019324, 0.087701, 0.016351, 0.037161, 0.469719, -0.074323, + 0.092160, 0.026756, 0.090674, 0.098106, 0.004459, -0.034188, 0.492016, + -0.367154, -0.093646, -0.063917, 0.041621, 0.017837, 0.026756, -0.062431, + -0.350803, 0.425125, 0.002973, 0.083241, 0.075809, 0.016351, 0.047566, + -0.185807, -0.107025, -0.098106, -0.144186, 0.255670, 0.020810, 0.105538, + 0.029729, 0.129321, 0.156077, 0.141213, 0.334452, 0.147159, -0.066890, + 0.035675, 0.115943, 0.240805, 0.328506, 0.162023, -0.237832, 0.218508, + 0.233373, 0.214049, 0.099592, 0.026756, -0.322560, -0.236346, -0.166483, + 0.225941, 0.109997, -0.147159, 0.147159, -0.266075, 0.111484, 0.078782, + -0.120403, 0.022297, -0.075809, -0.148645, -0.251210, -0.176888, -0.044594, + -0.023783, 0.016351, 0.026756, -0.013378, -0.069863, -0.112970, 0.013378, + 0.086214, 0.014865, 0.352289, -0.240805, -0.135267, -0.114457, -0.472692, + 0.334452, 0.095133, 0.047566, 0.130808, -0.068377, -0.007432, -0.130808, + -0.121889, -0.053512, -0.245265, -0.371613, -0.083241, 0.000000, -0.028243, + 0.029729, -0.093646, -0.004459, -0.038648, -0.108511, -0.475665, -0.169456, + -0.047566, -0.010405, -0.114457, -0.353776, -0.034188, -0.044594, 0.041621, + -0.047566, -0.107025, 0.004459, 0.053512, 0.047566, -0.358235, -0.193239, + 0.040134, -0.096619, -0.054999, 0.099592, 0.032702, 0.205130, -0.170942, + -0.237832, -0.405801, -0.126348, -0.072836, -0.203644, -0.169456, -0.093646, + -0.074323, 0.078782, 0.607959, -0.437017, -0.164996, -0.166483, 0.043107, + -0.016351, 0.258643, 0.065404, -0.057972, 0.017837, 0.080268, 0.050539, + -0.013378, -0.215536, -0.524718, 0.260129, 0.040134, -0.002973, -0.046080, + 0.020810, 0.025270, 0.145672, 0.515799, 0.233373, 0.011892, 0.139727, + 0.126348, 0.065404, -0.007432, -0.008919, 0.035675, 0.083241, 0.040134, + -0.005946, 0.503907, -0.490529, -0.181347, -0.092160, -0.038648, 0.019324, + 0.133781, -0.011892, 0.041621, 0.062431, -0.062431, -0.040134, -0.092160, + -0.111484, -0.133781, -0.130808, -0.484583, -0.248238, 0.037161, -0.092160, + -0.056485, -0.041621, 0.112970, 0.248238, 0.438503, 0.258643, -0.013378, + 0.004459, 0.043107, 0.040134, 0.017837, 0.101079, 0.264589, 0.212563, + 0.014865, 0.285399, 0.153105, 0.170942, 0.358235, 0.334452, 0.086214, + 0.132294, 0.098106, -0.001486, 0.107025, 0.200671, -0.026756, 0.344857, + 0.227427, -0.041621, 0.098106, 0.063917, -0.093646, 0.130808, 0.285399, + -0.319587, 0.035675, -0.017837, -0.319587, 0.016351, -0.098106, -0.017837, + 0.083241, 0.074323, -0.054999, 0.276480, 0.316614, -0.099592, -0.059458, + 0.156077, -0.043107, 0.035675, 0.056485, -0.022297, 0.017837, -0.001486, + 0.340398, 0.492016, 0.004459, 0.057972, -0.150132, -0.206617, -0.257156, + -0.248238, -0.080268, -0.164996, 0.352289, -0.054999, -0.056485, 0.010405, + -0.049053, -0.041621, -0.099592, 0.013378, -0.089187, 0.057972, -0.413234, + 0.217022, 0.013378, -0.080268, -0.035675, 0.035675, 0.007432, 0.002973, + -0.469719, 0.141213, 0.136754, 0.153105, 0.130808, -0.104052, -0.508367, + -0.291345, -0.072836, -0.019324, -0.252697, -0.214049, -0.214049, 0.130808, + 0.484583 +}; + +// Bias of shape {64} +const float bias_data_16x1x1[] = { + -0.245395, -0.083545, -0.262522, -0.407912, -0.560898, -0.364789, -0.037964, + -0.378594, 0.178152, 0.400380, -0.301349, -0.240913, -0.159454, -0.158757, + -0.073665, 0.455906, -0.061232, 0.318907, -0.226993, -0.344644, 0.140316, + 0.559608, 0.109774, 0.437391, 0.113849, -0.162068, 0.039572, 0.569472, + 0.460205, 0.113459, 0.370469, 0.176811, 0.203063, -0.296975, -0.271655, + 0.059862, -0.159912, -0.077310, -0.338314, -0.195477, -0.256762, 0.233834, + 0.083172, 0.029040, -0.236288, -0.267054, -0.166627, 0.188319, -0.271391, + -0.222920, 0.106463, 0.263614, 0.384986, -0.125957, -0.095890, 0.363686, + -0.036990, -0.358884, -0.178254, 0.305596, 0.390088, -0.189437, 0.613409, + 0.399639 +}; + +// Activation state with shape {64, 8}. These initial values must be copied into +// a mutable activation state tensor. +const float initial_activation_state_data_16x1x1[] = { + -0.582275, -0.586623, -1.262373, -1.277279, -1.542175, -1.271999, -1.429757, + -1.184425, -0.462094, -1.443421, 0.230736, -0.494701, -0.354955, -2.534061, + -4.277471, -4.218467, 0.403711, -0.248748, -0.330111, -0.467683, 0.549047, + 0.733511, -0.230115, 0.793136, -1.126353, -0.984123, -0.081984, -0.222351, + 0.692830, 0.517060, 1.367958, 2.118860, -0.116766, -0.826365, -2.402700, + -2.313884, -2.898954, -2.076005, -2.405185, -2.755481, 0.329490, 0.085400, + -1.485966, -2.034702, -2.161405, -1.269515, -1.151818, -1.823841, 0.561469, + 1.109273, 1.693411, -0.082605, -0.069252, -1.225107, -1.330693, -1.411435, + 0.253406, -0.357439, -1.593415, -0.879779, -1.111136, 1.821357, 2.471952, + 1.236908, -4.014127, -2.810448, -2.944604, -1.930980, -1.566398, -0.838166, + -0.319242, 0.749349, 1.156476, 0.658670, 1.997437, 2.080663, 2.912618, + 2.677224, 2.642442, 2.796163, -0.272349, -0.473273, 3.120063, 2.747097, + 3.595510, 1.874150, 2.049919, 2.093396, -1.049959, 0.277939, -1.255541, + -1.052443, -1.810177, -0.883505, -0.538178, 0.524203, -1.017662, -0.269244, + 0.039129, -0.227941, -0.114592, -2.018243, -2.548968, -0.706804, 0.890959, + 0.102480, 0.349986, 0.405885, 1.287216, 0.756181, 0.319242, -0.641590, + -3.841774, -2.716042, -4.342065, -3.826557, -2.924729, -1.643724, -1.237839, + -0.597492, -1.954892, -1.215169, -1.528201, -1.018904, -0.863941, -0.293467, + 0.039439, 0.672023, 1.408019, 1.362679, 1.467644, 1.006171, 0.310236, + -0.249990, -1.048406, -0.752144, -1.831605, -1.058033, -1.096541, -0.293467, + 0.051551, 0.232600, 0.088816, 2.570395, 0.704009, 2.465120, 3.010751, + 2.139357, 0.630410, 1.006171, 1.545281, 1.486898, -1.162998, -2.344317, + -4.593918, -3.522842, -2.872247, -1.416714, -0.642521, -0.230115, 0.315205, + -0.368930, -0.162726, 0.396879, 0.505570, 0.534451, 0.554947, 1.270447, + 0.388805, 0.531967, -1.243119, -0.671713, -1.214859, -0.238189, 0.016459, + -1.164550, 0.609603, 3.293348, 2.600208, 1.454290, -1.034121, -1.760179, + -1.192500, -0.613951, 3.449553, 2.912618, 1.917937, 1.435968, 0.879158, + 1.118279, 0.102791, -0.502465, -0.239121, -0.092853, 1.786265, 1.943091, + 2.547104, 2.630641, 2.585302, 2.965411, -0.945615, -2.538720, -2.474126, + -1.088156, 0.056209, 0.864873, 0.170490, 0.457435, 0.545941, 0.752765, + 1.569503, 1.129459, 0.662086, -0.527929, -0.810838, -1.662978, 1.285042, + 1.653040, 4.130893, 2.961995, 4.147041, 3.256393, 3.881524, 2.522571, + -0.875431, -1.112378, 2.105817, 2.180970, 3.121926, 1.577577, 1.639376, + 2.906407, -0.142230, 0.421101, 2.212335, 2.311399, 3.993321, 3.651719, + 4.206666, 4.678387, -1.304917, -1.130701, -2.543067, -2.500212, -2.197118, + -1.197158, -0.949652, -0.282908, 0.320795, -1.543728, 1.290322, 1.788128, + 3.957297, 3.205774, 2.892432, 2.297114, 0.138814, -0.139435, 0.936920, + 0.344707, 0.723263, -1.772290, -3.138385, -2.287177, -2.405806, -1.859864, + -4.572801, -3.410424, -3.855748, -2.239663, -2.269786, -1.582857, 4.238342, + 3.858543, 2.499901, 1.087535, 0.290051, -0.026086, -0.880400, -2.602692, + -1.404292, 0.253096, -0.665502, -1.443421, -0.925119, -0.096580, 1.115484, + 1.846200, -1.604284, -1.244671, -0.464888, 0.326385, 0.168006, -0.262723, + -0.744691, 0.953379, -0.407127, -0.349986, -1.154302, 0.831023, 1.590931, + 2.538720, 2.063583, 3.697680, -0.752455, -1.293117, -1.330693, -1.869802, + -0.592523, 0.631652, 1.198089, -0.481347, 3.738983, 4.153252, 2.782499, + 2.244321, 0.709289, 1.650245, 1.700865, 0.385078, 2.192460, 2.610456, + 4.009780, 3.492719, 2.574743, 2.116687, 1.856138, 1.205853, 2.722563, + 4.075305, 5.415935, 3.009198, 2.715421, 1.571056, 0.897170, -2.430339, + 0.749970, 0.425760, -0.302783, 0.817359, 1.031636, 1.913589, 2.686229, + 1.631923, -1.459259, -1.793097, -1.187531, -1.553355, -0.844998, -1.296843, + -1.805519, -0.486627, 0.909591, 2.082837, -1.473855, -2.456735, -3.851401, + -2.760139, -3.060438, -2.605487, -2.138735, -2.441519, -1.333177, -1.353984, + -0.245642, -0.588486, 0.033850, 2.084700, 0.076084, 0.690035, 0.747797, + 0.594697, -1.016109, -1.348083, -1.201195, -1.088466, 2.045571, 2.460772, + 0.717984, 0.041613, -0.721711, 1.134738, 2.322269, 1.112378, -0.307441, + -0.581033, -0.868599, -0.018633, 0.856488, 0.919839, 0.303094, -0.433213, + 0.811148, -0.508986, -1.060828, -1.227591, -1.566087, -1.117968, -1.385038, + -2.011101, -0.490353, -1.849616, -0.594697, -1.055859, 1.110205, 0.622646, + 0.145957, 0.359303, 1.012072, 0.774814, -0.400295, -1.484103, -2.007374, + -1.441247, -0.997787, -0.581033, -0.545941, -0.306510, 0.693451, 0.087264, + -0.227320, -1.211753, -1.532859, -1.688753, 0.065215, 0.134777, 0.608051, + -0.393152, -0.214588, -0.635689, -1.499320, 0.069562, -1.555839, -2.633126, + -2.966032, -1.550870, -0.101549, 0.874189, 0.436318, 0.299367, 2.289972, + 2.339659, 2.602071, 1.564535, 0.019254, -0.583207, -1.295912, -2.424749, + -1.221070, -1.175109, -0.577306, -0.102791, 1.877876, 2.568222, 2.173827, + 3.131243, 2.637784, 2.088737, 3.679047, 3.218506, 2.483442, 1.650556, + 1.363611, -0.027328, 1.486898, -0.721711, -3.684327, -3.006093, -3.777491, + -2.327548, -2.737470, -4.549510, -0.060867, 0.127635, 0.680408, 0.581344, + 0.320174, -0.403090, -0.838166, 0.293777, -0.995613, -0.165521, -0.419859, + 1.110515, 1.203679, 1.749931, 2.467294, 4.276539, 0.031055, -0.967664, + 1.167035, 1.865144, 3.221923, 3.248630, 4.121266, 4.187723, 0.749039, + -1.571056, 0.785994, 1.568572, 3.759479, 3.588678, 4.116608, 3.864444, + -0.290051, -0.271107, 0.375140, 0.537556, 0.536314, 0.095959, 0.054656, + 0.088816 +}; + +// One output with shape {1, 64} +const float golden_output_16x1x1[] = { + -0.087914, 1.145864, -0.418088, -1.556392, -0.925298, 0.205252, 0.289119, + 1.331180, -0.218010, 0.963057, -2.225886, 1.248478, 1.448983, 0.355467, + 1.682174, 0.803739, 0.449738, 0.543566, 1.916269, -2.975136, 0.222774, + 0.241589, -0.104216, 1.561748, 0.936818, -0.089907, -0.520117, -0.870353, + 1.606074, 0.895770, 0.521297, -0.369994, -0.889351, -2.809309, 2.404628, + 1.069754, -0.195456, -1.105652, 1.272715, -1.233177, 1.271416, -1.691805, + -1.058125, -0.716227, 0.052540, 1.262483, 0.540555, 1.735760, -0.539197, + -0.014367, -0.243002, 1.072254, 0.528985, -0.731151, -1.262649, 2.338702, + -0.603093, 0.970736, -3.567897, 0.035085, -0.201711, -0.550400, 1.545573, + -1.805005 +}; + +// One output with shape {1, 64} +const float golden_output_relu_16x1x1[] = { + 0.000000, 1.145864, 0.000000, 0.000000, 0.000000, 0.205252, 0.289119, + 1.331180, 0.000000, 0.963057, 0.000000, 1.248478, 1.448983, 0.355467, + 1.682174, 0.803739, 0.449738, 0.543566, 1.916269, 0.000000, 0.222774, + 0.241589, 0.000000, 1.561748, 0.936818, 0.000000, 0.000000, 0.000000, + 1.606074, 0.895770, 0.521297, 0.000000, 0.000000, 0.000000, 2.404628, + 1.069754, 0.000000, 0.000000, 1.272715, 0.000000, 1.271416, 0.000000, + 0.000000, 0.000000, 0.052540, 1.262483, 0.540555, 1.735760, 0.000000, + 0.000000, 0.000000, 1.072254, 0.528985, 0.000000, 0.000000, 2.338702, + 0.000000, 0.970736, 0.000000, 0.035085, 0.000000, 0.000000, 1.545573, + 0.000000 +}; + +template +void ValidateSVDFGoldens(const int batch_size, const int num_units, + const int input_size, const int rank, + TfLiteTensor *tensors, const int tensor_count, + TfLiteFusedActivation activaiton, + const T *input_sequences_data, + const int input_sequences_len, T *output_data, + const T *expected_output, float tolerance = 1e-5f) +{ + TfLiteSVDFParams params; + params.rank = rank; + params.activation = activaiton; + + int inputs_array_data[] = { 5, 0, 1, 2, 3, 4 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + + int outputs_array_data[] = { 1, 5 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = Register_SVDF(); + micro::KernelRunner runner(registration, tensors, tensor_count, inputs_array, + outputs_array, ¶ms); + + TfLiteStatus init_and_prepare_status = runner.InitAndPrepare(); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, init_and_prepare_status); + + // Abort early to make it clear init and prepare failed. + if (init_and_prepare_status != kTfLiteOk) { + return; + } + + int num_inputs = input_sequences_len / (input_size * batch_size); + + for (int i = 0; i < num_inputs; ++i) { + const T *input_batch_start = + input_sequences_data + i * input_size * batch_size; + + memcpy(tensors[0].data.raw, input_batch_start, tensors[0].bytes); + TfLiteStatus status = runner.Invoke(); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, status); + + // Only validate outputs when invoke has succeeded. + if (status == kTfLiteOk) { + int output_idx = 0; + int golden_idx = i * batch_size * num_units; + for (int j = golden_idx; j < golden_idx + batch_size * num_units; ++j) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output[j], output_data[output_idx], + tolerance); + output_idx++; + } + } + } +} + +#if !defined(XTENSA) // Needed to avoid build errors from unused functions. +void TestSVDF(const int batch_size, const int num_units, const int input_size, + const int memory_size, const int rank, + TfLiteFusedActivation activation, float *input_data, + const float *feature_weights_data, const float *time_weights_data, + float *activation_state_data, const float *bias_data, + float *scratch_data, float *output_data, + const float *input_sequences_data, int input_sequences_len, + const float *expected_output, float tolerance = 1e-5f) +{ + const int num_filters = num_units * rank; + + int input_dims_arg[] = { 2, batch_size, input_size }; + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_arg); + + int feature_weights_dims_args[] = { 2, num_filters, input_size }; + TfLiteIntArray *feature_weights_dims = + IntArrayFromInts(feature_weights_dims_args); + + int time_weights_dims_args[] = { 2, num_filters, memory_size }; + TfLiteIntArray *time_weights_dims = IntArrayFromInts(time_weights_dims_args); + + int activation_state_dims_args[] = { 2, batch_size, memory_size * num_filters }; + TfLiteIntArray *activation_state_dims = + IntArrayFromInts(activation_state_dims_args); + + int bias_dims_args[] = { 1, num_units }; + TfLiteIntArray *bias_dims = IntArrayFromInts(bias_dims_args); + + int output_dims_args[] = { 2, batch_size, num_units }; + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_args); + + const int tensor_count = 6; // 5 inputs, 1 output + TfLiteTensor tensors[] = { + CreateTensor(input_data, input_dims), + CreateTensor(feature_weights_data, feature_weights_dims), + CreateTensor(time_weights_data, time_weights_dims), + CreateTensor(bias_data, bias_dims), + CreateTensor(activation_state_data, activation_state_dims, + /*is_variable=*/true), + CreateTensor(output_data, output_dims), + }; + + ValidateSVDFGoldens(batch_size, num_units, input_size, rank, tensors, + tensor_count, activation, input_sequences_data, + input_sequences_len, output_data, expected_output, + tolerance); +} +#endif + +// The pattern to this method's arguemnts is: +// +// for each tensor in +// {input, feature weights, time weights, bias, activation state, output}: +// +inline void TestIntegerSVDF( + const int batch_size, const int num_units, const int input_size, + const int memory_size, const int rank, TfLiteFusedActivation activation, + int8_t *input_quantized, float input_scale, int input_zero_point, + const float *feature_weights_data, int8_t *feature_weights_quantized, + const float feature_weights_scale, const float *time_weights_data, + int16_t *time_weights_quantized, float time_weights_scale, + const float *bias_data, int32_t *bias_quantized, + const float *initial_activation_state_data, + int16_t *activation_state_quantized, float activation_state_scale, + int8_t *output_data, float output_scale, int output_zero_point, + const float *input_sequences_data, int8_t *input_sequences_quantized, + const int input_sequences_len, const float *golden_output, + int8_t *golden_output_quantized, int golden_output_len) +{ + const int num_filters = num_units * rank; + + int input_dims_arg[] = { 2, batch_size, input_size }; + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_arg); + + int feature_weights_dims_args[] = { 2, num_filters, input_size }; + TfLiteIntArray *feature_weights_dims = + IntArrayFromInts(feature_weights_dims_args); + + int time_weights_dims_args[] = { 2, num_filters, memory_size }; + TfLiteIntArray *time_weights_dims = IntArrayFromInts(time_weights_dims_args); + + int bias_dims_data[] = { 1, num_units }; + TfLiteIntArray *bias_dims = IntArrayFromInts(bias_dims_data); + + int activation_state_dims_args[] = { 2, batch_size, memory_size * num_filters }; + TfLiteIntArray *activation_state_dims = + IntArrayFromInts(activation_state_dims_args); + + int output_dims_args[] = { 2, batch_size, num_units }; + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_args); + + const int tensor_count = 6; // 5 inputs, 1 output + + TfLiteTensor tensors[] = { + CreateQuantizedTensor(input_quantized, input_dims, input_scale, + input_zero_point), + CreateQuantizedTensor(feature_weights_data, feature_weights_quantized, + feature_weights_dims, feature_weights_scale, 0), + CreateQuantizedTensor(time_weights_data, time_weights_quantized, + time_weights_dims, time_weights_scale, 0), + CreateQuantizedBiasTensor(bias_data, bias_quantized, bias_dims, + time_weights_scale, activation_state_scale), + CreateQuantizedTensor(initial_activation_state_data, + activation_state_quantized, activation_state_dims, + activation_state_scale, 0, + /*is_variable=*/true), + CreateQuantizedTensor(output_data, output_dims, output_scale, + output_zero_point) + }; + + tflite::Quantize(golden_output, golden_output_quantized, golden_output_len, + output_scale, output_zero_point); + tflite::Quantize(input_sequences_data, input_sequences_quantized, + input_sequences_len, input_scale, input_zero_point); + + ValidateSVDFGoldens(batch_size, num_units, input_size, rank, tensors, + tensor_count, activation, input_sequences_quantized, + input_sequences_len, output_data, golden_output_quantized, + /*tolerance*/ 1); +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +#if !defined(XTENSA) // TODO(b/170332589): xtensa kernels are less general than \ + // reference kernels and we ifdef out test cases that are \ + // currently known to fail. +TF_LITE_MICRO_TEST(SvdfFloat2x2Input2x4OutputShouldMatchGolden) +{ + constexpr int batch_size = 2; + constexpr int num_units = 4; + constexpr int input_size = 2; + constexpr int memory_size = 10; + constexpr int rank = 2; + constexpr int num_filters = num_units * rank; + + const int input_size_dims_count = batch_size * input_size; + float input_data[input_size_dims_count]; + + const int activation_state_dims_count = + batch_size * memory_size * num_filters; + float activation_state_data[activation_state_dims_count]; + + memcpy(activation_state_data, + tflite::testing::initial_activation_state_data_2x2x10, + sizeof(tflite::testing::initial_activation_state_data_2x2x10)); + + const int scratch_dims_count = batch_size * num_filters; + float scratch_data[scratch_dims_count]; + + const int output_dims_count = batch_size * num_units; + float output_data[output_dims_count]; + + tflite::testing::TestSVDF( + batch_size, num_units, input_size, memory_size, rank, kTfLiteActNone, + input_data, tflite::testing::feature_weights_data_2x2x10, + tflite::testing::time_weights_data_2x2x10, activation_state_data, + tflite::testing::bias_data_2x2x10, scratch_data, output_data, + tflite::testing::input_data_2x2x10, + sizeof(tflite::testing::input_data_2x2x10) / sizeof(float), + tflite::testing::golden_output_2x2x10); +} +#endif + +TF_LITE_MICRO_TEST(SvdfQuantized2x2Input2x4OutputShouldMatchGolden) +{ + constexpr int batch_size = 2; + constexpr int num_units = 4; + constexpr int input_size = 2; + constexpr int memory_size = 10; + constexpr int rank = 2; + constexpr int num_filters = num_units * rank; + + const int input_size_dims_count = batch_size * input_size; + + const int activation_state_dims_count = + batch_size * memory_size * num_filters; + + const int output_dims_count = batch_size * num_units; + int8_t output_data[output_dims_count]; + + float input_scale = 2.5f / INT8_MAX; // Range is [-2.5, 2.5] + float feature_weights_scale = 1.f / INT8_MAX; // Range is [-1, 1] + float time_weights_scale = 1.f / INT16_MAX; // Range is [-1, 1] + float activation_state_scale = 16.f / INT16_MAX; // Range is [-16, 16] + float output_scale = 1.f / INT8_MAX; // Range is [-1, 1] + + int input_zero_point = 0; + int output_zero_point = 0; + + int8_t input_quantized[input_size_dims_count]; + int8_t input_sequences_quantized[sizeof(tflite::testing::input_data_2x2x10) / + sizeof(float)]; + int8_t feature_weights_quantized + [sizeof(tflite::testing::feature_weights_data_2x2x10) / sizeof(float)]; + int16_t + time_weights_quantized[sizeof(tflite::testing::time_weights_data_2x2x10) / + sizeof(float)]; + int16_t activation_state_quantized[activation_state_dims_count]; + int32_t + bias_quantized[sizeof(tflite::testing::bias_data_2x2x10) / sizeof(float)]; + int8_t golden_quantized[sizeof(tflite::testing::golden_output_2x2x10) / + sizeof(float)]; + + tflite::testing::TestIntegerSVDF( + batch_size, num_units, input_size, memory_size, rank, kTfLiteActRelu, + input_quantized, input_scale, input_zero_point, + tflite::testing::feature_weights_data_2x2x10, feature_weights_quantized, + feature_weights_scale, tflite::testing::time_weights_data_2x2x10, + time_weights_quantized, time_weights_scale, + tflite::testing::bias_data_2x2x10, bias_quantized, + tflite::testing::initial_activation_state_data_2x2x10, + activation_state_quantized, activation_state_scale, output_data, + output_scale, output_zero_point, tflite::testing::input_data_2x2x10, + input_sequences_quantized, + sizeof(tflite::testing::input_data_2x2x10) / sizeof(float), + tflite::testing::golden_output_2x2x10, golden_quantized, + sizeof(tflite::testing::golden_output_2x2x10) / sizeof(float)); +} + +#if !defined(XTENSA) // TODO(b/170332589): xtensa kernels are less general than \ + // reference kernels and we ifdef out test cases that are \ + // currently known to fail. +TF_LITE_MICRO_TEST(SvdfFloat1x16Input64x1OutputShouldMatchGolden) +{ + constexpr int batch_size = 1; + constexpr int num_units = 64; + constexpr int input_size = 16; + constexpr int memory_size = 8; + constexpr int rank = 1; + constexpr int num_filters = num_units * rank; + constexpr int activation_state_dims_count = + batch_size * memory_size * num_filters; + constexpr int output_dims_count = batch_size * num_units; + constexpr int input_dims_count = batch_size * input_size; + + float input_data[input_dims_count]; + float output_data[output_dims_count]; + float scratch_buffer[batch_size * num_filters]; + float activation_state_data_mutable[activation_state_dims_count]; + + // Initialize activation state to starting values. + memcpy(activation_state_data_mutable, + tflite::testing::initial_activation_state_data_16x1x1, + sizeof(tflite::testing::initial_activation_state_data_16x1x1)); + + tflite::testing::TestSVDF( + batch_size, num_units, input_size, memory_size, rank, kTfLiteActNone, + input_data, tflite::testing::feature_weights_data_16x1x1, + tflite::testing::time_weights_data_16x1x1, activation_state_data_mutable, + tflite::testing::bias_data_16x1x1, scratch_buffer, output_data, + tflite::testing::input_data_16x1x1, input_size, + tflite::testing::golden_output_16x1x1); +} + +TF_LITE_MICRO_TEST(SvdfFloat1x16Input64x1OutputReluShouldMatchGolden) +{ + constexpr int batch_size = 1; + constexpr int num_units = 64; + constexpr int input_size = 16; + constexpr int memory_size = 8; + constexpr int rank = 1; + constexpr int num_filters = num_units * rank; + constexpr int activation_state_dims_count = + batch_size * memory_size * num_filters; + constexpr int output_dims_count = batch_size * num_units; + constexpr int input_dims_count = batch_size * input_size; + + float input_data[input_dims_count]; + float output_data[output_dims_count]; + float scratch_buffer[batch_size * num_filters]; + float activation_state_data_mutable[activation_state_dims_count]; + + // Initialize activation state to starting values. + memcpy(activation_state_data_mutable, + tflite::testing::initial_activation_state_data_16x1x1, + sizeof(tflite::testing::initial_activation_state_data_16x1x1)); + + tflite::testing::TestSVDF( + batch_size, num_units, input_size, memory_size, rank, kTfLiteActRelu, + input_data, tflite::testing::feature_weights_data_16x1x1, + tflite::testing::time_weights_data_16x1x1, activation_state_data_mutable, + tflite::testing::bias_data_16x1x1, scratch_buffer, output_data, + tflite::testing::input_data_16x1x1, input_size, + tflite::testing::golden_output_relu_16x1x1); +} +#endif + +TF_LITE_MICRO_TEST(SvdfQuantized1x16Input64x1OutputShouldMatchGolden) +{ + constexpr int batch_size = 1; + constexpr int num_units = 64; + constexpr int input_size = 16; + constexpr int memory_size = 8; + constexpr int rank = 1; + constexpr int num_filters = num_units * rank; + constexpr int activation_state_dims_count = + batch_size * memory_size * num_filters; + constexpr int output_dims_count = batch_size * num_units; + constexpr int input_dims_count = batch_size * input_size; + + int8_t output_data[output_dims_count]; + + float input_scale = 0.10075444; + float feature_weights_scale = 0.00649388; + float time_weights_scale = 0.001571355; + float activation_state_scale = 0.00045896982; + float output_scale = 0.051445257; + + int input_zero_point = 2; + int output_zero_point = 0; + + int8_t input_quantized[input_dims_count]; + int8_t input_sequences_quantized[sizeof(tflite::testing::input_data_16x1x1) / + sizeof(float)]; + int8_t feature_weights_quantized + [sizeof(tflite::testing::feature_weights_data_16x1x1) / sizeof(float)]; + int16_t + time_weights_quantized[sizeof(tflite::testing::time_weights_data_16x1x1) / + sizeof(float)]; + int16_t activation_state_quantized[activation_state_dims_count]; + int32_t + bias_quantized[sizeof(tflite::testing::bias_data_16x1x1) / sizeof(float)]; + int8_t golden_quantized[sizeof(tflite::testing::golden_output_16x1x1) / + sizeof(float)]; + + tflite::testing::TestIntegerSVDF( + batch_size, num_units, input_size, memory_size, rank, kTfLiteActNone, + input_quantized, input_scale, input_zero_point, + tflite::testing::feature_weights_data_16x1x1, feature_weights_quantized, + feature_weights_scale, tflite::testing::time_weights_data_16x1x1, + time_weights_quantized, time_weights_scale, + tflite::testing::bias_data_16x1x1, bias_quantized, + tflite::testing::initial_activation_state_data_16x1x1, + activation_state_quantized, activation_state_scale, output_data, + output_scale, output_zero_point, tflite::testing::input_data_16x1x1, + input_sequences_quantized, + sizeof(tflite::testing::input_data_16x1x1) / sizeof(float), + tflite::testing::golden_output_16x1x1, golden_quantized, + sizeof(tflite::testing::golden_output_16x1x1) / sizeof(float)); +} + +TF_LITE_MICRO_TEST(SvdfQuantized1x16Input64x1OutputReluShouldMatchGolden) +{ + constexpr int batch_size = 1; + constexpr int num_units = 64; + constexpr int input_size = 16; + constexpr int memory_size = 8; + constexpr int rank = 1; + constexpr int num_filters = num_units * rank; + constexpr int activation_state_dims_count = + batch_size * memory_size * num_filters; + constexpr int output_dims_count = batch_size * num_units; + constexpr int input_dims_count = batch_size * input_size; + + int8_t output_data[output_dims_count]; + + float input_scale = 0.10075444; + float feature_weights_scale = 0.00649388; + float time_weights_scale = 0.001571355; + float activation_state_scale = 0.00045896982; + float output_scale = 0.051445257; + + int input_zero_point = 2; + int output_zero_point = -128; + + int8_t input_quantized[input_dims_count]; + int8_t input_sequences_quantized[sizeof(tflite::testing::input_data_16x1x1) / + sizeof(float)]; + int8_t feature_weights_quantized + [sizeof(tflite::testing::feature_weights_data_16x1x1) / sizeof(float)]; + int16_t + time_weights_quantized[sizeof(tflite::testing::time_weights_data_16x1x1) / + sizeof(float)]; + int16_t activation_state_quantized[activation_state_dims_count]; + int32_t + bias_quantized[sizeof(tflite::testing::bias_data_16x1x1) / sizeof(float)]; + int8_t golden_quantized[sizeof(tflite::testing::golden_output_relu_16x1x1) / + sizeof(float)]; + + tflite::testing::TestIntegerSVDF( + batch_size, num_units, input_size, memory_size, rank, kTfLiteActRelu, + input_quantized, input_scale, input_zero_point, + tflite::testing::feature_weights_data_16x1x1, feature_weights_quantized, + feature_weights_scale, tflite::testing::time_weights_data_16x1x1, + time_weights_quantized, time_weights_scale, + tflite::testing::bias_data_16x1x1, bias_quantized, + tflite::testing::initial_activation_state_data_16x1x1, + activation_state_quantized, activation_state_scale, output_data, + output_scale, output_zero_point, tflite::testing::input_data_16x1x1, + input_sequences_quantized, + sizeof(tflite::testing::input_data_16x1x1) / sizeof(float), + tflite::testing::golden_output_relu_16x1x1, golden_quantized, + sizeof(tflite::testing::golden_output_relu_16x1x1) / sizeof(float)); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/tanh.cc b/components/tflite/tensorflow/lite/micro/kernels/tanh.cc new file mode 100644 index 00000000..96b76206 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/tanh.cc @@ -0,0 +1,163 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/integer_ops/tanh.h" + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/tanh.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/micro_utils.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace activations { +namespace { +constexpr int kInputTensor = 0; +constexpr int kOutputTensor = 0; + +struct OpData { + int32_t input_zero_point; + int32_t input_range_radius; + int32_t input_multiplier; + int input_left_shift; +}; + +void *TanhInit(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(OpData)); +} + +TfLiteStatus CalculateArithmeticOpData(TfLiteContext *context, TfLiteNode *node, + OpData *data) +{ + TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + const TfLiteTensor *input = GetInput(context, node, kInputTensor); + TF_LITE_ENSURE(context, input != nullptr); + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + + TF_LITE_ENSURE_TYPES_EQ(context, input->type, output->type); + + if (input->type == kTfLiteUInt8 || input->type == kTfLiteInt8) { + static constexpr int kInputIntegerBits = 4; + const double input_real_multiplier = + static_cast(input->params.scale) * + static_cast(1 << (31 - kInputIntegerBits)); + + const double q = std::frexp(input_real_multiplier, &data->input_left_shift); + data->input_multiplier = static_cast(TfLiteRound(q * (1ll << 31))); + + data->input_range_radius = + CalculateInputRadius(kInputIntegerBits, data->input_left_shift, 31); + } + return kTfLiteOk; +} + +TfLiteStatus TanhPrepare(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + + OpData *data = static_cast(node->user_data); + + const TfLiteTensor *input = GetInput(context, node, kInputTensor); + TF_LITE_ENSURE(context, input != nullptr); + data->input_zero_point = input->params.zero_point; + return CalculateArithmeticOpData(context, node, data); +} + +} // namespace + +TfLiteStatus TanhEval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + TFLITE_DCHECK(node->user_data != nullptr); + const OpData &data = *(static_cast(node->user_data)); + + switch (input->type) { + case kTfLiteFloat32: { + reference_ops::Tanh(tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + return kTfLiteOk; + } break; + case kTfLiteInt16: { + TanhParams params; + params.input_left_shift = data.input_left_shift; + reference_ops::Tanh(params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + return kTfLiteOk; + } break; + case kTfLiteUInt8: { + TanhParams params; + params.input_zero_point = data.input_zero_point; + params.input_range_radius = data.input_range_radius; + params.input_multiplier = data.input_multiplier; + params.input_left_shift = data.input_left_shift; + reference_ops::Tanh(params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + + return kTfLiteOk; + } break; + case kTfLiteInt8: { + reference_integer_ops::Tanh( + data.input_zero_point, data.input_range_radius, data.input_multiplier, + data.input_left_shift, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + return kTfLiteOk; + } break; + default: + TF_LITE_KERNEL_LOG(context, "Input %s, output %s not supported.", + TfLiteTypeGetName(input->type), + TfLiteTypeGetName(output->type)); + return kTfLiteError; + } +} + +} // namespace activations + +TfLiteRegistration Register_TANH() +{ + return { /*init=*/activations::TanhInit, + /*free=*/nullptr, + /*prepare=*/activations::TanhPrepare, + /*invoke=*/activations::TanhEval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/tanh_test.cc b/components/tflite/tensorflow/lite/micro/kernels/tanh_test.cc new file mode 100644 index 00000000..23772385 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/tanh_test.cc @@ -0,0 +1,230 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +constexpr int tanh_vec_size = 90; + +const float tanh_input_vec_fp[tanh_vec_size] = { + -8.0000000000, -7.8181818182, -7.6363636364, -7.4545454545, -7.2727272727, + -7.0909090909, -6.9090909091, -6.7272727273, -6.5454545455, -6.3636363636, + -6.1818181818, -6.0000000000, -5.8181818182, -5.6363636364, -5.4545454545, + -5.2727272727, -5.0909090909, -4.9090909091, -4.7272727273, -4.5454545455, + -4.3636363636, -4.1818181818, -4.0000000000, -3.8181818182, -3.6363636364, + -3.4545454545, -3.2727272727, -3.0909090909, -2.9090909091, -2.7272727273, + -2.5454545455, -2.3636363636, -2.1818181818, -2.0000000000, -1.8181818182, + -1.6363636364, -1.4545454545, -1.2727272727, -1.0909090909, -0.9090909091, + -0.7272727273, -0.5454545455, -0.3636363636, -0.1818181818, 0.0000000000, + 0.1818181818, 0.3636363636, 0.5454545455, 0.7272727273, 0.9090909091, + 1.0909090909, 1.2727272727, 1.4545454545, 1.6363636364, 1.8181818182, + 2.0000000000, 2.1818181818, 2.3636363636, 2.5454545455, 2.7272727273, + 2.9090909091, 3.0909090909, 3.2727272727, 3.4545454545, 3.6363636364, + 3.8181818182, 4.0000000000, 4.1818181818, 4.3636363636, 4.5454545455, + 4.7272727273, 4.9090909091, 5.0909090909, 5.2727272727, 5.4545454545, + 5.6363636364, 5.8181818182, 6.0000000000, 6.1818181818, 6.3636363636, + 6.5454545455, 6.7272727273, 6.9090909091, 7.0909090909, 7.2727272727, + 7.4545454545, 7.6363636364, 7.8181818182, 8.0000000000 +}; + +const float tanh_output_vec_fp[tanh_vec_size] = { + -0.9999997749, -0.9999996762, -0.9999995342, -0.9999993300, -0.9999990361, + -0.9999986134, -0.9999980053, -0.9999971306, -0.9999958722, -0.9999940619, + -0.9999914578, -0.9999877117, -0.9999823226, -0.9999745703, -0.9999634183, + -0.9999473758, -0.9999242982, -0.9998911009, -0.9998433469, -0.9997746542, + -0.9996758446, -0.9995337191, -0.9993292997, -0.9990353053, -0.9986125310, + -0.9980046622, -0.9971308601, -0.9958751909, -0.9940716137, -0.9914827859, + -0.9877703933, -0.9824541388, -0.9748561217, -0.9640275801, -0.9486568273, + -0.9269625051, -0.8965880154, -0.8545351057, -0.7972097087, -0.7206956332, + -0.6213939966, -0.4971057414, -0.3484130125, -0.1798408185, 0.0000000000, + 0.1798408185, 0.3484130125, 0.4971057414, 0.6213939966, 0.7206956332, + 0.7972097087, 0.8545351057, 0.8965880154, 0.9269625051, 0.9486568273, + 0.9640275801, 0.9748561217, 0.9824541388, 0.9877703933, 0.9914827859, + 0.9940716137, 0.9958751909, 0.9971308601, 0.9980046622, 0.9986125310, + 0.9990353053, 0.9993292997, 0.9995337191, 0.9996758446, 0.9997746542, + 0.9998433469, 0.9998911009, 0.9999242982, 0.9999473758, 0.9999634183, + 0.9999745703, 0.9999823226, 0.9999877117, 0.9999914578, 0.9999940619, + 0.9999958722, 0.9999971306, 0.9999980053, 0.9999986134, 0.9999990361, + 0.9999993300, 0.9999995342, 0.9999996762, 0.9999997749 +}; + +void TestTanhFloat(int input_dims_data[], const float *input_data, + const float *expected_output_data, int output_dims_data[], + float *output_data, const float tolerance) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_elements_count = ElementCount(*output_dims); + + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims), + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = tflite::ops::micro::Register_TANH(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_elements_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output_data[i], output_data[i], + tolerance); + } +} + +template +void TestTanhQuantized(int input_dims_data[], const float *input_data, + T *input_quantized, float input_scale, + int input_zero_point, const float *expected_output_data, + T *expected_output_quantized, int output_dims_data[], + float output_scale, int output_zero_point, + T *output_quantized, const int tolerance) +{ + static_assert(sizeof(T) == 1, "Valid only for 8bit data types"); + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_elements_count = ElementCount(*output_dims); + + tflite::Quantize(expected_output_data, expected_output_quantized, + output_elements_count, output_scale, output_zero_point); + + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateQuantizedTensor(input_data, input_quantized, input_dims, + input_scale, input_zero_point), + CreateQuantizedTensor(output_quantized, output_dims, output_scale, + output_zero_point) + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = tflite::ops::micro::Register_TANH(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_elements_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output_quantized[i], output_quantized[i], + tolerance); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(SimpleTestTanhFloat) +{ + using tflite::testing::tanh_input_vec_fp; + using tflite::testing::tanh_output_vec_fp; + using tflite::testing::tanh_vec_size; + + int input_shape[] = { 2, 1, tanh_vec_size }; + int output_shape[] = { 2, 1, tanh_vec_size }; + + float output_data[tanh_vec_size]; + tflite::testing::TestTanhFloat( // + input_shape, // Input shape. + tanh_input_vec_fp, // Input data + tanh_output_vec_fp, // Expected results. + output_shape, // Output shape. + output_data, 1e-7 /* tolerance */); +} + +TF_LITE_MICRO_TEST(SimpleTestTanhUInt8) +{ + using tflite::testing::tanh_input_vec_fp; + using tflite::testing::tanh_output_vec_fp; + using tflite::testing::tanh_vec_size; + + const float input_scale = 16 / 256.f; + const int input_zero_point = 128; + const float output_scale = 1.99999955f / 256.f; + const int output_zero_point = 128; + + int input_shape[] = { 2, 1, tanh_vec_size }; + int output_shape[] = { 2, 1, tanh_vec_size }; + + uint8_t input_quantized[tanh_vec_size]; + uint8_t expected_output_quantized[tanh_vec_size]; + uint8_t output_quantized[tanh_vec_size]; + tflite::testing::TestTanhQuantized( // + input_shape, // Input shape. + tanh_input_vec_fp, input_quantized, // Input data. + input_scale, input_zero_point, // Input quantized info. + tanh_output_vec_fp, expected_output_quantized, // Expected results. + output_shape, // Output shape. + output_scale, output_zero_point, // Output quantized info. + output_quantized, // Operation results + 2 // Tolerance. + ); +} + +TF_LITE_MICRO_TEST(SimpleTestTanhUInt8) +{ + using tflite::testing::tanh_input_vec_fp; + using tflite::testing::tanh_output_vec_fp; + using tflite::testing::tanh_vec_size; + + const float input_scale = 16 / 256.f; + const int input_zero_point = 0; + const float output_scale = 1.99999955f / 256.f; + const int output_zero_point = 0; + + int input_shape[] = { 2, 1, tanh_vec_size }; + int output_shape[] = { 2, 1, tanh_vec_size }; + + int8_t input_quantized[tanh_vec_size]; + int8_t expected_output_quantized[tanh_vec_size]; + int8_t output_quantized[tanh_vec_size]; + tflite::testing::TestTanhQuantized( // + input_shape, // Input shape. + tanh_input_vec_fp, input_quantized, // Input data. + input_scale, input_zero_point, // Input quantized info. + tanh_output_vec_fp, expected_output_quantized, // Expected results. + output_shape, // Output shape. + output_scale, output_zero_point, // Output quantized info. + output_quantized, // Operation results + 2 // Tolerance. + ); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/transpose.cc b/components/tflite/tensorflow/lite/micro/kernels/transpose.cc new file mode 100644 index 00000000..6891abcf --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/transpose.cc @@ -0,0 +1,116 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/kernels/internal/reference/transpose.h" + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/internal/types.h" +#include "tensorflow/lite/kernels/kernel_util.h" + +namespace tflite { +namespace { + +struct TransposeContext { + TransposeContext(TfLiteContext *context, TfLiteNode *node) + { + input = GetInput(context, node, 0); + perm = GetInput(context, node, 1); + output = GetOutput(context, node, 0); + } + const TfLiteTensor *input; + const TfLiteTensor *perm; + TfLiteTensor *output; +}; + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE_EQ(context, NumInputs(node), 2); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + + TransposeContext op_context(context, node); + + // Ensure validity of input tensor. + TF_LITE_ENSURE_MSG(context, NumDimensions(op_context.input) <= 5, + "Transpose op only supports 1D-5D input arrays."); + TF_LITE_ENSURE_TYPES_EQ(context, op_context.input->type, + op_context.output->type); + + int dims = NumDimensions(op_context.input); + const int32_t *perm_data = GetTensorData(op_context.perm); + + // Ensure validity of the permutations tensor as a 1D tensor. + TF_LITE_ENSURE_EQ(context, NumDimensions(op_context.perm), 1); + TF_LITE_ENSURE_EQ(context, op_context.perm->dims->data[0], dims); + for (int idx = 0; idx < dims; ++idx) { + TF_LITE_ENSURE_MSG(context, (perm_data[idx] >= 0 && perm_data[idx] < dims), + "Transpose op permutations array is out of bounds."); + } + + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + TransposeContext op_context(context, node); + + const int32_t *perm_data = GetTensorData(op_context.perm); + const int size = op_context.perm->dims->data[0]; + TransposeParams params; + params.perm_count = size; + for (int i = 0; i < size; ++i) { + params.perm[i] = perm_data[i]; + } + + // Transpose kernel only does rearranging values not numeric evaluations + // on each cell. It's safe to implement per size of scalar type and this + // trick keeps the total code size in a reasonable range. + switch (op_context.input->type) { + case kTfLiteFloat32: + reference_ops::Transpose(params, GetTensorShape(op_context.input), + GetTensorData(op_context.input), + GetTensorShape(op_context.output), + GetTensorData(op_context.output)); + break; + case kTfLiteInt8: + reference_ops::Transpose(params, GetTensorShape(op_context.input), + GetTensorData(op_context.input), + GetTensorShape(op_context.output), + GetTensorData(op_context.output)); + break; + default: + TF_LITE_KERNEL_LOG(context, + "Type %s is currently not supported by Transpose. " + "Only float32 and int8 is supported", + TfLiteTypeGetName(op_context.input->type)); + return kTfLiteError; + } + + return kTfLiteOk; +} + +} // namespace + +TfLiteRegistration Register_TRANSPOSE() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/transpose_conv.cc b/components/tflite/tensorflow/lite/micro/kernels/transpose_conv.cc new file mode 100644 index 00000000..fdecabd6 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/transpose_conv.cc @@ -0,0 +1,300 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/transpose_conv.h" + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/integer_ops/transpose_conv.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/padding.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace { + +// For the TfLite transpose_conv implementation, input tensor 0 corresponds to +// the OutputShapeTensor. However, since TFLM does not support dynamic tensors, +// the TFLM implementation ignores input tensor 0 and the only inputs we care +// about are kFilterTensor, kInputTensor and kBiasTensor. +constexpr int kFilterTensor = 1; +constexpr int kInputTensor = 2; +constexpr int kBiasTensor = 3; +constexpr int kOutputTensor = 0; + +// Conv is quantized along dimension 0: +// https://www.tensorflow.org/lite/performance/quantization_spec +constexpr int kConvQuantizedDimension = 0; + +struct OpData { + ConvParams params; + + // A scratch buffer is required for quantized implementations. + int scratch_buffer_index; + + // Multiplier and shift arrays are required for the int8 implementation. + int32_t *per_channel_output_multiplier; + int32_t *per_channel_output_shift; +}; + +inline PaddingType RuntimePaddingType(TfLitePadding padding) +{ + switch (padding) { + case TfLitePadding::kTfLitePaddingSame: + return PaddingType::kSame; + case TfLitePadding::kTfLitePaddingValid: + return PaddingType::kValid; + case TfLitePadding::kTfLitePaddingUnknown: + default: + return PaddingType::kNone; + } +} + +TfLiteStatus CalculateOpData(TfLiteContext *context, TfLiteNode *node, + const TfLiteConvParams *params, int width, + int height, int filter_width, int filter_height, + int out_width, int out_height, + const TfLiteType data_type, OpData *data) +{ + bool has_bias = node->inputs->size == 4; + // Check number of inputs/outputs + TF_LITE_ENSURE(context, has_bias || node->inputs->size == 3); + TF_LITE_ENSURE_EQ(context, node->outputs->size, 1); + + // Matching GetWindowedOutputSize in TensorFlow. + auto padding = params->padding; + TfLitePaddingValues padding_values = ComputePaddingHeightWidth( + params->stride_height, params->stride_width, + params->dilation_height_factor, params->dilation_width_factor, height, + width, filter_height, filter_width, padding, &out_height, &out_width); + + data->params.padding_type = RuntimePaddingType(padding); + data->params.padding_values.width = padding_values.width; + data->params.padding_values.height = padding_values.height; + + // Note that quantized inference requires that all tensors have their + // parameters set. This is usually done during quantized training. + if (data_type != kTfLiteFloat32) { + const TfLiteTensor *input = GetInput(context, node, kInputTensor); + TF_LITE_ENSURE(context, input != nullptr); + const TfLiteTensor *filter = GetInput(context, node, kFilterTensor); + TF_LITE_ENSURE(context, filter != nullptr); + const TfLiteTensor *bias = + GetOptionalInputTensor(context, node, kBiasTensor); + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + int output_channels = filter->dims->data[kConvQuantizedDimension]; + + TF_LITE_ENSURE_STATUS(tflite::PopulateConvolutionQuantizationParams( + context, input, filter, bias, output, params->activation, + &data->params.output_multiplier, &data->params.output_shift, + &data->params.quantized_activation_min, + &data->params.quantized_activation_max, + data->per_channel_output_multiplier, data->per_channel_output_shift, + output_channels)); + } + return kTfLiteOk; +} + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + return context->AllocatePersistentBuffer(context, sizeof(OpData)); +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + TFLITE_DCHECK(node->builtin_data != nullptr); + + OpData *data = static_cast(node->user_data); + const auto params = static_cast(node->builtin_data); + + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + const TfLiteTensor *input = GetInput(context, node, kInputTensor); + TF_LITE_ENSURE(context, input != nullptr); + const TfLiteTensor *filter = GetInput(context, node, kFilterTensor); + TF_LITE_ENSURE(context, filter != nullptr); + + int input_width = input->dims->data[2]; + int input_height = input->dims->data[1]; + int filter_width = filter->dims->data[2]; + int filter_height = filter->dims->data[1]; + int output_width = output->dims->data[2]; + int output_height = output->dims->data[1]; + + // Dynamically allocate per-channel quantization parameters. + const int num_channels = filter->dims->data[kConvQuantizedDimension]; + data->per_channel_output_multiplier = + static_cast(context->AllocatePersistentBuffer( + context, num_channels * sizeof(int32_t))); + data->per_channel_output_shift = + static_cast(context->AllocatePersistentBuffer( + context, num_channels * sizeof(int32_t))); + + // Quantized kernels use an int32 scratch buffer. + if (input->type == kTfLiteUInt8 || input->type == kTfLiteInt8) { + TFLITE_DCHECK(context->RequestScratchBufferInArena != nullptr); + TFLITE_DCHECK(context->RequestScratchBufferInArena( + context, + GetTensorShape(output).FlatSize() * sizeof(int32_t), + &(data->scratch_buffer_index)) == kTfLiteOk); + } + + // Quantized 16x8 kernels use an int64 scratch buffer. + if (input->type == kTfLiteInt16) { + TFLITE_DCHECK(context->RequestScratchBufferInArena != nullptr); + TFLITE_DCHECK(context->RequestScratchBufferInArena( + context, + GetTensorShape(output).FlatSize() * sizeof(std::int64_t), + &(data->scratch_buffer_index)) == kTfLiteOk); + } + + // All per-channel quantized tensors need valid zero point and scale arrays. + if (input->type == kTfLiteInt8 || input->type == kTfLiteInt16) { + TF_LITE_ENSURE_EQ(context, filter->quantization.type, + kTfLiteAffineQuantization); + + const auto *affine_quantization = + static_cast(filter->quantization.params); + TF_LITE_ENSURE(context, affine_quantization); + TF_LITE_ENSURE(context, affine_quantization->scale); + TF_LITE_ENSURE(context, affine_quantization->zero_point); + + TF_LITE_ENSURE(context, + affine_quantization->scale->size == 1 || + affine_quantization->scale->size == + filter->dims->data[kConvQuantizedDimension]); + TF_LITE_ENSURE_EQ(context, affine_quantization->scale->size, + affine_quantization->zero_point->size); + } + + TF_LITE_ENSURE_STATUS(CalculateOpData( + context, node, params, input_width, input_height, filter_width, + filter_height, output_width, output_height, input->type, data)); + + // Offsets (zero points) + data->params.input_offset = -input->params.zero_point; + data->params.weights_offset = -filter->params.zero_point; + data->params.output_offset = output->params.zero_point; + + // Stride + dilation + data->params.stride_width = params->stride_width; + data->params.stride_height = params->stride_height; + data->params.dilation_width_factor = params->dilation_width_factor; + data->params.dilation_height_factor = params->dilation_height_factor; + + float output_activation_min, output_activation_max; + CalculateActivationRange(params->activation, &output_activation_min, + &output_activation_max); + data->params.float_activation_min = output_activation_min; + data->params.float_activation_max = output_activation_max; + return kTfLiteOk; +} // namespace conv + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + const TfLiteEvalTensor *filter = + tflite::micro::GetEvalInput(context, node, kFilterTensor); + const TfLiteEvalTensor *bias = + (NumInputs(node) == 4) ? tflite::micro::GetEvalInput(context, node, kBiasTensor) : nullptr; + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + TFLITE_DCHECK(node->user_data != nullptr); + const OpData &data = *(static_cast(node->user_data)); + + TF_LITE_ENSURE_EQ(context, input->type, output->type); + TF_LITE_ENSURE_MSG( + context, + input->type == filter->type || + (input->type == kTfLiteInt16 && filter->type == kTfLiteInt8), + "Hybrid models are not supported on TFLite Micro."); + + switch (input->type) { // Already know in/out types are same. + case kTfLiteFloat32: { + reference_ops::TransposeConv( + data.params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(filter), + tflite::micro::GetTensorData(filter), + tflite::micro::GetTensorShape(bias), + tflite::micro::GetTensorData(bias), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output), + tflite::micro::GetTensorShape(nullptr), nullptr); + break; + } + case kTfLiteInt8: { + int32_t *scratch_buffer = static_cast( + context->GetScratchBuffer(context, data.scratch_buffer_index)); + reference_integer_ops::TransposeConv( + data.params, data.per_channel_output_multiplier, + data.per_channel_output_shift, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(filter), + tflite::micro::GetTensorData(filter), + tflite::micro::GetTensorShape(bias), + tflite::micro::GetTensorData(bias), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output), + tflite::micro::GetTensorShape(nullptr), nullptr, scratch_buffer); + break; + } + case kTfLiteInt16: { + std::int64_t *scratch_buffer = static_cast( + context->GetScratchBuffer(context, data.scratch_buffer_index)); + reference_integer_ops::TransposeConv( + data.params, data.per_channel_output_multiplier, + data.per_channel_output_shift, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(filter), + tflite::micro::GetTensorData(filter), + tflite::micro::GetTensorShape(bias), + tflite::micro::GetTensorData(bias), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output), + tflite::micro::GetTensorShape(nullptr), nullptr, scratch_buffer); + break; + } + default: + TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.", + TfLiteTypeGetName(input->type), input->type); + return kTfLiteError; + } + return kTfLiteOk; +} + +} // namespace + +TfLiteRegistration Register_TRANSPOSE_CONV() +{ + return { /*init=*/Init, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/transpose_conv_test.cc b/components/tflite/tensorflow/lite/micro/kernels/transpose_conv_test.cc new file mode 100644 index 00000000..956d8885 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/transpose_conv_test.cc @@ -0,0 +1,386 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/kernels/conv_test.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/micro_utils.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +// Common inputs and outputs. +constexpr int kInputElements = 32; +static int kInputShape[] = { 4, 1, 4, 4, 2 }; +static const float kInputData[kInputElements] = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 +}; + +constexpr int kFilterElements = 18; +static int kFilterShape[] = { 4, 1, 3, 3, 2 }; +static const float kFilterData[kFilterElements] = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 +}; + +constexpr int kBiasElements = 1; +static int kBiasShape[] = { 4, 1, 1, 1, 1 }; +static const float kBiasData[kBiasElements] = { 0 }; + +constexpr int kOutputElements = 16; +static int kOutputShape[] = { 4, 1, 4, 4, 1 }; +static const float kGoldenData[kOutputElements] = { + 184, 412, 568, 528, 678, 1347, 1689, 1434, + 1494, 2715, 3057, 2442, 1968, 3352, 3652, 2760 +}; + +// Transpose conv uses TfLiteConvParams. +static TfLiteConvParams common_conv_params = { kTfLitePaddingSame, // padding + 1, // stride_width + 1, // stride_height + kTfLiteActNone, + 1, + 1 }; + +template +TfLiteStatus InvokeTransposeConv(TfLiteTensor *tensors, int tensors_size, + int output_length, + TfLiteConvParams *conv_params, + T *output_data) +{ + int inputs_array_data[] = { 4, 0, 1, 2, 3 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 4 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = tflite::Register_TRANSPOSE_CONV(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, conv_params); + + const char *init_data = reinterpret_cast(conv_params); + TfLiteStatus status = runner.InitAndPrepare(init_data); + if (status != kTfLiteOk) { + return status; + } + return runner.Invoke(); +} + +template +TfLiteStatus ValidateTransposeConvGoldens(TfLiteTensor *tensors, + int tensors_size, + const T *expected_output_data, + int output_length, + TfLiteConvParams *conv_params, + T *output_data, float tolerance) +{ + TfLiteStatus status = InvokeTransposeConv( + tensors, tensors_size, output_length, conv_params, output_data); + if (status != kTfLiteOk) { + return status; + } + for (int i = 0; i < output_length; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output_data[i], output_data[i], + tolerance); + } + return kTfLiteOk; +} + +TfLiteStatus TestTransposeConvFloat( + int *input_dims_data, const float *input_data, int *filter_dims_data, + const float *filter_data, int *bias_dims_data, const float *bias_data, + int *output_dims_data, const float *expected_output_data, + TfLiteConvParams *conv_params, float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *filter_dims = IntArrayFromInts(filter_dims_data); + TfLiteIntArray *bias_dims = IntArrayFromInts(bias_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + int output_shape_dims_data[] = { 1, 0 }; + int32_t *output_shape = nullptr; + TfLiteIntArray *output_shape_dims = IntArrayFromInts(output_shape_dims_data); + + constexpr int inputs_size = 4; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(output_shape, output_shape_dims), + CreateTensor(filter_data, filter_dims), + CreateTensor(input_data, input_dims), + CreateTensor(bias_data, bias_dims), + CreateTensor(output_data, output_dims), + }; + + return ValidateTransposeConvGoldens(tensors, tensors_size, + expected_output_data, output_dims_count, + conv_params, output_data, 0.001f); +} + +TfLiteStatus TestTransposeConvQuantized( + int *input_dims_data, const float *input_data, int8_t *input_quantized, + float input_scale, int input_zero_point, int *filter_dims_data, + const float *filter_data, int8_t *filter_quantized, float filter_scale, + int *bias_dims_data, const float *bias_data, int32_t *bias_quantized, + float *bias_scales, int *bias_zero_points, int *output_dims_data, + const float *expected_output_data, int8_t *expected_output_quantized, + float output_scale, int output_zero_point, TfLiteConvParams *conv_params, + int8_t *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *filter_dims = IntArrayFromInts(filter_dims_data); + TfLiteIntArray *bias_dims = IntArrayFromInts(bias_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + int filter_zero_points[5]; + float filter_scales[5]; + TfLiteAffineQuantization filter_quant; + TfLiteTensor filter_tensor = CreateSymmetricPerChannelQuantizedTensor( + filter_data, filter_quantized, filter_dims, filter_scales, + filter_zero_points, &filter_quant, 0 /* quantized dimension */); + tflite::Quantize(expected_output_data, expected_output_quantized, + output_dims_count, output_scale, 0); + + int output_shape_dims_data[] = { 1, 0 }; + int32_t *output_shape = nullptr; + TfLiteIntArray *output_shape_dims = IntArrayFromInts(output_shape_dims_data); + + constexpr int inputs_size = 4; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(output_shape, output_shape_dims), filter_tensor, + CreateQuantizedTensor(input_data, input_quantized, input_dims, + input_scale, input_zero_point), + CreateQuantizedBiasTensor(bias_data, bias_quantized, bias_dims, + input_scale, filter_scale), + CreateQuantizedTensor(output_data, output_dims, output_scale, + output_zero_point) + }; + + return ValidateTransposeConvGoldens( + tensors, tensors_size, expected_output_quantized, output_dims_count, + conv_params, output_data, 1.0f); +} + +TfLiteStatus TestTransposeConvQuantized( + int *input_dims_data, const float *input_data, int16_t *input_quantized, + float input_scale, int input_zero_point, int *filter_dims_data, + const float *filter_data, int8_t *filter_quantized, float filter_scale, + int *bias_dims_data, const float *bias_data, std::int64_t *bias_quantized, + float *bias_scales, int *bias_zero_points, int *output_dims_data, + const float *expected_output_data, int16_t *expected_output_quantized, + float output_scale, int output_zero_point, TfLiteConvParams *conv_params, + int16_t *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *filter_dims = IntArrayFromInts(filter_dims_data); + TfLiteIntArray *bias_dims = IntArrayFromInts(bias_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + int filter_zero_points[5]; + float filter_scales[5]; + TfLiteAffineQuantization filter_quant; + TfLiteTensor filter_tensor = CreateSymmetricPerChannelQuantizedTensor( + filter_data, filter_quantized, filter_dims, filter_scales, + filter_zero_points, &filter_quant, 0 /* quantized dimension */); + tflite::Quantize(expected_output_data, expected_output_quantized, + output_dims_count, output_scale, 0); + + int output_shape_dims_data[] = { 1, 0 }; + int32_t *output_shape = nullptr; + TfLiteIntArray *output_shape_dims = IntArrayFromInts(output_shape_dims_data); + + constexpr int inputs_size = 4; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(output_shape, output_shape_dims), filter_tensor, + CreateQuantizedTensor(input_data, input_quantized, input_dims, + input_scale, input_zero_point), + CreateQuantizedBiasTensor(bias_data, bias_quantized, bias_dims, + input_scale, filter_scale), + CreateQuantizedTensor(output_data, output_dims, output_scale, + output_zero_point) + }; + + // Tolerance is slightly looser for 8x16 compared with float, since quant + // error is more pronounced on the finer-grained 16-bit output. + return ValidateTransposeConvGoldens( + tensors, tensors_size, expected_output_quantized, output_dims_count, + conv_params, output_data, 4.0f); +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(SimpleTestFloat) +{ + float output_data[tflite::testing::kOutputElements]; + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, + tflite::testing::TestTransposeConvFloat( + tflite::testing::kInputShape, tflite::testing::kInputData, + tflite::testing::kFilterShape, tflite::testing::kFilterData, + tflite::testing::kBiasShape, tflite::testing::kBiasData, + tflite::testing::kOutputShape, tflite::testing::kGoldenData, + &tflite::testing::common_conv_params, output_data)); +} + +TF_LITE_MICRO_TEST(SimpleTestQuantizedPerChannel) +{ + int8_t output_data[tflite::testing::kOutputElements]; + + const float input_scale = 0.5f; + const float output_scale = 30.0f; + const float filter_scale = 1.0f; + const int input_zero_point = 0; + const int output_zero_point = 0; + + int8_t input_quantized[tflite::testing::kInputElements]; + int8_t filter_quantized[tflite::testing::kFilterElements]; + int32_t bias_quantized[tflite::testing::kBiasElements]; + int8_t golden_quantized[tflite::testing::kOutputElements]; + int zero_points[tflite::testing::kBiasElements + 1]; + float scales[tflite::testing::kBiasElements + 1]; + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, + tflite::testing::TestTransposeConvQuantized( + tflite::testing::kInputShape, tflite::testing::kInputData, + input_quantized, input_scale, input_zero_point, + tflite::testing::kFilterShape, tflite::testing::kFilterData, + filter_quantized, filter_scale, tflite::testing::kBiasShape, + tflite::testing::kBiasData, bias_quantized, scales, zero_points, + tflite::testing::kOutputShape, tflite::testing::kGoldenData, + golden_quantized, output_scale, output_zero_point, + &tflite::testing::common_conv_params, output_data)); +} + +TF_LITE_MICRO_TEST(SimpleTestQuantized16x8PerChannel) +{ + int16_t output_data[tflite::testing::kOutputElements]; + + const float input_scale = 1.0f; + const float output_scale = 1.0f; + const float filter_scale = 1.0f; + const int input_zero_point = 0; + const int output_zero_point = 0; + + int16_t input_quantized[tflite::testing::kInputElements]; + int8_t filter_quantized[tflite::testing::kFilterElements]; + std::int64_t bias_quantized[tflite::testing::kBiasElements]; + int16_t golden_quantized[tflite::testing::kOutputElements]; + int zero_points[tflite::testing::kBiasElements + 1]; + float scales[tflite::testing::kBiasElements + 1]; + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, + tflite::testing::TestTransposeConvQuantized( + tflite::testing::kInputShape, tflite::testing::kInputData, + input_quantized, input_scale, input_zero_point, + tflite::testing::kFilterShape, tflite::testing::kFilterData, + filter_quantized, filter_scale, tflite::testing::kBiasShape, + tflite::testing::kBiasData, bias_quantized, scales, zero_points, + tflite::testing::kOutputShape, tflite::testing::kGoldenData, + golden_quantized, output_scale, output_zero_point, + &tflite::testing::common_conv_params, output_data)); +} + +TF_LITE_MICRO_TEST(InputOutputDifferentTypeIsError) +{ + using tflite::testing::CreateQuantizedTensor; + using tflite::testing::CreateTensor; + using tflite::testing::IntArrayFromInts; + + TfLiteIntArray *input_dims = IntArrayFromInts(tflite::testing::kInputShape); + TfLiteIntArray *filter_dims = IntArrayFromInts(tflite::testing::kFilterShape); + TfLiteIntArray *bias_dims = IntArrayFromInts(tflite::testing::kBiasShape); + TfLiteIntArray *output_dims = IntArrayFromInts(tflite::testing::kOutputShape); + const int output_dims_count = tflite::ElementCount(*output_dims); + constexpr int inputs_size = 4; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + + int8_t output_data[tflite::testing::kOutputElements]; + + int output_shape_dims_data[] = { 1, 0 }; + int32_t *output_shape = nullptr; + TfLiteIntArray *output_shape_dims = IntArrayFromInts(output_shape_dims_data); + + TfLiteTensor tensors[tensors_size] = { + CreateTensor(output_shape, output_shape_dims), + CreateTensor(tflite::testing::kInputData, input_dims), + CreateTensor(tflite::testing::kFilterData, filter_dims), + CreateTensor(tflite::testing::kBiasData, bias_dims), + CreateQuantizedTensor(output_data, output_dims, /*scale=*/1.0f, + /*zero_point=*/0), + }; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteError, tflite::testing::InvokeTransposeConv( + tensors, tensors_size, output_dims_count, + &tflite::testing::common_conv_params, output_data)); +} + +TF_LITE_MICRO_TEST(HybridModeIsError) +{ + using tflite::testing::CreateQuantizedTensor; + using tflite::testing::CreateTensor; + using tflite::testing::IntArrayFromInts; + + TfLiteIntArray *input_dims = IntArrayFromInts(tflite::testing::kInputShape); + TfLiteIntArray *filter_dims = IntArrayFromInts(tflite::testing::kFilterShape); + TfLiteIntArray *bias_dims = IntArrayFromInts(tflite::testing::kBiasShape); + TfLiteIntArray *output_dims = IntArrayFromInts(tflite::testing::kOutputShape); + const int output_dims_count = tflite::ElementCount(*output_dims); + + constexpr int inputs_size = 4; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + + int8_t filter_data[tflite::testing::kFilterElements] = {}; + float output_data[tflite::testing::kOutputElements]; + + int output_shape_dims_data[] = { 1, 0 }; + int32_t *output_shape = nullptr; + TfLiteIntArray *output_shape_dims = IntArrayFromInts(output_shape_dims_data); + + TfLiteTensor tensors[tensors_size] = { + CreateTensor(output_shape, output_shape_dims), + CreateTensor(tflite::testing::kInputData, input_dims), + CreateQuantizedTensor(filter_data, filter_dims, + /*scale=*/1.0f, + /*zero_point=*/0), + CreateTensor(tflite::testing::kBiasData, bias_dims), + CreateTensor(output_data, output_dims), + }; + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteError, tflite::testing::InvokeTransposeConv( + tensors, tensors_size, output_dims_count, + &tflite::testing::common_conv_params, output_data)); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/transpose_test.cc b/components/tflite/tensorflow/lite/micro/kernels/transpose_test.cc new file mode 100644 index 00000000..d1fef68d --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/transpose_test.cc @@ -0,0 +1,650 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/kernels/internal/reference/transpose.h" + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/portable_tensor.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/micro_utils.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +template +void RunTestPermutation(int num_dims, const int32_t *shape, + const int32_t *perms, T *input, T *input_transposed) +{ + // Count elements and allocate output. + int count = 1; + for (int i = 0; i < num_dims; i++) { + count *= shape[i]; + } + + // Create the dummy data + for (int i = 0; i < count; i++) { + input[i] = i; + } + + // Make input and output shapes. + const RuntimeShape input_shape = RuntimeShape(num_dims, shape); + RuntimeShape output_shape(num_dims); + + for (int i = 0; i < num_dims; i++) { + output_shape.SetDim(i, shape[perms[i]]); + } + + TransposeParams params; + params.perm_count = num_dims; + for (int i = 0; i < num_dims; ++i) { + params.perm[i] = perms[i]; + } + + reference_ops::Transpose(params, input_shape, input, output_shape, + input_transposed); +} + +template +TfLiteStatus InvokeTranspose(TfLiteTensor *tensors, int tensors_size, + T *output_data, int output_length, + TransposeParams *params) +{ + int inputs_array_data[] = { 2, 0, 1 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 2 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = Register_TRANSPOSE(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, reinterpret_cast(params)); + + const char *init_data = reinterpret_cast(params); + TfLiteStatus status = runner.InitAndPrepare(init_data); + if (status != kTfLiteOk) { + return status; + } + return runner.Invoke(); +} + +template +TfLiteStatus ValidateTranspose(TfLiteTensor *tensors, int tensors_size, + const T *expected_output_data, T *output_data, + int output_length, + tflite::TransposeParams *params, + float tolerance = 1e-5) +{ + TfLiteStatus status = InvokeTranspose(tensors, tensors_size, output_data, + output_length, params); + if (status != kTfLiteOk) { + return status; + } + + for (int i = 0; i < output_length; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output_data[i], output_data[i]); + } + return kTfLiteOk; +} + +template +void TestTranspose(int *input_dims_data, T *input_data, int *output_dims_data, + const T *expected_output_data, T *output_data, + TransposeParams *params) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int input_size = ElementCount(*input_dims); + for (int i = 0; i < input_size; i++) { + input_data[i] = i; + } + + for (int i = 0; i < input_dims->size; i++) { + output_dims->data[i] = input_dims->data[params->perm[i]]; + } + + int perm_dims_data[] = { 1, params->perm_count }; + TfLiteIntArray *perm_dims = IntArrayFromInts(perm_dims_data); + const int output_dims_count = ElementCount(*output_dims); + constexpr int inputs_size = 2; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(params->perm, perm_dims), + CreateTensor(output_data, output_dims), + }; + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, ValidateTranspose(tensors, tensors_size, expected_output_data, + output_data, output_dims_count, params)); +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(1D) +{ + int input_dims_data[] = { 1, 3 }; + int output_dims_data[] = { 1, 3 }; + + int8_t input_data[3]; + int8_t output_data[3]; + const int8_t expected_output_data[] = { 0, 1, 2 }; + + tflite::TransposeParams params = { 1, { 0 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(2DPerm1) +{ + int input_dims_data[] = { 2, 3, 2 }; + int output_dims_data[] = { 2, 3, 2 }; + + int8_t input_data[6]; + int8_t output_data[6]; + const int8_t expected_output_data[] = { 0, 2, 4, 1, 3, 5 }; + + tflite::TransposeParams params = { 2, { 1, 0 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(2D4x4KernelLeftOverRightSide) +{ + int input_dims_data[] = { 2, 4, 6 }; + int output_dims_data[] = { 2, 4, 6 }; + + int8_t input_data[24]; + int8_t output_data[24]; + const int8_t expected_output_data[] = { 0, 6, 12, 18, 1, 7, 13, 19, + 2, 8, 14, 20, 3, 9, 15, 21, + 4, 10, 16, 22, 5, 11, 17, 23 }; + + tflite::TransposeParams params = { 2, { 1, 0 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(2D4x4KernelLeftOverBottomSide) +{ + int input_dims_data[] = { 2, 6, 4 }; + int output_dims_data[] = { 2, 4, 6 }; + + int8_t input_data[24]; + int8_t output_data[24]; + const int8_t expected_output_data[] = { 0, 4, 8, 12, 16, 20, 1, 5, + 9, 13, 17, 21, 2, 6, 10, 14, + 18, 22, 3, 7, 11, 15, 19, 23 }; + + tflite::TransposeParams params = { 2, { 1, 0 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(3D) +{ + int input_dims_data[] = { 3, 2, 3, 4 }; + int output_dims_data[] = { 3, 2, 3, 4 }; + + int8_t input_data[24]; + int8_t output_data[24]; + const int8_t expected_output_data[] = { 0, 4, 8, 12, 16, 20, 1, 5, + 9, 13, 17, 21, 2, 6, 10, 14, + 18, 22, 3, 7, 11, 15, 19, 23 }; + + tflite::TransposeParams params = { 3, { 2, 0, 1 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(1DNotShrinked) +{ + int input_dims_data[] = { 1, 1 }; + int output_dims_data[] = { 1, 1 }; + + float input_data[1]; + float output_data[1]; + const float expected_output_data[] = { 0 }; + + tflite::TransposeParams params = { 1, { 0 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(2DShrinkedOneTime) +{ + int input_dims_data[] = { 2, 2, 1 }; + int output_dims_data[] = { 2, 2, 1 }; + + float input_data[2]; + float output_data[2]; + const float expected_output_data[] = { 0, 1 }; + + tflite::TransposeParams params = { 2, { 1, 0 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(2DShrinkedTwoTimes) +{ + int input_dims_data[] = { 2, 1, 1 }; + int output_dims_data[] = { 2, 1, 1 }; + + float input_data[1]; + float output_data[1]; + const float expected_output_data[] = { 0 }; + + tflite::TransposeParams params = { 2, { 1, 0 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(3DShrinkedOneTime) +{ + int input_dims_data[] = { 3, 2, 1, 3 }; + int output_dims_data[] = { 3, 2, 1, 3 }; + + float input_data[6]; + float output_data[6]; + const float expected_output_data[] = { 0, 1, 2, 3, 4, 5 }; + + tflite::TransposeParams params = { 3, { 0, 2, 1 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(3DShrinkedTwoTimes) +{ + int input_dims_data[] = { 3, 1, 1, 3 }; + int output_dims_data[] = { 3, 1, 1, 3 }; + + float input_data[3]; + float output_data[3]; + const float expected_output_data[] = { 0, 1, 2 }; + + tflite::TransposeParams params = { 3, { 1, 2, 0 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(3DShrinkedAll) +{ + int input_dims_data[] = { 3, 1, 1, 1 }; + int output_dims_data[] = { 3, 1, 1, 1 }; + + float input_data[1]; + float output_data[1]; + const float expected_output_data[] = { 0 }; + + tflite::TransposeParams params = { 3, { 1, 2, 0 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(4DShrinkedOneTimes) +{ + int input_dims_data[] = { 4, 2, 2, 3, 1 }; + int output_dims_data[] = { 4, 2, 2, 3, 1 }; + + float input_data[12]; + float output_data[12]; + const float expected_output_data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; + + tflite::TransposeParams params = { 4, { 3, 0, 1, 2 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(4DShrinkedTwoTimes) +{ + int input_dims_data[] = { 4, 2, 1, 3, 1 }; + int output_dims_data[] = { 4, 2, 1, 3, 1 }; + + float input_data[6]; + float output_data[6]; + const float expected_output_data[] = { 0, 1, 2, 3, 4, 5 }; + + tflite::TransposeParams params = { 4, { 0, 3, 1, 2 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(4DShrinkedThreeTimes) +{ + int input_dims_data[] = { 4, 2, 1, 1, 1 }; + int output_dims_data[] = { 4, 2, 1, 1, 1 }; + + float input_data[2]; + float output_data[2]; + const float expected_output_data[] = { 0, 1 }; + + tflite::TransposeParams params = { 4, { 3, 2, 1, 0 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(4DShrinkedFourTimes) +{ + int input_dims_data[] = { 4, 1, 1, 1, 1 }; + int output_dims_data[] = { 4, 1, 1, 1, 1 }; + + float input_data[1]; + float output_data[1]; + const float expected_output_data[] = { 0 }; + + tflite::TransposeParams params = { 4, { 2, 3, 1, 0 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(3DFlatten) +{ + int input_dims_data[] = { 3, 2, 2, 3 }; + int output_dims_data[] = { 3, 2, 2, 3 }; + + float input_data[12]; + float output_data[12]; + const float expected_output_data[] = { 0, 3, 1, 4, 2, 5, 6, 9, 7, 10, 8, 11 }; + + tflite::TransposeParams params = { 3, { 0, 2, 1 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(4DFlatten) +{ + int input_dims_data[] = { 4, 2, 2, 2, 2 }; + int output_dims_data[] = { 4, 2, 2, 2, 2 }; + + float input_data[16]; + float output_data[16]; + const float expected_output_data[] = { 0, 2, 1, 3, 4, 6, 5, 7, + 8, 10, 9, 11, 12, 14, 13, 15 }; + + tflite::TransposeParams params = { 4, { 0, 1, 3, 2 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(4DFlattenTwo) +{ + int input_dims_data[] = { 4, 2, 2, 2, 2 }; + int output_dims_data[] = { 4, 2, 2, 2, 2 }; + + float input_data[16]; + float output_data[16]; + const float expected_output_data[] = { 0, 4, 1, 5, 2, 6, 3, 7, + 8, 12, 9, 13, 10, 14, 11, 15 }; + + tflite::TransposeParams params = { 4, { 0, 2, 3, 1 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(3DDividedIntoTwo2DsOne) +{ + float input_data[24]; + float expected_output_data[24]; + int32_t shape[] = { 2, 3, 4 }; + int32_t perms[] = { 1, 2, 0 }; + tflite::testing::RunTestPermutation(3, shape, perms, input_data, + expected_output_data); + int input_dims_data[] = { 3, 2, 3, 4 }; + int output_dims_data[] = { 3, 2, 3, 4 }; + + float output_data[24]; + + tflite::TransposeParams params = { 3, { 1, 2, 0 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(3DDividedIntoTwo2DsTwo) +{ + float input_data[24]; + float expected_output_data[24]; + int32_t shape[] = { 2, 3, 4 }; + int32_t perms[] = { 2, 0, 1 }; + tflite::testing::RunTestPermutation(3, shape, perms, input_data, + expected_output_data); + int input_dims_data[] = { 3, 2, 3, 4 }; + int output_dims_data[] = { 3, 2, 3, 4 }; + + float output_data[24]; + + tflite::TransposeParams params = { 3, { 2, 0, 1 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(4DDividedIntoTwo2DsOne) +{ + int32_t shape[] = { 2, 3, 4, 2 }; + int32_t perms[] = { 1, 2, 3, 0 }; + float input_data[48]; + float expected_output_data[48]; + tflite::testing::RunTestPermutation(4, shape, perms, input_data, + expected_output_data); + int input_dims_data[] = { 4, 2, 3, 4, 2 }; + int output_dims_data[] = { 4, 2, 3, 4, 2 }; + + float output_data[48]; + + tflite::TransposeParams params = { 4, { 1, 2, 3, 0 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} +TF_LITE_MICRO_TEST(4DDividedIntoTwo2DsTwo) +{ + int32_t shape[] = { 2, 3, 4, 2 }; + int32_t perms[] = { 2, 3, 0, 1 }; + float input_data[48]; + float expected_output_data[48]; + tflite::testing::RunTestPermutation(4, shape, perms, input_data, + expected_output_data); + int input_dims_data[] = { 4, 2, 3, 4, 2 }; + int output_dims_data[] = { 4, 2, 3, 4, 2 }; + + float output_data[48]; + + tflite::TransposeParams params = { 4, { 2, 3, 0, 1 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(4DDividedIntoTwo2DsThree) +{ + int32_t shape[] = { 2, 3, 4, 2 }; + int32_t perms[] = { 3, 0, 1, 2 }; + float input_data[48]; + float expected_output_data[48]; + tflite::testing::RunTestPermutation(4, shape, perms, input_data, + expected_output_data); + int input_dims_data[] = { 4, 2, 3, 4, 2 }; + int output_dims_data[] = { 4, 2, 3, 4, 2 }; + + float output_data[48]; + + tflite::TransposeParams params = { 4, { 3, 0, 1, 2 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(5DDividedIntoTwo2DsOne) +{ + int32_t shape[] = { 2, 3, 2, 2, 2 }; + int32_t perms[] = { 1, 4, 2, 3, 0 }; + float input_data[48]; + float expected_output_data[48]; + tflite::testing::RunTestPermutation(5, shape, perms, input_data, + expected_output_data); + int input_dims_data[] = { 5, 2, 3, 2, 2, 2 }; + int output_dims_data[] = { 5, 2, 3, 2, 2, 2 }; + + float output_data[48]; + + tflite::TransposeParams params = { 5, { 1, 4, 2, 3, 0 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(5DDividedIntoTwo2DsTwo) +{ + int32_t shape[] = { 2, 3, 2, 2, 2 }; + int32_t perms[] = { 2, 3, 0, 4, 1 }; + float input_data[48]; + float expected_output_data[48]; + tflite::testing::RunTestPermutation(5, shape, perms, input_data, + expected_output_data); + int input_dims_data[] = { 5, 2, 3, 2, 2, 2 }; + int output_dims_data[] = { 5, 2, 3, 2, 2, 2 }; + + float output_data[48]; + + tflite::TransposeParams params = { 5, { 2, 3, 0, 4, 1 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(5DDividedIntoTwo2DsThree) +{ + int32_t shape[] = { 2, 3, 2, 2, 2 }; + int32_t perms[] = { 3, 0, 4, 1, 2 }; + float input_data[48]; + float expected_output_data[48]; + tflite::testing::RunTestPermutation(5, shape, perms, input_data, + expected_output_data); + int input_dims_data[] = { 5, 2, 3, 2, 2, 2 }; + int output_dims_data[] = { 5, 2, 3, 2, 2, 2 }; + + float output_data[48]; + + tflite::TransposeParams params = { 5, { 3, 0, 4, 1, 2 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(SimpleTestNoReorder) +{ + int input_dims_data[] = { 4, 1, 2, 3, 1 }; + int output_dims_data[] = { 4, 1, 2, 3, 1 }; + + float input_data[6]; + float output_data[6]; + const float expected_output_data[] = { 0, 1, 2, 3, 4, 5 }; + + tflite::TransposeParams params = { 4, { 0, 1, 2, 3 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(SimpleTestWithReorder) +{ + int input_dims_data[] = { 4, 1, 2, 3, 1 }; + int output_dims_data[] = { 4, 1, 2, 3, 1 }; + + float input_data[6]; + float output_data[6]; + const float expected_output_data[] = { 0, 3, 1, 4, 2, 5 }; + + tflite::TransposeParams params = { 4, { 2, 1, 3, 0 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(ComplexTestWithReorder) +{ + int input_dims_data[] = { 4, 2, 3, 4, 5 }; + int output_dims_data[] = { 4, 2, 3, 4, 5 }; + + float input_data[120]; + float output_data[120]; + const float expected_output_data[] = { + 0, 1, 2, 3, 4, 20, 21, 22, 23, 24, 40, 41, 42, 43, 44, + 60, 61, 62, 63, 64, 80, 81, 82, 83, 84, 100, 101, 102, 103, 104, + 5, 6, 7, 8, 9, 25, 26, 27, 28, 29, 45, 46, 47, 48, 49, + 65, 66, 67, 68, 69, 85, 86, 87, 88, 89, 105, 106, 107, 108, 109, + 10, 11, 12, 13, 14, 30, 31, 32, 33, 34, 50, 51, 52, 53, 54, + 70, 71, 72, 73, 74, 90, 91, 92, 93, 94, 110, 111, 112, 113, 114, + 15, 16, 17, 18, 19, 35, 36, 37, 38, 39, 55, 56, 57, 58, 59, + 75, 76, 77, 78, 79, 95, 96, 97, 98, 99, 115, 116, 117, 118, 119 + }; + + tflite::TransposeParams params = { 4, { 2, 0, 1, 3 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TEST(Complex5DTestWithReorder) +{ + int input_dims_data[] = { 5, 2, 3, 2, 2, 5 }; + int output_dims_data[] = { 5, 2, 3, 2, 2, 5 }; + + float input_data[120]; + float output_data[120]; + const float expected_output_data[] = { + 0, 5, 1, 6, 2, 7, 3, 8, 4, 9, 20, 25, 21, 26, 22, + 27, 23, 28, 24, 29, 40, 45, 41, 46, 42, 47, 43, 48, 44, 49, + 60, 65, 61, 66, 62, 67, 63, 68, 64, 69, 80, 85, 81, 86, 82, + 87, 83, 88, 84, 89, 100, 105, 101, 106, 102, 107, 103, 108, 104, 109, + 10, 15, 11, 16, 12, 17, 13, 18, 14, 19, 30, 35, 31, 36, 32, + 37, 33, 38, 34, 39, 50, 55, 51, 56, 52, 57, 53, 58, 54, 59, + 70, 75, 71, 76, 72, 77, 73, 78, 74, 79, 90, 95, 91, 96, 92, + 97, 93, 98, 94, 99, 110, 115, 111, 116, 112, 117, 113, 118, 114, 119 + }; + + tflite::TransposeParams params = { 5, { 2, 0, 1, 4, 3 } }; + + tflite::testing::TestTranspose(input_dims_data, input_data, output_dims_data, + expected_output_data, output_data, ¶ms); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/unpack.cc b/components/tflite/tensorflow/lite/micro/kernels/unpack.cc new file mode 100644 index 00000000..f2ad11d8 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/unpack.cc @@ -0,0 +1,125 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace ops { +namespace micro { +namespace unpack { +namespace { + +constexpr int kInputTensor = 0; + +template +TfLiteStatus UnpackImpl(TfLiteContext *context, TfLiteNode *node, + const TfLiteEvalTensor *input, int output_count, + int axis) +{ + const TfLiteEvalTensor *output0 = + tflite::micro::GetEvalOutput(context, node, 0); + const TfLiteIntArray *input_dims = input->dims; + const TfLiteIntArray *output_dims = output0->dims; + const int dimensions = input_dims->size; + + if (axis < 0) { + axis += input->dims->size; + } + + TFLITE_DCHECK_LT(axis, dimensions); + + int outer_size = 1; + for (int i = 0; i < axis; ++i) { + outer_size *= input_dims->data[i]; + } + int copy_size = 1; + for (int i = axis + 1; i < dimensions; ++i) { + copy_size *= input_dims->data[i]; + } + int output_size = 1; + for (int i = 0; i < output_dims->size; ++i) { + output_size *= output_dims->data[i]; + } + TFLITE_DCHECK_EQ(output_size, copy_size * outer_size); + + const T *input_data = tflite::micro::GetTensorData(input); + + for (int i = 0; i < output_count; ++i) { + TfLiteEvalTensor *t = tflite::micro::GetEvalOutput(context, node, i); + T *output_data = tflite::micro::GetTensorData(t); + for (int k = 0; k < outer_size; ++k) { + T *output_ptr = output_data + copy_size * k; + int loc = k * output_count * copy_size + i * copy_size; + const T *input_ptr = input_data + loc; + for (int j = 0; j < copy_size; ++j) + output_ptr[j] = input_ptr[j]; + } + } + + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + TfLiteUnpackParams *data = + reinterpret_cast(node->builtin_data); + + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + + switch (input->type) { + case kTfLiteFloat32: { + return UnpackImpl(context, node, input, data->num, data->axis); + } + case kTfLiteInt32: { + return UnpackImpl(context, node, input, data->num, data->axis); + } + case kTfLiteUInt8: { + return UnpackImpl(context, node, input, data->num, data->axis); + } + case kTfLiteInt8: { + return UnpackImpl(context, node, input, data->num, data->axis); + } + default: { + TF_LITE_KERNEL_LOG(context, "Type '%s' is not supported by unpack.", + TfLiteTypeGetName(input->type)); + return kTfLiteError; + } + } + + return kTfLiteOk; +} +} // namespace +} // namespace unpack + +TfLiteRegistration Register_UNPACK() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/nullptr, + /*invoke=*/unpack::Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace micro +} // namespace ops +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/unpack_test.cc b/components/tflite/tensorflow/lite/micro/kernels/unpack_test.cc new file mode 100644 index 00000000..c03577b6 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/unpack_test.cc @@ -0,0 +1,384 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/debug_log.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { + +void TestUnpackThreeOutputsFloat( + int *input_dims_data, const float *input_data, int axis, + int *output1_dims_data, const float *expected_output1_data, + int *output2_dims_data, const float *expected_output2_data, + int *output3_dims_data, const float *expected_output3_data, + float *output1_data, float *output2_data, float *output3_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output1_dims = IntArrayFromInts(output1_dims_data); + TfLiteIntArray *output2_dims = IntArrayFromInts(output2_dims_data); + TfLiteIntArray *output3_dims = IntArrayFromInts(output3_dims_data); + const int output1_dims_count = ElementCount(*output1_dims); + const int output2_dims_count = ElementCount(*output2_dims); + const int output3_dims_count = ElementCount(*output3_dims); + + constexpr int input_size = 1; + constexpr int output_size = 3; + constexpr int tensors_size = input_size + output_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(output1_data, output1_dims), + CreateTensor(output2_data, output2_dims), + CreateTensor(output3_data, output3_dims) + }; + + // Place a unique value in the uninitialized output buffer. + for (int i = 0; i < output1_dims_count; ++i) { + output1_data[i] = 23; + } + + for (int i = 0; i < output2_dims_count; ++i) { + output2_data[i] = 23; + } + + for (int i = 0; i < output3_dims_count; ++i) { + output3_data[i] = 23; + } + + TfLiteUnpackParams builtin_data = { + .num = 3, + .axis = axis, + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 3, 1, 2, 3 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = tflite::ops::micro::Register_UNPACK(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + reinterpret_cast(&builtin_data)); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output1_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output1_data[i], output1_data[i], 1e-5f); + } + + for (int i = 0; i < output2_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output2_data[i], output2_data[i], 1e-5f); + } + + for (int i = 0; i < output3_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output3_data[i], output3_data[i], 1e-5f); + } +} + +void TestUnpackOneOutputFloat(int *input_dims_data, const float *input_data, + int axis, int *output_dims_data, + const float *expected_output_data, + float *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(output_dims_data); + const int output_dims_count = ElementCount(*output_dims); + + constexpr int input_size = 1; + constexpr int output_size = 1; + constexpr int tensors_size = input_size + output_size; + TfLiteTensor tensors[tensors_size] = { CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims) }; + + // Place a unique value in the uninitialized output buffer. + for (int i = 0; i < output_dims_count; ++i) { + output_data[i] = 23; + } + + TfLiteUnpackParams builtin_data = { + .num = 1, + .axis = axis, + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = tflite::ops::micro::Register_UNPACK(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + reinterpret_cast(&builtin_data)); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_NEAR(expected_output_data[i], output_data[i], 1e-5f); + } +} + +void TestUnpackThreeOutputsQuantized( + int *input_dims_data, const uint8_t *input_data, int axis, + int *output1_dims_data, const uint8_t *expected_output1_data, + int *output2_dims_data, const uint8_t *expected_output2_data, + int *output3_dims_data, const uint8_t *expected_output3_data, + uint8_t *output1_data, uint8_t *output2_data, uint8_t *output3_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output1_dims = IntArrayFromInts(output1_dims_data); + TfLiteIntArray *output2_dims = IntArrayFromInts(output2_dims_data); + TfLiteIntArray *output3_dims = IntArrayFromInts(output3_dims_data); + const int output1_dims_count = ElementCount(*output1_dims); + const int output2_dims_count = ElementCount(*output2_dims); + const int output3_dims_count = ElementCount(*output3_dims); + + constexpr int input_size = 1; + constexpr int output_size = 3; + constexpr int tensors_size = input_size + output_size; + TfLiteTensor tensors[tensors_size] = { + // CreateQuantizedTensor needs min/max values as input, but these values + // don't matter as to the functionality of UNPACK, so just set as 0 + // and 10. + CreateQuantizedTensor(input_data, input_dims, 0, 10), + CreateQuantizedTensor(output1_data, output1_dims, 0, 10), + CreateQuantizedTensor(output2_data, output2_dims, 0, 10), + CreateQuantizedTensor(output3_data, output3_dims, 0, 10) + }; + + // Place a unique value in the uninitialized output buffer. + for (int i = 0; i < output1_dims_count; ++i) { + output1_data[i] = 23; + } + + for (int i = 0; i < output2_dims_count; ++i) { + output2_data[i] = 23; + } + + for (int i = 0; i < output3_dims_count; ++i) { + output3_data[i] = 23; + } + + TfLiteUnpackParams builtin_data = { + .num = 3, + .axis = axis, + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 3, 1, 2, 3 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = tflite::ops::micro::Register_UNPACK(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + reinterpret_cast(&builtin_data)); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output1_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output1_data[i], output1_data[i]); + } + + for (int i = 0; i < output2_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output2_data[i], output2_data[i]); + } + + for (int i = 0; i < output3_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output3_data[i], output3_data[i]); + } +} + +void TestUnpackThreeOutputsQuantized32( + int *input_dims_data, const int32_t *input_data, int axis, + int *output1_dims_data, const int32_t *expected_output1_data, + int *output2_dims_data, const int32_t *expected_output2_data, + int *output3_dims_data, const int32_t *expected_output3_data, + int32_t *output1_data, int32_t *output2_data, int32_t *output3_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output1_dims = IntArrayFromInts(output1_dims_data); + TfLiteIntArray *output2_dims = IntArrayFromInts(output2_dims_data); + TfLiteIntArray *output3_dims = IntArrayFromInts(output3_dims_data); + const int output1_dims_count = ElementCount(*output1_dims); + const int output2_dims_count = ElementCount(*output2_dims); + const int output3_dims_count = ElementCount(*output3_dims); + + constexpr int input_size = 1; + constexpr int output_size = 3; + constexpr int tensors_size = input_size + output_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(output1_data, output1_dims), + CreateTensor(output2_data, output2_dims), + CreateTensor(output3_data, output3_dims) + }; + + // Place a unique value in the uninitialized output buffer. + for (int i = 0; i < output1_dims_count; ++i) { + output1_data[i] = 23; + } + + for (int i = 0; i < output2_dims_count; ++i) { + output2_data[i] = 23; + } + + for (int i = 0; i < output3_dims_count; ++i) { + output3_data[i] = 23; + } + + TfLiteUnpackParams builtin_data = { + .num = 3, + .axis = axis, + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 3, 1, 2, 3 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = tflite::ops::micro::Register_UNPACK(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + reinterpret_cast(&builtin_data)); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output1_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output1_data[i], output1_data[i]); + } + + for (int i = 0; i < output2_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output2_data[i], output2_data[i]); + } + + for (int i = 0; i < output3_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output3_data[i], output3_data[i]); + } +} + +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(UnpackFloatThreeOutputs) +{ + int input_shape[] = { 2, 3, 2 }; + const float input_values[] = { 1, 2, 3, 4, 5, 6 }; + int output1_shape[] = { 1, 2 }; + const float output1_golden[] = { 1, 2 }; + int output2_shape[] = { 1, 2 }; + const float output2_golden[] = { 3, 4 }; + int output3_shape[] = { 1, 2 }; + const float output3_golden[] = { 5, 6 }; + constexpr int output1_dims_count = 2; + constexpr int output2_dims_count = 2; + constexpr int output3_dims_count = 2; + float output1_data[output1_dims_count]; + float output2_data[output2_dims_count]; + float output3_data[output3_dims_count]; + tflite::testing::TestUnpackThreeOutputsFloat( + input_shape, input_values, 0, output1_shape, output1_golden, + output2_shape, output2_golden, output3_shape, output3_golden, + output1_data, output2_data, output3_data); +} + +TF_LITE_MICRO_TEST(UnpackFloatThreeOutputsNegativeAxisTwo) +{ + int input_shape[] = { 2, 3, 2 }; + const float input_values[] = { 1, 2, 3, 4, 5, 6 }; + int output1_shape[] = { 1, 2 }; + const float output1_golden[] = { 1, 2 }; + int output2_shape[] = { 1, 2 }; + const float output2_golden[] = { 3, 4 }; + int output3_shape[] = { 1, 2 }; + const float output3_golden[] = { 5, 6 }; + constexpr int output1_dims_count = 2; + constexpr int output2_dims_count = 2; + constexpr int output3_dims_count = 2; + float output1_data[output1_dims_count]; + float output2_data[output2_dims_count]; + float output3_data[output3_dims_count]; + tflite::testing::TestUnpackThreeOutputsFloat( + input_shape, input_values, -2, output1_shape, output1_golden, + output2_shape, output2_golden, output3_shape, output3_golden, + output1_data, output2_data, output3_data); +} + +TF_LITE_MICRO_TEST(UnpackFloatOneOutput) +{ + int input_shape[] = { 2, 1, 6 }; + const float input_values[] = { 1, 2, 3, 4, 5, 6 }; + int output_shape[] = { 1, 6 }; + const float golden[] = { 1, 2, 3, 4, 5, 6 }; + constexpr int output_dims_count = 6; + float output_data[output_dims_count]; + tflite::testing::TestUnpackOneOutputFloat(input_shape, input_values, 0, + output_shape, golden, output_data); +} + +TF_LITE_MICRO_TEST(UnpackQuantizedThreeOutputs) +{ + int input_shape[] = { 2, 3, 2 }; + const uint8_t input_values[] = { 1, 2, 3, 4, 5, 6 }; + int output1_shape[] = { 1, 2 }; + const uint8_t output1_golden[] = { 1, 2 }; + int output2_shape[] = { 1, 2 }; + const uint8_t output2_golden[] = { 3, 4 }; + int output3_shape[] = { 1, 2 }; + const uint8_t output3_golden[] = { 5, 6 }; + constexpr int output1_dims_count = 2; + constexpr int output2_dims_count = 2; + constexpr int output3_dims_count = 2; + uint8_t output1_data[output1_dims_count]; + uint8_t output2_data[output2_dims_count]; + uint8_t output3_data[output3_dims_count]; + tflite::testing::TestUnpackThreeOutputsQuantized( + input_shape, input_values, 0, output1_shape, output1_golden, + output2_shape, output2_golden, output3_shape, output3_golden, + output1_data, output2_data, output3_data); +} + +TF_LITE_MICRO_TEST(UnpackQuantized32ThreeOutputs) +{ + int input_shape[] = { 2, 3, 2 }; + const int32_t input_values[] = { 1, 2, 3, 4, 5, 6 }; + int output1_shape[] = { 1, 2 }; + const int32_t output1_golden[] = { 1, 2 }; + int output2_shape[] = { 1, 2 }; + const int32_t output2_golden[] = { 3, 4 }; + int output3_shape[] = { 1, 2 }; + const int32_t output3_golden[] = { 5, 6 }; + constexpr int output1_dims_count = 2; + constexpr int output2_dims_count = 2; + constexpr int output3_dims_count = 2; + int32_t output1_data[output1_dims_count]; + int32_t output2_data[output2_dims_count]; + int32_t output3_data[output3_dims_count]; + tflite::testing::TestUnpackThreeOutputsQuantized32( + input_shape, input_values, 0, output1_shape, output1_golden, + output2_shape, output2_golden, output3_shape, output3_golden, + output1_data, output2_data, output3_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/kernels/zeros_like.cc b/components/tflite/tensorflow/lite/micro/kernels/zeros_like.cc new file mode 100644 index 00000000..fef5da01 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/zeros_like.cc @@ -0,0 +1,93 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace { + +constexpr int kInputTensor = 0; +constexpr int kOutputTensor = 0; + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); + TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); + const TfLiteTensor *input; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, kInputTensor, &input)); + TfLiteTensor *output; + TF_LITE_ENSURE_OK(context, + GetOutputSafe(context, node, kOutputTensor, &output)); + output->type = input->type; + + return kTfLiteOk; +} + +template +void resetZeros(T *out, const int num_elements) +{ + for (int i = 0; i < num_elements; ++i) { + out[i] = static_cast(0); + } +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + int flat_size = MatchingFlatSize(tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorShape(output)); + switch (input->type) { + case kTfLiteInt64: + resetZeros(tflite::micro::GetTensorData(output), flat_size); + break; + case kTfLiteInt32: + resetZeros(tflite::micro::GetTensorData(output), flat_size); + break; + case kTfLiteInt8: + resetZeros(tflite::micro::GetTensorData(output), flat_size); + break; + case kTfLiteFloat32: + resetZeros(tflite::micro::GetTensorData(output), flat_size); + break; + default: + TF_LITE_KERNEL_LOG(context, + "ZerosLike only currently supports int64, int32, " + "and float32, got %d.", + input->type); + return kTfLiteError; + } + return kTfLiteOk; +} +} // namespace + +TfLiteRegistration Register_ZEROS_LIKE() +{ + return { /*init=*/nullptr, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/kernels/zeros_like_test.cc b/components/tflite/tensorflow/lite/micro/kernels/zeros_like_test.cc new file mode 100644 index 00000000..88d190c5 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/kernels/zeros_like_test.cc @@ -0,0 +1,106 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/kernels/kernel_runner.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace testing { +namespace { + +template +void TestZerosLike(int *input_dims_data, const T *input_data, + const T *expected_output_data, T *output_data) +{ + TfLiteIntArray *input_dims = IntArrayFromInts(input_dims_data); + TfLiteIntArray *output_dims = IntArrayFromInts(input_dims_data); + const int output_dims_count = ElementCount(*output_dims); + constexpr int inputs_size = 1; + constexpr int outputs_size = 1; + constexpr int tensors_size = inputs_size + outputs_size; + TfLiteTensor tensors[tensors_size] = { + CreateTensor(input_data, input_dims), + CreateTensor(output_data, output_dims), + }; + + int inputs_array_data[] = { 1, 0 }; + TfLiteIntArray *inputs_array = IntArrayFromInts(inputs_array_data); + int outputs_array_data[] = { 1, 1 }; + TfLiteIntArray *outputs_array = IntArrayFromInts(outputs_array_data); + + const TfLiteRegistration registration = Register_ZEROS_LIKE(); + micro::KernelRunner runner(registration, tensors, tensors_size, inputs_array, + outputs_array, + /*builtin_data=*/nullptr); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.InitAndPrepare()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, runner.Invoke()); + + for (int i = 0; i < output_dims_count; ++i) { + TF_LITE_MICRO_EXPECT_EQ(expected_output_data[i], output_data[i]); + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestZerosLikeFloat) +{ + float output_data[6]; + int input_dims[] = { 2, 2, 3 }; + const float input_values[] = { -2.0, -1.0, 0.0, 1.0, 2.0, 3.0 }; + const float golden[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; + tflite::testing::TestZerosLike(input_dims, input_values, golden, + output_data); +} + +TF_LITE_MICRO_TEST(TestZerosLikeInt8) +{ + int8_t output_data[6]; + int input_dims[] = { 3, 1, 2, 3 }; + const int8_t input_values[] = { -2, -1, 0, 1, 2, 3 }; + const int8_t golden[] = { 0, 0, 0, 0, 0, 0 }; + tflite::testing::TestZerosLike(input_dims, input_values, golden, + output_data); +} + +TF_LITE_MICRO_TEST(TestZerosLikeInt32) +{ + int32_t output_data[4]; + int input_dims[] = { 4, 1, 2, 2, 1 }; + const int32_t input_values[] = { -2, -1, 0, 3 }; + const int32_t golden[] = { 0, 0, 0, 0 }; + tflite::testing::TestZerosLike(input_dims, input_values, golden, + output_data); +} + +TF_LITE_MICRO_TEST(TestZerosLikeInt64) +{ + int64_t output_data[4]; + int input_dims[] = { 4, 1, 2, 2, 1 }; + const int64_t input_values[] = { -2, -1, 0, 3 }; + const int64_t golden[] = { 0, 0, 0, 0 }; + tflite::testing::TestZerosLike(input_dims, input_values, golden, + output_data); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/memory_arena_threshold_test.cc b/components/tflite/tensorflow/lite/micro/memory_arena_threshold_test.cc new file mode 100644 index 00000000..1cc8e820 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/memory_arena_threshold_test.cc @@ -0,0 +1,255 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/benchmarks/keyword_scrambled_model_data.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/recording_micro_allocator.h" +#include "tensorflow/lite/micro/recording_micro_interpreter.h" +#include "tensorflow/lite/micro/testing/micro_test.h" +#include "tensorflow/lite/micro/testing/test_conv_model.h" + +/** + * Tests to ensure arena memory allocation does not regress by more than 3%. + */ + +namespace { + +// Ensure memory doesn't expand more that 3%: +constexpr float kAllocationThreshold = 0.03; + +// TODO(b/160617245): Record persistent allocations to provide a more accurate +// number here. +constexpr float kAllocationTailMiscCeiling = 2 * 1024; + +const bool kIs64BitSystem = (sizeof(void *) == 8); + +constexpr int kKeywordModelTensorArenaSize = 22 * 1024; +uint8_t keyword_model_tensor_arena[kKeywordModelTensorArenaSize]; + +constexpr int kKeywordModelTensorCount = 54; +constexpr int kKeywordModelNodeAndRegistrationCount = 15; + +// NOTE: These values are measured on x86-64: +// TODO(b/158651472): Consider auditing these values on non-64 bit systems. +// +// Run this test with '--copt=-DTF_LITE_STATIC_MEMORY' to get optimized memory +// runtime values: +#ifdef TF_LITE_STATIC_MEMORY +constexpr int kKeywordModelTotalSize = 14416; +constexpr int kKeywordModelTailSize = 13744; +constexpr int kKeywordModelPersistentTfLiteTensorDataSize = 128; +constexpr int kKeywordModelPersistentBufferDataSize = 564; +#else +constexpr int kKeywordModelTotalSize = 14992; +constexpr int kKeywordModelTailSize = 14320; +constexpr int kKeywordModelPersistentTfLiteTensorDataSize = 224; +constexpr int kKeywordModelPersistentBufferDataSize = 564; +#endif +constexpr int kKeywordModelHeadSize = 672; +constexpr int kKeywordModelTfLiteTensorVariableBufferDataSize = 10240; +constexpr int kKeywordModelPersistentTfLiteTensorQuantizationData = 64; +constexpr int kKeywordModelOpRuntimeDataSize = 148; + +constexpr int kTestConvModelArenaSize = 12 * 1024; +uint8_t test_conv_tensor_arena[kTestConvModelArenaSize]; + +constexpr int kTestConvModelTensorCount = 15; +constexpr int kTestConvModelNodeAndRegistrationCount = 7; + +// NOTE: These values are measured on x86-64: +// TODO(b/158651472): Consider auditing these values on non-64 bit systems. +#ifdef TF_LITE_STATIC_MEMORY +constexpr int kTestConvModelTotalSize = 9792; +constexpr int kTestConvModelTailSize = 2048; +constexpr int kTestConvModelPersistentTfLiteTensorDataSize = 128; +constexpr int kTestConvModelPersistentBufferDataSize = 680; +#else +constexpr int kTestConvModelTotalSize = 10112; +constexpr int kTestConvModelTailSize = 2368; +constexpr int kTestConvModelPersistentTfLiteTensorDataSize = 224; +constexpr int kTestConvModelPersistentBufferDataSize = 680; +#endif +constexpr int kTestConvModelHeadSize = 7744; +constexpr int kTestConvModelOpRuntimeDataSize = 136; +constexpr int kTestConvModelPersistentTfLiteTensorQuantizationData = 0; + +struct ModelAllocationThresholds { + size_t tensor_count = 0; + size_t node_and_registration_count = 0; + size_t total_alloc_size = 0; + size_t head_alloc_size = 0; + size_t tail_alloc_size = 0; + size_t tensor_variable_buffer_data_size = 0; + size_t persistent_tflite_tensor_data_size = 0; + size_t persistent_tflite_tensor_quantization_data_size = 0; + size_t op_runtime_data_size = 0; + size_t persistent_buffer_data = 0; +}; + +void EnsureAllocatedSizeThreshold(const char *allocation_type, size_t actual, + size_t expected) +{ + // TODO(b/158651472): Better auditing of non-64 bit systems: + if (kIs64BitSystem) { + // 64-bit systems should check floor and ceiling to catch memory savings: + TF_LITE_MICRO_EXPECT_NEAR(actual, expected, + expected * kAllocationThreshold); + if (actual != expected) { + TF_LITE_REPORT_ERROR(tflite::GetMicroErrorReporter(), + "%s threshold failed: %d != %d", allocation_type, + actual, expected); + } + } else { + // Non-64 bit systems should just expect allocation does not exceed the + // ceiling: + TF_LITE_MICRO_EXPECT_LE(actual, expected + expected * kAllocationThreshold); + } +} + +void ValidateModelAllocationThresholds( + const tflite::RecordingMicroAllocator &allocator, + const ModelAllocationThresholds &thresholds) +{ + allocator.PrintAllocations(); + + EnsureAllocatedSizeThreshold( + "Total", allocator.GetSimpleMemoryAllocator()->GetUsedBytes(), + thresholds.total_alloc_size); + EnsureAllocatedSizeThreshold( + "Head", allocator.GetSimpleMemoryAllocator()->GetHeadUsedBytes(), + thresholds.head_alloc_size); + EnsureAllocatedSizeThreshold( + "Tail", allocator.GetSimpleMemoryAllocator()->GetTailUsedBytes(), + thresholds.tail_alloc_size); + EnsureAllocatedSizeThreshold( + "TfLiteEvalTensor", + allocator + .GetRecordedAllocation( + tflite::RecordedAllocationType::kTfLiteEvalTensorData) + .used_bytes, + sizeof(TfLiteEvalTensor) * thresholds.tensor_count); + EnsureAllocatedSizeThreshold( + "VariableBufferData", + allocator + .GetRecordedAllocation( + tflite::RecordedAllocationType::kTfLiteTensorVariableBufferData) + .used_bytes, + thresholds.tensor_variable_buffer_data_size); + EnsureAllocatedSizeThreshold( + "PersistentTfLiteTensor", + allocator + .GetRecordedAllocation( + tflite::RecordedAllocationType::kPersistentTfLiteTensorData) + .used_bytes, + thresholds.persistent_tflite_tensor_data_size); + EnsureAllocatedSizeThreshold( + "PersistentTfliteTensorQuantizationData", + allocator + .GetRecordedAllocation(tflite::RecordedAllocationType:: + kPersistentTfLiteTensorQuantizationData) + .used_bytes, + thresholds.persistent_tflite_tensor_quantization_data_size); + EnsureAllocatedSizeThreshold( + "PersistentBufferData", + allocator + .GetRecordedAllocation( + tflite::RecordedAllocationType::kPersistentBufferData) + .used_bytes, + thresholds.persistent_buffer_data); + EnsureAllocatedSizeThreshold( + "NodeAndRegistration", + allocator + .GetRecordedAllocation( + tflite::RecordedAllocationType::kNodeAndRegistrationArray) + .used_bytes, + sizeof(tflite::NodeAndRegistration) * + thresholds.node_and_registration_count); + + // Ensure tail allocation recording is not missing any large chunks: + size_t tail_est_length = sizeof(TfLiteEvalTensor) * thresholds.tensor_count + + thresholds.tensor_variable_buffer_data_size + + sizeof(tflite::NodeAndRegistration) * + thresholds.node_and_registration_count + + thresholds.op_runtime_data_size; + TF_LITE_MICRO_EXPECT_LE(thresholds.tail_alloc_size - tail_est_length, + kAllocationTailMiscCeiling); +} + +} // namespace + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestKeywordModelMemoryThreshold) +{ + tflite::AllOpsResolver all_ops_resolver; + tflite::RecordingMicroInterpreter interpreter( + tflite::GetModel(g_keyword_scrambled_model_data), all_ops_resolver, + keyword_model_tensor_arena, kKeywordModelTensorArenaSize, + tflite::GetMicroErrorReporter()); + + interpreter.AllocateTensors(); + + ModelAllocationThresholds thresholds; + thresholds.tensor_count = kKeywordModelTensorCount; + thresholds.node_and_registration_count = + kKeywordModelNodeAndRegistrationCount; + thresholds.total_alloc_size = kKeywordModelTotalSize; + thresholds.head_alloc_size = kKeywordModelHeadSize; + thresholds.tail_alloc_size = kKeywordModelTailSize; + thresholds.tensor_variable_buffer_data_size = + kKeywordModelTfLiteTensorVariableBufferDataSize; + thresholds.op_runtime_data_size = kKeywordModelOpRuntimeDataSize; + thresholds.persistent_buffer_data = kKeywordModelPersistentBufferDataSize; + thresholds.persistent_tflite_tensor_data_size = + kKeywordModelPersistentTfLiteTensorDataSize; + thresholds.persistent_tflite_tensor_quantization_data_size = + kKeywordModelPersistentTfLiteTensorQuantizationData; + + ValidateModelAllocationThresholds(interpreter.GetMicroAllocator(), + thresholds); +} + +TF_LITE_MICRO_TEST(TestConvModelMemoryThreshold) +{ + tflite::AllOpsResolver all_ops_resolver; + tflite::RecordingMicroInterpreter interpreter( + tflite::GetModel(kTestConvModelData), all_ops_resolver, + test_conv_tensor_arena, kTestConvModelArenaSize, + tflite::GetMicroErrorReporter()); + + interpreter.AllocateTensors(); + + ModelAllocationThresholds thresholds; + thresholds.tensor_count = kTestConvModelTensorCount; + thresholds.node_and_registration_count = + kTestConvModelNodeAndRegistrationCount; + thresholds.total_alloc_size = kTestConvModelTotalSize; + thresholds.head_alloc_size = kTestConvModelHeadSize; + thresholds.tail_alloc_size = kTestConvModelTailSize; + thresholds.op_runtime_data_size = kTestConvModelOpRuntimeDataSize; + thresholds.persistent_buffer_data = kTestConvModelPersistentBufferDataSize; + thresholds.persistent_tflite_tensor_data_size = + kTestConvModelPersistentTfLiteTensorDataSize; + thresholds.persistent_tflite_tensor_quantization_data_size = + kTestConvModelPersistentTfLiteTensorQuantizationData; + + ValidateModelAllocationThresholds(interpreter.GetMicroAllocator(), + thresholds); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/memory_helpers.cc b/components/tflite/tensorflow/lite/micro/memory_helpers.cc new file mode 100644 index 00000000..15ba6370 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/memory_helpers.cc @@ -0,0 +1,174 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/memory_helpers.h" + +#include +#include + +#include "flatbuffers/flatbuffers.h" // from @flatbuffers +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/core/api/error_reporter.h" +#include "tensorflow/lite/core/api/flatbuffer_conversions.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/schema/schema_generated.h" + +namespace tflite { + +uint8_t *AlignPointerUp(uint8_t *data, size_t alignment) +{ + std::uintptr_t data_as_uintptr_t = reinterpret_cast(data); + uint8_t *aligned_result = reinterpret_cast( + ((data_as_uintptr_t + (alignment - 1)) / alignment) * alignment); + return aligned_result; +} + +uint8_t *AlignPointerDown(uint8_t *data, size_t alignment) +{ + std::uintptr_t data_as_uintptr_t = reinterpret_cast(data); + uint8_t *aligned_result = + reinterpret_cast((data_as_uintptr_t / alignment) * alignment); + return aligned_result; +} + +size_t AlignSizeUp(size_t size, size_t alignment) +{ + size_t aligned_size = (((size + (alignment - 1)) / alignment) * alignment); + return aligned_size; +} + +TfLiteStatus TfLiteTypeSizeOf(TfLiteType type, size_t *size) +{ + switch (type) { + case kTfLiteFloat16: + *size = sizeof(int16_t); + break; + case kTfLiteFloat32: + *size = sizeof(float); + break; + case kTfLiteFloat64: + *size = sizeof(double); + break; + case kTfLiteInt16: + *size = sizeof(int16_t); + break; + case kTfLiteInt32: + *size = sizeof(int32_t); + break; + case kTfLiteUInt32: + *size = sizeof(uint32_t); + break; + case kTfLiteUInt8: + *size = sizeof(uint8_t); + break; + case kTfLiteInt8: + *size = sizeof(int8_t); + break; + case kTfLiteInt64: + *size = sizeof(int64_t); + break; + case kTfLiteUInt64: + *size = sizeof(uint64_t); + break; + case kTfLiteBool: + *size = sizeof(bool); + break; + case kTfLiteComplex64: + *size = sizeof(float) * 2; + break; + case kTfLiteComplex128: + *size = sizeof(double) * 2; + break; + default: + return kTfLiteError; + } + return kTfLiteOk; +} + +TfLiteStatus BytesRequiredForTensor(const tflite::Tensor &flatbuffer_tensor, + size_t *bytes, size_t *type_size, + ErrorReporter *error_reporter) +{ + int element_count = 1; + // If flatbuffer_tensor.shape == nullptr, then flatbuffer_tensor is a scalar + // so has 1 element. + if (flatbuffer_tensor.shape() != nullptr) { + for (size_t n = 0; n < flatbuffer_tensor.shape()->Length(); ++n) { + element_count *= flatbuffer_tensor.shape()->Get(n); + } + } + + TfLiteType tf_lite_type; + TF_LITE_ENSURE_STATUS(ConvertTensorType(flatbuffer_tensor.type(), + &tf_lite_type, error_reporter)); + TF_LITE_ENSURE_STATUS(TfLiteTypeSizeOf(tf_lite_type, type_size)); + *bytes = element_count * (*type_size); + return kTfLiteOk; +} + +TfLiteStatus TfLiteEvalTensorByteLength(const TfLiteEvalTensor *eval_tensor, + size_t *out_bytes) +{ + TFLITE_DCHECK(out_bytes != nullptr); + + int element_count = 1; + // If eval_tensor->dims == nullptr, then tensor is a scalar so has 1 element. + if (eval_tensor->dims != nullptr) { + for (int n = 0; n < eval_tensor->dims->size; ++n) { + element_count *= eval_tensor->dims->data[n]; + } + } + size_t type_size; + TF_LITE_ENSURE_STATUS(TfLiteTypeSizeOf(eval_tensor->type, &type_size)); + *out_bytes = element_count * type_size; + return kTfLiteOk; +} + +TfLiteStatus AllocateOutputDimensionsFromInput(TfLiteContext *context, + const TfLiteTensor *input1, + const TfLiteTensor *input2, + TfLiteTensor *output) +{ + const TfLiteTensor *input = nullptr; + + TF_LITE_ENSURE(context, input1->dims != nullptr); + TF_LITE_ENSURE(context, input2->dims != nullptr); + TF_LITE_ENSURE(context, output->dims->size == 0); + + input = input1->dims->size > input2->dims->size ? input1 : input2; + TF_LITE_ENSURE(context, output->type == input->type); + + size_t size = 0; + TfLiteTypeSizeOf(input->type, &size); + const int dimensions_count = tflite::GetTensorShape(input).DimensionsCount(); + for (int i = 0; i < dimensions_count; i++) { + size *= input->dims->data[i]; + } + + output->bytes = size; + + output->dims = + reinterpret_cast(context->AllocatePersistentBuffer( + context, TfLiteIntArrayGetSizeInBytes(size))); + + output->dims->size = input->dims->size; + for (int i = 0; i < dimensions_count; i++) { + output->dims->data[i] = input->dims->data[i]; + } + + return kTfLiteOk; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/memory_helpers.h b/components/tflite/tensorflow/lite/micro/memory_helpers.h new file mode 100644 index 00000000..1ce9ca31 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/memory_helpers.h @@ -0,0 +1,58 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_MICRO_MEMORY_HELPERS_H_ +#define TENSORFLOW_LITE_MICRO_MEMORY_HELPERS_H_ + +#include +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/core/api/error_reporter.h" +#include "tensorflow/lite/schema/schema_generated.h" + +namespace tflite { +// Returns the next pointer address aligned to the given alignment. +uint8_t *AlignPointerUp(uint8_t *data, size_t alignment); + +// Returns the previous pointer address aligned to the given alignment. +uint8_t *AlignPointerDown(uint8_t *data, size_t alignment); + +// Returns an increased size that's a multiple of alignment. +size_t AlignSizeUp(size_t size, size_t alignment); + +// Returns size in bytes for a given TfLiteType. +TfLiteStatus TfLiteTypeSizeOf(TfLiteType type, size_t *size); + +// How many bytes are needed to hold a tensor's contents. +TfLiteStatus BytesRequiredForTensor(const tflite::Tensor &flatbuffer_tensor, + size_t *bytes, size_t *type_size, + ErrorReporter *error_reporter); + +// How many bytes are used in a TfLiteEvalTensor instance. The byte length is +// returned in out_bytes. +TfLiteStatus TfLiteEvalTensorByteLength(const TfLiteEvalTensor *eval_tensor, + size_t *out_bytes); + +// Deduce output dimensions from input and allocate given size. +// Useful for operators with two inputs where the largest input should equal the +// output dimension. +TfLiteStatus AllocateOutputDimensionsFromInput(TfLiteContext *context, + const TfLiteTensor *input1, + const TfLiteTensor *input2, + TfLiteTensor *output); + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_MEMORY_HELPERS_H_ diff --git a/components/tflite/tensorflow/lite/micro/memory_helpers_test.cc b/components/tflite/tensorflow/lite/micro/memory_helpers_test.cc new file mode 100644 index 00000000..48080916 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/memory_helpers_test.cc @@ -0,0 +1,240 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/memory_helpers.h" + +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace { + +// This just needs to be big enough to handle the array of 5 ints allocated +// in TestAllocateOutputDimensionsFromInput below. +const int kGlobalPersistentBufferLength = 100; +char global_persistent_buffer[kGlobalPersistentBufferLength]; + +// Only need to handle a single allocation at a time for output dimensions +// in TestAllocateOutputDimensionsFromInput. +void *FakeAllocatePersistentBuffer(TfLiteContext *context, size_t bytes) +{ + return reinterpret_cast(global_persistent_buffer); +} + +} // namespace + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestAlignPointerUp) +{ + uint8_t *input0 = reinterpret_cast(0); + + uint8_t *input0_aligned1 = tflite::AlignPointerUp(input0, 1); + TF_LITE_MICRO_EXPECT(input0 == input0_aligned1); + + uint8_t *input0_aligned2 = tflite::AlignPointerUp(input0, 2); + TF_LITE_MICRO_EXPECT(input0 == input0_aligned2); + + uint8_t *input0_aligned3 = tflite::AlignPointerUp(input0, 3); + TF_LITE_MICRO_EXPECT(input0 == input0_aligned3); + + uint8_t *input0_aligned16 = tflite::AlignPointerUp(input0, 16); + TF_LITE_MICRO_EXPECT(input0 == input0_aligned16); + + uint8_t *input23 = reinterpret_cast(23); + + uint8_t *input23_aligned1 = tflite::AlignPointerUp(input23, 1); + TF_LITE_MICRO_EXPECT(input23 == input23_aligned1); + + uint8_t *input23_aligned2 = tflite::AlignPointerUp(input23, 2); + uint8_t *expected23_aligned2 = reinterpret_cast(24); + TF_LITE_MICRO_EXPECT(expected23_aligned2 == input23_aligned2); + + uint8_t *input23_aligned3 = tflite::AlignPointerUp(input23, 3); + uint8_t *expected23_aligned3 = reinterpret_cast(24); + TF_LITE_MICRO_EXPECT(expected23_aligned3 == input23_aligned3); + + uint8_t *input23_aligned16 = tflite::AlignPointerUp(input23, 16); + uint8_t *expected23_aligned16 = reinterpret_cast(32); + TF_LITE_MICRO_EXPECT(expected23_aligned16 == input23_aligned16); +} + +TF_LITE_MICRO_TEST(TestAlignPointerDown) +{ + uint8_t *input0 = reinterpret_cast(0); + + uint8_t *input0_aligned1 = tflite::AlignPointerDown(input0, 1); + TF_LITE_MICRO_EXPECT(input0 == input0_aligned1); + + uint8_t *input0_aligned2 = tflite::AlignPointerDown(input0, 2); + TF_LITE_MICRO_EXPECT(input0 == input0_aligned2); + + uint8_t *input0_aligned3 = tflite::AlignPointerDown(input0, 3); + TF_LITE_MICRO_EXPECT(input0 == input0_aligned3); + + uint8_t *input0_aligned16 = tflite::AlignPointerDown(input0, 16); + TF_LITE_MICRO_EXPECT(input0 == input0_aligned16); + + uint8_t *input23 = reinterpret_cast(23); + + uint8_t *input23_aligned1 = tflite::AlignPointerDown(input23, 1); + TF_LITE_MICRO_EXPECT(input23 == input23_aligned1); + + uint8_t *input23_aligned2 = tflite::AlignPointerDown(input23, 2); + uint8_t *expected23_aligned2 = reinterpret_cast(22); + TF_LITE_MICRO_EXPECT(expected23_aligned2 == input23_aligned2); + + uint8_t *input23_aligned3 = tflite::AlignPointerDown(input23, 3); + uint8_t *expected23_aligned3 = reinterpret_cast(21); + TF_LITE_MICRO_EXPECT(expected23_aligned3 == input23_aligned3); + + uint8_t *input23_aligned16 = tflite::AlignPointerDown(input23, 16); + uint8_t *expected23_aligned16 = reinterpret_cast(16); + TF_LITE_MICRO_EXPECT(expected23_aligned16 == input23_aligned16); +} + +TF_LITE_MICRO_TEST(TestAlignSizeUp) +{ + TF_LITE_MICRO_EXPECT_EQ(static_cast(1), tflite::AlignSizeUp(1, 1)); + TF_LITE_MICRO_EXPECT_EQ(static_cast(2), tflite::AlignSizeUp(1, 2)); + TF_LITE_MICRO_EXPECT_EQ(static_cast(3), tflite::AlignSizeUp(1, 3)); + TF_LITE_MICRO_EXPECT_EQ(static_cast(16), tflite::AlignSizeUp(1, 16)); + + TF_LITE_MICRO_EXPECT_EQ(static_cast(23), tflite::AlignSizeUp(23, 1)); + TF_LITE_MICRO_EXPECT_EQ(static_cast(24), tflite::AlignSizeUp(23, 2)); + TF_LITE_MICRO_EXPECT_EQ(static_cast(24), tflite::AlignSizeUp(23, 3)); + TF_LITE_MICRO_EXPECT_EQ(static_cast(32), tflite::AlignSizeUp(23, 16)); +} + +TF_LITE_MICRO_TEST(TestTypeSizeOf) +{ + size_t size; + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + tflite::TfLiteTypeSizeOf(kTfLiteFloat16, &size)); + TF_LITE_MICRO_EXPECT_EQ(sizeof(int16_t), size); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + tflite::TfLiteTypeSizeOf(kTfLiteFloat32, &size)); + TF_LITE_MICRO_EXPECT_EQ(sizeof(float), size); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + tflite::TfLiteTypeSizeOf(kTfLiteFloat64, &size)); + TF_LITE_MICRO_EXPECT_EQ(sizeof(double), size); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + tflite::TfLiteTypeSizeOf(kTfLiteInt16, &size)); + TF_LITE_MICRO_EXPECT_EQ(sizeof(int16_t), size); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + tflite::TfLiteTypeSizeOf(kTfLiteInt32, &size)); + TF_LITE_MICRO_EXPECT_EQ(sizeof(int32_t), size); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + tflite::TfLiteTypeSizeOf(kTfLiteUInt32, &size)); + TF_LITE_MICRO_EXPECT_EQ(sizeof(uint32_t), size); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + tflite::TfLiteTypeSizeOf(kTfLiteUInt8, &size)); + TF_LITE_MICRO_EXPECT_EQ(sizeof(uint8_t), size); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + tflite::TfLiteTypeSizeOf(kTfLiteInt8, &size)); + TF_LITE_MICRO_EXPECT_EQ(sizeof(int8_t), size); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + tflite::TfLiteTypeSizeOf(kTfLiteInt64, &size)); + TF_LITE_MICRO_EXPECT_EQ(sizeof(int64_t), size); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + tflite::TfLiteTypeSizeOf(kTfLiteUInt64, &size)); + TF_LITE_MICRO_EXPECT_EQ(sizeof(uint64_t), size); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + tflite::TfLiteTypeSizeOf(kTfLiteBool, &size)); + TF_LITE_MICRO_EXPECT_EQ(sizeof(bool), size); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + tflite::TfLiteTypeSizeOf(kTfLiteComplex64, &size)); + TF_LITE_MICRO_EXPECT_EQ(sizeof(float) * 2, size); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + tflite::TfLiteTypeSizeOf(kTfLiteComplex128, &size)); + TF_LITE_MICRO_EXPECT_EQ(sizeof(double) * 2, size); + + TF_LITE_MICRO_EXPECT_NE( + kTfLiteOk, tflite::TfLiteTypeSizeOf(static_cast(-1), &size)); +} + +TF_LITE_MICRO_TEST(TestBytesRequiredForTensor) +{ + const tflite::Tensor *tensor100 = + tflite::testing::Create1dFlatbufferTensor(100); + size_t bytes; + size_t type_size; + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, tflite::BytesRequiredForTensor( + *tensor100, &bytes, &type_size, + tflite::GetMicroErrorReporter())); + TF_LITE_MICRO_EXPECT_EQ(static_cast(400), bytes); + TF_LITE_MICRO_EXPECT_EQ(static_cast(4), type_size); + + const tflite::Tensor *tensor200 = + tflite::testing::Create1dFlatbufferTensor(200); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, tflite::BytesRequiredForTensor( + *tensor200, &bytes, &type_size, + tflite::GetMicroErrorReporter())); + TF_LITE_MICRO_EXPECT_EQ(static_cast(800), bytes); + TF_LITE_MICRO_EXPECT_EQ(static_cast(4), type_size); +} + +TF_LITE_MICRO_TEST(TestAllocateOutputDimensionsFromInput) +{ + constexpr int kDimsLen = 4; + int input1_dims[] = { 1, 1 }; + int input2_dims[] = { kDimsLen, 5, 5, 5, 5 }; + int output_dims[] = { 0, 0, 0, 0, 0 }; + TfLiteTensor input_tensor1 = tflite::testing::CreateTensor( + nullptr, tflite::testing::IntArrayFromInts(input1_dims)); + TfLiteTensor input_tensor2 = tflite::testing::CreateTensor( + nullptr, tflite::testing::IntArrayFromInts(input2_dims)); + TfLiteTensor output_tensor = tflite::testing::CreateTensor( + nullptr, tflite::testing::IntArrayFromInts(output_dims)); + TfLiteContext context; + // Only need to allocate space for output_tensor.dims. Use a simple + // fake allocator. + context.AllocatePersistentBuffer = FakeAllocatePersistentBuffer; + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, tflite::AllocateOutputDimensionsFromInput( + &context, &input_tensor1, &input_tensor2, &output_tensor)); + + TF_LITE_MICRO_EXPECT_EQ(output_tensor.bytes, input_tensor2.bytes); + for (int i = 0; i < kDimsLen; i++) { + TF_LITE_MICRO_EXPECT_EQ(input_tensor2.dims->data[i], + output_tensor.dims->data[i]); + // Reset output dims for next iteration. + output_tensor.dims->data[i] = 0; + } + // Output tensor size must be 0 to allocate output dimensions from input. + output_tensor.dims->size = 0; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, tflite::AllocateOutputDimensionsFromInput( + &context, &input_tensor2, &input_tensor1, &output_tensor)); + for (int i = 0; i < kDimsLen; i++) { + TF_LITE_MICRO_EXPECT_EQ(input_tensor2.dims->data[i], + output_tensor.dims->data[i]); + } + TF_LITE_MICRO_EXPECT_EQ(output_tensor.bytes, input_tensor2.bytes); +} +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/memory_planner/greedy_memory_planner.cc b/components/tflite/tensorflow/lite/micro/memory_planner/greedy_memory_planner.cc new file mode 100644 index 00000000..6531c51d --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/memory_planner/greedy_memory_planner.cc @@ -0,0 +1,462 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/memory_planner/greedy_memory_planner.h" + +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/micro_string.h" + +namespace tflite { + +namespace { + +// Returns a character representing a numbered buffer +// for GreedyMemoryPlanner::PrintMemoryPlan() +char GetOrdinalCharacter(int i) +{ + if (i < 10) { + return '0' + i; + } else if (i < 36) { + return 'a' + (i - 10); + } else if (i < 62) { + return 'A' + (i - 36); + } + return '*'; +} + +} // namespace + +// Simple stable in-place sort function. Not time-efficient for large arrays. +// Would normally be in an anonymous namespace to keep it private, but we want +// to be able to test it externally. +void ReverseSortInPlace(int *values, int *ids, int size) +{ + bool any_swapped; + do { + any_swapped = false; + for (int i = 1; i < size; ++i) { + if (values[i - 1] < values[i]) { + const int value_temp = values[i - 1]; + values[i - 1] = values[i]; + values[i] = value_temp; + const int id_temp = ids[i - 1]; + ids[i - 1] = ids[i]; + ids[i] = id_temp; + any_swapped = true; + } + } + } while (any_swapped); +} + +GreedyMemoryPlanner::GreedyMemoryPlanner(unsigned char *scratch_buffer, + int scratch_buffer_size) + : buffer_count_(0), need_to_calculate_offsets_(true) +{ + // Allocate the arrays we need within the scratch buffer arena. + max_buffer_count_ = scratch_buffer_size / per_buffer_size(); + + unsigned char *next_free = scratch_buffer; + requirements_ = reinterpret_cast(next_free); + next_free += sizeof(BufferRequirements) * max_buffer_count_; + + buffer_sizes_sorted_ = reinterpret_cast(next_free); + next_free += sizeof(int) * max_buffer_count_; + + buffer_ids_sorted_ = reinterpret_cast(next_free); + next_free += sizeof(int) * max_buffer_count_; + + buffers_sorted_by_offset_ = reinterpret_cast(next_free); + next_free += sizeof(ListEntry) * max_buffer_count_; + + buffer_offsets_ = reinterpret_cast(next_free); +} + +GreedyMemoryPlanner::~GreedyMemoryPlanner() +{ + // We don't own the scratch buffer, so don't deallocate anything. +} + +TfLiteStatus GreedyMemoryPlanner::AddBuffer( + tflite::ErrorReporter *error_reporter, int size, int first_time_used, + int last_time_used) +{ + if (buffer_count_ >= max_buffer_count_) { + TF_LITE_REPORT_ERROR(error_reporter, "Too many buffers (max is %d)", + max_buffer_count_); + return kTfLiteError; + } + BufferRequirements *current = &requirements_[buffer_count_]; + current->size = size; + current->first_time_used = first_time_used; + current->last_time_used = last_time_used; + current->offline_offset = kOnlinePlannedBuffer; + ++buffer_count_; + need_to_calculate_offsets_ = true; + return kTfLiteOk; +} + +TfLiteStatus GreedyMemoryPlanner::AddBuffer( + tflite::ErrorReporter *error_reporter, int size, int first_time_used, + int last_time_used, int offline_offset) +{ + BufferRequirements *current = &requirements_[buffer_count_]; + if (AddBuffer(error_reporter, size, first_time_used, last_time_used) != + kTfLiteOk) { + return kTfLiteError; + } + current->offline_offset = offline_offset; + return kTfLiteOk; +} + +bool GreedyMemoryPlanner::DoesEntryOverlapInTime( + const GreedyMemoryPlanner::ListEntry *entry, const int first_time_used, + const int last_time_used) const +{ + const BufferRequirements *entry_requirements = + &requirements_[entry->requirements_index]; + if (entry_requirements->first_time_used > last_time_used) { + return false; + } + if (first_time_used > entry_requirements->last_time_used) { + return false; + } + return true; +} + +GreedyMemoryPlanner::ListEntry * +GreedyMemoryPlanner::NextSimultaneouslyActiveBuffer( + const GreedyMemoryPlanner::ListEntry *start, const int first_time_used, + const int last_time_used) +{ + ListEntry *result = nullptr; + ListEntry *candidate_next_entry; + if (start == nullptr) { + candidate_next_entry = &buffers_sorted_by_offset_[first_entry_index_]; + } else { + if (start->next_entry_index == -1) { + return nullptr; + } + candidate_next_entry = &buffers_sorted_by_offset_[start->next_entry_index]; + } + do { + if (DoesEntryOverlapInTime(candidate_next_entry, first_time_used, + last_time_used)) { + result = candidate_next_entry; + break; + } + if (candidate_next_entry->next_entry_index == -1) { + break; + } + candidate_next_entry = + &buffers_sorted_by_offset_[candidate_next_entry->next_entry_index]; + } while (true); + return result; +} + +void GreedyMemoryPlanner::CalculateOffsetsIfNeeded() +{ + if (!need_to_calculate_offsets_ || (buffer_count_ == 0)) { + return; + } + need_to_calculate_offsets_ = false; + + // Start off by ordering the buffers in descending order of size. + // This helps find a more compact layout. Intuitively, you can think + // about putting the large buffers in place first, and then the + // smaller buffers can fit in the gaps, rather than fragmenting the + // gaps with small buffers at the beginning. Add offline planned offsets + // first in the list, since they have a predetermined offset. + int idx_from_tail = buffer_count_; + int idx_from_head = 0; + for (int i = 0; i < buffer_count_; ++i) { + if (requirements_[i].offline_offset == kOnlinePlannedBuffer) { + idx_from_tail--; + buffer_sizes_sorted_[idx_from_tail] = requirements_[i].size; + buffer_ids_sorted_[idx_from_tail] = i; + buffer_offsets_[i] = -1; + } else { + buffer_sizes_sorted_[idx_from_head] = requirements_[i].size; + buffer_ids_sorted_[idx_from_head] = i; + buffer_offsets_[i] = requirements_[i].offline_offset; + idx_from_head++; + } + } + + // This sorting algorithm is naive, and may end up taking a very long time + // with hundreds of buffers. Do not sort the offline planned offsets. + ReverseSortInPlace(&buffer_sizes_sorted_[idx_from_head], + &buffer_ids_sorted_[idx_from_head], + buffer_count_ - idx_from_head); + + // Initialize the first entry to the first buffer in + // buffer_ids_sorted_. + // - If there are no offline planned offsets, the largest buffer will be + // first, and the buffers will be handled in size order. + // - If offline offsets are present, these will be handled first in order + // for the greedy algorithm to utilized gaps in the offline plan. + first_entry_index_ = 0; + next_free_entry_ = 1; + ListEntry *first_entry = &buffers_sorted_by_offset_[first_entry_index_]; + first_entry->next_entry_index = -1; // to mark the entry as end of list + int buffer_id = buffer_ids_sorted_[0]; + first_entry->requirements_index = buffer_id; + if (requirements_[buffer_id].offline_offset == kOnlinePlannedBuffer) { + buffer_offsets_[buffer_id] = 0; + } + first_entry->offset = buffer_offsets_[buffer_id]; + + // Work through the rest of the buffers to find a good gap to place each one. + for (int i = 1; i < buffer_count_; ++i) { + // The id is the order the buffer was originally added by the client. + buffer_id = buffer_ids_sorted_[i]; + // Look at what size and time range the buffer needs to be active. + BufferRequirements *wanted_requirements = &requirements_[buffer_id]; + const int wanted_size = wanted_requirements->size; + const int wanted_first_time_used = wanted_requirements->first_time_used; + const int wanted_last_time_used = wanted_requirements->last_time_used; + + // Find the first buffer that's active in our time range. All placed + // buffers are stored in the order of their starting position in the arena + // so that it's easy to find the next buffer in memory, and so the gap. + // The candidate_entry variable holds the buffer that we're considering + // placing the current buffer after. + + int candidate_offset = 0; + // Loop through the offset-ordered list of buffers, looking for gaps. + if (wanted_requirements->offline_offset == kOnlinePlannedBuffer) { + ListEntry *prior_entry = nullptr; + while (true) { + // Find out what the next active buffer is. + ListEntry *next_entry = NextSimultaneouslyActiveBuffer( + prior_entry, wanted_first_time_used, wanted_last_time_used); + + if (prior_entry) { + BufferRequirements *candidate_requirements = + &requirements_[prior_entry->requirements_index]; + const int prior_entry_offset = + prior_entry->offset + candidate_requirements->size; + if (prior_entry_offset > candidate_offset) { + candidate_offset = prior_entry_offset; + } + } + if (next_entry == nullptr) { + // We're at the end of the list, so we can always append the buffer + // here. + break; + } + // Find out how much space there is between us and the next buffer. + const int gap = next_entry->offset - candidate_offset; + if (gap >= wanted_size) { + // This entry has a big enough gap between it and the next, so + // use it! + break; + } + // The gap wasn't big enough, so move on to another candidate. + prior_entry = next_entry; + } + } else { + // Offline planned offset are to be considered constant + candidate_offset = wanted_requirements->offline_offset; + } + // At this point, we've either found a gap (possibly at the end of the + // list) and want to place the buffer there, or there are no other active + // buffers in this time range and so we can put it at offset zero. + // Record the buffer's offset in our plan. + buffer_offsets_[buffer_id] = candidate_offset; + // Add the newly-placed buffer to our offset-ordered list, so that + // subsequent passes can fit in their buffers around it. + ListEntry *new_entry = &buffers_sorted_by_offset_[next_free_entry_]; + new_entry->offset = candidate_offset; + new_entry->requirements_index = buffer_id; + const int new_entry_index = next_free_entry_; + ++next_free_entry_; + + if (first_entry->offset > candidate_offset) { + // The new entry offset is smaller than the first entry offset => + // replace the first entry + first_entry = new_entry; + first_entry->next_entry_index = first_entry_index_; + first_entry_index_ = new_entry_index; + } else { + ListEntry *current_entry = first_entry; + // Make sure that we insert the buffer at the correct place in the + // buffer-offset-ordered list + while (true) { + const int next_entry_index = current_entry->next_entry_index; + if (next_entry_index == -1) { + // We're at the end of the list, so just add the new entry here. + current_entry->next_entry_index = new_entry_index; + new_entry->next_entry_index = -1; + break; + } + // not at the end of the list -> take a look at next entry + ListEntry *next_entry = &buffers_sorted_by_offset_[next_entry_index]; + if (next_entry->offset > candidate_offset) { + // We're at the right spot to do an insertion and retain the sorting + // order, so place the new entry here. + new_entry->next_entry_index = current_entry->next_entry_index; + current_entry->next_entry_index = new_entry_index; + break; + } + current_entry = next_entry; + } + } + } +} + +size_t GreedyMemoryPlanner::GetMaximumMemorySize() +{ + CalculateOffsetsIfNeeded(); + if (buffer_count_ == 0) { + return 0; + } + ListEntry *entry = &buffers_sorted_by_offset_[first_entry_index_]; + size_t max_size = 0; + while (entry) { + BufferRequirements *requirements = + &requirements_[entry->requirements_index]; + const size_t current_size = entry->offset + requirements->size; + if (current_size > max_size) { + max_size = current_size; + } + if (entry->next_entry_index == -1) { + break; + } + entry = &buffers_sorted_by_offset_[entry->next_entry_index]; + } + return max_size; +} + +void GreedyMemoryPlanner::PrintMemoryPlan() +{ + CalculateOffsetsIfNeeded(); + + for (int i = 0; i < buffer_count_; ++i) { + MicroPrintf("%c (id=%d): size=%d, offset=%d, first_used=%d last_used=%d", + GetOrdinalCharacter(i), i, requirements_[i].size, + buffer_offsets_[i], requirements_[i].first_time_used, + requirements_[i].last_time_used); + } + + constexpr int kLineWidth = 80; + int max_size = kLineWidth; + int max_time = 0; + for (int i = 0; i < buffer_count_; ++i) { + BufferRequirements *requirements = &requirements_[i]; + const int offset = buffer_offsets_[i]; + const int last_time_used = requirements->last_time_used; + const int size = offset + requirements->size; + if (size > max_size) { + max_size = size; + } + if (last_time_used > max_time) { + max_time = last_time_used; + } + } + + char line[kLineWidth + 1]; + for (int t = 0; t <= max_time; ++t) { + for (int c = 0; c < kLineWidth; ++c) { + line[c] = '.'; + } + int memory_use = 0; + for (int i = 0; i < buffer_count_; ++i) { + BufferRequirements *requirements = &requirements_[i]; + if ((t < requirements->first_time_used) || + (t > requirements->last_time_used)) { + continue; + } + const int offset = buffer_offsets_[i]; + if (offset == -1) { + continue; + } + const int size = requirements->size; + memory_use += size; + const int line_start = (offset * kLineWidth) / max_size; + const int line_end = ((offset + size) * kLineWidth) / max_size; + for (int n = line_start; n < line_end; ++n) { + if (line[n] == '.') { + line[n] = GetOrdinalCharacter(i); + } else { + line[n] = '!'; + } + } + } + line[kLineWidth] = 0; + + MicroPrintf("%s%d: %s (%dk)", t < 10 ? " " : "", t, (const char *)line, + (memory_use + 1023) / 1024); + } +} + +int GreedyMemoryPlanner::GetBufferCount() +{ + return buffer_count_; +} + +TfLiteStatus GreedyMemoryPlanner::GetOffsetForBuffer( + tflite::ErrorReporter *error_reporter, int buffer_index, int *offset) +{ + CalculateOffsetsIfNeeded(); + if ((buffer_index < 0) || (buffer_index >= buffer_count_)) { + TF_LITE_REPORT_ERROR(error_reporter, + "buffer index %d is outside range 0 to %d", + buffer_index, buffer_count_); + return kTfLiteError; + } + *offset = buffer_offsets_[buffer_index]; + return kTfLiteOk; +} + +bool GreedyMemoryPlanner::DoAnyBuffersOverlap(ErrorReporter *error_reporter) +{ + CalculateOffsetsIfNeeded(); + bool were_overlaps_found = false; + for (int i = 0; i < buffer_count_; ++i) { + BufferRequirements *a_requirements = &requirements_[i]; + const int a_start_offset = buffer_offsets_[i]; + const int a_first_time_used = a_requirements->first_time_used; + const int a_last_time_used = a_requirements->last_time_used; + const int a_end_offset = a_start_offset + a_requirements->size; + for (int j = 0; j < buffer_count_; ++j) { + if (i == j) { + continue; + } + BufferRequirements *b_requirements = &requirements_[j]; + const int b_start_offset = buffer_offsets_[j]; + const int b_first_time_used = b_requirements->first_time_used; + const int b_last_time_used = b_requirements->last_time_used; + const int b_end_offset = b_start_offset + b_requirements->size; + if ((a_first_time_used > b_last_time_used) || + (b_first_time_used > a_last_time_used)) { + // Buffers don't overlap in time. + continue; + } + if ((a_start_offset >= b_end_offset) || + (b_start_offset >= a_end_offset)) { + // No overlap in memory. + continue; + } + were_overlaps_found = true; + TF_LITE_REPORT_ERROR( + error_reporter, "Overlap: %d (%d=>%d, %d->%d) vs %d (%d=>%d, %d->%d)", + i, a_first_time_used, a_last_time_used, a_start_offset, a_end_offset, + j, b_first_time_used, b_last_time_used, b_start_offset, b_end_offset); + } + } + return were_overlaps_found; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/memory_planner/greedy_memory_planner.h b/components/tflite/tensorflow/lite/micro/memory_planner/greedy_memory_planner.h new file mode 100644 index 00000000..f5c764a0 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/memory_planner/greedy_memory_planner.h @@ -0,0 +1,163 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_MEMORY_PLANNER_GREEDY_MEMORY_PLANNER_H_ +#define TENSORFLOW_LITE_MICRO_MEMORY_PLANNER_GREEDY_MEMORY_PLANNER_H_ + +#include "tensorflow/lite/micro/compatibility.h" +#include "tensorflow/lite/micro/memory_planner/memory_planner.h" + +namespace tflite { +constexpr int kOnlinePlannedBuffer = -1; + +// A memory planner that uses a greedy algorithm to arrange buffers in memory +// to minimize the overall arena size needed. +// +// The algorithm works like this: +// - The client enters the buffer information through AddBuffer(). +// - When a function like GetOffsetForBuffer() is called, the +// CalculateOffsetsIfNeeded() method is invoked. +// - If an up to date plan is not already present, one will be calculated. +// - The buffers are sorted in descending order of size. +// - The largest buffer is placed at offset zero. +// - The rest of the buffers are looped through in descending size order. +// - The other buffers that need to be in memory at the same time are found. +// - The first gap between simultaneously active buffers that the current +// buffer fits into will be used. +// - If no large-enough gap is found, the current buffer is placed after the +// last buffer that's simultaneously active. +// - This continues until all buffers are placed, and the offsets stored. +// +// This is not guaranteed to produce the best placement, since that's an +// NP-Complete problem, but in practice it should produce one that's decent. +class GreedyMemoryPlanner : public MemoryPlanner { +public: + // You need to pass in an area of memory to be used for planning. This memory + // needs to have a lifetime as long as the planner, but isn't owned by this + // object, so management should be handled by the client. This is so it can be + // stack or globally allocated if necessary on devices without dynamic memory + // allocation. How many buffers can be planned for will depend on the size of + // this scratch memory, so you should enlarge it if you see an error when + // calling AddBuffer(). The memory can be reused once you're done with the + // planner, as long as you copy the calculated offsets to another location. + // Each buffer requires about 36 bytes of scratch. + GreedyMemoryPlanner(unsigned char *scratch_buffer, int scratch_buffer_size); + ~GreedyMemoryPlanner() override; + + // Record details of a buffer we want to place. + TfLiteStatus AddBuffer(ErrorReporter *error_reporter, int size, + int first_time_used, int last_time_used) override; + + // Record details of an offline planned buffer offset we want to place. + // offline_offset is the buffer offset from the start of the arena. + TfLiteStatus AddBuffer(ErrorReporter *error_reporter, int size, + int first_time_used, int last_time_used, + int offline_offset); + + // Returns the high-water mark of used memory. This is the minimum size of a + // memory arena you'd need to allocate to hold these buffers. + size_t GetMaximumMemorySize() override; + + // How many buffers have been recorded. + int GetBufferCount() override; + + // Where a given buffer should be placed in the memory arena. + // This information is stored in the memory arena itself, so once the arena + // is used for inference, it will be overwritten. + TfLiteStatus GetOffsetForBuffer(ErrorReporter *error_reporter, + int buffer_index, int *offset) override; + + // Prints an ascii-art diagram of the buffer layout plan. + void PrintMemoryPlan(); + + // Debug method to check whether any buffer allocations are overlapping. This + // is an O(N^2) complexity operation, so only use for testing. + bool DoAnyBuffersOverlap(ErrorReporter *error_reporter); + + // Used to store a list of buffers ordered by their offset. + struct ListEntry { + int offset; + int requirements_index; + int next_entry_index; + }; + + // Number of bytes required in order to plan a buffer. + static size_t per_buffer_size() + { + const int per_buffer_size = + sizeof(BufferRequirements) + // requirements_ + sizeof(int) + // buffer_sizes_sorted_ + sizeof(int) + // buffer_ids_sorted_ + sizeof(ListEntry) + // buffers_sorted_by_offset_ + sizeof(int); // buffer_offsets_; + return per_buffer_size; + } + +private: + // Whether a buffer is active in a given time range. + bool DoesEntryOverlapInTime(const ListEntry *entry, const int first_time_used, + const int last_time_used) const; + + // Walks the list to return the next buffer that is active in a given time + // range, or a null pointer if there are none. + ListEntry *NextSimultaneouslyActiveBuffer(const ListEntry *start, + const int first_time_used, + const int last_time_used); + + // If there isn't an up to date plan, calculate a new one. + void CalculateOffsetsIfNeeded(); + + // How many buffers we can plan for, based on the arena size we're given in + // the constructor. + int max_buffer_count_; + + // The number of buffers added so far. + int buffer_count_; + + // Records the client-provided information about each buffer. + struct BufferRequirements { + int size; + int offline_offset; + int first_time_used; + int last_time_used; + }; + + // Working arrays used during the layout algorithm. + BufferRequirements *requirements_; + // buffer_sizes_sorted_ and buffer_ids_sorted_ are sorted according to: + // { + // offline planned buffers, + // online planned buffers sorted by size + // } + int *buffer_sizes_sorted_; + int *buffer_ids_sorted_; + ListEntry *buffers_sorted_by_offset_; + int next_free_entry_; // Index of the next free entry of + // buffers_sorted_by_offset_ + int first_entry_index_; // Index of the first entry (smallest offset) of + // buffers_sorted_by_offset_ + + // Stores the outcome of the plan, the location of each buffer in the arena. + int *buffer_offsets_; + + // Whether buffers have been added since the last plan was calculated. + bool need_to_calculate_offsets_; + + TF_LITE_REMOVE_VIRTUAL_DELETE +}; + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_MEMORY_PLANNER_GREEDY_MEMORY_PLANNER_H_ diff --git a/components/tflite/tensorflow/lite/micro/memory_planner/greedy_memory_planner_test.cc b/components/tflite/tensorflow/lite/micro/memory_planner/greedy_memory_planner_test.cc new file mode 100644 index 00000000..1ab73416 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/memory_planner/greedy_memory_planner_test.cc @@ -0,0 +1,283 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/memory_planner/greedy_memory_planner.h" + +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +// We don't declare this in the header since it's not a public interface, but we +// need to call it to test it, so declare it here instead. +void ReverseSortInPlace(int *values, int *ids, int size); +} // namespace tflite + +namespace { +constexpr int kScratchBufferSize = 4096; +unsigned char g_scratch_buffer[kScratchBufferSize]; +} // namespace + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestReverseSortInPlace) +{ + tflite::MicroErrorReporter micro_error_reporter; + + constexpr int a_size = 10; + int a_values[a_size] = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; + int a_ids[a_size] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + const int a_expected_values[a_size] = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; + const int a_expected_ids[a_size] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + tflite::ReverseSortInPlace(a_values, a_ids, a_size); + for (int i = 0; i < a_size; ++i) { + TF_LITE_MICRO_EXPECT_EQ(a_expected_values[i], a_values[i]); + TF_LITE_MICRO_EXPECT_EQ(a_expected_ids[i], a_ids[i]); + } + + constexpr int b_size = 10; + int b_values[b_size] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + int b_ids[b_size] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + const int b_expected_values[b_size] = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; + const int b_expected_ids[b_size] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; + tflite::ReverseSortInPlace(b_values, b_ids, b_size); + for (int i = 0; i < b_size; ++i) { + TF_LITE_MICRO_EXPECT_EQ(b_expected_values[i], b_values[i]); + TF_LITE_MICRO_EXPECT_EQ(b_expected_ids[i], b_ids[i]); + } + + constexpr int c_size = 100; + int c_values[c_size] = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 + }; + int c_ids[c_size] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, + 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, + 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, + 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99 + }; + const int c_expected_values[c_size] = { + 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 + }; + const int c_expected_ids[c_size] = { + 9, 19, 29, 39, 49, 59, 69, 79, 89, 99, 8, 18, 28, 38, 48, 58, 68, + 78, 88, 98, 7, 17, 27, 37, 47, 57, 67, 77, 87, 97, 6, 16, 26, 36, + 46, 56, 66, 76, 86, 96, 5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 4, + 14, 24, 34, 44, 54, 64, 74, 84, 94, 3, 13, 23, 33, 43, 53, 63, 73, + 83, 93, 2, 12, 22, 32, 42, 52, 62, 72, 82, 92, 1, 11, 21, 31, 41, + 51, 61, 71, 81, 91, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90 + }; + tflite::ReverseSortInPlace(c_values, c_ids, c_size); + for (int i = 0; i < c_size; ++i) { + TF_LITE_MICRO_EXPECT_EQ(c_expected_values[i], c_values[i]); + TF_LITE_MICRO_EXPECT_EQ(c_expected_ids[i], c_ids[i]); + } +} + +TF_LITE_MICRO_TEST(TestGreedyBasics) +{ + tflite::MicroErrorReporter micro_error_reporter; + + tflite::GreedyMemoryPlanner planner(g_scratch_buffer, kScratchBufferSize); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + planner.AddBuffer(µ_error_reporter, 10, 0, 1)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + planner.AddBuffer(µ_error_reporter, 20, 2, 3)); + + TF_LITE_MICRO_EXPECT_EQ(false, + planner.DoAnyBuffersOverlap(µ_error_reporter)); + + TF_LITE_MICRO_EXPECT_EQ(static_cast(20), + planner.GetMaximumMemorySize()); + + int offset = -1; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.GetOffsetForBuffer(µ_error_reporter, 0, &offset)); + TF_LITE_MICRO_EXPECT_EQ(0, offset); + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.GetOffsetForBuffer(µ_error_reporter, 1, &offset)); + TF_LITE_MICRO_EXPECT_EQ(0, offset); +} + +TF_LITE_MICRO_TEST(TestGreedyMedium) +{ + tflite::MicroErrorReporter micro_error_reporter; + + tflite::GreedyMemoryPlanner planner(g_scratch_buffer, kScratchBufferSize); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + planner.AddBuffer(µ_error_reporter, 10, 0, 1)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + planner.AddBuffer(µ_error_reporter, 20, 1, 2)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + planner.AddBuffer(µ_error_reporter, 30, 2, 3)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + planner.AddBuffer(µ_error_reporter, 40, 3, 4)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + planner.AddBuffer(µ_error_reporter, 50, 0, 1)); + + int offset = -1; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.GetOffsetForBuffer(µ_error_reporter, 0, &offset)); + TF_LITE_MICRO_EXPECT_EQ(50, offset); + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.GetOffsetForBuffer(µ_error_reporter, 1, &offset)); + TF_LITE_MICRO_EXPECT_EQ(70, offset); + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.GetOffsetForBuffer(µ_error_reporter, 2, &offset)); + TF_LITE_MICRO_EXPECT_EQ(40, offset); + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.GetOffsetForBuffer(µ_error_reporter, 3, &offset)); + TF_LITE_MICRO_EXPECT_EQ(0, offset); + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.GetOffsetForBuffer(µ_error_reporter, 4, &offset)); + TF_LITE_MICRO_EXPECT_EQ(0, offset); + + planner.PrintMemoryPlan(); + + TF_LITE_MICRO_EXPECT_EQ(false, + planner.DoAnyBuffersOverlap(µ_error_reporter)); + + TF_LITE_MICRO_EXPECT_EQ(static_cast(90), + planner.GetMaximumMemorySize()); +} + +TF_LITE_MICRO_TEST(TestPersonDetectionModel) +{ + tflite::MicroErrorReporter micro_error_reporter; + + tflite::GreedyMemoryPlanner planner(g_scratch_buffer, kScratchBufferSize); + // These buffer sizes and time ranges are taken from the 250KB MobileNet model + // used in the person detection example. + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 9216, 0, 29)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + planner.AddBuffer(µ_error_reporter, 3, 28, 29)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 256, 27, 28)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 2304, 26, 27)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 2304, 25, 26)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 2304, 24, 25)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 1152, 23, 24)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 4608, 22, 23)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 4608, 21, 22)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 4608, 20, 21)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 4608, 19, 20)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 4608, 18, 19)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 4608, 17, 18)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 4608, 16, 17)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 4608, 15, 16)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 4608, 14, 15)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 4608, 13, 14)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 4608, 12, 13)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 2304, 11, 12)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 9216, 10, 11)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 9216, 9, 10)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + planner.AddBuffer(µ_error_reporter, 9216, 8, 9)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + planner.AddBuffer(µ_error_reporter, 4608, 7, 8)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 18432, 6, 7)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 18432, 5, 6)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 18432, 4, 5)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + planner.AddBuffer(µ_error_reporter, 9216, 3, 4)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 36864, 2, 3)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 18432, 1, 2)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 18432, 0, 1)); + + planner.PrintMemoryPlan(); + + TF_LITE_MICRO_EXPECT_EQ(false, + planner.DoAnyBuffersOverlap(µ_error_reporter)); + + // The sum of all the buffers is 241,027 bytes, so we at least expect the plan + // to come up with something smaller than this. + TF_LITE_MICRO_EXPECT_GT(static_cast(241027), + planner.GetMaximumMemorySize()); +} + +TF_LITE_MICRO_TEST(TestOverlapCase) +{ + tflite::MicroErrorReporter micro_error_reporter; + + tflite::GreedyMemoryPlanner planner(g_scratch_buffer, kScratchBufferSize); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + planner.AddBuffer(µ_error_reporter, 100, 0, 1)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + planner.AddBuffer(µ_error_reporter, 50, 2, 3)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + planner.AddBuffer(µ_error_reporter, 20, 1, 2)); + + planner.PrintMemoryPlan(); + + TF_LITE_MICRO_EXPECT_EQ(false, + planner.DoAnyBuffersOverlap(µ_error_reporter)); + + TF_LITE_MICRO_EXPECT_EQ(static_cast(120), + planner.GetMaximumMemorySize()); +} + +TF_LITE_MICRO_TEST(TestSmallScratch) +{ + tflite::MicroErrorReporter micro_error_reporter; + + constexpr int scratch_buffer_size = 40; + unsigned char scratch_buffer[scratch_buffer_size]; + tflite::GreedyMemoryPlanner planner(scratch_buffer, scratch_buffer_size); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + planner.AddBuffer(µ_error_reporter, 100, 0, 1)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteError, + planner.AddBuffer(µ_error_reporter, 50, 2, 3)); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/memory_planner/linear_memory_planner.cc b/components/tflite/tensorflow/lite/micro/memory_planner/linear_memory_planner.cc new file mode 100644 index 00000000..16a7ddab --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/memory_planner/linear_memory_planner.cc @@ -0,0 +1,66 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/memory_planner/linear_memory_planner.h" + +namespace tflite { + +LinearMemoryPlanner::LinearMemoryPlanner() + : current_buffer_count_(0), next_free_offset_(0) +{ +} +LinearMemoryPlanner::~LinearMemoryPlanner() +{ +} + +TfLiteStatus LinearMemoryPlanner::AddBuffer( + tflite::ErrorReporter *error_reporter, int size, int first_time_used, + int last_time_used) +{ + if (current_buffer_count_ >= kMaxBufferCount) { + TF_LITE_REPORT_ERROR(error_reporter, "Too many buffers (max is %d)", + kMaxBufferCount); + return kTfLiteError; + } + buffer_offsets_[current_buffer_count_] = next_free_offset_; + next_free_offset_ += size; + ++current_buffer_count_; + return kTfLiteOk; +} + +size_t LinearMemoryPlanner::GetMaximumMemorySize() +{ + return next_free_offset_; +} + +int LinearMemoryPlanner::GetBufferCount() +{ + return current_buffer_count_; +} + +TfLiteStatus LinearMemoryPlanner::GetOffsetForBuffer( + tflite::ErrorReporter *error_reporter, int buffer_index, int *offset) +{ + if ((buffer_index < 0) || (buffer_index >= current_buffer_count_)) { + TF_LITE_REPORT_ERROR(error_reporter, + "buffer index %d is outside range 0 to %d", + buffer_index, current_buffer_count_); + return kTfLiteError; + } + *offset = buffer_offsets_[buffer_index]; + return kTfLiteOk; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/memory_planner/linear_memory_planner.h b/components/tflite/tensorflow/lite/micro/memory_planner/linear_memory_planner.h new file mode 100644 index 00000000..8973d97e --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/memory_planner/linear_memory_planner.h @@ -0,0 +1,49 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_MEMORY_PLANNER_LINEAR_MEMORY_PLANNER_H_ +#define TENSORFLOW_LITE_MICRO_MEMORY_PLANNER_LINEAR_MEMORY_PLANNER_H_ + +#include "tensorflow/lite/micro/compatibility.h" +#include "tensorflow/lite/micro/memory_planner/memory_planner.h" + +namespace tflite { +// The simplest possible memory planner that just lays out all buffers at +// increasing offsets without trying to reuse memory. +class LinearMemoryPlanner : public MemoryPlanner { +public: + LinearMemoryPlanner(); + ~LinearMemoryPlanner() override; + + TfLiteStatus AddBuffer(tflite::ErrorReporter *error_reporter, int size, + int first_time_used, int last_time_used) override; + + size_t GetMaximumMemorySize() override; + int GetBufferCount() override; + TfLiteStatus GetOffsetForBuffer(tflite::ErrorReporter *error_reporter, + int buffer_index, int *offset) override; + +private: + static constexpr int kMaxBufferCount = 1024; + size_t buffer_offsets_[kMaxBufferCount]; + int current_buffer_count_; + size_t next_free_offset_; + + TF_LITE_REMOVE_VIRTUAL_DELETE +}; + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_MEMORY_PLANNER_LINEAR_MEMORY_PLANNER_H_ diff --git a/components/tflite/tensorflow/lite/micro/memory_planner/linear_memory_planner_test.cc b/components/tflite/tensorflow/lite/micro/memory_planner/linear_memory_planner_test.cc new file mode 100644 index 00000000..92d5642e --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/memory_planner/linear_memory_planner_test.cc @@ -0,0 +1,127 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/memory_planner/linear_memory_planner.h" + +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestBasics) +{ + tflite::MicroErrorReporter micro_error_reporter; + + tflite::LinearMemoryPlanner planner; + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + planner.AddBuffer(µ_error_reporter, 10, 0, 1)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + planner.AddBuffer(µ_error_reporter, 20, 1, 2)); + TF_LITE_MICRO_EXPECT_EQ(static_cast(30), + planner.GetMaximumMemorySize()); + + int offset = -1; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.GetOffsetForBuffer(µ_error_reporter, 0, &offset)); + TF_LITE_MICRO_EXPECT_EQ(0, offset); + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.GetOffsetForBuffer(µ_error_reporter, 1, &offset)); + TF_LITE_MICRO_EXPECT_EQ(10, offset); +} + +TF_LITE_MICRO_TEST(TestErrorHandling) +{ + tflite::MicroErrorReporter micro_error_reporter; + + tflite::LinearMemoryPlanner planner; + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + planner.AddBuffer(µ_error_reporter, 10, 0, 1)); + + int offset = -1; + TF_LITE_MICRO_EXPECT_EQ(kTfLiteError, planner.GetOffsetForBuffer( + µ_error_reporter, 1, &offset)); +} + +TF_LITE_MICRO_TEST(TestPersonDetectionModel) +{ + tflite::MicroErrorReporter micro_error_reporter; + + tflite::LinearMemoryPlanner planner; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 9216, 0, 29)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + planner.AddBuffer(µ_error_reporter, 3, 28, 29)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 256, 27, 28)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 2304, 26, 27)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 2304, 25, 26)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 2304, 24, 25)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 1152, 23, 24)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 4608, 22, 23)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 4608, 21, 22)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 4608, 20, 21)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 4608, 19, 20)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 4608, 18, 19)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 4608, 17, 18)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 4608, 16, 17)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 4608, 15, 16)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 4608, 14, 15)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 4608, 13, 14)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 4608, 12, 13)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 2304, 11, 12)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 9216, 10, 11)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 9216, 9, 10)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + planner.AddBuffer(µ_error_reporter, 9216, 8, 9)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + planner.AddBuffer(µ_error_reporter, 4608, 7, 8)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 18432, 6, 7)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 18432, 5, 6)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 18432, 4, 5)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + planner.AddBuffer(µ_error_reporter, 9216, 3, 4)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 36864, 2, 3)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 18432, 1, 2)); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, planner.AddBuffer(µ_error_reporter, 18432, 0, 1)); + TF_LITE_MICRO_EXPECT_EQ(static_cast(241027), + planner.GetMaximumMemorySize()); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/memory_planner/memory_planner.h b/components/tflite/tensorflow/lite/micro/memory_planner/memory_planner.h new file mode 100644 index 00000000..c0f2b51e --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/memory_planner/memory_planner.h @@ -0,0 +1,74 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_MEMORY_PLANNER_MEMORY_PLANNER_H_ +#define TENSORFLOW_LITE_MICRO_MEMORY_PLANNER_MEMORY_PLANNER_H_ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/core/api/error_reporter.h" + +namespace tflite { +// Interface class for planning the layout of memory buffers during the +// execution of a graph. +// It's designed to be used by a client that iterates in any order through the +// buffers it wants to lay out, and then calls the getter functions for +// information about the calculated layout. For example: +// +// SomeMemoryPlanner planner; +// planner.AddBuffer(reporter, 100, 0, 1); // Buffer 0 +// planner.AddBuffer(reporter, 50, 2, 3); // Buffer 1 +// planner.AddBuffer(reporter, 50, 2, 3); // Buffer 2 +// +// int offset0; +// TF_EXPECT_OK(planner.GetOffsetForBuffer(reporter, 0, &offset0)); +// int offset1; +// TF_EXPECT_OK(planner.GetOffsetForBuffer(reporter, 1, &offset1)); +// int offset2; +// TF_EXPECT_OK(planner.GetOffsetForBuffer(reporter, 2, &offset2)); +// const int arena_size_needed = planner.GetMaximumMemorySize(); +// +// The goal is for applications to be able to experiment with different layout +// strategies without changing their client code, by swapping out classes that +// implement this interface.= +class MemoryPlanner { +public: + MemoryPlanner() + { + } + virtual ~MemoryPlanner() + { + } + + // Pass information about a buffer's size and lifetime to the layout + // algorithm. The order this is called implicitly assigns an index to the + // result, so the buffer information that's passed into the N-th call of + // this method will be used as the buffer_index argument to + // GetOffsetForBuffer(). + virtual TfLiteStatus AddBuffer(tflite::ErrorReporter *error_reporter, + int size, int first_time_used, + int last_time_used) = 0; + + // The largest contiguous block of memory that's needed to hold the layout. + virtual size_t GetMaximumMemorySize() = 0; + // How many buffers have been added to the planner. + virtual int GetBufferCount() = 0; + // Calculated layout offset for the N-th buffer added to the planner. + virtual TfLiteStatus GetOffsetForBuffer(tflite::ErrorReporter *error_reporter, + int buffer_index, int *offset) = 0; +}; + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_MEMORY_PLANNER_MEMORY_PLANNER_H_ diff --git a/components/tflite/tensorflow/lite/micro/micro_allocator.cc b/components/tflite/tensorflow/lite/micro/micro_allocator.cc new file mode 100644 index 00000000..d89f80d2 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_allocator.cc @@ -0,0 +1,1115 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/micro_allocator.h" + +#include +#include + +#include "flatbuffers/flatbuffers.h" // from @flatbuffers +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/core/api/error_reporter.h" +#include "tensorflow/lite/core/api/flatbuffer_conversions.h" +#include "tensorflow/lite/core/api/op_resolver.h" +#include "tensorflow/lite/core/api/tensor_utils.h" +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/micro/compatibility.h" +#include "tensorflow/lite/micro/memory_helpers.h" +#include "tensorflow/lite/micro/memory_planner/greedy_memory_planner.h" +#include "tensorflow/lite/micro/memory_planner/memory_planner.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/simple_memory_allocator.h" +#include "tensorflow/lite/schema/schema_generated.h" +#include "tensorflow/lite/schema/schema_utils.h" + +namespace tflite { + +namespace { + +// Maximum number of scratch buffer requests per operator. Operator kernels that +// request more than this value will receive an exception. +constexpr size_t kMaxScratchBuffersPerOp = 12; + +// Sentinel value used as a placeholder to mark a ScratchBufferRequest request +// needs a node id assignment. +constexpr int kUnassignedScratchBufferRequestIndex = -1; + +// Used to hold information used during allocation calculations. +struct AllocationInfo { + size_t bytes; + void **output_ptr; + int first_created; + int last_used; + int32_t offline_offset; + bool needs_allocating; +}; + +// We align tensor buffers to 16-byte boundaries, since this is a common +// requirement for SIMD extensions. +constexpr int kBufferAlignment = 16; +constexpr char kOfflineMemAllocMetadata[] = "OfflineMemoryAllocation"; +const TfLiteIntArray kZeroLengthIntArray = {}; + +class MicroBuiltinDataAllocator : public BuiltinDataAllocator { +public: + explicit MicroBuiltinDataAllocator(SimpleMemoryAllocator *memory_allocator) + : memory_allocator_(memory_allocator) + { + } + + void *Allocate(size_t size, size_t alignment_hint) override + { + return memory_allocator_->AllocateFromTail(size, alignment_hint); + } + void Deallocate(void *data) override + { + // Do not deallocate, builtin data needs to be available for the life time + // of the model. + } + +private: + SimpleMemoryAllocator *memory_allocator_; + + TF_LITE_REMOVE_VIRTUAL_DELETE +}; + +#if !defined(__clang__) +// Helper function to check flatbuffer metadata correctness. This function is +// not called by default. Hence it's not linked in to the final binary code. +TfLiteStatus CheckOfflinePlannedOffsets(const Model *model, + ErrorReporter *error_reporter) +{ + // Suppress compile warning for unused function + (void)CheckOfflinePlannedOffsets; + + if (model->metadata()) { + for (size_t i = 0; i < model->metadata()->size(); ++i) { + auto metadata = model->metadata()->Get(i); + if (strncmp(metadata->name()->c_str(), kOfflineMemAllocMetadata, + strlen(kOfflineMemAllocMetadata)) == 0) { + auto *subgraphs = model->subgraphs(); + const SubGraph *subgraph = (*subgraphs)[0]; + const flatbuffers::Vector > *tensors = + subgraph->tensors(); + const flatbuffers::Vector > *buffers = + model->buffers(); + int nbr_tflite_tensors = tensors->size(); + auto *buffer = (*buffers)[metadata->buffer()]; + auto *array = buffer->data(); + const uint32_t *metadata_buffer = (uint32_t *)array->data(); + int version = metadata_buffer[0]; + int subgraph_idx = metadata_buffer[1]; + const int nbr_offline_offsets = metadata_buffer[2]; +#ifndef TF_LITE_STRIP_ERROR_STRINGS + int *offline_planner_offsets = (int *)&metadata_buffer[3]; +#endif + + TF_LITE_REPORT_ERROR(error_reporter, "==== Model metadata info: ====="); + TF_LITE_REPORT_ERROR(error_reporter, + "Offline planner metadata found, version %d, " + "subgraph %d, nbr offline offsets %d", + version, subgraph_idx, nbr_offline_offsets); + for (int j = 0; j < nbr_offline_offsets; ++j) { + TF_LITE_REPORT_ERROR( + error_reporter, + "Offline planner tensor index %d, offline offset: %d", j, + offline_planner_offsets[j]); + } + + if (version != 1) { + TF_LITE_REPORT_ERROR(error_reporter, "Version not supported! (%d)\n", + version); + return kTfLiteError; + } + if (subgraph_idx != 0) { + TF_LITE_REPORT_ERROR(error_reporter, + "Only 1 subgraph supported! Subgraph idx (%d)\n", + subgraph_idx); + return kTfLiteError; + } + if (nbr_tflite_tensors != nbr_offline_offsets) { + TF_LITE_REPORT_ERROR(error_reporter, + "Nbr of offline buffer offsets (%d) in metadata " + "not equal nbr tensors (%d)\n", + nbr_offline_offsets, nbr_tflite_tensors); + return kTfLiteError; + } + } + } + } + return kTfLiteOk; +} +#endif + +// A helper class to construct AllocationInfo array. This array contains the +// lifetime of tensors / scratch_buffer and will be used to calculate the memory +// plan. Methods need to be called in order from `Init`, `Add*`, to `Finish`. +class AllocationInfoBuilder { +public: + AllocationInfoBuilder(AllocationInfo *info, size_t tensor_count, + size_t scratch_buffer_count, ErrorReporter *reporter) + : info_(info), + tensor_count_(tensor_count), + buffer_count_(scratch_buffer_count), + reporter_(reporter) + { + } + + // Check if model contains offline planned buffer offsets. + // - If there's no metadata available, offline_planner_offsets is not set + // - If there's metadata available, offline_planner_offsets will point to the + // first offset in the metadata buffer list. + TfLiteStatus GetOfflinePlannedOffsets( + const Model *model, const int32_t **offline_planner_offsets); + + // Add allocaiton information for the tensors. + TfLiteStatus AddTensors(const SubGraph *subgraph, + const int32_t *offline_offsets, + TfLiteEvalTensor *eval_tensors); + + // Add allocation information for the scratch buffers. + TfLiteStatus AddScratchBuffers( + internal::ScratchBufferRequest *scratch_buffer_requests, + ScratchBufferHandle *scratch_buffer_handles); + + // Returns a pointer to the built AllocationInfo array. + const AllocationInfo *Finish() const + { + return info_; + } + +private: + AllocationInfo *info_ = nullptr; + size_t tensor_count_ = 0; + size_t buffer_count_ = 0; + ErrorReporter *reporter_ = nullptr; +}; + +TfLiteStatus AllocationInfoBuilder::AddTensors(const SubGraph *subgraph, + const int32_t *offline_offsets, + TfLiteEvalTensor *eval_tensors) +{ + TFLITE_DCHECK(eval_tensors != nullptr); + + // Set up allocation info for all tensors. + for (size_t i = 0; i < tensor_count_; ++i) { + AllocationInfo *current = &info_[i]; + current->output_ptr = &(eval_tensors[i].data.data); + + TF_LITE_ENSURE_STATUS( + TfLiteEvalTensorByteLength(&eval_tensors[i], ¤t->bytes)); + + current->first_created = -1; + current->last_used = -1; + current->needs_allocating = (eval_tensors[i].data.data == nullptr) && + (!subgraph->tensors()->Get(i)->is_variable()); + if (offline_offsets) { + current->offline_offset = offline_offsets[i]; + } else { + current->offline_offset = kOnlinePlannedBuffer; + } + } + + for (size_t i = 0; i < subgraph->inputs()->size(); ++i) { + const int tensor_index = subgraph->inputs()->Get(i); + AllocationInfo *current = &info_[tensor_index]; + current->first_created = 0; + } + + // Mark all outputs as persistent to the end of the invocation. + for (size_t i = 0; i < subgraph->outputs()->size(); ++i) { + const int tensor_index = subgraph->outputs()->Get(i); + AllocationInfo *current = &info_[tensor_index]; + current->last_used = subgraph->operators()->size() - 1; + } + + // Figure out when the first and last use of each tensor is. + for (int i = (subgraph->operators()->size() - 1); i >= 0; --i) { + const auto *op = subgraph->operators()->Get(i); + for (size_t n = 0; n < op->inputs()->size(); ++n) { + const int tensor_index = op->inputs()->Get(n); + AllocationInfo *current = &info_[tensor_index]; + if (((current->last_used == -1) || (current->last_used < i))) { + current->last_used = i; + } + } + for (size_t n = 0; n < op->outputs()->size(); ++n) { + const int tensor_index = op->outputs()->Get(n); + AllocationInfo *current = &info_[tensor_index]; + if ((current->first_created == -1) || (current->first_created > i)) { + current->first_created = i; + } + } + } + return kTfLiteOk; +} + +// Get offline tensors allocation plan. See +// micro/docs/memory_management.md for more info. +TfLiteStatus AllocationInfoBuilder::GetOfflinePlannedOffsets( + const Model *model, const int32_t **offline_planner_offsets) +{ + if (model->metadata()) { + for (size_t i = 0; i < model->metadata()->size(); ++i) { + auto metadata = model->metadata()->Get(i); + if (strncmp(metadata->name()->c_str(), kOfflineMemAllocMetadata, + strlen(kOfflineMemAllocMetadata)) == 0) { + const flatbuffers::Vector > *buffers = + model->buffers(); + auto *buffer = (*buffers)[metadata->buffer()]; + auto *array = buffer->data(); + const uint32_t *metadata_buffer = + reinterpret_cast(array->data()); + const size_t nbr_tensors = static_cast(metadata_buffer[2]); + *offline_planner_offsets = + reinterpret_cast(&metadata_buffer[3]); + + if (tensor_count_ != nbr_tensors) { + TF_LITE_REPORT_ERROR(reporter_, + "Nbr of offline buffer offsets (%d) in metadata " + "not equal nbr tensors (%d)\n", + nbr_tensors, tensor_count_); + return kTfLiteError; + } + } + } + } + return kTfLiteOk; +} + +TfLiteStatus AllocationInfoBuilder::AddScratchBuffers( + internal::ScratchBufferRequest *scratch_buffer_requests, + ScratchBufferHandle *scratch_buffer_handles) +{ + // Set up allocation info for buffers. + for (size_t i = tensor_count_; i < tensor_count_ + buffer_count_; ++i) { + internal::ScratchBufferRequest *current_request = + &(scratch_buffer_requests[i - tensor_count_]); + ScratchBufferHandle *current_handle = + &(scratch_buffer_handles[i - tensor_count_]); + + AllocationInfo *current = &info_[i]; + current->output_ptr = reinterpret_cast(¤t_handle->data); + current->bytes = current_request->bytes; + current->first_created = current_request->node_idx; + current->last_used = current_request->node_idx; + current->offline_offset = kOnlinePlannedBuffer; + current->needs_allocating = true; + } + return kTfLiteOk; +} + +TfLiteStatus CreatePlan(ErrorReporter *error_reporter, + GreedyMemoryPlanner *planner, + const AllocationInfo *allocation_info, + size_t allocation_info_size) +{ + // Add the tensors to our allocation plan. + for (size_t i = 0; i < allocation_info_size; ++i) { + const AllocationInfo *current = &allocation_info[i]; + if (current->needs_allocating) { + size_t aligned_bytes_required = + AlignSizeUp(current->bytes, kBufferAlignment); + if (current->offline_offset == kOnlinePlannedBuffer) { + TF_LITE_ENSURE_STATUS( + planner->AddBuffer(error_reporter, aligned_bytes_required, + current->first_created, current->last_used)); + } else { + TF_LITE_ENSURE_STATUS(planner->AddBuffer( + error_reporter, aligned_bytes_required, current->first_created, + current->last_used, current->offline_offset)); + } + } + } + return kTfLiteOk; +} + +TfLiteStatus CommitPlan(ErrorReporter *error_reporter, MemoryPlanner *planner, + uint8_t *starting_point, + const AllocationInfo *allocation_info, + size_t allocation_info_size) +{ + // Figure out the actual memory addresses for each buffer, based on the plan. + int planner_index = 0; + for (size_t i = 0; i < allocation_info_size; ++i) { + const AllocationInfo *current = &allocation_info[i]; + if (current->needs_allocating) { + int offset = -1; + TF_LITE_ENSURE_STATUS( + planner->GetOffsetForBuffer(error_reporter, planner_index, &offset)); + *current->output_ptr = reinterpret_cast(starting_point + offset); + ++planner_index; + } + } + return kTfLiteOk; +} +} // namespace + +namespace internal { + +// Handles architecture safe mapping of flatbuffer vectors to a TfLite*Array +// struct. Matching types are required (e.g. float and TfLiteFloatArray). +// Big-endian systems will always allocate dimension array data in the tail +// (persistent) section. +template +TfLiteStatus FlatBufferVectorToTfLiteTypeArray( + SimpleMemoryAllocator *allocator, ErrorReporter *error_reporter, + const flatbuffers::Vector *flatbuffer_array, + kTfLiteArrayType **result) +{ + TFLITE_DCHECK(error_reporter != nullptr); + TFLITE_DCHECK(flatbuffer_array != nullptr); + // TODO(b/159668691): Consider adding type assertion or breaking this function + // into multiple functions for each type. std::is_same is c++11 and has a + // special updated constructor in c++17 that requires a string argument. + if (FLATBUFFERS_LITTLEENDIAN) { + // On little-endian machines, TfLite*Array happens to have the same memory + // layout as flatbuffers:Vector, so we can + // reinterpret_cast the flatbuffer vector and avoid a copy and malloc. + *result = const_cast( + reinterpret_cast(flatbuffer_array)); + } else { + // Big-endian architecture can not use the same memory layout as + // flatbuffers::Vector. Allocate from the tail and + // copy values from the flatbuffer into the newly allocated chunk. + kTfLiteArrayType *array = + reinterpret_cast(allocator->AllocateFromTail( + TfLiteIntArrayGetSizeInBytes(flatbuffer_array->Length()), + alignof(kTfLiteArrayType))); + if (array == nullptr) { + TF_LITE_REPORT_ERROR( + error_reporter, + "Failed to allocate %d bytes of memory to copy an array.", + TfLiteIntArrayGetSizeInBytes(flatbuffer_array->Length())); + return kTfLiteError; + } + array->size = flatbuffer_array->Length(); + for (int i = 0; i < array->size; ++i) { + array->data[i] = flatbuffer_array->Get(i); + } + *result = array; + } + return kTfLiteOk; +} + +// Returns a pointer to any buffer associated with the flatbuffer tensor. Can +// return nullptr if no buffer is found. +void *GetFlatbufferTensorBuffer( + const tflite::Tensor &flatbuffer_tensor, + const flatbuffers::Vector > *buffers) +{ + // We need to figure out where the actual contents of this tensor are stored + // in memory. We'll check to see if there's a serialized buffer (pretty much + // the same as a constant op in TensorFlow) associated with this tensor first, + // and if there is update the runtime structure to point to its location in + // memory. + // First see if there's any buffer information in the serialized tensor. + // TODO(b/170379532): Add better unit tests to validate flatbuffer values. + void *out_buffer = nullptr; + if (auto *buffer = (*buffers)[flatbuffer_tensor.buffer()]) { + // If we've found a buffer, does it have any data? + if (auto *array = buffer->data()) { + // If it has any data, is the data size larger than zero? + if (array->size()) { + // We've found a buffer with valid data, so update the runtime tensor + // data structure to point to it. + out_buffer = const_cast(static_cast(array->data())); + } + } + // TODO(petewarden): It's not clear in what circumstances we could have a + // buffer in the serialized tensor, but it doesn't have any data in it. Is + // that a validly-generated file, and if so what does it mean, or is it an + // error condition? It would be good to tighten up the specification to make + // it less ambiguous. + } + return out_buffer; +} + +TfLiteStatus InitializeTfLiteTensorFromFlatbuffer( + SimpleMemoryAllocator *allocator, bool allocate_temp, + const tflite::Tensor &flatbuffer_tensor, + const flatbuffers::Vector > *buffers, + ErrorReporter *error_reporter, TfLiteTensor *result) +{ + TFLITE_DCHECK(result != nullptr); + + *result = {}; + // Make sure the serialized type is one we know how to deal with, and convert + // it from a flatbuffer enum into a constant used by the kernel C API. + TF_LITE_ENSURE_STATUS(ConvertTensorType(flatbuffer_tensor.type(), + &result->type, error_reporter)); + // Make sure we remember if the serialized tensor is designated as a variable. + result->is_variable = flatbuffer_tensor.is_variable(); + + result->data.data = GetFlatbufferTensorBuffer(flatbuffer_tensor, buffers); + + // TODO(petewarden): Some of these paths aren't getting enough testing + // coverage, so we should figure out some tests that exercise them. + if (result->data.data == nullptr) { + // The tensor contents haven't been set from a serialized buffer, so + // make a note that they will be allocated from memory. The actual + // allocation won't happen until later. + result->allocation_type = kTfLiteArenaRw; + } else { + // We set the data from a serialized buffer, so record tha. + result->allocation_type = kTfLiteMmapRo; + } + + // Figure out what the size in bytes of the buffer is and store it. + size_t type_size; + TF_LITE_ENSURE_STATUS(BytesRequiredForTensor( + flatbuffer_tensor, &result->bytes, &type_size, error_reporter)); + + if (flatbuffer_tensor.shape() == nullptr) { + // flatbuffer_tensor.shape() can return a nullptr in the case of a scalar + // tensor. + result->dims = const_cast(&kZeroLengthIntArray); + } else { + // TFLM doesn't allow reshaping the tensor which requires dynamic memory + // allocation so it is safe to drop the const qualifier. In the future, if + // we really want to update the tensor shape, we can always pass in a new + // TfLiteIntArray - especially we have to do so if the dimension is + TF_LITE_ENSURE_STATUS(FlatBufferVectorToTfLiteTypeArray( + allocator, error_reporter, flatbuffer_tensor.shape(), &(result->dims))); + } + + // Copy the quantization information from the serialized data. + const auto *src_quantization = flatbuffer_tensor.quantization(); + if (src_quantization && src_quantization->scale() && + (src_quantization->scale()->size() > 0) && + src_quantization->zero_point() && + (src_quantization->zero_point()->size() > 0)) { + // Always populate the TfLiteTensor.params field, even if there are + // per-channel quantization parameters. + result->params.scale = src_quantization->scale()->Get(0); + // Note that the zero_point field in the FlatBuffers schema is a 64-bit + // integer, but the zero_point field in the TfLiteQuantizationParams struct + // is a 32-bit integer. + result->params.zero_point = + static_cast(src_quantization->zero_point()->Get(0)); + + // Populate per-channel quantization params. + int channels = src_quantization->scale()->size(); + TfLiteAffineQuantization *quantization = + allocate_temp ? reinterpret_cast( + allocator->AllocateTemp(sizeof(TfLiteAffineQuantization), + alignof(TfLiteAffineQuantization))) : + reinterpret_cast( + allocator->AllocateFromTail( + sizeof(TfLiteAffineQuantization), + alignof(TfLiteAffineQuantization))); + if (quantization == nullptr) { + TF_LITE_REPORT_ERROR(error_reporter, + "Unable to allocate TfLiteAffineQuantization.\n"); + return kTfLiteError; + } + + // TODO(b/153688719): Reduce tail allocation by using a global zero-point + // buffer. This value can not be reused from the flatbuffer since the + // zero_point is stored as a int64_t. + quantization->zero_point = + allocate_temp ? reinterpret_cast(allocator->AllocateTemp( + TfLiteIntArrayGetSizeInBytes(channels), + alignof(TfLiteIntArray))) : + reinterpret_cast(allocator->AllocateFromTail( + TfLiteIntArrayGetSizeInBytes(channels), + alignof(TfLiteIntArray))); + if (quantization->zero_point == nullptr) { + TF_LITE_REPORT_ERROR(error_reporter, + "Unable to allocate quantization->zero_point.\n"); + return kTfLiteError; + } + + TF_LITE_ENSURE_STATUS(FlatBufferVectorToTfLiteTypeArray( + allocator, error_reporter, src_quantization->scale(), + &quantization->scale)); + + quantization->zero_point->size = channels; + int *zero_point_data = quantization->zero_point->data; + for (int i = 0; i < channels; i++) { + zero_point_data[i] = src_quantization->zero_point()->Get(i); + } + // TODO(rocky): Need to add a micro_allocator test case that fails when + // this is not copied: + quantization->quantized_dimension = src_quantization->quantized_dimension(); + + result->quantization = { kTfLiteAffineQuantization, quantization }; + } + return kTfLiteOk; +} + +TfLiteStatus InitializeTfLiteEvalTensorFromFlatbuffer( + SimpleMemoryAllocator *allocator, const tflite::Tensor &flatbuffer_tensor, + const flatbuffers::Vector > *buffers, + ErrorReporter *error_reporter, TfLiteEvalTensor *result) +{ + *result = {}; + // Make sure the serialized type is one we know how to deal with, and convert + // it from a flatbuffer enum into a constant used by the kernel C API. + TF_LITE_ENSURE_STATUS(ConvertTensorType(flatbuffer_tensor.type(), + &result->type, error_reporter)); + + result->data.data = GetFlatbufferTensorBuffer(flatbuffer_tensor, buffers); + + if (flatbuffer_tensor.shape() == nullptr) { + // flatbuffer_tensor.shape() can return a nullptr in the case of a scalar + // tensor. + result->dims = const_cast(&kZeroLengthIntArray); + } else { + TF_LITE_ENSURE_STATUS(FlatBufferVectorToTfLiteTypeArray( + allocator, error_reporter, flatbuffer_tensor.shape(), &(result->dims))); + } + return kTfLiteOk; +} + +} // namespace internal + +MicroAllocator::MicroAllocator(SimpleMemoryAllocator *memory_allocator, + ErrorReporter *error_reporter) + : memory_allocator_(memory_allocator), + error_reporter_(error_reporter), + model_is_allocating_(false) +{ +} + +MicroAllocator::~MicroAllocator() +{ +} + +MicroAllocator *MicroAllocator::Create(uint8_t *tensor_arena, size_t arena_size, + ErrorReporter *error_reporter) +{ + uint8_t *aligned_arena = AlignPointerUp(tensor_arena, kBufferAlignment); + size_t aligned_arena_size = tensor_arena + arena_size - aligned_arena; + return Create(SimpleMemoryAllocator::Create(error_reporter, aligned_arena, + aligned_arena_size), + error_reporter); +} + +MicroAllocator *MicroAllocator::Create(SimpleMemoryAllocator *memory_allocator, + ErrorReporter *error_reporter) +{ + TFLITE_DCHECK(memory_allocator != nullptr); + TFLITE_DCHECK(error_reporter != nullptr); + + uint8_t *allocator_buffer = memory_allocator->AllocateFromTail( + sizeof(MicroAllocator), alignof(MicroAllocator)); + MicroAllocator *allocator = + new (allocator_buffer) MicroAllocator(memory_allocator, error_reporter); + return allocator; +} + +SubgraphAllocations *MicroAllocator::StartModelAllocation(const Model *model) +{ + TFLITE_DCHECK(model != nullptr); + + if (model_is_allocating_) { + TF_LITE_REPORT_ERROR(error_reporter_, + "MicroAllocator: Model allocation started before " + "finishing previously allocated model"); + return nullptr; + } + + model_is_allocating_ = true; + + uint8_t *data_allocator_buffer = memory_allocator_->AllocateFromTail( + sizeof(MicroBuiltinDataAllocator), alignof(MicroBuiltinDataAllocator)); + builtin_data_allocator_ = + new (data_allocator_buffer) MicroBuiltinDataAllocator(memory_allocator_); + + if (InitScratchBufferData() != kTfLiteOk) { + return nullptr; + } + + // Allocate struct to store eval tensors, nodes and registrations. + SubgraphAllocations *output = reinterpret_cast( + memory_allocator_->AllocateFromTail( + sizeof(SubgraphAllocations) * model->subgraphs()->size(), + alignof(SubgraphAllocations))); + if (output == nullptr) { + MicroPrintf("Failed to allocate memory for model metadata."); + return nullptr; + } + + if (AllocateTfLiteEvalTensors(model, output) != kTfLiteOk || + AllocateNodeAndRegistrations(model, output) != kTfLiteOk) { + return nullptr; + } + return output; +} + +TfLiteStatus MicroAllocator::FinishModelAllocation( + const Model *model, SubgraphAllocations *subgraph_allocations, + ScratchBufferHandle **scratch_buffer_handles) +{ + if (!model_is_allocating_) { + TF_LITE_REPORT_ERROR(error_reporter_, + "MicroAllocator: Model allocation finished before " + "starting allocating model"); + return kTfLiteError; + } + + // TODO(b/187993197): Track scratch buffers for each subgraph. + for (size_t subgraph_idx = 0; subgraph_idx < model->subgraphs()->size(); + subgraph_idx++) { + const SubGraph *subgraph = model->subgraphs()->Get(subgraph_idx); + TFLITE_DCHECK(subgraph != nullptr); + + TF_LITE_ENSURE_STATUS(AllocateScratchBufferHandles( + scratch_buffer_handles, scratch_buffer_request_count_)); + TF_LITE_ENSURE_STATUS(CommitStaticMemoryPlan( + model, subgraph_allocations[subgraph_idx].tensors, + *scratch_buffer_handles, subgraph_idx)); + TF_LITE_ENSURE_STATUS(AllocateVariables( + subgraph, subgraph_allocations[subgraph_idx].tensors)); + } + model_is_allocating_ = false; + return kTfLiteOk; +} + +void *MicroAllocator::AllocatePersistentBuffer(size_t bytes) +{ + return memory_allocator_->AllocateFromTail(bytes, kBufferAlignment); +} + +TfLiteStatus MicroAllocator::RequestScratchBufferInArena(size_t bytes, + int subgraph_idx, + int *buffer_idx) +{ + // All scratch buffer requests are stored in the head section of the arena + // when a model is in the prepare phase. First align a scratch buffer request + // pointer to the start of the head: + internal::ScratchBufferRequest *requests = GetScratchBufferRequests(); + + // Count the number of requested scratch buffers for the current node: + size_t current_node_request_count = 0; + for (size_t i = 0; i < scratch_buffer_request_count_; ++i) { + if (requests[i].node_idx == kUnassignedScratchBufferRequestIndex) { + ++current_node_request_count; + } + } + + // First, ensure that the per-kernel request has not exceeded the limit: + if (current_node_request_count >= kMaxScratchBuffersPerOp) { + TF_LITE_REPORT_ERROR( + error_reporter_, + "Scratch buffer request exeeds limit per operator (%d)", + kMaxScratchBuffersPerOp); + return kTfLiteError; + } + + // Initialize and assign values for the request at the current index: + internal::ScratchBufferRequest *current_request = + &requests[scratch_buffer_request_count_]; + *current_request = {}; + // Assign -1 as a sentinel value that will be updated when the node finishes + // allocating: + current_request->bytes = bytes; + current_request->node_idx = kUnassignedScratchBufferRequestIndex; + + // Assign the current request index to the out-param: + *buffer_idx = scratch_buffer_request_count_; + + // Bump the request count to prepare for the next request: + ++scratch_buffer_request_count_; + return kTfLiteOk; +} + +TfLiteStatus MicroAllocator::FinishPrepareNodeAllocations(int node_id) +{ + // When a node has finished preparing, all temp allocations performed by the + // kernel should be cleaned up: + ResetTempAllocations(); + + // Find and update any new scratch buffer requests for the current node: + internal::ScratchBufferRequest *requests = GetScratchBufferRequests(); + + for (size_t i = 0; i < scratch_buffer_request_count_; ++i) { + // A request with a node_idx of -1 is a sentinel value used to indicate this + // was a new request for the current node. The allocator finally knows the + // node index at this point. Assign the value and update the list of new + // requests so the head section can be adjusted to allow for the next kernel + // to allocate at most kMaxScratchBuffersPerOp requests: + if (requests[i].node_idx == kUnassignedScratchBufferRequestIndex) { + requests[i].node_idx = node_id; + } + } + + // Ensure that the head is re-adjusted to allow for another at-most + // kMaxScratchBuffersPerOp scratch buffer requests in the next operator: + TF_LITE_ENSURE_STATUS(memory_allocator_->SetHeadBufferSize( + sizeof(internal::ScratchBufferRequest) * + (scratch_buffer_request_count_ + kMaxScratchBuffersPerOp), + alignof(internal::ScratchBufferRequest))); + + return kTfLiteOk; +} + +size_t MicroAllocator::used_bytes() const +{ + return memory_allocator_->GetUsedBytes(); +} + +TfLiteStatus MicroAllocator::AllocateNodeAndRegistrations( + const Model *model, SubgraphAllocations *subgraph_allocations) +{ + TFLITE_DCHECK(subgraph_allocations != nullptr); + + for (size_t subgraph_idx = 0; subgraph_idx < model->subgraphs()->size(); + subgraph_idx++) { + const SubGraph *subgraph = model->subgraphs()->Get(subgraph_idx); + TFLITE_DCHECK(subgraph != nullptr); + + // Initialize NodeAndRegistrations for the subgraph. + NodeAndRegistration *output = reinterpret_cast( + memory_allocator_->AllocateFromTail( + sizeof(NodeAndRegistration) * subgraph->operators()->size(), + alignof(NodeAndRegistration))); + if (output == nullptr) { + TF_LITE_REPORT_ERROR( + error_reporter_, + "Failed to allocate memory for node_and_registrations."); + return kTfLiteError; + } + subgraph_allocations[subgraph_idx].node_and_registrations = output; + } + return kTfLiteOk; +} +TfLiteTensor *MicroAllocator::AllocatePersistentTfLiteTensor( + const Model *model, const SubgraphAllocations *subgraph_allocations, + int tensor_index, int subgraph_index) +{ + const SubGraph *subgraph = model->subgraphs()->Get(subgraph_index); + TFLITE_DCHECK(subgraph != nullptr); + + // This value is allocated from persistent arena space. It is guaranteed to be + // around for the lifetime of the application. + TfLiteTensor *tensor = AllocatePersistentTfLiteTensorInternal(); + + // Populate any fields from the flatbuffer, since this TfLiteTensor struct is + // allocated in the persistent section of the arena, ensure that additional + // allocations also take place in that section of the arena. + if (PopulateTfLiteTensorFromFlatbuffer( + model, tensor, tensor_index, subgraph_index, + /*allocate_temp=*/false) != kTfLiteOk) { + TF_LITE_REPORT_ERROR(error_reporter_, + "Failed to populate a persistent TfLiteTensor struct " + "from flatbuffer data!"); + return nullptr; + } + + if (subgraph_allocations != nullptr) { + // Tensor buffers that are allocated at runtime (e.g. non-weight buffers) + // and not located in the flatbuffer are stored on the pre-allocated list of + // TfLiteEvalTensors structs. These structs are the source of truth, simply + // point the corresponding buffer to the new TfLiteTensor data value. + tensor->data.data = + subgraph_allocations[subgraph_index].tensors[tensor_index].data.data; + // TfLiteEvalTensor structs must also be the source of truth for the + // TfLiteTensor dims. + tensor->dims = + subgraph_allocations[subgraph_index].tensors[tensor_index].dims; + } + return tensor; +} + +TfLiteTensor *MicroAllocator::AllocateTempTfLiteTensor( + const Model *model, const SubgraphAllocations *subgraph_allocations, + int tensor_index, int subgraph_index) +{ + const SubGraph *subgraph = model->subgraphs()->Get(subgraph_index); + TFLITE_DCHECK(subgraph != nullptr); + + // This value is allocated from temporary arena space. It is guaranteed to be + // around for at least the scope of the calling function. Since this struct + // allocation takes place in temp space, no need to own or cleanup. + TfLiteTensor *tensor = + reinterpret_cast(memory_allocator_->AllocateTemp( + sizeof(TfLiteTensor), alignof(TfLiteTensor))); + + // Populate any fields from the flatbuffer, since this TfLiteTensor struct is + // allocated in the temp section of the arena, ensure that additional + // allocations also take place in that section of the arena. + if (PopulateTfLiteTensorFromFlatbuffer(model, tensor, tensor_index, + subgraph_index, + /*allocate_temp=*/true) != kTfLiteOk) { + TF_LITE_REPORT_ERROR( + error_reporter_, + "Failed to populate a temp TfLiteTensor struct from flatbuffer data!"); + return nullptr; + } + + if (subgraph_allocations != nullptr) { + // Tensor buffers that are allocated at runtime (e.g. non-weight buffers) + // and not located in the flatbuffer are stored on the pre-allocated list of + // TfLiteEvalTensors structs. These structs are the source of truth, simply + // point the corresponding buffer to the new TfLiteTensor data value. + tensor->data.data = + subgraph_allocations[subgraph_index].tensors[tensor_index].data.data; + // TfLiteEvalTensor structs must also be the source of truth for the + // TfLiteTensor dims. + tensor->dims = + subgraph_allocations[subgraph_index].tensors[tensor_index].dims; + } + return tensor; +} + +void MicroAllocator::ResetTempAllocations() +{ + memory_allocator_->ResetTempAllocations(); +} + +TfLiteStatus MicroAllocator::AllocateTfLiteEvalTensors( + const Model *model, SubgraphAllocations *subgraph_allocations) +{ + TFLITE_DCHECK(subgraph_allocations != nullptr); + + for (size_t subgraph_idx = 0; subgraph_idx < model->subgraphs()->size(); + subgraph_idx++) { + const SubGraph *subgraph = model->subgraphs()->Get(subgraph_idx); + TFLITE_DCHECK(subgraph != nullptr); + + size_t alloc_count = subgraph->tensors()->size(); + TfLiteEvalTensor *tensors = + reinterpret_cast(memory_allocator_->AllocateFromTail( + sizeof(TfLiteEvalTensor) * alloc_count, alignof(TfLiteEvalTensor))); + if (tensors == nullptr) { + TF_LITE_REPORT_ERROR( + error_reporter_, + "Failed to allocate memory for context->eval_tensors, " + "%d bytes required", + sizeof(TfLiteEvalTensor) * alloc_count); + return kTfLiteError; + } + + for (size_t i = 0; i < alloc_count; ++i) { + TfLiteStatus status = internal::InitializeTfLiteEvalTensorFromFlatbuffer( + memory_allocator_, *subgraph->tensors()->Get(i), model->buffers(), + error_reporter_, &tensors[i]); + if (status != kTfLiteOk) { + TF_LITE_REPORT_ERROR(error_reporter_, "Failed to initialize tensor %d", + i); + return kTfLiteError; + } + } + subgraph_allocations[subgraph_idx].tensors = tensors; + } + return kTfLiteOk; +} +TfLiteStatus MicroAllocator::AllocateVariables(const SubGraph *subgraph, + TfLiteEvalTensor *eval_tensors) +{ + for (size_t i = 0; i < subgraph->tensors()->size(); ++i) { + auto *tensor = subgraph->tensors()->Get(i); + if (tensor->is_variable()) { + size_t buffer_size; + TF_LITE_ENSURE_STATUS( + TfLiteEvalTensorByteLength(&eval_tensors[i], &buffer_size)); + + eval_tensors[i].data.data = + memory_allocator_->AllocateFromTail(buffer_size, kBufferAlignment); + + if (eval_tensors[i].data.data == nullptr) { + TF_LITE_REPORT_ERROR(error_reporter_, + "Failed to allocate variable tensor of size %d", + buffer_size); + return kTfLiteError; + } + } + } + return kTfLiteOk; +} + +TfLiteTensor *MicroAllocator::AllocatePersistentTfLiteTensorInternal() +{ + return reinterpret_cast(memory_allocator_->AllocateFromTail( + sizeof(TfLiteTensor), alignof(TfLiteTensor))); +} + +TfLiteStatus MicroAllocator::PopulateTfLiteTensorFromFlatbuffer( + const Model *model, TfLiteTensor *tensor, int tensor_index, + int subgraph_idx, bool allocate_temp) +{ + // TODO(b/162311891): This method serves as a stub to ensure quantized + // allocations in the tail can be recorded. Once the interpreter has APIs for + // accessing buffers on TfLiteEvalTensor this method can be dropped. + return internal::InitializeTfLiteTensorFromFlatbuffer( + memory_allocator_, allocate_temp, + *model->subgraphs()->Get(subgraph_idx)->tensors()->Get(tensor_index), + model->buffers(), error_reporter_, tensor); +} + +ErrorReporter *MicroAllocator::error_reporter() const +{ + return error_reporter_; +} + +TfLiteStatus MicroAllocator::CommitStaticMemoryPlan( + const Model *model, TfLiteEvalTensor *eval_tensors, + ScratchBufferHandle *scratch_buffer_handles, int subgraph_idx) +{ + size_t head_usage = 0; + // Create static memory plan + // 1. Calculate AllocationInfo to know the lifetime of each tensor/buffer. + // 2. Add them into the planner (such as the GreedyMemoryPlanner). + // 3. Static memory planning using the planner. + // 4. Set tensor/buffer pointers based on the offsets from the previous step. + // + // Note that AllocationInfo is only needed for creating the plan. It will be + // allocated from the temp section and cleaned up at the bottom of this + // function. + + const SubGraph *subgraph = model->subgraphs()->Get(subgraph_idx); + size_t allocation_info_count = + subgraph->tensors()->size() + scratch_buffer_request_count_; + size_t bytes = sizeof(AllocationInfo) * allocation_info_count; + + // Allocate an array of AllocationInfo structs from the temp section. This + // struct will be used by AllocationInfoBuilder to find buffer usage. + AllocationInfo *allocation_info = reinterpret_cast( + memory_allocator_->AllocateTemp(bytes, alignof(AllocationInfo))); + if (allocation_info == nullptr) { + TF_LITE_REPORT_ERROR( + error_reporter_, + "Failed to allocate memory for allocation_info, %d bytes required", + bytes); + return kTfLiteError; + } + + // Use the AllocationInfoBuilder class to help determine where buffers are + // used in the subgraph. + AllocationInfoBuilder builder(allocation_info, subgraph->tensors()->size(), + scratch_buffer_request_count_, error_reporter_); + + const int32_t *offline_planner_offsets = nullptr; + TF_LITE_ENSURE_STATUS( + builder.GetOfflinePlannedOffsets(model, &offline_planner_offsets)); + TF_LITE_ENSURE_STATUS( + builder.AddTensors(subgraph, offline_planner_offsets, eval_tensors)); + + internal::ScratchBufferRequest *scratch_buffer_requests = + GetScratchBufferRequests(); + + TF_LITE_ENSURE_STATUS(builder.AddScratchBuffers(scratch_buffer_requests, + scratch_buffer_handles)); + + // Remaining arena size that memory planner can use for calculating offsets. + size_t remaining_arena_size = + memory_allocator_->GetAvailableMemory(kBufferAlignment); + uint8_t *planner_arena = + memory_allocator_->AllocateTemp(remaining_arena_size, kBufferAlignment); + TF_LITE_ENSURE(error_reporter_, planner_arena != nullptr); + GreedyMemoryPlanner planner(planner_arena, remaining_arena_size); + TF_LITE_ENSURE_STATUS(CreatePlan(error_reporter_, &planner, allocation_info, + allocation_info_count)); + + // Reset all temp allocations used above: + memory_allocator_->ResetTempAllocations(); + + size_t actual_available_arena_size = + memory_allocator_->GetAvailableMemory(kBufferAlignment); + + // Make sure we have enough arena size. + if (planner.GetMaximumMemorySize() > actual_available_arena_size) { + TF_LITE_REPORT_ERROR( + error_reporter_, + "Arena size is too small for all buffers. Needed %u but only " + "%u was available.", + planner.GetMaximumMemorySize(), actual_available_arena_size); + return kTfLiteError; + } + // Commit the plan. + TF_LITE_ENSURE_STATUS(CommitPlan(error_reporter_, &planner, + memory_allocator_->GetHeadBuffer(), + allocation_info, allocation_info_count)); +#ifdef TF_LITE_SHOW_MEMORY_USE + planner.PrintMemoryPlan(); +#endif + head_usage = planner.GetMaximumMemorySize(); + + // The head is used to store memory plans for one model at a time during the + // model preparation stage, and is re-purposed to store scratch buffer handles + // during model invocation. The head must be as large as the greater of the + // largest model memory plan's size and the total space required for all + // scratch buffer handles. + if (max_head_buffer_usage_ < head_usage) { + max_head_buffer_usage_ = head_usage; + } + + // The head is used for storing scratch buffer allocations before finalizing a + // memory plan in this function. Ensure that the head is set to the largest + // memory plan sent through the allocator: + TF_LITE_ENSURE_STATUS(memory_allocator_->SetHeadBufferSize( + max_head_buffer_usage_, kBufferAlignment)); + return kTfLiteOk; +} + +TfLiteStatus MicroAllocator::AllocateScratchBufferHandles( + ScratchBufferHandle **scratch_buffer_handles, size_t handle_count) +{ + TFLITE_DCHECK(scratch_buffer_handles != nullptr); + + if (scratch_buffer_request_count_ == 0) { + // No scratch buffer requests were requested during model allocation. + return kTfLiteOk; + } + + // Allocate a consecutive block of memory store the scratch buffer handles. + // This alignment ensures quick lookup during inference time for the model: + *scratch_buffer_handles = reinterpret_cast( + memory_allocator_->AllocateFromTail( + sizeof(ScratchBufferHandle) * handle_count, + alignof(ScratchBufferHandle))); + + return kTfLiteOk; +} + +TfLiteStatus MicroAllocator::InitScratchBufferData() +{ + // A model is preparing to allocate resources, ensure that scratch buffer + // request counter is cleared: + scratch_buffer_request_count_ = 0; + + // All requests will be stored in the head section. Each kernel is allowed at + // most kMaxScratchBuffersPerOp requests. Adjust the head to reserve at most + // that many requests to begin: + TF_LITE_ENSURE_STATUS(memory_allocator_->SetHeadBufferSize( + sizeof(internal::ScratchBufferRequest) * kMaxScratchBuffersPerOp, + alignof(internal::ScratchBufferRequest))); + + return kTfLiteOk; +} + +internal::ScratchBufferRequest *MicroAllocator::GetScratchBufferRequests() +{ + return reinterpret_cast( + AlignPointerUp(memory_allocator_->GetHeadBuffer(), + alignof(internal::ScratchBufferRequest))); +} + +TfLiteStatus MicroAllocator::FlatBufferVectorToTfLiteTypeArray( + const flatbuffers::Vector *flatbuffer_array, + TfLiteIntArray **result) +{ + return internal::FlatBufferVectorToTfLiteTypeArray( + memory_allocator_, error_reporter_, flatbuffer_array, result); +} + +BuiltinDataAllocator *MicroAllocator::GetBuiltinDataAllocator() +{ + return builtin_data_allocator_; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/micro_allocator.h b/components/tflite/tensorflow/lite/micro/micro_allocator.h new file mode 100644 index 00000000..aa8ec1e1 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_allocator.h @@ -0,0 +1,288 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_MICRO_MICRO_ALLOCATOR_H_ +#define TENSORFLOW_LITE_MICRO_MICRO_ALLOCATOR_H_ + +#include +#include + +#include "flatbuffers/flatbuffers.h" // from @flatbuffers +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/core/api/error_reporter.h" +#include "tensorflow/lite/core/api/flatbuffer_conversions.h" +#include "tensorflow/lite/micro/compatibility.h" +#include "tensorflow/lite/micro/simple_memory_allocator.h" +#include "tensorflow/lite/schema/schema_generated.h" + +namespace tflite { +namespace internal { +// Sets up all of the data structure members for a TfLiteTensor based on the +// contents of a serialized tensor in the flatbuffer. +// TODO(b/162311891): Drop this method when the interpreter has an API for +// returning buffers on TfLiteEvalTensor. +TfLiteStatus InitializeTfLiteTensorFromFlatbuffer( + SimpleMemoryAllocator *allocator, bool allocate_temp, + const tflite::Tensor &flatbuffer_tensor, + const flatbuffers::Vector > *buffers, + ErrorReporter *error_reporter, TfLiteTensor *result); + +// Holds placeholder information for a scratch buffer request from a kernel. +// This struct is only used during the model prepare stage. Each request from a +// kernel is stored in the head section. During the prepare stage, the head +// section will at least hold kMaxScratchBuffersPerOp number of requests plus +// any requests from previous kernel requests. +// +// When the memory plan is finalized, these structs are no longer used in favor +// of a sequential, array of ScratchBufferHandle allocations in the tail +// section. These allocations are indexed by the request API defined in the +// TfLiteContext struct. +typedef struct { + // Number of bytes required by the buffer. The actual allocated size might be + // greater than `bytes` due to buffer alignment. + size_t bytes; + // Node where the buffer is allocated for. This provides useful information to + // determine the lifetime of the buffer. In AllocationInfo, this buffer will + // have `before` = node_idx and `after` = node_idx. + int node_idx; +} ScratchBufferRequest; + +} // namespace internal + +typedef struct { + TfLiteNode node; + const TfLiteRegistration *registration; +} NodeAndRegistration; + +// Holds a pointer to a buffer for a scratch buffer requested by a kernel during +// the model prepare stage. This struct is allocated in-place and allows for +// quick pointer-indexed lookup for speed during model inference. +typedef struct { + // Pointer to location of the scratch buffer: + uint8_t *data; +} ScratchBufferHandle; + +// Stores all per-subgraph allocations. This includes the node and registration +// array, tensor list and scratch buffer handles for each subgraph. +typedef struct { + NodeAndRegistration *node_and_registrations; + TfLiteEvalTensor *tensors; +} SubgraphAllocations; + +// Allocator responsible for allocating memory for all intermediate tensors +// necessary to invoke a model. +// +// The lifetime of the model, tensor arena and error reporter must be at +// least as long as that of the allocator object, since the allocator needs +// them to be accessible during its entire lifetime. +// +// The MicroAllocator simply plans out additional allocations that are required +// to standup a model for inference in TF Micro. This class currently relies on +// an additional allocator - SimpleMemoryAllocator - for all allocations from an +// arena. These allocations are divided into head (non-persistent) and tail +// (persistent) regions: +// +// Memory layout to help understand how it works +// This information could change in the future version. +// ************** .memory_allocator->GetBuffer() +// Tensors/Scratch buffers (head) +// ************** .head_watermark +// unused memory +// ************** .memory_allocator->GetBuffer() + ->GetMaxBufferSize() +// - ->GetDataSize() +// persistent area (tail) +// ************** .memory_allocator->GetBuffer() + ->GetMaxBufferSize() +class MicroAllocator { +public: + // Creates a MicroAllocator instance from a given tensor arena. This arena + // will be managed by the created instance. + // Note: Please use __declspec(align(16)) to make sure tensor_arena is 16 + // bytes aligned, otherwise some head room will be wasted. + // TODO(b/157615197): Cleanup constructor + factory usage. + static MicroAllocator *Create(uint8_t *tensor_arena, size_t arena_size, + ErrorReporter *error_reporter); + + // Creates a MicroAllocator instance using the provided SimpleMemoryAllocator + // intance. This allocator instance will use the SimpleMemoryAllocator + // instance to manage allocations internally. + static MicroAllocator *Create(SimpleMemoryAllocator *memory_allocator, + ErrorReporter *error_reporter); + + // Allocates internal resources required for model inference for each subgraph + // from the arena. + // + // This method will run through the flatbuffer data supplied in the model to + // properly allocate tensor, node, and op registration data. This method is + // expected to be followed with a call to FinishModelAllocation() Returns a + // pointer to an array of SubgraphAllocations (also stored in the tail of the + // arena) where each index corresponds to a different subgraph in the model. + // Return value is nullptr if the allocations failed. + SubgraphAllocations *StartModelAllocation(const Model *model); + + // Finish allocating internal resources required for model inference. + // + // -Plan the memory for activation tensors and scratch buffers. + // -Update eval tensors for each subgraph based on planned offsets. + // -Allocate scratch buffer handles array and update based on planned offsets. + // + // This method should be called after assigning model resources + // in StartModelAllocation(). The subgraph_allocations pointer should be the + // value passed into this class during StartModelAllocation(). Scratch buffer + // handles are stored in the out-param `scratch_buffer_handles` array which is + // allocated in this method. This value will be used in `GetScratchBuffer` + // call to retrieve scratch buffers. + TfLiteStatus FinishModelAllocation( + const Model *model, SubgraphAllocations *subgraph_allocations, + ScratchBufferHandle **scratch_buffer_handles); + + // Allocates a TfLiteTensor struct and populates the returned value with + // properties from the model flatbuffer. This struct is allocated from + // persistent arena memory is only guaranteed for the lifetime of the + // application. The eval_tensors pointer should be the value passed into this + // class during StartModelAllocation() and contains the source-of-truth for + // buffers. + virtual TfLiteTensor *AllocatePersistentTfLiteTensor( + const Model *model, const SubgraphAllocations *subgraph_allocations, + int tensor_index, int subgraph_index); + + // Allocates a TfLiteTensor struct and populates the returned value with + // properties from the model flatbuffer. This struct is allocated from + // temporary arena memory is only guaranteed until a call is made to + // ResetTempAllocations(). Subgraph_allocaitons contains the array of + // TfLiteEvalTensors. If the newly allocated temp at the specified subgraph + // and tensor index is already present int the TfLiteEvalTensor array, its + // data buffer will be re-used. + virtual TfLiteTensor *AllocateTempTfLiteTensor( + const Model *model, const SubgraphAllocations *subgraph_allocations, + int tensor_index, int subgraph_index); + + // Resets all temporary allocations. This method should be called after a + // chain of temp allocations (e.g. chain of TfLiteTensor objects via + // AllocateTfLiteTensor()). + virtual void ResetTempAllocations(); + + // Allocates persistent buffer which has the same life time as the allocator. + // The memory is immediately available and is allocated from the tail of the + // arena. + virtual void *AllocatePersistentBuffer(size_t bytes); + + // Register a scratch buffer of size `bytes` for Node with `node_id`. + // This method only requests a buffer with a given size to be used after a + // model has finished allocation via FinishModelAllocation(). All requested + // buffers will be accessible by the out-param in that method. + TfLiteStatus RequestScratchBufferInArena(size_t bytes, int subgraph_idx, + int *buffer_idx); + + // Finish allocating a specific NodeAndRegistration prepare block (kernel + // entry for a model) with a given node ID. This call ensures that any scratch + // buffer requests and temporary allocations are handled and ready for the + // next node prepare block. + TfLiteStatus FinishPrepareNodeAllocations(int node_id); + + // Returns the arena usage in bytes, only available after + // `FinishModelAllocation`. Otherwise, it will return 0. + size_t used_bytes() const; + + // Converts a flatbuffer int32_t array to a TfLiteIntArray, accounting for + // endiannes. + TfLiteStatus FlatBufferVectorToTfLiteTypeArray( + const flatbuffers::Vector *flatbuffer_array, + TfLiteIntArray **result); + + BuiltinDataAllocator *GetBuiltinDataAllocator(); + +protected: + MicroAllocator(SimpleMemoryAllocator *memory_allocator, + ErrorReporter *error_reporter); + virtual ~MicroAllocator(); + + // Allocates an array in the arena to hold pointers to the node and + // registration pointers required to represent the inference graph of the + // model. + virtual TfLiteStatus AllocateNodeAndRegistrations( + const Model *model, SubgraphAllocations *subgraph_allocations); + + // Allocates the list of persistent TfLiteEvalTensors that are used for the + // "eval" phase of model inference. These structs will be the source of truth + // for all tensor buffers. + virtual TfLiteStatus AllocateTfLiteEvalTensors( + const Model *model, SubgraphAllocations *subgraph_allocations); + // Allocates persistent tensor buffers for variable tensors in the subgraph. + virtual TfLiteStatus AllocateVariables(const SubGraph *subgraph, + TfLiteEvalTensor *eval_tensors); + + // Allocate and return a persistent TfLiteTensor. + // TODO(b/162311891): Drop this method when the interpreter has an API for + // accessing TfLiteEvalTensor structs. + virtual TfLiteTensor *AllocatePersistentTfLiteTensorInternal(); + + // Populates a TfLiteTensor struct with data from the model flatbuffer. Any + // quantization data is allocated from either the tail (persistent) or temp + // sections of the arena based on the allocation flag. + virtual TfLiteStatus PopulateTfLiteTensorFromFlatbuffer(const Model *model, + TfLiteTensor *tensor, + int tensor_index, + int subgraph_idx, + bool allocate_temp); + + ErrorReporter *error_reporter() const; + +private: + // Commits a memory plan for all non-persistent buffer allocations in the + // 'head' section of the memory arena. The eval_tensors pointer is the list of + // pre-allocated TfLiteEvalTensor structs that will point to the buffers that + // will be allocated into the head section in this function call. The + // scratch_buffer_handles pointer is the array of pre-allocated + // ScratchBufferHandle structs that will point to allocated buffers also in + // the head section. + virtual TfLiteStatus CommitStaticMemoryPlan( + const Model *model, TfLiteEvalTensor *eval_tensors, + ScratchBufferHandle *scratch_buffer_handles, int subgraph_idx); + + // Allocates an array of ScratchBufferHandle structs in the tail section for a + // given number of handles. + virtual TfLiteStatus AllocateScratchBufferHandles( + ScratchBufferHandle **scratch_buffer_handles, size_t handle_count); + + // Clears all internal scratch buffer request counts and resets the head to + // prepare for kernels to request scratch buffer data when a model is + // preparing. + TfLiteStatus InitScratchBufferData(); + + // Returns the pointer for the array of ScratchBufferRequest allocations in + // the head section. + internal::ScratchBufferRequest *GetScratchBufferRequests(); + + // A simple memory allocator that always allocate from the arena tail or head. + SimpleMemoryAllocator *memory_allocator_; + + // Allocator used to allocate persistent builtin data. + BuiltinDataAllocator *builtin_data_allocator_; + + ErrorReporter *error_reporter_; + bool model_is_allocating_; + + // Holds the number of ScratchBufferRequest instances stored in the head + // section when a model is allocating. + size_t scratch_buffer_request_count_ = 0; + + // Holds the byte length of the memory plan with the largest head usage. Used + // to ensure that multi-tenant allocations can share the head for buffers. + size_t max_head_buffer_usage_ = 0; + + TF_LITE_REMOVE_VIRTUAL_DELETE +}; + +} // namespace tflite +#endif // TENSORFLOW_LITE_MICRO_MICRO_ALLOCATOR_H_ diff --git a/components/tflite/tensorflow/lite/micro/micro_allocator_test.cc b/components/tflite/tensorflow/lite/micro/micro_allocator_test.cc new file mode 100644 index 00000000..4b90b93a --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_allocator_test.cc @@ -0,0 +1,933 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/micro_allocator.h" + +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/memory_helpers.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/simple_memory_allocator.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" +#include "tensorflow/lite/micro/testing/test_conv_model.h" + +namespace tflite { +namespace testing { +namespace { + +constexpr int kExpectedAlignment = 4; +constexpr int t0 = 0; +constexpr int t1 = 1; +constexpr int t2 = 2; +constexpr int t3 = 3; +constexpr int t4 = 4; +constexpr int t5 = 5; + +void VerifyMockTfLiteTensor(TfLiteTensor *tensor, bool is_variable = false) +{ + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt32, tensor->type); + TF_LITE_MICRO_EXPECT_EQ(1, tensor->dims->size); + TF_LITE_MICRO_EXPECT_EQ(1, tensor->dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(is_variable, tensor->is_variable); + TF_LITE_MICRO_EXPECT_EQ(static_cast(4), tensor->bytes); + TF_LITE_MICRO_EXPECT_NE(nullptr, tensor->data.raw); + TF_LITE_MICRO_EXPECT_EQ(static_cast(0), + (reinterpret_cast(tensor->data.raw) % + kExpectedAlignment)); +} + +void VerifyMockWeightTfLiteTensor(TfLiteTensor *tensor) +{ + TF_LITE_MICRO_EXPECT_EQ(kTfLiteUInt8, tensor->type); + TF_LITE_MICRO_EXPECT_EQ(1, tensor->dims->size); + TF_LITE_MICRO_EXPECT_EQ(1, tensor->dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(static_cast(1), tensor->bytes); + TF_LITE_MICRO_EXPECT_NE(nullptr, tensor->data.raw); +} + +void VerifyMockTfLiteEvalTensor(TfLiteEvalTensor *tensor) +{ + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt32, tensor->type); + TF_LITE_MICRO_EXPECT_EQ(1, tensor->dims->size); + TF_LITE_MICRO_EXPECT_EQ(1, tensor->dims->data[0]); + size_t buffer_size; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, tflite::TfLiteEvalTensorByteLength(tensor, &buffer_size)); + TF_LITE_MICRO_EXPECT_EQ(static_cast(4), buffer_size); + TF_LITE_MICRO_EXPECT_NE(nullptr, tensor->data.raw); + TF_LITE_MICRO_EXPECT_EQ(static_cast(0), + (reinterpret_cast(tensor->data.raw) % + kExpectedAlignment)); +} + +void VerifyMockWeightTfLiteEvalTensor(TfLiteEvalTensor *tensor) +{ + TF_LITE_MICRO_EXPECT_EQ(kTfLiteUInt8, tensor->type); + TF_LITE_MICRO_EXPECT_EQ(1, tensor->dims->size); + TF_LITE_MICRO_EXPECT_EQ(1, tensor->dims->data[0]); + size_t buffer_size; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, tflite::TfLiteEvalTensorByteLength(tensor, &buffer_size)); + TF_LITE_MICRO_EXPECT_EQ(static_cast(1), buffer_size); + TF_LITE_MICRO_EXPECT_NE(nullptr, tensor->data.raw); +} + +void VerifyMockTensor(const Model *model, MicroAllocator *allocator, + SubgraphAllocations *subgraph_allocations, int tensor_idx, + bool is_variable = false) +{ + for (size_t subgraph_idx = 0; subgraph_idx < model->subgraphs()->size(); + subgraph_idx++) { + VerifyMockTfLiteTensor( + allocator->AllocatePersistentTfLiteTensor(model, subgraph_allocations, + tensor_idx, subgraph_idx), + is_variable); + VerifyMockTfLiteEvalTensor( + &subgraph_allocations[subgraph_idx].tensors[tensor_idx]); + } +} + +void VerifyMockWeightTensor(const Model *model, MicroAllocator *allocator, + SubgraphAllocations *subgraph_allocations, + int tensor_idx) +{ + for (size_t subgraph_idx = 0; subgraph_idx < model->subgraphs()->size(); + subgraph_idx++) { + VerifyMockWeightTfLiteTensor(allocator->AllocatePersistentTfLiteTensor( + model, subgraph_allocations, tensor_idx, subgraph_idx)); + VerifyMockWeightTfLiteEvalTensor( + &subgraph_allocations[subgraph_idx].tensors[tensor_idx]); + } +} + +void EnsureUniqueVariableTensorBuffer(const Model *model, + TfLiteEvalTensor *eval_tensors, + const int variable_tensor_idx) +{ + for (size_t i = 0; i < GetModelTensorCount(model); i++) { + if (i != static_cast(variable_tensor_idx)) { + TF_LITE_MICRO_EXPECT_NE(eval_tensors[variable_tensor_idx].data.raw, + eval_tensors[i].data.raw); + } + } +} + +void VerifyRegistrationAndNodeAllocation( + SubgraphAllocations *subgraph_allocations, size_t count, + int num_subgraphs) +{ + for (int subgraph_idx = 0; subgraph_idx < num_subgraphs; subgraph_idx++) { + for (size_t i = 0; i < count; i++) { + TF_LITE_MICRO_EXPECT_NE(nullptr, &subgraph_allocations[subgraph_idx] + .node_and_registrations[i] + .registration); + } + } +} + +} // namespace +} // namespace testing +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestInitializeRuntimeTensor) +{ + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::SimpleMemoryAllocator *simple_allocator = + tflite::SimpleMemoryAllocator::Create(tflite::GetMicroErrorReporter(), + arena, arena_size); + + const tflite::Tensor *tensor = tflite::testing::Create1dFlatbufferTensor(100); + const flatbuffers::Vector > *buffers = + tflite::testing::CreateFlatbufferBuffers(); + + TfLiteTensor allocated_tensor; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, + tflite::internal::InitializeTfLiteTensorFromFlatbuffer( + simple_allocator, /*allocate_temp=*/false, *tensor, buffers, + tflite::GetMicroErrorReporter(), &allocated_tensor)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt32, allocated_tensor.type); + TF_LITE_MICRO_EXPECT_EQ(1, allocated_tensor.dims->size); + TF_LITE_MICRO_EXPECT_EQ(100, allocated_tensor.dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(static_cast(400), allocated_tensor.bytes); + TF_LITE_MICRO_EXPECT(nullptr == allocated_tensor.data.i32); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteArenaRw, allocated_tensor.allocation_type); + + simple_allocator->~SimpleMemoryAllocator(); +} + +// TODO(b/162311891): Drop this test when InitializeTfLiteTensorFromFlatbuffer() +// always allocates from temp (interpreter returns buffers from +// TfLiteEvalTensor): +TF_LITE_MICRO_TEST(TestInitializeTempRuntimeTensor) +{ + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::SimpleMemoryAllocator *simple_allocator = + tflite::SimpleMemoryAllocator::Create(tflite::GetMicroErrorReporter(), + arena, arena_size); + + const tflite::Tensor *tensor = tflite::testing::Create1dFlatbufferTensor(100); + const flatbuffers::Vector > *buffers = + tflite::testing::CreateFlatbufferBuffers(); + + TfLiteTensor allocated_temp_tensor; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, tflite::internal::InitializeTfLiteTensorFromFlatbuffer( + simple_allocator, /*allocate_temp=*/true, *tensor, buffers, + tflite::GetMicroErrorReporter(), &allocated_temp_tensor)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt32, allocated_temp_tensor.type); + TF_LITE_MICRO_EXPECT_EQ(1, allocated_temp_tensor.dims->size); + TF_LITE_MICRO_EXPECT_EQ(100, allocated_temp_tensor.dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(static_cast(400), + allocated_temp_tensor.bytes); + TF_LITE_MICRO_EXPECT(nullptr == allocated_temp_tensor.data.i32); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteArenaRw, + allocated_temp_tensor.allocation_type); + + simple_allocator->~SimpleMemoryAllocator(); +} + +TF_LITE_MICRO_TEST(TestInitializeQuantizedTensor) +{ + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::SimpleMemoryAllocator *simple_allocator = + tflite::SimpleMemoryAllocator::Create(tflite::GetMicroErrorReporter(), + arena, arena_size); + + const tflite::Tensor *tensor = + tflite::testing::CreateQuantizedFlatbufferTensor(100); + const flatbuffers::Vector > *buffers = + tflite::testing::CreateFlatbufferBuffers(); + + TfLiteTensor allocated_tensor; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, + tflite::internal::InitializeTfLiteTensorFromFlatbuffer( + simple_allocator, /*allocate_temp=*/false, *tensor, buffers, + tflite::GetMicroErrorReporter(), &allocated_tensor)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt32, allocated_tensor.type); + TF_LITE_MICRO_EXPECT_EQ(1, allocated_tensor.dims->size); + TF_LITE_MICRO_EXPECT_EQ(100, allocated_tensor.dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(static_cast(400), allocated_tensor.bytes); + TF_LITE_MICRO_EXPECT(nullptr == allocated_tensor.data.i32); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteArenaRw, allocated_tensor.allocation_type); + + simple_allocator->~SimpleMemoryAllocator(); +} + +TF_LITE_MICRO_TEST(TestMissingQuantization) +{ + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::SimpleMemoryAllocator *simple_allocator = + tflite::SimpleMemoryAllocator::Create(tflite::GetMicroErrorReporter(), + arena, arena_size); + + const tflite::Tensor *tensor = + tflite::testing::CreateMissingQuantizationFlatbufferTensor(100); + const flatbuffers::Vector > *buffers = + tflite::testing::CreateFlatbufferBuffers(); + + TfLiteTensor allocated_tensor; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, + tflite::internal::InitializeTfLiteTensorFromFlatbuffer( + simple_allocator, /*allocate_temp=*/false, *tensor, buffers, + tflite::GetMicroErrorReporter(), &allocated_tensor)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt32, allocated_tensor.type); + TF_LITE_MICRO_EXPECT_EQ(1, allocated_tensor.dims->size); + TF_LITE_MICRO_EXPECT_EQ(100, allocated_tensor.dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(static_cast(400), allocated_tensor.bytes); + TF_LITE_MICRO_EXPECT(nullptr == allocated_tensor.data.i32); +} + +TF_LITE_MICRO_TEST(TestFailsWhenModelStartsTwice) +{ + const tflite::Model *model = tflite::testing::GetSimpleMockModel(); + tflite::AllOpsResolver op_resolver = tflite::testing::GetOpResolver(); + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::MicroAllocator *allocator = tflite::MicroAllocator::Create( + arena, arena_size, tflite::GetMicroErrorReporter()); + TF_LITE_MICRO_EXPECT(nullptr != allocator); + TF_LITE_MICRO_EXPECT_NE(nullptr, allocator->StartModelAllocation(model)); + TF_LITE_MICRO_EXPECT(nullptr == allocator->StartModelAllocation(model)); +} + +TF_LITE_MICRO_TEST(TestFailsWithWrongSequence) +{ + const tflite::Model *model = tflite::testing::GetSimpleMockModel(); + tflite::ScratchBufferHandle *scratch_buffer_handles = nullptr; + tflite::AllOpsResolver op_resolver = tflite::testing::GetOpResolver(); + tflite::SubgraphAllocations *subgraph_allocations = nullptr; + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::MicroAllocator *allocator = tflite::MicroAllocator::Create( + arena, arena_size, tflite::GetMicroErrorReporter()); + TF_LITE_MICRO_EXPECT_NE(nullptr, allocator); + + // We can't finish allocation before it ever got started. + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteError, allocator->FinishModelAllocation( + model, subgraph_allocations, &scratch_buffer_handles)); + + // Start twice is not allowed. + TF_LITE_MICRO_EXPECT(nullptr != allocator->StartModelAllocation(model)); + TF_LITE_MICRO_EXPECT(nullptr == allocator->StartModelAllocation(model)); +} + +TF_LITE_MICRO_TEST(TestMockModelAllocation) +{ + const tflite::Model *model = tflite::testing::GetSimpleMockModel(); + tflite::ScratchBufferHandle *scratch_buffer_handles = nullptr; + tflite::AllOpsResolver op_resolver = tflite::testing::GetOpResolver(); + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::MicroAllocator *allocator = tflite::MicroAllocator::Create( + arena, arena_size, tflite::GetMicroErrorReporter()); + TF_LITE_MICRO_EXPECT(nullptr != allocator); + tflite::SubgraphAllocations *subgraph_allocations = + allocator->StartModelAllocation(model); + TF_LITE_MICRO_EXPECT(nullptr != subgraph_allocations); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, allocator->FinishModelAllocation(model, subgraph_allocations, + &scratch_buffer_handles)); + + size_t model_tensor_size = tflite::testing::GetModelTensorCount(model); + TF_LITE_MICRO_EXPECT_EQ(static_cast(4), model_tensor_size); + + tflite::testing::VerifyMockTensor(model, allocator, subgraph_allocations, 0); + tflite::testing::VerifyMockWeightTensor(model, allocator, + subgraph_allocations, 1); + tflite::testing::VerifyMockTensor(model, allocator, subgraph_allocations, 2); + tflite::testing::VerifyMockTensor(model, allocator, subgraph_allocations, 3); + + TfLiteEvalTensor *eval_tensors = subgraph_allocations[0].tensors; + TF_LITE_MICRO_EXPECT_NE(eval_tensors[1].data.raw, eval_tensors[0].data.raw); + TF_LITE_MICRO_EXPECT_NE(eval_tensors[2].data.raw, eval_tensors[0].data.raw); + TF_LITE_MICRO_EXPECT_NE(eval_tensors[1].data.raw, eval_tensors[2].data.raw); + TF_LITE_MICRO_EXPECT_NE(eval_tensors[3].data.raw, eval_tensors[0].data.raw); + TF_LITE_MICRO_EXPECT_NE(eval_tensors[3].data.raw, eval_tensors[1].data.raw); + TF_LITE_MICRO_EXPECT_NE(eval_tensors[3].data.raw, eval_tensors[2].data.raw); + TF_LITE_MICRO_EXPECT_LE(allocator->used_bytes(), 856 + 100); + + // SimpleMockModel has 2 operators: + tflite::testing::VerifyRegistrationAndNodeAllocation(subgraph_allocations, + /*count=*/2, + /*num_subgraphs=*/1); +} + +TF_LITE_MICRO_TEST(TestMultiTenantAllocation) +{ + // The `OpResolver` is shared among different models in this test for + // simplicity but in practice you could have different `OpResolver`. + tflite::AllOpsResolver op_resolver = tflite::testing::GetOpResolver(); + + // Create a shared allocator. + constexpr size_t arena_size = 4096; + uint8_t arena[arena_size]; + tflite::MicroAllocator *allocator = tflite::MicroAllocator::Create( + arena, arena_size, tflite::GetMicroErrorReporter()); + TF_LITE_MICRO_EXPECT_NE(nullptr, allocator); + tflite::ScratchBufferHandle *scratch_buffer_handles = nullptr; + + // Allocate for model 1. We use ComplexMockModel here to cover the code path + // allocatig variables. + const tflite::Model *model1 = tflite::testing::GetComplexMockModel(); + tflite::SubgraphAllocations *subgraph_allocations1 = + allocator->StartModelAllocation(model1); + TF_LITE_MICRO_EXPECT(nullptr != subgraph_allocations1); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, allocator->FinishModelAllocation(model1, subgraph_allocations1, + &scratch_buffer_handles)); + const size_t single_model_used_bytes = allocator->used_bytes(); + + // Allocate for model 2. + const tflite::Model *model2 = tflite::testing::GetComplexMockModel(); + tflite::SubgraphAllocations *subgraph_allocations2 = + allocator->StartModelAllocation(model2); + TF_LITE_MICRO_EXPECT(nullptr != subgraph_allocations2); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, allocator->FinishModelAllocation(model2, subgraph_allocations2, + &scratch_buffer_handles)); + + // Allocation for two instances of the same model takes less memory as `head` + // of the arena is reused. + TF_LITE_MICRO_EXPECT_LE(allocator->used_bytes(), 2 * single_model_used_bytes); +} + +TF_LITE_MICRO_TEST(TestAllocationForModelsWithBranches) +{ + const tflite::Model *model = tflite::testing::GetSimpleModelWithBranch(); + tflite::ScratchBufferHandle *scratch_buffer_handles = nullptr; + tflite::AllOpsResolver op_resolver = tflite::testing::GetOpResolver(); + constexpr size_t arena_size = 4096; + uint8_t arena[arena_size]; + tflite::MicroAllocator *allocator = tflite::MicroAllocator::Create( + arena, arena_size, tflite::GetMicroErrorReporter()); + TF_LITE_MICRO_EXPECT_NE(nullptr, allocator); + tflite::SubgraphAllocations *subgraph_allocations = + allocator->StartModelAllocation(model); + TF_LITE_MICRO_EXPECT(nullptr != subgraph_allocations); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, allocator->FinishModelAllocation(model, subgraph_allocations, + &scratch_buffer_handles)); + + uint8_t *start = subgraph_allocations[0].tensors[0].data.uint8; + // Check test_helpers.cc BuildSimpleModelWithBranch for model structure. + // t0 is the first tensor, so place it in offset 0. + TF_LITE_MICRO_EXPECT_EQ( + 0, subgraph_allocations[0].tensors[0].data.uint8 - start); + // bytes = 2 * 2 * 3 * sizeof(float32) = 48, same for other tensors. + size_t buffer_size; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, tflite::TfLiteEvalTensorByteLength( + &subgraph_allocations[0].tensors[0], &buffer_size)); + TF_LITE_MICRO_EXPECT_EQ(static_cast(48), buffer_size); + // t1 can't reuse any memory, as n0 requires both t0 and t1. + TF_LITE_MICRO_EXPECT_EQ( + 96, subgraph_allocations[0].tensors[1].data.uint8 - start); + // t2 can't reuse any memory, as n1 requires both t0 and t2. Also n2 requires + // both t1 and t2. + TF_LITE_MICRO_EXPECT_EQ( + 48, subgraph_allocations[0].tensors[2].data.uint8 - start); + // t3 reuses the same memory from t0 as t0 is not an input to any node. + TF_LITE_MICRO_EXPECT_EQ( + 0, subgraph_allocations[0].tensors[3].data.uint8 - start); + + // SimpleModelWithBranch has 3 operators: + tflite::testing::VerifyRegistrationAndNodeAllocation(subgraph_allocations, + /*count=*/3, + /*num_subgraphs=*/1); +} + +TF_LITE_MICRO_TEST(TestAllocationForComplexModelAllocation) +{ + const tflite::Model *model = tflite::testing::GetComplexMockModel(); + tflite::ScratchBufferHandle *scratch_buffer_handles = nullptr; + tflite::AllOpsResolver op_resolver = tflite::testing::GetOpResolver(); + constexpr size_t arena_size = 2048; + uint8_t arena[arena_size]; + tflite::MicroAllocator *allocator = tflite::MicroAllocator::Create( + arena, arena_size, tflite::GetMicroErrorReporter()); + TF_LITE_MICRO_EXPECT(nullptr != allocator); + tflite::SubgraphAllocations *subgraph_allocations = + allocator->StartModelAllocation(model); + TF_LITE_MICRO_EXPECT(nullptr != subgraph_allocations); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, allocator->FinishModelAllocation(model, subgraph_allocations, + &scratch_buffer_handles)); + + size_t model_tensor_size = tflite::testing::GetModelTensorCount(model); + TF_LITE_MICRO_EXPECT_EQ(static_cast(10), model_tensor_size); + + // NOTE: Tensor indexes match the values in GetComplexMockModel(). + tflite::testing::VerifyMockTensor(model, allocator, subgraph_allocations, 0); + tflite::testing::VerifyMockTensor(model, allocator, subgraph_allocations, 1, + /*is_variable=*/true); + tflite::testing::VerifyMockWeightTensor(model, allocator, + subgraph_allocations, 2); + tflite::testing::VerifyMockTensor(model, allocator, subgraph_allocations, 3); + tflite::testing::VerifyMockTensor(model, allocator, subgraph_allocations, 4, + /*is_variable=*/true); + tflite::testing::VerifyMockWeightTensor(model, allocator, + subgraph_allocations, 5); + tflite::testing::VerifyMockTensor(model, allocator, subgraph_allocations, 6); + tflite::testing::VerifyMockTensor(model, allocator, subgraph_allocations, 7, + /*is_variable=*/true); + tflite::testing::VerifyMockWeightTensor(model, allocator, + subgraph_allocations, 8); + tflite::testing::VerifyMockTensor(model, allocator, subgraph_allocations, 9); + + // // Ensure that variable tensors have unique address + tflite::testing::EnsureUniqueVariableTensorBuffer( + model, subgraph_allocations[0].tensors, 1); + tflite::testing::EnsureUniqueVariableTensorBuffer( + model, subgraph_allocations[0].tensors, 4); + tflite::testing::EnsureUniqueVariableTensorBuffer( + model, subgraph_allocations[0].tensors, 7); + + // ComplexMockModel has 3 operators: + tflite::testing::VerifyRegistrationAndNodeAllocation(subgraph_allocations, + /*count=*/3, + /*num_subgraphs=*/1); +} + +TF_LITE_MICRO_TEST(OfflinePlannerBranchesAllOnline) +{ + int version = 1; + int subgraph = 0; + constexpr int number_tensors = 4; + tflite::AllOpsResolver op_resolver = tflite::testing::GetOpResolver(); + const int32_t metadata_buffer[tflite::testing::kOfflinePlannerHeaderSize + + number_tensors] = { version, subgraph, + number_tensors, // header + // memory offsets: + -1, -1, -1, -1 }; + + // The structure is identical to the one in + // TestAllocationForModelsWithBranches + int number_connections = 3; + tflite::testing::NodeConnection node_list[3] = { { + { 0 }, // input + { 1 } // output + }, + { + { 0 }, // input + { 2 } // output + }, + { + { 1, 2 }, // input1, input2 + { 3 } // output + } }; + + const tflite::Model *model = tflite::testing::GetModelWithOfflinePlanning( + number_tensors, metadata_buffer, node_list, number_connections); + + tflite::ScratchBufferHandle *scratch_buffer_handles = nullptr; + + constexpr size_t arena_size = 4096; + uint8_t arena[arena_size]; + tflite::MicroAllocator *allocator = tflite::MicroAllocator::Create( + arena, arena_size, tflite::GetMicroErrorReporter()); + + tflite::SubgraphAllocations *subgraph_allocations = + allocator->StartModelAllocation(model); + TF_LITE_MICRO_EXPECT(nullptr != subgraph_allocations); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, allocator->FinishModelAllocation(model, subgraph_allocations, + &scratch_buffer_handles)); + + // Since all of the tensors are online planned and the model structure is + // identical to that in TestAllocationForModelsWithBranches, + // the offsets be should identical to that test. + uint8_t *start = subgraph_allocations[0].tensors[0].data.uint8; + TF_LITE_MICRO_EXPECT_EQ( + 0, subgraph_allocations[0].tensors[0].data.uint8 - start); + + size_t buffer_size; + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, tflite::TfLiteEvalTensorByteLength( + &subgraph_allocations[0].tensors[0], &buffer_size)); + TF_LITE_MICRO_EXPECT_EQ(static_cast(48), buffer_size); + TF_LITE_MICRO_EXPECT_EQ( + 96, subgraph_allocations[0].tensors[1].data.uint8 - start); + TF_LITE_MICRO_EXPECT_EQ( + 48, subgraph_allocations[0].tensors[2].data.uint8 - start); + TF_LITE_MICRO_EXPECT_EQ( + 0, subgraph_allocations[0].tensors[3].data.uint8 - start); +} + +TF_LITE_MICRO_TEST(OfflinePlannerBasic) +{ + constexpr int number_tensors = 4; + tflite::AllOpsResolver op_resolver = tflite::testing::GetOpResolver(); + const int32_t metadata_buffer[tflite::testing::kOfflinePlannerHeaderSize + + number_tensors] = { 1, 0, number_tensors, + /*t0=*/0, + /*t1=*/48, + /*t2=*/0, + /*t3=*/48 }; + constexpr int number_connections = 3; + tflite::testing::NodeConnection node_list[number_connections] = { + { /*input=*/{ tflite::testing::t0 }, + /*output=*/{ tflite::testing::t1 } }, + { /*input=*/{ tflite::testing::t1 }, + /*output=*/{ tflite::testing::t2 } }, + { /*input=*/{ tflite::testing::t2 }, + /*output=*/{ tflite::testing::t3 } } + }; + + const tflite::Model *model = tflite::testing::GetModelWithOfflinePlanning( + number_tensors, metadata_buffer, node_list, number_connections); + + tflite::ScratchBufferHandle *scratch_buffer_handles = nullptr; + constexpr size_t arena_size = 4096; + uint8_t arena[arena_size]; + tflite::MicroAllocator *allocator = tflite::MicroAllocator::Create( + arena, arena_size, tflite::GetMicroErrorReporter()); + + tflite::SubgraphAllocations *subgraph_allocations = + allocator->StartModelAllocation(model); + TF_LITE_MICRO_EXPECT(nullptr != subgraph_allocations); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, allocator->FinishModelAllocation(model, subgraph_allocations, + &scratch_buffer_handles)); + + uint8_t *start = subgraph_allocations[0].tensors[0].data.uint8; + TF_LITE_MICRO_EXPECT_EQ( + 0, subgraph_allocations[0].tensors[0].data.uint8 - start); + TF_LITE_MICRO_EXPECT_EQ( + 48, subgraph_allocations[0].tensors[1].data.uint8 - start); + TF_LITE_MICRO_EXPECT_EQ( + 0, subgraph_allocations[0].tensors[2].data.uint8 - start); + TF_LITE_MICRO_EXPECT_EQ( + 48, subgraph_allocations[0].tensors[3].data.uint8 - start); +} + +TF_LITE_MICRO_TEST(OfflinePlannerOverlappingAllocation) +{ + constexpr int number_tensors = 4; + tflite::AllOpsResolver op_resolver = tflite::testing::GetOpResolver(); + const int32_t metadata_buffer[tflite::testing::kOfflinePlannerHeaderSize + + number_tensors] = { /*version=*/1, + /*subgraph=*/0, + number_tensors, + /*t0=*/0, + /*t1=*/0, + /*t2=*/48, + /*t3=*/-1 }; + + int number_connections = 2; + tflite::testing::NodeConnection node_list[2] = { + { /*input, scratch=*/{ tflite::testing::t0, tflite::testing::t1 }, + /*output=*/{ tflite::testing::t2 } }, + { /*input=*/{ tflite::testing::t2 }, + /*output=*/{ tflite::testing::t3 } }, + }; + + const tflite::Model *model = tflite::testing::GetModelWithOfflinePlanning( + number_tensors, metadata_buffer, node_list, number_connections); + + tflite::ScratchBufferHandle *scratch_buffer_handles = nullptr; + constexpr size_t arena_size = 4096; + uint8_t arena[arena_size]; + tflite::MicroAllocator *allocator = tflite::MicroAllocator::Create( + arena, arena_size, tflite::GetMicroErrorReporter()); + + tflite::SubgraphAllocations *subgraph_allocations = + allocator->StartModelAllocation(model); + TF_LITE_MICRO_EXPECT(nullptr != subgraph_allocations); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, allocator->FinishModelAllocation(model, subgraph_allocations, + &scratch_buffer_handles)); + + uint8_t *start = subgraph_allocations[0].tensors[0].data.uint8; + TF_LITE_MICRO_EXPECT_EQ( + 0, subgraph_allocations[0].tensors[0].data.uint8 - start); + TF_LITE_MICRO_EXPECT_EQ( + 0, subgraph_allocations[0].tensors[1].data.uint8 - start); + TF_LITE_MICRO_EXPECT_EQ( + 48, subgraph_allocations[0].tensors[2].data.uint8 - start); + TF_LITE_MICRO_EXPECT_EQ( + 0, subgraph_allocations[0].tensors[3].data.uint8 - start); + // TF_LITE_MICRO_EXPECT_EQ(static_cast(48), context.tensors[0].bytes); +} + +TF_LITE_MICRO_TEST(OfflinePlannerOfflineOnline) +{ + constexpr int number_tensors = 5; + tflite::AllOpsResolver op_resolver = tflite::testing::GetOpResolver(); + const int32_t metadata_buffer[tflite::testing::kOfflinePlannerHeaderSize + + number_tensors] = { /*version=*/1, + /*subgraph=*/0, + number_tensors, + /*t0=*/0, + /*t1=*/48, + /*t2=*/-1, + /*t3=*/0, + /*t4=*/-1 }; + + constexpr int number_connections = 2; + tflite::testing::NodeConnection node_list[number_connections] = { + { + /*input, scratch=*/{ tflite::testing::t0, tflite::testing::t1 }, + /*output=*/{ tflite::testing::t2 }, + }, + { + /*input=*/{ tflite::testing::t2 }, + /*output1, output2=*/{ tflite::testing::t3, tflite::testing::t4 }, + }, + }; + + const tflite::Model *model = tflite::testing::GetModelWithOfflinePlanning( + number_tensors, metadata_buffer, node_list, number_connections); + + tflite::ScratchBufferHandle *scratch_buffer_handles = nullptr; + constexpr size_t arena_size = 4096; + uint8_t arena[arena_size]; + tflite::MicroAllocator *allocator = tflite::MicroAllocator::Create( + arena, arena_size, tflite::GetMicroErrorReporter()); + + tflite::SubgraphAllocations *subgraph_allocations = + allocator->StartModelAllocation(model); + TF_LITE_MICRO_EXPECT(nullptr != subgraph_allocations); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, allocator->FinishModelAllocation(model, subgraph_allocations, + &scratch_buffer_handles)); + + uint8_t *start = subgraph_allocations[0].tensors[0].data.uint8; + TF_LITE_MICRO_EXPECT_EQ( + 0, subgraph_allocations[0].tensors[0].data.uint8 - start); + TF_LITE_MICRO_EXPECT_EQ( + 48, subgraph_allocations[0].tensors[1].data.uint8 - start); + TF_LITE_MICRO_EXPECT_EQ( + 96, subgraph_allocations[0].tensors[2].data.uint8 - start); + TF_LITE_MICRO_EXPECT_EQ( + 48, subgraph_allocations[0].tensors[4].data.uint8 - start); + TF_LITE_MICRO_EXPECT_EQ( + 0, subgraph_allocations[0].tensors[3].data.uint8 - start); +} + +TF_LITE_MICRO_TEST(TestAllocatePersistentTfLiteTensor) +{ + const tflite::Model *model = tflite::GetModel(kTestConvModelData); + constexpr size_t arena_size = 1024 * 12; + uint8_t arena[arena_size]; + tflite::MicroAllocator *allocator = tflite::MicroAllocator::Create( + arena, arena_size, tflite::GetMicroErrorReporter()); + TF_LITE_MICRO_EXPECT_NE(allocator, nullptr); + + TfLiteTensor *tensor1 = allocator->AllocatePersistentTfLiteTensor( + model, /*subgraph_allocations=*/nullptr, /*tensor_index=*/1, + /*subgraph_index=*/0); + TF_LITE_MICRO_EXPECT_NE(tensor1, nullptr); + TF_LITE_MICRO_EXPECT_NE(tensor1->quantization.params, nullptr); + TF_LITE_MICRO_EXPECT_FALSE(tensor1->is_variable); + + TfLiteTensor *tensor2 = allocator->AllocatePersistentTfLiteTensor( + model, /*subgraph_allocations=*/nullptr, /*tensor_index=*/2, + /*subgraph_index=*/0); + TF_LITE_MICRO_EXPECT_NE(tensor2, nullptr); + TF_LITE_MICRO_EXPECT_NE(tensor2->quantization.params, nullptr); + TF_LITE_MICRO_EXPECT_FALSE(tensor2->is_variable); + + // The address of tensor1 should be higher than the address of tensor2 since + // persistent allocations take place in the tail which grows downward. + TF_LITE_MICRO_EXPECT_GT(tensor1, tensor2); +} + +TF_LITE_MICRO_TEST(TestAllocateSingleTempTfLiteTensor) +{ + const tflite::Model *model = tflite::testing::GetSimpleMockModel(); + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::MicroAllocator *allocator = tflite::MicroAllocator::Create( + arena, arena_size, tflite::GetMicroErrorReporter()); + TF_LITE_MICRO_EXPECT_NE(allocator, nullptr); + + TfLiteTensor *tensor1 = allocator->AllocateTempTfLiteTensor( + model, /*subgraph_allocations=*/nullptr, /*tensor_index=*/1, + /*subgraph_index=*/0); + TF_LITE_MICRO_EXPECT_NE(tensor1, nullptr); +} + +TF_LITE_MICRO_TEST(TestAllocateChainOfTfLiteTensor) +{ + const tflite::Model *model = tflite::testing::GetSimpleMockModel(); + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::MicroAllocator *allocator = tflite::MicroAllocator::Create( + arena, arena_size, tflite::GetMicroErrorReporter()); + TF_LITE_MICRO_EXPECT_NE(allocator, nullptr); + + TfLiteTensor *tensor1 = allocator->AllocateTempTfLiteTensor( + model, /*subgraph_allocations=*/nullptr, /*tensor_index=*/1, + /*subgraph_index=*/0); + TF_LITE_MICRO_EXPECT_NE(tensor1, nullptr); + + TfLiteTensor *tensor2 = allocator->AllocateTempTfLiteTensor( + model, /*subgraph_allocations=*/nullptr, /*tensor_index=*/2, + /*subgraph_index=*/0); + TF_LITE_MICRO_EXPECT_NE(tensor2, nullptr); + + // The address of tensor2 should be higher than the address of tensor1 + // (chained allocations): + TF_LITE_MICRO_EXPECT_GT(tensor2, tensor1); +} + +TF_LITE_MICRO_TEST(TestAllocateTfLiteTensorWithReset) +{ + const tflite::Model *model = tflite::testing::GetSimpleMockModel(); + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::MicroAllocator *allocator = tflite::MicroAllocator::Create( + arena, arena_size, tflite::GetMicroErrorReporter()); + TF_LITE_MICRO_EXPECT(allocator != nullptr); + + TfLiteTensor *tensor1 = allocator->AllocateTempTfLiteTensor( + model, /*subgraph_allocations=*/nullptr, /*tensor_index=*/1, + /*subgraph_index=*/0); + TF_LITE_MICRO_EXPECT(tensor1 != nullptr); + + allocator->ResetTempAllocations(); + + TfLiteTensor *tensor2 = allocator->AllocateTempTfLiteTensor( + model, /*subgraph_allocations=*/nullptr, /*tensor_index=*/2, + /*subgraph_index=*/0); + TF_LITE_MICRO_EXPECT(tensor2 != nullptr); + + // The address of tensor2 should be equal than the address of tensor1 since + // allocations were not chained: + TF_LITE_MICRO_EXPECT(tensor2 == tensor1); +} + +TF_LITE_MICRO_TEST(TestOperatorInputsNotInSubgraphInputs) +{ + constexpr int number_tensors = 5; + tflite::AllOpsResolver op_resolver = tflite::testing::GetOpResolver(); + const int32_t metadata_buffer[tflite::testing::kOfflinePlannerHeaderSize + + number_tensors] = { /*version=*/1, + /*subgraph=*/0, + number_tensors, + /*t0=*/0, + /*t1=*/0, + /*t2=*/0, + /*t3=*/48, + /*t4=*/-1 }; + + constexpr int number_connections = 2; + tflite::testing::NodeConnection node_list[number_connections] = { + { // t0: input (actual input part of subgraph inputs as + // well as operator inputs) + // t1: scratch1 (only in operator inputs) + // t2: scratch2 (only in operator inputs) + { tflite::testing::t0, tflite::testing::t1, tflite::testing::t2 }, + /*t3: output=*/{ tflite::testing::t3 } }, + { /*t3: input=*/{ tflite::testing::t3 }, + /*t4: output=*/{ tflite::testing::t4 } }, + }; + + const tflite::Model *model = tflite::testing::GetModelWithOfflinePlanning( + number_tensors, metadata_buffer, node_list, number_connections, + /*Only first tensor (t0) is in subgraph input list=*/1); + + tflite::ScratchBufferHandle *scratch_buffer_handles = nullptr; + constexpr size_t arena_size = 4096; + uint8_t arena[arena_size]; + tflite::MicroAllocator *allocator = tflite::MicroAllocator::Create( + arena, arena_size, tflite::GetMicroErrorReporter()); + + tflite::SubgraphAllocations *subgraph_allocations = + allocator->StartModelAllocation(model); + TF_LITE_MICRO_EXPECT(nullptr != subgraph_allocations); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, allocator->FinishModelAllocation(model, subgraph_allocations, + &scratch_buffer_handles)); + + uint8_t *start = subgraph_allocations[0].tensors[0].data.uint8; + TF_LITE_MICRO_EXPECT_EQ( + 0, subgraph_allocations[0].tensors[0].data.uint8 - start); + TF_LITE_MICRO_EXPECT_EQ( + 0, subgraph_allocations[0].tensors[1].data.uint8 - start); + TF_LITE_MICRO_EXPECT_EQ( + 0, subgraph_allocations[0].tensors[2].data.uint8 - start); + TF_LITE_MICRO_EXPECT_EQ( + 48, subgraph_allocations[0].tensors[3].data.uint8 - start); + TF_LITE_MICRO_EXPECT_EQ( + 0, subgraph_allocations[0].tensors[4].data.uint8 - start); +} + +TF_LITE_MICRO_TEST(TestTypicalFirstOpAndSecondOpWithScratchTensors) +{ + constexpr int number_tensors = 6; + tflite::AllOpsResolver op_resolver = tflite::testing::GetOpResolver(); + const int32_t metadata_buffer[tflite::testing::kOfflinePlannerHeaderSize + + number_tensors] = { /*version=*/1, + /*subgraph=*/0, + number_tensors, + /*t0=*/0, + /*t1=*/0, + /*t2=*/0, + /*t3=*/0, + /*t4=*/48, + /*t5=*/-1 }; + + constexpr int number_connections = 3; + tflite::testing::NodeConnection node_list[number_connections] = { + { /*t0: input (subgraph and operator input)=*/{ tflite::testing::t0 }, + /*t1: output=*/{ tflite::testing::t1 } }, + { // t1: input + // t2: scratch1 (only in operator inputs) + // t3: scratch2 (only in operator inputs) + { tflite::testing::t1, tflite::testing::t2, tflite::testing::t3 }, + + /*t4: output=*/{ tflite::testing::t4 } }, + { /*t4: input=*/{ tflite::testing::t4 }, + /*t5: output=*/{ tflite::testing::t5 } }, + }; + + const tflite::Model *model = tflite::testing::GetModelWithOfflinePlanning( + number_tensors, metadata_buffer, node_list, number_connections, + /*Only first tensor (t0) is in subgraph input list=*/1); + + tflite::ScratchBufferHandle *scratch_buffer_handles = nullptr; + constexpr size_t arena_size = 4096; + uint8_t arena[arena_size]; + tflite::MicroAllocator *allocator = tflite::MicroAllocator::Create( + arena, arena_size, tflite::GetMicroErrorReporter()); + + tflite::SubgraphAllocations *subgraph_allocations = + allocator->StartModelAllocation(model); + TF_LITE_MICRO_EXPECT(nullptr != subgraph_allocations); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, allocator->FinishModelAllocation(model, subgraph_allocations, + &scratch_buffer_handles)); + + uint8_t *start = subgraph_allocations[0].tensors[0].data.uint8; + TF_LITE_MICRO_EXPECT_EQ( + 0, subgraph_allocations[0].tensors[0].data.uint8 - start); + TF_LITE_MICRO_EXPECT_EQ( + 0, subgraph_allocations[0].tensors[1].data.uint8 - start); + TF_LITE_MICRO_EXPECT_EQ( + 0, subgraph_allocations[0].tensors[2].data.uint8 - start); + TF_LITE_MICRO_EXPECT_EQ( + 0, subgraph_allocations[0].tensors[3].data.uint8 - start); + TF_LITE_MICRO_EXPECT_EQ( + 48, subgraph_allocations[0].tensors[4].data.uint8 - start); + TF_LITE_MICRO_EXPECT_EQ( + 0, subgraph_allocations[0].tensors[5].data.uint8 - start); +} + +TF_LITE_MICRO_TEST(TestModelWithUnusedTensors) +{ + tflite::AllOpsResolver op_resolver = tflite::testing::GetOpResolver(); + + const tflite::Model *model = tflite::testing::GetModelWithUnusedInputs(); + + tflite::ScratchBufferHandle *scratch_buffer_handles = nullptr; + constexpr size_t arena_size = 4096; + uint8_t arena[arena_size]; + tflite::MicroAllocator *allocator = tflite::MicroAllocator::Create( + arena, arena_size, tflite::GetMicroErrorReporter()); + + tflite::SubgraphAllocations *subgraph_allocations = + allocator->StartModelAllocation(model); + TF_LITE_MICRO_EXPECT(nullptr != subgraph_allocations); + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, allocator->FinishModelAllocation(model, subgraph_allocations, + &scratch_buffer_handles)); + + // Unused input tensor should not occupy any space. + uint8_t *start = subgraph_allocations[0].tensors[2].data.uint8; + TF_LITE_MICRO_EXPECT_EQ( + 64, subgraph_allocations[0].tensors[0].data.uint8 - start); + TF_LITE_MICRO_EXPECT_EQ( + 0, subgraph_allocations[0].tensors[1].data.uint8 - start); + TF_LITE_MICRO_EXPECT_EQ( + 0, subgraph_allocations[0].tensors[2].data.uint8 - start); + // Unused tensor should not occupy any space. + TF_LITE_MICRO_EXPECT_EQ( + 0, subgraph_allocations[0].tensors[3].data.uint8 - start); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/micro_error_reporter.cc b/components/tflite/tensorflow/lite/micro/micro_error_reporter.cc new file mode 100644 index 00000000..eb1820f2 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_error_reporter.cc @@ -0,0 +1,72 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/micro_error_reporter.h" + +#include +#include +#include + +#if !defined(TF_LITE_STRIP_ERROR_STRINGS) +#include "tensorflow/lite/micro/debug_log.h" +#include "tensorflow/lite/micro/micro_string.h" +#endif + +namespace { +uint8_t micro_error_reporter_buffer[sizeof(tflite::MicroErrorReporter)]; +tflite::MicroErrorReporter *error_reporter_ = nullptr; + +void Log(const char *format, va_list args) +{ +#if !defined(TF_LITE_STRIP_ERROR_STRINGS) + // Only pulling in the implementation of this function for builds where we + // expect to make use of it to be extra cautious about not increasing the code + // size. + static constexpr int kMaxLogLen = 256; + char log_buffer[kMaxLogLen]; + MicroVsnprintf(log_buffer, kMaxLogLen, format, args); + DebugLog(log_buffer); + DebugLog("\r\n"); +#endif +} + +} // namespace + +#if !defined(TF_LITE_STRIP_ERROR_STRINGS) +void MicroPrintf(const char *format, ...) +{ + va_list args; + va_start(args, format); + Log(format, args); + va_end(args); +} +#endif + +namespace tflite { +ErrorReporter *GetMicroErrorReporter() +{ + if (error_reporter_ == nullptr) { + error_reporter_ = new (micro_error_reporter_buffer) MicroErrorReporter(); + } + return error_reporter_; +} + +int MicroErrorReporter::Report(const char *format, va_list args) +{ + Log(format, args); + return 0; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/micro_error_reporter.h b/components/tflite/tensorflow/lite/micro/micro_error_reporter.h new file mode 100644 index 00000000..d30394bd --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_error_reporter.h @@ -0,0 +1,50 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_MICRO_MICRO_ERROR_REPORTER_H_ +#define TENSORFLOW_LITE_MICRO_MICRO_ERROR_REPORTER_H_ + +#include + +#include "tensorflow/lite/core/api/error_reporter.h" +#include "tensorflow/lite/micro/compatibility.h" + +#if !defined(TF_LITE_STRIP_ERROR_STRINGS) +// This function can be used independent of the MicroErrorReporter to get +// printf-like functionalitys and are common to all target platforms. +void MicroPrintf(const char *format, ...); +#else +// We use a #define to ensure that the strings are completely stripped, to +// prevent an unnecessary increase in the binary size. +#define MicroPrintf(format, ...) +#endif + +namespace tflite { +// Get a pointer to a singleton global error reporter. +ErrorReporter *GetMicroErrorReporter(); + +class MicroErrorReporter : public ErrorReporter { +public: + ~MicroErrorReporter() override + { + } + int Report(const char *format, va_list args) override; + +private: + TF_LITE_REMOVE_VIRTUAL_DELETE +}; + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_MICRO_ERROR_REPORTER_H_ diff --git a/components/tflite/tensorflow/lite/micro/micro_error_reporter_test.cc b/components/tflite/tensorflow/lite/micro/micro_error_reporter_test.cc new file mode 100644 index 00000000..d21101cb --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_error_reporter_test.cc @@ -0,0 +1,29 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/micro_error_reporter.h" + +int main(int argc, char **argv) +{ +#ifndef TF_LITE_STRIP_ERROR_STRINGS + tflite::MicroErrorReporter micro_error_reporter; + tflite::ErrorReporter *error_reporter = µ_error_reporter; + TF_LITE_REPORT_ERROR(error_reporter, "Number: %d", 42); + TF_LITE_REPORT_ERROR(error_reporter, "Badly-formed format string %"); + TF_LITE_REPORT_ERROR(error_reporter, + "Another % badly-formed %% format string"); + TF_LITE_REPORT_ERROR(error_reporter, "~~~%s~~~", "ALL TESTS PASSED"); +#endif // !defined(TF_LITE_STRIP_ERROR_STRINGS) +} diff --git a/components/tflite/tensorflow/lite/micro/micro_graph.cc b/components/tflite/tensorflow/lite/micro/micro_graph.cc new file mode 100644 index 00000000..1a310fb4 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_graph.cc @@ -0,0 +1,264 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/micro_graph.h" + +#include "flatbuffers/flatbuffers.h" // from @flatbuffers +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/micro/memory_helpers.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/micro_profiler.h" +#include "tensorflow/lite/schema/schema_generated.h" + +namespace tflite { +namespace { + +#ifndef TF_LITE_STRIP_ERROR_STRINGS +const char *OpNameFromRegistration(const TfLiteRegistration *registration) +{ + if (registration->builtin_code == BuiltinOperator_CUSTOM) { + return registration->custom_name; + } else { + return EnumNameBuiltinOperator(BuiltinOperator(registration->builtin_code)); + } +} +#endif // !defined(TF_LITE_STRIP_ERROR_STRINGS) + +} // namespace + +MicroGraph::MicroGraph(TfLiteContext *context, const Model *model, + MicroAllocator *allocator) + : context_(context), + model_(model), + allocator_(allocator), + current_subgraph_index_(0) +{ + if (model != nullptr) { + subgraphs_ = model->subgraphs(); + } +} + +MicroGraph::~MicroGraph() +{ +} + +TfLiteStatus MicroGraph::InitSubgraphs() +{ + int previous_subgraph_idx = current_subgraph_index_; + + for (size_t subgraph_idx = 0; subgraph_idx < subgraphs_->size(); + subgraph_idx++) { + current_subgraph_index_ = subgraph_idx; + + const SubGraph *subgraph = (*subgraphs_)[subgraph_idx]; + for (size_t i = 0; i < subgraph->operators()->size(); ++i) { + TfLiteNode *node = + &(subgraph_allocations_[subgraph_idx].node_and_registrations[i].node); + const TfLiteRegistration *registration = + subgraph_allocations_[subgraph_idx] + .node_and_registrations[i] + .registration; + size_t init_data_size; + const char *init_data; + if (registration->builtin_code == BuiltinOperator_CUSTOM) { + init_data = reinterpret_cast(node->custom_initial_data); + init_data_size = node->custom_initial_data_size; + } else { + init_data = reinterpret_cast(node->builtin_data); + init_data_size = 0; + } + if (registration->init) { + node->user_data = + registration->init(context_, init_data, init_data_size); + } + } + } + current_subgraph_index_ = previous_subgraph_idx; + + return kTfLiteOk; +} + +TfLiteStatus MicroGraph::PrepareSubgraphs() +{ + int previous_subgraph_idx = current_subgraph_index_; + + for (size_t subgraph_idx = 0; subgraph_idx < subgraphs_->size(); + subgraph_idx++) { + current_subgraph_index_ = subgraph_idx; + + const SubGraph *subgraph = (*subgraphs_)[subgraph_idx]; + for (size_t i = 0; i < subgraph->operators()->size(); ++i) { + TfLiteNode *node = + &(subgraph_allocations_[subgraph_idx].node_and_registrations[i].node); + const TfLiteRegistration *registration = + subgraph_allocations_[subgraph_idx] + .node_and_registrations[i] + .registration; + if (registration->prepare != nullptr) { + TfLiteStatus prepare_status = registration->prepare(context_, node); + if (prepare_status != kTfLiteOk) { + MicroPrintf("Node %s (number %df) failed to prepare with status %d", + OpNameFromRegistration(registration), i, prepare_status); + return kTfLiteError; + } + } + allocator_->FinishPrepareNodeAllocations(/*node_id=*/i); + } + } + current_subgraph_index_ = previous_subgraph_idx; + + return kTfLiteOk; +} + +TfLiteStatus MicroGraph::FreeSubgraphs() +{ + int previous_subgraph_idx = current_subgraph_index_; + + for (size_t subgraph_idx = 0; subgraph_idx < subgraphs_->size(); + subgraph_idx++) { + current_subgraph_index_ = subgraph_idx; + const SubGraph *subgraph = (*subgraphs_)[subgraph_idx]; + for (size_t i = 0; i < subgraph->operators()->size(); ++i) { + TfLiteNode *node = + &(subgraph_allocations_[subgraph_idx].node_and_registrations[i].node); + const TfLiteRegistration *registration = + subgraph_allocations_[subgraph_idx] + .node_and_registrations[i] + .registration; + // registration is allocated outside the interpreter, so double check to + // make sure it's not nullptr; + if (registration != nullptr && registration->free != nullptr) { + registration->free(context_, node->user_data); + } + } + } + current_subgraph_index_ = previous_subgraph_idx; + + return kTfLiteOk; +} + +TfLiteStatus MicroGraph::InvokeSubgraph(int subgraph_idx) +{ + int previous_subgraph_idx = current_subgraph_index_; + current_subgraph_index_ = subgraph_idx; + + if (static_cast(subgraph_idx) >= subgraphs_->size()) { + MicroPrintf("Accessing subgraph %d but only %d subgraphs found", + subgraph_idx, subgraphs_->size()); + return kTfLiteError; + } + const SubGraph *subgraph = (*subgraphs_)[subgraph_idx]; + + for (size_t i = 0; i < subgraph->operators()->size(); ++i) { + TfLiteNode *node = + &(subgraph_allocations_[subgraph_idx].node_and_registrations[i].node); + const TfLiteRegistration *registration = subgraph_allocations_[subgraph_idx] + .node_and_registrations[i] + .registration; + +// This ifdef is needed (even though ScopedMicroProfiler itself is a no-op with +// -DTF_LITE_STRIP_ERROR_STRINGS) because the function OpNameFromRegistration is +// only defined for builds with the error strings. +#if !defined(TF_LITE_STRIP_ERROR_STRINGS) + ScopedMicroProfiler scoped_profiler( + OpNameFromRegistration(registration), + reinterpret_cast(context_->profiler)); +#endif + + TFLITE_DCHECK(registration->invoke); + TfLiteStatus invoke_status = registration->invoke(context_, node); + + // All TfLiteTensor structs used in the kernel are allocated from temp + // memory in the allocator. This creates a chain of allocations in the + // temp section. The call below resets the chain of allocations to + // prepare for the next call. + allocator_->ResetTempAllocations(); + + if (invoke_status == kTfLiteError) { + MicroPrintf("Node %s (number %d) failed to invoke with status %d", + OpNameFromRegistration(registration), i, invoke_status); + return kTfLiteError; + } else if (invoke_status != kTfLiteOk) { + return invoke_status; + } + } + current_subgraph_index_ = previous_subgraph_idx; + return kTfLiteOk; +} + +TfLiteStatus MicroGraph::ResetVariableTensors() +{ + for (size_t subgraph_idx = 0; subgraph_idx < subgraphs_->size(); + subgraph_idx++) { + const SubGraph *subgraph = (*subgraphs_)[subgraph_idx]; + for (size_t i = 0; i < subgraph->tensors()->size(); ++i) { + auto *tensor = subgraph->tensors()->Get(i); + if (tensor->is_variable()) { + size_t buffer_size; + TF_LITE_ENSURE_STATUS(TfLiteEvalTensorByteLength( + &subgraph_allocations_[subgraph_idx].tensors[i], &buffer_size)); + + int value = 0; + if (tensor->type() == tflite::TensorType_INT8) { + value = tensor->quantization()->zero_point()->Get(0); + } + memset(subgraph_allocations_[subgraph_idx].tensors[i].data.raw, value, + buffer_size); + } + } + } + + return kTfLiteOk; +} + +int MicroGraph::NumSubgraphs() +{ + return model_->subgraphs()->size(); +} + +void MicroGraph::SetSubgraphAllocations( + SubgraphAllocations *subgraph_allocations) +{ + subgraph_allocations_ = subgraph_allocations; +} + +size_t MicroGraph::NumSubgraphInputs(int subgraph_idx) +{ + return model_->subgraphs()->Get(subgraph_idx)->inputs()->size(); +} + +TfLiteEvalTensor *MicroGraph::GetSubgraphInput(int subgraph_idx, + int input_idx) +{ + int tensor_idx = + model_->subgraphs()->Get(subgraph_idx)->inputs()->Get(input_idx); + return &subgraph_allocations_[subgraph_idx].tensors[tensor_idx]; +} + +size_t MicroGraph::NumSubgraphOutputs(int subgraph_idx) +{ + return model_->subgraphs()->Get(subgraph_idx)->outputs()->size(); +} + +TfLiteEvalTensor *MicroGraph::GetSubgraphOutput(int subgraph_idx, + int output_idx) +{ + int tensor_idx = + model_->subgraphs()->Get(subgraph_idx)->outputs()->Get(output_idx); + return &subgraph_allocations_[subgraph_idx].tensors[tensor_idx]; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/micro_graph.h b/components/tflite/tensorflow/lite/micro/micro_graph.h new file mode 100644 index 00000000..23e1dc7e --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_graph.h @@ -0,0 +1,102 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_MICRO_GRAPH_H_ +#define TENSORFLOW_LITE_MICRO_MICRO_GRAPH_H_ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/micro_allocator.h" +#include "tensorflow/lite/schema/schema_generated.h" + +namespace tflite { +// Abstracts the details of interacting with the tflite::Model. +// +// Provides methods to access, initialize, prepare, invoke and free any +// subgraph in the tflite::Graph. +class MicroGraph { +public: + // The lifetime of the context, model, and allocator must be at least as long + // as that of the graph object, since the this class may need to access them + // at any time. + MicroGraph(TfLiteContext *context, const Model *model, + MicroAllocator *allocator); + virtual ~MicroGraph(); + + // Sets up builtin data and calls TfLiteRegistration->Init for every operator + // in every subgraph in the model. + virtual TfLiteStatus InitSubgraphs(); + + // Calls TfLiteRegistration->Prepare for every operator in every subgraph in + // the model. + virtual TfLiteStatus PrepareSubgraphs(); + + // Calls TfLiteRegistration->Free for every operator in every subgraph in the + // model. + virtual TfLiteStatus FreeSubgraphs(); + + // Calls TfLiteRegistration->Invoke for every operator in a single subgraph in + // the model. + virtual TfLiteStatus InvokeSubgraph(int subgraph_idx); + + // Zeros out all variable tensors in all subgraphs in the model. + virtual TfLiteStatus ResetVariableTensors(); + + // Number of tensor inputs to a specified subgraph in the model. + virtual size_t NumSubgraphInputs(int subgraph_idx); + + // Get the specified input tensor of a specified subgraph in the model. + virtual TfLiteEvalTensor *GetSubgraphInput(int subgraph_idx, int input_idx); + + // Number of tensor outputs to a specified subgraph in the model. + virtual size_t NumSubgraphOutputs(int subgraph_idx); + + // Get the specified output tensor of a specified subgraph in the model. + virtual TfLiteEvalTensor *GetSubgraphOutput(int subgraph_idx, int output_idx); + + // Number of subgraphs in the model. + virtual int NumSubgraphs(); + + // Hook to pass in subgraph allocations tracked within the interpreter, + // allowing MicroGraph to init / prepare / invoke subgraphs in the model. + void SetSubgraphAllocations(SubgraphAllocations *subgraph_allocations); + + // Get the current subgraph index. Within an on operator, this is guaranteed + // to be the subgraph of that operator. + int GetCurrentSubgraphIndex() + { + return current_subgraph_index_; + } + + // Gets the list of alloctions for each subgraph. This is the source of truth + // for all per-subgraph allocation data. + SubgraphAllocations *GetAllocations() + { + return subgraph_allocations_; + } + +private: + TfLiteContext *context_; + const Model *model_; + MicroAllocator *allocator_; + SubgraphAllocations *subgraph_allocations_ = nullptr; + int current_subgraph_index_; + const flatbuffers::Vector > *subgraphs_; + + TF_LITE_REMOVE_VIRTUAL_DELETE +}; + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_MICRO_GRAPH_H_ diff --git a/components/tflite/tensorflow/lite/micro/micro_interpreter.cc b/components/tflite/tensorflow/lite/micro/micro_interpreter.cc new file mode 100644 index 00000000..f8aa45a4 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_interpreter.cc @@ -0,0 +1,390 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/micro/micro_interpreter.h" + +#include +#include +#include + +#include "flatbuffers/flatbuffers.h" // from @flatbuffers +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/core/api/error_reporter.h" +#include "tensorflow/lite/core/api/tensor_utils.h" +#include "tensorflow/lite/micro/memory_helpers.h" +#include "tensorflow/lite/micro/micro_allocator.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/micro_op_resolver.h" +#include "tensorflow/lite/micro/micro_profiler.h" +#include "tensorflow/lite/schema/schema_generated.h" +#include "tensorflow/lite/schema/schema_utils.h" + +namespace tflite { + +MicroInterpreter::MicroInterpreter(const Model *model, + const MicroOpResolver &op_resolver, + uint8_t *tensor_arena, + size_t tensor_arena_size, + ErrorReporter *error_reporter, + MicroProfiler *profiler) + : model_(model), + op_resolver_(op_resolver), + error_reporter_(error_reporter), + allocator_(*MicroAllocator::Create(tensor_arena, tensor_arena_size, + error_reporter)), + + graph_(&context_, model, &allocator_), + tensors_allocated_(false), + initialization_status_(kTfLiteError), + input_tensors_(nullptr), + output_tensors_(nullptr) +{ + Init(profiler); +} + +MicroInterpreter::MicroInterpreter(const Model *model, + const MicroOpResolver &op_resolver, + MicroAllocator *allocator, + ErrorReporter *error_reporter, + MicroProfiler *profiler) + : model_(model), + op_resolver_(op_resolver), + error_reporter_(error_reporter), + allocator_(*allocator), + graph_(&context_, model, allocator), + tensors_allocated_(false), + initialization_status_(kTfLiteError), + input_tensors_(nullptr), + output_tensors_(nullptr) +{ + Init(profiler); +} + +MicroInterpreter::~MicroInterpreter() +{ + if (graph_.GetAllocations() != nullptr) { + graph_.FreeSubgraphs(); + } +} + +void MicroInterpreter::Init(MicroProfiler *profiler) +{ + context_.impl_ = static_cast(this); + context_.ReportError = ReportOpError; + context_.GetTensor = GetTensor; + context_.ReportError = ReportOpError; + context_.GetTensor = GetTensor; + context_.GetEvalTensor = GetEvalTensor; + context_.profiler = profiler; + + initialization_status_ = kTfLiteOk; +} + +TfLiteStatus MicroInterpreter::PrepareNodeAndRegistrationDataFromFlatbuffer() +{ + for (int subgraph_idx = 0; subgraph_idx < graph_.NumSubgraphs(); + subgraph_idx++) { + const SubGraph *subgraph = model_->subgraphs()->Get(subgraph_idx); + TFLITE_DCHECK(subgraph != nullptr); + + auto *opcodes = model_->operator_codes(); + BuiltinDataAllocator *builtin_data_allocator = + allocator_.GetBuiltinDataAllocator(); + for (size_t i = 0; i < subgraph->operators()->size(); ++i) { + const auto *op = subgraph->operators()->Get(i); + const size_t index = op->opcode_index(); + if (index >= opcodes->size()) { + MicroPrintf("Missing registration for opcode_index %d\n", index); + return kTfLiteError; + } + const auto *opcode = opcodes->Get(index); + TfLiteStatus status = + GetRegistrationFromOpCode(opcode, op_resolver_, error_reporter_, + &(graph_.GetAllocations()[subgraph_idx] + .node_and_registrations[i] + .registration)); + if (status != kTfLiteOk) { + MicroPrintf("Failed to get registration from op code %s\n ", + EnumNameBuiltinOperator(GetBuiltinCode(opcode))); + return status; + } + const auto *registration = graph_.GetAllocations()[subgraph_idx] + .node_and_registrations[i] + .registration; + if (registration == nullptr) { + MicroPrintf("Skipping op for opcode_index %d\n", index); + return kTfLiteError; + } + BuiltinOperator op_type = + static_cast(registration->builtin_code); + + const char *custom_data = nullptr; + size_t custom_data_size = 0; + unsigned char *builtin_data = nullptr; + + if (op_type == BuiltinOperator_CUSTOM) { + // Custom Ops may or may not have a non-null custom_options field. + if (op->custom_options() != nullptr) { + custom_data = + reinterpret_cast(op->custom_options()->data()); + custom_data_size = op->custom_options()->size(); + } + } else { + if (op->custom_options() != nullptr) { + MicroPrintf( + "Unsupported behavior: found builtin operator %s with custom " + "options.\n", + EnumNameBuiltinOperator(op_type)); + return kTfLiteError; + } + + MicroOpResolver::BuiltinParseFunction parser = + op_resolver_.GetOpDataParser(op_type); + if (parser == nullptr) { + MicroPrintf("Did not find a parser for %s", + EnumNameBuiltinOperator(op_type)); + + return kTfLiteError; + } + TF_LITE_ENSURE_STATUS(parser(op, error_reporter_, + builtin_data_allocator, + (void **)(&builtin_data))); + } + + TfLiteIntArray *inputs_array; + TF_LITE_ENSURE_STATUS(allocator_.FlatBufferVectorToTfLiteTypeArray( + op->inputs(), &inputs_array)); + + TfLiteIntArray *outputs_array; + TF_LITE_ENSURE_STATUS(allocator_.FlatBufferVectorToTfLiteTypeArray( + op->outputs(), &outputs_array)); + + TfLiteNode *node = &( + graph_.GetAllocations()[subgraph_idx].node_and_registrations[i].node); + *node = {}; + node->inputs = inputs_array; + node->outputs = outputs_array; + node->builtin_data = reinterpret_cast(builtin_data); + node->custom_initial_data = custom_data; + node->custom_initial_data_size = custom_data_size; + } + } + return kTfLiteOk; +} + +TfLiteStatus MicroInterpreter::AllocateTensors() +{ + SubgraphAllocations *allocations = allocator_.StartModelAllocation(model_); + + if (allocations == nullptr) { + TF_LITE_REPORT_ERROR(error_reporter_, + "Failed starting model allocation.\n"); + initialization_status_ = kTfLiteError; + return kTfLiteError; + } + + graph_.SetSubgraphAllocations(allocations); + + TF_LITE_ENSURE_STATUS(PrepareNodeAndRegistrationDataFromFlatbuffer()); + + // Only allow AllocatePersistentBuffer in Init stage. + context_.AllocatePersistentBuffer = AllocatePersistentBuffer; + context_.RequestScratchBufferInArena = nullptr; + context_.GetScratchBuffer = nullptr; + context_.GetExecutionPlan = GetGraph; + graph_.InitSubgraphs(); + + // Both AllocatePersistentBuffer and RequestScratchBufferInArena is + // available in Prepare stage. + context_.RequestScratchBufferInArena = RequestScratchBufferInArena; + graph_.PrepareSubgraphs(); + + // Prepare is done, we're ready for Invoke. Memory allocation is no longer + // allowed. Kernels can only fetch scratch buffers via GetScratchBuffer. + context_.AllocatePersistentBuffer = nullptr; + context_.RequestScratchBufferInArena = nullptr; + context_.GetScratchBuffer = GetScratchBuffer; + + TF_LITE_ENSURE_OK(&context_, allocator_.FinishModelAllocation( + model_, graph_.GetAllocations(), + &scratch_buffer_handles_)); + + // TODO(b/162311891): Drop these allocations when the interpreter supports + // handling buffers from TfLiteEvalTensor. + input_tensors_ = + reinterpret_cast(allocator_.AllocatePersistentBuffer( + sizeof(TfLiteTensor *) * inputs_size())); + if (input_tensors_ == nullptr) { + TF_LITE_REPORT_ERROR( + error_reporter_, + "Failed to allocate memory for context->input_tensors_, " + "%d bytes required", + sizeof(TfLiteTensor *) * inputs_size()); + return kTfLiteError; + } + + for (size_t i = 0; i < inputs_size(); ++i) { + input_tensors_[i] = allocator_.AllocatePersistentTfLiteTensor( + model_, graph_.GetAllocations(), inputs().Get(i), 0); + if (input_tensors_[i] == nullptr) { + TF_LITE_REPORT_ERROR(error_reporter_, + "Failed to initialize input tensor %d", i); + return kTfLiteError; + } + } + + // TODO(b/162311891): Drop these allocations when the interpreter supports + // handling buffers from TfLiteEvalTensor. + output_tensors_ = + reinterpret_cast(allocator_.AllocatePersistentBuffer( + sizeof(TfLiteTensor *) * outputs_size())); + if (output_tensors_ == nullptr) { + TF_LITE_REPORT_ERROR( + error_reporter_, + "Failed to allocate memory for context->output_tensors_, " + "%d bytes required", + sizeof(TfLiteTensor *) * outputs_size()); + return kTfLiteError; + } + + for (size_t i = 0; i < outputs_size(); ++i) { + output_tensors_[i] = allocator_.AllocatePersistentTfLiteTensor( + model_, graph_.GetAllocations(), outputs().Get(i), 0); + if (output_tensors_[i] == nullptr) { + TF_LITE_REPORT_ERROR(error_reporter_, + "Failed to initialize output tensor %d", i); + return kTfLiteError; + } + } + + TF_LITE_ENSURE_STATUS(ResetVariableTensors()); + + tensors_allocated_ = true; + return kTfLiteOk; +} + +TfLiteStatus MicroInterpreter::Invoke() +{ + if (initialization_status_ != kTfLiteOk) { + TF_LITE_REPORT_ERROR(error_reporter_, + "Invoke() called after initialization failed\n"); + return kTfLiteError; + } + + // Ensure tensors are allocated before the interpreter is invoked to avoid + // difficult to debug segfaults. + if (!tensors_allocated_) { + TF_LITE_ENSURE_OK(&context_, AllocateTensors()); + } + return graph_.InvokeSubgraph(0); +} + +TfLiteTensor *MicroInterpreter::input(size_t index) +{ + const size_t length = inputs_size(); + if (index >= length) { + TF_LITE_REPORT_ERROR(error_reporter_, + "Input index %d out of range (length is %d)", index, + length); + return nullptr; + } + return input_tensors_[index]; +} + +TfLiteTensor *MicroInterpreter::output(size_t index) +{ + const size_t length = outputs_size(); + if (index >= length) { + TF_LITE_REPORT_ERROR(error_reporter_, + "Output index %d out of range (length is %d)", index, + length); + return nullptr; + } + return output_tensors_[index]; +} + +TfLiteStatus MicroInterpreter::ResetVariableTensors() +{ + return graph_.ResetVariableTensors(); +} + +void *MicroInterpreter::AllocatePersistentBuffer(TfLiteContext *ctx, + size_t bytes) +{ + return reinterpret_cast(ctx->impl_) + ->allocator_.AllocatePersistentBuffer(bytes); +} + +TfLiteStatus MicroInterpreter::RequestScratchBufferInArena(TfLiteContext *ctx, + size_t bytes, + int *buffer_idx) +{ + MicroInterpreter *interpreter = + reinterpret_cast(ctx->impl_); + return interpreter->allocator_.RequestScratchBufferInArena( + bytes, interpreter->graph_.GetCurrentSubgraphIndex(), buffer_idx); +} + +void *MicroInterpreter::GetScratchBuffer(TfLiteContext *ctx, int buffer_idx) +{ + MicroInterpreter *interpreter = + reinterpret_cast(ctx->impl_); + ScratchBufferHandle *handle = + interpreter->scratch_buffer_handles_ + buffer_idx; + return handle->data; +} + +void MicroInterpreter::ReportOpError(struct TfLiteContext *context, + const char *format, ...) +{ +#ifndef TF_LITE_STRIP_ERROR_STRINGS + MicroInterpreter *interpreter = + static_cast(context->impl_); + va_list args; + va_start(args, format); + TF_LITE_REPORT_ERROR(interpreter->error_reporter_, format, args); + va_end(args); +#endif +} + +TfLiteTensor *MicroInterpreter::GetTensor(const struct TfLiteContext *context, + int tensor_idx) +{ + MicroInterpreter *interpreter = + static_cast(context->impl_); + return interpreter->allocator_.AllocateTempTfLiteTensor( + interpreter->model_, interpreter->graph_.GetAllocations(), tensor_idx, + interpreter->get_subgraph_index()); +} + +TfLiteEvalTensor *MicroInterpreter::GetEvalTensor( + const struct TfLiteContext *context, int tensor_idx) +{ + MicroInterpreter *interpreter = + reinterpret_cast(context->impl_); + return &interpreter->graph_ + .GetAllocations()[interpreter->get_subgraph_index()] + .tensors[tensor_idx]; +} + +TfLiteStatus MicroInterpreter::GetGraph(struct TfLiteContext *context, + TfLiteIntArray **args) +{ + MicroInterpreter *interpreter = + reinterpret_cast(context->impl_); + *args = reinterpret_cast(&interpreter->graph_); + return kTfLiteOk; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/micro_interpreter.h b/components/tflite/tensorflow/lite/micro/micro_interpreter.h new file mode 100644 index 00000000..381c561a --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_interpreter.h @@ -0,0 +1,205 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_MICRO_MICRO_INTERPRETER_H_ +#define TENSORFLOW_LITE_MICRO_MICRO_INTERPRETER_H_ + +#include +#include + +#include "flatbuffers/flatbuffers.h" // from @flatbuffers +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/core/api/error_reporter.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/micro/micro_allocator.h" +#include "tensorflow/lite/micro/micro_graph.h" +#include "tensorflow/lite/micro/micro_op_resolver.h" +#include "tensorflow/lite/micro/micro_profiler.h" +#include "tensorflow/lite/portable_type_to_tflitetype.h" +#include "tensorflow/lite/schema/schema_generated.h" + +// Copied from tensorflow/lite/version.h to avoid a dependency chain into +// tensorflow/core. +#define TFLITE_SCHEMA_VERSION (3) + +namespace tflite { +class MicroInterpreter { +public: + // The lifetime of the model, op resolver, tensor arena, error reporter and + // profiler must be at least as long as that of the interpreter object, since + // the interpreter may need to access them at any time. This means that you + // should usually create them with the same scope as each other, for example + // having them all allocated on the stack as local variables through a + // top-level function. The interpreter doesn't do any deallocation of any of + // the pointed-to objects, ownership remains with the caller. + MicroInterpreter(const Model *model, const MicroOpResolver &op_resolver, + uint8_t *tensor_arena, size_t tensor_arena_size, + ErrorReporter *error_reporter, + MicroProfiler *profiler = nullptr); + + // Create an interpreter instance using an existing MicroAllocator instance. + // This constructor should be used when creating an allocator that needs to + // have allocation handled in more than one interpreter or for recording + // allocations inside the interpreter. The lifetime of the allocator must be + // as long as that of the interpreter object. + MicroInterpreter(const Model *model, const MicroOpResolver &op_resolver, + MicroAllocator *allocator, ErrorReporter *error_reporter, + MicroProfiler *profiler = nullptr); + + ~MicroInterpreter(); + + // Runs through the model and allocates all necessary input, output and + // intermediate tensors. + TfLiteStatus AllocateTensors(); + + // In order to support partial graph runs for strided models, this can return + // values other than kTfLiteOk and kTfLiteError. + // TODO(b/149795762): Add this to the TfLiteStatus enum. + TfLiteStatus Invoke(); + + TfLiteTensor *input(size_t index); + size_t inputs_size() const + { + return model_->subgraphs()->Get(0)->inputs()->size(); + } + const flatbuffers::Vector &inputs() const + { + return *model_->subgraphs()->Get(0)->inputs(); + } + TfLiteTensor *input_tensor(size_t index) + { + return input(index); + } + template + T *typed_input_tensor(int tensor_index) + { + if (TfLiteTensor *tensor_ptr = input_tensor(tensor_index)) { + if (tensor_ptr->type == typeToTfLiteType()) { + return GetTensorData(tensor_ptr); + } + } + return nullptr; + } + + TfLiteTensor *output(size_t index); + size_t outputs_size() const + { + return model_->subgraphs()->Get(0)->outputs()->size(); + } + const flatbuffers::Vector &outputs() const + { + return *model_->subgraphs()->Get(0)->outputs(); + } + TfLiteTensor *output_tensor(size_t index) + { + return output(index); + } + template + T *typed_output_tensor(int tensor_index) + { + if (TfLiteTensor *tensor_ptr = output_tensor(tensor_index)) { + if (tensor_ptr->type == typeToTfLiteType()) { + return GetTensorData(tensor_ptr); + } + } + return nullptr; + } + + // Reset all variable tensors to the default value. + TfLiteStatus ResetVariableTensors(); + + TfLiteStatus initialization_status() const + { + return initialization_status_; + } + + size_t operators_size() const + { + return model_->subgraphs()->Get(0)->operators()->size(); + } + + // Populates node and registration pointers representing the inference graph + // of the model from values inside the flatbuffer (loaded from the TfLiteModel + // instance). Persistent data (e.g. operator data) is allocated from the + // arena. + TfLiteStatus PrepareNodeAndRegistrationDataFromFlatbuffer(); + + // For debugging only. + // Returns the actual used arena in bytes. This method gives the optimal arena + // size. It's only available after `AllocateTensors` has been called. + // Note that normally `tensor_arena` requires 16 bytes alignment to fully + // utilize the space. If it's not the case, the optimial arena size would be + // arena_used_bytes() + 16. + size_t arena_used_bytes() const + { + return allocator_.used_bytes(); + } + +protected: + const MicroAllocator &allocator() const + { + return allocator_; + } + const TfLiteContext &context() const + { + return context_; + } + +private: + // TODO(b/158263161): Consider switching to Create() function to enable better + // error reporting during initialization. + void Init(MicroProfiler *profiler); + + // Gets the current subgraph index used from within context methods. + int get_subgraph_index() + { + return graph_.GetCurrentSubgraphIndex(); + } + + // Static functions that are bound to the TfLiteContext instance: + static void *AllocatePersistentBuffer(TfLiteContext *ctx, size_t bytes); + static TfLiteStatus RequestScratchBufferInArena(TfLiteContext *ctx, + size_t bytes, + int *buffer_idx); + static void *GetScratchBuffer(TfLiteContext *ctx, int buffer_idx); + static void ReportOpError(struct TfLiteContext *context, const char *format, + ...); + static TfLiteTensor *GetTensor(const struct TfLiteContext *context, + int tensor_idx); + static TfLiteEvalTensor *GetEvalTensor(const struct TfLiteContext *context, + int tensor_idx); + static TfLiteStatus GetGraph(struct TfLiteContext *context, + TfLiteIntArray **args); + + const Model *model_; + const MicroOpResolver &op_resolver_; + ErrorReporter *error_reporter_; + TfLiteContext context_ = {}; + MicroAllocator &allocator_; + MicroGraph graph_; + bool tensors_allocated_; + + TfLiteStatus initialization_status_; + + ScratchBufferHandle *scratch_buffer_handles_ = nullptr; + + // TODO(b/162311891): Clean these pointers up when this class supports buffers + // from TfLiteEvalTensor. + TfLiteTensor **input_tensors_; + TfLiteTensor **output_tensors_; +}; + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_MICRO_INTERPRETER_H_ diff --git a/components/tflite/tensorflow/lite/micro/micro_interpreter_test.cc b/components/tflite/tensorflow/lite/micro/micro_interpreter_test.cc new file mode 100644 index 00000000..0b5cf8ba --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_interpreter_test.cc @@ -0,0 +1,499 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/micro_interpreter.h" + +#include + +#include "tensorflow/lite/core/api/flatbuffer_conversions.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/compatibility.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/micro_profiler.h" +#include "tensorflow/lite/micro/micro_utils.h" +#include "tensorflow/lite/micro/recording_micro_allocator.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace { + +class MockProfiler : public MicroProfiler { +public: + MockProfiler() + : event_starts_(0), event_ends_(0) + { + } + + uint32_t BeginEvent(const char *tag) override + { + event_starts_++; + return 0; + } + + void EndEvent(uint32_t event_handle) override + { + event_ends_++; + } + + int event_starts() + { + return event_starts_; + } + int event_ends() + { + return event_ends_; + } + +private: + int event_starts_; + int event_ends_; + + TF_LITE_REMOVE_VIRTUAL_DELETE +}; + +} // namespace +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestInterpreter) +{ + const tflite::Model *model = tflite::testing::GetSimpleMockModel(); + TF_LITE_MICRO_EXPECT_NE(nullptr, model); + + tflite::AllOpsResolver op_resolver = tflite::testing::GetOpResolver(); + + constexpr size_t allocator_buffer_size = 2000; + uint8_t allocator_buffer[allocator_buffer_size]; + + // Create a new scope so that we can test the destructor. + { + tflite::MicroInterpreter interpreter(model, op_resolver, allocator_buffer, + allocator_buffer_size, + tflite::GetMicroErrorReporter()); + TF_LITE_MICRO_EXPECT_EQ(interpreter.AllocateTensors(), kTfLiteOk); + TF_LITE_MICRO_EXPECT_LE(interpreter.arena_used_bytes(), 928 + 100); + TF_LITE_MICRO_EXPECT_EQ(static_cast(1), interpreter.inputs_size()); + TF_LITE_MICRO_EXPECT_EQ(static_cast(2), interpreter.outputs_size()); + + TfLiteTensor *input = interpreter.input(0); + TF_LITE_MICRO_EXPECT_NE(nullptr, input); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt32, input->type); + TF_LITE_MICRO_EXPECT_EQ(1, input->dims->size); + TF_LITE_MICRO_EXPECT_EQ(1, input->dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(static_cast(4), input->bytes); + TF_LITE_MICRO_EXPECT_NE(nullptr, input->data.i32); + input->data.i32[0] = 21; + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, interpreter.Invoke()); + + TfLiteTensor *output = interpreter.output(0); + TF_LITE_MICRO_EXPECT_NE(nullptr, output); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt32, output->type); + TF_LITE_MICRO_EXPECT_EQ(1, output->dims->size); + TF_LITE_MICRO_EXPECT_EQ(1, output->dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(static_cast(4), output->bytes); + TF_LITE_MICRO_EXPECT_NE(nullptr, output->data.i32); + TF_LITE_MICRO_EXPECT_EQ(42, output->data.i32[0]); + + output = interpreter.output(1); + TF_LITE_MICRO_EXPECT_NE(nullptr, output); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt32, output->type); + TF_LITE_MICRO_EXPECT_EQ(1, output->dims->size); + TF_LITE_MICRO_EXPECT_EQ(1, output->dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(static_cast(4), output->bytes); + TF_LITE_MICRO_EXPECT_NE(nullptr, output->data.i32); + TF_LITE_MICRO_EXPECT_EQ(42, output->data.i32[0]); + } + + TF_LITE_MICRO_EXPECT_EQ(tflite::testing::MockCustom::freed_, true); +} + +TF_LITE_MICRO_TEST(TestMultiTenantInterpreter) +{ + tflite::AllOpsResolver op_resolver = tflite::testing::GetOpResolver(); + constexpr size_t arena_size = 8192; + uint8_t arena[arena_size]; + + size_t simple_model_head_usage = 0, complex_model_head_usage = 0; + + // Get simple_model_head_usage. + { + tflite::RecordingMicroAllocator *allocator = + tflite::RecordingMicroAllocator::Create( + arena, arena_size, tflite::GetMicroErrorReporter()); + const tflite::Model *model0 = tflite::testing::GetSimpleMockModel(); + tflite::MicroInterpreter interpreter0(model0, op_resolver, allocator, + tflite::GetMicroErrorReporter()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, interpreter0.AllocateTensors()); + simple_model_head_usage = + allocator->GetSimpleMemoryAllocator()->GetHeadUsedBytes(); + + TfLiteTensor *input = interpreter0.input(0); + TfLiteTensor *output = interpreter0.output(0); + input->data.i32[0] = 21; + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, interpreter0.Invoke()); + TF_LITE_MICRO_EXPECT_EQ(42, output->data.i32[0]); + } + + // Shared allocator for various models. + tflite::RecordingMicroAllocator *allocator = + tflite::RecordingMicroAllocator::Create(arena, arena_size, + tflite::GetMicroErrorReporter()); + + // Get complex_model_head_usage. No head space reuse since it's the first + // model allocated in the `allocator`. + const tflite::Model *model1 = tflite::testing::GetComplexMockModel(); + tflite::MicroInterpreter interpreter1(model1, op_resolver, allocator, + tflite::GetMicroErrorReporter()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, interpreter1.AllocateTensors()); + TfLiteTensor *input1 = interpreter1.input(0); + TfLiteTensor *output1 = interpreter1.output(0); + complex_model_head_usage = + allocator->GetSimpleMemoryAllocator()->GetHeadUsedBytes(); + + // Allocate simple model from the same `allocator`. Some head space will + // be reused thanks to multi-tenant TFLM support. Also makes sure that + // the output is correct. + const tflite::Model *model2 = tflite::testing::GetSimpleMockModel(); + tflite::MicroInterpreter interpreter2(model2, op_resolver, allocator, + tflite::GetMicroErrorReporter()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, interpreter2.AllocateTensors()); + TfLiteTensor *input2 = interpreter2.input(0); + TfLiteTensor *output2 = interpreter2.output(0); + // Verify that 1 + 1 < 2. + size_t multi_tenant_head_usage = + allocator->GetSimpleMemoryAllocator()->GetHeadUsedBytes(); + TF_LITE_MICRO_EXPECT_LE(multi_tenant_head_usage, + complex_model_head_usage + simple_model_head_usage); + + // Now we have model1 and model2 sharing the same `allocator`. + // Let's make sure that they can produce correct results. + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt32, input1->type); + input1->data.i32[0] = 10; + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, interpreter1.Invoke()); + // Output tensor for the first model. + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt32, output1->type); + TF_LITE_MICRO_EXPECT_EQ(10, output1->data.i32[0]); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt32, input2->type); + input2->data.i32[0] = 21; + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, interpreter2.Invoke()); + // Output for the second model. + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt32, output2->type); + TF_LITE_MICRO_EXPECT_EQ(42, output2->data.i32[0]); + + // Allocate another complex model from the `allocator` will not increase + // head space usage. + const tflite::Model *model3 = tflite::testing::GetComplexMockModel(); + tflite::MicroInterpreter interpreter3(model3, op_resolver, allocator, + tflite::GetMicroErrorReporter()); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, interpreter3.AllocateTensors()); + TfLiteTensor *input3 = interpreter3.input(0); + TfLiteTensor *output3 = interpreter3.output(0); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt32, input3->type); + input3->data.i32[0] = 10; + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, interpreter3.Invoke()); + // Output tensor for the third model. + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt32, output3->type); + TF_LITE_MICRO_EXPECT_EQ(10, output3->data.i32[0]); + // No increase on the head usage as we're reusing the space. + TF_LITE_MICRO_EXPECT_EQ( + multi_tenant_head_usage, + allocator->GetSimpleMemoryAllocator()->GetHeadUsedBytes()); +} + +TF_LITE_MICRO_TEST(TestKernelMemoryPlanning) +{ + const tflite::Model *model = tflite::testing::GetSimpleStatefulModel(); + TF_LITE_MICRO_EXPECT_NE(nullptr, model); + + tflite::AllOpsResolver op_resolver = tflite::testing::GetOpResolver(); + + constexpr size_t allocator_buffer_size = 4096; + uint8_t allocator_buffer[allocator_buffer_size]; + + tflite::RecordingMicroAllocator *allocator = + tflite::RecordingMicroAllocator::Create(allocator_buffer, + allocator_buffer_size, + tflite::GetMicroErrorReporter()); + + // Make sure kernel memory planning works in multi-tenant context. + for (int i = 0; i < 3; i++) { + tflite::MicroInterpreter interpreter(model, op_resolver, allocator, + tflite::GetMicroErrorReporter()); + TF_LITE_MICRO_EXPECT_EQ(interpreter.AllocateTensors(), kTfLiteOk); + TF_LITE_MICRO_EXPECT_EQ(static_cast(1), interpreter.inputs_size()); + TF_LITE_MICRO_EXPECT_EQ(static_cast(2), interpreter.outputs_size()); + + TfLiteTensor *input = interpreter.input(0); + TF_LITE_MICRO_EXPECT_EQ(1, input->dims->size); + TF_LITE_MICRO_EXPECT_EQ(3, input->dims->data[0]); + input->data.uint8[0] = 2; + input->data.uint8[1] = 3; + input->data.uint8[2] = 1; + + uint8_t expected_median = 2; + + { + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, interpreter.Invoke()); + TfLiteTensor *median = interpreter.output(0); + TF_LITE_MICRO_EXPECT_EQ(expected_median, median->data.uint8[0]); + TfLiteTensor *invoke_count = interpreter.output(1); + TF_LITE_MICRO_EXPECT_EQ(1, invoke_count->data.i32[0]); + } + + { + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, interpreter.Invoke()); + TfLiteTensor *median = interpreter.output(0); + TF_LITE_MICRO_EXPECT_EQ(expected_median, median->data.uint8[0]); + TfLiteTensor *invoke_count = interpreter.output(1); + TF_LITE_MICRO_EXPECT_EQ(2, invoke_count->data.i32[0]); + } + } +} + +// The interpreter initialization requires multiple steps and this test case +// ensures that simply creating and destructing an interpreter object is ok. +// b/147830765 has one example of a change that caused trouble for this simple +// case. +TF_LITE_MICRO_TEST(TestIncompleteInitialization) +{ + const tflite::Model *model = tflite::testing::GetComplexMockModel(); + TF_LITE_MICRO_EXPECT_NE(nullptr, model); + + tflite::AllOpsResolver op_resolver = tflite::testing::GetOpResolver(); + + constexpr size_t allocator_buffer_size = 2048; + uint8_t allocator_buffer[allocator_buffer_size]; + + tflite::MicroInterpreter interpreter(model, op_resolver, allocator_buffer, + allocator_buffer_size, + tflite::GetMicroErrorReporter()); +} + +// Test that an interpreter with a supplied profiler correctly calls the +// profiler each time an operator is invoked. +TF_LITE_MICRO_TEST(InterpreterWithProfilerShouldProfileOps) +{ + const tflite::Model *model = tflite::testing::GetComplexMockModel(); + TF_LITE_MICRO_EXPECT_NE(nullptr, model); + + tflite::AllOpsResolver op_resolver = tflite::testing::GetOpResolver(); + + constexpr size_t allocator_buffer_size = 2048; + uint8_t allocator_buffer[allocator_buffer_size]; + tflite::MockProfiler profiler; + tflite::MicroInterpreter interpreter( + model, op_resolver, allocator_buffer, allocator_buffer_size, + tflite::GetMicroErrorReporter(), &profiler); + + TF_LITE_MICRO_EXPECT_EQ(profiler.event_starts(), 0); + TF_LITE_MICRO_EXPECT_EQ(profiler.event_ends(), 0); + TF_LITE_MICRO_EXPECT_EQ(interpreter.AllocateTensors(), kTfLiteOk); + TF_LITE_MICRO_EXPECT_EQ(interpreter.Invoke(), kTfLiteOk); +#ifndef TF_LITE_STRIP_ERROR_STRINGS + TF_LITE_MICRO_EXPECT_EQ(profiler.event_starts(), 3); + TF_LITE_MICRO_EXPECT_EQ(profiler.event_ends(), 3); +#else + TF_LITE_MICRO_EXPECT_EQ(profiler.event_starts(), 0); + TF_LITE_MICRO_EXPECT_EQ(profiler.event_ends(), 0); +#endif +} + +TF_LITE_MICRO_TEST(TestIncompleteInitializationAllocationsWithSmallArena) +{ + const tflite::Model *model = tflite::testing::GetComplexMockModel(); + TF_LITE_MICRO_EXPECT_NE(nullptr, model); + + tflite::AllOpsResolver op_resolver = tflite::testing::GetOpResolver(); + + constexpr size_t allocator_buffer_size = 528; + uint8_t allocator_buffer[allocator_buffer_size]; + + tflite::RecordingMicroAllocator *allocator = + tflite::RecordingMicroAllocator::Create(allocator_buffer, + allocator_buffer_size, + tflite::GetMicroErrorReporter()); + TF_LITE_MICRO_EXPECT_NE(nullptr, allocator); + + tflite::MicroInterpreter interpreter(model, op_resolver, allocator, + tflite::GetMicroErrorReporter()); + + // Interpreter fails because arena is too small: + TF_LITE_MICRO_EXPECT_EQ(interpreter.Invoke(), kTfLiteError); + + TF_LITE_MICRO_EXPECT_EQ( + static_cast(192), + allocator->GetSimpleMemoryAllocator()->GetHeadUsedBytes()); + + // Ensure allocations are zero (ignore tail since some internal structs are + // initialized with this space): + TF_LITE_MICRO_EXPECT_EQ( + static_cast(0), + allocator + ->GetRecordedAllocation( + tflite::RecordedAllocationType::kTfLiteEvalTensorData) + .used_bytes); + TF_LITE_MICRO_EXPECT_EQ( + static_cast(0), + allocator + ->GetRecordedAllocation( + tflite::RecordedAllocationType::kTfLiteTensorVariableBufferData) + .used_bytes); + TF_LITE_MICRO_EXPECT_EQ( + static_cast(0), + allocator->GetRecordedAllocation(tflite::RecordedAllocationType::kOpData) + .used_bytes); +} + +TF_LITE_MICRO_TEST(TestInterpreterDoesNotAllocateUntilInvoke) +{ + const tflite::Model *model = tflite::testing::GetComplexMockModel(); + TF_LITE_MICRO_EXPECT_NE(nullptr, model); + + tflite::AllOpsResolver op_resolver = tflite::testing::GetOpResolver(); + + constexpr size_t allocator_buffer_size = 1024 * 10; + uint8_t allocator_buffer[allocator_buffer_size]; + + tflite::RecordingMicroAllocator *allocator = + tflite::RecordingMicroAllocator::Create(allocator_buffer, + allocator_buffer_size, + tflite::GetMicroErrorReporter()); + TF_LITE_MICRO_EXPECT_NE(nullptr, allocator); + + tflite::MicroInterpreter interpreter(model, op_resolver, allocator, + tflite::GetMicroErrorReporter()); + + // Ensure allocations are zero (ignore tail since some internal structs are + // initialized with this space): + TF_LITE_MICRO_EXPECT_EQ( + static_cast(0), + allocator->GetSimpleMemoryAllocator()->GetHeadUsedBytes()); + TF_LITE_MICRO_EXPECT_EQ( + static_cast(0), + allocator + ->GetRecordedAllocation( + tflite::RecordedAllocationType::kTfLiteTensorVariableBufferData) + .used_bytes); + TF_LITE_MICRO_EXPECT_EQ( + static_cast(0), + allocator + ->GetRecordedAllocation( + tflite::RecordedAllocationType::kTfLiteEvalTensorData) + .used_bytes); + TF_LITE_MICRO_EXPECT_EQ( + static_cast(0), + allocator->GetRecordedAllocation(tflite::RecordedAllocationType::kOpData) + .used_bytes); + + TF_LITE_MICRO_EXPECT_EQ(interpreter.Invoke(), kTfLiteOk); + allocator->PrintAllocations(); + + // Allocation sizes vary based on platform - check that allocations are now + // non-zero: + TF_LITE_MICRO_EXPECT_GT( + allocator->GetSimpleMemoryAllocator()->GetHeadUsedBytes(), + static_cast(0)); + TF_LITE_MICRO_EXPECT_GT( + allocator + ->GetRecordedAllocation( + tflite::RecordedAllocationType::kTfLiteEvalTensorData) + .used_bytes, + 0); + + TF_LITE_MICRO_EXPECT_GT( + allocator + ->GetRecordedAllocation( + tflite::RecordedAllocationType::kTfLiteTensorVariableBufferData) + .used_bytes, + static_cast(0)); + + // TODO(b/160160549): This check is mostly meaningless right now because the + // operator creation in our mock models is inconsistent. Revisit what + // this check should be once the mock models are properly created. + TF_LITE_MICRO_EXPECT_EQ( + allocator->GetRecordedAllocation(tflite::RecordedAllocationType::kOpData) + .used_bytes, + static_cast(0)); +} + +TF_LITE_MICRO_TEST(TestInterpreterMultipleInputs) +{ + const tflite::Model *model = tflite::testing::GetSimpleMultipleInputsModel(); + TF_LITE_MICRO_EXPECT_NE(nullptr, model); + + tflite::AllOpsResolver op_resolver = tflite::testing::GetOpResolver(); + + constexpr size_t allocator_buffer_size = 2000; + uint8_t allocator_buffer[allocator_buffer_size]; + + // Create a new scope so that we can test the destructor. + { + tflite::MicroInterpreter interpreter(model, op_resolver, allocator_buffer, + allocator_buffer_size, + tflite::GetMicroErrorReporter()); + + TF_LITE_MICRO_EXPECT_EQ(interpreter.AllocateTensors(), kTfLiteOk); + TF_LITE_MICRO_EXPECT_LE(interpreter.arena_used_bytes(), 928 + 100); + + TF_LITE_MICRO_EXPECT_EQ(static_cast(3), interpreter.inputs_size()); + TF_LITE_MICRO_EXPECT_EQ(static_cast(1), interpreter.outputs_size()); + + TfLiteTensor *input = interpreter.input(0); + TF_LITE_MICRO_EXPECT_NE(nullptr, input); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt32, input->type); + TF_LITE_MICRO_EXPECT_EQ(1, input->dims->size); + TF_LITE_MICRO_EXPECT_EQ(1, input->dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(static_cast(4), input->bytes); + TF_LITE_MICRO_EXPECT_NE(nullptr, input->data.i32); + input->data.i32[0] = 21; + + TfLiteTensor *input1 = interpreter.input(1); + TF_LITE_MICRO_EXPECT_NE(nullptr, input1); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt8, input1->type); + TF_LITE_MICRO_EXPECT_EQ(1, input1->dims->size); + TF_LITE_MICRO_EXPECT_EQ(1, input1->dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(static_cast(1), input1->bytes); + TF_LITE_MICRO_EXPECT_NE(nullptr, input1->data.i32); + input1->data.i32[0] = 21; + + TfLiteTensor *input2 = interpreter.input(2); + TF_LITE_MICRO_EXPECT_NE(nullptr, input2); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt32, input2->type); + TF_LITE_MICRO_EXPECT_EQ(1, input2->dims->size); + TF_LITE_MICRO_EXPECT_EQ(1, input2->dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(static_cast(4), input2->bytes); + TF_LITE_MICRO_EXPECT_NE(nullptr, input2->data.i32); + input2->data.i32[0] = 24; + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, interpreter.Invoke()); + + TfLiteTensor *output = interpreter.output(0); + TF_LITE_MICRO_EXPECT_NE(nullptr, output); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteInt32, output->type); + TF_LITE_MICRO_EXPECT_EQ(1, output->dims->size); + TF_LITE_MICRO_EXPECT_EQ(1, output->dims->data[0]); + TF_LITE_MICRO_EXPECT_EQ(static_cast(4), output->bytes); + TF_LITE_MICRO_EXPECT_NE(nullptr, output->data.i32); + TF_LITE_MICRO_EXPECT_EQ(66, output->data.i32[0]); + } + + TF_LITE_MICRO_EXPECT_EQ(tflite::testing::MultipleInputs::freed_, true); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/micro_mutable_op_resolver.h b/components/tflite/tensorflow/lite/micro/micro_mutable_op_resolver.h new file mode 100644 index 00000000..b24cf022 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_mutable_op_resolver.h @@ -0,0 +1,691 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_MICRO_MICRO_MUTABLE_OP_RESOLVER_H_ +#define TENSORFLOW_LITE_MICRO_MICRO_MUTABLE_OP_RESOLVER_H_ + +#include +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/core/api/error_reporter.h" +#include "tensorflow/lite/core/api/flatbuffer_conversions.h" +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/compatibility.h" +#include "tensorflow/lite/micro/kernels/conv.h" +#include "tensorflow/lite/micro/kernels/ethosu.h" +#include "tensorflow/lite/micro/kernels/fully_connected.h" +#include "tensorflow/lite/micro/kernels/micro_ops.h" +#include "tensorflow/lite/micro/kernels/softmax.h" +#include "tensorflow/lite/micro/micro_op_resolver.h" +#include "tensorflow/lite/schema/schema_generated.h" + +namespace tflite { +TfLiteRegistration *Register_DETECTION_POSTPROCESS(); + +template +class MicroMutableOpResolver : public MicroOpResolver { +public: + TF_LITE_REMOVE_VIRTUAL_DELETE + + explicit MicroMutableOpResolver(ErrorReporter *error_reporter = nullptr) + : error_reporter_(error_reporter) + { + } + + const TfLiteRegistration *FindOp(tflite::BuiltinOperator op) const override + { + if (op == BuiltinOperator_CUSTOM) + return nullptr; + + for (unsigned int i = 0; i < registrations_len_; ++i) { + const TfLiteRegistration ®istration = registrations_[i]; + if (registration.builtin_code == op) { + return ®istration; + } + } + return nullptr; + } + + const TfLiteRegistration *FindOp(const char *op) const override + { + for (unsigned int i = 0; i < registrations_len_; ++i) { + const TfLiteRegistration ®istration = registrations_[i]; + if ((registration.builtin_code == BuiltinOperator_CUSTOM) && + (strcmp(registration.custom_name, op) == 0)) { + return ®istration; + } + } + return nullptr; + } + + MicroOpResolver::BuiltinParseFunction GetOpDataParser( + BuiltinOperator op) const override + { + TFLITE_DCHECK(num_buitin_ops_ <= tOpCount); + for (unsigned int i = 0; i < num_buitin_ops_; ++i) { + if (builtin_codes_[i] == op) + return builtin_parsers_[i]; + } + return nullptr; + } + + // Registers a Custom Operator with the MicroOpResolver. + // + // Only the first call for a given name will be successful. i.e. if this + // function is called again for a previously added Custom Operator, the + // MicroOpResolver will be unchanged and this function will return + // kTfLiteError. + TfLiteStatus AddCustom(const char *name, TfLiteRegistration *registration) + { + if (registrations_len_ >= tOpCount) { + if (error_reporter_) { + TF_LITE_REPORT_ERROR( + error_reporter_, + "Couldn't register custom op '%s', resolver size is too small (%d)", + name, tOpCount); + } + return kTfLiteError; + } + + if (FindOp(name) != nullptr) { + if (error_reporter_ != nullptr) { + TF_LITE_REPORT_ERROR(error_reporter_, + "Calling AddCustom for the same op more than once " + "is not supported (Op: %s).", + name); + } + return kTfLiteError; + } + + TfLiteRegistration *new_registration = ®istrations_[registrations_len_]; + registrations_len_ += 1; + + *new_registration = *registration; + new_registration->builtin_code = BuiltinOperator_CUSTOM; + new_registration->custom_name = name; + return kTfLiteOk; + } + + // The Add* functions below add the various Builtin operators to the + // MicroMutableOpResolver object. + + TfLiteStatus AddAbs() + { + return AddBuiltin(BuiltinOperator_ABS, tflite::ops::micro::Register_ABS(), + ParseAbs); + } + + TfLiteStatus AddAdd() + { + return AddBuiltin(BuiltinOperator_ADD, tflite::ops::micro::Register_ADD(), + ParseAdd); + } + + TfLiteStatus AddAddN() + { + return AddBuiltin(BuiltinOperator_ADD_N, tflite::Register_ADD_N(), + ParseAddN); + } + + TfLiteStatus AddArgMax() + { + return AddBuiltin(BuiltinOperator_ARG_MAX, + tflite::ops::micro::Register_ARG_MAX(), ParseArgMax); + } + + TfLiteStatus AddArgMin() + { + return AddBuiltin(BuiltinOperator_ARG_MIN, + tflite::ops::micro::Register_ARG_MIN(), ParseArgMin); + } + + TfLiteStatus AddAveragePool2D() + { + return AddBuiltin(BuiltinOperator_AVERAGE_POOL_2D, + tflite::Register_AVERAGE_POOL_2D(), ParsePool); + } + + TfLiteStatus AddBatchToSpaceNd() + { + return AddBuiltin(BuiltinOperator_BATCH_TO_SPACE_ND, + Register_BATCH_TO_SPACE_ND(), ParseBatchToSpaceNd); + } + + TfLiteStatus AddCast() + { + return AddBuiltin(BuiltinOperator_CAST, Register_CAST(), ParseCast); + } + + TfLiteStatus AddCeil() + { + return AddBuiltin(BuiltinOperator_CEIL, tflite::ops::micro::Register_CEIL(), + ParseCeil); + } + + TfLiteStatus AddCircularBuffer() + { + return AddCustom("CIRCULAR_BUFFER", + tflite::ops::micro::Register_CIRCULAR_BUFFER()); + } + + TfLiteStatus AddConcatenation() + { + return AddBuiltin(BuiltinOperator_CONCATENATION, + tflite::ops::micro::Register_CONCATENATION(), + ParseConcatenation); + } + + TfLiteStatus AddConv2D( + const TfLiteRegistration ®istration = Register_CONV_2D()) + { + return AddBuiltin(BuiltinOperator_CONV_2D, registration, ParseConv2D); + } + + TfLiteStatus AddCos() + { + return AddBuiltin(BuiltinOperator_COS, tflite::ops::micro::Register_COS(), + ParseCos); + } + + TfLiteStatus AddCumSum() + { + return AddBuiltin(BuiltinOperator_CUMSUM, tflite::Register_CUMSUM(), + ParseCumsum); + } + + TfLiteStatus AddDepthToSpace() + { + return AddBuiltin(BuiltinOperator_DEPTH_TO_SPACE, + tflite::Register_DEPTH_TO_SPACE(), ParseDepthToSpace); + } + + TfLiteStatus AddDepthwiseConv2D() + { + return AddBuiltin(BuiltinOperator_DEPTHWISE_CONV_2D, + Register_DEPTHWISE_CONV_2D(), ParseDepthwiseConv2D); + } + + TfLiteStatus AddDequantize() + { + return AddBuiltin(BuiltinOperator_DEQUANTIZE, + tflite::ops::micro::Register_DEQUANTIZE(), + ParseDequantize); + } + + TfLiteStatus AddDetectionPostprocess() + { + return AddCustom("TFLite_Detection_PostProcess", + tflite::Register_DETECTION_POSTPROCESS()); + } + + TfLiteStatus AddElu() + { + return AddBuiltin(BuiltinOperator_ELU, tflite::Register_ELU(), ParseElu); + } + + TfLiteStatus AddEqual() + { + return AddBuiltin(BuiltinOperator_EQUAL, + tflite::ops::micro::Register_EQUAL(), ParseEqual); + } + + TfLiteStatus AddEthosU() + { + TfLiteRegistration *registration = tflite::Register_ETHOSU(); + if (registration) { + return AddCustom(tflite::GetString_ETHOSU(), registration); + } + return kTfLiteOk; + } + + TfLiteStatus AddExp() + { + return AddBuiltin(BuiltinOperator_EXP, Register_EXP(), ParseExp); + } + + TfLiteStatus AddExpandDims() + { + return AddBuiltin(BuiltinOperator_EXPAND_DIMS, Register_EXPAND_DIMS(), + ParseExpandDims); + } + + TfLiteStatus AddFill() + { + return AddBuiltin(BuiltinOperator_FILL, tflite::Register_FILL(), ParseFill); + } + + TfLiteStatus AddFloor() + { + return AddBuiltin(BuiltinOperator_FLOOR, + tflite::ops::micro::Register_FLOOR(), ParseFloor); + } + + TfLiteStatus AddFloorDiv() + { + return AddBuiltin(BuiltinOperator_FLOOR_DIV, tflite::Register_FLOOR_DIV(), + ParseFloorDiv); + } + + TfLiteStatus AddFloorMod() + { + return AddBuiltin(BuiltinOperator_FLOOR_MOD, tflite::Register_FLOOR_MOD(), + ParseFloorMod); + } + + TfLiteStatus AddFullyConnected( + const TfLiteRegistration ®istration = Register_FULLY_CONNECTED()) + { + return AddBuiltin(BuiltinOperator_FULLY_CONNECTED, registration, + ParseFullyConnected); + } + + TfLiteStatus AddGather() + { + return AddBuiltin(BuiltinOperator_GATHER, tflite::Register_GATHER(), + ParseGather); + } + + TfLiteStatus AddGatherNd() + { + return AddBuiltin(BuiltinOperator_GATHER_ND, tflite::Register_GATHER_ND(), + ParseGatherNd); + } + + TfLiteStatus AddGreater() + { + return AddBuiltin(BuiltinOperator_GREATER, + tflite::ops::micro::Register_GREATER(), ParseGreater); + } + + TfLiteStatus AddGreaterEqual() + { + return AddBuiltin(BuiltinOperator_GREATER_EQUAL, + tflite::ops::micro::Register_GREATER_EQUAL(), + ParseGreaterEqual); + } + + TfLiteStatus AddHardSwish() + { + return AddBuiltin(BuiltinOperator_HARD_SWISH, + tflite::ops::micro::Register_HARD_SWISH(), + ParseHardSwish); + } + + TfLiteStatus AddIf() + { + return AddBuiltin(BuiltinOperator_IF, tflite::Register_IF(), ParseIf); + } + + TfLiteStatus AddL2Normalization() + { + return AddBuiltin(BuiltinOperator_L2_NORMALIZATION, + tflite::ops::micro::Register_L2_NORMALIZATION(), + ParseL2Normalization); + } + + TfLiteStatus AddL2Pool2D() + { + return AddBuiltin(BuiltinOperator_L2_POOL_2D, tflite::Register_L2_POOL_2D(), + ParsePool); + } + + TfLiteStatus AddLeakyRelu() + { + return AddBuiltin(BuiltinOperator_LEAKY_RELU, tflite::Register_LEAKY_RELU(), + ParseLeakyRelu); + } + + TfLiteStatus AddLess() + { + return AddBuiltin(BuiltinOperator_LESS, tflite::ops::micro::Register_LESS(), + ParseLess); + } + + TfLiteStatus AddLessEqual() + { + return AddBuiltin(BuiltinOperator_LESS_EQUAL, + tflite::ops::micro::Register_LESS_EQUAL(), + ParseLessEqual); + } + + TfLiteStatus AddLog() + { + return AddBuiltin(BuiltinOperator_LOG, tflite::ops::micro::Register_LOG(), + ParseLog); + } + + TfLiteStatus AddLogicalAnd() + { + return AddBuiltin(BuiltinOperator_LOGICAL_AND, + tflite::ops::micro::Register_LOGICAL_AND(), + ParseLogicalAnd); + } + + TfLiteStatus AddLogicalNot() + { + return AddBuiltin(BuiltinOperator_LOGICAL_NOT, + tflite::ops::micro::Register_LOGICAL_NOT(), + ParseLogicalNot); + } + + TfLiteStatus AddLogicalOr() + { + return AddBuiltin(BuiltinOperator_LOGICAL_OR, + tflite::ops::micro::Register_LOGICAL_OR(), + ParseLogicalOr); + } + + TfLiteStatus AddLogistic() + { + return AddBuiltin(BuiltinOperator_LOGISTIC, + tflite::ops::micro::Register_LOGISTIC(), ParseLogistic); + } + + TfLiteStatus AddMaximum() + { + return AddBuiltin(BuiltinOperator_MAXIMUM, + tflite::ops::micro::Register_MAXIMUM(), ParseMaximum); + } + + TfLiteStatus AddMaxPool2D() + { + return AddBuiltin(BuiltinOperator_MAX_POOL_2D, + tflite::Register_MAX_POOL_2D(), ParsePool); + } + + TfLiteStatus AddMean() + { + return AddBuiltin(BuiltinOperator_MEAN, tflite::ops::micro::Register_MEAN(), + ParseReducer); + } + + TfLiteStatus AddMinimum() + { + return AddBuiltin(BuiltinOperator_MINIMUM, + tflite::ops::micro::Register_MINIMUM(), ParseMinimum); + } + + TfLiteStatus AddMul() + { + return AddBuiltin(BuiltinOperator_MUL, tflite::ops::micro::Register_MUL(), + ParseMul); + } + + TfLiteStatus AddNeg() + { + return AddBuiltin(BuiltinOperator_NEG, tflite::ops::micro::Register_NEG(), + ParseNeg); + } + + TfLiteStatus AddNotEqual() + { + return AddBuiltin(BuiltinOperator_NOT_EQUAL, + tflite::ops::micro::Register_NOT_EQUAL(), ParseNotEqual); + } + + TfLiteStatus AddPack() + { + return AddBuiltin(BuiltinOperator_PACK, tflite::ops::micro::Register_PACK(), + ParsePack); + } + + TfLiteStatus AddPad() + { + return AddBuiltin(BuiltinOperator_PAD, tflite::ops::micro::Register_PAD(), + ParsePad); + } + + TfLiteStatus AddPadV2() + { + return AddBuiltin(BuiltinOperator_PADV2, + tflite::ops::micro::Register_PADV2(), ParsePadV2); + } + + TfLiteStatus AddPrelu() + { + return AddBuiltin(BuiltinOperator_PRELU, + tflite::ops::micro::Register_PRELU(), ParsePrelu); + } + + TfLiteStatus AddQuantize() + { + return AddBuiltin(BuiltinOperator_QUANTIZE, Register_QUANTIZE(), + ParseQuantize); + } + + TfLiteStatus AddReduceMax() + { + return AddBuiltin(BuiltinOperator_REDUCE_MAX, + tflite::ops::micro::Register_REDUCE_MAX(), ParseReducer); + } + + TfLiteStatus AddRelu() + { + return AddBuiltin(BuiltinOperator_RELU, tflite::ops::micro::Register_RELU(), + ParseRelu); + } + + TfLiteStatus AddRelu6() + { + return AddBuiltin(BuiltinOperator_RELU6, + tflite::ops::micro::Register_RELU6(), ParseRelu6); + } + + TfLiteStatus AddReshape() + { + return AddBuiltin(BuiltinOperator_RESHAPE, + tflite::ops::micro::Register_RESHAPE(), ParseReshape); + } + + TfLiteStatus AddResizeBilinear() + { + return AddBuiltin(BuiltinOperator_RESIZE_BILINEAR, + Register_RESIZE_BILINEAR(), ParseResizeBilinear); + } + + TfLiteStatus AddResizeNearestNeighbor() + { + return AddBuiltin(BuiltinOperator_RESIZE_NEAREST_NEIGHBOR, + tflite::ops::micro::Register_RESIZE_NEAREST_NEIGHBOR(), + ParseResizeNearestNeighbor); + } + + TfLiteStatus AddRound() + { + return AddBuiltin(BuiltinOperator_ROUND, + tflite::ops::micro::Register_ROUND(), ParseRound); + } + + TfLiteStatus AddRsqrt() + { + return AddBuiltin(BuiltinOperator_RSQRT, + tflite::ops::micro::Register_RSQRT(), ParseRsqrt); + } + + TfLiteStatus AddShape() + { + return AddBuiltin(BuiltinOperator_SHAPE, Register_SHAPE(), ParseShape); + } + + TfLiteStatus AddSin() + { + return AddBuiltin(BuiltinOperator_SIN, tflite::ops::micro::Register_SIN(), + ParseSin); + } + + TfLiteStatus AddSoftmax( + const TfLiteRegistration ®istration = Register_SOFTMAX()) + { + return AddBuiltin(BuiltinOperator_SOFTMAX, registration, ParseSoftmax); + } + + TfLiteStatus AddSpaceToBatchNd() + { + return AddBuiltin(BuiltinOperator_SPACE_TO_BATCH_ND, + Register_SPACE_TO_BATCH_ND(), ParseSpaceToBatchNd); + } + + TfLiteStatus AddSpaceToDepth() + { + return AddBuiltin(BuiltinOperator_SPACE_TO_DEPTH, Register_SPACE_TO_DEPTH(), + ParseSpaceToDepth); + } + + TfLiteStatus AddSplit() + { + return AddBuiltin(BuiltinOperator_SPLIT, + tflite::ops::micro::Register_SPLIT(), ParseSplit); + } + + TfLiteStatus AddSplitV() + { + return AddBuiltin(BuiltinOperator_SPLIT_V, + tflite::ops::micro::Register_SPLIT_V(), ParseSplitV); + } + + TfLiteStatus AddSqueeze() + { + return AddBuiltin(BuiltinOperator_SQUEEZE, Register_SQUEEZE(), + ParseSqueeze); + } + + TfLiteStatus AddSqrt() + { + return AddBuiltin(BuiltinOperator_SQRT, tflite::ops::micro::Register_SQRT(), + ParseSqrt); + } + + TfLiteStatus AddSquare() + { + return AddBuiltin(BuiltinOperator_SQUARE, + tflite::ops::micro::Register_SQUARE(), ParseSquare); + } + + TfLiteStatus AddStridedSlice() + { + return AddBuiltin(BuiltinOperator_STRIDED_SLICE, + tflite::ops::micro::Register_STRIDED_SLICE(), + ParseStridedSlice); + } + + TfLiteStatus AddSub() + { + return AddBuiltin(BuiltinOperator_SUB, tflite::ops::micro::Register_SUB(), + ParseSub); + } + + TfLiteStatus AddSvdf() + { + return AddBuiltin(BuiltinOperator_SVDF, Register_SVDF(), ParseSvdf); + } + + TfLiteStatus AddTanh() + { + return AddBuiltin(BuiltinOperator_TANH, tflite::ops::micro::Register_TANH(), + ParseTanh); + } + + TfLiteStatus AddTransposeConv() + { + return AddBuiltin(BuiltinOperator_TRANSPOSE_CONV, + tflite::Register_TRANSPOSE_CONV(), ParseTransposeConv); + } + + TfLiteStatus AddTranspose() + { + return AddBuiltin(BuiltinOperator_TRANSPOSE, Register_TRANSPOSE(), + ParseTranspose); + } + + TfLiteStatus AddUnpack() + { + return AddBuiltin(BuiltinOperator_UNPACK, + tflite::ops::micro::Register_UNPACK(), ParseUnpack); + } + + TfLiteStatus AddZerosLike() + { + return AddBuiltin(BuiltinOperator_ZEROS_LIKE, Register_ZEROS_LIKE(), + ParseZerosLike); + } + + unsigned int GetRegistrationLength() + { + return registrations_len_; + } + +private: + TfLiteStatus AddBuiltin(tflite::BuiltinOperator op, + const TfLiteRegistration ®istration, + MicroOpResolver::BuiltinParseFunction parser) + { + if (op == BuiltinOperator_CUSTOM) { + if (error_reporter_ != nullptr) { + TF_LITE_REPORT_ERROR(error_reporter_, + "Invalid parameter BuiltinOperator_CUSTOM to the " + "AddBuiltin function."); + } + return kTfLiteError; + } + + if (FindOp(op) != nullptr) { + if (error_reporter_ != nullptr) { + TF_LITE_REPORT_ERROR(error_reporter_, + "Calling AddBuiltin with the same op more than " + "once is not supported (Op: #%d).", + op); + } + return kTfLiteError; + } + + if (registrations_len_ >= tOpCount) { + if (error_reporter_) { + TF_LITE_REPORT_ERROR(error_reporter_, + "Couldn't register builtin op #%d, resolver size " + "is too small (%d).", + op, tOpCount); + } + return kTfLiteError; + } + + registrations_[registrations_len_] = registration; + // Strictly speaking, the builtin_code is not necessary for TFLM but filling + // it in regardless. + registrations_[registrations_len_].builtin_code = op; + registrations_len_++; + + builtin_codes_[num_buitin_ops_] = op; + builtin_parsers_[num_buitin_ops_] = parser; + num_buitin_ops_++; + + return kTfLiteOk; + } + + TfLiteRegistration registrations_[tOpCount]; + unsigned int registrations_len_ = 0; + + // Arrays (and counter) to store the builtin codes and their corresponding + // parse functions as these are registered with the Op Resolver. + BuiltinOperator builtin_codes_[tOpCount]; + MicroOpResolver::BuiltinParseFunction builtin_parsers_[tOpCount]; + unsigned int num_buitin_ops_ = 0; + + ErrorReporter *error_reporter_; +}; + +}; // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_MICRO_MUTABLE_OP_RESOLVER_H_ diff --git a/components/tflite/tensorflow/lite/micro/micro_mutable_op_resolver_test.cc b/components/tflite/tensorflow/lite/micro/micro_mutable_op_resolver_test.cc new file mode 100644 index 00000000..8988a607 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_mutable_op_resolver_test.cc @@ -0,0 +1,148 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/micro_mutable_op_resolver.h" + +#include "tensorflow/lite/micro/micro_op_resolver.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +namespace tflite { +namespace { +void *MockInit(TfLiteContext *context, const char *buffer, size_t length) +{ + // Do nothing. + return nullptr; +} + +void MockFree(TfLiteContext *context, void *buffer) +{ + // Do nothing. +} + +TfLiteStatus MockPrepare(TfLiteContext *context, TfLiteNode *node) +{ + return kTfLiteOk; +} + +TfLiteStatus MockInvoke(TfLiteContext *context, TfLiteNode *node) +{ + return kTfLiteOk; +} + +class MockErrorReporter : public ErrorReporter { +public: + MockErrorReporter() + : has_been_called_(false) + { + } + int Report(const char *format, va_list args) override + { + has_been_called_ = true; + return 0; + }; + + bool HasBeenCalled() + { + return has_been_called_; + } + + void ResetState() + { + has_been_called_ = false; + } + +private: + bool has_been_called_; + TF_LITE_REMOVE_VIRTUAL_DELETE +}; + +} // namespace +} // namespace tflite + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestOperations) +{ + using tflite::BuiltinOperator_CONV_2D; + using tflite::BuiltinOperator_RELU; + using tflite::MicroMutableOpResolver; + using tflite::OpResolver; + + static TfLiteRegistration r = {}; + r.init = tflite::MockInit; + r.free = tflite::MockFree; + r.prepare = tflite::MockPrepare; + r.invoke = tflite::MockInvoke; + + MicroMutableOpResolver<1> micro_op_resolver; + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + micro_op_resolver.AddCustom("mock_custom", &r)); + + // Only one AddCustom per operator should return kTfLiteOk. + TF_LITE_MICRO_EXPECT_EQ(kTfLiteError, + micro_op_resolver.AddCustom("mock_custom", &r)); + + tflite::MicroOpResolver *resolver = µ_op_resolver; + + TF_LITE_MICRO_EXPECT_EQ(static_cast(1), + micro_op_resolver.GetRegistrationLength()); + + const TfLiteRegistration *registration = + resolver->FindOp(BuiltinOperator_RELU); + TF_LITE_MICRO_EXPECT(nullptr == registration); + + registration = resolver->FindOp("mock_custom"); + TF_LITE_MICRO_EXPECT(nullptr != registration); + TF_LITE_MICRO_EXPECT(nullptr == registration->init(nullptr, nullptr, 0)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, registration->prepare(nullptr, nullptr)); + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, registration->invoke(nullptr, nullptr)); + + registration = resolver->FindOp("nonexistent_custom"); + TF_LITE_MICRO_EXPECT(nullptr == registration); +} + +TF_LITE_MICRO_TEST(TestErrorReporting) +{ + using tflite::BuiltinOperator_CONV_2D; + using tflite::BuiltinOperator_RELU; + using tflite::MicroMutableOpResolver; + + static TfLiteRegistration r = {}; + r.init = tflite::MockInit; + r.free = tflite::MockFree; + r.prepare = tflite::MockPrepare; + r.invoke = tflite::MockInvoke; + + tflite::MockErrorReporter mock_reporter; + MicroMutableOpResolver<1> micro_op_resolver(&mock_reporter); + TF_LITE_MICRO_EXPECT_EQ(false, mock_reporter.HasBeenCalled()); + mock_reporter.ResetState(); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, + micro_op_resolver.AddCustom("mock_custom_0", &r)); + TF_LITE_MICRO_EXPECT_EQ(false, mock_reporter.HasBeenCalled()); + mock_reporter.ResetState(); + + // Attempting to Add more operators than the class template parameter for + // MicroMutableOpResolver should result in errors. + TF_LITE_MICRO_EXPECT_EQ(kTfLiteError, micro_op_resolver.AddRelu()); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteError, + micro_op_resolver.AddCustom("mock_custom_1", &r)); + TF_LITE_MICRO_EXPECT_EQ(true, mock_reporter.HasBeenCalled()); + mock_reporter.ResetState(); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/micro_op_resolver.h b/components/tflite/tensorflow/lite/micro/micro_op_resolver.h new file mode 100644 index 00000000..988c9bb2 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_op_resolver.h @@ -0,0 +1,76 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_MICRO_MICRO_OP_RESOLVER_H_ +#define TENSORFLOW_LITE_MICRO_MICRO_OP_RESOLVER_H_ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/core/api/error_reporter.h" +#include "tensorflow/lite/core/api/flatbuffer_conversions.h" +#include "tensorflow/lite/core/api/op_resolver.h" +#include "tensorflow/lite/schema/schema_generated.h" + +namespace tflite { +// This is an interface for the OpResolver for TFLiteMicro. The differences from +// the TFLite OpResolver base class are to: +// * explicitly remove support for Op versions +// * allow for finer grained registration of the Builtin Ops to reduce code +// size for TFLiteMicro. +// +// We need an interface class instead of directly using MicroMutableOpResolver +// because MicroMutableOpResolver is a class template with the number of +// registered Ops as the template parameter. +class MicroOpResolver : public OpResolver { +public: + typedef TfLiteStatus (*BuiltinParseFunction)(const Operator *op, + ErrorReporter *error_reporter, + BuiltinDataAllocator *allocator, + void **builtin_data); + + // Returns the Op registration struct corresponding to the enum code from the + // flatbuffer schema. Returns nullptr if the op is not found or if op == + // BuiltinOperator_CUSTOM. + virtual const TfLiteRegistration *FindOp(BuiltinOperator op) const = 0; + + // Returns the Op registration struct corresponding to the custom operator by + // name. + virtual const TfLiteRegistration *FindOp(const char *op) const = 0; + + // This implementation exists for compatibility with the OpResolver base class + // and disregards the version parameter. + const TfLiteRegistration *FindOp(BuiltinOperator op, + int version) const final + { + return FindOp(op); + } + + // This implementation exists for compatibility with the OpResolver base class + // and disregards the version parameter. + const TfLiteRegistration *FindOp(const char *op, int version) const final + { + return FindOp(op); + } + + // Returns the operator specific parsing function for the OpData for a + // BuiltinOperator (if registered), else nullptr. + virtual BuiltinParseFunction GetOpDataParser(BuiltinOperator op) const = 0; + + ~MicroOpResolver() override + { + } +}; + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_MICRO_OP_RESOLVER_H_ diff --git a/components/tflite/tensorflow/lite/micro/micro_profiler.cc b/components/tflite/tensorflow/lite/micro/micro_profiler.cc new file mode 100644 index 00000000..005f7af6 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_profiler.cc @@ -0,0 +1,62 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/micro/micro_profiler.h" + +#include + +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/micro_time.h" + +namespace tflite { + +uint32_t MicroProfiler::BeginEvent(const char *tag) +{ + if (num_events_ == kMaxEvents) { + num_events_ = 0; + } + + tags_[num_events_] = tag; + start_ticks_[num_events_] = GetCurrentTimeTicks(); + end_ticks_[num_events_] = start_ticks_[num_events_] - 1; + return num_events_++; +} + +void MicroProfiler::EndEvent(uint32_t event_handle) +{ + TFLITE_DCHECK(event_handle < kMaxEvents); + end_ticks_[event_handle] = GetCurrentTimeTicks(); +} + +int32_t MicroProfiler::GetTotalTicks() const +{ + int32_t ticks = 0; + for (int i = 0; i < num_events_; ++i) { + ticks += end_ticks_[i] - start_ticks_[i]; + } + return ticks; +} + +void MicroProfiler::Log() const +{ +#if !defined(TF_LITE_STRIP_ERROR_STRINGS) + for (int i = 0; i < num_events_; ++i) { + int32_t ticks = end_ticks_[i] - start_ticks_[i]; + MicroPrintf("%s took %d ticks (%d ms).", tags_[i], ticks, TicksToMs(ticks)); + } +#endif +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/micro_profiler.h b/components/tflite/tensorflow/lite/micro/micro_profiler.h new file mode 100644 index 00000000..63c9222e --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_profiler.h @@ -0,0 +1,124 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_MICRO_PROFILER_H_ +#define TENSORFLOW_LITE_MICRO_MICRO_PROFILER_H_ + +#include + +#include "tensorflow/lite/micro/compatibility.h" + +namespace tflite { +// MicroProfiler creates a common way to gain fine-grained insight into runtime +// performance. Bottleck operators can be identified along with slow code +// sections. This can be used in conjunction with running the relevant micro +// benchmark to evaluate end-to-end performance. +class MicroProfiler { +public: + MicroProfiler() = default; + virtual ~MicroProfiler() = default; + + // Marks the start of a new event and returns an event handle that can be used + // to mark the end of the event via EndEvent. The lifetime of the tag + // parameter must exceed that of the MicroProfiler. + virtual uint32_t BeginEvent(const char *tag); + + // Marks the end of an event associated with event_handle. It is the + // responsibility of the caller to ensure than EndEvent is called once and + // only once per event_handle. + // + // If EndEvent is called more than once for the same event_handle, the last + // call will be used as the end of event marker.If EndEvent is called 0 times + // for a particular event_handle, the duration of that event will be 0 ticks. + virtual void EndEvent(uint32_t event_handle); + + // Clears all the events that have been currently profiled. + void ClearEvents() + { + num_events_ = 0; + } + + // Returns the sum of the ticks taken across all the events. This number + // is only meaningful if all of the events are disjoint (the end time of + // event[i] <= start time of event[i+1]). + int32_t GetTotalTicks() const; + + // Prints the profiling information of each of the events. + void Log() const; + +private: + // Maximum number of events that this class can keep track of. If we call + // AddEvent more than kMaxEvents number of times, then the oldest event's + // profiling information will be overwritten. + static constexpr int kMaxEvents = 50; + + const char *tags_[kMaxEvents]; + int32_t start_ticks_[kMaxEvents]; + int32_t end_ticks_[kMaxEvents]; + int num_events_ = 0; + + TF_LITE_REMOVE_VIRTUAL_DELETE; +}; + +#if defined(TF_LITE_STRIP_ERROR_STRINGS) +// For release builds, the ScopedMicroProfiler is a noop. +// +// This is done because the ScipedProfiler is used as part of the +// MicroInterpreter and we want to ensure zero overhead for the release builds. +class ScopedMicroProfiler { +public: + explicit ScopedMicroProfiler(const char *tag, MicroProfiler *profiler) + { + } +}; + +#else + +// This class can be used to add events to a MicroProfiler object that span the +// lifetime of the ScopedMicroProfiler object. +// Usage example: +// +// MicroProfiler profiler(); +// ... +// { +// ScopedMicroProfiler scoped_profiler("custom_tag", profiler); +// work_to_profile(); +// } +class ScopedMicroProfiler { +public: + explicit ScopedMicroProfiler(const char *tag, MicroProfiler *profiler) + : profiler_(profiler) + { + if (profiler_ != nullptr) { + event_handle_ = profiler_->BeginEvent(tag); + } + } + + ~ScopedMicroProfiler() + { + if (profiler_ != nullptr) { + profiler_->EndEvent(event_handle_); + } + } + +private: + uint32_t event_handle_ = 0; + MicroProfiler *profiler_ = nullptr; +}; +#endif // !defined(NDEBUG) + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_MICRO_PROFILER_H_ diff --git a/components/tflite/tensorflow/lite/micro/micro_string.cc b/components/tflite/tensorflow/lite/micro/micro_string.cc new file mode 100644 index 00000000..59410a09 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_string.cc @@ -0,0 +1,330 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// Implements debug logging for numbers by converting them into strings and then +// calling the main DebugLog(char*) function. These are separated into a +// different file so that platforms can just implement the string output version +// of DebugLog() and then get the numerical variations without requiring any +// more code. + +#include "tensorflow/lite/micro/micro_string.h" + +#include +#include +#include + +namespace { + +// Int formats can need up to 10 bytes for the value plus a single byte for the +// sign. +constexpr int kMaxIntCharsNeeded = 10 + 1; +// Hex formats can need up to 8 bytes for the value plus two bytes for the "0x". +constexpr int kMaxHexCharsNeeded = 8 + 2; + +// Float formats can need up to 7 bytes for the fraction plus 3 bytes for "x2^" +// plus 3 bytes for the exponent and a single sign bit. +constexpr float kMaxFloatCharsNeeded = 7 + 3 + 3 + 1; + +// All input buffers to the number conversion functions must be this long. +const int kFastToBufferSize = 48; + +// Reverses a zero-terminated string in-place. +char *ReverseStringInPlace(char *start, char *end) +{ + char *p1 = start; + char *p2 = end - 1; + while (p1 < p2) { + char tmp = *p1; + *p1++ = *p2; + *p2-- = tmp; + } + return start; +} + +// Appends a string to a string, in-place. You need to pass in the maximum +// string length as the second argument. +char *StrCatStr(char *main, int main_max_length, const char *to_append) +{ + char *current = main; + while (*current != 0) { + ++current; + } + char *current_end = main + (main_max_length - 1); + while ((*to_append != 0) && (current < current_end)) { + *current = *to_append; + ++current; + ++to_append; + } + *current = 0; + return current; +} + +// Populates the provided buffer with an ASCII representation of the number. +char *FastUInt32ToBufferLeft(uint32_t i, char *buffer, int base) +{ + char *start = buffer; + do { + int32_t digit = i % base; + char character; + if (digit < 10) { + character = '0' + digit; + } else { + character = 'a' + (digit - 10); + } + *buffer++ = character; + i /= base; + } while (i > 0); + *buffer = 0; + ReverseStringInPlace(start, buffer); + return buffer; +} + +// Populates the provided buffer with an ASCII representation of the number. +char *FastInt32ToBufferLeft(int32_t i, char *buffer) +{ + uint32_t u = i; + if (i < 0) { + *buffer++ = '-'; + u = -u; + } + return FastUInt32ToBufferLeft(u, buffer, 10); +} + +// Converts a number to a string and appends it to another. +char *StrCatInt32(char *main, int main_max_length, int32_t number) +{ + char number_string[kFastToBufferSize]; + FastInt32ToBufferLeft(number, number_string); + return StrCatStr(main, main_max_length, number_string); +} + +// Converts a number to a string and appends it to another. +char *StrCatUInt32(char *main, int main_max_length, uint32_t number, int base) +{ + char number_string[kFastToBufferSize]; + FastUInt32ToBufferLeft(number, number_string, base); + return StrCatStr(main, main_max_length, number_string); +} + +// Populates the provided buffer with ASCII representation of the float number. +// Avoids the use of any floating point instructions (since these aren't +// supported on many microcontrollers) and as a consequence prints values with +// power-of-two exponents. +char *FastFloatToBufferLeft(float f, char *buffer) +{ + char *current = buffer; + char *current_end = buffer + (kFastToBufferSize - 1); + // Access the bit fields of the floating point value to avoid requiring any + // float instructions. These constants are derived from IEEE 754. + const uint32_t sign_mask = 0x80000000; + const uint32_t exponent_mask = 0x7f800000; + const int32_t exponent_shift = 23; + const int32_t exponent_bias = 127; + const uint32_t fraction_mask = 0x007fffff; + uint32_t u; + memcpy(&u, &f, sizeof(int32_t)); + const int32_t exponent = + ((u & exponent_mask) >> exponent_shift) - exponent_bias; + const uint32_t fraction = (u & fraction_mask); + // Expect ~0x2B1B9D3 for fraction. + if (u & sign_mask) { + *current = '-'; + current += 1; + } + *current = 0; + // These are special cases for infinities and not-a-numbers. + if (exponent == 128) { + if (fraction == 0) { + current = StrCatStr(current, (current_end - current), "Inf"); + return current; + } else { + current = StrCatStr(current, (current_end - current), "NaN"); + return current; + } + } + // 0x007fffff (8388607) represents 0.99... for the fraction, so to print the + // correct decimal digits we need to scale our value before passing it to the + // conversion function. This scale should be 10000000/8388608 = 1.1920928955. + // We can approximate this using multiply-adds and right-shifts using the + // values in this array. The 1. portion of the number string is printed out + // in a fixed way before the fraction, below. + const int32_t scale_shifts_size = 13; + const int8_t scale_shifts[13] = { 3, 4, 8, 11, 13, 14, 17, + 18, 19, 20, 21, 22, 23 }; + uint32_t scaled_fraction = fraction; + for (int i = 0; i < scale_shifts_size; ++i) { + scaled_fraction += (fraction >> scale_shifts[i]); + } + *current = '1'; + current += 1; + *current = '.'; + current += 1; + *current = 0; + + // Prepend leading zeros to fill in all 7 bytes of the fraction. Truncate + // zeros off the end of the fraction. Every fractional value takes 7 bytes. + // For example, 2500 would be written into the buffer as 0002500 since it + // represents .00025. + constexpr int kMaxFractionalDigits = 7; + + // Abort early if there is not enough space in the buffer. + if (current_end - current <= kMaxFractionalDigits) { + return current; + } + + // Pre-fill buffer with zeros to ensure zero-truncation works properly. + for (int i = 1; i < kMaxFractionalDigits; i++) { + *(current + i) = '0'; + } + + // Track how large the fraction is to add leading zeros. + char *previous = current; + current = StrCatUInt32(current, (current_end - current), scaled_fraction, 10); + int fraction_digits = current - previous; + int leading_zeros = kMaxFractionalDigits - fraction_digits; + + // Overwrite the null terminator from StrCatUInt32 to ensure zero-trunctaion + // works properly. + *current = '0'; + + // Shift fraction values and prepend zeros if necessary. + if (leading_zeros != 0) { + for (int i = 0; i < fraction_digits; i++) { + current--; + *(current + leading_zeros) = *current; + *current = '0'; + } + current += kMaxFractionalDigits; + } + + // Truncate trailing zeros for cleaner logs. Ensure we leave at least one + // fractional character for the case when scaled_fraction is 0. + while (*(current - 1) == '0' && (current - 1) > previous) { + current--; + } + *current = 0; + current = StrCatStr(current, (current_end - current), "*2^"); + current = StrCatInt32(current, (current_end - current), exponent); + return current; +} + +int FormatInt32(char *output, int32_t i) +{ + return static_cast(FastInt32ToBufferLeft(i, output) - output); +} + +int FormatUInt32(char *output, uint32_t i) +{ + return static_cast(FastUInt32ToBufferLeft(i, output, 10) - output); +} + +int FormatHex(char *output, uint32_t i) +{ + return static_cast(FastUInt32ToBufferLeft(i, output, 16) - output); +} + +int FormatFloat(char *output, float i) +{ + return static_cast(FastFloatToBufferLeft(i, output) - output); +} + +} // namespace + +extern "C" int MicroVsnprintf(char *output, int len, const char *format, + va_list args) +{ + int output_index = 0; + const char *current = format; + // One extra character must be left for the null terminator. + const int usable_length = len - 1; + while (*current != '\0' && output_index < usable_length) { + if (*current == '%') { + current++; + switch (*current) { + case 'd': + // Cut off log message if format could exceed log buffer length. + if (usable_length - output_index < kMaxIntCharsNeeded) { + output[output_index++] = '\0'; + return output_index; + } + output_index += + FormatInt32(&output[output_index], va_arg(args, int32_t)); + current++; + break; + case 'u': + if (usable_length - output_index < kMaxIntCharsNeeded) { + output[output_index++] = '\0'; + return output_index; + } + output_index += + FormatUInt32(&output[output_index], va_arg(args, uint32_t)); + current++; + break; + case 'x': + if (usable_length - output_index < kMaxHexCharsNeeded) { + output[output_index++] = '\0'; + return output_index; + } + output[output_index++] = '0'; + output[output_index++] = 'x'; + output_index += + FormatHex(&output[output_index], va_arg(args, uint32_t)); + current++; + break; + case 'f': + if (usable_length - output_index < kMaxFloatCharsNeeded) { + output[output_index++] = '\0'; + return output_index; + } + output_index += + FormatFloat(&output[output_index], va_arg(args, double)); + current++; + break; + case '%': + output[output_index++] = *current++; + break; + case 'c': + if (usable_length - output_index < 1) { + output[output_index++] = '\0'; + return output_index; + } + output[output_index++] = va_arg(args, int32_t); + current++; + break; + case 's': + char *string = va_arg(args, char *); + int string_idx = 0; + while (string_idx + output_index < usable_length && + string[string_idx] != '\0') { + output[output_index++] = string[string_idx++]; + } + current++; + } + } else { + output[output_index++] = *current++; + } + } + output[output_index++] = '\0'; + return output_index; +} + +extern "C" int MicroSnprintf(char *output, int len, const char *format, ...) +{ + va_list args; + va_start(args, format); + int bytes_written = MicroVsnprintf(output, len, format, args); + va_end(args); + return bytes_written; +} diff --git a/components/tflite/tensorflow/lite/micro/micro_string.h b/components/tflite/tensorflow/lite/micro/micro_string.h new file mode 100644 index 00000000..0fd29d34 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_string.h @@ -0,0 +1,33 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_MICRO_MICRO_STRING_H_ +#define TENSORFLOW_LITE_MICRO_MICRO_STRING_H_ + +#include + +// Implements simple string formatting for numeric types. Returns the number of +// bytes written to output. +extern "C" { +// Functionally equivalent to vsnprintf, trimmed down for TFLite Micro. +// MicroSnprintf() is implemented using MicroVsnprintf(). +int MicroVsnprintf(char *output, int len, const char *format, va_list args); +// Functionally equavalent to snprintf, trimmed down for TFLite Micro. +// For example, MicroSnprintf(buffer, 10, "int %d", 10) will put the string +// "int 10" in the buffer. +// Floating point values are logged in exponent notation (1.XXX*2^N). +int MicroSnprintf(char *output, int len, const char *format, ...); +} + +#endif // TENSORFLOW_LITE_MICRO_MICRO_STRING_H_ diff --git a/components/tflite/tensorflow/lite/micro/micro_string_test.cc b/components/tflite/tensorflow/lite/micro/micro_string_test.cc new file mode 100644 index 00000000..9c570811 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_string_test.cc @@ -0,0 +1,176 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/micro_string.h" + +#include "tensorflow/lite/micro/testing/micro_test.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(FormatPositiveIntShouldMatchExpected) +{ + const int kBufferLen = 32; + char buffer[kBufferLen]; + const char golden[] = "Int: 55"; + int bytes_written = MicroSnprintf(buffer, kBufferLen, "Int: %d", 55); + TF_LITE_MICRO_EXPECT_EQ(static_cast(sizeof(golden)), bytes_written); + TF_LITE_MICRO_EXPECT_STRING_EQ(golden, buffer); +} + +TF_LITE_MICRO_TEST(FormatNegativeIntShouldMatchExpected) +{ + const int kBufferLen = 32; + char buffer[kBufferLen]; + const char golden[] = "Int: -55"; + int bytes_written = MicroSnprintf(buffer, kBufferLen, "Int: %d", -55); + TF_LITE_MICRO_EXPECT_EQ(static_cast(sizeof(golden)), bytes_written); + TF_LITE_MICRO_EXPECT_STRING_EQ(golden, buffer); +} + +TF_LITE_MICRO_TEST(FormatUnsignedIntShouldMatchExpected) +{ + const int kBufferLen = 32; + char buffer[kBufferLen]; + const char golden[] = "UInt: 12345"; + int bytes_written = MicroSnprintf(buffer, kBufferLen, "UInt: %u", 12345); + TF_LITE_MICRO_EXPECT_EQ(static_cast(sizeof(golden)), bytes_written); + TF_LITE_MICRO_EXPECT_STRING_EQ(golden, buffer); +} + +TF_LITE_MICRO_TEST(FormatHexShouldMatchExpected) +{ + const int kBufferLen = 32; + char buffer[kBufferLen]; + const char golden[] = "Hex: 0x12345"; + int bytes_written = MicroSnprintf(buffer, kBufferLen, "Hex: %x", 0x12345); + TF_LITE_MICRO_EXPECT_EQ(static_cast(sizeof(golden)), bytes_written); + TF_LITE_MICRO_EXPECT_STRING_EQ(golden, buffer); +} + +TF_LITE_MICRO_TEST(FormatFloatShouldMatchExpected) +{ + const int kBufferLen = 32; + char buffer[kBufferLen]; + const char golden[] = "Float: 1.0*2^4"; + int bytes_written = MicroSnprintf(buffer, kBufferLen, "Float: %f", 16.); + TF_LITE_MICRO_EXPECT_EQ(static_cast(sizeof(golden)), bytes_written); + TF_LITE_MICRO_EXPECT_STRING_EQ(golden, buffer); +} + +TF_LITE_MICRO_TEST(FormatCharShouldMatchExpected) +{ + const int kBufferLen = 32; + char buffer[kBufferLen]; + const char golden[] = "Chars: @,Z"; + int bytes_written = + MicroSnprintf(buffer, kBufferLen, "Chars: %c,%c", 64, 'Z'); + TF_LITE_MICRO_EXPECT_EQ(static_cast(sizeof(golden)), bytes_written); + TF_LITE_MICRO_EXPECT_STRING_EQ(golden, buffer); +} + +TF_LITE_MICRO_TEST(BadlyFormattedStringShouldProduceReasonableString) +{ + const int kBufferLen = 32; + char buffer[kBufferLen]; + const char golden[] = "Test Badly % formated % string"; + int bytes_written = + MicroSnprintf(buffer, kBufferLen, "Test Badly %% formated %% string%"); + TF_LITE_MICRO_EXPECT_EQ(static_cast(sizeof(golden)), bytes_written); + TF_LITE_MICRO_EXPECT_STRING_EQ(golden, buffer); +} + +TF_LITE_MICRO_TEST(IntFormatOverrunShouldTruncate) +{ + const int kBufferLen = 8; + char buffer[kBufferLen]; + const char golden[] = "Int: "; + int bytes_written = MicroSnprintf(buffer, kBufferLen, "Int: %d", 12345); + TF_LITE_MICRO_EXPECT_EQ(static_cast(sizeof(golden)), bytes_written); + TF_LITE_MICRO_EXPECT_STRING_EQ(golden, buffer); +} + +TF_LITE_MICRO_TEST(UnsignedIntFormatOverrunShouldTruncate) +{ + const int kBufferLen = 8; + char buffer[kBufferLen]; + const char golden[] = "UInt: "; + int bytes_written = MicroSnprintf(buffer, kBufferLen, "UInt: %u", 12345); + TF_LITE_MICRO_EXPECT_EQ(static_cast(sizeof(golden)), bytes_written); + TF_LITE_MICRO_EXPECT_STRING_EQ(golden, buffer); +} + +TF_LITE_MICRO_TEST(HexFormatOverrunShouldTruncate) +{ + const int kBufferLen = 8; + char buffer[kBufferLen]; + const char golden[] = "Hex: "; + int bytes_written = MicroSnprintf(buffer, kBufferLen, "Hex: %x", 0x12345); + TF_LITE_MICRO_EXPECT_EQ(static_cast(sizeof(golden)), bytes_written); + TF_LITE_MICRO_EXPECT_STRING_EQ(golden, buffer); +} + +TF_LITE_MICRO_TEST(FloatFormatOverrunShouldTruncate) +{ + const int kBufferLen = 12; + char buffer[kBufferLen]; + const char golden[] = "Float: "; + int bytes_written = MicroSnprintf(buffer, kBufferLen, "Float: %x", 12345.); + TF_LITE_MICRO_EXPECT_EQ(static_cast(sizeof(golden)), bytes_written); + TF_LITE_MICRO_EXPECT_STRING_EQ(golden, buffer); +} + +TF_LITE_MICRO_TEST(FloatFormatShouldPrintFractionCorrectly) +{ + const int kBufferLen = 24; + char buffer[kBufferLen]; + const char golden[] = "Float: 1.0625*2^0"; + // Add small offset to float value to account for float rounding error. + int bytes_written = MicroSnprintf(buffer, kBufferLen, "Float: %f", 1.0625001); + TF_LITE_MICRO_EXPECT_EQ(static_cast(sizeof(golden)), bytes_written); + TF_LITE_MICRO_EXPECT_STRING_EQ(golden, buffer); +} + +TF_LITE_MICRO_TEST(FloatFormatShouldPrintFractionCorrectlyNoLeadingZeros) +{ + const int kBufferLen = 24; + char buffer[kBufferLen]; + const char golden[] = "Float: 1.6332993*2^-1"; + int bytes_written = MicroSnprintf(buffer, kBufferLen, "Float: %f", 0.816650); + TF_LITE_MICRO_EXPECT_EQ(static_cast(sizeof(golden)), bytes_written); + TF_LITE_MICRO_EXPECT_STRING_EQ(golden, buffer); +} + +TF_LITE_MICRO_TEST(StringFormatOverrunShouldTruncate) +{ + const int kBufferLen = 10; + char buffer[kBufferLen]; + const char golden[] = "String: h"; + int bytes_written = + MicroSnprintf(buffer, kBufferLen, "String: %s", "hello world"); + TF_LITE_MICRO_EXPECT_EQ(static_cast(sizeof(golden)), bytes_written); + TF_LITE_MICRO_EXPECT_STRING_EQ(golden, buffer); +} + +TF_LITE_MICRO_TEST(StringFormatWithExactOutputSizeOverrunShouldTruncate) +{ + const int kBufferLen = 10; + char buffer[kBufferLen]; + const char golden[] = "format st"; + int bytes_written = MicroSnprintf(buffer, kBufferLen, "format str"); + TF_LITE_MICRO_EXPECT_EQ(static_cast(sizeof(golden)), bytes_written); + TF_LITE_MICRO_EXPECT_STRING_EQ(golden, buffer); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/micro_time.cc b/components/tflite/tensorflow/lite/micro/micro_time.cc new file mode 100644 index 00000000..e44824b7 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_time.cc @@ -0,0 +1,71 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// Reference implementation of timer functions. Platforms are not required to +// implement these timer methods, but they are required to enable profiling. + +// On platforms that have a POSIX stack or C library, it can be written using +// methods from or clock() from . + +// To add an equivalent function for your own platform, create your own +// implementation file, and place it in a subfolder with named after the OS +// you're targeting. For example, see the Cortex M bare metal version in +// tensorflow/lite/micro/bluepill/micro_time.cc or the mbed one on +// tensorflow/lite/micro/mbed/micro_time.cc. + +#include "tensorflow/lite/micro/micro_time.h" + +#if defined(TF_LITE_USE_CTIME) +#include +#endif + +namespace tflite { + +#if !defined(TF_LITE_USE_CTIME) + +// Reference implementation of the ticks_per_second() function that's required +// for a platform to support Tensorflow Lite for Microcontrollers profiling. +// This returns 0 by default because timing is an optional feature that builds +// without errors on platforms that do not need it. +int32_t ticks_per_second() +{ + return 0; +} + +// Reference implementation of the GetCurrentTimeTicks() function that's +// required for a platform to support Tensorflow Lite for Microcontrollers +// profiling. This returns 0 by default because timing is an optional feature +// that builds without errors on platforms that do not need it. +int32_t GetCurrentTimeTicks() +{ + return 0; +} + +#else // defined(TF_LITE_USE_CTIME) + +// For platforms that support ctime, we implment the micro_time interface in +// this central location. +int32_t ticks_per_second() +{ + return CLOCKS_PER_SEC; +} + +int32_t GetCurrentTimeTicks() +{ + return clock(); +} +#endif + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/micro_time.h b/components/tflite/tensorflow/lite/micro/micro_time.h new file mode 100644 index 00000000..a02d8b02 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_time.h @@ -0,0 +1,36 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_MICRO_MICRO_TIME_H_ +#define TENSORFLOW_LITE_MICRO_MICRO_TIME_H_ + +#include + +namespace tflite { +// These functions should be implemented by each target platform, and provide an +// accurate tick count along with how many ticks there are per second. +int32_t ticks_per_second(); + +// Return time in ticks. The meaning of a tick varies per platform. +int32_t GetCurrentTimeTicks(); + +inline int32_t TicksToMs(int32_t ticks) +{ + return static_cast(1000.0f * static_cast(ticks) / + static_cast(ticks_per_second())); +} + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_MICRO_TIME_H_ diff --git a/components/tflite/tensorflow/lite/micro/micro_time_test.cc b/components/tflite/tensorflow/lite/micro/micro_time_test.cc new file mode 100644 index 00000000..f450cf5e --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_time_test.cc @@ -0,0 +1,49 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/micro_time.h" + +#include "tensorflow/lite/micro/testing/micro_test.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestBasicTimerFunctionality) +{ + int32_t ticks_per_second = tflite::ticks_per_second(); + + // Retry enough times to guarantee a tick advance, while not taking too long + // to complete. With 1e6 retries, assuming each loop takes tens of cycles, + // this will retry for less than 10 seconds on a 10MHz platform. + constexpr int kMaxRetries = 1e6; + int start_time = tflite::GetCurrentTimeTicks(); + + if (ticks_per_second != 0) { + for (int i = 0; i < kMaxRetries; i++) { + if (tflite::GetCurrentTimeTicks() - start_time > 0) { + break; + } + } + } + + // Ensure the timer is increasing. This works for the overflow case too, since + // (MIN_INT + x) - (MAX_INT - y) == x + y + 1. For example, + // 0x80000001(min int + 1) - 0x7FFFFFFE(max int - 1) = 0x00000003 == 3. + // GetTicksPerSecond() == 0 means the timer is not implemented on this + // platform. + TF_LITE_MICRO_EXPECT(ticks_per_second == 0 || + tflite::GetCurrentTimeTicks() - start_time > 0); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/micro_utils.cc b/components/tflite/tensorflow/lite/micro/micro_utils.cc new file mode 100644 index 00000000..6334b165 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_utils.cc @@ -0,0 +1,82 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/micro_utils.h" + +#include +#include +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/op_macros.h" + +namespace tflite { + +int ElementCount(const TfLiteIntArray &dims) +{ + int result = 1; + for (int i = 0; i < dims.size; ++i) { + result *= dims.data[i]; + } + return result; +} + +void SignedSymmetricPerChannelQuantize(const float *values, + TfLiteIntArray *dims, + int quantized_dimension, + int8_t *quantized_values, + float *scaling_factors) +{ + int input_size = ElementCount(*dims); + int channel_count = dims->data[quantized_dimension]; + int per_channel_size = input_size / channel_count; + + int stride; + int channel_stride; + if (quantized_dimension == 0) { + stride = 1; + channel_stride = per_channel_size; + } else if (quantized_dimension == 3) { + stride = channel_count; + channel_stride = 1; + } else { + TF_LITE_FATAL("quantized dimension must be 0 or 3"); + } + + // Calculate scales for each channel. + for (int channel = 0; channel < channel_count; channel++) { + float min = 0; + float max = 0; + + for (int i = 0; i < per_channel_size; i++) { + int idx = channel * channel_stride + i * stride; + min = fminf(min, values[idx]); + max = fmaxf(max, values[idx]); + } + scaling_factors[channel] = + fmaxf(fabs(min), fabs(max)) / std::numeric_limits::max(); + for (int i = 0; i < per_channel_size; i++) { + int idx = channel * channel_stride + i * stride; + const int32_t quantized_value = + static_cast(roundf(values[idx] / scaling_factors[channel])); + // Clamp: just in case some odd numeric offset. + quantized_values[idx] = + fminf(std::numeric_limits::max(), + fmaxf(std::numeric_limits::min() + 1, quantized_value)); + } + } +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/micro_utils.h b/components/tflite/tensorflow/lite/micro/micro_utils.h new file mode 100644 index 00000000..16b92542 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_utils.h @@ -0,0 +1,143 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_MICRO_UTILS_H_ +#define TENSORFLOW_LITE_MICRO_MICRO_UTILS_H_ + +#include +#include +#include +#include + +#include "tensorflow/lite/c/common.h" + +namespace tflite { +// Returns number of elements in the shape array. + +int ElementCount(const TfLiteIntArray &dims); + +// Converts a float value into a quantized value. Note that large values (close +// to max int and min int) may see significant error due to a lack of floating +// point granularity for large values. +template +T FloatToQuantizedType(const float value, const float scale, int zero_point) +{ + int32_t result = round(value / scale) + zero_point; + result = + std::max(static_cast(std::numeric_limits::min()), result); + result = + std::min(static_cast(std::numeric_limits::max()), result); + return result; +} + +template +T FloatToSymmetricQuantizedType(const float value, const float scale) +{ + // 64-bit values are required since 8x16 conv accumulates to int64, meaning + // an int64 bias is required. + std::int64_t result = round(value / scale); + result = std::max( + static_cast(std::numeric_limits::min() + 1), result); + result = std::min(static_cast(std::numeric_limits::max()), + result); + return result; +} + +// Helper methods to quantize arrays of floats to the desired format. +// +// There are several key flavors of quantization in TfLite: +// asymmetric symmetric per channel +// int8_t | X | X | X | +// uint8_t | X | X | | +// int16_t | X | | | +// int32_t | | X | X | +// +// The per-op quantization spec can be found here: +// https://www.tensorflow.org/lite/performance/quantization_spec +template +void Quantize(const float *input, T *output, int num_elements, float scale, + int zero_point) +{ + for (int i = 0; i < num_elements; i++) { + output[i] = FloatToQuantizedType(input[i], scale, zero_point); + } +} + +template +void SymmetricQuantize(const float *input, T *output, int num_elements, + float scale) +{ + for (int i = 0; i < num_elements; i++) { + output[i] = FloatToSymmetricQuantizedType(input[i], scale); + } +} + +template +void SymmetricPerChannelQuantize(const float *input, T *output, + int num_elements, int num_channels, + float *scales) +{ + int elements_per_channel = num_elements / num_channels; + for (int i = 0; i < num_channels; i++) { + for (int j = 0; j < elements_per_channel; j++) { + output[i * elements_per_channel + j] = FloatToSymmetricQuantizedType( + input[i * elements_per_channel + j], scales[i]); + } + } +} + +void SignedSymmetricPerChannelQuantize(const float *values, + TfLiteIntArray *dims, + int quantized_dimension, + int8_t *quantized_values, + float *scaling_factor); + +// Quantizes inputs based on the values provided, choosing the smallest range +// which includes all input values. +template +void SymmetricQuantizeCalculateScales(const float *values, TfLiteIntArray *dims, + T *output, float *scale) +{ + int input_size = ElementCount(*dims); + + float min = 0; + float max = 0; + for (int i = 0; i < input_size; i++) { + min = fminf(min, values[i]); + max = fmaxf(max, values[i]); + } + *scale = fmaxf(std::abs(min), std::abs(max)) / std::numeric_limits::max(); + for (int i = 0; i < input_size; i++) { + const int32_t quantized_value = + static_cast(roundf(values[i] / *scale)); + // Clamp: just in case some odd numeric offset. + quantized_value = fminf(std::numeric_limits::max(), quantized_value); + quantized_value = fmaxf(std::numeric_limits::min() + 1, quantized_value); + output[i] = quantized_value; + } +} + +template +void Dequantize(const T *values, const int size, const float scale, + int zero_point, float *dequantized_values) +{ + for (int i = 0; i < size; ++i) { + dequantized_values[i] = (values[i] - zero_point) * scale; + } +} + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_MICRO_UTILS_H_ diff --git a/components/tflite/tensorflow/lite/micro/micro_utils_test.cc b/components/tflite/tensorflow/lite/micro/micro_utils_test.cc new file mode 100644 index 00000000..397795b3 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/micro_utils_test.cc @@ -0,0 +1,127 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/micro_utils.h" + +#include "tensorflow/lite/micro/testing/micro_test.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(FloatToAsymmetricQuantizedUInt8Test) +{ + using tflite::FloatToQuantizedType; + // [0, 127.5] -> zero_point=0, scale=0.5 + TF_LITE_MICRO_EXPECT_EQ(0, FloatToQuantizedType(0, 0.5, 0)); + TF_LITE_MICRO_EXPECT_EQ(254, FloatToQuantizedType(127, 0.5, 0)); + TF_LITE_MICRO_EXPECT_EQ(255, FloatToQuantizedType(127.5, 0.5, 0)); + // [-10, 245] -> zero_point=10, scale=1.0 + TF_LITE_MICRO_EXPECT_EQ(0, FloatToQuantizedType(-10, 1.0, 10)); + TF_LITE_MICRO_EXPECT_EQ(1, FloatToQuantizedType(-9, 1.0, 10)); + TF_LITE_MICRO_EXPECT_EQ(128, FloatToQuantizedType(118, 1.0, 10)); + TF_LITE_MICRO_EXPECT_EQ(253, FloatToQuantizedType(243, 1.0, 10)); + TF_LITE_MICRO_EXPECT_EQ(254, FloatToQuantizedType(244, 1.0, 10)); + TF_LITE_MICRO_EXPECT_EQ(255, FloatToQuantizedType(245, 1.0, 10)); +} + +TF_LITE_MICRO_TEST(FloatToAsymmetricQuantizedInt8Test) +{ + using tflite::FloatToQuantizedType; + // [-64, 63.5] -> zero_point=0, scale=0.5 + TF_LITE_MICRO_EXPECT_EQ(2, FloatToQuantizedType(1, 0.5, 0)); + TF_LITE_MICRO_EXPECT_EQ(4, FloatToQuantizedType(2, 0.5, 0)); + TF_LITE_MICRO_EXPECT_EQ(6, FloatToQuantizedType(3, 0.5, 0)); + TF_LITE_MICRO_EXPECT_EQ(-10, FloatToQuantizedType(-5, 0.5, 0)); + TF_LITE_MICRO_EXPECT_EQ(-128, FloatToQuantizedType(-64, 0.5, 0)); + TF_LITE_MICRO_EXPECT_EQ(127, FloatToQuantizedType(63.5, 0.5, 0)); + // [-127, 128] -> zero_point=-1, scale=1.0 + TF_LITE_MICRO_EXPECT_EQ(0, FloatToQuantizedType(1, 1.0, -1)); + TF_LITE_MICRO_EXPECT_EQ(-1, FloatToQuantizedType(0, 1.0, -1)); + TF_LITE_MICRO_EXPECT_EQ(126, FloatToQuantizedType(127, 1.0, -1)); + TF_LITE_MICRO_EXPECT_EQ(127, FloatToQuantizedType(128, 1.0, -1)); + TF_LITE_MICRO_EXPECT_EQ(-127, FloatToQuantizedType(-126, 1.0, -1)); + TF_LITE_MICRO_EXPECT_EQ(-128, FloatToQuantizedType(-127, 1.0, -1)); +} + +TF_LITE_MICRO_TEST(FloatToSymmetricQuantizedInt8Test) +{ + using tflite::FloatToSymmetricQuantizedType; + // [-64, 63.5] -> zero_point=0, scale=0.5 + TF_LITE_MICRO_EXPECT_EQ(2, FloatToSymmetricQuantizedType(1, 0.5)); + TF_LITE_MICRO_EXPECT_EQ(4, FloatToSymmetricQuantizedType(2, 0.5)); + TF_LITE_MICRO_EXPECT_EQ(6, FloatToSymmetricQuantizedType(3, 0.5)); + TF_LITE_MICRO_EXPECT_EQ(-10, FloatToSymmetricQuantizedType(-5, 0.5)); + TF_LITE_MICRO_EXPECT_EQ(-127, + FloatToSymmetricQuantizedType(-64, 0.5)); + TF_LITE_MICRO_EXPECT_EQ(127, + FloatToSymmetricQuantizedType(63.5, 0.5)); + // [-127, 128] -> zero_point=-1, scale=1.0 + TF_LITE_MICRO_EXPECT_EQ(1, FloatToSymmetricQuantizedType(1, 1.0)); + TF_LITE_MICRO_EXPECT_EQ(0, FloatToSymmetricQuantizedType(0, 1.0)); + TF_LITE_MICRO_EXPECT_EQ(127, FloatToSymmetricQuantizedType(127, 1.0)); + TF_LITE_MICRO_EXPECT_EQ(127, FloatToSymmetricQuantizedType(128, 1.0)); + TF_LITE_MICRO_EXPECT_EQ(-126, + FloatToSymmetricQuantizedType(-126, 1.0)); + TF_LITE_MICRO_EXPECT_EQ(-127, + FloatToSymmetricQuantizedType(-127, 1.0)); +} + +TF_LITE_MICRO_TEST(FloatToAsymmetricQuantizedInt32Test) +{ + using tflite::FloatToSymmetricQuantizedType; + TF_LITE_MICRO_EXPECT_EQ(0, FloatToSymmetricQuantizedType(0, 0.5)); + TF_LITE_MICRO_EXPECT_EQ(2, FloatToSymmetricQuantizedType(1, 0.5)); + TF_LITE_MICRO_EXPECT_EQ(-2, FloatToSymmetricQuantizedType(-1, 0.5)); + TF_LITE_MICRO_EXPECT_EQ(-100, + FloatToSymmetricQuantizedType(-50, 0.5)); + TF_LITE_MICRO_EXPECT_EQ(100, FloatToSymmetricQuantizedType(50, 0.5)); +} + +TF_LITE_MICRO_TEST(AsymmetricQuantizeInt8) +{ + float values[] = { -10.3, -3.1, -2.1, -1.9, -0.9, 0.1, 0.9, 1.85, 2.9, 4.1 }; + int8_t goldens[] = { -20, -5, -3, -3, -1, 1, 3, 5, 7, 9 }; + constexpr int length = sizeof(values) / sizeof(float); + int8_t quantized[length]; + tflite::Quantize(values, quantized, length, 0.5, 1); + for (int i = 0; i < length; i++) { + TF_LITE_MICRO_EXPECT_EQ(quantized[i], goldens[i]); + } +} + +TF_LITE_MICRO_TEST(AsymmetricQuantizeUInt8) +{ + float values[] = { -10.3, -3.1, -2.1, -1.9, -0.9, 0.1, 0.9, 1.85, 2.9, 4.1 }; + uint8_t goldens[] = { 106, 121, 123, 123, 125, 127, 129, 131, 133, 135 }; + constexpr int length = sizeof(values) / sizeof(float); + uint8_t quantized[length]; + tflite::Quantize(values, quantized, length, 0.5, 127); + for (int i = 0; i < length; i++) { + TF_LITE_MICRO_EXPECT_EQ(quantized[i], goldens[i]); + } +} + +TF_LITE_MICRO_TEST(SymmetricQuantizeInt32) +{ + float values[] = { -10.3, -3.1, -2.1, -1.9, -0.9, 0.1, 0.9, 1.85, 2.9, 4.1 }; + int32_t goldens[] = { -21, -6, -4, -4, -2, 0, 2, 4, 6, 8 }; + constexpr int length = sizeof(values) / sizeof(float); + int32_t quantized[length]; + tflite::SymmetricQuantize(values, quantized, length, 0.5); + for (int i = 0; i < length; i++) { + TF_LITE_MICRO_EXPECT_EQ(quantized[i], goldens[i]); + } +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/mock_micro_graph.cc b/components/tflite/tensorflow/lite/micro/mock_micro_graph.cc new file mode 100644 index 00000000..58d17ad9 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/mock_micro_graph.cc @@ -0,0 +1,82 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/mock_micro_graph.h" + +#include "tensorflow/lite/micro/test_helpers.h" + +namespace tflite { + +MockMicroGraph::MockMicroGraph(SimpleMemoryAllocator *allocator) + : MicroGraph(nullptr, nullptr, nullptr), + allocator_(allocator), + init_count_(0), + prepare_count_(0), + free_count_(0) +{ + memset(invoke_counts_, 0, sizeof(invoke_counts_)); + mock_tensor_ = + reinterpret_cast(allocator_->AllocateFromTail( + sizeof(TfLiteEvalTensor), alignof(TfLiteEvalTensor))); + int *dims_array = reinterpret_cast( + allocator_->AllocateFromTail(3 * sizeof(int), alignof(int))); + float *data_array = reinterpret_cast( + allocator_->AllocateFromTail(2 * sizeof(float), alignof(float))); + int dims[] = { 2, 1, 2 }; + memcpy(dims_array, dims, 3 * sizeof(int)); + mock_tensor_->dims = testing::IntArrayFromInts(dims_array); + mock_tensor_->data.f = data_array; + mock_tensor_->type = kTfLiteFloat32; +} + +TfLiteStatus MockMicroGraph::InvokeSubgraph(int subgraph_idx) +{ + invoke_counts_[subgraph_idx]++; + return kTfLiteOk; +} + +TfLiteStatus MockMicroGraph::ResetVariableTensors() +{ + return kTfLiteOk; +} + +size_t MockMicroGraph::NumSubgraphInputs(int subgraph_idx) +{ + return 1; +} + +TfLiteEvalTensor *MockMicroGraph::GetSubgraphInput(int subgraph_idx, + int tensor_idx) +{ + return mock_tensor_; +} + +size_t MockMicroGraph::NumSubgraphOutputs(int subgraph_idx) +{ + return 1; +} + +TfLiteEvalTensor *MockMicroGraph::GetSubgraphOutput(int subgraph_idx, + int tensor_idx) +{ + return mock_tensor_; +} + +int MockMicroGraph::NumSubgraphs() +{ + return kMaxSubgraphs; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/mock_micro_graph.h b/components/tflite/tensorflow/lite/micro/mock_micro_graph.h new file mode 100644 index 00000000..1c6366a7 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/mock_micro_graph.h @@ -0,0 +1,69 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_MOCK_MICRO_GRAPH_H_ +#define TENSORFLOW_LITE_MICRO_MOCK_MICRO_GRAPH_H_ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/micro_allocator.h" +#include "tensorflow/lite/micro/micro_graph.h" +#include "tensorflow/lite/schema/schema_generated.h" + +namespace tflite { +// MockMicroGraph stubs out all MicroGraph methods used during invoke. A count +// of the number of calls to invoke for each subgraph is maintained for +// validation of control flow operators. +class MockMicroGraph : public MicroGraph { +public: + explicit MockMicroGraph(SimpleMemoryAllocator *allocator); + TfLiteStatus InvokeSubgraph(int subgraph_idx) override; + TfLiteStatus ResetVariableTensors() override; + size_t NumSubgraphInputs(int subgraph_idx) override; + TfLiteEvalTensor *GetSubgraphInput(int subgraph_idx, int tensor_idx) override; + size_t NumSubgraphOutputs(int subgraph_idx) override; + TfLiteEvalTensor *GetSubgraphOutput(int subgraph_idx, + int tensor_idx) override; + int NumSubgraphs() override; + int get_init_count() const + { + return init_count_; + } + int get_prepare_count() const + { + return prepare_count_; + } + int get_free_count() const + { + return free_count_; + } + int get_invoke_count(int subgraph_idx) const + { + return invoke_counts_[subgraph_idx]; + } + +private: + static constexpr int kMaxSubgraphs = 10; + SimpleMemoryAllocator *allocator_; + TfLiteEvalTensor *mock_tensor_; + int init_count_; + int prepare_count_; + int free_count_; + int invoke_counts_[kMaxSubgraphs]; + TF_LITE_REMOVE_VIRTUAL_DELETE +}; + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_MOCK_MICRO_GRAPH_H_ diff --git a/components/tflite/tensorflow/lite/micro/recording_micro_allocator.cc b/components/tflite/tensorflow/lite/micro/recording_micro_allocator.cc new file mode 100644 index 00000000..f1b179f3 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/recording_micro_allocator.cc @@ -0,0 +1,249 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/recording_micro_allocator.h" + +#include "tensorflow/lite/core/api/error_reporter.h" +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/micro/compatibility.h" +#include "tensorflow/lite/micro/micro_allocator.h" +#include "tensorflow/lite/micro/recording_simple_memory_allocator.h" + +namespace tflite { + +RecordingMicroAllocator::RecordingMicroAllocator( + RecordingSimpleMemoryAllocator *recording_memory_allocator, + ErrorReporter *error_reporter) + : MicroAllocator(recording_memory_allocator, error_reporter), + recording_memory_allocator_(recording_memory_allocator) +{ +} + +RecordingMicroAllocator *RecordingMicroAllocator::Create( + uint8_t *tensor_arena, size_t arena_size, ErrorReporter *error_reporter) +{ + TFLITE_DCHECK(error_reporter != nullptr); + + RecordingSimpleMemoryAllocator *simple_memory_allocator = + RecordingSimpleMemoryAllocator::Create(error_reporter, tensor_arena, + arena_size); + TFLITE_DCHECK(simple_memory_allocator != nullptr); + + uint8_t *allocator_buffer = simple_memory_allocator->AllocateFromTail( + sizeof(RecordingMicroAllocator), alignof(RecordingMicroAllocator)); + RecordingMicroAllocator *allocator = new (allocator_buffer) + RecordingMicroAllocator(simple_memory_allocator, error_reporter); + return allocator; +} + +RecordedAllocation RecordingMicroAllocator::GetRecordedAllocation( + RecordedAllocationType allocation_type) const +{ + switch (allocation_type) { + case RecordedAllocationType::kTfLiteEvalTensorData: + return recorded_tflite_eval_tensor_data_; + case RecordedAllocationType::kPersistentTfLiteTensorData: + return recorded_persistent_tflite_tensor_data_; + case RecordedAllocationType::kPersistentTfLiteTensorQuantizationData: + return recorded_persistent_tflite_tensor_quantization_data_; + case RecordedAllocationType::kPersistentBufferData: + return recorded_persistent_buffer_data_; + case RecordedAllocationType::kTfLiteTensorVariableBufferData: + return recorded_tflite_tensor_variable_buffer_data_; + case RecordedAllocationType::kNodeAndRegistrationArray: + return recorded_node_and_registration_array_data_; + case RecordedAllocationType::kOpData: + return recorded_op_data_; + } + TF_LITE_REPORT_ERROR(error_reporter(), "Invalid allocation type supplied: %d", + allocation_type); + return RecordedAllocation(); +} + +const RecordingSimpleMemoryAllocator * +RecordingMicroAllocator::GetSimpleMemoryAllocator() const +{ + return recording_memory_allocator_; +} + +void RecordingMicroAllocator::PrintAllocations() const +{ + TF_LITE_REPORT_ERROR( + error_reporter(), + "[RecordingMicroAllocator] Arena allocation total %d bytes", + recording_memory_allocator_->GetUsedBytes()); + TF_LITE_REPORT_ERROR( + error_reporter(), + "[RecordingMicroAllocator] Arena allocation head %d bytes", + recording_memory_allocator_->GetHeadUsedBytes()); + TF_LITE_REPORT_ERROR( + error_reporter(), + "[RecordingMicroAllocator] Arena allocation tail %d bytes", + recording_memory_allocator_->GetTailUsedBytes()); + PrintRecordedAllocation(RecordedAllocationType::kTfLiteEvalTensorData, + "TfLiteEvalTensor data", "allocations"); + PrintRecordedAllocation(RecordedAllocationType::kPersistentTfLiteTensorData, + "Persistent TfLiteTensor data", "tensors"); + PrintRecordedAllocation( + RecordedAllocationType::kPersistentTfLiteTensorQuantizationData, + "Persistent TfLiteTensor quantization data", "allocations"); + PrintRecordedAllocation(RecordedAllocationType::kPersistentBufferData, + "Persistent buffer data", "allocations"); + PrintRecordedAllocation( + RecordedAllocationType::kTfLiteTensorVariableBufferData, + "TfLiteTensor variable buffer data", "allocations"); + PrintRecordedAllocation(RecordedAllocationType::kNodeAndRegistrationArray, + "NodeAndRegistration struct", + "NodeAndRegistration structs"); + PrintRecordedAllocation(RecordedAllocationType::kOpData, + "Operator runtime data", "OpData structs"); +} + +void *RecordingMicroAllocator::AllocatePersistentBuffer(size_t bytes) +{ + RecordedAllocation allocations = SnapshotAllocationUsage(); + void *buffer = MicroAllocator::AllocatePersistentBuffer(bytes); + RecordAllocationUsage(allocations, recorded_persistent_buffer_data_); + + return buffer; +} + +void RecordingMicroAllocator::PrintRecordedAllocation( + RecordedAllocationType allocation_type, const char *allocation_name, + const char *allocation_description) const +{ +#ifndef TF_LITE_STRIP_ERROR_STRINGS + RecordedAllocation allocation = GetRecordedAllocation(allocation_type); + if (allocation.used_bytes > 0 || allocation.requested_bytes > 0) { + TF_LITE_REPORT_ERROR( + error_reporter(), + "[RecordingMicroAllocator] '%s' used %d bytes with alignment overhead " + "(requested %d bytes for %d %s)", + allocation_name, allocation.used_bytes, allocation.requested_bytes, + allocation.count, allocation_description); + } +#endif +} + +TfLiteStatus RecordingMicroAllocator::AllocateNodeAndRegistrations( + const Model *model, SubgraphAllocations *subgraph_allocations) +{ + RecordedAllocation allocations = SnapshotAllocationUsage(); + + TfLiteStatus status = + MicroAllocator::AllocateNodeAndRegistrations(model, subgraph_allocations); + for (size_t subgraph_idx = 0; subgraph_idx < model->subgraphs()->size(); + subgraph_idx++) { + RecordAllocationUsage(allocations, + recorded_node_and_registration_array_data_); + // The allocation count in SimpleMemoryAllocator will only be 1. To provide + // better logging, decrement by 1 and add in the actual number of operators + // used in the graph: + // The allocation for this recording will always be 1. This is because the + // parent class mallocs one large allocation for the number of nodes in the + // graph (e.g. sizeof(NodeAndRegistration) * num_nodes). + // To prevent extra overhead and potential for fragmentation, manually + // adjust the accounting by decrementing by 1 and adding the actual number + // of nodes used in the graph: + recorded_node_and_registration_array_data_.count += + model->subgraphs()->Get(subgraph_idx)->operators()->size() - 1; + } + return status; +} + +TfLiteStatus RecordingMicroAllocator::AllocateTfLiteEvalTensors( + const Model *model, SubgraphAllocations *subgraph_allocations) +{ + RecordedAllocation allocations = SnapshotAllocationUsage(); + + TfLiteStatus status = + MicroAllocator::AllocateTfLiteEvalTensors(model, subgraph_allocations); + for (size_t subgraph_idx = 0; subgraph_idx < model->subgraphs()->size(); + subgraph_idx++) { + RecordAllocationUsage(allocations, recorded_tflite_eval_tensor_data_); + // The allocation for this recording will always be 1. This is because the + // parent class mallocs one large allocation for the number of tensors in + // the graph (e.g. sizeof(TfLiteEvalTensor) * num_tensors). To prevent extra + // overhead and potential for fragmentation, manually adjust the accounting + // by decrementing by 1 and adding the actual number of tensors used in the + // graph: + recorded_tflite_eval_tensor_data_.count += + model->subgraphs()->Get(subgraph_idx)->tensors()->size() - 1; + } + return status; +} + +TfLiteStatus RecordingMicroAllocator::AllocateVariables( + const SubGraph *subgraph, TfLiteEvalTensor *eval_tensors) +{ + RecordedAllocation allocations = SnapshotAllocationUsage(); + + TfLiteStatus status = + MicroAllocator::AllocateVariables(subgraph, eval_tensors); + + RecordAllocationUsage(allocations, + recorded_tflite_tensor_variable_buffer_data_); + return status; +} + +TfLiteTensor * +RecordingMicroAllocator::AllocatePersistentTfLiteTensorInternal() +{ + RecordedAllocation allocations = SnapshotAllocationUsage(); + + TfLiteTensor *result = + MicroAllocator::AllocatePersistentTfLiteTensorInternal(); + + RecordAllocationUsage(allocations, recorded_persistent_tflite_tensor_data_); + return result; +} + +TfLiteStatus RecordingMicroAllocator::PopulateTfLiteTensorFromFlatbuffer( + const Model *model, TfLiteTensor *tensor, int tensor_index, + int subgraph_index, bool allocate_temp) +{ + RecordedAllocation allocations = SnapshotAllocationUsage(); + + TfLiteStatus status = MicroAllocator::PopulateTfLiteTensorFromFlatbuffer( + model, tensor, tensor_index, subgraph_index, allocate_temp); + + RecordAllocationUsage(allocations, + recorded_persistent_tflite_tensor_quantization_data_); + return status; +} + +RecordedAllocation RecordingMicroAllocator::SnapshotAllocationUsage() const +{ + return { /*requested_bytes=*/recording_memory_allocator_->GetRequestedBytes(), + /*used_bytes=*/recording_memory_allocator_->GetUsedBytes(), + /*count=*/recording_memory_allocator_->GetAllocatedCount() }; +} + +void RecordingMicroAllocator::RecordAllocationUsage( + const RecordedAllocation &snapshotted_allocation, + RecordedAllocation &recorded_allocation) +{ + recorded_allocation.requested_bytes += + recording_memory_allocator_->GetRequestedBytes() - + snapshotted_allocation.requested_bytes; + recorded_allocation.used_bytes += + recording_memory_allocator_->GetUsedBytes() - + snapshotted_allocation.used_bytes; + recorded_allocation.count += + recording_memory_allocator_->GetAllocatedCount() - + snapshotted_allocation.count; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/recording_micro_allocator.h b/components/tflite/tensorflow/lite/micro/recording_micro_allocator.h new file mode 100644 index 00000000..cd2bfa7b --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/recording_micro_allocator.h @@ -0,0 +1,121 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_RECORDING_MICRO_ALLOCATOR_H_ +#define TENSORFLOW_LITE_MICRO_RECORDING_MICRO_ALLOCATOR_H_ + +#include "tensorflow/lite/micro/compatibility.h" +#include "tensorflow/lite/micro/micro_allocator.h" +#include "tensorflow/lite/micro/recording_simple_memory_allocator.h" + +namespace tflite { +// List of buckets currently recorded by this class. Each type keeps a list of +// allocated information during model initialization. +// TODO(b/169834511): Add tracking for scratch buffer allocations. +enum class RecordedAllocationType { + kTfLiteEvalTensorData, + kPersistentTfLiteTensorData, + kPersistentTfLiteTensorQuantizationData, + kPersistentBufferData, + kTfLiteTensorVariableBufferData, + kNodeAndRegistrationArray, + kOpData, +}; + +// Container for holding information about allocation recordings by a given +// type. Each recording contains the number of bytes requested, the actual bytes +// allocated (can defer from requested by alignment), and the number of items +// allocated. +struct RecordedAllocation { + size_t requested_bytes; + size_t used_bytes; + size_t count; +}; + +// Utility subclass of MicroAllocator that records all allocations +// inside the arena. A summary of allocations can be logged through the +// ErrorReporter by invoking LogAllocations(). This special allocator requires +// an instance of RecordingSimpleMemoryAllocator to capture allocations in the +// head and tail. Arena allocation recording can be retrieved by type through +// the GetRecordedAllocation() function. This class should only be used for +// auditing memory usage or integration testing. +class RecordingMicroAllocator : public MicroAllocator { +public: + static RecordingMicroAllocator *Create(uint8_t *tensor_arena, + size_t arena_size, + ErrorReporter *error_reporter); + + // Returns the recorded allocations information for a given allocation type. + RecordedAllocation GetRecordedAllocation( + RecordedAllocationType allocation_type) const; + + const RecordingSimpleMemoryAllocator *GetSimpleMemoryAllocator() const; + + // Logs out through the ErrorReporter all allocation recordings by type + // defined in RecordedAllocationType. + void PrintAllocations() const; + + void *AllocatePersistentBuffer(size_t bytes) override; + +protected: + TfLiteStatus AllocateNodeAndRegistrations( + const Model *model, SubgraphAllocations *subgraph_allocations) override; + TfLiteStatus AllocateTfLiteEvalTensors( + const Model *model, SubgraphAllocations *subgraph_allocations) override; + TfLiteStatus AllocateVariables(const SubGraph *subgraph, + TfLiteEvalTensor *eval_tensors) override; + // TODO(b/162311891): Once all kernels have been updated to the new API drop + // this method. It is only used to record TfLiteTensor persistent allocations. + TfLiteTensor *AllocatePersistentTfLiteTensorInternal() override; + + // TODO(b/162311891): Once all kernels have been updated to the new API drop + // this function since all allocations for quantized data will take place in + // the temp section. + TfLiteStatus PopulateTfLiteTensorFromFlatbuffer(const Model *model, + TfLiteTensor *tensor, + int tensor_index, + int subgraph_index, + bool allocate_temp) override; + +private: + RecordingMicroAllocator(RecordingSimpleMemoryAllocator *memory_allocator, + ErrorReporter *error_reporter); + + void PrintRecordedAllocation(RecordedAllocationType allocation_type, + const char *allocation_name, + const char *allocation_description) const; + + RecordedAllocation SnapshotAllocationUsage() const; + void RecordAllocationUsage(const RecordedAllocation &snapshotted_allocation, + RecordedAllocation &recorded_allocation); + + const RecordingSimpleMemoryAllocator *recording_memory_allocator_; + + RecordedAllocation recorded_tflite_eval_tensor_data_ = {}; + RecordedAllocation recorded_persistent_tflite_tensor_data_ = {}; + RecordedAllocation recorded_persistent_tflite_tensor_quantization_data_ = {}; + RecordedAllocation recorded_persistent_buffer_data_ = {}; + RecordedAllocation recorded_tflite_tensor_variable_buffer_data_ = {}; + RecordedAllocation recorded_node_and_registration_array_data_ = {}; + + // TODO(b/187993291): Re-enable OpData allocating tracking. + RecordedAllocation recorded_op_data_ = {}; + + TF_LITE_REMOVE_VIRTUAL_DELETE +}; + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_RECORDING_MICRO_ALLOCATOR_H_ diff --git a/components/tflite/tensorflow/lite/micro/recording_micro_allocator_test.cc b/components/tflite/tensorflow/lite/micro/recording_micro_allocator_test.cc new file mode 100644 index 00000000..d1b79438 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/recording_micro_allocator_test.cc @@ -0,0 +1,302 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/recording_micro_allocator.h" + +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/micro_allocator.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" +#include "tensorflow/lite/micro/testing/test_conv_model.h" + +#define TF_LITE_TENSOR_STRUCT_SIZE sizeof(TfLiteTensor) +#define TF_LITE_EVAL_TENSOR_STRUCT_SIZE sizeof(TfLiteEvalTensor) +#define TF_LITE_AFFINE_QUANTIZATION_SIZE sizeof(TfLiteAffineQuantization) +#define NODE_AND_REGISTRATION_STRUCT_SIZE sizeof(tflite::NodeAndRegistration) + +// TODO(b/158303868): Move tests into anonymous namespace. +namespace { + +constexpr int kTestConvArenaSize = 1024 * 12; + +} // namespace + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestRecordsTfLiteEvalTensorArrayData) +{ + tflite::ScratchBufferHandle *scratch_buffer_handles = nullptr; + tflite::AllOpsResolver all_ops_resolver; + const tflite::Model *model = tflite::GetModel(kTestConvModelData); + uint8_t arena[kTestConvArenaSize]; + + tflite::RecordingMicroAllocator *micro_allocator = + tflite::RecordingMicroAllocator::Create(arena, kTestConvArenaSize, + tflite::GetMicroErrorReporter()); + // TODO(b/158102673): ugly workaround for not having fatal assertions. Same + // throughout this file. + TF_LITE_MICRO_EXPECT_NE(micro_allocator, nullptr); + if (micro_allocator == nullptr) + return 1; + + tflite::SubgraphAllocations *subgraph_allocations = + micro_allocator->StartModelAllocation(model); + TF_LITE_MICRO_EXPECT(nullptr != subgraph_allocations); + if (subgraph_allocations == nullptr) + return 1; + + TfLiteStatus status = micro_allocator->FinishModelAllocation( + model, subgraph_allocations, &scratch_buffer_handles); + TF_LITE_MICRO_EXPECT_EQ(status, kTfLiteOk); + if (status != kTfLiteOk) + return 1; + + micro_allocator->PrintAllocations(); + + tflite::RecordedAllocation recorded_allocation = + micro_allocator->GetRecordedAllocation( + tflite::RecordedAllocationType::kTfLiteEvalTensorData); + + micro_allocator->PrintAllocations(); + + size_t tensors_count = tflite::testing::GetModelTensorCount(model); + + TF_LITE_MICRO_EXPECT_EQ(recorded_allocation.count, tensors_count); + TF_LITE_MICRO_EXPECT_EQ(recorded_allocation.requested_bytes, + tensors_count * TF_LITE_EVAL_TENSOR_STRUCT_SIZE); + TF_LITE_MICRO_EXPECT_GE(recorded_allocation.used_bytes, + tensors_count * TF_LITE_EVAL_TENSOR_STRUCT_SIZE); +} + +TF_LITE_MICRO_TEST(TestRecordsNodeAndRegistrationArrayData) +{ + tflite::ScratchBufferHandle *scratch_buffer_handles = nullptr; + tflite::AllOpsResolver all_ops_resolver; + const tflite::Model *model = tflite::GetModel(kTestConvModelData); + uint8_t arena[kTestConvArenaSize]; + + tflite::RecordingMicroAllocator *micro_allocator = + tflite::RecordingMicroAllocator::Create(arena, kTestConvArenaSize, + tflite::GetMicroErrorReporter()); + TF_LITE_MICRO_EXPECT_NE(micro_allocator, nullptr); + if (micro_allocator == nullptr) + return 1; + + tflite::SubgraphAllocations *subgraph_allocations = + micro_allocator->StartModelAllocation(model); + TF_LITE_MICRO_EXPECT(nullptr != subgraph_allocations); + if (subgraph_allocations == nullptr) + return 1; + + TfLiteStatus status = micro_allocator->FinishModelAllocation( + model, subgraph_allocations, &scratch_buffer_handles); + TF_LITE_MICRO_EXPECT_EQ(status, kTfLiteOk); + if (status != kTfLiteOk) + return 1; + + size_t num_ops = model->subgraphs()->Get(0)->operators()->size(); + tflite::RecordedAllocation recorded_allocation = + micro_allocator->GetRecordedAllocation( + tflite::RecordedAllocationType::kNodeAndRegistrationArray); + + TF_LITE_MICRO_EXPECT_EQ(recorded_allocation.count, num_ops); + TF_LITE_MICRO_EXPECT_EQ(recorded_allocation.requested_bytes, + num_ops * NODE_AND_REGISTRATION_STRUCT_SIZE); + TF_LITE_MICRO_EXPECT_GE(recorded_allocation.used_bytes, + num_ops * NODE_AND_REGISTRATION_STRUCT_SIZE); +} + +TF_LITE_MICRO_TEST(TestRecordsMultiTenantAllocations) +{ + tflite::ScratchBufferHandle *scratch_buffer_handles = nullptr; + tflite::AllOpsResolver all_ops_resolver; + const tflite::Model *model = tflite::GetModel(kTestConvModelData); + + // Double the arena size to allocate two models inside of it: + uint8_t arena[kTestConvArenaSize * 2]; + + TfLiteStatus status; + + tflite::RecordingMicroAllocator *micro_allocator = + tflite::RecordingMicroAllocator::Create(arena, kTestConvArenaSize * 2, + tflite::GetMicroErrorReporter()); + TF_LITE_MICRO_EXPECT_NE(micro_allocator, nullptr); + if (micro_allocator == nullptr) + return 1; + + // First allocation with the model in the arena: + tflite::SubgraphAllocations *subgraph_allocations = + micro_allocator->StartModelAllocation(model); + TF_LITE_MICRO_EXPECT(nullptr != subgraph_allocations); + if (subgraph_allocations == nullptr) + return 1; + + status = micro_allocator->FinishModelAllocation(model, subgraph_allocations, + &scratch_buffer_handles); + TF_LITE_MICRO_EXPECT_EQ(status, kTfLiteOk); + if (status != kTfLiteOk) + return 1; + + // Second allocation with the same model in the arena: + subgraph_allocations = micro_allocator->StartModelAllocation(model); + TF_LITE_MICRO_EXPECT(nullptr != subgraph_allocations); + if (subgraph_allocations == nullptr) + return 1; + + status = kTfLiteOk, micro_allocator->FinishModelAllocation( + model, subgraph_allocations, &scratch_buffer_handles); + TF_LITE_MICRO_EXPECT_EQ(status, kTfLiteOk); + if (status != kTfLiteOk) + return 1; + + size_t tensors_count = tflite::testing::GetModelTensorCount(model); + + tflite::RecordedAllocation recorded_allocation = + micro_allocator->GetRecordedAllocation( + tflite::RecordedAllocationType::kTfLiteEvalTensorData); + + // Node and tensor arrays must be allocated as well as each node and tensor. + TF_LITE_MICRO_EXPECT_EQ(recorded_allocation.count, tensors_count * 2); + TF_LITE_MICRO_EXPECT_EQ(recorded_allocation.requested_bytes, + tensors_count * TF_LITE_EVAL_TENSOR_STRUCT_SIZE * 2); + TF_LITE_MICRO_EXPECT_GE(recorded_allocation.used_bytes, + tensors_count * TF_LITE_EVAL_TENSOR_STRUCT_SIZE * 2); +} + +TF_LITE_MICRO_TEST(TestRecordsPersistentTfLiteTensorData) +{ + const tflite::Model *model = tflite::GetModel(kTestConvModelData); + uint8_t arena[kTestConvArenaSize]; + + tflite::RecordingMicroAllocator *micro_allocator = + tflite::RecordingMicroAllocator::Create(arena, kTestConvArenaSize, + tflite::GetMicroErrorReporter()); + TF_LITE_MICRO_EXPECT_NE(micro_allocator, nullptr); + if (micro_allocator == nullptr) + return 1; + + TfLiteTensor *tensor = micro_allocator->AllocatePersistentTfLiteTensor( + model, /*subgraph_allocations=*/nullptr, 0, 0); + TF_LITE_MICRO_EXPECT_NE(tensor, nullptr); + if (tensor == nullptr) + return 1; + + tflite::RecordedAllocation recorded_allocation = + micro_allocator->GetRecordedAllocation( + tflite::RecordedAllocationType::kPersistentTfLiteTensorData); + + TF_LITE_MICRO_EXPECT_EQ(recorded_allocation.count, static_cast(1)); + TF_LITE_MICRO_EXPECT_EQ(recorded_allocation.requested_bytes, + TF_LITE_TENSOR_STRUCT_SIZE); + TF_LITE_MICRO_EXPECT_GE(recorded_allocation.used_bytes, + TF_LITE_TENSOR_STRUCT_SIZE); +} + +TF_LITE_MICRO_TEST(TestRecordsPersistentTfLiteTensorQuantizationData) +{ + const tflite::Model *model = tflite::GetModel(kTestConvModelData); + uint8_t arena[kTestConvArenaSize]; + + tflite::RecordingMicroAllocator *micro_allocator = + tflite::RecordingMicroAllocator::Create(arena, kTestConvArenaSize, + tflite::GetMicroErrorReporter()); + TF_LITE_MICRO_EXPECT_NE(micro_allocator, nullptr); + if (micro_allocator == nullptr) + return 1; + + TfLiteTensor *tensor = micro_allocator->AllocatePersistentTfLiteTensor( + model, /*subgraph_allocations=*/nullptr, 0, 0); + TF_LITE_MICRO_EXPECT_NE(tensor, nullptr); + if (tensor == nullptr) + return 1; + + // Walk the model subgraph to find all tensors with quantization params and + // keep a tally. + size_t quantized_channel_bytes = 0; + const tflite::Tensor *cur_tensor = + model->subgraphs()->Get(0)->tensors()->Get(0); + const tflite::QuantizationParameters *quantization_params = + cur_tensor->quantization(); + if (quantization_params && quantization_params->scale() && + quantization_params->scale()->size() > 0 && + quantization_params->zero_point() && + quantization_params->zero_point()->size() > 0) { + size_t num_channels = quantization_params->scale()->size(); + quantized_channel_bytes += TfLiteIntArrayGetSizeInBytes(num_channels); + } + + // Calculate the expected allocation bytes with subgraph quantization data: + size_t expected_requested_bytes = + TF_LITE_AFFINE_QUANTIZATION_SIZE + quantized_channel_bytes; + + tflite::RecordedAllocation recorded_allocation = + micro_allocator->GetRecordedAllocation( + tflite::RecordedAllocationType:: + kPersistentTfLiteTensorQuantizationData); + + // Each quantized tensors has 2 mallocs (quant struct, zero point dimensions): + TF_LITE_MICRO_EXPECT_EQ(recorded_allocation.count, static_cast(2)); + TF_LITE_MICRO_EXPECT_EQ(recorded_allocation.requested_bytes, + expected_requested_bytes); + TF_LITE_MICRO_EXPECT_GE(recorded_allocation.used_bytes, + expected_requested_bytes); +} + +TF_LITE_MICRO_TEST(TestRecordsPersistentBufferData) +{ + uint8_t arena[kTestConvArenaSize]; + + tflite::RecordingMicroAllocator *micro_allocator = + tflite::RecordingMicroAllocator::Create(arena, kTestConvArenaSize, + tflite::GetMicroErrorReporter()); + TF_LITE_MICRO_EXPECT_NE(micro_allocator, nullptr); + if (micro_allocator == nullptr) + return 1; + + void *buffer = micro_allocator->AllocatePersistentBuffer(/*bytes=*/100); + TF_LITE_MICRO_EXPECT_NE(buffer, nullptr); + if (buffer == nullptr) + return 1; + + tflite::RecordedAllocation recorded_allocation = + micro_allocator->GetRecordedAllocation( + tflite::RecordedAllocationType::kPersistentBufferData); + + TF_LITE_MICRO_EXPECT_EQ(recorded_allocation.count, static_cast(1)); + TF_LITE_MICRO_EXPECT_EQ(recorded_allocation.requested_bytes, + static_cast(100)); + TF_LITE_MICRO_EXPECT_GE(recorded_allocation.used_bytes, + static_cast(100)); + + buffer = micro_allocator->AllocatePersistentBuffer(/*bytes=*/50); + TF_LITE_MICRO_EXPECT_NE(buffer, nullptr); + if (buffer == nullptr) + return 1; + + recorded_allocation = micro_allocator->GetRecordedAllocation( + tflite::RecordedAllocationType::kPersistentBufferData); + + TF_LITE_MICRO_EXPECT_EQ(recorded_allocation.count, static_cast(2)); + TF_LITE_MICRO_EXPECT_EQ(recorded_allocation.requested_bytes, + static_cast(150)); + TF_LITE_MICRO_EXPECT_GE(recorded_allocation.used_bytes, + static_cast(150)); +} + +// TODO(b/158124094): Find a way to audit OpData allocations on +// cross-architectures. + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/recording_micro_interpreter.h b/components/tflite/tensorflow/lite/micro/recording_micro_interpreter.h new file mode 100644 index 00000000..2f68f1ac --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/recording_micro_interpreter.h @@ -0,0 +1,70 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_RECORDING_MICRO_INTERPRETER_H_ +#define TENSORFLOW_LITE_MICRO_RECORDING_MICRO_INTERPRETER_H_ + +#include "tensorflow/lite/micro/micro_interpreter.h" +#include "tensorflow/lite/micro/recording_micro_allocator.h" + +namespace tflite { +// Utility subclass that enables internal recordings of the MicroInterpreter. +// This class should be used to audit and analyze memory arena usage for a given +// model and interpreter. +// +// After construction and the first Invoke() or AllocateTensors() call - the +// memory usage is recorded and available through the GetMicroAllocator() +// function. See RecordingMicroAlloctor for more details on what is currently +// recorded from arena allocations. +// +// It is recommended for users to increase the tensor arena size by at least 1kb +// to ensure enough additional memory is available for internal recordings. +class RecordingMicroInterpreter : public MicroInterpreter { +public: + RecordingMicroInterpreter(const Model *model, + const MicroOpResolver &op_resolver, + uint8_t *tensor_arena, size_t tensor_arena_size, + ErrorReporter *error_reporter, + MicroProfiler *profiler = nullptr) + : MicroInterpreter(model, op_resolver, + RecordingMicroAllocator::Create( + tensor_arena, tensor_arena_size, error_reporter), + error_reporter, profiler), + recording_micro_allocator_( + static_cast(allocator())) + { + } + + RecordingMicroInterpreter(const Model *model, + const MicroOpResolver &op_resolver, + RecordingMicroAllocator *allocator, + ErrorReporter *error_reporter) + : MicroInterpreter(model, op_resolver, allocator, error_reporter), + recording_micro_allocator_(*allocator) + { + } + + const RecordingMicroAllocator &GetMicroAllocator() const + { + return recording_micro_allocator_; + } + +private: + const RecordingMicroAllocator &recording_micro_allocator_; +}; + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_RECORDING_MICRO_INTERPRETER_H_ diff --git a/components/tflite/tensorflow/lite/micro/recording_simple_memory_allocator.cc b/components/tflite/tensorflow/lite/micro/recording_simple_memory_allocator.cc new file mode 100644 index 00000000..ee5b0922 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/recording_simple_memory_allocator.cc @@ -0,0 +1,94 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/recording_simple_memory_allocator.h" + +#include + +#include "tensorflow/lite/kernels/internal/compatibility.h" + +namespace tflite { + +RecordingSimpleMemoryAllocator::RecordingSimpleMemoryAllocator( + ErrorReporter *error_reporter, uint8_t *buffer_head, size_t buffer_size) + : SimpleMemoryAllocator(error_reporter, buffer_head, buffer_size), + requested_head_bytes_(0), + requested_tail_bytes_(0), + used_bytes_(0), + alloc_count_(0) +{ +} + +RecordingSimpleMemoryAllocator::~RecordingSimpleMemoryAllocator() +{ +} + +RecordingSimpleMemoryAllocator *RecordingSimpleMemoryAllocator::Create( + ErrorReporter *error_reporter, uint8_t *buffer_head, size_t buffer_size) +{ + TFLITE_DCHECK(error_reporter != nullptr); + TFLITE_DCHECK(buffer_head != nullptr); + RecordingSimpleMemoryAllocator tmp = + RecordingSimpleMemoryAllocator(error_reporter, buffer_head, buffer_size); + + uint8_t *allocator_buffer = + tmp.AllocateFromTail(sizeof(RecordingSimpleMemoryAllocator), + alignof(RecordingSimpleMemoryAllocator)); + // Use the default copy constructor to populate internal states. + return new (allocator_buffer) RecordingSimpleMemoryAllocator(tmp); +} + +size_t RecordingSimpleMemoryAllocator::GetRequestedBytes() const +{ + return requested_head_bytes_ + requested_tail_bytes_; +} + +size_t RecordingSimpleMemoryAllocator::GetUsedBytes() const +{ + return used_bytes_; +} + +size_t RecordingSimpleMemoryAllocator::GetAllocatedCount() const +{ + return alloc_count_; +} + +TfLiteStatus RecordingSimpleMemoryAllocator::SetHeadBufferSize( + size_t size, size_t alignment) +{ + const uint8_t *previous_head = head(); + TfLiteStatus status = + SimpleMemoryAllocator::SetHeadBufferSize(size, alignment); + if (status == kTfLiteOk) { + used_bytes_ += head() - previous_head; + requested_head_bytes_ = size; + } + return status; +} + +uint8_t *RecordingSimpleMemoryAllocator::AllocateFromTail(size_t size, + size_t alignment) +{ + const uint8_t *previous_tail = tail(); + uint8_t *result = SimpleMemoryAllocator::AllocateFromTail(size, alignment); + if (result != nullptr) { + used_bytes_ += previous_tail - tail(); + requested_tail_bytes_ += size; + alloc_count_++; + } + return result; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/recording_simple_memory_allocator.h b/components/tflite/tensorflow/lite/micro/recording_simple_memory_allocator.h new file mode 100644 index 00000000..d9e1578f --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/recording_simple_memory_allocator.h @@ -0,0 +1,63 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_RECORDING_SIMPLE_MEMORY_ALLOCATOR_H_ +#define TENSORFLOW_LITE_MICRO_RECORDING_SIMPLE_MEMORY_ALLOCATOR_H_ + +#include "tensorflow/lite/micro/compatibility.h" +#include "tensorflow/lite/micro/simple_memory_allocator.h" + +namespace tflite { +// Utility class used to log allocations of a SimpleMemoryAllocator. Should only +// be used in debug/evaluation settings or unit tests to evaluate allocation +// usage. +class RecordingSimpleMemoryAllocator : public SimpleMemoryAllocator { +public: + RecordingSimpleMemoryAllocator(ErrorReporter *error_reporter, + uint8_t *buffer_head, size_t buffer_size); + // TODO(b/157615197): Cleanup constructors/destructor and use factory + // functions. + ~RecordingSimpleMemoryAllocator() override; + + static RecordingSimpleMemoryAllocator *Create(ErrorReporter *error_reporter, + uint8_t *buffer_head, + size_t buffer_size); + + // Returns the number of bytes requested from the head or tail. + size_t GetRequestedBytes() const; + + // Returns the number of bytes actually allocated from the head or tail. This + // value will be >= to the number of requested bytes due to padding and + // alignment. + size_t GetUsedBytes() const; + + // Returns the number of alloc calls from the head or tail. + size_t GetAllocatedCount() const; + + TfLiteStatus SetHeadBufferSize(size_t size, size_t alignment) override; + uint8_t *AllocateFromTail(size_t size, size_t alignment) override; + +private: + size_t requested_head_bytes_; + size_t requested_tail_bytes_; + size_t used_bytes_; + size_t alloc_count_; + + TF_LITE_REMOVE_VIRTUAL_DELETE +}; + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_RECORDING_SIMPLE_MEMORY_ALLOCATOR_H_ diff --git a/components/tflite/tensorflow/lite/micro/recording_simple_memory_allocator_test.cc b/components/tflite/tensorflow/lite/micro/recording_simple_memory_allocator_test.cc new file mode 100644 index 00000000..7e1dfe72 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/recording_simple_memory_allocator_test.cc @@ -0,0 +1,144 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/recording_simple_memory_allocator.h" + +#include + +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestRecordsTailAllocations) +{ + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::RecordingSimpleMemoryAllocator allocator( + tflite::GetMicroErrorReporter(), arena, arena_size); + + uint8_t *result = allocator.AllocateFromTail(/*size=*/10, /*alignment=*/1); + TF_LITE_MICRO_EXPECT_NE(result, nullptr); + TF_LITE_MICRO_EXPECT_EQ(allocator.GetUsedBytes(), static_cast(10)); + TF_LITE_MICRO_EXPECT_EQ(allocator.GetRequestedBytes(), + static_cast(10)); + TF_LITE_MICRO_EXPECT_EQ(allocator.GetAllocatedCount(), + static_cast(1)); + + result = allocator.AllocateFromTail(/*size=*/20, /*alignment=*/1); + TF_LITE_MICRO_EXPECT_NE(result, nullptr); + TF_LITE_MICRO_EXPECT_EQ(allocator.GetUsedBytes(), static_cast(30)); + TF_LITE_MICRO_EXPECT_EQ(allocator.GetRequestedBytes(), + static_cast(30)); + TF_LITE_MICRO_EXPECT_EQ(allocator.GetAllocatedCount(), + static_cast(2)); +} + +TF_LITE_MICRO_TEST(TestRecordsMisalignedTailAllocations) +{ + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::RecordingSimpleMemoryAllocator allocator( + tflite::GetMicroErrorReporter(), arena, arena_size); + + uint8_t *result = allocator.AllocateFromTail(/*size=*/10, /*alignment=*/12); + TF_LITE_MICRO_EXPECT_NE(result, nullptr); + // Validate used bytes in 8 byte range that can included alignment of 12: + TF_LITE_MICRO_EXPECT_GE(allocator.GetUsedBytes(), static_cast(10)); + TF_LITE_MICRO_EXPECT_LE(allocator.GetUsedBytes(), static_cast(20)); + TF_LITE_MICRO_EXPECT_EQ(allocator.GetRequestedBytes(), + static_cast(10)); + TF_LITE_MICRO_EXPECT_EQ(allocator.GetAllocatedCount(), + static_cast(1)); +} + +TF_LITE_MICRO_TEST(TestDoesNotRecordFailedTailAllocations) +{ + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::RecordingSimpleMemoryAllocator allocator( + tflite::GetMicroErrorReporter(), arena, arena_size); + + uint8_t *result = allocator.AllocateFromTail(/*size=*/2048, /*alignment=*/1); + TF_LITE_MICRO_EXPECT(result == nullptr); + TF_LITE_MICRO_EXPECT_EQ(allocator.GetUsedBytes(), static_cast(0)); + TF_LITE_MICRO_EXPECT_EQ(allocator.GetRequestedBytes(), + static_cast(0)); + TF_LITE_MICRO_EXPECT_EQ(allocator.GetAllocatedCount(), + static_cast(0)); +} + +TF_LITE_MICRO_TEST(TestRecordsHeadSizeAdjustment) +{ + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::RecordingSimpleMemoryAllocator allocator( + tflite::GetMicroErrorReporter(), arena, arena_size); + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, allocator.SetHeadBufferSize(/*size=*/5, /*alignment=*/1)); + TF_LITE_MICRO_EXPECT_EQ(allocator.GetUsedBytes(), static_cast(5)); + TF_LITE_MICRO_EXPECT_EQ(allocator.GetRequestedBytes(), + static_cast(5)); + // Head adjustments do not count as an allocation: + TF_LITE_MICRO_EXPECT_EQ(allocator.GetAllocatedCount(), + static_cast(0)); + + uint8_t *result = allocator.AllocateFromTail(/*size=*/15, /*alignment=*/1); + TF_LITE_MICRO_EXPECT_NE(result, nullptr); + TF_LITE_MICRO_EXPECT_EQ(allocator.GetUsedBytes(), static_cast(20)); + TF_LITE_MICRO_EXPECT_EQ(allocator.GetRequestedBytes(), + static_cast(20)); + TF_LITE_MICRO_EXPECT_EQ(allocator.GetAllocatedCount(), + static_cast(1)); +} + +TF_LITE_MICRO_TEST(TestRecordsMisalignedHeadSizeAdjustments) +{ + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::RecordingSimpleMemoryAllocator allocator( + tflite::GetMicroErrorReporter(), arena, arena_size); + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, allocator.SetHeadBufferSize(/*size=*/10, /*alignment=*/12)); + // Validate used bytes in 8 byte range that can included alignment of 12: + TF_LITE_MICRO_EXPECT_GE(allocator.GetUsedBytes(), static_cast(10)); + TF_LITE_MICRO_EXPECT_LE(allocator.GetUsedBytes(), static_cast(20)); + TF_LITE_MICRO_EXPECT_EQ(allocator.GetRequestedBytes(), + static_cast(10)); + // Head adjustments do not count as an allocation: + TF_LITE_MICRO_EXPECT_EQ(allocator.GetAllocatedCount(), + static_cast(0)); +} + +TF_LITE_MICRO_TEST(TestDoesNotRecordFailedTailAllocations) +{ + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::RecordingSimpleMemoryAllocator allocator( + tflite::GetMicroErrorReporter(), arena, arena_size); + + TF_LITE_MICRO_EXPECT_EQ(kTfLiteError, allocator.SetHeadBufferSize( + /*size=*/2048, /*alignment=*/1)); + TF_LITE_MICRO_EXPECT_EQ(allocator.GetUsedBytes(), static_cast(0)); + TF_LITE_MICRO_EXPECT_EQ(allocator.GetRequestedBytes(), + static_cast(0)); + TF_LITE_MICRO_EXPECT_EQ(allocator.GetAllocatedCount(), + static_cast(0)); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/simple_memory_allocator.cc b/components/tflite/tensorflow/lite/micro/simple_memory_allocator.cc new file mode 100644 index 00000000..0126610f --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/simple_memory_allocator.cc @@ -0,0 +1,176 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/simple_memory_allocator.h" + +#include +#include +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/core/api/error_reporter.h" +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/micro/memory_helpers.h" + +namespace tflite { + +SimpleMemoryAllocator::SimpleMemoryAllocator(ErrorReporter *error_reporter, + uint8_t *buffer_head, + uint8_t *buffer_tail) + : error_reporter_(error_reporter), + buffer_head_(buffer_head), + buffer_tail_(buffer_tail), + head_(buffer_head), + tail_(buffer_tail), + temp_(buffer_head_) +{ +} + +SimpleMemoryAllocator::SimpleMemoryAllocator(ErrorReporter *error_reporter, + uint8_t *buffer, + size_t buffer_size) + : SimpleMemoryAllocator(error_reporter, buffer, buffer + buffer_size) +{ +} + +/* static */ +SimpleMemoryAllocator *SimpleMemoryAllocator::Create( + ErrorReporter *error_reporter, uint8_t *buffer_head, size_t buffer_size) +{ + TFLITE_DCHECK(error_reporter != nullptr); + TFLITE_DCHECK(buffer_head != nullptr); + SimpleMemoryAllocator tmp = + SimpleMemoryAllocator(error_reporter, buffer_head, buffer_size); + + // Allocate enough bytes from the buffer to create a SimpleMemoryAllocator. + // The new instance will use the current adjusted tail buffer from the tmp + // allocator instance. + uint8_t *allocator_buffer = tmp.AllocateFromTail( + sizeof(SimpleMemoryAllocator), alignof(SimpleMemoryAllocator)); + // Use the default copy constructor to populate internal states. + return new (allocator_buffer) SimpleMemoryAllocator(tmp); +} + +SimpleMemoryAllocator::~SimpleMemoryAllocator() +{ +} + +TfLiteStatus SimpleMemoryAllocator::SetHeadBufferSize(size_t size, + size_t alignment) +{ + if (head_ != temp_) { + TF_LITE_REPORT_ERROR( + error_reporter_, + "Internal error: SetHeadBufferSize() needs to be called " + "after ResetTempAllocations()."); + return kTfLiteError; + } + + uint8_t *const aligned_result = AlignPointerUp(buffer_head_, alignment); + const size_t available_memory = tail_ - aligned_result; + if (available_memory < size) { + TF_LITE_REPORT_ERROR( + error_reporter_, + "Failed to set head size. Requested: %u, available %u, missing: %u", + size, available_memory, size - available_memory); + return kTfLiteError; + } + head_ = aligned_result + size; + temp_ = head_; + + return kTfLiteOk; +} + +uint8_t *SimpleMemoryAllocator::AllocateFromTail(size_t size, + size_t alignment) +{ + uint8_t *const aligned_result = AlignPointerDown(tail_ - size, alignment); + if (aligned_result < head_) { +#ifndef TF_LITE_STRIP_ERROR_STRINGS + const size_t missing_memory = head_ - aligned_result; + TF_LITE_REPORT_ERROR(error_reporter_, + "Failed to allocate tail memory. Requested: %u, " + "available %u, missing: %u", + size, size - missing_memory, missing_memory); +#endif + return nullptr; + } + tail_ = aligned_result; + return aligned_result; +} + +uint8_t *SimpleMemoryAllocator::AllocateTemp(size_t size, size_t alignment) +{ + uint8_t *const aligned_result = AlignPointerUp(temp_, alignment); + const size_t available_memory = tail_ - aligned_result; + if (available_memory < size) { + TF_LITE_REPORT_ERROR(error_reporter_, + "Failed to allocate temp memory. Requested: %u, " + "available %u, missing: %u", + size, available_memory, size - available_memory); + return nullptr; + } + temp_ = aligned_result + size; + return aligned_result; +} + +void SimpleMemoryAllocator::ResetTempAllocations() +{ + temp_ = head_; +} + +uint8_t *SimpleMemoryAllocator::GetHeadBuffer() const +{ + return buffer_head_; +} + +size_t SimpleMemoryAllocator::GetHeadUsedBytes() const +{ + return head_ - buffer_head_; +} + +size_t SimpleMemoryAllocator::GetTailUsedBytes() const +{ + return buffer_tail_ - tail_; +} + +size_t SimpleMemoryAllocator::GetAvailableMemory(size_t alignment) const +{ + uint8_t *const aligned_temp = AlignPointerUp(temp_, alignment); + uint8_t *const aligned_tail = AlignPointerDown(tail_, alignment); + return aligned_tail - aligned_temp; +} + +size_t SimpleMemoryAllocator::GetUsedBytes() const +{ + return GetBufferSize() - (tail_ - temp_); +} + +size_t SimpleMemoryAllocator::GetBufferSize() const +{ + return buffer_tail_ - buffer_head_; +} + +uint8_t *SimpleMemoryAllocator::head() const +{ + return head_; +} + +uint8_t *SimpleMemoryAllocator::tail() const +{ + return tail_; +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/simple_memory_allocator.h b/components/tflite/tensorflow/lite/micro/simple_memory_allocator.h new file mode 100644 index 00000000..18731f78 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/simple_memory_allocator.h @@ -0,0 +1,111 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_SIMPLE_MEMORY_ALLOCATOR_H_ +#define TENSORFLOW_LITE_MICRO_SIMPLE_MEMORY_ALLOCATOR_H_ + +#include +#include + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/core/api/error_reporter.h" +#include "tensorflow/lite/micro/compatibility.h" + +namespace tflite { +// TODO(petewarden): This allocator never frees up or reuses any memory, even +// though we have enough information about lifetimes of the tensors to do so. +// This makes it pretty wasteful, so we should use a more intelligent method. +class SimpleMemoryAllocator { +public: + // TODO(b/157615197): Cleanup constructors/destructor and use factory + // functions. + SimpleMemoryAllocator(ErrorReporter *error_reporter, uint8_t *buffer_head, + uint8_t *buffer_tail); + SimpleMemoryAllocator(ErrorReporter *error_reporter, uint8_t *buffer, + size_t buffer_size); + virtual ~SimpleMemoryAllocator(); + + // Creates a new SimpleMemoryAllocator from a given buffer head and size. + static SimpleMemoryAllocator *Create(ErrorReporter *error_reporter, + uint8_t *buffer_head, + size_t buffer_size); + + // Adjusts the head (lowest address and moving upwards) memory allocation to a + // given size. Calls to this method will also invalidate all temporary + // allocation values (it sets the location of temp space at the end of the + // head section). This call will fail if a chain of allocations through + // AllocateTemp() have not been cleaned up with a call to + // ResetTempAllocations(). + virtual TfLiteStatus SetHeadBufferSize(size_t size, size_t alignment); + + // Allocates memory starting at the tail of the arena (highest address and + // moving downwards). + virtual uint8_t *AllocateFromTail(size_t size, size_t alignment); + + // Allocates a temporary buffer from the head of the arena (lowest address and + // moving upwards) but does not update the actual head allocation size or + // position. The returned buffer is guaranteed until either + // ResetTempAllocations() is called or another call to AllocateFromHead(). + // Repeat calls to this function will create a chain of temp allocations. All + // calls to AllocateTemp() must end with a call to ResetTempAllocations(). If + // AllocateFromHead() is called before a call to ResetTempAllocations(), it + // will fail with an error message. + virtual uint8_t *AllocateTemp(size_t size, size_t alignment); + + // Resets a chain of temporary allocations back to the current head of the + // arena (lowest address). + virtual void ResetTempAllocations(); + + // Returns a pointer to the buffer currently assigned to the head section. + // This buffer is set by calling SetHeadSize(). + uint8_t *GetHeadBuffer() const; + + // Returns the size of the head section in bytes. + size_t GetHeadUsedBytes() const; + + // Returns the size of all allocations in the tail section in bytes. + size_t GetTailUsedBytes() const; + + // Returns the number of bytes available with a given alignment. This number + // takes in account any temporary allocations. + size_t GetAvailableMemory(size_t alignment) const; + + // Returns the number of used bytes in the allocator. This number takes in + // account any temporary allocations. + size_t GetUsedBytes() const; + +protected: + // Returns a pointer to the current end of the head buffer. + uint8_t *head() const; + + // Returns a pointer to the current end of the tail buffer. + uint8_t *tail() const; + +private: + size_t GetBufferSize() const; + + ErrorReporter *error_reporter_; + uint8_t *buffer_head_; + uint8_t *buffer_tail_; + uint8_t *head_; + uint8_t *tail_; + uint8_t *temp_; + + TF_LITE_REMOVE_VIRTUAL_DELETE +}; + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_SIMPLE_MEMORY_ALLOCATOR_H_ diff --git a/components/tflite/tensorflow/lite/micro/simple_memory_allocator_test.cc b/components/tflite/tensorflow/lite/micro/simple_memory_allocator_test.cc new file mode 100644 index 00000000..5acaeb86 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/simple_memory_allocator_test.cc @@ -0,0 +1,285 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/simple_memory_allocator.h" + +#include + +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(TestEnsureHeadSizeSimpleAlignment) +{ + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::SimpleMemoryAllocator allocator(tflite::GetMicroErrorReporter(), + arena, arena_size); + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, allocator.SetHeadBufferSize(/*size=*/100, /*alignment=*/1)); + TF_LITE_MICRO_EXPECT_EQ(static_cast(100), + allocator.GetHeadUsedBytes()); + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, allocator.SetHeadBufferSize(/*size=*/10, /*alignment=*/1)); + TF_LITE_MICRO_EXPECT_EQ(static_cast(10), + allocator.GetHeadUsedBytes()); + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, allocator.SetHeadBufferSize(/*size=*/1000, /*alignment=*/1)); + TF_LITE_MICRO_EXPECT_EQ(static_cast(1000), + allocator.GetHeadUsedBytes()); +} + +TF_LITE_MICRO_TEST(TestAdjustHeadSizeMisalignment) +{ + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::SimpleMemoryAllocator allocator(tflite::GetMicroErrorReporter(), + arena, arena_size); + + // First head adjustment of 100 bytes (aligned 12): + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, allocator.SetHeadBufferSize(/*size=*/100, /*alignment=*/12)); + + // Offset alignment of 12 can lead to allocation within 8 byte range of + // requested bytes based to arena alignment at runtime: + TF_LITE_MICRO_EXPECT_GE(allocator.GetHeadUsedBytes(), 100); + TF_LITE_MICRO_EXPECT_LE(allocator.GetHeadUsedBytes(), 100 + 11); + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, allocator.SetHeadBufferSize(/*size=*/10, /*alignment=*/12)); + TF_LITE_MICRO_EXPECT_GE(allocator.GetHeadUsedBytes(), 10); + TF_LITE_MICRO_EXPECT_LE(allocator.GetHeadUsedBytes(), 100 + 11); + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, allocator.SetHeadBufferSize(/*size=*/1000, /*alignment=*/12)); + TF_LITE_MICRO_EXPECT_GE(allocator.GetHeadUsedBytes(), 1000); + TF_LITE_MICRO_EXPECT_LE(allocator.GetHeadUsedBytes(), 1000 + 11); +} + +TF_LITE_MICRO_TEST(TestAdjustHeadSizeMisalignedHandlesCorrectBytesAvailable) +{ + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::SimpleMemoryAllocator allocator(tflite::GetMicroErrorReporter(), + arena, arena_size); + + // First head adjustment of 100 bytes (aligned 12): + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, allocator.SetHeadBufferSize(/*size=*/100, /*alignment=*/12)); + + // allocator.GetAvailableMemory() should also report the actual amount of + // memory available based on a requested offset (12): + size_t aligned_available_bytes = + allocator.GetAvailableMemory(/*alignment=*/12); + TF_LITE_MICRO_EXPECT_LE(aligned_available_bytes, arena_size - 100); + TF_LITE_MICRO_EXPECT_GE(aligned_available_bytes, arena_size - 100 - 24); + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, allocator.SetHeadBufferSize(/*size=*/10, /*alignment=*/12)); + aligned_available_bytes = allocator.GetAvailableMemory(/*alignment=*/12); + + TF_LITE_MICRO_EXPECT_LE(aligned_available_bytes, arena_size - 10); + TF_LITE_MICRO_EXPECT_GE(aligned_available_bytes, arena_size - 10 - 24); + + TF_LITE_MICRO_EXPECT_EQ( + kTfLiteOk, allocator.SetHeadBufferSize(/*size=*/1000, /*alignment=*/12)); + aligned_available_bytes = allocator.GetAvailableMemory(/*alignment=*/12); + TF_LITE_MICRO_EXPECT_LE(aligned_available_bytes, arena_size - 1000); + TF_LITE_MICRO_EXPECT_GE(aligned_available_bytes, arena_size - 1000 - 24); +} + +TF_LITE_MICRO_TEST(TestGetAvailableMemory) +{ + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::SimpleMemoryAllocator allocator(tflite::GetMicroErrorReporter(), + arena, arena_size); + + constexpr size_t allocation_size = 100; + allocator.SetHeadBufferSize(/*size=*/allocation_size, + /*alignment=*/1); + allocator.AllocateFromTail(/*size=*/allocation_size, + /*alignment=*/1); + + TF_LITE_MICRO_EXPECT_EQ(allocator.GetAvailableMemory(/*alignment=*/1), + arena_size - allocation_size * 2); +} + +TF_LITE_MICRO_TEST(TestGetAvailableMemoryWithTempAllocations) +{ + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::SimpleMemoryAllocator allocator(tflite::GetMicroErrorReporter(), + arena, arena_size); + + constexpr size_t allocation_size = 100; + allocator.AllocateTemp(/*size=*/allocation_size, + /*alignment=*/1); + + TF_LITE_MICRO_EXPECT_EQ(allocator.GetAvailableMemory(/*alignment=*/1), + arena_size - allocation_size); + + // Reset temp allocations and ensure GetAvailableMemory() is back to the + // starting size: + allocator.ResetTempAllocations(); + + TF_LITE_MICRO_EXPECT_EQ(allocator.GetAvailableMemory(/*alignment=*/1), + arena_size); +} + +TF_LITE_MICRO_TEST(TestGetUsedBytes) +{ + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::SimpleMemoryAllocator allocator(tflite::GetMicroErrorReporter(), + arena, arena_size); + TF_LITE_MICRO_EXPECT_EQ(allocator.GetUsedBytes(), static_cast(0)); + + constexpr size_t allocation_size = 100; + allocator.SetHeadBufferSize(/*size=*/allocation_size, + /*alignment=*/1); + allocator.AllocateFromTail(/*size=*/allocation_size, + /*alignment=*/1); + + TF_LITE_MICRO_EXPECT_EQ(allocator.GetUsedBytes(), allocation_size * 2); +} + +TF_LITE_MICRO_TEST(TestGetUsedBytesTempAllocations) +{ + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::SimpleMemoryAllocator allocator(tflite::GetMicroErrorReporter(), + arena, arena_size); + + constexpr size_t allocation_size = 100; + allocator.AllocateTemp(/*size=*/allocation_size, + /*alignment=*/1); + + TF_LITE_MICRO_EXPECT_EQ(allocator.GetUsedBytes(), allocation_size); + + // Reset temp allocations and ensure GetUsedBytes() is back to the starting + // size: + allocator.ResetTempAllocations(); + + TF_LITE_MICRO_EXPECT_EQ(allocator.GetUsedBytes(), static_cast(0)); +} + +TF_LITE_MICRO_TEST(TestJustFits) +{ + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::SimpleMemoryAllocator allocator(tflite::GetMicroErrorReporter(), + arena, arena_size); + + uint8_t *result = allocator.AllocateFromTail(arena_size, 1); + TF_LITE_MICRO_EXPECT(nullptr != result); +} + +TF_LITE_MICRO_TEST(TestAligned) +{ + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::SimpleMemoryAllocator allocator(tflite::GetMicroErrorReporter(), + arena, arena_size); + + uint8_t *result = allocator.AllocateFromTail(1, 1); + TF_LITE_MICRO_EXPECT(nullptr != result); + + result = allocator.AllocateFromTail(16, 4); + TF_LITE_MICRO_EXPECT(nullptr != result); + TF_LITE_MICRO_EXPECT_EQ(static_cast(0), + reinterpret_cast(result) & 3); +} + +TF_LITE_MICRO_TEST(TestMultipleTooLarge) +{ + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::SimpleMemoryAllocator allocator(tflite::GetMicroErrorReporter(), + arena, arena_size); + + uint8_t *result = allocator.AllocateFromTail(768, 1); + TF_LITE_MICRO_EXPECT(nullptr != result); + + result = allocator.AllocateFromTail(768, 1); + TF_LITE_MICRO_EXPECT(nullptr == result); +} + +TF_LITE_MICRO_TEST(TestTempAllocations) +{ + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::SimpleMemoryAllocator allocator(tflite::GetMicroErrorReporter(), + arena, arena_size); + + uint8_t *temp1 = allocator.AllocateTemp(100, 1); + TF_LITE_MICRO_EXPECT(nullptr != temp1); + + uint8_t *temp2 = allocator.AllocateTemp(100, 1); + TF_LITE_MICRO_EXPECT(nullptr != temp2); + + // Expect that the next micro allocation is 100 bytes away from each other. + TF_LITE_MICRO_EXPECT_EQ(temp2 - temp1, 100); +} + +TF_LITE_MICRO_TEST(TestResetTempAllocations) +{ + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::SimpleMemoryAllocator allocator(tflite::GetMicroErrorReporter(), + arena, arena_size); + + uint8_t *temp1 = allocator.AllocateTemp(100, 1); + TF_LITE_MICRO_EXPECT(nullptr != temp1); + + allocator.ResetTempAllocations(); + + uint8_t *temp2 = allocator.AllocateTemp(100, 1); + TF_LITE_MICRO_EXPECT(nullptr != temp2); + + // Reset temp allocations should have the same start address: + TF_LITE_MICRO_EXPECT_EQ(temp2 - temp1, 0); +} + +TF_LITE_MICRO_TEST(TestEnsureHeadSizeWithoutResettingTemp) +{ + constexpr size_t arena_size = 1024; + uint8_t arena[arena_size]; + tflite::SimpleMemoryAllocator allocator(tflite::GetMicroErrorReporter(), + arena, arena_size); + + uint8_t *temp = allocator.AllocateTemp(100, 1); + TF_LITE_MICRO_EXPECT(nullptr != temp); + + // Adjustment to head should fail since temp allocation was not followed by a + // call to ResetTempAllocations(). + TF_LITE_MICRO_EXPECT_EQ(kTfLiteError, allocator.SetHeadBufferSize(100, 1)); + + allocator.ResetTempAllocations(); + + // Reduce head size back to zero. + TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, allocator.SetHeadBufferSize(0, 1)); + + // The most recent head allocation should be in the same location as the + // original temp allocation pointer. + TF_LITE_MICRO_EXPECT(temp == allocator.GetHeadBuffer()); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/system_setup.cc b/components/tflite/tensorflow/lite/micro/system_setup.cc new file mode 100644 index 00000000..24881d5e --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/system_setup.cc @@ -0,0 +1,27 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/system_setup.h" + +namespace tflite { + +// To add an equivalent function for your own platform, create your own +// implementation file, and place it in a subfolder named after the target. See +// tensorflow/lite/micro/debug_log.cc for a similar example. +void InitializeTarget() +{ +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/system_setup.h b/components/tflite/tensorflow/lite/micro/system_setup.h new file mode 100644 index 00000000..9ef4266a --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/system_setup.h @@ -0,0 +1,26 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_MICRO_SYSTEM_SETUP_H_ +#define TENSORFLOW_LITE_MICRO_SYSTEM_SETUP_H_ + +namespace tflite { +// This should called during initialization of TFLM binaries and tests. It can +// be specialized if there is a need for custom target-specific intialization. +// For more information, see tensorflow/lite/micro/system_setup.cc. +void InitializeTarget(); + +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_SYSTEM_SETUP_H_ diff --git a/components/tflite/tensorflow/lite/micro/test_helpers.cc b/components/tflite/tensorflow/lite/micro/test_helpers.cc new file mode 100644 index 00000000..565ffbf1 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/test_helpers.cc @@ -0,0 +1,1394 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/test_helpers.h" + +#include +#include +#include +#include +#include + +#include "flatbuffers/flatbuffers.h" // from @flatbuffers +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/core/api/error_reporter.h" +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/micro_utils.h" +#include "tensorflow/lite/schema/schema_generated.h" + +// TODO(b/170464050): Use TFLM test only version of schema_utils. + +namespace tflite { +namespace testing { +namespace { + +class StackAllocator : public flatbuffers::Allocator { +public: + StackAllocator() + : data_(data_backing_), data_size_(0) + { + } + + uint8_t *allocate(size_t size) override + { + TFLITE_DCHECK((data_size_ + size) <= kStackAllocatorSize); + uint8_t *result = data_; + data_ += size; + data_size_ += size; + return result; + } + + void deallocate(uint8_t *p, size_t) override + { + } + + static StackAllocator &instance() + { + // Avoid using true dynamic memory allocation to be portable to bare metal. + static char inst_memory[sizeof(StackAllocator)]; + static StackAllocator *inst = new (inst_memory) StackAllocator; + return *inst; + } + + static constexpr size_t kStackAllocatorSize = 8192; + +private: + uint8_t data_backing_[kStackAllocatorSize]; + uint8_t *data_; + int data_size_; +}; + +flatbuffers::FlatBufferBuilder *BuilderInstance() +{ + static char inst_memory[sizeof(flatbuffers::FlatBufferBuilder)]; + static flatbuffers::FlatBufferBuilder *inst = + new (inst_memory) flatbuffers::FlatBufferBuilder( + StackAllocator::kStackAllocatorSize, &StackAllocator::instance()); + return inst; +} + +// A wrapper around FlatBuffer API to help build model easily. +class ModelBuilder { +public: + typedef int32_t Tensor; + typedef int Operator; + typedef int Node; + + // `builder` needs to be available until BuildModel is called. + explicit ModelBuilder(flatbuffers::FlatBufferBuilder *builder) + : builder_(builder) + { + } + + // Registers an operator that will be used in the model. + Operator RegisterOp(BuiltinOperator op, const char *custom_code); + + // Adds a tensor to the model. + Tensor AddTensor(TensorType type, std::initializer_list shape) + { + return AddTensorImpl(type, /* is_variable */ false, shape); + } + + // Adds a variable tensor to the model. + Tensor AddVariableTensor(TensorType type, + std::initializer_list shape) + { + return AddTensorImpl(type, /* is_variable */ true, shape); + } + + // Adds a node to the model with given input and output Tensors. + Node AddNode(Operator op, std::initializer_list inputs, + std::initializer_list outputs); + + void AddMetadata(const char *description_string, + const int32_t *metadata_buffer_data, size_t num_elements); + + // Constructs the flatbuffer model using `builder_` and return a pointer to + // it. The returned model has the same lifetime as `builder_`. + // Note the default value of 0 for num_subgraph_inputs means all tensor inputs + // are in subgraph input list. + const Model *BuildModel(std::initializer_list inputs, + std::initializer_list outputs, + size_t num_subgraph_inputs = 0); + +private: + // Adds a tensor to the model. + Tensor AddTensorImpl(TensorType type, bool is_variable, + std::initializer_list shape); + + flatbuffers::FlatBufferBuilder *builder_; + + static constexpr int kMaxOperatorCodes = 10; + flatbuffers::Offset operator_codes_[kMaxOperatorCodes]; + int next_operator_code_id_ = 0; + + static constexpr int kMaxOperators = 50; + flatbuffers::Offset operators_[kMaxOperators]; + int next_operator_id_ = 0; + + static constexpr int kMaxTensors = 50; + flatbuffers::Offset tensors_[kMaxTensors]; + + static constexpr int kMaxMetadataBuffers = 10; + + static constexpr int kMaxMetadatas = 10; + flatbuffers::Offset metadata_[kMaxMetadatas]; + + flatbuffers::Offset metadata_buffers_[kMaxMetadataBuffers]; + + int nbr_of_metadata_buffers_ = 0; + + int next_tensor_id_ = 0; +}; + +ModelBuilder::Operator ModelBuilder::RegisterOp(BuiltinOperator op, + const char *custom_code) +{ + TFLITE_DCHECK(next_operator_code_id_ <= kMaxOperatorCodes); + operator_codes_[next_operator_code_id_] = tflite::CreateOperatorCodeDirect( + *builder_, /*deprecated_builtin_code=*/0, custom_code, /*version=*/0, op); + next_operator_code_id_++; + return next_operator_code_id_ - 1; +} + +ModelBuilder::Node ModelBuilder::AddNode( + ModelBuilder::Operator op, + std::initializer_list inputs, + std::initializer_list outputs) +{ + TFLITE_DCHECK(next_operator_id_ <= kMaxOperators); + operators_[next_operator_id_] = tflite::CreateOperator( + *builder_, op, builder_->CreateVector(inputs.begin(), inputs.size()), + builder_->CreateVector(outputs.begin(), outputs.size()), + BuiltinOptions_NONE); + next_operator_id_++; + return next_operator_id_ - 1; +} + +void ModelBuilder::AddMetadata(const char *description_string, + const int32_t *metadata_buffer_data, + size_t num_elements) +{ + metadata_[ModelBuilder::nbr_of_metadata_buffers_] = + CreateMetadata(*builder_, builder_->CreateString(description_string), + 1 + ModelBuilder::nbr_of_metadata_buffers_); + + metadata_buffers_[nbr_of_metadata_buffers_] = tflite::CreateBuffer( + *builder_, builder_->CreateVector((uint8_t *)metadata_buffer_data, + sizeof(uint32_t) * num_elements)); + + ModelBuilder::nbr_of_metadata_buffers_++; +} + +const Model *ModelBuilder::BuildModel( + std::initializer_list inputs, + std::initializer_list outputs, + size_t num_subgraph_inputs) +{ + // Model schema requires an empty buffer at idx 0. + size_t buffer_size = 1 + ModelBuilder::nbr_of_metadata_buffers_; + flatbuffers::Offset buffers[kMaxMetadataBuffers]; + buffers[0] = tflite::CreateBuffer(*builder_); + + // Place the metadata buffers first in the buffer since the indices for them + // have already been set in AddMetadata() + for (int i = 1; i < ModelBuilder::nbr_of_metadata_buffers_ + 1; ++i) { + buffers[i] = metadata_buffers_[i - 1]; + } + + // Default to single subgraph model. + constexpr size_t subgraphs_size = 1; + + // Find out number of subgraph inputs. + if (num_subgraph_inputs == 0) { + // This is the default case. + num_subgraph_inputs = inputs.size(); + } else { + // A non-zero value of num_subgraph_inputs means that some of + // the operator input tensors are not subgraph inputs. + TFLITE_DCHECK(num_subgraph_inputs <= inputs.size()); + } + + const flatbuffers::Offset subgraphs[subgraphs_size] = { + tflite::CreateSubGraph( + *builder_, builder_->CreateVector(tensors_, next_tensor_id_), + builder_->CreateVector(inputs.begin(), num_subgraph_inputs), + builder_->CreateVector(outputs.begin(), outputs.size()), + builder_->CreateVector(operators_, next_operator_id_), + builder_->CreateString("test_subgraph")) + }; + + flatbuffers::Offset model_offset; + if (ModelBuilder::nbr_of_metadata_buffers_ > 0) { + model_offset = tflite::CreateModel( + *builder_, 0, + builder_->CreateVector(operator_codes_, next_operator_code_id_), + builder_->CreateVector(subgraphs, subgraphs_size), + builder_->CreateString("teset_model"), + builder_->CreateVector(buffers, buffer_size), 0, + builder_->CreateVector(metadata_, + ModelBuilder::nbr_of_metadata_buffers_)); + } else { + model_offset = tflite::CreateModel( + *builder_, 0, + builder_->CreateVector(operator_codes_, next_operator_code_id_), + builder_->CreateVector(subgraphs, subgraphs_size), + builder_->CreateString("teset_model"), + builder_->CreateVector(buffers, buffer_size)); + } + + tflite::FinishModelBuffer(*builder_, model_offset); + void *model_pointer = builder_->GetBufferPointer(); + const Model *model = flatbuffers::GetRoot(model_pointer); + return model; +} + +ModelBuilder::Tensor ModelBuilder::AddTensorImpl( + TensorType type, bool is_variable, std::initializer_list shape) +{ + TFLITE_DCHECK(next_tensor_id_ <= kMaxTensors); + tensors_[next_tensor_id_] = tflite::CreateTensor( + *builder_, builder_->CreateVector(shape.begin(), shape.size()), type, + /* buffer */ 0, /* name */ 0, /* quantization */ 0, + /* is_variable */ is_variable, + /* sparsity */ 0); + next_tensor_id_++; + return next_tensor_id_ - 1; +} + +const Model *BuildSimpleStatefulModel() +{ + using flatbuffers::Offset; + flatbuffers::FlatBufferBuilder *fb_builder = BuilderInstance(); + + ModelBuilder model_builder(fb_builder); + + const int op_id = + model_builder.RegisterOp(BuiltinOperator_CUSTOM, "simple_stateful_op"); + const int input_tensor = model_builder.AddTensor(TensorType_UINT8, { 3 }); + const int median_tensor = model_builder.AddTensor(TensorType_UINT8, { 3 }); + const int invoke_count_tensor = + model_builder.AddTensor(TensorType_INT32, { 1 }); + + model_builder.AddNode(op_id, { input_tensor }, + { median_tensor, invoke_count_tensor }); + return model_builder.BuildModel({ input_tensor }, + { median_tensor, invoke_count_tensor }); +} + +const Model *BuildSimpleModelWithBranch() +{ + using flatbuffers::Offset; + flatbuffers::FlatBufferBuilder *fb_builder = BuilderInstance(); + + ModelBuilder model_builder(fb_builder); + /* Model structure + | t0 + +------| + | v + | +---------+ + | | n0 | + | | | + | +---------+ + v + + | + +---------+ | t1 + | n1 | | + | | | + +---------+ | + | | + t2 | v + | +---------+ + +-->| n2 | + | | + +-------|-+ + |t3 + v + */ + const int op_id = + model_builder.RegisterOp(BuiltinOperator_CUSTOM, "mock_custom"); + const int t0 = model_builder.AddTensor(TensorType_FLOAT32, { 2, 2, 3 }); + const int t1 = model_builder.AddTensor(TensorType_FLOAT32, { 2, 2, 3 }); + const int t2 = model_builder.AddTensor(TensorType_FLOAT32, { 2, 2, 3 }); + const int t3 = model_builder.AddTensor(TensorType_FLOAT32, { 2, 2, 3 }); + model_builder.AddNode(op_id, { t0 }, { t1 }); // n0 + model_builder.AddNode(op_id, { t0 }, { t2 }); // n1 + model_builder.AddNode(op_id, { t1, t2 }, { t3 }); // n2 + return model_builder.BuildModel({ t0 }, { t3 }); +} + +const Model *BuildModelWithOfflinePlanning(int number_of_tensors, + const int32_t *metadata_buffer, + NodeConnection *node_conn, + int num_conns, + int num_subgraph_inputs) +{ + using flatbuffers::Offset; + flatbuffers::FlatBufferBuilder *fb_builder = BuilderInstance(); + + ModelBuilder model_builder(fb_builder); + + const int op_id = + model_builder.RegisterOp(BuiltinOperator_CUSTOM, "mock_custom"); + + for (int i = 0; i < number_of_tensors; ++i) { + model_builder.AddTensor(TensorType_FLOAT32, { 2, 2, 3 }); + } + + for (int i = 0; i < num_conns; ++i) { + model_builder.AddNode(op_id, node_conn[i].input, node_conn[i].output); + } + + model_builder.AddMetadata( + "OfflineMemoryAllocation", metadata_buffer, + number_of_tensors + tflite::testing::kOfflinePlannerHeaderSize); + + return model_builder.BuildModel( + node_conn[0].input, node_conn[num_conns - 1].output, num_subgraph_inputs); +} + +const Model *BuildModelWithUnusedInputs() +{ + using flatbuffers::Offset; + flatbuffers::FlatBufferBuilder *builder = BuilderInstance(); + + constexpr size_t buffers_size = 1; + const Offset buffers[buffers_size] = { CreateBuffer(*builder) }; + constexpr size_t tensor_shape_size = 2; + const int32_t tensor_shape[tensor_shape_size] = { 1, 64 }; + constexpr size_t tensors_size = 4; + const Offset tensors[tensors_size] = { + CreateTensor(*builder, + builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_INT8, 0, + builder->CreateString("test_input_tensor"), 0, false), + CreateTensor(*builder, + builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_INT8, 0, + builder->CreateString("test_unused_input_tensor"), 0, false), + CreateTensor(*builder, + builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_INT8, 0, + builder->CreateString("test_output_tensor"), 0, false), + CreateTensor(*builder, + builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_INT8, 0, + builder->CreateString("test_unused_tensor"), 0, false), + }; + constexpr size_t inputs_size = 2; + const int32_t inputs[inputs_size] = { 0, 1 }; + constexpr size_t outputs_size = 1; + const int32_t outputs[outputs_size] = { 2 }; + constexpr size_t operator_inputs_size = 1; + const int32_t operator_inputs[operator_inputs_size] = { 0 }; + constexpr size_t operator_outputs_size = 1; + const int32_t operator_outputs[operator_outputs_size] = { 2 }; + constexpr size_t operators_size = 1; + const Offset operators[operators_size] = { + CreateOperator( + *builder, 0, + builder->CreateVector(operator_inputs, operator_inputs_size), + builder->CreateVector(operator_outputs, operator_outputs_size), + BuiltinOptions_NONE), + }; + constexpr size_t subgraphs_size = 1; + const Offset subgraphs[subgraphs_size] = { + CreateSubGraph(*builder, builder->CreateVector(tensors, tensors_size), + builder->CreateVector(inputs, inputs_size), + builder->CreateVector(outputs, outputs_size), + builder->CreateVector(operators, operators_size), + builder->CreateString("test_subgraph")) + }; + constexpr size_t operator_codes_size = 1; + const Offset operator_codes[operator_codes_size] = { + CreateOperatorCodeDirect(*builder, /*deprecated_builtin_code=*/0, + "mock_custom", + /*version=*/0, BuiltinOperator_CUSTOM) + }; + const Offset model_offset = CreateModel( + *builder, 0, builder->CreateVector(operator_codes, operator_codes_size), + builder->CreateVector(subgraphs, subgraphs_size), + builder->CreateString("test_model"), + builder->CreateVector(buffers, buffers_size)); + FinishModelBuffer(*builder, model_offset); + void *model_pointer = builder->GetBufferPointer(); + const Model *model = flatbuffers::GetRoot(model_pointer); + return model; +} + +const Model *BuildSimpleMockModel() +{ + using flatbuffers::Offset; + flatbuffers::FlatBufferBuilder *builder = BuilderInstance(); + + constexpr size_t buffer_data_size = 1; + const uint8_t buffer_data[buffer_data_size] = { 21 }; + constexpr size_t buffers_size = 2; + const Offset buffers[buffers_size] = { + CreateBuffer(*builder), + CreateBuffer(*builder, + builder->CreateVector(buffer_data, buffer_data_size)) + }; + constexpr size_t tensor_shape_size = 1; + const int32_t tensor_shape[tensor_shape_size] = { 1 }; + constexpr size_t tensors_size = 4; + const Offset tensors[tensors_size] = { + CreateTensor(*builder, + builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_INT32, 0, + builder->CreateString("test_input_tensor"), 0, false), + CreateTensor(*builder, + builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_UINT8, 1, + builder->CreateString("test_weight_tensor"), 0, false), + CreateTensor(*builder, + builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_INT32, 0, + builder->CreateString("test_output_tensor"), 0, false), + CreateTensor(*builder, + builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_INT32, 0, + builder->CreateString("test_output2_tensor"), 0, false), + }; + constexpr size_t inputs_size = 1; + const int32_t inputs[inputs_size] = { 0 }; + constexpr size_t outputs_size = 2; + const int32_t outputs[outputs_size] = { 2, 3 }; + constexpr size_t operator_inputs_size = 2; + const int32_t operator_inputs[operator_inputs_size] = { 0, 1 }; + constexpr size_t operator_outputs_size = 1; + const int32_t operator_outputs[operator_outputs_size] = { 2 }; + const int32_t operator2_outputs[operator_outputs_size] = { 3 }; + constexpr size_t operators_size = 2; + const Offset operators[operators_size] = { + CreateOperator( + *builder, 0, + builder->CreateVector(operator_inputs, operator_inputs_size), + builder->CreateVector(operator_outputs, operator_outputs_size), + BuiltinOptions_NONE), + CreateOperator( + *builder, 0, + builder->CreateVector(operator_inputs, operator_inputs_size), + builder->CreateVector(operator2_outputs, operator_outputs_size), + BuiltinOptions_NONE), + }; + constexpr size_t subgraphs_size = 1; + const Offset subgraphs[subgraphs_size] = { + CreateSubGraph(*builder, builder->CreateVector(tensors, tensors_size), + builder->CreateVector(inputs, inputs_size), + builder->CreateVector(outputs, outputs_size), + builder->CreateVector(operators, operators_size), + builder->CreateString("test_subgraph")) + }; + constexpr size_t operator_codes_size = 1; + const Offset operator_codes[operator_codes_size] = { + CreateOperatorCodeDirect(*builder, /*deprecated_builtin_code=*/0, + "mock_custom", + /*version=*/0, BuiltinOperator_CUSTOM) + }; + const Offset model_offset = CreateModel( + *builder, 0, builder->CreateVector(operator_codes, operator_codes_size), + builder->CreateVector(subgraphs, subgraphs_size), + builder->CreateString("test_model"), + builder->CreateVector(buffers, buffers_size)); + FinishModelBuffer(*builder, model_offset); + void *model_pointer = builder->GetBufferPointer(); + const Model *model = flatbuffers::GetRoot(model_pointer); + return model; +} + +const Model *BuildComplexMockModel() +{ + using flatbuffers::Offset; + flatbuffers::FlatBufferBuilder *builder = BuilderInstance(); + + constexpr size_t buffer_data_size = 1; + const uint8_t buffer_data_1[buffer_data_size] = { 21 }; + const uint8_t buffer_data_2[buffer_data_size] = { 21 }; + const uint8_t buffer_data_3[buffer_data_size] = { 21 }; + constexpr size_t buffers_size = 7; + const Offset buffers[buffers_size] = { + // Op 1 buffers: + CreateBuffer(*builder), + CreateBuffer(*builder), + CreateBuffer(*builder, + builder->CreateVector(buffer_data_1, buffer_data_size)), + // Op 2 buffers: + CreateBuffer(*builder), + CreateBuffer(*builder, + builder->CreateVector(buffer_data_2, buffer_data_size)), + // Op 3 buffers: + CreateBuffer(*builder), + CreateBuffer(*builder, + builder->CreateVector(buffer_data_3, buffer_data_size)), + }; + constexpr size_t tensor_shape_size = 1; + const int32_t tensor_shape[tensor_shape_size] = { 1 }; + + constexpr size_t tensors_size = 10; + const Offset tensors[tensors_size] = { + // Op 1 inputs: + CreateTensor( + *builder, builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_INT32, 0, builder->CreateString("test_input_tensor_1"), 0, + false /* is_variable */), + CreateTensor( + *builder, builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_INT32, 1, builder->CreateString("test_variable_tensor_1"), + 0, true /* is_variable */), + CreateTensor( + *builder, builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_UINT8, 2, builder->CreateString("test_weight_tensor_1"), 0, + false /* is_variable */), + // Op 1 output / Op 2 input: + CreateTensor( + *builder, builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_INT32, 0, builder->CreateString("test_output_tensor_1"), 0, + false /* is_variable */), + // Op 2 inputs: + CreateTensor( + *builder, builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_INT32, 1, builder->CreateString("test_variable_tensor_2"), + 0, true /* is_variable */), + CreateTensor( + *builder, builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_UINT8, 2, builder->CreateString("test_weight_tensor_2"), 0, + false /* is_variable */), + // Op 2 output / Op 3 input: + CreateTensor( + *builder, builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_INT32, 0, builder->CreateString("test_output_tensor_2"), 0, + false /* is_variable */), + // Op 3 inputs: + CreateTensor( + *builder, builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_INT32, 1, builder->CreateString("test_variable_tensor_3"), + 0, true /* is_variable */), + CreateTensor( + *builder, builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_UINT8, 2, builder->CreateString("test_weight_tensor_3"), 0, + false /* is_variable */), + // Op 3 output: + CreateTensor( + *builder, builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_INT32, 0, builder->CreateString("test_output_tensor_3"), 0, + false /* is_variable */), + }; + + constexpr size_t operators_size = 3; + Offset operators[operators_size]; + { + // Set Op 1 attributes: + constexpr size_t operator_inputs_size = 3; + const int32_t operator_inputs[operator_inputs_size] = { 0, 1, 2 }; + constexpr size_t operator_outputs_size = 1; + const int32_t operator_outputs[operator_outputs_size] = { 3 }; + + operators[0] = { CreateOperator( + *builder, 0, + builder->CreateVector(operator_inputs, operator_inputs_size), + builder->CreateVector(operator_outputs, operator_outputs_size), + BuiltinOptions_NONE) }; + } + + { + // Set Op 2 attributes + constexpr size_t operator_inputs_size = 3; + const int32_t operator_inputs[operator_inputs_size] = { 3, 4, 5 }; + constexpr size_t operator_outputs_size = 1; + const int32_t operator_outputs[operator_outputs_size] = { 6 }; + + operators[1] = { CreateOperator( + *builder, 0, + builder->CreateVector(operator_inputs, operator_inputs_size), + builder->CreateVector(operator_outputs, operator_outputs_size), + BuiltinOptions_NONE) }; + } + + { + // Set Op 3 attributes + constexpr size_t operator_inputs_size = 3; + const int32_t operator_inputs[operator_inputs_size] = { 6, 7, 8 }; + constexpr size_t operator_outputs_size = 1; + const int32_t operator_outputs[operator_outputs_size] = { 9 }; + + operators[2] = { CreateOperator( + *builder, 0, + builder->CreateVector(operator_inputs, operator_inputs_size), + builder->CreateVector(operator_outputs, operator_outputs_size), + BuiltinOptions_NONE) }; + } + + constexpr size_t inputs_size = 1; + const int32_t inputs[inputs_size] = { 0 }; + constexpr size_t outputs_size = 1; + const int32_t outputs[outputs_size] = { 9 }; + + constexpr size_t subgraphs_size = 1; + const Offset subgraphs[subgraphs_size] = { + CreateSubGraph(*builder, builder->CreateVector(tensors, tensors_size), + builder->CreateVector(inputs, inputs_size), + builder->CreateVector(outputs, outputs_size), + builder->CreateVector(operators, operators_size), + builder->CreateString("test_subgraph")) + }; + + constexpr size_t operator_codes_size = 1; + const Offset operator_codes[operator_codes_size] = { + CreateOperatorCodeDirect(*builder, /*deprecated_builtin_code=*/0, + "mock_custom", + /*version=*/0, BuiltinOperator_CUSTOM) + }; + + const Offset model_offset = CreateModel( + *builder, 0, builder->CreateVector(operator_codes, operator_codes_size), + builder->CreateVector(subgraphs, subgraphs_size), + builder->CreateString("test_model"), + builder->CreateVector(buffers, buffers_size)); + + FinishModelBuffer(*builder, model_offset); + void *model_pointer = builder->GetBufferPointer(); + const Model *model = flatbuffers::GetRoot(model_pointer); + return model; +} + +const Model *BuildSimpleMultipleInputsModel() +{ + using flatbuffers::Offset; + flatbuffers::FlatBufferBuilder *builder = BuilderInstance(); + + constexpr size_t buffers_size = 1; + const Offset buffers[buffers_size] = { + CreateBuffer(*builder), + }; + constexpr size_t tensor_shape_size = 1; + const int32_t tensor_shape[tensor_shape_size] = { 1 }; + constexpr size_t tensors_size = 4; + const Offset tensors[tensors_size] = { + CreateTensor(*builder, + builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_INT32, 0, + builder->CreateString("test_input_tensor1"), 0, false), + CreateTensor(*builder, + builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_INT8, 0, + builder->CreateString("test_input_tensor2"), 0, false), + CreateTensor(*builder, + builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_INT32, 0, + builder->CreateString("test_input_tensor3"), 0, false), + CreateTensor(*builder, + builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_INT32, 0, + builder->CreateString("test_output_tensor"), 0, false), + }; + constexpr size_t inputs_size = 3; + const int32_t inputs[inputs_size] = { 0, 1, 2 }; + constexpr size_t outputs_size = 1; + const int32_t outputs[outputs_size] = { 3 }; + constexpr size_t operator_inputs_size = 3; + const int32_t operator_inputs[operator_inputs_size] = { 0, 1, 2 }; + constexpr size_t operator_outputs_size = 1; + const int32_t operator_outputs[operator_outputs_size] = { 3 }; + constexpr size_t operators_size = 1; + const Offset operators[operators_size] = { + CreateOperator( + *builder, 0, + builder->CreateVector(operator_inputs, operator_inputs_size), + builder->CreateVector(operator_outputs, operator_outputs_size), + BuiltinOptions_NONE), + }; + constexpr size_t subgraphs_size = 1; + const Offset subgraphs[subgraphs_size] = { + CreateSubGraph(*builder, builder->CreateVector(tensors, tensors_size), + builder->CreateVector(inputs, inputs_size), + builder->CreateVector(outputs, outputs_size), + builder->CreateVector(operators, operators_size), + builder->CreateString("test_subgraph")) + }; + constexpr size_t operator_codes_size = 1; + const Offset operator_codes[operator_codes_size] = { + CreateOperatorCodeDirect(*builder, /*deprecated_builtin_code=*/0, + "multiple_inputs_op", + /*version=*/0, BuiltinOperator_CUSTOM) + }; + const Offset model_offset = CreateModel( + *builder, 0, builder->CreateVector(operator_codes, operator_codes_size), + builder->CreateVector(subgraphs, subgraphs_size), + builder->CreateString("test_model"), + builder->CreateVector(buffers, buffers_size)); + FinishModelBuffer(*builder, model_offset); + void *model_pointer = builder->GetBufferPointer(); + const Model *model = flatbuffers::GetRoot(model_pointer); + return model; +} + +const Model *BuildSimpleModelWithSubgraphsAndIf() +{ + using flatbuffers::Offset; + flatbuffers::FlatBufferBuilder *builder = BuilderInstance(); + + constexpr size_t buffers_size = 1; + const Offset buffers[buffers_size] = { + CreateBuffer(*builder), + }; + const int32_t condition_tensor_shape[] = { 1 }; + const int32_t data_tensor_shape[] = { 1, 2 }; + constexpr size_t tensors_size = 4; + const Offset subgraph1_tensors[tensors_size] = { + CreateTensor(*builder, builder->CreateVector(condition_tensor_shape, 1), + TensorType_BOOL, 0, + builder->CreateString("condition tensor"), 0, false), + CreateTensor(*builder, builder->CreateVector(data_tensor_shape, 2), + TensorType_FLOAT32, 0, + builder->CreateString("input_tensor1"), 0, false), + CreateTensor(*builder, builder->CreateVector(data_tensor_shape, 2), + TensorType_FLOAT32, 0, + builder->CreateString("input_tensor2"), 0, false), + CreateTensor(*builder, builder->CreateVector(data_tensor_shape, 2), + TensorType_FLOAT32, 0, + builder->CreateString("output_tensor"), 0, false), + }; + const Offset subgraph2_tensors[tensors_size] = { + CreateTensor(*builder, builder->CreateVector(data_tensor_shape, 2), + TensorType_FLOAT32, 0, + builder->CreateString("input_tensor1"), 0, false), + CreateTensor(*builder, builder->CreateVector(data_tensor_shape, 2), + TensorType_FLOAT32, 0, + builder->CreateString("input_tensor2"), 0, false), + CreateTensor(*builder, builder->CreateVector(data_tensor_shape, 2), + TensorType_FLOAT32, 0, + builder->CreateString("output_tensor"), 0, false), + }; + const Offset subgraph3_tensors[tensors_size] = { + CreateTensor(*builder, builder->CreateVector(data_tensor_shape, 2), + TensorType_FLOAT32, 0, + builder->CreateString("input_tensor1"), 0, false), + CreateTensor(*builder, builder->CreateVector(data_tensor_shape, 2), + TensorType_FLOAT32, 0, + builder->CreateString("input_tensor2"), 0, false), + CreateTensor(*builder, builder->CreateVector(data_tensor_shape, 2), + TensorType_FLOAT32, 0, + builder->CreateString("output_tensor"), 0, false), + }; + + constexpr size_t if_inputs_size = 3; + const int32_t if_inputs[if_inputs_size] = { 0, 1, 2 }; + constexpr size_t outputs_size = 1; + const int32_t if_outputs[outputs_size] = { 3 }; + constexpr size_t operator_inputs_size = 2; + const int32_t operator_inputs[operator_inputs_size] = { 0, 1 }; + const int32_t operator_outputs[outputs_size] = { 2 }; + constexpr size_t operators_size = 1; + const Offset subgraph1_operators[operators_size] = { + CreateOperator( + *builder, 0, builder->CreateVector(if_inputs, if_inputs_size), + builder->CreateVector(if_outputs, outputs_size), + BuiltinOptions_IfOptions, CreateIfOptions(*builder, 1, 2).Union()), + }; + const Offset subgraph2_operators[operators_size] = { + CreateOperator( + *builder, 1, + builder->CreateVector(operator_inputs, operator_inputs_size), + builder->CreateVector(operator_outputs, outputs_size), + BuiltinOptions_NONE), + }; + const Offset subgraph3_operators[operators_size] = { + CreateOperator( + *builder, 2, + builder->CreateVector(operator_inputs, operator_inputs_size), + builder->CreateVector(operator_outputs, outputs_size), + BuiltinOptions_NONE), + }; + constexpr size_t subgraphs_size = 3; + const Offset subgraphs[subgraphs_size] = { + CreateSubGraph(*builder, builder->CreateVector(subgraph1_tensors, 4), + builder->CreateVector(if_inputs, if_inputs_size), + builder->CreateVector(if_outputs, outputs_size), + builder->CreateVector(subgraph1_operators, operators_size), + builder->CreateString("if_subgraph")), + CreateSubGraph( + *builder, builder->CreateVector(subgraph2_tensors, 3), + builder->CreateVector(operator_inputs, operator_inputs_size), + builder->CreateVector(operator_outputs, outputs_size), + builder->CreateVector(subgraph2_operators, operators_size), + builder->CreateString("then_subgraph")), + CreateSubGraph( + *builder, builder->CreateVector(subgraph3_tensors, 3), + builder->CreateVector(operator_inputs, operator_inputs_size), + builder->CreateVector(operator_outputs, outputs_size), + builder->CreateVector(subgraph3_operators, operators_size), + builder->CreateString("else_subgraph")), + }; + constexpr size_t operator_codes_size = 3; + const Offset operator_codes[operator_codes_size] = { + CreateOperatorCodeDirect(*builder, /*deprecated_builtin_code=*/0, + "multiple_inputs_op", + /*version=*/0, BuiltinOperator_IF), + CreateOperatorCodeDirect(*builder, /*deprecated_builtin_code=*/0, + "multiple_inputs_op", + /*version=*/0, BuiltinOperator_ADD), + CreateOperatorCodeDirect(*builder, /*deprecated_builtin_code=*/0, + "multiple_inputs_op", + /*version=*/0, BuiltinOperator_MUL), + }; + const Offset model_offset = CreateModel( + *builder, 0, builder->CreateVector(operator_codes, operator_codes_size), + builder->CreateVector(subgraphs, subgraphs_size), + builder->CreateString("test_model"), + builder->CreateVector(buffers, buffers_size)); + FinishModelBuffer(*builder, model_offset); + void *model_pointer = builder->GetBufferPointer(); + const Model *model = flatbuffers::GetRoot(model_pointer); + return model; +} + +} // namespace + +const TfLiteRegistration *SimpleStatefulOp::getRegistration() +{ + return GetMutableRegistration(); +} + +TfLiteRegistration *SimpleStatefulOp::GetMutableRegistration() +{ + static TfLiteRegistration r; + r.init = Init; + r.prepare = Prepare; + r.invoke = Invoke; + return &r; +} + +void *SimpleStatefulOp::Init(TfLiteContext *context, const char *buffer, + size_t length) +{ + TFLITE_DCHECK(context->AllocateBufferForEval == nullptr); + TFLITE_DCHECK(context->GetScratchBuffer == nullptr); + TFLITE_DCHECK(context->RequestScratchBufferInArena == nullptr); + + void *raw = context->AllocatePersistentBuffer(context, sizeof(OpData)); + OpData *data = reinterpret_cast(raw); + *data = {}; + return raw; +} + +TfLiteStatus SimpleStatefulOp::Prepare(TfLiteContext *context, + TfLiteNode *node) +{ + OpData *data = reinterpret_cast(node->user_data); + + // Make sure that the input is in uint8_t with at least 1 data entry. + const TfLiteTensor *input; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, kInputTensor, &input)); + if (input->type != kTfLiteUInt8) + return kTfLiteError; + if (NumElements(input->dims) == 0) + return kTfLiteError; + + // Allocate a temporary buffer with the same size of input for sorting. + TF_LITE_ENSURE_STATUS(context->RequestScratchBufferInArena( + context, sizeof(uint8_t) * NumElements(input->dims), + &data->sorting_buffer)); + // We can interleave scratch / persistent buffer allocation. + data->invoke_count = reinterpret_cast( + context->AllocatePersistentBuffer(context, sizeof(int))); + *data->invoke_count = 0; + + return kTfLiteOk; +} + +TfLiteStatus SimpleStatefulOp::Invoke(TfLiteContext *context, + TfLiteNode *node) +{ + OpData *data = reinterpret_cast(node->user_data); + *data->invoke_count += 1; + + const TfLiteTensor *input; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, kInputTensor, &input)); + const uint8_t *input_data = GetTensorData(input); + int size = NumElements(input->dims); + + uint8_t *sorting_buffer = reinterpret_cast( + context->GetScratchBuffer(context, data->sorting_buffer)); + // Copy inputs data to the sorting buffer. We don't want to mutate the input + // tensor as it might be used by a another node. + for (int i = 0; i < size; i++) { + sorting_buffer[i] = input_data[i]; + } + + // In place insertion sort on `sorting_buffer`. + for (int i = 1; i < size; i++) { + for (int j = i; j > 0 && sorting_buffer[j] < sorting_buffer[j - 1]; j--) { + std::swap(sorting_buffer[j], sorting_buffer[j - 1]); + } + } + + TfLiteTensor *median; + TF_LITE_ENSURE_OK(context, + GetOutputSafe(context, node, kMedianTensor, &median)); + uint8_t *median_data = GetTensorData(median); + TfLiteTensor *invoke_count; + TF_LITE_ENSURE_OK(context, + GetOutputSafe(context, node, kInvokeCount, &invoke_count)); + int32_t *invoke_count_data = GetTensorData(invoke_count); + + median_data[0] = sorting_buffer[size / 2]; + invoke_count_data[0] = *data->invoke_count; + return kTfLiteOk; +} + +const TfLiteRegistration *MockCustom::getRegistration() +{ + return GetMutableRegistration(); +} + +TfLiteRegistration *MockCustom::GetMutableRegistration() +{ + static TfLiteRegistration r; + r.init = Init; + r.prepare = Prepare; + r.invoke = Invoke; + r.free = Free; + return &r; +} + +void *MockCustom::Init(TfLiteContext *context, const char *buffer, + size_t length) +{ + // We don't support delegate in TFL micro. This is a weak check to test if + // context struct being zero-initialized. + TFLITE_DCHECK(context->ReplaceNodeSubsetsWithDelegateKernels == nullptr); + freed_ = false; + // Do nothing. + return nullptr; +} + +void MockCustom::Free(TfLiteContext *context, void *buffer) +{ + freed_ = true; +} + +TfLiteStatus MockCustom::Prepare(TfLiteContext *context, TfLiteNode *node) +{ + return kTfLiteOk; +} + +TfLiteStatus MockCustom::Invoke(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteTensor *input; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, 0, &input)); + const int32_t *input_data = input->data.i32; + const TfLiteTensor *weight; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, 1, &weight)); + const uint8_t *weight_data = weight->data.uint8; + TfLiteTensor *output; + TF_LITE_ENSURE_OK(context, GetOutputSafe(context, node, 0, &output)); + int32_t *output_data = output->data.i32; + output_data[0] = + 0; // Catch output tensor sharing memory with an input tensor + output_data[0] = input_data[0] + weight_data[0]; + return kTfLiteOk; +} + +bool MockCustom::freed_ = false; + +const TfLiteRegistration *MultipleInputs::getRegistration() +{ + return GetMutableRegistration(); +} + +TfLiteRegistration *MultipleInputs::GetMutableRegistration() +{ + static TfLiteRegistration r; + r.init = Init; + r.prepare = Prepare; + r.invoke = Invoke; + r.free = Free; + return &r; +} + +void *MultipleInputs::Init(TfLiteContext *context, const char *buffer, + size_t length) +{ + // We don't support delegate in TFL micro. This is a weak check to test if + // context struct being zero-initialized. + TFLITE_DCHECK(context->ReplaceNodeSubsetsWithDelegateKernels == nullptr); + freed_ = false; + // Do nothing. + return nullptr; +} + +void MultipleInputs::Free(TfLiteContext *context, void *buffer) +{ + freed_ = true; +} + +TfLiteStatus MultipleInputs::Prepare(TfLiteContext *context, TfLiteNode *node) +{ + return kTfLiteOk; +} + +TfLiteStatus MultipleInputs::Invoke(TfLiteContext *context, TfLiteNode *node) +{ + const TfLiteTensor *input; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, 0, &input)); + const int32_t *input_data = input->data.i32; + const TfLiteTensor *input1; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, 1, &input1)); + const int32_t *input_data1 = input1->data.i32; + const TfLiteTensor *input2; + TF_LITE_ENSURE_OK(context, GetInputSafe(context, node, 2, &input2)); + const int32_t *input_data2 = input2->data.i32; + + TfLiteTensor *output; + TF_LITE_ENSURE_OK(context, GetOutputSafe(context, node, 0, &output)); + int32_t *output_data = output->data.i32; + output_data[0] = + 0; // Catch output tensor sharing memory with an input tensor + output_data[0] = input_data[0] + input_data1[0] + input_data2[0]; + return kTfLiteOk; +} + +bool MultipleInputs::freed_ = false; + +AllOpsResolver GetOpResolver() +{ + AllOpsResolver op_resolver; + op_resolver.AddCustom("mock_custom", MockCustom::GetMutableRegistration()); + op_resolver.AddCustom("simple_stateful_op", + SimpleStatefulOp::GetMutableRegistration()); + op_resolver.AddCustom("multiple_inputs_op", + MultipleInputs::GetMutableRegistration()); + return op_resolver; +} +const Model *GetModelWithUnusedInputs() +{ + static Model *model = nullptr; + if (!model) { + model = const_cast(BuildModelWithUnusedInputs()); + } + return model; +} + +const Model *GetSimpleMockModel() +{ + static Model *model = nullptr; + if (!model) { + model = const_cast(BuildSimpleMockModel()); + } + return model; +} + +const Model *GetSimpleMultipleInputsModel() +{ + static Model *model = nullptr; + if (!model) { + model = const_cast(BuildSimpleMultipleInputsModel()); + } + return model; +} + +const Model *GetSimpleModelWithSubgraphsAndIf() +{ + static Model *model = nullptr; + if (!model) { + model = const_cast(BuildSimpleModelWithSubgraphsAndIf()); + } + return model; +} + +const Model *GetComplexMockModel() +{ + static Model *model = nullptr; + if (!model) { + model = const_cast(BuildComplexMockModel()); + } + return model; +} + +const Model *GetSimpleModelWithBranch() +{ + static Model *model = nullptr; + if (!model) { + model = const_cast(BuildSimpleModelWithBranch()); + } + return model; +} + +const Model *GetModelWithOfflinePlanning(int num_tensors, + const int32_t *metadata_buffer, + NodeConnection *node_conn, + int num_conns, + int num_subgraph_inputs) +{ + const Model *model = BuildModelWithOfflinePlanning( + num_tensors, metadata_buffer, node_conn, num_conns, num_subgraph_inputs); + return model; +} + +const Model *GetSimpleStatefulModel() +{ + static Model *model = nullptr; + if (!model) { + model = const_cast(BuildSimpleStatefulModel()); + } + return model; +} + +const Tensor *Create1dFlatbufferTensor(int size, bool is_variable) +{ + using flatbuffers::Offset; + flatbuffers::FlatBufferBuilder *builder = BuilderInstance(); + constexpr size_t tensor_shape_size = 1; + const int32_t tensor_shape[tensor_shape_size] = { size }; + const Offset tensor_offset = CreateTensor( + *builder, builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_INT32, 0, builder->CreateString("test_tensor"), 0, + is_variable); + builder->Finish(tensor_offset); + void *tensor_pointer = builder->GetBufferPointer(); + const Tensor *tensor = flatbuffers::GetRoot(tensor_pointer); + return tensor; +} + +const Tensor *CreateQuantizedFlatbufferTensor(int size) +{ + using flatbuffers::Offset; + flatbuffers::FlatBufferBuilder *builder = BuilderInstance(); + const Offset quant_params = + CreateQuantizationParameters( + *builder, + /*min=*/builder->CreateVector({ 0.1f }), + /*max=*/builder->CreateVector({ 0.2f }), + /*scale=*/builder->CreateVector({ 0.3f }), + /*zero_point=*/builder->CreateVector({ 100ll })); + + constexpr size_t tensor_shape_size = 1; + const int32_t tensor_shape[tensor_shape_size] = { size }; + const Offset tensor_offset = CreateTensor( + *builder, builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_INT32, 0, builder->CreateString("test_tensor"), quant_params, + false); + builder->Finish(tensor_offset); + void *tensor_pointer = builder->GetBufferPointer(); + const Tensor *tensor = flatbuffers::GetRoot(tensor_pointer); + return tensor; +} + +const Tensor *CreateMissingQuantizationFlatbufferTensor(int size) +{ + using flatbuffers::Offset; + flatbuffers::FlatBufferBuilder *builder = BuilderInstance(); + const Offset quant_params = + CreateQuantizationParameters(*builder, 0, 0, 0, 0, + QuantizationDetails_NONE, 0, 0); + constexpr size_t tensor_shape_size = 1; + const int32_t tensor_shape[tensor_shape_size] = { size }; + const Offset tensor_offset = CreateTensor( + *builder, builder->CreateVector(tensor_shape, tensor_shape_size), + TensorType_INT32, 0, builder->CreateString("test_tensor"), quant_params, + false); + builder->Finish(tensor_offset); + void *tensor_pointer = builder->GetBufferPointer(); + const Tensor *tensor = flatbuffers::GetRoot(tensor_pointer); + return tensor; +} + +const flatbuffers::Vector > * +CreateFlatbufferBuffers() +{ + using flatbuffers::Offset; + flatbuffers::FlatBufferBuilder *builder = BuilderInstance(); + constexpr size_t buffers_size = 1; + const Offset buffers[buffers_size] = { + CreateBuffer(*builder), + }; + const flatbuffers::Offset > > + buffers_offset = builder->CreateVector(buffers, buffers_size); + builder->Finish(buffers_offset); + void *buffers_pointer = builder->GetBufferPointer(); + const flatbuffers::Vector > *result = + flatbuffers::GetRoot > >( + buffers_pointer); + return result; +} + +int TestStrcmp(const char *a, const char *b) +{ + if ((a == nullptr) || (b == nullptr)) { + return -1; + } + while ((*a != 0) && (*a == *b)) { + a++; + b++; + } + return *reinterpret_cast(a) - + *reinterpret_cast(b); +} + +// Wrapper to forward kernel errors to the interpreter's error reporter. +void ReportOpError(struct TfLiteContext *context, const char *format, ...) +{ +#ifndef TF_LITE_STRIP_ERROR_STRINGS + ErrorReporter *error_reporter = static_cast(context->impl_); + va_list args; + va_start(args, format); + TF_LITE_REPORT_ERROR(error_reporter, format, args); + va_end(args); +#endif +} + +// Create a TfLiteIntArray from an array of ints. The first element in the +// supplied array must be the size of the array expressed as an int. +TfLiteIntArray *IntArrayFromInts(int *int_array) +{ + return reinterpret_cast(int_array); +} + +// Create a TfLiteFloatArray from an array of floats. The first element in the +// supplied array must be the size of the array expressed as a float. +TfLiteFloatArray *FloatArrayFromFloats(const float *floats) +{ + static_assert(sizeof(float) == sizeof(int), + "assumes sizeof(float) == sizeof(int) to perform casting"); + int size = static_cast(floats[0]); + *reinterpret_cast(const_cast(floats)) = size; + return reinterpret_cast(const_cast(floats)); +} + +TfLiteTensor CreateQuantizedBiasTensor(const float *data, int32_t *quantized, + TfLiteIntArray *dims, float input_scale, + float weights_scale, bool is_variable) +{ + float bias_scale = input_scale * weights_scale; + tflite::SymmetricQuantize(data, quantized, ElementCount(*dims), bias_scale); + + // Quantized int32_t tensors always have a zero point of 0, since the range of + // int32_t values is large, and because zero point costs extra cycles during + // processing. + TfLiteTensor result = + CreateQuantizedTensor(quantized, dims, bias_scale, 0, is_variable); + return result; +} + +TfLiteTensor CreateQuantizedBiasTensor(const float *data, + std::int64_t *quantized, + TfLiteIntArray *dims, float input_scale, + float weights_scale, bool is_variable) +{ + float bias_scale = input_scale * weights_scale; + tflite::SymmetricQuantize(data, quantized, ElementCount(*dims), bias_scale); + + // Quantized int32_t tensors always have a zero point of 0, since the range of + // int32_t values is large, and because zero point costs extra cycles during + // processing. + TfLiteTensor result = + CreateQuantizedTensor(quantized, dims, bias_scale, 0, is_variable); + return result; +} + +// Quantizes int32_t bias tensor with per-channel weights determined by input +// scale multiplied by weight scale for each channel. +template +TfLiteTensor CreatePerChannelQuantizedBiasTensor( + const float *input, T *quantized, TfLiteIntArray *dims, float input_scale, + float *weight_scales, float *scales, int *zero_points, + TfLiteAffineQuantization *affine_quant, int quantized_dimension, + bool is_variable) +{ + int input_size = ElementCount(*dims); + int num_channels = dims->data[quantized_dimension]; + // First element is reserved for array length + zero_points[0] = num_channels; + scales[0] = static_cast(num_channels); + float *scales_array = &scales[1]; + for (int i = 0; i < num_channels; i++) { + scales_array[i] = input_scale * weight_scales[i]; + zero_points[i + 1] = 0; + } + + SymmetricPerChannelQuantize(input, quantized, input_size, num_channels, + scales_array); + + affine_quant->scale = FloatArrayFromFloats(scales); + affine_quant->zero_point = IntArrayFromInts(zero_points); + affine_quant->quantized_dimension = quantized_dimension; + + TfLiteTensor result = CreateTensor(quantized, dims, is_variable); + result.quantization = { kTfLiteAffineQuantization, affine_quant }; + return result; +} + +TfLiteTensor CreatePerChannelQuantizedBiasTensor( + const float *input, int32_t *quantized, TfLiteIntArray *dims, + float input_scale, float *weight_scales, float *scales, int *zero_points, + TfLiteAffineQuantization *affine_quant, int quantized_dimension, + bool is_variable) +{ + return CreatePerChannelQuantizedBiasTensor( + input, quantized, dims, input_scale, weight_scales, scales, zero_points, + affine_quant, quantized_dimension, is_variable); +} + +TfLiteTensor CreatePerChannelQuantizedBiasTensor( + const float *input, std::int64_t *quantized, TfLiteIntArray *dims, + float input_scale, float *weight_scales, float *scales, int *zero_points, + TfLiteAffineQuantization *affine_quant, int quantized_dimension, + bool is_variable) +{ + return CreatePerChannelQuantizedBiasTensor( + input, quantized, dims, input_scale, weight_scales, scales, zero_points, + affine_quant, quantized_dimension, is_variable); +} + +TfLiteTensor CreateSymmetricPerChannelQuantizedTensor( + const float *input, int8_t *quantized, TfLiteIntArray *dims, float *scales, + int *zero_points, TfLiteAffineQuantization *affine_quant, + int quantized_dimension, bool is_variable) +{ + int channel_count = dims->data[quantized_dimension]; + scales[0] = static_cast(channel_count); + zero_points[0] = channel_count; + + SignedSymmetricPerChannelQuantize(input, dims, quantized_dimension, quantized, + &scales[1]); + + for (int i = 0; i < channel_count; i++) { + zero_points[i + 1] = 0; + } + + affine_quant->scale = FloatArrayFromFloats(scales); + affine_quant->zero_point = IntArrayFromInts(zero_points); + affine_quant->quantized_dimension = quantized_dimension; + + TfLiteTensor result = CreateTensor(quantized, dims, is_variable); + result.quantization = { kTfLiteAffineQuantization, affine_quant }; + return result; +} + +size_t GetModelTensorCount(const Model *model) +{ + auto *subgraphs = model->subgraphs(); + if (subgraphs) { + return (*subgraphs)[0]->tensors()->size(); + } + return 0; +} + +} // namespace testing +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/micro/test_helpers.h b/components/tflite/tensorflow/lite/micro/test_helpers.h new file mode 100644 index 00000000..eda966bd --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/test_helpers.h @@ -0,0 +1,266 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_TEST_HELPERS_H_ +#define TENSORFLOW_LITE_MICRO_TEST_HELPERS_H_ + +// Useful functions for writing tests. + +#include +#include + +#include "flatbuffers/flatbuffers.h" // from @flatbuffers +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/compatibility.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/micro_utils.h" +#include "tensorflow/lite/portable_type_to_tflitetype.h" +#include "tensorflow/lite/schema/schema_generated.h" + +namespace tflite { +namespace testing { +constexpr int kOfflinePlannerHeaderSize = 3; + +struct NodeConnection_ { + std::initializer_list input; + std::initializer_list output; +}; +typedef struct NodeConnection_ NodeConnection; + +// A simple operator that returns the median of the input with the number of +// times the kernel was invoked. The implementation below is deliberately +// complicated, just to demonstrate how kernel memory planning works. +class SimpleStatefulOp { + static constexpr int kBufferNotAllocated = 0; + // Inputs: + static constexpr int kInputTensor = 0; + // Outputs: + static constexpr int kMedianTensor = 0; + static constexpr int kInvokeCount = 1; + struct OpData { + int *invoke_count = nullptr; + int sorting_buffer = kBufferNotAllocated; + }; + +public: + static const TfLiteRegistration *getRegistration(); + static TfLiteRegistration *GetMutableRegistration(); + static void *Init(TfLiteContext *context, const char *buffer, size_t length); + static TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node); + static TfLiteStatus Invoke(TfLiteContext *context, TfLiteNode *node); +}; + +class MockCustom { +public: + static const TfLiteRegistration *getRegistration(); + static TfLiteRegistration *GetMutableRegistration(); + static void *Init(TfLiteContext *context, const char *buffer, size_t length); + static void Free(TfLiteContext *context, void *buffer); + static TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node); + static TfLiteStatus Invoke(TfLiteContext *context, TfLiteNode *node); + + static bool freed_; +}; + +// A simple operator with the purpose of testing multiple inputs. It returns +// the sum of the inputs. +class MultipleInputs { +public: + static const TfLiteRegistration *getRegistration(); + static TfLiteRegistration *GetMutableRegistration(); + static void *Init(TfLiteContext *context, const char *buffer, size_t length); + static void Free(TfLiteContext *context, void *buffer); + static TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node); + static TfLiteStatus Invoke(TfLiteContext *context, TfLiteNode *node); + + static bool freed_; +}; + +// Returns an Op Resolver that can be used in the testing code. +AllOpsResolver GetOpResolver(); + +// Returns a simple example flatbuffer TensorFlow Lite model. Contains 1 input, +// 1 layer of weights, 1 output Tensor, and 1 operator. +const Model *GetSimpleMockModel(); + +// Returns a flatbuffer TensorFlow Lite model with more inputs, variable +// tensors, and operators. +const Model *GetComplexMockModel(); + +// Returns a simple flatbuffer model with two branches. +const Model *GetSimpleModelWithBranch(); + +// Returns a simple example flatbuffer TensorFlow Lite model. Contains 3 inputs, +// 1 output Tensor, and 1 operator. +const Model *GetSimpleMultipleInputsModel(); + +// Returns a simple flatbuffer model with offline planned tensors +// @param[in] num_tensors Number of tensors in the model. +// @param[in] metadata_buffer Metadata for offline planner. +// @param[in] node_con List of connections, i.e. operators +// in the model. +// @param[in] num_conns Number of connections. +// @param[in] num_subgraph_inputs How many of the input tensors are in +// the subgraph inputs. The default value +// of 0 means all of the input tensors +// are in the subgraph input list. There +// must be at least 1 input tensor in the +// subgraph input list. +const Model *GetModelWithOfflinePlanning(int num_tensors, + const int32_t *metadata_buffer, + NodeConnection *node_conn, + int num_conns, + int num_subgraph_inputs = 0); + +// Returns a flatbuffer with a single operator, two inputs (one unused) and one +// output. +const Model *GetModelWithUnusedInputs(); + +// Returns a flatbuffer model with `simple_stateful_op` +const Model *GetSimpleStatefulModel(); + +// Returns a flatbuffer model with "if" and two subgraphs. +const Model *GetSimpleModelWithSubgraphsAndIf(); + +// Builds a one-dimensional flatbuffer tensor of the given size. +const Tensor *Create1dFlatbufferTensor(int size, bool is_variable = false); + +// Builds a one-dimensional flatbuffer tensor of the given size with +// quantization metadata. +const Tensor *CreateQuantizedFlatbufferTensor(int size); + +// Creates a one-dimensional tensor with no quantization metadata. +const Tensor *CreateMissingQuantizationFlatbufferTensor(int size); + +// Creates a vector of flatbuffer buffers. +const flatbuffers::Vector > * +CreateFlatbufferBuffers(); + +// Performs a simple string comparison without requiring standard C library. +int TestStrcmp(const char *a, const char *b); + +// Wrapper to forward kernel errors to the interpreter's error reporter. +void ReportOpError(struct TfLiteContext *context, const char *format, ...); + +void PopulateContext(TfLiteTensor *tensors, int tensors_size, + TfLiteContext *context); + +// Create a TfLiteIntArray from an array of ints. The first element in the +// supplied array must be the size of the array expressed as an int. +TfLiteIntArray *IntArrayFromInts(int *int_array); + +// Create a TfLiteFloatArray from an array of floats. The first element in the +// supplied array must be the size of the array expressed as a float. +TfLiteFloatArray *FloatArrayFromFloats(const float *floats); + +template +TfLiteTensor CreateTensor(const T *data, TfLiteIntArray *dims, + const bool is_variable = false) +{ + TfLiteTensor result; + result.dims = dims; + result.params = {}; + result.quantization = { kTfLiteNoQuantization, nullptr }; + result.is_variable = is_variable; + result.allocation_type = kTfLiteMemNone; + result.type = typeToTfLiteType(); + // Const cast is used to allow passing in const and non-const arrays within a + // single CreateTensor method. A Const array should be used for immutable + // input tensors and non-const array should be used for mutable and output + // tensors. + result.data.data = const_cast(data); + result.quantization = { kTfLiteAffineQuantization, nullptr }; + result.bytes = ElementCount(*dims) * sizeof(T); + return result; +} + +template +TfLiteTensor CreateQuantizedTensor(const T *data, TfLiteIntArray *dims, + const float scale, const int zero_point = 0, + const bool is_variable = false) +{ + TfLiteTensor result = CreateTensor(data, dims, is_variable); + result.params = { scale, zero_point }; + result.quantization = { kTfLiteAffineQuantization, nullptr }; + return result; +} + +template +TfLiteTensor CreateQuantizedTensor(const float *input, T *quantized, + TfLiteIntArray *dims, float scale, + int zero_point, bool is_variable = false) +{ + int input_size = ElementCount(*dims); + tflite::Quantize(input, quantized, input_size, scale, zero_point); + return CreateQuantizedTensor(quantized, dims, scale, zero_point, is_variable); +} + +TfLiteTensor CreateQuantizedBiasTensor(const float *data, int32_t *quantized, + TfLiteIntArray *dims, float input_scale, + float weights_scale, + bool is_variable = false); + +TfLiteTensor CreateQuantizedBiasTensor(const float *data, + std::int64_t *quantized, + TfLiteIntArray *dims, float input_scale, + float weights_scale, + bool is_variable = false); + +// Quantizes int32_t bias tensor with per-channel weights determined by input +// scale multiplied by weight scale for each channel. +TfLiteTensor CreatePerChannelQuantizedBiasTensor( + const float *input, int32_t *quantized, TfLiteIntArray *dims, + float input_scale, float *weight_scales, float *scales, int *zero_points, + TfLiteAffineQuantization *affine_quant, int quantized_dimension, + bool is_variable = false); + +// Quantizes int64_t bias tensor with per-channel weights determined by input +// scale multiplied by weight scale for each channel. +TfLiteTensor CreatePerChannelQuantizedBiasTensor( + const float *input, std::int64_t *quantized, TfLiteIntArray *dims, + float input_scale, float *weight_scales, float *scales, int *zero_points, + TfLiteAffineQuantization *affine_quant, int quantized_dimension, + bool is_variable = false); + +TfLiteTensor CreateSymmetricPerChannelQuantizedTensor( + const float *input, int8_t *quantized, TfLiteIntArray *dims, float *scales, + int *zero_points, TfLiteAffineQuantization *affine_quant, + int quantized_dimension, bool is_variable = false); + +// Returns the number of tensors in the default subgraph for a tflite::Model. +size_t GetModelTensorCount(const Model *model); + +// Derives the quantization scaling factor from a min and max range. +template +inline float ScaleFromMinMax(const float min, const float max) +{ + return (max - min) / + static_cast((std::numeric_limits::max() * 1.0) - + std::numeric_limits::min()); +} + +// Derives the quantization zero point from a min and max range. +template +inline int ZeroPointFromMinMax(const float min, const float max) +{ + return static_cast(std::numeric_limits::min()) + + static_cast(-min / ScaleFromMinMax(min, max) + 0.5f); +} + +} // namespace testing +} // namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_TEST_HELPERS_H_ diff --git a/components/tflite/tensorflow/lite/micro/testing/generate_test_models.py b/components/tflite/tensorflow/lite/micro/testing/generate_test_models.py new file mode 100644 index 00000000..afeab774 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/testing/generate_test_models.py @@ -0,0 +1,80 @@ +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +"""Python utility script to generate unit test model data.""" + +# Steps to regenerate model test data: +# TODO(b/158011574): Do these steps in the script here instead of manually. +# 1.) Run this script +# 2.) Hexdump the model into a .h/.cc file: +# xxd -i /tmp/tf_micro_conv_test_model.tflite > /tmp/temp.cc +# 3.) Copy/replace contents of temp.cc into desired header/source files (e.g. +# test_conv_model.h/.cc + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +from absl import app +import numpy as np +import tensorflow as tf + + +def generate_conv_model(): + """Creates a basic Keras model and converts to tflite. + + This model does not make any relevant classifications. It only exists to + generate a model that is designed to run on embedded devices. + """ + input_shape = (16, 16, 1) + + model = tf.keras.models.Sequential() + model.add( + tf.keras.layers.Conv2D(16, 3, activation="relu", input_shape=input_shape)) + model.add(tf.keras.layers.Conv2D(32, 3, activation="relu")) + model.add(tf.keras.layers.MaxPooling2D(2)) + model.add(tf.keras.layers.Flatten()) + model.add(tf.keras.layers.Dense(10)) + model.compile( + optimizer="adam", loss="categorical_crossentropy", metrics=["accuracy"]) + model.summary() + + # Test with random data + data_x = np.random.rand(12, 16, 16, 1) + data_y = np.random.randint(2, size=(12, 10)) + model.fit(data_x, data_y, epochs=5) + + def representative_dataset_gen(): + for _ in range(12): + yield [np.random.rand(16, 16).reshape(1, 16, 16, 1).astype(np.float32)] + + # Now convert to a TFLite model with full int8 quantization: + converter = tf.lite.TFLiteConverter.from_keras_model(model) + converter.optimizations = [tf.lite.Optimize.DEFAULT] + converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8] + converter.inference_input_type = tf.int8 + converter.inference_output_type = tf.int8 + converter.representative_dataset = representative_dataset_gen + + tflite_model = converter.convert() + open("/tmp/tf_micro_conv_test_model.int8.tflite", "wb").write(tflite_model) + + +def main(argv): + del argv # Unused for now + generate_conv_model() + + +if __name__ == "__main__": + app.run(main) diff --git a/components/tflite/tensorflow/lite/micro/testing/micro_test.h b/components/tflite/tensorflow/lite/micro/testing/micro_test.h new file mode 100644 index 00000000..cfcf973a --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/testing/micro_test.h @@ -0,0 +1,241 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// An ultra-lightweight testing framework designed for use with microcontroller +// applications. Its only dependency is on TensorFlow Lite's ErrorReporter +// interface, where log messages are output. This is designed to be usable even +// when no standard C or C++ libraries are available, and without any dynamic +// memory allocation or reliance on global constructors. +// +// To build a test, you use syntax similar to gunit, but with some extra +// decoration to create a hidden 'main' function containing each of the tests to +// be run. Your code should look something like: +// ---------------------------------------------------------------------------- +// #include "path/to/this/header" +// +// TF_LITE_MICRO_TESTS_BEGIN +// +// TF_LITE_MICRO_TEST(SomeTest) { +// TF_LITE_LOG_EXPECT_EQ(true, true); +// } +// +// TF_LITE_MICRO_TESTS_END +// ---------------------------------------------------------------------------- +// If you compile this for your platform, you'll get a normal binary that you +// should be able to run. Executing it will output logging information like this +// to stderr (or whatever equivalent is available and written to by +// ErrorReporter): +// ---------------------------------------------------------------------------- +// Testing SomeTest +// 1/1 tests passed +// ~~~ALL TESTS PASSED~~~ +// ---------------------------------------------------------------------------- +// This is designed to be human-readable, so you can just run tests manually, +// but the string "~~~ALL TESTS PASSED~~~" should only appear if all of the +// tests do pass. This makes it possible to integrate with automated test +// systems by scanning the output logs and looking for that magic value. +// +// This framework is intended to be a rudimentary alternative to no testing at +// all on systems that struggle to run more conventional approaches, so use with +// caution! + +#ifndef TENSORFLOW_LITE_MICRO_TESTING_MICRO_TEST_H_ +#define TENSORFLOW_LITE_MICRO_TESTING_MICRO_TEST_H_ + +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/system_setup.h" + +namespace micro_test { +extern int tests_passed; +extern int tests_failed; +extern bool is_test_complete; +extern bool did_test_fail; +} // namespace micro_test + +namespace tflite { +// This additional helper function is used (instead of directly calling +// tflite::InitializeTarget from the TF_LITE_MICRO_TESTS_BEGIN macro) to avoid +// adding a dependency from every bazel test target to micro:system_setp (which +// is the target that implements InitializeTarget(). +// +// The underlying issue here is that the use of the macros results in +// dependencies that can be containted within the micro/testing:micro_test +// target bleeding on to all the tests. +inline void InitializeTest() +{ + InitializeTarget(); +} +} // namespace tflite + +#define TF_LITE_MICRO_TESTS_BEGIN \ + namespace micro_test { \ + int tests_passed; \ + int tests_failed; \ + bool is_test_complete; \ + bool did_test_fail; \ + } \ + \ + int main(int argc, char **argv) \ + { \ + micro_test::tests_passed = 0; \ + micro_test::tests_failed = 0; \ + tflite::InitializeTest(); + +#define TF_LITE_MICRO_TESTS_END \ + MicroPrintf("%d/%d tests passed", micro_test::tests_passed, \ + (micro_test::tests_failed + micro_test::tests_passed)); \ + if (micro_test::tests_failed == 0) { \ + MicroPrintf("~~~ALL TESTS PASSED~~~\n"); \ + return kTfLiteOk; \ + } else { \ + MicroPrintf("~~~SOME TESTS FAILED~~~\n"); \ + return kTfLiteError; \ + } \ + } + +// TODO(petewarden): I'm going to hell for what I'm doing to this poor for loop. +#define TF_LITE_MICRO_TEST(name) \ + MicroPrintf("Testing " #name); \ + for (micro_test::is_test_complete = false, \ + micro_test::did_test_fail = false; \ + !micro_test::is_test_complete; micro_test::is_test_complete = true, \ + micro_test::tests_passed += (micro_test::did_test_fail) ? 0 : 1, \ + micro_test::tests_failed += (micro_test::did_test_fail) ? 1 : 0) + +#define TF_LITE_MICRO_EXPECT(x) \ + do { \ + if (!(x)) { \ + MicroPrintf(#x " failed at %s:%d", __FILE__, __LINE__); \ + micro_test::did_test_fail = true; \ + } \ + } while (false) + +// TODO(b/139142772): this macro is used with types other than ints even though +// the printf specifier is %d. +#define TF_LITE_MICRO_EXPECT_EQ(x, y) \ + do { \ + auto vx = x; \ + auto vy = y; \ + if ((vx) != (vy)) { \ + MicroPrintf(#x " == " #y " failed at %s:%d (%d vs %d)", __FILE__, \ + __LINE__, static_cast(vx), static_cast(vy)); \ + micro_test::did_test_fail = true; \ + } \ + } while (false) + +#define TF_LITE_MICRO_EXPECT_NE(x, y) \ + do { \ + if ((x) == (y)) { \ + MicroPrintf(#x " != " #y " failed at %s:%d", __FILE__, __LINE__); \ + micro_test::did_test_fail = true; \ + } \ + } while (false) + +// TODO(wangtz): Making it more generic once needed. +#define TF_LITE_MICRO_ARRAY_ELEMENT_EXPECT_NEAR(arr1, idx1, arr2, idx2, \ + epsilon) \ + do { \ + auto delta = ((arr1)[(idx1)] > (arr2)[(idx2)]) ? ((arr1)[(idx1)] - (arr2)[(idx2)]) : ((arr2)[(idx2)] - (arr1)[(idx1)]); \ + if (delta > epsilon) { \ + MicroPrintf(#arr1 "[%d] (%f) near " #arr2 "[%d] (%f) failed at %s:%d", \ + static_cast(idx1), static_cast((arr1)[(idx1)]), \ + static_cast(idx2), static_cast((arr2)[(idx2)]), \ + __FILE__, __LINE__); \ + micro_test::did_test_fail = true; \ + } \ + } while (false) + +// The check vx != vy is needed to properly handle the case where both +// x and y evaluate to infinity. See #46960 for more details. +#define TF_LITE_MICRO_EXPECT_NEAR(x, y, epsilon) \ + do { \ + auto vx = (x); \ + auto vy = (y); \ + auto delta = ((vx) > (vy)) ? ((vx) - (vy)) : ((vy) - (vx)); \ + if (vx != vy && delta > epsilon) { \ + MicroPrintf(#x " (%f) near " #y " (%f) failed at %s:%d", \ + static_cast(vx), static_cast(vy), __FILE__, \ + __LINE__); \ + micro_test::did_test_fail = true; \ + } \ + } while (false) + +#define TF_LITE_MICRO_EXPECT_GT(x, y) \ + do { \ + if ((x) <= (y)) { \ + MicroPrintf(#x " > " #y " failed at %s:%d", __FILE__, __LINE__); \ + micro_test::did_test_fail = true; \ + } \ + } while (false) + +#define TF_LITE_MICRO_EXPECT_LT(x, y) \ + do { \ + if ((x) >= (y)) { \ + MicroPrintf(#x " < " #y " failed at %s:%d", __FILE__, __LINE__); \ + micro_test::did_test_fail = true; \ + } \ + } while (false) + +#define TF_LITE_MICRO_EXPECT_GE(x, y) \ + do { \ + if ((x) < (y)) { \ + MicroPrintf(#x " >= " #y " failed at %s:%d", __FILE__, __LINE__); \ + micro_test::did_test_fail = true; \ + } \ + } while (false) + +#define TF_LITE_MICRO_EXPECT_LE(x, y) \ + do { \ + if ((x) > (y)) { \ + MicroPrintf(#x " <= " #y " failed at %s:%d", __FILE__, __LINE__); \ + micro_test::did_test_fail = true; \ + } \ + } while (false) + +#define TF_LITE_MICRO_EXPECT_TRUE(x) \ + do { \ + if (!(x)) { \ + MicroPrintf(#x " was not true failed at %s:%d", __FILE__, __LINE__); \ + micro_test::did_test_fail = true; \ + } \ + } while (false) + +#define TF_LITE_MICRO_EXPECT_FALSE(x) \ + do { \ + if (x) { \ + MicroPrintf(#x " was not false failed at %s:%d", __FILE__, __LINE__); \ + micro_test::did_test_fail = true; \ + } \ + } while (false) + +#define TF_LITE_MICRO_FAIL(msg) \ + do { \ + MicroPrintf("FAIL: %s", msg, __FILE__, __LINE__); \ + micro_test::did_test_fail = true; \ + } while (false) + +#define TF_LITE_MICRO_EXPECT_STRING_EQ(string1, string2) \ + do { \ + for (int i = 0; string1[i] != '\0' && string2[i] != '\0'; i++) { \ + if (string1[i] != string2[i]) { \ + MicroPrintf("FAIL: %s did not match %s", string1, string2, __FILE__, \ + __LINE__); \ + micro_test::did_test_fail = true; \ + } \ + } \ + } while (false) + +#endif // TENSORFLOW_LITE_MICRO_TESTING_MICRO_TEST_H_ diff --git a/components/tflite/tensorflow/lite/micro/testing/robot.resource.txt b/components/tflite/tensorflow/lite/micro/testing/robot.resource.txt new file mode 100644 index 00000000..e06720c8 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/testing/robot.resource.txt @@ -0,0 +1,26 @@ +*** Variables *** +${UART} sysbus.cpu.uartSemihosting + +*** Keywords *** +Teardown With Custom Message + Test Teardown + [Documentation] Replace robot fail message with whole UART output + ${UART_LOGS} Get File ${UART_LOG} + Set Test Message UART OUTPUT:\n\n${UART_LOGS} + Remove File ${UART_LOG} + +Create Platform + Execute Command $logfile=@${UART_LOG} + Execute Script ${RESC} + Provides ready-platform + +Test Binary + [Arguments] ${BIN} + Requires ready-platform + Execute Command sysbus LoadELF ${BIN} + + Create Terminal Tester ${UART} timeout=2 + Start Emulation + + Wait For Line On Uart ${UART_LINE_ON_SUCCESS} + diff --git a/components/tflite/tensorflow/lite/micro/testing/test_conv_model.cc b/components/tflite/tensorflow/lite/micro/testing/test_conv_model.cc new file mode 100644 index 00000000..fef21ad7 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/testing/test_conv_model.cc @@ -0,0 +1,1800 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/testing/test_conv_model.h" + +extern const unsigned char kTestConvModelData[] = { + 0x24, 0x00, 0x00, 0x00, 0x54, 0x46, 0x4c, 0x33, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x1c, 0x00, 0x04, 0x00, + 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x18, 0x00, + 0x12, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xb4, 0x52, 0x00, 0x00, + 0x3c, 0x42, 0x00, 0x00, 0x24, 0x42, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x0c, 0x00, 0x04, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, + 0x6d, 0x69, 0x6e, 0x5f, 0x72, 0x75, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x5f, + 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x00, 0x0f, 0x00, 0x00, 0x00, + 0xd4, 0x41, 0x00, 0x00, 0xc0, 0x41, 0x00, 0x00, 0x64, 0x41, 0x00, 0x00, + 0xc0, 0x40, 0x00, 0x00, 0x7c, 0x40, 0x00, 0x00, 0x58, 0x40, 0x00, 0x00, + 0x44, 0x13, 0x00, 0x00, 0xa0, 0x12, 0x00, 0x00, 0x8c, 0x00, 0x00, 0x00, + 0x80, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, + 0x44, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xd6, 0xbe, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x31, 0x2e, 0x35, 0x2e, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x94, 0xb2, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa4, 0xb2, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xb4, 0xb2, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xc4, 0xb2, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0xb2, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0x46, 0xbf, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x12, 0x00, 0x00, 0x7d, 0x6a, 0x24, 0xa1, 0xf6, 0xca, 0x70, 0x2f, + 0x8e, 0xb1, 0xe8, 0x15, 0x42, 0x08, 0x32, 0xf6, 0xe9, 0xfb, 0xa0, 0xda, + 0xe4, 0xf1, 0x0a, 0x9d, 0x72, 0x66, 0x88, 0x37, 0xe9, 0x9e, 0x08, 0x54, + 0x61, 0x51, 0x40, 0x93, 0x4d, 0xcf, 0xe2, 0x08, 0x36, 0xad, 0xb1, 0x8e, + 0xfc, 0xe4, 0x02, 0xd1, 0x9a, 0x1e, 0x05, 0x67, 0xa3, 0x3b, 0xa6, 0xde, + 0x5d, 0x2a, 0xcc, 0x8c, 0x3c, 0x2e, 0xd2, 0x15, 0xc2, 0x60, 0xab, 0xea, + 0x73, 0xe4, 0x88, 0xc1, 0x66, 0x21, 0xb0, 0xe5, 0x5b, 0x55, 0xda, 0x69, + 0x2d, 0x0c, 0x66, 0x07, 0x74, 0x36, 0xcd, 0x79, 0x81, 0xf9, 0x5c, 0x2c, + 0xb5, 0x93, 0xab, 0x76, 0xa1, 0x1f, 0x20, 0x90, 0x89, 0xe1, 0x41, 0xc7, + 0x32, 0xc2, 0xa3, 0x03, 0x77, 0x86, 0x79, 0xf7, 0x89, 0xc1, 0xb1, 0x42, + 0x2a, 0x75, 0xc7, 0xc1, 0x2f, 0xbb, 0xf6, 0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0x24, + 0x18, 0x67, 0x45, 0xd3, 0xf8, 0x3f, 0xc5, 0xdf, 0xac, 0x65, 0xd4, 0x0c, + 0x82, 0x63, 0xd6, 0x43, 0x94, 0xa0, 0x3b, 0xff, 0x03, 0x0f, 0xbb, 0xe4, + 0x4d, 0x3b, 0x41, 0x9f, 0xf4, 0x1a, 0xa9, 0xdb, 0x15, 0x5b, 0x9a, 0x92, + 0xcb, 0xd5, 0xb8, 0x33, 0x5e, 0xea, 0x28, 0x3d, 0x2d, 0x30, 0x20, 0xcd, + 0xb6, 0x23, 0x18, 0x0e, 0x10, 0x2a, 0xa9, 0xe1, 0xad, 0xbc, 0x96, 0xd1, + 0xf9, 0xf3, 0x95, 0x4f, 0x2a, 0x0b, 0x91, 0xff, 0xf0, 0x96, 0x14, 0x00, + 0xaa, 0xfb, 0x1a, 0x44, 0x21, 0x9b, 0xe8, 0x71, 0x31, 0x9e, 0xd6, 0x58, + 0x7f, 0x02, 0x36, 0x5e, 0x92, 0x8d, 0x93, 0x99, 0xac, 0xb6, 0x87, 0x39, + 0xda, 0x47, 0xef, 0x70, 0xd4, 0xf7, 0x8d, 0x2a, 0xbd, 0x08, 0x40, 0x4d, + 0xec, 0xeb, 0x4e, 0x1b, 0x85, 0x5d, 0x55, 0x64, 0x4c, 0xf3, 0x5e, 0x8f, + 0x68, 0x1e, 0x5e, 0x64, 0xc3, 0xb8, 0x92, 0x24, 0x41, 0x98, 0x78, 0x09, + 0x85, 0x87, 0x17, 0x2c, 0x88, 0x9e, 0x62, 0x86, 0x4f, 0x44, 0x71, 0x9c, + 0xa8, 0x73, 0xb3, 0x14, 0x1f, 0x3c, 0x96, 0x6b, 0xab, 0xad, 0x43, 0xdf, + 0x67, 0x34, 0x66, 0x30, 0x1d, 0x15, 0xd3, 0xe7, 0xd5, 0x8b, 0x00, 0xaa, + 0x11, 0x77, 0xea, 0x36, 0xc9, 0x49, 0x99, 0x93, 0x01, 0x6e, 0x00, 0x4a, + 0x93, 0x08, 0x2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0x8a, 0xb7, 0x54, 0xdb, 0xc7, 0xc5, 0x2c, 0x42, + 0x65, 0x51, 0xab, 0x56, 0x94, 0x73, 0xec, 0xd9, 0x95, 0xfa, 0x6a, 0x56, + 0xef, 0x22, 0x95, 0xa4, 0x75, 0x46, 0xee, 0x60, 0x8b, 0x25, 0xa6, 0x92, + 0x0a, 0x8e, 0xc1, 0x39, 0x97, 0x69, 0xa9, 0x19, 0x97, 0xf1, 0x0f, 0x61, + 0xc2, 0x40, 0x7d, 0x62, 0xe9, 0x5e, 0x22, 0x1f, 0x27, 0xe5, 0xc7, 0xe7, + 0xa4, 0x35, 0x5d, 0x90, 0xc7, 0x38, 0x38, 0x2d, 0xb0, 0x1e, 0x29, 0x0f, + 0x4f, 0x08, 0x8b, 0xdd, 0x69, 0x3c, 0x5c, 0x03, 0xbe, 0x9a, 0x76, 0xba, + 0x91, 0xf5, 0x57, 0x07, 0x39, 0xfe, 0x09, 0xfc, 0x01, 0x7b, 0x37, 0xc4, + 0x73, 0x7f, 0x76, 0x50, 0x76, 0xae, 0x6e, 0x4b, 0x22, 0x2c, 0x3b, 0xe7, + 0x77, 0x19, 0x9a, 0x92, 0x26, 0xdf, 0xc4, 0xe6, 0xd8, 0x57, 0xc1, 0x7f, + 0x65, 0x0b, 0xfb, 0xfa, 0xdd, 0xd2, 0x8c, 0xc7, 0xb1, 0x72, 0x2a, 0xb2, + 0x5a, 0xfa, 0xb2, 0x84, 0xb1, 0xec, 0x79, 0x9e, 0xde, 0xd8, 0x2f, 0xdf, + 0x3b, 0x39, 0x0b, 0xac, 0xfa, 0xb8, 0x07, 0x38, 0xff, 0x2e, 0x22, 0x2b, + 0xc9, 0x31, 0x3b, 0x09, 0x05, 0xd2, 0x06, 0xc4, 0x2d, 0x22, 0x1c, 0x21, + 0x70, 0x03, 0x93, 0xd1, 0x3a, 0x8d, 0x94, 0x60, 0xfe, 0x99, 0x13, 0xc3, + 0x00, 0x03, 0x41, 0xfa, 0x50, 0x79, 0x31, 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 0x48, 0x09, + 0x26, 0x6a, 0xbd, 0x3b, 0x10, 0xa1, 0x55, 0xe5, 0x99, 0x53, 0x1e, 0xd2, + 0xee, 0x7c, 0x54, 0xd8, 0x06, 0x8b, 0x1e, 0xe7, 0x3f, 0x08, 0x38, 0x9b, + 0x2e, 0x41, 0xdf, 0x0b, 0x7e, 0x83, 0x7f, 0x04, 0x38, 0xa5, 0x1f, 0x46, + 0x8b, 0x94, 0x28, 0x9f, 0xb8, 0x8c, 0x41, 0xfe, 0x96, 0xe2, 0x24, 0xd1, + 0x97, 0xa4, 0xcb, 0xba, 0xfa, 0x19, 0xc9, 0x57, 0x30, 0x0f, 0x88, 0x58, + 0xa9, 0x67, 0x31, 0x74, 0x51, 0x34, 0x03, 0xbc, 0xff, 0x3b, 0x12, 0x61, + 0x84, 0x63, 0x74, 0xec, 0x4d, 0xda, 0xa3, 0x56, 0xc3, 0xe5, 0x5e, 0x4a, + 0x03, 0x26, 0x88, 0x1a, 0x1d, 0x7f, 0xe8, 0x3f, 0x61, 0x78, 0xb6, 0xc5, + 0x66, 0xb7, 0xb4, 0xc1, 0xe7, 0x82, 0xc1, 0x44, 0xdf, 0xf9, 0x30, 0x30, + 0xe1, 0xd0, 0xf8, 0xf5, 0x40, 0x5a, 0x72, 0x29, 0xef, 0x30, 0xe1, 0x01, + 0xca, 0x1b, 0xb0, 0xa6, 0xa3, 0x17, 0x2b, 0x58, 0x03, 0xda, 0x25, 0x0f, + 0xdc, 0x49, 0x7c, 0xc5, 0x8f, 0x2d, 0x83, 0xca, 0x43, 0x08, 0xc0, 0x36, + 0x70, 0x1e, 0x42, 0xfd, 0xac, 0x4d, 0x31, 0xcf, 0x68, 0x4a, 0xda, 0xd8, + 0xcb, 0xee, 0xaa, 0xfc, 0xcf, 0xcc, 0xe6, 0xb2, 0x77, 0x8b, 0x83, 0x5b, + 0xd5, 0x3d, 0x55, 0xba, 0x03, 0x45, 0xce, 0x51, 0x78, 0x36, 0xcb, 0xcd, + 0x9a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xa5, 0x37, 0x06, 0x67, + 0x41, 0x1f, 0x6e, 0xa3, 0xc2, 0xb4, 0x96, 0x64, 0xfc, 0x46, 0x85, 0x95, + 0x4e, 0xd8, 0x2a, 0x4b, 0xaa, 0x1e, 0xec, 0xd5, 0xed, 0x81, 0x23, 0x68, + 0x0f, 0x5d, 0x0b, 0x95, 0x29, 0xd4, 0x36, 0x4d, 0x8c, 0x32, 0x73, 0x6a, + 0xb7, 0xad, 0xb8, 0x9c, 0xad, 0x76, 0x09, 0xad, 0xb9, 0xea, 0x2d, 0x17, + 0x3c, 0x33, 0x87, 0x7f, 0x62, 0x74, 0x77, 0xc9, 0xd6, 0x3d, 0x17, 0xbc, + 0xff, 0x57, 0x10, 0xec, 0x7a, 0xb7, 0x89, 0x05, 0x26, 0xf1, 0xb2, 0x53, + 0xa1, 0x91, 0xc5, 0x2a, 0xfb, 0x5a, 0xce, 0x5d, 0xd1, 0x6b, 0xbc, 0xb7, + 0x39, 0x09, 0x43, 0xdf, 0x20, 0xd3, 0xc1, 0x74, 0x8d, 0xf4, 0x0b, 0x2a, + 0xc7, 0xe8, 0xa1, 0x5f, 0xb2, 0xfe, 0x1a, 0x96, 0x3a, 0x92, 0xbc, 0x8f, + 0x85, 0xe2, 0x22, 0x73, 0x3f, 0x49, 0xb3, 0x6b, 0x90, 0xbd, 0xcb, 0x3f, + 0x36, 0x6c, 0x3d, 0xe3, 0x00, 0x00, 0x00, 0x00, 0x56, 0xd1, 0xff, 0xff, + 0x04, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x1f, 0x05, 0x81, 0x3f, + 0x25, 0x68, 0xde, 0x72, 0x88, 0x26, 0x66, 0x2d, 0xe4, 0xc8, 0x81, 0xf8, + 0x5d, 0x98, 0xa2, 0xc2, 0x02, 0x62, 0x63, 0x47, 0xe6, 0x61, 0x7f, 0xee, + 0xca, 0x3f, 0x81, 0xd7, 0x1e, 0xa9, 0xbf, 0x66, 0x59, 0x7f, 0xc3, 0x35, + 0x03, 0xae, 0xe5, 0xf2, 0x4d, 0x81, 0x82, 0x78, 0x5e, 0xaf, 0xaa, 0xd1, + 0x27, 0x41, 0x19, 0x93, 0xa8, 0x9b, 0x78, 0x4e, 0x95, 0x89, 0x7f, 0xce, + 0x49, 0xd0, 0x45, 0xb5, 0x7f, 0x1d, 0xe9, 0xee, 0x7f, 0x91, 0xf4, 0x0a, + 0x67, 0x7d, 0x75, 0xff, 0x38, 0x81, 0x27, 0x90, 0x14, 0xa5, 0x99, 0x40, + 0x5b, 0xe6, 0x9a, 0x81, 0x75, 0x22, 0x5f, 0x18, 0x81, 0x34, 0xb7, 0x54, + 0x2e, 0x8d, 0x81, 0x36, 0x0e, 0x5e, 0xc0, 0x5f, 0xd4, 0xc6, 0x34, 0x81, + 0xc8, 0xb9, 0xe2, 0xa9, 0x77, 0x81, 0x44, 0xb4, 0x06, 0x24, 0x81, 0x74, + 0x1c, 0xeb, 0xfb, 0xdd, 0x25, 0x81, 0x14, 0x09, 0x2d, 0xba, 0x11, 0x4b, + 0x07, 0x13, 0xf1, 0xae, 0x81, 0xaf, 0xa3, 0x87, 0x00, 0x00, 0x00, 0x00, + 0xf6, 0xd1, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x00, + 0x8a, 0x29, 0x03, 0xe6, 0x24, 0x2a, 0xd6, 0x21, 0xb6, 0xb1, 0x2d, 0x3a, + 0xff, 0xd6, 0x27, 0xd7, 0x18, 0x42, 0xc1, 0xb4, 0xf8, 0xfd, 0xdf, 0x45, + 0x09, 0x91, 0xcb, 0xfe, 0xe9, 0xb5, 0x24, 0xf1, 0xc0, 0x69, 0xd0, 0x64, + 0xa8, 0xeb, 0x12, 0x71, 0xe3, 0xb4, 0xbe, 0xb4, 0x93, 0xbf, 0x8a, 0x8b, + 0xf3, 0x4d, 0x13, 0x3b, 0x6f, 0x6f, 0x32, 0x12, 0x98, 0x95, 0xb9, 0x63, + 0xcd, 0xa5, 0x23, 0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, 0xf0, 0x70, 0x3c, 0xc4, 0x40, 0xa4, 0xd4, 0xee, + 0xaf, 0x3d, 0xe6, 0xcd, 0x31, 0x16, 0x31, 0x3b, 0xa0, 0x0e, 0xc4, 0x71, + 0xbf, 0xbd, 0x39, 0x89, 0x0f, 0x36, 0xba, 0xd8, 0xa2, 0x49, 0x01, 0xab, + 0xf4, 0x07, 0x99, 0xc7, 0xb1, 0x0c, 0x33, 0x9d, 0x71, 0xf1, 0x15, 0x4b, + 0x60, 0xe0, 0xed, 0x59, 0x0a, 0x34, 0xd9, 0xa2, 0x45, 0x99, 0x4a, 0x60, + 0xd3, 0xdc, 0x37, 0x56, 0x32, 0x4c, 0xea, 0xdc, 0xcf, 0xe6, 0x22, 0x27, + 0x17, 0xea, 0x75, 0x3f, 0x69, 0xd4, 0xcf, 0x53, 0x92, 0x98, 0xf4, 0xfe, + 0x13, 0xa8, 0xe2, 0xb2, 0x48, 0x5f, 0x64, 0xab, 0x2b, 0x61, 0x97, 0xf5, + 0xc5, 0xb6, 0xef, 0x32, 0x4e, 0x47, 0x26, 0x42, 0x48, 0x9c, 0x5b, 0x24, + 0xa3, 0xcb, 0x70, 0xc7, 0x31, 0x6c, 0xc8, 0x4d, 0x5c, 0x02, 0xca, 0x71, + 0x1e, 0x56, 0xdb, 0x27, 0x66, 0x5d, 0x4f, 0x0b, 0x09, 0x57, 0xbe, 0x72, + 0x17, 0x3b, 0xce, 0xdd, 0xd2, 0x20, 0x13, 0x67, 0x32, 0x04, 0xee, 0xc4, + 0x66, 0x23, 0x0e, 0x97, 0x5e, 0x21, 0x30, 0xb2, 0xe4, 0x16, 0x06, 0x57, + 0xc3, 0x9b, 0x29, 0x5b, 0x76, 0xd0, 0x36, 0xac, 0xe6, 0xa2, 0x91, 0x57, + 0x96, 0x4e, 0x1c, 0x6f, 0x4a, 0x03, 0x50, 0x55, 0x6d, 0xaf, 0x9a, 0x29, + 0xc9, 0x61, 0x6c, 0x18, 0x4c, 0xb9, 0xd5, 0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2, 0x58, 0xbe, 0x3f, 0x30, 0xdd, 0x65, 0xd0, 0x40, 0xe1, 0xaf, 0x09, + 0xf1, 0xf4, 0x0f, 0x1a, 0xe5, 0xef, 0x51, 0x50, 0x38, 0x5d, 0xb0, 0x1e, + 0xed, 0x19, 0x8d, 0x4e, 0x20, 0xa1, 0x65, 0x07, 0x5b, 0x23, 0x0c, 0x14, + 0xd3, 0x18, 0xa3, 0xda, 0x58, 0x9f, 0x10, 0x00, 0xbd, 0xb5, 0x95, 0x07, + 0x1d, 0x0f, 0xf9, 0x2a, 0xe4, 0x35, 0x3c, 0x60, 0xad, 0xb2, 0x13, 0x3b, + 0xd5, 0x9e, 0xeb, 0xc7, 0x09, 0x6e, 0x53, 0xff, 0x95, 0xf3, 0xc1, 0x9b, + 0xcd, 0x21, 0x15, 0x3b, 0x5f, 0xfe, 0x4e, 0xaf, 0x3f, 0xf8, 0xe3, 0xa8, + 0x35, 0xee, 0x44, 0x33, 0xc7, 0x8c, 0x9c, 0x1c, 0x33, 0x55, 0x3c, 0x4a, + 0xa4, 0x35, 0xf6, 0xf0, 0x32, 0x8e, 0xed, 0x6d, 0x06, 0xff, 0x8d, 0x24, + 0x05, 0x72, 0x4c, 0xa2, 0x97, 0x25, 0x93, 0x3d, 0x79, 0x18, 0x22, 0x15, + 0xec, 0x5c, 0xc4, 0x10, 0x65, 0xec, 0x90, 0x6d, 0x28, 0xba, 0x93, 0xb5, + 0x2f, 0x53, 0xe4, 0x00, 0x9c, 0x39, 0xf5, 0x4c, 0xde, 0x51, 0x39, 0xc3, + 0xd8, 0x03, 0xc3, 0x97, 0xe1, 0xa8, 0x3e, 0x06, 0x26, 0x4d, 0xd9, 0x49, + 0x75, 0xbb, 0xd5, 0x69, 0x20, 0xfb, 0x85, 0x12, 0xc9, 0xac, 0xfc, 0x05, + 0xad, 0x57, 0xa9, 0x58, 0xcd, 0xfd, 0xbe, 0x64, 0x31, 0x50, 0x4d, 0xa4, + 0x93, 0xb6, 0x23, 0x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0x33, 0x34, 0x29, 0x12, 0xf6, + 0x07, 0x22, 0xfd, 0xbb, 0x72, 0x60, 0x2a, 0xf5, 0xec, 0x71, 0xfe, 0xd7, + 0xc1, 0xf5, 0xdf, 0x97, 0x3e, 0x4a, 0x9a, 0x97, 0x6f, 0x56, 0xf1, 0xd4, + 0xba, 0x29, 0x09, 0x46, 0x3f, 0x10, 0xdc, 0x2d, 0xb2, 0x04, 0x32, 0x38, + 0xa3, 0xc7, 0x75, 0x95, 0x16, 0xd6, 0x12, 0x44, 0x7a, 0xd3, 0x18, 0xb3, + 0x51, 0x72, 0x63, 0xb8, 0xae, 0x9b, 0xf1, 0xec, 0x17, 0xe4, 0x2d, 0xed, + 0x29, 0x05, 0x63, 0xd7, 0x01, 0xf4, 0xf5, 0xc1, 0x6d, 0x13, 0x5f, 0x5c, + 0x73, 0x11, 0xc9, 0x53, 0xf4, 0xda, 0x90, 0xa2, 0x1c, 0x0b, 0x1d, 0x37, + 0x28, 0xa1, 0x06, 0x65, 0xd3, 0x49, 0x5d, 0x07, 0x1f, 0x93, 0xa9, 0x98, + 0xc5, 0xa5, 0x13, 0xc5, 0xac, 0xda, 0x64, 0x25, 0x77, 0x9a, 0xd5, 0xa9, + 0xe9, 0x3a, 0x77, 0x62, 0xac, 0xf2, 0x76, 0xf4, 0x03, 0xb6, 0x03, 0x6e, + 0xef, 0x97, 0x13, 0x1c, 0xd1, 0xb9, 0x73, 0x12, 0xf7, 0x10, 0xbd, 0x1c, + 0xa1, 0xe7, 0xed, 0xd7, 0xa0, 0xd7, 0x53, 0xa1, 0x21, 0xf1, 0x5f, 0x1e, + 0xec, 0x36, 0x0d, 0x2c, 0xce, 0x74, 0x4a, 0x0c, 0x97, 0x5a, 0x76, 0x62, + 0x18, 0x9c, 0xc3, 0xc1, 0xc4, 0x5e, 0xf1, 0xfa, 0xe6, 0x4b, 0x15, 0xda, + 0xfa, 0xfd, 0xe9, 0x98, 0x09, 0xc3, 0x67, 0x63, 0x1f, 0x28,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0x56, 0x15, 0x59, 0xd6, 0xd4, 0xe4, 0x1a, 0x25, 0xd5, 0xcf, + 0xe7, 0x6a, 0x55, 0xd4, 0xf8, 0x42, 0x4c, 0xcb, 0x9a, 0x48, 0x4d, 0x27, + 0x61, 0x4c, 0x36, 0x2b, 0xcb, 0x10, 0xba, 0xf7, 0xe3, 0x23, 0x27, 0xc5, + 0x6a, 0x1b, 0x94, 0x69, 0x64, 0xb1, 0x8c, 0xdb, 0xd4, 0x0d, 0x32, 0x3e, + 0x58, 0x73, 0xa8, 0x2f, 0x3d, 0x22, 0xd9, 0x0d, 0x2a, 0x52, 0xf0, 0xdd, + 0xeb, 0x21, 0x42, 0xc7, 0x59, 0x96, 0x09, 0x93, 0x5a, 0x70, 0xc3, 0x21, + 0x5f, 0xce, 0xc2, 0xdd, 0xcf, 0x61, 0xed, 0x1c, 0xfb, 0x2f, 0x57, 0xf7, + 0x31, 0xb8, 0x3e, 0x92, 0x29, 0xd4, 0x47, 0x6a, 0x19, 0x66, 0x00, 0xc2, + 0xc4, 0x6c, 0xb5, 0xc5, 0x68, 0x24, 0xa8, 0x64, 0x26, 0x72, 0x43, 0x20, + 0x9f, 0xf1, 0x3f, 0xac, 0x64, 0xb5, 0x12, 0x26, 0x13, 0x76, 0x52, 0x05, + 0xda, 0x57, 0xe3, 0x53, 0x73, 0x30, 0x21, 0x27, 0x75, 0x8d, 0x37, 0xd1, + 0x77, 0x40, 0x97, 0x2a, 0xb7, 0x0b, 0x2e, 0x9e, 0x4c, 0x36, 0x75, 0x44, + 0x15, 0xdb, 0x96, 0x70, 0xf9, 0x33, 0x9a, 0x1e, 0x6e, 0x13, 0x05, 0x38, + 0x2c, 0xbf, 0x0a, 0xdd, 0x2b, 0x2b, 0x38, 0x77, 0xa9, 0x00, 0x2d, 0x5e, + 0xee, 0x4b, 0xf3, 0x20, 0x7a, 0x90, 0x97, 0x44, 0xdf, 0x55, 0xfd, 0x50, + 0xe3, 0x24, 0x25, 0xa9, 0xd9, 0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0xee, + 0x67, 0x9f, 0x26, 0xfb, 0x2f, 0x63, 0xf2, 0x6a, 0x23, 0x45, 0x26, 0x2c, + 0x33, 0x8a, 0xf2, 0xd1, 0xb2, 0x77, 0x99, 0x98, 0xd6, 0x18, 0xfe, 0xf3, + 0xff, 0xa4, 0x36, 0x03, 0xf4, 0xf5, 0xb1, 0xca, 0xa3, 0x5f, 0xe2, 0xc6, + 0xb2, 0x55, 0x2c, 0xaa, 0x64, 0xef, 0x28, 0x3a, 0x9e, 0x98, 0x01, 0x57, + 0x49, 0x98, 0x61, 0x4f, 0x42, 0x57, 0x00, 0x19, 0xb9, 0xa8, 0xec, 0xed, + 0x2b, 0x63, 0xf3, 0x0c, 0x3a, 0x1f, 0x10, 0xab, 0xe9, 0x6e, 0x61, 0x69, + 0xd1, 0x2d, 0xf3, 0x1f, 0xaa, 0x00, 0x57, 0xe2, 0xab, 0x74, 0xcd, 0xff, + 0x97, 0x2c, 0x3b, 0x67, 0xae, 0xa3, 0xfc, 0x69, 0xa9, 0x4e, 0x42, 0x07, + 0xfc, 0xbf, 0x36, 0x1a, 0xef, 0x6d, 0x6d, 0x14, 0x61, 0x30, 0x27, 0x98, + 0xfa, 0xf8, 0xc9, 0x70, 0xb4, 0xaa, 0x53, 0x48, 0x72, 0x3f, 0x58, 0x69, + 0x8d, 0x08, 0xc8, 0x09, 0x2b, 0xfc, 0x1d, 0xa1, 0x92, 0xae, 0x62, 0xa0, + 0xea, 0x05, 0x40, 0xac, 0x9c, 0xaf, 0x0e, 0xf4, 0x1e, 0x45, 0x33, 0xee, + 0x31, 0x39, 0x08, 0x4b, 0x54, 0x02, 0x2d, 0x03, 0x1c, 0xe6, 0x2d, 0x0c, + 0xd0, 0x92, 0x44, 0xd6, 0xa1, 0x57, 0x4e, 0x17, 0xde, 0xe6, 0x4f, 0x6a, + 0x07, 0x9f, 0x58, 0xe2, 0x27, 0xdb, 0xa9, 0x0c, 0x19, 0x56, 0xa3, 0xb4, + 0xc4, 0xe8,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 0x67, 0x32, 0x12, 0x41, 0x04, 0xcb, 0x24, 0xae, 0x9e, 0xcc, + 0xd6, 0xc6, 0x67, 0x53, 0xfa, 0x29, 0x37, 0x73, 0xc6, 0xdf, 0xf2, 0x56, + 0x72, 0x06, 0x03, 0xaa, 0x5d, 0x07, 0xac, 0x38, 0xb9, 0x2a, 0x61, 0x02, + 0x24, 0xcf, 0x54, 0x3f, 0x98, 0xb0, 0x5c, 0xba, 0xe3, 0x15, 0x27, 0x52, + 0x63, 0x43, 0x12, 0x62, 0x33, 0x02, 0xb8, 0x69, 0x52, 0x70, 0x6c, 0xc0, + 0x23, 0x37, 0x65, 0x4b, 0xc9, 0xea, 0x98, 0x06, 0xde, 0x3d, 0x59, 0x72, + 0x94, 0x48, 0x60, 0xeb, 0xe7, 0xaa, 0x68, 0x72, 0x22, 0x15, 0x39, 0xf0, + 0x47, 0x43, 0xeb, 0x37, 0xb1, 0x3b, 0x9e, 0x05, 0x12, 0xdb, 0x74, 0x18, + 0xfe, 0x11, 0xcb, 0xae, 0xe0, 0xed, 0x1c, 0xe3, 0x19, 0x71, 0x56, 0xa6, + 0x04, 0xe6, 0x20, 0x62, 0xfd, 0xb1, 0x57, 0x44, 0xca, 0x3f, 0xdf, 0x51, + 0x23, 0x76, 0x3b, 0x70, 0x27, 0x33, 0x62, 0x74, 0x94, 0xff, 0x70, 0xcc, + 0xd4, 0xbf, 0x67, 0x12, 0x17, 0x5f, 0x71, 0xf8, 0x8f, 0x09, 0xca, 0xb5, + 0x49, 0x38, 0xcf, 0x1f, 0x94, 0x9a, 0xe6, 0x76, 0x0e, 0xa6, 0x5a, 0x2c, + 0x36, 0x61, 0x41, 0x2d, 0x14, 0x2f, 0x35, 0xa2, 0xaa, 0x2d, 0xd5, 0x54, + 0x3c, 0x4e, 0xa0, 0x63, 0xa9, 0x9e, 0xe9, 0x65, 0x62, 0xcf, 0x5a, 0x1a, + 0xb9, 0x70, 0xf7, 0xf1, 0x8a, 0xc7, 0x19, 0x6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1a, 0xd2, 0x73, + 0xed, 0x01, 0x20, 0x76, 0x59, 0x3b, 0x63, 0x15, 0xf7, 0x4a, 0x93, 0xf5, + 0xe8, 0xaa, 0x77, 0xf7, 0xee, 0x16, 0x26, 0x6d, 0x6d, 0x1e, 0xb3, 0x04, + 0xd1, 0x36, 0x6d, 0xdb, 0xe1, 0xee, 0xdf, 0x69, 0x0e, 0x28, 0x3b, 0x5a, + 0x37, 0x51, 0x61, 0x10, 0x58, 0xd0, 0x58, 0x75, 0x63, 0x5b, 0x76, 0x3e, + 0x55, 0x0a, 0x07, 0x3e, 0xfe, 0xb9, 0x6e, 0x4c, 0xfc, 0x1b, 0x8a, 0xa5, + 0x03, 0x1a, 0xb9, 0x04, 0x22, 0x60, 0x33, 0x66, 0xda, 0xb7, 0x1c, 0x3a, + 0xb6, 0x92, 0x45, 0x01, 0xc2, 0x73, 0x49, 0x6a, 0x9a, 0x54, 0x10, 0xe2, + 0x36, 0x45, 0xbd, 0x1d, 0x33, 0x2a, 0xd2, 0xc9, 0x70, 0x63, 0x39, 0xcf, + 0xf7, 0x76, 0x70, 0x37, 0xde, 0x23, 0x4c, 0xd2, 0xa1, 0x37, 0x2c, 0x52, + 0xae, 0xa3, 0xfb, 0x45, 0xd0, 0xb9, 0x46, 0x3e, 0x2a, 0xe8, 0xe9, 0x64, + 0xe1, 0x16, 0x30, 0x08, 0x36, 0xcd, 0x9e, 0x15, 0x44, 0xdd, 0x27, 0xa9, + 0x1c, 0x29, 0xf1, 0xa7, 0x20, 0x21, 0x59, 0x61, 0x4c, 0xbe, 0x5e, 0x20, + 0x36, 0xca, 0xb8, 0x6d, 0xb5, 0x0c, 0x29, 0x41, 0xa1, 0xd3, 0x8a, 0x2b, + 0x34, 0xd2, 0x5b, 0x92, 0x12, 0x1f, 0x36, 0x9f, 0x5d, 0x02, 0x2a, 0xca, + 0xac, 0x5b, 0x29, 0x8b, 0x51, 0x3a, 0x65, 0xf5, 0xdf, 0x60, 0x6c, 0x0c, + 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 0x4d, 0x0b, 0x9a, 0x82, 0xfe, 0x26, 0xc5, 0x17, 0x5b, 0x51, + 0x46, 0xf2, 0xf7, 0x27, 0xba, 0x06, 0x91, 0x0e, 0xc2, 0x07, 0xb3, 0x1b, + 0x54, 0xad, 0xb5, 0xf5, 0x02, 0xc1, 0x39, 0x6a, 0x2a, 0xd7, 0x46, 0xbf, + 0x3d, 0x39, 0x4e, 0x8e, 0xb1, 0x58, 0xf4, 0x90, 0xa7, 0x08, 0x0e, 0x99, + 0x64, 0x33, 0x3e, 0x1e, 0x09, 0xb7, 0x88, 0xa0, 0x29, 0xb2, 0x0b, 0x5c, + 0x15, 0xd4, 0x36, 0x55, 0x42, 0x48, 0xe7, 0x47, 0xf9, 0xb5, 0x05, 0xcd, + 0x40, 0xde, 0x92, 0x27, 0x11, 0x3b, 0xad, 0x3e, 0x9b, 0x95, 0x38, 0xad, + 0x11, 0xd5, 0x9d, 0x1d, 0x38, 0x60, 0xde, 0x31, 0xe3, 0x40, 0xb2, 0xf2, + 0x8e, 0xb4, 0x03, 0xaa, 0x51, 0x15, 0xe4, 0x36, 0x4d, 0x43, 0x05, 0xbc, + 0x36, 0x82, 0xdf, 0xfc, 0xfd, 0x23, 0x4d, 0xad, 0x9f, 0xf4, 0xce, 0xfb, + 0xaf, 0x46, 0xb3, 0x59, 0x98, 0x91, 0x85, 0x4a, 0xa7, 0x67, 0x70, 0xbd, + 0xca, 0x12, 0x9b, 0x6b, 0x00, 0xe5, 0x82, 0x3c, 0x37, 0x99, 0x8d, 0x6b, + 0x32, 0xaf, 0x08, 0x05, 0x36, 0xd6, 0xd7, 0xfb, 0x65, 0xce, 0x4e, 0x9f, + 0xd5, 0xd1, 0x3a, 0x42, 0xb0, 0x31, 0x62, 0xd0, 0xe2, 0xe5, 0x37, 0xc1, + 0x6d, 0x8a, 0x24, 0xa4, 0x19, 0xc2, 0x59, 0x3c, 0x44, 0xef, 0x96, 0xf6, + 0x35, 0x00, 0xe7, 0xe6, 0x2e,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56, 0xa8, + 0x3b, 0x3b, 0xe4, 0xe5, 0x70, 0x2e, 0xda, 0xde, 0xcd, 0x65, 0x4f, 0x2e, + 0xb6, 0x76, 0x17, 0x59, 0x6a, 0xaf, 0x0a, 0x24, 0x8c, 0x99, 0x0b, 0x2a, + 0xac, 0x46, 0x74, 0x2c, 0x3b, 0x40, 0x20, 0xad, 0x30, 0xab, 0x63, 0x34, + 0x8f, 0x30, 0x22, 0x50, 0x5c, 0xf8, 0x73, 0x21, 0x3e, 0xeb, 0x16, 0x44, + 0x30, 0xb9, 0x59, 0x0f, 0xf0, 0xe5, 0xb6, 0x6a, 0xde, 0x32, 0x03, 0x28, + 0x3c, 0xc8, 0xc2, 0x8d, 0x6b, 0x72, 0x2f, 0x3e, 0x2b, 0x99, 0xc1, 0xa6, + 0xdf, 0x5a, 0x91, 0x2d, 0x40, 0x39, 0xb2, 0x24, 0x27, 0x25, 0x26, 0x51, + 0xbb, 0xb5, 0x6a, 0x47, 0x38, 0x94, 0x2c, 0x3e, 0xa0, 0x96, 0x19, 0xf7, + 0x99, 0x0c, 0x34, 0x41, 0xb9, 0x0d, 0xad, 0x37, 0xa6, 0x0c, 0x38, 0x9c, + 0xee, 0x03, 0x68, 0x62, 0x76, 0x64, 0x18, 0x63, 0x62, 0x10, 0xd6, 0x2a, + 0xca, 0xdb, 0x73, 0x9b, 0x93, 0x35, 0x29, 0xb0, 0xec, 0x6c, 0xa8, 0x1f, + 0xa6, 0xac, 0xf8, 0xd8, 0xfa, 0x98, 0xc3, 0x02, 0xf0, 0xf5, 0x66, 0x2c, + 0xfc, 0x75, 0xc7, 0xb0, 0x76, 0xfe, 0x0f, 0x92, 0x9b, 0xce, 0xc5, 0xe8, + 0x9a, 0x5e, 0x8f, 0x16, 0x26, 0x8c, 0x97, 0x20, 0x97, 0x36, 0xca, 0x56, + 0xed, 0xf2, 0x05, 0x53, 0xf7, 0x9f, 0x23, 0xbb, 0x1e, 0xdc, 0x5a, 0x94, + 0x0b, 0x1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5, 0x4e, 0x5f, 0x2a, + 0xb6, 0x14, 0x5e, 0x2f, 0x16, 0x71, 0x48, 0x59, 0x77, 0x6b, 0xf9, 0x6c, + 0x79, 0xba, 0xc4, 0x26, 0x30, 0x44, 0x61, 0x62, 0x60, 0xef, 0x35, 0x95, + 0xe3, 0x77, 0xd5, 0xc8, 0x44, 0xa4, 0xf8, 0x95, 0xba, 0xd1, 0x73, 0x6f, + 0x92, 0xf2, 0xd3, 0x98, 0x4c, 0x8f, 0xe0, 0x2e, 0x27, 0xaa, 0x2f, 0x63, + 0x00, 0x00, 0x00, 0x00, 0x06, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x80, 0x04, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x26, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, + 0x0e, 0xfe, 0xff, 0xff, 0xbb, 0xfd, 0xff, 0xff, 0xe1, 0x05, 0x00, 0x00, + 0x4b, 0x0f, 0x00, 0x00, 0x8e, 0x15, 0x00, 0x00, 0x7f, 0x04, 0x00, 0x00, + 0x02, 0x02, 0x00, 0x00, 0x53, 0xe6, 0xff, 0xff, 0xa6, 0x04, 0x00, 0x00, + 0xdf, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x66, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, + 0x80, 0x00, 0x00, 0x00, 0x7f, 0xfd, 0xff, 0xff, 0x3e, 0xf8, 0xff, 0xff, + 0xae, 0x03, 0x00, 0x00, 0x5c, 0xfe, 0xff, 0xff, 0x82, 0xfa, 0xff, 0xff, + 0xbd, 0xf8, 0xff, 0xff, 0x04, 0xfe, 0xff, 0xff, 0x8c, 0xfe, 0xff, 0xff, + 0x9b, 0xf8, 0xff, 0xff, 0x51, 0x02, 0x00, 0x00, 0x19, 0xfe, 0xff, 0xff, + 0x54, 0xfe, 0xff, 0xff, 0x8f, 0xff, 0xff, 0xff, 0xe7, 0xfd, 0xff, 0xff, + 0xc2, 0x07, 0x00, 0x00, 0x36, 0x06, 0x00, 0x00, 0x57, 0xfd, 0xff, 0xff, + 0xa3, 0x03, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x79, 0x03, 0x00, 0x00, + 0x9b, 0xf7, 0xff, 0xff, 0xc7, 0x04, 0x00, 0x00, 0xbf, 0x06, 0x00, 0x00, + 0x86, 0xfe, 0xff, 0xff, 0x20, 0xfb, 0xff, 0xff, 0x90, 0xfc, 0xff, 0xff, + 0x16, 0x00, 0x00, 0x00, 0x8e, 0xff, 0xff, 0xff, 0xa0, 0x03, 0x00, 0x00, + 0xc7, 0xff, 0xff, 0xff, 0x51, 0x01, 0x00, 0x00, 0x24, 0xf8, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0xee, 0x01, 0x00, 0x00, + 0xda, 0x02, 0x00, 0x00, 0xa9, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0xc4, 0xfe, 0xff, 0xff, 0xfa, 0xfc, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, + 0x6a, 0xff, 0xff, 0xff, 0x92, 0x02, 0x00, 0x00, 0xa4, 0xff, 0xff, 0xff, + 0xfd, 0xfe, 0xff, 0xff, 0x4e, 0xfd, 0xff, 0xff, 0x87, 0x00, 0x00, 0x00, + 0x19, 0xfe, 0xff, 0xff, 0x17, 0xff, 0xff, 0xff, 0xa0, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xf4, 0xf3, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x04, 0xf4, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x4d, 0x4c, 0x49, 0x52, + 0x20, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x65, 0x64, 0x2e, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, + 0x18, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00, + 0x0e, 0x00, 0x00, 0x00, 0xf8, 0x01, 0x00, 0x00, 0xec, 0x01, 0x00, 0x00, + 0xe0, 0x01, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, + 0x07, 0x00, 0x00, 0x00, 0xa4, 0x01, 0x00, 0x00, 0x4c, 0x01, 0x00, 0x00, + 0xfc, 0x00, 0x00, 0x00, 0xa8, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, + 0x38, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x82, 0xfe, 0xff, 0xff, + 0x05, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x08, 0x00, + 0x0c, 0x00, 0x10, 0x00, 0x07, 0x00, 0x14, 0x00, 0x0e, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x03, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xc8, 0xf4, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x0b, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0xe6, 0xfe, 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0e, 0x00, 0x1a, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, + 0x07, 0x00, 0x14, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, + 0x01, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x07, 0x00, + 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00, 0x0e, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x0a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, + 0xc2, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 0x24, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xb4, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0e, 0x00, 0x14, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, + 0x07, 0x00, 0x10, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x10, 0x00, 0x06, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x07, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x10, 0x00, 0x04, 0x00, + 0x08, 0x00, 0x0c, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x0d, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xb8, 0x0d, 0x00, 0x00, + 0x64, 0x0c, 0x00, 0x00, 0x64, 0x0a, 0x00, 0x00, 0xe8, 0x09, 0x00, 0x00, + 0x9c, 0x09, 0x00, 0x00, 0x20, 0x09, 0x00, 0x00, 0x6c, 0x07, 0x00, 0x00, + 0x78, 0x04, 0x00, 0x00, 0x74, 0x03, 0x00, 0x00, 0x68, 0x02, 0x00, 0x00, + 0xbc, 0x01, 0x00, 0x00, 0x28, 0x01, 0x00, 0x00, 0xa4, 0x00, 0x00, 0x00, + 0x54, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xc8, 0xff, 0xff, 0xff, + 0x28, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x0a, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x00, 0x00, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x0a, 0x00, 0x00, 0x00, 0x14, 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, + 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x63, 0x6f, 0x6e, 0x76, 0x32, 0x64, 0x5f, 0x69, + 0x6e, 0x70, 0x75, 0x74, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x30, 0xf3, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, + 0x6c, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff, 0x0a, 0x00, 0x00, 0x00, 0x14, 0xf3, 0xff, 0xff, + 0x2c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x13, 0xc2, 0x47, 0x3b, + 0x01, 0x00, 0x00, 0x00, 0x8d, 0xf4, 0xad, 0x3e, 0x01, 0x00, 0x00, 0x00, + 0x15, 0x00, 0xe0, 0xbe, 0x0d, 0x00, 0x00, 0x00, 0x49, 0x64, 0x65, 0x6e, + 0x74, 0x69, 0x74, 0x79, 0x5f, 0x69, 0x6e, 0x74, 0x38, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, + 0xb0, 0xf3, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, 0x7c, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, + 0x80, 0x04, 0x00, 0x00, 0x94, 0xf3, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x6c, 0x02, 0xa5, 0x3a, + 0x01, 0x00, 0x00, 0x00, 0x6a, 0x5d, 0xa4, 0x3e, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x73, 0x65, 0x71, 0x75, + 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x66, 0x6c, 0x61, 0x74, 0x74, + 0x65, 0x6e, 0x2f, 0x52, 0x65, 0x73, 0x68, 0x61, 0x70, 0x65, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, + 0x40, 0xf4, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, 0x8c, 0x00, 0x00, 0x00, + 0x0b, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, + 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x2c, 0xf4, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x6c, 0x02, 0xa5, 0x3a, 0x01, 0x00, 0x00, 0x00, + 0x6a, 0x5d, 0xa4, 0x3e, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, + 0x61, 0x6c, 0x2f, 0x6d, 0x61, 0x78, 0x5f, 0x70, 0x6f, 0x6f, 0x6c, 0x69, + 0x6e, 0x67, 0x32, 0x64, 0x2f, 0x4d, 0x61, 0x78, 0x50, 0x6f, 0x6f, 0x6c, + 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0xe8, 0xf4, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, 0xec, 0x00, 0x00, 0x00, + 0x0a, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, + 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0xd4, 0xf4, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x6c, 0x02, 0xa5, 0x3a, 0x01, 0x00, 0x00, 0x00, + 0x6a, 0x5d, 0xa4, 0x3e, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x83, 0x00, 0x00, 0x00, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, + 0x61, 0x6c, 0x2f, 0x63, 0x6f, 0x6e, 0x76, 0x32, 0x64, 0x5f, 0x31, 0x2f, + 0x52, 0x65, 0x6c, 0x75, 0x3b, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, + 0x69, 0x61, 0x6c, 0x2f, 0x63, 0x6f, 0x6e, 0x76, 0x32, 0x64, 0x5f, 0x31, + 0x2f, 0x42, 0x69, 0x61, 0x73, 0x41, 0x64, 0x64, 0x3b, 0x73, 0x65, 0x71, + 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x63, 0x6f, 0x6e, 0x76, + 0x32, 0x64, 0x5f, 0x31, 0x2f, 0x43, 0x6f, 0x6e, 0x76, 0x32, 0x44, 0x3b, + 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x63, + 0x6f, 0x6e, 0x76, 0x32, 0x64, 0x5f, 0x31, 0x2f, 0x42, 0x69, 0x61, 0x73, + 0x41, 0x64, 0x64, 0x2f, 0x52, 0x65, 0x61, 0x64, 0x56, 0x61, 0x72, 0x69, + 0x61, 0x62, 0x6c, 0x65, 0x4f, 0x70, 0x2f, 0x72, 0x65, 0x73, 0x6f, 0x75, + 0x72, 0x63, 0x65, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0xf0, 0xf5, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, 0xe4, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, + 0x0e, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0xdc, 0xf5, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x15, 0xa1, 0x10, 0x3b, 0x01, 0x00, 0x00, 0x00, + 0x74, 0x10, 0x10, 0x3f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7b, 0x00, 0x00, 0x00, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, + 0x61, 0x6c, 0x2f, 0x63, 0x6f, 0x6e, 0x76, 0x32, 0x64, 0x2f, 0x52, 0x65, + 0x6c, 0x75, 0x3b, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, + 0x6c, 0x2f, 0x63, 0x6f, 0x6e, 0x76, 0x32, 0x64, 0x2f, 0x42, 0x69, 0x61, + 0x73, 0x41, 0x64, 0x64, 0x3b, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, + 0x69, 0x61, 0x6c, 0x2f, 0x63, 0x6f, 0x6e, 0x76, 0x32, 0x64, 0x2f, 0x43, + 0x6f, 0x6e, 0x76, 0x32, 0x44, 0x3b, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, + 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x63, 0x6f, 0x6e, 0x76, 0x32, 0x64, 0x2f, + 0x42, 0x69, 0x61, 0x73, 0x41, 0x64, 0x64, 0x2f, 0x52, 0x65, 0x61, 0x64, + 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x4f, 0x70, 0x2f, 0x72, + 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x3a, 0xf8, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, + 0xd4, 0x02, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0xac, 0x02, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xc4, 0xf6, 0xff, 0xff, 0x1c, 0x02, 0x00, 0x00, + 0x94, 0x01, 0x00, 0x00, 0x0c, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0xb9, 0x37, 0x74, 0x3a, 0x8b, 0xfe, 0x77, 0x3a, 0x54, 0xc7, 0x75, 0x3a, + 0xc4, 0x11, 0x78, 0x3a, 0xb9, 0x90, 0x74, 0x3a, 0x3b, 0x97, 0x7b, 0x3a, + 0xe8, 0x57, 0x75, 0x3a, 0x0c, 0x0e, 0x74, 0x3a, 0x76, 0x8b, 0x79, 0x3a, + 0x2b, 0x7b, 0x6d, 0x3a, 0x17, 0xad, 0x71, 0x3a, 0xe4, 0x9b, 0x77, 0x3a, + 0x0b, 0xab, 0x7a, 0x3a, 0x9e, 0x12, 0x75, 0x3a, 0x8c, 0xcf, 0x79, 0x3a, + 0xa0, 0x5a, 0x79, 0x3a, 0x74, 0xc3, 0x78, 0x3a, 0x0e, 0xa9, 0x74, 0x3a, + 0x6b, 0xf8, 0x6f, 0x3a, 0x53, 0xeb,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, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x2a, 0xfb, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, 0x94, 0x01, 0x00, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x6c, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xb4, 0xf9, 0xff, 0xff, 0x1c, 0x01, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00, + 0x8c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0xe6, 0x69, 0xc5, 0x3a, 0xa0, 0x8d, 0xa8, 0x3a, 0xfe, 0x5c, 0xc1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xaa, 0x48, 0xbe, + 0xde, 0x61, 0x44, 0xbe, 0xa9, 0x1c, 0x40, 0xbe, 0x18, 0x00, 0x00, 0x00, + 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x63, + 0x6f, 0x6e, 0x76, 0x32, 0x64, 0x2f, 0x43, 0x6f, 0x6e, 0x76, 0x32, 0x44, + 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0xda, 0xfc, 0xff, 0xff, 0x00, 0x00, 0x00, 0x09, 0x64, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x64, 0xfb, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x07, 0x72, 0x1e, 0x3a, 0x01, 0x00, 0x00, 0x00, 0x32, 0xe2, 0x9b, 0x3d, + 0x01, 0x00, 0x00, 0x00, 0x23, 0x35, 0x9d, 0xbd, 0x17, 0x00, 0x00, 0x00, + 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x64, + 0x65, 0x6e, 0x73, 0x65, 0x2f, 0x4d, 0x61, 0x74, 0x4d, 0x75, 0x6c, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, + 0x52, 0xfd, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, 0x38, 0x00, 0x00, 0x00, + 0x05, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x66, + 0x6c, 0x61, 0x74, 0x74, 0x65, 0x6e, 0x2f, 0x43, 0x6f, 0x6e, 0x73, 0x74, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x9a, 0xfd, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, 0x68, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x8c, 0xfd, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xfc, 0x41, 0x4c, 0x35, 0x30, 0x00, 0x00, 0x00, + 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x64, + 0x65, 0x6e, 0x73, 0x65, 0x2f, 0x42, 0x69, 0x61, 0x73, 0x41, 0x64, 0x64, + 0x2f, 0x52, 0x65, 0x61, 0x64, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, + 0x65, 0x4f, 0x70, 0x2f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, + 0x12, 0xfe, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, 0xdc, 0x01, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x9c, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x04, 0xfe, 0xff, 0xff, 0x0c, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x03, 0xf9, 0x09, 0x36, 0x3a, 0x1b, 0x0c, 0x36, 0xc6, 0xda, 0x0a, 0x36, + 0x16, 0x26, 0x0c, 0x36, 0x4b, 0x2b, 0x0a, 0x36, 0x60, 0x23, 0x0e, 0x36, + 0xd3, 0x9b, 0x0a, 0x36, 0x78, 0xe1, 0x09, 0x36, 0x78, 0xfb, 0x0c, 0x36, + 0xb6, 0x2a, 0x06, 0x36, 0x6f, 0x89, 0x08, 0x36, 0x7e, 0xe3, 0x0b, 0x36, + 0xf0, 0x9d, 0x0d, 0x36, 0xae, 0x74, 0x0a, 0x36, 0xef, 0x21, 0x0d, 0x36, + 0xe0, 0xdf, 0x0c, 0x36, 0x79, 0x8a, 0x0c, 0x36, 0x0a, 0x39, 0x0a, 0x36, + 0xbb, 0x92, 0x07, 0x36, 0x39, 0x3d, 0x09, 0x36, 0x25, 0xc9, 0x09, 0x36, + 0xd1, 0x3b, 0x0c, 0x36, 0x93, 0x54, 0x0b, 0x36, 0x9a, 0x4f, 0x06, 0x36, + 0x3c, 0xb2, 0x08, 0x36, 0x23, 0x4b, 0x0a, 0x36, 0xbe, 0x0e, 0x05, 0x36, + 0x83, 0x8b, 0x0c, 0x36, 0xc7, 0x6b, 0x0a, 0x36, 0x07, 0x91, 0x0c, 0x36, + 0x5d, 0x8e, 0x0a, 0x36, 0x7f, 0x2a, 0x09, 0x36, 0x33, 0x00, 0x00, 0x00, + 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x63, + 0x6f, 0x6e, 0x76, 0x32, 0x64, 0x5f, 0x31, 0x2f, 0x42, 0x69, 0x61, 0x73, + 0x41, 0x64, 0x64, 0x2f, 0x52, 0x65, 0x61, 0x64, 0x56, 0x61, 0x72, 0x69, + 0x61, 0x62, 0x6c, 0x65, 0x4f, 0x70, 0x2f, 0x72, 0x65, 0x73, 0x6f, 0x75, + 0x72, 0x63, 0x65, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0e, 0x00, 0x18, 0x00, 0x08, 0x00, 0x07, 0x00, 0x0c, 0x00, + 0x10, 0x00, 0x14, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x2c, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xec, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0xe1, 0x22, 0xc6, 0x36, 0x90, 0x2b, 0xa9, 0x36, 0x2d, 0x12, 0xc2, 0x36, + 0xbc, 0xbf, 0xcb, 0x36, 0xf2, 0x6c, 0xb6, 0x36, 0x19, 0xc5, 0xd1, 0x36, + 0xff, 0xc0, 0xcc, 0x36, 0x62, 0x93, 0xc8, 0x36, 0x4c, 0x1a, 0xa5, 0x36, + 0x05, 0xd8, 0xbe, 0x36, 0x49, 0x27, 0xc5, 0x36, 0xf5, 0x2a, 0xcc, 0x36, + 0x8a, 0xc0, 0xc2, 0x36, 0xf5, 0xfc, 0xca, 0x36, 0x2f, 0xa7, 0xc6, 0x36, + 0x57, 0x55, 0xc2, 0x36, 0x31, 0x00, 0x00, 0x00, 0x73, 0x65, 0x71, 0x75, + 0x65, 0x6e, 0x74, 0x69, 0x61, 0x6c, 0x2f, 0x63, 0x6f, 0x6e, 0x76, 0x32, + 0x64, 0x2f, 0x42, 0x69, 0x61, 0x73, 0x41, 0x64, 0x64, 0x2f, 0x52, 0x65, + 0x61, 0x64, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6c, 0x65, 0x4f, 0x70, + 0x2f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x1c, 0x00, + 0x08, 0x00, 0x07, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x18, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, + 0x88, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00, + 0x28, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x14, 0x00, 0x04, 0x00, 0x08, 0x00, + 0x0c, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xf0, 0x77, 0x80, 0x3b, + 0x01, 0x00, 0x00, 0x00, 0xf0, 0xee, 0x7f, 0x3f, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x63, 0x6f, 0x6e, 0x76, + 0x32, 0x64, 0x5f, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x5f, 0x69, 0x6e, 0x74, + 0x38, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0xca, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x06, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x07, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0xe6, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x09, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, + 0x06, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x16, 0x0a, 0x00, + 0x0e, 0x00, 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0a, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x11, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, + 0x0c, 0x00, 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0a, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00 +}; + +const unsigned int kTestConvModelDataSize = 21344; diff --git a/components/tflite/tensorflow/lite/micro/testing/test_conv_model.h b/components/tflite/tensorflow/lite/micro/testing/test_conv_model.h new file mode 100644 index 00000000..d8def7de --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/testing/test_conv_model.h @@ -0,0 +1,23 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_MICRO_TESTING_TEST_CONV_MODEL_H_ +#define TENSORFLOW_LITE_MICRO_TESTING_TEST_CONV_MODEL_H_ + +// See generate_test_models.py for updating the contents of this model: +extern const unsigned char kTestConvModelData[]; +extern const unsigned int kTestConvModelDataSize; + +#endif // TENSORFLOW_LITE_MICRO_TESTING_TEST_CONV_MODEL_H_ diff --git a/components/tflite/tensorflow/lite/micro/testing/util_test.cc b/components/tflite/tensorflow/lite/micro/testing/util_test.cc new file mode 100644 index 00000000..1af169b6 --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/testing/util_test.cc @@ -0,0 +1,30 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/testing/micro_test.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(ArgumentsExecutedOnlyOnce) +{ + float count = 0.; + // Make sure either argument is executed once after macro expansion. + TF_LITE_MICRO_EXPECT_NEAR(0, count++, 0.1f); + TF_LITE_MICRO_EXPECT_NEAR(1, count++, 0.1f); + TF_LITE_MICRO_EXPECT_NEAR(count++, 2, 0.1f); + TF_LITE_MICRO_EXPECT_NEAR(count++, 3, 0.1f); +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/micro/testing_helpers_test.cc b/components/tflite/tensorflow/lite/micro/testing_helpers_test.cc new file mode 100644 index 00000000..5ee62ccd --- /dev/null +++ b/components/tflite/tensorflow/lite/micro/testing_helpers_test.cc @@ -0,0 +1,109 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/micro/test_helpers.h" +#include "tensorflow/lite/micro/testing/micro_test.h" + +TF_LITE_MICRO_TESTS_BEGIN + +TF_LITE_MICRO_TEST(CreateQuantizedBiasTensor) +{ + float input_scale = 0.5; + float weight_scale = 0.5; + constexpr int tensor_size = 12; + int dims_arr[] = { 4, 2, 3, 2, 1 }; + int32_t quantized[tensor_size]; + float pre_quantized[] = { -10, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 10 }; + int32_t expected_quantized_values[] = { -40, -20, -16, -12, -8, -4, + 0, 4, 8, 12, 16, 40 }; + TfLiteIntArray *dims = tflite::testing::IntArrayFromInts(dims_arr); + + TfLiteTensor result = tflite::testing::CreateQuantizedBiasTensor( + pre_quantized, quantized, dims, input_scale, weight_scale); + + TF_LITE_MICRO_EXPECT_EQ(result.bytes, tensor_size * sizeof(int32_t)); + TF_LITE_MICRO_EXPECT(result.dims == dims); + TF_LITE_MICRO_EXPECT_EQ(result.params.scale, input_scale * weight_scale); + for (int i = 0; i < tensor_size; i++) { + TF_LITE_MICRO_EXPECT_EQ(expected_quantized_values[i], result.data.i32[i]); + } +} + +TF_LITE_MICRO_TEST(CreatePerChannelQuantizedBiasTensor) +{ + float input_scale = 0.5; + float weight_scales[] = { 0.5, 1, 2, 4 }; + constexpr int tensor_size = 12; + const int channels = 4; + int dims_arr[] = { 4, 4, 3, 1, 1 }; + int32_t quantized[tensor_size]; + float scales[channels + 1]; + int zero_points[] = { 4, 0, 0, 0, 0 }; + float pre_quantized[] = { -10, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 10 }; + int32_t expected_quantized_values[] = { -40, -20, -16, -6, -4, -2, + 0, 1, 2, 2, 2, 5 }; + TfLiteIntArray *dims = tflite::testing::IntArrayFromInts(dims_arr); + + TfLiteAffineQuantization quant; + TfLiteTensor result = tflite::testing::CreatePerChannelQuantizedBiasTensor( + pre_quantized, quantized, dims, input_scale, weight_scales, scales, + zero_points, &quant, 0); + + // Values in scales array start at index 1 since index 0 is dedicated to + // tracking the tensor size. + for (int i = 0; i < channels; i++) { + TF_LITE_MICRO_EXPECT_EQ(scales[i + 1], input_scale * weight_scales[i]); + } + + TF_LITE_MICRO_EXPECT_EQ(result.bytes, tensor_size * sizeof(int32_t)); + TF_LITE_MICRO_EXPECT(result.dims == dims); + for (int i = 0; i < tensor_size; i++) { + TF_LITE_MICRO_EXPECT_EQ(expected_quantized_values[i], result.data.i32[i]); + } +} + +TF_LITE_MICRO_TEST(CreateSymmetricPerChannelQuantizedTensor) +{ + const int tensor_size = 12; + constexpr int channels = 2; + int dims_arr[] = { 4, channels, 3, 2, 1 }; + int8_t quantized[12]; + const float pre_quantized[] = { -127, -55, -4, -3, -2, -1, + 0, 1, 2, 3, 4, 63.5 }; + const int8_t expected_quantized_values[] = { -127, -55, -4, -3, -2, -1, + 0, 2, 4, 6, 8, 127 }; + float expected_scales[] = { 1.0, 0.5 }; + TfLiteIntArray *dims = tflite::testing::IntArrayFromInts(dims_arr); + + int zero_points[channels + 1]; + float scales[channels + 1]; + TfLiteAffineQuantization quant; + TfLiteTensor result = + tflite::testing::CreateSymmetricPerChannelQuantizedTensor( + pre_quantized, quantized, dims, scales, zero_points, &quant, 0); + + TF_LITE_MICRO_EXPECT_EQ(result.bytes, tensor_size * sizeof(int8_t)); + TF_LITE_MICRO_EXPECT(result.dims == dims); + TfLiteFloatArray *result_scales = + static_cast(result.quantization.params)->scale; + for (int i = 0; i < channels; i++) { + TF_LITE_MICRO_EXPECT_EQ(result_scales->data[i], expected_scales[i]); + } + for (int i = 0; i < tensor_size; i++) { + TF_LITE_MICRO_EXPECT_EQ(expected_quantized_values[i], result.data.int8[i]); + } +} + +TF_LITE_MICRO_TESTS_END diff --git a/components/tflite/tensorflow/lite/portable_type_to_tflitetype.h b/components/tflite/tensorflow/lite/portable_type_to_tflitetype.h new file mode 100644 index 00000000..a63cbc1a --- /dev/null +++ b/components/tflite/tensorflow/lite/portable_type_to_tflitetype.h @@ -0,0 +1,76 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_PORTABLE_TYPE_TO_TFLITETYPE_H_ +#define TENSORFLOW_LITE_PORTABLE_TYPE_TO_TFLITETYPE_H_ + +// Most of the definitions have been moved to this subheader so that Micro +// can include it without relying on and , which isn't +// available on all platforms. + +// Arduino build defines abs as a macro here. That is invalid C++, and breaks +// libc++'s header, undefine it. +#ifdef abs +#undef abs +#endif + +#include + +#include "tensorflow/lite/c/common.h" + +namespace tflite { +// Map statically from a C++ type to a TfLiteType. Used in interpreter for +// safe casts. +// Example: +// typeToTfLiteType() -> kTfLiteBool +template +constexpr TfLiteType typeToTfLiteType() +{ + return kTfLiteNoType; +} +// Map from TfLiteType to the corresponding C++ type. +// Example: +// TfLiteTypeToType::Type -> bool +template +struct TfLiteTypeToType { +}; // Specializations below + +// Template specialization for both typeToTfLiteType and TfLiteTypeToType. +#define MATCH_TYPE_AND_TFLITE_TYPE(CPP_TYPE, TFLITE_TYPE_ENUM) \ + template <> \ + constexpr TfLiteType typeToTfLiteType() \ + { \ + return TFLITE_TYPE_ENUM; \ + } \ + template <> \ + struct TfLiteTypeToType { \ + using Type = CPP_TYPE; \ + } + +// No string mapping is included here, since the TF Lite packed representation +// doesn't correspond to a C++ type well. +MATCH_TYPE_AND_TFLITE_TYPE(int32_t, kTfLiteInt32); +MATCH_TYPE_AND_TFLITE_TYPE(uint32_t, kTfLiteUInt32); +MATCH_TYPE_AND_TFLITE_TYPE(int16_t, kTfLiteInt16); +MATCH_TYPE_AND_TFLITE_TYPE(int64_t, kTfLiteInt64); +MATCH_TYPE_AND_TFLITE_TYPE(float, kTfLiteFloat32); +MATCH_TYPE_AND_TFLITE_TYPE(unsigned char, kTfLiteUInt8); +MATCH_TYPE_AND_TFLITE_TYPE(int8_t, kTfLiteInt8); +MATCH_TYPE_AND_TFLITE_TYPE(bool, kTfLiteBool); +MATCH_TYPE_AND_TFLITE_TYPE(TfLiteFloat16, kTfLiteFloat16); +MATCH_TYPE_AND_TFLITE_TYPE(double, kTfLiteFloat64); +MATCH_TYPE_AND_TFLITE_TYPE(uint64_t, kTfLiteUInt64); + +} // namespace tflite +#endif // TENSORFLOW_LITE_PORTABLE_TYPE_TO_TFLITETYPE_H_ diff --git a/components/tflite/tensorflow/lite/schema/schema_generated.h b/components/tflite/tensorflow/lite/schema/schema_generated.h new file mode 100644 index 00000000..6345445d --- /dev/null +++ b/components/tflite/tensorflow/lite/schema/schema_generated.h @@ -0,0 +1,21963 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +// automatically generated by the FlatBuffers compiler, do not modify + +#ifndef FLATBUFFERS_GENERATED_SCHEMA_TFLITE_H_ +#define FLATBUFFERS_GENERATED_SCHEMA_TFLITE_H_ + +#include "flatbuffers/flatbuffers.h" + +namespace tflite { +struct CustomQuantization; +struct CustomQuantizationT; + +struct QuantizationParameters; +struct QuantizationParametersT; + +struct Int32Vector; +struct Int32VectorT; + +struct Uint16Vector; +struct Uint16VectorT; + +struct Uint8Vector; +struct Uint8VectorT; + +struct DimensionMetadata; +struct DimensionMetadataT; + +struct SparsityParameters; +struct SparsityParametersT; + +struct Tensor; +struct TensorT; + +struct Conv2DOptions; +struct Conv2DOptionsT; + +struct Conv3DOptions; +struct Conv3DOptionsT; + +struct Pool2DOptions; +struct Pool2DOptionsT; + +struct DepthwiseConv2DOptions; +struct DepthwiseConv2DOptionsT; + +struct ConcatEmbeddingsOptions; +struct ConcatEmbeddingsOptionsT; + +struct LSHProjectionOptions; +struct LSHProjectionOptionsT; + +struct SVDFOptions; +struct SVDFOptionsT; + +struct RNNOptions; +struct RNNOptionsT; + +struct SequenceRNNOptions; +struct SequenceRNNOptionsT; + +struct BidirectionalSequenceRNNOptions; +struct BidirectionalSequenceRNNOptionsT; + +struct FullyConnectedOptions; +struct FullyConnectedOptionsT; + +struct SoftmaxOptions; +struct SoftmaxOptionsT; + +struct ConcatenationOptions; +struct ConcatenationOptionsT; + +struct AddOptions; +struct AddOptionsT; + +struct MulOptions; +struct MulOptionsT; + +struct L2NormOptions; +struct L2NormOptionsT; + +struct LocalResponseNormalizationOptions; +struct LocalResponseNormalizationOptionsT; + +struct LSTMOptions; +struct LSTMOptionsT; + +struct UnidirectionalSequenceLSTMOptions; +struct UnidirectionalSequenceLSTMOptionsT; + +struct BidirectionalSequenceLSTMOptions; +struct BidirectionalSequenceLSTMOptionsT; + +struct ResizeBilinearOptions; +struct ResizeBilinearOptionsT; + +struct ResizeNearestNeighborOptions; +struct ResizeNearestNeighborOptionsT; + +struct CallOptions; +struct CallOptionsT; + +struct PadOptions; +struct PadOptionsT; + +struct PadV2Options; +struct PadV2OptionsT; + +struct ReshapeOptions; +struct ReshapeOptionsT; + +struct SpaceToBatchNDOptions; +struct SpaceToBatchNDOptionsT; + +struct BatchToSpaceNDOptions; +struct BatchToSpaceNDOptionsT; + +struct SkipGramOptions; +struct SkipGramOptionsT; + +struct SpaceToDepthOptions; +struct SpaceToDepthOptionsT; + +struct DepthToSpaceOptions; +struct DepthToSpaceOptionsT; + +struct SubOptions; +struct SubOptionsT; + +struct DivOptions; +struct DivOptionsT; + +struct TopKV2Options; +struct TopKV2OptionsT; + +struct EmbeddingLookupSparseOptions; +struct EmbeddingLookupSparseOptionsT; + +struct GatherOptions; +struct GatherOptionsT; + +struct TransposeOptions; +struct TransposeOptionsT; + +struct ExpOptions; +struct ExpOptionsT; + +struct CosOptions; +struct CosOptionsT; + +struct ReducerOptions; +struct ReducerOptionsT; + +struct SqueezeOptions; +struct SqueezeOptionsT; + +struct SplitOptions; +struct SplitOptionsT; + +struct SplitVOptions; +struct SplitVOptionsT; + +struct StridedSliceOptions; +struct StridedSliceOptionsT; + +struct LogSoftmaxOptions; +struct LogSoftmaxOptionsT; + +struct CastOptions; +struct CastOptionsT; + +struct DequantizeOptions; +struct DequantizeOptionsT; + +struct MaximumMinimumOptions; +struct MaximumMinimumOptionsT; + +struct TileOptions; +struct TileOptionsT; + +struct ArgMaxOptions; +struct ArgMaxOptionsT; + +struct ArgMinOptions; +struct ArgMinOptionsT; + +struct GreaterOptions; +struct GreaterOptionsT; + +struct GreaterEqualOptions; +struct GreaterEqualOptionsT; + +struct LessOptions; +struct LessOptionsT; + +struct LessEqualOptions; +struct LessEqualOptionsT; + +struct NegOptions; +struct NegOptionsT; + +struct SelectOptions; +struct SelectOptionsT; + +struct SliceOptions; +struct SliceOptionsT; + +struct TransposeConvOptions; +struct TransposeConvOptionsT; + +struct ExpandDimsOptions; +struct ExpandDimsOptionsT; + +struct SparseToDenseOptions; +struct SparseToDenseOptionsT; + +struct EqualOptions; +struct EqualOptionsT; + +struct NotEqualOptions; +struct NotEqualOptionsT; + +struct ShapeOptions; +struct ShapeOptionsT; + +struct RankOptions; +struct RankOptionsT; + +struct PowOptions; +struct PowOptionsT; + +struct FakeQuantOptions; +struct FakeQuantOptionsT; + +struct PackOptions; +struct PackOptionsT; + +struct LogicalOrOptions; +struct LogicalOrOptionsT; + +struct OneHotOptions; +struct OneHotOptionsT; + +struct AbsOptions; +struct AbsOptionsT; + +struct HardSwishOptions; +struct HardSwishOptionsT; + +struct LogicalAndOptions; +struct LogicalAndOptionsT; + +struct LogicalNotOptions; +struct LogicalNotOptionsT; + +struct UnpackOptions; +struct UnpackOptionsT; + +struct FloorDivOptions; +struct FloorDivOptionsT; + +struct SquareOptions; +struct SquareOptionsT; + +struct ZerosLikeOptions; +struct ZerosLikeOptionsT; + +struct FillOptions; +struct FillOptionsT; + +struct FloorModOptions; +struct FloorModOptionsT; + +struct RangeOptions; +struct RangeOptionsT; + +struct LeakyReluOptions; +struct LeakyReluOptionsT; + +struct SquaredDifferenceOptions; +struct SquaredDifferenceOptionsT; + +struct MirrorPadOptions; +struct MirrorPadOptionsT; + +struct UniqueOptions; +struct UniqueOptionsT; + +struct ReverseV2Options; +struct ReverseV2OptionsT; + +struct AddNOptions; +struct AddNOptionsT; + +struct GatherNdOptions; +struct GatherNdOptionsT; + +struct WhereOptions; +struct WhereOptionsT; + +struct ReverseSequenceOptions; +struct ReverseSequenceOptionsT; + +struct MatrixDiagOptions; +struct MatrixDiagOptionsT; + +struct QuantizeOptions; +struct QuantizeOptionsT; + +struct MatrixSetDiagOptions; +struct MatrixSetDiagOptionsT; + +struct IfOptions; +struct IfOptionsT; + +struct CallOnceOptions; +struct CallOnceOptionsT; + +struct WhileOptions; +struct WhileOptionsT; + +struct NonMaxSuppressionV4Options; +struct NonMaxSuppressionV4OptionsT; + +struct NonMaxSuppressionV5Options; +struct NonMaxSuppressionV5OptionsT; + +struct ScatterNdOptions; +struct ScatterNdOptionsT; + +struct SelectV2Options; +struct SelectV2OptionsT; + +struct DensifyOptions; +struct DensifyOptionsT; + +struct SegmentSumOptions; +struct SegmentSumOptionsT; + +struct BatchMatMulOptions; +struct BatchMatMulOptionsT; + +struct CumsumOptions; +struct CumsumOptionsT; + +struct BroadcastToOptions; +struct BroadcastToOptionsT; + +struct Rfft2dOptions; +struct Rfft2dOptionsT; + +struct HashtableOptions; +struct HashtableOptionsT; + +struct HashtableFindOptions; +struct HashtableFindOptionsT; + +struct HashtableImportOptions; +struct HashtableImportOptionsT; + +struct HashtableSizeOptions; +struct HashtableSizeOptionsT; + +struct OperatorCode; +struct OperatorCodeT; + +struct Operator; +struct OperatorT; + +struct SubGraph; +struct SubGraphT; + +struct Buffer; +struct BufferT; + +struct Metadata; +struct MetadataT; + +struct TensorMap; +struct TensorMapT; + +struct SignatureDef; +struct SignatureDefT; + +struct Model; +struct ModelT; + +enum TensorType { + TensorType_FLOAT32 = 0, + TensorType_FLOAT16 = 1, + TensorType_INT32 = 2, + TensorType_UINT8 = 3, + TensorType_INT64 = 4, + TensorType_STRING = 5, + TensorType_BOOL = 6, + TensorType_INT16 = 7, + TensorType_COMPLEX64 = 8, + TensorType_INT8 = 9, + TensorType_FLOAT64 = 10, + TensorType_COMPLEX128 = 11, + TensorType_UINT64 = 12, + TensorType_RESOURCE = 13, + TensorType_VARIANT = 14, + TensorType_UINT32 = 15, + TensorType_MIN = TensorType_FLOAT32, + TensorType_MAX = TensorType_UINT32 +}; + +inline const TensorType (&EnumValuesTensorType())[16] +{ + static const TensorType values[] = { + TensorType_FLOAT32, + TensorType_FLOAT16, + TensorType_INT32, + TensorType_UINT8, + TensorType_INT64, + TensorType_STRING, + TensorType_BOOL, + TensorType_INT16, + TensorType_COMPLEX64, + TensorType_INT8, + TensorType_FLOAT64, + TensorType_COMPLEX128, + TensorType_UINT64, + TensorType_RESOURCE, + TensorType_VARIANT, + TensorType_UINT32 + }; + return values; +} + +inline const char *const *EnumNamesTensorType() +{ + static const char *const names[17] = { + "FLOAT32", + "FLOAT16", + "INT32", + "UINT8", + "INT64", + "STRING", + "BOOL", + "INT16", + "COMPLEX64", + "INT8", + "FLOAT64", + "COMPLEX128", + "UINT64", + "RESOURCE", + "VARIANT", + "UINT32", + nullptr + }; + return names; +} + +inline const char *EnumNameTensorType(TensorType e) +{ + if (flatbuffers::IsOutRange(e, TensorType_FLOAT32, TensorType_UINT32)) + return ""; + const size_t index = static_cast(e); + return EnumNamesTensorType()[index]; +} + +enum QuantizationDetails { + QuantizationDetails_NONE = 0, + QuantizationDetails_CustomQuantization = 1, + QuantizationDetails_MIN = QuantizationDetails_NONE, + QuantizationDetails_MAX = QuantizationDetails_CustomQuantization +}; + +inline const QuantizationDetails (&EnumValuesQuantizationDetails())[2] +{ + static const QuantizationDetails values[] = { + QuantizationDetails_NONE, + QuantizationDetails_CustomQuantization + }; + return values; +} + +inline const char *const *EnumNamesQuantizationDetails() +{ + static const char *const names[3] = { + "NONE", + "CustomQuantization", + nullptr + }; + return names; +} + +inline const char *EnumNameQuantizationDetails(QuantizationDetails e) +{ + if (flatbuffers::IsOutRange(e, QuantizationDetails_NONE, QuantizationDetails_CustomQuantization)) + return ""; + const size_t index = static_cast(e); + return EnumNamesQuantizationDetails()[index]; +} + +template +struct QuantizationDetailsTraits { + static const QuantizationDetails enum_value = QuantizationDetails_NONE; +}; + +template <> +struct QuantizationDetailsTraits { + static const QuantizationDetails enum_value = QuantizationDetails_CustomQuantization; +}; + +struct QuantizationDetailsUnion { + QuantizationDetails type; + void *value; + + QuantizationDetailsUnion() + : type(QuantizationDetails_NONE), value(nullptr) + { + } + QuantizationDetailsUnion(QuantizationDetailsUnion &&u) FLATBUFFERS_NOEXCEPT : type(QuantizationDetails_NONE), value(nullptr) + { + std::swap(type, u.type); + std::swap(value, u.value); + } + QuantizationDetailsUnion(const QuantizationDetailsUnion &) FLATBUFFERS_NOEXCEPT; + QuantizationDetailsUnion &operator=(const QuantizationDetailsUnion &u) FLATBUFFERS_NOEXCEPT + { + QuantizationDetailsUnion t(u); + std::swap(type, t.type); + std::swap(value, t.value); + return *this; + } + QuantizationDetailsUnion &operator=(QuantizationDetailsUnion &&u) FLATBUFFERS_NOEXCEPT + { + std::swap(type, u.type); + std::swap(value, u.value); + return *this; + } + ~QuantizationDetailsUnion() + { + Reset(); + } + + void Reset(); + +#ifndef FLATBUFFERS_CPP98_STL + template + void Set(T &&val) + { + using RT = typename std::remove_reference::type; + Reset(); + type = QuantizationDetailsTraits::enum_value; + if (type != QuantizationDetails_NONE) { + value = new RT(std::forward(val)); + } + } +#endif // FLATBUFFERS_CPP98_STL + + static void *UnPack(const void *obj, QuantizationDetails type, const flatbuffers::resolver_function_t *resolver); + flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher = nullptr) const; + + tflite::CustomQuantizationT *AsCustomQuantization() + { + return type == QuantizationDetails_CustomQuantization ? + reinterpret_cast(value) : + nullptr; + } + const tflite::CustomQuantizationT *AsCustomQuantization() const + { + return type == QuantizationDetails_CustomQuantization ? + reinterpret_cast(value) : + nullptr; + } +}; + +bool VerifyQuantizationDetails(flatbuffers::Verifier &verifier, const void *obj, QuantizationDetails type); +bool VerifyQuantizationDetailsVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector > *values, const flatbuffers::Vector *types); + +enum DimensionType { + DimensionType_DENSE = 0, + DimensionType_SPARSE_CSR = 1, + DimensionType_MIN = DimensionType_DENSE, + DimensionType_MAX = DimensionType_SPARSE_CSR +}; + +inline const DimensionType (&EnumValuesDimensionType())[2] +{ + static const DimensionType values[] = { + DimensionType_DENSE, + DimensionType_SPARSE_CSR + }; + return values; +} + +inline const char *const *EnumNamesDimensionType() +{ + static const char *const names[3] = { + "DENSE", + "SPARSE_CSR", + nullptr + }; + return names; +} + +inline const char *EnumNameDimensionType(DimensionType e) +{ + if (flatbuffers::IsOutRange(e, DimensionType_DENSE, DimensionType_SPARSE_CSR)) + return ""; + const size_t index = static_cast(e); + return EnumNamesDimensionType()[index]; +} + +enum SparseIndexVector { + SparseIndexVector_NONE = 0, + SparseIndexVector_Int32Vector = 1, + SparseIndexVector_Uint16Vector = 2, + SparseIndexVector_Uint8Vector = 3, + SparseIndexVector_MIN = SparseIndexVector_NONE, + SparseIndexVector_MAX = SparseIndexVector_Uint8Vector +}; + +inline const SparseIndexVector (&EnumValuesSparseIndexVector())[4] +{ + static const SparseIndexVector values[] = { + SparseIndexVector_NONE, + SparseIndexVector_Int32Vector, + SparseIndexVector_Uint16Vector, + SparseIndexVector_Uint8Vector + }; + return values; +} + +inline const char *const *EnumNamesSparseIndexVector() +{ + static const char *const names[5] = { + "NONE", + "Int32Vector", + "Uint16Vector", + "Uint8Vector", + nullptr + }; + return names; +} + +inline const char *EnumNameSparseIndexVector(SparseIndexVector e) +{ + if (flatbuffers::IsOutRange(e, SparseIndexVector_NONE, SparseIndexVector_Uint8Vector)) + return ""; + const size_t index = static_cast(e); + return EnumNamesSparseIndexVector()[index]; +} + +template +struct SparseIndexVectorTraits { + static const SparseIndexVector enum_value = SparseIndexVector_NONE; +}; + +template <> +struct SparseIndexVectorTraits { + static const SparseIndexVector enum_value = SparseIndexVector_Int32Vector; +}; + +template <> +struct SparseIndexVectorTraits { + static const SparseIndexVector enum_value = SparseIndexVector_Uint16Vector; +}; + +template <> +struct SparseIndexVectorTraits { + static const SparseIndexVector enum_value = SparseIndexVector_Uint8Vector; +}; + +struct SparseIndexVectorUnion { + SparseIndexVector type; + void *value; + + SparseIndexVectorUnion() + : type(SparseIndexVector_NONE), value(nullptr) + { + } + SparseIndexVectorUnion(SparseIndexVectorUnion &&u) FLATBUFFERS_NOEXCEPT : type(SparseIndexVector_NONE), value(nullptr) + { + std::swap(type, u.type); + std::swap(value, u.value); + } + SparseIndexVectorUnion(const SparseIndexVectorUnion &) FLATBUFFERS_NOEXCEPT; + SparseIndexVectorUnion &operator=(const SparseIndexVectorUnion &u) FLATBUFFERS_NOEXCEPT + { + SparseIndexVectorUnion t(u); + std::swap(type, t.type); + std::swap(value, t.value); + return *this; + } + SparseIndexVectorUnion &operator=(SparseIndexVectorUnion &&u) FLATBUFFERS_NOEXCEPT + { + std::swap(type, u.type); + std::swap(value, u.value); + return *this; + } + ~SparseIndexVectorUnion() + { + Reset(); + } + + void Reset(); + +#ifndef FLATBUFFERS_CPP98_STL + template + void Set(T &&val) + { + using RT = typename std::remove_reference::type; + Reset(); + type = SparseIndexVectorTraits::enum_value; + if (type != SparseIndexVector_NONE) { + value = new RT(std::forward(val)); + } + } +#endif // FLATBUFFERS_CPP98_STL + + static void *UnPack(const void *obj, SparseIndexVector type, const flatbuffers::resolver_function_t *resolver); + flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher = nullptr) const; + + tflite::Int32VectorT *AsInt32Vector() + { + return type == SparseIndexVector_Int32Vector ? + reinterpret_cast(value) : + nullptr; + } + const tflite::Int32VectorT *AsInt32Vector() const + { + return type == SparseIndexVector_Int32Vector ? + reinterpret_cast(value) : + nullptr; + } + tflite::Uint16VectorT *AsUint16Vector() + { + return type == SparseIndexVector_Uint16Vector ? + reinterpret_cast(value) : + nullptr; + } + const tflite::Uint16VectorT *AsUint16Vector() const + { + return type == SparseIndexVector_Uint16Vector ? + reinterpret_cast(value) : + nullptr; + } + tflite::Uint8VectorT *AsUint8Vector() + { + return type == SparseIndexVector_Uint8Vector ? + reinterpret_cast(value) : + nullptr; + } + const tflite::Uint8VectorT *AsUint8Vector() const + { + return type == SparseIndexVector_Uint8Vector ? + reinterpret_cast(value) : + nullptr; + } +}; + +bool VerifySparseIndexVector(flatbuffers::Verifier &verifier, const void *obj, SparseIndexVector type); +bool VerifySparseIndexVectorVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector > *values, const flatbuffers::Vector *types); + +enum BuiltinOperator { + BuiltinOperator_ADD = 0, + BuiltinOperator_AVERAGE_POOL_2D = 1, + BuiltinOperator_CONCATENATION = 2, + BuiltinOperator_CONV_2D = 3, + BuiltinOperator_DEPTHWISE_CONV_2D = 4, + BuiltinOperator_DEPTH_TO_SPACE = 5, + BuiltinOperator_DEQUANTIZE = 6, + BuiltinOperator_EMBEDDING_LOOKUP = 7, + BuiltinOperator_FLOOR = 8, + BuiltinOperator_FULLY_CONNECTED = 9, + BuiltinOperator_HASHTABLE_LOOKUP = 10, + BuiltinOperator_L2_NORMALIZATION = 11, + BuiltinOperator_L2_POOL_2D = 12, + BuiltinOperator_LOCAL_RESPONSE_NORMALIZATION = 13, + BuiltinOperator_LOGISTIC = 14, + BuiltinOperator_LSH_PROJECTION = 15, + BuiltinOperator_LSTM = 16, + BuiltinOperator_MAX_POOL_2D = 17, + BuiltinOperator_MUL = 18, + BuiltinOperator_RELU = 19, + BuiltinOperator_RELU_N1_TO_1 = 20, + BuiltinOperator_RELU6 = 21, + BuiltinOperator_RESHAPE = 22, + BuiltinOperator_RESIZE_BILINEAR = 23, + BuiltinOperator_RNN = 24, + BuiltinOperator_SOFTMAX = 25, + BuiltinOperator_SPACE_TO_DEPTH = 26, + BuiltinOperator_SVDF = 27, + BuiltinOperator_TANH = 28, + BuiltinOperator_CONCAT_EMBEDDINGS = 29, + BuiltinOperator_SKIP_GRAM = 30, + BuiltinOperator_CALL = 31, + BuiltinOperator_CUSTOM = 32, + BuiltinOperator_EMBEDDING_LOOKUP_SPARSE = 33, + BuiltinOperator_PAD = 34, + BuiltinOperator_UNIDIRECTIONAL_SEQUENCE_RNN = 35, + BuiltinOperator_GATHER = 36, + BuiltinOperator_BATCH_TO_SPACE_ND = 37, + BuiltinOperator_SPACE_TO_BATCH_ND = 38, + BuiltinOperator_TRANSPOSE = 39, + BuiltinOperator_MEAN = 40, + BuiltinOperator_SUB = 41, + BuiltinOperator_DIV = 42, + BuiltinOperator_SQUEEZE = 43, + BuiltinOperator_UNIDIRECTIONAL_SEQUENCE_LSTM = 44, + BuiltinOperator_STRIDED_SLICE = 45, + BuiltinOperator_BIDIRECTIONAL_SEQUENCE_RNN = 46, + BuiltinOperator_EXP = 47, + BuiltinOperator_TOPK_V2 = 48, + BuiltinOperator_SPLIT = 49, + BuiltinOperator_LOG_SOFTMAX = 50, + BuiltinOperator_DELEGATE = 51, + BuiltinOperator_BIDIRECTIONAL_SEQUENCE_LSTM = 52, + BuiltinOperator_CAST = 53, + BuiltinOperator_PRELU = 54, + BuiltinOperator_MAXIMUM = 55, + BuiltinOperator_ARG_MAX = 56, + BuiltinOperator_MINIMUM = 57, + BuiltinOperator_LESS = 58, + BuiltinOperator_NEG = 59, + BuiltinOperator_PADV2 = 60, + BuiltinOperator_GREATER = 61, + BuiltinOperator_GREATER_EQUAL = 62, + BuiltinOperator_LESS_EQUAL = 63, + BuiltinOperator_SELECT = 64, + BuiltinOperator_SLICE = 65, + BuiltinOperator_SIN = 66, + BuiltinOperator_TRANSPOSE_CONV = 67, + BuiltinOperator_SPARSE_TO_DENSE = 68, + BuiltinOperator_TILE = 69, + BuiltinOperator_EXPAND_DIMS = 70, + BuiltinOperator_EQUAL = 71, + BuiltinOperator_NOT_EQUAL = 72, + BuiltinOperator_LOG = 73, + BuiltinOperator_SUM = 74, + BuiltinOperator_SQRT = 75, + BuiltinOperator_RSQRT = 76, + BuiltinOperator_SHAPE = 77, + BuiltinOperator_POW = 78, + BuiltinOperator_ARG_MIN = 79, + BuiltinOperator_FAKE_QUANT = 80, + BuiltinOperator_REDUCE_PROD = 81, + BuiltinOperator_REDUCE_MAX = 82, + BuiltinOperator_PACK = 83, + BuiltinOperator_LOGICAL_OR = 84, + BuiltinOperator_ONE_HOT = 85, + BuiltinOperator_LOGICAL_AND = 86, + BuiltinOperator_LOGICAL_NOT = 87, + BuiltinOperator_UNPACK = 88, + BuiltinOperator_REDUCE_MIN = 89, + BuiltinOperator_FLOOR_DIV = 90, + BuiltinOperator_REDUCE_ANY = 91, + BuiltinOperator_SQUARE = 92, + BuiltinOperator_ZEROS_LIKE = 93, + BuiltinOperator_FILL = 94, + BuiltinOperator_FLOOR_MOD = 95, + BuiltinOperator_RANGE = 96, + BuiltinOperator_RESIZE_NEAREST_NEIGHBOR = 97, + BuiltinOperator_LEAKY_RELU = 98, + BuiltinOperator_SQUARED_DIFFERENCE = 99, + BuiltinOperator_MIRROR_PAD = 100, + BuiltinOperator_ABS = 101, + BuiltinOperator_SPLIT_V = 102, + BuiltinOperator_UNIQUE = 103, + BuiltinOperator_CEIL = 104, + BuiltinOperator_REVERSE_V2 = 105, + BuiltinOperator_ADD_N = 106, + BuiltinOperator_GATHER_ND = 107, + BuiltinOperator_COS = 108, + BuiltinOperator_WHERE = 109, + BuiltinOperator_RANK = 110, + BuiltinOperator_ELU = 111, + BuiltinOperator_REVERSE_SEQUENCE = 112, + BuiltinOperator_MATRIX_DIAG = 113, + BuiltinOperator_QUANTIZE = 114, + BuiltinOperator_MATRIX_SET_DIAG = 115, + BuiltinOperator_ROUND = 116, + BuiltinOperator_HARD_SWISH = 117, + BuiltinOperator_IF = 118, + BuiltinOperator_WHILE = 119, + BuiltinOperator_NON_MAX_SUPPRESSION_V4 = 120, + BuiltinOperator_NON_MAX_SUPPRESSION_V5 = 121, + BuiltinOperator_SCATTER_ND = 122, + BuiltinOperator_SELECT_V2 = 123, + BuiltinOperator_DENSIFY = 124, + BuiltinOperator_SEGMENT_SUM = 125, + BuiltinOperator_BATCH_MATMUL = 126, + BuiltinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES = 127, + BuiltinOperator_CUMSUM = 128, + BuiltinOperator_CALL_ONCE = 129, + BuiltinOperator_BROADCAST_TO = 130, + BuiltinOperator_RFFT2D = 131, + BuiltinOperator_CONV_3D = 132, + BuiltinOperator_IMAG = 133, + BuiltinOperator_REAL = 134, + BuiltinOperator_COMPLEX_ABS = 135, + BuiltinOperator_HASHTABLE = 136, + BuiltinOperator_HASHTABLE_FIND = 137, + BuiltinOperator_HASHTABLE_IMPORT = 138, + BuiltinOperator_HASHTABLE_SIZE = 139, + BuiltinOperator_REDUCE_ALL = 140, + BuiltinOperator_CONV_3D_TRANSPOSE = 141, + BuiltinOperator_MIN = BuiltinOperator_ADD, + BuiltinOperator_MAX = BuiltinOperator_CONV_3D_TRANSPOSE +}; + +inline const BuiltinOperator (&EnumValuesBuiltinOperator())[142] +{ + static const BuiltinOperator values[] = { + BuiltinOperator_ADD, + BuiltinOperator_AVERAGE_POOL_2D, + BuiltinOperator_CONCATENATION, + BuiltinOperator_CONV_2D, + BuiltinOperator_DEPTHWISE_CONV_2D, + BuiltinOperator_DEPTH_TO_SPACE, + BuiltinOperator_DEQUANTIZE, + BuiltinOperator_EMBEDDING_LOOKUP, + BuiltinOperator_FLOOR, + BuiltinOperator_FULLY_CONNECTED, + BuiltinOperator_HASHTABLE_LOOKUP, + BuiltinOperator_L2_NORMALIZATION, + BuiltinOperator_L2_POOL_2D, + BuiltinOperator_LOCAL_RESPONSE_NORMALIZATION, + BuiltinOperator_LOGISTIC, + BuiltinOperator_LSH_PROJECTION, + BuiltinOperator_LSTM, + BuiltinOperator_MAX_POOL_2D, + BuiltinOperator_MUL, + BuiltinOperator_RELU, + BuiltinOperator_RELU_N1_TO_1, + BuiltinOperator_RELU6, + BuiltinOperator_RESHAPE, + BuiltinOperator_RESIZE_BILINEAR, + BuiltinOperator_RNN, + BuiltinOperator_SOFTMAX, + BuiltinOperator_SPACE_TO_DEPTH, + BuiltinOperator_SVDF, + BuiltinOperator_TANH, + BuiltinOperator_CONCAT_EMBEDDINGS, + BuiltinOperator_SKIP_GRAM, + BuiltinOperator_CALL, + BuiltinOperator_CUSTOM, + BuiltinOperator_EMBEDDING_LOOKUP_SPARSE, + BuiltinOperator_PAD, + BuiltinOperator_UNIDIRECTIONAL_SEQUENCE_RNN, + BuiltinOperator_GATHER, + BuiltinOperator_BATCH_TO_SPACE_ND, + BuiltinOperator_SPACE_TO_BATCH_ND, + BuiltinOperator_TRANSPOSE, + BuiltinOperator_MEAN, + BuiltinOperator_SUB, + BuiltinOperator_DIV, + BuiltinOperator_SQUEEZE, + BuiltinOperator_UNIDIRECTIONAL_SEQUENCE_LSTM, + BuiltinOperator_STRIDED_SLICE, + BuiltinOperator_BIDIRECTIONAL_SEQUENCE_RNN, + BuiltinOperator_EXP, + BuiltinOperator_TOPK_V2, + BuiltinOperator_SPLIT, + BuiltinOperator_LOG_SOFTMAX, + BuiltinOperator_DELEGATE, + BuiltinOperator_BIDIRECTIONAL_SEQUENCE_LSTM, + BuiltinOperator_CAST, + BuiltinOperator_PRELU, + BuiltinOperator_MAXIMUM, + BuiltinOperator_ARG_MAX, + BuiltinOperator_MINIMUM, + BuiltinOperator_LESS, + BuiltinOperator_NEG, + BuiltinOperator_PADV2, + BuiltinOperator_GREATER, + BuiltinOperator_GREATER_EQUAL, + BuiltinOperator_LESS_EQUAL, + BuiltinOperator_SELECT, + BuiltinOperator_SLICE, + BuiltinOperator_SIN, + BuiltinOperator_TRANSPOSE_CONV, + BuiltinOperator_SPARSE_TO_DENSE, + BuiltinOperator_TILE, + BuiltinOperator_EXPAND_DIMS, + BuiltinOperator_EQUAL, + BuiltinOperator_NOT_EQUAL, + BuiltinOperator_LOG, + BuiltinOperator_SUM, + BuiltinOperator_SQRT, + BuiltinOperator_RSQRT, + BuiltinOperator_SHAPE, + BuiltinOperator_POW, + BuiltinOperator_ARG_MIN, + BuiltinOperator_FAKE_QUANT, + BuiltinOperator_REDUCE_PROD, + BuiltinOperator_REDUCE_MAX, + BuiltinOperator_PACK, + BuiltinOperator_LOGICAL_OR, + BuiltinOperator_ONE_HOT, + BuiltinOperator_LOGICAL_AND, + BuiltinOperator_LOGICAL_NOT, + BuiltinOperator_UNPACK, + BuiltinOperator_REDUCE_MIN, + BuiltinOperator_FLOOR_DIV, + BuiltinOperator_REDUCE_ANY, + BuiltinOperator_SQUARE, + BuiltinOperator_ZEROS_LIKE, + BuiltinOperator_FILL, + BuiltinOperator_FLOOR_MOD, + BuiltinOperator_RANGE, + BuiltinOperator_RESIZE_NEAREST_NEIGHBOR, + BuiltinOperator_LEAKY_RELU, + BuiltinOperator_SQUARED_DIFFERENCE, + BuiltinOperator_MIRROR_PAD, + BuiltinOperator_ABS, + BuiltinOperator_SPLIT_V, + BuiltinOperator_UNIQUE, + BuiltinOperator_CEIL, + BuiltinOperator_REVERSE_V2, + BuiltinOperator_ADD_N, + BuiltinOperator_GATHER_ND, + BuiltinOperator_COS, + BuiltinOperator_WHERE, + BuiltinOperator_RANK, + BuiltinOperator_ELU, + BuiltinOperator_REVERSE_SEQUENCE, + BuiltinOperator_MATRIX_DIAG, + BuiltinOperator_QUANTIZE, + BuiltinOperator_MATRIX_SET_DIAG, + BuiltinOperator_ROUND, + BuiltinOperator_HARD_SWISH, + BuiltinOperator_IF, + BuiltinOperator_WHILE, + BuiltinOperator_NON_MAX_SUPPRESSION_V4, + BuiltinOperator_NON_MAX_SUPPRESSION_V5, + BuiltinOperator_SCATTER_ND, + BuiltinOperator_SELECT_V2, + BuiltinOperator_DENSIFY, + BuiltinOperator_SEGMENT_SUM, + BuiltinOperator_BATCH_MATMUL, + BuiltinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES, + BuiltinOperator_CUMSUM, + BuiltinOperator_CALL_ONCE, + BuiltinOperator_BROADCAST_TO, + BuiltinOperator_RFFT2D, + BuiltinOperator_CONV_3D, + BuiltinOperator_IMAG, + BuiltinOperator_REAL, + BuiltinOperator_COMPLEX_ABS, + BuiltinOperator_HASHTABLE, + BuiltinOperator_HASHTABLE_FIND, + BuiltinOperator_HASHTABLE_IMPORT, + BuiltinOperator_HASHTABLE_SIZE, + BuiltinOperator_REDUCE_ALL, + BuiltinOperator_CONV_3D_TRANSPOSE + }; + return values; +} + +inline const char *const *EnumNamesBuiltinOperator() +{ + static const char *const names[143] = { + "ADD", + "AVERAGE_POOL_2D", + "CONCATENATION", + "CONV_2D", + "DEPTHWISE_CONV_2D", + "DEPTH_TO_SPACE", + "DEQUANTIZE", + "EMBEDDING_LOOKUP", + "FLOOR", + "FULLY_CONNECTED", + "HASHTABLE_LOOKUP", + "L2_NORMALIZATION", + "L2_POOL_2D", + "LOCAL_RESPONSE_NORMALIZATION", + "LOGISTIC", + "LSH_PROJECTION", + "LSTM", + "MAX_POOL_2D", + "MUL", + "RELU", + "RELU_N1_TO_1", + "RELU6", + "RESHAPE", + "RESIZE_BILINEAR", + "RNN", + "SOFTMAX", + "SPACE_TO_DEPTH", + "SVDF", + "TANH", + "CONCAT_EMBEDDINGS", + "SKIP_GRAM", + "CALL", + "CUSTOM", + "EMBEDDING_LOOKUP_SPARSE", + "PAD", + "UNIDIRECTIONAL_SEQUENCE_RNN", + "GATHER", + "BATCH_TO_SPACE_ND", + "SPACE_TO_BATCH_ND", + "TRANSPOSE", + "MEAN", + "SUB", + "DIV", + "SQUEEZE", + "UNIDIRECTIONAL_SEQUENCE_LSTM", + "STRIDED_SLICE", + "BIDIRECTIONAL_SEQUENCE_RNN", + "EXP", + "TOPK_V2", + "SPLIT", + "LOG_SOFTMAX", + "DELEGATE", + "BIDIRECTIONAL_SEQUENCE_LSTM", + "CAST", + "PRELU", + "MAXIMUM", + "ARG_MAX", + "MINIMUM", + "LESS", + "NEG", + "PADV2", + "GREATER", + "GREATER_EQUAL", + "LESS_EQUAL", + "SELECT", + "SLICE", + "SIN", + "TRANSPOSE_CONV", + "SPARSE_TO_DENSE", + "TILE", + "EXPAND_DIMS", + "EQUAL", + "NOT_EQUAL", + "LOG", + "SUM", + "SQRT", + "RSQRT", + "SHAPE", + "POW", + "ARG_MIN", + "FAKE_QUANT", + "REDUCE_PROD", + "REDUCE_MAX", + "PACK", + "LOGICAL_OR", + "ONE_HOT", + "LOGICAL_AND", + "LOGICAL_NOT", + "UNPACK", + "REDUCE_MIN", + "FLOOR_DIV", + "REDUCE_ANY", + "SQUARE", + "ZEROS_LIKE", + "FILL", + "FLOOR_MOD", + "RANGE", + "RESIZE_NEAREST_NEIGHBOR", + "LEAKY_RELU", + "SQUARED_DIFFERENCE", + "MIRROR_PAD", + "ABS", + "SPLIT_V", + "UNIQUE", + "CEIL", + "REVERSE_V2", + "ADD_N", + "GATHER_ND", + "COS", + "WHERE", + "RANK", + "ELU", + "REVERSE_SEQUENCE", + "MATRIX_DIAG", + "QUANTIZE", + "MATRIX_SET_DIAG", + "ROUND", + "HARD_SWISH", + "IF", + "WHILE", + "NON_MAX_SUPPRESSION_V4", + "NON_MAX_SUPPRESSION_V5", + "SCATTER_ND", + "SELECT_V2", + "DENSIFY", + "SEGMENT_SUM", + "BATCH_MATMUL", + "PLACEHOLDER_FOR_GREATER_OP_CODES", + "CUMSUM", + "CALL_ONCE", + "BROADCAST_TO", + "RFFT2D", + "CONV_3D", + "IMAG", + "REAL", + "COMPLEX_ABS", + "HASHTABLE", + "HASHTABLE_FIND", + "HASHTABLE_IMPORT", + "HASHTABLE_SIZE", + "REDUCE_ALL", + "CONV_3D_TRANSPOSE", + nullptr + }; + return names; +} + +inline const char *EnumNameBuiltinOperator(BuiltinOperator e) +{ + if (flatbuffers::IsOutRange(e, BuiltinOperator_ADD, BuiltinOperator_CONV_3D_TRANSPOSE)) + return ""; + const size_t index = static_cast(e); + return EnumNamesBuiltinOperator()[index]; +} + +enum BuiltinOptions { + BuiltinOptions_NONE = 0, + BuiltinOptions_Conv2DOptions = 1, + BuiltinOptions_DepthwiseConv2DOptions = 2, + BuiltinOptions_ConcatEmbeddingsOptions = 3, + BuiltinOptions_LSHProjectionOptions = 4, + BuiltinOptions_Pool2DOptions = 5, + BuiltinOptions_SVDFOptions = 6, + BuiltinOptions_RNNOptions = 7, + BuiltinOptions_FullyConnectedOptions = 8, + BuiltinOptions_SoftmaxOptions = 9, + BuiltinOptions_ConcatenationOptions = 10, + BuiltinOptions_AddOptions = 11, + BuiltinOptions_L2NormOptions = 12, + BuiltinOptions_LocalResponseNormalizationOptions = 13, + BuiltinOptions_LSTMOptions = 14, + BuiltinOptions_ResizeBilinearOptions = 15, + BuiltinOptions_CallOptions = 16, + BuiltinOptions_ReshapeOptions = 17, + BuiltinOptions_SkipGramOptions = 18, + BuiltinOptions_SpaceToDepthOptions = 19, + BuiltinOptions_EmbeddingLookupSparseOptions = 20, + BuiltinOptions_MulOptions = 21, + BuiltinOptions_PadOptions = 22, + BuiltinOptions_GatherOptions = 23, + BuiltinOptions_BatchToSpaceNDOptions = 24, + BuiltinOptions_SpaceToBatchNDOptions = 25, + BuiltinOptions_TransposeOptions = 26, + BuiltinOptions_ReducerOptions = 27, + BuiltinOptions_SubOptions = 28, + BuiltinOptions_DivOptions = 29, + BuiltinOptions_SqueezeOptions = 30, + BuiltinOptions_SequenceRNNOptions = 31, + BuiltinOptions_StridedSliceOptions = 32, + BuiltinOptions_ExpOptions = 33, + BuiltinOptions_TopKV2Options = 34, + BuiltinOptions_SplitOptions = 35, + BuiltinOptions_LogSoftmaxOptions = 36, + BuiltinOptions_CastOptions = 37, + BuiltinOptions_DequantizeOptions = 38, + BuiltinOptions_MaximumMinimumOptions = 39, + BuiltinOptions_ArgMaxOptions = 40, + BuiltinOptions_LessOptions = 41, + BuiltinOptions_NegOptions = 42, + BuiltinOptions_PadV2Options = 43, + BuiltinOptions_GreaterOptions = 44, + BuiltinOptions_GreaterEqualOptions = 45, + BuiltinOptions_LessEqualOptions = 46, + BuiltinOptions_SelectOptions = 47, + BuiltinOptions_SliceOptions = 48, + BuiltinOptions_TransposeConvOptions = 49, + BuiltinOptions_SparseToDenseOptions = 50, + BuiltinOptions_TileOptions = 51, + BuiltinOptions_ExpandDimsOptions = 52, + BuiltinOptions_EqualOptions = 53, + BuiltinOptions_NotEqualOptions = 54, + BuiltinOptions_ShapeOptions = 55, + BuiltinOptions_PowOptions = 56, + BuiltinOptions_ArgMinOptions = 57, + BuiltinOptions_FakeQuantOptions = 58, + BuiltinOptions_PackOptions = 59, + BuiltinOptions_LogicalOrOptions = 60, + BuiltinOptions_OneHotOptions = 61, + BuiltinOptions_LogicalAndOptions = 62, + BuiltinOptions_LogicalNotOptions = 63, + BuiltinOptions_UnpackOptions = 64, + BuiltinOptions_FloorDivOptions = 65, + BuiltinOptions_SquareOptions = 66, + BuiltinOptions_ZerosLikeOptions = 67, + BuiltinOptions_FillOptions = 68, + BuiltinOptions_BidirectionalSequenceLSTMOptions = 69, + BuiltinOptions_BidirectionalSequenceRNNOptions = 70, + BuiltinOptions_UnidirectionalSequenceLSTMOptions = 71, + BuiltinOptions_FloorModOptions = 72, + BuiltinOptions_RangeOptions = 73, + BuiltinOptions_ResizeNearestNeighborOptions = 74, + BuiltinOptions_LeakyReluOptions = 75, + BuiltinOptions_SquaredDifferenceOptions = 76, + BuiltinOptions_MirrorPadOptions = 77, + BuiltinOptions_AbsOptions = 78, + BuiltinOptions_SplitVOptions = 79, + BuiltinOptions_UniqueOptions = 80, + BuiltinOptions_ReverseV2Options = 81, + BuiltinOptions_AddNOptions = 82, + BuiltinOptions_GatherNdOptions = 83, + BuiltinOptions_CosOptions = 84, + BuiltinOptions_WhereOptions = 85, + BuiltinOptions_RankOptions = 86, + BuiltinOptions_ReverseSequenceOptions = 87, + BuiltinOptions_MatrixDiagOptions = 88, + BuiltinOptions_QuantizeOptions = 89, + BuiltinOptions_MatrixSetDiagOptions = 90, + BuiltinOptions_HardSwishOptions = 91, + BuiltinOptions_IfOptions = 92, + BuiltinOptions_WhileOptions = 93, + BuiltinOptions_DepthToSpaceOptions = 94, + BuiltinOptions_NonMaxSuppressionV4Options = 95, + BuiltinOptions_NonMaxSuppressionV5Options = 96, + BuiltinOptions_ScatterNdOptions = 97, + BuiltinOptions_SelectV2Options = 98, + BuiltinOptions_DensifyOptions = 99, + BuiltinOptions_SegmentSumOptions = 100, + BuiltinOptions_BatchMatMulOptions = 101, + BuiltinOptions_CumsumOptions = 102, + BuiltinOptions_CallOnceOptions = 103, + BuiltinOptions_BroadcastToOptions = 104, + BuiltinOptions_Rfft2dOptions = 105, + BuiltinOptions_Conv3DOptions = 106, + BuiltinOptions_HashtableOptions = 107, + BuiltinOptions_HashtableFindOptions = 108, + BuiltinOptions_HashtableImportOptions = 109, + BuiltinOptions_HashtableSizeOptions = 110, + BuiltinOptions_MIN = BuiltinOptions_NONE, + BuiltinOptions_MAX = BuiltinOptions_HashtableSizeOptions +}; + +inline const BuiltinOptions (&EnumValuesBuiltinOptions())[111] +{ + static const BuiltinOptions values[] = { + BuiltinOptions_NONE, + BuiltinOptions_Conv2DOptions, + BuiltinOptions_DepthwiseConv2DOptions, + BuiltinOptions_ConcatEmbeddingsOptions, + BuiltinOptions_LSHProjectionOptions, + BuiltinOptions_Pool2DOptions, + BuiltinOptions_SVDFOptions, + BuiltinOptions_RNNOptions, + BuiltinOptions_FullyConnectedOptions, + BuiltinOptions_SoftmaxOptions, + BuiltinOptions_ConcatenationOptions, + BuiltinOptions_AddOptions, + BuiltinOptions_L2NormOptions, + BuiltinOptions_LocalResponseNormalizationOptions, + BuiltinOptions_LSTMOptions, + BuiltinOptions_ResizeBilinearOptions, + BuiltinOptions_CallOptions, + BuiltinOptions_ReshapeOptions, + BuiltinOptions_SkipGramOptions, + BuiltinOptions_SpaceToDepthOptions, + BuiltinOptions_EmbeddingLookupSparseOptions, + BuiltinOptions_MulOptions, + BuiltinOptions_PadOptions, + BuiltinOptions_GatherOptions, + BuiltinOptions_BatchToSpaceNDOptions, + BuiltinOptions_SpaceToBatchNDOptions, + BuiltinOptions_TransposeOptions, + BuiltinOptions_ReducerOptions, + BuiltinOptions_SubOptions, + BuiltinOptions_DivOptions, + BuiltinOptions_SqueezeOptions, + BuiltinOptions_SequenceRNNOptions, + BuiltinOptions_StridedSliceOptions, + BuiltinOptions_ExpOptions, + BuiltinOptions_TopKV2Options, + BuiltinOptions_SplitOptions, + BuiltinOptions_LogSoftmaxOptions, + BuiltinOptions_CastOptions, + BuiltinOptions_DequantizeOptions, + BuiltinOptions_MaximumMinimumOptions, + BuiltinOptions_ArgMaxOptions, + BuiltinOptions_LessOptions, + BuiltinOptions_NegOptions, + BuiltinOptions_PadV2Options, + BuiltinOptions_GreaterOptions, + BuiltinOptions_GreaterEqualOptions, + BuiltinOptions_LessEqualOptions, + BuiltinOptions_SelectOptions, + BuiltinOptions_SliceOptions, + BuiltinOptions_TransposeConvOptions, + BuiltinOptions_SparseToDenseOptions, + BuiltinOptions_TileOptions, + BuiltinOptions_ExpandDimsOptions, + BuiltinOptions_EqualOptions, + BuiltinOptions_NotEqualOptions, + BuiltinOptions_ShapeOptions, + BuiltinOptions_PowOptions, + BuiltinOptions_ArgMinOptions, + BuiltinOptions_FakeQuantOptions, + BuiltinOptions_PackOptions, + BuiltinOptions_LogicalOrOptions, + BuiltinOptions_OneHotOptions, + BuiltinOptions_LogicalAndOptions, + BuiltinOptions_LogicalNotOptions, + BuiltinOptions_UnpackOptions, + BuiltinOptions_FloorDivOptions, + BuiltinOptions_SquareOptions, + BuiltinOptions_ZerosLikeOptions, + BuiltinOptions_FillOptions, + BuiltinOptions_BidirectionalSequenceLSTMOptions, + BuiltinOptions_BidirectionalSequenceRNNOptions, + BuiltinOptions_UnidirectionalSequenceLSTMOptions, + BuiltinOptions_FloorModOptions, + BuiltinOptions_RangeOptions, + BuiltinOptions_ResizeNearestNeighborOptions, + BuiltinOptions_LeakyReluOptions, + BuiltinOptions_SquaredDifferenceOptions, + BuiltinOptions_MirrorPadOptions, + BuiltinOptions_AbsOptions, + BuiltinOptions_SplitVOptions, + BuiltinOptions_UniqueOptions, + BuiltinOptions_ReverseV2Options, + BuiltinOptions_AddNOptions, + BuiltinOptions_GatherNdOptions, + BuiltinOptions_CosOptions, + BuiltinOptions_WhereOptions, + BuiltinOptions_RankOptions, + BuiltinOptions_ReverseSequenceOptions, + BuiltinOptions_MatrixDiagOptions, + BuiltinOptions_QuantizeOptions, + BuiltinOptions_MatrixSetDiagOptions, + BuiltinOptions_HardSwishOptions, + BuiltinOptions_IfOptions, + BuiltinOptions_WhileOptions, + BuiltinOptions_DepthToSpaceOptions, + BuiltinOptions_NonMaxSuppressionV4Options, + BuiltinOptions_NonMaxSuppressionV5Options, + BuiltinOptions_ScatterNdOptions, + BuiltinOptions_SelectV2Options, + BuiltinOptions_DensifyOptions, + BuiltinOptions_SegmentSumOptions, + BuiltinOptions_BatchMatMulOptions, + BuiltinOptions_CumsumOptions, + BuiltinOptions_CallOnceOptions, + BuiltinOptions_BroadcastToOptions, + BuiltinOptions_Rfft2dOptions, + BuiltinOptions_Conv3DOptions, + BuiltinOptions_HashtableOptions, + BuiltinOptions_HashtableFindOptions, + BuiltinOptions_HashtableImportOptions, + BuiltinOptions_HashtableSizeOptions + }; + return values; +} + +inline const char *const *EnumNamesBuiltinOptions() +{ + static const char *const names[112] = { + "NONE", + "Conv2DOptions", + "DepthwiseConv2DOptions", + "ConcatEmbeddingsOptions", + "LSHProjectionOptions", + "Pool2DOptions", + "SVDFOptions", + "RNNOptions", + "FullyConnectedOptions", + "SoftmaxOptions", + "ConcatenationOptions", + "AddOptions", + "L2NormOptions", + "LocalResponseNormalizationOptions", + "LSTMOptions", + "ResizeBilinearOptions", + "CallOptions", + "ReshapeOptions", + "SkipGramOptions", + "SpaceToDepthOptions", + "EmbeddingLookupSparseOptions", + "MulOptions", + "PadOptions", + "GatherOptions", + "BatchToSpaceNDOptions", + "SpaceToBatchNDOptions", + "TransposeOptions", + "ReducerOptions", + "SubOptions", + "DivOptions", + "SqueezeOptions", + "SequenceRNNOptions", + "StridedSliceOptions", + "ExpOptions", + "TopKV2Options", + "SplitOptions", + "LogSoftmaxOptions", + "CastOptions", + "DequantizeOptions", + "MaximumMinimumOptions", + "ArgMaxOptions", + "LessOptions", + "NegOptions", + "PadV2Options", + "GreaterOptions", + "GreaterEqualOptions", + "LessEqualOptions", + "SelectOptions", + "SliceOptions", + "TransposeConvOptions", + "SparseToDenseOptions", + "TileOptions", + "ExpandDimsOptions", + "EqualOptions", + "NotEqualOptions", + "ShapeOptions", + "PowOptions", + "ArgMinOptions", + "FakeQuantOptions", + "PackOptions", + "LogicalOrOptions", + "OneHotOptions", + "LogicalAndOptions", + "LogicalNotOptions", + "UnpackOptions", + "FloorDivOptions", + "SquareOptions", + "ZerosLikeOptions", + "FillOptions", + "BidirectionalSequenceLSTMOptions", + "BidirectionalSequenceRNNOptions", + "UnidirectionalSequenceLSTMOptions", + "FloorModOptions", + "RangeOptions", + "ResizeNearestNeighborOptions", + "LeakyReluOptions", + "SquaredDifferenceOptions", + "MirrorPadOptions", + "AbsOptions", + "SplitVOptions", + "UniqueOptions", + "ReverseV2Options", + "AddNOptions", + "GatherNdOptions", + "CosOptions", + "WhereOptions", + "RankOptions", + "ReverseSequenceOptions", + "MatrixDiagOptions", + "QuantizeOptions", + "MatrixSetDiagOptions", + "HardSwishOptions", + "IfOptions", + "WhileOptions", + "DepthToSpaceOptions", + "NonMaxSuppressionV4Options", + "NonMaxSuppressionV5Options", + "ScatterNdOptions", + "SelectV2Options", + "DensifyOptions", + "SegmentSumOptions", + "BatchMatMulOptions", + "CumsumOptions", + "CallOnceOptions", + "BroadcastToOptions", + "Rfft2dOptions", + "Conv3DOptions", + "HashtableOptions", + "HashtableFindOptions", + "HashtableImportOptions", + "HashtableSizeOptions", + nullptr + }; + return names; +} + +inline const char *EnumNameBuiltinOptions(BuiltinOptions e) +{ + if (flatbuffers::IsOutRange(e, BuiltinOptions_NONE, BuiltinOptions_HashtableSizeOptions)) + return ""; + const size_t index = static_cast(e); + return EnumNamesBuiltinOptions()[index]; +} + +template +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_NONE; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_Conv2DOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_DepthwiseConv2DOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_ConcatEmbeddingsOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_LSHProjectionOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_Pool2DOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_SVDFOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_RNNOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_FullyConnectedOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_SoftmaxOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_ConcatenationOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_AddOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_L2NormOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_LocalResponseNormalizationOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_LSTMOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_ResizeBilinearOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_CallOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_ReshapeOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_SkipGramOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_SpaceToDepthOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_EmbeddingLookupSparseOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_MulOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_PadOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_GatherOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_BatchToSpaceNDOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_SpaceToBatchNDOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_TransposeOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_ReducerOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_SubOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_DivOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_SqueezeOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_SequenceRNNOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_StridedSliceOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_ExpOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_TopKV2Options; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_SplitOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_LogSoftmaxOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_CastOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_DequantizeOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_MaximumMinimumOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_ArgMaxOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_LessOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_NegOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_PadV2Options; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_GreaterOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_GreaterEqualOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_LessEqualOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_SelectOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_SliceOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_TransposeConvOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_SparseToDenseOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_TileOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_ExpandDimsOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_EqualOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_NotEqualOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_ShapeOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_PowOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_ArgMinOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_FakeQuantOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_PackOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_LogicalOrOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_OneHotOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_LogicalAndOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_LogicalNotOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_UnpackOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_FloorDivOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_SquareOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_ZerosLikeOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_FillOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_BidirectionalSequenceLSTMOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_BidirectionalSequenceRNNOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_UnidirectionalSequenceLSTMOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_FloorModOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_RangeOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_ResizeNearestNeighborOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_LeakyReluOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_SquaredDifferenceOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_MirrorPadOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_AbsOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_SplitVOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_UniqueOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_ReverseV2Options; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_AddNOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_GatherNdOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_CosOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_WhereOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_RankOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_ReverseSequenceOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_MatrixDiagOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_QuantizeOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_MatrixSetDiagOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_HardSwishOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_IfOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_WhileOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_DepthToSpaceOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_NonMaxSuppressionV4Options; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_NonMaxSuppressionV5Options; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_ScatterNdOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_SelectV2Options; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_DensifyOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_SegmentSumOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_BatchMatMulOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_CumsumOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_CallOnceOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_BroadcastToOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_Rfft2dOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_Conv3DOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_HashtableOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_HashtableFindOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_HashtableImportOptions; +}; + +template <> +struct BuiltinOptionsTraits { + static const BuiltinOptions enum_value = BuiltinOptions_HashtableSizeOptions; +}; + +struct BuiltinOptionsUnion { + BuiltinOptions type; + void *value; + + BuiltinOptionsUnion() + : type(BuiltinOptions_NONE), value(nullptr) + { + } + BuiltinOptionsUnion(BuiltinOptionsUnion &&u) FLATBUFFERS_NOEXCEPT : type(BuiltinOptions_NONE), value(nullptr) + { + std::swap(type, u.type); + std::swap(value, u.value); + } + BuiltinOptionsUnion(const BuiltinOptionsUnion &) FLATBUFFERS_NOEXCEPT; + BuiltinOptionsUnion &operator=(const BuiltinOptionsUnion &u) FLATBUFFERS_NOEXCEPT + { + BuiltinOptionsUnion t(u); + std::swap(type, t.type); + std::swap(value, t.value); + return *this; + } + BuiltinOptionsUnion &operator=(BuiltinOptionsUnion &&u) FLATBUFFERS_NOEXCEPT + { + std::swap(type, u.type); + std::swap(value, u.value); + return *this; + } + ~BuiltinOptionsUnion() + { + Reset(); + } + + void Reset(); + +#ifndef FLATBUFFERS_CPP98_STL + template + void Set(T &&val) + { + using RT = typename std::remove_reference::type; + Reset(); + type = BuiltinOptionsTraits::enum_value; + if (type != BuiltinOptions_NONE) { + value = new RT(std::forward(val)); + } + } +#endif // FLATBUFFERS_CPP98_STL + + static void *UnPack(const void *obj, BuiltinOptions type, const flatbuffers::resolver_function_t *resolver); + flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher = nullptr) const; + + tflite::Conv2DOptionsT *AsConv2DOptions() + { + return type == BuiltinOptions_Conv2DOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::Conv2DOptionsT *AsConv2DOptions() const + { + return type == BuiltinOptions_Conv2DOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::DepthwiseConv2DOptionsT *AsDepthwiseConv2DOptions() + { + return type == BuiltinOptions_DepthwiseConv2DOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::DepthwiseConv2DOptionsT *AsDepthwiseConv2DOptions() const + { + return type == BuiltinOptions_DepthwiseConv2DOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::ConcatEmbeddingsOptionsT *AsConcatEmbeddingsOptions() + { + return type == BuiltinOptions_ConcatEmbeddingsOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::ConcatEmbeddingsOptionsT *AsConcatEmbeddingsOptions() const + { + return type == BuiltinOptions_ConcatEmbeddingsOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::LSHProjectionOptionsT *AsLSHProjectionOptions() + { + return type == BuiltinOptions_LSHProjectionOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::LSHProjectionOptionsT *AsLSHProjectionOptions() const + { + return type == BuiltinOptions_LSHProjectionOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::Pool2DOptionsT *AsPool2DOptions() + { + return type == BuiltinOptions_Pool2DOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::Pool2DOptionsT *AsPool2DOptions() const + { + return type == BuiltinOptions_Pool2DOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::SVDFOptionsT *AsSVDFOptions() + { + return type == BuiltinOptions_SVDFOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::SVDFOptionsT *AsSVDFOptions() const + { + return type == BuiltinOptions_SVDFOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::RNNOptionsT *AsRNNOptions() + { + return type == BuiltinOptions_RNNOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::RNNOptionsT *AsRNNOptions() const + { + return type == BuiltinOptions_RNNOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::FullyConnectedOptionsT *AsFullyConnectedOptions() + { + return type == BuiltinOptions_FullyConnectedOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::FullyConnectedOptionsT *AsFullyConnectedOptions() const + { + return type == BuiltinOptions_FullyConnectedOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::SoftmaxOptionsT *AsSoftmaxOptions() + { + return type == BuiltinOptions_SoftmaxOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::SoftmaxOptionsT *AsSoftmaxOptions() const + { + return type == BuiltinOptions_SoftmaxOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::ConcatenationOptionsT *AsConcatenationOptions() + { + return type == BuiltinOptions_ConcatenationOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::ConcatenationOptionsT *AsConcatenationOptions() const + { + return type == BuiltinOptions_ConcatenationOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::AddOptionsT *AsAddOptions() + { + return type == BuiltinOptions_AddOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::AddOptionsT *AsAddOptions() const + { + return type == BuiltinOptions_AddOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::L2NormOptionsT *AsL2NormOptions() + { + return type == BuiltinOptions_L2NormOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::L2NormOptionsT *AsL2NormOptions() const + { + return type == BuiltinOptions_L2NormOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::LocalResponseNormalizationOptionsT *AsLocalResponseNormalizationOptions() + { + return type == BuiltinOptions_LocalResponseNormalizationOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::LocalResponseNormalizationOptionsT *AsLocalResponseNormalizationOptions() const + { + return type == BuiltinOptions_LocalResponseNormalizationOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::LSTMOptionsT *AsLSTMOptions() + { + return type == BuiltinOptions_LSTMOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::LSTMOptionsT *AsLSTMOptions() const + { + return type == BuiltinOptions_LSTMOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::ResizeBilinearOptionsT *AsResizeBilinearOptions() + { + return type == BuiltinOptions_ResizeBilinearOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::ResizeBilinearOptionsT *AsResizeBilinearOptions() const + { + return type == BuiltinOptions_ResizeBilinearOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::CallOptionsT *AsCallOptions() + { + return type == BuiltinOptions_CallOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::CallOptionsT *AsCallOptions() const + { + return type == BuiltinOptions_CallOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::ReshapeOptionsT *AsReshapeOptions() + { + return type == BuiltinOptions_ReshapeOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::ReshapeOptionsT *AsReshapeOptions() const + { + return type == BuiltinOptions_ReshapeOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::SkipGramOptionsT *AsSkipGramOptions() + { + return type == BuiltinOptions_SkipGramOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::SkipGramOptionsT *AsSkipGramOptions() const + { + return type == BuiltinOptions_SkipGramOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::SpaceToDepthOptionsT *AsSpaceToDepthOptions() + { + return type == BuiltinOptions_SpaceToDepthOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::SpaceToDepthOptionsT *AsSpaceToDepthOptions() const + { + return type == BuiltinOptions_SpaceToDepthOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::EmbeddingLookupSparseOptionsT *AsEmbeddingLookupSparseOptions() + { + return type == BuiltinOptions_EmbeddingLookupSparseOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::EmbeddingLookupSparseOptionsT *AsEmbeddingLookupSparseOptions() const + { + return type == BuiltinOptions_EmbeddingLookupSparseOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::MulOptionsT *AsMulOptions() + { + return type == BuiltinOptions_MulOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::MulOptionsT *AsMulOptions() const + { + return type == BuiltinOptions_MulOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::PadOptionsT *AsPadOptions() + { + return type == BuiltinOptions_PadOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::PadOptionsT *AsPadOptions() const + { + return type == BuiltinOptions_PadOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::GatherOptionsT *AsGatherOptions() + { + return type == BuiltinOptions_GatherOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::GatherOptionsT *AsGatherOptions() const + { + return type == BuiltinOptions_GatherOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::BatchToSpaceNDOptionsT *AsBatchToSpaceNDOptions() + { + return type == BuiltinOptions_BatchToSpaceNDOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::BatchToSpaceNDOptionsT *AsBatchToSpaceNDOptions() const + { + return type == BuiltinOptions_BatchToSpaceNDOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::SpaceToBatchNDOptionsT *AsSpaceToBatchNDOptions() + { + return type == BuiltinOptions_SpaceToBatchNDOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::SpaceToBatchNDOptionsT *AsSpaceToBatchNDOptions() const + { + return type == BuiltinOptions_SpaceToBatchNDOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::TransposeOptionsT *AsTransposeOptions() + { + return type == BuiltinOptions_TransposeOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::TransposeOptionsT *AsTransposeOptions() const + { + return type == BuiltinOptions_TransposeOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::ReducerOptionsT *AsReducerOptions() + { + return type == BuiltinOptions_ReducerOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::ReducerOptionsT *AsReducerOptions() const + { + return type == BuiltinOptions_ReducerOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::SubOptionsT *AsSubOptions() + { + return type == BuiltinOptions_SubOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::SubOptionsT *AsSubOptions() const + { + return type == BuiltinOptions_SubOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::DivOptionsT *AsDivOptions() + { + return type == BuiltinOptions_DivOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::DivOptionsT *AsDivOptions() const + { + return type == BuiltinOptions_DivOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::SqueezeOptionsT *AsSqueezeOptions() + { + return type == BuiltinOptions_SqueezeOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::SqueezeOptionsT *AsSqueezeOptions() const + { + return type == BuiltinOptions_SqueezeOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::SequenceRNNOptionsT *AsSequenceRNNOptions() + { + return type == BuiltinOptions_SequenceRNNOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::SequenceRNNOptionsT *AsSequenceRNNOptions() const + { + return type == BuiltinOptions_SequenceRNNOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::StridedSliceOptionsT *AsStridedSliceOptions() + { + return type == BuiltinOptions_StridedSliceOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::StridedSliceOptionsT *AsStridedSliceOptions() const + { + return type == BuiltinOptions_StridedSliceOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::ExpOptionsT *AsExpOptions() + { + return type == BuiltinOptions_ExpOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::ExpOptionsT *AsExpOptions() const + { + return type == BuiltinOptions_ExpOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::TopKV2OptionsT *AsTopKV2Options() + { + return type == BuiltinOptions_TopKV2Options ? + reinterpret_cast(value) : + nullptr; + } + const tflite::TopKV2OptionsT *AsTopKV2Options() const + { + return type == BuiltinOptions_TopKV2Options ? + reinterpret_cast(value) : + nullptr; + } + tflite::SplitOptionsT *AsSplitOptions() + { + return type == BuiltinOptions_SplitOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::SplitOptionsT *AsSplitOptions() const + { + return type == BuiltinOptions_SplitOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::LogSoftmaxOptionsT *AsLogSoftmaxOptions() + { + return type == BuiltinOptions_LogSoftmaxOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::LogSoftmaxOptionsT *AsLogSoftmaxOptions() const + { + return type == BuiltinOptions_LogSoftmaxOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::CastOptionsT *AsCastOptions() + { + return type == BuiltinOptions_CastOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::CastOptionsT *AsCastOptions() const + { + return type == BuiltinOptions_CastOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::DequantizeOptionsT *AsDequantizeOptions() + { + return type == BuiltinOptions_DequantizeOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::DequantizeOptionsT *AsDequantizeOptions() const + { + return type == BuiltinOptions_DequantizeOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::MaximumMinimumOptionsT *AsMaximumMinimumOptions() + { + return type == BuiltinOptions_MaximumMinimumOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::MaximumMinimumOptionsT *AsMaximumMinimumOptions() const + { + return type == BuiltinOptions_MaximumMinimumOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::ArgMaxOptionsT *AsArgMaxOptions() + { + return type == BuiltinOptions_ArgMaxOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::ArgMaxOptionsT *AsArgMaxOptions() const + { + return type == BuiltinOptions_ArgMaxOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::LessOptionsT *AsLessOptions() + { + return type == BuiltinOptions_LessOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::LessOptionsT *AsLessOptions() const + { + return type == BuiltinOptions_LessOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::NegOptionsT *AsNegOptions() + { + return type == BuiltinOptions_NegOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::NegOptionsT *AsNegOptions() const + { + return type == BuiltinOptions_NegOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::PadV2OptionsT *AsPadV2Options() + { + return type == BuiltinOptions_PadV2Options ? + reinterpret_cast(value) : + nullptr; + } + const tflite::PadV2OptionsT *AsPadV2Options() const + { + return type == BuiltinOptions_PadV2Options ? + reinterpret_cast(value) : + nullptr; + } + tflite::GreaterOptionsT *AsGreaterOptions() + { + return type == BuiltinOptions_GreaterOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::GreaterOptionsT *AsGreaterOptions() const + { + return type == BuiltinOptions_GreaterOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::GreaterEqualOptionsT *AsGreaterEqualOptions() + { + return type == BuiltinOptions_GreaterEqualOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::GreaterEqualOptionsT *AsGreaterEqualOptions() const + { + return type == BuiltinOptions_GreaterEqualOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::LessEqualOptionsT *AsLessEqualOptions() + { + return type == BuiltinOptions_LessEqualOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::LessEqualOptionsT *AsLessEqualOptions() const + { + return type == BuiltinOptions_LessEqualOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::SelectOptionsT *AsSelectOptions() + { + return type == BuiltinOptions_SelectOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::SelectOptionsT *AsSelectOptions() const + { + return type == BuiltinOptions_SelectOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::SliceOptionsT *AsSliceOptions() + { + return type == BuiltinOptions_SliceOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::SliceOptionsT *AsSliceOptions() const + { + return type == BuiltinOptions_SliceOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::TransposeConvOptionsT *AsTransposeConvOptions() + { + return type == BuiltinOptions_TransposeConvOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::TransposeConvOptionsT *AsTransposeConvOptions() const + { + return type == BuiltinOptions_TransposeConvOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::SparseToDenseOptionsT *AsSparseToDenseOptions() + { + return type == BuiltinOptions_SparseToDenseOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::SparseToDenseOptionsT *AsSparseToDenseOptions() const + { + return type == BuiltinOptions_SparseToDenseOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::TileOptionsT *AsTileOptions() + { + return type == BuiltinOptions_TileOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::TileOptionsT *AsTileOptions() const + { + return type == BuiltinOptions_TileOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::ExpandDimsOptionsT *AsExpandDimsOptions() + { + return type == BuiltinOptions_ExpandDimsOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::ExpandDimsOptionsT *AsExpandDimsOptions() const + { + return type == BuiltinOptions_ExpandDimsOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::EqualOptionsT *AsEqualOptions() + { + return type == BuiltinOptions_EqualOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::EqualOptionsT *AsEqualOptions() const + { + return type == BuiltinOptions_EqualOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::NotEqualOptionsT *AsNotEqualOptions() + { + return type == BuiltinOptions_NotEqualOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::NotEqualOptionsT *AsNotEqualOptions() const + { + return type == BuiltinOptions_NotEqualOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::ShapeOptionsT *AsShapeOptions() + { + return type == BuiltinOptions_ShapeOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::ShapeOptionsT *AsShapeOptions() const + { + return type == BuiltinOptions_ShapeOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::PowOptionsT *AsPowOptions() + { + return type == BuiltinOptions_PowOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::PowOptionsT *AsPowOptions() const + { + return type == BuiltinOptions_PowOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::ArgMinOptionsT *AsArgMinOptions() + { + return type == BuiltinOptions_ArgMinOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::ArgMinOptionsT *AsArgMinOptions() const + { + return type == BuiltinOptions_ArgMinOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::FakeQuantOptionsT *AsFakeQuantOptions() + { + return type == BuiltinOptions_FakeQuantOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::FakeQuantOptionsT *AsFakeQuantOptions() const + { + return type == BuiltinOptions_FakeQuantOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::PackOptionsT *AsPackOptions() + { + return type == BuiltinOptions_PackOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::PackOptionsT *AsPackOptions() const + { + return type == BuiltinOptions_PackOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::LogicalOrOptionsT *AsLogicalOrOptions() + { + return type == BuiltinOptions_LogicalOrOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::LogicalOrOptionsT *AsLogicalOrOptions() const + { + return type == BuiltinOptions_LogicalOrOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::OneHotOptionsT *AsOneHotOptions() + { + return type == BuiltinOptions_OneHotOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::OneHotOptionsT *AsOneHotOptions() const + { + return type == BuiltinOptions_OneHotOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::LogicalAndOptionsT *AsLogicalAndOptions() + { + return type == BuiltinOptions_LogicalAndOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::LogicalAndOptionsT *AsLogicalAndOptions() const + { + return type == BuiltinOptions_LogicalAndOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::LogicalNotOptionsT *AsLogicalNotOptions() + { + return type == BuiltinOptions_LogicalNotOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::LogicalNotOptionsT *AsLogicalNotOptions() const + { + return type == BuiltinOptions_LogicalNotOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::UnpackOptionsT *AsUnpackOptions() + { + return type == BuiltinOptions_UnpackOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::UnpackOptionsT *AsUnpackOptions() const + { + return type == BuiltinOptions_UnpackOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::FloorDivOptionsT *AsFloorDivOptions() + { + return type == BuiltinOptions_FloorDivOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::FloorDivOptionsT *AsFloorDivOptions() const + { + return type == BuiltinOptions_FloorDivOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::SquareOptionsT *AsSquareOptions() + { + return type == BuiltinOptions_SquareOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::SquareOptionsT *AsSquareOptions() const + { + return type == BuiltinOptions_SquareOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::ZerosLikeOptionsT *AsZerosLikeOptions() + { + return type == BuiltinOptions_ZerosLikeOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::ZerosLikeOptionsT *AsZerosLikeOptions() const + { + return type == BuiltinOptions_ZerosLikeOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::FillOptionsT *AsFillOptions() + { + return type == BuiltinOptions_FillOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::FillOptionsT *AsFillOptions() const + { + return type == BuiltinOptions_FillOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::BidirectionalSequenceLSTMOptionsT *AsBidirectionalSequenceLSTMOptions() + { + return type == BuiltinOptions_BidirectionalSequenceLSTMOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::BidirectionalSequenceLSTMOptionsT *AsBidirectionalSequenceLSTMOptions() const + { + return type == BuiltinOptions_BidirectionalSequenceLSTMOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::BidirectionalSequenceRNNOptionsT *AsBidirectionalSequenceRNNOptions() + { + return type == BuiltinOptions_BidirectionalSequenceRNNOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::BidirectionalSequenceRNNOptionsT *AsBidirectionalSequenceRNNOptions() const + { + return type == BuiltinOptions_BidirectionalSequenceRNNOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::UnidirectionalSequenceLSTMOptionsT *AsUnidirectionalSequenceLSTMOptions() + { + return type == BuiltinOptions_UnidirectionalSequenceLSTMOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::UnidirectionalSequenceLSTMOptionsT *AsUnidirectionalSequenceLSTMOptions() const + { + return type == BuiltinOptions_UnidirectionalSequenceLSTMOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::FloorModOptionsT *AsFloorModOptions() + { + return type == BuiltinOptions_FloorModOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::FloorModOptionsT *AsFloorModOptions() const + { + return type == BuiltinOptions_FloorModOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::RangeOptionsT *AsRangeOptions() + { + return type == BuiltinOptions_RangeOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::RangeOptionsT *AsRangeOptions() const + { + return type == BuiltinOptions_RangeOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::ResizeNearestNeighborOptionsT *AsResizeNearestNeighborOptions() + { + return type == BuiltinOptions_ResizeNearestNeighborOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::ResizeNearestNeighborOptionsT *AsResizeNearestNeighborOptions() const + { + return type == BuiltinOptions_ResizeNearestNeighborOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::LeakyReluOptionsT *AsLeakyReluOptions() + { + return type == BuiltinOptions_LeakyReluOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::LeakyReluOptionsT *AsLeakyReluOptions() const + { + return type == BuiltinOptions_LeakyReluOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::SquaredDifferenceOptionsT *AsSquaredDifferenceOptions() + { + return type == BuiltinOptions_SquaredDifferenceOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::SquaredDifferenceOptionsT *AsSquaredDifferenceOptions() const + { + return type == BuiltinOptions_SquaredDifferenceOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::MirrorPadOptionsT *AsMirrorPadOptions() + { + return type == BuiltinOptions_MirrorPadOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::MirrorPadOptionsT *AsMirrorPadOptions() const + { + return type == BuiltinOptions_MirrorPadOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::AbsOptionsT *AsAbsOptions() + { + return type == BuiltinOptions_AbsOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::AbsOptionsT *AsAbsOptions() const + { + return type == BuiltinOptions_AbsOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::SplitVOptionsT *AsSplitVOptions() + { + return type == BuiltinOptions_SplitVOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::SplitVOptionsT *AsSplitVOptions() const + { + return type == BuiltinOptions_SplitVOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::UniqueOptionsT *AsUniqueOptions() + { + return type == BuiltinOptions_UniqueOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::UniqueOptionsT *AsUniqueOptions() const + { + return type == BuiltinOptions_UniqueOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::ReverseV2OptionsT *AsReverseV2Options() + { + return type == BuiltinOptions_ReverseV2Options ? + reinterpret_cast(value) : + nullptr; + } + const tflite::ReverseV2OptionsT *AsReverseV2Options() const + { + return type == BuiltinOptions_ReverseV2Options ? + reinterpret_cast(value) : + nullptr; + } + tflite::AddNOptionsT *AsAddNOptions() + { + return type == BuiltinOptions_AddNOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::AddNOptionsT *AsAddNOptions() const + { + return type == BuiltinOptions_AddNOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::GatherNdOptionsT *AsGatherNdOptions() + { + return type == BuiltinOptions_GatherNdOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::GatherNdOptionsT *AsGatherNdOptions() const + { + return type == BuiltinOptions_GatherNdOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::CosOptionsT *AsCosOptions() + { + return type == BuiltinOptions_CosOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::CosOptionsT *AsCosOptions() const + { + return type == BuiltinOptions_CosOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::WhereOptionsT *AsWhereOptions() + { + return type == BuiltinOptions_WhereOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::WhereOptionsT *AsWhereOptions() const + { + return type == BuiltinOptions_WhereOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::RankOptionsT *AsRankOptions() + { + return type == BuiltinOptions_RankOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::RankOptionsT *AsRankOptions() const + { + return type == BuiltinOptions_RankOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::ReverseSequenceOptionsT *AsReverseSequenceOptions() + { + return type == BuiltinOptions_ReverseSequenceOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::ReverseSequenceOptionsT *AsReverseSequenceOptions() const + { + return type == BuiltinOptions_ReverseSequenceOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::MatrixDiagOptionsT *AsMatrixDiagOptions() + { + return type == BuiltinOptions_MatrixDiagOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::MatrixDiagOptionsT *AsMatrixDiagOptions() const + { + return type == BuiltinOptions_MatrixDiagOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::QuantizeOptionsT *AsQuantizeOptions() + { + return type == BuiltinOptions_QuantizeOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::QuantizeOptionsT *AsQuantizeOptions() const + { + return type == BuiltinOptions_QuantizeOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::MatrixSetDiagOptionsT *AsMatrixSetDiagOptions() + { + return type == BuiltinOptions_MatrixSetDiagOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::MatrixSetDiagOptionsT *AsMatrixSetDiagOptions() const + { + return type == BuiltinOptions_MatrixSetDiagOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::HardSwishOptionsT *AsHardSwishOptions() + { + return type == BuiltinOptions_HardSwishOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::HardSwishOptionsT *AsHardSwishOptions() const + { + return type == BuiltinOptions_HardSwishOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::IfOptionsT *AsIfOptions() + { + return type == BuiltinOptions_IfOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::IfOptionsT *AsIfOptions() const + { + return type == BuiltinOptions_IfOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::WhileOptionsT *AsWhileOptions() + { + return type == BuiltinOptions_WhileOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::WhileOptionsT *AsWhileOptions() const + { + return type == BuiltinOptions_WhileOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::DepthToSpaceOptionsT *AsDepthToSpaceOptions() + { + return type == BuiltinOptions_DepthToSpaceOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::DepthToSpaceOptionsT *AsDepthToSpaceOptions() const + { + return type == BuiltinOptions_DepthToSpaceOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::NonMaxSuppressionV4OptionsT *AsNonMaxSuppressionV4Options() + { + return type == BuiltinOptions_NonMaxSuppressionV4Options ? + reinterpret_cast(value) : + nullptr; + } + const tflite::NonMaxSuppressionV4OptionsT *AsNonMaxSuppressionV4Options() const + { + return type == BuiltinOptions_NonMaxSuppressionV4Options ? + reinterpret_cast(value) : + nullptr; + } + tflite::NonMaxSuppressionV5OptionsT *AsNonMaxSuppressionV5Options() + { + return type == BuiltinOptions_NonMaxSuppressionV5Options ? + reinterpret_cast(value) : + nullptr; + } + const tflite::NonMaxSuppressionV5OptionsT *AsNonMaxSuppressionV5Options() const + { + return type == BuiltinOptions_NonMaxSuppressionV5Options ? + reinterpret_cast(value) : + nullptr; + } + tflite::ScatterNdOptionsT *AsScatterNdOptions() + { + return type == BuiltinOptions_ScatterNdOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::ScatterNdOptionsT *AsScatterNdOptions() const + { + return type == BuiltinOptions_ScatterNdOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::SelectV2OptionsT *AsSelectV2Options() + { + return type == BuiltinOptions_SelectV2Options ? + reinterpret_cast(value) : + nullptr; + } + const tflite::SelectV2OptionsT *AsSelectV2Options() const + { + return type == BuiltinOptions_SelectV2Options ? + reinterpret_cast(value) : + nullptr; + } + tflite::DensifyOptionsT *AsDensifyOptions() + { + return type == BuiltinOptions_DensifyOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::DensifyOptionsT *AsDensifyOptions() const + { + return type == BuiltinOptions_DensifyOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::SegmentSumOptionsT *AsSegmentSumOptions() + { + return type == BuiltinOptions_SegmentSumOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::SegmentSumOptionsT *AsSegmentSumOptions() const + { + return type == BuiltinOptions_SegmentSumOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::BatchMatMulOptionsT *AsBatchMatMulOptions() + { + return type == BuiltinOptions_BatchMatMulOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::BatchMatMulOptionsT *AsBatchMatMulOptions() const + { + return type == BuiltinOptions_BatchMatMulOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::CumsumOptionsT *AsCumsumOptions() + { + return type == BuiltinOptions_CumsumOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::CumsumOptionsT *AsCumsumOptions() const + { + return type == BuiltinOptions_CumsumOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::CallOnceOptionsT *AsCallOnceOptions() + { + return type == BuiltinOptions_CallOnceOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::CallOnceOptionsT *AsCallOnceOptions() const + { + return type == BuiltinOptions_CallOnceOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::BroadcastToOptionsT *AsBroadcastToOptions() + { + return type == BuiltinOptions_BroadcastToOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::BroadcastToOptionsT *AsBroadcastToOptions() const + { + return type == BuiltinOptions_BroadcastToOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::Rfft2dOptionsT *AsRfft2dOptions() + { + return type == BuiltinOptions_Rfft2dOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::Rfft2dOptionsT *AsRfft2dOptions() const + { + return type == BuiltinOptions_Rfft2dOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::Conv3DOptionsT *AsConv3DOptions() + { + return type == BuiltinOptions_Conv3DOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::Conv3DOptionsT *AsConv3DOptions() const + { + return type == BuiltinOptions_Conv3DOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::HashtableOptionsT *AsHashtableOptions() + { + return type == BuiltinOptions_HashtableOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::HashtableOptionsT *AsHashtableOptions() const + { + return type == BuiltinOptions_HashtableOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::HashtableFindOptionsT *AsHashtableFindOptions() + { + return type == BuiltinOptions_HashtableFindOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::HashtableFindOptionsT *AsHashtableFindOptions() const + { + return type == BuiltinOptions_HashtableFindOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::HashtableImportOptionsT *AsHashtableImportOptions() + { + return type == BuiltinOptions_HashtableImportOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::HashtableImportOptionsT *AsHashtableImportOptions() const + { + return type == BuiltinOptions_HashtableImportOptions ? + reinterpret_cast(value) : + nullptr; + } + tflite::HashtableSizeOptionsT *AsHashtableSizeOptions() + { + return type == BuiltinOptions_HashtableSizeOptions ? + reinterpret_cast(value) : + nullptr; + } + const tflite::HashtableSizeOptionsT *AsHashtableSizeOptions() const + { + return type == BuiltinOptions_HashtableSizeOptions ? + reinterpret_cast(value) : + nullptr; + } +}; + +bool VerifyBuiltinOptions(flatbuffers::Verifier &verifier, const void *obj, BuiltinOptions type); +bool VerifyBuiltinOptionsVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector > *values, const flatbuffers::Vector *types); + +enum Padding { + Padding_SAME = 0, + Padding_VALID = 1, + Padding_MIN = Padding_SAME, + Padding_MAX = Padding_VALID +}; + +inline const Padding (&EnumValuesPadding())[2] +{ + static const Padding values[] = { + Padding_SAME, + Padding_VALID + }; + return values; +} + +inline const char *const *EnumNamesPadding() +{ + static const char *const names[3] = { + "SAME", + "VALID", + nullptr + }; + return names; +} + +inline const char *EnumNamePadding(Padding e) +{ + if (flatbuffers::IsOutRange(e, Padding_SAME, Padding_VALID)) + return ""; + const size_t index = static_cast(e); + return EnumNamesPadding()[index]; +} + +enum ActivationFunctionType { + ActivationFunctionType_NONE = 0, + ActivationFunctionType_RELU = 1, + ActivationFunctionType_RELU_N1_TO_1 = 2, + ActivationFunctionType_RELU6 = 3, + ActivationFunctionType_TANH = 4, + ActivationFunctionType_SIGN_BIT = 5, + ActivationFunctionType_MIN = ActivationFunctionType_NONE, + ActivationFunctionType_MAX = ActivationFunctionType_SIGN_BIT +}; + +inline const ActivationFunctionType (&EnumValuesActivationFunctionType())[6] +{ + static const ActivationFunctionType values[] = { + ActivationFunctionType_NONE, + ActivationFunctionType_RELU, + ActivationFunctionType_RELU_N1_TO_1, + ActivationFunctionType_RELU6, + ActivationFunctionType_TANH, + ActivationFunctionType_SIGN_BIT + }; + return values; +} + +inline const char *const *EnumNamesActivationFunctionType() +{ + static const char *const names[7] = { + "NONE", + "RELU", + "RELU_N1_TO_1", + "RELU6", + "TANH", + "SIGN_BIT", + nullptr + }; + return names; +} + +inline const char *EnumNameActivationFunctionType(ActivationFunctionType e) +{ + if (flatbuffers::IsOutRange(e, ActivationFunctionType_NONE, ActivationFunctionType_SIGN_BIT)) + return ""; + const size_t index = static_cast(e); + return EnumNamesActivationFunctionType()[index]; +} + +enum LSHProjectionType { + LSHProjectionType_UNKNOWN = 0, + LSHProjectionType_SPARSE = 1, + LSHProjectionType_DENSE = 2, + LSHProjectionType_MIN = LSHProjectionType_UNKNOWN, + LSHProjectionType_MAX = LSHProjectionType_DENSE +}; + +inline const LSHProjectionType (&EnumValuesLSHProjectionType())[3] +{ + static const LSHProjectionType values[] = { + LSHProjectionType_UNKNOWN, + LSHProjectionType_SPARSE, + LSHProjectionType_DENSE + }; + return values; +} + +inline const char *const *EnumNamesLSHProjectionType() +{ + static const char *const names[4] = { + "UNKNOWN", + "SPARSE", + "DENSE", + nullptr + }; + return names; +} + +inline const char *EnumNameLSHProjectionType(LSHProjectionType e) +{ + if (flatbuffers::IsOutRange(e, LSHProjectionType_UNKNOWN, LSHProjectionType_DENSE)) + return ""; + const size_t index = static_cast(e); + return EnumNamesLSHProjectionType()[index]; +} + +enum FullyConnectedOptionsWeightsFormat { + FullyConnectedOptionsWeightsFormat_DEFAULT = 0, + FullyConnectedOptionsWeightsFormat_SHUFFLED4x16INT8 = 1, + FullyConnectedOptionsWeightsFormat_MIN = FullyConnectedOptionsWeightsFormat_DEFAULT, + FullyConnectedOptionsWeightsFormat_MAX = FullyConnectedOptionsWeightsFormat_SHUFFLED4x16INT8 +}; + +inline const FullyConnectedOptionsWeightsFormat (&EnumValuesFullyConnectedOptionsWeightsFormat())[2] +{ + static const FullyConnectedOptionsWeightsFormat values[] = { + FullyConnectedOptionsWeightsFormat_DEFAULT, + FullyConnectedOptionsWeightsFormat_SHUFFLED4x16INT8 + }; + return values; +} + +inline const char *const *EnumNamesFullyConnectedOptionsWeightsFormat() +{ + static const char *const names[3] = { + "DEFAULT", + "SHUFFLED4x16INT8", + nullptr + }; + return names; +} + +inline const char *EnumNameFullyConnectedOptionsWeightsFormat(FullyConnectedOptionsWeightsFormat e) +{ + if (flatbuffers::IsOutRange(e, FullyConnectedOptionsWeightsFormat_DEFAULT, FullyConnectedOptionsWeightsFormat_SHUFFLED4x16INT8)) + return ""; + const size_t index = static_cast(e); + return EnumNamesFullyConnectedOptionsWeightsFormat()[index]; +} + +enum LSTMKernelType { + LSTMKernelType_FULL = 0, + LSTMKernelType_BASIC = 1, + LSTMKernelType_MIN = LSTMKernelType_FULL, + LSTMKernelType_MAX = LSTMKernelType_BASIC +}; + +inline const LSTMKernelType (&EnumValuesLSTMKernelType())[2] +{ + static const LSTMKernelType values[] = { + LSTMKernelType_FULL, + LSTMKernelType_BASIC + }; + return values; +} + +inline const char *const *EnumNamesLSTMKernelType() +{ + static const char *const names[3] = { + "FULL", + "BASIC", + nullptr + }; + return names; +} + +inline const char *EnumNameLSTMKernelType(LSTMKernelType e) +{ + if (flatbuffers::IsOutRange(e, LSTMKernelType_FULL, LSTMKernelType_BASIC)) + return ""; + const size_t index = static_cast(e); + return EnumNamesLSTMKernelType()[index]; +} + +enum CombinerType { + CombinerType_SUM = 0, + CombinerType_MEAN = 1, + CombinerType_SQRTN = 2, + CombinerType_MIN = CombinerType_SUM, + CombinerType_MAX = CombinerType_SQRTN +}; + +inline const CombinerType (&EnumValuesCombinerType())[3] +{ + static const CombinerType values[] = { + CombinerType_SUM, + CombinerType_MEAN, + CombinerType_SQRTN + }; + return values; +} + +inline const char *const *EnumNamesCombinerType() +{ + static const char *const names[4] = { + "SUM", + "MEAN", + "SQRTN", + nullptr + }; + return names; +} + +inline const char *EnumNameCombinerType(CombinerType e) +{ + if (flatbuffers::IsOutRange(e, CombinerType_SUM, CombinerType_SQRTN)) + return ""; + const size_t index = static_cast(e); + return EnumNamesCombinerType()[index]; +} + +enum MirrorPadMode { + MirrorPadMode_REFLECT = 0, + MirrorPadMode_SYMMETRIC = 1, + MirrorPadMode_MIN = MirrorPadMode_REFLECT, + MirrorPadMode_MAX = MirrorPadMode_SYMMETRIC +}; + +inline const MirrorPadMode (&EnumValuesMirrorPadMode())[2] +{ + static const MirrorPadMode values[] = { + MirrorPadMode_REFLECT, + MirrorPadMode_SYMMETRIC + }; + return values; +} + +inline const char *const *EnumNamesMirrorPadMode() +{ + static const char *const names[3] = { + "REFLECT", + "SYMMETRIC", + nullptr + }; + return names; +} + +inline const char *EnumNameMirrorPadMode(MirrorPadMode e) +{ + if (flatbuffers::IsOutRange(e, MirrorPadMode_REFLECT, MirrorPadMode_SYMMETRIC)) + return ""; + const size_t index = static_cast(e); + return EnumNamesMirrorPadMode()[index]; +} + +enum CustomOptionsFormat { + CustomOptionsFormat_FLEXBUFFERS = 0, + CustomOptionsFormat_MIN = CustomOptionsFormat_FLEXBUFFERS, + CustomOptionsFormat_MAX = CustomOptionsFormat_FLEXBUFFERS +}; + +inline const CustomOptionsFormat (&EnumValuesCustomOptionsFormat())[1] +{ + static const CustomOptionsFormat values[] = { + CustomOptionsFormat_FLEXBUFFERS + }; + return values; +} + +inline const char *const *EnumNamesCustomOptionsFormat() +{ + static const char *const names[2] = { + "FLEXBUFFERS", + nullptr + }; + return names; +} + +inline const char *EnumNameCustomOptionsFormat(CustomOptionsFormat e) +{ + if (flatbuffers::IsOutRange(e, CustomOptionsFormat_FLEXBUFFERS, CustomOptionsFormat_FLEXBUFFERS)) + return ""; + const size_t index = static_cast(e); + return EnumNamesCustomOptionsFormat()[index]; +} + +struct CustomQuantizationT : public flatbuffers::NativeTable { + typedef CustomQuantization TableType; + std::vector custom; + CustomQuantizationT() + { + } +}; + +struct CustomQuantization FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef CustomQuantizationT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_CUSTOM = 4 + }; + const flatbuffers::Vector *custom() const + { + return GetPointer *>(VT_CUSTOM); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_CUSTOM) && + verifier.VerifyVector(custom()) && + verifier.EndTable(); + } + CustomQuantizationT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(CustomQuantizationT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const CustomQuantizationT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct CustomQuantizationBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_custom(flatbuffers::Offset > custom) + { + fbb_.AddOffset(CustomQuantization::VT_CUSTOM, custom); + } + explicit CustomQuantizationBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + CustomQuantizationBuilder &operator=(const CustomQuantizationBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateCustomQuantization( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset > custom = 0) +{ + CustomQuantizationBuilder builder_(_fbb); + builder_.add_custom(custom); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateCustomQuantizationDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const std::vector *custom = nullptr) +{ + if (custom) { + _fbb.ForceVectorAlignment(custom->size(), sizeof(uint8_t), 16); + } + auto custom__ = custom ? _fbb.CreateVector(*custom) : 0; + return tflite::CreateCustomQuantization( + _fbb, + custom__); +} + +flatbuffers::Offset CreateCustomQuantization(flatbuffers::FlatBufferBuilder &_fbb, const CustomQuantizationT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct QuantizationParametersT : public flatbuffers::NativeTable { + typedef QuantizationParameters TableType; + std::vector min; + std::vector max; + std::vector scale; + std::vector zero_point; + tflite::QuantizationDetailsUnion details; + int32_t quantized_dimension; + QuantizationParametersT() + : quantized_dimension(0) + { + } +}; + +struct QuantizationParameters FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef QuantizationParametersT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_MIN = 4, + VT_MAX = 6, + VT_SCALE = 8, + VT_ZERO_POINT = 10, + VT_DETAILS_TYPE = 12, + VT_DETAILS = 14, + VT_QUANTIZED_DIMENSION = 16 + }; + const flatbuffers::Vector *min() const + { + return GetPointer *>(VT_MIN); + } + const flatbuffers::Vector *max() const + { + return GetPointer *>(VT_MAX); + } + const flatbuffers::Vector *scale() const + { + return GetPointer *>(VT_SCALE); + } + const flatbuffers::Vector *zero_point() const + { + return GetPointer *>(VT_ZERO_POINT); + } + tflite::QuantizationDetails details_type() const + { + return static_cast(GetField(VT_DETAILS_TYPE, 0)); + } + const void *details() const + { + return GetPointer(VT_DETAILS); + } + template + const T *details_as() const; + const tflite::CustomQuantization *details_as_CustomQuantization() const + { + return details_type() == tflite::QuantizationDetails_CustomQuantization ? static_cast(details()) : nullptr; + } + int32_t quantized_dimension() const + { + return GetField(VT_QUANTIZED_DIMENSION, 0); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_MIN) && + verifier.VerifyVector(min()) && + VerifyOffset(verifier, VT_MAX) && + verifier.VerifyVector(max()) && + VerifyOffset(verifier, VT_SCALE) && + verifier.VerifyVector(scale()) && + VerifyOffset(verifier, VT_ZERO_POINT) && + verifier.VerifyVector(zero_point()) && + VerifyField(verifier, VT_DETAILS_TYPE) && + VerifyOffset(verifier, VT_DETAILS) && + VerifyQuantizationDetails(verifier, details(), details_type()) && + VerifyField(verifier, VT_QUANTIZED_DIMENSION) && + verifier.EndTable(); + } + QuantizationParametersT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(QuantizationParametersT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const QuantizationParametersT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +template <> +inline const tflite::CustomQuantization *QuantizationParameters::details_as() const +{ + return details_as_CustomQuantization(); +} + +struct QuantizationParametersBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_min(flatbuffers::Offset > min) + { + fbb_.AddOffset(QuantizationParameters::VT_MIN, min); + } + void add_max(flatbuffers::Offset > max) + { + fbb_.AddOffset(QuantizationParameters::VT_MAX, max); + } + void add_scale(flatbuffers::Offset > scale) + { + fbb_.AddOffset(QuantizationParameters::VT_SCALE, scale); + } + void add_zero_point(flatbuffers::Offset > zero_point) + { + fbb_.AddOffset(QuantizationParameters::VT_ZERO_POINT, zero_point); + } + void add_details_type(tflite::QuantizationDetails details_type) + { + fbb_.AddElement(QuantizationParameters::VT_DETAILS_TYPE, static_cast(details_type), 0); + } + void add_details(flatbuffers::Offset details) + { + fbb_.AddOffset(QuantizationParameters::VT_DETAILS, details); + } + void add_quantized_dimension(int32_t quantized_dimension) + { + fbb_.AddElement(QuantizationParameters::VT_QUANTIZED_DIMENSION, quantized_dimension, 0); + } + explicit QuantizationParametersBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + QuantizationParametersBuilder &operator=(const QuantizationParametersBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateQuantizationParameters( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset > min = 0, + flatbuffers::Offset > max = 0, + flatbuffers::Offset > scale = 0, + flatbuffers::Offset > zero_point = 0, + tflite::QuantizationDetails details_type = tflite::QuantizationDetails_NONE, + flatbuffers::Offset details = 0, + int32_t quantized_dimension = 0) +{ + QuantizationParametersBuilder builder_(_fbb); + builder_.add_quantized_dimension(quantized_dimension); + builder_.add_details(details); + builder_.add_zero_point(zero_point); + builder_.add_scale(scale); + builder_.add_max(max); + builder_.add_min(min); + builder_.add_details_type(details_type); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateQuantizationParametersDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const std::vector *min = nullptr, + const std::vector *max = nullptr, + const std::vector *scale = nullptr, + const std::vector *zero_point = nullptr, + tflite::QuantizationDetails details_type = tflite::QuantizationDetails_NONE, + flatbuffers::Offset details = 0, + int32_t quantized_dimension = 0) +{ + auto min__ = min ? _fbb.CreateVector(*min) : 0; + auto max__ = max ? _fbb.CreateVector(*max) : 0; + auto scale__ = scale ? _fbb.CreateVector(*scale) : 0; + auto zero_point__ = zero_point ? _fbb.CreateVector(*zero_point) : 0; + return tflite::CreateQuantizationParameters( + _fbb, + min__, + max__, + scale__, + zero_point__, + details_type, + details, + quantized_dimension); +} + +flatbuffers::Offset CreateQuantizationParameters(flatbuffers::FlatBufferBuilder &_fbb, const QuantizationParametersT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct Int32VectorT : public flatbuffers::NativeTable { + typedef Int32Vector TableType; + std::vector values; + Int32VectorT() + { + } +}; + +struct Int32Vector FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef Int32VectorT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_VALUES = 4 + }; + const flatbuffers::Vector *values() const + { + return GetPointer *>(VT_VALUES); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_VALUES) && + verifier.VerifyVector(values()) && + verifier.EndTable(); + } + Int32VectorT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(Int32VectorT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const Int32VectorT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct Int32VectorBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_values(flatbuffers::Offset > values) + { + fbb_.AddOffset(Int32Vector::VT_VALUES, values); + } + explicit Int32VectorBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + Int32VectorBuilder &operator=(const Int32VectorBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateInt32Vector( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset > values = 0) +{ + Int32VectorBuilder builder_(_fbb); + builder_.add_values(values); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateInt32VectorDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const std::vector *values = nullptr) +{ + auto values__ = values ? _fbb.CreateVector(*values) : 0; + return tflite::CreateInt32Vector( + _fbb, + values__); +} + +flatbuffers::Offset CreateInt32Vector(flatbuffers::FlatBufferBuilder &_fbb, const Int32VectorT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct Uint16VectorT : public flatbuffers::NativeTable { + typedef Uint16Vector TableType; + std::vector values; + Uint16VectorT() + { + } +}; + +struct Uint16Vector FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef Uint16VectorT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_VALUES = 4 + }; + const flatbuffers::Vector *values() const + { + return GetPointer *>(VT_VALUES); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_VALUES) && + verifier.VerifyVector(values()) && + verifier.EndTable(); + } + Uint16VectorT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(Uint16VectorT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const Uint16VectorT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct Uint16VectorBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_values(flatbuffers::Offset > values) + { + fbb_.AddOffset(Uint16Vector::VT_VALUES, values); + } + explicit Uint16VectorBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + Uint16VectorBuilder &operator=(const Uint16VectorBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateUint16Vector( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset > values = 0) +{ + Uint16VectorBuilder builder_(_fbb); + builder_.add_values(values); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateUint16VectorDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const std::vector *values = nullptr) +{ + if (values) { + _fbb.ForceVectorAlignment(values->size(), sizeof(uint16_t), 4); + } + auto values__ = values ? _fbb.CreateVector(*values) : 0; + return tflite::CreateUint16Vector( + _fbb, + values__); +} + +flatbuffers::Offset CreateUint16Vector(flatbuffers::FlatBufferBuilder &_fbb, const Uint16VectorT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct Uint8VectorT : public flatbuffers::NativeTable { + typedef Uint8Vector TableType; + std::vector values; + Uint8VectorT() + { + } +}; + +struct Uint8Vector FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef Uint8VectorT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_VALUES = 4 + }; + const flatbuffers::Vector *values() const + { + return GetPointer *>(VT_VALUES); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_VALUES) && + verifier.VerifyVector(values()) && + verifier.EndTable(); + } + Uint8VectorT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(Uint8VectorT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const Uint8VectorT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct Uint8VectorBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_values(flatbuffers::Offset > values) + { + fbb_.AddOffset(Uint8Vector::VT_VALUES, values); + } + explicit Uint8VectorBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + Uint8VectorBuilder &operator=(const Uint8VectorBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateUint8Vector( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset > values = 0) +{ + Uint8VectorBuilder builder_(_fbb); + builder_.add_values(values); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateUint8VectorDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const std::vector *values = nullptr) +{ + if (values) { + _fbb.ForceVectorAlignment(values->size(), sizeof(uint8_t), 4); + } + auto values__ = values ? _fbb.CreateVector(*values) : 0; + return tflite::CreateUint8Vector( + _fbb, + values__); +} + +flatbuffers::Offset CreateUint8Vector(flatbuffers::FlatBufferBuilder &_fbb, const Uint8VectorT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct DimensionMetadataT : public flatbuffers::NativeTable { + typedef DimensionMetadata TableType; + tflite::DimensionType format; + int32_t dense_size; + tflite::SparseIndexVectorUnion array_segments; + tflite::SparseIndexVectorUnion array_indices; + DimensionMetadataT() + : format(tflite::DimensionType_DENSE), + dense_size(0) + { + } +}; + +struct DimensionMetadata FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef DimensionMetadataT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_FORMAT = 4, + VT_DENSE_SIZE = 6, + VT_ARRAY_SEGMENTS_TYPE = 8, + VT_ARRAY_SEGMENTS = 10, + VT_ARRAY_INDICES_TYPE = 12, + VT_ARRAY_INDICES = 14 + }; + tflite::DimensionType format() const + { + return static_cast(GetField(VT_FORMAT, 0)); + } + int32_t dense_size() const + { + return GetField(VT_DENSE_SIZE, 0); + } + tflite::SparseIndexVector array_segments_type() const + { + return static_cast(GetField(VT_ARRAY_SEGMENTS_TYPE, 0)); + } + const void *array_segments() const + { + return GetPointer(VT_ARRAY_SEGMENTS); + } + template + const T *array_segments_as() const; + const tflite::Int32Vector *array_segments_as_Int32Vector() const + { + return array_segments_type() == tflite::SparseIndexVector_Int32Vector ? static_cast(array_segments()) : nullptr; + } + const tflite::Uint16Vector *array_segments_as_Uint16Vector() const + { + return array_segments_type() == tflite::SparseIndexVector_Uint16Vector ? static_cast(array_segments()) : nullptr; + } + const tflite::Uint8Vector *array_segments_as_Uint8Vector() const + { + return array_segments_type() == tflite::SparseIndexVector_Uint8Vector ? static_cast(array_segments()) : nullptr; + } + tflite::SparseIndexVector array_indices_type() const + { + return static_cast(GetField(VT_ARRAY_INDICES_TYPE, 0)); + } + const void *array_indices() const + { + return GetPointer(VT_ARRAY_INDICES); + } + template + const T *array_indices_as() const; + const tflite::Int32Vector *array_indices_as_Int32Vector() const + { + return array_indices_type() == tflite::SparseIndexVector_Int32Vector ? static_cast(array_indices()) : nullptr; + } + const tflite::Uint16Vector *array_indices_as_Uint16Vector() const + { + return array_indices_type() == tflite::SparseIndexVector_Uint16Vector ? static_cast(array_indices()) : nullptr; + } + const tflite::Uint8Vector *array_indices_as_Uint8Vector() const + { + return array_indices_type() == tflite::SparseIndexVector_Uint8Vector ? static_cast(array_indices()) : nullptr; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FORMAT) && + VerifyField(verifier, VT_DENSE_SIZE) && + VerifyField(verifier, VT_ARRAY_SEGMENTS_TYPE) && + VerifyOffset(verifier, VT_ARRAY_SEGMENTS) && + VerifySparseIndexVector(verifier, array_segments(), array_segments_type()) && + VerifyField(verifier, VT_ARRAY_INDICES_TYPE) && + VerifyOffset(verifier, VT_ARRAY_INDICES) && + VerifySparseIndexVector(verifier, array_indices(), array_indices_type()) && + verifier.EndTable(); + } + DimensionMetadataT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(DimensionMetadataT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const DimensionMetadataT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +template <> +inline const tflite::Int32Vector *DimensionMetadata::array_segments_as() const +{ + return array_segments_as_Int32Vector(); +} + +template <> +inline const tflite::Uint16Vector *DimensionMetadata::array_segments_as() const +{ + return array_segments_as_Uint16Vector(); +} + +template <> +inline const tflite::Uint8Vector *DimensionMetadata::array_segments_as() const +{ + return array_segments_as_Uint8Vector(); +} + +template <> +inline const tflite::Int32Vector *DimensionMetadata::array_indices_as() const +{ + return array_indices_as_Int32Vector(); +} + +template <> +inline const tflite::Uint16Vector *DimensionMetadata::array_indices_as() const +{ + return array_indices_as_Uint16Vector(); +} + +template <> +inline const tflite::Uint8Vector *DimensionMetadata::array_indices_as() const +{ + return array_indices_as_Uint8Vector(); +} + +struct DimensionMetadataBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_format(tflite::DimensionType format) + { + fbb_.AddElement(DimensionMetadata::VT_FORMAT, static_cast(format), 0); + } + void add_dense_size(int32_t dense_size) + { + fbb_.AddElement(DimensionMetadata::VT_DENSE_SIZE, dense_size, 0); + } + void add_array_segments_type(tflite::SparseIndexVector array_segments_type) + { + fbb_.AddElement(DimensionMetadata::VT_ARRAY_SEGMENTS_TYPE, static_cast(array_segments_type), 0); + } + void add_array_segments(flatbuffers::Offset array_segments) + { + fbb_.AddOffset(DimensionMetadata::VT_ARRAY_SEGMENTS, array_segments); + } + void add_array_indices_type(tflite::SparseIndexVector array_indices_type) + { + fbb_.AddElement(DimensionMetadata::VT_ARRAY_INDICES_TYPE, static_cast(array_indices_type), 0); + } + void add_array_indices(flatbuffers::Offset array_indices) + { + fbb_.AddOffset(DimensionMetadata::VT_ARRAY_INDICES, array_indices); + } + explicit DimensionMetadataBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + DimensionMetadataBuilder &operator=(const DimensionMetadataBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateDimensionMetadata( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::DimensionType format = tflite::DimensionType_DENSE, + int32_t dense_size = 0, + tflite::SparseIndexVector array_segments_type = tflite::SparseIndexVector_NONE, + flatbuffers::Offset array_segments = 0, + tflite::SparseIndexVector array_indices_type = tflite::SparseIndexVector_NONE, + flatbuffers::Offset array_indices = 0) +{ + DimensionMetadataBuilder builder_(_fbb); + builder_.add_array_indices(array_indices); + builder_.add_array_segments(array_segments); + builder_.add_dense_size(dense_size); + builder_.add_array_indices_type(array_indices_type); + builder_.add_array_segments_type(array_segments_type); + builder_.add_format(format); + return builder_.Finish(); +} + +flatbuffers::Offset CreateDimensionMetadata(flatbuffers::FlatBufferBuilder &_fbb, const DimensionMetadataT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct SparsityParametersT : public flatbuffers::NativeTable { + typedef SparsityParameters TableType; + std::vector traversal_order; + std::vector block_map; + std::vector > dim_metadata; + SparsityParametersT() + { + } +}; + +struct SparsityParameters FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef SparsityParametersT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_TRAVERSAL_ORDER = 4, + VT_BLOCK_MAP = 6, + VT_DIM_METADATA = 8 + }; + const flatbuffers::Vector *traversal_order() const + { + return GetPointer *>(VT_TRAVERSAL_ORDER); + } + const flatbuffers::Vector *block_map() const + { + return GetPointer *>(VT_BLOCK_MAP); + } + const flatbuffers::Vector > *dim_metadata() const + { + return GetPointer > *>(VT_DIM_METADATA); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_TRAVERSAL_ORDER) && + verifier.VerifyVector(traversal_order()) && + VerifyOffset(verifier, VT_BLOCK_MAP) && + verifier.VerifyVector(block_map()) && + VerifyOffset(verifier, VT_DIM_METADATA) && + verifier.VerifyVector(dim_metadata()) && + verifier.VerifyVectorOfTables(dim_metadata()) && + verifier.EndTable(); + } + SparsityParametersT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(SparsityParametersT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const SparsityParametersT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct SparsityParametersBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_traversal_order(flatbuffers::Offset > traversal_order) + { + fbb_.AddOffset(SparsityParameters::VT_TRAVERSAL_ORDER, traversal_order); + } + void add_block_map(flatbuffers::Offset > block_map) + { + fbb_.AddOffset(SparsityParameters::VT_BLOCK_MAP, block_map); + } + void add_dim_metadata(flatbuffers::Offset > > dim_metadata) + { + fbb_.AddOffset(SparsityParameters::VT_DIM_METADATA, dim_metadata); + } + explicit SparsityParametersBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SparsityParametersBuilder &operator=(const SparsityParametersBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateSparsityParameters( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset > traversal_order = 0, + flatbuffers::Offset > block_map = 0, + flatbuffers::Offset > > dim_metadata = 0) +{ + SparsityParametersBuilder builder_(_fbb); + builder_.add_dim_metadata(dim_metadata); + builder_.add_block_map(block_map); + builder_.add_traversal_order(traversal_order); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateSparsityParametersDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const std::vector *traversal_order = nullptr, + const std::vector *block_map = nullptr, + const std::vector > *dim_metadata = nullptr) +{ + auto traversal_order__ = traversal_order ? _fbb.CreateVector(*traversal_order) : 0; + auto block_map__ = block_map ? _fbb.CreateVector(*block_map) : 0; + auto dim_metadata__ = dim_metadata ? _fbb.CreateVector >(*dim_metadata) : 0; + return tflite::CreateSparsityParameters( + _fbb, + traversal_order__, + block_map__, + dim_metadata__); +} + +flatbuffers::Offset CreateSparsityParameters(flatbuffers::FlatBufferBuilder &_fbb, const SparsityParametersT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct TensorT : public flatbuffers::NativeTable { + typedef Tensor TableType; + std::vector shape; + tflite::TensorType type; + uint32_t buffer; + std::string name; + std::unique_ptr quantization; + bool is_variable; + std::unique_ptr sparsity; + std::vector shape_signature; + TensorT() + : type(tflite::TensorType_FLOAT32), + buffer(0), + is_variable(false) + { + } +}; + +struct Tensor FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef TensorT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_SHAPE = 4, + VT_TYPE = 6, + VT_BUFFER = 8, + VT_NAME = 10, + VT_QUANTIZATION = 12, + VT_IS_VARIABLE = 14, + VT_SPARSITY = 16, + VT_SHAPE_SIGNATURE = 18 + }; + const flatbuffers::Vector *shape() const + { + return GetPointer *>(VT_SHAPE); + } + tflite::TensorType type() const + { + return static_cast(GetField(VT_TYPE, 0)); + } + uint32_t buffer() const + { + return GetField(VT_BUFFER, 0); + } + const flatbuffers::String *name() const + { + return GetPointer(VT_NAME); + } + const tflite::QuantizationParameters *quantization() const + { + return GetPointer(VT_QUANTIZATION); + } + bool is_variable() const + { + return GetField(VT_IS_VARIABLE, 0) != 0; + } + const tflite::SparsityParameters *sparsity() const + { + return GetPointer(VT_SPARSITY); + } + const flatbuffers::Vector *shape_signature() const + { + return GetPointer *>(VT_SHAPE_SIGNATURE); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_SHAPE) && + verifier.VerifyVector(shape()) && + VerifyField(verifier, VT_TYPE) && + VerifyField(verifier, VT_BUFFER) && + VerifyOffset(verifier, VT_NAME) && + verifier.VerifyString(name()) && + VerifyOffset(verifier, VT_QUANTIZATION) && + verifier.VerifyTable(quantization()) && + VerifyField(verifier, VT_IS_VARIABLE) && + VerifyOffset(verifier, VT_SPARSITY) && + verifier.VerifyTable(sparsity()) && + VerifyOffset(verifier, VT_SHAPE_SIGNATURE) && + verifier.VerifyVector(shape_signature()) && + verifier.EndTable(); + } + TensorT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(TensorT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const TensorT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct TensorBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_shape(flatbuffers::Offset > shape) + { + fbb_.AddOffset(Tensor::VT_SHAPE, shape); + } + void add_type(tflite::TensorType type) + { + fbb_.AddElement(Tensor::VT_TYPE, static_cast(type), 0); + } + void add_buffer(uint32_t buffer) + { + fbb_.AddElement(Tensor::VT_BUFFER, buffer, 0); + } + void add_name(flatbuffers::Offset name) + { + fbb_.AddOffset(Tensor::VT_NAME, name); + } + void add_quantization(flatbuffers::Offset quantization) + { + fbb_.AddOffset(Tensor::VT_QUANTIZATION, quantization); + } + void add_is_variable(bool is_variable) + { + fbb_.AddElement(Tensor::VT_IS_VARIABLE, static_cast(is_variable), 0); + } + void add_sparsity(flatbuffers::Offset sparsity) + { + fbb_.AddOffset(Tensor::VT_SPARSITY, sparsity); + } + void add_shape_signature(flatbuffers::Offset > shape_signature) + { + fbb_.AddOffset(Tensor::VT_SHAPE_SIGNATURE, shape_signature); + } + explicit TensorBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + TensorBuilder &operator=(const TensorBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateTensor( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset > shape = 0, + tflite::TensorType type = tflite::TensorType_FLOAT32, + uint32_t buffer = 0, + flatbuffers::Offset name = 0, + flatbuffers::Offset quantization = 0, + bool is_variable = false, + flatbuffers::Offset sparsity = 0, + flatbuffers::Offset > shape_signature = 0) +{ + TensorBuilder builder_(_fbb); + builder_.add_shape_signature(shape_signature); + builder_.add_sparsity(sparsity); + builder_.add_quantization(quantization); + builder_.add_name(name); + builder_.add_buffer(buffer); + builder_.add_shape(shape); + builder_.add_is_variable(is_variable); + builder_.add_type(type); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateTensorDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const std::vector *shape = nullptr, + tflite::TensorType type = tflite::TensorType_FLOAT32, + uint32_t buffer = 0, + const char *name = nullptr, + flatbuffers::Offset quantization = 0, + bool is_variable = false, + flatbuffers::Offset sparsity = 0, + const std::vector *shape_signature = nullptr) +{ + auto shape__ = shape ? _fbb.CreateVector(*shape) : 0; + auto name__ = name ? _fbb.CreateString(name) : 0; + auto shape_signature__ = shape_signature ? _fbb.CreateVector(*shape_signature) : 0; + return tflite::CreateTensor( + _fbb, + shape__, + type, + buffer, + name__, + quantization, + is_variable, + sparsity, + shape_signature__); +} + +flatbuffers::Offset CreateTensor(flatbuffers::FlatBufferBuilder &_fbb, const TensorT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct Conv2DOptionsT : public flatbuffers::NativeTable { + typedef Conv2DOptions TableType; + tflite::Padding padding; + int32_t stride_w; + int32_t stride_h; + tflite::ActivationFunctionType fused_activation_function; + int32_t dilation_w_factor; + int32_t dilation_h_factor; + Conv2DOptionsT() + : padding(tflite::Padding_SAME), + stride_w(0), + stride_h(0), + fused_activation_function(tflite::ActivationFunctionType_NONE), + dilation_w_factor(1), + dilation_h_factor(1) + { + } +}; + +struct Conv2DOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef Conv2DOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_PADDING = 4, + VT_STRIDE_W = 6, + VT_STRIDE_H = 8, + VT_FUSED_ACTIVATION_FUNCTION = 10, + VT_DILATION_W_FACTOR = 12, + VT_DILATION_H_FACTOR = 14 + }; + tflite::Padding padding() const + { + return static_cast(GetField(VT_PADDING, 0)); + } + int32_t stride_w() const + { + return GetField(VT_STRIDE_W, 0); + } + int32_t stride_h() const + { + return GetField(VT_STRIDE_H, 0); + } + tflite::ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + int32_t dilation_w_factor() const + { + return GetField(VT_DILATION_W_FACTOR, 1); + } + int32_t dilation_h_factor() const + { + return GetField(VT_DILATION_H_FACTOR, 1); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_PADDING) && + VerifyField(verifier, VT_STRIDE_W) && + VerifyField(verifier, VT_STRIDE_H) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_DILATION_W_FACTOR) && + VerifyField(verifier, VT_DILATION_H_FACTOR) && + verifier.EndTable(); + } + Conv2DOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(Conv2DOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const Conv2DOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct Conv2DOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_padding(tflite::Padding padding) + { + fbb_.AddElement(Conv2DOptions::VT_PADDING, static_cast(padding), 0); + } + void add_stride_w(int32_t stride_w) + { + fbb_.AddElement(Conv2DOptions::VT_STRIDE_W, stride_w, 0); + } + void add_stride_h(int32_t stride_h) + { + fbb_.AddElement(Conv2DOptions::VT_STRIDE_H, stride_h, 0); + } + void add_fused_activation_function(tflite::ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(Conv2DOptions::VT_FUSED_ACTIVATION_FUNCTION, static_cast(fused_activation_function), 0); + } + void add_dilation_w_factor(int32_t dilation_w_factor) + { + fbb_.AddElement(Conv2DOptions::VT_DILATION_W_FACTOR, dilation_w_factor, 1); + } + void add_dilation_h_factor(int32_t dilation_h_factor) + { + fbb_.AddElement(Conv2DOptions::VT_DILATION_H_FACTOR, dilation_h_factor, 1); + } + explicit Conv2DOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + Conv2DOptionsBuilder &operator=(const Conv2DOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateConv2DOptions( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::Padding padding = tflite::Padding_SAME, + int32_t stride_w = 0, + int32_t stride_h = 0, + tflite::ActivationFunctionType fused_activation_function = tflite::ActivationFunctionType_NONE, + int32_t dilation_w_factor = 1, + int32_t dilation_h_factor = 1) +{ + Conv2DOptionsBuilder builder_(_fbb); + builder_.add_dilation_h_factor(dilation_h_factor); + builder_.add_dilation_w_factor(dilation_w_factor); + builder_.add_stride_h(stride_h); + builder_.add_stride_w(stride_w); + builder_.add_fused_activation_function(fused_activation_function); + builder_.add_padding(padding); + return builder_.Finish(); +} + +flatbuffers::Offset CreateConv2DOptions(flatbuffers::FlatBufferBuilder &_fbb, const Conv2DOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct Conv3DOptionsT : public flatbuffers::NativeTable { + typedef Conv3DOptions TableType; + tflite::Padding padding; + int32_t stride_d; + int32_t stride_w; + int32_t stride_h; + tflite::ActivationFunctionType fused_activation_function; + int32_t dilation_d_factor; + int32_t dilation_w_factor; + int32_t dilation_h_factor; + Conv3DOptionsT() + : padding(tflite::Padding_SAME), + stride_d(0), + stride_w(0), + stride_h(0), + fused_activation_function(tflite::ActivationFunctionType_NONE), + dilation_d_factor(1), + dilation_w_factor(1), + dilation_h_factor(1) + { + } +}; + +struct Conv3DOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef Conv3DOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_PADDING = 4, + VT_STRIDE_D = 6, + VT_STRIDE_W = 8, + VT_STRIDE_H = 10, + VT_FUSED_ACTIVATION_FUNCTION = 12, + VT_DILATION_D_FACTOR = 14, + VT_DILATION_W_FACTOR = 16, + VT_DILATION_H_FACTOR = 18 + }; + tflite::Padding padding() const + { + return static_cast(GetField(VT_PADDING, 0)); + } + int32_t stride_d() const + { + return GetField(VT_STRIDE_D, 0); + } + int32_t stride_w() const + { + return GetField(VT_STRIDE_W, 0); + } + int32_t stride_h() const + { + return GetField(VT_STRIDE_H, 0); + } + tflite::ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + int32_t dilation_d_factor() const + { + return GetField(VT_DILATION_D_FACTOR, 1); + } + int32_t dilation_w_factor() const + { + return GetField(VT_DILATION_W_FACTOR, 1); + } + int32_t dilation_h_factor() const + { + return GetField(VT_DILATION_H_FACTOR, 1); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_PADDING) && + VerifyField(verifier, VT_STRIDE_D) && + VerifyField(verifier, VT_STRIDE_W) && + VerifyField(verifier, VT_STRIDE_H) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_DILATION_D_FACTOR) && + VerifyField(verifier, VT_DILATION_W_FACTOR) && + VerifyField(verifier, VT_DILATION_H_FACTOR) && + verifier.EndTable(); + } + Conv3DOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(Conv3DOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const Conv3DOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct Conv3DOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_padding(tflite::Padding padding) + { + fbb_.AddElement(Conv3DOptions::VT_PADDING, static_cast(padding), 0); + } + void add_stride_d(int32_t stride_d) + { + fbb_.AddElement(Conv3DOptions::VT_STRIDE_D, stride_d, 0); + } + void add_stride_w(int32_t stride_w) + { + fbb_.AddElement(Conv3DOptions::VT_STRIDE_W, stride_w, 0); + } + void add_stride_h(int32_t stride_h) + { + fbb_.AddElement(Conv3DOptions::VT_STRIDE_H, stride_h, 0); + } + void add_fused_activation_function(tflite::ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(Conv3DOptions::VT_FUSED_ACTIVATION_FUNCTION, static_cast(fused_activation_function), 0); + } + void add_dilation_d_factor(int32_t dilation_d_factor) + { + fbb_.AddElement(Conv3DOptions::VT_DILATION_D_FACTOR, dilation_d_factor, 1); + } + void add_dilation_w_factor(int32_t dilation_w_factor) + { + fbb_.AddElement(Conv3DOptions::VT_DILATION_W_FACTOR, dilation_w_factor, 1); + } + void add_dilation_h_factor(int32_t dilation_h_factor) + { + fbb_.AddElement(Conv3DOptions::VT_DILATION_H_FACTOR, dilation_h_factor, 1); + } + explicit Conv3DOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + Conv3DOptionsBuilder &operator=(const Conv3DOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateConv3DOptions( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::Padding padding = tflite::Padding_SAME, + int32_t stride_d = 0, + int32_t stride_w = 0, + int32_t stride_h = 0, + tflite::ActivationFunctionType fused_activation_function = tflite::ActivationFunctionType_NONE, + int32_t dilation_d_factor = 1, + int32_t dilation_w_factor = 1, + int32_t dilation_h_factor = 1) +{ + Conv3DOptionsBuilder builder_(_fbb); + builder_.add_dilation_h_factor(dilation_h_factor); + builder_.add_dilation_w_factor(dilation_w_factor); + builder_.add_dilation_d_factor(dilation_d_factor); + builder_.add_stride_h(stride_h); + builder_.add_stride_w(stride_w); + builder_.add_stride_d(stride_d); + builder_.add_fused_activation_function(fused_activation_function); + builder_.add_padding(padding); + return builder_.Finish(); +} + +flatbuffers::Offset CreateConv3DOptions(flatbuffers::FlatBufferBuilder &_fbb, const Conv3DOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct Pool2DOptionsT : public flatbuffers::NativeTable { + typedef Pool2DOptions TableType; + tflite::Padding padding; + int32_t stride_w; + int32_t stride_h; + int32_t filter_width; + int32_t filter_height; + tflite::ActivationFunctionType fused_activation_function; + Pool2DOptionsT() + : padding(tflite::Padding_SAME), + stride_w(0), + stride_h(0), + filter_width(0), + filter_height(0), + fused_activation_function(tflite::ActivationFunctionType_NONE) + { + } +}; + +struct Pool2DOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef Pool2DOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_PADDING = 4, + VT_STRIDE_W = 6, + VT_STRIDE_H = 8, + VT_FILTER_WIDTH = 10, + VT_FILTER_HEIGHT = 12, + VT_FUSED_ACTIVATION_FUNCTION = 14 + }; + tflite::Padding padding() const + { + return static_cast(GetField(VT_PADDING, 0)); + } + int32_t stride_w() const + { + return GetField(VT_STRIDE_W, 0); + } + int32_t stride_h() const + { + return GetField(VT_STRIDE_H, 0); + } + int32_t filter_width() const + { + return GetField(VT_FILTER_WIDTH, 0); + } + int32_t filter_height() const + { + return GetField(VT_FILTER_HEIGHT, 0); + } + tflite::ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_PADDING) && + VerifyField(verifier, VT_STRIDE_W) && + VerifyField(verifier, VT_STRIDE_H) && + VerifyField(verifier, VT_FILTER_WIDTH) && + VerifyField(verifier, VT_FILTER_HEIGHT) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + verifier.EndTable(); + } + Pool2DOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(Pool2DOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const Pool2DOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct Pool2DOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_padding(tflite::Padding padding) + { + fbb_.AddElement(Pool2DOptions::VT_PADDING, static_cast(padding), 0); + } + void add_stride_w(int32_t stride_w) + { + fbb_.AddElement(Pool2DOptions::VT_STRIDE_W, stride_w, 0); + } + void add_stride_h(int32_t stride_h) + { + fbb_.AddElement(Pool2DOptions::VT_STRIDE_H, stride_h, 0); + } + void add_filter_width(int32_t filter_width) + { + fbb_.AddElement(Pool2DOptions::VT_FILTER_WIDTH, filter_width, 0); + } + void add_filter_height(int32_t filter_height) + { + fbb_.AddElement(Pool2DOptions::VT_FILTER_HEIGHT, filter_height, 0); + } + void add_fused_activation_function(tflite::ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(Pool2DOptions::VT_FUSED_ACTIVATION_FUNCTION, static_cast(fused_activation_function), 0); + } + explicit Pool2DOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + Pool2DOptionsBuilder &operator=(const Pool2DOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreatePool2DOptions( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::Padding padding = tflite::Padding_SAME, + int32_t stride_w = 0, + int32_t stride_h = 0, + int32_t filter_width = 0, + int32_t filter_height = 0, + tflite::ActivationFunctionType fused_activation_function = tflite::ActivationFunctionType_NONE) +{ + Pool2DOptionsBuilder builder_(_fbb); + builder_.add_filter_height(filter_height); + builder_.add_filter_width(filter_width); + builder_.add_stride_h(stride_h); + builder_.add_stride_w(stride_w); + builder_.add_fused_activation_function(fused_activation_function); + builder_.add_padding(padding); + return builder_.Finish(); +} + +flatbuffers::Offset CreatePool2DOptions(flatbuffers::FlatBufferBuilder &_fbb, const Pool2DOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct DepthwiseConv2DOptionsT : public flatbuffers::NativeTable { + typedef DepthwiseConv2DOptions TableType; + tflite::Padding padding; + int32_t stride_w; + int32_t stride_h; + int32_t depth_multiplier; + tflite::ActivationFunctionType fused_activation_function; + int32_t dilation_w_factor; + int32_t dilation_h_factor; + DepthwiseConv2DOptionsT() + : padding(tflite::Padding_SAME), + stride_w(0), + stride_h(0), + depth_multiplier(0), + fused_activation_function(tflite::ActivationFunctionType_NONE), + dilation_w_factor(1), + dilation_h_factor(1) + { + } +}; + +struct DepthwiseConv2DOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef DepthwiseConv2DOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_PADDING = 4, + VT_STRIDE_W = 6, + VT_STRIDE_H = 8, + VT_DEPTH_MULTIPLIER = 10, + VT_FUSED_ACTIVATION_FUNCTION = 12, + VT_DILATION_W_FACTOR = 14, + VT_DILATION_H_FACTOR = 16 + }; + tflite::Padding padding() const + { + return static_cast(GetField(VT_PADDING, 0)); + } + int32_t stride_w() const + { + return GetField(VT_STRIDE_W, 0); + } + int32_t stride_h() const + { + return GetField(VT_STRIDE_H, 0); + } + int32_t depth_multiplier() const + { + return GetField(VT_DEPTH_MULTIPLIER, 0); + } + tflite::ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + int32_t dilation_w_factor() const + { + return GetField(VT_DILATION_W_FACTOR, 1); + } + int32_t dilation_h_factor() const + { + return GetField(VT_DILATION_H_FACTOR, 1); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_PADDING) && + VerifyField(verifier, VT_STRIDE_W) && + VerifyField(verifier, VT_STRIDE_H) && + VerifyField(verifier, VT_DEPTH_MULTIPLIER) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_DILATION_W_FACTOR) && + VerifyField(verifier, VT_DILATION_H_FACTOR) && + verifier.EndTable(); + } + DepthwiseConv2DOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(DepthwiseConv2DOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const DepthwiseConv2DOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct DepthwiseConv2DOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_padding(tflite::Padding padding) + { + fbb_.AddElement(DepthwiseConv2DOptions::VT_PADDING, static_cast(padding), 0); + } + void add_stride_w(int32_t stride_w) + { + fbb_.AddElement(DepthwiseConv2DOptions::VT_STRIDE_W, stride_w, 0); + } + void add_stride_h(int32_t stride_h) + { + fbb_.AddElement(DepthwiseConv2DOptions::VT_STRIDE_H, stride_h, 0); + } + void add_depth_multiplier(int32_t depth_multiplier) + { + fbb_.AddElement(DepthwiseConv2DOptions::VT_DEPTH_MULTIPLIER, depth_multiplier, 0); + } + void add_fused_activation_function(tflite::ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(DepthwiseConv2DOptions::VT_FUSED_ACTIVATION_FUNCTION, static_cast(fused_activation_function), 0); + } + void add_dilation_w_factor(int32_t dilation_w_factor) + { + fbb_.AddElement(DepthwiseConv2DOptions::VT_DILATION_W_FACTOR, dilation_w_factor, 1); + } + void add_dilation_h_factor(int32_t dilation_h_factor) + { + fbb_.AddElement(DepthwiseConv2DOptions::VT_DILATION_H_FACTOR, dilation_h_factor, 1); + } + explicit DepthwiseConv2DOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + DepthwiseConv2DOptionsBuilder &operator=(const DepthwiseConv2DOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateDepthwiseConv2DOptions( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::Padding padding = tflite::Padding_SAME, + int32_t stride_w = 0, + int32_t stride_h = 0, + int32_t depth_multiplier = 0, + tflite::ActivationFunctionType fused_activation_function = tflite::ActivationFunctionType_NONE, + int32_t dilation_w_factor = 1, + int32_t dilation_h_factor = 1) +{ + DepthwiseConv2DOptionsBuilder builder_(_fbb); + builder_.add_dilation_h_factor(dilation_h_factor); + builder_.add_dilation_w_factor(dilation_w_factor); + builder_.add_depth_multiplier(depth_multiplier); + builder_.add_stride_h(stride_h); + builder_.add_stride_w(stride_w); + builder_.add_fused_activation_function(fused_activation_function); + builder_.add_padding(padding); + return builder_.Finish(); +} + +flatbuffers::Offset CreateDepthwiseConv2DOptions(flatbuffers::FlatBufferBuilder &_fbb, const DepthwiseConv2DOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct ConcatEmbeddingsOptionsT : public flatbuffers::NativeTable { + typedef ConcatEmbeddingsOptions TableType; + int32_t num_channels; + std::vector num_columns_per_channel; + std::vector embedding_dim_per_channel; + ConcatEmbeddingsOptionsT() + : num_channels(0) + { + } +}; + +struct ConcatEmbeddingsOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef ConcatEmbeddingsOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_NUM_CHANNELS = 4, + VT_NUM_COLUMNS_PER_CHANNEL = 6, + VT_EMBEDDING_DIM_PER_CHANNEL = 8 + }; + int32_t num_channels() const + { + return GetField(VT_NUM_CHANNELS, 0); + } + const flatbuffers::Vector *num_columns_per_channel() const + { + return GetPointer *>(VT_NUM_COLUMNS_PER_CHANNEL); + } + const flatbuffers::Vector *embedding_dim_per_channel() const + { + return GetPointer *>(VT_EMBEDDING_DIM_PER_CHANNEL); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_NUM_CHANNELS) && + VerifyOffset(verifier, VT_NUM_COLUMNS_PER_CHANNEL) && + verifier.VerifyVector(num_columns_per_channel()) && + VerifyOffset(verifier, VT_EMBEDDING_DIM_PER_CHANNEL) && + verifier.VerifyVector(embedding_dim_per_channel()) && + verifier.EndTable(); + } + ConcatEmbeddingsOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(ConcatEmbeddingsOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const ConcatEmbeddingsOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct ConcatEmbeddingsOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_num_channels(int32_t num_channels) + { + fbb_.AddElement(ConcatEmbeddingsOptions::VT_NUM_CHANNELS, num_channels, 0); + } + void add_num_columns_per_channel(flatbuffers::Offset > num_columns_per_channel) + { + fbb_.AddOffset(ConcatEmbeddingsOptions::VT_NUM_COLUMNS_PER_CHANNEL, num_columns_per_channel); + } + void add_embedding_dim_per_channel(flatbuffers::Offset > embedding_dim_per_channel) + { + fbb_.AddOffset(ConcatEmbeddingsOptions::VT_EMBEDDING_DIM_PER_CHANNEL, embedding_dim_per_channel); + } + explicit ConcatEmbeddingsOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ConcatEmbeddingsOptionsBuilder &operator=(const ConcatEmbeddingsOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateConcatEmbeddingsOptions( + flatbuffers::FlatBufferBuilder &_fbb, + int32_t num_channels = 0, + flatbuffers::Offset > num_columns_per_channel = 0, + flatbuffers::Offset > embedding_dim_per_channel = 0) +{ + ConcatEmbeddingsOptionsBuilder builder_(_fbb); + builder_.add_embedding_dim_per_channel(embedding_dim_per_channel); + builder_.add_num_columns_per_channel(num_columns_per_channel); + builder_.add_num_channels(num_channels); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateConcatEmbeddingsOptionsDirect( + flatbuffers::FlatBufferBuilder &_fbb, + int32_t num_channels = 0, + const std::vector *num_columns_per_channel = nullptr, + const std::vector *embedding_dim_per_channel = nullptr) +{ + auto num_columns_per_channel__ = num_columns_per_channel ? _fbb.CreateVector(*num_columns_per_channel) : 0; + auto embedding_dim_per_channel__ = embedding_dim_per_channel ? _fbb.CreateVector(*embedding_dim_per_channel) : 0; + return tflite::CreateConcatEmbeddingsOptions( + _fbb, + num_channels, + num_columns_per_channel__, + embedding_dim_per_channel__); +} + +flatbuffers::Offset CreateConcatEmbeddingsOptions(flatbuffers::FlatBufferBuilder &_fbb, const ConcatEmbeddingsOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct LSHProjectionOptionsT : public flatbuffers::NativeTable { + typedef LSHProjectionOptions TableType; + tflite::LSHProjectionType type; + LSHProjectionOptionsT() + : type(tflite::LSHProjectionType_UNKNOWN) + { + } +}; + +struct LSHProjectionOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef LSHProjectionOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_TYPE = 4 + }; + tflite::LSHProjectionType type() const + { + return static_cast(GetField(VT_TYPE, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_TYPE) && + verifier.EndTable(); + } + LSHProjectionOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(LSHProjectionOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const LSHProjectionOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct LSHProjectionOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_type(tflite::LSHProjectionType type) + { + fbb_.AddElement(LSHProjectionOptions::VT_TYPE, static_cast(type), 0); + } + explicit LSHProjectionOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + LSHProjectionOptionsBuilder &operator=(const LSHProjectionOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateLSHProjectionOptions( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::LSHProjectionType type = tflite::LSHProjectionType_UNKNOWN) +{ + LSHProjectionOptionsBuilder builder_(_fbb); + builder_.add_type(type); + return builder_.Finish(); +} + +flatbuffers::Offset CreateLSHProjectionOptions(flatbuffers::FlatBufferBuilder &_fbb, const LSHProjectionOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct SVDFOptionsT : public flatbuffers::NativeTable { + typedef SVDFOptions TableType; + int32_t rank; + tflite::ActivationFunctionType fused_activation_function; + bool asymmetric_quantize_inputs; + SVDFOptionsT() + : rank(0), + fused_activation_function(tflite::ActivationFunctionType_NONE), + asymmetric_quantize_inputs(false) + { + } +}; + +struct SVDFOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef SVDFOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_RANK = 4, + VT_FUSED_ACTIVATION_FUNCTION = 6, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 8 + }; + int32_t rank() const + { + return GetField(VT_RANK, 0); + } + tflite::ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_RANK) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && + verifier.EndTable(); + } + SVDFOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(SVDFOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const SVDFOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct SVDFOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_rank(int32_t rank) + { + fbb_.AddElement(SVDFOptions::VT_RANK, rank, 0); + } + void add_fused_activation_function(tflite::ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(SVDFOptions::VT_FUSED_ACTIVATION_FUNCTION, static_cast(fused_activation_function), 0); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(SVDFOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, static_cast(asymmetric_quantize_inputs), 0); + } + explicit SVDFOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SVDFOptionsBuilder &operator=(const SVDFOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateSVDFOptions( + flatbuffers::FlatBufferBuilder &_fbb, + int32_t rank = 0, + tflite::ActivationFunctionType fused_activation_function = tflite::ActivationFunctionType_NONE, + bool asymmetric_quantize_inputs = false) +{ + SVDFOptionsBuilder builder_(_fbb); + builder_.add_rank(rank); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +flatbuffers::Offset CreateSVDFOptions(flatbuffers::FlatBufferBuilder &_fbb, const SVDFOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct RNNOptionsT : public flatbuffers::NativeTable { + typedef RNNOptions TableType; + tflite::ActivationFunctionType fused_activation_function; + bool asymmetric_quantize_inputs; + RNNOptionsT() + : fused_activation_function(tflite::ActivationFunctionType_NONE), + asymmetric_quantize_inputs(false) + { + } +}; + +struct RNNOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef RNNOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_FUSED_ACTIVATION_FUNCTION = 4, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 6 + }; + tflite::ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && + verifier.EndTable(); + } + RNNOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(RNNOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const RNNOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct RNNOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(tflite::ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(RNNOptions::VT_FUSED_ACTIVATION_FUNCTION, static_cast(fused_activation_function), 0); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(RNNOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, static_cast(asymmetric_quantize_inputs), 0); + } + explicit RNNOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + RNNOptionsBuilder &operator=(const RNNOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateRNNOptions( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::ActivationFunctionType fused_activation_function = tflite::ActivationFunctionType_NONE, + bool asymmetric_quantize_inputs = false) +{ + RNNOptionsBuilder builder_(_fbb); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +flatbuffers::Offset CreateRNNOptions(flatbuffers::FlatBufferBuilder &_fbb, const RNNOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct SequenceRNNOptionsT : public flatbuffers::NativeTable { + typedef SequenceRNNOptions TableType; + bool time_major; + tflite::ActivationFunctionType fused_activation_function; + bool asymmetric_quantize_inputs; + SequenceRNNOptionsT() + : time_major(false), + fused_activation_function(tflite::ActivationFunctionType_NONE), + asymmetric_quantize_inputs(false) + { + } +}; + +struct SequenceRNNOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef SequenceRNNOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_TIME_MAJOR = 4, + VT_FUSED_ACTIVATION_FUNCTION = 6, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 8 + }; + bool time_major() const + { + return GetField(VT_TIME_MAJOR, 0) != 0; + } + tflite::ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_TIME_MAJOR) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && + verifier.EndTable(); + } + SequenceRNNOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(SequenceRNNOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const SequenceRNNOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct SequenceRNNOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_time_major(bool time_major) + { + fbb_.AddElement(SequenceRNNOptions::VT_TIME_MAJOR, static_cast(time_major), 0); + } + void add_fused_activation_function(tflite::ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(SequenceRNNOptions::VT_FUSED_ACTIVATION_FUNCTION, static_cast(fused_activation_function), 0); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(SequenceRNNOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, static_cast(asymmetric_quantize_inputs), 0); + } + explicit SequenceRNNOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SequenceRNNOptionsBuilder &operator=(const SequenceRNNOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateSequenceRNNOptions( + flatbuffers::FlatBufferBuilder &_fbb, + bool time_major = false, + tflite::ActivationFunctionType fused_activation_function = tflite::ActivationFunctionType_NONE, + bool asymmetric_quantize_inputs = false) +{ + SequenceRNNOptionsBuilder builder_(_fbb); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_fused_activation_function(fused_activation_function); + builder_.add_time_major(time_major); + return builder_.Finish(); +} + +flatbuffers::Offset CreateSequenceRNNOptions(flatbuffers::FlatBufferBuilder &_fbb, const SequenceRNNOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct BidirectionalSequenceRNNOptionsT : public flatbuffers::NativeTable { + typedef BidirectionalSequenceRNNOptions TableType; + bool time_major; + tflite::ActivationFunctionType fused_activation_function; + bool merge_outputs; + bool asymmetric_quantize_inputs; + BidirectionalSequenceRNNOptionsT() + : time_major(false), + fused_activation_function(tflite::ActivationFunctionType_NONE), + merge_outputs(false), + asymmetric_quantize_inputs(false) + { + } +}; + +struct BidirectionalSequenceRNNOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef BidirectionalSequenceRNNOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_TIME_MAJOR = 4, + VT_FUSED_ACTIVATION_FUNCTION = 6, + VT_MERGE_OUTPUTS = 8, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 10 + }; + bool time_major() const + { + return GetField(VT_TIME_MAJOR, 0) != 0; + } + tflite::ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool merge_outputs() const + { + return GetField(VT_MERGE_OUTPUTS, 0) != 0; + } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_TIME_MAJOR) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_MERGE_OUTPUTS) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && + verifier.EndTable(); + } + BidirectionalSequenceRNNOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(BidirectionalSequenceRNNOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const BidirectionalSequenceRNNOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct BidirectionalSequenceRNNOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_time_major(bool time_major) + { + fbb_.AddElement(BidirectionalSequenceRNNOptions::VT_TIME_MAJOR, static_cast(time_major), 0); + } + void add_fused_activation_function(tflite::ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(BidirectionalSequenceRNNOptions::VT_FUSED_ACTIVATION_FUNCTION, static_cast(fused_activation_function), 0); + } + void add_merge_outputs(bool merge_outputs) + { + fbb_.AddElement(BidirectionalSequenceRNNOptions::VT_MERGE_OUTPUTS, static_cast(merge_outputs), 0); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(BidirectionalSequenceRNNOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, static_cast(asymmetric_quantize_inputs), 0); + } + explicit BidirectionalSequenceRNNOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + BidirectionalSequenceRNNOptionsBuilder &operator=(const BidirectionalSequenceRNNOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateBidirectionalSequenceRNNOptions( + flatbuffers::FlatBufferBuilder &_fbb, + bool time_major = false, + tflite::ActivationFunctionType fused_activation_function = tflite::ActivationFunctionType_NONE, + bool merge_outputs = false, + bool asymmetric_quantize_inputs = false) +{ + BidirectionalSequenceRNNOptionsBuilder builder_(_fbb); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_merge_outputs(merge_outputs); + builder_.add_fused_activation_function(fused_activation_function); + builder_.add_time_major(time_major); + return builder_.Finish(); +} + +flatbuffers::Offset CreateBidirectionalSequenceRNNOptions(flatbuffers::FlatBufferBuilder &_fbb, const BidirectionalSequenceRNNOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct FullyConnectedOptionsT : public flatbuffers::NativeTable { + typedef FullyConnectedOptions TableType; + tflite::ActivationFunctionType fused_activation_function; + tflite::FullyConnectedOptionsWeightsFormat weights_format; + bool keep_num_dims; + bool asymmetric_quantize_inputs; + FullyConnectedOptionsT() + : fused_activation_function(tflite::ActivationFunctionType_NONE), + weights_format(tflite::FullyConnectedOptionsWeightsFormat_DEFAULT), + keep_num_dims(false), + asymmetric_quantize_inputs(false) + { + } +}; + +struct FullyConnectedOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef FullyConnectedOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_FUSED_ACTIVATION_FUNCTION = 4, + VT_WEIGHTS_FORMAT = 6, + VT_KEEP_NUM_DIMS = 8, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 10 + }; + tflite::ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + tflite::FullyConnectedOptionsWeightsFormat weights_format() const + { + return static_cast(GetField(VT_WEIGHTS_FORMAT, 0)); + } + bool keep_num_dims() const + { + return GetField(VT_KEEP_NUM_DIMS, 0) != 0; + } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_WEIGHTS_FORMAT) && + VerifyField(verifier, VT_KEEP_NUM_DIMS) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && + verifier.EndTable(); + } + FullyConnectedOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(FullyConnectedOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const FullyConnectedOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct FullyConnectedOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(tflite::ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(FullyConnectedOptions::VT_FUSED_ACTIVATION_FUNCTION, static_cast(fused_activation_function), 0); + } + void add_weights_format(tflite::FullyConnectedOptionsWeightsFormat weights_format) + { + fbb_.AddElement(FullyConnectedOptions::VT_WEIGHTS_FORMAT, static_cast(weights_format), 0); + } + void add_keep_num_dims(bool keep_num_dims) + { + fbb_.AddElement(FullyConnectedOptions::VT_KEEP_NUM_DIMS, static_cast(keep_num_dims), 0); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(FullyConnectedOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, static_cast(asymmetric_quantize_inputs), 0); + } + explicit FullyConnectedOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + FullyConnectedOptionsBuilder &operator=(const FullyConnectedOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateFullyConnectedOptions( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::ActivationFunctionType fused_activation_function = tflite::ActivationFunctionType_NONE, + tflite::FullyConnectedOptionsWeightsFormat weights_format = tflite::FullyConnectedOptionsWeightsFormat_DEFAULT, + bool keep_num_dims = false, + bool asymmetric_quantize_inputs = false) +{ + FullyConnectedOptionsBuilder builder_(_fbb); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_keep_num_dims(keep_num_dims); + builder_.add_weights_format(weights_format); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +flatbuffers::Offset CreateFullyConnectedOptions(flatbuffers::FlatBufferBuilder &_fbb, const FullyConnectedOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct SoftmaxOptionsT : public flatbuffers::NativeTable { + typedef SoftmaxOptions TableType; + float beta; + SoftmaxOptionsT() + : beta(0.0f) + { + } +}; + +struct SoftmaxOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef SoftmaxOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_BETA = 4 + }; + float beta() const + { + return GetField(VT_BETA, 0.0f); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_BETA) && + verifier.EndTable(); + } + SoftmaxOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(SoftmaxOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const SoftmaxOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct SoftmaxOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_beta(float beta) + { + fbb_.AddElement(SoftmaxOptions::VT_BETA, beta, 0.0f); + } + explicit SoftmaxOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SoftmaxOptionsBuilder &operator=(const SoftmaxOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateSoftmaxOptions( + flatbuffers::FlatBufferBuilder &_fbb, + float beta = 0.0f) +{ + SoftmaxOptionsBuilder builder_(_fbb); + builder_.add_beta(beta); + return builder_.Finish(); +} + +flatbuffers::Offset CreateSoftmaxOptions(flatbuffers::FlatBufferBuilder &_fbb, const SoftmaxOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct ConcatenationOptionsT : public flatbuffers::NativeTable { + typedef ConcatenationOptions TableType; + int32_t axis; + tflite::ActivationFunctionType fused_activation_function; + ConcatenationOptionsT() + : axis(0), + fused_activation_function(tflite::ActivationFunctionType_NONE) + { + } +}; + +struct ConcatenationOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef ConcatenationOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_AXIS = 4, + VT_FUSED_ACTIVATION_FUNCTION = 6 + }; + int32_t axis() const + { + return GetField(VT_AXIS, 0); + } + tflite::ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_AXIS) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + verifier.EndTable(); + } + ConcatenationOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(ConcatenationOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const ConcatenationOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct ConcatenationOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_axis(int32_t axis) + { + fbb_.AddElement(ConcatenationOptions::VT_AXIS, axis, 0); + } + void add_fused_activation_function(tflite::ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(ConcatenationOptions::VT_FUSED_ACTIVATION_FUNCTION, static_cast(fused_activation_function), 0); + } + explicit ConcatenationOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ConcatenationOptionsBuilder &operator=(const ConcatenationOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateConcatenationOptions( + flatbuffers::FlatBufferBuilder &_fbb, + int32_t axis = 0, + tflite::ActivationFunctionType fused_activation_function = tflite::ActivationFunctionType_NONE) +{ + ConcatenationOptionsBuilder builder_(_fbb); + builder_.add_axis(axis); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +flatbuffers::Offset CreateConcatenationOptions(flatbuffers::FlatBufferBuilder &_fbb, const ConcatenationOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct AddOptionsT : public flatbuffers::NativeTable { + typedef AddOptions TableType; + tflite::ActivationFunctionType fused_activation_function; + bool pot_scale_int16; + AddOptionsT() + : fused_activation_function(tflite::ActivationFunctionType_NONE), + pot_scale_int16(true) + { + } +}; + +struct AddOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef AddOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_FUSED_ACTIVATION_FUNCTION = 4, + VT_POT_SCALE_INT16 = 6 + }; + tflite::ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool pot_scale_int16() const + { + return GetField(VT_POT_SCALE_INT16, 1) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_POT_SCALE_INT16) && + verifier.EndTable(); + } + AddOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(AddOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const AddOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct AddOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(tflite::ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(AddOptions::VT_FUSED_ACTIVATION_FUNCTION, static_cast(fused_activation_function), 0); + } + void add_pot_scale_int16(bool pot_scale_int16) + { + fbb_.AddElement(AddOptions::VT_POT_SCALE_INT16, static_cast(pot_scale_int16), 1); + } + explicit AddOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + AddOptionsBuilder &operator=(const AddOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateAddOptions( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::ActivationFunctionType fused_activation_function = tflite::ActivationFunctionType_NONE, + bool pot_scale_int16 = true) +{ + AddOptionsBuilder builder_(_fbb); + builder_.add_pot_scale_int16(pot_scale_int16); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +flatbuffers::Offset CreateAddOptions(flatbuffers::FlatBufferBuilder &_fbb, const AddOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct MulOptionsT : public flatbuffers::NativeTable { + typedef MulOptions TableType; + tflite::ActivationFunctionType fused_activation_function; + MulOptionsT() + : fused_activation_function(tflite::ActivationFunctionType_NONE) + { + } +}; + +struct MulOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef MulOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_FUSED_ACTIVATION_FUNCTION = 4 + }; + tflite::ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + verifier.EndTable(); + } + MulOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(MulOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const MulOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct MulOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(tflite::ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(MulOptions::VT_FUSED_ACTIVATION_FUNCTION, static_cast(fused_activation_function), 0); + } + explicit MulOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + MulOptionsBuilder &operator=(const MulOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateMulOptions( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::ActivationFunctionType fused_activation_function = tflite::ActivationFunctionType_NONE) +{ + MulOptionsBuilder builder_(_fbb); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +flatbuffers::Offset CreateMulOptions(flatbuffers::FlatBufferBuilder &_fbb, const MulOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct L2NormOptionsT : public flatbuffers::NativeTable { + typedef L2NormOptions TableType; + tflite::ActivationFunctionType fused_activation_function; + L2NormOptionsT() + : fused_activation_function(tflite::ActivationFunctionType_NONE) + { + } +}; + +struct L2NormOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef L2NormOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_FUSED_ACTIVATION_FUNCTION = 4 + }; + tflite::ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + verifier.EndTable(); + } + L2NormOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(L2NormOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const L2NormOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct L2NormOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(tflite::ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(L2NormOptions::VT_FUSED_ACTIVATION_FUNCTION, static_cast(fused_activation_function), 0); + } + explicit L2NormOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + L2NormOptionsBuilder &operator=(const L2NormOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateL2NormOptions( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::ActivationFunctionType fused_activation_function = tflite::ActivationFunctionType_NONE) +{ + L2NormOptionsBuilder builder_(_fbb); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +flatbuffers::Offset CreateL2NormOptions(flatbuffers::FlatBufferBuilder &_fbb, const L2NormOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct LocalResponseNormalizationOptionsT : public flatbuffers::NativeTable { + typedef LocalResponseNormalizationOptions TableType; + int32_t radius; + float bias; + float alpha; + float beta; + LocalResponseNormalizationOptionsT() + : radius(0), + bias(0.0f), + alpha(0.0f), + beta(0.0f) + { + } +}; + +struct LocalResponseNormalizationOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef LocalResponseNormalizationOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_RADIUS = 4, + VT_BIAS = 6, + VT_ALPHA = 8, + VT_BETA = 10 + }; + int32_t radius() const + { + return GetField(VT_RADIUS, 0); + } + float bias() const + { + return GetField(VT_BIAS, 0.0f); + } + float alpha() const + { + return GetField(VT_ALPHA, 0.0f); + } + float beta() const + { + return GetField(VT_BETA, 0.0f); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_RADIUS) && + VerifyField(verifier, VT_BIAS) && + VerifyField(verifier, VT_ALPHA) && + VerifyField(verifier, VT_BETA) && + verifier.EndTable(); + } + LocalResponseNormalizationOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(LocalResponseNormalizationOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const LocalResponseNormalizationOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct LocalResponseNormalizationOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_radius(int32_t radius) + { + fbb_.AddElement(LocalResponseNormalizationOptions::VT_RADIUS, radius, 0); + } + void add_bias(float bias) + { + fbb_.AddElement(LocalResponseNormalizationOptions::VT_BIAS, bias, 0.0f); + } + void add_alpha(float alpha) + { + fbb_.AddElement(LocalResponseNormalizationOptions::VT_ALPHA, alpha, 0.0f); + } + void add_beta(float beta) + { + fbb_.AddElement(LocalResponseNormalizationOptions::VT_BETA, beta, 0.0f); + } + explicit LocalResponseNormalizationOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + LocalResponseNormalizationOptionsBuilder &operator=(const LocalResponseNormalizationOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateLocalResponseNormalizationOptions( + flatbuffers::FlatBufferBuilder &_fbb, + int32_t radius = 0, + float bias = 0.0f, + float alpha = 0.0f, + float beta = 0.0f) +{ + LocalResponseNormalizationOptionsBuilder builder_(_fbb); + builder_.add_beta(beta); + builder_.add_alpha(alpha); + builder_.add_bias(bias); + builder_.add_radius(radius); + return builder_.Finish(); +} + +flatbuffers::Offset CreateLocalResponseNormalizationOptions(flatbuffers::FlatBufferBuilder &_fbb, const LocalResponseNormalizationOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct LSTMOptionsT : public flatbuffers::NativeTable { + typedef LSTMOptions TableType; + tflite::ActivationFunctionType fused_activation_function; + float cell_clip; + float proj_clip; + tflite::LSTMKernelType kernel_type; + bool asymmetric_quantize_inputs; + LSTMOptionsT() + : fused_activation_function(tflite::ActivationFunctionType_NONE), + cell_clip(0.0f), + proj_clip(0.0f), + kernel_type(tflite::LSTMKernelType_FULL), + asymmetric_quantize_inputs(false) + { + } +}; + +struct LSTMOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef LSTMOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_FUSED_ACTIVATION_FUNCTION = 4, + VT_CELL_CLIP = 6, + VT_PROJ_CLIP = 8, + VT_KERNEL_TYPE = 10, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 12 + }; + tflite::ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + float cell_clip() const + { + return GetField(VT_CELL_CLIP, 0.0f); + } + float proj_clip() const + { + return GetField(VT_PROJ_CLIP, 0.0f); + } + tflite::LSTMKernelType kernel_type() const + { + return static_cast(GetField(VT_KERNEL_TYPE, 0)); + } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_CELL_CLIP) && + VerifyField(verifier, VT_PROJ_CLIP) && + VerifyField(verifier, VT_KERNEL_TYPE) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && + verifier.EndTable(); + } + LSTMOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(LSTMOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const LSTMOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct LSTMOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(tflite::ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(LSTMOptions::VT_FUSED_ACTIVATION_FUNCTION, static_cast(fused_activation_function), 0); + } + void add_cell_clip(float cell_clip) + { + fbb_.AddElement(LSTMOptions::VT_CELL_CLIP, cell_clip, 0.0f); + } + void add_proj_clip(float proj_clip) + { + fbb_.AddElement(LSTMOptions::VT_PROJ_CLIP, proj_clip, 0.0f); + } + void add_kernel_type(tflite::LSTMKernelType kernel_type) + { + fbb_.AddElement(LSTMOptions::VT_KERNEL_TYPE, static_cast(kernel_type), 0); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(LSTMOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, static_cast(asymmetric_quantize_inputs), 0); + } + explicit LSTMOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + LSTMOptionsBuilder &operator=(const LSTMOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateLSTMOptions( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::ActivationFunctionType fused_activation_function = tflite::ActivationFunctionType_NONE, + float cell_clip = 0.0f, + float proj_clip = 0.0f, + tflite::LSTMKernelType kernel_type = tflite::LSTMKernelType_FULL, + bool asymmetric_quantize_inputs = false) +{ + LSTMOptionsBuilder builder_(_fbb); + builder_.add_proj_clip(proj_clip); + builder_.add_cell_clip(cell_clip); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_kernel_type(kernel_type); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +flatbuffers::Offset CreateLSTMOptions(flatbuffers::FlatBufferBuilder &_fbb, const LSTMOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct UnidirectionalSequenceLSTMOptionsT : public flatbuffers::NativeTable { + typedef UnidirectionalSequenceLSTMOptions TableType; + tflite::ActivationFunctionType fused_activation_function; + float cell_clip; + float proj_clip; + bool time_major; + bool asymmetric_quantize_inputs; + UnidirectionalSequenceLSTMOptionsT() + : fused_activation_function(tflite::ActivationFunctionType_NONE), + cell_clip(0.0f), + proj_clip(0.0f), + time_major(false), + asymmetric_quantize_inputs(false) + { + } +}; + +struct UnidirectionalSequenceLSTMOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef UnidirectionalSequenceLSTMOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_FUSED_ACTIVATION_FUNCTION = 4, + VT_CELL_CLIP = 6, + VT_PROJ_CLIP = 8, + VT_TIME_MAJOR = 10, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 12 + }; + tflite::ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + float cell_clip() const + { + return GetField(VT_CELL_CLIP, 0.0f); + } + float proj_clip() const + { + return GetField(VT_PROJ_CLIP, 0.0f); + } + bool time_major() const + { + return GetField(VT_TIME_MAJOR, 0) != 0; + } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_CELL_CLIP) && + VerifyField(verifier, VT_PROJ_CLIP) && + VerifyField(verifier, VT_TIME_MAJOR) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && + verifier.EndTable(); + } + UnidirectionalSequenceLSTMOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(UnidirectionalSequenceLSTMOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const UnidirectionalSequenceLSTMOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct UnidirectionalSequenceLSTMOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(tflite::ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(UnidirectionalSequenceLSTMOptions::VT_FUSED_ACTIVATION_FUNCTION, static_cast(fused_activation_function), 0); + } + void add_cell_clip(float cell_clip) + { + fbb_.AddElement(UnidirectionalSequenceLSTMOptions::VT_CELL_CLIP, cell_clip, 0.0f); + } + void add_proj_clip(float proj_clip) + { + fbb_.AddElement(UnidirectionalSequenceLSTMOptions::VT_PROJ_CLIP, proj_clip, 0.0f); + } + void add_time_major(bool time_major) + { + fbb_.AddElement(UnidirectionalSequenceLSTMOptions::VT_TIME_MAJOR, static_cast(time_major), 0); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(UnidirectionalSequenceLSTMOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, static_cast(asymmetric_quantize_inputs), 0); + } + explicit UnidirectionalSequenceLSTMOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + UnidirectionalSequenceLSTMOptionsBuilder &operator=(const UnidirectionalSequenceLSTMOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateUnidirectionalSequenceLSTMOptions( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::ActivationFunctionType fused_activation_function = tflite::ActivationFunctionType_NONE, + float cell_clip = 0.0f, + float proj_clip = 0.0f, + bool time_major = false, + bool asymmetric_quantize_inputs = false) +{ + UnidirectionalSequenceLSTMOptionsBuilder builder_(_fbb); + builder_.add_proj_clip(proj_clip); + builder_.add_cell_clip(cell_clip); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_time_major(time_major); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +flatbuffers::Offset CreateUnidirectionalSequenceLSTMOptions(flatbuffers::FlatBufferBuilder &_fbb, const UnidirectionalSequenceLSTMOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct BidirectionalSequenceLSTMOptionsT : public flatbuffers::NativeTable { + typedef BidirectionalSequenceLSTMOptions TableType; + tflite::ActivationFunctionType fused_activation_function; + float cell_clip; + float proj_clip; + bool merge_outputs; + bool time_major; + bool asymmetric_quantize_inputs; + BidirectionalSequenceLSTMOptionsT() + : fused_activation_function(tflite::ActivationFunctionType_NONE), + cell_clip(0.0f), + proj_clip(0.0f), + merge_outputs(false), + time_major(true), + asymmetric_quantize_inputs(false) + { + } +}; + +struct BidirectionalSequenceLSTMOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef BidirectionalSequenceLSTMOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_FUSED_ACTIVATION_FUNCTION = 4, + VT_CELL_CLIP = 6, + VT_PROJ_CLIP = 8, + VT_MERGE_OUTPUTS = 10, + VT_TIME_MAJOR = 12, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 14 + }; + tflite::ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + float cell_clip() const + { + return GetField(VT_CELL_CLIP, 0.0f); + } + float proj_clip() const + { + return GetField(VT_PROJ_CLIP, 0.0f); + } + bool merge_outputs() const + { + return GetField(VT_MERGE_OUTPUTS, 0) != 0; + } + bool time_major() const + { + return GetField(VT_TIME_MAJOR, 1) != 0; + } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_CELL_CLIP) && + VerifyField(verifier, VT_PROJ_CLIP) && + VerifyField(verifier, VT_MERGE_OUTPUTS) && + VerifyField(verifier, VT_TIME_MAJOR) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && + verifier.EndTable(); + } + BidirectionalSequenceLSTMOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(BidirectionalSequenceLSTMOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const BidirectionalSequenceLSTMOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct BidirectionalSequenceLSTMOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(tflite::ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_FUSED_ACTIVATION_FUNCTION, static_cast(fused_activation_function), 0); + } + void add_cell_clip(float cell_clip) + { + fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_CELL_CLIP, cell_clip, 0.0f); + } + void add_proj_clip(float proj_clip) + { + fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_PROJ_CLIP, proj_clip, 0.0f); + } + void add_merge_outputs(bool merge_outputs) + { + fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_MERGE_OUTPUTS, static_cast(merge_outputs), 0); + } + void add_time_major(bool time_major) + { + fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_TIME_MAJOR, static_cast(time_major), 1); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(BidirectionalSequenceLSTMOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, static_cast(asymmetric_quantize_inputs), 0); + } + explicit BidirectionalSequenceLSTMOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + BidirectionalSequenceLSTMOptionsBuilder &operator=(const BidirectionalSequenceLSTMOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateBidirectionalSequenceLSTMOptions( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::ActivationFunctionType fused_activation_function = tflite::ActivationFunctionType_NONE, + float cell_clip = 0.0f, + float proj_clip = 0.0f, + bool merge_outputs = false, + bool time_major = true, + bool asymmetric_quantize_inputs = false) +{ + BidirectionalSequenceLSTMOptionsBuilder builder_(_fbb); + builder_.add_proj_clip(proj_clip); + builder_.add_cell_clip(cell_clip); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_time_major(time_major); + builder_.add_merge_outputs(merge_outputs); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +flatbuffers::Offset CreateBidirectionalSequenceLSTMOptions(flatbuffers::FlatBufferBuilder &_fbb, const BidirectionalSequenceLSTMOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct ResizeBilinearOptionsT : public flatbuffers::NativeTable { + typedef ResizeBilinearOptions TableType; + bool align_corners; + bool half_pixel_centers; + ResizeBilinearOptionsT() + : align_corners(false), + half_pixel_centers(false) + { + } +}; + +struct ResizeBilinearOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef ResizeBilinearOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_ALIGN_CORNERS = 8, + VT_HALF_PIXEL_CENTERS = 10 + }; + bool align_corners() const + { + return GetField(VT_ALIGN_CORNERS, 0) != 0; + } + bool half_pixel_centers() const + { + return GetField(VT_HALF_PIXEL_CENTERS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_ALIGN_CORNERS) && + VerifyField(verifier, VT_HALF_PIXEL_CENTERS) && + verifier.EndTable(); + } + ResizeBilinearOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(ResizeBilinearOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const ResizeBilinearOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct ResizeBilinearOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_align_corners(bool align_corners) + { + fbb_.AddElement(ResizeBilinearOptions::VT_ALIGN_CORNERS, static_cast(align_corners), 0); + } + void add_half_pixel_centers(bool half_pixel_centers) + { + fbb_.AddElement(ResizeBilinearOptions::VT_HALF_PIXEL_CENTERS, static_cast(half_pixel_centers), 0); + } + explicit ResizeBilinearOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ResizeBilinearOptionsBuilder &operator=(const ResizeBilinearOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateResizeBilinearOptions( + flatbuffers::FlatBufferBuilder &_fbb, + bool align_corners = false, + bool half_pixel_centers = false) +{ + ResizeBilinearOptionsBuilder builder_(_fbb); + builder_.add_half_pixel_centers(half_pixel_centers); + builder_.add_align_corners(align_corners); + return builder_.Finish(); +} + +flatbuffers::Offset CreateResizeBilinearOptions(flatbuffers::FlatBufferBuilder &_fbb, const ResizeBilinearOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct ResizeNearestNeighborOptionsT : public flatbuffers::NativeTable { + typedef ResizeNearestNeighborOptions TableType; + bool align_corners; + bool half_pixel_centers; + ResizeNearestNeighborOptionsT() + : align_corners(false), + half_pixel_centers(false) + { + } +}; + +struct ResizeNearestNeighborOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef ResizeNearestNeighborOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_ALIGN_CORNERS = 4, + VT_HALF_PIXEL_CENTERS = 6 + }; + bool align_corners() const + { + return GetField(VT_ALIGN_CORNERS, 0) != 0; + } + bool half_pixel_centers() const + { + return GetField(VT_HALF_PIXEL_CENTERS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_ALIGN_CORNERS) && + VerifyField(verifier, VT_HALF_PIXEL_CENTERS) && + verifier.EndTable(); + } + ResizeNearestNeighborOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(ResizeNearestNeighborOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const ResizeNearestNeighborOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct ResizeNearestNeighborOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_align_corners(bool align_corners) + { + fbb_.AddElement(ResizeNearestNeighborOptions::VT_ALIGN_CORNERS, static_cast(align_corners), 0); + } + void add_half_pixel_centers(bool half_pixel_centers) + { + fbb_.AddElement(ResizeNearestNeighborOptions::VT_HALF_PIXEL_CENTERS, static_cast(half_pixel_centers), 0); + } + explicit ResizeNearestNeighborOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ResizeNearestNeighborOptionsBuilder &operator=(const ResizeNearestNeighborOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateResizeNearestNeighborOptions( + flatbuffers::FlatBufferBuilder &_fbb, + bool align_corners = false, + bool half_pixel_centers = false) +{ + ResizeNearestNeighborOptionsBuilder builder_(_fbb); + builder_.add_half_pixel_centers(half_pixel_centers); + builder_.add_align_corners(align_corners); + return builder_.Finish(); +} + +flatbuffers::Offset CreateResizeNearestNeighborOptions(flatbuffers::FlatBufferBuilder &_fbb, const ResizeNearestNeighborOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct CallOptionsT : public flatbuffers::NativeTable { + typedef CallOptions TableType; + uint32_t subgraph; + CallOptionsT() + : subgraph(0) + { + } +}; + +struct CallOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef CallOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_SUBGRAPH = 4 + }; + uint32_t subgraph() const + { + return GetField(VT_SUBGRAPH, 0); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_SUBGRAPH) && + verifier.EndTable(); + } + CallOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(CallOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const CallOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct CallOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_subgraph(uint32_t subgraph) + { + fbb_.AddElement(CallOptions::VT_SUBGRAPH, subgraph, 0); + } + explicit CallOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + CallOptionsBuilder &operator=(const CallOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateCallOptions( + flatbuffers::FlatBufferBuilder &_fbb, + uint32_t subgraph = 0) +{ + CallOptionsBuilder builder_(_fbb); + builder_.add_subgraph(subgraph); + return builder_.Finish(); +} + +flatbuffers::Offset CreateCallOptions(flatbuffers::FlatBufferBuilder &_fbb, const CallOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct PadOptionsT : public flatbuffers::NativeTable { + typedef PadOptions TableType; + PadOptionsT() + { + } +}; + +struct PadOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef PadOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + PadOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(PadOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const PadOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct PadOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit PadOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + PadOptionsBuilder &operator=(const PadOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreatePadOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + PadOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreatePadOptions(flatbuffers::FlatBufferBuilder &_fbb, const PadOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct PadV2OptionsT : public flatbuffers::NativeTable { + typedef PadV2Options TableType; + PadV2OptionsT() + { + } +}; + +struct PadV2Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef PadV2OptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + PadV2OptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(PadV2OptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const PadV2OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct PadV2OptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit PadV2OptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + PadV2OptionsBuilder &operator=(const PadV2OptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreatePadV2Options( + flatbuffers::FlatBufferBuilder &_fbb) +{ + PadV2OptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreatePadV2Options(flatbuffers::FlatBufferBuilder &_fbb, const PadV2OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct ReshapeOptionsT : public flatbuffers::NativeTable { + typedef ReshapeOptions TableType; + std::vector new_shape; + ReshapeOptionsT() + { + } +}; + +struct ReshapeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef ReshapeOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_NEW_SHAPE = 4 + }; + const flatbuffers::Vector *new_shape() const + { + return GetPointer *>(VT_NEW_SHAPE); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_NEW_SHAPE) && + verifier.VerifyVector(new_shape()) && + verifier.EndTable(); + } + ReshapeOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(ReshapeOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const ReshapeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct ReshapeOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_new_shape(flatbuffers::Offset > new_shape) + { + fbb_.AddOffset(ReshapeOptions::VT_NEW_SHAPE, new_shape); + } + explicit ReshapeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ReshapeOptionsBuilder &operator=(const ReshapeOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateReshapeOptions( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset > new_shape = 0) +{ + ReshapeOptionsBuilder builder_(_fbb); + builder_.add_new_shape(new_shape); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateReshapeOptionsDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const std::vector *new_shape = nullptr) +{ + auto new_shape__ = new_shape ? _fbb.CreateVector(*new_shape) : 0; + return tflite::CreateReshapeOptions( + _fbb, + new_shape__); +} + +flatbuffers::Offset CreateReshapeOptions(flatbuffers::FlatBufferBuilder &_fbb, const ReshapeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct SpaceToBatchNDOptionsT : public flatbuffers::NativeTable { + typedef SpaceToBatchNDOptions TableType; + SpaceToBatchNDOptionsT() + { + } +}; + +struct SpaceToBatchNDOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef SpaceToBatchNDOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + SpaceToBatchNDOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(SpaceToBatchNDOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const SpaceToBatchNDOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct SpaceToBatchNDOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit SpaceToBatchNDOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SpaceToBatchNDOptionsBuilder &operator=(const SpaceToBatchNDOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateSpaceToBatchNDOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + SpaceToBatchNDOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateSpaceToBatchNDOptions(flatbuffers::FlatBufferBuilder &_fbb, const SpaceToBatchNDOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct BatchToSpaceNDOptionsT : public flatbuffers::NativeTable { + typedef BatchToSpaceNDOptions TableType; + BatchToSpaceNDOptionsT() + { + } +}; + +struct BatchToSpaceNDOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef BatchToSpaceNDOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + BatchToSpaceNDOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(BatchToSpaceNDOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const BatchToSpaceNDOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct BatchToSpaceNDOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit BatchToSpaceNDOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + BatchToSpaceNDOptionsBuilder &operator=(const BatchToSpaceNDOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateBatchToSpaceNDOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + BatchToSpaceNDOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateBatchToSpaceNDOptions(flatbuffers::FlatBufferBuilder &_fbb, const BatchToSpaceNDOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct SkipGramOptionsT : public flatbuffers::NativeTable { + typedef SkipGramOptions TableType; + int32_t ngram_size; + int32_t max_skip_size; + bool include_all_ngrams; + SkipGramOptionsT() + : ngram_size(0), + max_skip_size(0), + include_all_ngrams(false) + { + } +}; + +struct SkipGramOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef SkipGramOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_NGRAM_SIZE = 4, + VT_MAX_SKIP_SIZE = 6, + VT_INCLUDE_ALL_NGRAMS = 8 + }; + int32_t ngram_size() const + { + return GetField(VT_NGRAM_SIZE, 0); + } + int32_t max_skip_size() const + { + return GetField(VT_MAX_SKIP_SIZE, 0); + } + bool include_all_ngrams() const + { + return GetField(VT_INCLUDE_ALL_NGRAMS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_NGRAM_SIZE) && + VerifyField(verifier, VT_MAX_SKIP_SIZE) && + VerifyField(verifier, VT_INCLUDE_ALL_NGRAMS) && + verifier.EndTable(); + } + SkipGramOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(SkipGramOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const SkipGramOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct SkipGramOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_ngram_size(int32_t ngram_size) + { + fbb_.AddElement(SkipGramOptions::VT_NGRAM_SIZE, ngram_size, 0); + } + void add_max_skip_size(int32_t max_skip_size) + { + fbb_.AddElement(SkipGramOptions::VT_MAX_SKIP_SIZE, max_skip_size, 0); + } + void add_include_all_ngrams(bool include_all_ngrams) + { + fbb_.AddElement(SkipGramOptions::VT_INCLUDE_ALL_NGRAMS, static_cast(include_all_ngrams), 0); + } + explicit SkipGramOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SkipGramOptionsBuilder &operator=(const SkipGramOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateSkipGramOptions( + flatbuffers::FlatBufferBuilder &_fbb, + int32_t ngram_size = 0, + int32_t max_skip_size = 0, + bool include_all_ngrams = false) +{ + SkipGramOptionsBuilder builder_(_fbb); + builder_.add_max_skip_size(max_skip_size); + builder_.add_ngram_size(ngram_size); + builder_.add_include_all_ngrams(include_all_ngrams); + return builder_.Finish(); +} + +flatbuffers::Offset CreateSkipGramOptions(flatbuffers::FlatBufferBuilder &_fbb, const SkipGramOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct SpaceToDepthOptionsT : public flatbuffers::NativeTable { + typedef SpaceToDepthOptions TableType; + int32_t block_size; + SpaceToDepthOptionsT() + : block_size(0) + { + } +}; + +struct SpaceToDepthOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef SpaceToDepthOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_BLOCK_SIZE = 4 + }; + int32_t block_size() const + { + return GetField(VT_BLOCK_SIZE, 0); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_BLOCK_SIZE) && + verifier.EndTable(); + } + SpaceToDepthOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(SpaceToDepthOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const SpaceToDepthOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct SpaceToDepthOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_block_size(int32_t block_size) + { + fbb_.AddElement(SpaceToDepthOptions::VT_BLOCK_SIZE, block_size, 0); + } + explicit SpaceToDepthOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SpaceToDepthOptionsBuilder &operator=(const SpaceToDepthOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateSpaceToDepthOptions( + flatbuffers::FlatBufferBuilder &_fbb, + int32_t block_size = 0) +{ + SpaceToDepthOptionsBuilder builder_(_fbb); + builder_.add_block_size(block_size); + return builder_.Finish(); +} + +flatbuffers::Offset CreateSpaceToDepthOptions(flatbuffers::FlatBufferBuilder &_fbb, const SpaceToDepthOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct DepthToSpaceOptionsT : public flatbuffers::NativeTable { + typedef DepthToSpaceOptions TableType; + int32_t block_size; + DepthToSpaceOptionsT() + : block_size(0) + { + } +}; + +struct DepthToSpaceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef DepthToSpaceOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_BLOCK_SIZE = 4 + }; + int32_t block_size() const + { + return GetField(VT_BLOCK_SIZE, 0); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_BLOCK_SIZE) && + verifier.EndTable(); + } + DepthToSpaceOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(DepthToSpaceOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const DepthToSpaceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct DepthToSpaceOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_block_size(int32_t block_size) + { + fbb_.AddElement(DepthToSpaceOptions::VT_BLOCK_SIZE, block_size, 0); + } + explicit DepthToSpaceOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + DepthToSpaceOptionsBuilder &operator=(const DepthToSpaceOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateDepthToSpaceOptions( + flatbuffers::FlatBufferBuilder &_fbb, + int32_t block_size = 0) +{ + DepthToSpaceOptionsBuilder builder_(_fbb); + builder_.add_block_size(block_size); + return builder_.Finish(); +} + +flatbuffers::Offset CreateDepthToSpaceOptions(flatbuffers::FlatBufferBuilder &_fbb, const DepthToSpaceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct SubOptionsT : public flatbuffers::NativeTable { + typedef SubOptions TableType; + tflite::ActivationFunctionType fused_activation_function; + bool pot_scale_int16; + SubOptionsT() + : fused_activation_function(tflite::ActivationFunctionType_NONE), + pot_scale_int16(true) + { + } +}; + +struct SubOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef SubOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_FUSED_ACTIVATION_FUNCTION = 4, + VT_POT_SCALE_INT16 = 6 + }; + tflite::ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool pot_scale_int16() const + { + return GetField(VT_POT_SCALE_INT16, 1) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + VerifyField(verifier, VT_POT_SCALE_INT16) && + verifier.EndTable(); + } + SubOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(SubOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const SubOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct SubOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(tflite::ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(SubOptions::VT_FUSED_ACTIVATION_FUNCTION, static_cast(fused_activation_function), 0); + } + void add_pot_scale_int16(bool pot_scale_int16) + { + fbb_.AddElement(SubOptions::VT_POT_SCALE_INT16, static_cast(pot_scale_int16), 1); + } + explicit SubOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SubOptionsBuilder &operator=(const SubOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateSubOptions( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::ActivationFunctionType fused_activation_function = tflite::ActivationFunctionType_NONE, + bool pot_scale_int16 = true) +{ + SubOptionsBuilder builder_(_fbb); + builder_.add_pot_scale_int16(pot_scale_int16); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +flatbuffers::Offset CreateSubOptions(flatbuffers::FlatBufferBuilder &_fbb, const SubOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct DivOptionsT : public flatbuffers::NativeTable { + typedef DivOptions TableType; + tflite::ActivationFunctionType fused_activation_function; + DivOptionsT() + : fused_activation_function(tflite::ActivationFunctionType_NONE) + { + } +}; + +struct DivOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef DivOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_FUSED_ACTIVATION_FUNCTION = 4 + }; + tflite::ActivationFunctionType fused_activation_function() const + { + return static_cast(GetField(VT_FUSED_ACTIVATION_FUNCTION, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_FUSED_ACTIVATION_FUNCTION) && + verifier.EndTable(); + } + DivOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(DivOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const DivOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct DivOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_fused_activation_function(tflite::ActivationFunctionType fused_activation_function) + { + fbb_.AddElement(DivOptions::VT_FUSED_ACTIVATION_FUNCTION, static_cast(fused_activation_function), 0); + } + explicit DivOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + DivOptionsBuilder &operator=(const DivOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateDivOptions( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::ActivationFunctionType fused_activation_function = tflite::ActivationFunctionType_NONE) +{ + DivOptionsBuilder builder_(_fbb); + builder_.add_fused_activation_function(fused_activation_function); + return builder_.Finish(); +} + +flatbuffers::Offset CreateDivOptions(flatbuffers::FlatBufferBuilder &_fbb, const DivOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct TopKV2OptionsT : public flatbuffers::NativeTable { + typedef TopKV2Options TableType; + TopKV2OptionsT() + { + } +}; + +struct TopKV2Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef TopKV2OptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + TopKV2OptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(TopKV2OptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const TopKV2OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct TopKV2OptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit TopKV2OptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + TopKV2OptionsBuilder &operator=(const TopKV2OptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateTopKV2Options( + flatbuffers::FlatBufferBuilder &_fbb) +{ + TopKV2OptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateTopKV2Options(flatbuffers::FlatBufferBuilder &_fbb, const TopKV2OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct EmbeddingLookupSparseOptionsT : public flatbuffers::NativeTable { + typedef EmbeddingLookupSparseOptions TableType; + tflite::CombinerType combiner; + EmbeddingLookupSparseOptionsT() + : combiner(tflite::CombinerType_SUM) + { + } +}; + +struct EmbeddingLookupSparseOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef EmbeddingLookupSparseOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_COMBINER = 4 + }; + tflite::CombinerType combiner() const + { + return static_cast(GetField(VT_COMBINER, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_COMBINER) && + verifier.EndTable(); + } + EmbeddingLookupSparseOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(EmbeddingLookupSparseOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const EmbeddingLookupSparseOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct EmbeddingLookupSparseOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_combiner(tflite::CombinerType combiner) + { + fbb_.AddElement(EmbeddingLookupSparseOptions::VT_COMBINER, static_cast(combiner), 0); + } + explicit EmbeddingLookupSparseOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + EmbeddingLookupSparseOptionsBuilder &operator=(const EmbeddingLookupSparseOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateEmbeddingLookupSparseOptions( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::CombinerType combiner = tflite::CombinerType_SUM) +{ + EmbeddingLookupSparseOptionsBuilder builder_(_fbb); + builder_.add_combiner(combiner); + return builder_.Finish(); +} + +flatbuffers::Offset CreateEmbeddingLookupSparseOptions(flatbuffers::FlatBufferBuilder &_fbb, const EmbeddingLookupSparseOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct GatherOptionsT : public flatbuffers::NativeTable { + typedef GatherOptions TableType; + int32_t axis; + int32_t batch_dims; + GatherOptionsT() + : axis(0), + batch_dims(0) + { + } +}; + +struct GatherOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef GatherOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_AXIS = 4, + VT_BATCH_DIMS = 6 + }; + int32_t axis() const + { + return GetField(VT_AXIS, 0); + } + int32_t batch_dims() const + { + return GetField(VT_BATCH_DIMS, 0); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_AXIS) && + VerifyField(verifier, VT_BATCH_DIMS) && + verifier.EndTable(); + } + GatherOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(GatherOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const GatherOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct GatherOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_axis(int32_t axis) + { + fbb_.AddElement(GatherOptions::VT_AXIS, axis, 0); + } + void add_batch_dims(int32_t batch_dims) + { + fbb_.AddElement(GatherOptions::VT_BATCH_DIMS, batch_dims, 0); + } + explicit GatherOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + GatherOptionsBuilder &operator=(const GatherOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateGatherOptions( + flatbuffers::FlatBufferBuilder &_fbb, + int32_t axis = 0, + int32_t batch_dims = 0) +{ + GatherOptionsBuilder builder_(_fbb); + builder_.add_batch_dims(batch_dims); + builder_.add_axis(axis); + return builder_.Finish(); +} + +flatbuffers::Offset CreateGatherOptions(flatbuffers::FlatBufferBuilder &_fbb, const GatherOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct TransposeOptionsT : public flatbuffers::NativeTable { + typedef TransposeOptions TableType; + TransposeOptionsT() + { + } +}; + +struct TransposeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef TransposeOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + TransposeOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(TransposeOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const TransposeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct TransposeOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit TransposeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + TransposeOptionsBuilder &operator=(const TransposeOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateTransposeOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + TransposeOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateTransposeOptions(flatbuffers::FlatBufferBuilder &_fbb, const TransposeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct ExpOptionsT : public flatbuffers::NativeTable { + typedef ExpOptions TableType; + ExpOptionsT() + { + } +}; + +struct ExpOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef ExpOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + ExpOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(ExpOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const ExpOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct ExpOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit ExpOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ExpOptionsBuilder &operator=(const ExpOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateExpOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + ExpOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateExpOptions(flatbuffers::FlatBufferBuilder &_fbb, const ExpOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct CosOptionsT : public flatbuffers::NativeTable { + typedef CosOptions TableType; + CosOptionsT() + { + } +}; + +struct CosOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef CosOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + CosOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(CosOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const CosOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct CosOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit CosOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + CosOptionsBuilder &operator=(const CosOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateCosOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + CosOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateCosOptions(flatbuffers::FlatBufferBuilder &_fbb, const CosOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct ReducerOptionsT : public flatbuffers::NativeTable { + typedef ReducerOptions TableType; + bool keep_dims; + ReducerOptionsT() + : keep_dims(false) + { + } +}; + +struct ReducerOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef ReducerOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_KEEP_DIMS = 4 + }; + bool keep_dims() const + { + return GetField(VT_KEEP_DIMS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_KEEP_DIMS) && + verifier.EndTable(); + } + ReducerOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(ReducerOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const ReducerOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct ReducerOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_keep_dims(bool keep_dims) + { + fbb_.AddElement(ReducerOptions::VT_KEEP_DIMS, static_cast(keep_dims), 0); + } + explicit ReducerOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ReducerOptionsBuilder &operator=(const ReducerOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateReducerOptions( + flatbuffers::FlatBufferBuilder &_fbb, + bool keep_dims = false) +{ + ReducerOptionsBuilder builder_(_fbb); + builder_.add_keep_dims(keep_dims); + return builder_.Finish(); +} + +flatbuffers::Offset CreateReducerOptions(flatbuffers::FlatBufferBuilder &_fbb, const ReducerOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct SqueezeOptionsT : public flatbuffers::NativeTable { + typedef SqueezeOptions TableType; + std::vector squeeze_dims; + SqueezeOptionsT() + { + } +}; + +struct SqueezeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef SqueezeOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_SQUEEZE_DIMS = 4 + }; + const flatbuffers::Vector *squeeze_dims() const + { + return GetPointer *>(VT_SQUEEZE_DIMS); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_SQUEEZE_DIMS) && + verifier.VerifyVector(squeeze_dims()) && + verifier.EndTable(); + } + SqueezeOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(SqueezeOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const SqueezeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct SqueezeOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_squeeze_dims(flatbuffers::Offset > squeeze_dims) + { + fbb_.AddOffset(SqueezeOptions::VT_SQUEEZE_DIMS, squeeze_dims); + } + explicit SqueezeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SqueezeOptionsBuilder &operator=(const SqueezeOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateSqueezeOptions( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset > squeeze_dims = 0) +{ + SqueezeOptionsBuilder builder_(_fbb); + builder_.add_squeeze_dims(squeeze_dims); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateSqueezeOptionsDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const std::vector *squeeze_dims = nullptr) +{ + auto squeeze_dims__ = squeeze_dims ? _fbb.CreateVector(*squeeze_dims) : 0; + return tflite::CreateSqueezeOptions( + _fbb, + squeeze_dims__); +} + +flatbuffers::Offset CreateSqueezeOptions(flatbuffers::FlatBufferBuilder &_fbb, const SqueezeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct SplitOptionsT : public flatbuffers::NativeTable { + typedef SplitOptions TableType; + int32_t num_splits; + SplitOptionsT() + : num_splits(0) + { + } +}; + +struct SplitOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef SplitOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_NUM_SPLITS = 4 + }; + int32_t num_splits() const + { + return GetField(VT_NUM_SPLITS, 0); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_NUM_SPLITS) && + verifier.EndTable(); + } + SplitOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(SplitOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const SplitOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct SplitOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_num_splits(int32_t num_splits) + { + fbb_.AddElement(SplitOptions::VT_NUM_SPLITS, num_splits, 0); + } + explicit SplitOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SplitOptionsBuilder &operator=(const SplitOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateSplitOptions( + flatbuffers::FlatBufferBuilder &_fbb, + int32_t num_splits = 0) +{ + SplitOptionsBuilder builder_(_fbb); + builder_.add_num_splits(num_splits); + return builder_.Finish(); +} + +flatbuffers::Offset CreateSplitOptions(flatbuffers::FlatBufferBuilder &_fbb, const SplitOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct SplitVOptionsT : public flatbuffers::NativeTable { + typedef SplitVOptions TableType; + int32_t num_splits; + SplitVOptionsT() + : num_splits(0) + { + } +}; + +struct SplitVOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef SplitVOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_NUM_SPLITS = 4 + }; + int32_t num_splits() const + { + return GetField(VT_NUM_SPLITS, 0); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_NUM_SPLITS) && + verifier.EndTable(); + } + SplitVOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(SplitVOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const SplitVOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct SplitVOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_num_splits(int32_t num_splits) + { + fbb_.AddElement(SplitVOptions::VT_NUM_SPLITS, num_splits, 0); + } + explicit SplitVOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SplitVOptionsBuilder &operator=(const SplitVOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateSplitVOptions( + flatbuffers::FlatBufferBuilder &_fbb, + int32_t num_splits = 0) +{ + SplitVOptionsBuilder builder_(_fbb); + builder_.add_num_splits(num_splits); + return builder_.Finish(); +} + +flatbuffers::Offset CreateSplitVOptions(flatbuffers::FlatBufferBuilder &_fbb, const SplitVOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct StridedSliceOptionsT : public flatbuffers::NativeTable { + typedef StridedSliceOptions TableType; + int32_t begin_mask; + int32_t end_mask; + int32_t ellipsis_mask; + int32_t new_axis_mask; + int32_t shrink_axis_mask; + StridedSliceOptionsT() + : begin_mask(0), + end_mask(0), + ellipsis_mask(0), + new_axis_mask(0), + shrink_axis_mask(0) + { + } +}; + +struct StridedSliceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef StridedSliceOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_BEGIN_MASK = 4, + VT_END_MASK = 6, + VT_ELLIPSIS_MASK = 8, + VT_NEW_AXIS_MASK = 10, + VT_SHRINK_AXIS_MASK = 12 + }; + int32_t begin_mask() const + { + return GetField(VT_BEGIN_MASK, 0); + } + int32_t end_mask() const + { + return GetField(VT_END_MASK, 0); + } + int32_t ellipsis_mask() const + { + return GetField(VT_ELLIPSIS_MASK, 0); + } + int32_t new_axis_mask() const + { + return GetField(VT_NEW_AXIS_MASK, 0); + } + int32_t shrink_axis_mask() const + { + return GetField(VT_SHRINK_AXIS_MASK, 0); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_BEGIN_MASK) && + VerifyField(verifier, VT_END_MASK) && + VerifyField(verifier, VT_ELLIPSIS_MASK) && + VerifyField(verifier, VT_NEW_AXIS_MASK) && + VerifyField(verifier, VT_SHRINK_AXIS_MASK) && + verifier.EndTable(); + } + StridedSliceOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(StridedSliceOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const StridedSliceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct StridedSliceOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_begin_mask(int32_t begin_mask) + { + fbb_.AddElement(StridedSliceOptions::VT_BEGIN_MASK, begin_mask, 0); + } + void add_end_mask(int32_t end_mask) + { + fbb_.AddElement(StridedSliceOptions::VT_END_MASK, end_mask, 0); + } + void add_ellipsis_mask(int32_t ellipsis_mask) + { + fbb_.AddElement(StridedSliceOptions::VT_ELLIPSIS_MASK, ellipsis_mask, 0); + } + void add_new_axis_mask(int32_t new_axis_mask) + { + fbb_.AddElement(StridedSliceOptions::VT_NEW_AXIS_MASK, new_axis_mask, 0); + } + void add_shrink_axis_mask(int32_t shrink_axis_mask) + { + fbb_.AddElement(StridedSliceOptions::VT_SHRINK_AXIS_MASK, shrink_axis_mask, 0); + } + explicit StridedSliceOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + StridedSliceOptionsBuilder &operator=(const StridedSliceOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateStridedSliceOptions( + flatbuffers::FlatBufferBuilder &_fbb, + int32_t begin_mask = 0, + int32_t end_mask = 0, + int32_t ellipsis_mask = 0, + int32_t new_axis_mask = 0, + int32_t shrink_axis_mask = 0) +{ + StridedSliceOptionsBuilder builder_(_fbb); + builder_.add_shrink_axis_mask(shrink_axis_mask); + builder_.add_new_axis_mask(new_axis_mask); + builder_.add_ellipsis_mask(ellipsis_mask); + builder_.add_end_mask(end_mask); + builder_.add_begin_mask(begin_mask); + return builder_.Finish(); +} + +flatbuffers::Offset CreateStridedSliceOptions(flatbuffers::FlatBufferBuilder &_fbb, const StridedSliceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct LogSoftmaxOptionsT : public flatbuffers::NativeTable { + typedef LogSoftmaxOptions TableType; + LogSoftmaxOptionsT() + { + } +}; + +struct LogSoftmaxOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef LogSoftmaxOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + LogSoftmaxOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(LogSoftmaxOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const LogSoftmaxOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct LogSoftmaxOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit LogSoftmaxOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + LogSoftmaxOptionsBuilder &operator=(const LogSoftmaxOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateLogSoftmaxOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + LogSoftmaxOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateLogSoftmaxOptions(flatbuffers::FlatBufferBuilder &_fbb, const LogSoftmaxOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct CastOptionsT : public flatbuffers::NativeTable { + typedef CastOptions TableType; + tflite::TensorType in_data_type; + tflite::TensorType out_data_type; + CastOptionsT() + : in_data_type(tflite::TensorType_FLOAT32), + out_data_type(tflite::TensorType_FLOAT32) + { + } +}; + +struct CastOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef CastOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_IN_DATA_TYPE = 4, + VT_OUT_DATA_TYPE = 6 + }; + tflite::TensorType in_data_type() const + { + return static_cast(GetField(VT_IN_DATA_TYPE, 0)); + } + tflite::TensorType out_data_type() const + { + return static_cast(GetField(VT_OUT_DATA_TYPE, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_IN_DATA_TYPE) && + VerifyField(verifier, VT_OUT_DATA_TYPE) && + verifier.EndTable(); + } + CastOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(CastOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const CastOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct CastOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_in_data_type(tflite::TensorType in_data_type) + { + fbb_.AddElement(CastOptions::VT_IN_DATA_TYPE, static_cast(in_data_type), 0); + } + void add_out_data_type(tflite::TensorType out_data_type) + { + fbb_.AddElement(CastOptions::VT_OUT_DATA_TYPE, static_cast(out_data_type), 0); + } + explicit CastOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + CastOptionsBuilder &operator=(const CastOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateCastOptions( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::TensorType in_data_type = tflite::TensorType_FLOAT32, + tflite::TensorType out_data_type = tflite::TensorType_FLOAT32) +{ + CastOptionsBuilder builder_(_fbb); + builder_.add_out_data_type(out_data_type); + builder_.add_in_data_type(in_data_type); + return builder_.Finish(); +} + +flatbuffers::Offset CreateCastOptions(flatbuffers::FlatBufferBuilder &_fbb, const CastOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct DequantizeOptionsT : public flatbuffers::NativeTable { + typedef DequantizeOptions TableType; + DequantizeOptionsT() + { + } +}; + +struct DequantizeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef DequantizeOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + DequantizeOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(DequantizeOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const DequantizeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct DequantizeOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit DequantizeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + DequantizeOptionsBuilder &operator=(const DequantizeOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateDequantizeOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + DequantizeOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateDequantizeOptions(flatbuffers::FlatBufferBuilder &_fbb, const DequantizeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct MaximumMinimumOptionsT : public flatbuffers::NativeTable { + typedef MaximumMinimumOptions TableType; + MaximumMinimumOptionsT() + { + } +}; + +struct MaximumMinimumOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef MaximumMinimumOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + MaximumMinimumOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(MaximumMinimumOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const MaximumMinimumOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct MaximumMinimumOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit MaximumMinimumOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + MaximumMinimumOptionsBuilder &operator=(const MaximumMinimumOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateMaximumMinimumOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + MaximumMinimumOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateMaximumMinimumOptions(flatbuffers::FlatBufferBuilder &_fbb, const MaximumMinimumOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct TileOptionsT : public flatbuffers::NativeTable { + typedef TileOptions TableType; + TileOptionsT() + { + } +}; + +struct TileOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef TileOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + TileOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(TileOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const TileOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct TileOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit TileOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + TileOptionsBuilder &operator=(const TileOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateTileOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + TileOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateTileOptions(flatbuffers::FlatBufferBuilder &_fbb, const TileOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct ArgMaxOptionsT : public flatbuffers::NativeTable { + typedef ArgMaxOptions TableType; + tflite::TensorType output_type; + ArgMaxOptionsT() + : output_type(tflite::TensorType_FLOAT32) + { + } +}; + +struct ArgMaxOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef ArgMaxOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_OUTPUT_TYPE = 4 + }; + tflite::TensorType output_type() const + { + return static_cast(GetField(VT_OUTPUT_TYPE, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_OUTPUT_TYPE) && + verifier.EndTable(); + } + ArgMaxOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(ArgMaxOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const ArgMaxOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct ArgMaxOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_output_type(tflite::TensorType output_type) + { + fbb_.AddElement(ArgMaxOptions::VT_OUTPUT_TYPE, static_cast(output_type), 0); + } + explicit ArgMaxOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ArgMaxOptionsBuilder &operator=(const ArgMaxOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateArgMaxOptions( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::TensorType output_type = tflite::TensorType_FLOAT32) +{ + ArgMaxOptionsBuilder builder_(_fbb); + builder_.add_output_type(output_type); + return builder_.Finish(); +} + +flatbuffers::Offset CreateArgMaxOptions(flatbuffers::FlatBufferBuilder &_fbb, const ArgMaxOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct ArgMinOptionsT : public flatbuffers::NativeTable { + typedef ArgMinOptions TableType; + tflite::TensorType output_type; + ArgMinOptionsT() + : output_type(tflite::TensorType_FLOAT32) + { + } +}; + +struct ArgMinOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef ArgMinOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_OUTPUT_TYPE = 4 + }; + tflite::TensorType output_type() const + { + return static_cast(GetField(VT_OUTPUT_TYPE, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_OUTPUT_TYPE) && + verifier.EndTable(); + } + ArgMinOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(ArgMinOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const ArgMinOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct ArgMinOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_output_type(tflite::TensorType output_type) + { + fbb_.AddElement(ArgMinOptions::VT_OUTPUT_TYPE, static_cast(output_type), 0); + } + explicit ArgMinOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ArgMinOptionsBuilder &operator=(const ArgMinOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateArgMinOptions( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::TensorType output_type = tflite::TensorType_FLOAT32) +{ + ArgMinOptionsBuilder builder_(_fbb); + builder_.add_output_type(output_type); + return builder_.Finish(); +} + +flatbuffers::Offset CreateArgMinOptions(flatbuffers::FlatBufferBuilder &_fbb, const ArgMinOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct GreaterOptionsT : public flatbuffers::NativeTable { + typedef GreaterOptions TableType; + GreaterOptionsT() + { + } +}; + +struct GreaterOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef GreaterOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + GreaterOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(GreaterOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const GreaterOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct GreaterOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit GreaterOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + GreaterOptionsBuilder &operator=(const GreaterOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateGreaterOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + GreaterOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateGreaterOptions(flatbuffers::FlatBufferBuilder &_fbb, const GreaterOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct GreaterEqualOptionsT : public flatbuffers::NativeTable { + typedef GreaterEqualOptions TableType; + GreaterEqualOptionsT() + { + } +}; + +struct GreaterEqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef GreaterEqualOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + GreaterEqualOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(GreaterEqualOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const GreaterEqualOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct GreaterEqualOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit GreaterEqualOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + GreaterEqualOptionsBuilder &operator=(const GreaterEqualOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateGreaterEqualOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + GreaterEqualOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateGreaterEqualOptions(flatbuffers::FlatBufferBuilder &_fbb, const GreaterEqualOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct LessOptionsT : public flatbuffers::NativeTable { + typedef LessOptions TableType; + LessOptionsT() + { + } +}; + +struct LessOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef LessOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + LessOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(LessOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const LessOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct LessOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit LessOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + LessOptionsBuilder &operator=(const LessOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateLessOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + LessOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateLessOptions(flatbuffers::FlatBufferBuilder &_fbb, const LessOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct LessEqualOptionsT : public flatbuffers::NativeTable { + typedef LessEqualOptions TableType; + LessEqualOptionsT() + { + } +}; + +struct LessEqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef LessEqualOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + LessEqualOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(LessEqualOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const LessEqualOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct LessEqualOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit LessEqualOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + LessEqualOptionsBuilder &operator=(const LessEqualOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateLessEqualOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + LessEqualOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateLessEqualOptions(flatbuffers::FlatBufferBuilder &_fbb, const LessEqualOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct NegOptionsT : public flatbuffers::NativeTable { + typedef NegOptions TableType; + NegOptionsT() + { + } +}; + +struct NegOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef NegOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + NegOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(NegOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const NegOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct NegOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit NegOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + NegOptionsBuilder &operator=(const NegOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateNegOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + NegOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateNegOptions(flatbuffers::FlatBufferBuilder &_fbb, const NegOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct SelectOptionsT : public flatbuffers::NativeTable { + typedef SelectOptions TableType; + SelectOptionsT() + { + } +}; + +struct SelectOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef SelectOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + SelectOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(SelectOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const SelectOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct SelectOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit SelectOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SelectOptionsBuilder &operator=(const SelectOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateSelectOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + SelectOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateSelectOptions(flatbuffers::FlatBufferBuilder &_fbb, const SelectOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct SliceOptionsT : public flatbuffers::NativeTable { + typedef SliceOptions TableType; + SliceOptionsT() + { + } +}; + +struct SliceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef SliceOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + SliceOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(SliceOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const SliceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct SliceOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit SliceOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SliceOptionsBuilder &operator=(const SliceOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateSliceOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + SliceOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateSliceOptions(flatbuffers::FlatBufferBuilder &_fbb, const SliceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct TransposeConvOptionsT : public flatbuffers::NativeTable { + typedef TransposeConvOptions TableType; + tflite::Padding padding; + int32_t stride_w; + int32_t stride_h; + TransposeConvOptionsT() + : padding(tflite::Padding_SAME), + stride_w(0), + stride_h(0) + { + } +}; + +struct TransposeConvOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef TransposeConvOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_PADDING = 4, + VT_STRIDE_W = 6, + VT_STRIDE_H = 8 + }; + tflite::Padding padding() const + { + return static_cast(GetField(VT_PADDING, 0)); + } + int32_t stride_w() const + { + return GetField(VT_STRIDE_W, 0); + } + int32_t stride_h() const + { + return GetField(VT_STRIDE_H, 0); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_PADDING) && + VerifyField(verifier, VT_STRIDE_W) && + VerifyField(verifier, VT_STRIDE_H) && + verifier.EndTable(); + } + TransposeConvOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(TransposeConvOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const TransposeConvOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct TransposeConvOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_padding(tflite::Padding padding) + { + fbb_.AddElement(TransposeConvOptions::VT_PADDING, static_cast(padding), 0); + } + void add_stride_w(int32_t stride_w) + { + fbb_.AddElement(TransposeConvOptions::VT_STRIDE_W, stride_w, 0); + } + void add_stride_h(int32_t stride_h) + { + fbb_.AddElement(TransposeConvOptions::VT_STRIDE_H, stride_h, 0); + } + explicit TransposeConvOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + TransposeConvOptionsBuilder &operator=(const TransposeConvOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateTransposeConvOptions( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::Padding padding = tflite::Padding_SAME, + int32_t stride_w = 0, + int32_t stride_h = 0) +{ + TransposeConvOptionsBuilder builder_(_fbb); + builder_.add_stride_h(stride_h); + builder_.add_stride_w(stride_w); + builder_.add_padding(padding); + return builder_.Finish(); +} + +flatbuffers::Offset CreateTransposeConvOptions(flatbuffers::FlatBufferBuilder &_fbb, const TransposeConvOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct ExpandDimsOptionsT : public flatbuffers::NativeTable { + typedef ExpandDimsOptions TableType; + ExpandDimsOptionsT() + { + } +}; + +struct ExpandDimsOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef ExpandDimsOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + ExpandDimsOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(ExpandDimsOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const ExpandDimsOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct ExpandDimsOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit ExpandDimsOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ExpandDimsOptionsBuilder &operator=(const ExpandDimsOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateExpandDimsOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + ExpandDimsOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateExpandDimsOptions(flatbuffers::FlatBufferBuilder &_fbb, const ExpandDimsOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct SparseToDenseOptionsT : public flatbuffers::NativeTable { + typedef SparseToDenseOptions TableType; + bool validate_indices; + SparseToDenseOptionsT() + : validate_indices(false) + { + } +}; + +struct SparseToDenseOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef SparseToDenseOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_VALIDATE_INDICES = 4 + }; + bool validate_indices() const + { + return GetField(VT_VALIDATE_INDICES, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_VALIDATE_INDICES) && + verifier.EndTable(); + } + SparseToDenseOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(SparseToDenseOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const SparseToDenseOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct SparseToDenseOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_validate_indices(bool validate_indices) + { + fbb_.AddElement(SparseToDenseOptions::VT_VALIDATE_INDICES, static_cast(validate_indices), 0); + } + explicit SparseToDenseOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SparseToDenseOptionsBuilder &operator=(const SparseToDenseOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateSparseToDenseOptions( + flatbuffers::FlatBufferBuilder &_fbb, + bool validate_indices = false) +{ + SparseToDenseOptionsBuilder builder_(_fbb); + builder_.add_validate_indices(validate_indices); + return builder_.Finish(); +} + +flatbuffers::Offset CreateSparseToDenseOptions(flatbuffers::FlatBufferBuilder &_fbb, const SparseToDenseOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct EqualOptionsT : public flatbuffers::NativeTable { + typedef EqualOptions TableType; + EqualOptionsT() + { + } +}; + +struct EqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef EqualOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + EqualOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(EqualOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const EqualOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct EqualOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit EqualOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + EqualOptionsBuilder &operator=(const EqualOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateEqualOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + EqualOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateEqualOptions(flatbuffers::FlatBufferBuilder &_fbb, const EqualOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct NotEqualOptionsT : public flatbuffers::NativeTable { + typedef NotEqualOptions TableType; + NotEqualOptionsT() + { + } +}; + +struct NotEqualOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef NotEqualOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + NotEqualOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(NotEqualOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const NotEqualOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct NotEqualOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit NotEqualOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + NotEqualOptionsBuilder &operator=(const NotEqualOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateNotEqualOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + NotEqualOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateNotEqualOptions(flatbuffers::FlatBufferBuilder &_fbb, const NotEqualOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct ShapeOptionsT : public flatbuffers::NativeTable { + typedef ShapeOptions TableType; + tflite::TensorType out_type; + ShapeOptionsT() + : out_type(tflite::TensorType_FLOAT32) + { + } +}; + +struct ShapeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef ShapeOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_OUT_TYPE = 4 + }; + tflite::TensorType out_type() const + { + return static_cast(GetField(VT_OUT_TYPE, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_OUT_TYPE) && + verifier.EndTable(); + } + ShapeOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(ShapeOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const ShapeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct ShapeOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_out_type(tflite::TensorType out_type) + { + fbb_.AddElement(ShapeOptions::VT_OUT_TYPE, static_cast(out_type), 0); + } + explicit ShapeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ShapeOptionsBuilder &operator=(const ShapeOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateShapeOptions( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::TensorType out_type = tflite::TensorType_FLOAT32) +{ + ShapeOptionsBuilder builder_(_fbb); + builder_.add_out_type(out_type); + return builder_.Finish(); +} + +flatbuffers::Offset CreateShapeOptions(flatbuffers::FlatBufferBuilder &_fbb, const ShapeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct RankOptionsT : public flatbuffers::NativeTable { + typedef RankOptions TableType; + RankOptionsT() + { + } +}; + +struct RankOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef RankOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + RankOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(RankOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const RankOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct RankOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit RankOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + RankOptionsBuilder &operator=(const RankOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateRankOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + RankOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateRankOptions(flatbuffers::FlatBufferBuilder &_fbb, const RankOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct PowOptionsT : public flatbuffers::NativeTable { + typedef PowOptions TableType; + PowOptionsT() + { + } +}; + +struct PowOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef PowOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + PowOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(PowOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const PowOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct PowOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit PowOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + PowOptionsBuilder &operator=(const PowOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreatePowOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + PowOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreatePowOptions(flatbuffers::FlatBufferBuilder &_fbb, const PowOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct FakeQuantOptionsT : public flatbuffers::NativeTable { + typedef FakeQuantOptions TableType; + float min; + float max; + int32_t num_bits; + bool narrow_range; + FakeQuantOptionsT() + : min(0.0f), + max(0.0f), + num_bits(0), + narrow_range(false) + { + } +}; + +struct FakeQuantOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef FakeQuantOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_MIN = 4, + VT_MAX = 6, + VT_NUM_BITS = 8, + VT_NARROW_RANGE = 10 + }; + float min() const + { + return GetField(VT_MIN, 0.0f); + } + float max() const + { + return GetField(VT_MAX, 0.0f); + } + int32_t num_bits() const + { + return GetField(VT_NUM_BITS, 0); + } + bool narrow_range() const + { + return GetField(VT_NARROW_RANGE, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_MIN) && + VerifyField(verifier, VT_MAX) && + VerifyField(verifier, VT_NUM_BITS) && + VerifyField(verifier, VT_NARROW_RANGE) && + verifier.EndTable(); + } + FakeQuantOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(FakeQuantOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const FakeQuantOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct FakeQuantOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_min(float min) + { + fbb_.AddElement(FakeQuantOptions::VT_MIN, min, 0.0f); + } + void add_max(float max) + { + fbb_.AddElement(FakeQuantOptions::VT_MAX, max, 0.0f); + } + void add_num_bits(int32_t num_bits) + { + fbb_.AddElement(FakeQuantOptions::VT_NUM_BITS, num_bits, 0); + } + void add_narrow_range(bool narrow_range) + { + fbb_.AddElement(FakeQuantOptions::VT_NARROW_RANGE, static_cast(narrow_range), 0); + } + explicit FakeQuantOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + FakeQuantOptionsBuilder &operator=(const FakeQuantOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateFakeQuantOptions( + flatbuffers::FlatBufferBuilder &_fbb, + float min = 0.0f, + float max = 0.0f, + int32_t num_bits = 0, + bool narrow_range = false) +{ + FakeQuantOptionsBuilder builder_(_fbb); + builder_.add_num_bits(num_bits); + builder_.add_max(max); + builder_.add_min(min); + builder_.add_narrow_range(narrow_range); + return builder_.Finish(); +} + +flatbuffers::Offset CreateFakeQuantOptions(flatbuffers::FlatBufferBuilder &_fbb, const FakeQuantOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct PackOptionsT : public flatbuffers::NativeTable { + typedef PackOptions TableType; + int32_t values_count; + int32_t axis; + PackOptionsT() + : values_count(0), + axis(0) + { + } +}; + +struct PackOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef PackOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_VALUES_COUNT = 4, + VT_AXIS = 6 + }; + int32_t values_count() const + { + return GetField(VT_VALUES_COUNT, 0); + } + int32_t axis() const + { + return GetField(VT_AXIS, 0); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_VALUES_COUNT) && + VerifyField(verifier, VT_AXIS) && + verifier.EndTable(); + } + PackOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(PackOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const PackOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct PackOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_values_count(int32_t values_count) + { + fbb_.AddElement(PackOptions::VT_VALUES_COUNT, values_count, 0); + } + void add_axis(int32_t axis) + { + fbb_.AddElement(PackOptions::VT_AXIS, axis, 0); + } + explicit PackOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + PackOptionsBuilder &operator=(const PackOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreatePackOptions( + flatbuffers::FlatBufferBuilder &_fbb, + int32_t values_count = 0, + int32_t axis = 0) +{ + PackOptionsBuilder builder_(_fbb); + builder_.add_axis(axis); + builder_.add_values_count(values_count); + return builder_.Finish(); +} + +flatbuffers::Offset CreatePackOptions(flatbuffers::FlatBufferBuilder &_fbb, const PackOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct LogicalOrOptionsT : public flatbuffers::NativeTable { + typedef LogicalOrOptions TableType; + LogicalOrOptionsT() + { + } +}; + +struct LogicalOrOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef LogicalOrOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + LogicalOrOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(LogicalOrOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const LogicalOrOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct LogicalOrOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit LogicalOrOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + LogicalOrOptionsBuilder &operator=(const LogicalOrOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateLogicalOrOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + LogicalOrOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateLogicalOrOptions(flatbuffers::FlatBufferBuilder &_fbb, const LogicalOrOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct OneHotOptionsT : public flatbuffers::NativeTable { + typedef OneHotOptions TableType; + int32_t axis; + OneHotOptionsT() + : axis(0) + { + } +}; + +struct OneHotOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef OneHotOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_AXIS = 4 + }; + int32_t axis() const + { + return GetField(VT_AXIS, 0); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_AXIS) && + verifier.EndTable(); + } + OneHotOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(OneHotOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const OneHotOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct OneHotOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_axis(int32_t axis) + { + fbb_.AddElement(OneHotOptions::VT_AXIS, axis, 0); + } + explicit OneHotOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + OneHotOptionsBuilder &operator=(const OneHotOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateOneHotOptions( + flatbuffers::FlatBufferBuilder &_fbb, + int32_t axis = 0) +{ + OneHotOptionsBuilder builder_(_fbb); + builder_.add_axis(axis); + return builder_.Finish(); +} + +flatbuffers::Offset CreateOneHotOptions(flatbuffers::FlatBufferBuilder &_fbb, const OneHotOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct AbsOptionsT : public flatbuffers::NativeTable { + typedef AbsOptions TableType; + AbsOptionsT() + { + } +}; + +struct AbsOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef AbsOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + AbsOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(AbsOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const AbsOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct AbsOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit AbsOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + AbsOptionsBuilder &operator=(const AbsOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateAbsOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + AbsOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateAbsOptions(flatbuffers::FlatBufferBuilder &_fbb, const AbsOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct HardSwishOptionsT : public flatbuffers::NativeTable { + typedef HardSwishOptions TableType; + HardSwishOptionsT() + { + } +}; + +struct HardSwishOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef HardSwishOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + HardSwishOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(HardSwishOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const HardSwishOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct HardSwishOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit HardSwishOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + HardSwishOptionsBuilder &operator=(const HardSwishOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateHardSwishOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + HardSwishOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateHardSwishOptions(flatbuffers::FlatBufferBuilder &_fbb, const HardSwishOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct LogicalAndOptionsT : public flatbuffers::NativeTable { + typedef LogicalAndOptions TableType; + LogicalAndOptionsT() + { + } +}; + +struct LogicalAndOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef LogicalAndOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + LogicalAndOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(LogicalAndOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const LogicalAndOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct LogicalAndOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit LogicalAndOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + LogicalAndOptionsBuilder &operator=(const LogicalAndOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateLogicalAndOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + LogicalAndOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateLogicalAndOptions(flatbuffers::FlatBufferBuilder &_fbb, const LogicalAndOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct LogicalNotOptionsT : public flatbuffers::NativeTable { + typedef LogicalNotOptions TableType; + LogicalNotOptionsT() + { + } +}; + +struct LogicalNotOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef LogicalNotOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + LogicalNotOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(LogicalNotOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const LogicalNotOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct LogicalNotOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit LogicalNotOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + LogicalNotOptionsBuilder &operator=(const LogicalNotOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateLogicalNotOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + LogicalNotOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateLogicalNotOptions(flatbuffers::FlatBufferBuilder &_fbb, const LogicalNotOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct UnpackOptionsT : public flatbuffers::NativeTable { + typedef UnpackOptions TableType; + int32_t num; + int32_t axis; + UnpackOptionsT() + : num(0), + axis(0) + { + } +}; + +struct UnpackOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef UnpackOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_NUM = 4, + VT_AXIS = 6 + }; + int32_t num() const + { + return GetField(VT_NUM, 0); + } + int32_t axis() const + { + return GetField(VT_AXIS, 0); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_NUM) && + VerifyField(verifier, VT_AXIS) && + verifier.EndTable(); + } + UnpackOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(UnpackOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const UnpackOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct UnpackOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_num(int32_t num) + { + fbb_.AddElement(UnpackOptions::VT_NUM, num, 0); + } + void add_axis(int32_t axis) + { + fbb_.AddElement(UnpackOptions::VT_AXIS, axis, 0); + } + explicit UnpackOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + UnpackOptionsBuilder &operator=(const UnpackOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateUnpackOptions( + flatbuffers::FlatBufferBuilder &_fbb, + int32_t num = 0, + int32_t axis = 0) +{ + UnpackOptionsBuilder builder_(_fbb); + builder_.add_axis(axis); + builder_.add_num(num); + return builder_.Finish(); +} + +flatbuffers::Offset CreateUnpackOptions(flatbuffers::FlatBufferBuilder &_fbb, const UnpackOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct FloorDivOptionsT : public flatbuffers::NativeTable { + typedef FloorDivOptions TableType; + FloorDivOptionsT() + { + } +}; + +struct FloorDivOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef FloorDivOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + FloorDivOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(FloorDivOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const FloorDivOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct FloorDivOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit FloorDivOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + FloorDivOptionsBuilder &operator=(const FloorDivOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateFloorDivOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + FloorDivOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateFloorDivOptions(flatbuffers::FlatBufferBuilder &_fbb, const FloorDivOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct SquareOptionsT : public flatbuffers::NativeTable { + typedef SquareOptions TableType; + SquareOptionsT() + { + } +}; + +struct SquareOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef SquareOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + SquareOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(SquareOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const SquareOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct SquareOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit SquareOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SquareOptionsBuilder &operator=(const SquareOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateSquareOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + SquareOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateSquareOptions(flatbuffers::FlatBufferBuilder &_fbb, const SquareOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct ZerosLikeOptionsT : public flatbuffers::NativeTable { + typedef ZerosLikeOptions TableType; + ZerosLikeOptionsT() + { + } +}; + +struct ZerosLikeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef ZerosLikeOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + ZerosLikeOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(ZerosLikeOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const ZerosLikeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct ZerosLikeOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit ZerosLikeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ZerosLikeOptionsBuilder &operator=(const ZerosLikeOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateZerosLikeOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + ZerosLikeOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateZerosLikeOptions(flatbuffers::FlatBufferBuilder &_fbb, const ZerosLikeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct FillOptionsT : public flatbuffers::NativeTable { + typedef FillOptions TableType; + FillOptionsT() + { + } +}; + +struct FillOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef FillOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + FillOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(FillOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const FillOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct FillOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit FillOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + FillOptionsBuilder &operator=(const FillOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateFillOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + FillOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateFillOptions(flatbuffers::FlatBufferBuilder &_fbb, const FillOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct FloorModOptionsT : public flatbuffers::NativeTable { + typedef FloorModOptions TableType; + FloorModOptionsT() + { + } +}; + +struct FloorModOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef FloorModOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + FloorModOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(FloorModOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const FloorModOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct FloorModOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit FloorModOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + FloorModOptionsBuilder &operator=(const FloorModOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateFloorModOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + FloorModOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateFloorModOptions(flatbuffers::FlatBufferBuilder &_fbb, const FloorModOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct RangeOptionsT : public flatbuffers::NativeTable { + typedef RangeOptions TableType; + RangeOptionsT() + { + } +}; + +struct RangeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef RangeOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + RangeOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(RangeOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const RangeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct RangeOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit RangeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + RangeOptionsBuilder &operator=(const RangeOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateRangeOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + RangeOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateRangeOptions(flatbuffers::FlatBufferBuilder &_fbb, const RangeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct LeakyReluOptionsT : public flatbuffers::NativeTable { + typedef LeakyReluOptions TableType; + float alpha; + LeakyReluOptionsT() + : alpha(0.0f) + { + } +}; + +struct LeakyReluOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef LeakyReluOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_ALPHA = 4 + }; + float alpha() const + { + return GetField(VT_ALPHA, 0.0f); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_ALPHA) && + verifier.EndTable(); + } + LeakyReluOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(LeakyReluOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const LeakyReluOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct LeakyReluOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_alpha(float alpha) + { + fbb_.AddElement(LeakyReluOptions::VT_ALPHA, alpha, 0.0f); + } + explicit LeakyReluOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + LeakyReluOptionsBuilder &operator=(const LeakyReluOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateLeakyReluOptions( + flatbuffers::FlatBufferBuilder &_fbb, + float alpha = 0.0f) +{ + LeakyReluOptionsBuilder builder_(_fbb); + builder_.add_alpha(alpha); + return builder_.Finish(); +} + +flatbuffers::Offset CreateLeakyReluOptions(flatbuffers::FlatBufferBuilder &_fbb, const LeakyReluOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct SquaredDifferenceOptionsT : public flatbuffers::NativeTable { + typedef SquaredDifferenceOptions TableType; + SquaredDifferenceOptionsT() + { + } +}; + +struct SquaredDifferenceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef SquaredDifferenceOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + SquaredDifferenceOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(SquaredDifferenceOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const SquaredDifferenceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct SquaredDifferenceOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit SquaredDifferenceOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SquaredDifferenceOptionsBuilder &operator=(const SquaredDifferenceOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateSquaredDifferenceOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + SquaredDifferenceOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateSquaredDifferenceOptions(flatbuffers::FlatBufferBuilder &_fbb, const SquaredDifferenceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct MirrorPadOptionsT : public flatbuffers::NativeTable { + typedef MirrorPadOptions TableType; + tflite::MirrorPadMode mode; + MirrorPadOptionsT() + : mode(tflite::MirrorPadMode_REFLECT) + { + } +}; + +struct MirrorPadOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef MirrorPadOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_MODE = 4 + }; + tflite::MirrorPadMode mode() const + { + return static_cast(GetField(VT_MODE, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_MODE) && + verifier.EndTable(); + } + MirrorPadOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(MirrorPadOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const MirrorPadOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct MirrorPadOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_mode(tflite::MirrorPadMode mode) + { + fbb_.AddElement(MirrorPadOptions::VT_MODE, static_cast(mode), 0); + } + explicit MirrorPadOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + MirrorPadOptionsBuilder &operator=(const MirrorPadOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateMirrorPadOptions( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::MirrorPadMode mode = tflite::MirrorPadMode_REFLECT) +{ + MirrorPadOptionsBuilder builder_(_fbb); + builder_.add_mode(mode); + return builder_.Finish(); +} + +flatbuffers::Offset CreateMirrorPadOptions(flatbuffers::FlatBufferBuilder &_fbb, const MirrorPadOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct UniqueOptionsT : public flatbuffers::NativeTable { + typedef UniqueOptions TableType; + tflite::TensorType idx_out_type; + UniqueOptionsT() + : idx_out_type(tflite::TensorType_INT32) + { + } +}; + +struct UniqueOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef UniqueOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_IDX_OUT_TYPE = 4 + }; + tflite::TensorType idx_out_type() const + { + return static_cast(GetField(VT_IDX_OUT_TYPE, 2)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_IDX_OUT_TYPE) && + verifier.EndTable(); + } + UniqueOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(UniqueOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const UniqueOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct UniqueOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_idx_out_type(tflite::TensorType idx_out_type) + { + fbb_.AddElement(UniqueOptions::VT_IDX_OUT_TYPE, static_cast(idx_out_type), 2); + } + explicit UniqueOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + UniqueOptionsBuilder &operator=(const UniqueOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateUniqueOptions( + flatbuffers::FlatBufferBuilder &_fbb, + tflite::TensorType idx_out_type = tflite::TensorType_INT32) +{ + UniqueOptionsBuilder builder_(_fbb); + builder_.add_idx_out_type(idx_out_type); + return builder_.Finish(); +} + +flatbuffers::Offset CreateUniqueOptions(flatbuffers::FlatBufferBuilder &_fbb, const UniqueOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct ReverseV2OptionsT : public flatbuffers::NativeTable { + typedef ReverseV2Options TableType; + ReverseV2OptionsT() + { + } +}; + +struct ReverseV2Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef ReverseV2OptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + ReverseV2OptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(ReverseV2OptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const ReverseV2OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct ReverseV2OptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit ReverseV2OptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ReverseV2OptionsBuilder &operator=(const ReverseV2OptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateReverseV2Options( + flatbuffers::FlatBufferBuilder &_fbb) +{ + ReverseV2OptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateReverseV2Options(flatbuffers::FlatBufferBuilder &_fbb, const ReverseV2OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct AddNOptionsT : public flatbuffers::NativeTable { + typedef AddNOptions TableType; + AddNOptionsT() + { + } +}; + +struct AddNOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef AddNOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + AddNOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(AddNOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const AddNOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct AddNOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit AddNOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + AddNOptionsBuilder &operator=(const AddNOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateAddNOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + AddNOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateAddNOptions(flatbuffers::FlatBufferBuilder &_fbb, const AddNOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct GatherNdOptionsT : public flatbuffers::NativeTable { + typedef GatherNdOptions TableType; + GatherNdOptionsT() + { + } +}; + +struct GatherNdOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef GatherNdOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + GatherNdOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(GatherNdOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const GatherNdOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct GatherNdOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit GatherNdOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + GatherNdOptionsBuilder &operator=(const GatherNdOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateGatherNdOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + GatherNdOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateGatherNdOptions(flatbuffers::FlatBufferBuilder &_fbb, const GatherNdOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct WhereOptionsT : public flatbuffers::NativeTable { + typedef WhereOptions TableType; + WhereOptionsT() + { + } +}; + +struct WhereOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef WhereOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + WhereOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(WhereOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const WhereOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct WhereOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit WhereOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + WhereOptionsBuilder &operator=(const WhereOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateWhereOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + WhereOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateWhereOptions(flatbuffers::FlatBufferBuilder &_fbb, const WhereOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct ReverseSequenceOptionsT : public flatbuffers::NativeTable { + typedef ReverseSequenceOptions TableType; + int32_t seq_dim; + int32_t batch_dim; + ReverseSequenceOptionsT() + : seq_dim(0), + batch_dim(0) + { + } +}; + +struct ReverseSequenceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef ReverseSequenceOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_SEQ_DIM = 4, + VT_BATCH_DIM = 6 + }; + int32_t seq_dim() const + { + return GetField(VT_SEQ_DIM, 0); + } + int32_t batch_dim() const + { + return GetField(VT_BATCH_DIM, 0); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_SEQ_DIM) && + VerifyField(verifier, VT_BATCH_DIM) && + verifier.EndTable(); + } + ReverseSequenceOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(ReverseSequenceOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const ReverseSequenceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct ReverseSequenceOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_seq_dim(int32_t seq_dim) + { + fbb_.AddElement(ReverseSequenceOptions::VT_SEQ_DIM, seq_dim, 0); + } + void add_batch_dim(int32_t batch_dim) + { + fbb_.AddElement(ReverseSequenceOptions::VT_BATCH_DIM, batch_dim, 0); + } + explicit ReverseSequenceOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ReverseSequenceOptionsBuilder &operator=(const ReverseSequenceOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateReverseSequenceOptions( + flatbuffers::FlatBufferBuilder &_fbb, + int32_t seq_dim = 0, + int32_t batch_dim = 0) +{ + ReverseSequenceOptionsBuilder builder_(_fbb); + builder_.add_batch_dim(batch_dim); + builder_.add_seq_dim(seq_dim); + return builder_.Finish(); +} + +flatbuffers::Offset CreateReverseSequenceOptions(flatbuffers::FlatBufferBuilder &_fbb, const ReverseSequenceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct MatrixDiagOptionsT : public flatbuffers::NativeTable { + typedef MatrixDiagOptions TableType; + MatrixDiagOptionsT() + { + } +}; + +struct MatrixDiagOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef MatrixDiagOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + MatrixDiagOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(MatrixDiagOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const MatrixDiagOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct MatrixDiagOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit MatrixDiagOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + MatrixDiagOptionsBuilder &operator=(const MatrixDiagOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateMatrixDiagOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + MatrixDiagOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateMatrixDiagOptions(flatbuffers::FlatBufferBuilder &_fbb, const MatrixDiagOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct QuantizeOptionsT : public flatbuffers::NativeTable { + typedef QuantizeOptions TableType; + QuantizeOptionsT() + { + } +}; + +struct QuantizeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef QuantizeOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + QuantizeOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(QuantizeOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const QuantizeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct QuantizeOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit QuantizeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + QuantizeOptionsBuilder &operator=(const QuantizeOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateQuantizeOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + QuantizeOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateQuantizeOptions(flatbuffers::FlatBufferBuilder &_fbb, const QuantizeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct MatrixSetDiagOptionsT : public flatbuffers::NativeTable { + typedef MatrixSetDiagOptions TableType; + MatrixSetDiagOptionsT() + { + } +}; + +struct MatrixSetDiagOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef MatrixSetDiagOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + MatrixSetDiagOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(MatrixSetDiagOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const MatrixSetDiagOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct MatrixSetDiagOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit MatrixSetDiagOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + MatrixSetDiagOptionsBuilder &operator=(const MatrixSetDiagOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateMatrixSetDiagOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + MatrixSetDiagOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateMatrixSetDiagOptions(flatbuffers::FlatBufferBuilder &_fbb, const MatrixSetDiagOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct IfOptionsT : public flatbuffers::NativeTable { + typedef IfOptions TableType; + int32_t then_subgraph_index; + int32_t else_subgraph_index; + IfOptionsT() + : then_subgraph_index(0), + else_subgraph_index(0) + { + } +}; + +struct IfOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef IfOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_THEN_SUBGRAPH_INDEX = 4, + VT_ELSE_SUBGRAPH_INDEX = 6 + }; + int32_t then_subgraph_index() const + { + return GetField(VT_THEN_SUBGRAPH_INDEX, 0); + } + int32_t else_subgraph_index() const + { + return GetField(VT_ELSE_SUBGRAPH_INDEX, 0); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_THEN_SUBGRAPH_INDEX) && + VerifyField(verifier, VT_ELSE_SUBGRAPH_INDEX) && + verifier.EndTable(); + } + IfOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(IfOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const IfOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct IfOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_then_subgraph_index(int32_t then_subgraph_index) + { + fbb_.AddElement(IfOptions::VT_THEN_SUBGRAPH_INDEX, then_subgraph_index, 0); + } + void add_else_subgraph_index(int32_t else_subgraph_index) + { + fbb_.AddElement(IfOptions::VT_ELSE_SUBGRAPH_INDEX, else_subgraph_index, 0); + } + explicit IfOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + IfOptionsBuilder &operator=(const IfOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateIfOptions( + flatbuffers::FlatBufferBuilder &_fbb, + int32_t then_subgraph_index = 0, + int32_t else_subgraph_index = 0) +{ + IfOptionsBuilder builder_(_fbb); + builder_.add_else_subgraph_index(else_subgraph_index); + builder_.add_then_subgraph_index(then_subgraph_index); + return builder_.Finish(); +} + +flatbuffers::Offset CreateIfOptions(flatbuffers::FlatBufferBuilder &_fbb, const IfOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct CallOnceOptionsT : public flatbuffers::NativeTable { + typedef CallOnceOptions TableType; + int32_t init_subgraph_index; + CallOnceOptionsT() + : init_subgraph_index(0) + { + } +}; + +struct CallOnceOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef CallOnceOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_INIT_SUBGRAPH_INDEX = 4 + }; + int32_t init_subgraph_index() const + { + return GetField(VT_INIT_SUBGRAPH_INDEX, 0); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_INIT_SUBGRAPH_INDEX) && + verifier.EndTable(); + } + CallOnceOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(CallOnceOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const CallOnceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct CallOnceOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_init_subgraph_index(int32_t init_subgraph_index) + { + fbb_.AddElement(CallOnceOptions::VT_INIT_SUBGRAPH_INDEX, init_subgraph_index, 0); + } + explicit CallOnceOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + CallOnceOptionsBuilder &operator=(const CallOnceOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateCallOnceOptions( + flatbuffers::FlatBufferBuilder &_fbb, + int32_t init_subgraph_index = 0) +{ + CallOnceOptionsBuilder builder_(_fbb); + builder_.add_init_subgraph_index(init_subgraph_index); + return builder_.Finish(); +} + +flatbuffers::Offset CreateCallOnceOptions(flatbuffers::FlatBufferBuilder &_fbb, const CallOnceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct WhileOptionsT : public flatbuffers::NativeTable { + typedef WhileOptions TableType; + int32_t cond_subgraph_index; + int32_t body_subgraph_index; + WhileOptionsT() + : cond_subgraph_index(0), + body_subgraph_index(0) + { + } +}; + +struct WhileOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef WhileOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_COND_SUBGRAPH_INDEX = 4, + VT_BODY_SUBGRAPH_INDEX = 6 + }; + int32_t cond_subgraph_index() const + { + return GetField(VT_COND_SUBGRAPH_INDEX, 0); + } + int32_t body_subgraph_index() const + { + return GetField(VT_BODY_SUBGRAPH_INDEX, 0); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_COND_SUBGRAPH_INDEX) && + VerifyField(verifier, VT_BODY_SUBGRAPH_INDEX) && + verifier.EndTable(); + } + WhileOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(WhileOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const WhileOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct WhileOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_cond_subgraph_index(int32_t cond_subgraph_index) + { + fbb_.AddElement(WhileOptions::VT_COND_SUBGRAPH_INDEX, cond_subgraph_index, 0); + } + void add_body_subgraph_index(int32_t body_subgraph_index) + { + fbb_.AddElement(WhileOptions::VT_BODY_SUBGRAPH_INDEX, body_subgraph_index, 0); + } + explicit WhileOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + WhileOptionsBuilder &operator=(const WhileOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateWhileOptions( + flatbuffers::FlatBufferBuilder &_fbb, + int32_t cond_subgraph_index = 0, + int32_t body_subgraph_index = 0) +{ + WhileOptionsBuilder builder_(_fbb); + builder_.add_body_subgraph_index(body_subgraph_index); + builder_.add_cond_subgraph_index(cond_subgraph_index); + return builder_.Finish(); +} + +flatbuffers::Offset CreateWhileOptions(flatbuffers::FlatBufferBuilder &_fbb, const WhileOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct NonMaxSuppressionV4OptionsT : public flatbuffers::NativeTable { + typedef NonMaxSuppressionV4Options TableType; + NonMaxSuppressionV4OptionsT() + { + } +}; + +struct NonMaxSuppressionV4Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef NonMaxSuppressionV4OptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + NonMaxSuppressionV4OptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(NonMaxSuppressionV4OptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const NonMaxSuppressionV4OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct NonMaxSuppressionV4OptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit NonMaxSuppressionV4OptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + NonMaxSuppressionV4OptionsBuilder &operator=(const NonMaxSuppressionV4OptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateNonMaxSuppressionV4Options( + flatbuffers::FlatBufferBuilder &_fbb) +{ + NonMaxSuppressionV4OptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateNonMaxSuppressionV4Options(flatbuffers::FlatBufferBuilder &_fbb, const NonMaxSuppressionV4OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct NonMaxSuppressionV5OptionsT : public flatbuffers::NativeTable { + typedef NonMaxSuppressionV5Options TableType; + NonMaxSuppressionV5OptionsT() + { + } +}; + +struct NonMaxSuppressionV5Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef NonMaxSuppressionV5OptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + NonMaxSuppressionV5OptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(NonMaxSuppressionV5OptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const NonMaxSuppressionV5OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct NonMaxSuppressionV5OptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit NonMaxSuppressionV5OptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + NonMaxSuppressionV5OptionsBuilder &operator=(const NonMaxSuppressionV5OptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateNonMaxSuppressionV5Options( + flatbuffers::FlatBufferBuilder &_fbb) +{ + NonMaxSuppressionV5OptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateNonMaxSuppressionV5Options(flatbuffers::FlatBufferBuilder &_fbb, const NonMaxSuppressionV5OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct ScatterNdOptionsT : public flatbuffers::NativeTable { + typedef ScatterNdOptions TableType; + ScatterNdOptionsT() + { + } +}; + +struct ScatterNdOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef ScatterNdOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + ScatterNdOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(ScatterNdOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const ScatterNdOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct ScatterNdOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit ScatterNdOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ScatterNdOptionsBuilder &operator=(const ScatterNdOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateScatterNdOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + ScatterNdOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateScatterNdOptions(flatbuffers::FlatBufferBuilder &_fbb, const ScatterNdOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct SelectV2OptionsT : public flatbuffers::NativeTable { + typedef SelectV2Options TableType; + SelectV2OptionsT() + { + } +}; + +struct SelectV2Options FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef SelectV2OptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + SelectV2OptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(SelectV2OptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const SelectV2OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct SelectV2OptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit SelectV2OptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SelectV2OptionsBuilder &operator=(const SelectV2OptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateSelectV2Options( + flatbuffers::FlatBufferBuilder &_fbb) +{ + SelectV2OptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateSelectV2Options(flatbuffers::FlatBufferBuilder &_fbb, const SelectV2OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct DensifyOptionsT : public flatbuffers::NativeTable { + typedef DensifyOptions TableType; + DensifyOptionsT() + { + } +}; + +struct DensifyOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef DensifyOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + DensifyOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(DensifyOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const DensifyOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct DensifyOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit DensifyOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + DensifyOptionsBuilder &operator=(const DensifyOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateDensifyOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + DensifyOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateDensifyOptions(flatbuffers::FlatBufferBuilder &_fbb, const DensifyOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct SegmentSumOptionsT : public flatbuffers::NativeTable { + typedef SegmentSumOptions TableType; + SegmentSumOptionsT() + { + } +}; + +struct SegmentSumOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef SegmentSumOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + SegmentSumOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(SegmentSumOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const SegmentSumOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct SegmentSumOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit SegmentSumOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SegmentSumOptionsBuilder &operator=(const SegmentSumOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateSegmentSumOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + SegmentSumOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateSegmentSumOptions(flatbuffers::FlatBufferBuilder &_fbb, const SegmentSumOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct BatchMatMulOptionsT : public flatbuffers::NativeTable { + typedef BatchMatMulOptions TableType; + bool adj_x; + bool adj_y; + bool asymmetric_quantize_inputs; + BatchMatMulOptionsT() + : adj_x(false), + adj_y(false), + asymmetric_quantize_inputs(false) + { + } +}; + +struct BatchMatMulOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef BatchMatMulOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_ADJ_X = 4, + VT_ADJ_Y = 6, + VT_ASYMMETRIC_QUANTIZE_INPUTS = 8 + }; + bool adj_x() const + { + return GetField(VT_ADJ_X, 0) != 0; + } + bool adj_y() const + { + return GetField(VT_ADJ_Y, 0) != 0; + } + bool asymmetric_quantize_inputs() const + { + return GetField(VT_ASYMMETRIC_QUANTIZE_INPUTS, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_ADJ_X) && + VerifyField(verifier, VT_ADJ_Y) && + VerifyField(verifier, VT_ASYMMETRIC_QUANTIZE_INPUTS) && + verifier.EndTable(); + } + BatchMatMulOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(BatchMatMulOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const BatchMatMulOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct BatchMatMulOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_adj_x(bool adj_x) + { + fbb_.AddElement(BatchMatMulOptions::VT_ADJ_X, static_cast(adj_x), 0); + } + void add_adj_y(bool adj_y) + { + fbb_.AddElement(BatchMatMulOptions::VT_ADJ_Y, static_cast(adj_y), 0); + } + void add_asymmetric_quantize_inputs(bool asymmetric_quantize_inputs) + { + fbb_.AddElement(BatchMatMulOptions::VT_ASYMMETRIC_QUANTIZE_INPUTS, static_cast(asymmetric_quantize_inputs), 0); + } + explicit BatchMatMulOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + BatchMatMulOptionsBuilder &operator=(const BatchMatMulOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateBatchMatMulOptions( + flatbuffers::FlatBufferBuilder &_fbb, + bool adj_x = false, + bool adj_y = false, + bool asymmetric_quantize_inputs = false) +{ + BatchMatMulOptionsBuilder builder_(_fbb); + builder_.add_asymmetric_quantize_inputs(asymmetric_quantize_inputs); + builder_.add_adj_y(adj_y); + builder_.add_adj_x(adj_x); + return builder_.Finish(); +} + +flatbuffers::Offset CreateBatchMatMulOptions(flatbuffers::FlatBufferBuilder &_fbb, const BatchMatMulOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct CumsumOptionsT : public flatbuffers::NativeTable { + typedef CumsumOptions TableType; + bool exclusive; + bool reverse; + CumsumOptionsT() + : exclusive(false), + reverse(false) + { + } +}; + +struct CumsumOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef CumsumOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_EXCLUSIVE = 4, + VT_REVERSE = 6 + }; + bool exclusive() const + { + return GetField(VT_EXCLUSIVE, 0) != 0; + } + bool reverse() const + { + return GetField(VT_REVERSE, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_EXCLUSIVE) && + VerifyField(verifier, VT_REVERSE) && + verifier.EndTable(); + } + CumsumOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(CumsumOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const CumsumOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct CumsumOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_exclusive(bool exclusive) + { + fbb_.AddElement(CumsumOptions::VT_EXCLUSIVE, static_cast(exclusive), 0); + } + void add_reverse(bool reverse) + { + fbb_.AddElement(CumsumOptions::VT_REVERSE, static_cast(reverse), 0); + } + explicit CumsumOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + CumsumOptionsBuilder &operator=(const CumsumOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateCumsumOptions( + flatbuffers::FlatBufferBuilder &_fbb, + bool exclusive = false, + bool reverse = false) +{ + CumsumOptionsBuilder builder_(_fbb); + builder_.add_reverse(reverse); + builder_.add_exclusive(exclusive); + return builder_.Finish(); +} + +flatbuffers::Offset CreateCumsumOptions(flatbuffers::FlatBufferBuilder &_fbb, const CumsumOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct BroadcastToOptionsT : public flatbuffers::NativeTable { + typedef BroadcastToOptions TableType; + BroadcastToOptionsT() + { + } +}; + +struct BroadcastToOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef BroadcastToOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + BroadcastToOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(BroadcastToOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const BroadcastToOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct BroadcastToOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit BroadcastToOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + BroadcastToOptionsBuilder &operator=(const BroadcastToOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateBroadcastToOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + BroadcastToOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateBroadcastToOptions(flatbuffers::FlatBufferBuilder &_fbb, const BroadcastToOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct Rfft2dOptionsT : public flatbuffers::NativeTable { + typedef Rfft2dOptions TableType; + Rfft2dOptionsT() + { + } +}; + +struct Rfft2dOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef Rfft2dOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + Rfft2dOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(Rfft2dOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const Rfft2dOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct Rfft2dOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit Rfft2dOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + Rfft2dOptionsBuilder &operator=(const Rfft2dOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateRfft2dOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + Rfft2dOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateRfft2dOptions(flatbuffers::FlatBufferBuilder &_fbb, const Rfft2dOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct HashtableOptionsT : public flatbuffers::NativeTable { + typedef HashtableOptions TableType; + int32_t table_id; + tflite::TensorType key_dtype; + tflite::TensorType value_dtype; + HashtableOptionsT() + : table_id(0), + key_dtype(tflite::TensorType_FLOAT32), + value_dtype(tflite::TensorType_FLOAT32) + { + } +}; + +struct HashtableOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef HashtableOptionsT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_TABLE_ID = 4, + VT_KEY_DTYPE = 6, + VT_VALUE_DTYPE = 8 + }; + int32_t table_id() const + { + return GetField(VT_TABLE_ID, 0); + } + tflite::TensorType key_dtype() const + { + return static_cast(GetField(VT_KEY_DTYPE, 0)); + } + tflite::TensorType value_dtype() const + { + return static_cast(GetField(VT_VALUE_DTYPE, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_TABLE_ID) && + VerifyField(verifier, VT_KEY_DTYPE) && + VerifyField(verifier, VT_VALUE_DTYPE) && + verifier.EndTable(); + } + HashtableOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(HashtableOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const HashtableOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct HashtableOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_table_id(int32_t table_id) + { + fbb_.AddElement(HashtableOptions::VT_TABLE_ID, table_id, 0); + } + void add_key_dtype(tflite::TensorType key_dtype) + { + fbb_.AddElement(HashtableOptions::VT_KEY_DTYPE, static_cast(key_dtype), 0); + } + void add_value_dtype(tflite::TensorType value_dtype) + { + fbb_.AddElement(HashtableOptions::VT_VALUE_DTYPE, static_cast(value_dtype), 0); + } + explicit HashtableOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + HashtableOptionsBuilder &operator=(const HashtableOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateHashtableOptions( + flatbuffers::FlatBufferBuilder &_fbb, + int32_t table_id = 0, + tflite::TensorType key_dtype = tflite::TensorType_FLOAT32, + tflite::TensorType value_dtype = tflite::TensorType_FLOAT32) +{ + HashtableOptionsBuilder builder_(_fbb); + builder_.add_table_id(table_id); + builder_.add_value_dtype(value_dtype); + builder_.add_key_dtype(key_dtype); + return builder_.Finish(); +} + +flatbuffers::Offset CreateHashtableOptions(flatbuffers::FlatBufferBuilder &_fbb, const HashtableOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct HashtableFindOptionsT : public flatbuffers::NativeTable { + typedef HashtableFindOptions TableType; + HashtableFindOptionsT() + { + } +}; + +struct HashtableFindOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef HashtableFindOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + HashtableFindOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(HashtableFindOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const HashtableFindOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct HashtableFindOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit HashtableFindOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + HashtableFindOptionsBuilder &operator=(const HashtableFindOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateHashtableFindOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + HashtableFindOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateHashtableFindOptions(flatbuffers::FlatBufferBuilder &_fbb, const HashtableFindOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct HashtableImportOptionsT : public flatbuffers::NativeTable { + typedef HashtableImportOptions TableType; + HashtableImportOptionsT() + { + } +}; + +struct HashtableImportOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef HashtableImportOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + HashtableImportOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(HashtableImportOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const HashtableImportOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct HashtableImportOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit HashtableImportOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + HashtableImportOptionsBuilder &operator=(const HashtableImportOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateHashtableImportOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + HashtableImportOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateHashtableImportOptions(flatbuffers::FlatBufferBuilder &_fbb, const HashtableImportOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct HashtableSizeOptionsT : public flatbuffers::NativeTable { + typedef HashtableSizeOptions TableType; + HashtableSizeOptionsT() + { + } +}; + +struct HashtableSizeOptions FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef HashtableSizeOptionsT NativeTableType; + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + verifier.EndTable(); + } + HashtableSizeOptionsT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(HashtableSizeOptionsT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const HashtableSizeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct HashtableSizeOptionsBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + explicit HashtableSizeOptionsBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + HashtableSizeOptionsBuilder &operator=(const HashtableSizeOptionsBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateHashtableSizeOptions( + flatbuffers::FlatBufferBuilder &_fbb) +{ + HashtableSizeOptionsBuilder builder_(_fbb); + return builder_.Finish(); +} + +flatbuffers::Offset CreateHashtableSizeOptions(flatbuffers::FlatBufferBuilder &_fbb, const HashtableSizeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct OperatorCodeT : public flatbuffers::NativeTable { + typedef OperatorCode TableType; + int8_t deprecated_builtin_code; + std::string custom_code; + int32_t version; + tflite::BuiltinOperator builtin_code; + OperatorCodeT() + : deprecated_builtin_code(0), + version(1), + builtin_code(tflite::BuiltinOperator_ADD) + { + } +}; + +struct OperatorCode FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef OperatorCodeT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_DEPRECATED_BUILTIN_CODE = 4, + VT_CUSTOM_CODE = 6, + VT_VERSION = 8, + VT_BUILTIN_CODE = 10 + }; + int8_t deprecated_builtin_code() const + { + return GetField(VT_DEPRECATED_BUILTIN_CODE, 0); + } + const flatbuffers::String *custom_code() const + { + return GetPointer(VT_CUSTOM_CODE); + } + int32_t version() const + { + return GetField(VT_VERSION, 1); + } + tflite::BuiltinOperator builtin_code() const + { + return static_cast(GetField(VT_BUILTIN_CODE, 0)); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_DEPRECATED_BUILTIN_CODE) && + VerifyOffset(verifier, VT_CUSTOM_CODE) && + verifier.VerifyString(custom_code()) && + VerifyField(verifier, VT_VERSION) && + VerifyField(verifier, VT_BUILTIN_CODE) && + verifier.EndTable(); + } + OperatorCodeT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(OperatorCodeT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const OperatorCodeT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct OperatorCodeBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_deprecated_builtin_code(int8_t deprecated_builtin_code) + { + fbb_.AddElement(OperatorCode::VT_DEPRECATED_BUILTIN_CODE, deprecated_builtin_code, 0); + } + void add_custom_code(flatbuffers::Offset custom_code) + { + fbb_.AddOffset(OperatorCode::VT_CUSTOM_CODE, custom_code); + } + void add_version(int32_t version) + { + fbb_.AddElement(OperatorCode::VT_VERSION, version, 1); + } + void add_builtin_code(tflite::BuiltinOperator builtin_code) + { + fbb_.AddElement(OperatorCode::VT_BUILTIN_CODE, static_cast(builtin_code), 0); + } + explicit OperatorCodeBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + OperatorCodeBuilder &operator=(const OperatorCodeBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateOperatorCode( + flatbuffers::FlatBufferBuilder &_fbb, + int8_t deprecated_builtin_code = 0, + flatbuffers::Offset custom_code = 0, + int32_t version = 1, + tflite::BuiltinOperator builtin_code = tflite::BuiltinOperator_ADD) +{ + OperatorCodeBuilder builder_(_fbb); + builder_.add_builtin_code(builtin_code); + builder_.add_version(version); + builder_.add_custom_code(custom_code); + builder_.add_deprecated_builtin_code(deprecated_builtin_code); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateOperatorCodeDirect( + flatbuffers::FlatBufferBuilder &_fbb, + int8_t deprecated_builtin_code = 0, + const char *custom_code = nullptr, + int32_t version = 1, + tflite::BuiltinOperator builtin_code = tflite::BuiltinOperator_ADD) +{ + auto custom_code__ = custom_code ? _fbb.CreateString(custom_code) : 0; + return tflite::CreateOperatorCode( + _fbb, + deprecated_builtin_code, + custom_code__, + version, + builtin_code); +} + +flatbuffers::Offset CreateOperatorCode(flatbuffers::FlatBufferBuilder &_fbb, const OperatorCodeT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct OperatorT : public flatbuffers::NativeTable { + typedef Operator TableType; + uint32_t opcode_index; + std::vector inputs; + std::vector outputs; + tflite::BuiltinOptionsUnion builtin_options; + std::vector custom_options; + tflite::CustomOptionsFormat custom_options_format; + std::vector mutating_variable_inputs; + std::vector intermediates; + OperatorT() + : opcode_index(0), + custom_options_format(tflite::CustomOptionsFormat_FLEXBUFFERS) + { + } +}; + +struct Operator FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef OperatorT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_OPCODE_INDEX = 4, + VT_INPUTS = 6, + VT_OUTPUTS = 8, + VT_BUILTIN_OPTIONS_TYPE = 10, + VT_BUILTIN_OPTIONS = 12, + VT_CUSTOM_OPTIONS = 14, + VT_CUSTOM_OPTIONS_FORMAT = 16, + VT_MUTATING_VARIABLE_INPUTS = 18, + VT_INTERMEDIATES = 20 + }; + uint32_t opcode_index() const + { + return GetField(VT_OPCODE_INDEX, 0); + } + const flatbuffers::Vector *inputs() const + { + return GetPointer *>(VT_INPUTS); + } + const flatbuffers::Vector *outputs() const + { + return GetPointer *>(VT_OUTPUTS); + } + tflite::BuiltinOptions builtin_options_type() const + { + return static_cast(GetField(VT_BUILTIN_OPTIONS_TYPE, 0)); + } + const void *builtin_options() const + { + return GetPointer(VT_BUILTIN_OPTIONS); + } + template + const T *builtin_options_as() const; + const tflite::Conv2DOptions *builtin_options_as_Conv2DOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_Conv2DOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::DepthwiseConv2DOptions *builtin_options_as_DepthwiseConv2DOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_DepthwiseConv2DOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::ConcatEmbeddingsOptions *builtin_options_as_ConcatEmbeddingsOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_ConcatEmbeddingsOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::LSHProjectionOptions *builtin_options_as_LSHProjectionOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_LSHProjectionOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::Pool2DOptions *builtin_options_as_Pool2DOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_Pool2DOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::SVDFOptions *builtin_options_as_SVDFOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_SVDFOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::RNNOptions *builtin_options_as_RNNOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_RNNOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::FullyConnectedOptions *builtin_options_as_FullyConnectedOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_FullyConnectedOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::SoftmaxOptions *builtin_options_as_SoftmaxOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_SoftmaxOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::ConcatenationOptions *builtin_options_as_ConcatenationOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_ConcatenationOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::AddOptions *builtin_options_as_AddOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_AddOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::L2NormOptions *builtin_options_as_L2NormOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_L2NormOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::LocalResponseNormalizationOptions *builtin_options_as_LocalResponseNormalizationOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_LocalResponseNormalizationOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::LSTMOptions *builtin_options_as_LSTMOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_LSTMOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::ResizeBilinearOptions *builtin_options_as_ResizeBilinearOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_ResizeBilinearOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::CallOptions *builtin_options_as_CallOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_CallOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::ReshapeOptions *builtin_options_as_ReshapeOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_ReshapeOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::SkipGramOptions *builtin_options_as_SkipGramOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_SkipGramOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::SpaceToDepthOptions *builtin_options_as_SpaceToDepthOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_SpaceToDepthOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::EmbeddingLookupSparseOptions *builtin_options_as_EmbeddingLookupSparseOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_EmbeddingLookupSparseOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::MulOptions *builtin_options_as_MulOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_MulOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::PadOptions *builtin_options_as_PadOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_PadOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::GatherOptions *builtin_options_as_GatherOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_GatherOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::BatchToSpaceNDOptions *builtin_options_as_BatchToSpaceNDOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_BatchToSpaceNDOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::SpaceToBatchNDOptions *builtin_options_as_SpaceToBatchNDOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_SpaceToBatchNDOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::TransposeOptions *builtin_options_as_TransposeOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_TransposeOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::ReducerOptions *builtin_options_as_ReducerOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_ReducerOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::SubOptions *builtin_options_as_SubOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_SubOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::DivOptions *builtin_options_as_DivOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_DivOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::SqueezeOptions *builtin_options_as_SqueezeOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_SqueezeOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::SequenceRNNOptions *builtin_options_as_SequenceRNNOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_SequenceRNNOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::StridedSliceOptions *builtin_options_as_StridedSliceOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_StridedSliceOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::ExpOptions *builtin_options_as_ExpOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_ExpOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::TopKV2Options *builtin_options_as_TopKV2Options() const + { + return builtin_options_type() == tflite::BuiltinOptions_TopKV2Options ? static_cast(builtin_options()) : nullptr; + } + const tflite::SplitOptions *builtin_options_as_SplitOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_SplitOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::LogSoftmaxOptions *builtin_options_as_LogSoftmaxOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_LogSoftmaxOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::CastOptions *builtin_options_as_CastOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_CastOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::DequantizeOptions *builtin_options_as_DequantizeOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_DequantizeOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::MaximumMinimumOptions *builtin_options_as_MaximumMinimumOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_MaximumMinimumOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::ArgMaxOptions *builtin_options_as_ArgMaxOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_ArgMaxOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::LessOptions *builtin_options_as_LessOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_LessOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::NegOptions *builtin_options_as_NegOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_NegOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::PadV2Options *builtin_options_as_PadV2Options() const + { + return builtin_options_type() == tflite::BuiltinOptions_PadV2Options ? static_cast(builtin_options()) : nullptr; + } + const tflite::GreaterOptions *builtin_options_as_GreaterOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_GreaterOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::GreaterEqualOptions *builtin_options_as_GreaterEqualOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_GreaterEqualOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::LessEqualOptions *builtin_options_as_LessEqualOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_LessEqualOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::SelectOptions *builtin_options_as_SelectOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_SelectOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::SliceOptions *builtin_options_as_SliceOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_SliceOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::TransposeConvOptions *builtin_options_as_TransposeConvOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_TransposeConvOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::SparseToDenseOptions *builtin_options_as_SparseToDenseOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_SparseToDenseOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::TileOptions *builtin_options_as_TileOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_TileOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::ExpandDimsOptions *builtin_options_as_ExpandDimsOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_ExpandDimsOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::EqualOptions *builtin_options_as_EqualOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_EqualOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::NotEqualOptions *builtin_options_as_NotEqualOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_NotEqualOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::ShapeOptions *builtin_options_as_ShapeOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_ShapeOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::PowOptions *builtin_options_as_PowOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_PowOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::ArgMinOptions *builtin_options_as_ArgMinOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_ArgMinOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::FakeQuantOptions *builtin_options_as_FakeQuantOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_FakeQuantOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::PackOptions *builtin_options_as_PackOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_PackOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::LogicalOrOptions *builtin_options_as_LogicalOrOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_LogicalOrOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::OneHotOptions *builtin_options_as_OneHotOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_OneHotOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::LogicalAndOptions *builtin_options_as_LogicalAndOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_LogicalAndOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::LogicalNotOptions *builtin_options_as_LogicalNotOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_LogicalNotOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::UnpackOptions *builtin_options_as_UnpackOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_UnpackOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::FloorDivOptions *builtin_options_as_FloorDivOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_FloorDivOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::SquareOptions *builtin_options_as_SquareOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_SquareOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::ZerosLikeOptions *builtin_options_as_ZerosLikeOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_ZerosLikeOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::FillOptions *builtin_options_as_FillOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_FillOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::BidirectionalSequenceLSTMOptions *builtin_options_as_BidirectionalSequenceLSTMOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_BidirectionalSequenceLSTMOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::BidirectionalSequenceRNNOptions *builtin_options_as_BidirectionalSequenceRNNOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_BidirectionalSequenceRNNOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::UnidirectionalSequenceLSTMOptions *builtin_options_as_UnidirectionalSequenceLSTMOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_UnidirectionalSequenceLSTMOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::FloorModOptions *builtin_options_as_FloorModOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_FloorModOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::RangeOptions *builtin_options_as_RangeOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_RangeOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::ResizeNearestNeighborOptions *builtin_options_as_ResizeNearestNeighborOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_ResizeNearestNeighborOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::LeakyReluOptions *builtin_options_as_LeakyReluOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_LeakyReluOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::SquaredDifferenceOptions *builtin_options_as_SquaredDifferenceOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_SquaredDifferenceOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::MirrorPadOptions *builtin_options_as_MirrorPadOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_MirrorPadOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::AbsOptions *builtin_options_as_AbsOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_AbsOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::SplitVOptions *builtin_options_as_SplitVOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_SplitVOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::UniqueOptions *builtin_options_as_UniqueOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_UniqueOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::ReverseV2Options *builtin_options_as_ReverseV2Options() const + { + return builtin_options_type() == tflite::BuiltinOptions_ReverseV2Options ? static_cast(builtin_options()) : nullptr; + } + const tflite::AddNOptions *builtin_options_as_AddNOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_AddNOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::GatherNdOptions *builtin_options_as_GatherNdOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_GatherNdOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::CosOptions *builtin_options_as_CosOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_CosOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::WhereOptions *builtin_options_as_WhereOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_WhereOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::RankOptions *builtin_options_as_RankOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_RankOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::ReverseSequenceOptions *builtin_options_as_ReverseSequenceOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_ReverseSequenceOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::MatrixDiagOptions *builtin_options_as_MatrixDiagOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_MatrixDiagOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::QuantizeOptions *builtin_options_as_QuantizeOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_QuantizeOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::MatrixSetDiagOptions *builtin_options_as_MatrixSetDiagOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_MatrixSetDiagOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::HardSwishOptions *builtin_options_as_HardSwishOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_HardSwishOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::IfOptions *builtin_options_as_IfOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_IfOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::WhileOptions *builtin_options_as_WhileOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_WhileOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::DepthToSpaceOptions *builtin_options_as_DepthToSpaceOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_DepthToSpaceOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::NonMaxSuppressionV4Options *builtin_options_as_NonMaxSuppressionV4Options() const + { + return builtin_options_type() == tflite::BuiltinOptions_NonMaxSuppressionV4Options ? static_cast(builtin_options()) : nullptr; + } + const tflite::NonMaxSuppressionV5Options *builtin_options_as_NonMaxSuppressionV5Options() const + { + return builtin_options_type() == tflite::BuiltinOptions_NonMaxSuppressionV5Options ? static_cast(builtin_options()) : nullptr; + } + const tflite::ScatterNdOptions *builtin_options_as_ScatterNdOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_ScatterNdOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::SelectV2Options *builtin_options_as_SelectV2Options() const + { + return builtin_options_type() == tflite::BuiltinOptions_SelectV2Options ? static_cast(builtin_options()) : nullptr; + } + const tflite::DensifyOptions *builtin_options_as_DensifyOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_DensifyOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::SegmentSumOptions *builtin_options_as_SegmentSumOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_SegmentSumOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::BatchMatMulOptions *builtin_options_as_BatchMatMulOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_BatchMatMulOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::CumsumOptions *builtin_options_as_CumsumOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_CumsumOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::CallOnceOptions *builtin_options_as_CallOnceOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_CallOnceOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::BroadcastToOptions *builtin_options_as_BroadcastToOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_BroadcastToOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::Rfft2dOptions *builtin_options_as_Rfft2dOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_Rfft2dOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::Conv3DOptions *builtin_options_as_Conv3DOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_Conv3DOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::HashtableOptions *builtin_options_as_HashtableOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_HashtableOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::HashtableFindOptions *builtin_options_as_HashtableFindOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_HashtableFindOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::HashtableImportOptions *builtin_options_as_HashtableImportOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_HashtableImportOptions ? static_cast(builtin_options()) : nullptr; + } + const tflite::HashtableSizeOptions *builtin_options_as_HashtableSizeOptions() const + { + return builtin_options_type() == tflite::BuiltinOptions_HashtableSizeOptions ? static_cast(builtin_options()) : nullptr; + } + const flatbuffers::Vector *custom_options() const + { + return GetPointer *>(VT_CUSTOM_OPTIONS); + } + tflite::CustomOptionsFormat custom_options_format() const + { + return static_cast(GetField(VT_CUSTOM_OPTIONS_FORMAT, 0)); + } + const flatbuffers::Vector *mutating_variable_inputs() const + { + return GetPointer *>(VT_MUTATING_VARIABLE_INPUTS); + } + const flatbuffers::Vector *intermediates() const + { + return GetPointer *>(VT_INTERMEDIATES); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_OPCODE_INDEX) && + VerifyOffset(verifier, VT_INPUTS) && + verifier.VerifyVector(inputs()) && + VerifyOffset(verifier, VT_OUTPUTS) && + verifier.VerifyVector(outputs()) && + VerifyField(verifier, VT_BUILTIN_OPTIONS_TYPE) && + VerifyOffset(verifier, VT_BUILTIN_OPTIONS) && + VerifyBuiltinOptions(verifier, builtin_options(), builtin_options_type()) && + VerifyOffset(verifier, VT_CUSTOM_OPTIONS) && + verifier.VerifyVector(custom_options()) && + VerifyField(verifier, VT_CUSTOM_OPTIONS_FORMAT) && + VerifyOffset(verifier, VT_MUTATING_VARIABLE_INPUTS) && + verifier.VerifyVector(mutating_variable_inputs()) && + VerifyOffset(verifier, VT_INTERMEDIATES) && + verifier.VerifyVector(intermediates()) && + verifier.EndTable(); + } + OperatorT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(OperatorT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const OperatorT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +template <> +inline const tflite::Conv2DOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_Conv2DOptions(); +} + +template <> +inline const tflite::DepthwiseConv2DOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_DepthwiseConv2DOptions(); +} + +template <> +inline const tflite::ConcatEmbeddingsOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_ConcatEmbeddingsOptions(); +} + +template <> +inline const tflite::LSHProjectionOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_LSHProjectionOptions(); +} + +template <> +inline const tflite::Pool2DOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_Pool2DOptions(); +} + +template <> +inline const tflite::SVDFOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_SVDFOptions(); +} + +template <> +inline const tflite::RNNOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_RNNOptions(); +} + +template <> +inline const tflite::FullyConnectedOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_FullyConnectedOptions(); +} + +template <> +inline const tflite::SoftmaxOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_SoftmaxOptions(); +} + +template <> +inline const tflite::ConcatenationOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_ConcatenationOptions(); +} + +template <> +inline const tflite::AddOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_AddOptions(); +} + +template <> +inline const tflite::L2NormOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_L2NormOptions(); +} + +template <> +inline const tflite::LocalResponseNormalizationOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_LocalResponseNormalizationOptions(); +} + +template <> +inline const tflite::LSTMOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_LSTMOptions(); +} + +template <> +inline const tflite::ResizeBilinearOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_ResizeBilinearOptions(); +} + +template <> +inline const tflite::CallOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_CallOptions(); +} + +template <> +inline const tflite::ReshapeOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_ReshapeOptions(); +} + +template <> +inline const tflite::SkipGramOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_SkipGramOptions(); +} + +template <> +inline const tflite::SpaceToDepthOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_SpaceToDepthOptions(); +} + +template <> +inline const tflite::EmbeddingLookupSparseOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_EmbeddingLookupSparseOptions(); +} + +template <> +inline const tflite::MulOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_MulOptions(); +} + +template <> +inline const tflite::PadOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_PadOptions(); +} + +template <> +inline const tflite::GatherOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_GatherOptions(); +} + +template <> +inline const tflite::BatchToSpaceNDOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_BatchToSpaceNDOptions(); +} + +template <> +inline const tflite::SpaceToBatchNDOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_SpaceToBatchNDOptions(); +} + +template <> +inline const tflite::TransposeOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_TransposeOptions(); +} + +template <> +inline const tflite::ReducerOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_ReducerOptions(); +} + +template <> +inline const tflite::SubOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_SubOptions(); +} + +template <> +inline const tflite::DivOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_DivOptions(); +} + +template <> +inline const tflite::SqueezeOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_SqueezeOptions(); +} + +template <> +inline const tflite::SequenceRNNOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_SequenceRNNOptions(); +} + +template <> +inline const tflite::StridedSliceOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_StridedSliceOptions(); +} + +template <> +inline const tflite::ExpOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_ExpOptions(); +} + +template <> +inline const tflite::TopKV2Options *Operator::builtin_options_as() const +{ + return builtin_options_as_TopKV2Options(); +} + +template <> +inline const tflite::SplitOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_SplitOptions(); +} + +template <> +inline const tflite::LogSoftmaxOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_LogSoftmaxOptions(); +} + +template <> +inline const tflite::CastOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_CastOptions(); +} + +template <> +inline const tflite::DequantizeOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_DequantizeOptions(); +} + +template <> +inline const tflite::MaximumMinimumOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_MaximumMinimumOptions(); +} + +template <> +inline const tflite::ArgMaxOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_ArgMaxOptions(); +} + +template <> +inline const tflite::LessOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_LessOptions(); +} + +template <> +inline const tflite::NegOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_NegOptions(); +} + +template <> +inline const tflite::PadV2Options *Operator::builtin_options_as() const +{ + return builtin_options_as_PadV2Options(); +} + +template <> +inline const tflite::GreaterOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_GreaterOptions(); +} + +template <> +inline const tflite::GreaterEqualOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_GreaterEqualOptions(); +} + +template <> +inline const tflite::LessEqualOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_LessEqualOptions(); +} + +template <> +inline const tflite::SelectOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_SelectOptions(); +} + +template <> +inline const tflite::SliceOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_SliceOptions(); +} + +template <> +inline const tflite::TransposeConvOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_TransposeConvOptions(); +} + +template <> +inline const tflite::SparseToDenseOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_SparseToDenseOptions(); +} + +template <> +inline const tflite::TileOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_TileOptions(); +} + +template <> +inline const tflite::ExpandDimsOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_ExpandDimsOptions(); +} + +template <> +inline const tflite::EqualOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_EqualOptions(); +} + +template <> +inline const tflite::NotEqualOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_NotEqualOptions(); +} + +template <> +inline const tflite::ShapeOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_ShapeOptions(); +} + +template <> +inline const tflite::PowOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_PowOptions(); +} + +template <> +inline const tflite::ArgMinOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_ArgMinOptions(); +} + +template <> +inline const tflite::FakeQuantOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_FakeQuantOptions(); +} + +template <> +inline const tflite::PackOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_PackOptions(); +} + +template <> +inline const tflite::LogicalOrOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_LogicalOrOptions(); +} + +template <> +inline const tflite::OneHotOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_OneHotOptions(); +} + +template <> +inline const tflite::LogicalAndOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_LogicalAndOptions(); +} + +template <> +inline const tflite::LogicalNotOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_LogicalNotOptions(); +} + +template <> +inline const tflite::UnpackOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_UnpackOptions(); +} + +template <> +inline const tflite::FloorDivOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_FloorDivOptions(); +} + +template <> +inline const tflite::SquareOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_SquareOptions(); +} + +template <> +inline const tflite::ZerosLikeOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_ZerosLikeOptions(); +} + +template <> +inline const tflite::FillOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_FillOptions(); +} + +template <> +inline const tflite::BidirectionalSequenceLSTMOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_BidirectionalSequenceLSTMOptions(); +} + +template <> +inline const tflite::BidirectionalSequenceRNNOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_BidirectionalSequenceRNNOptions(); +} + +template <> +inline const tflite::UnidirectionalSequenceLSTMOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_UnidirectionalSequenceLSTMOptions(); +} + +template <> +inline const tflite::FloorModOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_FloorModOptions(); +} + +template <> +inline const tflite::RangeOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_RangeOptions(); +} + +template <> +inline const tflite::ResizeNearestNeighborOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_ResizeNearestNeighborOptions(); +} + +template <> +inline const tflite::LeakyReluOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_LeakyReluOptions(); +} + +template <> +inline const tflite::SquaredDifferenceOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_SquaredDifferenceOptions(); +} + +template <> +inline const tflite::MirrorPadOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_MirrorPadOptions(); +} + +template <> +inline const tflite::AbsOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_AbsOptions(); +} + +template <> +inline const tflite::SplitVOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_SplitVOptions(); +} + +template <> +inline const tflite::UniqueOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_UniqueOptions(); +} + +template <> +inline const tflite::ReverseV2Options *Operator::builtin_options_as() const +{ + return builtin_options_as_ReverseV2Options(); +} + +template <> +inline const tflite::AddNOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_AddNOptions(); +} + +template <> +inline const tflite::GatherNdOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_GatherNdOptions(); +} + +template <> +inline const tflite::CosOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_CosOptions(); +} + +template <> +inline const tflite::WhereOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_WhereOptions(); +} + +template <> +inline const tflite::RankOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_RankOptions(); +} + +template <> +inline const tflite::ReverseSequenceOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_ReverseSequenceOptions(); +} + +template <> +inline const tflite::MatrixDiagOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_MatrixDiagOptions(); +} + +template <> +inline const tflite::QuantizeOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_QuantizeOptions(); +} + +template <> +inline const tflite::MatrixSetDiagOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_MatrixSetDiagOptions(); +} + +template <> +inline const tflite::HardSwishOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_HardSwishOptions(); +} + +template <> +inline const tflite::IfOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_IfOptions(); +} + +template <> +inline const tflite::WhileOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_WhileOptions(); +} + +template <> +inline const tflite::DepthToSpaceOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_DepthToSpaceOptions(); +} + +template <> +inline const tflite::NonMaxSuppressionV4Options *Operator::builtin_options_as() const +{ + return builtin_options_as_NonMaxSuppressionV4Options(); +} + +template <> +inline const tflite::NonMaxSuppressionV5Options *Operator::builtin_options_as() const +{ + return builtin_options_as_NonMaxSuppressionV5Options(); +} + +template <> +inline const tflite::ScatterNdOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_ScatterNdOptions(); +} + +template <> +inline const tflite::SelectV2Options *Operator::builtin_options_as() const +{ + return builtin_options_as_SelectV2Options(); +} + +template <> +inline const tflite::DensifyOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_DensifyOptions(); +} + +template <> +inline const tflite::SegmentSumOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_SegmentSumOptions(); +} + +template <> +inline const tflite::BatchMatMulOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_BatchMatMulOptions(); +} + +template <> +inline const tflite::CumsumOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_CumsumOptions(); +} + +template <> +inline const tflite::CallOnceOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_CallOnceOptions(); +} + +template <> +inline const tflite::BroadcastToOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_BroadcastToOptions(); +} + +template <> +inline const tflite::Rfft2dOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_Rfft2dOptions(); +} + +template <> +inline const tflite::Conv3DOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_Conv3DOptions(); +} + +template <> +inline const tflite::HashtableOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_HashtableOptions(); +} + +template <> +inline const tflite::HashtableFindOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_HashtableFindOptions(); +} + +template <> +inline const tflite::HashtableImportOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_HashtableImportOptions(); +} + +template <> +inline const tflite::HashtableSizeOptions *Operator::builtin_options_as() const +{ + return builtin_options_as_HashtableSizeOptions(); +} + +struct OperatorBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_opcode_index(uint32_t opcode_index) + { + fbb_.AddElement(Operator::VT_OPCODE_INDEX, opcode_index, 0); + } + void add_inputs(flatbuffers::Offset > inputs) + { + fbb_.AddOffset(Operator::VT_INPUTS, inputs); + } + void add_outputs(flatbuffers::Offset > outputs) + { + fbb_.AddOffset(Operator::VT_OUTPUTS, outputs); + } + void add_builtin_options_type(tflite::BuiltinOptions builtin_options_type) + { + fbb_.AddElement(Operator::VT_BUILTIN_OPTIONS_TYPE, static_cast(builtin_options_type), 0); + } + void add_builtin_options(flatbuffers::Offset builtin_options) + { + fbb_.AddOffset(Operator::VT_BUILTIN_OPTIONS, builtin_options); + } + void add_custom_options(flatbuffers::Offset > custom_options) + { + fbb_.AddOffset(Operator::VT_CUSTOM_OPTIONS, custom_options); + } + void add_custom_options_format(tflite::CustomOptionsFormat custom_options_format) + { + fbb_.AddElement(Operator::VT_CUSTOM_OPTIONS_FORMAT, static_cast(custom_options_format), 0); + } + void add_mutating_variable_inputs(flatbuffers::Offset > mutating_variable_inputs) + { + fbb_.AddOffset(Operator::VT_MUTATING_VARIABLE_INPUTS, mutating_variable_inputs); + } + void add_intermediates(flatbuffers::Offset > intermediates) + { + fbb_.AddOffset(Operator::VT_INTERMEDIATES, intermediates); + } + explicit OperatorBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + OperatorBuilder &operator=(const OperatorBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateOperator( + flatbuffers::FlatBufferBuilder &_fbb, + uint32_t opcode_index = 0, + flatbuffers::Offset > inputs = 0, + flatbuffers::Offset > outputs = 0, + tflite::BuiltinOptions builtin_options_type = tflite::BuiltinOptions_NONE, + flatbuffers::Offset builtin_options = 0, + flatbuffers::Offset > custom_options = 0, + tflite::CustomOptionsFormat custom_options_format = tflite::CustomOptionsFormat_FLEXBUFFERS, + flatbuffers::Offset > mutating_variable_inputs = 0, + flatbuffers::Offset > intermediates = 0) +{ + OperatorBuilder builder_(_fbb); + builder_.add_intermediates(intermediates); + builder_.add_mutating_variable_inputs(mutating_variable_inputs); + builder_.add_custom_options(custom_options); + builder_.add_builtin_options(builtin_options); + builder_.add_outputs(outputs); + builder_.add_inputs(inputs); + builder_.add_opcode_index(opcode_index); + builder_.add_custom_options_format(custom_options_format); + builder_.add_builtin_options_type(builtin_options_type); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateOperatorDirect( + flatbuffers::FlatBufferBuilder &_fbb, + uint32_t opcode_index = 0, + const std::vector *inputs = nullptr, + const std::vector *outputs = nullptr, + tflite::BuiltinOptions builtin_options_type = tflite::BuiltinOptions_NONE, + flatbuffers::Offset builtin_options = 0, + const std::vector *custom_options = nullptr, + tflite::CustomOptionsFormat custom_options_format = tflite::CustomOptionsFormat_FLEXBUFFERS, + const std::vector *mutating_variable_inputs = nullptr, + const std::vector *intermediates = nullptr) +{ + auto inputs__ = inputs ? _fbb.CreateVector(*inputs) : 0; + auto outputs__ = outputs ? _fbb.CreateVector(*outputs) : 0; + auto custom_options__ = custom_options ? _fbb.CreateVector(*custom_options) : 0; + auto mutating_variable_inputs__ = mutating_variable_inputs ? _fbb.CreateVector(*mutating_variable_inputs) : 0; + auto intermediates__ = intermediates ? _fbb.CreateVector(*intermediates) : 0; + return tflite::CreateOperator( + _fbb, + opcode_index, + inputs__, + outputs__, + builtin_options_type, + builtin_options, + custom_options__, + custom_options_format, + mutating_variable_inputs__, + intermediates__); +} + +flatbuffers::Offset CreateOperator(flatbuffers::FlatBufferBuilder &_fbb, const OperatorT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct SubGraphT : public flatbuffers::NativeTable { + typedef SubGraph TableType; + std::vector > tensors; + std::vector inputs; + std::vector outputs; + std::vector > operators; + std::string name; + SubGraphT() + { + } +}; + +struct SubGraph FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef SubGraphT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_TENSORS = 4, + VT_INPUTS = 6, + VT_OUTPUTS = 8, + VT_OPERATORS = 10, + VT_NAME = 12 + }; + const flatbuffers::Vector > *tensors() const + { + return GetPointer > *>(VT_TENSORS); + } + const flatbuffers::Vector *inputs() const + { + return GetPointer *>(VT_INPUTS); + } + const flatbuffers::Vector *outputs() const + { + return GetPointer *>(VT_OUTPUTS); + } + const flatbuffers::Vector > *operators() const + { + return GetPointer > *>(VT_OPERATORS); + } + const flatbuffers::String *name() const + { + return GetPointer(VT_NAME); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_TENSORS) && + verifier.VerifyVector(tensors()) && + verifier.VerifyVectorOfTables(tensors()) && + VerifyOffset(verifier, VT_INPUTS) && + verifier.VerifyVector(inputs()) && + VerifyOffset(verifier, VT_OUTPUTS) && + verifier.VerifyVector(outputs()) && + VerifyOffset(verifier, VT_OPERATORS) && + verifier.VerifyVector(operators()) && + verifier.VerifyVectorOfTables(operators()) && + VerifyOffset(verifier, VT_NAME) && + verifier.VerifyString(name()) && + verifier.EndTable(); + } + SubGraphT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(SubGraphT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const SubGraphT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct SubGraphBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_tensors(flatbuffers::Offset > > tensors) + { + fbb_.AddOffset(SubGraph::VT_TENSORS, tensors); + } + void add_inputs(flatbuffers::Offset > inputs) + { + fbb_.AddOffset(SubGraph::VT_INPUTS, inputs); + } + void add_outputs(flatbuffers::Offset > outputs) + { + fbb_.AddOffset(SubGraph::VT_OUTPUTS, outputs); + } + void add_operators(flatbuffers::Offset > > operators) + { + fbb_.AddOffset(SubGraph::VT_OPERATORS, operators); + } + void add_name(flatbuffers::Offset name) + { + fbb_.AddOffset(SubGraph::VT_NAME, name); + } + explicit SubGraphBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SubGraphBuilder &operator=(const SubGraphBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateSubGraph( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset > > tensors = 0, + flatbuffers::Offset > inputs = 0, + flatbuffers::Offset > outputs = 0, + flatbuffers::Offset > > operators = 0, + flatbuffers::Offset name = 0) +{ + SubGraphBuilder builder_(_fbb); + builder_.add_name(name); + builder_.add_operators(operators); + builder_.add_outputs(outputs); + builder_.add_inputs(inputs); + builder_.add_tensors(tensors); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateSubGraphDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const std::vector > *tensors = nullptr, + const std::vector *inputs = nullptr, + const std::vector *outputs = nullptr, + const std::vector > *operators = nullptr, + const char *name = nullptr) +{ + auto tensors__ = tensors ? _fbb.CreateVector >(*tensors) : 0; + auto inputs__ = inputs ? _fbb.CreateVector(*inputs) : 0; + auto outputs__ = outputs ? _fbb.CreateVector(*outputs) : 0; + auto operators__ = operators ? _fbb.CreateVector >(*operators) : 0; + auto name__ = name ? _fbb.CreateString(name) : 0; + return tflite::CreateSubGraph( + _fbb, + tensors__, + inputs__, + outputs__, + operators__, + name__); +} + +flatbuffers::Offset CreateSubGraph(flatbuffers::FlatBufferBuilder &_fbb, const SubGraphT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct BufferT : public flatbuffers::NativeTable { + typedef Buffer TableType; + std::vector data; + BufferT() + { + } +}; + +struct Buffer FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef BufferT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_DATA = 4 + }; + const flatbuffers::Vector *data() const + { + return GetPointer *>(VT_DATA); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_DATA) && + verifier.VerifyVector(data()) && + verifier.EndTable(); + } + BufferT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(BufferT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const BufferT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct BufferBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_data(flatbuffers::Offset > data) + { + fbb_.AddOffset(Buffer::VT_DATA, data); + } + explicit BufferBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + BufferBuilder &operator=(const BufferBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateBuffer( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset > data = 0) +{ + BufferBuilder builder_(_fbb); + builder_.add_data(data); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateBufferDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const std::vector *data = nullptr) +{ + if (data) { + _fbb.ForceVectorAlignment(data->size(), sizeof(uint8_t), 16); + } + auto data__ = data ? _fbb.CreateVector(*data) : 0; + return tflite::CreateBuffer( + _fbb, + data__); +} + +flatbuffers::Offset CreateBuffer(flatbuffers::FlatBufferBuilder &_fbb, const BufferT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct MetadataT : public flatbuffers::NativeTable { + typedef Metadata TableType; + std::string name; + uint32_t buffer; + MetadataT() + : buffer(0) + { + } +}; + +struct Metadata FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef MetadataT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_NAME = 4, + VT_BUFFER = 6 + }; + const flatbuffers::String *name() const + { + return GetPointer(VT_NAME); + } + uint32_t buffer() const + { + return GetField(VT_BUFFER, 0); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_NAME) && + verifier.VerifyString(name()) && + VerifyField(verifier, VT_BUFFER) && + verifier.EndTable(); + } + MetadataT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(MetadataT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const MetadataT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct MetadataBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_name(flatbuffers::Offset name) + { + fbb_.AddOffset(Metadata::VT_NAME, name); + } + void add_buffer(uint32_t buffer) + { + fbb_.AddElement(Metadata::VT_BUFFER, buffer, 0); + } + explicit MetadataBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + MetadataBuilder &operator=(const MetadataBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateMetadata( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset name = 0, + uint32_t buffer = 0) +{ + MetadataBuilder builder_(_fbb); + builder_.add_buffer(buffer); + builder_.add_name(name); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateMetadataDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const char *name = nullptr, + uint32_t buffer = 0) +{ + auto name__ = name ? _fbb.CreateString(name) : 0; + return tflite::CreateMetadata( + _fbb, + name__, + buffer); +} + +flatbuffers::Offset CreateMetadata(flatbuffers::FlatBufferBuilder &_fbb, const MetadataT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct TensorMapT : public flatbuffers::NativeTable { + typedef TensorMap TableType; + std::string name; + uint32_t tensor_index; + TensorMapT() + : tensor_index(0) + { + } +}; + +struct TensorMap FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef TensorMapT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_NAME = 4, + VT_TENSOR_INDEX = 6 + }; + const flatbuffers::String *name() const + { + return GetPointer(VT_NAME); + } + uint32_t tensor_index() const + { + return GetField(VT_TENSOR_INDEX, 0); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_NAME) && + verifier.VerifyString(name()) && + VerifyField(verifier, VT_TENSOR_INDEX) && + verifier.EndTable(); + } + TensorMapT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(TensorMapT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const TensorMapT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct TensorMapBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_name(flatbuffers::Offset name) + { + fbb_.AddOffset(TensorMap::VT_NAME, name); + } + void add_tensor_index(uint32_t tensor_index) + { + fbb_.AddElement(TensorMap::VT_TENSOR_INDEX, tensor_index, 0); + } + explicit TensorMapBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + TensorMapBuilder &operator=(const TensorMapBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateTensorMap( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset name = 0, + uint32_t tensor_index = 0) +{ + TensorMapBuilder builder_(_fbb); + builder_.add_tensor_index(tensor_index); + builder_.add_name(name); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateTensorMapDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const char *name = nullptr, + uint32_t tensor_index = 0) +{ + auto name__ = name ? _fbb.CreateString(name) : 0; + return tflite::CreateTensorMap( + _fbb, + name__, + tensor_index); +} + +flatbuffers::Offset CreateTensorMap(flatbuffers::FlatBufferBuilder &_fbb, const TensorMapT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct SignatureDefT : public flatbuffers::NativeTable { + typedef SignatureDef TableType; + std::vector > inputs; + std::vector > outputs; + std::string method_name; + std::string key; + SignatureDefT() + { + } +}; + +struct SignatureDef FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef SignatureDefT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_INPUTS = 4, + VT_OUTPUTS = 6, + VT_METHOD_NAME = 8, + VT_KEY = 10 + }; + const flatbuffers::Vector > *inputs() const + { + return GetPointer > *>(VT_INPUTS); + } + const flatbuffers::Vector > *outputs() const + { + return GetPointer > *>(VT_OUTPUTS); + } + const flatbuffers::String *method_name() const + { + return GetPointer(VT_METHOD_NAME); + } + const flatbuffers::String *key() const + { + return GetPointer(VT_KEY); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyOffset(verifier, VT_INPUTS) && + verifier.VerifyVector(inputs()) && + verifier.VerifyVectorOfTables(inputs()) && + VerifyOffset(verifier, VT_OUTPUTS) && + verifier.VerifyVector(outputs()) && + verifier.VerifyVectorOfTables(outputs()) && + VerifyOffset(verifier, VT_METHOD_NAME) && + verifier.VerifyString(method_name()) && + VerifyOffset(verifier, VT_KEY) && + verifier.VerifyString(key()) && + verifier.EndTable(); + } + SignatureDefT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(SignatureDefT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const SignatureDefT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct SignatureDefBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_inputs(flatbuffers::Offset > > inputs) + { + fbb_.AddOffset(SignatureDef::VT_INPUTS, inputs); + } + void add_outputs(flatbuffers::Offset > > outputs) + { + fbb_.AddOffset(SignatureDef::VT_OUTPUTS, outputs); + } + void add_method_name(flatbuffers::Offset method_name) + { + fbb_.AddOffset(SignatureDef::VT_METHOD_NAME, method_name); + } + void add_key(flatbuffers::Offset key) + { + fbb_.AddOffset(SignatureDef::VT_KEY, key); + } + explicit SignatureDefBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + SignatureDefBuilder &operator=(const SignatureDefBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateSignatureDef( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset > > inputs = 0, + flatbuffers::Offset > > outputs = 0, + flatbuffers::Offset method_name = 0, + flatbuffers::Offset key = 0) +{ + SignatureDefBuilder builder_(_fbb); + builder_.add_key(key); + builder_.add_method_name(method_name); + builder_.add_outputs(outputs); + builder_.add_inputs(inputs); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateSignatureDefDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const std::vector > *inputs = nullptr, + const std::vector > *outputs = nullptr, + const char *method_name = nullptr, + const char *key = nullptr) +{ + auto inputs__ = inputs ? _fbb.CreateVector >(*inputs) : 0; + auto outputs__ = outputs ? _fbb.CreateVector >(*outputs) : 0; + auto method_name__ = method_name ? _fbb.CreateString(method_name) : 0; + auto key__ = key ? _fbb.CreateString(key) : 0; + return tflite::CreateSignatureDef( + _fbb, + inputs__, + outputs__, + method_name__, + key__); +} + +flatbuffers::Offset CreateSignatureDef(flatbuffers::FlatBufferBuilder &_fbb, const SignatureDefT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +struct ModelT : public flatbuffers::NativeTable { + typedef Model TableType; + uint32_t version; + std::vector > operator_codes; + std::vector > subgraphs; + std::string description; + std::vector > buffers; + std::vector metadata_buffer; + std::vector > metadata; + std::vector > signature_defs; + ModelT() + : version(0) + { + } +}; + +struct Model FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef ModelT NativeTableType; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_VERSION = 4, + VT_OPERATOR_CODES = 6, + VT_SUBGRAPHS = 8, + VT_DESCRIPTION = 10, + VT_BUFFERS = 12, + VT_METADATA_BUFFER = 14, + VT_METADATA = 16, + VT_SIGNATURE_DEFS = 18 + }; + uint32_t version() const + { + return GetField(VT_VERSION, 0); + } + const flatbuffers::Vector > *operator_codes() const + { + return GetPointer > *>(VT_OPERATOR_CODES); + } + const flatbuffers::Vector > *subgraphs() const + { + return GetPointer > *>(VT_SUBGRAPHS); + } + const flatbuffers::String *description() const + { + return GetPointer(VT_DESCRIPTION); + } + const flatbuffers::Vector > *buffers() const + { + return GetPointer > *>(VT_BUFFERS); + } + const flatbuffers::Vector *metadata_buffer() const + { + return GetPointer *>(VT_METADATA_BUFFER); + } + const flatbuffers::Vector > *metadata() const + { + return GetPointer > *>(VT_METADATA); + } + const flatbuffers::Vector > *signature_defs() const + { + return GetPointer > *>(VT_SIGNATURE_DEFS); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_VERSION) && + VerifyOffset(verifier, VT_OPERATOR_CODES) && + verifier.VerifyVector(operator_codes()) && + verifier.VerifyVectorOfTables(operator_codes()) && + VerifyOffset(verifier, VT_SUBGRAPHS) && + verifier.VerifyVector(subgraphs()) && + verifier.VerifyVectorOfTables(subgraphs()) && + VerifyOffset(verifier, VT_DESCRIPTION) && + verifier.VerifyString(description()) && + VerifyOffset(verifier, VT_BUFFERS) && + verifier.VerifyVector(buffers()) && + verifier.VerifyVectorOfTables(buffers()) && + VerifyOffset(verifier, VT_METADATA_BUFFER) && + verifier.VerifyVector(metadata_buffer()) && + VerifyOffset(verifier, VT_METADATA) && + verifier.VerifyVector(metadata()) && + verifier.VerifyVectorOfTables(metadata()) && + VerifyOffset(verifier, VT_SIGNATURE_DEFS) && + verifier.VerifyVector(signature_defs()) && + verifier.VerifyVectorOfTables(signature_defs()) && + verifier.EndTable(); + } + ModelT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const; + void UnPackTo(ModelT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const; + static flatbuffers::Offset Pack(flatbuffers::FlatBufferBuilder &_fbb, const ModelT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); +}; + +struct ModelBuilder { + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_version(uint32_t version) + { + fbb_.AddElement(Model::VT_VERSION, version, 0); + } + void add_operator_codes(flatbuffers::Offset > > operator_codes) + { + fbb_.AddOffset(Model::VT_OPERATOR_CODES, operator_codes); + } + void add_subgraphs(flatbuffers::Offset > > subgraphs) + { + fbb_.AddOffset(Model::VT_SUBGRAPHS, subgraphs); + } + void add_description(flatbuffers::Offset description) + { + fbb_.AddOffset(Model::VT_DESCRIPTION, description); + } + void add_buffers(flatbuffers::Offset > > buffers) + { + fbb_.AddOffset(Model::VT_BUFFERS, buffers); + } + void add_metadata_buffer(flatbuffers::Offset > metadata_buffer) + { + fbb_.AddOffset(Model::VT_METADATA_BUFFER, metadata_buffer); + } + void add_metadata(flatbuffers::Offset > > metadata) + { + fbb_.AddOffset(Model::VT_METADATA, metadata); + } + void add_signature_defs(flatbuffers::Offset > > signature_defs) + { + fbb_.AddOffset(Model::VT_SIGNATURE_DEFS, signature_defs); + } + explicit ModelBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + ModelBuilder &operator=(const ModelBuilder &); + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateModel( + flatbuffers::FlatBufferBuilder &_fbb, + uint32_t version = 0, + flatbuffers::Offset > > operator_codes = 0, + flatbuffers::Offset > > subgraphs = 0, + flatbuffers::Offset description = 0, + flatbuffers::Offset > > buffers = 0, + flatbuffers::Offset > metadata_buffer = 0, + flatbuffers::Offset > > metadata = 0, + flatbuffers::Offset > > signature_defs = 0) +{ + ModelBuilder builder_(_fbb); + builder_.add_signature_defs(signature_defs); + builder_.add_metadata(metadata); + builder_.add_metadata_buffer(metadata_buffer); + builder_.add_buffers(buffers); + builder_.add_description(description); + builder_.add_subgraphs(subgraphs); + builder_.add_operator_codes(operator_codes); + builder_.add_version(version); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateModelDirect( + flatbuffers::FlatBufferBuilder &_fbb, + uint32_t version = 0, + const std::vector > *operator_codes = nullptr, + const std::vector > *subgraphs = nullptr, + const char *description = nullptr, + const std::vector > *buffers = nullptr, + const std::vector *metadata_buffer = nullptr, + const std::vector > *metadata = nullptr, + const std::vector > *signature_defs = nullptr) +{ + auto operator_codes__ = operator_codes ? _fbb.CreateVector >(*operator_codes) : 0; + auto subgraphs__ = subgraphs ? _fbb.CreateVector >(*subgraphs) : 0; + auto description__ = description ? _fbb.CreateString(description) : 0; + auto buffers__ = buffers ? _fbb.CreateVector >(*buffers) : 0; + auto metadata_buffer__ = metadata_buffer ? _fbb.CreateVector(*metadata_buffer) : 0; + auto metadata__ = metadata ? _fbb.CreateVector >(*metadata) : 0; + auto signature_defs__ = signature_defs ? _fbb.CreateVector >(*signature_defs) : 0; + return tflite::CreateModel( + _fbb, + version, + operator_codes__, + subgraphs__, + description__, + buffers__, + metadata_buffer__, + metadata__, + signature_defs__); +} + +flatbuffers::Offset CreateModel(flatbuffers::FlatBufferBuilder &_fbb, const ModelT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr); + +inline CustomQuantizationT *CustomQuantization::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new CustomQuantizationT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void CustomQuantization::UnPackTo(CustomQuantizationT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = custom(); + if (_e) { + _o->custom.resize(_e->size()); + std::copy(_e->begin(), _e->end(), _o->custom.begin()); + } + } +} + +inline flatbuffers::Offset CustomQuantization::Pack(flatbuffers::FlatBufferBuilder &_fbb, const CustomQuantizationT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateCustomQuantization(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateCustomQuantization(flatbuffers::FlatBufferBuilder &_fbb, const CustomQuantizationT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const CustomQuantizationT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + _fbb.ForceVectorAlignment(_o->custom.size(), sizeof(uint8_t), 16); + auto _custom = _o->custom.size() ? _fbb.CreateVector(_o->custom) : 0; + return tflite::CreateCustomQuantization( + _fbb, + _custom); +} + +inline QuantizationParametersT *QuantizationParameters::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new QuantizationParametersT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void QuantizationParameters::UnPackTo(QuantizationParametersT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = min(); + if (_e) { + _o->min.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->min[_i] = _e->Get(_i); + } + } + } + { + auto _e = max(); + if (_e) { + _o->max.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->max[_i] = _e->Get(_i); + } + } + } + { + auto _e = scale(); + if (_e) { + _o->scale.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->scale[_i] = _e->Get(_i); + } + } + } + { + auto _e = zero_point(); + if (_e) { + _o->zero_point.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->zero_point[_i] = _e->Get(_i); + } + } + } + { + auto _e = details_type(); + _o->details.type = _e; + } + { + auto _e = details(); + if (_e) + _o->details.value = tflite::QuantizationDetailsUnion::UnPack(_e, details_type(), _resolver); + } + { + auto _e = quantized_dimension(); + _o->quantized_dimension = _e; + } +} + +inline flatbuffers::Offset QuantizationParameters::Pack(flatbuffers::FlatBufferBuilder &_fbb, const QuantizationParametersT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateQuantizationParameters(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateQuantizationParameters(flatbuffers::FlatBufferBuilder &_fbb, const QuantizationParametersT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const QuantizationParametersT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _min = _o->min.size() ? _fbb.CreateVector(_o->min) : 0; + auto _max = _o->max.size() ? _fbb.CreateVector(_o->max) : 0; + auto _scale = _o->scale.size() ? _fbb.CreateVector(_o->scale) : 0; + auto _zero_point = _o->zero_point.size() ? _fbb.CreateVector(_o->zero_point) : 0; + auto _details_type = _o->details.type; + auto _details = _o->details.Pack(_fbb); + auto _quantized_dimension = _o->quantized_dimension; + return tflite::CreateQuantizationParameters( + _fbb, + _min, + _max, + _scale, + _zero_point, + _details_type, + _details, + _quantized_dimension); +} + +inline Int32VectorT *Int32Vector::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new Int32VectorT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void Int32Vector::UnPackTo(Int32VectorT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = values(); + if (_e) { + _o->values.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->values[_i] = _e->Get(_i); + } + } + } +} + +inline flatbuffers::Offset Int32Vector::Pack(flatbuffers::FlatBufferBuilder &_fbb, const Int32VectorT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateInt32Vector(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateInt32Vector(flatbuffers::FlatBufferBuilder &_fbb, const Int32VectorT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const Int32VectorT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _values = _o->values.size() ? _fbb.CreateVector(_o->values) : 0; + return tflite::CreateInt32Vector( + _fbb, + _values); +} + +inline Uint16VectorT *Uint16Vector::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new Uint16VectorT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void Uint16Vector::UnPackTo(Uint16VectorT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = values(); + if (_e) { + _o->values.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->values[_i] = _e->Get(_i); + } + } + } +} + +inline flatbuffers::Offset Uint16Vector::Pack(flatbuffers::FlatBufferBuilder &_fbb, const Uint16VectorT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateUint16Vector(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateUint16Vector(flatbuffers::FlatBufferBuilder &_fbb, const Uint16VectorT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const Uint16VectorT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + _fbb.ForceVectorAlignment(_o->values.size(), sizeof(uint16_t), 4); + auto _values = _o->values.size() ? _fbb.CreateVector(_o->values) : 0; + return tflite::CreateUint16Vector( + _fbb, + _values); +} + +inline Uint8VectorT *Uint8Vector::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new Uint8VectorT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void Uint8Vector::UnPackTo(Uint8VectorT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = values(); + if (_e) { + _o->values.resize(_e->size()); + std::copy(_e->begin(), _e->end(), _o->values.begin()); + } + } +} + +inline flatbuffers::Offset Uint8Vector::Pack(flatbuffers::FlatBufferBuilder &_fbb, const Uint8VectorT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateUint8Vector(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateUint8Vector(flatbuffers::FlatBufferBuilder &_fbb, const Uint8VectorT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const Uint8VectorT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + _fbb.ForceVectorAlignment(_o->values.size(), sizeof(uint8_t), 4); + auto _values = _o->values.size() ? _fbb.CreateVector(_o->values) : 0; + return tflite::CreateUint8Vector( + _fbb, + _values); +} + +inline DimensionMetadataT *DimensionMetadata::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new DimensionMetadataT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void DimensionMetadata::UnPackTo(DimensionMetadataT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = format(); + _o->format = _e; + } + { + auto _e = dense_size(); + _o->dense_size = _e; + } + { + auto _e = array_segments_type(); + _o->array_segments.type = _e; + } + { + auto _e = array_segments(); + if (_e) + _o->array_segments.value = tflite::SparseIndexVectorUnion::UnPack(_e, array_segments_type(), _resolver); + } + { + auto _e = array_indices_type(); + _o->array_indices.type = _e; + } + { + auto _e = array_indices(); + if (_e) + _o->array_indices.value = tflite::SparseIndexVectorUnion::UnPack(_e, array_indices_type(), _resolver); + } +} + +inline flatbuffers::Offset DimensionMetadata::Pack(flatbuffers::FlatBufferBuilder &_fbb, const DimensionMetadataT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateDimensionMetadata(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateDimensionMetadata(flatbuffers::FlatBufferBuilder &_fbb, const DimensionMetadataT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const DimensionMetadataT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _format = _o->format; + auto _dense_size = _o->dense_size; + auto _array_segments_type = _o->array_segments.type; + auto _array_segments = _o->array_segments.Pack(_fbb); + auto _array_indices_type = _o->array_indices.type; + auto _array_indices = _o->array_indices.Pack(_fbb); + return tflite::CreateDimensionMetadata( + _fbb, + _format, + _dense_size, + _array_segments_type, + _array_segments, + _array_indices_type, + _array_indices); +} + +inline SparsityParametersT *SparsityParameters::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new SparsityParametersT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void SparsityParameters::UnPackTo(SparsityParametersT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = traversal_order(); + if (_e) { + _o->traversal_order.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->traversal_order[_i] = _e->Get(_i); + } + } + } + { + auto _e = block_map(); + if (_e) { + _o->block_map.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->block_map[_i] = _e->Get(_i); + } + } + } + { + auto _e = dim_metadata(); + if (_e) { + _o->dim_metadata.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->dim_metadata[_i] = std::unique_ptr(_e->Get(_i)->UnPack(_resolver)); + } + } + } +} + +inline flatbuffers::Offset SparsityParameters::Pack(flatbuffers::FlatBufferBuilder &_fbb, const SparsityParametersT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateSparsityParameters(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateSparsityParameters(flatbuffers::FlatBufferBuilder &_fbb, const SparsityParametersT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const SparsityParametersT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _traversal_order = _o->traversal_order.size() ? _fbb.CreateVector(_o->traversal_order) : 0; + auto _block_map = _o->block_map.size() ? _fbb.CreateVector(_o->block_map) : 0; + auto _dim_metadata = _o->dim_metadata.size() ? _fbb.CreateVector >( + _o->dim_metadata.size(), [](size_t i, _VectorArgs *__va) { return CreateDimensionMetadata(*__va->__fbb, __va->__o->dim_metadata[i].get(), __va->__rehasher); }, &_va) : + 0; + return tflite::CreateSparsityParameters( + _fbb, + _traversal_order, + _block_map, + _dim_metadata); +} + +inline TensorT *Tensor::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new TensorT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void Tensor::UnPackTo(TensorT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = shape(); + if (_e) { + _o->shape.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->shape[_i] = _e->Get(_i); + } + } + } + { + auto _e = type(); + _o->type = _e; + } + { + auto _e = buffer(); + _o->buffer = _e; + } + { + auto _e = name(); + if (_e) + _o->name = _e->str(); + } + { + auto _e = quantization(); + if (_e) + _o->quantization = std::unique_ptr(_e->UnPack(_resolver)); + } + { + auto _e = is_variable(); + _o->is_variable = _e; + } + { + auto _e = sparsity(); + if (_e) + _o->sparsity = std::unique_ptr(_e->UnPack(_resolver)); + } + { + auto _e = shape_signature(); + if (_e) { + _o->shape_signature.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->shape_signature[_i] = _e->Get(_i); + } + } + } +} + +inline flatbuffers::Offset Tensor::Pack(flatbuffers::FlatBufferBuilder &_fbb, const TensorT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateTensor(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateTensor(flatbuffers::FlatBufferBuilder &_fbb, const TensorT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const TensorT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _shape = _o->shape.size() ? _fbb.CreateVector(_o->shape) : 0; + auto _type = _o->type; + auto _buffer = _o->buffer; + auto _name = _o->name.empty() ? 0 : _fbb.CreateString(_o->name); + auto _quantization = _o->quantization ? CreateQuantizationParameters(_fbb, _o->quantization.get(), _rehasher) : 0; + auto _is_variable = _o->is_variable; + auto _sparsity = _o->sparsity ? CreateSparsityParameters(_fbb, _o->sparsity.get(), _rehasher) : 0; + auto _shape_signature = _o->shape_signature.size() ? _fbb.CreateVector(_o->shape_signature) : 0; + return tflite::CreateTensor( + _fbb, + _shape, + _type, + _buffer, + _name, + _quantization, + _is_variable, + _sparsity, + _shape_signature); +} + +inline Conv2DOptionsT *Conv2DOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new Conv2DOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void Conv2DOptions::UnPackTo(Conv2DOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = padding(); + _o->padding = _e; + } + { + auto _e = stride_w(); + _o->stride_w = _e; + } + { + auto _e = stride_h(); + _o->stride_h = _e; + } + { + auto _e = fused_activation_function(); + _o->fused_activation_function = _e; + } + { + auto _e = dilation_w_factor(); + _o->dilation_w_factor = _e; + } + { + auto _e = dilation_h_factor(); + _o->dilation_h_factor = _e; + } +} + +inline flatbuffers::Offset Conv2DOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const Conv2DOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateConv2DOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateConv2DOptions(flatbuffers::FlatBufferBuilder &_fbb, const Conv2DOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const Conv2DOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _padding = _o->padding; + auto _stride_w = _o->stride_w; + auto _stride_h = _o->stride_h; + auto _fused_activation_function = _o->fused_activation_function; + auto _dilation_w_factor = _o->dilation_w_factor; + auto _dilation_h_factor = _o->dilation_h_factor; + return tflite::CreateConv2DOptions( + _fbb, + _padding, + _stride_w, + _stride_h, + _fused_activation_function, + _dilation_w_factor, + _dilation_h_factor); +} + +inline Conv3DOptionsT *Conv3DOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new Conv3DOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void Conv3DOptions::UnPackTo(Conv3DOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = padding(); + _o->padding = _e; + } + { + auto _e = stride_d(); + _o->stride_d = _e; + } + { + auto _e = stride_w(); + _o->stride_w = _e; + } + { + auto _e = stride_h(); + _o->stride_h = _e; + } + { + auto _e = fused_activation_function(); + _o->fused_activation_function = _e; + } + { + auto _e = dilation_d_factor(); + _o->dilation_d_factor = _e; + } + { + auto _e = dilation_w_factor(); + _o->dilation_w_factor = _e; + } + { + auto _e = dilation_h_factor(); + _o->dilation_h_factor = _e; + } +} + +inline flatbuffers::Offset Conv3DOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const Conv3DOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateConv3DOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateConv3DOptions(flatbuffers::FlatBufferBuilder &_fbb, const Conv3DOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const Conv3DOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _padding = _o->padding; + auto _stride_d = _o->stride_d; + auto _stride_w = _o->stride_w; + auto _stride_h = _o->stride_h; + auto _fused_activation_function = _o->fused_activation_function; + auto _dilation_d_factor = _o->dilation_d_factor; + auto _dilation_w_factor = _o->dilation_w_factor; + auto _dilation_h_factor = _o->dilation_h_factor; + return tflite::CreateConv3DOptions( + _fbb, + _padding, + _stride_d, + _stride_w, + _stride_h, + _fused_activation_function, + _dilation_d_factor, + _dilation_w_factor, + _dilation_h_factor); +} + +inline Pool2DOptionsT *Pool2DOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new Pool2DOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void Pool2DOptions::UnPackTo(Pool2DOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = padding(); + _o->padding = _e; + } + { + auto _e = stride_w(); + _o->stride_w = _e; + } + { + auto _e = stride_h(); + _o->stride_h = _e; + } + { + auto _e = filter_width(); + _o->filter_width = _e; + } + { + auto _e = filter_height(); + _o->filter_height = _e; + } + { + auto _e = fused_activation_function(); + _o->fused_activation_function = _e; + } +} + +inline flatbuffers::Offset Pool2DOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const Pool2DOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreatePool2DOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreatePool2DOptions(flatbuffers::FlatBufferBuilder &_fbb, const Pool2DOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const Pool2DOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _padding = _o->padding; + auto _stride_w = _o->stride_w; + auto _stride_h = _o->stride_h; + auto _filter_width = _o->filter_width; + auto _filter_height = _o->filter_height; + auto _fused_activation_function = _o->fused_activation_function; + return tflite::CreatePool2DOptions( + _fbb, + _padding, + _stride_w, + _stride_h, + _filter_width, + _filter_height, + _fused_activation_function); +} + +inline DepthwiseConv2DOptionsT *DepthwiseConv2DOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new DepthwiseConv2DOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void DepthwiseConv2DOptions::UnPackTo(DepthwiseConv2DOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = padding(); + _o->padding = _e; + } + { + auto _e = stride_w(); + _o->stride_w = _e; + } + { + auto _e = stride_h(); + _o->stride_h = _e; + } + { + auto _e = depth_multiplier(); + _o->depth_multiplier = _e; + } + { + auto _e = fused_activation_function(); + _o->fused_activation_function = _e; + } + { + auto _e = dilation_w_factor(); + _o->dilation_w_factor = _e; + } + { + auto _e = dilation_h_factor(); + _o->dilation_h_factor = _e; + } +} + +inline flatbuffers::Offset DepthwiseConv2DOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const DepthwiseConv2DOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateDepthwiseConv2DOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateDepthwiseConv2DOptions(flatbuffers::FlatBufferBuilder &_fbb, const DepthwiseConv2DOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const DepthwiseConv2DOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _padding = _o->padding; + auto _stride_w = _o->stride_w; + auto _stride_h = _o->stride_h; + auto _depth_multiplier = _o->depth_multiplier; + auto _fused_activation_function = _o->fused_activation_function; + auto _dilation_w_factor = _o->dilation_w_factor; + auto _dilation_h_factor = _o->dilation_h_factor; + return tflite::CreateDepthwiseConv2DOptions( + _fbb, + _padding, + _stride_w, + _stride_h, + _depth_multiplier, + _fused_activation_function, + _dilation_w_factor, + _dilation_h_factor); +} + +inline ConcatEmbeddingsOptionsT *ConcatEmbeddingsOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new ConcatEmbeddingsOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void ConcatEmbeddingsOptions::UnPackTo(ConcatEmbeddingsOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = num_channels(); + _o->num_channels = _e; + } + { + auto _e = num_columns_per_channel(); + if (_e) { + _o->num_columns_per_channel.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->num_columns_per_channel[_i] = _e->Get(_i); + } + } + } + { + auto _e = embedding_dim_per_channel(); + if (_e) { + _o->embedding_dim_per_channel.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->embedding_dim_per_channel[_i] = _e->Get(_i); + } + } + } +} + +inline flatbuffers::Offset ConcatEmbeddingsOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const ConcatEmbeddingsOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateConcatEmbeddingsOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateConcatEmbeddingsOptions(flatbuffers::FlatBufferBuilder &_fbb, const ConcatEmbeddingsOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const ConcatEmbeddingsOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _num_channels = _o->num_channels; + auto _num_columns_per_channel = _o->num_columns_per_channel.size() ? _fbb.CreateVector(_o->num_columns_per_channel) : 0; + auto _embedding_dim_per_channel = _o->embedding_dim_per_channel.size() ? _fbb.CreateVector(_o->embedding_dim_per_channel) : 0; + return tflite::CreateConcatEmbeddingsOptions( + _fbb, + _num_channels, + _num_columns_per_channel, + _embedding_dim_per_channel); +} + +inline LSHProjectionOptionsT *LSHProjectionOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new LSHProjectionOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void LSHProjectionOptions::UnPackTo(LSHProjectionOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = type(); + _o->type = _e; + } +} + +inline flatbuffers::Offset LSHProjectionOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const LSHProjectionOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateLSHProjectionOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateLSHProjectionOptions(flatbuffers::FlatBufferBuilder &_fbb, const LSHProjectionOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const LSHProjectionOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _type = _o->type; + return tflite::CreateLSHProjectionOptions( + _fbb, + _type); +} + +inline SVDFOptionsT *SVDFOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new SVDFOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void SVDFOptions::UnPackTo(SVDFOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = rank(); + _o->rank = _e; + } + { + auto _e = fused_activation_function(); + _o->fused_activation_function = _e; + } + { + auto _e = asymmetric_quantize_inputs(); + _o->asymmetric_quantize_inputs = _e; + } +} + +inline flatbuffers::Offset SVDFOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const SVDFOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateSVDFOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateSVDFOptions(flatbuffers::FlatBufferBuilder &_fbb, const SVDFOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const SVDFOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _rank = _o->rank; + auto _fused_activation_function = _o->fused_activation_function; + auto _asymmetric_quantize_inputs = _o->asymmetric_quantize_inputs; + return tflite::CreateSVDFOptions( + _fbb, + _rank, + _fused_activation_function, + _asymmetric_quantize_inputs); +} + +inline RNNOptionsT *RNNOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new RNNOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void RNNOptions::UnPackTo(RNNOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = fused_activation_function(); + _o->fused_activation_function = _e; + } + { + auto _e = asymmetric_quantize_inputs(); + _o->asymmetric_quantize_inputs = _e; + } +} + +inline flatbuffers::Offset RNNOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const RNNOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateRNNOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateRNNOptions(flatbuffers::FlatBufferBuilder &_fbb, const RNNOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const RNNOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _fused_activation_function = _o->fused_activation_function; + auto _asymmetric_quantize_inputs = _o->asymmetric_quantize_inputs; + return tflite::CreateRNNOptions( + _fbb, + _fused_activation_function, + _asymmetric_quantize_inputs); +} + +inline SequenceRNNOptionsT *SequenceRNNOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new SequenceRNNOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void SequenceRNNOptions::UnPackTo(SequenceRNNOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = time_major(); + _o->time_major = _e; + } + { + auto _e = fused_activation_function(); + _o->fused_activation_function = _e; + } + { + auto _e = asymmetric_quantize_inputs(); + _o->asymmetric_quantize_inputs = _e; + } +} + +inline flatbuffers::Offset SequenceRNNOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const SequenceRNNOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateSequenceRNNOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateSequenceRNNOptions(flatbuffers::FlatBufferBuilder &_fbb, const SequenceRNNOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const SequenceRNNOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _time_major = _o->time_major; + auto _fused_activation_function = _o->fused_activation_function; + auto _asymmetric_quantize_inputs = _o->asymmetric_quantize_inputs; + return tflite::CreateSequenceRNNOptions( + _fbb, + _time_major, + _fused_activation_function, + _asymmetric_quantize_inputs); +} + +inline BidirectionalSequenceRNNOptionsT *BidirectionalSequenceRNNOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new BidirectionalSequenceRNNOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void BidirectionalSequenceRNNOptions::UnPackTo(BidirectionalSequenceRNNOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = time_major(); + _o->time_major = _e; + } + { + auto _e = fused_activation_function(); + _o->fused_activation_function = _e; + } + { + auto _e = merge_outputs(); + _o->merge_outputs = _e; + } + { + auto _e = asymmetric_quantize_inputs(); + _o->asymmetric_quantize_inputs = _e; + } +} + +inline flatbuffers::Offset BidirectionalSequenceRNNOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const BidirectionalSequenceRNNOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateBidirectionalSequenceRNNOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateBidirectionalSequenceRNNOptions(flatbuffers::FlatBufferBuilder &_fbb, const BidirectionalSequenceRNNOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const BidirectionalSequenceRNNOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _time_major = _o->time_major; + auto _fused_activation_function = _o->fused_activation_function; + auto _merge_outputs = _o->merge_outputs; + auto _asymmetric_quantize_inputs = _o->asymmetric_quantize_inputs; + return tflite::CreateBidirectionalSequenceRNNOptions( + _fbb, + _time_major, + _fused_activation_function, + _merge_outputs, + _asymmetric_quantize_inputs); +} + +inline FullyConnectedOptionsT *FullyConnectedOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new FullyConnectedOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void FullyConnectedOptions::UnPackTo(FullyConnectedOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = fused_activation_function(); + _o->fused_activation_function = _e; + } + { + auto _e = weights_format(); + _o->weights_format = _e; + } + { + auto _e = keep_num_dims(); + _o->keep_num_dims = _e; + } + { + auto _e = asymmetric_quantize_inputs(); + _o->asymmetric_quantize_inputs = _e; + } +} + +inline flatbuffers::Offset FullyConnectedOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const FullyConnectedOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateFullyConnectedOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateFullyConnectedOptions(flatbuffers::FlatBufferBuilder &_fbb, const FullyConnectedOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const FullyConnectedOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _fused_activation_function = _o->fused_activation_function; + auto _weights_format = _o->weights_format; + auto _keep_num_dims = _o->keep_num_dims; + auto _asymmetric_quantize_inputs = _o->asymmetric_quantize_inputs; + return tflite::CreateFullyConnectedOptions( + _fbb, + _fused_activation_function, + _weights_format, + _keep_num_dims, + _asymmetric_quantize_inputs); +} + +inline SoftmaxOptionsT *SoftmaxOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new SoftmaxOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void SoftmaxOptions::UnPackTo(SoftmaxOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = beta(); + _o->beta = _e; + } +} + +inline flatbuffers::Offset SoftmaxOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const SoftmaxOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateSoftmaxOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateSoftmaxOptions(flatbuffers::FlatBufferBuilder &_fbb, const SoftmaxOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const SoftmaxOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _beta = _o->beta; + return tflite::CreateSoftmaxOptions( + _fbb, + _beta); +} + +inline ConcatenationOptionsT *ConcatenationOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new ConcatenationOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void ConcatenationOptions::UnPackTo(ConcatenationOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = axis(); + _o->axis = _e; + } + { + auto _e = fused_activation_function(); + _o->fused_activation_function = _e; + } +} + +inline flatbuffers::Offset ConcatenationOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const ConcatenationOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateConcatenationOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateConcatenationOptions(flatbuffers::FlatBufferBuilder &_fbb, const ConcatenationOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const ConcatenationOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _axis = _o->axis; + auto _fused_activation_function = _o->fused_activation_function; + return tflite::CreateConcatenationOptions( + _fbb, + _axis, + _fused_activation_function); +} + +inline AddOptionsT *AddOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new AddOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void AddOptions::UnPackTo(AddOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = fused_activation_function(); + _o->fused_activation_function = _e; + } + { + auto _e = pot_scale_int16(); + _o->pot_scale_int16 = _e; + } +} + +inline flatbuffers::Offset AddOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const AddOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateAddOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateAddOptions(flatbuffers::FlatBufferBuilder &_fbb, const AddOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const AddOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _fused_activation_function = _o->fused_activation_function; + auto _pot_scale_int16 = _o->pot_scale_int16; + return tflite::CreateAddOptions( + _fbb, + _fused_activation_function, + _pot_scale_int16); +} + +inline MulOptionsT *MulOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new MulOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void MulOptions::UnPackTo(MulOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = fused_activation_function(); + _o->fused_activation_function = _e; + } +} + +inline flatbuffers::Offset MulOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const MulOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateMulOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateMulOptions(flatbuffers::FlatBufferBuilder &_fbb, const MulOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const MulOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _fused_activation_function = _o->fused_activation_function; + return tflite::CreateMulOptions( + _fbb, + _fused_activation_function); +} + +inline L2NormOptionsT *L2NormOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new L2NormOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void L2NormOptions::UnPackTo(L2NormOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = fused_activation_function(); + _o->fused_activation_function = _e; + } +} + +inline flatbuffers::Offset L2NormOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const L2NormOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateL2NormOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateL2NormOptions(flatbuffers::FlatBufferBuilder &_fbb, const L2NormOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const L2NormOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _fused_activation_function = _o->fused_activation_function; + return tflite::CreateL2NormOptions( + _fbb, + _fused_activation_function); +} + +inline LocalResponseNormalizationOptionsT *LocalResponseNormalizationOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new LocalResponseNormalizationOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void LocalResponseNormalizationOptions::UnPackTo(LocalResponseNormalizationOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = radius(); + _o->radius = _e; + } + { + auto _e = bias(); + _o->bias = _e; + } + { + auto _e = alpha(); + _o->alpha = _e; + } + { + auto _e = beta(); + _o->beta = _e; + } +} + +inline flatbuffers::Offset LocalResponseNormalizationOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const LocalResponseNormalizationOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateLocalResponseNormalizationOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateLocalResponseNormalizationOptions(flatbuffers::FlatBufferBuilder &_fbb, const LocalResponseNormalizationOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const LocalResponseNormalizationOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _radius = _o->radius; + auto _bias = _o->bias; + auto _alpha = _o->alpha; + auto _beta = _o->beta; + return tflite::CreateLocalResponseNormalizationOptions( + _fbb, + _radius, + _bias, + _alpha, + _beta); +} + +inline LSTMOptionsT *LSTMOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new LSTMOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void LSTMOptions::UnPackTo(LSTMOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = fused_activation_function(); + _o->fused_activation_function = _e; + } + { + auto _e = cell_clip(); + _o->cell_clip = _e; + } + { + auto _e = proj_clip(); + _o->proj_clip = _e; + } + { + auto _e = kernel_type(); + _o->kernel_type = _e; + } + { + auto _e = asymmetric_quantize_inputs(); + _o->asymmetric_quantize_inputs = _e; + } +} + +inline flatbuffers::Offset LSTMOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const LSTMOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateLSTMOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateLSTMOptions(flatbuffers::FlatBufferBuilder &_fbb, const LSTMOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const LSTMOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _fused_activation_function = _o->fused_activation_function; + auto _cell_clip = _o->cell_clip; + auto _proj_clip = _o->proj_clip; + auto _kernel_type = _o->kernel_type; + auto _asymmetric_quantize_inputs = _o->asymmetric_quantize_inputs; + return tflite::CreateLSTMOptions( + _fbb, + _fused_activation_function, + _cell_clip, + _proj_clip, + _kernel_type, + _asymmetric_quantize_inputs); +} + +inline UnidirectionalSequenceLSTMOptionsT *UnidirectionalSequenceLSTMOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new UnidirectionalSequenceLSTMOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void UnidirectionalSequenceLSTMOptions::UnPackTo(UnidirectionalSequenceLSTMOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = fused_activation_function(); + _o->fused_activation_function = _e; + } + { + auto _e = cell_clip(); + _o->cell_clip = _e; + } + { + auto _e = proj_clip(); + _o->proj_clip = _e; + } + { + auto _e = time_major(); + _o->time_major = _e; + } + { + auto _e = asymmetric_quantize_inputs(); + _o->asymmetric_quantize_inputs = _e; + } +} + +inline flatbuffers::Offset UnidirectionalSequenceLSTMOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const UnidirectionalSequenceLSTMOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateUnidirectionalSequenceLSTMOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateUnidirectionalSequenceLSTMOptions(flatbuffers::FlatBufferBuilder &_fbb, const UnidirectionalSequenceLSTMOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const UnidirectionalSequenceLSTMOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _fused_activation_function = _o->fused_activation_function; + auto _cell_clip = _o->cell_clip; + auto _proj_clip = _o->proj_clip; + auto _time_major = _o->time_major; + auto _asymmetric_quantize_inputs = _o->asymmetric_quantize_inputs; + return tflite::CreateUnidirectionalSequenceLSTMOptions( + _fbb, + _fused_activation_function, + _cell_clip, + _proj_clip, + _time_major, + _asymmetric_quantize_inputs); +} + +inline BidirectionalSequenceLSTMOptionsT *BidirectionalSequenceLSTMOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new BidirectionalSequenceLSTMOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void BidirectionalSequenceLSTMOptions::UnPackTo(BidirectionalSequenceLSTMOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = fused_activation_function(); + _o->fused_activation_function = _e; + } + { + auto _e = cell_clip(); + _o->cell_clip = _e; + } + { + auto _e = proj_clip(); + _o->proj_clip = _e; + } + { + auto _e = merge_outputs(); + _o->merge_outputs = _e; + } + { + auto _e = time_major(); + _o->time_major = _e; + } + { + auto _e = asymmetric_quantize_inputs(); + _o->asymmetric_quantize_inputs = _e; + } +} + +inline flatbuffers::Offset BidirectionalSequenceLSTMOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const BidirectionalSequenceLSTMOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateBidirectionalSequenceLSTMOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateBidirectionalSequenceLSTMOptions(flatbuffers::FlatBufferBuilder &_fbb, const BidirectionalSequenceLSTMOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const BidirectionalSequenceLSTMOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _fused_activation_function = _o->fused_activation_function; + auto _cell_clip = _o->cell_clip; + auto _proj_clip = _o->proj_clip; + auto _merge_outputs = _o->merge_outputs; + auto _time_major = _o->time_major; + auto _asymmetric_quantize_inputs = _o->asymmetric_quantize_inputs; + return tflite::CreateBidirectionalSequenceLSTMOptions( + _fbb, + _fused_activation_function, + _cell_clip, + _proj_clip, + _merge_outputs, + _time_major, + _asymmetric_quantize_inputs); +} + +inline ResizeBilinearOptionsT *ResizeBilinearOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new ResizeBilinearOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void ResizeBilinearOptions::UnPackTo(ResizeBilinearOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = align_corners(); + _o->align_corners = _e; + } + { + auto _e = half_pixel_centers(); + _o->half_pixel_centers = _e; + } +} + +inline flatbuffers::Offset ResizeBilinearOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const ResizeBilinearOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateResizeBilinearOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateResizeBilinearOptions(flatbuffers::FlatBufferBuilder &_fbb, const ResizeBilinearOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const ResizeBilinearOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _align_corners = _o->align_corners; + auto _half_pixel_centers = _o->half_pixel_centers; + return tflite::CreateResizeBilinearOptions( + _fbb, + _align_corners, + _half_pixel_centers); +} + +inline ResizeNearestNeighborOptionsT *ResizeNearestNeighborOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new ResizeNearestNeighborOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void ResizeNearestNeighborOptions::UnPackTo(ResizeNearestNeighborOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = align_corners(); + _o->align_corners = _e; + } + { + auto _e = half_pixel_centers(); + _o->half_pixel_centers = _e; + } +} + +inline flatbuffers::Offset ResizeNearestNeighborOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const ResizeNearestNeighborOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateResizeNearestNeighborOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateResizeNearestNeighborOptions(flatbuffers::FlatBufferBuilder &_fbb, const ResizeNearestNeighborOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const ResizeNearestNeighborOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _align_corners = _o->align_corners; + auto _half_pixel_centers = _o->half_pixel_centers; + return tflite::CreateResizeNearestNeighborOptions( + _fbb, + _align_corners, + _half_pixel_centers); +} + +inline CallOptionsT *CallOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new CallOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void CallOptions::UnPackTo(CallOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = subgraph(); + _o->subgraph = _e; + } +} + +inline flatbuffers::Offset CallOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const CallOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateCallOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateCallOptions(flatbuffers::FlatBufferBuilder &_fbb, const CallOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const CallOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _subgraph = _o->subgraph; + return tflite::CreateCallOptions( + _fbb, + _subgraph); +} + +inline PadOptionsT *PadOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new PadOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void PadOptions::UnPackTo(PadOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset PadOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const PadOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreatePadOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreatePadOptions(flatbuffers::FlatBufferBuilder &_fbb, const PadOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const PadOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreatePadOptions( + _fbb); +} + +inline PadV2OptionsT *PadV2Options::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new PadV2OptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void PadV2Options::UnPackTo(PadV2OptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset PadV2Options::Pack(flatbuffers::FlatBufferBuilder &_fbb, const PadV2OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreatePadV2Options(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreatePadV2Options(flatbuffers::FlatBufferBuilder &_fbb, const PadV2OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const PadV2OptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreatePadV2Options( + _fbb); +} + +inline ReshapeOptionsT *ReshapeOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new ReshapeOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void ReshapeOptions::UnPackTo(ReshapeOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = new_shape(); + if (_e) { + _o->new_shape.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->new_shape[_i] = _e->Get(_i); + } + } + } +} + +inline flatbuffers::Offset ReshapeOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const ReshapeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateReshapeOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateReshapeOptions(flatbuffers::FlatBufferBuilder &_fbb, const ReshapeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const ReshapeOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _new_shape = _o->new_shape.size() ? _fbb.CreateVector(_o->new_shape) : 0; + return tflite::CreateReshapeOptions( + _fbb, + _new_shape); +} + +inline SpaceToBatchNDOptionsT *SpaceToBatchNDOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new SpaceToBatchNDOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void SpaceToBatchNDOptions::UnPackTo(SpaceToBatchNDOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset SpaceToBatchNDOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const SpaceToBatchNDOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateSpaceToBatchNDOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateSpaceToBatchNDOptions(flatbuffers::FlatBufferBuilder &_fbb, const SpaceToBatchNDOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const SpaceToBatchNDOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateSpaceToBatchNDOptions( + _fbb); +} + +inline BatchToSpaceNDOptionsT *BatchToSpaceNDOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new BatchToSpaceNDOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void BatchToSpaceNDOptions::UnPackTo(BatchToSpaceNDOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset BatchToSpaceNDOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const BatchToSpaceNDOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateBatchToSpaceNDOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateBatchToSpaceNDOptions(flatbuffers::FlatBufferBuilder &_fbb, const BatchToSpaceNDOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const BatchToSpaceNDOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateBatchToSpaceNDOptions( + _fbb); +} + +inline SkipGramOptionsT *SkipGramOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new SkipGramOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void SkipGramOptions::UnPackTo(SkipGramOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = ngram_size(); + _o->ngram_size = _e; + } + { + auto _e = max_skip_size(); + _o->max_skip_size = _e; + } + { + auto _e = include_all_ngrams(); + _o->include_all_ngrams = _e; + } +} + +inline flatbuffers::Offset SkipGramOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const SkipGramOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateSkipGramOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateSkipGramOptions(flatbuffers::FlatBufferBuilder &_fbb, const SkipGramOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const SkipGramOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _ngram_size = _o->ngram_size; + auto _max_skip_size = _o->max_skip_size; + auto _include_all_ngrams = _o->include_all_ngrams; + return tflite::CreateSkipGramOptions( + _fbb, + _ngram_size, + _max_skip_size, + _include_all_ngrams); +} + +inline SpaceToDepthOptionsT *SpaceToDepthOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new SpaceToDepthOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void SpaceToDepthOptions::UnPackTo(SpaceToDepthOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = block_size(); + _o->block_size = _e; + } +} + +inline flatbuffers::Offset SpaceToDepthOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const SpaceToDepthOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateSpaceToDepthOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateSpaceToDepthOptions(flatbuffers::FlatBufferBuilder &_fbb, const SpaceToDepthOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const SpaceToDepthOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _block_size = _o->block_size; + return tflite::CreateSpaceToDepthOptions( + _fbb, + _block_size); +} + +inline DepthToSpaceOptionsT *DepthToSpaceOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new DepthToSpaceOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void DepthToSpaceOptions::UnPackTo(DepthToSpaceOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = block_size(); + _o->block_size = _e; + } +} + +inline flatbuffers::Offset DepthToSpaceOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const DepthToSpaceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateDepthToSpaceOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateDepthToSpaceOptions(flatbuffers::FlatBufferBuilder &_fbb, const DepthToSpaceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const DepthToSpaceOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _block_size = _o->block_size; + return tflite::CreateDepthToSpaceOptions( + _fbb, + _block_size); +} + +inline SubOptionsT *SubOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new SubOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void SubOptions::UnPackTo(SubOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = fused_activation_function(); + _o->fused_activation_function = _e; + } + { + auto _e = pot_scale_int16(); + _o->pot_scale_int16 = _e; + } +} + +inline flatbuffers::Offset SubOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const SubOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateSubOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateSubOptions(flatbuffers::FlatBufferBuilder &_fbb, const SubOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const SubOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _fused_activation_function = _o->fused_activation_function; + auto _pot_scale_int16 = _o->pot_scale_int16; + return tflite::CreateSubOptions( + _fbb, + _fused_activation_function, + _pot_scale_int16); +} + +inline DivOptionsT *DivOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new DivOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void DivOptions::UnPackTo(DivOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = fused_activation_function(); + _o->fused_activation_function = _e; + } +} + +inline flatbuffers::Offset DivOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const DivOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateDivOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateDivOptions(flatbuffers::FlatBufferBuilder &_fbb, const DivOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const DivOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _fused_activation_function = _o->fused_activation_function; + return tflite::CreateDivOptions( + _fbb, + _fused_activation_function); +} + +inline TopKV2OptionsT *TopKV2Options::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new TopKV2OptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void TopKV2Options::UnPackTo(TopKV2OptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset TopKV2Options::Pack(flatbuffers::FlatBufferBuilder &_fbb, const TopKV2OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateTopKV2Options(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateTopKV2Options(flatbuffers::FlatBufferBuilder &_fbb, const TopKV2OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const TopKV2OptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateTopKV2Options( + _fbb); +} + +inline EmbeddingLookupSparseOptionsT *EmbeddingLookupSparseOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new EmbeddingLookupSparseOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void EmbeddingLookupSparseOptions::UnPackTo(EmbeddingLookupSparseOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = combiner(); + _o->combiner = _e; + } +} + +inline flatbuffers::Offset EmbeddingLookupSparseOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const EmbeddingLookupSparseOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateEmbeddingLookupSparseOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateEmbeddingLookupSparseOptions(flatbuffers::FlatBufferBuilder &_fbb, const EmbeddingLookupSparseOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const EmbeddingLookupSparseOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _combiner = _o->combiner; + return tflite::CreateEmbeddingLookupSparseOptions( + _fbb, + _combiner); +} + +inline GatherOptionsT *GatherOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new GatherOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void GatherOptions::UnPackTo(GatherOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = axis(); + _o->axis = _e; + } + { + auto _e = batch_dims(); + _o->batch_dims = _e; + } +} + +inline flatbuffers::Offset GatherOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const GatherOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateGatherOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateGatherOptions(flatbuffers::FlatBufferBuilder &_fbb, const GatherOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const GatherOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _axis = _o->axis; + auto _batch_dims = _o->batch_dims; + return tflite::CreateGatherOptions( + _fbb, + _axis, + _batch_dims); +} + +inline TransposeOptionsT *TransposeOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new TransposeOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void TransposeOptions::UnPackTo(TransposeOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset TransposeOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const TransposeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateTransposeOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateTransposeOptions(flatbuffers::FlatBufferBuilder &_fbb, const TransposeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const TransposeOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateTransposeOptions( + _fbb); +} + +inline ExpOptionsT *ExpOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new ExpOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void ExpOptions::UnPackTo(ExpOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset ExpOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const ExpOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateExpOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateExpOptions(flatbuffers::FlatBufferBuilder &_fbb, const ExpOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const ExpOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateExpOptions( + _fbb); +} + +inline CosOptionsT *CosOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new CosOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void CosOptions::UnPackTo(CosOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset CosOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const CosOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateCosOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateCosOptions(flatbuffers::FlatBufferBuilder &_fbb, const CosOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const CosOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateCosOptions( + _fbb); +} + +inline ReducerOptionsT *ReducerOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new ReducerOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void ReducerOptions::UnPackTo(ReducerOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = keep_dims(); + _o->keep_dims = _e; + } +} + +inline flatbuffers::Offset ReducerOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const ReducerOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateReducerOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateReducerOptions(flatbuffers::FlatBufferBuilder &_fbb, const ReducerOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const ReducerOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _keep_dims = _o->keep_dims; + return tflite::CreateReducerOptions( + _fbb, + _keep_dims); +} + +inline SqueezeOptionsT *SqueezeOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new SqueezeOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void SqueezeOptions::UnPackTo(SqueezeOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = squeeze_dims(); + if (_e) { + _o->squeeze_dims.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->squeeze_dims[_i] = _e->Get(_i); + } + } + } +} + +inline flatbuffers::Offset SqueezeOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const SqueezeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateSqueezeOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateSqueezeOptions(flatbuffers::FlatBufferBuilder &_fbb, const SqueezeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const SqueezeOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _squeeze_dims = _o->squeeze_dims.size() ? _fbb.CreateVector(_o->squeeze_dims) : 0; + return tflite::CreateSqueezeOptions( + _fbb, + _squeeze_dims); +} + +inline SplitOptionsT *SplitOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new SplitOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void SplitOptions::UnPackTo(SplitOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = num_splits(); + _o->num_splits = _e; + } +} + +inline flatbuffers::Offset SplitOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const SplitOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateSplitOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateSplitOptions(flatbuffers::FlatBufferBuilder &_fbb, const SplitOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const SplitOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _num_splits = _o->num_splits; + return tflite::CreateSplitOptions( + _fbb, + _num_splits); +} + +inline SplitVOptionsT *SplitVOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new SplitVOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void SplitVOptions::UnPackTo(SplitVOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = num_splits(); + _o->num_splits = _e; + } +} + +inline flatbuffers::Offset SplitVOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const SplitVOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateSplitVOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateSplitVOptions(flatbuffers::FlatBufferBuilder &_fbb, const SplitVOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const SplitVOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _num_splits = _o->num_splits; + return tflite::CreateSplitVOptions( + _fbb, + _num_splits); +} + +inline StridedSliceOptionsT *StridedSliceOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new StridedSliceOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void StridedSliceOptions::UnPackTo(StridedSliceOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = begin_mask(); + _o->begin_mask = _e; + } + { + auto _e = end_mask(); + _o->end_mask = _e; + } + { + auto _e = ellipsis_mask(); + _o->ellipsis_mask = _e; + } + { + auto _e = new_axis_mask(); + _o->new_axis_mask = _e; + } + { + auto _e = shrink_axis_mask(); + _o->shrink_axis_mask = _e; + } +} + +inline flatbuffers::Offset StridedSliceOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const StridedSliceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateStridedSliceOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateStridedSliceOptions(flatbuffers::FlatBufferBuilder &_fbb, const StridedSliceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const StridedSliceOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _begin_mask = _o->begin_mask; + auto _end_mask = _o->end_mask; + auto _ellipsis_mask = _o->ellipsis_mask; + auto _new_axis_mask = _o->new_axis_mask; + auto _shrink_axis_mask = _o->shrink_axis_mask; + return tflite::CreateStridedSliceOptions( + _fbb, + _begin_mask, + _end_mask, + _ellipsis_mask, + _new_axis_mask, + _shrink_axis_mask); +} + +inline LogSoftmaxOptionsT *LogSoftmaxOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new LogSoftmaxOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void LogSoftmaxOptions::UnPackTo(LogSoftmaxOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset LogSoftmaxOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const LogSoftmaxOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateLogSoftmaxOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateLogSoftmaxOptions(flatbuffers::FlatBufferBuilder &_fbb, const LogSoftmaxOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const LogSoftmaxOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateLogSoftmaxOptions( + _fbb); +} + +inline CastOptionsT *CastOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new CastOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void CastOptions::UnPackTo(CastOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = in_data_type(); + _o->in_data_type = _e; + } + { + auto _e = out_data_type(); + _o->out_data_type = _e; + } +} + +inline flatbuffers::Offset CastOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const CastOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateCastOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateCastOptions(flatbuffers::FlatBufferBuilder &_fbb, const CastOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const CastOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _in_data_type = _o->in_data_type; + auto _out_data_type = _o->out_data_type; + return tflite::CreateCastOptions( + _fbb, + _in_data_type, + _out_data_type); +} + +inline DequantizeOptionsT *DequantizeOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new DequantizeOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void DequantizeOptions::UnPackTo(DequantizeOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset DequantizeOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const DequantizeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateDequantizeOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateDequantizeOptions(flatbuffers::FlatBufferBuilder &_fbb, const DequantizeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const DequantizeOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateDequantizeOptions( + _fbb); +} + +inline MaximumMinimumOptionsT *MaximumMinimumOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new MaximumMinimumOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void MaximumMinimumOptions::UnPackTo(MaximumMinimumOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset MaximumMinimumOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const MaximumMinimumOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateMaximumMinimumOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateMaximumMinimumOptions(flatbuffers::FlatBufferBuilder &_fbb, const MaximumMinimumOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const MaximumMinimumOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateMaximumMinimumOptions( + _fbb); +} + +inline TileOptionsT *TileOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new TileOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void TileOptions::UnPackTo(TileOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset TileOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const TileOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateTileOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateTileOptions(flatbuffers::FlatBufferBuilder &_fbb, const TileOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const TileOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateTileOptions( + _fbb); +} + +inline ArgMaxOptionsT *ArgMaxOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new ArgMaxOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void ArgMaxOptions::UnPackTo(ArgMaxOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = output_type(); + _o->output_type = _e; + } +} + +inline flatbuffers::Offset ArgMaxOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const ArgMaxOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateArgMaxOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateArgMaxOptions(flatbuffers::FlatBufferBuilder &_fbb, const ArgMaxOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const ArgMaxOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _output_type = _o->output_type; + return tflite::CreateArgMaxOptions( + _fbb, + _output_type); +} + +inline ArgMinOptionsT *ArgMinOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new ArgMinOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void ArgMinOptions::UnPackTo(ArgMinOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = output_type(); + _o->output_type = _e; + } +} + +inline flatbuffers::Offset ArgMinOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const ArgMinOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateArgMinOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateArgMinOptions(flatbuffers::FlatBufferBuilder &_fbb, const ArgMinOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const ArgMinOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _output_type = _o->output_type; + return tflite::CreateArgMinOptions( + _fbb, + _output_type); +} + +inline GreaterOptionsT *GreaterOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new GreaterOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void GreaterOptions::UnPackTo(GreaterOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset GreaterOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const GreaterOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateGreaterOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateGreaterOptions(flatbuffers::FlatBufferBuilder &_fbb, const GreaterOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const GreaterOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateGreaterOptions( + _fbb); +} + +inline GreaterEqualOptionsT *GreaterEqualOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new GreaterEqualOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void GreaterEqualOptions::UnPackTo(GreaterEqualOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset GreaterEqualOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const GreaterEqualOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateGreaterEqualOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateGreaterEqualOptions(flatbuffers::FlatBufferBuilder &_fbb, const GreaterEqualOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const GreaterEqualOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateGreaterEqualOptions( + _fbb); +} + +inline LessOptionsT *LessOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new LessOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void LessOptions::UnPackTo(LessOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset LessOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const LessOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateLessOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateLessOptions(flatbuffers::FlatBufferBuilder &_fbb, const LessOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const LessOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateLessOptions( + _fbb); +} + +inline LessEqualOptionsT *LessEqualOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new LessEqualOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void LessEqualOptions::UnPackTo(LessEqualOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset LessEqualOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const LessEqualOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateLessEqualOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateLessEqualOptions(flatbuffers::FlatBufferBuilder &_fbb, const LessEqualOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const LessEqualOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateLessEqualOptions( + _fbb); +} + +inline NegOptionsT *NegOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new NegOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void NegOptions::UnPackTo(NegOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset NegOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const NegOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateNegOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateNegOptions(flatbuffers::FlatBufferBuilder &_fbb, const NegOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const NegOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateNegOptions( + _fbb); +} + +inline SelectOptionsT *SelectOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new SelectOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void SelectOptions::UnPackTo(SelectOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset SelectOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const SelectOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateSelectOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateSelectOptions(flatbuffers::FlatBufferBuilder &_fbb, const SelectOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const SelectOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateSelectOptions( + _fbb); +} + +inline SliceOptionsT *SliceOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new SliceOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void SliceOptions::UnPackTo(SliceOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset SliceOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const SliceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateSliceOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateSliceOptions(flatbuffers::FlatBufferBuilder &_fbb, const SliceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const SliceOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateSliceOptions( + _fbb); +} + +inline TransposeConvOptionsT *TransposeConvOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new TransposeConvOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void TransposeConvOptions::UnPackTo(TransposeConvOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = padding(); + _o->padding = _e; + } + { + auto _e = stride_w(); + _o->stride_w = _e; + } + { + auto _e = stride_h(); + _o->stride_h = _e; + } +} + +inline flatbuffers::Offset TransposeConvOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const TransposeConvOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateTransposeConvOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateTransposeConvOptions(flatbuffers::FlatBufferBuilder &_fbb, const TransposeConvOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const TransposeConvOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _padding = _o->padding; + auto _stride_w = _o->stride_w; + auto _stride_h = _o->stride_h; + return tflite::CreateTransposeConvOptions( + _fbb, + _padding, + _stride_w, + _stride_h); +} + +inline ExpandDimsOptionsT *ExpandDimsOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new ExpandDimsOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void ExpandDimsOptions::UnPackTo(ExpandDimsOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset ExpandDimsOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const ExpandDimsOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateExpandDimsOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateExpandDimsOptions(flatbuffers::FlatBufferBuilder &_fbb, const ExpandDimsOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const ExpandDimsOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateExpandDimsOptions( + _fbb); +} + +inline SparseToDenseOptionsT *SparseToDenseOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new SparseToDenseOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void SparseToDenseOptions::UnPackTo(SparseToDenseOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = validate_indices(); + _o->validate_indices = _e; + } +} + +inline flatbuffers::Offset SparseToDenseOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const SparseToDenseOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateSparseToDenseOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateSparseToDenseOptions(flatbuffers::FlatBufferBuilder &_fbb, const SparseToDenseOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const SparseToDenseOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _validate_indices = _o->validate_indices; + return tflite::CreateSparseToDenseOptions( + _fbb, + _validate_indices); +} + +inline EqualOptionsT *EqualOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new EqualOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void EqualOptions::UnPackTo(EqualOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset EqualOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const EqualOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateEqualOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateEqualOptions(flatbuffers::FlatBufferBuilder &_fbb, const EqualOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const EqualOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateEqualOptions( + _fbb); +} + +inline NotEqualOptionsT *NotEqualOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new NotEqualOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void NotEqualOptions::UnPackTo(NotEqualOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset NotEqualOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const NotEqualOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateNotEqualOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateNotEqualOptions(flatbuffers::FlatBufferBuilder &_fbb, const NotEqualOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const NotEqualOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateNotEqualOptions( + _fbb); +} + +inline ShapeOptionsT *ShapeOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new ShapeOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void ShapeOptions::UnPackTo(ShapeOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = out_type(); + _o->out_type = _e; + } +} + +inline flatbuffers::Offset ShapeOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const ShapeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateShapeOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateShapeOptions(flatbuffers::FlatBufferBuilder &_fbb, const ShapeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const ShapeOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _out_type = _o->out_type; + return tflite::CreateShapeOptions( + _fbb, + _out_type); +} + +inline RankOptionsT *RankOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new RankOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void RankOptions::UnPackTo(RankOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset RankOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const RankOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateRankOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateRankOptions(flatbuffers::FlatBufferBuilder &_fbb, const RankOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const RankOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateRankOptions( + _fbb); +} + +inline PowOptionsT *PowOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new PowOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void PowOptions::UnPackTo(PowOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset PowOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const PowOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreatePowOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreatePowOptions(flatbuffers::FlatBufferBuilder &_fbb, const PowOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const PowOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreatePowOptions( + _fbb); +} + +inline FakeQuantOptionsT *FakeQuantOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new FakeQuantOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void FakeQuantOptions::UnPackTo(FakeQuantOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = min(); + _o->min = _e; + } + { + auto _e = max(); + _o->max = _e; + } + { + auto _e = num_bits(); + _o->num_bits = _e; + } + { + auto _e = narrow_range(); + _o->narrow_range = _e; + } +} + +inline flatbuffers::Offset FakeQuantOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const FakeQuantOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateFakeQuantOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateFakeQuantOptions(flatbuffers::FlatBufferBuilder &_fbb, const FakeQuantOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const FakeQuantOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _min = _o->min; + auto _max = _o->max; + auto _num_bits = _o->num_bits; + auto _narrow_range = _o->narrow_range; + return tflite::CreateFakeQuantOptions( + _fbb, + _min, + _max, + _num_bits, + _narrow_range); +} + +inline PackOptionsT *PackOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new PackOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void PackOptions::UnPackTo(PackOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = values_count(); + _o->values_count = _e; + } + { + auto _e = axis(); + _o->axis = _e; + } +} + +inline flatbuffers::Offset PackOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const PackOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreatePackOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreatePackOptions(flatbuffers::FlatBufferBuilder &_fbb, const PackOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const PackOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _values_count = _o->values_count; + auto _axis = _o->axis; + return tflite::CreatePackOptions( + _fbb, + _values_count, + _axis); +} + +inline LogicalOrOptionsT *LogicalOrOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new LogicalOrOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void LogicalOrOptions::UnPackTo(LogicalOrOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset LogicalOrOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const LogicalOrOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateLogicalOrOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateLogicalOrOptions(flatbuffers::FlatBufferBuilder &_fbb, const LogicalOrOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const LogicalOrOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateLogicalOrOptions( + _fbb); +} + +inline OneHotOptionsT *OneHotOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new OneHotOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void OneHotOptions::UnPackTo(OneHotOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = axis(); + _o->axis = _e; + } +} + +inline flatbuffers::Offset OneHotOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const OneHotOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateOneHotOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateOneHotOptions(flatbuffers::FlatBufferBuilder &_fbb, const OneHotOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const OneHotOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _axis = _o->axis; + return tflite::CreateOneHotOptions( + _fbb, + _axis); +} + +inline AbsOptionsT *AbsOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new AbsOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void AbsOptions::UnPackTo(AbsOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset AbsOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const AbsOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateAbsOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateAbsOptions(flatbuffers::FlatBufferBuilder &_fbb, const AbsOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const AbsOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateAbsOptions( + _fbb); +} + +inline HardSwishOptionsT *HardSwishOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new HardSwishOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void HardSwishOptions::UnPackTo(HardSwishOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset HardSwishOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const HardSwishOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateHardSwishOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateHardSwishOptions(flatbuffers::FlatBufferBuilder &_fbb, const HardSwishOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const HardSwishOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateHardSwishOptions( + _fbb); +} + +inline LogicalAndOptionsT *LogicalAndOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new LogicalAndOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void LogicalAndOptions::UnPackTo(LogicalAndOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset LogicalAndOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const LogicalAndOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateLogicalAndOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateLogicalAndOptions(flatbuffers::FlatBufferBuilder &_fbb, const LogicalAndOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const LogicalAndOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateLogicalAndOptions( + _fbb); +} + +inline LogicalNotOptionsT *LogicalNotOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new LogicalNotOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void LogicalNotOptions::UnPackTo(LogicalNotOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset LogicalNotOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const LogicalNotOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateLogicalNotOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateLogicalNotOptions(flatbuffers::FlatBufferBuilder &_fbb, const LogicalNotOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const LogicalNotOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateLogicalNotOptions( + _fbb); +} + +inline UnpackOptionsT *UnpackOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new UnpackOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void UnpackOptions::UnPackTo(UnpackOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = num(); + _o->num = _e; + } + { + auto _e = axis(); + _o->axis = _e; + } +} + +inline flatbuffers::Offset UnpackOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const UnpackOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateUnpackOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateUnpackOptions(flatbuffers::FlatBufferBuilder &_fbb, const UnpackOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const UnpackOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _num = _o->num; + auto _axis = _o->axis; + return tflite::CreateUnpackOptions( + _fbb, + _num, + _axis); +} + +inline FloorDivOptionsT *FloorDivOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new FloorDivOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void FloorDivOptions::UnPackTo(FloorDivOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset FloorDivOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const FloorDivOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateFloorDivOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateFloorDivOptions(flatbuffers::FlatBufferBuilder &_fbb, const FloorDivOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const FloorDivOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateFloorDivOptions( + _fbb); +} + +inline SquareOptionsT *SquareOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new SquareOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void SquareOptions::UnPackTo(SquareOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset SquareOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const SquareOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateSquareOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateSquareOptions(flatbuffers::FlatBufferBuilder &_fbb, const SquareOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const SquareOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateSquareOptions( + _fbb); +} + +inline ZerosLikeOptionsT *ZerosLikeOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new ZerosLikeOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void ZerosLikeOptions::UnPackTo(ZerosLikeOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset ZerosLikeOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const ZerosLikeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateZerosLikeOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateZerosLikeOptions(flatbuffers::FlatBufferBuilder &_fbb, const ZerosLikeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const ZerosLikeOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateZerosLikeOptions( + _fbb); +} + +inline FillOptionsT *FillOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new FillOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void FillOptions::UnPackTo(FillOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset FillOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const FillOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateFillOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateFillOptions(flatbuffers::FlatBufferBuilder &_fbb, const FillOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const FillOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateFillOptions( + _fbb); +} + +inline FloorModOptionsT *FloorModOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new FloorModOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void FloorModOptions::UnPackTo(FloorModOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset FloorModOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const FloorModOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateFloorModOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateFloorModOptions(flatbuffers::FlatBufferBuilder &_fbb, const FloorModOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const FloorModOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateFloorModOptions( + _fbb); +} + +inline RangeOptionsT *RangeOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new RangeOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void RangeOptions::UnPackTo(RangeOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset RangeOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const RangeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateRangeOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateRangeOptions(flatbuffers::FlatBufferBuilder &_fbb, const RangeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const RangeOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateRangeOptions( + _fbb); +} + +inline LeakyReluOptionsT *LeakyReluOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new LeakyReluOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void LeakyReluOptions::UnPackTo(LeakyReluOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = alpha(); + _o->alpha = _e; + } +} + +inline flatbuffers::Offset LeakyReluOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const LeakyReluOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateLeakyReluOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateLeakyReluOptions(flatbuffers::FlatBufferBuilder &_fbb, const LeakyReluOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const LeakyReluOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _alpha = _o->alpha; + return tflite::CreateLeakyReluOptions( + _fbb, + _alpha); +} + +inline SquaredDifferenceOptionsT *SquaredDifferenceOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new SquaredDifferenceOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void SquaredDifferenceOptions::UnPackTo(SquaredDifferenceOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset SquaredDifferenceOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const SquaredDifferenceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateSquaredDifferenceOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateSquaredDifferenceOptions(flatbuffers::FlatBufferBuilder &_fbb, const SquaredDifferenceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const SquaredDifferenceOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateSquaredDifferenceOptions( + _fbb); +} + +inline MirrorPadOptionsT *MirrorPadOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new MirrorPadOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void MirrorPadOptions::UnPackTo(MirrorPadOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = mode(); + _o->mode = _e; + } +} + +inline flatbuffers::Offset MirrorPadOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const MirrorPadOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateMirrorPadOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateMirrorPadOptions(flatbuffers::FlatBufferBuilder &_fbb, const MirrorPadOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const MirrorPadOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _mode = _o->mode; + return tflite::CreateMirrorPadOptions( + _fbb, + _mode); +} + +inline UniqueOptionsT *UniqueOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new UniqueOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void UniqueOptions::UnPackTo(UniqueOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = idx_out_type(); + _o->idx_out_type = _e; + } +} + +inline flatbuffers::Offset UniqueOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const UniqueOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateUniqueOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateUniqueOptions(flatbuffers::FlatBufferBuilder &_fbb, const UniqueOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const UniqueOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _idx_out_type = _o->idx_out_type; + return tflite::CreateUniqueOptions( + _fbb, + _idx_out_type); +} + +inline ReverseV2OptionsT *ReverseV2Options::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new ReverseV2OptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void ReverseV2Options::UnPackTo(ReverseV2OptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset ReverseV2Options::Pack(flatbuffers::FlatBufferBuilder &_fbb, const ReverseV2OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateReverseV2Options(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateReverseV2Options(flatbuffers::FlatBufferBuilder &_fbb, const ReverseV2OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const ReverseV2OptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateReverseV2Options( + _fbb); +} + +inline AddNOptionsT *AddNOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new AddNOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void AddNOptions::UnPackTo(AddNOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset AddNOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const AddNOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateAddNOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateAddNOptions(flatbuffers::FlatBufferBuilder &_fbb, const AddNOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const AddNOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateAddNOptions( + _fbb); +} + +inline GatherNdOptionsT *GatherNdOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new GatherNdOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void GatherNdOptions::UnPackTo(GatherNdOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset GatherNdOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const GatherNdOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateGatherNdOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateGatherNdOptions(flatbuffers::FlatBufferBuilder &_fbb, const GatherNdOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const GatherNdOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateGatherNdOptions( + _fbb); +} + +inline WhereOptionsT *WhereOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new WhereOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void WhereOptions::UnPackTo(WhereOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset WhereOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const WhereOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateWhereOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateWhereOptions(flatbuffers::FlatBufferBuilder &_fbb, const WhereOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const WhereOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateWhereOptions( + _fbb); +} + +inline ReverseSequenceOptionsT *ReverseSequenceOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new ReverseSequenceOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void ReverseSequenceOptions::UnPackTo(ReverseSequenceOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = seq_dim(); + _o->seq_dim = _e; + } + { + auto _e = batch_dim(); + _o->batch_dim = _e; + } +} + +inline flatbuffers::Offset ReverseSequenceOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const ReverseSequenceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateReverseSequenceOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateReverseSequenceOptions(flatbuffers::FlatBufferBuilder &_fbb, const ReverseSequenceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const ReverseSequenceOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _seq_dim = _o->seq_dim; + auto _batch_dim = _o->batch_dim; + return tflite::CreateReverseSequenceOptions( + _fbb, + _seq_dim, + _batch_dim); +} + +inline MatrixDiagOptionsT *MatrixDiagOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new MatrixDiagOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void MatrixDiagOptions::UnPackTo(MatrixDiagOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset MatrixDiagOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const MatrixDiagOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateMatrixDiagOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateMatrixDiagOptions(flatbuffers::FlatBufferBuilder &_fbb, const MatrixDiagOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const MatrixDiagOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateMatrixDiagOptions( + _fbb); +} + +inline QuantizeOptionsT *QuantizeOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new QuantizeOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void QuantizeOptions::UnPackTo(QuantizeOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset QuantizeOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const QuantizeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateQuantizeOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateQuantizeOptions(flatbuffers::FlatBufferBuilder &_fbb, const QuantizeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const QuantizeOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateQuantizeOptions( + _fbb); +} + +inline MatrixSetDiagOptionsT *MatrixSetDiagOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new MatrixSetDiagOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void MatrixSetDiagOptions::UnPackTo(MatrixSetDiagOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset MatrixSetDiagOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const MatrixSetDiagOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateMatrixSetDiagOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateMatrixSetDiagOptions(flatbuffers::FlatBufferBuilder &_fbb, const MatrixSetDiagOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const MatrixSetDiagOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateMatrixSetDiagOptions( + _fbb); +} + +inline IfOptionsT *IfOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new IfOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void IfOptions::UnPackTo(IfOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = then_subgraph_index(); + _o->then_subgraph_index = _e; + } + { + auto _e = else_subgraph_index(); + _o->else_subgraph_index = _e; + } +} + +inline flatbuffers::Offset IfOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const IfOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateIfOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateIfOptions(flatbuffers::FlatBufferBuilder &_fbb, const IfOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const IfOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _then_subgraph_index = _o->then_subgraph_index; + auto _else_subgraph_index = _o->else_subgraph_index; + return tflite::CreateIfOptions( + _fbb, + _then_subgraph_index, + _else_subgraph_index); +} + +inline CallOnceOptionsT *CallOnceOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new CallOnceOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void CallOnceOptions::UnPackTo(CallOnceOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = init_subgraph_index(); + _o->init_subgraph_index = _e; + } +} + +inline flatbuffers::Offset CallOnceOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const CallOnceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateCallOnceOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateCallOnceOptions(flatbuffers::FlatBufferBuilder &_fbb, const CallOnceOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const CallOnceOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _init_subgraph_index = _o->init_subgraph_index; + return tflite::CreateCallOnceOptions( + _fbb, + _init_subgraph_index); +} + +inline WhileOptionsT *WhileOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new WhileOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void WhileOptions::UnPackTo(WhileOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = cond_subgraph_index(); + _o->cond_subgraph_index = _e; + } + { + auto _e = body_subgraph_index(); + _o->body_subgraph_index = _e; + } +} + +inline flatbuffers::Offset WhileOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const WhileOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateWhileOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateWhileOptions(flatbuffers::FlatBufferBuilder &_fbb, const WhileOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const WhileOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _cond_subgraph_index = _o->cond_subgraph_index; + auto _body_subgraph_index = _o->body_subgraph_index; + return tflite::CreateWhileOptions( + _fbb, + _cond_subgraph_index, + _body_subgraph_index); +} + +inline NonMaxSuppressionV4OptionsT *NonMaxSuppressionV4Options::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new NonMaxSuppressionV4OptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void NonMaxSuppressionV4Options::UnPackTo(NonMaxSuppressionV4OptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset NonMaxSuppressionV4Options::Pack(flatbuffers::FlatBufferBuilder &_fbb, const NonMaxSuppressionV4OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateNonMaxSuppressionV4Options(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateNonMaxSuppressionV4Options(flatbuffers::FlatBufferBuilder &_fbb, const NonMaxSuppressionV4OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const NonMaxSuppressionV4OptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateNonMaxSuppressionV4Options( + _fbb); +} + +inline NonMaxSuppressionV5OptionsT *NonMaxSuppressionV5Options::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new NonMaxSuppressionV5OptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void NonMaxSuppressionV5Options::UnPackTo(NonMaxSuppressionV5OptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset NonMaxSuppressionV5Options::Pack(flatbuffers::FlatBufferBuilder &_fbb, const NonMaxSuppressionV5OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateNonMaxSuppressionV5Options(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateNonMaxSuppressionV5Options(flatbuffers::FlatBufferBuilder &_fbb, const NonMaxSuppressionV5OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const NonMaxSuppressionV5OptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateNonMaxSuppressionV5Options( + _fbb); +} + +inline ScatterNdOptionsT *ScatterNdOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new ScatterNdOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void ScatterNdOptions::UnPackTo(ScatterNdOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset ScatterNdOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const ScatterNdOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateScatterNdOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateScatterNdOptions(flatbuffers::FlatBufferBuilder &_fbb, const ScatterNdOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const ScatterNdOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateScatterNdOptions( + _fbb); +} + +inline SelectV2OptionsT *SelectV2Options::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new SelectV2OptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void SelectV2Options::UnPackTo(SelectV2OptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset SelectV2Options::Pack(flatbuffers::FlatBufferBuilder &_fbb, const SelectV2OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateSelectV2Options(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateSelectV2Options(flatbuffers::FlatBufferBuilder &_fbb, const SelectV2OptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const SelectV2OptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateSelectV2Options( + _fbb); +} + +inline DensifyOptionsT *DensifyOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new DensifyOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void DensifyOptions::UnPackTo(DensifyOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset DensifyOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const DensifyOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateDensifyOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateDensifyOptions(flatbuffers::FlatBufferBuilder &_fbb, const DensifyOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const DensifyOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateDensifyOptions( + _fbb); +} + +inline SegmentSumOptionsT *SegmentSumOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new SegmentSumOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void SegmentSumOptions::UnPackTo(SegmentSumOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset SegmentSumOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const SegmentSumOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateSegmentSumOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateSegmentSumOptions(flatbuffers::FlatBufferBuilder &_fbb, const SegmentSumOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const SegmentSumOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateSegmentSumOptions( + _fbb); +} + +inline BatchMatMulOptionsT *BatchMatMulOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new BatchMatMulOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void BatchMatMulOptions::UnPackTo(BatchMatMulOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = adj_x(); + _o->adj_x = _e; + } + { + auto _e = adj_y(); + _o->adj_y = _e; + } + { + auto _e = asymmetric_quantize_inputs(); + _o->asymmetric_quantize_inputs = _e; + } +} + +inline flatbuffers::Offset BatchMatMulOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const BatchMatMulOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateBatchMatMulOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateBatchMatMulOptions(flatbuffers::FlatBufferBuilder &_fbb, const BatchMatMulOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const BatchMatMulOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _adj_x = _o->adj_x; + auto _adj_y = _o->adj_y; + auto _asymmetric_quantize_inputs = _o->asymmetric_quantize_inputs; + return tflite::CreateBatchMatMulOptions( + _fbb, + _adj_x, + _adj_y, + _asymmetric_quantize_inputs); +} + +inline CumsumOptionsT *CumsumOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new CumsumOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void CumsumOptions::UnPackTo(CumsumOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = exclusive(); + _o->exclusive = _e; + } + { + auto _e = reverse(); + _o->reverse = _e; + } +} + +inline flatbuffers::Offset CumsumOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const CumsumOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateCumsumOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateCumsumOptions(flatbuffers::FlatBufferBuilder &_fbb, const CumsumOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const CumsumOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _exclusive = _o->exclusive; + auto _reverse = _o->reverse; + return tflite::CreateCumsumOptions( + _fbb, + _exclusive, + _reverse); +} + +inline BroadcastToOptionsT *BroadcastToOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new BroadcastToOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void BroadcastToOptions::UnPackTo(BroadcastToOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset BroadcastToOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const BroadcastToOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateBroadcastToOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateBroadcastToOptions(flatbuffers::FlatBufferBuilder &_fbb, const BroadcastToOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const BroadcastToOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateBroadcastToOptions( + _fbb); +} + +inline Rfft2dOptionsT *Rfft2dOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new Rfft2dOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void Rfft2dOptions::UnPackTo(Rfft2dOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset Rfft2dOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const Rfft2dOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateRfft2dOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateRfft2dOptions(flatbuffers::FlatBufferBuilder &_fbb, const Rfft2dOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const Rfft2dOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateRfft2dOptions( + _fbb); +} + +inline HashtableOptionsT *HashtableOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new HashtableOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void HashtableOptions::UnPackTo(HashtableOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = table_id(); + _o->table_id = _e; + } + { + auto _e = key_dtype(); + _o->key_dtype = _e; + } + { + auto _e = value_dtype(); + _o->value_dtype = _e; + } +} + +inline flatbuffers::Offset HashtableOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const HashtableOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateHashtableOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateHashtableOptions(flatbuffers::FlatBufferBuilder &_fbb, const HashtableOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const HashtableOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _table_id = _o->table_id; + auto _key_dtype = _o->key_dtype; + auto _value_dtype = _o->value_dtype; + return tflite::CreateHashtableOptions( + _fbb, + _table_id, + _key_dtype, + _value_dtype); +} + +inline HashtableFindOptionsT *HashtableFindOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new HashtableFindOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void HashtableFindOptions::UnPackTo(HashtableFindOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset HashtableFindOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const HashtableFindOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateHashtableFindOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateHashtableFindOptions(flatbuffers::FlatBufferBuilder &_fbb, const HashtableFindOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const HashtableFindOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateHashtableFindOptions( + _fbb); +} + +inline HashtableImportOptionsT *HashtableImportOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new HashtableImportOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void HashtableImportOptions::UnPackTo(HashtableImportOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset HashtableImportOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const HashtableImportOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateHashtableImportOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateHashtableImportOptions(flatbuffers::FlatBufferBuilder &_fbb, const HashtableImportOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const HashtableImportOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateHashtableImportOptions( + _fbb); +} + +inline HashtableSizeOptionsT *HashtableSizeOptions::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new HashtableSizeOptionsT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void HashtableSizeOptions::UnPackTo(HashtableSizeOptionsT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; +} + +inline flatbuffers::Offset HashtableSizeOptions::Pack(flatbuffers::FlatBufferBuilder &_fbb, const HashtableSizeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateHashtableSizeOptions(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateHashtableSizeOptions(flatbuffers::FlatBufferBuilder &_fbb, const HashtableSizeOptionsT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const HashtableSizeOptionsT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + return tflite::CreateHashtableSizeOptions( + _fbb); +} + +inline OperatorCodeT *OperatorCode::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new OperatorCodeT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void OperatorCode::UnPackTo(OperatorCodeT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = deprecated_builtin_code(); + _o->deprecated_builtin_code = _e; + } + { + auto _e = custom_code(); + if (_e) + _o->custom_code = _e->str(); + } + { + auto _e = version(); + _o->version = _e; + } + { + auto _e = builtin_code(); + _o->builtin_code = _e; + } +} + +inline flatbuffers::Offset OperatorCode::Pack(flatbuffers::FlatBufferBuilder &_fbb, const OperatorCodeT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateOperatorCode(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateOperatorCode(flatbuffers::FlatBufferBuilder &_fbb, const OperatorCodeT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const OperatorCodeT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _deprecated_builtin_code = _o->deprecated_builtin_code; + auto _custom_code = _o->custom_code.empty() ? 0 : _fbb.CreateString(_o->custom_code); + auto _version = _o->version; + auto _builtin_code = _o->builtin_code; + return tflite::CreateOperatorCode( + _fbb, + _deprecated_builtin_code, + _custom_code, + _version, + _builtin_code); +} + +inline OperatorT *Operator::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new OperatorT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void Operator::UnPackTo(OperatorT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = opcode_index(); + _o->opcode_index = _e; + } + { + auto _e = inputs(); + if (_e) { + _o->inputs.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->inputs[_i] = _e->Get(_i); + } + } + } + { + auto _e = outputs(); + if (_e) { + _o->outputs.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->outputs[_i] = _e->Get(_i); + } + } + } + { + auto _e = builtin_options_type(); + _o->builtin_options.type = _e; + } + { + auto _e = builtin_options(); + if (_e) + _o->builtin_options.value = tflite::BuiltinOptionsUnion::UnPack(_e, builtin_options_type(), _resolver); + } + { + auto _e = custom_options(); + if (_e) { + _o->custom_options.resize(_e->size()); + std::copy(_e->begin(), _e->end(), _o->custom_options.begin()); + } + } + { + auto _e = custom_options_format(); + _o->custom_options_format = _e; + } + { + auto _e = mutating_variable_inputs(); + if (_e) { + _o->mutating_variable_inputs.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->mutating_variable_inputs[_i] = _e->Get(_i) != 0; + } + } + } + { + auto _e = intermediates(); + if (_e) { + _o->intermediates.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->intermediates[_i] = _e->Get(_i); + } + } + } +} + +inline flatbuffers::Offset Operator::Pack(flatbuffers::FlatBufferBuilder &_fbb, const OperatorT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateOperator(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateOperator(flatbuffers::FlatBufferBuilder &_fbb, const OperatorT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const OperatorT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _opcode_index = _o->opcode_index; + auto _inputs = _o->inputs.size() ? _fbb.CreateVector(_o->inputs) : 0; + auto _outputs = _o->outputs.size() ? _fbb.CreateVector(_o->outputs) : 0; + auto _builtin_options_type = _o->builtin_options.type; + auto _builtin_options = _o->builtin_options.Pack(_fbb); + auto _custom_options = _o->custom_options.size() ? _fbb.CreateVector(_o->custom_options) : 0; + auto _custom_options_format = _o->custom_options_format; + auto _mutating_variable_inputs = _o->mutating_variable_inputs.size() ? _fbb.CreateVector(_o->mutating_variable_inputs) : 0; + auto _intermediates = _o->intermediates.size() ? _fbb.CreateVector(_o->intermediates) : 0; + return tflite::CreateOperator( + _fbb, + _opcode_index, + _inputs, + _outputs, + _builtin_options_type, + _builtin_options, + _custom_options, + _custom_options_format, + _mutating_variable_inputs, + _intermediates); +} + +inline SubGraphT *SubGraph::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new SubGraphT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void SubGraph::UnPackTo(SubGraphT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = tensors(); + if (_e) { + _o->tensors.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->tensors[_i] = std::unique_ptr(_e->Get(_i)->UnPack(_resolver)); + } + } + } + { + auto _e = inputs(); + if (_e) { + _o->inputs.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->inputs[_i] = _e->Get(_i); + } + } + } + { + auto _e = outputs(); + if (_e) { + _o->outputs.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->outputs[_i] = _e->Get(_i); + } + } + } + { + auto _e = operators(); + if (_e) { + _o->operators.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->operators[_i] = std::unique_ptr(_e->Get(_i)->UnPack(_resolver)); + } + } + } + { + auto _e = name(); + if (_e) + _o->name = _e->str(); + } +} + +inline flatbuffers::Offset SubGraph::Pack(flatbuffers::FlatBufferBuilder &_fbb, const SubGraphT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateSubGraph(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateSubGraph(flatbuffers::FlatBufferBuilder &_fbb, const SubGraphT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const SubGraphT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _tensors = _o->tensors.size() ? _fbb.CreateVector >( + _o->tensors.size(), [](size_t i, _VectorArgs *__va) { return CreateTensor(*__va->__fbb, __va->__o->tensors[i].get(), __va->__rehasher); }, &_va) : + 0; + auto _inputs = _o->inputs.size() ? _fbb.CreateVector(_o->inputs) : 0; + auto _outputs = _o->outputs.size() ? _fbb.CreateVector(_o->outputs) : 0; + auto _operators = _o->operators.size() ? _fbb.CreateVector >( + _o->operators.size(), [](size_t i, _VectorArgs *__va) { return CreateOperator(*__va->__fbb, __va->__o->operators[i].get(), __va->__rehasher); }, &_va) : + 0; + auto _name = _o->name.empty() ? 0 : _fbb.CreateString(_o->name); + return tflite::CreateSubGraph( + _fbb, + _tensors, + _inputs, + _outputs, + _operators, + _name); +} + +inline BufferT *Buffer::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new BufferT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void Buffer::UnPackTo(BufferT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = data(); + if (_e) { + _o->data.resize(_e->size()); + std::copy(_e->begin(), _e->end(), _o->data.begin()); + } + } +} + +inline flatbuffers::Offset Buffer::Pack(flatbuffers::FlatBufferBuilder &_fbb, const BufferT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateBuffer(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateBuffer(flatbuffers::FlatBufferBuilder &_fbb, const BufferT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const BufferT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + _fbb.ForceVectorAlignment(_o->data.size(), sizeof(uint8_t), 16); + auto _data = _o->data.size() ? _fbb.CreateVector(_o->data) : 0; + return tflite::CreateBuffer( + _fbb, + _data); +} + +inline MetadataT *Metadata::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new MetadataT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void Metadata::UnPackTo(MetadataT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = name(); + if (_e) + _o->name = _e->str(); + } + { + auto _e = buffer(); + _o->buffer = _e; + } +} + +inline flatbuffers::Offset Metadata::Pack(flatbuffers::FlatBufferBuilder &_fbb, const MetadataT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateMetadata(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateMetadata(flatbuffers::FlatBufferBuilder &_fbb, const MetadataT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const MetadataT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _name = _o->name.empty() ? 0 : _fbb.CreateString(_o->name); + auto _buffer = _o->buffer; + return tflite::CreateMetadata( + _fbb, + _name, + _buffer); +} + +inline TensorMapT *TensorMap::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new TensorMapT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void TensorMap::UnPackTo(TensorMapT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = name(); + if (_e) + _o->name = _e->str(); + } + { + auto _e = tensor_index(); + _o->tensor_index = _e; + } +} + +inline flatbuffers::Offset TensorMap::Pack(flatbuffers::FlatBufferBuilder &_fbb, const TensorMapT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateTensorMap(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateTensorMap(flatbuffers::FlatBufferBuilder &_fbb, const TensorMapT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const TensorMapT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _name = _o->name.empty() ? 0 : _fbb.CreateString(_o->name); + auto _tensor_index = _o->tensor_index; + return tflite::CreateTensorMap( + _fbb, + _name, + _tensor_index); +} + +inline SignatureDefT *SignatureDef::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new SignatureDefT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void SignatureDef::UnPackTo(SignatureDefT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = inputs(); + if (_e) { + _o->inputs.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->inputs[_i] = std::unique_ptr(_e->Get(_i)->UnPack(_resolver)); + } + } + } + { + auto _e = outputs(); + if (_e) { + _o->outputs.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->outputs[_i] = std::unique_ptr(_e->Get(_i)->UnPack(_resolver)); + } + } + } + { + auto _e = method_name(); + if (_e) + _o->method_name = _e->str(); + } + { + auto _e = key(); + if (_e) + _o->key = _e->str(); + } +} + +inline flatbuffers::Offset SignatureDef::Pack(flatbuffers::FlatBufferBuilder &_fbb, const SignatureDefT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateSignatureDef(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateSignatureDef(flatbuffers::FlatBufferBuilder &_fbb, const SignatureDefT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const SignatureDefT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _inputs = _o->inputs.size() ? _fbb.CreateVector >( + _o->inputs.size(), [](size_t i, _VectorArgs *__va) { return CreateTensorMap(*__va->__fbb, __va->__o->inputs[i].get(), __va->__rehasher); }, &_va) : + 0; + auto _outputs = _o->outputs.size() ? _fbb.CreateVector >( + _o->outputs.size(), [](size_t i, _VectorArgs *__va) { return CreateTensorMap(*__va->__fbb, __va->__o->outputs[i].get(), __va->__rehasher); }, &_va) : + 0; + auto _method_name = _o->method_name.empty() ? 0 : _fbb.CreateString(_o->method_name); + auto _key = _o->key.empty() ? 0 : _fbb.CreateString(_o->key); + return tflite::CreateSignatureDef( + _fbb, + _inputs, + _outputs, + _method_name, + _key); +} + +inline ModelT *Model::UnPack(const flatbuffers::resolver_function_t *_resolver) const +{ + auto _o = new ModelT(); + UnPackTo(_o, _resolver); + return _o; +} + +inline void Model::UnPackTo(ModelT *_o, const flatbuffers::resolver_function_t *_resolver) const +{ + (void)_o; + (void)_resolver; + { + auto _e = version(); + _o->version = _e; + } + { + auto _e = operator_codes(); + if (_e) { + _o->operator_codes.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->operator_codes[_i] = std::unique_ptr(_e->Get(_i)->UnPack(_resolver)); + } + } + } + { + auto _e = subgraphs(); + if (_e) { + _o->subgraphs.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->subgraphs[_i] = std::unique_ptr(_e->Get(_i)->UnPack(_resolver)); + } + } + } + { + auto _e = description(); + if (_e) + _o->description = _e->str(); + } + { + auto _e = buffers(); + if (_e) { + _o->buffers.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->buffers[_i] = std::unique_ptr(_e->Get(_i)->UnPack(_resolver)); + } + } + } + { + auto _e = metadata_buffer(); + if (_e) { + _o->metadata_buffer.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->metadata_buffer[_i] = _e->Get(_i); + } + } + } + { + auto _e = metadata(); + if (_e) { + _o->metadata.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->metadata[_i] = std::unique_ptr(_e->Get(_i)->UnPack(_resolver)); + } + } + } + { + auto _e = signature_defs(); + if (_e) { + _o->signature_defs.resize(_e->size()); + for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { + _o->signature_defs[_i] = std::unique_ptr(_e->Get(_i)->UnPack(_resolver)); + } + } + } +} + +inline flatbuffers::Offset Model::Pack(flatbuffers::FlatBufferBuilder &_fbb, const ModelT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + return CreateModel(_fbb, _o, _rehasher); +} + +inline flatbuffers::Offset CreateModel(flatbuffers::FlatBufferBuilder &_fbb, const ModelT *_o, const flatbuffers::rehasher_function_t *_rehasher) +{ + (void)_rehasher; + (void)_o; + struct _VectorArgs { + flatbuffers::FlatBufferBuilder *__fbb; + const ModelT *__o; + const flatbuffers::rehasher_function_t *__rehasher; + } _va = { &_fbb, _o, _rehasher }; + (void)_va; + auto _version = _o->version; + auto _operator_codes = _o->operator_codes.size() ? _fbb.CreateVector >( + _o->operator_codes.size(), [](size_t i, _VectorArgs *__va) { return CreateOperatorCode(*__va->__fbb, __va->__o->operator_codes[i].get(), __va->__rehasher); }, &_va) : + 0; + auto _subgraphs = _o->subgraphs.size() ? _fbb.CreateVector >( + _o->subgraphs.size(), [](size_t i, _VectorArgs *__va) { return CreateSubGraph(*__va->__fbb, __va->__o->subgraphs[i].get(), __va->__rehasher); }, &_va) : + 0; + auto _description = _o->description.empty() ? 0 : _fbb.CreateString(_o->description); + auto _buffers = _o->buffers.size() ? _fbb.CreateVector >( + _o->buffers.size(), [](size_t i, _VectorArgs *__va) { return CreateBuffer(*__va->__fbb, __va->__o->buffers[i].get(), __va->__rehasher); }, &_va) : + 0; + auto _metadata_buffer = _o->metadata_buffer.size() ? _fbb.CreateVector(_o->metadata_buffer) : 0; + auto _metadata = _o->metadata.size() ? _fbb.CreateVector >( + _o->metadata.size(), [](size_t i, _VectorArgs *__va) { return CreateMetadata(*__va->__fbb, __va->__o->metadata[i].get(), __va->__rehasher); }, &_va) : + 0; + auto _signature_defs = _o->signature_defs.size() ? _fbb.CreateVector >( + _o->signature_defs.size(), [](size_t i, _VectorArgs *__va) { return CreateSignatureDef(*__va->__fbb, __va->__o->signature_defs[i].get(), __va->__rehasher); }, &_va) : + 0; + return tflite::CreateModel( + _fbb, + _version, + _operator_codes, + _subgraphs, + _description, + _buffers, + _metadata_buffer, + _metadata, + _signature_defs); +} + +inline bool VerifyQuantizationDetails(flatbuffers::Verifier &verifier, const void *obj, QuantizationDetails type) +{ + switch (type) { + case QuantizationDetails_NONE: { + return true; + } + case QuantizationDetails_CustomQuantization: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + default: + return true; + } +} + +inline bool VerifyQuantizationDetailsVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector > *values, const flatbuffers::Vector *types) +{ + if (!values || !types) + return !values && !types; + if (values->size() != types->size()) + return false; + for (flatbuffers::uoffset_t i = 0; i < values->size(); ++i) { + if (!VerifyQuantizationDetails( + verifier, values->Get(i), types->GetEnum(i))) { + return false; + } + } + return true; +} + +inline void *QuantizationDetailsUnion::UnPack(const void *obj, QuantizationDetails type, const flatbuffers::resolver_function_t *resolver) +{ + switch (type) { + case QuantizationDetails_CustomQuantization: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + default: + return nullptr; + } +} + +inline flatbuffers::Offset QuantizationDetailsUnion::Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher) const +{ + switch (type) { + case QuantizationDetails_CustomQuantization: { + auto ptr = reinterpret_cast(value); + return CreateCustomQuantization(_fbb, ptr, _rehasher).Union(); + } + default: + return 0; + } +} + +inline QuantizationDetailsUnion::QuantizationDetailsUnion(const QuantizationDetailsUnion &u) FLATBUFFERS_NOEXCEPT : type(u.type), value(nullptr) +{ + switch (type) { + case QuantizationDetails_CustomQuantization: { + value = new tflite::CustomQuantizationT(*reinterpret_cast(u.value)); + break; + } + default: + break; + } +} + +inline void QuantizationDetailsUnion::Reset() +{ + switch (type) { + case QuantizationDetails_CustomQuantization: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + default: + break; + } + value = nullptr; + type = QuantizationDetails_NONE; +} + +inline bool VerifySparseIndexVector(flatbuffers::Verifier &verifier, const void *obj, SparseIndexVector type) +{ + switch (type) { + case SparseIndexVector_NONE: { + return true; + } + case SparseIndexVector_Int32Vector: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case SparseIndexVector_Uint16Vector: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case SparseIndexVector_Uint8Vector: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + default: + return true; + } +} + +inline bool VerifySparseIndexVectorVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector > *values, const flatbuffers::Vector *types) +{ + if (!values || !types) + return !values && !types; + if (values->size() != types->size()) + return false; + for (flatbuffers::uoffset_t i = 0; i < values->size(); ++i) { + if (!VerifySparseIndexVector( + verifier, values->Get(i), types->GetEnum(i))) { + return false; + } + } + return true; +} + +inline void *SparseIndexVectorUnion::UnPack(const void *obj, SparseIndexVector type, const flatbuffers::resolver_function_t *resolver) +{ + switch (type) { + case SparseIndexVector_Int32Vector: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case SparseIndexVector_Uint16Vector: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case SparseIndexVector_Uint8Vector: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + default: + return nullptr; + } +} + +inline flatbuffers::Offset SparseIndexVectorUnion::Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher) const +{ + switch (type) { + case SparseIndexVector_Int32Vector: { + auto ptr = reinterpret_cast(value); + return CreateInt32Vector(_fbb, ptr, _rehasher).Union(); + } + case SparseIndexVector_Uint16Vector: { + auto ptr = reinterpret_cast(value); + return CreateUint16Vector(_fbb, ptr, _rehasher).Union(); + } + case SparseIndexVector_Uint8Vector: { + auto ptr = reinterpret_cast(value); + return CreateUint8Vector(_fbb, ptr, _rehasher).Union(); + } + default: + return 0; + } +} + +inline SparseIndexVectorUnion::SparseIndexVectorUnion(const SparseIndexVectorUnion &u) FLATBUFFERS_NOEXCEPT : type(u.type), value(nullptr) +{ + switch (type) { + case SparseIndexVector_Int32Vector: { + value = new tflite::Int32VectorT(*reinterpret_cast(u.value)); + break; + } + case SparseIndexVector_Uint16Vector: { + value = new tflite::Uint16VectorT(*reinterpret_cast(u.value)); + break; + } + case SparseIndexVector_Uint8Vector: { + value = new tflite::Uint8VectorT(*reinterpret_cast(u.value)); + break; + } + default: + break; + } +} + +inline void SparseIndexVectorUnion::Reset() +{ + switch (type) { + case SparseIndexVector_Int32Vector: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case SparseIndexVector_Uint16Vector: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case SparseIndexVector_Uint8Vector: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + default: + break; + } + value = nullptr; + type = SparseIndexVector_NONE; +} + +inline bool VerifyBuiltinOptions(flatbuffers::Verifier &verifier, const void *obj, BuiltinOptions type) +{ + switch (type) { + case BuiltinOptions_NONE: { + return true; + } + case BuiltinOptions_Conv2DOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_DepthwiseConv2DOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_ConcatEmbeddingsOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_LSHProjectionOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_Pool2DOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_SVDFOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_RNNOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_FullyConnectedOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_SoftmaxOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_ConcatenationOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_AddOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_L2NormOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_LocalResponseNormalizationOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_LSTMOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_ResizeBilinearOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_CallOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_ReshapeOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_SkipGramOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_SpaceToDepthOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_EmbeddingLookupSparseOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_MulOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_PadOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_GatherOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_BatchToSpaceNDOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_SpaceToBatchNDOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_TransposeOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_ReducerOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_SubOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_DivOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_SqueezeOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_SequenceRNNOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_StridedSliceOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_ExpOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_TopKV2Options: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_SplitOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_LogSoftmaxOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_CastOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_DequantizeOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_MaximumMinimumOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_ArgMaxOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_LessOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_NegOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_PadV2Options: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_GreaterOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_GreaterEqualOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_LessEqualOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_SelectOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_SliceOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_TransposeConvOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_SparseToDenseOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_TileOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_ExpandDimsOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_EqualOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_NotEqualOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_ShapeOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_PowOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_ArgMinOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_FakeQuantOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_PackOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_LogicalOrOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_OneHotOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_LogicalAndOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_LogicalNotOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_UnpackOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_FloorDivOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_SquareOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_ZerosLikeOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_FillOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_BidirectionalSequenceLSTMOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_BidirectionalSequenceRNNOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_UnidirectionalSequenceLSTMOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_FloorModOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_RangeOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_ResizeNearestNeighborOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_LeakyReluOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_SquaredDifferenceOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_MirrorPadOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_AbsOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_SplitVOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_UniqueOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_ReverseV2Options: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_AddNOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_GatherNdOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_CosOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_WhereOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_RankOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_ReverseSequenceOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_MatrixDiagOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_QuantizeOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_MatrixSetDiagOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_HardSwishOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_IfOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_WhileOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_DepthToSpaceOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_NonMaxSuppressionV4Options: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_NonMaxSuppressionV5Options: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_ScatterNdOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_SelectV2Options: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_DensifyOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_SegmentSumOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_BatchMatMulOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_CumsumOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_CallOnceOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_BroadcastToOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_Rfft2dOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_Conv3DOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_HashtableOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_HashtableFindOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_HashtableImportOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + case BuiltinOptions_HashtableSizeOptions: { + auto ptr = reinterpret_cast(obj); + return verifier.VerifyTable(ptr); + } + default: + return true; + } +} + +inline bool VerifyBuiltinOptionsVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector > *values, const flatbuffers::Vector *types) +{ + if (!values || !types) + return !values && !types; + if (values->size() != types->size()) + return false; + for (flatbuffers::uoffset_t i = 0; i < values->size(); ++i) { + if (!VerifyBuiltinOptions( + verifier, values->Get(i), types->GetEnum(i))) { + return false; + } + } + return true; +} + +inline void *BuiltinOptionsUnion::UnPack(const void *obj, BuiltinOptions type, const flatbuffers::resolver_function_t *resolver) +{ + switch (type) { + case BuiltinOptions_Conv2DOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_DepthwiseConv2DOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_ConcatEmbeddingsOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_LSHProjectionOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_Pool2DOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_SVDFOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_RNNOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_FullyConnectedOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_SoftmaxOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_ConcatenationOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_AddOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_L2NormOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_LocalResponseNormalizationOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_LSTMOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_ResizeBilinearOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_CallOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_ReshapeOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_SkipGramOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_SpaceToDepthOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_EmbeddingLookupSparseOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_MulOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_PadOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_GatherOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_BatchToSpaceNDOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_SpaceToBatchNDOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_TransposeOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_ReducerOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_SubOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_DivOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_SqueezeOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_SequenceRNNOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_StridedSliceOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_ExpOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_TopKV2Options: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_SplitOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_LogSoftmaxOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_CastOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_DequantizeOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_MaximumMinimumOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_ArgMaxOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_LessOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_NegOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_PadV2Options: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_GreaterOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_GreaterEqualOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_LessEqualOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_SelectOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_SliceOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_TransposeConvOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_SparseToDenseOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_TileOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_ExpandDimsOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_EqualOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_NotEqualOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_ShapeOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_PowOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_ArgMinOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_FakeQuantOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_PackOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_LogicalOrOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_OneHotOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_LogicalAndOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_LogicalNotOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_UnpackOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_FloorDivOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_SquareOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_ZerosLikeOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_FillOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_BidirectionalSequenceLSTMOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_BidirectionalSequenceRNNOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_UnidirectionalSequenceLSTMOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_FloorModOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_RangeOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_ResizeNearestNeighborOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_LeakyReluOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_SquaredDifferenceOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_MirrorPadOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_AbsOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_SplitVOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_UniqueOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_ReverseV2Options: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_AddNOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_GatherNdOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_CosOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_WhereOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_RankOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_ReverseSequenceOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_MatrixDiagOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_QuantizeOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_MatrixSetDiagOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_HardSwishOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_IfOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_WhileOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_DepthToSpaceOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_NonMaxSuppressionV4Options: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_NonMaxSuppressionV5Options: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_ScatterNdOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_SelectV2Options: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_DensifyOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_SegmentSumOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_BatchMatMulOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_CumsumOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_CallOnceOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_BroadcastToOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_Rfft2dOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_Conv3DOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_HashtableOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_HashtableFindOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_HashtableImportOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + case BuiltinOptions_HashtableSizeOptions: { + auto ptr = reinterpret_cast(obj); + return ptr->UnPack(resolver); + } + default: + return nullptr; + } +} + +inline flatbuffers::Offset BuiltinOptionsUnion::Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher) const +{ + switch (type) { + case BuiltinOptions_Conv2DOptions: { + auto ptr = reinterpret_cast(value); + return CreateConv2DOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_DepthwiseConv2DOptions: { + auto ptr = reinterpret_cast(value); + return CreateDepthwiseConv2DOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_ConcatEmbeddingsOptions: { + auto ptr = reinterpret_cast(value); + return CreateConcatEmbeddingsOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_LSHProjectionOptions: { + auto ptr = reinterpret_cast(value); + return CreateLSHProjectionOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_Pool2DOptions: { + auto ptr = reinterpret_cast(value); + return CreatePool2DOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_SVDFOptions: { + auto ptr = reinterpret_cast(value); + return CreateSVDFOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_RNNOptions: { + auto ptr = reinterpret_cast(value); + return CreateRNNOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_FullyConnectedOptions: { + auto ptr = reinterpret_cast(value); + return CreateFullyConnectedOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_SoftmaxOptions: { + auto ptr = reinterpret_cast(value); + return CreateSoftmaxOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_ConcatenationOptions: { + auto ptr = reinterpret_cast(value); + return CreateConcatenationOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_AddOptions: { + auto ptr = reinterpret_cast(value); + return CreateAddOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_L2NormOptions: { + auto ptr = reinterpret_cast(value); + return CreateL2NormOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_LocalResponseNormalizationOptions: { + auto ptr = reinterpret_cast(value); + return CreateLocalResponseNormalizationOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_LSTMOptions: { + auto ptr = reinterpret_cast(value); + return CreateLSTMOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_ResizeBilinearOptions: { + auto ptr = reinterpret_cast(value); + return CreateResizeBilinearOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_CallOptions: { + auto ptr = reinterpret_cast(value); + return CreateCallOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_ReshapeOptions: { + auto ptr = reinterpret_cast(value); + return CreateReshapeOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_SkipGramOptions: { + auto ptr = reinterpret_cast(value); + return CreateSkipGramOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_SpaceToDepthOptions: { + auto ptr = reinterpret_cast(value); + return CreateSpaceToDepthOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_EmbeddingLookupSparseOptions: { + auto ptr = reinterpret_cast(value); + return CreateEmbeddingLookupSparseOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_MulOptions: { + auto ptr = reinterpret_cast(value); + return CreateMulOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_PadOptions: { + auto ptr = reinterpret_cast(value); + return CreatePadOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_GatherOptions: { + auto ptr = reinterpret_cast(value); + return CreateGatherOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_BatchToSpaceNDOptions: { + auto ptr = reinterpret_cast(value); + return CreateBatchToSpaceNDOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_SpaceToBatchNDOptions: { + auto ptr = reinterpret_cast(value); + return CreateSpaceToBatchNDOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_TransposeOptions: { + auto ptr = reinterpret_cast(value); + return CreateTransposeOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_ReducerOptions: { + auto ptr = reinterpret_cast(value); + return CreateReducerOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_SubOptions: { + auto ptr = reinterpret_cast(value); + return CreateSubOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_DivOptions: { + auto ptr = reinterpret_cast(value); + return CreateDivOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_SqueezeOptions: { + auto ptr = reinterpret_cast(value); + return CreateSqueezeOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_SequenceRNNOptions: { + auto ptr = reinterpret_cast(value); + return CreateSequenceRNNOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_StridedSliceOptions: { + auto ptr = reinterpret_cast(value); + return CreateStridedSliceOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_ExpOptions: { + auto ptr = reinterpret_cast(value); + return CreateExpOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_TopKV2Options: { + auto ptr = reinterpret_cast(value); + return CreateTopKV2Options(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_SplitOptions: { + auto ptr = reinterpret_cast(value); + return CreateSplitOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_LogSoftmaxOptions: { + auto ptr = reinterpret_cast(value); + return CreateLogSoftmaxOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_CastOptions: { + auto ptr = reinterpret_cast(value); + return CreateCastOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_DequantizeOptions: { + auto ptr = reinterpret_cast(value); + return CreateDequantizeOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_MaximumMinimumOptions: { + auto ptr = reinterpret_cast(value); + return CreateMaximumMinimumOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_ArgMaxOptions: { + auto ptr = reinterpret_cast(value); + return CreateArgMaxOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_LessOptions: { + auto ptr = reinterpret_cast(value); + return CreateLessOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_NegOptions: { + auto ptr = reinterpret_cast(value); + return CreateNegOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_PadV2Options: { + auto ptr = reinterpret_cast(value); + return CreatePadV2Options(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_GreaterOptions: { + auto ptr = reinterpret_cast(value); + return CreateGreaterOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_GreaterEqualOptions: { + auto ptr = reinterpret_cast(value); + return CreateGreaterEqualOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_LessEqualOptions: { + auto ptr = reinterpret_cast(value); + return CreateLessEqualOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_SelectOptions: { + auto ptr = reinterpret_cast(value); + return CreateSelectOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_SliceOptions: { + auto ptr = reinterpret_cast(value); + return CreateSliceOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_TransposeConvOptions: { + auto ptr = reinterpret_cast(value); + return CreateTransposeConvOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_SparseToDenseOptions: { + auto ptr = reinterpret_cast(value); + return CreateSparseToDenseOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_TileOptions: { + auto ptr = reinterpret_cast(value); + return CreateTileOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_ExpandDimsOptions: { + auto ptr = reinterpret_cast(value); + return CreateExpandDimsOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_EqualOptions: { + auto ptr = reinterpret_cast(value); + return CreateEqualOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_NotEqualOptions: { + auto ptr = reinterpret_cast(value); + return CreateNotEqualOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_ShapeOptions: { + auto ptr = reinterpret_cast(value); + return CreateShapeOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_PowOptions: { + auto ptr = reinterpret_cast(value); + return CreatePowOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_ArgMinOptions: { + auto ptr = reinterpret_cast(value); + return CreateArgMinOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_FakeQuantOptions: { + auto ptr = reinterpret_cast(value); + return CreateFakeQuantOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_PackOptions: { + auto ptr = reinterpret_cast(value); + return CreatePackOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_LogicalOrOptions: { + auto ptr = reinterpret_cast(value); + return CreateLogicalOrOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_OneHotOptions: { + auto ptr = reinterpret_cast(value); + return CreateOneHotOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_LogicalAndOptions: { + auto ptr = reinterpret_cast(value); + return CreateLogicalAndOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_LogicalNotOptions: { + auto ptr = reinterpret_cast(value); + return CreateLogicalNotOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_UnpackOptions: { + auto ptr = reinterpret_cast(value); + return CreateUnpackOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_FloorDivOptions: { + auto ptr = reinterpret_cast(value); + return CreateFloorDivOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_SquareOptions: { + auto ptr = reinterpret_cast(value); + return CreateSquareOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_ZerosLikeOptions: { + auto ptr = reinterpret_cast(value); + return CreateZerosLikeOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_FillOptions: { + auto ptr = reinterpret_cast(value); + return CreateFillOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_BidirectionalSequenceLSTMOptions: { + auto ptr = reinterpret_cast(value); + return CreateBidirectionalSequenceLSTMOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_BidirectionalSequenceRNNOptions: { + auto ptr = reinterpret_cast(value); + return CreateBidirectionalSequenceRNNOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_UnidirectionalSequenceLSTMOptions: { + auto ptr = reinterpret_cast(value); + return CreateUnidirectionalSequenceLSTMOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_FloorModOptions: { + auto ptr = reinterpret_cast(value); + return CreateFloorModOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_RangeOptions: { + auto ptr = reinterpret_cast(value); + return CreateRangeOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_ResizeNearestNeighborOptions: { + auto ptr = reinterpret_cast(value); + return CreateResizeNearestNeighborOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_LeakyReluOptions: { + auto ptr = reinterpret_cast(value); + return CreateLeakyReluOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_SquaredDifferenceOptions: { + auto ptr = reinterpret_cast(value); + return CreateSquaredDifferenceOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_MirrorPadOptions: { + auto ptr = reinterpret_cast(value); + return CreateMirrorPadOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_AbsOptions: { + auto ptr = reinterpret_cast(value); + return CreateAbsOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_SplitVOptions: { + auto ptr = reinterpret_cast(value); + return CreateSplitVOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_UniqueOptions: { + auto ptr = reinterpret_cast(value); + return CreateUniqueOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_ReverseV2Options: { + auto ptr = reinterpret_cast(value); + return CreateReverseV2Options(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_AddNOptions: { + auto ptr = reinterpret_cast(value); + return CreateAddNOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_GatherNdOptions: { + auto ptr = reinterpret_cast(value); + return CreateGatherNdOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_CosOptions: { + auto ptr = reinterpret_cast(value); + return CreateCosOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_WhereOptions: { + auto ptr = reinterpret_cast(value); + return CreateWhereOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_RankOptions: { + auto ptr = reinterpret_cast(value); + return CreateRankOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_ReverseSequenceOptions: { + auto ptr = reinterpret_cast(value); + return CreateReverseSequenceOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_MatrixDiagOptions: { + auto ptr = reinterpret_cast(value); + return CreateMatrixDiagOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_QuantizeOptions: { + auto ptr = reinterpret_cast(value); + return CreateQuantizeOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_MatrixSetDiagOptions: { + auto ptr = reinterpret_cast(value); + return CreateMatrixSetDiagOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_HardSwishOptions: { + auto ptr = reinterpret_cast(value); + return CreateHardSwishOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_IfOptions: { + auto ptr = reinterpret_cast(value); + return CreateIfOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_WhileOptions: { + auto ptr = reinterpret_cast(value); + return CreateWhileOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_DepthToSpaceOptions: { + auto ptr = reinterpret_cast(value); + return CreateDepthToSpaceOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_NonMaxSuppressionV4Options: { + auto ptr = reinterpret_cast(value); + return CreateNonMaxSuppressionV4Options(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_NonMaxSuppressionV5Options: { + auto ptr = reinterpret_cast(value); + return CreateNonMaxSuppressionV5Options(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_ScatterNdOptions: { + auto ptr = reinterpret_cast(value); + return CreateScatterNdOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_SelectV2Options: { + auto ptr = reinterpret_cast(value); + return CreateSelectV2Options(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_DensifyOptions: { + auto ptr = reinterpret_cast(value); + return CreateDensifyOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_SegmentSumOptions: { + auto ptr = reinterpret_cast(value); + return CreateSegmentSumOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_BatchMatMulOptions: { + auto ptr = reinterpret_cast(value); + return CreateBatchMatMulOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_CumsumOptions: { + auto ptr = reinterpret_cast(value); + return CreateCumsumOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_CallOnceOptions: { + auto ptr = reinterpret_cast(value); + return CreateCallOnceOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_BroadcastToOptions: { + auto ptr = reinterpret_cast(value); + return CreateBroadcastToOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_Rfft2dOptions: { + auto ptr = reinterpret_cast(value); + return CreateRfft2dOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_Conv3DOptions: { + auto ptr = reinterpret_cast(value); + return CreateConv3DOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_HashtableOptions: { + auto ptr = reinterpret_cast(value); + return CreateHashtableOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_HashtableFindOptions: { + auto ptr = reinterpret_cast(value); + return CreateHashtableFindOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_HashtableImportOptions: { + auto ptr = reinterpret_cast(value); + return CreateHashtableImportOptions(_fbb, ptr, _rehasher).Union(); + } + case BuiltinOptions_HashtableSizeOptions: { + auto ptr = reinterpret_cast(value); + return CreateHashtableSizeOptions(_fbb, ptr, _rehasher).Union(); + } + default: + return 0; + } +} + +inline BuiltinOptionsUnion::BuiltinOptionsUnion(const BuiltinOptionsUnion &u) FLATBUFFERS_NOEXCEPT : type(u.type), value(nullptr) +{ + switch (type) { + case BuiltinOptions_Conv2DOptions: { + value = new tflite::Conv2DOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_DepthwiseConv2DOptions: { + value = new tflite::DepthwiseConv2DOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_ConcatEmbeddingsOptions: { + value = new tflite::ConcatEmbeddingsOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_LSHProjectionOptions: { + value = new tflite::LSHProjectionOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_Pool2DOptions: { + value = new tflite::Pool2DOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_SVDFOptions: { + value = new tflite::SVDFOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_RNNOptions: { + value = new tflite::RNNOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_FullyConnectedOptions: { + value = new tflite::FullyConnectedOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_SoftmaxOptions: { + value = new tflite::SoftmaxOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_ConcatenationOptions: { + value = new tflite::ConcatenationOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_AddOptions: { + value = new tflite::AddOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_L2NormOptions: { + value = new tflite::L2NormOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_LocalResponseNormalizationOptions: { + value = new tflite::LocalResponseNormalizationOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_LSTMOptions: { + value = new tflite::LSTMOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_ResizeBilinearOptions: { + value = new tflite::ResizeBilinearOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_CallOptions: { + value = new tflite::CallOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_ReshapeOptions: { + value = new tflite::ReshapeOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_SkipGramOptions: { + value = new tflite::SkipGramOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_SpaceToDepthOptions: { + value = new tflite::SpaceToDepthOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_EmbeddingLookupSparseOptions: { + value = new tflite::EmbeddingLookupSparseOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_MulOptions: { + value = new tflite::MulOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_PadOptions: { + value = new tflite::PadOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_GatherOptions: { + value = new tflite::GatherOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_BatchToSpaceNDOptions: { + value = new tflite::BatchToSpaceNDOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_SpaceToBatchNDOptions: { + value = new tflite::SpaceToBatchNDOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_TransposeOptions: { + value = new tflite::TransposeOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_ReducerOptions: { + value = new tflite::ReducerOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_SubOptions: { + value = new tflite::SubOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_DivOptions: { + value = new tflite::DivOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_SqueezeOptions: { + value = new tflite::SqueezeOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_SequenceRNNOptions: { + value = new tflite::SequenceRNNOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_StridedSliceOptions: { + value = new tflite::StridedSliceOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_ExpOptions: { + value = new tflite::ExpOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_TopKV2Options: { + value = new tflite::TopKV2OptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_SplitOptions: { + value = new tflite::SplitOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_LogSoftmaxOptions: { + value = new tflite::LogSoftmaxOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_CastOptions: { + value = new tflite::CastOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_DequantizeOptions: { + value = new tflite::DequantizeOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_MaximumMinimumOptions: { + value = new tflite::MaximumMinimumOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_ArgMaxOptions: { + value = new tflite::ArgMaxOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_LessOptions: { + value = new tflite::LessOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_NegOptions: { + value = new tflite::NegOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_PadV2Options: { + value = new tflite::PadV2OptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_GreaterOptions: { + value = new tflite::GreaterOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_GreaterEqualOptions: { + value = new tflite::GreaterEqualOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_LessEqualOptions: { + value = new tflite::LessEqualOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_SelectOptions: { + value = new tflite::SelectOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_SliceOptions: { + value = new tflite::SliceOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_TransposeConvOptions: { + value = new tflite::TransposeConvOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_SparseToDenseOptions: { + value = new tflite::SparseToDenseOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_TileOptions: { + value = new tflite::TileOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_ExpandDimsOptions: { + value = new tflite::ExpandDimsOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_EqualOptions: { + value = new tflite::EqualOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_NotEqualOptions: { + value = new tflite::NotEqualOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_ShapeOptions: { + value = new tflite::ShapeOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_PowOptions: { + value = new tflite::PowOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_ArgMinOptions: { + value = new tflite::ArgMinOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_FakeQuantOptions: { + value = new tflite::FakeQuantOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_PackOptions: { + value = new tflite::PackOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_LogicalOrOptions: { + value = new tflite::LogicalOrOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_OneHotOptions: { + value = new tflite::OneHotOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_LogicalAndOptions: { + value = new tflite::LogicalAndOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_LogicalNotOptions: { + value = new tflite::LogicalNotOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_UnpackOptions: { + value = new tflite::UnpackOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_FloorDivOptions: { + value = new tflite::FloorDivOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_SquareOptions: { + value = new tflite::SquareOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_ZerosLikeOptions: { + value = new tflite::ZerosLikeOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_FillOptions: { + value = new tflite::FillOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_BidirectionalSequenceLSTMOptions: { + value = new tflite::BidirectionalSequenceLSTMOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_BidirectionalSequenceRNNOptions: { + value = new tflite::BidirectionalSequenceRNNOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_UnidirectionalSequenceLSTMOptions: { + value = new tflite::UnidirectionalSequenceLSTMOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_FloorModOptions: { + value = new tflite::FloorModOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_RangeOptions: { + value = new tflite::RangeOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_ResizeNearestNeighborOptions: { + value = new tflite::ResizeNearestNeighborOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_LeakyReluOptions: { + value = new tflite::LeakyReluOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_SquaredDifferenceOptions: { + value = new tflite::SquaredDifferenceOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_MirrorPadOptions: { + value = new tflite::MirrorPadOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_AbsOptions: { + value = new tflite::AbsOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_SplitVOptions: { + value = new tflite::SplitVOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_UniqueOptions: { + value = new tflite::UniqueOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_ReverseV2Options: { + value = new tflite::ReverseV2OptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_AddNOptions: { + value = new tflite::AddNOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_GatherNdOptions: { + value = new tflite::GatherNdOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_CosOptions: { + value = new tflite::CosOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_WhereOptions: { + value = new tflite::WhereOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_RankOptions: { + value = new tflite::RankOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_ReverseSequenceOptions: { + value = new tflite::ReverseSequenceOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_MatrixDiagOptions: { + value = new tflite::MatrixDiagOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_QuantizeOptions: { + value = new tflite::QuantizeOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_MatrixSetDiagOptions: { + value = new tflite::MatrixSetDiagOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_HardSwishOptions: { + value = new tflite::HardSwishOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_IfOptions: { + value = new tflite::IfOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_WhileOptions: { + value = new tflite::WhileOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_DepthToSpaceOptions: { + value = new tflite::DepthToSpaceOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_NonMaxSuppressionV4Options: { + value = new tflite::NonMaxSuppressionV4OptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_NonMaxSuppressionV5Options: { + value = new tflite::NonMaxSuppressionV5OptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_ScatterNdOptions: { + value = new tflite::ScatterNdOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_SelectV2Options: { + value = new tflite::SelectV2OptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_DensifyOptions: { + value = new tflite::DensifyOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_SegmentSumOptions: { + value = new tflite::SegmentSumOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_BatchMatMulOptions: { + value = new tflite::BatchMatMulOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_CumsumOptions: { + value = new tflite::CumsumOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_CallOnceOptions: { + value = new tflite::CallOnceOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_BroadcastToOptions: { + value = new tflite::BroadcastToOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_Rfft2dOptions: { + value = new tflite::Rfft2dOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_Conv3DOptions: { + value = new tflite::Conv3DOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_HashtableOptions: { + value = new tflite::HashtableOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_HashtableFindOptions: { + value = new tflite::HashtableFindOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_HashtableImportOptions: { + value = new tflite::HashtableImportOptionsT(*reinterpret_cast(u.value)); + break; + } + case BuiltinOptions_HashtableSizeOptions: { + value = new tflite::HashtableSizeOptionsT(*reinterpret_cast(u.value)); + break; + } + default: + break; + } +} + +inline void BuiltinOptionsUnion::Reset() +{ + switch (type) { + case BuiltinOptions_Conv2DOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_DepthwiseConv2DOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_ConcatEmbeddingsOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_LSHProjectionOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_Pool2DOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_SVDFOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_RNNOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_FullyConnectedOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_SoftmaxOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_ConcatenationOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_AddOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_L2NormOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_LocalResponseNormalizationOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_LSTMOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_ResizeBilinearOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_CallOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_ReshapeOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_SkipGramOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_SpaceToDepthOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_EmbeddingLookupSparseOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_MulOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_PadOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_GatherOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_BatchToSpaceNDOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_SpaceToBatchNDOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_TransposeOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_ReducerOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_SubOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_DivOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_SqueezeOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_SequenceRNNOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_StridedSliceOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_ExpOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_TopKV2Options: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_SplitOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_LogSoftmaxOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_CastOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_DequantizeOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_MaximumMinimumOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_ArgMaxOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_LessOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_NegOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_PadV2Options: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_GreaterOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_GreaterEqualOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_LessEqualOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_SelectOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_SliceOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_TransposeConvOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_SparseToDenseOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_TileOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_ExpandDimsOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_EqualOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_NotEqualOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_ShapeOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_PowOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_ArgMinOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_FakeQuantOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_PackOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_LogicalOrOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_OneHotOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_LogicalAndOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_LogicalNotOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_UnpackOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_FloorDivOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_SquareOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_ZerosLikeOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_FillOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_BidirectionalSequenceLSTMOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_BidirectionalSequenceRNNOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_UnidirectionalSequenceLSTMOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_FloorModOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_RangeOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_ResizeNearestNeighborOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_LeakyReluOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_SquaredDifferenceOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_MirrorPadOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_AbsOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_SplitVOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_UniqueOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_ReverseV2Options: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_AddNOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_GatherNdOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_CosOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_WhereOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_RankOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_ReverseSequenceOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_MatrixDiagOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_QuantizeOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_MatrixSetDiagOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_HardSwishOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_IfOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_WhileOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_DepthToSpaceOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_NonMaxSuppressionV4Options: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_NonMaxSuppressionV5Options: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_ScatterNdOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_SelectV2Options: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_DensifyOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_SegmentSumOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_BatchMatMulOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_CumsumOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_CallOnceOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_BroadcastToOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_Rfft2dOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_Conv3DOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_HashtableOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_HashtableFindOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_HashtableImportOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + case BuiltinOptions_HashtableSizeOptions: { + auto ptr = reinterpret_cast(value); + delete ptr; + break; + } + default: + break; + } + value = nullptr; + type = BuiltinOptions_NONE; +} + +inline const tflite::Model *GetModel(const void *buf) +{ + return flatbuffers::GetRoot(buf); +} + +inline const tflite::Model *GetSizePrefixedModel(const void *buf) +{ + return flatbuffers::GetSizePrefixedRoot(buf); +} + +inline const char *ModelIdentifier() +{ + return "TFL3"; +} + +inline bool ModelBufferHasIdentifier(const void *buf) +{ + return flatbuffers::BufferHasIdentifier( + buf, ModelIdentifier()); +} + +inline bool VerifyModelBuffer( + flatbuffers::Verifier &verifier) +{ + return verifier.VerifyBuffer(ModelIdentifier()); +} + +inline bool VerifySizePrefixedModelBuffer( + flatbuffers::Verifier &verifier) +{ + return verifier.VerifySizePrefixedBuffer(ModelIdentifier()); +} + +inline const char *ModelExtension() +{ + return "tflite"; +} + +inline void FinishModelBuffer( + flatbuffers::FlatBufferBuilder &fbb, + flatbuffers::Offset root) +{ + fbb.Finish(root, ModelIdentifier()); +} + +inline void FinishSizePrefixedModelBuffer( + flatbuffers::FlatBufferBuilder &fbb, + flatbuffers::Offset root) +{ + fbb.FinishSizePrefixed(root, ModelIdentifier()); +} + +inline std::unique_ptr UnPackModel( + const void *buf, + const flatbuffers::resolver_function_t *res = nullptr) +{ + return std::unique_ptr(GetModel(buf)->UnPack(res)); +} + +inline std::unique_ptr UnPackSizePrefixedModel( + const void *buf, + const flatbuffers::resolver_function_t *res = nullptr) +{ + return std::unique_ptr(GetSizePrefixedModel(buf)->UnPack(res)); +} + +} // namespace tflite + +#endif // FLATBUFFERS_GENERATED_SCHEMA_TFLITE_H_ diff --git a/components/tflite/tensorflow/lite/schema/schema_utils.cc b/components/tflite/tensorflow/lite/schema/schema_utils.cc new file mode 100644 index 00000000..40f7caab --- /dev/null +++ b/components/tflite/tensorflow/lite/schema/schema_utils.cc @@ -0,0 +1,64 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include "tensorflow/lite/schema/schema_utils.h" + +#include + +#include "tensorflow/lite/kernels/internal/compatibility.h" + +namespace tflite { + +// The following GetBuiltinCode methods are the utility methods for reading +// builtin operatore code, ensuring compatibility issues between v3 and v3a +// schema. Always the maximum value of the two fields always will be the correct +// value as follows: +// +// - Supporting schema version v3 models +// +// The `builtin_code` field is not available in the v3 models. Flatbuffer +// library will feed zero value, which is the default value in the v3a schema. +// The actual builtin operatore code value will exist in the +// `deprecated_builtin_code` field. At the same time, it implies that +// `deprecated_builtin_code` >= `builtin_code` and the maximum value of the two +// fields will be same with `deprecated_builtin_code'. +// +// - Supporting builtin operator codes beyonds 127 +// +// New builtin operators, whose operator code is larger than 127, can not be +// assigned to the `deprecated_builtin_code` field. In such cases, the +// value of the `builtin_code` field should be used for the builtin operator +// code. In the case, the maximum value of the two fields will be the value of +// the `builtin_code` as the right value. + +BuiltinOperator GetBuiltinCode(const OperatorCode *op_code) +{ + // Caller should guarantee that the given argument value is not a nullptr. + TFLITE_DCHECK(op_code != nullptr); + + return std::max( + op_code->builtin_code(), + static_cast(op_code->deprecated_builtin_code())); +} + +BuiltinOperator GetBuiltinCode(const OperatorCodeT *op_code) +{ + // Caller should guarantee that the given argument value is not a nullptr. + TFLITE_DCHECK(op_code != nullptr); + + return std::max(op_code->builtin_code, static_cast( + op_code->deprecated_builtin_code)); +} + +} // namespace tflite diff --git a/components/tflite/tensorflow/lite/schema/schema_utils.h b/components/tflite/tensorflow/lite/schema/schema_utils.h new file mode 100644 index 00000000..54b375a1 --- /dev/null +++ b/components/tflite/tensorflow/lite/schema/schema_utils.h @@ -0,0 +1,32 @@ +/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_LITE_SCHEMA_SCHEMA_UTILS_H_ +#define TENSORFLOW_LITE_SCHEMA_SCHEMA_UTILS_H_ + +#include "flatbuffers/flatbuffers.h" +#include "tensorflow/lite/schema/schema_generated.h" + +namespace tflite { +// The following methods are introduced to resolve op builtin code shortage +// problem. The new builtin operator will be assigned to the extended builtin +// code field in the flatbuffer schema. Those methods helps to hide builtin code +// details. +BuiltinOperator GetBuiltinCode(const OperatorCode *op_code); + +BuiltinOperator GetBuiltinCode(const OperatorCodeT *op_code); + +} // namespace tflite + +#endif // TENSORFLOW_LITE_SCHEMA_SCHEMA_UTILS_H_ diff --git a/components/tflite/third_party/flatbuffers/include/flatbuffers/base.h b/components/tflite/third_party/flatbuffers/include/flatbuffers/base.h new file mode 100644 index 00000000..8e97c084 --- /dev/null +++ b/components/tflite/third_party/flatbuffers/include/flatbuffers/base.h @@ -0,0 +1,427 @@ +#ifndef FLATBUFFERS_BASE_H_ +#define FLATBUFFERS_BASE_H_ + +// clang-format off + +// If activate should be declared and included first. +#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && \ + defined(_MSC_VER) && defined(_DEBUG) + // The _CRTDBG_MAP_ALLOC inside will replace + // calloc/free (etc) to its debug version using #define directives. + #define _CRTDBG_MAP_ALLOC + #include + #include + // Replace operator new by trace-enabled version. + #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) + #define new DEBUG_NEW +#endif + +#if !defined(FLATBUFFERS_ASSERT) +#include +#define FLATBUFFERS_ASSERT assert +#elif defined(FLATBUFFERS_ASSERT_INCLUDE) +// Include file with forward declaration +#include FLATBUFFERS_ASSERT_INCLUDE +#endif + +#ifndef ARDUINO +#include +#endif + +#include +#include +#include + +#if defined(ARDUINO) && !defined(ARDUINOSTL_M_H) + #include +#else + #include +#endif + +#include +#include +#include +#include +#include +#include +#include + +#if defined(__unix__) && !defined(FLATBUFFERS_LOCALE_INDEPENDENT) + #include +#endif + +#ifdef _STLPORT_VERSION + #define FLATBUFFERS_CPP98_STL +#endif + +#ifdef __ANDROID__ + #include +#endif + +#if defined(__ICCARM__) +#include +#endif + +// Note the __clang__ check is needed, because clang presents itself +// as an older GNUC compiler (4.2). +// Clang 3.3 and later implement all of the ISO C++ 2011 standard. +// Clang 3.4 and later implement all of the ISO C++ 2014 standard. +// http://clang.llvm.org/cxx_status.html + +// Note the MSVC value '__cplusplus' may be incorrect: +// The '__cplusplus' predefined macro in the MSVC stuck at the value 199711L, +// indicating (erroneously!) that the compiler conformed to the C++98 Standard. +// This value should be correct starting from MSVC2017-15.7-Preview-3. +// The '__cplusplus' will be valid only if MSVC2017-15.7-P3 and the `/Zc:__cplusplus` switch is set. +// Workaround (for details see MSDN): +// Use the _MSC_VER and _MSVC_LANG definition instead of the __cplusplus for compatibility. +// The _MSVC_LANG macro reports the Standard version regardless of the '/Zc:__cplusplus' switch. + +#if defined(__GNUC__) && !defined(__clang__) + #define FLATBUFFERS_GCC (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) +#else + #define FLATBUFFERS_GCC 0 +#endif + +#if defined(__clang__) + #define FLATBUFFERS_CLANG (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) +#else + #define FLATBUFFERS_CLANG 0 +#endif + +/// @cond FLATBUFFERS_INTERNAL +#if __cplusplus <= 199711L && \ + (!defined(_MSC_VER) || _MSC_VER < 1600) && \ + (!defined(__GNUC__) || \ + (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ < 40400)) + #error A C++11 compatible compiler with support for the auto typing is \ + required for FlatBuffers. + #error __cplusplus _MSC_VER __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ +#endif + +#if !defined(__clang__) && \ + defined(__GNUC__) && \ + (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ < 40600) + // Backwards compatibility for g++ 4.4, and 4.5 which don't have the nullptr + // and constexpr keywords. Note the __clang__ check is needed, because clang + // presents itself as an older GNUC compiler. + #ifndef nullptr_t + const class nullptr_t { + public: + template inline operator T*() const { return 0; } + private: + void operator&() const; + } nullptr = {}; + #endif + #ifndef constexpr + #define constexpr const + #endif +#endif + +// The wire format uses a little endian encoding (since that's efficient for +// the common platforms). +#if defined(__s390x__) + #define FLATBUFFERS_LITTLEENDIAN 0 +#endif // __s390x__ +#if !defined(FLATBUFFERS_LITTLEENDIAN) + #if defined(__GNUC__) || defined(__clang__) || defined(__ICCARM__) + #if (defined(__BIG_ENDIAN__) || \ + (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) + #define FLATBUFFERS_LITTLEENDIAN 0 + #else + #define FLATBUFFERS_LITTLEENDIAN 1 + #endif // __BIG_ENDIAN__ + #elif defined(_MSC_VER) + #if defined(_M_PPC) + #define FLATBUFFERS_LITTLEENDIAN 0 + #else + #define FLATBUFFERS_LITTLEENDIAN 1 + #endif + #else + #error Unable to determine endianness, define FLATBUFFERS_LITTLEENDIAN. + #endif +#endif // !defined(FLATBUFFERS_LITTLEENDIAN) + +#define FLATBUFFERS_VERSION_MAJOR 1 +#define FLATBUFFERS_VERSION_MINOR 12 +#define FLATBUFFERS_VERSION_REVISION 0 +#define FLATBUFFERS_STRING_EXPAND(X) #X +#define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X) +namespace flatbuffers { + // Returns version as string "MAJOR.MINOR.REVISION". + const char* FLATBUFFERS_VERSION(); +} + +#if (!defined(_MSC_VER) || _MSC_VER > 1600) && \ + (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 407)) || \ + defined(__clang__) + #define FLATBUFFERS_FINAL_CLASS final + #define FLATBUFFERS_OVERRIDE override + #define FLATBUFFERS_EXPLICIT_CPP11 explicit + #define FLATBUFFERS_VTABLE_UNDERLYING_TYPE : flatbuffers::voffset_t +#else + #define FLATBUFFERS_FINAL_CLASS + #define FLATBUFFERS_OVERRIDE + #define FLATBUFFERS_EXPLICIT_CPP11 + #define FLATBUFFERS_VTABLE_UNDERLYING_TYPE +#endif + +#if (!defined(_MSC_VER) || _MSC_VER >= 1900) && \ + (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)) || \ + (defined(__cpp_constexpr) && __cpp_constexpr >= 200704) + #define FLATBUFFERS_CONSTEXPR constexpr + #define FLATBUFFERS_CONSTEXPR_CPP11 constexpr + #define FLATBUFFERS_CONSTEXPR_DEFINED +#else + #define FLATBUFFERS_CONSTEXPR const + #define FLATBUFFERS_CONSTEXPR_CPP11 +#endif + +// This macro is never used in code! +#if (defined(__cplusplus) && __cplusplus >= 201402L) || \ + (defined(__cpp_constexpr) && __cpp_constexpr >= 201304) + #define FLATBUFFERS_CONSTEXPR_CPP14 FLATBUFFERS_CONSTEXPR +#else + #define FLATBUFFERS_CONSTEXPR_CPP14 +#endif + +#if (defined(__GXX_EXPERIMENTAL_CXX0X__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)) || \ + (defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 190023026)) || \ + defined(__clang__) + #define FLATBUFFERS_NOEXCEPT noexcept +#else + #define FLATBUFFERS_NOEXCEPT +#endif + +// NOTE: the FLATBUFFERS_DELETE_FUNC macro may change the access mode to +// private, so be sure to put it at the end or reset access mode explicitly. +#if (!defined(_MSC_VER) || _MSC_FULL_VER >= 180020827) && \ + (!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 404)) || \ + defined(__clang__) + #define FLATBUFFERS_DELETE_FUNC(func) func = delete; +#else + #define FLATBUFFERS_DELETE_FUNC(func) private: func; +#endif + +// Check if we can use template aliases +// Not possible if Microsoft Compiler before 2012 +// Possible is the language feature __cpp_alias_templates is defined well +// Or possible if the C++ std is C+11 or newer +#if (defined(_MSC_VER) && _MSC_VER > 1700 /* MSVC2012 */) \ + || (defined(__cpp_alias_templates) && __cpp_alias_templates >= 200704) \ + || (defined(__cplusplus) && __cplusplus >= 201103L) + #define FLATBUFFERS_TEMPLATES_ALIASES +#endif + +#ifndef FLATBUFFERS_HAS_STRING_VIEW + // Only provide flatbuffers::string_view if __has_include can be used + // to detect a header that provides an implementation + #if defined(__has_include) + // Check for std::string_view (in c++17) + #if __has_include() && (__cplusplus >= 201606 || (defined(_HAS_CXX17) && _HAS_CXX17)) + #include + namespace flatbuffers { + typedef std::string_view string_view; + } + #define FLATBUFFERS_HAS_STRING_VIEW 1 + // Check for std::experimental::string_view (in c++14, compiler-dependent) + #elif __has_include() && (__cplusplus >= 201411) + #include + namespace flatbuffers { + typedef std::experimental::string_view string_view; + } + #define FLATBUFFERS_HAS_STRING_VIEW 1 + // Check for absl::string_view + #elif __has_include("absl/strings/string_view.h") + #include "absl/strings/string_view.h" + namespace flatbuffers { + typedef absl::string_view string_view; + } + #define FLATBUFFERS_HAS_STRING_VIEW 1 + #endif + #endif // __has_include +#endif // !FLATBUFFERS_HAS_STRING_VIEW + +#ifndef FLATBUFFERS_HAS_NEW_STRTOD + // Modern (C++11) strtod and strtof functions are available for use. + // 1) nan/inf strings as argument of strtod; + // 2) hex-float as argument of strtod/strtof. + #if (defined(_MSC_VER) && _MSC_VER >= 1900) || \ + (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409)) || \ + (defined(__clang__)) + #define FLATBUFFERS_HAS_NEW_STRTOD 1 + #endif +#endif // !FLATBUFFERS_HAS_NEW_STRTOD + +#ifndef FLATBUFFERS_LOCALE_INDEPENDENT + // Enable locale independent functions {strtof_l, strtod_l,strtoll_l, strtoull_l}. + #if ((defined(_MSC_VER) && _MSC_VER >= 1800) || \ + (defined(_XOPEN_VERSION) && (_XOPEN_VERSION>=700)) && (!defined(__ANDROID_API__) || (defined(__ANDROID_API__) && (__ANDROID_API__>=21)))) + #define FLATBUFFERS_LOCALE_INDEPENDENT 1 + #else + #define FLATBUFFERS_LOCALE_INDEPENDENT 0 + #endif +#endif // !FLATBUFFERS_LOCALE_INDEPENDENT + +// Suppress Undefined Behavior Sanitizer (recoverable only). Usage: +// - __supress_ubsan__("undefined") +// - __supress_ubsan__("signed-integer-overflow") +#if defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >=7)) + #define __supress_ubsan__(type) __attribute__((no_sanitize(type))) +#elif defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409) + #define __supress_ubsan__(type) __attribute__((no_sanitize_undefined)) +#else + #define __supress_ubsan__(type) +#endif + +// This is constexpr function used for checking compile-time constants. +// Avoid `#pragma warning(disable: 4127) // C4127: expression is constant`. +template FLATBUFFERS_CONSTEXPR inline bool IsConstTrue(T t) { + return !!t; +} + +// Enable C++ attribute [[]] if std:c++17 or higher. +#if ((__cplusplus >= 201703L) \ + || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L))) + // All attributes unknown to an implementation are ignored without causing an error. + #define FLATBUFFERS_ATTRIBUTE(attr) [[attr]] + + #define FLATBUFFERS_FALLTHROUGH() [[fallthrough]] +#else + #define FLATBUFFERS_ATTRIBUTE(attr) + + #if FLATBUFFERS_CLANG >= 30800 + #define FLATBUFFERS_FALLTHROUGH() [[clang::fallthrough]] + #elif FLATBUFFERS_GCC >= 70300 + #define FLATBUFFERS_FALLTHROUGH() [[gnu::fallthrough]] + #else + #define FLATBUFFERS_FALLTHROUGH() + #endif +#endif + +/// @endcond + +/// @file +namespace flatbuffers { + +/// @cond FLATBUFFERS_INTERNAL +// Our default offset / size type, 32bit on purpose on 64bit systems. +// Also, using a consistent offset type maintains compatibility of serialized +// offset values between 32bit and 64bit systems. +typedef uint32_t uoffset_t; + +// Signed offsets for references that can go in both directions. +typedef int32_t soffset_t; + +// Offset/index used in v-tables, can be changed to uint8_t in +// format forks to save a bit of space if desired. +typedef uint16_t voffset_t; + +typedef uintmax_t largest_scalar_t; + +// In 32bits, this evaluates to 2GB - 1 +#define FLATBUFFERS_MAX_BUFFER_SIZE ((1ULL << (sizeof(::flatbuffers::soffset_t) * 8 - 1)) - 1) + +// We support aligning the contents of buffers up to this size. +#define FLATBUFFERS_MAX_ALIGNMENT 16 + +#if defined(_MSC_VER) + #pragma warning(disable: 4351) // C4351: new behavior: elements of array ... will be default initialized + #pragma warning(push) + #pragma warning(disable: 4127) // C4127: conditional expression is constant +#endif + +template T EndianSwap(T t) { + #if defined(_MSC_VER) + #define FLATBUFFERS_BYTESWAP16 _byteswap_ushort + #define FLATBUFFERS_BYTESWAP32 _byteswap_ulong + #define FLATBUFFERS_BYTESWAP64 _byteswap_uint64 + #elif defined(__ICCARM__) + #define FLATBUFFERS_BYTESWAP16 __REV16 + #define FLATBUFFERS_BYTESWAP32 __REV + #define FLATBUFFERS_BYTESWAP64(x) \ + ((__REV(static_cast(x >> 32U))) | (static_cast(__REV(static_cast(x)))) << 32U) + #else + #if defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ < 408 && !defined(__clang__) + // __builtin_bswap16 was missing prior to GCC 4.8. + #define FLATBUFFERS_BYTESWAP16(x) \ + static_cast(__builtin_bswap32(static_cast(x) << 16)) + #else + #define FLATBUFFERS_BYTESWAP16 __builtin_bswap16 + #endif + #define FLATBUFFERS_BYTESWAP32 __builtin_bswap32 + #define FLATBUFFERS_BYTESWAP64 __builtin_bswap64 + #endif + if (sizeof(T) == 1) { // Compile-time if-then's. + return t; + } else if (sizeof(T) == 2) { + union { T t; uint16_t i; } u = { t }; + u.i = FLATBUFFERS_BYTESWAP16(u.i); + return u.t; + } else if (sizeof(T) == 4) { + union { T t; uint32_t i; } u = { t }; + u.i = FLATBUFFERS_BYTESWAP32(u.i); + return u.t; + } else if (sizeof(T) == 8) { + union { T t; uint64_t i; } u = { t }; + u.i = FLATBUFFERS_BYTESWAP64(u.i); + return u.t; + } else { + FLATBUFFERS_ASSERT(0); + return t; + } +} + +#if defined(_MSC_VER) + #pragma warning(pop) +#endif + + +template T EndianScalar(T t) { + #if FLATBUFFERS_LITTLEENDIAN + return t; + #else + return EndianSwap(t); + #endif +} + +template +// UBSAN: C++ aliasing type rules, see std::bit_cast<> for details. +__supress_ubsan__("alignment") +T ReadScalar(const void *p) { + return EndianScalar(*reinterpret_cast(p)); +} + +// See https://github.com/google/flatbuffers/issues/5950 + +#if (FLATBUFFERS_GCC >= 100000) && (FLATBUFFERS_GCC < 110000) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstringop-overflow" +#endif + +template +// UBSAN: C++ aliasing type rules, see std::bit_cast<> for details. +__supress_ubsan__("alignment") +void WriteScalar(void *p, T t) { + *reinterpret_cast(p) = EndianScalar(t); +} + +template struct Offset; +template __supress_ubsan__("alignment") void WriteScalar(void *p, Offset t) { + *reinterpret_cast(p) = EndianScalar(t.o); +} + +#if (FLATBUFFERS_GCC >= 100000) && (FLATBUFFERS_GCC < 110000) + #pragma GCC diagnostic pop +#endif + +// Computes how many bytes you'd have to pad to be able to write an +// "scalar_size" scalar if the buffer had grown to "buf_size" (downwards in +// memory). +__supress_ubsan__("unsigned-integer-overflow") +inline size_t PaddingBytes(size_t buf_size, size_t scalar_size) { + return ((~buf_size) + 1) & (scalar_size - 1); +} + +} // namespace flatbuffers +#endif // FLATBUFFERS_BASE_H_ diff --git a/components/tflite/third_party/flatbuffers/include/flatbuffers/code_generators.h b/components/tflite/third_party/flatbuffers/include/flatbuffers/code_generators.h new file mode 100644 index 00000000..d0b3d1c7 --- /dev/null +++ b/components/tflite/third_party/flatbuffers/include/flatbuffers/code_generators.h @@ -0,0 +1,255 @@ +/* + * Copyright 2014 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FLATBUFFERS_CODE_GENERATORS_H_ +#define FLATBUFFERS_CODE_GENERATORS_H_ + +#include +#include + +#include "flatbuffers/idl.h" + +namespace flatbuffers { +// Utility class to assist in generating code through use of text templates. +// +// Example code: +// CodeWriter code("\t"); +// code.SetValue("NAME", "Foo"); +// code += "void {{NAME}}() { printf("%s", "{{NAME}}"); }"; +// code.SetValue("NAME", "Bar"); +// code += "void {{NAME}}() { printf("%s", "{{NAME}}"); }"; +// std::cout << code.ToString() << std::endl; +// +// Output: +// void Foo() { printf("%s", "Foo"); } +// void Bar() { printf("%s", "Bar"); } +class CodeWriter { +public: + CodeWriter(std::string pad = std::string()) + : pad_(pad), cur_ident_lvl_(0), ignore_ident_(false) + { + } + + // Clears the current "written" code. + void Clear() + { + stream_.str(""); + stream_.clear(); + } + + // Associates a key with a value. All subsequent calls to operator+=, where + // the specified key is contained in {{ and }} delimiters will be replaced by + // the given value. + void SetValue(const std::string &key, const std::string &value) + { + value_map_[key] = value; + } + + std::string GetValue(const std::string &key) const + { + const auto it = value_map_.find(key); + return it == value_map_.end() ? "" : it->second; + } + + // Appends the given text to the generated code as well as a newline + // character. Any text within {{ and }} delimiters is replaced by values + // previously stored in the CodeWriter by calling SetValue above. The newline + // will be suppressed if the text ends with the \\ character. + void operator+=(std::string text); + + // Returns the current contents of the CodeWriter as a std::string. + std::string ToString() const + { + return stream_.str(); + } + + // Increase ident level for writing code + void IncrementIdentLevel() + { + cur_ident_lvl_++; + } + // Decrease ident level for writing code + void DecrementIdentLevel() + { + if (cur_ident_lvl_) + cur_ident_lvl_--; + } + + void SetPadding(const std::string &padding) + { + pad_ = padding; + } + +private: + std::map value_map_; + std::stringstream stream_; + std::string pad_; + int cur_ident_lvl_; + bool ignore_ident_; + + // Add ident padding (tab or space) based on ident level + void AppendIdent(std::stringstream &stream); +}; + +class BaseGenerator { +public: + virtual bool generate() = 0; + + static std::string NamespaceDir(const Parser &parser, const std::string &path, + const Namespace &ns); + + std::string GeneratedFileName(const std::string &path, + const std::string &file_name, + const IDLOptions &options) const; + +protected: + BaseGenerator(const Parser &parser, const std::string &path, + const std::string &file_name, std::string qualifying_start, + std::string qualifying_separator, std::string default_extension) + : parser_(parser), + path_(path), + file_name_(file_name), + qualifying_start_(qualifying_start), + qualifying_separator_(qualifying_separator), + default_extension_(default_extension) + { + } + virtual ~BaseGenerator() + { + } + + // No copy/assign. + BaseGenerator &operator=(const BaseGenerator &); + BaseGenerator(const BaseGenerator &); + + std::string NamespaceDir(const Namespace &ns) const; + + static const char *FlatBuffersGeneratedWarning(); + + static std::string FullNamespace(const char *separator, const Namespace &ns); + + static std::string LastNamespacePart(const Namespace &ns); + + // tracks the current namespace for early exit in WrapInNameSpace + // c++, java and csharp returns a different namespace from + // the following default (no early exit, always fully qualify), + // which works for js and php + virtual const Namespace *CurrentNameSpace() const + { + return nullptr; + } + + // Ensure that a type is prefixed with its namespace even within + // its own namespace to avoid conflict between generated method + // names and similarly named classes or structs + std::string WrapInNameSpace(const Namespace *ns, + const std::string &name) const; + + std::string WrapInNameSpace(const Definition &def) const; + + std::string GetNameSpace(const Definition &def) const; + + const Parser &parser_; + const std::string &path_; + const std::string &file_name_; + const std::string qualifying_start_; + const std::string qualifying_separator_; + const std::string default_extension_; +}; + +struct CommentConfig { + const char *first_line; + const char *content_line_prefix; + const char *last_line; +}; + +extern void GenComment(const std::vector &dc, + std::string *code_ptr, const CommentConfig *config, + const char *prefix = ""); + +class FloatConstantGenerator { +public: + virtual ~FloatConstantGenerator() + { + } + std::string GenFloatConstant(const FieldDef &field) const; + +private: + virtual std::string Value(double v, const std::string &src) const = 0; + virtual std::string Inf(double v) const = 0; + virtual std::string NaN(double v) const = 0; + + virtual std::string Value(float v, const std::string &src) const = 0; + virtual std::string Inf(float v) const = 0; + virtual std::string NaN(float v) const = 0; + + template + std::string GenFloatConstantImpl(const FieldDef &field) const; +}; + +class SimpleFloatConstantGenerator : public FloatConstantGenerator { +public: + SimpleFloatConstantGenerator(const char *nan_number, + const char *pos_inf_number, + const char *neg_inf_number); + +private: + std::string Value(double v, + const std::string &src) const FLATBUFFERS_OVERRIDE; + std::string Inf(double v) const FLATBUFFERS_OVERRIDE; + std::string NaN(double v) const FLATBUFFERS_OVERRIDE; + + std::string Value(float v, const std::string &src) const FLATBUFFERS_OVERRIDE; + std::string Inf(float v) const FLATBUFFERS_OVERRIDE; + std::string NaN(float v) const FLATBUFFERS_OVERRIDE; + + const std::string nan_number_; + const std::string pos_inf_number_; + const std::string neg_inf_number_; +}; + +// C++, C#, Java like generator. +class TypedFloatConstantGenerator : public FloatConstantGenerator { +public: + TypedFloatConstantGenerator(const char *double_prefix, + const char *single_prefix, const char *nan_number, + const char *pos_inf_number, + const char *neg_inf_number = ""); + +private: + std::string Value(double v, + const std::string &src) const FLATBUFFERS_OVERRIDE; + std::string Inf(double v) const FLATBUFFERS_OVERRIDE; + + std::string NaN(double v) const FLATBUFFERS_OVERRIDE; + + std::string Value(float v, const std::string &src) const FLATBUFFERS_OVERRIDE; + std::string Inf(float v) const FLATBUFFERS_OVERRIDE; + std::string NaN(float v) const FLATBUFFERS_OVERRIDE; + + std::string MakeNaN(const std::string &prefix) const; + std::string MakeInf(bool neg, const std::string &prefix) const; + + const std::string double_prefix_; + const std::string single_prefix_; + const std::string nan_number_; + const std::string pos_inf_number_; + const std::string neg_inf_number_; +}; + +} // namespace flatbuffers + +#endif // FLATBUFFERS_CODE_GENERATORS_H_ diff --git a/components/tflite/third_party/flatbuffers/include/flatbuffers/flatbuffers.h b/components/tflite/third_party/flatbuffers/include/flatbuffers/flatbuffers.h new file mode 100644 index 00000000..2bc94c8d --- /dev/null +++ b/components/tflite/third_party/flatbuffers/include/flatbuffers/flatbuffers.h @@ -0,0 +1,3388 @@ +/* + * Copyright 2014 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FLATBUFFERS_H_ +#define FLATBUFFERS_H_ + +#include "flatbuffers/base.h" +#include "flatbuffers/stl_emulation.h" + +#ifndef FLATBUFFERS_CPP98_STL +#include +#endif + +#if defined(FLATBUFFERS_NAN_DEFAULTS) +#include +#endif + +namespace flatbuffers { +// Generic 'operator==' with conditional specialisations. +// T e - new value of a scalar field. +// T def - default of scalar (is known at compile-time). +template +inline bool IsTheSameAs(T e, T def) +{ + return e == def; +} + +#if defined(FLATBUFFERS_NAN_DEFAULTS) && \ + defined(FLATBUFFERS_HAS_NEW_STRTOD) && (FLATBUFFERS_HAS_NEW_STRTOD > 0) +// Like `operator==(e, def)` with weak NaN if T=(float|double). +template +inline bool IsFloatTheSameAs(T e, T def) +{ + return (e == def) || ((def != def) && (e != e)); +} +template <> +inline bool IsTheSameAs(float e, float def) +{ + return IsFloatTheSameAs(e, def); +} +template <> +inline bool IsTheSameAs(double e, double def) +{ + return IsFloatTheSameAs(e, def); +} +#endif + +// Check 'v' is out of closed range [low; high]. +// Workaround for GCC warning [-Werror=type-limits]: +// comparison is always true due to limited range of data type. +template +inline bool IsOutRange(const T &v, const T &low, const T &high) +{ + return (v < low) || (high < v); +} + +// Check 'v' is in closed range [low; high]. +template +inline bool IsInRange(const T &v, const T &low, const T &high) +{ + return !IsOutRange(v, low, high); +} + +// Wrapper for uoffset_t to allow safe template specialization. +// Value is allowed to be 0 to indicate a null object (see e.g. AddOffset). +template +struct Offset { + uoffset_t o; + Offset() + : o(0) + { + } + Offset(uoffset_t _o) + : o(_o) + { + } + Offset Union() const + { + return Offset(o); + } + bool IsNull() const + { + return !o; + } +}; + +inline void EndianCheck() +{ + int endiantest = 1; + // If this fails, see FLATBUFFERS_LITTLEENDIAN above. + FLATBUFFERS_ASSERT(*reinterpret_cast(&endiantest) == + FLATBUFFERS_LITTLEENDIAN); + (void)endiantest; +} + +template +FLATBUFFERS_CONSTEXPR size_t AlignOf() +{ + // clang-format off + #ifdef _MSC_VER + return __alignof(T); + #else + #ifndef alignof + return __alignof__(T); + #else + return alignof(T); + #endif + #endif + // clang-format on +} + +// When we read serialized data from memory, in the case of most scalars, +// we want to just read T, but in the case of Offset, we want to actually +// perform the indirection and return a pointer. +// The template specialization below does just that. +// It is wrapped in a struct since function templates can't overload on the +// return type like this. +// The typedef is for the convenience of callers of this function +// (avoiding the need for a trailing return decltype) +template +struct IndirectHelper { + typedef T return_type; + typedef T mutable_return_type; + static const size_t element_stride = sizeof(T); + static return_type Read(const uint8_t *p, uoffset_t i) + { + return EndianScalar((reinterpret_cast(p))[i]); + } +}; +template +struct IndirectHelper > { + typedef const T *return_type; + typedef T *mutable_return_type; + static const size_t element_stride = sizeof(uoffset_t); + static return_type Read(const uint8_t *p, uoffset_t i) + { + p += i * sizeof(uoffset_t); + return reinterpret_cast(p + ReadScalar(p)); + } +}; +template +struct IndirectHelper { + typedef const T *return_type; + typedef T *mutable_return_type; + static const size_t element_stride = sizeof(T); + static return_type Read(const uint8_t *p, uoffset_t i) + { + return reinterpret_cast(p + i * sizeof(T)); + } +}; + +// An STL compatible iterator implementation for Vector below, effectively +// calling Get() for every element. +template +struct VectorIterator { + typedef std::random_access_iterator_tag iterator_category; + typedef IT value_type; + typedef ptrdiff_t difference_type; + typedef IT *pointer; + typedef IT &reference; + + VectorIterator(const uint8_t *data, uoffset_t i) + : data_(data + IndirectHelper::element_stride * i) + { + } + VectorIterator(const VectorIterator &other) + : data_(other.data_) + { + } + VectorIterator() + : data_(nullptr) + { + } + + VectorIterator &operator=(const VectorIterator &other) + { + data_ = other.data_; + return *this; + } + + // clang-format off + #if !defined(FLATBUFFERS_CPP98_STL) + VectorIterator &operator=(VectorIterator &&other) { + data_ = other.data_; + return *this; + } + #endif // !defined(FLATBUFFERS_CPP98_STL) + // clang-format on + + bool operator==(const VectorIterator &other) const + { + return data_ == other.data_; + } + + bool operator<(const VectorIterator &other) const + { + return data_ < other.data_; + } + + bool operator!=(const VectorIterator &other) const + { + return data_ != other.data_; + } + + difference_type operator-(const VectorIterator &other) const + { + return (data_ - other.data_) / IndirectHelper::element_stride; + } + + IT operator*() const + { + return IndirectHelper::Read(data_, 0); + } + + IT operator->() const + { + return IndirectHelper::Read(data_, 0); + } + + VectorIterator &operator++() + { + data_ += IndirectHelper::element_stride; + return *this; + } + + VectorIterator operator++(int) + { + VectorIterator temp(data_, 0); + data_ += IndirectHelper::element_stride; + return temp; + } + + VectorIterator operator+(const uoffset_t &offset) const + { + return VectorIterator(data_ + offset * IndirectHelper::element_stride, + 0); + } + + VectorIterator &operator+=(const uoffset_t &offset) + { + data_ += offset * IndirectHelper::element_stride; + return *this; + } + + VectorIterator &operator--() + { + data_ -= IndirectHelper::element_stride; + return *this; + } + + VectorIterator operator--(int) + { + VectorIterator temp(data_, 0); + data_ -= IndirectHelper::element_stride; + return temp; + } + + VectorIterator operator-(const uoffset_t &offset) const + { + return VectorIterator(data_ - offset * IndirectHelper::element_stride, + 0); + } + + VectorIterator &operator-=(const uoffset_t &offset) + { + data_ -= offset * IndirectHelper::element_stride; + return *this; + } + +private: + const uint8_t *data_; +}; + +template +struct VectorReverseIterator : public std::reverse_iterator { + explicit VectorReverseIterator(Iterator iter) + : std::reverse_iterator(iter) + { + } + + typename Iterator::value_type operator*() const + { + return *(std::reverse_iterator::current); + } + + typename Iterator::value_type operator->() const + { + return *(std::reverse_iterator::current); + } +}; + +struct String; + +// This is used as a helper type for accessing vectors. +// Vector::data() assumes the vector elements start after the length field. +template +class Vector { +public: + typedef VectorIterator::mutable_return_type> + iterator; + typedef VectorIterator::return_type> + const_iterator; + typedef VectorReverseIterator reverse_iterator; + typedef VectorReverseIterator const_reverse_iterator; + + uoffset_t size() const + { + return EndianScalar(length_); + } + + // Deprecated: use size(). Here for backwards compatibility. + FLATBUFFERS_ATTRIBUTE(deprecated("use size() instead")) + uoffset_t Length() const + { + return size(); + } + + typedef typename IndirectHelper::return_type return_type; + typedef typename IndirectHelper::mutable_return_type mutable_return_type; + + return_type Get(uoffset_t i) const + { + FLATBUFFERS_ASSERT(i < size()); + return IndirectHelper::Read(Data(), i); + } + + return_type operator[](uoffset_t i) const + { + return Get(i); + } + + // If this is a Vector of enums, T will be its storage type, not the enum + // type. This function makes it convenient to retrieve value with enum + // type E. + template + E GetEnum(uoffset_t i) const + { + return static_cast(Get(i)); + } + + // If this a vector of unions, this does the cast for you. There's no check + // to make sure this is the right type! + template + const U *GetAs(uoffset_t i) const + { + return reinterpret_cast(Get(i)); + } + + // If this a vector of unions, this does the cast for you. There's no check + // to make sure this is actually a string! + const String *GetAsString(uoffset_t i) const + { + return reinterpret_cast(Get(i)); + } + + const void *GetStructFromOffset(size_t o) const + { + return reinterpret_cast(Data() + o); + } + + iterator begin() + { + return iterator(Data(), 0); + } + const_iterator begin() const + { + return const_iterator(Data(), 0); + } + + iterator end() + { + return iterator(Data(), size()); + } + const_iterator end() const + { + return const_iterator(Data(), size()); + } + + reverse_iterator rbegin() + { + return reverse_iterator(end() - 1); + } + const_reverse_iterator rbegin() const + { + return const_reverse_iterator(end() - 1); + } + + reverse_iterator rend() + { + return reverse_iterator(begin() - 1); + } + const_reverse_iterator rend() const + { + return const_reverse_iterator(begin() - 1); + } + + const_iterator cbegin() const + { + return begin(); + } + + const_iterator cend() const + { + return end(); + } + + const_reverse_iterator crbegin() const + { + return rbegin(); + } + + const_reverse_iterator crend() const + { + return rend(); + } + + // Change elements if you have a non-const pointer to this object. + // Scalars only. See reflection.h, and the documentation. + void Mutate(uoffset_t i, const T &val) + { + FLATBUFFERS_ASSERT(i < size()); + WriteScalar(data() + i, val); + } + + // Change an element of a vector of tables (or strings). + // "val" points to the new table/string, as you can obtain from + // e.g. reflection::AddFlatBuffer(). + void MutateOffset(uoffset_t i, const uint8_t *val) + { + FLATBUFFERS_ASSERT(i < size()); + static_assert(sizeof(T) == sizeof(uoffset_t), "Unrelated types"); + WriteScalar(data() + i, + static_cast(val - (Data() + i * sizeof(uoffset_t)))); + } + + // Get a mutable pointer to tables/strings inside this vector. + mutable_return_type GetMutableObject(uoffset_t i) const + { + FLATBUFFERS_ASSERT(i < size()); + return const_cast(IndirectHelper::Read(Data(), i)); + } + + // The raw data in little endian format. Use with care. + const uint8_t *Data() const + { + return reinterpret_cast(&length_ + 1); + } + + uint8_t *Data() + { + return reinterpret_cast(&length_ + 1); + } + + // Similarly, but typed, much like std::vector::data + const T *data() const + { + return reinterpret_cast(Data()); + } + T *data() + { + return reinterpret_cast(Data()); + } + + template + return_type LookupByKey(K key) const + { + void *search_result = std::bsearch( + &key, Data(), size(), IndirectHelper::element_stride, KeyCompare); + + if (!search_result) { + return nullptr; // Key not found. + } + + const uint8_t *element = reinterpret_cast(search_result); + + return IndirectHelper::Read(element, 0); + } + +protected: + // This class is only used to access pre-existing data. Don't ever + // try to construct these manually. + Vector(); + + uoffset_t length_; + +private: + // This class is a pointer. Copying will therefore create an invalid object. + // Private and unimplemented copy constructor. + Vector(const Vector &); + Vector &operator=(const Vector &); + + template + static int KeyCompare(const void *ap, const void *bp) + { + const K *key = reinterpret_cast(ap); + const uint8_t *data = reinterpret_cast(bp); + auto table = IndirectHelper::Read(data, 0); + + // std::bsearch compares with the operands transposed, so we negate the + // result here. + return -table->KeyCompareWithValue(*key); + } +}; + +// Represent a vector much like the template above, but in this case we +// don't know what the element types are (used with reflection.h). +class VectorOfAny { +public: + uoffset_t size() const + { + return EndianScalar(length_); + } + + const uint8_t *Data() const + { + return reinterpret_cast(&length_ + 1); + } + uint8_t *Data() + { + return reinterpret_cast(&length_ + 1); + } + +protected: + VectorOfAny(); + + uoffset_t length_; + +private: + VectorOfAny(const VectorOfAny &); + VectorOfAny &operator=(const VectorOfAny &); +}; + +#ifndef FLATBUFFERS_CPP98_STL +template +Vector > *VectorCast(Vector > *ptr) +{ + static_assert(std::is_base_of::value, "Unrelated types"); + return reinterpret_cast > *>(ptr); +} + +template +const Vector > *VectorCast(const Vector > *ptr) +{ + static_assert(std::is_base_of::value, "Unrelated types"); + return reinterpret_cast > *>(ptr); +} +#endif + +// Convenient helper function to get the length of any vector, regardless +// of whether it is null or not (the field is not set). +template +static inline size_t VectorLength(const Vector *v) +{ + return v ? v->size() : 0; +} + +// This is used as a helper type for accessing arrays. +template +class Array { + typedef + typename flatbuffers::integral_constant::value> + scalar_tag; + typedef + typename flatbuffers::conditional::type + IndirectHelperType; + +public: + typedef typename IndirectHelper::return_type return_type; + typedef VectorIterator const_iterator; + typedef VectorReverseIterator const_reverse_iterator; + + FLATBUFFERS_CONSTEXPR uint16_t size() const + { + return length; + } + + return_type Get(uoffset_t i) const + { + FLATBUFFERS_ASSERT(i < size()); + return IndirectHelper::Read(Data(), i); + } + + return_type operator[](uoffset_t i) const + { + return Get(i); + } + + // If this is a Vector of enums, T will be its storage type, not the enum + // type. This function makes it convenient to retrieve value with enum + // type E. + template + E GetEnum(uoffset_t i) const + { + return static_cast(Get(i)); + } + + const_iterator begin() const + { + return const_iterator(Data(), 0); + } + const_iterator end() const + { + return const_iterator(Data(), size()); + } + + const_reverse_iterator rbegin() const + { + return const_reverse_iterator(end()); + } + const_reverse_iterator rend() const + { + return const_reverse_iterator(end()); + } + + const_iterator cbegin() const + { + return begin(); + } + const_iterator cend() const + { + return end(); + } + + const_reverse_iterator crbegin() const + { + return rbegin(); + } + const_reverse_iterator crend() const + { + return rend(); + } + + // Get a mutable pointer to elements inside this array. + // This method used to mutate arrays of structs followed by a @p Mutate + // operation. For primitive types use @p Mutate directly. + // @warning Assignments and reads to/from the dereferenced pointer are not + // automatically converted to the correct endianness. + typename flatbuffers::conditional::type + GetMutablePointer(uoffset_t i) const + { + FLATBUFFERS_ASSERT(i < size()); + return const_cast(&data()[i]); + } + + // Change elements if you have a non-const pointer to this object. + void Mutate(uoffset_t i, const T &val) + { + MutateImpl(scalar_tag(), i, val); + } + + // The raw data in little endian format. Use with care. + const uint8_t *Data() const + { + return data_; + } + + uint8_t *Data() + { + return data_; + } + + // Similarly, but typed, much like std::vector::data + const T *data() const + { + return reinterpret_cast(Data()); + } + T *data() + { + return reinterpret_cast(Data()); + } + +protected: + void MutateImpl(flatbuffers::integral_constant, uoffset_t i, + const T &val) + { + FLATBUFFERS_ASSERT(i < size()); + WriteScalar(data() + i, val); + } + + void MutateImpl(flatbuffers::integral_constant, uoffset_t i, + const T &val) + { + *(GetMutablePointer(i)) = val; + } + + // This class is only used to access pre-existing data. Don't ever + // try to construct these manually. + // 'constexpr' allows us to use 'size()' at compile time. + // @note Must not use 'FLATBUFFERS_CONSTEXPR' here, as const is not allowed on + // a constructor. +#if defined(__cpp_constexpr) + constexpr Array(); +#else + Array(); +#endif + + uint8_t data_[length * sizeof(T)]; + +private: + // This class is a pointer. Copying will therefore create an invalid object. + // Private and unimplemented copy constructor. + Array(const Array &); + Array &operator=(const Array &); +}; + +// Specialization for Array[struct] with access using Offset pointer. +// This specialization used by idl_gen_text.cpp. +template +class Array, length> { + static_assert(flatbuffers::is_same::value, "unexpected type T"); + +public: + typedef const void *return_type; + + const uint8_t *Data() const + { + return data_; + } + + // Make idl_gen_text.cpp::PrintContainer happy. + return_type operator[](uoffset_t) const + { + FLATBUFFERS_ASSERT(false); + return nullptr; + } + +private: + // This class is only used to access pre-existing data. + Array(); + Array(const Array &); + Array &operator=(const Array &); + + uint8_t data_[1]; +}; + +// Lexicographically compare two strings (possibly containing nulls), and +// return true if the first is less than the second. +static inline bool StringLessThan(const char *a_data, uoffset_t a_size, + const char *b_data, uoffset_t b_size) +{ + const auto cmp = memcmp(a_data, b_data, (std::min)(a_size, b_size)); + return cmp == 0 ? a_size < b_size : cmp < 0; +} + +struct String : public Vector { + const char *c_str() const + { + return reinterpret_cast(Data()); + } + std::string str() const + { + return std::string(c_str(), size()); + } + + // clang-format off + #ifdef FLATBUFFERS_HAS_STRING_VIEW + flatbuffers::string_view string_view() const { + return flatbuffers::string_view(c_str(), size()); + } + #endif // FLATBUFFERS_HAS_STRING_VIEW + // clang-format on + + bool operator<(const String &o) const + { + return StringLessThan(this->data(), this->size(), o.data(), o.size()); + } +}; + +// Convenience function to get std::string from a String returning an empty +// string on null pointer. +static inline std::string GetString(const String *str) +{ + return str ? str->str() : ""; +} + +// Convenience function to get char* from a String returning an empty string on +// null pointer. +static inline const char *GetCstring(const String *str) +{ + return str ? str->c_str() : ""; +} + +#ifdef FLATBUFFERS_HAS_STRING_VIEW +// Convenience function to get string_view from a String returning an empty +// string_view on null pointer. +static inline flatbuffers::string_view GetStringView(const String *str) +{ + return str ? str->string_view() : flatbuffers::string_view(); +} +#endif // FLATBUFFERS_HAS_STRING_VIEW + +// Allocator interface. This is flatbuffers-specific and meant only for +// `vector_downward` usage. +class Allocator { +public: + virtual ~Allocator() + { + } + + // Allocate `size` bytes of memory. + virtual uint8_t *allocate(size_t size) = 0; + + // Deallocate `size` bytes of memory at `p` allocated by this allocator. + virtual void deallocate(uint8_t *p, size_t size) = 0; + + // Reallocate `new_size` bytes of memory, replacing the old region of size + // `old_size` at `p`. In contrast to a normal realloc, this grows downwards, + // and is intended specifcally for `vector_downward` use. + // `in_use_back` and `in_use_front` indicate how much of `old_size` is + // actually in use at each end, and needs to be copied. + virtual uint8_t *reallocate_downward(uint8_t *old_p, size_t old_size, + size_t new_size, size_t in_use_back, + size_t in_use_front) + { + FLATBUFFERS_ASSERT(new_size > old_size); // vector_downward only grows + uint8_t *new_p = allocate(new_size); + memcpy_downward(old_p, old_size, new_p, new_size, in_use_back, + in_use_front); + deallocate(old_p, old_size); + return new_p; + } + +protected: + // Called by `reallocate_downward` to copy memory from `old_p` of `old_size` + // to `new_p` of `new_size`. Only memory of size `in_use_front` and + // `in_use_back` will be copied from the front and back of the old memory + // allocation. + void memcpy_downward(uint8_t *old_p, size_t old_size, uint8_t *new_p, + size_t new_size, size_t in_use_back, + size_t in_use_front) + { + memcpy(new_p + new_size - in_use_back, old_p + old_size - in_use_back, + in_use_back); + memcpy(new_p, old_p, in_use_front); + } +}; + +// DefaultAllocator uses new/delete to allocate memory regions +class DefaultAllocator : public Allocator { +public: + uint8_t *allocate(size_t size) FLATBUFFERS_OVERRIDE + { + return new uint8_t[size]; + } + + void deallocate(uint8_t *p, size_t) FLATBUFFERS_OVERRIDE + { + delete[] p; + } + + static void dealloc(void *p, size_t) + { + delete[] static_cast(p); + } +}; + +// These functions allow for a null allocator to mean use the default allocator, +// as used by DetachedBuffer and vector_downward below. +// This is to avoid having a statically or dynamically allocated default +// allocator, or having to move it between the classes that may own it. +inline uint8_t *Allocate(Allocator *allocator, size_t size) +{ + return allocator ? allocator->allocate(size) : DefaultAllocator().allocate(size); +} + +inline void Deallocate(Allocator *allocator, uint8_t *p, size_t size) +{ + if (allocator) + allocator->deallocate(p, size); + else + DefaultAllocator().deallocate(p, size); +} + +inline uint8_t *ReallocateDownward(Allocator *allocator, uint8_t *old_p, + size_t old_size, size_t new_size, + size_t in_use_back, size_t in_use_front) +{ + return allocator ? allocator->reallocate_downward(old_p, old_size, new_size, + in_use_back, in_use_front) : + DefaultAllocator().reallocate_downward( + old_p, old_size, new_size, in_use_back, in_use_front); +} + +// DetachedBuffer is a finished flatbuffer memory region, detached from its +// builder. The original memory region and allocator are also stored so that +// the DetachedBuffer can manage the memory lifetime. +class DetachedBuffer { +public: + DetachedBuffer() + : allocator_(nullptr), + own_allocator_(false), + buf_(nullptr), + reserved_(0), + cur_(nullptr), + size_(0) + { + } + + DetachedBuffer(Allocator *allocator, bool own_allocator, uint8_t *buf, + size_t reserved, uint8_t *cur, size_t sz) + : allocator_(allocator), + own_allocator_(own_allocator), + buf_(buf), + reserved_(reserved), + cur_(cur), + size_(sz) + { + } + + // clang-format off + #if !defined(FLATBUFFERS_CPP98_STL) + // clang-format on + DetachedBuffer(DetachedBuffer &&other) + : allocator_(other.allocator_), + own_allocator_(other.own_allocator_), + buf_(other.buf_), + reserved_(other.reserved_), + cur_(other.cur_), + size_(other.size_) + { + other.reset(); + } + // clang-format off + #endif // !defined(FLATBUFFERS_CPP98_STL) + // clang-format on + + // clang-format off + #if !defined(FLATBUFFERS_CPP98_STL) + // clang-format on + DetachedBuffer &operator=(DetachedBuffer &&other) + { + if (this == &other) + return *this; + + destroy(); + + allocator_ = other.allocator_; + own_allocator_ = other.own_allocator_; + buf_ = other.buf_; + reserved_ = other.reserved_; + cur_ = other.cur_; + size_ = other.size_; + + other.reset(); + + return *this; + } + // clang-format off + #endif // !defined(FLATBUFFERS_CPP98_STL) + // clang-format on + + ~DetachedBuffer() + { + destroy(); + } + + const uint8_t *data() const + { + return cur_; + } + + uint8_t *data() + { + return cur_; + } + + size_t size() const + { + return size_; + } + + // clang-format off + #if 0 // disabled for now due to the ordering of classes in this header + template + bool Verify() const { + Verifier verifier(data(), size()); + return verifier.Verify(nullptr); + } + + template + const T* GetRoot() const { + return flatbuffers::GetRoot(data()); + } + + template + T* GetRoot() { + return flatbuffers::GetRoot(data()); + } + #endif + // clang-format on + + // clang-format off + #if !defined(FLATBUFFERS_CPP98_STL) + // clang-format on + // These may change access mode, leave these at end of public section + FLATBUFFERS_DELETE_FUNC(DetachedBuffer(const DetachedBuffer &other)) + FLATBUFFERS_DELETE_FUNC( + DetachedBuffer &operator=(const DetachedBuffer &other)) + // clang-format off + #endif // !defined(FLATBUFFERS_CPP98_STL) + // clang-format on + +protected: + Allocator *allocator_; + bool own_allocator_; + uint8_t *buf_; + size_t reserved_; + uint8_t *cur_; + size_t size_; + + inline void destroy() + { + if (buf_) + Deallocate(allocator_, buf_, reserved_); + if (own_allocator_ && allocator_) { + delete allocator_; + } + reset(); + } + + inline void reset() + { + allocator_ = nullptr; + own_allocator_ = false; + buf_ = nullptr; + reserved_ = 0; + cur_ = nullptr; + size_ = 0; + } +}; + +// This is a minimal replication of std::vector functionality, +// except growing from higher to lower addresses. i.e push_back() inserts data +// in the lowest address in the vector. +// Since this vector leaves the lower part unused, we support a "scratch-pad" +// that can be stored there for temporary data, to share the allocated space. +// Essentially, this supports 2 std::vectors in a single buffer. +class vector_downward { +public: + explicit vector_downward(size_t initial_size, Allocator *allocator, + bool own_allocator, size_t buffer_minalign) + : allocator_(allocator), + own_allocator_(own_allocator), + initial_size_(initial_size), + buffer_minalign_(buffer_minalign), + reserved_(0), + buf_(nullptr), + cur_(nullptr), + scratch_(nullptr) + { + } + + // clang-format off + #if !defined(FLATBUFFERS_CPP98_STL) + vector_downward(vector_downward &&other) + #else + vector_downward(vector_downward &other) + #endif // defined(FLATBUFFERS_CPP98_STL) + // clang-format on + : allocator_(other.allocator_), + own_allocator_(other.own_allocator_), + initial_size_(other.initial_size_), + buffer_minalign_(other.buffer_minalign_), + reserved_(other.reserved_), + buf_(other.buf_), + cur_(other.cur_), + scratch_(other.scratch_) + { + // No change in other.allocator_ + // No change in other.initial_size_ + // No change in other.buffer_minalign_ + other.own_allocator_ = false; + other.reserved_ = 0; + other.buf_ = nullptr; + other.cur_ = nullptr; + other.scratch_ = nullptr; + } + + // clang-format off + #if !defined(FLATBUFFERS_CPP98_STL) + // clang-format on + vector_downward &operator=(vector_downward &&other) + { + // Move construct a temporary and swap idiom + vector_downward temp(std::move(other)); + swap(temp); + return *this; + } + // clang-format off + #endif // defined(FLATBUFFERS_CPP98_STL) + // clang-format on + + ~vector_downward() + { + clear_buffer(); + clear_allocator(); + } + + void reset() + { + clear_buffer(); + clear(); + } + + void clear() + { + if (buf_) { + cur_ = buf_ + reserved_; + } else { + reserved_ = 0; + cur_ = nullptr; + } + clear_scratch(); + } + + void clear_scratch() + { + scratch_ = buf_; + } + + void clear_allocator() + { + if (own_allocator_ && allocator_) { + delete allocator_; + } + allocator_ = nullptr; + own_allocator_ = false; + } + + void clear_buffer() + { + if (buf_) + Deallocate(allocator_, buf_, reserved_); + buf_ = nullptr; + } + + // Relinquish the pointer to the caller. + uint8_t *release_raw(size_t &allocated_bytes, size_t &offset) + { + auto *buf = buf_; + allocated_bytes = reserved_; + offset = static_cast(cur_ - buf_); + + // release_raw only relinquishes the buffer ownership. + // Does not deallocate or reset the allocator. Destructor will do that. + buf_ = nullptr; + clear(); + return buf; + } + + // Relinquish the pointer to the caller. + DetachedBuffer release() + { + // allocator ownership (if any) is transferred to DetachedBuffer. + DetachedBuffer fb(allocator_, own_allocator_, buf_, reserved_, cur_, + size()); + if (own_allocator_) { + allocator_ = nullptr; + own_allocator_ = false; + } + buf_ = nullptr; + clear(); + return fb; + } + + size_t ensure_space(size_t len) + { + FLATBUFFERS_ASSERT(cur_ >= scratch_ && scratch_ >= buf_); + if (len > static_cast(cur_ - scratch_)) { + reallocate(len); + } + // Beyond this, signed offsets may not have enough range: + // (FlatBuffers > 2GB not supported). + FLATBUFFERS_ASSERT(size() < FLATBUFFERS_MAX_BUFFER_SIZE); + return len; + } + + inline uint8_t *make_space(size_t len) + { + size_t space = ensure_space(len); + cur_ -= space; + return cur_; + } + + // Returns nullptr if using the DefaultAllocator. + Allocator *get_custom_allocator() + { + return allocator_; + } + + uoffset_t size() const + { + return static_cast(reserved_ - (cur_ - buf_)); + } + + uoffset_t scratch_size() const + { + return static_cast(scratch_ - buf_); + } + + size_t capacity() const + { + return reserved_; + } + + uint8_t *data() const + { + FLATBUFFERS_ASSERT(cur_); + return cur_; + } + + uint8_t *scratch_data() const + { + FLATBUFFERS_ASSERT(buf_); + return buf_; + } + + uint8_t *scratch_end() const + { + FLATBUFFERS_ASSERT(scratch_); + return scratch_; + } + + uint8_t *data_at(size_t offset) const + { + return buf_ + reserved_ - offset; + } + + void push(const uint8_t *bytes, size_t num) + { + if (num > 0) { + memcpy(make_space(num), bytes, num); + } + } + + // Specialized version of push() that avoids memcpy call for small data. + template + void push_small(const T &little_endian_t) + { + make_space(sizeof(T)); + *reinterpret_cast(cur_) = little_endian_t; + } + + template + void scratch_push_small(const T &t) + { + ensure_space(sizeof(T)); + *reinterpret_cast(scratch_) = t; + scratch_ += sizeof(T); + } + + // fill() is most frequently called with small byte counts (<= 4), + // which is why we're using loops rather than calling memset. + void fill(size_t zero_pad_bytes) + { + make_space(zero_pad_bytes); + for (size_t i = 0; i < zero_pad_bytes; i++) + cur_[i] = 0; + } + + // Version for when we know the size is larger. + // Precondition: zero_pad_bytes > 0 + void fill_big(size_t zero_pad_bytes) + { + memset(make_space(zero_pad_bytes), 0, zero_pad_bytes); + } + + void pop(size_t bytes_to_remove) + { + cur_ += bytes_to_remove; + } + void scratch_pop(size_t bytes_to_remove) + { + scratch_ -= bytes_to_remove; + } + + void swap(vector_downward &other) + { + using std::swap; + swap(allocator_, other.allocator_); + swap(own_allocator_, other.own_allocator_); + swap(initial_size_, other.initial_size_); + swap(buffer_minalign_, other.buffer_minalign_); + swap(reserved_, other.reserved_); + swap(buf_, other.buf_); + swap(cur_, other.cur_); + swap(scratch_, other.scratch_); + } + + void swap_allocator(vector_downward &other) + { + using std::swap; + swap(allocator_, other.allocator_); + swap(own_allocator_, other.own_allocator_); + } + +private: + // You shouldn't really be copying instances of this class. + FLATBUFFERS_DELETE_FUNC(vector_downward(const vector_downward &)) + FLATBUFFERS_DELETE_FUNC(vector_downward &operator=(const vector_downward &)) + + Allocator *allocator_; + bool own_allocator_; + size_t initial_size_; + size_t buffer_minalign_; + size_t reserved_; + uint8_t *buf_; + uint8_t *cur_; // Points at location between empty (below) and used (above). + uint8_t *scratch_; // Points to the end of the scratchpad in use. + + void reallocate(size_t len) + { + auto old_reserved = reserved_; + auto old_size = size(); + auto old_scratch_size = scratch_size(); + reserved_ += + (std::max)(len, old_reserved ? old_reserved / 2 : initial_size_); + reserved_ = (reserved_ + buffer_minalign_ - 1) & ~(buffer_minalign_ - 1); + if (buf_) { + buf_ = ReallocateDownward(allocator_, buf_, old_reserved, reserved_, + old_size, old_scratch_size); + } else { + buf_ = Allocate(allocator_, reserved_); + } + cur_ = buf_ + reserved_ - old_size; + scratch_ = buf_ + old_scratch_size; + } +}; + +// Converts a Field ID to a virtual table offset. +inline voffset_t FieldIndexToOffset(voffset_t field_id) +{ + // Should correspond to what EndTable() below builds up. + const int fixed_fields = 2; // Vtable size and Object Size. + return static_cast((field_id + fixed_fields) * sizeof(voffset_t)); +} + +template +const T *data(const std::vector &v) +{ + // Eventually the returned pointer gets passed down to memcpy, so + // we need it to be non-null to avoid undefined behavior. + static uint8_t t; + return v.empty() ? reinterpret_cast(&t) : &v.front(); +} +template +T *data(std::vector &v) +{ + // Eventually the returned pointer gets passed down to memcpy, so + // we need it to be non-null to avoid undefined behavior. + static uint8_t t; + return v.empty() ? reinterpret_cast(&t) : &v.front(); +} + +/// @endcond + +/// @addtogroup flatbuffers_cpp_api +/// @{ +/// @class FlatBufferBuilder +/// @brief Helper class to hold data needed in creation of a FlatBuffer. +/// To serialize data, you typically call one of the `Create*()` functions in +/// the generated code, which in turn call a sequence of `StartTable`/ +/// `PushElement`/`AddElement`/`EndTable`, or the builtin `CreateString`/ +/// `CreateVector` functions. Do this is depth-first order to build up a tree to +/// the root. `Finish()` wraps up the buffer ready for transport. +class FlatBufferBuilder { +public: + /// @brief Default constructor for FlatBufferBuilder. + /// @param[in] initial_size The initial size of the buffer, in bytes. Defaults + /// to `1024`. + /// @param[in] allocator An `Allocator` to use. If null will use + /// `DefaultAllocator`. + /// @param[in] own_allocator Whether the builder/vector should own the + /// allocator. Defaults to / `false`. + /// @param[in] buffer_minalign Force the buffer to be aligned to the given + /// minimum alignment upon reallocation. Only needed if you intend to store + /// types with custom alignment AND you wish to read the buffer in-place + /// directly after creation. + explicit FlatBufferBuilder( + size_t initial_size = 1024, Allocator *allocator = nullptr, + bool own_allocator = false, + size_t buffer_minalign = AlignOf()) + : buf_(initial_size, allocator, own_allocator, buffer_minalign), + num_field_loc(0), + max_voffset_(0), + nested(false), + finished(false), + minalign_(1), + force_defaults_(false), + dedup_vtables_(true), + string_pool(nullptr) + { + EndianCheck(); + } + + // clang-format off + /// @brief Move constructor for FlatBufferBuilder. + #if !defined(FLATBUFFERS_CPP98_STL) + FlatBufferBuilder(FlatBufferBuilder &&other) + #else + FlatBufferBuilder(FlatBufferBuilder &other) + #endif // #if !defined(FLATBUFFERS_CPP98_STL) + : buf_(1024, nullptr, false, AlignOf()), + num_field_loc(0), + max_voffset_(0), + nested(false), + finished(false), + minalign_(1), + force_defaults_(false), + dedup_vtables_(true), + string_pool(nullptr) { + EndianCheck(); + // Default construct and swap idiom. + // Lack of delegating constructors in vs2010 makes it more verbose than needed. + Swap(other); + } + // clang-format on + + // clang-format off + #if !defined(FLATBUFFERS_CPP98_STL) + // clang-format on + /// @brief Move assignment operator for FlatBufferBuilder. + FlatBufferBuilder &operator=(FlatBufferBuilder &&other) + { + // Move construct a temporary and swap idiom + FlatBufferBuilder temp(std::move(other)); + Swap(temp); + return *this; + } + // clang-format off + #endif // defined(FLATBUFFERS_CPP98_STL) + // clang-format on + + void Swap(FlatBufferBuilder &other) + { + using std::swap; + buf_.swap(other.buf_); + swap(num_field_loc, other.num_field_loc); + swap(max_voffset_, other.max_voffset_); + swap(nested, other.nested); + swap(finished, other.finished); + swap(minalign_, other.minalign_); + swap(force_defaults_, other.force_defaults_); + swap(dedup_vtables_, other.dedup_vtables_); + swap(string_pool, other.string_pool); + } + + ~FlatBufferBuilder() + { + if (string_pool) + delete string_pool; + } + + void Reset() + { + Clear(); // clear builder state + buf_.reset(); // deallocate buffer + } + + /// @brief Reset all the state in this FlatBufferBuilder so it can be reused + /// to construct another buffer. + void Clear() + { + ClearOffsets(); + buf_.clear(); + nested = false; + finished = false; + minalign_ = 1; + if (string_pool) + string_pool->clear(); + } + + /// @brief The current size of the serialized buffer, counting from the end. + /// @return Returns an `uoffset_t` with the current size of the buffer. + uoffset_t GetSize() const + { + return buf_.size(); + } + + /// @brief Get the serialized buffer (after you call `Finish()`). + /// @return Returns an `uint8_t` pointer to the FlatBuffer data inside the + /// buffer. + uint8_t *GetBufferPointer() const + { + Finished(); + return buf_.data(); + } + + /// @brief Get a pointer to an unfinished buffer. + /// @return Returns a `uint8_t` pointer to the unfinished buffer. + uint8_t *GetCurrentBufferPointer() const + { + return buf_.data(); + } + + /// @brief Get the released pointer to the serialized buffer. + /// @warning Do NOT attempt to use this FlatBufferBuilder afterwards! + /// @return A `FlatBuffer` that owns the buffer and its allocator and + /// behaves similar to a `unique_ptr` with a deleter. + FLATBUFFERS_ATTRIBUTE(deprecated("use Release() instead")) + DetachedBuffer ReleaseBufferPointer() + { + Finished(); + return buf_.release(); + } + + /// @brief Get the released DetachedBuffer. + /// @return A `DetachedBuffer` that owns the buffer and its allocator. + DetachedBuffer Release() + { + Finished(); + return buf_.release(); + } + + /// @brief Get the released pointer to the serialized buffer. + /// @param size The size of the memory block containing + /// the serialized `FlatBuffer`. + /// @param offset The offset from the released pointer where the finished + /// `FlatBuffer` starts. + /// @return A raw pointer to the start of the memory block containing + /// the serialized `FlatBuffer`. + /// @remark If the allocator is owned, it gets deleted when the destructor is + /// called.. + uint8_t *ReleaseRaw(size_t &size, size_t &offset) + { + Finished(); + return buf_.release_raw(size, offset); + } + + /// @brief get the minimum alignment this buffer needs to be accessed + /// properly. This is only known once all elements have been written (after + /// you call Finish()). You can use this information if you need to embed + /// a FlatBuffer in some other buffer, such that you can later read it + /// without first having to copy it into its own buffer. + size_t GetBufferMinAlignment() const + { + Finished(); + return minalign_; + } + + /// @cond FLATBUFFERS_INTERNAL + void Finished() const + { + // If you get this assert, you're attempting to get access a buffer + // which hasn't been finished yet. Be sure to call + // FlatBufferBuilder::Finish with your root table. + // If you really need to access an unfinished buffer, call + // GetCurrentBufferPointer instead. + FLATBUFFERS_ASSERT(finished); + } + /// @endcond + + /// @brief In order to save space, fields that are set to their default value + /// don't get serialized into the buffer. + /// @param[in] fd When set to `true`, always serializes default values that + /// are set. Optional fields which are not set explicitly, will still not be + /// serialized. + void ForceDefaults(bool fd) + { + force_defaults_ = fd; + } + + /// @brief By default vtables are deduped in order to save space. + /// @param[in] dedup When set to `true`, dedup vtables. + void DedupVtables(bool dedup) + { + dedup_vtables_ = dedup; + } + + /// @cond FLATBUFFERS_INTERNAL + void Pad(size_t num_bytes) + { + buf_.fill(num_bytes); + } + + void TrackMinAlign(size_t elem_size) + { + if (elem_size > minalign_) + minalign_ = elem_size; + } + + void Align(size_t elem_size) + { + TrackMinAlign(elem_size); + buf_.fill(PaddingBytes(buf_.size(), elem_size)); + } + + void PushFlatBuffer(const uint8_t *bytes, size_t size) + { + PushBytes(bytes, size); + finished = true; + } + + void PushBytes(const uint8_t *bytes, size_t size) + { + buf_.push(bytes, size); + } + + void PopBytes(size_t amount) + { + buf_.pop(amount); + } + + template + void AssertScalarT() + { + // The code assumes power of 2 sizes and endian-swap-ability. + static_assert(flatbuffers::is_scalar::value, "T must be a scalar type"); + } + + // Write a single aligned scalar to the buffer + template + uoffset_t PushElement(T element) + { + AssertScalarT(); + T litle_endian_element = EndianScalar(element); + Align(sizeof(T)); + buf_.push_small(litle_endian_element); + return GetSize(); + } + + template + uoffset_t PushElement(Offset off) + { + // Special case for offsets: see ReferTo below. + return PushElement(ReferTo(off.o)); + } + + // When writing fields, we track where they are, so we can create correct + // vtables later. + void TrackField(voffset_t field, uoffset_t off) + { + FieldLoc fl = { off, field }; + buf_.scratch_push_small(fl); + num_field_loc++; + max_voffset_ = (std::max)(max_voffset_, field); + } + + // Like PushElement, but additionally tracks the field this represents. + template + void AddElement(voffset_t field, T e, T def) + { + // We don't serialize values equal to the default. + if (IsTheSameAs(e, def) && !force_defaults_) + return; + auto off = PushElement(e); + TrackField(field, off); + } + + template + void AddElement(voffset_t field, T e) + { + auto off = PushElement(e); + TrackField(field, off); + } + + template + void AddOffset(voffset_t field, Offset off) + { + if (off.IsNull()) + return; // Don't store. + AddElement(field, ReferTo(off.o), static_cast(0)); + } + + template + void AddStruct(voffset_t field, const T *structptr) + { + if (!structptr) + return; // Default, don't store. + Align(AlignOf()); + buf_.push_small(*structptr); + TrackField(field, GetSize()); + } + + void AddStructOffset(voffset_t field, uoffset_t off) + { + TrackField(field, off); + } + + // Offsets initially are relative to the end of the buffer (downwards). + // This function converts them to be relative to the current location + // in the buffer (when stored here), pointing upwards. + uoffset_t ReferTo(uoffset_t off) + { + // Align to ensure GetSize() below is correct. + Align(sizeof(uoffset_t)); + // Offset must refer to something already in buffer. + FLATBUFFERS_ASSERT(off && off <= GetSize()); + return GetSize() - off + static_cast(sizeof(uoffset_t)); + } + + void NotNested() + { + // If you hit this, you're trying to construct a Table/Vector/String + // during the construction of its parent table (between the MyTableBuilder + // and table.Finish(). + // Move the creation of these sub-objects to above the MyTableBuilder to + // not get this assert. + // Ignoring this assert may appear to work in simple cases, but the reason + // it is here is that storing objects in-line may cause vtable offsets + // to not fit anymore. It also leads to vtable duplication. + FLATBUFFERS_ASSERT(!nested); + // If you hit this, fields were added outside the scope of a table. + FLATBUFFERS_ASSERT(!num_field_loc); + } + + // From generated code (or from the parser), we call StartTable/EndTable + // with a sequence of AddElement calls in between. + uoffset_t StartTable() + { + NotNested(); + nested = true; + return GetSize(); + } + + // This finishes one serialized object by generating the vtable if it's a + // table, comparing it against existing vtables, and writing the + // resulting vtable offset. + uoffset_t EndTable(uoffset_t start) + { + // If you get this assert, a corresponding StartTable wasn't called. + FLATBUFFERS_ASSERT(nested); + // Write the vtable offset, which is the start of any Table. + // We fill it's value later. + auto vtableoffsetloc = PushElement(0); + // Write a vtable, which consists entirely of voffset_t elements. + // It starts with the number of offsets, followed by a type id, followed + // by the offsets themselves. In reverse: + // Include space for the last offset and ensure empty tables have a + // minimum size. + max_voffset_ = + (std::max)(static_cast(max_voffset_ + sizeof(voffset_t)), + FieldIndexToOffset(0)); + buf_.fill_big(max_voffset_); + auto table_object_size = vtableoffsetloc - start; + // Vtable use 16bit offsets. + FLATBUFFERS_ASSERT(table_object_size < 0x10000); + WriteScalar(buf_.data() + sizeof(voffset_t), + static_cast(table_object_size)); + WriteScalar(buf_.data(), max_voffset_); + // Write the offsets into the table + for (auto it = buf_.scratch_end() - num_field_loc * sizeof(FieldLoc); + it < buf_.scratch_end(); it += sizeof(FieldLoc)) { + auto field_location = reinterpret_cast(it); + auto pos = static_cast(vtableoffsetloc - field_location->off); + // If this asserts, it means you've set a field twice. + FLATBUFFERS_ASSERT( + !ReadScalar(buf_.data() + field_location->id)); + WriteScalar(buf_.data() + field_location->id, pos); + } + ClearOffsets(); + auto vt1 = reinterpret_cast(buf_.data()); + auto vt1_size = ReadScalar(vt1); + auto vt_use = GetSize(); + // See if we already have generated a vtable with this exact same + // layout before. If so, make it point to the old one, remove this one. + if (dedup_vtables_) { + for (auto it = buf_.scratch_data(); it < buf_.scratch_end(); + it += sizeof(uoffset_t)) { + auto vt_offset_ptr = reinterpret_cast(it); + auto vt2 = reinterpret_cast(buf_.data_at(*vt_offset_ptr)); + auto vt2_size = ReadScalar(vt2); + if (vt1_size != vt2_size || 0 != memcmp(vt2, vt1, vt1_size)) + continue; + vt_use = *vt_offset_ptr; + buf_.pop(GetSize() - vtableoffsetloc); + break; + } + } + // If this is a new vtable, remember it. + if (vt_use == GetSize()) { + buf_.scratch_push_small(vt_use); + } + // Fill the vtable offset we created above. + // The offset points from the beginning of the object to where the + // vtable is stored. + // Offsets default direction is downward in memory for future format + // flexibility (storing all vtables at the start of the file). + WriteScalar(buf_.data_at(vtableoffsetloc), + static_cast(vt_use) - + static_cast(vtableoffsetloc)); + + nested = false; + return vtableoffsetloc; + } + + FLATBUFFERS_ATTRIBUTE(deprecated("call the version above instead")) + uoffset_t EndTable(uoffset_t start, voffset_t /*numfields*/) + { + return EndTable(start); + } + + // This checks a required field has been set in a given table that has + // just been constructed. + template + void Required(Offset table, voffset_t field); + + uoffset_t StartStruct(size_t alignment) + { + Align(alignment); + return GetSize(); + } + + uoffset_t EndStruct() + { + return GetSize(); + } + + void ClearOffsets() + { + buf_.scratch_pop(num_field_loc * sizeof(FieldLoc)); + num_field_loc = 0; + max_voffset_ = 0; + } + + // Aligns such that when "len" bytes are written, an object can be written + // after it with "alignment" without padding. + void PreAlign(size_t len, size_t alignment) + { + TrackMinAlign(alignment); + buf_.fill(PaddingBytes(GetSize() + len, alignment)); + } + template + void PreAlign(size_t len) + { + AssertScalarT(); + PreAlign(len, sizeof(T)); + } + /// @endcond + + /// @brief Store a string in the buffer, which can contain any binary data. + /// @param[in] str A const char pointer to the data to be stored as a string. + /// @param[in] len The number of bytes that should be stored from `str`. + /// @return Returns the offset in the buffer where the string starts. + Offset CreateString(const char *str, size_t len) + { + NotNested(); + PreAlign(len + 1); // Always 0-terminated. + buf_.fill(1); + PushBytes(reinterpret_cast(str), len); + PushElement(static_cast(len)); + return Offset(GetSize()); + } + + /// @brief Store a string in the buffer, which is null-terminated. + /// @param[in] str A const char pointer to a C-string to add to the buffer. + /// @return Returns the offset in the buffer where the string starts. + Offset CreateString(const char *str) + { + return CreateString(str, strlen(str)); + } + + /// @brief Store a string in the buffer, which is null-terminated. + /// @param[in] str A char pointer to a C-string to add to the buffer. + /// @return Returns the offset in the buffer where the string starts. + Offset CreateString(char *str) + { + return CreateString(str, strlen(str)); + } + + /// @brief Store a string in the buffer, which can contain any binary data. + /// @param[in] str A const reference to a std::string to store in the buffer. + /// @return Returns the offset in the buffer where the string starts. + Offset CreateString(const std::string &str) + { + return CreateString(str.c_str(), str.length()); + } + + // clang-format off + #ifdef FLATBUFFERS_HAS_STRING_VIEW + /// @brief Store a string in the buffer, which can contain any binary data. + /// @param[in] str A const string_view to copy in to the buffer. + /// @return Returns the offset in the buffer where the string starts. + Offset CreateString(flatbuffers::string_view str) { + return CreateString(str.data(), str.size()); + } + #endif // FLATBUFFERS_HAS_STRING_VIEW + // clang-format on + + /// @brief Store a string in the buffer, which can contain any binary data. + /// @param[in] str A const pointer to a `String` struct to add to the buffer. + /// @return Returns the offset in the buffer where the string starts + Offset CreateString(const String *str) + { + return str ? CreateString(str->c_str(), str->size()) : 0; + } + + /// @brief Store a string in the buffer, which can contain any binary data. + /// @param[in] str A const reference to a std::string like type with support + /// of T::c_str() and T::length() to store in the buffer. + /// @return Returns the offset in the buffer where the string starts. + template + Offset CreateString(const T &str) + { + return CreateString(str.c_str(), str.length()); + } + + /// @brief Store a string in the buffer, which can contain any binary data. + /// If a string with this exact contents has already been serialized before, + /// instead simply returns the offset of the existing string. + /// @param[in] str A const char pointer to the data to be stored as a string. + /// @param[in] len The number of bytes that should be stored from `str`. + /// @return Returns the offset in the buffer where the string starts. + Offset CreateSharedString(const char *str, size_t len) + { + if (!string_pool) + string_pool = new StringOffsetMap(StringOffsetCompare(buf_)); + auto size_before_string = buf_.size(); + // Must first serialize the string, since the set is all offsets into + // buffer. + auto off = CreateString(str, len); + auto it = string_pool->find(off); + // If it exists we reuse existing serialized data! + if (it != string_pool->end()) { + // We can remove the string we serialized. + buf_.pop(buf_.size() - size_before_string); + return *it; + } + // Record this string for future use. + string_pool->insert(off); + return off; + } + + /// @brief Store a string in the buffer, which null-terminated. + /// If a string with this exact contents has already been serialized before, + /// instead simply returns the offset of the existing string. + /// @param[in] str A const char pointer to a C-string to add to the buffer. + /// @return Returns the offset in the buffer where the string starts. + Offset CreateSharedString(const char *str) + { + return CreateSharedString(str, strlen(str)); + } + + /// @brief Store a string in the buffer, which can contain any binary data. + /// If a string with this exact contents has already been serialized before, + /// instead simply returns the offset of the existing string. + /// @param[in] str A const reference to a std::string to store in the buffer. + /// @return Returns the offset in the buffer where the string starts. + Offset CreateSharedString(const std::string &str) + { + return CreateSharedString(str.c_str(), str.length()); + } + + /// @brief Store a string in the buffer, which can contain any binary data. + /// If a string with this exact contents has already been serialized before, + /// instead simply returns the offset of the existing string. + /// @param[in] str A const pointer to a `String` struct to add to the buffer. + /// @return Returns the offset in the buffer where the string starts + Offset CreateSharedString(const String *str) + { + return CreateSharedString(str->c_str(), str->size()); + } + + /// @cond FLATBUFFERS_INTERNAL + uoffset_t EndVector(size_t len) + { + FLATBUFFERS_ASSERT(nested); // Hit if no corresponding StartVector. + nested = false; + return PushElement(static_cast(len)); + } + + void StartVector(size_t len, size_t elemsize) + { + NotNested(); + nested = true; + PreAlign(len * elemsize); + PreAlign(len * elemsize, elemsize); // Just in case elemsize > uoffset_t. + } + + // Call this right before StartVector/CreateVector if you want to force the + // alignment to be something different than what the element size would + // normally dictate. + // This is useful when storing a nested_flatbuffer in a vector of bytes, + // or when storing SIMD floats, etc. + void ForceVectorAlignment(size_t len, size_t elemsize, size_t alignment) + { + PreAlign(len * elemsize, alignment); + } + + // Similar to ForceVectorAlignment but for String fields. + void ForceStringAlignment(size_t len, size_t alignment) + { + PreAlign((len + 1) * sizeof(char), alignment); + } + + /// @endcond + + /// @brief Serialize an array into a FlatBuffer `vector`. + /// @tparam T The data type of the array elements. + /// @param[in] v A pointer to the array of type `T` to serialize into the + /// buffer as a `vector`. + /// @param[in] len The number of elements to serialize. + /// @return Returns a typed `Offset` into the serialized data indicating + /// where the vector is stored. + template + Offset > CreateVector(const T *v, size_t len) + { + // If this assert hits, you're specifying a template argument that is + // causing the wrong overload to be selected, remove it. + AssertScalarT(); + StartVector(len, sizeof(T)); + if (len == 0) { + return Offset >(EndVector(len)); + } + // clang-format off + #if FLATBUFFERS_LITTLEENDIAN + PushBytes(reinterpret_cast(v), len * sizeof(T)); + #else + if (sizeof(T) == 1) { + PushBytes(reinterpret_cast(v), len); + } else { + for (auto i = len; i > 0; ) { + PushElement(v[--i]); + } + } + #endif + // clang-format on + return Offset >(EndVector(len)); + } + + template + Offset > > CreateVector(const Offset *v, size_t len) + { + StartVector(len, sizeof(Offset)); + for (auto i = len; i > 0;) { + PushElement(v[--i]); + } + return Offset > >(EndVector(len)); + } + + /// @brief Serialize a `std::vector` into a FlatBuffer `vector`. + /// @tparam T The data type of the `std::vector` elements. + /// @param v A const reference to the `std::vector` to serialize into the + /// buffer as a `vector`. + /// @return Returns a typed `Offset` into the serialized data indicating + /// where the vector is stored. + template + Offset > CreateVector(const std::vector &v) + { + return CreateVector(data(v), v.size()); + } + + // vector may be implemented using a bit-set, so we can't access it as + // an array. Instead, read elements manually. + // Background: https://isocpp.org/blog/2012/11/on-vectorbool + Offset > CreateVector(const std::vector &v) + { + StartVector(v.size(), sizeof(uint8_t)); + for (auto i = v.size(); i > 0;) { + PushElement(static_cast(v[--i])); + } + return Offset >(EndVector(v.size())); + } + + // clang-format off + #ifndef FLATBUFFERS_CPP98_STL + /// @brief Serialize values returned by a function into a FlatBuffer `vector`. + /// This is a convenience function that takes care of iteration for you. + /// @tparam T The data type of the `std::vector` elements. + /// @param f A function that takes the current iteration 0..vector_size-1 and + /// returns any type that you can construct a FlatBuffers vector out of. + /// @return Returns a typed `Offset` into the serialized data indicating + /// where the vector is stored. + template Offset > CreateVector(size_t vector_size, + const std::function &f) { + std::vector elems(vector_size); + for (size_t i = 0; i < vector_size; i++) elems[i] = f(i); + return CreateVector(elems); + } + #endif + // clang-format on + + /// @brief Serialize values returned by a function into a FlatBuffer `vector`. + /// This is a convenience function that takes care of iteration for you. + /// @tparam T The data type of the `std::vector` elements. + /// @param f A function that takes the current iteration 0..vector_size-1, + /// and the state parameter returning any type that you can construct a + /// FlatBuffers vector out of. + /// @param state State passed to f. + /// @return Returns a typed `Offset` into the serialized data indicating + /// where the vector is stored. + template + Offset > CreateVector(size_t vector_size, F f, S *state) + { + std::vector elems(vector_size); + for (size_t i = 0; i < vector_size; i++) + elems[i] = f(i, state); + return CreateVector(elems); + } + + /// @brief Serialize a `std::vector` into a FlatBuffer `vector`. + /// This is a convenience function for a common case. + /// @param v A const reference to the `std::vector` to serialize into the + /// buffer as a `vector`. + /// @return Returns a typed `Offset` into the serialized data indicating + /// where the vector is stored. + Offset > > CreateVectorOfStrings( + const std::vector &v) + { + std::vector > offsets(v.size()); + for (size_t i = 0; i < v.size(); i++) + offsets[i] = CreateString(v[i]); + return CreateVector(offsets); + } + + /// @brief Serialize an array of structs into a FlatBuffer `vector`. + /// @tparam T The data type of the struct array elements. + /// @param[in] v A pointer to the array of type `T` to serialize into the + /// buffer as a `vector`. + /// @param[in] len The number of elements to serialize. + /// @return Returns a typed `Offset` into the serialized data indicating + /// where the vector is stored. + template + Offset > CreateVectorOfStructs(const T *v, size_t len) + { + StartVector(len * sizeof(T) / AlignOf(), AlignOf()); + PushBytes(reinterpret_cast(v), sizeof(T) * len); + return Offset >(EndVector(len)); + } + + /// @brief Serialize an array of native structs into a FlatBuffer `vector`. + /// @tparam T The data type of the struct array elements. + /// @tparam S The data type of the native struct array elements. + /// @param[in] v A pointer to the array of type `S` to serialize into the + /// buffer as a `vector`. + /// @param[in] len The number of elements to serialize. + /// @return Returns a typed `Offset` into the serialized data indicating + /// where the vector is stored. + template + Offset > CreateVectorOfNativeStructs(const S *v, + size_t len) + { + extern T Pack(const S &); + std::vector vv(len); + std::transform(v, v + len, vv.begin(), Pack); + return CreateVectorOfStructs(data(vv), vv.size()); + } + + // clang-format off + #ifndef FLATBUFFERS_CPP98_STL + /// @brief Serialize an array of structs into a FlatBuffer `vector`. + /// @tparam T The data type of the struct array elements. + /// @param[in] filler A function that takes the current iteration 0..vector_size-1 + /// and a pointer to the struct that must be filled. + /// @return Returns a typed `Offset` into the serialized data indicating + /// where the vector is stored. + /// This is mostly useful when flatbuffers are generated with mutation + /// accessors. + template Offset > CreateVectorOfStructs( + size_t vector_size, const std::function &filler) { + T* structs = StartVectorOfStructs(vector_size); + for (size_t i = 0; i < vector_size; i++) { + filler(i, structs); + structs++; + } + return EndVectorOfStructs(vector_size); + } + #endif + // clang-format on + + /// @brief Serialize an array of structs into a FlatBuffer `vector`. + /// @tparam T The data type of the struct array elements. + /// @param[in] f A function that takes the current iteration 0..vector_size-1, + /// a pointer to the struct that must be filled and the state argument. + /// @param[in] state Arbitrary state to pass to f. + /// @return Returns a typed `Offset` into the serialized data indicating + /// where the vector is stored. + /// This is mostly useful when flatbuffers are generated with mutation + /// accessors. + template + Offset > CreateVectorOfStructs(size_t vector_size, F f, + S *state) + { + T *structs = StartVectorOfStructs(vector_size); + for (size_t i = 0; i < vector_size; i++) { + f(i, structs, state); + structs++; + } + return EndVectorOfStructs(vector_size); + } + + /// @brief Serialize a `std::vector` of structs into a FlatBuffer `vector`. + /// @tparam T The data type of the `std::vector` struct elements. + /// @param[in] v A const reference to the `std::vector` of structs to + /// serialize into the buffer as a `vector`. + /// @return Returns a typed `Offset` into the serialized data indicating + /// where the vector is stored. + template + Offset > CreateVectorOfStructs( + const std::vector &v) + { + return CreateVectorOfStructs(data(v), v.size()); + } + + /// @brief Serialize a `std::vector` of native structs into a FlatBuffer + /// `vector`. + /// @tparam T The data type of the `std::vector` struct elements. + /// @tparam S The data type of the `std::vector` native struct elements. + /// @param[in] v A const reference to the `std::vector` of structs to + /// serialize into the buffer as a `vector`. + /// @return Returns a typed `Offset` into the serialized data indicating + /// where the vector is stored. + template + Offset > CreateVectorOfNativeStructs( + const std::vector &v) + { + return CreateVectorOfNativeStructs(data(v), v.size()); + } + + /// @cond FLATBUFFERS_INTERNAL + template + struct StructKeyComparator { + bool operator()(const T &a, const T &b) const + { + return a.KeyCompareLessThan(&b); + } + + FLATBUFFERS_DELETE_FUNC( + StructKeyComparator &operator=(const StructKeyComparator &)) + }; + /// @endcond + + /// @brief Serialize a `std::vector` of structs into a FlatBuffer `vector` + /// in sorted order. + /// @tparam T The data type of the `std::vector` struct elements. + /// @param[in] v A const reference to the `std::vector` of structs to + /// serialize into the buffer as a `vector`. + /// @return Returns a typed `Offset` into the serialized data indicating + /// where the vector is stored. + template + Offset > CreateVectorOfSortedStructs(std::vector *v) + { + return CreateVectorOfSortedStructs(data(*v), v->size()); + } + + /// @brief Serialize a `std::vector` of native structs into a FlatBuffer + /// `vector` in sorted order. + /// @tparam T The data type of the `std::vector` struct elements. + /// @tparam S The data type of the `std::vector` native struct elements. + /// @param[in] v A const reference to the `std::vector` of structs to + /// serialize into the buffer as a `vector`. + /// @return Returns a typed `Offset` into the serialized data indicating + /// where the vector is stored. + template + Offset > CreateVectorOfSortedNativeStructs( + std::vector *v) + { + return CreateVectorOfSortedNativeStructs(data(*v), v->size()); + } + + /// @brief Serialize an array of structs into a FlatBuffer `vector` in sorted + /// order. + /// @tparam T The data type of the struct array elements. + /// @param[in] v A pointer to the array of type `T` to serialize into the + /// buffer as a `vector`. + /// @param[in] len The number of elements to serialize. + /// @return Returns a typed `Offset` into the serialized data indicating + /// where the vector is stored. + template + Offset > CreateVectorOfSortedStructs(T *v, size_t len) + { + std::sort(v, v + len, StructKeyComparator()); + return CreateVectorOfStructs(v, len); + } + + /// @brief Serialize an array of native structs into a FlatBuffer `vector` in + /// sorted order. + /// @tparam T The data type of the struct array elements. + /// @tparam S The data type of the native struct array elements. + /// @param[in] v A pointer to the array of type `S` to serialize into the + /// buffer as a `vector`. + /// @param[in] len The number of elements to serialize. + /// @return Returns a typed `Offset` into the serialized data indicating + /// where the vector is stored. + template + Offset > CreateVectorOfSortedNativeStructs(S *v, + size_t len) + { + extern T Pack(const S &); + typedef T (*Pack_t)(const S &); + std::vector vv(len); + std::transform(v, v + len, vv.begin(), static_cast(Pack)); + return CreateVectorOfSortedStructs(vv, len); + } + + /// @cond FLATBUFFERS_INTERNAL + template + struct TableKeyComparator { + TableKeyComparator(vector_downward &buf) + : buf_(buf) + { + } + TableKeyComparator(const TableKeyComparator &other) + : buf_(other.buf_) + { + } + bool operator()(const Offset &a, const Offset &b) const + { + auto table_a = reinterpret_cast(buf_.data_at(a.o)); + auto table_b = reinterpret_cast(buf_.data_at(b.o)); + return table_a->KeyCompareLessThan(table_b); + } + vector_downward &buf_; + + private: + FLATBUFFERS_DELETE_FUNC(TableKeyComparator &operator=(const TableKeyComparator &other)) + }; + /// @endcond + + /// @brief Serialize an array of `table` offsets as a `vector` in the buffer + /// in sorted order. + /// @tparam T The data type that the offset refers to. + /// @param[in] v An array of type `Offset` that contains the `table` + /// offsets to store in the buffer in sorted order. + /// @param[in] len The number of elements to store in the `vector`. + /// @return Returns a typed `Offset` into the serialized data indicating + /// where the vector is stored. + template + Offset > > CreateVectorOfSortedTables(Offset *v, + size_t len) + { + std::sort(v, v + len, TableKeyComparator(buf_)); + return CreateVector(v, len); + } + + /// @brief Serialize an array of `table` offsets as a `vector` in the buffer + /// in sorted order. + /// @tparam T The data type that the offset refers to. + /// @param[in] v An array of type `Offset` that contains the `table` + /// offsets to store in the buffer in sorted order. + /// @return Returns a typed `Offset` into the serialized data indicating + /// where the vector is stored. + template + Offset > > CreateVectorOfSortedTables( + std::vector > *v) + { + return CreateVectorOfSortedTables(data(*v), v->size()); + } + + /// @brief Specialized version of `CreateVector` for non-copying use cases. + /// Write the data any time later to the returned buffer pointer `buf`. + /// @param[in] len The number of elements to store in the `vector`. + /// @param[in] elemsize The size of each element in the `vector`. + /// @param[out] buf A pointer to a `uint8_t` pointer that can be + /// written to at a later time to serialize the data into a `vector` + /// in the buffer. + uoffset_t CreateUninitializedVector(size_t len, size_t elemsize, + uint8_t **buf) + { + NotNested(); + StartVector(len, elemsize); + buf_.make_space(len * elemsize); + auto vec_start = GetSize(); + auto vec_end = EndVector(len); + *buf = buf_.data_at(vec_start); + return vec_end; + } + + /// @brief Specialized version of `CreateVector` for non-copying use cases. + /// Write the data any time later to the returned buffer pointer `buf`. + /// @tparam T The data type of the data that will be stored in the buffer + /// as a `vector`. + /// @param[in] len The number of elements to store in the `vector`. + /// @param[out] buf A pointer to a pointer of type `T` that can be + /// written to at a later time to serialize the data into a `vector` + /// in the buffer. + template + Offset > CreateUninitializedVector(size_t len, T **buf) + { + AssertScalarT(); + return CreateUninitializedVector(len, sizeof(T), + reinterpret_cast(buf)); + } + + template + Offset > CreateUninitializedVectorOfStructs(size_t len, + T **buf) + { + return CreateUninitializedVector(len, sizeof(T), + reinterpret_cast(buf)); + } + + // @brief Create a vector of scalar type T given as input a vector of scalar + // type U, useful with e.g. pre "enum class" enums, or any existing scalar + // data of the wrong type. + template + Offset > CreateVectorScalarCast(const U *v, size_t len) + { + AssertScalarT(); + AssertScalarT(); + StartVector(len, sizeof(T)); + for (auto i = len; i > 0;) { + PushElement(static_cast(v[--i])); + } + return Offset >(EndVector(len)); + } + + /// @brief Write a struct by itself, typically to be part of a union. + template + Offset CreateStruct(const T &structobj) + { + NotNested(); + Align(AlignOf()); + buf_.push_small(structobj); + return Offset(GetSize()); + } + + /// @brief The length of a FlatBuffer file header. + static const size_t kFileIdentifierLength = 4; + + /// @brief Finish serializing a buffer by writing the root offset. + /// @param[in] file_identifier If a `file_identifier` is given, the buffer + /// will be prefixed with a standard FlatBuffers file header. + template + void Finish(Offset root, const char *file_identifier = nullptr) + { + Finish(root.o, file_identifier, false); + } + + /// @brief Finish a buffer with a 32 bit size field pre-fixed (size of the + /// buffer following the size field). These buffers are NOT compatible + /// with standard buffers created by Finish, i.e. you can't call GetRoot + /// on them, you have to use GetSizePrefixedRoot instead. + /// All >32 bit quantities in this buffer will be aligned when the whole + /// size pre-fixed buffer is aligned. + /// These kinds of buffers are useful for creating a stream of FlatBuffers. + template + void FinishSizePrefixed(Offset root, + const char *file_identifier = nullptr) + { + Finish(root.o, file_identifier, true); + } + + void SwapBufAllocator(FlatBufferBuilder &other) + { + buf_.swap_allocator(other.buf_); + } + +protected: + // You shouldn't really be copying instances of this class. + FlatBufferBuilder(const FlatBufferBuilder &); + FlatBufferBuilder &operator=(const FlatBufferBuilder &); + + void Finish(uoffset_t root, const char *file_identifier, bool size_prefix) + { + NotNested(); + buf_.clear_scratch(); + // This will cause the whole buffer to be aligned. + PreAlign((size_prefix ? sizeof(uoffset_t) : 0) + sizeof(uoffset_t) + + (file_identifier ? kFileIdentifierLength : 0), + minalign_); + if (file_identifier) { + FLATBUFFERS_ASSERT(strlen(file_identifier) == kFileIdentifierLength); + PushBytes(reinterpret_cast(file_identifier), + kFileIdentifierLength); + } + PushElement(ReferTo(root)); // Location of root. + if (size_prefix) { + PushElement(GetSize()); + } + finished = true; + } + + struct FieldLoc { + uoffset_t off; + voffset_t id; + }; + + vector_downward buf_; + + // Accumulating offsets of table members while it is being built. + // We store these in the scratch pad of buf_, after the vtable offsets. + uoffset_t num_field_loc; + // Track how much of the vtable is in use, so we can output the most compact + // possible vtable. + voffset_t max_voffset_; + + // Ensure objects are not nested. + bool nested; + + // Ensure the buffer is finished before it is being accessed. + bool finished; + + size_t minalign_; + + bool force_defaults_; // Serialize values equal to their defaults anyway. + + bool dedup_vtables_; + + struct StringOffsetCompare { + StringOffsetCompare(const vector_downward &buf) + : buf_(&buf) + { + } + bool operator()(const Offset &a, const Offset &b) const + { + auto stra = reinterpret_cast(buf_->data_at(a.o)); + auto strb = reinterpret_cast(buf_->data_at(b.o)); + return StringLessThan(stra->data(), stra->size(), strb->data(), + strb->size()); + } + const vector_downward *buf_; + }; + + // For use with CreateSharedString. Instantiated on first use only. + typedef std::set, StringOffsetCompare> StringOffsetMap; + StringOffsetMap *string_pool; + +private: + // Allocates space for a vector of structures. + // Must be completed with EndVectorOfStructs(). + template + T *StartVectorOfStructs(size_t vector_size) + { + StartVector(vector_size * sizeof(T) / AlignOf(), AlignOf()); + return reinterpret_cast(buf_.make_space(vector_size * sizeof(T))); + } + + // End the vector of structues in the flatbuffers. + // Vector should have previously be started with StartVectorOfStructs(). + template + Offset > EndVectorOfStructs(size_t vector_size) + { + return Offset >(EndVector(vector_size)); + } +}; +/// @} + +/// @cond FLATBUFFERS_INTERNAL +// Helpers to get a typed pointer to the root object contained in the buffer. +template +T *GetMutableRoot(void *buf) +{ + EndianCheck(); + return reinterpret_cast( + reinterpret_cast(buf) + + EndianScalar(*reinterpret_cast(buf))); +} + +template +const T *GetRoot(const void *buf) +{ + return GetMutableRoot(const_cast(buf)); +} + +template +const T *GetSizePrefixedRoot(const void *buf) +{ + return GetRoot(reinterpret_cast(buf) + sizeof(uoffset_t)); +} + +/// Helpers to get a typed pointer to objects that are currently being built. +/// @warning Creating new objects will lead to reallocations and invalidates +/// the pointer! +template +T *GetMutableTemporaryPointer(FlatBufferBuilder &fbb, Offset offset) +{ + return reinterpret_cast(fbb.GetCurrentBufferPointer() + fbb.GetSize() - + offset.o); +} + +template +const T *GetTemporaryPointer(FlatBufferBuilder &fbb, Offset offset) +{ + return GetMutableTemporaryPointer(fbb, offset); +} + +/// @brief Get a pointer to the the file_identifier section of the buffer. +/// @return Returns a const char pointer to the start of the file_identifier +/// characters in the buffer. The returned char * has length +/// 'flatbuffers::FlatBufferBuilder::kFileIdentifierLength'. +/// This function is UNDEFINED for FlatBuffers whose schema does not include +/// a file_identifier (likely points at padding or the start of a the root +/// vtable). +inline const char *GetBufferIdentifier(const void *buf, + bool size_prefixed = false) +{ + return reinterpret_cast(buf) + + ((size_prefixed) ? 2 * sizeof(uoffset_t) : sizeof(uoffset_t)); +} + +// Helper to see if the identifier in a buffer has the expected value. +inline bool BufferHasIdentifier(const void *buf, const char *identifier, + bool size_prefixed = false) +{ + return strncmp(GetBufferIdentifier(buf, size_prefixed), identifier, + FlatBufferBuilder::kFileIdentifierLength) == 0; +} + +// Helper class to verify the integrity of a FlatBuffer +class Verifier FLATBUFFERS_FINAL_CLASS { +public: + Verifier(const uint8_t *buf, size_t buf_len, uoffset_t _max_depth = 64, + uoffset_t _max_tables = 1000000, bool _check_alignment = true) + : buf_(buf), + size_(buf_len), + depth_(0), + max_depth_(_max_depth), + num_tables_(0), + max_tables_(_max_tables), + upper_bound_(0), + check_alignment_(_check_alignment) + { + FLATBUFFERS_ASSERT(size_ < FLATBUFFERS_MAX_BUFFER_SIZE); + } + + // Central location where any verification failures register. + bool Check(bool ok) const + { + // clang-format off + #ifdef FLATBUFFERS_DEBUG_VERIFICATION_FAILURE + FLATBUFFERS_ASSERT(ok); + #endif + #ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE + if (!ok) + upper_bound_ = 0; + #endif + // clang-format on + return ok; + } + + // Verify any range within the buffer. + bool Verify(size_t elem, size_t elem_len) const + { + // clang-format off + #ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE + auto upper_bound = elem + elem_len; + if (upper_bound_ < upper_bound) + upper_bound_ = upper_bound; + #endif + // clang-format on + return Check(elem_len < size_ && elem <= size_ - elem_len); + } + + template + bool VerifyAlignment(size_t elem) const + { + return Check((elem & (sizeof(T) - 1)) == 0 || !check_alignment_); + } + + // Verify a range indicated by sizeof(T). + template + bool Verify(size_t elem) const + { + return VerifyAlignment(elem) && Verify(elem, sizeof(T)); + } + + bool VerifyFromPointer(const uint8_t *p, size_t len) + { + auto o = static_cast(p - buf_); + return Verify(o, len); + } + + // Verify relative to a known-good base pointer. + bool Verify(const uint8_t *base, voffset_t elem_off, size_t elem_len) const + { + return Verify(static_cast(base - buf_) + elem_off, elem_len); + } + + template + bool Verify(const uint8_t *base, voffset_t elem_off) const + { + return Verify(static_cast(base - buf_) + elem_off, sizeof(T)); + } + + // Verify a pointer (may be NULL) of a table type. + template + bool VerifyTable(const T *table) + { + return !table || table->Verify(*this); + } + + // Verify a pointer (may be NULL) of any vector type. + template + bool VerifyVector(const Vector *vec) const + { + return !vec || VerifyVectorOrString(reinterpret_cast(vec), + sizeof(T)); + } + + // Verify a pointer (may be NULL) of a vector to struct. + template + bool VerifyVector(const Vector *vec) const + { + return VerifyVector(reinterpret_cast *>(vec)); + } + + // Verify a pointer (may be NULL) to string. + bool VerifyString(const String *str) const + { + size_t end; + return !str || (VerifyVectorOrString(reinterpret_cast(str), + 1, &end) && + Verify(end, 1) && // Must have terminator + Check(buf_[end] == '\0')); // Terminating byte must be 0. + } + + // Common code between vectors and strings. + bool VerifyVectorOrString(const uint8_t *vec, size_t elem_size, + size_t *end = nullptr) const + { + auto veco = static_cast(vec - buf_); + // Check we can read the size field. + if (!Verify(veco)) + return false; + // Check the whole array. If this is a string, the byte past the array + // must be 0. + auto size = ReadScalar(vec); + auto max_elems = FLATBUFFERS_MAX_BUFFER_SIZE / elem_size; + if (!Check(size < max_elems)) + return false; // Protect against byte_size overflowing. + auto byte_size = sizeof(size) + elem_size * size; + if (end) + *end = veco + byte_size; + return Verify(veco, byte_size); + } + + // Special case for string contents, after the above has been called. + bool VerifyVectorOfStrings(const Vector > *vec) const + { + if (vec) { + for (uoffset_t i = 0; i < vec->size(); i++) { + if (!VerifyString(vec->Get(i))) + return false; + } + } + return true; + } + + // Special case for table contents, after the above has been called. + template + bool VerifyVectorOfTables(const Vector > *vec) + { + if (vec) { + for (uoffset_t i = 0; i < vec->size(); i++) { + if (!vec->Get(i)->Verify(*this)) + return false; + } + } + return true; + } + + __supress_ubsan__("unsigned-integer-overflow") bool VerifyTableStart( + const uint8_t *table) + { + // Check the vtable offset. + auto tableo = static_cast(table - buf_); + if (!Verify(tableo)) + return false; + // This offset may be signed, but doing the subtraction unsigned always + // gives the result we want. + auto vtableo = tableo - static_cast(ReadScalar(table)); + // Check the vtable size field, then check vtable fits in its entirety. + return VerifyComplexity() && Verify(vtableo) && + VerifyAlignment(ReadScalar(buf_ + vtableo)) && + Verify(vtableo, ReadScalar(buf_ + vtableo)); + } + + template + bool VerifyBufferFromStart(const char *identifier, size_t start) + { + if (identifier && !Check((size_ >= 2 * sizeof(flatbuffers::uoffset_t) && + BufferHasIdentifier(buf_ + start, identifier)))) { + return false; + } + + // Call T::Verify, which must be in the generated code for this type. + auto o = VerifyOffset(start); + return o && reinterpret_cast(buf_ + start + o)->Verify(*this) + // clang-format off + #ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE + && GetComputedSize() + #endif + ; + // clang-format on + } + + // Verify this whole buffer, starting with root type T. + template + bool VerifyBuffer() + { + return VerifyBuffer(nullptr); + } + + template + bool VerifyBuffer(const char *identifier) + { + return VerifyBufferFromStart(identifier, 0); + } + + template + bool VerifySizePrefixedBuffer(const char *identifier) + { + return Verify(0U) && + ReadScalar(buf_) == size_ - sizeof(uoffset_t) && + VerifyBufferFromStart(identifier, sizeof(uoffset_t)); + } + + uoffset_t VerifyOffset(size_t start) const + { + if (!Verify(start)) + return 0; + auto o = ReadScalar(buf_ + start); + // May not point to itself. + if (!Check(o != 0)) + return 0; + // Can't wrap around / buffers are max 2GB. + if (!Check(static_cast(o) >= 0)) + return 0; + // Must be inside the buffer to create a pointer from it (pointer outside + // buffer is UB). + if (!Verify(start + o, 1)) + return 0; + return o; + } + + uoffset_t VerifyOffset(const uint8_t *base, voffset_t start) const + { + return VerifyOffset(static_cast(base - buf_) + start); + } + + // Called at the start of a table to increase counters measuring data + // structure depth and amount, and possibly bails out with false if + // limits set by the constructor have been hit. Needs to be balanced + // with EndTable(). + bool VerifyComplexity() + { + depth_++; + num_tables_++; + return Check(depth_ <= max_depth_ && num_tables_ <= max_tables_); + } + + // Called at the end of a table to pop the depth count. + bool EndTable() + { + depth_--; + return true; + } + + // Returns the message size in bytes + size_t GetComputedSize() const + { + // clang-format off + #ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE + uintptr_t size = upper_bound_; + // Align the size to uoffset_t + size = (size - 1 + sizeof(uoffset_t)) & ~(sizeof(uoffset_t) - 1); + return (size > size_) ? 0 : size; + #else + // Must turn on FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE for this to work. + (void)upper_bound_; + FLATBUFFERS_ASSERT(false); + return 0; + #endif + // clang-format on + } + +private: + const uint8_t *buf_; + size_t size_; + uoffset_t depth_; + uoffset_t max_depth_; + uoffset_t num_tables_; + uoffset_t max_tables_; + mutable size_t upper_bound_; + bool check_alignment_; +}; + +// Convenient way to bundle a buffer and its length, to pass it around +// typed by its root. +// A BufferRef does not own its buffer. +struct BufferRefBase { +}; // for std::is_base_of +template +struct BufferRef : BufferRefBase { + BufferRef() + : buf(nullptr), len(0), must_free(false) + { + } + BufferRef(uint8_t *_buf, uoffset_t _len) + : buf(_buf), len(_len), must_free(false) + { + } + + ~BufferRef() + { + if (must_free) + free(buf); + } + + const T *GetRoot() const + { + return flatbuffers::GetRoot(buf); + } + + bool Verify() + { + Verifier verifier(buf, len); + return verifier.VerifyBuffer(nullptr); + } + + uint8_t *buf; + uoffset_t len; + bool must_free; +}; + +// "structs" are flat structures that do not have an offset table, thus +// always have all members present and do not support forwards/backwards +// compatible extensions. + +class Struct FLATBUFFERS_FINAL_CLASS { +public: + template + T GetField(uoffset_t o) const + { + return ReadScalar(&data_[o]); + } + + template + T GetStruct(uoffset_t o) const + { + return reinterpret_cast(&data_[o]); + } + + const uint8_t *GetAddressOf(uoffset_t o) const + { + return &data_[o]; + } + uint8_t *GetAddressOf(uoffset_t o) + { + return &data_[o]; + } + +private: + // private constructor & copy constructor: you obtain instances of this + // class by pointing to existing data only + Struct(); + Struct(const Struct &); + Struct &operator=(const Struct &); + + uint8_t data_[1]; +}; + +// "tables" use an offset table (possibly shared) that allows fields to be +// omitted and added at will, but uses an extra indirection to read. +class Table { +public: + const uint8_t *GetVTable() const + { + return data_ - ReadScalar(data_); + } + + // This gets the field offset for any of the functions below it, or 0 + // if the field was not present. + voffset_t GetOptionalFieldOffset(voffset_t field) const + { + // The vtable offset is always at the start. + auto vtable = GetVTable(); + // The first element is the size of the vtable (fields + type id + itself). + auto vtsize = ReadScalar(vtable); + // If the field we're accessing is outside the vtable, we're reading older + // data, so it's the same as if the offset was 0 (not present). + return field < vtsize ? ReadScalar(vtable + field) : 0; + } + + template + T GetField(voffset_t field, T defaultval) const + { + auto field_offset = GetOptionalFieldOffset(field); + return field_offset ? ReadScalar(data_ + field_offset) : defaultval; + } + + template + P GetPointer(voffset_t field) + { + auto field_offset = GetOptionalFieldOffset(field); + auto p = data_ + field_offset; + return field_offset ? reinterpret_cast

(p + ReadScalar(p)) : nullptr; + } + template + P GetPointer(voffset_t field) const + { + return const_cast(this)->GetPointer

(field); + } + + template + P GetStruct(voffset_t field) const + { + auto field_offset = GetOptionalFieldOffset(field); + auto p = const_cast(data_ + field_offset); + return field_offset ? reinterpret_cast

(p) : nullptr; + } + + template + flatbuffers::Optional GetOptional(voffset_t field) const + { + auto field_offset = GetOptionalFieldOffset(field); + auto p = data_ + field_offset; + return field_offset ? Optional(static_cast(ReadScalar(p))) : Optional(); + } + + template + bool SetField(voffset_t field, T val, T def) + { + auto field_offset = GetOptionalFieldOffset(field); + if (!field_offset) + return IsTheSameAs(val, def); + WriteScalar(data_ + field_offset, val); + return true; + } + template + bool SetField(voffset_t field, T val) + { + auto field_offset = GetOptionalFieldOffset(field); + if (!field_offset) + return false; + WriteScalar(data_ + field_offset, val); + return true; + } + + bool SetPointer(voffset_t field, const uint8_t *val) + { + auto field_offset = GetOptionalFieldOffset(field); + if (!field_offset) + return false; + WriteScalar(data_ + field_offset, + static_cast(val - (data_ + field_offset))); + return true; + } + + uint8_t *GetAddressOf(voffset_t field) + { + auto field_offset = GetOptionalFieldOffset(field); + return field_offset ? data_ + field_offset : nullptr; + } + const uint8_t *GetAddressOf(voffset_t field) const + { + return const_cast

(this)->GetAddressOf(field); + } + + bool CheckField(voffset_t field) const + { + return GetOptionalFieldOffset(field) != 0; + } + + // Verify the vtable of this table. + // Call this once per table, followed by VerifyField once per field. + bool VerifyTableStart(Verifier &verifier) const + { + return verifier.VerifyTableStart(data_); + } + + // Verify a particular field. + template + bool VerifyField(const Verifier &verifier, voffset_t field) const + { + // Calling GetOptionalFieldOffset should be safe now thanks to + // VerifyTable(). + auto field_offset = GetOptionalFieldOffset(field); + // Check the actual field. + return !field_offset || verifier.Verify(data_, field_offset); + } + + // VerifyField for required fields. + template + bool VerifyFieldRequired(const Verifier &verifier, voffset_t field) const + { + auto field_offset = GetOptionalFieldOffset(field); + return verifier.Check(field_offset != 0) && + verifier.Verify(data_, field_offset); + } + + // Versions for offsets. + bool VerifyOffset(const Verifier &verifier, voffset_t field) const + { + auto field_offset = GetOptionalFieldOffset(field); + return !field_offset || verifier.VerifyOffset(data_, field_offset); + } + + bool VerifyOffsetRequired(const Verifier &verifier, voffset_t field) const + { + auto field_offset = GetOptionalFieldOffset(field); + return verifier.Check(field_offset != 0) && + verifier.VerifyOffset(data_, field_offset); + } + +private: + // private constructor & copy constructor: you obtain instances of this + // class by pointing to existing data only + Table(); + Table(const Table &other); + Table &operator=(const Table &); + + uint8_t data_[1]; +}; + +// This specialization allows avoiding warnings like: +// MSVC C4800: type: forcing value to bool 'true' or 'false'. +template <> +inline flatbuffers::Optional Table::GetOptional( + voffset_t field) const +{ + auto field_offset = GetOptionalFieldOffset(field); + auto p = data_ + field_offset; + return field_offset ? Optional(ReadScalar(p) != 0) : Optional(); +} + +template +void FlatBufferBuilder::Required(Offset table, voffset_t field) +{ + auto table_ptr = reinterpret_cast(buf_.data_at(table.o)); + bool ok = table_ptr->GetOptionalFieldOffset(field) != 0; + // If this fails, the caller will show what field needs to be set. + FLATBUFFERS_ASSERT(ok); + (void)ok; +} + +/// @brief This can compute the start of a FlatBuffer from a root pointer, i.e. +/// it is the opposite transformation of GetRoot(). +/// This may be useful if you want to pass on a root and have the recipient +/// delete the buffer afterwards. +inline const uint8_t *GetBufferStartFromRootPointer(const void *root) +{ + auto table = reinterpret_cast(root); + auto vtable = table->GetVTable(); + // Either the vtable is before the root or after the root. + auto start = (std::min)(vtable, reinterpret_cast(root)); + // Align to at least sizeof(uoffset_t). + start = reinterpret_cast(reinterpret_cast(start) & + ~(sizeof(uoffset_t) - 1)); + // Additionally, there may be a file_identifier in the buffer, and the root + // offset. The buffer may have been aligned to any size between + // sizeof(uoffset_t) and FLATBUFFERS_MAX_ALIGNMENT (see "force_align"). + // Sadly, the exact alignment is only known when constructing the buffer, + // since it depends on the presence of values with said alignment properties. + // So instead, we simply look at the next uoffset_t values (root, + // file_identifier, and alignment padding) to see which points to the root. + // None of the other values can "impersonate" the root since they will either + // be 0 or four ASCII characters. + static_assert(FlatBufferBuilder::kFileIdentifierLength == sizeof(uoffset_t), + "file_identifier is assumed to be the same size as uoffset_t"); + for (auto possible_roots = FLATBUFFERS_MAX_ALIGNMENT / sizeof(uoffset_t) + 1; + possible_roots; possible_roots--) { + start -= sizeof(uoffset_t); + if (ReadScalar(start) + start == + reinterpret_cast(root)) + return start; + } + // We didn't find the root, either the "root" passed isn't really a root, + // or the buffer is corrupt. + // Assert, because calling this function with bad data may cause reads + // outside of buffer boundaries. + FLATBUFFERS_ASSERT(false); + return nullptr; +} + +/// @brief This return the prefixed size of a FlatBuffer. +inline uoffset_t GetPrefixedSize(const uint8_t *buf) +{ + return ReadScalar(buf); +} + +// Base class for native objects (FlatBuffer data de-serialized into native +// C++ data structures). +// Contains no functionality, purely documentative. +struct NativeTable { +}; + +/// @brief Function types to be used with resolving hashes into objects and +/// back again. The resolver gets a pointer to a field inside an object API +/// object that is of the type specified in the schema using the attribute +/// `cpp_type` (it is thus important whatever you write to this address +/// matches that type). The value of this field is initially null, so you +/// may choose to implement a delayed binding lookup using this function +/// if you wish. The resolver does the opposite lookup, for when the object +/// is being serialized again. +typedef uint64_t hash_value_t; +// clang-format off +#ifdef FLATBUFFERS_CPP98_STL + typedef void (*resolver_function_t)(void **pointer_adr, hash_value_t hash); + typedef hash_value_t (*rehasher_function_t)(void *pointer); +#else + typedef std::function + resolver_function_t; + typedef std::function rehasher_function_t; +#endif +// clang-format on + +// Helper function to test if a field is present, using any of the field +// enums in the generated code. +// `table` must be a generated table type. Since this is a template parameter, +// this is not typechecked to be a subclass of Table, so beware! +// Note: this function will return false for fields equal to the default +// value, since they're not stored in the buffer (unless force_defaults was +// used). +template +bool IsFieldPresent(const T *table, typename T::FlatBuffersVTableOffset field) +{ + // Cast, since Table is a private baseclass of any table types. + return reinterpret_cast(table)->CheckField( + static_cast(field)); +} + +// Utility function for reverse lookups on the EnumNames*() functions +// (in the generated C++ code) +// names must be NULL terminated. +inline int LookupEnum(const char **names, const char *name) +{ + for (const char **p = names; *p; p++) + if (!strcmp(*p, name)) + return static_cast(p - names); + return -1; +} + +// These macros allow us to layout a struct with a guarantee that they'll end +// up looking the same on different compilers and platforms. +// It does this by disallowing the compiler to do any padding, and then +// does padding itself by inserting extra padding fields that make every +// element aligned to its own size. +// Additionally, it manually sets the alignment of the struct as a whole, +// which is typically its largest element, or a custom size set in the schema +// by the force_align attribute. +// These are used in the generated code only. + +// clang-format off +#if defined(_MSC_VER) + #define FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(alignment) \ + __pragma(pack(1)) \ + struct __declspec(align(alignment)) + #define FLATBUFFERS_STRUCT_END(name, size) \ + __pragma(pack()) \ + static_assert(sizeof(name) == size, "compiler breaks packing rules") +#elif defined(__GNUC__) || defined(__clang__) || defined(__ICCARM__) + #define FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(alignment) \ + _Pragma("pack(1)") \ + struct __attribute__((aligned(alignment))) + #define FLATBUFFERS_STRUCT_END(name, size) \ + _Pragma("pack()") \ + static_assert(sizeof(name) == size, "compiler breaks packing rules") +#else + #error Unknown compiler, please define structure alignment macros +#endif +// clang-format on + +// Minimal reflection via code generation. +// Besides full-fat reflection (see reflection.h) and parsing/printing by +// loading schemas (see idl.h), we can also have code generation for mimimal +// reflection data which allows pretty-printing and other uses without needing +// a schema or a parser. +// Generate code with --reflect-types (types only) or --reflect-names (names +// also) to enable. +// See minireflect.h for utilities using this functionality. + +// These types are organized slightly differently as the ones in idl.h. +enum SequenceType { ST_TABLE, + ST_STRUCT, + ST_UNION, + ST_ENUM }; + +// Scalars have the same order as in idl.h +// clang-format off +#define FLATBUFFERS_GEN_ELEMENTARY_TYPES(ET) \ + ET(ET_UTYPE) \ + ET(ET_BOOL) \ + ET(ET_CHAR) \ + ET(ET_UCHAR) \ + ET(ET_SHORT) \ + ET(ET_USHORT) \ + ET(ET_INT) \ + ET(ET_UINT) \ + ET(ET_LONG) \ + ET(ET_ULONG) \ + ET(ET_FLOAT) \ + ET(ET_DOUBLE) \ + ET(ET_STRING) \ + ET(ET_SEQUENCE) // See SequenceType. + +enum ElementaryType { + #define FLATBUFFERS_ET(E) E, + FLATBUFFERS_GEN_ELEMENTARY_TYPES(FLATBUFFERS_ET) + #undef FLATBUFFERS_ET +}; + +inline const char * const *ElementaryTypeNames() { + static const char * const names[] = { + #define FLATBUFFERS_ET(E) #E, + FLATBUFFERS_GEN_ELEMENTARY_TYPES(FLATBUFFERS_ET) + #undef FLATBUFFERS_ET + }; + return names; +} +// clang-format on + +// Basic type info cost just 16bits per field! +struct TypeCode { + uint16_t base_type : 4; // ElementaryType + uint16_t is_repeating : 1; // Either vector (in table) or array (in struct) + int16_t sequence_ref : 11; // Index into type_refs below, or -1 for none. +}; + +static_assert(sizeof(TypeCode) == 2, "TypeCode"); + +struct TypeTable; + +// Signature of the static method present in each type. +typedef const TypeTable *(*TypeFunction)(); + +struct TypeTable { + SequenceType st; + size_t num_elems; // of type_codes, values, names (but not type_refs). + const TypeCode *type_codes; // num_elems count + const TypeFunction *type_refs; // less than num_elems entries (see TypeCode). + const int16_t *array_sizes; // less than num_elems entries (see TypeCode). + const int64_t *values; // Only set for non-consecutive enum/union or structs. + const char *const *names; // Only set if compiled with --reflect-names. +}; + +// String which identifies the current version of FlatBuffers. +// flatbuffer_version_string is used by Google developers to identify which +// applications uploaded to Google Play are using this library. This allows +// the development team at Google to determine the popularity of the library. +// How it works: Applications that are uploaded to the Google Play Store are +// scanned for this version string. We track which applications are using it +// to measure popularity. You are free to remove it (of course) but we would +// appreciate if you left it in. + +// Weak linkage is culled by VS & doesn't work on cygwin. +// clang-format off +#if !defined(_WIN32) && !defined(__CYGWIN__) + +extern volatile __attribute__((weak)) const char *flatbuffer_version_string; +volatile __attribute__((weak)) const char *flatbuffer_version_string = + "FlatBuffers " + FLATBUFFERS_STRING(FLATBUFFERS_VERSION_MAJOR) "." + FLATBUFFERS_STRING(FLATBUFFERS_VERSION_MINOR) "." + FLATBUFFERS_STRING(FLATBUFFERS_VERSION_REVISION); + +#endif // !defined(_WIN32) && !defined(__CYGWIN__) + +#define FLATBUFFERS_DEFINE_BITMASK_OPERATORS(E, T)\ + inline E operator | (E lhs, E rhs){\ + return E(T(lhs) | T(rhs));\ + }\ + inline E operator & (E lhs, E rhs){\ + return E(T(lhs) & T(rhs));\ + }\ + inline E operator ^ (E lhs, E rhs){\ + return E(T(lhs) ^ T(rhs));\ + }\ + inline E operator ~ (E lhs){\ + return E(~T(lhs));\ + }\ + inline E operator |= (E &lhs, E rhs){\ + lhs = lhs | rhs;\ + return lhs;\ + }\ + inline E operator &= (E &lhs, E rhs){\ + lhs = lhs & rhs;\ + return lhs;\ + }\ + inline E operator ^= (E &lhs, E rhs){\ + lhs = lhs ^ rhs;\ + return lhs;\ + }\ + inline bool operator !(E rhs) \ + {\ + return !bool(T(rhs)); \ + } +/// @endcond +} // namespace flatbuffers + +// clang-format on + +#endif // FLATBUFFERS_H_ diff --git a/components/tflite/third_party/flatbuffers/include/flatbuffers/flatc.h b/components/tflite/third_party/flatbuffers/include/flatbuffers/flatc.h new file mode 100644 index 00000000..522fa2a8 --- /dev/null +++ b/components/tflite/third_party/flatbuffers/include/flatbuffers/flatc.h @@ -0,0 +1,104 @@ +/* + * Copyright 2017 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FLATBUFFERS_FLATC_H_ +#define FLATBUFFERS_FLATC_H_ + +#include +#include +#include + +#include "flatbuffers/flatbuffers.h" +#include "flatbuffers/idl.h" +#include "flatbuffers/util.h" + +namespace flatbuffers { +extern void LogCompilerWarn(const std::string &warn); +extern void LogCompilerError(const std::string &err); + +class FlatCompiler { +public: + // Output generator for the various programming languages and formats we + // support. + struct Generator { + typedef bool (*GenerateFn)(const flatbuffers::Parser &parser, + const std::string &path, + const std::string &file_name); + typedef std::string (*MakeRuleFn)(const flatbuffers::Parser &parser, + const std::string &path, + const std::string &file_name); + + GenerateFn generate; + const char *generator_opt_short; + const char *generator_opt_long; + const char *lang_name; + bool schema_only; + GenerateFn generateGRPC; + flatbuffers::IDLOptions::Language lang; + const char *generator_help; + MakeRuleFn make_rule; + }; + + typedef void (*WarnFn)(const FlatCompiler *flatc, const std::string &warn, + bool show_exe_name); + + typedef void (*ErrorFn)(const FlatCompiler *flatc, const std::string &err, + bool usage, bool show_exe_name); + + // Parameters required to initialize the FlatCompiler. + struct InitParams { + InitParams() + : generators(nullptr), + num_generators(0), + warn_fn(nullptr), + error_fn(nullptr) + { + } + + const Generator *generators; + size_t num_generators; + WarnFn warn_fn; + ErrorFn error_fn; + }; + + explicit FlatCompiler(const InitParams ¶ms) + : params_(params) + { + } + + int Compile(int argc, const char **argv); + + std::string GetUsageString(const char *program_name) const; + +private: + void ParseFile(flatbuffers::Parser &parser, const std::string &filename, + const std::string &contents, + std::vector &include_directories) const; + + void LoadBinarySchema(Parser &parser, const std::string &filename, + const std::string &contents); + + void Warn(const std::string &warn, bool show_exe_name = true) const; + + void Error(const std::string &err, bool usage = true, + bool show_exe_name = true) const; + + InitParams params_; +}; + +} // namespace flatbuffers + +#endif // FLATBUFFERS_FLATC_H_ diff --git a/components/tflite/third_party/flatbuffers/include/flatbuffers/flexbuffers.h b/components/tflite/third_party/flatbuffers/include/flatbuffers/flexbuffers.h new file mode 100644 index 00000000..f9dc0973 --- /dev/null +++ b/components/tflite/third_party/flatbuffers/include/flatbuffers/flexbuffers.h @@ -0,0 +1,2133 @@ +/* + * Copyright 2017 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FLATBUFFERS_FLEXBUFFERS_H_ +#define FLATBUFFERS_FLEXBUFFERS_H_ + +#include +// Used to select STL variant. +#include "flatbuffers/base.h" +// We use the basic binary writing functions from the regular FlatBuffers. +#include "flatbuffers/util.h" + +#ifdef _MSC_VER +#include +#endif + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable : 4127) // C4127: conditional expression is constant +#endif + +namespace flexbuffers { +class Reference; +class Map; + +// These are used in the lower 2 bits of a type field to determine the size of +// the elements (and or size field) of the item pointed to (e.g. vector). +enum BitWidth { + BIT_WIDTH_8 = 0, + BIT_WIDTH_16 = 1, + BIT_WIDTH_32 = 2, + BIT_WIDTH_64 = 3, +}; + +// These are used as the upper 6 bits of a type field to indicate the actual +// type. +enum Type { + FBT_NULL = 0, + FBT_INT = 1, + FBT_UINT = 2, + FBT_FLOAT = 3, + // Types above stored inline, types below store an offset. + FBT_KEY = 4, + FBT_STRING = 5, + FBT_INDIRECT_INT = 6, + FBT_INDIRECT_UINT = 7, + FBT_INDIRECT_FLOAT = 8, + FBT_MAP = 9, + FBT_VECTOR = 10, // Untyped. + FBT_VECTOR_INT = 11, // Typed any size (stores no type table). + FBT_VECTOR_UINT = 12, + FBT_VECTOR_FLOAT = 13, + FBT_VECTOR_KEY = 14, + // DEPRECATED, use FBT_VECTOR or FBT_VECTOR_KEY instead. + // Read test.cpp/FlexBuffersDeprecatedTest() for details on why. + FBT_VECTOR_STRING_DEPRECATED = 15, + FBT_VECTOR_INT2 = 16, // Typed tuple (no type table, no size field). + FBT_VECTOR_UINT2 = 17, + FBT_VECTOR_FLOAT2 = 18, + FBT_VECTOR_INT3 = 19, // Typed triple (no type table, no size field). + FBT_VECTOR_UINT3 = 20, + FBT_VECTOR_FLOAT3 = 21, + FBT_VECTOR_INT4 = 22, // Typed quad (no type table, no size field). + FBT_VECTOR_UINT4 = 23, + FBT_VECTOR_FLOAT4 = 24, + FBT_BLOB = 25, + FBT_BOOL = 26, + FBT_VECTOR_BOOL = + 36, // To Allow the same type of conversion of type to vector type +}; + +inline bool IsInline(Type t) +{ + return t <= FBT_FLOAT || t == FBT_BOOL; +} + +inline bool IsTypedVectorElementType(Type t) +{ + return (t >= FBT_INT && t <= FBT_STRING) || t == FBT_BOOL; +} + +inline bool IsTypedVector(Type t) +{ + return (t >= FBT_VECTOR_INT && t <= FBT_VECTOR_STRING_DEPRECATED) || + t == FBT_VECTOR_BOOL; +} + +inline bool IsFixedTypedVector(Type t) +{ + return t >= FBT_VECTOR_INT2 && t <= FBT_VECTOR_FLOAT4; +} + +inline Type ToTypedVector(Type t, size_t fixed_len = 0) +{ + FLATBUFFERS_ASSERT(IsTypedVectorElementType(t)); + switch (fixed_len) { + case 0: + return static_cast(t - FBT_INT + FBT_VECTOR_INT); + case 2: + return static_cast(t - FBT_INT + FBT_VECTOR_INT2); + case 3: + return static_cast(t - FBT_INT + FBT_VECTOR_INT3); + case 4: + return static_cast(t - FBT_INT + FBT_VECTOR_INT4); + default: + FLATBUFFERS_ASSERT(0); + return FBT_NULL; + } +} + +inline Type ToTypedVectorElementType(Type t) +{ + FLATBUFFERS_ASSERT(IsTypedVector(t)); + return static_cast(t - FBT_VECTOR_INT + FBT_INT); +} + +inline Type ToFixedTypedVectorElementType(Type t, uint8_t *len) +{ + FLATBUFFERS_ASSERT(IsFixedTypedVector(t)); + auto fixed_type = t - FBT_VECTOR_INT2; + *len = static_cast(fixed_type / 3 + + 2); // 3 types each, starting from length 2. + return static_cast(fixed_type % 3 + FBT_INT); +} + +// TODO: implement proper support for 8/16bit floats, or decide not to +// support them. +typedef int16_t half; +typedef int8_t quarter; + +// TODO: can we do this without conditionals using intrinsics or inline asm +// on some platforms? Given branch prediction the method below should be +// decently quick, but it is the most frequently executed function. +// We could do an (unaligned) 64-bit read if we ifdef out the platforms for +// which that doesn't work (or where we'd read into un-owned memory). +template +R ReadSizedScalar(const uint8_t *data, uint8_t byte_width) +{ + return byte_width < 4 ? (byte_width < 2 ? static_cast(flatbuffers::ReadScalar(data)) : static_cast(flatbuffers::ReadScalar(data))) : (byte_width < 8 ? static_cast(flatbuffers::ReadScalar(data)) : static_cast(flatbuffers::ReadScalar(data))); +} + +inline int64_t ReadInt64(const uint8_t *data, uint8_t byte_width) +{ + return ReadSizedScalar( + data, byte_width); +} + +inline uint64_t ReadUInt64(const uint8_t *data, uint8_t byte_width) +{ + // This is the "hottest" function (all offset lookups use this), so worth + // optimizing if possible. + // TODO: GCC apparently replaces memcpy by a rep movsb, but only if count is a + // constant, which here it isn't. Test if memcpy is still faster than + // the conditionals in ReadSizedScalar. Can also use inline asm. + // clang-format off + #if defined(_MSC_VER) && (defined(_M_X64) || defined _M_IX86) + uint64_t u = 0; + __movsb(reinterpret_cast(&u), + reinterpret_cast(data), byte_width); + return flatbuffers::EndianScalar(u); + #else + return ReadSizedScalar( + data, byte_width); + #endif + // clang-format on +} + +inline double ReadDouble(const uint8_t *data, uint8_t byte_width) +{ + return ReadSizedScalar(data, + byte_width); +} + +inline const uint8_t *Indirect(const uint8_t *offset, uint8_t byte_width) +{ + return offset - ReadUInt64(offset, byte_width); +} + +template +const uint8_t *Indirect(const uint8_t *offset) +{ + return offset - flatbuffers::ReadScalar(offset); +} + +inline BitWidth WidthU(uint64_t u) +{ +#define FLATBUFFERS_GET_FIELD_BIT_WIDTH(value, width) \ + { \ + if (!((u) & ~((1ULL << (width)) - 1ULL))) \ + return BIT_WIDTH_##width; \ + } + FLATBUFFERS_GET_FIELD_BIT_WIDTH(u, 8); + FLATBUFFERS_GET_FIELD_BIT_WIDTH(u, 16); + FLATBUFFERS_GET_FIELD_BIT_WIDTH(u, 32); +#undef FLATBUFFERS_GET_FIELD_BIT_WIDTH + return BIT_WIDTH_64; +} + +inline BitWidth WidthI(int64_t i) +{ + auto u = static_cast(i) << 1; + return WidthU(i >= 0 ? u : ~u); +} + +inline BitWidth WidthF(double f) +{ + return static_cast(static_cast(f)) == f ? BIT_WIDTH_32 : BIT_WIDTH_64; +} + +// Base class of all types below. +// Points into the data buffer and allows access to one type. +class Object { +public: + Object(const uint8_t *data, uint8_t byte_width) + : data_(data), byte_width_(byte_width) + { + } + +protected: + const uint8_t *data_; + uint8_t byte_width_; +}; + +// Object that has a size, obtained either from size prefix, or elsewhere. +class Sized : public Object { +public: + // Size prefix. + Sized(const uint8_t *data, uint8_t byte_width) + : Object(data, byte_width), size_(read_size()) + { + } + // Manual size. + Sized(const uint8_t *data, uint8_t byte_width, size_t sz) + : Object(data, byte_width), size_(sz) + { + } + size_t size() const + { + return size_; + } + // Access size stored in `byte_width_` bytes before data_ pointer. + size_t read_size() const + { + return static_cast(ReadUInt64(data_ - byte_width_, byte_width_)); + } + +protected: + size_t size_; +}; + +class String : public Sized { +public: + // Size prefix. + String(const uint8_t *data, uint8_t byte_width) + : Sized(data, byte_width) + { + } + // Manual size. + String(const uint8_t *data, uint8_t byte_width, size_t sz) + : Sized(data, byte_width, sz) + { + } + + size_t length() const + { + return size(); + } + const char *c_str() const + { + return reinterpret_cast(data_); + } + std::string str() const + { + return std::string(c_str(), size()); + } + + static String EmptyString() + { + static const char *empty_string = ""; + return String(reinterpret_cast(empty_string), 1, 0); + } + bool IsTheEmptyString() const + { + return data_ == EmptyString().data_; + } +}; + +class Blob : public Sized { +public: + Blob(const uint8_t *data_buf, uint8_t byte_width) + : Sized(data_buf, byte_width) + { + } + + static Blob EmptyBlob() + { + static const uint8_t empty_blob[] = { 0 /*len*/ }; + return Blob(empty_blob + 1, 1); + } + bool IsTheEmptyBlob() const + { + return data_ == EmptyBlob().data_; + } + const uint8_t *data() const + { + return data_; + } +}; + +class Vector : public Sized { +public: + Vector(const uint8_t *data, uint8_t byte_width) + : Sized(data, byte_width) + { + } + + Reference operator[](size_t i) const; + + static Vector EmptyVector() + { + static const uint8_t empty_vector[] = { 0 /*len*/ }; + return Vector(empty_vector + 1, 1); + } + bool IsTheEmptyVector() const + { + return data_ == EmptyVector().data_; + } +}; + +class TypedVector : public Sized { +public: + TypedVector(const uint8_t *data, uint8_t byte_width, Type element_type) + : Sized(data, byte_width), type_(element_type) + { + } + + Reference operator[](size_t i) const; + + static TypedVector EmptyTypedVector() + { + static const uint8_t empty_typed_vector[] = { 0 /*len*/ }; + return TypedVector(empty_typed_vector + 1, 1, FBT_INT); + } + bool IsTheEmptyVector() const + { + return data_ == TypedVector::EmptyTypedVector().data_; + } + + Type ElementType() + { + return type_; + } + + friend Reference; + +private: + Type type_; + + friend Map; +}; + +class FixedTypedVector : public Object { +public: + FixedTypedVector(const uint8_t *data, uint8_t byte_width, Type element_type, + uint8_t len) + : Object(data, byte_width), type_(element_type), len_(len) + { + } + + Reference operator[](size_t i) const; + + static FixedTypedVector EmptyFixedTypedVector() + { + static const uint8_t fixed_empty_vector[] = { 0 /* unused */ }; + return FixedTypedVector(fixed_empty_vector, 1, FBT_INT, 0); + } + bool IsTheEmptyFixedTypedVector() const + { + return data_ == FixedTypedVector::EmptyFixedTypedVector().data_; + } + + Type ElementType() + { + return type_; + } + uint8_t size() + { + return len_; + } + +private: + Type type_; + uint8_t len_; +}; + +class Map : public Vector { +public: + Map(const uint8_t *data, uint8_t byte_width) + : Vector(data, byte_width) + { + } + + Reference operator[](const char *key) const; + Reference operator[](const std::string &key) const; + + Vector Values() const + { + return Vector(data_, byte_width_); + } + + TypedVector Keys() const + { + const size_t num_prefixed_fields = 3; + auto keys_offset = data_ - byte_width_ * num_prefixed_fields; + return TypedVector(Indirect(keys_offset, byte_width_), + static_cast( + ReadUInt64(keys_offset + byte_width_, byte_width_)), + FBT_KEY); + } + + static Map EmptyMap() + { + static const uint8_t empty_map[] = { + 0 /*keys_len*/, 0 /*keys_offset*/, 1 /*keys_width*/, 0 /*len*/ + }; + return Map(empty_map + 4, 1); + } + + bool IsTheEmptyMap() const + { + return data_ == EmptyMap().data_; + } +}; + +template +void AppendToString(std::string &s, T &&v, bool keys_quoted) +{ + s += "[ "; + for (size_t i = 0; i < v.size(); i++) { + if (i) + s += ", "; + v[i].ToString(true, keys_quoted, s); + } + s += " ]"; +} + +class Reference { +public: + Reference() + : data_(nullptr), + parent_width_(0), + byte_width_(BIT_WIDTH_8), + type_(FBT_NULL) + { + } + + Reference(const uint8_t *data, uint8_t parent_width, uint8_t byte_width, + Type type) + : data_(data), + parent_width_(parent_width), + byte_width_(byte_width), + type_(type) + { + } + + Reference(const uint8_t *data, uint8_t parent_width, uint8_t packed_type) + : data_(data), parent_width_(parent_width) + { + byte_width_ = 1U << static_cast(packed_type & 3); + type_ = static_cast(packed_type >> 2); + } + + Type GetType() const + { + return type_; + } + + bool IsNull() const + { + return type_ == FBT_NULL; + } + bool IsBool() const + { + return type_ == FBT_BOOL; + } + bool IsInt() const + { + return type_ == FBT_INT || type_ == FBT_INDIRECT_INT; + } + bool IsUInt() const + { + return type_ == FBT_UINT || type_ == FBT_INDIRECT_UINT; + } + bool IsIntOrUint() const + { + return IsInt() || IsUInt(); + } + bool IsFloat() const + { + return type_ == FBT_FLOAT || type_ == FBT_INDIRECT_FLOAT; + } + bool IsNumeric() const + { + return IsIntOrUint() || IsFloat(); + } + bool IsString() const + { + return type_ == FBT_STRING; + } + bool IsKey() const + { + return type_ == FBT_KEY; + } + bool IsVector() const + { + return type_ == FBT_VECTOR || type_ == FBT_MAP; + } + bool IsUntypedVector() const + { + return type_ == FBT_VECTOR; + } + bool IsTypedVector() const + { + return flexbuffers::IsTypedVector(type_); + } + bool IsFixedTypedVector() const + { + return flexbuffers::IsFixedTypedVector(type_); + } + bool IsAnyVector() const + { + return (IsTypedVector() || IsFixedTypedVector() || IsVector()); + } + bool IsMap() const + { + return type_ == FBT_MAP; + } + bool IsBlob() const + { + return type_ == FBT_BLOB; + } + bool AsBool() const + { + return (type_ == FBT_BOOL ? ReadUInt64(data_, parent_width_) : AsUInt64()) != 0; + } + + // Reads any type as a int64_t. Never fails, does most sensible conversion. + // Truncates floats, strings are attempted to be parsed for a number, + // vectors/maps return their size. Returns 0 if all else fails. + int64_t AsInt64() const + { + if (type_ == FBT_INT) { + // A fast path for the common case. + return ReadInt64(data_, parent_width_); + } else + switch (type_) { + case FBT_INDIRECT_INT: + return ReadInt64(Indirect(), byte_width_); + case FBT_UINT: + return ReadUInt64(data_, parent_width_); + case FBT_INDIRECT_UINT: + return ReadUInt64(Indirect(), byte_width_); + case FBT_FLOAT: + return static_cast(ReadDouble(data_, parent_width_)); + case FBT_INDIRECT_FLOAT: + return static_cast(ReadDouble(Indirect(), byte_width_)); + case FBT_NULL: + return 0; + case FBT_STRING: + return flatbuffers::StringToInt(AsString().c_str()); + case FBT_VECTOR: + return static_cast(AsVector().size()); + case FBT_BOOL: + return ReadInt64(data_, parent_width_); + default: + // Convert other things to int. + return 0; + } + } + + // TODO: could specialize these to not use AsInt64() if that saves + // extension ops in generated code, and use a faster op than ReadInt64. + int32_t AsInt32() const + { + return static_cast(AsInt64()); + } + int16_t AsInt16() const + { + return static_cast(AsInt64()); + } + int8_t AsInt8() const + { + return static_cast(AsInt64()); + } + + uint64_t AsUInt64() const + { + if (type_ == FBT_UINT) { + // A fast path for the common case. + return ReadUInt64(data_, parent_width_); + } else + switch (type_) { + case FBT_INDIRECT_UINT: + return ReadUInt64(Indirect(), byte_width_); + case FBT_INT: + return ReadInt64(data_, parent_width_); + case FBT_INDIRECT_INT: + return ReadInt64(Indirect(), byte_width_); + case FBT_FLOAT: + return static_cast(ReadDouble(data_, parent_width_)); + case FBT_INDIRECT_FLOAT: + return static_cast(ReadDouble(Indirect(), byte_width_)); + case FBT_NULL: + return 0; + case FBT_STRING: + return flatbuffers::StringToUInt(AsString().c_str()); + case FBT_VECTOR: + return static_cast(AsVector().size()); + case FBT_BOOL: + return ReadUInt64(data_, parent_width_); + default: + // Convert other things to uint. + return 0; + } + } + + uint32_t AsUInt32() const + { + return static_cast(AsUInt64()); + } + uint16_t AsUInt16() const + { + return static_cast(AsUInt64()); + } + uint8_t AsUInt8() const + { + return static_cast(AsUInt64()); + } + + double AsDouble() const + { + if (type_ == FBT_FLOAT) { + // A fast path for the common case. + return ReadDouble(data_, parent_width_); + } else + switch (type_) { + case FBT_INDIRECT_FLOAT: + return ReadDouble(Indirect(), byte_width_); + case FBT_INT: + return static_cast(ReadInt64(data_, parent_width_)); + case FBT_UINT: + return static_cast(ReadUInt64(data_, parent_width_)); + case FBT_INDIRECT_INT: + return static_cast(ReadInt64(Indirect(), byte_width_)); + case FBT_INDIRECT_UINT: + return static_cast(ReadUInt64(Indirect(), byte_width_)); + case FBT_NULL: + return 0.0; + case FBT_STRING: { + double d; + flatbuffers::StringToNumber(AsString().c_str(), &d); + return d; + } + case FBT_VECTOR: + return static_cast(AsVector().size()); + case FBT_BOOL: + return static_cast(ReadUInt64(data_, parent_width_)); + default: + // Convert strings and other things to float. + return 0; + } + } + + float AsFloat() const + { + return static_cast(AsDouble()); + } + + const char *AsKey() const + { + if (type_ == FBT_KEY || type_ == FBT_STRING) { + return reinterpret_cast(Indirect()); + } else { + return ""; + } + } + + // This function returns the empty string if you try to read something that + // is not a string or key. + String AsString() const + { + if (type_ == FBT_STRING) { + return String(Indirect(), byte_width_); + } else if (type_ == FBT_KEY) { + auto key = Indirect(); + return String(key, byte_width_, + strlen(reinterpret_cast(key))); + } else { + return String::EmptyString(); + } + } + + // Unlike AsString(), this will convert any type to a std::string. + std::string ToString() const + { + std::string s; + ToString(false, false, s); + return s; + } + + // Convert any type to a JSON-like string. strings_quoted determines if + // string values at the top level receive "" quotes (inside other values + // they always do). keys_quoted determines if keys are quoted, at any level. + // TODO(wvo): add further options to have indentation/newlines. + void ToString(bool strings_quoted, bool keys_quoted, std::string &s) const + { + if (type_ == FBT_STRING) { + String str(Indirect(), byte_width_); + if (strings_quoted) { + flatbuffers::EscapeString(str.c_str(), str.length(), &s, true, false); + } else { + s.append(str.c_str(), str.length()); + } + } else if (IsKey()) { + auto str = AsKey(); + if (keys_quoted) { + flatbuffers::EscapeString(str, strlen(str), &s, true, false); + } else { + s += str; + } + } else if (IsInt()) { + s += flatbuffers::NumToString(AsInt64()); + } else if (IsUInt()) { + s += flatbuffers::NumToString(AsUInt64()); + } else if (IsFloat()) { + s += flatbuffers::NumToString(AsDouble()); + } else if (IsNull()) { + s += "null"; + } else if (IsBool()) { + s += AsBool() ? "true" : "false"; + } else if (IsMap()) { + s += "{ "; + auto m = AsMap(); + auto keys = m.Keys(); + auto vals = m.Values(); + for (size_t i = 0; i < keys.size(); i++) { + keys[i].ToString(true, keys_quoted, s); + s += ": "; + vals[i].ToString(true, keys_quoted, s); + if (i < keys.size() - 1) + s += ", "; + } + s += " }"; + } else if (IsVector()) { + AppendToString(s, AsVector(), keys_quoted); + } else if (IsTypedVector()) { + AppendToString(s, AsTypedVector(), keys_quoted); + } else if (IsFixedTypedVector()) { + AppendToString(s, AsFixedTypedVector(), keys_quoted); + } else if (IsBlob()) { + auto blob = AsBlob(); + flatbuffers::EscapeString(reinterpret_cast(blob.data()), + blob.size(), &s, true, false); + } else { + s += "(?)"; + } + } + + // This function returns the empty blob if you try to read a not-blob. + // Strings can be viewed as blobs too. + Blob AsBlob() const + { + if (type_ == FBT_BLOB || type_ == FBT_STRING) { + return Blob(Indirect(), byte_width_); + } else { + return Blob::EmptyBlob(); + } + } + + // This function returns the empty vector if you try to read a not-vector. + // Maps can be viewed as vectors too. + Vector AsVector() const + { + if (type_ == FBT_VECTOR || type_ == FBT_MAP) { + return Vector(Indirect(), byte_width_); + } else { + return Vector::EmptyVector(); + } + } + + TypedVector AsTypedVector() const + { + if (IsTypedVector()) { + auto tv = + TypedVector(Indirect(), byte_width_, ToTypedVectorElementType(type_)); + if (tv.type_ == FBT_STRING) { + // These can't be accessed as strings, since we don't know the bit-width + // of the size field, see the declaration of + // FBT_VECTOR_STRING_DEPRECATED above for details. + // We change the type here to be keys, which are a subtype of strings, + // and will ignore the size field. This will truncate strings with + // embedded nulls. + tv.type_ = FBT_KEY; + } + return tv; + } else { + return TypedVector::EmptyTypedVector(); + } + } + + FixedTypedVector AsFixedTypedVector() const + { + if (IsFixedTypedVector()) { + uint8_t len = 0; + auto vtype = ToFixedTypedVectorElementType(type_, &len); + return FixedTypedVector(Indirect(), byte_width_, vtype, len); + } else { + return FixedTypedVector::EmptyFixedTypedVector(); + } + } + + Map AsMap() const + { + if (type_ == FBT_MAP) { + return Map(Indirect(), byte_width_); + } else { + return Map::EmptyMap(); + } + } + + template + T As() const; + + // Experimental: Mutation functions. + // These allow scalars in an already created buffer to be updated in-place. + // Since by default scalars are stored in the smallest possible space, + // the new value may not fit, in which case these functions return false. + // To avoid this, you can construct the values you intend to mutate using + // Builder::ForceMinimumBitWidth. + bool MutateInt(int64_t i) + { + if (type_ == FBT_INT) { + return Mutate(data_, i, parent_width_, WidthI(i)); + } else if (type_ == FBT_INDIRECT_INT) { + return Mutate(Indirect(), i, byte_width_, WidthI(i)); + } else if (type_ == FBT_UINT) { + auto u = static_cast(i); + return Mutate(data_, u, parent_width_, WidthU(u)); + } else if (type_ == FBT_INDIRECT_UINT) { + auto u = static_cast(i); + return Mutate(Indirect(), u, byte_width_, WidthU(u)); + } else { + return false; + } + } + + bool MutateBool(bool b) + { + return type_ == FBT_BOOL && Mutate(data_, b, parent_width_, BIT_WIDTH_8); + } + + bool MutateUInt(uint64_t u) + { + if (type_ == FBT_UINT) { + return Mutate(data_, u, parent_width_, WidthU(u)); + } else if (type_ == FBT_INDIRECT_UINT) { + return Mutate(Indirect(), u, byte_width_, WidthU(u)); + } else if (type_ == FBT_INT) { + auto i = static_cast(u); + return Mutate(data_, i, parent_width_, WidthI(i)); + } else if (type_ == FBT_INDIRECT_INT) { + auto i = static_cast(u); + return Mutate(Indirect(), i, byte_width_, WidthI(i)); + } else { + return false; + } + } + + bool MutateFloat(float f) + { + if (type_ == FBT_FLOAT) { + return MutateF(data_, f, parent_width_, BIT_WIDTH_32); + } else if (type_ == FBT_INDIRECT_FLOAT) { + return MutateF(Indirect(), f, byte_width_, BIT_WIDTH_32); + } else { + return false; + } + } + + bool MutateFloat(double d) + { + if (type_ == FBT_FLOAT) { + return MutateF(data_, d, parent_width_, WidthF(d)); + } else if (type_ == FBT_INDIRECT_FLOAT) { + return MutateF(Indirect(), d, byte_width_, WidthF(d)); + } else { + return false; + } + } + + bool MutateString(const char *str, size_t len) + { + auto s = AsString(); + if (s.IsTheEmptyString()) + return false; + // This is very strict, could allow shorter strings, but that creates + // garbage. + if (s.length() != len) + return false; + memcpy(const_cast(s.c_str()), str, len); + return true; + } + bool MutateString(const char *str) + { + return MutateString(str, strlen(str)); + } + bool MutateString(const std::string &str) + { + return MutateString(str.data(), str.length()); + } + +private: + const uint8_t *Indirect() const + { + return flexbuffers::Indirect(data_, parent_width_); + } + + template + bool Mutate(const uint8_t *dest, T t, size_t byte_width, + BitWidth value_width) + { + auto fits = static_cast(static_cast(1U) << value_width) <= + byte_width; + if (fits) { + t = flatbuffers::EndianScalar(t); + memcpy(const_cast(dest), &t, byte_width); + } + return fits; + } + + template + bool MutateF(const uint8_t *dest, T t, size_t byte_width, + BitWidth value_width) + { + if (byte_width == sizeof(double)) + return Mutate(dest, static_cast(t), byte_width, value_width); + if (byte_width == sizeof(float)) + return Mutate(dest, static_cast(t), byte_width, value_width); + FLATBUFFERS_ASSERT(false); + return false; + } + + const uint8_t *data_; + uint8_t parent_width_; + uint8_t byte_width_; + Type type_; +}; + +// Template specialization for As(). +template <> +inline bool Reference::As() const +{ + return AsBool(); +} + +template <> +inline int8_t Reference::As() const +{ + return AsInt8(); +} +template <> +inline int16_t Reference::As() const +{ + return AsInt16(); +} +template <> +inline int32_t Reference::As() const +{ + return AsInt32(); +} +template <> +inline int64_t Reference::As() const +{ + return AsInt64(); +} + +template <> +inline uint8_t Reference::As() const +{ + return AsUInt8(); +} +template <> +inline uint16_t Reference::As() const +{ + return AsUInt16(); +} +template <> +inline uint32_t Reference::As() const +{ + return AsUInt32(); +} +template <> +inline uint64_t Reference::As() const +{ + return AsUInt64(); +} + +template <> +inline double Reference::As() const +{ + return AsDouble(); +} +template <> +inline float Reference::As() const +{ + return AsFloat(); +} + +template <> +inline String Reference::As() const +{ + return AsString(); +} +template <> +inline std::string Reference::As() const +{ + return AsString().str(); +} + +template <> +inline Blob Reference::As() const +{ + return AsBlob(); +} +template <> +inline Vector Reference::As() const +{ + return AsVector(); +} +template <> +inline TypedVector Reference::As() const +{ + return AsTypedVector(); +} +template <> +inline FixedTypedVector Reference::As() const +{ + return AsFixedTypedVector(); +} +template <> +inline Map Reference::As() const +{ + return AsMap(); +} + +inline uint8_t PackedType(BitWidth bit_width, Type type) +{ + return static_cast(bit_width | (type << 2)); +} + +inline uint8_t NullPackedType() +{ + return PackedType(BIT_WIDTH_8, FBT_NULL); +} + +// Vector accessors. +// Note: if you try to access outside of bounds, you get a Null value back +// instead. Normally this would be an assert, but since this is "dynamically +// typed" data, you may not want that (someone sends you a 2d vector and you +// wanted 3d). +// The Null converts seamlessly into a default value for any other type. +// TODO(wvo): Could introduce an #ifdef that makes this into an assert? +inline Reference Vector::operator[](size_t i) const +{ + auto len = size(); + if (i >= len) + return Reference(nullptr, 1, NullPackedType()); + auto packed_type = (data_ + len * byte_width_)[i]; + auto elem = data_ + i * byte_width_; + return Reference(elem, byte_width_, packed_type); +} + +inline Reference TypedVector::operator[](size_t i) const +{ + auto len = size(); + if (i >= len) + return Reference(nullptr, 1, NullPackedType()); + auto elem = data_ + i * byte_width_; + return Reference(elem, byte_width_, 1, type_); +} + +inline Reference FixedTypedVector::operator[](size_t i) const +{ + if (i >= len_) + return Reference(nullptr, 1, NullPackedType()); + auto elem = data_ + i * byte_width_; + return Reference(elem, byte_width_, 1, type_); +} + +template +int KeyCompare(const void *key, const void *elem) +{ + auto str_elem = reinterpret_cast( + Indirect(reinterpret_cast(elem))); + auto skey = reinterpret_cast(key); + return strcmp(skey, str_elem); +} + +inline Reference Map::operator[](const char *key) const +{ + auto keys = Keys(); + // We can't pass keys.byte_width_ to the comparison function, so we have + // to pick the right one ahead of time. + int (*comp)(const void *, const void *) = nullptr; + switch (keys.byte_width_) { + case 1: + comp = KeyCompare; + break; + case 2: + comp = KeyCompare; + break; + case 4: + comp = KeyCompare; + break; + case 8: + comp = KeyCompare; + break; + } + auto res = std::bsearch(key, keys.data_, keys.size(), keys.byte_width_, comp); + if (!res) + return Reference(nullptr, 1, NullPackedType()); + auto i = (reinterpret_cast(res) - keys.data_) / keys.byte_width_; + return (*static_cast(this))[i]; +} + +inline Reference Map::operator[](const std::string &key) const +{ + return (*this)[key.c_str()]; +} + +inline Reference GetRoot(const uint8_t *buffer, size_t size) +{ + // See Finish() below for the serialization counterpart of this. + // The root starts at the end of the buffer, so we parse backwards from there. + auto end = buffer + size; + auto byte_width = *--end; + auto packed_type = *--end; + end -= byte_width; // The root data item. + return Reference(end, byte_width, packed_type); +} + +inline Reference GetRoot(const std::vector &buffer) +{ + return GetRoot(flatbuffers::vector_data(buffer), buffer.size()); +} + +// Flags that configure how the Builder behaves. +// The "Share" flags determine if the Builder automatically tries to pool +// this type. Pooling can reduce the size of serialized data if there are +// multiple maps of the same kind, at the expense of slightly slower +// serialization (the cost of lookups) and more memory use (std::set). +// By default this is on for keys, but off for strings. +// Turn keys off if you have e.g. only one map. +// Turn strings on if you expect many non-unique string values. +// Additionally, sharing key vectors can save space if you have maps with +// identical field populations. +enum BuilderFlag { + BUILDER_FLAG_NONE = 0, + BUILDER_FLAG_SHARE_KEYS = 1, + BUILDER_FLAG_SHARE_STRINGS = 2, + BUILDER_FLAG_SHARE_KEYS_AND_STRINGS = 3, + BUILDER_FLAG_SHARE_KEY_VECTORS = 4, + BUILDER_FLAG_SHARE_ALL = 7, +}; + +class Builder FLATBUFFERS_FINAL_CLASS { +public: + Builder(size_t initial_size = 256, + BuilderFlag flags = BUILDER_FLAG_SHARE_KEYS) + : buf_(initial_size), + finished_(false), + flags_(flags), + force_min_bit_width_(BIT_WIDTH_8), + key_pool(KeyOffsetCompare(buf_)), + string_pool(StringOffsetCompare(buf_)) + { + buf_.clear(); + } + + /// @brief Get the serialized buffer (after you call `Finish()`). + /// @return Returns a vector owned by this class. + const std::vector &GetBuffer() const + { + Finished(); + return buf_; + } + + // Size of the buffer. Does not include unfinished values. + size_t GetSize() const + { + return buf_.size(); + } + + // Reset all state so we can re-use the buffer. + void Clear() + { + buf_.clear(); + stack_.clear(); + finished_ = false; + // flags_ remains as-is; + force_min_bit_width_ = BIT_WIDTH_8; + key_pool.clear(); + string_pool.clear(); + } + + // All value constructing functions below have two versions: one that + // takes a key (for placement inside a map) and one that doesn't (for inside + // vectors and elsewhere). + + void Null() + { + stack_.push_back(Value()); + } + void Null(const char *key) + { + Key(key); + Null(); + } + + void Int(int64_t i) + { + stack_.push_back(Value(i, FBT_INT, WidthI(i))); + } + void Int(const char *key, int64_t i) + { + Key(key); + Int(i); + } + + void UInt(uint64_t u) + { + stack_.push_back(Value(u, FBT_UINT, WidthU(u))); + } + void UInt(const char *key, uint64_t u) + { + Key(key); + UInt(u); + } + + void Float(float f) + { + stack_.push_back(Value(f)); + } + void Float(const char *key, float f) + { + Key(key); + Float(f); + } + + void Double(double f) + { + stack_.push_back(Value(f)); + } + void Double(const char *key, double d) + { + Key(key); + Double(d); + } + + void Bool(bool b) + { + stack_.push_back(Value(b)); + } + void Bool(const char *key, bool b) + { + Key(key); + Bool(b); + } + + void IndirectInt(int64_t i) + { + PushIndirect(i, FBT_INDIRECT_INT, WidthI(i)); + } + void IndirectInt(const char *key, int64_t i) + { + Key(key); + IndirectInt(i); + } + + void IndirectUInt(uint64_t u) + { + PushIndirect(u, FBT_INDIRECT_UINT, WidthU(u)); + } + void IndirectUInt(const char *key, uint64_t u) + { + Key(key); + IndirectUInt(u); + } + + void IndirectFloat(float f) + { + PushIndirect(f, FBT_INDIRECT_FLOAT, BIT_WIDTH_32); + } + void IndirectFloat(const char *key, float f) + { + Key(key); + IndirectFloat(f); + } + + void IndirectDouble(double f) + { + PushIndirect(f, FBT_INDIRECT_FLOAT, WidthF(f)); + } + void IndirectDouble(const char *key, double d) + { + Key(key); + IndirectDouble(d); + } + + size_t Key(const char *str, size_t len) + { + auto sloc = buf_.size(); + WriteBytes(str, len + 1); + if (flags_ & BUILDER_FLAG_SHARE_KEYS) { + auto it = key_pool.find(sloc); + if (it != key_pool.end()) { + // Already in the buffer. Remove key we just serialized, and use + // existing offset instead. + buf_.resize(sloc); + sloc = *it; + } else { + key_pool.insert(sloc); + } + } + stack_.push_back(Value(static_cast(sloc), FBT_KEY, BIT_WIDTH_8)); + return sloc; + } + + size_t Key(const char *str) + { + return Key(str, strlen(str)); + } + size_t Key(const std::string &str) + { + return Key(str.c_str(), str.size()); + } + + size_t String(const char *str, size_t len) + { + auto reset_to = buf_.size(); + auto sloc = CreateBlob(str, len, 1, FBT_STRING); + if (flags_ & BUILDER_FLAG_SHARE_STRINGS) { + StringOffset so(sloc, len); + auto it = string_pool.find(so); + if (it != string_pool.end()) { + // Already in the buffer. Remove string we just serialized, and use + // existing offset instead. + buf_.resize(reset_to); + sloc = it->first; + stack_.back().u_ = sloc; + } else { + string_pool.insert(so); + } + } + return sloc; + } + size_t String(const char *str) + { + return String(str, strlen(str)); + } + size_t String(const std::string &str) + { + return String(str.c_str(), str.size()); + } + void String(const flexbuffers::String &str) + { + String(str.c_str(), str.length()); + } + + void String(const char *key, const char *str) + { + Key(key); + String(str); + } + void String(const char *key, const std::string &str) + { + Key(key); + String(str); + } + void String(const char *key, const flexbuffers::String &str) + { + Key(key); + String(str); + } + + size_t Blob(const void *data, size_t len) + { + return CreateBlob(data, len, 0, FBT_BLOB); + } + size_t Blob(const std::vector &v) + { + return CreateBlob(flatbuffers::vector_data(v), v.size(), 0, FBT_BLOB); + } + + // TODO(wvo): support all the FlexBuffer types (like flexbuffers::String), + // e.g. Vector etc. Also in overloaded versions. + // Also some FlatBuffers types? + + size_t StartVector() + { + return stack_.size(); + } + size_t StartVector(const char *key) + { + Key(key); + return stack_.size(); + } + size_t StartMap() + { + return stack_.size(); + } + size_t StartMap(const char *key) + { + Key(key); + return stack_.size(); + } + + // TODO(wvo): allow this to specify an aligment greater than the natural + // alignment. + size_t EndVector(size_t start, bool typed, bool fixed) + { + auto vec = CreateVector(start, stack_.size() - start, 1, typed, fixed); + // Remove temp elements and return vector. + stack_.resize(start); + stack_.push_back(vec); + return static_cast(vec.u_); + } + + size_t EndMap(size_t start) + { + // We should have interleaved keys and values on the stack. + // Make sure it is an even number: + auto len = stack_.size() - start; + FLATBUFFERS_ASSERT(!(len & 1)); + len /= 2; + // Make sure keys are all strings: + for (auto key = start; key < stack_.size(); key += 2) { + FLATBUFFERS_ASSERT(stack_[key].type_ == FBT_KEY); + } + // Now sort values, so later we can do a binary search lookup. + // We want to sort 2 array elements at a time. + struct TwoValue { + Value key; + Value val; + }; + // TODO(wvo): strict aliasing? + // TODO(wvo): allow the caller to indicate the data is already sorted + // for maximum efficiency? With an assert to check sortedness to make sure + // we're not breaking binary search. + // Or, we can track if the map is sorted as keys are added which would be + // be quite cheap (cheaper than checking it here), so we can skip this + // step automatically when appliccable, and encourage people to write in + // sorted fashion. + // std::sort is typically already a lot faster on sorted data though. + auto dict = + reinterpret_cast(flatbuffers::vector_data(stack_) + start); + std::sort(dict, dict + len, + [&](const TwoValue &a, const TwoValue &b) -> bool { + auto as = reinterpret_cast( + flatbuffers::vector_data(buf_) + a.key.u_); + auto bs = reinterpret_cast( + flatbuffers::vector_data(buf_) + b.key.u_); + auto comp = strcmp(as, bs); + // If this assertion hits, you've added two keys with the same + // value to this map. + // TODO: Have to check for pointer equality, as some sort + // implementation apparently call this function with the same + // element?? Why? + FLATBUFFERS_ASSERT(comp || &a == &b); + return comp < 0; + }); + // First create a vector out of all keys. + // TODO(wvo): if kBuilderFlagShareKeyVectors is true, see if we can share + // the first vector. + auto keys = CreateVector(start, len, 2, true, false); + auto vec = CreateVector(start + 1, len, 2, false, false, &keys); + // Remove temp elements and return map. + stack_.resize(start); + stack_.push_back(vec); + return static_cast(vec.u_); + } + + template + size_t Vector(F f) + { + auto start = StartVector(); + f(); + return EndVector(start, false, false); + } + template + size_t Vector(F f, T &state) + { + auto start = StartVector(); + f(state); + return EndVector(start, false, false); + } + template + size_t Vector(const char *key, F f) + { + auto start = StartVector(key); + f(); + return EndVector(start, false, false); + } + template + size_t Vector(const char *key, F f, T &state) + { + auto start = StartVector(key); + f(state); + return EndVector(start, false, false); + } + + template + void Vector(const T *elems, size_t len) + { + if (flatbuffers::is_scalar::value) { + // This path should be a lot quicker and use less space. + ScalarVector(elems, len, false); + } else { + auto start = StartVector(); + for (size_t i = 0; i < len; i++) + Add(elems[i]); + EndVector(start, false, false); + } + } + template + void Vector(const char *key, const T *elems, size_t len) + { + Key(key); + Vector(elems, len); + } + template + void Vector(const std::vector &vec) + { + Vector(flatbuffers::vector_data(vec), vec.size()); + } + + template + size_t TypedVector(F f) + { + auto start = StartVector(); + f(); + return EndVector(start, true, false); + } + template + size_t TypedVector(F f, T &state) + { + auto start = StartVector(); + f(state); + return EndVector(start, true, false); + } + template + size_t TypedVector(const char *key, F f) + { + auto start = StartVector(key); + f(); + return EndVector(start, true, false); + } + template + size_t TypedVector(const char *key, F f, T &state) + { + auto start = StartVector(key); + f(state); + return EndVector(start, true, false); + } + + template + size_t FixedTypedVector(const T *elems, size_t len) + { + // We only support a few fixed vector lengths. Anything bigger use a + // regular typed vector. + FLATBUFFERS_ASSERT(len >= 2 && len <= 4); + // And only scalar values. + static_assert(flatbuffers::is_scalar::value, "Unrelated types"); + return ScalarVector(elems, len, true); + } + + template + size_t FixedTypedVector(const char *key, const T *elems, size_t len) + { + Key(key); + return FixedTypedVector(elems, len); + } + + template + size_t Map(F f) + { + auto start = StartMap(); + f(); + return EndMap(start); + } + template + size_t Map(F f, T &state) + { + auto start = StartMap(); + f(state); + return EndMap(start); + } + template + size_t Map(const char *key, F f) + { + auto start = StartMap(key); + f(); + return EndMap(start); + } + template + size_t Map(const char *key, F f, T &state) + { + auto start = StartMap(key); + f(state); + return EndMap(start); + } + template + void Map(const std::map &map) + { + auto start = StartMap(); + for (auto it = map.begin(); it != map.end(); ++it) + Add(it->first.c_str(), it->second); + EndMap(start); + } + + // If you wish to share a value explicitly (a value not shared automatically + // through one of the BUILDER_FLAG_SHARE_* flags) you can do so with these + // functions. Or if you wish to turn those flags off for performance reasons + // and still do some explicit sharing. For example: + // builder.IndirectDouble(M_PI); + // auto id = builder.LastValue(); // Remember where we stored it. + // .. more code goes here .. + // builder.ReuseValue(id); // Refers to same double by offset. + // LastValue works regardless of whether the value has a key or not. + // Works on any data type. + struct Value; + Value LastValue() + { + return stack_.back(); + } + void ReuseValue(Value v) + { + stack_.push_back(v); + } + void ReuseValue(const char *key, Value v) + { + Key(key); + ReuseValue(v); + } + + // Overloaded Add that tries to call the correct function above. + void Add(int8_t i) + { + Int(i); + } + void Add(int16_t i) + { + Int(i); + } + void Add(int32_t i) + { + Int(i); + } + void Add(int64_t i) + { + Int(i); + } + void Add(uint8_t u) + { + UInt(u); + } + void Add(uint16_t u) + { + UInt(u); + } + void Add(uint32_t u) + { + UInt(u); + } + void Add(uint64_t u) + { + UInt(u); + } + void Add(float f) + { + Float(f); + } + void Add(double d) + { + Double(d); + } + void Add(bool b) + { + Bool(b); + } + void Add(const char *str) + { + String(str); + } + void Add(const std::string &str) + { + String(str); + } + void Add(const flexbuffers::String &str) + { + String(str); + } + + template + void Add(const std::vector &vec) + { + Vector(vec); + } + + template + void Add(const char *key, const T &t) + { + Key(key); + Add(t); + } + + template + void Add(const std::map &map) + { + Map(map); + } + + template + void operator+=(const T &t) + { + Add(t); + } + + // This function is useful in combination with the Mutate* functions above. + // It forces elements of vectors and maps to have a minimum size, such that + // they can later be updated without failing. + // Call with no arguments to reset. + void ForceMinimumBitWidth(BitWidth bw = BIT_WIDTH_8) + { + force_min_bit_width_ = bw; + } + + void Finish() + { + // If you hit this assert, you likely have objects that were never included + // in a parent. You need to have exactly one root to finish a buffer. + // Check your Start/End calls are matched, and all objects are inside + // some other object. + FLATBUFFERS_ASSERT(stack_.size() == 1); + + // Write root value. + auto byte_width = Align(stack_[0].ElemWidth(buf_.size(), 0)); + WriteAny(stack_[0], byte_width); + // Write root type. + Write(stack_[0].StoredPackedType(), 1); + // Write root size. Normally determined by parent, but root has no parent :) + Write(byte_width, 1); + + finished_ = true; + } + +private: + void Finished() const + { + // If you get this assert, you're attempting to get access a buffer + // which hasn't been finished yet. Be sure to call + // Builder::Finish with your root object. + FLATBUFFERS_ASSERT(finished_); + } + + // Align to prepare for writing a scalar with a certain size. + uint8_t Align(BitWidth alignment) + { + auto byte_width = 1U << alignment; + buf_.insert(buf_.end(), flatbuffers::PaddingBytes(buf_.size(), byte_width), + 0); + return static_cast(byte_width); + } + + void WriteBytes(const void *val, size_t size) + { + buf_.insert(buf_.end(), reinterpret_cast(val), + reinterpret_cast(val) + size); + } + + template + void Write(T val, size_t byte_width) + { + FLATBUFFERS_ASSERT(sizeof(T) >= byte_width); + val = flatbuffers::EndianScalar(val); + WriteBytes(&val, byte_width); + } + + void WriteDouble(double f, uint8_t byte_width) + { + switch (byte_width) { + case 8: + Write(f, byte_width); + break; + case 4: + Write(static_cast(f), byte_width); + break; + // case 2: Write(static_cast(f), byte_width); break; + // case 1: Write(static_cast(f), byte_width); break; + default: + FLATBUFFERS_ASSERT(0); + } + } + + void WriteOffset(uint64_t o, uint8_t byte_width) + { + auto reloff = buf_.size() - o; + FLATBUFFERS_ASSERT(byte_width == 8 || reloff < 1ULL << (byte_width * 8)); + Write(reloff, byte_width); + } + + template + void PushIndirect(T val, Type type, BitWidth bit_width) + { + auto byte_width = Align(bit_width); + auto iloc = buf_.size(); + Write(val, byte_width); + stack_.push_back(Value(static_cast(iloc), type, bit_width)); + } + + static BitWidth WidthB(size_t byte_width) + { + switch (byte_width) { + case 1: + return BIT_WIDTH_8; + case 2: + return BIT_WIDTH_16; + case 4: + return BIT_WIDTH_32; + case 8: + return BIT_WIDTH_64; + default: + FLATBUFFERS_ASSERT(false); + return BIT_WIDTH_64; + } + } + + template + static Type GetScalarType() + { + static_assert(flatbuffers::is_scalar::value, "Unrelated types"); + return flatbuffers::is_floating_point::value ? FBT_FLOAT : flatbuffers::is_same::value ? FBT_BOOL : + (flatbuffers::is_unsigned::value ? FBT_UINT : FBT_INT); + } + +public: + // This was really intended to be private, except for LastValue/ReuseValue. + struct Value { + union { + int64_t i_; + uint64_t u_; + double f_; + }; + + Type type_; + + // For scalars: of itself, for vector: of its elements, for string: length. + BitWidth min_bit_width_; + + Value() + : i_(0), type_(FBT_NULL), min_bit_width_(BIT_WIDTH_8) + { + } + + Value(bool b) + : u_(static_cast(b)), + type_(FBT_BOOL), + min_bit_width_(BIT_WIDTH_8) + { + } + + Value(int64_t i, Type t, BitWidth bw) + : i_(i), type_(t), min_bit_width_(bw) + { + } + Value(uint64_t u, Type t, BitWidth bw) + : u_(u), type_(t), min_bit_width_(bw) + { + } + + Value(float f) + : f_(static_cast(f)), + type_(FBT_FLOAT), + min_bit_width_(BIT_WIDTH_32) + { + } + Value(double f) + : f_(f), type_(FBT_FLOAT), min_bit_width_(WidthF(f)) + { + } + + uint8_t StoredPackedType(BitWidth parent_bit_width_ = BIT_WIDTH_8) const + { + return PackedType(StoredWidth(parent_bit_width_), type_); + } + + BitWidth ElemWidth(size_t buf_size, size_t elem_index) const + { + if (IsInline(type_)) { + return min_bit_width_; + } else { + // We have an absolute offset, but want to store a relative offset + // elem_index elements beyond the current buffer end. Since whether + // the relative offset fits in a certain byte_width depends on + // the size of the elements before it (and their alignment), we have + // to test for each size in turn. + for (size_t byte_width = 1; + byte_width <= sizeof(flatbuffers::largest_scalar_t); + byte_width *= 2) { + // Where are we going to write this offset? + auto offset_loc = buf_size + + flatbuffers::PaddingBytes(buf_size, byte_width) + + elem_index * byte_width; + // Compute relative offset. + auto offset = offset_loc - u_; + // Does it fit? + auto bit_width = WidthU(offset); + if (static_cast(static_cast(1U) << bit_width) == + byte_width) + return bit_width; + } + FLATBUFFERS_ASSERT(false); // Must match one of the sizes above. + return BIT_WIDTH_64; + } + } + + BitWidth StoredWidth(BitWidth parent_bit_width_ = BIT_WIDTH_8) const + { + if (IsInline(type_)) { + return (std::max)(min_bit_width_, parent_bit_width_); + } else { + return min_bit_width_; + } + } + }; + +private: + void WriteAny(const Value &val, uint8_t byte_width) + { + switch (val.type_) { + case FBT_NULL: + case FBT_INT: + Write(val.i_, byte_width); + break; + case FBT_BOOL: + case FBT_UINT: + Write(val.u_, byte_width); + break; + case FBT_FLOAT: + WriteDouble(val.f_, byte_width); + break; + default: + WriteOffset(val.u_, byte_width); + break; + } + } + + size_t CreateBlob(const void *data, size_t len, size_t trailing, Type type) + { + auto bit_width = WidthU(len); + auto byte_width = Align(bit_width); + Write(len, byte_width); + auto sloc = buf_.size(); + WriteBytes(data, len + trailing); + stack_.push_back(Value(static_cast(sloc), type, bit_width)); + return sloc; + } + + template + size_t ScalarVector(const T *elems, size_t len, bool fixed) + { + auto vector_type = GetScalarType(); + auto byte_width = sizeof(T); + auto bit_width = WidthB(byte_width); + // If you get this assert, you're trying to write a vector with a size + // field that is bigger than the scalars you're trying to write (e.g. a + // byte vector > 255 elements). For such types, write a "blob" instead. + // TODO: instead of asserting, could write vector with larger elements + // instead, though that would be wasteful. + FLATBUFFERS_ASSERT(WidthU(len) <= bit_width); + Align(bit_width); + if (!fixed) + Write(len, byte_width); + auto vloc = buf_.size(); + for (size_t i = 0; i < len; i++) + Write(elems[i], byte_width); + stack_.push_back(Value(static_cast(vloc), + ToTypedVector(vector_type, fixed ? len : 0), + bit_width)); + return vloc; + } + + Value CreateVector(size_t start, size_t vec_len, size_t step, bool typed, + bool fixed, const Value *keys = nullptr) + { + FLATBUFFERS_ASSERT( + !fixed || + typed); // typed=false, fixed=true combination is not supported. + // Figure out smallest bit width we can store this vector with. + auto bit_width = (std::max)(force_min_bit_width_, WidthU(vec_len)); + auto prefix_elems = 1; + if (keys) { + // If this vector is part of a map, we will pre-fix an offset to the keys + // to this vector. + bit_width = (std::max)(bit_width, keys->ElemWidth(buf_.size(), 0)); + prefix_elems += 2; + } + Type vector_type = FBT_KEY; + // Check bit widths and types for all elements. + for (size_t i = start; i < stack_.size(); i += step) { + auto elem_width = + stack_[i].ElemWidth(buf_.size(), i - start + prefix_elems); + bit_width = (std::max)(bit_width, elem_width); + if (typed) { + if (i == start) { + vector_type = stack_[i].type_; + } else { + // If you get this assert, you are writing a typed vector with + // elements that are not all the same type. + FLATBUFFERS_ASSERT(vector_type == stack_[i].type_); + } + } + } + // If you get this assert, your fixed types are not one of: + // Int / UInt / Float / Key. + FLATBUFFERS_ASSERT(!fixed || IsTypedVectorElementType(vector_type)); + auto byte_width = Align(bit_width); + // Write vector. First the keys width/offset if available, and size. + if (keys) { + WriteOffset(keys->u_, byte_width); + Write(1ULL << keys->min_bit_width_, byte_width); + } + if (!fixed) + Write(vec_len, byte_width); + // Then the actual data. + auto vloc = buf_.size(); + for (size_t i = start; i < stack_.size(); i += step) { + WriteAny(stack_[i], byte_width); + } + // Then the types. + if (!typed) { + for (size_t i = start; i < stack_.size(); i += step) { + buf_.push_back(stack_[i].StoredPackedType(bit_width)); + } + } + return Value(static_cast(vloc), + keys ? FBT_MAP : (typed ? ToTypedVector(vector_type, fixed ? vec_len : 0) : FBT_VECTOR), + bit_width); + } + + // You shouldn't really be copying instances of this class. + Builder(const Builder &); + Builder &operator=(const Builder &); + + std::vector buf_; + std::vector stack_; + + bool finished_; + + BuilderFlag flags_; + + BitWidth force_min_bit_width_; + + struct KeyOffsetCompare { + explicit KeyOffsetCompare(const std::vector &buf) + : buf_(&buf) + { + } + bool operator()(size_t a, size_t b) const + { + auto stra = + reinterpret_cast(flatbuffers::vector_data(*buf_) + a); + auto strb = + reinterpret_cast(flatbuffers::vector_data(*buf_) + b); + return strcmp(stra, strb) < 0; + } + const std::vector *buf_; + }; + + typedef std::pair StringOffset; + struct StringOffsetCompare { + explicit StringOffsetCompare(const std::vector &buf) + : buf_(&buf) + { + } + bool operator()(const StringOffset &a, const StringOffset &b) const + { + auto stra = reinterpret_cast( + flatbuffers::vector_data(*buf_) + a.first); + auto strb = reinterpret_cast( + flatbuffers::vector_data(*buf_) + b.first); + return strncmp(stra, strb, (std::min)(a.second, b.second) + 1) < 0; + } + const std::vector *buf_; + }; + + typedef std::set KeyOffsetMap; + typedef std::set StringOffsetMap; + + KeyOffsetMap key_pool; + StringOffsetMap string_pool; +}; + +} // namespace flexbuffers + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + +#endif // FLATBUFFERS_FLEXBUFFERS_H_ diff --git a/components/tflite/third_party/flatbuffers/include/flatbuffers/grpc.h b/components/tflite/third_party/flatbuffers/include/flatbuffers/grpc.h new file mode 100644 index 00000000..dc4c78ab --- /dev/null +++ b/components/tflite/third_party/flatbuffers/include/flatbuffers/grpc.h @@ -0,0 +1,390 @@ +/* + * Copyright 2014 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FLATBUFFERS_GRPC_H_ +#define FLATBUFFERS_GRPC_H_ + +// Helper functionality to glue FlatBuffers and GRPC. + +#include "flatbuffers/flatbuffers.h" +#include "grpc++/support/byte_buffer.h" +#include "grpc/byte_buffer_reader.h" + +namespace flatbuffers { +namespace grpc { +// Message is a typed wrapper around a buffer that manages the underlying +// `grpc_slice` and also provides flatbuffers-specific helpers such as `Verify` +// and `GetRoot`. Since it is backed by a `grpc_slice`, the underlying buffer +// is refcounted and ownership is be managed automatically. +template +class Message { +public: + Message() + : slice_(grpc_empty_slice()) + { + } + + Message(grpc_slice slice, bool add_ref) + : slice_(add_ref ? grpc_slice_ref(slice) : slice) + { + } + + Message &operator=(const Message &other) = delete; + + Message(Message &&other) + : slice_(other.slice_) + { + other.slice_ = grpc_empty_slice(); + } + + Message(const Message &other) = delete; + + Message &operator=(Message &&other) + { + grpc_slice_unref(slice_); + slice_ = other.slice_; + other.slice_ = grpc_empty_slice(); + return *this; + } + + ~Message() + { + grpc_slice_unref(slice_); + } + + const uint8_t *mutable_data() const + { + return GRPC_SLICE_START_PTR(slice_); + } + + const uint8_t *data() const + { + return GRPC_SLICE_START_PTR(slice_); + } + + size_t size() const + { + return GRPC_SLICE_LENGTH(slice_); + } + + bool Verify() const + { + Verifier verifier(data(), size()); + return verifier.VerifyBuffer(nullptr); + } + + T *GetMutableRoot() + { + return flatbuffers::GetMutableRoot(mutable_data()); + } + + const T *GetRoot() const + { + return flatbuffers::GetRoot(data()); + } + + // This is only intended for serializer use, or if you know what you're doing + const grpc_slice &BorrowSlice() const + { + return slice_; + } + +private: + grpc_slice slice_; +}; + +class MessageBuilder; + +// SliceAllocator is a gRPC-specific allocator that uses the `grpc_slice` +// refcounted slices to manage memory ownership. This makes it easy and +// efficient to transfer buffers to gRPC. +class SliceAllocator : public Allocator { +public: + SliceAllocator() + : slice_(grpc_empty_slice()) + { + } + + SliceAllocator(const SliceAllocator &other) = delete; + SliceAllocator &operator=(const SliceAllocator &other) = delete; + + SliceAllocator(SliceAllocator &&other) + : slice_(grpc_empty_slice()) + { + // default-construct and swap idiom + swap(other); + } + + SliceAllocator &operator=(SliceAllocator &&other) + { + // move-construct and swap idiom + SliceAllocator temp(std::move(other)); + swap(temp); + return *this; + } + + void swap(SliceAllocator &other) + { + using std::swap; + swap(slice_, other.slice_); + } + + virtual ~SliceAllocator() + { + grpc_slice_unref(slice_); + } + + virtual uint8_t *allocate(size_t size) override + { + FLATBUFFERS_ASSERT(GRPC_SLICE_IS_EMPTY(slice_)); + slice_ = grpc_slice_malloc(size); + return GRPC_SLICE_START_PTR(slice_); + } + + virtual void deallocate(uint8_t *p, size_t size) override + { + FLATBUFFERS_ASSERT(p == GRPC_SLICE_START_PTR(slice_)); + FLATBUFFERS_ASSERT(size == GRPC_SLICE_LENGTH(slice_)); + grpc_slice_unref(slice_); + slice_ = grpc_empty_slice(); + } + + virtual uint8_t *reallocate_downward(uint8_t *old_p, size_t old_size, + size_t new_size, size_t in_use_back, + size_t in_use_front) override + { + FLATBUFFERS_ASSERT(old_p == GRPC_SLICE_START_PTR(slice_)); + FLATBUFFERS_ASSERT(old_size == GRPC_SLICE_LENGTH(slice_)); + FLATBUFFERS_ASSERT(new_size > old_size); + grpc_slice old_slice = slice_; + grpc_slice new_slice = grpc_slice_malloc(new_size); + uint8_t *new_p = GRPC_SLICE_START_PTR(new_slice); + memcpy_downward(old_p, old_size, new_p, new_size, in_use_back, + in_use_front); + slice_ = new_slice; + grpc_slice_unref(old_slice); + return new_p; + } + +private: + grpc_slice &get_slice(uint8_t *p, size_t size) + { + FLATBUFFERS_ASSERT(p == GRPC_SLICE_START_PTR(slice_)); + FLATBUFFERS_ASSERT(size == GRPC_SLICE_LENGTH(slice_)); + return slice_; + } + + grpc_slice slice_; + + friend class MessageBuilder; +}; + +// SliceAllocatorMember is a hack to ensure that the MessageBuilder's +// slice_allocator_ member is constructed before the FlatBufferBuilder, since +// the allocator is used in the FlatBufferBuilder ctor. +namespace detail { +struct SliceAllocatorMember { + SliceAllocator slice_allocator_; +}; +} // namespace detail + +// MessageBuilder is a gRPC-specific FlatBufferBuilder that uses SliceAllocator +// to allocate gRPC buffers. +class MessageBuilder : private detail::SliceAllocatorMember, + public FlatBufferBuilder { +public: + explicit MessageBuilder(uoffset_t initial_size = 1024) + : FlatBufferBuilder(initial_size, &slice_allocator_, false) + { + } + + MessageBuilder(const MessageBuilder &other) = delete; + MessageBuilder &operator=(const MessageBuilder &other) = delete; + + MessageBuilder(MessageBuilder &&other) + : FlatBufferBuilder(1024, &slice_allocator_, false) + { + // Default construct and swap idiom. + Swap(other); + } + + /// Create a MessageBuilder from a FlatBufferBuilder. + explicit MessageBuilder(FlatBufferBuilder &&src, + void (*dealloc)(void *, + size_t) = &DefaultAllocator::dealloc) + : FlatBufferBuilder(1024, &slice_allocator_, false) + { + src.Swap(*this); + src.SwapBufAllocator(*this); + if (buf_.capacity()) { + uint8_t *buf = buf_.scratch_data(); // pointer to memory + size_t capacity = buf_.capacity(); // size of memory + slice_allocator_.slice_ = grpc_slice_new_with_len(buf, capacity, dealloc); + } else { + slice_allocator_.slice_ = grpc_empty_slice(); + } + } + + /// Move-assign a FlatBufferBuilder to a MessageBuilder. + /// Only FlatBufferBuilder with default allocator (basically, nullptr) is + /// supported. + MessageBuilder &operator=(FlatBufferBuilder &&src) + { + // Move construct a temporary and swap + MessageBuilder temp(std::move(src)); + Swap(temp); + return *this; + } + + MessageBuilder &operator=(MessageBuilder &&other) + { + // Move construct a temporary and swap + MessageBuilder temp(std::move(other)); + Swap(temp); + return *this; + } + + void Swap(MessageBuilder &other) + { + slice_allocator_.swap(other.slice_allocator_); + FlatBufferBuilder::Swap(other); + // After swapping the FlatBufferBuilder, we swap back the allocator, which + // restores the original allocator back in place. This is necessary because + // MessageBuilder's allocator is its own member (SliceAllocatorMember). The + // allocator passed to FlatBufferBuilder::vector_downward must point to this + // member. + buf_.swap_allocator(other.buf_); + } + + // Releases the ownership of the buffer pointer. + // Returns the size, offset, and the original grpc_slice that + // allocated the buffer. Also see grpc_slice_unref(). + uint8_t *ReleaseRaw(size_t &size, size_t &offset, grpc_slice &slice) + { + uint8_t *buf = FlatBufferBuilder::ReleaseRaw(size, offset); + slice = slice_allocator_.slice_; + slice_allocator_.slice_ = grpc_empty_slice(); + return buf; + } + + ~MessageBuilder() + { + } + + // GetMessage extracts the subslice of the buffer corresponding to the + // flatbuffers-encoded region and wraps it in a `Message` to handle buffer + // ownership. + template + Message GetMessage() + { + auto buf_data = buf_.scratch_data(); // pointer to memory + auto buf_size = buf_.capacity(); // size of memory + auto msg_data = buf_.data(); // pointer to msg + auto msg_size = buf_.size(); // size of msg + // Do some sanity checks on data/size + FLATBUFFERS_ASSERT(msg_data); + FLATBUFFERS_ASSERT(msg_size); + FLATBUFFERS_ASSERT(msg_data >= buf_data); + FLATBUFFERS_ASSERT(msg_data + msg_size <= buf_data + buf_size); + // Calculate offsets from the buffer start + auto begin = msg_data - buf_data; + auto end = begin + msg_size; + // Get the slice we are working with (no refcount change) + grpc_slice slice = slice_allocator_.get_slice(buf_data, buf_size); + // Extract a subslice of the existing slice (increment refcount) + grpc_slice subslice = grpc_slice_sub(slice, begin, end); + // Wrap the subslice in a `Message`, but don't increment refcount + Message msg(subslice, false); + return msg; + } + + template + Message ReleaseMessage() + { + Message msg = GetMessage(); + Reset(); + return msg; + } + +private: + // SliceAllocator slice_allocator_; // part of SliceAllocatorMember +}; + +} // namespace grpc +} // namespace flatbuffers + +namespace grpc { +template +class SerializationTraits > { +public: + static grpc::Status Serialize(const flatbuffers::grpc::Message &msg, + grpc_byte_buffer **buffer, bool *own_buffer) + { + // We are passed in a `Message`, which is a wrapper around a + // `grpc_slice`. We extract it here using `BorrowSlice()`. The const cast + // is necessary because the `grpc_raw_byte_buffer_create` func expects + // non-const slices in order to increment their refcounts. + grpc_slice *slice = const_cast(&msg.BorrowSlice()); + // Now use `grpc_raw_byte_buffer_create` to package the single slice into a + // `grpc_byte_buffer`, incrementing the refcount in the process. + *buffer = grpc_raw_byte_buffer_create(slice, 1); + *own_buffer = true; + return grpc::Status::OK; + } + + // Deserialize by pulling the + static grpc::Status Deserialize(grpc_byte_buffer *buffer, + flatbuffers::grpc::Message *msg) + { + if (!buffer) { + return ::grpc::Status(::grpc::StatusCode::INTERNAL, "No payload"); + } + // Check if this is a single uncompressed slice. + if ((buffer->type == GRPC_BB_RAW) && + (buffer->data.raw.compression == GRPC_COMPRESS_NONE) && + (buffer->data.raw.slice_buffer.count == 1)) { + // If it is, then we can reference the `grpc_slice` directly. + grpc_slice slice = buffer->data.raw.slice_buffer.slices[0]; + // We wrap a `Message` around the slice, incrementing the refcount. + *msg = flatbuffers::grpc::Message(slice, true); + } else { + // Otherwise, we need to use `grpc_byte_buffer_reader_readall` to read + // `buffer` into a single contiguous `grpc_slice`. The gRPC reader gives + // us back a new slice with the refcount already incremented. + grpc_byte_buffer_reader reader; + grpc_byte_buffer_reader_init(&reader, buffer); + grpc_slice slice = grpc_byte_buffer_reader_readall(&reader); + grpc_byte_buffer_reader_destroy(&reader); + // We wrap a `Message` around the slice, but don't increment refcount + *msg = flatbuffers::grpc::Message(slice, false); + } + grpc_byte_buffer_destroy(buffer); +#if FLATBUFFERS_GRPC_DISABLE_AUTO_VERIFICATION + return ::grpc::Status::OK; +#else + if (msg->Verify()) { + return ::grpc::Status::OK; + } else { + return ::grpc::Status(::grpc::StatusCode::INTERNAL, + "Message verification failed"); + } +#endif + } +}; + +} // namespace grpc + +#endif // FLATBUFFERS_GRPC_H_ diff --git a/components/tflite/third_party/flatbuffers/include/flatbuffers/hash.h b/components/tflite/third_party/flatbuffers/include/flatbuffers/hash.h new file mode 100644 index 00000000..a197cb5f --- /dev/null +++ b/components/tflite/third_party/flatbuffers/include/flatbuffers/hash.h @@ -0,0 +1,141 @@ +/* + * Copyright 2015 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FLATBUFFERS_HASH_H_ +#define FLATBUFFERS_HASH_H_ + +#include +#include + +#include "flatbuffers/flatbuffers.h" + +namespace flatbuffers { +template +struct FnvTraits { + static const T kFnvPrime; + static const T kOffsetBasis; +}; + +template <> +struct FnvTraits { + static const uint32_t kFnvPrime = 0x01000193; + static const uint32_t kOffsetBasis = 0x811C9DC5; +}; + +template <> +struct FnvTraits { + static const uint64_t kFnvPrime = 0x00000100000001b3ULL; + static const uint64_t kOffsetBasis = 0xcbf29ce484222645ULL; +}; + +template +T HashFnv1(const char *input) +{ + T hash = FnvTraits::kOffsetBasis; + for (const char *c = input; *c; ++c) { + hash *= FnvTraits::kFnvPrime; + hash ^= static_cast(*c); + } + return hash; +} + +template +T HashFnv1a(const char *input) +{ + T hash = FnvTraits::kOffsetBasis; + for (const char *c = input; *c; ++c) { + hash ^= static_cast(*c); + hash *= FnvTraits::kFnvPrime; + } + return hash; +} + +template <> +inline uint16_t HashFnv1(const char *input) +{ + uint32_t hash = HashFnv1(input); + return (hash >> 16) ^ (hash & 0xffff); +} + +template <> +inline uint16_t HashFnv1a(const char *input) +{ + uint32_t hash = HashFnv1a(input); + return (hash >> 16) ^ (hash & 0xffff); +} + +template +struct NamedHashFunction { + const char *name; + + typedef T (*HashFunction)(const char *); + HashFunction function; +}; + +const NamedHashFunction kHashFunctions16[] = { + { "fnv1_16", HashFnv1 }, + { "fnv1a_16", HashFnv1a }, +}; + +const NamedHashFunction kHashFunctions32[] = { + { "fnv1_32", HashFnv1 }, + { "fnv1a_32", HashFnv1a }, +}; + +const NamedHashFunction kHashFunctions64[] = { + { "fnv1_64", HashFnv1 }, + { "fnv1a_64", HashFnv1a }, +}; + +inline NamedHashFunction::HashFunction FindHashFunction16( + const char *name) +{ + std::size_t size = sizeof(kHashFunctions16) / sizeof(kHashFunctions16[0]); + for (std::size_t i = 0; i < size; ++i) { + if (std::strcmp(name, kHashFunctions16[i].name) == 0) { + return kHashFunctions16[i].function; + } + } + return nullptr; +} + +inline NamedHashFunction::HashFunction FindHashFunction32( + const char *name) +{ + std::size_t size = sizeof(kHashFunctions32) / sizeof(kHashFunctions32[0]); + for (std::size_t i = 0; i < size; ++i) { + if (std::strcmp(name, kHashFunctions32[i].name) == 0) { + return kHashFunctions32[i].function; + } + } + return nullptr; +} + +inline NamedHashFunction::HashFunction FindHashFunction64( + const char *name) +{ + std::size_t size = sizeof(kHashFunctions64) / sizeof(kHashFunctions64[0]); + for (std::size_t i = 0; i < size; ++i) { + if (std::strcmp(name, kHashFunctions64[i].name) == 0) { + return kHashFunctions64[i].function; + } + } + return nullptr; +} + +} // namespace flatbuffers + +#endif // FLATBUFFERS_HASH_H_ diff --git a/components/tflite/third_party/flatbuffers/include/flatbuffers/idl.h b/components/tflite/third_party/flatbuffers/include/flatbuffers/idl.h new file mode 100644 index 00000000..8de343d3 --- /dev/null +++ b/components/tflite/third_party/flatbuffers/include/flatbuffers/idl.h @@ -0,0 +1,1241 @@ +/* + * Copyright 2014 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FLATBUFFERS_IDL_H_ +#define FLATBUFFERS_IDL_H_ + +#include +#include +#include + +#include "flatbuffers/base.h" +#include "flatbuffers/flatbuffers.h" +#include "flatbuffers/flexbuffers.h" +#include "flatbuffers/hash.h" +#include "flatbuffers/reflection.h" + +#if !defined(FLATBUFFERS_CPP98_STL) +#include +#endif // !defined(FLATBUFFERS_CPP98_STL) + +// This file defines the data types representing a parsed IDL (Interface +// Definition Language) / schema file. + +// Limits maximum depth of nested objects. +// Prevents stack overflow while parse flatbuffers or json. +#if !defined(FLATBUFFERS_MAX_PARSING_DEPTH) +#define FLATBUFFERS_MAX_PARSING_DEPTH 64 +#endif + +namespace flatbuffers { +// The order of these matters for Is*() functions below. +// Additionally, Parser::ParseType assumes bool..string is a contiguous range +// of type tokens. +// clang-format off +#define FLATBUFFERS_GEN_TYPES_SCALAR(TD) \ + TD(NONE, "", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8) \ + TD(UTYPE, "", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8) /* begin scalar/int */ \ + TD(BOOL, "bool", uint8_t, boolean,bool, bool, bool, bool, Boolean, Bool) \ + TD(CHAR, "byte", int8_t, byte, int8, sbyte, int8, i8, Byte, Int8) \ + TD(UCHAR, "ubyte", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8) \ + TD(SHORT, "short", int16_t, short, int16, short, int16, i16, Short, Int16) \ + TD(USHORT, "ushort", uint16_t, short, uint16, ushort, uint16, u16, UShort, UInt16) \ + TD(INT, "int", int32_t, int, int32, int, int32, i32, Int, Int32) \ + TD(UINT, "uint", uint32_t, int, uint32, uint, uint32, u32, UInt, UInt32) \ + TD(LONG, "long", int64_t, long, int64, long, int64, i64, Long, Int64) \ + TD(ULONG, "ulong", uint64_t, long, uint64, ulong, uint64, u64, ULong, UInt64) /* end int */ \ + TD(FLOAT, "float", float, float, float32, float, float32, f32, Float, Float32) /* begin float */ \ + TD(DOUBLE, "double", double, double, float64, double, float64, f64, Double, Double) /* end float/scalar */ +#define FLATBUFFERS_GEN_TYPES_POINTER(TD) \ + TD(STRING, "string", Offset, int, int, StringOffset, int, unused, Int, Offset) \ + TD(VECTOR, "", Offset, int, int, VectorOffset, int, unused, Int, Offset) \ + TD(STRUCT, "", Offset, int, int, int, int, unused, Int, Offset) \ + TD(UNION, "", Offset, int, int, int, int, unused, Int, Offset) +#define FLATBUFFERS_GEN_TYPE_ARRAY(TD) \ + TD(ARRAY, "", int, int, int, int, int, unused, Int, Offset) +// The fields are: +// - enum +// - FlatBuffers schema type. +// - C++ type. +// - Java type. +// - Go type. +// - C# / .Net type. +// - Python type. +// - Rust type. +// - Kotlin type. + +// using these macros, we can now write code dealing with types just once, e.g. + +/* +switch (type) { + #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, \ + RTYPE, KTYPE) \ + case BASE_TYPE_ ## ENUM: \ + // do something specific to CTYPE here + FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) + #undef FLATBUFFERS_TD +} +*/ + +// If not all FLATBUFFERS_GEN_() arguments are necessary for implementation +// of FLATBUFFERS_TD, you can use a variadic macro (with __VA_ARGS__ if needed). +// In the above example, only CTYPE is used to generate the code, it can be rewritten: + +/* +switch (type) { + #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, ...) \ + case BASE_TYPE_ ## ENUM: \ + // do something specific to CTYPE here + FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) + #undef FLATBUFFERS_TD +} +*/ + +#define FLATBUFFERS_GEN_TYPES(TD) \ + FLATBUFFERS_GEN_TYPES_SCALAR(TD) \ + FLATBUFFERS_GEN_TYPES_POINTER(TD) \ + FLATBUFFERS_GEN_TYPE_ARRAY(TD) + +// Create an enum for all the types above. +#ifdef __GNUC__ +__extension__ // Stop GCC complaining about trailing comma with -Wpendantic. +#endif +enum BaseType { + #define FLATBUFFERS_TD(ENUM, ...) \ + BASE_TYPE_ ## ENUM, + FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) + #undef FLATBUFFERS_TD +}; + +#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, ...) \ + static_assert(sizeof(CTYPE) <= sizeof(largest_scalar_t), \ + "define largest_scalar_t as " #CTYPE); + FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) +#undef FLATBUFFERS_TD + +inline bool IsScalar (BaseType t) { return t >= BASE_TYPE_UTYPE && + t <= BASE_TYPE_DOUBLE; } +inline bool IsInteger(BaseType t) { return t >= BASE_TYPE_UTYPE && + t <= BASE_TYPE_ULONG; } +inline bool IsFloat (BaseType t) { return t == BASE_TYPE_FLOAT || + t == BASE_TYPE_DOUBLE; } +inline bool IsLong (BaseType t) { return t == BASE_TYPE_LONG || + t == BASE_TYPE_ULONG; } +inline bool IsBool (BaseType t) { return t == BASE_TYPE_BOOL; } +inline bool IsOneByte(BaseType t) { return t >= BASE_TYPE_UTYPE && + t <= BASE_TYPE_UCHAR; } + +inline bool IsUnsigned(BaseType t) { + return (t == BASE_TYPE_UTYPE) || (t == BASE_TYPE_UCHAR) || + (t == BASE_TYPE_USHORT) || (t == BASE_TYPE_UINT) || + (t == BASE_TYPE_ULONG); +} + +// clang-format on + +extern const char *const kTypeNames[]; +extern const char kTypeSizes[]; + +inline size_t SizeOf(BaseType t) +{ + return kTypeSizes[t]; +} + +struct StructDef; +struct EnumDef; +class Parser; + +// Represents any type in the IDL, which is a combination of the BaseType +// and additional information for vectors/structs_. +struct Type { + explicit Type(BaseType _base_type = BASE_TYPE_NONE, StructDef *_sd = nullptr, + EnumDef *_ed = nullptr, uint16_t _fixed_length = 0) + : base_type(_base_type), + element(BASE_TYPE_NONE), + struct_def(_sd), + enum_def(_ed), + fixed_length(_fixed_length) + { + } + + bool operator==(const Type &o) + { + return base_type == o.base_type && element == o.element && + struct_def == o.struct_def && enum_def == o.enum_def; + } + + Type VectorType() const + { + return Type(element, struct_def, enum_def, fixed_length); + } + + Offset Serialize(FlatBufferBuilder *builder) const; + + bool Deserialize(const Parser &parser, const reflection::Type *type); + + BaseType base_type; + BaseType element; // only set if t == BASE_TYPE_VECTOR + StructDef *struct_def; // only set if t or element == BASE_TYPE_STRUCT + EnumDef *enum_def; // set if t == BASE_TYPE_UNION / BASE_TYPE_UTYPE, + // or for an integral type derived from an enum. + uint16_t fixed_length; // only set if t == BASE_TYPE_ARRAY +}; + +// Represents a parsed scalar value, it's type, and field offset. +struct Value { + Value() + : constant("0"), + offset(static_cast(~(static_cast(0U)))) + { + } + Type type; + std::string constant; + voffset_t offset; +}; + +// Helper class that retains the original order of a set of identifiers and +// also provides quick lookup. +template +class SymbolTable { +public: + ~SymbolTable() + { + for (auto it = vec.begin(); it != vec.end(); ++it) { + delete *it; + } + } + + bool Add(const std::string &name, T *e) + { + vector_emplace_back(&vec, e); + auto it = dict.find(name); + if (it != dict.end()) + return true; + dict[name] = e; + return false; + } + + void Move(const std::string &oldname, const std::string &newname) + { + auto it = dict.find(oldname); + if (it != dict.end()) { + auto obj = it->second; + dict.erase(it); + dict[newname] = obj; + } else { + FLATBUFFERS_ASSERT(false); + } + } + + T *Lookup(const std::string &name) const + { + auto it = dict.find(name); + return it == dict.end() ? nullptr : it->second; + } + +public: + std::map dict; // quick lookup + std::vector vec; // Used to iterate in order of insertion +}; + +// A name space, as set in the schema. +struct Namespace { + Namespace() + : from_table(0) + { + } + + // Given a (potentially unqualified) name, return the "fully qualified" name + // which has a full namespaced descriptor. + // With max_components you can request less than the number of components + // the current namespace has. + std::string GetFullyQualifiedName(const std::string &name, + size_t max_components = 1000) const; + + std::vector components; + size_t from_table; // Part of the namespace corresponds to a message/table. +}; + +inline bool operator<(const Namespace &a, const Namespace &b) +{ + size_t min_size = std::min(a.components.size(), b.components.size()); + for (size_t i = 0; i < min_size; ++i) { + if (a.components[i] != b.components[i]) + return a.components[i] < b.components[i]; + } + return a.components.size() < b.components.size(); +} + +// Base class for all definition types (fields, structs_, enums_). +struct Definition { + Definition() + : generated(false), + defined_namespace(nullptr), + serialized_location(0), + index(-1), + refcount(1) + { + } + + flatbuffers::Offset< + flatbuffers::Vector > > + SerializeAttributes(FlatBufferBuilder *builder, const Parser &parser) const; + + bool DeserializeAttributes(Parser &parser, + const Vector > *attrs); + + std::string name; + std::string file; + std::vector doc_comment; + SymbolTable attributes; + bool generated; // did we already output code for this definition? + Namespace *defined_namespace; // Where it was defined. + + // For use with Serialize() + uoffset_t serialized_location; + int index; // Inside the vector it is stored. + int refcount; +}; + +struct FieldDef : public Definition { + FieldDef() + : deprecated(false), + required(false), + key(false), + shared(false), + native_inline(false), + flexbuffer(false), + optional(false), + nested_flatbuffer(NULL), + padding(0) + { + } + + Offset Serialize(FlatBufferBuilder *builder, uint16_t id, + const Parser &parser) const; + + bool Deserialize(Parser &parser, const reflection::Field *field); + + bool IsScalarOptional() const + { + return IsScalar(value.type.base_type) && optional; + } + + Value value; + bool deprecated; // Field is allowed to be present in old data, but can't be. + // written in new data nor accessed in new code. + bool required; // Field must always be present. + bool key; // Field functions as a key for creating sorted vectors. + bool shared; // Field will be using string pooling (i.e. CreateSharedString) + // as default serialization behavior if field is a string. + bool native_inline; // Field will be defined inline (instead of as a pointer) + // for native tables if field is a struct. + bool flexbuffer; // This field contains FlexBuffer data. + bool optional; // If True, this field is Null (as opposed to default + // valued). + StructDef *nested_flatbuffer; // This field contains nested FlatBuffer data. + size_t padding; // Bytes to always pad after this field. +}; + +struct StructDef : public Definition { + StructDef() + : fixed(false), + predecl(true), + sortbysize(true), + has_key(false), + minalign(1), + bytesize(0) + { + } + + void PadLastField(size_t min_align) + { + auto padding = PaddingBytes(bytesize, min_align); + bytesize += padding; + if (fields.vec.size()) + fields.vec.back()->padding = padding; + } + + Offset Serialize(FlatBufferBuilder *builder, + const Parser &parser) const; + + bool Deserialize(Parser &parser, const reflection::Object *object); + + SymbolTable fields; + + bool fixed; // If it's struct, not a table. + bool predecl; // If it's used before it was defined. + bool sortbysize; // Whether fields come in the declaration or size order. + bool has_key; // It has a key field. + size_t minalign; // What the whole object needs to be aligned to. + size_t bytesize; // Size if fixed. + + flatbuffers::unique_ptr original_location; +}; + +struct EnumDef; +struct EnumValBuilder; + +struct EnumVal { + Offset Serialize(FlatBufferBuilder *builder, + const Parser &parser) const; + + bool Deserialize(const Parser &parser, const reflection::EnumVal *val); + + uint64_t GetAsUInt64() const + { + return static_cast(value); + } + int64_t GetAsInt64() const + { + return value; + } + bool IsZero() const + { + return 0 == value; + } + bool IsNonZero() const + { + return !IsZero(); + } + + std::string name; + std::vector doc_comment; + Type union_type; + +private: + friend EnumDef; + friend EnumValBuilder; + friend bool operator==(const EnumVal &lhs, const EnumVal &rhs); + + EnumVal(const std::string &_name, int64_t _val) + : name(_name), value(_val) + { + } + EnumVal() + : value(0) + { + } + + int64_t value; +}; + +struct EnumDef : public Definition { + EnumDef() + : is_union(false), uses_multiple_type_instances(false) + { + } + + Offset Serialize(FlatBufferBuilder *builder, + const Parser &parser) const; + + bool Deserialize(Parser &parser, const reflection::Enum *values); + + template + void ChangeEnumValue(EnumVal *ev, T new_val); + void SortByValue(); + void RemoveDuplicates(); + + std::string AllFlags() const; + const EnumVal *MinValue() const; + const EnumVal *MaxValue() const; + // Returns the number of integer steps from v1 to v2. + uint64_t Distance(const EnumVal *v1, const EnumVal *v2) const; + // Returns the number of integer steps from Min to Max. + uint64_t Distance() const + { + return Distance(MinValue(), MaxValue()); + } + + EnumVal *ReverseLookup(int64_t enum_idx, + bool skip_union_default = false) const; + EnumVal *FindByValue(const std::string &constant) const; + + std::string ToString(const EnumVal &ev) const + { + return IsUInt64() ? NumToString(ev.GetAsUInt64()) : NumToString(ev.GetAsInt64()); + } + + size_t size() const + { + return vals.vec.size(); + } + + const std::vector &Vals() const + { + return vals.vec; + } + + const EnumVal *Lookup(const std::string &enum_name) const + { + return vals.Lookup(enum_name); + } + + bool is_union; + // Type is a union which uses type aliases where at least one type is + // available under two different names. + bool uses_multiple_type_instances; + Type underlying_type; + +private: + bool IsUInt64() const + { + return (BASE_TYPE_ULONG == underlying_type.base_type); + } + + friend EnumValBuilder; + SymbolTable vals; +}; + +inline bool IsStruct(const Type &type) +{ + return type.base_type == BASE_TYPE_STRUCT && type.struct_def->fixed; +} + +inline bool IsUnion(const Type &type) +{ + return type.enum_def != nullptr && type.enum_def->is_union; +} + +inline bool IsVector(const Type &type) +{ + return type.base_type == BASE_TYPE_VECTOR; +} + +inline bool IsArray(const Type &type) +{ + return type.base_type == BASE_TYPE_ARRAY; +} + +inline bool IsSeries(const Type &type) +{ + return IsVector(type) || IsArray(type); +} + +inline bool IsEnum(const Type &type) +{ + return type.enum_def != nullptr && IsInteger(type.base_type); +} + +inline size_t InlineSize(const Type &type) +{ + return IsStruct(type) ? type.struct_def->bytesize : (IsArray(type) ? InlineSize(type.VectorType()) * type.fixed_length : SizeOf(type.base_type)); +} + +inline size_t InlineAlignment(const Type &type) +{ + if (IsStruct(type)) { + return type.struct_def->minalign; + } else if (IsArray(type)) { + return IsStruct(type.VectorType()) ? type.struct_def->minalign : SizeOf(type.element); + } else { + return SizeOf(type.base_type); + } +} +inline bool operator==(const EnumVal &lhs, const EnumVal &rhs) +{ + return lhs.value == rhs.value; +} +inline bool operator!=(const EnumVal &lhs, const EnumVal &rhs) +{ + return !(lhs == rhs); +} + +inline bool EqualByName(const Type &a, const Type &b) +{ + return a.base_type == b.base_type && a.element == b.element && + (a.struct_def == b.struct_def || + a.struct_def->name == b.struct_def->name) && + (a.enum_def == b.enum_def || a.enum_def->name == b.enum_def->name); +} + +struct RPCCall : public Definition { + Offset Serialize(FlatBufferBuilder *builder, + const Parser &parser) const; + + bool Deserialize(Parser &parser, const reflection::RPCCall *call); + + StructDef *request, *response; +}; + +struct ServiceDef : public Definition { + Offset Serialize(FlatBufferBuilder *builder, + const Parser &parser) const; + bool Deserialize(Parser &parser, const reflection::Service *service); + + SymbolTable calls; +}; + +// Container of options that may apply to any of the source/text generators. +struct IDLOptions { + bool gen_jvmstatic; + // Use flexbuffers instead for binary and text generation + bool use_flexbuffers; + bool strict_json; + bool skip_js_exports; + bool use_goog_js_export_format; + bool use_ES6_js_export_format; + bool output_default_scalars_in_json; + int indent_step; + bool output_enum_identifiers; + bool prefixed_enums; + bool scoped_enums; + bool include_dependence_headers; + bool mutable_buffer; + bool one_file; + bool proto_mode; + bool proto_oneof_union; + bool generate_all; + bool skip_unexpected_fields_in_json; + bool generate_name_strings; + bool generate_object_based_api; + bool gen_compare; + std::string cpp_object_api_pointer_type; + std::string cpp_object_api_string_type; + bool cpp_object_api_string_flexible_constructor; + bool gen_nullable; + bool java_checkerframework; + bool gen_generated; + std::string object_prefix; + std::string object_suffix; + bool union_value_namespacing; + bool allow_non_utf8; + bool natural_utf8; + std::string include_prefix; + bool keep_include_path; + bool binary_schema_comments; + bool binary_schema_builtins; + bool binary_schema_gen_embed; + bool skip_flatbuffers_import; + std::string go_import; + std::string go_namespace; + bool reexport_ts_modules; + bool js_ts_short_names; + bool protobuf_ascii_alike; + bool size_prefixed; + std::string root_type; + bool force_defaults; + bool java_primitive_has_method; + bool cs_gen_json_serializer; + std::vector cpp_includes; + std::string cpp_std; + std::string proto_namespace_suffix; + std::string filename_suffix; + std::string filename_extension; + + // Possible options for the more general generator below. + enum Language { + kJava = 1 << 0, + kCSharp = 1 << 1, + kGo = 1 << 2, + kCpp = 1 << 3, + kJs = 1 << 4, + kPython = 1 << 5, + kPhp = 1 << 6, + kJson = 1 << 7, + kBinary = 1 << 8, + kTs = 1 << 9, + kJsonSchema = 1 << 10, + kDart = 1 << 11, + kLua = 1 << 12, + kLobster = 1 << 13, + kRust = 1 << 14, + kKotlin = 1 << 15, + kSwift = 1 << 16, + kMAX + }; + + Language lang; + + enum MiniReflect { kNone, + kTypes, + kTypesAndNames }; + + MiniReflect mini_reflect; + + // The corresponding language bit will be set if a language is included + // for code generation. + unsigned long lang_to_generate; + + // If set (default behavior), empty string fields will be set to nullptr to + // make the flatbuffer more compact. + bool set_empty_strings_to_null; + + // If set (default behavior), empty vector fields will be set to nullptr to + // make the flatbuffer more compact. + bool set_empty_vectors_to_null; + + IDLOptions() + : gen_jvmstatic(false), + use_flexbuffers(false), + strict_json(false), + skip_js_exports(false), + use_goog_js_export_format(false), + use_ES6_js_export_format(false), + output_default_scalars_in_json(false), + indent_step(2), + output_enum_identifiers(true), + prefixed_enums(true), + scoped_enums(false), + include_dependence_headers(true), + mutable_buffer(false), + one_file(false), + proto_mode(false), + proto_oneof_union(false), + generate_all(false), + skip_unexpected_fields_in_json(false), + generate_name_strings(false), + generate_object_based_api(false), + gen_compare(false), + cpp_object_api_pointer_type("std::unique_ptr"), + cpp_object_api_string_flexible_constructor(false), + gen_nullable(false), + java_checkerframework(false), + gen_generated(false), + object_suffix("T"), + union_value_namespacing(true), + allow_non_utf8(false), + natural_utf8(false), + keep_include_path(false), + binary_schema_comments(false), + binary_schema_builtins(false), + binary_schema_gen_embed(false), + skip_flatbuffers_import(false), + reexport_ts_modules(true), + js_ts_short_names(false), + protobuf_ascii_alike(false), + size_prefixed(false), + force_defaults(false), + java_primitive_has_method(false), + cs_gen_json_serializer(false), + filename_suffix("_generated"), + filename_extension(), + lang(IDLOptions::kJava), + mini_reflect(IDLOptions::kNone), + lang_to_generate(0), + set_empty_strings_to_null(true), + set_empty_vectors_to_null(true) + { + } +}; + +// This encapsulates where the parser is in the current source file. +struct ParserState { + ParserState() + : cursor_(nullptr), + line_start_(nullptr), + line_(0), + token_(-1), + attr_is_trivial_ascii_string_(true) + { + } + +protected: + void ResetState(const char *source) + { + cursor_ = source; + line_ = 0; + MarkNewLine(); + } + + void MarkNewLine() + { + line_start_ = cursor_; + line_ += 1; + } + + int64_t CursorPosition() const + { + FLATBUFFERS_ASSERT(cursor_ && line_start_ && cursor_ >= line_start_); + return static_cast(cursor_ - line_start_); + } + + const char *cursor_; + const char *line_start_; + int line_; // the current line being parsed + int token_; + + // Flag: text in attribute_ is true ASCII string without escape + // sequences. Only printable ASCII (without [\t\r\n]). + // Used for number-in-string (and base64 string in future). + bool attr_is_trivial_ascii_string_; + std::string attribute_; + std::vector doc_comment_; +}; + +// A way to make error propagation less error prone by requiring values to be +// checked. +// Once you create a value of this type you must either: +// - Call Check() on it. +// - Copy or assign it to another value. +// Failure to do so leads to an assert. +// This guarantees that this as return value cannot be ignored. +class CheckedError { +public: + explicit CheckedError(bool error) + : is_error_(error), has_been_checked_(false) + { + } + + CheckedError &operator=(const CheckedError &other) + { + is_error_ = other.is_error_; + has_been_checked_ = false; + other.has_been_checked_ = true; + return *this; + } + + CheckedError(const CheckedError &other) + { + *this = other; // Use assignment operator. + } + + ~CheckedError() + { + FLATBUFFERS_ASSERT(has_been_checked_); + } + + bool Check() + { + has_been_checked_ = true; + return is_error_; + } + +private: + bool is_error_; + mutable bool has_been_checked_; +}; + +// Additionally, in GCC we can get these errors statically, for additional +// assurance: +// clang-format off +#ifdef __GNUC__ +#define FLATBUFFERS_CHECKED_ERROR CheckedError \ + __attribute__((warn_unused_result)) +#else +#define FLATBUFFERS_CHECKED_ERROR CheckedError +#endif +// clang-format on + +class Parser : public ParserState { +public: + explicit Parser(const IDLOptions &options = IDLOptions()) + : current_namespace_(nullptr), + empty_namespace_(nullptr), + flex_builder_(256, flexbuffers::BUILDER_FLAG_SHARE_ALL), + root_struct_def_(nullptr), + opts(options), + uses_flexbuffers_(false), + source_(nullptr), + anonymous_counter(0), + recurse_protection_counter(0) + { + if (opts.force_defaults) { + builder_.ForceDefaults(true); + } + // Start out with the empty namespace being current. + empty_namespace_ = new Namespace(); + namespaces_.push_back(empty_namespace_); + current_namespace_ = empty_namespace_; + known_attributes_["deprecated"] = true; + known_attributes_["required"] = true; + known_attributes_["key"] = true; + known_attributes_["shared"] = true; + known_attributes_["hash"] = true; + known_attributes_["id"] = true; + known_attributes_["force_align"] = true; + known_attributes_["bit_flags"] = true; + known_attributes_["original_order"] = true; + known_attributes_["nested_flatbuffer"] = true; + known_attributes_["csharp_partial"] = true; + known_attributes_["streaming"] = true; + known_attributes_["idempotent"] = true; + known_attributes_["cpp_type"] = true; + known_attributes_["cpp_ptr_type"] = true; + known_attributes_["cpp_ptr_type_get"] = true; + known_attributes_["cpp_str_type"] = true; + known_attributes_["cpp_str_flex_ctor"] = true; + known_attributes_["native_inline"] = true; + known_attributes_["native_custom_alloc"] = true; + known_attributes_["native_type"] = true; + known_attributes_["native_default"] = true; + known_attributes_["flexbuffer"] = true; + known_attributes_["private"] = true; + } + + ~Parser() + { + for (auto it = namespaces_.begin(); it != namespaces_.end(); ++it) { + delete *it; + } + } + + // Parse the string containing either schema or JSON data, which will + // populate the SymbolTable's or the FlatBufferBuilder above. + // include_paths is used to resolve any include statements, and typically + // should at least include the project path (where you loaded source_ from). + // include_paths must be nullptr terminated if specified. + // If include_paths is nullptr, it will attempt to load from the current + // directory. + // If the source was loaded from a file and isn't an include file, + // supply its name in source_filename. + // All paths specified in this call must be in posix format, if you accept + // paths from user input, please call PosixPath on them first. + bool Parse(const char *_source, const char **include_paths = nullptr, + const char *source_filename = nullptr); + + // Set the root type. May override the one set in the schema. + bool SetRootType(const char *name); + + // Mark all definitions as already having code generated. + void MarkGenerated(); + + // Get the files recursively included by the given file. The returned + // container will have at least the given file. + std::set GetIncludedFilesRecursive( + const std::string &file_name) const; + + // Fills builder_ with a binary version of the schema parsed. + // See reflection/reflection.fbs + void Serialize(); + + // Deserialize a schema buffer + bool Deserialize(const uint8_t *buf, const size_t size); + + // Fills internal structure as if the schema passed had been loaded by parsing + // with Parse except that included filenames will not be populated. + bool Deserialize(const reflection::Schema *schema); + + Type *DeserializeType(const reflection::Type *type); + + // Checks that the schema represented by this parser is a safe evolution + // of the schema provided. Returns non-empty error on any problems. + std::string ConformTo(const Parser &base); + + // Similar to Parse(), but now only accepts JSON to be parsed into a + // FlexBuffer. + bool ParseFlexBuffer(const char *source, const char *source_filename, + flexbuffers::Builder *builder); + + StructDef *LookupStruct(const std::string &id) const; + + std::string UnqualifiedName(const std::string &fullQualifiedName); + + FLATBUFFERS_CHECKED_ERROR Error(const std::string &msg); + + // @brief Verify that any of 'opts.lang_to_generate' supports Optional scalars + // in a schema. + // @param opts Options used to parce a schema and generate code. + static bool SupportsOptionalScalars(const flatbuffers::IDLOptions &opts); + +private: + void Message(const std::string &msg); + void Warning(const std::string &msg); + FLATBUFFERS_CHECKED_ERROR ParseHexNum(int nibbles, uint64_t *val); + FLATBUFFERS_CHECKED_ERROR Next(); + FLATBUFFERS_CHECKED_ERROR SkipByteOrderMark(); + bool Is(int t) const; + bool IsIdent(const char *id) const; + FLATBUFFERS_CHECKED_ERROR Expect(int t); + std::string TokenToStringId(int t) const; + EnumDef *LookupEnum(const std::string &id); + FLATBUFFERS_CHECKED_ERROR ParseNamespacing(std::string *id, + std::string *last); + FLATBUFFERS_CHECKED_ERROR ParseTypeIdent(Type &type); + FLATBUFFERS_CHECKED_ERROR ParseType(Type &type); + FLATBUFFERS_CHECKED_ERROR AddField(StructDef &struct_def, + const std::string &name, const Type &type, + FieldDef **dest); + FLATBUFFERS_CHECKED_ERROR ParseField(StructDef &struct_def); + FLATBUFFERS_CHECKED_ERROR ParseString(Value &val, bool use_string_pooling); + FLATBUFFERS_CHECKED_ERROR ParseComma(); + FLATBUFFERS_CHECKED_ERROR ParseAnyValue(Value &val, FieldDef *field, + size_t parent_fieldn, + const StructDef *parent_struct_def, + uoffset_t count, + bool inside_vector = false); + template + FLATBUFFERS_CHECKED_ERROR ParseTableDelimiters(size_t &fieldn, + const StructDef *struct_def, + F body); + FLATBUFFERS_CHECKED_ERROR ParseTable(const StructDef &struct_def, + std::string *value, uoffset_t *ovalue); + void SerializeStruct(const StructDef &struct_def, const Value &val); + void SerializeStruct(FlatBufferBuilder &builder, const StructDef &struct_def, + const Value &val); + template + FLATBUFFERS_CHECKED_ERROR ParseVectorDelimiters(uoffset_t &count, F body); + FLATBUFFERS_CHECKED_ERROR ParseVector(const Type &type, uoffset_t *ovalue, + FieldDef *field, size_t fieldn); + FLATBUFFERS_CHECKED_ERROR ParseArray(Value &array); + FLATBUFFERS_CHECKED_ERROR ParseNestedFlatbuffer( + Value &val, FieldDef *field, size_t fieldn, + const StructDef *parent_struct_def); + FLATBUFFERS_CHECKED_ERROR ParseMetaData(SymbolTable *attributes); + FLATBUFFERS_CHECKED_ERROR TryTypedValue(const std::string *name, int dtoken, + bool check, Value &e, BaseType req, + bool *destmatch); + FLATBUFFERS_CHECKED_ERROR ParseHash(Value &e, FieldDef *field); + FLATBUFFERS_CHECKED_ERROR TokenError(); + FLATBUFFERS_CHECKED_ERROR ParseSingleValue(const std::string *name, Value &e, + bool check_now); + FLATBUFFERS_CHECKED_ERROR ParseFunction(const std::string *name, Value &e); + FLATBUFFERS_CHECKED_ERROR ParseEnumFromString(const Type &type, + std::string *result); + StructDef *LookupCreateStruct(const std::string &name, + bool create_if_new = true, + bool definition = false); + FLATBUFFERS_CHECKED_ERROR ParseEnum(bool is_union, EnumDef **dest); + FLATBUFFERS_CHECKED_ERROR ParseNamespace(); + FLATBUFFERS_CHECKED_ERROR StartStruct(const std::string &name, + StructDef **dest); + FLATBUFFERS_CHECKED_ERROR StartEnum(const std::string &name, bool is_union, + EnumDef **dest); + FLATBUFFERS_CHECKED_ERROR ParseDecl(); + FLATBUFFERS_CHECKED_ERROR ParseService(); + FLATBUFFERS_CHECKED_ERROR ParseProtoFields(StructDef *struct_def, + bool isextend, bool inside_oneof); + FLATBUFFERS_CHECKED_ERROR ParseProtoOption(); + FLATBUFFERS_CHECKED_ERROR ParseProtoKey(); + FLATBUFFERS_CHECKED_ERROR ParseProtoDecl(); + FLATBUFFERS_CHECKED_ERROR ParseProtoCurliesOrIdent(); + FLATBUFFERS_CHECKED_ERROR ParseTypeFromProtoType(Type *type); + FLATBUFFERS_CHECKED_ERROR SkipAnyJsonValue(); + FLATBUFFERS_CHECKED_ERROR ParseFlexBufferValue(flexbuffers::Builder *builder); + FLATBUFFERS_CHECKED_ERROR StartParseFile(const char *source, + const char *source_filename); + FLATBUFFERS_CHECKED_ERROR ParseRoot(const char *_source, + const char **include_paths, + const char *source_filename); + FLATBUFFERS_CHECKED_ERROR DoParse(const char *_source, + const char **include_paths, + const char *source_filename, + const char *include_filename); + FLATBUFFERS_CHECKED_ERROR CheckClash(std::vector &fields, + StructDef *struct_def, + const char *suffix, BaseType baseType); + + bool SupportsAdvancedUnionFeatures() const; + bool SupportsAdvancedArrayFeatures() const; + bool SupportsOptionalScalars() const; + Namespace *UniqueNamespace(Namespace *ns); + + FLATBUFFERS_CHECKED_ERROR RecurseError(); + template + CheckedError Recurse(F f); + +public: + SymbolTable types_; + SymbolTable structs_; + SymbolTable enums_; + SymbolTable services_; + std::vector namespaces_; + Namespace *current_namespace_; + Namespace *empty_namespace_; + std::string error_; // User readable error_ if Parse() == false + + FlatBufferBuilder builder_; // any data contained in the file + flexbuffers::Builder flex_builder_; + flexbuffers::Reference flex_root_; + StructDef *root_struct_def_; + std::string file_identifier_; + std::string file_extension_; + + std::map included_files_; + std::map > files_included_per_file_; + std::vector native_included_files_; + + std::map known_attributes_; + + IDLOptions opts; + bool uses_flexbuffers_; + +private: + const char *source_; + + std::string file_being_parsed_; + + std::vector > field_stack_; + + int anonymous_counter; + int recurse_protection_counter; +}; + +// Utility functions for multiple generators: + +extern std::string MakeCamel(const std::string &in, bool first = true); + +extern std::string MakeScreamingCamel(const std::string &in); + +// Generate text (JSON) from a given FlatBuffer, and a given Parser +// object that has been populated with the corresponding schema. +// If ident_step is 0, no indentation will be generated. Additionally, +// if it is less than 0, no linefeeds will be generated either. +// See idl_gen_text.cpp. +// strict_json adds "quotes" around field names if true. +// If the flatbuffer cannot be encoded in JSON (e.g., it contains non-UTF-8 +// byte arrays in String values), returns false. +extern bool GenerateTextFromTable(const Parser &parser, const void *table, + const std::string &tablename, + std::string *text); +extern bool GenerateText(const Parser &parser, const void *flatbuffer, + std::string *text); +extern bool GenerateTextFile(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate binary files from a given FlatBuffer, and a given Parser +// object that has been populated with the corresponding schema. +// See code_generators.cpp. +extern bool GenerateBinary(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate a C++ header from the definitions in the Parser object. +// See idl_gen_cpp. +extern bool GenerateCPP(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate C# files from the definitions in the Parser object. +// See idl_gen_csharp.cpp. +extern bool GenerateCSharp(const Parser &parser, const std::string &path, + const std::string &file_name); + +extern bool GenerateDart(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate Java files from the definitions in the Parser object. +// See idl_gen_java.cpp. +extern bool GenerateJava(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate JavaScript or TypeScript code from the definitions in the Parser +// object. See idl_gen_js. +extern bool GenerateJSTS(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate Go files from the definitions in the Parser object. +// See idl_gen_go.cpp. +extern bool GenerateGo(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate Php code from the definitions in the Parser object. +// See idl_gen_php. +extern bool GeneratePhp(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate Python files from the definitions in the Parser object. +// See idl_gen_python.cpp. +extern bool GeneratePython(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate Lobster files from the definitions in the Parser object. +// See idl_gen_lobster.cpp. +extern bool GenerateLobster(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate Lua files from the definitions in the Parser object. +// See idl_gen_lua.cpp. +extern bool GenerateLua(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate Rust files from the definitions in the Parser object. +// See idl_gen_rust.cpp. +extern bool GenerateRust(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate Json schema file +// See idl_gen_json_schema.cpp. +extern bool GenerateJsonSchema(const Parser &parser, const std::string &path, + const std::string &file_name); + +extern bool GenerateKotlin(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate Swift classes. +// See idl_gen_swift.cpp +extern bool GenerateSwift(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate a schema file from the internal representation, useful after +// parsing a .proto schema. +extern std::string GenerateFBS(const Parser &parser, + const std::string &file_name); +extern bool GenerateFBS(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate a make rule for the generated JavaScript or TypeScript code. +// See idl_gen_js.cpp. +extern std::string JSTSMakeRule(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate a make rule for the generated C++ header. +// See idl_gen_cpp.cpp. +extern std::string CPPMakeRule(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate a make rule for the generated Dart code +// see idl_gen_dart.cpp +extern std::string DartMakeRule(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate a make rule for the generated Rust code. +// See idl_gen_rust.cpp. +extern std::string RustMakeRule(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate a make rule for generated Java or C# files. +// See code_generators.cpp. +extern std::string JavaCSharpMakeRule(const Parser &parser, + const std::string &path, + const std::string &file_name); + +// Generate a make rule for the generated text (JSON) files. +// See idl_gen_text.cpp. +extern std::string TextMakeRule(const Parser &parser, const std::string &path, + const std::string &file_names); + +// Generate a make rule for the generated binary files. +// See code_generators.cpp. +extern std::string BinaryMakeRule(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate GRPC Cpp interfaces. +// See idl_gen_grpc.cpp. +bool GenerateCppGRPC(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate GRPC Go interfaces. +// See idl_gen_grpc.cpp. +bool GenerateGoGRPC(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate GRPC Java classes. +// See idl_gen_grpc.cpp +bool GenerateJavaGRPC(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate GRPC Python interfaces. +// See idl_gen_grpc.cpp. +bool GeneratePythonGRPC(const Parser &parser, const std::string &path, + const std::string &file_name); + +// Generate GRPC Swift interfaces. +// See idl_gen_grpc.cpp. +extern bool GenerateSwiftGRPC(const Parser &parser, const std::string &path, + const std::string &file_name); + +} // namespace flatbuffers + +#endif // FLATBUFFERS_IDL_H_ diff --git a/components/tflite/third_party/flatbuffers/include/flatbuffers/minireflect.h b/components/tflite/third_party/flatbuffers/include/flatbuffers/minireflect.h new file mode 100644 index 00000000..3bd75a21 --- /dev/null +++ b/components/tflite/third_party/flatbuffers/include/flatbuffers/minireflect.h @@ -0,0 +1,547 @@ +/* + * Copyright 2017 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FLATBUFFERS_MINIREFLECT_H_ +#define FLATBUFFERS_MINIREFLECT_H_ + +#include "flatbuffers/flatbuffers.h" +#include "flatbuffers/util.h" + +namespace flatbuffers { +// Utilities that can be used with the "mini reflection" tables present +// in generated code with --reflect-types (only types) or --reflect-names +// (also names). +// This allows basic reflection functionality such as pretty-printing +// that does not require the use of the schema parser or loading of binary +// schema files at runtime (reflection.h). + +// For any of the functions below that take `const TypeTable *`, you pass +// `FooTypeTable()` if the type of the root is `Foo`. + +// First, a generic iterator that can be used by multiple algorithms. + +struct IterationVisitor { + // These mark the scope of a table or struct. + virtual void StartSequence() + { + } + virtual void EndSequence() + { + } + // Called for each field regardless of whether it is present or not. + // If not present, val == nullptr. set_idx is the index of all set fields. + virtual void Field(size_t /*field_idx*/, size_t /*set_idx*/, + ElementaryType /*type*/, bool /*is_vector*/, + const TypeTable * /*type_table*/, const char * /*name*/, + const uint8_t * /*val*/) + { + } + // Called for a value that is actually present, after a field, or as part + // of a vector. + virtual void UType(uint8_t, const char *) + { + } + virtual void Bool(bool) + { + } + virtual void Char(int8_t, const char *) + { + } + virtual void UChar(uint8_t, const char *) + { + } + virtual void Short(int16_t, const char *) + { + } + virtual void UShort(uint16_t, const char *) + { + } + virtual void Int(int32_t, const char *) + { + } + virtual void UInt(uint32_t, const char *) + { + } + virtual void Long(int64_t) + { + } + virtual void ULong(uint64_t) + { + } + virtual void Float(float) + { + } + virtual void Double(double) + { + } + virtual void String(const String *) + { + } + virtual void Unknown(const uint8_t *) + { + } // From a future version. + // These mark the scope of a vector. + virtual void StartVector() + { + } + virtual void EndVector() + { + } + virtual void Element(size_t /*i*/, ElementaryType /*type*/, + const TypeTable * /*type_table*/, + const uint8_t * /*val*/) + { + } + virtual ~IterationVisitor() + { + } +}; + +inline size_t InlineSize(ElementaryType type, const TypeTable *type_table) +{ + switch (type) { + case ET_UTYPE: + case ET_BOOL: + case ET_CHAR: + case ET_UCHAR: + return 1; + case ET_SHORT: + case ET_USHORT: + return 2; + case ET_INT: + case ET_UINT: + case ET_FLOAT: + case ET_STRING: + return 4; + case ET_LONG: + case ET_ULONG: + case ET_DOUBLE: + return 8; + case ET_SEQUENCE: + switch (type_table->st) { + case ST_TABLE: + case ST_UNION: + return 4; + case ST_STRUCT: + return static_cast(type_table->values[type_table->num_elems]); + default: + FLATBUFFERS_ASSERT(false); + return 1; + } + default: + FLATBUFFERS_ASSERT(false); + return 1; + } +} + +inline int64_t LookupEnum(int64_t enum_val, const int64_t *values, + size_t num_values) +{ + if (!values) + return enum_val; + for (size_t i = 0; i < num_values; i++) { + if (enum_val == values[i]) + return static_cast(i); + } + return -1; // Unknown enum value. +} + +template +const char *EnumName(T tval, const TypeTable *type_table) +{ + if (!type_table || !type_table->names) + return nullptr; + auto i = LookupEnum(static_cast(tval), type_table->values, + type_table->num_elems); + if (i >= 0 && i < static_cast(type_table->num_elems)) { + return type_table->names[i]; + } + return nullptr; +} + +void IterateObject(const uint8_t *obj, const TypeTable *type_table, + IterationVisitor *visitor); + +inline void IterateValue(ElementaryType type, const uint8_t *val, + const TypeTable *type_table, const uint8_t *prev_val, + soffset_t vector_index, IterationVisitor *visitor) +{ + switch (type) { + case ET_UTYPE: { + auto tval = ReadScalar(val); + visitor->UType(tval, EnumName(tval, type_table)); + break; + } + case ET_BOOL: { + visitor->Bool(ReadScalar(val) != 0); + break; + } + case ET_CHAR: { + auto tval = ReadScalar(val); + visitor->Char(tval, EnumName(tval, type_table)); + break; + } + case ET_UCHAR: { + auto tval = ReadScalar(val); + visitor->UChar(tval, EnumName(tval, type_table)); + break; + } + case ET_SHORT: { + auto tval = ReadScalar(val); + visitor->Short(tval, EnumName(tval, type_table)); + break; + } + case ET_USHORT: { + auto tval = ReadScalar(val); + visitor->UShort(tval, EnumName(tval, type_table)); + break; + } + case ET_INT: { + auto tval = ReadScalar(val); + visitor->Int(tval, EnumName(tval, type_table)); + break; + } + case ET_UINT: { + auto tval = ReadScalar(val); + visitor->UInt(tval, EnumName(tval, type_table)); + break; + } + case ET_LONG: { + visitor->Long(ReadScalar(val)); + break; + } + case ET_ULONG: { + visitor->ULong(ReadScalar(val)); + break; + } + case ET_FLOAT: { + visitor->Float(ReadScalar(val)); + break; + } + case ET_DOUBLE: { + visitor->Double(ReadScalar(val)); + break; + } + case ET_STRING: { + val += ReadScalar(val); + visitor->String(reinterpret_cast(val)); + break; + } + case ET_SEQUENCE: { + switch (type_table->st) { + case ST_TABLE: + val += ReadScalar(val); + IterateObject(val, type_table, visitor); + break; + case ST_STRUCT: + IterateObject(val, type_table, visitor); + break; + case ST_UNION: { + val += ReadScalar(val); + FLATBUFFERS_ASSERT(prev_val); + auto union_type = *prev_val; // Always a uint8_t. + if (vector_index >= 0) { + auto type_vec = reinterpret_cast *>(prev_val); + union_type = type_vec->Get(static_cast(vector_index)); + } + auto type_code_idx = + LookupEnum(union_type, type_table->values, type_table->num_elems); + if (type_code_idx >= 0 && + type_code_idx < static_cast(type_table->num_elems)) { + auto type_code = type_table->type_codes[type_code_idx]; + switch (type_code.base_type) { + case ET_SEQUENCE: { + auto ref = type_table->type_refs[type_code.sequence_ref](); + IterateObject(val, ref, visitor); + break; + } + case ET_STRING: + visitor->String(reinterpret_cast(val)); + break; + default: + visitor->Unknown(val); + } + } else { + visitor->Unknown(val); + } + break; + } + case ST_ENUM: + FLATBUFFERS_ASSERT(false); + break; + } + break; + } + default: { + visitor->Unknown(val); + break; + } + } +} + +inline void IterateObject(const uint8_t *obj, const TypeTable *type_table, + IterationVisitor *visitor) +{ + visitor->StartSequence(); + const uint8_t *prev_val = nullptr; + size_t set_idx = 0; + size_t array_idx = 0; + for (size_t i = 0; i < type_table->num_elems; i++) { + auto type_code = type_table->type_codes[i]; + auto type = static_cast(type_code.base_type); + auto is_repeating = type_code.is_repeating != 0; + auto ref_idx = type_code.sequence_ref; + const TypeTable *ref = nullptr; + if (ref_idx >= 0) { + ref = type_table->type_refs[ref_idx](); + } + auto name = type_table->names ? type_table->names[i] : nullptr; + const uint8_t *val = nullptr; + if (type_table->st == ST_TABLE) { + val = reinterpret_cast(obj)->GetAddressOf( + FieldIndexToOffset(static_cast(i))); + } else { + val = obj + type_table->values[i]; + } + visitor->Field(i, set_idx, type, is_repeating, ref, name, val); + if (val) { + set_idx++; + if (is_repeating) { + auto elem_ptr = val; + size_t size = 0; + if (type_table->st == ST_TABLE) { + // variable length vector + val += ReadScalar(val); + auto vec = reinterpret_cast *>(val); + elem_ptr = vec->Data(); + size = vec->size(); + } else { + // otherwise fixed size array + size = type_table->array_sizes[array_idx]; + ++array_idx; + } + visitor->StartVector(); + for (size_t j = 0; j < size; j++) { + visitor->Element(j, type, ref, elem_ptr); + IterateValue(type, elem_ptr, ref, prev_val, static_cast(j), + visitor); + elem_ptr += InlineSize(type, ref); + } + visitor->EndVector(); + } else { + IterateValue(type, val, ref, prev_val, -1, visitor); + } + } + prev_val = val; + } + visitor->EndSequence(); +} + +inline void IterateFlatBuffer(const uint8_t *buffer, + const TypeTable *type_table, + IterationVisitor *callback) +{ + IterateObject(GetRoot(buffer), type_table, callback); +} + +// Outputting a Flatbuffer to a string. Tries to conform as close to JSON / +// the output generated by idl_gen_text.cpp. + +struct ToStringVisitor : public IterationVisitor { + std::string s; + std::string d; + bool q; + std::string in; + size_t indent_level; + bool vector_delimited; + ToStringVisitor(std::string delimiter, bool quotes, std::string indent, + bool vdelimited = true) + : d(delimiter), + q(quotes), + in(indent), + indent_level(0), + vector_delimited(vdelimited) + { + } + ToStringVisitor(std::string delimiter) + : d(delimiter), + q(false), + in(""), + indent_level(0), + vector_delimited(true) + { + } + + void append_indent() + { + for (size_t i = 0; i < indent_level; i++) { + s += in; + } + } + + void StartSequence() + { + s += "{"; + s += d; + indent_level++; + } + void EndSequence() + { + s += d; + indent_level--; + append_indent(); + s += "}"; + } + void Field(size_t /*field_idx*/, size_t set_idx, ElementaryType /*type*/, + bool /*is_vector*/, const TypeTable * /*type_table*/, + const char *name, const uint8_t *val) + { + if (!val) + return; + if (set_idx) { + s += ","; + s += d; + } + append_indent(); + if (name) { + if (q) + s += "\""; + s += name; + if (q) + s += "\""; + s += ": "; + } + } + template + void Named(T x, const char *name) + { + if (name) { + if (q) + s += "\""; + s += name; + if (q) + s += "\""; + } else { + s += NumToString(x); + } + } + void UType(uint8_t x, const char *name) + { + Named(x, name); + } + void Bool(bool x) + { + s += x ? "true" : "false"; + } + void Char(int8_t x, const char *name) + { + Named(x, name); + } + void UChar(uint8_t x, const char *name) + { + Named(x, name); + } + void Short(int16_t x, const char *name) + { + Named(x, name); + } + void UShort(uint16_t x, const char *name) + { + Named(x, name); + } + void Int(int32_t x, const char *name) + { + Named(x, name); + } + void UInt(uint32_t x, const char *name) + { + Named(x, name); + } + void Long(int64_t x) + { + s += NumToString(x); + } + void ULong(uint64_t x) + { + s += NumToString(x); + } + void Float(float x) + { + s += NumToString(x); + } + void Double(double x) + { + s += NumToString(x); + } + void String(const struct String *str) + { + EscapeString(str->c_str(), str->size(), &s, true, false); + } + void Unknown(const uint8_t *) + { + s += "(?)"; + } + void StartVector() + { + s += "["; + if (vector_delimited) { + s += d; + indent_level++; + append_indent(); + } else { + s += " "; + } + } + void EndVector() + { + if (vector_delimited) { + s += d; + indent_level--; + append_indent(); + } else { + s += " "; + } + s += "]"; + } + void Element(size_t i, ElementaryType /*type*/, + const TypeTable * /*type_table*/, const uint8_t * /*val*/) + { + if (i) { + s += ","; + if (vector_delimited) { + s += d; + append_indent(); + } else { + s += " "; + } + } + } +}; + +inline std::string FlatBufferToString(const uint8_t *buffer, + const TypeTable *type_table, + bool multi_line = false, + bool vector_delimited = true) +{ + ToStringVisitor tostring_visitor(multi_line ? "\n" : " ", false, "", + vector_delimited); + IterateFlatBuffer(buffer, type_table, &tostring_visitor); + return tostring_visitor.s; +} + +} // namespace flatbuffers + +#endif // FLATBUFFERS_MINIREFLECT_H_ diff --git a/components/tflite/third_party/flatbuffers/include/flatbuffers/pch/flatc_pch.h b/components/tflite/third_party/flatbuffers/include/flatbuffers/pch/flatc_pch.h new file mode 100644 index 00000000..77132790 --- /dev/null +++ b/components/tflite/third_party/flatbuffers/include/flatbuffers/pch/flatc_pch.h @@ -0,0 +1,39 @@ +/* + * Copyright 2017 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FLATBUFFERS_FLATC_PCH_H_ +#define FLATBUFFERS_FLATC_PCH_H_ + +// stl +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// flatbuffers +#include "flatbuffers/pch/pch.h" +#include "flatbuffers/code_generators.h" +#include "flatbuffers/flatbuffers.h" +#include "flatbuffers/flexbuffers.h" +#include "flatbuffers/idl.h" + +#endif // FLATBUFFERS_FLATC_PCH_H_ diff --git a/components/tflite/third_party/flatbuffers/include/flatbuffers/pch/pch.h b/components/tflite/third_party/flatbuffers/include/flatbuffers/pch/pch.h new file mode 100644 index 00000000..804e99ed --- /dev/null +++ b/components/tflite/third_party/flatbuffers/include/flatbuffers/pch/pch.h @@ -0,0 +1,38 @@ +/* + * Copyright 2017 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FLATBUFFERS_PCH_H_ +#define FLATBUFFERS_PCH_H_ + +// stl +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// flatbuffers +#include "flatbuffers/util.h" + +#endif // FLATBUFFERS_PCH_H_ diff --git a/components/tflite/third_party/flatbuffers/include/flatbuffers/reflection.h b/components/tflite/third_party/flatbuffers/include/flatbuffers/reflection.h new file mode 100644 index 00000000..9c85956e --- /dev/null +++ b/components/tflite/third_party/flatbuffers/include/flatbuffers/reflection.h @@ -0,0 +1,559 @@ +/* + * Copyright 2015 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FLATBUFFERS_REFLECTION_H_ +#define FLATBUFFERS_REFLECTION_H_ + +// This is somewhat of a circular dependency because flatc (and thus this +// file) is needed to generate this header in the first place. +// Should normally not be a problem since it can be generated by the +// previous version of flatc whenever this code needs to change. +// See reflection/generate_code.sh +#include "flatbuffers/reflection_generated.h" + +// Helper functionality for reflection. + +namespace flatbuffers { +// ------------------------- GETTERS ------------------------- + +inline bool IsScalar(reflection::BaseType t) +{ + return t >= reflection::UType && t <= reflection::Double; +} +inline bool IsInteger(reflection::BaseType t) +{ + return t >= reflection::UType && t <= reflection::ULong; +} +inline bool IsFloat(reflection::BaseType t) +{ + return t == reflection::Float || t == reflection::Double; +} +inline bool IsLong(reflection::BaseType t) +{ + return t == reflection::Long || t == reflection::ULong; +} + +// Size of a basic type, don't use with structs. +inline size_t GetTypeSize(reflection::BaseType base_type) +{ + // This needs to correspond to the BaseType enum. + static size_t sizes[] = { + 0, // None + 1, // UType + 1, // Bool + 1, // Byte + 1, // UByte + 2, // Short + 2, // UShort + 4, // Int + 4, // UInt + 8, // Long + 8, // ULong + 4, // Float + 8, // Double + 4, // String + 4, // Vector + 4, // Obj + 4, // Union + 0, // Array. Only used in structs. 0 was chosen to prevent out-of-bounds errors. + + 0 // MaxBaseType. This must be kept the last entry in this array. + }; + static_assert(sizeof(sizes) / sizeof(size_t) == reflection::MaxBaseType + 1, + "Size of sizes[] array does not match the count of BaseType enum values."); + return sizes[base_type]; +} + +// Same as above, but now correctly returns the size of a struct if +// the field (or vector element) is a struct. +inline size_t GetTypeSizeInline(reflection::BaseType base_type, int type_index, + const reflection::Schema &schema) +{ + if (base_type == reflection::Obj && + schema.objects()->Get(type_index)->is_struct()) { + return schema.objects()->Get(type_index)->bytesize(); + } else { + return GetTypeSize(base_type); + } +} + +// Get the root, regardless of what type it is. +inline Table *GetAnyRoot(uint8_t *flatbuf) +{ + return GetMutableRoot
(flatbuf); +} +inline const Table *GetAnyRoot(const uint8_t *flatbuf) +{ + return GetRoot
(flatbuf); +} + +// Get a field's default, if you know it's an integer, and its exact type. +template +T GetFieldDefaultI(const reflection::Field &field) +{ + FLATBUFFERS_ASSERT(sizeof(T) == GetTypeSize(field.type()->base_type())); + return static_cast(field.default_integer()); +} + +// Get a field's default, if you know it's floating point and its exact type. +template +T GetFieldDefaultF(const reflection::Field &field) +{ + FLATBUFFERS_ASSERT(sizeof(T) == GetTypeSize(field.type()->base_type())); + return static_cast(field.default_real()); +} + +// Get a field, if you know it's an integer, and its exact type. +template +T GetFieldI(const Table &table, const reflection::Field &field) +{ + FLATBUFFERS_ASSERT(sizeof(T) == GetTypeSize(field.type()->base_type())); + return table.GetField(field.offset(), + static_cast(field.default_integer())); +} + +// Get a field, if you know it's floating point and its exact type. +template +T GetFieldF(const Table &table, const reflection::Field &field) +{ + FLATBUFFERS_ASSERT(sizeof(T) == GetTypeSize(field.type()->base_type())); + return table.GetField(field.offset(), + static_cast(field.default_real())); +} + +// Get a field, if you know it's a string. +inline const String *GetFieldS(const Table &table, + const reflection::Field &field) +{ + FLATBUFFERS_ASSERT(field.type()->base_type() == reflection::String); + return table.GetPointer(field.offset()); +} + +// Get a field, if you know it's a vector. +template +Vector *GetFieldV(const Table &table, const reflection::Field &field) +{ + FLATBUFFERS_ASSERT(field.type()->base_type() == reflection::Vector && + sizeof(T) == GetTypeSize(field.type()->element())); + return table.GetPointer *>(field.offset()); +} + +// Get a field, if you know it's a vector, generically. +// To actually access elements, use the return value together with +// field.type()->element() in any of GetAnyVectorElemI below etc. +inline VectorOfAny *GetFieldAnyV(const Table &table, + const reflection::Field &field) +{ + return table.GetPointer(field.offset()); +} + +// Get a field, if you know it's a table. +inline Table *GetFieldT(const Table &table, const reflection::Field &field) +{ + FLATBUFFERS_ASSERT(field.type()->base_type() == reflection::Obj || + field.type()->base_type() == reflection::Union); + return table.GetPointer
(field.offset()); +} + +// Get a field, if you know it's a struct. +inline const Struct *GetFieldStruct(const Table &table, + const reflection::Field &field) +{ + // TODO: This does NOT check if the field is a table or struct, but we'd need + // access to the schema to check the is_struct flag. + FLATBUFFERS_ASSERT(field.type()->base_type() == reflection::Obj); + return table.GetStruct(field.offset()); +} + +// Get a structure's field, if you know it's a struct. +inline const Struct *GetFieldStruct(const Struct &structure, + const reflection::Field &field) +{ + FLATBUFFERS_ASSERT(field.type()->base_type() == reflection::Obj); + return structure.GetStruct(field.offset()); +} + +// Raw helper functions used below: get any value in memory as a 64bit int, a +// double or a string. +// All scalars get static_cast to an int64_t, strings use strtoull, every other +// data type returns 0. +int64_t GetAnyValueI(reflection::BaseType type, const uint8_t *data); +// All scalars static cast to double, strings use strtod, every other data +// type is 0.0. +double GetAnyValueF(reflection::BaseType type, const uint8_t *data); +// All scalars converted using stringstream, strings as-is, and all other +// data types provide some level of debug-pretty-printing. +std::string GetAnyValueS(reflection::BaseType type, const uint8_t *data, + const reflection::Schema *schema, int type_index); + +// Get any table field as a 64bit int, regardless of what type it is. +inline int64_t GetAnyFieldI(const Table &table, + const reflection::Field &field) +{ + auto field_ptr = table.GetAddressOf(field.offset()); + return field_ptr ? GetAnyValueI(field.type()->base_type(), field_ptr) : field.default_integer(); +} + +// Get any table field as a double, regardless of what type it is. +inline double GetAnyFieldF(const Table &table, const reflection::Field &field) +{ + auto field_ptr = table.GetAddressOf(field.offset()); + return field_ptr ? GetAnyValueF(field.type()->base_type(), field_ptr) : field.default_real(); +} + +// Get any table field as a string, regardless of what type it is. +// You may pass nullptr for the schema if you don't care to have fields that +// are of table type pretty-printed. +inline std::string GetAnyFieldS(const Table &table, + const reflection::Field &field, + const reflection::Schema *schema) +{ + auto field_ptr = table.GetAddressOf(field.offset()); + return field_ptr ? GetAnyValueS(field.type()->base_type(), field_ptr, schema, + field.type()->index()) : + ""; +} + +// Get any struct field as a 64bit int, regardless of what type it is. +inline int64_t GetAnyFieldI(const Struct &st, const reflection::Field &field) +{ + return GetAnyValueI(field.type()->base_type(), + st.GetAddressOf(field.offset())); +} + +// Get any struct field as a double, regardless of what type it is. +inline double GetAnyFieldF(const Struct &st, const reflection::Field &field) +{ + return GetAnyValueF(field.type()->base_type(), + st.GetAddressOf(field.offset())); +} + +// Get any struct field as a string, regardless of what type it is. +inline std::string GetAnyFieldS(const Struct &st, + const reflection::Field &field) +{ + return GetAnyValueS(field.type()->base_type(), + st.GetAddressOf(field.offset()), nullptr, -1); +} + +// Get any vector element as a 64bit int, regardless of what type it is. +inline int64_t GetAnyVectorElemI(const VectorOfAny *vec, + reflection::BaseType elem_type, size_t i) +{ + return GetAnyValueI(elem_type, vec->Data() + GetTypeSize(elem_type) * i); +} + +// Get any vector element as a double, regardless of what type it is. +inline double GetAnyVectorElemF(const VectorOfAny *vec, + reflection::BaseType elem_type, size_t i) +{ + return GetAnyValueF(elem_type, vec->Data() + GetTypeSize(elem_type) * i); +} + +// Get any vector element as a string, regardless of what type it is. +inline std::string GetAnyVectorElemS(const VectorOfAny *vec, + reflection::BaseType elem_type, size_t i) +{ + return GetAnyValueS(elem_type, vec->Data() + GetTypeSize(elem_type) * i, + nullptr, -1); +} + +// Get a vector element that's a table/string/vector from a generic vector. +// Pass Table/String/VectorOfAny as template parameter. +// Warning: does no typechecking. +template +T *GetAnyVectorElemPointer(const VectorOfAny *vec, size_t i) +{ + auto elem_ptr = vec->Data() + sizeof(uoffset_t) * i; + return reinterpret_cast(elem_ptr + ReadScalar(elem_ptr)); +} + +// Get the inline-address of a vector element. Useful for Structs (pass Struct +// as template arg), or being able to address a range of scalars in-line. +// Get elem_size from GetTypeSizeInline(). +// Note: little-endian data on all platforms, use EndianScalar() instead of +// raw pointer access with scalars). +template +T *GetAnyVectorElemAddressOf(const VectorOfAny *vec, size_t i, + size_t elem_size) +{ + return reinterpret_cast(vec->Data() + elem_size * i); +} + +// Similarly, for elements of tables. +template +T *GetAnyFieldAddressOf(const Table &table, const reflection::Field &field) +{ + return reinterpret_cast(table.GetAddressOf(field.offset())); +} + +// Similarly, for elements of structs. +template +T *GetAnyFieldAddressOf(const Struct &st, const reflection::Field &field) +{ + return reinterpret_cast(st.GetAddressOf(field.offset())); +} + +// ------------------------- SETTERS ------------------------- + +// Set any scalar field, if you know its exact type. +template +bool SetField(Table *table, const reflection::Field &field, T val) +{ + reflection::BaseType type = field.type()->base_type(); + if (!IsScalar(type)) { + return false; + } + FLATBUFFERS_ASSERT(sizeof(T) == GetTypeSize(type)); + T def; + if (IsInteger(type)) { + def = GetFieldDefaultI(field); + } else { + FLATBUFFERS_ASSERT(IsFloat(type)); + def = GetFieldDefaultF(field); + } + return table->SetField(field.offset(), val, def); +} + +// Raw helper functions used below: set any value in memory as a 64bit int, a +// double or a string. +// These work for all scalar values, but do nothing for other data types. +// To set a string, see SetString below. +void SetAnyValueI(reflection::BaseType type, uint8_t *data, int64_t val); +void SetAnyValueF(reflection::BaseType type, uint8_t *data, double val); +void SetAnyValueS(reflection::BaseType type, uint8_t *data, const char *val); + +// Set any table field as a 64bit int, regardless of type what it is. +inline bool SetAnyFieldI(Table *table, const reflection::Field &field, + int64_t val) +{ + auto field_ptr = table->GetAddressOf(field.offset()); + if (!field_ptr) + return val == GetFieldDefaultI(field); + SetAnyValueI(field.type()->base_type(), field_ptr, val); + return true; +} + +// Set any table field as a double, regardless of what type it is. +inline bool SetAnyFieldF(Table *table, const reflection::Field &field, + double val) +{ + auto field_ptr = table->GetAddressOf(field.offset()); + if (!field_ptr) + return val == GetFieldDefaultF(field); + SetAnyValueF(field.type()->base_type(), field_ptr, val); + return true; +} + +// Set any table field as a string, regardless of what type it is. +inline bool SetAnyFieldS(Table *table, const reflection::Field &field, + const char *val) +{ + auto field_ptr = table->GetAddressOf(field.offset()); + if (!field_ptr) + return false; + SetAnyValueS(field.type()->base_type(), field_ptr, val); + return true; +} + +// Set any struct field as a 64bit int, regardless of type what it is. +inline void SetAnyFieldI(Struct *st, const reflection::Field &field, + int64_t val) +{ + SetAnyValueI(field.type()->base_type(), st->GetAddressOf(field.offset()), + val); +} + +// Set any struct field as a double, regardless of type what it is. +inline void SetAnyFieldF(Struct *st, const reflection::Field &field, + double val) +{ + SetAnyValueF(field.type()->base_type(), st->GetAddressOf(field.offset()), + val); +} + +// Set any struct field as a string, regardless of type what it is. +inline void SetAnyFieldS(Struct *st, const reflection::Field &field, + const char *val) +{ + SetAnyValueS(field.type()->base_type(), st->GetAddressOf(field.offset()), + val); +} + +// Set any vector element as a 64bit int, regardless of type what it is. +inline void SetAnyVectorElemI(VectorOfAny *vec, reflection::BaseType elem_type, + size_t i, int64_t val) +{ + SetAnyValueI(elem_type, vec->Data() + GetTypeSize(elem_type) * i, val); +} + +// Set any vector element as a double, regardless of type what it is. +inline void SetAnyVectorElemF(VectorOfAny *vec, reflection::BaseType elem_type, + size_t i, double val) +{ + SetAnyValueF(elem_type, vec->Data() + GetTypeSize(elem_type) * i, val); +} + +// Set any vector element as a string, regardless of type what it is. +inline void SetAnyVectorElemS(VectorOfAny *vec, reflection::BaseType elem_type, + size_t i, const char *val) +{ + SetAnyValueS(elem_type, vec->Data() + GetTypeSize(elem_type) * i, val); +} + +// ------------------------- RESIZING SETTERS ------------------------- + +// "smart" pointer for use with resizing vectors: turns a pointer inside +// a vector into a relative offset, such that it is not affected by resizes. +template +class pointer_inside_vector { +public: + pointer_inside_vector(T *ptr, std::vector &vec) + : offset_(reinterpret_cast(ptr) - + reinterpret_cast(flatbuffers::vector_data(vec))), + vec_(vec) + { + } + + T *operator*() const + { + return reinterpret_cast( + reinterpret_cast(flatbuffers::vector_data(vec_)) + offset_); + } + T *operator->() const + { + return operator*(); + } + +private: + size_t offset_; + std::vector &vec_; +}; + +// Helper to create the above easily without specifying template args. +template +pointer_inside_vector piv(T *ptr, std::vector &vec) +{ + return pointer_inside_vector(ptr, vec); +} + +inline const char *UnionTypeFieldSuffix() +{ + return "_type"; +} + +// Helper to figure out the actual table type a union refers to. +inline const reflection::Object &GetUnionType( + const reflection::Schema &schema, const reflection::Object &parent, + const reflection::Field &unionfield, const Table &table) +{ + auto enumdef = schema.enums()->Get(unionfield.type()->index()); + // TODO: this is clumsy and slow, but no other way to find it? + auto type_field = parent.fields()->LookupByKey( + (unionfield.name()->str() + UnionTypeFieldSuffix()).c_str()); + FLATBUFFERS_ASSERT(type_field); + auto union_type = GetFieldI(table, *type_field); + auto enumval = enumdef->values()->LookupByKey(union_type); + return *enumval->object(); +} + +// Changes the contents of a string inside a FlatBuffer. FlatBuffer must +// live inside a std::vector so we can resize the buffer if needed. +// "str" must live inside "flatbuf" and may be invalidated after this call. +// If your FlatBuffer's root table is not the schema's root table, you should +// pass in your root_table type as well. +void SetString(const reflection::Schema &schema, const std::string &val, + const String *str, std::vector *flatbuf, + const reflection::Object *root_table = nullptr); + +// Resizes a flatbuffers::Vector inside a FlatBuffer. FlatBuffer must +// live inside a std::vector so we can resize the buffer if needed. +// "vec" must live inside "flatbuf" and may be invalidated after this call. +// If your FlatBuffer's root table is not the schema's root table, you should +// pass in your root_table type as well. +uint8_t *ResizeAnyVector(const reflection::Schema &schema, uoffset_t newsize, + const VectorOfAny *vec, uoffset_t num_elems, + uoffset_t elem_size, std::vector *flatbuf, + const reflection::Object *root_table = nullptr); + +template +void ResizeVector(const reflection::Schema &schema, uoffset_t newsize, T val, + const Vector *vec, std::vector *flatbuf, + const reflection::Object *root_table = nullptr) +{ + auto delta_elem = static_cast(newsize) - static_cast(vec->size()); + auto newelems = ResizeAnyVector( + schema, newsize, reinterpret_cast(vec), vec->size(), + static_cast(sizeof(T)), flatbuf, root_table); + // Set new elements to "val". + for (int i = 0; i < delta_elem; i++) { + auto loc = newelems + i * sizeof(T); + auto is_scalar = flatbuffers::is_scalar::value; + if (is_scalar) { + WriteScalar(loc, val); + } else { // struct + *reinterpret_cast(loc) = val; + } + } +} + +// Adds any new data (in the form of a new FlatBuffer) to an existing +// FlatBuffer. This can be used when any of the above methods are not +// sufficient, in particular for adding new tables and new fields. +// This is potentially slightly less efficient than a FlatBuffer constructed +// in one piece, since the new FlatBuffer doesn't share any vtables with the +// existing one. +// The return value can now be set using Vector::MutateOffset or SetFieldT +// below. +const uint8_t *AddFlatBuffer(std::vector &flatbuf, + const uint8_t *newbuf, size_t newlen); + +inline bool SetFieldT(Table *table, const reflection::Field &field, + const uint8_t *val) +{ + FLATBUFFERS_ASSERT(sizeof(uoffset_t) == + GetTypeSize(field.type()->base_type())); + return table->SetPointer(field.offset(), val); +} + +// ------------------------- COPYING ------------------------- + +// Generic copying of tables from a FlatBuffer into a FlatBuffer builder. +// Can be used to do any kind of merging/selecting you may want to do out +// of existing buffers. Also useful to reconstruct a whole buffer if the +// above resizing functionality has introduced garbage in a buffer you want +// to remove. +// Note: this does not deal with DAGs correctly. If the table passed forms a +// DAG, the copy will be a tree instead (with duplicates). Strings can be +// shared however, by passing true for use_string_pooling. + +Offset CopyTable(FlatBufferBuilder &fbb, + const reflection::Schema &schema, + const reflection::Object &objectdef, + const Table &table, + bool use_string_pooling = false); + +// Verifies the provided flatbuffer using reflection. +// root should point to the root type for this flatbuffer. +// buf should point to the start of flatbuffer data. +// length specifies the size of the flatbuffer data. +bool Verify(const reflection::Schema &schema, const reflection::Object &root, + const uint8_t *buf, size_t length, uoffset_t max_depth = 64, + uoffset_t max_tables = 1000000); + +} // namespace flatbuffers + +#endif // FLATBUFFERS_REFLECTION_H_ diff --git a/components/tflite/third_party/flatbuffers/include/flatbuffers/reflection_generated.h b/components/tflite/third_party/flatbuffers/include/flatbuffers/reflection_generated.h new file mode 100644 index 00000000..2bfc9798 --- /dev/null +++ b/components/tflite/third_party/flatbuffers/include/flatbuffers/reflection_generated.h @@ -0,0 +1,1399 @@ +// automatically generated by the FlatBuffers compiler, do not modify + +#ifndef FLATBUFFERS_GENERATED_REFLECTION_REFLECTION_H_ +#define FLATBUFFERS_GENERATED_REFLECTION_REFLECTION_H_ + +#include "flatbuffers/flatbuffers.h" + +namespace reflection { +struct Type; +struct TypeBuilder; + +struct KeyValue; +struct KeyValueBuilder; + +struct EnumVal; +struct EnumValBuilder; + +struct Enum; +struct EnumBuilder; + +struct Field; +struct FieldBuilder; + +struct Object; +struct ObjectBuilder; + +struct RPCCall; +struct RPCCallBuilder; + +struct Service; +struct ServiceBuilder; + +struct Schema; +struct SchemaBuilder; + +enum BaseType { + None = 0, + UType = 1, + Bool = 2, + Byte = 3, + UByte = 4, + Short = 5, + UShort = 6, + Int = 7, + UInt = 8, + Long = 9, + ULong = 10, + Float = 11, + Double = 12, + String = 13, + Vector = 14, + Obj = 15, + Union = 16, + Array = 17, + MaxBaseType = 18 +}; + +inline const BaseType (&EnumValuesBaseType())[19] +{ + static const BaseType values[] = { + None, + UType, + Bool, + Byte, + UByte, + Short, + UShort, + Int, + UInt, + Long, + ULong, + Float, + Double, + String, + Vector, + Obj, + Union, + Array, + MaxBaseType + }; + return values; +} + +inline const char *const *EnumNamesBaseType() +{ + static const char *const names[20] = { + "None", + "UType", + "Bool", + "Byte", + "UByte", + "Short", + "UShort", + "Int", + "UInt", + "Long", + "ULong", + "Float", + "Double", + "String", + "Vector", + "Obj", + "Union", + "Array", + "MaxBaseType", + nullptr + }; + return names; +} + +inline const char *EnumNameBaseType(BaseType e) +{ + if (flatbuffers::IsOutRange(e, None, MaxBaseType)) + return ""; + const size_t index = static_cast(e); + return EnumNamesBaseType()[index]; +} + +struct Type FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef TypeBuilder Builder; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_BASE_TYPE = 4, + VT_ELEMENT = 6, + VT_INDEX = 8, + VT_FIXED_LENGTH = 10 + }; + reflection::BaseType base_type() const + { + return static_cast(GetField(VT_BASE_TYPE, 0)); + } + reflection::BaseType element() const + { + return static_cast(GetField(VT_ELEMENT, 0)); + } + int32_t index() const + { + return GetField(VT_INDEX, -1); + } + uint16_t fixed_length() const + { + return GetField(VT_FIXED_LENGTH, 0); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyField(verifier, VT_BASE_TYPE) && + VerifyField(verifier, VT_ELEMENT) && + VerifyField(verifier, VT_INDEX) && + VerifyField(verifier, VT_FIXED_LENGTH) && + verifier.EndTable(); + } +}; + +struct TypeBuilder { + typedef Type Table; + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_base_type(reflection::BaseType base_type) + { + fbb_.AddElement(Type::VT_BASE_TYPE, static_cast(base_type), 0); + } + void add_element(reflection::BaseType element) + { + fbb_.AddElement(Type::VT_ELEMENT, static_cast(element), 0); + } + void add_index(int32_t index) + { + fbb_.AddElement(Type::VT_INDEX, index, -1); + } + void add_fixed_length(uint16_t fixed_length) + { + fbb_.AddElement(Type::VT_FIXED_LENGTH, fixed_length, 0); + } + explicit TypeBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + return o; + } +}; + +inline flatbuffers::Offset CreateType( + flatbuffers::FlatBufferBuilder &_fbb, + reflection::BaseType base_type = reflection::None, + reflection::BaseType element = reflection::None, + int32_t index = -1, + uint16_t fixed_length = 0) +{ + TypeBuilder builder_(_fbb); + builder_.add_index(index); + builder_.add_fixed_length(fixed_length); + builder_.add_element(element); + builder_.add_base_type(base_type); + return builder_.Finish(); +} + +struct KeyValue FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef KeyValueBuilder Builder; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_KEY = 4, + VT_VALUE = 6 + }; + const flatbuffers::String *key() const + { + return GetPointer(VT_KEY); + } + bool KeyCompareLessThan(const KeyValue *o) const + { + return *key() < *o->key(); + } + int KeyCompareWithValue(const char *val) const + { + return strcmp(key()->c_str(), val); + } + const flatbuffers::String *value() const + { + return GetPointer(VT_VALUE); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyOffsetRequired(verifier, VT_KEY) && + verifier.VerifyString(key()) && + VerifyOffset(verifier, VT_VALUE) && + verifier.VerifyString(value()) && + verifier.EndTable(); + } +}; + +struct KeyValueBuilder { + typedef KeyValue Table; + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_key(flatbuffers::Offset key) + { + fbb_.AddOffset(KeyValue::VT_KEY, key); + } + void add_value(flatbuffers::Offset value) + { + fbb_.AddOffset(KeyValue::VT_VALUE, value); + } + explicit KeyValueBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + fbb_.Required(o, KeyValue::VT_KEY); + return o; + } +}; + +inline flatbuffers::Offset CreateKeyValue( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset key = 0, + flatbuffers::Offset value = 0) +{ + KeyValueBuilder builder_(_fbb); + builder_.add_value(value); + builder_.add_key(key); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateKeyValueDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const char *key = nullptr, + const char *value = nullptr) +{ + auto key__ = key ? _fbb.CreateString(key) : 0; + auto value__ = value ? _fbb.CreateString(value) : 0; + return reflection::CreateKeyValue( + _fbb, + key__, + value__); +} + +struct EnumVal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef EnumValBuilder Builder; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_NAME = 4, + VT_VALUE = 6, + VT_OBJECT = 8, + VT_UNION_TYPE = 10, + VT_DOCUMENTATION = 12 + }; + const flatbuffers::String *name() const + { + return GetPointer(VT_NAME); + } + int64_t value() const + { + return GetField(VT_VALUE, 0); + } + bool KeyCompareLessThan(const EnumVal *o) const + { + return value() < o->value(); + } + int KeyCompareWithValue(int64_t val) const + { + return static_cast(value() > val) - static_cast(value() < val); + } + const reflection::Object *object() const + { + return GetPointer(VT_OBJECT); + } + const reflection::Type *union_type() const + { + return GetPointer(VT_UNION_TYPE); + } + const flatbuffers::Vector > *documentation() const + { + return GetPointer > *>(VT_DOCUMENTATION); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyOffsetRequired(verifier, VT_NAME) && + verifier.VerifyString(name()) && + VerifyField(verifier, VT_VALUE) && + VerifyOffset(verifier, VT_OBJECT) && + verifier.VerifyTable(object()) && + VerifyOffset(verifier, VT_UNION_TYPE) && + verifier.VerifyTable(union_type()) && + VerifyOffset(verifier, VT_DOCUMENTATION) && + verifier.VerifyVector(documentation()) && + verifier.VerifyVectorOfStrings(documentation()) && + verifier.EndTable(); + } +}; + +struct EnumValBuilder { + typedef EnumVal Table; + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_name(flatbuffers::Offset name) + { + fbb_.AddOffset(EnumVal::VT_NAME, name); + } + void add_value(int64_t value) + { + fbb_.AddElement(EnumVal::VT_VALUE, value, 0); + } + void add_object(flatbuffers::Offset object) + { + fbb_.AddOffset(EnumVal::VT_OBJECT, object); + } + void add_union_type(flatbuffers::Offset union_type) + { + fbb_.AddOffset(EnumVal::VT_UNION_TYPE, union_type); + } + void add_documentation(flatbuffers::Offset > > documentation) + { + fbb_.AddOffset(EnumVal::VT_DOCUMENTATION, documentation); + } + explicit EnumValBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + fbb_.Required(o, EnumVal::VT_NAME); + return o; + } +}; + +inline flatbuffers::Offset CreateEnumVal( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset name = 0, + int64_t value = 0, + flatbuffers::Offset object = 0, + flatbuffers::Offset union_type = 0, + flatbuffers::Offset > > documentation = 0) +{ + EnumValBuilder builder_(_fbb); + builder_.add_value(value); + builder_.add_documentation(documentation); + builder_.add_union_type(union_type); + builder_.add_object(object); + builder_.add_name(name); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateEnumValDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const char *name = nullptr, + int64_t value = 0, + flatbuffers::Offset object = 0, + flatbuffers::Offset union_type = 0, + const std::vector > *documentation = nullptr) +{ + auto name__ = name ? _fbb.CreateString(name) : 0; + auto documentation__ = documentation ? _fbb.CreateVector >(*documentation) : 0; + return reflection::CreateEnumVal( + _fbb, + name__, + value, + object, + union_type, + documentation__); +} + +struct Enum FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef EnumBuilder Builder; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_NAME = 4, + VT_VALUES = 6, + VT_IS_UNION = 8, + VT_UNDERLYING_TYPE = 10, + VT_ATTRIBUTES = 12, + VT_DOCUMENTATION = 14 + }; + const flatbuffers::String *name() const + { + return GetPointer(VT_NAME); + } + bool KeyCompareLessThan(const Enum *o) const + { + return *name() < *o->name(); + } + int KeyCompareWithValue(const char *val) const + { + return strcmp(name()->c_str(), val); + } + const flatbuffers::Vector > *values() const + { + return GetPointer > *>(VT_VALUES); + } + bool is_union() const + { + return GetField(VT_IS_UNION, 0) != 0; + } + const reflection::Type *underlying_type() const + { + return GetPointer(VT_UNDERLYING_TYPE); + } + const flatbuffers::Vector > *attributes() const + { + return GetPointer > *>(VT_ATTRIBUTES); + } + const flatbuffers::Vector > *documentation() const + { + return GetPointer > *>(VT_DOCUMENTATION); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyOffsetRequired(verifier, VT_NAME) && + verifier.VerifyString(name()) && + VerifyOffsetRequired(verifier, VT_VALUES) && + verifier.VerifyVector(values()) && + verifier.VerifyVectorOfTables(values()) && + VerifyField(verifier, VT_IS_UNION) && + VerifyOffsetRequired(verifier, VT_UNDERLYING_TYPE) && + verifier.VerifyTable(underlying_type()) && + VerifyOffset(verifier, VT_ATTRIBUTES) && + verifier.VerifyVector(attributes()) && + verifier.VerifyVectorOfTables(attributes()) && + VerifyOffset(verifier, VT_DOCUMENTATION) && + verifier.VerifyVector(documentation()) && + verifier.VerifyVectorOfStrings(documentation()) && + verifier.EndTable(); + } +}; + +struct EnumBuilder { + typedef Enum Table; + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_name(flatbuffers::Offset name) + { + fbb_.AddOffset(Enum::VT_NAME, name); + } + void add_values(flatbuffers::Offset > > values) + { + fbb_.AddOffset(Enum::VT_VALUES, values); + } + void add_is_union(bool is_union) + { + fbb_.AddElement(Enum::VT_IS_UNION, static_cast(is_union), 0); + } + void add_underlying_type(flatbuffers::Offset underlying_type) + { + fbb_.AddOffset(Enum::VT_UNDERLYING_TYPE, underlying_type); + } + void add_attributes(flatbuffers::Offset > > attributes) + { + fbb_.AddOffset(Enum::VT_ATTRIBUTES, attributes); + } + void add_documentation(flatbuffers::Offset > > documentation) + { + fbb_.AddOffset(Enum::VT_DOCUMENTATION, documentation); + } + explicit EnumBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + fbb_.Required(o, Enum::VT_NAME); + fbb_.Required(o, Enum::VT_VALUES); + fbb_.Required(o, Enum::VT_UNDERLYING_TYPE); + return o; + } +}; + +inline flatbuffers::Offset CreateEnum( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset name = 0, + flatbuffers::Offset > > values = 0, + bool is_union = false, + flatbuffers::Offset underlying_type = 0, + flatbuffers::Offset > > attributes = 0, + flatbuffers::Offset > > documentation = 0) +{ + EnumBuilder builder_(_fbb); + builder_.add_documentation(documentation); + builder_.add_attributes(attributes); + builder_.add_underlying_type(underlying_type); + builder_.add_values(values); + builder_.add_name(name); + builder_.add_is_union(is_union); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateEnumDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const char *name = nullptr, + std::vector > *values = nullptr, + bool is_union = false, + flatbuffers::Offset underlying_type = 0, + std::vector > *attributes = nullptr, + const std::vector > *documentation = nullptr) +{ + auto name__ = name ? _fbb.CreateString(name) : 0; + auto values__ = values ? _fbb.CreateVectorOfSortedTables(values) : 0; + auto attributes__ = attributes ? _fbb.CreateVectorOfSortedTables(attributes) : 0; + auto documentation__ = documentation ? _fbb.CreateVector >(*documentation) : 0; + return reflection::CreateEnum( + _fbb, + name__, + values__, + is_union, + underlying_type, + attributes__, + documentation__); +} + +struct Field FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef FieldBuilder Builder; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_NAME = 4, + VT_TYPE = 6, + VT_ID = 8, + VT_OFFSET = 10, + VT_DEFAULT_INTEGER = 12, + VT_DEFAULT_REAL = 14, + VT_DEPRECATED = 16, + VT_REQUIRED = 18, + VT_KEY = 20, + VT_ATTRIBUTES = 22, + VT_DOCUMENTATION = 24, + VT_OPTIONAL = 26 + }; + const flatbuffers::String *name() const + { + return GetPointer(VT_NAME); + } + bool KeyCompareLessThan(const Field *o) const + { + return *name() < *o->name(); + } + int KeyCompareWithValue(const char *val) const + { + return strcmp(name()->c_str(), val); + } + const reflection::Type *type() const + { + return GetPointer(VT_TYPE); + } + uint16_t id() const + { + return GetField(VT_ID, 0); + } + uint16_t offset() const + { + return GetField(VT_OFFSET, 0); + } + int64_t default_integer() const + { + return GetField(VT_DEFAULT_INTEGER, 0); + } + double default_real() const + { + return GetField(VT_DEFAULT_REAL, 0.0); + } + bool deprecated() const + { + return GetField(VT_DEPRECATED, 0) != 0; + } + bool required() const + { + return GetField(VT_REQUIRED, 0) != 0; + } + bool key() const + { + return GetField(VT_KEY, 0) != 0; + } + const flatbuffers::Vector > *attributes() const + { + return GetPointer > *>(VT_ATTRIBUTES); + } + const flatbuffers::Vector > *documentation() const + { + return GetPointer > *>(VT_DOCUMENTATION); + } + bool optional() const + { + return GetField(VT_OPTIONAL, 0) != 0; + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyOffsetRequired(verifier, VT_NAME) && + verifier.VerifyString(name()) && + VerifyOffsetRequired(verifier, VT_TYPE) && + verifier.VerifyTable(type()) && + VerifyField(verifier, VT_ID) && + VerifyField(verifier, VT_OFFSET) && + VerifyField(verifier, VT_DEFAULT_INTEGER) && + VerifyField(verifier, VT_DEFAULT_REAL) && + VerifyField(verifier, VT_DEPRECATED) && + VerifyField(verifier, VT_REQUIRED) && + VerifyField(verifier, VT_KEY) && + VerifyOffset(verifier, VT_ATTRIBUTES) && + verifier.VerifyVector(attributes()) && + verifier.VerifyVectorOfTables(attributes()) && + VerifyOffset(verifier, VT_DOCUMENTATION) && + verifier.VerifyVector(documentation()) && + verifier.VerifyVectorOfStrings(documentation()) && + VerifyField(verifier, VT_OPTIONAL) && + verifier.EndTable(); + } +}; + +struct FieldBuilder { + typedef Field Table; + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_name(flatbuffers::Offset name) + { + fbb_.AddOffset(Field::VT_NAME, name); + } + void add_type(flatbuffers::Offset type) + { + fbb_.AddOffset(Field::VT_TYPE, type); + } + void add_id(uint16_t id) + { + fbb_.AddElement(Field::VT_ID, id, 0); + } + void add_offset(uint16_t offset) + { + fbb_.AddElement(Field::VT_OFFSET, offset, 0); + } + void add_default_integer(int64_t default_integer) + { + fbb_.AddElement(Field::VT_DEFAULT_INTEGER, default_integer, 0); + } + void add_default_real(double default_real) + { + fbb_.AddElement(Field::VT_DEFAULT_REAL, default_real, 0.0); + } + void add_deprecated(bool deprecated) + { + fbb_.AddElement(Field::VT_DEPRECATED, static_cast(deprecated), 0); + } + void add_required(bool required) + { + fbb_.AddElement(Field::VT_REQUIRED, static_cast(required), 0); + } + void add_key(bool key) + { + fbb_.AddElement(Field::VT_KEY, static_cast(key), 0); + } + void add_attributes(flatbuffers::Offset > > attributes) + { + fbb_.AddOffset(Field::VT_ATTRIBUTES, attributes); + } + void add_documentation(flatbuffers::Offset > > documentation) + { + fbb_.AddOffset(Field::VT_DOCUMENTATION, documentation); + } + void add_optional(bool optional) + { + fbb_.AddElement(Field::VT_OPTIONAL, static_cast(optional), 0); + } + explicit FieldBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + fbb_.Required(o, Field::VT_NAME); + fbb_.Required(o, Field::VT_TYPE); + return o; + } +}; + +inline flatbuffers::Offset CreateField( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset name = 0, + flatbuffers::Offset type = 0, + uint16_t id = 0, + uint16_t offset = 0, + int64_t default_integer = 0, + double default_real = 0.0, + bool deprecated = false, + bool required = false, + bool key = false, + flatbuffers::Offset > > attributes = 0, + flatbuffers::Offset > > documentation = 0, + bool optional = false) +{ + FieldBuilder builder_(_fbb); + builder_.add_default_real(default_real); + builder_.add_default_integer(default_integer); + builder_.add_documentation(documentation); + builder_.add_attributes(attributes); + builder_.add_type(type); + builder_.add_name(name); + builder_.add_offset(offset); + builder_.add_id(id); + builder_.add_optional(optional); + builder_.add_key(key); + builder_.add_required(required); + builder_.add_deprecated(deprecated); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateFieldDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const char *name = nullptr, + flatbuffers::Offset type = 0, + uint16_t id = 0, + uint16_t offset = 0, + int64_t default_integer = 0, + double default_real = 0.0, + bool deprecated = false, + bool required = false, + bool key = false, + std::vector > *attributes = nullptr, + const std::vector > *documentation = nullptr, + bool optional = false) +{ + auto name__ = name ? _fbb.CreateString(name) : 0; + auto attributes__ = attributes ? _fbb.CreateVectorOfSortedTables(attributes) : 0; + auto documentation__ = documentation ? _fbb.CreateVector >(*documentation) : 0; + return reflection::CreateField( + _fbb, + name__, + type, + id, + offset, + default_integer, + default_real, + deprecated, + required, + key, + attributes__, + documentation__, + optional); +} + +struct Object FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef ObjectBuilder Builder; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_NAME = 4, + VT_FIELDS = 6, + VT_IS_STRUCT = 8, + VT_MINALIGN = 10, + VT_BYTESIZE = 12, + VT_ATTRIBUTES = 14, + VT_DOCUMENTATION = 16 + }; + const flatbuffers::String *name() const + { + return GetPointer(VT_NAME); + } + bool KeyCompareLessThan(const Object *o) const + { + return *name() < *o->name(); + } + int KeyCompareWithValue(const char *val) const + { + return strcmp(name()->c_str(), val); + } + const flatbuffers::Vector > *fields() const + { + return GetPointer > *>(VT_FIELDS); + } + bool is_struct() const + { + return GetField(VT_IS_STRUCT, 0) != 0; + } + int32_t minalign() const + { + return GetField(VT_MINALIGN, 0); + } + int32_t bytesize() const + { + return GetField(VT_BYTESIZE, 0); + } + const flatbuffers::Vector > *attributes() const + { + return GetPointer > *>(VT_ATTRIBUTES); + } + const flatbuffers::Vector > *documentation() const + { + return GetPointer > *>(VT_DOCUMENTATION); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyOffsetRequired(verifier, VT_NAME) && + verifier.VerifyString(name()) && + VerifyOffsetRequired(verifier, VT_FIELDS) && + verifier.VerifyVector(fields()) && + verifier.VerifyVectorOfTables(fields()) && + VerifyField(verifier, VT_IS_STRUCT) && + VerifyField(verifier, VT_MINALIGN) && + VerifyField(verifier, VT_BYTESIZE) && + VerifyOffset(verifier, VT_ATTRIBUTES) && + verifier.VerifyVector(attributes()) && + verifier.VerifyVectorOfTables(attributes()) && + VerifyOffset(verifier, VT_DOCUMENTATION) && + verifier.VerifyVector(documentation()) && + verifier.VerifyVectorOfStrings(documentation()) && + verifier.EndTable(); + } +}; + +struct ObjectBuilder { + typedef Object Table; + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_name(flatbuffers::Offset name) + { + fbb_.AddOffset(Object::VT_NAME, name); + } + void add_fields(flatbuffers::Offset > > fields) + { + fbb_.AddOffset(Object::VT_FIELDS, fields); + } + void add_is_struct(bool is_struct) + { + fbb_.AddElement(Object::VT_IS_STRUCT, static_cast(is_struct), 0); + } + void add_minalign(int32_t minalign) + { + fbb_.AddElement(Object::VT_MINALIGN, minalign, 0); + } + void add_bytesize(int32_t bytesize) + { + fbb_.AddElement(Object::VT_BYTESIZE, bytesize, 0); + } + void add_attributes(flatbuffers::Offset > > attributes) + { + fbb_.AddOffset(Object::VT_ATTRIBUTES, attributes); + } + void add_documentation(flatbuffers::Offset > > documentation) + { + fbb_.AddOffset(Object::VT_DOCUMENTATION, documentation); + } + explicit ObjectBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + fbb_.Required(o, Object::VT_NAME); + fbb_.Required(o, Object::VT_FIELDS); + return o; + } +}; + +inline flatbuffers::Offset CreateObject( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset name = 0, + flatbuffers::Offset > > fields = 0, + bool is_struct = false, + int32_t minalign = 0, + int32_t bytesize = 0, + flatbuffers::Offset > > attributes = 0, + flatbuffers::Offset > > documentation = 0) +{ + ObjectBuilder builder_(_fbb); + builder_.add_documentation(documentation); + builder_.add_attributes(attributes); + builder_.add_bytesize(bytesize); + builder_.add_minalign(minalign); + builder_.add_fields(fields); + builder_.add_name(name); + builder_.add_is_struct(is_struct); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateObjectDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const char *name = nullptr, + std::vector > *fields = nullptr, + bool is_struct = false, + int32_t minalign = 0, + int32_t bytesize = 0, + std::vector > *attributes = nullptr, + const std::vector > *documentation = nullptr) +{ + auto name__ = name ? _fbb.CreateString(name) : 0; + auto fields__ = fields ? _fbb.CreateVectorOfSortedTables(fields) : 0; + auto attributes__ = attributes ? _fbb.CreateVectorOfSortedTables(attributes) : 0; + auto documentation__ = documentation ? _fbb.CreateVector >(*documentation) : 0; + return reflection::CreateObject( + _fbb, + name__, + fields__, + is_struct, + minalign, + bytesize, + attributes__, + documentation__); +} + +struct RPCCall FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef RPCCallBuilder Builder; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_NAME = 4, + VT_REQUEST = 6, + VT_RESPONSE = 8, + VT_ATTRIBUTES = 10, + VT_DOCUMENTATION = 12 + }; + const flatbuffers::String *name() const + { + return GetPointer(VT_NAME); + } + bool KeyCompareLessThan(const RPCCall *o) const + { + return *name() < *o->name(); + } + int KeyCompareWithValue(const char *val) const + { + return strcmp(name()->c_str(), val); + } + const reflection::Object *request() const + { + return GetPointer(VT_REQUEST); + } + const reflection::Object *response() const + { + return GetPointer(VT_RESPONSE); + } + const flatbuffers::Vector > *attributes() const + { + return GetPointer > *>(VT_ATTRIBUTES); + } + const flatbuffers::Vector > *documentation() const + { + return GetPointer > *>(VT_DOCUMENTATION); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyOffsetRequired(verifier, VT_NAME) && + verifier.VerifyString(name()) && + VerifyOffsetRequired(verifier, VT_REQUEST) && + verifier.VerifyTable(request()) && + VerifyOffsetRequired(verifier, VT_RESPONSE) && + verifier.VerifyTable(response()) && + VerifyOffset(verifier, VT_ATTRIBUTES) && + verifier.VerifyVector(attributes()) && + verifier.VerifyVectorOfTables(attributes()) && + VerifyOffset(verifier, VT_DOCUMENTATION) && + verifier.VerifyVector(documentation()) && + verifier.VerifyVectorOfStrings(documentation()) && + verifier.EndTable(); + } +}; + +struct RPCCallBuilder { + typedef RPCCall Table; + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_name(flatbuffers::Offset name) + { + fbb_.AddOffset(RPCCall::VT_NAME, name); + } + void add_request(flatbuffers::Offset request) + { + fbb_.AddOffset(RPCCall::VT_REQUEST, request); + } + void add_response(flatbuffers::Offset response) + { + fbb_.AddOffset(RPCCall::VT_RESPONSE, response); + } + void add_attributes(flatbuffers::Offset > > attributes) + { + fbb_.AddOffset(RPCCall::VT_ATTRIBUTES, attributes); + } + void add_documentation(flatbuffers::Offset > > documentation) + { + fbb_.AddOffset(RPCCall::VT_DOCUMENTATION, documentation); + } + explicit RPCCallBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + fbb_.Required(o, RPCCall::VT_NAME); + fbb_.Required(o, RPCCall::VT_REQUEST); + fbb_.Required(o, RPCCall::VT_RESPONSE); + return o; + } +}; + +inline flatbuffers::Offset CreateRPCCall( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset name = 0, + flatbuffers::Offset request = 0, + flatbuffers::Offset response = 0, + flatbuffers::Offset > > attributes = 0, + flatbuffers::Offset > > documentation = 0) +{ + RPCCallBuilder builder_(_fbb); + builder_.add_documentation(documentation); + builder_.add_attributes(attributes); + builder_.add_response(response); + builder_.add_request(request); + builder_.add_name(name); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateRPCCallDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const char *name = nullptr, + flatbuffers::Offset request = 0, + flatbuffers::Offset response = 0, + std::vector > *attributes = nullptr, + const std::vector > *documentation = nullptr) +{ + auto name__ = name ? _fbb.CreateString(name) : 0; + auto attributes__ = attributes ? _fbb.CreateVectorOfSortedTables(attributes) : 0; + auto documentation__ = documentation ? _fbb.CreateVector >(*documentation) : 0; + return reflection::CreateRPCCall( + _fbb, + name__, + request, + response, + attributes__, + documentation__); +} + +struct Service FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef ServiceBuilder Builder; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_NAME = 4, + VT_CALLS = 6, + VT_ATTRIBUTES = 8, + VT_DOCUMENTATION = 10 + }; + const flatbuffers::String *name() const + { + return GetPointer(VT_NAME); + } + bool KeyCompareLessThan(const Service *o) const + { + return *name() < *o->name(); + } + int KeyCompareWithValue(const char *val) const + { + return strcmp(name()->c_str(), val); + } + const flatbuffers::Vector > *calls() const + { + return GetPointer > *>(VT_CALLS); + } + const flatbuffers::Vector > *attributes() const + { + return GetPointer > *>(VT_ATTRIBUTES); + } + const flatbuffers::Vector > *documentation() const + { + return GetPointer > *>(VT_DOCUMENTATION); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyOffsetRequired(verifier, VT_NAME) && + verifier.VerifyString(name()) && + VerifyOffset(verifier, VT_CALLS) && + verifier.VerifyVector(calls()) && + verifier.VerifyVectorOfTables(calls()) && + VerifyOffset(verifier, VT_ATTRIBUTES) && + verifier.VerifyVector(attributes()) && + verifier.VerifyVectorOfTables(attributes()) && + VerifyOffset(verifier, VT_DOCUMENTATION) && + verifier.VerifyVector(documentation()) && + verifier.VerifyVectorOfStrings(documentation()) && + verifier.EndTable(); + } +}; + +struct ServiceBuilder { + typedef Service Table; + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_name(flatbuffers::Offset name) + { + fbb_.AddOffset(Service::VT_NAME, name); + } + void add_calls(flatbuffers::Offset > > calls) + { + fbb_.AddOffset(Service::VT_CALLS, calls); + } + void add_attributes(flatbuffers::Offset > > attributes) + { + fbb_.AddOffset(Service::VT_ATTRIBUTES, attributes); + } + void add_documentation(flatbuffers::Offset > > documentation) + { + fbb_.AddOffset(Service::VT_DOCUMENTATION, documentation); + } + explicit ServiceBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + fbb_.Required(o, Service::VT_NAME); + return o; + } +}; + +inline flatbuffers::Offset CreateService( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset name = 0, + flatbuffers::Offset > > calls = 0, + flatbuffers::Offset > > attributes = 0, + flatbuffers::Offset > > documentation = 0) +{ + ServiceBuilder builder_(_fbb); + builder_.add_documentation(documentation); + builder_.add_attributes(attributes); + builder_.add_calls(calls); + builder_.add_name(name); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateServiceDirect( + flatbuffers::FlatBufferBuilder &_fbb, + const char *name = nullptr, + std::vector > *calls = nullptr, + std::vector > *attributes = nullptr, + const std::vector > *documentation = nullptr) +{ + auto name__ = name ? _fbb.CreateString(name) : 0; + auto calls__ = calls ? _fbb.CreateVectorOfSortedTables(calls) : 0; + auto attributes__ = attributes ? _fbb.CreateVectorOfSortedTables(attributes) : 0; + auto documentation__ = documentation ? _fbb.CreateVector >(*documentation) : 0; + return reflection::CreateService( + _fbb, + name__, + calls__, + attributes__, + documentation__); +} + +struct Schema FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { + typedef SchemaBuilder Builder; + enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { + VT_OBJECTS = 4, + VT_ENUMS = 6, + VT_FILE_IDENT = 8, + VT_FILE_EXT = 10, + VT_ROOT_TABLE = 12, + VT_SERVICES = 14 + }; + const flatbuffers::Vector > *objects() const + { + return GetPointer > *>(VT_OBJECTS); + } + const flatbuffers::Vector > *enums() const + { + return GetPointer > *>(VT_ENUMS); + } + const flatbuffers::String *file_ident() const + { + return GetPointer(VT_FILE_IDENT); + } + const flatbuffers::String *file_ext() const + { + return GetPointer(VT_FILE_EXT); + } + const reflection::Object *root_table() const + { + return GetPointer(VT_ROOT_TABLE); + } + const flatbuffers::Vector > *services() const + { + return GetPointer > *>(VT_SERVICES); + } + bool Verify(flatbuffers::Verifier &verifier) const + { + return VerifyTableStart(verifier) && + VerifyOffsetRequired(verifier, VT_OBJECTS) && + verifier.VerifyVector(objects()) && + verifier.VerifyVectorOfTables(objects()) && + VerifyOffsetRequired(verifier, VT_ENUMS) && + verifier.VerifyVector(enums()) && + verifier.VerifyVectorOfTables(enums()) && + VerifyOffset(verifier, VT_FILE_IDENT) && + verifier.VerifyString(file_ident()) && + VerifyOffset(verifier, VT_FILE_EXT) && + verifier.VerifyString(file_ext()) && + VerifyOffset(verifier, VT_ROOT_TABLE) && + verifier.VerifyTable(root_table()) && + VerifyOffset(verifier, VT_SERVICES) && + verifier.VerifyVector(services()) && + verifier.VerifyVectorOfTables(services()) && + verifier.EndTable(); + } +}; + +struct SchemaBuilder { + typedef Schema Table; + flatbuffers::FlatBufferBuilder &fbb_; + flatbuffers::uoffset_t start_; + void add_objects(flatbuffers::Offset > > objects) + { + fbb_.AddOffset(Schema::VT_OBJECTS, objects); + } + void add_enums(flatbuffers::Offset > > enums) + { + fbb_.AddOffset(Schema::VT_ENUMS, enums); + } + void add_file_ident(flatbuffers::Offset file_ident) + { + fbb_.AddOffset(Schema::VT_FILE_IDENT, file_ident); + } + void add_file_ext(flatbuffers::Offset file_ext) + { + fbb_.AddOffset(Schema::VT_FILE_EXT, file_ext); + } + void add_root_table(flatbuffers::Offset root_table) + { + fbb_.AddOffset(Schema::VT_ROOT_TABLE, root_table); + } + void add_services(flatbuffers::Offset > > services) + { + fbb_.AddOffset(Schema::VT_SERVICES, services); + } + explicit SchemaBuilder(flatbuffers::FlatBufferBuilder &_fbb) + : fbb_(_fbb) + { + start_ = fbb_.StartTable(); + } + flatbuffers::Offset Finish() + { + const auto end = fbb_.EndTable(start_); + auto o = flatbuffers::Offset(end); + fbb_.Required(o, Schema::VT_OBJECTS); + fbb_.Required(o, Schema::VT_ENUMS); + return o; + } +}; + +inline flatbuffers::Offset CreateSchema( + flatbuffers::FlatBufferBuilder &_fbb, + flatbuffers::Offset > > objects = 0, + flatbuffers::Offset > > enums = 0, + flatbuffers::Offset file_ident = 0, + flatbuffers::Offset file_ext = 0, + flatbuffers::Offset root_table = 0, + flatbuffers::Offset > > services = 0) +{ + SchemaBuilder builder_(_fbb); + builder_.add_services(services); + builder_.add_root_table(root_table); + builder_.add_file_ext(file_ext); + builder_.add_file_ident(file_ident); + builder_.add_enums(enums); + builder_.add_objects(objects); + return builder_.Finish(); +} + +inline flatbuffers::Offset CreateSchemaDirect( + flatbuffers::FlatBufferBuilder &_fbb, + std::vector > *objects = nullptr, + std::vector > *enums = nullptr, + const char *file_ident = nullptr, + const char *file_ext = nullptr, + flatbuffers::Offset root_table = 0, + std::vector > *services = nullptr) +{ + auto objects__ = objects ? _fbb.CreateVectorOfSortedTables(objects) : 0; + auto enums__ = enums ? _fbb.CreateVectorOfSortedTables(enums) : 0; + auto file_ident__ = file_ident ? _fbb.CreateString(file_ident) : 0; + auto file_ext__ = file_ext ? _fbb.CreateString(file_ext) : 0; + auto services__ = services ? _fbb.CreateVectorOfSortedTables(services) : 0; + return reflection::CreateSchema( + _fbb, + objects__, + enums__, + file_ident__, + file_ext__, + root_table, + services__); +} + +inline const reflection::Schema *GetSchema(const void *buf) +{ + return flatbuffers::GetRoot(buf); +} + +inline const reflection::Schema *GetSizePrefixedSchema(const void *buf) +{ + return flatbuffers::GetSizePrefixedRoot(buf); +} + +inline const char *SchemaIdentifier() +{ + return "BFBS"; +} + +inline bool SchemaBufferHasIdentifier(const void *buf) +{ + return flatbuffers::BufferHasIdentifier( + buf, SchemaIdentifier()); +} + +inline bool VerifySchemaBuffer( + flatbuffers::Verifier &verifier) +{ + return verifier.VerifyBuffer(SchemaIdentifier()); +} + +inline bool VerifySizePrefixedSchemaBuffer( + flatbuffers::Verifier &verifier) +{ + return verifier.VerifySizePrefixedBuffer(SchemaIdentifier()); +} + +inline const char *SchemaExtension() +{ + return "bfbs"; +} + +inline void FinishSchemaBuffer( + flatbuffers::FlatBufferBuilder &fbb, + flatbuffers::Offset root) +{ + fbb.Finish(root, SchemaIdentifier()); +} + +inline void FinishSizePrefixedSchemaBuffer( + flatbuffers::FlatBufferBuilder &fbb, + flatbuffers::Offset root) +{ + fbb.FinishSizePrefixed(root, SchemaIdentifier()); +} + +} // namespace reflection + +#endif // FLATBUFFERS_GENERATED_REFLECTION_REFLECTION_H_ diff --git a/components/tflite/third_party/flatbuffers/include/flatbuffers/registry.h b/components/tflite/third_party/flatbuffers/include/flatbuffers/registry.h new file mode 100644 index 00000000..cc8158b5 --- /dev/null +++ b/components/tflite/third_party/flatbuffers/include/flatbuffers/registry.h @@ -0,0 +1,141 @@ +/* + * Copyright 2017 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FLATBUFFERS_REGISTRY_H_ +#define FLATBUFFERS_REGISTRY_H_ + +#include "flatbuffers/idl.h" + +namespace flatbuffers { +// Convenience class to easily parse or generate text for arbitrary FlatBuffers. +// Simply pre-populate it with all schema filenames that may be in use, and +// This class will look them up using the file_identifier declared in the +// schema. +class Registry { +public: + // Call this for all schemas that may be in use. The identifier has + // a function in the generated code, e.g. MonsterIdentifier(). + void Register(const char *file_identifier, const char *schema_path) + { + Schema schema; + schema.path_ = schema_path; + schemas_[file_identifier] = schema; + } + + // Generate text from an arbitrary FlatBuffer by looking up its + // file_identifier in the registry. + bool FlatBufferToText(const uint8_t *flatbuf, size_t len, std::string *dest) + { + // Get the identifier out of the buffer. + // If the buffer is truncated, exit. + if (len < sizeof(uoffset_t) + FlatBufferBuilder::kFileIdentifierLength) { + lasterror_ = "buffer truncated"; + return false; + } + std::string ident( + reinterpret_cast(flatbuf) + sizeof(uoffset_t), + FlatBufferBuilder::kFileIdentifierLength); + // Load and parse the schema. + Parser parser; + if (!LoadSchema(ident, &parser)) + return false; + // Now we're ready to generate text. + if (!GenerateText(parser, flatbuf, dest)) { + lasterror_ = "unable to generate text for FlatBuffer binary"; + return false; + } + return true; + } + + // Converts a binary buffer to text using one of the schemas in the registry, + // use the file_identifier to indicate which. + // If DetachedBuffer::data() is null then parsing failed. + DetachedBuffer TextToFlatBuffer(const char *text, + const char *file_identifier) + { + // Load and parse the schema. + Parser parser; + if (!LoadSchema(file_identifier, &parser)) + return DetachedBuffer(); + // Parse the text. + if (!parser.Parse(text)) { + lasterror_ = parser.error_; + return DetachedBuffer(); + } + // We have a valid FlatBuffer. Detach it from the builder and return. + return parser.builder_.Release(); + } + + // Modify any parsing / output options used by the other functions. + void SetOptions(const IDLOptions &opts) + { + opts_ = opts; + } + + // If schemas used contain include statements, call this function for every + // directory the parser should search them for. + void AddIncludeDirectory(const char *path) + { + include_paths_.push_back(path); + } + + // Returns a human readable error if any of the above functions fail. + const std::string &GetLastError() + { + return lasterror_; + } + +private: + bool LoadSchema(const std::string &ident, Parser *parser) + { + // Find the schema, if not, exit. + auto it = schemas_.find(ident); + if (it == schemas_.end()) { + // Don't attach the identifier, since it may not be human readable. + lasterror_ = "identifier for this buffer not in the registry"; + return false; + } + auto &schema = it->second; + // Load the schema from disk. If not, exit. + std::string schematext; + if (!LoadFile(schema.path_.c_str(), false, &schematext)) { + lasterror_ = "could not load schema: " + schema.path_; + return false; + } + // Parse schema. + parser->opts = opts_; + if (!parser->Parse(schematext.c_str(), vector_data(include_paths_), + schema.path_.c_str())) { + lasterror_ = parser->error_; + return false; + } + return true; + } + + struct Schema { + std::string path_; + // TODO(wvo) optionally cache schema file or parsed schema here. + }; + + std::string lasterror_; + IDLOptions opts_; + std::vector include_paths_; + std::map schemas_; +}; + +} // namespace flatbuffers + +#endif // FLATBUFFERS_REGISTRY_H_ diff --git a/components/tflite/third_party/flatbuffers/include/flatbuffers/stl_emulation.h b/components/tflite/third_party/flatbuffers/include/flatbuffers/stl_emulation.h new file mode 100644 index 00000000..c9a1a8bf --- /dev/null +++ b/components/tflite/third_party/flatbuffers/include/flatbuffers/stl_emulation.h @@ -0,0 +1,449 @@ +/* + * Copyright 2017 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FLATBUFFERS_STL_EMULATION_H_ +#define FLATBUFFERS_STL_EMULATION_H_ + +// clang-format off +#include "flatbuffers/base.h" + +#include +#include +#include +#include +#include + +// Detect C++17 compatible compiler. +// __cplusplus >= 201703L - a compiler has support of 'static inline' variables. +#if defined(FLATBUFFERS_USE_STD_OPTIONAL) \ + || (defined(__cplusplus) && __cplusplus >= 201703L) \ + || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)) + #include + #ifndef FLATBUFFERS_USE_STD_OPTIONAL + #define FLATBUFFERS_USE_STD_OPTIONAL + #endif +#endif + +#if defined(_STLPORT_VERSION) && !defined(FLATBUFFERS_CPP98_STL) + #define FLATBUFFERS_CPP98_STL +#endif // defined(_STLPORT_VERSION) && !defined(FLATBUFFERS_CPP98_STL) + +#if defined(FLATBUFFERS_CPP98_STL) + #include +#endif // defined(FLATBUFFERS_CPP98_STL) + +// This header provides backwards compatibility for C++98 STLs like stlport. +namespace flatbuffers { + +// Retrieve ::back() from a string in a way that is compatible with pre C++11 +// STLs (e.g stlport). +inline char& string_back(std::string &value) { + return value[value.length() - 1]; +} + +inline char string_back(const std::string &value) { + return value[value.length() - 1]; +} + +// Helper method that retrieves ::data() from a vector in a way that is +// compatible with pre C++11 STLs (e.g stlport). +template inline T *vector_data(std::vector &vector) { + // In some debug environments, operator[] does bounds checking, so &vector[0] + // can't be used. + return vector.empty() ? nullptr : &vector[0]; +} + +template inline const T *vector_data( + const std::vector &vector) { + return vector.empty() ? nullptr : &vector[0]; +} + +template +inline void vector_emplace_back(std::vector *vector, V &&data) { + #if defined(FLATBUFFERS_CPP98_STL) + vector->push_back(data); + #else + vector->emplace_back(std::forward(data)); + #endif // defined(FLATBUFFERS_CPP98_STL) +} + +#ifndef FLATBUFFERS_CPP98_STL + #if defined(FLATBUFFERS_TEMPLATES_ALIASES) + template + using numeric_limits = std::numeric_limits; + #else + template class numeric_limits : + public std::numeric_limits {}; + #endif // defined(FLATBUFFERS_TEMPLATES_ALIASES) +#else + template class numeric_limits : + public std::numeric_limits { + public: + // Android NDK fix. + static T lowest() { + return std::numeric_limits::min(); + } + }; + + template <> class numeric_limits : + public std::numeric_limits { + public: + static float lowest() { return -FLT_MAX; } + }; + + template <> class numeric_limits : + public std::numeric_limits { + public: + static double lowest() { return -DBL_MAX; } + }; + + template <> class numeric_limits { + public: + static unsigned long long min() { return 0ULL; } + static unsigned long long max() { return ~0ULL; } + static unsigned long long lowest() { + return numeric_limits::min(); + } + }; + + template <> class numeric_limits { + public: + static long long min() { + return static_cast(1ULL << ((sizeof(long long) << 3) - 1)); + } + static long long max() { + return static_cast( + (1ULL << ((sizeof(long long) << 3) - 1)) - 1); + } + static long long lowest() { + return numeric_limits::min(); + } + }; +#endif // FLATBUFFERS_CPP98_STL + +#if defined(FLATBUFFERS_TEMPLATES_ALIASES) + #ifndef FLATBUFFERS_CPP98_STL + template using is_scalar = std::is_scalar; + template using is_same = std::is_same; + template using is_floating_point = std::is_floating_point; + template using is_unsigned = std::is_unsigned; + template using is_enum = std::is_enum; + template using make_unsigned = std::make_unsigned; + template + using conditional = std::conditional; + template + using integral_constant = std::integral_constant; + #else + // Map C++ TR1 templates defined by stlport. + template using is_scalar = std::tr1::is_scalar; + template using is_same = std::tr1::is_same; + template using is_floating_point = + std::tr1::is_floating_point; + template using is_unsigned = std::tr1::is_unsigned; + template using is_enum = std::tr1::is_enum; + // Android NDK doesn't have std::make_unsigned or std::tr1::make_unsigned. + template struct make_unsigned { + static_assert(is_unsigned::value, "Specialization not implemented!"); + using type = T; + }; + template<> struct make_unsigned { using type = unsigned char; }; + template<> struct make_unsigned { using type = unsigned short; }; + template<> struct make_unsigned { using type = unsigned int; }; + template<> struct make_unsigned { using type = unsigned long; }; + template<> + struct make_unsigned { using type = unsigned long long; }; + template + using conditional = std::tr1::conditional; + template + using integral_constant = std::tr1::integral_constant; + #endif // !FLATBUFFERS_CPP98_STL +#else + // MSVC 2010 doesn't support C++11 aliases. + template struct is_scalar : public std::is_scalar {}; + template struct is_same : public std::is_same {}; + template struct is_floating_point : + public std::is_floating_point {}; + template struct is_unsigned : public std::is_unsigned {}; + template struct is_enum : public std::is_enum {}; + template struct make_unsigned : public std::make_unsigned {}; + template + struct conditional : public std::conditional {}; + template + struct integral_constant : public std::integral_constant {}; +#endif // defined(FLATBUFFERS_TEMPLATES_ALIASES) + +#ifndef FLATBUFFERS_CPP98_STL + #if defined(FLATBUFFERS_TEMPLATES_ALIASES) + template using unique_ptr = std::unique_ptr; + #else + // MSVC 2010 doesn't support C++11 aliases. + // We're manually "aliasing" the class here as we want to bring unique_ptr + // into the flatbuffers namespace. We have unique_ptr in the flatbuffers + // namespace we have a completely independent implementation (see below) + // for C++98 STL implementations. + template class unique_ptr : public std::unique_ptr { + public: + unique_ptr() {} + explicit unique_ptr(T* p) : std::unique_ptr(p) {} + unique_ptr(std::unique_ptr&& u) { *this = std::move(u); } + unique_ptr(unique_ptr&& u) { *this = std::move(u); } + unique_ptr& operator=(std::unique_ptr&& u) { + std::unique_ptr::reset(u.release()); + return *this; + } + unique_ptr& operator=(unique_ptr&& u) { + std::unique_ptr::reset(u.release()); + return *this; + } + unique_ptr& operator=(T* p) { + return std::unique_ptr::operator=(p); + } + }; + #endif // defined(FLATBUFFERS_TEMPLATES_ALIASES) +#else + // Very limited implementation of unique_ptr. + // This is provided simply to allow the C++ code generated from the default + // settings to function in C++98 environments with no modifications. + template class unique_ptr { + public: + typedef T element_type; + + unique_ptr() : ptr_(nullptr) {} + explicit unique_ptr(T* p) : ptr_(p) {} + unique_ptr(unique_ptr&& u) : ptr_(nullptr) { reset(u.release()); } + unique_ptr(const unique_ptr& u) : ptr_(nullptr) { + reset(const_cast(&u)->release()); + } + ~unique_ptr() { reset(); } + + unique_ptr& operator=(const unique_ptr& u) { + reset(const_cast(&u)->release()); + return *this; + } + + unique_ptr& operator=(unique_ptr&& u) { + reset(u.release()); + return *this; + } + + unique_ptr& operator=(T* p) { + reset(p); + return *this; + } + + const T& operator*() const { return *ptr_; } + T* operator->() const { return ptr_; } + T* get() const noexcept { return ptr_; } + explicit operator bool() const { return ptr_ != nullptr; } + + // modifiers + T* release() { + T* value = ptr_; + ptr_ = nullptr; + return value; + } + + void reset(T* p = nullptr) { + T* value = ptr_; + ptr_ = p; + if (value) delete value; + } + + void swap(unique_ptr& u) { + T* temp_ptr = ptr_; + ptr_ = u.ptr_; + u.ptr_ = temp_ptr; + } + + private: + T* ptr_; + }; + + template bool operator==(const unique_ptr& x, + const unique_ptr& y) { + return x.get() == y.get(); + } + + template bool operator==(const unique_ptr& x, + const D* y) { + return static_cast(x.get()) == y; + } + + template bool operator==(const unique_ptr& x, intptr_t y) { + return reinterpret_cast(x.get()) == y; + } + + template bool operator!=(const unique_ptr& x, decltype(nullptr)) { + return !!x; + } + + template bool operator!=(decltype(nullptr), const unique_ptr& x) { + return !!x; + } + + template bool operator==(const unique_ptr& x, decltype(nullptr)) { + return !x; + } + + template bool operator==(decltype(nullptr), const unique_ptr& x) { + return !x; + } + +#endif // !FLATBUFFERS_CPP98_STL + +#ifdef FLATBUFFERS_USE_STD_OPTIONAL +template +using Optional = std::optional; +using nullopt_t = std::nullopt_t; +inline constexpr nullopt_t nullopt = std::nullopt; + +#else +// Limited implementation of Optional type for a scalar T. +// This implementation limited by trivial types compatible with +// std::is_arithmetic or std::is_enum type traits. + +// A tag to indicate an empty flatbuffers::optional. +struct nullopt_t { + explicit FLATBUFFERS_CONSTEXPR_CPP11 nullopt_t(int) {} +}; + +#if defined(FLATBUFFERS_CONSTEXPR_DEFINED) + namespace internal { + template struct nullopt_holder { + static constexpr nullopt_t instance_ = nullopt_t(0); + }; + template + constexpr nullopt_t nullopt_holder::instance_; + } + static constexpr const nullopt_t &nullopt = internal::nullopt_holder::instance_; + +#else + namespace internal { + template struct nullopt_holder { + static const nullopt_t instance_; + }; + template + const nullopt_t nullopt_holder::instance_ = nullopt_t(0); + } + static const nullopt_t &nullopt = internal::nullopt_holder::instance_; + +#endif + +template +class Optional FLATBUFFERS_FINAL_CLASS { + // Non-scalar 'T' would extremely complicated Optional. + // Use is_scalar checking because flatbuffers flatbuffers::is_arithmetic + // isn't implemented. + static_assert(flatbuffers::is_scalar::value, "unexpected type T"); + + public: + ~Optional() {} + + FLATBUFFERS_CONSTEXPR_CPP11 Optional() FLATBUFFERS_NOEXCEPT + : value_(), has_value_(false) {} + + FLATBUFFERS_CONSTEXPR_CPP11 Optional(nullopt_t) FLATBUFFERS_NOEXCEPT + : value_(), has_value_(false) {} + + FLATBUFFERS_CONSTEXPR_CPP11 Optional(T val) FLATBUFFERS_NOEXCEPT + : value_(val), has_value_(true) {} + + FLATBUFFERS_CONSTEXPR_CPP11 Optional(const Optional &other) FLATBUFFERS_NOEXCEPT + : value_(other.value_), has_value_(other.has_value_) {} + + FLATBUFFERS_CONSTEXPR_CPP14 Optional &operator=(const Optional &other) FLATBUFFERS_NOEXCEPT { + value_ = other.value_; + has_value_ = other.has_value_; + return *this; + } + + FLATBUFFERS_CONSTEXPR_CPP14 Optional &operator=(nullopt_t) FLATBUFFERS_NOEXCEPT { + value_ = T(); + has_value_ = false; + return *this; + } + + FLATBUFFERS_CONSTEXPR_CPP14 Optional &operator=(T val) FLATBUFFERS_NOEXCEPT { + value_ = val; + has_value_ = true; + return *this; + } + + void reset() FLATBUFFERS_NOEXCEPT { + *this = nullopt; + } + + void swap(Optional &other) FLATBUFFERS_NOEXCEPT { + std::swap(value_, other.value_); + std::swap(has_value_, other.has_value_); + } + + FLATBUFFERS_CONSTEXPR_CPP11 FLATBUFFERS_EXPLICIT_CPP11 operator bool() const FLATBUFFERS_NOEXCEPT { + return has_value_; + } + + FLATBUFFERS_CONSTEXPR_CPP11 bool has_value() const FLATBUFFERS_NOEXCEPT { + return has_value_; + } + + FLATBUFFERS_CONSTEXPR_CPP11 const T& operator*() const FLATBUFFERS_NOEXCEPT { + return value_; + } + + const T& value() const { + FLATBUFFERS_ASSERT(has_value()); + return value_; + } + + T value_or(T default_value) const FLATBUFFERS_NOEXCEPT { + return has_value() ? value_ : default_value; + } + + private: + T value_; + bool has_value_; +}; + +template +FLATBUFFERS_CONSTEXPR_CPP11 bool operator==(const Optional& opt, nullopt_t) FLATBUFFERS_NOEXCEPT { + return !opt; +} +template +FLATBUFFERS_CONSTEXPR_CPP11 bool operator==(nullopt_t, const Optional& opt) FLATBUFFERS_NOEXCEPT { + return !opt; +} + +template +FLATBUFFERS_CONSTEXPR_CPP11 bool operator==(const Optional& lhs, const U& rhs) FLATBUFFERS_NOEXCEPT { + return static_cast(lhs) && (*lhs == rhs); +} + +template +FLATBUFFERS_CONSTEXPR_CPP11 bool operator==(const T& lhs, const Optional& rhs) FLATBUFFERS_NOEXCEPT { + return static_cast(rhs) && (lhs == *rhs); +} + +template +FLATBUFFERS_CONSTEXPR_CPP11 bool operator==(const Optional& lhs, const Optional& rhs) FLATBUFFERS_NOEXCEPT { + return static_cast(lhs) != static_cast(rhs) + ? false + : !static_cast(lhs) ? false : (*lhs == *rhs); +} +#endif // FLATBUFFERS_USE_STD_OPTIONAL + +} // namespace flatbuffers + +#endif // FLATBUFFERS_STL_EMULATION_H_ diff --git a/components/tflite/third_party/flatbuffers/include/flatbuffers/util.h b/components/tflite/third_party/flatbuffers/include/flatbuffers/util.h new file mode 100644 index 00000000..f5feec4c --- /dev/null +++ b/components/tflite/third_party/flatbuffers/include/flatbuffers/util.h @@ -0,0 +1,782 @@ +/* + * Copyright 2014 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FLATBUFFERS_UTIL_H_ +#define FLATBUFFERS_UTIL_H_ + +#include + +#include "flatbuffers/base.h" +#include "flatbuffers/stl_emulation.h" + +#ifndef FLATBUFFERS_PREFER_PRINTF +#include +#else // FLATBUFFERS_PREFER_PRINTF +#include +#include +#endif // FLATBUFFERS_PREFER_PRINTF + +#include +#include + +namespace flatbuffers { +// @locale-independent functions for ASCII characters set. + +// Fast checking that character lies in closed range: [a <= x <= b] +// using one compare (conditional branch) operator. +inline bool check_ascii_range(char x, char a, char b) +{ + FLATBUFFERS_ASSERT(a <= b); + // (Hacker's Delight): `a <= x <= b` <=> `(x-a) <={u} (b-a)`. + // The x, a, b will be promoted to int and subtracted without overflow. + return static_cast(x - a) <= static_cast(b - a); +} + +// Case-insensitive isalpha +inline bool is_alpha(char c) +{ + // ASCII only: alpha to upper case => reset bit 0x20 (~0x20 = 0xDF). + return check_ascii_range(c & 0xDF, 'a' & 0xDF, 'z' & 0xDF); +} + +// Check (case-insensitive) that `c` is equal to alpha. +inline bool is_alpha_char(char c, char alpha) +{ + FLATBUFFERS_ASSERT(is_alpha(alpha)); + // ASCII only: alpha to upper case => reset bit 0x20 (~0x20 = 0xDF). + return ((c & 0xDF) == (alpha & 0xDF)); +} + +// https://en.cppreference.com/w/cpp/string/byte/isxdigit +// isdigit and isxdigit are the only standard narrow character classification +// functions that are not affected by the currently installed C locale. although +// some implementations (e.g. Microsoft in 1252 codepage) may classify +// additional single-byte characters as digits. +inline bool is_digit(char c) +{ + return check_ascii_range(c, '0', '9'); +} + +inline bool is_xdigit(char c) +{ + // Replace by look-up table. + return is_digit(c) || check_ascii_range(c & 0xDF, 'a' & 0xDF, 'f' & 0xDF); +} + +// Case-insensitive isalnum +inline bool is_alnum(char c) +{ + return is_alpha(c) || is_digit(c); +} + +inline char CharToUpper(char c) +{ + return static_cast(::toupper(static_cast(c))); +} + +inline char CharToLower(char c) +{ + return static_cast(::tolower(static_cast(c))); +} + +// @end-locale-independent functions for ASCII character set + +#ifdef FLATBUFFERS_PREFER_PRINTF +template +size_t IntToDigitCount(T t) +{ + size_t digit_count = 0; + // Count the sign for negative numbers + if (t < 0) + digit_count++; + // Count a single 0 left of the dot for fractional numbers + if (-1 < t && t < 1) + digit_count++; + // Count digits until fractional part + T eps = std::numeric_limits::epsilon(); + while (t <= (-1 + eps) || (1 - eps) <= t) { + t /= 10; + digit_count++; + } + return digit_count; +} + +template +size_t NumToStringWidth(T t, int precision = 0) +{ + size_t string_width = IntToDigitCount(t); + // Count the dot for floating point numbers + if (precision) + string_width += (precision + 1); + return string_width; +} + +template +std::string NumToStringImplWrapper(T t, const char *fmt, int precision = 0) +{ + size_t string_width = NumToStringWidth(t, precision); + std::string s(string_width, 0x00); + // Allow snprintf to use std::string trailing null to detect buffer overflow + snprintf(const_cast(s.data()), (s.size() + 1), fmt, string_width, t); + return s; +} +#endif // FLATBUFFERS_PREFER_PRINTF + +// Convert an integer or floating point value to a string. +// In contrast to std::stringstream, "char" values are +// converted to a string of digits, and we don't use scientific notation. +template +std::string NumToString(T t) +{ + // clang-format off + + #ifndef FLATBUFFERS_PREFER_PRINTF + std::stringstream ss; + ss << t; + return ss.str(); + #else // FLATBUFFERS_PREFER_PRINTF + auto v = static_cast(t); + return NumToStringImplWrapper(v, "%.*lld"); + #endif // FLATBUFFERS_PREFER_PRINTF + // clang-format on +} +// Avoid char types used as character data. +template <> +inline std::string NumToString(signed char t) +{ + return NumToString(static_cast(t)); +} +template <> +inline std::string NumToString(unsigned char t) +{ + return NumToString(static_cast(t)); +} +template <> +inline std::string NumToString(char t) +{ + return NumToString(static_cast(t)); +} +#if defined(FLATBUFFERS_CPP98_STL) +template <> +inline std::string NumToString(long long t) +{ + char buf[21]; // (log((1 << 63) - 1) / log(10)) + 2 + snprintf(buf, sizeof(buf), "%lld", t); + return std::string(buf); +} + +template <> +inline std::string NumToString(unsigned long long t) +{ + char buf[22]; // (log((1 << 63) - 1) / log(10)) + 1 + snprintf(buf, sizeof(buf), "%llu", t); + return std::string(buf); +} +#endif // defined(FLATBUFFERS_CPP98_STL) + +// Special versions for floats/doubles. +template +std::string FloatToString(T t, int precision) +{ + // clang-format off + + #ifndef FLATBUFFERS_PREFER_PRINTF + // to_string() prints different numbers of digits for floats depending on + // platform and isn't available on Android, so we use stringstream + std::stringstream ss; + // Use std::fixed to suppress scientific notation. + ss << std::fixed; + // Default precision is 6, we want that to be higher for doubles. + ss << std::setprecision(precision); + ss << t; + auto s = ss.str(); + #else // FLATBUFFERS_PREFER_PRINTF + auto v = static_cast(t); + auto s = NumToStringImplWrapper(v, "%0.*f", precision); + #endif // FLATBUFFERS_PREFER_PRINTF + // clang-format on + // Sadly, std::fixed turns "1" into "1.00000", so here we undo that. + auto p = s.find_last_not_of('0'); + if (p != std::string::npos) { + // Strip trailing zeroes. If it is a whole number, keep one zero. + s.resize(p + (s[p] == '.' ? 2 : 1)); + } + return s; +} + +template <> +inline std::string NumToString(double t) +{ + return FloatToString(t, 12); +} +template <> +inline std::string NumToString(float t) +{ + return FloatToString(t, 6); +} + +// Convert an integer value to a hexadecimal string. +// The returned string length is always xdigits long, prefixed by 0 digits. +// For example, IntToStringHex(0x23, 8) returns the string "00000023". +inline std::string IntToStringHex(int i, int xdigits) +{ + FLATBUFFERS_ASSERT(i >= 0); + // clang-format off + + #ifndef FLATBUFFERS_PREFER_PRINTF + std::stringstream ss; + ss << std::setw(xdigits) << std::setfill('0') << std::hex << std::uppercase + << i; + return ss.str(); + #else // FLATBUFFERS_PREFER_PRINTF + return NumToStringImplWrapper(i, "%.*X", xdigits); + #endif // FLATBUFFERS_PREFER_PRINTF + // clang-format on +} + +// clang-format off +// Use locale independent functions {strtod_l, strtof_l, strtoll_l, strtoull_l}. +#if defined(FLATBUFFERS_LOCALE_INDEPENDENT) && (FLATBUFFERS_LOCALE_INDEPENDENT > 0) + class ClassicLocale { + #ifdef _MSC_VER + typedef _locale_t locale_type; + #else + typedef locale_t locale_type; // POSIX.1-2008 locale_t type + #endif + ClassicLocale(); + ~ClassicLocale(); + locale_type locale_; + static ClassicLocale instance_; + public: + static locale_type Get() { return instance_.locale_; } + }; + + #ifdef _MSC_VER + #define __strtoull_impl(s, pe, b) _strtoui64_l(s, pe, b, ClassicLocale::Get()) + #define __strtoll_impl(s, pe, b) _strtoi64_l(s, pe, b, ClassicLocale::Get()) + #define __strtod_impl(s, pe) _strtod_l(s, pe, ClassicLocale::Get()) + #define __strtof_impl(s, pe) _strtof_l(s, pe, ClassicLocale::Get()) + #else + #define __strtoull_impl(s, pe, b) strtoull_l(s, pe, b, ClassicLocale::Get()) + #define __strtoll_impl(s, pe, b) strtoll_l(s, pe, b, ClassicLocale::Get()) + #define __strtod_impl(s, pe) strtod_l(s, pe, ClassicLocale::Get()) + #define __strtof_impl(s, pe) strtof_l(s, pe, ClassicLocale::Get()) + #endif +#else + #define __strtod_impl(s, pe) strtod(s, pe) + #define __strtof_impl(s, pe) static_cast(strtod(s, pe)) + #ifdef _MSC_VER + #define __strtoull_impl(s, pe, b) _strtoui64(s, pe, b) + #define __strtoll_impl(s, pe, b) _strtoi64(s, pe, b) + #else + #define __strtoull_impl(s, pe, b) strtoull(s, pe, b) + #define __strtoll_impl(s, pe, b) strtoll(s, pe, b) + #endif +#endif + +inline void strtoval_impl(int64_t *val, const char *str, char **endptr, + int base) { + *val = __strtoll_impl(str, endptr, base); +} + +inline void strtoval_impl(uint64_t *val, const char *str, char **endptr, + int base) { + *val = __strtoull_impl(str, endptr, base); +} + +inline void strtoval_impl(double *val, const char *str, char **endptr) { + *val = __strtod_impl(str, endptr); +} + +// UBSAN: double to float is safe if numeric_limits::is_iec559 is true. +__supress_ubsan__("float-cast-overflow") +inline void strtoval_impl(float *val, const char *str, char **endptr) { + *val = __strtof_impl(str, endptr); +} +#undef __strtoull_impl +#undef __strtoll_impl +#undef __strtod_impl +#undef __strtof_impl +// clang-format on + +// Adaptor for strtoull()/strtoll(). +// Flatbuffers accepts numbers with any count of leading zeros (-009 is -9), +// while strtoll with base=0 interprets first leading zero as octal prefix. +// In future, it is possible to add prefixed 0b0101. +// 1) Checks errno code for overflow condition (out of range). +// 2) If base <= 0, function try to detect base of number by prefix. +// +// Return value (like strtoull and strtoll, but reject partial result): +// - If successful, an integer value corresponding to the str is returned. +// - If full string conversion can't be performed, 0 is returned. +// - If the converted value falls out of range of corresponding return type, a +// range error occurs. In this case value MAX(T)/MIN(T) is returned. +template +inline bool StringToIntegerImpl(T *val, const char *const str, + const int base = 0, + const bool check_errno = true) +{ + // T is int64_t or uint64_T + FLATBUFFERS_ASSERT(str); + if (base <= 0) { + auto s = str; + while (*s && !is_digit(*s)) + s++; + if (s[0] == '0' && is_alpha_char(s[1], 'X')) + return StringToIntegerImpl(val, str, 16, check_errno); + // if a prefix not match, try base=10 + return StringToIntegerImpl(val, str, 10, check_errno); + } else { + if (check_errno) + errno = 0; // clear thread-local errno + auto endptr = str; + strtoval_impl(val, str, const_cast(&endptr), base); + if ((*endptr != '\0') || (endptr == str)) { + *val = 0; // erase partial result + return false; // invalid string + } + // errno is out-of-range, return MAX/MIN + if (check_errno && errno) + return false; + return true; + } +} + +template +inline bool StringToFloatImpl(T *val, const char *const str) +{ + // Type T must be either float or double. + FLATBUFFERS_ASSERT(str && val); + auto end = str; + strtoval_impl(val, str, const_cast(&end)); + auto done = (end != str) && (*end == '\0'); + if (!done) + *val = 0; // erase partial result + return done; +} + +// Convert a string to an instance of T. +// Return value (matched with StringToInteger64Impl and strtod): +// - If successful, a numeric value corresponding to the str is returned. +// - If full string conversion can't be performed, 0 is returned. +// - If the converted value falls out of range of corresponding return type, a +// range error occurs. In this case value MAX(T)/MIN(T) is returned. +template +inline bool StringToNumber(const char *s, T *val) +{ + FLATBUFFERS_ASSERT(s && val); + int64_t i64; + // The errno check isn't needed, will return MAX/MIN on overflow. + if (StringToIntegerImpl(&i64, s, 0, false)) { + const int64_t max = (flatbuffers::numeric_limits::max)(); + const int64_t min = flatbuffers::numeric_limits::lowest(); + if (i64 > max) { + *val = static_cast(max); + return false; + } + if (i64 < min) { + // For unsigned types return max to distinguish from + // "no conversion can be performed" when 0 is returned. + *val = static_cast(flatbuffers::is_unsigned::value ? max : min); + return false; + } + *val = static_cast(i64); + return true; + } + *val = 0; + return false; +} + +template <> +inline bool StringToNumber(const char *str, int64_t *val) +{ + return StringToIntegerImpl(val, str); +} + +template <> +inline bool StringToNumber(const char *str, uint64_t *val) +{ + if (!StringToIntegerImpl(val, str)) + return false; + // The strtoull accepts negative numbers: + // If the minus sign was part of the input sequence, the numeric value + // calculated from the sequence of digits is negated as if by unary minus + // in the result type, which applies unsigned integer wraparound rules. + // Fix this behaviour (except -0). + if (*val) { + auto s = str; + while (*s && !is_digit(*s)) + s++; + s = (s > str) ? (s - 1) : s; // step back to one symbol + if (*s == '-') { + // For unsigned types return the max to distinguish from + // "no conversion can be performed". + *val = (flatbuffers::numeric_limits::max)(); + return false; + } + } + return true; +} + +template <> +inline bool StringToNumber(const char *s, float *val) +{ + return StringToFloatImpl(val, s); +} + +template <> +inline bool StringToNumber(const char *s, double *val) +{ + return StringToFloatImpl(val, s); +} + +inline int64_t StringToInt(const char *s, int base = 10) +{ + int64_t val; + return StringToIntegerImpl(&val, s, base) ? val : 0; +} + +inline uint64_t StringToUInt(const char *s, int base = 10) +{ + uint64_t val; + return StringToIntegerImpl(&val, s, base) ? val : 0; +} + +typedef bool (*LoadFileFunction)(const char *filename, bool binary, + std::string *dest); +typedef bool (*FileExistsFunction)(const char *filename); + +LoadFileFunction SetLoadFileFunction(LoadFileFunction load_file_function); + +FileExistsFunction SetFileExistsFunction( + FileExistsFunction file_exists_function); + +// Check if file "name" exists. +bool FileExists(const char *name); + +// Check if "name" exists and it is also a directory. +bool DirExists(const char *name); + +// Load file "name" into "buf" returning true if successful +// false otherwise. If "binary" is false data is read +// using ifstream's text mode, otherwise data is read with +// no transcoding. +bool LoadFile(const char *name, bool binary, std::string *buf); + +// Save data "buf" of length "len" bytes into a file +// "name" returning true if successful, false otherwise. +// If "binary" is false data is written using ifstream's +// text mode, otherwise data is written with no +// transcoding. +bool SaveFile(const char *name, const char *buf, size_t len, bool binary); + +// Save data "buf" into file "name" returning true if +// successful, false otherwise. If "binary" is false +// data is written using ifstream's text mode, otherwise +// data is written with no transcoding. +inline bool SaveFile(const char *name, const std::string &buf, bool binary) +{ + return SaveFile(name, buf.c_str(), buf.size(), binary); +} + +// Functionality for minimalistic portable path handling. + +// The functions below behave correctly regardless of whether posix ('/') or +// Windows ('/' or '\\') separators are used. + +// Any new separators inserted are always posix. +FLATBUFFERS_CONSTEXPR char kPathSeparator = '/'; + +// Returns the path with the extension, if any, removed. +std::string StripExtension(const std::string &filepath); + +// Returns the extension, if any. +std::string GetExtension(const std::string &filepath); + +// Return the last component of the path, after the last separator. +std::string StripPath(const std::string &filepath); + +// Strip the last component of the path + separator. +std::string StripFileName(const std::string &filepath); + +// Concatenates a path with a filename, regardless of whether the path +// ends in a separator or not. +std::string ConCatPathFileName(const std::string &path, + const std::string &filename); + +// Replaces any '\\' separators with '/' +std::string PosixPath(const char *path); + +// This function ensure a directory exists, by recursively +// creating dirs for any parts of the path that don't exist yet. +void EnsureDirExists(const std::string &filepath); + +// Obtains the absolute path from any other path. +// Returns the input path if the absolute path couldn't be resolved. +std::string AbsolutePath(const std::string &filepath); + +// To and from UTF-8 unicode conversion functions + +// Convert a unicode code point into a UTF-8 representation by appending it +// to a string. Returns the number of bytes generated. +inline int ToUTF8(uint32_t ucc, std::string *out) +{ + FLATBUFFERS_ASSERT(!(ucc & 0x80000000)); // Top bit can't be set. + // 6 possible encodings: http://en.wikipedia.org/wiki/UTF-8 + for (int i = 0; i < 6; i++) { + // Max bits this encoding can represent. + uint32_t max_bits = 6 + i * 5 + static_cast(!i); + if (ucc < (1u << max_bits)) { // does it fit? + // Remaining bits not encoded in the first byte, store 6 bits each + uint32_t remain_bits = i * 6; + // Store first byte: + (*out) += static_cast((0xFE << (max_bits - remain_bits)) | + (ucc >> remain_bits)); + // Store remaining bytes: + for (int j = i - 1; j >= 0; j--) { + (*out) += static_cast(((ucc >> (j * 6)) & 0x3F) | 0x80); + } + return i + 1; // Return the number of bytes added. + } + } + FLATBUFFERS_ASSERT(0); // Impossible to arrive here. + return -1; +} + +// Converts whatever prefix of the incoming string corresponds to a valid +// UTF-8 sequence into a unicode code. The incoming pointer will have been +// advanced past all bytes parsed. +// returns -1 upon corrupt UTF-8 encoding (ignore the incoming pointer in +// this case). +inline int FromUTF8(const char **in) +{ + int len = 0; + // Count leading 1 bits. + for (int mask = 0x80; mask >= 0x04; mask >>= 1) { + if (**in & mask) { + len++; + } else { + break; + } + } + if ((static_cast(**in) << len) & 0x80) + return -1; // Bit after leading 1's must be 0. + if (!len) + return *(*in)++; + // UTF-8 encoded values with a length are between 2 and 4 bytes. + if (len < 2 || len > 4) { + return -1; + } + // Grab initial bits of the code. + int ucc = *(*in)++ & ((1 << (7 - len)) - 1); + for (int i = 0; i < len - 1; i++) { + if ((**in & 0xC0) != 0x80) + return -1; // Upper bits must 1 0. + ucc <<= 6; + ucc |= *(*in)++ & 0x3F; // Grab 6 more bits of the code. + } + // UTF-8 cannot encode values between 0xD800 and 0xDFFF (reserved for + // UTF-16 surrogate pairs). + if (ucc >= 0xD800 && ucc <= 0xDFFF) { + return -1; + } + // UTF-8 must represent code points in their shortest possible encoding. + switch (len) { + case 2: + // Two bytes of UTF-8 can represent code points from U+0080 to U+07FF. + if (ucc < 0x0080 || ucc > 0x07FF) { + return -1; + } + break; + case 3: + // Three bytes of UTF-8 can represent code points from U+0800 to U+FFFF. + if (ucc < 0x0800 || ucc > 0xFFFF) { + return -1; + } + break; + case 4: + // Four bytes of UTF-8 can represent code points from U+10000 to U+10FFFF. + if (ucc < 0x10000 || ucc > 0x10FFFF) { + return -1; + } + break; + } + return ucc; +} + +#ifndef FLATBUFFERS_PREFER_PRINTF +// Wraps a string to a maximum length, inserting new lines where necessary. Any +// existing whitespace will be collapsed down to a single space. A prefix or +// suffix can be provided, which will be inserted before or after a wrapped +// line, respectively. +inline std::string WordWrap(const std::string in, size_t max_length, + const std::string wrapped_line_prefix, + const std::string wrapped_line_suffix) +{ + std::istringstream in_stream(in); + std::string wrapped, line, word; + + in_stream >> word; + line = word; + + while (in_stream >> word) { + if ((line.length() + 1 + word.length() + wrapped_line_suffix.length()) < + max_length) { + line += " " + word; + } else { + wrapped += line + wrapped_line_suffix + "\n"; + line = wrapped_line_prefix + word; + } + } + wrapped += line; + + return wrapped; +} +#endif // !FLATBUFFERS_PREFER_PRINTF + +inline bool EscapeString(const char *s, size_t length, std::string *_text, + bool allow_non_utf8, bool natural_utf8) +{ + std::string &text = *_text; + text += "\""; + for (uoffset_t i = 0; i < length; i++) { + char c = s[i]; + switch (c) { + case '\n': + text += "\\n"; + break; + case '\t': + text += "\\t"; + break; + case '\r': + text += "\\r"; + break; + case '\b': + text += "\\b"; + break; + case '\f': + text += "\\f"; + break; + case '\"': + text += "\\\""; + break; + case '\\': + text += "\\\\"; + break; + default: + if (c >= ' ' && c <= '~') { + text += c; + } else { + // Not printable ASCII data. Let's see if it's valid UTF-8 first: + const char *utf8 = s + i; + int ucc = FromUTF8(&utf8); + if (ucc < 0) { + if (allow_non_utf8) { + text += "\\x"; + text += IntToStringHex(static_cast(c), 2); + } else { + // There are two cases here: + // + // 1) We reached here by parsing an IDL file. In that case, + // we previously checked for non-UTF-8, so we shouldn't reach + // here. + // + // 2) We reached here by someone calling GenerateText() + // on a previously-serialized flatbuffer. The data might have + // non-UTF-8 Strings, or might be corrupt. + // + // In both cases, we have to give up and inform the caller + // they have no JSON. + return false; + } + } else { + if (natural_utf8) { + // utf8 points to past all utf-8 bytes parsed + text.append(s + i, static_cast(utf8 - s - i)); + } else if (ucc <= 0xFFFF) { + // Parses as Unicode within JSON's \uXXXX range, so use that. + text += "\\u"; + text += IntToStringHex(ucc, 4); + } else if (ucc <= 0x10FFFF) { + // Encode Unicode SMP values to a surrogate pair using two \u + // escapes. + uint32_t base = ucc - 0x10000; + auto high_surrogate = (base >> 10) + 0xD800; + auto low_surrogate = (base & 0x03FF) + 0xDC00; + text += "\\u"; + text += IntToStringHex(high_surrogate, 4); + text += "\\u"; + text += IntToStringHex(low_surrogate, 4); + } + // Skip past characters recognized. + i = static_cast(utf8 - s - 1); + } + } + break; + } + } + text += "\""; + return true; +} + +inline std::string BufferToHexText(const void *buffer, size_t buffer_size, + size_t max_length, + const std::string &wrapped_line_prefix, + const std::string &wrapped_line_suffix) +{ + std::string text = wrapped_line_prefix; + size_t start_offset = 0; + const char *s = reinterpret_cast(buffer); + for (size_t i = 0; s && i < buffer_size; i++) { + // Last iteration or do we have more? + bool have_more = i + 1 < buffer_size; + text += "0x"; + text += IntToStringHex(static_cast(s[i]), 2); + if (have_more) { + text += ','; + } + // If we have more to process and we reached max_length + if (have_more && + text.size() + wrapped_line_suffix.size() >= start_offset + max_length) { + text += wrapped_line_suffix; + text += '\n'; + start_offset = text.size(); + text += wrapped_line_prefix; + } + } + text += wrapped_line_suffix; + return text; +} + +// Remove paired quotes in a string: "text"|'text' -> text. +std::string RemoveStringQuotes(const std::string &s); + +// Change th global C-locale to locale with name . +// Returns an actual locale name in <_value>, useful if locale_name is "" or +// null. +bool SetGlobalTestLocale(const char *locale_name, + std::string *_value = nullptr); + +// Read (or test) a value of environment variable. +bool ReadEnvironmentVariable(const char *var_name, + std::string *_value = nullptr); + +// MSVC specific: Send all assert reports to STDOUT to prevent CI hangs. +void SetupDefaultCRTReportMode(); + +} // namespace flatbuffers + +#endif // FLATBUFFERS_UTIL_H_ diff --git a/components/tflite/third_party/gemmlowp/fixedpoint/fixedpoint.h b/components/tflite/third_party/gemmlowp/fixedpoint/fixedpoint.h new file mode 100644 index 00000000..1fa1654a --- /dev/null +++ b/components/tflite/third_party/gemmlowp/fixedpoint/fixedpoint.h @@ -0,0 +1,983 @@ +// Copyright 2015 The Gemmlowp Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// fixedpoint.h: fixed-point arithmetic, with basic operations and +// a few math functions such as tanh. + +#ifndef GEMMLOWP_INTERNAL_FIXEDPOINT_H_ +#define GEMMLOWP_INTERNAL_FIXEDPOINT_H_ + +#include +#include +#include +#include +#include + +#include "../internal/detect_platform.h" + +namespace gemmlowp { +// Part 1: Low-level integer-arithmetic primitives. +// The implementations here are generic implementations valid for +// scalar types (e.g. std::int32_t). Architecture-specific SIMD types +// (e.g. NEON int32x4_t) may be supported by providing +// specializations for them in separate files. +// +// The purpose of these primitives is two-fold: +// - They will be used to implement higher-level fixed-point +// abstractions, namely the FixedPoint class and its arithmetic +// operators. +// - They will be directly used to implement some more involved +// fixed-point computations, e.g. the fixed-point implementation +// of math functions such as tanh. + +// Some compile-time traits around raw types to handle SIMD aspects: +// number of lanes, underlying scalar type. +template +struct FixedPointRawTypeTraits { +}; + +template <> +struct FixedPointRawTypeTraits { + typedef std::int32_t ScalarRawType; + static constexpr int kLanes = 1; +}; + +template <> +struct FixedPointRawTypeTraits { + typedef std::int16_t ScalarRawType; + static constexpr int kLanes = 1; +}; + +// Returns a SIMD value duplicating a scalar value across all lanes. +template +tRawType Dup(typename FixedPointRawTypeTraits::ScalarRawType x) +{ + return x; +} + +// Plain bit-wise AND +template +tIntegerType BitAnd(tIntegerType a, tIntegerType b) +{ + return a & b; +} + +// Plain bit-wise OR +template +tIntegerType BitOr(tIntegerType a, tIntegerType b) +{ + return a | b; +} + +// Plain bit-wise XOR +template +tIntegerType BitXor(tIntegerType a, tIntegerType b) +{ + return a ^ b; +} + +// Plain bit-wise NOT +template +tIntegerType BitNot(tIntegerType a) +{ + return ~a; +} + +// Integer addition. Not saturating. Overflow is undefined behavior. +template +tIntegerType Add(tIntegerType a, tIntegerType b) +{ + return a + b; +} + +// Integer subtraction. Not saturating. Overflow is undefined behavior. +template +tIntegerType Mul(tIntegerType a, tIntegerType b) +{ + return a * b; +} + +template +tIntegerType Sub(tIntegerType a, tIntegerType b) +{ + return a - b; +} + +// Integer unary negative. Not saturating. Overflow is undefined behavior. +template +tIntegerType Neg(tIntegerType a) +{ + return -a; +} + +// Integer arithmetic left-shift, equivalent to multiplying with a power of two. +// Negative values are OK. In case of overflow, no Undefined +// Behavior, but the results are implementation-defined (in practice, +// they currently are saturated, but we make no commitment to that). The idea +// is that the caller will want to implement the overflowing cases with +// saturation with compare-and-mask, so we don't care about the results +// in the overflow case, we just want to avoid undefined behavior. +// +// tIntegerType may be int32 or any narrower signed type. +template +tIntegerType ShiftLeft(tIntegerType a, int offset) +{ + const std::int64_t wide_a = static_cast(a); + const std::int64_t wide_shifted = wide_a * (1 << offset); + const auto min = std::numeric_limits::min(); + const auto max = std::numeric_limits::max(); + return wide_shifted < min ? min : wide_shifted > max ? max : + static_cast(wide_shifted); +} + +// Integer arithmetic right-shift. Not rounding. +// Relying on implementation-defined, but in-practice-consistent, +// C++ compiler behavior. +template +tIntegerType ShiftRight(tIntegerType a, int offset) +{ + return a >> offset; +} + +// Each bit of the result is set to the corresponding bit of either then_val or +// else_val depending on whether the corresponding bit of if_mask is set. +// Equivalent to the VBSL instruction in ARM NEON. +template +tIntegerType SelectUsingMask(tIntegerType if_mask, tIntegerType then_val, + tIntegerType else_val) +{ + return BitXor(BitAnd(if_mask, then_val), BitAnd(BitNot(if_mask), else_val)); +} + +// For each input scalar, the corresponding bits of the result are set if the +// input scalar is non-zero. +template +tIntegerType MaskIfNonZero(tIntegerType a) +{ + static constexpr tIntegerType zero = 0; + return a ? BitNot(zero) : zero; +} + +// For each input scalar, the corresponding bits of the result are set if the +// input scalar is zero. +template +tIntegerType MaskIfZero(tIntegerType a) +{ + return MaskIfNonZero(!a); +} + +// For each pair of input scalars, the corresponding bits of the result are +// set if the input scalars are equal. +template +tIntegerType MaskIfEqual(tIntegerType a, tIntegerType b) +{ + return MaskIfNonZero(a == b); +} + +// For each pair of input scalars, the corresponding bits of the result are +// set if the input scalars are not equal. +template +tIntegerType MaskIfNotEqual(tIntegerType a, tIntegerType b) +{ + return MaskIfNonZero(a != b); +} + +// For each pair of input scalars, the corresponding bits of the result are +// set if the input scalars a, b satisfy a > b. +template +tIntegerType MaskIfGreaterThan(tIntegerType a, tIntegerType b) +{ + return MaskIfNonZero(a > b); +} + +// For each pair of input scalars, the corresponding bits of the result are +// set if the input scalars a, b satisfy a >= b. +template +tIntegerType MaskIfGreaterThanOrEqual(tIntegerType a, tIntegerType b) +{ + return MaskIfNonZero(a >= b); +} + +// For each pair of input scalars, the corresponding bits of the result are +// set if the input scalars a, b satisfy a < b. +template +tIntegerType MaskIfLessThan(tIntegerType a, tIntegerType b) +{ + return MaskIfNonZero(a < b); +} + +// For each pair of input scalars, the corresponding bits of the result are +// set if the input scalars a, b satisfy a <= b. +template +tIntegerType MaskIfLessThanOrEqual(tIntegerType a, tIntegerType b) +{ + return MaskIfNonZero(a <= b); +} + +// Returns true if all of the input scalars are nonzero. +// This function may currently assume that each of the input scalars has either +// all or none of its bits set. Otherwise, its behavior is currently undefined. +template +bool All(tIntegerType a) +{ + return a; +} + +// Returns true if any of the input scalars are nonzero. +// This function may currently assume that each of the input scalars has either +// all or none of its bits set. Otherwise, its behavior is currently undefined. +template +bool Any(tIntegerType a) +{ + return a; +} + +// Returns (a+b)/2, rounded to the nearest integer. +// Equivalent to VRHADD in the ARM NEON instruction set. +template +IntegerType RoundingHalfSum(IntegerType a, IntegerType b) +{ + static_assert(std::is_same::value, "unimplemented"); + (void)b; + return a; +} + +template <> +inline std::int32_t RoundingHalfSum(std::int32_t a, std::int32_t b) +{ + std::int64_t a64 = a; + std::int64_t b64 = b; + std::int64_t sum = a64 + b64; + std::int64_t sign = sum >= 0 ? 1 : -1; + return static_cast((sum + sign) / 2); +} + +template <> +inline std::int16_t RoundingHalfSum(std::int16_t a, std::int16_t b) +{ + std::int32_t a32 = a; + std::int32_t b32 = b; + std::int32_t sum = a32 + b32; + std::int32_t sign = sum >= 0 ? 1 : -1; + return static_cast((sum + sign) / 2); +} + +template +IntegerType SaturatingAdd(IntegerType a, IntegerType b) +{ + static_assert(std::is_same::value, "unimplemented"); + (void)b; + return a; +} + +// So far this is only needed for int16. +template <> +inline std::int16_t SaturatingAdd(std::int16_t a, std::int16_t b) +{ + std::int32_t a32 = a; + std::int32_t b32 = b; + std::int32_t sum = a32 + b32; + return static_cast( + std::min(static_cast(32767), + std::max(static_cast(-32768), sum))); +} + +// Returns a+b, saturating if the integers are 16bit or narrower, +// otherwise just a plain addition. +template +struct AddSaturatingIf16BitImpl { + static IntegerType Run(IntegerType a, IntegerType b) + { + return Add(a, b); + } +}; +template +struct AddSaturatingIf16BitImpl { + static IntegerType Run(IntegerType a, IntegerType b) + { + return SaturatingAdd(a, b); + } +}; +template +IntegerType AddSaturatingIf16Bit(IntegerType a, IntegerType b) +{ + using ScalarType = + typename FixedPointRawTypeTraits::ScalarRawType; + return AddSaturatingIf16BitImpl::Run(a, + b); +} + +// Returns the integer that represents the product of two fixed-point +// numbers, interpreting all integers as fixed-point values in the +// interval [-1, 1), rounding to the nearest value, and saturating +// -1 * -1 to the maximum value (since 1 is not in the half-open +// interval [-1, 1)). +// +// [The explanation below specializes to std::int32_t for example purpose.] +// +// The mapping between IntegerType and the interval [-1, 1) is unique and +// implied by IntegerType, which is assumed to be signed. For example, +// for IntegerType==std::int32_t, the mapping is +// real_value = integer_value / 2^31. +// So in this case, and leaving aside rounding and saturating, this +// function computes ((a / 2^31) * (b / 2^31)) * 2^31, which simplifies to +// (a * b) / 2^31. +// +// The 'doubling' part in the name of this function comes from the fact that +// this operation is very close to a "multiply-high" operation, keeping only +// the top half bits, except that that would be effectively computing +// (a * b) / 2^32, +// so here we are computing 2x that, since +// 1/2^31 = 2 * 1/2^32. +// The idea is to use all of the available 32 bits in the destination int32 +// value. +// +// [End of the explanation specializing to int32.] +// +// This is equivalent to the VQRDMULH instruction in ARM NEON. +template +IntegerType SaturatingRoundingDoublingHighMul(IntegerType a, IntegerType b) +{ + static_assert(std::is_same::value, "unimplemented"); + (void)b; + return a; +} + +// This function implements the same computation as the ARMv7 NEON VQRDMULH +// instruction. +template <> +inline std::int32_t SaturatingRoundingDoublingHighMul(std::int32_t a, + std::int32_t b) +{ + bool overflow = a == b && a == std::numeric_limits::min(); + std::int64_t a_64(a); + std::int64_t b_64(b); + std::int64_t ab_64 = a_64 * b_64; + std::int32_t nudge = ab_64 >= 0 ? (1 << 30) : (1 - (1 << 30)); + std::int32_t ab_x2_high32 = + static_cast((ab_64 + nudge) / (1ll << 31)); + return overflow ? std::numeric_limits::max() : ab_x2_high32; +} + +template <> +inline std::int16_t SaturatingRoundingDoublingHighMul(std::int16_t a, + std::int16_t b) +{ + bool overflow = a == b && a == std::numeric_limits::min(); + std::int32_t a_32(a); + std::int32_t b_32(b); + std::int32_t ab_32 = a_32 * b_32; + std::int16_t nudge = ab_32 >= 0 ? (1 << 14) : (1 - (1 << 14)); + std::int16_t ab_x2_high16 = + static_cast((ab_32 + nudge) / (1 << 15)); + return overflow ? std::numeric_limits::max() : ab_x2_high16; +} + +// Correctly-rounded-to-nearest division by a power-of-two. +// Also known as a rounding arithmetic right shift. +template +inline IntegerType RoundingDivideByPOT(IntegerType x, int exponent) +{ + assert(exponent >= 0); + assert(exponent <= 31); + const IntegerType mask = Dup((1ll << exponent) - 1); + const IntegerType zero = Dup(0); + const IntegerType one = Dup(1); + const IntegerType remainder = BitAnd(x, mask); + const IntegerType threshold = + Add(ShiftRight(mask, 1), BitAnd(MaskIfLessThan(x, zero), one)); + return Add(ShiftRight(x, exponent), + BitAnd(MaskIfGreaterThan(remainder, threshold), one)); +} + +// Returns the product of a run-time integer value by a compile-time power +// of two, with either a positive exponent (equivalent to an arithmetic +// left shift, saturating) or a negative exponent (equivalent to an arithmetic +// right shift, rounding to nearest). +template 0 ? 1 : Exponent < 0 ? -1 : + 0)> +struct ImplSaturatingRoundingMultiplyByPOT { +}; + +template +struct ImplSaturatingRoundingMultiplyByPOT { + static IntegerType eval(IntegerType x) + { + return x; + } +}; + +template +struct ImplSaturatingRoundingMultiplyByPOT { + static IntegerType eval(IntegerType x) + { + using ScalarIntegerType = + typename FixedPointRawTypeTraits::ScalarRawType; + const IntegerType min = + Dup(std::numeric_limits::min()); + const IntegerType max = + Dup(std::numeric_limits::max()); + const int ScalarIntegerTypeBits = 8 * sizeof(ScalarIntegerType); + + const std::int32_t threshold = + ((1 << (ScalarIntegerTypeBits - 1 - Exponent)) - 1); + const IntegerType positive_mask = + MaskIfGreaterThan(x, Dup(threshold)); + const IntegerType negative_mask = + MaskIfLessThan(x, Dup(-threshold)); + + IntegerType result = ShiftLeft(x, Exponent); + result = SelectUsingMask(positive_mask, max, result); + result = SelectUsingMask(negative_mask, min, result); + return result; + } +}; + +template +struct ImplSaturatingRoundingMultiplyByPOT { + static IntegerType eval(IntegerType x) + { + return RoundingDivideByPOT(x, -Exponent); + } +}; + +template +IntegerType SaturatingRoundingMultiplyByPOT(IntegerType x) +{ + return ImplSaturatingRoundingMultiplyByPOT::eval(x); +} + +// Part 2: the FixedPoint class. + +// A FixedPoint object represents a fixed-point value stored in the underlying +// integer type tRawType, if tRawType is a plain scalar integer type. +// Alternatively, tRawType may be a SIMD type (e.g. NEON int32x4_t) in which +// case a FixedPoint object represents a corresponding SIMD vector of fixed +// point values. +// +// tIntegerBits describes the range of the fixed-point format: if +// tIntegerBits == m then the range of representable values is the half-open +// interval [-2^m; 2^m) where the open boundary on the right side means that +// 2^m is not representable (how close the maximum representable value is to +// it, depends on bit-depth of tRawType). +// +// In "Q format notation", +// https://en.wikipedia.org/wiki/Q_(number_format) +// we are describing the format +// Qm.n +// where +// m = tIntegerBits +// and +// n = NumberOfBits(tRawType) - (m + 1) +// Note that the (m + 1) in the above line is because we adopt the convention +// that we count the integer bits exclusively of the sign bit; so (m + 1) is +// the total number of integer bits inclusive of the sign bit. +// +// Accordingly, the number of integral representable values in our range +// [-2^m ; 2^m) +// is equal to 2^(m+1). +template +class FixedPoint { +public: + typedef tRawType RawType; + + typedef FixedPointRawTypeTraits RawTypeTraits; + typedef typename RawTypeTraits::ScalarRawType ScalarRawType; + + static constexpr int kTotalBits = 8 * sizeof(ScalarRawType); + static constexpr int kIntegerBits = tIntegerBits; + static constexpr int kFractionalBits = kTotalBits - 1 - kIntegerBits; + static_assert(kIntegerBits >= 0 && kIntegerBits < kTotalBits, + "bad IntegerBits"); + + typedef FixedPoint ScalarFixedPointType; + + static const ScalarRawType ScalarRawMin() + { + return std::numeric_limits::min(); + } + + static const ScalarRawType ScalarRawMax() + { + return std::numeric_limits::max(); + } + + static const ScalarRawType RawMin() + { + return VectorFromScalar(ScalarRawMin()); + } + + static const ScalarRawType RawMax() + { + return VectorFromScalar(ScalarRawMax()); + } + + static FixedPoint FromRaw(RawType x) + { + FixedPoint retval; + retval.raw() = x; + return retval; + } + + static FixedPoint FromScalarRaw(ScalarRawType x) + { + FixedPoint retval; + retval.raw() = Dup(x); + return retval; + } + + static FixedPoint FromScalarFixedPoint(ScalarFixedPointType x) + { + return FromScalarRaw(x.raw()); + } + + template + static FixedPoint ConstantPOT() + { + static constexpr int kOffset = kFractionalBits + Exponent; + static_assert( + kOffset < 31, + "Constant not exactly representable in this fixed-point format"); + return FromScalarRaw(ScalarRawType(1) << kOffset); + } + + static FixedPoint Zero() + { + return FromScalarRaw(0); + } + + static FixedPoint One() + { + return FromScalarRaw( + kIntegerBits == 0 ? ScalarRawMax() : (ScalarRawType(1) << (kIntegerBits == 0 ? 0 : kFractionalBits))); + } + + static FixedPoint FromDouble(double x) + { + const double min_bound = static_cast(ScalarRawMin()); + const double max_bound = static_cast(ScalarRawMax()); + return FromScalarRaw(static_cast(std::min( + std::max(round(x * static_cast(1ll << kFractionalBits)), + min_bound), + max_bound))); + } + + RawType raw() const + { + return i_; + } + RawType &raw() + { + return i_; + } + +private: + RawType i_; +}; + +// Part 3: implementation of arithmetic operators for the +// FixedPoint class, and a few related functions. + +// A FixedPoint multiplication is just a +// SaturatingRoundingDoublingHighMul operation on the underlying +// raw integer values. The IntegerBits simply add up, as is obvious +// from the fact that the range is [-2^IntegerBits, 2^IntegerBits). +template +FixedPoint operator*( + FixedPoint a, + FixedPoint b) +{ + FixedPoint c; + c.raw() = SaturatingRoundingDoublingHighMul(a.raw(), b.raw()); + return c; +} + +// Tweaking IntegerBits gives exact multiplication by a power of two. +template +FixedPoint ExactMulByPot( + FixedPoint a) +{ + FixedPoint c; + c.raw() = a.raw(); + return c; +} + +// If we want to leave IntegerBits fixed, then multiplication +// by a power of two has to be saturating/rounding, not exact anymore. +template +FixedPoint SaturatingRoundingMultiplyByPOT( + FixedPoint a) +{ + return FixedPoint::FromRaw( + SaturatingRoundingMultiplyByPOT(a.raw())); +} + +// Generic arithmetic operators. + +#define MAKE_FIXEDPOINT_UNARY_FUNC(FuncName, ImplFuncName) \ + template \ + FixedPoint FuncName( \ + FixedPoint a) \ + { \ + return FixedPoint::FromRaw(ImplFuncName(a.raw())); \ + } + +#define MAKE_FIXEDPOINT_BINARY_FUNC(FuncName, ImplFuncName) \ + template \ + FixedPoint FuncName( \ + FixedPoint a, \ + FixedPoint b) \ + { \ + return FixedPoint::FromRaw( \ + ImplFuncName(a.raw(), b.raw())); \ + } + +MAKE_FIXEDPOINT_UNARY_FUNC(operator-, Neg) +MAKE_FIXEDPOINT_UNARY_FUNC(operator~, BitNot) +MAKE_FIXEDPOINT_BINARY_FUNC(operator+, Add) +MAKE_FIXEDPOINT_BINARY_FUNC(operator-, Sub) +MAKE_FIXEDPOINT_BINARY_FUNC(operator&, BitAnd) +MAKE_FIXEDPOINT_BINARY_FUNC(operator^, BitXor) +MAKE_FIXEDPOINT_BINARY_FUNC(operator|, BitOr) +MAKE_FIXEDPOINT_BINARY_FUNC(RoundingHalfSum, RoundingHalfSum) + +#undef MAKE_FIXEDPOINT_UNARY_FUNC +#undef MAKE_FIXEDPOINT_BINARY_FUNC + +#define MAKE_FIXEDPOINT_UNARY_FUNC_RETURNING_RAW(FuncName) \ + template \ + tRawType FuncName(FixedPoint a) \ + { \ + return FuncName(a.raw()); \ + } + +#define MAKE_FIXEDPOINT_BINARY_FUNC_RETURNING_RAW(FuncName) \ + template \ + tRawType FuncName(FixedPoint a, \ + FixedPoint b) \ + { \ + return FuncName(a.raw(), b.raw()); \ + } + +MAKE_FIXEDPOINT_UNARY_FUNC_RETURNING_RAW(MaskIfZero) +MAKE_FIXEDPOINT_UNARY_FUNC_RETURNING_RAW(MaskIfNonZero) +MAKE_FIXEDPOINT_BINARY_FUNC_RETURNING_RAW(MaskIfEqual) +MAKE_FIXEDPOINT_BINARY_FUNC_RETURNING_RAW(MaskIfNotEqual) +MAKE_FIXEDPOINT_BINARY_FUNC_RETURNING_RAW(MaskIfGreaterThan) +MAKE_FIXEDPOINT_BINARY_FUNC_RETURNING_RAW(MaskIfGreaterThanOrEqual) +MAKE_FIXEDPOINT_BINARY_FUNC_RETURNING_RAW(MaskIfLessThan) +MAKE_FIXEDPOINT_BINARY_FUNC_RETURNING_RAW(MaskIfLessThanOrEqual) + +#undef MAKE_FIXEDPOINT_UNARY_FUNC_RETURNING_RAW +#undef MAKE_FIXEDPOINT_BINARY_FUNC_RETURNING_RAW + +template +FixedPoint SelectUsingMask( + tRawType if_mask, FixedPoint then_val, + FixedPoint else_val) +{ + return FixedPoint::FromRaw( + SelectUsingMask(if_mask, then_val.raw(), else_val.raw())); +} + +template +bool operator==(FixedPoint a, + FixedPoint b) +{ + return All(MaskIfEqual(a.raw(), b.raw())); +} + +template +bool operator!=(FixedPoint a, + FixedPoint b) +{ + return !(a == b); +} + +template +FixedPoint SaturatingAdd( + FixedPoint a, + FixedPoint b) +{ + return FixedPoint::FromRaw( + SaturatingAdd(a.raw(), b.raw())); +} + +template +FixedPoint AddSaturatingIf16Bit( + FixedPoint a, + FixedPoint b) +{ + return FixedPoint::FromRaw( + AddSaturatingIf16Bit(a.raw(), b.raw())); +} + +// Conversion to floating-point. +template +double ToDouble(FixedPoint x) +{ + static_assert(FixedPointRawTypeTraits::kLanes == 1, + "not applicable to SIMD types"); + typedef FixedPoint F; + return x.raw() / static_cast(1ll << F::kFractionalBits); +} + +// Rescale changes the number of IntegerBits and updates the underlying +// raw integer value accordingly. +template +FixedPoint Rescale( + FixedPoint x) +{ + static constexpr int kExponent = tIntegerBitsSrc - tIntegerBitsDst; + FixedPoint result; + result.raw() = SaturatingRoundingMultiplyByPOT(x.raw()); + return result; +} + +// CheckedFixedPointConstant allows to specify fixed-point constants +// initialized as real numbers, in a way that does not compile floating-point +// arithmetic in production code, yet still checks agreement with the +// floating-point expressions when asserts are enabled. +// +// The raw integer value provided is always a int32, encoding a 32-bit +// fixed-point value, regardless of the actual Scalar type. This allows +// writing generic code that applies just as well to the 32-bit and 16-bit +// cases. In the 16-bit case, the raw integer value is internally +// rounding-shifted by 16 bits to the right. +template +inline typename FixedPointType::ScalarRawType RescaleConstantInitializer( + std::int32_t int32_value) +{ + typedef typename FixedPointType::ScalarRawType ScalarRawType; + static constexpr int ScalarTypeBits = 8 * sizeof(ScalarRawType); + return static_cast( + RoundingDivideByPOT(int32_value, 32 - ScalarTypeBits)); +} +#ifdef GEMMLOWP_ENABLE_FIXEDPOINT_CONSTANTS_CHECKS +template +FixedPointType CheckedFixedPointConstant(std::int32_t raw_value, + double double_value) +{ + const FixedPointType result = FixedPointType::FromScalarRaw(raw_value); + assert(result == FixedPointType::FromDouble(double_value)); + return result; +} +#define GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(FixedPointType, \ + ScalarRawInt32Value, DoubleValue) \ + (gemmlowp::CheckedFixedPointConstant( \ + gemmlowp::RescaleConstantInitializer( \ + ScalarRawInt32Value), \ + DoubleValue)) + +#else +#define GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(FixedPointType, \ + ScalarRawInt32Value, DoubleValue) \ + (FixedPointType::FromScalarRaw( \ + gemmlowp::RescaleConstantInitializer( \ + ScalarRawInt32Value))) +#endif + +// Implementation of exponential function. + +// Returns exp(x) for x in [-1/4, 0). +template +FixedPoint exp_on_interval_between_negative_one_quarter_and_0_excl( + FixedPoint a) +{ + typedef FixedPoint F; + const F constant_term = + GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(F, 1895147668, std::exp(-1.0 / 8.0)); + const F constant_1_over_3 = + GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(F, 715827883, 1.0 / 3.0); + // We're evaluating a Taylor expansion around -1/8, so we do the change of + // variable: x = a + 1/8. + // In fixed-point with 0 integer bits, 1/8 is represented by 1 << 28. + F x = a + F::template ConstantPOT<-3>(); + F x2 = x * x; + F x3 = x2 * x; + F x4 = x2 * x2; + F x4_over_4 = SaturatingRoundingMultiplyByPOT<-2>(x4); + F x4_over_24_plus_x3_over_6_plus_x2_over_2 = + SaturatingRoundingMultiplyByPOT<-1>( + ((x4_over_4 + x3) * constant_1_over_3) + x2); + return AddSaturatingIf16Bit( + constant_term, + constant_term * (x + x4_over_24_plus_x3_over_6_plus_x2_over_2)); +} + +// Returns exp(x) for x < 0. +template +FixedPoint exp_on_negative_values( + FixedPoint a) +{ + typedef FixedPoint InputF; + typedef FixedPoint ResultF; + static constexpr int kFractionalBits = InputF::kFractionalBits; + static constexpr int kIntegerBits = InputF::kIntegerBits; + const InputF kOneQuarter = InputF::template ConstantPOT<-2>(); + InputF mask = kOneQuarter - InputF::FromScalarRaw(1); + InputF a_mod_quarter_minus_one_quarter = (a & mask) - kOneQuarter; + ResultF result = exp_on_interval_between_negative_one_quarter_and_0_excl( + Rescale<0>(a_mod_quarter_minus_one_quarter)); + tRawType remainder = (a_mod_quarter_minus_one_quarter - a).raw(); + +#define GEMMLOWP_EXP_BARREL_SHIFTER(Exponent, FixedPointMultiplier) \ + if (kIntegerBits > Exponent) { \ + const ResultF kMultiplier = GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT( \ + ResultF, FixedPointMultiplier, std::exp(-std::pow(2.0, Exponent))); \ + static constexpr int kShiftAmount = \ + kIntegerBits > Exponent ? kFractionalBits + Exponent : 0; \ + result = SelectUsingMask( \ + MaskIfNonZero(BitAnd(remainder, Dup(1 << kShiftAmount))), \ + result * kMultiplier, result); \ + } + + GEMMLOWP_EXP_BARREL_SHIFTER(-2, 1672461947); + GEMMLOWP_EXP_BARREL_SHIFTER(-1, 1302514674); + GEMMLOWP_EXP_BARREL_SHIFTER(+0, 790015084); + GEMMLOWP_EXP_BARREL_SHIFTER(+1, 290630308); + GEMMLOWP_EXP_BARREL_SHIFTER(+2, 39332535); + GEMMLOWP_EXP_BARREL_SHIFTER(+3, 720401); + GEMMLOWP_EXP_BARREL_SHIFTER(+4, 242); + +#undef GEMMLOWP_EXP_BARREL_SHIFTER + + static constexpr int clampB = kIntegerBits > 5 ? 36 - kIntegerBits : 0; + if (kIntegerBits > 5) { + const InputF clamp = + GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(InputF, -(1 << clampB), -32.0); + result = SelectUsingMask(MaskIfLessThan(a, clamp), ResultF::Zero(), result); + } + + result = SelectUsingMask(MaskIfZero(a), ResultF::One(), result); + return result; +} + +// Implementation of tanh: (1 - exp(-2x)) / (1 + exp(-2x)). + +// Returns (1 - x) / (1 + x) for x in (0, 1). +template +FixedPoint one_minus_x_over_one_plus_x_for_x_in_0_1( + FixedPoint a) +{ + typedef FixedPoint F0; + typedef FixedPoint F2; + F0 half_denominator = RoundingHalfSum(a, F0::One()); + // Newton-Raphson division + // https://en.wikipedia.org/wiki/Division_algorithm#Newton.E2.80.93Raphson_division + // Refer to that page for the logic behind the 48/17 and 32/17 constants. + const F2 constant_48_over_17 = + GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(F2, 1515870810, 48.0 / 17.0); + const F2 constant_neg_32_over_17 = + GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(F2, -1010580540, -32.0 / 17.0); + F2 x = constant_48_over_17 + half_denominator * constant_neg_32_over_17; + for (int i = 0; i < 3; i++) { + F2 half_denominator_times_x = half_denominator * x; + F2 one_minus_half_denominator_times_x = + F2::One() - half_denominator_times_x; + x = x + Rescale<2>(x * one_minus_half_denominator_times_x); + } + return Rescale<0>(x - F2::One()); +} + +// Returns -tanh(x) for x < 0. +template +FixedPoint neg_tanh_on_negative_values( + FixedPoint a) +{ + return one_minus_x_over_one_plus_x_for_x_in_0_1( + exp_on_negative_values(ExactMulByPot<1>(a))); +} + +// Returns tanh(x) for any x. +template +FixedPoint tanh(FixedPoint a) +{ + typedef FixedPoint InputF; + typedef FixedPoint ResultF; + tRawType mask_if_negative = MaskIfLessThan(a, InputF::Zero()); + tRawType mask_if_zero = MaskIfZero(a); + InputF n = SelectUsingMask(mask_if_negative, a, -a); + ResultF t = neg_tanh_on_negative_values(n); + return SelectUsingMask(mask_if_zero, ResultF::Zero(), + SelectUsingMask(mask_if_negative, -t, t)); +} + +// Implementation of logistic function. + +// Returns 1 / (1 + x) for x in (0, 1). +template +FixedPoint one_over_one_plus_x_for_x_in_0_1( + FixedPoint a) +{ + typedef FixedPoint F0; + typedef FixedPoint F2; + F0 half_denominator = RoundingHalfSum(a, F0::One()); + // Newton-Raphson division + // https://en.wikipedia.org/wiki/Division_algorithm#Newton.E2.80.93Raphson_division + // Refer to that page for the logic behind the 48/17 and 32/17 constants. + const F2 constant_48_over_17 = + GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(F2, 1515870810, 48.0 / 17.0); + const F2 constant_neg_32_over_17 = + GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(F2, -1010580540, -32.0 / 17.0); + F2 x = constant_48_over_17 + half_denominator * constant_neg_32_over_17; + for (int i = 0; i < 3; i++) { + F2 half_denominator_times_x = half_denominator * x; + F2 one_minus_half_denominator_times_x = + F2::One() - half_denominator_times_x; + x = x + Rescale<2>(x * one_minus_half_denominator_times_x); + } + return Rescale<0>(ExactMulByPot<-1>(x)); +} + +// Returns logistic(x) = 1 / (1 + exp(-x)) for x > 0. +template +FixedPoint logistic_on_positive_values( + FixedPoint a) +{ + return one_over_one_plus_x_for_x_in_0_1(exp_on_negative_values(-a)); +} + +// Returns logistic(x) = 1 / (1 + exp(-x)) for any x. +template +FixedPoint logistic(FixedPoint a) +{ + typedef FixedPoint InputF; + typedef FixedPoint ResultF; + tRawType mask_if_positive = MaskIfGreaterThan(a, InputF::Zero()); + tRawType mask_if_zero = MaskIfZero(a); + InputF abs_input = SelectUsingMask(mask_if_positive, a, -a); + ResultF result_if_positive = logistic_on_positive_values(abs_input); + ResultF result_if_negative = ResultF::One() - result_if_positive; + const ResultF one_half = + GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(ResultF, 1 << 30, 0.5); + return SelectUsingMask(mask_if_zero, one_half, + SelectUsingMask(mask_if_positive, result_if_positive, + result_if_negative)); +} + +} // end namespace gemmlowp + +#ifdef GEMMLOWP_NEON +#include "./fixedpoint_neon.h" +#elif defined(GEMMLOWP_AVX2) +#include "./fixedpoint_avx.h" +#elif defined(GEMMLOWP_SSE4) +#include "./fixedpoint_sse.h" +#elif defined(GEMMLOWP_MSA) +#include "./fixedpoint_msa.h" +#endif + +#endif // GEMMLOWP_INTERNAL_FIXEDPOINT_H_ diff --git a/components/tflite/third_party/gemmlowp/fixedpoint/fixedpoint_neon.h b/components/tflite/third_party/gemmlowp/fixedpoint/fixedpoint_neon.h new file mode 100644 index 00000000..7ec6399e --- /dev/null +++ b/components/tflite/third_party/gemmlowp/fixedpoint/fixedpoint_neon.h @@ -0,0 +1,387 @@ +// Copyright 2015 The Gemmlowp Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// fixedpoint_neon.h: optimized NEON specializations of the templates +// in fixedpoint.h. + +#ifndef GEMMLOWP_INTERNAL_FIXEDPOINT_NEON_H_ +#define GEMMLOWP_INTERNAL_FIXEDPOINT_NEON_H_ + +#include + +namespace gemmlowp { +template <> +struct FixedPointRawTypeTraits { + typedef std::int32_t ScalarRawType; + static constexpr int kLanes = 4; +}; + +template <> +struct FixedPointRawTypeTraits { + typedef std::int16_t ScalarRawType; + static constexpr int kLanes = 8; +}; + +template <> +inline int32x4_t BitAnd(int32x4_t a, int32x4_t b) +{ + return vandq_s32(a, b); +} + +template <> +inline int16x8_t BitAnd(int16x8_t a, int16x8_t b) +{ + return vandq_s16(a, b); +} + +template <> +inline int32x4_t BitOr(int32x4_t a, int32x4_t b) +{ + return vorrq_s32(a, b); +} + +template <> +inline int16x8_t BitOr(int16x8_t a, int16x8_t b) +{ + return vorrq_s16(a, b); +} + +template <> +inline int32x4_t BitXor(int32x4_t a, int32x4_t b) +{ + return veorq_s32(a, b); +} + +template <> +inline int16x8_t BitXor(int16x8_t a, int16x8_t b) +{ + return veorq_s16(a, b); +} + +template <> +inline int32x4_t BitNot(int32x4_t a) +{ + return veorq_s32(a, vdupq_n_s32(-1)); +} + +template <> +inline int16x8_t BitNot(int16x8_t a) +{ + return veorq_s16(a, vdupq_n_s16(-1)); +} + +template <> +inline int32x4_t Add(int32x4_t a, int32x4_t b) +{ + return vaddq_s32(a, b); +} + +template <> +inline int16x8_t Add(int16x8_t a, int16x8_t b) +{ + return vaddq_s16(a, b); +} + +template <> +inline int32x4_t Sub(int32x4_t a, int32x4_t b) +{ + return vsubq_s32(a, b); +} + +template <> +inline int16x8_t Sub(int16x8_t a, int16x8_t b) +{ + return vsubq_s16(a, b); +} + +template <> +inline int32x4_t Neg(int32x4_t a) +{ + return vnegq_s32(a); +} + +template <> +inline int16x8_t Neg(int16x8_t a) +{ + return vnegq_s16(a); +} + +template <> +inline int32x4_t ShiftLeft(int32x4_t a, int offset) +{ + return vshlq_s32(a, vdupq_n_s32(offset)); +} + +template <> +inline int16x8_t ShiftLeft(int16x8_t a, int offset) +{ + return vshlq_s16(a, vdupq_n_s16(offset)); +} + +template <> +inline int32x4_t ShiftRight(int32x4_t a, int offset) +{ + return vshlq_s32(a, vdupq_n_s32(-offset)); +} + +template <> +inline int16x8_t ShiftRight(int16x8_t a, int offset) +{ + return vshlq_s16(a, vdupq_n_s16(-offset)); +} + +template <> +inline int32x4_t SelectUsingMask(int32x4_t if_mask, int32x4_t then_val, + int32x4_t else_val) +{ + return vbslq_s32(vreinterpretq_u32_s32(if_mask), then_val, else_val); +} + +template <> +inline int16x8_t SelectUsingMask(int16x8_t if_mask, int16x8_t then_val, + int16x8_t else_val) +{ + return vbslq_s16(vreinterpretq_u16_s16(if_mask), then_val, else_val); +} + +template <> +inline int32x4_t MaskIfEqual(int32x4_t a, int32x4_t b) +{ + return vreinterpretq_s32_u32(vceqq_s32(a, b)); +} + +template <> +inline int16x8_t MaskIfEqual(int16x8_t a, int16x8_t b) +{ + return vreinterpretq_s16_u16(vceqq_s16(a, b)); +} + +template <> +inline int32x4_t MaskIfNotEqual(int32x4_t a, int32x4_t b) +{ + return BitNot(MaskIfEqual(a, b)); +} + +template <> +inline int16x8_t MaskIfNotEqual(int16x8_t a, int16x8_t b) +{ + return BitNot(MaskIfEqual(a, b)); +} + +template <> +inline int32x4_t MaskIfZero(int32x4_t a) +{ + return MaskIfEqual(a, vdupq_n_s32(0)); +} + +template <> +inline int16x8_t MaskIfZero(int16x8_t a) +{ + return MaskIfEqual(a, vdupq_n_s16(0)); +} + +template <> +inline int32x4_t MaskIfNonZero(int32x4_t a) +{ + return vreinterpretq_s32_u32(vtstq_s32(a, a)); +} + +template <> +inline int16x8_t MaskIfNonZero(int16x8_t a) +{ + return vreinterpretq_s16_u16(vtstq_s16(a, a)); +} + +template <> +inline int32x4_t MaskIfGreaterThan(int32x4_t a, int32x4_t b) +{ + return vreinterpretq_s32_u32(vcgtq_s32(a, b)); +} + +template <> +inline int16x8_t MaskIfGreaterThan(int16x8_t a, int16x8_t b) +{ + return vreinterpretq_s16_u16(vcgtq_s16(a, b)); +} + +template <> +inline int32x4_t MaskIfGreaterThanOrEqual(int32x4_t a, int32x4_t b) +{ + return vreinterpretq_s32_u32(vcgeq_s32(a, b)); +} + +template <> +inline int16x8_t MaskIfGreaterThanOrEqual(int16x8_t a, int16x8_t b) +{ + return vreinterpretq_s16_u16(vcgeq_s16(a, b)); +} + +template <> +inline int32x4_t MaskIfLessThan(int32x4_t a, int32x4_t b) +{ + return vreinterpretq_s32_u32(vcltq_s32(a, b)); +} + +template <> +inline int16x8_t MaskIfLessThan(int16x8_t a, int16x8_t b) +{ + return vreinterpretq_s16_u16(vcltq_s16(a, b)); +} + +template <> +inline int32x4_t MaskIfLessThanOrEqual(int32x4_t a, int32x4_t b) +{ + return vreinterpretq_s32_u32(vcleq_s32(a, b)); +} + +template <> +inline int16x8_t MaskIfLessThanOrEqual(int16x8_t a, int16x8_t b) +{ + return vreinterpretq_s16_u16(vcleq_s16(a, b)); +} + +template <> +inline bool All(int32x4_t a) +{ + a = vandq_s32(a, vextq_s32(a, a, 1)); + a = vandq_s32(a, vextq_s32(a, a, 2)); + return vgetq_lane_s32(a, 0); +} + +template <> +inline bool All(int16x8_t a) +{ + a = vandq_s16(a, vextq_s16(a, a, 1)); + a = vandq_s16(a, vextq_s16(a, a, 2)); + a = vandq_s16(a, vextq_s16(a, a, 4)); + return vgetq_lane_s16(a, 0); +} + +template <> +inline bool Any(int32x4_t a) +{ + a = vorrq_s32(a, vextq_s32(a, a, 1)); + a = vorrq_s32(a, vextq_s32(a, a, 2)); + return vgetq_lane_s32(a, 0); +} + +template <> +inline bool Any(int16x8_t a) +{ + a = vorrq_s16(a, vextq_s16(a, a, 1)); + a = vorrq_s16(a, vextq_s16(a, a, 2)); + a = vorrq_s16(a, vextq_s16(a, a, 4)); + return vgetq_lane_s16(a, 0); +} + +template <> +inline int32x4_t RoundingHalfSum(int32x4_t a, int32x4_t b) +{ + return vrhaddq_s32(a, b); +} + +template <> +inline int16x8_t RoundingHalfSum(int16x8_t a, int16x8_t b) +{ + return vrhaddq_s16(a, b); +} + +template <> +inline int32x4_t SaturatingRoundingDoublingHighMul(int32x4_t a, int32x4_t b) +{ + return vqrdmulhq_s32(a, b); +} + +template <> +inline int16x8_t SaturatingRoundingDoublingHighMul(int16x8_t a, int16x8_t b) +{ + return vqrdmulhq_s16(a, b); +} + +template <> +inline int32x4_t RoundingDivideByPOT(int32x4_t x, int exponent) +{ + const int32x4_t shift_vec = vdupq_n_s32(-exponent); + const int32x4_t fixup = vshrq_n_s32(vandq_s32(x, shift_vec), 31); + const int32x4_t fixed_up_x = vqaddq_s32(x, fixup); + return vrshlq_s32(fixed_up_x, shift_vec); +} + +template <> +inline int16x8_t RoundingDivideByPOT(int16x8_t x, int exponent) +{ + const int16x8_t shift_vec = vdupq_n_s16(-exponent); + const int16x8_t fixup = vshrq_n_s16(vandq_s16(x, shift_vec), 15); + const int16x8_t fixed_up_x = vqaddq_s16(x, fixup); + return vrshlq_s16(fixed_up_x, shift_vec); +} + +template +struct ImplSaturatingRoundingMultiplyByPOT { + static int32x4_t eval(int32x4_t x) + { + return vqshlq_n_s32(x, Exponent); + } +}; + +template +struct ImplSaturatingRoundingMultiplyByPOT { + static int32x4_t eval(int32x4_t x) + { + const int32x4_t fixup = vshrq_n_s32(x, 31); + const int32x4_t fixed_up_x = vqaddq_s32(x, fixup); + return vrshrq_n_s32(fixed_up_x, -Exponent); + } +}; + +template +struct ImplSaturatingRoundingMultiplyByPOT { + static int16x8_t eval(int16x8_t x) + { + return vqshlq_n_s16(x, Exponent); + } +}; + +template +struct ImplSaturatingRoundingMultiplyByPOT { + static int16x8_t eval(int16x8_t x) + { + const int16x8_t fixup = vshrq_n_s16(x, 15); + const int16x8_t fixed_up_x = vqaddq_s16(x, fixup); + return vrshrq_n_s16(fixed_up_x, -Exponent); + } +}; + +template <> +inline int32x4_t Dup(std::int32_t x) +{ + return vdupq_n_s32(x); +} + +template <> +inline int16x8_t Dup(std::int16_t x) +{ + return vdupq_n_s16(x); +} + +// So far this is only needed for int16. +template <> +inline int16x8_t SaturatingAdd(int16x8_t a, int16x8_t b) +{ + return vqaddq_s16(a, b); +} + +} // end namespace gemmlowp + +#endif // GEMMLOWP_INTERNAL_FIXEDPOINT_NEON_H_ diff --git a/components/tflite/third_party/gemmlowp/internal/detect_platform.h b/components/tflite/third_party/gemmlowp/internal/detect_platform.h new file mode 100644 index 00000000..391f27f8 --- /dev/null +++ b/components/tflite/third_party/gemmlowp/internal/detect_platform.h @@ -0,0 +1,166 @@ +// Copyright 2018 The Gemmlowp Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// detect_platform.h: Sets up macros that control architecture-specific +// features of gemmlowp's implementation. + +#ifndef GEMMLOWP_INTERNAL_DETECT_PLATFORM_H_ +#define GEMMLOWP_INTERNAL_DETECT_PLATFORM_H_ + +// Our inline assembly path assume GCC/Clang syntax. +// Native Client doesn't seem to support inline assembly(?). +#if defined(__GNUC__) && !defined(__native_client__) +#define GEMMLOWP_ALLOW_INLINE_ASM +#endif + +// Define macro statement that avoids inlining for GCC. +// For non-GCC, define as empty macro. +#if defined(__GNUC__) +#define GEMMLOWP_NOINLINE __attribute__((noinline)) +#else +#define GEMMLOWP_NOINLINE +#endif + +// Detect ARM, 32-bit or 64-bit +#ifdef __arm__ +#define GEMMLOWP_ARM_32 +#endif + +#ifdef __aarch64__ +#define GEMMLOWP_ARM_64 +#endif + +#if defined(GEMMLOWP_ARM_32) || defined(GEMMLOWP_ARM_64) +#define GEMMLOWP_ARM +#endif + +// Detect MIPS, 32-bit or 64-bit +#if defined(__mips) && !defined(__LP64__) +#define GEMMLOWP_MIPS_32 +#endif + +#if defined(__mips) && defined(__LP64__) +#define GEMMLOWP_MIPS_64 +#endif + +#if defined(GEMMLOWP_MIPS_32) || defined(GEMMLOWP_MIPS_64) +#define GEMMLOWP_MIPS +#endif + +// Detect x86, 32-bit or 64-bit +#if defined(__i386__) || defined(_M_IX86) || defined(_X86_) || defined(__i386) +#define GEMMLOWP_X86_32 +#endif + +#if defined(__x86_64__) || defined(_M_X64) || defined(__amd64) +#define GEMMLOWP_X86_64 +#endif + +#if defined(GEMMLOWP_X86_32) || defined(GEMMLOWP_X86_64) +#define GEMMLOWP_X86 +#endif + +// Some of our optimized paths use inline assembly and for +// now we don't bother enabling some other optimized paths using intrinddics +// where we can't use inline assembly paths. +#ifdef GEMMLOWP_ALLOW_INLINE_ASM + +// Detect NEON. It's important to check for both tokens. +#if (defined __ARM_NEON) || (defined __ARM_NEON__) +#define GEMMLOWP_NEON +#endif + +// Convenience NEON tokens for 32-bit or 64-bit +#if defined(GEMMLOWP_NEON) && defined(GEMMLOWP_ARM_32) +#define GEMMLOWP_NEON_32 +#endif + +#if defined(GEMMLOWP_NEON) && defined(GEMMLOWP_ARM_64) +#define GEMMLOWP_NEON_64 +#endif + +// Detect MIPS MSA. +// Limit MSA optimizations to little-endian CPUs for now. +// TODO: Perhaps, eventually support MSA optimizations on big-endian CPUs? +#if defined(GEMMLOWP_MIPS) && (__mips_isa_rev >= 5) && defined(__mips_msa) && \ + defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) +#define GEMMLOWP_MSA +#endif + +// Convenience MIPS MSA tokens for 32-bit or 64-bit. +#if defined(GEMMLOWP_MSA) && defined(GEMMLOWP_MIPS_32) +#define GEMMLOWP_MSA_32 +#endif + +#if defined(GEMMLOWP_MSA) && defined(GEMMLOWP_MIPS_64) +#define GEMMLOWP_MSA_64 +#endif + +// compiler define for AVX2 -D GEMMLOWP_ENABLE_AVX2 +// Detect AVX2 +#if defined(__AVX2__) && defined(GEMMLOWP_ENABLE_AVX2) +#define GEMMLOWP_AVX2 +// Detect SSE4. +// MSVC does not have __SSE4_1__ macro, but will enable SSE4 +// when AVX is turned on. +#elif defined(__SSE4_1__) || (defined(_MSC_VER) && defined(__AVX__)) +#define GEMMLOWP_SSE4 +// Detect SSE3. +#elif defined(__SSE3__) +#define GEMMLOWP_SSE3 +#endif + +// Convenience SSE4 tokens for 32-bit or 64-bit +#if defined(GEMMLOWP_SSE4) && defined(GEMMLOWP_X86_32) && \ + !defined(GEMMLOWP_DISABLE_SSE4) +#define GEMMLOWP_SSE4_32 +#endif + +#if defined(GEMMLOWP_SSE3) && defined(GEMMLOWP_X86_32) +#define GEMMLOWP_SSE3_32 +#endif + +#if defined(GEMMLOWP_SSE4) && defined(GEMMLOWP_X86_64) && \ + !defined(GEMMLOWP_DISABLE_SSE4) +#define GEMMLOWP_SSE4_64 +#endif + +#if defined(GEMMLOWP_SSE3) && defined(GEMMLOWP_X86_64) +#define GEMMLOWP_SSE3_64 +#endif + +#if defined(GEMMLOWP_AVX2) && defined(GEMMLOWP_X86_64) +#define GEMMLOWP_AVX2_64 +#endif + +#if defined(__has_feature) +#if __has_feature(memory_sanitizer) +#include +#define GEMMLOWP_MARK_MEMORY_AS_INITIALIZED __msan_unpoison +#elif __has_feature(address_sanitizer) +#include +#define GEMMLOWP_MARK_MEMORY_AS_INITIALIZED __asan_unpoison_memory_region +#endif +#endif + +#endif // GEMMLOWP_ALLOW_INLINE_ASM + +// Detect Android. Don't conflate with ARM - we care about tuning +// for non-ARM Android devices too. This can be used in conjunction +// with x86 to tune differently for mobile x86 CPUs (Atom) vs. desktop x86 CPUs. +#if defined(__ANDROID__) || defined(ANDROID) +#define GEMMLOWP_ANDROID +#endif + +#endif // GEMMLOWP_INTERNAL_DETECT_PLATFORM_H_ diff --git a/components/tflite/third_party/hexagon/LICENSE b/components/tflite/third_party/hexagon/LICENSE new file mode 100644 index 00000000..0353ff4c --- /dev/null +++ b/components/tflite/third_party/hexagon/LICENSE @@ -0,0 +1,231 @@ +/* Copyright 2020 The Qualcomm Innovation Center, Inc. All Rights Reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted (subject to the limitations in the disclaimer +below) provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. +* Neither the name of Qualcomm Innovation Center, Inc. nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + +NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY +THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT +NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +==============================================================================*/ + + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/components/tflite/third_party/hexagon/fully_connected.cc b/components/tflite/third_party/hexagon/fully_connected.cc new file mode 100644 index 00000000..75adbd9e --- /dev/null +++ b/components/tflite/third_party/hexagon/fully_connected.cc @@ -0,0 +1,318 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +/* Copyright 2020 The Qualcomm Innovation Center, Inc. All Rights Reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted (subject to the limitations in the disclaimer +below) provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. +* Neither the name of Qualcomm Innovation Center, Inc. nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + +NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY +THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT +NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +==============================================================================*/ + +#include "tensorflow/lite/micro/kernels/fully_connected.h" + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/fully_connected.h" +#include "tensorflow/lite/kernels/internal/reference/integer_ops/fully_connected.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "third_party/hexagon/hexagon_tflm_translation_fully_connected.h" + +namespace tflite { +namespace { + +// Input tensors. +constexpr int kInputTensor = 0; +constexpr int kWeightsTensor = 1; +constexpr int kBiasTensor = 2; +// Output tensor. +constexpr int kOutputTensor = 0; + +struct OpData { + // The scaling factor from input to output (aka the 'real multiplier') can + // be represented as a fixed point multiplier plus a left shift. + int32_t output_multiplier; + int output_shift; + // The range of the fused activation layer. For example for kNone and + // uint8_t these would be 0 and 255. + int32_t output_activation_min; + int32_t output_activation_max; + // The index of the temporary tensor where the quantized inputs are cached. + int input_quantized_index; + // Cached zero point values of tensors. + int32_t input_zero_point; + int32_t filter_zero_point; + int32_t output_zero_point; + + void *hexagon_data; +}; + +TfLiteStatus CalculateOpData(TfLiteContext *context, + TfLiteFusedActivation activation, + TfLiteType data_type, const TfLiteTensor *input, + const TfLiteTensor *filter, + const TfLiteTensor *bias, TfLiteTensor *output, + OpData *data) +{ + TfLiteStatus status = kTfLiteOk; + if (data_type != kTfLiteFloat32) { + double real_multiplier = 0.0; + TF_LITE_ENSURE_STATUS(GetQuantizedConvolutionMultipler( + context, input, filter, bias, output, &real_multiplier)); + int exponent; + QuantizeMultiplier(real_multiplier, &data->output_multiplier, &exponent); + data->output_shift = -exponent; + TF_LITE_ENSURE_STATUS(CalculateActivationRangeQuantized( + context, activation, output, &data->output_activation_min, + &data->output_activation_max)); + + data->input_zero_point = input->params.zero_point; + data->filter_zero_point = filter->params.zero_point; + data->output_zero_point = output->params.zero_point; + } + return status; +} + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + void *data = nullptr; + data = context->AllocatePersistentBuffer(context, sizeof(OpData)); + + if (data == nullptr) { + return nullptr; + } + OpData *opdata = static_cast(data); + opdata->hexagon_data = + tflite::hexagon_fully_connected::HexagonInit(context, buffer, length); + + return data; +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->user_data != nullptr); + TFLITE_DCHECK(node->builtin_data != nullptr); + + OpData *data = static_cast(node->user_data); + const auto params = + static_cast(node->builtin_data); + + const TfLiteTensor *input = GetInput(context, node, kInputTensor); + TF_LITE_ENSURE(context, input != nullptr); + const TfLiteTensor *filter = GetInput(context, node, kWeightsTensor); + TF_LITE_ENSURE(context, filter != nullptr); + const TfLiteTensor *bias = GetOptionalInputTensor(context, node, kBiasTensor); + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + + TF_LITE_ENSURE_TYPES_EQ(context, input->type, output->type); + TF_LITE_ENSURE_MSG(context, input->type == filter->type, + "Hybrid models are not supported on TFLite Micro."); + + tflite::hexagon_fully_connected::HexagonOptimizationEvaluation(context, node); + + if (tflite::hexagon_fully_connected::HexagonOptimizable(context, node)) { + return tflite::hexagon_fully_connected::HexagonPrepare(context, node); + } else { + return CalculateOpData(context, params->activation, input->type, input, + filter, bias, output, data); + } +} + +TfLiteStatus EvalQuantizedInt8(TfLiteContext *context, TfLiteNode *node, + const OpData &data, + const TfLiteEvalTensor *input, + const TfLiteEvalTensor *filter, + const TfLiteEvalTensor *bias, + TfLiteEvalTensor *output) +{ + tflite::FullyConnectedParams op_params; + op_params.input_offset = -data.input_zero_point; + op_params.weights_offset = -data.filter_zero_point; + op_params.output_offset = data.output_zero_point; + op_params.output_multiplier = data.output_multiplier; + // TODO(b/138810107): Figure out whether output shift should be inverted + op_params.output_shift = -data.output_shift; + op_params.quantized_activation_min = data.output_activation_min; + op_params.quantized_activation_max = data.output_activation_max; + + reference_integer_ops::FullyConnected( + op_params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(filter), + tflite::micro::GetTensorData(filter), + tflite::micro::GetTensorShape(bias), + tflite::micro::GetTensorData(bias), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + + return kTfLiteOk; +} + +TfLiteStatus EvalQuantized(TfLiteContext *context, TfLiteNode *node, + const OpData &data, const TfLiteEvalTensor *input, + const TfLiteEvalTensor *filter, + const TfLiteEvalTensor *bias, + TfLiteEvalTensor *output) +{ + const int32_t input_offset = -data.input_zero_point; + const int32_t filter_offset = -data.filter_zero_point; + const int32_t output_offset = data.output_zero_point; + + tflite::FullyConnectedParams op_params; + op_params.input_offset = input_offset; + op_params.weights_offset = filter_offset; + op_params.output_offset = output_offset; + op_params.output_multiplier = data.output_multiplier; + // Legacy ops used mixed left and right shifts. Now all are +ve-means-left. + op_params.output_shift = -data.output_shift; + op_params.quantized_activation_min = data.output_activation_min; + op_params.quantized_activation_max = data.output_activation_max; + +#define TF_LITE_FULLY_CONNECTED(output_data_type) \ + reference_ops::FullyConnected( \ + op_params, tflite::micro::GetTensorShape(input), \ + tflite::micro::GetTensorData(input), \ + tflite::micro::GetTensorShape(filter), \ + tflite::micro::GetTensorData(filter), \ + tflite::micro::GetTensorShape(bias), \ + tflite::micro::GetTensorData(bias), \ + tflite::micro::GetTensorShape(output), \ + tflite::micro::GetTensorData(output)) + switch (output->type) { + case kTfLiteUInt8: + TF_LITE_FULLY_CONNECTED(uint8_t); + break; + case kTfLiteInt16: + TF_LITE_FULLY_CONNECTED(int16_t); + break; + default: + TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.", + TfLiteTypeGetName(output->type), output->type); + return kTfLiteError; + } + + return kTfLiteOk; +} + +TfLiteStatus EvalFloat(TfLiteContext *context, TfLiteNode *node, + TfLiteFusedActivation activation, + const TfLiteEvalTensor *input, + const TfLiteEvalTensor *filter, + const TfLiteEvalTensor *bias, TfLiteEvalTensor *output) +{ + float output_activation_min, output_activation_max; + CalculateActivationRange(activation, &output_activation_min, + &output_activation_max); + tflite::FullyConnectedParams op_params; + op_params.float_activation_min = output_activation_min; + op_params.float_activation_max = output_activation_max; + tflite::reference_ops::FullyConnected( + op_params, tflite::micro::GetTensorShape(input), + tflite::micro::GetTensorData(input), + tflite::micro::GetTensorShape(filter), + tflite::micro::GetTensorData(filter), + tflite::micro::GetTensorShape(bias), + tflite::micro::GetTensorData(bias), + tflite::micro::GetTensorShape(output), + tflite::micro::GetTensorData(output)); + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->builtin_data != nullptr); + const auto *params = + static_cast(node->builtin_data); + + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + const TfLiteEvalTensor *filter = + tflite::micro::GetEvalInput(context, node, kWeightsTensor); + const TfLiteEvalTensor *bias = + tflite::micro::GetEvalInput(context, node, kBiasTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + TFLITE_DCHECK(node->user_data != nullptr); + const OpData &data = *(static_cast(node->user_data)); + + // Checks in Prepare ensure input, output and filter types are all the same. + switch (input->type) { + case kTfLiteFloat32: + return EvalFloat(context, node, params->activation, input, filter, bias, + output); + + case kTfLiteInt8: + if (tflite::hexagon_fully_connected::HexagonOptimizable(context, node)) { + return tflite::hexagon_fully_connected::HexagonEvalQuantizedInt8( + context, node, node->user_data, input, filter, bias, output); + } else { + return EvalQuantizedInt8(context, node, data, input, filter, bias, + output); + } + + case kTfLiteUInt8: + return EvalQuantized(context, node, data, input, filter, bias, output); + + default: + TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.", + TfLiteTypeGetName(input->type), input->type); + return kTfLiteError; + } + return kTfLiteOk; +} + +} // namespace + +TfLiteRegistration Register_FULLY_CONNECTED() +{ + return { /*init=*/Init, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/third_party/hexagon/hexagon_tflm_translation_fully_connected.h b/components/tflite/third_party/hexagon/hexagon_tflm_translation_fully_connected.h new file mode 100644 index 00000000..9f4fac7d --- /dev/null +++ b/components/tflite/third_party/hexagon/hexagon_tflm_translation_fully_connected.h @@ -0,0 +1,78 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +/* Copyright 2020 The Qualcomm Innovation Center, Inc. All Rights Reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted (subject to the limitations in the disclaimer +below) provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. +* Neither the name of Qualcomm Innovation Center, Inc. nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + +NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY +THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT +NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +==============================================================================*/ + +#ifndef _HEXAGON_TFLM_TRANSLATION_FULLY_CONNECTED_H_ +#define _HEXAGON_TFLM_TRANSLATION_FULLY_CONNECTED_H_ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/reference/fully_connected.h" +#include "tensorflow/lite/kernels/internal/reference/integer_ops/fully_connected.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/fully_connected.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" + +namespace tflite { +namespace hexagon_fully_connected { +void *HexagonInit(TfLiteContext *context, const char *buffer, size_t length); + +TfLiteStatus HexagonPrepare(TfLiteContext *context, TfLiteNode *node); + +TfLiteStatus HexagonEvalQuantizedInt8(TfLiteContext *context, TfLiteNode *node, + void *op_data, + const TfLiteEvalTensor *input, + const TfLiteEvalTensor *filter, + const TfLiteEvalTensor *bias, + TfLiteEvalTensor *output); + +void HexagonOptimizationEvaluation(TfLiteContext *context, TfLiteNode *node); +bool HexagonOptimizable(TfLiteContext *context, TfLiteNode *node); + +} // namespace hexagon_fully_connected +} // namespace tflite + +#endif // _HEXAGON_TFLM_TRANSLATION_FULLY_CONNECTED_H_ diff --git a/components/tflite/third_party/hexagon/hexagon_tflm_translation_svdf.h b/components/tflite/third_party/hexagon/hexagon_tflm_translation_svdf.h new file mode 100644 index 00000000..fc3a81cd --- /dev/null +++ b/components/tflite/third_party/hexagon/hexagon_tflm_translation_svdf.h @@ -0,0 +1,80 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +/* Copyright 2020 The Qualcomm Innovation Center, Inc. All Rights Reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted (subject to the limitations in the disclaimer +below) provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. +* Neither the name of Qualcomm Innovation Center, Inc. nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + +NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY +THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT +NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +==============================================================================*/ + +#ifndef _HEXAGON_TFLM_TRANSLATION_SVDF_H_ +#define _HEXAGON_TFLM_TRANSLATION_SVDF_H_ + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/activation_utils.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/micro_utils.h" + +namespace tflite { +namespace hexagon_svdf { +void *HexagonInit(TfLiteContext *context, const char *buffer, size_t length); + +TfLiteStatus HexagonPrepare(TfLiteContext *context, TfLiteNode *node); + +void HexagonEvalIntegerSVDF(TfLiteContext *context, TfLiteNode *node, + const TfLiteEvalTensor *input_tensor, + const TfLiteEvalTensor *weights_feature_tensor, + const TfLiteEvalTensor *weights_time_tensor, + const TfLiteEvalTensor *bias_tensor, + const TfLiteSVDFParams *params, + TfLiteEvalTensor *activation_state_tensor, + TfLiteEvalTensor *output_tensor, void *op_data); + +void HexagonOptimizationEvaluation(TfLiteContext *context, TfLiteNode *node); +bool HexagonOptimizable(TfLiteContext *context, TfLiteNode *node); + +} // namespace hexagon_svdf +} // namespace tflite + +#endif // _HEXAGON_TFLM_TRANSLATION_SVDF_H_ diff --git a/components/tflite/third_party/hexagon/svdf.cc b/components/tflite/third_party/hexagon/svdf.cc new file mode 100644 index 00000000..a0b59d9b --- /dev/null +++ b/components/tflite/third_party/hexagon/svdf.cc @@ -0,0 +1,610 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +/* Copyright 2020 The Qualcomm Innovation Center, Inc. All Rights Reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted (subject to the limitations in the disclaimer +below) provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. +* Neither the name of Qualcomm Innovation Center, Inc. nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + +NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY +THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT +NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +==============================================================================*/ + +#include + +#include "tensorflow/lite/c/builtin_op_data.h" +#include "tensorflow/lite/c/common.h" +#include "tensorflow/lite/kernels/internal/common.h" +#include "tensorflow/lite/kernels/internal/quantization_util.h" +#include "tensorflow/lite/kernels/internal/tensor_ctypes.h" +#include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/kernels/op_macros.h" +#include "tensorflow/lite/micro/kernels/activation_utils.h" +#include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/micro_utils.h" +#include "third_party/hexagon/hexagon_tflm_translation_svdf.h" + +namespace tflite { +namespace { + +// Input tensors. +constexpr int kInputTensor = 0; +constexpr int kWeightsFeatureTensor = 1; +constexpr int kWeightsTimeTensor = 2; +constexpr int kBiasTensor = 3; +constexpr int kInputActivationStateTensor = 4; +// Output tensor. +constexpr int kOutputTensor = 0; + +struct OpData { + int32_t effective_scale_1_a; + int32_t effective_scale_2_a; + // b versions of each scale are kept at int since the numbers are just the + // shift value - typically between [-32, 32]. + int effective_scale_1_b; + int effective_scale_2_b; + int scratch_tensor_index; + int scratch_output_tensor_index; + + // Cached tensor zero point values for quantized operations. + int input_zero_point; + int output_zero_point; + + void *hexagon_data; +}; + +/** + * This version of SVDF is specific to TFLite Micro. It contains the following + * differences between the TFLite version: + * + * 1.) Scratch tensor allocation - scratch tensors must be known ahead of time + * for the Micro interpreter. + * 2.) Output dimensions - the TFLite version determines output size and runtime + * and resizes the output tensor. Micro runtime does not support tensor + * resizing. + */ +static inline void ApplyTimeWeightsBiasAndActivation( + int batch_size, int memory_size, int num_filters, int num_units, int rank, + const float *const __restrict__ weights_time_ptr, + const float *const __restrict__ bias_ptr, TfLiteFusedActivation activation, + float *const __restrict__ state_ptr, float *const __restrict__ scratch_ptr, + float *const __restrict__ output_ptr) +{ + // Compute matmul(activation_state, weights_time). + for (int b = 0; b < batch_size; ++b) { + // Perform batched vector dot product: + float *scratch_ptr_batch = scratch_ptr + b * num_filters; + const float *vector1_ptr = weights_time_ptr; + const float *vector2_ptr = state_ptr + b * memory_size * num_filters; + for (int i = 0; i < num_filters; ++i) { + *scratch_ptr_batch = 0.f; + for (int j = 0; j < memory_size; ++j) { + *scratch_ptr_batch += *vector1_ptr++ * *vector2_ptr++; + } + scratch_ptr_batch++; + } + } + + // Initialize output with bias if provided. + if (bias_ptr) { + // VectorBatchVectorAssign + for (int i = 0; i < batch_size; ++i) { + float *output_data = output_ptr + i * num_units; + const float *bias_data = bias_ptr; + for (int j = 0; j < num_units; ++j) { + *output_data++ = *bias_data++; + } + } + } else { + float *output_data = output_ptr; + for (int i = 0; i < batch_size * num_units; ++i) { + *output_data++ = 0.0f; + } + } + + // Reduction sum. + for (int b = 0; b < batch_size; ++b) { + float *output_ptr_batch = output_ptr + b * num_units; + float *scratch_ptr_batch = scratch_ptr + b * num_filters; + + // Reduction sum vector + for (int i = 0; i < num_units; ++i) { + for (int j = 0; j < rank; j++) { + output_ptr_batch[i] += *scratch_ptr_batch++; + } + } + } + + // Apply activation. + for (int b = 0; b < batch_size; ++b) { + float *output_ptr_batch = output_ptr + b * num_units; + for (int i = 0; i < num_units; ++i) { + *output_ptr_batch = + tflite::ops::micro::ActivationValFloat(activation, *output_ptr_batch); + ++output_ptr_batch; + } + } +} + +inline void EvalFloatSVDF( + TfLiteContext *context, TfLiteNode *node, const TfLiteEvalTensor *input, + const TfLiteEvalTensor *weights_feature, + const TfLiteEvalTensor *weights_time, const TfLiteEvalTensor *bias, + const TfLiteSVDFParams *params, int scratch_tensor_index, + TfLiteEvalTensor *activation_state, TfLiteEvalTensor *output) +{ + const int rank = params->rank; + const int batch_size = input->dims->data[0]; + const int input_size = input->dims->data[1]; + const int num_filters = weights_feature->dims->data[0]; + const int num_units = num_filters / rank; + const int memory_size = weights_time->dims->data[1]; + + const float *weights_feature_ptr = + tflite::micro::GetTensorData(weights_feature); + const float *weights_time_ptr = + tflite::micro::GetTensorData(weights_time); + const float *bias_ptr = tflite::micro::GetTensorData(bias); + const float *input_ptr = tflite::micro::GetTensorData(input); + + float *state_ptr = tflite::micro::GetTensorData(activation_state); + + TFLITE_DCHECK(context != nullptr); + TFLITE_DCHECK(context->GetScratchBuffer != nullptr); + + float *scratch_ptr = static_cast( + context->GetScratchBuffer(context, scratch_tensor_index)); + + float *output_ptr = tflite::micro::GetTensorData(output); + + // Left shift the activation_state. + { + float *new_state_start = state_ptr; + const float *old_state_start = state_ptr + 1; + const float *old_state_end = + state_ptr + batch_size * num_filters * memory_size; + while (old_state_start != old_state_end) { + *new_state_start++ = *old_state_start++; + } + } + + // Note: no need to clear the latest activation, matmul is not accumulative. + + // Compute conv1d(inputs, weights_feature). + // The activation_state's rightmost column is used to save current cycle + // activation. This is achieved by starting at state_ptr[memory_size - 1] and + // having the stride equal to memory_size. + + // Perform batched matrix vector multiply operation: + { + const float *matrix = weights_feature_ptr; + const float *vector = input_ptr; + float *result = &state_ptr[memory_size - 1]; + float *result_in_batch = result; + for (int i = 0; i < batch_size; ++i) { + const float *matrix_ptr = matrix; + for (int j = 0; j < num_filters; ++j) { + float dot_prod = 0.0f; + const float *vector_in_batch = vector + i * input_size; + for (int k = 0; k < input_size; ++k) { + dot_prod += *matrix_ptr++ * *vector_in_batch++; + } + *result_in_batch = dot_prod; + result_in_batch += memory_size; + } + } + } + + ApplyTimeWeightsBiasAndActivation( + batch_size, memory_size, num_filters, num_units, rank, weights_time_ptr, + bias_ptr, params->activation, state_ptr, scratch_ptr, output_ptr); +} + +void EvalIntegerSVDF(TfLiteContext *context, TfLiteNode *node, + const TfLiteEvalTensor *input_tensor, + const TfLiteEvalTensor *weights_feature_tensor, + const TfLiteEvalTensor *weights_time_tensor, + const TfLiteEvalTensor *bias_tensor, + const TfLiteSVDFParams *params, + TfLiteEvalTensor *activation_state_tensor, + TfLiteEvalTensor *output_tensor, const OpData &data) +{ + const int n_rank = params->rank; + const int n_batch = input_tensor->dims->data[0]; + const int n_input = input_tensor->dims->data[1]; + const int n_filter = weights_feature_tensor->dims->data[0]; + const int n_unit = n_filter / n_rank; + const int n_memory = weights_time_tensor->dims->data[1]; + + TFLITE_DCHECK(context != nullptr); + TFLITE_DCHECK(context->GetScratchBuffer != nullptr); + + int32_t *scratch_tensor = static_cast( + context->GetScratchBuffer(context, data.scratch_tensor_index)); + int32_t *scratch_output_tensor = static_cast( + context->GetScratchBuffer(context, data.scratch_output_tensor_index)); + + // Shift states. + int16_t *const state_ptr = + tflite::micro::GetTensorData(activation_state_tensor); + + // Left shift the activation_state. + { + int16_t *new_state_start = state_ptr; + const int16_t *old_state_start = state_ptr + 1; + const int16_t *old_state_end = state_ptr + n_batch * n_filter * n_memory; + while (old_state_start != old_state_end) { + *new_state_start++ = *old_state_start++; + } + } + + // Note: no need to clear the latest activation, matmul is not accumulative. + + // Feature matmul. + { + int16_t *state = + tflite::micro::GetTensorData(activation_state_tensor); + const int8_t *input = tflite::micro::GetTensorData(input_tensor); + const int8_t *weight_feature = + tflite::micro::GetTensorData(weights_feature_tensor); + const int32_t output_max = std::numeric_limits::max(); + const int32_t output_min = std::numeric_limits::min(); + int16_t *result_in_batch = state + (n_memory - 1); + for (int b = 0; b < n_batch; b++) { + const int8_t *matrix_ptr = weight_feature; + for (int r = 0; r < n_filter; r++) { + int32_t dot_prod = 0; + const int8_t *vector_in_batch = input + b * n_input; + for (int c = 0; c < n_input; c++) { + dot_prod += + *matrix_ptr++ * (*vector_in_batch++ - data.input_zero_point); + } + dot_prod = MultiplyByQuantizedMultiplier( + dot_prod, data.effective_scale_1_a, data.effective_scale_1_b); + dot_prod = std::min(std::max(output_min, dot_prod), output_max); + // This assumes state is symmetrically quantized. Otherwise last bit of + // state should be initialized to its zero point and accumulate the + // dot_prod. + // Equivalent as the following: + // result_in_batch = zero point, which happens to be zero. + // result_in_batch += dot_prod_56. + *result_in_batch = dot_prod; + result_in_batch += n_memory; + } + } + } + + // Time. + { + for (int b = 0; b < n_batch; ++b) { + int32_t *scratch_ptr_batch = scratch_tensor + b * n_filter; + + // Perform batched vector dot product: + const int16_t *vector1_ptr = + tflite::micro::GetTensorData(weights_time_tensor); + const int16_t *vector2_ptr = + tflite::micro::GetTensorData(activation_state_tensor) + + b * n_memory * n_filter; + + for (int i = 0; i < n_filter; i++) { + *scratch_ptr_batch = 0; + for (int j = 0; j < n_memory; j++) { + *scratch_ptr_batch += *vector1_ptr++ * *vector2_ptr++; + } + scratch_ptr_batch++; + } + } + } + + // Reduce, add bias, rescale, activation. + { + // Add bias. + { + if (bias_tensor) { + // Vector batch assign: + const int32_t *bias_data = + tflite::micro::GetTensorData(bias_tensor); + for (int i = 0; i < n_batch; ++i) { + int32_t *output_ptr = scratch_output_tensor + i * n_unit; + const int32_t *bias_ptr = bias_data; + for (int j = 0; j < n_unit; ++j) { + *output_ptr++ = *bias_ptr++; + } + } + } else { + int32_t *output_ptr = scratch_output_tensor; + for (int i = 0; i < n_batch * n_unit; ++i) { + *output_ptr++ = 0; + } + } + } + + // Reduce. + { + for (int b = 0; b < n_batch; ++b) { + int32_t *output_temp_ptr = scratch_output_tensor + b * n_unit; + int32_t *scratch_ptr_batch = scratch_tensor + b * n_filter; + + // Reduction sum vector + for (int i = 0; i < n_unit; ++i) { + for (int j = 0; j < n_rank; ++j) { + output_temp_ptr[i] += *scratch_ptr_batch++; + } + } + } + } + + // Rescale. + { + const int32_t output_max = std::numeric_limits::max(); + const int32_t output_min = std::numeric_limits::min(); + for (int i = 0; i < n_batch * n_unit; ++i) { + int32_t x1 = scratch_output_tensor[i]; + int32_t x2 = MultiplyByQuantizedMultiplier(x1, data.effective_scale_2_a, + data.effective_scale_2_b); + int32_t x3 = x2 + data.output_zero_point; + int32_t x4 = std::min(std::max(output_min, x3), output_max); + tflite::micro::GetTensorData(output_tensor)[i] = + static_cast(x4); + } + } + } +} + +void *Init(TfLiteContext *context, const char *buffer, size_t length) +{ + TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr); + void *data = context->AllocatePersistentBuffer(context, sizeof(OpData)); + + if (data == nullptr) { + return nullptr; + } + OpData *opdata = static_cast(data); + opdata->hexagon_data = + tflite::hexagon_svdf::HexagonInit(context, buffer, length); + + return data; +} + +TfLiteStatus Prepare(TfLiteContext *context, TfLiteNode *node) +{ + TFLITE_DCHECK(node->builtin_data != nullptr); + + const auto *params = static_cast(node->builtin_data); + + // Validate Tensor Inputs (dtype depends on quantization): + // [0] = Input, {2, batch_size, input_size} + // [1] = Weights Feature, {2, num_filters, input_size} + // [2] = Weights Time, {2, num_filters, memory_size} + // [3] = Bias (optional), {1, num_units} + // [4] = Activation State (variable), + // {2, batch_size, memory_size * num_filters} + const TfLiteTensor *input = GetInput(context, node, kInputTensor); + TF_LITE_ENSURE(context, input != nullptr); + const TfLiteTensor *weights_feature = + GetInput(context, node, kWeightsFeatureTensor); + TF_LITE_ENSURE(context, weights_feature != nullptr); + const TfLiteTensor *weights_time = + GetInput(context, node, kWeightsTimeTensor); + TF_LITE_ENSURE(context, weights_time != nullptr); + const TfLiteTensor *bias = GetOptionalInputTensor(context, node, kBiasTensor); + const TfLiteTensor *activation_state = + GetInput(context, node, kInputActivationStateTensor); + TF_LITE_ENSURE(context, activation_state != nullptr); + + // Define input constants based on input tensor definition above: + const int rank = params->rank; + const int input_size = input->dims->data[1]; + const int batch_size = input->dims->data[0]; + const int num_filters = weights_feature->dims->data[0]; + TF_LITE_ENSURE_EQ(context, num_filters % rank, 0); + const int num_units = num_filters / rank; + const int memory_size = weights_time->dims->data[1]; + + // Validate Input Tensor: + TF_LITE_ENSURE(context, + input->type == kTfLiteFloat32 || input->type == kTfLiteInt8); + TF_LITE_ENSURE_EQ(context, NumDimensions(input), 2); + + // Validate Tensor Output: + // [0] = float/int8_t, {2, batch_size, num_units} + TF_LITE_ENSURE_EQ(context, node->outputs->size, 1); + TfLiteTensor *output = GetOutput(context, node, kOutputTensor); + TF_LITE_ENSURE(context, output != nullptr); + TF_LITE_ENSURE_EQ(context, NumDimensions(output), 2); + TF_LITE_ENSURE_EQ(context, output->dims->data[0], batch_size); + TF_LITE_ENSURE_EQ(context, output->dims->data[1], num_units); + + // Validate Weights Feature Input Tensor: + TF_LITE_ENSURE_EQ(context, NumDimensions(weights_feature), 2); + TF_LITE_ENSURE_EQ(context, weights_feature->dims->data[1], input_size); + + // Validate Weights Time Input Tensor: + TF_LITE_ENSURE_EQ(context, NumDimensions(weights_time), 2); + TF_LITE_ENSURE_EQ(context, weights_time->dims->data[0], num_filters); + TF_LITE_ENSURE_EQ(context, weights_time->dims->data[1], memory_size); + + // Validate Optional Bias Input Tensor: + if (bias != nullptr) { + TF_LITE_ENSURE_EQ(context, bias->dims->data[0], num_units); + } + + // Validate Activation State Input Tensor: + TF_LITE_ENSURE_EQ(context, NumDimensions(activation_state), 2); + TF_LITE_ENSURE_EQ(context, activation_state->dims->data[0], batch_size); + TF_LITE_ENSURE_EQ(context, activation_state->dims->data[1], + memory_size * num_filters); + // Since is_variable is not part of TFLiteEvalTensor, check is_variable here. + TF_LITE_ENSURE_EQ(context, activation_state->is_variable, true); + + TF_LITE_ENSURE_EQ(context, node->inputs->size, 5); + + TFLITE_DCHECK(node->user_data != nullptr); + OpData *data = static_cast(node->user_data); + + if (input->type == kTfLiteInt8) { + TF_LITE_ENSURE_EQ(context, weights_feature->type, kTfLiteInt8); + TF_LITE_ENSURE_EQ(context, weights_time->type, kTfLiteInt16); + TF_LITE_ENSURE_EQ(context, activation_state->type, kTfLiteInt16); + if (bias != nullptr) { + TF_LITE_ENSURE_EQ(context, bias->type, kTfLiteInt32); + } + + TF_LITE_ENSURE_TYPES_EQ(context, output->type, kTfLiteInt8); + + const double effective_scale_1 = static_cast( + input->params.scale * weights_feature->params.scale / + activation_state->params.scale); + const double effective_scale_2 = + static_cast(activation_state->params.scale * + weights_time->params.scale / output->params.scale); + + // TODO(b/162018098): Use TF_LITE_ENSURE_NEAR when it is ready. + TF_LITE_ENSURE( + context, + std::abs(static_cast(bias->params.scale) - + static_cast(activation_state->params.scale * + weights_time->params.scale)) < 1e-5); + + QuantizeMultiplier(effective_scale_1, &(data->effective_scale_1_a), + &(data->effective_scale_1_b)); + QuantizeMultiplier(effective_scale_2, &(data->effective_scale_2_a), + &(data->effective_scale_2_b)); + + data->input_zero_point = input->params.zero_point; + data->output_zero_point = output->params.zero_point; + + TFLITE_DCHECK(context->RequestScratchBufferInArena != nullptr); + + tflite::hexagon_svdf::HexagonOptimizationEvaluation(context, node); + + if (tflite::hexagon_svdf::HexagonOptimizable(context, node)) { + TF_LITE_ENSURE_OK(context, + tflite::hexagon_svdf::HexagonPrepare(context, node)); + } else { + const TfLiteStatus scratch_status = context->RequestScratchBufferInArena( + context, batch_size * num_filters * sizeof(int32_t), + &(data->scratch_tensor_index)); + TF_LITE_ENSURE_OK(context, scratch_status); + + const TfLiteStatus scratch_output_status = + context->RequestScratchBufferInArena( + context, batch_size * num_units * sizeof(int32_t), + &(data->scratch_output_tensor_index)); + TF_LITE_ENSURE_OK(context, scratch_output_status); + } + } else { + TF_LITE_ENSURE_EQ(context, weights_feature->type, kTfLiteFloat32); + TF_LITE_ENSURE_EQ(context, weights_time->type, kTfLiteFloat32); + TF_LITE_ENSURE_EQ(context, activation_state->type, kTfLiteFloat32); + if (bias != nullptr) { + TF_LITE_ENSURE_EQ(context, bias->type, kTfLiteFloat32); + } + TF_LITE_ENSURE_TYPES_EQ(context, output->type, kTfLiteFloat32); + + TFLITE_DCHECK(context->RequestScratchBufferInArena != nullptr); + const TfLiteStatus scratch_status = context->RequestScratchBufferInArena( + context, batch_size * num_filters * sizeof(float), + &(data->scratch_tensor_index)); + TF_LITE_ENSURE_OK(context, scratch_status); + } + + return kTfLiteOk; +} + +TfLiteStatus Eval(TfLiteContext *context, TfLiteNode *node) +{ + auto *params = reinterpret_cast(node->builtin_data); + TFLITE_DCHECK(node->user_data != nullptr); + const OpData &data = *(static_cast(node->user_data)); + + const TfLiteEvalTensor *input = + tflite::micro::GetEvalInput(context, node, kInputTensor); + const TfLiteEvalTensor *weights_feature = + tflite::micro::GetEvalInput(context, node, kWeightsFeatureTensor); + const TfLiteEvalTensor *weights_time = + tflite::micro::GetEvalInput(context, node, kWeightsTimeTensor); + const TfLiteEvalTensor *bias = + (NumInputs(node) == 5) ? tflite::micro::GetEvalInput(context, node, kBiasTensor) : nullptr; + TfLiteEvalTensor *activation_state = tflite::micro::GetMutableEvalInput( + context, node, kInputActivationStateTensor); + TfLiteEvalTensor *output = + tflite::micro::GetEvalOutput(context, node, kOutputTensor); + + switch (weights_feature->type) { + case kTfLiteFloat32: { + EvalFloatSVDF(context, node, input, weights_feature, weights_time, bias, + params, data.scratch_tensor_index, activation_state, + output); + return kTfLiteOk; + break; + } + + case kTfLiteInt8: { + if (tflite::hexagon_svdf::HexagonOptimizable(context, node)) { + tflite::hexagon_svdf::HexagonEvalIntegerSVDF( + context, node, input, weights_feature, weights_time, bias, params, + activation_state, output, node->user_data); + } else { + EvalIntegerSVDF(context, node, input, weights_feature, weights_time, + bias, params, activation_state, output, data); + } + return kTfLiteOk; + break; + } + + default: + TF_LITE_KERNEL_LOG(context, "Type %s not currently supported.", + TfLiteTypeGetName(weights_feature->type)); + return kTfLiteError; + } + return kTfLiteOk; +} + +} // namespace + +TfLiteRegistration Register_SVDF() +{ + return { /*init=*/Init, + /*free=*/nullptr, + /*prepare=*/Prepare, + /*invoke=*/Eval, + /*profiling_string=*/nullptr, + /*builtin_code=*/0, + /*custom_name=*/nullptr, + /*version=*/0 }; +} + +} // namespace tflite diff --git a/components/tflite/third_party/kissfft/_kiss_fft_guts.h b/components/tflite/third_party/kissfft/_kiss_fft_guts.h new file mode 100644 index 00000000..28835996 --- /dev/null +++ b/components/tflite/third_party/kissfft/_kiss_fft_guts.h @@ -0,0 +1,175 @@ +/* +Copyright (c) 2003-2010, Mark Borgerding + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* kiss_fft.h + defines kiss_fft_scalar as either short or a float type + and defines + typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */ +#include "kiss_fft.h" +#include + +#define MAXFACTORS 32 +/* e.g. an fft of length 128 has 4 factors + as far as kissfft is concerned + 4*4*4*2 + */ + +struct kiss_fft_state { + int nfft; + int inverse; + int factors[2 * MAXFACTORS]; + kiss_fft_cpx twiddles[1]; +}; + +/* + Explanation of macros dealing with complex math: + + C_MUL(m,a,b) : m = a*b + C_FIXDIV( c , div ) : if a fixed point impl., c /= div. noop otherwise + C_SUB( res, a,b) : res = a - b + C_SUBFROM( res , a) : res -= a + C_ADDTO( res , a) : res += a + * */ +#ifdef FIXED_POINT +#if (FIXED_POINT == 32) +#define FRACBITS 31 +#define SAMPPROD int64_t +#define SAMP_MAX 2147483647 +#else +#define FRACBITS 15 +#define SAMPPROD int32_t +#define SAMP_MAX 32767 +#endif + +#define SAMP_MIN -SAMP_MAX + +#if defined(CHECK_OVERFLOW) +#define CHECK_OVERFLOW_OP(a, op, b) \ + if ((SAMPPROD)(a)op(SAMPPROD)(b) > SAMP_MAX || (SAMPPROD)(a)op(SAMPPROD)(b) < SAMP_MIN) { \ + fprintf(stderr, "WARNING:overflow @ " __FILE__ "(%d): (%d " #op " %d) = %ld\n", __LINE__, (a), (b), (SAMPPROD)(a)op(SAMPPROD)(b)); \ + } +#endif + +#define smul(a, b) ((SAMPPROD)(a) * (b)) +#define sround(x) (kiss_fft_scalar)(((x) + (1 << (FRACBITS - 1))) >> FRACBITS) + +#define S_MUL(a, b) sround(smul(a, b)) + +#define C_MUL(m, a, b) \ + do { \ + (m).r = sround(smul((a).r, (b).r) - smul((a).i, (b).i)); \ + (m).i = sround(smul((a).r, (b).i) + smul((a).i, (b).r)); \ + } while (0) + +#define DIVSCALAR(x, k) \ + (x) = sround(smul(x, SAMP_MAX / k)) + +#define C_FIXDIV(c, div) \ + do { \ + DIVSCALAR((c).r, div); \ + DIVSCALAR((c).i, div); \ + } while (0) + +#define C_MULBYSCALAR(c, s) \ + do { \ + (c).r = sround(smul((c).r, s)); \ + (c).i = sround(smul((c).i, s)); \ + } while (0) + +#else /* not FIXED_POINT*/ + +#define S_MUL(a, b) ((a) * (b)) +#define C_MUL(m, a, b) \ + do { \ + (m).r = (a).r * (b).r - (a).i * (b).i; \ + (m).i = (a).r * (b).i + (a).i * (b).r; \ + } while (0) +#define C_FIXDIV(c, div) /* NOOP */ +#define C_MULBYSCALAR(c, s) \ + do { \ + (c).r *= (s); \ + (c).i *= (s); \ + } while (0) +#endif + +#ifndef CHECK_OVERFLOW_OP +#define CHECK_OVERFLOW_OP(a, op, b) /* noop */ +#endif + +#define C_ADD(res, a, b) \ + do { \ + CHECK_OVERFLOW_OP((a).r, +, (b).r) \ + CHECK_OVERFLOW_OP((a).i, +, (b).i) \ + (res).r = (a).r + (b).r; \ + (res).i = (a).i + (b).i; \ + } while (0) +#define C_SUB(res, a, b) \ + do { \ + CHECK_OVERFLOW_OP((a).r, -, (b).r) \ + CHECK_OVERFLOW_OP((a).i, -, (b).i) \ + (res).r = (a).r - (b).r; \ + (res).i = (a).i - (b).i; \ + } while (0) +#define C_ADDTO(res, a) \ + do { \ + CHECK_OVERFLOW_OP((res).r, +, (a).r) \ + CHECK_OVERFLOW_OP((res).i, +, (a).i) \ + (res).r += (a).r; \ + (res).i += (a).i; \ + } while (0) + +#define C_SUBFROM(res, a) \ + do { \ + CHECK_OVERFLOW_OP((res).r, -, (a).r) \ + CHECK_OVERFLOW_OP((res).i, -, (a).i) \ + (res).r -= (a).r; \ + (res).i -= (a).i; \ + } while (0) + +#ifdef FIXED_POINT +#define KISS_FFT_COS(phase) floor(.5 + SAMP_MAX * cos(phase)) +#define KISS_FFT_SIN(phase) floor(.5 + SAMP_MAX * sin(phase)) +#define HALF_OF(x) ((x) >> 1) +#elif defined(USE_SIMD) +#define KISS_FFT_COS(phase) _mm_set1_ps(cos(phase)) +#define KISS_FFT_SIN(phase) _mm_set1_ps(sin(phase)) +#define HALF_OF(x) ((x)*_mm_set1_ps(.5)) +#else +#define KISS_FFT_COS(phase) (kiss_fft_scalar) cos(phase) +#define KISS_FFT_SIN(phase) (kiss_fft_scalar) sin(phase) +#define HALF_OF(x) ((x)*.5) +#endif + +#define kf_cexp(x, phase) \ + do { \ + (x)->r = KISS_FFT_COS(phase); \ + (x)->i = KISS_FFT_SIN(phase); \ + } while (0) + +/* a debugging function */ +#define pcpx(c) \ + fprintf(stderr, "%g + %gi\n", (double)((c)->r), (double)((c)->i)) + +#ifdef KISS_FFT_USE_ALLOCA +// define this to allow use of alloca instead of malloc for temporary buffers +// Temporary buffers are used in two case: +// 1. FFT sizes that have "bad" factors. i.e. not 2,3 and 5 +// 2. "in-place" FFTs. Notice the quotes, since kissfft does not really do an in-place transform. +#include +#define KISS_FFT_TMP_ALLOC(nbytes) alloca(nbytes) +#define KISS_FFT_TMP_FREE(ptr) +#else +#define KISS_FFT_TMP_ALLOC(nbytes) KISS_FFT_MALLOC(nbytes) +#define KISS_FFT_TMP_FREE(ptr) KISS_FFT_FREE(ptr) +#endif diff --git a/components/tflite/third_party/kissfft/kiss_fft.c b/components/tflite/third_party/kissfft/kiss_fft.c new file mode 100644 index 00000000..33eae186 --- /dev/null +++ b/components/tflite/third_party/kissfft/kiss_fft.c @@ -0,0 +1,438 @@ +/* +Copyright (c) 2003-2010, Mark Borgerding + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "_kiss_fft_guts.h" +/* The guts header contains all the multiplication and addition macros that are defined for + fixed or floating point complex numbers. It also delares the kf_ internal functions. + */ + +static void kf_bfly2( + kiss_fft_cpx *Fout, + const size_t fstride, + const kiss_fft_cfg st, + int m) +{ + kiss_fft_cpx *Fout2; + kiss_fft_cpx *tw1 = st->twiddles; + kiss_fft_cpx t; + Fout2 = Fout + m; + do { + C_FIXDIV(*Fout, 2); + C_FIXDIV(*Fout2, 2); + + C_MUL(t, *Fout2, *tw1); + tw1 += fstride; + C_SUB(*Fout2, *Fout, t); + C_ADDTO(*Fout, t); + ++Fout2; + ++Fout; + } while (--m); +} + +static void kf_bfly4( + kiss_fft_cpx *Fout, + const size_t fstride, + const kiss_fft_cfg st, + const size_t m) +{ + kiss_fft_cpx *tw1, *tw2, *tw3; + kiss_fft_cpx scratch[6]; + size_t k = m; + const size_t m2 = 2 * m; + const size_t m3 = 3 * m; + + tw3 = tw2 = tw1 = st->twiddles; + + do { + C_FIXDIV(*Fout, 4); + C_FIXDIV(Fout[m], 4); + C_FIXDIV(Fout[m2], 4); + C_FIXDIV(Fout[m3], 4); + + C_MUL(scratch[0], Fout[m], *tw1); + C_MUL(scratch[1], Fout[m2], *tw2); + C_MUL(scratch[2], Fout[m3], *tw3); + + C_SUB(scratch[5], *Fout, scratch[1]); + C_ADDTO(*Fout, scratch[1]); + C_ADD(scratch[3], scratch[0], scratch[2]); + C_SUB(scratch[4], scratch[0], scratch[2]); + C_SUB(Fout[m2], *Fout, scratch[3]); + tw1 += fstride; + tw2 += fstride * 2; + tw3 += fstride * 3; + C_ADDTO(*Fout, scratch[3]); + + if (st->inverse) { + Fout[m].r = scratch[5].r - scratch[4].i; + Fout[m].i = scratch[5].i + scratch[4].r; + Fout[m3].r = scratch[5].r + scratch[4].i; + Fout[m3].i = scratch[5].i - scratch[4].r; + } else { + Fout[m].r = scratch[5].r + scratch[4].i; + Fout[m].i = scratch[5].i - scratch[4].r; + Fout[m3].r = scratch[5].r - scratch[4].i; + Fout[m3].i = scratch[5].i + scratch[4].r; + } + ++Fout; + } while (--k); +} + +static void kf_bfly3( + kiss_fft_cpx *Fout, + const size_t fstride, + const kiss_fft_cfg st, + size_t m) +{ + size_t k = m; + const size_t m2 = 2 * m; + kiss_fft_cpx *tw1, *tw2; + kiss_fft_cpx scratch[5]; + kiss_fft_cpx epi3; + epi3 = st->twiddles[fstride * m]; + + tw1 = tw2 = st->twiddles; + + do { + C_FIXDIV(*Fout, 3); + C_FIXDIV(Fout[m], 3); + C_FIXDIV(Fout[m2], 3); + + C_MUL(scratch[1], Fout[m], *tw1); + C_MUL(scratch[2], Fout[m2], *tw2); + + C_ADD(scratch[3], scratch[1], scratch[2]); + C_SUB(scratch[0], scratch[1], scratch[2]); + tw1 += fstride; + tw2 += fstride * 2; + + Fout[m].r = Fout->r - HALF_OF(scratch[3].r); + Fout[m].i = Fout->i - HALF_OF(scratch[3].i); + + C_MULBYSCALAR(scratch[0], epi3.i); + + C_ADDTO(*Fout, scratch[3]); + + Fout[m2].r = Fout[m].r + scratch[0].i; + Fout[m2].i = Fout[m].i - scratch[0].r; + + Fout[m].r -= scratch[0].i; + Fout[m].i += scratch[0].r; + + ++Fout; + } while (--k); +} + +static void kf_bfly5( + kiss_fft_cpx *Fout, + const size_t fstride, + const kiss_fft_cfg st, + int m) +{ + kiss_fft_cpx *Fout0, *Fout1, *Fout2, *Fout3, *Fout4; + int u; + kiss_fft_cpx scratch[13]; + kiss_fft_cpx *twiddles = st->twiddles; + kiss_fft_cpx *tw; + kiss_fft_cpx ya, yb; + ya = twiddles[fstride * m]; + yb = twiddles[fstride * 2 * m]; + + Fout0 = Fout; + Fout1 = Fout0 + m; + Fout2 = Fout0 + 2 * m; + Fout3 = Fout0 + 3 * m; + Fout4 = Fout0 + 4 * m; + + tw = st->twiddles; + for (u = 0; u < m; ++u) { + C_FIXDIV(*Fout0, 5); + C_FIXDIV(*Fout1, 5); + C_FIXDIV(*Fout2, 5); + C_FIXDIV(*Fout3, 5); + C_FIXDIV(*Fout4, 5); + scratch[0] = *Fout0; + + C_MUL(scratch[1], *Fout1, tw[u * fstride]); + C_MUL(scratch[2], *Fout2, tw[2 * u * fstride]); + C_MUL(scratch[3], *Fout3, tw[3 * u * fstride]); + C_MUL(scratch[4], *Fout4, tw[4 * u * fstride]); + + C_ADD(scratch[7], scratch[1], scratch[4]); + C_SUB(scratch[10], scratch[1], scratch[4]); + C_ADD(scratch[8], scratch[2], scratch[3]); + C_SUB(scratch[9], scratch[2], scratch[3]); + + Fout0->r += scratch[7].r + scratch[8].r; + Fout0->i += scratch[7].i + scratch[8].i; + + scratch[5].r = scratch[0].r + S_MUL(scratch[7].r, ya.r) + S_MUL(scratch[8].r, yb.r); + scratch[5].i = scratch[0].i + S_MUL(scratch[7].i, ya.r) + S_MUL(scratch[8].i, yb.r); + + scratch[6].r = S_MUL(scratch[10].i, ya.i) + S_MUL(scratch[9].i, yb.i); + scratch[6].i = -S_MUL(scratch[10].r, ya.i) - S_MUL(scratch[9].r, yb.i); + + C_SUB(*Fout1, scratch[5], scratch[6]); + C_ADD(*Fout4, scratch[5], scratch[6]); + + scratch[11].r = scratch[0].r + S_MUL(scratch[7].r, yb.r) + S_MUL(scratch[8].r, ya.r); + scratch[11].i = scratch[0].i + S_MUL(scratch[7].i, yb.r) + S_MUL(scratch[8].i, ya.r); + scratch[12].r = -S_MUL(scratch[10].i, yb.i) + S_MUL(scratch[9].i, ya.i); + scratch[12].i = S_MUL(scratch[10].r, yb.i) - S_MUL(scratch[9].r, ya.i); + + C_ADD(*Fout2, scratch[11], scratch[12]); + C_SUB(*Fout3, scratch[11], scratch[12]); + + ++Fout0; + ++Fout1; + ++Fout2; + ++Fout3; + ++Fout4; + } +} + +/* perform the butterfly for one stage of a mixed radix FFT */ +static void kf_bfly_generic( + kiss_fft_cpx *Fout, + const size_t fstride, + const kiss_fft_cfg st, + int m, + int p) +{ + int u, k, q1, q; + kiss_fft_cpx *twiddles = st->twiddles; + kiss_fft_cpx t; + int Norig = st->nfft; + + kiss_fft_cpx *scratch = (kiss_fft_cpx *)KISS_FFT_TMP_ALLOC(sizeof(kiss_fft_cpx) * p); + + for (u = 0; u < m; ++u) { + k = u; + for (q1 = 0; q1 < p; ++q1) { + scratch[q1] = Fout[k]; + C_FIXDIV(scratch[q1], p); + k += m; + } + + k = u; + for (q1 = 0; q1 < p; ++q1) { + int twidx = 0; + Fout[k] = scratch[0]; + for (q = 1; q < p; ++q) { + twidx += fstride * k; + if (twidx >= Norig) + twidx -= Norig; + C_MUL(t, scratch[q], twiddles[twidx]); + C_ADDTO(Fout[k], t); + } + k += m; + } + } + KISS_FFT_TMP_FREE(scratch); +} + +static void kf_work( + kiss_fft_cpx *Fout, + const kiss_fft_cpx *f, + const size_t fstride, + int in_stride, + int *factors, + const kiss_fft_cfg st) +{ + kiss_fft_cpx *Fout_beg = Fout; + const int p = *factors++; /* the radix */ + const int m = *factors++; /* stage's fft length/p */ + const kiss_fft_cpx *Fout_end = Fout + p * m; + +#ifdef _OPENMP + // use openmp extensions at the + // top-level (not recursive) + if (fstride == 1 && p <= 5) { + int k; + + // execute the p different work units in different threads +#pragma omp parallel for + for (k = 0; k < p; ++k) + kf_work(Fout + k * m, f + fstride * in_stride * k, fstride * p, in_stride, factors, st); + // all threads have joined by this point + + switch (p) { + case 2: + kf_bfly2(Fout, fstride, st, m); + break; + case 3: + kf_bfly3(Fout, fstride, st, m); + break; + case 4: + kf_bfly4(Fout, fstride, st, m); + break; + case 5: + kf_bfly5(Fout, fstride, st, m); + break; + default: + kf_bfly_generic(Fout, fstride, st, m, p); + break; + } + return; + } +#endif + + if (m == 1) { + do { + *Fout = *f; + f += fstride * in_stride; + } while (++Fout != Fout_end); + } else { + do { + // recursive call: + // DFT of size m*p performed by doing + // p instances of smaller DFTs of size m, + // each one takes a decimated version of the input + kf_work(Fout, f, fstride * p, in_stride, factors, st); + f += fstride * in_stride; + } while ((Fout += m) != Fout_end); + } + + Fout = Fout_beg; + + // recombine the p smaller DFTs + switch (p) { + case 2: + kf_bfly2(Fout, fstride, st, m); + break; + case 3: + kf_bfly3(Fout, fstride, st, m); + break; + case 4: + kf_bfly4(Fout, fstride, st, m); + break; + case 5: + kf_bfly5(Fout, fstride, st, m); + break; + default: + kf_bfly_generic(Fout, fstride, st, m, p); + break; + } +} + +/* facbuf is populated by p1,m1,p2,m2, ... + where + p[i] * m[i] = m[i-1] + m0 = n */ +static void kf_factor(int n, int *facbuf) +{ + int p = 4; + double floor_sqrt; + floor_sqrt = floor(sqrt((double)n)); + + /*factor out powers of 4, powers of 2, then any remaining primes */ + do { + while (n % p) { + switch (p) { + case 4: + p = 2; + break; + case 2: + p = 3; + break; + default: + p += 2; + break; + } + if (p > floor_sqrt) + p = n; /* no more factors, skip to end */ + } + n /= p; + *facbuf++ = p; + *facbuf++ = n; + } while (n > 1); +} + +/* + * + * User-callable function to allocate all necessary storage space for the fft. + * + * The return value is a contiguous block of memory, allocated with malloc. As such, + * It can be freed with free(), rather than a kiss_fft-specific function. + * */ +kiss_fft_cfg kiss_fft_alloc(int nfft, int inverse_fft, void *mem, size_t *lenmem) +{ + kiss_fft_cfg st = NULL; + size_t memneeded = sizeof(struct kiss_fft_state) + sizeof(kiss_fft_cpx) * (nfft - 1); /* twiddle factors*/ + + if (lenmem == NULL) { + st = (kiss_fft_cfg)KISS_FFT_MALLOC(memneeded); + } else { + if (mem != NULL && *lenmem >= memneeded) + st = (kiss_fft_cfg)mem; + *lenmem = memneeded; + } + if (st) { + int i; + st->nfft = nfft; + st->inverse = inverse_fft; + + for (i = 0; i < nfft; ++i) { + const double pi = 3.141592653589793238462643383279502884197169399375105820974944; + double phase = -2 * pi * i / nfft; + if (st->inverse) + phase *= -1; + kf_cexp(st->twiddles + i, phase); + } + + kf_factor(nfft, st->factors); + } + return st; +} + +void kiss_fft_stride(kiss_fft_cfg st, const kiss_fft_cpx *fin, kiss_fft_cpx *fout, int in_stride) +{ + if (fin == fout) { + //NOTE: this is not really an in-place FFT algorithm. + //It just performs an out-of-place FFT into a temp buffer + kiss_fft_cpx *tmpbuf = (kiss_fft_cpx *)KISS_FFT_TMP_ALLOC(sizeof(kiss_fft_cpx) * st->nfft); + kf_work(tmpbuf, fin, 1, in_stride, st->factors, st); + memcpy(fout, tmpbuf, sizeof(kiss_fft_cpx) * st->nfft); + KISS_FFT_TMP_FREE(tmpbuf); + } else { + kf_work(fout, fin, 1, in_stride, st->factors, st); + } +} + +void kiss_fft(kiss_fft_cfg cfg, const kiss_fft_cpx *fin, kiss_fft_cpx *fout) +{ + kiss_fft_stride(cfg, fin, fout, 1); +} + +void kiss_fft_cleanup(void) +{ + // nothing needed any more +} + +int kiss_fft_next_fast_size(int n) +{ + while (1) { + int m = n; + while ((m % 2) == 0) + m /= 2; + while ((m % 3) == 0) + m /= 3; + while ((m % 5) == 0) + m /= 5; + if (m <= 1) + break; /* n is completely factorable by twos, threes, and fives */ + n++; + } + return n; +} diff --git a/components/tflite/third_party/kissfft/kiss_fft.h b/components/tflite/third_party/kissfft/kiss_fft.h new file mode 100644 index 00000000..c288d47e --- /dev/null +++ b/components/tflite/third_party/kissfft/kiss_fft.h @@ -0,0 +1,129 @@ +#ifndef KISS_FFT_H +#define KISS_FFT_H + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + ATTENTION! + If you would like a : + -- a utility that will handle the caching of fft objects + -- real-only (no imaginary time component ) FFT + -- a multi-dimensional FFT + -- a command-line utility to perform ffts + -- a command-line utility to perform fast-convolution filtering + + Then see kfc.h kiss_fftr.h kiss_fftnd.h fftutil.c kiss_fastfir.c + in the tools/ directory. +*/ + +#ifdef USE_SIMD +#include +#define kiss_fft_scalar __m128 +#define KISS_FFT_MALLOC(nbytes) _mm_malloc(nbytes, 16) +#define KISS_FFT_FREE _mm_free +#else +#define KISS_FFT_MALLOC(X) (void *)(0) /* Patched. */ +#define KISS_FFT_FREE(X) /* Patched. */ +#endif + +// Patched automatically by download_dependencies.sh so default is 16 bit. +#ifndef FIXED_POINT +#define FIXED_POINT (16) +#endif +// End patch. + +#ifdef FIXED_POINT +#include /* Patched. */ +#include +#if (FIXED_POINT == 32) +#define kiss_fft_scalar int32_t +#else +#define kiss_fft_scalar int16_t +#endif +#else +#ifndef kiss_fft_scalar +/* default is float */ +#define kiss_fft_scalar float +#endif +#endif + +typedef struct { + kiss_fft_scalar r; + kiss_fft_scalar i; +} kiss_fft_cpx; + +typedef struct kiss_fft_state *kiss_fft_cfg; + +/* + * kiss_fft_alloc + * + * Initialize a FFT (or IFFT) algorithm's cfg/state buffer. + * + * typical usage: kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL); + * + * The return value from fft_alloc is a cfg buffer used internally + * by the fft routine or NULL. + * + * If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc. + * The returned value should be free()d when done to avoid memory leaks. + * + * The state can be placed in a user supplied buffer 'mem': + * If lenmem is not NULL and mem is not NULL and *lenmem is large enough, + * then the function places the cfg in mem and the size used in *lenmem + * and returns mem. + * + * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough), + * then the function returns NULL and places the minimum cfg + * buffer size in *lenmem. + * */ + +kiss_fft_cfg kiss_fft_alloc(int nfft, int inverse_fft, void *mem, size_t *lenmem); + +/* + * kiss_fft(cfg,in_out_buf) + * + * Perform an FFT on a complex input buffer. + * for a forward FFT, + * fin should be f[0] , f[1] , ... ,f[nfft-1] + * fout will be F[0] , F[1] , ... ,F[nfft-1] + * Note that each element is complex and can be accessed like + f[k].r and f[k].i + * */ +void kiss_fft(kiss_fft_cfg cfg, const kiss_fft_cpx *fin, kiss_fft_cpx *fout); + +/* + A more generic version of the above function. It reads its input from every Nth sample. + * */ +void kiss_fft_stride(kiss_fft_cfg cfg, const kiss_fft_cpx *fin, kiss_fft_cpx *fout, int fin_stride); + +/* If kiss_fft_alloc allocated a buffer, it is one contiguous + buffer and can be simply free()d when no longer needed*/ +#define kiss_fft_free free + +/* + Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up + your compiler output to call this before you exit. +*/ +void kiss_fft_cleanup(void); + +/* + * Returns the smallest integer k, such that k>=n and k has only "fast" factors (2,3,5) + */ +int kiss_fft_next_fast_size(int n); + +/* for real ffts, we need an even size */ +#define kiss_fftr_next_fast_size_real(n) \ + (kiss_fft_next_fast_size(((n) + 1) >> 1) << 1) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/components/tflite/third_party/kissfft/tools/kiss_fftr.c b/components/tflite/third_party/kissfft/tools/kiss_fftr.c new file mode 100644 index 00000000..3f567a66 --- /dev/null +++ b/components/tflite/third_party/kissfft/tools/kiss_fftr.c @@ -0,0 +1,159 @@ +/* +Copyright (c) 2003-2004, Mark Borgerding + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "kiss_fftr.h" +#include "_kiss_fft_guts.h" + +struct kiss_fftr_state { + kiss_fft_cfg substate; + kiss_fft_cpx *tmpbuf; + kiss_fft_cpx *super_twiddles; +#ifdef USE_SIMD + void *pad; +#endif +}; + +kiss_fftr_cfg kiss_fftr_alloc(int nfft, int inverse_fft, void *mem, size_t *lenmem) +{ + int i; + kiss_fftr_cfg st = NULL; + size_t subsize, memneeded; + + if (nfft & 1) { + /* fprintf(stderr,"Real FFT optimization must be even.\n"); */ + return NULL; + } + nfft >>= 1; + + kiss_fft_alloc(nfft, inverse_fft, NULL, &subsize); + memneeded = sizeof(struct kiss_fftr_state) + subsize + sizeof(kiss_fft_cpx) * (nfft * 3 / 2); + + if (lenmem == NULL) { + st = (kiss_fftr_cfg)KISS_FFT_MALLOC(memneeded); + } else { + if (*lenmem >= memneeded) + st = (kiss_fftr_cfg)mem; + *lenmem = memneeded; + } + if (!st) + return NULL; + + st->substate = (kiss_fft_cfg)(st + 1); /*just beyond kiss_fftr_state struct */ + st->tmpbuf = (kiss_fft_cpx *)(((char *)st->substate) + subsize); + st->super_twiddles = st->tmpbuf + nfft; + kiss_fft_alloc(nfft, inverse_fft, st->substate, &subsize); + + for (i = 0; i < nfft / 2; ++i) { + double phase = + -3.14159265358979323846264338327 * ((double)(i + 1) / nfft + .5); + if (inverse_fft) + phase *= -1; + kf_cexp(st->super_twiddles + i, phase); + } + return st; +} + +void kiss_fftr(kiss_fftr_cfg st, const kiss_fft_scalar *timedata, kiss_fft_cpx *freqdata) +{ + /* input buffer timedata is stored row-wise */ + int k, ncfft; + kiss_fft_cpx fpnk, fpk, f1k, f2k, tw, tdc; + + if (st->substate->inverse) { + /* fprintf(stderr,"kiss fft usage error: improper alloc\n"); */ + return; /* exit(1); */ + } + + ncfft = st->substate->nfft; + + /*perform the parallel fft of two real signals packed in real,imag*/ + kiss_fft(st->substate, (const kiss_fft_cpx *)timedata, st->tmpbuf); + /* The real part of the DC element of the frequency spectrum in st->tmpbuf + * contains the sum of the even-numbered elements of the input time sequence + * The imag part is the sum of the odd-numbered elements + * + * The sum of tdc.r and tdc.i is the sum of the input time sequence. + * yielding DC of input time sequence + * The difference of tdc.r - tdc.i is the sum of the input (dot product) [1,-1,1,-1... + * yielding Nyquist bin of input time sequence + */ + + tdc.r = st->tmpbuf[0].r; + tdc.i = st->tmpbuf[0].i; + C_FIXDIV(tdc, 2); + CHECK_OVERFLOW_OP(tdc.r, +, tdc.i); + CHECK_OVERFLOW_OP(tdc.r, -, tdc.i); + freqdata[0].r = tdc.r + tdc.i; + freqdata[ncfft].r = tdc.r - tdc.i; +#ifdef USE_SIMD + freqdata[ncfft].i = freqdata[0].i = _mm_set1_ps(0); +#else + freqdata[ncfft].i = freqdata[0].i = 0; +#endif + + for (k = 1; k <= ncfft / 2; ++k) { + fpk = st->tmpbuf[k]; + fpnk.r = st->tmpbuf[ncfft - k].r; + fpnk.i = -st->tmpbuf[ncfft - k].i; + C_FIXDIV(fpk, 2); + C_FIXDIV(fpnk, 2); + + C_ADD(f1k, fpk, fpnk); + C_SUB(f2k, fpk, fpnk); + C_MUL(tw, f2k, st->super_twiddles[k - 1]); + + freqdata[k].r = HALF_OF(f1k.r + tw.r); + freqdata[k].i = HALF_OF(f1k.i + tw.i); + freqdata[ncfft - k].r = HALF_OF(f1k.r - tw.r); + freqdata[ncfft - k].i = HALF_OF(tw.i - f1k.i); + } +} + +void kiss_fftri(kiss_fftr_cfg st, const kiss_fft_cpx *freqdata, kiss_fft_scalar *timedata) +{ + /* input buffer timedata is stored row-wise */ + int k, ncfft; + + if (st->substate->inverse == 0) { + /* fprintf (stderr, "kiss fft usage error: improper alloc\n"); */ + return; /* exit (1); */ + } + + ncfft = st->substate->nfft; + + st->tmpbuf[0].r = freqdata[0].r + freqdata[ncfft].r; + st->tmpbuf[0].i = freqdata[0].r - freqdata[ncfft].r; + C_FIXDIV(st->tmpbuf[0], 2); + + for (k = 1; k <= ncfft / 2; ++k) { + kiss_fft_cpx fk, fnkc, fek, fok, tmp; + fk = freqdata[k]; + fnkc.r = freqdata[ncfft - k].r; + fnkc.i = -freqdata[ncfft - k].i; + C_FIXDIV(fk, 2); + C_FIXDIV(fnkc, 2); + + C_ADD(fek, fk, fnkc); + C_SUB(tmp, fk, fnkc); + C_MUL(fok, tmp, st->super_twiddles[k - 1]); + C_ADD(st->tmpbuf[k], fek, fok); + C_SUB(st->tmpbuf[ncfft - k], fek, fok); +#ifdef USE_SIMD + st->tmpbuf[ncfft - k].i *= _mm_set1_ps(-1.0); +#else + st->tmpbuf[ncfft - k].i *= -1; +#endif + } + kiss_fft(st->substate, st->tmpbuf, (kiss_fft_cpx *)timedata); +} diff --git a/components/tflite/third_party/kissfft/tools/kiss_fftr.h b/components/tflite/third_party/kissfft/tools/kiss_fftr.h new file mode 100644 index 00000000..cd7b710b --- /dev/null +++ b/components/tflite/third_party/kissfft/tools/kiss_fftr.h @@ -0,0 +1,43 @@ +#ifndef KISS_FTR_H +#define KISS_FTR_H + +#include "kiss_fft.h" +#ifdef __cplusplus +extern "C" { +#endif + +/* + + Real optimized version can save about 45% cpu time vs. complex fft of a real seq. + + + + */ + +typedef struct kiss_fftr_state *kiss_fftr_cfg; + +kiss_fftr_cfg kiss_fftr_alloc(int nfft, int inverse_fft, void *mem, size_t *lenmem); +/* + nfft must be even + + If you don't care to allocate space, use mem = lenmem = NULL +*/ + +void kiss_fftr(kiss_fftr_cfg cfg, const kiss_fft_scalar *timedata, kiss_fft_cpx *freqdata); +/* + input timedata has nfft scalar points + output freqdata has nfft/2+1 complex points +*/ + +void kiss_fftri(kiss_fftr_cfg cfg, const kiss_fft_cpx *freqdata, kiss_fft_scalar *timedata); +/* + input freqdata has nfft/2+1 complex points + output timedata has nfft scalar points +*/ + +#define kiss_fftr_free free + +#ifdef __cplusplus +} +#endif +#endif diff --git a/components/tflite/third_party/ruy/ruy/profiler/instrumentation.h b/components/tflite/third_party/ruy/ruy/profiler/instrumentation.h new file mode 100644 index 00000000..c4dc71a8 --- /dev/null +++ b/components/tflite/third_party/ruy/ruy/profiler/instrumentation.h @@ -0,0 +1,230 @@ +/* Copyright 2020 Google LLC. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef RUY_RUY_PROFILER_INSTRUMENTATION_H_ +#define RUY_RUY_PROFILER_INSTRUMENTATION_H_ + +#ifdef RUY_PROFILER +#include +#include +#include +#endif + +namespace ruy { +namespace profiler { +#ifdef RUY_PROFILER + +// A label is how a code scope is annotated to appear in profiles. +// The stacks that are sampled by the profiler are stacks of such labels. +// A label consists of a literal string, plus optional integer arguments. +class Label { +public: + Label() + { + } + template + explicit Label(Args... args) + { + Set(args...); + } + void Set(const char *format) + { + format_ = format; + args_count_ = 0; + } + template + void Set(const char *format, Args... args) + { + format_ = format; + args_count_ = sizeof...(args); + SetArgs(0, args...); + } + + void operator=(const Label &other); + + bool operator==(const Label &other) const; + + std::string Formatted() const; + const char *format() const + { + return format_; + } + +private: + void SetArgs(int position, int arg0) + { + args_[position] = arg0; + } + + template + void SetArgs(int position, int arg0, Args... args) + { + SetArgs(position, arg0); + SetArgs(position + 1, args...); + } + + static constexpr int kMaxArgs = 4; + const char *format_ = nullptr; + int args_count_ = 0; + int args_[kMaxArgs]; +}; + +namespace detail { +// Forward-declaration, see class ThreadStack below. +class ThreadStack; + +bool &GlobalIsProfilerRunning(); + +// Returns the global vector of pointers to all stacks, there being one stack +// per thread executing instrumented code. +std::vector *GlobalAllThreadStacks(); + +// Returns the mutex to be locked around any access to GlobalAllThreadStacks(). +std::mutex *GlobalsMutex(); + +// Returns the thread-local stack, specific to the current thread. +ThreadStack *ThreadLocalThreadStack(); + +// This 'stack' is what may be more appropriately called a 'pseudostack': +// It contains Label entries that are 'manually' entered by instrumentation +// code. It's unrelated to real call stacks. +struct Stack { + std::uint32_t id = 0; + static constexpr int kMaxSize = 64; + int size = 0; + Label labels[kMaxSize]; +}; + +// Returns the buffer byte size required by CopyToSample. +int GetBufferSize(const Stack &stack); + +// Copies this Stack into a byte buffer, called a 'sample'. +void CopyToBuffer(const Stack &stack, char *dst); + +// Populates this Stack from an existing sample buffer, typically +// produced by CopyToSample. +void ReadFromBuffer(const char *src, Stack *stack); + +// ThreadStack is meant to be used as a thread-local singleton, assigning to +// each thread a Stack object holding its pseudo-stack of profile labels, +// plus a mutex allowing to synchronize accesses to this pseudo-stack between +// this thread and a possible profiler thread sampling it. +class ThreadStack { +public: + ThreadStack(); + ~ThreadStack(); + + const Stack &stack() const + { + return stack_; + } + + // Returns the mutex to lock around any access to this stack. Each stack is + // accessed by potentially two threads: the thread that it belongs to + // (which calls Push and Pop) and the profiler thread during profiling + // (which calls CopyToSample). + std::mutex &Mutex() const + { + return mutex_; + } + + // Pushes a new label on the top of this Stack. + template + void Push(Args... args) + { + // This mutex locking is needed to guard against race conditions as both + // the current thread and the profiler thread may be concurrently accessing + // this stack. In addition to that, this mutex locking also serves the other + // purpose of acting as a barrier (of compiler code reordering, of runtime + // CPU instruction reordering, and of memory access reordering), which + // gives a measure of correctness to this profiler. The downside is some + // latency. As this lock will be uncontended most of the times, the cost + // should be roughly that of an sequentially-consistent atomic access, + // comparable to an access to the level of CPU data cache that is shared + // among all cores, typically 60 cycles on current ARM CPUs, plus side + // effects from barrier instructions. + std::lock_guard lock(mutex_); + // Avoid overrunning the stack, even in 'release' builds. This profiling + // instrumentation code should not ship in release builds anyway, the + // overhead of this check is negligible, and overrunning a stack array would + // be bad. + if (stack_.size >= Stack::kMaxSize) { + abort(); + } + stack_.labels[stack_.size++].Set(args...); + } + + // Pops the top-most label from this Stack. + void Pop() + { + // See the comment in Push about this lock. While it would be tempting to + // try to remove this lock and just atomically decrement size_ with a + // store-release, that would not necessarily be a substitute for all of the + // purposes that this lock serves, or if it was done carefully to serve all + // of the same purposes, then that wouldn't be faster than this (mostly + // uncontended) lock. + std::lock_guard lock(mutex_); + stack_.size--; + } + +private: + mutable std::mutex mutex_; + Stack stack_; +}; + +} // namespace detail + +// RAII user-facing way to construct Labels associated with their life scope +// and get them pushed to / popped from the current thread stack. +class ScopeLabel { +public: + template + ScopeLabel(Args... args) + : thread_stack_(detail::ThreadLocalThreadStack()) + { + thread_stack_->Push(args...); + } + + ~ScopeLabel() + { + thread_stack_->Pop(); + } + +private: + detail::ThreadStack *thread_stack_; +}; + +#else // no RUY_PROFILER + +class ScopeLabel { +public: + template + explicit ScopeLabel(Args...) + { + } + + // This destructor is needed to consistently silence clang's -Wunused-variable + // which seems to trigger semi-randomly. + ~ScopeLabel() + { + } +}; + +#endif + +} // namespace profiler +} // namespace ruy + +#endif // RUY_RUY_PROFILER_INSTRUMENTATION_H_