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 ///////////////////////////////////////////////////////////////////////////////////////////////////
20 #include "api/CPP/network.hpp"
23 #include "engine_impl.h"
24 #include "event_impl.h"
25 #include "program_impl.h"
26 #include "refcounted_obj.h"
30 #include <unordered_map>
37 struct network_impl : public refcounted_obj<network_impl>
40 network_impl(const program_impl& program, bool is_internal = false);
41 network_impl(engine_impl& engine, const topology_impl& topo, const build_options& options = build_options(), bool is_internal = false);
42 network_impl(engine_impl& engine, const std::set<std::shared_ptr<program_node>>& nodes, const build_options & options, bool is_internal);
44 const program_impl& get_program() const { return *_program; }
45 engine_impl& get_engine() const { return _program->get_engine(); }
47 void reset_execution(bool wait = true);
48 void set_input_data(const primitive_id& id, memory_impl& data);
50 void set_learning_rate(const float lr);
51 float get_learning_rate();
53 std::vector<std::shared_ptr<primitive_inst>> const& get_outputs() { return _outputs; }
55 const std::vector<std::shared_ptr<const primitive_inst>>& get_outputs() const
57 return reinterpret_cast<const std::vector<std::shared_ptr<const primitive_inst>>&>(_outputs);
60 std::vector<primitive_id> get_output_ids() const;
61 std::vector<primitive_id> get_executed_primitive_ids() const;
62 std::vector<primitive_id> get_all_primitive_ids() const;
63 std::vector<primitive_id> get_all_primitive_org_ids() const;
64 void execute(const std::vector<event_impl::ptr>& events);
65 void validate_primitives();
66 // Implementation specific calls
67 std::shared_ptr<primitive_inst> get_primitive(const primitive_id& id);
68 std::string get_primitive_info(const primitive_id& id) const;
69 const event_impl::ptr& get_primitive_event(const primitive_id& id) const { return _events.at(id); }
70 std::vector<std::shared_ptr<primitive_inst>> get_primitives(const std::vector<primitive_id>& ids);
71 std::vector<std::shared_ptr<primitive_inst>> get_primitives(const std::vector<program_node*>& nodes);
72 void execute_primitive(const std::shared_ptr<primitive_inst>& primitive, const std::vector<event_impl::ptr>& events);
73 void allocate_primitives();
74 void build_insts_deps();
75 uint32_t get_id() const { return net_id; }
76 void build_exec_order();
77 bool is_internal() const { return _internal; }
80 const program_impl::cptr _program;
82 float _learning_rate = float(0.00001);
84 std::map<primitive_id, std::shared_ptr<primitive_inst>> _primitives;
85 std::vector<std::shared_ptr<primitive_inst>> _inputs;
86 std::vector<std::shared_ptr<primitive_inst>> _outputs;
87 std::list<std::shared_ptr<primitive_inst>> _exec_order;
88 std::list<std::shared_ptr<primitive_inst>> _data_outputs;
90 std::unordered_map<primitive_id, event_impl::ptr> _events;
92 void allocate_primitive_instance(program_node const& node);
93 void add_to_exec_order(const primitive_id& id);
94 std::shared_ptr<primitive_inst> find_in_internal_networks(const primitive_id& id);
95 std::shared_ptr<primitive_inst> find_primitive(const primitive_id& id);
100 API_CAST(::cldnn_network, cldnn::network_impl)