Auryn simulator  v0.8.1-206-gb56e451
Plastic Spiking Neural Network Simulator
SyncBuffer.h
Go to the documentation of this file.
1 /*
2 * Copyright 2014-2018 Friedemann Zenke
3 *
4 * This file is part of Auryn, a simulation package for plastic
5 * spiking neural networks.
6 *
7 * Auryn is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * Auryn is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Auryn. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * If you are using Auryn or parts of it for your work please cite:
21 * Zenke, F. and Gerstner, W., 2014. Limits to high-speed simulations
22 * of spiking neural networks using general-purpose computers.
23 * Front Neuroinform 8, 76. doi: 10.3389/fninf.2014.00076
24 */
25 
26 
27 #ifndef SYNCBUFFER_H_
28 #define SYNCBUFFER_H_
29 
30 
31 #define SYNCBUFFER_SIZE_MARGIN_MULTIPLIER 5
32 #define SYNCBUFFER_SIZE_HIST_LEN 512
33 
34 
38 #define SYNCBUFFER_DELTA_DATATYPE NeuronID
39 
40 #include "auryn_definitions.h"
41 #include "SpikeDelay.h"
42 #include <vector>
43 #include <algorithm>
44 
45 #ifdef AURYN_CODE_USE_MPI
46 
47 #include <boost/mpi.hpp>
48 #include <mpi.h>
49 
50 namespace auryn {
51 
57  class SyncBuffer
58  {
59  private:
60  std::vector<NeuronID> send_buf;
61  std::vector<NeuronID> recv_buf;
62 
63  NeuronID overflow_value;
64  unsigned int overflow_counter;
65 
66  SYNCBUFFER_DELTA_DATATYPE max_delta_size;
67  SYNCBUFFER_DELTA_DATATYPE undefined_delta_size;
68 
69  unsigned int sync_counter;
70 
71  int * rank_send_sum;
72  int * rank_send_sum2;
73  int * rank_recv_count;
74  int * rank_displs;
75 
77  int max_send_size;
78 
79  mpi::communicator * mpicom;
80 
81 
82  SYNCBUFFER_DELTA_DATATYPE carry_offset;
83 
84  SYNCBUFFER_DELTA_DATATYPE * pop_delta_spikes;
85  SYNCBUFFER_DELTA_DATATYPE * last_spike_pos;
86 
88  unsigned int * pop_offsets;
89 
90  void reset_send_buffer();
91  void resize_buffers(unsigned int send_size);
92 
93  void init();
94  void free();
95 
96  void update_send_recv_counts();
97  int compute_buffer_margin(int n, int sum, int sum2);
98  int compute_buffer_size_with_margin(int n, int sum, int sum2);
99 
101  NeuronID * read_delta_spike_from_buffer(NeuronID * iter, SYNCBUFFER_DELTA_DATATYPE & delta);
102 
104  NeuronID * read_attribute_from_buffer(NeuronID * iter, AurynFloat & attrib);
105 
107  void sync_allgatherv();
108 
110  void sync_allgather();
111 
112  public:
113 
115  SyncBuffer( mpi::communicator * com );
116 
118  virtual ~SyncBuffer( );
119 
121  void sync();
122 
124  void push(SpikeDelay * delay, const NeuronID size);
125 
128 
130  void pop(SpikeDelay * delay, const NeuronID size);
131 
134 
136  unsigned int get_sync_count();
137 
139  unsigned int get_overflow_count();
140 
141 #ifdef CODE_COLLECT_SYNC_TIMING_STATS
142  AurynDouble deltaT;
143  AurynDouble measurement_start;
144  AurynDouble get_relative_sync_time();
145  AurynDouble get_sync_time();
146  AurynDouble get_elapsed_wall_time();
147  void reset_sync_time();
148 #endif
149  };
150 }
151 
152 #endif // AURYN_CODE_USE_MPI
153 
154 #endif /*SYNCBUFFER_H_*/
155 
void push(SpikeDelay *delay, const NeuronID size)
Pushes a spike delay with all its spikes to the SyncBuffer.
Definition: SyncBuffer.cpp:101
double AurynDouble
Higher precision floating point datatype.
Definition: auryn_definitions.h:158
Delay object for spikes which is synchronized between nodes using the SyncBuffer formalism implemente...
Definition: SpikeDelay.h:47
int n
Definition: mkpat.py:5
Definition: ABSConnection.h:38
void sync()
Synchronize spikes and additional information across ranks.
Definition: SyncBuffer.cpp:500
unsigned int get_sync_count()
Return sync count since object instantiation.
Definition: SyncBuffer.cpp:541
void pop(SpikeDelay *delay, const NeuronID size)
Rerieves a spike delay with all its spikes from the SyncBuffer.
Definition: SyncBuffer.cpp:185
float AurynFloat
Low precision floating point datatype.
Definition: auryn_definitions.h:157
SyncBuffer(mpi::communicator *com)
The default contructor.
Definition: SyncBuffer.cpp:32
unsigned int get_overflow_count()
Return overflow count since object instantiation.
Definition: SyncBuffer.cpp:536
Buffer object to capsulate native MPI_Allgather for SpikingGroups.
Definition: SyncBuffer.h:57
void null_terminate_send_buffer()
Terminate send buffer.
Definition: SyncBuffer.cpp:154
#define SYNCBUFFER_DELTA_DATATYPE
Datatype used for delta computation should be a "long" for large nets with sparse activity otherwise ...
Definition: SyncBuffer.h:38
virtual ~SyncBuffer()
The default destructor.
Definition: SyncBuffer.cpp:38
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
int get_max_send_buffer_size()
Return max_send_size value which determines the size of the MPI AllGather operation.
Definition: SyncBuffer.cpp:531