Skip to content

Commit 1c1b8b4

Browse files
author
Nicolas Cornu
authored
Remove support of AoS layout (BlueBrain/nmodl#565)
Consider that we always use SoA. NMODL currently has support for AoS layout. This was added for compatibility and testing with MOD2C and CoreNEURON. We remove AoS support due to following reasons: In practice, we never use AoS layout for CPU vectorisation or GPUs This part remains untested because of the same reason Simplify the code What have been done: Remove CLI option in nmodl for layout Remove all logic in src/codegen where we we are using LayoutType::aos. Fix BlueBrain/nmodl#563 NMODL Repo SHA: BlueBrain/nmodl@520f60e
1 parent 5c42435 commit 1c1b8b4

8 files changed

+51
-158
lines changed

src/nmodl/codegen/codegen_acc_visitor.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,15 @@ class CodegenAccVisitor: public CodegenCVisitor {
9898
public:
9999
CodegenAccVisitor(const std::string& mod_file,
100100
const std::string& output_dir,
101-
LayoutType layout,
102101
const std::string& float_type,
103102
bool optimize_ionvar_copies)
104-
: CodegenCVisitor(mod_file, output_dir, layout, float_type, optimize_ionvar_copies) {}
103+
: CodegenCVisitor(mod_file, output_dir, float_type, optimize_ionvar_copies) {}
105104

106105
CodegenAccVisitor(const std::string& mod_file,
107106
std::ostream& stream,
108-
LayoutType layout,
109107
const std::string& float_type,
110108
bool optimize_ionvar_copies)
111-
: CodegenCVisitor(mod_file, stream, layout, float_type, optimize_ionvar_copies) {}
109+
: CodegenCVisitor(mod_file, stream, float_type, optimize_ionvar_copies) {}
112110
};
113111

114112
/** @} */ // end of codegen_backends

src/nmodl/codegen/codegen_c_visitor.cpp

+18-59
Original file line numberDiff line numberDiff line change
@@ -1921,7 +1921,7 @@ std::string CodegenCVisitor::process_verbatim_text(std::string text) {
19211921
name = "&" + name;
19221922
}
19231923
if (token == "_STRIDE") {
1924-
name = (layout == LayoutType::soa) ? "pnodecount+id" : "1";
1924+
name = "pnodecount+id";
19251925
}
19261926
result += name;
19271927
}
@@ -2024,18 +2024,6 @@ void CodegenCVisitor::print_nmodl_constants() {
20242024
}
20252025

20262026

