telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 4 | // |
| 5 | #pragma once |
| 6 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 7 | #include "QuantizeHelper.hpp" |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 8 | #include "WorkloadTestUtils.hpp" |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 9 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 10 | #include <armnn/ArmNN.hpp> |
| 11 | #include <armnn/Tensor.hpp> |
| 12 | #include <armnn/TypesUtils.hpp> |
| 13 | |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 14 | #include <test/TensorHelpers.hpp> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 15 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 16 | #include <backendsCommon/CpuTensorHandle.hpp> |
| 17 | #include <backendsCommon/WorkloadFactory.hpp> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 18 | |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 19 | #include "reference/workloads/LstmUtils.hpp" |
| 20 | |
| 21 | //LstmUtils Tests |
| 22 | // TODO: Add tests for the remaining functions in LstmUtils.hpp |
| 23 | |
| 24 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 25 | void LstmUtilsVectorBatchVectorAddTestImpl( |
| 26 | boost::multi_array<float, 1>& vec, |
| 27 | boost::multi_array<float, 2>& batchVec, |
| 28 | uint32_t vSize, |
| 29 | uint32_t nBatch, |
| 30 | boost::multi_array<float, 2>& expectedOutput ) |
| 31 | { |
| 32 | float qScale = 0.0f; |
| 33 | int32_t qOffset = 0; |
| 34 | armnn::TensorInfo tensorInfo({nBatch, vSize}, ArmnnType, qScale, qOffset ); |
| 35 | |
| 36 | // Make encoder and decoder |
| 37 | std::unique_ptr<armnn::Decoder<float>> vecDecoder = armnn::MakeDecoder<float>(tensorInfo, vec.data()); |
| 38 | std::unique_ptr<armnn::Decoder<float>> batchVecDecoder = armnn::MakeDecoder<float>(tensorInfo, batchVec.data()); |
| 39 | std::unique_ptr<armnn::Encoder<float>> batchVecEncoder = armnn::MakeEncoder<float>(tensorInfo, batchVec.data()); |
| 40 | |
| 41 | VectorBatchVectorAdd(*vecDecoder, vSize, *batchVecDecoder, nBatch, *batchVecEncoder); |
| 42 | |
| 43 | // check shape and compare values |
| 44 | BOOST_TEST(CompareTensors(batchVec, expectedOutput)); |
| 45 | |
| 46 | // check if iterator is back at start position |
| 47 | batchVecEncoder->Set(1.0f); |
| 48 | BOOST_TEST(batchVec[0][0] == 1.0f); |
| 49 | } |
| 50 | |
| 51 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 52 | void LstmUtilsZeroVectorTestImpl( |
| 53 | boost::multi_array<float, 1>& input, |
| 54 | uint32_t vSize, |
| 55 | boost::multi_array<float, 1>& expectedOutput) { |
| 56 | |
| 57 | float qScale = 0.0f; |
| 58 | int32_t qOffset = 0; |
| 59 | |
| 60 | armnn::TensorInfo tensorInfo({vSize}, ArmnnType, qScale, qOffset ); |
| 61 | |
| 62 | // Make encoder for input |
| 63 | std::unique_ptr<armnn::Encoder<float>> outputEncoder = armnn::MakeEncoder<float>(tensorInfo, input.data()); |
| 64 | |
| 65 | // call ZeroVector |
| 66 | ZeroVector(*outputEncoder, vSize); |
| 67 | |
| 68 | // check shape and compare values |
| 69 | BOOST_TEST(CompareTensors(input, expectedOutput)); |
| 70 | |
| 71 | // check if iterator is back at start position |
| 72 | outputEncoder->Set(1.0f); |
| 73 | BOOST_TEST(input[0] == 1.0f); |
| 74 | |
| 75 | } |
| 76 | |
| 77 | |
| 78 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 79 | void LstmUtilsMeanStddevNormalizationTestImpl( |
| 80 | boost::multi_array<float, 2>& input, |
| 81 | uint32_t vSize, |
| 82 | uint32_t nBatch, |
| 83 | boost::multi_array<float, 2>& expectedOutput) |
| 84 | { |
| 85 | float qScale = 0.0f; |
| 86 | int32_t qOffset = 0; |
| 87 | armnn::TensorInfo tensorInfo({nBatch, vSize}, ArmnnType, qScale, qOffset ); |
| 88 | |
| 89 | // Make encoder and decoder for input |
| 90 | std::unique_ptr<armnn::Decoder<float>> inputDecoder = armnn::MakeDecoder<float>(tensorInfo, input.data()); |
| 91 | std::unique_ptr<armnn::Encoder<float>> outputEncoder = armnn::MakeEncoder<float>(tensorInfo, input.data()); |
| 92 | |
| 93 | MeanStddevNormalization(*inputDecoder, *outputEncoder, vSize, nBatch, 1e-8f); |
| 94 | |
| 95 | // check shape and compare values |
| 96 | BOOST_TEST(CompareTensors(input, expectedOutput)); |
| 97 | |
| 98 | // check if iterator is back at start position |
| 99 | outputEncoder->Set(1.0f); |
| 100 | BOOST_TEST(input[0][0] == 1.0f); |
| 101 | } |
| 102 | |
| 103 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 104 | void LstmUtilsVectorBatchVectorCwiseProductTestImpl( |
| 105 | boost::multi_array<float, 1>& vec, |
| 106 | boost::multi_array<float, 2>& batchVec, |
| 107 | uint32_t vSize, |
| 108 | uint32_t nBatch, |
| 109 | boost::multi_array<float, 2>& expectedOutput) |
| 110 | { |
| 111 | float qScale = 0.0f; |
| 112 | int32_t qOffset = 0; |
| 113 | armnn::TensorInfo tensorInfo({nBatch, vSize}, ArmnnType, qScale, qOffset ); |
| 114 | |
| 115 | // Make encoder and decoder |
| 116 | std::unique_ptr<armnn::Decoder<float>> vecDecoder = armnn::MakeDecoder<float>(tensorInfo, vec.data()); |
| 117 | std::unique_ptr<armnn::Decoder<float>> batchVecDecoder = armnn::MakeDecoder<float>(tensorInfo, batchVec.data()); |
| 118 | std::unique_ptr<armnn::Encoder<float>> batchVecEncoder = armnn::MakeEncoder<float>(tensorInfo, batchVec.data()); |
| 119 | |
| 120 | VectorBatchVectorCwiseProduct(*vecDecoder, vSize, *batchVecDecoder, nBatch, *batchVecEncoder); |
| 121 | |
| 122 | // check shape and compare values |
| 123 | BOOST_TEST(CompareTensors(batchVec, expectedOutput)); |
| 124 | |
| 125 | // check if iterator is back at start position |
| 126 | batchVecEncoder->Set(1.0f); |
| 127 | BOOST_TEST(batchVec[0][0] == 1.0f); |
| 128 | } |
| 129 | |
| 130 | // Lstm Layer tests: |
| 131 | |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 132 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 133 | LayerTestResult<T, 2> |
| 134 | LstmNoCifgNoPeepholeNoProjectionTestImpl( |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 135 | armnn::IWorkloadFactory& workloadFactory, |
| 136 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 137 | const boost::multi_array<T, 2>& input, |
| 138 | const boost::multi_array<T, 2>& outputExpected, |
| 139 | float qScale = 0.0f, |
| 140 | int32_t qOffset = 0, |
| 141 | armnn::DataType constantDataType = armnn::DataType::Float32) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 142 | { |
| 143 | unsigned int batchSize = boost::numeric_cast<unsigned int>(input.shape()[0]); |
| 144 | unsigned int inputSize = boost::numeric_cast<unsigned int>(input.shape()[1]); |
| 145 | unsigned int outputSize = boost::numeric_cast<unsigned int>(outputExpected.shape()[1]); |
| 146 | // cellSize and outputSize have the same size when there is no projection. |
| 147 | unsigned numUnits = outputSize; |
| 148 | |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 149 | armnn::TensorInfo inputTensorInfo({batchSize , inputSize}, ArmnnType, qScale, qOffset ); |
| 150 | armnn::TensorInfo cellStateInTensorInfo({batchSize , numUnits}, ArmnnType, qScale, qOffset); |
| 151 | armnn::TensorInfo outputStateInTensorInfo({batchSize , outputSize}, ArmnnType, qScale, qOffset); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 152 | |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 153 | armnn::TensorInfo scratchBufferTensorInfo({batchSize, numUnits * 4}, ArmnnType, qScale, qOffset); |
| 154 | armnn::TensorInfo cellStateOutTensorInfo({batchSize, numUnits}, ArmnnType, qScale, qOffset); |
| 155 | armnn::TensorInfo outputStateOutTensorInfo({batchSize, outputSize}, ArmnnType, qScale, qOffset); |
| 156 | armnn::TensorInfo outputTensorInfo({batchSize, outputSize}, ArmnnType, qScale, qOffset); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 157 | |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 158 | LayerTestResult<T, 2> ret(outputTensorInfo); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 159 | |
| 160 | std::vector<float> inputVector; |
| 161 | inputVector.assign(input.data(), input.data() + (batchSize * inputSize)); |
| 162 | auto inputTensor = MakeTensor<float,2>(inputTensorInfo, inputVector); |
| 163 | |
| 164 | std::vector<float> cellStateInVector(batchSize * numUnits, 0.f); |
| 165 | auto cellStateInTensor = MakeTensor<float,2>(cellStateInTensorInfo, cellStateInVector); |
| 166 | |
| 167 | std::vector<float> outputStateInVector(batchSize * outputSize, 0.f); |
| 168 | auto outputStateInTensor = MakeTensor<float,2>(outputStateInTensorInfo, outputStateInVector); |
| 169 | |
Matteo Martincigh | a65b7ae | 2018-11-14 12:39:55 +0000 | [diff] [blame] | 170 | std::vector<float> scratchBufferVector(batchSize * numUnits * 4, 0.f); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 171 | auto scratchBufferTensor = MakeTensor<float,2>(scratchBufferTensorInfo, scratchBufferVector); |
| 172 | |
| 173 | std::vector<float> outputStateOutVector(batchSize * outputSize, 0.f); |
| 174 | auto outputStateOutTensor = MakeTensor<float,2>(outputStateOutTensorInfo, outputStateOutVector); |
| 175 | |
| 176 | std::vector<float> cellStateOutVector(batchSize * numUnits, 0.f); |
| 177 | auto cellStateOutTensor = MakeTensor<float,2>(cellStateOutTensorInfo, cellStateOutVector); |
| 178 | |
| 179 | std::vector<float> outputVector; |
| 180 | outputVector.assign(outputExpected.data(), outputExpected.data() + (batchSize * outputSize)); |
| 181 | ret.outputExpected = MakeTensor<float, 2>(outputTensorInfo, outputVector); |
| 182 | |
| 183 | std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); |
| 184 | std::unique_ptr<armnn::ITensorHandle> cellStateInHandle = |
| 185 | workloadFactory.CreateTensorHandle(cellStateInTensorInfo); |
| 186 | std::unique_ptr<armnn::ITensorHandle> outputStateInHandle = |
| 187 | workloadFactory.CreateTensorHandle(outputStateInTensorInfo); |
| 188 | |
| 189 | std::unique_ptr<armnn::ITensorHandle> scratchHandle = workloadFactory.CreateTensorHandle(scratchBufferTensorInfo); |
| 190 | std::unique_ptr<armnn::ITensorHandle> outputStateOutHandle = |
| 191 | workloadFactory.CreateTensorHandle(outputStateOutTensorInfo); |
| 192 | std::unique_ptr<armnn::ITensorHandle> cellStateOutHandle = |
| 193 | workloadFactory.CreateTensorHandle(cellStateOutTensorInfo); |
| 194 | std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo); |
| 195 | |
| 196 | |
| 197 | armnn::LstmQueueDescriptor data; |
| 198 | armnn::WorkloadInfo info; |
| 199 | |
| 200 | AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); |
| 201 | AddInputToWorkload(data, info, outputStateInTensorInfo, outputStateInHandle.get()); |
| 202 | AddInputToWorkload(data, info, cellStateInTensorInfo, cellStateInHandle.get()); |
| 203 | |
| 204 | AddOutputToWorkload(data, info, scratchBufferTensorInfo, scratchHandle.get()); |
| 205 | AddOutputToWorkload(data, info, outputStateOutTensorInfo, outputStateOutHandle.get()); |
| 206 | AddOutputToWorkload(data, info, cellStateOutTensorInfo, cellStateOutHandle.get()); |
| 207 | AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); |
| 208 | |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 209 | armnn::TensorInfo tensorInfo4({numUnits}, constantDataType , qScale, qOffset); |
| 210 | armnn::TensorInfo tensorInfo8({numUnits, 2}, constantDataType, qScale, qOffset); |
| 211 | armnn::TensorInfo tensorInfo16({numUnits, 4}, constantDataType, qScale, qOffset); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 212 | |
| 213 | auto inputToInputWeights = MakeTensor<float, 2>(tensorInfo8, {-0.45018822f, -0.02338299f, -0.0870589f, |
| 214 | -0.34550029f, 0.04266912f, -0.15680569f, |
| 215 | -0.34856534f, 0.43890524f}); |
| 216 | |
| 217 | auto inputToForgetWeights = MakeTensor<float, 2>(tensorInfo8, {0.09701663f, 0.20334584f, -0.50592935f, |
| 218 | -0.31343272f, -0.40032279f, 0.44781327f, |
| 219 | 0.01387155f, -0.35593212f}); |
| 220 | |
| 221 | auto inputToCellWeights = MakeTensor<float, 2>(tensorInfo8, {-0.50013041f, 0.1370284f, 0.11810488f, 0.2013163f, |
| 222 | -0.20583314f, 0.44344562f, 0.22077113f, |
| 223 | -0.29909778f}); |
| 224 | |
| 225 | auto inputToOutputWeights = MakeTensor<float, 2>(tensorInfo8, {-0.25065863f, -0.28290087f, 0.04613829f, |
| 226 | 0.40525138f, 0.44272184f, 0.03897077f, |
| 227 | -0.1556896f, 0.19487578f}); |
| 228 | |
| 229 | auto recurrentToInputWeights = MakeTensor<float, 2>(tensorInfo16, {-0.0063535f, -0.2042388f, 0.31454784f, |
| 230 | -0.35746509f, 0.28902304f, 0.08183324f, |
| 231 | -0.16555229f, 0.02286911f, -0.13566875f, |
| 232 | 0.03034258f, 0.48091322f, -0.12528998f, |
| 233 | 0.24077177f, -0.51332325f, -0.33502164f, |
| 234 | 0.10629296f}); |
| 235 | |
| 236 | auto recurrentToForgetWeights = MakeTensor<float, 2>(tensorInfo16, {-0.48684245f, -0.06655136f, 0.42224967f, |
| 237 | 0.2112639f, 0.27654213f, 0.20864892f, |
| 238 | -0.07646349f, 0.45877004f, 0.00141793f, |
| 239 | -0.14609534f, 0.36447752f, 0.09196436f, |
| 240 | 0.28053468f, 0.01560611f, -0.20127171f, |
| 241 | -0.01140004f}); |
| 242 | |
| 243 | auto recurrentToCellWeights = MakeTensor<float, 2>(tensorInfo16, {-0.3407414f, 0.24443203f, -0.2078532f, |
| 244 | 0.26320225f, 0.05695659f, -0.00123841f, |
| 245 | -0.4744786f, -0.35869038f, -0.06418842f, |
| 246 | -0.13502428f, -0.501764f, 0.22830659f, |
| 247 | -0.46367589f, 0.26016325f, -0.03894562f, |
| 248 | -0.16368064f}); |
| 249 | |
| 250 | auto recurrentToOutputWeights = MakeTensor<float, 2>(tensorInfo16, {0.43385774f, -0.17194885f, 0.2718237f, |
| 251 | 0.09215671f, 0.24107647f, -0.39835793f, |
| 252 | 0.18212086f, 0.01301402f, 0.48572797f, |
| 253 | -0.50656658f, 0.20047462f, -0.20607421f, |
| 254 | -0.51818722f, -0.15390486f, 0.0468148f, |
| 255 | 0.39922136f}); |
| 256 | |
| 257 | auto cellToInputWeights = MakeTensor<float, 1>(tensorInfo4, {0., 0., 0., 0.}); |
| 258 | |
| 259 | auto inputGateBias = MakeTensor<float, 1>(tensorInfo4, {0., 0., 0., 0.}); |
| 260 | |
| 261 | auto forgetGateBias = MakeTensor<float, 1>(tensorInfo4, {1., 1., 1., 1.}); |
| 262 | |
| 263 | auto cellBias = MakeTensor<float, 1>(tensorInfo4, {0., 0., 0., 0.}); |
| 264 | |
| 265 | auto outputGateBias = MakeTensor<float, 1>(tensorInfo4, {0., 0., 0., 0.}); |
| 266 | |
| 267 | armnn::ScopedCpuTensorHandle inputToInputWeightsTensor(tensorInfo8); |
| 268 | armnn::ScopedCpuTensorHandle inputToForgetWeightsTensor(tensorInfo8); |
| 269 | armnn::ScopedCpuTensorHandle inputToCellWeightsTensor(tensorInfo8); |
| 270 | armnn::ScopedCpuTensorHandle inputToOutputWeightsTensor(tensorInfo8); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 271 | armnn::ScopedCpuTensorHandle recurrentToInputWeightsTensor(tensorInfo16); |
Matteo Martincigh | a65b7ae | 2018-11-14 12:39:55 +0000 | [diff] [blame] | 272 | armnn::ScopedCpuTensorHandle recurrentToForgetWeightsTensor(tensorInfo16); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 273 | armnn::ScopedCpuTensorHandle recurrentToCellWeightsTensor(tensorInfo16); |
| 274 | armnn::ScopedCpuTensorHandle recurrentToOutputWeightsTensor(tensorInfo16); |
| 275 | armnn::ScopedCpuTensorHandle cellToInputWeightsTensor(tensorInfo4); |
| 276 | armnn::ScopedCpuTensorHandle inputGateBiasTensor(tensorInfo4); |
| 277 | armnn::ScopedCpuTensorHandle forgetGateBiasTensor(tensorInfo4); |
| 278 | armnn::ScopedCpuTensorHandle cellBiasTensor(tensorInfo4); |
| 279 | armnn::ScopedCpuTensorHandle outputGateBiasTensor(tensorInfo4); |
| 280 | |
| 281 | AllocateAndCopyDataToITensorHandle(&inputToInputWeightsTensor, &inputToInputWeights[0][0]); |
| 282 | AllocateAndCopyDataToITensorHandle(&inputToForgetWeightsTensor, &inputToForgetWeights[0][0]); |
| 283 | AllocateAndCopyDataToITensorHandle(&inputToCellWeightsTensor, &inputToCellWeights[0][0]); |
| 284 | AllocateAndCopyDataToITensorHandle(&inputToOutputWeightsTensor, &inputToOutputWeights[0][0]); |
| 285 | AllocateAndCopyDataToITensorHandle(&recurrentToInputWeightsTensor, &recurrentToInputWeights[0][0]); |
| 286 | AllocateAndCopyDataToITensorHandle(&recurrentToForgetWeightsTensor, &recurrentToForgetWeights[0][0]); |
| 287 | AllocateAndCopyDataToITensorHandle(&recurrentToCellWeightsTensor, &recurrentToCellWeights[0][0]); |
| 288 | AllocateAndCopyDataToITensorHandle(&recurrentToOutputWeightsTensor, &recurrentToOutputWeights[0][0]); |
| 289 | AllocateAndCopyDataToITensorHandle(&cellToInputWeightsTensor, &cellToInputWeights[0]); |
| 290 | AllocateAndCopyDataToITensorHandle(&inputGateBiasTensor, &inputGateBias[0]); |
| 291 | AllocateAndCopyDataToITensorHandle(&forgetGateBiasTensor, &forgetGateBias[0]); |
| 292 | AllocateAndCopyDataToITensorHandle(&cellBiasTensor, &cellBias[0]); |
| 293 | AllocateAndCopyDataToITensorHandle(&outputGateBiasTensor, &outputGateBias[0]); |
| 294 | |
| 295 | data.m_InputToInputWeights = &inputToInputWeightsTensor; |
| 296 | data.m_InputToForgetWeights = &inputToForgetWeightsTensor; |
| 297 | data.m_InputToCellWeights = &inputToCellWeightsTensor; |
| 298 | data.m_InputToOutputWeights = &inputToOutputWeightsTensor; |
| 299 | data.m_RecurrentToInputWeights = &recurrentToInputWeightsTensor; |
| 300 | data.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor; |
| 301 | data.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor; |
| 302 | data.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 303 | data.m_InputGateBias = &inputGateBiasTensor; |
| 304 | data.m_ForgetGateBias = &forgetGateBiasTensor; |
| 305 | data.m_CellBias = &cellBiasTensor; |
| 306 | data.m_OutputGateBias = &outputGateBiasTensor; |
| 307 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 308 | // Flags to set test configuration |
| 309 | data.m_Parameters.m_ActivationFunc = 4; |
| 310 | data.m_Parameters.m_CifgEnabled = false; |
| 311 | data.m_Parameters.m_PeepholeEnabled = false; |
| 312 | data.m_Parameters.m_ProjectionEnabled = false; |
| 313 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 314 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateLstm(data, info); |
| 315 | inputHandle->Allocate(); |
| 316 | outputStateInHandle->Allocate(); |
| 317 | cellStateInHandle->Allocate(); |
| 318 | |
| 319 | scratchHandle->Allocate(); |
| 320 | outputStateOutHandle->Allocate(); |
| 321 | cellStateOutHandle->Allocate(); |
| 322 | outputHandle->Allocate(); |
| 323 | |
| 324 | CopyDataToITensorHandle(inputHandle.get(), &inputTensor[0][0]); |
| 325 | CopyDataToITensorHandle(outputStateInHandle.get(), &outputStateInTensor[0][0]); |
| 326 | CopyDataToITensorHandle(cellStateInHandle.get(), &cellStateInTensor[0][0]); |
| 327 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 328 | workload->Execute(); |
| 329 | |
| 330 | CopyDataFromITensorHandle(&ret.output[0][0], outputHandle.get()); |
| 331 | |
| 332 | return ret; |
| 333 | } |
| 334 | |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 335 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 336 | LayerTestResult<T, 2> |
Matteo Martincigh | a65b7ae | 2018-11-14 12:39:55 +0000 | [diff] [blame] | 337 | LstmLayerNoCifgWithPeepholeWithProjectionTestImpl(armnn::IWorkloadFactory& workloadFactory, |
| 338 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 339 | const boost::multi_array<T, 2>& input, |
| 340 | const boost::multi_array<T, 2>& outputExpected, |
| 341 | float qScale = 0.0f, |
| 342 | int32_t qOffset = 0, |
| 343 | armnn::DataType constantDataType = armnn::DataType::Float32) |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 344 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 345 | unsigned int batchSize = 2; |
| 346 | unsigned int outputSize = 16; |
| 347 | unsigned int inputSize = 5; |
| 348 | unsigned numUnits = 20; |
| 349 | |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 350 | armnn::TensorInfo inputTensorInfo({batchSize , inputSize}, ArmnnType, qScale, qOffset); |
| 351 | armnn::TensorInfo cellStateInTensorInfo({batchSize , numUnits}, ArmnnType, qScale, qOffset); |
| 352 | armnn::TensorInfo outputStateInTensorInfo({batchSize , outputSize}, ArmnnType, qScale, qOffset); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 353 | |
Matteo Martincigh | a65b7ae | 2018-11-14 12:39:55 +0000 | [diff] [blame] | 354 | // Scratch buffer size without CIFG [batchSize, numUnits * 4] |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 355 | armnn::TensorInfo scratchBufferTensorInfo({batchSize, numUnits * 4}, ArmnnType, qScale, qOffset); |
| 356 | armnn::TensorInfo cellStateOutTensorInfo({batchSize, numUnits}, ArmnnType, qScale, qOffset); |
| 357 | armnn::TensorInfo outputStateOutTensorInfo({batchSize, outputSize}, ArmnnType, qScale, qOffset); |
| 358 | armnn::TensorInfo outputTensorInfo({batchSize, outputSize}, ArmnnType, qScale, qOffset); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 359 | |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 360 | LayerTestResult<T, 2> ret(outputTensorInfo); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 361 | |
| 362 | std::vector<float> inputVector; |
| 363 | inputVector.assign(input.data(), input.data() + (batchSize * inputSize)); |
| 364 | auto inputTensor = MakeTensor<float,2>(inputTensorInfo, inputVector); |
| 365 | |
| 366 | std::vector<float> cellStateInVector(batchSize * numUnits, 0.f); |
| 367 | auto cellStateInTensor = MakeTensor<float,2>(cellStateInTensorInfo, cellStateInVector); |
| 368 | |
| 369 | std::vector<float> outputStateInVector(batchSize * outputSize, 0.f); |
| 370 | auto outputStateInTensor = MakeTensor<float,2>(outputStateInTensorInfo, outputStateInVector); |
| 371 | |
Matteo Martincigh | a65b7ae | 2018-11-14 12:39:55 +0000 | [diff] [blame] | 372 | std::vector<float> scratchBufferVector(batchSize * numUnits * 4, 0.f); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 373 | auto scratchBufferTensor = MakeTensor<float,2>(scratchBufferTensorInfo, scratchBufferVector); |
| 374 | |
| 375 | std::vector<float> outputStateOutVector(batchSize * outputSize, 0.f); |
| 376 | auto outputStateOutTensor = MakeTensor<float,2>(outputStateOutTensorInfo, outputStateOutVector); |
| 377 | |
| 378 | std::vector<float> cellStateOutVector(batchSize * numUnits, 0.f); |
| 379 | auto cellStateOutTensor = MakeTensor<float,2>(cellStateOutTensorInfo, cellStateOutVector); |
| 380 | |
| 381 | std::vector<float> outputVector; |
| 382 | outputVector.assign(outputExpected.data(), outputExpected.data() + (batchSize * outputSize)); |
| 383 | ret.outputExpected = MakeTensor<float, 2>(outputTensorInfo, outputVector); |
| 384 | |
| 385 | std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); |
| 386 | std::unique_ptr<armnn::ITensorHandle> cellStateInHandle = |
| 387 | workloadFactory.CreateTensorHandle(cellStateInTensorInfo); |
| 388 | std::unique_ptr<armnn::ITensorHandle> outputStateInHandle = |
| 389 | workloadFactory.CreateTensorHandle(outputStateInTensorInfo); |
| 390 | |
| 391 | std::unique_ptr<armnn::ITensorHandle> scratchHandle = workloadFactory.CreateTensorHandle(scratchBufferTensorInfo); |
| 392 | std::unique_ptr<armnn::ITensorHandle> outputStateOutHandle = |
| 393 | workloadFactory.CreateTensorHandle(outputStateOutTensorInfo); |
| 394 | std::unique_ptr<armnn::ITensorHandle> cellStateOutHandle = |
| 395 | workloadFactory.CreateTensorHandle(cellStateOutTensorInfo); |
| 396 | std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo); |
| 397 | |
| 398 | armnn::LstmQueueDescriptor data; |
| 399 | armnn::WorkloadInfo info; |
| 400 | |
| 401 | AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); |
| 402 | AddInputToWorkload(data, info, outputStateInTensorInfo, outputStateInHandle.get()); |
| 403 | AddInputToWorkload(data, info, cellStateInTensorInfo, cellStateInHandle.get()); |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 404 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 405 | AddOutputToWorkload(data, info, scratchBufferTensorInfo, scratchHandle.get()); |
| 406 | AddOutputToWorkload(data, info, outputStateOutTensorInfo, outputStateOutHandle.get()); |
| 407 | AddOutputToWorkload(data, info, cellStateOutTensorInfo, cellStateOutHandle.get()); |
| 408 | AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); |
| 409 | |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 410 | armnn::TensorInfo tensorInfo16({outputSize}, constantDataType, qScale, qOffset); |
| 411 | armnn::TensorInfo tensorInfo20({numUnits}, constantDataType, qScale, qOffset); |
| 412 | armnn::TensorInfo tensorInfo20x5({numUnits, inputSize}, constantDataType, qScale, qOffset); |
| 413 | armnn::TensorInfo tensorInfo20x16({numUnits, outputSize}, constantDataType, qScale, qOffset); |
| 414 | armnn::TensorInfo tensorInfo16x20({outputSize, numUnits}, constantDataType, qScale, qOffset); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 415 | |
| 416 | auto inputToInputWeights = |
| 417 | MakeTensor<float, 2>(tensorInfo20x5, {0.021393683f,0.06124551f, 0.046905167f,-0.014657677f,-0.03149463f, |
| 418 | 0.09171803f, 0.14647801f,0.10797193f, -0.0057968358f,0.0019193048f, |
| 419 | -0.2726754f, 0.10154029f, -0.018539885f, 0.080349885f, -0.10262385f, |
| 420 | -0.022599787f,-0.09121155f, -0.008675967f, -0.045206103f,-0.0821282f, |
| 421 | -0.008045952f,0.015478081f, 0.055217247f, 0.038719587f, 0.044153627f, |
| 422 | -0.06453243f,0.05031825f, -0.046935108f, -0.008164439f, 0.014574226f, |
| 423 | -0.1671009f, -0.15519552f, -0.16819797f,-0.13971269f,-0.11953059f, |
| 424 | 0.25005487f, -0.22790983f, 0.009855087f, -0.028140958f, -0.11200698f, |
| 425 | 0.11295408f, -0.0035217577f, 0.054485075f, 0.05184695f, 0.064711206f, |
| 426 | 0.10989193f, 0.11674786f, 0.03490607f, 0.07727357f, 0.11390585f, |
| 427 | -0.1863375f, -0.1034451f, -0.13945189f, -0.049401227f, -0.18767063f, |
| 428 | 0.042483903f, 0.14233552f, 0.13832581f, 0.18350165f, 0.14545603f, |
| 429 | -0.028545704f,0.024939531f,0.050929718f,0.0076203286f,-0.0029723682f, |
| 430 | -0.042484224f, -0.11827596f, -0.09171104f, -0.10808628f,-0.16327988f, |
| 431 | -0.2273378f, -0.0993647f, -0.017155107f,0.0023917493f,0.049272764f, |
| 432 | 0.0038534778f, 0.054764505f, 0.089753784f, 0.06947234f, 0.08014476f, |
| 433 | -0.04544234f, -0.0497073f,-0.07135631f, -0.048929106f,-0.004042012f, |
| 434 | -0.009284026f, 0.018042054f, 0.0036860977f,-0.07427302f, -0.11434604f, |
| 435 | -0.018995456f, 0.031487543f, 0.012834908f,0.019977754f,0.044256654f, |
| 436 | -0.39292613f, -0.18519334f, -0.11651281f,-0.06809892f, 0.011373677f |
| 437 | }); |
| 438 | |
| 439 | auto inputToForgetWeights = |
| 440 | MakeTensor<float, 2>(tensorInfo20x5, {-0.0018401089f, -0.004852237f,0.03698424f, 0.014181704f,0.028273236f, |
| 441 | -0.016726194f, -0.05249759f,-0.10204261f, 0.00861066f,-0.040979505f, |
| 442 | -0.009899187f,0.01923892f,-0.028177269f, -0.08535103f,-0.14585495f, |
| 443 | 0.10662567f,-0.01909731f,-0.017883534f,-0.0047269356f,-0.045103323f, |
| 444 | 0.0030784295f,0.076784775f,0.07463696f, 0.094531395f,0.0814421f, |
| 445 | -0.12257899f, -0.033945758f,-0.031303465f, 0.045630626f,0.06843887f, |
| 446 | -0.13492945f, -0.012480007f,-0.0811829f, -0.07224499f,-0.09628791f, |
| 447 | 0.045100946f,0.0012300825f, 0.013964662f, 0.099372394f,0.02543059f, |
| 448 | 0.06958324f, 0.034257296f, 0.0482646f, 0.06267997f,0.052625068f, |
| 449 | 0.12784666f, 0.07077897f, 0.025725935f, 0.04165009f,0.07241905f, |
| 450 | 0.018668644f, -0.037377294f,-0.06277783f,-0.08833636f,-0.040120605f, |
| 451 | -0.011405586f,-0.007808335f,-0.010301386f,-0.005102167f,0.027717464f, |
| 452 | 0.05483423f, 0.11449111f, 0.11289652f,0.10939839f, 0.13396506f, |
| 453 | -0.08402166f,-0.01901462f, -0.044678304f,-0.07720565f,0.014350063f, |
| 454 | -0.11757958f, -0.0652038f, -0.08185733f,-0.076754324f,-0.092614375f, |
| 455 | 0.10405491f, 0.052960336f, 0.035755895f,0.035839386f,-0.012540553f, |
| 456 | 0.036881298f, 0.02913376f, 0.03420159f,0.05448447f,-0.054523353f, |
| 457 | 0.02582715f, 0.02327355f, -0.011857179f,-0.0011980024f,-0.034641717f, |
| 458 | -0.026125094f,-0.17582615f,-0.15923657f,-0.27486774f,-0.0006143371f, |
| 459 | 0.0001771948f, -8.470171e-05f, 0.02651807f,0.045790765f,0.06956496f |
| 460 | }); |
| 461 | |
| 462 | auto inputToCellWeights = |
| 463 | MakeTensor<float, 2>(tensorInfo20x5, {-0.04580283f, -0.09549462f, -0.032418985f, -0.06454633f, |
| 464 | -0.043528453f, 0.043018587f, -0.049152344f, -0.12418144f, |
| 465 | -0.078985475f, -0.07596889f, 0.019484362f, -0.11434962f, |
| 466 | -0.0074034138f, -0.06314844f, -0.092981495f, 0.0062155537f, |
| 467 | -0.025034338f, -0.0028890965f, 0.048929527f, 0.06235075f, |
| 468 | 0.10665918f, -0.032036792f, -0.08505916f, -0.10843358f, |
| 469 | -0.13002433f, -0.036816437f, -0.02130134f, -0.016518239f, |
| 470 | 0.0047691227f, -0.0025825808f, 0.066017866f, 0.029991534f, |
| 471 | -0.10652836f, -0.1037554f, -0.13056071f, -0.03266643f, |
| 472 | -0.033702414f, -0.006473424f, -0.04611692f, 0.014419339f, |
| 473 | -0.025174323f, 0.0396852f, 0.081777506f, 0.06157468f, |
| 474 | 0.10210095f, -0.009658194f, 0.046511717f, 0.03603906f, |
| 475 | 0.0069369148f, 0.015960095f, -0.06507666f, 0.09551598f, |
| 476 | 0.053568836f, 0.06408714f, 0.12835667f, -0.008714329f, |
| 477 | -0.20211966f, -0.12093674f, 0.029450472f, 0.2849013f, |
| 478 | -0.029227901f, 0.1164364f, -0.08560263f, 0.09941786f, |
| 479 | -0.036999565f, -0.028842626f, -0.0033637602f, -0.017012902f, |
| 480 | -0.09720865f, -0.11193351f, -0.029155117f, -0.017936034f, |
| 481 | -0.009768936f, -0.04223324f, -0.036159635f, 0.06505112f, |
| 482 | -0.021742892f, -0.023377212f, -0.07221364f, -0.06430552f, |
| 483 | 0.05453865f, 0.091149814f, 0.06387331f, 0.007518393f, |
| 484 | 0.055960953f, 0.069779344f, 0.046411168f, 0.10509911f, |
| 485 | 0.07463894f, 0.0075130584f, 0.012850982f, 0.04555431f, |
| 486 | 0.056955688f, 0.06555285f, 0.050801456f, -0.009862683f, |
| 487 | 0.00826772f, -0.026555609f, -0.0073611983f, -0.0014897042f |
| 488 | }); |
| 489 | |
| 490 | auto inputToOutputWeights = |
| 491 | MakeTensor<float, 2>(tensorInfo20x5, {-0.0998932f, -0.07201956f, -0.052803773f,-0.15629593f,-0.15001918f, |
| 492 | -0.07650751f,0.02359855f, -0.075155355f, -0.08037709f, -0.15093534f, |
| 493 | 0.029517552f, -0.04751393f, 0.010350531f,-0.02664851f, -0.016839722f, |
| 494 | -0.023121163f, 0.0077019283f, 0.012851257f, -0.05040649f,-0.0129761f, |
| 495 | -0.021737747f,-0.038305793f,-0.06870586f, -0.01481247f,-0.001285394f, |
| 496 | 0.10124236f, 0.083122835f, 0.053313006f,-0.062235646f,-0.075637154f, |
| 497 | -0.027833903f, 0.029774971f, 0.1130802f, 0.09218906f, 0.09506135f, |
| 498 | -0.086665764f,-0.037162706f,-0.038880914f,-0.035832845f,-0.014481564f, |
| 499 | -0.09825003f,-0.12048569f,-0.097665586f,-0.05287633f, -0.0964047f, |
| 500 | -0.11366429f, 0.035777505f, 0.13568819f, 0.052451383f,0.050649304f, |
| 501 | 0.05798951f, -0.021852335f,-0.099848844f,0.014740475f,-0.078897946f, |
| 502 | 0.04974699f, 0.014160473f, 0.06973932f, 0.04964942f, 0.033364646f, |
| 503 | 0.08190124f, 0.025535367f, 0.050893165f, 0.048514254f,0.06945813f, |
| 504 | -0.078907564f,-0.06707616f, -0.11844508f, -0.09986688f,-0.07509403f, |
| 505 | 0.06263226f, 0.14925587f, 0.20188436f, 0.12098451f,0.14639415f, |
| 506 | 0.0015017595f, -0.014267382f, -0.03417257f,0.012711468f,0.0028300495f, |
| 507 | -0.024758482f, -0.05098548f,-0.0821182f, 0.014225672f, 0.021544158f, |
| 508 | 0.08949725f, 0.07505268f, -0.0020780868f, 0.04908258f,0.06476295f, |
| 509 | -0.022907063f,0.027562456f,0.040185735f, 0.019567577f,-0.015598739f, |
| 510 | -0.049097303f, -0.017121866f, -0.083368234f,-0.02332002f,-0.0840956f |
| 511 | }); |
| 512 | |
| 513 | auto inputGateBias = |
| 514 | MakeTensor<float, 1>(tensorInfo20, {0.02234832f, 0.14757581f, 0.18176508f, 0.10380666f, 0.053110216f, |
| 515 | -0.06928846f, -0.13942584f, -0.11816189f, 0.19483899f, 0.03652339f, |
| 516 | -0.10250295f, 0.036714908f, -0.18426876f, 0.036065217f, 0.21810818f, |
| 517 | 0.02383196f, -0.043370757f, 0.08690144f, -0.04444982f, 0.00030581196f |
| 518 | }); |
| 519 | |
| 520 | auto forgetGateBias = |
| 521 | MakeTensor<float, 1>(tensorInfo20, {0.035185695f, -0.042891346f, -0.03032477f, 0.23027696f, |
| 522 | 0.11098921f, 0.15378423f, 0.09263801f, 0.09790885f, |
| 523 | 0.09508917f, 0.061199076f, 0.07665568f, -0.015443159f, |
| 524 | -0.03499149f, 0.046190713f, 0.08895977f, 0.10899629f, |
| 525 | 0.40694186f, 0.06030037f, 0.012413437f, -0.06108739f |
| 526 | }); |
| 527 | |
| 528 | auto cellBias = |
| 529 | MakeTensor<float, 1>(tensorInfo20, {-0.024379363f, 0.0055531194f, 0.23377132f, 0.033463873f, |
| 530 | -0.1483596f, -0.10639995f, -0.091433935f, 0.058573797f, |
| 531 | -0.06809782f, -0.07889636f, -0.043246906f, -0.09829136f, |
| 532 | -0.4279842f, 0.034901652f, 0.18797937f, 0.0075234566f, |
| 533 | 0.016178843f, 0.1749513f, 0.13975595f, 0.92058027f |
| 534 | }); |
| 535 | |
| 536 | auto outputGateBias = |
| 537 | MakeTensor<float, 1>(tensorInfo20, {0.046159424f, -0.0012809046f, 0.03563469f, 0.12648113f, 0.027195795f, |
| 538 | 0.35373217f, -0.018957434f, 0.008907322f, -0.0762701f, 0.12018895f, |
| 539 | 0.04216877f, 0.0022856654f, 0.040952638f, 0.3147856f, 0.08225149f, |
| 540 | -0.057416286f, -0.14995944f, -0.008040261f, 0.13208859f, 0.029760877f |
| 541 | }); |
| 542 | |
| 543 | auto recurrentToInputWeights = |
| 544 | MakeTensor<float, 2>(tensorInfo20x16, {-0.001374326f, -0.078856036f, 0.10672688f, 0.029162422f, |
| 545 | -0.11585556f, 0.02557986f, -0.13446963f, -0.035785314f, |
| 546 | -0.01244275f, 0.025961924f, -0.02337298f, -0.044228926f, |
| 547 | -0.055839065f, -0.046598054f, -0.010546039f, -0.06900766f, |
| 548 | 0.027239809f, 0.022582639f, -0.013296484f, -0.05459212f, |
| 549 | 0.08981f, -0.045407712f, 0.08682226f, -0.06867011f, |
| 550 | -0.14390695f, -0.02916037f, 0.000996957f, 0.091420636f, |
| 551 | 0.14283475f, -0.07390571f, -0.06402044f, 0.062524505f, |
| 552 | -0.093129106f, 0.04860203f, -0.08364217f, -0.08119002f, |
| 553 | 0.009352075f, 0.22920375f, 0.0016303885f, 0.11583097f, |
| 554 | -0.13732095f, 0.012405723f, -0.07551853f, 0.06343048f, |
| 555 | 0.12162708f, -0.031923793f, -0.014335606f, 0.01790974f, |
| 556 | -0.10650317f, -0.0724401f, 0.08554849f, -0.05727212f, |
| 557 | 0.06556731f, -0.042729504f, -0.043227166f, 0.011683251f, |
| 558 | -0.013082158f, -0.029302018f, -0.010899579f, -0.062036745f, |
| 559 | -0.022509435f, -0.00964907f, -0.01567329f, 0.04260106f, |
| 560 | -0.07787477f, -0.11576462f, 0.017356863f, 0.048673786f, |
| 561 | -0.017577527f, -0.05527947f, -0.082487635f, -0.040137455f, |
| 562 | -0.10820036f, -0.04666372f, 0.022746278f, -0.07851417f, |
| 563 | 0.01068115f, 0.032956902f, 0.022433773f, 0.0026891115f, |
| 564 | 0.08944216f, -0.0685835f, 0.010513544f, 0.07228705f, |
| 565 | 0.02032331f, -0.059686817f, -0.0005566496f, -0.086984694f, |
| 566 | 0.040414046f, -0.1380399f, 0.094208956f, -0.05722982f, |
| 567 | 0.012092817f, -0.04989123f, -0.086576f, -0.003399834f, |
| 568 | -0.04696032f, -0.045747425f, 0.10091314f, 0.048676282f, |
| 569 | -0.029037097f, 0.031399418f, -0.0040285117f, 0.047237843f, |
| 570 | 0.09504992f, 0.041799378f, -0.049185462f, -0.031518843f, |
| 571 | -0.10516937f, 0.026374253f, 0.10058866f, -0.0033195973f, |
| 572 | -0.041975245f, 0.0073591834f, 0.0033782164f, -0.004325073f, |
| 573 | -0.10167381f, 0.042500053f, -0.01447153f, 0.06464186f, |
| 574 | -0.017142897f, 0.03312627f, 0.009205989f, 0.024138335f, |
| 575 | -0.011337001f, 0.035530265f, -0.010912711f, 0.0706555f, |
| 576 | -0.005894094f, 0.051841937f, -0.1401738f, -0.02351249f, |
| 577 | 0.0365468f, 0.07590991f, 0.08838724f, 0.021681072f, |
| 578 | -0.10086113f, 0.019608743f, -0.06195883f, 0.077335775f, |
| 579 | 0.023646897f, -0.095322326f, 0.02233014f, 0.09756986f, |
| 580 | -0.048691444f, -0.009579111f, 0.07595467f, 0.11480546f, |
| 581 | -0.09801813f, 0.019894179f, 0.08502348f, 0.004032281f, |
| 582 | 0.037211012f, 0.068537936f, -0.048005626f, -0.091520436f, |
| 583 | -0.028379958f, -0.01556313f, 0.06554592f, -0.045599163f, |
| 584 | -0.01672207f, -0.020169014f, -0.011877351f, -0.20212261f, |
| 585 | 0.010889619f, 0.0047078193f, 0.038385306f, 0.08540671f, |
| 586 | -0.017140968f, -0.0035865551f, 0.016678626f, 0.005633034f, |
| 587 | 0.015963363f, 0.00871737f, 0.060130805f, 0.028611384f, |
| 588 | 0.10109069f, -0.015060172f, -0.07894427f, 0.06401885f, |
| 589 | 0.011584063f, -0.024466386f, 0.0047652307f, -0.09041358f, |
| 590 | 0.030737216f, -0.0046374933f, 0.14215417f, -0.11823516f, |
| 591 | 0.019899689f, 0.006106124f, -0.027092824f, 0.0786356f, |
| 592 | 0.05052217f, -0.058925f, -0.011402121f, -0.024987547f, |
| 593 | -0.0013661642f, -0.06832946f, -0.015667673f, -0.1083353f, |
| 594 | -0.00096863037f, -0.06988685f, -0.053350925f, -0.027275559f, |
| 595 | -0.033664223f, -0.07978348f, -0.025200296f, -0.017207067f, |
| 596 | -0.058403496f, -0.055697463f, 0.005798788f, 0.12965427f, |
| 597 | -0.062582195f, 0.0013350133f, -0.10482091f, 0.0379771f, |
| 598 | 0.072521195f, -0.0029455067f, -0.13797039f, -0.03628521f, |
| 599 | 0.013806405f, -0.017858358f, -0.01008298f, -0.07700066f, |
| 600 | -0.017081132f, 0.019358726f, 0.0027079724f, 0.004635139f, |
| 601 | 0.062634714f, -0.02338735f, -0.039547626f, -0.02050681f, |
| 602 | 0.03385117f, -0.083611414f, 0.002862572f, -0.09421313f, |
| 603 | 0.058618143f, -0.08598433f, 0.00972939f, 0.023867095f, |
| 604 | -0.053934585f, -0.023203006f, 0.07452513f, -0.048767887f, |
| 605 | -0.07314807f, -0.056307215f, -0.10433547f, -0.06440842f, |
| 606 | 0.04328182f, 0.04389765f, -0.020006588f, -0.09076438f, |
| 607 | -0.11652589f, -0.021705797f, 0.03345259f, -0.010329105f, |
| 608 | -0.025767034f, 0.013057034f, -0.07316461f, -0.10145612f, |
| 609 | 0.06358255f, 0.18531723f, 0.07759293f, 0.12006465f, |
| 610 | 0.1305557f, 0.058638252f, -0.03393652f, 0.09622831f, |
| 611 | -0.16253184f, -2.4580743e-06f, 0.079869635f, -0.070196845f, |
| 612 | -0.005644518f, 0.06857898f, -0.12598175f, -0.035084512f, |
| 613 | 0.03156317f, -0.12794146f, -0.031963028f, 0.04692781f, |
| 614 | 0.030070418f, 0.0071660685f, -0.095516115f, -0.004643372f, |
| 615 | 0.040170413f, -0.062104587f, -0.0037324072f, 0.0554317f, |
| 616 | 0.08184801f, -0.019164372f, 0.06791302f, 0.034257166f, |
| 617 | -0.10307039f, 0.021943003f, 0.046745934f, 0.0790918f, |
| 618 | -0.0265588f, -0.007824208f, 0.042546265f, -0.00977924f, |
| 619 | -0.0002440307f, -0.017384544f, -0.017990116f, 0.12252321f, |
| 620 | -0.014512694f, -0.08251313f, 0.08861942f, 0.13589665f, |
| 621 | 0.026351685f, 0.012641483f, 0.07466548f, 0.044301085f, |
| 622 | -0.045414884f, -0.051112458f, 0.03444247f, -0.08502782f, |
| 623 | -0.04106223f, -0.028126027f, 0.028473156f, 0.10467447f |
| 624 | }); |
| 625 | |
| 626 | auto recurrentToForgetWeights = |
| 627 | MakeTensor<float, 2>(tensorInfo20x16, {-0.057784554f, -0.026057621f, -0.068447545f, -0.022581743f, |
| 628 | 0.14811787f, 0.10826372f, 0.09471067f, 0.03987225f, |
| 629 | -0.0039523416f, 0.00030638507f, 0.053185795f, 0.10572994f, |
| 630 | 0.08414449f, -0.022036452f, -0.00066928595f, -0.09203576f, |
| 631 | 0.032950465f, -0.10985798f, -0.023809856f, 0.0021431844f, |
| 632 | -0.02196096f, -0.00326074f, 0.00058621005f, -0.074678116f, |
| 633 | -0.06193199f, 0.055729095f, 0.03736828f, 0.020123724f, |
| 634 | 0.061878487f, -0.04729229f, 0.034919553f, -0.07585433f, |
| 635 | -0.04421272f, -0.044019096f, 0.085488975f, 0.04058006f, |
| 636 | -0.06890133f, -0.030951202f, -0.024628663f, -0.07672815f, |
| 637 | 0.034293607f, 0.08556707f, -0.05293577f, -0.033561368f, |
| 638 | -0.04899627f, 0.0241671f, 0.015736353f, -0.095442444f, |
| 639 | -0.029564252f, 0.016493602f, -0.035026584f, 0.022337519f, |
| 640 | -0.026871363f, 0.004780428f, 0.0077918363f, -0.03601621f, |
| 641 | 0.016435321f, -0.03263031f, -0.09543275f, -0.047392778f, |
| 642 | 0.013454138f, 0.028934088f, 0.01685226f, -0.086110644f, |
| 643 | -0.046250615f, -0.01847454f, 0.047608484f, 0.07339695f, |
| 644 | 0.034546845f, -0.04881143f, 0.009128804f, -0.08802852f, |
| 645 | 0.03761666f, 0.008096139f, -0.014454086f, 0.014361001f, |
| 646 | -0.023502491f, -0.0011840804f, -0.07607001f, 0.001856849f, |
| 647 | -0.06509276f, -0.006021153f, -0.08570962f, -0.1451793f, |
| 648 | 0.060212336f, 0.055259194f, 0.06974018f, 0.049454916f, |
| 649 | -0.027794661f, -0.08077226f, -0.016179763f, 0.1169753f, |
| 650 | 0.17213494f, -0.0056326236f, -0.053934924f, -0.0124349f, |
| 651 | -0.11520337f, 0.05409887f, 0.088759385f, 0.0019655675f, |
| 652 | 0.0042065294f, 0.03881498f, 0.019844765f, 0.041858196f, |
| 653 | -0.05695512f, 0.047233116f, 0.038937137f, -0.06542224f, |
| 654 | 0.014429736f, -0.09719407f, 0.13908425f, -0.05379757f, |
| 655 | 0.012321099f, 0.082840554f, -0.029899208f, 0.044217527f, |
| 656 | 0.059855383f, 0.07711018f, -0.045319796f, 0.0948846f, |
| 657 | -0.011724666f, -0.0033288454f, -0.033542685f, -0.04764985f, |
| 658 | -0.13873616f, 0.040668588f, 0.034832682f, -0.015319203f, |
| 659 | -0.018715994f, 0.046002675f, 0.0599172f, -0.043107376f, |
| 660 | 0.0294216f, -0.002314414f, -0.022424703f, 0.0030315618f, |
| 661 | 0.0014641669f, 0.0029166266f, -0.11878115f, 0.013738511f, |
| 662 | 0.12375372f, -0.0006038222f, 0.029104086f, 0.087442465f, |
| 663 | 0.052958444f, 0.07558703f, 0.04817258f, 0.044462286f, |
| 664 | -0.015213451f, -0.08783778f, -0.0561384f, -0.003008196f, |
| 665 | 0.047060397f, -0.002058388f, 0.03429439f, -0.018839769f, |
| 666 | 0.024734668f, 0.024614193f, -0.042046934f, 0.09597743f, |
| 667 | -0.0043254104f, 0.04320769f, 0.0064070094f, -0.0019131786f, |
| 668 | -0.02558259f, -0.022822596f, -0.023273505f, -0.02464396f, |
| 669 | -0.10991725f, -0.006240552f, 0.0074488563f, 0.024044557f, |
| 670 | 0.04383914f, -0.046476185f, 0.028658995f, 0.060410924f, |
| 671 | 0.050786525f, 0.009452605f, -0.0073054377f, -0.024810238f, |
| 672 | 0.0052906186f, 0.0066939713f, -0.0020913032f, 0.014515517f, |
| 673 | 0.015898481f, 0.021362653f, -0.030262267f, 0.016587038f, |
| 674 | -0.011442813f, 0.041154444f, -0.007631438f, -0.03423484f, |
| 675 | -0.010977775f, 0.036152758f, 0.0066366293f, 0.11915515f, |
| 676 | 0.02318443f, -0.041350313f, 0.021485701f, -0.10906167f, |
| 677 | -0.028218046f, -0.00954771f, 0.020531068f, -0.11995105f, |
| 678 | -0.03672871f, 0.024019798f, 0.014255957f, -0.05221243f, |
| 679 | -0.00661567f, -0.04630967f, 0.033188973f, 0.10107534f, |
| 680 | -0.014027541f, 0.030796422f, -0.10270911f, -0.035999842f, |
| 681 | 0.15443139f, 0.07684145f, 0.036571592f, -0.035900835f, |
| 682 | -0.0034699554f, 0.06209149f, 0.015920248f, -0.031122351f, |
| 683 | -0.03858649f, 0.01849943f, 0.13872518f, 0.01503974f, |
| 684 | 0.069941424f, -0.06948533f, -0.0088794185f, 0.061282158f, |
| 685 | -0.047401894f, 0.03100163f, -0.041533746f, -0.10430945f, |
| 686 | 0.044574402f, -0.01425562f, -0.024290353f, 0.034563623f, |
| 687 | 0.05866852f, 0.023947537f, -0.09445152f, 0.035450947f, |
| 688 | 0.02247216f, -0.0042998926f, 0.061146557f, -0.10250651f, |
| 689 | 0.020881841f, -0.06747029f, 0.10062043f, -0.0023941975f, |
| 690 | 0.03532124f, -0.016341697f, 0.09685456f, -0.016764693f, |
| 691 | 0.051808182f, 0.05875331f, -0.04536488f, 0.001626336f, |
| 692 | -0.028892258f, -0.01048663f, -0.009793449f, -0.017093895f, |
| 693 | 0.010987891f, 0.02357273f, -0.00010856845f, 0.0099760275f, |
| 694 | -0.001845119f, -0.03551521f, 0.0018358806f, 0.05763657f, |
| 695 | -0.01769146f, 0.040995963f, 0.02235177f, -0.060430344f, |
| 696 | 0.11475477f, -0.023854522f, 0.10071741f, 0.0686208f, |
| 697 | -0.014250481f, 0.034261297f, 0.047418304f, 0.08562733f, |
| 698 | -0.030519066f, 0.0060542435f, 0.014653856f, -0.038836084f, |
| 699 | 0.04096551f, 0.032249358f, -0.08355519f, -0.026823482f, |
| 700 | 0.056386515f, -0.010401743f, -0.028396193f, 0.08507674f, |
| 701 | 0.014410365f, 0.020995233f, 0.17040324f, 0.11511526f, |
| 702 | 0.02459721f, 0.0066619175f, 0.025853224f, -0.023133837f, |
| 703 | -0.081302024f, 0.017264642f, -0.009585969f, 0.09491168f, |
| 704 | -0.051313367f, 0.054532815f, -0.014298593f, 0.10657464f, |
| 705 | 0.007076659f, 0.10964551f, 0.0409152f, 0.008275321f, |
| 706 | -0.07283536f, 0.07937492f, 0.04192024f, -0.1075027f |
| 707 | }); |
| 708 | |
| 709 | auto recurrentToCellWeights = |
| 710 | MakeTensor<float, 2>(tensorInfo20x16, {-0.037322544f, 0.018592842f, 0.0056175636f, -0.06253426f, |
| 711 | 0.055647098f, -0.05713207f, -0.05626563f, 0.005559383f, |
| 712 | 0.03375411f, -0.025757805f, -0.088049285f, 0.06017052f, |
| 713 | -0.06570978f, 0.007384076f, 0.035123326f, -0.07920549f, |
| 714 | 0.053676967f, 0.044480428f, -0.07663568f, 0.0071805613f, |
| 715 | 0.08089997f, 0.05143358f, 0.038261272f, 0.03339287f, |
| 716 | -0.027673481f, 0.044746667f, 0.028349208f, 0.020090483f, |
| 717 | -0.019443132f, -0.030755889f, -0.0040000007f, 0.04465846f, |
| 718 | -0.021585021f, 0.0031670958f, 0.0053199246f, -0.056117613f, |
| 719 | -0.10893326f, 0.076739706f, -0.08509834f, -0.027997585f, |
| 720 | 0.037871376f, 0.01449768f, -0.09002357f, -0.06111149f, |
| 721 | -0.046195522f, 0.0422062f, -0.005683705f, -0.1253618f, |
| 722 | -0.012925729f, -0.04890792f, 0.06985068f, 0.037654128f, |
| 723 | 0.03398274f, -0.004781977f, 0.007032333f, -0.031787455f, |
| 724 | 0.010868644f, -0.031489216f, 0.09525667f, 0.013939797f, |
| 725 | 0.0058680447f, 0.0167067f, 0.02668468f, -0.04797466f, |
| 726 | -0.048885044f, -0.12722108f, 0.035304096f, 0.06554885f, |
| 727 | 0.00972396f, -0.039238118f, -0.05159735f, -0.11329045f, |
| 728 | 0.1613692f, -0.03750952f, 0.06529313f, -0.071974665f, |
| 729 | -0.11769596f, 0.015524369f, -0.0013754242f, -0.12446318f, |
| 730 | 0.02786344f, -0.014179351f, 0.005264273f, 0.14376344f, |
| 731 | 0.015983658f, 0.03406988f, -0.06939408f, 0.040699873f, |
| 732 | 0.02111075f, 0.09669095f, 0.041345075f, -0.08316494f, |
| 733 | -0.07684199f, -0.045768797f, 0.032298047f, -0.041805092f, |
| 734 | 0.0119405f, 0.0061010392f, 0.12652606f, 0.0064572375f, |
| 735 | -0.024950314f, 0.11574242f, 0.04508852f, -0.04335324f, |
| 736 | 0.06760663f, -0.027437469f, 0.07216407f, 0.06977076f, |
| 737 | -0.05438599f, 0.034033038f, -0.028602652f, 0.05346137f, |
| 738 | 0.043184172f, -0.037189785f, 0.10420091f, 0.00882477f, |
| 739 | -0.054019816f, -0.074273005f, -0.030617684f, -0.0028467078f, |
| 740 | 0.024302477f, -0.0038869337f, 0.005332455f, 0.0013399826f, |
| 741 | 0.04361412f, -0.007001822f, 0.09631092f, -0.06702025f, |
| 742 | -0.042049985f, -0.035070654f, -0.04103342f, -0.10273396f, |
| 743 | 0.0544271f, 0.037184782f, -0.13150354f, -0.0058036847f, |
| 744 | -0.008264958f, 0.042035464f, 0.05891794f, 0.029673764f, |
| 745 | 0.0063542654f, 0.044788733f, 0.054816857f, 0.062257513f, |
| 746 | -0.00093483756f, 0.048938446f, -0.004952862f, -0.007730018f, |
| 747 | -0.04043371f, -0.017094059f, 0.07229206f, -0.023670016f, |
| 748 | -0.052195564f, -0.025616996f, -0.01520939f, 0.045104615f, |
| 749 | -0.007376126f, 0.003533447f, 0.006570588f, 0.056037236f, |
| 750 | 0.12436656f, 0.051817212f, 0.028532185f, -0.08686856f, |
| 751 | 0.11868599f, 0.07663395f, -0.07323171f, 0.03463402f, |
| 752 | -0.050708205f, -0.04458982f, -0.11590894f, 0.021273347f, |
| 753 | 0.1251325f, -0.15313013f, -0.12224372f, 0.17228661f, |
| 754 | 0.023029093f, 0.086124025f, 0.006445803f, -0.03496501f, |
| 755 | 0.028332196f, 0.04449512f, -0.042436164f, -0.026587414f, |
| 756 | -0.006041347f, -0.09292539f, -0.05678812f, 0.03897832f, |
| 757 | 0.09465633f, 0.008115513f, -0.02171956f, 0.08304309f, |
| 758 | 0.071401566f, 0.019622514f, 0.032163795f, -0.004167056f, |
| 759 | 0.02295182f, 0.030739572f, 0.056506045f, 0.004612461f, |
| 760 | 0.06524936f, 0.059999723f, 0.046395954f, -0.0045512207f, |
| 761 | -0.1335546f, -0.030136576f, 0.11584653f, -0.014678886f, |
| 762 | 0.0020118146f, -0.09688814f, -0.0790206f, 0.039770417f, |
| 763 | -0.0329582f, 0.07922767f, 0.029322514f, 0.026405897f, |
| 764 | 0.04207835f, -0.07073373f, 0.063781224f, 0.0859677f, |
| 765 | -0.10925287f, -0.07011058f, 0.048005477f, 0.03438226f, |
| 766 | -0.09606514f, -0.006669445f, -0.043381985f, 0.04240257f, |
| 767 | -0.06955775f, -0.06769346f, 0.043903265f, -0.026784198f, |
| 768 | -0.017840602f, 0.024307009f, -0.040079936f, -0.019946516f, |
| 769 | 0.045318738f, -0.12233574f, 0.026170589f, 0.0074471775f, |
| 770 | 0.15978073f, 0.10185836f, 0.10298046f, -0.015476589f, |
| 771 | -0.039390966f, -0.072174534f, 0.0739445f, -0.1211869f, |
| 772 | -0.0347889f, -0.07943156f, 0.014809798f, -0.12412325f, |
| 773 | -0.0030663363f, 0.039695457f, 0.0647603f, -0.08291318f, |
| 774 | -0.018529687f, -0.004423833f, 0.0037507233f, 0.084633216f, |
| 775 | -0.01514876f, -0.056505352f, -0.012800942f, -0.06994386f, |
| 776 | 0.012962922f, -0.031234352f, 0.07029052f, 0.016418684f, |
| 777 | 0.03618972f, 0.055686004f, -0.08663945f, -0.017404709f, |
| 778 | -0.054761406f, 0.029065743f, 0.052404847f, 0.020238016f, |
| 779 | 0.0048197987f, -0.0214882f, 0.07078733f, 0.013016777f, |
| 780 | 0.06262858f, 0.009184685f, 0.020785125f, -0.043904778f, |
| 781 | -0.0270329f, -0.03299152f, -0.060088247f, -0.015162964f, |
| 782 | -0.001828936f, 0.12642565f, -0.056757294f, 0.013586685f, |
| 783 | 0.09232601f, -0.035886683f, 0.06000002f, 0.05229691f, |
| 784 | -0.052580316f, -0.082029596f, -0.010794592f, 0.012947712f, |
| 785 | -0.036429964f, -0.085508935f, -0.13127148f, -0.017744139f, |
| 786 | 0.031502828f, 0.036232427f, -0.031581745f, 0.023051167f, |
| 787 | -0.05325106f, -0.03421577f, 0.028793324f, -0.034633752f, |
| 788 | -0.009881397f, -0.043551125f, -0.018609839f, 0.0019097115f, |
| 789 | -0.008799762f, 0.056595087f, 0.0022273948f, 0.055752404f |
| 790 | }); |
| 791 | |
| 792 | auto recurrentToOutputWeights = |
| 793 | MakeTensor<float, 2>(tensorInfo20x16, {0.025825322f, -0.05813119f, 0.09495884f,-0.045984812f, -0.01255415f, |
| 794 | -0.0026479573f,-0.08196161f,-0.054914974f,-0.0046604523f, |
| 795 | -0.029587349f, -0.044576716f, -0.07480124f, -0.082868785f, |
| 796 | 0.023254942f, 0.027502948f, -0.0039728214f, -0.08683098f, |
| 797 | -0.08116779f, -0.014675607f, -0.037924774f, -0.023314456f, |
| 798 | -0.007401714f, -0.09255757f, 0.029460307f, -0.08829125f, |
| 799 | -0.005139627f, -0.08989442f, -0.0555066f, 0.13596267f, |
| 800 | -0.025062224f, -0.048351806f, -0.03850004f, 0.07266485f, |
| 801 | -0.022414139f, 0.05940088f, 0.075114764f, 0.09597592f, |
| 802 | -0.010211725f, -0.0049794707f, -0.011523867f, -0.025980417f, |
| 803 | 0.072999895f, 0.11091378f, -0.081685916f, 0.014416728f, |
| 804 | 0.043229222f, 0.034178585f, -0.07530371f, 0.035837382f, |
| 805 | -0.085607f, -0.007721233f, -0.03287832f, -0.043848954f, |
| 806 | -0.06404588f, -0.06632928f, -0.073643476f, 0.008214239f, |
| 807 | -0.045984086f, 0.039764922f, 0.03474462f, 0.060612556f, |
| 808 | -0.080590084f, 0.049127717f, 0.04151091f, -0.030063879f, |
| 809 | 0.008801774f, -0.023021035f, -0.019558564f, 0.05158114f, |
| 810 | -0.010947698f, -0.011825728f, 0.0075720972f, 0.0699727f, |
| 811 | -0.0039981045f, 0.069350146f, 0.08799282f, 0.016156472f, |
| 812 | 0.035502106f, 0.11695009f, 0.006217345f, 0.13392477f, |
| 813 | -0.037875112f, 0.025745004f, 0.08940699f, -0.00924166f, |
| 814 | 0.0046702605f, -0.036598757f, -0.08811812f, 0.10522024f, |
| 815 | -0.032441203f, 0.008176899f, -0.04454919f, 0.07058152f, |
| 816 | 0.0067963637f, 0.039206743f, 0.03259838f, 0.03725492f, |
| 817 | -0.09515802f, 0.013326398f, -0.052055415f, -0.025676316f, |
| 818 | 0.03198509f, -0.015951829f, -0.058556724f, 0.036879618f, |
| 819 | 0.043357447f, 0.028362012f, -0.05908629f, 0.0059240665f, |
| 820 | -0.04995891f, -0.019187413f,0.0276265f, -0.01628143f, 0.0025863599f, |
| 821 | 0.08800015f, 0.035250366f, -0.022165963f, -0.07328642f, |
| 822 | -0.009415526f, -0.07455109f, 0.11690406f, 0.0363299f, |
| 823 | 0.07411125f, 0.042103454f, -0.009660886f, 0.019076364f, |
| 824 | 0.018299393f, -0.046004917f, 0.08891175f,0.0431396f, -0.026327137f, |
| 825 | -0.051502608f, 0.08979574f, -0.051670972f, 0.04940282f, |
| 826 | -0.07491107f, -0.021240504f, 0.022596184f, -0.034280192f, |
| 827 | 0.060163025f, -0.058211457f, -0.051837247f, -0.01349775f, |
| 828 | -0.04639988f, -0.035936575f, -0.011681591f, 0.064818054f, |
| 829 | 0.0073146066f, -0.021745546f, -0.043124277f, -0.06471268f, |
| 830 | -0.07053354f, -0.029321948f, -0.05330136f, 0.016933719f, |
| 831 | -0.053782392f, 0.13747959f, -0.1361751f, -0.11569455f, |
| 832 | 0.0033329215f, 0.05693899f, -0.053219706f, 0.063698f, |
| 833 | 0.07977434f, -0.07924483f, 0.06936997f, 0.0034815092f, |
| 834 | -0.007305279f, -0.037325785f, -0.07251102f, -0.033633437f, |
| 835 | -0.08677009f, 0.091591336f, -0.14165086f, 0.021752775f, |
| 836 | 0.019683983f, 0.0011612234f, -0.058154266f, 0.049996935f, |
| 837 | 0.0288841f, -0.0024567875f, -0.14345716f, 0.010955264f,-0.10234828f, |
| 838 | 0.1183656f, -0.0010731248f, -0.023590032f,-0.072285876f,-0.0724771f, |
| 839 | -0.026382286f, -0.0014920527f, 0.042667855f, 0.0018776858f, |
| 840 | 0.02986552f, 0.009814309f, 0.0733756f, 0.12289186f, |
| 841 | 0.018043943f, -0.0458958f, 0.049412545f, 0.033632483f, |
| 842 | 0.05495232f, 0.036686596f, -0.013781798f, -0.010036754f, |
| 843 | 0.02576849f, -0.08307328f, 0.010112348f, 0.042521734f, |
| 844 | -0.05869831f, -0.071689695f, 0.03876447f, -0.13275425f, -0.0352966f, |
| 845 | -0.023077697f, 0.10285965f, 0.084736146f, 0.15568255f, |
| 846 | -0.00040734606f, 0.027835453f, -0.10292561f, -0.032401145f, |
| 847 | 0.10053256f, -0.026142767f, -0.08271222f, -0.0030240538f, |
| 848 | -0.016368777f, 0.1070414f, 0.042672627f, 0.013456989f, |
| 849 | -0.0437609f, -0.022309763f, 0.11576483f, 0.04108048f, |
| 850 | 0.061026827f, -0.0190714f, -0.0869359f, 0.037901703f, 0.0610107f, |
| 851 | 0.07202949f, 0.01675338f, 0.086139716f, -0.08795751f, |
| 852 | -0.014898893f, -0.023771819f, -0.01965048f, 0.007955471f, |
| 853 | -0.043740474f, 0.03346837f, -0.10549954f, 0.090567775f, |
| 854 | 0.042013682f, -0.03176985f, 0.12569028f, -0.02421228f, |
| 855 | -0.029526481f, 0.023851605f, 0.031539805f, 0.05292009f, |
| 856 | -0.02344001f, -0.07811758f, -0.08834428f, 0.10094801f, |
| 857 | 0.16594367f, -0.06861939f, -0.021256343f, -0.041093912f, |
| 858 | -0.06669611f, 0.035498552f, 0.021757556f, -0.09302526f, |
| 859 | -0.015403468f, -0.06614931f, -0.051798206f, -0.013874718f, |
| 860 | 0.03630673f, 0.010412845f, -0.08077351f, 0.046185967f, |
| 861 | 0.0035662893f, 0.03541868f, -0.094149634f, -0.034814864f, |
| 862 | 0.003128424f, -0.020674974f, -0.03944324f, -0.008110165f, |
| 863 | -0.11113267f, 0.08484226f, 0.043586485f, 0.040582247f, |
| 864 | 0.0968012f, -0.065249965f, -0.028036479f, 0.0050708856f, |
| 865 | 0.0017462453f, 0.0326779f, 0.041296225f, 0.09164146f, |
| 866 | -0.047743853f, -0.015952192f, -0.034451712f, 0.084197424f, |
| 867 | -0.05347844f, -0.11768019f, 0.085926116f, -0.08251791f, |
| 868 | -0.045081906f, 0.0948852f, 0.068401024f, 0.024856757f, |
| 869 | 0.06978981f, -0.057309967f, -0.012775832f, -0.0032452994f, |
| 870 | 0.01977615f, -0.041040014f, -0.024264973f,0.063464895f, 0.05431621f |
| 871 | }); |
| 872 | |
| 873 | auto cellToInputWeights = |
| 874 | MakeTensor<float, 1>(tensorInfo20, {0.040369894f, 0.030746894f, 0.24704495f, 0.018586371f, -0.037586458f, |
| 875 | -0.15312155f, -0.11812848f, -0.11465643f, 0.20259799f, 0.11418174f, |
| 876 | -0.10116027f, -0.011334949f, 0.12411352f, -0.076769054f,-0.052169047f, |
| 877 | 0.21198851f, -0.38871562f, -0.09061183f, -0.09683246f, -0.21929175f |
| 878 | }); |
| 879 | |
| 880 | |
| 881 | auto cellToForgetWeights = |
| 882 | MakeTensor<float, 1>(tensorInfo20, {-0.01998659f,-0.15568835f,-0.24248174f, -0.012770197f, 0.041331276f, |
| 883 | -0.072311886f, -0.052123554f,-0.0066330447f,-0.043891653f,0.036225766f, |
| 884 | -0.047248036f, 0.021479502f,0.033189066f, 0.11952997f, -0.020432774f, |
| 885 | 0.64658105f, -0.06650122f, -0.03467612f, 0.095340036f, 0.23647355f |
| 886 | }); |
| 887 | |
| 888 | auto cellToOutputWeights = |
| 889 | MakeTensor<float, 1>(tensorInfo20, {0.08286371f, -0.08261836f, -0.51210177f, 0.002913762f, 0.17764764f, |
| 890 | -0.5495371f, -0.08460716f, -0.24552552f, 0.030037103f, 0.04123544f, |
| 891 | -0.11940523f, 0.007358328f, 0.1890978f, 0.4833202f, -0.34441817f, |
| 892 | 0.36312827f, -0.26375428f, 0.1457655f, -0.19724406f, 0.15548733f |
| 893 | }); |
| 894 | |
| 895 | auto projectionWeights = |
| 896 | MakeTensor<float, 2>(tensorInfo16x20, |
| 897 | {-0.009802181f, 0.09401916f, 0.0717386f, -0.13895074f, 0.09641832f, |
| 898 | 0.060420845f, 0.08539281f, 0.054285463f, 0.061395317f, 0.034448683f, |
| 899 | -0.042991187f, 0.019801661f, -0.16840284f, -0.015726732f, -0.23041931f, |
| 900 | -0.024478018f, -0.10959692f, -0.013875541f, 0.18600968f, -0.061274476f, |
| 901 | 0.0138165f, -0.08160894f, -0.07661644f, 0.032372914f, 0.16169067f, |
| 902 | 0.22465782f, -0.03993472f, -0.004017731f, 0.08633481f, -0.28869787f, |
| 903 | 0.08682067f, 0.17240396f, 0.014975425f, 0.056431185f, 0.031037588f, |
| 904 | 0.16702051f, 0.0077946745f, 0.15140012f, 0.29405436f, 0.120285f, |
| 905 | -0.188994f, -0.027265169f, 0.043389652f, -0.022061434f, 0.014777949f, |
| 906 | -0.20203483f, 0.094781205f, 0.19100232f, 0.13987629f, -0.036132768f, |
| 907 | -0.06426278f, -0.05108664f, 0.13221376f, 0.009441198f, -0.16715929f, |
| 908 | 0.15859416f, -0.040437475f, 0.050779544f, -0.022187516f, 0.012166504f, |
| 909 | 0.027685808f, -0.07675938f, -0.0055694645f, -0.09444123f, 0.0046453946f, |
| 910 | 0.050794356f, 0.10770313f, -0.20790008f, -0.07149004f, -0.11425117f, |
| 911 | 0.008225835f, -0.035802525f, 0.14374903f, 0.15262283f, 0.048710253f, |
| 912 | 0.1847461f, -0.007487823f, 0.11000021f, -0.09542012f, 0.22619456f, |
| 913 | -0.029149994f, 0.08527916f, 0.009043713f, 0.0042746216f, 0.016261552f, |
| 914 | 0.022461696f, 0.12689082f, -0.043589946f, -0.12035478f, -0.08361797f, |
| 915 | -0.050666027f, -0.1248618f, -0.1275799f, -0.071875185f, 0.07377272f, |
| 916 | 0.09944291f, -0.18897448f, -0.1593054f, -0.06526116f, -0.040107165f, |
| 917 | -0.004618631f, -0.067624845f, -0.007576253f, 0.10727444f, 0.041546922f, |
| 918 | -0.20424393f, 0.06907816f, 0.050412357f, 0.00724631f, 0.039827548f, |
| 919 | 0.12449835f, 0.10747581f, 0.13708383f, 0.09134148f, -0.12617786f, |
| 920 | -0.06428341f, 0.09956831f, 0.1208086f, -0.14676677f, -0.0727722f, |
| 921 | 0.1126304f, 0.010139365f, 0.015571211f, -0.038128063f, 0.022913318f, |
| 922 | -0.042050496f, 0.16842307f, -0.060597885f, 0.10531834f, -0.06411776f, |
| 923 | -0.07451711f, -0.03410368f, -0.13393489f, 0.06534304f, 0.003620307f, |
| 924 | 0.04490757f, 0.05970546f, 0.05197996f, 0.02839995f, 0.10434969f, |
| 925 | -0.013699693f, -0.028353551f, -0.07260381f, 0.047201227f, -0.024575593f, |
| 926 | -0.036445823f, 0.07155557f, 0.009672501f, -0.02328883f, 0.009533515f, |
| 927 | -0.03606021f, -0.07421458f, -0.028082801f, -0.2678904f, -0.13221288f, |
| 928 | 0.18419984f, -0.13012612f, -0.014588381f, -0.035059117f, -0.04824723f, |
| 929 | 0.07830115f, -0.056184657f, 0.03277091f, 0.025466874f, 0.14494097f, |
| 930 | -0.12522776f, -0.098633975f, -0.10766018f, -0.08317623f, 0.08594209f, |
| 931 | 0.07749552f, 0.039474737f, 0.1776665f, -0.07409566f, -0.0477268f, |
| 932 | 0.29323658f, 0.10801441f, 0.1154011f, 0.013952499f, 0.10739139f, |
| 933 | 0.10708251f, -0.051456142f, 0.0074137426f, -0.10430189f, 0.10034707f, |
| 934 | 0.045594677f, 0.0635285f, -0.0715442f, -0.089667566f, -0.10811871f, |
| 935 | 0.00026344223f, 0.08298446f, -0.009525053f, 0.006585689f, -0.24567553f, |
| 936 | -0.09450807f, 0.09648481f, 0.026996298f, -0.06419476f, -0.04752702f, |
| 937 | -0.11063944f, -0.23441927f, -0.17608605f, -0.052156363f, 0.067035615f, |
| 938 | 0.19271925f, -0.0032889997f, -0.043264326f, 0.09663576f, -0.057112187f, |
| 939 | -0.10100678f, 0.0628376f, 0.04447668f, 0.017961001f, -0.10094388f, |
| 940 | -0.10190601f, 0.18335468f, 0.10494553f, -0.052095775f, -0.0026118709f, |
| 941 | 0.10539724f, -0.04383912f, -0.042349473f, 0.08438151f, -0.1947263f, |
| 942 | 0.02251204f, 0.11216432f, -0.10307853f, 0.17351969f, -0.039091777f, |
| 943 | 0.08066188f, -0.00561982f, 0.12633002f, 0.11335965f, -0.0088127935f, |
| 944 | -0.019777594f, 0.06864014f, -0.059751723f, 0.016233567f, -0.06894641f, |
| 945 | -0.28651384f, -0.004228674f, 0.019708522f, -0.16305895f, -0.07468996f, |
| 946 | -0.0855457f, 0.099339016f, -0.07580735f, -0.13775392f, 0.08434318f, |
| 947 | 0.08330512f, -0.12131499f, 0.031935584f, 0.09180414f, -0.08876437f, |
| 948 | -0.08049874f, 0.008753825f, 0.03498998f, 0.030215185f, 0.03907079f, |
| 949 | 0.089751154f, 0.029194152f, -0.03337423f, -0.019092513f, 0.04331237f, |
| 950 | 0.04299654f, -0.036394123f, -0.12915532f, 0.09793732f, 0.07512415f, |
| 951 | -0.11319543f, -0.032502122f, 0.15661901f, 0.07671967f, -0.005491124f, |
| 952 | -0.19379048f, -0.218606f, 0.21448623f, 0.017840758f, 0.1416943f, |
| 953 | -0.07051762f, 0.19488361f, 0.02664691f, -0.18104725f, -0.09334311f, |
| 954 | 0.15026465f, -0.15493552f, -0.057762887f, -0.11604192f, -0.262013f, |
| 955 | -0.01391798f, 0.012185008f, 0.11156489f, -0.07483202f, 0.06693364f, |
| 956 | -0.26151478f, 0.046425626f, 0.036540434f, -0.16435726f, 0.17338543f, |
| 957 | -0.21401681f, -0.11385144f, -0.08283257f, -0.069031075f, 0.030635102f, |
| 958 | 0.010969227f, 0.11109743f, 0.010919218f, 0.027526086f, 0.13519906f, |
| 959 | 0.01891392f, -0.046839405f, -0.040167913f, 0.017953383f, -0.09700955f, |
| 960 | 0.0061885654f, -0.07000971f, 0.026893595f, -0.038844477f, 0.14543656f |
| 961 | }); |
| 962 | |
| 963 | std::vector<float> projectionBiasVector(outputSize, 0.f); |
| 964 | auto projectionBias = MakeTensor<float,1>(tensorInfo16, projectionBiasVector); |
| 965 | |
| 966 | armnn::ScopedCpuTensorHandle inputToInputWeightsTensor(tensorInfo20x5); |
| 967 | armnn::ScopedCpuTensorHandle inputToForgetWeightsTensor(tensorInfo20x5); |
| 968 | armnn::ScopedCpuTensorHandle inputToCellWeightsTensor(tensorInfo20x5); |
| 969 | armnn::ScopedCpuTensorHandle inputToOutputWeightsTensor(tensorInfo20x5); |
| 970 | armnn::ScopedCpuTensorHandle recurrentToForgetWeightsTensor(tensorInfo20x16); |
| 971 | armnn::ScopedCpuTensorHandle recurrentToInputWeightsTensor(tensorInfo20x16); |
| 972 | armnn::ScopedCpuTensorHandle recurrentToCellWeightsTensor(tensorInfo20x16); |
| 973 | armnn::ScopedCpuTensorHandle recurrentToOutputWeightsTensor(tensorInfo20x16); |
| 974 | armnn::ScopedCpuTensorHandle cellToInputWeightsTensor(tensorInfo20); |
| 975 | armnn::ScopedCpuTensorHandle inputGateBiasTensor(tensorInfo20); |
| 976 | armnn::ScopedCpuTensorHandle forgetGateBiasTensor(tensorInfo20); |
| 977 | armnn::ScopedCpuTensorHandle cellBiasTensor(tensorInfo20); |
| 978 | armnn::ScopedCpuTensorHandle outputGateBiasTensor(tensorInfo20); |
| 979 | armnn::ScopedCpuTensorHandle cellToForgetWeightsTensor(tensorInfo20); |
| 980 | armnn::ScopedCpuTensorHandle cellToOutputWeightsTensor(tensorInfo20); |
| 981 | armnn::ScopedCpuTensorHandle projectionWeightsTensor(tensorInfo16x20); |
| 982 | armnn::ScopedCpuTensorHandle projectionBiasTensor(tensorInfo16); |
| 983 | |
| 984 | AllocateAndCopyDataToITensorHandle(&inputToInputWeightsTensor, &inputToInputWeights[0][0]); |
| 985 | AllocateAndCopyDataToITensorHandle(&inputToForgetWeightsTensor, &inputToForgetWeights[0][0]); |
| 986 | AllocateAndCopyDataToITensorHandle(&inputToCellWeightsTensor, &inputToCellWeights[0][0]); |
| 987 | AllocateAndCopyDataToITensorHandle(&inputToOutputWeightsTensor, &inputToOutputWeights[0][0]); |
| 988 | AllocateAndCopyDataToITensorHandle(&recurrentToInputWeightsTensor, &recurrentToInputWeights[0][0]); |
| 989 | AllocateAndCopyDataToITensorHandle(&recurrentToForgetWeightsTensor, &recurrentToForgetWeights[0][0]); |
| 990 | AllocateAndCopyDataToITensorHandle(&recurrentToCellWeightsTensor, &recurrentToCellWeights[0][0]); |
| 991 | AllocateAndCopyDataToITensorHandle(&recurrentToOutputWeightsTensor, &recurrentToOutputWeights[0][0]); |
| 992 | AllocateAndCopyDataToITensorHandle(&cellToInputWeightsTensor, &cellToInputWeights[0]); |
| 993 | AllocateAndCopyDataToITensorHandle(&inputGateBiasTensor, &inputGateBias[0]); |
| 994 | AllocateAndCopyDataToITensorHandle(&forgetGateBiasTensor, &forgetGateBias[0]); |
| 995 | AllocateAndCopyDataToITensorHandle(&cellBiasTensor, &cellBias[0]); |
| 996 | AllocateAndCopyDataToITensorHandle(&outputGateBiasTensor, &outputGateBias[0]); |
| 997 | AllocateAndCopyDataToITensorHandle(&cellToForgetWeightsTensor, &cellToForgetWeights[0]); |
| 998 | AllocateAndCopyDataToITensorHandle(&cellToOutputWeightsTensor, &cellToOutputWeights[0]); |
| 999 | AllocateAndCopyDataToITensorHandle(&projectionWeightsTensor, &projectionWeights[0][0]); |
| 1000 | AllocateAndCopyDataToITensorHandle(&projectionBiasTensor, &projectionBias[0]); |
| 1001 | |
| 1002 | data.m_InputToInputWeights = &inputToInputWeightsTensor; |
| 1003 | data.m_InputToForgetWeights = &inputToForgetWeightsTensor; |
| 1004 | data.m_InputToCellWeights = &inputToCellWeightsTensor; |
| 1005 | data.m_InputToOutputWeights = &inputToOutputWeightsTensor; |
| 1006 | data.m_RecurrentToInputWeights = &recurrentToInputWeightsTensor; |
| 1007 | data.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor; |
| 1008 | data.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor; |
| 1009 | data.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor; |
| 1010 | data.m_CellToInputWeights = &cellToInputWeightsTensor; |
| 1011 | data.m_InputGateBias = &inputGateBiasTensor; |
| 1012 | data.m_ForgetGateBias = &forgetGateBiasTensor; |
| 1013 | data.m_CellBias = &cellBiasTensor; |
| 1014 | data.m_OutputGateBias = &outputGateBiasTensor; |
| 1015 | data.m_CellToForgetWeights = &cellToForgetWeightsTensor; |
| 1016 | data.m_CellToOutputWeights = &cellToOutputWeightsTensor; |
| 1017 | data.m_ProjectionWeights = &projectionWeightsTensor; |
| 1018 | data.m_ProjectionBias = &projectionBiasTensor; |
| 1019 | |
| 1020 | // Flags to set test configuration |
| 1021 | data.m_Parameters.m_ActivationFunc = 4; |
| 1022 | data.m_Parameters.m_CifgEnabled = false; |
| 1023 | data.m_Parameters.m_PeepholeEnabled = true; |
| 1024 | data.m_Parameters.m_ProjectionEnabled = true; |
| 1025 | |
| 1026 | |
| 1027 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateLstm(data, info); |
| 1028 | inputHandle->Allocate(); |
| 1029 | outputStateInHandle->Allocate(); |
| 1030 | cellStateInHandle->Allocate(); |
| 1031 | |
| 1032 | scratchHandle->Allocate(); |
| 1033 | outputStateOutHandle->Allocate(); |
| 1034 | cellStateOutHandle->Allocate(); |
| 1035 | outputHandle->Allocate(); |
| 1036 | |
| 1037 | CopyDataToITensorHandle(inputHandle.get(), &inputTensor[0][0]); |
| 1038 | CopyDataToITensorHandle(outputStateInHandle.get(), &outputStateInTensor[0][0]); |
| 1039 | CopyDataToITensorHandle(cellStateInHandle.get(), &cellStateInTensor[0][0]); |
| 1040 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1041 | workload->Execute(); |
| 1042 | |
| 1043 | CopyDataFromITensorHandle(&ret.output[0][0], outputHandle.get()); |
| 1044 | |
| 1045 | return ret; |
| 1046 | |
| 1047 | } |
| 1048 | |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 1049 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 1050 | LayerTestResult<T, 2> LstmLayerWithCifgWithPeepholeNoProjectionTestImpl( |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 1051 | armnn::IWorkloadFactory& workloadFactory, |
| 1052 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 1053 | const boost::multi_array<T, 2>& input, |
| 1054 | const boost::multi_array<T, 2>& outputExpected, |
| 1055 | float qScale = 0.0f, |
| 1056 | int32_t qOffset = 0, |
| 1057 | armnn::DataType constantDataType = armnn::DataType::Float32) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1058 | { |
| 1059 | bool cifgEnabled = true; |
| 1060 | bool peepholeEnabled = true; |
| 1061 | bool projectionEnabled = false; |
| 1062 | // These are not the input and the output of Lstm yet |
| 1063 | unsigned int batchSize = boost::numeric_cast<unsigned int>(input.shape()[0]); |
| 1064 | unsigned int inputSize = boost::numeric_cast<unsigned int>(input.shape()[1]); |
| 1065 | |
| 1066 | unsigned int outputSize = boost::numeric_cast<unsigned int>(outputExpected.shape()[1]); |
| 1067 | |
| 1068 | const unsigned int cellSize = outputSize; |
| 1069 | |
| 1070 | // Decide the shape of all input tensors |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 1071 | armnn::TensorInfo inputTensorInfo({batchSize , inputSize}, ArmnnType, qScale, qOffset); // change to ArmnnType |
| 1072 | armnn::TensorInfo outputStateInTensorInfo({batchSize, outputSize}, ArmnnType, qScale, qOffset); |
| 1073 | armnn::TensorInfo cellStateInTensorInfo({batchSize, cellSize}, ArmnnType, qScale, qOffset); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1074 | |
Matteo Martincigh | a65b7ae | 2018-11-14 12:39:55 +0000 | [diff] [blame] | 1075 | unsigned int scratchBufferSize = cifgEnabled ? cellSize * 3 : cellSize * 4; |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 1076 | armnn::TensorInfo scratchBufferTensorInfo({batchSize, scratchBufferSize}, ArmnnType, qScale, qOffset); |
| 1077 | armnn::TensorInfo outputStateOutTensorInfo({batchSize, outputSize}, ArmnnType, qScale, qOffset); |
| 1078 | armnn::TensorInfo cellStateOutTensorInfo({batchSize, cellSize}, ArmnnType, qScale, qOffset); |
| 1079 | armnn::TensorInfo outputTensorInfo({batchSize, outputSize}, ArmnnType, qScale, qOffset); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1080 | |
| 1081 | // List of inputs |
| 1082 | std::vector<float> inputData; |
| 1083 | inputData.assign(input.data(), input.data() + batchSize*inputSize); |
| 1084 | auto inputTensor = MakeTensor<float,2>(inputTensorInfo, inputData); |
| 1085 | |
| 1086 | std::vector<float> outputStateInVector(batchSize * outputSize, 0.f); |
| 1087 | auto outputStateInTensor = MakeTensor<float, 2>(outputStateInTensorInfo, outputStateInVector); |
| 1088 | |
| 1089 | std::vector<float> cellStateInVector(batchSize * cellSize, 0.f); |
| 1090 | auto cellStateInTensor = MakeTensor<float, 2>(cellStateInTensorInfo, cellStateInVector); |
| 1091 | |
| 1092 | |
| 1093 | // Prepare all the weights in the descriptor for LSTM |
| 1094 | armnn::LstmQueueDescriptor data; |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 1095 | armnn::TensorInfo tensorInfoInput({cellSize, inputSize}, constantDataType, qScale, qOffset); |
| 1096 | armnn::TensorInfo tensorInfoOutput({cellSize, outputSize}, constantDataType, qScale, qOffset); |
| 1097 | armnn::TensorInfo tensorInfoNumUnits({cellSize}, constantDataType, qScale, qOffset); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1098 | |
| 1099 | auto inputToCellWeights = MakeTensor<float, 2>(tensorInfoInput, |
| 1100 | {-0.49770179f, -0.27711356f, -0.09624726f, 0.05100781f, |
| 1101 | 0.04717243f, 0.48944736f, -0.38535351f, |
| 1102 | -0.17212132f}); |
| 1103 | auto inputToForgetWeights = MakeTensor<float, 2>(tensorInfoInput, |
| 1104 | {-0.55291498f, -0.42866567f, 0.13056988f, |
| 1105 | -0.3633365f, -0.22755712f, 0.28253698f, 0.24407166f, |
| 1106 | 0.33826375f}); |
| 1107 | auto inputToOutputWeights = MakeTensor<float, 2>(tensorInfoInput, |
| 1108 | {0.10725588f, -0.02335852f, -0.55932593f, |
| 1109 | -0.09426838f, -0.44257352f, 0.54939759f, |
| 1110 | 0.01533556f, 0.42751634f}); |
| 1111 | auto cellBias = MakeTensor<float, 1>(tensorInfoNumUnits, {0.f, 0.f, 0.f, 0.f}); |
| 1112 | auto forgetGateBias = MakeTensor<float, 1>(tensorInfoNumUnits, {1.f, 1.f, 1.f, 1.f}); |
| 1113 | auto outputGateBias = MakeTensor<float, 1>(tensorInfoNumUnits, {0.f, 0.f, 0.f, 0.f}); |
| 1114 | |
| 1115 | auto recurrentToCellWeights = MakeTensor<float, 2>(tensorInfoOutput, |
| 1116 | {0.54066205f, -0.32668582f, -0.43562764f, -0.56094903f, 0.42957711f, |
| 1117 | 0.01841056f, -0.32764608f, -0.33027974f, -0.10826075f, 0.20675004f, |
| 1118 | 0.19069612f, -0.03026325f, -0.54532051f, 0.33003211f, 0.44901288f, |
| 1119 | 0.21193194f}); |
| 1120 | auto recurrentToForgetWeights = MakeTensor<float, 2>(tensorInfoOutput, |
| 1121 | {-0.13832897f, -0.0515101f, -0.2359007f, -0.16661474f, -0.14340827f, |
| 1122 | 0.36986142f, 0.23414481f, 0.55899f, 0.10798943f, -0.41174671f, 0.17751795f, |
| 1123 | -0.34484994f, -0.35874045f, -0.11352962f, 0.27268326f, 0.54058349f}); |
| 1124 | |
| 1125 | auto recurrentToOutputWeights = MakeTensor<float, 2>(tensorInfoOutput, |
| 1126 | {0.41613156f, 0.42610586f, -0.16495961f, -0.5663873f, 0.30579174f, -0.05115908f, |
| 1127 | -0.33941799f, 0.23364776f, 0.11178309f, 0.09481031f, -0.26424935f, 0.46261835f, |
| 1128 | 0.50248802f, 0.26114327f, -0.43736315f, 0.33149987f}); |
| 1129 | |
| 1130 | auto cellToForgetWeights = MakeTensor<float, 1>(tensorInfoNumUnits, |
| 1131 | {0.47485286f, -0.51955009f, -0.24458408f, 0.31544167f}); |
| 1132 | auto cellToOutputWeights = MakeTensor<float, 1>(tensorInfoNumUnits, |
| 1133 | {-0.17135078f, 0.82760304f, 0.85573703f, -0.77109635f}); |
| 1134 | |
| 1135 | armnn::ScopedCpuTensorHandle inputToCellWeightsTensor(tensorInfoInput); |
| 1136 | armnn::ScopedCpuTensorHandle inputToForgetWeightsTensor(tensorInfoInput); |
| 1137 | armnn::ScopedCpuTensorHandle inputToOutputWeightsTensor(tensorInfoInput); |
| 1138 | |
| 1139 | armnn::ScopedCpuTensorHandle cellBiasTensor(tensorInfoNumUnits); |
| 1140 | armnn::ScopedCpuTensorHandle forgetGateBiasTensor(tensorInfoNumUnits); |
| 1141 | armnn::ScopedCpuTensorHandle outputGateBiasTensor(tensorInfoNumUnits); |
| 1142 | |
| 1143 | armnn::ScopedCpuTensorHandle recurrentToCellWeightsTensor(tensorInfoOutput); |
| 1144 | armnn::ScopedCpuTensorHandle recurrentToForgetWeightsTensor(tensorInfoOutput); |
| 1145 | armnn::ScopedCpuTensorHandle recurrentToOutputWeightsTensor(tensorInfoOutput); |
| 1146 | |
| 1147 | |
| 1148 | armnn::ScopedCpuTensorHandle cellToForgetWeightsTensor(tensorInfoNumUnits); |
| 1149 | armnn::ScopedCpuTensorHandle cellToOutputWeightsTensor(tensorInfoNumUnits); |
| 1150 | |
| 1151 | AllocateAndCopyDataToITensorHandle(&inputToCellWeightsTensor, &inputToCellWeights[0][0]); |
| 1152 | AllocateAndCopyDataToITensorHandle(&inputToForgetWeightsTensor, &inputToForgetWeights[0][0]); |
| 1153 | AllocateAndCopyDataToITensorHandle(&inputToOutputWeightsTensor, &inputToOutputWeights[0][0]); |
| 1154 | |
| 1155 | AllocateAndCopyDataToITensorHandle(&cellBiasTensor, &cellBias[0]); |
| 1156 | AllocateAndCopyDataToITensorHandle(&forgetGateBiasTensor, &forgetGateBias[0]); |
| 1157 | AllocateAndCopyDataToITensorHandle(&outputGateBiasTensor, &outputGateBias[0]); |
| 1158 | |
| 1159 | AllocateAndCopyDataToITensorHandle(&recurrentToCellWeightsTensor, &recurrentToCellWeights[0][0]); |
| 1160 | AllocateAndCopyDataToITensorHandle(&recurrentToForgetWeightsTensor, &recurrentToForgetWeights[0][0]); |
| 1161 | AllocateAndCopyDataToITensorHandle(&recurrentToOutputWeightsTensor, &recurrentToOutputWeights[0][0]); |
| 1162 | |
| 1163 | AllocateAndCopyDataToITensorHandle(&cellToForgetWeightsTensor, &cellToForgetWeights[0]); |
| 1164 | AllocateAndCopyDataToITensorHandle(&cellToOutputWeightsTensor, &cellToOutputWeights[0]); |
| 1165 | |
| 1166 | |
| 1167 | data.m_InputToCellWeights = &inputToCellWeightsTensor; |
| 1168 | data.m_InputToForgetWeights = &inputToForgetWeightsTensor; |
| 1169 | data.m_InputToOutputWeights = &inputToOutputWeightsTensor; |
| 1170 | |
| 1171 | data.m_CellBias = &cellBiasTensor; |
| 1172 | data.m_ForgetGateBias = &forgetGateBiasTensor; |
| 1173 | data.m_OutputGateBias = &outputGateBiasTensor; |
| 1174 | |
| 1175 | data.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor; |
| 1176 | data.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor; |
| 1177 | data.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor; |
| 1178 | |
| 1179 | data.m_CellToForgetWeights = &cellToForgetWeightsTensor; |
| 1180 | data.m_CellToOutputWeights = &cellToOutputWeightsTensor; |
| 1181 | |
| 1182 | // other parameters for the descriptor |
| 1183 | data.m_Parameters.m_CifgEnabled = cifgEnabled; |
| 1184 | data.m_Parameters.m_ProjectionEnabled = projectionEnabled; |
| 1185 | data.m_Parameters.m_PeepholeEnabled = peepholeEnabled; |
| 1186 | |
| 1187 | data.m_Parameters.m_ActivationFunc = 4; |
| 1188 | data.m_Parameters.m_ClippingThresProj = 0.0; |
| 1189 | data.m_Parameters.m_ClippingThresCell = 0.0; |
| 1190 | |
| 1191 | |
| 1192 | // List of outputs |
| 1193 | std::vector<float> scratchBufferVector(batchSize * scratchBufferSize, 0.f); |
| 1194 | auto scratchBufferTensor = MakeTensor<float,2>(scratchBufferTensorInfo, scratchBufferVector); |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 1195 | LayerTestResult<T, 2> ret0(scratchBufferTensorInfo); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1196 | |
| 1197 | // Output state for a certain time step |
| 1198 | std::vector<float> outputStateOutVector(batchSize * outputSize, 0.f); |
| 1199 | auto outputStateOutTensor = MakeTensor<float,2>(outputStateOutTensorInfo, outputStateOutVector); |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 1200 | LayerTestResult<T, 2> ret1(outputStateOutTensorInfo); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1201 | |
| 1202 | // Cell state for a certain time step |
| 1203 | std::vector<float> cellStateOutVector(batchSize * cellSize, 0.f); |
| 1204 | auto cellStateOutTensor = MakeTensor<float,2>(cellStateOutTensorInfo, cellStateOutVector); |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 1205 | LayerTestResult<T, 2> ret2(cellStateOutTensorInfo); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1206 | |
| 1207 | // Output for a certain time step |
| 1208 | std::vector<float> outputVector(batchSize * outputSize, 0.f); |
| 1209 | auto outputTensor = MakeTensor<float, 2>(outputTensorInfo, outputVector); |
| 1210 | std::vector<float> outputData; |
| 1211 | outputData.assign(outputExpected.data(), outputExpected.data() + batchSize*outputSize); |
Conor Kennedy | b9971c9 | 2019-05-07 07:14:23 +0100 | [diff] [blame] | 1212 | LayerTestResult<T, 2> ret3(outputTensorInfo); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1213 | ret3.outputExpected = MakeTensor<float, 2>(outputTensorInfo, outputData); |
| 1214 | |
| 1215 | // Prepare the inputs and outputs for the workload |
| 1216 | std::unique_ptr<armnn::ITensorHandle> inputHandle = |
| 1217 | workloadFactory.CreateTensorHandle(inputTensorInfo); |
| 1218 | std::unique_ptr<armnn::ITensorHandle> outputStateInHandle = |
| 1219 | workloadFactory.CreateTensorHandle(outputStateInTensorInfo); |
| 1220 | std::unique_ptr<armnn::ITensorHandle> cellStateInHandle = |
| 1221 | workloadFactory.CreateTensorHandle(cellStateInTensorInfo); |
| 1222 | |
| 1223 | std::unique_ptr<armnn::ITensorHandle> scratchBufferHandle = |
| 1224 | workloadFactory.CreateTensorHandle(scratchBufferTensorInfo); |
| 1225 | std::unique_ptr<armnn::ITensorHandle> outputStateOutHandle = |
| 1226 | workloadFactory.CreateTensorHandle(outputStateOutTensorInfo); |
| 1227 | std::unique_ptr<armnn::ITensorHandle> cellStateOutHandle = |
| 1228 | workloadFactory.CreateTensorHandle(cellStateOutTensorInfo); |
| 1229 | std::unique_ptr<armnn::ITensorHandle> outputHandle = |
| 1230 | workloadFactory.CreateTensorHandle(outputTensorInfo); |
| 1231 | |
| 1232 | armnn::WorkloadInfo info; |
| 1233 | AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); |
| 1234 | AddInputToWorkload(data, info, outputStateInTensorInfo, outputStateInHandle.get()); |
| 1235 | AddInputToWorkload(data, info, cellStateInTensorInfo, cellStateInHandle.get()); |
| 1236 | |
| 1237 | AddOutputToWorkload(data, info, scratchBufferTensorInfo, scratchBufferHandle.get()); |
| 1238 | AddOutputToWorkload(data, info, outputStateOutTensorInfo, outputStateOutHandle.get()); |
| 1239 | AddOutputToWorkload(data, info, cellStateOutTensorInfo, cellStateOutHandle.get()); |
| 1240 | AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); |
| 1241 | |
| 1242 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateLstm(data, info); |
| 1243 | |
| 1244 | |
| 1245 | inputHandle->Allocate(); |
| 1246 | outputStateInHandle->Allocate(); |
| 1247 | cellStateInHandle->Allocate(); |
| 1248 | |
| 1249 | scratchBufferHandle->Allocate(); |
| 1250 | outputStateOutHandle->Allocate(); |
| 1251 | cellStateOutHandle->Allocate(); |
| 1252 | outputHandle->Allocate(); |
| 1253 | |
| 1254 | |
| 1255 | CopyDataToITensorHandle(inputHandle.get(), &inputTensor[0][0]); |
| 1256 | CopyDataToITensorHandle(outputStateInHandle.get(), &outputStateInTensor[0][0]); |
| 1257 | CopyDataToITensorHandle(cellStateInHandle.get(), &cellStateInTensor[0][0]); |
| 1258 | |
| 1259 | CopyDataToITensorHandle(scratchBufferHandle.get(), &scratchBufferTensor[0][0]); |
| 1260 | CopyDataToITensorHandle(outputStateOutHandle.get(), &outputStateOutTensor[0][0]); |
| 1261 | CopyDataToITensorHandle(cellStateOutHandle.get(), &cellStateOutTensor[0][0]); |
| 1262 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1263 | workload->Execute(); |
| 1264 | |
| 1265 | CopyDataFromITensorHandle(&ret0.output[0][0], scratchBufferHandle.get()); |
| 1266 | CopyDataFromITensorHandle(&ret1.output[0][0], outputStateOutHandle.get()); |
| 1267 | CopyDataFromITensorHandle(&ret2.output[0][0], cellStateOutHandle.get()); |
| 1268 | CopyDataFromITensorHandle(&ret3.output[0][0], outputHandle.get()); |
| 1269 | |
| 1270 | return ret3; |
| 1271 | } |
Jan Eilers | 38e05bd | 2019-06-26 13:10:09 +0100 | [diff] [blame] | 1272 | |
| 1273 | |
| 1274 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 1275 | LayerTestResult<T, 2> |
| 1276 | LstmLayerNoCifgWithPeepholeWithProjectionWithLayerNormTestImpl(armnn::IWorkloadFactory& workloadFactory, |
| 1277 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 1278 | const boost::multi_array<T, 2>& input, |
| 1279 | const boost::multi_array<T, 2>& outputExpected, |
| 1280 | float qScale = 0.0f, |
| 1281 | int32_t qOffset = 0, |
| 1282 | armnn::DataType constantDataType = armnn::DataType::Float32) |
| 1283 | { |
| 1284 | unsigned int batchSize = 2; |
| 1285 | unsigned int outputSize = 3; |
| 1286 | unsigned int inputSize = 5; |
| 1287 | unsigned numUnits = 4; |
| 1288 | |
| 1289 | armnn::TensorInfo inputTensorInfo({batchSize , inputSize}, ArmnnType, qScale, qOffset); |
| 1290 | armnn::TensorInfo cellStateInTensorInfo({batchSize , numUnits}, ArmnnType, qScale, qOffset); |
| 1291 | armnn::TensorInfo outputStateInTensorInfo({batchSize , outputSize}, ArmnnType, qScale, qOffset); |
| 1292 | |
| 1293 | // Scratch buffer size without CIFG [batchSize, numUnits * 4] |
| 1294 | armnn::TensorInfo scratchBufferTensorInfo({batchSize, numUnits * 4}, ArmnnType, qScale, qOffset); |
| 1295 | armnn::TensorInfo cellStateOutTensorInfo({batchSize, numUnits}, ArmnnType, qScale, qOffset); |
| 1296 | armnn::TensorInfo outputStateOutTensorInfo({batchSize, outputSize}, ArmnnType, qScale, qOffset); |
| 1297 | armnn::TensorInfo outputTensorInfo({batchSize, outputSize}, ArmnnType, qScale, qOffset); |
| 1298 | |
| 1299 | LayerTestResult<T, 2> ret(outputTensorInfo); |
| 1300 | |
| 1301 | std::vector<float> inputVector; |
| 1302 | inputVector.assign(input.data(), input.data() + (batchSize * inputSize)); |
| 1303 | auto inputTensor = MakeTensor<float,2>(inputTensorInfo, inputVector); |
| 1304 | |
| 1305 | std::vector<float> cellStateInVector(batchSize * numUnits, 0.f); |
| 1306 | auto cellStateInTensor = MakeTensor<float,2>(cellStateInTensorInfo, cellStateInVector); |
| 1307 | |
| 1308 | std::vector<float> outputStateInVector(batchSize * outputSize, 0.f); |
| 1309 | auto outputStateInTensor = MakeTensor<float,2>(outputStateInTensorInfo, outputStateInVector); |
| 1310 | |
| 1311 | std::vector<float> scratchBufferVector(batchSize * numUnits * 4, 0.f); |
| 1312 | auto scratchBufferTensor = MakeTensor<float,2>(scratchBufferTensorInfo, scratchBufferVector); |
| 1313 | |
| 1314 | std::vector<float> outputStateOutVector(batchSize * outputSize, 0.f); |
| 1315 | auto outputStateOutTensor = MakeTensor<float,2>(outputStateOutTensorInfo, outputStateOutVector); |
| 1316 | |
| 1317 | std::vector<float> cellStateOutVector(batchSize * numUnits, 0.f); |
| 1318 | auto cellStateOutTensor = MakeTensor<float,2>(cellStateOutTensorInfo, cellStateOutVector); |
| 1319 | |
| 1320 | std::vector<float> outputVector; |
| 1321 | outputVector.assign(outputExpected.data(), outputExpected.data() + (batchSize * outputSize)); |
| 1322 | ret.outputExpected = MakeTensor<float, 2>(outputTensorInfo, outputVector); |
| 1323 | |
| 1324 | std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); |
| 1325 | std::unique_ptr<armnn::ITensorHandle> cellStateInHandle = |
| 1326 | workloadFactory.CreateTensorHandle(cellStateInTensorInfo); |
| 1327 | std::unique_ptr<armnn::ITensorHandle> outputStateInHandle = |
| 1328 | workloadFactory.CreateTensorHandle(outputStateInTensorInfo); |
| 1329 | |
| 1330 | std::unique_ptr<armnn::ITensorHandle> scratchHandle = workloadFactory.CreateTensorHandle(scratchBufferTensorInfo); |
| 1331 | std::unique_ptr<armnn::ITensorHandle> outputStateOutHandle = |
| 1332 | workloadFactory.CreateTensorHandle(outputStateOutTensorInfo); |
| 1333 | std::unique_ptr<armnn::ITensorHandle> cellStateOutHandle = |
| 1334 | workloadFactory.CreateTensorHandle(cellStateOutTensorInfo); |
| 1335 | std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo); |
| 1336 | |
| 1337 | armnn::LstmQueueDescriptor data; |
| 1338 | armnn::WorkloadInfo info; |
| 1339 | |
| 1340 | AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); |
| 1341 | AddInputToWorkload(data, info, outputStateInTensorInfo, outputStateInHandle.get()); |
| 1342 | AddInputToWorkload(data, info, cellStateInTensorInfo, cellStateInHandle.get()); |
| 1343 | |
| 1344 | AddOutputToWorkload(data, info, scratchBufferTensorInfo, scratchHandle.get()); |
| 1345 | AddOutputToWorkload(data, info, outputStateOutTensorInfo, outputStateOutHandle.get()); |
| 1346 | AddOutputToWorkload(data, info, cellStateOutTensorInfo, cellStateOutHandle.get()); |
| 1347 | AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); |
| 1348 | |
| 1349 | armnn::TensorInfo tensorInfo3({outputSize}, constantDataType, qScale, qOffset); |
| 1350 | armnn::TensorInfo tensorInfo4({numUnits}, constantDataType, qScale, qOffset); |
| 1351 | armnn::TensorInfo tensorInfo4x5({numUnits, inputSize}, constantDataType, qScale, qOffset); |
| 1352 | armnn::TensorInfo tensorInfo4x3({numUnits, outputSize}, constantDataType, qScale, qOffset); |
| 1353 | armnn::TensorInfo tensorInfo3x4({outputSize, numUnits}, constantDataType, qScale, qOffset); |
| 1354 | |
| 1355 | auto inputToInputWeights = |
| 1356 | MakeTensor<float, 2>(tensorInfo4x5, { 0.5f, 0.6f, 0.7f, -0.8f, -0.9f, |
| 1357 | 0.1f, 0.2f, 0.3f, -0.4f, 0.5f, |
| 1358 | -0.8f, 0.7f, -0.6f, 0.5f, -0.4f, |
| 1359 | -0.5f, -0.4f, -0.3f, -0.2f, -0.1f}); //{numUnits, inputSize} |
| 1360 | |
| 1361 | auto inputToForgetWeights = |
| 1362 | MakeTensor<float, 2>(tensorInfo4x5, {-0.6f, -0.1f, 0.3f, 0.2f, 0.9f, |
| 1363 | -0.5f, -0.2f, -0.4f, 0.3f, -0.8f, |
| 1364 | -0.4f, 0.3f, -0.5f, -0.4f, -0.6f, |
| 1365 | 0.3f, -0.4f, -0.6f, -0.5f, -0.5f}); //{numUnits, inputSize} |
| 1366 | |
| 1367 | auto inputToCellWeights = |
| 1368 | MakeTensor<float, 2>(tensorInfo4x5, {-0.4f, -0.3f, -0.2f, -0.1f, -0.5f, |
| 1369 | 0.5f, -0.2f, -0.3f, -0.2f, -0.6f, |
| 1370 | 0.6f, -0.1f, -0.4f, -0.3f, -0.7f, |
| 1371 | 0.7f, -0.9f, -0.5f, 0.8f, 0.6f}); //{numUnits, inputSize} |
| 1372 | |
| 1373 | auto inputToOutputWeights = |
| 1374 | MakeTensor<float, 2>(tensorInfo4x5, {-0.8f, -0.4f, -0.2f, -0.9f, -0.1f, |
| 1375 | -0.7f, 0.3f, -0.3f, -0.8f, -0.2f, |
| 1376 | 0.6f, -0.2f, 0.4f, -0.7f, -0.3f, |
| 1377 | -0.5f, 0.1f, 0.5f, -0.6f, -0.4f}); //{numUnits, inputSize} |
| 1378 | |
| 1379 | auto inputGateBias = |
| 1380 | MakeTensor<float, 1>(tensorInfo4, {0.03f, 0.15f, 0.22f, 0.38f}); //{numUnits} |
| 1381 | |
| 1382 | auto forgetGateBias = |
| 1383 | MakeTensor<float, 1>(tensorInfo4, {0.1f, -0.3f, -0.2f, 0.1f}); //{numUnits} |
| 1384 | |
| 1385 | auto cellBias = |
| 1386 | MakeTensor<float, 1>(tensorInfo4, {-0.05f, 0.72f, 0.25f, 0.08f}); //{numUnits} |
| 1387 | |
| 1388 | auto outputGateBias = |
| 1389 | MakeTensor<float, 1>(tensorInfo4, {0.05f, -0.01f, 0.2f, 0.1f}); //{numUnits} |
| 1390 | |
| 1391 | auto recurrentToInputWeights = |
| 1392 | MakeTensor<float, 2>(tensorInfo4x3, {-0.2f, -0.3f, 0.4f, |
| 1393 | 0.1f, -0.5f, 0.9f, |
| 1394 | -0.2f, -0.3f, -0.7f, |
| 1395 | 0.05f, -0.2f, -0.6f}); //{numUnits, outputSize} |
| 1396 | |
| 1397 | auto recurrentToCellWeights = |
| 1398 | MakeTensor<float, 2>(tensorInfo4x3, {-0.3f, 0.2f, 0.1f, |
| 1399 | -0.3f, 0.8f, -0.08f, |
| 1400 | -0.2f, 0.3f, 0.8f, |
| 1401 | -0.6f, -0.1f, 0.2f}); //{numUnits, outputSize} |
| 1402 | |
| 1403 | auto recurrentToForgetWeights = |
| 1404 | MakeTensor<float, 2>(tensorInfo4x3, {-0.5f, -0.3f, -0.5f, |
| 1405 | -0.2f, 0.6f, 0.4f, |
| 1406 | 0.9f, 0.3f, -0.1f, |
| 1407 | 0.2f, 0.5f, 0.2f}); //{numUnits, outputSize} |
| 1408 | |
| 1409 | auto recurrentToOutputWeights = |
| 1410 | MakeTensor<float, 2>(tensorInfo4x3, { 0.3f, -0.1f, 0.1f, |
| 1411 | -0.2f, -0.5f, -0.7f, |
| 1412 | -0.2f, -0.6f, -0.1f, |
| 1413 | -0.4f, -0.7f, -0.2f}); //{numUnits, outputSize} |
| 1414 | |
| 1415 | auto cellToInputWeights = |
| 1416 | MakeTensor<float, 1>(tensorInfo4, {0.05f, 0.1f, 0.25f, 0.15f}); //{numUnits} |
| 1417 | |
| 1418 | auto cellToForgetWeights = |
| 1419 | MakeTensor<float, 1>(tensorInfo4, {-0.02f, -0.15f, -0.25f, -0.03f}); //{numUnits} |
| 1420 | |
| 1421 | auto cellToOutputWeights = |
| 1422 | MakeTensor<float, 1>(tensorInfo4, {0.1f, -0.1f, -0.5f, 0.05f}); //{numUnits} |
| 1423 | |
| 1424 | auto projectionWeights = |
| 1425 | MakeTensor<float, 2>(tensorInfo3x4, |
| 1426 | {-0.1f, 0.2f, 0.01f, -0.2f, |
| 1427 | 0.1f, 0.5f, 0.3f, 0.08f, |
| 1428 | 0.07f, 0.2f, -0.4f, 0.2f}); //{outputSize, numUnits} |
| 1429 | |
| 1430 | std::vector<float> projectionBiasVector(outputSize, 0.f); |
| 1431 | auto projectionBias = MakeTensor<float,1>(tensorInfo3, projectionBiasVector); //{outputSize} |
| 1432 | |
| 1433 | auto inputLayerNormWeights = |
| 1434 | MakeTensor<float, 1>(tensorInfo4, {0.1f, 0.2f, 0.3f, 0.5f}); //{numUnits} |
| 1435 | |
| 1436 | auto forgetLayerNormWeights = |
| 1437 | MakeTensor<float, 1>(tensorInfo4, {0.2f, 0.2f, 0.4f, 0.3f}); //{numUnits} |
| 1438 | |
| 1439 | auto cellLayerNormWeights = |
| 1440 | MakeTensor<float, 1>(tensorInfo4, {0.7f, 0.2f, 0.3f, 0.8f}); //{numUnits} |
| 1441 | |
| 1442 | auto outputLayerNormWeights = |
| 1443 | MakeTensor<float, 1>(tensorInfo4, {0.6f, 0.2f, 0.2f, 0.5f}); //{numUnits} |
| 1444 | |
| 1445 | |
| 1446 | armnn::ScopedCpuTensorHandle inputToInputWeightsTensor(tensorInfo4x5); |
| 1447 | armnn::ScopedCpuTensorHandle inputToForgetWeightsTensor(tensorInfo4x5); |
| 1448 | armnn::ScopedCpuTensorHandle inputToCellWeightsTensor(tensorInfo4x5); |
| 1449 | armnn::ScopedCpuTensorHandle inputToOutputWeightsTensor(tensorInfo4x5); |
| 1450 | armnn::ScopedCpuTensorHandle recurrentToForgetWeightsTensor(tensorInfo4x3); |
| 1451 | armnn::ScopedCpuTensorHandle recurrentToInputWeightsTensor(tensorInfo4x3); |
| 1452 | armnn::ScopedCpuTensorHandle recurrentToCellWeightsTensor(tensorInfo4x3); |
| 1453 | armnn::ScopedCpuTensorHandle recurrentToOutputWeightsTensor(tensorInfo4x3); |
| 1454 | armnn::ScopedCpuTensorHandle cellToInputWeightsTensor(tensorInfo4); |
| 1455 | armnn::ScopedCpuTensorHandle inputGateBiasTensor(tensorInfo4); |
| 1456 | armnn::ScopedCpuTensorHandle forgetGateBiasTensor(tensorInfo4); |
| 1457 | armnn::ScopedCpuTensorHandle cellBiasTensor(tensorInfo4); |
| 1458 | armnn::ScopedCpuTensorHandle outputGateBiasTensor(tensorInfo4); |
| 1459 | armnn::ScopedCpuTensorHandle cellToForgetWeightsTensor(tensorInfo4); |
| 1460 | armnn::ScopedCpuTensorHandle cellToOutputWeightsTensor(tensorInfo4); |
| 1461 | armnn::ScopedCpuTensorHandle projectionWeightsTensor(tensorInfo3x4); |
| 1462 | armnn::ScopedCpuTensorHandle projectionBiasTensor(tensorInfo3); |
| 1463 | |
| 1464 | armnn::ScopedCpuTensorHandle inputLayerNormWeightsTensor(tensorInfo4); |
| 1465 | armnn::ScopedCpuTensorHandle forgetLayerNormWeightsTensor(tensorInfo4); |
| 1466 | armnn::ScopedCpuTensorHandle cellLayerNormWeightsTensor(tensorInfo4); |
| 1467 | armnn::ScopedCpuTensorHandle outputLayerNormWeightsTensor(tensorInfo4); |
| 1468 | |
| 1469 | AllocateAndCopyDataToITensorHandle(&inputToInputWeightsTensor, &inputToInputWeights[0][0]); |
| 1470 | AllocateAndCopyDataToITensorHandle(&inputToForgetWeightsTensor, &inputToForgetWeights[0][0]); |
| 1471 | AllocateAndCopyDataToITensorHandle(&inputToCellWeightsTensor, &inputToCellWeights[0][0]); |
| 1472 | AllocateAndCopyDataToITensorHandle(&inputToOutputWeightsTensor, &inputToOutputWeights[0][0]); |
| 1473 | AllocateAndCopyDataToITensorHandle(&recurrentToInputWeightsTensor, &recurrentToInputWeights[0][0]); |
| 1474 | AllocateAndCopyDataToITensorHandle(&recurrentToForgetWeightsTensor, &recurrentToForgetWeights[0][0]); |
| 1475 | AllocateAndCopyDataToITensorHandle(&recurrentToCellWeightsTensor, &recurrentToCellWeights[0][0]); |
| 1476 | AllocateAndCopyDataToITensorHandle(&recurrentToOutputWeightsTensor, &recurrentToOutputWeights[0][0]); |
| 1477 | AllocateAndCopyDataToITensorHandle(&cellToInputWeightsTensor, &cellToInputWeights[0]); |
| 1478 | AllocateAndCopyDataToITensorHandle(&inputGateBiasTensor, &inputGateBias[0]); |
| 1479 | AllocateAndCopyDataToITensorHandle(&forgetGateBiasTensor, &forgetGateBias[0]); |
| 1480 | AllocateAndCopyDataToITensorHandle(&cellBiasTensor, &cellBias[0]); |
| 1481 | AllocateAndCopyDataToITensorHandle(&outputGateBiasTensor, &outputGateBias[0]); |
| 1482 | AllocateAndCopyDataToITensorHandle(&cellToForgetWeightsTensor, &cellToForgetWeights[0]); |
| 1483 | AllocateAndCopyDataToITensorHandle(&cellToOutputWeightsTensor, &cellToOutputWeights[0]); |
| 1484 | AllocateAndCopyDataToITensorHandle(&projectionWeightsTensor, &projectionWeights[0][0]); |
| 1485 | AllocateAndCopyDataToITensorHandle(&projectionBiasTensor, &projectionBias[0]); |
| 1486 | |
| 1487 | AllocateAndCopyDataToITensorHandle(&inputLayerNormWeightsTensor, &inputLayerNormWeights[0]); |
| 1488 | AllocateAndCopyDataToITensorHandle(&forgetLayerNormWeightsTensor, &forgetLayerNormWeights[0]); |
| 1489 | AllocateAndCopyDataToITensorHandle(&cellLayerNormWeightsTensor, &cellLayerNormWeights[0]); |
| 1490 | AllocateAndCopyDataToITensorHandle(&outputLayerNormWeightsTensor, &outputLayerNormWeights[0]); |
| 1491 | |
| 1492 | data.m_InputToInputWeights = &inputToInputWeightsTensor; |
| 1493 | data.m_InputToForgetWeights = &inputToForgetWeightsTensor; |
| 1494 | data.m_InputToCellWeights = &inputToCellWeightsTensor; |
| 1495 | data.m_InputToOutputWeights = &inputToOutputWeightsTensor; |
| 1496 | data.m_RecurrentToInputWeights = &recurrentToInputWeightsTensor; |
| 1497 | data.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor; |
| 1498 | data.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor; |
| 1499 | data.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor; |
| 1500 | data.m_CellToInputWeights = &cellToInputWeightsTensor; |
| 1501 | data.m_InputGateBias = &inputGateBiasTensor; |
| 1502 | data.m_ForgetGateBias = &forgetGateBiasTensor; |
| 1503 | data.m_CellBias = &cellBiasTensor; |
| 1504 | data.m_OutputGateBias = &outputGateBiasTensor; |
| 1505 | data.m_CellToForgetWeights = &cellToForgetWeightsTensor; |
| 1506 | data.m_CellToOutputWeights = &cellToOutputWeightsTensor; |
| 1507 | data.m_ProjectionWeights = &projectionWeightsTensor; |
| 1508 | data.m_ProjectionBias = &projectionBiasTensor; |
| 1509 | |
| 1510 | data.m_InputLayerNormWeights = &inputLayerNormWeightsTensor; |
| 1511 | data.m_ForgetLayerNormWeights = &forgetLayerNormWeightsTensor; |
| 1512 | data.m_CellLayerNormWeights = &cellLayerNormWeightsTensor; |
| 1513 | data.m_OutputLayerNormWeights = &outputLayerNormWeightsTensor; |
| 1514 | |
| 1515 | // Flags to set test configuration |
| 1516 | data.m_Parameters.m_ActivationFunc = 4; |
| 1517 | data.m_Parameters.m_CifgEnabled = false; |
| 1518 | data.m_Parameters.m_PeepholeEnabled = true; |
| 1519 | data.m_Parameters.m_ProjectionEnabled = true; |
| 1520 | data.m_Parameters.m_LayerNormEnabled = true; |
| 1521 | |
| 1522 | |
| 1523 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateLstm(data, info); |
| 1524 | inputHandle->Allocate(); |
| 1525 | outputStateInHandle->Allocate(); |
| 1526 | cellStateInHandle->Allocate(); |
| 1527 | |
| 1528 | scratchHandle->Allocate(); |
| 1529 | outputStateOutHandle->Allocate(); |
| 1530 | cellStateOutHandle->Allocate(); |
| 1531 | outputHandle->Allocate(); |
| 1532 | |
| 1533 | CopyDataToITensorHandle(inputHandle.get(), &inputTensor[0][0]); |
| 1534 | CopyDataToITensorHandle(outputStateInHandle.get(), &outputStateInTensor[0][0]); |
| 1535 | CopyDataToITensorHandle(cellStateInHandle.get(), &cellStateInTensor[0][0]); |
| 1536 | |
| 1537 | workload->Execute(); |
| 1538 | |
| 1539 | CopyDataFromITensorHandle(&ret.output[0][0], outputHandle.get()); |
| 1540 | |
| 1541 | return ret; |
| 1542 | |
| 1543 | } |