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

Commit 557f256

Browse files
author
Omar Awile
authored
Encapsulating global data into containers and data structures (#203)
This merge brings a number of code modernizations and improvements: * Improvements for raw pointers in coreneuron: - Replace NULL and nil with C++ nullptr, which allows us to better detect type confusion - do proper pointer initialization - Use references in some places wehre pointers aren't needed - Use a vector for the helper array rather than having to explicitly alloc/dealloc. * Added scopmath as a dependency to coreneuron as it is needed for the custom command to succeed (it links with scopmath down the line). * Created Coreneuron class that has for now a global instance - moved most other global data structures into this class. * Updated headers and build system accordingly * Replaced a few for loops by algorithms and range-based loops Many more to consider, but it's a start. * Added a simple CUDA managed allocation handling for C++ classes. Aligned memory allocation on CPU still missing. * Switched to class member initialization rather then setting the members of `NrnThread` in `nrn_threads_create`. We now create instances of the class through construction (and used CUDA managed allocation if built with CUDA). * Remove option to set version for libcorenrnmech library - we are integrating coreneuron into neuron - nrnivmodl will invoke nrnivmodl-core - neuron has auto-detection logic to find out libcorenrnmech so it doesn't make sense set version explicitly * Update submodules to latest master; do not track branches * Many code improvements thanks to @pramodk, @tristan0x and others! Note: For now the accesses to any of the Coreneuron class members is through a reference getter, which is really not how it should be done, but in the next step many of the involved functions will become methods that access the private data. In other cases the data will be rearranged and accessed through it's own container class.
1 parent b06d7b0 commit 557f256

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1016
-924
lines changed

.gitmodules

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[submodule "external/mod2c"]
2-
path = external/mod2c
2+
path = external/mod2c
33
url = https://github.com/BlueBrain/mod2c
4-
branch = master
54
[submodule "external/nmodl"]
6-
path = external/nmodl
7-
url = https://github.com/BlueBrain/nmodl
5+
path = external/nmodl
6+
url = https://github.com/BlueBrain/nmodl

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ project(coreneuron)
1313
set(VERSION_MAJOR "0")
1414
set(VERSION_MINOR "16")
1515
set(VERSION_PATCH "0")
16-
set(CMAKE_CXX_STANDARD 11)
16+
set(CMAKE_CXX_STANDARD 14)
1717
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1818
set(CMAKE_CXX_EXTENSIONS OFF)
1919
set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")

coreneuron/coreneuron.h

Lines changed: 0 additions & 64 deletions
This file was deleted.

coreneuron/coreneuron.hpp

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
/*
2+
Copyright (c) 2016, Blue Brain Project
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without modification,
6+
are permitted provided that the following conditions are met:
7+
1. Redistributions of source code must retain the above copyright notice,
8+
this list of conditions and the following disclaimer.
9+
2. Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation
11+
and/or other materials provided with the distribution.
12+
3. Neither the name of the copyright holder nor the names of its contributors
13+
may be used to endorse or promote products derived from this software
14+
without specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26+
THE POSSIBILITY OF SUCH DAMAGE.
27+
*/
28+
#pragma once
29+
30+
/***
31+
* Includes all headers required to communicate and run all methods
32+
* described in CoreNEURON, neurox, and mod2c C-generated mechanisms
33+
* functions.
34+
**/
35+
36+
37+
#include <cstdio>
38+
#include <cstdlib>
39+
#include <cmath>
40+
#include <string.h>
41+
#include <vector>
42+
#include <array>
43+
44+
#include "coreneuron/utils/randoms/nrnran123.h" //Random Number Generator
45+
#include "coreneuron/scopmath_core/newton_struct.h" //Newton Struct
46+
#include "coreneuron/nrnoc/membdef.h" //static definitions
47+
#include "coreneuron/nrnoc/nrnoc_ml.h" //Memb_list and mechs info
48+
49+
#include "coreneuron/nrniv/memory.h" //Memory alignments and padding
50+
#include "coreneuron/nrnconf.h"
51+
#include "coreneuron/nrnoc/multicore.h"
52+
#include "coreneuron/nrnoc/nrnoc_decl.h"
53+
#include "coreneuron/nrnoc/mech_mapping.hpp"
54+
55+
namespace coreneuron {
56+
57+
// from nrnoc/capac.c
58+
extern void nrn_init_capacitance(NrnThread*, Memb_list*, int);
59+
extern void nrn_cur_capacitance(NrnThread* _nt, Memb_list* ml, int type);
60+
extern void nrn_alloc_capacitance(double* data, Datum* pdata, int type);
61+
62+
// from nrnoc/eion.c
63+
extern void nrn_init_ion(NrnThread*, Memb_list*, int);
64+
extern void nrn_cur_ion(NrnThread* _nt, Memb_list* ml, int type);
65+
extern void nrn_alloc_ion(double* data, Datum* pdata, int type);
66+
extern void second_order_cur(NrnThread* _nt, int secondorder);
67+
68+
using DependencyTable = std::vector<std::vector<int>>;
69+
70+
/**
71+
* A class representing the CoreNEURON state, holding pointers to the various data structures
72+
*
73+
* The pointers to "global" data such as the NrnThread, Memb_list and Memb_func data structures
74+
* are managed here. they logically share their lifetime and runtime scope with instances of
75+
* this class.
76+
*/
77+
class CoreNeuron {
78+
79+
80+
/// Local to coreneuron, used to keep track of point process IDs
81+
int pointtype = 1; /* starts at 1 since 0 means not point in pnt_map*/
82+
83+
/**
84+
* map if mech is a point process
85+
* In the future only a field of Mechanism class
86+
*/
87+
std::vector<char> pnt_map; /* so prop_free can know its a point mech*/
88+
89+
/** Vector mapping the types (IDs) of different mechanisms of mod files between NEURON and
90+
* CoreNEURON
91+
*/
92+
std::vector<int> different_mechanism_type;
93+
94+
/**
95+
* dependency helper filled by calls to hoc_register_dparam_semantics
96+
* used when nrn_mech_depend is called
97+
* vector-of-vector DS. First idx is the mech, second idx is the dependent mech.
98+
*/
99+
DependencyTable ion_write_dependency;
100+
101+
std::vector<Memb_func> memb_funcs;
102+
103+
/**
104+
* Net send / Net receive
105+
* only used in CoreNEURON for book keeping synapse mechs, should go into CoreNEURON class
106+
*/
107+
std::vector<std::pair<NetBufReceive_t, int>> net_buf_receive;
108+
std::vector<int> net_buf_send_type;
109+
110+
/**
111+
* before-after-blocks from nmodl are registered here as function pointers
112+
*/
113+
std::array<BAMech*, BEFORE_AFTER_SIZE> bamech;
114+
115+
/**
116+
* Internal lookup tables. Number of float and int variables in each mechanism and memory layout
117+
* future --> mech class
118+
*/
119+
std::vector<int> nrn_prop_param_size;
120+
std::vector<int> nrn_prop_dparam_size;
121+
std::vector<int> nrn_mech_data_layout; /* 1 AoS (default), 0 SoA */
122+
/* array is parallel to memb_func. All are 0 except 1 for ARTIFICIAL_CELL */
123+
std::vector<short> nrn_artcell_qindex;
124+
std::vector<bool> nrn_is_artificial;
125+
126+
/**
127+
* Net Receive function pointer lookup tables
128+
*/
129+
std::vector<pnt_receive_t> pnt_receive; /* for synaptic events. */
130+
std::vector<pnt_receive_t> pnt_receive_init;
131+
std::vector<short> pnt_receive_size;
132+
133+
/**
134+
* Holds function pointers for WATCH callback
135+
*/
136+
std::vector<nrn_watch_check_t> nrn_watch_check;
137+
138+
/**
139+
* values are type numbers of mechanisms which do net_send call
140+
* related to NMODL net_event()
141+
*
142+
*/
143+
std::vector<int> nrn_has_net_event;
144+
145+
/**
146+
* inverse of nrn_has_net_event_ maps the values of nrn_has_net_event_ to the index of
147+
* ptntype2presyn
148+
*/
149+
std::vector<int> pnttype2presyn;
150+
151+
152+
std::vector<bbcore_read_t> nrn_bbcore_read;
153+
std::vector<bbcore_write_t> nrn_bbcore_write;
154+
155+
public:
156+
157+
auto& get_memb_funcs() {
158+
return memb_funcs;
159+
}
160+
161+
auto& get_memb_func(size_t idx) {
162+
return memb_funcs[idx];
163+
}
164+
165+
auto& get_different_mechanism_type() {
166+
return different_mechanism_type;
167+
}
168+
169+
auto& get_pnt_map() {
170+
return pnt_map;
171+
}
172+
173+
auto& get_ion_write_dependency() {
174+
return ion_write_dependency;
175+
}
176+
177+
auto& get_net_buf_receive() {
178+
return net_buf_receive;
179+
}
180+
181+
auto& get_net_buf_send_type() {
182+
return net_buf_send_type;
183+
}
184+
185+
auto& get_bamech() {
186+
return bamech;
187+
}
188+
189+
auto& get_prop_param_size() {
190+
return nrn_prop_param_size;
191+
}
192+
193+
auto& get_prop_dparam_size() {
194+
return nrn_prop_dparam_size;
195+
}
196+
197+
auto& get_mech_data_layout() {
198+
return nrn_mech_data_layout;
199+
}
200+
201+
auto& get_is_artificial() {
202+
return nrn_is_artificial;
203+
}
204+
205+
auto& get_artcell_qindex() {
206+
return nrn_artcell_qindex;
207+
}
208+
209+
auto& get_pnt_receive() {
210+
return pnt_receive;
211+
}
212+
213+
auto& get_pnt_receive_init() {
214+
return pnt_receive_init;
215+
}
216+
217+
auto& get_pnt_receive_size() {
218+
return pnt_receive_size;
219+
}
220+
221+
auto& get_watch_check() {
222+
return nrn_watch_check;
223+
}
224+
225+
auto& get_has_net_event() {
226+
return nrn_has_net_event;
227+
}
228+
229+
auto& get_pnttype2presyn() {
230+
return pnttype2presyn;
231+
}
232+
233+
auto& get_bbcore_read() {
234+
return nrn_bbcore_read;
235+
}
236+
237+
auto& get_bbcore_write() {
238+
return nrn_bbcore_write;
239+
}
240+
241+
242+
/**
243+
* Generate point process IDs for pnt_map starting at 1 (since 0 means no point process)
244+
* \return the next available point process ID
245+
*/
246+
int get_next_pointtype() {
247+
return pointtype++;
248+
}
249+
250+
};
251+
252+
extern CoreNeuron corenrn;
253+
254+
} // namespace coreneuron

coreneuron/nrnconf.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,10 @@ namespace coreneuron {
3939

4040
#define NRNBBCORE 1
4141

42-
#define nil NULL
43-
#define Sprintf sprintf
44-
4542
typedef int Datum;
46-
//#define Datum int
4743
typedef int (*Pfri)();
4844
typedef char Symbol;
4945

50-
#define CACHEVEC 2
5146
#define VEC_A(i) (_nt->_actual_a[(i)])
5247
#define VEC_B(i) (_nt->_actual_b[(i)])
5348
#define VEC_D(i) (_nt->_actual_d[(i)])

0 commit comments

Comments
 (0)