Skip to content

Commit 91f7b97

Browse files
committed
Update multi-file generation option
Added --generate-components-library command line option to enable the generation of a library for standard Bambu RTL components separated from the generated top function RTL description
1 parent 1a92ea5 commit 91f7b97

File tree

9 files changed

+71
-111
lines changed

9 files changed

+71
-111
lines changed

src/BambuParameter.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@
226226
#define OPT_SHARED_INPUT_REGISTERS (1 + OPT_NANOXPLORE_BYPASS)
227227
#define OPT_INLINE_FUNCTIONS (1 + OPT_SHARED_INPUT_REGISTERS)
228228
#define OPT_AXI_BURST_TYPE (1 + OPT_INLINE_FUNCTIONS)
229+
#define OPT_GENERATE_COMPONENTS_LIBRARY (1 + OPT_AXI_BURST_TYPE)
229230

230231
/// constant correspond to the "parametric list based option"
231232
#define PAR_LIST_BASED_OPT "parametric-list-based"
@@ -876,6 +877,8 @@ void BambuParameter::PrintHelp(std::ostream& os) const
876877
<< std::endl;
877878
// options defining where backend tools could be found
878879
os << " Backend configuration:\n\n"
880+
<< " --generate-components-library\n"
881+
<< " Export standard Bambu RTL components as a separate library"
879882
<< " --mentor-visualizer\n"
880883
<< " Simulate the RTL implementation and then open Mentor Visualizer.\n"
881884
<< " (Mentor root has to be correctly set, see --mentor-root)\n\n"
@@ -1095,6 +1098,7 @@ int BambuParameter::Exec()
10951098
{"verilator-parallel", optional_argument, nullptr, OPT_VERILATOR_PARALLEL},
10961099
{"shared-input-registers", no_argument, nullptr, OPT_SHARED_INPUT_REGISTERS},
10971100
{"inline-fname", required_argument, nullptr, OPT_INLINE_FUNCTIONS},
1101+
{"generate-components-library", no_argument, nullptr, OPT_GENERATE_COMPONENTS_LIBRARY},
10981102
GCC_LONG_OPTIONS,
10991103
{nullptr, 0, nullptr, 0}
11001104
};
@@ -2124,6 +2128,11 @@ int BambuParameter::Exec()
21242128
setOption(OPT_inline_functions, std::string(optarg));
21252129
break;
21262130
}
2131+
case OPT_GENERATE_COMPONENTS_LIBRARY:
2132+
{
2133+
setOption(OPT_generate_components_library, true);
2134+
break;
2135+
}
21272136
case 0:
21282137
{
21292138
if(strcmp(long_options[option_index].name, "module-binding") == 0)
@@ -3736,6 +3745,7 @@ void BambuParameter::SetDefaults()
37363745
setOption(OPT_evaluation_mode, Evaluation_Mode::NONE);
37373746
setOption(OPT_evaluation_objectives, "");
37383747

3748+
setOption(OPT_generate_components_library, false);
37393749
setOption(OPT_altera_root, "/opt/altera" STR_CST_string_separator "/opt/intelFPGA");
37403750
setOption(OPT_lattice_root, "/opt/diamond" STR_CST_string_separator "/usr/local/diamond");
37413751
setOption(OPT_mentor_root, "/opt/mentor");

src/HLS/backend/generate_hdl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ DesignFlowStep_Status generate_hdl::Exec()
116116
top_circuits.push_back(HLSMgr->get_HLS(top_fnode->index)->top->get_circ());
117117
}
118118

119-
HM.hdl_gen(file_name, top_circuits, HLSMgr->hdl_files, HLSMgr->aux_files, false);
119+
const auto generate_bambu_lib = parameters->getOption<bool>(OPT_generate_components_library);
120+
HM.hdl_gen(file_name, top_circuits, HLSMgr->hdl_files, HLSMgr->aux_files, !generate_bambu_lib);
120121
return DesignFlowStep_Status::SUCCESS;
121122
}

src/Parameter.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class xml_element;
102102
mentor_root)(mentor_modelsim_bin)(mentor_optimizer)(verilator)(verilator_timescale_override)( \
103103
verilator_parallel)(altera_root)(quartus_settings)(quartus_13_settings)(quartus_13_64bit)(nanoxplore_root)( \
104104
nanoxplore_settings)(nanoxplore_bypass)(shared_input_registers)(inline_functions)(function_constraints)( \
105-
resource_constraints)(axi_burst_type)
105+
resource_constraints)(axi_burst_type)(generate_components_library)
106106

