PandA-2024.02
pipeline_controller.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) 2004-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  */
41 #include "pipeline_controller.hpp"
42 #include "BambuParameter.hpp"
44 #include "behavioral_helper.hpp"
45 #include "commandport_obj.hpp"
46 #include "conn_binding.hpp"
47 #include "connection_obj.hpp"
48 #include "copyrights_strings.hpp"
49 #include "custom_map.hpp"
50 #include "custom_set.hpp"
51 #include "dbgPrintHelper.hpp"
52 #include "exceptions.hpp"
53 #include "fu_binding.hpp"
54 #include "function_behavior.hpp"
55 #include "funit_obj.hpp"
56 #include "hls.hpp"
57 #include "hls_device.hpp"
58 #include "hls_manager.hpp"
59 #include "liveness.hpp"
60 #include "mux_obj.hpp"
61 #include "op_graph.hpp"
62 #include "reg_binding.hpp"
63 #include "register_obj.hpp"
64 #include "schedule.hpp"
68 #include "string_manipulation.hpp"
69 #include "structural_manager.hpp"
70 #include "structural_objects.hpp"
71 #include "technology_manager.hpp"
72 #include "technology_node.hpp"
73 #include "tree_helper.hpp"
74 #include "tree_manager.hpp"
75 #include "tree_node.hpp"
76 #include "tree_reindex.hpp"
77 #include <deque>
78 #include <iosfwd>
79 #include <list>
80 #include <utility>
81 #include <vector>
82 
84  unsigned int _funId, const DesignFlowManagerConstRef _design_flow_manager,
85  const HLSFlowStep_Type _hls_flow_step_type)
86  : ControllerCreatorBaseStep(_Param, _HLSMgr, _funId, _design_flow_manager, _hls_flow_step_type)
87 {
88  debug_level = parameters->get_class_debug_level(GET_CLASS(*this), DEBUG_LEVEL_NONE);
89 }
90 
92 
94 {
95  THROW_ASSERT(HLS->STG, "State transition graph not created");
96 
98  PRINT_DBG_MEX(DEBUG_LEVEL_VERBOSE, debug_level, "Pipeline shift-register controller creation");
99  const FunctionBehaviorConstRef FB = HLSMgr->CGetFunctionBehavior(funId);
100 
101  const std::string function_name = FB->CGetBehavioralHelper()->get_function_name();
103  structural_type_descriptorRef module_type =
104  structural_type_descriptorRef(new structural_type_descriptor("controller_" + function_name));
106  SM->set_top_info("Controller_i", module_type);
107  structural_objectRef circuit = SM->get_circ();
108  circuit->set_black_box(false);
109  this->add_common_ports(circuit, SM);
110  structural_objectRef clock_port = circuit->find_member(CLOCK_PORT_NAME, port_o_K, circuit);
111  structural_objectRef reset_port = circuit->find_member(RESET_PORT_NAME, port_o_K, circuit);
112  structural_objectRef done_port = circuit->find_member(DONE_PORT_NAME, port_o_K, circuit);
113  structural_objectRef start_port = circuit->find_member(START_PORT_NAME, port_o_K, circuit);
114 
115  PRINT_DBG_MEX(DEBUG_LEVEL_PEDANTIC, debug_level, "Determining size of the controller...");
116  unsigned int num_states = HLS->STG->get_number_of_states() - 1;
117 
118  std::string name = "controller_" + function_name;
119  std::string library = HLS->HLS_D->get_technology_manager()->get_library(register_SHIFT);
120  structural_objectRef controller = SM->add_module_from_technology_library(name, register_SHIFT, library, circuit,
121  HLS->HLS_D->get_technology_manager());
122  controller->SetParameter("CONTROLLER_LENGTH", std::to_string(num_states));
123  const StateTransitionGraphConstRef astg = HLS->STG->CGetAstg();
125  std::list<vertex> working_list;
126  astg->TopologicalSort(working_list);
127  vertex entry = HLS->STG->get_entry_state();
128  THROW_ASSERT(boost::out_degree(entry, *astg) == 1, "Non deterministic initial state");
129  OutEdgeIterator oe, oend;
130  boost::tie(oe, oend) = boost::out_edges(entry, *astg);
132  vertex first_state = boost::target(*oe, *astg);
133  THROW_ASSERT(std::find(working_list.begin(), working_list.end(), first_state) != working_list.end(),
134  "unexpected case");
135  working_list.erase(std::find(working_list.begin(), working_list.end(), first_state));
136  working_list.push_front(first_state);
137  std::map<unsigned long long, structural_objectRef> null_values;
138  for(const auto& v : working_list)
139  {
140  const auto& operations = astg->CGetStateInfo(v)->executing_operations;
141  for(const auto& op : operations)
142  {
144  technology_nodeRef op_tn = GetPointer<functional_unit>(tn)->get_operation(
145  tree_helper::NormalizeTypename(data->CGetOpNodeInfo(op)->GetOperation()));
146  THROW_ASSERT(GetPointer<operation>(op_tn)->time_m,
147  "Time model not available for operation: " + GET_NAME(data, op));
148  structural_managerRef CM = GetPointer<functional_unit>(tn)->CM;
149  if(!CM)
150  {
151  continue;
152  }
154  THROW_ASSERT(top, "expected");
155  auto* fu_module = GetPointer<module>(top);
156  THROW_ASSERT(fu_module, "expected");
157  structural_objectRef start_port_i = fu_module->find_member(START_PORT_NAME, port_o_K, top);
158  if((GET_TYPE(data, op) & TYPE_EXTERNAL) && start_port_i)
159  {
160  auto genObj = HLS->Rconn->bind_selector_port(conn_binding::IN, commandport_obj::UNBOUNDED, op, data);
161  THROW_ASSERT(genObj, "null object");
162  auto portObj = GetPointer<commandport_obj>(genObj)->get_controller_obj();
163  THROW_ASSERT(portObj, "null object");
164  if(null_values.find(GET_TYPE_SIZE(portObj)) == null_values.end())
165  {
167  "Adding null value for bitsize " + STR(GET_TYPE_SIZE(portObj)));
168  structural_objectRef const_obj = SM->add_constant("null_value_" + STR(GET_TYPE_SIZE(portObj)), circuit,
169  portObj->get_typeRef(), STR(0));
170  null_values[GET_TYPE_SIZE(portObj)] = const_obj;
171  }
172  SM->add_connection(portObj, null_values[GET_TYPE_SIZE(portObj)]);
173  }
174  }
175  }
176  structural_objectRef port_ck = controller->find_member(CLOCK_PORT_NAME, port_o_K, controller);
177  SM->add_connection(clock_port, port_ck);
178  structural_objectRef port_rst = controller->find_member(RESET_PORT_NAME, port_o_K, controller);
179  SM->add_connection(reset_port, port_rst);
180  structural_objectRef port_dn = controller->find_member("out1", port_o_K, controller);
181  SM->add_connection(done_port, port_dn);
182  structural_objectRef port_strt = controller->find_member("in1", port_o_K, controller);
183  SM->add_connection(start_port, port_strt);
184 
186  "Created a shift register with " + std::to_string(num_states) + " bits as pipeline controller");
187 
188  out_ports.clear();
189  mu_ports.clear();
190  cond_ports.clear();
192 }
void add_connection(structural_objectRef src, structural_objectRef dest)
Create a connection between a source structural object and a destination structural object...
Class specification to contain liveness information.
const HLS_managerRef HLSMgr
information about all the HLS synthesis
Definition: hls_step.hpp:205
Data structure representing the entire HLS information.
void * top(node_stack *head)
Definition: tree.c:75
boost::graph_traits< graph >::out_edge_iterator OutEdgeIterator
out_edge_iterator definition.
Definition: graph.hpp:1312
#define GET_TYPE(data, vertex_index)
Helper macro returning the type associated with a node.
pipeline_controller(const ParameterConstRef Param, const HLS_managerRef HLSMgr, unsigned int funId, const DesignFlowManagerConstRef design_flow_manager, const HLSFlowStep_Type hls_flow_step_type=HLSFlowStep_Type::PIPELINE_CONTROLLER_CREATOR)
Constructor.
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 PRINT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
#define DEBUG_LEVEL_PEDANTIC
very verbose debugging print is performed.
#define START_PORT_NAME
This file contains the structures needed to manage a graph that will represent the state transition g...
Structure representing the most relevant information about the type of a structural object...
Base class for all command ports into datapath.
string target
Definition: lenet_tvm.py:16
#define GET_CLASS(obj)
Macro returning the actual type of an object.
std::string get_function_name() const
Return the name of the function.
const structural_objectRef get_circ() const
Get a reference to circ field.
vertex get_entry_state() const
Gets vertex that represents state that contains entry node.
generic_objRef bind_selector_port(direction_type dir, unsigned int mode, const vertex &cond, const OpGraphConstRef data)
virtual void add_common_ports(structural_objectRef circuit, structural_managerRef SM)
This member function adds the standard ports (clock, reset, done and command ones) to a circuit...
DesignFlowStep_Status InternalExec() override
Execute the step.
unsigned int get_assign(const vertex &v) const
Returns the functional unit assigned to the vertex.
Definition: fu_binding.cpp:242
const unsigned int funId
identifier of the function to be processed (0 means that it is a global step)
#define GET_NAME(data, vertex_index)
Helper macro returning the name associated with a node.
const HLS_deviceRef HLS_D
reference to the information representing the target for the synthesis
Definition: hls.hpp:107
exceptions managed by PandA
AllocationInformationRef allocation_information
Store the technology information.
Definition: hls.hpp:115
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.
std::map< vertex, unsigned int > cond_ports
This is the same as in_ports except that the first element is of type vertex.
static technology_nodeRef get_fu(const std::string &fu_name, const HLS_managerConstRef hls_manager)
Returns the technology_node associated with the given operation.
redefinition of map to manage ordered/unordered structures
#define STR(s)
Macro which performs a lexical_cast to a string.
Auxiliary methods for manipulating string.
#define CLOCK_PORT_NAME
standard name for ports
const OpNodeInfoConstRef CGetOpNodeInfo(const vertex node) const
Returns the info associated with a node.
Definition: op_graph.hpp:843
fu_bindingRef Rfu
Store the refcounted functional unit binding of the operations.
Definition: hls.hpp:121
#define register_SHIFT
simple shift register with reset
Data structure used to store the register binding of variables.
Base class for multiplexer into datapath.
void set_top_info(const std::string &id, const technology_managerRef &LM, const std::string &Library="")
Data structure used to store the interconnection binding of datapath elements.
Data structure used to store the schedule of the operations.
#define DONE_PORT_NAME
Control flow graph.
HLSFlowStep_Type
Definition: hls_step.hpp:95
Class specification of the data structures used to manage technology information. ...
#define TYPE_EXTERNAL
constant identifying the node type of a EXTERNAL operation (a function call)
Definition: op_graph.hpp:95
redefinition of set to manage ordered/unordered structures
~pipeline_controller() override
Destructor.
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
void set_black_box(bool bb)
Set the black box property associated with the structural_object.
Base class for all register into datapath.
This file contains the structures needed to manage a graph that will represent the state transition g...
void SetParameter(const std::string &name, const std::string &value)
Set a parameter value.
const BehavioralHelperConstRef CGetBehavioralHelper() const
Returns the helper associated with the function.
Classes specification of the tree_node data structures.
static std::string NormalizeTypename(const std::string &id)
Return normalized name of types and variables.
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
This package is used by all HLS packages to manage resource constraints and characteristics.
std::map< generic_objRef, unsigned int > out_ports
This contains all the ports that go from the controller to the datapath, used to enable the registers...
#define DEBUG_LEVEL_NONE
no debugging print is performed.
This package is used to define the storage value scheme adopted by the register allocation algorithms...
const StateTransitionGraphConstRef CGetAstg() const
Returns pointer to state transition graph created.
This file collects some utility functions.
structural_objectRef add_constant(std::string id, structural_objectRef owner, structural_type_descriptorRef type, std::string value, unsigned int treenode=0)
Create a new constant;.
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.
Class specification of the tree_reindex support class.
Generic class managing controller creation algorithms.
Header class for the creation of a shift register controlling a pipeline.
Data structure used to store the functional-unit binding of the vertexes.
const OpGraphConstRef CGetOpGraph(FunctionBehavior::graph_type gt) const
This method returns the operation graphs.
hlsRef HLS
HLS data structure of the function to be analyzed.
Data structures used in operations graph.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
It collects all the common strings covering PandA copyrights issues.
#define RESET_PORT_NAME
Class implementation of the structural_manager.
StateTransitionGraphManagerRef STG
Store the refcounted state transition graph.
Definition: hls.hpp:124
int debug_level
The debug level.
Base class for all register into datapath.
#define DEBUG_LEVEL_VERBOSE
verbose debugging print is performed.
Data structure definition for high-level synthesis flow.
conn_bindingRef Rconn
Store the refcounted interconnection of datapath elements.
Definition: hls.hpp:139
Class specification of the manager of the tree structures extracted from the raw file.
HLS specialization of generic_device.
A brief description of the C++ Header File.
std::map< vertex, unsigned int > mu_ports
This map put into relation fsm states and alldone multi_unbounded ports.
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...
Definition: exceptions.hpp:289

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