1- # Absolute path to top directory of accelerator project
2- PWD = $(shell readlink -f .)
1+ # Check environment ###########################################################
32
4- # Checks for XILINX_VITIS
53ifndef XILINX_VITIS
64$(error XILINX_VITIS variable is not set, please set correctly and rerun)
75endif
86
9- # Checks for XILINX_XRT
107ifndef XILINX_XRT
118$(error XILINX_XRT variable is not set, please set correctly and rerun)
129endif
1310
14- # Checks for XILINX_VIVADO
1511ifndef XILINX_VIVADO
1612$(error XILINX_VIVADO variable is not set, please set correctly and rerun)
1713endif
1814
19- # Checks for g++
2015ifneq ($(shell expr $(shell g++ -dumpversion) \>= 5) , 1)
2116CXX := $(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 ) )
2318endif
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
4155LDFLAGS = -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
0 commit comments