IVGCVSW-4451 Add QLstm NEON workload
authorJames Conroy <james.conroy@arm.com>
Tue, 12 May 2020 17:08:52 +0000 (18:08 +0100)
committerJan Eilers <jan.eilers@arm.com>
Wed, 20 May 2020 13:16:18 +0000 (14:16 +0100)
* Adds QLstm workload.
* Adds CreateWorkload and Layer tests.

Signed-off-by: James Conroy <james.conroy@arm.com>
Change-Id: I585eb2691395ee4ccd45b5a853660f90fc5cc821

12 files changed:
src/backends/neon/NeonLayerSupport.cpp
src/backends/neon/NeonLayerSupport.hpp
src/backends/neon/NeonWorkloadFactory.cpp
src/backends/neon/NeonWorkloadFactory.hpp
src/backends/neon/backend.mk
src/backends/neon/test/NeonCreateWorkloadTests.cpp
src/backends/neon/test/NeonLayerTests.cpp
src/backends/neon/workloads/CMakeLists.txt
src/backends/neon/workloads/NeonQLstmWorkload.cpp [new file with mode: 0644]
src/backends/neon/workloads/NeonQLstmWorkload.hpp [new file with mode: 0644]
src/backends/neon/workloads/NeonWorkloadUtils.hpp
src/backends/neon/workloads/NeonWorkloads.hpp

index b095ed5629f81cd04956578523e6f328b57f6df9..53d0f0b633372233fb0f77d5bdc73ec08e8efb36 100644 (file)
@@ -48,6 +48,7 @@
 #include "workloads/NeonPermuteWorkload.hpp"
 #include "workloads/NeonPooling2dWorkload.hpp"
 #include "workloads/NeonPreluWorkload.hpp"
+#include "workloads/NeonQLstmWorkload.hpp"
 #include "workloads/NeonQuantizeWorkload.hpp"
 #include "workloads/NeonQuantizedLstmWorkload.hpp"
 #include "workloads/NeonReshapeWorkload.hpp"
@@ -615,6 +616,41 @@ bool NeonLayerSupport::IsPreluSupported(const armnn::TensorInfo &input,
     FORWARD_WORKLOAD_VALIDATE_FUNC(NeonPreluWorkloadValidate, reasonIfUnsupported, input, alpha, output);
 }
 
+bool NeonLayerSupport::IsQLstmSupported(const TensorInfo& input,
+                                        const TensorInfo& previousOutputIn,
+                                        const TensorInfo& previousCellStateIn,
+                                        const TensorInfo& outputStateOut,
+                                        const TensorInfo& cellStateOut,
+                                        const TensorInfo& output,
+                                        const QLstmDescriptor& descriptor,
+                                        const LstmInputParamsInfo& paramsInfo,
+                                        Optional<std::string&> reasonIfUnsupported) const
+{
+    // Check required here in order to pass IsLayerSupported for datatypes tests
+    if (input.GetDataType()               == armnn::DataType::QAsymmS8 &&
+        previousOutputIn.GetDataType()    == armnn::DataType::QAsymmS8 &&
+        previousCellStateIn.GetDataType() == armnn::DataType::QSymmS16 &&
+        outputStateOut.GetDataType()      == armnn::DataType::QAsymmS8 &&
+        cellStateOut.GetDataType()        == armnn::DataType::QSymmS16 &&
+        output.GetDataType()              == armnn::DataType::QAsymmS8)
+    {
+        FORWARD_WORKLOAD_VALIDATE_FUNC(NeonQLstmWorkloadValidate,
+                                       reasonIfUnsupported,
+                                       input,
+                                       previousCellStateIn,
+                                       previousOutputIn,
+                                       cellStateOut,
+                                       outputStateOut,
+                                       output,
+                                       descriptor,
+                                       paramsInfo);
+    }
+    else
+    {
+        return false;
+    }
+}
+
 bool NeonLayerSupport::IsQuantizeSupported(const TensorInfo& input,
                                            const TensorInfo& output,
                                            Optional<std::string&> reasonIfUnsupported) const
index fda0bc30d3455739fbb5a4cebfd69c6f6a02c34f..adb1891de8d9aa3743d22a869cd937042d5ea455 100644 (file)
@@ -212,6 +212,16 @@ public:
                           const TensorInfo& output,
                           Optional<std::string&> reasonIfUnsupported = EmptyOptional()) const override;
 
+    bool IsQLstmSupported(const TensorInfo& input,
+                          const TensorInfo& previousOutputIn,
+                          const TensorInfo& previousCellStateIn,
+                          const TensorInfo& outputStateOut,
+                          const TensorInfo& cellStateOut,
+                          const TensorInfo& output,
+                          const QLstmDescriptor& descriptor,
+                          const LstmInputParamsInfo& paramsInfo,
+                          Optional<std::string&> reasonIfUnsupported = EmptyOptional()) const override;
+
     bool IsQuantizeSupported(const TensorInfo& input,
                              const TensorInfo& output,
                              Optional<std::string&> reasonIfUnsupported = EmptyOptional()) const override;
