PandA-2024.02
cdfc_module_binding.hpp
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  */
42 #ifndef CDFC_MODULE_BINDING_HPP
43 #define CDFC_MODULE_BINDING_HPP
44 
45 #include "fu_binding_creator.hpp"
46 
47 #include "graph.hpp"
48 
49 #include "hash_helper.hpp"
50 
52 #include <string>
53 
55 #include <deque>
56 #include <utility>
57 #include <vector>
58 
59 #include "custom_map.hpp"
60 #include "custom_set.hpp"
61 
62 //#define HC_APPROACH
63 
65 enum class CliqueCovering_Algorithm;
68 struct spec_hierarchical_clustering;
71 class OpVertexSet;
73 
75 {
76  public:
79 
84  explicit CDFCModuleBindingSpecialization(const CliqueCovering_Algorithm clique_covering_algorithm);
85 
89  std::string GetKindText() const override;
90 
94  std::string GetSignature() const override;
95 };
96 
98 template <typename Graph>
100 {
101  public:
102  using vertex_descriptor = typename boost::graph_traits<Graph>::vertex_descriptor;
105  cdfc_graph_vertex_selector() : all(true), support(nullptr)
106  {
107  }
109  explicit cdfc_graph_vertex_selector(const SET_container* _support) : all(false), support(_support)
110  {
111  }
113  bool operator()(const vertex_descriptor& v) const
114  {
115  if(all)
116  {
117  return true;
118  }
119  else
120  {
121  return support->find(v) != support->end();
122  }
123  }
124 
125  private:
126  bool all;
128 };
129 
131 template <typename Graph>
133 {
134  private:
136  int selector;
137 
140 
141  public:
147  cdfc_graph_edge_selector(const int _selector, Graph* _g) : selector(_selector), g(_g)
148  {
149  }
150 
152  cdfc_graph_edge_selector() : selector(0), g(nullptr)
153  {
154  }
155 
157  template <typename Edge>
158  bool operator()(const Edge& e) const
159  {
160  return selector & (*g)[e].selector;
161  }
162 };
163 
165 {
166  public:
168  int selector;
169 
171  int weight;
172 
176  edge_cdfc_selector() : selector(0), weight(0)
177  {
178  }
179 
184  explicit edge_cdfc_selector(int _selector) : selector(_selector), weight(0)
185  {
186  }
187 
193  edge_cdfc_selector(int _selector, int _weight) : selector(_selector), weight(_weight)
194  {
195  }
196 };
197 
199 using boost_cdfc_graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS,
200  boost::property<boost::vertex_index_t, std::size_t>, edge_cdfc_selector>;
201 
204 
206 using cdfc_graph = boost::filtered_graph<boost_cdfc_graph, cdfc_graph_edge_selector<boost_cdfc_graph>,
208 
213 using cdfc_vertex = boost::graph_traits<cdfc_graph>::vertex_descriptor;
215 using cdfc_in_edge_iterator = boost::graph_traits<cdfc_graph>::in_edge_iterator;
217 using cdfc_out_edge_iterator = boost::graph_traits<cdfc_graph>::out_edge_iterator;
219 using cdfc_edge_iterator = boost::graph_traits<cdfc_graph>::edge_iterator;
221 using cdfc_edge = boost::graph_traits<cdfc_graph>::edge_descriptor;
222 
223 struct CdfcEdgeInfo : public EdgeInfo
224 {
225  const int edge_weight;
226 
231  explicit CdfcEdgeInfo(const int edge_weight);
232 };
235 
239 struct CdfcGraphInfo : public GraphInfo
240 {
242 
245 
249  CdfcGraphInfo(const CustomUnorderedMap<vertex, vertex>& c2s, const OpGraphConstRef operation_graph);
250 };
253 
258 {
259  public:
266 
270  ~CdfcGraphsCollection() override;
271 
280  inline EdgeDescriptor AddEdge(const vertex source, const vertex target, const int selector, const int weight)
281  {
282  THROW_ASSERT(not ExistsEdge(source, target), "Trying to add an already existing edge");
283  return InternalAddEdge(source, target, selector, EdgeInfoRef(new CdfcEdgeInfo(weight)));
284  }
285 
293  inline EdgeDescriptor AddEdge(const vertex source, const vertex target, const int selector)
294  {
295  if(ExistsEdge(source, target))
296  {
297  return AddSelector(source, target, selector);
298  }
299  else
300  {
301  return InternalAddEdge(source, target, selector, EdgeInfoRef(new CdfcEdgeInfo(0)));
302  }
303  }
304 };
307 
311 class CdfcGraph : public graph
312 {
313  public:
319  CdfcGraph(const CdfcGraphsCollectionRef cdfc_graphs_collection, const int selector);
320 
327  CdfcGraph(const CdfcGraphsCollectionRef cdfc_graphs_collection, const int selector,
328  const CustomUnorderedSet<vertex>& vertices);
329 
333  ~CdfcGraph() override;
334 
339  {
340  return RefcountCast<const CdfcEdgeInfo>(graph::CGetEdgeInfo(e));
341  }
342 
348  void WriteDot(const std::string& file_name, const int detail_level = 0) const;
349 };
352 
363 {
368 };
369 
372 using connection_relation =
374 
379 {
380  protected:
383 
384  bool false_loop_search(cdfc_vertex start, unsigned k, const cdfc_graphConstRef& cdfc, const cdfc_graphConstRef& cg,
385  std::deque<cdfc_edge>& candidate_edges);
386  bool false_loop_search_cdfc_1(cdfc_vertex src, unsigned int level, unsigned k, cdfc_vertex start,
387  const cdfc_graphConstRef& cdfc, const cdfc_graphConstRef& cg,
388  std::deque<cdfc_edge>& candidate_edges, std::vector<bool>& visited,
389  std::vector<bool>& cg_visited, std::vector<bool>& cdfc_visited);
390  bool false_loop_search_cdfc_more(cdfc_vertex src, unsigned int level, unsigned k, cdfc_vertex start,
391  const cdfc_graphConstRef& cdfc, const cdfc_graphConstRef& cg,
392  std::deque<cdfc_edge>& candidate_edges, std::vector<bool>& visited,
393  std::vector<bool>& cg_visited, std::vector<bool>& cdfc_visited);
394  bool can_be_clustered(vertex v, OpGraphConstRef fsdg, const fu_bindingConstRef fu,
395  const CustomUnorderedMap<vertex, double>& slack_time, const double mux_time);
396 
397  int weight_computation(bool cond1, bool cond2, vertex v1, vertex v2, const double mux_time,
398  const OpGraphConstRef fdfg, const fu_bindingConstRef fu,
399  const CustomUnorderedMap<vertex, double>& slack_time,
400  CustomUnorderedMap<vertex, double>& starting_time,
401 #ifdef HC_APPROACH
402  spec_hierarchical_clustering& hc,
403 #endif
404  connection_relation& con_rel, double controller_delay, unsigned long long prec);
405 
406  void update_slack_starting_time(const OpGraphConstRef fdfg, OpVertexSet& sorted_vertices,
408  CustomUnorderedMap<vertex, double>& starting_time, bool update_starting_time,
409  bool only_backward, bool only_forward);
410 
411  void initialize_connection_relation(connection_relation& con_rel, const OpVertexSet& all_candidate_vertices);
412 
413  static const int CD_EDGE = 1;
414  static const int COMPATIBILITY_EDGE = 2;
415 
419 
420  public:
424  cdfc_module_binding(const ParameterConstRef _parameters, const HLS_managerRef HLSMgr, unsigned int funId,
425  const DesignFlowManagerConstRef design_flow_manager,
426  const HLSFlowStepSpecializationConstRef hls_flow_step_specialization);
427 
431  ~cdfc_module_binding() override;
432 
437  DesignFlowStep_Status InternalExec() override;
438 };
439 
440 #endif
The info associated with a cdfc graph.
bool operator()(const Edge &e) const
edge selector operator
Base class storing user data information to the whole graph.
Definition: graph_info.hpp:60
string target
Definition: lenet_tvm.py:16
boost::graph_traits< cdfc_graph >::in_edge_iterator cdfc_in_edge_iterator
in_edge_iterator definition.
Predicate functor object used to select the proper set of edges.
Class specification of the graph structures.
const EdgeInfoConstRef CGetEdgeInfo(typename boost::graph_traits< graphs_collection >::vertex_descriptor source, typename boost::graph_traits< graphs_collection >::vertex_descriptor target) const
Get the edge property.
Definition: graph.hpp:811
CliqueCovering_Algorithm
Defines all clique covering algorithm.
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMapUnstable
Definition: custom_map.hpp:156
cdfc_graph_edge_selector()
all edges selector
CustomUnorderedMap< vertex, std::vector< CustomOrderedSet< std::pair< conn_code, std::pair< unsigned int, vertex > >> >> connection_relation
put into relation an operation vertex with its sources op vertex -> vector of port index -> set of pa...
redefinition of map to manage ordered/unordered structures
A set of operation vertices.
Definition: op_graph.hpp:654
boost::filtered_graph< boost_cdfc_graph, cdfc_graph_edge_selector< boost_cdfc_graph >, cdfc_graph_vertex_selector< boost_cdfc_graph > > cdfc_graph
compatibility graph
const CdfcEdgeInfoConstRef CGetCdfcEdgeInfo(const EdgeDescriptor e) const
Returns the info associated with an edge.
conn_code
connection code can be no_def - source is not defined because is a parameter or a constan value in th...
std::string GetSignature() const override
Return the contribution to the signature of a step given by the specialization.
typename boost::graph_traits< Graph >::vertex_descriptor vertex_descriptor
CustomUnorderedMap< vertex, bool > can_be_clustered_table
record if a vertex has to be clustered or not
REF_FORWARD_DECL(fu_binding)
Abstract class containing information about specialization of the single steps.
Definition: hls_step.hpp:75
EdgeDescriptor AddEdge(const vertex source, const vertex target, const int selector)
Add an edge with empty information associated.
Cdfc collection of graphs.
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMap
Definition: custom_map.hpp:148
Class managing the module allocation.
static const uint32_t k[]
Definition: sha-256.c:22
bool operator()(const vertex_descriptor &v) const
selector operator
cdfc_graph_vertex_selector(const SET_container *_support)
constructor
int selector
The selector associated with the edge.
std::string GetKindText() const override
Return the string representation of this.
refcount< EdgeInfo > EdgeInfoRef
RefCount type definition of the edge_info class structure.
Definition: edge_info.hpp:67
edge_cdfc_selector(int _selector, int _weight)
Constructor with selector.
const CliqueCovering_Algorithm clique_covering_algorithm
The cdfc module binding algorithm.
redefinition of set to manage ordered/unordered structures
const CustomUnorderedMap< vertex, vertex > & c2s
const OpGraphConstRef operation_graph
The operation graph associated with the cdfc graph.
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
edge_cdfc_selector()
default constructor
General class used to describe a graph in PandA.
Definition: graph.hpp:771
CONSTREF_FORWARD_DECL(AllocationInformation)
STD include.
DesignFlowStep_Status
The status of a step.
Cdfc graph.
Base class storing user data information.
Definition: edge_info.hpp:55
Base class for all module binding algorithms.
edge_cdfc_selector(int _selector)
Constructor with selector only.
const double small_normalized_resource_area
Threshold used in sharing of functional units.
boost::graph_traits< cdfc_graph >::edge_descriptor cdfc_edge
edge definition.
bulk graph.
Definition: graph.hpp:287
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, boost::property< boost::vertex_index_t, std::size_t >, edge_cdfc_selector > boost_cdfc_graph
bulk compatibility graph
boost::graph_traits< cdfc_graph >::edge_iterator cdfc_edge_iterator
edge_iterator definition.
CDFCModuleBindingSpecialization(const CliqueCovering_Algorithm clique_covering_algorithm)
Constructor.
EdgeDescriptor AddEdge(const vertex source, const vertex target, const int selector, const int weight)
Add an edge with a weight.
Predicate functor object used to select the proper set of vertices.
This file collects some hash functors.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
int level
Definition: main.c:98
int selector
The selector associated with the filtered graph.
Class managing the functional-unit binding.
Definition: fu_binding.hpp:90
boost::graph_traits< cdfc_graph >::vertex_descriptor cdfc_vertex
vertex definition
Class used to describe a particular graph with operations as nodes.
Definition: op_graph.hpp:783
CustomUnorderedMapUnstable< std::pair< vertex, unsigned int >, bool > is_complex
cdfc_graph_edge_selector(const int _selector, Graph *_g)
Constructor for filtering only on selector.
boost::graph_traits< cdfc_graph >::out_edge_iterator cdfc_out_edge_iterator
out_edge_iterator definition.
Generic class managing module binding algorithms.
boost::graph_traits< graph >::edge_descriptor EdgeDescriptor
edge definition.
Definition: graph.hpp:1316
#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