Auryn simulator  v0.8.1-206-gb56e451
Plastic Spiking Neural Network Simulator
auryn_definitions.h
Go to the documentation of this file.
1 /*
2 * Copyright 2014-2018 Friedemann Zenke
3 *
4 * This file is part of Auryn, a simulation package for plastic
5 * spiking neural networks.
6 *
7 * Auryn is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * Auryn is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Auryn. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * If you are using Auryn or parts of it for your work please cite:
21 * Zenke, F. and Gerstner, W., 2014. Limits to high-speed simulations
22 * of spiking neural networks using general-purpose computers.
23 * Front Neuroinform 8, 76. doi: 10.3389/fninf.2014.00076
24 */
25 
26 #ifndef AURYN_DEFINITIONS_H_
27 #define AURYN_DEFINITIONS_H_
28 
29 
33 #define AURYN_CODE_USE_MPI
34 
35 
38 #define CODE_ALIGNED_SIMD_INSTRUCTIONS
39 
44 #define CODE_ACTIVATE_PREFETCHING_INTRINSICS
45 
51 #define CODE_USE_SIMD_INSTRUCTIONS_EXPLICITLY
52 
58 // #define CODE_ACTIVATE_CILK_INSTRUCTIONS
59 
64 #define SIMD_NUM_OF_PARALLEL_FLOAT_OPERATIONS 4
65 
70 // #define CODE_COLLECT_SYNC_TIMING_STATS //!< toggle collection of timing data on sync/all_gather
71 
72 
82 #define MINDELAY 8
83 
90 #define DEFAULT_MINDISTRIBUTEDSIZE 16
91 
92 
95 #define DEFAULT_TRACE_MODEL Trace
96 #define PRE_TRACE_MODEL Trace
97 
98 
99 //* -- End of precompiler options -- *//
100 
101 
102 #include <iostream>
103 #include <iomanip>
104 #include <string>
105 #include <cmath>
106 #include <cstdlib>
107 #include <list>
108 #include <exception>
109 #include <limits>
110 
111 #ifdef CODE_USE_SIMD_INSTRUCTIONS_EXPLICITLY
112 #ifndef CODE_ACTIVATE_CILK_INSTRUCTIONS
113 #include <x86intrin.h> // SIMD intrinsics (pulls everything you need)
114 #else // XMM registers are not supported on the phi platform
115 #include <immintrin.h> // AVX only
116 #endif /* CODE_ACTIVATE_CILK_INSTRUCTIONS */
117 #endif /* CODE_USE_SIMD_INSTRUCTIONS_EXPLICITLY */
118 
119 #ifdef AURYN_CODE_USE_MPI
120 #include <boost/mpi.hpp>
121 namespace mpi = boost::mpi;
122 #endif
123 
124 
125 #include "Logger.h"
126 
127 
128 namespace auryn {
129 
134  extern double auryn_timestep;
135 
143  MEM,
145  };
146 
149 
150 
151  typedef unsigned int NeuronID;
152  typedef NeuronID AurynInt;
153  typedef unsigned int StateID;
154  typedef unsigned long AurynLong;
155  typedef NeuronID AurynTime;
156  typedef std::string string;
157  typedef float AurynFloat;
158  typedef double AurynDouble;
159  typedef AurynFloat AurynWeight;
160  typedef AurynFloat AurynState;
161  typedef std::vector<NeuronID> SpikeContainer;
162  typedef std::vector<float> AttributeContainer;
163 
164 
165 
167  struct neuron_pair {
168  NeuronID i,j;
169  } ;
170 
172  struct pattern_member {
173  NeuronID i;
174  AurynDouble gamma;
175  } ;
176 
177  typedef std::vector<pattern_member> type_pattern;
178 
179 
180 
181 
188  int auryn_AlignOffset (const int N, const void *vp, const int inc, const int align);
189 
191  NeuronID calculate_vector_size(NeuronID i);
192 
195  {
196  AurynTime time;
197  NeuronID neuronID;
198  };
199 
202  {
203  AurynTime time;
204  AurynState value;
205  };
206 
207  // Exceptions
208  class AurynOpenFileException: public std::exception
209  {
210  virtual const char* what() const throw()
211  {
212  return "Failed opening file.";
213  }
214  };
215 
216  class AurynMMFileException: public std::exception
217  {
218  virtual const char* what() const throw()
219  {
220  return "Problem reading MatrixMarket file. Not row major format?";
221  }
222  };
223 
224  class AurynMatrixDimensionalityException: public std::exception
225  {
226  virtual const char* what() const throw()
227  {
228  return "Cannot add data outside of matrix.";
229  }
230  };
231 
232  class AurynMatrixComplexStateException: public std::exception
233  {
234  virtual const char* what() const throw()
235  {
236  return "Trying to access non existing complex synaptic states.";
237  }
238  };
239 
240  class AurynMatrixBufferException: public std::exception
241  {
242  virtual const char* what() const throw()
243  {
244  return "Buffer full.";
245  }
246  };
247 
248  class AurynMatrixPushBackException: public std::exception
249  {
250  virtual const char* what() const throw()
251  {
252  return "Could not push_back in SimpleMatrix. Out of order execution?";
253  }
254  };
255 
256  class AurynConnectionAllocationException: public std::exception
257  {
258  virtual const char* what() const throw()
259  {
260  return "Buffer has not been allocated.";
261  }
262  };
263 
264 
265  class AurynMemoryAlignmentException: public std::exception
266  {
267  virtual const char* what() const throw()
268  {
269  return "Memory not aligned or problem allocating aligned memory.";
270  }
271  };
272 
273  class AurynDelayTooSmallException: public std::exception
274  {
275  virtual const char* what() const throw()
276  {
277  return "One of the SpikeDelays was chosen shorter than the current value of MINDELAY.";
278  }
279  };
280 
281  class AurynTimeOverFlowException: public std::exception
282  {
283  virtual const char* what() const throw()
284  {
285  return "Trying to simulate more timesteps than are available in AurynTime.";
286  }
287  };
288 
289  class AurynStateVectorException: public std::exception
290  {
291  virtual const char* what() const throw()
292  {
293  return "Auryn encountered an undefined problem when dealing with StateVectors.";
294  }
295  };
296 
297  class AurynGenericException: public std::exception
298  {
299  virtual const char* what() const throw()
300  {
301  return "Auryn encountered a problem which it deemed serious enough to break the run. \
302  To debug set logger vebosity to VERBOSE or EVERYTHING and analyze the log files.";
303  }
304  };
305 
306  class AurynVectorDimensionalityException: public std::exception
307  {
308  virtual const char* what() const throw()
309  {
310  return "Dimensions do not match or trying to read beyond vector size. "
311  "Are the vectors zero padded to a multiples of four dimension?";
312  }
313  };
314 
315  class AurynSpikeAttributeSizeException: public std::exception
316  {
317  virtual const char* what() const throw()
318  {
319  return "The number of spike attributes can only be increased.";
320  }
321  };
322 
323 
324 
325  // forward declartion of template class which is implemented in AurynVector.h
326  template <typename T, typename IndexType >
327  class AurynVector;
328 
329  class AurynVectorFloat; // Forward declaration
330 
339 
342 
343  // Legacy state vector types
345  typedef AurynStateVector auryn_vector_float;
346 
349 
350 
351  // Legacy float vector functions
352  // These functions should not be used any more in the future. Instead use the member functions of AurynVectorFloat
353 
355  auryn_vector_float * auryn_vector_float_alloc(const NeuronID n);
356 
358  void auryn_vector_float_free (auryn_vector_float * v);
359 
361  void auryn_vector_float_set_zero (auryn_vector_float * v);
362 
364  void auryn_vector_float_set_all (auryn_vector_float * v, AurynFloat x);
365 
370  void auryn_vector_float_copy (auryn_vector_float * src, auryn_vector_float * dst );
371 
373  AurynFloat auryn_vector_float_get (auryn_vector_float * v, const NeuronID i);
374 
376  void auryn_vector_float_set (auryn_vector_float * v, const NeuronID i, AurynFloat x);
377 
379  AurynFloat * auryn_vector_float_ptr (auryn_vector_float * v, const NeuronID i);
380 
382  void auryn_vector_float_mul( auryn_vector_float * a, auryn_vector_float * b);
383 
387  void auryn_vector_float_add_constant( auryn_vector_float * a, float b );
388 
392  void auryn_vector_float_saxpy( const float a, auryn_vector_float * x, auryn_vector_float * y );
394  void auryn_vector_float_scale(const float a, auryn_vector_float * b );
396  void auryn_vector_float_clip(auryn_vector_float * v, const float a , const float b );
397 
399  void auryn_vector_float_clip(auryn_vector_float * v, const float a );
400 
404  void auryn_vector_float_add( auryn_vector_float * a, auryn_vector_float * b);
405 
409  void auryn_vector_float_sub( auryn_vector_float * a, auryn_vector_float * b);
410 
412  void auryn_vector_float_sub( auryn_vector_float * a, auryn_vector_float * b, auryn_vector_float * r);
413 
414 
415 
416  // Legacy ushort vector functions
418  auryn_vector_ushort * auryn_vector_ushort_alloc(const NeuronID n);
420  void auryn_vector_ushort_free (auryn_vector_ushort * v);
422  void auryn_vector_ushort_set_zero (auryn_vector_ushort * v);
423 
425  void auryn_vector_ushort_set_all (auryn_vector_ushort * v, unsigned short x);
426 
430  void auryn_vector_ushort_copy (auryn_vector_ushort * src, auryn_vector_ushort * dst );
432  unsigned short auryn_vector_ushort_get (auryn_vector_ushort * v, const NeuronID i);
434  void auryn_vector_ushort_set (auryn_vector_ushort * v, const NeuronID i, unsigned short x);
436  unsigned short * auryn_vector_ushort_ptr (auryn_vector_ushort * v, const NeuronID i);
437 
438 } // namespace
439 
440 #endif /*AURYN_DEFINITIONS_H__*/
Default Auryn vector template.
Definition: auryn_definitions.h:327
r
Definition: mkpat.py:9
Definition: auryn_definitions.h:216
Current based synapse. Adds the transmitted quantity directly to membrane voltage.
Definition: auryn_definitions.h:143
void auryn_vector_float_add_constant(auryn_vector_float *a, const float b)
Computes a := a + b.
Definition: auryn_definitions.cpp:69
AurynTime time
Definition: auryn_definitions.h:196
NeuronID i
Definition: auryn_definitions.h:173
void auryn_vector_ushort_copy(auryn_vector_ushort *src, auryn_vector_ushort *dst)
Definition: auryn_definitions.cpp:168
Auryn spike event for binary monitors.
Definition: auryn_definitions.h:201
void auryn_vector_float_mul(auryn_vector_float *a, auryn_vector_float *b)
Definition: auryn_definitions.cpp:64
Standard Glutamatergic (excitatory) transmission.
Definition: auryn_definitions.h:139
void auryn_vector_float_free(auryn_vector_float *v)
Definition: auryn_definitions.cpp:111
Definition: auryn_definitions.h:148
unsigned short auryn_vector_ushort_get(auryn_vector_ushort *v, const NeuronID i)
Definition: auryn_definitions.cpp:156
Struct that defines a pair of neurons in SparseConnection.
Definition: auryn_definitions.h:167
void auryn_vector_float_set_all(auryn_vector_float *v, AurynFloat x)
Definition: auryn_definitions.cpp:115
NeuronID calculate_vector_size(NeuronID i)
Rounds vector size to multiple of four to allow using the SSE optimizations.
Definition: auryn_definitions.cpp:50
std::vector< NeuronID > SpikeContainer
Spike container type. Used for storing spikes.
Definition: auryn_definitions.h:161
void auryn_vector_ushort_set_all(auryn_vector_ushort *v, unsigned short x)
Definition: auryn_definitions.cpp:148
void auryn_vector_ushort_set_zero(auryn_vector_ushort *v)
Definition: auryn_definitions.cpp:152
Definition: auryn_definitions.h:315
void auryn_vector_float_scale(const float a, auryn_vector_float *b)
Definition: auryn_definitions.cpp:74
Definition: auryn_definitions.h:297
std::vector< float > AttributeContainer
Attribute container type. Used for storing spike attributes that are needed for efficient STP impleme...
Definition: auryn_definitions.h:162
void auryn_vector_ushort_free(auryn_vector_ushort *v)
Definition: auryn_definitions.cpp:144
double AurynDouble
Higher precision floating point datatype.
Definition: auryn_definitions.h:158
AurynFloat AurynWeight
Unit of synaptic weights.
Definition: auryn_definitions.h:159
Definition: auryn_definitions.h:148
Only targets NMDA.
Definition: auryn_definitions.h:142
int n
Definition: mkpat.py:5
Definition: auryn_definitions.h:148
Definition: auryn_definitions.h:232
Definition: auryn_definitions.h:265
NeuronID neuronID
Definition: auryn_definitions.h:197
std::vector< pattern_member > type_pattern
Definition: auryn_definitions.h:177
void auryn_vector_float_clip(auryn_vector_float *v, const float a, const float b)
Definition: auryn_definitions.cpp:99
AurynState value
Definition: auryn_definitions.h:204
Definition: auryn_definitions.h:273
Definition: auryn_definitions.h:208
NeuronID AurynInt
Definition: auryn_definitions.h:152
AurynStateVector auryn_vector_float
Legacy definition of AurynStateVector.
Definition: auryn_definitions.h:345
Definition: ABSConnection.h:38
unsigned long AurynLong
An unsigned long type used to count synapses or similar.
Definition: auryn_definitions.h:154
#define N
Definition: sim_delay_connection.cpp:23
void auryn_vector_float_saxpy(const float a, auryn_vector_float *x, auryn_vector_float *y)
Definition: auryn_definitions.cpp:79
AurynFloat AurynState
Type for Auryn state variables (default single precision since it needs to be compatible with auryn_v...
Definition: auryn_definitions.h:160
int auryn_AlignOffset(const int N, const void *vp, const int inc, const int align)
Determines memory alignment (adapted from ATLAS library)
Definition: auryn_definitions.cpp:34
AurynFloat auryn_vector_float_get(auryn_vector_float *v, const NeuronID i)
Definition: auryn_definitions.cpp:123
AurynDouble gamma
Definition: auryn_definitions.h:174
double auryn_timestep
Simulation timestep in seconds.
Definition: auryn_definitions.cpp:31
StimulusGroupModeType
Specifies stimulus order used in StimulusGroup.
Definition: auryn_definitions.h:148
Definition: auryn_definitions.h:148
void auryn_vector_float_copy(auryn_vector_float *src, auryn_vector_float *dst)
Copies vector src to dst assuming they have the same size.
Definition: auryn_definitions.cpp:135
TransmitterType
Specifies the different transmitter types that Auryn knows.
Definition: auryn_definitions.h:138
unsigned short * auryn_vector_ushort_ptr(auryn_vector_ushort *v, const NeuronID i)
Definition: auryn_definitions.cpp:160
float AurynFloat
Low precision floating point datatype.
Definition: auryn_definitions.h:157
Definition: auryn_definitions.h:306
auryn_vector_float * auryn_vector_float_alloc(const NeuronID n)
Definition: auryn_definitions.cpp:107
AurynVectorFloat AurynStateVector
Defines AurynStateVector type as synonymous to AurynVectorFloat.
Definition: auryn_definitions.h:329
Definition: auryn_definitions.h:240
NeuronID i
Definition: auryn_definitions.h:168
AurynTime time
Definition: auryn_definitions.h:203
AurynVector< AurynWeight, AurynLong > AurynSynStateVector
Defines AurynSynStateVector for synaptic states.
Definition: auryn_definitions.h:341
Definition: auryn_definitions.h:256
auryn_vector_ushort * auryn_vector_ushort_alloc(const NeuronID n)
Definition: auryn_definitions.cpp:140
Current based synapse with dynamics.
Definition: auryn_definitions.h:144
void auryn_vector_float_sub(auryn_vector_float *a, auryn_vector_float *b)
Computes a := a-b.
Definition: auryn_definitions.cpp:89
Definition: auryn_definitions.h:289
void auryn_vector_float_set_zero(auryn_vector_float *v)
Definition: auryn_definitions.cpp:119
Standard Gabaergic (inhibitory) transmission.
Definition: auryn_definitions.h:140
Definition: auryn_definitions.h:224
void auryn_vector_float_add(auryn_vector_float *a, auryn_vector_float *b)
Internal version of to add GSL vectors.
Definition: auryn_definitions.cpp:84
AurynFloat * auryn_vector_float_ptr(auryn_vector_float *v, const NeuronID i)
Definition: auryn_definitions.cpp:127
Only targets AMPA channels.
Definition: auryn_definitions.h:141
Struct used to define neuronal assembly patterns in SparseConnection.
Definition: auryn_definitions.h:172
AurynVector< unsigned short, NeuronID > auryn_vector_ushort
Legacy definition of AurynVector<unsigned short>
Definition: auryn_definitions.h:348
Default AurynVectorFloat class for performance computation.
Definition: AurynVector.h:796
Definition: auryn_definitions.h:148
Definition: auryn_definitions.h:248
void auryn_vector_ushort_set(auryn_vector_ushort *v, const NeuronID i, unsigned short x)
Definition: auryn_definitions.cpp:164
NeuronID AurynTime
Defines Auryns discrete time unit of the System clock. Change to AurynLong if 120h of simtime are not...
Definition: auryn_definitions.h:155
unsigned int StateID
StateID is an unsigned integeger type used to index synaptic states in Auryn.
Definition: auryn_definitions.h:153
Definition: auryn_definitions.h:281
std::string string
Standard library string type which is imported into Auryn namespace.
Definition: auryn_definitions.h:156
unsigned int NeuronID
NeuronID is an unsigned integeger type used to index neurons in Auryn.
Definition: auryn_definitions.h:151
Auryn spike event for binary monitors.
Definition: auryn_definitions.h:194
void auryn_vector_float_set(auryn_vector_float *v, const NeuronID i, AurynFloat x)
Definition: auryn_definitions.cpp:131
NeuronID j
Definition: auryn_definitions.h:168