nmodl
nmodl copied to clipboard
Better support for Random123 routines in verbatim blocks for GPU
Consider following example in Ampa and Gaba synapses of BBP model :
VERBATIM
static void bbcore_read(double* x, int* d, int* xx, int* offset, _threadargsproto_) {
assert(!_p_rng);
uint32_t* di = ((uint32_t*)d) + *offset;
if (di[0] != 0 || di[1] != 0 || di[2] != 0) {
nrnran123_State** pv = (nrnran123_State**)(&_p_rng);
*pv = nrnran123_newstream3(di[0], di[1], di[2]);
char which = (char)di[4];
nrnran123_setseq(*pv, di[3], which);
}
*offset += 5;
}
ENDVERBATIM
INITIAL {
LOCAL tp_AMPA, tp_NMDA
tp_AMPA = (tau_r_AMPA*tau_d_AMPA)/(tau_d_AMPA-tau_r_AMPA)*log(tau_d_AMPA/tau_r_AMPA)
....
VERBATIM
if( usingR123 ) {
nrnran123_setseq((nrnran123_State*)_p_rng, 0, 0);
}
ENDVERBATIM
}
As these mod files are compiled for GPU, nrnran123_setseq get replaced with cu_nrnran123_setseq (because of macro in nrnran123.h).
nrnran123_setseq in INITIAL block is called on GPU so its ok to call cu_nrnran123_setseq. But bbcore_read is called in CPU context and calling CUDA kernel cu_nrnran123_setseq result in abort.
I think this is fixed by #1125 and no more writing directly random functions