PandA-2024.02
add_library.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  */
44 #include "add_library.hpp"
45 #include "Parameter.hpp" // for ParameterConstRef
46 #include "behavioral_helper.hpp"
47 #include "call_graph_manager.hpp"
48 #include "dbgPrintHelper.hpp" // for INDENT_DBG_MEX, DEBUG_LEVEL_VERY_...
49 #include "exceptions.hpp" // for THROW_ASSERT, THROW_UNREACHABLE
50 #include "hls.hpp" // for HLS_managerRef
51 #include "hls_device.hpp" // for generic_deviceRef
52 #include "hls_manager.hpp" // for HLS_managerRef
53 #include "library_manager.hpp"
54 #include "string_manipulation.hpp" // for STR GET_CLASS
55 #include "technology_manager.hpp" // for WORK_LIBRARY
56 #include "technology_node.hpp" // for functional_unit, operation (ptr o...
57 
58 #include "fu_binding.hpp"
59 #include "hls_constraints.hpp"
60 #include "memory.hpp"
61 #include "reg_binding.hpp"
64 
65 #include "area_info.hpp"
66 #include "omp_functions.hpp"
67 #include "time_info.hpp"
68 
70 #include "structural_manager.hpp"
71 
74 
76 #include "custom_set.hpp"
77 #include <tuple>
78 
79 AddLibrarySpecialization::AddLibrarySpecialization(const bool _interfaced) : interfaced(_interfaced)
80 {
81 }
82 
84 {
85  return interfaced ? "Interfaced" : "";
86 }
87 
89 {
90  return interfaced ? "Interfaced" : "";
91 }
92 
93 add_library::add_library(const ParameterConstRef _parameters, const HLS_managerRef _HLSMgr, unsigned _funId,
94  const DesignFlowManagerConstRef _design_flow_manager,
95  const HLSFlowStepSpecializationConstRef _hls_flow_step_specialization)
96  : HLSFunctionStep(_parameters, _HLSMgr, _funId, _design_flow_manager, HLSFlowStep_Type::ADD_LIBRARY,
97  _hls_flow_step_specialization)
98 {
99  debug_level = parameters->get_class_debug_level(GET_CLASS(*this));
100 }
101 
102 add_library::~add_library() = default;
103 
106 {
107  const auto* const add_library_specialization =
108  GetPointer<const AddLibrarySpecialization>(hls_flow_step_specialization);
109  THROW_ASSERT(hls_flow_step_specialization, "Empty specialization type");
110  THROW_ASSERT(add_library_specialization,
111  "Wrong specialization type: " + hls_flow_step_specialization->GetKindText());
113  switch(relationship_type)
114  {
116  {
117  if(add_library_specialization->interfaced)
118  {
119  ret.insert(std::make_tuple(parameters->getOption<HLSFlowStep_Type>(OPT_interface_type),
121  }
122  else
123  {
124  ret.insert(std::make_tuple(parameters->getOption<HLSFlowStep_Type>(OPT_function_allocation_algorithm),
126  HLSFlowStep_Relationship::SAME_FUNCTION)); // add dependence to omp_function
127  if(HLSMgr->Rfuns)
128  {
129  bool found = false;
130  if(parameters->isOption(OPT_context_switch))
131  {
132  auto omp_functions = GetPointer<OmpFunctions>(HLSMgr->Rfuns);
133  THROW_ASSERT(omp_functions, "OMP_functions must not be null");
134  if(omp_functions->omp_for_wrappers.find(funId) != omp_functions->omp_for_wrappers.end())
135  {
137  ret.insert(std::make_tuple(top_entity_type, HLSFlowStepSpecializationConstRef(),
139  found = true;
140  }
141  else
142  {
143  if(omp_functions->kernel_functions.find(funId) != omp_functions->kernel_functions.end())
144  {
145  found = true;
146  }
147  if(omp_functions->atomic_functions.find(funId) != omp_functions->atomic_functions.end())
148  {
149  found = true;
150  }
151  if(omp_functions->parallelized_functions.find(funId) !=
152  omp_functions->parallelized_functions.end())
153  {
154  found = true;
155  }
156  if(found) // use new top_entity
157  {
159  ret.insert(std::make_tuple(top_entity_type, HLSFlowStepSpecializationConstRef(),
161  }
162  }
163  }
164  if(!found) // use standard
165  {
166  const auto cg_man = HLSMgr->CGetCallGraphManager();
167  const HLSFlowStep_Type top_entity_type =
168  HLSMgr->hasToBeInterfaced(funId) && (cg_man->ExistsAddressedFunction() ||
169  parameters->getOption<bool>(OPT_memory_mapped_top)) ?
172  ret.insert(std::make_tuple(top_entity_type, HLSFlowStepSpecializationConstRef(),
174  }
175  }
176  }
177  break;
178  }
180  {
181  break;
182  }
184  {
185  break;
186  }
187  default:
188  THROW_UNREACHABLE("");
189  }
190  return ret;
191 }
192 
194 {
195  const auto add_library_specialization = GetPointerS<const AddLibrarySpecialization>(hls_flow_step_specialization);
196  const auto FB = HLSMgr->CGetFunctionBehavior(funId);
197  const auto BH = FB->CGetBehavioralHelper();
198  THROW_ASSERT(HLS->top, "Top has not been set");
199  const auto& module_name = HLS->top->get_circ()->get_typeRef()->id_type;
200  const auto TechM = HLS->HLS_D->get_technology_manager();
201  const auto wrapped_fu_name = WRAPPED_PROXY_PREFIX + module_name;
202  const auto wrapper_tn = TechM->get_fu(wrapped_fu_name, PROXY_LIBRARY);
203  if(wrapper_tn)
204  {
205  TechM->get_library_manager(PROXY_LIBRARY)->remove_fu(wrapped_fu_name);
206  }
207  const auto proxy_fu_name = PROXY_PREFIX + module_name;
208  const auto proxy_tn = TechM->get_fu(proxy_fu_name, PROXY_LIBRARY);
209  if(proxy_tn)
210  {
211  TechM->get_library_manager(PROXY_LIBRARY)->remove_fu(proxy_fu_name);
212  }
213 
215  "Adding " + module_name + " to " + WORK_LIBRARY + " - Object is " + HLS->top->get_circ()->get_path());
216  TechM->add_resource(WORK_LIBRARY, module_name, HLS->top);
217  const auto clock_period_value = HLS->HLS_C->get_clock_period();
218  const auto cprf = HLS->HLS_C->get_clock_period_resource_fraction();
219  const auto clk = cprf * clock_period_value;
220  const auto device = HLS->HLS_D;
221  const auto fu = GetPointerS<functional_unit>(TechM->get_fu(module_name, WORK_LIBRARY));
222  fu->set_clock_period(clock_period_value);
223  fu->set_clock_period_resource_fraction(cprf);
224  auto module_parameters = (HLS->top->get_circ() && GetPointer<module>(HLS->top->get_circ()) &&
225  GetPointerS<module>(HLS->top->get_circ())->get_NP_functionality()) ?
226  GetPointerS<module>(HLS->top->get_circ())
227  ->get_NP_functionality()
228  ->get_NP_functionality(NP_functionality::LIBRARY) :
229  "";
230  if(module_parameters.find(' ') != std::string::npos)
231  {
232  module_parameters = module_parameters.substr(module_parameters.find(' '));
233  }
234  fu->CM->add_NP_functionality(HLS->top->get_circ(), NP_functionality::LIBRARY, module_name + module_parameters);
235  if(!add_library_specialization->interfaced)
236  {
237  const auto function_name = BH->get_function_name();
238  TechM->add_operation(WORK_LIBRARY, module_name, function_name);
239  const auto op = GetPointerS<operation>(fu->get_operation(function_name));
240  op->primary_inputs_registered = HLS->registered_inputs;
241  op->bounded = HLS->STG && HLS->STG->CGetStg()->CGetStateTransitionGraphInfo()->bounded;
242  const auto call_delay =
244  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Estimated call delay " + STR(call_delay));
245  op->time_m = time_info::factory(parameters);
246  if(op->bounded)
247  {
248  const auto min_cycles = HLS->STG->CGetStg()->CGetStateTransitionGraphInfo()->min_cycles;
249  const auto max_cycles = HLS->STG->CGetStg()->CGetStateTransitionGraphInfo()->max_cycles;
250  const auto exec_time = [&]() {
251  if(min_cycles > 1)
252  {
253  return clk * (min_cycles - 1) + call_delay;
254  }
255  return call_delay;
256  }();
257  op->time_m->set_execution_time(exec_time, min_cycles);
258  if(max_cycles > 1)
259  {
260  if(FB->is_simple_pipeline())
261  {
262  op->time_m->set_stage_period(call_delay);
263  const ControlStep jj(1);
264  op->time_m->set_initiation_time(jj);
265  }
266  else
267  {
268  op->time_m->set_stage_period(0.0);
269  }
270  }
271  else
272  {
273  op->time_m->set_stage_period(0.0);
274  }
275  if(min_cycles <= 1 &&
276  (HLSMgr->Rmem->get_allocated_space() + HLSMgr->Rmem->get_allocated_parameters_memory()) == 0)
277  {
278  fu->logical_type = functional_unit::COMBINATIONAL;
279  }
280  }
281  else
282  {
283  op->time_m->set_execution_time(call_delay, 0);
284  }
285  op->time_m->set_synthesis_dependent(true);
287  "Added " + module_name + (op->bounded ? "" : "(unbounded)") + " to WORK_LIBRARY");
288  }
289  else
290  {
291  INDENT_DBG_MEX(DEBUG_LEVEL_MINIMUM, debug_level, "Added " + module_name + " to WORK_LIBRARY");
292  }
293  fu->area_m = area_info::factory(parameters);
294  fu->area_m->set_area_value(2000);
295 
297 }
#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;.
Collect information about resource area.
add_library(const ParameterConstRef _parameters, const HLS_managerRef HLSMgr, unsigned int funId, const DesignFlowManagerConstRef design_flow_manager, const HLSFlowStepSpecializationConstRef hls_flow_step_specialization)
Constructor.
Definition: add_library.cpp:93
File containing functions and utilities to support the printing of debug messagges.
This step adds the current module to the technology library.
This file contains the structures needed to manage a graph that will represent the state transition g...
#define GET_CLASS(obj)
Macro returning the actual type of an object.
const structural_objectRef get_circ() const
Get a reference to circ field.
RelationshipType
The relationship type.
Source must be executed to satisfy target.
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
exceptions managed by PandA
AllocationInformationRef allocation_information
Store the technology information.
Definition: hls.hpp:115
Collect information about resource performance.
Class specification of the manager of the technology library data structures.
~add_library() override
Destructor.
#define STR(s)
Macro which performs a lexical_cast to a string.
Auxiliary methods for manipulating string.
structural_managerRef top
Store the top description.
Definition: hls.hpp:164
bool registered_inputs
true when the module has registered inputs
Definition: hls.hpp:147
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
Definition: exceptions.hpp:292
Data structure used to store the register binding of variables.
HLSFlowStep_Type
Definition: hls_step.hpp:95
Class specification of the data structures used to manage technology information. ...
const std::string get_path() const
Return a unique identifier of the structural object.
redefinition of set to manage ordered/unordered structures
#define PROXY_PREFIX
This file contains the structures needed to manage a graph that will represent the state transition g...
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.
Data structure definition for HLS constraints.
#define WRAPPED_PROXY_PREFIX
AddLibrarySpecialization(const bool interfaced)
Constructor.
Definition: add_library.cpp:79
std::string id_type
Original type id of the structural object.
const structural_type_descriptorRef & get_typeRef() const
Return the type descriptor of the structural_object.
static area_infoRef factory(const ParameterConstRef &Param)
Factory method.
Definition: area_info.cpp:52
Data structure used to store the functional-unit binding of the vertexes.
#define WORK_LIBRARY
working library.
hlsRef HLS
HLS data structure of the function to be analyzed.
std::string GetSignature() const override
Return the contribution to the signature of a step given by the specialization.
Definition: add_library.cpp:88
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
this class is used to manage the command-line or XML options.
Wrapper to call graph.
Class implementation of the structural_manager.
StateTransitionGraphManagerRef STG
Store the refcounted state transition graph.
Definition: hls.hpp:124
const HLS_constraintsRef HLS_C
store the HLS constraints
Definition: hls.hpp:110
Class specification of the manager for each library.
int debug_level
The debug level.
refcount< const HLSFlowStepSpecialization > HLSFlowStepSpecializationConstRef
const refcount definition of the class
Definition: hls_step.hpp:93
std::string GetKindText() const override
Return the string representation of this.
Definition: add_library.cpp:83
Datastructure to describe functions allocation in high-level synthesis.
Data structure definition for high-level synthesis flow.
Superclass include.
DesignFlowStep_Status InternalExec() override
Execute the step.
const StateTransitionGraphConstRef CGetStg() const
Returns pointer to state transition graph created.
const bool interfaced
True if we are adding module with interface.
Definition: add_library.hpp:62
static time_infoRef factory(const ParameterConstRef Param)
Definition: time_info.cpp:110
Datastructure to represent memory information in high-level synthesis.
#define PROXY_LIBRARY
proxy library
const CustomUnorderedSet< std::tuple< HLSFlowStep_Type, HLSFlowStepSpecializationConstRef, HLSFlowStep_Relationship > > ComputeHLSRelationships(const DesignFlowStep::RelationshipType relationship_type) const override
Return the set of analyses in relationship with this design step.
const HLSFlowStepSpecializationConstRef hls_flow_step_specialization
The information about specialization.
Definition: hls_step.hpp:211
HLS specialization of generic_device.
#define DEBUG_LEVEL_MINIMUM
minimum debugging print is performed.
#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:54 for PandA-2024.02 by doxygen 1.8.13