GeNN  4.9.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 <string>
6 #include <vector>
7 
8 // GeNN includes
9 #include "gennExport.h"
12 #include "postsynapticModels.h"
13 #include "weightUpdateModels.h"
14 #include "synapseMatrixType.h"
15 #include "variableMode.h"
16 
17 // Forward declarations
20 
21 //------------------------------------------------------------------------
22 // SynapseGroup
23 //------------------------------------------------------------------------
25 {
26 public:
27  SynapseGroup(const SynapseGroup&) = delete;
28  SynapseGroup() = delete;
29 
30  //------------------------------------------------------------------------
31  // Enumerations
32  //------------------------------------------------------------------------
33  enum class SpanType
34  {
35  POSTSYNAPTIC,
36  PRESYNAPTIC
37  };
38 
39  //------------------------------------------------------------------------
40  // Public methods
41  //------------------------------------------------------------------------
43 
44  void setWUVarLocation(const std::string &varName, VarLocation loc);
45 
47 
48  void setWUPreVarLocation(const std::string &varName, VarLocation loc);
49 
51 
52  void setWUPostVarLocation(const std::string &varName, VarLocation loc);
53 
55 
57  void setWUExtraGlobalParamLocation(const std::string &paramName, VarLocation loc);
58 
60 
61  void setPSVarLocation(const std::string &varName, VarLocation loc);
62 
64 
66  void setPSExtraGlobalParamLocation(const std::string &paramName, VarLocation loc);
67 
69 
70  void setPSTargetVar(const std::string &varName);
71 
73 
74  void setPreTargetVar(const std::string &varName);
75 
77 
79  void setSparseConnectivityExtraGlobalParamLocation(const std::string &paramName, VarLocation loc);
80 
82 
83  void setInSynVarLocation(VarLocation loc) { m_InSynLocation = loc; }
84 
86 
87  void setSparseConnectivityLocation(VarLocation loc);
88 
90  void setDendriticDelayLocation(VarLocation loc) { m_DendriticDelayLocation = loc; }
91 
93 
94  void setMaxConnections(unsigned int maxConnections);
95 
97 
98  void setMaxSourceConnections(unsigned int maxPostConnections);
99 
101  void setMaxDendriticDelayTimesteps(unsigned int maxDendriticDelay);
102 
104 
105  void setSpanType(SpanType spanType);
106 
108  // **TODO** this shouldn't be in SynapseGroup - it's backend-specific
109  void setNumThreadsPerSpike(unsigned int numThreadsPerSpike);
110 
112  void setBackPropDelaySteps(unsigned int timesteps);
113 
115  void setNarrowSparseIndEnabled(bool enabled);
116 
117  //------------------------------------------------------------------------
118  // Public const methods
119  //------------------------------------------------------------------------
120  const std::string &getName() const{ return m_Name; }
121 
122  SpanType getSpanType() const{ return m_SpanType; }
123  unsigned int getNumThreadsPerSpike() const{ return m_NumThreadsPerSpike; }
124  unsigned int getDelaySteps() const{ return m_DelaySteps; }
125  unsigned int getBackPropDelaySteps() const{ return m_BackPropDelaySteps; }
126  unsigned int getMaxConnections() const;
127  unsigned int getMaxSourceConnections() const;
128  unsigned int getMaxDendriticDelayTimesteps() const{ return m_MaxDendriticDelayTimesteps; }
129  SynapseMatrixType getMatrixType() const{ return m_MatrixType; }
130  const std::vector<unsigned int> &getKernelSize() const { return m_KernelSize; }
131  size_t getKernelSizeFlattened() const;
132 
134  VarLocation getInSynLocation() const { return m_InSynLocation; }
135 
137  VarLocation getSparseConnectivityLocation() const;
138 
140  VarLocation getDendriticDelayLocation() const{ return m_DendriticDelayLocation; }
141 
143  bool isTrueSpikeRequired() const;
144 
146  bool isSpikeEventRequired() const;
147 
149  bool isWeightSharingSlave() const { return (getWeightSharingMaster() != nullptr); }
150 
152 
153  bool isPSModelFused() const{ return m_FusedPSVarSuffix != getName(); }
154 
157 
158  bool isWUPreModelFused() const { return m_FusedWUPreVarSuffix != getName(); }
159 
162 
163  bool isWUPostModelFused() const { return m_FusedWUPostVarSuffix != getName(); }
164 
166 
167  std::string getSparseIndType() const;
168 
169  const WeightUpdateModels::Base *getWUModel() const{ return m_WUModel; }
170 
171  const std::vector<double> &getWUParams() const{ return m_WUParams; }
172  const std::vector<Models::VarInit> &getWUVarInitialisers() const{ return m_WUVarInitialisers; }
173  const std::vector<Models::VarInit> &getWUPreVarInitialisers() const{ return m_WUPreVarInitialisers; }
174  const std::vector<Models::VarInit> &getWUPostVarInitialisers() const{ return m_WUPostVarInitialisers; }
175  const std::vector<double> getWUConstInitVals() const;
176 
177  const PostsynapticModels::Base *getPSModel() const{ return m_PSModel; }
178 
179  const std::vector<double> &getPSParams() const{ return m_PSParams; }
180  const std::vector<Models::VarInit> &getPSVarInitialisers() const{ return m_PSVarInitialisers; }
181  const std::vector<double> getPSConstInitVals() const;
182 
183  const InitSparseConnectivitySnippet::Init &getConnectivityInitialiser() const{ return m_SparseConnectivityInitialiser; }
184  const InitToeplitzConnectivitySnippet::Init &getToeplitzConnectivityInitialiser() const { return m_ToeplitzConnectivityInitialiser; }
185 
186  bool isZeroCopyEnabled() const;
187 
189  VarLocation getWUVarLocation(const std::string &var) const;
190 
192  VarLocation getWUVarLocation(size_t index) const;
193 
195  VarLocation getWUPreVarLocation(const std::string &var) const;
196 
198  VarLocation getWUPreVarLocation(size_t index) const{ return m_WUPreVarLocation.at(index); }
199 
201  VarLocation getWUPostVarLocation(const std::string &var) const;
202 
204  VarLocation getWUPostVarLocation(size_t index) const{ return m_WUPostVarLocation.at(index); }
205 
207 
208  VarLocation getWUExtraGlobalParamLocation(const std::string &paramName) const;
209 
211 
212  VarLocation getWUExtraGlobalParamLocation(size_t index) const{ return m_WUExtraGlobalParamLocation.at(index); }
213 
215  VarLocation getPSVarLocation(const std::string &var) const;
216 
218  VarLocation getPSVarLocation(size_t index) const{ return m_PSVarLocation.at(index); }
219 
221 
222  VarLocation getPSExtraGlobalParamLocation(const std::string &paramName) const;
223 
225 
226  VarLocation getPSExtraGlobalParamLocation(size_t index) const{ return m_PSExtraGlobalParamLocation.at(index); }
227 
229 
230  const std::string &getPSTargetVar() const{ return m_PSTargetVar; }
231 
233 
234  const std::string &getPreTargetVar() const{ return m_PreTargetVar; }
235 
237 
238  VarLocation getSparseConnectivityExtraGlobalParamLocation(const std::string &paramName) const;
239 
241 
242  VarLocation getSparseConnectivityExtraGlobalParamLocation(size_t index) const;
243 
245  bool isDendriticDelayRequired() const;
246 
248  bool isPresynapticOutputRequired() const;
249 
251  bool isProceduralConnectivityRNGRequired() const;
252 
254  bool isPSInitRNGRequired() const;
255 
257  bool isWUInitRNGRequired() const;
258 
260  bool isWUPreInitRNGRequired() const;
261 
263  bool isWUPostInitRNGRequired() const;
264 
266  bool isHostInitRNGRequired() const;
267 
269  bool isWUVarInitRequired() const;
270 
272  bool isSparseConnectivityInitRequired() const;
273 
274 protected:
275  SynapseGroup(const std::string &name, SynapseMatrixType matrixType, unsigned int delaySteps,
276  const WeightUpdateModels::Base *wu, const std::vector<double> &wuParams, const std::vector<Models::VarInit> &wuVarInitialisers, const std::vector<Models::VarInit> &wuPreVarInitialisers, const std::vector<Models::VarInit> &wuPostVarInitialisers,
277  const PostsynapticModels::Base *ps, const std::vector<double> &psParams, const std::vector<Models::VarInit> &psVarInitialisers,
278  NeuronGroupInternal *srcNeuronGroup, NeuronGroupInternal *trgNeuronGroup, const SynapseGroupInternal *weightSharingMaster,
279  const InitSparseConnectivitySnippet::Init &connectivityInitialiser,
280  const InitToeplitzConnectivitySnippet::Init &toeplitzInitialiser,
281  VarLocation defaultVarLocation, VarLocation defaultExtraGlobalParamLocation,
282  VarLocation defaultSparseConnectivityLocation, bool defaultNarrowSparseIndEnabled);
283 
284  //------------------------------------------------------------------------
285  // Protected methods
286  //------------------------------------------------------------------------
287  NeuronGroupInternal *getSrcNeuronGroup(){ return m_SrcNeuronGroup; }
288  NeuronGroupInternal *getTrgNeuronGroup(){ return m_TrgNeuronGroup; }
289 
290  void setEventThresholdReTestRequired(bool req){ m_EventThresholdReTestRequired = req; }
291 
293  void setWUVarReferencedByCustomUpdate(bool ref) { m_WUVarReferencedByCustomUpdate = ref; }
294 
295  void setFusedPSVarSuffix(const std::string &suffix){ m_FusedPSVarSuffix = suffix; }
296  void setFusedWUPreVarSuffix(const std::string &suffix){ m_FusedWUPreVarSuffix = suffix; }
297  void setFusedWUPostVarSuffix(const std::string &suffix){ m_FusedWUPostVarSuffix = suffix; }
298  void setFusedPreOutputSuffix(const std::string &suffix){ m_FusedPreOutputSuffix = suffix; }
299 
300  void initDerivedParams(double dt);
301 
302  //------------------------------------------------------------------------
303  // Protected const methods
304  //------------------------------------------------------------------------
305  const NeuronGroupInternal *getSrcNeuronGroup() const{ return m_SrcNeuronGroup; }
306  const NeuronGroupInternal *getTrgNeuronGroup() const{ return m_TrgNeuronGroup; }
307 
308  const std::vector<double> &getWUDerivedParams() const{ return m_WUDerivedParams; }
309  const std::vector<double> &getPSDerivedParams() const{ return m_PSDerivedParams; }
310 
311  const SynapseGroupInternal *getWeightSharingMaster() const { return m_WeightSharingMaster; }
312 
314 
315  bool isEventThresholdReTestRequired() const{ return m_EventThresholdReTestRequired; }
316 
317  const std::string &getFusedPSVarSuffix() const{ return m_FusedPSVarSuffix; }
318  const std::string &getFusedWUPreVarSuffix() const { return m_FusedWUPreVarSuffix; }
319  const std::string &getFusedWUPostVarSuffix() const { return m_FusedWUPostVarSuffix; }
320  const std::string &getFusedPreOutputSuffix() const { return m_FusedPreOutputSuffix; }
321 
323  bool areWUVarReferencedByCustomUpdate() const { return m_WUVarReferencedByCustomUpdate; }
324 
326  bool canPSBeFused() const;
327 
329  bool canWUMPreUpdateBeFused() const;
330 
332  bool canPreOutputBeFused() const;
333 
335  bool canWUMPostUpdateBeFused() const;
336 
338 
339  boost::uuids::detail::sha1::digest_type getWUHashDigest() const;
340 
342 
343  boost::uuids::detail::sha1::digest_type getWUPreHashDigest() const;
344 
346 
347  boost::uuids::detail::sha1::digest_type getWUPostHashDigest() const;
348 
350 
351  boost::uuids::detail::sha1::digest_type getPSHashDigest() const;
352 
355 
356  boost::uuids::detail::sha1::digest_type getWUPreFuseHashDigest() const;
357 
360 
361  boost::uuids::detail::sha1::digest_type getWUPostFuseHashDigest() const;
362 
365 
366  boost::uuids::detail::sha1::digest_type getPSFuseHashDigest() const;
367 
369 
370  boost::uuids::detail::sha1::digest_type getPreOutputHashDigest() const;
371 
372  boost::uuids::detail::sha1::digest_type getDendriticDelayUpdateHashDigest() const;
373 
375 
376  boost::uuids::detail::sha1::digest_type getWUInitHashDigest() const;
377 
379 
380  boost::uuids::detail::sha1::digest_type getWUPreInitHashDigest() const;
381 
383 
384  boost::uuids::detail::sha1::digest_type getWUPostInitHashDigest() const;
385 
387 
388  boost::uuids::detail::sha1::digest_type getPSInitHashDigest() const;
389 
391 
392  boost::uuids::detail::sha1::digest_type getPreOutputInitHashDigest() const;
393 
395 
396  boost::uuids::detail::sha1::digest_type getConnectivityInitHashDigest() const;
397 
399 
400  boost::uuids::detail::sha1::digest_type getConnectivityHostInitHashDigest() const;
401 
402  boost::uuids::detail::sha1::digest_type getVarLocationHashDigest() const;
403 private:
404  //------------------------------------------------------------------------
405  // Members
406  //------------------------------------------------------------------------
408  const std::string m_Name;
409 
411  SpanType m_SpanType;
412 
414  unsigned int m_NumThreadsPerSpike;
415 
417  unsigned int m_DelaySteps;
418 
420  unsigned int m_BackPropDelaySteps;
421 
423  unsigned int m_MaxConnections;
424 
426  unsigned int m_MaxSourceConnections;
427 
429  unsigned int m_MaxDendriticDelayTimesteps;
430 
432  std::vector<unsigned int> m_KernelSize;
433 
435  const SynapseMatrixType m_MatrixType;
436 
438  NeuronGroupInternal * const m_SrcNeuronGroup;
439 
441  NeuronGroupInternal * const m_TrgNeuronGroup;
442 
444  const SynapseGroupInternal *m_WeightSharingMaster;
445 
447 
448  bool m_EventThresholdReTestRequired;
449 
451  bool m_NarrowSparseIndEnabled;
452 
454  bool m_WUVarReferencedByCustomUpdate;
455 
457  VarLocation m_InSynLocation;
458 
460  VarLocation m_DendriticDelayLocation;
461 
463  const WeightUpdateModels::Base *m_WUModel;
464 
466  const std::vector<double> m_WUParams;
467 
469  std::vector<double> m_WUDerivedParams;
470 
472  std::vector<Models::VarInit> m_WUVarInitialisers;
473 
475  std::vector<Models::VarInit> m_WUPreVarInitialisers;
476 
478  std::vector<Models::VarInit> m_WUPostVarInitialisers;
479 
481  const PostsynapticModels::Base *m_PSModel;
482 
484  const std::vector<double> m_PSParams;
485 
487  std::vector<double> m_PSDerivedParams;
488 
490  std::vector<Models::VarInit> m_PSVarInitialisers;
491 
493  std::vector<VarLocation> m_WUVarLocation;
494 
496  std::vector<VarLocation> m_WUPreVarLocation;
497 
499  std::vector<VarLocation> m_WUPostVarLocation;
500 
502  std::vector<VarLocation> m_WUExtraGlobalParamLocation;
503 
505  std::vector<VarLocation> m_PSVarLocation;
506 
508  std::vector<VarLocation> m_PSExtraGlobalParamLocation;
509 
511  InitSparseConnectivitySnippet::Init m_SparseConnectivityInitialiser;
512 
514  InitToeplitzConnectivitySnippet::Init m_ToeplitzConnectivityInitialiser;
515 
517  VarLocation m_SparseConnectivityLocation;
518 
520  std::vector<VarLocation> m_ConnectivityExtraGlobalParamLocation;
521 
523 
524  std::string m_FusedPSVarSuffix;
525 
527 
528  std::string m_FusedWUPreVarSuffix;
529 
531 
532  std::string m_FusedWUPostVarSuffix;
533 
535 
536  std::string m_FusedPreOutputSuffix;
537 
539 
540  std::string m_PSTargetVar;
541 
543 
544  std::string m_PreTargetVar;
545 };
Definition: neuronGroupInternal.h:9
VarLocation getInSynLocation() const
Get variable mode used for variables used to combine input from this synapse group.
Definition: synapseGroup.h:134
void setFusedWUPreVarSuffix(const std::string &suffix)
Definition: synapseGroup.h:296
NeuronGroupInternal * getSrcNeuronGroup()
Definition: synapseGroup.h:287
VarLocation getPSVarLocation(size_t index) const
Get location of postsynaptic model state variable.
Definition: synapseGroup.h:218
const PostsynapticModels::Base * getPSModel() const
Definition: synapseGroup.h:177
const std::vector< Models::VarInit > & getWUVarInitialisers() const
Definition: synapseGroup.h:172
VarLocation
< Flags defining which memory space variables should be allocated in
Definition: variableMode.h:10
bool isWUPreModelFused() const
Definition: synapseGroup.h:158
Definition: initSparseConnectivitySnippet.h:81
const std::vector< Models::VarInit > & getWUPostVarInitialisers() const
Definition: synapseGroup.h:174
const std::string & getPSTargetVar() const
Get name of neuron input variable postsynaptic model will target.
Definition: synapseGroup.h:230
#define GENN_EXPORT
Definition: gennExport.h:13
unsigned int getNumThreadsPerSpike() const
Definition: synapseGroup.h:123
bool isPSModelFused() const
Has this synapse group&#39;s postsynaptic model been fused with those from other synapse groups...
Definition: synapseGroup.h:153
unsigned int getDelaySteps() const
Definition: synapseGroup.h:124
Definition: initToeplitzConnectivitySnippet.h:66
VarLocation getWUExtraGlobalParamLocation(size_t index) const
Get location of weight update model extra global parameter by index.
Definition: synapseGroup.h:212
const std::vector< Models::VarInit > & getWUPreVarInitialisers() const
Definition: synapseGroup.h:173
Base class for all postsynaptic models.
Definition: postsynapticModels.h:23
SpanType
Definition: synapseGroup.h:33
const std::vector< double > & getWUDerivedParams() const
Definition: synapseGroup.h:308
bool isEventThresholdReTestRequired() const
Definition: synapseGroup.h:315
NeuronGroupInternal * getTrgNeuronGroup()
Definition: synapseGroup.h:288
Definition: synapseGroupInternal.h:9
const SynapseGroupInternal * getWeightSharingMaster() const
Does the event threshold needs to be retested in the synapse kernel?
Definition: synapseGroup.h:311
const std::vector< Models::VarInit > & getPSVarInitialisers() const
Definition: synapseGroup.h:180
Base class for all weight update models.
Definition: weightUpdateModels.h:46
unsigned int getBackPropDelaySteps() const
Definition: synapseGroup.h:125
const std::vector< unsigned int > & getKernelSize() const
Definition: synapseGroup.h:130
VarLocation getWUPreVarLocation(size_t index) const
Get location of weight update model presynaptic state variable by index.
Definition: synapseGroup.h:198
Definition: synapseGroup.h:24
const std::string & getFusedWUPostVarSuffix() const
Definition: synapseGroup.h:319
void setInSynVarLocation(VarLocation loc)
Set location of variables used to combine input from this synapse group.
Definition: synapseGroup.h:83
const InitSparseConnectivitySnippet::Init & getConnectivityInitialiser() const
Definition: synapseGroup.h:183
const std::string & getFusedPSVarSuffix() const
Definition: synapseGroup.h:317
void setEventThresholdReTestRequired(bool req)
Definition: synapseGroup.h:290
const std::vector< double > & getPSParams() const
Definition: synapseGroup.h:179
bool areWUVarReferencedByCustomUpdate() const
Are any of this synapse group&#39;s weight update model variables referenced by a custom update...
Definition: synapseGroup.h:323
const NeuronGroupInternal * getSrcNeuronGroup() const
Definition: synapseGroup.h:305
VarLocation getWUPostVarLocation(size_t index) const
Get location of weight update model postsynaptic state variable by index.
Definition: synapseGroup.h:204
void setFusedWUPostVarSuffix(const std::string &suffix)
Definition: synapseGroup.h:297
unsigned int getMaxDendriticDelayTimesteps() const
Definition: synapseGroup.h:128
VarLocation getPSExtraGlobalParamLocation(size_t index) const
Get location of postsynaptic model extra global parameter by index.
Definition: synapseGroup.h:226
bool isWUPostModelFused() const
Definition: synapseGroup.h:163
VarLocation getDendriticDelayLocation() const
Get variable mode used for this synapse group&#39;s dendritic delay buffers.
Definition: synapseGroup.h:140
const std::string & getName() const
Definition: synapseGroup.h:120
void setFusedPreOutputSuffix(const std::string &suffix)
Definition: synapseGroup.h:298
const std::vector< double > & getWUParams() const
Definition: synapseGroup.h:171
bool isWeightSharingSlave() const
Is this synapse group a weight-sharing slave.
Definition: synapseGroup.h:149
SynapseMatrixType
Supported combinations of SynapticMatrixConnectivity and SynapticMatrixWeight.
Definition: synapseMatrixType.h:27
const InitToeplitzConnectivitySnippet::Init & getToeplitzConnectivityInitialiser() const
Definition: synapseGroup.h:184
SynapseMatrixType getMatrixType() const
Definition: synapseGroup.h:129
void setFusedPSVarSuffix(const std::string &suffix)
Definition: synapseGroup.h:295
SpanType getSpanType() const
Definition: synapseGroup.h:122
void setDendriticDelayLocation(VarLocation loc)
Set variable mode used for this synapse group&#39;s dendritic delay buffers.
Definition: synapseGroup.h:90
const std::string & getFusedPreOutputSuffix() const
Definition: synapseGroup.h:320
const WeightUpdateModels::Base * getWUModel() const
Definition: synapseGroup.h:169
const std::string & getFusedWUPreVarSuffix() const
Definition: synapseGroup.h:318
const NeuronGroupInternal * getTrgNeuronGroup() const
Definition: synapseGroup.h:306
const std::string & getPreTargetVar() const
Get name of neuron input variable which a presynaptic output specified with will target...
Definition: synapseGroup.h:234
void setWUVarReferencedByCustomUpdate(bool ref)
Set if any of this synapse group&#39;s weight update model variables referenced by a custom update...
Definition: synapseGroup.h:293
const std::vector< double > & getPSDerivedParams() const
Definition: synapseGroup.h:309