Skip to content

Commit

Permalink
Move GLOBAL related code. (#1137)
Browse files Browse the repository at this point in the history
The methods:
  - print_global_var_struct_decl
  - print_global_var_struct_assertions
  - instance_struct
  - global_struct
  - global_struct_instance

have been moved from the CoreNEURON C++ printer to the shared C++
printer.
  • Loading branch information
1uc authored Jan 12, 2024
1 parent 72af0a3 commit b01e5f7
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 63 deletions.
18 changes: 0 additions & 18 deletions src/codegen/codegen_coreneuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,6 @@ void CodegenCoreneuronCppVisitor::print_abort_routine() const {
}


void CodegenCoreneuronCppVisitor::print_global_var_struct_decl() {
printer->add_line(global_struct(), ' ', global_struct_instance(), ';');
}


/****************************************************************************************/
/* Printing routines for code generation */
/****************************************************************************************/
Expand Down Expand Up @@ -1805,19 +1800,6 @@ void CodegenCoreneuronCppVisitor::print_mechanism_global_var_structure(bool prin
}


void CodegenCoreneuronCppVisitor::print_global_var_struct_assertions() const {
// Assert some things that we assume when copying instances of this struct
// to the GPU and so on.
printer->fmt_line("static_assert(std::is_trivially_copy_constructible_v<{}>);",
global_struct());
printer->fmt_line("static_assert(std::is_trivially_move_constructible_v<{}>);",
global_struct());
printer->fmt_line("static_assert(std::is_trivially_copy_assignable_v<{}>);", global_struct());
printer->fmt_line("static_assert(std::is_trivially_move_assignable_v<{}>);", global_struct());
printer->fmt_line("static_assert(std::is_trivially_destructible_v<{}>);", global_struct());
}


/**
* Print structs that encapsulate information about scalar and
* vector elements of type global and thread variables.
Expand Down
39 changes: 0 additions & 39 deletions src/codegen/codegen_coreneuron_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,30 +83,6 @@ class CodegenCoreneuronCppVisitor: public CodegenCppVisitor {
virtual std::string backend_name() const override;


/**
* Name of structure that wraps range variables
*/
std::string instance_struct() const {
return fmt::format("{}_Instance", info.mod_suffix);
}


/**
* Name of structure that wraps global variables
*/
std::string global_struct() const {
return fmt::format("{}_Store", info.mod_suffix);
}


/**
* Name of the (host-only) global instance of `global_struct`
*/
std::string global_struct_instance() const {
return info.mod_suffix + "_global";
}


/**
* Determine the number of threads to allocate
*/
Expand Down Expand Up @@ -370,15 +346,6 @@ class CodegenCoreneuronCppVisitor: public CodegenCppVisitor {
virtual void print_abort_routine() const;


/**
* Instantiate global var instance
*
* For C++ code generation this is empty
* \return ""
*/
virtual void print_global_var_struct_decl();


/**
* Print declarations of the functions used by \ref
* print_instance_struct_copy_to_device and \ref
Expand Down Expand Up @@ -788,12 +755,6 @@ class CodegenCoreneuronCppVisitor: public CodegenCppVisitor {
void print_mechanism_global_var_structure(bool print_initializers) override;


/**
* Print static assertions about the global variable struct.
*/
virtual void print_global_var_struct_assertions() const;


/**
* Print byte arrays that register scalar and vector variables for hoc interface
*
Expand Down
19 changes: 19 additions & 0 deletions src/codegen/codegen_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,25 @@ bool CodegenCppVisitor::need_semicolon(const Statement& node) {
/* Main printing routines for code generation */
/****************************************************************************************/


void CodegenCppVisitor::print_global_var_struct_assertions() const {
// Assert some things that we assume when copying instances of this struct
// to the GPU and so on.
printer->fmt_line("static_assert(std::is_trivially_copy_constructible_v<{}>);",
global_struct());
printer->fmt_line("static_assert(std::is_trivially_move_constructible_v<{}>);",
global_struct());
printer->fmt_line("static_assert(std::is_trivially_copy_assignable_v<{}>);", global_struct());
printer->fmt_line("static_assert(std::is_trivially_move_assignable_v<{}>);", global_struct());
printer->fmt_line("static_assert(std::is_trivially_destructible_v<{}>);", global_struct());
}


void CodegenCppVisitor::print_global_var_struct_decl() {
printer->add_line(global_struct(), ' ', global_struct_instance(), ';');
}


void CodegenCppVisitor::print_function_call(const FunctionCall& node) {
const auto& name = node.get_node_name();
auto function_name = name;
Expand Down
39 changes: 39 additions & 0 deletions src/codegen/codegen_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,30 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor {
virtual std::string simulator_name() = 0;


/**
* Name of structure that wraps range variables
*/
std::string instance_struct() const {
return fmt::format("{}_Instance", info.mod_suffix);
}


/**
* Name of structure that wraps global variables
*/
std::string global_struct() const {
return fmt::format("{}_Store", info.mod_suffix);
}


/**
* Name of the (host-only) global instance of `global_struct`
*/
std::string global_struct_instance() const {
return info.mod_suffix + "_global";
}


/**
* Name of the code generation backend
*/
Expand Down Expand Up @@ -577,6 +601,15 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor {
virtual void print_atomic_reduction_pragma() = 0;


/**
* Instantiate global var instance
*
* For C++ code generation this is empty
* \return ""
*/
virtual void print_global_var_struct_decl();


/****************************************************************************************/
/* Printing routines for code generation */
/****************************************************************************************/
Expand Down Expand Up @@ -883,6 +916,12 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor {
virtual void print_mechanism_global_var_structure(bool print_initializers) = 0;


/**
* Print static assertions about the global variable struct.
*/
virtual void print_global_var_struct_assertions() const;


/**
* Print declaration of macro NRN_PRCELLSTATE for debugging
*/
Expand Down
6 changes: 0 additions & 6 deletions src/codegen/codegen_neuron_cpp_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,6 @@ class CodegenNeuronCppVisitor: public CodegenCppVisitor {
*/
virtual std::string backend_name() const override;

/**
* Name of structure that wraps range variables
*/
std::string instance_struct() const {
return fmt::format("{}_Instance", info.mod_suffix);
}

/****************************************************************************************/
/* Common helper routines accross codegen functions */
Expand Down

0 comments on commit b01e5f7

Please sign in to comment.