diff --git a/conifer/backends/boards/__init__.py b/conifer/backends/boards/__init__.py index 52bc3f7..2428944 100644 --- a/conifer/backends/boards/__init__.py +++ b/conifer/backends/boards/__init__.py @@ -35,4 +35,23 @@ def get_board_config(name): def get_builder(project_config, board_config, **kwargs): builder = __builders.get(type(board_config), None) assert builder is not None, f'Could not find builder for {type(board_config)} from {list(__builders.keys())}' - return builder(project_config, board_config, **kwargs) \ No newline at end of file + return builder(project_config, board_config, **kwargs) + +def register_board_config(name : str, config : BoardConfig): + ''' + Register a new board for building accelerators + + Parameters + ---------- + name: str + Name of new board + config: BoardConfig + Configuration for new board + ''' + if name in __configs.keys(): + logger.error(f'board configuration with name "{name}" is already registered') + else: + assert isinstance(config, BoardConfig), f'Expected BoardConfig object, got {type(config)}' + assert type(config) in __builders.keys(), f'Cannot get builder for {type(config)}, expected one of {__builders.keys()}' + logger.info('registering board "{name}"') + __configs[name] = config \ No newline at end of file diff --git a/conifer/backends/boards/boards.py b/conifer/backends/boards/boards.py index 415b053..3f1116f 100644 --- a/conifer/backends/boards/boards.py +++ b/conifer/backends/boards/boards.py @@ -144,15 +144,21 @@ def get_export_format(self): def get_maxi64(self): return False - def build(self): + def build(self, vivado_opts=None): ''' Build Zynq project + + Parameters + ---------- + vivado_opts: string (optional) + additional options to pass to vivado command ''' self.write() cwd = os.getcwd() os.chdir(self.project_cfg.output_dir) success = True - cmd = 'vivado -mode batch -source build_bit.tcl > vivado_build.log' + vivado_opts = '' if vivado_opts is None else vivado_opts + cmd = f'vivado -mode batch -source build_bit.tcl {vivado_opts} > vivado_build.log' logger.info(f'Building Zynq bitfile with command "{cmd}"') success = success and os.system(cmd)==0 os.chdir(cwd) @@ -161,6 +167,7 @@ def build(self): def package(self, retry: int = 6, retries: int = 10): ''' Collect build products and compress to a zip file + Parameters ---------- retry: int (optional) @@ -233,13 +240,17 @@ def get_maxi64(self): def write(self): return - def build(self, target='hw'): + def build(self, target = 'hw', vitis_opts : str = None): ''' Build Alveo project + Parameters ---------- target: string (optional) v++ target + + vitis_opts: string (optional) + additional options to pass to v++ command ''' self.write() cwd = os.getcwd() @@ -248,7 +259,8 @@ def build(self, target='hw'): os.chdir(od) success = True pn = pn - vitis_cmd = f'v++ -t {target} --platform {self.board_cfg.platform} --link {pn}/solution1/impl/export.xo -o {pn}.xclbin > vitis_build.log' + vitis_opts = '' if vitis_opts is None else vitis_opts + vitis_cmd = f'v++ -t {target} --platform {self.board_cfg.platform} --link {pn}/solution1/impl/export.xo -o {pn}.xclbin {vitis_opts} > vitis_build.log' logger.info(f'Building Alveo bitfile with command "{vitis_cmd}"') success = success and os.system(vitis_cmd)==0 os.chdir(cwd) diff --git a/conifer/backends/fpu/writer.py b/conifer/backends/fpu/writer.py index 87bf8e5..35365e3 100644 --- a/conifer/backends/fpu/writer.py +++ b/conifer/backends/fpu/writer.py @@ -401,7 +401,7 @@ def write(self): self.write_params() self.write_tcl() - def build(self, csynth=True, bitfile=True): + def build(self, csynth=True, bitfile=True, **build_kwargs): ''' Build FPU project Parameters @@ -420,7 +420,7 @@ def build(self, csynth=True, bitfile=True): logger.info(f'Building FPU HLS with command "{cmd}"') success = success and os.system(cmd)==0 if success and bitfile: - success = success and self.board_builder.build() + success = success and self.board_builder.build(**build_kwargs) os.chdir(cwd) return success diff --git a/conifer/backends/xilinxhls/writer.py b/conifer/backends/xilinxhls/writer.py index bcc9d10..0a41b57 100644 --- a/conifer/backends/xilinxhls/writer.py +++ b/conifer/backends/xilinxhls/writer.py @@ -545,7 +545,7 @@ def compile(self): os.chdir(curr_dir) @copydocstring(ModelBase.build) - def build(self, reset=False, csim=False, synth=True, cosim=False, export=False, vsynth=False, bitfile=False, package=False): + def build(self, reset=False, csim=False, synth=True, cosim=False, export=False, vsynth=False, bitfile=False, package=False, **bitfile_kwargs): cwd = os.getcwd() os.chdir(self.config.output_dir) @@ -590,7 +590,7 @@ def build(self, reset=False, csim=False, synth=True, cosim=False, export=False, logger.error('bitfile was requested but no accelerator_config found') rval = False else: - rval = self.config.accelerator_builder.build() + rval = self.config.accelerator_builder.build(**bitfile_kwargs) if rval: self.config.accelerator_builder.package() os.chdir(cwd)