PandA-2024.02
weighted_clique_register.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 
45 #include <filesystem>
46 
47 #include "check_clique.hpp"
48 #include "clique_covering.hpp"
49 #include "filter_clique.hpp"
50 
51 #include "hls.hpp"
52 #include "hls_manager.hpp"
53 #include "liveness.hpp"
54 #include "reg_binding.hpp"
55 
57 #include "Parameter.hpp"
58 
60 #include "cdfc_module_binding.hpp"
61 
64 
66 #include "behavioral_helper.hpp"
67 
69 #include "cpu_time.hpp"
70 
72  const CliqueCovering_Algorithm _clique_covering_algorithm)
73  : clique_covering_algorithm(_clique_covering_algorithm)
74 {
75 }
76 
78 {
80 }
81 
83 {
84  return STR(static_cast<unsigned int>(clique_covering_algorithm));
85 }
86 
88  const ParameterConstRef _parameters, const HLS_managerRef _HLSMgr, unsigned int _funId,
89  const DesignFlowManagerConstRef _design_flow_manager,
90  const HLSFlowStepSpecializationConstRef _hls_flow_step_specialization)
92  _parameters, _HLSMgr, _funId, _design_flow_manager, HLSFlowStep_Type::WEIGHTED_CLIQUE_REGISTER_BINDING,
93  _hls_flow_step_specialization ?
94  _hls_flow_step_specialization :
96  _parameters->getOption<CliqueCovering_Algorithm>(OPT_weighted_clique_register_algorithm))))
97 {
98 }
99 
101 
103 {
106 }
107 
109 {
110  const auto FB = HLSMgr->CGetFunctionBehavior(funId);
111  long step_time = 0;
113  {
114  START_TIME(step_time);
115  }
116  const auto clique_covering_algorithm =
117  GetPointer<const WeightedCliqueRegisterBindingSpecialization>(hls_flow_step_specialization)
118  ->clique_covering_algorithm;
119  const auto register_clique = clique_covering<CG_vertex_descriptor>::create_solver(
120  clique_covering_algorithm, HLS->storage_value_information->get_number_of_storage_values());
122 
123  size_t vertex_index = 0;
124  unsigned int num_registers = 0;
125  for(const auto v : verts)
126  {
127  register_clique->add_vertex(v, STR(vertex_index++));
128  }
129  if(vertex_index > 0)
130  {
131  if(clique_covering_algorithm == CliqueCovering_Algorithm::BIPARTITE_MATCHING)
132  {
133  const std::list<vertex>& support = HLS->Rliv->get_support();
134  unsigned current_partition = 0;
135  for(auto vState : support)
136  {
137  const CustomOrderedSet<unsigned int>& live = HLS->Rliv->get_live_in(vState);
138  for(auto l : live)
139  {
140  unsigned int sv = HLS->storage_value_information->get_storage_value_index(vState, l);
141  register_clique->add_subpartitions(current_partition, verts[sv]);
142  }
143  ++current_partition;
144  }
145  }
146  HLS->Rreg->set_used_regs(num_registers);
147  BOOST_FOREACH(compatibility_graph::edge_descriptor e, boost::edges(*CG))
148  {
149  const auto src = boost::source(e, *CG);
150  const auto tgt = boost::target(e, *CG);
151  register_clique->add_edge(src, tgt, (*CG)[e].weight);
152  }
153  if(parameters->getOption<bool>(OPT_print_dot))
154  {
155  const auto functionName = FB->CGetBehavioralHelper()->get_function_name();
156  const auto output_directory = parameters->getOption<std::string>(OPT_dot_directory) + "/" + functionName + "/";
157  if(!std::filesystem::exists(output_directory))
158  {
159  std::filesystem::create_directories(output_directory);
160  }
161  const auto file_name = output_directory + "HLS_RegisterBinding.dot";
162  register_clique->writeDot(file_name);
163  }
166  register_clique->exec(no_filter_clique<CG_vertex_descriptor>(), cq);
170  num_registers = static_cast<unsigned int>(register_clique->num_vertices());
171  for(unsigned int i = 0; i < num_registers; ++i)
172  {
173  for(const auto v : register_clique->get_clique(i))
174  {
175  v2c[v] = i;
176  }
177  }
180  for(const auto v : HLS->Rliv->get_support())
181  {
182  for(const auto k : HLS->Rliv->get_live_in(v))
183  {
184  unsigned int storage_value_index = HLS->storage_value_information->get_storage_value_index(v, k);
185  HLS->Rreg->bind(storage_value_index, v2c[verts[storage_value_index]]);
186  }
187  }
188  }
189  else
190  {
192  num_registers = 0;
193  }
194  delete CG;
195  HLS->Rreg->set_used_regs(num_registers);
197  {
198  STOP_TIME(step_time);
199  }
201  {
203  }
205  "-->Register binding information for function " + FB->CGetBehavioralHelper()->get_function_name() +
206  ":");
208  std::string("---Register allocation algorithm obtains ") +
209  (num_registers == register_lower_bound ? "an optimal" : "a sub-optimal") +
210  " result: " + STR(num_registers) + " registers" +
211  (num_registers == register_lower_bound ? "" : ("(LB:" + STR(register_lower_bound) + ")")));
213  {
214  HLS->Rreg->print();
215  }
217  {
219  "Time to perform register binding: " + print_cpu_time(step_time) + " seconds");
220  }
223  {
225  }
227 }
void Initialize() override
Initialize the step (i.e., like a constructor, but executed just before exec.
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.
Module binding based on the analysis of the control data flow chained graph.
This header file includes four different algorithms heuristically solving the clique covering problem...
string target
Definition: lenet_tvm.py:16
const CliqueCovering_Algorithm clique_covering_algorithm
The algorithm to be used.
Weighted clique covering register allocation procedure.
const int output_level
The output level.
compatibility_graph * CG
compatibility graph
#define INDENT_OUT_MEX(outLevel, curOutLevel, mex)
void set_used_regs(unsigned int regs)
sets number of used register
const unsigned int funId
identifier of the function to be processed (0 means that it is a global step)
void bind(unsigned int sv, unsigned int index)
CliqueCovering_Algorithm
Defines all clique covering algorithm.
std::vector< CG_vertex_descriptor > verts
ordered vector containing the vertices of the compatibility graph
#define OUTPUT_LEVEL_MINIMUM
minimum debugging print is performed.
Include a set of utilities used to manage CPU time measures.
#define STR(s)
Macro which performs a lexical_cast to a string.
static reg_bindingRef create_reg_binding(const hlsRef &HLS, const HLS_managerRef HLSMgr_)
Definition: reg_binding.cpp:85
DesignFlowStep_Status RegisterBinding() final
const std::list< vertex > & get_support() const
return the support set of the live in/out
Definition: liveness.hpp:212
#define START_TIME(time_var)
Macro used to store the start time into time_var.
Definition: cpu_time.hpp:133
unsigned edges[4545]
Definition: graph.h:25
Data structure used to store the register binding of variables.
StorageValueInformationRef storage_value_information
data-structure for storage values
Definition: hls.hpp:130
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMap
Definition: custom_map.hpp:148
static const uint32_t k[]
Definition: sha-256.c:22
static refcount< clique_covering< VertexType > > create_solver(CliqueCovering_Algorithm solver, unsigned int nvert)
Creates a reference to desired solver.
HLSFlowStep_Type
Definition: hls_step.hpp:95
#define STOP_TIME(time_var)
Macro used to store the elapsed time into time_var.
Definition: cpu_time.hpp:136
weighted_clique_register(const ParameterConstRef _Param, const HLS_managerRef _HLSMgr, unsigned int _funId, const DesignFlowManagerConstRef design_flow_manager, const HLSFlowStepSpecializationConstRef hls_flow_step_specialization)
Constructor of the class.
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
reg_bindingRef Rreg
Store the refcounted register binding of the variables.
Definition: hls.hpp:133
unsigned int register_lower_bound
lower bound
This package is used to define the storage value scheme adopted by the register allocation algorithms...
livenessRef Rliv
data-structure containing the variable liveness
Definition: hls.hpp:127
std::string print_cpu_time(long int t)
massage a long which represents a time interval in milliseconds, into a string suitable for output ...
Definition: cpu_time.hpp:110
virtual void print() const
Function that prints the class variable2obj.
Definition: Variable.hpp:82
const std::string CliqueCovering_AlgorithmToString(const CliqueCovering_Algorithm clique_covering_algorithm)
Header include.
#define OUTPUT_LEVEL_PEDANTIC
verbose debugging print is performed.
#define OUTPUT_LEVEL_VERY_PEDANTIC
verbose debugging print is performed.
hlsRef HLS
HLS data structure of the function to be analyzed.
virtual unsigned int get_storage_value_index(vertex curr_vertex, unsigned int var_index)=0
Returns the index of the storage value associated with the variable in a given vertex.
WeightedCliqueRegisterBindingSpecialization(const CliqueCovering_Algorithm clique_covering_algorithm)
Constructor.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
std::string GetKindText() const override
Return the string representation of this.
this class is used to manage the command-line or XML options.
std::string GetSignature() const override
Return the contribution to the signature of a step given by the specialization.
unsigned int get_number_of_storage_values() const
Returns the number of storage values inserted.
void Initialize() override
Initialize the step (i.e., like a constructor, but executed just before exec.
void create_compatibility_graph()
Creates the compatibility graph.
Data structure definition for high-level synthesis flow.
const HLSFlowStepSpecializationConstRef hls_flow_step_specialization
The information about specialization.
Definition: hls_step.hpp:211
~weighted_clique_register() override
const CustomOrderedSet< unsigned int > & get_live_in(const vertex &v) const
Get the set of variables live at the input of a vertex.
Definition: liveness.cpp:109

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