forked from UWB-Biocomputing/BrainGrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAllSpikingNeurons.h
228 lines (200 loc) · 8.34 KB
/
AllSpikingNeurons.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/**
* @file AllSpikingNeurons.h
*
* @brief A container of all spiking neuron data
*/
/**
** @class AllSpikingNeurons AllSpikingNeurons.h "AllSpikingNeurons.h"
**
** \latexonly \subsubsection*{Implementation} \endlatexonly
** \htmlonly <h3>Implementation</h3> \endhtmlonly
**
** A container of all spiking neuron data.
** This is the base class of all spiking neuron classes.
**
** The class uses a data-centric structure, which utilizes a structure as the containers of
** all neuron.
**
** The container holds neuron parameters of all neurons.
** Each kind of neuron parameter is stored in a 1D array, of which length
** is number of all neurons. Each array of a neuron parameter is pointed by a
** corresponding member variable of the neuron parameter in the class.
**
** This structure was originally designed for the GPU implementation of the
** simulator, and this refactored version of the simulator simply uses that design for
** all other implementations as well. This is to simplify transitioning from
** single-threaded to multi-threaded.
**
** \latexonly \subsubsection*{Credits} \endlatexonly
** \htmlonly <h3>Credits</h3> \endhtmlonly
**
** Some models in this simulator is a rewrite of CSIM (2006) and other
** work (Stiber and Kawasaki (2007?))
**
**/
#pragma once
using namespace std;
#include "Global.h"
#include "SimulationInfo.h"
#include "AllNeurons.h"
#include "AllSpikingSynapses.h"
class AllSpikingNeurons : public AllNeurons
{
public:
AllSpikingNeurons();
virtual ~AllSpikingNeurons();
/**
* Setup the internal structure of the class.
* Allocate memories to store all neurons' state.
*
* @param sim_info SimulationInfo class to read information from.
*/
virtual void setupNeurons(SimulationInfo *sim_info);
/**
* Cleanup the class.
* Deallocate memories.
*/
virtual void cleanupNeurons();
/**
* Clear the spike counts out of all Neurons.
*
* @param sim_info SimulationInfo class to read information from.
*/
void clearSpikeCounts(const SimulationInfo *sim_info);
#if defined(USE_GPU)
public:
/**
* Set some parameters used for advanceNeuronsDevice.
* Currently we set the two member variables: m_fpPreSpikeHit_h and m_fpPostSpikeHit_h.
* These are function pointers for PreSpikeHit and PostSpikeHit device functions
* respectively, and these functions are called from advanceNeuronsDevice device
* function. We use this scheme because we cannot not use virtual function (Polymorphism)
* in device functions.
*
* @param synapses Reference to the allSynapses struct on host memory.
*/
virtual void setAdvanceNeuronsDeviceParams(IAllSynapses &synapses);
/**
* Copy spike counts data stored in device memory to host.
*
* @param allNeuronsDevice Reference to the allNeurons struct on device memory.
* @param sim_info SimulationInfo to refer from.
*/
virtual void copyNeuronDeviceSpikeCountsToHost( void* allNeuronsDevice, const SimulationInfo *sim_info ) = 0;
/**
* Copy spike history data stored in device memory to host.
*
* @param allNeuronsDevice Reference to the allNeurons struct on device memory.
* @param sim_info SimulationInfo to refer from.
*/
virtual void copyNeuronDeviceSpikeHistoryToHost( void* allNeuronsDevice, const SimulationInfo *sim_info ) = 0;
/**
* Clear the spike counts out of all neurons.
*
* @param allNeuronsDevice Reference to the allNeurons struct on device memory.
* @param sim_info SimulationInfo to refer from.
*/
virtual void clearNeuronSpikeCounts( void* allNeuronsDevice, const SimulationInfo *sim_info ) = 0;
protected:
/**
* Copy spike history data stored in device memory to host.
* (Helper function of copyNeuronDeviceSpikeHistoryToHost)
*
* @param allNeurons Reference to the allNeurons struct.
* @param sim_info SimulationInfo to refer from.
*/
void copyDeviceSpikeHistoryToHost( AllSpikingNeurons& allNeurons, const SimulationInfo *sim_info );
/**
* Copy spike counts data stored in device memory to host.
* (Helper function of copyNeuronDeviceSpikeCountsToHost)
*
* @param allNeurons Reference to the allNeurons struct.
* @param sim_info SimulationInfo to refer from.
*/
void copyDeviceSpikeCountsToHost( AllSpikingNeurons& allNeurons, const SimulationInfo *sim_info );
/**
* Clear the spike counts out of all neurons in device memory.
* (helper function of clearNeuronSpikeCounts)
*
* @param allNeurons Reference to the allNeurons struct.
* @param sim_info SimulationInfo to refer from.
*/
void clearDeviceSpikeCounts( AllSpikingNeurons& allNeurons, const SimulationInfo *sim_info );
#else // !defined(USE_GPU)
public:
/**
* Update internal state of the indexed Neuron (called by every simulation step).
* Notify outgoing synapses if neuron has fired.
*
* @param synapses The Synapse list to search from.
* @param sim_info SimulationInfo class to read information from.
* @param synapseIndexMap Reference to the SynapseIndexMap.
*/
virtual void advanceNeurons(IAllSynapses &synapses, const SimulationInfo *sim_info, const SynapseIndexMap *synapseIndexMap);
/**
* Get the spike history of neuron[index] at the location offIndex.
*
* @param index Index of the neuron to get spike history.
* @param offIndex Offset of the history buffer to get from.
* @param sim_info SimulationInfo class to read information from.
*/
uint64_t getSpikeHistory(int index, int offIndex, const SimulationInfo *sim_info);
protected:
/**
* Helper for #advanceNeuron. Updates state of a single neuron.
*
* @param index Index of the neuron to update.
* @param sim_info SimulationInfo class to read information from.
*/
virtual void advanceNeuron(const int index, const SimulationInfo *sim_info) = 0;
/**
* Initiates a firing of a neuron to connected neurons
*
* @param index Index of the neuron to fire.
* @param sim_info SimulationInfo class to read information from.
*/
virtual void fire(const int index, const SimulationInfo *sim_info) const;
#endif // defined(USE_GPU)
private:
/**
* Deallocate all resources
*/
void freeResources();
public:
/**
* The booleans which track whether the neuron has fired.
*/
bool *hasFired;
/**
* The number of spikes since the last growth cycle.
*/
int *spikeCount;
/**
* Offset of the spike_history buffer.
*/
int *spikeCountOffset;
/**
* Step count (history) for each spike fired by each neuron.
* The step counts are stored in a buffer for each neuron, and the pointers
* to the buffer are stored in a list pointed by spike_history.
* Each buffer is a circular, and offset of top location of the buffer i is
* specified by spikeCountOffset[i].
*/
uint64_t **spike_history;
protected:
/**
* True if back propagaion is allowed.
* (parameters used for advanceNeuronsDevice.)
*/
bool m_fAllowBackPropagation;
/**
* Pointer to the device function preSpikeHit() function.
* (parameters used for advanceNeuronsDevice.)
*/
fpPreSynapsesSpikeHit_t m_fpPreSpikeHit_h;
/**
* Pointer o the device function postSpikeHit().
* (parameters used for advanceNeuronsDevice.)
*/
fpPostSynapsesSpikeHit_t m_fpPostSpikeHit_h;
};