2027-
void CodegenCVisitor::print_memory_layout_getter() {
2028-
printer->add_newline(2);
2029-
printer->add_line("static inline int get_memory_layout() {");
2030-
if (layout == LayoutType::aos) {
2031-
printer->add_line(" return 1; //aos");
2032-
} else {
2033-
printer->add_line(" return 0; //soa");
2034-
}
2035-
printer->add_line("}");
2036-
}
2037-
2038-
20392027
void CodegenCVisitor::print_first_pointer_var_index_getter() {
20402028
printer->add_newline(2);
20412029
print_device_method_annotation();
@@ -2093,14 +2081,6 @@ void CodegenCVisitor::print_memb_list_getter() {
20932081
}
20942082

20952083

2096-
void CodegenCVisitor::print_post_channel_iteration_common_code() {
2097-
if (layout == LayoutType::aos) {
2098-
printer->add_line("data = ml->data + id*{};"_format(float_variables_size()));
2099-
printer->add_line("indexes = ml->pdata + id*{};"_format(int_variables_size()));
2100-
}
2101-
}
2102-
2103-
21042084
void CodegenCVisitor::print_namespace_start() {
21052085
printer->add_newline(2);
21062086
printer->start_block("namespace coreneuron");
@@ -2182,18 +2162,14 @@ std::string CodegenCVisitor::float_variable_name(const SymbolType& symbol,
21822162
// clang-format off
21832163
if (symbol->is_array()) {
21842164
if (use_instance) {
2185-
auto stride = (layout == LayoutType::soa) ? dimension : num_float;
2186-
return "(inst->{}+id*{})"_format(name, stride);
2165+
return "(inst->{}+id*{})"_format(name, dimension);
21872166
}
2188-
auto stride = (layout == LayoutType::soa) ? "{}*pnodecount+id*{}"_format(position, dimension) : "{}"_format(position);
2189-
return "(data+{})"_format(stride);
2167+
return "(data + {}*pnodecount + id*{})"_format(position, dimension);
21902168
}
21912169
if (use_instance) {
2192-
auto stride = (layout == LayoutType::soa) ? "id" : "id*{}"_format(num_float);
2193-
return "inst->{}[{}]"_format(name, stride);
2170+
return "inst->{}[id]"_format(name);
21942171
}
2195-
auto stride = (layout == LayoutType::soa) ? "{}*pnodecount+id"_format(position) : "{}"_format(position);
2196-
return "data[{}]"_format(stride);
2172+
return "data[{}*pnodecount + id]"_format(position);
21972173
// clang-format on
21982174
}
21992175

@@ -2203,29 +2179,24 @@ std::string CodegenCVisitor::int_variable_name(const IndexVariableInfo& symbol,
22032179
bool use_instance) const {
22042180
auto position = position_of_int_var(name);
22052181
auto num_int = int_variables_size();
2206-
std::string offset;
22072182
// clang-format off
22082183
if (symbol.is_index) {
2209-
offset = std::to_string(position);
22102184
if (use_instance) {
2211-
return "inst->{}[{}]"_format(name, offset);
2185+
return "inst->{}[{}]"_format(name, position);
22122186
}
2213-
return "indexes[{}]"_format(offset);
2187+
return "indexes[{}]"_format(position);
22142188
}
22152189
if (symbol.is_integer) {
22162190
if (use_instance) {
2217-
offset = (layout == LayoutType::soa) ? "{}*pnodecount+id"_format(position) : "id*{}+{}"_format(num_int, position);
2218-
return "inst->{}[{}]"_format(name, offset);
2191+
return "inst->{}[{}*pnodecount+id]"_format(name, position);
22192192
}
2220-
offset = (layout == LayoutType::soa) ? "{}*pnodecount+id"_format(position) : "id";
2221-
return "indexes[{}]"_format(offset);
2193+
return "indexes[{}*pnodecount+id]"_format(position);
22222194
}
2223-
offset = (layout == LayoutType::soa) ? "{}*pnodecount+id"_format(position) : "{}"_format(position);
22242195
if (use_instance) {
2225-
return "inst->{}[indexes[{}]]"_format(name, offset);
2196+
return "inst->{}[indexes[{}*pnodecount + id]]"_format(name, position);
22262197
}
22272198
auto data = symbol.is_vdata ? "_vdata" : "_data";
2228-
return "nt->{}[indexes[{}]]"_format(data, offset);
2199+
return "nt->{}[indexes[{}]]"_format(data, position);
22292200
// clang-format on
22302201
}
22312202

@@ -2622,8 +2593,6 @@ void CodegenCVisitor::print_global_variables_for_hoc() {
26222593
* - If nrn_get_mechtype is < -1 means that mechanism is not used in the
26232594
* context of neuron execution and hence could be ignored in coreneuron
26242595
* execution.
2625-
* - Each mechanism could have different layout and hence we register the
2626-
* layout with the simulator. In practice all mechanisms have same layout.
26272596
* - Ions are internally defined and their types can be queried similar to
26282597
* other mechanisms.
26292598
* - hoc_register_var may not be needed in the context of coreneuron
@@ -2646,7 +2615,7 @@ void CodegenCVisitor::print_mechanism_register() {
26462615
printer->add_line("}");
26472616

26482617
printer->add_newline();
2649-
printer->add_line("_nrn_layout_reg(mech_type, get_memory_layout());");
2618+
printer->add_line("_nrn_layout_reg(mech_type, 0);"); // 0 for SoA
26502619

26512620
// register mechanism
26522621
auto args = register_mechanism_arguments();
@@ -2999,7 +2968,7 @@ void CodegenCVisitor::print_global_variable_setup() {
29992968
value = *value_ptr;
30002969
}
30012970
/// use %g to be same as nocmodl in neuron
3002-
printer->add_line("{} = {};"_format(name, "{:g}"_format(value)));
2971+
printer->add_line("{} = {:g};"_format(name, value));
30032972
}
30042973
}
30052974

@@ -3012,7 +2981,7 @@ void CodegenCVisitor::print_global_variable_setup() {
30122981
value = *value_ptr;
30132982
}
30142983
/// use %g to be same as nocmodl in neuron
3015-
printer->add_line("{} = {};"_format(name, "{:g}"_format(value)));
2984+
printer->add_line("{} = {:g};"_format(name, value));
30162985
}
30172986

30182987
if (info.table_count > 0) {
@@ -3139,10 +3108,8 @@ void CodegenCVisitor::print_instance_variable_setup() {
31393108
}
31403109

31413110
std::string stride;
3142-
if (layout == LayoutType::soa) {
3143-
printer->add_line("int pnodecount = ml->_nodecount_padded;");
3144-
stride = "*pnodecount";
3145-
}
3111+
printer->add_line("int pnodecount = ml->_nodecount_padded;");
3112+
stride = "*pnodecount";
31463113

31473114
printer->add_line("Datum* indexes = ml->pdata;");
31483115

@@ -3317,8 +3284,6 @@ void CodegenCVisitor::print_nrn_init(bool skip_init_check) {
33173284
print_channel_iteration_tiling_block_begin(BlockType::Initial);
33183285
print_channel_iteration_block_begin(BlockType::Initial);
33193286

3320-
print_post_channel_iteration_common_code();
3321-
33223287
if (info.net_receive_node != nullptr) {
33233288
printer->add_line("{} = -1e20;"_format(get_variable_name("tsave")));
33243289
}
@@ -3411,7 +3376,6 @@ void CodegenCVisitor::print_watch_check() {
34113376
print_global_function_common_code(BlockType::Watch);
34123377
print_channel_iteration_tiling_block_begin(BlockType::Watch);
34133378
print_channel_iteration_block_begin(BlockType::Watch);
3414-
print_post_channel_iteration_common_code();
34153379

34163380
if (info.is_voltage_used_by_watch_statements()) {
34173381
printer->add_line("int node_id = node_index[id];");
@@ -3798,9 +3762,7 @@ void CodegenCVisitor::visit_for_netcon(const ast::ForNetcon& node) {
37983762
})->index;
37993763
const auto num_int = int_variables_size();
38003764

3801-
std::string offset = (layout == LayoutType::soa) ? "{}*pnodecount + id"_format(index)
3802-
: "{} + id*{}"_format(index, num_int);
3803-
printer->add_text("const size_t offset = {};"_format(offset));
3765+
printer->add_text("const size_t offset = {}*pnodecount + id;"_format(index));
38043766
printer->add_newline();
38053767
printer->add_line(
38063768
"const size_t for_netcon_start = nt->_fornetcon_perm_indices[indexes[offset]];");
@@ -3925,7 +3887,7 @@ void CodegenCVisitor::print_derivimplicit_kernel(Block* block) {
39253887
auto list_num = info.derivimplicit_list_num;
39263888
auto block_name = block->get_node_name();
39273889
auto primes_size = info.primes_size;
3928-
auto stride = (layout == LayoutType::aos) ? "" : "*pnodecount+id";
3890+
auto stride = "*pnodecount+id";
39293891

39303892
printer->add_newline(2);
39313893

@@ -4037,7 +3999,6 @@ void CodegenCVisitor::print_nrn_state() {
40373999
print_global_function_common_code(BlockType::State);
40384000
print_channel_iteration_tiling_block_begin(BlockType::State);
40394001
print_channel_iteration_block_begin(BlockType::State);
4040-
print_post_channel_iteration_common_code();
40414002

40424003
printer->add_line("int node_id = node_index[id];");
40434004
printer->add_line("double v = voltage[node_id];");
@@ -4252,7 +4213,6 @@ void CodegenCVisitor::print_nrn_cur() {
42524213
print_global_function_common_code(BlockType::Equation);
42534214
print_channel_iteration_tiling_block_begin(BlockType::Equation);
42544215
print_channel_iteration_block_begin(BlockType::Equation);
4255-
print_post_channel_iteration_common_code();
42564216
print_nrn_cur_kernel(*info.breakpoint_node);
42574217
print_nrn_cur_matrix_shadow_update();
42584218
if (!nrn_cur_reduction_loop_required()) {
@@ -4300,7 +4260,6 @@ void CodegenCVisitor::print_namespace_end() {
43004260

43014261
void CodegenCVisitor::print_common_getters() {
43024262
print_first_pointer_var_index_getter();
4303-
print_memory_layout_getter();
43044263
print_net_receive_arg_size_getter();
43054264
print_thread_getters();
43064265
print_num_variable_getter();

src/nmodl/codegen/codegen_c_visitor.hpp

-45
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,6 @@ struct IndexVariableInfo {
132132
};
133133

134134

135-
/**
136-
* \enum LayoutType
137-
* \brief Represents memory layout to use for code generation
138-
*
139-
*/
140-
enum class LayoutType {
141-
/// array of structure
142-
aos,
143-
144-
/// structure of array
145-
soa
146-
};
147-
148-
149135
/**
150136
* \class ShadowUseStatement
151137
* \brief Represents ion write statement during code generation
@@ -270,11 +256,6 @@ class CodegenCVisitor: public visitor::ConstAstVisitor {
270256
*/
271257
std::string float_type = codegen::naming::DEFAULT_FLOAT_TYPE;
272258

273-
/**
274-
* Memory layout for code generation
275-
*/
276-
LayoutType layout;
277-
278259
/**
279260
* All ast information for code generation
280261
*/
@@ -1121,13 +1102,6 @@ class CodegenCVisitor: public visitor::ConstAstVisitor {
11211102
void print_thread_getters();
11221103

11231104

1124-
/**
1125-
* Print the getter method for memory layout
1126-
*
1127-
*/
1128-
void print_memory_layout_getter();
1129-
1130-
11311105
/**
11321106
* Print the getter method for index position of first pointer variable
11331107
*
@@ -1314,12 +1288,6 @@ class CodegenCVisitor: public visitor::ConstAstVisitor {
13141288
virtual void print_channel_iteration_block_end();
13151289

13161290

1317-
/**
1318-
* Print common code post channel instance iteration
1319-
*/
1320-
void print_post_channel_iteration_common_code();
1321-
1322-
13231291
/**
13241292
* Print function and procedures prototype declaration
13251293
*/
@@ -1644,7 +1612,6 @@ class CodegenCVisitor: public visitor::ConstAstVisitor {
16441612

16451613
CodegenCVisitor(const std::string& mod_filename,
16461614
const std::string& output_dir,
1647-
LayoutType layout,
16481615
const std::string& float_type,
16491616
const bool optimize_ionvar_copies,
16501617
const std::string& extension,
@@ -1653,13 +1620,11 @@ class CodegenCVisitor: public visitor::ConstAstVisitor {
16531620
, wrapper_printer(new CodePrinter(output_dir + "/" + mod_filename + wrapper_ext))
16541621
, printer(target_printer)
16551622
, mod_filename(mod_filename)
1656-
, layout(layout)
16571623
, float_type(float_type)
16581624
, optimize_ionvar_copies(optimize_ionvar_copies) {}
16591625

16601626
CodegenCVisitor(const std::string& mod_filename,
16611627
std::ostream& stream,
1662-
LayoutType layout,
16631628
const std::string& float_type,
16641629
const bool optimize_ionvar_copies,
16651630
const std::string& extension,
@@ -1668,7 +1633,6 @@ class CodegenCVisitor: public visitor::ConstAstVisitor {
16681633
, wrapper_printer(new CodePrinter(stream))
16691634
, printer(target_printer)
16701635
, mod_filename(mod_filename)
1671-
, layout(layout)
16721636
, float_type(float_type)
16731637
, optimize_ionvar_copies(optimize_ionvar_copies) {}
16741638

@@ -1687,21 +1651,18 @@ class CodegenCVisitor: public visitor::ConstAstVisitor {
16871651
* \param mod_filename The name of the model for which code should be generated.
16881652
* It is used for constructing an output filename.
16891653
* \param output_dir The directory where target C file should be generated.
1690-
* \param layout The memory layout to be used for data structure generation.
16911654
* \param float_type The float type to use in the generated code. The string will be used
16921655
* as-is in the target code. This defaults to \c double.
16931656
* \param extension The file extension to use. This defaults to \c .cpp .
16941657
*/
16951658
CodegenCVisitor(const std::string& mod_filename,
16961659
const std::string& output_dir,
1697-
LayoutType layout,
16981660
std::string float_type,
16991661
const bool optimize_ionvar_copies,
17001662
const std::string& extension = ".cpp")
17011663
: target_printer(new CodePrinter(output_dir + "/" + mod_filename + extension))
17021664
, printer(target_printer)
17031665
, mod_filename(mod_filename)
1704-
, layout(layout)
17051666
, float_type(std::move(float_type))
17061667
, optimize_ionvar_copies(optimize_ionvar_copies) {}
17071668

@@ -1718,19 +1679,16 @@ class CodegenCVisitor: public visitor::ConstAstVisitor {
17181679
* \param mod_filename The name of the model for which code should be generated.
17191680
* It is used for constructing an output filename.
17201681
* \param stream The output stream onto which to write the generated code
1721-
* \param layout The memory layout to be used for data structure generation.
17221682
* \param float_type The float type to use in the generated code. The string will be used
17231683
* as-is in the target code. This defaults to \c double.
17241684
*/
17251685
CodegenCVisitor(const std::string& mod_filename,
17261686
std::ostream& stream,
1727-
LayoutType layout,
17281687
const std::string& float_type,
17291688
const bool optimize_ionvar_copies)
17301689
: target_printer(new CodePrinter(stream))
17311690
, printer(target_printer)
17321691
, mod_filename(mod_filename)
1733-
, layout(layout)
17341692
, float_type(float_type)
17351693
, optimize_ionvar_copies(optimize_ionvar_copies) {}
17361694

@@ -1747,21 +1705,18 @@ class CodegenCVisitor: public visitor::ConstAstVisitor {
17471705
*
17481706
* \param mod_filename The name of the model for which code should be generated.
17491707
* It is used for constructing an output filename.
1750-
* \param layout The memory layout to be used for data structure generation.
17511708
* \param float_type The float type to use in the generated code. The string will be used
17521709
* as-is in the target code. This defaults to \c double.
17531710
* \param target_printer A printer defined outside this visitor to be used for the code
17541711
* generation
17551712
*/
17561713
CodegenCVisitor(std::string mod_filename,
1757-
LayoutType layout,
17581714
std::string float_type,
17591715
const bool optimize_ionvar_copies,
17601716
std::shared_ptr<CodePrinter>& target_printer)
17611717
: target_printer(target_printer)
17621718
, printer(target_printer)
17631719
, mod_filename(mod_filename)
1764-
, layout(layout)
17651720
, float_type(float_type)
17661721
, optimize_ionvar_copies(optimize_ionvar_copies) {}
17671722

0 commit comments

Comments
 (0)