Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions coreneuron/io/nrn_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,15 +732,7 @@ void nrn_cleanup() {

NetSendBuffer_t* nsb = ml->_net_send_buffer;
if (nsb) {
if (nsb->_size) {
free_memory(nsb->_sendtype);
free_memory(nsb->_vdata_index);
free_memory(nsb->_pnt_index);
free_memory(nsb->_weight_index);
free_memory(nsb->_nsb_t);
free_memory(nsb->_nsb_flag);
}
free_memory(nsb);
delete nsb;
}

if (tml->dependencies)
Expand Down
18 changes: 2 additions & 16 deletions coreneuron/io/phase2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,23 +464,9 @@ void Phase2::set_net_send_buffer(Memb_list** ml_list, const std::vector<int>& pn
// Does this thread have this type.
Memb_list* ml = ml_list[type];
if (ml) { // needs a NetSendBuffer
NetSendBuffer_t* nsb = (NetSendBuffer_t*)ecalloc_align(1, sizeof(NetSendBuffer_t));
ml->_net_send_buffer = nsb;

// begin with a size equal to twice number of instances
// at present there is no provision for dynamically increasing this.
nsb->_size = ml->nodecount * 2;
nsb->_cnt = 0;

nsb->_sendtype = (int*)ecalloc_align(nsb->_size, sizeof(int));
nsb->_vdata_index = (int*)ecalloc_align(nsb->_size, sizeof(int));
nsb->_pnt_index = (int*)ecalloc_align(nsb->_size, sizeof(int));
nsb->_weight_index = (int*)ecalloc_align(nsb->_size, sizeof(int));
// when == 1, NetReceiveBuffer_t is newly allocated (i.e. we need to free previous copy
// and recopy new data
nsb->reallocated = 1;
nsb->_nsb_t = (double*)ecalloc_align(nsb->_size, sizeof(double));
nsb->_nsb_flag = (double*)ecalloc_align(nsb->_size, sizeof(double));
NetSendBuffer_t* nsb = new NetSendBuffer_t(ml->nodecount * 2);
ml->_net_send_buffer = nsb;
}
}
}
Expand Down
55 changes: 54 additions & 1 deletion coreneuron/mechanism/mechanism.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once

#include <string.h>

#include "coreneuron/nrnconf.h"
#include "coreneuron/utils/memory.h"

namespace coreneuron {
#if PG_ACC_BUGS
Expand Down Expand Up @@ -66,7 +69,7 @@ struct NetReceiveBuffer_t {
int _pnt_offset;
};

struct NetSendBuffer_t {
struct NetSendBuffer_t : MemoryManaged {
int* _sendtype; // net_send, net_event, net_move
int* _vdata_index;
int* _pnt_index;
Expand All @@ -76,6 +79,56 @@ struct NetSendBuffer_t {
int _cnt;
int _size; /* capacity */
int reallocated; /* if buffer resized/reallocated, needs to be copy to cpu */

NetSendBuffer_t(int size) : _size(size) {
_cnt = 0;

_sendtype = (int*)ecalloc_align(_size, sizeof(int));
_vdata_index = (int*)ecalloc_align(_size, sizeof(int));
_pnt_index = (int*)ecalloc_align(_size, sizeof(int));
_weight_index = (int*)ecalloc_align(_size, sizeof(int));
// when == 1, NetReceiveBuffer_t is newly allocated (i.e. we need to free previous copy
// and recopy new data
reallocated = 1;
_nsb_t = (double*)ecalloc_align(_size, sizeof(double));
_nsb_flag = (double*)ecalloc_align(_size, sizeof(double));
}

~NetSendBuffer_t() {
free_memory(_sendtype);
free_memory(_vdata_index);
free_memory(_pnt_index);
free_memory(_weight_index);
free_memory(_nsb_t);
free_memory(_nsb_flag);
}

void grow() {
#if defined(_OPENACC)
int cannot_reallocate_on_device = 0;
assert(cannot_reallocate_on_device);
#else
int new_size = _size * 2;
grow_buf(&_sendtype, _size, new_size);
grow_buf(&_vdata_index, _size, new_size);
grow_buf(&_pnt_index, _size, new_size);
grow_buf(&_weight_index, _size, new_size);
grow_buf(&_nsb_t, _size, new_size);
grow_buf(&_nsb_flag, _size, new_size);
_size = new_size;
#endif
}

private:
template <typename T>
void grow_buf(T** buf, int size, int new_size) {
T* new_buf = nullptr;
new_buf = (T*)ecalloc_align(new_size, sizeof(T));
memcpy(new_buf, *buf, size * sizeof(T));
free(*buf);
*buf = new_buf;
}

};

struct Memb_list {
Expand Down