GeNN  4.9.0
GPU enhanced Neuronal Networks (GeNN)
logOutput.h
Go to the documentation of this file.
1 #pragma once
2 
3 // Standard C++ includes
4 #include <fstream>
5 #include <set>
6 #include <string>
7 #include <vector>
8 
9 // SpineML simulator includes
10 #include "modelProperty.h"
11 #include "networkClient.h"
12 
13 // Forward declarations
14 namespace pugi
15 {
16  class xml_node;
17 }
18 
19 namespace filesystem
20 {
21  class path;
22 }
23 
24 //----------------------------------------------------------------------------
25 // SpineMLSimulator::LogOutput::Base
26 //----------------------------------------------------------------------------
27 namespace SpineMLSimulator
28 {
29 namespace LogOutput
30 {
31 class Base
32 {
33 public:
34  Base(const pugi::xml_node &node, double dt);
35  virtual ~Base(){}
36 
37  //----------------------------------------------------------------------------
38  // Declared virtuals
39  //----------------------------------------------------------------------------
40  // Record any data required during this timestep
41  virtual void record(double dt, unsigned long long timestep) = 0;
42 
43 protected:
44  //----------------------------------------------------------------------------
45  // Protected API
46  //----------------------------------------------------------------------------
47  bool shouldRecord(unsigned long long timestep) const
48  {
49  return (timestep >= m_StartTimeStep && timestep < m_EndTimeStep);
50  }
51 
52  unsigned long long getEndTimestep() const{ return m_EndTimeStep; }
53 
54 private:
55  //----------------------------------------------------------------------------
56  // Members
57  //----------------------------------------------------------------------------
58  unsigned long long m_StartTimeStep;
59  unsigned long long m_EndTimeStep;
60 };
61 
62 //----------------------------------------------------------------------------
63 // SpineMLSimulator::LogOutput::AnalogueBase
64 //----------------------------------------------------------------------------
65 class AnalogueBase : public Base
66 {
67 public:
68  AnalogueBase(const pugi::xml_node &node, double dt,
69  const ModelProperty::Base *modelProperty);
70 
71  //----------------------------------------------------------------------------
72  // Public API
73  //----------------------------------------------------------------------------
74  const scalar *getStateVarBegin() const{ return m_ModelProperty->getHostStateVar(); }
75  const scalar *getStateVarEnd() const{ return (m_ModelProperty->getHostStateVar() + m_ModelProperty->getSize()); }
76 
77  unsigned int getModelPropertySize() const{ return m_ModelProperty->getSize(); }
78 
79  const std::vector<unsigned int> &getIndices() const{ return m_Indices; }
80 
81 protected:
82  //----------------------------------------------------------------------------
83  // Protected API
84  //----------------------------------------------------------------------------
85  void pullModelPropertyFromDevice() const{ m_ModelProperty->pullFromDevice(); }
86 
87 private:
88  //----------------------------------------------------------------------------
89  // Members
90  //----------------------------------------------------------------------------
91  // The property that is being logged
92  const ModelProperty::Base *m_ModelProperty;
93 
94  // Which members of population to log (all if empty)
95  std::vector<unsigned int> m_Indices;
96 };
97 
98 //----------------------------------------------------------------------------
99 // SpineMLSimulator::LogOutput::AnalogueFile
100 //----------------------------------------------------------------------------
102 {
103 public:
104  AnalogueFile(const pugi::xml_node &node, double dt, unsigned long long numTimeSteps,
105  const std::string &port, unsigned int popSize,
106  const filesystem::path &logPath,
107  const ModelProperty::Base *modelProperty);
108 
109  //----------------------------------------------------------------------------
110  // Base virtuals
111  //----------------------------------------------------------------------------
112  // Record any data required during this timestep
113  virtual void record(double dt, unsigned long long timestep) override;
114 
115 private:
116  //----------------------------------------------------------------------------
117  // Members
118  //----------------------------------------------------------------------------
119  std::ofstream m_File;
120 
121  // Buffer used, if indices are in use, to store contiguous output data
122  std::vector<scalar> m_OutputBuffer;
123 };
124 
125 //----------------------------------------------------------------------------
126 // SpineMLSimulator::LogOutput::AnalogueNetwork
127 //----------------------------------------------------------------------------
129 {
130 public:
131  AnalogueExternal(const pugi::xml_node &node, double dt,
132  const std::string &port, unsigned int popSize,
133 
134  const filesystem::path &logPath,
135  const ModelProperty::Base *modelProperty);
136 
137  //----------------------------------------------------------------------------
138  // Base virtuals
139  //----------------------------------------------------------------------------
140  // Record any data required during this timestep
141  virtual void record(double dt, unsigned long long timestep) final;
142 
143 protected:
144  //----------------------------------------------------------------------------
145  // Declared virtuals
146  //----------------------------------------------------------------------------
147  virtual void recordInternal(){}
148 
149 private:
150  //----------------------------------------------------------------------------
151  // Members
152  //----------------------------------------------------------------------------
153  // How many GeNN timesteps do we wait before logging
154  unsigned int m_IntervalTimesteps;
155 
156  // Count down to next time we log
157  unsigned int m_CurrentIntervalTimesteps;
158 };
159 
160 //----------------------------------------------------------------------------
161 // SpineMLSimulator::LogOutput::AnalogueNetwork
162 //----------------------------------------------------------------------------
164 {
165 public:
166  AnalogueNetwork(const pugi::xml_node &node, double dt,
167  const std::string &port, unsigned int popSize,
168  const filesystem::path &logPath,
169  const ModelProperty::Base *modelProperty);
170 
171 protected:
172  //----------------------------------------------------------------------------
173  // AnalogueExternal virtuals
174  //----------------------------------------------------------------------------
175  virtual void recordInternal() override;
176 
177 private:
178  //----------------------------------------------------------------------------
179  // Members
180  //----------------------------------------------------------------------------
181  NetworkClient m_Client;
182 
183  // Buffer used to generate contiguous output data
184  // **NOTE** network protocol always uses double precision
185  std::vector<double> m_OutputBuffer;
186 };
187 
188 //----------------------------------------------------------------------------
189 // SpineMLSimulator::LogOutput::Event
190 //----------------------------------------------------------------------------
191 class Event : public Base
192 {
193 public:
194  Event(const pugi::xml_node &node, double dt, unsigned long long numTimeSteps,
195  const std::string &port, unsigned int popSize,
196  const filesystem::path &logPath, unsigned int *spikeQueuePtr,
197  unsigned int *hostSpikeCount, unsigned int *hostSpikes,
198  void (*pullCurrentSpikesFunc)(void));
199 
200  //----------------------------------------------------------------------------
201  // Base virtuals
202  //----------------------------------------------------------------------------
203  // Record any data required during this timestep
204  virtual void record(double dt, unsigned long long timestep) override;
205 
206 private:
207  //----------------------------------------------------------------------------
208  // Members
209  //----------------------------------------------------------------------------
210  std::ofstream m_File;
211 
212  const unsigned int m_PopSize;
213 
214  unsigned int *m_SpikeQueuePtr;
215  unsigned int *m_HostSpikeCount;
216  unsigned int *m_HostSpikes;
217 
218  void (*m_PullCurrentSpikesFunc)(void);
219 
220  std::set<unsigned int> m_Indices;
221 };
222 } // namespace LogOutput
223 } // namespace SpineMLSimulator
unsigned long long getEndTimestep() const
Definition: logOutput.h:52
Definition: networkClient.h:27
Definition: logOutput.h:191
bool shouldRecord(unsigned long long timestep) const
Definition: logOutput.h:47
const std::vector< unsigned int > & getIndices() const
Definition: logOutput.h:79
Definition: modelProperty.h:30
virtual ~Base()
Definition: logOutput.h:35
const scalar * getStateVarBegin() const
Definition: logOutput.h:74
const scalar * getStateVarEnd() const
Definition: logOutput.h:75
unsigned int getModelPropertySize() const
Definition: logOutput.h:77
Definition: logOutput.h:31
Definition: connectors.h:25
virtual void recordInternal()
Definition: logOutput.h:147
void pullModelPropertyFromDevice() const
Definition: logOutput.h:85
Definition: generateModules.h:16
Definition: connectors.h:12
float scalar
Definition: modelProperty.h:27