Skip to content

Commit f5b8839

Browse files
author
Quentin Berthet
committed
Update makefile
1 parent 20bec3b commit f5b8839

File tree

2 files changed

+99
-46
lines changed

2 files changed

+99
-46
lines changed
Lines changed: 99 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,126 @@
1-
# Absolute path to top directory of accelerator project
2-
PWD = $(shell readlink -f .)
1+
# Check environment ###########################################################
32

4-
# Checks for XILINX_VITIS
53
ifndef XILINX_VITIS
64
$(error XILINX_VITIS variable is not set, please set correctly and rerun)
75
endif
86

9-
# Checks for XILINX_XRT
107
ifndef XILINX_XRT
118
$(error XILINX_XRT variable is not set, please set correctly and rerun)
129
endif
1310

14-
# Checks for XILINX_VIVADO
1511
ifndef XILINX_VIVADO
1612
$(error XILINX_VIVADO variable is not set, please set correctly and rerun)
1713
endif
1814

19-
# Checks for g++
2015
ifneq ($(shell expr $(shell g++ -dumpversion) \>= 5), 1)
2116
CXX := $(XILINX_VIVADO)/tps/lnx64/gcc-6.2.0/bin/g++
22-
$(warning [WARNING]: g++ version older. Using g++ provided by the tool : $(CXX))
17+
$(warning [WARNING]: g++ version older. Using g++ provided by the tool: $(CXX))
2318
endif
2419

25-
KERN_LIBRARIES += -I./ -I./firmware/ -I./firmware/weights -I./firmware/nnet_utils/
20+
# Configuration variables #####################################################
21+
22+
# Absolute path to top directory of accelerator project
23+
PWD := $(shell pwd)
24+
25+
# Target (hw, hw_emu, sw_emu)
26+
TARGET ?= hw
27+
28+
# Accelerator card configuration file
29+
CARD_CFG ?= accelerator_card.cfg
30+
31+
# Platform (currently extracted from accelerator_card.cfg if not already set)
32+
PLATFORM ?= $(shell awk -F '=' '/platform=/ {print $$2}' $(CARD_CFG))
33+
34+
# kernel name
35+
KERNEL_NAME := myproject
36+
37+
# Wrapper name
38+
WRAPPER_NAME := kernel_wrapper
2639

27-
.PHONY: all
28-
all: hls xclbin
40+
# Top level build directory
41+
BUILD_DIR := ./build_$(TARGET)
2942

30-
# Building kernel
31-
./build/myproject_kernel.xo: kernel_wrapper.cpp
32-
mkdir -p ./build && mkdir -p ./build/xo
33-
v++ -c -t hw --config ./accelerator_card.cfg --temp_dir build/xo kernel_wrapper.cpp firmware/myproject.cpp -o ./build/myproject_kernel.xo $(KERN_LIBRARIES)
43+
# Directories for kernel synthesis
44+
XO_DIR := $(BUILD_DIR)/xo
45+
XCLBIN_DIR := $(BUILD_DIR)/xclbin
3446

35-
# hls-fpga-machine-learning packaging
47+
# CC flags for v++
48+
XOCCFLAGS := -t $(TARGET) --config $(CARD_CFG) --messageDb=$(BUILD_DIR)/kernel_wrapper.mdb
3649

37-
# Building Host
38-
INCLUDES += -I$(XILINX_XRT)/include/ -I$(XILINX_VIVADO)/include/ -I$(XILINX_HLS)/include/ \
39-
-I$(PWD)/libs/ -I$(PWD)/firmware/ -I$(PWD)/firmware/nnet_utils/
40-
CXXFLAGS += -Wall -std=c++11 -Wno-unknown-pragmas -g -O0
50+
# Linker flags for V++
51+
XOLDFLAGS := -t $(TARGET) --config $(CARD_CFG) --messageDb=$(BUILD_DIR)/kernel_wrapper.mdb
52+
53+
# C++ compiler & linker flags
54+
CXXFLAGS := -Wall -std=c++11 -Wno-unknown-pragmas
4155
LDFLAGS = -L$(XILINX_XRT)/lib/ -lstdc++ -lpthread -lrt -lOpenCL
4256

