Skip to content

Replace contiguous NrnThread->_data with smaller memory chunks used in the CoreNEURON #493

@pramodk

Description

@pramodk

Currently, NEURON constructs NrnThread for CoreNEURON with one big memory chunk via nt->_data:

    nt._data = (double*)ecalloc_align(nt._ndata, sizeof(double));
    nt._actual_rhs = nt._data + 0 * ne;
    nt._actual_d = nt._data + 1 * ne;
    nt._actual_a = nt._data + 2 * ne;
    nt._actual_b = nt._data + 3 * ne;
    nt._actual_v = nt._data + 4 * ne;
    nt._actual_area = nt._data + 5 * ne;
    nt._actual_diam = ndiam ? nt._data + 6 * ne : nullptr;
    for (auto tml = nt.tml; tml; tml = tml->next) {
        Memb_list* ml = tml->ml;
        ml->data = nt._data + (ml->data - (double*)0);
    }
....
    int extra_nv = (&nt == nrn_threads) ? nrn_extra_thread0_vdata : 0;
    if (nt._nvdata + extra_nv)
        nt._vdata = (void**)ecalloc_align(nt._nvdata + extra_nv, sizeof(void*));

IIRC, there are also vdata members that can have global offsets to nt._data.

I believe it will be helpful if we can change these global offsets with more local ones and remove one big memory block nt->_data with smaller ones because of the following reasons:

  • if we have to allocate different type of memories for different mechanisms or mechanism properties, currently it's not possible. This we require for GPUs or even KNLs.
  • if we decide perform some of the mechanisms on GPUs on some on CPU, it's difficult to do because we have to copy all data to GPU (because of global memory offset).
  • when we have to construct data structure piece-by-piece or use some nice C++ containers instead of raw pointers, it's not possible.
  • @alkino is performing some of the refactoring of how we load the data in nrn_setup Split nrn_setup.cpp in phase1 / phase2 BlueBrain/CoreNeuron#283 but these global offsets and contiguous memory requirement pose a significant challenge in simplifying the code.

@nrnhines : we discussed this in the past but never able to make this priority. As Nico is doing very nice work on simplifying coreneuron code in BlueBrain/CoreNeuron#283, do you think we can make this change? This will also help NMODL and how we generate the code.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions