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

Move shared parallel hint code. #1542

Merged
merged 1 commit into from
Oct 29, 2024
Merged
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
35 changes: 0 additions & 35 deletions src/codegen/codegen_coreneuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,41 +218,6 @@ void CodegenCoreneuronCppVisitor::print_net_init_acc_serial_annotation_block_end
}


/**
* \details Depending programming model and compiler, we print compiler hint
* for parallelization. For example:
*
* \code
* #pragma omp simd
* for(int id = 0; id < nodecount; id++) {
*
* #pragma acc parallel loop
* for(int id = 0; id < nodecount; id++) {
* \endcode
*/
void CodegenCoreneuronCppVisitor::print_channel_iteration_block_parallel_hint(
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
// error with gcc < 9 if atomic and simd pragmas are nested). So, emit
// ivdep/simd pragma when no MUTEXLOCK/MUTEXUNLOCK/PROTECT statements
// are used in the given block.
std::vector<std::shared_ptr<const ast::Ast>> nodes;
if (block) {
nodes = collect_nodes(*block,
{ast::AstNodeType::PROTECT_STATEMENT,
ast::AstNodeType::MUTEX_LOCK,
ast::AstNodeType::MUTEX_UNLOCK});
}
if (nodes.empty()) {
printer->add_line("#pragma omp simd");
printer->add_line("#pragma ivdep");
}
}


bool CodegenCoreneuronCppVisitor::nrn_cur_reduction_loop_required() {
return info.point_process;
}
Expand Down
17 changes: 0 additions & 17 deletions src/codegen/codegen_coreneuron_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,23 +201,6 @@ class CodegenCoreneuronCppVisitor: public CodegenCppVisitor {
virtual void print_net_init_acc_serial_annotation_block_end();


/**
* Print pragma annotations for channel iterations
*
* This can be overriden by backends to provide additonal annotations or pragmas to enable
* for example SIMD code generation (e.g. through \c ivdep)
* The default implementation prints
*
* \code
* #pragma ivdep
* \endcode
*
* \param type The block type
*/
virtual void print_channel_iteration_block_parallel_hint(BlockType type,
const ast::Block* block);


/**
* Check if reduction block in \c nrn\_cur required
*/
Expand Down
35 changes: 35 additions & 0 deletions src/codegen/codegen_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,41 @@ std::string CodegenCppVisitor::breakpoint_current(std::string current) const {
return current;
}


/**
* \details Depending programming model and compiler, we print compiler hint
* for parallelization. For example:
*
* \code
* #pragma omp simd
* for(int id = 0; id < nodecount; id++) {
*
* #pragma acc parallel loop
* for(int id = 0; id < nodecount; id++) {
* \endcode
*/
void CodegenCppVisitor::print_channel_iteration_block_parallel_hint(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
// error with gcc < 9 if atomic and simd pragmas are nested). So, emit
// ivdep/simd pragma when no MUTEXLOCK/MUTEXUNLOCK/PROTECT statements
// are used in the given block.
std::vector<std::shared_ptr<const ast::Ast>> nodes;
if (block) {
nodes = collect_nodes(*block,
{ast::AstNodeType::PROTECT_STATEMENT,
ast::AstNodeType::MUTEX_LOCK,
ast::AstNodeType::MUTEX_UNLOCK});
}
if (nodes.empty()) {
printer->add_line("#pragma omp simd");
printer->add_line("#pragma ivdep");
}
}


/****************************************************************************************/
/* Routines for returning variable name */
/****************************************************************************************/
Expand Down
17 changes: 17 additions & 0 deletions src/codegen/codegen_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,23 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor {
std::string breakpoint_current(std::string current) const;


/**
* Print pragma annotations for channel iterations
*
* This can be overriden by backends to provide additonal annotations or pragmas to enable
* for example SIMD code generation (e.g. through \c ivdep)
* The default implementation prints
*
* \code
* #pragma ivdep
* \endcode
*
* \param type The block type
*/
virtual void print_channel_iteration_block_parallel_hint(BlockType type,
const ast::Block* block);


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