Skip to content

Commit 55ff7e2

Browse files
committed
Add hls4ml example
1 parent 4ec3d53 commit 55ff7e2

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import hls4ml
2+
from hls4ml.backends import VitisAcceleratorConfig
3+
4+
# Fetch a keras model from our example repository
5+
# This will download our example model to your working directory and return an example configuration file
6+
config = hls4ml.utils.fetch_example_model('KERAS_3layer.json')
7+
8+
# You can print it to see some default parameters
9+
#print(config)
10+
11+
# Default config:
12+
#{
13+
# 'OutputDir': 'my-hls-test',
14+
# 'ProjectName': 'myproject',
15+
# 'Backend': 'Vivado',
16+
# 'Part': 'xcku115-flvb2104-2-i',
17+
# 'ClockPeriod': 5,
18+
# 'IOType': 'io_parallel',
19+
# 'HLSConfig': {
20+
# 'Model': {
21+
# 'Precision': 'ap_fixed<16,6>',
22+
# 'ReuseFactor': 1
23+
# }
24+
# },
25+
# 'KerasJson': 'KERAS_3layer.json',
26+
# 'KerasH5': 'KERAS_3layer_weights.h5'
27+
#}
28+
29+
config['OutputDir'] = 'prj_tuto_vitis_stream'
30+
config['ProjectName'] = 'PrjTutoVitisStream'
31+
config['Backend'] = 'VitisAccelerator'
32+
config['Part'] = 'xcu50-fsvh2104-2-e'
33+
config['IOType'] = 'io_stream'
34+
config['AcceleratorConfig'] = {} # Initialize AcceleratorConfig as a dictionary
35+
config['AcceleratorConfig']['Platform'] = 'xilinx_u50_gen3x16_xdma_5_202210_1'
36+
37+
print("[K] Print config after setting up backend:")
38+
print(config)
39+
40+
# Convert it to a hls project
41+
hls_model = hls4ml.converters.keras_to_hls(config)
42+
43+
## Print full list of example model if you want to explore more
44+
#hls4ml.utils.fetch_example_list()
45+
46+
# Use Vivado HLS to synthesize the model
47+
# This might take several minutes
48+
hls_model.build()
49+
50+
# Print out the report if you want
51+
hls4ml.report.read_vivado_report(' prj_tuto_vitis_stream')

0 commit comments

Comments
 (0)