IVGCVSW-4450 Add CL Enhanced Quantized LSTM Workload
authorRyan OShea <Ryan.OShea2@arm.com>
Wed, 13 May 2020 15:36:19 +0000 (16:36 +0100)
committerJan Eilers <jan.eilers@arm.com>
Wed, 20 May 2020 14:58:12 +0000 (15:58 +0100)
 * Adds QLstm CL workload
 * Added Layer and CreateWorkload tests

Signed-off-by: Ryan OShea <Ryan.OShea2@arm.com>
Signed-off-by: James Conroy <james.conroy@arm.com>
Change-Id: I32335e528467bfd619edb249d2971705ac2a6163

12 files changed:
src/backends/cl/ClLayerSupport.cpp
src/backends/cl/ClLayerSupport.hpp
src/backends/cl/ClWorkloadFactory.cpp
src/backends/cl/ClWorkloadFactory.hpp
src/backends/cl/backend.mk
src/backends/cl/test/ClCreateWorkloadTests.cpp
src/backends/cl/test/ClLayerTests.cpp
src/backends/cl/workloads/CMakeLists.txt
src/backends/cl/workloads/ClQLstmWorkload.cpp [new file with mode: 0644]
src/backends/cl/workloads/ClQLstmWorkload.hpp [new file with mode: 0644]
src/backends/cl/workloads/ClWorkloadUtils.hpp
src/backends/cl/workloads/ClWorkloads.hpp

index eb68a80..7418dbd 100644 (file)
 #include "workloads/ClPermuteWorkload.hpp"
 #include "workloads/ClPooling2dWorkload.hpp"
 #include "workloads/ClPreluWorkload.hpp"
+#include "workloads/ClQLstmWorkload.hpp"
+#include "workloads/ClQuantizedLstmWorkload.hpp"
+#include "workloads/ClQuantizeWorkload.hpp"
 #include "workloads/ClReshapeWorkload.hpp"
 #include "workloads/ClResizeWorkload.hpp"
 #include "workloads/ClRsqrtWorkload.hpp"
-#include "workloads/ClQuantizedLstmWorkload.hpp"
-#include "workloads/ClQuantizeWorkload.hpp"
 #include "workloads/ClSliceWorkload.hpp"
 #include "workloads/ClSoftmaxWorkload.hpp"
 #include "workloads/ClSpaceToBatchNdWorkload.hpp"
@@ -618,6 +619,40 @@ bool ClLayerSupport::IsPreluSupported(const armnn::TensorInfo &input,
     FORWARD_WORKLOAD_VALIDATE_FUNC(ClPreluWorkloadValidate, reasonIfUnsupported, input, alpha, output);
 }
 
