xmos-ai-tools 1.3.2.dev180__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 +73 -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 +307 -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 +153 -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 +83 -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 +53 -0
- xmos_ai_tools/runtime/include/lib_tflite_micro/api/inference_engine.h +218 -0
- xmos_ai_tools/runtime/include/lib_tflite_micro/api/load_weights.h +64 -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_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 +79 -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 +68 -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 +64 -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 +651 -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.dev180.data/data/bin/xcore-opt +0 -0
- xmos_ai_tools-1.3.2.dev180.dist-info/METADATA +33 -0
- xmos_ai_tools-1.3.2.dev180.dist-info/RECORD +395 -0
- xmos_ai_tools-1.3.2.dev180.dist-info/WHEEL +5 -0
- xmos_ai_tools-1.3.2.dev180.dist-info/top_level.txt +1 -0
@@ -0,0 +1,291 @@
|
|
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_INTEGER_OPS_DEPTHWISE_CONV_H_
|
16
|
+
#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_DEPTHWISE_CONV_H_
|
17
|
+
|
18
|
+
#include <algorithm>
|
19
|
+
|
20
|
+
#include "tensorflow/lite/kernels/internal/common.h"
|
21
|
+
|
22
|
+
namespace tflite_micro {
|
23
|
+
namespace reference_integer_ops {
|
24
|
+
inline void DepthwiseConvPerChannel(
|
25
|
+
const DepthwiseParams& params, const int32_t* output_multiplier,
|
26
|
+
const int32_t* output_shift, const RuntimeShape& input_shape,
|
27
|
+
const int8_t* input_data, const RuntimeShape& filter_shape,
|
28
|
+
const int8_t* filter_data, const RuntimeShape& bias_shape,
|
29
|
+
const int32_t* bias_data, const RuntimeShape& output_shape,
|
30
|
+
int8_t* output_data) {
|
31
|
+
// Get parameters.
|
32
|
+
// TODO(b/141565753): Re-introduce ScopedProfilingLabel on Micro.
|
33
|
+
const int stride_width = params.stride_width;
|
34
|
+
const int stride_height = params.stride_height;
|
35
|
+
const int dilation_width_factor = params.dilation_width_factor;
|
36
|
+
const int dilation_height_factor = params.dilation_height_factor;
|
37
|
+
const int pad_width = params.padding_values.width;
|
38
|
+
const int pad_height = params.padding_values.height;
|
39
|
+
const int depth_multiplier = params.depth_multiplier;
|
40
|
+
const int32_t input_offset = params.input_offset;
|
41
|
+
const int32_t output_offset = params.output_offset;
|
42
|
+
const int32_t output_activation_min = params.quantized_activation_min;
|
43
|
+
const int32_t output_activation_max = params.quantized_activation_max;
|
44
|
+
|
45
|
+
// Check dimensions of the tensors.
|
46
|
+
TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4);
|
47
|
+
TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4);
|
48
|
+
TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4);
|
49
|
+
|
50
|
+
TFLITE_DCHECK_LE(output_activation_min, output_activation_max);
|
51
|
+
const int batches = MatchingDim(input_shape, 0, output_shape, 0);
|
52
|
+
const int output_depth = MatchingDim(filter_shape, 3, output_shape, 3);
|
53
|
+
const int input_height = input_shape.Dims(1);
|
54
|
+
const int input_width = input_shape.Dims(2);
|
55
|
+
const int input_depth = input_shape.Dims(3);
|
56
|
+
const int filter_height = filter_shape.Dims(1);
|
57
|
+
const int filter_width = filter_shape.Dims(2);
|
58
|
+
const int output_height = output_shape.Dims(1);
|
59
|
+
const int output_width = output_shape.Dims(2);
|
60
|
+
TFLITE_DCHECK_EQ(output_depth, input_depth * depth_multiplier);
|
61
|
+
TFLITE_DCHECK_EQ(bias_shape.FlatSize(), output_depth);
|
62
|
+
|
63
|
+
for (int batch = 0; batch < batches; ++batch) {
|
64
|
+
for (int out_y = 0; out_y < output_height; ++out_y) {
|
65
|
+
for (int out_x = 0; out_x < output_width; ++out_x) {
|
66
|
+
for (int in_channel = 0; in_channel < input_depth; ++in_channel) {
|
67
|
+
for (int m = 0; m < depth_multiplier; ++m) {
|
68
|
+
const int output_channel = m + in_channel * depth_multiplier;
|
69
|
+
const int in_x_origin = (out_x * stride_width) - pad_width;
|
70
|
+
const int in_y_origin = (out_y * stride_height) - pad_height;
|
71
|
+
int32_t acc = 0;
|
72
|
+
for (int filter_y = 0; filter_y < filter_height; ++filter_y) {
|
73
|
+
for (int filter_x = 0; filter_x < filter_width; ++filter_x) {
|
74
|
+
const int in_x = in_x_origin + dilation_width_factor * filter_x;
|
75
|
+
const int in_y =
|
76
|
+
in_y_origin + dilation_height_factor * filter_y;
|
77
|
+
// Zero padding by omitting the areas outside the image.
|
78
|
+
const bool is_point_inside_image =
|
79
|
+
(in_x >= 0) && (in_x < input_width) && (in_y >= 0) &&
|
80
|
+
(in_y < input_height);
|
81
|
+
if (is_point_inside_image) {
|
82
|
+
int32_t input_val = input_data[Offset(
|
83
|
+
input_shape, batch, in_y, in_x, in_channel)];
|
84
|
+
int32_t filter_val = filter_data[Offset(
|
85
|
+
filter_shape, 0, filter_y, filter_x, output_channel)];
|
86
|
+
// Accumulate with 32 bits accumulator.
|
87
|
+
// In the nudging process during model quantization, we force
|
88
|
+
// real value of 0.0 be represented by a quantized value. This
|
89
|
+
// guarantees that the input_offset is a int8_t, even though
|
90
|
+
// it is represented using int32_t. int32_t += int8_t *
|
91
|
+
// (int8_t - int8_t) so the highest value we can get from each
|
92
|
+
// accumulation is [-127, 127] * ([-128, 127] -
|
93
|
+
// [-128, 127]), which is [-32512, 32512]. log2(32512)
|
94
|
+
// = 14.98, which means we can accumulate at least 2^16
|
95
|
+
// multiplications without overflow. The accumulator is
|
96
|
+
// applied to a filter so the accumulation logic will hold as
|
97
|
+
// long as the filter size (filter_y * filter_x * in_channel)
|
98
|
+
// does not exceed 2^16, which is the case in all the models
|
99
|
+
// we have seen so far.
|
100
|
+
// TODO(b/174275578): Add a check to make sure the
|
101
|
+
// accumulator depth is smaller than 2^16.
|
102
|
+
acc += filter_val * (input_val + input_offset);
|
103
|
+
}
|
104
|
+
}
|
105
|
+
}
|
106
|
+
if (bias_data) {
|
107
|
+
acc += bias_data[output_channel];
|
108
|
+
}
|
109
|
+
acc = MultiplyByQuantizedMultiplier(
|
110
|
+
acc, output_multiplier[output_channel],
|
111
|
+
output_shift[output_channel]);
|
112
|
+
acc += output_offset;
|
113
|
+
acc = std::max(acc, output_activation_min);
|
114
|
+
acc = std::min(acc, output_activation_max);
|
115
|
+
output_data[Offset(output_shape, batch, out_y, out_x,
|
116
|
+
output_channel)] = static_cast<int8_t>(acc);
|
117
|
+
}
|
118
|
+
}
|
119
|
+
}
|
120
|
+
}
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
inline void DepthwiseConvPerChannel(
|
125
|
+
const DepthwiseParams& params, const int32_t* output_multiplier,
|
126
|
+
const int32_t* output_shift, const RuntimeShape& input_shape,
|
127
|
+
const int16_t* input_data, const RuntimeShape& filter_shape,
|
128
|
+
const int8_t* filter_data, const RuntimeShape& bias_shape,
|
129
|
+
const std::int64_t* bias_data, const RuntimeShape& output_shape,
|
130
|
+
int16_t* output_data) {
|
131
|
+
// Get parameters.
|
132
|
+
const int stride_width = params.stride_width;
|
133
|
+
const int stride_height = params.stride_height;
|
134
|
+
const int dilation_width_factor = params.dilation_width_factor;
|
135
|
+
const int dilation_height_factor = params.dilation_height_factor;
|
136
|
+
const int pad_width = params.padding_values.width;
|
137
|
+
const int pad_height = params.padding_values.height;
|
138
|
+
const int depth_multiplier = params.depth_multiplier;
|
139
|
+
const int32_t output_activation_min = params.quantized_activation_min;
|
140
|
+
const int32_t output_activation_max = params.quantized_activation_max;
|
141
|
+
|
142
|
+
// Check dimensions of the tensors.
|
143
|
+
TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4);
|
144
|
+
TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4);
|
145
|
+
TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4);
|
146
|
+
|
147
|
+
TFLITE_DCHECK_LE(output_activation_min, output_activation_max);
|
148
|
+
const int batches = MatchingDim(input_shape, 0, output_shape, 0);
|
149
|
+
const int output_depth = MatchingDim(filter_shape, 3, output_shape, 3);
|
150
|
+
const int input_height = input_shape.Dims(1);
|
151
|
+
const int input_width = input_shape.Dims(2);
|
152
|
+
const int input_depth = input_shape.Dims(3);
|
153
|
+
const int filter_height = filter_shape.Dims(1);
|
154
|
+
const int filter_width = filter_shape.Dims(2);
|
155
|
+
const int output_height = output_shape.Dims(1);
|
156
|
+
const int output_width = output_shape.Dims(2);
|
157
|
+
TFLITE_DCHECK_EQ(output_depth, input_depth * depth_multiplier);
|
158
|
+
TFLITE_DCHECK_EQ(bias_shape.FlatSize(), output_depth);
|
159
|
+
|
160
|
+
for (int batch = 0; batch < batches; ++batch) {
|
161
|
+
for (int out_y = 0; out_y < output_height; ++out_y) {
|
162
|
+
for (int out_x = 0; out_x < output_width; ++out_x) {
|
163
|
+
for (int in_channel = 0; in_channel < input_depth; ++in_channel) {
|
164
|
+
for (int m = 0; m < depth_multiplier; ++m) {
|
165
|
+
const int output_channel = m + in_channel * depth_multiplier;
|
166
|
+
const int in_x_origin = (out_x * stride_width) - pad_width;
|
167
|
+
const int in_y_origin = (out_y * stride_height) - pad_height;
|
168
|
+
std::int64_t acc = 0;
|
169
|
+
for (int filter_y = 0; filter_y < filter_height; ++filter_y) {
|
170
|
+
for (int filter_x = 0; filter_x < filter_width; ++filter_x) {
|
171
|
+
const int in_x = in_x_origin + dilation_width_factor * filter_x;
|
172
|
+
const int in_y =
|
173
|
+
in_y_origin + dilation_height_factor * filter_y;
|
174
|
+
// Zero padding by omitting the areas outside the image.
|
175
|
+
const bool is_point_inside_image =
|
176
|
+
(in_x >= 0) && (in_x < input_width) && (in_y >= 0) &&
|
177
|
+
(in_y < input_height);
|
178
|
+
if (is_point_inside_image) {
|
179
|
+
int32_t input_val = input_data[Offset(
|
180
|
+
input_shape, batch, in_y, in_x, in_channel)];
|
181
|
+
int32_t filter_val = filter_data[Offset(
|
182
|
+
filter_shape, 0, filter_y, filter_x, output_channel)];
|
183
|
+
// Accumulate with 64 bits accumulator.
|
184
|
+
// We assume maximum of 2^16 accumulations as with the 8-bit
|
185
|
+
// case so actually the value in the accumulator should not
|
186
|
+
// exceed 40 bits
|
187
|
+
acc += static_cast<int64_t>(filter_val) *
|
188
|
+
static_cast<int64_t>(input_val);
|
189
|
+
}
|
190
|
+
}
|
191
|
+
}
|
192
|
+
if (bias_data) {
|
193
|
+
acc += bias_data[output_channel];
|
194
|
+
}
|
195
|
+
int32_t scaled_acc = MultiplyByQuantizedMultiplier(
|
196
|
+
acc, output_multiplier[output_channel],
|
197
|
+
output_shift[output_channel]);
|
198
|
+
scaled_acc = std::max(scaled_acc, output_activation_min);
|
199
|
+
scaled_acc = std::min(scaled_acc, output_activation_max);
|
200
|
+
output_data[Offset(output_shape, batch, out_y, out_x,
|
201
|
+
output_channel)] =
|
202
|
+
static_cast<int16_t>(scaled_acc);
|
203
|
+
}
|
204
|
+
}
|
205
|
+
}
|
206
|
+
}
|
207
|
+
}
|
208
|
+
}
|
209
|
+
|
210
|
+
inline void DepthwiseConvHybridPerChannel(
|
211
|
+
const DepthwiseParams& params, float* scaling_factors_ptr,
|
212
|
+
const RuntimeShape& input_shape, const int8_t* input_data,
|
213
|
+
const RuntimeShape& filter_shape, const int8_t* filter_data,
|
214
|
+
const RuntimeShape& bias_shape, const float* bias_data,
|
215
|
+
const RuntimeShape& output_shape, float* output_data,
|
216
|
+
const float* per_channel_scale, int32_t* input_offset) {
|
217
|
+
const int stride_width = params.stride_width;
|
218
|
+
const int stride_height = params.stride_height;
|
219
|
+
const int dilation_width_factor = params.dilation_width_factor;
|
220
|
+
const int dilation_height_factor = params.dilation_height_factor;
|
221
|
+
const int pad_width = params.padding_values.width;
|
222
|
+
const int pad_height = params.padding_values.height;
|
223
|
+
const int depth_multiplier = params.depth_multiplier;
|
224
|
+
const float output_activation_min = params.float_activation_min;
|
225
|
+
const float output_activation_max = params.float_activation_max;
|
226
|
+
// Check dimensions of the tensors.
|
227
|
+
TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4);
|
228
|
+
TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4);
|
229
|
+
TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4);
|
230
|
+
|
231
|
+
const int batches = MatchingDim(input_shape, 0, output_shape, 0);
|
232
|
+
const int output_depth = MatchingDim(filter_shape, 3, output_shape, 3);
|
233
|
+
const int input_height = input_shape.Dims(1);
|
234
|
+
const int input_width = input_shape.Dims(2);
|
235
|
+
const int input_depth = input_shape.Dims(3);
|
236
|
+
const int filter_height = filter_shape.Dims(1);
|
237
|
+
const int filter_width = filter_shape.Dims(2);
|
238
|
+
const int output_height = output_shape.Dims(1);
|
239
|
+
const int output_width = output_shape.Dims(2);
|
240
|
+
const int bias_depth = bias_shape.FlatSize();
|
241
|
+
TFLITE_DCHECK_EQ(output_depth, input_depth * depth_multiplier);
|
242
|
+
TFLITE_DCHECK_EQ(bias_depth, output_depth);
|
243
|
+
|
244
|
+
for (int batch = 0; batch < batches; ++batch) {
|
245
|
+
for (int out_y = 0; out_y < output_height; ++out_y) {
|
246
|
+
for (int out_x = 0; out_x < output_width; ++out_x) {
|
247
|
+
for (int in_channel = 0; in_channel < input_depth; ++in_channel) {
|
248
|
+
for (int m = 0; m < depth_multiplier; ++m) {
|
249
|
+
const int output_channel = m + in_channel * depth_multiplier;
|
250
|
+
const int in_x_origin = (out_x * stride_width) - pad_width;
|
251
|
+
const int in_y_origin = (out_y * stride_height) - pad_height;
|
252
|
+
int32_t acc = 0;
|
253
|
+
for (int filter_y = 0; filter_y < filter_height; ++filter_y) {
|
254
|
+
for (int filter_x = 0; filter_x < filter_width; ++filter_x) {
|
255
|
+
const int in_x = in_x_origin + dilation_width_factor * filter_x;
|
256
|
+
const int in_y =
|
257
|
+
in_y_origin + dilation_height_factor * filter_y;
|
258
|
+
// Zero padding by omitting the areas outside the image.
|
259
|
+
const bool is_point_inside_image =
|
260
|
+
(in_x >= 0) && (in_x < input_width) && (in_y >= 0) &&
|
261
|
+
(in_y < input_height);
|
262
|
+
if (is_point_inside_image) {
|
263
|
+
int32_t input_val = input_data[Offset(
|
264
|
+
input_shape, batch, in_y, in_x, in_channel)];
|
265
|
+
int32_t filter_val = filter_data[Offset(
|
266
|
+
filter_shape, 0, filter_y, filter_x, output_channel)];
|
267
|
+
acc += filter_val * (input_val - input_offset[batch]);
|
268
|
+
}
|
269
|
+
}
|
270
|
+
}
|
271
|
+
float acc_float = static_cast<float>(acc);
|
272
|
+
acc_float *=
|
273
|
+
per_channel_scale[output_channel] * scaling_factors_ptr[batch];
|
274
|
+
if (bias_data && output_channel < bias_depth) {
|
275
|
+
acc_float += bias_data[output_channel];
|
276
|
+
}
|
277
|
+
output_data[Offset(output_shape, batch, out_y, out_x,
|
278
|
+
output_channel)] =
|
279
|
+
ActivationFunctionWithMinMax(acc_float, output_activation_min,
|
280
|
+
output_activation_max);
|
281
|
+
}
|
282
|
+
}
|
283
|
+
}
|
284
|
+
}
|
285
|
+
}
|
286
|
+
}
|
287
|
+
|
288
|
+
} // namespace reference_integer_ops
|
289
|
+
} // namespace tflite_micro
|
290
|
+
|
291
|
+
#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_DEPTHWISE_CONV_H_
|
@@ -0,0 +1,126 @@
|
|
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_INTEGER_OPS_FULLY_CONNECTED_H_
|
16
|
+
#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_FULLY_CONNECTED_H_
|
17
|
+
|
18
|
+
#include <algorithm>
|
19
|
+
|
20
|
+
#include "tensorflow/lite/kernels/internal/common.h"
|
21
|
+
|
22
|
+
namespace tflite_micro {
|
23
|
+
namespace reference_integer_ops {
|
24
|
+
|
25
|
+
// For per-channel functions, since it is defined in quantization spec that
|
26
|
+
// weights are symmetric
|
27
|
+
// (https://www.tensorflow.org/lite/performance/quantization_spec#symmetric_vs_asymmetric),
|
28
|
+
// zero_point (params.weights_offset) is always 0.
|
29
|
+
// However, for per-tensor functions, params.weights_offset is still applied for
|
30
|
+
// backward compatibility.
|
31
|
+
template <typename InputType, typename WeightType, typename OutputType,
|
32
|
+
typename BiasType>
|
33
|
+
void FullyConnectedPerChannel(
|
34
|
+
const FullyConnectedParams& params, const int32_t* output_multiplier,
|
35
|
+
const int* output_shift, const RuntimeShape& input_shape,
|
36
|
+
const InputType* input_data, const RuntimeShape& filter_shape,
|
37
|
+
const WeightType* filter_data, const RuntimeShape& bias_shape,
|
38
|
+
const BiasType* bias_data, const RuntimeShape& output_shape,
|
39
|
+
OutputType* output_data) {
|
40
|
+
const int32_t input_offset = params.input_offset;
|
41
|
+
const int32_t output_offset = params.output_offset;
|
42
|
+
const int32_t output_activation_min = params.quantized_activation_min;
|
43
|
+
const int32_t output_activation_max = params.quantized_activation_max;
|
44
|
+
TFLITE_DCHECK_GE(filter_shape.DimensionsCount(), 2);
|
45
|
+
TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 2);
|
46
|
+
|
47
|
+
TFLITE_DCHECK_LE(output_activation_min, output_activation_max);
|
48
|
+
const int filter_dim_count = filter_shape.DimensionsCount();
|
49
|
+
const int batches = output_shape.Dims(0);
|
50
|
+
const int output_depth = output_shape.Dims(1);
|
51
|
+
TFLITE_DCHECK_LE(output_depth, filter_shape.Dims(filter_dim_count - 2));
|
52
|
+
const int accum_depth = filter_shape.Dims(filter_dim_count - 1);
|
53
|
+
for (int b = 0; b < batches; ++b) {
|
54
|
+
for (int out_c = 0; out_c < output_depth; ++out_c) {
|
55
|
+
BiasType acc = 0;
|
56
|
+
for (int d = 0; d < accum_depth; ++d) {
|
57
|
+
int32_t input_val = input_data[b * accum_depth + d];
|
58
|
+
int32_t filter_val = filter_data[out_c * accum_depth + d];
|
59
|
+
acc += filter_val * (input_val + input_offset);
|
60
|
+
}
|
61
|
+
if (bias_data) {
|
62
|
+
acc += bias_data[out_c];
|
63
|
+
}
|
64
|
+
int32_t acc_scaled = MultiplyByQuantizedMultiplier(
|
65
|
+
acc, output_multiplier[out_c], output_shift[out_c]);
|
66
|
+
acc_scaled += output_offset;
|
67
|
+
acc_scaled = std::max(acc_scaled, output_activation_min);
|
68
|
+
acc_scaled = std::min(acc_scaled, output_activation_max);
|
69
|
+
output_data[out_c + output_depth * b] =
|
70
|
+
static_cast<OutputType>(acc_scaled);
|
71
|
+
}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
template <typename InputType, typename WeightType, typename OutputType,
|
76
|
+
typename BiasType>
|
77
|
+
void FullyConnected(const FullyConnectedParams& params,
|
78
|
+
const RuntimeShape& input_shape,
|
79
|
+
const InputType* input_data,
|
80
|
+
const RuntimeShape& filter_shape,
|
81
|
+
const WeightType* filter_data,
|
82
|
+
const RuntimeShape& bias_shape, const BiasType* bias_data,
|
83
|
+
const RuntimeShape& output_shape, OutputType* output_data) {
|
84
|
+
const int32_t input_offset = params.input_offset;
|
85
|
+
const int32_t filter_offset = params.weights_offset;
|
86
|
+
const int32_t output_offset = params.output_offset;
|
87
|
+
const int32_t output_multiplier = params.output_multiplier;
|
88
|
+
const int output_shift = params.output_shift;
|
89
|
+
const int32_t output_activation_min = params.quantized_activation_min;
|
90
|
+
const int32_t output_activation_max = params.quantized_activation_max;
|
91
|
+
TFLITE_DCHECK_GE(filter_shape.DimensionsCount(), 2);
|
92
|
+
TFLITE_DCHECK_GE(output_shape.DimensionsCount(), 1);
|
93
|
+
|
94
|
+
TFLITE_DCHECK_LE(output_activation_min, output_activation_max);
|
95
|
+
const int filter_dim_count = filter_shape.DimensionsCount();
|
96
|
+
const int output_dim_count = output_shape.DimensionsCount();
|
97
|
+
const int batches = FlatSizeSkipDim(output_shape, output_dim_count - 1);
|
98
|
+
const int output_depth = output_shape.Dims(output_dim_count - 1);
|
99
|
+
TFLITE_DCHECK_LE(output_depth, filter_shape.Dims(filter_dim_count - 2));
|
100
|
+
const int accum_depth = filter_shape.Dims(filter_dim_count - 1);
|
101
|
+
for (int b = 0; b < batches; ++b) {
|
102
|
+
for (int out_c = 0; out_c < output_depth; ++out_c) {
|
103
|
+
BiasType acc = 0;
|
104
|
+
for (int d = 0; d < accum_depth; ++d) {
|
105
|
+
int32_t input_val = input_data[b * accum_depth + d];
|
106
|
+
int32_t filter_val = filter_data[out_c * accum_depth + d];
|
107
|
+
acc += (filter_val + filter_offset) * (input_val + input_offset);
|
108
|
+
}
|
109
|
+
if (bias_data) {
|
110
|
+
acc += bias_data[out_c];
|
111
|
+
}
|
112
|
+
int32_t acc_scaled =
|
113
|
+
MultiplyByQuantizedMultiplier(acc, output_multiplier, output_shift);
|
114
|
+
acc_scaled += output_offset;
|
115
|
+
acc_scaled = std::max(acc_scaled, output_activation_min);
|
116
|
+
acc_scaled = std::min(acc_scaled, output_activation_max);
|
117
|
+
output_data[out_c + output_depth * b] =
|
118
|
+
static_cast<OutputType>(acc_scaled);
|
119
|
+
}
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
} // namespace reference_integer_ops
|
124
|
+
} // namespace tflite_micro
|
125
|
+
|
126
|
+
#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_FULLY_CONNECTED_H_
|
@@ -0,0 +1,67 @@
|
|
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_INTEGER_OPS_L2NORMALIZATION_H_
|
16
|
+
#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_L2NORMALIZATION_H_
|
17
|
+
|
18
|
+
#include <algorithm>
|
19
|
+
|
20
|
+
#include "tensorflow/lite/kernels/internal/common.h"
|
21
|
+
|
22
|
+
namespace tflite_micro {
|
23
|
+
namespace reference_integer_ops {
|
24
|
+
|
25
|
+
inline void L2Normalization(int32_t input_zero_point, int32_t outer_size,
|
26
|
+
int32_t depth, const int8_t* input_data,
|
27
|
+
int8_t* output_data) {
|
28
|
+
static constexpr int8_t kMinInt8 = std::numeric_limits<int8_t>::min();
|
29
|
+
static constexpr int8_t kMaxInt8 = std::numeric_limits<int8_t>::max();
|
30
|
+
// The output scale must be in sync with Prepare().
|
31
|
+
// Output is in 1/128 scale so the actual output range is nudged from [-1, 1]
|
32
|
+
// to [-1, 127/128].
|
33
|
+
static constexpr int32_t kOutputScale = 7;
|
34
|
+
for (int outer_index = 0; outer_index < outer_size; ++outer_index) {
|
35
|
+
// int32_t = (int8_t - int8_t) ^ 2.
|
36
|
+
// ([-128, 127] - [-128, 127]) ^ 2 = [0, (2^8 - 1)^2] so the accumulator is
|
37
|
+
// safe from overflowing in at least 2^16 steps.
|
38
|
+
int32_t acc = 0;
|
39
|
+
for (int inner_index = 0; inner_index < depth; ++inner_index) {
|
40
|
+
int32_t input =
|
41
|
+
input_data[depth * outer_index + inner_index] - input_zero_point;
|
42
|
+
acc += input * input;
|
43
|
+
}
|
44
|
+
int32_t inv_l2norm_multiplier;
|
45
|
+
int inv_l2norm_shift;
|
46
|
+
GetInvSqrtQuantizedMultiplierExp(acc, kReverseShift, &inv_l2norm_multiplier,
|
47
|
+
&inv_l2norm_shift);
|
48
|
+
|
49
|
+
for (int inner_index = 0; inner_index < depth; ++inner_index) {
|
50
|
+
int32_t input =
|
51
|
+
input_data[depth * outer_index + inner_index] - input_zero_point;
|
52
|
+
|
53
|
+
// Rescale and downcast. Rescale is folded into the division.
|
54
|
+
int32_t output_in_q24 = MultiplyByQuantizedMultiplier(
|
55
|
+
input, inv_l2norm_multiplier, inv_l2norm_shift + kOutputScale);
|
56
|
+
output_in_q24 =
|
57
|
+
std::min(static_cast<int32_t>(kMaxInt8),
|
58
|
+
std::max(static_cast<int32_t>(kMinInt8), output_in_q24));
|
59
|
+
output_data[depth * outer_index + inner_index] =
|
60
|
+
static_cast<int8_t>(output_in_q24);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
} // namespace reference_integer_ops
|
65
|
+
} // namespace tflite_micro
|
66
|
+
|
67
|
+
#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_L2NORMALIZATION_H_
|
xmos_ai_tools/runtime/include/tensorflow/lite/kernels/internal/reference/integer_ops/logistic.h
ADDED
@@ -0,0 +1,121 @@
|
|
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_INTEGER_OPS_LOGISTIC_H_
|
16
|
+
#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_LOGISTIC_H_
|
17
|
+
|
18
|
+
#include <algorithm>
|
19
|
+
#include <limits>
|
20
|
+
|
21
|
+
#include "tensorflow/lite/kernels/internal/common.h"
|
22
|
+
|
23
|
+
namespace tflite_micro {
|
24
|
+
namespace reference_integer_ops {
|
25
|
+
|
26
|
+
inline void Logistic(int32_t input_zero_point, int32_t input_range_radius,
|
27
|
+
int32_t input_multiplier, int32_t input_left_shift,
|
28
|
+
int32_t input_size, const int8_t* input_data,
|
29
|
+
int8_t* output_data) {
|
30
|
+
// Integer bits must be in sync with Prepare() function.
|
31
|
+
static constexpr int32_t kInputIntegerBits = 4;
|
32
|
+
static constexpr int32_t kOutputIntegerBits = 8;
|
33
|
+
static constexpr int8_t kMinInt8 = std::numeric_limits<int8_t>::min();
|
34
|
+
static constexpr int8_t kMaxInt8 = std::numeric_limits<int8_t>::max();
|
35
|
+
static constexpr int32_t kOutputZeroPoint = -128;
|
36
|
+
|
37
|
+
for (int i = 0; i < input_size; ++i) {
|
38
|
+
const int32_t input =
|
39
|
+
static_cast<int32_t>(input_data[i]) - input_zero_point;
|
40
|
+
if (input <= -input_range_radius) {
|
41
|
+
output_data[i] = kMinInt8;
|
42
|
+
} else if (input >= input_range_radius) {
|
43
|
+
output_data[i] = kMaxInt8;
|
44
|
+
} else {
|
45
|
+
const int32_t input_in_q4 = MultiplyByQuantizedMultiplier(
|
46
|
+
input, input_multiplier, input_left_shift);
|
47
|
+
using FixedPoint4 = gemmlowp::FixedPoint<int32_t, kInputIntegerBits>;
|
48
|
+
const int32_t output_in_q0 =
|
49
|
+
gemmlowp::logistic(FixedPoint4::FromRaw(input_in_q4)).raw();
|
50
|
+
|
51
|
+
// Rescale and downcast.
|
52
|
+
using gemmlowp::RoundingDivideByPOT;
|
53
|
+
int32_t output_in_q23 =
|
54
|
+
RoundingDivideByPOT(output_in_q0, 31 - kOutputIntegerBits);
|
55
|
+
output_in_q23 = std::min(std::max(output_in_q23 + kOutputZeroPoint,
|
56
|
+
static_cast<int32_t>(kMinInt8)),
|
57
|
+
static_cast<int32_t>(kMaxInt8));
|
58
|
+
output_data[i] = static_cast<int8_t>(output_in_q23);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
inline void Logistic(int32_t input_multiplier, int32_t input_left_shift,
|
64
|
+
int32_t input_size, const int16_t* ptr_input_data,
|
65
|
+
int16_t* ptr_output_data) {
|
66
|
+
// We use the LUT for sigmoid and take into account, that
|
67
|
+
// tanh(x) = 2*sigmoid(2*x) - 1
|
68
|
+
|
69
|
+
// We scale by 3/4 to expand range [-8,8]->[-10.7,10.7].
|
70
|
+
// In case of general parameter scale, multiplier 3 is taken into account
|
71
|
+
// in TanhPrepare function and it is included in
|
72
|
+
// input_multiplier already.
|
73
|
+
|
74
|
+
TFLITE_DCHECK_GE(input_left_shift, 0);
|
75
|
+
if (input_multiplier == 0) { // power of two case
|
76
|
+
input_multiplier = 3 << input_left_shift;
|
77
|
+
input_left_shift = 0;
|
78
|
+
}
|
79
|
+
|
80
|
+
int32_t round = (input_left_shift > 0) ? 1 << (input_left_shift - 1) : 0;
|
81
|
+
|
82
|
+
for (int i = 0; i < input_size; ++i, ptr_input_data++, ptr_output_data++) {
|
83
|
+
int32_t input_data =
|
84
|
+
((*ptr_input_data) * input_multiplier + round) >> input_left_shift;
|
85
|
+
|
86
|
+
// We do interpolation on unsigned values.
|
87
|
+
uint32_t abs_input_data = abs(input_data);
|
88
|
+
|
89
|
+
// We divide by 2 power of 9, because
|
90
|
+
// we need to divide by 2 in power of 7 for
|
91
|
+
// the input conversion + 1/4 from the scale above.
|
92
|
+
|
93
|
+
// Define uh as uint32_t type not to make this function overflow.
|
94
|
+
uint32_t uh = abs_input_data >> 9;
|
95
|
+
uint32_t result;
|
96
|
+
|
97
|
+
if (uh >= 255) {
|
98
|
+
// Saturate to maximum.
|
99
|
+
result = 0x7FFF << 10;
|
100
|
+
} else {
|
101
|
+
uint32_t ua = sigmoid_table_uint16[uh];
|
102
|
+
uint32_t ub = sigmoid_table_uint16[uh + 1];
|
103
|
+
uint32_t ut = abs_input_data & 0x1ff;
|
104
|
+
// Interpolation is done using the fractional bit.
|
105
|
+
result = (ua << 9) + ut * (ub - ua);
|
106
|
+
}
|
107
|
+
|
108
|
+
result = (input_data >= 0) ? (result + (1 << 9))
|
109
|
+
: ((1 << (16 + 9)) - result + (1 << 9) - 1);
|
110
|
+
|
111
|
+
// Back to 16-bit.
|
112
|
+
result >>= 10;
|
113
|
+
|
114
|
+
*ptr_output_data = result;
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
} // namespace reference_integer_ops
|
119
|
+
} // namespace tflite_micro
|
120
|
+
|
121
|
+
#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_LOGISTIC_H_
|
@@ -0,0 +1,18 @@
|
|
1
|
+
/* Copyright 2023 The TensorFlow Authors. All Rights Reserved.
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
14
|
+
==============================================================================*/
|
15
|
+
#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_MEAN_H_
|
16
|
+
#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_MEAN_H_
|
17
|
+
|
18
|
+
#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_INTEGER_OPS_MEAN_H_
|