xmos-ai-tools 1.3.2.dev80__py3-none-macosx_10_15_universal2.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (395) hide show
  1. xmos_ai_tools/__init__.py +7 -0
  2. xmos_ai_tools/io_server/__init__.py +151 -0
  3. xmos_ai_tools/runtime/__init__.py +0 -0
  4. xmos_ai_tools/runtime/buildfiles/aitoolslib.cmake +13 -0
  5. xmos_ai_tools/runtime/buildfiles/aitoolslib.make +8 -0
  6. xmos_ai_tools/runtime/include/flash_server.h +74 -0
  7. xmos_ai_tools/runtime/include/flatbuffers/allocator.h +68 -0
  8. xmos_ai_tools/runtime/include/flatbuffers/array.h +243 -0
  9. xmos_ai_tools/runtime/include/flatbuffers/base.h +474 -0
  10. xmos_ai_tools/runtime/include/flatbuffers/bfbs_generator.h +43 -0
  11. xmos_ai_tools/runtime/include/flatbuffers/buffer.h +142 -0
  12. xmos_ai_tools/runtime/include/flatbuffers/buffer_ref.h +53 -0
  13. xmos_ai_tools/runtime/include/flatbuffers/code_generators.h +235 -0
  14. xmos_ai_tools/runtime/include/flatbuffers/default_allocator.h +64 -0
  15. xmos_ai_tools/runtime/include/flatbuffers/detached_buffer.h +114 -0
  16. xmos_ai_tools/runtime/include/flatbuffers/flatbuffer_builder.h +1197 -0
  17. xmos_ai_tools/runtime/include/flatbuffers/flatbuffers.h +270 -0
  18. xmos_ai_tools/runtime/include/flatbuffers/flatc.h +111 -0
  19. xmos_ai_tools/runtime/include/flatbuffers/flexbuffers.h +1897 -0
  20. xmos_ai_tools/runtime/include/flatbuffers/grpc.h +300 -0
  21. xmos_ai_tools/runtime/include/flatbuffers/hash.h +127 -0
  22. xmos_ai_tools/runtime/include/flatbuffers/idl.h +1232 -0
  23. xmos_ai_tools/runtime/include/flatbuffers/minireflect.h +419 -0
  24. xmos_ai_tools/runtime/include/flatbuffers/pch/flatc_pch.h +39 -0
  25. xmos_ai_tools/runtime/include/flatbuffers/pch/pch.h +38 -0
  26. xmos_ai_tools/runtime/include/flatbuffers/reflection.h +502 -0
  27. xmos_ai_tools/runtime/include/flatbuffers/reflection_generated.h +1449 -0
  28. xmos_ai_tools/runtime/include/flatbuffers/registry.h +128 -0
  29. xmos_ai_tools/runtime/include/flatbuffers/stl_emulation.h +509 -0
  30. xmos_ai_tools/runtime/include/flatbuffers/string.h +64 -0
  31. xmos_ai_tools/runtime/include/flatbuffers/struct.h +53 -0
  32. xmos_ai_tools/runtime/include/flatbuffers/table.h +168 -0
  33. xmos_ai_tools/runtime/include/flatbuffers/util.h +690 -0
  34. xmos_ai_tools/runtime/include/flatbuffers/vector.h +370 -0
  35. xmos_ai_tools/runtime/include/flatbuffers/vector_downward.h +271 -0
  36. xmos_ai_tools/runtime/include/flatbuffers/verifier.h +283 -0
  37. xmos_ai_tools/runtime/include/ioserver.h +44 -0
  38. xmos_ai_tools/runtime/include/lib_nn/api/TransposeConv.h +24 -0
  39. xmos_ai_tools/runtime/include/lib_nn/api/add_int16.h +27 -0
  40. xmos_ai_tools/runtime/include/lib_nn/api/add_int16_transform.h +42 -0
  41. xmos_ai_tools/runtime/include/lib_nn/api/dequantize_int16.h +22 -0
  42. xmos_ai_tools/runtime/include/lib_nn/api/dequantize_int16_transform.h +34 -0
  43. xmos_ai_tools/runtime/include/lib_nn/api/expand_8_to_16.h +8 -0
  44. xmos_ai_tools/runtime/include/lib_nn/api/multiply_int16.h +42 -0
  45. xmos_ai_tools/runtime/include/lib_nn/api/multiply_int16_transform.h +71 -0
  46. xmos_ai_tools/runtime/include/lib_nn/api/nn_api.h +15 -0
  47. xmos_ai_tools/runtime/include/lib_nn/api/nn_bin_types.h +14 -0
  48. xmos_ai_tools/runtime/include/lib_nn/api/nn_config.h +287 -0
  49. xmos_ai_tools/runtime/include/lib_nn/api/nn_conv2d_structs.h +72 -0
  50. xmos_ai_tools/runtime/include/lib_nn/api/nn_image.h +26 -0
  51. xmos_ai_tools/runtime/include/lib_nn/api/nn_layers.h +303 -0
  52. xmos_ai_tools/runtime/include/lib_nn/api/nn_op_helper.h +132 -0
  53. xmos_ai_tools/runtime/include/lib_nn/api/nn_op_utils.h +150 -0
  54. xmos_ai_tools/runtime/include/lib_nn/api/nn_operator.h +18 -0
  55. xmos_ai_tools/runtime/include/lib_nn/api/nn_pooling.h +551 -0
  56. xmos_ai_tools/runtime/include/lib_nn/api/nn_types.h +83 -0
  57. xmos_ai_tools/runtime/include/lib_nn/api/nn_window_params.h +55 -0
  58. xmos_ai_tools/runtime/include/lib_nn/api/output_transform_fn_int16.h +54 -0
  59. xmos_ai_tools/runtime/include/lib_nn/api/output_transform_fn_int16_kernel_transform.h +37 -0
  60. xmos_ai_tools/runtime/include/lib_nn/api/output_transform_fn_int16_mappings.h +13 -0
  61. xmos_ai_tools/runtime/include/lib_nn/api/quadratic_approximation.h +82 -0
  62. xmos_ai_tools/runtime/include/lib_nn/api/quadratic_interpolation.h +23 -0
  63. xmos_ai_tools/runtime/include/lib_nn/api/quantize_int16.h +22 -0
  64. xmos_ai_tools/runtime/include/lib_nn/api/quantize_int16_transform.h +33 -0
  65. xmos_ai_tools/runtime/include/lib_nn/api/version.h +13 -0
  66. xmos_ai_tools/runtime/include/lib_nn/api/vpu_memmove_word_aligned.h +15 -0
  67. xmos_ai_tools/runtime/include/lib_nn/api/vpu_memset_256.h +55 -0
  68. xmos_ai_tools/runtime/include/lib_nn/api/vpu_sim.h +118 -0
  69. xmos_ai_tools/runtime/include/lib_nn/api/xs3_vpu.h +216 -0
  70. xmos_ai_tools/runtime/include/lib_nn/api/xs3a_registers.h +2869 -0
  71. xmos_ai_tools/runtime/include/lib_nn/src/asm/asm_constants.h +41 -0
  72. xmos_ai_tools/runtime/include/lib_nn/src/asm/window_op_plan.h +25 -0
  73. xmos_ai_tools/runtime/include/lib_tflite_micro/api/fast_flash.h +47 -0
  74. xmos_ai_tools/runtime/include/lib_tflite_micro/api/inference_engine.h +218 -0
  75. xmos_ai_tools/runtime/include/lib_tflite_micro/api/memory_parallel_transport.h +52 -0
  76. xmos_ai_tools/runtime/include/lib_tflite_micro/api/version.h +13 -0
  77. xmos_ai_tools/runtime/include/lib_tflite_micro/api/xcore_config.h +17 -0
  78. xmos_ai_tools/runtime/include/lib_tflite_micro/api/xcore_device_memory.h +62 -0
  79. xmos_ai_tools/runtime/include/lib_tflite_micro/api/xcore_shared_config.h +31 -0
  80. xmos_ai_tools/runtime/include/lib_tflite_micro/src/tflite-xcore-kernels/conv2d_float.h +155 -0
  81. xmos_ai_tools/runtime/include/lib_tflite_micro/src/tflite-xcore-kernels/xcore_common.h +19 -0
  82. xmos_ai_tools/runtime/include/lib_tflite_micro/src/tflite-xcore-kernels/xcore_custom_options.h +28 -0
  83. xmos_ai_tools/runtime/include/lib_tflite_micro/src/tflite-xcore-kernels/xcore_error_reporter.h +32 -0
  84. xmos_ai_tools/runtime/include/lib_tflite_micro/src/tflite-xcore-kernels/xcore_interpreter.h +49 -0
  85. xmos_ai_tools/runtime/include/lib_tflite_micro/src/tflite-xcore-kernels/xcore_ops.h +71 -0
  86. xmos_ai_tools/runtime/include/lib_tflite_micro/src/tflite-xcore-kernels/xcore_profiler.h +49 -0
  87. xmos_ai_tools/runtime/include/lib_tflite_micro/src/tflite-xcore-kernels/xcore_utils.h +160 -0
  88. xmos_ai_tools/runtime/include/lib_tflite_micro/src/thread_call.h +119 -0
  89. xmos_ai_tools/runtime/include/lib_xud/lib_xud/api/legacy/usb_defs.h +4 -0
  90. xmos_ai_tools/runtime/include/lib_xud/lib_xud/api/legacy/usb_device.h +4 -0
  91. xmos_ai_tools/runtime/include/lib_xud/lib_xud/api/legacy/usb_std_descriptors.h +4 -0
  92. xmos_ai_tools/runtime/include/lib_xud/lib_xud/api/legacy/usb_std_requests.h +4 -0
  93. xmos_ai_tools/runtime/include/lib_xud/lib_xud/api/xud.h +518 -0
  94. xmos_ai_tools/runtime/include/lib_xud/lib_xud/api/xud_conf_default.h +11 -0
  95. xmos_ai_tools/runtime/include/lib_xud/lib_xud/api/xud_device.h +87 -0
  96. xmos_ai_tools/runtime/include/lib_xud/lib_xud/api/xud_std_descriptors.h +191 -0
  97. xmos_ai_tools/runtime/include/lib_xud/lib_xud/api/xud_std_requests.h +120 -0
  98. xmos_ai_tools/runtime/include/lib_xud/lib_xud/src/user/XUD_USB_Defines.h +70 -0
  99. xmos_ai_tools/runtime/include/lib_xud/lib_xud/src/user/class/hid.h +23 -0
  100. xmos_ai_tools/runtime/include/lib_xud/lib_xud/src/user/class/usbaudio10.h +30 -0
  101. xmos_ai_tools/runtime/include/lib_xud/lib_xud/src/user/class/usbaudio20.h +357 -0
  102. xmos_ai_tools/runtime/include/lib_xud/lib_xud/src/user/class/usbaudiocommon.h +168 -0
  103. xmos_ai_tools/runtime/include/signal/micro/kernels/delay_flexbuffers_generated_data.h +25 -0
  104. xmos_ai_tools/runtime/include/signal/micro/kernels/energy_flexbuffers_generated_data.h +28 -0
  105. xmos_ai_tools/runtime/include/signal/micro/kernels/fft_flexbuffers_generated_data.h +37 -0
  106. xmos_ai_tools/runtime/include/signal/micro/kernels/filter_bank_flexbuffers_generated_data.h +25 -0
  107. xmos_ai_tools/runtime/include/signal/micro/kernels/filter_bank_log_flexbuffers_generated_data.h +27 -0
  108. xmos_ai_tools/runtime/include/signal/micro/kernels/filter_bank_spectral_subtraction_flexbuffers_generated_data.h +26 -0
  109. xmos_ai_tools/runtime/include/signal/micro/kernels/framer_flexbuffers_generated_data.h +25 -0
  110. xmos_ai_tools/runtime/include/signal/micro/kernels/irfft.h +31 -0
  111. xmos_ai_tools/runtime/include/signal/micro/kernels/overlap_add_flexbuffers_generated_data.h +25 -0
  112. xmos_ai_tools/runtime/include/signal/micro/kernels/pcan_flexbuffers_generated_data.h +7 -0
  113. xmos_ai_tools/runtime/include/signal/micro/kernels/rfft.h +31 -0
  114. xmos_ai_tools/runtime/include/signal/micro/kernels/stacker_flexbuffers_generated_data.h +25 -0
  115. xmos_ai_tools/runtime/include/signal/micro/kernels/window_flexbuffers_generated_data.h +25 -0
  116. xmos_ai_tools/runtime/include/signal/src/circular_buffer.h +118 -0
  117. xmos_ai_tools/runtime/include/signal/src/complex.h +29 -0
  118. xmos_ai_tools/runtime/include/signal/src/energy.h +38 -0
  119. xmos_ai_tools/runtime/include/signal/src/fft_auto_scale.h +35 -0
  120. xmos_ai_tools/runtime/include/signal/src/filter_bank.h +69 -0
  121. xmos_ai_tools/runtime/include/signal/src/filter_bank_log.h +38 -0
  122. xmos_ai_tools/runtime/include/signal/src/filter_bank_spectral_subtraction.h +73 -0
  123. xmos_ai_tools/runtime/include/signal/src/filter_bank_square_root.h +34 -0
  124. xmos_ai_tools/runtime/include/signal/src/irfft.h +84 -0
  125. xmos_ai_tools/runtime/include/signal/src/kiss_fft_wrappers/kiss_fft_common.h +49 -0
  126. xmos_ai_tools/runtime/include/signal/src/kiss_fft_wrappers/kiss_fft_float.h +31 -0
  127. xmos_ai_tools/runtime/include/signal/src/kiss_fft_wrappers/kiss_fft_int16.h +30 -0
  128. xmos_ai_tools/runtime/include/signal/src/kiss_fft_wrappers/kiss_fft_int32.h +31 -0
  129. xmos_ai_tools/runtime/include/signal/src/log.h +30 -0
  130. xmos_ai_tools/runtime/include/signal/src/max_abs.h +31 -0
  131. xmos_ai_tools/runtime/include/signal/src/msb.h +32 -0
  132. xmos_ai_tools/runtime/include/signal/src/overlap_add.h +46 -0
  133. xmos_ai_tools/runtime/include/signal/src/pcan_argc_fixed.h +41 -0
  134. xmos_ai_tools/runtime/include/signal/src/rfft.h +85 -0
  135. xmos_ai_tools/runtime/include/signal/src/square_root.h +32 -0
  136. xmos_ai_tools/runtime/include/signal/src/window.h +31 -0
  137. xmos_ai_tools/runtime/include/signal/testdata/fft_test_data.h +48 -0
  138. xmos_ai_tools/runtime/include/tensorflow/lite/array.h +156 -0
  139. xmos_ai_tools/runtime/include/tensorflow/lite/builtin_op_data.h +22 -0
  140. xmos_ai_tools/runtime/include/tensorflow/lite/builtin_ops.h +241 -0
  141. xmos_ai_tools/runtime/include/tensorflow/lite/c/builtin_op_data.h +20 -0
  142. xmos_ai_tools/runtime/include/tensorflow/lite/c/c_api_types.h +26 -0
  143. xmos_ai_tools/runtime/include/tensorflow/lite/c/common.h +30 -0
  144. xmos_ai_tools/runtime/include/tensorflow/lite/context_util.h +54 -0
  145. xmos_ai_tools/runtime/include/tensorflow/lite/core/api/error_reporter.h +72 -0
  146. xmos_ai_tools/runtime/include/tensorflow/lite/core/api/flatbuffer_conversions.h +440 -0
  147. xmos_ai_tools/runtime/include/tensorflow/lite/core/api/tensor_utils.h +28 -0
  148. xmos_ai_tools/runtime/include/tensorflow/lite/core/c/builtin_op_data.h +626 -0
  149. xmos_ai_tools/runtime/include/tensorflow/lite/core/c/c_api_types.h +178 -0
  150. xmos_ai_tools/runtime/include/tensorflow/lite/core/c/common.h +1496 -0
  151. xmos_ai_tools/runtime/include/tensorflow/lite/core/macros.h +78 -0
  152. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/bits.h +102 -0
  153. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/fft.h +50 -0
  154. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/fft_io.h +34 -0
  155. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/fft_util.h +34 -0
  156. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/filterbank.h +63 -0
  157. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/filterbank_io.h +35 -0
  158. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/filterbank_util.h +50 -0
  159. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/frontend.h +64 -0
  160. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/frontend_io.h +31 -0
  161. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/frontend_util.h +52 -0
  162. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/kiss_fft_common.h +48 -0
  163. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/kiss_fft_int16.h +33 -0
  164. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/log_lut.h +40 -0
  165. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/log_scale.h +39 -0
  166. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/log_scale_io.h +33 -0
  167. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/log_scale_util.h +45 -0
  168. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/noise_reduction.h +46 -0
  169. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_io.h +36 -0
  170. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_util.h +50 -0
  171. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.h +47 -0
  172. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control_util.h +57 -0
  173. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/window.h +49 -0
  174. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/window_io.h +34 -0
  175. xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/window_util.h +45 -0
  176. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/common.h +1358 -0
  177. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/compatibility.h +122 -0
  178. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/cppmath.h +40 -0
  179. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/max.h +35 -0
  180. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/min.h +35 -0
  181. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/optimized/neon_check.h +20 -0
  182. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/portable_tensor.h +141 -0
  183. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/portable_tensor_utils.h +623 -0
  184. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/quantization_util.h +292 -0
  185. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/add.h +561 -0
  186. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/add_n.h +86 -0
  187. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/arg_min_max.h +88 -0
  188. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/batch_matmul.h +275 -0
  189. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/batch_to_space_nd.h +101 -0
  190. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/binary_function.h +91 -0
  191. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/broadcast_args.h +56 -0
  192. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/broadcast_to.h +97 -0
  193. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/ceil.h +37 -0
  194. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/comparisons.h +271 -0
  195. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/concatenation.h +141 -0
  196. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/conv.h +289 -0
  197. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/cumsum.h +175 -0
  198. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/depth_to_space.h +79 -0
  199. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/depthwiseconv_float.h +100 -0
  200. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/depthwiseconv_uint8.h +319 -0
  201. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/dequantize.h +78 -0
  202. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/div.h +247 -0
  203. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/elu.h +37 -0
  204. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/exp.h +38 -0
  205. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/fill.h +38 -0
  206. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/floor.h +39 -0
  207. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/floor_div.h +35 -0
  208. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/floor_mod.h +44 -0
  209. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/fully_connected.h +323 -0
  210. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/hard_swish.h +168 -0
  211. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/add.h +250 -0
  212. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/conv.h +241 -0
  213. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/depthwise_conv.h +291 -0
  214. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/fully_connected.h +126 -0
  215. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/l2normalization.h +67 -0
  216. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/logistic.h +121 -0
  217. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/mean.h +18 -0
  218. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/mul.h +194 -0
  219. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/pooling.h +264 -0
  220. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/tanh.h +117 -0
  221. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/transpose_conv.h +224 -0
  222. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/l2normalization.h +90 -0
  223. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/leaky_relu.h +69 -0
  224. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/log_softmax.h +256 -0
  225. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/logistic.h +132 -0
  226. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/lstm_cell.h +422 -0
  227. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/maximum_minimum.h +64 -0
  228. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/mul.h +267 -0
  229. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/neg.h +37 -0
  230. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/pad.h +169 -0
  231. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/pooling.h +303 -0
  232. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/portable_tensor_utils.h +333 -0
  233. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/portable_tensor_utils_impl.h +244 -0
  234. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/prelu.h +111 -0
  235. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/process_broadcast_shapes.h +140 -0
  236. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/quantize.h +89 -0
  237. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/reduce.h +491 -0
  238. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/requantize.h +70 -0
  239. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/resize_bilinear.h +233 -0
  240. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/resize_nearest_neighbor.h +102 -0
  241. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/round.h +51 -0
  242. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/select.h +151 -0
  243. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/slice.h +80 -0
  244. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/softmax.h +233 -0
  245. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/space_to_batch_nd.h +109 -0
  246. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/space_to_depth.h +80 -0
  247. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/strided_slice.h +147 -0
  248. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/sub.h +465 -0
  249. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/tanh.h +129 -0
  250. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/transpose.h +203 -0
  251. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/transpose_conv.h +225 -0
  252. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/runtime_shape.h +168 -0
  253. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/strided_slice_logic.h +278 -0
  254. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/tensor_ctypes.h +42 -0
  255. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/types.h +1096 -0
  256. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/kernel_util.h +341 -0
  257. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/op_macros.h +49 -0
  258. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/padding.h +115 -0
  259. xmos_ai_tools/runtime/include/tensorflow/lite/micro/arena_allocator/ibuffer_allocator.h +100 -0
  260. xmos_ai_tools/runtime/include/tensorflow/lite/micro/arena_allocator/non_persistent_arena_buffer_allocator.h +104 -0
  261. xmos_ai_tools/runtime/include/tensorflow/lite/micro/arena_allocator/persistent_arena_buffer_allocator.h +58 -0
  262. xmos_ai_tools/runtime/include/tensorflow/lite/micro/arena_allocator/recording_single_arena_buffer_allocator.h +63 -0
  263. xmos_ai_tools/runtime/include/tensorflow/lite/micro/arena_allocator/single_arena_buffer_allocator.h +144 -0
  264. xmos_ai_tools/runtime/include/tensorflow/lite/micro/benchmarks/micro_benchmark.h +95 -0
  265. xmos_ai_tools/runtime/include/tensorflow/lite/micro/compatibility.h +32 -0
  266. xmos_ai_tools/runtime/include/tensorflow/lite/micro/cortex_m_generic/debug_log_callback.h +49 -0
  267. xmos_ai_tools/runtime/include/tensorflow/lite/micro/debug_log.h +38 -0
  268. xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/micro_model_settings.h +37 -0
  269. xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/network_tester/expected_output_data.h +47 -0
  270. xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/network_tester/input_data.h +108 -0
  271. xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/network_tester/network_model.h +166 -0
  272. xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/person_detection/detection_responder.h +32 -0
  273. xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/person_detection/image_provider.h +38 -0
  274. xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/person_detection/main_functions.h +37 -0
  275. xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/person_detection/model_settings.h +35 -0
  276. xmos_ai_tools/runtime/include/tensorflow/lite/micro/fake_micro_context.h +70 -0
  277. xmos_ai_tools/runtime/include/tensorflow/lite/micro/flatbuffer_utils.h +65 -0
  278. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/activation_utils.h +57 -0
  279. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/activations.h +64 -0
  280. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/add.h +78 -0
  281. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/arc_mli/mli_function_specializations.h +141 -0
  282. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/arc_mli/mli_interface.h +75 -0
  283. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/arc_mli/mli_slicers.h +56 -0
  284. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/arc_mli/mli_tf_utils.h +310 -0
  285. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/arc_mli/scratch_buf_mgr.h +145 -0
  286. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/arc_mli/scratch_buffers.h +78 -0
  287. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/ceva/ceva_common.h +24 -0
  288. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/ceva/ceva_tflm_lib.h +613 -0
  289. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/ceva/mcps_macros.h +115 -0
  290. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/ceva/types.h +1286 -0
  291. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/circular_buffer.h +45 -0
  292. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/circular_buffer_flexbuffers_generated_data.h +22 -0
  293. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/conv.h +117 -0
  294. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/conv_test.h +94 -0
  295. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/depthwise_conv.h +80 -0
  296. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/dequantize.h +38 -0
  297. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/detection_postprocess_flexbuffers_generated_data.h +25 -0
  298. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/ethosu.h +28 -0
  299. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/fully_connected.h +112 -0
  300. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/hard_swish.h +30 -0
  301. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/kernel_runner.h +86 -0
  302. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/kernel_util.h +150 -0
  303. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/leaky_relu.h +43 -0
  304. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/logical.h +35 -0
  305. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/logistic.h +42 -0
  306. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/lstm_eval.h +541 -0
  307. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/lstm_eval_test.h +817 -0
  308. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/lstm_shared.h +150 -0
  309. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/micro_ops.h +158 -0
  310. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/micro_tensor_utils.h +56 -0
  311. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/mul.h +74 -0
  312. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/pad.h +27 -0
  313. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/pooling.h +142 -0
  314. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/prelu.h +39 -0
  315. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/quantize.h +37 -0
  316. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/reduce.h +65 -0
  317. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/reshape.h +26 -0
  318. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/softmax.h +67 -0
  319. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/strided_slice.h +40 -0
  320. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/sub.h +60 -0
  321. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/svdf.h +100 -0
  322. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/testdata/conv_test_data.h +37 -0
  323. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/testdata/lstm_test_data.h +579 -0
  324. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/unidirectional_sequence_lstm.h +47 -0
  325. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/hifimini/fixedpoint_utils.h +139 -0
  326. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/lstm_eval.h +216 -0
  327. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/lstm_shared.h +78 -0
  328. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa.h +38 -0
  329. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_add.h +48 -0
  330. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_conv.h +89 -0
  331. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_depthwise_conv.h +74 -0
  332. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_fully_connected.h +78 -0
  333. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_pad.h +49 -0
  334. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_pooling.h +76 -0
  335. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_reduce.h +47 -0
  336. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_reshape.h +44 -0
  337. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_softmax.h +58 -0
  338. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_svdf.h +39 -0
  339. xmos_ai_tools/runtime/include/tensorflow/lite/micro/memory_helpers.h +64 -0
  340. xmos_ai_tools/runtime/include/tensorflow/lite/micro/memory_planner/greedy_memory_planner.h +170 -0
  341. xmos_ai_tools/runtime/include/tensorflow/lite/micro/memory_planner/linear_memory_planner.h +53 -0
  342. xmos_ai_tools/runtime/include/tensorflow/lite/micro/memory_planner/memory_plan_struct.h +73 -0
  343. xmos_ai_tools/runtime/include/tensorflow/lite/micro/memory_planner/micro_memory_planner.h +95 -0
  344. xmos_ai_tools/runtime/include/tensorflow/lite/micro/memory_planner/non_persistent_buffer_planner_shim.h +133 -0
  345. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_allocation_info.h +138 -0
  346. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_allocator.h +351 -0
  347. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_arena_constants.h +28 -0
  348. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_common.h +38 -0
  349. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_context.h +176 -0
  350. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_graph.h +79 -0
  351. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_interpreter.h +189 -0
  352. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_interpreter_context.h +125 -0
  353. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_interpreter_graph.h +110 -0
  354. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_log.h +42 -0
  355. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_mutable_op_resolver.h +708 -0
  356. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_op_resolver.h +62 -0
  357. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_profiler.h +140 -0
  358. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_profiler_interface.h +38 -0
  359. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_resource_variable.h +89 -0
  360. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_time.h +36 -0
  361. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_utils.h +162 -0
  362. xmos_ai_tools/runtime/include/tensorflow/lite/micro/mock_micro_graph.h +60 -0
  363. xmos_ai_tools/runtime/include/tensorflow/lite/micro/python/interpreter/src/python_ops_resolver.h +21 -0
  364. xmos_ai_tools/runtime/include/tensorflow/lite/micro/python/tflite_size/src/flatbuffer_size.h +30 -0
  365. xmos_ai_tools/runtime/include/tensorflow/lite/micro/python/tflite_size/src/flatbuffer_size_wrapper.h +33 -0
  366. xmos_ai_tools/runtime/include/tensorflow/lite/micro/recording_micro_allocator.h +125 -0
  367. xmos_ai_tools/runtime/include/tensorflow/lite/micro/recording_micro_interpreter.h +69 -0
  368. xmos_ai_tools/runtime/include/tensorflow/lite/micro/system_setup.h +27 -0
  369. xmos_ai_tools/runtime/include/tensorflow/lite/micro/test_helper_custom_ops.h +49 -0
  370. xmos_ai_tools/runtime/include/tensorflow/lite/micro/test_helpers.h +334 -0
  371. xmos_ai_tools/runtime/include/tensorflow/lite/micro/testing/micro_test.h +267 -0
  372. xmos_ai_tools/runtime/include/tensorflow/lite/micro/testing/test_conv_model.h +23 -0
  373. xmos_ai_tools/runtime/include/tensorflow/lite/micro/tflite_bridge/flatbuffer_conversions_bridge.h +45 -0
  374. xmos_ai_tools/runtime/include/tensorflow/lite/micro/tflite_bridge/micro_error_reporter.h +36 -0
  375. xmos_ai_tools/runtime/include/tensorflow/lite/micro/tools/benchmarking/log_utils.h +273 -0
  376. xmos_ai_tools/runtime/include/tensorflow/lite/micro/tools/benchmarking/metrics.h +41 -0
  377. xmos_ai_tools/runtime/include/tensorflow/lite/micro/tools/benchmarking/op_resolver.h +127 -0
  378. xmos_ai_tools/runtime/include/tensorflow/lite/portable_type_to_tflitetype.h +75 -0
  379. xmos_ai_tools/runtime/include/tensorflow/lite/schema/schema_generated.h +24644 -0
  380. xmos_ai_tools/runtime/include/tensorflow/lite/schema/schema_utils.h +33 -0
  381. xmos_ai_tools/runtime/include/tile_ram_server.h +38 -0
  382. xmos_ai_tools/runtime/lib/libhost_xtflitemicro.a +0 -0
  383. xmos_ai_tools/runtime/lib/libxtflitemicro.a +0 -0
  384. xmos_ai_tools/xformer/__init__.py +60 -0
  385. xmos_ai_tools/xformer/flash.py +190 -0
  386. xmos_ai_tools/xinterpreters/__init__.py +1 -0
  387. xmos_ai_tools/xinterpreters/exceptions.py +38 -0
  388. xmos_ai_tools/xinterpreters/host_interpreter.py +652 -0
  389. xmos_ai_tools/xinterpreters/libs/macos/xtflm_python.1.0.1.dylib +0 -0
  390. xmos_ai_tools/xinterpreters/libs/macos/xtflm_python.dylib +0 -0
  391. xmos_ai_tools-1.3.2.dev80.data/data/bin/xcore-opt +0 -0
  392. xmos_ai_tools-1.3.2.dev80.dist-info/METADATA +33 -0
  393. xmos_ai_tools-1.3.2.dev80.dist-info/RECORD +395 -0
  394. xmos_ai_tools-1.3.2.dev80.dist-info/WHEEL +5 -0
  395. xmos_ai_tools-1.3.2.dev80.dist-info/top_level.txt +1 -0
