From 2eb8ddd23af8670364d0b59d9586a3fafc3514ec Mon Sep 17 00:00:00 2001 From: Ioannis Magkanaris Date: Wed, 6 Sep 2023 15:41:24 +0200 Subject: [PATCH 1/4] Revert "Revert "Avoid duplicate calculation of number of float and int variables"" This reverts commit 9db0f46d694de6b350a620ba58804feb832809b1. --- src/codegen/codegen_cpp_visitor.cpp | 52 ++--------------------------- src/codegen/codegen_cpp_visitor.hpp | 12 ------- 2 files changed, 2 insertions(+), 62 deletions(-) diff --git a/src/codegen/codegen_cpp_visitor.cpp b/src/codegen/codegen_cpp_visitor.cpp index bfd23bb468..ad8425ddef 100644 --- a/src/codegen/codegen_cpp_visitor.cpp +++ b/src/codegen/codegen_cpp_visitor.cpp @@ -535,54 +535,6 @@ std::string CodegenCppVisitor::breakpoint_current(std::string current) const { } -int CodegenCppVisitor::float_variables_size() const { - auto count_length = [](int l, const SymbolType& variable) { - return l += variable->get_length(); - }; - - int float_size = std::accumulate(info.range_parameter_vars.begin(), - info.range_parameter_vars.end(), - 0, - count_length); - float_size += std::accumulate(info.range_assigned_vars.begin(), - info.range_assigned_vars.end(), - 0, - count_length); - float_size += std::accumulate(info.range_state_vars.begin(), - info.range_state_vars.end(), - 0, - count_length); - float_size += - std::accumulate(info.assigned_vars.begin(), info.assigned_vars.end(), 0, count_length); - - /// all state variables for which we add Dstate variables - float_size += std::accumulate(info.state_vars.begin(), info.state_vars.end(), 0, count_length); - - /// for v_unused variable - if (info.vectorize) { - float_size++; - } - /// for g_unused variable - if (breakpoint_exist()) { - float_size++; - } - /// for tsave variable - if (net_receive_exist()) { - float_size++; - } - return float_size; -} - - -int CodegenCppVisitor::int_variables_size() const { - int num_variables = 0; - for (const auto& semantic: info.semantics) { - num_variables += semantic.size; - } - return num_variables; -} - - /** * \details Depending upon the block type, we have to print read/write ion variables * during code generation. Depending on block/procedure being printed, this @@ -2192,13 +2144,13 @@ void CodegenCppVisitor::print_num_variable_getter() { printer->add_newline(2); print_device_method_annotation(); printer->start_block("static inline int float_variables_size()"); - printer->fmt_line("return {};", float_variables_size()); + printer->fmt_line("return {};", codegen_float_variables.size()); printer->end_block(1); printer->add_newline(2); print_device_method_annotation(); printer->start_block("static inline int int_variables_size()"); - printer->fmt_line("return {};", int_variables_size()); + printer->fmt_line("return {};", codegen_int_variables.size()); printer->end_block(1); } diff --git a/src/codegen/codegen_cpp_visitor.hpp b/src/codegen/codegen_cpp_visitor.hpp index 09e6f0bd0a..96802f8d02 100644 --- a/src/codegen/codegen_cpp_visitor.hpp +++ b/src/codegen/codegen_cpp_visitor.hpp @@ -503,18 +503,6 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor { } - /** - * Number of float variables in the model - */ - int float_variables_size() const; - - - /** - * Number of integer variables in the model - */ - int int_variables_size() const; - - /** * Determine the position in the data array for a given float variable * \param name The name of a float variable From 7f903eb1483621f5c1e1a27c358f032015552751 Mon Sep 17 00:00:00 2001 From: Ioannis Magkanaris Date: Fri, 8 Sep 2023 17:11:54 +0200 Subject: [PATCH 2/4] Int variables count is based on semantics --- src/codegen/codegen_cpp_visitor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codegen/codegen_cpp_visitor.cpp b/src/codegen/codegen_cpp_visitor.cpp index ad8425ddef..531870ac85 100644 --- a/src/codegen/codegen_cpp_visitor.cpp +++ b/src/codegen/codegen_cpp_visitor.cpp @@ -2150,7 +2150,7 @@ void CodegenCppVisitor::print_num_variable_getter() { printer->add_newline(2); print_device_method_annotation(); printer->start_block("static inline int int_variables_size()"); - printer->fmt_line("return {};", codegen_int_variables.size()); + printer->fmt_line("return {};", info.semantics.size()); printer->end_block(1); } From de63f6d4f751ff3ac0b63ba78ea4502bf08f8c1a Mon Sep 17 00:00:00 2001 From: Ioannis Magkanaris Date: Mon, 11 Sep 2023 15:07:44 +0200 Subject: [PATCH 3/4] Semantics might have size > 1 so we need to accumulate their size --- src/codegen/codegen_cpp_visitor.cpp | 8 +++++++- src/codegen/codegen_cpp_visitor.hpp | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/codegen/codegen_cpp_visitor.cpp b/src/codegen/codegen_cpp_visitor.cpp index 531870ac85..aa9a3857d3 100644 --- a/src/codegen/codegen_cpp_visitor.cpp +++ b/src/codegen/codegen_cpp_visitor.cpp @@ -535,6 +535,12 @@ std::string CodegenCppVisitor::breakpoint_current(std::string current) const { } +int CodegenCppVisitor::int_variables_size() const { + const auto count_semantics = [](int sum, const IndexSemantics& sem) { return sum += sem.size; }; + return std::accumulate(info.semantics.begin(), info.semantics.end(), 0, count_semantics); +} + + /** * \details Depending upon the block type, we have to print read/write ion variables * during code generation. Depending on block/procedure being printed, this @@ -2150,7 +2156,7 @@ void CodegenCppVisitor::print_num_variable_getter() { printer->add_newline(2); print_device_method_annotation(); printer->start_block("static inline int int_variables_size()"); - printer->fmt_line("return {};", info.semantics.size()); + printer->fmt_line("return {};", int_variables_size()); printer->end_block(1); } diff --git a/src/codegen/codegen_cpp_visitor.hpp b/src/codegen/codegen_cpp_visitor.hpp index 96802f8d02..e7f2a51239 100644 --- a/src/codegen/codegen_cpp_visitor.hpp +++ b/src/codegen/codegen_cpp_visitor.hpp @@ -503,6 +503,12 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor { } + /** + * Number of integer variables in the model + */ + int int_variables_size() const; + + /** * Determine the position in the data array for a given float variable * \param name The name of a float variable From 13d4b1b9eb0a5071d2c91557ed00bdc73e8e2062 Mon Sep 17 00:00:00 2001 From: Ioannis Magkanaris Date: Tue, 12 Sep 2023 11:56:57 +0200 Subject: [PATCH 4/4] Add refactored float_variables_size() --- src/codegen/codegen_cpp_visitor.cpp | 7 ++++++- src/codegen/codegen_cpp_visitor.hpp | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/codegen/codegen_cpp_visitor.cpp b/src/codegen/codegen_cpp_visitor.cpp index aa9a3857d3..450139cd82 100644 --- a/src/codegen/codegen_cpp_visitor.cpp +++ b/src/codegen/codegen_cpp_visitor.cpp @@ -535,6 +535,11 @@ std::string CodegenCppVisitor::breakpoint_current(std::string current) const { } +int CodegenCppVisitor::float_variables_size() const { + return codegen_float_variables.size(); +} + + int CodegenCppVisitor::int_variables_size() const { const auto count_semantics = [](int sum, const IndexSemantics& sem) { return sum += sem.size; }; return std::accumulate(info.semantics.begin(), info.semantics.end(), 0, count_semantics); @@ -2150,7 +2155,7 @@ void CodegenCppVisitor::print_num_variable_getter() { printer->add_newline(2); print_device_method_annotation(); printer->start_block("static inline int float_variables_size()"); - printer->fmt_line("return {};", codegen_float_variables.size()); + printer->fmt_line("return {};", float_variables_size()); printer->end_block(1); printer->add_newline(2); diff --git a/src/codegen/codegen_cpp_visitor.hpp b/src/codegen/codegen_cpp_visitor.hpp index e7f2a51239..09e6f0bd0a 100644 --- a/src/codegen/codegen_cpp_visitor.hpp +++ b/src/codegen/codegen_cpp_visitor.hpp @@ -503,6 +503,12 @@ class CodegenCppVisitor: public visitor::ConstAstVisitor { } + /** + * Number of float variables in the model + */ + int float_variables_size() const; + + /** * Number of integer variables in the model */