Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / api / C / lstm.h
1 /*
2 // Copyright (c) 2016 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 ///////////////////////////////////////////////////////////////////////////////////////////////////
18 #ifndef LSTM_H
19 #define LSTM_H
20
21 #include <stdbool.h>
22 #include "cldnn.h"
23 /// @addtogroup c_api C API
24 /// @{
25 /// @addtogroup c_topology Network Topology
26 /// @{
27 /// @addtogroup c_primitives Primitives
28 /// @{
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 /// @brief Weights orders
35 /// @details Specifies the order in which the weights are concatenated.
36 /// e.g. [i, o, f, z] : [input, output, forget, block]
37 /// ONNX order: iofz
38 /// Caffe order: ifoz
39 /// pyTorch order: izof
40 /// IE order: fizo
41 typedef enum /*:int32_t*/
42 {
43     cldnn_lstm_offset_order_iofz = 0,
44     cldnn_lstm_offset_order_ifoz,
45     cldnn_lstm_offset_order_izof,
46     cldnn_lstm_offset_order_fizo
47 } cldnn_lstm_offset_order;
48
49 /// @brief LSTM Output selection
50 /// @details The current implementation allows the use to select the output
51 /// of an LSTM node by specifing any of the following options 
52 typedef enum /*:int32_t*/
53 {
54     /// output the entire hidden sequence
55     cldnn_lstm_output_sequence = 0,
56     /// output just the last hidden value
57     cldnn_lstm_output_hidden,
58     /// output the last hidden and last cell values
59     cldnn_lstm_output_hidden_cell,
60     /// output the hidden sequence concatenated with the last cell
61     cldnn_lstm_output_sequence_cell
62 } cldnn_lstm_output;
63
64 /// @brief Performs forward Long Short-Term Memory (LSTM) layer.
65 /// @details The current implementation of LSTM is described the following equations.
66 ///   it = f(Xt*(Wi^T) + Ht-1*Ri + Wbi)
67 ///   ft = f(Xt*(Wf^T) + Ht-1*Rf + Wbf)
68 ///   ct = g(Xt*(Wc^T) + Ht-1*Rc + Wbc)
69 ///   Ct = ft (.) Ct-1 + it (.) ct
70 ///   ot = f(Xt*(Wo^T) + Ht-1*Ro + Wbo)
71 ///   Ht = ot (.) h(Ct)
72 /// Where f = Sigmoid, g = Tanh, and h = Tanh.
73 CLDNN_BEGIN_PRIMITIVE_DESC(lstm)
74 /// @brief Array of primitive ids containing weight matrices for input, output, forget, and cell gates.
75 cldnn_primitive_id weights;
76 /// @brief Array of primitive ids containing recurrent weight matrices for input, output, forget, and cell gates.
77 cldnn_primitive_id recurrent;
78 /// @brief Array of primitive ids containing bias vectors for input, output, forget, and cell gates.
79 cldnn_primitive_id bias;
80 /// @brief Array of primitive ids containing the initial value of the hidden data (Ht-1).
81 cldnn_primitive_id initial_hidden;
82 /// @brief Array of primitive ids containing the initial value of the cell state data (Ct-1).
83 cldnn_primitive_id initial_cell;
84 /// @brief Array of primitive ids containing peephole weight vectors for input, output, and forget gates.
85 cldnn_primitive_id peepholes;
86 /// @brief Cell clip threshold T. It is applied to the input of activations [-T, T]. No clip is applied if it is not specified.
87 float clip;
88 /// @brief Couple the input and forget gates if input_forget is 1. Default is 0.
89 bool input_forget;
90 /// @brief A list of 3 activation functions for the input, output, forget, cell, and hidden.
91 cldnn_activation_func activations[3];
92 /// @brief Optional scaling values used by some activation functions. The values are consumed in the order of activation functions.
93 cldnn_activation_additional_params activation_params[3];
94 /// @brief Output selection. Default the entire hidden sequence is returned
95 cldnn_lstm_output output_selection;
96 /// @brief Weights, recurrent weights, and biases order. [iofz] : ONNX, [ifoz] : Caffe
97 cldnn_lstm_offset_order offset_order;
98 // NOT SUPPORTED YET
99 // uint32_t output_sequence;
100 CLDNN_END_PRIMITIVE_DESC(lstm)
101
102 CLDNN_DECLARE_PRIMITIVE_TYPE_ID(lstm);
103
104
105
106 /// @brief LSTM Layer GEMM helper primitive.
107 /// @details The current helper primitive performs fused GEMM operations.
108 CLDNN_BEGIN_PRIMITIVE_DESC(lstm_gemm)
109 /// @brief Array of primitive ids containing weight matrices for input, output, forget, and cell gates.
110 cldnn_primitive_id weights;
111 /// @brief Array of primitive ids containing recurrent weight matrices for input, output, forget, and cell gates.
112 cldnn_primitive_id recurrent;
113 /// @brief Array of primitive ids containing bias vectors for input, output, forget, and cell gates.
114 cldnn_primitive_id bias;
115 /// @brief Array of primitive ids containing the initial value of the hidden data (Ht-1).
116 cldnn_primitive_id hidden;
117 /// @brief direction default = 0, bidirectional = 1.
118 uint32_t direction;
119 CLDNN_END_PRIMITIVE_DESC(lstm_gemm)
120
121 CLDNN_DECLARE_PRIMITIVE_TYPE_ID(lstm_gemm);
122
123
124
125 /// @brief LSTM Layer element-wise helper primitive.
126 /// @details The current helper primitive performs fused element-wise operations.
127 CLDNN_BEGIN_PRIMITIVE_DESC(lstm_elt)
128 /// @brief Array of primitive ids containing the initial value of the cell state data (Ct-1).
129 cldnn_primitive_id cell;
130 /// @brief Cell clip threshold T. It is applied to the input of activations [-T, T]. No clip is applied if it is not specified.
131 float clip;
132 /// @brief Couple the input and forget gates if input_forget is 1. Default is 0.
133 bool input_forget;
134 /// @brief A list of 3 activation functions for the input, output, forget, cell, and hidden.
135 cldnn_activation_func activations[3];
136 /// @brief Optional scaling values used by some activation functions. The values are consumed in the order of activation functions.
137 cldnn_activation_additional_params activation_params[3];
138 /// @brief Weights, recurrent weights, and biases order. [iofz] : ONNX, [ifoz] : Caffe
139 cldnn_lstm_offset_order offset_order;
140 /// @brief direction default = 0, bidirectional = 1.
141 uint32_t direction;
142 // NOT SUPPORTED YET
143 // uint32_t output_sequence;
144 CLDNN_END_PRIMITIVE_DESC(lstm_elt)
145
146 CLDNN_DECLARE_PRIMITIVE_TYPE_ID(lstm_elt);
147
148 #ifdef __cplusplus
149 }
150 #endif
151
152 /// @}
153 /// @}
154 /// @}
155 #endif /* LSTM_H */
156