GeNN  4.9.0
GPU enhanced Neuronal Networks (GeNN)
simulator.h
Go to the documentation of this file.
1 #pragma once
2 
3 // Standard C++ includes
4 #include <map>
5 #include <set>
6 #include <string>
7 #include <tuple>
8 
9 // PLOG includes
10 #include <plog/Severity.h>
11 #include <plog/Appenders/ConsoleAppender.h>
12 
13 // SpineML simulator includes
14 #include "input.h"
15 #include "inputValue.h"
16 #include "logOutput.h"
17 #include "modelProperty.h"
18 
19 //----------------------------------------------------------------------------
20 // SpineMLSimulator::Simulator
21 //----------------------------------------------------------------------------
22 namespace SpineMLSimulator
23 {
24 class Simulator
25 {
26 public:
27  Simulator(plog::Severity logLevel = plog::warning);
28  Simulator(const std::string &experimentXML, const std::string &overrideOutputPath = "", plog::Severity logLevel = plog::warning);
29  ~Simulator();
30 
31  //------------------------------------------------------------------------
32  // Public API
33  //------------------------------------------------------------------------
35  void load(const std::string &experimentXML, const std::string &overrideOutputPath = "");
36 
38  void stepTime();
39 
41  const LogOutput::AnalogueExternal *getExternalLogger(const std::string &name) const;
42 
44  InputValue::External *getExternalInput(const std::string &name) const;
45 
47  double getDT() const{ return m_DT; }
48 
50  double getDurationMs() const{ return m_DurationMs; }
51 
53  double getInputMs() const{ return m_InputMs; }
54  double getSimulateMs() const{ return m_SimulateMs; }
55  double getLogMs() const{ return m_LogMs; }
56 
58  double getNeuronUpdateTime() const;
59  double getInitTime() const;
60  double getPresynapticUpdateTime() const;
61  double getPostsynapticUpdateTime() const;
62  double getSynapseDynamicsTime() const;
63  double getInitSparseTime() const;
64 
66  unsigned long long calcNumTimesteps() const
67  {
68  return (unsigned long long)std::ceil(getDurationMs() / getDT());
69  }
70 
71 private:
72  //------------------------------------------------------------------------
73  // Typedefines
74  //------------------------------------------------------------------------
76 #ifdef _WIN32
77  typedef HMODULE LibraryHandle;
78 #else
79  typedef void* LibraryHandle;
80 #endif
81 
83  typedef void (*VoidFunction)(void);
84 
86  typedef std::map<std::string, std::pair<std::set<std::string>, std::set<std::string>>> ComponentEventPorts;
87 
89 
90  typedef std::tuple<unsigned int*, unsigned int*, unsigned int*, VoidFunction, VoidFunction> NeuronPopSpikeVars;
91 
92  //------------------------------------------------------------------------
93  // Private functions
94  //------------------------------------------------------------------------
96 
97  void *getLibrarySymbol(const char *name, bool allowMissing = false) const;
98 
99 
100  NeuronPopSpikeVars getNeuronPopSpikeVars(const std::string &popName) const;
101 
102  void addPropertiesAndSizes(const filesystem::path &basePath, const pugi::xml_node &node,
103  const pugi::xml_node &modelNode, const std::string &geNNPopName,
104  unsigned int popSize, std::map<std::string, unsigned int> &sizes,
105  const std::vector<unsigned int> *remapIndices = nullptr);
106 
108  std::unique_ptr<Input::Base> createInput(const pugi::xml_node &node,
109  const std::map<std::string, unsigned int> &componentSizes,
110  const std::map<std::string, std::string> &componentURLs,
111  const ComponentEventPorts &componentEventPorts);
112 
113  std::unique_ptr<LogOutput::Base> createLogOutput(const pugi::xml_node &node, const filesystem::path &logPath,
114  const std::map<std::string, unsigned int> &componentSizes,
115  const std::map<std::string, std::string> &componentURLs,
116  const ComponentEventPorts &componentEventPorts);
117 
119  unsigned int getComponentSize(const std::string &componentName,
120  const std::map<std::string, unsigned int> &componentSizes);
121 
123  bool isEventSendPort(const std::string &targetName, const std::string &portName,
124  const std::map<std::string, std::string> &componentURLs,
125  const ComponentEventPorts &componentEventPorts) const;
126 
128  bool isEventReceivePort(const std::string &targetName, const std::string &portName,
129  const std::map<std::string, std::string> &componentURLs,
130  const ComponentEventPorts &componentEventPorts) const;
131 
134  void addEventPorts(const filesystem::path &basePath, const pugi::xml_node &node,
135  std::map<std::string, std::string> &componentURLs,
136  ComponentEventPorts &componentEventPorts);
137 
138  //------------------------------------------------------------------------
139  // Members
140  //------------------------------------------------------------------------
142  LibraryHandle m_ModelLibrary;
143 
145  VoidFunction m_StepTime;
146 
148  float *m_SimulationTime;
149 
151  unsigned long long *m_SimulationTimestep;
152 
154  double m_DT;
155 
157  double m_DurationMs;
158 
160  double m_InputMs;
161  double m_SimulateMs;
162  double m_LogMs;
163 
165  std::vector<std::unique_ptr<LogOutput::Base>> m_Loggers;
166 
168  std::vector<std::unique_ptr<Input::Base>> m_Inputs;
169 
171  std::map<std::string, std::map<std::string, std::unique_ptr<ModelProperty::Base>>> m_ComponentProperties;
172 
174  std::map<std::string, const LogOutput::AnalogueExternal*> m_ExternalLoggers;
175 
177  std::map<std::string, InputValue::External*> m_ExternalInputs;
178 
180  plog::ConsoleAppender<plog::TxtFormatter> m_ConsoleAppender;
181 };
182 } // namespace SpineMLSimulator
double getInitSparseTime() const
Definition: simulator.cc:417
double getNeuronUpdateTime() const
Timings of individual kernels provided by GeNN.
Definition: simulator.cc:392
double getLogMs() const
Definition: simulator.h:55
const LogOutput::AnalogueExternal * getExternalLogger(const std::string &name) const
Get an external logger by name.
Definition: simulator.cc:370
~Simulator()
Definition: simulator.cc:70
InputValue::External * getExternalInput(const std::string &name) const
Get an external input by name.
Definition: simulator.cc:381
double getSynapseDynamicsTime() const
Definition: simulator.cc:412
Definition: simulator.h:24
void stepTime()
Advance simulation by one timestep.
Definition: simulator.cc:329
double getInputMs() const
Get the total times accumulated in each stage of the simulation.
Definition: simulator.h:53
double getDurationMs() const
Get duration of simulation read from experiment in ms.
Definition: simulator.h:50
Simulator(plog::Severity logLevel=plog::warning)
Definition: simulator.cc:57
double getInitTime() const
Definition: simulator.cc:397
Definition: connectors.h:25
void load(const std::string &experimentXML, const std::string &overrideOutputPath="")
Load model from XML file.
Definition: simulator.cc:82
unsigned long long calcNumTimesteps() const
Calculate duration of simulation read from experiment in timesteps.
Definition: simulator.h:66
double getDT() const
Get the simulation timestep (in ms)
Definition: simulator.h:47
Definition: inputValue.h:162
double getPresynapticUpdateTime() const
Definition: simulator.cc:402
double getPostsynapticUpdateTime() const
Definition: simulator.cc:407
double getSimulateMs() const
Definition: simulator.h:54