GeNN  3.3.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 "global.h"
11 #include "newNeuronModels.h"
12 #include "variableMode.h"
13 
14 class CurrentSource;
15 
16 //------------------------------------------------------------------------
17 // NeuronGroup
18 //------------------------------------------------------------------------
20 {
21 public:
22  NeuronGroup(const std::string &name, int numNeurons, const NeuronModels::Base *neuronModel,
23  const std::vector<double> &params, const std::vector<NewModels::VarInit> &varInitialisers, int hostID, int deviceID) :
24  m_Name(name), m_NumNeurons(numNeurons), m_IDRange(0, 0), m_PaddedIDRange(0, 0),
25  m_NeuronModel(neuronModel), m_Params(params), m_VarInitialisers(varInitialisers),
26  m_SpikeTimeRequired(false), m_TrueSpikeRequired(false), m_SpikeEventRequired(false),
27  m_NumDelaySlots(1), m_VarQueueRequired(varInitialisers.size(), false),
28  m_SpikeVarMode(GENN_PREFERENCES::defaultVarMode), m_SpikeEventVarMode(GENN_PREFERENCES::defaultVarMode),
29  m_SpikeTimeVarMode(GENN_PREFERENCES::defaultVarMode), m_VarMode(varInitialisers.size(), GENN_PREFERENCES::defaultVarMode),
30  m_HostID(hostID), m_DeviceID(deviceID)
31  {
32  }
33  NeuronGroup(const NeuronGroup&) = delete;
34  NeuronGroup() = delete;
35 
36  //------------------------------------------------------------------------
37  // Public methods
38  //------------------------------------------------------------------------
40  void checkNumDelaySlots(unsigned int requiredDelay);
41 
43  void updatePreVarQueues(const std::string &code);
44 
46  void updatePostVarQueues(const std::string &code);
47 
48  void setSpikeTimeRequired(bool req){ m_SpikeTimeRequired = req; }
49  void setTrueSpikeRequired(bool req){ m_TrueSpikeRequired = req; }
50  void setSpikeEventRequired(bool req){ m_SpikeEventRequired = req; }
51 
53 
54  void setSpikeZeroCopyEnabled(bool enabled)
55  {
57  }
58 
60 
61  void setSpikeEventZeroCopyEnabled(bool enabled)
62  {
64  }
65 
67 
68  void setSpikeTimeZeroCopyEnabled(bool enabled)
69  {
71  }
72 
74 
75  void setVarZeroCopyEnabled(const std::string &varName, bool enabled)
76  {
78  }
79 
81 
82  void setSpikeVarMode(VarMode mode) { m_SpikeVarMode = mode; }
83 
85 
86  void setSpikeEventVarMode(VarMode mode) { m_SpikeEventVarMode = mode; }
87 
89 
90  void setSpikeTimeVarMode(VarMode mode) { m_SpikeTimeVarMode = mode; }
91 
93 
94  void setVarMode(const std::string &varName, VarMode mode);
95 
96  void addSpkEventCondition(const std::string &code, const std::string &supportCodeNamespace);
97 
98  void addInSyn(SynapseGroup *synapseGroup){ m_InSyn.push_back(synapseGroup); }
99  void addOutSyn(SynapseGroup *synapseGroup){ m_OutSyn.push_back(synapseGroup); }
100 
101  void initDerivedParams(double dt);
102  void calcSizes(unsigned int blockSize, unsigned int &idStart, unsigned int &paddedIDStart);
103 
105  void mergeIncomingPSM();
106 
108  void injectCurrent(CurrentSource *source);
109 
110  //------------------------------------------------------------------------
111  // Public const methods
112  //------------------------------------------------------------------------
113  const std::string &getName() const{ return m_Name; }
114 
116  unsigned int getNumNeurons() const{ return m_NumNeurons; }
117  const std::pair<unsigned int, unsigned int> &getPaddedIDRange() const{ return m_PaddedIDRange; }
118  const std::pair<unsigned int, unsigned int> &getIDRange() const{ return m_IDRange; }
119 
121  const NeuronModels::Base *getNeuronModel() const{ return m_NeuronModel; }
122 
123  const std::vector<double> &getParams() const{ return m_Params; }
124  const std::vector<double> &getDerivedParams() const{ return m_DerivedParams; }
125  const std::vector<NewModels::VarInit> &getVarInitialisers() const{ return m_VarInitialisers; }
126 
128  const std::vector<SynapseGroup*> &getInSyn() const{ return m_InSyn; }
129  const std::vector<std::pair<SynapseGroup*, std::vector<SynapseGroup*>>> &getMergedInSyn() const{ return m_MergedInSyn; }
130 
132  const std::vector<SynapseGroup*> &getOutSyn() const{ return m_OutSyn; }
133 
135  const std::vector<CurrentSource*> &getCurrentSources() const { return m_CurrentSources; }
136 
137  int getClusterHostID() const{ return m_HostID; }
138 
139  int getClusterDeviceID() const{ return m_DeviceID; }
140 
141  bool isSpikeTimeRequired() const{ return m_SpikeTimeRequired; }
142  bool isTrueSpikeRequired() const{ return m_TrueSpikeRequired; }
143  bool isSpikeEventRequired() const{ return m_SpikeEventRequired; }
144 
145  bool isVarQueueRequired(const std::string &var) const;
146  bool isVarQueueRequired(size_t index) const{ return m_VarQueueRequired[index]; }
147 
148  const std::set<std::pair<std::string, std::string>> &getSpikeEventCondition() const{ return m_SpikeEventCondition; }
149 
150  unsigned int getNumDelaySlots() const{ return m_NumDelaySlots; }
151  bool isDelayRequired() const{ return (m_NumDelaySlots > 1); }
152 
153  bool isSpikeZeroCopyEnabled() const{ return (m_SpikeVarMode & VarLocation::ZERO_COPY); }
154  bool isSpikeEventZeroCopyEnabled() const{ return (m_SpikeEventVarMode & VarLocation::ZERO_COPY); }
155  bool isSpikeTimeZeroCopyEnabled() const{ return (m_SpikeTimeVarMode & VarLocation::ZERO_COPY); }
156  bool isZeroCopyEnabled() const;
157  bool isVarZeroCopyEnabled(const std::string &var) const{ return (getVarMode(var) & VarLocation::ZERO_COPY); }
158 
160  VarMode getSpikeVarMode() const{ return m_SpikeVarMode; }
161 
163  VarMode getSpikeEventVarMode() const{ return m_SpikeEventVarMode; }
164 
166  VarMode getSpikeTimeVarMode() const{ return m_SpikeTimeVarMode; }
167 
169  VarMode getVarMode(const std::string &varName) const;
170 
172  VarMode getVarMode(size_t index) const{ return m_VarMode[index]; }
173 
175  bool isParamRequiredBySpikeEventCondition(const std::string &pnamefull) const;
176 
177  void addExtraGlobalParams(std::map<std::string, std::string> &kernelParameters) const;
178 
180  bool isInitCodeRequired() const;
181 
183  bool isSimRNGRequired() const;
184 
186  bool isInitRNGRequired(VarInit varInitMode) const;
187 
189  bool isDeviceVarInitRequired() const;
190 
192  bool isDeviceInitRequired() const;
193 
195 
197  bool canRunOnCPU() const;
198 
200  bool hasOutputToHost(int targetHostID) const;
201 
203  std::string getCurrentQueueOffset(const std::string &devPrefix) const;
204 
206  std::string getPrevQueueOffset(const std::string &devPrefix) const;
207 
208 private:
209  //------------------------------------------------------------------------
210  // Private methods
211  //------------------------------------------------------------------------
213  void updateVarQueues(const std::string &code, const std::string &suffix);
214 
215  //------------------------------------------------------------------------
216  // Members
217  //------------------------------------------------------------------------
218  std::string m_Name;
219 
220  unsigned int m_NumNeurons;
221  std::pair<unsigned int, unsigned int> m_IDRange;
222  std::pair<unsigned int, unsigned int> m_PaddedIDRange;
223 
224  const NeuronModels::Base *m_NeuronModel;
225  std::vector<double> m_Params;
226  std::vector<double> m_DerivedParams;
227  std::vector<NewModels::VarInit> m_VarInitialisers;
228  std::vector<SynapseGroup*> m_InSyn;
229  std::vector<SynapseGroup*> m_OutSyn;
230  std::vector<std::pair<SynapseGroup*, std::vector<SynapseGroup*>>> m_MergedInSyn;
231  bool m_SpikeTimeRequired;
232  bool m_TrueSpikeRequired;
233  bool m_SpikeEventRequired;
234  std::set<std::pair<std::string, std::string>> m_SpikeEventCondition;
235  unsigned int m_NumDelaySlots;
236  std::vector<CurrentSource*> m_CurrentSources;
237 
239  std::vector<bool> m_VarQueueRequired;
240 
242  VarMode m_SpikeVarMode;
243 
245  VarMode m_SpikeEventVarMode;
246 
248  VarMode m_SpikeTimeVarMode;
249 
251  std::vector<VarMode> m_VarMode;
252 
254  int m_HostID;
255 
257  int m_DeviceID;
258 };
const std::pair< unsigned int, unsigned int > & getIDRange() const
Definition: neuronGroup.h:118
void setSpikeTimeZeroCopyEnabled(bool enabled)
Function to enable the use of zero-copied memory for spike times (deprecated use NeuronGroup::setSpik...
Definition: neuronGroup.h:68
void addInSyn(SynapseGroup *synapseGroup)
Definition: neuronGroup.h:98
Definition: neuronGroup.h:19
VarMode getVarMode(size_t index) const
Get variable mode used by neuron model state variable.
Definition: neuronGroup.h:172
void setSpikeEventZeroCopyEnabled(bool enabled)
Function to enable the use of zero-copied memory for spike-like events (deprecated use NeuronGroup::s...
Definition: neuronGroup.h:61
const std::vector< SynapseGroup * > & getInSyn() const
Gets pointers to all synapse groups which provide input to this neuron group.
Definition: neuronGroup.h:128
void setSpikeEventVarMode(VarMode mode)
Set variable mode used for variables containing this neuron group&#39;s output spike events.
Definition: neuronGroup.h:86
bool isDelayRequired() const
Definition: neuronGroup.h:151
bool isSpikeTimeZeroCopyEnabled() const
Definition: neuronGroup.h:155
NeuronGroup(const std::string &name, int numNeurons, const NeuronModels::Base *neuronModel, const std::vector< double > &params, const std::vector< NewModels::VarInit > &varInitialisers, int hostID, int deviceID)
Definition: neuronGroup.h:22
const std::vector< CurrentSource * > & getCurrentSources() const
Gets pointers to all current sources which provide input to this neuron group.
Definition: neuronGroup.h:135
void addExtraGlobalParams(std::map< std::string, std::string > &kernelParameters) const
Definition: neuronGroup.cc:191
unsigned int getNumNeurons() const
Gets number of neurons in group.
Definition: neuronGroup.h:116
const std::vector< SynapseGroup * > & getOutSyn() const
Gets pointers to all synapse groups emanating from this neuron group.
Definition: neuronGroup.h:132
Definition: global.h:43
bool isDeviceInitRequired() const
Is any form of device initialisation required?
Definition: neuronGroup.cc:311
VarMode getSpikeVarMode() const
Get variable mode used for variables containing this neuron group&#39;s output spikes.
Definition: neuronGroup.h:160
bool isSimRNGRequired() const
Does this neuron group require an RNG to simulate?
Definition: neuronGroup.cc:216
class for specifying a neuron model.
Definition: neuronModels.h:16
const std::pair< unsigned int, unsigned int > & getPaddedIDRange() const
Definition: neuronGroup.h:117
bool canRunOnCPU() const
Can this neuron group run on the CPU?
Definition: neuronGroup.cc:316
unsigned int getNumDelaySlots() const
Definition: neuronGroup.h:150
void calcSizes(unsigned int blockSize, unsigned int &idStart, unsigned int &paddedIDStart)
Definition: neuronGroup.cc:68
bool isVarQueueRequired(const std::string &var) const
Definition: neuronGroup.cc:154
bool isSpikeTimeRequired() const
Definition: neuronGroup.h:141
bool isDeviceVarInitRequired() const
Is device var init code required for any variables in this neuron group?
Definition: neuronGroup.cc:263
VarMode
Definition: variableMode.h:25
Global header file containing a few global variables. Part of the code generation section...
int getClusterDeviceID() const
Definition: neuronGroup.h:139
name
Definition: setup.py:112
std::string getPrevQueueOffset(const std::string &devPrefix) const
Get the expression to calculate the queue offset for accessing state of variables in previous timeste...
Definition: neuronGroup.cc:356
bool isTrueSpikeRequired() const
Definition: neuronGroup.h:142
VarMode getSpikeTimeVarMode() const
Get variable mode used for variables containing this neuron group&#39;s output spike times.
Definition: neuronGroup.h:166
void updatePostVarQueues(const std::string &code)
Update which postsynaptic variables require queues based on piece of code.
Definition: neuronGroup.cc:30
bool isVarQueueRequired(size_t index) const
Definition: neuronGroup.h:146
void setSpikeVarMode(VarMode mode)
Set variable mode used for variables containing this neuron group&#39;s output spikes.
Definition: neuronGroup.h:82
bool hasOutputToHost(int targetHostID) const
Does this neuron group have outgoing connections specified host id?
Definition: neuronGroup.cc:338
const NeuronModels::Base * getNeuronModel() const
Gets the neuron model used by this group.
Definition: neuronGroup.h:121
void updatePreVarQueues(const std::string &code)
Update which presynaptic variables require queues based on piece of code.
Definition: neuronGroup.cc:25
void addSpkEventCondition(const std::string &code, const std::string &supportCodeNamespace)
Definition: neuronGroup.cc:45
VarMode defaultVarMode
What is the default behaviour for model state variables? Historically, everything was allocated on bo...
Definition: global.cc:43
void setSpikeTimeVarMode(VarMode mode)
Set variable mode used for variables containing this neuron group&#39;s output spike times.
Definition: neuronGroup.h:90
const std::vector< NewModels::VarInit > & getVarInitialisers() const
Definition: neuronGroup.h:125
Definition: synapseGroup.h:19
void setSpikeZeroCopyEnabled(bool enabled)
Function to enable the use of zero-copied memory for spikes (deprecated use NeuronGroup::setSpikeVarM...
Definition: neuronGroup.h:54
const std::vector< std::pair< SynapseGroup *, std::vector< SynapseGroup * > > > & getMergedInSyn() const
Definition: neuronGroup.h:129
bool isZeroCopyEnabled() const
Definition: neuronGroup.cc:160
void checkNumDelaySlots(unsigned int requiredDelay)
Checks delay slots currently provided by the neuron group against a required delay and extends if req...
Definition: neuronGroup.cc:17
NeuronGroup()=delete
void setTrueSpikeRequired(bool req)
Definition: neuronGroup.h:49
bool isVarZeroCopyEnabled(const std::string &var) const
Definition: neuronGroup.h:157
const std::vector< double > & getParams() const
Definition: neuronGroup.h:123
bool isSpikeEventRequired() const
Definition: neuronGroup.h:143
VarMode getSpikeEventVarMode() const
Get variable mode used for variables containing this neuron group&#39;s output spike events.
Definition: neuronGroup.h:163
void addOutSyn(SynapseGroup *synapseGroup)
Definition: neuronGroup.h:99
bool isSpikeEventZeroCopyEnabled() const
Definition: neuronGroup.h:154
int getClusterHostID() const
Definition: neuronGroup.h:137
void setSpikeEventRequired(bool req)
Definition: neuronGroup.h:50
bool isInitRNGRequired(VarInit varInitMode) const
Does this neuron group require an RNG for it&#39;s init code?
Definition: neuronGroup.cc:243
void setVarMode(const std::string &varName, VarMode mode)
Set variable mode of neuron model state variable.
Definition: neuronGroup.cc:35
void injectCurrent(CurrentSource *source)
add input current source
Definition: neuronGroup.cc:363
std::string getCurrentQueueOffset(const std::string &devPrefix) const
Get the expression to calculate the queue offset for accessing state of variables this timestep...
Definition: neuronGroup.cc:349
bool isInitCodeRequired() const
Does this neuron group require any initialisation code to be run?
Definition: neuronGroup.cc:206
void mergeIncomingPSM()
Merge incoming postsynaptic models.
Definition: neuronGroup.cc:86
void initDerivedParams(double dt)
Definition: neuronGroup.cc:50
const std::string & getName() const
Definition: neuronGroup.h:113
const std::vector< double > & getDerivedParams() const
Definition: neuronGroup.h:124
bool isSpikeZeroCopyEnabled() const
Definition: neuronGroup.h:153
Base class for all neuron models.
Definition: newNeuronModels.h:31
bool isParamRequiredBySpikeEventCondition(const std::string &pnamefull) const
Do any of the spike event conditions tested by this neuron require specified parameter?
Definition: neuronGroup.cc:177
const std::set< std::pair< std::string, std::string > > & getSpikeEventCondition() const
Definition: neuronGroup.h:148
void setSpikeTimeRequired(bool req)
Definition: neuronGroup.h:48
VarMode getVarMode(const std::string &varName) const
Get variable mode used by neuron model state variable.
Definition: neuronGroup.cc:40
void setVarZeroCopyEnabled(const std::string &varName, bool enabled)
Function to enable the use zero-copied memory for a particular state variable (deprecated use NeuronG...
Definition: neuronGroup.h:75
VarInit
Definition: variableMode.h:18
Definition: currentSource.h:17