hls4ml.writer package
Submodules
hls4ml.writer.catapult_writer module
- class hls4ml.writer.catapult_writer.CatapultWriter
Bases:
Writer- print_array_to_cpp(var, odir, write_txt_file=True)
Write a weights array to C++ header files.
- Parameters:
var (WeightVariable) – Weight to write
odir (str) – Output directory
write_txt_file (bool, optional) – Write txt files in addition to .h files. Defaults to True.
- write_bridge(model)
Write the Python-C++ bridge (myproject_bridge.cpp)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_build_script(model)
Write the TCL/Shell build scripts (build_prj.tcl, build_lib.sh)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_defines(model)
Write the C++ type definitions file (defines.h)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_generated_code(model)
Write the generated code (nnet_code_gen.h)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_hls(model)
- write_nnet_utils(model)
Copy the nnet_utils, AP types headers and any custom source to the project output directory
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_output_dir(model)
Write the base output directory
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_parameters(model)
Write the C++ layer config file (parameters.h)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_project_cpp(model)
Write the main architecture source file (myproject.cpp)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_project_header(model)
Write the main architecture header file (myproject.h)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_tar(model)
Write the generated project as a .tar.gz archive
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_test_bench(model)
Write the testbench files (myproject_test.cpp and input/output .dat files)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_weights(model)
Write the weights into header files
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_yml(model)
Write the config to the YAML file
- Parameters:
model (ModelGraph) – the hls4ml model.
hls4ml.writer.coyote_writer module
- class hls4ml.writer.coyote_writer.CoyoteWriter
Bases:
VitisWriter- restructure_dir(model)
Simply moves around some files; these files were generated from the Vitis backend For a cleaner integration with the rest of the Coyote library, these are moved to the src/ folder
- Parameters:
model (ModelGraph) – the hls4ml model
- write_build_script(model)
- Generate the following build scripts:
build_lib.sh — used for software emulation (with gcc) of the model
CMakeLists.txt — for synthesizing the hardware with Coyote and the corresponding software library
- Parameters:
model (ModelGraph) – the hls4ml model
- write_coyote(model)
Copies the Coyote repository to the project folder
- Parameters:
model (ModelGraph) – the hls4ml model
- write_hls(model)
Write the HLS project. Most of the functionality inherited from VitisWriter; some additional functionality added for Coyote specifically.
- Parameters:
model (ModelGraph) – the hls4ml model
- write_host_code(model)
Generates the host code, namely myproject_host.cpp and host_libs.hpp host_libs.hpp implements the “glue” logic which interacts with the Coyote software library. myproject_host.cpp is a stand-alone program that can be compiled and used to run model inference on an FPGA, with inputs from tb_data.
- Parameters:
model (ModelGraph) – the hls4ml model
- write_model_wrapper(model)
Generate the model_wrapper and vfpga_top
model_wrapper encapsulates the hls4ml model kernel as well as AXI-to-data and data-to-AXI converters. More details on the model_wrapper and these converters can be found in model_wrapper.hpp.
vfpga_top.svh is a simple SystemVerilog header that is needed to synthesize any Coyote project; see vfpga_top.svh and the Coyote examples for more details
- Parameters:
model (ModelGraph) – the hls4ml model
- write_nnet_utils_overrides(model)
Writes the HLS templates, both from Vitis and from Coyote
- Parameters:
model (ModelGraph) – the hls4ml model
- write_project_cpp(model)
Write the main architecture source file (myproject.cpp) Very similar to VivadoWriter, but with a different generation for I/O. Since the myproject.cpp is no longer the top-level file (but model_wrapper is), no need to specify interfaces. Additionally, inlining can cause issues here when integrated with the model_wrapper, so it’s disabled.
- Parameters:
model (ModelGraph) – the hls4ml model
- write_test_bench(model)
Generates the HLS testbench; very similar to the testbench in Vivado/Vitis backends For differences, refer to the myproject_test.cpp file.
- Parameters:
model (ModelGraph) – the hls4ml model
hls4ml.writer.libero_writer module
- class hls4ml.writer.libero_writer.LiberoWriter
Bases:
Writer- print_array_to_cpp(var, odir, namespace=None, write_txt_file=True)
Write a weights array to C++ header files.
- Parameters:
var (WeightVariable) – Weight to write
odir (str) – Output directory
namespace (str, optional) – Writes a namespace for the weights to avoid clashes with global variables.
write_txt_file (bool, optional) – Write txt files in addition to .h files. Defaults to True.
- write_bridge(model)
Write the Python-C++ bridge (myproject_bridge.cpp)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_build_script(model)
Write the TCL/Shell build scripts (config.tcl, Makefile, build_lib.sh)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_defines(model)
Write the C++ type definitions file (defines.h)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_generated_code(model)
Write the generated code (nnet_code_gen.h)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_hls(model)
- write_nnet_utils(model)
Copy the nnet_utils, AP types headers and any custom source to the project output directory
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_parameters(model)
Write the C++ layer config file (parameters.h)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_project_cpp(model)
Write the main architecture source file (myproject.cpp)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_project_dir(model)
Write the base project directory
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_project_header(model)
Write the main architecture header file (myproject.h)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_tar(model)
Write the generated project as a .tar.gz archive
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_test_bench(model)
Write the testbench files (myproject_test.cpp and input/output .dat files)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_weights(model)
Write the weights into header files
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_yml(model)
Write the config to the YAML file
- Parameters:
model (ModelGraph) – the hls4ml model.
hls4ml.writer.oneapi_writer module
- class hls4ml.writer.oneapi_writer.OneAPIWriter
Bases:
Writer- get_max_reuse_factor(model)
- print_array_to_cpp(var, layer, odir)
Write a weights array to C++ header files.
- Parameters:
var (WeightVariable) – Weight to write
layer (Layer) – Instance of the layer to which the weights belong
odir (str) – Output directory
- write_activation_tables(model)
Write the lookup tables for activation functions
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_bridge(model)
Write the Python-C++ bridge (myproject_bridge.cpp)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_build_script(model)
Write the build scripts (Makefile, build_lib.sh)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_defines(model)
Write the C++ type definitions file (defines.h)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_generated_code(model)
Write the generated code (nnet_code_gen.h)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_hls(model)
- write_nnet_utils(model)
Copy the nnet_utils, AP types headers and any custom source to the project output directory
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_parameters(model)
Write the C++ layer config file (parameters.h)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_project_cpp(model)
Write the main architecture source file (myproject.cpp)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_project_dir(model)
Write the base project directory
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_project_header(model)
Write the main architecture header file (myproject.h)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_tar(model)
Write the generated project as a .tar.gz archive
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_test_bench(model)
Write the testbench
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_weights(model)
Write the weights into header files
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_yml(model)
Write the config to the YAML file
- Parameters:
model (ModelGraph) – the hls4ml model.
hls4ml.writer.quartus_writer module
- class hls4ml.writer.quartus_writer.QuartusWriter
Bases:
Writer- get_max_reuse_factor(model)
- next_pow2(x)
- print_array_to_cpp(var, layer, odir)
Write a weights array to C++ header files.
- Parameters:
var (WeightVariable) – Weight to write
layer (Layer) – Instance of the layer to which the weights belong
odir (str) – Output directory
- write_activation_tables(model)
Write the lookup tables for activation functions
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_bridge(model)
Write the Python-C++ bridge (myproject_bridge.cpp)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_build_script(model)
Write the build scripts (Makefile, build_lib.sh)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_defines(model)
Write the C++ type definitions file (defines.h)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_hls(model)
- write_nnet_utils(model)
Copy the nnet_utils, AP types headers and any custom source to the project output directory
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_parameters(model)
Write the C++ layer config file (parameters.h)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_project_cpp(model)
Write the main architecture source file (myproject.cpp)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_project_dir(model)
Write the base project directory
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_project_header(model)
Write the main architecture header file (myproject.h)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_tar(model)
Write the generated project as a .tar.gz archive
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_test_bench(model)
Write the testbench
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_testbench_parallel(model)
Write the testbench file for io_parallel (myproject_test.cpp and input/output .dat files)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_testbench_stream(model)
Write the testbench file for io_stream (myproject_test.cpp and input/output .dat files)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_weights(model)
Write the weights into header files
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_yml(model)
Write the config to the YAML file
- Parameters:
model (ModelGraph) – the hls4ml model.
hls4ml.writer.symbolic_writer module
- class hls4ml.writer.symbolic_writer.SymbolicExpressionWriter
Bases:
VivadoWriter- write_build_script(model)
Write the TCL/Shell build scripts (project.tcl, build_prj.tcl, vivado_synth.tcl, build_lib.sh)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_hls(model)
- write_nnet_utils(model)
Copy the nnet_utils, AP types headers and any custom source to the project output directory
- Parameters:
model (ModelGraph) – the hls4ml model.
hls4ml.writer.vitis_writer module
- class hls4ml.writer.vitis_writer.VitisWriter
Bases:
VivadoWriter- write_board_script_override(model)
Write the tcl scripts and kernel sources to create a Vitis IPI
- write_build_opts(model)
- write_build_prj_override(model)
- write_hls(model)
Write the HLS project. Calls the steps from VivadoWriter, adapted for Vitis
- write_nnet_utils_overrides(model)
hls4ml.writer.vivado_accelerator_writer module
- class hls4ml.writer.vivado_accelerator_writer.VivadoAcceleratorWriter
Bases:
VivadoWriter- modify_build_script(model)
Modify the build_prj.tcl and build_lib.sh scripts to add the extra wrapper files and set the top function
- write_axi_wrapper(model)
Write a top level HLS C++ file to wrap the hls4ml project with AXI interfaces :param model: The ModelGraph to write the wrapper for
- write_board_script(model)
Write the tcl scripts and kernel sources to create a Vivado IPI project for the VivadoAccelerator
- write_driver(model)
- write_hls(model)
Write the HLS project. Calls the VivadoBackend writer, and extra steps for VivadoAccelerator/AXI interface
- write_new_tar(model)
- write_wrapper_test(model)
hls4ml.writer.vivado_writer module
- class hls4ml.writer.vivado_writer.VivadoWriter
Bases:
Writer- print_array_to_cpp(var, odir, namespace=None, write_txt_file=True)
Write a weights array to C++ header files.
- Parameters:
var (WeightVariable) – Weight to write
odir (str) – Output directory
namespace (str, optional) – Writes a namespace for the weights to avoid clashes with global variables.
write_txt_file (bool, optional) – Write txt files in addition to .h files. Defaults to True.
- write_bridge(model)
Write the Python-C++ bridge (myproject_bridge.cpp)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_bridge_multigraph(model)
Write the Python-C++ bridge (myproject_stitched_bridge.cpp) :param model: the hls4ml multigraph model. :type model: MultiModelGraph
- write_build_script(model)
Write the TCL/Shell build scripts (project.tcl, build_prj.tcl, vivado_synth.tcl, build_lib.sh)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_build_script_multigraph(model)
Write the build script (build_lib.sh) for stitched multigraph project :param model: the hls4ml multigraph model. :type model: MultiModelGraph
- write_defines(model)
Write the C++ type definitions file (defines.h)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_generated_code(model)
Write the generated code (nnet_code_gen.h)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_hls(model, is_multigraph=False)
- write_multigraph_weights(model)
Write the weights into header files
- Parameters:
model (MultiModelGraph) – the hls4ml multigraph model.
- write_nnet_utils(model)
Copy the nnet_utils, AP types headers and any custom source to the project output directory
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_parameters(model)
Write the C++ layer config file (parameters.h)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_project_cpp(model)
Write the main architecture source file (myproject.cpp)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_project_dir(model)
Write the base project directory
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_project_header(model)
Write the main architecture header file (myproject.h)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_tar(model)
Write the generated project as a .tar.gz archive
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_test_bench(model)
Write the testbench files (myproject_test.cpp and input/output .dat files)
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_weights(model)
Write the weights into header files
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_yml(model)
Write the config to the YAML file
- Parameters:
model (ModelGraph) – the hls4ml model.
hls4ml.writer.writers module
- hls4ml.writer.writers.get_writer(name)
- hls4ml.writer.writers.register_writer(name, writer_cls)
hls4ml.writer.xls_writer module
- class hls4ml.writer.xls_writer.XLSWriter
Bases:
Writer- write_build_script(model: ModelGraph) None
- write_hls(model: ModelGraph) None
- write_layer(model: ModelGraph, layer: Layer)
- write_layers(model: ModelGraph)
- write_nnet_utils(model: ModelGraph) None
Copy the nnet_utils, AP types headers to the project output directory
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_project_dir(model: ModelGraph) None
Write the base project directory
- Parameters:
model (ModelGraph) – the hls4ml model.
- write_project_dslx(model: ModelGraph) None
Write the main architecture source file (myproject.x)
- Parameters:
model (ModelGraph) – the hls4ml model.
- static write_tar(model)
Write the generated project as a .tar.gz archive
- Parameters:
model (ModelGraph) – the hls4ml model.
- hls4ml.writer.xls_writer.append_line(line: str, x: Any, indent=None) str
- hls4ml.writer.xls_writer.append_lines(s: str, *xs: Any, indent=None) str
- hls4ml.writer.xls_writer.firmware_dir(model: ModelGraph)
- hls4ml.writer.xls_writer.reports_dir(model: ModelGraph)
- hls4ml.writer.xls_writer.to_tuple_or_singleton_str(xs: Iterable[Any], sep: str = ', ') str
- hls4ml.writer.xls_writer.xls_function_definition(name, params, args, output_type, body) str
- hls4ml.writer.xls_writer.xls_import_const_definition(const_def: XLSConstDefinition, module_name, new_name=None) XLSConstDefinition
Returns: const new_name = module_name::const_name
- hls4ml.writer.xls_writer.xls_import_module(name: str, alias: str | None = None) str
- hls4ml.writer.xls_writer.xls_import_type_alias(type_alias_def: XLSTypeAliasDefinition, module_name, new_name=None) XLSTypeAliasDefinition
Returns: type new_name = module_name::type_name
- hls4ml.writer.xls_writer.xls_variable_definition(name, value, type=None)