43-
host: myproject_host_cl.cpp libs/xcl2.cpp
44-
$(CXX) $(CXXFLAGS) $^ -o $@ $(INCLUDES) $(LDFLAGS)
57+
ifdef DEBUG
58+
XOCCFLAGS += -g
59+
XOLDFLAGS += -g
60+
CXXFLAGS += -g -O0
61+
else
62+
# Optimization flags can be added here
63+
endif
64+
65+
.PHONY: all xclbin hls clean cleanhls cleanxclbin
66+
67+
all: xclbin host
68+
69+
# Kernel C/RTL synthesis ######################################################
70+
71+
HLS_INCLUDES := -I./ -I./firmware/ -I./firmware/weights -I./firmware/nnet_utils/
72+
73+
$(BUILD_DIR)/$(KERNEL_NAME)_kernel.xo: $(WRAPPER_NAME).cpp firmware/$(KERNEL_NAME).cpp
74+
mkdir -p $(XO_DIR)
75+
v++ -c $(XOCCFLAGS) --temp_dir $(XO_DIR) --log_dir $(XO_DIR) -o $@ $^ $(HLS_INCLUDES)
76+
77+
hls: $(BUILD_DIR)/$(KERNEL_NAME)_kernel.xo
78+
79+
# Kernel linking & packaging ##################################################
80+
81+
# For Standard Alveo, a single step is required for linking and packaging
82+
ifneq (,$(findstring vck5000,$(PLATFORM)))
83+
84+
$(BUILD_DIR)/$(WRAPPER_NAME).xclbin: $(BUILD_DIR)/$(KERNEL_NAME)_kernel.xo
85+
mkdir -p $(XCLBIN_DIR)
86+
v++ -l $(XOLDFLAGS) --temp_dir $(XCLBIN_DIR) --log_dir $(XCLBIN_DIR) -o $@ $^
87+
88+
# For VCK5000, linking and packaging are separate steps
89+
else
90+
91+
$(BUILD_DIR)/$(WRAPPER_NAME).xsa: $(BUILD_DIR)/$(KERNEL_NAME)_kernel.xo
92+
mkdir -p $(XCLBIN_DIR)
93+
v++ -l $(XOLDFLAGS) --temp_dir $(XCLBIN_DIR) --log_dir $(XCLBIN_DIR) -o $@ $^
94+
95+
XOCCPFLAGS := -t $(TARGET) -f $(PLATFORM) --package.boot_mode=ospi --messageDb=$(BUILD_DIR)/kernel_wrapper.mdb
96+
97+
# VCK5000 specific packaging
98+
$(BUILD_DIR)/$(WRAPPER_NAME).xclbin: $(BUILD_DIR)/$(WRAPPER_NAME).xsa
99+
v++ -p $(XOCCPFLAGS) --temp_dir $(XCLBIN_DIR) --log_dir $(XCLBIN_DIR) -o $@ $^
100+
101+
endif
102+
103+
xclbin: $(BUILD_DIR)/$(WRAPPER_NAME).xclbin
104+
105+
# Host compilation ############################################################
106+
107+
INCLUDES := -I$(XILINX_XRT)/include/ -I$(XILINX_VIVADO)/include/ -I$(XILINX_HLS)/include/
108+
INCLUDES += -I$(PWD)/libs/ -I$(PWD)/firmware/ -I$(PWD)/firmware/nnet_utils/
109+
110+
host: $(KERNEL_NAME)_host_cl.cpp libs/xcl2.cpp
111+
$(CXX) $(CXXFLAGS) $^ -o $@ $(INCLUDES) $(LDFLAGS)
45112

46-
.PHONY: hls
47-
hls: ./build/myproject_kernel.xo
113+
# Cleanup #####################################################################
48114

49-
.PHONY: xclbin
50-
xclbin: ./build/kernel_wrapper.xclbin host
115+
cleanxclbin:
116+
rm -rf host tb_data/hw_results.dat
117+
rm -rf *$(WRAPPER_NAME)*.log
118+
rm -rf $(BUILD_DIR)/$(WRAPPER_NAME).xclbin* $(BUILD_DIR)/$(WRAPPER_NAME).xsa* $(BUILD_DIR)/$(WRAPPER_NAME).ltx $(BUILD_DIR)/$(WRAPPER_NAME).mdb
119+
rm -rf $(BUILD_DIR)/xclbincleanhls
51120

52-
# Cleaning stuff
53-
.PHONY: cleanxclbin
54-
-rm -rf host tb_data/hw_results.dat
55-
-rm -rf *kernel_wrapper*.log
56-
-rm -rf build/kernel_wrapper.xclbin* build/kernel_wrapper.xsa* build/kernel_wrapper.ltx build/kernel_wrapper.mdb
57-
-rm -rf build/xclbin
121+
cleanhls:
122+
rm -rf $(BUILD_DIR)/$(KERNEL_NAME)_kernel.xo*
123+
rm -rf $(BUILD_DIR)/xo
124+
rm -rf *$(KERNEL_NAME)_kernel*.log
58125

59-
.PHONY: cleanhls
60-
-rm -rf build/myproject_kernel.xo*
61-
-rm -rf build/xo
62-
-rm -rf *myproject_kernel*.log
126+
clean: cleanxclbin cleanhls

hls4ml/writer/vitis_accelerator_writer.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,6 @@ def write_makefile(self, model):
206206
for line in f.readlines():
207207
if 'myproject' in line:
208208
newline = line.replace('myproject', project_name)
209-
elif '# hls-fpga-machine-learning packaging' in line:
210-
if board_type == "alveo":
211-
newline = f'./build/kernel_wrapper.xclbin: ./build/{project_name}_kernel.xo\n'
212-
newline += f'\tmkdir -p ./build/xclbin\n'
213-
newline += f'\tv++ -l -t hw --config ./accelerator_card.cfg --temp_dir build/xclbin ./build/{project_name}_kernel.xo -o ./build/kernel_wrapper.xclbin\n'
214-
elif board_type == "versal":
215-
newline = f'./build/kernel_wrapper.xsa: ./build/{project_name}_kernel.xo\n'
216-
newline += f'\tmkdir -p ./build/xclbin\n'
217-
newline += f'\tv++ -l -t hw --config ./accelerator_card.cfg --temp_dir build/xclbin ./build/{project_name}_kernel.xo -o ./build/kernel_wrapper.xsa\n\n'
218-
newline += f'./build/kernel_wrapper.xclbin: ./build/kernel_wrapper.xsa\n'
219-
newline += f'\tv++ --package -t hw --config ./accelerator_card.cfg --temp_dir build/xclbin ./build/kernel_wrapper.xsa -o ./build/kernel_wrapper.xclbin\n'
220209
else:
221210
newline = line
222211
fout.write(newline)

0 commit comments

Comments
 (0)