AnimatLab  2
Test
printSNNInfo.cpp
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 #include "snn.h"
42 
43 #if ! (_WIN32 || _WIN64)
44 #include <string.h>
45 #define strcmpi(s1,s2) strcasecmp(s1,s2)
46 #endif
47 
48 
49 extern MTRand_closed getRandClosed;
50 extern MTRand getRand;
51 extern RNG_rand48* gpuRand48;
52 
54 {
55  checkNetworkBuilt();
56 
57  fprintf(fp, "*************Memory Info *************\n");
58  int totMemSize = cpuSnnSz.networkInfoSize+cpuSnnSz.synapticInfoSize+cpuSnnSz.neuronInfoSize+cpuSnnSz.spikingInfoSize;
59  fprintf(fp, "Neuron Info Size: %3.2f (%f MB)\n", cpuSnnSz.neuronInfoSize*100.0/totMemSize, cpuSnnSz.neuronInfoSize/(1024.0*1024));
60  fprintf(fp, "Synaptic Info Size: %3.2f (%f MB)\n", cpuSnnSz.synapticInfoSize*100.0/totMemSize, cpuSnnSz.synapticInfoSize/(1024.0*1024));
61  fprintf(fp, "Network Size: %3.2f (%f MB)\n", cpuSnnSz.networkInfoSize*100.0/totMemSize, cpuSnnSz.networkInfoSize/(1024.0*1024));
62  fprintf(fp, "Firing Info Size: %3.2f (%f MB)\n", cpuSnnSz.spikingInfoSize*100.0/totMemSize, cpuSnnSz.spikingInfoSize/(1024.0*1024));
63  fprintf(fp, "Additional Info: %3.2f (%f MB)\n", cpuSnnSz.addInfoSize*100.0/totMemSize, cpuSnnSz.addInfoSize/(1024.0*1024));
64  fprintf(fp, "DebugInfo Info: %3.2f (%f MB)\n", cpuSnnSz.debugInfoSize*100.0/totMemSize, cpuSnnSz.debugInfoSize/(1024.0*1024));
65  fprintf(fp, "**************************************\n\n");
66 
67  fprintf(fp, "************* Connection Info *************\n");
68  for(int g=0; g < numGrp; g++) {
69  int TNpost=0;
70  int TNpre=0;
71  int TNpre_plastic=0;
72  for(int i=grp_Info[g].StartN; i <= grp_Info[g].EndN; i++) {
73  TNpost += Npost[i];
74  TNpre += Npre[i];
75  TNpre_plastic += Npre_plastic[i];
76  }
77  fprintf(fp, "%s Group (num_neurons=%5d): \n\t\tNpost[%2d] = %3d, Npre[%2d]=%3d Npre_plastic[%2d]=%3d \n\t\tcumPre[%5d]=%5d cumPre[%5d]=%5d cumPost[%5d]=%5d cumPost[%5d]=%5d \n",
78  grp_Info2[g].Name.c_str(), grp_Info[g].SizeN, g, TNpost/grp_Info[g].SizeN, g, TNpre/grp_Info[g].SizeN, g, TNpre_plastic/grp_Info[g].SizeN,
79  grp_Info[g].StartN, cumulativePre[grp_Info[g].StartN], grp_Info[g].EndN, cumulativePre[grp_Info[g].EndN],
80  grp_Info[g].StartN, cumulativePost[grp_Info[g].StartN], grp_Info[g].EndN, cumulativePost[grp_Info[g].EndN]);
81  }
82  fprintf(fp, "**************************************\n\n");
83 
84 }
85 
86 
87 
88 
89 // This method allows us to print all information about the neuron.
90 // If the enablePrint is false for a specific group, we do not print its state.
91 void CpuSNN::printState(const char *str)
92 {
93  fprintf(stderr, "%s", str);
94  for(int g=0; g < numGrp; g++) {
95  if(grp_Info2[g].enablePrint) {
96  printNeuronState(g, stderr);
97  //printWeight(currentMode, g, "Displaying weights\n");
98  }
99  }
100 }
101 
102 void CpuSNN::printGroupInfo(FILE* fp)
103 {
104  //FILE* fpg=fopen("group_info.txt", "w");
105  //fprintf(fpg, "Group Id : Start : End : Group Name\n");
106  for(int g=0; g < numGrp; g++) {
107  //fprintf(fpg, "%d %d %d %s\n", g, grp_Info[g].StartN, grp_Info[g].EndN, grp_Info2[g].Name.c_str());
108  fprintf(fp, "Group %s: \n", grp_Info2[g].Name.c_str());
109  fprintf(fp, "------------\n");
110  fprintf(fp, "\t Size = %d\n", grp_Info[g].SizeN);
111  fprintf(fp, "\t Start = %d\n", grp_Info[g].StartN);
112  fprintf(fp, "\t End = %d\n", grp_Info[g].EndN);
113  fprintf(fp, "\t numPostSynapses = %d\n", grp_Info[g].numPostSynapses);
114  fprintf(fp, "\t numPreSynapses = %d\n", grp_Info[g].numPreSynapses);
115  fprintf(fp, "\t Average Post Connections = %f\n", 1.0*grp_Info2[g].numPostConn/grp_Info[g].SizeN);
116  fprintf(fp, "\t Average Pre Connections = %f\n", 1.0*grp_Info2[g].numPreConn/grp_Info[g].SizeN);
117 
118  if(grp_Info[g].Type&POISSON_NEURON) {
119  fprintf(fp, "\t Refractory-Period = %f\n", grp_Info[g].RefractPeriod);
120  }
121 
122  fprintf(fp, "\t FIXED_WTS = %s\n", grp_Info[g].FixedInputWts? "FIXED_WTS":"PLASTIC_WTS");
123 
124  if (grp_Info[g].WithSTP) {
125  fprintf(fp, "\t STP_U = %f\n", grp_Info[g].STP_U);
126  fprintf(fp, "\t STP_tD = %f\n", grp_Info[g].STP_tD);
127  fprintf(fp, "\t STP_tF = %f\n", grp_Info[g].STP_tF);
128  }
129 
130  if(grp_Info[g].WithSTDP) {
131  fprintf(fp, "\t ALPHA_LTP = %f\n", grp_Info[g].ALPHA_LTP);
132  fprintf(fp, "\t ALPHA_LTD = %f\n", grp_Info[g].ALPHA_LTD);
133  fprintf(fp, "\t TAU_LTP_INV = %f\n", grp_Info[g].TAU_LTP_INV);
134  fprintf(fp, "\t TAU_LTD_INV = %f\n", grp_Info[g].TAU_LTD_INV);
135  }
136 
137  }
138  //fclose(fpg);
139 }
140 
141 void CpuSNN::printGroupInfo2(FILE* fpg)
142 {
143  fprintf(fpg, "#Group Information\n");
144  for(int g=0; g < numGrp; g++) {
145  fprintf(fpg, "group %d: name %s : type %s %s %s %s %s: size %d : start %d : end %d \n",
146  g, grp_Info2[g].Name.c_str(),
147  (grp_Info[g].Type&POISSON_NEURON) ? "poisson " : "",
148  (grp_Info[g].Type&TARGET_AMPA) ? "AMPA" : "",
149  (grp_Info[g].Type&TARGET_NMDA) ? "NMDA" : "",
150  (grp_Info[g].Type&TARGET_GABAa) ? "GABAa" : "",
151  (grp_Info[g].Type&TARGET_GABAb) ? "GABAb" : "",
152  grp_Info[g].SizeN,
153  grp_Info[g].StartN,
154  grp_Info[g].EndN);
155  }
156  fprintf(fpg, "\n");
157  fflush(fpg);
158 }
159 
160 void CpuSNN::printConnectionInfo2(FILE *fpg)
161 {
162  grpConnectInfo_t* newInfo = connectBegin;
163 
164  fprintf(fpg, "#Connection Information \n");
165  fprintf(fpg, "#(e.g. from => to : approx. # of post (numPostSynapses) : approx. # of pre-synaptic (numPreSynapses) : weights.. : type plastic or fixed : max and min axonal delay\n");
166  while(newInfo) {
167  bool synWtType = GET_FIXED_PLASTIC(newInfo->connProp);
168  fprintf(fpg, " %d => %d : %s => %s : numPostSynapses %d : numPreSynapses %d : initWeight %f : maxWeight %3.3f : type %s : maxDelay %d : minDelay %d\n",
169  newInfo->grpSrc, newInfo->grpDest, grp_Info2[newInfo->grpSrc].Name.c_str(), grp_Info2[newInfo->grpDest].Name.c_str(),
170  newInfo->numPostSynapses, newInfo->numPreSynapses, newInfo->initWt, newInfo->maxWt,
171  (synWtType == SYN_PLASTIC)?"plastic":"fixed", newInfo->maxDelay, newInfo->minDelay);
172  newInfo = newInfo->next;
173  }
174  fprintf(fpg, "\n");
175  fflush(fpg);
176 }
177 
178 void CpuSNN::printConnectionInfo(FILE *fp)
179 {
180  grpConnectInfo_t* newInfo = connectBegin;
181 
182  // fprintf(fp, "\nGlobal STDP Info: \n");
183  // fprintf(fp, "------------\n");
184  // fprintf(fp, " alpha_ltp: %f\n tau_ltp: %f\n alpha_ldp: %f\n tau_ldp: %f\n", ALPHA_LTP, TAU_LTP, ALPHA_LTD, TAU_LTD);
185 
186  fprintf(fp, "\nConnections: \n");
187  fprintf(fp, "------------\n");
188  while(newInfo) {
189  bool synWtType = GET_FIXED_PLASTIC(newInfo->connProp);
190  fprintf(fp, " // (%s => %s): numPostSynapses=%d, numPreSynapses=%d, iWt=%3.3f, mWt=%3.3f, ty=%x, maxD=%d, minD=%d %s\n",
191  grp_Info2[newInfo->grpSrc].Name.c_str(), grp_Info2[newInfo->grpDest].Name.c_str(),
192  newInfo->numPostSynapses, newInfo->numPreSynapses, newInfo->initWt, newInfo->maxWt,
193  newInfo->connProp, newInfo->maxDelay, newInfo->minDelay, (synWtType == SYN_PLASTIC)?"(*)":"");
194 
195  // weights of input spike generating layers need not be observed...
196  // bool synWtType = GET_FIXED_PLASTIC(newInfo->connProp);
197  // if ((synWtType == SYN_PLASTIC) && (enableSimLogs))
198  // storeWeights(newInfo->grpDest, newInfo->grpSrc, "logs");
199  newInfo = newInfo->next;
200  }
201 
202  fflush(fp);
203 }
204 
205 void CpuSNN::printParameters(FILE* fp)
206 {
207 #ifdef USE_EXCEPTIONS
208  if(fp == NULL)
209  throw std::runtime_error("print parmaters file was not specified.\n");
210 #else
211  assert(fp!=NULL);
212 #endif
213 
214  printGroupInfo(fp);
215  printConnectionInfo(fp);
216 }
217 
218 void CpuSNN::printGroupInfo(string& strName)
219 {
220  fprintf(stderr, "String Name : %s\n", strName.c_str());
221  for(int g=0; g < numGrp; g++) {
222  if(grp_Info[g].Type&POISSON_NEURON)
223  fprintf(stderr, "Poisson Group %d: %s\n", g, grp_Info2[g].Name.c_str());
224  }
225 }
226 
227 // print all post-connections...
229 {
230  if(fp) fprintf(fp, "PRINTING POST-SYNAPTIC CONNECTION TOPOLOGY\n");
231  if(fp) fprintf(fp, "(((((((((((((((((((((())))))))))))))))))))))\n");
232  for(int i=0; i < numGrp; i++)
233  printPostConnection(i,fp);
234 }
235 
236 // print all the pre-connections...
237 void CpuSNN::printPreConnection(FILE *fp)
238 {
239  if(fp) fprintf(fp, "PRINTING PRE-SYNAPTIC CONNECTION TOPOLOGY\n");
240  if(fp) fprintf(fp, "(((((((((((((((((((((())))))))))))))))))))))\n");
241  for(int i=0; i < numGrp; i++)
242  printPreConnection(i,fp);
243 }
244 
245 // print the connection info of grpId
246 int CpuSNN::printPostConnection2(int grpId, FILE* fpg)
247 {
248  int maxLength = -1;
249  for(int i=grp_Info[grpId].StartN; i<=grp_Info[grpId].EndN; i++) {
250  fprintf(fpg, " id %d : group %d : postlength %d ", i, findGrpId(i), Npost[i]);
251  // fetch the starting position
252  post_info_t* postIds = &postSynapticIds[cumulativePost[i]];
253  for(int j=0; j <= D; j++) {
254  int len = postDelayInfo[i*(D+1)+j].delay_length;
255  int start = postDelayInfo[i*(D+1)+j].delay_index_start;
256  for(int k=start; k < len; k++) {
257  int post_nid = GET_CONN_NEURON_ID((*postIds));
258  // int post_gid = GET_CONN_GRP_ID((*postIds));
259  fprintf(fpg, " : %d,%d ", post_nid, j);
260  postIds++;
261  }
262  if (Npost[i] > maxLength)
263  maxLength = Npost[i];
264  if ((start+len) >= Npost[i])
265  break;
266  }
267  fprintf(fpg, "\n");
268  }
269  fflush(fpg);
270  return maxLength;
271 }
272 
273 void CpuSNN::printNetworkInfo()
274 {
275  int maxLengthPost = -1;
276  int maxLengthPre = -1;
277  FILE *fpg = fopen("net_info.txt", "w");
278  printGroupInfo2(fpg);
279  printConnectionInfo2(fpg);
280  fprintf(fpg, "#Flat Network Info Format \n");
281  fprintf(fpg, "#(neuron id : length (number of connections) : neuron_id0,delay0 : neuron_id1,delay1 : ... \n");
282  for(int g=0; g < numGrp; g++) {
283  int postM = printPostConnection2(g, fpg);
284  int numPreSynapses = printPreConnection2(g, fpg);
285  if (postM > maxLengthPost)
286  maxLengthPost = postM;
287  if (numPreSynapses > maxLengthPre)
288  maxLengthPre = numPreSynapses;
289  }
290  fflush(fpg);
291  fclose(fpg);
292  fprintf(stdout, "Max post-synaptic length = %d\n", maxLengthPost);
293  fprintf(stdout, "Max pre-synaptic length = %d\n", maxLengthPre);
294 }
295 
296 void CpuSNN::printFiringRate(char *fname)
297 {
298  static int printCnt = 0;
299  FILE *fpg;
300  string strFname;
301  if (fname == NULL)
302  strFname = networkName;
303  else
304  strFname = fname;
305 
306  strFname += ".stat";
307  if(printCnt==0)
308  fpg = fopen(strFname.c_str(), "w");
309  else
310  fpg = fopen(strFname.c_str(), "a");
311 
312  fprintf(fpg, "#Average Firing Rate\n");
313  if(printCnt==0) {
314  fprintf(fpg, "#network %s: size = %d\n", networkName.c_str(), numN);
315  for(int grpId=0; grpId < numGrp; grpId++) {
316  fprintf(fpg, "#group %d: name %s : size = %d\n", grpId, grp_Info2[grpId].Name.c_str(), grp_Info[grpId].SizeN);
317  }
318  }
319  fprintf(fpg, "Time %d ms\n", simTime);
320  fprintf(fpg, "#activeNeurons ( <= 1.0) = fraction of neuron in the given group that are firing more than 1Hz\n");
321  fprintf(fpg, "#avgFiring (in Hz) = Average firing rate of activeNeurons in given group\n");
322  for(int grpId=0; grpId < numGrp; grpId++) {
323  fprintf(fpg, "group %d : \t", grpId);
324  int totSpike = 0;
325  int activeCnt = 0;
326  for(int i=grp_Info[grpId].StartN; i<=grp_Info[grpId].EndN; i++) {
327  if (nSpikeCnt[i] >= 1.0) {
328  totSpike += nSpikeCnt[i];
329  activeCnt++;
330  }
331  }
332  fprintf(fpg, " activeNeurons = %3.3f : avgFiring = %3.3f \n", activeCnt*1.0/grp_Info[grpId].SizeN, (activeCnt==0)?0.0:totSpike*1.0/activeCnt);
333  }
334  printCnt++;
335  fflush(fpg);
336  fclose(fpg);
337 }
338 
339 // print the connection info of grpId
340 void CpuSNN::printPostConnection(int grpId, FILE* fp)
341 {
342  for(int i=grp_Info[grpId].StartN; i<=grp_Info[grpId].EndN; i++) {
343  if(fp) fprintf(fp, " %3d ( %3d ) : \t", i, Npost[i]);
344  // fetch the starting position
345  post_info_t* postIds = &postSynapticIds[cumulativePost[i]];
346  int offset = cumulativePost[i];
347  for(int j=0; j < Npost[i]; j++, postIds++) {
348  int post_nid = GET_CONN_NEURON_ID((*postIds));
349  int post_gid = GET_CONN_GRP_ID((*postIds));
350 
351 #ifdef USE_EXCEPTIONS
352  if(findGrpId(post_nid) != post_gid)
353  throw std::runtime_error("findGrpId(post_nid) != post_gid.\n");
354 #else
355  assert( findGrpId(post_nid) == post_gid);
356 #endif
357 
358  if(fp) fprintf(fp, " %3d ( D=%3d, Grp=%3d) ", post_nid, tmp_SynapticDelay[offset+j], post_gid);
359  }
360  if(fp) fprintf(fp, "\n");
361  if(fp) fprintf(fp, " Delay ( %3d ) : ", i);
362  for(int j=0; j < D; j++) {
363  if(fp) fprintf(fp, " %d,%d ", postDelayInfo[i*(D+1)+j].delay_length,
364  postDelayInfo[i*(D+1)+j].delay_index_start);
365  }
366  if(fp) fprintf(fp, "\n");
367  }
368 }
369 
370 int CpuSNN::printPreConnection2(int grpId, FILE* fpg)
371 {
372  int maxLength = -1;
373  for(int i=grp_Info[grpId].StartN; i<=grp_Info[grpId].EndN; i++) {
374  fprintf(fpg, " id %d : group %d : prelength %d ", i, findGrpId(i), Npre[i]);
375  post_info_t* preIds = &preSynapticIds[cumulativePre[i]];
376  for(int j=0; j < Npre[i]; j++, preIds++) {
377  if (doneReorganization && (!memoryOptimized))
378  fprintf(fpg, ": %d,%s", GET_CONN_NEURON_ID((*preIds)), (j < Npre_plastic[i])?"P":"F");
379  }
380  if ( Npre[i] > maxLength)
381  maxLength = Npre[i];
382  fprintf(fpg, "\n");
383  }
384  return maxLength;
385 }
386 
387 void CpuSNN::printPreConnection(int grpId, FILE* fp)
388 {
389  for(int i=grp_Info[grpId].StartN; i<=grp_Info[grpId].EndN; i++) {
390  if(fp) fprintf(fp, " %d ( preCnt=%d, prePlastic=%d ) : (id => (wt, maxWt),(preId, P/F)\n\t", i, Npre[i], Npre_plastic[i]);
391  post_info_t* preIds = &preSynapticIds[cumulativePre[i]];
392  int pos_i = cumulativePre[i];
393  for(int j=0; j < Npre[i]; j++, pos_i++, preIds++) {
394  if(fp) fprintf(fp, " %d => (%f, %f)", j, wt[pos_i], maxSynWt[pos_i]);
395  if(doneReorganization && (!memoryOptimized))
396  if(fp) fprintf(fp, ",(%d, %s)",
397  GET_CONN_NEURON_ID((*preIds)),
398  (j < Npre_plastic[i])?"P":"F");
399  }
400  if(fp) fprintf(fp, "\n");
401  }
402 }
403 
404 /* deprecated
405  void CpuSNN::storeWeights(int destGrp, int src_grp, const string& logname, int restoreTime )
406  {
407  if(!enableSimLogs)
408  return;
409 
410  checkNetworkBuilt();
411 
412  // if restoreTime has some value then we restore the weight to that time, else dont restore (default -1)
413  bool restore = (restoreTime == -1) ? 0 : 1; // default false;
414  int retVal;
415 
416  for(int k=0, nid = grp_Info[destGrp].StartN; nid <= grp_Info[destGrp].EndN; nid++,k++)
417  {
418  char fname[200];
419  char dirname[200];
420 
421  if(restore)
422  sprintf(dirname, "%s", logname.c_str());
423  else {
424  sprintf(dirname, "%s/%d", logname.c_str(), randSeed);
425 
426  sprintf(fname, "mkdir -p %s", dirname );
427  retVal = system(fname);
428  if(retVal == -1) {
429  fprintf(stderr, "system command(%s) failed !!\n", fname);
430  return;
431  }
432 
433  sprintf(fname, "cp -f param.txt %s", dirname );
434  retVal = system(fname);
435  if(retVal == -1) {
436  fprintf(stderr, "system command(%s) failed !!\n", fname);
437  return;
438  }
439  }
440 
441  if(restore) {
442  sprintf(fname, "%s/weightsSrc%dDest%d_%d.m", dirname, src_grp, nid, restoreTime);
443  fprintf( stderr, "Restoring simulation status using %s (weights from grp=%d to nid=%d\n", fname, src_grp, nid);
444  }
445  else {
446  sprintf(fname, "%s/weightsSrc%dDest%d_%lld.m", dirname, src_grp, nid, (unsigned long long)simTimeSec);
447  fprintf( stderr, "Saving simulation status using %s (weights from grp=%d to nid=%d\n", fname, src_grp, nid);
448  }
449 
450  FILE *fp;
451 
452  if(restore)
453  fp= fopen(fname, "r");
454  else
455  fp= fopen(fname, "a");
456 
457  if(fp==NULL) {
458  fprintf(stderr, "Unable to open/create log file => %s\n", fname);
459  return;
460  }
461 
462  int dest_grp = findGrpId(nid);
463  post_info_t* preIds = &preSynapticIds[cumulativePre[nid]];
464  float* synWts = &wt[cumulativePre[nid]];
465 
466  assert(grpConnInfo[src_grp][dest_grp] != NULL);
467  assert(synWts != NULL);
468 
469  // find a suitable match for each pre-syn id that we are interested in ..
470  float maxWt = grpConnInfo[src_grp][dest_grp]->maxWt;
471 
472  int preNum = 0;
473  if(restore) {
474  retVal = fscanf(fp, "%d ", &preNum);
475  assert(retVal > 0);
476  assert(preNum == Npre[nid]);
477  }
478  else
479  fprintf(fp, "%d ", Npre[nid]);
480 
481  for(int i=0; i < Npre[nid]; i++, preIds++, synWts++) {
482  //int preId = (*preIds) & POST_SYN_NEURON_MASK;
483  int preId = GET_CONN_NEURON_ID((*preIds));
484  assert(preId < (numN));
485  // preId matches the src_grp that we are interested..
486  if( src_grp == findGrpId(preId)) {
487  if (restore) {
488  retVal = fscanf(fp, " %f ", synWts);
489  assert(retVal > 0);
490  *synWts = maxWt*(*synWts);
491  //fprintf(stderr, " %f", *synWts);
492  }
493  else
494  fprintf(fp, " %f ", *synWts/maxWt);
495  }
496  }
497 
498  if (restore) {
499  fprintf(fp, "\n");
500  }
501  else
502  fprintf(stderr, "\n");
503  fclose(fp);
504  }
505  }
506 */
507 void CpuSNN::printNeuronState(int grpId, FILE*fp)
508 {
509  if (currentMode==GPU_MODE) {
510  copyNeuronState(&cpuNetPtrs, &cpu_gpuNetPtrs, cudaMemcpyDeviceToHost, false, grpId);
511  }
512 
513  fprintf(fp, "[MODE=%s] ", (currentMode==GPU_MODE)?"GPU_MODE":"CPU_MODE");
514  fprintf(fp, "Group %s (%d) Neuron State Information (totSpike=%d, poissSpike=%d)\n",
515  grp_Info2[grpId].Name.c_str(), grpId, spikeCountAll, nPoissonSpikes);
516 
517  // poisson group does not have default neuron state
518  if(grp_Info[grpId].Type&POISSON_NEURON) {
519  fprintf(fp, "t=%d msec ", simTime);
520  int totSpikes = 0;
521  for (int nid=grp_Info[grpId].StartN; nid <= grp_Info[grpId].EndN; nid++) {
522  totSpikes += cpuNetPtrs.nSpikeCnt[nid];
523  fprintf(fp, "%d ", cpuNetPtrs.nSpikeCnt[nid]);
524  }
525  fprintf(fp, "\n");
526  fprintf(fp, "TotalSpikes [grp=%d, %s]= %d\n", grpId, grp_Info2[grpId].Name.c_str(), totSpikes);
527  return;
528  }
529 
530  int totSpikes = 0;
531  for (int nid=grp_Info[grpId].StartN; nid <= grp_Info[grpId].EndN; nid++) {
532  // copy the neuron firing information from the GPU to the CPU...
533  totSpikes += cpuNetPtrs.nSpikeCnt[nid];
534  if(!sim_with_conductances) {
535  if(cpuNetPtrs.current[nid] != 0.0)
536  fprintf(fp, "t=%d id=%d v=%+3.3f u=%+3.3f I=%+3.3f nSpikes=%d\n", simTime, nid,
537  cpuNetPtrs.voltage[nid], cpuNetPtrs.recovery[nid], cpuNetPtrs.current[nid],
538  cpuNetPtrs.nSpikeCnt[nid]);
539  }
540  else {
541  if (cpuNetPtrs.gAMPA[nid]+ cpuNetPtrs.gNMDA[nid]+cpuNetPtrs.gGABAa[nid]+cpuNetPtrs.gGABAb[nid] != 0.0)
542  fprintf(fp, "t=%d id=%d v=%+3.3f u=%+3.3f I=%+3.3f gAMPA=%2.5f gNMDA=%2.5f gGABAa=%2.5f gGABAb=%2.5f nSpikes=%d\n", simTime, nid,
543  cpuNetPtrs.voltage[nid], cpuNetPtrs.recovery[nid], cpuNetPtrs.current[nid], cpuNetPtrs.gAMPA[nid],
544  cpuNetPtrs.gNMDA[nid], cpuNetPtrs.gGABAa[nid], cpuNetPtrs.gGABAb[nid], cpuNetPtrs.nSpikeCnt[nid]);
545  }
546  }
547  fprintf(fp, "TotalSpikes [grp=%d, %s] = %d\n", grpId, grp_Info2[grpId].Name.c_str(), totSpikes);
548  fprintf(fp, "\n");
549  fflush(fp);
550 }
unsigned int * nSpikeCnt
homeostatic plasticity variables
Definition: snn.h:413
void printMemoryInfo(FILE *fp=stdout)
prints memory info to file
Definition: mtrand.h:97
void printPostConnection(FILE *fp=stdout)
print all the connections...
connection infos...
Definition: snn.h:517