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.
- xmos_ai_tools/runtime/include/lib_nn/api/nn_layers.h +16 -0
- xmos_ai_tools/runtime/include/lib_nn/api/quadratic_approximation.h +80 -0
- xmos_ai_tools/runtime/include/lib_nn/api/quadratic_interpolation.h +23 -0
- xmos_ai_tools/runtime/include/lib_tflite_micro/src/tflite-xcore-kernels/xcore_ops.h +15 -15
- 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
- xmos_ai_tools/runtime/include/signal/micro/kernels/energy_flexbuffers_generated_data.h +28 -0
- xmos_ai_tools/runtime/include/signal/micro/kernels/fft_flexbuffers_generated_data.h +37 -0
- xmos_ai_tools/runtime/include/signal/micro/kernels/filter_bank_flexbuffers_generated_data.h +25 -0
- xmos_ai_tools/runtime/include/signal/micro/kernels/filter_bank_log_flexbuffers_generated_data.h +27 -0
- xmos_ai_tools/runtime/include/signal/micro/kernels/filter_bank_spectral_subtraction_flexbuffers_generated_data.h +26 -0
- xmos_ai_tools/runtime/include/signal/micro/kernels/framer_flexbuffers_generated_data.h +25 -0
- 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
- xmos_ai_tools/runtime/include/signal/micro/kernels/overlap_add_flexbuffers_generated_data.h +25 -0
- xmos_ai_tools/runtime/include/signal/micro/kernels/pcan_flexbuffers_generated_data.h +7 -0
- xmos_ai_tools/runtime/include/signal/micro/kernels/rfft.h +31 -0
- xmos_ai_tools/runtime/include/signal/micro/kernels/stacker_flexbuffers_generated_data.h +25 -0
- xmos_ai_tools/runtime/include/signal/micro/kernels/window_flexbuffers_generated_data.h +25 -0
- xmos_ai_tools/runtime/include/signal/src/circular_buffer.h +118 -0
- xmos_ai_tools/runtime/include/signal/src/complex.h +29 -0
- xmos_ai_tools/runtime/include/signal/src/energy.h +38 -0
- xmos_ai_tools/runtime/include/signal/src/fft_auto_scale.h +35 -0
- xmos_ai_tools/runtime/include/signal/src/filter_bank.h +69 -0
- xmos_ai_tools/runtime/include/signal/src/filter_bank_log.h +38 -0
- xmos_ai_tools/runtime/include/signal/src/filter_bank_spectral_subtraction.h +73 -0
- xmos_ai_tools/runtime/include/{tensorflow/lite/micro/examples/micro_speech/main_functions.h → signal/src/filter_bank_square_root.h} +14 -17
- xmos_ai_tools/runtime/include/signal/src/irfft.h +84 -0
- xmos_ai_tools/runtime/include/signal/src/kiss_fft_wrappers/kiss_fft_common.h +49 -0
- xmos_ai_tools/runtime/include/signal/src/kiss_fft_wrappers/kiss_fft_float.h +31 -0
- xmos_ai_tools/runtime/include/signal/src/kiss_fft_wrappers/kiss_fft_int16.h +30 -0
- xmos_ai_tools/runtime/include/signal/src/kiss_fft_wrappers/kiss_fft_int32.h +31 -0
- xmos_ai_tools/runtime/include/{tensorflow/lite/micro/examples/micro_speech/micro_features/no_micro_features_data.h → signal/src/log.h} +13 -6
- xmos_ai_tools/runtime/include/{tensorflow/lite/micro/python/interpreter/src/python_utils.h → signal/src/max_abs.h} +11 -11
- xmos_ai_tools/runtime/include/{tensorflow/lite/micro/examples/micro_speech/micro_features/yes_micro_features_data.h → signal/src/msb.h} +15 -6
- xmos_ai_tools/runtime/include/signal/src/overlap_add.h +46 -0
- xmos_ai_tools/runtime/include/signal/src/pcan_argc_fixed.h +41 -0
- xmos_ai_tools/runtime/include/signal/src/rfft.h +85 -0
- xmos_ai_tools/runtime/include/signal/src/square_root.h +32 -0
- xmos_ai_tools/runtime/include/{tensorflow/lite/micro/python/interpreter/src/numpy_utils.h → signal/src/window.h} +13 -15
- xmos_ai_tools/runtime/include/signal/testdata/fft_test_data.h +48 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/array.h +156 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/builtin_ops.h +44 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/c/c_api_types.h +6 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/c/common.h +8 -25
- xmos_ai_tools/runtime/include/tensorflow/lite/core/api/error_reporter.h +3 -3
- xmos_ai_tools/runtime/include/tensorflow/lite/core/api/flatbuffer_conversions.h +15 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/core/c/builtin_op_data.h +92 -3
- xmos_ai_tools/runtime/include/tensorflow/lite/core/c/c_api_types.h +61 -51
- xmos_ai_tools/runtime/include/tensorflow/lite/core/c/common.h +302 -1
- xmos_ai_tools/runtime/include/tensorflow/lite/core/macros.h +78 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/common.h +129 -43
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/cppmath.h +2 -2
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/portable_tensor.h +23 -4
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/add.h +210 -151
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/comparisons.h +9 -18
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/conv.h +2 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/add.h +103 -72
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/conv.h +2 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/mean.h +2 -63
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/mul.h +87 -26
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/mul.h +129 -80
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/reduce.h +42 -93
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/resize_bilinear.h +5 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/sub.h +249 -263
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/runtime_shape.h +11 -1
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/strided_slice_logic.h +5 -1
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/tensor_ctypes.h +5 -10
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/types.h +4 -2
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/kernel_util.h +25 -14
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/op_macros.h +14 -3
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/debug_log.h +10 -3
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/micro_model_settings.h +37 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/fake_micro_context.h +7 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/add.h +6 -5
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/circular_buffer.h +0 -3
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/conv.h +19 -20
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/conv_test.h +8 -31
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/depthwise_conv.h +8 -8
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/ethosu.h +1 -1
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/fully_connected.h +9 -9
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/kernel_runner.h +14 -9
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/kernel_util.h +9 -4
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/micro_ops.h +119 -100
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/mul.h +4 -4
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/pooling.h +8 -8
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/reduce.h +4 -4
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/reshape.h +26 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/softmax.h +12 -16
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/strided_slice.h +40 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/svdf.h +8 -7
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/unidirectional_sequence_lstm.h +5 -5
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa.h +2 -2
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_conv.h +26 -21
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_depthwise_conv.h +4 -4
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_reshape.h +2 -4
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_softmax.h +2 -2
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/memory_planner/greedy_memory_planner.h +5 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/memory_planner/linear_memory_planner.h +4 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/memory_planner/micro_memory_planner.h +4 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/memory_planner/non_persistent_buffer_planner_shim.h +4 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_allocator.h +23 -8
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_common.h +38 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_context.h +23 -65
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_graph.h +15 -57
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_interpreter.h +16 -5
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_interpreter_context.h +125 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_interpreter_graph.h +110 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_log.h +6 -8
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_mutable_op_resolver.h +114 -32
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_op_resolver.h +6 -5
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_profiler.h +1 -1
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/mock_micro_graph.h +1 -1
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/python/interpreter/src/python_ops_resolver.h +21 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/test_helper_custom_ops.h +3 -4
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/test_helpers.h +28 -12
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/testing/micro_test.h +1 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/tools/benchmarking/log_utils.h +273 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/tools/benchmarking/metrics.h +41 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/tools/benchmarking/op_resolver.h +127 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/schema/schema_generated.h +9139 -5010
- xmos_ai_tools/runtime/lib/libhost_xtflitemicro.a +0 -0
- xmos_ai_tools/runtime/lib/libxtflitemicro.a +0 -0
- xmos_ai_tools/xinterpreters/libs/macos/xtflm_python.1.0.1.dylib +0 -0
- xmos_ai_tools/xinterpreters/libs/macos/xtflm_python.dylib +0 -0
- {xmos_ai_tools-1.1.2.dev216.data → xmos_ai_tools-1.1.2.dev236.data}/data/bin/xcore-opt +0 -0
- {xmos_ai_tools-1.1.2.dev216.dist-info → xmos_ai_tools-1.1.2.dev236.dist-info}/METADATA +3 -4
- {xmos_ai_tools-1.1.2.dev216.dist-info → xmos_ai_tools-1.1.2.dev236.dist-info}/RECORD +128 -105
- {xmos_ai_tools-1.1.2.dev216.dist-info → xmos_ai_tools-1.1.2.dev236.dist-info}/WHEEL +1 -1
- xmos_ai_tools/runtime/include/tensorflow/lite/core/api/op_resolver.h +0 -129
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/all_ops_resolver.h +0 -38
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/audio_provider.h +0 -44
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/command_responder.h +0 -30
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/feature_provider.h +0 -50
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/micro_features/micro_features_generator.h +0 -30
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.h +0 -43
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/micro_features/no_feature_data_slice.h +0 -29
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/micro_features/yes_feature_data_slice.h +0 -29
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/recognize_commands.h +0 -151
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/simple_features/no_power_spectrum_data.h +0 -29
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/simple_features/simple_features_generator.h +0 -29
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/simple_features/simple_model_settings.h +0 -43
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/simple_features/yes_power_spectrum_data.h +0 -29
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/micro_speech/simple_features/yes_simple_features_data.h +0 -23
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_string.h +0 -33
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/python/interpreter/src/interpreter_wrapper.h +0 -51
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/python/interpreter/src/pybind11_lib.h +0 -64
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/python/interpreter/src/shared_library.h +0 -40
- {xmos_ai_tools-1.1.2.dev216.dist-info → xmos_ai_tools-1.1.2.dev236.dist-info}/top_level.txt +0 -0
@@ -16,6 +16,7 @@ limitations under the License.
|
|
16
16
|
#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_ADD_H_
|
17
17
|
|
18
18
|
#include <algorithm>
|
19
|
+
#include <cstddef>
|
19
20
|
#include <limits>
|
20
21
|
|
21
22
|
#include "tensorflow/lite/kernels/internal/common.h"
|
@@ -35,12 +36,35 @@ inline void CheckArithmeticParams(const ArithmeticParams& params) {
|
|
35
36
|
TFLITE_DCHECK_LE(-params.input2_offset, std::numeric_limits<int8_t>::max());
|
36
37
|
}
|
37
38
|
|
39
|
+
// TODO: b/270589088 - move to a more appropriate file (b/270589088#comment2)
|
38
40
|
template <typename T>
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
void BroadcastInput1(int size, const ArithmeticParams& params,
|
42
|
+
const T* input1_data, const T* input2_data, T* output_data,
|
43
|
+
void (*check_arithmetic_params)(const ArithmeticParams&),
|
44
|
+
T (*binary_func)(T, T, const ArithmeticParams&)) {
|
45
|
+
CheckArithmeticParams(params);
|
46
|
+
for (int i = 0; i < size; ++i) {
|
47
|
+
output_data[i] = binary_func(input1_data[0], input2_data[i], params);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
template <typename T>
|
52
|
+
void BroadcastInput2(int size, const ArithmeticParams& params,
|
53
|
+
const T* input1_data, const T* input2_data, T* output_data,
|
54
|
+
void (*check_arithmetic_params)(const ArithmeticParams&),
|
55
|
+
T (*binary_func)(T, T, const ArithmeticParams&)) {
|
56
|
+
CheckArithmeticParams(params);
|
57
|
+
for (int i = 0; i < size; ++i) {
|
58
|
+
output_data[i] = binary_func(input1_data[i], input2_data[0], params);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
// TODO: b/270589088 - move to a more appropriate file (b/270589088#comment2)
|
63
|
+
template <typename T>
|
64
|
+
void ElementWise(int size, const ArithmeticParams& params, const T* input1_data,
|
65
|
+
const T* input2_data, T* output_data,
|
66
|
+
void (*check_arithmetic_params)(const ArithmeticParams&),
|
67
|
+
T (*binary_func)(T, T, const ArithmeticParams&)) {
|
44
68
|
CheckArithmeticParams(params);
|
45
69
|
for (int i = 0; i < size; ++i) {
|
46
70
|
output_data[i] = binary_func(input1_data[i], input2_data[i], params);
|
@@ -48,19 +72,66 @@ inline void ElementWise(
|
|
48
72
|
}
|
49
73
|
|
50
74
|
template <typename T>
|
51
|
-
inline void
|
75
|
+
inline void BroadcastAddRecursiveDimensions(
|
76
|
+
const ArithmeticParams& params, int dimension, size_t* input1_offset_p,
|
77
|
+
size_t* input2_offset_p, size_t* output_offset,
|
78
|
+
size_t* compressed_input1_stride, size_t* compressed_input2_stride,
|
79
|
+
size_t* compressed_output_shape, const T* input1_data, const T* input2_data,
|
80
|
+
T* output_data, void (*check_arithmetic_params)(const ArithmeticParams&),
|
81
|
+
T (*binary_func)(T, T, const ArithmeticParams&)) {
|
82
|
+
if (dimension > 0) {
|
83
|
+
for (size_t c = 0; c < compressed_output_shape[dimension]; ++c) {
|
84
|
+
size_t input1_offset_c = *input1_offset_p;
|
85
|
+
size_t input2_offset_c = *input2_offset_p;
|
86
|
+
BroadcastAddRecursiveDimensions(
|
87
|
+
params, dimension - 1, &input1_offset_c, &input2_offset_c,
|
88
|
+
output_offset, compressed_input1_stride, compressed_input2_stride,
|
89
|
+
compressed_output_shape, input1_data, input2_data, output_data,
|
90
|
+
check_arithmetic_params, binary_func);
|
91
|
+
*input1_offset_p += compressed_input1_stride[dimension];
|
92
|
+
*input2_offset_p += compressed_input2_stride[dimension];
|
93
|
+
}
|
94
|
+
} else {
|
95
|
+
TFLITE_DCHECK(dimension == 0);
|
96
|
+
bool input1_is_broadcast = compressed_input1_stride[dimension] == 0;
|
97
|
+
bool input2_is_broadcast = compressed_input2_stride[dimension] == 0;
|
98
|
+
TFLITE_DCHECK(!(input1_is_broadcast && input2_is_broadcast));
|
99
|
+
const T* input1_data_ptr = input1_data + *input1_offset_p;
|
100
|
+
const T* input2_data_ptr = input2_data + *input2_offset_p;
|
101
|
+
T* output_data_ptr = output_data + *output_offset;
|
102
|
+
if (input1_is_broadcast) {
|
103
|
+
// input1 is broadcast.
|
104
|
+
BroadcastInput1<T>(compressed_output_shape[dimension], params,
|
105
|
+
input1_data_ptr, input2_data_ptr, output_data_ptr,
|
106
|
+
check_arithmetic_params, binary_func);
|
107
|
+
*input2_offset_p += compressed_output_shape[dimension];
|
108
|
+
} else if (input2_is_broadcast) {
|
109
|
+
// input2 is broadcast.
|
110
|
+
BroadcastInput2<T>(compressed_output_shape[dimension], params,
|
111
|
+
input1_data_ptr, input2_data_ptr, output_data_ptr,
|
112
|
+
check_arithmetic_params, binary_func);
|
113
|
+
*input1_offset_p += compressed_output_shape[dimension];
|
114
|
+
} else {
|
115
|
+
// Add element-wise.
|
116
|
+
ElementWise<T>(compressed_output_shape[dimension], params,
|
117
|
+
input1_data_ptr, input2_data_ptr, output_data_ptr,
|
118
|
+
check_arithmetic_params, binary_func);
|
119
|
+
*input1_offset_p += compressed_output_shape[dimension];
|
120
|
+
*input2_offset_p += compressed_output_shape[dimension];
|
121
|
+
}
|
122
|
+
*output_offset += compressed_output_shape[dimension];
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
// TODO: b/270589088 - move to a more appropriate file. (b/270589088#comment2)
|
127
|
+
template <typename T>
|
128
|
+
void BroadcastBinaryFunction6DSlow(
|
52
129
|
const ArithmeticParams& params, const RuntimeShape& input1_shape,
|
53
130
|
const T* input1_data, const RuntimeShape& input2_shape,
|
54
|
-
const T* input2_data, const RuntimeShape& output_shape,
|
55
|
-
T* output_data,
|
131
|
+
const T* input2_data, const RuntimeShape& output_shape, T* output_data,
|
56
132
|
void (*check_arithmetic_params)(const ArithmeticParams&),
|
57
133
|
T (*binary_func)(T, T, const ArithmeticParams&)) {
|
58
|
-
|
59
|
-
NdArrayDesc<6> desc2;
|
60
|
-
NdArrayDescsForElementwiseBroadcast(input1_shape, input2_shape, &desc1,
|
61
|
-
&desc2);
|
62
|
-
const RuntimeShape extended_output_shape =
|
63
|
-
RuntimeShape::ExtendedShape(6, output_shape);
|
134
|
+
constexpr int kMaxBroadcastDim = 6;
|
64
135
|
|
65
136
|
// In Tensorflow, the dimensions are canonically named (batch_number, row,
|
66
137
|
// col, channel), with extents (batches, height, width, depth), with the
|
@@ -73,65 +144,25 @@ inline void BroadcastBinaryFunction6DSlow(
|
|
73
144
|
// We name our variables by their Tensorflow convention, but generate C code
|
74
145
|
// nesting loops such that the innermost loop has the smallest stride for the
|
75
146
|
// best cache behavior.
|
76
|
-
size_t
|
77
|
-
size_t
|
78
|
-
size_t
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
size_t input2_offset_b = input2_offset_d;
|
86
|
-
size_t output_offset_b = output_offset_d;
|
87
|
-
for (int b = 0; b < extended_output_shape.Dims(2); ++b) {
|
88
|
-
size_t input1_offset_y = input1_offset_b;
|
89
|
-
size_t input2_offset_y = input2_offset_b;
|
90
|
-
size_t output_offset_y = output_offset_b;
|
91
|
-
for (int y = 0; y < extended_output_shape.Dims(3); ++y) {
|
92
|
-
size_t input1_offset_x = input1_offset_y;
|
93
|
-
size_t input2_offset_x = input2_offset_y;
|
94
|
-
size_t output_offset_x = output_offset_y;
|
95
|
-
for (int x = 0; x < extended_output_shape.Dims(4); ++x) {
|
96
|
-
size_t input1_offset_c = input1_offset_x;
|
97
|
-
size_t input2_offset_c = input2_offset_x;
|
98
|
-
size_t output_offset_c = output_offset_x;
|
99
|
-
for (int c = 0; c < extended_output_shape.Dims(5); ++c) {
|
100
|
-
output_data[output_offset_c] =
|
101
|
-
binary_func(input1_data[input1_offset_c],
|
102
|
-
input2_data[input2_offset_c], params);
|
103
|
-
input1_offset_c += desc1.strides[5];
|
104
|
-
input2_offset_c += desc2.strides[5];
|
105
|
-
++output_offset_c;
|
106
|
-
}
|
107
|
-
input1_offset_x += desc1.strides[4];
|
108
|
-
input2_offset_x += desc2.strides[4];
|
109
|
-
output_offset_x += extended_output_shape.Dims(5);
|
110
|
-
}
|
111
|
-
input1_offset_y += desc1.strides[3];
|
112
|
-
input2_offset_y += desc2.strides[3];
|
113
|
-
output_offset_y +=
|
114
|
-
extended_output_shape.Dims(4) * extended_output_shape.Dims(5);
|
115
|
-
}
|
116
|
-
input1_offset_b += desc1.strides[2];
|
117
|
-
input2_offset_b += desc2.strides[2];
|
118
|
-
output_offset_b += extended_output_shape.Dims(3) *
|
119
|
-
extended_output_shape.Dims(4) *
|
120
|
-
extended_output_shape.Dims(5);
|
121
|
-
}
|
122
|
-
input1_offset_d += desc1.strides[1];
|
123
|
-
input2_offset_d += desc2.strides[1];
|
124
|
-
output_offset_d +=
|
125
|
-
extended_output_shape.Dims(2) * extended_output_shape.Dims(3) *
|
126
|
-
extended_output_shape.Dims(4) * extended_output_shape.Dims(5);
|
127
|
-
}
|
128
|
-
input1_offset_a += desc1.strides[0];
|
129
|
-
input2_offset_a += desc2.strides[0];
|
130
|
-
output_offset_a +=
|
131
|
-
extended_output_shape.Dims(1) * extended_output_shape.Dims(2) *
|
132
|
-
extended_output_shape.Dims(3) * extended_output_shape.Dims(4) *
|
133
|
-
extended_output_shape.Dims(5);
|
147
|
+
size_t compressed_input1_stride[kMaxBroadcastDim];
|
148
|
+
size_t compressed_input2_stride[kMaxBroadcastDim];
|
149
|
+
size_t compressed_output_shape[kMaxBroadcastDim];
|
150
|
+
bool broadcastable_shape = ReduceDimensionsForBroadcast<kMaxBroadcastDim>(
|
151
|
+
input1_shape, input2_shape, compressed_input1_stride,
|
152
|
+
compressed_input2_stride, compressed_output_shape);
|
153
|
+
// Skip broadcasting for degenerate shapes.
|
154
|
+
if (!broadcastable_shape) {
|
155
|
+
return;
|
134
156
|
}
|
157
|
+
|
158
|
+
size_t input1_offset = 0;
|
159
|
+
size_t input2_offset = 0;
|
160
|
+
size_t output_offset = 0;
|
161
|
+
BroadcastAddRecursiveDimensions(
|
162
|
+
params, kMaxBroadcastDim - 1, &input1_offset, &input2_offset,
|
163
|
+
&output_offset, compressed_input1_stride, compressed_input2_stride,
|
164
|
+
compressed_output_shape, input1_data, input2_data, output_data,
|
165
|
+
check_arithmetic_params, binary_func);
|
135
166
|
}
|
136
167
|
|
137
168
|
template <typename T>
|
@@ -63,8 +63,10 @@ inline void ConvPerChannel(
|
|
63
63
|
const int filter_width = filter_shape.Dims(2);
|
64
64
|
const int filter_input_depth = filter_shape.Dims(3);
|
65
65
|
const int groups = input_depth / filter_input_depth;
|
66
|
+
TFLITE_DCHECK_NE(groups, 0);
|
66
67
|
TFLITE_DCHECK_EQ(input_depth % filter_input_depth, 0);
|
67
68
|
const int filters_per_group = output_depth / groups;
|
69
|
+
TFLITE_DCHECK_NE(filters_per_group, 0);
|
68
70
|
const int output_height = output_shape.Dims(1);
|
69
71
|
const int output_width = output_shape.Dims(2);
|
70
72
|
for (int batch = 0; batch < batches; ++batch) {
|
@@ -1,10 +1,10 @@
|
|
1
|
-
/* Copyright
|
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.
|
5
5
|
You may obtain a copy of the License at
|
6
6
|
|
7
|
-
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
8
|
|
9
9
|
Unless required by applicable law or agreed to in writing, software
|
10
10
|
distributed under the License is distributed on an "AS IS" BASIS,
|
@@ -15,65 +15,4 @@ limitations under the License.
|
|
15
15
|
#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_MEAN_H_
|
16
16
|
#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_MEAN_H_
|
17
17
|
|
18
|
-
#include <algorithm>
|
19
|
-
|
20
|
-
#include "tensorflow/lite/kernels/internal/common.h"
|
21
|
-
|
22
|
-
namespace tflite {
|
23
|
-
namespace reference_integer_ops {
|
24
|
-
|
25
|
-
template <typename integer_type>
|
26
|
-
inline void Mean(const tflite::MeanParams& op_params, int32_t multiplier,
|
27
|
-
int32_t shift, const RuntimeShape& unextended_input_shape,
|
28
|
-
const integer_type* input_data, int32_t input_zero_point,
|
29
|
-
const RuntimeShape& unextended_output_shape,
|
30
|
-
integer_type* output_data, int32_t output_zero_point) {
|
31
|
-
// Current implementation only supports dimension equals 4 and simultaneous
|
32
|
-
// reduction over width and height.
|
33
|
-
TFLITE_CHECK_EQ(unextended_input_shape.DimensionsCount(), 4);
|
34
|
-
TFLITE_CHECK_LE(unextended_output_shape.DimensionsCount(), 4);
|
35
|
-
const RuntimeShape input_shape =
|
36
|
-
RuntimeShape::ExtendedShape(4, unextended_input_shape);
|
37
|
-
const RuntimeShape output_shape =
|
38
|
-
RuntimeShape::ExtendedShape(4, unextended_output_shape);
|
39
|
-
const int output_batch = output_shape.Dims(0);
|
40
|
-
const int output_height = output_shape.Dims(1);
|
41
|
-
const int output_width = output_shape.Dims(2);
|
42
|
-
const int output_depth = output_shape.Dims(3);
|
43
|
-
const int input_height = input_shape.Dims(1);
|
44
|
-
const int input_width = input_shape.Dims(2);
|
45
|
-
const int num_elements_in_axis = input_width * input_height;
|
46
|
-
|
47
|
-
TFLITE_CHECK_EQ(op_params.axis_count, 2);
|
48
|
-
TFLITE_CHECK((op_params.axis[0] == 1 && op_params.axis[1] == 2) ||
|
49
|
-
(op_params.axis[0] == 2 && op_params.axis[1] == 1));
|
50
|
-
TFLITE_CHECK_EQ(output_height, 1);
|
51
|
-
TFLITE_CHECK_EQ(output_width, 1);
|
52
|
-
|
53
|
-
static constexpr int32_t kMinInt = std::numeric_limits<integer_type>::min();
|
54
|
-
static constexpr int32_t kMaxInt = std::numeric_limits<integer_type>::max();
|
55
|
-
|
56
|
-
for (int out_b = 0; out_b < output_batch; ++out_b) {
|
57
|
-
for (int out_d = 0; out_d < output_depth; ++out_d) {
|
58
|
-
int32_t acc = 0;
|
59
|
-
for (int in_h = 0; in_h < input_height; ++in_h) {
|
60
|
-
for (int in_w = 0; in_w < input_width; ++in_w) {
|
61
|
-
acc += input_data[Offset(input_shape, out_b, in_h, in_w, out_d)] -
|
62
|
-
input_zero_point;
|
63
|
-
}
|
64
|
-
}
|
65
|
-
acc = MultiplyByQuantizedMultiplier(acc, multiplier, shift);
|
66
|
-
acc = acc > 0 ? (acc + num_elements_in_axis / 2) / num_elements_in_axis
|
67
|
-
: (acc - num_elements_in_axis / 2) / num_elements_in_axis;
|
68
|
-
acc += output_zero_point;
|
69
|
-
acc = std::min(std::max(acc, kMinInt), kMaxInt);
|
70
|
-
output_data[Offset(output_shape, out_b, 0, 0, out_d)] =
|
71
|
-
static_cast<integer_type>(acc);
|
72
|
-
}
|
73
|
-
}
|
74
|
-
}
|
75
|
-
|
76
|
-
} // namespace reference_integer_ops
|
77
|
-
} // namespace tflite
|
78
|
-
|
79
18
|
#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_MEAN_H_
|
@@ -24,6 +24,9 @@ limitations under the License.
|
|
24
24
|
namespace tflite {
|
25
25
|
namespace reference_integer_ops {
|
26
26
|
|
27
|
+
// Maximum dimension supported by the broadcast mul operation.
|
28
|
+
constexpr int kMaxMulBroadcastDim = 6;
|
29
|
+
|
27
30
|
template <typename InputType, typename OutputType>
|
28
31
|
void MulElementwise(int size, const ArithmeticParams& params,
|
29
32
|
const InputType* input1_data, const InputType* input2_data,
|
@@ -88,46 +91,104 @@ inline void Mul(const ArithmeticParams& params,
|
|
88
91
|
}
|
89
92
|
|
90
93
|
template <typename T>
|
91
|
-
inline void
|
94
|
+
inline void BroadcastMul6DSlow(
|
92
95
|
const ArithmeticParams& params, const RuntimeShape& input1_shape,
|
93
96
|
const T* input1_data, const RuntimeShape& input2_shape,
|
94
97
|
const T* input2_data, const RuntimeShape& output_shape, T* output_data) {
|
95
|
-
ruy::profiler::ScopeLabel label("
|
98
|
+
ruy::profiler::ScopeLabel label("BroadcastMul6DSlow");
|
96
99
|
|
97
|
-
NdArrayDesc<
|
98
|
-
NdArrayDesc<
|
100
|
+
NdArrayDesc<kMaxMulBroadcastDim> desc1;
|
101
|
+
NdArrayDesc<kMaxMulBroadcastDim> desc2;
|
99
102
|
// The input shapes are extended as part of NdArrayDesc initialization.
|
100
103
|
NdArrayDescsForElementwiseBroadcast(input1_shape, input2_shape, &desc1,
|
101
104
|
&desc2);
|
102
105
|
const RuntimeShape extended_output_shape =
|
103
|
-
RuntimeShape::ExtendedShape(
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
106
|
+
RuntimeShape::ExtendedShape(kMaxMulBroadcastDim, output_shape);
|
107
|
+
// Cache output shape dimensions.
|
108
|
+
int32_t extended_output_shape_dims[kMaxMulBroadcastDim];
|
109
|
+
std::memcpy(extended_output_shape_dims, extended_output_shape.DimsData(),
|
110
|
+
sizeof(extended_output_shape_dims));
|
111
|
+
|
112
|
+
size_t input1_offset_a = 0;
|
113
|
+
size_t input2_offset_a = 0;
|
114
|
+
size_t output_offset_a = 0;
|
115
|
+
for (int a = 0; a < extended_output_shape_dims[0]; ++a) {
|
116
|
+
size_t input1_offset_d = input1_offset_a;
|
117
|
+
size_t input2_offset_d = input2_offset_a;
|
118
|
+
size_t output_offset_d = output_offset_a;
|
119
|
+
for (int d = 0; d < extended_output_shape_dims[1]; ++d) {
|
120
|
+
size_t input1_offset_b = input1_offset_d;
|
121
|
+
size_t input2_offset_b = input2_offset_d;
|
122
|
+
size_t output_offset_b = output_offset_d;
|
123
|
+
for (int b = 0; b < extended_output_shape_dims[2]; ++b) {
|
124
|
+
size_t input1_offset_y = input1_offset_b;
|
125
|
+
size_t input2_offset_y = input2_offset_b;
|
126
|
+
size_t output_offset_y = output_offset_b;
|
127
|
+
for (int y = 0; y < extended_output_shape_dims[3]; ++y) {
|
128
|
+
size_t input1_offset_x = input1_offset_y;
|
129
|
+
size_t input2_offset_x = input2_offset_y;
|
130
|
+
size_t output_offset_x = output_offset_y;
|
131
|
+
for (int x = 0; x < extended_output_shape_dims[4]; ++x) {
|
132
|
+
size_t input1_offset_c = input1_offset_x;
|
133
|
+
size_t input2_offset_c = input2_offset_x;
|
134
|
+
size_t output_offset_c = output_offset_x;
|
135
|
+
for (int c = 0; c < extended_output_shape_dims[5]; ++c) {
|
136
|
+
const int32_t input1_val =
|
137
|
+
params.input1_offset + input1_data[input1_offset_c];
|
138
|
+
const int32_t input2_val =
|
139
|
+
params.input2_offset + input2_data[input2_offset_c];
|
140
|
+
const int32_t unclamped_result =
|
141
|
+
params.output_offset +
|
142
|
+
MultiplyByQuantizedMultiplier(input1_val * input2_val,
|
143
|
+
params.output_multiplier,
|
144
|
+
params.output_shift);
|
145
|
+
const int32_t clamped_output = std::min(
|
146
|
+
params.quantized_activation_max,
|
147
|
+
std::max(params.quantized_activation_min, unclamped_result));
|
148
|
+
output_data[output_offset_c] = static_cast<T>(clamped_output);
|
149
|
+
input1_offset_c += desc1.strides[5];
|
150
|
+
input2_offset_c += desc2.strides[5];
|
151
|
+
++output_offset_c;
|
152
|
+
}
|
153
|
+
input1_offset_x += desc1.strides[4];
|
154
|
+
input2_offset_x += desc2.strides[4];
|
155
|
+
output_offset_x += extended_output_shape_dims[5];
|
156
|
+
}
|
157
|
+
input1_offset_y += desc1.strides[3];
|
158
|
+
input2_offset_y += desc2.strides[3];
|
159
|
+
output_offset_y +=
|
160
|
+
extended_output_shape_dims[4] * extended_output_shape_dims[5];
|
125
161
|
}
|
162
|
+
input1_offset_b += desc1.strides[2];
|
163
|
+
input2_offset_b += desc2.strides[2];
|
164
|
+
output_offset_b += extended_output_shape_dims[3] *
|
165
|
+
extended_output_shape_dims[4] *
|
166
|
+
extended_output_shape_dims[5];
|
126
167
|
}
|
168
|
+
input1_offset_d += desc1.strides[1];
|
169
|
+
input2_offset_d += desc2.strides[1];
|
170
|
+
output_offset_d +=
|
171
|
+
extended_output_shape_dims[2] * extended_output_shape_dims[3] *
|
172
|
+
extended_output_shape_dims[4] * extended_output_shape_dims[5];
|
127
173
|
}
|
174
|
+
input1_offset_a += desc1.strides[0];
|
175
|
+
input2_offset_a += desc2.strides[0];
|
176
|
+
output_offset_a +=
|
177
|
+
extended_output_shape_dims[1] * extended_output_shape_dims[2] *
|
178
|
+
extended_output_shape_dims[3] * extended_output_shape_dims[4] *
|
179
|
+
extended_output_shape_dims[5];
|
128
180
|
}
|
129
181
|
}
|
130
182
|
|
183
|
+
template <typename T>
|
184
|
+
inline void BroadcastMul4DSlow(
|
185
|
+
const ArithmeticParams& params, const RuntimeShape& input1_shape,
|
186
|
+
const T* input1_data, const RuntimeShape& input2_shape,
|
187
|
+
const T* input2_data, const RuntimeShape& output_shape, T* output_data) {
|
188
|
+
BroadcastMul6DSlow(params, input1_shape, input1_data, input2_shape,
|
189
|
+
input2_data, output_shape, output_data);
|
190
|
+
}
|
191
|
+
|
131
192
|
} // namespace reference_integer_ops
|
132
193
|
} // namespace tflite
|
133
194
|
#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_MUL_H_
|