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,1496 @@
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
+ // This file defines common C types and APIs for implementing operations,
17
+ // delegates and other constructs in TensorFlow Lite. The actual operations and
18
+ // delegates can be defined using C++, but the interface between the interpreter
19
+ // and the operations are C.
20
+ //
21
+ // Summary of abstractions
22
+ // TF_LITE_ENSURE - Self-sufficient error checking
23
+ // TfLiteStatus - Status reporting
24
+ // TfLiteIntArray - stores tensor shapes (dims),
25
+ // TfLiteContext - allows an op to access the tensors
26
+ // TfLiteTensor - tensor (a multidimensional array)
27
+ // TfLiteNode - a single node or operation
28
+ // TfLiteRegistration - the implementation of a conceptual operation.
29
+ // TfLiteDelegate - allows delegation of nodes to alternative backends.
30
+ //
31
+ // Some abstractions in this file are created and managed by Interpreter.
32
+ //
33
+ // NOTE: The order of values in these structs are "semi-ABI stable". New values
34
+ // should be added only to the end of structs and never reordered.
35
+
36
+ /// WARNING: Users of TensorFlow Lite should not include this file directly,
37
+ /// but should instead include
38
+ /// "third_party/tensorflow/lite/c/common.h".
39
+ /// Only the TensorFlow Lite implementation itself should include this
40
+ /// file directly.
41
+ // IWYU pragma: private, include "third_party/tensorflow/lite/c/common.h"
42
+
43
+ #ifndef TENSORFLOW_LITE_CORE_C_COMMON_H_
44
+ #define TENSORFLOW_LITE_CORE_C_COMMON_H_
45
+
46
+ #include <stdarg.h>
47
+ #include <stdbool.h>
48
+ #include <stddef.h>
49
+ #include <stdint.h>
50
+
51
+ #include "tensorflow/lite/core/c/c_api_types.h" // IWYU pragma: export
52
+
53
+ #ifdef __cplusplus
54
+ extern "C" {
55
+ #endif // __cplusplus
56
+
57
+ // The list of external context types known to TF Lite. This list exists solely
58
+ // to avoid conflicts and to ensure ops can share the external contexts they
59
+ // need. Access to the external contexts is controlled by one of the
60
+ // corresponding support files.
61
+ typedef enum TfLiteExternalContextType {
62
+ kTfLiteEigenContext = 0, // include eigen_support.h to use.
63
+ kTfLiteGemmLowpContext = 1, // include gemm_support.h to use.
64
+ kTfLiteEdgeTpuContext = 2, // Placeholder for Edge TPU support.
65
+ kTfLiteCpuBackendContext = 3, // include cpu_backend_context.h to use.
66
+ kTfLiteMaxExternalContexts = 4
67
+ } TfLiteExternalContextType;
68
+
69
+ // Forward declare so dependent structs and methods can reference these types
70
+ // prior to the struct definitions.
71
+ struct TfLiteContext;
72
+ struct TfLiteDelegate;
73
+ struct TfLiteRegistration;
74
+ struct TfLiteOpaqueDelegateBuilder;
75
+
76
+ // An external context is a collection of information unrelated to the TF Lite
77
+ // framework, but useful to a subset of the ops. TF Lite knows very little
78
+ // about the actual contexts, but it keeps a list of them, and is able to
79
+ // refresh them if configurations like the number of recommended threads
80
+ // change.
81
+ typedef struct TfLiteExternalContext {
82
+ TfLiteExternalContextType type;
83
+ TfLiteStatus (*Refresh)(struct TfLiteContext* context);
84
+ } TfLiteExternalContext;
85
+
86
+ #define kTfLiteOptionalTensor (-1)
87
+
88
+ // Fixed size list of integers. Used for dimensions and inputs/outputs tensor
89
+ // indices
90
+ typedef struct TfLiteIntArray {
91
+ int size;
92
+
93
+ #if defined(_MSC_VER)
94
+ // Context for why this is needed is in http://b/189926408#comment21
95
+ int data[1];
96
+ #elif (!defined(__clang__) && defined(__GNUC__) && __GNUC__ == 6 && \
97
+ __GNUC_MINOR__ >= 1) || \
98
+ defined(HEXAGON) || \
99
+ (defined(__clang__) && __clang_major__ == 7 && __clang_minor__ == 1)
100
+ // gcc 6.1+ have a bug where flexible members aren't properly handled
101
+ // https://github.com/google/re2/commit/b94b7cd42e9f02673cd748c1ac1d16db4052514c
102
+ int data[0];
103
+ #else
104
+ int data[];
105
+ #endif
106
+ } TfLiteIntArray;
107
+
108
+ // Given the size (number of elements) in a TfLiteIntArray, calculate its size
109
+ // in bytes.
110
+ size_t TfLiteMicroIntArrayGetSizeInBytes(int size);
111
+
112
+ #ifndef TF_LITE_STATIC_MEMORY
113
+ // Create a array of a given `size` (uninitialized entries).
114
+ // This returns a pointer, that you must free using TfLiteIntArrayFree().
115
+ TfLiteIntArray* TfLiteMicroIntArrayCreate(int size);
116
+ #endif
117
+
118
+ // Check if two intarrays are equal. Returns 1 if they are equal, 0 otherwise.
119
+ int TfLiteMicroIntArrayEqual(const TfLiteIntArray* a, const TfLiteIntArray* b);
120
+
121
+ // Check if an intarray equals an array. Returns 1 if equals, 0 otherwise.
122
+ int TfLiteMicroIntArrayEqualsArray(const TfLiteIntArray* a, int b_size,
123
+ const int b_data[]);
124
+
125
+ #ifndef TF_LITE_STATIC_MEMORY
126
+ // Create a copy of an array passed as `src`.
127
+ // You are expected to free memory with TfLiteIntArrayFree
128
+ TfLiteIntArray* TfLiteMicroIntArrayCopy(const TfLiteIntArray* src);
129
+
130
+ // Free memory of array `a`.
131
+ void TfLiteMicroIntArrayFree(TfLiteIntArray* a);
132
+ #endif // TF_LITE_STATIC_MEMORY
133
+
134
+ // Fixed size list of floats. Used for per-channel quantization.
135
+ typedef struct TfLiteFloatArray {
136
+ int size;
137
+ #if defined(_MSC_VER)
138
+ // Context for why this is needed is in http://b/189926408#comment21
139
+ float data[1];
140
+ #elif (!defined(__clang__) && defined(__GNUC__) && __GNUC__ == 6 && \
141
+ __GNUC_MINOR__ >= 1) || \
142
+ defined(HEXAGON) || \
143
+ (defined(__clang__) && __clang_major__ == 7 && __clang_minor__ == 1)
144
+ // gcc 6.1+ have a bug where flexible members aren't properly handled
145
+ // https://github.com/google/re2/commit/b94b7cd42e9f02673cd748c1ac1d16db4052514c
146
+ float data[0];
147
+ #else
148
+ float data[];
149
+ #endif
150
+ } TfLiteFloatArray;
151
+
152
+ // Given the size (number of elements) in a TfLiteFloatArray, calculate its size
153
+ // in bytes.
154
+ int TfLiteFloatArrayGetSizeInBytes(int size);
155
+
156
+ #ifndef TF_LITE_STATIC_MEMORY
157
+ // Create a array of a given `size` (uninitialized entries).
158
+ // This returns a pointer, that you must free using TfLiteFloatArrayFree().
159
+ TfLiteFloatArray* TfLiteMicroFloatArrayCreate(int size);
160
+
161
+ // Create a copy of an array passed as `src`.
162
+ // You are expected to free memory with TfLiteFloatArrayFree.
163
+ TfLiteFloatArray* TfLiteMicroFloatArrayCopy(const TfLiteFloatArray* src);
164
+
165
+ // Free memory of array `a`.
166
+ void TfLiteMicroFloatArrayFree(TfLiteFloatArray* a);
167
+ #endif // TF_LITE_STATIC_MEMORY
168
+
169
+ // Since we must not depend on any libraries, define a minimal subset of
170
+ // error macros while avoiding names that have pre-conceived meanings like
171
+ // assert and check.
172
+
173
+ // Try to make all reporting calls through TF_LITE_KERNEL_LOG rather than
174
+ // calling the context->ReportError function directly, so that message strings
175
+ // can be stripped out if the binary size needs to be severely optimized.
176
+ #ifndef TF_LITE_STRIP_ERROR_STRINGS
177
+ #define TF_LITE_KERNEL_LOG(context, ...) \
178
+ do { \
179
+ (context)->ReportError((context), __VA_ARGS__); \
180
+ } while (false)
181
+
182
+ #define TF_LITE_MAYBE_KERNEL_LOG(context, ...) \
183
+ do { \
184
+ if ((context) != nullptr) { \
185
+ (context)->ReportError((context), __VA_ARGS__); \
186
+ } \
187
+ } while (false)
188
+ #else // TF_LITE_STRIP_ERROR_STRINGS
189
+ #define ARGS_UNUSED(...) (void)sizeof(#__VA_ARGS__)
190
+ #define TF_LITE_KERNEL_LOG(context, ...) ARGS_UNUSED(__VA_ARGS__)
191
+ #define TF_LITE_MAYBE_KERNEL_LOG(context, ...) ARGS_UNUSED(__VA_ARGS__)
192
+ #endif // TF_LITE_STRIP_ERROR_STRINGS
193
+
194
+ // Check whether value is true, and if not return kTfLiteError from
195
+ // the current function (and report the error string msg).
196
+ #define TF_LITE_ENSURE_MSG(context, value, msg) \
197
+ do { \
198
+ if (!(value)) { \
199
+ TF_LITE_KERNEL_LOG((context), __FILE__ " " msg); \
200
+ return kTfLiteError; \
201
+ } \
202
+ } while (0)
203
+
204
+ // Check whether the value `a` is true, and if not return kTfLiteError from
205
+ // the current function, while also reporting the location of the error.
206
+ #define TF_LITE_ENSURE(context, a) \
207
+ do { \
208
+ if (!(a)) { \
209
+ TF_LITE_KERNEL_LOG((context), "%s:%d %s was not true.", __FILE__, \
210
+ __LINE__, #a); \
211
+ return kTfLiteError; \
212
+ } \
213
+ } while (0)
214
+
215
+ #define TF_LITE_ENSURE_STATUS(a) \
216
+ do { \
217
+ const TfLiteStatus s = (a); \
218
+ if (s != kTfLiteOk) { \
219
+ return s; \
220
+ } \
221
+ } while (0)
222
+
223
+ // Check whether the value `a == b` is true, and if not return kTfLiteError from
224
+ // the current function, while also reporting the location of the error.
225
+ // `a` and `b` may be evaluated more than once, so no side effects or
226
+ // extremely expensive computations should be done.
227
+ // NOTE: Use TF_LITE_ENSURE_TYPES_EQ if comparing TfLiteTypes.
228
+ #define TF_LITE_ENSURE_EQ(context, a, b) \
229
+ do { \
230
+ if ((a) != (b)) { \
231
+ TF_LITE_KERNEL_LOG((context), "%s:%d %s != %s (%d != %d)", __FILE__, \
232
+ __LINE__, #a, #b, (a), (b)); \
233
+ return kTfLiteError; \
234
+ } \
235
+ } while (0)
236
+
237
+ #define TF_LITE_ENSURE_TYPES_EQ(context, a, b) \
238
+ do { \
239
+ if ((a) != (b)) { \
240
+ TF_LITE_KERNEL_LOG((context), "%s:%d %s != %s (%s != %s)", __FILE__, \
241
+ __LINE__, #a, #b, TfLiteMicroTypeGetName(a), \
242
+ TfLiteMicroTypeGetName(b)); \
243
+ return kTfLiteError; \
244
+ } \
245
+ } while (0)
246
+
247
+ #define TF_LITE_ENSURE_NEAR(context, a, b, epsilon) \
248
+ do { \
249
+ auto delta = ((a) > (b)) ? ((a) - (b)) : ((b) - (a)); \
250
+ if (delta > epsilon) { \
251
+ TF_LITE_KERNEL_LOG((context), "%s:%d %s not near %s (%f != %f)", \
252
+ __FILE__, __LINE__, #a, #b, static_cast<double>(a), \
253
+ static_cast<double>(b)); \
254
+ return kTfLiteError; \
255
+ } \
256
+ } while (0)
257
+
258
+ #define TF_LITE_ENSURE_OK(context, status) \
259
+ do { \
260
+ const TfLiteStatus s = (status); \
261
+ if ((s) != kTfLiteOk) { \
262
+ return s; \
263
+ } \
264
+ } while (0)
265
+
266
+ // Single-precision complex data type compatible with the C99 definition.
267
+ typedef struct TfLiteComplex64 {
268
+ float re, im; // real and imaginary parts, respectively.
269
+ } TfLiteComplex64;
270
+
271
+ // Double-precision complex data type compatible with the C99 definition.
272
+ typedef struct TfLiteComplex128 {
273
+ double re, im; // real and imaginary parts, respectively.
274
+ } TfLiteComplex128;
275
+
276
+ // Half precision data type compatible with the C99 definition.
277
+ typedef struct TfLiteFloat16 {
278
+ uint16_t data;
279
+ } TfLiteFloat16;
280
+
281
+ // Return the name of a given type, for error reporting purposes.
282
+ const char* TfLiteMicroTypeGetName(TfLiteType type);
283
+
284
+ // SupportedQuantizationTypes.
285
+ typedef enum TfLiteQuantizationType {
286
+ // No quantization.
287
+ kTfLiteNoQuantization = 0,
288
+ // Affine quantization (with support for per-channel quantization).
289
+ // Corresponds to TfLiteAffineQuantization.
290
+ kTfLiteAffineQuantization = 1,
291
+ } TfLiteQuantizationType;
292
+
293
+ // Structure specifying the quantization used by the tensor, if-any.
294
+ typedef struct TfLiteQuantization {
295
+ // The type of quantization held by params.
296
+ TfLiteQuantizationType type;
297
+ // Holds an optional reference to a quantization param structure. The actual
298
+ // type depends on the value of the `type` field (see the comment there for
299
+ // the values and corresponding types).
300
+ void* params;
301
+ } TfLiteQuantization;
302
+
303
+ // Parameters for asymmetric quantization across a dimension (i.e per output
304
+ // channel quantization).
305
+ // quantized_dimension specifies which dimension the scales and zero_points
306
+ // correspond to.
307
+ // For a particular value in quantized_dimension, quantized values can be
308
+ // converted back to float using:
309
+ // real_value = scale * (quantized_value - zero_point)
310
+ typedef struct TfLiteAffineQuantization {
311
+ TfLiteFloatArray* scale;
312
+ TfLiteIntArray* zero_point;
313
+ int32_t quantized_dimension;
314
+ } TfLiteAffineQuantization;
315
+
316
+ /* A union of pointers that points to memory for a given tensor. */
317
+ typedef union TfLitePtrUnion {
318
+ /* Do not access these members directly, if possible, use
319
+ * GetTensorData<TYPE>(tensor) instead, otherwise only access .data, as other
320
+ * members are deprecated. */
321
+ int32_t* i32;
322
+ uint32_t* u32;
323
+ int64_t* i64;
324
+ uint64_t* u64;
325
+ float* f;
326
+ TfLiteFloat16* f16;
327
+ double* f64;
328
+ char* raw;
329
+ const char* raw_const;
330
+ uint8_t* uint8;
331
+ bool* b;
332
+ int16_t* i16;
333
+ uint16_t* ui16;
334
+ TfLiteComplex64* c64;
335
+ TfLiteComplex128* c128;
336
+ int8_t* int8;
337
+ /* Only use this member. */
338
+ void* data;
339
+ } TfLitePtrUnion;
340
+
341
+ // Memory allocation strategies.
342
+ // * kTfLiteMmapRo: Read-only memory-mapped data, or data externally allocated.
343
+ // * kTfLiteArenaRw: Arena allocated with no guarantees about persistence,
344
+ // and available during eval.
345
+ // * kTfLiteArenaRwPersistent: Arena allocated but persistent across eval, and
346
+ // only available during eval.
347
+ // * kTfLiteDynamic: Allocated during eval, or for string tensors.
348
+ // * kTfLitePersistentRo: Allocated and populated during prepare. This is
349
+ // useful for tensors that can be computed during prepare and treated
350
+ // as constant inputs for downstream ops (also in prepare).
351
+ // * kTfLiteCustom: Custom memory allocation provided by the user. See
352
+ // TfLiteCustomAllocation below.
353
+ // * kTfLiteVariantObject: Allocation is an arbitrary type-erased C++ object.
354
+ // Allocation and deallocation are done through `new` and `delete`.
355
+ typedef enum TfLiteAllocationType {
356
+ kTfLiteMemNone = 0,
357
+ kTfLiteMmapRo,
358
+ kTfLiteArenaRw,
359
+ kTfLiteArenaRwPersistent,
360
+ kTfLiteDynamic,
361
+ kTfLitePersistentRo,
362
+ kTfLiteCustom,
363
+ kTfLiteVariantObject,
364
+ } TfLiteAllocationType;
365
+
366
+ // Memory allocation strategies.
367
+ //
368
+ // TfLiteAllocationType values have been overloaded to mean more than their
369
+ // original intent. This enum should only be used to document the allocation
370
+ // strategy used by a tensor for it data.
371
+ typedef enum TfLiteAllocationStrategy {
372
+ kTfLiteAllocationStrategyUnknown,
373
+ kTfLiteAllocationStrategyNone, // No data is allocated.
374
+ kTfLiteAllocationStrategyMMap, // Data is mmaped.
375
+ kTfLiteAllocationStrategyArena, // Handled by the arena.
376
+ kTfLiteAllocationStrategyMalloc, // Uses `malloc`/`free`.
377
+ kTfLiteAllocationStrategyNew // Uses `new[]`/`delete[]`.
378
+ } TfLiteAllocationStrategy;
379
+
380
+ // Describes how stable a tensor attribute is with regards to an interpreter
381
+ // runs.
382
+ typedef enum TfLiteRunStability {
383
+ kTfLiteRunStabilityUnknown,
384
+ kTfLiteRunStabilityUnstable, // May change at any time.
385
+ kTfLiteRunStabilitySingleRun, // Will stay the same for one run.
386
+ kTfLiteRunStabilityAcrossRuns // Will stay the same across all runs.
387
+ } TfLiteRunStability;
388
+
389
+ // Describes the steps of a TFLite operation life cycle.
390
+ typedef enum TfLiteRunStep {
391
+ kTfLiteRunStepUnknown,
392
+ kTfLiteRunStepInit,
393
+ kTfLiteRunStepPrepare,
394
+ kTfLiteRunStepEval
395
+ } TfLiteRunStep;
396
+
397
+ // The delegates should use zero or positive integers to represent handles.
398
+ // -1 is reserved from unallocated status.
399
+ typedef int TfLiteBufferHandle;
400
+ enum {
401
+ kTfLiteNullBufferHandle = -1,
402
+ };
403
+
404
+ // Storage format of each dimension in a sparse tensor.
405
+ typedef enum TfLiteDimensionType {
406
+ kTfLiteDimDense = 0,
407
+ kTfLiteDimSparseCSR,
408
+ } TfLiteDimensionType;
409
+
410
+ // Metadata to encode each dimension in a sparse tensor.
411
+ typedef struct TfLiteDimensionMetadata {
412
+ TfLiteDimensionType format;
413
+ int dense_size;
414
+ TfLiteIntArray* array_segments;
415
+ TfLiteIntArray* array_indices;
416
+ } TfLiteDimensionMetadata;
417
+
418
+ // Parameters used to encode a sparse tensor. For detailed explanation of each
419
+ // field please refer to lite/schema/schema.fbs.
420
+ typedef struct TfLiteSparsity {
421
+ TfLiteIntArray* traversal_order;
422
+ TfLiteIntArray* block_map;
423
+ TfLiteDimensionMetadata* dim_metadata;
424
+ int dim_metadata_size;
425
+ } TfLiteSparsity;
426
+
427
+ // Defines a custom memory allocation not owned by the runtime.
428
+ // `data` should be aligned to kDefaultTensorAlignment defined in
429
+ // lite/util.h. (Currently 64 bytes)
430
+ // NOTE: See Interpreter.SetCustomAllocationForTensor for details on usage.
431
+ typedef struct TfLiteCustomAllocation {
432
+ void* data;
433
+ size_t bytes;
434
+ } TfLiteCustomAllocation;
435
+
436
+ // The flags used in `Interpreter::SetCustomAllocationForTensor`.
437
+ // Note that this is a bitmask, so the values should be 1, 2, 4, 8, ...etc.
438
+ typedef enum TfLiteCustomAllocationFlags {
439
+ kTfLiteCustomAllocationFlagsNone = 0,
440
+ // Skips checking whether allocation.data points to an aligned buffer as
441
+ // expected by the TFLite runtime.
442
+ // NOTE: Setting this flag can cause crashes when calling Invoke().
443
+ // Use with caution.
444
+ kTfLiteCustomAllocationFlagsSkipAlignCheck = 1,
445
+ } TfLiteCustomAllocationFlags;
446
+
447
+ // A tensor in the interpreter system which is a wrapper around a buffer of
448
+ // data including a dimensionality (or NULL if not currently defined).
449
+ #ifndef TF_LITE_STATIC_MEMORY
450
+ typedef struct TfLiteTensor {
451
+ // The data type specification for data stored in `data`. This affects
452
+ // what member of `data` union should be used.
453
+ TfLiteType type;
454
+ // A union of data pointers. The appropriate type should be used for a typed
455
+ // tensor based on `type`.
456
+ TfLitePtrUnion data;
457
+ // A pointer to a structure representing the dimensionality interpretation
458
+ // that the buffer should have. NOTE: the product of elements of `dims`
459
+ // and the element datatype size should be equal to `bytes` below.
460
+ TfLiteIntArray* dims;
461
+ // Quantization information.
462
+ TfLiteQuantizationParams params;
463
+ // How memory is mapped
464
+ // kTfLiteMmapRo: Memory mapped read only.
465
+ // i.e. weights
466
+ // kTfLiteArenaRw: Arena allocated read write memory
467
+ // (i.e. temporaries, outputs).
468
+ TfLiteAllocationType allocation_type;
469
+ // The number of bytes required to store the data of this Tensor. I.e.
470
+ // (bytes of each element) * dims[0] * ... * dims[n-1]. For example, if
471
+ // type is kTfLiteFloat32 and dims = {3, 2} then
472
+ // bytes = sizeof(float) * 3 * 2 = 4 * 3 * 2 = 24.
473
+ size_t bytes;
474
+
475
+ // An opaque pointer to a tflite_micro::MMapAllocation
476
+ const void* allocation;
477
+
478
+ // Null-terminated name of this tensor.
479
+ const char* name;
480
+
481
+ // The delegate which knows how to handle `buffer_handle`.
482
+ // WARNING: This is an experimental interface that is subject to change.
483
+ struct TfLiteDelegate* delegate;
484
+
485
+ // An integer buffer handle that can be handled by `delegate`.
486
+ // The value is valid only when delegate is not null.
487
+ // WARNING: This is an experimental interface that is subject to change.
488
+ TfLiteBufferHandle buffer_handle;
489
+
490
+ // If the delegate uses its own buffer (e.g. GPU memory), the delegate is
491
+ // responsible to set data_is_stale to true.
492
+ // `delegate->CopyFromBufferHandle` can be called to copy the data from
493
+ // delegate buffer.
494
+ // WARNING: This is an // experimental interface that is subject to change.
495
+ bool data_is_stale;
496
+
497
+ // True if the tensor is a variable.
498
+ bool is_variable;
499
+
500
+ // Quantization information. Replaces params field above.
501
+ TfLiteQuantization quantization;
502
+
503
+ // Parameters used to encode a sparse tensor.
504
+ // This is optional. The field is NULL if a tensor is dense.
505
+ // WARNING: This is an experimental interface that is subject to change.
506
+ TfLiteSparsity* sparsity;
507
+
508
+ // Optional. Encodes shapes with unknown dimensions with -1. This field is
509
+ // only populated when unknown dimensions exist in a read-write tensor (i.e.
510
+ // an input or output tensor). (e.g. `dims` contains [1, 1, 1, 3] and
511
+ // `dims_signature` contains [1, -1, -1, 3]). If no unknown dimensions exist
512
+ // then `dims_signature` is either null, or set to an empty array. Note that
513
+ // this field only exists when TF_LITE_STATIC_MEMORY is not defined.
514
+ const TfLiteIntArray* dims_signature;
515
+ } TfLiteTensor;
516
+
517
+ // A structure representing an instance of a node.
518
+ // This structure only exhibits the inputs, outputs, user defined data and some
519
+ // node properties (like statefulness), not other features like the type.
520
+ typedef struct TfLiteNode {
521
+ // Inputs to this node expressed as indices into the simulator's tensors.
522
+ TfLiteIntArray* inputs;
523
+
524
+ // Outputs to this node expressed as indices into the simulator's tensors.
525
+ TfLiteIntArray* outputs;
526
+
527
+ // intermediate tensors to this node expressed as indices into the simulator's
528
+ // tensors.
529
+ TfLiteIntArray* intermediates;
530
+
531
+ // Temporary tensors uses during the computations. This usually contains no
532
+ // tensors, but ops are allowed to change that if they need scratch space of
533
+ // any sort.
534
+ TfLiteIntArray* temporaries;
535
+
536
+ // Opaque data provided by the node implementer through `Registration.init`.
537
+ void* user_data;
538
+
539
+ // Opaque data provided to the node if the node is a builtin. This is usually
540
+ // a structure defined in builtin_op_data.h
541
+ void* builtin_data;
542
+
543
+ // Custom initial data. This is the opaque data provided in the flatbuffer.
544
+ // WARNING: This is an experimental interface that is subject to change.
545
+ const void* custom_initial_data;
546
+ int custom_initial_data_size;
547
+
548
+ // The pointer to the delegate. This is non-null only when the node is
549
+ // created by calling `interpreter.ModifyGraphWithDelegate`.
550
+ // WARNING: This is an experimental interface that is subject to change.
551
+ struct TfLiteDelegate* delegate;
552
+
553
+ // Whether this op might have side effect (e.g. stateful op).
554
+ bool might_have_side_effect;
555
+ } TfLiteNode;
556
+ #else // defined(TF_LITE_STATIC_MEMORY)?
557
+ // NOTE: This flag is opt-in only at compile time.
558
+ //
559
+ // Specific reduced TfLiteTensor struct for TF Micro runtime. This struct
560
+ // contains only the minimum fields required to initialize and prepare a micro
561
+ // inference graph. The fields in this struct have been ordered from
562
+ // largest-to-smallest for optimal struct sizeof.
563
+ //
564
+ // This struct does not use:
565
+ // - allocation
566
+ // - buffer_handle
567
+ // - data_is_stale
568
+ // - delegate
569
+ // - dims_signature
570
+ // - name
571
+ // - sparsity
572
+ typedef struct TfLiteTensor {
573
+ // A union of data pointers. The appropriate type should be used for a typed
574
+ // tensor based on `type`.
575
+ TfLitePtrUnion data;
576
+
577
+ // A pointer to a structure representing the dimensionality interpretation
578
+ // that the buffer should have. NOTE: the product of elements of `dims`
579
+ // and the element datatype size should be equal to `bytes` below.
580
+ TfLiteIntArray* dims;
581
+
582
+ // The data type specification for data stored in `data`. This affects
583
+ // what member of `data` union should be used.
584
+ TfLiteType type;
585
+
586
+ // TODO(b/155784997): Consider consolidating these quantization fields:
587
+ // Quantization information. Replaces params field above.
588
+ TfLiteQuantization quantization;
589
+
590
+ // Quantization information.
591
+ TfLiteQuantizationParams params;
592
+
593
+ // The number of bytes required to store the data of this Tensor. I.e.
594
+ // (bytes of each element) * dims[0] * ... * dims[n-1]. For example, if
595
+ // type is kTfLiteFloat32 and dims = {3, 2} then
596
+ // bytes = sizeof(float) * 3 * 2 = 4 * 3 * 2 = 24.
597
+ size_t bytes;
598
+
599
+ // How memory is mapped
600
+ // kTfLiteMmapRo: Memory mapped read only.
601
+ // i.e. weights
602
+ // kTfLiteArenaRw: Arena allocated read write memory
603
+ // (i.e. temporaries, outputs).
604
+ TfLiteAllocationType allocation_type;
605
+
606
+ // True if the tensor is a variable.
607
+ bool is_variable;
608
+ } TfLiteTensor;
609
+
610
+ // Specific reduced TfLiteNode struct for TF Micro runtime. This struct contains
611
+ // only the minimum fields required to represent a node.
612
+ //
613
+ // This struct does not use:
614
+ // - delegate
615
+ // - intermediates
616
+ // - temporaries
617
+ typedef struct TfLiteNode {
618
+ // Inputs to this node expressed as indices into the simulator's tensors.
619
+ TfLiteIntArray* inputs;
620
+
621
+ // Outputs to this node expressed as indices into the simulator's tensors.
622
+ TfLiteIntArray* outputs;
623
+
624
+ // Opaque data provided by the node implementer through `Registration.init`.
625
+ void* user_data;
626
+
627
+ // Opaque data provided to the node if the node is a builtin. This is usually
628
+ // a structure defined in builtin_op_data.h
629
+ void* builtin_data;
630
+
631
+ // Custom initial data. This is the opaque data provided in the flatbuffer.
632
+ // WARNING: This is an experimental interface that is subject to change.
633
+ int custom_initial_data_size;
634
+ } TfLiteNode;
635
+ #endif // TF_LITE_STATIC_MEMORY
636
+
637
+ // Light-weight tensor struct for TF Micro runtime. Provides the minimal amount
638
+ // of information required for a kernel to run during TfLiteRegistration::Eval.
639
+ // TODO(b/160955687): Move this field into TF_LITE_STATIC_MEMORY when TFLM
640
+ // builds with this flag by default internally.
641
+ typedef struct TfLiteEvalTensor {
642
+ // A union of data pointers. The appropriate type should be used for a typed
643
+ // tensor based on `type`.
644
+ TfLitePtrUnion data;
645
+
646
+ // A pointer to a structure representing the dimensionality interpretation
647
+ // that the buffer should have.
648
+ TfLiteIntArray* dims;
649
+
650
+ // The data type specification for data stored in `data`. This affects
651
+ // what member of `data` union should be used.
652
+ TfLiteType type;
653
+ } TfLiteEvalTensor;
654
+
655
+ #ifndef TF_LITE_STATIC_MEMORY
656
+ // Free data memory of tensor `t`.
657
+ void TfLiteTensorDataFree(TfLiteTensor* t);
658
+
659
+ // Free quantization data.
660
+ void TfLiteMicroQuantizationFree(TfLiteQuantization* quantization);
661
+
662
+ // Free sparsity parameters.
663
+ void TfLiteMicroSparsityFree(TfLiteSparsity* sparsity);
664
+
665
+ // Free memory of tensor `t`.
666
+ void TfLiteTensorFree(TfLiteTensor* t);
667
+
668
+ // Set all of a tensor's fields (and free any previously allocated data).
669
+ void TfLiteTensorReset(TfLiteType type, const char* name, TfLiteIntArray* dims,
670
+ TfLiteQuantizationParams quantization, char* buffer,
671
+ size_t size, TfLiteAllocationType allocation_type,
672
+ const void* allocation, bool is_variable,
673
+ TfLiteTensor* tensor);
674
+
675
+ // Copies the contents of 'src' in 'dst'.
676
+ // Function does nothing if either 'src' or 'dst' is passed as nullptr and
677
+ // return kTfLiteOk.
678
+ // Returns kTfLiteError if 'src' and 'dst' doesn't have matching data size.
679
+ // Note function copies contents, so it won't create new data pointer
680
+ // or change allocation type.
681
+ // All Tensor related properties will be copied from 'src' to 'dst' like
682
+ // quantization, sparsity, ...
683
+ TfLiteStatus TfLiteTensorCopy(const TfLiteTensor* src, TfLiteTensor* dst);
684
+
685
+ // Change the size of the memory block owned by `tensor` to `num_bytes`.
686
+ // Tensors with allocation types other than `kTfLiteDynamic` will be ignored and
687
+ // a kTfLiteOk will be returned.
688
+ // `tensor`'s internal data buffer will be assigned a pointer
689
+ // which can safely be passed to free or realloc if `num_bytes` is zero.
690
+ // If `preserve_data` is true, tensor data will be unchanged in the range from
691
+ // the start of the region up to the minimum of the old and new sizes. In the
692
+ // case of NULL tensor, or an error allocating new memory, returns
693
+ // `kTfLiteError`.
694
+ TfLiteStatus TfLiteTensorResizeMaybeCopy(size_t num_bytes, TfLiteTensor* tensor,
695
+ bool preserve_data);
696
+
697
+ // Change the size of the memory block owned by `tensor` to `num_bytes`.
698
+ // Tensors with allocation types other than kTfLiteDynamic will be ignored and
699
+ // a kTfLiteOk will be returned.
700
+ // `tensor`'s internal data buffer will be assigned a pointer
701
+ // which can safely be passed to free or realloc if `num_bytes` is zero.
702
+ // Tensor data will be unchanged in the range from the start of the region up to
703
+ // the minimum of the old and new sizes. In the case
704
+ // of NULL tensor, or an error allocating new memory, returns `kTfLiteError`.
705
+ TfLiteStatus TfLiteTensorRealloc(size_t num_bytes, TfLiteTensor* tensor);
706
+ #endif // TF_LITE_STATIC_MEMORY
707
+
708
+ // WARNING: This is an experimental interface that is subject to change.
709
+ //
710
+ // Currently, TfLiteDelegateParams has to be allocated in a way that it's
711
+ // trivially destructable. It will be stored as `builtin_data` field in
712
+ // `TfLiteNode` of the delegate node.
713
+ //
714
+ // See also the `CreateDelegateParams` function in `interpreter.cc` details.
715
+ typedef struct TfLiteDelegateParams {
716
+ struct TfLiteDelegate* delegate;
717
+ TfLiteIntArray* nodes_to_replace;
718
+ TfLiteIntArray* input_tensors;
719
+ TfLiteIntArray* output_tensors;
720
+ } TfLiteDelegateParams;
721
+
722
+ // WARNING: This is an experimental interface that is subject to change.
723
+ //
724
+ // Currently, TfLiteOpaqueDelegateParams has to be allocated in a way that it's
725
+ // trivially destructable. It will be stored as `builtin_data` field in
726
+ // `TfLiteNode` of the delegate node.
727
+ //
728
+ // See also the `CreateOpaqueDelegateParams` function in `subgraph.cc`
729
+ // details.
730
+ typedef struct TfLiteOpaqueDelegateParams {
731
+ TfLiteOpaqueDelegate* delegate;
732
+ void* delegate_data;
733
+ TfLiteIntArray* nodes_to_replace;
734
+ TfLiteIntArray* input_tensors;
735
+ TfLiteIntArray* output_tensors;
736
+ } TfLiteOpaqueDelegateParams;
737
+
738
+ typedef struct TfLiteContext {
739
+ // Number of tensors in the context.
740
+ size_t tensors_size;
741
+
742
+ // The execution plan contains a list of the node indices in execution
743
+ // order. execution_plan->size is the current number of nodes. And,
744
+ // execution_plan->data[0] is the first node that needs to be run.
745
+ // TfLiteDelegates can traverse the current execution plan by iterating
746
+ // through each member of this array and using GetNodeAndRegistration() to
747
+ // access details about a node. i.e.
748
+ //
749
+ // TfLiteIntArray* execution_plan;
750
+ // TF_LITE_ENSURE_STATUS(context->GetExecutionPlan(context, &execution_plan));
751
+ // for (int exec_index = 0; exec_index < execution_plan->size; exec_index++) {
752
+ // int node_index = execution_plan->data[exec_index];
753
+ // TfLiteNode* node;
754
+ // TfLiteRegistration* reg;
755
+ // context->GetNodeAndRegistration(context, node_index, &node, &reg);
756
+ // }
757
+ // Note: the memory pointed by '`*execution_plan` is OWNED by TfLite runtime.
758
+ // Future calls to GetExecutionPlan invalidates earlier outputs. The following
759
+ // code snippet shows the issue of such an invocation pattern. After calling
760
+ // CheckNode, subsequent access to `plan_1st` is undefined.
761
+ //
762
+ // void CheckNode(const TfLiteNode* node) {
763
+ // ...
764
+ // TfLiteIntArray* plan_2nd;
765
+ // TF_LITE_ENSURE_STATUS(context->GetExecutionPlan(context, &plan_2nd));
766
+ // ...
767
+ // }
768
+ //
769
+ // TfLiteIntArray* plan_1st;
770
+ // TF_LITE_ENSURE_STATUS(context->GetExecutionPlan(context, &plan_1st));
771
+ // for (int exec_index = 0; exec_index < plan_1st->size; exec_index++) {
772
+ // int node_index = plan_1st->data[exec_index];
773
+ // TfLiteNode* node;
774
+ // TfLiteRegistration* reg;
775
+ // context->GetNodeAndRegistration(context, node_index, &node, &reg);
776
+ // CheckNode(node);
777
+ // }
778
+ //
779
+ // WARNING: This is an experimental interface that is subject to change.
780
+ TfLiteStatus (*GetExecutionPlan)(struct TfLiteContext* context,
781
+ TfLiteIntArray** execution_plan);
782
+
783
+ // An array of tensors in the interpreter context (of length `tensors_size`)
784
+ TfLiteTensor* tensors;
785
+
786
+ // opaque full context ptr (an opaque c++ data structure)
787
+ void* impl_;
788
+
789
+ // Request memory pointer be resized. Updates dimensions on the tensor.
790
+ // NOTE: ResizeTensor takes ownership of newSize.
791
+ TfLiteStatus (*ResizeTensor)(struct TfLiteContext*, TfLiteTensor* tensor,
792
+ TfLiteIntArray* new_size);
793
+ // Request that an error be reported with format string msg.
794
+ void (*ReportError)(struct TfLiteContext*, const char* msg, ...);
795
+
796
+ // Add `tensors_to_add` tensors, preserving pre-existing Tensor entries. If
797
+ // non-null, the value pointed to by `first_new_tensor_index` will be set to
798
+ // the index of the first new tensor.
799
+ TfLiteStatus (*AddTensors)(struct TfLiteContext*, int tensors_to_add,
800
+ int* first_new_tensor_index);
801
+
802
+ // Get a Tensor node by node_index.
803
+ // WARNING: This is an experimental interface that is subject to change.
804
+ TfLiteStatus (*GetNodeAndRegistration)(
805
+ struct TfLiteContext*, int node_index, TfLiteNode** node,
806
+ struct TfLiteRegistration** registration);
807
+
808
+ // Replace ops with one or more stub delegate operations. This function
809
+ // does not take ownership of `nodes_to_replace`.
810
+ TfLiteStatus (*ReplaceNodeSubsetsWithDelegateKernels)(
811
+ struct TfLiteContext*, struct TfLiteRegistration registration,
812
+ const TfLiteIntArray* nodes_to_replace, struct TfLiteDelegate* delegate);
813
+
814
+ // Number of threads that are recommended to subsystems like gemmlowp and
815
+ // eigen.
816
+ int recommended_num_threads;
817
+
818
+ // Access external contexts by type.
819
+ // WARNING: This is an experimental interface that is subject to change.
820
+ TfLiteExternalContext* (*GetExternalContext)(struct TfLiteContext*,
821
+ TfLiteExternalContextType);
822
+ // Set the value of a external context. Does not take ownership of the
823
+ // pointer.
824
+ // WARNING: This is an experimental interface that is subject to change.
825
+ void (*SetExternalContext)(struct TfLiteContext*, TfLiteExternalContextType,
826
+ TfLiteExternalContext*);
827
+
828
+ // Flag for allowing float16 precision for FP32 calculation.
829
+ // default: false.
830
+ // WARNING: This is an experimental API and subject to change.
831
+ bool allow_fp32_relax_to_fp16;
832
+
833
+ // Pointer to the op-level profiler, if set; nullptr otherwise.
834
+ void* profiler;
835
+
836
+ // Allocate persistent buffer which has the same life time as the interpreter.
837
+ // Returns nullptr on failure.
838
+ // The memory is allocated from heap for TFL, and from tail in TFLM.
839
+ // This method is only available in Init or Prepare stage.
840
+ // WARNING: This is an experimental interface that is subject to change.
841
+ void* (*AllocatePersistentBuffer)(struct TfLiteContext* ctx, size_t bytes);
842
+
843
+ // Allocate a buffer which will be deallocated right after invoke phase.
844
+ // The memory is allocated from heap in TFL, and from volatile arena in TFLM.
845
+ // This method is only available in invoke stage.
846
+ // NOTE: If possible use RequestScratchBufferInArena method to avoid memory
847
+ // allocation during inference time.
848
+ // WARNING: This is an experimental interface that is subject to change.
849
+ TfLiteStatus (*AllocateBufferForEval)(struct TfLiteContext* ctx, size_t bytes,
850
+ void** ptr);
851
+
852
+ // Request a scratch buffer in the arena through static memory planning.
853
+ // This method is only available in Prepare stage and the buffer is allocated
854
+ // by the interpreter between Prepare and Eval stage. In Eval stage,
855
+ // GetScratchBuffer API can be used to fetch the address.
856
+ // WARNING: This is an experimental interface that is subject to change.
857
+ TfLiteStatus (*RequestScratchBufferInArena)(struct TfLiteContext* ctx,
858
+ size_t bytes, int* buffer_idx);
859
+
860
+ // Get the scratch buffer pointer.
861
+ // This method is only available in Eval stage.
862
+ // WARNING: This is an experimental interface that is subject to change.
863
+ void* (*GetScratchBuffer)(struct TfLiteContext* ctx, int buffer_idx);
864
+
865
+ // Resize the memory pointer of the `tensor`. This method behaves the same as
866
+ // `ResizeTensor`, except that it makes a copy of the shape array internally
867
+ // so the shape array could be deallocated right afterwards.
868
+ // WARNING: This is an experimental interface that is subject to change.
869
+ TfLiteStatus (*ResizeTensorExplicit)(struct TfLiteContext* ctx,
870
+ TfLiteTensor* tensor, int dims,
871
+ const int* shape);
872
+
873
+ // This method provides a preview of post-delegation partitioning. Each
874
+ // TfLiteDelegateParams in the referenced array corresponds to one instance of
875
+ // the delegate kernel.
876
+ // Example usage:
877
+ //
878
+ // TfLiteIntArray* nodes_to_replace = ...;
879
+ // TfLiteDelegateParams* params_array;
880
+ // int num_partitions = 0;
881
+ // TF_LITE_ENSURE_STATUS(context->PreviewDelegatePartitioning(
882
+ // context, delegate, nodes_to_replace, &params_array, &num_partitions));
883
+ // for (int idx = 0; idx < num_partitions; idx++) {
884
+ // const auto& partition_params = params_array[idx];
885
+ // ...
886
+ // }
887
+ //
888
+ // NOTE: The context owns the memory referenced by partition_params_array. It
889
+ // will be cleared with another call to PreviewDelegatePartitioning, or after
890
+ // TfLiteDelegateParams::Prepare returns.
891
+ //
892
+ // WARNING: This is an experimental interface that is subject to change.
893
+ TfLiteStatus (*PreviewDelegatePartitioning)(
894
+ struct TfLiteContext* context, const TfLiteIntArray* nodes_to_replace,
895
+ TfLiteDelegateParams** partition_params_array, int* num_partitions);
896
+
897
+ // Returns a TfLiteTensor struct for a given index.
898
+ // WARNING: This is an experimental interface that is subject to change.
899
+ // WARNING: This method may not be available on all platforms.
900
+ TfLiteTensor* (*GetTensor)(const struct TfLiteContext* context,
901
+ int tensor_idx);
902
+
903
+ // Returns a TfLiteEvalTensor struct for a given index.
904
+ // WARNING: This is an experimental interface that is subject to change.
905
+ // WARNING: This method may not be available on all platforms.
906
+ TfLiteEvalTensor* (*GetEvalTensor)(const struct TfLiteContext* context,
907
+ int tensor_idx);
908
+
909
+ // Retrieves named metadata buffer from the TFLite model.
910
+ // Returns kTfLiteOk if metadata is successfully obtained from the flatbuffer
911
+ // Model: that is, there exists a `metadata` entry with given `name` string.
912
+ // (see TFLite's schema.fbs).
913
+ // The corresponding `buffer` information is populated in `ptr` & `bytes`.
914
+ // The data from `ptr` is valid for the lifetime of the Interpreter.
915
+ //
916
+ // WARNING: This is an experimental interface that is subject to change.
917
+ TfLiteStatus (*GetModelMetadata)(const struct TfLiteContext* context,
918
+ const char* name, const char** ptr,
919
+ size_t* bytes);
920
+
921
+ // Retrieves the corresponding TfLiteContext of a subgraph that the given
922
+ // subgraph_index points to and switches to the delegate context for that
923
+ // subgraph. If an invalid subgraph index is given, returns kTfLiteError.
924
+ // NOTE: This function is expected to be paired with ReleaseSubgraphContext()
925
+ // once the delegate preparation is done and/or the delegate context functions
926
+ // are no longer needed.
927
+ //
928
+ // WARNING: This is an experimental interface that is subject to change.
929
+ TfLiteStatus (*AcquireSubgraphContext)(
930
+ struct TfLiteContext* context, int subgraph_index,
931
+ struct TfLiteContext** acquired_context);
932
+ // Releases the subgraph context by switching back to the TFLite kernel
933
+ // context for the subgraph that the given subgraph_index points to.
934
+ // NOTE: This function is expected to be used after AcquireSubgraphContext()
935
+ // once the delegate preparation is done and/or the delegate context functions
936
+ // are no longer needed.
937
+ //
938
+ // WARNING: This is an experimental interface that is subject to change.
939
+ TfLiteStatus (*ReleaseSubgraphContext)(struct TfLiteContext* context,
940
+ int subgraph_index);
941
+ } TfLiteContext;
942
+
943
+ // `TfLiteRegistrationExternal` is an external version of `TfLiteRegistration`
944
+ // for C API which doesn't use internal types (such as `TfLiteContext`) but only
945
+ // uses stable API types (such as `TfLiteOpaqueContext`). The purpose of each
946
+ // field is the exactly the same as with `TfLiteRegistration`.
947
+ typedef struct TfLiteRegistrationExternal TfLiteRegistrationExternal;
948
+
949
+ // The valid values of the `inplace_operator` field in `TfLiteRegistration`.
950
+ // This allow an op to signal to the runtime that the same data pointer
951
+ // may be passed as an input and output without impacting the result.
952
+ // This does not mean that the memory can safely be reused, it is up to the
953
+ // runtime to determine this, e.g. if another op consumes the same input or not
954
+ // or if an input tensor has sufficient memory allocated to store the output
955
+ // data.
956
+ //
957
+ // Setting these flags authorizes the runtime to set the data pointers of an
958
+ // input and output tensor to the same value. In such cases, the memory required
959
+ // by the output must be less than or equal to that required by the shared
960
+ // input, never greater. If kTfLiteInplaceOpDataUnmodified is set, then the
961
+ // runtime can share the same input tensor with multiple operator's outputs,
962
+ // provided that kTfLiteInplaceOpDataUnmodified is set for all of them.
963
+ // Otherwise, if an input tensor is consumed by multiple operators, it may only
964
+ // be shared with the operator which is the last to consume it.
965
+ //
966
+ // Note that this is a bitmask, so the values should be 1, 2, 4, 8, ...etc.
967
+ typedef enum {
968
+ // The default value. This indicates that the same data pointer cannot safely
969
+ // be passed as an op's input and output.
970
+ kTfLiteInplaceOpNone = 0,
971
+ // This indicates that an op's first output's data is identical to its first
972
+ // input's data, for example Reshape.
973
+ kTfLiteInplaceOpDataUnmodified = 1,
974
+ // Setting kTfLiteInplaceInputCanBeSharedWithCorrespondingOutput means
975
+ // that InputN may be shared with OutputN instead of with the first output.
976
+ // This flag requires one or more of kTfLiteInplaceOpInputNShared to be set.
977
+ kTfLiteInplaceInputCanBeSharedWithCorrespondingOutput = 2,
978
+ // kTfLiteInplaceOpInputNShared indicates that it is safe for an op to share
979
+ // InputN's data pointer with an output tensor. If
980
+ // kTfLiteInplaceInputCanBeSharedWithCorrespondingOutput is set then
981
+ // kTfLiteInplaceOpInputNShared indicates that InputN may be shared
982
+ // with OutputN, otherwise kTfLiteInplaceOpInputNShared indicates that InputN
983
+ // may be shared with the first output.
984
+ //
985
+ // Indicates that an op's first input may be shared with the first output
986
+ // tensor. kTfLiteInplaceInputCanBeSharedWithCorrespondingOutput has
987
+ // no impact on the behavior allowed by this flag.
988
+ kTfLiteInplaceOpInput0Shared = 4,
989
+ // Indicates that an op's second input may be shared with the first output
990
+ // if kTfLiteInplaceInputCanBeSharedWithCorrespondingOutput is not set
991
+ // or second output if kTfLiteInplaceInputCanBeSharedWithCorrespondingOutput
992
+ // is set.
993
+ kTfLiteInplaceOpInput1Shared = 8,
994
+ // Indicates that an op's third input may be shared with the first output
995
+ // if kTfLiteInplaceInputCanBeSharedWithCorrespondingOutput is not set
996
+ // or third output if kTfLiteInplaceInputCanBeSharedWithCorrespondingOutput is
997
+ // set.
998
+ kTfLiteInplaceOpInput2Shared = 16,
999
+ // Placeholder to ensure that enum can hold 64 bit values to accommodate
1000
+ // future fields.
1001
+ kTfLiteInplaceOpMaxValue = UINT64_MAX,
1002
+ } TfLiteInPlaceOp;
1003
+
1004
+ // The number of shareable inputs supported.
1005
+ static const int kTfLiteMaxSharableOpInputs = 3;
1006
+
1007
+ typedef struct TfLiteRegistration {
1008
+ // Initializes the op from serialized data.
1009
+ // Called only *once* for the lifetime of the op, so any one-time allocations
1010
+ // should be made here (unless they depend on tensor sizes).
1011
+ //
1012
+ // If a built-in op:
1013
+ // `buffer` is the op's params data (TfLiteLSTMParams*).
1014
+ // `length` is zero.
1015
+ // If custom op:
1016
+ // `buffer` is the op's `custom_options`.
1017
+ // `length` is the size of the buffer.
1018
+ //
1019
+ // Returns a type-punned (i.e. void*) opaque data (e.g. a primitive pointer
1020
+ // or an instance of a struct).
1021
+ //
1022
+ // The returned pointer will be stored with the node in the `user_data` field,
1023
+ // accessible within prepare and invoke functions below.
1024
+ // NOTE: if the data is already in the desired format, simply implement this
1025
+ // function to return `nullptr` and implement the free function to be a no-op.
1026
+ void* (*init)(TfLiteContext* context, const char* buffer, size_t length);
1027
+
1028
+ // The pointer `buffer` is the data previously returned by an init invocation.
1029
+ void (*free)(TfLiteContext* context, void* buffer);
1030
+
1031
+ // prepare is called when the inputs this node depends on have been resized.
1032
+ // context->ResizeTensor() can be called to request output tensors to be
1033
+ // resized.
1034
+ // Can be called multiple times for the lifetime of the op.
1035
+ //
1036
+ // Returns kTfLiteOk on success.
1037
+ TfLiteStatus (*prepare)(TfLiteContext* context, TfLiteNode* node);
1038
+
1039
+ // Execute the node (should read node->inputs and output to node->outputs).
1040
+ // Returns kTfLiteOk on success.
1041
+ TfLiteStatus (*invoke)(TfLiteContext* context, TfLiteNode* node);
1042
+
1043
+ // profiling_string is called during summarization of profiling information
1044
+ // in order to group executions together. Providing a value here will cause a
1045
+ // given op to appear multiple times is the profiling report. This is
1046
+ // particularly useful for custom ops that can perform significantly
1047
+ // different calculations depending on their `user-data`.
1048
+ const char* (*profiling_string)(const TfLiteContext* context,
1049
+ const TfLiteNode* node);
1050
+
1051
+ // Builtin codes. If this kernel refers to a builtin this is the code
1052
+ // of the builtin. This is so we can do marshaling to other frameworks like
1053
+ // NN API.
1054
+ // Note: It is the responsibility of the registration binder to set this
1055
+ // properly.
1056
+ int32_t builtin_code;
1057
+
1058
+ // Custom op name. If the op is a builtin, this will be null.
1059
+ // Note: It is the responsibility of the registration binder to set this
1060
+ // properly.
1061
+ // WARNING: This is an experimental interface that is subject to change.
1062
+ const char* custom_name;
1063
+
1064
+ // The version of the op.
1065
+ // Note: It is the responsibility of the registration binder to set this
1066
+ // properly.
1067
+ int version;
1068
+
1069
+ // The external version of `TfLiteRegistration`. Since we can't use internal
1070
+ // types (such as `TfLiteContext`) for C API to maintain ABI stability.
1071
+ // C API user will provide `TfLiteRegistrationExternal` to implement custom
1072
+ // ops. We keep it inside of `TfLiteRegistration` and use it to route
1073
+ // callbacks properly.
1074
+ TfLiteRegistrationExternal* registration_external;
1075
+
1076
+ // Retrieves asynchronous kernel.
1077
+ //
1078
+ // If the `async_kernel` field is nullptr, it means the operation described by
1079
+ // this TfLiteRegistration object does not support asynchronous execution.
1080
+ // Otherwise, the function that the field points to should only be called for
1081
+ // delegate kernel nodes, i.e. `node` should be a delegate kernel node created
1082
+ // by applying a delegate.
1083
+ // If the function returns nullptr, that means that the underlying delegate
1084
+ // does not support asynchronous execution for this `node`.
1085
+ struct TfLiteAsyncKernel* (*async_kernel)(TfLiteContext* context,
1086
+ TfLiteNode* node);
1087
+
1088
+ // Indicates if an operator's output may safely overwrite its inputs.
1089
+ // See the comments in `TfLiteInPlaceOp`.
1090
+ uint64_t inplace_operator;
1091
+ } TfLiteRegistration;
1092
+
1093
+ /// \private
1094
+ // Old version of `TfLiteRegistration` to maintain binary backward
1095
+ // compatibility.
1096
+ // The legacy registration type must be a POD struct type whose field types must
1097
+ // be a prefix of the field types in TfLiteRegistration, and offset of the first
1098
+ // field in TfLiteRegistration that is not present in the legacy registration
1099
+ // type must be greater than or equal to the size of the legacy registration
1100
+ // type.
1101
+ // WARNING: This structure is deprecated / not an official part of the
1102
+ // API. It should be only used for binary backward compatibility.
1103
+ typedef struct TfLiteRegistration_V3 {
1104
+ void* (*init)(TfLiteContext* context, const char* buffer, size_t length);
1105
+ void (*free)(TfLiteContext* context, void* buffer);
1106
+ TfLiteStatus (*prepare)(TfLiteContext* context, TfLiteNode* node);
1107
+ TfLiteStatus (*invoke)(TfLiteContext* context, TfLiteNode* node);
1108
+ const char* (*profiling_string)(const TfLiteContext* context,
1109
+ const TfLiteNode* node);
1110
+ int32_t builtin_code;
1111
+ const char* custom_name;
1112
+ int version;
1113
+ TfLiteRegistrationExternal* registration_external;
1114
+ struct TfLiteAsyncKernel* (*async_kernel)(TfLiteContext* context,
1115
+ TfLiteNode* node);
1116
+ } TfLiteRegistration_V3;
1117
+
1118
+ /// \private
1119
+ // Old version of `TfLiteRegistration` to maintain binary backward
1120
+ // compatibility.
1121
+ // The legacy registration type must be a POD struct type whose field types must
1122
+ // be a prefix of the field types in TfLiteRegistration, and offset of the first
1123
+ // field in TfLiteRegistration that is not present in the legacy registration
1124
+ // type must be greater than or equal to the size of the legacy registration
1125
+ // type.
1126
+ // WARNING: This structure is deprecated / not an official part of the
1127
+ // API. It should be only used for binary backward compatibility.
1128
+ typedef struct TfLiteRegistration_V2 {
1129
+ void* (*init)(TfLiteContext* context, const char* buffer, size_t length);
1130
+ void (*free)(TfLiteContext* context, void* buffer);
1131
+ TfLiteStatus (*prepare)(TfLiteContext* context, TfLiteNode* node);
1132
+ TfLiteStatus (*invoke)(TfLiteContext* context, TfLiteNode* node);
1133
+ const char* (*profiling_string)(const TfLiteContext* context,
1134
+ const TfLiteNode* node);
1135
+ int32_t builtin_code;
1136
+ const char* custom_name;
1137
+ int version;
1138
+ TfLiteRegistrationExternal* registration_external;
1139
+ } TfLiteRegistration_V2;
1140
+
1141
+ /// \private
1142
+ // Old version of `TfLiteRegistration` to maintain binary backward
1143
+ // compatibility.
1144
+ // The legacy registration type must be a POD struct type whose field types must
1145
+ // be a prefix of the field types in TfLiteRegistration, and offset of the first
1146
+ // field in TfLiteRegistration that is not present in the legacy registration
1147
+ // type must be greater than or equal to the size of the legacy registration
1148
+ // type.
1149
+ // WARNING: This structure is deprecated / not an official part of the
1150
+ // API. It should be only used for binary backward compatibility.
1151
+ typedef struct TfLiteRegistration_V1 {
1152
+ void* (*init)(TfLiteContext* context, const char* buffer, size_t length);
1153
+ void (*free)(TfLiteContext* context, void* buffer);
1154
+ TfLiteStatus (*prepare)(TfLiteContext* context, TfLiteNode* node);
1155
+ TfLiteStatus (*invoke)(TfLiteContext* context, TfLiteNode* node);
1156
+ const char* (*profiling_string)(const TfLiteContext* context,
1157
+ const TfLiteNode* node);
1158
+ int32_t builtin_code;
1159
+ const char* custom_name;
1160
+ int version;
1161
+ } TfLiteRegistration_V1;
1162
+
1163
+ // The flags used in `TfLiteDelegate`. Note that this is a bitmask, so the
1164
+ // values should be 1, 2, 4, 8, ...etc.
1165
+ typedef enum TfLiteDelegateFlags {
1166
+ kTfLiteDelegateFlagsNone = 0,
1167
+ // The flag is set if the delegate can handle dynamic sized tensors.
1168
+ // For example, the output shape of a `Resize` op with non-constant shape
1169
+ // can only be inferred when the op is invoked.
1170
+ // In this case, the Delegate is responsible for calling
1171
+ // `SetTensorToDynamic` to mark the tensor as a dynamic tensor, and calling
1172
+ // `ResizeTensor` when invoking the op.
1173
+ //
1174
+ // If the delegate isn't capable to handle dynamic tensors, this flag need
1175
+ // to be set to false.
1176
+ kTfLiteDelegateFlagsAllowDynamicTensors = 1,
1177
+
1178
+ // This flag can be used by delegates (that allow dynamic tensors) to ensure
1179
+ // applicable tensor shapes are automatically propagated in the case of tensor
1180
+ // resizing.
1181
+ // This means that non-dynamic (allocation_type != kTfLiteDynamic) I/O tensors
1182
+ // of a delegate kernel will have correct shapes before its Prepare() method
1183
+ // is called. The runtime leverages TFLite builtin ops in the original
1184
+ // execution plan to propagate shapes.
1185
+ //
1186
+ // A few points to note:
1187
+ // 1. This requires kTfLiteDelegateFlagsAllowDynamicTensors. If that flag is
1188
+ // false, this one is redundant since the delegate kernels are re-initialized
1189
+ // every time tensors are resized.
1190
+ // 2. Enabling this flag adds some overhead to AllocateTensors(), since extra
1191
+ // work is required to prepare the original execution plan.
1192
+ // 3. This flag requires that the original execution plan only have ops with
1193
+ // valid registrations (and not 'dummy' custom ops like with Flex).
1194
+ // WARNING: This feature is experimental and subject to change.
1195
+ kTfLiteDelegateFlagsRequirePropagatedShapes = 2,
1196
+
1197
+ // This flag can be used by delegates to request per-operator profiling. If a
1198
+ // node is a delegate node, this flag will be checked before profiling. If
1199
+ // set, then the node will not be profiled. The delegate will then add per
1200
+ // operator information using Profiler::EventType::OPERATOR_INVOKE_EVENT and
1201
+ // the results will appear in the operator-wise Profiling section and not in
1202
+ // the Delegate internal section.
1203
+ kTfLiteDelegateFlagsPerOperatorProfiling = 4
1204
+ } TfLiteDelegateFlags;
1205
+
1206
+ // WARNING: This is an experimental interface that is subject to change.
1207
+ typedef struct TfLiteDelegate {
1208
+ // Data that delegate needs to identify itself. This data is owned by the
1209
+ // delegate. The delegate is owned in the user code, so the delegate is
1210
+ // responsible for deallocating this when it is destroyed.
1211
+ void* data_;
1212
+
1213
+ // Invoked by ModifyGraphWithDelegate. This prepare is called, giving the
1214
+ // delegate a view of the current graph through TfLiteContext*. It typically
1215
+ // will look at the nodes and call ReplaceNodeSubsetsWithDelegateKernels()
1216
+ // to ask the TensorFlow lite runtime to create macro-nodes to represent
1217
+ // delegated subgraphs of the original graph.
1218
+ TfLiteStatus (*Prepare)(TfLiteContext* context,
1219
+ struct TfLiteDelegate* delegate);
1220
+
1221
+ // Copy the data from delegate buffer handle into raw memory of the given
1222
+ // 'tensor'. Note that the delegate is allowed to allocate the raw bytes as
1223
+ // long as it follows the rules for kTfLiteDynamic tensors, in which case this
1224
+ // cannot be null.
1225
+ TfLiteStatus (*CopyFromBufferHandle)(TfLiteContext* context,
1226
+ struct TfLiteDelegate* delegate,
1227
+ TfLiteBufferHandle buffer_handle,
1228
+ TfLiteTensor* tensor);
1229
+
1230
+ // Copy the data from raw memory of the given 'tensor' to delegate buffer
1231
+ // handle. This can be null if the delegate doesn't use its own buffer.
1232
+ TfLiteStatus (*CopyToBufferHandle)(TfLiteContext* context,
1233
+ struct TfLiteDelegate* delegate,
1234
+ TfLiteBufferHandle buffer_handle,
1235
+ TfLiteTensor* tensor);
1236
+
1237
+ // Free the Delegate Buffer Handle. Note: This only frees the handle, but
1238
+ // this doesn't release the underlying resource (e.g. textures). The
1239
+ // resources are either owned by application layer or the delegate.
1240
+ // This can be null if the delegate doesn't use its own buffer.
1241
+ void (*FreeBufferHandle)(TfLiteContext* context,
1242
+ struct TfLiteDelegate* delegate,
1243
+ TfLiteBufferHandle* handle);
1244
+
1245
+ // Bitmask flags. See the comments in `TfLiteDelegateFlags`.
1246
+ int64_t flags;
1247
+
1248
+ // The opaque delegate builder associated with this object. If set then the
1249
+ // TF Lite runtime will give precedence to this field. E.g. instead of
1250
+ // invoking 'Prepare' via the function pointer inside the 'TfLiteDelegate'
1251
+ // object, the runtime will first check if the corresponding function
1252
+ // pointer inside 'opaque_delegate_builder' is set and if so invoke that.
1253
+ //
1254
+ // If this field is non-null, then the 'Prepare' field (of the
1255
+ // 'TfLiteDelegate') should be null.
1256
+ struct TfLiteOpaqueDelegateBuilder* opaque_delegate_builder;
1257
+ } TfLiteDelegate;
1258
+
1259
+ // Build a 'null' delegate, with all the fields properly set to their default
1260
+ // values.
1261
+ TfLiteDelegate TfLiteDelegateCreate(void);
1262
+
1263
+ // `TfLiteOpaqueDelegateBuilder` is used for constructing
1264
+ // `TfLiteOpaqueDelegate`, see `TfLiteOpaqueDelegateCreate` below. Note:
1265
+ // This struct is not ABI stable.
1266
+ //
1267
+ // For forward source compatibility `TfLiteOpaqueDelegateBuilder` objects should
1268
+ // be brace-initialized, so that all fields (including any that might be added
1269
+ // in the future) get zero-initialized. The purpose of each field is exactly
1270
+ // the same as with `TfLiteDelegate`.
1271
+ //
1272
+ // WARNING: This is an experimental interface that is subject to change.
1273
+ typedef struct TfLiteOpaqueDelegateBuilder {
1274
+ // Data that delegate needs to identify itself. This data is owned by the
1275
+ // delegate. The delegate is owned in the user code, so the delegate is
1276
+ // responsible for deallocating this when it is destroyed.
1277
+ void* data;
1278
+ // Invoked by ModifyGraphWithDelegate. This prepare is called, giving the
1279
+ // delegate a view of the current graph through TfLiteContext*. It typically
1280
+ // will look at the nodes and call ReplaceNodeSubsetsWithDelegateKernels()
1281
+ // to ask the TensorFlow lite runtime to create macro-nodes to represent
1282
+ // delegated subgraphs of the original graph.
1283
+ TfLiteStatus (*Prepare)(TfLiteOpaqueContext* context, // NOLINT
1284
+ TfLiteOpaqueDelegate* delegate, void* data);
1285
+ // Copies the data from delegate buffer handle into raw memory of the given
1286
+ // 'tensor'. Note that the delegate is allowed to allocate the raw bytes as
1287
+ // long as it follows the rules for kTfLiteDynamic tensors, in which case this
1288
+ // cannot be null.
1289
+ TfLiteStatus (*CopyFromBufferHandle)( // NOLINT
1290
+ TfLiteOpaqueContext* context, TfLiteOpaqueDelegate* delegate, void* data,
1291
+ TfLiteBufferHandle buffer_handle, TfLiteOpaqueTensor* tensor);
1292
+ // Copies the data from raw memory of the given 'tensor' to delegate buffer
1293
+ // handle. This can be null if the delegate doesn't use its own buffer.
1294
+ TfLiteStatus (*CopyToBufferHandle)( // NOLINT
1295
+ TfLiteOpaqueContext* context, TfLiteOpaqueDelegate* delegate, void* data,
1296
+ TfLiteBufferHandle buffer_handle, TfLiteOpaqueTensor* tensor);
1297
+ // Frees the Delegate Buffer Handle. Note: This only frees the handle, but
1298
+ // this doesn't release the underlying resource (e.g. textures). The
1299
+ // resources are either owned by application layer or the delegate.
1300
+ // This can be null if the delegate doesn't use its own buffer.
1301
+ void (*FreeBufferHandle)(TfLiteOpaqueContext* context, // NOLINT
1302
+ TfLiteOpaqueDelegate* delegate, void* data,
1303
+ TfLiteBufferHandle* handle);
1304
+ // Bitmask flags. See the comments in `TfLiteDelegateFlags`.
1305
+ int64_t flags;
1306
+ } TfLiteOpaqueDelegateBuilder;
1307
+
1308
+ #ifndef TF_LITE_STATIC_MEMORY
1309
+ // Creates an opaque delegate and returns its address. The opaque delegate will
1310
+ // behave according to the provided 'opaque_delegate_builder'. The lifetime of
1311
+ // the objects pointed to by any of the fields within the
1312
+ // 'opaque_delegate_builder' must outlive the returned
1313
+ // 'TfLiteOpaqueDelegate' and any 'TfLiteInterpreter',
1314
+ // 'TfLiteInterpreterOptions', 'tflite_micro::Interpreter', or
1315
+ // 'tflite_micro::InterpreterBuilder' that the delegate is added to. The returned
1316
+ // address should be passed to 'TfLiteOpaqueDelegateDelete' for deletion. If
1317
+ // 'opaque_delegate_builder' is a null pointer, then a null pointer will be
1318
+ // returned.
1319
+ TfLiteOpaqueDelegate* TfLiteOpaqueDelegateCreate(
1320
+ const TfLiteOpaqueDelegateBuilder* opaque_delegate_builder);
1321
+
1322
+ // Deletes the provided opaque 'delegate'. This function has no effect if the
1323
+ // 'delegate' is a null pointer.
1324
+ void TfLiteOpaqueDelegateDelete(TfLiteOpaqueDelegate* delegate);
1325
+ #endif // TF_LITE_STATIC_MEMORY
1326
+
1327
+ // Returns a pointer to the data associated with the provided opaque 'delegate'.
1328
+ //
1329
+ // A null pointer will be returned when:
1330
+ // - The 'delegate' is null.
1331
+ // - The 'data' field of the 'TfLiteOpaqueDelegateBuilder' used to construct the
1332
+ // 'delegate' was null.
1333
+ // - Or in case of any other error.
1334
+ // - The 'delegate' has been constructed via a 'TfLiteOpaqueDelegateBuilder',
1335
+ // but the 'data' field of the 'TfLiteOpaqueDelegateBuilder' is null.
1336
+ //
1337
+ // The data_ field of 'delegate' will be returned if the
1338
+ // 'opaque_delegate_builder' field is null.
1339
+ void* TfLiteOpaqueDelegateGetData(const TfLiteOpaqueDelegate* delegate);
1340
+
1341
+ // Returns a tensor data allocation strategy.
1342
+ TfLiteAllocationStrategy TfLiteTensorGetAllocationStrategy(
1343
+ const TfLiteTensor* t);
1344
+
1345
+ // Returns how stable a tensor data buffer address is across runs.
1346
+ TfLiteRunStability TfLiteTensorGetBufferAddressStability(const TfLiteTensor* t);
1347
+
1348
+ // Returns how stable a tensor data values are across runs.
1349
+ TfLiteRunStability TfLiteTensorGetDataStability(const TfLiteTensor* t);
1350
+
1351
+ // Returns the operation step when the data of a tensor is populated.
1352
+ //
1353
+ // Some operations can precompute their results before the evaluation step. This
1354
+ // makes the data available earlier for subsequent operations.
1355
+ TfLiteRunStep TfLiteTensorGetDataKnownStep(const TfLiteTensor* t);
1356
+
1357
+ // Returns the operation steop when the shape of a tensor is computed.
1358
+ //
1359
+ // Some operations can precompute the shape of their results before the
1360
+ // evaluation step. This makes the shape available earlier for subsequent
1361
+ // operations.
1362
+ TfLiteRunStep TfLiteTensorGetShapeKnownStep(const TfLiteTensor* t);
1363
+
1364
+ #ifdef __cplusplus
1365
+ } // extern "C"
1366
+
1367
+ #include <utility>
1368
+
1369
+ // --- TFLITE VARIANT TENSORS ----
1370
+ // Programming languges usually define "variant" as a type that can hold an
1371
+ // unbounded set of types. See std::any
1372
+ // (https://en.cppreference.com/w/cpp/utility/any) for a related standard
1373
+ // library construct. In tensorflow, variant tensors have a data member which is
1374
+ // an Object that is destructible and copy constructible.
1375
+ // Variant tensors are commonly used to represent non trivial data
1376
+ // semantics that don't fit into simple primitives, such as lists of tensors and
1377
+ // datasets. Additionally, they can facilitate containers for optimizing
1378
+ // memory movement of tensor data.
1379
+ //
1380
+ // The following set of classes define the variant tensor member for tflite.
1381
+ // They implement a type-erased container intended to be used behind the
1382
+ // `data.data : void*` member of `TfLiteTensor`s. Runtime functions interact
1383
+ // the variant member at the level of a `VariantData`, whereas kernels
1384
+ // operate with the full knowledge of the un-erased type. The `VariantData`
1385
+ // class provides abstract methods for destroying and copying `VariantData`.
1386
+ // Invoking these methods will dispatch to the erased type opaquely.
1387
+ // The contents of any object of type derived from `AbstractVariant` can be
1388
+ // written to `TfLiteTensor::data::data : void*` from kernels. If the runtime
1389
+ // were to copy such a tensor through `TfLiteTensorCopy`, the destination data
1390
+ // member will contain the result of invoking the erased type's copy
1391
+ // constructor. Similar for the runtime releasing tensors from memory, the
1392
+ // erased type's destructor will be invoked. There are a few caveats to consider
1393
+ // to use these safely, which we discuss below.
1394
+ //
1395
+ // EXAMPLE: READING VARIANT TENSORS
1396
+ // ```
1397
+ // // retrieve input with `type == kTfLiteVariant`
1398
+ // TfLiteTensor* input = ...
1399
+ // // must first static cast to `VariantData`, more on this below.
1400
+ // VariantData* vd_input = static_cast<VariantData*>(t->data.data);
1401
+ // CustomType* typed_input =
1402
+ // static_cast<CustomType*>(vd_input);
1403
+ // // do custom work on `typed_input`...
1404
+ // ```
1405
+ //
1406
+ // EXAMPLE: WRITING VARIANT TENSORS
1407
+ // ```
1408
+ // TfLiteTensor* output = ...
1409
+ // // construct a new variant object behind the target tensor
1410
+ // TfLiteVariantRealloc<DerivedType, DerivedArgs...>(output, args...);
1411
+ // // again must static cast to `VariantData*` before writing to `void*`.
1412
+ // output->data.data = static_cast<VariantData*>(typed_output);
1413
+ // ```
1414
+ //
1415
+ // WHY STATIC CAST TO `VariantData*`
1416
+ // The Standard defines a `reinterpret_cast` from a derived type to its
1417
+ // parents as undefined behavior when the parent is a non-standard layout.
1418
+ // https://en.cppreference.com/w/cpp/language/reinterpret_cast (see bullet 5).
1419
+ // Due to the `VariantData` having virtual members it is indeed non-standard
1420
+ // layout, and any type derived from `VariantData` fails to be
1421
+ // "transparently-replaceable". I.e. implicit cast from derived to base in this
1422
+ // case may adjust the pointer and by definition `reinterpret_cast` will not
1423
+ // the adjust the pointer.
1424
+ // Thus, dereferencing a pointer of type `VariantData` which addresses
1425
+ // the first byte of an object of said derived type is UB unless it was first
1426
+ // implicitly or statically casted to a `VariantData`. Writing the object of
1427
+ // derived type directly to `void*` which is dereferenced as a `VariantData` is
1428
+ // then UB, and so the intermediate cast through `VariantData` must be enforced.
1429
+ // A good example of this issue is ellucidate in the bottom code snippet
1430
+ // here: https://en.cppreference.com/w/cpp/utility/launder.
1431
+ class VariantData {
1432
+ public:
1433
+ // All variant objects must be able to be destroyed and copied.
1434
+ virtual ~VariantData() = default;
1435
+ // A "virtual copy-constructor". Often the destination tensor of a variant
1436
+ // copy may have been previously allocated in a prior call to inference. We
1437
+ // allow the copy to target the destinations buffer (`maybe_alloc`),
1438
+ // for potential reuse and optimizations. `maybe_alloc` must be of the same
1439
+ // underlying derived type. References to whatever object is at
1440
+ // `maybe_alloc` may be invalidated.
1441
+ virtual VariantData* CloneTo(VariantData* maybe_alloc) const = 0;
1442
+ };
1443
+
1444
+ // Concrete implementations extend `AbstractVariantData` with CRPT.
1445
+ template <typename ErasedDerived>
1446
+ class AbstractVariantData : public VariantData {
1447
+ public:
1448
+ VariantData* CloneTo(VariantData* maybe_alloc) const override {
1449
+ if (maybe_alloc != nullptr) {
1450
+ // If the output is still allocated, then its object may still be
1451
+ // in its life time and the destructor must be called before re-using the
1452
+ // buffer.
1453
+ // This may actual have a non-negligible effect on performance if the
1454
+ // destructor is complex. A future iteration may
1455
+ // introduce copy or move assignment semantics, allowing for the
1456
+ // underlying implementation to optimize for this case.
1457
+ auto* derived = static_cast<ErasedDerived*>(maybe_alloc);
1458
+ derived->~ErasedDerived();
1459
+ return new (derived)
1460
+ ErasedDerived(static_cast<ErasedDerived const&>(*this));
1461
+ }
1462
+ return new ErasedDerived(static_cast<ErasedDerived const&>(*this));
1463
+ }
1464
+
1465
+ protected:
1466
+ AbstractVariantData() = default;
1467
+ AbstractVariantData(const AbstractVariantData&) = default;
1468
+ AbstractVariantData(AbstractVariantData&&) = delete;
1469
+ };
1470
+
1471
+ // Analogous to `TfLiteTensorRealloc` for allocation of tensors whose
1472
+ // data member points to an arbitrary C++ object. `VariantType` refers
1473
+ // to the erased type of said object and `VariantArgs` refers to
1474
+ // a list of argument types with which to construct a new `VariantType`.
1475
+ // `VariantArgs` must match a constructor of `VariantType`.
1476
+ template <class VariantType, class... VariantArgs>
1477
+ TfLiteStatus TfLiteTensorVariantRealloc(TfLiteTensor* t,
1478
+ VariantArgs&&... args) {
1479
+ if (t->type != kTfLiteVariant) return kTfLiteError;
1480
+ VariantType* new_vd;
1481
+ if (t->data.raw != nullptr) {
1482
+ auto* target_vd = static_cast<VariantData*>(t->data.data);
1483
+ target_vd->~VariantData();
1484
+ // As above, we assume if `t` is already allocated then it was allocated
1485
+ // with the same `VariantType` as templated.
1486
+ new_vd = new (t->data.raw) VariantType(std::forward<VariantArgs>(args)...);
1487
+ } else {
1488
+ new_vd = new VariantType(std::forward<VariantArgs>(args)...);
1489
+ }
1490
+ t->data.data = static_cast<VariantData*>(new_vd);
1491
+ t->allocation_type = kTfLiteVariantObject;
1492
+ return kTfLiteOk;
1493
+ }
1494
+
1495
+ #endif // __cplusplus
1496
+ #endif // TENSORFLOW_LITE_CORE_C_COMMON_H_