Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit 55c5e15

Browse files
authored
fornetcon: fix GPU execution. (#781)
* Bump submodule past BlueBrain/mod2c#77.
1 parent c1093ba commit 55c5e15

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

coreneuron/gpu/nrn_acc_manager.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,17 @@ void setup_nrnthreads_on_device(NrnThread* threads, int nthreads) {
562562
// not kept up to date timestep-by-timestep on the device.
563563
}
564564
}
565+
{
566+
auto* d_fornetcon_perm_indices = cnrn_target_copyin(nt->_fornetcon_perm_indices,
567+
nt->_fornetcon_perm_indices_size);
568+
cnrn_target_memcpy_to_device(&(d_nt->_fornetcon_perm_indices),
569+
&d_fornetcon_perm_indices);
570+
}
571+
{
572+
auto* d_fornetcon_weight_perm = cnrn_target_copyin(nt->_fornetcon_weight_perm,
573+
nt->_fornetcon_weight_perm_size);
574+
cnrn_target_memcpy_to_device(&(d_nt->_fornetcon_weight_perm), &d_fornetcon_weight_perm);
575+
}
565576
}
566577

567578
#endif
@@ -937,6 +948,8 @@ void delete_nrnthreads_on_device(NrnThread* threads, int nthreads) {
937948
#ifdef CORENEURON_ENABLE_GPU
938949
for (int i = 0; i < nthreads; i++) {
939950
NrnThread* nt = threads + i;
951+
cnrn_target_delete(nt->_fornetcon_weight_perm);
952+
cnrn_target_delete(nt->_fornetcon_perm_indices);
940953
{
941954
TrajectoryRequests* tr = nt->trajec_requests;
942955
if (tr) {

coreneuron/io/nrn_setup.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,11 @@ void nrn_cleanup_ion_map() {
704704
nrn_ion_global_map_size = 0;
705705
}
706706

707+
void delete_fornetcon_info(NrnThread& nt) {
708+
delete[] std::exchange(nt._fornetcon_perm_indices, nullptr);
709+
delete[] std::exchange(nt._fornetcon_weight_perm, nullptr);
710+
}
711+
707712
/* nrn_threads_free() presumes all NrnThread and NrnThreadMembList data is
708713
* allocated with malloc(). This is not the case here, so let's try and fix
709714
* things up first. */
@@ -726,6 +731,7 @@ void nrn_cleanup() {
726731
for (int it = 0; it < nrn_nthread; ++it) {
727732
NrnThread* nt = nrn_threads + it;
728733
NrnThreadMembList* next_tml = nullptr;
734+
delete_fornetcon_info(*nt);
729735
delete_trajectory_requests(*nt);
730736
for (NrnThreadMembList* tml = nt->tml; tml; tml = next_tml) {
731737
Memb_list* ml = tml->ml;

coreneuron/io/setup_fornetcon.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,15 @@ void setup_fornetcon_info(NrnThread& nt) {
126126

127127
// Displacement vector has an extra element since the number for last item
128128
// at n-1 is x[n] - x[n-1] and number for first is x[0] = 0.
129-
nt._fornetcon_perm_indices.resize(n_perm_indices + 1);
130-
nt._fornetcon_weight_perm.resize(n_weight_perm);
129+
delete[] std::exchange(nt._fornetcon_perm_indices, nullptr);
130+
delete[] std::exchange(nt._fornetcon_weight_perm, nullptr);
131+
// Manual memory management because of needing to copy NrnThread to the GPU
132+
// and update device-side pointers there. Note the {} ensure the allocated
133+
// arrays are zero-initalised.
134+
nt._fornetcon_perm_indices_size = n_perm_indices + 1;
135+
nt._fornetcon_perm_indices = new size_t[nt._fornetcon_perm_indices_size]{};
136+
nt._fornetcon_weight_perm_size = n_weight_perm;
137+
nt._fornetcon_weight_perm = new size_t[nt._fornetcon_weight_perm_size]{};
131138

132139
// From dparam fornetcon slots, compute displacement vector, and
133140
// set the dparam fornetcon slot to the index of the displacement vector

coreneuron/sim/multicore.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ struct NrnThread: public MemoryManaged {
144144
TrajectoryRequests* trajec_requests = nullptr; /* per time step values returned to NEURON */
145145

146146
/* Needed in case there are FOR_NETCON statements in use. */
147-
std::vector<size_t> _fornetcon_perm_indices; /* displacement like list of indices */
148-
std::vector<size_t> _fornetcon_weight_perm; /* permutation indices into weight */
147+
std::size_t _fornetcon_perm_indices_size{}; /* length of _fornetcon_perm_indices */
148+
size_t* _fornetcon_perm_indices{}; /* displacement like list of indices */
149+
std::size_t _fornetcon_weight_perm_size{}; /* length of _fornetcon_weight_perm */
150+
size_t* _fornetcon_weight_perm{}; /* permutation indices into weight */
149151

150152
std::vector<int> _pnt_offset; /* for SelfEvent queue transfer */
151153
};

external/mod2c

0 commit comments

Comments
 (0)