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,170 @@
1
+ /* Copyright 2019 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_MEMORY_PLANNER_GREEDY_MEMORY_PLANNER_H_
17
+ #define TENSORFLOW_LITE_MICRO_MEMORY_PLANNER_GREEDY_MEMORY_PLANNER_H_
18
+
19
+ #include "tensorflow/lite/micro/compatibility.h"
20
+ #include "tensorflow/lite/micro/memory_planner/micro_memory_planner.h"
21
+
22
+ namespace tflite_micro {
23
+
24
+ constexpr int kOnlinePlannedBuffer = -1;
25
+
26
+ // A memory planner that uses a greedy algorithm to arrange buffers in memory
27
+ // to minimize the overall arena size needed.
28
+ //
29
+ // The algorithm works like this:
30
+ // - The client enters the buffer information through AddBuffer().
31
+ // - When a function like GetOffsetForBuffer() is called, the
32
+ // CalculateOffsetsIfNeeded() method is invoked.
33
+ // - If an up to date plan is not already present, one will be calculated.
34
+ // - The buffers are sorted in descending order of size.
35
+ // - The largest buffer is placed at offset zero.
36
+ // - The rest of the buffers are looped through in descending size order.
37
+ // - The other buffers that need to be in memory at the same time are found.
38
+ // - The first gap between simultaneously active buffers that the current
39
+ // buffer fits into will be used.
40
+ // - If no large-enough gap is found, the current buffer is placed after the
41
+ // last buffer that's simultaneously active.
42
+ // - This continues until all buffers are placed, and the offsets stored.
43
+ //
44
+ // This is not guaranteed to produce the best placement, since that's an
45
+ // NP-Complete problem, but in practice it should produce one that's decent.
46
+ class GreedyMemoryPlanner : public MicroMemoryPlanner {
47
+ public:
48
+ GreedyMemoryPlanner();
49
+ ~GreedyMemoryPlanner() override;
50
+
51
+ // You need to pass in an area of memory to be used for planning. The client
52
+ // should ensure the validity of the memory when it needs to use this object.
53
+ // This memory isn't owned by this object, so management should be handled by
54
+ // the client. This is so it can be stack or globally allocated if necessary
55
+ // on devices without dynamic memory allocation. How many buffers can be
56
+ // planned for will depend on the size of this scratch memory, so you should
57
+ // enlarge it if you see an error when calling AddBuffer(). The memory can be
58
+ // reused once you're done with the planner, as long as you copy the
59
+ // calculated offsets to another location. Each buffer requires about 36 bytes
60
+ // of scratch.
61
+ TfLiteStatus Init(unsigned char* scratch_buffer,
62
+ int scratch_buffer_size) override;
63
+
64
+ // Record details of a buffer we want to place.
65
+ TfLiteStatus AddBuffer(int size, int first_time_used,
66
+ int last_time_used) override;
67
+
68
+ // Record details of an offline planned buffer offset we want to place.
69
+ // offline_offset is the buffer offset from the start of the arena.
70
+ TfLiteStatus AddBuffer(int size, int first_time_used, int last_time_used,
71
+ int offline_offset) override;
72
+
73
+ // Returns the high-water mark of used memory. This is the minimum size of a
74
+ // memory arena you'd need to allocate to hold these buffers.
75
+ size_t GetMaximumMemorySize() override;
76
+
77
+ // How many buffers have been recorded.
78
+ int GetBufferCount() override;
79
+
80
+ // Where a given buffer should be placed in the memory arena.
81
+ // This information is stored in the memory arena itself, so once the arena
82
+ // is used for inference, it will be overwritten.
83
+ TfLiteStatus GetOffsetForBuffer(int buffer_index, int* offset) override;
84
+
85
+ // Prints an ascii-art diagram of the buffer layout plan.
86
+ void PrintMemoryPlan() override;
87
+
88
+ // Debug method to check whether any buffer allocations are overlapping. This
89
+ // is an O(N^2) complexity operation, so only use for testing.
90
+ bool DoAnyBuffersOverlap();
91
+
92
+ // Used to store a list of buffers ordered by their offset.
93
+ struct ListEntry {
94
+ int offset;
95
+ int requirements_index;
96
+ int next_entry_index;
97
+ };
98
+
99
+ // Number of bytes required in order to plan a buffer.
100
+ static size_t per_buffer_size() {
101
+ const int per_buffer_size =
102
+ sizeof(BufferRequirements) + // requirements_
103
+ sizeof(int) + // buffer_sizes_sorted_
104
+ sizeof(int) + // buffer_ids_sorted_
105
+ sizeof(ListEntry) + // buffers_sorted_by_offset_
106
+ sizeof(int); // buffer_offsets_;
107
+ return per_buffer_size;
108
+ }
109
+
110
+ // Returns False because the GreedyMemoryPlanner doesn't preserves all tensors
111
+ // after invocation. Do to the fact that tensors that tensor data for tensors
112
+ // that aren't being used during a phase of invocation are overwritten.
113
+ bool preserves_all_tensors() const override { return false; }
114
+
115
+ TF_LITE_REMOVE_VIRTUAL_DELETE
116
+
117
+ private:
118
+ // Whether a buffer is active in a given time range.
119
+ bool DoesEntryOverlapInTime(const ListEntry* entry, const int first_time_used,
120
+ const int last_time_used) const;
121
+
122
+ // Walks the list to return the next buffer that is active in a given time
123
+ // range, or a null pointer if there are none.
124
+ ListEntry* NextSimultaneouslyActiveBuffer(const ListEntry* start,
125
+ const int first_time_used,
126
+ const int last_time_used);
127
+
128
+ // If there isn't an up to date plan, calculate a new one.
129
+ void CalculateOffsetsIfNeeded();
130
+
131
+ // How many buffers we can plan for, based on the arena size we're given in
132
+ // the constructor.
133
+ int max_buffer_count_;
134
+
135
+ // The number of buffers added so far.
136
+ int buffer_count_;
137
+
138
+ // Records the client-provided information about each buffer.
139
+ struct BufferRequirements {
140
+ int size;
141
+ int offline_offset;
142
+ int first_time_used;
143
+ int last_time_used;
144
+ };
145
+
146
+ // Working arrays used during the layout algorithm.
147
+ BufferRequirements* requirements_;
148
+ // buffer_sizes_sorted_ and buffer_ids_sorted_ are sorted according to:
149
+ // {
150
+ // offline planned buffers,
151
+ // online planned buffers sorted by size
152
+ // }
153
+ int* buffer_sizes_sorted_;
154
+ int* buffer_ids_sorted_;
155
+ ListEntry* buffers_sorted_by_offset_;
156
+ int next_free_entry_; // Index of the next free entry of
157
+ // buffers_sorted_by_offset_
158
+ int first_entry_index_; // Index of the first entry (smallest offset) of
159
+ // buffers_sorted_by_offset_
160
+
161
+ // Stores the outcome of the plan, the location of each buffer in the arena.
162
+ int* buffer_offsets_;
163
+
164
+ // Whether buffers have been added since the last plan was calculated.
165
+ bool need_to_calculate_offsets_;
166
+ };
167
+
168
+ } // namespace tflite_micro
169
+
170
+ #endif // TENSORFLOW_LITE_MICRO_MEMORY_PLANNER_GREEDY_MEMORY_PLANNER_H_
@@ -0,0 +1,53 @@
1
+ /* Copyright 2019 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_MEMORY_PLANNER_LINEAR_MEMORY_PLANNER_H_
17
+ #define TENSORFLOW_LITE_MICRO_MEMORY_PLANNER_LINEAR_MEMORY_PLANNER_H_
18
+
19
+ #include "tensorflow/lite/micro/compatibility.h"
20
+ #include "tensorflow/lite/micro/memory_planner/micro_memory_planner.h"
21
+
22
+ namespace tflite_micro {
23
+
24
+ // The simplest possible memory planner that just lays out all buffers at
25
+ // increasing offsets without trying to reuse memory.
26
+ class LinearMemoryPlanner : public MicroMemoryPlanner {
27
+ public:
28
+ LinearMemoryPlanner();
29
+ ~LinearMemoryPlanner() override;
30
+
31
+ TfLiteStatus AddBuffer(int size, int first_time_used,
32
+ int last_time_used) override;
33
+
34
+ size_t GetMaximumMemorySize() override;
35
+ int GetBufferCount() override;
36
+ TfLiteStatus GetOffsetForBuffer(int buffer_index, int* offset) override;
37
+
38
+ // Returns True because the LinearMemoryPlanner preserves all tensors after
39
+ // invocation.
40
+ bool preserves_all_tensors() const override { return true; }
41
+
42
+ private:
43
+ static constexpr int kMaxBufferCount = 1024;
44
+ size_t buffer_offsets_[kMaxBufferCount];
45
+ int current_buffer_count_;
46
+ size_t next_free_offset_;
47
+
48
+ TF_LITE_REMOVE_VIRTUAL_DELETE
49
+ };
50
+
51
+ } // namespace tflite_micro
52
+
53
+ #endif // TENSORFLOW_LITE_MICRO_MEMORY_PLANNER_LINEAR_MEMORY_PLANNER_H_
@@ -0,0 +1,73 @@
1
+ /* Copyright 2021 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_MEMORY_PLANNER_MEMORY_PLAN_STRUCT_H_
17
+ #define TENSORFLOW_LITE_MICRO_MEMORY_PLANNER_MEMORY_PLAN_STRUCT_H_
18
+
19
+ #include <stddef.h>
20
+ #include <stdint.h>
21
+
22
+ #include "tensorflow/lite/micro/micro_utils.h"
23
+
24
+ namespace tflite_micro {
25
+
26
+ // This is an experimental feature and subjected to change.
27
+ // More description is available at
28
+ // tensorflow/lite/micro/docs/offline_memory_plan.md.
29
+
30
+ // Describes a buffer's layout inside an arena. This struct should be kept as
31
+ // small as possible for memory footprint sensitive applications and should use
32
+ // only primitive fields, making it easy to adjust offline.
33
+ struct BufferDescriptor {
34
+ // Starting offset inside an arena for this buffer.
35
+ // Offset is the minimum information needed for the buffer. The user knows
36
+ // the model and the size of each buffer in order to lay out a valid buffer
37
+ // plan.
38
+ int32_t offset;
39
+ };
40
+
41
+ // A structure describing the lay out of buffers inside an arena.
42
+ struct BufferPlan {
43
+ // Number of buffers described in this plan.
44
+ int32_t buffer_count;
45
+
46
+ // Each element describes one buffer.
47
+ // Buffer index is implicit by the order of AddBuffer() call.
48
+ // Specifically, indices of activation tensors are 0 … N-1 where N is the
49
+ // number of activation tensors.
50
+ // The rest are based on the order of OP requests.
51
+ //
52
+ // This is a flexible array member and should ideally be
53
+ // arena_entries[]; However, in order to support a variety
54
+ // of compilers (and without needing to add ifdef's), we
55
+ // are implementing the flexible array member with an array of
56
+ // length 1 as the last member of the struct. When the size of a BufferPlan
57
+ // is needed, use the provided SizeOfBufferPlan(buffer_count) that
58
+ // accounts for this implemenatation caveat.
59
+ BufferDescriptor buffer_plan_entries[1];
60
+ };
61
+
62
+ // Returns size of a BufferPlan given a buffer count. This size is compile time
63
+ // known if buffer_count is a compile time constant.
64
+ constexpr size_t SizeOfBufferPlan(int32_t buffer_count) {
65
+ // Minus 1 because a BufferPlan struct have a BufferDescriptor already.
66
+ // Max to provide a lower bound for the corner case of buffer_count = 0.
67
+ return sizeof(BufferPlan) +
68
+ sizeof(BufferDescriptor) * Max(buffer_count - 1, 0);
69
+ }
70
+
71
+ } // namespace tflite_micro
72
+
73
+ #endif // TENSORFLOW_LITE_MICRO_MEMORY_PLANNER_MEMORY_PLAN_STRUCT_H_
@@ -0,0 +1,95 @@
1
+ /* Copyright 2019 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_MICRO_MEMORY_PLANNER_MEMORY_PLANNER_H_
17
+ #define TENSORFLOW_LITE_MICRO_MICRO_MEMORY_PLANNER_MEMORY_PLANNER_H_
18
+
19
+ #include "tensorflow/lite/c/common.h"
20
+
21
+ namespace tflite_micro {
22
+
23
+ // Interface class for planning the layout of memory buffers during the
24
+ // execution of a graph.
25
+ // It's designed to be used by a client that iterates in any order through the
26
+ // buffers it wants to lay out, and then calls the getter functions for
27
+ // information about the calculated layout. For example:
28
+ //
29
+ // SomeMemoryPlanner planner;
30
+ // planner.AddBuffer(100, 0, 1); // Buffer 0
31
+ // planner.AddBuffer(50, 2, 3); // Buffer 1
32
+ // planner.AddBuffer(50, 2, 3); // Buffer 2
33
+ //
34
+ // int offset0;
35
+ // TF_EXPECT_OK(planner.GetOffsetForBuffer(0, &offset0));
36
+ // int offset1;
37
+ // TF_EXPECT_OK(planner.GetOffsetForBuffer(1, &offset1));
38
+ // int offset2;
39
+ // TF_EXPECT_OK(planner.GetOffsetForBuffer(2, &offset2));
40
+ // const int arena_size_needed = planner.GetMaximumMemorySize();
41
+ //
42
+ // The goal is for applications to be able to experiment with different layout
43
+ // strategies without changing their client code, by swapping out classes that
44
+ // implement this interface.=
45
+ class MicroMemoryPlanner {
46
+ public:
47
+ MicroMemoryPlanner() {}
48
+ virtual ~MicroMemoryPlanner() {}
49
+
50
+ // Pass information about a buffer's size and lifetime to the layout
51
+ // algorithm. The order this is called implicitly assigns an index to the
52
+ // result, so the buffer information that's passed into the N-th call of
53
+ // this method will be used as the buffer_index argument to
54
+ // GetOffsetForBuffer().
55
+ virtual TfLiteStatus AddBuffer(int size, int first_time_used,
56
+ int last_time_used) = 0;
57
+
58
+ // Record details of an offline planned buffer offset we want to place.
59
+ // offline_offset is the buffer offset from the start of the arena.
60
+ // This is to support offline memory planning from the flatbuffer metadata.
61
+ // By default, it returns an error.
62
+ virtual TfLiteStatus AddBuffer(int size, int first_time_used,
63
+ int last_time_used, int offline_offset) {
64
+ return kTfLiteError;
65
+ }
66
+
67
+ // The largest contiguous block of memory that's needed to hold the layout.
68
+ virtual size_t GetMaximumMemorySize() = 0;
69
+ // How many buffers have been added to the planner.
70
+ virtual int GetBufferCount() = 0;
71
+ // Calculated layout offset for the N-th buffer added to the planner.
72
+ virtual TfLiteStatus GetOffsetForBuffer(int buffer_index, int* offset) = 0;
73
+
74
+ // Provides the scratch buffer in case that the memory planner needs it.
75
+ // The lifetime of scratch buffers lifetime lasts until the static memory plan
76
+ // is committed.
77
+ // The default implementation is for the memory planner that does not need
78
+ // scratch buffer and simply returns ok.
79
+ virtual TfLiteStatus Init(unsigned char* scratch_buffer,
80
+ int scratch_buffer_size) {
81
+ return kTfLiteOk;
82
+ }
83
+
84
+ // Method will return True if the MicroMemoryPlanner preserves all tensors
85
+ // after invocation, and False if it doesn't.
86
+ virtual bool preserves_all_tensors() const = 0;
87
+
88
+ virtual void PrintMemoryPlan() {
89
+ // Default does nothing.
90
+ }
91
+ };
92
+
93
+ } // namespace tflite_micro
94
+
95
+ #endif // TENSORFLOW_LITE_MICRO_MICRO_MEMORY_PLANNER_MEMORY_PLANNER_H_
@@ -0,0 +1,133 @@
1
+ /* Copyright 2021 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_MEMORY_PLANNER_NON_PERSISTENT_MEMORY_PLANNER_SHIM_H__
17
+ #define TENSORFLOW_LITE_MICRO_MEMORY_PLANNER_NON_PERSISTENT_MEMORY_PLANNER_SHIM_H__
18
+
19
+ #include "tensorflow/lite/micro/compatibility.h"
20
+ #include "tensorflow/lite/micro/memory_planner/memory_plan_struct.h"
21
+ #include "tensorflow/lite/micro/memory_planner/micro_memory_planner.h"
22
+
23
+ namespace tflite_micro {
24
+
25
+ /* This is an experimental feature and subjected to change.
26
+ *
27
+ The NonPersistentMemoryPlannerShim enables TFLM to work with an external tooling
28
+ that can plan the offset of each non persistent buffer for the Model within the
29
+ TFLM arena.
30
+
31
+ If the NonPersistentMemoryPlannerShim is used, then the final binary does not
32
+ have any of the symbols associated with the GreedyMemoryPlanner which results in
33
+ a reduced memory footprint.
34
+
35
+ Additionally, the offline planning of the non-persistent buffers can be used to
36
+ have a more efficient utilization compared to the GreedyMemoryPlanner.
37
+
38
+ For example, consider the following hypothetical model:
39
+
40
+ A1(400) A2(401)
41
+ ──┬─────────┐ ┌───────────
42
+ │ │ │
43
+ │ │ │
44
+ │ ▼ ▼
45
+ │ ┌────────┐
46
+ │ │ OP1 │
47
+ │ └───┬────┘ A4(201)
48
+ │ A3(10) │ │
49
+ │ │ │
50
+ │ │ │
51
+ │ ┌───┴────┐ │
52
+ │ │ OP2 │◄────────┤
53
+ │ └───┬────┘ │
54
+ │ A5(11) │ A6(202) │
55
+ │ │ │ │
56
+ │ ▼ │ │
57
+ │ ┌────────┐ │ │
58
+ │ │ OP3 │◄─┘ │
59
+ │ └───┬────┘ │
60
+ │ │ A8(200) │
61
+ │ A7(12) │ │ │
62
+ │ │ │ │
63
+ │ ┌───┴────┐◄──┘ │
64
+ └──────►│ OP4 │ │
65
+ └───┬────┘◄────────┘
66
+
67
+ A9(13) │
68
+
69
+
70
+ The GreedyMemoryPlanner will give the following memory layout that requires 1012
71
+ bytes of scratch arena size:
72
+
73
+ ┌─────────────────────────────────────────┬──────────────────────────┬────────┬───────┐
74
+ │ A2(401) │ A1(400) │ A4(201)│
75
+ A3(10)│
76
+ └─────────────────────────────────────────┴──────────────────────────┴────────┴───────┘
77
+
78
+ ┌───────────┬──────┬──────┐
79
+ │ A6(202) │A5(11)│A7(12)│
80
+ └───────────┴──────┴──────┘
81
+
82
+ ┌──────────┬───────┐
83
+ │ A8(200) │A9(13) │
84
+ └──────────┴───────┘
85
+
86
+ But a more efficient offline memory plan that requires only 826 bytes of scratch
87
+ arena size can be
88
+
89
+ ┌──────────────────────────────────────┬─────────────────────────────┬───────┬──────┐
90
+ │ A1(400) │ A2(401) │
91
+ A3(10)│A5(11)│
92
+ └──────────────────────────────────────┴─────────────────────────────┴───────┴──────┘
93
+
94
+ ┌────────────────┬────────────┬────────┬───────┐
95
+ │A4(201) │ A8(200) │A9(13)
96
+ │A7(12) │ └────────────────┴────────────┴────────┴───────┘
97
+
98
+ ┌─────────────┐
99
+ │ A6(202) │
100
+ └─────────────┘
101
+
102
+ */
103
+ class NonPersistentMemoryPlannerShim : public MicroMemoryPlanner {
104
+ public:
105
+ // Does not take ownership of buffer_plan, which must refer to a valid
106
+ // BufferPlan that outlives this object.
107
+ explicit NonPersistentMemoryPlannerShim(const BufferPlan* buffer_plan);
108
+ ~NonPersistentMemoryPlannerShim() override;
109
+
110
+ TfLiteStatus GetOffsetForBuffer(int buffer_request_index,
111
+ int* offset) override;
112
+
113
+ TfLiteStatus AddBuffer(int size, int first_time_used,
114
+ int last_time_used) override;
115
+ size_t GetMaximumMemorySize() override;
116
+ int GetBufferCount() override;
117
+
118
+ // Returns False because the NonPersistentMemoryPlannerShim doesn't preserves
119
+ // all tensors after invocation.
120
+ bool preserves_all_tensors() const override { return false; }
121
+
122
+ private:
123
+ const BufferPlan* buffer_plan_; // not owned, can't be null
124
+
125
+ // The number of buffers requested so far. Used for error checking.
126
+ int buffer_request_count_;
127
+
128
+ TF_LITE_REMOVE_VIRTUAL_DELETE
129
+ };
130
+
131
+ } // namespace tflite_micro
132
+
133
+ #endif // TENSORFLOW_LITE_MICRO_MEMORY_PLANNER_NON_PERSISTENT_MEMORY_PLANNER_SHIM_H__
@@ -0,0 +1,138 @@
1
+ /* Copyright 2022 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
+ #ifndef TENSORFLOW_LITE_MICRO_MICRO_ALLOCATION_INFO_H_
16
+ #define TENSORFLOW_LITE_MICRO_MICRO_ALLOCATION_INFO_H_
17
+
18
+ #include "tensorflow/lite/c/common.h"
19
+ #include "tensorflow/lite/micro/compatibility.h"
20
+ #include "tensorflow/lite/micro/flatbuffer_utils.h"
21
+ #include "tensorflow/lite/micro/micro_allocator.h"
22
+ #include "tensorflow/lite/schema/schema_generated.h"
23
+
24
+ namespace tflite_micro {
25
+
26
+ // Used to hold information used during allocation calculations.
27
+ struct AllocationInfo {
28
+ size_t bytes;
29
+ void** output_ptr;
30
+ int first_created;
31
+ int last_used;
32
+ int32_t offline_offset;
33
+ bool needs_allocating;
34
+ };
35
+
36
+ // Used to hold the allocation info list and related metadata for the entire
37
+ // graph (including subgraphs). Since all subgraphs are planned together, the
38
+ // allocation info list contains allocations for all subgraphs. Track the offset
39
+ // into this list for each subgraph then reserve space to track all allocations.
40
+ //
41
+ // The AllocationInfo list is a contiguous list of allocations across all
42
+ // subgraphs and scratch buffers. Each element here is marked as
43
+ // s<subgraph index>t<tensor index>. The following is a possible
44
+ // AllocationInfo list:
45
+ // [s0t0, s0t1, s1t0, s2t1, s1t2, s3t0, s3t1, scratch0, scratch1, scratch2]
46
+ //
47
+ // For this example, the subgraph offsets would be [0, 2, 5] and the scratch
48
+ // offset would be 7.
49
+ struct GraphAllocationInfo {
50
+ AllocationInfo* allocation_info;
51
+ size_t allocation_info_count;
52
+ size_t* subgraph_offsets;
53
+ size_t scratch_offset;
54
+ size_t tensor_count;
55
+ size_t scratch_buffer_count;
56
+ };
57
+
58
+ // A helper class to construct AllocationInfo array. This array contains the
59
+ // lifetime of tensors / scratch_buffer and will be used to calculate the memory
60
+ // plan. Methods need to be called in order from `Create`, Init`, `Add*`, to
61
+ // `Finish`.
62
+ class AllocationInfoBuilder {
63
+ public:
64
+ AllocationInfoBuilder(const Model* model,
65
+ INonPersistentBufferAllocator* non_persistent_allocator)
66
+ : model_(model), non_persistent_allocator_(non_persistent_allocator) {}
67
+
68
+ // Check if model contains offline planned buffer offsets.
69
+ // - If there's no metadata available, offline_planner_offsets is not set
70
+ // - If there's metadata available, offline_planner_offsets will point to the
71
+ // first offset in the metadata buffer list.
72
+ TfLiteStatus GetOfflinePlannedOffsets(
73
+ const int32_t** offline_planner_offsets);
74
+
75
+ // Allocate memory for the allocation info array as well as offsets into that
76
+ // array for each subgraph.
77
+ TfLiteStatus CreateAllocationInfo(int scratch_buffer_request_count);
78
+
79
+ // Release memory used for the allocation info array.
80
+ TfLiteStatus FreeAllocationInfo();
81
+
82
+ // Initialize AllocationInfo for all tensors and scratch buffers in the graph.
83
+ TfLiteStatus InitializeAllocationInfo(const int32_t* offline_offsets,
84
+ SubgraphAllocations* allocations);
85
+
86
+ // Mark the scope of each tensor and scratch buffer across the graph. Enter
87
+ // all possible subgraphs invoked by each control flow operator. This method
88
+ // marks the maximum lifetime of each buffer so that tensors are correctly
89
+ // planned for all valid invocation flows.
90
+ TfLiteStatus MarkAllocationLifetimes(
91
+ int subgraph_idx, internal::ScratchBufferRequest* scratch_buffer_request,
92
+ ScratchBufferHandle* scratch_buffer_handles,
93
+ SubgraphAllocations* allocations);
94
+
95
+ // Identify control flow operators and recursively mark all subgraphs which
96
+ // that operator can invoke. The lifetime of all tensors within a subgraph
97
+ // can only be extended. The order of subgraph invocation does not matter
98
+ // since subgraphs within the same control flow operator are executed
99
+ // within their own allocation scope (planned buffers in a subgraph cannot
100
+ // persist beyond the end of that subgraph's invocation).
101
+ TfLiteStatus MarkSubgraphLifetimesIfNecessary(
102
+ const Operator* op,
103
+ internal::ScratchBufferRequest* scratch_buffer_requests,
104
+ ScratchBufferHandle* scratch_buffer_handles,
105
+ SubgraphAllocations* allocations);
106
+
107
+ // Returns the number of allocations.
108
+ int AllocationCount() const { return info_.allocation_info_count; }
109
+
110
+ // Returns a pointer to the built AllocationInfo array.
111
+ AllocationInfo* Finish() const { return info_.allocation_info; }
112
+
113
+ private:
114
+ // Mark the given Allocation info as first created at the specified allocation
115
+ // scope count. Only the first creation must be recorded since the allocation
116
+ // scope count monotonically increases throughout the lifetime marking
117
+ // process.
118
+ void UpdateFirstCreated(AllocationInfo* current, int allocation_scope_count);
119
+
120
+ // Mark the given AllocationInfo as last used at the specified allocation
121
+ // scope
122
+ // count. Update the last used marker every time, since the allocation scope
123
+ // count monotonically increases through the lifetime marking process.
124
+ void UpdateLastUsed(AllocationInfo* current, int allocation_scope_count);
125
+
126
+ // Validate if a subgraph satisfies assumptions.
127
+ TfLiteStatus ValidateSubgraph(const SubGraph* subgraph,
128
+ TfLiteEvalTensor* eval_tensors);
129
+
130
+ const tflite_micro::Model* model_ = nullptr;
131
+ INonPersistentBufferAllocator* non_persistent_allocator_ = nullptr;
132
+ GraphAllocationInfo info_;
133
+ int allocation_scope_count_ = 0;
134
+ };
135
+
136
+ } // namespace tflite_micro
137
+
138
+ #endif // TENSORFLOW_LITE_MICRO_MICRO_ALLOCATION_INFO_H_