Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include "BaseIterator.hpp" |
James Conroy | 1f58f03 | 2021-04-27 17:13:27 +0100 | [diff] [blame] | 9 | #include <backendsCommon/TensorHandle.hpp> |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 10 | |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 11 | // Helper functions ported from the Android code base |
| 12 | // Refer to: android/external/tensorflow/tensorflow/contrib/lite/kernels/internal/reference/portable_tensor_utils.cc |
| 13 | |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 14 | |
| 15 | void VectorBatchVectorAdd(armnn::Decoder<float>& vector, |
| 16 | uint32_t vSize, |
| 17 | armnn::Decoder<float>& batchVector, |
| 18 | uint32_t nBatch, |
| 19 | armnn::Encoder<float>& outResult ); |
| 20 | |
| 21 | // Layer norm for each batch. |
| 22 | // normalization_epsilon is added to avoid divergence. |
| 23 | void MeanStddevNormalization(armnn::Decoder<float>& input_vector, |
| 24 | armnn::Encoder<float>& output_vector, |
| 25 | uint32_t v_size, |
| 26 | uint32_t n_batch, |
| 27 | float normalization_epsilon); |
| 28 | |
| 29 | void ZeroVector(armnn::Encoder<float>& vector, |
| 30 | uint32_t vSize); |
| 31 | |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 32 | void MatrixBatchVectorMultiplyAccumulate(armnn::Decoder<float>& matrix, |
| 33 | uint32_t mRows, |
| 34 | uint32_t mCols, |
| 35 | armnn::Decoder<float>& vector, |
| 36 | uint32_t nBatch, |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 37 | armnn::Encoder<float>& outResult); |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 38 | |
| 39 | void VectorBatchVectorAssign(armnn::Decoder<float>& vector, |
| 40 | uint32_t vSize, |
| 41 | uint32_t nBatch, |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 42 | armnn::Encoder<float>& outBatchVector); |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 43 | |
| 44 | void VectorBatchVectorCwiseProductAccumulate(armnn::Decoder<float>& vector, |
| 45 | uint32_t vSize, |
| 46 | armnn::Decoder<float>& batchVector, |
| 47 | uint32_t nBatch, |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 48 | armnn::Encoder<float>& outResult); |
| 49 | |
| 50 | void VectorBatchVectorCwiseProduct(armnn::Decoder<float>& vector, |
| 51 | uint32_t vSize, |
| 52 | armnn::Decoder<float>& batchVector, |
| 53 | uint32_t nBatch, |
| 54 | armnn::Encoder<float>& outResult); |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 55 | |
| 56 | void Sub1Vector(armnn::Decoder<float>& vector, |
| 57 | uint32_t vSize, |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 58 | armnn::Encoder<float>& result); |
| 59 | |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 60 | |
| 61 | void VectorVectorCwiseProduct(armnn::Decoder<float>& vector1, |
| 62 | armnn::Decoder<float>& vector2, |
| 63 | uint32_t vSize, |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 64 | armnn::Encoder<float>& outResult); |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 65 | |
| 66 | void VectorVectorCwiseProductAccumulate(armnn::Decoder<float>& vector1, |
| 67 | armnn::Decoder<float>& vector2, |
| 68 | uint32_t vSize, |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 69 | armnn::Encoder<float>& outResult); |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 70 | |
| 71 | float Clip(float f, |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 72 | float absLimit); |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 73 | |
| 74 | void ClipVector(armnn::Decoder<float>& vector, |
| 75 | uint32_t vSize, |
| 76 | float absLimit, |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 77 | armnn::Encoder<float>& outResult); |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 78 | |
| 79 | void CopyVector(armnn::Decoder<float>& vector, |
| 80 | uint32_t vSize, |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 81 | armnn::Encoder<float>& outResult); |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 82 | |
| 83 | void SetActivationParameters(uint32_t activation, |
| 84 | armnn::ActivationFunction& outArmnnActivation, |
| 85 | float& outA, |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 86 | float& outB); |
Nattapat Chaimanowong | eb2b329 | 2019-05-07 12:02:30 +0100 | [diff] [blame] | 87 | |
James Conroy | 1f58f03 | 2021-04-27 17:13:27 +0100 | [diff] [blame] | 88 | std::unique_ptr<armnn::ScopedTensorHandle> AssignScopedTensorHandle(const armnn::ConstTensorHandle *ptr); |