Kaspersky Neuromorphic Platform  1.0.0
API Reference
Loading...
Searching...
No Matches
model_loader.h
Go to the documentation of this file.
1
22#pragma once
23
24#include <knp/core/impexp.h>
26#include <knp/framework/model.h>
28
29#include <filesystem>
30#include <functional>
31#include <memory>
32#include <unordered_map>
33#include <utility>
34#include <vector>
35
36
40namespace knp::framework
41{
45class KNP_DECLSPEC ModelLoader
46{
47public:
51 using InputChannelMap = std::unordered_map<core::UID, io::input::DataGenerator, core::uid_hash>;
52
53public:
59 ModelLoader(std::shared_ptr<core::Backend> backend, InputChannelMap i_map)
60 : backend_(backend), i_map_(std::move(i_map))
61 {
62 }
63
67 ModelLoader(const ModelLoader &) = delete;
71 ModelLoader operator=(const ModelLoader &) = delete;
72
73public:
78 void load(knp::framework::Model &model);
79
80public:
87 io::output::OutputChannel &get_output_channel(const core::UID &channel_uid);
95 const io::output::OutputChannel &get_output_channel(const core::UID &channel_uid) const;
96
103 io::input::InputChannel &get_input_channel(const core::UID &channel_uid);
111 const io::input::InputChannel &get_input_channel(const core::UID &channel_uid) const;
112
117 auto &get_inputs() noexcept { return in_channels_; }
118
123 auto &get_outputs() noexcept { return out_channels_; }
124
129 std::shared_ptr<core::Backend> get_backend() { return backend_; }
130
131private:
132 template <typename GenType>
133 void init_channels(
134 knp::framework::Model &model, const std::unordered_multimap<core::UID, core::UID, core::uid_hash> &channels,
135 GenType channel_gen);
136
137 void gen_input_channel(knp::framework::Model &model, const core::UID &, const std::vector<core::UID> &);
138 void gen_output_channel(knp::framework::Model &model, const core::UID &, const std::vector<core::UID> &);
139
140private:
141 knp::core::BaseData base_;
142 std::shared_ptr<core::Backend> backend_;
143
144 InputChannelMap i_map_;
145 // cppcheck-suppress unusedStructMember
146 std::vector<knp::framework::io::input::InputChannel> in_channels_;
147 // cppcheck-suppress unusedStructMember
148 std::vector<knp::framework::io::output::OutputChannel> out_channels_;
149};
150} // namespace knp::framework
The ModelLoader class is a definition of a loader that uploads the model to the specified backend.
const io::input::InputChannel & get_input_channel(const core::UID &channel_uid) const
Get reference to input channel by its UID.
io::input::InputChannel & get_input_channel(const core::UID &channel_uid)
Get reference to input channel by its UID.
void load(knp::framework::Model &model)
Write model to backend.
auto & get_inputs() noexcept
Get input channels.
const io::output::OutputChannel & get_output_channel(const core::UID &channel_uid) const
Get reference to output channel.
std::shared_ptr< core::Backend > get_backend()
Get pointer to backend object.
ModelLoader operator=(const ModelLoader &)=delete
Avoid copy assignment of ModelLoader.
auto & get_outputs() noexcept
Get output channels.
io::output::OutputChannel & get_output_channel(const core::UID &channel_uid)
Get reference to output channel.
ModelLoader(std::shared_ptr< core::Backend > backend, InputChannelMap i_map)
Model loader constructor.
ModelLoader(const ModelLoader &)=delete
Avoid copy of ModelLoader.
Header for input converter.
Model interface.
Framework namespace.
Observer class that unloads messages and stores them.