44from hls4ml .model .flow import register_flow
55from hls4ml .report import parse_vivado_report
66
7+
78class VivadoAcceleratorBackend (VivadoBackend ):
89 def __init__ (self ):
910 super (VivadoBackend , self ).__init__ (name = 'VivadoAccelerator' )
1011 self ._register_flows ()
1112
12- def build (self , model , reset = False , csim = True , synth = True , cosim = False , validation = False , export = False , vsynth = False , fifo_opt = False , bitfile = False ):
13+ def build (
14+ self ,
15+ model ,
16+ reset = False ,
17+ csim = True ,
18+ synth = True ,
19+ cosim = False ,
20+ validation = False ,
21+ export = False ,
22+ vsynth = False ,
23+ fifo_opt = False ,
24+ bitfile = False ,
25+ ):
1326 # run the VivadoBackend build
14- report = super ().build (model , reset = reset , csim = csim , synth = synth , cosim = cosim , validation = validation , export = export , vsynth = vsynth , fifo_opt = fifo_opt )
27+ super ().build (
28+ model ,
29+ reset = reset ,
30+ csim = csim ,
31+ synth = synth ,
32+ cosim = cosim ,
33+ validation = validation ,
34+ export = export ,
35+ vsynth = vsynth ,
36+ fifo_opt = fifo_opt ,
37+ )
1538 # Get Config to view Board and Platform
1639 from hls4ml .backends import VivadoAcceleratorConfig
17- vivado_accelerator_config = VivadoAcceleratorConfig (model .config , model .get_input_variables (),model .get_output_variables ())
40+
41+ vivado_accelerator_config = VivadoAcceleratorConfig (
42+ model .config , model .get_input_variables (), model .get_output_variables ()
43+ )
1844 # now make a bitfile
1945 if bitfile :
20- if ( vivado_accelerator_config .get_board ().startswith ('alveo' ) ):
21- self .make_xclbin (model ,vivado_accelerator_config .get_platform ())
46+ if vivado_accelerator_config .get_board ().startswith ('alveo' ):
47+ self .make_xclbin (model , vivado_accelerator_config .get_platform ())
2248 else :
2349 curr_dir = os .getcwd ()
2450 os .chdir (model .config .get_output_dir ())
2551 try :
2652 os .system ('vivado -mode batch -source design.tcl' )
27- except :
53+ except Exception :
2854 print ("Something went wrong, check the Vivado logs" )
2955 os .chdir (curr_dir )
3056
3157 return parse_vivado_report (model .config .get_output_dir ())
3258
33- def make_xclbin (self ,model , platform = 'xilinx_u250_xdma_201830_2' ):
59+ def make_xclbin (self , model , platform = 'xilinx_u250_xdma_201830_2' ):
3460 """
3561
3662 Parameters
@@ -40,27 +66,46 @@ def make_xclbin(self,model, platform='xilinx_u250_xdma_201830_2'):
4066 deployment target platform, both can be found on the Getting Started section of the Alveo card.
4167 """
4268 curr_dir = os .getcwd ()
43- abs_path_dir = os .path .abspath (model .config .get_output_dir ())
69+ abs_path_dir = os .path .abspath (model .config .get_output_dir ())
4470 os .chdir (abs_path_dir )
4571 os .makedirs ('xo_files' , exist_ok = True )
4672 try :
4773 os .system ('vivado -mode batch -source design.tcl' )
48- except :
74+ except Exception :
4975 print ("Something went wrong, check the Vivado logs" )
50- project_name = model .config .get_project_name ()
51- ip_repo_path = abs_path_dir + '/' + project_name + '_prj' + '/solution1/impl/ip'
76+ project_name = model .config .get_project_name ()
77+ ip_repo_path = abs_path_dir + '/' + project_name + '_prj' + '/solution1/impl/ip'
5278 os .makedirs ('xclbin_files' , exist_ok = True )
5379 os .chdir (abs_path_dir + '/xclbin_files' )
5480 # TODO Add other platforms
55- 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
81+ vitis_cmd = (
82+ "v++ -t hw --platform "
83+ + platform
84+ + " --link ../xo_files/"
85+ + project_name
86+ + "_kernel.xo -o'"
87+ + project_name
88+ + "_kernel.xclbin' --user_ip_repo_paths "
89+ + ip_repo_path
90+ )
5691 try :
5792 os .system (vitis_cmd )
58- except :
93+ except Exception :
5994 print ("Something went wrong, check the Vitis/Vivado logs" )
6095 os .chdir (curr_dir )
6196
62- def create_initial_config (self , board = 'pynq-z2' , part = None , clock_period = 5 , io_type = 'io_parallel' , interface = 'axi_stream' ,
63- driver = 'python' , input_type = 'float' , output_type = 'float' ,platform = 'xilinx_u250_xdma_201830_2' ):
97+ def create_initial_config (
98+ self ,
99+ board = 'pynq-z2' ,
100+ part = None ,
101+ clock_period = 5 ,
102+ io_type = 'io_parallel' ,
103+ interface = 'axi_stream' ,
104+ driver = 'python' ,
105+ input_type = 'float' ,
106+ output_type = 'float' ,
107+ platform = 'xilinx_u250_xdma_201830_2' ,
108+ ):
64109 '''
65110 Create initial accelerator config with default parameters
66111 Args:
@@ -77,13 +122,13 @@ def create_initial_config(self, board='pynq-z2', part=None, clock_period=5, io_t
77122 will round the number of bits used to the next power-of-2 value.
78123 output_type: the wrapper output precision. Can be `float` or an `ap_type`. Note:
79124 VivadoAcceleratorBackend will round the number of bits used to the next power-of-2 value.
80- platform: development target platform
125+ platform: development target platform
81126
82127 Returns:
83128 populated config
84129 '''
85130 board = board if board is not None else 'pynq-z2'
86- config = super (VivadoAcceleratorBackend , self ).create_initial_config (part , clock_period , io_type )
131+ config = super ().create_initial_config (part , clock_period , io_type )
87132 config ['AcceleratorConfig' ] = {}
88133 config ['AcceleratorConfig' ]['Board' ] = board
89134 config ['AcceleratorConfig' ]['Interface' ] = interface # axi_stream, axi_master, axi_lite
@@ -94,7 +139,7 @@ def create_initial_config(self, board='pynq-z2', part=None, clock_period=5, io_t
94139 config ['AcceleratorConfig' ]['Precision' ]['Input' ] = input_type # float, double or ap_fixed<a,b>
95140 config ['AcceleratorConfig' ]['Precision' ]['Output' ] = output_type # float, double or ap_fixed<a,b>
96141 if board .startswith ('alveo' ):
97- config ['AcceleratorConfig' ]['Platform' ] = platform
142+ config ['AcceleratorConfig' ]['Platform' ] = platform
98143
99144 return config
100145
@@ -110,8 +155,6 @@ def _register_flows(self):
110155 self ._writer_flow = register_flow ('write' , writer_passes , requires = [vivado_ip ], backend = self .name )
111156 self ._default_flow = vivado_ip
112157
113- fifo_depth_opt_passes = [
114- 'vivadoaccelerator:fifo_depth_optimization'
115- ] + writer_passes
158+ fifo_depth_opt_passes = ['vivadoaccelerator:fifo_depth_optimization' ] + writer_passes
116159
117- register_flow ('fifo_depth_optimization' , fifo_depth_opt_passes , requires = [self . _writer_flow ], backend = self .name )
160+ register_flow ('fifo_depth_optimization' , fifo_depth_opt_passes , requires = [vivado_ip ], backend = self .name )
0 commit comments