Skip to content

Commit

Permalink
Providing support for Alveo boards (#552)
Browse files Browse the repository at this point in the history
Providing support for Alveo boards (#552)

Co-authored-by: Sioni Summers <sioni.summers10@imperial.ac.uk>
Co-authored-by: Gabriele-bot <gabrielebortolato.1996@yahoo.it>
Co-authored-by: Selwyn96 <selwyn96@prp-gpu-1.t2.ucsd.edu>
  • Loading branch information
4 people committed Jun 20, 2022
1 parent eb9f3b4 commit aa7ce78
Show file tree
Hide file tree
Showing 17 changed files with 1,998 additions and 22 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ graft example-prjs
graft example-models
graft test
recursive-include hls4ml/templates *
include hls4ml/backends/vivado_accelerator/supported_boards.json
2 changes: 1 addition & 1 deletion example-models
30 changes: 29 additions & 1 deletion hls4ml/backends/vivado_accelerator/supported_boards.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,33 @@
"tcl_scripts": { "axi_stream": "axi_stream_design.tcl"},
"python_drivers": {"axi_stream": "axi_stream_driver.py"},
"c_drivers": {}
},
"alveo-u50": {
"part": "xcu50-fsvh2104-2-e",
"tcl_scripts": {"axi_stream": "axi_stream_design.tcl"},
"python_drivers": {"axi_stream": "axi_stream_driver.py"},
"krnl_rtl_srcs": {"axi_stream": "krnl_rtl_src"},
"c_drivers": {}
},
"alveo-u250": {
"part": "xcu250-figd2104-2L-e",
"tcl_scripts": {"axi_stream": "axi_stream_design.tcl"},
"python_drivers": {"axi_stream": "axi_stream_driver.py"},
"krnl_rtl_srcs": {"axi_stream": "krnl_rtl_src"},
"c_drivers": {}
},
"alveo-u200": {
"part": "xcu200-fsgd2104-2-e",
"tcl_scripts": {"axi_stream": "axi_stream_design.tcl"},
"python_drivers": {"axi_stream": "axi_stream_driver.py"},
"krnl_rtl_srcs": {"axi_stream": "krnl_rtl_src"},
"c_drivers": {}
},
"alveo-u280": {
"part": "xcu280-fsvh2892-2L-e",
"tcl_scripts": {"axi_stream": "axi_stream_design.tcl"},
"python_drivers": {"axi_stream": "axi_stream_driver.py"},
"krnl_rtl_srcs": {"axi_stream": "krnl_rtl_src"},
"c_drivers": {}
}
}
}
55 changes: 47 additions & 8 deletions hls4ml/backends/vivado_accelerator/vivado_accelerator_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,55 @@ def __init__(self):
def build(self, model, reset=False, csim=True, synth=True, cosim=False, validation=False, export=False, vsynth=False, bitfile=False):
# run the VivadoBackend build
report = super().build(model, reset=reset, csim=csim, synth=synth, cosim=cosim, validation=validation, export=export, vsynth=vsynth)
# Get Config to view Board and Platform
from hls4ml.backends import VivadoAcceleratorConfig
vivado_accelerator_config=VivadoAcceleratorConfig(model.config, model.get_input_variables(),model.get_output_variables())
# now make a bitfile
if bitfile:
curr_dir = os.getcwd()
os.chdir(model.config.get_output_dir())
try:
os.system('vivado -mode batch -source design.tcl')
except:
print("Something went wrong, check the Vivado logs")
os.chdir(curr_dir)
if(vivado_accelerator_config.get_board().startswith('alveo')):
self.make_xclbin(model,vivado_accelerator_config.get_platform())
else:
curr_dir = os.getcwd()
os.chdir(model.config.get_output_dir())
try:
os.system('vivado -mode batch -source design.tcl')
except:
print("Something went wrong, check the Vivado logs")
os.chdir(curr_dir)

return parse_vivado_report(model.config.get_output_dir())

