data.cpp 2.11 KB
Newer Older
openvino-pushbot's avatar
openvino-pushbot committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
// Copyright (c) 2016 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/

///////////////////////////////////////////////////////////////////////////////////////////////////
#include "data_inst.h"
#include "primitive_type_base.h"
#include "memory_impl.h"

Alexey Suhov's avatar
Alexey Suhov committed
22 23
#include "json_object.h"

openvino-pushbot's avatar
openvino-pushbot committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
namespace cldnn
{
primitive_type_id data_type_id()
{
    static primitive_type_base<data> instance;
    return &instance;
}

namespace {
    memory_impl::ptr attach_or_copy_data(network_impl& network, memory_impl& mem)
    {
        auto& engine = network.get_engine();
        if (mem.is_allocated_by(engine))
            return &mem;

        memory_impl::ptr result = engine.allocate_memory(mem.get_layout());
        mem_lock<char> src(mem);
        mem_lock<char> dst(result);
        std::copy(src.begin(), src.end(), dst.begin());
        return result;
    }
}

data_node::typed_program_node(const std::shared_ptr<data> dprim, program_impl& prog)
    : parent(dprim, prog), mem(api_cast(dprim->mem.get()))
{
    constant = true;
    recalc_output_layout(false);
}

void data_node::attach_memory(memory_impl& new_mem, bool invalidate_users_if_changed)
{
    mem = &new_mem;
    recalc_output_layout(invalidate_users_if_changed);
}

std::string data_inst::to_string(data_node const& node)
{
    auto node_info = node.desc_to_json();

    std::stringstream primitive_description;
    
Alexey Suhov's avatar
Alexey Suhov committed
66
    node_info->dump(primitive_description);
openvino-pushbot's avatar
openvino-pushbot committed
67 68 69 70 71 72 73 74 75
    return primitive_description.str();
}

data_inst::typed_primitive_inst(network_impl& network, data_node const& node)
    : parent(network, node, *attach_or_copy_data(network, node.get_attached_memory()))
{
}

}