CARLsim  6.1.0
CARLsim: a GPU-accelerated SNN simulator
snn.h
Go to the documentation of this file.
1 /* * Copyright (c) 2016 Regents of the University of California. All rights reserved.
2  *
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions
5  * are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * 3. The names of its contributors may not be used to endorse or promote
15  * products derived from this software without specific prior written
16  * permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * *********************************************************************************************** *
31  * CARLsim
32  * created by: (MDR) Micah Richert, (JN) Jayram M. Nageswaran
33  * maintained by:
34  * (MA) Mike Avery <averym@uci.edu>
35  * (MB) Michael Beyeler <mbeyeler@uci.edu>,
36  * (KDC) Kristofor Carlson <kdcarlso@uci.edu>
37  * (TSC) Ting-Shuo Chou <tingshuc@uci.edu>
38  * (HK) Hirak J Kashyap <kashyaph@uci.edu>
39  *
40  * CARLsim v1.0: JM, MDR
41  * CARLsim v2.0/v2.1/v2.2: JM, MDR, MA, MB, KDC
42  * CARLsim3: MB, KDC, TSC
43  * CARLsim4: TSC, HK
44  * CARLsim5: HK, JX, KC
45  * CARLsim6: LN, KC, JX, KW
46  *
47  * CARLsim available from http://socsci.uci.edu/~jkrichma/CARLsim/
48  * Ver 12/31/2016
49  */
50 
51 /*
52  * Common Abbreviations used in CARLsim
53  * snn/SNN: spiking neural network
54  * stp/STP: short-term plasticity
55  * stdp/STDP: spike-timing dependent plasticity
56  * syn/SYN: synapse
57  * wt/WT: weight
58  * exc/Exc: excitatory
59  * inh/Inh: inhibitory
60  * grp: group
61  * nid/NId/NID: neuron id
62  * gid/GId/GID: group id
63  *
64  * conn: connection
65  * min: minimum
66  * max: maximum
67  * num: number
68  * mem: memory
69  * id/Id/ID: identification
70  * info: information
71  * cnt: count
72  * curr: current
73  * mon: monitor
74  * reg/Reg: regurlar
75  * pois/Pois: poisson
76  */
77 #ifndef _SNN_GOLD_H_
78 #define _SNN_GOLD_H_
79 
80 
81 //{ LN fixes for CARLsim6
82 //#define LN_FIX_DA_DECAY_GPU
83 //#define LN_FIX_DA_DECAY_CPU
84 //#define LN_FIX_ALL_DECAY_CPU
85 //#define LN_FIX_ALL_DECAY_GPU
86 //}
87 
88 //{ LN feat for CARLsim6
89 //#define LN_UPDATE_CURSPIKES
90 //#define LN_UPDATE_CURSPIKES_MT
91 //}
92 
93 //{ LN feat for CARLsim6, performance Issue Setup
94 //#define LN_FIX_CONNLIST_
95 //#define LN_SETUP_NETWORK_MT; // featFastSetup LN 20201108
96 //}
97 
98 
99 #include <map>
100 #include <list>
101 #include <cmath>
102 #include <cstring>
103 #include <cassert>
104 #include <cstdio>
105 #include <climits>
106 
107 // experimental
108 #include <mutex>
109 
110 #include <carlsim.h>
111 #include <callback_core.h>
112 
113 #include <snn_definitions.h>
114 #include <snn_datastructures.h>
115 
116 // #include <spike_buffer.h>
117 #include <poisson_rate.h>
118 
119 class SpikeMonitor;
120 class SpikeMonitorCore;
121 class NeuronMonitor;
122 class NeuronMonitorCore;
124 class ConnectionMonitor;
125 
126 class SpikeBuffer;
127 
128 
132 
138 class SNN {
139 
143 public:
145 
151  SNN(const std::string& name, SimMode preferredSimMode, LoggerMode loggerMode, int randSeed);
152 
154 
157  ~SNN();
158 
159  // +++++ PUBLIC PROPERTIES ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
160 
161  const static unsigned int MAJOR_VERSION = 6;
162  const static unsigned int MINOR_VERSION = 0;
163 
164 
165 
166  // +++++ PUBLIC METHODS: SETTING UP A SIMULATION ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
167 
168  // NOTE: there should be no default argument values in here, this should be handled by the user interface
169 
172 
187  short int connect(int gIDpre, int gIDpost, const std::string& _type, float initWt, float maxWt, float prob,
188  uint8_t minDelay, uint8_t maxDelay, RadiusRF radius,
189  float mulSynFast, float mulSynSlow, bool synWtType);
190 
191  /* Creates synaptic projections using a callback mechanism.
192  *
193  * \param _grpIdPre:ID of the pre-synaptic group
194  * \param _grpIdPost ID of the post-synaptic group
195  * \param _conn: pointer to an instance of class ConnectionGenerator
196  * \param _synWtType: (optional) connection type, either SYN_FIXED or SYN_PLASTIC, default = SYN_FIXED
197  * \return number of created synaptic projections
198  */
199  short int connect(int gIDpre, int gIDpost, ConnectionGeneratorCore* conn, float mulSynFast, float mulSynSlow,
200  bool synWtType);
201 
202  /* Creates synaptic projections using a callback mechanism.
203  *
204  * \param _grpId1:ID lower layer group
205  * \param _grpId2 ID upper level group
206  */
207  short int connectCompartments(int grpIdLower, int grpIdUpper);
208 
210 
215  int createGroup(const std::string& grpName, const Grid3D& grid, int neurType, int preferredPartition, ComputingBackend preferredBackend);
216 
218 
225  int createGroupLIF(const std::string& grpName, const Grid3D& grid, int neurType, int preferredPartition, ComputingBackend preferredBackend);
226 
228 
233  int createSpikeGeneratorGroup(const std::string& grpName, const Grid3D& grid, int neurType, int preferredPartition, ComputingBackend preferredBackend);
234 
241  void setCompartmentParameters(int grpId, float couplingUp, float couplingDown);
242 
243 #define LN_I_CALC_TYPES__REQUIRED_FOR_NETWORK_LEVE
244 
255  void setConductances(bool isSet, int tdAMPA, int trNMDA, int tdNMDA, int tdGABAa, int trGABAb, int tdGABAb);
256 
257 #ifdef LN_I_CALC_TYPES
258 
261  // \todo LN transfer doc
262  void setConductances(int grpId, bool isSet, int tdAMPA, int trNMDA, int tdNMDA, int tdGABAa, int trGABAb, int tdGABAb);
263 
264  void setNM4weighted(int grpId, IcalcType type, float wDA, float w5HT, float wACh, float wNE, float wNorm, float wBase);
265 #endif
266 
267 
274  void setHomeostasis(int grpId, bool isSet, float homeoScale, float avgTimeScale);
275 
277  void setHomeoBaseFiringRate(int groupId, float baseFiring, float baseFiringSD);
278 
280  void setIntegrationMethod(integrationMethod_t method, int numStepsPerMs);
281 
283 
295  void setNeuronParameters(int grpId, float izh_a, float izh_a_sd, float izh_b, float izh_b_sd,
296  float izh_c, float izh_c_sd, float izh_d, float izh_d_sd);
297 
310  void setNeuronParametersLIF(int grpId, int tau_m, int tau_ref, float vTh, float vReset, double minRmem, double maxRmem);
311 
313 
336  void setNeuronParameters(int grpId, float izh_C, float izh_C_sd, float izh_k, float izh_k_sd,
337  float izh_vr, float izh_vr_sd, float izh_vt, float izh_vt_sd,
338  float izh_a, float izh_a_sd, float izh_b, float izh_b_sd,
339  float izh_vpeak, float izh_vpeak_sd, float izh_c, float izh_c_sd,
340  float izh_d, float izh_d_sd);
341 
343 
354  void setNeuromodulator(int grpId, float baseDP, float tauDP, float base5HT, float tau5HT,
355  float baseACh, float tauACh, float baseNE, float tauNE);
356 
358  void setNeuromodulator(int grpId,
359  float baseDP, float tauDP, float releaseDP, bool activeDP,
360  float base5HT, float tau5HT, float release5HT, bool active5HT,
361  float baseACh, float tauACh, float releaseAch, bool activeACh,
362  float baseNE, float tauNE, float releaseNE, bool activeNE);
363 
364 
366  /*
367  * \brief STDP must be defined post-synaptically; that is, if STP should be implemented on the connections from group 0 to group 1,
368  * call setSTP on group 1. Fore details on the phenomeon, see (for example) (Bi & Poo, 2001).
369  * \param[in] grpId ID of the neuron group
370  * \param[in] isSet_enable set to true to enable STDP for this group
371  * \param[in] type STDP type (STANDARD, DA_MOD)
372  * \param[in] alphaPlus max magnitude for LTP change
373  * \param[in] tauPlus decay time constant for LTP
374  * \param[in] alphaMinus max magnitude for LTD change (leave positive)
375  * \param[in] tauMinus decay time constant for LTD
376  */
377  void setESTDP(int preGrpId, int postGrpId, bool isSet, STDPType type, STDPCurve curve, float alphaPlus, float tauPlus, float alphaMinus, float tauMinus, float gamma);
378 
379 #ifdef LN_I_CALC_TYPES
380  /*
382  * \brief STDP
383  * \param[in] ...
384  */
385  void setESTDP(int preGrpId, int postGrpId, bool isSet, STDPType type, STDPCurve curve, float alphaPlus, float tauPlus, float alphaMinus, float tauMinus, int nm_pka, float w_pka, int nm_plc, float w_plc);
386  void setConnectionModulation(int preGrpId, int postGrpId, IcalcType icalcType);
387 #endif
388 
390  /*
391  * \brief STDP must be defined post-synaptically; that is, if STP should be implemented on the connections from group 0 to group 1,
392  * call setSTP on group 1. Fore details on the phenomeon, see (for example) (Bi & Poo, 2001).
393  * \param[in] grpId ID of the neuron group
394  * \param[in] isSet_enable set to true to enable STDP for this group
395  * \param[in] type STDP type (STANDARD, DA_MOD)
396  * \param[in] curve STDP curve
397  * \param[in] ab1 magnitude for LTP change
398  * \param[in] ab2 magnitude for LTD change (leave positive)
399  * \param[in] tau1, the interval for LTP
400  * \param[in] tau2, the interval for LTD
401  */
402  void setISTDP(int preGrpId, int postGrpId, bool isSet, STDPType type, STDPCurve curve, float ab1, float ab2, float tau1, float tau2);
403 
424  void setSTP(int grpId, bool isSet, float STP_U, float STP_tau_u, float STP_tau_x);
425 
426 
427 #ifdef LN_I_CALC_TYPES
428  void setNM4STP(int grpId, float wSTP_U[], float wSTP_tau_u[], float wSTP_tau_x[]);
429 #endif
430 
431 
433 
438  void setWeightAndWeightChangeUpdate(UpdateInterval wtANDwtChangeUpdateInterval, bool enableWtChangeDecay, float wtChangeDecay);
439 
440 
441 
442  // +++++ PUBLIC METHODS: RUNNING A SIMULATION +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
443 
449  int runNetwork(int _nsec, int _nmsec, bool printRunSummary);
450 
455  void setupNetwork();
456 
457 #ifdef LN_SETUP_NETWORK_MT
458  // LN experimental
459  void setupNetworkMT();
460 #endif
461 
462  // +++++ PUBLIC METHODS: INTERACTING WITH A SIMULATION ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
463 
464  // adds a bias to every weight in the connection
465  void biasWeights(short int connId, float bias, bool updateWeightRange = false);
466 
468  void exitSimulation(int val = 1);
469 
472  /*
473  * \brief After calling SNN::loadSimulation, you should run SNN::runNetwork before calling fclose(fp).
474  * \param fid: file pointer
475  * \sa SNN::saveSimulation()
476  */
477  void loadSimulation(FILE* fid);
478 
479  // multiplies every weight with a scaling factor
480  void scaleWeights(short int connId, float scale, bool updateWeightRange = false);
481 
483 
488  GroupMonitor* setGroupMonitor(int grpId, FILE* fid, int mode = 0);
489 
491 
496  ConnectionMonitor* setConnectionMonitor(int grpIdPre, int grpIdPost, FILE* fid);
497 
499  void setExternalCurrent(int grpId, const std::vector<float>& current);
500 
502  void setSpikeGenerator(int grpId, SpikeGeneratorCore* spikeGenFunc);
503 
505 
510  SpikeMonitor* setSpikeMonitor(int gid, FILE* fid);
511 
513 
518  NeuronMonitor* setNeuronMonitor(int gid, FILE* fid);
519 
521 
526  void setSpikeRate(int grpId, PoissonRate* spikeRate, int refPeriod);
527 
529  void setWeight(short int connId, int neurIdPre, int neurIdPost, float weight, bool updateWeightRange = false);
530 
532  void startTesting(bool shallUpdateWeights = true);
533 
535  void stopTesting();
536 
538  void updateConnectionMonitor(short int connId = ALL);
539 
541  void updateGroupMonitor(int grpId = ALL);
542 
543 
544 #ifdef LN_UPDATE_CURSPIKES
545  void updateCurSpike(std::vector<bool>& firings, int netId);
547 #endif
548 #ifdef LN_UPDATE_CURSPIKES_MT
549  void updateCurSpikeMT(std::vector<bool>& firings, int netId);
551 #endif
552 
553 #ifdef LN_AXON_PLAST
554  void findWavefrontPath(std::vector<int>& path, std::vector<float>& eligibility, int netId, int grpId, int startNId, int goalNId);
555  bool updateDelays(int gGrpIdPre, int gGrpIdPost, std::vector<std::tuple<int, int, uint8_t>> connDelays);
556  void printEntrails(char* buffer, unsigned length, int gGrpIdPre, int gGrpIdPost);
557 #endif
558 
569  void updateSpikeMonitor(int grpId = ALL);
570 
581  void updateNeuronMonitor(int grpId = ALL);
582 
584  /*
585  * \param fid file pointer
586  */
587  void saveSimulation(FILE* fid, bool saveSynapseInfo = false);
588 
590  //void writePopWeights(std::string fname, int gIDpre, int gIDpost);
591 
592 
593  // +++++ PUBLIC METHODS: LOGGING / PLOTTING +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
594 
596  const FILE* getLogFpInf() { return fpInf_; }
598  const FILE* getLogFpErr() { return fpErr_; }
600  const FILE* getLogFpDeb() { return fpDeb_; }
602  const FILE* getLogFpLog() { return fpLog_; }
603 
608  void setLogsFp(FILE* fpInf = NULL, FILE* fpErr = NULL, FILE* fpDeb = NULL, FILE* fpLog = NULL);
609 
610 
611  // +++++ PUBLIC METHODS: GETTERS / SETTERS ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
612 
613  short int getConnectId(int grpIdPre, int grpIdPost);
614  ConnectConfig getConnectConfig(short int connectId);
615  ConnSTDPInfo getConnSTDPInfo(short int connId);
616 
618  RangeDelay getDelayRange(short int connId);
619 
621 
629  uint8_t* getDelays(int gGrpIdPre, int gGrpIdPost, int& numPreN, int& numPostN);
630 
631  Grid3D getGroupGrid3D(int grpId);
632  int getGroupId(std::string grpName);
633  std::string getGroupName(int grpId);
635 
636  LoggerMode getLoggerMode() { return loggerMode_; }
637 
638  // get functions for GroupInfo
639  int getGroupStartNeuronId(int gGrpId) { return groupConfigMDMap[gGrpId].gStartN; }
640  int getGroupEndNeuronId(int gGrpId) { return groupConfigMDMap[gGrpId].gEndN; }
641  int getGroupNumNeurons(int gGrpId) { return groupConfigMap[gGrpId].numN; }
642 
643  std::string getNetworkName() { return networkName_; }
644 
645  Point3D getNeuronLocation3D(int neurId);
646  Point3D getNeuronLocation3D(int grpId, int relNeurId);
647 
648  int getNeuronId(int gGrpId, Point3D location);
649  //int getRelNeuronId(int gGrpId, int x, int y, int z); //!< normalized primtive bravis lattice
650 
651 
652  int getNumConnections() { return numConnections; }
653  int getNumSynapticConnections(short int connectionId);
654  int getNumCompartmentConnections() { return numCompartmentConnections; }
655  int getNumGroups() { return numGroups; }
656  int getNumNeurons() { return glbNetworkConfig.numN; }
657  int getNumNeuronsReg() { return glbNetworkConfig.numNReg; }
658  int getNumNeuronsRegExc() { return glbNetworkConfig.numNExcReg; }
659  int getNumNeuronsRegInh() { return glbNetworkConfig.numNInhReg; }
660  int getNumNeuronsGen() { return glbNetworkConfig.numNPois; }
661  int getNumNeuronsGenExc() { return glbNetworkConfig.numNExcPois; }
662  int getNumNeuronsGenInh() { return glbNetworkConfig.numNInhPois; }
663  int getNumSynapses() { return glbNetworkConfig.numSynNet; }
664 
665  int getRandSeed() { return randSeed_; }
666 
667  int getSimTime() { return simTime; }
668  int getSimTimeSec() { return simTimeSec; }
669  int getSimTimeMs() { return simTimeMs; }
670 
672  SpikeMonitor* getSpikeMonitor(int grpId);
673 
677 
679  NeuronMonitor* getNeuronMonitor(int grpId);
680 
684 
686  float* getCurrent() { return managerRuntimeData.current; }
687 
688  std::vector< std::vector<float> > getWeightMatrix2D(short int connId);
689 
690  std::vector<float> getConductanceAMPA(int grpId);
691  std::vector<float> getConductanceNMDA(int grpId);
692  std::vector<float> getConductanceGABAa(int grpId);
693  std::vector<float> getConductanceGABAb(int grpId);
694 
696  float* getSTPu() { return managerRuntimeData.stpu; }
697 
699  float* getSTPx() { return managerRuntimeData.stpx; }
700 
702  bool isConnectionPlastic(short int connId);
703 
705  RangeWeight getWeightRange(short int connId);
706 
707  bool isExcitatoryGroup(int gGrpId) { return (groupConfigMap[gGrpId].type & TARGET_AMPA) || (groupConfigMap[gGrpId].type & TARGET_NMDA); }
708  bool isInhibitoryGroup(int gGrpId) { return (groupConfigMap[gGrpId].type & TARGET_GABAa) || (groupConfigMap[gGrpId].type & TARGET_GABAb); }
709  bool isPoissonGroup(int gGrpId) { return (groupConfigMap[gGrpId].type & POISSON_NEURON); }
710  bool isDopaminergicGroup(int gGrpId) { return (groupConfigMap[gGrpId].type & TARGET_DA); }
711  // LN2021 \todo LN
712 
714  bool isGroupWithHomeostasis(int grpId);
715 
716 #ifdef LN_I_CALC_TYPES
717  bool isGroupWith(int grpId, IcalcType icalcType) { return groupConfigMap[grpId].icalcType == icalcType; };
719  bool isGroupWithCOBA(int grpId) { return isGroupWith(grpId, COBA); };
720  bool isGroupWithCUBA(int grpId) { return isGroupWith(grpId, CUBA); };
721  bool isGroupWithNMDARise(int grpId) { return false; };
722  bool isGroupWithGABAbRise(int grpId) { return false; };
723 
724  IcalcType getIcalcType(int grpId) { return groupConfigMap[grpId].icalcType; };
725 
726  // factors
727  void getConductanceConfig(int grpId, float &dAMPA, float &rNMDA, float &dNMDA, float &dGABAa, float &rGABAb, float &dGABAb) {
728  auto config = groupConfigMap[grpId].conductanceConfig;
729  dAMPA = config.dAMPA;
730  rNMDA = config.rNMDA;
731  dNMDA = config.dNMDA;
732  dGABAa = config.dGABAa;
733  rGABAb = config.rGABAb;
734  dGABAb = config.dGABAb;
735  };
736 
737  // times
738  void getConductanceConfig(int grpId, int& tdAMPA, int& trNMDA, int& tdNMDA, int& tdGABAa, int& trGABAb, int& tdGABAb) {
739 
741  //double d = 1.0 / (1.0 - 0.833333313);
742  //float f = 1.0f / (1.0f - 0.833333313f);
743  //int i = std::round<int>(f);
744 
745  // \todo LN ensure at set that float does not goes below min precision
746 
747  auto config = groupConfigMap[grpId].conductanceConfig;
748  tdAMPA = round(1.0f / (1.0f - config.dAMPA));
749  trNMDA = abs(config.rNMDA) < 0.000001f ? 0 : round(1.0f / (1.0f - config.rNMDA));
750  tdNMDA = round(1.0f / (1.0f - config.dNMDA));
751  tdGABAa = round(1.0f / (1.0f - config.dGABAa));
752  trGABAb = abs(config.rGABAb) < 0.000001f ? 0 : round(1.0f / (1.0f - config.rGABAb));
753  tdGABAb = round(1.0f / (1.0f - config.dGABAb));
754  };
755 #endif
756 
758  double getRFDist3D(const RadiusRF& radius, const Point3D& pre, const Point3D& post);
759  bool isPoint3DinRF(const RadiusRF& radius, const Point3D& pre, const Point3D& post);
760 
761  bool isSimulationWithCompartments() { return sim_with_compartments; }
762 #define LN_I_CALC_TYPES__REQUIRED_FOR_NETWORK_LEVEL
763  bool isSimulationWithCOBA() { return sim_with_conductances; }
764  bool isSimulationWithCUBA() { return !sim_with_conductances; }
765  bool isSimulationWithNMDARise() { return sim_with_NMDA_rise; }
766  bool isSimulationWithGABAbRise() { return sim_with_GABAb_rise; }
767  bool isSimulationWithFixedWeightsOnly() { return sim_with_fixedwts; }
768  bool isSimulationWithHomeostasis() { return sim_with_homeostasis; }
769  bool isSimulationWithPlasticWeights() { return !sim_with_fixedwts; }
770  bool isSimulationWithSTDP() { return sim_with_stdp; }
771  bool isSimulationWithSTP() { return sim_with_stp; }
772 
773 
775 #ifndef __NO_CUDA__
776  // GPU backend: utility function
777  static int cudaDeviceCount();
778  static void cudaDeviceDescription(unsigned ithGPU, const char **desc);
779 #else
780  static int cudaDeviceCount() { return 0; }
781  static void cuda_device_description(unsigned , const char **) {};
782 #endif
783 
784 
785 
786  // **************************************************************************************************************** //
787  // PRIVATE METHODS
788  // **************************************************************************************************************** //
789 
790 private:
792  void SNNinit();
793 
795  void advSimStep();
796 
798  void allocateManagerRuntimeData();
799 
800  int assignGroup(int gGrpId, int availableNeuronId);
801  int assignGroup(std::list<GroupConfigMD>::iterator grpIt, int localGroupId, int availableNeuronId);
802  void generateGroupRuntime(int netId, int lGrpId);
803  void generatePoissonGroupRuntime(int netId, int lGrpId);
804  void generateConnectionRuntime(int netId);
805  void generateCompConnectionRuntime(int netId);
806 
810  void generateRuntimeNetworkConfigs();
811  void generateRuntimeGroupConfigs();
812  void generateRuntimeConnectConfigs();
813 
817  void collectGlobalNetworkConfigC();
818  void compileConnectConfig();
819  void compileGroupConfig();
820 
821  void collectGlobalNetworkConfigP();
822 
826  void connectNetwork();
827  inline void connectNeurons(int netId, int srcGrp, int destGrp, int srcN, int destN, short int connId, int externalNetId);
828  inline void connectNeurons(int netId, int _grpSrc, int _grpDest, int _nSrc, int _nDest, short int _connId, float initWt, float maxWt, uint8_t delay, int externalNetId);
829  void connectFull(int netId, std::list<ConnectConfig>::iterator connIt, bool isExternal);
830  void connectOneToOne(int netId, std::list<ConnectConfig>::iterator connIt, bool isExternal);
831  void connectRandom(int netId, std::list<ConnectConfig>::iterator connIt, bool isExternal);
832  void connectGaussian(int netId, std::list<ConnectConfig>::iterator connIt, bool isExternal);
833  void connectUserDefined(int netId, std::list<ConnectConfig>::iterator connIt, bool isExternal);
834 
835 #ifdef LN_SETUP_NETWORK_MT
836  void connectNetworkMT();
837  inline void connectNeuronsMT(std::mutex &mtx, int netId, int srcGrp, int destGrp, int srcN, int destN, short int connId, int externalNetId);
838  void connectRandomMT(int netId, std::list<ConnectConfig>::iterator connIt, bool isExternal);
839 #endif
840 
841  void deleteObjects();
842 
843  void findMaxNumSynapsesGroups(int* _maxNumPostSynGrp, int* _maxNumPreSynGrp);
844  void findMaxNumSynapsesNeurons(int _netId, int& _maxNumPostSynN, int& _maxNumPreSynN);
845  void findMaxSpikesD1D2(int netId, unsigned int& _maxSpikesD1, unsigned int& _maxSpikesD2);
846  void findNumSynapsesNetwork(int netId, int& _numPostSynNet, int& _numPreSynNet);
847  void findNumN(int _netId, int& _numN, int& _nunNExternal, int& numNAssigned,
848  int& _numNReg, int& _numNExcReg, int& _numNInhReg,
849  int& _numNPois, int& _numNExcPois, int& _numNInhPois);
850  void findNumNSpikeGenAndOffset(int _netId);
851 
852  void generatePostSynapticSpike(int preNId, int postNId, int synId, int tD, int netId);
853  void fillSpikeGenBits(int netId);
854  void userDefinedSpikeGenerator(int gGrpId);
855 
856  float generateWeight(int connProp, float initWt, float maxWt, int nid, int grpId);
857 
859  void verifyNetwork();
860 
862  void verifySTDP();
863 
865  void verifyHomeostasis();
866 
868  void verifyCompartments();
869 
871  //void verifyNumNeurons();
872 
873  void compileSNN();
874 
875  void partitionSNN();
876  void generateRuntimeSNN();
877 
878 #ifdef LN_SETUP_NETWORK_MT
879  void partitionSNNMT(); // featFastSetup LN 20201108
880 #endif
881 
900  //int poissonSpike(int currTime, float frate, int refractPeriod);
901 
902  void printConnectionInfo(short int connId);
903  void printConnectionInfo(int netId, std::list<ConnectConfig>::iterator connIt);
904  void printGroupInfo(int grpId);
905  void printGroupInfo(int netId, std::list<GroupConfigMD>::iterator grpIt);
906  void printSimSummary();
907  void printStatusConnectionMonitor(int connId = ALL);
908  void printStatusGroupMonitor(int gGrpId = ALL);
909  void printStatusSpikeMonitor(int gGrpId = ALL);
910  void printSikeRoutingInfo();
911 
912  int loadSimulation_internal(bool onlyPlastic);
913 
914  void resetConductances(int netId);
915  void resetCurrent(int netId);
916  void resetFiringInformation();
917  void resetGroupConfigs(bool deallocate = false);
918  void resetNeuromodulator(int netId, int lGrpId);
919  void resetNeuron(int netId, int lGrpId, int lNId);
920  void resetMonitors(bool deallocate = false);
921  void resetConnectionConfigs(bool deallocate = false);
922  void deleteManagerRuntimeData();
923  void resetPoissonNeuron(int netId, int lGrpId, int lNId);
924  void resetPropogationBuffer();
925  void resetSynapse(int netId, bool changeWeights = false);
926  void resetTimeTable();
927  void resetFiringTable();
928  void routeSpikes();
929  void transferSpikes(void* dest, int destNetId, void* src, int srcNetId, int size);
930  void resetTiming();
931 
932  inline SynInfo SET_CONN_ID(int nid, int sid, int grpId);
933 
934  void setGrpTimeSlice(int grpId, int timeSlice);
935  int setRandSeed(int seed);
936 
937  void startTiming();
938  void stopTiming();
939 
940  void generateUserDefinedSpikes();
941 
942  void allocateManagerSpikeTables();
943 
944  bool updateTime();
945 
946  float getCompCurrent(int netid, int lGrpId, int lneurId, float const0 = 0.0f, float const1 = 0.0f);
947 
948  // Abstract layer for setupNetwork() and runNetwork()
949  void allocateSNN(int netId);
950  void clearExtFiringTable();
951  void convertExtSpikesD1(int netId, int startIdx, int endIdx, int GtoLOffset);
952  void convertExtSpikesD2(int netId, int startIdx, int endIdx, int GtoLOffset);
953  void doCurrentUpdate();
954  void doSTPUpdateAndDecayCond();
955  void deleteRuntimeData();
956  void findFiring();
957  void globalStateUpdate();
958  void resetSpikeCnt(int gGrpId);
959  void shiftSpikeTables();
960  void spikeGeneratorUpdate();
961  void updateTimingTable();
962  void updateWeights();
963  void updateNetworkConfig(int netId);
964 
965  // Abstract layer for trasferring data (local-to-global copy)
966  void fetchConductanceAMPA(int gGrpId);
967  void fetchConductanceNMDA(int gGrpId);
968  void fetchConductanceGABAa(int gGrpId);
969  void fetchConductanceGABAb(int gGrpId);
970  void fetchNetworkSpikeCount();
971  void fetchNeuronSpikeCount(int gGrpId);
972  void fetchSTPState(int gGrpId);
973 
974  // Abstract layer for trasferring data (local-to-local copy)
975  void fetchSpikeTables(int netId);
976  void fetchNeuronStateBuffer(int netId, int lGrpId);
977  void fetchGroupState(int netId, int lGrpId);
978  void fetchWeightState(int netId, int lGrpId);
979  void fetchGrpIdsLookupArray(int netId);
980  void fetchConnIdsLookupArray(int netId);
981  void fetchLastSpikeTime(int netId);
982  void fetchCurSpike(int netId);
983  void fetchRandNum(int netId);
984  void fetchPoissonFireRate(int netId);
985  void fetchSpikeGenBits(int netId);
986  void fetchPreConnectionInfo(int netId);
987  void fetchPostConnectionInfo(int netId);
988  void fetchSynapseState(int netId);
989  void fetchExtFiringTable(int netId);
990  void fetchTimeTable(int netId);
991  void writeBackTimeTable(int netId);
992 
993 #ifndef __NO_CUDA__
994  // GPU implementation for setupNetwork() and runNetwork()
995  void allocateSNN_GPU(int netId);
996  void assignPoissonFiringRate_GPU(int netId);
997  void clearExtFiringTable_GPU(int netId);
998  void convertExtSpikesD1_GPU(int netId, int startIdx, int endIdx, int GtoLOffset);
999  void convertExtSpikesD2_GPU(int netId, int startIdx, int endIdx, int GtoLOffset);
1000  void doCurrentUpdateD1_GPU(int netId);
1001  void doCurrentUpdateD2_GPU(int netId);
1002  void doSTPUpdateAndDecayCond_GPU(int netId);
1003  void deleteRuntimeData_GPU(int netId);
1004  void findFiring_GPU(int netId);
1005  void globalStateUpdate_C_GPU(int netId);
1006  void globalStateUpdate_N_GPU(int netId);
1007  void globalStateUpdate_G_GPU(int netId);
1008  void resetSpikeCnt_GPU(int netId, int lGrpId);
1009  void shiftSpikeTables_F_GPU(int netId);
1010  void shiftSpikeTables_T_GPU(int netId);
1011  void spikeGeneratorUpdate_GPU(int netId);
1012  void updateTimingTable_GPU(int netId);
1013  void updateWeights_GPU(int netId);
1014 #else
1015  void allocateSNN_GPU(int netId) { assert(false); }
1016  void assignPoissonFiringRate_GPU(int netId) { assert(false); }
1017  void clearExtFiringTable_GPU(int netId) { assert(false); }
1018  void convertExtSpikesD1_GPU(int netId, int startIdx, int endIdx, int GtoLOffset) { assert(false); }
1019  void convertExtSpikesD2_GPU(int netId, int startIdx, int endIdx, int GtoLOffset) { assert(false); }
1020  void doCurrentUpdateD1_GPU(int netId) { assert(false); }
1021  void doCurrentUpdateD2_GPU(int netId) { assert(false); }
1022  void doSTPUpdateAndDecayCond_GPU(int netId) { assert(false); }
1023  void deleteRuntimeData_GPU(int netId) { assert(false); }
1024  void findFiring_GPU(int netId) { assert(false); }
1025  void globalStateUpdate_C_GPU(int netId) { assert(false); }
1026  void globalStateUpdate_N_GPU(int netId) { assert(false); }
1027  void globalStateUpdate_G_GPU(int netId) { assert(false); }
1028  void resetSpikeCnt_GPU(int netId, int lGrpId) { assert(false); }
1029  void shiftSpikeTables_F_GPU(int netId) { assert(false); }
1030  void shiftSpikeTables_T_GPU(int netId) { assert(false); }
1031  void spikeGeneratorUpdate_GPU(int netId) { assert(false); }
1032  void updateTimingTable_GPU(int netId) { assert(false); }
1033  void updateWeights_GPU(int netId) { assert(false); }
1034 #endif
1035 
1036 #ifndef __NO_CUDA__
1037  // GPU backend: utility function
1038  void allocateGroupId(int netId);
1039  int allocateStaticLoad(int netId, int bufSize);
1040  void checkAndSetGPUDevice(int netId);
1041  void checkDestSrcPtrs(RuntimeData* dest, RuntimeData* src, cudaMemcpyKind kind, bool allocateMem, int grpId, int destOffset);
1042  int configGPUDevice();
1043  void initGPU(int netId);
1044 #else
1045  //int configGPUDevice() { return 0; }
1046 #endif
1047 
1048 #ifndef __NO_CUDA__
1049  // GPU backend: data transfer functions
1050  void copyAuxiliaryData(int netId, int lGrpId, RuntimeData* dest, cudaMemcpyKind kind, bool allocateMem);
1051  void copyConductanceAMPA(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, cudaMemcpyKind kind, bool allocateMem, int destOffset);
1052  void copyConductanceNMDA(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, cudaMemcpyKind kind, bool allocateMem, int destOffset);
1053  void copyConductanceGABAa(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, cudaMemcpyKind kind, bool allocateMem, int destOffset);
1054  void copyConductanceGABAb(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, cudaMemcpyKind kind, bool allocateMem, int destOffset);
1055  void copyPreConnectionInfo(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, cudaMemcpyKind kind, bool allocateMem);
1056  void copyPostConnectionInfo(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, cudaMemcpyKind kind, bool allocateMem);
1057  void copyExternalCurrent(int netId, int lGrpId, RuntimeData* dest, cudaMemcpyKind kind, bool allocateMem);
1058  void copyNeuronParameters(int netId, int lGrpId, RuntimeData* dest, cudaMemcpyKind kind, bool allocateMem);
1059  void copyGroupState(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, cudaMemcpyKind kind, bool allocateMem);
1060  void copyNeuronState(int netId, int lGrpId, RuntimeData* dest, cudaMemcpyKind kind, bool allocateMem);
1061  void copyNeuronStateBuffer(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, cudaMemcpyKind kind, bool allocateMem);
1062  void copyNeuronSpikeCount(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, cudaMemcpyKind kind, bool allocateMem, int destOffset);
1063  void copySynapseState(int netId, RuntimeData* dest, RuntimeData* src, cudaMemcpyKind kind, bool allocateMem);
1064  void copySTPState(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, cudaMemcpyKind kind, bool allocateMem);
1065  void copyWeightState(int netId, int lGrpId, cudaMemcpyKind kind);
1066  void copyNetworkConfig(int netId, cudaMemcpyKind kind);
1067  void copyGroupConfigs(int netId);
1068  void copyConnectConfigs(int netId);
1069  void copyGrpIdsLookupArray(int netId, cudaMemcpyKind kind);
1070  void copyConnIdsLookupArray(int netId, cudaMemcpyKind kind);
1071  void copyLastSpikeTime(int netId, cudaMemcpyKind kind);
1072  void copyCurSpikes(int netId, cudaMemcpyKind kind); // LN20201101 featSpikes
1073  void copyRandNum(int netId, cudaMemcpyKind kind); // LN20201101 featSpikes
1074  void copyPoissonFireRate(int netId, cudaMemcpyKind kind); // LN20201102 featSpikes
1075  void copySpikeGenBits(int netId, cudaMemcpyKind kind); // LN20201101 featSpikes
1076  void copyNetworkSpikeCount(int netId, cudaMemcpyKind kind,
1077  unsigned int* spikeCountD1, unsigned int* spikeCountD2,
1078  unsigned int* spikeCountExtD1, unsigned int* spikeCountExtD2);
1079  void copySpikeTables(int netId, cudaMemcpyKind kind);
1080  void copyTimeTable(int netId, cudaMemcpyKind kind);
1081  void copyExtFiringTable(int netId, cudaMemcpyKind kind);
1082 #else
1083  #define cudaMemcpyKind int
1084  #define cudaMemcpyHostToHost 0
1085  #define cudaMemcpyHostToDevice 0
1086  #define cudaMemcpyDeviceToHost 0
1087  #define cudaMemcpyDeviceToDevice 0
1088  #define cudaMemcpyDefault 0
1089 
1090  void copyAuxiliaryData(int netId, int lGrpId, RuntimeData* dest, cudaMemcpyKind kind, bool allocateMem) { assert(false); }
1091  void copyConductanceAMPA(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, cudaMemcpyKind kind, bool allocateMem, int destOffset) { assert(false); }
1092  void copyConductanceNMDA(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, cudaMemcpyKind kind, bool allocateMem, int destOffset) { assert(false); }
1093  void copyConductanceGABAa(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, cudaMemcpyKind kind, bool allocateMem, int destOffset) { assert(false); }
1094  void copyConductanceGABAb(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, cudaMemcpyKind kind, bool allocateMem, int destOffset) { assert(false); }
1095  void copyPreConnectionInfo(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, cudaMemcpyKind kind, bool allocateMem) { assert(false); }
1096  void copyPostConnectionInfo(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, cudaMemcpyKind kind, bool allocateMem) { assert(false); }
1097  void copyExternalCurrent(int netId, int lGrpId, RuntimeData* dest, cudaMemcpyKind kind, bool allocateMem) { assert(false); }
1098  void copyNeuronParameters(int netId, int lGrpId, RuntimeData* dest, cudaMemcpyKind kind, bool allocateMem) { assert(false); }
1099  void copyGroupState(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, cudaMemcpyKind kind, bool allocateMem) { assert(false); }
1100  void copyNeuronState(int netId, int lGrpId, RuntimeData* dest, cudaMemcpyKind kind, bool allocateMem) { assert(false); }
1101  void copyNeuronStateBuffer(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, cudaMemcpyKind kind, bool allocateMem) { assert(false); }
1102  void copyNeuronSpikeCount(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, cudaMemcpyKind kind, bool allocateMem, int destOffset) { assert(false); }
1103  void copySynapseState(int netId, RuntimeData* dest, RuntimeData* src, cudaMemcpyKind kind, bool allocateMem) { assert(false); }
1104  void copySTPState(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, cudaMemcpyKind kind, bool allocateMem) { assert(false); }
1105  void copyWeightState(int netId, int lGrpId, cudaMemcpyKind kind) { assert(false); }
1106  void copyNetworkConfig(int netId, cudaMemcpyKind kind) { assert(false); }
1107  void copyGroupConfigs(int netId) { assert(false); }
1108  void copyGrpIdsLookupArray(int netId, cudaMemcpyKind kind) { assert(false); }
1109  void copyConnIdsLookupArray(int netId, cudaMemcpyKind kind) { assert(false); }
1110  void copyLastSpikeTime(int netId, cudaMemcpyKind kind) { assert(false); }
1111  void copyCurSpikes(int netId, cudaMemcpyKind kind) { assert(false); } // LN20201101 featSpikes
1112  void copyPoissonFireRate(int netId, cudaMemcpyKind kind) { assert(false); } // LN20201102 featSpikes
1113  void copyRandNum(int netId, cudaMemcpyKind kind) { assert(false); } // LN20201101 featSpikes
1114  void copySpikeGenBits(int netId, cudaMemcpyKind kind) { assert(false); } // LN20201101 featSpikes
1115  void copyNetworkSpikeCount(int netId, cudaMemcpyKind kind,
1116  unsigned int* spikeCountD1, unsigned int* spikeCountD2,
1117  unsigned int* spikeCountExtD1, unsigned int* spikeCountExtD2) { assert(false); }
1118  void copySpikeTables(int netId, cudaMemcpyKind kind) { assert(false); }
1119  void copyTimeTable(int netId, cudaMemcpyKind kind) { assert(false); }
1120  void copyExtFiringTable(int netId, cudaMemcpyKind kind) { assert(false); }
1121 #endif
1122 
1123  // CPU implementation for setupNetwork() and runNetwork()
1124 
1125  //allocates runtime data on CPU memory
1126  void allocateSNN_CPU(int netId);
1127 
1128  // runNetwork functions - multithreaded in LINUX using pthreads
1129 #ifdef __NO_PTHREADS__
1130  void assignPoissonFiringRate_CPU(int netId);
1131  void clearExtFiringTable_CPU(int netId);
1132  void convertExtSpikesD2_CPU(int netId, int startIdx, int endIdx, int GtoLOffset);
1133  void convertExtSpikesD1_CPU(int netId, int startIdx, int endIdx, int GtoLOffset);
1134  void doCurrentUpdateD2_CPU(int netId);
1135  void doCurrentUpdateD1_CPU(int netId);
1136  void doSTPUpdateAndDecayCond_CPU(int netId);
1137  void deleteRuntimeData_CPU(int netId);
1138  void findFiring_CPU(int netId);
1139  void globalStateUpdate_CPU(int netId);
1140  void resetSpikeCnt_CPU(int netId, int lGrpId);
1141  void shiftSpikeTables_CPU(int netId);
1142  void spikeGeneratorUpdate_CPU(int netId);
1143  void updateTimingTable_CPU(int netId);
1144  void updateWeights_CPU(int netId);
1145 #else // for APPLE and Win systems - returns a void* to pthread_create - only differ in the return type compared to the counterparts above
1146  void* assignPoissonFiringRate_CPU(int netId);
1147  void* clearExtFiringTable_CPU(int netId);
1148  void* convertExtSpikesD2_CPU(int netId, int startIdx, int endIdx, int GtoLOffset);
1149  void* convertExtSpikesD1_CPU(int netId, int startIdx, int endIdx, int GtoLOffset);
1150  void* doCurrentUpdateD2_CPU(int netId);
1151  void* doCurrentUpdateD1_CPU(int netId);
1152  void* doSTPUpdateAndDecayCond_CPU(int netId);
1153  void* deleteRuntimeData_CPU(int netId);
1154  void* findFiring_CPU(int netId);
1155  void* globalStateUpdate_CPU(int netId);
1156  void* resetSpikeCnt_CPU(int netId, int lGrpId);
1157  void* shiftSpikeTables_CPU(int netId);
1158  void* spikeGeneratorUpdate_CPU(int netId);
1159  void* updateTimingTable_CPU(int netId);
1160  void* updateWeights_CPU(int netId);
1161 
1162  // static multithreading helper methods for the above CPU runNetwork() methods
1163  static void* helperAssignPoissonFiringRate_CPU(void*);
1164  static void* helperClearExtFiringTable_CPU(void*);
1165  static void* helperConvertExtSpikesD2_CPU(void*);
1166  static void* helperConvertExtSpikesD1_CPU(void*);
1167  static void* helperDoCurrentUpdateD2_CPU(void*);
1168  static void* helperDoCurrentUpdateD1_CPU(void*);
1169  static void* helperDoSTPUpdateAndDecayCond_CPU(void*);
1170  static void* helperDeleteRuntimeData_CPU(void*);
1171  static void* helperFindFiring_CPU(void*);
1172  static void* helperGlobalStateUpdate_CPU(void*);
1173  static void* helperResetSpikeCnt_CPU(void*);
1174  static void* helperShiftSpikeTables_CPU(void*);
1175  static void* helperSpikeGeneratorUpdate_CPU(void*);
1176  static void* helperUpdateTimingTable_CPU(void*);
1177  static void* helperUpdateWeights_CPU(void*);
1178 #endif
1179 
1180  // CPU computing backend: data transfer function
1181  void copyAuxiliaryData(int netId, int lGrpId, RuntimeData* dest, bool allocateMem);
1182  void copyConductanceAMPA(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, bool allocateMem, int destOffset);
1183  void copyConductanceNMDA(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, bool allocateMem, int destOffset);
1184  void copyConductanceGABAa(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, bool allocateMem, int destOffset);
1185  void copyConductanceGABAb(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, bool allocateMem, int destOffset);
1186  void copyPreConnectionInfo(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, bool allocateMem);
1187  void copyPostConnectionInfo(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, bool allocateMem);
1188  void copyExternalCurrent(int netId, int lGrpId, RuntimeData* dest, bool allocateMem);
1189  void copyNeuronParameters(int netId, int lGrpId, RuntimeData* dest, bool allocateMem);
1190  void copyGroupState(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, bool allocateMem);
1191  void copyNeuronStateBuffer(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, bool allocateMem);
1192  void copyNeuronState(int netId, int lGrpId, RuntimeData* dest, bool allocateMem);
1193  void copyNeuronSpikeCount(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, bool allocateMem, int destOffset);
1194  void copySynapseState(int netId, RuntimeData* dest, RuntimeData* src, bool allocateMem);
1195  void copySTPState(int netId, int lGrpId, RuntimeData* dest, RuntimeData* src, bool allocateMem);
1196  void copyWeightState(int netId, int lGrpId);
1197  void copyNetworkConfig(int netId);
1198  void copyGrpIdsLookupArray(int netId);
1199  void copyConnIdsLookupArray(int netId);
1200  void copyLastSpikeTime(int netId);
1201  void copyCurSpikes(int netId); // LN20201101 featSpikes
1202  void copyRandNum(int netId); // LN20201101 featSpikes
1203  void copyPoissonFireRate(int netId); // LN20201102 featSpikes
1204  void copySpikeGenBits(int netId); // LN20201101 featSpikes
1205  void copyNetworkSpikeCount(int netId,
1206  unsigned int* spikeCountD1, unsigned int* spikeCountD2,
1207  unsigned int* spikeCountExtD1, unsigned int* spikeCountExtD2);
1208  void copySpikeTables(int netId);
1209  void copyTimeTable(int netId, bool toManager);
1210  void copyExtFiringTable(int netId);
1211 
1212  // CPU backend: utility function
1213  void firingUpdateSTP(int lNId, int lGrpId, int netId);
1214  void updateLTP(int lNId, int lGrpId, int netId);
1215  void resetFiredNeuron(int lNId, short int lGrpId, int netId);
1216  bool getPoissonSpike(int lNId, int netId);
1217  bool getSpikeGenBit(unsigned int nIdPos, int netId);
1218 
1219 
1220 #ifdef LN_AXON_PLAST
1221  void findWavefrontPath_CPU(std::vector<int>& path, std::vector<float>& eligibility, int netId, int grpId, int startNId, int goalNId);
1222  bool updateDelays_CPU(int netId, int lGrpIdPre, int lGrpIdPost, std::vector<std::tuple<int, int, uint8_t>> connDelays);
1223  void printEntrails_CPU(char* buffer, unsigned length, int netId, int lGrpIdPre, int lGrpIdPost);
1224 #ifndef __NO_CUDA__
1225  bool updateDelays_GPU(int netId, int lGrpIdPre, int lGrpIdPost, std::vector<std::tuple<int, int, uint8_t>> connDelays);
1226  void printEntrails_GPU(int netId, int lGrpIdPre, int lGrpIdPost);
1227  void printEntrails_GPU(char* buffer, unsigned length, int netId, int lGrpIdPre, int lGrpIdPost);
1228 #else
1229  bool updateDelays_GPU(int netId, int lGrpIdPre, int lGrpIdPost, std::vector<std::tuple<int, int, uint8_t>> connDelays) { assert(false); }
1230  void printEntrails_GPU(int netId, int lGrpIdPre, int lGrpIdPost) { assert(false); }
1231  void printEntrails_GPU(char* buffer, unsigned length, int netId, int lGrpIdPre, int lGrpIdPost) { assert(false); }
1232 #endif
1233 
1234 #endif
1235 
1236  // +++++ PRIVATE PROPERTIES +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
1237  SNNState snnState;
1238  FILE* loadSimFID;
1239 
1240  const std::string networkName_;
1241  const LoggerMode loggerMode_;
1242  const SimMode preferredSimMode_;
1243  const int randSeed_;
1244 
1245  int numGPUs;
1246  int numCores;
1247 
1248  int numAvailableGPUs;
1249 
1250  bool simulatorDeleted;
1251  bool spikeRateUpdated;
1252 
1254  bool sim_in_testing;
1255 
1256  int numGroups;
1257  int numConnections;
1258  int numCompartmentConnections;
1259 
1260  std::map<int, GroupConfig> groupConfigMap;
1261  std::map<int, GroupConfigMD> groupConfigMDMap;
1262  std::map<int, ConnectConfig> connectConfigMap;
1263  std::map<int, compConnectConfig> compConnectConfigMap;
1264 
1265  // data structure assisting network partitioning
1266  std::list<GroupConfigMD> groupPartitionLists[MAX_NET_PER_SNN];
1267  std::list<ConnectConfig> localConnectLists[MAX_NET_PER_SNN];
1268  std::list<ConnectConfig> externalConnectLists[MAX_NET_PER_SNN];
1269  std::list<compConnectConfig> localCompConnectLists[MAX_NET_PER_SNN];
1270 
1271 
1272 #ifdef LN_FIX_CONNLIST_
1273  std::vector<ConnectionInfo> connectionLists[MAX_NET_PER_SNN];
1274 #else
1275  std::list<ConnectionInfo> connectionLists[MAX_NET_PER_SNN];
1276 #endif
1277  std::list<RoutingTableEntry> spikeRoutingTable;
1278 
1279  float *mulSynFast;
1280  float *mulSynSlow;
1281 
1283  SpikeBuffer* spikeBuf;
1284 
1285 #define LN_I_CALC_TYPES__REQUIRED_FOR_NETWORK_LEVEL
1286  bool sim_with_conductances;
1287  bool sim_with_NMDA_rise;
1288  bool sim_with_GABAb_rise;
1289 #define LN_I_CALC_TYPES__REQUIRED_FOR_BACKWARD_COMPAT
1290  double dAMPA;
1291  double rNMDA;
1292  double dNMDA;
1293  double sNMDA;
1294  double dGABAa;
1295  double rGABAb;
1296  double dGABAb;
1297  double sGABAb;
1298 
1299  bool sim_with_compartments;
1300  bool sim_with_fixedwts;
1301  bool sim_with_stdp;
1302  bool sim_with_modulated_stdp;
1303  bool sim_with_homeostasis;
1304  bool sim_with_stp;
1305  bool sim_with_spikecounters;
1306 
1307  GlobalNetworkConfig glbNetworkConfig;
1308 
1309  //time and timestep
1310  int simTimeRunStart;
1311  int simTimeRunStop;
1312  int simTimeLastRunSummary;
1313  int simTimeMs;
1314  int simTimeSec;
1315  int simTime;
1316 
1318 #ifndef __NO_CUDA__
1319  StopWatchInterface* timer;
1320 #endif
1321  float cumExecutionTime;
1322  float lastExecutionTime;
1323  float prevExecutionTime;
1324  float executionTime;
1325 
1326  FILE* fpInf_;
1327  FILE* fpErr_;
1328  FILE* fpDeb_;
1329  FILE* fpLog_;
1330 
1331  // keep track of number of SpikeMonitor/SpikeMonitorCore objects
1332  int numSpikeMonitor;
1333  SpikeMonitorCore* spikeMonCoreList[MAX_GRP_PER_SNN];
1334  SpikeMonitor* spikeMonList[MAX_GRP_PER_SNN];
1335 
1336  // neuron monitor variables
1337  int numNeuronMonitor;
1338  NeuronMonitor* neuronMonList[MAX_GRP_PER_SNN];
1339  NeuronMonitorCore* neuronMonCoreList[MAX_GRP_PER_SNN];
1340 
1341  // \FIXME \DEPRECATED this one moved to group-based
1342  long int simTimeLastUpdSpkMon_;
1343 
1344  int numSpikeGenGrps;
1345 
1346  // keep track of number of GroupMonitor/GroupMonitorCore objects
1347  int numGroupMonitor;
1348  GroupMonitorCore* groupMonCoreList[MAX_GRP_PER_SNN];
1349  GroupMonitor* groupMonList[MAX_GRP_PER_SNN];
1350 
1351  // neuron monitor variables
1352  //NeuronMonitorCore* neurBufferCallback[MAX_]
1353  //int numNeuronMonitor;
1354 
1355  // connection monitor variables
1356  int numConnectionMonitor;
1357  ConnectionMonitorCore* connMonCoreList[MAX_CONN_PER_SNN];
1358  ConnectionMonitor* connMonList[MAX_CONN_PER_SNN];
1359 
1360  RuntimeData runtimeData[MAX_NET_PER_SNN];
1361  RuntimeData managerRuntimeData;
1362 
1363  typedef struct ManagerRuntimeDataSize_s {
1364  unsigned int maxMaxSpikeD1;
1365  unsigned int maxMaxSpikeD2;
1366  int maxNumN;
1367  int maxNumNReg;
1368  int maxNumNSpikeGen;
1369  int maxNumNPois;
1370  int maxNumNAssigned;
1371  int maxNumGroups;
1372  int maxNumConnections;
1373  int maxNumPostSynNet;
1374  int maxNumPreSynNet;
1375  int maxNumNPerGroup;
1376  int glbNumN;
1377  int glbNumNReg;
1378  } ManagerRuntimeDataSize;
1379 
1380  ManagerRuntimeDataSize managerRTDSize;
1381 
1382  // runtime configurations
1383  NetworkConfigRT networkConfigs[MAX_NET_PER_SNN];
1386 
1387  // weight update parameter
1388  int wtANDwtChangeUpdateInterval_;
1389  int wtANDwtChangeUpdateIntervalCnt_;
1390  float stdpScaleFactor_;
1391  float wtChangeDecay_;
1392 };
1393 
1394 #endif
Class for generating Poisson spike trains.
Definition: poisson_rate.h:88
static int cudaDeviceCount()
Get Info of suitable Harware for integration of CARLsim in NeuroInf-IDEs NIIDEs (LN20201017) ...
void setNeuronParametersLIF(int grpId, int tau_m, int tau_ref, float vTh, float vReset, double minRmem, double maxRmem)
Sets neuron parameters for a group of LIF spiking neurons.
SNNState
the state of spiking neural network, used with in kernel.
bool isPoissonGroup(int gGrpId)
Definition: snn.h:709
float * getCurrent()
temporary getter to return pointer to current[]
Definition: snn.h:686
bool isSimulationWithGABAbRise()
Definition: snn.h:766
int createGroupLIF(const std::string &grpName, const Grid3D &grid, int neurType, int preferredPartition, ComputingBackend preferredBackend)
Creates a group of LIF spiking neurons.
RangeDelay getDelayRange(short int connId)
returns the RangeDelay struct of a connection
int getNumNeuronsGen()
Definition: snn.h:660
void findWavefrontPath(std::vector< int > &path, std::vector< float > &eligibility, int netId, int grpId, int startNId, int goalNId)
A struct for retrieving STDP related information of a connection.
NeuronMonitor * getNeuronMonitor(int grpId)
Returns pointer to existing NeuronMonitor object, NULL else.
void updateGroupMonitor(int grpId=ALL)
access group status (currently the concentration of neuromodulator)
float * getSTPx()
temporary getter to return pointer to stpx[]
Definition: snn.h:699
#define ALL
CARLsim common definitions.
void getConductanceConfig(int grpId, float &dAMPA, float &rNMDA, float &dNMDA, float &dGABAa, float &rGABAb, float &dGABAb)
Definition: snn.h:727
int getSimTimeSec()
Definition: snn.h:668
static void cudaDeviceDescription(unsigned ithGPU, const char **desc)
void setNM4weighted(int grpId, IcalcType type, float wDA, float w5HT, float wACh, float wNE, float wNorm, float wBase)
GroupNeuromodulatorInfo getGroupNeuromodulatorInfo(int grpId)
int getNumGroups()
Definition: snn.h:655
int getRandSeed()
Definition: snn.h:665
bool isGroupWithCUBA(int grpId)
Definition: snn.h:720
void setISTDP(int preGrpId, int postGrpId, bool isSet, STDPType type, STDPCurve curve, float ab1, float ab2, float tau1, float tau2)
Set the inhibitory spike-timing-dependent plasticity (STDP) with anti-hebbian curve for a neuron grou...
ConnectionMonitor * setConnectionMonitor(int grpIdPre, int grpIdPost, FILE *fid)
sets up a network monitor registered with a callback to process the spikes.
UpdateInterval
Update frequency for weights.
bool isGroupWithCOBA(int grpId)
Definition: snn.h:719
int getNumNeuronsGenExc()
Definition: snn.h:661
int getNumNeuronsReg()
Definition: snn.h:657
int numSynNet
number of total synaptic connections in the global network
void setNeuromodulator(int grpId, float baseDP, float tauDP, float base5HT, float tau5HT, float baseACh, float tauACh, float baseNE, float tauNE)
Sets baseline concentration and decay time constant of neuromodulators (DP, 5HT, ACh, NE) for a neuron group.
std::vector< float > getConductanceNMDA(int grpId)
void setNM4STP(int grpId, float wSTP_U[], float wSTP_tau_u[], float wSTP_tau_x[])
bool updateDelays(int gGrpIdPre, int gGrpIdPost, std::vector< std::tuple< int, int, uint8_t >> connDelays)
void startTesting(bool shallUpdateWeights=true)
enters a testing phase, where all weight updates are disabled
NeuronMonitorCore * getNeuronMonitorCore(int grpId)
bool isGroupWithHomeostasis(int grpId)
returns whether group has homeostasis enabled (true) or not (false)
void exitSimulation(int val=1)
deallocates all dynamical structures and exits
#define MAX_GRP_PER_SNN
a point in 3D space
std::vector< float > getConductanceGABAb(int grpId)
int getNumNeurons()
Definition: snn.h:656
STDPType
STDP flavors.
void scaleWeights(short int connId, float scale, bool updateWeightRange=false)
Class SpikeMonitor.
void printEntrails(char *buffer, unsigned length, int gGrpIdPre, int gGrpIdPost)
LoggerMode getLoggerMode()
Definition: snn.h:636
LoggerMode
Logger modes.
int createGroup(const std::string &grpName, const Grid3D &grid, int neurType, int preferredPartition, ComputingBackend preferredBackend)
Creates a group of Izhikevich spiking neurons.
used for relaying callback to ConnectionGenerator
Definition: callback_core.h:91
void updateNeuronMonitor(int grpId=ALL)
copy required neuron state values from ??? buffer to ??? buffer
bool isExcitatoryGroup(int gGrpId)
Definition: snn.h:707
GroupMonitor * setGroupMonitor(int grpId, FILE *fid, int mode=0)
sets up a group monitor registered with a callback to process the spikes.
bool isGroupWith(int grpId, IcalcType icalcType)
Definition: snn.h:718
The configuration of a connection.
void setLogsFp(FILE *fpInf=NULL, FILE *fpErr=NULL, FILE *fpDeb=NULL, FILE *fpLog=NULL)
Sets the file pointers for all log files file pointer NULL means don&#39;t change it. ...
short int getConnectId(int grpIdPre, int grpIdPost)
find connection ID based on pre-post group pair, O(N)
bool isSimulationWithHomeostasis()
Definition: snn.h:768
Circular buffer for delivering spikes.
Definition: spike_buffer.h:67
SimMode
simulation mode
Grid3D getGroupGrid3D(int grpId)
void setupNetwork()
build the network
STDPCurve
STDP curves.
A struct to arrange neurons on a 3D grid (a primitive cubic Bravais lattice with cubic side length 1)...
static const unsigned int MAJOR_VERSION
major release version, as in CARLsim X
Definition: snn.h:161
void getConductanceConfig(int grpId, int &tdAMPA, int &trNMDA, int &tdNMDA, int &tdGABAa, int &trGABAb, int &tdGABAb)
Definition: snn.h:738
bool isSimulationWithCOBA()
Definition: snn.h:763
void saveSimulation(FILE *fid, bool saveSynapseInfo=false)
stores the pre and post synaptic neuron ids with the weight and delay
void updateConnectionMonitor(short int connId=ALL)
polls connection weights
used for relaying callback to SpikeGenerator
Definition: callback_core.h:71
SpikeMonitor * getSpikeMonitor(int grpId)
Returns pointer to existing SpikeMonitor object, NULL else.
NeuronMonitor * setNeuronMonitor(int gid, FILE *fid)
sets up a neuron monitor registered with a callback to process the neuron state values, there can only be one NeuronMonitor per group
std::string getGroupName(int grpId)
void updateSpikeMonitor(int grpId=ALL)
copy required spikes from firing buffer to spike buffer
const FILE * getLogFpLog()
returns file pointer to log file
Definition: snn.h:602
int numNPois
number of poisson neurons in the global network
int getNumNeuronsRegInh()
Definition: snn.h:659
#define TARGET_GABAb
bool isSimulationWithNMDARise()
Definition: snn.h:765
bool isGroupWithNMDARise(int grpId)
Definition: snn.h:721
#define TARGET_GABAa
int getNumCompartmentConnections()
Definition: snn.h:654
SpikeMonitorCore * getSpikeMonitorCore(int grpId)
int numNExcPois
number of excitatory poisson neurons in the global network
bool isSimulationWithPlasticWeights()
Definition: snn.h:769
bool isSimulationWithCUBA()
Definition: snn.h:764
std::string getNetworkName()
Definition: snn.h:643
double getRFDist3D(const RadiusRF &radius, const Point3D &pre, const Point3D &post)
checks whether a point pre lies in the receptive field for point post
uint8_t * getDelays(int gGrpIdPre, int gGrpIdPost, int &numPreN, int &numPostN)
Returns the delay information for all synaptic connections between a pre-synaptic and a post-synaptic...
void setSpikeRate(int grpId, PoissonRate *spikeRate, int refPeriod)
Sets the Poisson spike rate for a group. For information on how to set up spikeRate, see Section Poisson spike generators in the Tutorial.
conductance
Class GroupMonitor.
IcalcType
input current calculation
int getGroupEndNeuronId(int gGrpId)
Definition: snn.h:640
void biasWeights(short int connId, float bias, bool updateWeightRange=false)
int getNumSynapticConnections(short int connectionId)
gets number of connections associated with a connection ID
short int connect(int gIDpre, int gIDpost, const std::string &_type, float initWt, float maxWt, float prob, uint8_t minDelay, uint8_t maxDelay, RadiusRF radius, float mulSynFast, float mulSynSlow, bool synWtType)
make from each neuron in grpId1 to &#39;numPostSynapses&#39; neurons in grpId2
Definition: snn_manager.cpp:97
The runtime configuration of a connection.
integrationMethod_t
Integration methods.
void setNeuronParameters(int grpId, float izh_a, float izh_a_sd, float izh_b, float izh_b_sd, float izh_c, float izh_c_sd, float izh_d, float izh_d_sd)
Sets the Izhikevich parameters a, b, c, and d of a neuron group.
a range struct for synaptic delays
void setCompartmentParameters(int grpId, float couplingUp, float couplingDown)
Coupling constants for the compartment are set using this method.
void setHomeoBaseFiringRate(int groupId, float baseFiring, float baseFiringSD)
Sets homeostatic target firing rate (enforced through homeostatic synaptic scaling) ...
#define TARGET_DA
std::vector< float > getConductanceGABAa(int grpId)
bool isSimulationWithCompartments()
Definition: snn.h:761
SNN(const std::string &name, SimMode preferredSimMode, LoggerMode loggerMode, int randSeed)
SNN Constructor.
Definition: snn_manager.cpp:78
int runNetwork(int _nsec, int _nmsec, bool printRunSummary)
run the simulation for n sec
The runtime configuration of a group.
A struct for retrieving neuromodulator information of a group.
RangeWeight getWeightRange(short int connId)
returns RangeWeight struct of a connection
int createSpikeGeneratorGroup(const std::string &grpName, const Grid3D &grid, int neurType, int preferredPartition, ComputingBackend preferredBackend)
Creates a spike generator group (dummy-neurons, not Izhikevich spiking neurons)
Point3D getNeuronLocation3D(int neurId)
void setIntegrationMethod(integrationMethod_t method, int numStepsPerMs)
Sets the integration method and the number of integration steps per 1ms simulation time step...
int numNInhReg
number of regular inhibitory neurons in the global network
int numN
number of neurons in the global network
std::vector< float > getConductanceAMPA(int grpId)
ConnSTDPInfo getConnSTDPInfo(short int connId)
#define POISSON_NEURON
int getGroupStartNeuronId(int gGrpId)
Definition: snn.h:639
Class ConnectionMonitor.
int numNInhPois
number of inhibitory poisson neurons in the global network
int getNeuronId(int gGrpId, Point3D location)
the inverse of getNeuronLocation3D
void setExternalCurrent(int grpId, const std::vector< float > &current)
injects current (mA) into the soma of every neuron in the group
const FILE * getLogFpErr()
returns file pointer to error log
Definition: snn.h:598
a range struct for synaptic weight magnitudes
Contains all of CARLsim&#39;s core functionality.
Definition: snn.h:138
ComputingBackend
computing backend
int numNExcReg
number of regular excitatory neurons in the global network
bool isSimulationWithFixedWeightsOnly()
Definition: snn.h:767
int getSimTimeMs()
Definition: snn.h:669
void setESTDP(int preGrpId, int postGrpId, bool isSet, STDPType type, STDPCurve curve, float alphaPlus, float tauPlus, float alphaMinus, float tauMinus, float gamma)
Set the spike-timing-dependent plasticity (STDP) for a neuron group.
bool isGroupWithGABAbRise(int grpId)
Definition: snn.h:722
IcalcType getIcalcType(int grpId)
Definition: snn.h:724
void stopTesting()
exits a testing phase, making weight updates possible again
short int connectCompartments(int grpIdLower, int grpIdUpper)
void setHomeostasis(int grpId, bool isSet, float homeoScale, float avgTimeScale)
Sets the homeostasis parameters. g is the grpID, enable=true(false) enables(disables) homeostasis...
int getNumNeuronsRegExc()
Definition: snn.h:658
int getNumNeuronsGenInh()
Definition: snn.h:662
std::vector< std::vector< float > > getWeightMatrix2D(short int connId)
#define TARGET_NMDA
void setSTP(int grpId, bool isSet, float STP_U, float STP_tau_u, float STP_tau_x)
Sets STP params U, tau_u, and tau_x of a neuron group (pre-synaptically) CARLsim implements the short...
void setSpikeGenerator(int grpId, SpikeGeneratorCore *spikeGenFunc)
sets up a spike generator
bool isPoint3DinRF(const RadiusRF &radius, const Point3D &pre, const Point3D &post)
bool isSimulationWithSTP()
Definition: snn.h:771
bool isSimulationWithSTDP()
Definition: snn.h:770
int getGroupId(std::string grpName)
int getSimTime()
Definition: snn.h:667
const FILE * getLogFpDeb()
returns file pointer to debug log
Definition: snn.h:600
GroupMonitor private core implementation.
void setWeightAndWeightChangeUpdate(UpdateInterval wtANDwtChangeUpdateInterval, bool enableWtChangeDecay, float wtChangeDecay)
Sets the weight and weight change update parameters.
#define MAX_CONN_PER_SNN
runtime network configuration
int numNReg
number of regular (spking) neurons in the global network
bool isInhibitoryGroup(int gGrpId)
Definition: snn.h:708
SpikeMonitor * setSpikeMonitor(int gid, FILE *fid)
sets up a spike monitor registered with a callback to process the spikes, there can only be one Spike...
int getNumConnections()
Definition: snn.h:652
int getNumSynapses()
Definition: snn.h:663
bool isConnectionPlastic(short int connId)
returns whether synapses in connection are fixed (false) or plastic (true)
int getGroupNumNeurons(int gGrpId)
Definition: snn.h:641
void setWeight(short int connId, int neurIdPre, int neurIdPost, float weight, bool updateWeightRange=false)
sets the weight value of a specific synapse
void setConductances(bool isSet, int tdAMPA, int trNMDA, int tdNMDA, int tdGABAa, int trGABAb, int tdGABAb)
Sets custom values for conductance decay () or disables conductances alltogether These will be applie...
#define MAX_NET_PER_SNN
float * getSTPu()
temporary getter to return pointer to stpu[]
Definition: snn.h:696
void setConnectionModulation(int preGrpId, int postGrpId, IcalcType icalcType)
#define TARGET_AMPA
static const unsigned int MINOR_VERSION
minor release version, as in CARLsim 2.X
Definition: snn.h:162
void loadSimulation(FILE *fid)
bool isDopaminergicGroup(int gGrpId)
Definition: snn.h:710
ConnectConfig getConnectConfig(short int connectId)
required for homeostasis
A struct to specify the receptive field (RF) radius in 3 dimensions.
~SNN()
SNN Destructor.
Definition: snn_manager.cpp:87
const FILE * getLogFpInf()
function writes population weights from gIDpre to gIDpost to file fname in binary.
Definition: snn.h:596