Publishing R3
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / include / lstm_inst.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 #pragma once
19 #include "api/CPP/lstm.hpp"
20 #include "primitive_inst.h"
21
22 namespace cldnn
23 {
24 template <>
25 struct typed_program_node<lstm> : public typed_program_node_base<lstm>
26 {
27     using parent = typed_program_node_base<lstm>;
28
29 public:
30     using parent::parent;
31
32     decltype(auto) input() const { return get_dependency(0); }
33     decltype(auto) weights() const { return get_dependency(1); }
34     decltype(auto) recurrent() const { return get_dependency(2); }
35     decltype(auto) bias() const { return get_dependency(3); }
36     decltype(auto) inital_hidden() const {
37         return get_dependency(bias_term() ? 4 : 3);
38     }
39     decltype(auto) inital_cell() const {
40         // This doesn't scale. We should use a map to get the dependencies index at primitive level
41         return get_dependency(bias_term() ? (initial_hidden_term() ? 5 : 4) : (initial_hidden_term() ? 4 : 2));
42     }
43     decltype(auto) peepholes() const { return get_dependency(6); }
44     bool bias_term() const { return !get_primitive()->bias.empty(); }
45     bool peepholes_term() const { return !get_primitive()->peepholes.empty(); }
46     bool initial_hidden_term() const { return !get_primitive()->initial_hidden.empty(); }
47     bool initial_cell_term() const { return !get_primitive()->initial_cell.empty(); }
48     auto activations() const { return get_primitive()->activations; }
49     auto activation_params() const { return get_primitive()->activation_params; }
50 };
51
52 using lstm_node = typed_program_node<lstm>;
53
54 template <>
55 class typed_primitive_inst<lstm> : public typed_primitive_inst_base<lstm>
56 {
57     using parent = typed_primitive_inst_base<lstm>;
58
59 public:
60     static layout calc_output_layout(lstm_node const& node);
61     static std::string to_string(lstm_node const& node);
62
63 public:
64     typed_primitive_inst(network_impl& network, lstm_node const& node);
65
66     decltype(auto) weights_memory() const { return dep_memory(1); }
67     decltype(auto) recurrent_memory() const { return dep_memory(2); }
68     decltype(auto) bias_memory() const { return dep_memory(3); }
69     decltype(auto) initial_hidden_memory() const
70     {
71         return dep_memory(bias_term() ? 4 : 3);
72     }
73     decltype(auto) initial_cell_memory() const {
74         return dep_memory(bias_term() ? (initial_hidden_term() ? 5 : 4) : (initial_hidden_term() ? 4 : 2));
75     }
76     decltype(auto) peepholes_memory() const { return dep_memory(6); }
77     bool bias_term() const { return !argument.bias.empty(); }
78     bool peepholes_term() const { return !argument.peepholes.empty(); }
79     bool initial_hidden_term() const { return !argument.initial_hidden.empty(); }
80     bool initial_cell_term() const { return !argument.initial_cell.empty(); }
81     auto activations() const { return argument.activations; }
82     auto activation_params() const { return argument.activation_params; }
83 };
84
85 using lstm_inst = typed_primitive_inst<lstm>;
86
87 }