Skip to content

Commit

Permalink
Move parallel hint code.
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc committed Oct 29, 2024
1 parent 31a6c48 commit 53b7e5c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 52 deletions.
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

0 comments on commit 53b7e5c

Please sign in to comment.