Skip to content

Commit 4ceb431

Browse files
alex-yang-upennQuentin Berthet
authored andcommitted
build dir name + versal packaging + ultraclean
1 parent 9cb3997 commit 4ceb431

File tree

3 files changed

+43
-18
lines changed

3 files changed

+43
-18
lines changed

hls4ml/backends/vitis_accelerator/vitis_accelerator_backend.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def create_initial_config(
5050
config['AcceleratorConfig']['Vivado_Directives'] = vivado_directives
5151
return config
5252

53-
def build(self, model, reset=False, synth=True, vsynth=True, **kwargs):
53+
def build(self, model, reset=False, synth=True, vsynth=True, csim=False, cosim=False, debug=False, **kwargs):
5454
if 'linux' in sys.platform:
5555
if 'XILINX_VITIS' not in os.environ:
5656
raise Exception("XILINX_VITIS environmental variable missing. Please install XRT and Vitis, and run the setup scripts before building")
@@ -71,13 +71,22 @@ def build(self, model, reset=False, synth=True, vsynth=True, **kwargs):
7171

7272
if vsynth:
7373
if synth:
74-
target = "all"
74+
target = "all "
7575
else:
76-
target = "xclbin"
76+
target = "xclbin "
7777
elif synth:
78-
target = "hls"
78+
target = "hls "
7979
else:
80-
target = "host"
80+
target = "host "
81+
82+
if cosim:
83+
target += "TARGET=hw_emu "
84+
elif csim:
85+
target += "TARGET=sw_emu "
86+
87+
if debug:
88+
target += "DEBUG"
89+
8190
command = "make " + target
8291

8392
# Pre-loading libudev

hls4ml/templates/vitis_accelerator/Makefile

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,22 @@ CARD_CFG ?= accelerator_card.cfg
3131
# Platform (currently extracted from accelerator_card.cfg if not already set)
3232
PLATFORM ?= $(shell awk -F '=' '/platform=/ {print $$2}' $(CARD_CFG))
3333

34-
# kernel name
34+
# Board Type (determines whether design will go through packaging step)
35+
BOARD_TYPE :=
36+
37+
# Kernel name
3538
KERNEL_NAME := myproject
3639

3740
# Wrapper name
3841
WRAPPER_NAME := kernel_wrapper
3942

4043
# Top level build directory
4144
BUILD_DIR := ./build_$(TARGET)
45+
ifdef DEBUG
46+
BUILD_DIR += _deb
47+
else
48+
BUILD_DIR += _rel
49+
endif
4250

4351
# Directories for kernel synthesis
4452
XO_DIR := $(BUILD_DIR)/xo
@@ -78,27 +86,27 @@ hls: $(BUILD_DIR)/$(KERNEL_NAME)_kernel.xo
7886

7987
# Kernel linking & packaging ##################################################
8088

89+
ifeq ($(BOARD_TYPE),alveo)
8190
# For Standard Alveo, a single step is required for linking and packaging
82-
ifeq (,$(findstring vck5000,$(PLATFORM)))
8391
# This is standard Alveo linking and packaging
84-
8592
$(BUILD_DIR)/$(WRAPPER_NAME).xclbin: $(BUILD_DIR)/$(KERNEL_NAME)_kernel.xo
8693
mkdir -p $(XCLBIN_DIR)
8794
v++ -l $(XOLDFLAGS) --temp_dir $(XCLBIN_DIR) --log_dir $(XCLBIN_DIR) -o $@ $^
8895

89-
else
90-
# For VCK5000, linking and packaging are separate steps
91-
96+
else ifeq ($(BOARD_TYPE),alveo-versal) || ($(BOARD_TYPE),versal)
97+
# For Versal architecture, linking and packaging are separate steps
9298
$(BUILD_DIR)/$(WRAPPER_NAME).xsa: $(BUILD_DIR)/$(KERNEL_NAME)_kernel.xo
9399
mkdir -p $(XCLBIN_DIR)
94100
v++ -l $(XOLDFLAGS) --temp_dir $(XCLBIN_DIR) --log_dir $(XCLBIN_DIR) -o $@ $^
95101

96-
XOCCPFLAGS := -t $(TARGET) -f $(PLATFORM) --package.boot_mode=ospi --messageDb=$(BUILD_DIR)/kernel_wrapper.mdb
97-
98102
# VCK5000 specific packaging
103+
XOCCPFLAGS := -t $(TARGET) -f $(PLATFORM) --package.boot_mode=ospi --messageDb=$(BUILD_DIR)/kernel_wrapper.mdb
99104
$(BUILD_DIR)/$(WRAPPER_NAME).xclbin: $(BUILD_DIR)/$(WRAPPER_NAME).xsa
100105
v++ -p $(XOCCPFLAGS) --temp_dir $(XCLBIN_DIR) --log_dir $(XCLBIN_DIR) -o $@ $^
101106

107+
else
108+
@echo "$(BOARD_TYPE) board type is currently unsupported"
109+
102110
endif
103111

104112
xclbin: $(BUILD_DIR)/$(WRAPPER_NAME).xclbin
@@ -114,14 +122,19 @@ host: $(KERNEL_NAME)_host_cl.cpp libs/xcl2.cpp
114122
# Cleanup #####################################################################
115123

116124
cleanxclbin:
117-
rm -rf host tb_data/hw_results.dat
125+
rm -rf host tb_data/hw_results.dat tb_data/tb_input_features.dat
118126
rm -rf *$(WRAPPER_NAME)*.log
119-
rm -rf $(BUILD_DIR)/$(WRAPPER_NAME).xclbin* $(BUILD_DIR)/$(WRAPPER_NAME).xsa* $(BUILD_DIR)/$(WRAPPER_NAME).ltx $(BUILD_DIR)/$(WRAPPER_NAME).mdb
120-
rm -rf $(BUILD_DIR)/xclbincleanhls
127+
rm -rf $(BUILD_DIR)/$(WRAPPER_NAME).xclbin.* $(BUILD_DIR)/$(WRAPPER_NAME).xsa* $(BUILD_DIR)/$(WRAPPER_NAME).ltx $(BUILD_DIR)/$(WRAPPER_NAME).mdb
128+
rm -rf $(XCLBIN_DIR)
121129

122130
cleanhls:
123-
rm -rf $(BUILD_DIR)/$(KERNEL_NAME)_kernel.xo*
124-
rm -rf $(BUILD_DIR)/xo
125131
rm -rf *$(KERNEL_NAME)_kernel*.log
132+
rm -rf $(BUILD_DIR)/$(KERNEL_NAME)_kernel.xo.*
133+
rm -rf $(XO_DIR)
126134

127135
clean: cleanxclbin cleanhls
136+
137+
ultraclean:
138+
rm -rf host tb_data/hw_results.dat tb_data/tb_input_features.dat *.log
139+
rm -rf $(BUILD_DIR)
140+

hls4ml/writer/vitis_accelerator_writer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ def write_makefile(self, model):
206206
for line in f.readlines():
207207
if 'myproject' in line:
208208
newline = line.replace('myproject', project_name)
209+
if 'BOARD_TYPE :=' in line:
210+
newline = line
211+
newline += board_type
209212
else:
210213
newline = line
211214
fout.write(newline)

0 commit comments

Comments
 (0)