GeNN  4.9.0
GPU enhanced Neuronal Networks (GeNN)
presynapticUpdateStrategySIMT.h
Go to the documentation of this file.
1 #pragma once
2 
3 // GeNN code generator includes
5 
6 // Forward declarations
8 
9 namespace CodeGenerator
10 {
11 class BackendSIMT;
12 class ModelSpecMerged;
13 }
14 
15 //--------------------------------------------------------------------------
16 // CodeGenerator::PresynapticUpdateStrategySIMT::Base
17 //--------------------------------------------------------------------------
18 namespace CodeGenerator
19 {
20 namespace PresynapticUpdateStrategySIMT
21 {
22 class Base
23 {
24 public:
25  //------------------------------------------------------------------------
26  // Declared virtuals
27  //------------------------------------------------------------------------
29  virtual size_t getNumThreads(const SynapseGroupInternal &sg) const = 0;
30 
32  virtual size_t getSynapticMatrixRowStride(const SynapseGroupInternal &sg) const = 0;
33 
35  virtual bool isCompatible(const SynapseGroupInternal &sg, const PreferencesBase &preferences) const = 0;
36 
38  virtual size_t getSharedMemoryPerThread(const PresynapticUpdateGroupMerged &sg, const BackendSIMT &backend) const = 0;
39 
40  virtual void genPreamble(CodeStream &os, const ModelSpecMerged &modelMerged, const PresynapticUpdateGroupMerged &sg,
41  const Substitutions &popSubs, const BackendSIMT &backend) const = 0;
42 
44  virtual void genUpdate(CodeStream &os, const ModelSpecMerged &modelMerged, const PresynapticUpdateGroupMerged &sg,
45  const Substitutions &popSubs, const BackendSIMT &backend, bool trueSpike) const = 0;
46 
47  virtual void genPostamble(CodeStream &os, const ModelSpecMerged &modelMerged, const PresynapticUpdateGroupMerged &sg,
48  const Substitutions &popSubs, const BackendSIMT &backend) const = 0;
49 };
50 
51 //--------------------------------------------------------------------------
52 // CodeGenerator::PresynapticUpdateStrategySIMT::PreSpan
53 //--------------------------------------------------------------------------
55 class PreSpan : public Base
56 {
57 public:
58  //------------------------------------------------------------------------
59  // PresynapticUpdateStrategy::Base virtuals
60  //------------------------------------------------------------------------
62  virtual size_t getNumThreads(const SynapseGroupInternal &sg) const override;
63 
65  virtual size_t getSynapticMatrixRowStride(const SynapseGroupInternal &sg) const override;
66 
68  virtual bool isCompatible(const SynapseGroupInternal &sg, const PreferencesBase &preferences) const override;
69 
71  virtual size_t getSharedMemoryPerThread(const PresynapticUpdateGroupMerged &sg, const BackendSIMT &backend) const override;
72 
73  virtual void genPreamble(CodeStream &os, const ModelSpecMerged &modelMerged, const PresynapticUpdateGroupMerged &sg,
74  const Substitutions &popSubs, const BackendSIMT &backend) const override;
75 
77  virtual void genUpdate(CodeStream &os, const ModelSpecMerged &modelMerged, const PresynapticUpdateGroupMerged &sg,
78  const Substitutions &popSubs, const BackendSIMT &backend, bool trueSpike) const override;
79 
80  virtual void genPostamble(CodeStream &os, const ModelSpecMerged &modelMerged, const PresynapticUpdateGroupMerged &sg,
81  const Substitutions &popSubs, const BackendSIMT &backend) const override;
82 };
83 
84 //--------------------------------------------------------------------------
85 // CodeGenerator::PresynapticUpdateStrategySIMT::PostSpan
86 //--------------------------------------------------------------------------
88 class PostSpan : public Base
89 {
90 public:
91  //------------------------------------------------------------------------
92  // PresynapticUpdateStrategy::Base virtuals
93  //------------------------------------------------------------------------
95  virtual size_t getNumThreads(const SynapseGroupInternal &sg) const override;
96 
98  virtual size_t getSynapticMatrixRowStride(const SynapseGroupInternal &sg) const override;
99 
101  virtual bool isCompatible(const SynapseGroupInternal &sg, const PreferencesBase &preferences) const override;
102 
104  virtual size_t getSharedMemoryPerThread(const PresynapticUpdateGroupMerged &sg, const BackendSIMT &backend) const override;
105 
106  virtual void genPreamble(CodeStream &os, const ModelSpecMerged &modelMerged, const PresynapticUpdateGroupMerged &sg,
107  const Substitutions &popSubs, const BackendSIMT &backend) const override;
108 
110  virtual void genUpdate(CodeStream &os, const ModelSpecMerged &modelMerged, const PresynapticUpdateGroupMerged &sg,
111  const Substitutions &popSubs, const BackendSIMT &backend, bool trueSpike) const override;
112 
113  virtual void genPostamble(CodeStream &os, const ModelSpecMerged &modelMerged, const PresynapticUpdateGroupMerged &sg,
114  const Substitutions &popSubs, const BackendSIMT &backend) const override;
115 
116 private:
117  //--------------------------------------------------------------------------
118  // Private methods
119  //--------------------------------------------------------------------------
121  bool shouldAccumulateInRegister(const PresynapticUpdateGroupMerged &sg) const;
122 
123 };
124 
125 //--------------------------------------------------------------------------
126 // CodeGenerator::PresynapticUpdateStrategySIMT::PostSpanBitmask
127 //--------------------------------------------------------------------------
129 class PostSpanBitmask : public Base
130 {
131 public:
132  //------------------------------------------------------------------------
133  // PresynapticUpdateStrategy::Base virtuals
134  //------------------------------------------------------------------------
136  virtual size_t getNumThreads(const SynapseGroupInternal &sg) const override;
137 
139  virtual size_t getSynapticMatrixRowStride(const SynapseGroupInternal &sg) const override;
140 
142  virtual bool isCompatible(const SynapseGroupInternal &sg, const PreferencesBase &preferences) const override;
143 
145  virtual size_t getSharedMemoryPerThread(const PresynapticUpdateGroupMerged &sg, const BackendSIMT &backend) const override;
146 
147  virtual void genPreamble(CodeStream &os, const ModelSpecMerged &modelMerged, const PresynapticUpdateGroupMerged &sg,
148  const Substitutions &popSubs, const BackendSIMT &backend) const override;
149 
151  virtual void genUpdate(CodeStream &os, const ModelSpecMerged &modelMerged, const PresynapticUpdateGroupMerged &sg,
152  const Substitutions &popSubs, const BackendSIMT &backend, bool trueSpike) const override;
153 
154  virtual void genPostamble(CodeStream &os, const ModelSpecMerged &modelMerged, const PresynapticUpdateGroupMerged &sg,
155  const Substitutions &popSubs, const BackendSIMT &backend) const override;
156 };
157 
158 //--------------------------------------------------------------------------
159 // CodeGenerator::PresynapticUpdateStrategySIMT::PreSpanProcedural
160 //--------------------------------------------------------------------------
162 class PreSpanProcedural : public Base
163 {
164 public:
165  //------------------------------------------------------------------------
166  // PresynapticUpdateStrategy::Base virtuals
167  //------------------------------------------------------------------------
169  virtual size_t getNumThreads(const SynapseGroupInternal &sg) const override;
170 
172  virtual size_t getSynapticMatrixRowStride(const SynapseGroupInternal &sg) const override;
173 
175  virtual bool isCompatible(const SynapseGroupInternal &sg, const PreferencesBase &preferences) const override;
176 
178  virtual size_t getSharedMemoryPerThread(const PresynapticUpdateGroupMerged &sg, const BackendSIMT &backend) const override;
179 
180  virtual void genPreamble(CodeStream &os, const ModelSpecMerged &modelMerged, const PresynapticUpdateGroupMerged &sg,
181  const Substitutions &popSubs, const BackendSIMT &backend) const override;
182 
184  virtual void genUpdate(CodeStream &os, const ModelSpecMerged &modelMerged, const PresynapticUpdateGroupMerged &sg,
185  const Substitutions &popSubs, const BackendSIMT &backend, bool trueSpike) const override;
186 
187  virtual void genPostamble(CodeStream &os, const ModelSpecMerged &modelMerged, const PresynapticUpdateGroupMerged &sg,
188  const Substitutions &popSubs, const BackendSIMT &backend) const override;
189 };
190 
191 //--------------------------------------------------------------------------
192 // CodeGenerator::PresynapticUpdateStrategySIMT::PostSpanToeplitz
193 //--------------------------------------------------------------------------
195 class PostSpanToeplitz : public Base
196 {
197 public:
198  //------------------------------------------------------------------------
199  // PresynapticUpdateStrategy::Base virtuals
200  //------------------------------------------------------------------------
202  virtual size_t getNumThreads(const SynapseGroupInternal &sg) const override;
203 
205  virtual size_t getSynapticMatrixRowStride(const SynapseGroupInternal &sg) const override;
206 
208  virtual bool isCompatible(const SynapseGroupInternal &sg, const PreferencesBase &preferences) const override;
209 
211  virtual size_t getSharedMemoryPerThread(const PresynapticUpdateGroupMerged &sg, const BackendSIMT &backend) const override;
212 
213  virtual void genPreamble(CodeStream &os, const ModelSpecMerged &modelMerged, const PresynapticUpdateGroupMerged &sg,
214  const Substitutions &popSubs, const BackendSIMT &backend) const override;
215 
217  virtual void genUpdate(CodeStream &os, const ModelSpecMerged &modelMerged, const PresynapticUpdateGroupMerged &sg,
218  const Substitutions &popSubs, const BackendSIMT &backend, bool trueSpike) const override;
219 
220  virtual void genPostamble(CodeStream &os, const ModelSpecMerged &modelMerged, const PresynapticUpdateGroupMerged &sg,
221  const Substitutions &popSubs, const BackendSIMT &backend) const override;
222 };
223 } // namespace PresynapticUpdateStrategySIMT
224 } // namespace CodeGenerator
Base class for Single Instruction Multiple Thread style backends.
Definition: backendSIMT.h:51
Postsynaptic parallelism.
Definition: presynapticUpdateStrategySIMT.h:88
virtual size_t getSynapticMatrixRowStride(const SynapseGroupInternal &sg) const =0
Gets the stride used to access synaptic matrix rows, taking into account sparse data structure...
virtual size_t getSharedMemoryPerThread(const PresynapticUpdateGroupMerged &sg, const BackendSIMT &backend) const =0
How many neurons does each thread accumulate the outputs of into shared memory.
Postsynaptic parallelism for Toeplitz connectivity.
Definition: presynapticUpdateStrategySIMT.h:195
Base class for backend preferences - can be accessed via a global in 'classic' C++ code generator...
Definition: backendBase.h:58
Definition: modelSpecMerged.h:31
Helper class for generating code - automatically inserts brackets, indents etc.
Definition: backendBase.h:30
virtual void genPostamble(CodeStream &os, const ModelSpecMerged &modelMerged, const PresynapticUpdateGroupMerged &sg, const Substitutions &popSubs, const BackendSIMT &backend) const =0
Definition: synapseGroupInternal.h:9
Definition: codeStream.h:21
Definition: substitutions.h:21
Presynaptic parallelism.
Definition: presynapticUpdateStrategySIMT.h:55
Presynaptic parallelism with procedural connectivity.
Definition: presynapticUpdateStrategySIMT.h:162
virtual bool isCompatible(const SynapseGroupInternal &sg, const PreferencesBase &preferences) const =0
Is this presynaptic update strategy compatible with a given synapse group?
Definition: presynapticUpdateStrategySIMT.h:22
virtual void genPreamble(CodeStream &os, const ModelSpecMerged &modelMerged, const PresynapticUpdateGroupMerged &sg, const Substitutions &popSubs, const BackendSIMT &backend) const =0
virtual void genUpdate(CodeStream &os, const ModelSpecMerged &modelMerged, const PresynapticUpdateGroupMerged &sg, const Substitutions &popSubs, const BackendSIMT &backend, bool trueSpike) const =0
Generate presynaptic update code.
Definition: synapseUpdateGroupMerged.h:15
Postsynaptic parallelism.
Definition: presynapticUpdateStrategySIMT.h:129
virtual size_t getNumThreads(const SynapseGroupInternal &sg) const =0
Get the number of threads that presynaptic updates should be parallelised across. ...