index 4a3533186a6018660a11da5730e1d3fb67f88c22..ee0e70304ba058c54e5a83109a980cd32912f4f1 100644 (file)
@@ -415,6 +415,12 @@ std::unique_ptr<armnn::IWorkload> NeonWorkloadFactory::CreatePrelu(const armnn::
     return std::make_unique<NeonPreluWorkload>(descriptor, info);
 }
 
+std::unique_ptr<IWorkload> NeonWorkloadFactory::CreateQLstm(const QLstmQueueDescriptor& descriptor,
+                                                            const WorkloadInfo& info) const
+{
+    return std::make_unique<NeonQLstmWorkload>(descriptor, info);
+}
+
 std::unique_ptr<armnn::IWorkload> NeonWorkloadFactory::CreateQuantize(const QuantizeQueueDescriptor& descriptor,
                                                                       const WorkloadInfo& info) const
 {
index d6968fa9dd03d29ba0700cd8ba87ee0811bc27c7..0e9428ad240fdfa4ff50658bd024779e07b7f01a 100644 (file)
@@ -174,6 +174,9 @@ public:
     std::unique_ptr<IWorkload> CreatePrelu(const PreluQueueDescriptor& descriptor,
                                            const WorkloadInfo& info) const override;
 
+    std::unique_ptr<IWorkload> CreateQLstm(const QLstmQueueDescriptor& descriptor,
+                                           const WorkloadInfo& info) const override;
+
     std::unique_ptr<IWorkload> CreateQuantize(const QuantizeQueueDescriptor& descriptor,
                                               const WorkloadInfo& info) const override;
 
index 2bba74a79dc8a2935d71bc804583ad0b78088c5f..225687f1581737427775e5330d494fc077758d89 100644 (file)
@@ -56,6 +56,7 @@ BACKEND_SOURCES := \
         workloads/NeonPermuteWorkload.cpp \
         workloads/NeonPooling2dWorkload.cpp \
         workloads/NeonPreluWorkload.cpp \
+        workloads/NeonQLstmWorkload.cpp \
         workloads/NeonQuantizedLstmWorkload.cpp \
         workloads/NeonQuantizeWorkload.cpp \
         workloads/NeonReshapeWorkload.cpp \
index 0af9bf3e0dc8cd2e6efde9692c6e345dbb9ba200..73491c781066d52d5c369359d5634d8080c88271 100644 (file)
@@ -967,4 +967,31 @@ BOOST_AUTO_TEST_CASE(CreateQuantizedLstmWorkload)
     NeonCreateQuantizedLstmWorkloadTest<NeonQuantizedLstmWorkload>();
 }
 
+template <typename QLstmWorkloadType>
+static void NeonCreateQLstmWorkloadTest()
+{
+    Graph graph;
+    NeonWorkloadFactory factory = NeonWorkloadFactoryHelper::GetFactory(NeonWorkloadFactoryHelper::GetMemoryManager());
+
+    auto workload = CreateQLstmWorkloadTest<QLstmWorkloadType>(factory, graph);
+    QLstmQueueDescriptor queueDescriptor = workload->GetData();
+
+    IAclTensorHandle* inputHandle = PolymorphicDowncast<IAclTensorHandle*>(queueDescriptor.m_Inputs[0]);
+    BOOST_TEST((inputHandle->GetShape() == TensorShape({2, 4})));
+    BOOST_TEST((inputHandle->GetDataType() == arm_compute::DataType::QASYMM8_SIGNED));
+
+    IAclTensorHandle* cellStateOutHandle = PolymorphicDowncast<IAclTensorHandle*>(queueDescriptor.m_Outputs[1]);
+    BOOST_TEST((cellStateOutHandle->GetShape() == TensorShape({2, 4})));
+    BOOST_TEST((cellStateOutHandle->GetDataType() == arm_compute::DataType::QSYMM16));
+
+    IAclTensorHandle* outputHandle = PolymorphicDowncast<IAclTensorHandle*>(queueDescriptor.m_Outputs[2]);
+    BOOST_TEST((outputHandle->GetShape() == TensorShape({2, 4})));
+    BOOST_TEST((outputHandle->GetDataType() == arm_compute::DataType::QASYMM8_SIGNED));
+}
+
+BOOST_AUTO_TEST_CASE(CreateQLstmWorkloadTest)
+{
+    NeonCreateQLstmWorkloadTest<NeonQLstmWorkload>();
+}
+
 BOOST_AUTO_TEST_SUITE_END()
