ArmNN
 21.08
QuantizedLstmEndToEndTestImpl.cpp File Reference
#include "QuantizedLstmEndToEndTestImpl.hpp"
#include "CommonTestUtils.hpp"
#include "EndToEndTestImpl.hpp"
#include <ResolveType.hpp>
#include <armnn/INetwork.hpp>
#include <armnn/QuantizedLstmParams.hpp>
#include <armnn/utility/NumericCast.hpp>
#include <test/TensorHelpers.hpp>
#include <doctest/doctest.h>
#include <type_traits>

Go to the source code of this file.

Functions

void QuantizedLstmEndToEnd (const std::vector< armnn::BackendId > &backends)
 

Function Documentation

◆ QuantizedLstmEndToEnd()

void QuantizedLstmEndToEnd ( const std::vector< armnn::BackendId > &  backends)

Definition at line 179 of file QuantizedLstmEndToEndTestImpl.cpp.

References armnn::Optimize(), armnn::QAsymmU8, and armnn::QSymmS16.

Referenced by TEST_SUITE().

180 {
181  std::vector<uint8_t> inputVector = {166, 179, 50, 150};
182  armnn::TensorInfo inputDesc({2, 2}, armnn::DataType::QAsymmU8);
183 
184  std::vector<int16_t> cellStateInVector = {876, 1034, 955, -909, 761, 1029, 796, -1036};
185  armnn::TensorInfo cellStateInDesc({2, 4}, armnn::DataType::QSymmS16);
186 
187  std::vector<uint8_t> outputStateInVector = {136, 150, 140, 115, 135, 152, 138, 112};
188  armnn::TensorInfo outputStateInDesc({2, 4}, armnn::DataType::QAsymmU8);
189 
190  std::vector<int16_t> cellStateOutVector = {1485, 1177, 1373, -1023, 1019, 1355, 1097, -1235};
191  armnn::TensorInfo cellStateOutVectorDesc({2, 4}, armnn::DataType::QSymmS16);
192 
193  std::vector<uint8_t> outputStateOutVector = {140, 151, 146, 112, 136, 156, 142, 112};
194  armnn::TensorInfo outputDesc({2, 4}, armnn::DataType::QAsymmU8);
195 
196  // Builds up the structure of the network
197  armnn::INetworkPtr net = CreateQuantizedLstmNetwork(inputDesc.GetShape(), outputDesc.GetShape());
198 
200  IRuntimePtr runtime(IRuntime::Create(options));
201 
202  // optimize the network
203  IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime->GetDeviceSpec());
204 
205  // Loads it into the runtime.
206  NetworkId netId;
207  runtime->LoadNetwork(netId, std::move(optNet));
208 
209  InputTensors inputTensors;
210  inputTensors.reserve(3);
211 
212  // input
213  inputTensors.push_back({0, ConstTensor(runtime->GetInputTensorInfo(netId, 0), inputVector.data())});
214  inputTensors.push_back({1, ConstTensor(runtime->GetInputTensorInfo(netId, 1), cellStateInVector.data())});
215  inputTensors.push_back({2, ConstTensor(runtime->GetInputTensorInfo(netId, 2), outputStateInVector.data())});
216 
217  OutputTensors outputTensors;
218  outputTensors.reserve(2);
219 
220  //output
221  std::vector<int16_t> cellStateOutResult(cellStateOutVector.size());
222  std::vector<uint8_t> outputStateOutResult(outputStateOutVector.size());
223  outputTensors.push_back({0, Tensor(runtime->GetOutputTensorInfo(netId, 0), cellStateOutResult.data())});
224  outputTensors.push_back({1, Tensor(runtime->GetOutputTensorInfo(netId, 1), outputStateOutResult.data())});
225 
226  // Does the inference.
227  runtime->EnqueueWorkload(netId, inputTensors, outputTensors);
228 
229  // Checks the results
230  constexpr int16_t toleranceInt16 = 2;
231  for (unsigned int i = 0u; i < cellStateOutResult.size(); ++i)
232  {
233  CHECK(IsCloseEnough(cellStateOutVector[i], cellStateOutResult[i], toleranceInt16));
234  }
235 
236  constexpr uint8_t toleranceUint8 = 1;
237  for (unsigned int i = 0u; i < outputStateOutResult.size(); ++i)
238  {
239  CHECK(IsCloseEnough(outputStateOutVector[i], outputStateOutResult[i], toleranceUint8));
240  }
241 }
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
Definition: IRuntime.hpp:30
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
Definition: Tensor.hpp:360
A tensor defined by a TensorInfo (shape and data type) and a mutable backing store.
Definition: Tensor.hpp:319
IOptimizedNetworkPtr Optimize(const INetwork &network, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptions &options=OptimizerOptions(), Optional< std::vector< std::string > &> messages=EmptyOptional())
Create an optimized version of the network.
Definition: Network.cpp:1613
int NetworkId
Definition: IRuntime.hpp:24
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
Definition: Tensor.hpp:327
std::vector< std::pair< LayerBindingId, class Tensor > > OutputTensors
Definition: Tensor.hpp:361
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
Definition: INetwork.hpp:173
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:172