xmos-ai-tools 1.1.2.dev216__py3-none-macosx_11_0_arm64.whl → 1.1.2.dev236__py3-none-macosx_11_0_arm64.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 (147) hide show
  1. xmos_ai_tools/runtime/include/lib_nn/api/nn_layers.h +16 -0
  2. xmos_ai_tools/runtime/include/lib_nn/api/quadratic_approximation.h +80 -0
  3. xmos_ai_tools/runtime/include/lib_nn/api/quadratic_interpolation.h +23 -0
  4. xmos_ai_tools/runtime/include/lib_tflite_micro/src/tflite-xcore-kernels/xcore_ops.h +15 -15
  5. xmos_ai_tools/runtime/include/{tensorflow/lite/micro/examples/micro_speech/simple_features/model.h → signal/micro/kernels/delay_flexbuffers_generated_data.h} +7 -9
  6. xmos_ai_tools/runtime/include/signal/micro/kernels/energy_flexbuffers_generated_data.h +28 -0
  7. xmos_ai_tools/runtime/include/signal/micro/kernels/fft_flexbuffers_generated_data.h +37 -0
  8. xmos_ai_tools/runtime/include/signal/micro/kernels/filter_bank_flexbuffers_generated_data.h +25 -0
  9. xmos_ai_tools/runtime/include/signal/micro/kernels/filter_bank_log_flexbuffers_generated_data.h +27 -0
  10. xmos_ai_tools/runtime/include/signal/micro/kernels/filter_bank_spectral_subtraction_flexbuffers_generated_data.h +26 -0
  11. xmos_ai_tools/runtime/include/signal/micro/kernels/framer_flexbuffers_generated_data.h +25 -0
  12. xmos_ai_tools/runtime/include/{tensorflow/lite/micro/examples/micro_speech/simple_features/no_simple_features_data.h → signal/micro/kernels/irfft.h} +15 -7
  13. xmos_ai_tools/runtime/include/signal/micro/kernels/overlap_add_flexbuffers_generated_data.h +25 -0
  14. xmos_ai_tools/runtime/include/signal/micro/kernels/pcan_flexbuffers_generated_data.h +7 -0
  15. xmos_ai_tools/runtime/include/signal/micro/kernels/rfft.h +31 -0
  16. xmos_ai_tools/runtime/include/signal/micro/kernels/stacker_flexbuffers_generated_data.h +25 -0
  17. xmos_ai_tools/runtime/include/signal/micro/kernels/window_flexbuffers_generated_data.h +25 -0
  18. xmos_ai_tools/runtime/include/signal/src/circular_buffer.h +118 -0
  19. xmos_ai_tools/runtime/include/signal/src/complex.h +29 -0
  20. xmos_ai_tools/runtime/include/signal/src/energy.h +38 -0
  21. xmos_ai_tools/runtime/include/signal/src/fft_auto_scale.h +35 -0
  22. xmos_ai_tools/runtime/include/signal/src/filter_bank.h +69 -0
  23. xmos_ai_tools/runtime/include/signal/src/filter_bank_log.h +38 -0
  24. xmos_ai_tools/runtime/include/signal/src/filter_bank_spectral_subtraction.h +73 -0
  25. xmos_ai_tools/runtime/include/{tensorflow/lite/micro/examples/micro_speech/main_functions.h → signal/src/filter_bank_square_root.h} +14 -17
  26. xmos_ai_tools/runtime/include/signal/src/irfft.h +84 -0
  27. xmos_ai_tools/runtime/include/signal/src/kiss_fft_wrappers/kiss_fft_common.h +49 -0
  28. xmos_ai_tools/runtime/include/signal/src/kiss_fft_wrappers/kiss_fft_float.h +31 -0
  29. xmos_ai_tools/runtime/include/signal/src/kiss_fft_wrappers/kiss_fft_int16.h +30 -0
  30. xmos_ai_tools/runtime/include/signal/src/kiss_fft_wrappers/kiss_fft_int32.h +31 -0
  31. xmos_ai_tools/runtime/include/{tensorflow/lite/micro/examples/micro_speech/micro_features/no_micro_features_data.h → signal/src/log.h} +13 -6
  32. xmos_ai_tools/runtime/include/{tensorflow/lite/micro/python/interpreter/src/python_utils.h → signal/src/max_abs.h} +11 -11
  33. xmos_ai_tools/runtime/include/{tensorflow/lite/micro/examples/micro_speech/micro_features/yes_micro_features_data.h → signal/src/msb.h} +15 -6
  34. xmos_ai_tools/runtime/include/signal/src/overlap_add.h +46 -0
  35. xmos_ai_tools/runtime/include/signal/src/pcan_argc_fixed.h +41 -0
  36. xmos_ai_tools/runtime/include/signal/src/rfft.h +85 -0
  37. xmos_ai_tools/runtime/include/signal/src/square_root.h +32 -0
  38. xmos_ai_tools/runtime/include/{tensorflow/lite/micro/python/interpreter/src/numpy_utils.h → signal/src/window.h} +13 -15
  39. xmos_ai_tools/runtime/include/signal/testdata/fft_test_data.h +48 -0
  40. xmos_ai_tools/runtime/include/tensorflow/lite/array.h +156 -0
  41. xmos_ai_tools/runtime/include/tensorflow/lite/builtin_ops.h +44 -0
  42. xmos_ai_tools/runtime/include/tensorflow/lite/c/c_api_types.h +6 -0
  43. xmos_ai_tools/runtime/include/tensorflow/lite/c/common.h +8 -25
  44. xmos_ai_tools/runtime/include/tensorflow/lite/core/api/error_reporter.h +3 -3
  45. xmos_ai_tools/runtime/include/tensorflow/lite/core/api/flatbuffer_conversions.h +15 -0
  46. xmos_ai_tools/runtime/include/tensorflow/lite/core/c/builtin_op_data.h +92 -3
  47. xmos_ai_tools/runtime/include/tensorflow/lite/core/c/c_api_types.h +61 -51
  48. xmos_ai_tools/runtime/include/tensorflow/lite/core/c/common.h +302 -1
  49. xmos_ai_tools/runtime/include/tensorflow/lite/core/macros.h +78 -0
  50. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/common.h +129 -43
  51. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/cppmath.h +2 -2
  52. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/portable_tensor.h +23 -4
  53. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/add.h +210 -151
  54. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/comparisons.h +9 -18
  55. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/conv.h +2 -0
  56. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/add.h +103 -72
  57. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/conv.h +2 -0
  58. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/mean.h +2 -63
  59. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/mul.h +87 -26
  60. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/mul.h +129 -80
  61. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/reduce.h +42 -93
  62. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/resize_bilinear.h +5 -0
  63. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/sub.h +249 -263
  64. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/runtime_shape.h +11 -1
  65. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/strided_slice_logic.h +5 -1
  66. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/tensor_ctypes.h +5 -10
  67. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/types.h +4 -2
  68. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/kernel_util.h +25 -14
  69. xmos_ai_tools/runtime/include/tensorflow/lite/kernels/op_macros.h +14 -3
  70. xmos_ai_tools/runtime/include/tensorflow/lite/micro/debug_log.h +10 -3
  71. xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/micro_model_settings.h +37 -0
  72. xmos_ai_tools/runtime/include/tensorflow/lite/micro/fake_micro_context.h +7 -0
  73. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/add.h +6 -5
  74. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/circular_buffer.h +0 -3
  75. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/conv.h +19 -20
  76. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/conv_test.h +8 -31
  77. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/depthwise_conv.h +8 -8
  78. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/ethosu.h +1 -1
  79. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/fully_connected.h +9 -9
  80. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/kernel_runner.h +14 -9
  81. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/kernel_util.h +9 -4
  82. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/micro_ops.h +119 -100
  83. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/mul.h +4 -4
  84. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/pooling.h +8 -8
  85. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/reduce.h +4 -4
  86. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/reshape.h +26 -0
  87. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/softmax.h +12 -16
  88. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/strided_slice.h +40 -0
  89. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/svdf.h +8 -7
  90. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/unidirectional_sequence_lstm.h +5 -5
  91. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa.h +2 -2
  92. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_conv.h +26 -21
  93. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_depthwise_conv.h +4 -4
  94. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_reshape.h +2 -4
  95. xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_softmax.h +2 -2
  96. xmos_ai_tools/runtime/include/tensorflow/lite/micro/memory_planner/greedy_memory_planner.h +5 -0
  97. xmos_ai_tools/runtime/include/tensorflow/lite/micro/memory_planner/linear_memory_planner.h +4 -0
  98. xmos_ai_tools/runtime/include/tensorflow/lite/micro/memory_planner/micro_memory_planner.h +4 -0
  99. xmos_ai_tools/runtime/include/tensorflow/lite/micro/memory_planner/non_persistent_buffer_planner_shim.h +4 -0
  100. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_allocator.h +23 -8
  101. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_common.h +38 -0
  102. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_context.h +23 -65
  103. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_graph.h +15 -57
  104. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_interpreter.h +16 -5
  105. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_interpreter_context.h +125 -0
  106. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_interpreter_graph.h +110 -0
  107. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_log.h +6 -8
  108. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_mutable_op_resolver.h +114 -32
  109. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_op_resolver.h +6 -5
  110. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_profiler.h +1 -1
  111. xmos_ai_tools/runtime/include/tensorflow/lite/micro/mock_micro_graph.h +1 -1
  112. xmos_ai_tools/runtime/include/tensorflow/lite/micro/python/interpreter/src/python_ops_resolver.h +21 -0
  113. xmos_ai_tools/runtime/include/tensorflow/lite/micro/test_helper_custom_ops.h +3 -4
  114. xmos_ai_tools/runtime/include/tensorflow/lite/micro/test_helpers.h +28 -12
  115. xmos_ai_tools/runtime/include/tensorflow/lite/micro/testing/micro_test.h +1 -0
  116. xmos_ai_tools/runtime/include/tensorflow/lite/micro/tools/benchmarking/log_utils.h +273 -0
  117. xmos_ai_tools/runtime/include/tensorflow/lite/micro/tools/benchmarking/metrics.h +41 -0
  118. xmos_ai_tools/runtime/include/tensorflow/lite/micro/tools/benchmarking/op_resolver.h +127 -0
  119. xmos_ai_tools/runtime/include/tensorflow/lite/schema/schema_generated.h +9139 -5010
  120. xmos_ai_tools/runtime/lib/libhost_xtflitemicro.a +0 -0
  121. xmos_ai_tools/runtime/lib/libxtflitemicro.a +0 -0
  122. xmos_ai_tools/xinterpreters/libs/macos/xtflm_python.1.0.1.dylib +0 -0
  123. xmos_ai_tools/xinterpreters/libs/macos/xtflm_python.dylib +0 -0
  124. {xmos_ai_tools-1.1.2.dev216.data → xmos_ai_tools-1.1.2.dev236.data}/data/bin/xcore-opt +0 -0
  125. {xmos_ai_tools-1.1.2.dev216.dist-info → xmos_ai_tools-1.1.2.dev236.dist-info}/METADATA +3 -4
  126. {xmos_ai_tools-1.1.2.dev216.dist-info → xmos_ai_tools-1.1.2.dev236.dist-info}/RECORD +128 -105
  127. {xmos_ai_tools-1.1.2.dev216.dist-info → xmos_ai_tools-1.1.2.dev236.dist-info}/WHEEL +1 -1
  128. xmos_ai_tools/runtime/include/tensorflow/lite/core/api/op_resolver.h +0 -129
  129. xmos_ai_tools/runtime/include/tensorflow/lite/micro/all_ops_resolver.h +0 -38
  130. xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/audio_provider.h +0 -44
  131. xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/command_responder.h +0 -30
  132. xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/feature_provider.h +0 -50
  133. xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/micro_features/micro_features_generator.h +0 -30
  134. xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.h +0 -43
  135. xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/micro_features/no_feature_data_slice.h +0 -29
  136. xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/micro_features/yes_feature_data_slice.h +0 -29
  137. xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/recognize_commands.h +0 -151
  138. xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/simple_features/no_power_spectrum_data.h +0 -29
  139. xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/simple_features/simple_features_generator.h +0 -29
  140. xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/simple_features/simple_model_settings.h +0 -43
  141. xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/simple_features/yes_power_spectrum_data.h +0 -29
  142. xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/simple_features/yes_simple_features_data.h +0 -23
  143. xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_string.h +0 -33
  144. xmos_ai_tools/runtime/include/tensorflow/lite/micro/python/interpreter/src/interpreter_wrapper.h +0 -51
  145. xmos_ai_tools/runtime/include/tensorflow/lite/micro/python/interpreter/src/pybind11_lib.h +0 -64
  146. xmos_ai_tools/runtime/include/tensorflow/lite/micro/python/interpreter/src/shared_library.h +0 -40
  147. {xmos_ai_tools-1.1.2.dev216.dist-info → xmos_ai_tools-1.1.2.dev236.dist-info}/top_level.txt +0 -0
