GeNN  4.9.0
GPU enhanced Neuronal Networks (GeNN)
input.h
Go to the documentation of this file.
1 #pragma once
2 
3 // Standard C++ includes
4 #include <functional>
5 #include <map>
6 #include <memory>
7 #include <random>
8 
9 // Forward declarations
10 namespace pugi
11 {
12  class xml_node;
13 }
14 
15 namespace SpineMLSimulator
16 {
17  namespace InputValue
18  {
19  class Base;
20  }
21 
22  namespace ModelProperty
23  {
24  class Base;
25  }
26 }
27 
28 //----------------------------------------------------------------------------
29 // SpineMLSimulator::Input::Base
30 //----------------------------------------------------------------------------
31 namespace SpineMLSimulator
32 {
33 namespace Input
34 {
35 class Base
36 {
37 public:
38  virtual ~Base();
39 
40  //----------------------------------------------------------------------------
41  // Declared virtuals
42  //----------------------------------------------------------------------------
43  virtual void apply(double dt, unsigned long long timestep) = 0;
44 
45 protected:
46  Base(double dt, const pugi::xml_node &node, std::unique_ptr<InputValue::Base> value);
47 
48  //----------------------------------------------------------------------------
49  // Protected API
50  //----------------------------------------------------------------------------
51  bool shouldApply(unsigned long long timestep) const
52  {
53  return (timestep >= m_StartTimeStep && timestep < m_EndTimeStep);
54  }
55 
56  void updateValues(double dt, unsigned long long timestep,
57  std::function<void(unsigned int, double)> applyValueFunc) const;
58 
59 private:
60  //----------------------------------------------------------------------------
61  // Members
62  //----------------------------------------------------------------------------
63  unsigned long long m_StartTimeStep;
64  unsigned long long m_EndTimeStep;
65 
66  std::unique_ptr<InputValue::Base> m_Value;
67 };
68 
69 //----------------------------------------------------------------------------
70 // SpineMLSimulator::Input::SpikeBase
71 //----------------------------------------------------------------------------
72 class SpikeBase : public Base
73 {
74 protected:
75  typedef void (*PushCurrentSpikesFunc)();
76 
77  SpikeBase(double dt, const pugi::xml_node &node, std::unique_ptr<InputValue::Base> value,
78  unsigned int popSize, unsigned int *spikeQueuePtr, unsigned int *hostSpikeCount, unsigned int *hostSpikes,
79  PushCurrentSpikesFunc pushCurrentSpikes);
80 
81  //----------------------------------------------------------------------------
82  // Protected API
83  //----------------------------------------------------------------------------
84  void injectSpike(unsigned int neuronID);
85 
86  void uploadSpikes();
87 
88 private:
89  //----------------------------------------------------------------------------
90  // Private API
91  //----------------------------------------------------------------------------
92  unsigned int getSpikeQueueIndex() const
93  {
94  return (m_SpikeQueuePtr == nullptr) ? 0 : *m_SpikeQueuePtr;
95  }
96 
97  //----------------------------------------------------------------------------
98  // Members
99  //----------------------------------------------------------------------------
100  const unsigned int m_PopSize;
101 
102  unsigned int *m_SpikeQueuePtr;
103  unsigned int *m_HostSpikeCount;
104  unsigned int *m_HostSpikes;
105  PushCurrentSpikesFunc m_PushCurrentSpikes;
106 };
107 
108 //----------------------------------------------------------------------------
109 // SpineMLSimulator::Input::InterSpikeIntervalBase
110 //----------------------------------------------------------------------------
112 {
113 public:
114  //----------------------------------------------------------------------------
115  // Base virtuals
116  //----------------------------------------------------------------------------
117  virtual void apply(double dt, unsigned long long timestep) override;
118 
119 protected:
120  InterSpikeIntervalBase(double dt, const pugi::xml_node &node, std::unique_ptr<InputValue::Base> value,
121  unsigned int popSize, unsigned int *spikeQueuePtr, unsigned int *hostSpikeCount, unsigned int *hostSpikes,
122  PushCurrentSpikesFunc pushCurrentSpikes);
123 
124  //----------------------------------------------------------------------------
125  // Declared virtuals
126  //----------------------------------------------------------------------------
127  virtual double getTimeToSpike(double isiMs) = 0;
128 
129 private:
130  //----------------------------------------------------------------------------
131  // Members
132  //----------------------------------------------------------------------------
133  std::map<unsigned int, std::pair<double, double>> m_TimeToSpike;
134 };
135 
136 //----------------------------------------------------------------------------
137 // SpineMLSimulator::Input::RegularSpikeRate
138 //----------------------------------------------------------------------------
140 {
141 public:
142  RegularSpikeRate(double dt, const pugi::xml_node &node, std::unique_ptr<InputValue::Base> value,
143  unsigned int popSize, unsigned int *spikeQueuePtr, unsigned int *hostSpikeCount, unsigned int *hostSpikes,
144  PushCurrentSpikesFunc pushCurrentSpikes);
145 
146 protected:
147  //----------------------------------------------------------------------------
148  // InterSpikeIntervalBase virtuals
149  //----------------------------------------------------------------------------
150  virtual double getTimeToSpike(double isiMs) override;
151 };
152 
153 //----------------------------------------------------------------------------
154 // SpineMLSimulator::Input::PoissonSpikeRate
155 //----------------------------------------------------------------------------
157 {
158 public:
159  PoissonSpikeRate(double dt, const pugi::xml_node &node, std::unique_ptr<InputValue::Base> value,
160  unsigned int popSize, unsigned int *spikeQueuePtr, unsigned int *hostSpikeCount, unsigned int *hostSpikes,
161  PushCurrentSpikesFunc pushCurrentSpikes);
162 
163 protected:
164  //----------------------------------------------------------------------------
165  // InterSpikeIntervalBase virtuals
166  //----------------------------------------------------------------------------
167  virtual double getTimeToSpike(double isiMs);
168 
169 private:
170  //----------------------------------------------------------------------------
171  // Members
172  //----------------------------------------------------------------------------
173  std::mt19937 m_RandomGenerator;
174 };
175 
176 //----------------------------------------------------------------------------
177 // SpineMLSimulator::Input::SpikeTime
178 //----------------------------------------------------------------------------
179 class SpikeTime : public SpikeBase
180 {
181 public:
182  SpikeTime(double dt, const pugi::xml_node &node, std::unique_ptr<InputValue::Base> value,
183  unsigned int popSize, unsigned int *spikeQueuePtr, unsigned int *hostSpikeCount, unsigned int *hostSpikes,
184  PushCurrentSpikesFunc pushCurrentSpikes);
185 
186  //----------------------------------------------------------------------------
187  // SpikeBase virtuals
188  //----------------------------------------------------------------------------
189  virtual void apply(double dt, unsigned long long timestep) override;
190 };
191 
192 //----------------------------------------------------------------------------
193 // SpineMLSimulator::Input::Analogue
194 //----------------------------------------------------------------------------
195 class Analogue : public Base
196 {
197 public:
198  Analogue(double dt, const pugi::xml_node &node, std::unique_ptr<InputValue::Base> value,
199  ModelProperty::Base *modelProperty);
200 
201  //----------------------------------------------------------------------------
202  // Base virtuals
203  //----------------------------------------------------------------------------
204  virtual void apply(double dt, unsigned long long timestep) override;
205 
206 private:
207  //----------------------------------------------------------------------------
208  // Members
209  //----------------------------------------------------------------------------
211  bool m_PropertyUpdateRequired;
212 
213  ModelProperty::Base *m_ModelProperty;
214 
215  // Current values to apply
216  std::map<unsigned int, double> m_CurrentValues;
217 };
218 
219 } // namespace Input
220 } // namespace SpineMLSimulator
Definition: inputValue.h:26
Definition: modelProperty.h:30
bool shouldApply(unsigned long long timestep) const
Definition: input.h:51
Definition: connectors.h:25
Definition: input.h:35
Definition: connectors.h:12
Definition: input.h:179
Definition: input.h:195