54 #if defined(WIN32) || defined(WIN64) || defined(__APPLE__)
55 void SNN::spikeGeneratorUpdate_CPU(
int netId) {
57 void* SNN::spikeGeneratorUpdate_CPU(
int netId) {
59 assert(runtimeData[netId].allocated);
60 assert(runtimeData[netId].memType ==
CPU_MEM);
64 for (
int poisN = 0; poisN < networkConfigs[netId].
numNPois; poisN++) {
66 runtimeData[netId].
randNum[poisN] = drand48();
70 if (networkConfigs[netId].numNSpikeGen > 0) {
74 memset(managerRuntimeData.
spikeGenBits, 0,
sizeof(
int) * (networkConfigs[netId].numNSpikeGen / 32 + 1));
77 fillSpikeGenBits(netId);
80 memcpy(runtimeData[netId].spikeGenBits, managerRuntimeData.
spikeGenBits,
sizeof(
int) * (networkConfigs[netId].numNSpikeGen / 32 + 1));
84 #if !defined(WIN32) && !defined(WIN64) && !defined(__APPLE__) // Linux or MAC
86 void* SNN::helperSpikeGeneratorUpdate_CPU(
void* arguments) {
94 #if defined(WIN32) || defined(WIN64) || defined(__APPLE__)
95 void SNN::updateTimingTable_CPU(
int netId) {
97 void* SNN::updateTimingTable_CPU(
int netId) {
99 assert(runtimeData[netId].memType ==
CPU_MEM);
105 #if !defined(WIN32) && !defined(WIN64) && !defined(__APPLE__) // Linux or MAC
107 void* SNN::helperUpdateTimingTable_CPU(
void* arguments) {
230 #if defined(WIN32) || defined(WIN64) || defined(__APPLE__)
231 void SNN::convertExtSpikesD2_CPU(
int netId,
int startIdx,
int endIdx,
int GtoLOffset) {
233 void* SNN::convertExtSpikesD2_CPU(
int netId,
int startIdx,
int endIdx,
int GtoLOffset) {
235 int spikeCountExtRx = endIdx - startIdx;
243 for (
int extIdx = startIdx; extIdx < endIdx; extIdx++)
244 runtimeData[netId].firingTableD2[extIdx] += GtoLOffset;
247 #if !defined(WIN32) && !defined(WIN64) && !defined(__APPLE__) // Linux or MAC
249 void* SNN::helperConvertExtSpikesD2_CPU(
void* arguments) {
257 #if defined(WIN32) || defined(WIN64) || defined(__APPLE__)
258 void SNN::convertExtSpikesD1_CPU(
int netId,
int startIdx,
int endIdx,
int GtoLOffset) {
260 void* SNN::convertExtSpikesD1_CPU(
int netId,
int startIdx,
int endIdx,
int GtoLOffset) {
262 int spikeCountExtRx = endIdx - startIdx;
269 for (
int extIdx = startIdx; extIdx < endIdx; extIdx++)
270 runtimeData[netId].firingTableD1[extIdx] += GtoLOffset;
273 #if !defined(WIN32) && !defined(WIN64) && !defined(__APPLE__) // Linux or MAC
275 void* SNN::helperConvertExtSpikesD1_CPU(
void* arguments) {
283 #if defined(WIN32) || defined(WIN64) || defined(__APPLE__)
284 void SNN::clearExtFiringTable_CPU(
int netId) {
286 void* SNN::clearExtFiringTable_CPU(
int netId) {
288 assert(runtimeData[netId].memType ==
CPU_MEM);
290 memset(runtimeData[netId].extFiringTableEndIdxD1, 0,
sizeof(
int) * networkConfigs[netId].numGroups);
291 memset(runtimeData[netId].extFiringTableEndIdxD2, 0,
sizeof(
int) * networkConfigs[netId].numGroups);
294 #if !defined(WIN32) && !defined(WIN64) && !defined(__APPLE__) // Linux or MAC
296 void* SNN::helperClearExtFiringTable_CPU(
void* arguments) {
304 void SNN::copyTimeTable(
int netId,
bool toManager) {
308 memcpy(managerRuntimeData.
timeTableD2, runtimeData[netId].timeTableD2,
sizeof(
int) * (1000 + glbNetworkConfig.
maxDelay + 1));
309 memcpy(managerRuntimeData.
timeTableD1, runtimeData[netId].timeTableD1,
sizeof(
int) * (1000 + glbNetworkConfig.
maxDelay + 1));
311 memcpy(runtimeData[netId].timeTableD2, managerRuntimeData.
timeTableD2,
sizeof(
int)*(1000 + glbNetworkConfig.
maxDelay + 1));
312 memcpy(runtimeData[netId].timeTableD1, managerRuntimeData.
timeTableD1,
sizeof(
int)*(1000 + glbNetworkConfig.
maxDelay + 1));
316 void SNN::copyExtFiringTable(
int netId) {
319 memcpy(managerRuntimeData.
extFiringTableEndIdxD2, runtimeData[netId].extFiringTableEndIdxD2,
sizeof(
int) * networkConfigs[netId].numGroups);
320 memcpy(managerRuntimeData.
extFiringTableEndIdxD1, runtimeData[netId].extFiringTableEndIdxD1,
sizeof(
int) * networkConfigs[netId].numGroups);
321 memcpy(managerRuntimeData.
extFiringTableD2, runtimeData[netId].extFiringTableD2,
sizeof(
int*) * networkConfigs[netId].numGroups);
322 memcpy(managerRuntimeData.
extFiringTableD1, runtimeData[netId].extFiringTableD1,
sizeof(
int*) * networkConfigs[netId].numGroups);
330 #if defined(WIN32) || defined(WIN64) || defined(__APPLE__)
331 void SNN::resetSpikeCnt_CPU(
int netId,
int lGrpId) {
333 void* SNN::resetSpikeCnt_CPU(
int netId,
int lGrpId) {
335 assert(runtimeData[netId].memType ==
CPU_MEM);
338 memset(runtimeData[netId].nSpikeCnt, 0,
sizeof(
int) * networkConfigs[netId].numN);
340 int lStartN = groupConfigs[netId][lGrpId].
lStartN;
341 int numN = groupConfigs[netId][lGrpId].
numN;
342 memset(runtimeData[netId].nSpikeCnt + lStartN, 0,
sizeof(
int) * numN);
346 #if !defined(WIN32) && !defined(WIN64) && !defined(__APPLE__) // Linux or MAC
348 void* SNN::helperResetSpikeCnt_CPU(
void* arguments) {
358 #if defined(WIN32) || defined(WIN64) || defined(__APPLE__)
359 void SNN::doCurrentUpdateD1_CPU(
int netId) {
361 void* SNN::doCurrentUpdateD1_CPU(
int netId) {
363 assert(runtimeData[netId].memType ==
CPU_MEM);
365 int k = runtimeData[netId].
timeTableD1[simTimeMs + networkConfigs[netId].
maxDelay + 1] - 1;
366 int k_end = runtimeData[netId].
timeTableD1[simTimeMs + networkConfigs[netId].maxDelay];
368 while((k >= k_end) && (k >= 0)) {
381 assert(postNId < networkConfigs[netId].numNAssigned);
384 assert(synId < (runtimeData[netId].Npre[postNId]));
386 if (postNId < networkConfigs[netId].numN)
387 generatePostSynapticSpike(lNId , postNId, synId, 0, netId);
394 #if !defined(WIN32) && !defined(WIN64) && !defined(__APPLE__) // Linux or MAC
396 void* SNN::helperDoCurrentUpdateD1_CPU(
void* arguments) {
406 #if defined(WIN32) || defined(WIN64) || defined(__APPLE__)
407 void SNN::doCurrentUpdateD2_CPU(
int netId) {
409 void* SNN::doCurrentUpdateD2_CPU(
int netId) {
411 assert(runtimeData[netId].memType ==
CPU_MEM);
413 if (networkConfigs[netId].maxDelay > 1) {
414 int k = runtimeData[netId].
timeTableD2[simTimeMs + 1 + networkConfigs[netId].maxDelay] - 1;
415 int k_end = runtimeData[netId].
timeTableD2[simTimeMs + 1];
416 int t_pos = simTimeMs;
418 while ((k >= k_end) && (k >= 0)) {
423 while (!((k >= runtimeData[netId].timeTableD2[t_pos + networkConfigs[netId].maxDelay]) && (k < runtimeData[netId].timeTableD2[t_pos + networkConfigs[netId].maxDelay + 1]))) {
425 assert((t_pos + networkConfigs[netId].maxDelay - 1) >= 0);
430 int tD = simTimeMs - t_pos;
432 assert((tD < networkConfigs[netId].maxDelay) && (tD >= 0));
445 assert(postNId < networkConfigs[netId].numNAssigned);
448 assert(synId < (runtimeData[netId].Npre[postNId]));
450 if (postNId < networkConfigs[netId].numN)
451 generatePostSynapticSpike(lNId , postNId, synId, tD, netId);
459 #if !defined(WIN32) && !defined(WIN64) && !defined(__APPLE__) // Linux or MAC
461 void* SNN::helperDoCurrentUpdateD2_CPU(
void* arguments) {
469 #if defined(WIN32) || defined(WIN64) || defined(__APPLE__)
470 void SNN::doSTPUpdateAndDecayCond_CPU(
int netId) {
472 void* SNN::doSTPUpdateAndDecayCond_CPU(
int netId) {
474 assert(runtimeData[netId].memType ==
CPU_MEM);
477 for (
int lGrpId = 0; lGrpId < networkConfigs[netId].numGroups; lGrpId++) {
478 for(
int lNId = groupConfigs[netId][lGrpId].lStartN; lNId <= groupConfigs[netId][lGrpId].
lEndN; lNId++) {
479 if (groupConfigs[netId][lGrpId].WithSTP) {
482 runtimeData[netId].
stpu[ind_plus] = runtimeData[netId].
stpu[ind_minus] * (1.0f - groupConfigs[netId][lGrpId].
STP_tau_u_inv);
483 runtimeData[netId].
stpx[ind_plus] = runtimeData[netId].
stpx[ind_minus] + (1.0f - runtimeData[netId].
stpx[ind_minus]) * groupConfigs[netId][lGrpId].STP_tau_x_inv;
487 if (networkConfigs[netId].sim_with_conductances &&
IS_REGULAR_NEURON(lNId, networkConfigs[netId].numNReg, networkConfigs[netId].numNPois)) {
488 runtimeData[netId].
gAMPA[lNId] *= dAMPA;
489 if (sim_with_NMDA_rise) {
490 runtimeData[netId].
gNMDA_r[lNId] *= rNMDA;
491 runtimeData[netId].
gNMDA_d[lNId] *= dNMDA;
493 runtimeData[netId].
gNMDA[lNId] *= dNMDA;
496 runtimeData[netId].
gGABAa[lNId] *= dGABAa;
497 if (sim_with_GABAb_rise) {
498 runtimeData[netId].
gGABAb_r[lNId] *= rGABAb;
499 runtimeData[netId].
gGABAb_d[lNId] *= dGABAb;
501 runtimeData[netId].
gGABAb[lNId] *= dGABAb;
508 #if !defined(WIN32) && !defined(WIN64) && !defined(__APPLE__) // Linux or MAC
510 void* SNN::helperDoSTPUpdateAndDecayCond_CPU(
void* arguments) {
518 #if defined(WIN32) || defined(WIN64) || defined(__APPLE__)
519 void SNN::findFiring_CPU(
int netId) {
521 void* SNN::findFiring_CPU(
int netId) {
523 assert(runtimeData[netId].memType ==
CPU_MEM);
525 for(
int lGrpId = 0; lGrpId < networkConfigs[netId].numGroups; lGrpId++) {
526 for (
int lNId = groupConfigs[netId][lGrpId].lStartN; lNId <= groupConfigs[netId][lGrpId].
lEndN; lNId++) {
527 bool needToWrite =
false;
530 if(groupConfigs[netId][lGrpId].isSpikeGenFunc) {
531 unsigned int offset = lNId - groupConfigs[netId][lGrpId].
lStartN + groupConfigs[netId][lGrpId].
Noffset;
532 needToWrite = getSpikeGenBit(offset, netId);
534 needToWrite = getPoissonSpike(lNId, netId);
540 if (runtimeData[netId].curSpike[lNId]) {
541 runtimeData[netId].
curSpike[lNId] =
false;
546 if (networkConfigs[netId].sim_with_nm && lNId - groupConfigs[netId][lGrpId].lStartN <
MAX_NEURON_MON_GRP_SZIE) {
548 runtimeData[netId].
nVBuffer[idxBase + lNId - groupConfigs[netId][lGrpId].
lStartN] = runtimeData[netId].
voltage[lNId];
549 runtimeData[netId].
nUBuffer[idxBase + lNId - groupConfigs[netId][lGrpId].lStartN] = runtimeData[netId].
recovery[lNId];
556 bool hasSpace =
false;
560 if (groupConfigs[netId][lGrpId].MaxDelay == 1)
562 if (runtimeData[netId].spikeCountD1Sec + 1 < networkConfigs[netId].maxSpikesD1) {
567 if (runtimeData[netId].spikeCountD2Sec + runtimeData[netId].spikeCountLastSecLeftD2 + 1 < networkConfigs[netId].maxSpikesD2) {
577 if (groupConfigs[netId][lGrpId].MaxDelay == 1) {
584 if (groupConfigs[netId][lGrpId].hasExternalConnect) {
586 if (groupConfigs[netId][lGrpId].MaxDelay == 1) {
593 assert(extFireId != -1);
597 if (groupConfigs[netId][lGrpId].WithSTP) {
598 firingUpdateSTP(lNId, lGrpId, netId);
604 if (
IS_REGULAR_NEURON(lNId, networkConfigs[netId].numNReg, networkConfigs[netId].numNPois))
605 resetFiredNeuron(lNId, lGrpId, netId);
608 if (!sim_in_testing && groupConfigs[netId][lGrpId].WithSTDP) {
609 updateLTP(lNId, lGrpId, netId);
616 #if !defined(WIN32) && !defined(WIN64) && !defined(__APPLE__) // Linux or MAC
618 void* SNN::helperFindFiring_CPU(
void* arguments) {
627 void SNN::updateLTP(
int lNId,
int lGrpId,
int netId) {
628 unsigned int pos_ij = runtimeData[netId].
cumulativePre[lNId];
629 for(
int j = 0; j < runtimeData[netId].
Npre_plastic[lNId]; pos_ij++, j++) {
630 int stdp_tDiff = (simTime - runtimeData[netId].
synSpikeTime[pos_ij]);
631 assert(!((stdp_tDiff < 0) && (runtimeData[netId].synSpikeTime[pos_ij] !=
MAX_SIMULATION_TIME)));
633 if (stdp_tDiff > 0) {
635 if (groupConfigs[netId][lGrpId].WithESTDP && runtimeData[netId].maxSynWt[pos_ij] >= 0) {
637 switch (groupConfigs[netId][lGrpId].WithESTDPcurve) {
639 if (stdp_tDiff * groupConfigs[netId][lGrpId].TAU_PLUS_INV_EXC < 25)
640 runtimeData[netId].
wtChange[pos_ij] +=
STDP(stdp_tDiff, groupConfigs[netId][lGrpId].ALPHA_PLUS_EXC, groupConfigs[netId][lGrpId].TAU_PLUS_INV_EXC);
643 if (stdp_tDiff * groupConfigs[netId][lGrpId].TAU_PLUS_INV_EXC < 25) {
644 if (stdp_tDiff <= groupConfigs[netId][lGrpId].GAMMA)
645 runtimeData[netId].
wtChange[pos_ij] += groupConfigs[netId][lGrpId].
OMEGA + groupConfigs[netId][lGrpId].
KAPPA *
STDP(stdp_tDiff, groupConfigs[netId][lGrpId].ALPHA_PLUS_EXC, groupConfigs[netId][lGrpId].TAU_PLUS_INV_EXC);
647 runtimeData[netId].
wtChange[pos_ij] -=
STDP(stdp_tDiff, groupConfigs[netId][lGrpId].ALPHA_PLUS_EXC, groupConfigs[netId][lGrpId].TAU_PLUS_INV_EXC);
654 }
else if (groupConfigs[netId][lGrpId].WithISTDP && runtimeData[netId].maxSynWt[pos_ij] < 0) {
656 switch (groupConfigs[netId][lGrpId].WithISTDPcurve) {
658 if (stdp_tDiff * groupConfigs[netId][lGrpId].TAU_PLUS_INV_INB < 25) {
659 runtimeData[netId].
wtChange[pos_ij] -=
STDP(stdp_tDiff, groupConfigs[netId][lGrpId].ALPHA_PLUS_INB, groupConfigs[netId][lGrpId].TAU_PLUS_INV_INB);
663 if (stdp_tDiff <= groupConfigs[netId][lGrpId].LAMBDA) {
664 runtimeData[netId].
wtChange[pos_ij] -= groupConfigs[netId][lGrpId].
BETA_LTP;
666 }
else if (stdp_tDiff <= groupConfigs[netId][lGrpId].DELTA) {
667 runtimeData[netId].
wtChange[pos_ij] -= groupConfigs[netId][lGrpId].
BETA_LTD;
680 void SNN::firingUpdateSTP(
int lNId,
int lGrpId,
int netId) {
683 int ind_plus =
STP_BUF_POS(lNId, simTime, networkConfigs[netId].maxDelay);
684 int ind_minus =
STP_BUF_POS(lNId, (simTime - 1), networkConfigs[netId].maxDelay);
687 runtimeData[netId].
stpu[ind_plus] += groupConfigs[netId][lGrpId].
STP_U * (1.0f - runtimeData[netId].
stpu[ind_minus]);
690 runtimeData[netId].
stpx[ind_plus] -= runtimeData[netId].
stpu[ind_plus] * runtimeData[netId].
stpx[ind_minus];
693 void SNN::resetFiredNeuron(
int lNId,
short int lGrpId,
int netId) {
694 if (groupConfigs[netId][lGrpId].WithSTDP)
697 if (networkConfigs[netId].sim_with_homeostasis) {
703 bool SNN::getPoissonSpike(
int lNId,
int netId) {
707 return runtimeData[netId].
randNum[lNId - networkConfigs[netId].numNReg] * 1000.0f
708 < runtimeData[netId].
poissonFireRate[lNId - networkConfigs[netId].numNReg];
711 bool SNN::getSpikeGenBit(
unsigned int nIdPos,
int netId) {
712 const int nIdBitPos = nIdPos % 32;
713 const int nIdIndex = nIdPos / 32;
714 return ((runtimeData[netId].spikeGenBits[nIdIndex] >> nIdBitPos) & 0x1);
730 void SNN::generatePostSynapticSpike(
int preNId,
int postNId,
int synId,
int tD,
int netId) {
732 unsigned int pos = runtimeData[netId].
cumulativePre[postNId] + synId;
733 assert(postNId < networkConfigs[netId].numNReg);
736 short int post_grpId = runtimeData[netId].
grpIds[postNId];
737 short int pre_grpId = runtimeData[netId].
grpIds[preNId];
739 unsigned int pre_type = groupConfigs[netId][pre_grpId].
Type;
746 assert(mulIndex >= 0 && mulIndex < numConnections);
751 float change = runtimeData[netId].
wt[pos];
754 if (groupConfigs[netId][pre_grpId].WithSTP) {
761 int ind_minus =
STP_BUF_POS(preNId, (simTime-tD-1), networkConfigs[netId].maxDelay);
762 int ind_plus =
STP_BUF_POS(preNId, (simTime-tD), networkConfigs[netId].maxDelay);
764 change *= groupConfigs[netId][pre_grpId].
STP_A * runtimeData[netId].
stpu[ind_plus] * runtimeData[netId].
stpx[ind_minus];
777 if (sim_with_conductances) {
779 runtimeData[netId].
gAMPA [postNId] += change * mulSynFast[mulIndex];
781 if (sim_with_NMDA_rise) {
782 runtimeData[netId].
gNMDA_r[postNId] += change * sNMDA * mulSynSlow[mulIndex];
783 runtimeData[netId].
gNMDA_d[postNId] += change * sNMDA * mulSynSlow[mulIndex];
785 runtimeData[netId].
gNMDA [postNId] += change * mulSynSlow[mulIndex];
789 runtimeData[netId].
gGABAa[postNId] -= change * mulSynFast[mulIndex];
791 if (sim_with_GABAb_rise) {
792 runtimeData[netId].
gGABAb_r[postNId] -= change * sGABAb * mulSynSlow[mulIndex];
793 runtimeData[netId].
gGABAb_d[postNId] -= change * sGABAb * mulSynSlow[mulIndex];
795 runtimeData[netId].
gGABAb[postNId] -= change * mulSynSlow[mulIndex];
799 runtimeData[netId].
current[postNId] += change;
808 runtimeData[netId].
grpDA[post_grpId] += 0.04;
813 if (!sim_in_testing && groupConfigs[netId][post_grpId].WithSTDP) {
814 int stdp_tDiff = (simTime - runtimeData[netId].
lastSpikeTime[postNId]);
816 if (stdp_tDiff >= 0) {
819 switch (groupConfigs[netId][post_grpId].WithISTDPcurve) {
821 if (stdp_tDiff * groupConfigs[netId][post_grpId].TAU_MINUS_INV_INB < 25) {
822 runtimeData[netId].
wtChange[pos] -=
STDP(stdp_tDiff, groupConfigs[netId][post_grpId].ALPHA_MINUS_INB, groupConfigs[netId][post_grpId].TAU_MINUS_INV_INB);
826 if (stdp_tDiff <= groupConfigs[netId][post_grpId].LAMBDA) {
827 runtimeData[netId].
wtChange[pos] -= groupConfigs[netId][post_grpId].
BETA_LTP;
828 }
else if (stdp_tDiff <= groupConfigs[netId][post_grpId].DELTA) {
829 runtimeData[netId].
wtChange[pos] -= groupConfigs[netId][post_grpId].
BETA_LTD;
836 }
else if (groupConfigs[netId][post_grpId].WithESTDP && ((pre_type &
TARGET_AMPA) || (pre_type &
TARGET_NMDA))) {
838 switch (groupConfigs[netId][post_grpId].WithESTDPcurve) {
841 if (stdp_tDiff * groupConfigs[netId][post_grpId].TAU_MINUS_INV_EXC < 25)
842 runtimeData[netId].
wtChange[pos] +=
STDP(stdp_tDiff, groupConfigs[netId][post_grpId].ALPHA_MINUS_EXC, groupConfigs[netId][post_grpId].TAU_MINUS_INV_EXC);
850 assert(!((stdp_tDiff < 0) && (runtimeData[netId].lastSpikeTime[postNId] !=
MAX_SIMULATION_TIME)));
856 float dvdtIzhikevich4(
float volt,
float recov,
float totalCurrent,
float timeStep = 1.0f) {
857 return (((0.04f * volt + 5.0f) * volt + 140.0f - recov + totalCurrent) * timeStep);
862 float dudtIzhikevich4(
float volt,
float recov,
float izhA,
float izhB,
float timeStep = 1.0f) {
863 return (izhA * (izhB * volt - recov) * timeStep);
868 float dvdtIzhikevich9(
float volt,
float recov,
float invCapac,
float izhK,
float voltRest,
869 float voltInst,
float totalCurrent,
float timeStep = 1.0f)
871 return ((izhK * (volt - voltRest) * (volt - voltInst) - recov + totalCurrent) * invCapac * timeStep);
876 float dudtIzhikevich9(
float volt,
float recov,
float voltRest,
float izhA,
float izhB,
float timeStep = 1.0f) {
877 return (izhA * (izhB * (volt - voltRest) - recov) * timeStep);
882 float dvdtLIF(
float volt,
float lif_vReset,
float lif_gain,
float lif_bias,
int lif_tau_m,
float totalCurrent,
float timeStep = 1.0f) {
883 return ((lif_vReset -volt + ((totalCurrent * lif_gain) + lif_bias))/ (
float) lif_tau_m) * timeStep;
886 float SNN::getCompCurrent(
int netid,
int lGrpId,
int lneurId,
float const0,
float const1) {
887 float compCurrent = 0.0f;
891 int lGrpIdOther = groupConfigs[netid][lGrpId].
compNeighbors[k];
892 int lneurIdOther = lneurId - groupConfigs[netid][lGrpId].
lStartN + groupConfigs[netid][lGrpIdOther].
lStartN;
893 compCurrent += groupConfigs[netid][lGrpId].
compCoupling[k] * ((runtimeData[netid].
voltage[lneurIdOther] + const1)
894 - (runtimeData[netid].voltage[lneurId] + const0));
900 #if defined(WIN32) || defined(WIN64) || defined(__APPLE__)
901 void SNN::globalStateUpdate_CPU(
int netId) {
903 void* SNN::globalStateUpdate_CPU(
int netId) {
905 assert(runtimeData[netId].memType ==
CPU_MEM);
907 float timeStep = networkConfigs[netId].timeStep;
910 for (
int j = 1; j <= networkConfigs[netId].simNumStepsPerMs; j++) {
911 bool lastIter = (j == networkConfigs[netId].simNumStepsPerMs);
912 for (
int lGrpId = 0; lGrpId < networkConfigs[netId].numGroups; lGrpId++) {
914 if (groupConfigs[netId][lGrpId].WithHomeostasis & (lastIter)) {
915 for (
int lNId = groupConfigs[netId][lGrpId].lStartN; lNId <= groupConfigs[netId][lGrpId].
lEndN; lNId++)
916 runtimeData[netId].avgFiring[lNId] *= groupConfigs[netId][lGrpId].avgTimeScale_decay;
921 for (
int lNId = groupConfigs[netId][lGrpId].lStartN; lNId <= groupConfigs[netId][lGrpId].
lEndN; lNId++) {
922 assert(lNId < networkConfigs[netId].numNReg);
926 float v = runtimeData[netId].
voltage[lNId];
927 float v_next = runtimeData[netId].
nextVoltage[lNId];
928 float u = runtimeData[netId].
recovery[lNId];
929 float I_sum, NMDAtmp;
933 float k = runtimeData[netId].
Izh_k[lNId];
934 float vr = runtimeData[netId].
Izh_vr[lNId];
935 float vt = runtimeData[netId].
Izh_vt[lNId];
936 float inverse_C = 1.0f / runtimeData[netId].
Izh_C[lNId];
937 float vpeak = runtimeData[netId].
Izh_vpeak[lNId];
938 float a = runtimeData[netId].
Izh_a[lNId];
939 float b = runtimeData[netId].
Izh_b[lNId];
942 int lif_tau_m = runtimeData[netId].
lif_tau_m[lNId];
943 int lif_tau_ref = runtimeData[netId].
lif_tau_ref[lNId];
945 float lif_vTh = runtimeData[netId].
lif_vTh[lNId];
946 float lif_vReset = runtimeData[netId].
lif_vReset[lNId];
947 float lif_gain = runtimeData[netId].
lif_gain[lNId];
948 float lif_bias = runtimeData[netId].
lif_bias[lNId];
950 float totalCurrent = runtimeData[netId].
extCurrent[lNId];
952 if (networkConfigs[netId].sim_with_conductances) {
953 NMDAtmp = (v + 80.0f) * (v + 80.0f) / 60.0f / 60.0f;
954 gNMDA = (networkConfigs[netId].sim_with_NMDA_rise) ? (runtimeData[netId].gNMDA_d[lNId] - runtimeData[netId].gNMDA_r[lNId]) : runtimeData[netId].
gNMDA[lNId];
955 gGABAb = (networkConfigs[netId].sim_with_GABAb_rise) ? (runtimeData[netId].gGABAb_d[lNId] - runtimeData[netId].gGABAb_r[lNId]) : runtimeData[netId].
gGABAb[lNId];
957 I_sum = -(runtimeData[netId].
gAMPA[lNId] * (v - 0.0f)
958 + gNMDA * NMDAtmp / (1.0f + NMDAtmp) * (v - 0.0f)
959 + runtimeData[netId].gGABAa[lNId] * (v + 70.0f)
960 + gGABAb * (v + 90.0f));
962 totalCurrent += I_sum;
965 totalCurrent += runtimeData[netId].
current[lNId];
967 if (groupConfigs[netId][lGrpId].withCompartments) {
968 totalCurrent += getCompCurrent(netId, lGrpId, lNId);
971 switch (networkConfigs[netId].simIntegrationMethod) {
973 if (!groupConfigs[netId][lGrpId].withParamModel_9 && !groupConfigs[netId][lGrpId].isLIF)
977 if (v_next > 30.0f) {
979 runtimeData[netId].
curSpike[lNId] =
true;
980 v_next = runtimeData[netId].
Izh_c[lNId];
981 u += runtimeData[netId].
Izh_d[lNId];
984 else if (!groupConfigs[netId][lGrpId].isLIF)
987 v_next = v +
dvdtIzhikevich9(v, u, inverse_C, k, vr, vt, totalCurrent, timeStep);
988 if (v_next > vpeak) {
990 runtimeData[netId].
curSpike[lNId] =
true;
991 v_next = runtimeData[netId].
Izh_c[lNId];
992 u += runtimeData[netId].
Izh_d[lNId];
997 if (lif_tau_ref_c > 0){
1000 v_next = lif_vReset;
1004 if (v_next > lif_vTh) {
1005 runtimeData[netId].
curSpike[lNId] =
true;
1006 v_next = lif_vReset;
1016 v_next = v +
dvdtLIF(v, lif_vReset, lif_gain, lif_bias, lif_tau_m, totalCurrent, timeStep);
1021 if (groupConfigs[netId][lGrpId].isLIF){
1022 if (v_next < lif_vReset) v_next = lif_vReset;
1025 if (v_next < -90.0f) v_next = -90.0f;
1027 if (!groupConfigs[netId][lGrpId].withParamModel_9)
1040 if (!groupConfigs[netId][lGrpId].withParamModel_9 && !groupConfigs[netId][lGrpId].isLIF) {
1045 float k2 =
dvdtIzhikevich4(v + k1 / 2.0f, u + l1 / 2.0f, totalCurrent,
1047 float l2 =
dudtIzhikevich4(v + k1 / 2.0f, u + l1 / 2.0f, a, b, timeStep);
1049 float k3 =
dvdtIzhikevich4(v + k2 / 2.0f, u + l2 / 2.0f, totalCurrent,
1051 float l3 =
dudtIzhikevich4(v + k2 / 2.0f, u + l2 / 2.0f, a, b, timeStep);
1055 v_next = v + (1.0f / 6.0f) * (k1 + 2.0f * k2 + 2.0f * k3 + k4);
1056 if (v_next > 30.0f) {
1058 runtimeData[netId].
curSpike[lNId] =
true;
1059 v_next = runtimeData[netId].
Izh_c[lNId];
1060 u += runtimeData[netId].
Izh_d[lNId];
1062 if (v_next < -90.0f) v_next = -90.0f;
1064 u += (1.0f / 6.0f) * (l1 + 2.0f * l2 + 2.0f * l3 + l4);
1066 else if(!groupConfigs[netId][lGrpId].isLIF){
1072 float k2 =
dvdtIzhikevich9(v + k1 / 2.0f, u + l1 / 2.0f, inverse_C, k, vr, vt,
1073 totalCurrent, timeStep);
1074 float l2 =
dudtIzhikevich9(v + k1 / 2.0f, u + l1 / 2.0f, vr, a, b, timeStep);
1076 float k3 =
dvdtIzhikevich9(v + k2 / 2.0f, u + l2 / 2.0f, inverse_C, k, vr, vt,
1077 totalCurrent, timeStep);
1078 float l3 =
dudtIzhikevich9(v + k2 / 2.0f, u + l2 / 2.0f, vr, a, b, timeStep);
1081 totalCurrent, timeStep);
1084 v_next = v + (1.0f / 6.0f) * (k1 + 2.0f * k2 + 2.0f * k3 + k4);
1086 if (v_next > vpeak) {
1088 runtimeData[netId].
curSpike[lNId] =
true;
1089 v_next = runtimeData[netId].
Izh_c[lNId];
1090 u += runtimeData[netId].
Izh_d[lNId];
1093 if (v_next < -90.0f) v_next = -90.0f;
1095 u += (1.0f / 6.0f) * (l1 + 2.0f * l2 + 2.0f * l3 + l4);
1099 if (lif_tau_ref_c > 0){
1102 v_next = lif_vReset;
1106 if (v_next > lif_vTh) {
1107 runtimeData[netId].
curSpike[lNId] =
true;
1108 v_next = lif_vReset;
1118 v_next = v +
dvdtLIF(v, lif_vReset, lif_gain, lif_bias, lif_tau_m, totalCurrent, timeStep);
1121 if (v_next < lif_vReset) v_next = lif_vReset;
1130 runtimeData[netId].
recovery[lNId] = u;
1135 if (networkConfigs[netId].sim_with_conductances) {
1136 runtimeData[netId].
current[lNId] = I_sum;
1140 runtimeData[netId].
current[lNId] = 0.0f;
1145 if (groupConfigs[netId][lGrpId].WithHomeostasis)
1149 if (networkConfigs[netId].sim_with_nm && lNId - groupConfigs[netId][lGrpId].lStartN <
MAX_NEURON_MON_GRP_SZIE) {
1151 runtimeData[netId].
nIBuffer[idxBase + lNId - groupConfigs[netId][lGrpId].
lStartN] = totalCurrent;
1161 if ((groupConfigs[netId][lGrpId].WithESTDPtype ==
DA_MOD || groupConfigs[netId][lGrpId].WithISTDP ==
DA_MOD) && runtimeData[netId].grpDA[lGrpId] > groupConfigs[netId][lGrpId].baseDP) {
1162 runtimeData[netId].
grpDA[lGrpId] *= groupConfigs[netId][lGrpId].
decayDP;
1164 runtimeData[netId].
grpDABuffer[lGrpId * 1000 + simTimeMs] = runtimeData[netId].
grpDA[lGrpId];
1171 memcpy(runtimeData[netId].voltage, runtimeData[netId].nextVoltage,
sizeof(
float)*networkConfigs[netId].numNReg);
1176 #if !defined(WIN32) && !defined(WIN64) && !defined(__APPLE__) // Linux or MAC
1178 void* SNN::helperGlobalStateUpdate_CPU(
void* arguments) {
1187 #if defined(WIN32) || defined(WIN64) || defined(__APPLE__)
1188 void SNN::updateWeights_CPU(
int netId) {
1190 void* SNN::updateWeights_CPU(
int netId) {
1193 assert(sim_in_testing==
false);
1194 assert(sim_with_fixedwts==
false);
1195 assert(runtimeData[netId].memType ==
CPU_MEM);
1198 for (
int lGrpId = 0; lGrpId < networkConfigs[netId].numGroups; lGrpId++) {
1200 if (groupConfigs[netId][lGrpId].FixedInputWts || !(groupConfigs[netId][lGrpId].WithSTDP))
1203 for (
int lNId = groupConfigs[netId][lGrpId].lStartN; lNId <= groupConfigs[netId][lGrpId].
lEndN; lNId++) {
1204 assert(lNId < networkConfigs[netId].numNReg);
1205 unsigned int offset = runtimeData[netId].
cumulativePre[lNId];
1206 float diff_firing = 0.0;
1207 float homeostasisScale = 1.0;
1209 if (groupConfigs[netId][lGrpId].WithHomeostasis) {
1210 assert(runtimeData[netId].baseFiring[lNId] > 0);
1211 diff_firing = 1 - runtimeData[netId].
avgFiring[lNId] / runtimeData[netId].
baseFiring[lNId];
1215 if (lNId == groupConfigs[netId][lGrpId].lStartN)
1216 KERNEL_DEBUG(
"Weights, Change at %d (diff_firing: %f)", simTimeSec, diff_firing);
1218 for (
int j = 0; j < runtimeData[netId].
Npre_plastic[lNId]; j++) {
1221 float effectiveWtChange = stdpScaleFactor_ * runtimeData[netId].
wtChange[offset + j];
1227 switch (groupConfigs[netId][lGrpId].WithESTDPtype) {
1229 if (groupConfigs[netId][lGrpId].WithHomeostasis) {
1230 runtimeData[netId].
wt[offset + j] += (diff_firing*runtimeData[netId].
wt[offset + j] * homeostasisScale + runtimeData[netId].
wtChange[offset + j])*runtimeData[netId].baseFiring[lNId] / groupConfigs[netId][lGrpId].avgTimeScale / (1 + fabs(diff_firing) * 50);
1233 runtimeData[netId].
wt[offset + j] += effectiveWtChange;
1237 if (groupConfigs[netId][lGrpId].WithHomeostasis) {
1238 effectiveWtChange = runtimeData[netId].
grpDA[lGrpId] * effectiveWtChange;
1239 runtimeData[netId].
wt[offset + j] += (diff_firing*runtimeData[netId].
wt[offset + j] * homeostasisScale + effectiveWtChange)*runtimeData[netId].baseFiring[lNId] / groupConfigs[netId][lGrpId].avgTimeScale / (1 + fabs(diff_firing) * 50);
1241 runtimeData[netId].
wt[offset + j] += runtimeData[netId].
grpDA[lGrpId] * effectiveWtChange;
1250 switch (groupConfigs[netId][lGrpId].WithISTDPtype) {
1252 if (groupConfigs[netId][lGrpId].WithHomeostasis) {
1253 runtimeData[netId].
wt[offset + j] += (diff_firing*runtimeData[netId].
wt[offset + j] * homeostasisScale + runtimeData[netId].
wtChange[offset + j])*runtimeData[netId].baseFiring[lNId] / groupConfigs[netId][lGrpId].avgTimeScale / (1 + fabs(diff_firing) * 50);
1256 runtimeData[netId].
wt[offset + j] += effectiveWtChange;
1260 if (groupConfigs[netId][lGrpId].WithHomeostasis) {
1261 effectiveWtChange = runtimeData[netId].
grpDA[lGrpId] * effectiveWtChange;
1262 runtimeData[netId].
wt[offset + j] += (diff_firing*runtimeData[netId].
wt[offset + j] * homeostasisScale + effectiveWtChange)*runtimeData[netId].baseFiring[lNId] / groupConfigs[netId][lGrpId].avgTimeScale / (1 + fabs(diff_firing) * 50);
1264 runtimeData[netId].
wt[offset + j] += runtimeData[netId].
grpDA[lGrpId] * effectiveWtChange;
1275 runtimeData[netId].
wtChange[offset + j] *= wtChangeDecay_;
1278 if (runtimeData[netId].maxSynWt[offset + j] >= 0) {
1279 if (runtimeData[netId].wt[offset + j] >= runtimeData[netId].maxSynWt[offset + j])
1280 runtimeData[netId].
wt[offset + j] = runtimeData[netId].
maxSynWt[offset + j];
1281 if (runtimeData[netId].wt[offset + j] < 0)
1282 runtimeData[netId].
wt[offset + j] = 0.0;
1285 if (runtimeData[netId].wt[offset + j] <= runtimeData[netId].maxSynWt[offset + j])
1286 runtimeData[netId].
wt[offset + j] = runtimeData[netId].
maxSynWt[offset + j];
1287 if (runtimeData[netId].wt[offset + j] > 0)
1288 runtimeData[netId].
wt[offset + j] = 0.0;
1295 #if !defined(WIN32) && !defined(WIN64) && !defined(__APPLE__) // Linux or MAC
1297 void* SNN::helperUpdateWeights_CPU(
void* arguments) {
1309 #if defined(WIN32) || defined(WIN64) || defined(__APPLE__)
1310 void SNN::shiftSpikeTables_CPU(
int netId) {
1312 void* SNN::shiftSpikeTables_CPU(
int netId) {
1314 assert(runtimeData[netId].memType ==
CPU_MEM);
1317 for(
int p = runtimeData[netId].timeTableD2[999], k = 0; p < runtimeData[netId].
timeTableD2[999 + networkConfigs[netId].maxDelay + 1]; p++, k++) {
1321 for(
int i = 0; i < networkConfigs[netId].maxDelay; i++) {
1326 runtimeData[netId].
timeTableD1[networkConfigs[netId].maxDelay] = 0;
1339 #if !defined(WIN32) && !defined(WIN64) && !defined(__APPLE__) // Linux or MAC
1341 void* SNN::helperShiftSpikeTables_CPU(
void* arguments) {
1349 void SNN::allocateSNN_CPU(
int netId) {
1362 runtimeData[netId].
randNum =
new float[networkConfigs[netId].numNPois];
1370 copyPreConnectionInfo(netId,
ALL, &runtimeData[netId], &managerRuntimeData,
true);
1371 copyPostConnectionInfo(netId,
ALL, &runtimeData[netId], &managerRuntimeData,
true);
1376 copySynapseState(netId, &runtimeData[netId], &managerRuntimeData,
true);
1386 copyNeuronState(netId,
ALL, &runtimeData[netId],
true);
1391 copySTPState(netId,
ALL, &runtimeData[netId], &managerRuntimeData,
true);
1398 copyGroupState(netId,
ALL, &runtimeData[netId], &managerRuntimeData,
true);
1407 copyAuxiliaryData(netId,
ALL, &runtimeData[netId],
true);
1417 for (
int lGrpId = 0; lGrpId < networkConfigs[netId].numGroupsAssigned; lGrpId++) {
1418 KERNEL_DEBUG(
"Settings for Group %s:", groupConfigMap[groupConfigs[netId][lGrpId].gGrpId].grpName.c_str());
1420 KERNEL_DEBUG(
"\tType: %d",(
int)groupConfigs[netId][lGrpId].Type);
1421 KERNEL_DEBUG(
"\tNumN: %d",groupConfigs[netId][lGrpId].numN);
1422 KERNEL_DEBUG(
"\tM: %d",groupConfigs[netId][lGrpId].numPostSynapses);
1423 KERNEL_DEBUG(
"\tPreM: %d",groupConfigs[netId][lGrpId].numPreSynapses);
1424 KERNEL_DEBUG(
"\tspikeGenerator: %d",(
int)groupConfigs[netId][lGrpId].isSpikeGenerator);
1425 KERNEL_DEBUG(
"\tFixedInputWts: %d",(
int)groupConfigs[netId][lGrpId].FixedInputWts);
1426 KERNEL_DEBUG(
"\tMaxDelay: %d",(
int)groupConfigs[netId][lGrpId].MaxDelay);
1427 KERNEL_DEBUG(
"\tWithSTDP: %d",(
int)groupConfigs[netId][lGrpId].WithSTDP);
1428 if (groupConfigs[netId][lGrpId].WithSTDP) {
1430 KERNEL_DEBUG(
"\t\tTAU_PLUS_INV_EXC: %f",groupConfigs[netId][lGrpId].TAU_PLUS_INV_EXC);
1431 KERNEL_DEBUG(
"\t\tTAU_MINUS_INV_EXC: %f",groupConfigs[netId][lGrpId].TAU_MINUS_INV_EXC);
1432 KERNEL_DEBUG(
"\t\tALPHA_PLUS_EXC: %f",groupConfigs[netId][lGrpId].ALPHA_PLUS_EXC);
1433 KERNEL_DEBUG(
"\t\tALPHA_MINUS_EXC: %f",groupConfigs[netId][lGrpId].ALPHA_MINUS_EXC);
1435 KERNEL_DEBUG(
"\t\tTAU_PLUS_INV_INB: %f",groupConfigs[netId][lGrpId].TAU_PLUS_INV_INB);
1436 KERNEL_DEBUG(
"\t\tTAU_MINUS_INV_INB: %f",groupConfigs[netId][lGrpId].TAU_MINUS_INV_INB);
1437 KERNEL_DEBUG(
"\t\tALPHA_PLUS_INB: %f",groupConfigs[netId][lGrpId].ALPHA_PLUS_INB);
1438 KERNEL_DEBUG(
"\t\tALPHA_MINUS_INB: %f",groupConfigs[netId][lGrpId].ALPHA_MINUS_INB);
1439 KERNEL_DEBUG(
"\t\tLAMBDA: %f",groupConfigs[netId][lGrpId].LAMBDA);
1440 KERNEL_DEBUG(
"\t\tDELTA: %f",groupConfigs[netId][lGrpId].DELTA);
1441 KERNEL_DEBUG(
"\t\tBETA_LTP: %f",groupConfigs[netId][lGrpId].BETA_LTP);
1442 KERNEL_DEBUG(
"\t\tBETA_LTD: %f",groupConfigs[netId][lGrpId].BETA_LTD);
1444 KERNEL_DEBUG(
"\tWithSTP: %d",(
int)groupConfigs[netId][lGrpId].WithSTP);
1445 if (groupConfigs[netId][lGrpId].WithSTP) {
1446 KERNEL_DEBUG(
"\t\tSTP_U: %f", groupConfigs[netId][lGrpId].STP_U);
1450 KERNEL_DEBUG(
"\tspikeGen: %s", groupConfigs[netId][lGrpId].isSpikeGenFunc?
"is Set" :
"is not set ");
1475 void SNN::copyPreConnectionInfo(
int netId,
int lGrpId,
RuntimeData* dest,
RuntimeData* src,
bool allocateMem) {
1476 int lengthN, lengthSyn, posN, posSyn;
1478 if (lGrpId ==
ALL) {
1479 lengthN = networkConfigs[netId].numNAssigned;
1482 lengthN = groupConfigs[netId][lGrpId].
numN;
1483 posN = groupConfigs[netId][lGrpId].
lStartN;
1488 dest->
Npre =
new unsigned short[networkConfigs[netId].numNAssigned];
1489 memcpy(&dest->
Npre[posN], &src->
Npre[posN],
sizeof(
short) * lengthN);
1492 if (!sim_with_fixedwts) {
1495 dest->
Npre_plastic =
new unsigned short[networkConfigs[netId].numNAssigned];
1500 float* Npre_plasticInv =
new float[networkConfigs[netId].numNAssigned];
1502 for (
int i = 0; i < networkConfigs[netId].numNAssigned; i++)
1503 Npre_plasticInv[i] = 1.0f / managerRuntimeData.
Npre_plastic[i];
1505 dest->
Npre_plasticInv =
new float[networkConfigs[netId].numNAssigned];
1506 memcpy(dest->
Npre_plasticInv, Npre_plasticInv,
sizeof(
float) * networkConfigs[netId].numNAssigned);
1508 delete[] Npre_plasticInv;
1514 dest->
cumulativePre =
new unsigned int[networkConfigs[netId].numNAssigned];
1518 if (lGrpId ==
ALL) {
1519 lengthSyn = networkConfigs[netId].numPreSynNet;
1523 for (
int lNId = groupConfigs[netId][lGrpId].lStartN; lNId <= groupConfigs[netId][lGrpId].
lEndN; lNId++)
1524 lengthSyn += dest->
Npre[lNId];
1526 posSyn = dest->
cumulativePre[groupConfigs[netId][lGrpId].lStartN];
1550 void SNN::copyPostConnectionInfo(
int netId,
int lGrpId,
RuntimeData* dest,
RuntimeData* src,
bool allocateMem) {
1551 int lengthN, lengthSyn, posN, posSyn;
1553 if (lGrpId ==
ALL) {
1554 lengthN = networkConfigs[netId].numNAssigned;
1557 lengthN = groupConfigs[netId][lGrpId].
numN;
1558 posN = groupConfigs[netId][lGrpId].
lStartN;
1563 dest->
Npost =
new unsigned short[networkConfigs[netId].numNAssigned];
1564 memcpy(&dest->
Npost[posN], &src->
Npost[posN],
sizeof(
short) * lengthN);
1568 dest->
cumulativePost =
new unsigned int[networkConfigs[netId].numNAssigned];
1573 if (lGrpId ==
ALL) {
1574 lengthSyn = networkConfigs[netId].numPostSynNet;
1578 for (
int lNId = groupConfigs[netId][lGrpId].lStartN; lNId <= groupConfigs[netId][lGrpId].
lEndN; lNId++)
1579 lengthSyn += dest->
Npost[lNId];
1581 posSyn = dest->
cumulativePost[groupConfigs[netId][lGrpId].lStartN];
1611 assert(networkConfigs[netId].numPreSynNet > 0);
1615 dest->
wt =
new float[networkConfigs[netId].numPreSynNet];
1616 memcpy(dest->
wt, src->
wt,
sizeof(
float) * networkConfigs[netId].numPreSynNet);
1621 if (!sim_with_fixedwts) {
1624 dest->
wtChange =
new float[networkConfigs[netId].numPreSynNet];
1625 memcpy(dest->
wtChange, src->
wtChange,
sizeof(
float) * networkConfigs[netId].numPreSynNet);
1629 dest->
maxSynWt =
new float[networkConfigs[netId].numPreSynNet];
1630 memcpy(dest->
maxSynWt, src->
maxSynWt,
sizeof(
float) * networkConfigs[netId].numPreSynNet);
1650 void SNN::copyNeuronState(
int netId,
int lGrpId,
RuntimeData* dest,
bool allocateMem) {
1655 length = networkConfigs[netId].numNReg;
1658 ptrPos = groupConfigs[netId][lGrpId].
lStartN;
1659 length = groupConfigs[netId][lGrpId].
numN;
1662 assert(length <= networkConfigs[netId].numNReg);
1667 if(!allocateMem && groupConfigs[netId][lGrpId].Type &
POISSON_NEURON)
1671 dest->
recovery =
new float[length];
1672 memcpy(&dest->
recovery[ptrPos], &managerRuntimeData.
recovery[ptrPos],
sizeof(
float) * length);
1675 dest->
voltage =
new float[length];
1676 memcpy(&dest->
voltage[ptrPos], &managerRuntimeData.
voltage[ptrPos],
sizeof(
float) * length);
1684 dest->
current =
new float[length];
1685 memcpy(&dest->
current[ptrPos], &managerRuntimeData.
current[ptrPos],
sizeof(
float) * length);
1687 if (sim_with_conductances) {
1689 copyConductanceAMPA(netId, lGrpId, dest, &managerRuntimeData, allocateMem, 0);
1690 copyConductanceNMDA(netId, lGrpId, dest, &managerRuntimeData, allocateMem, 0);
1691 copyConductanceGABAa(netId, lGrpId, dest, &managerRuntimeData, allocateMem, 0);
1692 copyConductanceGABAb(netId, lGrpId, dest, &managerRuntimeData, allocateMem, 0);
1697 copyExternalCurrent(netId, lGrpId, dest, allocateMem);
1701 memcpy(&dest->
curSpike[ptrPos], &managerRuntimeData.
curSpike[ptrPos],
sizeof(
bool) * length);
1703 copyNeuronParameters(netId, lGrpId, dest, allocateMem);
1705 if (networkConfigs[netId].sim_with_nm)
1706 copyNeuronStateBuffer(netId, lGrpId, dest, &managerRuntimeData, allocateMem);
1708 if (sim_with_homeostasis) {
1713 memcpy(&dest->
avgFiring[ptrPos], &managerRuntimeData.
avgFiring[ptrPos],
sizeof(
float) * length);
1735 void SNN::copyConductanceAMPA(
int netId,
int lGrpId,
RuntimeData* dest,
RuntimeData* src,
bool allocateMem,
int destOffset) {
1742 length = networkConfigs[netId].numNReg;
1744 ptrPos = groupConfigs[netId][lGrpId].
lStartN;
1745 length = groupConfigs[netId][lGrpId].
numN;
1747 assert(length <= networkConfigs[netId].numNReg);
1751 assert(src->
gAMPA != NULL);
1753 dest->
gAMPA =
new float[length];
1754 memcpy(&dest->
gAMPA[ptrPos + destOffset], &src->
gAMPA[ptrPos],
sizeof(
float) * length);
1775 void SNN::copyConductanceNMDA(
int netId,
int lGrpId,
RuntimeData* dest,
RuntimeData* src,
bool allocateMem,
int destOffset) {
1782 length = networkConfigs[netId].numNReg;
1784 ptrPos = groupConfigs[netId][lGrpId].
lStartN;
1785 length = groupConfigs[netId][lGrpId].
numN;
1787 assert(length <= networkConfigs[netId].numNReg);
1793 dest->
gNMDA_r =
new float[length];
1794 memcpy(&dest->
gNMDA_r[ptrPos], &src->
gNMDA_r[ptrPos],
sizeof(
float) * length);
1798 dest->
gNMDA_d =
new float[length];
1799 memcpy(&dest->
gNMDA_d[ptrPos], &src->
gNMDA_d[ptrPos],
sizeof(
float) * length);
1801 assert(src->
gNMDA != NULL);
1803 dest->
gNMDA =
new float[length];
1804 memcpy(&dest->
gNMDA[ptrPos + destOffset], &src->
gNMDA[ptrPos],
sizeof(
float) * length);
1826 void SNN::copyConductanceGABAa(
int netId,
int lGrpId,
RuntimeData* dest,
RuntimeData* src,
bool allocateMem,
int destOffset) {
1833 length = networkConfigs[netId].numNReg;
1835 ptrPos = groupConfigs[netId][lGrpId].
lStartN;
1836 length = groupConfigs[netId][lGrpId].
numN;
1838 assert(length <= networkConfigs[netId].numNReg);
1841 assert(src->
gGABAa != NULL);
1843 dest->
gGABAa =
new float[length];
1844 memcpy(&dest->
gGABAa[ptrPos + destOffset], &src->
gGABAa[ptrPos],
sizeof(
float) * length);
1865 void SNN::copyConductanceGABAb(
int netId,
int lGrpId,
RuntimeData* dest,
RuntimeData* src,
bool allocateMem,
int destOffset) {
1870 if (lGrpId ==
ALL) {
1872 length = networkConfigs[netId].numNReg;
1874 ptrPos = groupConfigs[netId][lGrpId].
lStartN;
1875 length = groupConfigs[netId][lGrpId].
numN;
1877 assert(length <= networkConfigs[netId].numNReg);
1883 dest->
gGABAb_r =
new float[length];
1884 memcpy(&dest->
gGABAb_r[ptrPos], &src->
gGABAb_r[ptrPos],
sizeof(
float) * length);
1888 dest->
gGABAb_d =
new float[length];
1889 memcpy(&dest->
gGABAb_d[ptrPos], &src->
gGABAb_d[ptrPos],
sizeof(
float) * length);
1891 assert(src->
gGABAb != NULL);
1893 dest->
gGABAb =
new float[length];
1894 memcpy(&dest->
gGABAb[ptrPos + destOffset], &src->
gGABAb[ptrPos],
sizeof(
float) * length);
1915 void SNN::copyNeuronStateBuffer(
int netId,
int lGrpId,
RuntimeData* dest,
RuntimeData* src,
bool allocateMem) {
1927 if (lGrpId ==
ALL) {
1932 memcpy(&dest->
nVBuffer[ptrPos], &src->
nVBuffer[ptrPos],
sizeof(
float) * length);
1933 memcpy(&dest->
nUBuffer[ptrPos], &src->
nUBuffer[ptrPos],
sizeof(
float) * length);
1934 memcpy(&dest->
nIBuffer[ptrPos], &src->
nIBuffer[ptrPos],
sizeof(
float) * length);
1937 for (
int t = 0; t < 1000; t++) {
1945 memcpy(&dest->
nVBuffer[ptrPos], &src->
nVBuffer[ptrPos],
sizeof(
float) * length);
1946 memcpy(&dest->
nUBuffer[ptrPos], &src->
nUBuffer[ptrPos],
sizeof(
float) * length);
1947 memcpy(&dest->
nIBuffer[ptrPos], &src->
nIBuffer[ptrPos],
sizeof(
float) * length);
1970 void SNN::copyExternalCurrent(
int netId,
int lGrpId,
RuntimeData* dest,
bool allocateMem) {
1975 lengthN = networkConfigs[netId].numNReg;
1977 assert(lGrpId >= 0);
1978 posN = groupConfigs[netId][lGrpId].
lStartN;
1979 lengthN = groupConfigs[netId][lGrpId].
numN;
1981 assert(lengthN >= 0 && lengthN <= networkConfigs[netId].numNReg);
1983 KERNEL_DEBUG(
"copyExternalCurrent: lGrpId=%d, ptrPos=%d, length=%d, allocate=%s", lGrpId, posN, lengthN, allocateMem?
"y":
"n");
1987 memcpy(&(dest->
extCurrent[posN]), &(managerRuntimeData.
extCurrent[posN]),
sizeof(
float) * lengthN);
2008 void SNN::copyNeuronParameters(
int netId,
int lGrpId,
RuntimeData* dest,
bool allocateMem) {
2013 assert(lGrpId ==
ALL);
2014 assert(dest->
Izh_a == NULL);
2015 assert(dest->
Izh_b == NULL);
2016 assert(dest->
Izh_c == NULL);
2017 assert(dest->
Izh_d == NULL);
2018 assert(dest->
Izh_C == NULL);
2019 assert(dest->
Izh_k == NULL);
2020 assert(dest->
Izh_vr == NULL);
2021 assert(dest->
Izh_vt == NULL);
2026 assert(dest->
lif_vTh == NULL);
2034 length = networkConfigs[netId].numNReg;
2037 ptrPos = groupConfigs[netId][lGrpId].
lStartN;
2038 length = groupConfigs[netId][lGrpId].
numN;
2042 dest->
Izh_a =
new float[length];
2043 memcpy(&dest->
Izh_a[ptrPos], &(managerRuntimeData.
Izh_a[ptrPos]),
sizeof(
float) * length);
2046 dest->
Izh_b =
new float[length];
2047 memcpy(&dest->
Izh_b[ptrPos], &(managerRuntimeData.
Izh_b[ptrPos]),
sizeof(
float) * length);
2050 dest->
Izh_c =
new float[length];
2051 memcpy(&dest->
Izh_c[ptrPos], &(managerRuntimeData.
Izh_c[ptrPos]),
sizeof(
float) * length);
2054 dest->
Izh_d =
new float[length];
2055 memcpy(&dest->
Izh_d[ptrPos], &(managerRuntimeData.
Izh_d[ptrPos]),
sizeof(
float) * length);
2058 dest->
Izh_C =
new float[length];
2059 memcpy(&dest->
Izh_C[ptrPos], &(managerRuntimeData.
Izh_C[ptrPos]),
sizeof(
float) * length);
2062 dest->
Izh_k =
new float[length];
2063 memcpy(&dest->
Izh_k[ptrPos], &(managerRuntimeData.
Izh_k[ptrPos]),
sizeof(
float) * length);
2066 dest->
Izh_vr =
new float[length];
2067 memcpy(&dest->
Izh_vr[ptrPos], &(managerRuntimeData.
Izh_vr[ptrPos]),
sizeof(
float) * length);
2070 dest->
Izh_vt =
new float[length];
2071 memcpy(&dest->
Izh_vt[ptrPos], &(managerRuntimeData.
Izh_vt[ptrPos]),
sizeof(
float) * length);
2075 memcpy(&dest->
Izh_vpeak[ptrPos], &(managerRuntimeData.
Izh_vpeak[ptrPos]),
sizeof(
float) * length);
2080 memcpy(&dest->
lif_tau_m[ptrPos], &(managerRuntimeData.
lif_tau_m[ptrPos]),
sizeof(
int) * length);
2091 dest->
lif_vTh =
new float[length];
2092 memcpy(&dest->
lif_vTh[ptrPos], &(managerRuntimeData.
lif_vTh[ptrPos]),
sizeof(
float) * length);
2096 memcpy(&dest->
lif_vReset[ptrPos], &(managerRuntimeData.
lif_vReset[ptrPos]),
sizeof(
float) * length);
2099 dest->
lif_gain =
new float[length];
2100 memcpy(&dest->
lif_gain[ptrPos], &(managerRuntimeData.
lif_gain[ptrPos]),
sizeof(
float) * length);
2103 dest->
lif_bias =
new float[length];
2104 memcpy(&dest->
lif_bias[ptrPos], &(managerRuntimeData.
lif_bias[ptrPos]),
sizeof(
float) * length);
2107 if (sim_with_homeostasis) {
2108 float* baseFiringInv =
new float[length];
2109 for(
int nid = 0; nid < length; nid++) {
2110 if (managerRuntimeData.
baseFiring[nid] != 0.0f)
2111 baseFiringInv[nid] = 1.0f / managerRuntimeData.
baseFiring[ptrPos + nid];
2113 baseFiringInv[nid] = 0.0;
2118 memcpy(&dest->
baseFiringInv[ptrPos], baseFiringInv,
sizeof(
float) * length);
2124 delete [] baseFiringInv;
2149 assert(dest->
stpu == NULL);
2150 assert(dest->
stpx == NULL);
2152 assert(dest->
stpu != NULL);
2153 assert(dest->
stpx != NULL);
2155 assert(src->
stpu != NULL); assert(src->
stpx != NULL);
2158 dest->
stpu =
new float[networkConfigs[netId].numN * (networkConfigs[netId].maxDelay + 1)];
2159 memcpy(dest->
stpu, src->
stpu,
sizeof(
float) * networkConfigs[netId].numN * (networkConfigs[netId].maxDelay + 1));
2162 dest->
stpx =
new float[networkConfigs[netId].numN * (networkConfigs[netId].maxDelay + 1)];
2163 memcpy(dest->
stpx, src->
stpx,
sizeof(
float) * networkConfigs[netId].numN * (networkConfigs[netId].maxDelay + 1));
2187 dest->
grpDA =
new float[networkConfigs[netId].numGroups];
2188 dest->
grp5HT =
new float[networkConfigs[netId].numGroups];
2189 dest->
grpACh =
new float[networkConfigs[netId].numGroups];
2190 dest->
grpNE =
new float[networkConfigs[netId].numGroups];
2192 memcpy(dest->
grpDA, src->
grpDA,
sizeof(
float) * networkConfigs[netId].numGroups);
2193 memcpy(dest->
grp5HT, src->
grp5HT,
sizeof(
float) * networkConfigs[netId].numGroups);
2194 memcpy(dest->
grpACh, src->
grpACh,
sizeof(
float) * networkConfigs[netId].numGroups);
2195 memcpy(dest->
grpNE, src->
grpNE,
sizeof(
float) * networkConfigs[netId].numGroups);
2197 if (lGrpId ==
ALL) {
2200 dest->
grpDABuffer =
new float[1000 * networkConfigs[netId].numGroups];
2201 dest->
grp5HTBuffer =
new float[1000 * networkConfigs[netId].numGroups];
2202 dest->
grpAChBuffer =
new float[1000 * networkConfigs[netId].numGroups];
2203 dest->
grpNEBuffer =
new float[1000 * networkConfigs[netId].numGroups];
2210 assert(!allocateMem);
2238 void SNN::copyAuxiliaryData(
int netId,
int lGrpId,
RuntimeData* dest,
bool allocateMem) {
2239 assert(networkConfigs[netId].numN > 0);
2242 dest->
spikeGenBits =
new unsigned int[networkConfigs[netId].numNSpikeGen / 32 + 1];
2243 memset(dest->
spikeGenBits, 0,
sizeof(
int) * (networkConfigs[netId].numNSpikeGen / 32 + 1));
2248 memset(dest->
poissonFireRate, 0,
sizeof(
float) * networkConfigs[netId].numNPois);
2253 networkConfigs[netId].I_setLength = ceil(((networkConfigs[netId].maxNumPreSynN) / 32.0f));
2254 dest->
I_set =
new int[networkConfigs[netId].numNReg * networkConfigs[netId].I_setLength];
2256 assert(networkConfigs[netId].maxNumPreSynN >= 0);
2257 memset(dest->
I_set, 0,
sizeof(
int) * networkConfigs[netId].numNReg * networkConfigs[netId].I_setLength);
2261 dest->
synSpikeTime =
new int[networkConfigs[netId].numPreSynNet];
2268 dest->
lastSpikeTime =
new int[networkConfigs[netId].numNAssigned];
2272 copyNeuronSpikeCount(netId, lGrpId, dest, &managerRuntimeData,
true, 0);
2276 dest->
grpIds =
new short int[networkConfigs[netId].numNAssigned];
2277 memcpy(dest->
grpIds, managerRuntimeData.
grpIds,
sizeof(
short int) * networkConfigs[netId].numNAssigned);
2281 dest->
connIdsPreIdx =
new short int[networkConfigs[netId].numPreSynNet];
2322 dest->
firingTableD1 =
new int[networkConfigs[netId].maxSpikesD1];
2323 if (networkConfigs[netId].maxSpikesD1 > 0)
2328 dest->
firingTableD2 =
new int[networkConfigs[netId].maxSpikesD2];
2329 if (networkConfigs[netId].maxSpikesD2 > 0)
2335 memset(dest->
extFiringTableD1, 0 ,
sizeof(
int*) * networkConfigs[netId].numGroups);
2336 for (
int lGrpId = 0; lGrpId < networkConfigs[netId].numGroups; lGrpId++) {
2337 if (groupConfigs[netId][lGrpId].hasExternalConnect) {
2347 memset(dest->
extFiringTableD2, 0 ,
sizeof(
int*) * networkConfigs[netId].numGroups);
2348 for (
int lGrpId = 0; lGrpId < networkConfigs[netId].numGroups; lGrpId++) {
2349 if (groupConfigs[netId][lGrpId].hasExternalConnect) {
2386 void SNN::copyNeuronSpikeCount(
int netId,
int lGrpId,
RuntimeData* dest,
RuntimeData* src,
bool allocateMem,
int destOffset) {
2391 lengthN = networkConfigs[netId].numN;
2393 posN = groupConfigs[netId][lGrpId].
lStartN;
2394 lengthN = groupConfigs[netId][lGrpId].
numN;
2396 assert(lengthN > 0 && lengthN <= networkConfigs[netId].numN);
2401 memcpy(&dest->
nSpikeCnt[posN + destOffset], &src->
nSpikeCnt[posN],
sizeof(
int) * lengthN);
2405 #if defined(WIN32) || defined(WIN64) || defined(__APPLE__)
2406 void SNN::assignPoissonFiringRate_CPU(
int netId) {
2408 void* SNN::assignPoissonFiringRate_CPU(
int netId) {
2410 assert(runtimeData[netId].memType ==
CPU_MEM);
2412 for (
int lGrpId = 0; lGrpId < networkConfigs[netId].numGroups; lGrpId++) {
2414 if (groupConfigs[netId][lGrpId].isSpikeGenerator) {
2415 int lNId = groupConfigs[netId][lGrpId].
lStartN;
2416 int gGrpId = groupConfigs[netId][lGrpId].
gGrpId;
2417 PoissonRate* rate = groupConfigMDMap[gGrpId].ratePtr;
2420 if (groupConfigMap[gGrpId].spikeGenFunc || rate == NULL)
2423 assert(runtimeData[netId].poissonFireRate != NULL);
2424 assert(rate->
isOnGPU() ==
false);
2426 memcpy(&runtimeData[netId].poissonFireRate[lNId - networkConfigs[netId].numNReg], rate->
getRatePtrCPU(),
2432 #if !defined(WIN32) && !defined(WIN64) && !defined(__APPLE__) // Linux or MAC
2434 void* SNN::helperAssignPoissonFiringRate_CPU(
void* arguments) {
2456 void SNN::copyWeightState(
int netId,
int lGrpId) {
2457 int lengthSyn, posSyn;
2460 copyPreConnectionInfo(netId, lGrpId, &managerRuntimeData, &runtimeData[netId],
false);
2462 if (lGrpId ==
ALL) {
2463 lengthSyn = networkConfigs[netId].numPreSynNet;
2468 for (
int lNId = groupConfigs[netId][lGrpId].lStartN; lNId <= groupConfigs[netId][lGrpId].
lEndN; lNId++)
2469 lengthSyn += managerRuntimeData.
Npre[lNId];
2471 posSyn = managerRuntimeData.
cumulativePre[groupConfigs[netId][lGrpId].lStartN];
2474 assert(posSyn < networkConfigs[netId].numPreSynNet || networkConfigs[netId].numPreSynNet == 0);
2475 assert(lengthSyn <= networkConfigs[netId].numPreSynNet);
2477 memcpy(&managerRuntimeData.
wt[posSyn], &runtimeData[netId].wt[posSyn],
sizeof(
float) * lengthSyn);
2482 if ((!sim_with_fixedwts) || sim_with_stdp) {
2484 memcpy(&managerRuntimeData.
wtChange[posSyn], &runtimeData[netId].wtChange[posSyn],
sizeof(
float) * lengthSyn);
2488 void SNN::copyNetworkConfig(
int netId) {
2492 void SNN::copyGrpIdsLookupArray(
int netId) {
2493 memcpy(managerRuntimeData.
grpIds, runtimeData[netId].grpIds,
sizeof(
short int) * networkConfigs[netId].numNAssigned);
2496 void SNN::copyConnIdsLookupArray(
int netId) {
2497 memcpy(managerRuntimeData.
connIdsPreIdx, runtimeData[netId].connIdsPreIdx,
sizeof(
short int) * networkConfigs[netId].numPreSynNet);
2500 void SNN::copyLastSpikeTime(
int netId) {
2501 memcpy(managerRuntimeData.
lastSpikeTime, runtimeData[netId].lastSpikeTime,
sizeof(
int) * networkConfigs[netId].numN);
2507 void SNN::copyNetworkSpikeCount(
int netId,
2508 unsigned int* spikeCountD1,
unsigned int* spikeCountD2,
2509 unsigned int* spikeCountExtD1,
unsigned int* spikeCountExtD2) {
2522 void SNN::copySpikeTables(
int netId) {
2523 unsigned int spikeCountD1Sec, spikeCountD2Sec, spikeCountLastSecLeftD2;
2528 memcpy(managerRuntimeData.
firingTableD2, runtimeData[netId].firingTableD2,
sizeof(
int) * (spikeCountD2Sec + spikeCountLastSecLeftD2));
2529 memcpy(managerRuntimeData.
firingTableD1, runtimeData[netId].firingTableD1,
sizeof(
int) * spikeCountD1Sec);
2530 memcpy(managerRuntimeData.
timeTableD2, runtimeData[netId].timeTableD2,
sizeof(
int) * (1000 + networkConfigs[netId].maxDelay + 1));
2531 memcpy(managerRuntimeData.
timeTableD1, runtimeData[netId].timeTableD1,
sizeof(
int) * (1000 + networkConfigs[netId].maxDelay + 1));
2534 #if defined(WIN32) || defined(WIN64) || defined(__APPLE__)
2535 void SNN::deleteRuntimeData_CPU(
int netId) {
2537 void* SNN::deleteRuntimeData_CPU(
int netId) {
2539 assert(runtimeData[netId].memType ==
CPU_MEM);
2541 delete [] runtimeData[netId].
voltage;
2543 delete [] runtimeData[netId].
recovery;
2544 delete [] runtimeData[netId].
current;
2546 delete [] runtimeData[netId].
curSpike;
2547 delete [] runtimeData[netId].
Npre;
2550 delete [] runtimeData[netId].
Npost;
2554 delete [] runtimeData[netId].
wt;
2555 delete [] runtimeData[netId].
wtChange;
2556 delete [] runtimeData[netId].
maxSynWt;
2562 delete [] runtimeData[netId].
grpDA;
2563 delete [] runtimeData[netId].
grp5HT;
2564 delete [] runtimeData[netId].
grpACh;
2565 delete [] runtimeData[netId].
grpNE;
2572 if (networkConfigs[netId].sim_with_nm) {
2573 delete[] runtimeData[netId].
nVBuffer;
2574 delete[] runtimeData[netId].
nUBuffer;
2575 delete[] runtimeData[netId].
nIBuffer;
2578 delete [] runtimeData[netId].
grpIds;
2580 delete [] runtimeData[netId].
Izh_a;
2581 delete [] runtimeData[netId].
Izh_b;
2582 delete [] runtimeData[netId].
Izh_c;
2583 delete [] runtimeData[netId].
Izh_d;
2584 delete [] runtimeData[netId].
Izh_C;
2585 delete [] runtimeData[netId].
Izh_k;
2586 delete [] runtimeData[netId].
Izh_vr;
2587 delete [] runtimeData[netId].
Izh_vt;
2593 delete [] runtimeData[netId].
lif_vTh;
2595 delete [] runtimeData[netId].
lif_gain;
2596 delete [] runtimeData[netId].
lif_bias;
2598 delete [] runtimeData[netId].
gAMPA;
2599 if (sim_with_NMDA_rise) {
2600 delete [] runtimeData[netId].
gNMDA_r;
2601 delete [] runtimeData[netId].
gNMDA_d;
2604 delete [] runtimeData[netId].
gNMDA;
2606 delete [] runtimeData[netId].
gGABAa;
2607 if (sim_with_GABAb_rise) {
2608 delete [] runtimeData[netId].
gGABAb_r;
2609 delete [] runtimeData[netId].
gGABAb_d;
2612 delete [] runtimeData[netId].
gGABAb;
2615 delete [] runtimeData[netId].
stpu;
2616 delete [] runtimeData[netId].
stpx;
2623 delete [] runtimeData[netId].
I_set;
2635 tempPtrs =
new int*[networkConfigs[netId].numGroups];
2638 memcpy(tempPtrs, runtimeData[netId].extFiringTableD2,
sizeof(
int*) * networkConfigs[netId].numGroups);
2639 for (
int i = 0; i < networkConfigs[netId].numGroups; i++)
2640 delete [] tempPtrs[i];
2644 memcpy(tempPtrs, runtimeData[netId].extFiringTableD1,
sizeof(
int*) * networkConfigs[netId].numGroups);
2645 for (
int i = 0; i < networkConfigs[netId].numGroups; i++)
2646 delete [] tempPtrs[i];
2654 if (runtimeData[netId].randNum != NULL)
delete [] runtimeData[netId].
randNum;
2655 runtimeData[netId].
randNum = NULL;
2658 #if !defined(WIN32) && !defined(WIN64) && !defined(__APPLE__) // Linux or MAC
2660 void* SNN::helperDeleteRuntimeData_CPU(
void* arguments) {