Skip to content

Commit c63d97d

Browse files
committed
Added LIF to multithreaded cpu backend, changed namespace in lif neuron test: KasperskyLab#189
1 parent 7fe3f26 commit c63d97d

2 files changed

Lines changed: 38 additions & 37 deletions

File tree

  • knp
    • backends/cpu/cpu-multi-threaded-backend/include/knp/backends/cpu-multi-threaded
    • tests/framework

knp/backends/cpu/cpu-multi-threaded-backend/include/knp/backends/cpu-multi-threaded/backend.h

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ class KNP_DECLSPEC MultiThreadedCPUBackend : public knp::core::Backend
7777
/**
7878
* @brief List of neuron types supported by the multi-threaded CPU backend.
7979
*/
80-
using SupportedNeurons =
81-
boost::mp11::mp_list<knp::neuron_traits::BLIFATNeuron, knp::neuron_traits::SynapticResourceSTDPBLIFATNeuron>;
80+
using SupportedNeurons = boost::mp11::mp_list<
81+
knp::neuron_traits::BLIFATNeuron, knp::neuron_traits::SynapticResourceSTDPBLIFATNeuron,
82+
knp::neuron_traits::LIFNeuron>;
8283

8384
/**
8485
* @brief List of synapse types supported by the multi-threaded CPU backend.
@@ -97,25 +98,25 @@ class KNP_DECLSPEC MultiThreadedCPUBackend : public knp::core::Backend
9798
using SupportedProjections = boost::mp11::mp_transform<knp::core::Projection, SupportedSynapses>;
9899
/**
99100
* @brief Population variant that contains any population type specified in `SupportedPopulations`.
100-
*
101+
*
101102
* @details `PopulationVariants` takes the value of `std::variant<PopulationType_1,..., PopulationType_n>`, where
102103
* `PopulationType_[1..n]` is the population type specified in `SupportedPopulations`. \n
103104
* For example, if `SupportedPopulations` contains BLIFATNeuron and IzhikevichNeuron types,
104105
* then `PopulationVariants = std::variant<BLIFATNeuron, IzhikevichNeuron>`. \n
105106
* `PopulationVariants` retains the same order of message types as defined in `SupportedPopulations`.
106-
*
107+
*
107108
* @see ALL_NEURONS.
108109
*/
109110
using PopulationVariants = boost::mp11::mp_rename<SupportedPopulations, std::variant>;
110111
/**
111112
* @brief Projection variant that contains any projection type specified in `SupportedProjections`.
112-
*
113+
*
113114
* @details `ProjectionVariants` takes the value of `std::variant<ProjectionType_1,..., ProjectionType_n>`, where
114115
* `ProjectionType_[1..n]` is the projection type specified in `SupportedProjections`. \n
115116
* For example, if `SupportedProjections` contains DeltaSynapse and AdditiveSTDPSynapse types,
116117
* then `ProjectionVariants = std::variant<DeltaSynapse, AdditiveSTDPSynapse>`. \n
117118
* `ProjectionVariants` retains the same order of message types as defined in `SupportedProjections`.
118-
*
119+
*
119120
* @see ALL_SYNAPSES.
120121
*/
121122
using ProjectionVariants = boost::mp11::mp_rename<SupportedProjections, std::variant>;
@@ -149,7 +150,7 @@ class KNP_DECLSPEC MultiThreadedCPUBackend : public knp::core::Backend
149150

150151
/**
151152
* @brief Get a set of iterators for projections and populations.
152-
*
153+
*
153154
* @return `DataRanges` structure containing iterators.
154155
*/
155156
[[nodiscard]] DataRanges get_network_data() const override;
@@ -168,167 +169,167 @@ class KNP_DECLSPEC MultiThreadedCPUBackend : public knp::core::Backend
168169
public:
169170
/**
170171
* @brief Default constructor for multi-threaded CPU backend.
171-
*
172+
*
172173
* @param thread_count number of threads.
173174
* @param population_part_size number of synapses that are calculated in a single thread.
174175
* @param projection_part_size number of neurons that are calculated in a single thread.
175-
*
176+
*
176177
* @note If `thread_count` equals `0`, then the number of threads is calculated automatically.
177178
*/
178179
explicit MultiThreadedCPUBackend(
179180
size_t thread_count = 0, size_t population_part_size = default_population_part_size,
180181
size_t projection_part_size = default_projection_part_size);
181182
/**
182183
* @brief Destructor for multi-threaded CPU backend.
183-
*
184+
*
184185
* @note All threads are stopped and joined on destruction by an internal thread pool object.
185186
*/
186187
~MultiThreadedCPUBackend() override = default;
187188

188189
public:
189190
/**
190191
* @brief Create an object of the multi-threaded CPU backend.
191-
*
192+
*
192193
* @return shared pointer to backend object.
193194
*/
194195
static std::shared_ptr<MultiThreadedCPUBackend> create();
195196

196197
public:
197198
/**
198199
* @brief Define if plasticity is supported.
199-
*
200+
*
200201
* @return `true` if plasticity is supported, `false` if plasticity is not supported.
201202
*/
202203
[[nodiscard]] bool plasticity_supported() const override { return true; }
203204
/**
204205
* @brief Get type names of supported neurons.
205-
*
206+
*
206207
* @return vector of supported neuron type names.
207208
*/
208209
[[nodiscard]] std::vector<std::string> get_supported_neurons() const override;
209210
/**
210211
* @brief Get type names of supported synapses.
211-
*
212+
*
212213
* @return vector of supported synapse type names.
213214
*/
214215
[[nodiscard]] std::vector<std::string> get_supported_synapses() const override;
215216
/**
216217
* @brief Get indexes of supported projections.
217-
*
218+
*
218219
* @return vector of supported type indexes.
219220
*/
220221
[[nodiscard]] std::vector<size_t> get_supported_projection_indexes() const override;
221222
/**
222223
* @brief Get indexes of supported populations.
223-
*
224+
*
224225
* @return vector of supported type indexes.
225226
*/
226227
[[nodiscard]] std::vector<size_t> get_supported_population_indexes() const override;
227228