107107
#define FRAMEWORK_OPTIONS \
108108
(benchmark_name)(cat_args)(find_max_transformations)(max_transformations)(compatible_compilers)(compute_size_of)( \

src/design_flows/backend/ToHDL/HDL_manager.cpp

Lines changed: 50 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "fileIO.hpp"
5555
#include "generic_device.hpp"
5656
#include "hls_manager.hpp"
57+
#include "library_manager.hpp"
5758
#include "string_manipulation.hpp"
5859
#include "structural_manager.hpp"
5960
#include "structural_objects.hpp"
@@ -218,10 +219,9 @@ std::string HDL_manager::write_components(const std::string& filename, HDLWriter
218219
}
219220

220221
void HDL_manager::write_components(const std::string& filename, const std::list<structural_objectRef>& components,
221-
std::list<std::string>& hdl_files, std::list<std::string>& aux_files, bool tb)
222+
std::list<std::string>& hdl_files, std::list<std::string>& aux_files,
223+
bool unique_out)
222224
{
223-
bool multiFileP =
224-
!tb && parameters->IsParameter("enable-multifiles") && parameters->GetParameter<bool>("enable-multifiles");
225225
/// default language
226226
auto language = parameters->getOption<HDLWriter_Language>(OPT_writer_language);
227227

@@ -246,122 +246,81 @@ void HDL_manager::write_components(const std::string& filename, const std::list<
246246
}
247247

248248
/// determine the proper language for each component
249-
std::map<HDLWriter_Language, std::list<structural_objectRef>> component_language;
249+
std::map<HDLWriter_Language, std::list<structural_objectRef>> hdl_comp, aux_comp;
250250
for(const auto& component : components)
251251
{
252-
auto* mod = GetPointer<module>(component);
252+
const auto mod = GetPointer<module>(component);
253253
THROW_ASSERT(mod, "Expected a component object");
254+
const auto n_elements = mod->get_internal_objects_size();
255+
const auto np = mod->get_NP_functionality();
254256

255-
unsigned int n_elements = mod->get_internal_objects_size();
256-
257-
const NP_functionalityRef np = mod->get_NP_functionality();
258-
259-
if(n_elements || (np && (np->exist_NP_functionality(type) ||
260-
(language == HDLWriter_Language::VERILOG &&
261-
np->exist_NP_functionality(NP_functionality::VERILOG_FILE_PROVIDED)) ||
262-
(language == HDLWriter_Language::VHDL &&
263-
np->exist_NP_functionality(NP_functionality::VHDL_PROVIDED)))))
264-
{
265-
component_language[language].push_back(component);
266-
}
267-
else
257+
HDLWriter_Language comp_language = language;
258+
if(!n_elements && np)
268259
{
269-
if(np and
270-
(np->exist_NP_functionality(NP_functionality::FSM) or np->exist_NP_functionality(NP_functionality::FSM_CS)))
260+
const auto has_verilog = np->exist_NP_functionality(NP_functionality::VERILOG_PROVIDED) ||
261+
np->exist_NP_functionality(NP_functionality::VERILOG_FILE_PROVIDED);
262+
const auto has_vhdl = np->exist_NP_functionality(NP_functionality::VHDL_PROVIDED) ||
263+
np->exist_NP_functionality(NP_functionality::FLOPOCO_PROVIDED) ||
264+
np->exist_NP_functionality(NP_functionality::VHDL_FILE_PROVIDED);
265+
if(np->exist_NP_functionality(type) || (language == HDLWriter_Language::VERILOG && has_verilog) ||
266+
(language == HDLWriter_Language::VHDL && has_vhdl) || np->exist_NP_functionality(NP_functionality::FSM) ||
267+
np->exist_NP_functionality(NP_functionality::FSM_CS))
271268
{
272-
component_language[language].push_back(component);
269+
comp_language = language;
273270
}
274-
else if(np && (np->exist_NP_functionality(NP_functionality::VERILOG_PROVIDED) ||
275-
np->exist_NP_functionality(NP_functionality::VERILOG_FILE_PROVIDED)))
271+
else if(has_verilog)
276272
{
277-
if(!parameters->getOption<bool>(OPT_mixed_design))
278-
{
279-
THROW_ERROR("VHDL implementation of " + component->get_path() + " is not available");
280-
}
281-
component_language[HDLWriter_Language::VERILOG].push_back(component);
273+
comp_language = HDLWriter_Language::VERILOG;
282274
}
283-
else if(np && (np->exist_NP_functionality(NP_functionality::VHDL_PROVIDED) ||
284-
np->exist_NP_functionality(NP_functionality::FLOPOCO_PROVIDED) ||
285-
np->exist_NP_functionality(NP_functionality::VHDL_FILE_PROVIDED)))
275+
else if(has_vhdl)
286276
{
287-
if(!parameters->getOption<bool>(OPT_mixed_design))
288-
{
289-
THROW_ERROR("Verilog implementation of " + component->get_path() + " is not available");
290-
}
291-
else
292-
{
293-
THROW_WARNING(component->get_path() + " is available only in VHDL");
294-
}
295-
component_language[HDLWriter_Language::VHDL].push_back(component);
277+
comp_language = HDLWriter_Language::VHDL;
296278
}
297-
else if(np && np->exist_NP_functionality(NP_functionality::SYSTEM_VERILOG_PROVIDED))
279+
else if(np->exist_NP_functionality(NP_functionality::SYSTEM_VERILOG_PROVIDED))
298280
{
299-
component_language[HDLWriter_Language::SYSTEM_VERILOG].push_back(component);
281+
comp_language = HDLWriter_Language::SYSTEM_VERILOG;
300282
}
301283
else
302284
{
303285
THROW_ERROR("Language not supported! Module " + mod->get_path());
304286
}
305287
}
306-
}
307-
308-
/// generate the auxiliary files
309-
for(auto l = component_language.begin(); l != component_language.end(); ++l)
310-
{
311-
if(language == l->first)
288+
const auto library = TM->get_library(component->get_typeRef()->id_type);
289+
if(unique_out || library.empty() || !starts_with(library, "STD"))
312290
{
313-
continue;
314-
}
315-
if(multiFileP)
316-
{
317-
language_writerRef writer = language_writer::create_writer(l->first, TM, parameters);
318-
for(const auto& c : component_language[l->first])
319-
{
320-
std::list<structural_objectRef> singletonList;
321-
singletonList.push_back(c);
322-
std::string mod_name = convert_to_identifier(writer.get(), GET_TYPE_NAME(c));
323-
std::string generated_filename = write_components(mod_name, l->first, singletonList, aux_files);
324-
aux_files.push_back(generated_filename);
325-
}
291+
hdl_comp[comp_language].push_back(component);
326292
}
327293
else
328294
{
329-
std::string generated_filename = write_components(filename, l->first, component_language[l->first], aux_files);
330-
aux_files.push_back(generated_filename);
295+
aux_comp[comp_language].push_back(component);
331296
}
332297
}
333298

334-
if(multiFileP)
299+
for(auto& [lang, comps] : aux_comp)
335300
{
336-
language_writerRef writer = language_writer::create_writer(language, TM, parameters);
337-
338-
auto counter = component_language[language].size();
339-
for(const auto& c : component_language[language])
301+
auto writer = language_writer::create_writer(lang, TM, parameters);
302+
auto lib_dir = "bambu_lib/" + writer->get_name() + "/";
303+
std::filesystem::create_directories(lib_dir);
304+
for(auto& comp : comps)
340305
{
341-
--counter;
342-
std::list<structural_objectRef> singletonList;
343-
singletonList.push_back(c);
344-
std::string mod_name = convert_to_identifier(writer.get(), GET_TYPE_NAME(c));
345-
if(counter == 0)
346-
{
347-
mod_name = filename;
348-
}
349-
std::string generated_filename = write_components(mod_name, language, singletonList, aux_files);
350-
if(counter == 0)
351-
{
352-
hdl_files.push_back(generated_filename);
353-
}
354-
else
355-
{
356-
aux_files.push_back(generated_filename);
357-
}
306+
auto mod_name = lib_dir + convert_to_identifier(writer.get(), GET_TYPE_NAME(comp));
307+
auto generated_filename = write_components(mod_name, lang, {comp}, aux_files);
308+
aux_files.push_back(generated_filename);
358309
}
359310
}
360-
else
311+
312+
for(auto& [lang, comps] : hdl_comp)
361313
{
362-
std::string complete_filename = write_components(filename, language, component_language[language], aux_files);
363-
/// add the generated file to the global list
364-
hdl_files.push_back(complete_filename);
314+
auto writer = language_writer::create_writer(lang, TM, parameters);
315+
auto generated_filename = write_components(filename, lang, comps, aux_files);
316+
if(lang == language)
317+
{
318+
hdl_files.push_back(generated_filename);
319+
}
320+
else
321+
{
322+
aux_files.push_back(generated_filename);
323+
}
365324
}
366325

367326
#if HAVE_FLOPOCO
@@ -375,7 +334,7 @@ void HDL_manager::write_components(const std::string& filename, const std::list<
375334
}
376335

377336
void HDL_manager::hdl_gen(const std::string& filename, const std::list<structural_objectRef>& cirs,
378-
std::list<std::string>& hdl_files, std::list<std::string>& aux_files, bool tb)
337+
std::list<std::string>& hdl_files, std::list<std::string>& aux_files, bool unique_out)
379338
{
380339
PRINT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level,
381340
" compute the list of components for which a structural description exists");
@@ -398,7 +357,7 @@ void HDL_manager::hdl_gen(const std::string& filename, const std::list<structura
398357
}
399358

