Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SIMD/ivdep pragmas. #1540

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/codegen/codegen_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,15 @@ std::string CodegenCppVisitor::breakpoint_current(std::string current) const {
* for(int id = 0; id < nodecount; id++) {
* \endcode
*/
void CodegenCppVisitor::print_parallel_iteration_hint(BlockType /* type */,
const ast::Block* block) {
void CodegenCppVisitor::print_parallel_iteration_hint(BlockType type, const ast::Block* block) {
if (parallel_iteration_condition(type, block)) {
printer->add_line("#pragma omp simd");
printer->add_line("#pragma ivdep");
}
}

bool CodegenCppVisitor::parallel_iteration_condition(BlockType /* type */,
const ast::Block* block) {
// ivdep allows SIMD parallelisation of a block/loop but doesn't provide
// a standard mechanism for atomics. Also, even with openmp 5.0, openmp
// atomics do not enable vectorisation under "omp simd" (gives compiler
Expand All @@ -406,10 +413,8 @@ void CodegenCppVisitor::print_parallel_iteration_hint(BlockType /* type */,
ast::AstNodeType::MUTEX_LOCK,
ast::AstNodeType::MUTEX_UNLOCK});
}
if (nodes.empty()) {
printer->add_line("#pragma omp simd");
printer->add_line("#pragma ivdep");
}

return nodes.empty();
}


Expand Down
4 changes: 4 additions & 0 deletions src/codegen/codegen_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,10 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor {
virtual void print_parallel_iteration_hint(BlockType type, const ast::Block* block);


/** Condition for parallel iteration. */
virtual bool parallel_iteration_condition(BlockType type, const ast::Block* block);


/****************************************************************************************/
/* Backend specific routines */
/****************************************************************************************/
Expand Down
12 changes: 11 additions & 1 deletion src/codegen/codegen_neuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@
}


bool CodegenNeuronCppVisitor::parallel_iteration_condition(BlockType type,
const ast::Block* block) {
return info.thread_safe && CodegenCppVisitor::parallel_iteration_condition(type, block);
}


/****************************************************************************************/
/* Backend specific routines */
/****************************************************************************************/
Expand Down Expand Up @@ -754,7 +760,7 @@
print_macro("_nt", "nt");
print_macro("_tqitem", "tqitem");

auto print_args_macro = [this, print_macro](const std::string& macro_basename,

Check warning on line 763 in src/codegen/codegen_neuron_cpp_visitor.cpp

View workflow job for this annotation

GitHub Actions / { "flag_warnings": "ON", "os": "ubuntu-22.04", "sanitizer": "undefined" }

lambda capture 'this' is not used [-Wunused-lambda-capture]
const ParamVector& params) {
print_macro("_" + macro_basename + "_", get_arg_str(params));
print_macro("_" + macro_basename + "comma_", get_arg_str(params) + ",");
Expand Down Expand Up @@ -2041,6 +2047,7 @@

print_global_function_common_code(BlockType::Initial);

print_parallel_iteration_hint(BlockType::Initial, info.initial_node);
printer->push_block("for (int id = 0; id < nodecount; id++)");

printer->add_line("auto* _ppvar = _ml_arg->pdata[id];");
Expand Down Expand Up @@ -2084,6 +2091,8 @@

print_entrypoint_setup_code_from_memb_list();
printer->fmt_line("auto nodecount = _ml_arg->nodecount;");

print_parallel_iteration_hint(BlockType::Equation, nullptr);
printer->push_block("for (int id = 0; id < nodecount; id++)"); // begin for

if (breakpoint_exist()) {
Expand Down Expand Up @@ -2291,6 +2300,7 @@
printer->add_newline(2);
print_global_function_common_code(BlockType::State);

print_parallel_iteration_hint(BlockType::State, info.nrn_state_block);
printer->push_block("for (int id = 0; id < nodecount; id++)");
printer->add_line("int node_id = node_data.nodeindices[id];");
printer->add_line("auto* _ppvar = _ml_arg->pdata[id];");
Expand Down Expand Up @@ -2504,7 +2514,7 @@
printer->add_newline(2);
printer->add_line("/** update current */");
print_global_function_common_code(BlockType::Equation);
// print_channel_iteration_block_parallel_hint(BlockType::Equation, info.breakpoint_node);
print_parallel_iteration_hint(BlockType::Equation, info.breakpoint_node);
printer->push_block("for (int id = 0; id < nodecount; id++)");
print_nrn_cur_kernel(*info.breakpoint_node);
// print_nrn_cur_matrix_shadow_update();
Expand Down
3 changes: 3 additions & 0 deletions src/codegen/codegen_neuron_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ class CodegenNeuronCppVisitor: public CodegenCppVisitor {
int position_of_int_var(const std::string& name) const override;


bool parallel_iteration_condition(BlockType type, const ast::Block* block) override;


/****************************************************************************************/
/* Backend specific routines */
/****************************************************************************************/
Expand Down
Loading