18 #include <boost/test/unit_test.hpp> 20 #include <type_traits> 25 using MultiArray =
const boost::multi_array<uint8_t, 2>&;
28 MultiArray expectedOutput)
34 float inputOutputScale = 0.0078125f;
35 int32_t inputOutputOffset = 128;
37 float weightsScale = 0.00408021f;
38 int32_t weightsOffset = 100;
40 float biasScale = 3.1876640625e-05f;
41 int32_t biasOffset = 0;
43 float cellStateScale = 0.00048828125f;
44 int32_t cellStateOffset = 0;
60 const std::vector<uint8_t> inputToInputWeightsVector = {146, 250, 235, 171, 10, 218, 171, 108};
61 armnn::ConstTensor inputToInputWeightsTensor(inputWeightsInfo, inputToInputWeightsVector.data());
63 const std::vector<uint8_t> inputToForgetWeightsVector = {24, 50, 132, 179, 158, 110, 3, 169};
64 armnn::ConstTensor inputToForgetWeightsTensor(inputWeightsInfo, inputToForgetWeightsVector.data());
66 const std::vector<uint8_t> inputToCellWeightsTensorVector = {133, 34, 29, 49, 206, 109, 54, 183};
67 armnn::ConstTensor inputToCellWeightsTensor(inputWeightsInfo, inputToCellWeightsTensorVector.data());
69 const std::vector<uint8_t> inputToOutputWeightsTensorVector = {195, 187, 11, 99, 109, 10, 218, 48};
70 armnn::ConstTensor inputToOutputWeightsTensor(inputWeightsInfo, inputToOutputWeightsTensorVector.data());
72 const std::vector<uint8_t> recurrentToInputWeightsTensorVector =
73 {254, 206, 77, 168, 71, 20, 215, 6, 223, 7, 118, 225, 59, 130, 174, 26};
74 armnn::ConstTensor recurrentToInputWeightsTensor(recurrentWeightsInfo, recurrentToInputWeightsTensorVector.data());
76 const std::vector<uint8_t> recurrentToForgetWeightsTensorVector =
77 {137, 240, 103, 52, 68, 51, 237, 112, 0, 220, 89, 23, 69, 4, 207, 253};
79 recurrentToForgetWeightsTensorVector.data());
81 const std::vector<uint8_t> recurrentToCellWeightsTensorVector =
82 {172, 60, 205, 65, 14, 0, 140, 168, 240, 223, 133, 56, 142, 64, 246, 216};
83 armnn::ConstTensor recurrentToCellWeightsTensor(recurrentWeightsInfo, recurrentToCellWeightsTensorVector.data());
85 const std::vector<uint8_t> recurrentToOutputWeightsTensorVector =
86 {106, 214, 67, 23, 59, 158, 45, 3, 119, 132, 49, 205, 129, 218, 11, 98};
88 recurrentToOutputWeightsTensorVector.data());
90 const std::vector<int32_t> inputGateBiasTensorVector = {-7876, 13488, -726, 32839};
93 const std::vector<int32_t> forgetGateBiasTensorVector = {9206, -46884, -11693, -38724};
96 const std::vector<int32_t> cellBiasTensorVector = {39481, 48624, 48976, -21419};
99 const std::vector<int32_t> outputGateBiasTensorVector = {-58999, -17050, -41852, -40538};
102 data.m_InputToInputWeights = &inputToInputWeightsTensor;
103 data.m_InputToForgetWeights = &inputToForgetWeightsTensor;
104 data.m_InputToCellWeights = &inputToCellWeightsTensor;
105 data.m_InputToOutputWeights = &inputToOutputWeightsTensor;
106 data.m_RecurrentToInputWeights = &recurrentToInputWeightsTensor;
107 data.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor;
108 data.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor;
109 data.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor;
110 data.m_InputGateBias = &inputGateBiasTensor;
111 data.m_ForgetGateBias = &forgetGateBiasTensor;
112 data.m_CellBias = &cellBiasTensor;
113 data.m_OutputGateBias = &outputGateBiasTensor;
151 Connect(inputLayer, quantizedLstmLayer, inputTensorInfo, 0, 0);
152 Connect(cellStateIn, quantizedLstmLayer, cellStateInTensorInfo, 0, 1);
153 Connect(outputStateIn, quantizedLstmLayer, outputStateInTensorInfo, 0, 2);
156 Connect(quantizedLstmLayer, cellStateOut, cellStateOutTensorInfo, 0, 0);
157 Connect(quantizedLstmLayer, outputStateOut, outputTensorInfo, 1, 0);
165 typename std::enable_if<std::is_arithmetic<T>::value,
bool>::type
166 IsCloseEnough(T value1, T value2, T tolerance)
173 T diff = value1 >= value2 ?
static_cast<T
>(value1 - value2) : static_cast<T>(value2 - value1);
174 return diff <= tolerance;
181 std::vector<uint8_t> inputVector = {166, 179, 50, 150};
183 boost::multi_array<uint8_t, 2> input = MakeTensor<uint8_t, 2>(inputDesc, inputVector);
185 std::vector<int16_t> cellStateInVector = {876, 1034, 955, -909, 761, 1029, 796, -1036};
187 boost::multi_array<int16_t, 2> cellStateIn = MakeTensor<int16_t, 2>(cellStateInDesc, cellStateInVector);
189 std::vector<uint8_t> outputStateInVector = {136, 150, 140, 115, 135, 152, 138, 112};
191 boost::multi_array<uint8_t, 2> outputStateIn = MakeTensor<uint8_t, 2>(outputStateInDesc, outputStateInVector);
193 std::vector<int16_t> cellStateOutVector = {1485, 1177, 1373, -1023, 1019, 1355, 1097, -1235};
195 boost::multi_array<int16_t, 2> cellStateOut = MakeTensor<int16_t, 2>(cellStateOutVectorDesc, cellStateOutVector);
197 std::vector<uint8_t> outputStateOutVector = {140, 151, 146, 112, 136, 156, 142, 112};
199 boost::multi_array<uint8_t, 2> outputStateOut = MakeTensor<uint8_t, 2>(outputDesc, outputStateOutVector);
204 BOOST_TEST_CHECKPOINT(
"create a network");
214 runtime->LoadNetwork(netId, std::move(optNet));
217 inputTensors.reserve(3);
220 inputTensors.push_back({0,
ConstTensor(runtime->GetInputTensorInfo(netId, 0), inputVector.data())});
221 inputTensors.push_back({1,
ConstTensor(runtime->GetInputTensorInfo(netId, 1), cellStateInVector.data())});
222 inputTensors.push_back({2,
ConstTensor(runtime->GetInputTensorInfo(netId, 2), outputStateInVector.data())});
225 outputTensors.reserve(2);
228 std::vector<int16_t > cellStateOutResult(cellStateOutVector.size());
229 std::vector<uint8_t > outputStateOutResult(outputStateOutVector.size());
230 outputTensors.push_back({0,
Tensor(runtime->GetOutputTensorInfo(netId, 0), cellStateOutResult.data())});
231 outputTensors.push_back({1,
Tensor(runtime->GetOutputTensorInfo(netId, 1), outputStateOutResult.data())});
234 runtime->EnqueueWorkload(netId, inputTensors, outputTensors);
237 constexpr int16_t toleranceInt16 = 2;
238 for (
unsigned int i = 0u; i < cellStateOutResult.size(); ++i)
240 BOOST_CHECK(IsCloseEnough(cellStateOutVector[i], cellStateOutResult[i], toleranceInt16));
243 constexpr uint8_t toleranceUint8 = 1;
244 for (
unsigned int i = 0u; i < outputStateOutResult.size(); ++i)
246 BOOST_TEST(IsCloseEnough(outputStateOutVector[i], outputStateOutResult[i], toleranceUint8));
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
A tensor defined by a TensorInfo (shape and data type) and a mutable backing store.
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.
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
std::vector< std::pair< LayerBindingId, class Tensor > > OutputTensors
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
void QuantizedLstmEndToEnd(const std::vector< armnn::BackendId > &backends)
void Connect(armnn::IConnectableLayer *from, armnn::IConnectableLayer *to, const armnn::TensorInfo &tensorInfo, unsigned int fromIndex, unsigned int toIndex)
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
static INetworkPtr Create()