Kaspersky Neuromorphic Platform  1.0.0
API Reference
Loading...
Searching...
No Matches
init.h
Go to the documentation of this file.
1
22#pragma once
23
26#include <knp/core/projection.h>
27
28#include <spdlog/spdlog.h>
29
30#include <string>
31#include <tuple>
32#include <variant>
33
34
38namespace knp::backends::cpu
39{
40
45template <typename SynapseType>
47{
51 static void subscribe(const typename core::Projection<SynapseType> &, knp::core::MessageEndpoint &) {}
52};
53
54
60template <template <typename> typename Rule, typename SynapseType>
61struct subscribe_stdp_projection<knp::synapse_traits::STDP<Rule, SynapseType>>
62{
68 static void subscribe(
69 const typename core::Projection<knp::synapse_traits::STDP<Rule, SynapseType>> &p,
70 knp::core::MessageEndpoint &message_endpoint)
71 {
72 SPDLOG_TRACE("Subscribing method for the STDP projection {}...", std::string(p.get_uid()));
73 for (const auto &[pop_uid, _] : p.get_shared_parameters().stdp_populations_)
74 {
75 SPDLOG_TRACE("Subscribing STDP projection {} to {}...", std::string(p.get_uid()), std::string(pop_uid));
76 if (pop_uid) message_endpoint.subscribe<knp::core::messaging::SpikeMessage>(p.get_uid(), {pop_uid});
77 }
78 }
79};
80
81
88template <typename ProjectionContainer>
89void init(const ProjectionContainer &projections, knp::core::MessageEndpoint &message_endpoint)
90{
91 for (const auto &p : projections)
92 {
93 const auto [pre_uid, post_uid, this_uid] = std::visit(
94 [&message_endpoint](const auto &proj)
95 {
96 using T = std::decay_t<decltype(proj)>;
98 return std::make_tuple(proj.get_presynaptic(), proj.get_postsynaptic(), proj.get_uid());
99 },
100 p.arg_);
101
102 if (pre_uid) message_endpoint.subscribe<knp::core::messaging::SpikeMessage>(this_uid, {pre_uid});
103 if (post_uid) message_endpoint.subscribe<knp::core::messaging::SynapticImpactMessage>(post_uid, {this_uid});
104 }
105}
106
107} // namespace knp::backends::cpu
Subscription< MessageType > & subscribe(const UID &receiver, const std::vector< UID > &senders)
Add a subscription to messages of the specified type from senders with given UIDs.
Message endpoint interface.
Common header for messaging.
Namespace for CPU backends.
void init(const ProjectionContainer &projections, knp::core::MessageEndpoint &message_endpoint)
Initialize backend.
Definition init.h:89
General projection interface.
static void subscribe(const typename core::Projection< knp::synapse_traits::STDP< Rule, SynapseType > > &p, knp::core::MessageEndpoint &message_endpoint)
Subscribe projection to message endpoint.
Definition init.h:68
static void subscribe(const typename core::Projection< SynapseType > &, knp::core::MessageEndpoint &)
Subscribe STDP projection to messages.
Definition init.h:51