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

Commit a2a6435

Browse files
author
Nicolas Cornu
authored
Use enum to represent memory layout everywhere (#475)
* An enum exists to know that 0 mean SoA and 1 AoS, use it. * move it at different site so that enum is available everywhere.
1 parent 1877bed commit a2a6435

File tree

9 files changed

+22
-21
lines changed

9 files changed

+22
-21
lines changed

coreneuron/io/core2nrn_data_return.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void core2nrn_data_return() {
135135
double* cndat = ml->data;
136136
int layout = corenrn.get_mech_data_layout()[mtype];
137137
int sz = corenrn.get_prop_param_size()[mtype];
138-
if (layout == 0) { /* SoA */
138+
if (layout == Layout::SoA) {
139139
int stride = ml->_nodecount_padded;
140140
if (permute) {
141141
soa2aos_inverse_permute_copy(n, sz, stride, cndat, mdata, permute);

coreneuron/io/mem_layout_util.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ namespace coreneuron {
1919
#define NRN_SOA_PAD 8
2020
#endif
2121

22-
// If MATRIX_LAYOUT is 1 then a,b,d,rhs,v,area is not padded using NRN_SOA_PAD
23-
// When MATRIX_LAYOUT is 0 then mechanism pdata index values into _actual_v
24-
// and _actual_area data need to be updated.
25-
enum Layout { SoA = 0, AoS = 1 };
26-
2722
#if !defined(LAYOUT)
2823
#define LAYOUT Layout::AoS
2924
#define MATRIX_LAYOUT Layout::AoS

coreneuron/io/nrn_checkpoint.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ T* chkpnt_soa2aos(T* data, int cnt, int sz, int layout, int* permute) {
8888
// original file order depends on padding and permutation.
8989
// Good for a, b, area, v, diam, Memb_list.data, or anywhere values do not change.
9090
T* d = new T[cnt * sz];
91-
if (layout == 1) { /* AoS */
91+
if (layout == Layout::AoS) {
9292
for (int i = 0; i < cnt * sz; ++i) {
9393
d[i] = data[i];
9494
}
95-
} else if (layout == 0) { /* SoA */
95+
} else if (layout == Layout::SoA) {
9696
int align_cnt = nrn_soa_padded_size(cnt, layout);
9797
for (int i = 0; i < cnt; ++i) {
9898
int ip = i;
@@ -328,7 +328,7 @@ static void write_phase2(NrnThread& nt, FileHandlerWrap& fh) {
328328
int p = d[ix] - (eml->data - nt._data);
329329
int ei_instance, ei;
330330
nrn_inverse_i_layout(p, ei_instance, ecnt, ei, esz, elayout);
331-
if (elayout == 0) {
331+
if (elayout == Layout::SoA) {
332332
if (eml->_permute) {
333333
if (!ml_pinv[etype]) {
334334
ml_pinv[etype] = inverse_permute(eml->_permute,

coreneuron/io/nrn_setup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,10 +654,10 @@ double* stdindex2ptr(int mtype, int index, NrnThread& nt) {
654654

655655
// from i to (icnt, isz)
656656
void nrn_inverse_i_layout(int i, int& icnt, int cnt, int& isz, int sz, int layout) {
657-
if (layout == 1) {
657+
if (layout == Layout::AoS) {
658658
icnt = i / sz;
659659
isz = i % sz;
660-
} else if (layout == 0) {
660+
} else if (layout == Layout::SoA) {
661661
int padded_cnt = nrn_soa_padded_size(cnt, layout);
662662
icnt = i % padded_cnt;
663663
isz = i / padded_cnt;

coreneuron/io/setup_fornetcon.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ static int* fornetcon_slot(const int mtype,
6464
int sz = corenrn.get_prop_dparam_size()[mtype];
6565
Memb_list* ml = nt._ml_list[mtype];
6666
int* fn = nullptr;
67-
if (layout == 1) { /* AoS */
67+
if (layout == Layout::AoS) {
6868
fn = ml->pdata + (instance * sz + fnslot);
69-
} else if (layout == 0) { /* SoA */
69+
} else if (layout == Layout::SoA) {
7070
int padded_cnt = nrn_soa_padded_size(ml->nodecount, layout);
7171
fn = ml->pdata + (fnslot * padded_cnt + instance);
7272
}

coreneuron/mechanism/patternstim.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ void nrn_mkPatternStim(const char* fname, double tstop) {
8686
int _iml = pnt->_i_instance;
8787
double* _p = ml->data;
8888
Datum* _ppvar = ml->pdata;
89-
if (layout == 1) {
89+
if (layout == Layout::AoS) {
9090
_p += _iml * sz;
9191
_ppvar += _iml * psz;
92-
} else if (layout == 0) {
92+
} else if (layout == Layout::SoA) {
9393
;
9494
} else {
9595
assert(0);

coreneuron/nrniv/nrniv_decl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,10 @@ extern int nrn_soa_padded_size(int cnt, int layout);
7171

7272
extern int interleave_permute_type;
7373
extern int cellorder_nwarp;
74+
75+
// If MATRIX_LAYOUT is 1 then a,b,d,rhs,v,area is not padded using NRN_SOA_PAD
76+
// When MATRIX_LAYOUT is 0 then mechanism pdata index values into _actual_v
77+
// and _actual_area data need to be updated.
78+
enum Layout { SoA = 0, AoS = 1 };
7479
} // namespace coreneuron
7580
#endif

coreneuron/permute/node_permute.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void permute(T* data, int cnt, int sz, int layout, int* p) {
9393
return;
9494
}
9595

96-
if (layout == 0) { // for SoA, n might be larger due to cnt padding
96+
if (layout == Layout::SoA) { // for SoA, n might be larger due to cnt padding
9797
n = nrn_soa_padded_size(cnt, layout) * sz;
9898
}
9999

@@ -208,12 +208,12 @@ void update_pdata_values(Memb_list* ml, int type, NrnThread& nt) {
208208
int ix = *pd - edata0;
209209
// from ix determine i_ecnt and i_esz (need to permute i_ecnt)
210210
int i_ecnt, i_esz, padded_ecnt;
211-
if (elayout == 1) { // AoS
211+
if (elayout == Layout::AoS) {
212212
padded_ecnt = ecnt;
213213
i_ecnt = ix / esz;
214214
i_esz = ix % esz;
215215
} else { // SoA
216-
assert(elayout == 0);
216+
assert(elayout == Layout::SoA);
217217
padded_ecnt = nrn_soa_padded_size(ecnt, elayout);
218218
i_ecnt = ix % padded_ecnt;
219219
i_esz = ix / padded_ecnt;
@@ -258,13 +258,13 @@ int nrn_index_permute(int ix, int type, Memb_list* ml) {
258258
return ix;
259259
}
260260
int layout = corenrn.get_mech_data_layout()[type];
261-
if (layout == 1) {
261+
if (layout == Layout::AoS) {
262262
int sz = corenrn.get_prop_param_size()[type];
263263
int i_cnt = ix / sz;
264264
int i_sz = ix % sz;
265265
return p[i_cnt] * sz + i_sz;
266266
} else {
267-
assert(layout == 0);
267+
assert(layout == Layout::SoA);
268268
int padded_cnt = nrn_soa_padded_size(ml->nodecount, layout);
269269
int i_cnt = ix % padded_cnt;
270270
int i_sz = ix / padded_cnt;

coreneuron/utils/memory.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <cstring>
1414

1515
#include "coreneuron/utils/nrn_assert.h"
16+
#include "coreneuron/nrniv/nrniv_decl.h"
1617

1718
#if !defined(NRN_SOA_BYTE_ALIGN)
1819
// for layout 0, every range variable array must be aligned by at least 16 bytes (the size of the
@@ -109,7 +110,7 @@ namespace coreneuron {
109110
template <int chunk>
110111
inline int soa_padded_size(int cnt, int layout) {
111112
int imod = cnt % chunk;
112-
if (layout == 1)
113+
if (layout == Layout::AoS)
113114
return cnt;
114115
if (imod) {
115116
int idiv = cnt / chunk;

0 commit comments

Comments
 (0)