GeNN  3.3.0
GPU enhanced Neuronal Networks (GeNN)
synapseGroup.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
11 #include "neuronGroup.h"
12 #include "newPostsynapticModels.h"
13 #include "newWeightUpdateModels.h"
14 #include "synapseMatrixType.h"
15 
16 //------------------------------------------------------------------------
17 // SynapseGroup
18 //------------------------------------------------------------------------
20 {
21 public:
22  SynapseGroup(const std::string name, SynapseMatrixType matrixType, unsigned int delaySteps,
23  const WeightUpdateModels::Base *wu, const std::vector<double> &wuParams, const std::vector<NewModels::VarInit> &wuVarInitialisers, const std::vector<NewModels::VarInit> &wuPreVarInitialisers, const std::vector<NewModels::VarInit> &wuPostVarInitialisers,
24  const PostsynapticModels::Base *ps, const std::vector<double> &psParams, const std::vector<NewModels::VarInit> &psVarInitialisers,
25  NeuronGroup *srcNeuronGroup, NeuronGroup *trgNeuronGroup,
26  const InitSparseConnectivitySnippet::Init &connectivityInitialiser);
27  SynapseGroup(const SynapseGroup&) = delete;
28  SynapseGroup() = delete;
29 
30  //------------------------------------------------------------------------
31  // Enumerations
32  //------------------------------------------------------------------------
33  enum class SpanType
34  {
37  };
38 
39  //------------------------------------------------------------------------
40  // Public methods
41  //------------------------------------------------------------------------
42  NeuronGroup *getSrcNeuronGroup(){ return m_SrcNeuronGroup; }
43  NeuronGroup *getTrgNeuronGroup(){ return m_TrgNeuronGroup; }
44 
45  void setTrueSpikeRequired(bool req){ m_TrueSpikeRequired = req; }
46  void setSpikeEventRequired(bool req){ m_SpikeEventRequired = req; }
47  void setEventThresholdReTestRequired(bool req){ m_EventThresholdReTestRequired = req; }
48 
49  void setPSModelMergeTarget(const std::string &targetName)
50  {
51  m_PSModelTargetName = targetName;
52  }
53 
55 
56  void setWUVarZeroCopyEnabled(const std::string &varName, bool enabled)
57  {
59  }
60 
62 
63  void setPSVarZeroCopyEnabled(const std::string &varName, bool enabled)
64  {
66  }
67 
69 
70  void setWUVarMode(const std::string &varName, VarMode mode);
71 
73 
74  void setWUPreVarMode(const std::string &varName, VarMode mode);
75 
77 
78  void setWUPostVarMode(const std::string &varName, VarMode mode);
79 
81 
82  void setPSVarMode(const std::string &varName, VarMode mode);
83 
85 
86  void setInSynVarMode(VarMode mode) { m_InSynVarMode = mode; }
87 
89 
90  void setSparseConnectivityVarMode(VarMode mode){ m_SparseConnectivityVarMode = mode; }
91 
93 
94  void setDendriticDelayVarMode(VarMode mode) { m_DendriticDelayVarMode = mode; }
95 
97 
98  void setMaxConnections(unsigned int maxConnections);
99 
101 
102  void setMaxSourceConnections(unsigned int maxPostConnections);
103 
105  void setMaxDendriticDelayTimesteps(unsigned int maxDendriticDelay);
106 
108 
109  void setSpanType(SpanType spanType);
110 
112  void setBackPropDelaySteps(unsigned int timesteps);
113 
114  void initDerivedParams(double dt);
115  void calcKernelSizes(unsigned int blockSize, unsigned int &paddedKernelIDStart);
116 
117  //------------------------------------------------------------------------
118  // Public const methods
119  //------------------------------------------------------------------------
120  std::pair<unsigned int, unsigned int> getPaddedKernelIDRange() const{ return m_PaddedKernelIDRange; }
121 
122  const std::string &getName() const{ return m_Name; }
123 
124  SpanType getSpanType() const{ return m_SpanType; }
125  unsigned int getDelaySteps() const{ return m_DelaySteps; }
126  unsigned int getBackPropDelaySteps() const{ return m_BackPropDelaySteps; }
127  unsigned int getMaxConnections() const{ return m_MaxConnections; }
128  unsigned int getMaxSourceConnections() const{ return m_MaxSourceConnections; }
129  unsigned int getMaxDendriticDelayTimesteps() const{ return m_MaxDendriticDelayTimesteps; }
130  SynapseMatrixType getMatrixType() const{ return m_MatrixType; }
131 
133  VarMode getInSynVarMode() const { return m_InSynVarMode; }
134 
136  VarMode getSparseConnectivityVarMode() const{ return m_SparseConnectivityVarMode; }
137 
139  VarMode getDendriticDelayVarMode() const{ return m_DendriticDelayVarMode; }
140 
141  unsigned int getPaddedDynKernelSize(unsigned int blockSize) const;
142  unsigned int getPaddedPostLearnKernelSize(unsigned int blockSize) const;
143 
144  const NeuronGroup *getSrcNeuronGroup() const{ return m_SrcNeuronGroup; }
145  const NeuronGroup *getTrgNeuronGroup() const{ return m_TrgNeuronGroup; }
146 
147  int getClusterHostID() const{ return m_TrgNeuronGroup->getClusterHostID(); }
148  int getClusterDeviceID() const{ return m_TrgNeuronGroup->getClusterDeviceID(); }
149 
150  bool isTrueSpikeRequired() const{ return m_TrueSpikeRequired; }
151  bool isSpikeEventRequired() const{ return m_SpikeEventRequired; }
152  bool isEventThresholdReTestRequired() const{ return m_EventThresholdReTestRequired; }
153 
154  const WeightUpdateModels::Base *getWUModel() const{ return m_WUModel; }
155 
156  const std::vector<double> &getWUParams() const{ return m_WUParams; }
157  const std::vector<double> &getWUDerivedParams() const{ return m_WUDerivedParams; }
158  const std::vector<NewModels::VarInit> &getWUVarInitialisers() const{ return m_WUVarInitialisers; }
159  const std::vector<NewModels::VarInit> &getWUPreVarInitialisers() const{ return m_WUPreVarInitialisers; }
160  const std::vector<NewModels::VarInit> &getWUPostVarInitialisers() const{ return m_WUPostVarInitialisers; }
161  const std::vector<double> getWUConstInitVals() const;
162 
163  const PostsynapticModels::Base *getPSModel() const{ return m_PSModel; }
164 
165  const std::vector<double> &getPSParams() const{ return m_PSParams; }
166  const std::vector<double> &getPSDerivedParams() const{ return m_PSDerivedParams; }
167  const std::vector<NewModels::VarInit> &getPSVarInitialisers() const{ return m_PSVarInitialisers; }
168  const std::vector<double> getPSConstInitVals() const;
169 
170  const InitSparseConnectivitySnippet::Init &getConnectivityInitialiser() const{ return m_ConnectivityInitialiser; }
171 
172  const std::string &getPSModelTargetName() const{ return m_PSModelTargetName; }
173  bool isPSModelMerged() const{ return m_PSModelTargetName != getName(); }
174 
175  bool isZeroCopyEnabled() const;
176  bool isWUVarZeroCopyEnabled(const std::string &var) const{ return (getWUVarMode(var) & VarLocation::ZERO_COPY); }
177  bool isPSVarZeroCopyEnabled(const std::string &var) const{ return (getPSVarMode(var) & VarLocation::ZERO_COPY); }
178 
180  VarMode getWUVarMode(const std::string &var) const;
181 
183  VarMode getWUVarMode(size_t index) const{ return m_WUVarMode[index]; }
184 
186  VarMode getWUPreVarMode(const std::string &var) const;
187 
189  VarMode getWUPreVarMode(size_t index) const{ return m_WUPreVarMode[index]; }
190 
192  VarMode getWUPostVarMode(const std::string &var) const;
193 
195  VarMode getWUPostVarMode(size_t index) const{ return m_WUPostVarMode[index]; }
196 
198  VarMode getPSVarMode(const std::string &var) const;
199 
201  VarMode getPSVarMode(size_t index) const{ return m_PSVarMode[index]; }
202 
203  void addExtraGlobalConnectivityInitialiserParams(std::map<string, string> &kernelParameters) const;
204  void addExtraGlobalNeuronParams(std::map<string, string> &kernelParameters) const;
205  void addExtraGlobalSynapseParams(std::map<string, string> &kernelParameters) const;
206  void addExtraGlobalPostLearnParams(std::map<string, string> &kernelParameters) const;
207  void addExtraGlobalSynapseDynamicsParams(std::map<string, string> &kernelParameters) const;
208 
211  std::string getPresynapticAxonalDelaySlot(const std::string &devPrefix) const;
212 
215  std::string getPostsynapticBackPropDelaySlot(const std::string &devPrefix) const;
216 
217  std::string getDendriticDelayOffset(const std::string &devPrefix, const std::string &offset = "") const;
218 
220  bool isDendriticDelayRequired() const;
221 
223  bool isPSInitRNGRequired(VarInit varInitMode) const;
224 
226  bool isWUInitRNGRequired(VarInit varInitMode) const;
227 
229  bool isPSDeviceVarInitRequired() const;
230 
232  bool isWUDeviceVarInitRequired() const;
233 
235  bool isWUDevicePreVarInitRequired() const;
236 
238  bool isWUDevicePostVarInitRequired() const;
239 
242 
244  bool isDeviceInitRequired() const;
245 
247  bool isDeviceSparseInitRequired() const;
248 
250 
252  bool canRunOnCPU() const;
253 
254 private:
255  //------------------------------------------------------------------------
256  // Private methods
257  //------------------------------------------------------------------------
258  void addExtraGlobalSimParams(const std::string &prefix, const std::string &suffix, const NewModels::Base::StringPairVec &extraGlobalParameters,
259  std::map<std::string, std::string> &kernelParameters) const;
260  void addExtraGlobalPostLearnParams(const std::string &prefix, const std::string &suffix, const NewModels::Base::StringPairVec &extraGlobalParameters,
261  std::map<std::string, std::string> &kernelParameters) const;
262  void addExtraGlobalSynapseDynamicsParams(const std::string &prefix, const std::string &suffix, const NewModels::Base::StringPairVec &extraGlobalParameters,
263  std::map<std::string, std::string> &kernelParameters) const;
264 
265  //------------------------------------------------------------------------
266  // Members
267  //------------------------------------------------------------------------
269  std::pair<unsigned int, unsigned int> m_PaddedKernelIDRange;
270 
272  std::string m_Name;
273 
275  SpanType m_SpanType;
276 
278  unsigned int m_DelaySteps;
279 
281  unsigned int m_BackPropDelaySteps;
282 
284  unsigned int m_MaxConnections;
285 
287  unsigned int m_MaxSourceConnections;
288 
290  unsigned int m_MaxDendriticDelayTimesteps;
291 
293  SynapseMatrixType m_MatrixType;
294 
296  NeuronGroup *m_SrcNeuronGroup;
297 
299  NeuronGroup *m_TrgNeuronGroup;
300 
302  bool m_TrueSpikeRequired;
303 
305  bool m_SpikeEventRequired;
306 
308  bool m_EventThresholdReTestRequired;
309 
311  VarMode m_InSynVarMode;
312 
314  VarMode m_DendriticDelayVarMode;
315 
317  const WeightUpdateModels::Base *m_WUModel;
318 
320  std::vector<double> m_WUParams;
321 
323  std::vector<double> m_WUDerivedParams;
324 
326  std::vector<NewModels::VarInit> m_WUVarInitialisers;
327 
329  std::vector<NewModels::VarInit> m_WUPreVarInitialisers;
330 
332  std::vector<NewModels::VarInit> m_WUPostVarInitialisers;
333 
335  const PostsynapticModels::Base *m_PSModel;
336 
338  std::vector<double> m_PSParams;
339 
341  std::vector<double> m_PSDerivedParams;
342 
344  std::vector<NewModels::VarInit> m_PSVarInitialisers;
345 
347  std::vector<VarMode> m_WUVarMode;
348 
350  std::vector<VarMode> m_WUPreVarMode;
351 
353  std::vector<VarMode> m_WUPostVarMode;
354 
356  std::vector<VarMode> m_PSVarMode;
357 
359  InitSparseConnectivitySnippet::Init m_ConnectivityInitialiser;
360 
362  VarMode m_SparseConnectivityVarMode;
363 
365 
366  std::string m_PSModelTargetName;
367 };
Definition: neuronGroup.h:19
void setInSynVarMode(VarMode mode)
Set variable mode used for variables used to combine input from this synapse group.
Definition: synapseGroup.h:86
bool isDendriticDelayRequired() const
Does this synapse group require dendritic delay?
Definition: synapseGroup.cc:424
VarMode getWUPreVarMode(size_t index) const
Get variable mode used by weight update model presynaptic state variable.
Definition: synapseGroup.h:189
const PostsynapticModels::Base * getPSModel() const
Definition: synapseGroup.h:163
const std::vector< NewModels::VarInit > & getPSVarInitialisers() const
Definition: synapseGroup.h:167
void setBackPropDelaySteps(unsigned int timesteps)
Sets the number of delay steps used to delay postsynaptic spikes travelling back along dendrites to s...
Definition: synapseGroup.cc:169
bool isWUDevicePostVarInitRequired() const
Is device var init code required for any postsynaptic variables in this synapse group&#39;s weight update...
Definition: synapseGroup.cc:488
const std::vector< NewModels::VarInit > & getWUPreVarInitialisers() const
Definition: synapseGroup.h:159
bool isDeviceSparseInitRequired() const
Is any form of sparse device initialisation required?
Definition: synapseGroup.cc:513
int getClusterDeviceID() const
Definition: synapseGroup.h:148
void setWUVarZeroCopyEnabled(const std::string &varName, bool enabled)
Function to enable the use zero-copied memory for a particular postsynaptic model state variable (dep...
Definition: synapseGroup.h:56
const NeuronGroup * getSrcNeuronGroup() const
Definition: synapseGroup.h:144
const std::vector< NewModels::VarInit > & getWUVarInitialisers() const
Definition: synapseGroup.h:158
bool isDeviceSparseConnectivityInitRequired() const
Is device sparse connectivity initialisation code required for this synapse group?
Definition: synapseGroup.cc:494
void setPSVarMode(const std::string &varName, VarMode mode)
Set variable mode of postsynaptic model state variable.
Definition: synapseGroup.cc:120
bool isTrueSpikeRequired() const
Definition: synapseGroup.h:150
Definition: initSparseConnectivitySnippet.h:60
bool isWUDeviceVarInitRequired() const
Is device var init code required for any variables in this synapse group&#39;s weight update model...
Definition: synapseGroup.cc:469
void addExtraGlobalPostLearnParams(std::map< string, string > &kernelParameters) const
Definition: synapseGroup.cc:359
void addExtraGlobalSynapseDynamicsParams(std::map< string, string > &kernelParameters) const
Definition: synapseGroup.cc:374
const NeuronGroup * getTrgNeuronGroup() const
Definition: synapseGroup.h:145
void setMaxConnections(unsigned int maxConnections)
Sets the maximum number of target neurons any source neurons can connect to.
Definition: synapseGroup.cc:125
bool canRunOnCPU() const
Can this synapse group run on the CPU?
Definition: synapseGroup.cc:530
bool isSpikeEventRequired() const
Definition: synapseGroup.h:151
VarMode
Definition: variableMode.h:25
void calcKernelSizes(unsigned int blockSize, unsigned int &paddedKernelIDStart)
Definition: synapseGroup.cc:209
VarMode getInSynVarMode() const
Get variable mode used for variables used to combine input from this synapse group.
Definition: synapseGroup.h:133
unsigned int getPaddedDynKernelSize(unsigned int blockSize) const
Definition: synapseGroup.cc:232
void setSparseConnectivityVarMode(VarMode mode)
Set variable mode used for sparse connectivity.
Definition: synapseGroup.h:90
void initDerivedParams(double dt)
Definition: synapseGroup.cc:176
NeuronGroup * getSrcNeuronGroup()
Definition: synapseGroup.h:42
unsigned int getDelaySteps() const
Definition: synapseGroup.h:125
name
Definition: setup.py:112
unsigned int getPaddedPostLearnKernelSize(unsigned int blockSize) const
Definition: synapseGroup.cc:244
NeuronGroup * getTrgNeuronGroup()
Definition: synapseGroup.h:43
bool isPSVarZeroCopyEnabled(const std::string &var) const
Definition: synapseGroup.h:177
unsigned int getMaxConnections() const
Definition: synapseGroup.h:127
Base class for all postsynaptic models.
Definition: newPostsynapticModels.h:21
const std::vector< double > getPSConstInitVals() const
Definition: synapseGroup.cc:259
SpanType
Definition: synapseGroup.h:33
const std::vector< double > & getWUDerivedParams() const
Definition: synapseGroup.h:157
bool isEventThresholdReTestRequired() const
Definition: synapseGroup.h:152
std::string getPresynapticAxonalDelaySlot(const std::string &devPrefix) const
Definition: synapseGroup.cc:388
bool isWUDevicePreVarInitRequired() const
Is device var init code required for any presynaptic variables in this synapse group&#39;s weight update ...
Definition: synapseGroup.cc:482
VarMode getDendriticDelayVarMode() const
Get variable mode used for this synapse group&#39;s dendritic delay buffers.
Definition: synapseGroup.h:139
unsigned int getMaxSourceConnections() const
Definition: synapseGroup.h:128
Base class for all weight update models.
Definition: newWeightUpdateModels.h:42
VarMode getWUPostVarMode(const std::string &var) const
Get variable mode used by weight update model postsynaptic state variable.
Definition: synapseGroup.cc:293
void setWUVarMode(const std::string &varName, VarMode mode)
Set variable mode of weight update model state variable.
Definition: synapseGroup.cc:105
const std::string & getPSModelTargetName() const
Definition: synapseGroup.h:172
VarMode getWUVarMode(const std::string &var) const
Get variable mode used by weight update model per-synapse state variable.
Definition: synapseGroup.cc:283
unsigned int getBackPropDelaySteps() const
Definition: synapseGroup.h:126
void setWUPreVarMode(const std::string &varName, VarMode mode)
Set variable mode of weight update model presynaptic state variable.
Definition: synapseGroup.cc:110
Definition: synapseGroup.h:19
bool isZeroCopyEnabled() const
Definition: synapseGroup.cc:264
const std::vector< NewModels::VarInit > & getWUPostVarInitialisers() const
Definition: synapseGroup.h:160
void addExtraGlobalSynapseParams(std::map< string, string > &kernelParameters) const
Definition: synapseGroup.cc:342
const InitSparseConnectivitySnippet::Init & getConnectivityInitialiser() const
Definition: synapseGroup.h:170
void setEventThresholdReTestRequired(bool req)
Definition: synapseGroup.h:47
bool isPSModelMerged() const
Definition: synapseGroup.h:173
const std::vector< double > & getPSParams() const
Definition: synapseGroup.h:165
VarMode getWUVarMode(size_t index) const
Get variable mode used by weight update model per-synapse state variable.
Definition: synapseGroup.h:183
std::string getDendriticDelayOffset(const std::string &devPrefix, const std::string &offset="") const
Definition: synapseGroup.cc:412
int getClusterHostID() const
Definition: synapseGroup.h:147
VarMode getWUPreVarMode(const std::string &var) const
Get variable mode used by weight update model presynaptic state variable.
Definition: synapseGroup.cc:288
unsigned int getMaxDendriticDelayTimesteps() const
Definition: synapseGroup.h:129
VarMode getWUPostVarMode(size_t index) const
Get variable mode used by weight update model postsynaptic state variable.
Definition: synapseGroup.h:195
SynapseGroup()=delete
void setSpikeEventRequired(bool req)
Definition: synapseGroup.h:46
const std::string & getName() const
Definition: synapseGroup.h:122
void setSpanType(SpanType spanType)
Set how CUDA implementation is parallelised.
Definition: synapseGroup.cc:159
const std::vector< double > getWUConstInitVals() const
Definition: synapseGroup.cc:254
const std::vector< double > & getWUParams() const
Definition: synapseGroup.h:156
void setMaxDendriticDelayTimesteps(unsigned int maxDendriticDelay)
Sets the maximum dendritic delay for synapses in this synapse group.
Definition: synapseGroup.cc:153
void setMaxSourceConnections(unsigned int maxPostConnections)
Sets the maximum number of source neurons any target neuron can connect to.
Definition: synapseGroup.cc:139
SynapseMatrixType
Definition: synapseMatrixType.h:25
SynapseMatrixType getMatrixType() const
Definition: synapseGroup.h:130
std::pair< unsigned int, unsigned int > getPaddedKernelIDRange() const
Definition: synapseGroup.h:120
void setPSVarZeroCopyEnabled(const std::string &varName, bool enabled)
Definition: synapseGroup.h:63
void setPSModelMergeTarget(const std::string &targetName)
Function to enable the use of zero-copied memory for a particular weight update model state variable ...
Definition: synapseGroup.h:49
std::string getPostsynapticBackPropDelaySlot(const std::string &devPrefix) const
Definition: synapseGroup.cc:400
SpanType getSpanType() const
Definition: synapseGroup.h:124
VarMode getPSVarMode(size_t index) const
Get variable mode used by postsynaptic model state variable.
Definition: synapseGroup.h:201
void addExtraGlobalConnectivityInitialiserParams(std::map< string, string > &kernelParameters) const
Definition: synapseGroup.cc:303
void setTrueSpikeRequired(bool req)
Definition: synapseGroup.h:45
void setDendriticDelayVarMode(VarMode mode)
Set variable mode used for this synapse group&#39;s dendritic delay buffers.
Definition: synapseGroup.h:94
const WeightUpdateModels::Base * getWUModel() const
Definition: synapseGroup.h:154
bool isPSDeviceVarInitRequired() const
Is device var init code required for any variables in this synapse group&#39;s postsynaptic model...
Definition: synapseGroup.cc:456
std::vector< std::pair< std::string, std::string > > StringPairVec
Definition: snippet.h:117
void addExtraGlobalNeuronParams(std::map< string, string > &kernelParameters) const
Definition: synapseGroup.cc:317
void setWUPostVarMode(const std::string &varName, VarMode mode)
Set variable mode of weight update model postsynaptic state variable.
Definition: synapseGroup.cc:115
bool isWUInitRNGRequired(VarInit varInitMode) const
Does this synapse group require an RNG for it&#39;s weight update init code?
Definition: synapseGroup.cc:445
bool isPSInitRNGRequired(VarInit varInitMode) const
Does this synapse group require an RNG for it&#39;s postsynaptic init code?
Definition: synapseGroup.cc:439
VarMode getSparseConnectivityVarMode() const
Get variable mode used for sparse connectivity.
Definition: synapseGroup.h:136
bool isWUVarZeroCopyEnabled(const std::string &var) const
Definition: synapseGroup.h:176
const std::vector< double > & getPSDerivedParams() const
Definition: synapseGroup.h:166
VarMode getPSVarMode(const std::string &var) const
Get variable mode used by postsynaptic model state variable.
Definition: synapseGroup.cc:298
VarInit
Definition: variableMode.h:18
bool isDeviceInitRequired() const
Is any form of device initialisation required?
Definition: synapseGroup.cc:501