2828
2929#include < spdlog/spdlog.h>
3030
31+ #include < algorithm>
3132#include < unordered_map>
3233#include < utility>
3334#include < vector>
@@ -152,11 +153,12 @@ constexpr bool is_additive_stdp_synapse()
152153
153154
154155template <class DeltaLikeSynapse >
155- void register_additive_stdp_spikes (
156+ void register_additive_stdp_spikes_part (
156157 knp::core::Projection<knp::synapse_traits::STDP<knp::synapse_traits::STDPAdditiveRule, DeltaLikeSynapse>>
157158 &projection,
158- std::vector<SpikeMessage> &all_messages)
159+ std::vector<SpikeMessage> &all_messages, uint64_t part_start, uint64_t part_end )
159160{
161+ if (part_start != 0 ) return ; // Not much sense to parallelize this by projection, so it's calculated just once.
160162 SPDLOG_DEBUG (" Calculating additive STDP delta synapse projection..." );
161163
162164 using ProjectionType = typename std::decay_t <decltype (projection)>;
@@ -209,13 +211,15 @@ void register_additive_stdp_spikes(
209211
210212
211213template <class DeltaLikeSynapse >
212- void update_projection_weights_additive_stdp (
214+ void update_projection_weights_additive_stdp_part (
213215 knp::core::Projection<knp::synapse_traits::STDP<knp::synapse_traits::STDPAdditiveRule, DeltaLikeSynapse>>
214- &projection)
216+ &projection,
217+ uint64_t part_start, uint64_t part_end)
215218{
216219 // Update projection parameters.
217- for (auto &proj : projection)
220+ for (uint64_t i = part_start; i < std::min ( projection. size (), part_end); ++i )
218221 {
222+ auto &proj = projection[i];
219223 SPDLOG_TRACE (" Applying STDP rule..." );
220224 auto &rule = std::get<knp::core::synapse_data>(proj).rule_ ;
221225 const auto period = rule.tau_plus_ + rule.tau_minus_ ;
@@ -238,19 +242,32 @@ template <class DeltaLikeSynapse>
238242struct WeightUpdateSTDP <synapse_traits::STDP<synapse_traits::STDPAdditiveRule, DeltaLikeSynapse>>
239243{
240244 using Synapse = synapse_traits::STDP<synapse_traits::STDPAdditiveRule, DeltaLikeSynapse>;
241- static void init_projection (
242- knp::core::Projection<Synapse> &projection, std::vector<SpikeMessage> &all_messages, knp::core::Step step)
245+
246+ static void init_projection_part (
247+ knp::core::Projection<Synapse> &projection, std::vector<SpikeMessage> &all_messages, knp::core::Step step,
248+ uint64_t part_start, uint64_t part_end)
243249 {
244- register_additive_stdp_spikes (projection, all_messages);
250+ register_additive_stdp_spikes_part (projection, all_messages, part_start, part_end );
245251 }
246252
247253 static void init_synapse (const knp::synapse_traits::synapse_parameters<Synapse> &projection, knp::core::Step step)
248254 {
249255 }
250256
257+ static void modify_weights_part (knp::core::Projection<Synapse> &projection, uint64_t part_start, uint64_t part_end)
258+ {
259+ update_projection_weights_additive_stdp_part (projection, part_start, part_end);
260+ }
261+
262+ static void init_projection (
263+ knp::core::Projection<Synapse> &projection, std::vector<SpikeMessage> &all_messages, knp::core::Step step)
264+ {
265+ init_projection_part (projection, all_messages, step, 0 , projection.size ());
266+ }
267+
251268 static void modify_weights (knp::core::Projection<Synapse> &projection)
252269 {
253- update_projection_weights_additive_stdp (projection);
270+ modify_weights_part (projection, 0 , projection. size () );
254271 }
255272};
256273
0 commit comments