Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / input_layout.cpp
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 #include "input_layout_inst.h"
19 #include "primitive_type_base.h"
20 #include "memory_impl.h"
21 #include "error_handler.h"
22 #include "json_object.h"
23
24 namespace cldnn
25 {
26 primitive_type_id input_layout_type_id()
27 {
28     static primitive_type_base<input_layout> instance;
29     return &instance;
30 }
31
32 input_layout_node::typed_program_node(const std::shared_ptr<input_layout> dprim, program_impl& prog)
33     : parent(dprim, prog)
34 {
35     can_share_buffer(false);
36 }
37
38 input_layout_inst::typed_primitive_inst(network_impl& network, input_layout_node const& node)
39     : parent(network, node)
40 {
41     _has_valid_input = false; //by default input for 'input_layout' is invalid as long as user doesn't call set_data
42 }
43
44 void input_layout_inst::set_data(memory_impl& mem)
45 {
46
47     CLDNN_ERROR_LAYOUT_MISMATCH("input layout", "memory layout", mem.get_layout(), "output memory layout", node.get_output_layout(), "");
48
49     if (mem.is_allocated_by(get_network().get_engine()))
50     {
51         _output = &mem;
52     }
53     else
54     {
55         mem_lock<char> src(&mem);
56         mem_lock<char> dst(_output);
57         std::copy(src.begin(), src.end(), dst.begin());
58     }
59
60     _has_valid_input = true;
61     _output_changed = true;
62 }
63
64 std::string input_layout_inst::to_string(input_layout_node const& node)
65 {
66     auto node_info = node.desc_to_json();
67
68     std::stringstream primitive_description;
69
70     node_info->dump(primitive_description);
71
72     return primitive_description.str();
73 }
74
75 }