User Guide
codegen_acc_visitor.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2023 Blue Brain Project, EPFL.
3  * See the top-level LICENSE file for details.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #pragma once
9 
10 /**
11  * \file
12  * \brief \copybrief nmodl::codegen::CodegenAccVisitor
13  */
14 
16 
17 
18 namespace nmodl {
19 namespace codegen {
20 
21 /**
22  * \addtogroup codegen_backends
23  * \{
24  */
25 
26 /**
27  * \class CodegenAccVisitor
28  * \brief %Visitor for printing C++ code with OpenACC backend
29  */
31  public:
32  using CodegenCoreneuronCppVisitor::CodegenCoreneuronCppVisitor;
33 
34  protected:
35 
36  /// name of the code generation backend
37  std::string backend_name() const override;
38 
39 
40  /// common includes : standard c++, coreneuron and backend specific
41  void print_backend_includes() override;
42 
43 
44  /// ivdep like annotation for channel iterations
45  void print_parallel_iteration_hint(BlockType type, const ast::Block* block) override;
46 
47 
48  /// atomic update pragma for reduction statements
49  void print_atomic_reduction_pragma() override;
50 
51 
52  /// memory allocation routine
53  void print_memory_allocation_routine() const override;
54 
55 
56  /// abort routine
57  void print_abort_routine() const override;
58 
59 
60  /// annotations like "acc enter data present(...)" for main kernel
62 
63 
64  /// end of annotation like "acc enter data"
66 
67 
68  /// start of annotation "acc kernels" for net_init kernel
70 
71 
72  /// end of annotation "acc kernels" for net_init kernel
74 
75 
76  /// update to matrix elements with/without shadow vectors
77  void print_nrn_cur_matrix_shadow_update() override;
78 
79 
80  /// reduction to matrix elements from shadow vectors
82 
83  /// fast membrane current calculation
84  void print_fast_imem_calculation() override;
85 
86  /// setup method for setting matrix shadow vectors
87  void print_rhs_d_shadow_variables() override;
88 
89 
90  /// if reduction block in nrn_cur required
91  bool nrn_cur_reduction_loop_required() override;
92 
93  /// update global variable from host to the device
95 
96  /// transfer newtonspace structure to device
97  void print_newtonspace_transfer_to_device() const override;
98 
99  /// declare helper functions for copying the instance struct to the device
101 
102  /// define helper functions for copying the instance struct to the device
104  const std::vector<std::string>& ptr_members) override;
105 
106  /// call helper function for copying the instance struct to the device
107  void print_instance_struct_copy_to_device() override;
108 
109  /// call helper function that deletes the instance struct from the device
111 
112  /// update derivimplicit advance flag on the gpu device
113  void print_deriv_advance_flag_transfer_to_device() const override;
114 
115  /// update NetSendBuffer_t count from device to host
116  void print_net_send_buf_count_update_to_host() const override;
117 
118  /// update NetSendBuffer_t from device to host
119  void print_net_send_buf_update_to_host() const override;
120 
121  /// update NetSendBuffer_t count from host to device
122  void print_net_send_buf_count_update_to_device() const override;
123 
124  /// update dt from host to device
125  void print_dt_update_to_device() const override;
126 
127  // synchronise/wait on stream specific to NrnThread
128  void print_device_stream_wait() const override;
129 
130  /// print atomic capture pragma
131  void print_device_atomic_capture_annotation() const override;
132 
133  /// print atomic update of NetSendBuffer_t cnt
134  void print_net_send_buffering_cnt_update() const override;
135 
136  /// Replace default implementation by a no-op
137  /// since the buffer cannot be grown up during gpu execution
138  void print_net_send_buffering_grow() override;
139 };
140 
141 /** \} */ // end of codegen_backends
142 
143 } // namespace codegen
144 } // namespace nmodl
nmodl::codegen::CodegenAccVisitor::print_net_send_buf_count_update_to_host
void print_net_send_buf_count_update_to_host() const override
update NetSendBuffer_t count from device to host
Definition: codegen_acc_visitor.cpp:341
nmodl::codegen::CodegenAccVisitor::print_device_stream_wait
void print_device_stream_wait() const override
Print the code to synchronise/wait on stream specific to NrnThread.
Definition: codegen_acc_visitor.cpp:334
nmodl::codegen::CodegenAccVisitor::print_kernel_data_present_annotation_block_begin
void print_kernel_data_present_annotation_block_begin() override
annotations like "acc enter data present(...)" for main kernel
Definition: codegen_acc_visitor.cpp:142
nmodl::codegen::CodegenAccVisitor::print_parallel_iteration_hint
void print_parallel_iteration_hint(BlockType type, const ast::Block *block) override
ivdep like annotation for channel iterations
Definition: codegen_acc_visitor.cpp:34
nmodl::codegen::CodegenAccVisitor::print_net_send_buffering_grow
void print_net_send_buffering_grow() override
Replace default implementation by a no-op since the buffer cannot be grown up during gpu execution.
Definition: codegen_acc_visitor.cpp:124
nmodl::codegen::CodegenAccVisitor::print_newtonspace_transfer_to_device
void print_newtonspace_transfer_to_device() const override
transfer newtonspace structure to device
Definition: codegen_acc_visitor.cpp:240
nmodl::codegen::CodegenCoreneuronCppVisitor
Visitor for printing C++ code compatible with legacy api of CoreNEURON
Definition: codegen_coreneuron_cpp_visitor.hpp:62
nmodl::codegen::CodegenAccVisitor::print_nrn_cur_matrix_shadow_reduction
void print_nrn_cur_matrix_shadow_reduction() override
reduction to matrix elements from shadow vectors
Definition: codegen_acc_visitor.cpp:205
nmodl::codegen::CodegenAccVisitor::print_net_send_buffering_cnt_update
void print_net_send_buffering_cnt_update() const override
print atomic update of NetSendBuffer_t cnt
Definition: codegen_acc_visitor.cpp:115
nmodl::codegen::CodegenAccVisitor::print_net_init_acc_serial_annotation_block_begin
void print_net_init_acc_serial_annotation_block_begin() override
start of annotation "acc kernels" for net_init kernel
Definition: codegen_acc_visitor.cpp:159
nmodl::codegen::CodegenAccVisitor::print_deriv_advance_flag_transfer_to_device
void print_deriv_advance_flag_transfer_to_device() const override
update derivimplicit advance flag on the gpu device
Definition: codegen_acc_visitor.cpp:322
nmodl::codegen::CodegenAccVisitor::nrn_cur_reduction_loop_required
bool nrn_cur_reduction_loop_required() override
if reduction block in nrn_cur required
Definition: codegen_acc_visitor.cpp:225
nmodl
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
nmodl::codegen::CodegenAccVisitor::print_device_atomic_capture_annotation
void print_device_atomic_capture_annotation() const override
print atomic capture pragma
Definition: codegen_acc_visitor.cpp:328
nmodl::codegen::CodegenAccVisitor::print_fast_imem_calculation
void print_fast_imem_calculation() override
fast membrane current calculation
Definition: codegen_acc_visitor.cpp:186
nmodl::codegen::CodegenAccVisitor::print_atomic_reduction_pragma
void print_atomic_reduction_pragma() override
atomic update pragma for reduction statements
Definition: codegen_acc_visitor.cpp:57
nmodl::ast::Block
Base class for all block scoped nodes.
Definition: block.hpp:41
nmodl::codegen::CodegenAccVisitor::print_instance_struct_transfer_routine_declarations
void print_instance_struct_transfer_routine_declarations() override
declare helper functions for copying the instance struct to the device
Definition: codegen_acc_visitor.cpp:256
codegen_coreneuron_cpp_visitor.hpp
Visitor for printing C++ code compatible with legacy api of CoreNEURON
nmodl::codegen::CodegenAccVisitor::print_nrn_cur_matrix_shadow_update
void print_nrn_cur_matrix_shadow_update() override
update to matrix elements with/without shadow vectors
Definition: codegen_acc_visitor.cpp:173
nmodl::codegen::CodegenAccVisitor::print_instance_struct_copy_to_device
void print_instance_struct_copy_to_device() override
call helper function for copying the instance struct to the device
Definition: codegen_acc_visitor.cpp:306
nmodl::codegen::CodegenAccVisitor::print_rhs_d_shadow_variables
void print_rhs_d_shadow_variables() override
setup method for setting matrix shadow vectors
Definition: codegen_acc_visitor.cpp:220
nmodl::codegen::CodegenAccVisitor
Visitor for printing C++ code with OpenACC backend
Definition: codegen_acc_visitor.hpp:30
nmodl::codegen::CodegenAccVisitor::print_dt_update_to_device
void print_dt_update_to_device() const override
update dt from host to device
Definition: codegen_acc_visitor.cpp:364
nmodl::codegen::CodegenAccVisitor::print_global_variable_device_update_annotation
void print_global_variable_device_update_annotation() override
update global variable from host to the device
Definition: codegen_acc_visitor.cpp:230
nmodl::codegen::CodegenAccVisitor::print_kernel_data_present_annotation_block_end
void print_kernel_data_present_annotation_block_end() override
end of annotation like "acc enter data"
Definition: codegen_acc_visitor.cpp:213
nmodl::codegen::BlockType
BlockType
Helper to represent various block types.
Definition: codegen_cpp_visitor.hpp:56
nmodl::codegen::CodegenAccVisitor::print_abort_routine
void print_abort_routine() const override
abort routine
Definition: codegen_acc_visitor.cpp:107
nmodl::codegen::CodegenAccVisitor::print_backend_includes
void print_backend_includes() override
common includes : standard c++, coreneuron and backend specific
Definition: codegen_acc_visitor.cpp:63
nmodl::codegen::CodegenAccVisitor::print_instance_struct_delete_from_device
void print_instance_struct_delete_from_device() override
call helper function that deletes the instance struct from the device
Definition: codegen_acc_visitor.cpp:314
nmodl::codegen::CodegenAccVisitor::print_net_send_buf_update_to_host
void print_net_send_buf_update_to_host() const override
update NetSendBuffer_t from device to host
Definition: codegen_acc_visitor.cpp:347
nmodl::codegen::CodegenAccVisitor::print_net_send_buf_count_update_to_device
void print_net_send_buf_count_update_to_device() const override
update NetSendBuffer_t count from host to device
Definition: codegen_acc_visitor.cpp:356
nmodl::codegen::CodegenAccVisitor::print_instance_struct_transfer_routines
void print_instance_struct_transfer_routines(const std::vector< std::string > &ptr_members) override
define helper functions for copying the instance struct to the device
Definition: codegen_acc_visitor.cpp:268
nmodl::codegen::CodegenAccVisitor::print_net_init_acc_serial_annotation_block_end
void print_net_init_acc_serial_annotation_block_end() override
end of annotation "acc kernels" for net_init kernel
Definition: codegen_acc_visitor.cpp:167
nmodl::codegen::CodegenAccVisitor::backend_name
std::string backend_name() const override
name of the code generation backend
Definition: codegen_acc_visitor.cpp:69
nmodl::codegen::CodegenAccVisitor::print_memory_allocation_routine
void print_memory_allocation_routine() const override
memory allocation routine
Definition: codegen_acc_visitor.cpp:74