GeNN  4.9.0
GPU enhanced Neuronal Networks (GeNN)
neuronGroup.h
Go to the documentation of this file.
1 #pragma once
2 
3 // Standard includes
4 #include <map>
5 #include <set>
6 #include <string>
7 #include <vector>
8 
9 // GeNN includes
10 #include "gennExport.h"
11 #include "neuronModels.h"
12 #include "variableMode.h"
13 
14 // Forward declarations
17 
18 //------------------------------------------------------------------------
19 // NeuronGroup
20 //------------------------------------------------------------------------
22 {
23 public:
24  //------------------------------------------------------------------------
25  // SpikeEventThreshold
26  //------------------------------------------------------------------------
29  {
30  SpikeEventThreshold(const std::string &e, const std::string &s, bool egp, SynapseGroupInternal *sg)
31  : eventThresholdCode(e), supportCode(s), synapseStateInThresholdCode(egp), synapseGroup(sg)
32  {
33  }
34 
35  const std::string eventThresholdCode;
36  const std::string supportCode;
39 
43  bool operator < (const SpikeEventThreshold &other) const
44  {
45  if(other.eventThresholdCode < eventThresholdCode) {
46  return false;
47  }
48  else if(eventThresholdCode < other.eventThresholdCode) {
49  return true;
50  }
51 
52  if(other.supportCode < supportCode) {
53  return false;
54  }
55  else if(supportCode < other.supportCode) {
56  return true;
57  }
58 
59  if(synapseStateInThresholdCode) {
60  if(other.synapseGroup < synapseGroup) {
61  return false;
62  }
63  else if(synapseGroup < other.synapseGroup) {
64  return true;
65  }
66  }
67 
68  return false;
69  }
70 
74  bool operator == (const SpikeEventThreshold &other) const
75  {
76  return ((eventThresholdCode == other.eventThresholdCode)
77  && (supportCode == other.supportCode));
78  }
79  };
80 
81  NeuronGroup(const NeuronGroup&) = delete;
82  NeuronGroup() = delete;
83 
84  //------------------------------------------------------------------------
85  // Public methods
86  //------------------------------------------------------------------------
88 
89  void setSpikeLocation(VarLocation loc) { m_SpikeLocation = loc; }
90 
92 
93  void setSpikeEventLocation(VarLocation loc) { m_SpikeEventLocation = loc; }
94 
96 
97  void setSpikeTimeLocation(VarLocation loc) { m_SpikeTimeLocation = loc; }
98 
100 
101  void setPrevSpikeTimeLocation(VarLocation loc) { m_PrevSpikeTimeLocation = loc; }
102 
104 
105  void setSpikeEventTimeLocation(VarLocation loc) { m_SpikeEventTimeLocation = loc; }
106 
108 
109  void setPrevSpikeEventTimeLocation(VarLocation loc) { m_PrevSpikeEventTimeLocation = loc; }
110 
112 
113  void setVarLocation(const std::string &varName, VarLocation loc);
114 
116 
118  void setExtraGlobalParamLocation(const std::string &paramName, VarLocation loc);
119 
121  void setSpikeRecordingEnabled(bool enabled) { m_SpikeRecordingEnabled = enabled; }
122 
124  void setSpikeEventRecordingEnabled(bool enabled) { m_SpikeEventRecordingEnabled = enabled; }
125 
126  //------------------------------------------------------------------------
127  // Public const methods
128  //------------------------------------------------------------------------
129  const std::string &getName() const{ return m_Name; }
130 
132  unsigned int getNumNeurons() const{ return m_NumNeurons; }
133 
135  const NeuronModels::Base *getNeuronModel() const{ return m_NeuronModel; }
136 
137  const std::vector<double> &getParams() const{ return m_Params; }
138  const std::vector<Models::VarInit> &getVarInitialisers() const{ return m_VarInitialisers; }
139 
140  bool isSpikeTimeRequired() const;
141  bool isPrevSpikeTimeRequired() const;
142  bool isSpikeEventTimeRequired() const;
143  bool isPrevSpikeEventTimeRequired() const;
144  bool isTrueSpikeRequired() const;
145  bool isSpikeEventRequired() const;
146 
147  unsigned int getNumDelaySlots() const{ return m_NumDelaySlots; }
148  bool isDelayRequired() const{ return (m_NumDelaySlots > 1); }
149  bool isZeroCopyEnabled() const;
150 
152  VarLocation getSpikeLocation() const{ return m_SpikeLocation; }
153 
155  VarLocation getSpikeEventLocation() const{ return m_SpikeEventLocation; }
156 
158  VarLocation getSpikeTimeLocation() const{ return m_SpikeTimeLocation; }
159 
161  VarLocation getPrevSpikeTimeLocation() const { return m_PrevSpikeTimeLocation; }
162 
164  VarLocation getSpikeEventTimeLocation() const { return m_SpikeEventTimeLocation; }
165 
167  VarLocation getPrevSpikeEventTimeLocation() const { return m_PrevSpikeEventTimeLocation; }
168 
170  VarLocation getVarLocation(const std::string &varName) const;
171 
173  VarLocation getVarLocation(size_t index) const{ return m_VarLocation.at(index); }
174 
176 
177  VarLocation getExtraGlobalParamLocation(const std::string &paramName) const;
178 
180 
181  VarLocation getExtraGlobalParamLocation(size_t index) const{ return m_ExtraGlobalParamLocation.at(index); }
182 
184  bool isSpikeRecordingEnabled() const { return m_SpikeRecordingEnabled; }
185 
187  bool isSpikeEventRecordingEnabled() const { return m_SpikeEventRecordingEnabled; }
188 
190  bool isSimRNGRequired() const;
191 
193  bool isInitRNGRequired() const;
194 
196  bool isRecordingEnabled() const;
197 
198 protected:
199  NeuronGroup(const std::string &name, int numNeurons, const NeuronModels::Base *neuronModel,
200  const std::vector<double> &params, const std::vector<Models::VarInit> &varInitialisers,
201  VarLocation defaultVarLocation, VarLocation defaultExtraGlobalParamLocation);
202 
203  //------------------------------------------------------------------------
204  // Protected methods
205  //------------------------------------------------------------------------
207  void checkNumDelaySlots(unsigned int requiredDelay);
208 
210  void updatePreVarQueues(const std::string &code);
211 
213  void updatePostVarQueues(const std::string &code);
214 
215  void addSpkEventCondition(const std::string &code, SynapseGroupInternal *synapseGroup);
216 
217  void addInSyn(SynapseGroupInternal *synapseGroup){ m_InSyn.push_back(synapseGroup); }
218  void addOutSyn(SynapseGroupInternal *synapseGroup){ m_OutSyn.push_back(synapseGroup); }
219 
220  void initDerivedParams(double dt);
221 
223  void fusePrePostSynapses(bool fusePSM, bool fusePrePostWUM);
224 
226  void injectCurrent(CurrentSourceInternal *source);
227 
228  //------------------------------------------------------------------------
229  // Protected const methods
230  //------------------------------------------------------------------------
232  const std::vector<SynapseGroupInternal*> &getInSyn() const{ return m_InSyn; }
233  const std::vector<SynapseGroupInternal*> &getFusedPSMInSyn() const{ return m_FusedPSMInSyn; }
234  const std::vector<SynapseGroupInternal *> &getFusedWUPostInSyn() const { return m_FusedWUPostInSyn; }
235 
237  const std::vector<SynapseGroupInternal*> &getOutSyn() const{ return m_OutSyn; }
238  const std::vector<SynapseGroupInternal *> &getFusedWUPreOutSyn() const { return m_FusedWUPreOutSyn; }
239 
240  const std::vector<SynapseGroupInternal *> &getFusedPreOutputOutSyn() const { return m_FusedPreOutputOutSyn; }
241 
243  const std::vector<CurrentSourceInternal*> &getCurrentSources() const { return m_CurrentSources; }
244 
245  const std::vector<double> &getDerivedParams() const{ return m_DerivedParams; }
246 
247  const std::set<SpikeEventThreshold> &getSpikeEventCondition() const{ return m_SpikeEventCondition; }
248 
250  std::vector<SynapseGroupInternal*> getFusedInSynWithPostCode() const;
251 
253  std::vector<SynapseGroupInternal*> getFusedOutSynWithPreCode() const;
254 
256  std::vector<SynapseGroupInternal *> getFusedInSynWithPostVars() const;
257 
259  std::vector<SynapseGroupInternal *> getFusedOutSynWithPreVars() const;
260 
261  bool isVarQueueRequired(const std::string &var) const;
262  bool isVarQueueRequired(size_t index) const{ return m_VarQueueRequired[index]; }
263 
265 
266  boost::uuids::detail::sha1::digest_type getHashDigest() const;
267 
269 
270  boost::uuids::detail::sha1::digest_type getInitHashDigest() const;
271 
272  boost::uuids::detail::sha1::digest_type getSpikeQueueUpdateHashDigest() const;
273 
274  boost::uuids::detail::sha1::digest_type getPrevSpikeTimeUpdateHashDigest() const;
275 
276  boost::uuids::detail::sha1::digest_type getVarLocationHashDigest() const;
277 
278 private:
279  //------------------------------------------------------------------------
280  // Private methods
281  //------------------------------------------------------------------------
283  void updateVarQueues(const std::string &code, const std::string &suffix);
284 
285  //------------------------------------------------------------------------
286  // Members
287  //------------------------------------------------------------------------
288  const std::string m_Name;
289 
290  const unsigned int m_NumNeurons;
291 
292  const NeuronModels::Base *m_NeuronModel;
293  const std::vector<double> m_Params;
294  std::vector<double> m_DerivedParams;
295  std::vector<Models::VarInit> m_VarInitialisers;
296  std::vector<SynapseGroupInternal*> m_InSyn;
297  std::vector<SynapseGroupInternal*> m_OutSyn;
298  std::vector<SynapseGroupInternal*> m_FusedPSMInSyn;
299  std::vector<SynapseGroupInternal *> m_FusedWUPostInSyn;
300  std::vector<SynapseGroupInternal *> m_FusedWUPreOutSyn;
301  std::vector<SynapseGroupInternal *> m_FusedPreOutputOutSyn;
302  std::set<SpikeEventThreshold> m_SpikeEventCondition;
303  unsigned int m_NumDelaySlots;
304  std::vector<CurrentSourceInternal*> m_CurrentSources;
305 
307  std::vector<bool> m_VarQueueRequired;
308 
310  VarLocation m_SpikeLocation;
311 
313  VarLocation m_SpikeEventLocation;
314 
316  VarLocation m_SpikeTimeLocation;
317 
319  VarLocation m_PrevSpikeTimeLocation;
320 
322  VarLocation m_SpikeEventTimeLocation;
323 
325  VarLocation m_PrevSpikeEventTimeLocation;
326 
328  std::vector<VarLocation> m_VarLocation;
329 
331  std::vector<VarLocation> m_ExtraGlobalParamLocation;
332 
334  bool m_SpikeRecordingEnabled;
335 
337  bool m_SpikeEventRecordingEnabled;
338 };
Definition: neuronGroup.h:21
const std::vector< SynapseGroupInternal * > & getFusedWUPreOutSyn() const
Definition: neuronGroup.h:238
SpikeEventThreshold(const std::string &e, const std::string &s, bool egp, SynapseGroupInternal *sg)
Definition: neuronGroup.h:30
const bool synapseStateInThresholdCode
Definition: neuronGroup.h:37
bool isDelayRequired() const
Definition: neuronGroup.h:148
VarLocation
< Flags defining which memory space variables should be allocated in
Definition: variableMode.h:10
bool isSpikeRecordingEnabled() const
Is spike recording enabled for this population?
Definition: neuronGroup.h:184
unsigned int getNumNeurons() const
Gets number of neurons in group.
Definition: neuronGroup.h:132
void setSpikeLocation(VarLocation loc)
Set location of this neuron group&#39;s output spikes.
Definition: neuronGroup.h:89
const std::vector< SynapseGroupInternal * > & getFusedPreOutputOutSyn() const
Definition: neuronGroup.h:240
const std::vector< CurrentSourceInternal * > & getCurrentSources() const
Gets pointers to all current sources which provide input to this neuron group.
Definition: neuronGroup.h:243
#define GENN_EXPORT
Definition: gennExport.h:13
unsigned int getNumDelaySlots() const
Definition: neuronGroup.h:147
VarLocation getPrevSpikeEventTimeLocation() const
Get location of this neuron group&#39;s previous output spike-like-event times.
Definition: neuronGroup.h:167
VarLocation getExtraGlobalParamLocation(size_t index) const
Get location of neuron model extra global parameter by omdex.
Definition: neuronGroup.h:181
VarLocation getSpikeLocation() const
Get location of this neuron group&#39;s output spikes.
Definition: neuronGroup.h:152
void setSpikeTimeLocation(VarLocation loc)
Set location of this neuron group&#39;s output spike times.
Definition: neuronGroup.h:97
Structure used for storing spike event data.
Definition: neuronGroup.h:28
Definition: synapseGroupInternal.h:9
bool isVarQueueRequired(size_t index) const
Definition: neuronGroup.h:262
void setSpikeEventRecordingEnabled(bool enabled)
Enables and disable spike event recording for this population.
Definition: neuronGroup.h:124
const NeuronModels::Base * getNeuronModel() const
Gets the neuron model used by this group.
Definition: neuronGroup.h:135
SynapseGroupInternal * synapseGroup
Definition: neuronGroup.h:38
const std::vector< SynapseGroupInternal * > & getOutSyn() const
Gets pointers to all synapse groups emanating from this neuron group.
Definition: neuronGroup.h:237
void setSpikeRecordingEnabled(bool enabled)
Enables and disable spike recording for this population.
Definition: neuronGroup.h:121
const std::vector< SynapseGroupInternal * > & getFusedPSMInSyn() const
Definition: neuronGroup.h:233
const std::vector< double > & getParams() const
Definition: neuronGroup.h:137
bool isSpikeEventRecordingEnabled() const
Is spike event recording enabled for this population?
Definition: neuronGroup.h:187
const std::string supportCode
Definition: neuronGroup.h:36
const std::vector< SynapseGroupInternal * > & getFusedWUPostInSyn() const
Definition: neuronGroup.h:234
VarLocation getVarLocation(size_t index) const
Get location of neuron model state variable by index.
Definition: neuronGroup.h:173
VarLocation getSpikeTimeLocation() const
Get location of this neuron group&#39;s output spike times.
Definition: neuronGroup.h:158
void addOutSyn(SynapseGroupInternal *synapseGroup)
Definition: neuronGroup.h:218
VarLocation getPrevSpikeTimeLocation() const
Get location of this neuron group&#39;s previous output spike times.
Definition: neuronGroup.h:161
const std::string eventThresholdCode
Definition: neuronGroup.h:35
void setPrevSpikeTimeLocation(VarLocation loc)
Set location of this neuron group&#39;s previous output spike times.
Definition: neuronGroup.h:101
const std::vector< Models::VarInit > & getVarInitialisers() const
Definition: neuronGroup.h:138
const std::string & getName() const
Definition: neuronGroup.h:129
const std::vector< double > & getDerivedParams() const
Definition: neuronGroup.h:245
Base class for all neuron models.
Definition: neuronModels.h:32
const std::set< SpikeEventThreshold > & getSpikeEventCondition() const
Definition: neuronGroup.h:247
const std::vector< SynapseGroupInternal * > & getInSyn() const
Gets pointers to all synapse groups which provide input to this neuron group.
Definition: neuronGroup.h:232
void setSpikeEventLocation(VarLocation loc)
Set location of this neuron group&#39;s output spike events.
Definition: neuronGroup.h:93
void setSpikeEventTimeLocation(VarLocation loc)
Set location of this neuron group&#39;s output spike-like-event times.
Definition: neuronGroup.h:105
void addInSyn(SynapseGroupInternal *synapseGroup)
Definition: neuronGroup.h:217
VarLocation getSpikeEventTimeLocation() const
Get location of this neuron group&#39;s output spike-like-event times.
Definition: neuronGroup.h:164
VarLocation getSpikeEventLocation() const
Get location of this neuron group&#39;s output spike events.
Definition: neuronGroup.h:155
Definition: currentSourceInternal.h:9
void setPrevSpikeEventTimeLocation(VarLocation loc)
Set location of this neuron group&#39;s previous output spike-like-event times.
Definition: neuronGroup.h:109