400359
/// generate the HDL descriptions for all the components
401-
write_components(filename, list_of_com, hdl_files, aux_files, tb);
360+
write_components(filename, list_of_com, hdl_files, aux_files, unique_out);
402361
}
403362

404363
/**

src/design_flows/backend/ToHDL/HDL_manager.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class HDL_manager
122122
* Determines the proper language for each component and generates the corresponding HDL descriptions
123123
*/
124124
void write_components(const std::string& filename, const std::list<structural_objectRef>& components,
125-
std::list<std::string>& hdl_files, std::list<std::string>& aux_files, bool tb);
125+
std::list<std::string>& hdl_files, std::list<std::string>& aux_files, bool unique_out);
126126

127127
/**
128128
* Writes the module description.
@@ -201,9 +201,10 @@ class HDL_manager
201201
* @param cirs are the structural objects representing the components to be generated
202202
* @param the created files (file_name + other files)
203203
* @param the created aux files
204+
* @param single_file generate a unique output file with all components
204205
*/
205206
void hdl_gen(const std::string& filename, const std::list<structural_objectRef>& cirs,
206-
std::list<std::string>& hdl_files, std::list<std::string>& aux_files, bool tb);
207+
std::list<std::string>& hdl_files, std::list<std::string>& aux_files, bool unique_out = false);
207208

