PandA-2024.02
top_entity_cs.cpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (c) 2016-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
40 #include "top_entity_cs.hpp"
41 #include "BambuParameter.hpp"
42 #include "dbgPrintHelper.hpp"
43 #include "hls.hpp"
44 #include "hls_device.hpp"
45 #include "hls_manager.hpp"
46 #include "math_function.hpp"
47 #include "omp_functions.hpp"
48 #include "structural_manager.hpp"
49 #include "structural_objects.hpp"
50 #include "technology_manager.hpp"
51 #include "utility.hpp"
52 #include <string>
53 
54 top_entity_cs::top_entity_cs(const ParameterConstRef _parameters, const HLS_managerRef _HLSMgr, unsigned int _funId,
55  const DesignFlowManagerConstRef _design_flow_manager,
56  const HLSFlowStep_Type _hls_flow_step_type)
57  : top_entity(_parameters, _HLSMgr, _funId, _design_flow_manager, _hls_flow_step_type)
58 {
59  debug_level = parameters->get_class_debug_level(GET_CLASS(*this));
60 }
61 
63 
65 {
66  auto omp_functions = GetPointer<OmpFunctions>(HLSMgr->Rfuns);
68  if(omp_functions->kernel_functions.find(funId) != omp_functions->kernel_functions.end())
69  {
70  HLS->registered_inputs = true;
71  }
73 
74  if(omp_functions->kernel_functions.find(funId) != omp_functions->kernel_functions.end())
75  {
77  }
78  else
79  {
80  bool found = false;
81  if(omp_functions->parallelized_functions.find(funId) != omp_functions->parallelized_functions.end())
82  {
83  found = true;
84  }
85  if(omp_functions->atomic_functions.find(funId) != omp_functions->atomic_functions.end())
86  {
87  found = true;
88  }
89  if(found) // function with selector
90  {
92  }
93  }
95 }
96 
98 {
100  structural_objectRef circuit = SM->get_circ();
101  structural_managerRef Datapath = HLS->datapath;
102  structural_managerRef Controller = HLS->controller;
103  structural_objectRef datapath_circuit = Datapath->get_circ();
104  structural_objectRef controller_circuit = Controller->get_circ();
106  structural_objectRef suspension_obj = SM->add_port(STR(SUSPENSION), port_o::OUT, circuit, bool_type);
107  structural_objectRef datapath_suspension =
108  datapath_circuit->find_member(STR(SUSPENSION), port_o_K, datapath_circuit);
109  SM->add_connection(datapath_suspension, suspension_obj);
110 
111  auto num_slots = ceil_log2(parameters->getOption<unsigned long long int>(OPT_context_switch));
112  if(!num_slots)
113  {
114  num_slots = 1;
115  }
117  structural_type_descriptorRef(new structural_type_descriptor("bool", static_cast<unsigned>(num_slots)));
118  structural_objectRef selector_obj = SM->add_port(STR(SELECTOR_REGISTER_FILE), port_o::IN, circuit, port_type);
119  structural_objectRef datapath_selector =
120  datapath_circuit->find_member(STR(SELECTOR_REGISTER_FILE), port_o_K, datapath_circuit);
121  SM->add_connection(datapath_selector, selector_obj);
122  structural_objectRef controller_selector =
123  controller_circuit->find_member(STR(SELECTOR_REGISTER_FILE), port_o_K, controller_circuit);
124  SM->add_connection(controller_selector, selector_obj);
125  auto selector_regFile_sign = circuit->find_member(STR(SELECTOR_REGISTER_FILE) + "_signal", signal_o_K, circuit);
126  if(selector_regFile_sign)
127  {
128  SM->add_connection(selector_obj, selector_regFile_sign);
129  }
131 }
132 
134 {
135  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Adding ports to kernel module");
136  structural_managerRef Datapath = HLS->datapath;
137  structural_managerRef Controller = HLS->controller;
138  structural_objectRef datapath_circuit = Datapath->get_circ();
139  structural_objectRef controller_circuit = Controller->get_circ();
140  structural_objectRef circuit = SM->get_circ();
142  auto num_slots = ceil_log2(parameters->getOption<unsigned long long int>(OPT_context_switch));
143  if(!num_slots)
144  {
145  num_slots = 1;
146  }
147 
148  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Adding selector register file connection");
150  structural_type_descriptorRef(new structural_type_descriptor("bool", static_cast<unsigned>(num_slots)));
151  structural_objectRef datapath_selector =
152  datapath_circuit->find_member(STR(SELECTOR_REGISTER_FILE), port_o_K, datapath_circuit);
153  auto selector_regFile_sign = circuit->find_member(STR(SELECTOR_REGISTER_FILE) + "_signal", signal_o_K, circuit);
154  if(not selector_regFile_sign)
155  {
156  selector_regFile_sign = SM->add_sign(STR(SELECTOR_REGISTER_FILE) + "_signal", circuit, port_type);
157  }
158  SM->add_connection(datapath_selector, selector_regFile_sign);
159  structural_objectRef controller_selector =
160  controller_circuit->find_member(STR(SELECTOR_REGISTER_FILE), port_o_K, controller_circuit);
161  SM->add_connection(selector_regFile_sign, controller_selector);
162 
164  structural_objectRef task_pool_end_obj = SM->add_port(STR(TASKS_POOL_END), port_o::IN, circuit, bool_type);
165  structural_objectRef datapath_task_pool_end =
166  datapath_circuit->find_member(STR(TASKS_POOL_END), port_o_K, datapath_circuit);
167  SM->add_connection(datapath_task_pool_end, task_pool_end_obj);
168 
170  structural_objectRef done_request_obj = SM->add_port(STR(DONE_REQUEST), port_o::OUT, circuit, bool_type);
171  structural_objectRef datapath_done_request =
172  datapath_circuit->find_member(STR(DONE_REQUEST), port_o_K, datapath_circuit);
173  SM->add_connection(datapath_done_request, done_request_obj);
174 
176  structural_objectRef datapath_done_port =
177  datapath_circuit->find_member(STR(DONE_SCHEDULER), port_o_K, datapath_circuit);
178  structural_objectRef done_signal_in = circuit->find_member("done_delayed_REG_signal_in", signal_o_K, circuit);
179  SM->add_connection(done_signal_in, datapath_done_port); // connect signal out controller to datapath START_PORT_NAME
180 
182  structural_objectRef datapath_start_port =
183  datapath_circuit->find_member(STR(START_PORT_NAME) + "_task", port_o_K, datapath_circuit);
184  structural_objectRef start_signal_in = circuit->find_member(STR(START_PORT_NAME), port_o_K, circuit);
185  SM->add_connection(start_signal_in, datapath_start_port); // connect start to datapath
186  circuit->AddParameter("KERN_NUM", "0");
187 
188  GetPointer<module>(datapath_circuit)->SetParameter("KERN_NUM", "KERN_NUM");
189  SM->add_NP_functionality(circuit, NP_functionality::LIBRARY, "KERN_NUM");
190  GetPointer<module>(circuit)->AddParameter("KERN_NUM", "0"); // taken from kernel instantiation
191  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Added ports to kernel module");
192 }
193 
194 void top_entity_cs::add_input_register(structural_objectRef port_in, const std::string& port_prefix,
195  structural_objectRef circuit, structural_objectRef clock_port,
197 {
198  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Adding input registers");
199  auto TM = HLS->HLS_D->get_technology_manager();
200  auto register_library = TM->get_library("register_file");
201  auto register_file_module =
202  SM->add_module_from_technology_library(port_prefix + "_REG", "register_file", register_library, circuit, TM);
203  auto cs_number = HLS->Param->getOption<unsigned int>(OPT_context_switch);
204  GetPointer<module>(register_file_module)->SetParameter("n_elements", STR(cs_number));
206  GetPointer<module>(register_file_module)->get_in_port(1)->type_resize(GET_TYPE_SIZE(port_in));
207 
209  GetPointer<module>(register_file_module)->get_out_port(0)->type_resize(GET_TYPE_SIZE(port_in));
210 
212  auto rf_clock_port = register_file_module->find_member(CLOCK_PORT_NAME, port_o_K, register_file_module);
213  SM->add_connection(clock_port, rf_clock_port);
214 
216  auto start_port = circuit->find_member(START_PORT_NAME, port_o_K, circuit);
217  auto rf_we_port = GetPointer<module>(register_file_module)->get_in_port(2);
218  SM->add_connection(start_port, rf_we_port);
219 
221  auto controller_circuit = HLS->controller->get_circ();
222  auto register_file_selector_port =
223  controller_circuit->find_member(SELECTOR_REGISTER_FILE, port_o_K, controller_circuit);
224  auto rf_register_file_selector_port = GetPointer<module>(register_file_module)->get_in_port(3);
225  const auto sel_bits = ceil_log2(cs_number);
226  rf_register_file_selector_port->type_resize(sel_bits);
227 
228  auto register_file_selector_signal = circuit->find_member(SELECTOR_REGISTER_FILE "_signal", signal_o_K, circuit);
229  if(not register_file_selector_signal)
230  {
231  register_file_selector_signal =
232  SM->add_sign(STR(SELECTOR_REGISTER_FILE) + "_signal", circuit, register_file_selector_port->get_typeRef());
233  }
234  SM->add_connection(register_file_selector_signal, rf_register_file_selector_port);
235 
237  auto external_port_to_register = SM->add_sign(port_prefix + "_to_reg", circuit, port_in->get_typeRef());
238  SM->add_connection(e_port, external_port_to_register);
239  SM->add_connection(GetPointer<module>(register_file_module)->get_in_port(1), external_port_to_register);
240 
242  auto register_to_internal_port = SM->add_sign(
243  port_prefix + "_from_reg", circuit, GetPointer<module>(register_file_module)->get_out_port(0)->get_typeRef());
244  SM->add_connection(GetPointer<module>(register_file_module)->get_out_port(0), register_to_internal_port);
245  SM->add_connection(port_in, register_to_internal_port);
246  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Added input registers");
247 }
void add_connection(structural_objectRef src, structural_objectRef dest)
Create a connection between a source structural object and a destination structural object...
structural_managerRef SM
reference to the resulting circuit
Definition: top_entity.hpp:54
#define TASKS_POOL_END
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
const HLS_managerRef HLSMgr
information about all the HLS synthesis
Definition: hls_step.hpp:205
Data structure representing the entire HLS information.
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
DesignFlowStep_Status InternalExec() override
Execute the step.
Definition: top_entity.cpp:110
#define DONE_SCHEDULER
refcount< structural_type_descriptor > structural_type_descriptorRef
RefCount type definition of the structural_type_descriptor class structure.
File containing functions and utilities to support the printing of debug messagges.
#define DONE_REQUEST
structural_managerRef datapath
Store the datapath description.
Definition: hls.hpp:155
#define START_PORT_NAME
Structure representing the most relevant information about the type of a structural object...
const ParameterConstRef Param
class containing all the parameters
Definition: hls.hpp:169
#define GET_CLASS(obj)
Macro returning the actual type of an object.
const structural_objectRef get_circ() const
Get a reference to circ field.
mathematical utility function not provided by standard libraries
const unsigned int funId
identifier of the function to be processed (0 means that it is a global step)
const HLS_deviceRef HLS_D
reference to the information representing the target for the synthesis
Definition: hls.hpp:107
virtual structural_objectRef find_member(const std::string &id, so_kind type, const structural_objectRef owner) const =0
Return the object named id of a given type which belongs to or it is associated with the object...
Class specification of the manager of the technology library data structures.
#define STR(s)
Macro which performs a lexical_cast to a string.
virtual void AddParameter(const std::string &name, const std::string &default_value)
Add a parameter.
#define CLOCK_PORT_NAME
standard name for ports
bool registered_inputs
true when the module has registered inputs
Definition: hls.hpp:147
T ceil_log2(T x)
Return the smallest n such that 2**n >= X.
static void add_NP_functionality(structural_objectRef cir, NP_functionality::NP_functionaly_type dt, std::string functionality_description)
Add a not-parsed functionality.
HLSFlowStep_Type
Definition: hls_step.hpp:95
static structural_objectRef add_port(const std::string &id, port_o::port_direction pdir, structural_objectRef owner, structural_type_descriptorRef type_descr, unsigned int treenode=0)
Create a new port.
void add_context_switch_port_kernel()
void add_context_switch_port()
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
DesignFlowStep_Status InternalExec() override
Add selector and suspension.
This file collects some utility functions and macros.
void add_input_register(structural_objectRef port_in, const std::string &port_prefix, structural_objectRef circuit, structural_objectRef clock_port, structural_objectRef reset_port, structural_objectRef e_port) override
Add the register file to store input parameters.
top_entity_cs(const ParameterConstRef _parameters, const HLS_managerRef HLSMgr, unsigned int funId, const DesignFlowManagerConstRef design_flow_manager, const HLSFlowStep_Type _hls_flow_step_type=HLSFlowStep_Type::TOP_ENTITY_CS_CREATION)
structural_objectRef add_module_from_technology_library(const std::string &id, const std::string &fu_name, const std::string &library_name, const structural_objectRef owner, const technology_managerConstRef TM)
Create a new object starting from a library component.
structural_managerRef controller
Store the controller description.
Definition: hls.hpp:158
#define GET_TYPE_SIZE(structural_obj)
Macro returning the size of the type of a structural object.
This class describes all classes used to represent a structural object.
const structural_type_descriptorRef & get_typeRef() const
Return the type descriptor of the structural_object.
static structural_objectRef add_sign(std::string id, structural_objectRef owner, structural_type_descriptorRef sign_type, unsigned int treenode=0)
Create a new signal.
hlsRef HLS
HLS data structure of the function to be analyzed.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
~top_entity_cs() override
Destructor.
#define SELECTOR_REGISTER_FILE
Class implementation of the structural_manager.
int debug_level
The debug level.
Datastructure to describe functions allocation in high-level synthesis.
Data structure definition for high-level synthesis flow.
#define SUSPENSION
HLS specialization of generic_device.

Generated on Mon Feb 12 2024 13:02:53 for PandA-2024.02 by doxygen 1.8.13