4
4
from hls4ml .model .flow import register_flow
5
5
from hls4ml .report import parse_vivado_report
6
6
7
+
7
8
class VivadoAcceleratorBackend (VivadoBackend ):
8
9
def __init__ (self ):
9
10
super (VivadoBackend , self ).__init__ (name = 'VivadoAccelerator' )
10
11
self ._register_flows ()
11
12
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
+ ):
13
26
# 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
+ )
15
38
# Get Config to view Board and Platform
16
39
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
+ )
18
44
# now make a bitfile
19
45
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 ())
22
48
else :
23
49
curr_dir = os .getcwd ()
24
50
os .chdir (model .config .get_output_dir ())
25
51
try :
26
52
os .system ('vivado -mode batch -source design.tcl' )
27
- except :
53
+ except Exception :
28
54
print ("Something went wrong, check the Vivado logs" )
29
55
os .chdir (curr_dir )
30
56
31
57
return parse_vivado_report (model .config .get_output_dir ())
32
58
33
- def make_xclbin (self ,model , platform = 'xilinx_u250_xdma_201830_2' ):
59
+ def make_xclbin (self , model , platform = 'xilinx_u250_xdma_201830_2' ):
34
60
"""
35
61
36
62
Parameters
@@ -40,27 +66,46 @@ def make_xclbin(self,model, platform='xilinx_u250_xdma_201830_2'):
40
66
deployment target platform, both can be found on the Getting Started section of the Alveo card.
41
67
"""
42
68
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 ())
44
70
os .chdir (abs_path_dir )
45
71
os .makedirs ('xo_files' , exist_ok = True )
46
72
try :
47
73
os .system ('vivado -mode batch -source design.tcl' )
48
- except :
74
+ except Exception :
49
75
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'
52
78
os .makedirs ('xclbin_files' , exist_ok = True )
53
79
os .chdir (abs_path_dir + '/xclbin_files' )
54
80
# 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
+ )
56
91
try :
57
92
os .system (vitis_cmd )
58
- except :
93
+ except Exception :
59
94
print ("Something went wrong, check the Vitis/Vivado logs" )
60
95
os .chdir (curr_dir )
61
96
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
+ ):
64
109
'''
65
110
Create initial accelerator config with default parameters
66
111
Args:
@@ -77,13 +122,13 @@ def create_initial_config(self, board='pynq-z2', part=None, clock_period=5, io_t
77
122
will round the number of bits used to the next power-of-2 value.
78
123
output_type: the wrapper output precision. Can be `float` or an `ap_type`. Note:
79
124
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
81
126
82
127
Returns:
83
128
populated config
84
129
'''
85
130
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 )
87
132
config ['AcceleratorConfig' ] = {}
88
133
config ['AcceleratorConfig' ]['Board' ] = board
89
134
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
94
139
config ['AcceleratorConfig' ]['Precision' ]['Input' ] = input_type # float, double or ap_fixed<a,b>
95
140
config ['AcceleratorConfig' ]['Precision' ]['Output' ] = output_type # float, double or ap_fixed<a,b>
96
141
if board .startswith ('alveo' ):
97
- config ['AcceleratorConfig' ]['Platform' ] = platform
142
+ config ['AcceleratorConfig' ]['Platform' ] = platform
98
143
99
144
return config
100
145
@@ -110,8 +155,6 @@ def _register_flows(self):
110
155
self ._writer_flow = register_flow ('write' , writer_passes , requires = [vivado_ip ], backend = self .name )
111
156
self ._default_flow = vivado_ip
112
157
113
- fifo_depth_opt_passes = [
114
- 'vivadoaccelerator:fifo_depth_optimization'
115
- ] + writer_passes
158
+ fifo_depth_opt_passes = ['vivadoaccelerator:fifo_depth_optimization' ] + writer_passes
116
159
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