48 #include "gpu_random.h"
50 #include "PropagatedSpikeBuffer.h"
52 #define USE_EXCEPTIONS 1
57 #endif // USE_EXCEPTIONS
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>
75 #include "CUDAVersionControl.h"
80 #define CARLSIM_STEP_INCREMENT 0.001
84 #define CARLSIM_STEP_SIZE 10
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)
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))
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)
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
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)
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)
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"); \
150 #define STP_BUF_POS(nid,t) (nid*STP_BUF_SIZE+((t)%STP_BUF_SIZE))
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))))
166 inline bool isExcitatoryNeuron (
unsigned int& nid,
unsigned int& numNInhPois,
unsigned int& numNReg,
unsigned int& numNExcReg,
unsigned int& numN)
168 return ((nid < numN) && ((nid < numNExcReg) || (nid >= numNReg + numNInhPois)));
170 inline bool isInhibitoryNeuron (
unsigned int& nid,
unsigned int& numNInhPois,
unsigned int& numNReg,
unsigned int& numNExcReg,
unsigned int& numN)
172 return ((nid >= numNExcReg) && (nid < (numNReg + numNInhPois)));
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)
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)
191 #ifdef USE_EXCEPTIONS
192 #define carlsim_assert(pred) {if(!(pred)) throw std::runtime_error("Assert triggered.\n");}
194 #define carlsim_assert(pred) assert(pred)
212 virtual void updateMonitors(
CpuSNN* s,
int step) { assert(
false);};
232 virtual unsigned int nextSpikeTime(
CpuSNN* s,
int grpId,
int i,
unsigned int currentTime) { assert(
false);
return 0; };
250 virtual void connect(
CpuSNN* s,
int srcGrpId,
int i,
int destGrpId,
int j,
float& weight,
float& maxWt,
float& delay,
bool& connected) { assert(
false); };
256 virtual void set(
CpuSNN* s,
int grpId,
int i,
float& a,
float& b,
float& c,
float& d) {};
271 virtual void update(
CpuSNN* s,
int grpId,
unsigned int* Nids,
unsigned int* timeCnts,
unsigned int total_spikes,
float firing_Rate) {};
277 PoissonRate(
float* _rates, uint32_t _len,
bool _onGPU=
false) {
281 allocatedRatesInternally =
false;
286 CUDA_CHECK_ERRORS(cudaMalloc ((
void**)&rates, _len*
sizeof(
float)));
288 rates =
new float[_len];
292 allocatedRatesInternally =
true;
297 if (allocatedRatesInternally) {
299 CUDA_CHECK_ERRORS(cudaThreadSynchronize());
300 CUDA_CHECK_ERRORS(cudaFree(rates));
311 bool allocatedRatesInternally;
316 short delay_index_start;
327 unsigned int numN,numPostSynapses,D,numNExcReg,numNInhReg, numNReg;
328 unsigned int I_setLength;
330 unsigned int preSynLength;
333 unsigned int postSynCnt;
334 unsigned int preSynCnt;
335 unsigned int maxSpikesD2,maxSpikesD1;
337 unsigned int numNExcPois;
338 unsigned int numNInhPois;
339 unsigned int numNPois;
341 bool sim_with_fixedwts;
342 bool sim_with_conductances;
348 inline post_info_t SET_CONN_ID(
int nid,
int sid,
int grpId)
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);
355 p.postId = (((sid)<<CONN_SYN_NEURON_BITS)+((nid)&CONN_SYN_NEURON_MASK));
361 float *voltage, *recovery, *Izh_a, *Izh_b, *Izh_c, *Izh_d, *current;
364 float *gNMDA, *gAMPA, *gGABAa, *gGABAb;
375 float *wtChange, *
wt;
377 uint32_t *synSpikeTime;
378 uint32_t *neuronFiring;
379 unsigned int *cumulativePost;
380 unsigned int *cumulativePre;
392 unsigned int* firingTableD1;
393 unsigned int* firingTableD2;
403 float* probeHomeoFreq;
404 float* probeBaseFreq;
406 float* poissonFireRate;
408 int2* neuronAllocation;
410 short int* synIdLimit;
416 float* baseFiringInv;
424 uint32_t* spikeGenBits;
442 uint32_t SliceUpdateTime;
446 bool isSpikeGenerator;
449 bool WithHomeostasis;
450 bool WithConductances;
470 float avgTimeScale_decay;
471 float avgTimeScaleInv;
472 float homeostasisScale;
514 enum conType_t { CONN_RANDOM, CONN_ONE_TO_ONE, CONN_FULL, CONN_FULL_NO_DIRECT, CONN_USER_DEFINED, CONN_UNKNOWN};
519 uint8_t maxDelay, minDelay;
529 int numberOfConnections;
534 #define MAX_GRPS_PER_BLOCK 100
535 #define MAX_BLOCKS 120
547 int* randomDelayPointer;
579 void resize(
int inc) {
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));
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);
592 weights[count] = weight;
593 maxWeights[count] = maxWeight;
594 preIds[count] = preId;
595 postIds[count] = postId;
598 if (preId > maxPreId) maxPreId = preId;
599 if (postId > maxPostId) maxPostId = postId;
604 unsigned int count, size, maxPreId, maxPostId;
607 unsigned int* preIds;
608 unsigned int* postIds;
626 CpuSNN(
const string& _name,
int _numConfig = 1,
int randomize = 0,
int mode=CPU_MODE);
630 int createGroup(
const string& _name,
unsigned int _numN,
int _nType,
int configId = ALL);
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);
641 void setNeuronParameters(
int groupId,
float _a,
float _b,
float _c,
float _d,
int configId=ALL);
645 void setGroupInfo(
int groupId,
group_info_t info,
int configId=ALL);
655 void CpuSNNInit(
unsigned int _numN,
unsigned int _numPostSynapses,
unsigned int _numPreSynapses,
unsigned int _D);
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 =
" ");
670 int runNetwork(
int _nsec,
int _tstep = 0,
int simType = CPU_MODE,
int ithGPU = 0,
bool enablePrint=
false,
int copyState=
false);
673 uint64_t getSimTime() {
return simTime; }
675 uint32_t getSimTimeSec() {
return simTimeSec; }
677 uint32_t getSimTimeMs() {
return simTimeMs; }
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);
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);
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);
702 void setHomeostasis(
int g,
bool enable,
float homeostasisScale,
float avgTimeScale,
int configId=0);
709 void setBaseFiring(
int groupId,
int configId,
float _baseFiring,
float _baseFiringSD);
718 void setSpikeRate(
int grpId,
PoissonRate* spikeRate,
int refPeriod=1,
int configId=ALL);
719 void setSpikeGenerator(
int grpId,
SpikeGenerator* spikeGen,
int configId=ALL);
725 #if READNETWORK_ADD_SYNAPSES_FROM_FILE
726 int readNetwork_internal(
bool onlyPlastic);
728 int readNetwork_internal();
732 void copyGrpInfo_GPU();
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);
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);
753 void printTuningLog();
755 void setTuningLog(
string fname)
757 fpTuningLog = fopen(fname.c_str(),
"w");
758 carlsim_assert(fpTuningLog != NULL);
765 showLog = (_cnt == 0)? 0 : 1;
778 void setProbe(
int g,
const string& type,
int startId=0,
int cnt=1, uint32_t _printProbe=0);
780 int grpStartNeuronId(
int g) {
return grp_Info[g].StartN; }
782 int grpEndNeuronId(
int g) {
return grp_Info[g].EndN; }
784 int grpNumNeurons(
int g) {
return grp_Info[g].SizeN; }
791 int getNumConfigurations() {
794 int getGroupId(
int groupId,
int configId);
796 int getNextGroupId(
int);
797 int getConnectionId(
int connId,
int configId);
800 void setPrintState(
int grpId,
bool _status,
int neuronId=-1)
804 void printState(
const char *str =
"");
805 void printWeight(
int grpId,
const char *str =
"");
806 void printNeuronState(
int grpId, FILE *fp = stderr);
808 void setSimLogs(
bool enable,
string logDirName =
"") {
809 enableSimLogs = enable;
810 if (logDirName !=
"") {
811 simLogDirName = logDirName;
815 void printParameters(FILE *fp);
817 void printGroupInfo(FILE* fp);
819 void printGroupInfo(
string& strName);
821 void printConnectionInfo(FILE* fp);
823 void printConnectionInfo2(FILE *fpg);
825 void printGroupInfo2(FILE* fpg);
827 int printPostConnection2(
int grpId, FILE* fpg);
829 int printPreConnection2(
int grpId, FILE* fpg);
831 void printFiringRate(
char *fname=NULL);
870 enableGPUSpikeCntPtr=_enableGPUSpikeCntPtr;
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);
886 if(simType == GPU_MODE){
887 carlsim_assert(enableGPUSpikeCntPtr);
890 return ((grpId == -1) ? nSpikeCnt : &nSpikeCnt[grp_Info[grpId].StartN]);
903 void reassignFixedWeights(
int connectId,
float weightMatrix [],
int matrixSize,
int configId = ALL);
909 void printNetworkInfo();
914 void printPreConnection(FILE *fp = stdout);
916 void printConnection(
const string& fname)
918 FILE *fp = fopen(fname.c_str(),
"w");
923 void printConnection(FILE *fp = stdout)
926 printPreConnection(fp);
933 printPreConnection(grpId, fp);
938 void printPreConnection(
int grpId, FILE *fp = stdout);
941 void showGroupStatus(
int _f) { showGrpFiringInfo = _f; }
943 void showDottyViewer(
int _f) { showDotty = _f; }
957 void setStepFeedback(
StepFeedback *feedback) {stepFeedback = feedback;};
959 void setSpikeRateUpdated() {spikeRateUpdated =
true;};
962 void setGrpTimeSlice(
int grpId,
int timeSlice);
966 void dumpSpikeBuffToFile_GPU(
int gid);
968 void assignPoissonFiringRate_GPU();
970 void setSpikeGenBit_GPU(
unsigned int nid,
int grp);
972 void generateSpikes();
974 void generateSpikes(
int grpId);
976 void generateSpikesFromFuncPtr(
int grpId);
978 void generateSpikesFromRate(
int grpId);
980 void startCPUTiming();
981 void resetCPUTiming();
982 void stopCPUTiming();
983 void startGPUTiming();
984 void resetGPUTiming();
985 void stopGPUTiming();
987 void resetPointers();
989 void resetConductances();
990 void resetCounters();
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();
998 void resetFiringInformation();
1000 void resetFiringInformation_GPU();
1003 void doD1CurrentUpdate();
1004 void doD2CurrentUpdate();
1008 void doSTPUpdates();
1010 void generatePostSpike(
unsigned int pre_i,
unsigned int idx_d,
unsigned int offset,
unsigned int tD);
1012 void globalStateUpdate();
1014 void updateStateAndFiringTable();
1016 void updateSpikesFromGrp(
int grpId);
1018 void updateSpikeGeneratorsInit();
1020 void updateSpikeGenerators();
1024 int addSpikeToTable(
int id,
int g);
1026 float getWeights(
int connProp,
float initWt,
float maxWt,
unsigned int nid,
int grpId);
1029 inline void setConnection(
int srcGrpId,
int destGrpId,
unsigned int src,
unsigned int dest,
float synWt,
float maxWt, uint8_t dVal,
int connProp);
1036 void exitSimulation(
int val,
const char *errorString);
1038 void deleteObjects();
1039 void deleteObjectsGPU();
1041 void testSpikeSenderReceiver(FILE* fpLog,
int simTime);
1043 void printFiringInfo(FILE* fp,
int grpId=-1);
1045 void printFiredId(FILE* fp,
bool clear=
false,
int myGrpId=-1);
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);
1049 void printGpuLoadBalance(
bool init =
false,
int numBlocks = MAX_BLOCKS, FILE*fp = stdout);
1051 void printCurrentInfo(FILE *fp);
1053 int checkErrors(
string kernelName,
int numBlocks);
1054 int checkErrors(
int numBlocks);
1056 void updateParameters(
int* numN,
int* numPostSynapses,
int* D,
int nConfig=1);
1058 int updateSpikeTables();
1060 void reorganizeNetwork(
bool removeTempMemory,
int simType);
1062 void reorganizeDelay();
1064 void swapConnections(
int nid,
int oldPos,
int newPos);
1067 void compactConnections();
1071 void regroupConnections(FILE *fp=NULL);
1074 void initSynapticWeights();
1077 int findGrpId(
int nid);
1080 void updateSpikeMonitor();
1082 void updateSpikeMonitor_GPU();
1084 void updateMonitors();
1086 void updateAfterMaxTime();
1090 void CpuSNNinitGPUparams();
1093 void allocateSNN_GPU(
int ithGPU);
1095 void allocateNetworkParameters();
1097 void allocateGroupParameters();
1099 void buildNetwork();
1101 void buildGroup(
int groupId);
1103 void buildPoissonGroup(
int groupId);
1105 void copyWeightsGPU(
unsigned int nid,
int src_grp);
1114 void copyNeuronParameters(
network_ptr_t* dest,
int kind,
int allocateMem,
int grpId = -1);
1120 void copyConnections(
network_ptr_t* dest,
int kind,
int allocateMem);
1122 void copyPostConnectionInfo(
network_ptr_t* dest,
int allocateMem);
1124 void copyState(
network_ptr_t* dest,
int kind,
int allocateMem);
1126 void printGpuPostConnection(
int grpId, FILE* fp,
int numBlock);
1130 void copyParameters();
1132 int getPoissNeuronPos(
int nid);
1134 void findFiring_GPU();
1136 void spikeGeneratorUpdate_GPU();
1138 void updateTimingTable_GPU();
1140 void doCurrentUpdate_GPU();
1142 void globalStateUpdate_GPU();
1146 void initGPU(
int gridSize,
int blkSize);
1148 int allocateStaticLoad(
int bufSize);
1150 void allocateGroupId();
1152 void copyFiringInfo_GPU();
1154 void copyFiringStateFromGPU (
int grpId = -1);
1156 void updateStateAndFiringTable_GPU();
1158 void showStatus(
int simType=CPU_MODE);
1159 void showStatus_GPU();
1161 void checkInitialization(
char* testString=NULL);
1163 void checkInitialization2(
char* testString=NULL);
1165 int getNumGroups() {
1169 bool isExcitatoryGroup(
int g) {
1170 return (grp_Info[g].Type&TARGET_AMPA) || (grp_Info[g].Type&TARGET_NMDA);
1173 bool isInhibitoryGroup(
int g) {
1174 return (grp_Info[g].Type&TARGET_GABAa) || (grp_Info[g].Type&TARGET_GABAb);
1177 bool isPoissonGroup(
int g) {
1178 return (grp_Info[g].Type&POISSON_NEURON);
1182 void setDefaultParameters(
float alpha_ltp=0,
float tau_ltp=0,
float alpha_ltd=0,
float tau_ltd=0);
1184 void setupNetwork(
int simType=CPU_MODE,
int ithGPU=0,
bool removeTempMemory=
true);
1189 FILE* readNetworkFID;
1192 uint8_t *tmp_SynapticDelay;
1194 bool simulatorDeleted;
1196 bool spikeRateUpdated;
1198 float prevCpuExecutionTime;
1199 float cpuExecutionTime;
1200 float prevGpuExecutionTime;
1201 float gpuExecutionTime;
1210 bool doneReorganization;
1211 bool memoryOptimized;
1217 unsigned int allocatedN;
1218 unsigned int allocatedPre;
1219 unsigned int allocatedPost;
1226 bool sim_with_fixedwts;
1229 bool sim_with_conductances;
1231 bool enableGPUSpikeCntPtr;
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;
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;
1245 uint32_t *synSpikeTime;
1246 unsigned int postSynCnt;
1247 unsigned int preSynCnt;
1248 float *intrinsicWeight;
1252 unsigned int *nextTaste;
1253 unsigned int *nextDeath;
1254 unsigned int *cumulativePost;
1255 unsigned int *cumulativePre;
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;
1278 unsigned int postConnCnt;
1279 unsigned int preConnCnt;
1282 unsigned int *timeTableD2;
1283 unsigned int *timeTableD1;
1284 unsigned int *firingTableD2;
1285 unsigned int *firingTableD1;
1286 unsigned int maxSpikesD1, maxSpikesD2;
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;
1300 StopWatchInterface* timer;
1302 float cumExecutionTime;
1303 float lastExecutionTime;
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];
1325 unsigned int numSpikeGenGrps;
1328 unsigned int numProbe;
1329 typedef struct probeParam_s {
1330 uint32_t printProbe;
1346 struct probeParam_s *next;
1349 probeParam_t* neuronProbe;
1362 string simLogDirName;
1372 bool finishedPoissonGroup;
1376 bool showGrpFiringInfo;
1380 unsigned int gpu_tStep, gpu_simSec;
1381 unsigned int gpu_simTime;
1385 float* testVar, *testVar2;
1386 uint32_t* spikeGenBits;
unsigned int * delay_opts
first 8 bits are delay, higher are for Fixed/Plastic and any other future options ...
static const unsigned int MAJOR_VERSION
major release version, as in CARLsim X
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).
size_t STP_Pitch
numN rounded upwards to the nearest 256 boundary
int createGroup(const string &_name, unsigned int _numN, int _nType, int configId=ALL)
creates a group of Izhikevich spiking neurons
float dGABAb
homeostatic plasticity variables
used for fine-grained control over the stepping behavior during a runNetwork execution ...
int getNumConnections(int connectionId)
Input: connectionID. Output: the number of connections associated with that connection ID...
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
void printConnection(int grpId, FILE *fp=stdout)
print the connection info of grpId
float * Npre_plasticInv
stores the 1/number of plastic input connections, for use on the GPU
void setSpikeMonitor(int gid, SpikeMonitor *spikeMon=NULL, int configId=ALL)
float * wt
stores the synaptic weight and weight change of a synaptic connection
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 ...
unsigned int * lastSpikeTime
storees the firing time of the neuron
int * fixedDestGrps
connected destination groups array, (x=destGrpId, y=startN, z=endN, w=function pointer) ...
void resetSpikeCnt(int grpId=-1)
Resets the spike count for a particular group.
unsigned int * nSpikeCnt
homeostatic plasticity variables
used for fine-grained control over spike generation, using a callback mechanism
delay_info_t * postDelayInfo
delay information
bool updateTime()
returns true when a new second is started
used for fine-grained control over spike generation, using a callback mechanism
int allocated
true if all data has been allocated..
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...
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).
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)
int * fixedDestParam
connected destination parameters , (x=Start, y=Width, z=Stride, w=height)
bool hasCommonDelay
'true' if the grpDelayVector is same as the neuron DelayVector
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.
unsigned short * Npost
stores the number of output connections from a neuron.
float * maxSynWt
maximum synaptic weight for given connection..
void printMemoryInfo(FILE *fp=stdout)
prints memory info to file
int grpDelayVector
a vector with ones in position having a given delay
bool hasRandomConn
set to 'true' if the group has random connections
void setLogCycle(unsigned int _cnt, int mode=0, FILE *fp=NULL)
sets the update cycle for log messages
unsigned int * poissonRandPtr
firing random number. max value is 10,000
unsigned short * Npre
stores the number of input connections to the neuron
virtual unsigned int nextSpikeTime(CpuSNN *s, int grpId, int i, unsigned int currentTime)
controls spike generation using a callback
bool enablePrint
when we call print state, should the group properties be printed. default is false and we do not want...
virtual bool stepUpdate(CpuSNN *s, int step)
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.
void printPostConnection(FILE *fp=stdout)
print all the connections...
void readNetwork(FILE *fid)
reads the network state from file
void updateNetwork()
Original updateNetwork() function used by JMN.
short int MaxFiringRate
this is for the monitoring mechanism, it needs to know what is the maximum firing rate in order to al...
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
void writeNetwork(FILE *fid)
stores the pre and post synaptic neuron ids with the weight and delay
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...
int srcStartN
starting neuron to begin computation
void printDotty()
prints a network graph using Dotty (GraphViz)
int srcEndN
ending neuron to stop computation
void setHomeostasis(int g, bool enable, int configId=0)
Sets the homeostasis parameters. g is the grpID, enable=true(false) enables(disables) homeostasis...
int3 * groupIdInfo
used for group Id calculations...
void resetSpikeCntUtil(int grpId=-1)
Resets the spike count for a particular neuron group. Input: group ID variable named grpID...
unsigned short * Npre_plastic
stores the number of plastic input connections
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.
can be used to create a custom spike monitor
int16_t fixedDestGrpCnt
destination group count
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...
void copyUpdateVariables_GPU()
void setCopyFiringStateFromGPU(bool _enableGPUSpikeCntPtr)
Sets enableGpuSpikeCntPtr to true or false. True allows getSpikeCntPtr_GPU to copy firing state infor...
post_info_t * postSynapticIds
10 bit syn id, 22 bit neuron id, ordered based on delay
int CurrTimeSlice
timeSlice is used by the Poisson generators in order to note generate too many or too few spikes with...
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...
Contains all of CARLsim's core functionality.
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...
int grpMaxM
the maximum value of the number of post-synaptic connections