Skip to content

Commit

Permalink
Improve several mod files for coreneuron in memory transfer. (#8)
Browse files Browse the repository at this point in the history
Modify bbcore_read in `GlueSynapse.mod` and `StochKv.mod`.
Replace `VecStim.mod` with `vecevent.mod` from neuron repo.
  • Loading branch information
WeinaJi authored Jun 21, 2024
1 parent e88cc89 commit 0fd4698
Show file tree
Hide file tree
Showing 14 changed files with 187 additions and 182 deletions.
19 changes: 13 additions & 6 deletions common/mod/GluSynapse.mod
Original file line number Diff line number Diff line change
Expand Up @@ -644,14 +644,15 @@ static void bbcore_write(double* dArray, int* iArray, int* doffset, int* ioffset
}

static void bbcore_read(double* dArray, int* iArray, int* doffset, int* ioffset, _threadargsproto_) {
// make sure it's not previously set
assert(!_p_rng);
assert(!_p_delay_times && !_p_delay_weights);

uint32_t* ia = ((uint32_t*)iArray) + *ioffset;
// make sure non-zero identifier seeds
if (ia[0] != 0 || ia[1] != 0 || ia[2] != 0) {
nrnran123_State** pv = (nrnran123_State**)(&_p_rng);
#if !NRNBBCORE
if(*pv) {
nrnran123_deletestream(*pv);
}
#endif
// get new stream
*pv = nrnran123_newstream3(ia[0], ia[1], ia[2]);
// restore sequence
Expand All @@ -668,8 +669,14 @@ static void bbcore_read(double* dArray, int* iArray, int* doffset, int* ioffset,
double* x_i = dArray + *doffset;

// allocate vectors
_p_delay_times = (double*)vector_new1(delay_times_sz);
_p_delay_weights = (double*)vector_new1(delay_weights_sz);
if (!_p_delay_times) {
_p_delay_times = (double*)vector_new1(delay_times_sz);
}
assert(delay_times_sz == vector_capacity((IvocVect*)_p_delay_times));
if (!_p_delay_weights) {
_p_delay_weights = (double*)vector_new1(delay_weights_sz);
}
assert(delay_weights_sz == vector_capacity((IvocVect*)_p_delay_weights));

double* delay_times_el = vector_vec((IvocVect*)_p_delay_times);
double* delay_weights_el = vector_vec((IvocVect*)_p_delay_weights);
Expand Down
169 changes: 0 additions & 169 deletions common/mod/VecStim.mod

This file was deleted.

163 changes: 163 additions & 0 deletions common/mod/vecevent.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
: Vector stream of events, copied from nrn/share/examples/nrniv/netcon/vecevent.mod

COMMENT
A VecStim is an artificial spiking cell that generates
events at times that are specified in a Vector.

HOC Example:

// assumes spt is a Vector whose elements are all > 0
// and are sorted in monotonically increasing order
objref vs
vs = new VecStim()
vs.play(spt)
// now launch a simulation, and vs will produce spike events
// at the times contained in spt

Python Example:

from neuron import h
spt = h.Vector(10).indgen(1, 0.2)
vs = h.VecStim()
vs.play(spt)

def pr():
print (h.t)

nc = h.NetCon(vs, None)
nc.record(pr)

cvode = h.CVode()
h.finitialize()
cvode.solve(20)

ENDCOMMENT

NEURON {
THREADSAFE
ARTIFICIAL_CELL VecStim
BBCOREPOINTER ptr
}

ASSIGNED {
index
etime (ms)
ptr
}


INITIAL {
index = 0
element()
if (index > 0) {
net_send(etime - t, 1)
}
}

NET_RECEIVE (w) {
if (flag == 1) {
net_event(t)
element()
if (index > 0) {
net_send(etime - t, 1)
}
}
}

DESTRUCTOR {
VERBATIM
#if !NRNBBCORE
void* vv = (void*)(_p_ptr);
if (vv) {
hoc_obj_unref(*vector_pobj(vv));
}
#endif
ENDVERBATIM
}

PROCEDURE element() {
VERBATIM
{ void* vv; int i, size; double* px;
i = (int)index;
if (i >= 0) {
vv = (void*)(_p_ptr);
if (vv) {
size = vector_capacity(vv);
px = vector_vec(vv);
if (i < size) {
etime = px[i];
index += 1.;
}else{
index = -1.;
}
}else{
index = -1.;
}
}
}
ENDVERBATIM
}

PROCEDURE play() {
VERBATIM
#if !NRNBBCORE
{
void** pv;
void* ptmp = NULL;
if (ifarg(1)) {
ptmp = vector_arg(1);
hoc_obj_ref(*vector_pobj(ptmp));
}
pv = (void**)(&_p_ptr);
if (*pv) {
hoc_obj_unref(*vector_pobj(*pv));
}
*pv = ptmp;
}
#endif
ENDVERBATIM
}

VERBATIM
static void bbcore_write(double* xarray, int* iarray, int* xoffset, int* ioffset, _threadargsproto_) {
int i, dsize, *ia;
double *xa, *dv;
dsize = 0;
if (_p_ptr) {
dsize = vector_capacity(_p_ptr);
}
if (iarray) {
void* vec = _p_ptr;
ia = iarray + *ioffset;
xa = xarray + *xoffset;
ia[0] = dsize;
if (dsize) {
dv = vector_vec(vec);
for (i = 0; i < dsize; ++i) {
xa[i] = dv[i];
}
}
}
*ioffset += 1;
*xoffset += dsize;
}

static void bbcore_read(double* xarray, int* iarray, int* xoffset, int* ioffset, _threadargsproto_) {
int dsize, i, *ia;
double *xa, *dv;
xa = xarray + *xoffset;
ia = iarray + *ioffset;
dsize = ia[0];
if (!_p_ptr) {
_p_ptr = vector_new1(dsize);
}
assert(dsize == vector_capacity(_p_ptr));
dv = vector_vec(_p_ptr);
for (i = 0; i < dsize; ++i) {
dv[i] = xa[i];
}
*xoffset += dsize;
*ioffset += 1;
}

ENDVERBATIM
2 changes: 1 addition & 1 deletion common/test/glusynapse/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ How to run tests
================

First we need to compile GluSynapse and VecStim:
$ nrnivmodl ../../common/mod/GluSynapse2019.mod ../../common/mod/VecStim.mod
$ nrnivmodl ../../common/mod/GluSynapse2019.mod ../../common/mod/vecevent.mod

Then we can use the Nose test suite to run the tests:
$ nosetests -v test\_ltpltd.py
Expand Down
2 changes: 1 addition & 1 deletion common/test/run_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ which nrniv || (echo "Please load Neuron" && exit 1)
cd "$(dirname "${BASH_SOURCE[0]}")" # cd to this dir

pushd glusynapse
nrnivmodl ../../mod/VecStim.mod ../../mod/GluSynapse.mod # Compile mod
nrnivmodl ../../mod/vecevent.mod ../../mod/GluSynapse.mod # Compile mod
nosetests -v test_transmission.py
nosetests -v test_ltpltd.py
popd
1 change: 0 additions & 1 deletion hippocampus/mod/VecStim.mod

This file was deleted.

1 change: 1 addition & 0 deletions hippocampus/mod/vecevent.mod
Loading

0 comments on commit 0fd4698

Please sign in to comment.