From 0ae102a0fc9d66b7067cf8d7a0ed1af5ed65ae50 Mon Sep 17 00:00:00 2001 From: Mike Kelly Date: Mon, 25 Apr 2022 16:18:57 +0100 Subject: IVGCVSW-6806 Fixed issue with missing TensorInfos in UnidirectionalSequenceLSTM * Corrected TensorInfo order for IsUnidirectionalSequenceLstmSupported * outputStateOut TensorInfo is not optional. * cellStateOut TensorInfo is not optional. * TensorInfo Order matches other QLSTM/LSTM layers. !armnn:7455 Signed-off-by: Mike Kelly Change-Id: I5b0e0fa4b6e1c3da6689d9aefc9b959172c2e7d4 --- ConversionUtils_1_2.hpp | 25 ++++++++++++------- test/UnidirectionalSequenceLstm.hpp | 48 ++++++++++++++++++------------------- 2 files changed, 41 insertions(+), 32 deletions(-) diff --git a/ConversionUtils_1_2.hpp b/ConversionUtils_1_2.hpp index 1bcd9f2e..0ff50cff 100644 --- a/ConversionUtils_1_2.hpp +++ b/ConversionUtils_1_2.hpp @@ -3455,6 +3455,18 @@ bool ConvertUnidirectionalSequenceLstm(const HalOperation& operation, // Outputs const TensorInfo& outputInfo = GetTensorInfoForOperand(*output); + unsigned int batchSize = inputInfo.GetShape()[0]; + unsigned int outputSize = outputInfo.GetShape()[2]; + unsigned int numUnits = cellStateInInfo.GetShape()[1]; + + armnn::DataType dataType = inputInfo.GetDataType(); + float qScale = inputInfo.GetQuantizationScale(); + int qOffset = inputInfo.GetQuantizationOffset(); + + armnn::TensorInfo cellStateOutInfo({batchSize, numUnits}, cellStateInInfo.GetDataType(), + cellStateInInfo.GetQuantizationScale(), cellStateInInfo.GetQuantizationOffset()); + armnn::TensorInfo outputStateOutInfo({batchSize, outputSize}, dataType, qScale, qOffset); + // Basic parameters LstmInputParamsInfo paramsInfo; paramsInfo.m_InputToForgetWeights = &(params.m_InputToForgetWeights->GetInfo()); @@ -3505,9 +3517,6 @@ bool ConvertUnidirectionalSequenceLstm(const HalOperation& operation, paramsInfo.m_OutputLayerNormWeights = &(params.m_OutputLayerNormWeights->GetInfo()); } - auto hiddenStateOutInfo = EmptyOptional(); - auto cellStateOutInfo = EmptyOptional(); - bool isSupported = false; auto validateFunc = [&](const armnn::TensorInfo& outputInfo, bool& isSupported) { @@ -3518,9 +3527,9 @@ bool ConvertUnidirectionalSequenceLstm(const HalOperation& operation, inputInfo, outputStateInInfo, cellStateInInfo, - outputInfo, - hiddenStateOutInfo, + outputStateOutInfo, cellStateOutInfo, + outputInfo, desc, paramsInfo); }; @@ -3552,12 +3561,12 @@ bool ConvertUnidirectionalSequenceLstm(const HalOperation& operation, if (!isDynamic) { - return (SetupAndTrackLayerOutputSlot(operation, 0, *layer, 0, model, data)); + return (SetupAndTrackLayerOutputSlot(operation, 0, *layer, 2, model, data)); } else { - return (SetupAndTrackLayerOutputSlot( - operation, 0, *layer, 0, model, data, nullptr, validateFunc, ActivationFn::kActivationNone, true)); + return (SetupAndTrackLayerOutputSlot(operation, 0, *layer, 2, model, data, nullptr, + validateFunc, ActivationFn::kActivationNone, true)); } } diff --git a/test/UnidirectionalSequenceLstm.hpp b/test/UnidirectionalSequenceLstm.hpp index d03f8ab3..75b7a8d4 100644 --- a/test/UnidirectionalSequenceLstm.hpp +++ b/test/UnidirectionalSequenceLstm.hpp @@ -138,10 +138,10 @@ void UnidirectionalSequenceLstmTestImpl(const hidl_vec& inputDimension const std::vector& outputLayerNormWeightsValue, const hidl_vec& outputDimensions, const std::vector& outputValue, - const hidl_vec&, - const std::vector&, - const hidl_vec&, - const std::vector&, + const hidl_vec&, // outputStateOutDimensions, + const std::vector&, // outputStateOutValue, + const hidl_vec&, // cellStateOutDimensions, + const std::vector&, // cellStateOutValue, armnn::Compute compute, float epsilonValue = 0) { @@ -519,12 +519,12 @@ void UnidirectionalSequenceLstmLayerFloat32TestImpl(armnn::Compute compute) // 1: The hidden state (out): A 2-D tensor of ANEURALNETWORKS_TENSOR_FLOAT32/16, of shape // [batch_size, output_size]. This output is optional and can be omitted. If this output // is present then output #2 must be present as well. - hidl_vec hiddenStateOutDimensions{0}; - std::vector hiddenStateOutValue; + hidl_vec hiddenStateOutDimensions{batchSize, outputSize}; + std::vector hiddenStateOutValue(batchSize * outputSize, 0.f); // 2: The cell state (out): A 2-D tensor of ANEURALNETWORKS_TENSOR_FLOAT32/16, of shape // [batch_size, num_units]. This output is optional and can be omitted. - hidl_vec cellStateOutDimensions{0}; - std::vector cellStateOutValue; + hidl_vec cellStateOutDimensions{batchSize, numUnits}; + std::vector cellStateOutValue(batchSize * numUnits, 0.f); UnidirectionalSequenceLstmTestImpl(inputDimensions, inputValue, inputToInputWeightsDimensions, inputToInputWeightsValue, @@ -724,12 +724,12 @@ void UnidirectionalSequenceLstmLayerFloat32TimeMajorTestImpl(armnn::Compute comp // 1: The hidden state (out): A 2-D tensor of ANEURALNETWORKS_TENSOR_FLOAT32/16, of shape // [batch_size, output_size]. This output is optional and can be omitted. If this output // is present then output #2 must be present as well. - hidl_vec hiddenStateOutDimensions{0}; - std::vector hiddenStateOutValue; + hidl_vec hiddenStateOutDimensions{batchSize, outputSize}; + std::vector hiddenStateOutValue(batchSize * outputSize, 0.f); // 2: The cell state (out): A 2-D tensor of ANEURALNETWORKS_TENSOR_FLOAT32/16, of shape // [batch_size, num_units]. This output is optional and can be omitted. - hidl_vec cellStateOutDimensions{0}; - std::vector cellStateOutValue; + hidl_vec cellStateOutDimensions{batchSize, numUnits}; + std::vector cellStateOutValue(batchSize * numUnits, 0.f); UnidirectionalSequenceLstmTestImpl(inputDimensions, inputValue, inputToInputWeightsDimensions, inputToInputWeightsValue, @@ -964,12 +964,12 @@ void UnidirectionalSequenceLstmLayerNoCifgWithPeepholeWithProjectionTestImpl(arm // 1: The hidden state (out): A 2-D tensor of ANEURALNETWORKS_TENSOR_FLOAT32/16, of shape // [batch_size, output_size]. This output is optional and can be omitted. If this output // is present then output #2 must be present as well. - hidl_vec hiddenStateOutDimensions{0}; - std::vector hiddenStateOutValue; + hidl_vec hiddenStateOutDimensions{batchSize, outputSize}; + std::vector hiddenStateOutValue(batchSize * outputSize, 0.f); // 2: The cell state (out): A 2-D tensor of ANEURALNETWORKS_TENSOR_FLOAT32/16, of shape // [batch_size, num_units]. This output is optional and can be omitted. - hidl_vec cellStateOutDimensions{0}; - std::vector cellStateOutValue; + hidl_vec cellStateOutDimensions{batchSize, numUnits}; + std::vector cellStateOutValue(batchSize * numUnits, 0.f); UnidirectionalSequenceLstmTestImpl(inputDimensions, inputValue, inputToInputWeightsDimensions, inputToInputWeightsValue, @@ -1179,12 +1179,12 @@ void UnidirectionalSequenceLstmLayerNoCifgWithPeepholeWithProjectionWithLayerNor // 1: The hidden state (out): A 2-D tensor of ANEURALNETWORKS_TENSOR_FLOAT32/16, of shape // [batch_size, output_size]. This output is optional and can be omitted. If this output // is present then output #2 must be present as well. - hidl_vec hiddenStateOutDimensions{0}; - std::vector hiddenStateOutValue; + hidl_vec hiddenStateOutDimensions{batchSize, outputSize}; + std::vector hiddenStateOutValue(batchSize * outputSize, 0.f); // 2: The cell state (out): A 2-D tensor of ANEURALNETWORKS_TENSOR_FLOAT32/16, of shape // [batch_size, num_units]. This output is optional and can be omitted. - hidl_vec cellStateOutDimensions{0}; - std::vector cellStateOutValue; + hidl_vec cellStateOutDimensions{batchSize, numUnits}; + std::vector cellStateOutValue(batchSize * numUnits, 0.f); UnidirectionalSequenceLstmTestImpl(inputDimensions, inputValue, inputToInputWeightsDimensions, inputToInputWeightsValue, @@ -1376,12 +1376,12 @@ void UnidirectionalSequenceLstmWithCifgWithPeepholeNoProjectionTestImpl(armnn::C // 1: The hidden state (out): A 2-D tensor of ANEURALNETWORKS_TENSOR_FLOAT32/16, of shape // [batch_size, output_size]. This output is optional and can be omitted. If this output // is present then output #2 must be present as well. - hidl_vec hiddenStateOutDimensions{0}; - std::vector hiddenStateOutValue; + hidl_vec hiddenStateOutDimensions{batchSize, outputSize}; + std::vector hiddenStateOutValue(batchSize * outputSize, 0.f); // 2: The cell state (out): A 2-D tensor of ANEURALNETWORKS_TENSOR_FLOAT32/16, of shape // [batch_size, num_units]. This output is optional and can be omitted. - hidl_vec cellStateOutDimensions{0}; - std::vector cellStateOutValue; + hidl_vec cellStateOutDimensions{batchSize, numUnits}; + std::vector cellStateOutValue(batchSize * numUnits, 0.f); UnidirectionalSequenceLstmTestImpl(inputDimensions, inputValue, inputToInputWeightsDimensions, inputToInputWeightsValue, -- cgit v1.2.1