User Guide
codegen_coreneuron_cpp_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  * \dir
12  * \brief Code generation backend implementations for CoreNEURON
13  *
14  * \file
15  * \brief \copybrief nmodl::codegen::CodegenCoreneuronCppVisitor
16  */
17 
18 #include <algorithm>
19 #include <cmath>
20 #include <ctime>
21 #include <numeric>
22 #include <ostream>
23 #include <string>
24 #include <string_view>
25 #include <utility>
26 
28 #include "codegen/codegen_info.hpp"
30 #include "printer/code_printer.hpp"
31 #include "symtab/symbol_table.hpp"
32 #include "utils/logger.hpp"
33 #include "visitors/ast_visitor.hpp"
34 
35 
36 namespace nmodl {
37 
38 namespace codegen {
39 
40 
41 using printer::CodePrinter;
42 
43 
44 /**
45  * \defgroup codegen_backends Codegen Backends
46  * \ingroup codegen
47  * \brief Code generation backends for CoreNEURON
48  * \{
49  */
50 
51 /**
52  * \class CodegenCoreneuronCppVisitor
53  * \brief %Visitor for printing C++ code compatible with legacy api of CoreNEURON
54  *
55  * \todo
56  * - Handle define statement (i.e. macros)
57  * - If there is a return statement in the verbatim block
58  * of inlined function then it will be error. Need better
59  * error checking. For example, see netstim.mod where we
60  * have removed return from verbatim block.
61  */
63  public:
65 
66  protected:
67  /****************************************************************************************/
68  /* Member variables */
69  /****************************************************************************************/
70 
71 
72  /****************************************************************************************/
73  /* Generic information getters */
74  /****************************************************************************************/
75 
76 
77  /**
78  * Name of the simulator the code was generated for
79  */
80  std::string simulator_name() override;
81 
82 
83  /**
84  * Name of the code generation backend
85  */
86  virtual std::string backend_name() const override;
87 
88 
89  /**
90  * Determine the number of threads to allocate
91  */
92  int num_thread_objects() const noexcept {
93  return info.vectorize ? (info.thread_data_index + 1) : 0;
94  }
95 
96 
97  /****************************************************************************************/
98  /* Common helper routines accross codegen functions */
99  /****************************************************************************************/
100 
101 
102  /**
103  * Determine the position in the data array for a given float variable
104  * \param name The name of a float variable
105  * \return The position index in the data array
106  */
107  int position_of_float_var(const std::string& name) const override;
108 
109 
110  /**
111  * Determine the position in the data array for a given int variable
112  * \param name The name of an int variable
113  * \return The position index in the data array
114  */
115  int position_of_int_var(const std::string& name) const override;
116 
117 
118  /**
119  * Process a token in a verbatim block for possible variable renaming
120  * \param token The verbatim token to be processed
121  * \return The code after variable renaming
122  */
123  std::string process_verbatim_token(const std::string& token);
124 
125 
126  /**
127  * Check if variable is qualified as constant
128  * \param name The name of variable
129  * \return \c true if it is constant
130  */
131  virtual bool is_constant_variable(const std::string& name) const;
132 
133 
134  /****************************************************************************************/
135  /* Backend specific routines */
136  /****************************************************************************************/
137 
138 
139  /**
140  * Print the code to copy derivative advance flag to device
141  */
142  virtual void print_deriv_advance_flag_transfer_to_device() const;
143 
144 
145  /**
146  * Print pragma annotation for increase and capture of variable in automatic way
147  */
148  virtual void print_device_atomic_capture_annotation() const;
149 
150 
151  /**
152  * Print the code to update NetSendBuffer_t count from device to host
153  */
154  virtual void print_net_send_buf_count_update_to_host() const;
155 
156 
157  /**
158  * Print the code to update NetSendBuffer_t from device to host
159  */
160  virtual void print_net_send_buf_update_to_host() const;
161 
162 
163  /**
164  * Print the code to update NetSendBuffer_t count from host to device
165  */
166  virtual void print_net_send_buf_count_update_to_device() const;
167 
168  /**
169  * Print the code to update dt from host to device
170  */
171  virtual void print_dt_update_to_device() const;
172 
173  /**
174  * Print the code to synchronise/wait on stream specific to NrnThread
175  */
176  virtual void print_device_stream_wait() const;
177 
178 
179  /**
180  * Print accelerator annotations indicating data presence on device
181  */
183 
184 
185  /**
186  * Print matching block end of accelerator annotations for data presence on device
187  */
189 
190 
191  /**
192  * Print accelerator kernels begin annotation for net_init kernel
193  */
195 
196 
197  /**
198  * Print accelerator kernels end annotation for net_init kernel
199  */
201 
202 
203  /**
204  * Print pragma annotations for channel iterations
205  *
206  * This can be overriden by backends to provide additonal annotations or pragmas to enable
207  * for example SIMD code generation (e.g. through \c ivdep)
208  * The default implementation prints
209  *
210  * \code
211  * #pragma ivdep
212  * \endcode
213  *
214  * \param type The block type
215  */
217  const ast::Block* block);
218 
219 
220  /**
221  * Check if reduction block in \c nrn\_cur required
222  */
223  virtual bool nrn_cur_reduction_loop_required();
224 
225 
226  /**
227  * Print the setup method for setting matrix shadow vectors
228  *
229  */
230  virtual void print_rhs_d_shadow_variables();
231 
232 
233  /**
234  * Print the update to matrix elements with/without shadow vectors
235  *
236  */
237  virtual void print_nrn_cur_matrix_shadow_update();
238 
239 
240  /**
241  * Print the reduction to matrix elements from shadow vectors
242  *
243  */
245 
246 
247  /**
248  * Print atomic update pragma for reduction statements
249  */
250  virtual void print_atomic_reduction_pragma() override;
251 
252 
253  /**
254  * Print the backend specific device method annotation
255  *
256  * \note This is not used for the C++ backend
257  */
258  virtual void print_device_method_annotation();
259 
260 
261  /**
262  * Print backend specific global method annotation
263  *
264  * \note This is not used for the C++ backend
265  */
266  virtual void print_global_method_annotation();
267 
268 
269  /**
270  * Prints the start of namespace for the backend-specific code
271  *
272  * For the C++ backend no additional namespace is required
273  */
274  virtual void print_backend_namespace_start();
275 
276 
277  /**
278  * Prints the end of namespace for the backend-specific code
279  *
280  * For the C++ backend no additional namespace is required
281  */
282  virtual void print_backend_namespace_stop();
283 
284 
285  /**
286  * Print backend specific includes (none needed for C++ backend)
287  */
288  virtual void print_backend_includes();
289 
290 
291  /**
292  * Check if ion variable copies should be avoided
293  */
294  bool optimize_ion_variable_copies() const override;
295 
296 
297  /**
298  * Print memory allocation routine
299  */
300  virtual void print_memory_allocation_routine() const;
301 
302 
303  /**
304  * Print backend specific abort routine
305  */
306  virtual void print_abort_routine() const;
307 
308 
309  /**
310  * Print declarations of the functions used by \ref
311  * print_instance_struct_copy_to_device and \ref
312  * print_instance_struct_delete_from_device.
313  */
315 
316  /**
317  * Print the definitions of the functions used by \ref
318  * print_instance_struct_copy_to_device and \ref
319  * print_instance_struct_delete_from_device. Declarations of these functions
320  * are printed by \ref print_instance_struct_transfer_routine_declarations.
321  *
322  * This updates the (pointer) member variables in the device copy of the
323  * instance struct to contain device pointers, which is why you must pass a
324  * list of names of those member variables.
325  *
326  * \param ptr_members List of instance struct member names.
327  */
329  std::vector<std::string> const& /* ptr_members */) {}
330 
331 
332  /**
333  * Transfer the instance struct to the device. This calls a function
334  * declared by \ref print_instance_struct_transfer_routine_declarations.
335  */
337 
338 
339  /**
340  * Delete the instance struct from the device. This calls a function
341  * declared by \ref print_instance_struct_transfer_routine_declarations.
342  */
344 
345 
346  /****************************************************************************************/
347  /* Printing routines for code generation */
348  /****************************************************************************************/
349 
350 
351  /**
352  * Print top level (global scope) verbatim blocks
353  */
355 
356 
357  /**
358  * Print function and procedures prototype declaration
359  */
360  void print_function_prototypes() override;
361 
362 
363  /**
364  * Check if the given name exist in the symbol
365  * \return \c return a tuple <true, array_length> if variable
366  * is an array otherwise <false, 0>
367  */
368  std::tuple<bool, int> check_if_var_is_array(const std::string& name);
369 
370 
371  /**
372  * Print \c check\_function() for functions or procedure using table
373  * \param node The AST node representing a function or procedure block
374  */
375  void print_table_check_function(const ast::Block& node);
376 
377 
378  /**
379  * Print replacement function for function or procedure using table
380  * \param node The AST node representing a function or procedure block
381  */
383 
384 
385  /**
386  * Print check_table functions
387  */
389 
390 
391  /**
392  * Print nmodl function or procedure (common code)
393  * \param node the AST node representing the function or procedure in NMODL
394  * \param name the name of the function or procedure
395  */
396  void print_function_or_procedure(const ast::Block& node, const std::string& name) override;
397 
398 
399  /**
400  * Common helper function to help printing function or procedure blocks
401  * \param node the AST node representing the function or procedure in NMODL
402  */
403  void print_function_procedure_helper(const ast::Block& node) override;
404 
405 
406  /**
407  * Print NMODL procedure in target backend code
408  * \param node
409  */
410  virtual void print_procedure(const ast::ProcedureBlock& node) override;
411 
412 
413  /**
414  * Print NMODL function in target backend code
415  * \param node
416  */
417  void print_function(const ast::FunctionBlock& node) override;
418 
419 
420  /**
421  * Print NMODL function_table in target backend code
422  * \param node
423  */
425 
426 
427  bool is_functor_const(const ast::StatementBlock& variable_block,
428  const ast::StatementBlock& functor_block);
429 
430 
431  /**
432  * \brief Based on the \c EigenNewtonSolverBlock passed print the definition needed for its
433  * functor
434  *
435  * \param node \c EigenNewtonSolverBlock for which to print the functor
436  */
438 
439 
440  virtual void print_eigen_linear_solver(const std::string& float_type, int N);
441 
442 
443  /****************************************************************************************/
444  /* Code-specific helper routines */
445  /****************************************************************************************/
446 
447 
448  /**
449  * Arguments for functions that are defined and used internally.
450  * \return the method arguments
451  */
452  std::string internal_method_arguments() override;
453 
454 
455  /**
456  * Parameters for internally defined functions
457  * \return the method parameters
458  */
460 
461 
462  /**
463  * Arguments for external functions called from generated code
464  * \return A string representing the arguments passed to an external function
465  */
466  const char* external_method_arguments() noexcept override;
467 
468 
469  /**
470  * Parameters for functions in generated code that are called back from external code
471  *
472  * Functions registered in NEURON during initialization for callback must adhere to a prescribed
473  * calling convention. This method generates the string representing the function parameters for
474  * these externally called functions.
475  * \param table
476  * \return A string representing the parameters of the function
477  */
478  const char* external_method_parameters(bool table = false) noexcept override;
479 
480 
481  /**
482  * Arguments for "_threadargs_" macro in neuron implementation
483  */
484  std::string nrn_thread_arguments() const override;
485 
486 
487  /**
488  * Arguments for "_threadargs_" macro in neuron implementation
489  */
490  std::string nrn_thread_internal_arguments() override;
491 
492 
493  /**
494  * Replace commonly used verbatim variables
495  * \param name A variable name to be checked and possibly updated
496  * \return The possibly replace variable name
497  */
498  std::string replace_if_verbatim_variable(std::string name);
499 
500 
501  /**
502  * Process a verbatim block for possible variable renaming
503  * \param text The verbatim code to be processed
504  * \return The code with all variables renamed as needed
505  */
506  std::string process_verbatim_text(std::string const& text) override;
507 
508 
509  /**
510  * Arguments for register_mech or point_register_mech function
511  */
512  std::string register_mechanism_arguments() const override;
513 
514 
515  /**
516  * Generate Function call statement for nrn_wrote_conc
517  * \param ion_name The name of the ion variable
518  * \param concentration The name of the concentration variable
519  * \param index
520  * \return The string representing the function call
521  */
522  std::string conc_write_statement(const std::string& ion_name,
523  const std::string& concentration,
524  int index) override;
525 
526  /****************************************************************************************/
527  /* Code-specific printing routines for code generations */
528  /****************************************************************************************/
529 
530 
531  /**
532  * Print the getter method for index position of first pointer variable
533  *
534  */
536 
537 
538  /**
539  * Print the getter method for index position of first RANDOM variable
540  *
541  */
543 
544 
545  /**
546  * Print the getter methods for float and integer variables count
547  *
548  */
550 
551 
552  /**
553  * Print the getter method for getting number of arguments for net_receive
554  *
555  */
557 
558 
559  /**
560  * Print the getter method for returning mechtype
561  *
562  */
563  void print_mech_type_getter();
564 
565 
566  /**
567  * Print the getter method for returning membrane list from NrnThread
568  *
569  */
570  void print_memb_list_getter();
571 
572 
573  /**
574  * Prints the start of the \c coreneuron namespace
575  */
576  void print_namespace_start() override;
577 
578 
579  /**
580  * Prints the end of the \c coreneuron namespace
581  */
582  void print_namespace_stop() override;
583 
584 
585  /**
586  * Print the getter method for thread variables and ids
587  *
588  */
589  void print_thread_getters();
590 
591 
592  /****************************************************************************************/
593  /* Routines for returning variable name */
594  /****************************************************************************************/
595 
596 
597  /**
598  * Determine the name of a \c float variable given its symbol
599  *
600  * This function typically returns the accessor expression in backend code for the given symbol.
601  * Since the model variables are stored in data arrays and accessed by offset, this function
602  * will return the C++ string representing the array access at the correct offset
603  *
604  * \param symbol The symbol of a variable for which we want to obtain its name
605  * \param use_instance Should the variable be accessed via instance or data array
606  * \return The backend code string representing the access to the given variable
607  * symbol
608  */
609  std::string float_variable_name(const SymbolType& symbol, bool use_instance) const override;
610 
611 
612  /**
613  * Determine the name of an \c int variable given its symbol
614  *
615  * This function typically returns the accessor expression in backend code for the given symbol.
616  * Since the model variables are stored in data arrays and accessed by offset, this function
617  * will return the C++ string representing the array access at the correct offset
618  *
619  * \param symbol The symbol of a variable for which we want to obtain its name
620  * \param name The name of the index variable
621  * \param use_instance Should the variable be accessed via instance or data array
622  * \return The backend code string representing the access to the given variable
623  * symbol
624  */
625  std::string int_variable_name(const IndexVariableInfo& symbol,
626  const std::string& name,
627  bool use_instance) const override;
628 
629 
630  /**
631  * Determine the variable name for a global variable given its symbol
632  * \param symbol The symbol of a variable for which we want to obtain its name
633  * \param use_instance Should the variable be accessed via the (host-only)
634  * global variable or the instance-specific copy (also available on GPU).
635  * \return The C++ string representing the access to the global variable
636  */
637  std::string global_variable_name(const SymbolType& symbol,
638  bool use_instance = true) const override;
639 
640 
641  /**
642  * Determine variable name in the structure of mechanism properties
643  *
644  * \param name Variable name that is being printed
645  * \param use_instance Should the variable be accessed via instance or data array
646  * \return The C++ string representing the access to the variable in the neuron
647  * thread structure
648  */
649  std::string get_variable_name(const std::string& name, bool use_instance = true) const override;
650 
651 
652  /****************************************************************************************/
653  /* Main printing routines for code generation */
654  /****************************************************************************************/
655 
656 
657  /**
658  * Print top file header printed in generated code
659  */
660  void print_backend_info() override;
661 
662 
663  /**
664  * Print standard C/C++ includes
665  */
666  void print_standard_includes() override;
667 
668 
669  /**
670  * Print includes from coreneuron
671  */
673 
674 
675  void print_sdlists_init(bool print_initializers) override;
676 
677 
678  /**
679  * Print the structure that wraps all global variables used in the NMODL
680  *
681  * \param print_initializers Whether to include default values in the struct
682  * definition (true: int foo{42}; false: int foo;)
683  */
684  void print_mechanism_global_var_structure(bool print_initializers) override;
685 
686 
687  /**
688  * Print byte arrays that register scalar and vector variables for hoc interface
689  *
690  */
691  void print_global_variables_for_hoc() override;
692 
693 
694  /**
695  * Print the mechanism registration function
696  *
697  */
698  void print_mechanism_register() override;
699 
700 
701  /**
702  * Print thread related memory allocation and deallocation callbacks
703  */
705 
706 
707  /**
708  * Print structure of ion variables used for local copies
709  */
711 
712 
713  /**
714  * Print constructor of ion variables
715  * \param members The ion variable names
716  */
717  virtual void print_ion_var_constructor(const std::vector<std::string>& members);
718 
719 
720  /**
721  * Print the ion variable struct
722  */
723  virtual void print_ion_variable();
724 
725 
726  /**
727  * Print the pragma annotation to update global variables from host to the device
728  *
729  * \note This is not used for the C++ backend
730  */
732 
733 
734  /**
735  * Print the function that initialize range variable with different data type
736  */
738 
739 
740  /**
741  * Returns floating point type for given range variable symbol
742  * \param symbol A range variable symbol
743  */
744  std::string get_range_var_float_type(const SymbolType& symbol);
745 
746 
747  /**
748  * Print initial block statements
749  *
750  * Generate the target backend code corresponding to the NMODL initial block statements
751  *
752  * \param node The AST Node representing a NMODL initial block
753  */
754  void print_initial_block(const ast::InitialBlock* node);
755 
756 
757  /**
758  * Print common code for global functions like nrn_init, nrn_cur and nrn_state
759  * \param type The target backend code block type
760  */
762  const std::string& function_name = "") override;
763 
764 
765  /**
766  * Print the \c nrn\_init function definition
767  * \param skip_init_check \c true to generate code executing the initialization conditionally
768  */
769  void print_nrn_init(bool skip_init_check = true);
770 
771 
772  /**
773  * Print NMODL before / after block in target backend code
774  * \param node AST node of type before/after type being printed
775  * \param block_id Index of the before/after block
776  */
777  virtual void print_before_after_block(const ast::Block* node, size_t block_id);
778 
779 
780  /**
781  * Print nrn_constructor function definition
782  *
783  */
784  void print_nrn_constructor() override;
785 
786 
787  /**
788  * Print nrn_destructor function definition
789  *
790  */
791  void print_nrn_destructor() override;
792 
793 
794  /**
795  * Go through the map of \c EigenNewtonSolverBlock s and their corresponding functor names
796  * and print the functor definitions before the definitions of the functions of the generated
797  * file
798  *
799  */
801 
802 
803  /**
804  * Print nrn_alloc function definition
805  *
806  */
807  void print_nrn_alloc() override;
808 
809 
810  /**
811  * Print watch activate function
812  *
813  */
814  void print_watch_activate();
815 
816 
817  /**
818  * Print watch activate function
819  */
820  void print_watch_check();
821 
822 
823  /**
824  * Print the common code section for net receive related methods
825  *
826  * \param node The AST node representing the corresponding NMODL block
827  * \param need_mech_inst \c true if a local \c inst variable needs to be defined in generated
828  * code
829  */
830  void print_net_receive_common_code(const ast::Block& node, bool need_mech_inst = true);
831 
832 
833  /**
834  * Print call to \c net\_send
835  * \param node The AST node representing the function call
836  */
837  void print_net_send_call(const ast::FunctionCall& node) override;
838 
839 
840  /**
841  * Print call to net\_move
842  * \param node The AST node representing the function call
843  */
844  void print_net_move_call(const ast::FunctionCall& node) override;
845 
846 
847  /**
848  * Print call to net\_event
849  * \param node The AST node representing the function call
850  */
851  void print_net_event_call(const ast::FunctionCall& node) override;
852 
853 
854  /**
855  * Print initial block in the net receive block
856  */
857  void print_net_init();
858 
859 
860  /**
861  * Print send event move block used in net receive as well as watch
862  */
863  void print_send_event_move();
864 
865 
866  /**
867  * Generate the target backend code for the \c net\_receive\_buffering function delcaration
868  * \return The target code string
869  */
870  virtual std::string net_receive_buffering_declaration();
871 
872 
873  /**
874  * Print the target backend code for defining and checking a local \c Memb\_list variable
875  */
876  virtual void print_get_memb_list();
877 
878 
879  /**
880  * Print the code for the main \c net\_receive loop
881  */
882  virtual void print_net_receive_loop_begin();
883 
884 
885  /**
886  * Print the code for closing the main \c net\_receive loop
887  */
888  virtual void print_net_receive_loop_end();
889 
890 
891  /**
892  * Print kernel for buffering net_receive events
893  *
894  * This kernel is only needed for accelerator backends where \c net\_receive needs to be
895  * executed in two stages as the actual communication must be done in the host code. \param
896  * need_mech_inst \c true if the generated code needs a local inst variable to be defined
897  */
898  void print_net_receive_buffering(bool need_mech_inst = true);
899 
900 
901  /**
902  * Print the code related to the update of NetSendBuffer_t cnt. For GPU this needs to be done
903  * with atomic operation, on CPU it's not needed.
904  *
905  */
906  virtual void print_net_send_buffering_cnt_update() const;
907 
908 
909  /**
910  * Print statement that grows NetSendBuffering_t structure if needed.
911  * This function should be overridden for backends that cannot dynamically reallocate the buffer
912  */
913  virtual void print_net_send_buffering_grow();
914 
915 
916  /**
917  * Print kernel for buffering net_send events
918  *
919  * This kernel is only needed for accelerator backends where \c net\_send needs to be executed
920  * in two stages as the actual communication must be done in the host code.
921  */
923 
924 
925  /**
926  * Print \c net\_receive kernel function definition
927  */
929 
930 
931  /**
932  * Print \c net\_receive function definition
933  */
934  void print_net_receive();
935 
936 
937  /**
938  * Print derivative kernel when \c derivimplicit method is used
939  *
940  * \param block The corresponding AST node representing an NMODL \c derivimplicit block
941  */
942  void print_derivimplicit_kernel(const ast::Block& block);
943 
944 
945  /**
946  * Print code block to transfer newtonspace structure to device
947  */
948  virtual void print_newtonspace_transfer_to_device() const;
949 
950 
951  /****************************************************************************************/
952  /* Print nrn_state routine */
953  /****************************************************************************************/
954 
955 
956  /**
957  * Print nrn_state / state update function definition
958  */
959  void print_nrn_state() override;
960 
961 
962  /****************************************************************************************/
963  /* Print nrn_cur related routines */
964  /****************************************************************************************/
965 
966 
967  /**
968  * Print the \c nrn_current kernel
969  *
970  * \note nrn_cur_kernel will have two calls to nrn_current if no conductance keywords specified
971  * \param node the AST node representing the NMODL breakpoint block
972  */
973  void print_nrn_current(const ast::BreakpointBlock& node) override;
974 
975 
976  /**
977  * Print the \c nrn\_cur kernel with NMODL \c conductance keyword provisions
978  *
979  * If the NMODL \c conductance keyword is used in the \c breakpoint block, then
980  * CodegenCoreneuronCppVisitor::print_nrn_cur_kernel will use this printer
981  *
982  * \param node the AST node representing the NMODL breakpoint block
983  */
984  void print_nrn_cur_conductance_kernel(const ast::BreakpointBlock& node) override;
985 
986 
987  /**
988  * Print the \c nrn\_cur kernel without NMODL \c conductance keyword provisions
989  *
990  * If the NMODL \c conductance keyword is \b not used in the \c breakpoint block, then
991  * CodegenCoreneuronCppVisitor::print_nrn_cur_kernel will use this printer
992  */
993  void print_nrn_cur_non_conductance_kernel() override;
994 
995 
996  /**
997  * Print main body of nrn_cur function
998  * \param node the AST node representing the NMODL breakpoint block
999  */
1000  void print_nrn_cur_kernel(const ast::BreakpointBlock& node) override;
1001 
1002 
1003  /**
1004  * Print fast membrane current calculation code
1005  */
1006  virtual void print_fast_imem_calculation() override;
1007 
1008 
1009  /**
1010  * Print nrn_cur / current update function definition
1011  */
1012  void print_nrn_cur() override;
1013 
1014 
1015  /****************************************************************************************/
1016  /* Main code printing entry points */
1017  /****************************************************************************************/
1018 
1019 
1020  /**
1021  * Print all includes
1022  *
1023  */
1024  void print_headers_include() override;
1025 
1026 
1027  /**
1028  * Print start of namespaces
1029  *
1030  */
1031  void print_namespace_begin() override;
1032 
1033 
1034  /**
1035  * Print end of namespaces
1036  *
1037  */
1038  void print_namespace_end() override;
1039 
1040 
1041  /**
1042  * Print common getters
1043  *
1044  */
1045  void print_common_getters();
1046 
1047 
1048  /**
1049  * Print all classes
1050  * \param print_initializers Whether to include default values.
1051  */
1052  void print_data_structures(bool print_initializers) override;
1053 
1054 
1055  /**
1056  * Set v_unused (voltage) for NRN_PRCELLSTATE feature
1057  */
1058  void print_v_unused() const override;
1059 
1060 
1061  /**
1062  * Set g_unused (conductance) for NRN_PRCELLSTATE feature
1063  */
1064  void print_g_unused() const override;
1065 
1066 
1067  /**
1068  * Print all compute functions for every backend
1069  *
1070  */
1071  virtual void print_compute_functions() override;
1072 
1073 
1074  /**
1075  * Print entry point to code generation
1076  *
1077  */
1078  virtual void print_codegen_routines() override;
1079 
1080 
1081  /****************************************************************************************/
1082  /* Overloaded visitor routines */
1083  /****************************************************************************************/
1084 
1085 
1086  void visit_derivimplicit_callback(const ast::DerivimplicitCallback& node) override;
1087  void visit_eigen_newton_solver_block(const ast::EigenNewtonSolverBlock& node) override;
1088  void visit_eigen_linear_solver_block(const ast::EigenLinearSolverBlock& node) override;
1089  void visit_for_netcon(const ast::ForNetcon& node) override;
1090  virtual void visit_watch_statement(const ast::WatchStatement& node) override;
1091 
1092 
1093  /**
1094  * Print prototype declarations of functions or procedures
1095  * \tparam T The AST node type of the node (must be of nmodl::ast::Ast or subclass)
1096  * \param node The AST node representing the function or procedure block
1097  * \param name A user defined name for the function
1098  */
1099  template <typename T>
1100  void print_function_declaration(const T& node, const std::string& name);
1101 
1102 
1103  public:
1104  /****************************************************************************************/
1105  /* Public printing routines for code generation for use in unit tests */
1106  /****************************************************************************************/
1107 
1108 
1109  /**
1110  * Print the function that initialize instance structure
1111  */
1113 
1114 
1115  /**
1116  * Print the structure that wraps all range and int variables required for the NMODL
1117  *
1118  * \param print_initializers Whether or not default values for variables
1119  * be included in the struct declaration.
1120  */
1121  void print_mechanism_range_var_structure(bool print_initializers) override;
1122 };
1123 
1124 
1125 /**
1126  * \details If there is an argument with name (say alpha) same as range variable (say alpha),
1127  * we want to avoid it being printed as instance->alpha. And hence we disable variable
1128  * name lookup during prototype declaration. Note that the name of procedure can be
1129  * different in case of table statement.
1130  */
1131 template <typename T>
1133  const std::string& name) {
1135  auto type = default_float_data_type();
1136 
1137  // internal and user provided arguments
1138  auto internal_params = internal_method_parameters();
1139  const auto& params = node.get_parameters();
1140  for (const auto& param: params) {
1141  internal_params.emplace_back("", type, "", param.get()->get_node_name());
1142  }
1143 
1144  // procedures have "int" return type by default
1145  const char* return_type = "int";
1146  if (node.is_function_block()) {
1147  return_type = default_float_data_type();
1148  }
1149 
1151  printer->add_indent();
1152  printer->fmt_text("inline {} {}({})",
1153  return_type,
1154  method_name(name),
1155  get_parameter_str(internal_params));
1156 
1158 }
1159 
1160 /** \} */ // end of codegen_backends
1161 
1162 } // namespace codegen
1163 } // namespace nmodl
nmodl::codegen::CodegenCoreneuronCppVisitor::print_procedure
virtual void print_procedure(const ast::ProcedureBlock &node) override
Print NMODL procedure in target backend code.
Definition: codegen_coreneuron_cpp_visitor.cpp:703
nmodl::codegen::CodegenCoreneuronCppVisitor::print_device_method_annotation
virtual void print_device_method_annotation()
Print the backend specific device method annotation.
Definition: codegen_coreneuron_cpp_visitor.cpp:306
nmodl::codegen::CodegenCoreneuronCppVisitor::print_coreneuron_includes
void print_coreneuron_includes()
Print includes from coreneuron.
Definition: codegen_coreneuron_cpp_visitor.cpp:1378
nmodl::codegen::CodegenCoreneuronCppVisitor::net_receive_buffering_declaration
virtual std::string net_receive_buffering_declaration()
Generate the target backend code for the net_receive_buffering function delcaration.
Definition: codegen_coreneuron_cpp_visitor.cpp:2816
nmodl::codegen::CodegenCoreneuronCppVisitor::nrn_cur_reduction_loop_required
virtual bool nrn_cur_reduction_loop_required()
Check if reduction block in nrn_cur required.
Definition: codegen_coreneuron_cpp_visitor.cpp:259
nmodl::codegen::CodegenCoreneuronCppVisitor::print_backend_namespace_start
virtual void print_backend_namespace_start()
Prints the start of namespace for the backend-specific code.
Definition: codegen_coreneuron_cpp_visitor.cpp:316
nmodl::codegen::CodegenCoreneuronCppVisitor::print_net_move_call
void print_net_move_call(const ast::FunctionCall &node) override
Print call to net_move.
Definition: codegen_coreneuron_cpp_visitor.cpp:2684
nmodl::codegen::CodegenCoreneuronCppVisitor::print_mechanism_range_var_structure
void print_mechanism_range_var_structure(bool print_initializers) override
Print the structure that wraps all range and int variables required for the NMODL.
Definition: codegen_coreneuron_cpp_visitor.cpp:1937
nmodl::codegen::CodegenCoreneuronCppVisitor::print_net_send_buf_count_update_to_host
virtual void print_net_send_buf_count_update_to_host() const
Print the code to update NetSendBuffer_t count from device to host.
Definition: codegen_coreneuron_cpp_visitor.cpp:165
nmodl::codegen::CodegenCoreneuronCppVisitor
Visitor for printing C++ code compatible with legacy api of CoreNEURON
Definition: codegen_coreneuron_cpp_visitor.hpp:62
nmodl::codegen::CodegenCoreneuronCppVisitor::print_function_prototypes
void print_function_prototypes() override
Print function and procedures prototype declaration.
Definition: codegen_coreneuron_cpp_visitor.cpp:390
nmodl::codegen::CodegenCoreneuronCppVisitor::print_functors_definitions
void print_functors_definitions()
Go through the map of EigenNewtonSolverBlock s and their corresponding functor names and print the fu...
Definition: codegen_coreneuron_cpp_visitor.cpp:2450
nmodl::codegen::CodegenCoreneuronCppVisitor::print_namespace_stop
void print_namespace_stop() override
Prints the end of the coreneuron namespace.
Definition: codegen_coreneuron_cpp_visitor.cpp:1153
nmodl::codegen::IndexVariableInfo
Helper to represent information about index/int variables.
Definition: codegen_cpp_visitor.hpp:111
nmodl::codegen::CodegenCoreneuronCppVisitor::print_v_unused
void print_v_unused() const override
Set v_unused (voltage) for NRN_PRCELLSTATE feature.
Definition: codegen_coreneuron_cpp_visitor.cpp:3411
nmodl::codegen::CodegenCoreneuronCppVisitor::print_ion_variable
virtual void print_ion_variable()
Print the ion variable struct.
Definition: codegen_coreneuron_cpp_visitor.cpp:2026
nmodl::codegen::CodegenCoreneuronCppVisitor::print_derivimplicit_kernel
void print_derivimplicit_kernel(const ast::Block &block)
Print derivative kernel when derivimplicit method is used.
Definition: codegen_coreneuron_cpp_visitor.cpp:3028
nmodl::codegen::CodegenCoreneuronCppVisitor::print_device_stream_wait
virtual void print_device_stream_wait() const
Print the code to synchronise/wait on stream specific to NrnThread.
Definition: codegen_coreneuron_cpp_visitor.cpp:185
nmodl::codegen::CodegenCoreneuronCppVisitor::print_instance_struct_delete_from_device
virtual void print_instance_struct_delete_from_device()
Delete the instance struct from the device.
Definition: codegen_coreneuron_cpp_visitor.hpp:343
nmodl::codegen::CodegenCoreneuronCppVisitor::print_net_send_buf_count_update_to_device
virtual void print_net_send_buf_count_update_to_device() const
Print the code to update NetSendBuffer_t count from host to device.
Definition: codegen_coreneuron_cpp_visitor.cpp:175
nmodl::codegen::CodegenCppVisitor::info
codegen::CodegenInfo info
All ast information for code generation.
Definition: codegen_cpp_visitor.hpp:284
nmodl::codegen::CodegenCoreneuronCppVisitor::print_functor_definition
void print_functor_definition(const ast::EigenNewtonSolverBlock &node)
Based on the EigenNewtonSolverBlock passed print the definition needed for its functor.
Definition: codegen_coreneuron_cpp_visitor.cpp:802
nmodl::codegen::CodegenCoreneuronCppVisitor::global_variable_name
std::string global_variable_name(const SymbolType &symbol, bool use_instance=true) const override
Determine the variable name for a global variable given its symbol.
Definition: codegen_coreneuron_cpp_visitor.cpp:1264
nmodl::ast::FunctionBlock
TODO.
Definition: function_block.hpp:39
nmodl::codegen::CodegenCoreneuronCppVisitor::visit_eigen_linear_solver_block
void visit_eigen_linear_solver_block(const ast::EigenLinearSolverBlock &node) override
visit node of type ast::EigenLinearSolverBlock
Definition: codegen_coreneuron_cpp_visitor.cpp:3530
nmodl::codegen::CodegenCoreneuronCppVisitor::print_newtonspace_transfer_to_device
virtual void print_newtonspace_transfer_to_device() const
Print code block to transfer newtonspace structure to device.
Definition: codegen_coreneuron_cpp_visitor.cpp:3117
nmodl::codegen::CodegenInfo::thread_data_index
int thread_data_index
thread_data_index indicates number of threads being allocated.
Definition: codegen_info.hpp:262
nmodl::codegen::CodegenCoreneuronCppVisitor::print_namespace_end
void print_namespace_end() override
Print end of namespaces.
Definition: codegen_coreneuron_cpp_visitor.cpp:3387
nmodl::codegen::CodegenCoreneuronCppVisitor::print_net_send_call
void print_net_send_call(const ast::FunctionCall &node) override
Print call to net_send.
Definition: codegen_coreneuron_cpp_visitor.cpp:2652
nmodl::codegen::CodegenCoreneuronCppVisitor::print_net_receive_loop_begin
virtual void print_net_receive_loop_begin()
Print the code for the main net_receive loop.
Definition: codegen_coreneuron_cpp_visitor.cpp:2830
nmodl::codegen::CodegenCoreneuronCppVisitor::print_kernel_data_present_annotation_block_begin
virtual void print_kernel_data_present_annotation_block_begin()
Print accelerator annotations indicating data presence on device.
Definition: codegen_coreneuron_cpp_visitor.cpp:204
nmodl::ast::FunctionTableBlock
TODO.
Definition: function_table_block.hpp:39
nmodl::codegen::CodegenCoreneuronCppVisitor::print_backend_info
void print_backend_info() override
Print top file header printed in generated code.
Definition: codegen_coreneuron_cpp_visitor.cpp:1347
nmodl::codegen::CodegenCoreneuronCppVisitor::print_g_unused
void print_g_unused() const override
Set g_unused (conductance) for NRN_PRCELLSTATE feature.
Definition: codegen_coreneuron_cpp_visitor.cpp:3423
nmodl::codegen::CodegenCoreneuronCppVisitor::print_common_getters
void print_common_getters()
Print common getters.
Definition: codegen_coreneuron_cpp_visitor.cpp:3393
nmodl::codegen::CodegenCoreneuronCppVisitor::int_variable_name
std::string int_variable_name(const IndexVariableInfo &symbol, const std::string &name, bool use_instance) const override
Determine the name of an int variable given its symbol.
Definition: codegen_coreneuron_cpp_visitor.cpp:1238
nmodl::codegen::CodegenCoreneuronCppVisitor::check_if_var_is_array
std::tuple< bool, int > check_if_var_is_array(const std::string &name)
Check if the given name exist in the symbol.
Definition: codegen_coreneuron_cpp_visitor.cpp:424
nmodl::codegen::CodegenCoreneuronCppVisitor::print_initial_block
void print_initial_block(const ast::InitialBlock *node)
Print initial block statements.
Definition: codegen_coreneuron_cpp_visitor.cpp:2196
nmodl::codegen::CodegenCoreneuronCppVisitor::print_net_receive_kernel
void print_net_receive_kernel()
Print net_receive kernel function definition.
Definition: codegen_coreneuron_cpp_visitor.cpp:2928
nmodl::codegen::CodegenCoreneuronCppVisitor::print_thread_getters
void print_thread_getters()
Print the getter method for thread variables and ids.
Definition: codegen_coreneuron_cpp_visitor.cpp:1169
nmodl::codegen::CodegenCoreneuronCppVisitor::simulator_name
std::string simulator_name() override
Name of the simulator the code was generated for.
Definition: codegen_coreneuron_cpp_visitor.cpp:56
nmodl::codegen::CodegenCoreneuronCppVisitor::print_net_send_buffering
void print_net_send_buffering()
Print kernel for buffering net_send events.
Definition: codegen_coreneuron_cpp_visitor.cpp:2900
nmodl
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
nmodl::codegen::CodegenCoreneuronCppVisitor::num_thread_objects
int num_thread_objects() const noexcept
Determine the number of threads to allocate.
Definition: codegen_coreneuron_cpp_visitor.hpp:92
nmodl::codegen::CodegenCoreneuronCppVisitor::print_fast_imem_calculation
virtual void print_fast_imem_calculation() override
Print fast membrane current calculation code.
Definition: codegen_coreneuron_cpp_visitor.cpp:3308
nmodl::codegen::CodegenCoreneuronCppVisitor::print_function_declaration
void print_function_declaration(const T &node, const std::string &name)
Print prototype declarations of functions or procedures.
Definition: codegen_coreneuron_cpp_visitor.hpp:1132
nmodl::codegen::CodegenCoreneuronCppVisitor::print_dt_update_to_device
virtual void print_dt_update_to_device() const
Print the code to update dt from host to device.
Definition: codegen_coreneuron_cpp_visitor.cpp:180
nmodl::codegen::CodegenCoreneuronCppVisitor::print_net_init_acc_serial_annotation_block_end
virtual void print_net_init_acc_serial_annotation_block_end()
Print accelerator kernels end annotation for net_init kernel.
Definition: codegen_coreneuron_cpp_visitor.cpp:219
nmodl::codegen::CodegenCoreneuronCppVisitor::print_net_init
void print_net_init()
Print initial block in the net receive block.
Definition: codegen_coreneuron_cpp_visitor.cpp:2763
nmodl::codegen::CodegenCoreneuronCppVisitor::print_net_event_call
void print_net_event_call(const ast::FunctionCall &node) override
Print call to net_event.
Definition: codegen_coreneuron_cpp_visitor.cpp:2711
nmodl::codegen::CodegenCoreneuronCppVisitor::print_nrn_destructor
void print_nrn_destructor() override
Print nrn_destructor function definition.
Definition: codegen_coreneuron_cpp_visitor.cpp:2438
nmodl::codegen::CodegenCoreneuronCppVisitor::print_sdlists_init
void print_sdlists_init(bool print_initializers) override
Definition: codegen_coreneuron_cpp_visitor.cpp:1411
symbol_table.hpp
Implement classes for representing symbol table at block and file scope.
nmodl::codegen::CodegenCoreneuronCppVisitor::print_headers_include
void print_headers_include() override
Print all includes.
Definition: codegen_coreneuron_cpp_visitor.cpp:3374
nmodl::codegen::CodegenCoreneuronCppVisitor::print_send_event_move
void print_send_event_move()
Print send event move block used in net receive as well as watch.
Definition: codegen_coreneuron_cpp_visitor.cpp:2795
nmodl::codegen::CodegenCoreneuronCppVisitor::print_table_replacement_function
void print_table_replacement_function(const ast::Block &node)
Print replacement function for function or procedure using table.
Definition: codegen_coreneuron_cpp_visitor.cpp:535
nmodl::codegen::CodegenCoreneuronCppVisitor::print_atomic_reduction_pragma
virtual void print_atomic_reduction_pragma() override
Print atomic update pragma for reduction statements.
Definition: codegen_coreneuron_cpp_visitor.cpp:301
nmodl::codegen::CodegenCoreneuronCppVisitor::print_instance_struct_copy_to_device
virtual void print_instance_struct_copy_to_device()
Transfer the instance struct to the device.
Definition: codegen_coreneuron_cpp_visitor.hpp:336
nmodl::codegen::CodegenCoreneuronCppVisitor::print_global_variables_for_hoc
void print_global_variables_for_hoc() override
Print byte arrays that register scalar and vector variables for hoc interface.
Definition: codegen_coreneuron_cpp_visitor.cpp:1625
nmodl::SymbolType
parser::NmodlParser::symbol_type SymbolType
Definition: nmodl_utils.hpp:26
nmodl::codegen::CodegenCoreneuronCppVisitor::print_function_or_procedure
void print_function_or_procedure(const ast::Block &node, const std::string &name) override
Print nmodl function or procedure (common code)
Definition: codegen_coreneuron_cpp_visitor.cpp:668
nmodl::codegen::CodegenCoreneuronCppVisitor::print_net_receive_common_code
void print_net_receive_common_code(const ast::Block &node, bool need_mech_inst=true)
Print the common code section for net receive related methods.
Definition: codegen_coreneuron_cpp_visitor.cpp:2601
nmodl::codegen::CodegenCoreneuronCppVisitor::print_nrn_current
void print_nrn_current(const ast::BreakpointBlock &node) override
Print the nrn_current kernel.
Definition: codegen_coreneuron_cpp_visitor.cpp:3182
nmodl::codegen::CodegenCppVisitor::default_float_data_type
const char * default_float_data_type() const noexcept
Default data type for floating point elements.
Definition: codegen_cpp_visitor.hpp:423
nmodl::codegen::CodegenCoreneuronCppVisitor::conc_write_statement
std::string conc_write_statement(const std::string &ion_name, const std::string &concentration, int index) override
Generate Function call statement for nrn_wrote_conc.
Definition: codegen_coreneuron_cpp_visitor.cpp:1053
nmodl::codegen::CodegenCoreneuronCppVisitor::print_first_pointer_var_index_getter
void print_first_pointer_var_index_getter()
Print the getter method for index position of first pointer variable.
Definition: codegen_coreneuron_cpp_visitor.cpp:1080
nmodl::codegen::CodegenCoreneuronCppVisitor::print_setup_range_variable
void print_setup_range_variable()
Print the function that initialize range variable with different data type.
Definition: codegen_coreneuron_cpp_visitor.cpp:2036
nmodl::codegen::CodegenCoreneuronCppVisitor::internal_method_arguments
std::string internal_method_arguments() override
Arguments for functions that are defined and used internally.
Definition: codegen_coreneuron_cpp_visitor.cpp:911
nmodl::codegen::CodegenCoreneuronCppVisitor::print_instance_struct_transfer_routine_declarations
virtual void print_instance_struct_transfer_routine_declarations()
Print declarations of the functions used by print_instance_struct_copy_to_device and print_instance_s...
Definition: codegen_coreneuron_cpp_visitor.hpp:314
nmodl::codegen::CodegenCoreneuronCppVisitor::nrn_thread_arguments
std::string nrn_thread_arguments() const override
Arguments for "_threadargs_" macro in neuron implementation.
Definition: codegen_coreneuron_cpp_visitor.cpp:954
nmodl::ast::EigenNewtonSolverBlock
Represent newton solver solution block based on Eigen.
Definition: eigen_newton_solver_block.hpp:38
nmodl::codegen::CodegenCoreneuronCppVisitor::print_net_receive_arg_size_getter
void print_net_receive_arg_size_getter()
Print the getter method for getting number of arguments for net_receive.
Definition: codegen_coreneuron_cpp_visitor.cpp:1113
nmodl::codegen::CodegenCoreneuronCppVisitor::is_functor_const
bool is_functor_const(const ast::StatementBlock &variable_block, const ast::StatementBlock &functor_block)
Checks whether the functor_block generated by sympy solver modifies any variable outside its scope.
Definition: codegen_coreneuron_cpp_visitor.cpp:766
codegen_cpp_visitor.hpp
Visitor for printing C++ code compatible with legacy api of CoreNEURON
codegen_naming.hpp
nmodl::ast::Block
Base class for all block scoped nodes.
Definition: block.hpp:41
nmodl::ast::InitialBlock
Represents a INITIAL block in the NMODL.
Definition: initial_block.hpp:49
nmodl::codegen::CodegenCoreneuronCppVisitor::print_nrn_cur_matrix_shadow_update
virtual void print_nrn_cur_matrix_shadow_update()
Print the update to matrix elements with/without shadow vectors.
Definition: codegen_coreneuron_cpp_visitor.cpp:272
nmodl::codegen::CodegenCoreneuronCppVisitor::register_mechanism_arguments
std::string register_mechanism_arguments() const override
Arguments for register_mech or point_register_mech function.
Definition: codegen_coreneuron_cpp_visitor.cpp:1034
nmodl::codegen::CodegenCoreneuronCppVisitor::print_net_init_acc_serial_annotation_block_begin
virtual void print_net_init_acc_serial_annotation_block_begin()
Print accelerator kernels begin annotation for net_init kernel.
Definition: codegen_coreneuron_cpp_visitor.cpp:214
nmodl::codegen::CodegenCoreneuronCppVisitor::print_deriv_advance_flag_transfer_to_device
virtual void print_deriv_advance_flag_transfer_to_device() const
Print the code to copy derivative advance flag to device.
Definition: codegen_coreneuron_cpp_visitor.cpp:155
nmodl::codegen::CodegenCoreneuronCppVisitor::print_first_random_var_index_getter
void print_first_random_var_index_getter()
Print the getter method for index position of first RANDOM variable.
Definition: codegen_coreneuron_cpp_visitor.cpp:1089
nmodl::ast::WatchStatement
Represent WATCH statement in NMODL.
Definition: watch_statement.hpp:39
nmodl::codegen::CodegenCoreneuronCppVisitor::print_eigen_linear_solver
virtual void print_eigen_linear_solver(const std::string &float_type, int N)
Definition: codegen_coreneuron_cpp_visitor.cpp:869
nmodl::codegen::CodegenCoreneuronCppVisitor::print_before_after_block
virtual void print_before_after_block(const ast::Block *node, size_t block_id)
Print NMODL before / after block in target backend code.
Definition: codegen_coreneuron_cpp_visitor.cpp:2372
nmodl::ast::BreakpointBlock
Represents a BREAKPOINT block in NMODL.
Definition: breakpoint_block.hpp:53
nmodl::ast::FunctionCall
TODO.
Definition: function_call.hpp:38
code_printer.hpp
Helper class for printing C/C++ code.
nmodl::codegen::CodegenCoreneuronCppVisitor::print_ion_var_structure
void print_ion_var_structure()
Print structure of ion variables used for local copies.
Definition: codegen_coreneuron_cpp_visitor.cpp:1979
nmodl::codegen::CodegenCoreneuronCppVisitor::internal_method_parameters
ParamVector internal_method_parameters() override
Parameters for internally defined functions.
Definition: codegen_coreneuron_cpp_visitor.cpp:922
nmodl::codegen::CodegenCoreneuronCppVisitor::position_of_int_var
int position_of_int_var(const std::string &name) const override
Determine the position in the data array for a given int variable.
Definition: codegen_coreneuron_cpp_visitor.cpp:78
nmodl::codegen::CodegenCoreneuronCppVisitor::print_channel_iteration_block_parallel_hint
virtual void print_channel_iteration_block_parallel_hint(BlockType type, const ast::Block *block)
Print pragma annotations for channel iterations.
Definition: codegen_coreneuron_cpp_visitor.cpp:236
nmodl::codegen::CodegenCoreneuronCppVisitor::is_constant_variable
virtual bool is_constant_variable(const std::string &name) const
Check if variable is qualified as constant.
Definition: codegen_coreneuron_cpp_visitor.cpp:130
nmodl::codegen::CodegenCoreneuronCppVisitor::print_function_procedure_helper
void print_function_procedure_helper(const ast::Block &node) override
Common helper function to help printing function or procedure blocks.
Definition: codegen_coreneuron_cpp_visitor.cpp:689
nmodl::codegen::CodegenCoreneuronCppVisitor::external_method_parameters
const char * external_method_parameters(bool table=false) noexcept override
Parameters for functions in generated code that are called back from external code.
Definition: codegen_coreneuron_cpp_visitor.cpp:944
nmodl::codegen::CodegenCoreneuronCppVisitor::visit_for_netcon
void visit_for_netcon(const ast::ForNetcon &node) override
visit node of type ast::ForNetcon
Definition: codegen_coreneuron_cpp_visitor.cpp:3556
nmodl::codegen::CodegenCoreneuronCppVisitor::print_compute_functions
virtual void print_compute_functions() override
Print all compute functions for every backend.
Definition: codegen_coreneuron_cpp_visitor.cpp:3432
nmodl::codegen::CodegenCoreneuronCppVisitor::print_nrn_cur_conductance_kernel
void print_nrn_cur_conductance_kernel(const ast::BreakpointBlock &node) override
Print the nrn_cur kernel with NMODL conductance keyword provisions.
Definition: codegen_coreneuron_cpp_visitor.cpp:3201
nmodl::codegen::CodegenCoreneuronCppVisitor::print_memory_allocation_routine
virtual void print_memory_allocation_routine() const
Print memory allocation routine.
Definition: codegen_coreneuron_cpp_visitor.cpp:336
nmodl::codegen::CodegenCoreneuronCppVisitor::print_check_table_thread_function
void print_check_table_thread_function()
Print check_table functions.
Definition: codegen_coreneuron_cpp_visitor.cpp:644
nmodl::codegen::CodegenCoreneuronCppVisitor::print_namespace_begin
void print_namespace_begin() override
Print start of namespaces.
Definition: codegen_coreneuron_cpp_visitor.cpp:3381
nmodl::codegen::CodegenCoreneuronCppVisitor::backend_name
virtual std::string backend_name() const override
Name of the code generation backend.
Definition: codegen_coreneuron_cpp_visitor.cpp:51
nmodl::codegen::CodegenCoreneuronCppVisitor::print_rhs_d_shadow_variables
virtual void print_rhs_d_shadow_variables()
Print the setup method for setting matrix shadow vectors.
Definition: codegen_coreneuron_cpp_visitor.cpp:264
nmodl::codegen::CodegenCoreneuronCppVisitor::process_verbatim_text
std::string process_verbatim_text(std::string const &text) override
Process a verbatim block for possible variable renaming.
Definition: codegen_coreneuron_cpp_visitor.cpp:1007
nmodl::codegen::CodegenCoreneuronCppVisitor::print_net_receive
void print_net_receive()
Print net_receive function definition.
Definition: codegen_coreneuron_cpp_visitor.cpp:2987
nmodl::codegen::CodegenInfo::vectorize
bool vectorize
true if mod file is vectorizable (which should be always true for coreneuron) But there are some bloc...
Definition: codegen_info.hpp:212
nmodl::codegen::CodegenCoreneuronCppVisitor::optimize_ion_variable_copies
bool optimize_ion_variable_copies() const override
Check if ion variable copies should be avoided.
Definition: codegen_coreneuron_cpp_visitor.cpp:331
nmodl::codegen::CodegenCoreneuronCppVisitor::print_function
void print_function(const ast::FunctionBlock &node) override
Print NMODL function in target backend code.
Definition: codegen_coreneuron_cpp_visitor.cpp:708
nmodl::codegen::CodegenCoreneuronCppVisitor::print_top_verbatim_blocks
void print_top_verbatim_blocks()
Print top level (global scope) verbatim blocks.
Definition: codegen_coreneuron_cpp_visitor.cpp:366
codegen_info.hpp
Various types to store code generation specific information.
nmodl::ast::EigenLinearSolverBlock
Represent linear solver solution block based on Eigen.
Definition: eigen_linear_solver_block.hpp:38
nmodl::codegen::CodegenCoreneuronCppVisitor::print_mechanism_global_var_structure
void print_mechanism_global_var_structure(bool print_initializers) override
Print the structure that wraps all global variables used in the NMODL.
Definition: codegen_coreneuron_cpp_visitor.cpp:1478
nmodl::codegen::CodegenCoreneuronCppVisitor::visit_eigen_newton_solver_block
void visit_eigen_newton_solver_block(const ast::EigenNewtonSolverBlock &node) override
visit node of type ast::EigenNewtonSolverBlock
Definition: codegen_coreneuron_cpp_visitor.cpp:3502
nmodl::codegen::CodegenCoreneuronCppVisitor::print_nrn_constructor
void print_nrn_constructor() override
Print nrn_constructor function definition.
Definition: codegen_coreneuron_cpp_visitor.cpp:2426
nmodl::codegen::CodegenCoreneuronCppVisitor::print_kernel_data_present_annotation_block_end
virtual void print_kernel_data_present_annotation_block_end()
Print matching block end of accelerator annotations for data presence on device.
Definition: codegen_coreneuron_cpp_visitor.cpp:209
nmodl::codegen::CodegenCoreneuronCppVisitor::print_instance_struct_transfer_routines
virtual void print_instance_struct_transfer_routines(std::vector< std::string > const &)
Print the definitions of the functions used by print_instance_struct_copy_to_device and print_instanc...
Definition: codegen_coreneuron_cpp_visitor.hpp:328
nmodl::codegen::CodegenCoreneuronCppVisitor::print_nrn_alloc
void print_nrn_alloc() override
Print nrn_alloc function definition.
Definition: codegen_coreneuron_cpp_visitor.cpp:2458
nmodl::codegen::CodegenCoreneuronCppVisitor::print_nrn_cur_matrix_shadow_reduction
virtual void print_nrn_cur_matrix_shadow_reduction()
Print the reduction to matrix elements from shadow vectors.
Definition: codegen_coreneuron_cpp_visitor.cpp:285
nmodl::codegen::CodegenCoreneuronCppVisitor::print_memb_list_getter
void print_memb_list_getter()
Print the getter method for returning membrane list from NrnThread.
Definition: codegen_coreneuron_cpp_visitor.cpp:1135
nmodl::codegen::CodegenCppVisitor::get_parameter_str
static std::string get_parameter_str(const ParamVector &params)
Generate the string representing the procedure parameter declaration.
Definition: codegen_cpp_visitor.cpp:34
nmodl::codegen::CodegenCoreneuronCppVisitor::print_watch_check
void print_watch_check()
Print watch activate function.
Definition: codegen_coreneuron_cpp_visitor.cpp:2519
nmodl::codegen::CodegenCoreneuronCppVisitor::external_method_arguments
const char * external_method_arguments() noexcept override
Arguments for external functions called from generated code.
Definition: codegen_coreneuron_cpp_visitor.cpp:939
nmodl::codegen::CodegenCoreneuronCppVisitor::print_instance_variable_setup
void print_instance_variable_setup()
Print the function that initialize instance structure.
Definition: codegen_coreneuron_cpp_visitor.cpp:2073
nmodl::codegen::CodegenCoreneuronCppVisitor::print_nrn_init
void print_nrn_init(bool skip_init_check=true)
Print the nrn_init function definition.
Definition: codegen_coreneuron_cpp_visitor.cpp:2297
nmodl::ast::StatementBlock
Represents block encapsulating list of statements.
Definition: statement_block.hpp:53
nmodl::codegen::CodegenCoreneuronCppVisitor::get_variable_name
std::string get_variable_name(const std::string &name, bool use_instance=true) const override
Determine variable name in the structure of mechanism properties.
Definition: codegen_coreneuron_cpp_visitor.cpp:1274
nmodl::codegen::CodegenCoreneuronCppVisitor::print_namespace_start
void print_namespace_start() override
Prints the start of the coreneuron namespace.
Definition: codegen_coreneuron_cpp_visitor.cpp:1147
nmodl::ast::ForNetcon
TODO.
Definition: for_netcon.hpp:39
nmodl::codegen::CodegenCoreneuronCppVisitor::print_abort_routine
virtual void print_abort_routine() const
Print backend specific abort routine.
Definition: codegen_coreneuron_cpp_visitor.cpp:353
nmodl::codegen::CodegenCoreneuronCppVisitor::print_table_check_function
void print_table_check_function(const ast::Block &node)
Print check_function() for functions or procedure using table.
Definition: codegen_coreneuron_cpp_visitor.cpp:438
nmodl::codegen::CodegenCoreneuronCppVisitor::print_nrn_cur
void print_nrn_cur() override
Print nrn_cur / current update function definition.
Definition: codegen_coreneuron_cpp_visitor.cpp:3337
nmodl::codegen::CodegenCoreneuronCppVisitor::get_range_var_float_type
std::string get_range_var_float_type(const SymbolType &symbol)
Returns floating point type for given range variable symbol.
Definition: codegen_coreneuron_cpp_visitor.cpp:2057
nmodl::codegen::CodegenCoreneuronCppVisitor::print_net_send_buffering_cnt_update
virtual void print_net_send_buffering_cnt_update() const
Print the code related to the update of NetSendBuffer_t cnt.
Definition: codegen_coreneuron_cpp_visitor.cpp:2888
nmodl::codegen::CodegenCoreneuronCppVisitor::print_thread_memory_callbacks
void print_thread_memory_callbacks()
Print thread related memory allocation and deallocation callbacks.
Definition: codegen_coreneuron_cpp_visitor.cpp:1874
nmodl::ast::DerivimplicitCallback
Represent a callback to NEURON's derivimplicit solver.
Definition: derivimplicit_callback.hpp:38
nmodl::ast::ProcedureBlock
TODO.
Definition: procedure_block.hpp:39
nmodl::codegen::CodegenCoreneuronCppVisitor::print_net_receive_buffering
void print_net_receive_buffering(bool need_mech_inst=true)
Print kernel for buffering net_receive events.
Definition: codegen_coreneuron_cpp_visitor.cpp:2842
nmodl::codegen::CodegenCoreneuronCppVisitor::print_global_function_common_code
virtual void print_global_function_common_code(BlockType type, const std::string &function_name="") override
Print common code for global functions like nrn_init, nrn_cur and nrn_state.
Definition: codegen_coreneuron_cpp_visitor.cpp:2246
nmodl::codegen::CodegenCppVisitor::CodegenCppVisitor
CodegenCppVisitor(std::string mod_filename, const std::string &output_dir, std::string float_type, const bool optimize_ionvar_copies, size_t blame_line=0)
Constructs the C++ code generator visitor.
Definition: codegen_cpp_visitor.hpp:198
nmodl::codegen::CodegenCppVisitor::float_type
std::string float_type
Data type of floating point variables.
Definition: codegen_cpp_visitor.hpp:272
logger.hpp
Implement logger based on spdlog library.
nmodl::codegen::CodegenCppVisitor::enable_variable_name_lookup
bool enable_variable_name_lookup
Variable name should be converted to instance name (but not for function arguments)
Definition: codegen_cpp_visitor.hpp:315
nmodl::codegen::BlockType
BlockType
Helper to represent various block types.
Definition: codegen_cpp_visitor.hpp:56
nmodl::codegen::CodegenCoreneuronCppVisitor::print_mechanism_register
void print_mechanism_register() override
Print the mechanism registration function.
Definition: codegen_coreneuron_cpp_visitor.cpp:1732
nmodl::codegen::CodegenCoreneuronCppVisitor::print_global_method_annotation
virtual void print_global_method_annotation()
Print backend specific global method annotation.
Definition: codegen_coreneuron_cpp_visitor.cpp:311
nmodl::codegen::CodegenCoreneuronCppVisitor::print_nrn_cur_kernel
void print_nrn_cur_kernel(const ast::BreakpointBlock &node) override
Print main body of nrn_cur function.
Definition: codegen_coreneuron_cpp_visitor.cpp:3272
nmodl::codegen::CodegenCoreneuronCppVisitor::nrn_thread_internal_arguments
std::string nrn_thread_internal_arguments() override
Arguments for "_threadargs_" macro in neuron implementation.
Definition: codegen_coreneuron_cpp_visitor.cpp:966
nmodl::codegen::CodegenCoreneuronCppVisitor::print_device_atomic_capture_annotation
virtual void print_device_atomic_capture_annotation() const
Print pragma annotation for increase and capture of variable in automatic way.
Definition: codegen_coreneuron_cpp_visitor.cpp:160
nmodl::codegen::CodegenCoreneuronCppVisitor::visit_derivimplicit_callback
void visit_derivimplicit_callback(const ast::DerivimplicitCallback &node) override
visit node of type ast::DerivimplicitCallback
Definition: codegen_coreneuron_cpp_visitor.cpp:3494
nmodl::codegen::CodegenCppVisitor
Visitor for printing C++ code compatible with legacy api of CoreNEURON
Definition: codegen_cpp_visitor.hpp:180
nmodl::codegen::CodegenCoreneuronCppVisitor::print_get_memb_list
virtual void print_get_memb_list()
Print the target backend code for defining and checking a local Memb_list variable.
Definition: codegen_coreneuron_cpp_visitor.cpp:2821
nmodl::codegen::CodegenCoreneuronCppVisitor::print_num_variable_getter
void print_num_variable_getter()
Print the getter methods for float and integer variables count.
Definition: codegen_coreneuron_cpp_visitor.cpp:1098
nmodl::codegen::CodegenCoreneuronCppVisitor::print_standard_includes
void print_standard_includes() override
Print standard C/C++ includes.
Definition: codegen_coreneuron_cpp_visitor.cpp:1367
nmodl::codegen::CodegenCoreneuronCppVisitor::print_net_receive_loop_end
virtual void print_net_receive_loop_end()
Print the code for closing the main net_receive loop.
Definition: codegen_coreneuron_cpp_visitor.cpp:2837
nmodl::codegen::CodegenCoreneuronCppVisitor::print_mech_type_getter
void print_mech_type_getter()
Print the getter method for returning mechtype.
Definition: codegen_coreneuron_cpp_visitor.cpp:1125
nmodl::codegen::CodegenCoreneuronCppVisitor::float_variable_name
std::string float_variable_name(const SymbolType &symbol, bool use_instance) const override
Determine the name of a float variable given its symbol.
Definition: codegen_coreneuron_cpp_visitor.cpp:1218
nmodl::codegen::CodegenCoreneuronCppVisitor::print_global_variable_device_update_annotation
virtual void print_global_variable_device_update_annotation()
Print the pragma annotation to update global variables from host to the device.
Definition: codegen_coreneuron_cpp_visitor.cpp:2031
nmodl::codegen::CodegenCppVisitor::printer
std::unique_ptr< CodePrinter > printer
Code printer object for target (C++)
Definition: codegen_cpp_visitor.hpp:260
nmodl::codegen::CodegenCoreneuronCppVisitor::print_function_tables
void print_function_tables(const ast::FunctionTableBlock &node)
Print NMODL function_table in target backend code.
Definition: codegen_coreneuron_cpp_visitor.cpp:728
nmodl::codegen::CodegenCppVisitor::method_name
std::string method_name(const std::string &name) const
Constructs the name of a function or procedure.
Definition: codegen_cpp_visitor.hpp:920
nmodl::codegen::CodegenCoreneuronCppVisitor::visit_watch_statement
virtual void visit_watch_statement(const ast::WatchStatement &node) override
visit node of type ast::WatchStatement
Definition: codegen_coreneuron_cpp_visitor.cpp:3594
nmodl::codegen::CodegenCoreneuronCppVisitor::print_nrn_cur_non_conductance_kernel
void print_nrn_cur_non_conductance_kernel() override
Print the nrn_cur kernel without NMODL conductance keyword provisions.
Definition: codegen_coreneuron_cpp_visitor.cpp:3238
nmodl::codegen::CodegenCoreneuronCppVisitor::print_backend_includes
virtual void print_backend_includes()
Print backend specific includes (none needed for C++ backend)
Definition: codegen_coreneuron_cpp_visitor.cpp:326
nmodl::codegen::CodegenCoreneuronCppVisitor::process_verbatim_token
std::string process_verbatim_token(const std::string &token)
Process a token in a verbatim block for possible variable renaming.
Definition: codegen_coreneuron_cpp_visitor.cpp:94
nmodl::codegen::CodegenCoreneuronCppVisitor::print_nrn_state
void print_nrn_state() override
Print nrn_state / state update function definition.
Definition: codegen_coreneuron_cpp_visitor.cpp:3127
nmodl::codegen::CodegenCoreneuronCppVisitor::print_codegen_routines
virtual void print_codegen_routines() override
Print entry point to code generation.
Definition: codegen_coreneuron_cpp_visitor.cpp:3463
nmodl::codegen::CodegenCoreneuronCppVisitor::print_watch_activate
void print_watch_activate()
Print watch activate function.
Definition: codegen_coreneuron_cpp_visitor.cpp:2471
nmodl::codegen::CodegenCoreneuronCppVisitor::print_net_send_buffering_grow
virtual void print_net_send_buffering_grow()
Print statement that grows NetSendBuffering_t structure if needed.
Definition: codegen_coreneuron_cpp_visitor.cpp:2893
nmodl::codegen::CodegenCoreneuronCppVisitor::print_backend_namespace_stop
virtual void print_backend_namespace_stop()
Prints the end of namespace for the backend-specific code.
Definition: codegen_coreneuron_cpp_visitor.cpp:321
nmodl::codegen::CodegenCoreneuronCppVisitor::print_net_send_buf_update_to_host
virtual void print_net_send_buf_update_to_host() const
Print the code to update NetSendBuffer_t from device to host.
Definition: codegen_coreneuron_cpp_visitor.cpp:170
nmodl::codegen::CodegenCoreneuronCppVisitor::print_data_structures
void print_data_structures(bool print_initializers) override
Print all classes.
Definition: codegen_coreneuron_cpp_visitor.cpp:3404
nmodl::codegen::CodegenCoreneuronCppVisitor::replace_if_verbatim_variable
std::string replace_if_verbatim_variable(std::string name)
Replace commonly used verbatim variables.
Definition: codegen_coreneuron_cpp_visitor.cpp:978
nmodl::codegen::CodegenCoreneuronCppVisitor::print_ion_var_constructor
virtual void print_ion_var_constructor(const std::vector< std::string > &members)
Print constructor of ion variables.
Definition: codegen_coreneuron_cpp_visitor.cpp:2009
nmodl::codegen::CodegenCoreneuronCppVisitor::position_of_float_var
int position_of_float_var(const std::string &name) const override
Determine the position in the data array for a given float variable.
Definition: codegen_coreneuron_cpp_visitor.cpp:66
nmodl::codegen::CodegenCppVisitor::ParamVector
std::vector< std::tuple< std::string, std::string, std::string, std::string > > ParamVector
A vector of parameters represented by a 4-tuple of strings:
Definition: codegen_cpp_visitor.hpp:250
ast_visitor.hpp
Concrete visitor for all AST classes.