Skip to content

Commit

Permalink
Provide interface to add boards. Add option to pass extra build param…
Browse files Browse the repository at this point in the history
…eters to Vivado/Vitis
  • Loading branch information
thesps committed Nov 23, 2023
1 parent c287e2e commit 3011fdc
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
21 changes: 20 additions & 1 deletion conifer/backends/boards/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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
20 changes: 16 additions & 4 deletions conifer/backends/boards/boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions conifer/backends/fpu/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions conifer/backends/xilinxhls/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3011fdc

Please sign in to comment.