index f992bd61a187bf6e63401747630bca450a95d7fe..e8f0f78babdf8a27c0cc8495a63536b65e56229f 100644 (file)
@@ -773,6 +773,10 @@ ARMNN_AUTO_TEST_CASE(LstmLayerFloat32NoCifgWithPeepholeWithProjection,
 ARMNN_AUTO_TEST_CASE(LstmLayerFloat32NoCifgWithPeepholeWithProjectionWithLayerNorm,
                      LstmLayerFloat32NoCifgWithPeepholeWithProjectionWithLayerNormTest)
 
+// QLstm
+ARMNN_AUTO_TEST_CASE(QLstm, QLstmTest)
+
+// QuantizedLstm
 ARMNN_AUTO_TEST_CASE(QuantizedLstm, QuantizedLstmTest)
 
 // Mean
index 939c621475f1edae9a909dad81c104079aca9a19..f3b08ecb5dcbfa680a1bc0b48725cfa4075bb3f2 100644 (file)
@@ -74,6 +74,8 @@ list(APPEND armnnNeonBackendWorkloads_sources
     NeonPooling2dWorkload.hpp
     NeonPreluWorkload.cpp
     NeonPreluWorkload.hpp
+    NeonQLstmWorkload.cpp
+    NeonQLstmWorkload.hpp
     NeonQuantizedLstmWorkload.cpp
     NeonQuantizedLstmWorkload.hpp
     NeonQuantizeWorkload.cpp
diff --git a/src/backends/neon/workloads/NeonQLstmWorkload.cpp b/src/backends/neon/workloads/NeonQLstmWorkload.cpp
new file mode 100644 (file)
index 0000000..daa4fba
--- /dev/null
@@ -0,0 +1,421 @@
+//
+// Copyright © 2020 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "NeonQLstmWorkload.hpp"
+#include "NeonWorkloadUtils.hpp"
+
+#include "aclCommon/ArmComputeTensorUtils.hpp"
+
+#include "neon/NeonTensorHandle.hpp"
+
+namespace armnn
+{
+using namespace armcomputetensorutils;
+
+NeonQLstmWorkload::NeonQLstmWorkload(const QLstmQueueDescriptor& descriptor, const WorkloadInfo& info)
+        : BaseWorkload<QLstmQueueDescriptor>(descriptor, info)
+{
+    arm_compute::LSTMParams<arm_compute::ITensor> qLstmParams;
+
+    // Mandatory tensors
+    m_InputToForgetWeightsTensor = std::make_unique<arm_compute::Tensor>();
+    BuildArmComputeTensor(*m_InputToForgetWeightsTensor, m_Data.m_InputToForgetWeights->GetTensorInfo());
+
+    m_InputToCellWeightsTensor = std::make_unique<arm_compute::Tensor>();
+    BuildArmComputeTensor(*m_InputToCellWeightsTensor, m_Data.m_InputToCellWeights->GetTensorInfo());
+
+    m_InputToOutputWeightsTensor = std::make_unique<arm_compute::Tensor>();
+    BuildArmComputeTensor(*m_InputToOutputWeightsTensor, m_Data.m_InputToOutputWeights->GetTensorInfo());
+
+    m_RecurrentToForgetWeightsTensor = std::make_unique<arm_compute::Tensor>();
+    BuildArmComputeTensor(*m_RecurrentToForgetWeightsTensor, m_Data.m_RecurrentToForgetWeights->GetTensorInfo());
+
+    m_RecurrentToCellWeightsTensor = std::make_unique<arm_compute::Tensor>();
+    BuildArmComputeTensor(*m_RecurrentToCellWeightsTensor, m_Data.m_RecurrentToCellWeights->GetTensorInfo());
+
+    m_RecurrentToOutputWeightsTensor = std::make_unique<arm_compute::Tensor>();
+    BuildArmComputeTensor(*m_RecurrentToOutputWeightsTensor, m_Data.m_RecurrentToOutputWeights->GetTensorInfo());
+
+    m_ForgetGateBiasTensor = std::make_unique<arm_compute::Tensor>();
+    BuildArmComputeTensor(*m_ForgetGateBiasTensor, m_Data.m_ForgetGateBias->GetTensorInfo());
+
+    m_CellBiasTensor = std::make_unique<arm_compute::Tensor>();
+    BuildArmComputeTensor(*m_CellBiasTensor, m_Data.m_CellBias->GetTensorInfo());
+
+    m_OutputGateBiasTensor = std::make_unique<arm_compute::Tensor>();
+    BuildArmComputeTensor(*m_OutputGateBiasTensor, m_Data.m_OutputGateBias->GetTensorInfo());
+
+    // Create tensors for optional params if they are enabled
+    if (m_Data.m_Parameters.m_PeepholeEnabled)
+    {
+        m_CellToInputWeightsTensor = std::make_unique<arm_compute::Tensor>();
+
+        if (!m_Data.m_Parameters.m_CifgEnabled)
+        {
+            // In ACL this is categorised as a CIFG param and not a Peephole param
+            BuildArmComputeTensor(*m_CellToInputWeightsTensor, m_Data.m_CellToInputWeights->GetTensorInfo());
+        }
+
+        m_CellToForgetWeightsTensor = std::make_unique<arm_compute::Tensor>();
+        BuildArmComputeTensor(*m_CellToForgetWeightsTensor, m_Data.m_CellToForgetWeights->GetTensorInfo());
+
+        m_CellToOutputWeightsTensor = std::make_unique<arm_compute::Tensor>();
+        BuildArmComputeTensor(*m_CellToOutputWeightsTensor, m_Data.m_CellToOutputWeights->GetTensorInfo());
+
+        // Set Peephole params
+        qLstmParams.set_peephole_params(m_CellToForgetWeightsTensor.get(),
+                                        m_CellToOutputWeightsTensor.get());
+    }
+
+    if (m_Data.m_Parameters.m_ProjectionEnabled)
+    {
+        m_ProjectionWeightsTensor = std::make_unique<arm_compute::Tensor>();
+        BuildArmComputeTensor(*m_ProjectionWeightsTensor, m_Data.m_ProjectionWeights->GetTensorInfo());
+
+        m_ProjectionBiasTensor = std::make_unique<arm_compute::Tensor>();
+        if (m_Data.m_ProjectionBias != nullptr)
+        {
+            BuildArmComputeTensor(*m_ProjectionBiasTensor, m_Data.m_ProjectionBias->GetTensorInfo());
+        }
+
+        // Set projection params
+        qLstmParams.set_projection_params(
+                m_ProjectionWeightsTensor.get(),
+                m_Data.m_ProjectionBias != nullptr ? m_ProjectionBiasTensor.get() : nullptr);
+    }
+
+    if (m_Data.m_Parameters.m_LayerNormEnabled)
+    {
+        m_InputLayerNormWeightsTensor = std::make_unique<arm_compute::Tensor>();
+
+        if (!m_Data.m_Parameters.m_CifgEnabled)
+        {
+            BuildArmComputeTensor(*m_InputLayerNormWeightsTensor, m_Data.m_InputLayerNormWeights->GetTensorInfo());
+        }
+
+        m_ForgetLayerNormWeightsTensor = std::make_unique<arm_compute::Tensor>();
+        BuildArmComputeTensor(*m_ForgetLayerNormWeightsTensor, m_Data.m_ForgetLayerNormWeights->GetTensorInfo());
+
+        m_CellLayerNormWeightsTensor = std::make_unique<arm_compute::Tensor>();
+        BuildArmComputeTensor(*m_CellLayerNormWeightsTensor, m_Data.m_CellLayerNormWeights->GetTensorInfo());
+
+        m_OutputLayerNormWeightsTensor = std::make_unique<arm_compute::Tensor>();
+        BuildArmComputeTensor(*m_OutputLayerNormWeightsTensor, m_Data.m_OutputLayerNormWeights->GetTensorInfo());
+
+        // Set layer norm params
+        qLstmParams.set_layer_normalization_params(
+                m_Data.m_InputLayerNormWeights != nullptr ? m_InputLayerNormWeightsTensor.get() : nullptr,
+                m_ForgetLayerNormWeightsTensor.get(),
+                m_CellLayerNormWeightsTensor.get(),
+                m_OutputLayerNormWeightsTensor.get());
+    }
+
+    if (!m_Data.m_Parameters.m_CifgEnabled)
+    {
+        m_InputToInputWeightsTensor = std::make_unique<arm_compute::Tensor>();
+        BuildArmComputeTensor(*m_InputToInputWeightsTensor, m_Data.m_InputToInputWeights->GetTensorInfo());
+
+        m_RecurrentToInputWeightsTensor = std::make_unique<arm_compute::Tensor>();
+        BuildArmComputeTensor(*m_RecurrentToInputWeightsTensor, m_Data.m_RecurrentToInputWeights->GetTensorInfo());
+
+        m_InputGateBiasTensor = std::make_unique<arm_compute::Tensor>();
+        BuildArmComputeTensor(*m_InputGateBiasTensor, m_Data.m_InputGateBias->GetTensorInfo());
+
+        // Set CIFG params
+        qLstmParams.set_cifg_params(
+                m_InputToInputWeightsTensor.get(),
+                m_RecurrentToInputWeightsTensor.get(),
+                m_Data.m_CellToInputWeights != nullptr ? m_CellToInputWeightsTensor.get() : nullptr,
+                m_InputGateBiasTensor.get());
+    }
+
+    // Input/output tensors
+    const arm_compute::ITensor& input         = static_cast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
+    const arm_compute::ITensor& outputStateIn = static_cast<IAclTensorHandle*>(m_Data.m_Inputs[1])->GetTensor();
+    const arm_compute::ITensor& cellStateIn   = static_cast<IAclTensorHandle*>(m_Data.m_Inputs[2])->GetTensor();
+
+    arm_compute::ITensor& outputStateOut = static_cast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
+    arm_compute::ITensor& cellStateOut   = static_cast<IAclTensorHandle*>(m_Data.m_Outputs[1])->GetTensor();
+    arm_compute::ITensor& output         = static_cast<IAclTensorHandle*>(m_Data.m_Outputs[2])->GetTensor();
+
+
+    // Set scalar descriptor params
+    qLstmParams.set_cell_clip_params(m_Data.m_Parameters.m_CellClip);
+    qLstmParams.set_projection_clip_params(m_Data.m_Parameters.m_ProjectionClip);
+    qLstmParams.set_hidden_state_params(m_Data.m_Parameters.m_HiddenStateZeroPoint,
+                                        m_Data.m_Parameters.m_HiddenStateScale);
+    qLstmParams.set_matmul_scale_params(m_Data.m_Parameters.m_InputIntermediateScale,
+                                        m_Data.m_Parameters.m_ForgetIntermediateScale,
+                                        m_Data.m_Parameters.m_CellIntermediateScale,
+                                        m_Data.m_Parameters.m_OutputIntermediateScale);
+
+    // QLSTM NEON configure
+    m_QLstmLayer.configure(&input,
+                           m_InputToForgetWeightsTensor.get(),
+                           m_InputToCellWeightsTensor.get(),
+                           m_InputToOutputWeightsTensor.get(),
+                           m_RecurrentToForgetWeightsTensor.get(),
+                           m_RecurrentToCellWeightsTensor.get(),
+                           m_RecurrentToOutputWeightsTensor.get(),
+                           m_ForgetGateBiasTensor.get(),
+                           m_CellBiasTensor.get(),
+                           m_OutputGateBiasTensor.get(),
+                           &cellStateIn,
+                           &outputStateIn,
+                           &cellStateOut,
+                           &outputStateOut,
+                           &output,
+                           qLstmParams);
+
+    // Initialise ACL tensor data for mandatory params
+    InitializeArmComputeTensorData(*m_InputToForgetWeightsTensor, m_Data.m_InputToForgetWeights);
+    InitializeArmComputeTensorData(*m_InputToCellWeightsTensor,   m_Data.m_InputToCellWeights);
+    InitializeArmComputeTensorData(*m_InputToOutputWeightsTensor, m_Data.m_InputToOutputWeights);
+
+    InitializeArmComputeTensorData(*m_RecurrentToForgetWeightsTensor, m_Data.m_RecurrentToForgetWeights);
+    InitializeArmComputeTensorData(*m_RecurrentToCellWeightsTensor,   m_Data.m_RecurrentToCellWeights);
+    InitializeArmComputeTensorData(*m_RecurrentToOutputWeightsTensor, m_Data.m_RecurrentToOutputWeights);
+
+    InitializeArmComputeTensorData(*m_ForgetGateBiasTensor, m_Data.m_ForgetGateBias);
+    InitializeArmComputeTensorData(*m_CellBiasTensor,       m_Data.m_CellBias);
+    InitializeArmComputeTensorData(*m_OutputGateBiasTensor, m_Data.m_OutputGateBias);
+
+    // Initialise ACL tensor data for optional params
+    if (!m_Data.m_Parameters.m_CifgEnabled)
+    {
+        InitializeArmComputeTensorData(*m_InputToInputWeightsTensor,     m_Data.m_InputToInputWeights);
+        InitializeArmComputeTensorData(*m_RecurrentToInputWeightsTensor, m_Data.m_RecurrentToInputWeights);
+        InitializeArmComputeTensorData(*m_InputGateBiasTensor,           m_Data.m_InputGateBias);
+    }
+
+    if (m_Data.m_Parameters.m_ProjectionEnabled)
+    {
+        InitializeArmComputeTensorData(*m_ProjectionWeightsTensor, m_Data.m_ProjectionWeights);
+
+        if (m_Data.m_ProjectionBias != nullptr)
+        {
+            InitializeArmComputeTensorData(*m_ProjectionBiasTensor, m_Data.m_ProjectionBias);
+        }
+    }
+
+    if (m_Data.m_Parameters.m_PeepholeEnabled)
+    {
+        if (!m_Data.m_Parameters.m_CifgEnabled)
+        {
+            InitializeArmComputeTensorData(*m_CellToInputWeightsTensor, m_Data.m_CellToInputWeights);
+        }
+
+        InitializeArmComputeTensorData(*m_CellToForgetWeightsTensor, m_Data.m_CellToForgetWeights);
+        InitializeArmComputeTensorData(*m_CellToOutputWeightsTensor, m_Data.m_CellToOutputWeights);
+    }
+
+    if (m_Data.m_Parameters.m_LayerNormEnabled)
+    {
+        if (!m_Data.m_Parameters.m_CifgEnabled)
+        {
+            InitializeArmComputeTensorData(*m_InputLayerNormWeightsTensor, m_Data.m_InputLayerNormWeights);
+        }
+
+        InitializeArmComputeTensorData(*m_ForgetLayerNormWeightsTensor, m_Data.m_ForgetLayerNormWeights);
+        InitializeArmComputeTensorData(*m_CellLayerNormWeightsTensor,   m_Data.m_CellLayerNormWeights);
+        InitializeArmComputeTensorData(*m_OutputLayerNormWeightsTensor, m_Data.m_OutputLayerNormWeights);
+    }
+
+    // QLSTM NEON prepare
+    m_QLstmLayer.prepare();
+
+    FreeUnusedTensors();
+}
+
+void NeonQLstmWorkload::Execute() const
+{
+    m_QLstmLayer.run();
+}
+
+arm_compute::Status NeonQLstmWorkloadValidate(const TensorInfo& input,
+                                              const TensorInfo& cellStateIn,
+                                              const TensorInfo& outputStateIn,
+                                              const TensorInfo& cellStateOut,
+                                              const TensorInfo& outputStateOut,
+                                              const TensorInfo& output,
+                                              const QLstmDescriptor& descriptor,
+                                              const LstmInputParamsInfo& paramsInfo)
+{
+    arm_compute::LSTMParams<arm_compute::ITensorInfo> aclParamsInfo;
+
+    // Input/Output tensor info
+    const arm_compute::TensorInfo aclInputInfo         = BuildArmComputeTensorInfo(input);
+    const arm_compute::TensorInfo aclOutputStateInInfo = BuildArmComputeTensorInfo(outputStateIn);
+    const arm_compute::TensorInfo aclCellStateInInfo   = BuildArmComputeTensorInfo(cellStateIn);
+
+    const arm_compute::TensorInfo aclOutputStateOutInfo = BuildArmComputeTensorInfo(outputStateOut);
+    const arm_compute::TensorInfo aclCellStateOutInfo   = BuildArmComputeTensorInfo(cellStateOut);
+    const arm_compute::TensorInfo aclOutputInfo         =  BuildArmComputeTensorInfo(output);
+
+    // Mandatory tensor info
+    const arm_compute::TensorInfo aclInputToForgetWeightsInfo
+            = BuildArmComputeTensorInfo(paramsInfo.GetInputToForgetWeights());
+    const arm_compute::TensorInfo aclInputToCellWeightsInfo
+            = BuildArmComputeTensorInfo(paramsInfo.GetInputToCellWeights());
+    const arm_compute::TensorInfo aclInputToOutputWeightsInfo
+            = BuildArmComputeTensorInfo(paramsInfo.GetInputToOutputWeights());
+    const arm_compute::TensorInfo aclRecurrentToForgetWeightsInfo
+            = BuildArmComputeTensorInfo(paramsInfo.GetRecurrentToForgetWeights());
+    const arm_compute::TensorInfo aclRecurrentToCellWeightsInfo
+            = BuildArmComputeTensorInfo(paramsInfo.GetRecurrentToCellWeights());
+    const arm_compute::TensorInfo aclRecurrentToOutputWeightsInfo
+            = BuildArmComputeTensorInfo(paramsInfo.GetRecurrentToOutputWeights());
+    const arm_compute::TensorInfo aclForgetGateBiasInfo
+            = BuildArmComputeTensorInfo(paramsInfo.GetForgetGateBias());
+    const arm_compute::TensorInfo aclCellBiasInfo
+            = BuildArmComputeTensorInfo(paramsInfo.GetCellBias());
+    const arm_compute::TensorInfo aclOutputGateBiasInfo
+            = BuildArmComputeTensorInfo(paramsInfo.GetOutputGateBias());
+
+    // Optional tensor info
+    arm_compute::TensorInfo aclInputToInputWeightsInfo;
+    arm_compute::TensorInfo aclRecurrentToInputWeightsInfo;
+
+    arm_compute::TensorInfo aclCellToInputWeightsInfo;
+    arm_compute::TensorInfo aclCellToForgetWeightsInfo;
+    arm_compute::TensorInfo aclCellToOutputWeightsInfo;
+
+    arm_compute::TensorInfo aclInputGateBiasInfo;
+
+    arm_compute::TensorInfo aclProjectionWeightsInfo;
+    arm_compute::TensorInfo aclProjectionBiasInfo;
+
+    arm_compute::TensorInfo aclInputLayerNormWeightsInfo;
+    arm_compute::TensorInfo aclForgetLayerNormWeightsInfo;
+    arm_compute::TensorInfo aclCellLayerNormWeightsInfo;
+    arm_compute::TensorInfo aclOutputLayerNormWeightsInfo;
+
+
+    // Create tensor info for optional params if they are enabled
+    if (descriptor.m_PeepholeEnabled)
+    {
+        if (!descriptor.m_CifgEnabled)
+        {
+            aclCellToInputWeightsInfo = BuildArmComputeTensorInfo(paramsInfo.GetCellToInputWeights());
+        }
+
+        aclCellToForgetWeightsInfo = BuildArmComputeTensorInfo(paramsInfo.GetCellToForgetWeights());
+        aclCellToOutputWeightsInfo = BuildArmComputeTensorInfo(paramsInfo.GetCellToOutputWeights());
+
+        // Set peephole params info
+        aclParamsInfo.set_peephole_params(&aclCellToForgetWeightsInfo,
+                                          &aclCellToOutputWeightsInfo);
+    }
+
+    if (descriptor.m_ProjectionEnabled)
+    {
+        aclProjectionWeightsInfo = BuildArmComputeTensorInfo(paramsInfo.GetProjectionWeights());
+
+        if (paramsInfo.m_ProjectionBias != nullptr)
+        {
+            aclProjectionBiasInfo = BuildArmComputeTensorInfo(paramsInfo.GetProjectionBias());
+        }
+
+        // Set projection params info
+        aclParamsInfo.set_projection_params(
+                &aclProjectionWeightsInfo,
+                paramsInfo.m_ProjectionBias != nullptr ? &aclProjectionBiasInfo : nullptr);
+    }
+
+
+
+    if (descriptor.m_LayerNormEnabled)
+    {
+        if (!descriptor.m_CifgEnabled)
+        {
+            aclInputLayerNormWeightsInfo = BuildArmComputeTensorInfo(paramsInfo.GetInputLayerNormWeights());
+
+        }
+
+        aclForgetLayerNormWeightsInfo = BuildArmComputeTensorInfo(paramsInfo.GetForgetLayerNormWeights());
+        aclCellLayerNormWeightsInfo   = BuildArmComputeTensorInfo(paramsInfo.GetCellLayerNormWeights());
+        aclOutputLayerNormWeightsInfo = BuildArmComputeTensorInfo(paramsInfo.GetOutputLayerNormWeights());
+
+        // Set layer norm params info
+        aclParamsInfo.set_layer_normalization_params(
+                paramsInfo.m_InputLayerNormWeights != nullptr ? &aclInputLayerNormWeightsInfo : nullptr,
+                &aclForgetLayerNormWeightsInfo,
+                &aclCellLayerNormWeightsInfo,
+                &aclOutputLayerNormWeightsInfo);
+    }
+
+    if (!descriptor.m_CifgEnabled)
+    {
+        aclInputToInputWeightsInfo     = BuildArmComputeTensorInfo(paramsInfo.GetInputToInputWeights());
+        aclRecurrentToInputWeightsInfo = BuildArmComputeTensorInfo(paramsInfo.GetRecurrentToInputWeights());
+        aclInputGateBiasInfo           = BuildArmComputeTensorInfo(paramsInfo.GetInputGateBias());
+
+        // Set CIFG params info
+        aclParamsInfo.set_cifg_params(
+                &aclInputToInputWeightsInfo,
+                &aclRecurrentToInputWeightsInfo,
+                paramsInfo.m_CellToInputWeights != nullptr ? &aclCellToInputWeightsInfo : nullptr,
+                &aclInputGateBiasInfo);
+    }
+
+    // Set scalar descriptor params
+    aclParamsInfo.set_cell_clip_params(descriptor.m_CellClip);
+    aclParamsInfo.set_projection_clip_params(descriptor.m_ProjectionClip);
+    aclParamsInfo.set_hidden_state_params(descriptor.m_HiddenStateZeroPoint, descriptor.m_HiddenStateScale);
+    aclParamsInfo.set_matmul_scale_params(descriptor.m_InputIntermediateScale,
+                                          descriptor.m_ForgetIntermediateScale,
+                                          descriptor.m_CellIntermediateScale,
+                                          descriptor.m_OutputIntermediateScale);
+
+    // QLSTM NEON validate
+    return arm_compute::NEQLSTMLayer::validate(&aclInputInfo,
+                                               &aclInputToForgetWeightsInfo,
+                                               &aclInputToCellWeightsInfo,
+                                               &aclInputToOutputWeightsInfo,
+                                               &aclRecurrentToForgetWeightsInfo,
+                                               &aclRecurrentToCellWeightsInfo,
+                                               &aclRecurrentToOutputWeightsInfo,
+                                               &aclForgetGateBiasInfo,
+                                               &aclCellBiasInfo,
+                                               &aclOutputGateBiasInfo,
+                                               &aclCellStateInInfo,
+                                               &aclOutputStateInInfo,
+                                               &aclCellStateOutInfo,
+                                               &aclOutputStateOutInfo,
+                                               &aclOutputInfo,
+                                               aclParamsInfo);
+}
+
+void NeonQLstmWorkload::FreeUnusedTensors()
+{
+    FreeTensorIfUnused(m_InputToInputWeightsTensor);
+    FreeTensorIfUnused(m_InputToForgetWeightsTensor);
+    FreeTensorIfUnused(m_InputToCellWeightsTensor);
+    FreeTensorIfUnused(m_InputToOutputWeightsTensor);
+
+    FreeTensorIfUnused(m_RecurrentToInputWeightsTensor);
+    FreeTensorIfUnused(m_RecurrentToForgetWeightsTensor);
+    FreeTensorIfUnused(m_RecurrentToCellWeightsTensor);
+    FreeTensorIfUnused(m_RecurrentToOutputWeightsTensor);
+
+    FreeTensorIfUnused(m_CellToInputWeightsTensor);
+    FreeTensorIfUnused(m_CellToForgetWeightsTensor);
+    FreeTensorIfUnused(m_CellToOutputWeightsTensor);
+
+    FreeTensorIfUnused(m_InputGateBiasTensor);
+    FreeTensorIfUnused(m_ForgetGateBiasTensor);
+    FreeTensorIfUnused(m_CellBiasTensor);
+    FreeTensorIfUnused(m_OutputGateBiasTensor);
+
+    FreeTensorIfUnused(m_ProjectionWeightsTensor);
+    FreeTensorIfUnused(m_ProjectionBiasTensor);
+
+    FreeTensorIfUnused(m_InputLayerNormWeightsTensor);
+    FreeTensorIfUnused(m_ForgetLayerNormWeightsTensor);
+    FreeTensorIfUnused(m_CellLayerNormWeightsTensor);
+    FreeTensorIfUnused(m_OutputLayerNormWeightsTensor);
+}
+
+} //namespace armnn
\ No newline at end of file
diff --git a/src/backends/neon/workloads/NeonQLstmWorkload.hpp b/src/backends/neon/workloads/NeonQLstmWorkload.hpp
new file mode 100644 (file)
index 0000000..5da1518
--- /dev/null
@@ -0,0 +1,67 @@
+//
+// Copyright © 2020 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include <armnn/Descriptors.hpp>
+#include <armnn/LstmParams.hpp>
+#include <backendsCommon/Workload.hpp>
+#include <backendsCommon/WorkloadData.hpp>
+
+#include "arm_compute/graph/Tensor.h"
+#include "arm_compute/runtime/NEON/functions/NEQLSTMLayer.h"
+
+namespace armnn
+{
+
+class NeonQLstmWorkload : public BaseWorkload<QLstmQueueDescriptor>
+{
+public:
+    NeonQLstmWorkload(const QLstmQueueDescriptor& descriptor, const WorkloadInfo& info);
+    virtual void Execute() const override;
+
+private:
+    mutable arm_compute::NEQLSTMLayer m_QLstmLayer;
+
+    std::unique_ptr<arm_compute::Tensor> m_InputToInputWeightsTensor;
+    std::unique_ptr<arm_compute::Tensor> m_InputToForgetWeightsTensor;
+    std::unique_ptr<arm_compute::Tensor> m_InputToCellWeightsTensor;
+    std::unique_ptr<arm_compute::Tensor> m_InputToOutputWeightsTensor;
+
+    std::unique_ptr<arm_compute::Tensor> m_RecurrentToInputWeightsTensor;
+    std::unique_ptr<arm_compute::Tensor> m_RecurrentToForgetWeightsTensor;
+    std::unique_ptr<arm_compute::Tensor> m_RecurrentToCellWeightsTensor;
+    std::unique_ptr<arm_compute::Tensor> m_RecurrentToOutputWeightsTensor;
+
+    std::unique_ptr<arm_compute::Tensor> m_CellToInputWeightsTensor;
+    std::unique_ptr<arm_compute::Tensor> m_CellToForgetWeightsTensor;
+    std::unique_ptr<arm_compute::Tensor> m_CellToOutputWeightsTensor;
+
+    std::unique_ptr<arm_compute::Tensor> m_InputGateBiasTensor;
+    std::unique_ptr<arm_compute::Tensor> m_ForgetGateBiasTensor;
+    std::unique_ptr<arm_compute::Tensor> m_CellBiasTensor;
+    std::unique_ptr<arm_compute::Tensor> m_OutputGateBiasTensor;
+
+    std::unique_ptr<arm_compute::Tensor> m_ProjectionWeightsTensor;
+    std::unique_ptr<arm_compute::Tensor> m_ProjectionBiasTensor;
+
+    std::unique_ptr<arm_compute::Tensor> m_InputLayerNormWeightsTensor;
+    std::unique_ptr<arm_compute::Tensor> m_ForgetLayerNormWeightsTensor;
+    std::unique_ptr<arm_compute::Tensor> m_CellLayerNormWeightsTensor;
+    std::unique_ptr<arm_compute::Tensor> m_OutputLayerNormWeightsTensor;
+
+    void FreeUnusedTensors();
+};
+
+arm_compute::Status NeonQLstmWorkloadValidate(const TensorInfo& input,
+                                              const TensorInfo& cellStateIn,
+                                              const TensorInfo& outputStateIn,
+                                              const TensorInfo& cellStateOut,
+                                              const TensorInfo& outputStateOut,
+                                              const TensorInfo& output,
+                                              const QLstmDescriptor& descriptor,
+                                              const LstmInputParamsInfo& paramsInfo);
+
+} //namespace armnn
index 860a8353d69ab5d746720d9ee434b08ed94615d8..628cca93c69906e4e5c0a5177d928d1420580a54 100644 (file)
@@ -59,6 +59,9 @@ inline void InitializeArmComputeTensorData(arm_compute::Tensor& tensor,
         case DataType::Signed32:
             CopyArmComputeTensorData(tensor, handle->GetConstTensor<int32_t>());
             break;
+        case DataType::QSymmS16:
+            CopyArmComputeTensorData(tensor, handle->GetConstTensor<int16_t>());
+            break;
         default:
             ARMNN_ASSERT_MSG(false, "Unexpected tensor type.");
     }
index 9da698fc8c72711e458b0341e7c6ccb0879b4ac1..2da6ea0c01063b1eea96405d404dac0a0f89f47a 100644 (file)
@@ -39,6 +39,7 @@
 #include "NeonPermuteWorkload.hpp"
 #include "NeonPooling2dWorkload.hpp"
 #include "NeonPreluWorkload.hpp"
+#include "NeonQLstmWorkload.hpp"
 #include "NeonQuantizedLstmWorkload.hpp"
 #include "NeonQuantizeWorkload.hpp"
 #include "NeonReshapeWorkload.hpp"