2 // Copyright (c) 2016 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 ///////////////////////////////////////////////////////////////////////////////////////////////////
18 #include "lstm_elt_inst.h"
19 #include "primitive_type_base.h"
20 #include "error_handler.h"
21 #include "json_object.h"
25 primitive_type_id lstm_elt_type_id()
27 static primitive_type_base<lstm_elt> instance;
31 layout lstm_elt_inst::calc_output_layout(lstm_elt_node const& node)
33 assert((bool)node.get_primitive()->output_data_type == false
34 && "Output data type forcing is not supported for lstm_elt_node!");
35 auto desc = node.get_primitive();
36 auto input_layout = node.input().get_output_layout();
38 // tempGEMM{bfyx} = [b: batch, f: direction, x: 1, y: 4 * hidden_size ] input
39 // cell{bfyx} = [b: batch, f: direction, x: 1, y: hidden_size ] optional
40 // output{bfyx} = [b: batch, f: 2, x: direction, y: hidden_size ] output
41 // The output of the lstm_elt node is the concatenation of the intermediate [hidden, cell] tensors.
42 // A crop/split node is needed to extract each individual tensors
43 auto result = layout(input_layout.data_type, input_layout.format,
44 tensor(input_layout.size.batch[0], 2, input_layout.size.spatial[0] / 4, input_layout.size.feature[0]));
48 std::string lstm_elt_inst::to_string(lstm_elt_node const& node)
50 auto desc = node.get_primitive();
51 auto node_info = node.desc_to_json();
52 auto cell_id = desc->cell;
54 std::stringstream primitive_description;
56 json_composite lstm_elt_info;
57 lstm_elt_info.add("cell id", cell_id);
58 node_info->add("lstm elt info", lstm_elt_info);
59 node_info->dump(primitive_description);
61 return primitive_description.str();
64 lstm_elt_inst::typed_primitive_inst(network_impl& network, lstm_elt_node const& node)
65 :parent(network, node)
67 auto input_size = node.input().get_output_layout();
68 CLDNN_ERROR_NOT_PROPER_FORMAT(node.id(), "input format", input_size.format.value, "expected format", format::bfyx, format::fyxb);