PandA-2024.02
omp_function_allocation_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) 2015-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 
46 #include "Parameter.hpp"
47 
49 #include "call_graph.hpp"
50 #include "call_graph_manager.hpp"
51 #include "function_behavior.hpp"
52 
54 #include <boost/range/adaptor/reversed.hpp>
55 
57 #include "hls_manager.hpp"
58 
60 #include "omp_functions.hpp"
61 
63 #include <list>
64 
66 #include "behavioral_helper.hpp"
67 #include "tree_manager.hpp"
68 
70 #include "dbgPrintHelper.hpp"
71 #include "utility.hpp"
72 
74  const DesignFlowManagerConstRef _design_flow_manager)
75  : fun_dominator_allocation(_parameters, _HLSMgr, _design_flow_manager, HLSFlowStep_Type::OMP_FUNCTION_ALLOCATION_CS)
76 {
77  debug_level = parameters->get_class_debug_level(GET_CLASS(*this));
78 }
79 
81 
83 {
84  auto omp_functions = GetPointer<OmpFunctions>(HLSMgr->Rfuns);
85  const auto TM = HLSMgr->get_tree_manager();
87  const auto call_graph_manager = HLSMgr->CGetCallGraphManager();
88  auto root_functions = call_graph_manager->GetRootFunctions();
89  if(parameters->isOption(OPT_top_design_name)) // top design function become the top_vertex
90  {
91  const auto top_rtldesign_function =
92  HLSMgr->get_tree_manager()->GetFunction(parameters->getOption<std::string>(OPT_top_design_name));
93  if(top_rtldesign_function && root_functions.count(top_rtldesign_function->index))
94  {
95  root_functions.clear();
96  root_functions.insert(top_rtldesign_function->index);
97  }
98  }
99  CustomUnorderedSet<vertex> vertex_subset;
100  for(const auto f_id : root_functions)
101  {
102  for(const auto reached_f_id : call_graph_manager->GetReachedFunctionsFrom(f_id))
103  {
104  vertex_subset.insert(call_graph_manager->GetVertex(reached_f_id));
105  }
106  }
107  const auto call_graph = call_graph_manager->CGetCallSubGraph(vertex_subset);
108  std::list<vertex> sorted_functions;
109  call_graph->TopologicalSort(sorted_functions);
110  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "Computing functions to be parallelized");
111  int cycleInd = 0;
112  for(const auto function : sorted_functions)
113  {
114  bool function_classification_found = false;
115  const auto function_id = call_graph_manager->get_function(function);
116  std::cout << cycleInd << " "
117  << HLSMgr->CGetFunctionBehavior(function_id)->CGetBehavioralHelper()->get_function_name() << std::endl;
118  if(HLSMgr->CGetFunctionBehavior(function_id)
119  ->CGetBehavioralHelper()
120  ->GetOmpForDegree()) // look for OMP function, add it to struct
121  {
123  "---Found omp for wrapper " +
124  HLSMgr->CGetFunctionBehavior(function_id)->CGetBehavioralHelper()->get_function_name());
125  omp_functions->omp_for_wrappers.insert(function_id);
126  ++cycleInd;
127  continue;
128  }
129  InEdgeIterator ie, ie_end;
130  for(boost::tie(ie, ie_end) = boost::in_edges(function, *call_graph);
131  ie != ie_end && !function_classification_found; ie++)
132  { // if current function is called by parallel then is kernel
133  const auto source = boost::source(*ie, *call_graph);
134  const auto source_id = call_graph_manager->get_function(source);
135  if(omp_functions->omp_for_wrappers.find(source_id) != omp_functions->omp_for_wrappers.end())
136  {
138  "---Found kernel function: " +
139  HLSMgr->CGetFunctionBehavior(function_id)->CGetBehavioralHelper()->get_function_name());
140  omp_functions->kernel_functions.insert(function_id);
141  function_classification_found = true;
142  break;
143  }
144  }
145  for(boost::tie(ie, ie_end) = boost::in_edges(function, *call_graph);
146  ie != ie_end && !function_classification_found; ie++)
147  { // if current function is called by kernel or a parallel function then is a function inside the kernel
148  const auto source = boost::source(*ie, *call_graph);
149  const auto source_id = call_graph_manager->get_function(source);
150  if(omp_functions->kernel_functions.find(source_id) != omp_functions->kernel_functions.end() or
151  omp_functions->parallelized_functions.find(source_id) != omp_functions->parallelized_functions.end())
152  {
153  if(HLSMgr->CGetFunctionBehavior(function_id)
154  ->CGetBehavioralHelper()
155  ->IsOmpFunctionAtomic()) // atomic function
156  {
159  "---Found atomic function: " +
160  HLSMgr->CGetFunctionBehavior(function_id)->CGetBehavioralHelper()->get_function_name());
161  omp_functions->atomic_functions.insert(function_id);
162  }
163  else // is a normal function under the kernel
164  {
167  "---Found function to be parallelized: " +
168  HLSMgr->CGetFunctionBehavior(function_id)->CGetBehavioralHelper()->get_function_name());
169  omp_functions->parallelized_functions.insert(function_id);
170  }
171  break;
172  }
173  }
174  cycleInd = cycleInd + 1;
175  }
176  // invert list
177  cycleInd = 0;
178  for(const auto function : boost::adaptors::reverse(sorted_functions))
179  {
180  const auto function_id = call_graph_manager->get_function(function);
181  std::cout << cycleInd << " "
182  << HLSMgr->CGetFunctionBehavior(function_id)->CGetBehavioralHelper()->get_function_name() << std::endl;
183  OutEdgeIterator ie, ie_end;
184  for(boost::tie(ie, ie_end) = boost::out_edges(function, *call_graph); ie != ie_end; ie++)
185  { // if current function is called by parallel then is kernel
186  const auto target = boost::target(*ie, *call_graph);
187  const auto target_id = call_graph_manager->get_function(target);
188  if(omp_functions->omp_for_wrappers.find(target_id) != omp_functions->omp_for_wrappers.end() or
189  omp_functions->hierarchical_functions.find(target_id) != omp_functions->hierarchical_functions.end())
190  {
192  "---Found hierarchical function: " +
193  HLSMgr->CGetFunctionBehavior(function_id)->CGetBehavioralHelper()->get_function_name());
194  omp_functions->hierarchical_functions.insert(function_id);
195  break;
196  }
197  }
198  ++cycleInd;
199  }
201 }
202 
204 {
206  HLSMgr->Rfuns = functionsRef(new OmpFunctions(HLSMgr));
207 }
#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;.
boost::graph_traits< graph >::out_edge_iterator OutEdgeIterator
out_edge_iterator definition.
Definition: graph.hpp:1312
virtual void Initialize()
Initialize the step (i.e., like a constructor, but executed just before exec.
File containing functions and utilities to support the printing of debug messagges.
void Initialize() override
Initialize the step (i.e., like a constructor, but executed just before exec.
string target
Definition: lenet_tvm.py:16
#define GET_CLASS(obj)
Macro returning the actual type of an object.
boost::graph_traits< graph >::in_edge_iterator InEdgeIterator
in_edge_iterator definition.
Definition: graph.hpp:1310
~OmpFunctionAllocationCS() override
Destructor.
refcount< functions > functionsRef
refcount definition of the class
Definition: functions.hpp:159
DesignFlowStep_Status Exec() override
Execute the step.
DesignFlowStep_Status Exec() override
Execute the step.
HLSFlowStep_Type
Definition: hls_step.hpp:95
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
This file collects some utility functions and macros.
Call graph hierarchy.
OmpFunctionAllocationCS(const ParameterConstRef _parameters, const HLS_managerRef HLSMgr, const DesignFlowManagerConstRef design_flow_manager)
Constructor.
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.
int debug_level
The debug level.
Datastructure to describe functions allocation in high-level synthesis.
Class specification of the manager of the tree structures extracted from the raw file.
A brief description of the C++ Header File.

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