diff --git a/hls4ml/templates/vivado/build_prj.tcl b/hls4ml/templates/vivado/build_prj.tcl index d34337c573..af37b0f4aa 100644 --- a/hls4ml/templates/vivado/build_prj.tcl +++ b/hls4ml/templates/vivado/build_prj.tcl @@ -229,7 +229,7 @@ if {$opt(validation)} { if {$opt(export)} { puts "***** EXPORT IP *****" set time_start [clock clicks -milliseconds] - export_design -format ip_catalog + export_design -format ip_catalog -version $version set time_end [clock clicks -milliseconds] report_time "EXPORT IP" $time_start $time_end } diff --git a/hls4ml/utils/config.py b/hls4ml/utils/config.py index 3743659649..5d7ca1ae72 100644 --- a/hls4ml/utils/config.py +++ b/hls4ml/utils/config.py @@ -5,7 +5,29 @@ import hls4ml -def create_config(output_dir='my-hls-test', project_name='myproject', backend='Vivado', **kwargs): +def create_config(output_dir='my-hls-test', project_name='myproject', backend='Vivado', version='1.0.0', **kwargs): + """Create an initial configuration to guide the conversion process. + + The resulting configuration will contain general information about the project (like project name and output directory) + as well as the backend-specific configuration (part numbers, clocks etc). Extra arguments of this function will be + passed to the backend's ``create_initial_config``. For the possible list of arguments, check the documentation of each + backend. + + Args: + output_dir (str, optional): The output directory to which the generated project will be written. + Defaults to 'my-hls-test'. + project_name (str, optional): The name of the project, that will be used as a top-level function in HLS designs. + Defaults to 'myproject'. + backend (str, optional): The backend to use. Defaults to 'Vivado'. + version (str, optional): Optional string to version the generated project for backends that support it. + Defaults to '1.0.0'. + + Raises: + Exception: Raised if unknown backend is specified. + + Returns: + dict: The conversion configuration. + """ backend_list = hls4ml.backends.get_available_backends() if backend.lower() not in backend_list: raise Exception(f'Unknown backend: {backend}') @@ -18,6 +40,7 @@ def create_config(output_dir='my-hls-test', project_name='myproject', backend='V config['OutputDir'] = output_dir config['ProjectName'] = project_name config['Backend'] = backend.name + config['Version'] = version config.update(backend_config) return config diff --git a/hls4ml/writer/vivado_accelerator_writer.py b/hls4ml/writer/vivado_accelerator_writer.py index 98ac8f2dcd..3b4e5fdf13 100644 --- a/hls4ml/writer/vivado_accelerator_writer.py +++ b/hls4ml/writer/vivado_accelerator_writer.py @@ -392,6 +392,8 @@ def write_board_script(self, model): f.write('set clock_period {}\n'.format(model.config.get_config_value('ClockPeriod'))) f.write('variable clock_uncertainty\n') f.write('set clock_uncertainty {}\n'.format(model.config.get_config_value('ClockUncertainty', '12.5%'))) + f.write('variable version\n') + f.write('set version "{}"\n'.format(model.config.get_config_value('Version', '1.0.0'))) if self.vivado_accelerator_config.get_interface() == 'axi_stream': in_bit, out_bit = self.vivado_accelerator_config.get_io_bitwidth() f.write(f'set bit_width_hls_output {in_bit}\n') diff --git a/hls4ml/writer/vivado_writer.py b/hls4ml/writer/vivado_writer.py index 2fbe3d9438..0080b5e78d 100644 --- a/hls4ml/writer/vivado_writer.py +++ b/hls4ml/writer/vivado_writer.py @@ -588,6 +588,8 @@ def write_build_script(self, model): f.write('set clock_period {}\n'.format(model.config.get_config_value('ClockPeriod'))) f.write('variable clock_uncertainty\n') f.write('set clock_uncertainty {}\n'.format(model.config.get_config_value('ClockUncertainty', '12.5%'))) + f.write('variable version\n') + f.write('set version "{}"\n'.format(model.config.get_config_value('Version', '1.0.0'))) f.close() # build_prj.tcl