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

Commit a0a760f

Browse files
fouriauxpramodk
authored andcommitted
* Move coreneuron towards c++ (#82)
- coreneuron namespace added - change ivocvect vector compatibility and declarations - core_read and core_write to be out of coreneuron namespace - change public API of coreneuron to explose core_psolve - add pulbic header - kinderiv.h has prototype declaration for euler methods - changes to integrate with neurodamus: psolve_core renamed and added --skip-mpi-finalize command line option - OpenACC pragma annotation was missing for kernels using euler - cudaMemset wrong pointer (bug fix) - user provided flags should take precedence - change tests to comply to new changes - link with mod2c generated files
1 parent 7799a94 commit a0a760f

File tree

111 files changed

+421
-414
lines changed

Some content is hidden

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

111 files changed

+421
-414
lines changed

apps/coreneuron.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
2626
THE POSSIBILITY OF SUCH DAMAGE.
2727
*/
2828

29-
30-
extern int main1(int argc, char** argv, char** env);
29+
#include <coreneuron/engine.h>
3130
extern "C" {extern void modl_reg(void);}
3231

33-
int main(int argc, char** argv, char** env) {
34-
return main1(argc, argv, env);
32+
int main(int argc, char** argv) {
33+
return solve_core(argc, argv);
3534
}
3635

3736
/// Declare an empty function if Neurodamus mechanisms are not used, otherwise register them in mechs/cfile/mod_func.c

coreneuron/CMakeLists.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ set(MOD2C env "MODLUNIT=${MOD2C_UNITS}" ${MOD2C})
5555
macro(mod2c_target name input)
5656
get_filename_component(mod2c_source_ ${input} ABSOLUTE)
5757
get_filename_component(mod2c_modname_ ${input} NAME)
58-
string(REGEX REPLACE "\\.mod$" ".c" mod2c_cname_ "${mod2c_modname_}")
58+
string(REGEX REPLACE "\\.mod$" ".cpp" mod2c_cname_ "${mod2c_modname_}")
5959

6060
set(mod2c_output_ "${CMAKE_CURRENT_BINARY_DIR}/${mod2c_cname_}")
6161
list(APPEND MOD2C_${name}_OUTPUTS "${mod2c_output_}")
@@ -192,7 +192,7 @@ mod2c_from_file(OPTMECH "${ADDITIONAL_MECHS}" "${ADDITIONAL_MECHPATH}")
192192

193193
# For 'non-standard' mod files, need to generate registering function in mod_func.c
194194

195-
set(MOD_FUNC_C "${CMAKE_CURRENT_BINARY_DIR}/mod_func.c")
195+
set(MOD_FUNC_C "${CMAKE_CURRENT_BINARY_DIR}/mod_func.cpp")
196196
set(MOD_FUNC_C_PL "${CMAKE_CURRENT_SOURCE_DIR}/mech/mod_func.c.pl")
197197

198198
# ... pass as argument to the perl script the list of mod file names;
@@ -221,7 +221,7 @@ add_custom_command(OUTPUT "${KINDERIV_H}"
221221

222222
if (EXPORT_MECHS_FUNCTIONS)
223223
# Create C file with all "get function pointers" methods
224-
set(MOD_FUNC_PTRS_C "${CMAKE_CURRENT_BINARY_DIR}/mod_func_ptrs.c")
224+
set(MOD_FUNC_PTRS_C "${CMAKE_CURRENT_BINARY_DIR}/mod_func_ptrs.cpp")
225225
set(MOD_FUNC_PTRS_C_PL "${CMAKE_CURRENT_SOURCE_DIR}/mech/mod_func_ptrs.c.pl")
226226

227227
# ... pass as argument to the perl script the list of mods full paths;
@@ -236,10 +236,10 @@ set(GENERATED_MECH_C_FILES ${MOD_FUNC_C} ${MOD_FUNC_PTRS_C} ${MOD2C_STDMECH_OUTP
236236

237237
# artificial cells must be on cpu, defaul nrnran123.c is for cpu, nrn_setup.cpp uses nrnran123 for only memory calculation purpose which should use cpu version of nrnran123
238238
set(NOACC_MECH_C_FILES
239-
${CMAKE_CURRENT_BINARY_DIR}/netstim.c
240-
${CMAKE_CURRENT_BINARY_DIR}/netstim_inhpoisson.c
241-
${CMAKE_CURRENT_BINARY_DIR}/pattern.c
242-
${CMAKE_CURRENT_SOURCE_DIR}/utils/randoms/nrnran123.c
239+
${CMAKE_CURRENT_BINARY_DIR}/netstim.cpp
240+
${CMAKE_CURRENT_BINARY_DIR}/netstim_inhpoisson.cpp
241+
${CMAKE_CURRENT_BINARY_DIR}/pattern.cpp
242+
${CMAKE_CURRENT_SOURCE_DIR}/utils/randoms/nrnran123.cpp
243243
${CMAKE_CURRENT_SOURCE_DIR}/nrniv/nrn_setup.cpp
244244
${CMAKE_CURRENT_SOURCE_DIR}/nrniv/global_vars.cpp)
245245

@@ -291,6 +291,7 @@ set_target_properties(coreneuron PROPERTIES
291291
install(TARGETS coreneuron
292292
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
293293
ARCHIVE DESTINATION ${LIB_INSTALL_DIR} )
294+
install(FILES "engine.h" DESTINATION include/coreneuron)
294295

295296
if(ENABLE_DEV_FILES_INSTALLATION)
296297
install(DIRECTORY .

coreneuron/coreneuron.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,14 @@ THE POSSIBILITY OF SUCH DAMAGE.
3939
#include <stdlib.h>
4040
#include <math.h>
4141

42+
#include "coreneuron/utils/randoms/nrnran123.h" //Random Number Generator
4243
#include "coreneuron/scopmath_core/newton_struct.h" //Newton Struct
4344
#include "coreneuron/nrnoc/membdef.h" //static definitions
4445
#include "coreneuron/nrnoc/nrnoc_ml.h" //Memb_list and mechs info
45-
#include "coreneuron/utils/randoms/nrnran123.h" //Random Number Generator
4646

47-
#if defined(__cplusplus)
4847
#include "coreneuron/nrniv/memory.h" //Memory alignments and padding
4948

50-
extern "C" {
51-
#endif
49+
namespace coreneuron {
5250

5351
#ifdef EXPORT_MECHS_FUNCTIONS
5452
// from (auto-generated) mod_func_ptrs.c
@@ -59,18 +57,16 @@ extern mod_f_t get_BA_function(const char* sym, int BA_func_id);
5957
#endif
6058

6159
// from nrnoc/capac.c
62-
extern void nrn_init_capacitance(struct NrnThread*, struct Memb_list*, int);
63-
extern void nrn_cur_capacitance(struct NrnThread* _nt, struct Memb_list* ml, int type);
60+
extern void nrn_init_capacitance(NrnThread*, Memb_list*, int);
61+
extern void nrn_cur_capacitance(NrnThread* _nt, Memb_list* ml, int type);
6462
extern void nrn_alloc_capacitance(double* data, Datum* pdata, int type);
6563

6664
// from nrnoc/eion.c
67-
extern void nrn_init_ion(struct NrnThread*, struct Memb_list*, int);
68-
extern void nrn_cur_ion(struct NrnThread* _nt, struct Memb_list* ml, int type);
65+
extern void nrn_init_ion(NrnThread*, Memb_list*, int);
66+
extern void nrn_cur_ion(NrnThread* _nt, Memb_list* ml, int type);
6967
extern void nrn_alloc_ion(double* data, Datum* pdata, int type);
7068
extern void second_order_cur(NrnThread* _nt, int secondorder);
7169

72-
#if defined(__cplusplus)
73-
}
74-
#endif
70+
} //namespace coreneuron
7571

7672
#endif

coreneuron/engine.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef CORENEURON_ENGINE_H
2+
#define CORENEURON_ENGINE_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
extern int solve_core (int argc, char** argv);
8+
#ifdef __cplusplus
9+
}
10+
#endif
11+
12+
#endif

coreneuron/kinderiv.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import os
1616

17-
fnames = [f.replace('.mod', '.c') for f in os.listdir('.') if f.endswith('.mod')]
17+
fnames = [f.replace('.mod', '.cpp') for f in os.listdir('.') if f.endswith('.mod')]
1818
euler = []
1919
deriv = []
2020
kin = []
@@ -47,6 +47,7 @@
4747
fout.write(' */\n')
4848

4949
fout.write("\n/* declarations */\n")
50+
fout.write("\nnamespace coreneuron {\n")
5051
for item in deriv:
5152
fout.write('#pragma acc routine seq\n')
5253
fout.write('extern int %s%s(_threadargsproto_);\n' % (item[0], item[1]))
@@ -94,6 +95,8 @@
9495
fout.write("\n")
9596

9697
fout.write('\n#endif\n')
98+
99+
fout.write("\n} //namespace coreneuron\n")
97100
fout.close()
98101

99102
# if kf exists and is same as kftmp, just remove kftmp. Otherwise

coreneuron/mech/cfile/cabvars.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
2626
THE POSSIBILITY OF SUCH DAMAGE.
2727
*/
2828

29-
#ifdef __cplusplus
30-
extern "C" {
31-
#endif
29+
30+
namespace coreneuron {
3231

3332
extern void capacitance_reg(void), _passive_reg(void),
3433
#if EXTRACELLULAR
@@ -44,6 +43,4 @@ static void (*mechanism[])(void) = {/* type will start at 3 */
4443
#endif
4544
_stim_reg, _hh_reg, _expsyn_reg, _netstim_reg, _exp2syn_reg, 0};
4645

47-
#ifdef __cplusplus
48-
}
49-
#endif
46+
} //namespace coreneuron

coreneuron/mech/mod2c_core_thread.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
#include "coreneuron/nrnoc/multicore.h"
55
#include "coreneuron/nrnoc/nrnoc_ml.h"
66

7-
#if defined(__cplusplus)
8-
extern "C" {
9-
#endif
7+
namespace coreneuron {
108

119
#if !defined(LAYOUT)
1210
/* 1 means AoS, >1 means AoSoA, <= 0 means SOA */
@@ -141,8 +139,6 @@ extern void _modl_set_dt_thread(double, NrnThread*);
141139

142140
void nrn_sparseobj_copyto_device(SparseObj* so);
143141

144-
#if defined(__cplusplus)
145-
}
146-
#endif
142+
} // namespace coreneuron
147143

148144
#endif

coreneuron/mech/mod_func.c.pl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
print << "__eof";
2828
#include <stdio.h>
29+
namespace coreneuron {
2930
extern int nrnmpi_myid;
3031
extern int nrn_nobanner_;
3132
extern int @{[join ",\n ", map{"_${_}_reg(void)"} @mods]};
@@ -41,4 +42,5 @@
4142

4243
@{[join "\n", map{" _${_}_reg();"} @mods] }
4344
}
45+
} //namespace coreneuron
4446
__eof

coreneuron/mech/mod_func_ptrs.c.pl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <string.h>
3434
#include <stdlib.h>
3535
#include "coreneuron/coreneuron.h"
36+
namespace coreneuron {
3637
__eof
3738

3839
#Get the correct SUFFIX from each mod file for each mechanism
@@ -121,5 +122,6 @@
121122
{
122123
return NULL;
123124
}
125+
} //namespace coreneuron
124126
__eof
125127

coreneuron/mech/modfile/pattern.mod

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ NET_RECEIVE (w) {LOCAL nst
3232

3333
VERBATIM
3434

35-
extern void nrn_fake_fire(int gid, double spiketime, int fake_out);
36-
3735
typedef struct {
3836
int size;
3937
double* tvec;
@@ -57,16 +55,17 @@ Info* mkinfo(_threadargsproto_) {
5755
return info;
5856
}
5957
/* for CoreNEURON checkpoint save and restore */
58+
namespace coreneuron {
6059
int checkpoint_save_patternstim(_threadargsproto_) {
6160
INFOCAST; Info* info = *ip;
6261
return info->index;
6362
}
6463
void checkpoint_restore_patternstim(int _index, double _te, _threadargsproto_) {
6564
INFOCAST; Info* info = *ip;
6665
info->index = _index;
67-
artcell_net_send(_tqitem, -1, _nt->_vdata[_ppvar[1*_STRIDE]], _te, 1.0);
66+
artcell_net_send(_tqitem, -1, (Point_process*)_nt->_vdata[_ppvar[1*_STRIDE]], _te, 1.0);
6867
}
69-
68+
} //namespace coreneuron
7069
ENDVERBATIM
7170

7271
FUNCTION initps() {
@@ -109,7 +108,7 @@ ENDVERBATIM
109108
VERBATIM
110109
static void bbcore_write(double* x, int* d, int* xx, int *offset, _threadargsproto_){}
111110
static void bbcore_read(double* x, int* d, int* xx, int* offset, _threadargsproto_){}
112-
111+
namespace coreneuron {
113112
void pattern_stim_setup_helper(int size, double* tv, int* gv, _threadargsproto_) {
114113
INFOCAST;
115114
Info* info = mkinfo(_threadargs_);
@@ -118,6 +117,6 @@ void pattern_stim_setup_helper(int size, double* tv, int* gv, _threadargsproto_)
118117
info->tvec = tv;
119118
info->gidvec = gv;
120119
}
121-
120+
} // namespace coreneuron
122121
ENDVERBATIM
123122

0 commit comments

Comments
 (0)