-
Notifications
You must be signed in to change notification settings - Fork 371
/
Copy pathmodel_manager.h
331 lines (281 loc) · 10 KB
/
model_manager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/*
* model_manager.h
*
* This file is part of NEST.
*
* Copyright (C) 2004 The NEST Initiative
*
* NEST is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* NEST is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NEST. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef MODEL_MANAGER_H
#define MODEL_MANAGER_H
// C++ includes:
#include <string>
// Includes from nestkernel:
#include "connector_model.h"
#include "genericmodel.h"
#include "manager_interface.h"
#include "model.h"
#include "nest.h"
#include "nest_time.h"
#include "nest_timeconverter.h"
#include "nest_types.h"
#include "node.h"
// Includes from sli:
#include "dictutils.h"
namespace nest
{
class ModelManager : public ManagerInterface
{
public:
ModelManager();
~ModelManager() override;
void initialize( const bool ) override;
void finalize( const bool ) override;
void set_status( const DictionaryDatum& ) override;
void get_status( DictionaryDatum& ) override;
/**
* Resize the structures for the Connector objects if necessary.
*
* This function should be called after number of threads, min_delay,
* max_delay, and time representation have been changed in the scheduler.
* The TimeConverter is used to convert times from the old to the new
* representation. It is also forwarding the calibration
* request to all ConnectorModel objects.
*/
void calibrate( const TimeConverter& );
/**
* Return a proxynode configured for thread tid and the given
* node_id.
*/
Node* get_proxy_node( size_t tid, size_t node_id );
/**
* Return pointer to protoype for given synapse id.
*
* @throws UnknownSynapseType
*
* @todo: make the return type const, after the increment of
* num_connections and the min_ and max_delay setting in
* ConnectorBase was moved out to the ConnectionManager
*/
ConnectorModel& get_connection_model( synindex syn_id, size_t thread_id );
const std::vector< ConnectorModel* >& get_connection_models( size_t tid );
/**
* Register a node-model prototype.
*
* This function must be called exactly once for each model class to make
* it known in the simulator. The natural place for a call to this function
* is in a *module.cpp file.
* @param name of the new node model.
* @param deprecation_info If non-empty string, deprecation warning will
* be issued for model with this info to user.
* @return ID of the new model object.
* @see register_connection_model
*/
template < class ModelT >
size_t register_node_model( const Name& name, std::string deprecation_info = std::string() );
/**
* Register a synape model with a custom Connector model and without any
* common properties.
*
* "hpc synapses" use `TargetIdentifierIndex` for `ConnectionT` and store
* the target neuron in form of a 2 Byte index instead of an 8 Byte pointer.
* This limits the number of thread local neurons to 65,536. No support for
* different receptor types. Otherwise identical to non-hpc version.
*
* When called, this function should be specialised by a class template,
* e.g. `bernoulli_synapse< targetidentifierT >`
*
* @param name The name under which the ConnectorModel will be registered.
*/
template < template < typename targetidentifierT > class ConnectionT >
void register_connection_model( const std::string& name );
/**
* Copy an existing model and register it as a new model.
*
* This function allows users to create their own, cloned models.
* @param old_name name of existing model.
* @param new_name name of new model.
* @param params default parameters of new model.
* @see copy_node_model_, copy_connection_model_
*/
void copy_model( Name old_name, Name new_name, DictionaryDatum params );
/**
* Set the default parameters of a model.
*
* @param name of model.
* @param params default parameters to be set.
* @return true if the operation succeeded, else false
* @see set_node_defaults_, set_synapse_defaults_
*/
bool set_model_defaults( Name name, DictionaryDatum params );
/**
* @return The model ID for a Model with a given name
* @throws UnknownModelName if the model is not available
*/
size_t get_node_model_id( const Name ) const;
/**
* @return The Model registered with the given model ID
*/
Model* get_node_model( size_t ) const;
/**
* @return The numeric ID of a given synapse model
* @throws UnknownSynapseType if the model is not available
*/
size_t get_synapse_model_id( std::string model_name );
DictionaryDatum get_connector_defaults( synindex syn_id ) const;
void set_connector_defaults( synindex syn_id, const DictionaryDatum& d );
/**
* Asserts validity of synapse index, otherwise throws exception.
* @throws UnknownSynapseType
*/
void assert_valid_syn_id( synindex syn_id, size_t t = 0 ) const;
bool are_model_defaults_modified() const;
size_t get_num_connection_models() const;
/**
* Print out the memory information for each node model.
*/
void memory_info() const;
SecondaryEvent& get_secondary_event_prototype( const synindex syn_id, const size_t tid );
private:
/**
* Delete all models and clear the modeldict
*
* This function deletes all models, which will as a side-effect also
* delete all nodes. The built-in models will be re-registered in
* initialize()
*/
void clear_node_models_();
void clear_connection_models_();
size_t register_node_model_( Model* model );
template < typename CompleteConnecionT >
void register_specific_connection_model_( const std::string& name );
/**
* Copy an existing node model and register it as a new model.
*
* @param old_id ID of existing model.
* @param new_name name of new model.
* @see copy_model(), copy_connection_model_()
*/
void copy_node_model_( const size_t old_id, Name new_name, DictionaryDatum params );
/**
* Copy an existing synapse model and register it as a new model.
*
* @param old_id ID of existing model.
* @param new_name name of new model.
* @see copy_model(), copy_node_model_()
*/
void copy_connection_model_( const size_t old_id, Name new_name, DictionaryDatum params );
/**
* Set the default parameters of a model.
*
* @param model_id of model.
* @param params default parameters to be set.
* @see set_model_defaults, set_synapse_defaults_
*/
void set_node_defaults_( size_t model_id, const DictionaryDatum& params );
/**
* Set the default parameters of a model.
*
* @param name of model.
* @param params default parameters to be set.
* @see set_model_defaults, set_node_defaults_
*/
void set_synapse_defaults_( size_t model_id, const DictionaryDatum& params );
//! Compares model ids for sorting in memory_info
static bool compare_model_by_id_( const int a, const int b );
/**
* List of node models.
*
* The list contains all built-in node models requested for
* compilation using -Dwith-models or -Dwith-modelset, models
* registered from within extension modules, and models created by
* calls to CopyModel().
*
* This list is cleared and built-in models are re-registered upon
* calls to ResetKernel, while those registered from user-modules
* and copies are not.
*
* The elements of this list are used to create instances and are
* responsible for the storage of model defaults.
*/
std::vector< Model* > node_models_;
/**
* The list of connection models.
*
* This list contains all built-in connection models requested for
* compilation using -Dwith-models or -Dwith-modelset, models
* registered from within extension modules, and models created by
* calls to CopyModel().
*
* The first dimension is thread-optimitzed by containing one vector
* with all models per thread, as to avoid colliding memory accesses
* during connection creation.
*
* This list is cleared and built-in models are re-registered upon
* calls to ResetKernel, while those registered from user-modules
* and copies are not.
*
* The elements of this list are used to create instances and are
* responsible for the storage of model defaults.
*/
std::vector< std::vector< ConnectorModel* > > connection_models_;
DictionaryDatum modeldict_; //!< Dictionary of all node models
DictionaryDatum synapsedict_; //!< Dictionary of all synapse models
Model* proxynode_model_;
Node* create_proxynode_( size_t t, int model_id );
//! Placeholders for remote nodes, one per thread
std::vector< std::vector< Node* > > proxy_nodes_;
//! True if any model defaults have been modified
bool model_defaults_modified_;
};
inline Model*
ModelManager::get_node_model( size_t m ) const
{
assert( m < node_models_.size() );
return node_models_[ m ];
}
inline bool
ModelManager::are_model_defaults_modified() const
{
return model_defaults_modified_;
}
inline ConnectorModel&
ModelManager::get_connection_model( synindex syn_id, size_t thread_id )
{
assert_valid_syn_id( syn_id );
return *( connection_models_[ thread_id ][ syn_id ] );
}
inline const std::vector< ConnectorModel* >&
ModelManager::get_connection_models( size_t tid )
{
return connection_models_[ tid ];
}
inline void
ModelManager::assert_valid_syn_id( synindex syn_id, size_t t ) const
{
if ( syn_id >= connection_models_[ t ].size() or not connection_models_[ t ][ syn_id ] )
{
throw UnknownSynapseType( syn_id );
}
}
inline SecondaryEvent&
ModelManager::get_secondary_event_prototype( const synindex syn_id, const size_t tid )
{
assert_valid_syn_id( syn_id );
return *get_connection_model( syn_id, tid ).get_secondary_event();
}
} // namespace nest
#endif /* MODEL_MANAGER_H */