228229
public:
229230
/**
230231
* @brief Load populations to the backend.
231-
*
232+
*
232233
* @param populations vector of populations to load.
233234
*/
234235
void load_populations(const std::vector<PopulationVariants> &populations);
235236

236237
/**
237238
* @brief Load projections to the backend.
238-
*
239+
*
239240
* @param projections vector of projections to load.
240241
*/
241242
void load_projections(const std::vector<ProjectionVariants> &projections);
242243

243244
/**
244245
* @brief Add projections to backend.
245-
*
246+
*
246247
* @param projections projections to add.
247-
*
248+
*
248249
* @throw exception if the `projections` parameter contains unsupported projection types.
249250
*/
250251
void load_all_projections(const std::vector<knp::core::AllProjectionsVariant> &projections) override;
251252

252253
/**
253254
* @brief Add populations to backend.
254-
*
255+
*
255256
* @param populations populations to add.
256-
*
257+
*
257258
* @throw exception if the `populations` parameter contains unsupported population types.
258259
*/
259260
void load_all_populations(const std::vector<knp::core::AllPopulationsVariant> &populations) override;
260261

261262
public:
262263
/**
263264
* @brief Get an iterator pointing to the first element of the population loaded to backend.
264-
*
265+
*
265266
* @return population iterator.
266267
*/
267268
[[nodiscard]] PopulationIterator begin_populations();
268269
/**
269270
* @brief Get an iterator pointing to the first element of the population loaded to backend.
270-
*
271+
*
271272
* @return constant population iterator.
272273
*/
273274
[[nodiscard]] PopulationConstIterator begin_populations() const;
274275
/**
275276
* @brief Get an iterator pointing to the last element of the population.
276-
*
277+
*
277278
* @return iterator.
278279
*/
279280
[[nodiscard]] PopulationIterator end_populations();
280281
/**
281282
* @brief Get a constant iterator pointing to the last element of the population.
282-
*
283+
*
283284
* @return iterator.
284285
*/
285286
[[nodiscard]] PopulationConstIterator end_populations() const;
286287
/**
287288
* @brief Get an iterator pointing to the first element of the projection loaded to backend.
288-
*
289+
*
289290
* @return projection iterator.
290291
*/
291292
[[nodiscard]] ProjectionIterator begin_projections();
292293
/**
293294
* @brief Get an iterator pointing to the first element of the projection loaded to backend.
294-
*
295+
*
295296
* @return constant projection iterator.
296297
*/
297298
[[nodiscard]] ProjectionConstIterator begin_projections() const;
298299
/**
299300
* @brief Get an iterator pointing to the last element of the projection.
300-
*
301+
*
301302
* @return iterator.
302303
*/
303304
[[nodiscard]] ProjectionIterator end_projections();
304305
/**
305306
* @brief Get a constant iterator pointing to the last element of the projection.
306-
*
307+
*
307308
* @return iterator.
308309
*/
309310
[[nodiscard]] ProjectionConstIterator end_projections() const;
310311

311312
public:
312313
/**
313314
* @brief Remove projections with given UIDs from the backend.
314-
*
315+
*
315316
* @param uids UIDs of projections to remove.
316317
*/
317318
void remove_projections(const std::vector<knp::core::UID> &uids) override {}
318319

319320
/**
320321
* @brief Remove populations with given UIDs from the backend.
321-
*
322+
*
322323
* @param uids UIDs of populations to remove.
323324
*/
324325
void remove_populations(const std::vector<knp::core::UID> &uids) override {}
325326

326327
public:
327328
/**
328329
* @brief Get a list of devices supported by the backend.
329-
*
330+
*
330331
* @return list of devices.
331-
*
332+
*
332333
* @see Device.
333334
*/
334335
[[nodiscard]] std::vector<std::unique_ptr<knp::core::Device>> get_devices() const override;

knp/tests/framework/lif_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
using Synapse = knp::synapse_traits::DeltaSynapse;
3636

3737

38-
namespace knp::testing
38+
namespace
3939
{
4040

4141
class TestingBackendST : public knp::backends::single_threaded_cpu::SingleThreadedCPUBackend
@@ -62,7 +62,7 @@ NeuronLog run_lif_neuron(
6262
{
6363
const knp::core::UID pop_uid, in_uid, out_uid;
6464
knp::core::Population<knp::neuron_traits::LIFNeuron> population{pop_uid, [&neuron](size_t) { return neuron; }, 1};
65-
knp::testing::TestingBackendST backend;
65+
TestingBackendST backend;
6666
backend.subscribe<knp::core::messaging::SynapticImpactMessage>(pop_uid, {in_uid});
6767
auto endpoint = backend.get_message_bus().create_endpoint();
6868
endpoint.subscribe<knp::core::messaging::SpikeMessage>(out_uid, {pop_uid});
@@ -97,7 +97,7 @@ NeuronLog run_lif_neuron(
9797
return result;
9898
}
9999

100-
} // namespace knp::testing
100+
} //namespace
101101

102102

103103
TEST(LIFNeuron, NeuronPotentialLeakRev)

0 commit comments

Comments
 (0)