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 "data_inst.h"
19 #include "primitive_type_base.h"
20 #include "memory_impl.h"
22 #include "json_object.h"
26 primitive_type_id data_type_id()
28 static primitive_type_base<data> instance;
33 memory_impl::ptr attach_or_copy_data(network_impl& network, memory_impl& mem)
35 auto& engine = network.get_engine();
36 if (mem.is_allocated_by(engine))
39 memory_impl::ptr result = engine.allocate_memory(mem.get_layout());
40 mem_lock<char> src(mem);
41 mem_lock<char> dst(result);
42 std::copy(src.begin(), src.end(), dst.begin());
47 data_node::typed_program_node(const std::shared_ptr<data> dprim, program_impl& prog)
48 : parent(dprim, prog), mem(api_cast(dprim->mem.get()))
51 can_share_buffer(false);
52 recalc_output_layout(false);
55 void data_node::attach_memory(memory_impl& new_mem, bool invalidate_users_if_changed)
58 recalc_output_layout(invalidate_users_if_changed);
61 std::string data_inst::to_string(data_node const& node)
63 auto node_info = node.desc_to_json();
65 std::stringstream primitive_description;
67 node_info->dump(primitive_description);
68 return primitive_description.str();
71 data_inst::typed_primitive_inst(network_impl& network, data_node const& node)
72 : parent(network, node, *attach_or_copy_data(network, node.get_attached_memory()))