def make_xclbin(self,model, platform='xilinx_u250_xdma_201830_2'):
"""
Parameters
----------
- model : compiled and built hls_model.
- platform : development Target Platform, must be installed first. On the host machine is required only the
deployment target platform, both can be found on the Getting Started section of the Alveo card.
"""
curr_dir = os.getcwd()
abs_path_dir=os.path.abspath(model.config.get_output_dir())
os.chdir(abs_path_dir)
os.makedirs('xo_files', exist_ok=True)
try:
os.system('vivado -mode batch -source design.tcl')
except:
print("Something went wrong, check the Vivado logs")
project_name=model.config.get_project_name()
ip_repo_path = abs_path_dir + '/'+project_name+'_prj'+'/solution1/impl/ip'
os.makedirs('xclbin_files', exist_ok=True)
os.chdir(abs_path_dir + '/xclbin_files')
# TODO Add other platforms
vitis_cmd = "v++ -t hw --platform " + platform + " --link ../xo_files/"+project_name+"_kernel.xo -o'"+project_name+"_kernel.xclbin' --user_ip_repo_paths " + ip_repo_path
try:
os.system(vitis_cmd)
except:
print("Something went wrong, check the Vitis/Vivado logs")
os.chdir(curr_dir)

def create_initial_config(self, board='pynq-z2', part=None, clock_period=5, io_type='io_parallel', interface='axi_stream',
driver='python', input_type='float', output_type='float'):
driver='python', input_type='float', output_type='float',platform='xilinx_u250_xdma_201830_2'):
'''
Create initial accelerator config with default parameters
Args:
Expand All @@ -42,6 +77,7 @@ def create_initial_config(self, board='pynq-z2', part=None, clock_period=5, io_t
will round the number of bits used to the next power-of-2 value.
output_type: the wrapper output precision. Can be `float` or an `ap_type`. Note:
VivadoAcceleratorBackend will round the number of bits used to the next power-of-2 value.
platform: development target platform
Returns:
populated config
Expand All @@ -57,6 +93,9 @@ def create_initial_config(self, board='pynq-z2', part=None, clock_period=5, io_t
config['AcceleratorConfig']['Precision']['Output'] = {}
config['AcceleratorConfig']['Precision']['Input'] = input_type # float, double or ap_fixed<a,b>
config['AcceleratorConfig']['Precision']['Output'] = output_type # float, double or ap_fixed<a,b>
if board.startswith('alveo'):
config['AcceleratorConfig']['Platform'] = platform

return config

def _register_flows(self):
Expand Down
23 changes: 21 additions & 2 deletions hls4ml/backends/vivado_accelerator/vivado_accelerator_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(self, config, model_inputs, model_outputs):
'float') # float, double or ap_fixed<a,b>
self.output_type = self.config['AcceleratorConfig']['Precision'].get('Output',
'float') # float, double or ap_fixed<a,b>
self.platform= self.config['AcceleratorConfig'].get('Platform', 'xilinx_u250_xdma_201830_2') # Get platform folder name

assert len(
model_inputs) == 1, "Only models with one input tensor are currently supported by VivadoAcceleratorBackend"
Expand Down Expand Up @@ -118,14 +119,28 @@ def get_driver(self):
def get_board(self):
return self.board

def get_platform(self):
return self.platform

def get_clock_period(self):
return self.clock_period

def get_driver_path(self):
return '../templates/vivado_accelerator/' + self.board + '/' + self.driver + '_drivers/' + \
if self.board.startswith('alveo'):
return '../templates/vivado_accelerator/' + 'alveo/' + self.driver + '_drivers/' + \
self.get_driver_file()
else:
return '../templates/vivado_accelerator/' + self.board + '/' + self.driver + '_drivers/' + \
self.get_driver_file()

def get_driver_file(self):
driver_ext = '.py' if self.driver == 'python' else '.h'
return self.interface + '_driver' + driver_ext

def get_krnl_rtl_src_dir(self):
return '../templates/vivado_accelerator/' + 'alveo/' + '/krnl_rtl_src'


def get_input_type(self):
return self.input_type

Expand All @@ -140,4 +155,8 @@ def get_tcl_file_path(self):
tcl_script = tcl_scripts.get(self.interface, None)
if tcl_script is None:
raise Exception('No tcl script definition available for the desired interface in supported_board.json')
return '../templates/vivado_accelerator/' + self.board + '/tcl_scripts/' + tcl_script
if self.board.startswith('alveo'):
return '../templates/vivado_accelerator/' + 'alveo/' + '/tcl_scripts/' + tcl_script
else:
return '../templates/vivado_accelerator/' + self.board + '/tcl_scripts/' + tcl_script

0 comments on commit aa7ce78

Please sign in to comment.