@@ -0,0 +1,817 @@
1
+ /* Copyright 2023 The TensorFlow Authors. All Rights Reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+ ==============================================================================*/
15
+
16
+ #ifndef TENSORFLOW_LITE_MICRO_KERNELS_LSTM_EVAL_TEST_H_
17
+ #define TENSORFLOW_LITE_MICRO_KERNELS_LSTM_EVAL_TEST_H_
18
+
19
+ #include <algorithm>
20
+ #include <limits>
21
+
22
+ #include "tensorflow/lite/micro/kernels/lstm_eval.h"
23
+ #include "tensorflow/lite/micro/kernels/testdata/lstm_test_data.h"
24
+ #include "tensorflow/lite/micro/test_helpers.h"
25
+ #include "tensorflow/lite/micro/testing/micro_test.h"
26
+
27
+ namespace tflite_micro {
28
+ namespace testing {
29
+
30
+ /*Helper Functions (mainly about mimicking the kernel preparation)*/
31
+
32
+ // Create fully connected parameters using quantization settings of input and
33
+ // weight tensors.
34
+ // Since TfLiteContext is not available during the kernel test, here we mimic
35
+ // (put into stack memory) CalculateOpDataFullyConnected in
36
+ // tensorflow/lite/micro/kernels/fully_connected_common.cc
37
+ template <typename CellType>
38
+ tflite_micro::FullyConnectedParams CreateFCParams(
39
+ const TensorQuantizationParameters& input_quant_params,
40
+ const TensorQuantizationParameters& weight_quant_params,
41
+ const float nonlinear_activation_input_scale) {
42
+ OpDataFullyConnected data;
43
+ const double input_product_scale =
44
+ input_quant_params.scale * weight_quant_params.scale;
45
+ double effective_scale =
46
+ input_product_scale /
47
+ static_cast<double>(nonlinear_activation_input_scale);
48
+
49
+ QuantizeMultiplier(effective_scale, &data.output_multiplier,
50
+ &data.output_shift);
51
+
52
+ data.input_zero_point = input_quant_params.zero_point;
53
+
54
+ data.filter_zero_point = 0; // symmetrically quantized
55
+ data.output_zero_point = 0; // symmetrically quantized
56
+
57
+ data.output_activation_min = std::numeric_limits<CellType>::min();
58
+ data.output_activation_max = std::numeric_limits<CellType>::max();
59
+
60
+ return tflite_micro::FullyConnectedParamsQuantized(data);
61
+ }
62
+
63
+ inline tflite_micro::FullyConnectedParams CreateFCParamsFloat() {
64
+ FullyConnectedParams op_params;
65
+ CalculateActivationRange(kTfLiteActNone, &op_params.float_activation_min,
66
+ &op_params.float_activation_max);
67
+ return op_params;
68
+ }
69
+
70
+ // Wrapper function to create gate parameters for the four internal LSTM gates
71
+ template <typename CellType>
72
+ tflite_micro::GateParameters CreateGateParams(
73
+ const TensorQuantizationParameters& input_quant_params,
74
+ const TensorQuantizationParameters& hidden_state_quant_params,
75
+ const GateQuantizationParameters& gate_quantization_settings,
76
+ const float nonlinear_activation_input_scale) {
77
+ tflite_micro::GateParameters gate_params = {};
78
+ gate_params.input_fc_params = CreateFCParams<CellType>(
79
+ input_quant_params, gate_quantization_settings.activation_weight,
80
+ nonlinear_activation_input_scale);
81
+ gate_params.recurrent_fc_params = CreateFCParams<CellType>(
82
+ hidden_state_quant_params, gate_quantization_settings.recurrent_weight,
83
+ nonlinear_activation_input_scale);
84
+ return gate_params;
85
+ }
86
+
87
+ inline tflite_micro::GateParameters CreateGateParamsFloat() {
88
+ tflite_micro::GateParameters gate_params = {};
89
+ gate_params.input_fc_params = CreateFCParamsFloat();
90
+ gate_params.recurrent_fc_params = CreateFCParamsFloat();
91
+ return gate_params;
92
+ }
93
+ // Create parameters for element wise multiplication that happens in a) cell
94
+ // state update ; b) hidden state update
95
+ // Note that all the output of gates are symmetrically quantized so only scales
96
+ // are required for input. However, during the hidden state update phase, the
97
+ // output is the updated hidden state, which is asymmetrically quantized. Thus
98
+ // output may require zero point
99
+ template <typename OutputType>
100
+ tflite_micro::ArithmeticParams CreateInterGateMulParams(const float input1_scale,
101
+ const float input2_scale,
102
+ const float output_scale,
103
+ const int output_zp = 0) {
104
+ tflite_micro::ArithmeticParams op_params = {};
105
+ op_params.quantized_activation_min = std::numeric_limits<OutputType>::min();
106
+ op_params.quantized_activation_max = std::numeric_limits<OutputType>::max();
107
+ op_params.input1_offset = 0;
108
+ op_params.input2_offset = 0;
109
+ op_params.output_offset = output_zp;
110
+
111
+ const double input_product_scale =
112
+ static_cast<double>(input1_scale) * static_cast<double>(input2_scale);
113
+ double effective_scale =
114
+ input_product_scale / static_cast<double>(output_scale);
115
+
116
+ QuantizeMultiplier(effective_scale, &op_params.output_multiplier,
117
+ &op_params.output_shift);
118
+ return op_params;
119
+ }
120
+
121
+ inline tflite_micro::ArithmeticParams CreateInterGateMulParamsFloat() {
122
+ tflite_micro::ArithmeticParams op_params = {};
123
+ CalculateActivationRange(kTfLiteActNone, &op_params.float_activation_min,
124
+ &op_params.float_activation_max);
125
+ return op_params;
126
+ }
127
+
128
+ // Create the additional information about the cell state, which include:
129
+ // cell_state_scale_power: used in integer nonlinear function (e.g., tanh)
130
+ // quantized_cell_clip: quantized cell clip range
131
+ CellStateInfo CreateLstmCellStateInfo(const float cell_state_scale,
132
+ const float cell_clip) {
133
+ CellStateInfo cell_state_info;
134
+ // cell_state_scale_power: 2^-cell_state_scale_power = cell state scale
135
+ int buffer;
136
+ tflite_micro::CheckedLog2(cell_state_scale, &buffer);
137
+ cell_state_info.cell_state_scale_power = buffer;
138
+ // Cell state specifics
139
+ cell_state_info.cell_clip = cell_clip;
140
+ cell_state_info.quantized_cell_clip = static_cast<int16_t>(
141
+ std::min(std::max(static_cast<double>(cell_clip) /
142
+ static_cast<double>(cell_state_scale),
143
+ -32768.0),
144
+ 32767.0));
145
+ return cell_state_info;
146
+ }
147
+
148
+ // Create LSTMKernelContents from LstmNodeContent by copying TfLiteEvalTensor
149
+ // pointers
150
+ template <typename ActivationType, typename WeightType, typename BiasType,
151
+ typename CellType, int batch_size, int time_steps,
152
+ int input_dimension, int state_dimension>
153
+ LSTMKernelContents CreateLSTMKernelContent(
154
+ LstmNodeContent<ActivationType, WeightType, BiasType, CellType, batch_size,
155
+ time_steps, input_dimension, state_dimension>&
156
+ node_contents) {
157
+ LSTMKernelContents kernel_content;
158
+ // Point to correct tensors
159
+ kernel_content.internal_tensors[kLstmInputTensor] =
160
+ node_contents.GetEvalTensor(kLstmInputTensor);
161
+ kernel_content.internal_tensors[kLstmInputToInputWeightsTensor] =
162
+ node_contents.GetEvalTensor(kLstmInputToInputWeightsTensor);
163
+ kernel_content.internal_tensors[kLstmInputToForgetWeightsTensor] =
164
+ node_contents.GetEvalTensor(kLstmInputToForgetWeightsTensor);
165
+ kernel_content.internal_tensors[kLstmInputToCellWeightsTensor] =
166
+ node_contents.GetEvalTensor(kLstmInputToCellWeightsTensor);
167
+ kernel_content.internal_tensors[kLstmInputToOutputWeightsTensor] =
168
+ node_contents.GetEvalTensor(kLstmInputToOutputWeightsTensor);
169
+ kernel_content.internal_tensors[kLstmRecurrentToInputWeightsTensor] =
170
+ node_contents.GetEvalTensor(kLstmRecurrentToInputWeightsTensor);
171
+ kernel_content.internal_tensors[kLstmRecurrentToForgetWeightsTensor] =
172
+ node_contents.GetEvalTensor(kLstmRecurrentToForgetWeightsTensor);
173
+ kernel_content.internal_tensors[kLstmRecurrentToCellWeightsTensor] =
174
+ node_contents.GetEvalTensor(kLstmRecurrentToCellWeightsTensor);
175
+ kernel_content.internal_tensors[kLstmRecurrentToOutputWeightsTensor] =
176
+ node_contents.GetEvalTensor(kLstmRecurrentToOutputWeightsTensor);
177
+ kernel_content.internal_tensors[kLstmInputGateBiasTensor] =
178
+ node_contents.GetEvalTensor(kLstmInputGateBiasTensor);
179
+ kernel_content.internal_tensors[kLstmForgetGateBiasTensor] =
180
+ node_contents.GetEvalTensor(kLstmForgetGateBiasTensor);
181
+ kernel_content.internal_tensors[kLstmCellGateBiasTensor] =
182
+ node_contents.GetEvalTensor(kLstmCellGateBiasTensor);
183
+ kernel_content.internal_tensors[kLstmOutputGateBiasTensor] =
184
+ node_contents.GetEvalTensor(kLstmOutputGateBiasTensor);
185
+ kernel_content.internal_tensors[kLstmOutputStateTensor] =
186
+ node_contents.GetEvalTensor(kLstmOutputStateTensor);
187
+ kernel_content.internal_tensors[kLstmOutputGateBiasTensor] =
188
+ node_contents.GetEvalTensor(kLstmOutputGateBiasTensor);
189
+ kernel_content.internal_tensors[kLstmCellStateTensor] =
190
+ node_contents.GetEvalTensor(kLstmCellStateTensor);
191
+ // Not used internal tensors
192
+ kernel_content.internal_tensors[kLstmCellToInputWeightsTensor] = nullptr;
193
+ kernel_content.internal_tensors[kLstmCellToForgetWeightsTensor] = nullptr;
194
+ kernel_content.internal_tensors[kLstmCellToOutputWeightsTensor] = nullptr;
195
+ kernel_content.internal_tensors[kLstmProjectionWeightsTensor] = nullptr;
196
+ kernel_content.internal_tensors[kLstmProjectionBiasTensor] = nullptr;
197
+ kernel_content.internal_tensors[kLstmInputLayerNormCoefficientsTensor] =
198
+ nullptr;
199
+ kernel_content.internal_tensors[kLstmForgetLayerNormCoefficientsTensor] =
200
+ nullptr;
201
+ kernel_content.internal_tensors[kLstmInputLayerNormCoefficientsTensor] =
202
+ nullptr;
203
+ kernel_content.internal_tensors[kLstmCellLayerNormCoefficientsTensor] =
204
+ nullptr;
205
+ kernel_content.internal_tensors[kLstmOutputLayerNormCoefficientsTensor] =
206
+ nullptr;
207
+ // Output tensor
208
+ kernel_content.output_tensor = node_contents.OutputEvalTensor();
209
+ return kernel_content;
210
+ }
211
+
212
+ // Deduce the size information (Batch (B), Time Steps (T), Input dimension (I),
213
+ // State dimension (S)) that defines the LSTM using the input and hidden state
214
+ // tensor
215
+ LstmSizeInfo CreateLstmSizeInfo(
216
+ const bool time_major, const TfLiteIntArray* input_tensor_shape,
217
+ const TfLiteIntArray* hidden_state_tensor_shape) {
218
+ LstmSizeInfo size_info;
219
+ size_info.time_major = time_major;
220
+ size_info.batch_size =
221
+ time_major ? input_tensor_shape->data[1] : input_tensor_shape->data[0];
222
+ size_info.time_steps =
223
+ time_major ? input_tensor_shape->data[0] : input_tensor_shape->data[1];
224
+ size_info.input_dimension = input_tensor_shape->data[2];
225
+ size_info.state_dimension = hidden_state_tensor_shape->data[1];
226
+ return size_info;
227
+ }
228
+
229
+ // Create the LstmOpData using the LstmNodeContent and
230
+ // NodeQuantizationParameters (defined in test_data/lstm_test_data) During the
231
+ // actual inference phase, OpDataLSTM is created using information from the
232
+ // flatbuffer file. The test divide the complete LSTM node information into
233
+ // LstmNodeContent and NodeQuantizationParameters for easy construction
234
+ // purposes
235
+ template <typename ActivationType, typename WeightType, typename BiasType,
236
+ typename CellType, int batch_size, int time_steps,
237
+ int input_dimension, int state_dimension>
238
+ OpDataLSTM CreateLstmOpData(
239
+ LstmNodeContent<ActivationType, WeightType, BiasType, CellType, batch_size,
240
+ time_steps, input_dimension, state_dimension>&
241
+ node_contents) {
242
+ const auto& builtin_data = node_contents.BuiltinData();
243
+ const auto& quantization_settings = node_contents.QuantizationSettings();
244
+ OpDataLSTM op_data;
245
+
246
+ op_data.cell_gate_nonlinear_type = builtin_data.activation;
247
+ op_data.size_info =
248
+ CreateLstmSizeInfo(builtin_data.time_major,
249
+ node_contents.GetEvalTensor(kLstmInputTensor)->dims,
250
+ node_contents.HiddenStateEvalTensor()->dims);
251
+
252
+ op_data.cell_state_info = CreateLstmCellStateInfo(
253
+ quantization_settings.cell_state.scale, builtin_data.cell_clip);
254
+
255
+ // Gate Parameters
256
+ op_data.forget_gate_parameters = CreateGateParams<CellType>(
257
+ quantization_settings.input, quantization_settings.hidden_state,
258
+ quantization_settings.forget_gate,
259
+ quantization_settings.nonlinear_activation_input_scale);
260
+ op_data.input_gate_parameters = CreateGateParams<CellType>(
261
+ quantization_settings.input, quantization_settings.hidden_state,
262
+ quantization_settings.input_gate,
263
+ quantization_settings.nonlinear_activation_input_scale);
264
+ op_data.cell_gate_parameters = CreateGateParams<CellType>(
265
+ quantization_settings.input, quantization_settings.hidden_state,
266
+ quantization_settings.cell_gate,
267
+ quantization_settings.nonlinear_activation_input_scale);
268
+ op_data.output_gate_parameters = CreateGateParams<CellType>(
269
+ quantization_settings.input, quantization_settings.hidden_state,
270
+ quantization_settings.output_gate,
271
+ quantization_settings.nonlinear_activation_input_scale);
272
+ // Inter gate multiplication parameters
273
+ op_data.inter_gate_parameters.forget_cell_mul_params =
274
+ CreateInterGateMulParams<CellType>(
275
+ quantization_settings.nonlinear_activation_output_scale,
276
+ quantization_settings.cell_state.scale,
277
+ quantization_settings.cell_state.scale);
278
+ op_data.inter_gate_parameters.input_mul_params =
279
+ CreateInterGateMulParams<CellType>(
280
+ quantization_settings.nonlinear_activation_output_scale,
281
+ quantization_settings.nonlinear_activation_output_scale,
282
+ quantization_settings.cell_state.scale);
283
+ op_data.inter_gate_parameters.output_mul_params =
284
+ CreateInterGateMulParams<ActivationType>(
285
+ quantization_settings.nonlinear_activation_output_scale,
286
+ quantization_settings.nonlinear_activation_output_scale,
287
+ quantization_settings.hidden_state.scale,
288
+ quantization_settings.hidden_state.zero_point);
289
+ return op_data;
290
+ }
291
+
292
+ template <int batch_size, int time_steps, int input_dimension,
293
+ int state_dimension>
294
+ OpDataLSTM CreateLstmOpDataFloat(
295
+ LstmNodeContent<float, float, float, float, batch_size, time_steps,
296
+ input_dimension, state_dimension>& node_contents) {
297
+ const auto& builtin_data = node_contents.BuiltinData();
298
+ OpDataLSTM op_data;
299
+
300
+ op_data.cell_gate_nonlinear_type = builtin_data.activation;
301
+ op_data.size_info =
302
+ CreateLstmSizeInfo(builtin_data.time_major,
303
+ node_contents.GetEvalTensor(kLstmInputTensor)->dims,
304
+ node_contents.HiddenStateEvalTensor()->dims);
305
+ op_data.cell_state_info.cell_clip = builtin_data.cell_clip;
306
+ op_data.cell_state_info.quantized_cell_clip = 0; // No quantization
307
+ op_data.cell_state_info.cell_state_scale_power = 0; // No quantization
308
+
309
+ // Gate Parameters
310
+ op_data.forget_gate_parameters = CreateGateParamsFloat();
311
+ op_data.input_gate_parameters = CreateGateParamsFloat();
312
+ op_data.cell_gate_parameters = CreateGateParamsFloat();
313
+ op_data.output_gate_parameters = CreateGateParamsFloat();
314
+ // Inter gate multiplication parameters
315
+ op_data.inter_gate_parameters.forget_cell_mul_params =
316
+ CreateInterGateMulParamsFloat();
317
+ op_data.inter_gate_parameters.input_mul_params =
318
+ CreateInterGateMulParamsFloat();
319
+ op_data.inter_gate_parameters.output_mul_params =
320
+ CreateInterGateMulParamsFloat();
321
+ return op_data;
322
+ }
323
+
324
+ /*Test Functions Below Here*/
325
+ template <typename T>
326
+ void ValidateResultGoldens(const T* golden, const T* output_data,
327
+ const int output_len, const float tolerance) {
328
+ for (int i = 0; i < output_len; ++i) {
329
+ TF_LITE_MICRO_EXPECT_NEAR(golden[i], output_data[i], tolerance);
330
+ }
331
+ }
332
+
333
+ template <int batch_size, int state_dimension>
334
+ void TestCalculateLstmGateFloat(const TfLiteEvalTensor* input,
335
+ const TfLiteEvalTensor* input_weight,
336
+ const TfLiteEvalTensor* input_bias,
337
+ // Recurrent FC
338
+ const TfLiteEvalTensor* recurrent,
339
+ const TfLiteEvalTensor* recurrent_weight,
340
+ const TfLiteEvalTensor* recurrent_bias,
341
+ // Result comparison
342
+ TfLiteFusedActivation nonlinear_type,
343
+ const float* expected_vals, float tolerance) {
344
+ float gate_output[batch_size * state_dimension] = {};
345
+ float fc_output_buffer[batch_size * state_dimension] = {};
346
+
347
+ tflite_micro::GateParameters gate_params = CreateGateParamsFloat();
348
+
349
+ // Create step information: only one time step, no need to update
350
+ auto size_info = tflite_micro::testing::CreateLstmSizeInfo(
351
+ /*time_major*/ false, input->dims, recurrent->dims);
352
+ // revise time_major = true to enable batch inference
353
+ size_info.time_major = true;
354
+ tflite_micro::lstm_internal::LstmStepManager step_info(&size_info);
355
+
356
+ tflite_micro::lstm_internal::CalculateLstmGate<float, float, float, float>(
357
+ step_info, gate_params,
358
+ // Input FC
359
+ input, input_weight, input_bias,
360
+ // Recurrent FC
361
+ recurrent, recurrent_weight, recurrent_bias,
362
+ // Output
363
+ gate_output,
364
+ // Scratch arrays
365
+ fc_output_buffer, nonlinear_type);
366
+
367
+ ValidateResultGoldens(expected_vals, gate_output,
368
+ batch_size * state_dimension, tolerance);
369
+ }
370
+
371
+ template <typename ActivationType, typename WeightType, typename BiasType,
372
+ typename CellType, int batch_size, int state_dimension>
373
+ void TestCalculateLstmGateInteger(
374
+ const TfLiteEvalTensor* input, const TfLiteEvalTensor* input_weight,
375
+ const TfLiteEvalTensor* input_bias,
376
+ // Recurrent FC
377
+ const TfLiteEvalTensor* recurrent, const TfLiteEvalTensor* recurrent_weight,
378
+ const TfLiteEvalTensor* recurrent_bias,
379
+ // Quantization settings
380
+ const NodeQuantizationParameters& node_quantization_settings,
381
+ const GateQuantizationParameters& gate_quantization_settings,
382
+ // Result comparison
383
+ TfLiteFusedActivation nonlinear_type, const float* expected_vals,
384
+ float tolerance) {
385
+ CellType gate_output[batch_size * state_dimension] = {};
386
+ CellType fc_output_buffer[batch_size * state_dimension] = {};
387
+
388
+ tflite_micro::GateParameters gate_params = CreateGateParams<CellType>(
389
+ node_quantization_settings.input, node_quantization_settings.hidden_state,
390
+ gate_quantization_settings,
391
+ node_quantization_settings.nonlinear_activation_input_scale);
392
+
393
+ // Create step information: only one time step, no need to update
394
+ auto size_info = tflite_micro::testing::CreateLstmSizeInfo(
395
+ /*time_major*/ false, input->dims, recurrent->dims);
396
+ // revise time_major = true to enable batch inference
397
+ size_info.time_major = true;
398
+ tflite_micro::lstm_internal::LstmStepManager step_info(&size_info);
399
+
400
+ // only int8 weight is supported now
401
+ tflite_micro::lstm_internal::CalculateLstmGate<ActivationType, WeightType, CellType,
402
+ BiasType>(
403
+ step_info, gate_params,
404
+ // Input FC
405
+ input, input_weight, input_bias,
406
+ // Recurrent FC
407
+ recurrent, recurrent_weight, recurrent_bias,
408
+ // Output
409
+ gate_output,
410
+ // Scratch arrays
411
+ fc_output_buffer, nonlinear_type);
412
+
413
+ float gate_output_float[batch_size * state_dimension] = {};
414
+ Dequantize(gate_output, batch_size * state_dimension,
415
+ node_quantization_settings.nonlinear_activation_output_scale, 0,
416
+ gate_output_float);
417
+
418
+ ValidateResultGoldens(expected_vals, gate_output_float,
419
+ batch_size * state_dimension, tolerance);
420
+ }
421
+
422
+ template <int batch_size, int time_steps, int input_dimension,
423
+ int state_dimension>
424
+ void TestUpdateLstmCellFloat(
425
+ const GateOutputCheckData<batch_size * input_dimension,
426
+ batch_size * state_dimension>& gate_output_data,
427
+ LstmNodeContent<float, float, float, float, batch_size, time_steps,
428
+ input_dimension, state_dimension>& node_content,
429
+ const float tolerance) {
430
+ float buffer[batch_size * state_dimension] = {};
431
+
432
+ auto forget_cell_mul_params = CreateInterGateMulParamsFloat();
433
+ auto input_mul_params = CreateInterGateMulParamsFloat();
434
+
435
+ auto cell_state = node_content.CellStateEvalTensor();
436
+ // Create step information: only one time step, no need to update
437
+ auto size_info = tflite_micro::testing::CreateLstmSizeInfo(
438
+ /*time_major*/ false,
439
+ node_content.GetEvalTensor(tflite_micro::kLstmInputTensor)->dims,
440
+ node_content.HiddenStateEvalTensor()->dims);
441
+ // revise time_major = true to enable batch inference
442
+ size_info.time_major = true;
443
+ tflite_micro::lstm_internal::LstmStepManager step_info(&size_info);
444
+
445
+ // copy the data since it will be updated
446
+ float forget_gate[batch_size * state_dimension] = {};
447
+ std::memcpy(forget_gate, gate_output_data.expected_forget_gate_output,
448
+ batch_size * state_dimension * sizeof(float));
449
+
450
+ CellStateInfo cell_state_info;
451
+ cell_state_info.cell_clip = node_content.BuiltinData().cell_clip;
452
+ // Call the function to be tested
453
+ tflite_micro::lstm_internal::UpdateLstmCell<float>(
454
+ step_info, cell_state, forget_gate,
455
+ gate_output_data.expected_input_gate_output,
456
+ gate_output_data.expected_cell_gate_output, forget_cell_mul_params,
457
+ input_mul_params, cell_state_info, buffer);
458
+
459
+ ValidateResultGoldens(gate_output_data.expected_updated_cell,
460
+ tflite_micro::micro::GetTensorData<float>(cell_state),
461
+ batch_size * state_dimension, tolerance);
462
+ }
463
+
464
+ template <typename ActivationType, typename WeightType, typename BiasType,
465
+ typename CellType, int batch_size, int time_steps,
466
+ int input_dimension, int state_dimension>
467
+ void TestUpdateLstmCellInteger(
468
+ const GateOutputCheckData<batch_size * input_dimension,
469
+ batch_size * state_dimension>& gate_output_data,
470
+ LstmNodeContent<ActivationType, WeightType, BiasType, CellType, batch_size,
471
+ time_steps, input_dimension, state_dimension>& node_content,
472
+ const float tolerance) {
473
+ const auto& quantization_settings = node_content.QuantizationSettings();
474
+ CellType quantized_forget_gate[batch_size * state_dimension] = {};
475
+ tflite_micro::Quantize(gate_output_data.expected_forget_gate_output,
476
+ quantized_forget_gate, batch_size * state_dimension,
477
+ quantization_settings.nonlinear_activation_output_scale, 0);
478
+
479
+ CellType quantized_input_gate[batch_size * state_dimension] = {};
480
+ tflite_micro::Quantize(gate_output_data.expected_input_gate_output,
481
+ quantized_input_gate, batch_size * state_dimension,
482
+ quantization_settings.nonlinear_activation_output_scale, 0);
483
+
484
+ CellType quantized_cell_gate[batch_size * state_dimension] = {};
485
+ tflite_micro::Quantize(gate_output_data.expected_cell_gate_output,
486
+ quantized_cell_gate, batch_size * state_dimension,
487
+ quantization_settings.nonlinear_activation_output_scale, 0);
488
+
489
+ CellType buffer[batch_size * state_dimension] = {};
490
+
491
+ auto forget_cell_mul_params = CreateInterGateMulParams<CellType>(
492
+ quantization_settings.nonlinear_activation_output_scale,
493
+ quantization_settings.cell_state.scale,
494
+ quantization_settings.cell_state.scale);
495
+ auto input_mul_params = CreateInterGateMulParams<CellType>(
496
+ quantization_settings.nonlinear_activation_output_scale,
497
+ quantization_settings.nonlinear_activation_output_scale,
498
+ quantization_settings.cell_state.scale);
499
+
500
+ auto cell_state_info =
501
+ CreateLstmCellStateInfo(quantization_settings.cell_state.scale,
502
+ node_content.BuiltinData().cell_clip);
503
+
504
+ auto cell_state = node_content.CellStateEvalTensor();
505
+ // Create step information: only one time step, no need to update
506
+ auto size_info = tflite_micro::testing::CreateLstmSizeInfo(
507
+ /*time_major*/ false,
508
+ node_content.GetEvalTensor(tflite_micro::kLstmInputTensor)->dims,
509
+ node_content.HiddenStateEvalTensor()->dims);
510
+ // revise time_major = true to enable batch inference
511
+ size_info.time_major = true;
512
+ tflite_micro::lstm_internal::LstmStepManager step_info(&size_info);
513
+
514
+ // Call the function to be tested
515
+ tflite_micro::lstm_internal::UpdateLstmCell<CellType>(
516
+ step_info, cell_state, quantized_forget_gate, quantized_input_gate,
517
+ quantized_cell_gate, forget_cell_mul_params, input_mul_params,
518
+ cell_state_info, buffer);
519
+
520
+ float cell_state_float[batch_size * state_dimension] = {};
521
+ Dequantize(tflite_micro::micro::GetTensorData<CellType>(cell_state),
522
+ batch_size * state_dimension,
523
+ quantization_settings.cell_state.scale,
524
+ quantization_settings.cell_state.zero_point, cell_state_float);
525
+
526
+ ValidateResultGoldens(gate_output_data.expected_updated_cell,
527
+ cell_state_float, batch_size * state_dimension,
528
+ tolerance);
529
+ }
530
+
531
+ template <int batch_size, int time_steps, int input_dimension,
532
+ int state_dimension>
533
+ void TestUpdateLstmHiddenFloat(
534
+ const GateOutputCheckData<batch_size * input_dimension,
535
+ batch_size * state_dimension>& gate_output_data,
536
+ LstmNodeContent<float, float, float, float, batch_size, time_steps,
537
+ input_dimension, state_dimension>& node_content,
538
+ const float tolerance) {
539
+ float buffer[batch_size * state_dimension] = {};
540
+
541
+ auto mul_params = CreateInterGateMulParamsFloat();
542
+
543
+ int32_t cell_state_scale_power = 0;
544
+
545
+ // Create step information: only one time step, no need to update
546
+ auto size_info = tflite_micro::testing::CreateLstmSizeInfo(
547
+ /*time_major*/ false,
548
+ node_content.GetEvalTensor(tflite_micro::kLstmInputTensor)->dims,
549
+ node_content.HiddenStateEvalTensor()->dims);
550
+ // revise time_major = true to enable batch inference
551
+ size_info.time_major = true;
552
+ tflite_micro::lstm_internal::LstmStepManager step_info(&size_info);
553
+
554
+ auto cell_state = node_content.CellStateEvalTensor();
555
+ auto hidden_state = node_content.HiddenStateEvalTensor();
556
+
557
+ tflite_micro::lstm_internal::UpdateLstmHidden<float, float>(
558
+ step_info, cell_state, hidden_state,
559
+ gate_output_data.expected_output_gate_output, mul_params,
560
+ cell_state_scale_power, buffer);
561
+
562
+ ValidateResultGoldens(gate_output_data.expected_updated_hidden,
563
+ tflite_micro::micro::GetTensorData<float>(hidden_state),
564
+ batch_size * state_dimension, tolerance);
565
+ }
566
+
567
+ template <typename ActivationType, typename WeightType, typename BiasType,
568
+ typename CellType, int batch_size, int time_steps,
569
+ int input_dimension, int state_dimension>
570
+ void TestUpdateLstmHiddenInteger(
571
+ const GateOutputCheckData<batch_size * input_dimension,
572
+ batch_size * state_dimension>& gate_output_data,
573
+ LstmNodeContent<ActivationType, WeightType, BiasType, CellType, batch_size,
574
+ time_steps, input_dimension, state_dimension>& node_content,
575
+ const float tolerance) {
576
+ const auto& quantization_settings = node_content.QuantizationSettings();
577
+ CellType quantized_output_gate[batch_size * state_dimension] = {};
578
+ tflite_micro::Quantize(gate_output_data.expected_output_gate_output,
579
+ quantized_output_gate, batch_size * state_dimension,
580
+ quantization_settings.nonlinear_activation_output_scale, 0);
581
+
582
+ CellType buffer[batch_size * state_dimension] = {};
583
+
584
+ auto mul_params = CreateInterGateMulParams<ActivationType>(
585
+ quantization_settings.nonlinear_activation_output_scale,
586
+ quantization_settings.nonlinear_activation_output_scale,
587
+ quantization_settings.hidden_state.scale,
588
+ quantization_settings.hidden_state.zero_point);
589
+
590
+ int cell_state_scale_power_buffer;
591
+ tflite_micro::CheckedLog2(quantization_settings.cell_state.scale,
592
+ &cell_state_scale_power_buffer);
593
+ int32_t cell_state_scale_power = cell_state_scale_power_buffer;
594
+
595
+ // Create step information: only one time step, no need to update
596
+ auto size_info = tflite_micro::testing::CreateLstmSizeInfo(
597
+ /*time_major*/ false,
598
+ node_content.GetEvalTensor(tflite_micro::kLstmInputTensor)->dims,
599
+ node_content.HiddenStateEvalTensor()->dims);
600
+ // revise time_major = true to enable batch inference
601
+ size_info.time_major = true;
602
+ tflite_micro::lstm_internal::LstmStepManager step_info(&size_info);
603
+
604
+ auto cell_state = node_content.CellStateEvalTensor();
605
+ auto hidden_state = node_content.HiddenStateEvalTensor();
606
+
607
+ tflite_micro::lstm_internal::UpdateLstmHidden<CellType, ActivationType>(
608
+ step_info, cell_state, hidden_state, quantized_output_gate, mul_params,
609
+ cell_state_scale_power, buffer);
610
+
611
+ float hidden_state_float[batch_size * state_dimension] = {};
612
+ Dequantize(tflite_micro::micro::GetTensorData<ActivationType>(hidden_state),
613
+ batch_size * state_dimension,
614
+ quantization_settings.hidden_state.scale,
615
+ quantization_settings.hidden_state.zero_point, hidden_state_float);
616
+
617
+ ValidateResultGoldens(gate_output_data.expected_updated_hidden,
618
+ hidden_state_float, batch_size * state_dimension,
619
+ tolerance);
620
+ }
621
+
622
+ template <int batch_size, int time_steps, int input_dimension,
623
+ int state_dimension>
624
+ void TestLstmStepFloat(
625
+ const GateOutputCheckData<batch_size * input_dimension,
626
+ batch_size * state_dimension>& gate_output_data,
627
+ const float hidden_state_tolerance, const float cell_state_tolerance,
628
+ /*can not be const, state will be updated*/
629
+ LstmNodeContent<float, float, float, float, batch_size, time_steps,
630
+ input_dimension, state_dimension>& node_contents) {
631
+ // Mimicking the kernel preparation phase, node_contents approximate the
632
+ LSTMKernelContents kernel_content = CreateLSTMKernelContent(node_contents);
633
+ LSTMBuffers<float> buffers;
634
+ // Scratch buffers on the stack
635
+ float buffer0[batch_size * state_dimension] = {};
636
+ buffers.buffer0 = buffer0;
637
+ float buffer1[batch_size * state_dimension] = {};
638
+ buffers.buffer1 = buffer1;
639
+ float buffer2[batch_size * state_dimension] = {};
640
+ buffers.buffer2 = buffer2;
641
+ float buffer3[batch_size * state_dimension] = {};
642
+ buffers.buffer3 = buffer3;
643
+
644
+ OpDataLSTM op_data = CreateLstmOpDataFloat(node_contents);
645
+ // set time_major to true to test batch inference
646
+ op_data.size_info.time_major = true;
647
+ tflite_micro::lstm_internal::LstmStepManager step_info(&op_data.size_info);
648
+ tflite_micro::lstm_internal::LstmStep<float, float, float, float>(
649
+ step_info, op_data, kernel_content, buffers);
650
+
651
+ ValidateResultGoldens(
652
+ gate_output_data.expected_updated_hidden,
653
+ tflite_micro::micro::GetTensorData<float>(kernel_content.HiddenStateTensor()),
654
+ batch_size * state_dimension, hidden_state_tolerance);
655
+ ValidateResultGoldens(
656
+ gate_output_data.expected_updated_cell,
657
+ tflite_micro::micro::GetTensorData<float>(kernel_content.CellStateTensor()),
658
+ batch_size * state_dimension, cell_state_tolerance);
659
+ }
660
+
661
+ template <typename ActivationType, typename WeightType, typename BiasType,
662
+ typename CellType, int batch_size, int time_steps,
663
+ int input_dimension, int state_dimension>
664
+ void TestLstmStepInteger(
665
+ const GateOutputCheckData<batch_size * input_dimension,
666
+ batch_size * state_dimension>& gate_output_data,
667
+ const float hidden_state_tolerance, const float cell_state_tolerance,
668
+ /*can not be const, state will be updated*/
669
+ LstmNodeContent<ActivationType, WeightType, BiasType, CellType, batch_size,
670
+ time_steps, input_dimension, state_dimension>&
671
+ node_contents) {
672
+ // Mimicking the kernel preparation phase, node_contents approximate the
673
+ LSTMKernelContents kernel_content = CreateLSTMKernelContent(node_contents);
674
+ LSTMBuffers<CellType> buffers;
675
+
676
+ // Scratch buffers on the stack
677
+ CellType buffer0[batch_size * state_dimension] = {};
678
+ buffers.buffer0 = buffer0;
679
+ CellType buffer1[batch_size * state_dimension] = {};
680
+ buffers.buffer1 = buffer1;
681
+ CellType buffer2[batch_size * state_dimension] = {};
682
+ buffers.buffer2 = buffer2;
683
+ CellType buffer3[batch_size * state_dimension] = {};
684
+ buffers.buffer3 = buffer3;
685
+
686
+ OpDataLSTM op_data = CreateLstmOpData(node_contents);
687
+ // set time_major to true to test batch inference
688
+ op_data.size_info.time_major = true;
689
+ tflite_micro::lstm_internal::LstmStepManager step_info(&op_data.size_info);
690
+ tflite_micro::lstm_internal::LstmStep<ActivationType, WeightType, CellType,
691
+ BiasType>(step_info, op_data, kernel_content,
692
+ buffers);
693
+
694
+ const auto& quantization_settings = node_contents.QuantizationSettings();
695
+ float dequantized_hidden_state[batch_size * state_dimension] = {};
696
+ Dequantize(
697
+ tflite_micro::micro::GetTensorData<ActivationType>(
698
+ kernel_content.HiddenStateTensor()),
699
+ batch_size * state_dimension, quantization_settings.hidden_state.scale,
700
+ quantization_settings.hidden_state.zero_point, dequantized_hidden_state);
701
+
702
+ float dequantized_cell_state[batch_size * state_dimension] = {};
703
+ Dequantize(
704
+ tflite_micro::micro::GetTensorData<CellType>(kernel_content.CellStateTensor()),
705
+ batch_size * state_dimension, quantization_settings.cell_state.scale,
706
+ quantization_settings.cell_state.zero_point, dequantized_cell_state);
707
+
708
+ ValidateResultGoldens(gate_output_data.expected_updated_hidden,
709
+ dequantized_hidden_state, batch_size * state_dimension,
710
+ hidden_state_tolerance);
711
+ ValidateResultGoldens(gate_output_data.expected_updated_cell,
712
+ dequantized_cell_state, batch_size * state_dimension,
713
+ cell_state_tolerance);
714
+ }
715
+
716
+ template <int batch_size, int time_steps, int input_dimension,
717
+ int state_dimension>
718
+ void TestEvalLstmFloat(
719
+ const LstmEvalCheckData<
720
+ batch_size * time_steps * input_dimension, batch_size * state_dimension,
721
+ batch_size * state_dimension * time_steps>& eval_check_data,
722
+ const float hidden_state_tolerance, const float cell_state_tolerance,
723
+ LstmNodeContent<float, float, float, float, batch_size, time_steps,
724
+ input_dimension, state_dimension>& node_contents) {
725
+ // Mimicking the kernel preparation phase, node_contents approximate the node
726
+ LSTMKernelContents kernel_content = CreateLSTMKernelContent(node_contents);
727
+ // Scratch buffers on the stack
728
+ LSTMBuffers<float> buffers;
729
+ float buffer0[batch_size * state_dimension] = {};
730
+ buffers.buffer0 = buffer0;
731
+ float buffer1[batch_size * state_dimension] = {};
732
+ buffers.buffer1 = buffer1;
733
+ float buffer2[batch_size * state_dimension] = {};
734
+ buffers.buffer2 = buffer2;
735
+ float buffer3[batch_size * state_dimension] = {};
736
+ buffers.buffer3 = buffer3;
737
+
738
+ OpDataLSTM op_data = CreateLstmOpDataFloat(node_contents);
739
+
740
+ tflite_micro::EvalLstm<float, float, float, float>(op_data, kernel_content,
741
+ buffers);
742
+
743
+ ValidateResultGoldens(eval_check_data.expected_hidden_state,
744
+ node_contents.GetHiddenStateData(),
745
+ batch_size * state_dimension, hidden_state_tolerance);
746
+
747
+ ValidateResultGoldens(eval_check_data.expected_cell_state,
748
+ node_contents.GetCellStateData(),
749
+ batch_size * state_dimension, cell_state_tolerance);
750
+
751
+ ValidateResultGoldens(eval_check_data.expected_output,
752
+ node_contents.GetOutputData(),
753
+ batch_size * state_dimension, hidden_state_tolerance);
754
+ }
755
+
756
+ template <typename ActivationType, typename WeightType, typename BiasType,
757
+ typename CellType, int batch_size, int time_steps,
758
+ int input_dimension, int state_dimension>
759
+ void TestEvalLstmInteger(
760
+ const LstmEvalCheckData<
761
+ batch_size * time_steps * input_dimension, batch_size * state_dimension,
762
+ batch_size * state_dimension * time_steps>& eval_check_data,
763
+ const float hidden_state_tolerance, const float cell_state_tolerance,
764
+ LstmNodeContent<ActivationType, WeightType, BiasType, CellType, batch_size,
765
+ time_steps, input_dimension, state_dimension>&
766
+ node_contents) {
767
+ // Mimicking the kernel preparation phase, node_contents approximate the node
768
+ LSTMKernelContents kernel_content = CreateLSTMKernelContent(node_contents);
769
+ // Scratch buffers on the stack
770
+ LSTMBuffers<CellType> buffers;
771
+ CellType buffer0[batch_size * state_dimension] = {};
772
+ buffers.buffer0 = buffer0;
773
+ CellType buffer1[batch_size * state_dimension] = {};
774
+ buffers.buffer1 = buffer1;
775
+ CellType buffer2[batch_size * state_dimension] = {};
776
+ buffers.buffer2 = buffer2;
777
+ CellType buffer3[batch_size * state_dimension] = {};
778
+ buffers.buffer3 = buffer3;
779
+
780
+ OpDataLSTM op_data = CreateLstmOpData(node_contents);
781
+
782
+ tflite_micro::EvalLstm<ActivationType, WeightType, CellType, BiasType>(
783
+ op_data, kernel_content, buffers);
784
+
785
+ const auto& quantization_settings = node_contents.QuantizationSettings();
786
+ float dequantized_hidden_state[batch_size * state_dimension] = {};
787
+ Dequantize(node_contents.GetHiddenStateData(), batch_size * state_dimension,
788
+ quantization_settings.hidden_state.scale,
789
+ quantization_settings.hidden_state.zero_point,
790
+ dequantized_hidden_state);
791
+
792
+ ValidateResultGoldens(eval_check_data.expected_hidden_state,
793
+ dequantized_hidden_state, batch_size * state_dimension,
794
+ hidden_state_tolerance);
795
+
796
+ float dequantized_cell_state[batch_size * state_dimension] = {};
797
+ Dequantize(node_contents.GetCellStateData(), batch_size * state_dimension,
798
+ quantization_settings.cell_state.scale,
799
+ quantization_settings.cell_state.zero_point,
800
+ dequantized_cell_state);
801
+ ValidateResultGoldens(eval_check_data.expected_cell_state,
802
+ dequantized_cell_state, batch_size * state_dimension,
803
+ cell_state_tolerance);
804
+
805
+ float dequantized_output[batch_size * state_dimension * time_steps] = {};
806
+ Dequantize(node_contents.GetOutputData(),
807
+ batch_size * state_dimension * time_steps,
808
+ quantization_settings.output.scale,
809
+ quantization_settings.output.zero_point, dequantized_output);
810
+ ValidateResultGoldens(eval_check_data.expected_output, dequantized_output,
811
+ batch_size * state_dimension, hidden_state_tolerance);
812
+ }
813
+
814
+ } // namespace testing
815
+ } // namespace tflite_micro
816
+
817
+ #endif // TENSORFLOW_LITE_MICRO_KERNELS_LSTM_EVAL_TEST_H_