208209
/**
209210
* Converts a generic string to a language compliant identifier

src/technology/RTL_characterization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ void RTLCharacterization::AnalyzeCell(functional_unit* fu, const unsigned int pr
11601160
std::list<std::string> hdl_files, aux_files;
11611161
std::list<structural_objectRef> circuits;
11621162
circuits.push_back(circuit);
1163-
HDL->hdl_gen(fu_name, circuits, hdl_files, aux_files, false);
1163+
HDL->hdl_gen(fu_name, circuits, hdl_files, aux_files);
11641164
int PipelineDepth = -1;
11651165
#if HAVE_FLOPOCO
11661166
if(n_pipe_parameters > 0 && NPF && NPF->exist_NP_functionality(NP_functionality::FLOPOCO_PROVIDED) &&

src/technology/parse_technology.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void read_technology_File(const std::string& fn, const technology_managerRef& TM
7171
}
7272
for(const auto& library : TM->get_library_list())
7373
{
74-
if(WORK_LIBRARY == library || DESIGN == library || PROXY_LIBRARY == library)
74+
if(WORK_LIBRARY == library || PROXY_LIBRARY == library)
7575
{
7676
continue;
7777
}

src/technology/technology_manager.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,7 @@ void technology_manager::add(const technology_nodeRef curr, const std::string& L
201201
auto it = std::find(libraries.begin(), libraries.end(), Library);
202202
if(it == libraries.end())
203203
{
204-
bool std = true;
205-
if(Library == CG_LIBRARY || Library == DESIGN)
206-
{
207-
std = false;
208-
}
209-
library_managerRef lib(new library_manager(Library, Param, std));
204+
library_managerRef lib(new library_manager(Library, Param, true));
210205
library_map[Library] = lib;
211206
libraries.push_back(Library);
212207
}

src/technology/technology_manager.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@
4141
*/
4242
#ifndef TECHNOLOGY_MANAGER_HPP
4343
#define TECHNOLOGY_MANAGER_HPP
44-
45-
/// Autoheader include
46-
#include "config_HAVE_CIRCUIT_BUILT.hpp"
47-
4844
#include "custom_map.hpp"
4945
#include "custom_set.hpp"
5046
#include "refcount.hpp"
@@ -54,8 +50,8 @@
5450
#include <string>
5551
#include <vector>
5652

57-
/// working library.
58-
#define DESIGN std::string("design")
53+
#include "config_HAVE_CIRCUIT_BUILT.hpp"
54+
5955
/// working library.
6056
#define WORK_LIBRARY std::string("work")
6157
/// OpenMP library
@@ -68,8 +64,6 @@
6864
#define LIBRARY_STD std::string("STD")
6965
/// standard library where all standard HLS resources are defined
7066
#define LIBRARY_STD_FU std::string("STD_FU")
71-
/// compound gates
72-
#define CG_LIBRARY std::string("CG")
7367
/// standard library for parallel controller
7468
#define LIBRARY_PC std::string("STD_PC")
7569
/// standard library for dataflow interface modules

0 commit comments

Comments
 (0)