AnimatLab  2
Test
snn.h
1 /*
2  * Copyright (c) 2013 Regents of the University of California. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * 3. The names of its contributors may not be used to endorse or promote
16  * products derived from this software without specific prior written
17  * permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  * *********************************************************************************************** *
32  * CARLsim
33  * created by: (MDR) Micah Richert, (JN) Jayram M. Nageswaran
34  * maintained by: (MA) Mike Avery <averym@uci.edu>, (MB) Michael Beyeler <mbeyeler@uci.edu>,
35  * (KDC) Kristofor Carlson <kdcarlso@uci.edu>
36  *
37  * CARLsim available from http://socsci.uci.edu/~jkrichma/CARLsim/
38  * Ver 07/13/2013
39  */
40 
41 #ifndef _SNN_GOLD_H_
42 #define _SNN_GOLD_H_
43 
44 #include <iostream>
45 #include <string>
46 #include <map>
47 #include "mtrand.h"
48 #include "gpu_random.h"
49 #include "config.h"
50 #include "PropagatedSpikeBuffer.h"
51 
52 #define USE_EXCEPTIONS 1
53 
54 #ifdef USE_EXCEPTIONS
55  #include <exception>
56  #include <stdexcept>
57 #endif // USE_EXCEPTIONS
58 
59 using std::string;
60 using std::map;
61 
62 //#if __CUDA3__
63 //#include <cuda.h>
64 //#include <cutil_inline.h>
65 //#include <cutil_math.h>
66 //#elif __CUDA5__
67 #include <cuda.h>
68 #include <cuda_runtime.h>
69 #include <helper_cuda.h>
70 #include <helper_functions.h>
71 #include <helper_timer.h>
72 #include <helper_math.h>
73 //#endif
74 
75 #include "CUDAVersionControl.h"
76 
77 extern RNG_rand48* gpuRand48;
78 
79 //Specifies the time step used for the integration.
80 #define CARLSIM_STEP_INCREMENT 0.001
81 
82 //This controls how many iterations are taken before an update occurs.
83 //I have it set here to 10 ms, the default for CarlSim would be 1000 for 1 second.
84 #define CARLSIM_STEP_SIZE 10
85 
86 #define ALL -1
87 
88 #define SYN_FIXED 0
89 #define SYN_PLASTIC 1
90 
91 #define CPU_MODE 0
92 #define GPU_MODE 1
93 
94 // Bit flags to be used to specify the type of neuron. Future types can be added in the future such as Dopamine, etc.
95 // Yes, they should be bit flags because some neurons release more than one transmitter at a synapse.
96 #define UNKNOWN_NEURON (0)
97 #define POISSON_NEURON (1<<0)
98 #define TARGET_AMPA (1<<1)
99 #define TARGET_NMDA (1<<2)
100 #define TARGET_GABAa (1<<3)
101 #define TARGET_GABAb (1<<4)
102 
103 #define INHIBITORY_NEURON (TARGET_GABAa | TARGET_GABAb)
104 #define EXCITATORY_NEURON (TARGET_NMDA | TARGET_AMPA)
105 #define EXCITATORY_POISSON (EXCITATORY_NEURON | POISSON_NEURON)
106 #define INHIBITORY_POISSON (INHIBITORY_NEURON | POISSON_NEURON)
107 #define IS_INHIBITORY_TYPE(type) (((type)&TARGET_GABAa) || ((type)&TARGET_GABAb))
108 #define IS_EXCITATORY_TYPE(type) (!IS_INHIBITORY_TYPE(type))
109 
110 
111 #define CONN_SYN_NEURON_BITS 20
112 #define CONN_SYN_BITS (32 - CONN_SYN_NEURON_BITS)
113 #define CONN_SYN_NEURON_MASK ((1 << CONN_SYN_NEURON_BITS) - 1)
114 #define CONN_SYN_MASK ((1 << CONN_SYN_BITS) - 1)
115 #define GET_CONN_NEURON_ID(a) (((unsigned int)a.postId) & CONN_SYN_NEURON_MASK)
116 #define GET_CONN_SYN_ID(b) (((unsigned int)b.postId) >> CONN_SYN_NEURON_BITS)
117 #define GET_CONN_GRP_ID(c) (c.grpId)
118 //#define SET_CONN_ID(a,b) ((b) > CONN_SYN_MASK) ? (fprintf(stderr, "Error: Syn Id exceeds maximum limit (%d)\n", CONN_SYN_MASK)): (((b)<<CONN_SYN_NEURON_BITS)+((a)&CONN_SYN_NEURON_MASK))
119 
120 
121 #define CONNECTION_INITWTS_RANDOM 0
122 #define CONNECTION_CONN_PRESENT 1
123 #define CONNECTION_FIXED_PLASTIC 2
124 #define CONNECTION_INITWTS_RAMPUP 3
125 #define CONNECTION_INITWTS_RAMPDOWN 4
126 
127 #define SET_INITWTS_RANDOM(a) ((a&1) << CONNECTION_INITWTS_RANDOM)
128 #define SET_CONN_PRESENT(a) ((a&1) << CONNECTION_CONN_PRESENT)
129 #define SET_FIXED_PLASTIC(a) ((a&1) << CONNECTION_FIXED_PLASTIC)
130 #define SET_INITWTS_RAMPUP(a) ((a&1) << CONNECTION_INITWTS_RAMPUP)
131 #define SET_INITWTS_RAMPDOWN(a) ((a&1) << CONNECTION_INITWTS_RAMPDOWN)
132 
133 #define GET_INITWTS_RANDOM(a) (((a) >> CONNECTION_INITWTS_RANDOM)&1)
134 #define GET_CONN_PRESENT(a) (((a) >> CONNECTION_CONN_PRESENT)&1)
135 #define GET_FIXED_PLASTIC(a) (((a) >> CONNECTION_FIXED_PLASTIC)&1)
136 #define GET_INITWTS_RAMPUP(a) (((a) >> CONNECTION_INITWTS_RAMPUP)&1)
137 #define GET_INITWTS_RAMPDOWN(a) (((a) >> CONNECTION_INITWTS_RAMPDOWN)&1)
138 
139 #define checkNetworkBuilt() { \
140  if(!doneReorganization) { \
141  DBG(0, fpLog, AT, "checkNetworkBuilt()"); \
142  fprintf(fpLog, "Network not yet elaborated and built...\n"); \
143  fprintf(stderr, "Network not yet elaborated and built...\n"); \
144  return; \
145  } \
146  }
147 
148 /****************************/
149 
150 #define STP_BUF_POS(nid,t) (nid*STP_BUF_SIZE+((t)%STP_BUF_SIZE))
151 
160 #define IS_POISSON_NEURON(nid, numNReg, numNPois) ((nid) >= (numNReg) && ((nid) < (numNReg+numNPois)))
161 #define IS_REGULAR_NEURON(nid, numNReg, numNPois) (((nid) < (numNReg)) && ((nid) < (numNReg+numNPois)))
162 #define IS_INHIBITORY(nid, numNInhPois, numNReg, numNExcReg, numN) (((nid) >= (numNExcReg)) && ((nid) < (numNReg + numNInhPois)))
163 #define IS_EXCITATORY(nid, numNInhPois, numNReg, numNExcReg, numN) (((nid) < (numNReg)) && (((nid) < (numNExcReg)) || ((nid) >= (numNReg + numNInhPois))))
164 
165 #if __CUDACC__
166 inline bool isExcitatoryNeuron (unsigned int& nid, unsigned int& numNInhPois, unsigned int& numNReg, unsigned int& numNExcReg, unsigned int& numN)
167 {
168  return ((nid < numN) && ((nid < numNExcReg) || (nid >= numNReg + numNInhPois)));
169 }
170 inline bool isInhibitoryNeuron (unsigned int& nid, unsigned int& numNInhPois, unsigned int& numNReg, unsigned int& numNExcReg, unsigned int& numN)
171 {
172  return ((nid >= numNExcReg) && (nid < (numNReg + numNInhPois)));
173 }
174 #endif
175 
176 #define STATIC_LOAD_START(n) (n.x)
177 #define STATIC_LOAD_GROUP(n) (n.y &0xff)
178 #define STATIC_LOAD_SIZE(n) ((n.y >> 16) & 0xff)
179 
180 #define MAX_NUMBER_OF_NEURONS_BITS (20)
181 #define MAX_NUMBER_OF_GROUPS_BITS (32-MAX_NUMBER_OF_NEURONS_BITS)
182 #define MAX_NUMBER_OF_NEURONS_MASK ((1 << MAX_NUMBER_OF_NEURONS_BITS)-1)
183 #define MAX_NUMBER_OF_GROUPS_MASK ((1 << MAX_NUMBER_OF_GROUPS_BITS)-1)
184 #define SET_FIRING_TABLE(nid, gid) (((gid) << MAX_NUMBER_OF_NEURONS_BITS) | (nid))
185 #define GET_FIRING_TABLE_NID(val) ((val) & MAX_NUMBER_OF_NEURONS_MASK)
186 #define GET_FIRING_TABLE_GID(val) (((val) >> MAX_NUMBER_OF_NEURONS_BITS) & MAX_NUMBER_OF_GROUPS_MASK)
187 
189 
190 
191 #ifdef USE_EXCEPTIONS
192  #define carlsim_assert(pred) {if(!(pred)) throw std::runtime_error("Assert triggered.\n");}
193 #else
194  #define carlsim_assert(pred) assert(pred)
195 #endif
196 
197 //Various callback functions
198 
199 class CpuSNN;
200 
202 
207  public:
208  StepFeedback() {};
209 
211  virtual bool stepUpdate(CpuSNN* s, int step) { assert(false); return false;}; // the virtual method should never be called directly
212  virtual void updateMonitors(CpuSNN* s, int step) { assert(false);}; // the virtual method should never be called directly
213 };
214 
215 
216 
218 
227  public:
228  SpikeGenerator() {};
229 
231 
232  virtual unsigned int nextSpikeTime(CpuSNN* s, int grpId, int i, unsigned int currentTime) { assert(false); return 0; }; // the virtual method should never be called directly
233 };
234 
236 
245  public:
246  ConnectionGenerator() {};
247 
249 
250  virtual void connect(CpuSNN* s, int srcGrpId, int i, int destGrpId, int j, float& weight, float& maxWt, float& delay, bool& connected) { assert(false); }; // the virtual method should never be called directly
251 };
252 
254  public:
255  IzhGenerator() {};
256  virtual void set(CpuSNN* s, int grpId, int i, float& a, float& b, float& c, float& d) {};
257 };
258 
260 
266  public:
267  SpikeMonitor() {};
268 
270 
271  virtual void update(CpuSNN* s, int grpId, unsigned int* Nids, unsigned int* timeCnts, unsigned int total_spikes, float firing_Rate) {};
272 };
273 
274 
275 class PoissonRate {
276  public:
277  PoissonRate(float* _rates, uint32_t _len, bool _onGPU=false) {
278  rates=_rates;
279  len=_len;
280  onGPU=_onGPU;
281  allocatedRatesInternally = false;
282  };
283 
284  PoissonRate(uint32_t _len, bool _onGPU=false) {
285  if (_onGPU) {
286  CUDA_CHECK_ERRORS(cudaMalloc ((void**)&rates, _len*sizeof(float)));
287  } else {
288  rates = new float[_len];
289  }
290  len=_len;
291  onGPU=_onGPU;
292  allocatedRatesInternally = true;
293  };
294 
295  // destructor
296  ~PoissonRate() {
297  if (allocatedRatesInternally) {
298  if (onGPU) {
299  CUDA_CHECK_ERRORS(cudaThreadSynchronize()); // wait for kernel to complete
300  CUDA_CHECK_ERRORS(cudaFree(rates)); // free memory
301  }
302  else {
303  delete[] rates;
304  }
305  }
306  }
307 
308  float* rates;
309  uint32_t len;
310  bool onGPU;
311  bool allocatedRatesInternally;
312 };
313 
314 
315 typedef struct {
316  short delay_index_start;
317  short delay_length;
318 } delay_info_t;
319 
320 typedef struct {
321  int postId;
322  uint8_t grpId;
323 } post_info_t;
324 
325 typedef struct network_info_s {
326  size_t STP_Pitch;
327  unsigned int numN,numPostSynapses,D,numNExcReg,numNInhReg, numNReg;
328  unsigned int I_setLength;
329  size_t I_setPitch;
330  unsigned int preSynLength;
331  // unsigned int numRandNeurons;
332  // unsigned int numNoise;
333  unsigned int postSynCnt;
334  unsigned int preSynCnt;
335  unsigned int maxSpikesD2,maxSpikesD1;
336  uint32_t numProbe;
337  unsigned int numNExcPois;
338  unsigned int numNInhPois;
339  unsigned int numNPois;
340  unsigned int numGrp;
341  bool sim_with_fixedwts;
342  bool sim_with_conductances;
343  bool sim_with_stdp;
344  bool sim_with_stp;
346 
348 inline post_info_t SET_CONN_ID(int nid, int sid, int grpId)
349 {
350  if (sid > CONN_SYN_MASK) {
351  fprintf(stderr, "Error: Syn Id (%d) exceeds maximum limit (%d) for neuron %d\n", sid, CONN_SYN_MASK, nid);
352  assert(0);
353  }
354  post_info_t p;
355  p.postId = (((sid)<<CONN_SYN_NEURON_BITS)+((nid)&CONN_SYN_NEURON_MASK));
356  p.grpId = grpId;
357  return p;
358 }
359 
360 typedef struct network_ptr_s {
361  float *voltage, *recovery, *Izh_a, *Izh_b, *Izh_c, *Izh_d, *current;
362 
363  // conductances and stp values
364  float *gNMDA, *gAMPA, *gGABAa, *gGABAb;
365  int* I_set;
366  int memType;
367  int allocated;
368  float *stpx, *stpu;
369 
370  unsigned short *Npre;
371  unsigned short *Npre_plastic;
373  unsigned short *Npost;
374  unsigned int *lastSpikeTime;
375  float *wtChange, *wt;
376  float *maxSynWt;
377  uint32_t *synSpikeTime;
378  uint32_t *neuronFiring;
379  unsigned int *cumulativePost;
380  unsigned int *cumulativePre;
381 
389 
390  post_info_t *preSynapticIds;
392  unsigned int* firingTableD1;
393  unsigned int* firingTableD2;
394  // int* randId;
395  // void* noiseGenProp;
396 
397  float* probeV;
398  float* probeI;
399  uint32_t* probeId;
400 
403  float* probeHomeoFreq;
404  float* probeBaseFreq;
405 
406  float* poissonFireRate;
407  unsigned int* poissonRandPtr;
408  int2* neuronAllocation;
409  int3* groupIdInfo;
410  short int* synIdLimit; //
411  float* synMaxWts; //
412 
413  unsigned int* nSpikeCnt;
414 
416  float* baseFiringInv;
417  float* baseFiring;
418  float* avgFiring;
419 
420 
421 
422  float* testVar;
423  float* testVar2;
424  uint32_t* spikeGenBits;
425  bool* curSpike;
426 } network_ptr_t;
427 
428 typedef struct group_info_s
429 {
430  // properties of group of neurons size, location, initial weights etc.
431  PoissonRate* RatePtr;
432  int StartN;
433  int EndN;
434  char Type;
435  int SizeN;
436  int NumTraceN;
437  short int MaxFiringRate;
438  int MonitorId;
439  float RefractPeriod;
441  int NewTimeSlice;
442  uint32_t SliceUpdateTime;
443  int FiringCount1sec;
444  int numPostSynapses;
445  int numPreSynapses;
446  bool isSpikeGenerator;
447  bool WithSTP;
448  bool WithSTDP;
449  bool WithHomeostasis;
450  bool WithConductances;
451  int homeoId;
452  bool FixedInputWts;
453  int Noffset;
454  int8_t MaxDelay;
455 
456  float STP_U;
457  float STP_tD;
458  float STP_tF;
459  float TAU_LTP_INV;
460  float TAU_LTD_INV;
461  float ALPHA_LTP;
462  float ALPHA_LTD;
463  float dAMPA;
464  float dNMDA;
465  float dGABAa;
466  float dGABAb;
467 
469  float avgTimeScale;
470  float avgTimeScale_decay;
471  float avgTimeScaleInv;
472  float homeostasisScale;
473 
474  SpikeGenerator* spikeGen;
475  bool newUpdates;
476 } group_info_t;
477 
483 typedef struct group_info2_s
484 {
485  string Name;
486  short ConfigId;
487  // properties of group of neurons size, location, initial weights etc.
488  //<! homeostatic plasticity variables
489  float baseFiring;
490  float baseFiringSD;
491  float Izh_a;
492  float Izh_a_sd;
493  float Izh_b;
494  float Izh_b_sd;
495  float Izh_c;
496  float Izh_c_sd;
497  float Izh_d;
498  float Izh_d_sd;
499  IzhGenerator* IzhGen;
500 
506  int numPostConn;
507  int numPreConn;
508  int maxPostConn;
509  int maxPreConn;
510  int sumPostConn;
511  int sumPreConn;
512 } group_info2_t;
513 
514 enum conType_t { CONN_RANDOM, CONN_ONE_TO_ONE, CONN_FULL, CONN_FULL_NO_DIRECT, CONN_USER_DEFINED, CONN_UNKNOWN};
515 
517 typedef struct connectData_s {
518  int grpSrc, grpDest;
519  uint8_t maxDelay, minDelay;
520  float initWt, maxWt;
521  int numPostSynapses;
522  int numPreSynapses;
523  uint32_t connProp;
524  ConnectionGenerator* conn;
525  conType_t type;
526  float p;
527  int connId;
528  bool newUpdates;
529  int numberOfConnections;
530  struct connectData_s* next;
532 
533 
534 #define MAX_GRPS_PER_BLOCK 100
535 #define MAX_BLOCKS 120
536 // member variable
539 typedef struct grpConnInfo_s {
540  int16_t srcGrpId;
541  int srcStartN;
542  int srcEndN;
544  int grpMaxM;
547  int* randomDelayPointer; //
548  int16_t fixedDestGrpCnt;
551 } grpConnInfo_t;
552 
553 
555  public:
556  SparseWeightDelayMatrix(int Npre, int Npost, int initSize=0) {
557  count = 0;
558  size = 0;
559  weights = NULL;
560  maxWeights = NULL;
561  preIds = NULL;
562  preIds = NULL;
563  delay_opts = NULL;
564 
565  maxPreId = 0;
566  maxPostId = 0;
567 
568  resize(initSize);
569  }
570 
572  free(weights);
573  free(maxWeights);
574  free(preIds);
575  free(postIds);
576  free(delay_opts);
577  }
578 
579  void resize(int inc) {
580  size += inc;
581 
582  weights = (float*)realloc(weights,size*sizeof(float));
583  maxWeights = (float*)realloc(maxWeights,size*sizeof(float));
584  preIds = (unsigned int*)realloc(preIds,size*sizeof(int));
585  postIds = (unsigned int*)realloc(postIds,size*sizeof(int));
586  delay_opts = (unsigned int*)realloc(delay_opts,size*sizeof(int));
587  }
588 
589  int add(int preId, int postId, float weight, float maxWeight, uint8_t delay, int opts=0) {
590  if (count == size) resize(size==0?1000:size*2);
591 
592  weights[count] = weight;
593  maxWeights[count] = maxWeight;
594  preIds[count] = preId;
595  postIds[count] = postId;
596  delay_opts[count] = delay | (opts << 8);
597 
598  if (preId > maxPreId) maxPreId = preId;
599  if (postId > maxPostId) maxPostId = postId;
600 
601  return ++count;
602  }
603 
604  unsigned int count, size, maxPreId, maxPostId;
605  float* weights;
606  float* maxWeights;
607  unsigned int* preIds;
608  unsigned int* postIds;
609  unsigned int* delay_opts;
610 };
611 
612 
613 
619 class CpuSNN
620 {
621  public:
622 
623  const static unsigned int MAJOR_VERSION = 2;
624  const static unsigned int MINOR_VERSION = 3;
625 
626  CpuSNN(const string& _name, int _numConfig = 1, int randomize = 0, int mode=CPU_MODE);
627  ~CpuSNN();
628 
630  int createGroup(const string& _name, unsigned int _numN, int _nType, int configId = ALL);
631 
633  int createSpikeGeneratorGroup(const string& _name, int unsigned size_n, int stype, int configId = ALL);
634 
636 
638  void setNeuronParameters(int groupId, float _a, float a_sd, float _b, float b_sd, float _c, float c_sd, float _d, float d_sd, int configId=ALL);
639 
641  void setNeuronParameters(int groupId, float _a, float _b, float _c, float _d, int configId=ALL);
642 
643  void setNeuronParameters(int groupId, IzhGenerator* IzhGen, int configId=ALL);
644 
645  void setGroupInfo(int groupId, group_info_t info, int configId=ALL);
646  group_info_t getGroupInfo(int groupId, int configId=0);
647  group_info2_t getGroupInfo2(int groupId, int configId=0);
648 
650  void printDotty ();
651 
652  // required for homeostasis
653  grpConnectInfo_t* getConnectInfo(int connectId, int configId=0);
654 
655  void CpuSNNInit(unsigned int _numN, unsigned int _numPostSynapses, unsigned int _numPreSynapses, unsigned int _D);
656 
660  int connect(int gIDpre, int gIDpost, const string& _type, float initWt, float maxWt, float _C, uint8_t minDelay, uint8_t maxDelay, bool synWtType = SYN_FIXED, const string& wtType = " ");
661 
662  int connect(int gIDpre, int gIDpost, ConnectionGenerator* conn, bool synWtType = SYN_FIXED, int maxM=0, int maxPreM=0);
663 
664 
670  int runNetwork(int _nsec, int _tstep = 0, int simType = CPU_MODE, int ithGPU = 0, bool enablePrint=false, int copyState=false);
671 
672  bool updateTime();
673  uint64_t getSimTime() { return simTime; }
674 
675  uint32_t getSimTimeSec() { return simTimeSec; }
676 
677  uint32_t getSimTimeMs() { return simTimeMs; }
678 
679 
680  // grpId == -1, means all groups
681  void setSTDP(int grpId, bool enable, int configId=ALL);
682  void setSTDP(int grpId, bool enable, float _ALPHA_LTP, float _TAU_LTP, float _ALPHA_LTD, float _TAU_LTD, int configId=ALL);
683 
684  // g == -1, means all groups
685  void setSTP(int g, bool enable, int configId=ALL);
686  void setSTP(int g, bool enable, float STP_U, float STP_tD, float STP_tF, int configId=ALL);
687 
688  // g == -1, means all groups
689  void setConductances(int g, bool enable, int configId=ALL);
690  void setConductances(int g, bool enable, float tAMPA, float tNMDA, float tGABAa, float tGABAb, int configId=ALL);
695  void setHomeostasis(int g, bool enable, int configId=0);
702  void setHomeostasis(int g, bool enable, float homeostasisScale, float avgTimeScale, int configId=0);
703 
704 
709  void setBaseFiring(int groupId, int configId, float _baseFiring, float _baseFiringSD);
710 
713  void setSpikeMonitor(int gid, SpikeMonitor* spikeMon=NULL, int configId=ALL);
714 
716  void setSpikeMonitor(int gid, const string& fname, int configId=0);
717 
718  void setSpikeRate(int grpId, PoissonRate* spikeRate, int refPeriod=1, int configId=ALL);
719  void setSpikeGenerator(int grpId, SpikeGenerator* spikeGen, int configId=ALL);
720 
721 
722  void writeNetwork(FILE* fid);
723 
724  void readNetwork(FILE* fid);
725 #if READNETWORK_ADD_SYNAPSES_FROM_FILE
726  int readNetwork_internal(bool onlyPlastic);
727 #else
728  int readNetwork_internal();
729 #endif
730 
731  // Used to copy grp_info to gpu for setSTDP, setSTP, and setHomeostasis
732  void copyGrpInfo_GPU();
733 
741  void getPopWeights(int gIDpre, int gIDpost, float*& weights, int& size, int configId = 0);
745  void writePopWeights(string fname, int gIDpre, int gIDpost, int configId = 0);
746 
747  float* getWeights(int gIDpre, int gIDpost, int& Npre, int& Npost, float* weights=NULL);
748  float* getWeightChanges(int gIDpre, int gIDpost, int& Npre, int& Npost, float* weightChanges=NULL);
749  uint8_t* getDelays(int gIDpre, int gIDpost, int& Npre, int& Npost, uint8_t* delays=NULL);
750 
751  void printSimSummary(FILE *fp = stdout);
752  void printMemoryInfo(FILE* fp=stdout);
753  void printTuningLog();
754 
755  void setTuningLog(string fname)
756  {
757  fpTuningLog = fopen(fname.c_str(), "w");
758  carlsim_assert(fpTuningLog != NULL);
759  }
760 
762  void setLogCycle(unsigned int _cnt, int mode=0, FILE *fp=NULL) {
763 
764  //enable or disable logging...
765  showLog = (_cnt == 0)? 0 : 1;
766 
767  //set the update cycle...
768  showLogCycle = _cnt;
769 
770  showLogMode = mode;
771 
772  if (fp!=NULL)
773  fpProgLog = fp;
774 
775  }
776 
777 
778  void setProbe(int g, const string& type, int startId=0, int cnt=1, uint32_t _printProbe=0);
779 
780  int grpStartNeuronId(int g) { return grp_Info[g].StartN; }
781 
782  int grpEndNeuronId(int g) { return grp_Info[g].EndN; }
783 
784  int grpNumNeurons(int g) { return grp_Info[g].SizeN; }
785 
786 
787 
788  void plotProbes();
789 
790 
791  int getNumConfigurations() {
792  return numConfig;
793  }
794  int getGroupId(int groupId, int configId);
795  // Used in setHomeostasis function.
796  int getNextGroupId(int);
797  int getConnectionId(int connId, int configId);
798 
799 
800  void setPrintState(int grpId, bool _status, int neuronId=-1)
801  {
802  grp_Info2[grpId].enablePrint = _status;
803  }
804  void printState(const char *str = "");
805  void printWeight(int grpId, const char *str = "");
806  void printNeuronState(int grpId, FILE *fp = stderr);
807 
808  void setSimLogs(bool enable, string logDirName = "") {
809  enableSimLogs = enable;
810  if (logDirName != "") {
811  simLogDirName = logDirName;
812  }
813  }
814 
815  void printParameters(FILE *fp);
816 
817  void printGroupInfo(FILE* fp);
818 
819  void printGroupInfo(string& strName);
820 
821  void printConnectionInfo(FILE* fp);
822 
823  void printConnectionInfo2(FILE *fpg);
824 
825  void printGroupInfo2(FILE* fpg);
826 
827  int printPostConnection2(int grpId, FILE* fpg);
828 
829  int printPreConnection2(int grpId, FILE* fpg);
830 
831  void printFiringRate(char *fname=NULL);
832 
833  // added this to output regular neuron state variables
834  // to a binary file at every timestep. -- KDC
839  void printNeuronStateBinary(string fname, int grpId, int configId=0, int count=-1);
840 
845  void updateNetwork(bool resetFiringInfo, bool resetWeights);
846 
849  void updateNetwork_GPU(bool resetFiringInfo);
850 
852  void updateNetwork();
853 
857 
858  //Added this to copy firing state information from gpu kernel
859  //to cpuNetPtrs so it can be accessed by the user. To use
860  //getSpikeCntPtr_GPU this flag must be set to true. This should be
861  //set to false by default because it adds additional overhead.
862  //This can be toggled on or off between runNetwork
863  //calls. -- KDC
869  void setCopyFiringStateFromGPU(bool _enableGPUSpikeCntPtr){
870  enableGPUSpikeCntPtr=_enableGPUSpikeCntPtr;
871  }
872 
873  //added this for Jay's functionality -- KDC
874  //TAGS:TODO: may need to make it work for different configurations. -- KDC
879  unsigned int* getSpikeCntPtr(int grpId = -1, int simType = CPU_MODE) {
881  if(simType == GPU_MODE && enableGPUSpikeCntPtr == false){
882  fprintf(stderr,"Error: the enableGPUSpikeCntPtr flag must be set to true to use this function in GPU_MODE.\n");
883  carlsim_assert(enableGPUSpikeCntPtr);
884  }
885 
886  if(simType == GPU_MODE){
887  carlsim_assert(enableGPUSpikeCntPtr);
888  }
889 
890  return ((grpId == -1) ? nSpikeCnt : &nSpikeCnt[grp_Info[grpId].StartN]);
891  }
892 
893  // This function calls the callback connect function for a particular
894  // connection (or number of identical configurations of a connection).
895  // This function can only be used for fixed weights and for connections
896  // of type CONN_USER_DEFINED. Only the weights are change, not the
897  // maxWts, delays, or the connected values. -- KDC
903  void reassignFixedWeights(int connectId, float weightMatrix [], int matrixSize, int configId = ALL);
904 
906  int getNumConnections(int connectionId);
907 
908 
909  void printNetworkInfo();
910 
912  void printPostConnection(FILE *fp = stdout);
913 
914  void printPreConnection(FILE *fp = stdout);
915 
916  void printConnection(const string& fname)
917  {
918  FILE *fp = fopen(fname.c_str(), "w");
919  printConnection(fp);
920  fclose(fp);
921  }
922 
923  void printConnection(FILE *fp = stdout)
924  {
926  printPreConnection(fp);
927  }
928 
930  void printConnection(int grpId, FILE *fp = stdout)
931  {
932  printPostConnection(grpId, fp);
933  printPreConnection(grpId, fp);
934  }
935 
936  void printPostConnection(int grpId, FILE *fp = stdout);
937 
938  void printPreConnection(int grpId, FILE *fp = stdout);
939 
940 
941  void showGroupStatus(int _f) { showGrpFiringInfo = _f; }
942 
943  void showDottyViewer(int _f) { showDotty = _f; }
944 
946  void resetSpikeCnt(int grpId = -1);
952  void resetSpikeCntUtil(int grpId = -1);
953 
955  void resetSpikeCnt_GPU(int _startGrp, int _endGrp);
956 
957  void setStepFeedback(StepFeedback *feedback) {stepFeedback = feedback;};
958 
959  void setSpikeRateUpdated() {spikeRateUpdated = true;};
960 
961  private:
962  void setGrpTimeSlice(int grpId, int timeSlice);
963 
964  void doSnnSim();
965 
966  void dumpSpikeBuffToFile_GPU(int gid);
967 
968  void assignPoissonFiringRate_GPU();
969 
970  void setSpikeGenBit_GPU(unsigned int nid, int grp);
971 
972  void generateSpikes();
973 
974  void generateSpikes(int grpId);
975 
976  void generateSpikesFromFuncPtr(int grpId);
977 
978  void generateSpikesFromRate(int grpId);
979 
980  void startCPUTiming();
981  void resetCPUTiming();
982  void stopCPUTiming();
983  void startGPUTiming();
984  void resetGPUTiming();
985  void stopGPUTiming();
986 
987  void resetPointers();
988 
989  void resetConductances();
990  void resetCounters();
991  void resetCurrent();
992  void resetSynapticConnections(bool changeWeights=false);
993  void resetTimingTable();
994  void resetPoissonNeuron(unsigned int nid, int grpId);
995  void resetNeuron(unsigned int nid, int grpId);
996  void resetPropogationBuffer();
997  void resetGroups();
998  void resetFiringInformation();
1000  void resetFiringInformation_GPU();
1001 
1002 
1003  void doD1CurrentUpdate();
1004  void doD2CurrentUpdate();
1005 
1006  void findFiring();
1007 
1008  void doSTPUpdates();
1009 
1010  void generatePostSpike(unsigned int pre_i, unsigned int idx_d, unsigned int offset, unsigned int tD);
1011 
1012  void globalStateUpdate();
1013 
1014  void updateStateAndFiringTable();
1015 
1016  void updateSpikesFromGrp(int grpId);
1017 
1018  void updateSpikeGeneratorsInit();
1019 
1020  void updateSpikeGenerators();
1021 
1022 
1024  int addSpikeToTable(int id, int g);
1025 
1026  float getWeights(int connProp, float initWt, float maxWt, unsigned int nid, int grpId);
1027 
1028  //conection related methods...
1029  inline void setConnection(int srcGrpId, int destGrpId, unsigned int src, unsigned int dest, float synWt, float maxWt, uint8_t dVal, int connProp);
1030  void connectUserDefined ( grpConnectInfo_t* info);
1031  void connectRandom(grpConnectInfo_t* info);
1032  void connectFull(grpConnectInfo_t* info);
1033  void connectOneToOne(grpConnectInfo_t* info);
1034  void connectFromMatrix(SparseWeightDelayMatrix* mat, int connProp);
1035 
1036  void exitSimulation(int val, const char *errorString);
1037 
1038  void deleteObjects();
1039  void deleteObjectsGPU();
1040 
1041  void testSpikeSenderReceiver(FILE* fpLog, int simTime);
1042 
1043  void printFiringInfo(FILE* fp, int grpId=-1);
1044 
1045  void printFiredId(FILE* fp, bool clear=false, int myGrpId=-1);
1046 
1047  void printTestVarInfo(FILE *fp, char* testString, bool test1=true, bool test2=true, bool test12=false, int subVal=0, int grouping1=0, int grouping2=0);
1048 
1049  void printGpuLoadBalance(bool init = false, int numBlocks = MAX_BLOCKS, FILE*fp = stdout);
1050 
1051  void printCurrentInfo(FILE *fp);
1052 
1053  int checkErrors(string kernelName, int numBlocks);
1054  int checkErrors(int numBlocks);
1055 
1056  void updateParameters(int* numN, int* numPostSynapses, int* D, int nConfig=1);
1057 
1058  int updateSpikeTables();
1059 
1060  void reorganizeNetwork(bool removeTempMemory, int simType);
1061 
1062  void reorganizeDelay();
1063 
1064  void swapConnections(int nid, int oldPos, int newPos);
1065 
1067  void compactConnections();
1068 
1071  void regroupConnections(FILE *fp=NULL);
1072 
1074  void initSynapticWeights();
1075 
1077  int findGrpId(int nid);
1078 
1080  void updateSpikeMonitor();
1081 
1082  void updateSpikeMonitor_GPU();
1083 
1084  void updateMonitors();
1085 
1086  void updateAfterMaxTime();
1087 
1088 
1090  void CpuSNNinitGPUparams();
1091 
1093  void allocateSNN_GPU(int ithGPU);
1094 
1095  void allocateNetworkParameters();
1096 
1097  void allocateGroupParameters();
1098 
1099  void buildNetwork();
1100 
1101  void buildGroup(int groupId);
1102 
1103  void buildPoissonGroup(int groupId);
1104 
1105  void copyWeightsGPU(unsigned int nid, int src_grp);
1106 
1107  void makePtrInfo();
1108 
1109  void copyNeuronState(network_ptr_t* dest, network_ptr_t* src, cudaMemcpyKind kind, int allocateMem, int grpId=-1);
1110 
1112  void copyWeightState(network_ptr_t* dest, network_ptr_t* src, cudaMemcpyKind kind, int allocateMem, int grpId=-1);
1113 
1114  void copyNeuronParameters(network_ptr_t* dest, int kind, int allocateMem, int grpId = -1);
1115 
1116  void copySTPState(network_ptr_t* dest, network_ptr_t* src, int kind, int allocateMem);
1117 
1118  void checkDestSrcPtrs(network_ptr_t* dest, network_ptr_t* src, cudaMemcpyKind kind, int allocateMem, int grpId);
1119 
1120  void copyConnections(network_ptr_t* dest, int kind, int allocateMem);
1121 
1122  void copyPostConnectionInfo(network_ptr_t* dest, int allocateMem);
1123 
1124  void copyState(network_ptr_t* dest, int kind, int allocateMem);
1125 
1126  void printGpuPostConnection(int grpId, FILE* fp, int numBlock);
1127 
1128  void gpuProbeInit(network_ptr_t* dest);
1129 
1130  void copyParameters();
1131 
1132  int getPoissNeuronPos(int nid);
1133 
1134  void findFiring_GPU();
1135 
1136  void spikeGeneratorUpdate_GPU();
1137 
1138  void updateTimingTable_GPU();
1139 
1140  void doCurrentUpdate_GPU();
1141 
1142  void globalStateUpdate_GPU();
1143 
1144  void doGPUSim();
1145 
1146  void initGPU(int gridSize, int blkSize);
1147 
1148  int allocateStaticLoad(int bufSize);
1149 
1150  void allocateGroupId();
1151 
1152  void copyFiringInfo_GPU();
1153 
1154  void copyFiringStateFromGPU (int grpId = -1);
1155 
1156  void updateStateAndFiringTable_GPU();
1157 
1158  void showStatus(int simType=CPU_MODE);
1159  void showStatus_GPU();
1160 
1161  void checkInitialization(char* testString=NULL);
1162 
1163  void checkInitialization2(char* testString=NULL);
1164 
1165  int getNumGroups() {
1166  return numGrp;
1167  }
1168 
1169  bool isExcitatoryGroup(int g) {
1170  return (grp_Info[g].Type&TARGET_AMPA) || (grp_Info[g].Type&TARGET_NMDA);
1171  }
1172 
1173  bool isInhibitoryGroup(int g) {
1174  return (grp_Info[g].Type&TARGET_GABAa) || (grp_Info[g].Type&TARGET_GABAb);
1175  }
1176 
1177  bool isPoissonGroup(int g) {
1178  return (grp_Info[g].Type&POISSON_NEURON);
1179  }
1180 
1182  void setDefaultParameters(float alpha_ltp=0, float tau_ltp=0, float alpha_ltd=0, float tau_ltd=0);
1183 
1184  void setupNetwork(int simType=CPU_MODE, int ithGPU=0, bool removeTempMemory=true);
1185 
1186  private:
1187  SparseWeightDelayMatrix* tmp_SynapseMatrix_fixed;
1188  SparseWeightDelayMatrix* tmp_SynapseMatrix_plastic;
1189  FILE* readNetworkFID;
1190 
1192  uint8_t *tmp_SynapticDelay;
1193 
1194  bool simulatorDeleted;
1195 
1196  bool spikeRateUpdated;
1197 
1198  float prevCpuExecutionTime;
1199  float cpuExecutionTime;
1200  float prevGpuExecutionTime;
1201  float gpuExecutionTime;
1202 
1203  int randSeed;
1204 
1205  int currentMode;
1206 
1207  int numConfig;
1208 
1210  bool doneReorganization;
1211  bool memoryOptimized;
1212 
1213  string networkName;
1214  int numGrp;
1215  int numConnections;
1217  unsigned int allocatedN;
1218  unsigned int allocatedPre;
1219  unsigned int allocatedPost;
1220 
1221  grpConnectInfo_t* connectBegin;
1222 
1224  PropagatedSpikeBuffer* pbuf;
1225 
1226  bool sim_with_fixedwts;
1227  bool sim_with_stdp;
1228  bool sim_with_stp;
1229  bool sim_with_conductances;
1231  bool enableGPUSpikeCntPtr;
1232 
1233  // spiking network related info.. neurons, synapses and network parameters
1234  int numN,numNReg,numPostSynapses,D,numNExcReg,numNInhReg, numPreSynapses;
1235  int numNExcPois, numNInhPois, numNPois;
1236  float *voltage, *recovery, *Izh_a, *Izh_b, *Izh_c, *Izh_d, *current;
1237  bool *curSpike;
1238  unsigned int *nSpikeCnt;
1239  unsigned short *Npre;
1240  unsigned short *Npre_plastic;
1241  unsigned short *Npost;
1242  uint32_t *lastSpikeTime;
1243  float *wtChange, *wt;
1244  float *maxSynWt;
1245  uint32_t *synSpikeTime;
1246  unsigned int postSynCnt;
1247  unsigned int preSynCnt;
1248  float *intrinsicWeight;
1249  //added to include homeostasis. -- KDC
1250  float *baseFiring;
1251  float *avgFiring;
1252  unsigned int *nextTaste;
1253  unsigned int *nextDeath;
1254  unsigned int *cumulativePost;
1255  unsigned int *cumulativePre;
1256  post_info_t *preSynapticIds;
1257  post_info_t *postSynapticIds;
1258  delay_info_t *postDelayInfo;
1259 
1260  FILE* fpDotty;
1261 
1263  typedef struct snnSize_s {
1264  unsigned int neuronInfoSize;
1265  unsigned int synapticInfoSize;
1266  unsigned int networkInfoSize;
1267  unsigned int spikingInfoSize;
1268  unsigned int debugInfoSize;
1269  unsigned int addInfoSize;
1270  unsigned int blkInfoSize;
1271  unsigned int monitorInfoSize;
1272  unsigned int probeInfoSize;
1273  } snnSize_t;
1274 
1275  snnSize_t cpuSnnSz;
1276  snnSize_t gpuSnnSz;
1277 
1278  unsigned int postConnCnt;
1279  unsigned int preConnCnt;
1280 
1282  unsigned int *timeTableD2;
1283  unsigned int *timeTableD1;
1284  unsigned int *firingTableD2;
1285  unsigned int *firingTableD1;
1286  unsigned int maxSpikesD1, maxSpikesD2;
1287 
1288  //time and timestep
1289  unsigned int simTimeMs;
1290  uint64_t simTimeSec;
1291  unsigned int simTime;
1292  unsigned int spikeCountAll1sec, secD1fireCntHost, secD2fireCntHost;
1293  unsigned int spikeCountAll, spikeCountD1Host, spikeCountD2Host;
1294  unsigned int nPoissonSpikes;
1295 
1296  //cuda keep track of performance...
1297 //#if __CUDA3__
1298 // unsigned int timer;
1299 //#elif __CUDA5__
1300  StopWatchInterface* timer;
1301 //#endif
1302  float cumExecutionTime;
1303  float lastExecutionTime;
1304 
1305  //debug file
1306  FILE* fpProgLog;
1307  FILE* fpLog;
1308  FILE* fpTuningLog;
1309  int cntTuning;
1310  FILE *fpParam;
1311  int showLog;
1312  int showLogMode;
1313  int showLogCycle;
1314 
1315 
1316  //spike monitor code...
1317  unsigned int numSpikeMonitor;
1318  unsigned int monGrpId[MAX_GRP_PER_SNN];
1319  unsigned int monBufferPos[MAX_GRP_PER_SNN];
1320  unsigned int monBufferSize[MAX_GRP_PER_SNN];
1321  unsigned int* monBufferFiring[MAX_GRP_PER_SNN];
1322  unsigned int* monBufferTimeCnt[MAX_GRP_PER_SNN];
1323  SpikeMonitor* monBufferCallback[MAX_GRP_PER_SNN];
1324 
1325  unsigned int numSpikeGenGrps;
1326 
1327  //current/voltage probe code...
1328  unsigned int numProbe;
1329  typedef struct probeParam_s {
1330  uint32_t printProbe;
1331  uint32_t debugCnt;
1332  unsigned int nid;
1333  int type;
1334  float* bufferI;
1335  float* bufferV;
1336  float* bufferFRate;
1337  float* bufferHomeo;
1338  bool* spikeBins;
1339  int cumCount;
1340  float vmax;
1341  float vmin;
1342  float imax;
1343  float imin;
1344  float fmax;
1345  float hfmax;
1346  struct probeParam_s *next;
1347  } probeParam_t;
1348 
1349  probeParam_t* neuronProbe;
1350 
1351  /* Markram et al. (1998), where the short-term dynamics of synapses is characterized by three parameters:
1352  U (which roughly models the release probability of a synaptic vesicle for the first spike in a train of spikes),
1353  D (time constant for recovery from depression), and F (time constant for recovery from facilitation). */
1354  float* stpu;
1355  float* stpx;
1356  float* gAMPA;
1357  float* gNMDA;
1358  float* gGABAa;
1359  float* gGABAb;
1360 
1361  bool enableSimLogs;
1362  string simLogDirName;
1363 
1364  network_info_t net_Info;
1365 
1366  network_ptr_t cpu_gpuNetPtrs;
1367  network_ptr_t cpuNetPtrs;
1368 
1369  //int Noffset;
1370  int NgenFunc;
1371 
1372  bool finishedPoissonGroup;
1373  bool showDotty;
1375 
1376  bool showGrpFiringInfo;
1377 
1378  // gpu related info...
1379  // information about various data allocated at GPU side...
1380  unsigned int gpu_tStep, gpu_simSec;
1381  unsigned int gpu_simTime;
1382 
1383  group_info_t grp_Info[MAX_GRP_PER_SNN];
1384  group_info2_t grp_Info2[MAX_GRP_PER_SNN];
1385  float* testVar, *testVar2;
1386  uint32_t* spikeGenBits;
1387 
1388  StepFeedback *stepFeedback;
1389 
1390 
1391  /* these are deprecated, and replaced by writeNetwork(FILE*)
1392  void storePostWeight (int destGrp, int srcNid, const string& fname, const string& name);
1393 
1394  void dumpHistogram();
1395  void dumpHistogram(int* table_sHist, int* table_sdHist, FILE *fph, int sec, char* fname, int histSize=HISTOGRAM_SIZE);
1396 
1397  void printHistogram(const char* histName=NULL, bool dontOverWrite=0, int histSize=HISTOGRAM_SIZE);
1398 
1399  void putHistogram(FILE *fp, int sec, const char* fname, int histSize=HISTOGRAM_SIZE, bool dontOverWrite=false);
1400 
1401  void generateHistogram(int* sHist, int* sdHist, int histSize, FILE *fp);
1402 
1403  void generateHistogram_GPU(int* sHist, int* sdHist, int histSize);
1404 
1405  void storeWeights(int dest_grp, int src_grp, const string& dirname, int restoreTime = -1);
1406 
1407  void saveConnectionWeights();
1408 
1409  //histogram related
1410  int stopHistogram;
1411  int histFileCnt;
1412  int rasterFileCnt;
1413  */
1414 
1415  /* deprecated
1416  void initThalInput();
1417  void initThalInput_GPU();
1418 
1419  void plotFiringRate(FILE* fp = NULL, int x=0, int y=0, int y_limit=10000);
1420 
1421  void plotFiringRate(const string& fname, int x, int y, int y_limit);
1422 
1423  void getScaledWeights(void* img, int dest_grp, int src_grp, int resx=1, int resy=1);
1424 
1425  void getScaledWeights1D (void* imgPtr, unsigned int nid, int src_grp, int repx, int repy);
1426 
1427  void showWeightPattern1D (int destGrp, int srcGrp, int locx, int locy);
1428 
1429  void showWeightPattern (int destGrp, int srcGrp, int locx, int locy, int size = IMAGE_SIZE);
1430 
1431  void showWeightRatePattern1D (int destGrp, int srcGrp);
1432 
1433  void getScaledWeightRates1D(unsigned int nid, int src_grp);
1434 
1435  void plotSpikeBuff(int gid, int row, int col=900);
1436 
1437  void setImgWin(int monId, int localId, int t);
1438 
1439  void plotBuffInit(int gid);
1440 
1441 
1442  void updateNetwork();
1443 
1444  // input noise related codes...
1445  void randomNoiseCurrent(float neuronPercentage, float currentStrength, int groupId=-1);
1446 
1447  void updateRandomProperty(); // for random thalamic input
1448 
1449 
1450  // noise generator related info...
1451  int numNoise; // Total number of noise generators
1452  int numRandNeurons; // Total number of neurons selected each time step
1453  int* randNeuronId; // Store the ids of neuron which will get random input current..
1454  noiseGenProperty_t noiseGenGroup[MAX_GRP_PER_SNN];
1455 
1456  */
1457 };
1458 
1459 /*
1460  typedef struct noiseGenProperty_s {
1461  float neuronPercentage; // percentage of neuron that needs random inputs..
1462  float currentStrength; // strength of the noise current applied...
1463  int groupId; // group id.. cross references to group properties
1464  int nstart; // start of the neuron id
1465  int ncount; // total neuron in current group
1466  int rand_ncount; // (ncount*neuronPercentage/100) neurons will be selected
1467  } noiseGenProperty_t;
1468 
1469 */
1470 
1471 #endif
unsigned int * delay_opts
first 8 bits are delay, higher are for Fixed/Plastic and any other future options ...
Definition: snn.h:609
static const unsigned int MAJOR_VERSION
major release version, as in CARLsim X
Definition: snn.h:623
virtual void update(CpuSNN *s, int grpId, unsigned int *Nids, unsigned int *timeCnts, unsigned int total_spikes, float firing_Rate)
Controls actions that are performed when certain neurons fire (user-defined).
Definition: snn.h:271
size_t STP_Pitch
numN rounded upwards to the nearest 256 boundary
Definition: snn.h:326
int createGroup(const string &_name, unsigned int _numN, int _nType, int configId=ALL)
creates a group of Izhikevich spiking neurons
Definition: snn_cpu.cpp:787
float dGABAb
homeostatic plasticity variables
Definition: snn.h:466
used for fine-grained control over the stepping behavior during a runNetwork execution ...
Definition: snn.h:206
int getNumConnections(int connectionId)
Input: connectionID. Output: the number of connections associated with that connection ID...
Definition: snn_cpu.cpp:4153
int connect(int gIDpre, int gIDpost, const string &_type, float initWt, float maxWt, float _C, uint8_t minDelay, uint8_t maxDelay, bool synWtType=SYN_FIXED, const string &wtType=" ")
make from each neuron in grpId1 to 'numPostSynapses' neurons in grpId2
Definition: snn_cpu.cpp:1600
void printConnection(int grpId, FILE *fp=stdout)
print the connection info of grpId
Definition: snn.h:930
float * Npre_plasticInv
stores the 1/number of plastic input connections, for use on the GPU
Definition: snn.h:372
void setSpikeMonitor(int gid, SpikeMonitor *spikeMon=NULL, int configId=ALL)
Definition: snn_cpu.cpp:3981
float * wt
stores the synaptic weight and weight change of a synaptic connection
Definition: snn.h:375
virtual void connect(CpuSNN *s, int srcGrpId, int i, int destGrpId, int j, float &weight, float &maxWt, float &delay, bool &connected)
specifies which synaptic connections (per group, per neuron, per synapse) should be made ...
Definition: snn.h:250
unsigned int * lastSpikeTime
storees the firing time of the neuron
Definition: snn.h:374
int * fixedDestGrps
connected destination groups array, (x=destGrpId, y=startN, z=endN, w=function pointer) ...
Definition: snn.h:549
void resetSpikeCnt(int grpId=-1)
Resets the spike count for a particular group.
Definition: snn_cpu.cpp:293
unsigned int * nSpikeCnt
homeostatic plasticity variables
Definition: snn.h:413
used for fine-grained control over spike generation, using a callback mechanism
Definition: snn.h:226
delay_info_t * postDelayInfo
delay information
Definition: snn.h:391
bool updateTime()
returns true when a new second is started
Definition: snn_cpu.cpp:2622
used for fine-grained control over spike generation, using a callback mechanism
Definition: snn.h:244
int allocated
true if all data has been allocated..
Definition: snn.h:367
int runNetwork(int _nsec, int _tstep=0, int simType=CPU_MODE, int ithGPU=0, bool enablePrint=false, int copyState=false)
run the simulation for n sec simType can either be CPU_MODE or GPU_MODE ithGPU: specify on which CUDA...
Definition: snn_cpu.cpp:2644
int createSpikeGeneratorGroup(const string &_name, int unsigned size_n, int stype, int configId=ALL)
creates a spike generator group (dummy-neurons, not Izhikevich spiking neurons).
Definition: snn_cpu.cpp:838
Schedule/Store spikes to be delivered at a later point in the simulation.
void CpuSNNInit(unsigned int _numN, unsigned int _numPostSynapses, unsigned int _numPreSynapses, unsigned int _D)
Definition: snn_cpu.cpp:159
int * fixedDestParam
connected destination parameters , (x=Start, y=Width, z=Stride, w=height)
Definition: snn.h:550
bool hasCommonDelay
'true' if the grpDelayVector is same as the neuron DelayVector
Definition: snn.h:545
void setNeuronParameters(int groupId, float _a, float a_sd, float _b, float b_sd, float _c, float c_sd, float _d, float d_sd, int configId=ALL)
Sets the Izhikevich parameters a, b, c, and d of a neuron group.
Definition: snn_cpu.cpp:923
unsigned short * Npost
stores the number of output connections from a neuron.
Definition: snn.h:373
int16_t srcGrpId
group id
Definition: snn.h:540
float * maxSynWt
maximum synaptic weight for given connection..
Definition: snn.h:376
void printMemoryInfo(FILE *fp=stdout)
prints memory info to file
int grpDelayVector
a vector with ones in position having a given delay
Definition: snn.h:543
bool hasRandomConn
set to 'true' if the group has random connections
Definition: snn.h:546
void setLogCycle(unsigned int _cnt, int mode=0, FILE *fp=NULL)
sets the update cycle for log messages
Definition: snn.h:762
unsigned int * poissonRandPtr
firing random number. max value is 10,000
Definition: snn.h:407
unsigned short * Npre
stores the number of input connections to the neuron
Definition: snn.h:370
virtual unsigned int nextSpikeTime(CpuSNN *s, int grpId, int i, unsigned int currentTime)
controls spike generation using a callback
Definition: snn.h:232
bool enablePrint
when we call print state, should the group properties be printed. default is false and we do not want...
Definition: snn.h:505
virtual bool stepUpdate(CpuSNN *s, int step)
Definition: snn.h:211
void resetSpikeCnt_GPU(int _startGrp, int _endGrp)
Utility function to clear spike counts in the GPU code.
bool newUpdates
FIXME this flag has mixed meaning and is not rechecked after the simulation is started.
Definition: snn.h:475
void printPostConnection(FILE *fp=stdout)
print all the connections...
void readNetwork(FILE *fid)
reads the network state from file
Definition: snn_cpu.cpp:1952
void updateNetwork()
Original updateNetwork() function used by JMN.
Definition: snn_cpu.cpp:3588
short int MaxFiringRate
this is for the monitoring mechanism, it needs to know what is the maximum firing rate in order to al...
Definition: snn.h:437
void printNeuronStateBinary(string fname, int grpId, int configId=0, int count=-1)
Debugging function that outputs regular neuron state variables to a binary file at every timestep...
static const unsigned int MINOR_VERSION
minor release version, as in CARLsim 2.X
Definition: snn.h:624
void writeNetwork(FILE *fid)
stores the pre and post synaptic neuron ids with the weight and delay
Definition: snn_cpu.cpp:1886
void updateNetwork_GPU(bool resetFiringInfo)
void getPopWeights(int gIDpre, int gIDpost, float *&weights, int &size, int configId=0)
Writes weights from synaptic connections from gIDpre to gIDpost. Returns a pointer to the weights and...
Definition: snn_cpu.cpp:1166
int srcStartN
starting neuron to begin computation
Definition: snn.h:541
void printDotty()
prints a network graph using Dotty (GraphViz)
Definition: snn_cpu.cpp:1464
int srcEndN
ending neuron to stop computation
Definition: snn.h:542
void setHomeostasis(int g, bool enable, int configId=0)
Sets the homeostasis parameters. g is the grpID, enable=true(false) enables(disables) homeostasis...
Definition: snn_cpu.cpp:746
int3 * groupIdInfo
used for group Id calculations...
Definition: snn.h:409
connection infos...
Definition: snn.h:517
void resetSpikeCntUtil(int grpId=-1)
Resets the spike count for a particular neuron group. Input: group ID variable named grpID...
Definition: snn_cpu.cpp:318
unsigned short * Npre_plastic
stores the number of plastic input connections
Definition: snn.h:371
void printSimSummary(FILE *fp=stdout)
prints a simulation summary to file
void writePopWeights(string fname, int gIDpre, int gIDpost, int configId=0)
function writes population weights from gIDpre to gIDpost to file fname in binary.
Definition: snn_cpu.cpp:1228
can be used to create a custom spike monitor
Definition: snn.h:265
int16_t fixedDestGrpCnt
destination group count
Definition: snn.h:548
void setBaseFiring(int groupId, int configId, float _baseFiring, float _baseFiringSD)
Sets the homeostatic target firing rate. Neurons will try to attain this firing rate using homeostati...
Definition: snn_cpu.cpp:779
void copyUpdateVariables_GPU()
uint32_t * probeId
Definition: snn.h:399
void setCopyFiringStateFromGPU(bool _enableGPUSpikeCntPtr)
Sets enableGpuSpikeCntPtr to true or false. True allows getSpikeCntPtr_GPU to copy firing state infor...
Definition: snn.h:869
post_info_t * postSynapticIds
10 bit syn id, 22 bit neuron id, ordered based on delay
Definition: snn.h:388
int CurrTimeSlice
timeSlice is used by the Poisson generators in order to note generate too many or too few spikes with...
Definition: snn.h:440
unsigned int * getSpikeCntPtr(int grpId=-1, int simType=CPU_MODE)
Returns pointer to nSpikeCnt, which is a 1D array of the number of spikes every neuron in the group h...
Definition: snn.h:879
Contains all of CARLsim's core functionality.
Definition: snn.h:619
void reassignFixedWeights(int connectId, float weightMatrix[], int matrixSize, int configId=ALL)
Reassigns fixed weights to values passed into the function in a single 1D float matrix called weightM...
Definition: snn_cpu.cpp:4099
int grpMaxM
the maximum value of the number of post-synaptic connections
Definition: snn.h:544