@@ -25,9 +25,9 @@ namespace tflite {
25
25
  struct XtensaDepthwiseConvOpData {
26
26
  OpDataConv reference_op_data;
27
27
 
28
- #if defined(HIFI4) || defined(HIFI5)
28
+ #if defined(HIFI3) || defined(HIFI4) || defined(HIFI5)
29
29
  int scratch_tensor_index;
30
- #endif // defined(HIFI4) || defined(HIFI5)
30
+ #endif // defined(HIFI3) || defined(HIFI4) || defined(HIFI5)
31
31
 
32
32
  #if defined(VISION_P6)
33
33
  int8_t* reorder_coefficient_bias; // buffers used to keep reordered coeff and
@@ -39,7 +39,7 @@ struct XtensaDepthwiseConvOpData {
39
39
  #endif // VISION_P6
40
40
  };
41
41
 
42
- #if defined(HIFI4) || defined(HIFI5)
42
+ #if defined(HIFI3) || defined(HIFI4) || defined(HIFI5)
43
43
  TfLiteStatus DepthwiseConvPrepareHifi(TfLiteContext* context, TfLiteNode* node);
44
44
 
45
45
  TfLiteStatus DepthwiseConvEvalHifi(TfLiteContext* context, TfLiteNode* node,
@@ -52,7 +52,7 @@ TfLiteStatus DepthwiseConvEvalHifi(TfLiteContext* context, TfLiteNode* node,
52
52
 
53
53
  TfLiteStatus DepthwiseConvReferenceEvalInt8(TfLiteContext* context,
54
54
  TfLiteNode* node);
55
- #endif // defined(HIFI4) || defined(HIFI5)
55
+ #endif // defined(HIFI3) || defined(HIFI4) || defined(HIFI5)
56
56
 
57
57
  #if defined(VISION_P6)
58
58
 
@@ -1,4 +1,4 @@
1
- /* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
1
+ /* Copyright 2023 The TensorFlow Authors. All Rights Reserved.
2
2
 
3
3
  Licensed under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License.
@@ -19,10 +19,8 @@ limitations under the License.
19
19
 
20
20
  #include "tensorflow/lite/c/common.h"
21
21
  #include "tensorflow/lite/kernels/internal/types.h"
22
- namespace tflite {
23
22
 
24
- constexpr int kReshapeInputTensor = 0;
25
- constexpr int kReshapeOutputTensor = 0;
23
+ namespace tflite {
26
24
 
27
25
  #if defined(VISION_P6)
28
26
 
@@ -22,12 +22,12 @@ limitations under the License.
22
22
 
23
23
  namespace tflite {
24
24
 
25
- #if defined(HIFI4) || defined(HIFI5)
25
+ #if defined(HIFI3) || defined(HIFI4) || defined(HIFI5)
26
26
  struct XtensaSoftmaxOpData {
27
27
  SoftmaxParams params;
28
28
  int scratch_tensor_index;
29
29
  };
30
- #endif // defined(HIFI4) || defined(HIFI5)
30
+ #endif // defined(HIFI3) || defined(HIFI4) || defined(HIFI5)
31
31
 
32
32
  #if defined(VISION_P6)
33
33
  struct XtensaSoftmaxOpData {
@@ -107,6 +107,11 @@ class GreedyMemoryPlanner : public MicroMemoryPlanner {
107
107
  return per_buffer_size;
108
108
  }
109
109
 
110
+ // Returns False because the GreedyMemoryPlanner doesn't preserves all tensors
111
+ // after invocation. Do to the fact that tensors that tensor data for tensors
112
+ // that aren't being used during a phase of invocation are overwritten.
113
+ bool preserves_all_tensors() const override { return false; }
114
+
110
115
  TF_LITE_REMOVE_VIRTUAL_DELETE
111
116
 
112
117
  private:
@@ -35,6 +35,10 @@ class LinearMemoryPlanner : public MicroMemoryPlanner {
35
35
  int GetBufferCount() override;
36
36
  TfLiteStatus GetOffsetForBuffer(int buffer_index, int* offset) override;
37
37
 
38
+ // Returns True because the LinearMemoryPlanner preserves all tensors after
39
+ // invocation.
40
+ bool preserves_all_tensors() const override { return true; }
41
+
38
42
  private:
39
43
  static constexpr int kMaxBufferCount = 1024;
40
44
  size_t buffer_offsets_[kMaxBufferCount];
@@ -81,6 +81,10 @@ class MicroMemoryPlanner {
81
81
  return kTfLiteOk;
82
82
  }
83
83
 
84
+ // Method will return True if the MicroMemoryPlanner preserves all tensors
85
+ // after invocation, and False if it doesn't.
86
+ virtual bool preserves_all_tensors() const = 0;
87
+
84
88
  virtual void PrintMemoryPlan() {
85
89
  // Default does nothing.
86
90
  }
@@ -115,6 +115,10 @@ class NonPersistentMemoryPlannerShim : public MicroMemoryPlanner {
115
115
  size_t GetMaximumMemorySize() override;
116
116
  int GetBufferCount() override;
117
117
 
118
+ // Returns False because the NonPersistentMemoryPlannerShim doesn't preserves
119
+ // all tensors after invocation.
120
+ bool preserves_all_tensors() const override { return false; }
121
+
118
122
  private:
119
123
  const BufferPlan* buffer_plan_; // not owned, can't be null
120
124
 
@@ -18,11 +18,11 @@ limitations under the License.
18
18
  #include <cstddef>
19
19
  #include <cstdint>
20
20
 
21
- #include "tensorflow/lite/c/common.h"
22
21
  #include "tensorflow/lite/micro/arena_allocator/single_arena_buffer_allocator.h"
23
22
  #include "tensorflow/lite/micro/compatibility.h"
24
23
  #include "tensorflow/lite/micro/flatbuffer_utils.h"
25
24
  #include "tensorflow/lite/micro/memory_planner/micro_memory_planner.h"
25
+ #include "tensorflow/lite/micro/micro_common.h"
26
26
  #include "tensorflow/lite/micro/tflite_bridge/flatbuffer_conversions_bridge.h"
27
27
  #include "tensorflow/lite/schema/schema_generated.h"
28
28
 
@@ -66,9 +66,16 @@ struct ScratchBufferRequest {
66
66
 
67
67
  } // namespace internal
68
68
 
69
+ // Enum used to keep track of which MemoryPlanner is being used for
70
+ // MicroAllocater::Create();
71
+ enum class MemoryPlannerType {
72
+ kGreedy,
73
+ kLinear,
74
+ };
75
+
69
76
  struct NodeAndRegistration {
70
77
  TfLiteNode node;
71
- const TfLiteRegistration_V1* registration;
78
+ const TFLMRegistration* registration;
72
79
  };
73
80
 
74
81
  // Holds a pointer to a buffer for a scratch buffer requested by a kernel during
@@ -117,7 +124,9 @@ class MicroAllocator {
117
124
  // Note: Please use alignas(16) to make sure tensor_arena is 16
118
125
  // bytes aligned, otherwise some head room will be wasted.
119
126
  // TODO(b/157615197): Cleanup constructor + factory usage.
120
- static MicroAllocator* Create(uint8_t* tensor_arena, size_t arena_size);
127
+ static MicroAllocator* Create(
128
+ uint8_t* tensor_arena, size_t arena_size,
129
+ MemoryPlannerType memory_planner_type = MemoryPlannerType::kGreedy);
121
130
 
122
131
  // Creates a MicroAllocator instance from a given tensor arena and a given
123
132
  // MemoryPlanner. This arena will be managed by the created instance. Note:
@@ -137,14 +146,20 @@ class MicroAllocator {
137
146
  // SingleArenaBufferAllocator instance and the MemoryPlanner. This allocator
138
147
  // instance will use the SingleArenaBufferAllocator instance to manage
139
148
  // allocations internally.
140
- static MicroAllocator* Create(uint8_t* persistent_tensor_arena,
141
- size_t persistent_arena_size,
142
- uint8_t* non_persistent_tensor_arena,
143
- size_t non_persistent_arena_size);
149
+ static MicroAllocator* Create(
150
+ uint8_t* persistent_tensor_arena, size_t persistent_arena_size,
151
+ uint8_t* non_persistent_tensor_arena, size_t non_persistent_arena_size,
152
+ MemoryPlannerType memory_planner_type = MemoryPlannerType::kGreedy);
144
153
 
145
154
  // Returns the fixed amount of memory overhead of MicroAllocator.
146
155
  static size_t GetDefaultTailUsage(bool is_memory_planner_given);
147
156
 
157
+ // Returns True if the MicroAllocator uses a LinearMemoryPlanner(is compatible
158
+ // with the PerserveAllTensors flag / feature ) and False otherwise.
159
+ bool preserves_all_tensor() const {
160
+ return memory_planner_->preserves_all_tensors();
161
+ };
162
+
148
163
  // Allocates internal resources required for model inference for each subgraph
149
164
  // from the arena.
150
165
  //
@@ -185,7 +200,7 @@ class MicroAllocator {
185
200
  // Allocates a TfLiteTensor struct and populates the returned value with
186
201
  // properties from the model flatbuffer. This struct is allocated from
187
202
  // temporary arena memory is only guaranteed until a call is made to
188
- // ResetTempAllocations(). Subgraph_allocaitons contains the array of
203
+ // ResetTempAllocations(). Subgraph_allocations contains the array of
189
204
  // TfLiteEvalTensors. If the newly allocated temp at the specified subgraph
190
205
  // and tensor index is already present int the TfLiteEvalTensor array, its
191
206
  // data buffer will be re-used.
@@ -0,0 +1,38 @@
1
+ /* Copyright 2023 The TensorFlow Authors. All Rights Reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+ ==============================================================================*/
15
+ #ifndef THIRD_PARTY_TFLITE_MICRO_TENSORFLOW_LITE_MICRO_MICRO_COMMON_H_
16
+ #define THIRD_PARTY_TFLITE_MICRO_TENSORFLOW_LITE_MICRO_MICRO_COMMON_H_
17
+
18
+ #include "tensorflow/lite/c/common.h"
19
+
20
+ // TFLMRegistration defines the API that TFLM kernels need to implement.
21
+ // This will be replacing the current TfLiteRegistration_V1 struct with
22
+ // something more compatible Embedded enviroment TFLM is used in.
23
+ struct TFLMRegistration {
24
+ void* (*init)(TfLiteContext* context, const char* buffer, size_t length);
25
+ void (*free)(TfLiteContext* context, void* buffer);
26
+ TfLiteStatus (*prepare)(TfLiteContext* context, TfLiteNode* node);
27
+ TfLiteStatus (*invoke)(TfLiteContext* context, TfLiteNode* node);
28
+ void (*reset)(TfLiteContext* context, void* buffer);
29
+ int32_t builtin_code;
30
+ const char* custom_name;
31
+ };
32
+
33
+ struct TFLMInferenceRegistration {
34
+ TfLiteStatus (*invoke)(TfLiteContext* context, TfLiteNode* node);
35
+ void (*reset)(TfLiteContext* context, void* buffer);
36
+ };
37
+
38
+ #endif // THIRD_PARTY_TFLITE_MICRO_TENSORFLOW_LITE_MICRO_MICRO_COMMON_H_
@@ -17,7 +17,6 @@ limitations under the License.
17
17
  #define TENSORFLOW_LITE_MICRO_MICRO_CONTEXT_H_
18
18
 
19
19
  #include "tensorflow/lite/c/common.h"
20
- #include "tensorflow/lite/micro/micro_allocator.h"
21
20
  #include "tensorflow/lite/micro/micro_graph.h"
22
21
 
23
22
  #define XCORE_TFLITE_MICRO_PATCHED
@@ -25,6 +24,8 @@ limitations under the License.
25
24
  #ifdef NO_INTERPRETER
26
25
 
27
26
  namespace tflite {
27
+ const TfLiteStatus kTfLiteAbort = static_cast<TfLiteStatus>(15);
28
+
28
29
  struct MicroContext{
29
30
  TfLiteTensor* (*AllocateTempInputTensor)(const TfLiteNode* node, int index);
30
31
  TfLiteTensor* (*AllocateTempOutputTensor)(const TfLiteNode* node, int index);
@@ -40,6 +41,9 @@ namespace tflite {
40
41
  #else
41
42
 
42
43
  namespace tflite {
44
+ // TODO(b/149795762): kTfLiteAbort cannot be part of the tflite TfLiteStatus.
45
+ const TfLiteStatus kTfLiteAbort = static_cast<TfLiteStatus>(15);
46
+
43
47
  // MicroContext is eventually going to become the API between TFLM and the
44
48
  // kernels, replacing all the functions in TfLiteContext. The end state is code
45
49
  // kernels to have code like:
@@ -48,119 +52,73 @@ namespace tflite {
48
52
  // micro_context-><TFLM kernel API>
49
53
  class MicroContext {
50
54
  public:
51
- // Enum that allows MicroContext to keep track of the stages different memory
52
- // planning APIs are available to kernels.
53
- enum class InterpreterState {
54
- kInit,
55
- kPrepare,
56
- kMemoryPlanning,
57
- kInvoke,
58
- };
59
-
60
- // Does not take any ownership, and all pointers must refer to valid objects
61
- // that outlive the one constructed.
62
- explicit MicroContext(MicroAllocator* allocator, const Model* model,
63
- MicroGraph* graph);
64
- virtual ~MicroContext();
55
+ virtual ~MicroContext() = default;
65
56
 
66
57
  // Allocate persistent buffer which has the same life time as the interpreter.
67
58
  // Returns nullptr on failure.
68
59
  // The memory is allocated from the tail.
69
60
  // This method is only available in Init or Prepare stage.
70
- // Virtual so that it can be faked for kernel tests.
71
- virtual void* AllocatePersistentBuffer(size_t bytes);
61
+ virtual void* AllocatePersistentBuffer(size_t bytes) = 0;
72
62
 
73
63
  // Request a scratch buffer in the arena through static memory planning.
74
64
  // This method is only available in Prepare stage and the buffer is allocated
75
65
  // by the interpreter between Prepare and Eval stage. In Eval stage,
76
66
  // GetScratchBuffer API can be used to fetch the address.
77
- // Virtual so that it can be faked for kernel tests.
78
67
  virtual TfLiteStatus RequestScratchBufferInArena(size_t bytes,
79
- int* buffer_idx);
68
+ int* buffer_idx) = 0;
80
69
 
81
70
  // Get the scratch buffer pointer.
82
71
  // This method is only available in Eval stage.
83
- // Virtual so that it can be faked for kernel tests.
84
- virtual void* GetScratchBuffer(int buffer_idx);
72
+ virtual void* GetScratchBuffer(int buffer_idx) = 0;
85
73
 
86
74
  // Returns a temporary TfLiteTensor struct for a given index.
87
- // Virtual so that it can be faked for kernel tests.
88
- virtual TfLiteTensor* AllocateTempTfLiteTensor(int tensor_idx);
89
- TfLiteTensor* AllocateTempTfLiteTensor(int tensor_idx, int sg);
75
+ virtual TfLiteTensor* AllocateTempTfLiteTensor(int tensor_idx) = 0;
76
+ virtual TfLiteTensor* AllocateTempTfLiteTensor(int tensor_idx, int sg){return nullptr;}
90
77
 
91
78
  // Returns a temporary TfLiteTensor struct for the specified input tensor of a
92
79
  // given mode. This is the recommended API over the deprecated
93
80
  // GetInput/GetInputSafe to get a temp input tensor. The returned tensor shall
94
81
  // be freed via calling DeallocateTempTfLiteTensor.
95
- virtual TfLiteTensor* AllocateTempInputTensor(const TfLiteNode* node,
96
- int index);
82
+ TfLiteTensor* AllocateTempInputTensor(const TfLiteNode* node, int index);
97
83
 
98
84
  // Returns a temporary TfLiteTensor struct for the specified output tensor of
99
85
  // a given mode. This is the recommended API over the deprecated
100
86
  // GetOutput/GetOutputSafe to get a temp output tensor. The returned tensor
101
87
  // shall be freed via calling DeallocateTempTfLiteTensor.
102
- virtual TfLiteTensor* AllocateTempOutputTensor(const TfLiteNode* node,
103
- int index);
88
+ TfLiteTensor* AllocateTempOutputTensor(const TfLiteNode* node, int index);
104
89
 
105
90
  // Returns a temporary TfLiteTensor struct for the specified intermediate
106
91
  // tensor of a given mode. This is the recommended API over the deprecated
107
92
  // GetIntermediates/GetIntermediatesSafe to get a temp intermediate tensor.
108
93
  // The returned tensor shall be freed via calling DeallocateTempTfLiteTensor.
109
- virtual TfLiteTensor* AllocateTempIntermediateTensor(const TfLiteNode* node,
110
- int index);
94
+ TfLiteTensor* AllocateTempIntermediateTensor(const TfLiteNode* node,
95
+ int index);
111
96
 
112
97
  // Deallocates a temp TfLiteTensor.
113
- // Virtual so that it can be faked for kernel tests.
114
- virtual void DeallocateTempTfLiteTensor(TfLiteTensor* tensor);
98
+ virtual void DeallocateTempTfLiteTensor(TfLiteTensor* tensor) = 0;
115
99
 
116
100
  // Returns a pointer to a temporary buffer (from the arena).
117
101
  // This API is only valid from the kernel's Prepare function and
118
102
  // the buffer's lifetime is also that of the Prepare function.
119
- // Virtual so that it can be faked for kernel tests.
120
- virtual uint8_t* AllocateTempBuffer(size_t size, size_t alignment);
103
+ virtual uint8_t* AllocateTempBuffer(size_t size, size_t alignment) = 0;
121
104
 
122
105
  // Signals that the temporary buffer is no longer needed.
123
- // Virtual so that it can be faked for kernel tests.
124
- virtual void DeallocateTempBuffer(uint8_t* buffer);
106
+ virtual void DeallocateTempBuffer(uint8_t* buffer) = 0;
125
107
 
126
108
  // Returns a TfLiteEvalTensor struct for a given index.
127
- // Virtual so that it can be faked for kernel tests.
128
- virtual TfLiteEvalTensor* GetEvalTensor(int tensor_idx);
129
- TfLiteEvalTensor* GetEvalTensor(int tensor_idx, int sg);
130
-
131
- // Sets the State of MemoryPlanning MicroContext
132
- void SetInterpreterState(MicroContext::InterpreterState state);
133
-
134
- // Sets the State of MemoryPlanning MicroContext
135
- MicroContext::InterpreterState GetInterpreterState() const;
109
+ virtual TfLiteEvalTensor* GetEvalTensor(int tensor_idx) = 0;
110
+ virtual TfLiteEvalTensor* GetEvalTensor(int tensor_idx, int sg){return nullptr;}
136
111
 
137
112
  // Does not take ownership of the pointer and the pointer must refer to valid
138
113
  // an object that outlive this class instance.
139
114
  // This can only be called once to set one external context.
140
- TfLiteStatus set_external_context(void* external_context_payload);
141
-
142
- void* external_context() { return external_context_payload_; }
115
+ virtual TfLiteStatus set_external_context(void* external_context_payload) = 0;
143
116
 
144
- MicroGraph& graph() { return graph_; }
117
+ virtual void* external_context() = 0;
145
118
 
146
- // Sets the pointer to a list of ScratchBufferHandle instances.
147
- // Not API between TFLM and kernels. Primarily used by the framework for
148
- // housekeeping in MicroContext.
149
- void SetScratchBufferHandles(ScratchBufferHandle* scratch_buffer_handles);
119
+ virtual MicroGraph& graph() = 0;
150
120
 
151
121
  private:
152
- // Return the tensor index as tensor_indices[index]. tensor_indices is of
153
- // max_size. Return -1 if index is not in the valid range of tensor_indices.
154
- int GetTensorIndex(int index, int max_size, const int* tensor_indices);
155
-
156
- MicroAllocator& allocator_;
157
- MicroGraph& graph_;
158
- const Model* model_;
159
- InterpreterState state_;
160
-
161
- ScratchBufferHandle* scratch_buffer_handles_ = nullptr;
162
- void* external_context_payload_ = nullptr;
163
-
164
122
  TF_LITE_REMOVE_VIRTUAL_DELETE
165
123
  };
166
124
 
@@ -16,10 +16,9 @@ limitations under the License.
16
16
  #ifndef TENSORFLOW_LITE_MICRO_MICRO_GRAPH_H_
17
17
  #define TENSORFLOW_LITE_MICRO_MICRO_GRAPH_H_
18
18
 
19
- #include "tensorflow/lite/c/common.h"
20
- #include "tensorflow/lite/micro/micro_allocator.h"
19
+ #include "tensorflow/lite/micro/compatibility.h"
20
+ #include "tensorflow/lite/micro/micro_common.h"
21
21
  #include "tensorflow/lite/micro/micro_resource_variable.h"
22
- #include "tensorflow/lite/schema/schema_generated.h"
23
22
 
24
23
  #ifdef NO_INTERPRETER
25
24
 
@@ -38,79 +37,38 @@ namespace tflite {
38
37
 
39
38
  namespace tflite {
40
39
 
41
- // Abstracts the details of interacting with the tflite::Model.
40
+ // Abstracts the details of interacting with the graph from the kernels
42
41
  //
43
- // Provides methods to access, initialize, prepare, invoke and free any
44
- // subgraph in the tflite::Graph.
42
+ // Provides methods to invoke any subgraph in the tflite::Graph.
45
43
  class MicroGraph {
46
44
  public:
47
- // The lifetime of the context, model, allocator and resource_variables must
48
- // be at least as long as that of the graph object, since the this class may
49
- // need to access them at any time. If resource_variables is a nullptr,
50
- // GetResourceVariables will return a nullptr.
51
- MicroGraph(TfLiteContext* context, const Model* model,
52
- MicroAllocator* allocator,
53
- MicroResourceVariables* resource_variables);
54
- virtual ~MicroGraph();
55
-
56
- // Sets up builtin data and calls TfLiteRegistration_V1->Init for every
57
- // operator in every subgraph in the model.
58
- virtual TfLiteStatus InitSubgraphs();
59
-
60
- // Calls TfLiteRegistration_V1->Prepare for every operator in every subgraph
61
- // in the model.
62
- virtual TfLiteStatus PrepareSubgraphs();
63
-
64
- // Calls TfLiteRegistration_V1->Free for every operator in every subgraph in
65
- // the model.
66
- virtual TfLiteStatus FreeSubgraphs();
45
+ virtual ~MicroGraph() = default;
67
46
 
68
- // Calls TfLiteRegistration_V1->Invoke for every operator in a single subgraph
47
+ // Calls TFLMRegistration->Invoke for every operator in a single subgraph
69
48
  // in the model.
70
- virtual TfLiteStatus InvokeSubgraph(int subgraph_idx);
71
-
72
- // Zeros out all variable tensors in all subgraphs in the model.
73
- virtual TfLiteStatus ResetVariableTensors();
49
+ virtual TfLiteStatus InvokeSubgraph(int subgraph_idx) = 0;
74
50
 
75
51
  // Number of tensor inputs to a specified subgraph in the model.
76
- virtual size_t NumSubgraphInputs(int subgraph_idx);
52
+ virtual size_t NumSubgraphInputs(int subgraph_idx) = 0;
77
53
 
78
54
  // Get the specified input tensor of a specified subgraph in the model.
79
- virtual TfLiteEvalTensor* GetSubgraphInput(int subgraph_idx, int input_idx);
55
+ virtual TfLiteEvalTensor* GetSubgraphInput(int subgraph_idx,
56
+ int input_idx) = 0;
80
57
 
81
58
  // Number of tensor outputs from a specified subgraph in the model.
82
- virtual size_t NumSubgraphOutputs(int subgraph_idx);
59
+ virtual size_t NumSubgraphOutputs(int subgraph_idx) = 0;
83
60
 
84
61
  // Get the specified output tensor of a specified subgraph in the model.
85
- virtual TfLiteEvalTensor* GetSubgraphOutput(int subgraph_idx, int output_idx);
62
+ virtual TfLiteEvalTensor* GetSubgraphOutput(int subgraph_idx,
63
+ int output_idx) = 0;
86
64
 
87
65
  // Number of subgraphs in the model.
88
- virtual int NumSubgraphs();
89
-
90
- // Hook to pass in subgraph allocations tracked within the interpreter,
91
- // allowing MicroGraph to init / prepare / invoke subgraphs in the model.
92
- void SetSubgraphAllocations(SubgraphAllocations* subgraph_allocations);
93
-
94
- // Get the current subgraph index. Within an on operator, this is guaranteed
95
- // to be the subgraph of that operator.
96
- int GetCurrentSubgraphIndex() { return current_subgraph_index_; }
97
-
98
- // Gets the list of alloctions for each subgraph. This is the source of truth
99
- // for all per-subgraph allocation data.
100
- SubgraphAllocations* GetAllocations() { return subgraph_allocations_; }
66
+ virtual int NumSubgraphs() = 0;
101
67
 
102
68
  // Get the resource variables for this TFLM graph.
103
- MicroResourceVariables* GetResourceVariables() { return resource_variables_; }
69
+ virtual MicroResourceVariables* GetResourceVariables() = 0;
104
70
 
105
71
  private:
106
- TfLiteContext* context_;
107
- const Model* model_;
108
- MicroAllocator* allocator_;
109
- SubgraphAllocations* subgraph_allocations_ = nullptr;
110
- int current_subgraph_index_;
111
- MicroResourceVariables* resource_variables_;
112
- const flatbuffers::Vector<flatbuffers::Offset<SubGraph>>* subgraphs_;
113
-
114
72
  TF_LITE_REMOVE_VIRTUAL_DELETE
115
73
  };
116
74
 
@@ -24,8 +24,8 @@ limitations under the License.
24
24
  #include "tensorflow/lite/core/api/error_reporter.h"
25
25
  #include "tensorflow/lite/kernels/internal/tensor_ctypes.h"
26
26
  #include "tensorflow/lite/micro/micro_allocator.h"
27
- #include "tensorflow/lite/micro/micro_context.h"
28
- #include "tensorflow/lite/micro/micro_graph.h"
27
+ #include "tensorflow/lite/micro/micro_interpreter_context.h"
28
+ #include "tensorflow/lite/micro/micro_interpreter_graph.h"
29
29
  #include "tensorflow/lite/micro/micro_op_resolver.h"
30
30
  #include "tensorflow/lite/micro/micro_profiler_interface.h"
31
31
  #include "tensorflow/lite/portable_type_to_tflitetype.h"
@@ -50,7 +50,8 @@ class MicroInterpreter {
50
50
  MicroInterpreter(const Model* model, const MicroOpResolver& op_resolver,
51
51
  uint8_t* tensor_arena, size_t tensor_arena_size,
52
52
  MicroResourceVariables* resource_variables = nullptr,
53
- MicroProfilerInterface* profiler = nullptr);
53
+ MicroProfilerInterface* profiler = nullptr,
54
+ bool preserve_all_tensors = false);
54
55
 
55
56
  // Create an interpreter instance using an existing MicroAllocator instance.
56
57
  // This constructor should be used when creating an allocator that needs to
@@ -115,6 +116,9 @@ class MicroInterpreter {
115
116
  return nullptr;
116
117
  }
117
118
 
119
+ // Returns a pointer to the tensor for the corresponding tensor_index
120
+ TfLiteEvalTensor* GetTensor(int tensor_index, int subgraph_index = 0);
121
+
118
122
  // Reset the state to be what you would expect when the interpreter is first
119
123
  // created. i.e. after Init and Prepare is called for the very first time.
120
124
  TfLiteStatus Reset();
@@ -135,6 +139,13 @@ class MicroInterpreter {
135
139
  // arena_used_bytes() + 16.
136
140
  size_t arena_used_bytes() const { return allocator_.used_bytes(); }
137
141
 
142
+ // Returns True if all Tensors are being preserves
143
+ // TODO(b/297106074) : revisit making C++ example or test for
144
+ // preserve_all_tesnors
145
+ bool preserve_all_tensors() const {
146
+ return allocator_.preserves_all_tensor();
147
+ }
148
+
138
149
  size_t operators_size(int sg) const { return model_->subgraphs()->Get(sg)->operators()->size(); }
139
150
 
140
151
  // For debugging only.
@@ -158,7 +169,7 @@ class MicroInterpreter {
158
169
  const MicroOpResolver& op_resolver_;
159
170
  TfLiteContext context_ = {};
160
171
  MicroAllocator& allocator_;
161
- MicroGraph graph_;
172
+ MicroInterpreterGraph graph_;
162
173
  bool tensors_allocated_;
163
174
 
164
175
  TfLiteStatus initialization_status_;
@@ -170,7 +181,7 @@ class MicroInterpreter {
170
181
  TfLiteTensor** input_tensors_;
171
182
  TfLiteTensor** output_tensors_;
172
183
 
173
- MicroContext micro_context_;
184
+ MicroInterpreterContext micro_context_;
174
185
  };
175
186
 
176
187
  } // namespace tflite