67 void DECODE_FU_LIB(std::string& fu_name, std::string& fu_library,
const std::string& combined)
69 std::vector<std::string> splitted =
SplitString(combined,
":");
70 fu_name = splitted[0];
71 fu_library = splitted[1];
75 : clock_period(_Param->getOption<double>(OPT_clock_period)),
76 clock_period_resource_fraction(_Param->getOption<double>(OPT_clock_period_resource_fraction)),
78 fun_name(
std::move(_fun_name)),
84 auto debug_level =
parameters->getOption<
unsigned int>(OPT_debug_level);
85 if(
parameters->isOption(OPT_xml_input_configuration))
88 auto fn =
parameters->getOption<std::string>(OPT_xml_input_configuration);
98 for(
auto& iter : list)
100 auto* Enode = GetPointer<xml_element>(iter);
105 std::string function_name;
108 if(
CE_XVM(function_name, Enode))
114 constraint_node = Enode;
119 if(!
CE_XVM(function_name, Enode))
121 constraint_node = Enode;
128 xload(constraint_node);
131 catch(
const char* msg)
133 THROW_ERROR(
"Error during constraints file parsing: " + std::string(msg));
135 catch(
const std::string& msg)
137 THROW_ERROR(
"Error during constraints file parsing: " + msg);
139 catch(
const std::exception& ex)
141 THROW_ERROR(
"Error during constraints file parsing: " + std::string(ex.what()));
145 THROW_ERROR(
"Error during constraints file parsing");
148 " ==== XML configuration file parsed for constraints information ====");
161 if(
parameters->isOption(OPT_constraints_file))
173 if(
parameters->isOption(OPT_clock_period_resource_fraction))
213 const std::string& fu_library,
const unsigned int fu_index)
215 binding_constraints[vertex_name] = std::make_pair(fu_name, std::make_pair(fu_library, fu_index));
242 void HLS_constraints::check_HLS_constraints(
const behavioral_managerRef & GM,
const technology_managerRef & TM)
const 248 const graph * cfg = GM->CGetOpGraph(behavioral_manager::CFG);
249 HLS_constraints_functor<base_constraints_functor> CF(*
this);
251 for (boost::tie(v, v_end) = boost::vertices(*cfg); v != v_end; v++)
253 (void) TM->get_attribute_of_fu_per_op(GET_OP(cfg, *v),
technology_manager::min, technology_manager::execution_time, fu_name, flag);
255 THROW_ERROR(std::string(
"Does not exist a functional unit for operation ") + GET_OP(cfg, *v));
256 fu_max_power = TM->get_attribute_of_fu_per_op(GET_OP(cfg, *v),
technology_manager::max, technology_manager::power_consumption, fu_name, flag);
257 if (max_power_per_cycle < fu_max_power)
258 THROW_ERROR(std::string(
"Functional units consumption is too high ") + GET_OP(cfg, *v));
259 if (!TM->check_technology_constraint(GET_OP(cfg, *v), CF))
260 THROW_ERROR(std::string(
"Does not exist enough functional unit for operation \"") + GET_OP(cfg, *v) + std::string(
"\". Check the number of resources that can implement that operation"));
273 os <<
"- Registers: " <<
registers <<
"\n";
277 os <<
"- Resource constraints:\n";
281 os << i->first <<
" " << i->second << std::endl;
286 os <<
"- Binding constraints:\n";
290 os << i->first <<
" " << i->second.first <<
" " << i->second.second.first <<
" " << i->second.second.second
296 os <<
"- Scheduling constraints:\n";
300 os << i->first <<
" " << i->second << std::endl;
309 for(
const auto& iter : list)
311 const auto* EnodeC = GetPointer<const xml_element>(iter);
316 if(EnodeC->get_name() ==
"tech_constraints")
322 THROW_ASSERT(!fu_name.empty(),
"bad formed xml file: fu_name expected in a tech_constraints");
323 if(
CE_XVM(fu_library, EnodeC))
330 else if(EnodeC->get_name() ==
"binding_constraints")
332 std::string vertex_name;
335 unsigned int fu_index = 0;
337 THROW_ASSERT(!vertex_name.empty(),
"bad formed xml file: vertex_name expected in a binding_constraints");
339 THROW_ASSERT(!fu_name.empty(),
"bad formed xml file: fu_name expected in a binding_constraints");
340 if(
CE_XVM(fu_library, EnodeC))
345 binding_constraints[vertex_name] = std::make_pair(fu_name, std::make_pair(fu_library, fu_index));
347 else if(EnodeC->get_name() ==
"scheduling_constraints")
349 std::string vertex_name;
352 THROW_ASSERT(!vertex_name.empty(),
"bad formed xml file: vertex_name expected in a scheduling_constraints");
368 unsigned int n,
bool forDump)
393 const std::string& fu_name,
const std::string& fu_library,
394 unsigned int fu_index)
420 std::string fu_library;
421 unsigned int n = i->second;
429 std::string vertex_name = bi->first;
430 std::string fu_name = bi->second.first;
431 std::string fu_library = bi->second.second.first;
432 unsigned int fu_index = bi->second.second.second;
439 std::string vertex_name = sch->first;
440 int priority = sch->second;
459 const char* builtin_constraints_data = {
460 #include "constraints_STD.data" 462 const char* builtin_constraints_data_ALUs = {
463 #include "constraints_STD_ALUs.data" 467 XMLDomParser parser_noALUs(
"builtin_constraints_data", builtin_constraints_data);
468 XMLDomParser parser_ALUs(
"builtin_constraints_data_ALUs", builtin_constraints_data_ALUs);
470 parameters->isOption(OPT_use_ALUs) &&
parameters->getOption<
bool>(OPT_use_ALUs) ? parser_ALUs : parser_noALUs;
479 for(
const auto& iter : list)
481 const auto* Enode = GetPointer<const xml_element>(iter);
490 catch(
const char* msg)
492 std::cerr << msg << std::endl;
493 THROW_ERROR(
"Error during parsing of constraint file");
495 catch(
const std::string& msg)
497 std::cerr << msg << std::endl;
498 THROW_ERROR(
"Error during parsing of constraint file");
500 catch(
const std::exception& ex)
502 std::cout <<
"Exception caught: " << ex.what() << std::endl;
503 THROW_ERROR(
"Error during parsing of constraint file");
507 std::cerr <<
"unknown exception" << std::endl;
508 THROW_ERROR(
"Error during parsing of constraint file");
525 for(
const auto& iter : list)
527 const auto* Enode = GetPointer<const xml_element>(iter);
536 catch(
const char* msg)
538 std::cerr << msg << std::endl;
540 catch(
const std::string& msg)
542 std::cerr << msg << std::endl;
544 catch(
const std::exception& ex)
546 std::cout <<
"Exception caught: " << ex.what() << std::endl;
550 std::cerr <<
"unknown exception" << std::endl;
563 catch(
const char* msg)
565 std::cerr << msg << std::endl;
567 catch(
const std::string& msg)
569 std::cerr << msg << std::endl;
571 catch(
const std::exception& ex)
573 std::cout <<
"Exception caught: " << ex.what() << std::endl;
577 std::cerr <<
"unknown exception" << std::endl;
void DECODE_FU_LIB(std::string &fu_name, std::string &fu_library, const std::string &combined)
function used to extract the functional unit name and its library from a string.
unsigned int registers
Variable storing the number of registers.
std::string get_kind_text() const
definition of the get_kind_text method
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;.
bool has_binding_to_fu(const std::string &vertex_name) const
Binds a vertex to a functional unit.
#define DEBUG_LEVEL_PEDANTIC
very verbose debugging print is performed.
void read_HLS_constraints_File(const std::string &f)
Reads an XML file describing the structural data structures.
const std::vector< std::string > SplitString(const std::string &input, const std::string &separators)
Function which splits a string into tokens.
std::string get_function_name() const
Gets the name of the function which the constraints are associated with.
void set_max_registers(unsigned int n_resources)
Sets the number of registers present in the function.
void set_clock_period(double period)
Sets the clock period.
CustomOrderedMap< T, U > CustomMap
exceptions managed by PandA
#define CE_XVM(variable, node)
Check existence XML Value Macro. Check if an XML attribute is present in the XML tree.
Definition of hash function for EdgeDescriptor.
void set_scheduling_priority(const std::string &vertex_name, int Priority)
Stores the priority value for an operation vertex.
void xload(const xml_element *Enode)
Loads a set of HLS constraints starting from an XML node.
Class specification of the manager of the technology library data structures.
void xwriteBindingConstraints(xml_element *Enode, const std::string &vertex_name, const std::string &fu_name, const std::string &fu_library, unsigned int fu_index)
Writes the binding constraints (i.e., functional unit, instance and library) associated with an opera...
redefinition of map to manage ordered/unordered structures
unsigned int get_number_fu(const std::string &name, const std::string &library) const
This method returns the maximum number of functional units available for the design.
Auxiliary methods for manipulating string.
void xwriteFUConstraints(xml_element *Enode, const std::string &fu_name, const std::string &fu_library, unsigned int number_fu, bool forDump=false)
Writes the constraints on the functional units.
void set_number_fu(const std::string &name, const std::string &library, unsigned int n_resources=std::numeric_limits< unsigned int >::max())
Sets the maximum number of resources available in the design.
CustomMap< std::string, std::pair< std::string, std::pair< std::string, unsigned int > > > binding_constraints
put into relation the vertex name with the functional unit, its library and the functional unit index...
void write_to_file_formatted(const std::filesystem::path &filename)
Write the document to a file.
#define LIBRARY_STD
standard library where all built-in ports are defined.
xml_element * create_root_node(const std::string &_name)
Creates the root node.
void print(std::ostream &os) const
Function that prints the class HLS_constraints.
Data structure used to store all the HLS constraints.
utility function used to read files.
void xwrite(xml_element *rootnode)
Writes the HLS constraints into an XML tree.
General class used to describe a graph in PandA.
boost::graph_traits< graph >::vertex_iterator VertexIterator
vertex_iterator definition.
This file collects some utility functions and macros.
#define GET_CLASS_NAME(meth)
Macro returning the name of a class.
void Exec()
Parse an XML document from a file.
std::list< xml_nodeRef > node_list
type for list of xml nodes
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
Data structure definition for HLS constraints.
CustomMap< std::string, int > get_scheduling_priority() const
Returns the data structure containing scheduling priority constraints.
std::string GetPath(std::filesystem::path path)
void write_HLS_constraints_File(const std::string &f)
Writes an XML file describing the high level synthesis constraints data structure.
#define WRITE_XVM(variable, node)
WRITE XML Value Macro. Insert a value in an XML tree.
#define INFINITE_UINT
UNSIGNED INT representing infinite.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
xml_documentRef get_document()
Obtain the parsed document.
void xwriteSchedulingConstraints(xml_element *Enode, const std::string &vertex_name, int priority)
Writes the scheduling constraints (i.e., priority value) associated with an operation.
void bind_vertex_to_fu(const std::string &vertex_name, const std::string &fu_name, const std::string &fu_library, const unsigned int fu_index)
Binds a vertex to a functional unit.
this class is used to manage the command-line or XML options.
#define LOAD_XVM(variable, node)
LOAD XML Value Macro. Set a variable starting from an XML value. Conversion is performed if needed...
Some macro used to interface with the XML library.
node_list const & get_children()
Obtain the list of child nodes.
CustomMap< std::string, unsigned int > tech_constraints
For each functional unit tech_constraints stores the number of resources.
const ParameterConstRef parameters
The set of input parameters.
CustomMap< std::string, int > scheduling_constraints
map between an operation vertex and its given scheduling priority value
double clock_period_resource_fraction
current value of the resource fraction
std::string fun_name
name of the function which the constraints are associated with; emtpy string means that they are glob...
#define DEBUG_LEVEL_VERBOSE
verbose debugging print is performed.
#define ENCODE_FU_LIB(fu_name, library)
macro used to convert the functional unit name and the library in an unique string.
xml_element * add_child_element(const std::string &name)
Add a child element to this node.
HLS_constraints(const ParameterConstRef &Param, std::string _fun_name)
Constructor.
void add_builtin_constraints()
Adds the builtin constraints.
#define DEBUG_LEVEL_MINIMUM
minimum debugging print is performed.
double clock_period
Clock period in ns.
void xwriteHLSConstraints(xml_element *Enode, bool forDump=false)
Writes the generic synthesis constraints.
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...