From bd575b270f65601ff7bdfdc58de45b9675d5541a Mon Sep 17 00:00:00 2001 From: Narumol Prangnawarat Date: Tue, 31 Aug 2021 16:53:54 +0100 Subject: MLCE-530 Add support of int8 weight for UnidirectionalSequenceLstm to Ref backend and armnn delegate Signed-off-by: Narumol Prangnawarat Change-Id: I203d0029c12221228ffe229acda3c90594394e9b --- .../src/test/UnidirectionalSequenceLstmTest.cpp | 638 +++++++++++++++++ docs/01_03_delegate.dox | 2 + docs/05_operator_list.dox | 45 +- .../UnidirectionalSequenceLstmTestImpl.cpp | 768 +++++++++++++++++++++ .../UnidirectionalSequenceLstmTestImpl.hpp | 25 + src/backends/reference/RefLayerSupport.cpp | 5 +- src/backends/reference/test/RefLayerTests.cpp | 10 + 7 files changed, 1454 insertions(+), 39 deletions(-) diff --git a/delegate/src/test/UnidirectionalSequenceLstmTest.cpp b/delegate/src/test/UnidirectionalSequenceLstmTest.cpp index f0a96da57e..4bee715788 100644 --- a/delegate/src/test/UnidirectionalSequenceLstmTest.cpp +++ b/delegate/src/test/UnidirectionalSequenceLstmTest.cpp @@ -786,7 +786,615 @@ void UnidirectionalSequenceLstmNoCifgWithPeepholeWithProjectionWithLayerNormTest isTimeMajor); } +void UnidirectionalSequenceLstmInt8Test(std::vector& backends) +{ + int32_t batchSize = 3; + int32_t timeSize = 2; + int32_t inputSize = 3; + int32_t outputSize = 4; + // cellSize and outputSize have the same size when there is no projection. + int32_t numUnits = outputSize; + + //tensorInfo12 + bool hasInputToInputWeights = true; + std::vector inputToInputWeights = { -4, -1, -1, -2, 3, -2, 2, 4, 1, -4, -2, 3 }; + + std::vector inputToForgetWeights = { 2, 1, 4, -4, 3, -1, -3, -2, -3, 1, -4, -1 }; + + std::vector inputToCellWeights = { -2, 1, -2, 4, -3, -2, -4, 3, -2, -2, -6, 3 }; + + std::vector inputToOutputWeights = { 2, 5, -4, 5, 2, -3, 5, 7, 3, -5, 1, -4 }; + + //tensorInfo16 + bool hasRecurrentToInputWeights = true; + std::vector recurrentToInputWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, 5, -1, 1, 3, -1, -1 }; + + std::vector recurrentToForgetWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, 5, -1, 1, 3, -2, -1 }; + + std::vector recurrentToCellWeights = { -2, -3, -1, -3, -4, 2, 1, -1, 2, 2, 1, 2, 3, -2, 3, -3 }; + + std::vector recurrentToOutputWeights = { -3, 3, -1, -2, -2, -2, -1, -5, 1, 3, -4, -1, -1, -1, 2, -1 }; + + // tensorInfo4 + bool hasCellToInputWeights = false; + std::vector cellToInputWeights; + bool hasCellToForgetWeights = false; + std::vector cellToForgetWeights; + bool hasCellToOutputWeights = false; + std::vector cellToOutputWeights; + + bool hasInputGateBias = true; + std::vector inputGateBias = { 0., 0., 0., 0. }; + std::vector forgetGateBias = { 1., 1., 1., 1. }; + std::vector cellBias = { 0., 0., 0., 0. }; + std::vector outputGateBias = { 0., 0., 0., 0. }; + + bool hasProjectionWeights = false; + std::vector projectionWeights; + bool hasProjectionBias = false; + std::vector projectionBias; + + bool hasInputLayerNormWeights = false; + std::vector inputLayerNormWeights; + bool hasForgetLayerNormWeights = false; + std::vector forgetLayerNormWeights; + bool hasCellLayerNormWeights = false; + std::vector cellLayerNormWeights; + bool hasOutputLayerNormWeights = false; + std::vector outputLayerNormWeights; + + std::vector inputValues = { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.4f, + 0.3f, 0.2f, 0.1f, 0.2f, 0.3f, 0.4f, + 0.5f, 0.4f, 0.3f, 0.2f, 0.1f, 0.2f }; + + std::vector expectedOutputValues = { -0.0142517f, -0.0198845f, -0.0120569f, -0.0116868f, + -0.0350714f, -0.0343202f, -0.047504f, -0.0569789f, + -0.0146346f, 0.0106663f, -0.0247238f, -0.0319502f, + -0.0294759f, -0.0129935f, -0.0444175f, -0.0444354f, + -0.0280855f, 0.00545101f, -0.051422f, -0.0463838f, + -0.0310702f, 0.00915739f, -0.0625207f, -0.0482648f }; + + tflite::ActivationFunctionType activationFunction = tflite::ActivationFunctionType_TANH; + float clippingThresCell = 10.f; + float clippingThresProj = 0.f; + bool isTimeMajor = false; + + UnidirectionalSequenceLstmTestImpl(backends, + ::tflite::TensorType_INT8, + batchSize, + timeSize, + inputSize, + outputSize, + numUnits, + hasInputToInputWeights, + inputToInputWeights, + inputToForgetWeights, + inputToCellWeights, + inputToOutputWeights, + hasRecurrentToInputWeights, + recurrentToInputWeights, + recurrentToForgetWeights, + recurrentToCellWeights, + recurrentToOutputWeights, + hasCellToInputWeights, + cellToInputWeights, + hasCellToForgetWeights, + cellToForgetWeights, + hasCellToOutputWeights, + cellToOutputWeights, + hasInputGateBias, + inputGateBias, + forgetGateBias, + cellBias, + outputGateBias, + hasProjectionWeights, + projectionWeights, + hasProjectionBias, + projectionBias, + hasInputLayerNormWeights, + inputLayerNormWeights, + hasForgetLayerNormWeights, + forgetLayerNormWeights, + hasCellLayerNormWeights, + cellLayerNormWeights, + hasOutputLayerNormWeights, + outputLayerNormWeights, + inputValues, + expectedOutputValues, + activationFunction, + clippingThresCell, + clippingThresProj, + isTimeMajor, + 0.1f); +} + +void UnidirectionalSequenceLstmInt8TimeMajorTest(std::vector& backends) +{ + int32_t batchSize = 3; + int32_t timeSize = 2; + int32_t inputSize = 3; + int32_t outputSize = 4; + // cellSize and outputSize have the same size when there is no projection. + int32_t numUnits = outputSize; + + //tensorInfo12 + bool hasInputToInputWeights = true; + std::vector inputToInputWeights = { -4, -1, -1, -2, 3, -2, 2, 4, 1, -4, -2, 3 }; + + std::vector inputToForgetWeights = { 2, 1, 4, -4, 3, -1, -3, -2, -3, 1, -4, -1 }; + + std::vector inputToCellWeights = { -2, 1, -2, 4, -3, -2, -4, 3, -2, -2, -6, 3 }; + + std::vector inputToOutputWeights = { 2, 5, -4, 5, 2, -3, 5, 7, 3, -5, 1, -4 }; + + //tensorInfo16 + bool hasRecurrentToInputWeights = true; + std::vector recurrentToInputWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, 5, -1, 1, 3, -1, -1 }; + std::vector recurrentToForgetWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, 5, -1, 1, 3, -2, -1 }; + + std::vector recurrentToCellWeights = { -2, -3, -1, -3, -4, 2, 1, -1, 2, 2, 1, 2, 3, -2, 3, -3 }; + + std::vector recurrentToOutputWeights = { -3, 3, -1, -2, -2, -2, -1, -5, 1, 3, -4, -1, -1, -1, 2, -1 }; + + // tensorInfo4 + bool hasCellToInputWeights = false; + std::vector cellToInputWeights; + bool hasCellToForgetWeights = false; + std::vector cellToForgetWeights; + bool hasCellToOutputWeights = false; + std::vector cellToOutputWeights; + + bool hasInputGateBias = true; + std::vector inputGateBias = { 0., 0., 0., 0. }; + std::vector forgetGateBias = { 1., 1., 1., 1. }; + std::vector cellBias = { 0., 0., 0., 0. }; + std::vector outputGateBias = { 0., 0., 0., 0. }; + + bool hasProjectionWeights = false; + std::vector projectionWeights; + bool hasProjectionBias = false; + std::vector projectionBias; + + bool hasInputLayerNormWeights = false; + std::vector inputLayerNormWeights; + bool hasForgetLayerNormWeights = false; + std::vector forgetLayerNormWeights; + bool hasCellLayerNormWeights = false; + std::vector cellLayerNormWeights; + bool hasOutputLayerNormWeights = false; + std::vector outputLayerNormWeights; + + std::vector inputValues = { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.4f, + 0.3f, 0.2f, 0.1f, 0.2f, 0.3f, 0.4f, + 0.5f, 0.4f, 0.3f, 0.2f, 0.1f, 0.2f }; + + std::vector expectedOutputValues = { -0.0142517f, -0.0198845f, -0.0120122f, -0.0116868f, + -0.0261295f, -0.0188487f, -0.0345463f, -0.049733f, + -0.0146346f, 0.0106663f, -0.0247238f, -0.0319502f, + -0.0291863f, -0.0369402f, -0.0354071f, -0.0296529f, + -0.0419539f, -0.00617731f, -0.0814796f, -0.0804005f, + -0.0244737f, 0.0119905f, -0.0457527f, -0.0331862f }; + + tflite::ActivationFunctionType activationFunction = tflite::ActivationFunctionType_TANH; + float clippingThresCell = 10.f; + float clippingThresProj = 0.f; + bool isTimeMajor = true; + + UnidirectionalSequenceLstmTestImpl(backends, + ::tflite::TensorType_INT8, + batchSize, + timeSize, + inputSize, + outputSize, + numUnits, + hasInputToInputWeights, + inputToInputWeights, + inputToForgetWeights, + inputToCellWeights, + inputToOutputWeights, + hasRecurrentToInputWeights, + recurrentToInputWeights, + recurrentToForgetWeights, + recurrentToCellWeights, + recurrentToOutputWeights, + hasCellToInputWeights, + cellToInputWeights, + hasCellToForgetWeights, + cellToForgetWeights, + hasCellToOutputWeights, + cellToOutputWeights, + hasInputGateBias, + inputGateBias, + forgetGateBias, + cellBias, + outputGateBias, + hasProjectionWeights, + projectionWeights, + hasProjectionBias, + projectionBias, + hasInputLayerNormWeights, + inputLayerNormWeights, + hasForgetLayerNormWeights, + forgetLayerNormWeights, + hasCellLayerNormWeights, + cellLayerNormWeights, + hasOutputLayerNormWeights, + outputLayerNormWeights, + inputValues, + expectedOutputValues, + activationFunction, + clippingThresCell, + clippingThresProj, + isTimeMajor, + 0.1); +} + +void UnidirectionalSequenceLstmInt8NoCifgWithPeepholeWithProjectionTest(std::vector& backends) +{ + int32_t batchSize = 3; + int32_t timeSize = 2; + int32_t inputSize = 3; + int32_t outputSize = 4; + int32_t numUnits = 4; + + bool hasInputToInputWeights = true; + std::vector inputToInputWeights = { -4, -1, -1, -2, 3, -2, 2, 4, 1, -4, -2, 3 }; + + std::vector inputToForgetWeights = { 2, 1, 4, -4, 3, -1, -3, -2, -3, 1, -4, -1 }; + + std::vector inputToCellWeights = { -2, 1, -2, 4, -3, -2, -4, 3, -2, -2, -6, 3 }; + + std::vector inputToOutputWeights = { 2, 5, -4, 5, 2, -3, 5, 7, 3, -5, 1, -4 }; + + //tensorInfo16 + bool hasRecurrentToInputWeights = true; + std::vector recurrentToInputWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, 5, -1, 1, 3, -1, -1 }; + + std::vector recurrentToForgetWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, 5, -1, 1, 3, -2, -1 }; + + std::vector recurrentToCellWeights = { -2, -3, -1, -3, -4, 2, 1, -1, 2, 2, 1, 2, 3, -2, 3, -3 }; + + std::vector recurrentToOutputWeights = { -3, 3, -1, -2, -2, -2, -1, -5, 1, 3, -4, -1, -1, -1, 2, -1 }; + + // tensorInfo4 + bool hasCellToInputWeights = true; + std::vector cellToInputWeights = { 5, 10, 25, 15 }; + bool hasCellToForgetWeights = true; + std::vector cellToForgetWeights = { -5, 15, 25, 3 }; + bool hasCellToOutputWeights = true; + std::vector cellToOutputWeights = { 10, -10, -5, 50 }; + + bool hasInputGateBias = true; + std::vector inputGateBias = { 0.02234832f, 0.14757581f, 0.18176508f, 0.10380666f}; + std::vector forgetGateBias = { 0.035185695f, -0.042891346f, -0.3032477f, 0.23027696f}; + std::vector cellBias = { -0.124379363f, 0.55531194f, 0.23377132f, 0.033463873f }; + std::vector outputGateBias = { 0.046159424f, -0.12809046f, 0.03563469f, 0.12648113f }; + + bool hasProjectionWeights = true; + std::vector projectionWeights = { -25, 51, 3, -5, 25, 127, 77, 20, 18, 51, -10, 51, -25, 88, 77, -13 }; + bool hasProjectionBias = true; + std::vector projectionBias(outputSize, 0.f); + + bool hasInputLayerNormWeights = false; + std::vector inputLayerNormWeights; + bool hasForgetLayerNormWeights = false; + std::vector forgetLayerNormWeights; + bool hasCellLayerNormWeights = false; + std::vector cellLayerNormWeights; + bool hasOutputLayerNormWeights = false; + std::vector outputLayerNormWeights; + + std::vector inputValues = { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.4f, + 0.3f, 0.2f, 0.1f, 0.2f, 0.3f, 0.4f, + 0.5f, 0.4f, 0.3f, 0.2f, 0.1f, 0.2f }; + + std::vector expectedOutputValues = { 0.612103f, 1.56788f, 0.31966f, 1.42956f, + 0.909718f, 3.07916f, -0.560586f, 3.8907f, + 0.753671f, 1.77485f, 0.365122f, 1.60077f, + 0.812644f, 2.79092f, -0.605396f, 3.61742f, + 0.791857f, 1.64353f, 0.316588f, 1.55192f, + 0.807265f, 2.47012f, -0.539598f, 3.25654f }; + + tflite::ActivationFunctionType activationFunction = tflite::ActivationFunctionType_TANH; + float clippingThresCell = 10.f; + float clippingThresProj = 0.f; + bool isTimeMajor = false; + + UnidirectionalSequenceLstmTestImpl(backends, + ::tflite::TensorType_INT8, + batchSize, + timeSize, + inputSize, + outputSize, + numUnits, + hasInputToInputWeights, + inputToInputWeights, + inputToForgetWeights, + inputToCellWeights, + inputToOutputWeights, + hasRecurrentToInputWeights, + recurrentToInputWeights, + recurrentToForgetWeights, + recurrentToCellWeights, + recurrentToOutputWeights, + hasCellToInputWeights, + cellToInputWeights, + hasCellToForgetWeights, + cellToForgetWeights, + hasCellToOutputWeights, + cellToOutputWeights, + hasInputGateBias, + inputGateBias, + forgetGateBias, + cellBias, + outputGateBias, + hasProjectionWeights, + projectionWeights, + hasProjectionBias, + projectionBias, + hasInputLayerNormWeights, + inputLayerNormWeights, + hasForgetLayerNormWeights, + forgetLayerNormWeights, + hasCellLayerNormWeights, + cellLayerNormWeights, + hasOutputLayerNormWeights, + outputLayerNormWeights, + inputValues, + expectedOutputValues, + activationFunction, + clippingThresCell, + clippingThresProj, + isTimeMajor, + 0.1f); +} + +void UnidirectionalSequenceLstmInt8WithCifgWithPeepholeNoProjectionTest(std::vector& backends) +{ + int32_t batchSize = 3; + int32_t timeSize = 2; + int32_t inputSize = 3; + int32_t outputSize = 4; + // cellSize and outputSize have the same size when there is no projection. + int32_t numUnits = outputSize; + + //tensorInfo12, + bool hasInputToInputWeights = false; + std::vector inputToInputWeights; + + std::vector inputToForgetWeights = { 2, 1, 4, -4, 3, -1, -3, -2, -3, 1, -4, -1 }; + + std::vector inputToCellWeights = { -2, 1, -2, 4, -3, -2, -4, 3, -2, -2, -6, 3 }; + + std::vector inputToOutputWeights = { 2, 5, -4, 5, 2, -3, 5, 7, 3, -5, 1, -4 }; + + //tensorInfo16, + bool hasRecurrentToInputWeights = false; + std::vector recurrentToInputWeights; + std::vector recurrentToForgetWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, 5, -1, 1, 3, -2, -1 }; + + std::vector recurrentToCellWeights = { -2, -3, -1, -3, -4, 2, 1, -1, 2, 2, 1, 2, 3, -2, 3, -3 }; + + std::vector recurrentToOutputWeights = { -3, 3, -1, -2, -2, -2, -1, -5, 1, 3, -4, -1, -1, -1, 2, -1 }; + + // tensorInfo4 + bool hasCellToInputWeights = false; + std::vector cellToInputWeights; + bool hasCellToForgetWeights = true; + std::vector cellToForgetWeights = { 47, -52, -24, 31 }; + bool hasCellToOutputWeights = true; + std::vector cellToOutputWeights = { -17, 82, 85, -77 }; + + bool hasInputGateBias = false; + std::vector inputGateBias; + std::vector forgetGateBias = { 1., 1., 1., 1. }; + std::vector cellBias = { 0., 0., 0., 0. }; + std::vector outputGateBias = { 0., 0., 0., 0. }; + + bool hasProjectionWeights = false; + std::vector projectionWeights; + bool hasProjectionBias = false; + std::vector projectionBias; + + bool hasInputLayerNormWeights = false; + std::vector inputLayerNormWeights; + bool hasForgetLayerNormWeights = false; + std::vector forgetLayerNormWeights; + bool hasCellLayerNormWeights = false; + std::vector cellLayerNormWeights; + bool hasOutputLayerNormWeights = false; + std::vector outputLayerNormWeights; + + std::vector inputValues = { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.4f, + 0.3f, 0.2f, 0.1f, 0.2f, 0.3f, 0.4f, + 0.5f, 0.4f, 0.3f, 0.2f, 0.1f, 0.2f }; + + std::vector expectedOutputValues = { -0.0072104f, -0.00991171f, -0.00650478f, -0.00713055f, + -0.0191782f, -0.0161269f, -0.0233683f, -0.054299f, + -0.00783725f, 0.00635271f, -0.0126718f, -0.022613f, + -0.0161351f, -0.00775868f, -0.021054f, -0.0339778f, + -0.0146392f, 0.00330261f, -0.0258733f, -0.0407797f, + -0.0174297f, 0.0050105f, -0.0266275f, -0.0362564f }; + + tflite::ActivationFunctionType activationFunction = tflite::ActivationFunctionType_TANH; + float clippingThresCell = 10.f; + float clippingThresProj = 0.f; + bool isTimeMajor = false; + + UnidirectionalSequenceLstmTestImpl(backends, + ::tflite::TensorType_INT8, + batchSize, + timeSize, + inputSize, + outputSize, + numUnits, + hasInputToInputWeights, + inputToInputWeights, + inputToForgetWeights, + inputToCellWeights, + inputToOutputWeights, + hasRecurrentToInputWeights, + recurrentToInputWeights, + recurrentToForgetWeights, + recurrentToCellWeights, + recurrentToOutputWeights, + hasCellToInputWeights, + cellToInputWeights, + hasCellToForgetWeights, + cellToForgetWeights, + hasCellToOutputWeights, + cellToOutputWeights, + hasInputGateBias, + inputGateBias, + forgetGateBias, + cellBias, + outputGateBias, + hasProjectionWeights, + projectionWeights, + hasProjectionBias, + projectionBias, + hasInputLayerNormWeights, + inputLayerNormWeights, + hasForgetLayerNormWeights, + forgetLayerNormWeights, + hasCellLayerNormWeights, + cellLayerNormWeights, + hasOutputLayerNormWeights, + outputLayerNormWeights, + inputValues, + expectedOutputValues, + activationFunction, + clippingThresCell, + clippingThresProj, + isTimeMajor, + 0.1); +} + +void UnidirectionalSequenceLstmInt8NoCifgWithPeepholeWithProjectionWithLayerNormTest( + std::vector& backends) +{ + int32_t batchSize = 3; + int32_t timeSize = 2; + int32_t inputSize = 3; + int32_t outputSize = 4; + int32_t numUnits = 5; + + bool hasInputToInputWeights = true; + std::vector inputToInputWeights = { -4, -1, -1, -2, 3, -2, 2, 4, 1, -4, -2, 3, 2, 2, -4 }; + + std::vector inputToForgetWeights = { 2, 1, 4, -4, 3, -1, -3, -2, -3, 1, -4, -1, -3, -2, -4 }; + + std::vector inputToCellWeights = { -2, 1, -2, 4, -3, -2, -4, 3, -2, -2, -6, 3, 2, 5, -4 }; + + std::vector inputToOutputWeights = { 2, 5, -4, 5, 2, -3, 5, 7, 3, -5, 1, -4, -4, -1, -1 }; + + bool hasRecurrentToInputWeights = true; + std::vector recurrentToInputWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, + 5, -1, 1, 3, -1, -1, -1, 4, 2, 3 }; + + std::vector recurrentToForgetWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, + 5, -1, 1, 3, -2, -1, -1, 2, 2, 1 }; + + std::vector recurrentToCellWeights = { -2, -3, -1, -3, -4, 2, 1, -1, 2, 2, + 1, 2, 3, -2, 3, -3, -1, -5, 1, 3 }; + + std::vector recurrentToOutputWeights = { -3, 3, -1, -2, -2, -2, -1, -5, 1, 3, + -4, -1, -1, -1, 2, -1, 5, 1, -3, -4 }; + + // tensorInfo5 + bool hasCellToInputWeights = true; + std::vector cellToInputWeights = { 5, 3, 8, -5, 2 }; + bool hasCellToForgetWeights = true; + std::vector cellToForgetWeights = { -2, -7, 5, -3, 4 }; + bool hasCellToOutputWeights = true; + std::vector cellToOutputWeights = { 9, -10 , -5, 5, 1 }; + + bool hasInputGateBias = true; + std::vector inputGateBias = { 0.03f, 0.15f, 0.22f, 0.38f, 0.05f }; + std::vector forgetGateBias = { 0.1f, -0.3f, -0.2f, 0.1f, 0.4f }; + std::vector cellBias = { -0.05f, 0.72f, 0.25f, 0.08f, 0.1f }; + std::vector outputGateBias = { 0.05f, -0.01f, 0.2f, 0.1f, -0.2f }; + + bool hasProjectionWeights = true; + std::vector projectionWeights = { -1, 2, 1, -2, 1, 5, 3, 8, 7, 2, + -4, 2, 5, -4, 3, -2, 3, 8, -7, 2 }; + bool hasProjectionBias = true; + std::vector projectionBias(outputSize, 0.f); + + bool hasInputLayerNormWeights = true; + std::vector inputLayerNormWeights = { 0.1f, 0.2f, -0.3f, -0.1f, 0.5f }; + bool hasForgetLayerNormWeights = true; + std::vector forgetLayerNormWeights = { -0.1f, 0.2f, 0.3f, 0.5f, 0.2f }; + bool hasCellLayerNormWeights = true; + std::vector cellLayerNormWeights = { 0.5f, 0.2f, 0.3f, 0.4f, -0.5f }; + bool hasOutputLayerNormWeights = true; + std::vector outputLayerNormWeights = { 0.6f, -0.2f, -0.2f, 0.5f, 0.1f }; + + std::vector inputValues = { 1., 8., 3., 4., 5., 4., + 3., 2., 1., 2., 3., 4., + 5., 4., 3., 2., 1., 2. }; + + std::vector expectedOutputValues = { 0.0471276f, 0.0168155f, 0.0789885f, 0.16550f, + 0.0643133f, -0.0400722f, 0.100593f, 0.197722f, + 0.0465562f, -0.0600682f, 0.0622087f, 0.115053f, + 0.056287f, -0.0566218f, 0.0856832f, 0.148484f, + 0.0457859f, -0.0588112f, 0.0623636f, 0.114333f, + 0.0509271f, -0.0754262f, 0.058600f, 0.0801288f }; + + tflite::ActivationFunctionType activationFunction = tflite::ActivationFunctionType_TANH; + float clippingThresCell = 10.f; + float clippingThresProj = 0.f; + bool isTimeMajor = false; + + UnidirectionalSequenceLstmTestImpl(backends, + ::tflite::TensorType_INT8, + batchSize, + timeSize, + inputSize, + outputSize, + numUnits, + hasInputToInputWeights, + inputToInputWeights, + inputToForgetWeights, + inputToCellWeights, + inputToOutputWeights, + hasRecurrentToInputWeights, + recurrentToInputWeights, + recurrentToForgetWeights, + recurrentToCellWeights, + recurrentToOutputWeights, + hasCellToInputWeights, + cellToInputWeights, + hasCellToForgetWeights, + cellToForgetWeights, + hasCellToOutputWeights, + cellToOutputWeights, + hasInputGateBias, + inputGateBias, + forgetGateBias, + cellBias, + outputGateBias, + hasProjectionWeights, + projectionWeights, + hasProjectionBias, + projectionBias, + hasInputLayerNormWeights, + inputLayerNormWeights, + hasForgetLayerNormWeights, + forgetLayerNormWeights, + hasCellLayerNormWeights, + cellLayerNormWeights, + hasOutputLayerNormWeights, + outputLayerNormWeights, + inputValues, + expectedOutputValues, + activationFunction, + clippingThresCell, + clippingThresProj, + isTimeMajor, + 0.1); +} TEST_SUITE("UnidirectionalSequenceLstmTest_CpuRefTests") { @@ -821,6 +1429,36 @@ TEST_CASE ("UnidirectionalSequenceLstmNoCifgWithPeepholeWithProjectionWithLayerN UnidirectionalSequenceLstmNoCifgWithPeepholeWithProjectionWithLayerNormTest(backends); } +TEST_CASE ("UnidirectionalSequenceLstmInt8Test_CpuRef_Test") +{ + std::vector backends = {armnn::Compute::CpuRef}; + UnidirectionalSequenceLstmInt8Test(backends); +} + +TEST_CASE ("UnidirectionalSequenceLstmTimeInt8TimeMajorTest_CpuRef_Test") +{ + std::vector backends = {armnn::Compute::CpuRef}; + UnidirectionalSequenceLstmInt8TimeMajorTest(backends); +} + +TEST_CASE ("UnidirectionalSequenceLstmInt8NoCifgWithPeepholeWithProjectionTest_CpuRef_Test") +{ + std::vector backends = {armnn::Compute::CpuRef}; + UnidirectionalSequenceLstmInt8NoCifgWithPeepholeWithProjectionTest(backends); +} + +TEST_CASE ("UnidirectionalSequenceLstmInt8WithCifgWithPeepholeNoProjectionTest_CpuRef_Test") +{ + std::vector backends = {armnn::Compute::CpuRef}; + UnidirectionalSequenceLstmInt8WithCifgWithPeepholeNoProjectionTest(backends); +} + +TEST_CASE ("UnidirectionalSequenceLstmInt8NoCifgWithPeepholeWithProjectionWithLayerNormTest_CpuRef_Test") +{ + std::vector backends = {armnn::Compute::CpuRef}; + UnidirectionalSequenceLstmInt8NoCifgWithPeepholeWithProjectionWithLayerNormTest(backends); +} + } //End of TEST_SUITE("UnidirectionalSequenceLstmTest_CpuRef") } // namespace armnnDelegate \ No newline at end of file diff --git a/docs/01_03_delegate.dox b/docs/01_03_delegate.dox index 92cdf6d7e1..04f216a87d 100644 --- a/docs/01_03_delegate.dox +++ b/docs/01_03_delegate.dox @@ -165,6 +165,8 @@ The Arm NN SDK TensorFlow Lite delegate currently supports the following operato - TRANSPOSE_CONV +- UNIDIRECTIONAL_SEQUENCE_LSTM + - UNPACK More machine learning operators will be supported in future releases. diff --git a/docs/05_operator_list.dox b/docs/05_operator_list.dox index 4c4f6d10ed..1f4b43f55e 100644 --- a/docs/05_operator_list.dox +++ b/docs/05_operator_list.dox @@ -3173,7 +3173,7 @@ where N = batches, C = channels, H = height, W = width UnidirectionalSquenceLstmLayer - Layer to perform unidirectional LSTM operation. + Layer to perform unidirectional sequence LSTM operation.
  • ANEURALNETWORKS_UNIDIRECTIONAL_SEQUENCE_LSTM @@ -3185,43 +3185,14 @@ where N = batches, C = channels, H = height, W = width
-
-
All +
Input Types +
FLOAT32 +
+ +
Weight Types +
FLOAT32 +
QASYMMS8
- - CpuAcc - -
    -
  • NHWC -
  • NCHW -
- - -
-
SIGNED32 -
FLOAT16 -
FLOAT32 -
QASYMMU8 -
QASYMMS8 -
QUANTIZEDSYMM8PERAXIS -
- - GpuAcc - -
    -
  • NHWC -
  • NCHW -
- - -
-
SIGNED32 -
FLOAT16 -
FLOAT32 -
QASYMMU8 -
QASYMMS8 -
QUANTIZEDSYMM8PERAXIS -
UnmapLayer Layer to perform unmap operation on tensor. diff --git a/src/backends/backendsCommon/test/layerTests/UnidirectionalSequenceLstmTestImpl.cpp b/src/backends/backendsCommon/test/layerTests/UnidirectionalSequenceLstmTestImpl.cpp index ac22d5df48..d17dceb3f6 100644 --- a/src/backends/backendsCommon/test/layerTests/UnidirectionalSequenceLstmTestImpl.cpp +++ b/src/backends/backendsCommon/test/layerTests/UnidirectionalSequenceLstmTestImpl.cpp @@ -1028,3 +1028,771 @@ LayerTestResult UnidirectionalSequenceLstmWithCifgWithPeepholeNoProjec outputHandle->GetShape(), outputTensorInfo.GetShape()); } + +LayerTestResult UnidirectionalSequenceLstmLayerInt8Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + unsigned int batchSize = 3; + unsigned int timeSize = 2; + unsigned int inputSize = 3; + unsigned int outputSize = 4; + unsigned numUnits = outputSize; + + armnn::TensorInfo inputTensorInfo({batchSize, timeSize, inputSize}, armnn::DataType::Float32); + armnn::TensorInfo cellStateInTensorInfo({batchSize, numUnits}, armnn::DataType::Float32); + armnn::TensorInfo outputStateInTensorInfo({batchSize, outputSize}, armnn::DataType::Float32); + + armnn::TensorInfo outputTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32); + + const std::vector inputVector = { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.4f, + 0.3f, 0.2f, 0.1f, 0.2f, 0.3f, 0.4f, + 0.5f, 0.4f, 0.3f, 0.2f, 0.1f, 0.2f }; + + std::vector cellStateInVector(batchSize * numUnits, 0.f); + std::vector outputStateInVector(batchSize * outputSize, 0.f); + + std::vector actualOutput(outputTensorInfo.GetNumElements()); + + const std::vector outputVector = { -0.0142517f, -0.0198845f, -0.0120569f, -0.0116868f, + -0.0350714f, -0.0343202f, -0.047504f, -0.0569789f, + -0.0146346f, 0.0106663f, -0.0247238f, -0.0319502f, + -0.0294759f, -0.0129935f, -0.0444175f, -0.0444354f, + -0.0280855f, 0.00545101f, -0.051422f, -0.0463838f, + -0.0310702f, 0.00915739f, -0.0625207f, -0.0482648f }; + + std::unique_ptr inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo); + std::unique_ptr cellStateInHandle = + tensorHandleFactory.CreateTensorHandle(cellStateInTensorInfo); + std::unique_ptr outputStateInHandle = + tensorHandleFactory.CreateTensorHandle(outputStateInTensorInfo); + + std::unique_ptr outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo); + + armnn::UnidirectionalSequenceLstmQueueDescriptor data; + armnn::WorkloadInfo info; + + AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); + AddInputToWorkload(data, info, outputStateInTensorInfo, outputStateInHandle.get()); + AddInputToWorkload(data, info, cellStateInTensorInfo, cellStateInHandle.get()); + + AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); + + armnn::TensorInfo tensorInfoNumFp({numUnits}, armnn::DataType::Float32); + armnn::TensorInfo tensorInfoNumInput({numUnits, inputSize}, armnn::DataType::QAsymmS8, 0.1f, 0); + armnn::TensorInfo tensorInfoNumOutput({numUnits, outputSize}, armnn::DataType::QAsymmS8, 0.1f, 0); + + std::vector inputToInputWeights = { -4, -1, -1, -2, 3, -2, 2, 4, 1, -4, -2, 3 }; + std::vector inputToForgetWeights = { 2, 1, 4, -4, 3, -1, -3, -2, -3, 1, -4, -1 }; + std::vector inputToCellWeights = { -2, 1, -2, 4, -3, -2, -4, 3, -2, -2, -6, 3 }; + std::vector inputToOutputWeights = { 2, 5, -4, 5, 2, -3, 5, 7, 3, -5, 1, -4 }; + + std::vector recurrentToInputWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, 5, -1, 1, 3, -1, -1 }; + std::vector recurrentToForgetWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, 5, -1, 1, 3, -2, -1 }; + std::vector recurrentToCellWeights = { -2, -3, -1, -3, -4, 2, 1, -1, 2, 2, 1, 2, 3, -2, 3, -3 }; + std::vector recurrentToOutputWeights = { -3, 3, -1, -2, -2, -2, -1, -5, 1, 3, -4, -1, -1, -1, 2, -1 }; + + std::vector inputGateBias = { 0., 0., 0., 0. }; + std::vector forgetGateBias = { 1., 1., 1., 1. }; + std::vector cellBias = { 0., 0., 0., 0. }; + std::vector outputGateBias = { 0., 0., 0., 0. }; + + armnn::ScopedTensorHandle inputToInputWeightsTensor(tensorInfoNumInput); + armnn::ScopedTensorHandle inputToForgetWeightsTensor(tensorInfoNumInput); + armnn::ScopedTensorHandle inputToCellWeightsTensor(tensorInfoNumInput); + armnn::ScopedTensorHandle inputToOutputWeightsTensor(tensorInfoNumInput); + armnn::ScopedTensorHandle recurrentToInputWeightsTensor(tensorInfoNumOutput); + armnn::ScopedTensorHandle recurrentToForgetWeightsTensor(tensorInfoNumOutput); + armnn::ScopedTensorHandle recurrentToCellWeightsTensor(tensorInfoNumOutput); + armnn::ScopedTensorHandle recurrentToOutputWeightsTensor(tensorInfoNumOutput); + armnn::ScopedTensorHandle inputGateBiasTensor(tensorInfoNumFp); + armnn::ScopedTensorHandle forgetGateBiasTensor(tensorInfoNumFp); + armnn::ScopedTensorHandle cellBiasTensor(tensorInfoNumFp); + armnn::ScopedTensorHandle outputGateBiasTensor(tensorInfoNumFp); + + AllocateAndCopyDataToITensorHandle(&inputToInputWeightsTensor, inputToInputWeights.data()); + AllocateAndCopyDataToITensorHandle(&inputToForgetWeightsTensor, inputToForgetWeights.data()); + AllocateAndCopyDataToITensorHandle(&inputToCellWeightsTensor, inputToCellWeights.data()); + AllocateAndCopyDataToITensorHandle(&inputToOutputWeightsTensor, inputToOutputWeights.data()); + AllocateAndCopyDataToITensorHandle(&recurrentToInputWeightsTensor, recurrentToInputWeights.data()); + AllocateAndCopyDataToITensorHandle(&recurrentToForgetWeightsTensor, recurrentToForgetWeights.data()); + AllocateAndCopyDataToITensorHandle(&recurrentToCellWeightsTensor, recurrentToCellWeights.data()); + AllocateAndCopyDataToITensorHandle(&recurrentToOutputWeightsTensor, recurrentToOutputWeights.data()); + AllocateAndCopyDataToITensorHandle(&inputGateBiasTensor, inputGateBias.data()); + AllocateAndCopyDataToITensorHandle(&forgetGateBiasTensor, forgetGateBias.data()); + AllocateAndCopyDataToITensorHandle(&cellBiasTensor, cellBias.data()); + AllocateAndCopyDataToITensorHandle(&outputGateBiasTensor, outputGateBias.data()); + + data.m_InputToInputWeights = &inputToInputWeightsTensor; + data.m_InputToForgetWeights = &inputToForgetWeightsTensor; + data.m_InputToCellWeights = &inputToCellWeightsTensor; + data.m_InputToOutputWeights = &inputToOutputWeightsTensor; + data.m_RecurrentToInputWeights = &recurrentToInputWeightsTensor; + data.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor; + data.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor; + data.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor; + data.m_InputGateBias = &inputGateBiasTensor; + data.m_ForgetGateBias = &forgetGateBiasTensor; + data.m_CellBias = &cellBiasTensor; + data.m_OutputGateBias = &outputGateBiasTensor; + + // Flags to set test configuration + data.m_Parameters.m_ClippingThresCell = 10; + data.m_Parameters.m_ClippingThresProj = 0; + data.m_Parameters.m_ActivationFunc = 4; + data.m_Parameters.m_CifgEnabled = false; + data.m_Parameters.m_PeepholeEnabled = false; + data.m_Parameters.m_ProjectionEnabled = false; + data.m_Parameters.m_TimeMajor = false; + + std::unique_ptr workload = workloadFactory.CreateUnidirectionalSequenceLstm(data, info); + inputHandle->Allocate(); + outputStateInHandle->Allocate(); + cellStateInHandle->Allocate(); + + outputHandle->Allocate(); + + CopyDataToITensorHandle(inputHandle.get(), inputVector.data()); + CopyDataToITensorHandle(outputStateInHandle.get(), outputStateInVector.data()); + CopyDataToITensorHandle(cellStateInHandle.get(), cellStateInVector.data()); + + workload->Execute(); + + CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get()); + + return LayerTestResult(actualOutput, + outputVector, + outputHandle->GetShape(), + outputTensorInfo.GetShape()); +} + +LayerTestResult UnidirectionalSequenceLstmLayerInt8TimeMajorTest( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + unsigned int batchSize = 3; + unsigned int timeSize = 2; + unsigned int inputSize = 3; + unsigned int outputSize = 4; + unsigned numUnits = outputSize; + + armnn::TensorInfo inputTensorInfo({timeSize, batchSize, inputSize}, armnn::DataType::Float32); + armnn::TensorInfo cellStateInTensorInfo({batchSize, numUnits}, armnn::DataType::Float32); + armnn::TensorInfo outputStateInTensorInfo({batchSize, outputSize}, armnn::DataType::Float32); + + armnn::TensorInfo outputTensorInfo({timeSize, batchSize, outputSize}, armnn::DataType::Float32); + + const std::vector inputVector = { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.4f, + 0.3f, 0.2f, 0.1f, 0.2f, 0.3f, 0.4f, + 0.5f, 0.4f, 0.3f, 0.2f, 0.1f, 0.2f }; + + std::vector cellStateInVector(batchSize * numUnits, 0.f); + std::vector outputStateInVector(batchSize * outputSize, 0.f); + + std::vector actualOutput(outputTensorInfo.GetNumElements()); + + const std::vector outputVector = { -0.0142517f, -0.0198845f, -0.0120122f, -0.0116868f, + -0.0261295f, -0.0188487f, -0.0345463f, -0.049733f, + -0.0146346f, 0.0106663f, -0.0247238f, -0.0319502f, + -0.0291863f, -0.0369402f, -0.0354071f, -0.0296529f, + -0.0419539f, -0.00617731f, -0.0814796f, -0.0804005f, + -0.0244737f, 0.0119905f, -0.0457527f, -0.0331862f }; + std::unique_ptr inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo); + std::unique_ptr cellStateInHandle = + tensorHandleFactory.CreateTensorHandle(cellStateInTensorInfo); + std::unique_ptr outputStateInHandle = + tensorHandleFactory.CreateTensorHandle(outputStateInTensorInfo); + + std::unique_ptr outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo); + + armnn::UnidirectionalSequenceLstmQueueDescriptor data; + armnn::WorkloadInfo info; + + AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); + AddInputToWorkload(data, info, outputStateInTensorInfo, outputStateInHandle.get()); + AddInputToWorkload(data, info, cellStateInTensorInfo, cellStateInHandle.get()); + + AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); + + armnn::TensorInfo tensorInfoNumFp({numUnits}, armnn::DataType::Float32); + armnn::TensorInfo tensorInfoNumInput({numUnits, inputSize}, armnn::DataType::QAsymmS8, 0.1f, 0); + armnn::TensorInfo tensorInfoNumOutput({numUnits, outputSize}, armnn::DataType::QAsymmS8, 0.1f, 0); + + std::vector inputToInputWeights = { -4, -1, -1, -2, 3, -2, 2, 4, 1, -4, -2, 3 }; + std::vector inputToForgetWeights = { 2, 1, 4, -4, 3, -1, -3, -2, -3, 1, -4, -1 }; + std::vector inputToCellWeights = { -2, 1, -2, 4, -3, -2, -4, 3, -2, -2, -6, 3 }; + std::vector inputToOutputWeights = { 2, 5, -4, 5, 2, -3, 5, 7, 3, -5, 1, -4 }; + + std::vector recurrentToInputWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, 5, -1, 1, 3, -1, -1 }; + std::vector recurrentToForgetWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, 5, -1, 1, 3, -2, -1 }; + std::vector recurrentToCellWeights = { -2, -3, -1, -3, -4, 2, 1, -1, 2, 2, 1, 2, 3, -2, 3, -3 }; + std::vector recurrentToOutputWeights = { -3, 3, -1, -2, -2, -2, -1, -5, 1, 3, -4, -1, -1, -1, 2, -1 }; + + + std::vector inputGateBias = { 0., 0., 0., 0. }; + std::vector forgetGateBias = { 1., 1., 1., 1. }; + std::vector cellBias = { 0., 0., 0., 0. }; + std::vector outputGateBias = { 0., 0., 0., 0. }; + + armnn::ScopedTensorHandle inputToInputWeightsTensor(tensorInfoNumInput); + armnn::ScopedTensorHandle inputToForgetWeightsTensor(tensorInfoNumInput); + armnn::ScopedTensorHandle inputToCellWeightsTensor(tensorInfoNumInput); + armnn::ScopedTensorHandle inputToOutputWeightsTensor(tensorInfoNumInput); + armnn::ScopedTensorHandle recurrentToInputWeightsTensor(tensorInfoNumOutput); + armnn::ScopedTensorHandle recurrentToForgetWeightsTensor(tensorInfoNumOutput); + armnn::ScopedTensorHandle recurrentToCellWeightsTensor(tensorInfoNumOutput); + armnn::ScopedTensorHandle recurrentToOutputWeightsTensor(tensorInfoNumOutput); + armnn::ScopedTensorHandle inputGateBiasTensor(tensorInfoNumFp); + armnn::ScopedTensorHandle forgetGateBiasTensor(tensorInfoNumFp); + armnn::ScopedTensorHandle cellBiasTensor(tensorInfoNumFp); + armnn::ScopedTensorHandle outputGateBiasTensor(tensorInfoNumFp); + + AllocateAndCopyDataToITensorHandle(&inputToInputWeightsTensor, inputToInputWeights.data()); + AllocateAndCopyDataToITensorHandle(&inputToForgetWeightsTensor, inputToForgetWeights.data()); + AllocateAndCopyDataToITensorHandle(&inputToCellWeightsTensor, inputToCellWeights.data()); + AllocateAndCopyDataToITensorHandle(&inputToOutputWeightsTensor, inputToOutputWeights.data()); + AllocateAndCopyDataToITensorHandle(&recurrentToInputWeightsTensor, recurrentToInputWeights.data()); + AllocateAndCopyDataToITensorHandle(&recurrentToForgetWeightsTensor, recurrentToForgetWeights.data()); + AllocateAndCopyDataToITensorHandle(&recurrentToCellWeightsTensor, recurrentToCellWeights.data()); + AllocateAndCopyDataToITensorHandle(&recurrentToOutputWeightsTensor, recurrentToOutputWeights.data()); + AllocateAndCopyDataToITensorHandle(&inputGateBiasTensor, inputGateBias.data()); + AllocateAndCopyDataToITensorHandle(&forgetGateBiasTensor, forgetGateBias.data()); + AllocateAndCopyDataToITensorHandle(&cellBiasTensor, cellBias.data()); + AllocateAndCopyDataToITensorHandle(&outputGateBiasTensor, outputGateBias.data()); + + data.m_InputToInputWeights = &inputToInputWeightsTensor; + data.m_InputToForgetWeights = &inputToForgetWeightsTensor; + data.m_InputToCellWeights = &inputToCellWeightsTensor; + data.m_InputToOutputWeights = &inputToOutputWeightsTensor; + data.m_RecurrentToInputWeights = &recurrentToInputWeightsTensor; + data.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor; + data.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor; + data.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor; + data.m_InputGateBias = &inputGateBiasTensor; + data.m_ForgetGateBias = &forgetGateBiasTensor; + data.m_CellBias = &cellBiasTensor; + data.m_OutputGateBias = &outputGateBiasTensor; + + // Flags to set test configuration + data.m_Parameters.m_ClippingThresCell = 10; + data.m_Parameters.m_ClippingThresProj = 0; + data.m_Parameters.m_ActivationFunc = 4; + data.m_Parameters.m_CifgEnabled = false; + data.m_Parameters.m_PeepholeEnabled = false; + data.m_Parameters.m_ProjectionEnabled = false; + data.m_Parameters.m_TimeMajor = true; + + std::unique_ptr workload = workloadFactory.CreateUnidirectionalSequenceLstm(data, info); + inputHandle->Allocate(); + outputStateInHandle->Allocate(); + cellStateInHandle->Allocate(); + + outputHandle->Allocate(); + + CopyDataToITensorHandle(inputHandle.get(), inputVector.data()); + CopyDataToITensorHandle(outputStateInHandle.get(), outputStateInVector.data()); + CopyDataToITensorHandle(cellStateInHandle.get(), cellStateInVector.data()); + + workload->Execute(); + + CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get()); + + return LayerTestResult(actualOutput, + outputVector, + outputHandle->GetShape(), + outputTensorInfo.GetShape()); +} + +LayerTestResult UnidirectionalSequenceLstmLayerInt8NoCifgWithPeepholeWithProjectionTest( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + unsigned int batchSize = 3; + unsigned int timeSize = 2; + unsigned int outputSize = 4; + unsigned int inputSize = 3; + unsigned numUnits = 4; + + armnn::TensorInfo inputTensorInfo({batchSize, timeSize, inputSize}, armnn::DataType::Float32); + armnn::TensorInfo cellStateInTensorInfo({batchSize , numUnits}, armnn::DataType::Float32); + armnn::TensorInfo outputStateInTensorInfo({batchSize , outputSize}, armnn::DataType::Float32); + armnn::TensorInfo outputTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32); + + const std::vector inputVector = { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.4f, + 0.3f, 0.2f, 0.1f, 0.2f, 0.3f, 0.4f, + 0.5f, 0.4f, 0.3f, 0.2f, 0.1f, 0.2f }; + + std::vector cellStateInVector(batchSize * numUnits, 0.f); + std::vector outputStateInVector(batchSize * outputSize, 0.f); + + std::vector actualOutput(outputTensorInfo.GetNumElements()); + + const std::vector expectedOutput = { 0.612103f, 1.56788f, 0.31966f, 1.42956f, + 0.909718f, 3.07916f, -0.560586f, 3.8907f, + 0.753671f, 1.77485f, 0.365122f, 1.60077f, + 0.812644f, 2.79092f, -0.605396f, 3.61742f, + 0.791857f, 1.64353f, 0.316588f, 1.55192f, + 0.807265f, 2.47012f, -0.539598f, 3.25654f }; + + std::unique_ptr inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo); + std::unique_ptr cellStateInHandle = + tensorHandleFactory.CreateTensorHandle(cellStateInTensorInfo); + std::unique_ptr outputStateInHandle = + tensorHandleFactory.CreateTensorHandle(outputStateInTensorInfo); + std::unique_ptr outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo); + + armnn::UnidirectionalSequenceLstmQueueDescriptor data; + armnn::WorkloadInfo info; + + AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); + AddInputToWorkload(data, info, outputStateInTensorInfo, outputStateInHandle.get()); + AddInputToWorkload(data, info, cellStateInTensorInfo, cellStateInHandle.get()); + AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); + + armnn::TensorInfo tensorInfoOut({outputSize}, armnn::DataType::Float32); + armnn::TensorInfo tensorInfoNumFp({numUnits}, armnn::DataType::Float32); + armnn::TensorInfo tensorInfoNum({numUnits}, armnn::DataType::QAsymmS8, 0.1f, 0); + armnn::TensorInfo tensorInfoNumInput({numUnits, inputSize}, armnn::DataType::QAsymmS8, 0.1f, 0); + armnn::TensorInfo tensorInfoNumOutput({numUnits, outputSize}, armnn::DataType::QAsymmS8, 0.1f, 0); + armnn::TensorInfo tensorInfoOutNum({outputSize, numUnits}, armnn::DataType::QAsymmS8, 0.1f, 0); + + std::vector inputToInputWeights = { -4, -1, -1, -2, 3, -2, 2, 4, 1, -4, -2, 3 }; + std::vector inputToForgetWeights = { 2, 1, 4, -4, 3, -1, -3, -2, -3, 1, -4, -1 }; + std::vector inputToCellWeights = { -2, 1, -2, 4, -3, -2, -4, 3, -2, -2, -6, 3 }; + std::vector inputToOutputWeights = { 2, 5, -4, 5, 2, -3, 5, 7, 3, -5, 1, -4 }; + + std::vector recurrentToInputWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, 5, -1, 1, 3, -1, -1 }; + std::vector recurrentToForgetWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, 5, -1, 1, 3, -2, -1 }; + std::vector recurrentToCellWeights = { -2, -3, -1, -3, -4, 2, 1, -1, 2, 2, 1, 2, 3, -2, 3, -3 }; + std::vector recurrentToOutputWeights = { -3, 3, -1, -2, -2, -2, -1, -5, 1, 3, -4, -1, -1, -1, 2, -1 }; + + std::vector inputGateBias = { 0.02234832f, 0.14757581f, 0.18176508f, 0.10380666f}; + std::vector forgetGateBias = { 0.035185695f, -0.042891346f, -0.3032477f, 0.23027696f}; + std::vector cellBias = { -0.124379363f, 0.55531194f, 0.23377132f, 0.033463873f }; + std::vector outputGateBias = { 0.046159424f, -0.12809046f, 0.03563469f, 0.12648113f }; + + std::vector cellToInputWeights = { 5, 10, 25, 15 }; + std::vector cellToForgetWeights = { -5, 15, 25, 3 }; + std::vector cellToOutputWeights = { 10, -10, -5, 50 }; + + std::vector projectionWeights = { -25, 51, 3, -5, 25, 127, 77, 20, 18, 51, -10, 51, -25, 88, 77, -13 }; + + std::vector projectionBiasVector(outputSize, 0.f); //{outputSize} + + armnn::ScopedTensorHandle inputToInputWeightsTensor(tensorInfoNumInput); + armnn::ScopedTensorHandle inputToForgetWeightsTensor(tensorInfoNumInput); + armnn::ScopedTensorHandle inputToCellWeightsTensor(tensorInfoNumInput); + armnn::ScopedTensorHandle inputToOutputWeightsTensor(tensorInfoNumInput); + armnn::ScopedTensorHandle recurrentToForgetWeightsTensor(tensorInfoNumOutput); + armnn::ScopedTensorHandle recurrentToInputWeightsTensor(tensorInfoNumOutput); + armnn::ScopedTensorHandle recurrentToCellWeightsTensor(tensorInfoNumOutput); + armnn::ScopedTensorHandle recurrentToOutputWeightsTensor(tensorInfoNumOutput); + armnn::ScopedTensorHandle cellToInputWeightsTensor(tensorInfoNum); + armnn::ScopedTensorHandle inputGateBiasTensor(tensorInfoNumFp); + armnn::ScopedTensorHandle forgetGateBiasTensor(tensorInfoNumFp); + armnn::ScopedTensorHandle cellBiasTensor(tensorInfoNumFp); + armnn::ScopedTensorHandle outputGateBiasTensor(tensorInfoNumFp); + armnn::ScopedTensorHandle cellToForgetWeightsTensor(tensorInfoNum); + armnn::ScopedTensorHandle cellToOutputWeightsTensor(tensorInfoNum); + armnn::ScopedTensorHandle projectionWeightsTensor(tensorInfoOutNum); + armnn::ScopedTensorHandle projectionBiasTensor(tensorInfoOut); + + AllocateAndCopyDataToITensorHandle(&inputToInputWeightsTensor, inputToInputWeights.data()); + AllocateAndCopyDataToITensorHandle(&inputToForgetWeightsTensor, inputToForgetWeights.data()); + AllocateAndCopyDataToITensorHandle(&inputToCellWeightsTensor, inputToCellWeights.data()); + AllocateAndCopyDataToITensorHandle(&inputToOutputWeightsTensor, inputToOutputWeights.data()); + AllocateAndCopyDataToITensorHandle(&recurrentToInputWeightsTensor, recurrentToInputWeights.data()); + AllocateAndCopyDataToITensorHandle(&recurrentToForgetWeightsTensor, recurrentToForgetWeights.data()); + AllocateAndCopyDataToITensorHandle(&recurrentToCellWeightsTensor, recurrentToCellWeights.data()); + AllocateAndCopyDataToITensorHandle(&recurrentToOutputWeightsTensor, recurrentToOutputWeights.data()); + AllocateAndCopyDataToITensorHandle(&cellToInputWeightsTensor, cellToInputWeights.data()); + AllocateAndCopyDataToITensorHandle(&inputGateBiasTensor, inputGateBias.data()); + AllocateAndCopyDataToITensorHandle(&forgetGateBiasTensor, forgetGateBias.data()); + AllocateAndCopyDataToITensorHandle(&cellBiasTensor, cellBias.data()); + AllocateAndCopyDataToITensorHandle(&outputGateBiasTensor, outputGateBias.data()); + AllocateAndCopyDataToITensorHandle(&cellToForgetWeightsTensor, cellToForgetWeights.data()); + AllocateAndCopyDataToITensorHandle(&cellToOutputWeightsTensor, cellToOutputWeights.data()); + AllocateAndCopyDataToITensorHandle(&projectionWeightsTensor, projectionWeights.data()); + AllocateAndCopyDataToITensorHandle(&projectionBiasTensor, projectionBiasVector.data()); + + data.m_InputToInputWeights = &inputToInputWeightsTensor; + data.m_InputToForgetWeights = &inputToForgetWeightsTensor; + data.m_InputToCellWeights = &inputToCellWeightsTensor; + data.m_InputToOutputWeights = &inputToOutputWeightsTensor; + data.m_RecurrentToInputWeights = &recurrentToInputWeightsTensor; + data.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor; + data.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor; + data.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor; + data.m_CellToInputWeights = &cellToInputWeightsTensor; + data.m_InputGateBias = &inputGateBiasTensor; + data.m_ForgetGateBias = &forgetGateBiasTensor; + data.m_CellBias = &cellBiasTensor; + data.m_OutputGateBias = &outputGateBiasTensor; + data.m_CellToForgetWeights = &cellToForgetWeightsTensor; + data.m_CellToOutputWeights = &cellToOutputWeightsTensor; + data.m_ProjectionWeights = &projectionWeightsTensor; + data.m_ProjectionBias = &projectionBiasTensor; + + // Flags to set test configuration + data.m_Parameters.m_ActivationFunc = 4; + data.m_Parameters.m_CifgEnabled = false; + data.m_Parameters.m_PeepholeEnabled = true; + data.m_Parameters.m_ProjectionEnabled = true; + data.m_Parameters.m_LayerNormEnabled = false; + data.m_Parameters.m_TimeMajor = false; + data.m_Parameters.m_ClippingThresCell = 10.0f; + + + std::unique_ptr workload = workloadFactory.CreateUnidirectionalSequenceLstm(data, info); + inputHandle->Allocate(); + outputStateInHandle->Allocate(); + cellStateInHandle->Allocate(); + outputHandle->Allocate(); + + CopyDataToITensorHandle(inputHandle.get(), inputVector.data()); + CopyDataToITensorHandle(outputStateInHandle.get(), outputStateInVector.data()); + CopyDataToITensorHandle(cellStateInHandle.get(), cellStateInVector.data()); + + workload->Execute(); + + CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get()); + + return LayerTestResult(actualOutput, + expectedOutput, + outputHandle->GetShape(), + outputTensorInfo.GetShape()); +} + +LayerTestResult UnidirectionalSequenceLstmLayerInt8NoCifgWithPeepholeWithProjectionWithLayerNormTest( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + unsigned int batchSize = 3; + unsigned int timeSize = 2; + unsigned int outputSize = 4; + unsigned int inputSize = 3; + unsigned numUnits = 5; + + armnn::TensorInfo inputTensorInfo({batchSize, timeSize, inputSize}, armnn::DataType::Float32); + armnn::TensorInfo cellStateInTensorInfo({batchSize , numUnits}, armnn::DataType::Float32); + armnn::TensorInfo outputStateInTensorInfo({batchSize , outputSize}, armnn::DataType::Float32); + armnn::TensorInfo outputTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32); + + const std::vector inputVector = { 1., 8., 3., 4., 5., 4., + 3., 2., 1., 2., 3., 4., + 5., 4., 3., 2., 1., 2. }; + + std::vector cellStateInVector(batchSize * numUnits, 0.f); + std::vector outputStateInVector(batchSize * outputSize, 0.f); + + std::vector actualOutput(outputTensorInfo.GetNumElements()); + + const std::vector expectedOutput = { 0.0471276f, 0.0168155f, 0.0789885f, 0.16550f, + 0.0643133f, -0.0400722f, 0.100593f, 0.197722f, + 0.0465562f, -0.0600682f, 0.0622087f, 0.115053f, + 0.056287f, -0.0566218f, 0.0856832f, 0.148484f, + 0.0457859f, -0.0588112f, 0.0623636f, 0.114333f, + 0.0509271f, -0.0754262f, 0.058600f, 0.0801288f }; + + std::unique_ptr inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo); + std::unique_ptr cellStateInHandle = + tensorHandleFactory.CreateTensorHandle(cellStateInTensorInfo); + std::unique_ptr outputStateInHandle = + tensorHandleFactory.CreateTensorHandle(outputStateInTensorInfo); + + std::unique_ptr outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo); + + armnn::UnidirectionalSequenceLstmQueueDescriptor data; + armnn::WorkloadInfo info; + + AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); + AddInputToWorkload(data, info, outputStateInTensorInfo, outputStateInHandle.get()); + AddInputToWorkload(data, info, cellStateInTensorInfo, cellStateInHandle.get()); + + AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); + + armnn::TensorInfo tensorInfoOut({outputSize}, armnn::DataType::Float32); + armnn::TensorInfo tensorInfoNumFp({numUnits}, armnn::DataType::Float32); + armnn::TensorInfo tensorInfoNum({numUnits}, armnn::DataType::QAsymmS8, 0.1f, 0); + armnn::TensorInfo tensorInfoNumInput({numUnits, inputSize}, armnn::DataType::QAsymmS8, 0.1f, 0); + armnn::TensorInfo tensorInfoNumOutput({numUnits, outputSize}, armnn::DataType::QAsymmS8, 0.1f, 0); + armnn::TensorInfo tensorInfoOutNum({outputSize, numUnits}, armnn::DataType::QAsymmS8, 0.1f, 0); + + std::vector inputToInputWeights = { -4, -1, -1, -2, 3, -2, 2, 4, 1, -4, -2, 3, 2, 2, -4 }; + std::vector inputToForgetWeights = { 2, 1, 4, -4, 3, -1, -3, -2, -3, 1, -4, -1, -3, -2, -4 }; + std::vector inputToCellWeights = { -2, 1, -2, 4, -3, -2, -4, 3, -2, -2, -6, 3, 2, 5, -4 }; + std::vector inputToOutputWeights = { 2, 5, -4, 5, 2, -3, 5, 7, 3, -5, 1, -4, -4, -1, -1 }; + + std::vector inputGateBias = { 0.03f, 0.15f, 0.22f, 0.38f, 0.05f }; + std::vector forgetGateBias = { 0.1f, -0.3f, -0.2f, 0.1f, 0.4f }; + std::vector cellBias = { -0.05f, 0.72f, 0.25f, 0.08f, 0.1f }; + std::vector outputGateBias = { 0.05f, -0.01f, 0.2f, 0.1f, -0.2f }; + + std::vector recurrentToInputWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, + 5, -1, 1, 3, -1, -1, -1, 4, 2, 3 }; + + std::vector recurrentToForgetWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, + 5, -1, 1, 3, -2, -1, -1, 2, 2, 1 }; + + std::vector recurrentToCellWeights = { -2, -3, -1, -3, -4, 2, 1, -1, 2, 2, + 1, 2, 3, -2, 3, -3, -1, -5, 1, 3 }; + + std::vector recurrentToOutputWeights = { -3, 3, -1, -2, -2, -2, -1, -5, 1, 3, + -4, -1, -1, -1, 2, -1, 5, 1, -3, -4 }; + + std::vector cellToInputWeights = { 5, 3, 8, -5, 2 }; + std::vector cellToForgetWeights = { -2, -7, 5, -3, 4 }; + std::vector cellToOutputWeights = { 9, -10 , -5, 5, 1 }; + + std::vector projectionWeights = { -1, 2, 1, -2, 1, 5, 3, 8, 7, 2, + -4, 2, 5, -4, 3, -2, 3, 8, -7, 2 }; + + std::vector projectionBiasVector(outputSize, 0.f); //{outputSize} + + std::vector inputLayerNormWeights = { 0.1f, 0.2f, -0.3f, -0.1f, 0.5f }; + std::vector forgetLayerNormWeights = { -0.1f, 0.2f, 0.3f, 0.5f, 0.2f }; + std::vector cellLayerNormWeights = { 0.5f, 0.2f, 0.3f, 0.4f, -0.5f }; + std::vector outputLayerNormWeights = { 0.6f, -0.2f, -0.2f, 0.5f, 0.1f }; + + armnn::ScopedTensorHandle inputToInputWeightsTensor(tensorInfoNumInput); + armnn::ScopedTensorHandle inputToForgetWeightsTensor(tensorInfoNumInput); + armnn::ScopedTensorHandle inputToCellWeightsTensor(tensorInfoNumInput); + armnn::ScopedTensorHandle inputToOutputWeightsTensor(tensorInfoNumInput); + armnn::ScopedTensorHandle recurrentToForgetWeightsTensor(tensorInfoNumOutput); + armnn::ScopedTensorHandle recurrentToInputWeightsTensor(tensorInfoNumOutput); + armnn::ScopedTensorHandle recurrentToCellWeightsTensor(tensorInfoNumOutput); + armnn::ScopedTensorHandle recurrentToOutputWeightsTensor(tensorInfoNumOutput); + armnn::ScopedTensorHandle cellToInputWeightsTensor(tensorInfoNum); + armnn::ScopedTensorHandle inputGateBiasTensor(tensorInfoNumFp); + armnn::ScopedTensorHandle forgetGateBiasTensor(tensorInfoNumFp); + armnn::ScopedTensorHandle cellBiasTensor(tensorInfoNumFp); + armnn::ScopedTensorHandle outputGateBiasTensor(tensorInfoNumFp); + armnn::ScopedTensorHandle cellToForgetWeightsTensor(tensorInfoNum); + armnn::ScopedTensorHandle cellToOutputWeightsTensor(tensorInfoNum); + armnn::ScopedTensorHandle projectionWeightsTensor(tensorInfoOutNum); + armnn::ScopedTensorHandle projectionBiasTensor(tensorInfoOut); + + armnn::ScopedTensorHandle inputLayerNormWeightsTensor(tensorInfoNumFp); + armnn::ScopedTensorHandle forgetLayerNormWeightsTensor(tensorInfoNumFp); + armnn::ScopedTensorHandle cellLayerNormWeightsTensor(tensorInfoNumFp); + armnn::ScopedTensorHandle outputLayerNormWeightsTensor(tensorInfoNumFp); + + AllocateAndCopyDataToITensorHandle(&inputToInputWeightsTensor, inputToInputWeights.data()); + AllocateAndCopyDataToITensorHandle(&inputToForgetWeightsTensor, inputToForgetWeights.data()); + AllocateAndCopyDataToITensorHandle(&inputToCellWeightsTensor, inputToCellWeights.data()); + AllocateAndCopyDataToITensorHandle(&inputToOutputWeightsTensor, inputToOutputWeights.data()); + AllocateAndCopyDataToITensorHandle(&recurrentToInputWeightsTensor, recurrentToInputWeights.data()); + AllocateAndCopyDataToITensorHandle(&recurrentToForgetWeightsTensor, recurrentToForgetWeights.data()); + AllocateAndCopyDataToITensorHandle(&recurrentToCellWeightsTensor, recurrentToCellWeights.data()); + AllocateAndCopyDataToITensorHandle(&recurrentToOutputWeightsTensor, recurrentToOutputWeights.data()); + AllocateAndCopyDataToITensorHandle(&cellToInputWeightsTensor, cellToInputWeights.data()); + AllocateAndCopyDataToITensorHandle(&inputGateBiasTensor, inputGateBias.data()); + AllocateAndCopyDataToITensorHandle(&forgetGateBiasTensor, forgetGateBias.data()); + AllocateAndCopyDataToITensorHandle(&cellBiasTensor, cellBias.data()); + AllocateAndCopyDataToITensorHandle(&outputGateBiasTensor, outputGateBias.data()); + AllocateAndCopyDataToITensorHandle(&cellToForgetWeightsTensor, cellToForgetWeights.data()); + AllocateAndCopyDataToITensorHandle(&cellToOutputWeightsTensor, cellToOutputWeights.data()); + AllocateAndCopyDataToITensorHandle(&projectionWeightsTensor, projectionWeights.data()); + AllocateAndCopyDataToITensorHandle(&projectionBiasTensor, projectionBiasVector.data()); + + AllocateAndCopyDataToITensorHandle(&inputLayerNormWeightsTensor, inputLayerNormWeights.data()); + AllocateAndCopyDataToITensorHandle(&forgetLayerNormWeightsTensor, forgetLayerNormWeights.data()); + AllocateAndCopyDataToITensorHandle(&cellLayerNormWeightsTensor, cellLayerNormWeights.data()); + AllocateAndCopyDataToITensorHandle(&outputLayerNormWeightsTensor, outputLayerNormWeights.data()); + + data.m_InputToInputWeights = &inputToInputWeightsTensor; + data.m_InputToForgetWeights = &inputToForgetWeightsTensor; + data.m_InputToCellWeights = &inputToCellWeightsTensor; + data.m_InputToOutputWeights = &inputToOutputWeightsTensor; + data.m_RecurrentToInputWeights = &recurrentToInputWeightsTensor; + data.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor; + data.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor; + data.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor; + data.m_CellToInputWeights = &cellToInputWeightsTensor; + data.m_InputGateBias = &inputGateBiasTensor; + data.m_ForgetGateBias = &forgetGateBiasTensor; + data.m_CellBias = &cellBiasTensor; + data.m_OutputGateBias = &outputGateBiasTensor; + data.m_CellToForgetWeights = &cellToForgetWeightsTensor; + data.m_CellToOutputWeights = &cellToOutputWeightsTensor; + data.m_ProjectionWeights = &projectionWeightsTensor; + data.m_ProjectionBias = &projectionBiasTensor; + + data.m_InputLayerNormWeights = &inputLayerNormWeightsTensor; + data.m_ForgetLayerNormWeights = &forgetLayerNormWeightsTensor; + data.m_CellLayerNormWeights = &cellLayerNormWeightsTensor; + data.m_OutputLayerNormWeights = &outputLayerNormWeightsTensor; + + // Flags to set test configuration + data.m_Parameters.m_ActivationFunc = 4; + data.m_Parameters.m_CifgEnabled = false; + data.m_Parameters.m_PeepholeEnabled = true; + data.m_Parameters.m_ProjectionEnabled = true; + data.m_Parameters.m_LayerNormEnabled = true; + data.m_Parameters.m_TimeMajor = false; + data.m_Parameters.m_ClippingThresCell = 10.0f; + + std::unique_ptr workload = workloadFactory.CreateUnidirectionalSequenceLstm(data, info); + inputHandle->Allocate(); + outputStateInHandle->Allocate(); + cellStateInHandle->Allocate(); + outputHandle->Allocate(); + + CopyDataToITensorHandle(inputHandle.get(), inputVector.data()); + CopyDataToITensorHandle(outputStateInHandle.get(), outputStateInVector.data()); + CopyDataToITensorHandle(cellStateInHandle.get(), cellStateInVector.data()); + + workload->Execute(); + + CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get()); + + return LayerTestResult(actualOutput, + expectedOutput, + outputHandle->GetShape(), + outputTensorInfo.GetShape()); +} + +LayerTestResult UnidirectionalSequenceLstmInt8WithCifgWithPeepholeNoProjectionTest( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory) +{ + IgnoreUnused(memoryManager); + unsigned int batchSize = 3; + unsigned int timeSize = 2; + unsigned int inputSize = 3; + unsigned int outputSize = 4; + unsigned numUnits = outputSize; + + armnn::TensorInfo inputTensorInfo({batchSize, timeSize, inputSize}, armnn::DataType::Float32); + armnn::TensorInfo cellStateInTensorInfo({batchSize, numUnits}, armnn::DataType::Float32); + armnn::TensorInfo outputStateInTensorInfo({batchSize, outputSize}, armnn::DataType::Float32); + + armnn::TensorInfo outputTensorInfo({batchSize, timeSize, outputSize}, armnn::DataType::Float32); + + const std::vector inputVector = { 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.4f, + 0.3f, 0.2f, 0.1f, 0.2f, 0.3f, 0.4f, + 0.5f, 0.4f, 0.3f, 0.2f, 0.1f, 0.2f }; + + std::vector cellStateInVector(batchSize * numUnits, 0.f); + std::vector outputStateInVector(batchSize * outputSize, 0.f); + + std::vector actualOutput(outputTensorInfo.GetNumElements()); + + const std::vector outputVector = { -0.0072104f, -0.00991171f, -0.00650478f, -0.00713055f, + -0.0191782f, -0.0161269f, -0.0233683f, -0.054299f, + -0.00783725f, 0.00635271f, -0.0126718f, -0.022613f, + -0.0161351f, -0.00775868f, -0.021054f, -0.0339778f, + -0.0146392f, 0.00330261f, -0.0258733f, -0.0407797f, + -0.0174297f, 0.0050105f, -0.0266275f, -0.0362564f }; + + std::unique_ptr inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo); + std::unique_ptr cellStateInHandle = + tensorHandleFactory.CreateTensorHandle(cellStateInTensorInfo); + std::unique_ptr outputStateInHandle = + tensorHandleFactory.CreateTensorHandle(outputStateInTensorInfo); + + std::unique_ptr outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo); + + armnn::UnidirectionalSequenceLstmQueueDescriptor data; + armnn::WorkloadInfo info; + + AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); + AddInputToWorkload(data, info, outputStateInTensorInfo, outputStateInHandle.get()); + AddInputToWorkload(data, info, cellStateInTensorInfo, cellStateInHandle.get()); + + AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); + + armnn::TensorInfo tensorInfoNumFp({numUnits}, armnn::DataType::Float32); + armnn::TensorInfo tensorInfoNum({numUnits}, armnn::DataType::QAsymmS8, 0.1f, 0); + armnn::TensorInfo tensorInfoNumInput({numUnits, inputSize}, armnn::DataType::QAsymmS8, 0.1f, 0); + armnn::TensorInfo tensorInfoNumOutput({numUnits, outputSize}, armnn::DataType::QAsymmS8, 0.1f, 0); + + std::vector inputToForgetWeights = { 2, 1, 4, -4, 3, -1, -3, -2, -3, 1, -4, -1 }; + std::vector inputToCellWeights = { -2, 1, -2, 4, -3, -2, -4, 3, -2, -2, -6, 3 }; + std::vector inputToOutputWeights = { 2, 5, -4, 5, 2, -3, 5, 7, 3, -5, 1, -4 }; + + std::vector recurrentToForgetWeights = { -1, 1, -1, 1, -3, -4, -1, 4, 2, 3, 5, -1, 1, 3, -2, -1 }; + std::vector recurrentToCellWeights = { -2, -3, -1, -3, -4, 2, 1, -1, 2, 2, 1, 2, 3, -2, 3, -3 }; + std::vector recurrentToOutputWeights = { -3, 3, -1, -2, -2, -2, -1, -5, 1, 3, -4, -1, -1, -1, 2, -1 }; + + std::vector cellToForgetWeights = { 47, -52, -24, 31 }; + std::vector cellToOutputWeights = { -17, 82, 85, -77 }; + + std::vector forgetGateBias = { 1., 1., 1., 1. }; + std::vector cellBias = { 0., 0., 0., 0. }; + std::vector outputGateBias = { 0., 0., 0., 0. }; + + armnn::ScopedTensorHandle inputToForgetWeightsTensor(tensorInfoNumInput); + armnn::ScopedTensorHandle inputToCellWeightsTensor(tensorInfoNumInput); + armnn::ScopedTensorHandle inputToOutputWeightsTensor(tensorInfoNumInput); + armnn::ScopedTensorHandle recurrentToForgetWeightsTensor(tensorInfoNumOutput); + armnn::ScopedTensorHandle recurrentToCellWeightsTensor(tensorInfoNumOutput); + armnn::ScopedTensorHandle recurrentToOutputWeightsTensor(tensorInfoNumOutput); + armnn::ScopedTensorHandle cellToForgetWeightsTensor(tensorInfoNum); + armnn::ScopedTensorHandle cellToOutputWeightsTensor(tensorInfoNum); + armnn::ScopedTensorHandle forgetGateBiasTensor(tensorInfoNumFp); + armnn::ScopedTensorHandle cellBiasTensor(tensorInfoNumFp); + armnn::ScopedTensorHandle outputGateBiasTensor(tensorInfoNumFp); + + AllocateAndCopyDataToITensorHandle(&inputToForgetWeightsTensor, inputToForgetWeights.data()); + AllocateAndCopyDataToITensorHandle(&inputToCellWeightsTensor, inputToCellWeights.data()); + AllocateAndCopyDataToITensorHandle(&inputToOutputWeightsTensor, inputToOutputWeights.data()); + AllocateAndCopyDataToITensorHandle(&recurrentToForgetWeightsTensor, recurrentToForgetWeights.data()); + AllocateAndCopyDataToITensorHandle(&recurrentToCellWeightsTensor, recurrentToCellWeights.data()); + AllocateAndCopyDataToITensorHandle(&recurrentToOutputWeightsTensor, recurrentToOutputWeights.data()); + AllocateAndCopyDataToITensorHandle(&cellToForgetWeightsTensor, cellToForgetWeights.data()); + AllocateAndCopyDataToITensorHandle(&cellToOutputWeightsTensor, cellToOutputWeights.data()); + AllocateAndCopyDataToITensorHandle(&forgetGateBiasTensor, forgetGateBias.data()); + AllocateAndCopyDataToITensorHandle(&cellBiasTensor, cellBias.data()); + AllocateAndCopyDataToITensorHandle(&outputGateBiasTensor, outputGateBias.data()); + + data.m_InputToForgetWeights = &inputToForgetWeightsTensor; + data.m_InputToCellWeights = &inputToCellWeightsTensor; + data.m_InputToOutputWeights = &inputToOutputWeightsTensor; + data.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor; + data.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor; + data.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor; + data.m_CellToForgetWeights = &cellToForgetWeightsTensor; + data.m_CellToOutputWeights = &cellToOutputWeightsTensor; + data.m_ForgetGateBias = &forgetGateBiasTensor; + data.m_CellBias = &cellBiasTensor; + data.m_OutputGateBias = &outputGateBiasTensor; + + // Flags to set test configuration + data.m_Parameters.m_ClippingThresCell = 10; + data.m_Parameters.m_ClippingThresProj = 0; + data.m_Parameters.m_ActivationFunc = 4; + data.m_Parameters.m_CifgEnabled = true; + data.m_Parameters.m_PeepholeEnabled = true; + data.m_Parameters.m_ProjectionEnabled = false; + data.m_Parameters.m_TimeMajor = false; + + std::unique_ptr workload = workloadFactory.CreateUnidirectionalSequenceLstm(data, info); + inputHandle->Allocate(); + outputStateInHandle->Allocate(); + cellStateInHandle->Allocate(); + + outputHandle->Allocate(); + + CopyDataToITensorHandle(inputHandle.get(), inputVector.data()); + CopyDataToITensorHandle(outputStateInHandle.get(), outputStateInVector.data()); + CopyDataToITensorHandle(cellStateInHandle.get(), cellStateInVector.data()); + + workload->Execute(); + + CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get()); + + return LayerTestResult(actualOutput, + outputVector, + outputHandle->GetShape(), + outputTensorInfo.GetShape()); +} \ No newline at end of file diff --git a/src/backends/backendsCommon/test/layerTests/UnidirectionalSequenceLstmTestImpl.hpp b/src/backends/backendsCommon/test/layerTests/UnidirectionalSequenceLstmTestImpl.hpp index 7b14065728..20ac3135a4 100644 --- a/src/backends/backendsCommon/test/layerTests/UnidirectionalSequenceLstmTestImpl.hpp +++ b/src/backends/backendsCommon/test/layerTests/UnidirectionalSequenceLstmTestImpl.hpp @@ -31,6 +31,31 @@ LayerTestResult UnidirectionalSequenceLstmLayerNoCifgWithPeepholeWithP const armnn::ITensorHandleFactory& tensorHandleFactory); LayerTestResult UnidirectionalSequenceLstmWithCifgWithPeepholeNoProjectionTest( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult UnidirectionalSequenceLstmLayerInt8Test( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult UnidirectionalSequenceLstmLayerInt8TimeMajorTest( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult UnidirectionalSequenceLstmLayerInt8NoCifgWithPeepholeWithProjectionTest( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult UnidirectionalSequenceLstmLayerInt8NoCifgWithPeepholeWithProjectionWithLayerNormTest( + armnn::IWorkloadFactory& workloadFactory, + const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, + const armnn::ITensorHandleFactory& tensorHandleFactory); + +LayerTestResult UnidirectionalSequenceLstmInt8WithCifgWithPeepholeNoProjectionTest( armnn::IWorkloadFactory& workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, const armnn::ITensorHandleFactory& tensorHandleFactory); \ No newline at end of file diff --git a/src/backends/reference/RefLayerSupport.cpp b/src/backends/reference/RefLayerSupport.cpp index 2603371927..5eba3e5919 100644 --- a/src/backends/reference/RefLayerSupport.cpp +++ b/src/backends/reference/RefLayerSupport.cpp @@ -2317,9 +2317,10 @@ bool RefLayerSupport::IsUnidirectionalSequenceLstmSupported( DataType::Float32 }; - std::array supportedWeightTypes = + std::array supportedWeightTypes = { - DataType::Float32 + DataType::Float32, + DataType::QAsymmS8 }; // check inputs and outputs diff --git a/src/backends/reference/test/RefLayerTests.cpp b/src/backends/reference/test/RefLayerTests.cpp index 0cf36f2c6e..e906b2962c 100644 --- a/src/backends/reference/test/RefLayerTests.cpp +++ b/src/backends/reference/test/RefLayerTests.cpp @@ -2341,5 +2341,15 @@ ARMNN_AUTO_TEST_CASE_WITH_THF(UnidirectionalSequenceLstmLayerNoCifgWithPeepholeW UnidirectionalSequenceLstmLayerNoCifgWithPeepholeWithProjectionWithLayerNormTest) ARMNN_AUTO_TEST_CASE_WITH_THF(UnidirectionalSequenceLstmWithCifgWithPeepholeNoProjection, UnidirectionalSequenceLstmWithCifgWithPeepholeNoProjectionTest) +ARMNN_AUTO_TEST_CASE_WITH_THF(UnidirectionalSequenceLstmLayerInt8, + UnidirectionalSequenceLstmLayerInt8Test) +ARMNN_AUTO_TEST_CASE_WITH_THF(UnidirectionalSequenceLstmLayerInt8TimeMajor, + UnidirectionalSequenceLstmLayerInt8TimeMajorTest) +ARMNN_AUTO_TEST_CASE_WITH_THF(UnidirectionalSequenceLstmLayerInt8NoCifgWithPeepholeWithProjection, + UnidirectionalSequenceLstmLayerInt8NoCifgWithPeepholeWithProjectionTest) +ARMNN_AUTO_TEST_CASE_WITH_THF(UnidirectionalSequenceLstmLayerInt8NoCifgWithPeepholeWithProjectionWithLayerNorm, + UnidirectionalSequenceLstmLayerInt8NoCifgWithPeepholeWithProjectionWithLayerNormTest) +ARMNN_AUTO_TEST_CASE_WITH_THF(UnidirectionalSequenceLstmInt8WithCifgWithPeepholeNoProjection, + UnidirectionalSequenceLstmInt8WithCifgWithPeepholeNoProjectionTest) } \ No newline at end of file -- cgit v1.2.1