+bool ClLayerSupport::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
+{
+    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(ClQLstmWorkloadValidate,
+                                       reasonIfUnsupported,
+                                       input,
+                                       previousCellStateIn,
+                                       previousOutputIn,
+                                       cellStateOut,
+                                       outputStateOut,
+                                       output,
+                                       descriptor,
+                                       paramsInfo);
+    }
+    else
+    {
+        return false;
+    }
+}
+
 bool ClLayerSupport::IsQuantizedLstmSupported(const TensorInfo& input,
                                               const TensorInfo& previousCellStateIn,
                                               const TensorInfo& previousOutputIn,
index 60899d0..d785f54 100644 (file)
@@ -203,6 +203,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 IsQuantizedLstmSupported(const TensorInfo& input,
                                   const TensorInfo& previousCellStateIn,
                                   const TensorInfo& previousOutputIn,
index f584272..50a867c 100644 (file)
@@ -431,6 +431,12 @@ std::unique_ptr<IWorkload> ClWorkloadFactory::CreatePrelu(const PreluQueueDescri
     return MakeWorkload<ClPreluWorkload>(descriptor, info);
 }
 
+std::unique_ptr<IWorkload> ClWorkloadFactory::CreateQLstm(const QLstmQueueDescriptor& descriptor,
+                                                          const WorkloadInfo& info) const
+{
+    return std::make_unique<ClQLstmWorkload>(descriptor, info);
+}
+
 std::unique_ptr<IWorkload> ClWorkloadFactory::CreateQuantize(const QuantizeQueueDescriptor& descriptor,
                                                              const WorkloadInfo& info) const
 {
index b1c6321..3f92e86 100644 (file)
@@ -168,6 +168,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 8b464bb..f18f8f0 100644 (file)
@@ -53,6 +53,7 @@ BACKEND_SOURCES := \
         workloads/ClPermuteWorkload.cpp \
         workloads/ClPooling2dWorkload.cpp \
         workloads/ClPreluWorkload.cpp \
+        workloads/ClQLstmWorkload.cpp \
         workloads/ClQuantizedLstmWorkload.cpp \
         workloads/ClQuantizeWorkload.cpp \
         workloads/ClReshapeWorkload.cpp \
index b752254..896d486 100644 (file)
@@ -1035,6 +1035,34 @@ BOOST_AUTO_TEST_CASE(CreateStackUint8Workload)
     ClCreateStackWorkloadTest<armnn::DataType::QAsymmU8>({ 3, 4, 5 }, { 3, 4, 2, 5 }, 2, 2);
 }
 
+
+template <typename QLstmWorkloadType>
+static void ClCreateQLstmWorkloadTest()
+{
+    Graph graph;
+    ClWorkloadFactory factory = ClWorkloadFactoryHelper::GetFactory(ClWorkloadFactoryHelper::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)
+{
+    ClCreateQLstmWorkloadTest<ClQLstmWorkload>();
+}
+
 template <typename QuantizedLstmWorkloadType>
 static void ClCreateQuantizedLstmWorkloadTest()
 {
index ce4496e..1c433a8 100644 (file)
@@ -516,6 +516,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)
 
 // Convert from Float16 to Float32
index 1d8ac3c..6d0aa79 100644 (file)
@@ -66,6 +66,8 @@ list(APPEND armnnClBackendWorkloads_sources
     ClPooling2dWorkload.hpp
     ClPreluWorkload.cpp
     ClPreluWorkload.hpp
+    ClQLstmWorkload.cpp
+    ClQLstmWorkload.hpp
     ClQuantizedLstmWorkload.cpp
     ClQuantizedLstmWorkload.hpp
     ClQuantizeWorkload.cpp
diff --git a/src/backends/cl/workloads/ClQLstmWorkload.cpp b/src/backends/cl/workloads/ClQLstmWorkload.cpp
new file mode 100644 (file)
index 0000000..ea51f37
--- /dev/null
@@ -0,0 +1,401 @@
+//
+// Copyright © 2020 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "ClQLstmWorkload.hpp"
+#include "ClWorkloadUtils.hpp"
+
+#include "aclCommon/ArmComputeTensorUtils.hpp"
+
+#include "cl/ClTensorHandle.hpp"
+
+namespace armnn
+{
+using namespace armcomputetensorutils;
+
+ClQLstmWorkload::ClQLstmWorkload(const QLstmQueueDescriptor &descriptor, const WorkloadInfo &info)
+    : BaseWorkload<QLstmQueueDescriptor>(descriptor, info)
+{
+    arm_compute::LSTMParams<arm_compute::ICLTensor> qLstmParams;
+
+    // Mandatory params
+    m_InputToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
+    BuildArmComputeTensor(*m_InputToForgetWeightsTensor, m_Data.m_InputToForgetWeights->GetTensorInfo());
+
+    m_InputToCellWeightsTensor = std::make_unique<arm_compute::CLTensor>();
+    BuildArmComputeTensor(*m_InputToCellWeightsTensor, m_Data.m_InputToCellWeights->GetTensorInfo());
+
+    m_InputToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
+    BuildArmComputeTensor(*m_InputToOutputWeightsTensor, m_Data.m_InputToOutputWeights->GetTensorInfo());
+
+    m_RecurrentToForgetWeightsTensor = std::make_unique<arm_compute::CLTensor>();
+    BuildArmComputeTensor(*m_RecurrentToForgetWeightsTensor, m_Data.m_RecurrentToForgetWeights->GetTensorInfo());
+
+    m_RecurrentToCellWeightsTensor = std::make_unique<arm_compute::CLTensor>();
+    BuildArmComputeTensor(*m_RecurrentToCellWeightsTensor, m_Data.m_RecurrentToCellWeights->GetTensorInfo());
+
+    m_RecurrentToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
+    BuildArmComputeTensor(*m_RecurrentToOutputWeightsTensor, m_Data.m_RecurrentToOutputWeights->GetTensorInfo());
+
+    m_ForgetGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
+    BuildArmComputeTensor(*m_ForgetGateBiasTensor, m_Data.m_ForgetGateBias->GetTensorInfo());
+
+    m_CellBiasTensor = std::make_unique<arm_compute::CLTensor>();
+    BuildArmComputeTensor(*m_CellBiasTensor, m_Data.m_CellBias->GetTensorInfo());
+
+    m_OutputGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
+    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::CLTensor>();
+
+        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::CLTensor>();
+        BuildArmComputeTensor(*m_CellToForgetWeightsTensor, m_Data.m_CellToForgetWeights->GetTensorInfo());
+
+        m_CellToOutputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
+        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::CLTensor>();
+        BuildArmComputeTensor(*m_ProjectionWeightsTensor, m_Data.m_ProjectionWeights->GetTensorInfo());
+
+        m_ProjectionBiasTensor = std::make_unique<arm_compute::CLTensor>();
+        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::CLTensor>();
+
+        if (!m_Data.m_Parameters.m_CifgEnabled)
+        {
+            BuildArmComputeTensor(*m_InputLayerNormWeightsTensor, m_Data.m_InputLayerNormWeights->GetTensorInfo());
+        }
+
+        m_ForgetLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
+        BuildArmComputeTensor(*m_ForgetLayerNormWeightsTensor, m_Data.m_ForgetLayerNormWeights->GetTensorInfo());
+
+        m_CellLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
+        BuildArmComputeTensor(*m_CellLayerNormWeightsTensor, m_Data.m_CellLayerNormWeights->GetTensorInfo());
+
+        m_OutputLayerNormWeightsTensor = std::make_unique<arm_compute::CLTensor>();
+        BuildArmComputeTensor(*m_OutputLayerNormWeightsTensor, m_Data.m_OutputLayerNormWeights->GetTensorInfo());
+
+        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::CLTensor>();
+        BuildArmComputeTensor(*m_InputToInputWeightsTensor, m_Data.m_InputToInputWeights->GetTensorInfo());
+
+        m_RecurrentToInputWeightsTensor = std::make_unique<arm_compute::CLTensor>();
+        BuildArmComputeTensor(*m_RecurrentToInputWeightsTensor, m_Data.m_RecurrentToInputWeights->GetTensorInfo());
+
+        m_InputGateBiasTensor = std::make_unique<arm_compute::CLTensor>();
+        BuildArmComputeTensor(*m_InputGateBiasTensor, m_Data.m_InputGateBias->GetTensorInfo());
+
+        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::ICLTensor& input         = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
+    const arm_compute::ICLTensor& outputStateIn = static_cast<IClTensorHandle*>(m_Data.m_Inputs[1])->GetTensor();
+    const arm_compute::ICLTensor& cellStateIn   = static_cast<IClTensorHandle*>(m_Data.m_Inputs[2])->GetTensor();
+
+    arm_compute::ICLTensor& outputStateOut = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
+    arm_compute::ICLTensor& cellStateOut   = static_cast<IClTensorHandle*>(m_Data.m_Outputs[1])->GetTensor();
+    arm_compute::ICLTensor& output         = static_cast<IClTensorHandle*>(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);
+
+    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);
+
+    // InitializeArmComputeTensorData for mandatory params
+    InitializeArmComputeClTensorData(*m_InputToForgetWeightsTensor, m_Data.m_InputToForgetWeights);
+    InitializeArmComputeClTensorData(*m_InputToCellWeightsTensor,   m_Data.m_InputToCellWeights);
+    InitializeArmComputeClTensorData(*m_InputToOutputWeightsTensor, m_Data.m_InputToOutputWeights);
+
+    InitializeArmComputeClTensorData(*m_RecurrentToForgetWeightsTensor, m_Data.m_RecurrentToForgetWeights);
+    InitializeArmComputeClTensorData(*m_RecurrentToCellWeightsTensor,   m_Data.m_RecurrentToCellWeights);
+    InitializeArmComputeClTensorData(*m_RecurrentToOutputWeightsTensor, m_Data.m_RecurrentToOutputWeights);
+
+    InitializeArmComputeClTensorData(*m_ForgetGateBiasTensor, m_Data.m_ForgetGateBias);
+    InitializeArmComputeClTensorData(*m_CellBiasTensor,       m_Data.m_CellBias);
+    InitializeArmComputeClTensorData(*m_OutputGateBiasTensor, m_Data.m_OutputGateBias);
+
+    if (!m_Data.m_Parameters.m_CifgEnabled)
+    {
+        InitializeArmComputeClTensorData(*m_InputToInputWeightsTensor,     m_Data.m_InputToInputWeights);
+        InitializeArmComputeClTensorData(*m_RecurrentToInputWeightsTensor, m_Data.m_RecurrentToInputWeights);
+        InitializeArmComputeClTensorData(*m_InputGateBiasTensor,           m_Data.m_InputGateBias);
+    }
+
+    if (m_Data.m_Parameters.m_ProjectionEnabled)
+    {
+        InitializeArmComputeClTensorData(*m_ProjectionWeightsTensor, m_Data.m_ProjectionWeights);
+
+        if (m_Data.m_ProjectionBias != nullptr)
+        {
+            InitializeArmComputeClTensorData(*m_ProjectionBiasTensor, m_Data.m_ProjectionBias);
+        }
+    }
+
+    if (m_Data.m_Parameters.m_PeepholeEnabled)
+    {
+        if (!m_Data.m_Parameters.m_CifgEnabled)
+        {
+            InitializeArmComputeClTensorData(*m_CellToInputWeightsTensor, m_Data.m_CellToInputWeights);
+        }
+
+        InitializeArmComputeClTensorData(*m_CellToForgetWeightsTensor, m_Data.m_CellToForgetWeights);
+        InitializeArmComputeClTensorData(*m_CellToOutputWeightsTensor, m_Data.m_CellToOutputWeights);
+    }
+
+    if (m_Data.m_Parameters.m_LayerNormEnabled)
+    {
+        if (!m_Data.m_Parameters.m_CifgEnabled)
+        {
+            InitializeArmComputeClTensorData(*m_InputLayerNormWeightsTensor, m_Data.m_InputLayerNormWeights);
+        }
+        InitializeArmComputeClTensorData(*m_ForgetLayerNormWeightsTensor, m_Data.m_ForgetLayerNormWeights);
+        InitializeArmComputeClTensorData(*m_CellLayerNormWeightsTensor,   m_Data.m_CellLayerNormWeights);
+        InitializeArmComputeClTensorData(*m_OutputLayerNormWeightsTensor, m_Data.m_OutputLayerNormWeights);
+    }
+
+    m_QLstmLayer.prepare();
+
+    FreeUnusedTensors();
+}
+
+void ClQLstmWorkload::Execute() const
+{
+    m_QLstmLayer.run();
+}
+
+arm_compute::Status ClQLstmWorkloadValidate(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;
+
+    // The inputs and outputs
+    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;
+
+
+    if (descriptor.m_PeepholeEnabled)
+    {
+        if (!descriptor.m_CifgEnabled)
+        {
+            aclCellToInputWeightsInfo = BuildArmComputeTensorInfo(paramsInfo.GetCellToInputWeights());
+        }
+
+        aclCellToForgetWeightsInfo = BuildArmComputeTensorInfo(paramsInfo.GetCellToForgetWeights());
+        aclCellToOutputWeightsInfo = BuildArmComputeTensorInfo(paramsInfo.GetCellToOutputWeights());
+
+        aclParamsInfo.set_peephole_params(&aclCellToForgetWeightsInfo,
+                                          &aclCellToOutputWeightsInfo);
+    }
+
+    if (descriptor.m_ProjectionEnabled)
+    {
+        aclProjectionWeightsInfo = BuildArmComputeTensorInfo(paramsInfo.GetProjectionWeights());
+
+        if (paramsInfo.m_ProjectionBias != nullptr)
+        {
+            aclProjectionBiasInfo = BuildArmComputeTensorInfo(paramsInfo.GetProjectionBias());
+        }
+
+        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());
+
+        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());
+
+
+        aclParamsInfo.set_cifg_params(
+            &aclInputToInputWeightsInfo,
+            &aclRecurrentToInputWeightsInfo,
+            paramsInfo.m_CellToInputWeights      != nullptr ? &aclCellToInputWeightsInfo      : nullptr,
+            &aclInputGateBiasInfo);
+    }
+
+    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);
+
+    return arm_compute::CLQLSTMLayer::validate(&aclInputInfo,
+                                               &aclInputToForgetWeightsInfo,
+                                               &aclInputToCellWeightsInfo,
+                                               &aclInputToOutputWeightsInfo,
+                                               &aclRecurrentToForgetWeightsInfo,
+                                               &aclRecurrentToCellWeightsInfo,
+                                               &aclRecurrentToOutputWeightsInfo,
+                                               &aclForgetGateBiasInfo,
+                                               &aclCellBiasInfo,
+                                               &aclOutputGateBiasInfo,
+                                               &aclCellStateInInfo,
+                                               &aclOutputStateInInfo,
+                                               &aclCellStateOutInfo,
+                                               &aclOutputStateOutInfo,
+                                               &aclOutputInfo,
+                                               aclParamsInfo);
+}
+
+void ClQLstmWorkload::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
diff --git a/src/backends/cl/workloads/ClQLstmWorkload.hpp b/src/backends/cl/workloads/ClQLstmWorkload.hpp
new file mode 100644 (file)
index 0000000..f98c9b3
--- /dev/null
@@ -0,0 +1,66 @@
+//
+// 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/CL/functions/CLQLSTMLayer.h"
+
+namespace armnn
+{
+
+class ClQLstmWorkload : public BaseWorkload<QLstmQueueDescriptor>
+{
+public:
+    ClQLstmWorkload(const QLstmQueueDescriptor& descriptor, const WorkloadInfo& info);
+    virtual void Execute() const override;
+
+private:
+    mutable arm_compute::CLQLSTMLayer m_QLstmLayer;
+
+    std::unique_ptr<arm_compute::CLTensor> m_InputToInputWeightsTensor;
+    std::unique_ptr<arm_compute::CLTensor> m_InputToForgetWeightsTensor;
+    std::unique_ptr<arm_compute::CLTensor> m_InputToCellWeightsTensor;
+    std::unique_ptr<arm_compute::CLTensor> m_InputToOutputWeightsTensor;
+
+    std::unique_ptr<arm_compute::CLTensor> m_RecurrentToInputWeightsTensor;
+    std::unique_ptr<arm_compute::CLTensor> m_RecurrentToForgetWeightsTensor;
+    std::unique_ptr<arm_compute::CLTensor> m_RecurrentToCellWeightsTensor;
+    std::unique_ptr<arm_compute::CLTensor> m_RecurrentToOutputWeightsTensor;
+
+    std::unique_ptr<arm_compute::CLTensor> m_CellToInputWeightsTensor;
+    std::unique_ptr<arm_compute::CLTensor> m_CellToForgetWeightsTensor;
+    std::unique_ptr<arm_compute::CLTensor> m_CellToOutputWeightsTensor;
+
+    std::unique_ptr<arm_compute::CLTensor> m_InputGateBiasTensor;
+    std::unique_ptr<arm_compute::CLTensor> m_ForgetGateBiasTensor;
+    std::unique_ptr<arm_compute::CLTensor> m_CellBiasTensor;
+    std::unique_ptr<arm_compute::CLTensor> m_OutputGateBiasTensor;
+
+    std::unique_ptr<arm_compute::CLTensor> m_ProjectionWeightsTensor;
+    std::unique_ptr<arm_compute::CLTensor> m_ProjectionBiasTensor;
+
+    std::unique_ptr<arm_compute::CLTensor> m_InputLayerNormWeightsTensor;
+    std::unique_ptr<arm_compute::CLTensor> m_ForgetLayerNormWeightsTensor;
+    std::unique_ptr<arm_compute::CLTensor> m_CellLayerNormWeightsTensor;
+    std::unique_ptr<arm_compute::CLTensor> m_OutputLayerNormWeightsTensor;
+
+    void FreeUnusedTensors();
+};
+
+arm_compute::Status ClQLstmWorkloadValidate(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 54e7717..f2fb80a 100644 (file)
@@ -111,6 +111,9 @@ inline void InitializeArmComputeClTensorData(arm_compute::CLTensor& clTensor,
         case DataType::QSymmS8:
             CopyArmComputeClTensorData(clTensor, handle->GetConstTensor<int8_t>());
             break;
+        case DataType::QSymmS16:
+            CopyArmComputeClTensorData(clTensor, handle->GetConstTensor<int16_t>());
+            break;
         ARMNN_NO_DEPRECATE_WARN_END
         case DataType::Signed32:
             CopyArmComputeClTensorData(clTensor, handle->GetConstTensor<int32_t>());
index 62b73da..7b3ce43 100644 (file)
@@ -33,6 +33,7 @@
 #include "ClPadWorkload.hpp"
 #include "ClPooling2dWorkload.hpp"
 #include "ClPreluWorkload.hpp"
+#include "ClQLstmWorkload.hpp"
 #include "ClQuantizeWorkload.hpp"
 #include "ClQuantizedLstmWorkload.hpp"
 #include "ClReshapeWorkload.hpp"