diff --git a/knp/backends/cpu/cpu-library/include/knp/backends/cpu-library/impl/blifat_population_impl.h b/knp/backends/cpu/cpu-library/include/knp/backends/cpu-library/impl/blifat_population_impl.h index 9cb5698f..09bedf42 100644 --- a/knp/backends/cpu/cpu-library/include/knp/backends/cpu-library/impl/blifat_population_impl.h +++ b/knp/backends/cpu/cpu-library/include/knp/backends/cpu-library/impl/blifat_population_impl.h @@ -4,18 +4,18 @@ * @kaspersky_support Artiom N. * @date 21.02.2023 * @license Apache 2.0 - * @copyright © 2024 AO Kaspersky Lab - * - * 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 + * @copyright © 2024 AO Kaspersky Lab + * + * 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. */ @@ -131,7 +131,7 @@ void process_inputs( { if (impact.synapse_type_ == synapse_traits::OutputType::EXCITATORY) { - neuron.is_being_forced_ = message.is_forcing_; + neuron.is_being_forced_ |= message.is_forcing_; } } } diff --git a/knp/backends/cpu/cpu-library/include/knp/backends/cpu-library/impl/synaptic_resource_stdp_impl.h b/knp/backends/cpu/cpu-library/include/knp/backends/cpu-library/impl/synaptic_resource_stdp_impl.h index a48c473a..96e422e2 100644 --- a/knp/backends/cpu/cpu-library/include/knp/backends/cpu-library/impl/synaptic_resource_stdp_impl.h +++ b/knp/backends/cpu/cpu-library/include/knp/backends/cpu-library/impl/synaptic_resource_stdp_impl.h @@ -4,18 +4,18 @@ * @kaspersky_support Artiom N. * @date 06.10.2023 * @license Apache 2.0 - * @copyright © 2024 AO Kaspersky Lab - * - * 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 + * @copyright © 2024 AO Kaspersky Lab + * + * 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. */ @@ -146,8 +146,8 @@ template neuron_traits::ISIPeriodType update_isi( neuron_traits::neuron_parameters> &neuron, uint64_t step) { - if (neuron - .is_being_forced_) // This neuron got a forcing spike this turn and doesn't continue its spiking sequence. + // This neuron got a forcing spike this turn and doesn't continue its spiking sequence. + if (neuron.is_being_forced_) { neuron.isi_status_ = neuron_traits::ISIPeriodType::is_forced; // Do not update last_step_. @@ -320,8 +320,8 @@ void do_dopamine_plasticity( if (step - synapse->rule_.last_spike_step_ < synapse->rule_.dopamine_plasticity_period_) { // Change synapse resource. - float d_r = neuron.dopamine_value_ * - std::min(static_cast(std::pow(2, -neuron.stability_)), 1.F) / 1000.0F; + float d_r = + neuron.dopamine_value_ * std::min(static_cast(std::pow(2, -neuron.stability_)), 1.F); synapse->rule_.synaptic_resource_ += d_r; neuron.free_synaptic_resource_ -= d_r; } diff --git a/knp/core-library/impl/messaging/fbs/synaptic_impact_message.fbs b/knp/core-library/impl/messaging/fbs/synaptic_impact_message.fbs index 7b2831ae..8eaf6e85 100644 --- a/knp/core-library/impl/messaging/fbs/synaptic_impact_message.fbs +++ b/knp/core-library/impl/messaging/fbs/synaptic_impact_message.fbs @@ -40,6 +40,7 @@ table SynapticImpactMessage header: MessageHeader; presynaptic_population_uid: UID; postsynaptic_population_uid: UID; + is_forcing: bool; impacts: [SynapticImpact]; } diff --git a/knp/core-library/impl/messaging/synaptic_impact_message.cpp b/knp/core-library/impl/messaging/synaptic_impact_message.cpp index 4afcd576..96e9f1f7 100644 --- a/knp/core-library/impl/messaging/synaptic_impact_message.cpp +++ b/knp/core-library/impl/messaging/synaptic_impact_message.cpp @@ -68,7 +68,7 @@ std::ostream &operator<<(std::ostream &stream, const SynapticImpact &impact) std::ostream &operator<<(std::ostream &stream, const SynapticImpactMessage &msg) { stream << msg.header_ << " " << msg.postsynaptic_population_uid_ << " " << msg.presynaptic_population_uid_ << " " - << msg.impacts_.size(); + << static_cast(msg.is_forcing_) << " " << msg.impacts_.size(); for (auto v : msg.impacts_) stream << " " << v; return stream; } @@ -77,8 +77,11 @@ std::ostream &operator<<(std::ostream &stream, const SynapticImpactMessage &msg) std::istream &operator>>(std::istream &stream, SynapticImpactMessage &msg) { size_t impacts_count = 0; - stream >> msg.header_ >> msg.postsynaptic_population_uid_ >> msg.presynaptic_population_uid_ >> impacts_count; + int forcing_buf; + stream >> msg.header_ >> msg.postsynaptic_population_uid_ >> msg.presynaptic_population_uid_ >> forcing_buf >> + impacts_count; + msg.is_forcing_ = forcing_buf; if (0 == impacts_count) return stream; msg.impacts_.resize(impacts_count); @@ -112,7 +115,8 @@ ::flatbuffers::uoffset_t pack_internal(::flatbuffers::FlatBufferBuilder &builder auto pre_synaptic_uid = get_marshaled_uid(msg.presynaptic_population_uid_); auto post_synaptic_uid = get_marshaled_uid(msg.postsynaptic_population_uid_); - return marshal::CreateSynapticImpactMessageDirect(builder, &header, &pre_synaptic_uid, &post_synaptic_uid, &impacts) + return marshal::CreateSynapticImpactMessageDirect( + builder, &header, &pre_synaptic_uid, &post_synaptic_uid, msg.is_forcing_, &impacts) .o; } @@ -138,7 +142,6 @@ SynapticImpactMessage unpack(const marshal::SynapticImpactMessage *s_msg) UID sender_uid{false}; UID presynaptic_uid{false}; UID postsynaptic_uid{false}; - bool is_forced = false; std::copy( s_msg_header->sender_uid().data()->begin(), // clang_sa_ignore [core.CallAndMessage] s_msg_header->sender_uid().data()->end(), // clang_sa_ignore [core.CallAndMessage] @@ -150,7 +153,6 @@ SynapticImpactMessage unpack(const marshal::SynapticImpactMessage *s_msg) std::vector impacts; impacts.reserve(s_msg->impacts()->size()); - std::transform( s_msg->impacts()->begin(), s_msg->impacts()->end(), std::back_inserter(impacts), [](const auto &msg_val) @@ -160,9 +162,9 @@ SynapticImpactMessage unpack(const marshal::SynapticImpactMessage *s_msg) msg_val->connection_index(), msg_val->impact_value(), type, msg_val->presynaptic_neuron_index(), msg_val->postsynaptic_neuron_index()}; }); - + bool is_forcing = s_msg->is_forcing(); return SynapticImpactMessage{ - {sender_uid, s_msg_header->send_time()}, presynaptic_uid, postsynaptic_uid, is_forced, std::move(impacts)}; + {sender_uid, s_msg_header->send_time()}, presynaptic_uid, postsynaptic_uid, is_forcing, std::move(impacts)}; } } // namespace knp::core::messaging diff --git a/knp/neuron-traits-library/include/knp/neuron-traits/stdp_synaptic_resource_rule.h b/knp/neuron-traits-library/include/knp/neuron-traits/stdp_synaptic_resource_rule.h index fae63f73..abfcebd4 100644 --- a/knp/neuron-traits-library/include/knp/neuron-traits/stdp_synaptic_resource_rule.h +++ b/knp/neuron-traits-library/include/knp/neuron-traits/stdp_synaptic_resource_rule.h @@ -153,7 +153,7 @@ struct neuron_parameters> : public neuron /** * @brief ISI period status. */ - ISIPeriodType isi_status_ = ISIPeriodType::period_continued; + ISIPeriodType isi_status_ = ISIPeriodType::not_in_period; /** * @brief Last non-forced spike step. diff --git a/knp/tests/core/message_bus_test.cpp b/knp/tests/core/message_bus_test.cpp index 4b09dbeb..50eae52a 100644 --- a/knp/tests/core/message_bus_test.cpp +++ b/knp/tests/core/message_bus_test.cpp @@ -122,7 +122,7 @@ TEST(MessageBusSuite, SynapticImpactMessageSendZMQ) {knp::core::UID{}}, knp::core::UID{}, knp::core::UID{}, - false, + true, {{1, 2, synapse_type, 3, 4}, {4, 3, synapse_type, 2, 1}, {7, 8, synapse_type, 9, 10}}}; auto &subscription = ep1.subscribe(knp::core::UID(), {msg.header_.sender_uid_}); @@ -138,6 +138,7 @@ TEST(MessageBusSuite, SynapticImpactMessageSendZMQ) EXPECT_EQ(msgs[0].header_.sender_uid_, msg.header_.sender_uid_); ASSERT_EQ(msgs[0].presynaptic_population_uid_, msg.presynaptic_population_uid_); ASSERT_EQ(msgs[0].postsynaptic_population_uid_, msg.postsynaptic_population_uid_); + ASSERT_EQ(msgs[0].is_forcing_, msg.is_forcing_); ASSERT_EQ(msgs[0].impacts_, msg.impacts_); } @@ -153,7 +154,7 @@ TEST(MessageBusSuite, SynapticImpactMessageSendCPU) {knp::core::UID{}}, knp::core::UID{}, knp::core::UID{}, - false, + true, {{1, 2, synapse_type, 3, 4}, {4, 3, synapse_type, 2, 1}, {7, 8, synapse_type, 9, 10}}}; auto &subscription = ep1.subscribe(knp::core::UID(), {msg.header_.sender_uid_}); @@ -169,5 +170,6 @@ TEST(MessageBusSuite, SynapticImpactMessageSendCPU) EXPECT_EQ(msgs[0].header_.sender_uid_, msg.header_.sender_uid_); ASSERT_EQ(msgs[0].presynaptic_population_uid_, msg.presynaptic_population_uid_); ASSERT_EQ(msgs[0].postsynaptic_population_uid_, msg.postsynaptic_population_uid_); + ASSERT_EQ(msgs[0].is_forcing_, msg.is_forcing_); ASSERT_EQ(msgs[0].impacts_, msg.impacts_); } diff --git a/knp/tests/core/messaging_test.cpp b/knp/tests/core/messaging_test.cpp index b12b2dfe..c54c902e 100644 --- a/knp/tests/core/messaging_test.cpp +++ b/knp/tests/core/messaging_test.cpp @@ -50,10 +50,11 @@ TEST(MessageSuite, ImpactToChannelTest) { const knp::core::UID uid{true}, pre_uid{true}, post_uid{true}; const size_t time = 7; + const bool forcing = true; const knp::synapse_traits::OutputType type = knp::synapse_traits::OutputType::DOPAMINE; const std::vector impacts{{1, 2, type, 3, 4}, {5, 6, type, 7, 8}}; - const knp::core::messaging::SynapticImpactMessage message_in{{uid, time}, pre_uid, post_uid, false, impacts}; + const knp::core::messaging::SynapticImpactMessage message_in{{uid, time}, pre_uid, post_uid, forcing, impacts}; knp::core::messaging::SynapticImpactMessage message_out; std::stringstream stream; @@ -65,6 +66,7 @@ TEST(MessageSuite, ImpactToChannelTest) ASSERT_EQ(message_out.header_.send_time_, time); ASSERT_EQ(message_out.presynaptic_population_uid_, pre_uid); ASSERT_EQ(message_out.postsynaptic_population_uid_, post_uid); + ASSERT_EQ(message_out.is_forcing_, forcing); ASSERT_EQ(message_out.impacts_, impacts); }