aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/layers/LstmLayer.hpp
blob: 247fec389d77b615459510e5dea079007e79e384 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//
#pragma once

#include "LayerWithParameters.hpp"

namespace armnn
{

class ScopedCpuTensorHandle;

struct LstmOptCifgParameters
{
    std::unique_ptr<ScopedCpuTensorHandle> m_InputToInputWeights;
    std::unique_ptr<ScopedCpuTensorHandle> m_RecurrentToInputWeights;
    std::unique_ptr<ScopedCpuTensorHandle> m_CellToInputWeights;
    std::unique_ptr<ScopedCpuTensorHandle> m_InputGateBias;
};

struct LstmOptProjectionParameters
{
    std::unique_ptr<ScopedCpuTensorHandle> m_ProjectionWeights;
    std::unique_ptr<ScopedCpuTensorHandle> m_ProjectionBias;
};

struct LstmOptPeepholeParameters
{
    std::unique_ptr<ScopedCpuTensorHandle> m_CellToForgetWeights;
    std::unique_ptr<ScopedCpuTensorHandle> m_CellToOutputWeights;
};

struct LstmBasicParameters
{
    std::unique_ptr<ScopedCpuTensorHandle> m_InputToForgetWeights;
    std::unique_ptr<ScopedCpuTensorHandle> m_InputToCellWeights;
    std::unique_ptr<ScopedCpuTensorHandle> m_InputToOutputWeights;
    std::unique_ptr<ScopedCpuTensorHandle> m_RecurrentToForgetWeights;
    std::unique_ptr<ScopedCpuTensorHandle> m_RecurrentToCellWeights;
    std::unique_ptr<ScopedCpuTensorHandle> m_RecurrentToOutputWeights;
    std::unique_ptr<ScopedCpuTensorHandle> m_ForgetGateBias;
    std::unique_ptr<ScopedCpuTensorHandle> m_CellBias;
    std::unique_ptr<ScopedCpuTensorHandle> m_OutputGateBias;
};

class LstmLayer : public LayerWithParameters<LstmDescriptor>
{
public:

    LstmBasicParameters m_BasicParameters;
    LstmOptCifgParameters m_CifgParameters;
    LstmOptProjectionParameters m_ProjectionParameters;
    LstmOptPeepholeParameters m_PeepholeParameters;

    virtual std::unique_ptr<IWorkload> CreateWorkload(const Graph&            graph,
                                                      const IWorkloadFactory& factory) const override;
    LstmLayer* Clone(Graph& graph) const override;

    void ValidateTensorShapesFromInputs() override;
    std::vector<TensorShape> InferOutputShapes(const std::vector<TensorShape>& inputShapes) const override;

protected:
    LstmLayer(const LstmDescriptor& param, const char* name);
    ~LstmLayer() = default;

    Layer::ConstantTensors GetConstantTensorsByRef() override;
};

} // namespace