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.
- xmos_ai_tools/__init__.py +7 -0
- xmos_ai_tools/io_server/__init__.py +151 -0
- xmos_ai_tools/runtime/__init__.py +0 -0
- xmos_ai_tools/runtime/buildfiles/aitoolslib.cmake +13 -0
- xmos_ai_tools/runtime/buildfiles/aitoolslib.make +8 -0
- xmos_ai_tools/runtime/include/flash_server.h +74 -0
- xmos_ai_tools/runtime/include/flatbuffers/allocator.h +68 -0
- xmos_ai_tools/runtime/include/flatbuffers/array.h +243 -0
- xmos_ai_tools/runtime/include/flatbuffers/base.h +474 -0
- xmos_ai_tools/runtime/include/flatbuffers/bfbs_generator.h +43 -0
- xmos_ai_tools/runtime/include/flatbuffers/buffer.h +142 -0
- xmos_ai_tools/runtime/include/flatbuffers/buffer_ref.h +53 -0
- xmos_ai_tools/runtime/include/flatbuffers/code_generators.h +235 -0
- xmos_ai_tools/runtime/include/flatbuffers/default_allocator.h +64 -0
- xmos_ai_tools/runtime/include/flatbuffers/detached_buffer.h +114 -0
- xmos_ai_tools/runtime/include/flatbuffers/flatbuffer_builder.h +1197 -0
- xmos_ai_tools/runtime/include/flatbuffers/flatbuffers.h +270 -0
- xmos_ai_tools/runtime/include/flatbuffers/flatc.h +111 -0
- xmos_ai_tools/runtime/include/flatbuffers/flexbuffers.h +1897 -0
- xmos_ai_tools/runtime/include/flatbuffers/grpc.h +300 -0
- xmos_ai_tools/runtime/include/flatbuffers/hash.h +127 -0
- xmos_ai_tools/runtime/include/flatbuffers/idl.h +1232 -0
- xmos_ai_tools/runtime/include/flatbuffers/minireflect.h +419 -0
- xmos_ai_tools/runtime/include/flatbuffers/pch/flatc_pch.h +39 -0
- xmos_ai_tools/runtime/include/flatbuffers/pch/pch.h +38 -0
- xmos_ai_tools/runtime/include/flatbuffers/reflection.h +502 -0
- xmos_ai_tools/runtime/include/flatbuffers/reflection_generated.h +1449 -0
- xmos_ai_tools/runtime/include/flatbuffers/registry.h +128 -0
- xmos_ai_tools/runtime/include/flatbuffers/stl_emulation.h +509 -0
- xmos_ai_tools/runtime/include/flatbuffers/string.h +64 -0
- xmos_ai_tools/runtime/include/flatbuffers/struct.h +53 -0
- xmos_ai_tools/runtime/include/flatbuffers/table.h +168 -0
- xmos_ai_tools/runtime/include/flatbuffers/util.h +690 -0
- xmos_ai_tools/runtime/include/flatbuffers/vector.h +370 -0
- xmos_ai_tools/runtime/include/flatbuffers/vector_downward.h +271 -0
- xmos_ai_tools/runtime/include/flatbuffers/verifier.h +283 -0
- xmos_ai_tools/runtime/include/ioserver.h +44 -0
- xmos_ai_tools/runtime/include/lib_nn/api/TransposeConv.h +24 -0
- xmos_ai_tools/runtime/include/lib_nn/api/add_int16.h +27 -0
- xmos_ai_tools/runtime/include/lib_nn/api/add_int16_transform.h +42 -0
- xmos_ai_tools/runtime/include/lib_nn/api/dequantize_int16.h +22 -0
- xmos_ai_tools/runtime/include/lib_nn/api/dequantize_int16_transform.h +34 -0
- xmos_ai_tools/runtime/include/lib_nn/api/expand_8_to_16.h +8 -0
- xmos_ai_tools/runtime/include/lib_nn/api/multiply_int16.h +42 -0
- xmos_ai_tools/runtime/include/lib_nn/api/multiply_int16_transform.h +71 -0
- xmos_ai_tools/runtime/include/lib_nn/api/nn_api.h +15 -0
- xmos_ai_tools/runtime/include/lib_nn/api/nn_bin_types.h +14 -0
- xmos_ai_tools/runtime/include/lib_nn/api/nn_config.h +287 -0
- xmos_ai_tools/runtime/include/lib_nn/api/nn_conv2d_structs.h +72 -0
- xmos_ai_tools/runtime/include/lib_nn/api/nn_image.h +26 -0
- xmos_ai_tools/runtime/include/lib_nn/api/nn_layers.h +303 -0
- xmos_ai_tools/runtime/include/lib_nn/api/nn_op_helper.h +132 -0
- xmos_ai_tools/runtime/include/lib_nn/api/nn_op_utils.h +150 -0
- xmos_ai_tools/runtime/include/lib_nn/api/nn_operator.h +18 -0
- xmos_ai_tools/runtime/include/lib_nn/api/nn_pooling.h +551 -0
- xmos_ai_tools/runtime/include/lib_nn/api/nn_types.h +83 -0
- xmos_ai_tools/runtime/include/lib_nn/api/nn_window_params.h +55 -0
- xmos_ai_tools/runtime/include/lib_nn/api/output_transform_fn_int16.h +54 -0
- xmos_ai_tools/runtime/include/lib_nn/api/output_transform_fn_int16_kernel_transform.h +37 -0
- xmos_ai_tools/runtime/include/lib_nn/api/output_transform_fn_int16_mappings.h +13 -0
- xmos_ai_tools/runtime/include/lib_nn/api/quadratic_approximation.h +82 -0
- xmos_ai_tools/runtime/include/lib_nn/api/quadratic_interpolation.h +23 -0
- xmos_ai_tools/runtime/include/lib_nn/api/quantize_int16.h +22 -0
- xmos_ai_tools/runtime/include/lib_nn/api/quantize_int16_transform.h +33 -0
- xmos_ai_tools/runtime/include/lib_nn/api/version.h +13 -0
- xmos_ai_tools/runtime/include/lib_nn/api/vpu_memmove_word_aligned.h +15 -0
- xmos_ai_tools/runtime/include/lib_nn/api/vpu_memset_256.h +55 -0
- xmos_ai_tools/runtime/include/lib_nn/api/vpu_sim.h +118 -0
- xmos_ai_tools/runtime/include/lib_nn/api/xs3_vpu.h +216 -0
- xmos_ai_tools/runtime/include/lib_nn/api/xs3a_registers.h +2869 -0
- xmos_ai_tools/runtime/include/lib_nn/src/asm/asm_constants.h +41 -0
- xmos_ai_tools/runtime/include/lib_nn/src/asm/window_op_plan.h +25 -0
- xmos_ai_tools/runtime/include/lib_tflite_micro/api/fast_flash.h +47 -0
- xmos_ai_tools/runtime/include/lib_tflite_micro/api/inference_engine.h +218 -0
- xmos_ai_tools/runtime/include/lib_tflite_micro/api/memory_parallel_transport.h +52 -0
- xmos_ai_tools/runtime/include/lib_tflite_micro/api/version.h +13 -0
- xmos_ai_tools/runtime/include/lib_tflite_micro/api/xcore_config.h +17 -0
- xmos_ai_tools/runtime/include/lib_tflite_micro/api/xcore_device_memory.h +62 -0
- xmos_ai_tools/runtime/include/lib_tflite_micro/api/xcore_shared_config.h +31 -0
- xmos_ai_tools/runtime/include/lib_tflite_micro/src/tflite-xcore-kernels/conv2d_float.h +155 -0
- xmos_ai_tools/runtime/include/lib_tflite_micro/src/tflite-xcore-kernels/xcore_common.h +19 -0
- xmos_ai_tools/runtime/include/lib_tflite_micro/src/tflite-xcore-kernels/xcore_custom_options.h +28 -0
- xmos_ai_tools/runtime/include/lib_tflite_micro/src/tflite-xcore-kernels/xcore_error_reporter.h +32 -0
- xmos_ai_tools/runtime/include/lib_tflite_micro/src/tflite-xcore-kernels/xcore_interpreter.h +49 -0
- xmos_ai_tools/runtime/include/lib_tflite_micro/src/tflite-xcore-kernels/xcore_ops.h +71 -0
- xmos_ai_tools/runtime/include/lib_tflite_micro/src/tflite-xcore-kernels/xcore_profiler.h +49 -0
- xmos_ai_tools/runtime/include/lib_tflite_micro/src/tflite-xcore-kernels/xcore_utils.h +160 -0
- xmos_ai_tools/runtime/include/lib_tflite_micro/src/thread_call.h +119 -0
- xmos_ai_tools/runtime/include/lib_xud/lib_xud/api/legacy/usb_defs.h +4 -0
- xmos_ai_tools/runtime/include/lib_xud/lib_xud/api/legacy/usb_device.h +4 -0
- xmos_ai_tools/runtime/include/lib_xud/lib_xud/api/legacy/usb_std_descriptors.h +4 -0
- xmos_ai_tools/runtime/include/lib_xud/lib_xud/api/legacy/usb_std_requests.h +4 -0
- xmos_ai_tools/runtime/include/lib_xud/lib_xud/api/xud.h +518 -0
- xmos_ai_tools/runtime/include/lib_xud/lib_xud/api/xud_conf_default.h +11 -0
- xmos_ai_tools/runtime/include/lib_xud/lib_xud/api/xud_device.h +87 -0
- xmos_ai_tools/runtime/include/lib_xud/lib_xud/api/xud_std_descriptors.h +191 -0
- xmos_ai_tools/runtime/include/lib_xud/lib_xud/api/xud_std_requests.h +120 -0
- xmos_ai_tools/runtime/include/lib_xud/lib_xud/src/user/XUD_USB_Defines.h +70 -0
- xmos_ai_tools/runtime/include/lib_xud/lib_xud/src/user/class/hid.h +23 -0
- xmos_ai_tools/runtime/include/lib_xud/lib_xud/src/user/class/usbaudio10.h +30 -0
- xmos_ai_tools/runtime/include/lib_xud/lib_xud/src/user/class/usbaudio20.h +357 -0
- xmos_ai_tools/runtime/include/lib_xud/lib_xud/src/user/class/usbaudiocommon.h +168 -0
- xmos_ai_tools/runtime/include/signal/micro/kernels/delay_flexbuffers_generated_data.h +25 -0
- 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/signal/micro/kernels/irfft.h +31 -0
- 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/signal/src/filter_bank_square_root.h +34 -0
- 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/signal/src/log.h +30 -0
- xmos_ai_tools/runtime/include/signal/src/max_abs.h +31 -0
- xmos_ai_tools/runtime/include/signal/src/msb.h +32 -0
- 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/signal/src/window.h +31 -0
- 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_op_data.h +22 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/builtin_ops.h +241 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/c/builtin_op_data.h +20 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/c/c_api_types.h +26 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/c/common.h +30 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/context_util.h +54 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/core/api/error_reporter.h +72 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/core/api/flatbuffer_conversions.h +440 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/core/api/tensor_utils.h +28 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/core/c/builtin_op_data.h +626 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/core/c/c_api_types.h +178 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/core/c/common.h +1496 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/core/macros.h +78 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/bits.h +102 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/fft.h +50 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/fft_io.h +34 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/fft_util.h +34 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/filterbank.h +63 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/filterbank_io.h +35 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/filterbank_util.h +50 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/frontend.h +64 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/frontend_io.h +31 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/frontend_util.h +52 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/kiss_fft_common.h +48 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/kiss_fft_int16.h +33 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/log_lut.h +40 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/log_scale.h +39 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/log_scale_io.h +33 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/log_scale_util.h +45 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/noise_reduction.h +46 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_io.h +36 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_util.h +50 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.h +47 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control_util.h +57 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/window.h +49 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/window_io.h +34 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/experimental/microfrontend/lib/window_util.h +45 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/common.h +1358 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/compatibility.h +122 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/cppmath.h +40 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/max.h +35 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/min.h +35 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/optimized/neon_check.h +20 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/portable_tensor.h +141 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/portable_tensor_utils.h +623 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/quantization_util.h +292 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/add.h +561 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/add_n.h +86 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/arg_min_max.h +88 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/batch_matmul.h +275 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/batch_to_space_nd.h +101 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/binary_function.h +91 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/broadcast_args.h +56 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/broadcast_to.h +97 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/ceil.h +37 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/comparisons.h +271 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/concatenation.h +141 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/conv.h +289 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/cumsum.h +175 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/depth_to_space.h +79 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/depthwiseconv_float.h +100 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/depthwiseconv_uint8.h +319 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/dequantize.h +78 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/div.h +247 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/elu.h +37 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/exp.h +38 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/fill.h +38 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/floor.h +39 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/floor_div.h +35 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/floor_mod.h +44 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/fully_connected.h +323 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/hard_swish.h +168 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/add.h +250 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/conv.h +241 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/depthwise_conv.h +291 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/fully_connected.h +126 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/l2normalization.h +67 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/logistic.h +121 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/mean.h +18 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/mul.h +194 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/pooling.h +264 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/tanh.h +117 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/transpose_conv.h +224 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/l2normalization.h +90 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/leaky_relu.h +69 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/log_softmax.h +256 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/logistic.h +132 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/lstm_cell.h +422 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/maximum_minimum.h +64 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/mul.h +267 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/neg.h +37 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/pad.h +169 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/pooling.h +303 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/portable_tensor_utils.h +333 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/portable_tensor_utils_impl.h +244 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/prelu.h +111 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/process_broadcast_shapes.h +140 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/quantize.h +89 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/reduce.h +491 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/requantize.h +70 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/resize_bilinear.h +233 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/resize_nearest_neighbor.h +102 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/round.h +51 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/select.h +151 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/slice.h +80 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/softmax.h +233 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/space_to_batch_nd.h +109 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/space_to_depth.h +80 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/strided_slice.h +147 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/sub.h +465 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/tanh.h +129 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/transpose.h +203 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/transpose_conv.h +225 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/runtime_shape.h +168 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/strided_slice_logic.h +278 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/tensor_ctypes.h +42 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/types.h +1096 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/kernel_util.h +341 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/op_macros.h +49 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/kernels/padding.h +115 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/arena_allocator/ibuffer_allocator.h +100 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/arena_allocator/non_persistent_arena_buffer_allocator.h +104 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/arena_allocator/persistent_arena_buffer_allocator.h +58 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/arena_allocator/recording_single_arena_buffer_allocator.h +63 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/arena_allocator/single_arena_buffer_allocator.h +144 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/benchmarks/micro_benchmark.h +95 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/compatibility.h +32 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/cortex_m_generic/debug_log_callback.h +49 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/debug_log.h +38 -0
- 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/examples/network_tester/expected_output_data.h +47 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/network_tester/input_data.h +108 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/network_tester/network_model.h +166 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/person_detection/detection_responder.h +32 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/person_detection/image_provider.h +38 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/person_detection/main_functions.h +37 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/examples/person_detection/model_settings.h +35 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/fake_micro_context.h +70 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/flatbuffer_utils.h +65 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/activation_utils.h +57 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/activations.h +64 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/add.h +78 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/arc_mli/mli_function_specializations.h +141 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/arc_mli/mli_interface.h +75 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/arc_mli/mli_slicers.h +56 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/arc_mli/mli_tf_utils.h +310 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/arc_mli/scratch_buf_mgr.h +145 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/arc_mli/scratch_buffers.h +78 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/ceva/ceva_common.h +24 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/ceva/ceva_tflm_lib.h +613 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/ceva/mcps_macros.h +115 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/ceva/types.h +1286 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/circular_buffer.h +45 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/circular_buffer_flexbuffers_generated_data.h +22 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/conv.h +117 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/conv_test.h +94 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/depthwise_conv.h +80 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/dequantize.h +38 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/detection_postprocess_flexbuffers_generated_data.h +25 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/ethosu.h +28 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/fully_connected.h +112 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/hard_swish.h +30 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/kernel_runner.h +86 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/kernel_util.h +150 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/leaky_relu.h +43 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/logical.h +35 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/logistic.h +42 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/lstm_eval.h +541 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/lstm_eval_test.h +817 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/lstm_shared.h +150 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/micro_ops.h +158 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/micro_tensor_utils.h +56 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/mul.h +74 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/pad.h +27 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/pooling.h +142 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/prelu.h +39 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/quantize.h +37 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/reduce.h +65 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/reshape.h +26 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/softmax.h +67 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/strided_slice.h +40 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/sub.h +60 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/svdf.h +100 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/testdata/conv_test_data.h +37 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/testdata/lstm_test_data.h +579 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/unidirectional_sequence_lstm.h +47 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/hifimini/fixedpoint_utils.h +139 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/lstm_eval.h +216 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/lstm_shared.h +78 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa.h +38 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_add.h +48 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_conv.h +89 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_depthwise_conv.h +74 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_fully_connected.h +78 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_pad.h +49 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_pooling.h +76 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_reduce.h +47 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_reshape.h +44 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_softmax.h +58 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/kernels/xtensa/xtensa_svdf.h +39 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/memory_helpers.h +64 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/memory_planner/greedy_memory_planner.h +170 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/memory_planner/linear_memory_planner.h +53 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/memory_planner/memory_plan_struct.h +73 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/memory_planner/micro_memory_planner.h +95 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/memory_planner/non_persistent_buffer_planner_shim.h +133 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_allocation_info.h +138 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_allocator.h +351 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_arena_constants.h +28 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_common.h +38 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_context.h +176 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_graph.h +79 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_interpreter.h +189 -0
- 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 +42 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_mutable_op_resolver.h +708 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_op_resolver.h +62 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_profiler.h +140 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_profiler_interface.h +38 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_resource_variable.h +89 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_time.h +36 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/micro_utils.h +162 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/mock_micro_graph.h +60 -0
- 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/python/tflite_size/src/flatbuffer_size.h +30 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/python/tflite_size/src/flatbuffer_size_wrapper.h +33 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/recording_micro_allocator.h +125 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/recording_micro_interpreter.h +69 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/system_setup.h +27 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/test_helper_custom_ops.h +49 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/test_helpers.h +334 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/testing/micro_test.h +267 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/testing/test_conv_model.h +23 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/tflite_bridge/flatbuffer_conversions_bridge.h +45 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/micro/tflite_bridge/micro_error_reporter.h +36 -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/portable_type_to_tflitetype.h +75 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/schema/schema_generated.h +24644 -0
- xmos_ai_tools/runtime/include/tensorflow/lite/schema/schema_utils.h +33 -0
- xmos_ai_tools/runtime/include/tile_ram_server.h +38 -0
- xmos_ai_tools/runtime/lib/libhost_xtflitemicro.a +0 -0
- xmos_ai_tools/runtime/lib/libxtflitemicro.a +0 -0
- xmos_ai_tools/xformer/__init__.py +60 -0
- xmos_ai_tools/xformer/flash.py +190 -0
- xmos_ai_tools/xinterpreters/__init__.py +1 -0
- xmos_ai_tools/xinterpreters/exceptions.py +38 -0
- xmos_ai_tools/xinterpreters/host_interpreter.py +652 -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.3.2.dev80.data/data/bin/xcore-opt +0 -0
- xmos_ai_tools-1.3.2.dev80.dist-info/METADATA +33 -0
- xmos_ai_tools-1.3.2.dev80.dist-info/RECORD +395 -0
- xmos_ai_tools-1.3.2.dev80.dist-info/WHEEL +5 -0
- xmos_ai_tools-1.3.2.dev80.dist-info/top_level.txt +1 -0
@@ -0,0 +1,88 @@
|
|
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
|
+
#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ARG_MIN_MAX_H_
|
16
|
+
#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ARG_MIN_MAX_H_
|
17
|
+
|
18
|
+
#include <functional>
|
19
|
+
|
20
|
+
#include "tensorflow/lite/kernels/internal/types.h"
|
21
|
+
|
22
|
+
namespace tflite_micro {
|
23
|
+
|
24
|
+
namespace reference_ops {
|
25
|
+
|
26
|
+
template <typename T>
|
27
|
+
std::function<bool(T, T)> GetComparefunction(bool is_arg_max) {
|
28
|
+
if (is_arg_max) {
|
29
|
+
return std::greater<T>();
|
30
|
+
} else {
|
31
|
+
return std::less<T>();
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
template <typename T1, typename T2, typename T3, typename Cmp>
|
36
|
+
void ArgMinMax(const RuntimeShape& input1_shape, const T1* input1_data,
|
37
|
+
const T3* input2_data, const RuntimeShape& output_shape,
|
38
|
+
T2* output_data, const Cmp& cmp) {
|
39
|
+
TFLITE_DCHECK_GT(input1_shape.DimensionsCount(), 0);
|
40
|
+
TFLITE_DCHECK_EQ(input1_shape.DimensionsCount() - 1,
|
41
|
+
output_shape.DimensionsCount());
|
42
|
+
int axis = input2_data[0];
|
43
|
+
if (axis < 0) {
|
44
|
+
axis += input1_shape.DimensionsCount();
|
45
|
+
}
|
46
|
+
const int axis_size = input1_shape.Dims(axis);
|
47
|
+
|
48
|
+
int outer_size = 1;
|
49
|
+
for (int i = 0; i < axis; ++i) {
|
50
|
+
TFLITE_DCHECK_EQ(input1_shape.Dims(i), output_shape.Dims(i));
|
51
|
+
outer_size *= input1_shape.Dims(i);
|
52
|
+
}
|
53
|
+
|
54
|
+
int inner_size = 1;
|
55
|
+
const int dims_count = input1_shape.DimensionsCount();
|
56
|
+
for (int i = axis + 1; i < dims_count; ++i) {
|
57
|
+
TFLITE_DCHECK_EQ(input1_shape.Dims(i), output_shape.Dims(i - 1));
|
58
|
+
inner_size *= input1_shape.Dims(i);
|
59
|
+
}
|
60
|
+
for (int outer = 0; outer < outer_size; ++outer) {
|
61
|
+
for (int inner = 0; inner < inner_size; ++inner) {
|
62
|
+
auto min_max_value = input1_data[outer * axis_size * inner_size + inner];
|
63
|
+
T2 min_max_index = 0;
|
64
|
+
for (int i = 1; i < axis_size; ++i) {
|
65
|
+
const auto& curr_value =
|
66
|
+
input1_data[(outer * axis_size + i) * inner_size + inner];
|
67
|
+
if (cmp(curr_value, min_max_value)) {
|
68
|
+
min_max_value = curr_value;
|
69
|
+
min_max_index = static_cast<T2>(i);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
output_data[outer * inner_size + inner] = min_max_index;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
template <typename T1, typename T2, typename T3>
|
78
|
+
void ArgMinMax(const RuntimeShape& input1_shape, const T1* input1_data,
|
79
|
+
const T3* input2_data, const RuntimeShape& output_shape,
|
80
|
+
T2* output_data, const bool is_arg_max) {
|
81
|
+
ArgMinMax(input1_shape, input1_data, input2_data, output_shape, output_data,
|
82
|
+
GetComparefunction<T1>(is_arg_max));
|
83
|
+
}
|
84
|
+
|
85
|
+
} // namespace reference_ops
|
86
|
+
} // namespace tflite_micro
|
87
|
+
|
88
|
+
#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ARG_MIN_MAX_H_
|
@@ -0,0 +1,275 @@
|
|
1
|
+
/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
14
|
+
==============================================================================*/
|
15
|
+
#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BATCH_MATMUL_H_
|
16
|
+
#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BATCH_MATMUL_H_
|
17
|
+
|
18
|
+
#include <algorithm>
|
19
|
+
#include <cstdint>
|
20
|
+
|
21
|
+
#include "tensorflow/lite/kernels/internal/common.h"
|
22
|
+
#include "tensorflow/lite/kernels/internal/compatibility.h"
|
23
|
+
#include "tensorflow/lite/kernels/internal/portable_tensor_utils.h"
|
24
|
+
#include "tensorflow/lite/kernels/internal/types.h"
|
25
|
+
|
26
|
+
namespace tflite_micro {
|
27
|
+
namespace reference_ops {
|
28
|
+
namespace batch_matmul {
|
29
|
+
|
30
|
+
// Determine which dimension is the broadcast dimension.
|
31
|
+
inline int broadcast_dim(int lhs_dim, int rhs_dim) {
|
32
|
+
if (lhs_dim == rhs_dim) return lhs_dim;
|
33
|
+
if (lhs_dim == 1) return rhs_dim;
|
34
|
+
TFLITE_DCHECK_EQ(rhs_dim, 1);
|
35
|
+
return lhs_dim;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Compute the "extent" for iterating on this dimension.
|
39
|
+
// If we are broadcasting, then don't advance (i.e return 0).
|
40
|
+
inline int extent(const RuntimeShape& shape, int x) {
|
41
|
+
if (shape.Dims(x) == 1) {
|
42
|
+
return 0;
|
43
|
+
}
|
44
|
+
int prod = 1;
|
45
|
+
for (int i = x + 1; i < shape.DimensionsCount(); ++i) {
|
46
|
+
prod *= shape.Dims(i);
|
47
|
+
}
|
48
|
+
return prod;
|
49
|
+
}
|
50
|
+
|
51
|
+
} // namespace batch_matmul
|
52
|
+
|
53
|
+
template <typename Ta, typename Tb, typename Tout>
|
54
|
+
inline void BatchMatMul(const RuntimeShape& lhs_shape, const Ta* lhs_data,
|
55
|
+
const RuntimeShape& rhs_shape, const Tb* rhs_data,
|
56
|
+
const RuntimeShape& output_shape, Tout* output_data) {
|
57
|
+
const RuntimeShape extended_lhs_shape =
|
58
|
+
RuntimeShape::ExtendedShape(5, lhs_shape);
|
59
|
+
const RuntimeShape extended_rhs_shape =
|
60
|
+
RuntimeShape::ExtendedShape(5, rhs_shape);
|
61
|
+
|
62
|
+
const int batch_dim0 = batch_matmul::broadcast_dim(
|
63
|
+
extended_lhs_shape.Dims(0), extended_rhs_shape.Dims(0));
|
64
|
+
const int batch_dim1 = batch_matmul::broadcast_dim(
|
65
|
+
extended_lhs_shape.Dims(1), extended_rhs_shape.Dims(1));
|
66
|
+
const int batch_dim2 = batch_matmul::broadcast_dim(
|
67
|
+
extended_lhs_shape.Dims(2), extended_rhs_shape.Dims(2));
|
68
|
+
|
69
|
+
const int lhs_ext0 = batch_matmul::extent(extended_lhs_shape, 0);
|
70
|
+
const int lhs_ext1 = batch_matmul::extent(extended_lhs_shape, 1);
|
71
|
+
const int lhs_ext2 = batch_matmul::extent(extended_lhs_shape, 2);
|
72
|
+
const int rhs_ext0 = batch_matmul::extent(extended_rhs_shape, 0);
|
73
|
+
const int rhs_ext1 = batch_matmul::extent(extended_rhs_shape, 1);
|
74
|
+
const int rhs_ext2 = batch_matmul::extent(extended_rhs_shape, 2);
|
75
|
+
|
76
|
+
// Set params for each matrix multiply.
|
77
|
+
const int lhs_rows = extended_lhs_shape.Dims(3);
|
78
|
+
const int rhs_cols = extended_rhs_shape.Dims(4);
|
79
|
+
const int accum_depth = extended_lhs_shape.Dims(4);
|
80
|
+
|
81
|
+
for (int b0 = 0; b0 < batch_dim0; ++b0) {
|
82
|
+
const Ta* lhs_ptr0 = lhs_data + (b0 * lhs_ext0);
|
83
|
+
const Tb* rhs_ptr0 = rhs_data + (b0 * rhs_ext0);
|
84
|
+
for (int b1 = 0; b1 < batch_dim1; ++b1) {
|
85
|
+
const Ta* lhs_ptr1 = lhs_ptr0 + b1 * lhs_ext1;
|
86
|
+
const Tb* rhs_ptr1 = rhs_ptr0 + b1 * rhs_ext1;
|
87
|
+
for (int b2 = 0; b2 < batch_dim2; ++b2) {
|
88
|
+
const Ta* lhs_ptr2 = lhs_ptr1 + b2 * lhs_ext2;
|
89
|
+
const Tb* rhs_ptr2 = rhs_ptr1 + b2 * rhs_ext2;
|
90
|
+
Tout* out_ptr = output_data + ((b0 * batch_dim1 * batch_dim2) +
|
91
|
+
b1 * batch_dim2 + b2) *
|
92
|
+
lhs_rows * rhs_cols;
|
93
|
+
for (int j = 0; j < rhs_cols; ++j) {
|
94
|
+
for (int i = 0; i < lhs_rows; ++i) {
|
95
|
+
Tout total = 0;
|
96
|
+
for (int k = 0; k < accum_depth; ++k) {
|
97
|
+
total += static_cast<Tout>(lhs_ptr2[accum_depth * i + k]) *
|
98
|
+
static_cast<Tout>(rhs_ptr2[j * accum_depth + k]);
|
99
|
+
}
|
100
|
+
int idx = lhs_rows * j + i;
|
101
|
+
out_ptr[idx] = total;
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}
|
105
|
+
}
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
inline void BatchMatMul(const RuntimeShape& lhs_shape, const int8_t* lhs_data,
|
110
|
+
const RuntimeShape& rhs_shape, const int8_t* rhs_data,
|
111
|
+
const float* scaling_factors,
|
112
|
+
const int32_t* input_offset, int32_t* row_sums,
|
113
|
+
const RuntimeShape& output_shape, float* output_data,
|
114
|
+
bool* compute_row_sums) {
|
115
|
+
const RuntimeShape extended_lhs_shape =
|
116
|
+
RuntimeShape::ExtendedShape(5, lhs_shape);
|
117
|
+
const RuntimeShape extended_rhs_shape =
|
118
|
+
RuntimeShape::ExtendedShape(5, rhs_shape);
|
119
|
+
|
120
|
+
const int batch_dim0 = batch_matmul::broadcast_dim(
|
121
|
+
extended_lhs_shape.Dims(0), extended_rhs_shape.Dims(0));
|
122
|
+
const int batch_dim1 = batch_matmul::broadcast_dim(
|
123
|
+
extended_lhs_shape.Dims(1), extended_rhs_shape.Dims(1));
|
124
|
+
const int batch_dim2 = batch_matmul::broadcast_dim(
|
125
|
+
extended_lhs_shape.Dims(2), extended_rhs_shape.Dims(2));
|
126
|
+
|
127
|
+
const int lhs_ext0 = batch_matmul::extent(extended_lhs_shape, 0);
|
128
|
+
const int lhs_ext1 = batch_matmul::extent(extended_lhs_shape, 1);
|
129
|
+
const int lhs_ext2 = batch_matmul::extent(extended_lhs_shape, 2);
|
130
|
+
const int rhs_ext0 = batch_matmul::extent(extended_rhs_shape, 0);
|
131
|
+
const int rhs_ext1 = batch_matmul::extent(extended_rhs_shape, 1);
|
132
|
+
const int rhs_ext2 = batch_matmul::extent(extended_rhs_shape, 2);
|
133
|
+
|
134
|
+
// Set params for each matrix multiply.
|
135
|
+
const int lhs_rows = extended_lhs_shape.Dims(3);
|
136
|
+
const int rhs_cols = extended_rhs_shape.Dims(4);
|
137
|
+
const int accum_depth = extended_lhs_shape.Dims(4);
|
138
|
+
|
139
|
+
const int ioff_ext0 = rhs_ext0 == 0 ? 0 : rhs_cols;
|
140
|
+
const int ioff_ext1 = rhs_ext1 == 0 ? 0 : rhs_cols;
|
141
|
+
const int ioff_ext2 = rhs_ext2 == 0 ? 0 : rhs_cols;
|
142
|
+
const int woff_ext0 = lhs_ext0 == 0 ? 0 : lhs_rows;
|
143
|
+
const int woff_ext1 = lhs_ext1 == 0 ? 0 : lhs_rows;
|
144
|
+
const int woff_ext2 = lhs_ext2 == 0 ? 0 : lhs_rows;
|
145
|
+
|
146
|
+
if (!compute_row_sums || *compute_row_sums) {
|
147
|
+
int num_weights_matrices = 1;
|
148
|
+
for (int i = 1; i < extended_lhs_shape.DimensionsCount() - 2; ++i) {
|
149
|
+
num_weights_matrices *= extended_lhs_shape.Dims(i);
|
150
|
+
}
|
151
|
+
tensor_utils::ReductionSumVector(
|
152
|
+
lhs_data, row_sums, num_weights_matrices * lhs_rows, accum_depth);
|
153
|
+
if (compute_row_sums) {
|
154
|
+
*compute_row_sums = false;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
for (int b0 = 0; b0 < batch_dim0; ++b0) {
|
159
|
+
const int8_t* lhs_ptr0 = lhs_data + (b0 * lhs_ext0);
|
160
|
+
const int8_t* rhs_ptr0 = rhs_data + (b0 * rhs_ext0);
|
161
|
+
const int32_t* ioff_ptr0 = input_offset + (b0 * ioff_ext0);
|
162
|
+
const float* scale_ptr0 = scaling_factors + (b0 * ioff_ext0);
|
163
|
+
const int32_t* woff_ptr0 = row_sums + (b0 * woff_ext0);
|
164
|
+
for (int b1 = 0; b1 < batch_dim1; ++b1) {
|
165
|
+
const int8_t* lhs_ptr1 = lhs_ptr0 + b1 * lhs_ext1;
|
166
|
+
const int8_t* rhs_ptr1 = rhs_ptr0 + b1 * rhs_ext1;
|
167
|
+
const int32_t* ioff_ptr1 = ioff_ptr0 + (b1 * ioff_ext1);
|
168
|
+
const float* scale_ptr1 = scale_ptr0 + (b1 * ioff_ext1);
|
169
|
+
const int32_t* woff_ptr1 = woff_ptr0 + (b1 * woff_ext1);
|
170
|
+
for (int b2 = 0; b2 < batch_dim2; ++b2) {
|
171
|
+
const int8_t* lhs_ptr2 = lhs_ptr1 + b2 * lhs_ext2;
|
172
|
+
const int8_t* rhs_ptr2 = rhs_ptr1 + b2 * rhs_ext2;
|
173
|
+
const int32_t* ioff_ptr2 = ioff_ptr1 + (b2 * ioff_ext2);
|
174
|
+
const float* scale_ptr2 = scale_ptr1 + (b2 * ioff_ext2);
|
175
|
+
const int32_t* woff_ptr2 = woff_ptr1 + (b2 * woff_ext2);
|
176
|
+
float* out_ptr = output_data + ((b0 * batch_dim1 * batch_dim2) +
|
177
|
+
b1 * batch_dim2 + b2) *
|
178
|
+
lhs_rows * rhs_cols;
|
179
|
+
for (int j = 0; j < rhs_cols; ++j) {
|
180
|
+
const float batch_scaling_factor = scale_ptr2[j];
|
181
|
+
const float batch_offset = static_cast<float>(ioff_ptr2[j]);
|
182
|
+
for (int i = 0; i < lhs_rows; ++i) {
|
183
|
+
int32_t total = 0;
|
184
|
+
for (int k = 0; k < accum_depth; ++k) {
|
185
|
+
total +=
|
186
|
+
lhs_ptr2[accum_depth * i + k] * rhs_ptr2[j * accum_depth + k];
|
187
|
+
}
|
188
|
+
int32_t row_sum = woff_ptr2[i];
|
189
|
+
total -= row_sum * batch_offset;
|
190
|
+
int idx = lhs_rows * j + i;
|
191
|
+
out_ptr[idx] += batch_scaling_factor * total;
|
192
|
+
}
|
193
|
+
}
|
194
|
+
}
|
195
|
+
}
|
196
|
+
}
|
197
|
+
}
|
198
|
+
|
199
|
+
template <typename T, typename AccumT>
|
200
|
+
inline void BatchMatMul(const FullyConnectedParams& params,
|
201
|
+
const RuntimeShape& lhs_shape, const T* lhs_data,
|
202
|
+
const RuntimeShape& rhs_shape, const T* rhs_data,
|
203
|
+
const RuntimeShape& output_shape, T* output_data) {
|
204
|
+
const RuntimeShape extended_lhs_shape =
|
205
|
+
RuntimeShape::ExtendedShape(5, lhs_shape);
|
206
|
+
const RuntimeShape extended_rhs_shape =
|
207
|
+
RuntimeShape::ExtendedShape(5, rhs_shape);
|
208
|
+
|
209
|
+
const int batch_dim0 = batch_matmul::broadcast_dim(
|
210
|
+
extended_lhs_shape.Dims(0), extended_rhs_shape.Dims(0));
|
211
|
+
const int batch_dim1 = batch_matmul::broadcast_dim(
|
212
|
+
extended_lhs_shape.Dims(1), extended_rhs_shape.Dims(1));
|
213
|
+
const int batch_dim2 = batch_matmul::broadcast_dim(
|
214
|
+
extended_lhs_shape.Dims(2), extended_rhs_shape.Dims(2));
|
215
|
+
|
216
|
+
const int lhs_ext0 = batch_matmul::extent(extended_lhs_shape, 0);
|
217
|
+
const int lhs_ext1 = batch_matmul::extent(extended_lhs_shape, 1);
|
218
|
+
const int lhs_ext2 = batch_matmul::extent(extended_lhs_shape, 2);
|
219
|
+
const int rhs_ext0 = batch_matmul::extent(extended_rhs_shape, 0);
|
220
|
+
const int rhs_ext1 = batch_matmul::extent(extended_rhs_shape, 1);
|
221
|
+
const int rhs_ext2 = batch_matmul::extent(extended_rhs_shape, 2);
|
222
|
+
|
223
|
+
// Set params for each matrix multiply.
|
224
|
+
const int lhs_rows = extended_lhs_shape.Dims(3);
|
225
|
+
const int rhs_cols = extended_rhs_shape.Dims(4);
|
226
|
+
const int accum_depth = extended_lhs_shape.Dims(4);
|
227
|
+
|
228
|
+
const int32_t input_offset = params.input_offset;
|
229
|
+
const int32_t filter_offset = params.weights_offset;
|
230
|
+
const int32_t output_offset = params.output_offset;
|
231
|
+
const int32_t output_multiplier = params.output_multiplier;
|
232
|
+
const int output_shift = params.output_shift;
|
233
|
+
const int32_t output_activation_min = params.quantized_activation_min;
|
234
|
+
const int32_t output_activation_max = params.quantized_activation_max;
|
235
|
+
TFLITE_DCHECK_LE(output_activation_min, output_activation_max);
|
236
|
+
|
237
|
+
for (int b0 = 0; b0 < batch_dim0; ++b0) {
|
238
|
+
const T* lhs_ptr0 = lhs_data + (b0 * lhs_ext0);
|
239
|
+
const T* rhs_ptr0 = rhs_data + (b0 * rhs_ext0);
|
240
|
+
for (int b1 = 0; b1 < batch_dim1; ++b1) {
|
241
|
+
const T* lhs_ptr1 = lhs_ptr0 + b1 * lhs_ext1;
|
242
|
+
const T* rhs_ptr1 = rhs_ptr0 + b1 * rhs_ext1;
|
243
|
+
for (int b2 = 0; b2 < batch_dim2; ++b2) {
|
244
|
+
const T* lhs_ptr2 = lhs_ptr1 + b2 * lhs_ext2;
|
245
|
+
const T* rhs_ptr2 = rhs_ptr1 + b2 * rhs_ext2;
|
246
|
+
T* out_ptr = output_data +
|
247
|
+
((b0 * batch_dim1 * batch_dim2) + b1 * batch_dim2 + b2) *
|
248
|
+
lhs_rows * rhs_cols;
|
249
|
+
|
250
|
+
for (int j = 0; j < rhs_cols; ++j) {
|
251
|
+
for (int i = 0; i < lhs_rows; ++i) {
|
252
|
+
AccumT total = 0;
|
253
|
+
for (int k = 0; k < accum_depth; ++k) {
|
254
|
+
AccumT lhs_val = lhs_ptr2[accum_depth * i + k];
|
255
|
+
AccumT rhs_val = rhs_ptr2[accum_depth * j + k];
|
256
|
+
total += (lhs_val + filter_offset) * (rhs_val + input_offset);
|
257
|
+
}
|
258
|
+
int32_t total_scaled = MultiplyByQuantizedMultiplier(
|
259
|
+
total, output_multiplier, output_shift);
|
260
|
+
total_scaled += output_offset;
|
261
|
+
total_scaled = std::max(total_scaled, output_activation_min);
|
262
|
+
total_scaled = std::min(total_scaled, output_activation_max);
|
263
|
+
const int idx = lhs_rows * j + i;
|
264
|
+
out_ptr[idx] = static_cast<T>(total_scaled);
|
265
|
+
}
|
266
|
+
}
|
267
|
+
}
|
268
|
+
}
|
269
|
+
}
|
270
|
+
}
|
271
|
+
|
272
|
+
} // namespace reference_ops
|
273
|
+
} // namespace tflite_micro
|
274
|
+
|
275
|
+
#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BATCH_MATMUL_H_
|
@@ -0,0 +1,101 @@
|
|
1
|
+
/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
14
|
+
==============================================================================*/
|
15
|
+
#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BATCH_TO_SPACE_ND_H_
|
16
|
+
#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BATCH_TO_SPACE_ND_H_
|
17
|
+
|
18
|
+
#include <cmath>
|
19
|
+
|
20
|
+
#include "ruy/profiler/instrumentation.h" // from @ruy
|
21
|
+
#include "tensorflow/lite/kernels/internal/types.h"
|
22
|
+
|
23
|
+
namespace tflite_micro {
|
24
|
+
namespace reference_ops {
|
25
|
+
|
26
|
+
// TODO(b/135760455): Move this method anonymous namespace in a cc file.
|
27
|
+
inline RuntimeShape ExtendShapeBatchToSpace(const RuntimeShape& shape) {
|
28
|
+
if (shape.DimensionsCount() == 4) {
|
29
|
+
return shape;
|
30
|
+
}
|
31
|
+
RuntimeShape new_shape(4, 1);
|
32
|
+
new_shape.SetDim(0, shape.Dims(0));
|
33
|
+
new_shape.SetDim(1, shape.Dims(1));
|
34
|
+
new_shape.SetDim(3, shape.Dims(2));
|
35
|
+
return new_shape;
|
36
|
+
}
|
37
|
+
|
38
|
+
template <typename T>
|
39
|
+
inline void BatchToSpaceND(const RuntimeShape& unextended_input1_shape,
|
40
|
+
const T* input1_data,
|
41
|
+
const RuntimeShape& unextended_input2_shape,
|
42
|
+
const int32_t* block_shape_data,
|
43
|
+
const RuntimeShape& unextended_input3_shape,
|
44
|
+
const int32_t* crops_data,
|
45
|
+
const RuntimeShape& unextended_output_shape,
|
46
|
+
T* output_data) {
|
47
|
+
ruy::profiler::ScopeLabel label("BatchToSpaceND");
|
48
|
+
TFLITE_DCHECK_GE(unextended_input1_shape.DimensionsCount(), 3);
|
49
|
+
TFLITE_DCHECK_LE(unextended_input1_shape.DimensionsCount(), 4);
|
50
|
+
TFLITE_DCHECK_EQ(unextended_input1_shape.DimensionsCount(),
|
51
|
+
unextended_output_shape.DimensionsCount());
|
52
|
+
|
53
|
+
const RuntimeShape input1_shape =
|
54
|
+
ExtendShapeBatchToSpace(unextended_input1_shape);
|
55
|
+
const RuntimeShape output_shape =
|
56
|
+
ExtendShapeBatchToSpace(unextended_output_shape);
|
57
|
+
|
58
|
+
const int output_width = output_shape.Dims(2);
|
59
|
+
const int output_height = output_shape.Dims(1);
|
60
|
+
const int output_batch_size = output_shape.Dims(0);
|
61
|
+
|
62
|
+
const int depth = input1_shape.Dims(3);
|
63
|
+
const int input_width = input1_shape.Dims(2);
|
64
|
+
const int input_height = input1_shape.Dims(1);
|
65
|
+
const int input_batch_size = input1_shape.Dims(0);
|
66
|
+
|
67
|
+
const int block_shape_height = block_shape_data[0];
|
68
|
+
const int block_shape_width =
|
69
|
+
unextended_input1_shape.DimensionsCount() == 4 ? block_shape_data[1] : 1;
|
70
|
+
const int crops_top = crops_data[0];
|
71
|
+
const int crops_left =
|
72
|
+
unextended_input1_shape.DimensionsCount() == 4 ? crops_data[2] : 0;
|
73
|
+
for (int in_batch = 0; in_batch < input_batch_size; ++in_batch) {
|
74
|
+
const int out_batch = in_batch % output_batch_size;
|
75
|
+
const int spatial_offset = in_batch / output_batch_size;
|
76
|
+
for (int in_h = 0; in_h < input_height; ++in_h) {
|
77
|
+
const int out_h = in_h * block_shape_height +
|
78
|
+
spatial_offset / block_shape_width - crops_top;
|
79
|
+
if (out_h < 0 || out_h >= output_height) {
|
80
|
+
continue;
|
81
|
+
}
|
82
|
+
for (int in_w = 0; in_w < input_width; ++in_w) {
|
83
|
+
const int out_w = in_w * block_shape_width +
|
84
|
+
spatial_offset % block_shape_width - crops_left;
|
85
|
+
|
86
|
+
if (out_w < 0 || out_w >= output_width) {
|
87
|
+
continue;
|
88
|
+
}
|
89
|
+
T* out = output_data + Offset(output_shape, out_batch, out_h, out_w, 0);
|
90
|
+
const T* in =
|
91
|
+
input1_data + Offset(input1_shape, in_batch, in_h, in_w, 0);
|
92
|
+
memcpy(out, in, depth * sizeof(T));
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
} // namespace reference_ops
|
99
|
+
} // namespace tflite_micro
|
100
|
+
|
101
|
+
#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BATCH_TO_SPACE_ND_H_
|
@@ -0,0 +1,91 @@
|
|
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
|
+
#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BINARY_FUNCTION_H_
|
16
|
+
#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BINARY_FUNCTION_H_
|
17
|
+
|
18
|
+
#include "tensorflow/lite/kernels/internal/common.h"
|
19
|
+
#include "tensorflow/lite/kernels/internal/compatibility.h"
|
20
|
+
#include "tensorflow/lite/kernels/internal/types.h"
|
21
|
+
|
22
|
+
namespace tflite_micro {
|
23
|
+
|
24
|
+
namespace reference_ops {
|
25
|
+
|
26
|
+
// Also appears to duplicate MinimumMaximum.
|
27
|
+
//
|
28
|
+
// R: Result type. T1: Input 1 type. T2: Input 2 type.
|
29
|
+
template <typename R, typename T1, typename T2>
|
30
|
+
inline void BroadcastBinaryFunction4DSlow(
|
31
|
+
const RuntimeShape& unextended_input1_shape, const T1* input1_data,
|
32
|
+
const RuntimeShape& unextended_input2_shape, const T2* input2_data,
|
33
|
+
const RuntimeShape& unextended_output_shape, R* output_data,
|
34
|
+
R (*func)(T1, T2)) {
|
35
|
+
TFLITE_DCHECK_LE(unextended_input1_shape.DimensionsCount(), 4);
|
36
|
+
TFLITE_DCHECK_LE(unextended_input2_shape.DimensionsCount(), 4);
|
37
|
+
TFLITE_DCHECK_LE(unextended_output_shape.DimensionsCount(), 4);
|
38
|
+
const RuntimeShape output_shape =
|
39
|
+
RuntimeShape::ExtendedShape(4, unextended_output_shape);
|
40
|
+
|
41
|
+
NdArrayDesc<4> desc1;
|
42
|
+
NdArrayDesc<4> desc2;
|
43
|
+
NdArrayDescsForElementwiseBroadcast(unextended_input1_shape,
|
44
|
+
unextended_input2_shape, &desc1, &desc2);
|
45
|
+
|
46
|
+
const int* dims_data =
|
47
|
+
reinterpret_cast<const int*>(output_shape.DimsDataUpTo5D());
|
48
|
+
for (int b = 0; b < output_shape.Dims(0); ++b) {
|
49
|
+
int out_idx_b = b * dims_data[1];
|
50
|
+
int in_idx1_b = desc1.strides[0] * b;
|
51
|
+
int in_idx2_b = desc2.strides[0] * b;
|
52
|
+
for (int y = 0; y < output_shape.Dims(1); ++y) {
|
53
|
+
int out_idx_y = (out_idx_b + y) * dims_data[2];
|
54
|
+
int in_idx1_y = in_idx1_b + desc1.strides[1] * y;
|
55
|
+
int in_idx2_y = in_idx2_b + desc2.strides[1] * y;
|
56
|
+
for (int x = 0; x < output_shape.Dims(2); ++x) {
|
57
|
+
int out_idx_x = (out_idx_y + x) * dims_data[3];
|
58
|
+
int in1_idx = in_idx1_y + desc1.strides[2] * x;
|
59
|
+
int in2_idx = in_idx2_y + desc2.strides[2] * x;
|
60
|
+
for (int c = 0; c < output_shape.Dims(3); ++c) {
|
61
|
+
auto out_idx = out_idx_x + c;
|
62
|
+
auto in1_val = input1_data[in1_idx];
|
63
|
+
auto in2_val = input2_data[in2_idx];
|
64
|
+
output_data[out_idx] = func(in1_val, in2_val);
|
65
|
+
in1_idx += desc1.strides[3];
|
66
|
+
in2_idx += desc2.strides[3];
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
// R: Result type. T1: Input 1 type. T2: Input 2 type.
|
74
|
+
template <typename R, typename T1, typename T2>
|
75
|
+
inline void BinaryFunction(const RuntimeShape& input1_shape,
|
76
|
+
const T1* input1_data,
|
77
|
+
const RuntimeShape& input2_shape,
|
78
|
+
const T2* input2_data,
|
79
|
+
const RuntimeShape& output_shape, R* output_data,
|
80
|
+
R (*func)(T1, T2)) {
|
81
|
+
const int flat_size =
|
82
|
+
MatchingFlatSize(input1_shape, input2_shape, output_shape);
|
83
|
+
for (int i = 0; i < flat_size; ++i) {
|
84
|
+
output_data[i] = func(input1_data[i], input2_data[i]);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
} // namespace reference_ops
|
89
|
+
} // namespace tflite_micro
|
90
|
+
|
91
|
+
#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BINARY_FUNCTION_H_
|
@@ -0,0 +1,56 @@
|
|
1
|
+
/* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
14
|
+
==============================================================================*/
|
15
|
+
#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BROADCAST_ARGS_H_
|
16
|
+
#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BROADCAST_ARGS_H_
|
17
|
+
|
18
|
+
#include "tensorflow/lite/kernels/internal/compatibility.h"
|
19
|
+
#include "tensorflow/lite/kernels/internal/types.h"
|
20
|
+
|
21
|
+
namespace tflite_micro {
|
22
|
+
namespace reference_ops {
|
23
|
+
|
24
|
+
template <typename T>
|
25
|
+
void BroadcastArgs(const RuntimeShape& input1_shape, const T* input1_data,
|
26
|
+
const RuntimeShape& input2_shape, const T* input2_data,
|
27
|
+
const RuntimeShape& output_shape, T* output_data) {
|
28
|
+
// Gets data at the backward index i of the shape tensor. Returns 1 if the
|
29
|
+
// index is out of range.
|
30
|
+
auto get_shape_data = [](const RuntimeShape& shape, const T* data,
|
31
|
+
int backward_idx) -> T {
|
32
|
+
int forward_idx = shape.FlatSize() - 1 - backward_idx;
|
33
|
+
if (forward_idx < 0) return 1;
|
34
|
+
return data[forward_idx];
|
35
|
+
};
|
36
|
+
|
37
|
+
int output_num_elements = output_shape.FlatSize();
|
38
|
+
for (int i = 0; i < output_num_elements; ++i) {
|
39
|
+
int backward_i = output_num_elements - 1 - i;
|
40
|
+
int shape1_i = get_shape_data(input1_shape, input1_data, i);
|
41
|
+
int shape2_i = get_shape_data(input2_shape, input2_data, i);
|
42
|
+
if (shape1_i == 1) {
|
43
|
+
output_data[backward_i] = shape2_i;
|
44
|
+
} else if (shape2_i == 1) {
|
45
|
+
output_data[backward_i] = shape1_i;
|
46
|
+
} else {
|
47
|
+
TFLITE_CHECK_EQ(shape1_i, shape2_i);
|
48
|
+
output_data[backward_i] = shape1_i;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
} // namespace reference_ops
|
54
|
+
} // namespace tflite_micro
|
55
|
+
|
56
|
+
#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BROADCAST_ARGS_H_
|