1+ import os
2+ import sys
3+ import subprocess
4+
15from hls4ml .backends import VitisBackend , VivadoBackend
26from hls4ml .model .flow import get_flow , register_flow
37
@@ -8,38 +12,15 @@ def __init__(self):
812 self ._register_layer_attributes ()
913 self ._register_flows ()
1014
11- def _register_flows (self ):
12- validation_passes = [
13- 'vitisaccelerator:validate_conv_implementation' ,
14- 'vitisaccelerator:validate_strategy' ,
15- ]
16- validation_flow = register_flow ('validation' , validation_passes , requires = ['vivado:init_layers' ], backend = self .name )
17-
18- # Any potential templates registered specifically for Vitis backend
19- template_flow = register_flow (
20- 'apply_templates' , self ._get_layer_templates , requires = ['vivado:init_layers' ], backend = self .name
21- )
22-
23- writer_passes = ['make_stamp' , 'vitisaccelerator:write_hls' ]
24- self ._writer_flow = register_flow ('write' , writer_passes , requires = ['vitis:ip' ], backend = self .name )
25-
26- ip_flow_requirements = get_flow ('vivado:ip' ).requires .copy ()
27- ip_flow_requirements .insert (ip_flow_requirements .index ('vivado:init_layers' ), validation_flow )
28- ip_flow_requirements .insert (ip_flow_requirements .index ('vivado:apply_templates' ), template_flow )
29-
30- self ._default_flow = register_flow ('ip' , None , requires = ip_flow_requirements , backend = self .name )
31-
3215 def create_initial_config (
3316 self ,
34- board = 'pynq-z2 ' ,
17+ board = 'alveo-u55c ' ,
3518 part = None ,
3619 clock_period = 5 ,
3720 io_type = 'io_parallel' ,
38- interface = 'axi_stream' ,
39- driver = 'python' ,
40- input_type = 'float' ,
41- output_type = 'float' ,
42- platform = 'xilinx_u250_xdma_201830_2' ,
21+ num_kernel = 1 ,
22+ num_thread = 1 ,
23+ batchsize = 8192
4324 ):
4425 '''
4526 Create initial accelerator config with default parameters
@@ -48,32 +29,66 @@ def create_initial_config(
4829 board: one of the keys defined in supported_boards.json
4930 clock_period: clock period passed to hls project
5031 io_type: io_parallel or io_stream
51- interface: `axi_stream`: generate hardware designs and drivers which exploit axi stream channels.
52- `axi_master`: generate hardware designs and drivers which exploit axi master channels.
53- `axi_lite` : generate hardware designs and drivers which exploit axi lite channels. (Don't use it
54- to exchange large amount of data)
55- driver: `python`: generates the python driver to use the accelerator in the PYNQ stack.
56- `c`: generates the c driver to use the accelerator bare-metal.
57- input_type: the wrapper input precision. Can be `float` or an `ap_type`. Note: VivadoAcceleratorBackend
58- will round the number of bits used to the next power-of-2 value.
59- output_type: the wrapper output precision. Can be `float` or an `ap_type`. Note:
60- VivadoAcceleratorBackend will round the number of bits used to the next power-of-2 value.
61- platform: development target platform
62-
32+ num_kernel: how many compute units to create on the fpga
33+ num_thread: how many threads the host cpu uses to drive the fpga
6334 Returns:
6435 populated config
6536 '''
66- board = board if board is not None else 'pynq-z2 '
37+ board = board if board is not None else 'alveo-u55c '
6738 config = super ().create_initial_config (part , clock_period , io_type )
6839 config ['AcceleratorConfig' ] = {}
6940 config ['AcceleratorConfig' ]['Board' ] = board
70- config ['AcceleratorConfig' ]['Interface' ] = interface # axi_stream, axi_master, axi_lite
71- config ['AcceleratorConfig' ]['Driver' ] = driver
72- config ['AcceleratorConfig' ]['Precision' ] = {}
73- config ['AcceleratorConfig' ]['Precision' ]['Input' ] = {}
74- config ['AcceleratorConfig' ]['Precision' ]['Output' ] = {}
75- config ['AcceleratorConfig' ]['Precision' ]['Input' ] = input_type # float, double or ap_fixed<a,b>
76- config ['AcceleratorConfig' ]['Precision' ]['Output' ] = output_type # float, double or ap_fixed<a,b>
77- config ['AcceleratorConfig' ]['Platform' ] = platform
78-
41+ config ['AcceleratorConfig' ]['Num_Kernel' ] = num_kernel
42+ config ['AcceleratorConfig' ]['Num_Thread' ] = num_thread
43+ config ['AcceleratorConfig' ]['Batchsize' ] = batchsize
7944 return config
45+
46+ def build (self , model , target = "all" ):
47+ if 'linux' in sys .platform :
48+ if 'XILINX_VITIS' not in os .environ :
49+ raise Exception ("XILINX_VITIS environmental variable missing. Please install XRT and Vitis, and run the setup scripts before building" )
50+ if 'XILINX_XRT' not in os .environ :
51+ raise Exception ("XILINX_XRT environmental variable missing. Please install XRT and Vitis, and run the setup scripts before building" )
52+ if 'XILINX_VIVADO' not in os .environ :
53+ raise Exception ("XILINX_VIVADO environmental variable missing. Please install XRT and Vitis, and run the setup scripts before building" )
54+
55+ if target not in ["all" , "host" , "hls" , "xclbin" ]:
56+ raise Exception ("Invalid build target" )
57+
58+ curr_dir = os .getcwd ()
59+ os .chdir (model .config .get_output_dir ())
60+ command = "make " + target
61+ # Pre-loading libudev
62+ ldconfig_output = subprocess .check_output (["ldconfig" , "-p" ]).decode ("utf-8" )
63+ for line in ldconfig_output .split ("\n " ):
64+ if "libudev.so" in line and "x86" in line :
65+ command = "LD_PRELOAD=" + line .split ("=>" )[1 ].strip () + " " + command
66+ break
67+ os .system (command )
68+ os .chdir (curr_dir )
69+ else :
70+ raise Exception ("Currently untested on non-Linux OS" )
71+
72+ def predict (self , model , x ):
73+ raise Exception ("TODO: Needs to be implemented" )
74+
75+ def _register_flows (self ):
76+ validation_passes = [
77+ 'vitisaccelerator:validate_conv_implementation' ,
78+ 'vitisaccelerator:validate_strategy' ,
79+ ]
80+ validation_flow = register_flow ('validation' , validation_passes , requires = ['vivado:init_layers' ], backend = self .name )
81+
82+ # Any potential templates registered specifically for Vitis backend
83+ template_flow = register_flow (
84+ 'apply_templates' , self ._get_layer_templates , requires = ['vivado:init_layers' ], backend = self .name
85+ )
86+
87+ writer_passes = ['make_stamp' , 'vitisaccelerator:write_hls' ]
88+ self ._writer_flow = register_flow ('write' , writer_passes , requires = ['vitis:ip' ], backend = self .name )
89+
90+ ip_flow_requirements = get_flow ('vivado:ip' ).requires .copy ()
91+ ip_flow_requirements .insert (ip_flow_requirements .index ('vivado:init_layers' ), validation_flow )
92+ ip_flow_requirements .insert (ip_flow_requirements .index ('vivado:apply_templates' ), template_flow )
93+
94+ self ._default_flow = register_flow ('ip' , None , requires = ip_flow_requirements , backend = self .name )
0 commit comments